From: "H. J. Lu" <hjl@lucon.org>
To: binutils@sources.redhat.com
Subject: PATCH: PR ld/3223: ld fails to link correct variables from linker script
Date: Sat, 23 Sep 2006 16:36:00 -0000 [thread overview]
Message-ID: <20060923010929.GA22529@lucon.org> (raw)
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
next reply other threads:[~2006-09-23 1:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-23 16:36 H. J. Lu [this message]
2006-09-24 0:08 ` H. J. Lu
2006-09-24 3:15 ` H. J. Lu
2006-09-26 12:43 ` Alan Modra
2006-09-26 13:57 ` H. J. Lu
2006-09-27 0:41 ` Alan Modra
2006-09-27 3:52 ` H. J. Lu
2006-09-27 4:07 ` Alan Modra
2006-09-27 9:46 ` H. J. Lu
2006-09-27 11:14 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060923010929.GA22529@lucon.org \
--to=hjl@lucon.org \
--cc=binutils@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).