From 9e9143bc874ab4742433b7498413313fb1723e8b Mon Sep 17 00:00:00 2001 From: Sriraman Tallam Date: Thu, 10 Jan 2013 00:18:15 +0000 Subject: 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 * 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. --- gold/script-sections.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gold/script-sections.cc') 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 -- cgit v1.1