This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Sat, Sep 23, 2006 at 09:56:27AM -0700, H. J. Lu wrote:
> 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.
> 
> 

It turns out that x86-64 linker scripts have

  .ldata   ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE)
- 1)) :
  {
    *(.ldata .ldata.* .gnu.linkonce.l.*)
    . = ALIGN(. != 0 ? 64 / 8 : 1);
  }
  . = ALIGN(64 / 8);
  _end = .; PROVIDE (end = .);

If .ldata is empty, we want to totally remove it without any trace.
This patch will hornor the constant adress of an empty output section.


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 to a
	constant.
	(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-3.s: Likewise.
	* ld-scripts/empty-address-3a.d: Likewise.
	* ld-scripts/empty-address-3a.t: Likewise.
	* ld-scripts/empty-address-3b.d: Likewise.
	* ld-scripts/empty-address-3b.t: Likewise.
	* ld-scripts/empty-address.exp: Likewise.

--- ld/ldlang.c.empty	2006-09-23 09:46:41.000000000 -0700
+++ ld/ldlang.c	2006-09-23 13:58:58.000000000 -0700
@@ -3373,6 +3373,11 @@ 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 to a constant,
+	     we update "dot" even if it is ignored.  */
+	  os->ignored_vma
+	    = (os->addr_tree == NULL
+	       || os->addr_tree->type.node_class != etree_value);
 	  output_section->flags |= SEC_EXCLUDE;
 	  bfd_section_list_remove (output_bfd, output_section);
 	  output_bfd->section_count--;
@@ -4461,7 +4466,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 +4820,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:46:41.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-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-1.d	2006-09-23 09:46:41.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-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-1.s	2006-09-23 09:46:41.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-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-1.t	2006-09-23 14:10:30.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-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-2.d	2006-09-23 09:46:41.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-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-2.s	2006-09-23 09:46:41.000000000 -0700
@@ -0,0 +1,4 @@
+	.text
+	.global _start
+_start:
+	.long __data_end
--- ld/testsuite/ld-scripts/empty-address-2.t.empty	2006-09-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-2.t	2006-09-23 14:10:38.000000000 -0700
@@ -0,0 +1,7 @@
+SECTIONS
+{
+  .text : { *(.text) }
+  .data : { *(.data) }
+  __data_end = .;
+  /DISCARD/ : { *(.*) }
+}
--- ld/testsuite/ld-scripts/empty-address-3.s.empty	2006-09-23 14:12:51.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-3.s	2006-09-23 13:59:46.000000000 -0700
@@ -0,0 +1,5 @@
+	.text
+	.global _start
+_start:
+	.byte 0,0,0,0,0,0,0,0
+	.byte 0,0,0,0,0,0,0,0
--- ld/testsuite/ld-scripts/empty-address-3a.d.empty	2006-09-23 14:12:51.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-3a.d	2006-09-23 14:08:07.000000000 -0700
@@ -0,0 +1,8 @@
+#source: empty-address-3.s
+#ld: -T empty-address-3a.t
+#nm: -n
+#...
+0+0 T _start
+#...
+0+10 A __data_end
+#pass
--- ld/testsuite/ld-scripts/empty-address-3a.t.empty	2006-09-23 14:12:51.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-3a.t	2006-09-23 14:10:43.000000000 -0700
@@ -0,0 +1,10 @@
+SECTIONS
+{
+  .text 0x00000000: { *(.text) }
+  .data ALIGN(0x1000) + (. & (0x1000 - 1)):
+  {
+    *(.data)
+  }
+  __data_end = .;
+  /DISCARD/ : { *(.*) }
+}
--- ld/testsuite/ld-scripts/empty-address-3b.d.empty	2006-09-23 14:12:51.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-3b.d	2006-09-23 14:04:58.000000000 -0700
@@ -0,0 +1,10 @@
+#source: empty-address-3.s
+#ld: -T empty-address-3b.t
+#nm: -n
+#...
+0+0 T _start
+#...
+0+10 A __data_end
+#...
+0+1010 A __data_start
+#pass
--- ld/testsuite/ld-scripts/empty-address-3b.t.empty	2006-09-23 14:12:51.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address-3b.t	2006-09-23 14:10:24.000000000 -0700
@@ -0,0 +1,11 @@
+SECTIONS
+{
+  .text 0x00000000: { *(.text) }
+  .data ALIGN(0x1000) + (. & (0x1000 - 1)):
+  {
+    __data_start = .;
+    *(.data)
+  }
+  __data_end = .;
+  /DISCARD/ : { *(.*) }
+}
--- ld/testsuite/ld-scripts/empty-address.exp.empty	2006-09-23 09:46:41.000000000 -0700
+++ ld/testsuite/ld-scripts/empty-address.exp	2006-09-23 14:02:52.000000000 -0700
@@ -0,0 +1,23 @@
+# 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
+run_dump_test empty-address-3a
+run_dump_test empty-address-3b


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]