diff options
author | Sriraman Tallam <tmsriram@google.com> | 2013-01-24 18:49:55 +0000 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2013-01-24 18:49:55 +0000 |
commit | c6ac678db54ed727cb673a87beeb7a41bdf13182 (patch) | |
tree | b2a220a0034d74e463386bb5efa8e1ac0a2fd697 /gold/output.cc | |
parent | 45e6c716a91b609472e7b807347f9ed3a86c8113 (diff) | |
download | gdb-c6ac678db54ed727cb673a87beeb7a41bdf13182.zip gdb-c6ac678db54ed727cb673a87beeb7a41bdf13182.tar.gz gdb-c6ac678db54ed727cb673a87beeb7a41bdf13182.tar.bz2 |
Default text reordering fix with a flag to turn it off.
2013-01-24 Sriraman Tallam <tmsriram@google.com>
* layout.cc (Layout::layout): Check for option text_reorder.
(Layout::make_output_section): Ditto.
* options.h (text_reorder): New option.
* output.cc (Input_section_sort_compare): Remove special ordering
of section names.
(Output_section::
Input_section_sort_section_name_special_ordering_compare::
operator()): New function.
(Output_section::sort_attached_input_sections): Use new sort function
for .text.
* output.h (Input_section_sort_section_name_special_ordering_compare):
New struct.
* testsuite/Makefile.am (text_section_grouping): Test option
--no-text-reorder
* testsuite/Makefile.in: Regenerate.
* testsuite/text_section_grouping.sh: Check order of functions without
default text reordering.
Diffstat (limited to 'gold/output.cc')
-rw-r--r-- | gold/output.cc | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/gold/output.cc b/gold/output.cc index 01126a3..22c0bf0 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -3389,19 +3389,6 @@ Output_section::Input_section_sort_compare::operator()( return s1.index() < s2.index(); } - // Some input section names have special ordering requirements. - int o1 = Layout::special_ordering_of_input_section(s1.section_name().c_str()); - int o2 = Layout::special_ordering_of_input_section(s2.section_name().c_str()); - if (o1 != o2) - { - if (o1 < 0) - return false; - else if (o2 < 0) - return true; - else - return o1 < o2; - } - // A section with a priority follows a section without a priority. bool s1_has_priority = s1.has_priority(); bool s2_has_priority = s2.has_priority(); @@ -3508,6 +3495,42 @@ Output_section::Input_section_sort_section_order_index_compare::operator()( return s1_secn_index < s2_secn_index; } +// Return true if S1 should come before S2. This is the sort comparison +// function for .text to sort sections with prefixes +// .text.{unlikely,exit,startup,hot} before other sections. +bool +Output_section::Input_section_sort_section_name_special_ordering_compare + ::operator()( + const Output_section::Input_section_sort_entry& s1, + const Output_section::Input_section_sort_entry& s2) const +{ + // We sort all the sections with no names to the end. + if (!s1.section_has_name() || !s2.section_has_name()) + { + if (s1.section_has_name()) + return true; + if (s2.section_has_name()) + return false; + return s1.index() < s2.index(); + } + + // Some input section names have special ordering requirements. + int o1 = Layout::special_ordering_of_input_section(s1.section_name().c_str()); + int o2 = Layout::special_ordering_of_input_section(s2.section_name().c_str()); + if (o1 != o2) + { + if (o1 < 0) + return false; + else if (o2 < 0) + return true; + else + return o1 < o2; + } + + // Keep input order otherwise. + return s1.index() < s2.index(); +} + // This updates the section order index of input sections according to the // the order specified in the mapping from Section id to order index. @@ -3576,6 +3599,9 @@ Output_section::sort_attached_input_sections() || this->type() == elfcpp::SHT_FINI_ARRAY) std::sort(sort_list.begin(), sort_list.end(), Input_section_sort_init_fini_compare()); + else if (strcmp(this->name(), ".text") == 0) + std::sort(sort_list.begin(), sort_list.end(), + Input_section_sort_section_name_special_ordering_compare()); else std::sort(sort_list.begin(), sort_list.end(), Input_section_sort_compare()); |