summaryrefslogtreecommitdiffstats
path: root/binutils-2.22/gold/layout.cc
diff options
context:
space:
mode:
authorAlexander Ivchenko <alexander.ivchenko@intel.com>2013-01-25 14:35:38 +0400
committerAlexander Ivchenko <alexander.ivchenko@intel.com>2013-01-25 15:38:32 +0400
commit43cc3f59831134ed0b2447bb21767371417ac54a (patch)
treec10353fa1c13ac509d4d2269f8d15ac71d78eee4 /binutils-2.22/gold/layout.cc
parent8415ff0aaeb157307bb01a45373dba81919882fc (diff)
downloadtoolchain_binutils-43cc3f59831134ed0b2447bb21767371417ac54a.tar.gz
toolchain_binutils-43cc3f59831134ed0b2447bb21767371417ac54a.tar.bz2
toolchain_binutils-43cc3f59831134ed0b2447bb21767371417ac54a.zip
[2.22.90] Backport of two patches from mainline that enable
sorting of text sections Author: Sriraman Tallam <tmsriram@google.com> Date: Thu Jan 10 00:18:14 2013 +0000 Make linker scripts and section ordering via --section-ordering-file or linker plugins work. This patch lets linker scripts take precedence. 2013-01-09 Sriraman Tallam <tmsriram@google.com> * output.h (sort_attached_input_sections): Change to be public. * script-sections.cc (Output_section_definition::set_section_addresses): Sort attached input sections according to section order before linker script assigns section addresses. (Orphan_output_section::set_section_addresses): Sort attached input sections according to section order before linker script assigns section addresses. * Makefile.am (final_layout.sh): Use a simple linker script to check if section ordering still works. * Makefile.in: Regenerate. Author: Ian Lance Taylor <ian@airs.com> Date: Fri Dec 21 06:24:31 2012 +0000 * layout.cc (Layout::special_ordering_of_input_section): New function. (Layout::layout): If input section requires special ordering, must sort input sections. (Layout::make_output_section): May sort .text input sections. (Layout::is_section_name_prefix_grouped): Remove. * layout.h (class Layout): Declare special_ordering_of_input_section. Don't declare is_section_name_prefix_grouped. * output.cc (Output_section::add_input_section): Revert last change. (Output_section::Input_section_sort::match_file_name): Don't crash if called on output section data. (Output_section::Input_section_sort_compare): Sort based on special ordering. (Output_section::Input_section_sort_section_order_index_compare): Revert last patch. (Output_section::sort_attached_input_sections): Likewise. Change-Id: I385c609300f697abcdeb82324c9af903259fe2b6
Diffstat (limited to 'binutils-2.22/gold/layout.cc')
-rw-r--r--binutils-2.22/gold/layout.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/binutils-2.22/gold/layout.cc b/binutils-2.22/gold/layout.cc
index ad667ab8..cc800cdb 100644
--- a/binutils-2.22/gold/layout.cc
+++ b/binutils-2.22/gold/layout.cc
@@ -993,6 +993,33 @@ Layout::init_fixed_output_section(const char* name,
return os;
}
+// Return the index by which an input section should be ordered. This
+// is used to sort some .text sections, for compatibility with GNU ld.
+
+int
+Layout::special_ordering_of_input_section(const char* name)
+{
+ // The GNU linker has some special handling for some sections that
+ // wind up in the .text section. Sections that start with these
+ // prefixes must appear first, and must appear in the order listed
+ // here.
+ static const char* const text_section_sort[] =
+ {
+ ".text.unlikely",
+ ".text.exit",
+ ".text.startup",
+ ".text.hot"
+ };
+
+ for (size_t i = 0;
+ i < sizeof(text_section_sort) / sizeof(text_section_sort[0]);
+ i++)
+ if (is_prefix_of(text_section_sort[i], name))
+ return i;
+
+ return -1;
+}
+
// Return the output section to use for input section SHNDX, with name
// NAME, with header HEADER, from object OBJECT. RELOC_SHNDX is the
// index of a relocation section which applies to this section, or 0
@@ -1052,6 +1079,13 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
|| strcmp(name, ".dtors") == 0))))
os->set_must_sort_attached_input_sections();
+ // By default the GNU linker sorts some special text sections ahead
+ // of others. We are compatible.
+ if (!this->script_options_->saw_sections_clause()
+ && !parameters->options().relocatable()
+ && Layout::special_ordering_of_input_section(name) >= 0)
+ os->set_must_sort_attached_input_sections();
+
// If this is a .ctors or .ctors.* section being mapped to a
// .init_array section, or a .dtors or .dtors.* section being mapped
// to a .fini_array section, we will need to reverse the words if
@@ -1530,6 +1564,15 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type,
|| strcmp(name, ".dtors") == 0))))
os->set_may_sort_attached_input_sections();
+ // The GNU linker by default sorts .text.{unlikely,exit,startup,hot}
+ // sections before other .text sections. We are compatible. We
+ // need to know that this might happen before we attach any input
+ // sections.
+ if (!this->script_options_->saw_sections_clause()
+ && !parameters->options().relocatable()
+ && strcmp(name, ".text") == 0)
+ os->set_may_sort_attached_input_sections();
+
// Check for .stab*str sections, as .stab* sections need to link to
// them.
if (type == elfcpp::SHT_STRTAB