This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH COMMITTED: Fix section groups in objects with many sections
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Mon, 05 May 2008 12:19:04 -0700
- Subject: PATCH COMMITTED: Fix section groups in objects with many sections
Gold was not correctly handling section groups in object with many
sections, in the case where the object was created by a version of the
GNU binutils from before the fix for PR 5900. I committed this patch
to fix it. I added a template to the many sections test, which causes
the bug to appear.
Ian
2008-05-05 Ian Lance Taylor <iant@google.com>
* object.cc (Sized_relobj::include_section_group): Adjust section
indexes read from group data. Build vector to pass to
layout_group.
* layout.cc (Layout::layout_group): Add flags and shndxes
parameters. Remove contents parameter. Change caller. Update
explicit instantiations.
* layout.h (class Layout): Update layout_group declaration.
* output.cc (Output_data_group::Output_data_group): Add flags and
input_shndxes parameters. Remove contents parameter. Change
caller.
(Output_data_group::do_write): Change input_sections_ to
input_shndxes_.
* output.h (class Output_data_group): Update constructor
declaration. Rename input_sections_ to input_shndxes_.
* testsuite/many_sections_test.cc: Add template.
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.101
diff -p -u -r1.101 layout.cc
--- layout.cc 1 May 2008 01:23:21 -0000 1.101
+++ layout.cc 5 May 2008 19:12:34 -0000
@@ -503,7 +503,8 @@ Layout::layout_group(Symbol_table* symta
const char* group_section_name,
const char* signature,
const elfcpp::Shdr<size, big_endian>& shdr,
- const elfcpp::Elf_Word* contents)
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* shndxes)
{
gold_assert(parameters->options().relocatable());
gold_assert(shdr.get_sh_type() == elfcpp::SHT_GROUP);
@@ -531,7 +532,8 @@ Layout::layout_group(Symbol_table* symta
section_size_type entry_count =
convert_to_section_size_type(shdr.get_sh_size() / 4);
Output_section_data* posd =
- new Output_data_group<size, big_endian>(object, entry_count, contents);
+ new Output_data_group<size, big_endian>(object, entry_count, flags,
+ shndxes);
os->add_output_section_data(posd);
}
@@ -3258,7 +3260,8 @@ Layout::layout_group<32, false>(Symbol_t
const char* group_section_name,
const char* signature,
const elfcpp::Shdr<32, false>& shdr,
- const elfcpp::Elf_Word* contents);
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* shndxes);
#endif
#ifdef HAVE_TARGET_32_BIG
@@ -3270,7 +3273,8 @@ Layout::layout_group<32, true>(Symbol_ta
const char* group_section_name,
const char* signature,
const elfcpp::Shdr<32, true>& shdr,
- const elfcpp::Elf_Word* contents);
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* shndxes);
#endif
#ifdef HAVE_TARGET_64_LITTLE
@@ -3282,7 +3286,8 @@ Layout::layout_group<64, false>(Symbol_t
const char* group_section_name,
const char* signature,
const elfcpp::Shdr<64, false>& shdr,
- const elfcpp::Elf_Word* contents);
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* shndxes);
#endif
#ifdef HAVE_TARGET_64_BIG
@@ -3294,7 +3299,8 @@ Layout::layout_group<64, true>(Symbol_ta
const char* group_section_name,
const char* signature,
const elfcpp::Shdr<64, true>& shdr,
- const elfcpp::Elf_Word* contents);
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* shndxes);
#endif
#ifdef HAVE_TARGET_32_LITTLE
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.56
diff -p -u -r1.56 layout.h
--- layout.h 1 May 2008 01:23:21 -0000 1.56
+++ layout.h 5 May 2008 19:12:34 -0000
@@ -125,7 +125,8 @@ class Layout
const char* group_section_name,
const char* signature,
const elfcpp::Shdr<size, big_endian>& shdr,
- const elfcpp::Elf_Word* contents);
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* shndxes);
// Like layout, only for exception frame sections. OBJECT is an
// object file. SYMBOLS is the contents of the symbol table
Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.73
diff -p -u -r1.73 object.cc
--- object.cc 1 May 2008 01:23:21 -0000 1.73
+++ object.cc 5 May 2008 19:12:34 -0000
@@ -604,10 +604,6 @@ Sized_relobj<size, big_endian>::include_
bool include_group = ((flags & elfcpp::GRP_COMDAT) == 0
|| layout->add_comdat(this, index, signature, true));
- if (include_group && parameters->options().relocatable())
- layout->layout_group(symtab, this, index, name, signature.c_str(),
- shdr, pword);
-
Relobj* kept_object = NULL;
Comdat_group* kept_group = NULL;
@@ -629,10 +625,20 @@ Sized_relobj<size, big_endian>::include_
}
size_t count = shdr.get_sh_size() / sizeof(elfcpp::Elf_Word);
+
+ std::vector<unsigned int> shndxes;
+ bool relocate_group = include_group && parameters->options().relocatable();
+ if (relocate_group)
+ shndxes.reserve(count - 1);
+
for (size_t i = 1; i < count; ++i)
{
elfcpp::Elf_Word secnum =
- elfcpp::Swap<32, big_endian>::readval(pword + i);
+ this->adjust_shndx(elfcpp::Swap<32, big_endian>::readval(pword + i));
+
+ if (relocate_group)
+ shndxes.push_back(secnum);
+
if (secnum >= this->shnum())
{
this->error(_("section %u in section group %u out of range"),
@@ -681,6 +687,10 @@ Sized_relobj<size, big_endian>::include_
}
}
+ if (relocate_group)
+ layout->layout_group(symtab, this, index, name, signature.c_str(),
+ shdr, flags, &shndxes);
+
return include_group;
}
Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.73
diff -p -u -r1.73 output.cc
--- output.cc 19 Apr 2008 18:30:58 -0000 1.73
+++ output.cc 5 May 2008 19:12:34 -0000
@@ -997,16 +997,13 @@ template<int size, bool big_endian>
Output_data_group<size, big_endian>::Output_data_group(
Sized_relobj<size, big_endian>* relobj,
section_size_type entry_count,
- const elfcpp::Elf_Word* contents)
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* input_shndxes)
: Output_section_data(entry_count * 4, 4),
- relobj_(relobj)
+ relobj_(relobj),
+ flags_(flags)
{
- this->flags_ = elfcpp::Swap<32, big_endian>::readval(contents);
- for (section_size_type i = 1; i < entry_count; ++i)
- {
- unsigned int shndx = elfcpp::Swap<32, big_endian>::readval(contents + i);
- this->input_sections_.push_back(shndx);
- }
+ this->input_shndxes_.swap(*input_shndxes);
}
// Write out the section group, which means translating the section
@@ -1026,8 +1023,8 @@ Output_data_group<size, big_endian>::do_
++contents;
for (std::vector<unsigned int>::const_iterator p =
- this->input_sections_.begin();
- p != this->input_sections_.end();
+ this->input_shndxes_.begin();
+ p != this->input_shndxes_.end();
++p, ++contents)
{
section_offset_type dummy;
@@ -1052,7 +1049,7 @@ Output_data_group<size, big_endian>::do_
of->write_output_view(off, oview_size, oview);
// We no longer need this information.
- this->input_sections_.clear();
+ this->input_shndxes_.clear();
}
// Output_data_got::Got_entry methods.
Index: output.h
===================================================================
RCS file: /cvs/src/src/gold/output.h,v
retrieving revision 1.65
diff -p -u -r1.65 output.h
--- output.h 19 Apr 2008 18:30:58 -0000 1.65
+++ output.h 5 May 2008 19:12:35 -0000
@@ -1346,9 +1346,11 @@ template<int size, bool big_endian>
class Output_data_group : public Output_section_data
{
public:
+ // The constructor clears *INPUT_SHNDXES.
Output_data_group(Sized_relobj<size, big_endian>* relobj,
section_size_type entry_count,
- const elfcpp::Elf_Word* contents);
+ elfcpp::Elf_Word flags,
+ std::vector<unsigned int>* input_shndxes);
void
do_write(Output_file*);
@@ -1359,7 +1361,7 @@ class Output_data_group : public Output_
// The group flag word.
elfcpp::Elf_Word flags_;
// The section indexes of the input sections in this group.
- std::vector<unsigned int> input_sections_;
+ std::vector<unsigned int> input_shndxes_;
};
// Output_data_got is used to manage a GOT. Each entry in the GOT is
Index: testsuite/many_sections_test.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/many_sections_test.cc,v
retrieving revision 1.1
diff -p -u -r1.1 many_sections_test.cc
--- testsuite/many_sections_test.cc 19 Apr 2008 18:30:58 -0000 1.1
+++ testsuite/many_sections_test.cc 5 May 2008 19:12:35 -0000
@@ -29,9 +29,23 @@
#include "many_sections_define.h"
+// This tests a section group.
+template<typename T>
+class C
+{
+ public:
+ static T val() { return C::val_; }
+ private:
+ static T val_;
+};
+
+template<typename T>
+T C<T>::val_;
+
int
main(int, char**)
{
#include "many_sections_check.h"
+ assert(C<int>::val() == 0);
return 0;
}