bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stabs, incremental linking, gdb crash


From: Felix Lee
Subject: stabs, incremental linking, gdb crash
Date: Thu, 26 Feb 2004 03:14:21 -0800

this is related to
    http://sources.redhat.com/ml/binutils/2003-11/msg00413.html

say you have an incrementally linked object with these stabs:

    BINCL x.h
    EINCL
    BINCL a.h
      EXCL x.h
    EINCL
    BINCL b.h
      LSYM b_t:t(4,1)=...
    EINCL

if you link it after another object with a.h,
then current binutils will turn those stabs into

    EXCL x.h
    EXCL a.h
    BINCL b.h
      LSYM b_t:t(4,1)=...
    EINCL

which means the file numbers in the LSYM are now wrong,
which means gdb gets very confused, sometimes crashes.

the linker has to preserve any nested EXCLs when replacing a
BINCL with an EXCL.

patch below was tested on x86 redhat 9.
I think the testcase is machine independent, but I haven't checked.

bfd/ChangeLog
2004-02-25  Felix Lee  <address@hidden>

        * stabs.c (_bfd_link_section_stabs): Never delete N_EXCL stabs.

ld/testsuite/ChangeLog
2004-02-26  Felix Lee  <address@hidden>

        * ld-stabs/excl1.d: New test.
        * ld-stabs/excl1a.s: New.
        * ld-stabs/excl1b.s: New.
        * ld-stabs/stabs.exp: New driver.

diff -u -p -r1.15 stabs.c
--- bfd/stabs.c 25 Nov 2003 11:59:57 -0000      1.15
+++ bfd/stabs.c 26 Feb 2004 10:54:24 -0000
@@ -456,6 +456,8 @@ _bfd_link_section_stabs (abfd, psinfo, s
                    }
                  else if (incl_type == (int) N_BINCL)
                    ++nest;
+                  else if (incl_type == (int) N_EXCL)
+                    continue;
                  else if (nest == 0)
                    {
                      *incl_pstridx = (bfd_size_type) -1;

diff -urN /dev/null ld/testsuite/ld-stabs/excl1.d
--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ ld/testsuite/ld-stabs/excl1.d       2004-02-26 02:13:13.000000000 -0800
@@ -0,0 +1,44 @@
+#objdump: -G
+#ld: -r
+#source: excl1a.s
+#source: excl1b.s
+
+# This checks EXCL substitution when linking incrementally.
+
+#...
+0      SO     0      0      00000000 70     a1
+1      BINCL  0      0      00000667 70     a1
+2      LSYM   0      0      00000000 73     char:t\(0,1\)=r\(0,1\);0;255;
+3      BINCL  0      0      000003c3 99     x1
+4      LSYM   0      0      00000000 102    x1_t:t\(2,1\)=\(0,1\)
+5      EINCL  0      0      00000000 0 *
+6      BINCL  0      0      00000000 120    x2
+7      EXCL   0      0      000003c3 99     x1
+8      EINCL  0      0      00000000 0 *
+9      BINCL  0      0      000003f3 123    ax
+10     LSYM   0      0      00000000 126    ax_t:t\(5,1\)=\(0,1\)
+11     EINCL  0      0      00000000 0 *
+12     SO     0      0      00000000 0 *
+13     SO     0      0      00000000 144    a2
+14     BINCL  0      0      000005d4 144    a2
+15     LSYM   0      0      00000000 73     char:t\(0,1\)=r\(0,1\);0;255;
+16     EXCL   0      0      00000000 120    x2
+17     EXCL   0      0      000003c3 99     x1
+18     SO     0      0      00000000 0 *
+19     SO     0      0      00000000 147    b1
+20     BINCL  0      0      00000668 147    b1
+21     LSYM   0      0      00000000 73     char:t\(0,1\)=r\(0,1\);0;255;
+22     EXCL   0      0      000003c3 99     x1
+23     EXCL   0      0      00000000 120    x2
+24     EXCL   0      0      000003c3 99     x1
+25     BINCL  0      0      000003f4 150    bx
+26     LSYM   0      0      00000000 153    bx_t:t\(5,1\)=\(0,1\)
+27     EINCL  0      0      00000000 0 *
+28     SO     0      0      00000000 0 *
+29     SO     0      0      00000000 171    b2
+30     BINCL  0      0      000005d4 171    b2
+31     LSYM   0      0      00000000 73     char:t\(0,1\)=r\(0,1\);0;255;
+32     EXCL   0      0      00000000 120    x2
+33     EXCL   0      0      000003c3 99     x1
+34     SO     0      0      00000000 0 *
+
diff -urN /dev/null ld/testsuite/ld-stabs/excl1a.s
--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ ld/testsuite/ld-stabs/excl1a.s      2004-02-26 02:45:14.000000000 -0800
@@ -0,0 +1,36 @@
+        /* simulate stabs for incrementally linked obj */
+
+        .set    N_SO,       0x64
+        .set    N_BINCL,    0x82
+        .set    N_LSYM,     0x80
+        .set    N_EINCL,    0xa2
+        .set    N_EXCL,     0xc2
+
+        /* this has to be updated manually */
+        .set    X1_SUM,     0x03c3
+        .set    X2_SUM,     0x0000
+
+        .stabs  "a1",N_SO,0,0,0
+        .stabs  "a1",N_BINCL,0,0,0
+        .stabs      "char:t(0,1)=r(0,1);0;255;",N_LSYM,0,0,0
+
+        .stabs      "x1",N_BINCL,0,0,0
+        .stabs          "x1_t:t(2,1)=(0,1)",N_LSYM,0,0,0
+        .stabn      N_EINCL,0,0,0
+
+        .stabs      "x2",N_BINCL,0,0,0
+        .stabs          "x1",N_EXCL,0,0,X1_SUM
+        .stabn      N_EINCL,0,0,0
+
+        .stabs      "ax",N_BINCL,0,0,0
+        .stabs          "ax_t:t(5,1)=(0,1)",N_LSYM,0,0,0
+        .stabn      N_EINCL,0,0,0
+        .stabn  N_SO,0,0,0
+
+        .stabs  "a2",N_SO,0,0,0
+        .stabs  "a2",N_BINCL,0,0,0
+        .stabs      "char:t(0,1)=r(0,1);0;255;",N_LSYM,0,0,0
+
+        .stabs      "x2",N_EXCL,0,0,X2_SUM
+        .stabs      "x1",N_EXCL,0,0,X1_SUM
+        .stabn  N_SO,0,0,0
diff -urN /dev/null ld/testsuite/ld-stabs/excl1b.s
--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ ld/testsuite/ld-stabs/excl1b.s      2004-02-26 02:45:01.000000000 -0800
@@ -0,0 +1,36 @@
+        /* simulate stabs for incrementally linked obj */
+
+        .set    N_SO,       0x64
+        .set    N_BINCL,    0x82
+        .set    N_LSYM,     0x80
+        .set    N_EINCL,    0xa2
+        .set    N_EXCL,     0xc2
+
+        /* this has to be updated manually */
+        .set    X1_SUM,     0x03c3
+        .set    X2_SUM,     0x0000
+
+        .stabs  "b1",N_SO,0,0,0
+        .stabs  "b1",N_BINCL,0,0,0
+        .stabs      "char:t(0,1)=r(0,1);0;255;",N_LSYM,0,0,0
+
+        .stabs      "x1",N_BINCL,0,0,0
+        .stabs          "x1_t:t(2,1)=(0,1)",N_LSYM,0,0,0
+        .stabn      N_EINCL,0,0,0
+
+        .stabs      "x2",N_BINCL,0,0,0
+        .stabs          "x1",N_EXCL,0,0,X1_SUM
+        .stabn      N_EINCL,0,0,0
+
+        .stabs      "bx",N_BINCL,0,0,0
+        .stabs          "bx_t:t(5,1)=(0,1)",N_LSYM,0,0,0
+        .stabn      N_EINCL,0,0,0
+        .stabn  N_SO,0,0,0
+
+        .stabs  "b2",N_SO,0,0,0
+        .stabs  "b2",N_BINCL,0,0,0
+        .stabs      "char:t(0,1)=r(0,1);0;255;",N_LSYM,0,0,0
+
+        .stabs      "x2",N_EXCL,0,0,X2_SUM
+        .stabs      "x1",N_EXCL,0,0,X1_SUM
+        .stabn  N_SO,0,0,0
diff -urN /dev/null ld/testsuite/ld-stabs/stabs.exp
--- /dev/null   1969-12-31 16:00:00.000000000 -0800
+++ ld/testsuite/ld-stabs/stabs.exp     2004-02-25 23:09:28.000000000 -0800
@@ -0,0 +1,24 @@
+# Expect script for LD stabs tests.
+#   Copyright 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+foreach t $test_list {
+  set t [file rootname $t]
+  verbose $t
+  run_dump_test $t
+}
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]