From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20051 invoked by alias); 23 Sep 2006 01:09:35 -0000 Received: (qmail 20043 invoked by uid 22791); 23 Sep 2006 01:09:35 -0000 X-Spam-Check-By: sourceware.org Received: from smtp106.sbc.mail.mud.yahoo.com (HELO smtp106.sbc.mail.mud.yahoo.com) (68.142.198.205) by sourceware.org (qpsmtpd/0.31) with SMTP; Sat, 23 Sep 2006 01:09:32 +0000 Received: (qmail 53664 invoked from network); 23 Sep 2006 01:09:30 -0000 Received: from unknown (HELO lucon.org) (hjjean@sbcglobal.net@71.146.100.252 with login) by smtp106.sbc.mail.mud.yahoo.com with SMTP; 23 Sep 2006 01:09:30 -0000 Received: by lucon.org (Postfix, from userid 500) id 580C1105B5; Fri, 22 Sep 2006 18:09:29 -0700 (PDT) Date: Sat, 23 Sep 2006 16:36:00 -0000 From: "H. J. Lu" To: binutils@sources.redhat.com Subject: PATCH: PR ld/3223: ld fails to link correct variables from linker script Message-ID: <20060923010929.GA22529@lucon.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-09/txt/msg00244.txt.bz2 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 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 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