This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Fix ADDR(nosuchsection) crash
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: binutils at sources dot redhat dot com
- Date: Mon, 18 Dec 2006 11:12:16 +0000
- Subject: Fix ADDR(nosuchsection) crash
A linker script that uses ADDR(nosuchsection) can cause confusing errors and a
crash. The linker script in this patch for instance, produces:
nathan@kosh:116>m68k-elf/ld/ld-new -T 1150.ld 1150.o
m68k-elf/ld/ld-new: warning: cannot find entry symbol RAM; defaulting to 00000000
1150.o: In function `foo':
1150.c:(.text+0x6): undefined reference to `RAM'
m68k-elf/ld/ld-new: BFD 2.17.50 20061218 internal error, aborting at
../../src/bfd/elflink.c line 6991 in elf_link_output_extsym
m68k-elf/ld/ld-new: Please report this bug.
which is less than enlightening :) This patch changes fold-name to give an
error when ADDR, LOADADDR or SIZEOF are given a non-existant section name. Am I
correct in thinking that lang_output_section_find only returns non-null when the
section is not mentioned in the output script (it doesn't return NULL when the
section is not output). with this patch we get:
expr1.t:13: undefined section `ram' referenced in expression
tested on m68k-elf, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2006-12-18 Nathan Sidwell <nathan@codesourcery.com>
* ldexp.c (fold_name): Issue error on undefined sections.
* ld-scripts/expr.exp: New.
* ld-scripts/expr1.s: New.
* ld-scripts/expr1.d: New.
* ld-scripts/expr1.t: New.
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.63
diff -c -3 -p -r1.63 ldexp.c
*** ld/ldexp.c 23 Aug 2006 01:35:31 -0000 1.63
--- ld/ldexp.c 18 Dec 2006 11:04:37 -0000
*************** fold_name (etree_type *tree)
*** 563,569 ****
lang_output_section_statement_type *os;
os = lang_output_section_find (tree->name.name);
! if (os != NULL && os->processed_vma)
new_rel (0, NULL, os->bfd_section);
}
break;
--- 563,575 ----
lang_output_section_statement_type *os;
os = lang_output_section_find (tree->name.name);
! if (os == NULL)
! {
! if (expld.phase == lang_final_phase_enum)
! einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
! tree->name.name);
! }
! else if (os->processed_vma)
new_rel (0, NULL, os->bfd_section);
}
break;
*************** fold_name (etree_type *tree)
*** 574,580 ****
lang_output_section_statement_type *os;
os = lang_output_section_find (tree->name.name);
! if (os != NULL && os->processed_lma)
{
if (os->load_base == NULL)
new_abs (os->bfd_section->lma);
--- 580,592 ----
lang_output_section_statement_type *os;
os = lang_output_section_find (tree->name.name);
! if (os == NULL)
! {
! if (expld.phase == lang_final_phase_enum)
! einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
! tree->name.name);
! }
! else if (os->processed_lma)
{
if (os->load_base == NULL)
new_abs (os->bfd_section->lma);
*************** fold_name (etree_type *tree)
*** 592,598 ****
os = lang_output_section_find (tree->name.name);
if (os == NULL)
! new_abs (0);
else if (os->processed_vma)
new_abs (os->bfd_section->size / opb);
}
--- 604,615 ----
os = lang_output_section_find (tree->name.name);
if (os == NULL)
! {
! if (expld.phase == lang_final_phase_enum)
! einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
! tree->name.name);
! new_abs (0);
! }
else if (os->processed_vma)
new_abs (os->bfd_section->size / opb);
}
Index: ld/testsuite/ld-scripts/expr.exp
===================================================================
RCS file: ld/testsuite/ld-scripts/expr.exp
diff -N ld/testsuite/ld-scripts/expr.exp
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/expr.exp 18 Dec 2006 11:04:39 -0000
***************
*** 0 ****
--- 1,20 ----
+ # Test ALIGN in a linker script.
+ # By Nathan Sidwell, CodeSourcery LLC
+ # 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 expr1
Index: ld/testsuite/ld-scripts/expr1.d
===================================================================
RCS file: ld/testsuite/ld-scripts/expr1.d
diff -N ld/testsuite/ld-scripts/expr1.d
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/expr1.d 18 Dec 2006 11:04:39 -0000
***************
*** 0 ****
--- 1,2 ----
+ # ld: -T expr1.t
+ # error: undefined section .* in expression
Index: ld/testsuite/ld-scripts/expr1.s
===================================================================
RCS file: ld/testsuite/ld-scripts/expr1.s
diff -N ld/testsuite/ld-scripts/expr1.s
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/expr1.s 18 Dec 2006 11:04:39 -0000
***************
*** 0 ****
--- 1,2 ----
+ .word 0
+
Index: ld/testsuite/ld-scripts/expr1.t
===================================================================
RCS file: ld/testsuite/ld-scripts/expr1.t
diff -N ld/testsuite/ld-scripts/expr1.t
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/expr1.t 18 Dec 2006 11:04:39 -0000
***************
*** 0 ****
--- 1,12 ----
+ ENTRY(RAM)
+
+ MEMORY
+ {
+ ram (rwx) : ORIGIN = 0, LENGTH = 0x1000000
+ }
+
+ SECTIONS
+ {
+ .text : { } >ram
+ }
+ RAM = ADDR(ram);