[RFA:] Fix rarely exercised bug in bfd/aoutx.h find_nearest_line
Hans-Peter Nilsson
hans-peter.nilsson@axis.com
Sun Feb 6 14:46:00 GMT 2005
Building a cris-aout tool, and test-compiling "hello, world",
gave linker SEGV:s instead of the friendly warnings (from
libgloss/libnosys/warning.h) and an executable as cris-elf does.
Running the linker under valgrind showed a few invalid accesses.
A gdb session confirmed that the SEGV:d accesses were from the
a.out find_nearest_line support, trying to emit an "reference to
undefined symbol" error. Setting the reason for the undefined
reference aside, apparently GCC emits a stabs file-name
construct that's supposed to consist of two parts, but it looks
like there's an optional end part that's just a terminator. The
BFD support looks like it should handle end-of-symbols for that
case, except the code is wrong: "break" just breaks out of the
"switch", not out of the "for" and since the NULL terminator was
just stepped over, the loop continues with invalid accesses
until some spurious NULL is found or SEGV (SEGV for me with this
particular test; YMMV). There's a label after the for-loop, so
the right thing seems to be to go to it.
For test-case, perhaps an ld-aout section should be warranted,
but then there'd be a new directory and something to identify
a.out target (or options to emit it) so I just stick to putting
the tests in the ld-cris section. I hope that's ok; it's not
like a.out is a common critical object format (anymore). If you
prefer, I can make an ld-aout directory and all that's needed it
to move the test-cases there (they should be fairly
target-independent). The undef3 test is just for comparison
with ELF; it works even without this patch of course.
Ok for the aoutx.h part (below)?
ld/testsuite:
* ld-cris/stabs1.s: New file.
* ld-cris/undef2.d, ld-cris/undef3.d: New tests.
--- /dev/null Tue Oct 29 15:57:07 2002
+++ ld-cris/stabs1.s Fri Feb 4 01:42:38 2005
@@ -0,0 +1,26 @@
+ .stabs "/x/y/z/",100,0,2,Ltext0
+ .stabs "/blah/foo.c",100,0,2,Ltext0
+ .text
+Ltext0:
+ .global _xyzzy
+ .type _xyzzy, @function
+_xyzzy:
+ .stabd 46,0,0
+ .stabn 68,0,95,LM16-_xyzzy
+LM16:
+ .long 0
+ .stabn 68,0,96,LM17-_xyzzy
+LM17:
+ .long globsym1
+ .stabn 68,0,88,LM25-_xyzzy
+LM25:
+ .long 0
+ .size _xyzzy, .-_xyzzy
+ .stabn 192,0,0,_xyzzy-_xyzzy
+ .stabn 224,0,0,Lscope0-_xyzzy
+Lscope0:
+;# This is the stabs construct that was barfed upon; BFD for
+;# a.out expects it to be of two parts, like the construct at
+;# the top of this file.
+ .stabs "",100,0,0,Letext0
+Letext0:
--- /dev/null Tue Oct 29 15:57:07 2002
+++ ld-cris/undef2.d Fri Feb 4 01:25:57 2005
@@ -0,0 +1,6 @@
+# source: start1.s
+# source: stabs1.s
+# target: cris-*-*elf* cris-*-*aout*
+# as: --em=crisaout
+# ld: -mcrisaout
+# error: .o:/blah/foo.c:96: undefined reference to `globsym1'$
--- /dev/null Tue Oct 29 15:57:07 2002
+++ ld-cris/undef3.d Fri Feb 4 01:26:04 2005
@@ -0,0 +1,6 @@
+#source: start1.s
+#source: stabs1.s
+#target: cris-*-*elf* cris-*-*aout*
+#as: --em=criself
+#ld: -mcriself
+#error: .o:/blah/foo.c:96: undefined reference to `globsym1'$
bfd:
* aoutx.h (NAME(aout,find_nearest_line)): Correct case for N_SO
being the last symbol.
--- aoutx.h.original Tue Feb 1 00:15:35 2005
+++ aoutx.h Fri Feb 4 02:00:23 2005
@@ -2748,7 +2748,7 @@ NAME(aout,find_nearest_line)
/* Look ahead to next symbol to check if that too is an N_SO. */
p++;
if (*p == NULL)
- break;
+ goto done;
q = (aout_symbol_type *) (*p);
if (q->type != (int)N_SO)
goto next;
brgds, H-P
More information about the Binutils
mailing list