diff options
author | Sriraman Tallam <tmsriram@google.com> | 2013-01-10 00:18:15 +0000 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2013-01-10 00:18:15 +0000 |
commit | 9e9143bc874ab4742433b7498413313fb1723e8b (patch) | |
tree | affd5cff00b087689a5da91d989d3fcdc3527f47 /gold | |
parent | 40c134978ad094bc831acd08703edee156b68f75 (diff) | |
download | gdb-9e9143bc874ab4742433b7498413313fb1723e8b.zip gdb-9e9143bc874ab4742433b7498413313fb1723e8b.tar.gz gdb-9e9143bc874ab4742433b7498413313fb1723e8b.tar.bz2 |
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.
Diffstat (limited to 'gold')
-rw-r--r-- | gold/ChangeLog | 14 | ||||
-rw-r--r-- | gold/output.h | 8 | ||||
-rw-r--r-- | gold/script-sections.cc | 18 | ||||
-rw-r--r-- | gold/testsuite/Makefile.am | 8 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 7 |
5 files changed, 46 insertions, 9 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog index 1ee71dd..72271fa 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,17 @@ +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. + 2013-01-09 Ben Cheng <bccheng@google.com> * arm.cc (Target_arm::attributes_accept_div): New function. diff --git a/gold/output.h b/gold/output.h index a8fe594..8f3943b 100644 --- a/gold/output.h +++ b/gold/output.h @@ -3300,6 +3300,10 @@ class Output_section : public Output_data this->dynsym_index_ = index; } + // Sort the attached input sections. + void + sort_attached_input_sections(); + // Return whether the input sections sections attachd to this output // section may require sorting. This is used to handle constructor // priorities compatibly with GNU ld. @@ -4253,10 +4257,6 @@ class Output_section : public Output_data add_output_merge_section(Output_section_data* posd, bool is_string, uint64_t entsize); - // Sort the attached input sections. - void - sort_attached_input_sections(); - // Find the merge section into which an input section with index SHNDX in // OBJECT has been added. Return NULL if none found. Output_section_data* diff --git a/gold/script-sections.cc b/gold/script-sections.cc index e5d3a93..2fb8cbb 100644 --- a/gold/script-sections.cc +++ b/gold/script-sections.cc @@ -2294,6 +2294,15 @@ Output_section_definition::set_section_addresses(Symbol_table* symtab, uint64_t old_dot_value = *dot_value; uint64_t old_load_address = *load_address; + // If input section sorting is requested via --section-ordering-file or + // linker plugins, then do it here. This is important because we want + // any sorting specified in the linker scripts, which will be done after + // this, to take precedence. The final order of input sections is then + // guaranteed to be according to the linker script specification. + if (this->output_section_ != NULL + && this->output_section_->input_section_order_specified()) + this->output_section_->sort_attached_input_sections(); + // Decide the start address for the section. The algorithm is: // 1) If an address has been specified in a linker script, use that. // 2) Otherwise if a memory region has been specified for the section, @@ -2865,6 +2874,15 @@ Orphan_output_section::set_section_addresses(Symbol_table*, Layout*, uint64_t address = *dot_value; address = align_address(address, this->os_->addralign()); + // If input section sorting is requested via --section-ordering-file or + // linker plugins, then do it here. This is important because we want + // any sorting specified in the linker scripts, which will be done after + // this, to take precedence. The final order of input sections is then + // guaranteed to be according to the linker script specification. + if (this->os_ != NULL + && this->os_->input_section_order_specified()) + this->os_->sort_attached_input_sections(); + // For a relocatable link, all orphan sections are put at // address 0. In general we expect all sections to be at // address 0 for a relocatable link, but we permit the linker diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 74621e9..e5f445a 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -246,13 +246,15 @@ icf_safe_so_test_2.stdout: icf_safe_so_test check_SCRIPTS += final_layout.sh check_DATA += final_layout.stdout -MOSTLYCLEANFILES += final_layout final_layout_sequence.txt +MOSTLYCLEANFILES += final_layout final_layout_sequence.txt final_layout_script.lds final_layout.o: final_layout.cc $(CXXCOMPILE) -O0 -c -ffunction-sections -fdata-sections -g -o $@ $< final_layout_sequence.txt: (echo "*_Z3barv*" && echo ".text._Z3bazv" && echo "*_Z3foov*" && echo "*global_varb*" && echo "*global_vara*" && echo "*global_varc*") > final_layout_sequence.txt -final_layout: final_layout.o final_layout_sequence.txt gcctestdir/ld - $(CXXLINK) -Bgcctestdir/ -Wl,--section-ordering-file,final_layout_sequence.txt final_layout.o +final_layout_script.lds: + (echo "SECTIONS { .text : { *(.text*) } .bss : { *(.bss*) } }") > final_layout_script.lds +final_layout: final_layout.o final_layout_sequence.txt final_layout_script.lds gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -Wl,--section-ordering-file,final_layout_sequence.txt -Wl,-T,final_layout_script.lds final_layout.o final_layout.stdout: final_layout $(TEST_NM) -n --synthetic final_layout > final_layout.stdout diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index f829774..6e22934 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -125,6 +125,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_test icf_safe_so_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout_sequence.txt \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout_script.lds \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \ @@ -4355,8 +4356,10 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fdata-sections -g -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@final_layout_sequence.txt: @GCC_TRUE@@NATIVE_LINKER_TRUE@ (echo "*_Z3barv*" && echo ".text._Z3bazv" && echo "*_Z3foov*" && echo "*global_varb*" && echo "*global_vara*" && echo "*global_varc*") > final_layout_sequence.txt -@GCC_TRUE@@NATIVE_LINKER_TRUE@final_layout: final_layout.o final_layout_sequence.txt gcctestdir/ld -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--section-ordering-file,final_layout_sequence.txt final_layout.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@final_layout_script.lds: +@GCC_TRUE@@NATIVE_LINKER_TRUE@ (echo "SECTIONS { .text : { *(.text*) } .bss : { *(.bss*) } }") > final_layout_script.lds +@GCC_TRUE@@NATIVE_LINKER_TRUE@final_layout: final_layout.o final_layout_sequence.txt final_layout_script.lds gcctestdir/ld +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--section-ordering-file,final_layout_sequence.txt -Wl,-T,final_layout_script.lds final_layout.o @GCC_TRUE@@NATIVE_LINKER_TRUE@final_layout.stdout: final_layout @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic final_layout > final_layout.stdout @GCC_TRUE@@NATIVE_LINKER_TRUE@text_section_grouping.o: text_section_grouping.cc |