diff options
author | Ian Lance Taylor <ian@airs.com> | 2008-03-28 22:42:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2008-03-28 22:42:34 +0000 |
commit | 2fd322316ec7699c44d24b1c465c80ada336754d (patch) | |
tree | 9f4f290c5d9e5efe79544cfaf10a3c62f63b83d3 /gold/layout.cc | |
parent | 2460c166aeb65cd1664234dfebbd779c77ee2956 (diff) | |
download | gdb-2fd322316ec7699c44d24b1c465c80ada336754d.zip gdb-2fd322316ec7699c44d24b1c465c80ada336754d.tar.gz gdb-2fd322316ec7699c44d24b1c465c80ada336754d.tar.bz2 |
* layout.cc (Layout::layout): If we see an input section with a
name that needs sorting, set the must_sort flag for the output
section.
(Layout::make_output_section): If the name of the output section
indicates that it might require sorting, set the may_sort flag.
* output.h (Output_section::may_sort_attached_input_sections): New
function.
(Output_section::set_may_sort_attached_input_sections): New
function.
(Output_section::must_sort_attached_input_sections): New
function.
(Output_section::set_must_sort_attached_input_sections): New
function.
(class Output_section): Declare Input_section_sort_entry. Define
Input_section_sort_compare. Declare
sort_attached_input_sections. Add new fields:
may_sort_attached_input_sections_,
must_sort_attached_input_sections_,
attached_input_sections_are_sorted_.
* output.cc (Output_section::Output_section): Initialize new
fields.
(Output_section::add_input_section): Add an entry to
input_sections_ if may_sort or must_sort are true.
(Output_section::set_final_data_size): Call
sort_attached_input_sections if necessary.
(Output_section::Input_section_sort_entry): Define new class.
(Output_section::Input_section_sort_compare::operator()): New
function.
(Output_section::sort_attached_input_sections): New function.
* configure.ac: Check whether the compiler supports constructor
priorities. Define a CONSTRUCTOR_PRIORITY automake conditional.
* testsuite/initpri1.c: New file.
* testsuite/Makefile.am (check_PROGRAMS): Add initpri1 if
CONSTRUCTOR_PRIORITY.
(initpri1_SOURCES, initpri1_DEPENDENCIES): New variables.
(initpri1_LDFLAGS): New variable.
* configure, Makefile.in, testsuite/Makefile.in: Rebuild.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r-- | gold/layout.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gold/layout.cc b/gold/layout.cc index 1bbfcb6..e8582ca 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -404,6 +404,17 @@ Layout::layout(Sized_relobj<size, big_endian>* object, unsigned int shndx, return NULL; } + // By default the GNU linker sorts input sections whose names match + // .ctor.*, .dtor.*, .init_array.*, or .fini_array.*. The sections + // are sorted by name. This is used to implement constructor + // priority ordering. We are compatible. + if (!this->script_options_->saw_sections_clause() + && (is_prefix_of(".ctors.", name) + || is_prefix_of(".dtors.", name) + || is_prefix_of(".init_array.", name) + || is_prefix_of(".fini_array.", name))) + os->set_must_sort_attached_input_sections(); + // FIXME: Handle SHF_LINK_ORDER somewhere. *off = os->add_input_section(object, shndx, name, shdr, reloc_shndx, @@ -671,6 +682,16 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type, else this->attach_to_segment(os, flags); + // The GNU linker by default sorts some sections by priority, so we + // do the same. We need to know that this might happen before we + // attach any input sections. + if (!this->script_options_->saw_sections_clause() + && (strcmp(name, ".ctors") == 0 + || strcmp(name, ".dtors") == 0 + || strcmp(name, ".init_array") == 0 + || strcmp(name, ".fini_array") == 0)) + os->set_may_sort_attached_input_sections(); + return os; } |