[PATCH][GOLD] Fix sorting of .init_array and .fini_array input sections.
Ian Lance Taylor
iant@google.com
Mon Mar 1 19:34:00 GMT 2010
"Doug Kwan (關振德)" <dougkwan@google.com> writes:
> 2010-03-01 Doug Kwan <dougkwan@google.com>
>
> * layout.cc (Layout::get_output_section): Force section types of
> .init_array and .fini_array.
> * output.cc (Output_section::Input_section_sort_entry::has_priority):
> Fix check of return value of std::string::find.().
> (Output_section::Input_section_sort_compare::operator()): Remove
> comment about .init_array.
> (Output_section::Input_section_sort_init_fini_compare::operator()):
> New method.
> (Output_section::sort_attached_input_sections): Handle .init_array
> and .fini_array specially.
> * output.h (Output_section::Inut_section_sort_compare): Update
> comment.
> (Output_section::Input_section_sort_init_fini_compare): New struct.
> Index: gold/layout.cc
> ===================================================================
> RCS file: /cvs/src/src/gold/layout.cc,v
> retrieving revision 1.166
> diff -u -u -p -r1.166 layout.cc
> --- gold/layout.cc 24 Feb 2010 20:45:12 -0000 1.166
> +++ gold/layout.cc 1 Mar 2010 09:13:39 -0000
> @@ -417,6 +417,14 @@ Layout::get_output_section(const char* n
> // controlling this.
> lookup_flags &= ~(elfcpp::SHF_WRITE | elfcpp::SHF_EXECINSTR);
>
> + // For section ".init_array" and ".fini_array", force the appropriate
> + // section types. Sometimes .init_array.* and .fini_array.* sections have
> + // type SHT_PROGBITS.
> + if (strcmp(name, ".init_array") == 0)
> + type = elfcpp::SHT_INIT_ARRAY;
> + else if (strcmp(name, ".fini_array") == 0)
> + type = elfcpp::SHT_FINI_ARRAY;
> +
> const Key key(name_key, std::make_pair(type, lookup_flags));
> const std::pair<Key, Output_section*> v(key, NULL);
> std::pair<Section_name_map::iterator, bool> ins(
I don't think this is the right place for this. I think you should do
it in the loop over sections in Sized_relobj::do_layout. Perhaps you
could call a little function to change the type if appropriate. I
think you should only change the type if the initial type is
SHT_PROGBITS. You should also force .preinit_array to change from
SHT_PROGBITS to SHT_PREINIT_ARRAY.
> @@ -2819,7 +2853,13 @@ Output_section::sort_attached_input_sect
> sort_list.push_back(Input_section_sort_entry(*p, i));
>
> // Sort the input sections.
> - std::sort(sort_list.begin(), sort_list.end(), Input_section_sort_compare());
> + if (strcmp(this->name(), ".init_array") == 0
> + || strcmp(this->name(), ".fini_array") == 0)
> + std::sort(sort_list.begin(), sort_list.end(),
> + Input_section_sort_init_fini_compare());
> + else
> + std::sort(sort_list.begin(), sort_list.end(),
> + Input_section_sort_compare());
Now that you have set the type, you should check the type here rather
the name. You should also check for PREINIT_ARRAY.
This is OK with those changes.
Thanks.
Ian
More information about the Binutils
mailing list