This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/3223: ld fails to link correct variables from linker script
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Fri, 22 Sep 2006 18:09:29 -0700
- Subject: PATCH: PR ld/3223: ld fails to link correct variables from linker script
When an empty output section is ignored, we also ignore its address. I
think we should honor its address.
H.J.
---
ld/
2006-09-22 H.J. Lu <hongjiu.lu@intel.com>
PR ld/3223
* ldlang.c (lang_size_sections_1): Update "dot" for
ignored output sections if their addresses are set.
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-22 17:28:27.000000000 -0700
@@ -4461,7 +4461,10 @@ lang_size_sections_1
}
os->processed_lma = TRUE;
- if (bfd_is_abs_section (os->bfd_section) || os->ignored)
+ /* If address of output section is set, we update "dot"
+ even if it is ignored. */
+ if (bfd_is_abs_section (os->bfd_section)
+ || (os->ignored && !os->addr_tree))
break;
/* Keep track of normal sections using the default
@@ -4815,7 +4818,10 @@ 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 address of output section is set, we update "dot"
+ even if it is ignored. */
+ if (os->bfd_section != NULL
+ && (!os->ignored || os->addr_tree))
{
dot = os->bfd_section->vma;
--- 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