ack icon indicating copy to clipboard operation
ack copied to clipboard

[FAQ?] asize, astrip ... bad format

Open drawkula opened this issue 5 years ago • 3 comments

$ ls -l mandelbrot-s4p12.c
-rw-r--r-- 1 yeti yeti 887 Jun 21 15:08 mandelbrot-s4p12.c
$ ack -mlinux386 -O4 mandelbrot-s4p12.c -o mandelbrot-s4p12
"mandelbrot-s4p12.c", line 24: (warning) 'main' old-fashioned function definition
$ asize mandelbrot-s4p12
asize: mandelbrot-s4p12-- bad format
$ size mandelbrot-s4p12
   text    data     bss     dec     hex filename
   2200     176     144    2520     9d8 mandelbrot-s4p12
$ astrip mandelbrot-s4p12
astrip: mandelbrot-s4p12-- bad format
$ file mandelbrot-s4p12
mandelbrot-s4p12: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, not stripped
$ strip mandelbrot-s4p12
$ file mandelbrot-s4p12
mandelbrot-s4p12: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, stripped

How can I use asize and astrip correctly? Or is using the GNUish variants indeed the right way to go?

drawkula avatar Jun 21 '19 15:06 drawkula

asize and astrip only work on object files, rather than on the linker output files. So you'll need to strip all your object files one at a time before linking. It's possible to tell the linker to strip the resulting file but it looks like the ack driver doesn't have a way to pass that flag on to the linker --- that's worth having.

davidgiven avatar Jun 21 '19 22:06 davidgiven

but it looks like the ack driver doesn't have a way to pass that flag on to the linker --- that's worth having.

I indeed looked into the man page for it... ;-)

Thanks for the fast answer!

drawkula avatar Jun 21 '19 22:06 drawkula

Use ack -Rled-s to tell the linker to strip the symbols.

$ ack -mlinux386 -O4 example.c -Rled-s -o example 
$ file example
example: ELF 32-bit LSB executable, Intel 80386, version 1
$ nm example
nm: example: no section header table

Tools like anm, asize, astrip only work ack.out(5) files, which are *.o before linking, or *.out after linking. If you use ack -c.out to stop the conversion to ELF, you can use the tools.

$ ack -mlinux386 -O4 example.c -c.out -o example.out
$ anm -n example.out
      16  A  - EINVAL
 8048054  0  S (NULL)
 8048054  0  - begtext
...
$ asize example.out
224+0+4+144 = 372 = 0x174
$ astrip example.out
$ ack -mlinux386 example.out -o example
$ file example
example: ELF 32-bit LSB executable, Intel 80386, version 1
$ nm example
nm: example: no section header table

kernigh avatar Aug 29 '19 15:08 kernigh