Page 1 of 1
get rid of debug-info in ELF-file
Posted: Sat Aug 14, 2004 6:08 am
by Saotome
could anyone tell my how to get rid of the debug-info in a compiled elf-file? - i mean the function-names/labels/symbols or whatever they are called - what you see, when you dissassemble it. what compiler flag to set or to remove?
thanks
Posted: Sat Aug 14, 2004 6:24 am
by mrbrown
ee-strip -o final-stripped.elf final.elf
If you don't need the symbols at all in the original ELF, you can omit the -o parameter.
Posted: Sat Aug 14, 2004 7:02 am
by pixel
You can also use the -s option on gcc's command line to strip those at link time.
Posted: Sat Aug 14, 2004 7:45 am
by Saotome
thanks very much, both of you
already thought that the final-elf will be smaller, but didnt expect that much: 120kB -> 46kB :)
Posted: Mon Sep 06, 2004 10:07 pm
by tjd
-s in a link strips all the symbols, not just the debug info. This may be what you want, but renders an "nm" quite useless and makes debugging harder. You might also ensure that you don't use -g. Failing that, if you run a "size -Ax" and see all those tasty "debug_*" sections, then you can always provide your own linker script and add a " * ( debug_* )" to the DISCARD pile.
Personally, for both the EE & IOP I always use -g (with -O0 or -O2 so as to not confuse gdb & me too much). I have two targets: one with a -s to produce the smallest executable possible which gets fed to the iron and the other leaving everything alone that I feed to gdb in order to debug. YMMV.
tjd
Posted: Tue Sep 07, 2004 7:13 am
by J.F.
Use -S to strip just the debug symbols. Lower case = all symbols, upper case = just debug symbols.
Posted: Thu Sep 09, 2004 10:26 pm
by tjd
strip -s -S
yeah, but it doesn't work with gcc-3.2.2 (loads of error messages and the resulting file is trash), but -s does work with gcc/g++/ld... Go figure.
Posted: Fri Sep 10, 2004 12:08 pm
by J.F.
Stripping is a linker function. If you are trying to strip from the gcc line, you have to use "-Wl,-s" or "-Wl,-S". This tells gcc to pass the -s or -S to the linker.
So your line in the makefile might be something like this:
gcc $@.o -o $@ -Wl,-s $(LIBS)
Posted: Fri Sep 10, 2004 5:08 pm
by mrbrown
Stripping is not just a linker function. The linker is never invoked when you do "gcc -s -c myfile.c -o foo.o". Technically, "gcc -s" and "gcc -Wl,-s" are too different things, but I'll let the GCC and binutils manuals sort that out for you :P.
Posted: Fri Sep 10, 2004 9:48 pm
by tjd
yes gcc -s and gcc -Wl,-s are "supposed" to be different. Indeed, when you wsant to look at the assembler code, gcc -s foo.c is a good thing.
But (isn't there always one?). 'Splain this:
Code: Select all
[broadq@mcv-1-1-1 poweroff]$ make
ps2-gcc -o poweroff.irx -s -G0 -g -miop -nostdlib -nostartfiles test.iop.o poweroff.iop.o scmd.iop.o vblank_poweroff.iop.o mediostub.iop.o -L/home/broadq/src/ps2lib-2.1/iop/lib -lkernel -lgcc
ps2-gcc -o poweroff.full.irx -G0 -g -miop -nostdlib -nostartfiles test.iop.o poweroff.iop.o scmd.iop.o vblank_poweroff.iop.o mediostub.iop.o -L/home/broadq/src/ps2lib-2.1/iop/lib -lkernel -lgcc
[broadq@mcv-1-1-1 poweroff]$ file *irx
poweroff.full.irx: ELF 32-bit LSB mips-1 processor-specific, MIPS R3000_LE [bfd bug], version 1 MathCoPro/FPU/MAU Required (SYSV), not stripped
poweroff.irx: ELF 32-bit LSB mips-1 processor-specific, MIPS R3000_LE [bfd bug], version 1 MathCoPro/FPU/MAU Required (SYSV), stripped
[broadq@mcv-1-1-1 poweroff]$
Looks stripped to me. Anyway, there seems to be a difference in the way things are operating if invoked as part of the link phase, vs. a strip.
Posted: Fri Sep 10, 2004 10:07 pm
by Drakonite
gcc manual wrote:
-s Remove all symbol table and relocation information from the executable.
Posted: Sat Sep 11, 2004 1:06 am
by blackdroid
[quote="tjd"]yes gcc -s and gcc -Wl,-s are "supposed" to be different. Indeed, when you wsant to look at the assembler code, gcc -s foo.c is a good thing.
[/code]
I suppose you meant
-S Stop after the stage of compilation proper; do not assemble. The output is
an assembler code file for each non-assembler input file specified.
Posted: Sat Sep 11, 2004 1:14 am
by tjd
yes, -S is what my fingers should have typed... It's been a long night. But we all digress. My point a while back is that an IRX produced from "gcc -s ..." and "strip ..." do not appear to create the same file. The results of the "strip" are garbage. (all this from gcc-3.2.2 and binutils 2.14)
Posted: Sat Sep 11, 2004 3:05 am
by pixel
Anyway, if you REALLY want very strict stripping code, then, look at ps2-packer and sjuncrunch code. The idea would be to load all the PT_LOAD sections (just what ps2-packer does), and write a new ELF with only program header sections (just what sjuncrunch does). You can also change the writer part by shorting up the header size. The default 0x1000 bytes is a bit too much, and it can be reduced to something much smaller.
Posted: Sat Sep 11, 2004 11:17 pm
by tjd
Well, thanks. But objcopy to a raw file and zip/unzip works nicely too ;-)