aboutsummaryrefslogtreecommitdiff
path: root/gold/layout.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2012-12-21 06:24:31 +0000
committerIan Lance Taylor <ian@airs.com>2012-12-21 06:24:31 +0000
commitedcac0c105556029774320bc8288beb472e999b5 (patch)
treefe3f5136d7ebc3d5df8dd65aa0bc20cd3cee3cb5 /gold/layout.cc
parent600e715a7ba9eb29f781efdf35fb1627879a2e83 (diff)
downloadgdb-edcac0c105556029774320bc8288beb472e999b5.zip
gdb-edcac0c105556029774320bc8288beb472e999b5.tar.gz
gdb-edcac0c105556029774320bc8288beb472e999b5.tar.bz2
* 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.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r--gold/layout.cc57
1 files changed, 43 insertions, 14 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index 62b4cad..f7f0e7e 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -1033,6 +1033,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
@@ -1120,6 +1147,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
@@ -1607,6 +1641,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
@@ -2409,20 +2452,6 @@ Layout::relaxation_loop_body(
return off;
}
-// By default, gold groups input sections with certain prefixes. This
-// function returns true if this section name NAME contains such a prefix.
-
-bool
-Layout::is_section_name_prefix_grouped(const char *name)
-{
- if (is_prefix_of(".text.unlikely", name)
- || is_prefix_of(".text.startup", name)
- || is_prefix_of(".text.hot", name))
- return true;
-
- return false;
-}
-
// Search the list of patterns and find the postion of the given section
// name in the output section. If the section name matches a glob
// pattern and a non-glob name, then the non-glob position takes