PATCH: PR ld/3223: ld fails to link correct variables from linker script

H. J. Lu hjl@lucon.org
Sun Sep 24 00:08:00 GMT 2006


On Fri, Sep 22, 2006 at 06:09:29PM -0700, H. J. Lu wrote:
> When an empty output section is ignored, we also ignore its address. I
> think we should honor its address.
> 

Here is the updated patch. I added ignored_vma so that we can set it
in one place.


H.J.
---
ld/

2006-09-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/3223
	* ldlang.h (lang_output_section_statement_type): Add ignored_vma.
	* ldlang.c (strip_excluded_output_sections): Set ignored_vma
	to TRUE if address of an empty output section isn't set.
	(lang_size_sections_1): Check ignored_vma for updating "dot",
	instead of ignored.
	(lang_do_assignments_1): Likewise.

ld/testsuite/

2006-09-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/3223
	* ld-scripts/empty-address-1.d: New file.
	* ld-scripts/empty-address-1.s: Likewise.
	* ld-scripts/empty-address-1.t: Likewise.
	* ld-scripts/empty-address-2.d: Likewise.
	* ld-scripts/empty-address-2.s: Likewise.
	* ld-scripts/empty-address-2.t: Likewise.
	* ld-scripts/empty-address.exp: Likewise.

--- ld/ldlang.c.empty	2006-09-22 12:44:41.000000000 -0700
+++ ld/ldlang.c	2006-09-23 09:40:10.000000000 -0700
@@ -3373,6 +3373,9 @@ strip_excluded_output_sections (void)
 	  /* We don't set bfd_section to NULL since bfd_section of the
 	     removed output section statement may still be used.  */
 	  os->ignored = TRUE;
+	  /* If address of an empty output section is set, we update
+	     "dot" even if it is ignored.  */
+	  os->ignored_vma = os->addr_tree == NULL;
 	  output_section->flags |= SEC_EXCLUDE;
 	  bfd_section_list_remove (output_bfd, output_section);
 	  output_bfd->section_count--;
@@ -4461,7 +4464,7 @@ lang_size_sections_1
 	      }
 	    os->processed_lma = TRUE;
 
-	    if (bfd_is_abs_section (os->bfd_section) || os->ignored)
+	    if (bfd_is_abs_section (os->bfd_section) || os->ignored_vma)
 	      break;
 
 	    /* Keep track of normal sections using the default
@@ -4815,7 +4818,7 @@ lang_do_assignments_1 (lang_statement_un
 	    lang_output_section_statement_type *os;
 
 	    os = &(s->output_section_statement);
-	    if (os->bfd_section != NULL && !os->ignored)
+	    if (os->bfd_section != NULL && !os->ignored_vma)
 	      {
 		dot = os->bfd_section->vma;
 
--- ld/ldlang.h.empty	2006-09-07 10:16:34.000000000 -0700
+++ ld/ldlang.h	2006-09-23 09:29:53.000000000 -0700
@@ -154,6 +154,7 @@ typedef struct lang_output_section_state
   unsigned int processed_lma : 1;
   unsigned int all_input_readonly : 1;
   unsigned int ignored : 1; 
+  unsigned int ignored_vma : 1; 
 } lang_output_section_statement_type;
 
 typedef struct
--- ld/testsuite/ld-scripts/empty-address-1.d.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-1.d	2006-09-22 18:00:44.000000000 -0700
@@ -0,0 +1,8 @@
+#ld: -T empty-address-1.t
+#nm: -n
+#...
+0+0 T _start
+#...
+0+2000000 A __data_end
+0+2000000 A __data_start
+#pass
--- ld/testsuite/ld-scripts/empty-address-1.s.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-1.s	2006-09-22 17:47:42.000000000 -0700
@@ -0,0 +1,5 @@
+	.text
+	.global _start
+_start:
+	.long __data_start
+	.long __data_end
--- ld/testsuite/ld-scripts/empty-address-1.t.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-1.t	2006-09-22 18:00:56.000000000 -0700
@@ -0,0 +1,11 @@
+SECTIONS
+{
+  .text 0x0000000: { *(.text) }
+  .data 0x2000000:
+  {
+    __data_start = . ;
+    *(.data)
+  }
+   __data_end = .;
+  /DISCARD/ : { *(.*) }
+}
--- ld/testsuite/ld-scripts/empty-address-2.d.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-2.d	2006-09-22 18:01:04.000000000 -0700
@@ -0,0 +1,7 @@
+#ld: -Ttext 0x0000000 -Tdata 0x2000000 -T empty-address-2.t
+#nm: -n
+#...
+0+0 T _start
+#...
+0+2000000 A __data_end
+#pass
--- ld/testsuite/ld-scripts/empty-address-2.s.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-2.s	2006-09-22 17:47:50.000000000 -0700
@@ -0,0 +1,4 @@
+	.text
+	.global _start
+_start:
+	.long __data_end
--- ld/testsuite/ld-scripts/empty-address-2.t.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-2.t	2006-09-22 17:48:44.000000000 -0700
@@ -0,0 +1,7 @@
+SECTIONS
+{
+  .text : { *(.text) }
+  .data : { *(.data) }
+   __data_end = .;
+  /DISCARD/ : { *(.*) }
+}
--- ld/testsuite/ld-scripts/empty-address.exp.empty	2006-09-22 17:58:49.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address.exp	2006-09-22 18:05:30.000000000 -0700
@@ -0,0 +1,21 @@
+# Make sure that "dot" is updated for empty sections if their addresses
+# are set.
+#   Copyright 2006
+#   Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+run_dump_test empty-address-1
+run_dump_test empty-address-2



More information about the Binutils mailing list