Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a stripped binary is produced with binutils-2.14 #4

Open
sezero opened this issue Aug 20, 2017 · 12 comments
Open

a stripped binary is produced with binutils-2.14 #4

sezero opened this issue Aug 20, 2017 · 12 comments

Comments

@sezero
Copy link

sezero commented Aug 20, 2017

As the title says. And no, I don't use -s on the gcc link command line.

This doesn't happen with binutils-2.9.1.

@cahirwpz
Copy link
Member

I cannot reproduce the problem. Without -s flag the file should contain information about symbols and in fact it does:

/* test.c */
int a;
char *str = "universe";

int foobar() {
  return 42;
}

int main() {
  return foobar();
}
# m68k-amigaos-gcc -mcrt=nix -Wl,-v -O2 -o test test.c
collect2 version 2.95.3 20010315 (release) (68k, MIT syntax)
/Users/cahir/Amiga/m68k-amigaos/bin/ld -L/Users/cahir/Amiga/m68k-amigaos/libnix/lib -fl libnix -o test /Users/cahir/Amiga/m68k-amigaos/libnix/lib/libnix/ncrt0.o -L/Users/cahir/Amiga/lib/gcc-lib/m68k-amigaos/2.95.3 -L/Users/cahir/Amiga/m68k-amigaos/lib -v /var/folders/9h/n58bx40n61b5jvxs1clytv140000gn/T/ccKgxXxb.o -lnixmain -lnix -lnix -lamiga -lstubs -lgcc -lnix -lnix
GNU ld version 2.14 20030612 (adtools build 20080628)
# m68k-amigaos-nm test
...
00000028 B _a
000000d6 T _foobar
000000ca T _geta4
000000e0 T _main
0000005c D _str

When I repeat the whole experiment with -s flag the file is indeed stripped:

# m68k-amigaos-gcc -mcrt=nix -O2 -s -o test test.c
# m68k-amigaos-nm test
m68k-amigaos-nm: test: no symbols

@sezero
Copy link
Author

sezero commented Aug 21, 2017

The file lengths of original binary and the output from strip -S
are the same for me, which is 2808 bytes for the above test case.
With binutils-2.9.1, it is 5172 bytes before strip, and 2080 bytes
after strip -S.

@cahirwpz
Copy link
Member

That's correct and expected behaviour in case of capital -S vs. small -s option. It does strip debug info but not symbol table:

# m68k-amigaos-gcc -mcrt=nix -O2 -g -o test test.c
# ls -l test
...  5964 ...
# m68k-amigaos-strip -S test
# ls -l test
...  2808 ...
# m68k-amigaos-strip -s test
# ls -l test
... 1984 ...

@sezero
Copy link
Author

sezero commented Aug 21, 2017

is it expected behavior to discard the debug info without -s on the
gcc link command line?

@cahirwpz
Copy link
Member

cahirwpz commented Aug 21, 2017

AFAIK it's expected behaviour for gcc not to generate debug information without explicit request with -g option. According to gcc documentation chapter Options for Debugging Your Program:

-g Produce debugging information in the operating system's native format.

In our case it's STABS format.

EDIT: I might have misunderstood your last question.

@sezero
Copy link
Author

sezero commented Aug 21, 2017

... without explicit request with -g ...

Yes yes, I do generate by objects with -g, and linkage keeps discarding the dgb info.

@cahirwpz
Copy link
Member

I checked the behaviour with Linux box:

# gcc -g -c -o test.o test.c
# gcc -o test.1 test.o
# gcc -g -o test.2 test.o

Both files test.1 and test.2 are the same.

And repeated the expriment with m68k-amigaos toolchain:

# m68k-amigaos-gcc -mcrt=nix -O2 -g -c -o test.o test.c
# m68k-amigaos-gcc -mcrt=nix -O2 -g -o test.1 test.o
# m68k-amigaos-gcc -mcrt=nix -O2 -o test.2 test.o

Indeed file test.2 was stripped of debug information.

So finally, we have a clear problem statement ;-)

@sezero
Copy link
Author

sezero commented Aug 21, 2017

OK :)

@cahirwpz
Copy link
Member

cahirwpz commented Aug 21, 2017

Let's have a look at what gcc compiler driver does when test.1 and test.2 are produced:

m68k-amigaos-gcc -mcrt=nix -O2 -Wl,-v -o test.1 test.o

/Users/cahir/Amiga/m68k-amigaos/bin/ld -L/Users/cahir/Amiga/m68k-amigaos/libnix/lib
-fl libnix -o test.1 /Users/cahir/Amiga/m68k-amigaos/libnix/lib/libnix/ncrt0.o
-L/Users/cahir/Amiga/lib/gcc-lib/m68k-amigaos/2.95.3
-L/Users/cahir/Amiga/m68k-amigaos/lib
-v test.o -lnixmain -lnix -lnix -lamiga -lstubs -lgcc -lnix -lnix

m68k-amigaos-gcc -mcrt=nix -O2 -Wl,-v -g -o test.2 test.o

/Users/cahir/Amiga/m68k-amigaos/bin/ld -L/Users/cahir/Amiga/m68k-amigaos/libnix/lib
-fl libnix -amiga-debug-hunk -o test.2 /Users/cahir/Amiga/m68k-amigaos/libnix/lib/libnix/ncrt0.o
-L/Users/cahir/Amiga/lib/gcc-lib/m68k-amigaos/2.95.3
-L/Users/cahir/Amiga/m68k-amigaos/lib
-v test.o -lnixmain -lnix -lnix -lamiga -lstubs -lgcc -lnix -lnix

So apparently there's a difference how -amiga-debug-hunk option is handled by ld in 2.9.1 and 2.14.

@sezero Could you investigate that?

EDIT: What is -amiga-debug-hunk option supposed to do?

@sezero
Copy link
Author

sezero commented Aug 21, 2017

Ok, -amiga-debug-hunk sets write_debug_hunk to 1.

ld/emultempl/amiga.em, parse_args():

    case OPTION_AMIGA_DEBUG:
      write_debug_hunk=1; /* Write out debug hunk */
      break;

2.9.1, bfd/amigaoslink.c:

int write_debug_hunk = 0;

Note that this is 1 instead of 0 in 2.14,
but its amiga.em:before_parse() sets it to 0,
so no difference there.

2.9.1, bfd/amigaos.c, amiga_write_object_contents():

  if (amiga_data->IsLoadFile /* && write_debug_hunk */ )

However, in 2.14, the write_debug_hunk check is NOT
commented out: that's the reason 2.14 discards the
debug info when run gcc is without -g for linkage..

@sezero
Copy link
Author

sezero commented Aug 21, 2017

Seems like that change happened with commit d6af3b0 (2006, 16 Mar.)

@sezero
Copy link
Author

sezero commented Aug 29, 2017

PING ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants