[gold patch] Start sections at 0 for relocatable links

Cary Coutant ccoutant@google.com
Fri Apr 12 23:42:00 GMT 2013


If an Output_section_definition immediately follows an orphaned
section of non-zero size in the layout order, that section is assigned
a starting address based on the length of the last orphaned section.
This patch fixes this by resetting dot_value to 0 after each orphaned
section.

Tested on x86_64. OK to apply?

-cary

gold/
    * script-sections.cc (Orphan_output_section): Reset address
    to zero after each orphaned section for relocatable links.
-------------- next part --------------
2013-04-12  Cary Coutant  <ccoutant@google.com>

gold/
	* script-sections.cc (Orphan_output_section): Reset address
	to zero after each orphaned section for relocatable links.


diff --git a/gold/script-sections.cc b/gold/script-sections.cc
index 2fb8cbb..a57e53f 100644
--- a/gold/script-sections.cc
+++ b/gold/script-sections.cc
@@ -2918,11 +2918,17 @@ Orphan_output_section::set_section_addresses(Symbol_table*, Layout*,
       address += size;
     }
 
-  // An SHF_TLS/SHT_NOBITS section does not take up any address space.
-  if (this->os_ == NULL
-      || (this->os_->flags() & elfcpp::SHF_TLS) == 0
-      || this->os_->type() != elfcpp::SHT_NOBITS)
+  if (parameters->options().relocatable())
+    {
+      // For a relocatable link, reset DOT_VALUE to 0.
+      *dot_value = 0;
+      *load_address = 0;
+    }
+  else if (this->os_ == NULL
+	   || (this->os_->flags() & elfcpp::SHF_TLS) == 0
+	   || this->os_->type() != elfcpp::SHT_NOBITS)
     {
+      // An SHF_TLS/SHT_NOBITS section does not take up any address space.
       if (!have_load_address)
 	*load_address = address;
       else


More information about the Binutils mailing list