public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ld (bfd?) bug: unmatched excluded include in stabs
@ 2003-11-17 18:14 Mattias Engdegård
  2003-11-18 14:55 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Mattias Engdegård @ 2003-11-17 18:14 UTC (permalink / raw)
  To: binutils, bug-binutils

It seems that recent binutils (at least 2.14, but not 2.13) merge
repeated include-file stabs when linking partially. When these partial
linked objects then are linked again, this can cause the generation of
excluded stabs that do not refer to any include file stab. I found
this when linking the Linux kernel.

For instance, consider the following files:

alfa.c:
 #include "alfa.h"
alfa.h:
 #include "beta.h"
 #include "gamma.h"
beta.h:
 struct A { int a; }
gamma.h:
 struct B { float b; }
gamma.c:
 #include "gamma.h"

Then gamma.o will have the stabs

  BINCL gamma.h
   LSYM (definition of B)
  EINCL

and alfa.o will contain the stabs

  BINCL alfa.h
   BINCL beta.h
    LSYM (definition of A)
   EINCL
   BINCL gamma.h
    LSYM (definition of B)
   EINCL
  EINCL

When partially linked together (-r), ld will compute checksums to BINCL stabs
and replace some BINCL/EINCL pairs by matching EXCL stabs:

  BINCL gamma.h (with a nonzero checksum)
   LSYM (definition of B)
  EINCL
  BINCL alfa.h  (with checksum == 0)
   BINCL beta.h
    LSYM (definition of A)
   EINCL
   EXCL gamma.h  (with a checksum that matches that of BINCL gamma.h)
  EINCL

The alfa.h checksum is zero, because there are no non-nested stabs there
(the EXCL stab is added afterwards).

Now consider another object file that includes alfa.h. Its stabs will be
roughly equal to those of alfa.o above. When this is linked to the partial
link, the resulting BINCL of alfa.h will have checksum != 0 (since this
time the EXCL gamma.h contributes), but the use will have checksum == 0.

Thus a debugger sees, in the final executable

  BINCL alfa.h, checksum != 0
  ...
  EXCL  alfa.h, checksum == 0

and won't be able to match them. GDB complains about this, if complaints
are turned on.

I have a testcase for this, which I could wrap up if someone is interested.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ld (bfd?) bug: unmatched excluded include in stabs
  2003-11-17 18:14 ld (bfd?) bug: unmatched excluded include in stabs Mattias Engdegård
@ 2003-11-18 14:55 ` Nick Clifton
  2003-11-18 15:26   ` Mattias Engdegård
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2003-11-18 14:55 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: binutils, bug-binutils

Hi Mattias,

> Now consider another object file that includes alfa.h. Its stabs will be
> roughly equal to those of alfa.o above. When this is linked to the partial
> link, the resulting BINCL of alfa.h will have checksum != 0 (since this
> time the EXCL gamma.h contributes), but the use will have checksum == 0.

Not being an expert on STABS, I am not sure if the following question
makes any sense, but I will ask it anyway:  Is this the correct
behaviour for the linker, or should it be ignoring the EXCL gamma.h
when computing the checksum for the BINCL of alfa.h ?


> I have a testcase for this, which I could wrap up if someone is
> interested.

Yes - please send the testcase to the list.  (I assume that it is a
*small* testcase ? :-)

Cheers
        Nick
        

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ld (bfd?) bug: unmatched excluded include in stabs
  2003-11-18 14:55 ` Nick Clifton
@ 2003-11-18 15:26   ` Mattias Engdegård
  2003-11-25 12:00     ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Mattias Engdegård @ 2003-11-18 15:26 UTC (permalink / raw)
  To: nickc; +Cc: binutils, bug-binutils

>Not being an expert on STABS, I am not sure if the following question
>makes any sense, but I will ask it anyway:  Is this the correct
>behaviour for the linker, or should it be ignoring the EXCL gamma.h
>when computing the checksum for the BINCL of alfa.h ?

I think ignoring EXCLs when computing checksums makes sense, since
that would give the same behaviour as if the EXCL were replaced by the
equivalent BINCL ... EINCL sequence.

The correct behaviour is largely defined by Sun's linker, but it does
not elide duplicated includes when doing partial links anyway.

>Yes - please send the testcase to the list.  (I assume that it is a
>*small* testcase ? :-)

It's small. ftp://ptah.lnf.kth.se/pub/misc/bug.tar.gz

Here is the proposed patch, which seems to cure it:

--- binutils-031118/bfd/stabs.c~        Tue Nov  4 12:30:54 2003
+++ binutils-031118/bfd/stabs.c Tue Nov 18 16:24:01 2003
@@ -358,6 +358,8 @@
              incl_type = incl_sym[TYPEOFF];
              if (incl_type == 0)
                break;
+             else if (incl_type == (int) N_EXCL)
+                continue;
              else if (incl_type == (int) N_EINCL)
                {
                  if (nest == 0)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ld (bfd?) bug: unmatched excluded include in stabs
  2003-11-18 15:26   ` Mattias Engdegård
@ 2003-11-25 12:00     ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2003-11-25 12:00 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: binutils, bug-binutils

Hi Mattias,

> Here is the proposed patch, which seems to cure it:
>
> --- binutils-031118/bfd/stabs.c~        Tue Nov  4 12:30:54 2003
> +++ binutils-031118/bfd/stabs.c Tue Nov 18 16:24:01 2003
> @@ -358,6 +358,8 @@
>               incl_type = incl_sym[TYPEOFF];
>               if (incl_type == 0)
>                 break;
> +             else if (incl_type == (int) N_EXCL)
> +                continue;
>               else if (incl_type == (int) N_EINCL)
>                 {
>                   if (nest == 0)

Thanks very much.  This patch is quite reasonable, so I have applied
it together with this ChangeLog entry:

  2003-11-25  Mattias Engdegard  <mattias@virtutech.se>

	* stabs.c (_bfd_link_section_stabs): Skip N_EXCL stabs when
	processing N_BINCL stabs.

Cheers
        Nick
        

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-11-25 12:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-17 18:14 ld (bfd?) bug: unmatched excluded include in stabs Mattias Engdegård
2003-11-18 14:55 ` Nick Clifton
2003-11-18 15:26   ` Mattias Engdegård
2003-11-25 12:00     ` Nick Clifton

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).