get rid of debug-info in ELF-file

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

get rid of debug-info in ELF-file

Post 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
infj
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post 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.
"He was warned..."
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

You can also use the -s option on gcc's command line to strip those at link time.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

thanks very much, both of you
already thought that the final-elf will be smaller, but didnt expect that much: 120kB -> 46kB :)
infj
tjd
Posts: 23
Joined: Thu May 27, 2004 1:54 am
Location: Austin, TX
Contact:

Post 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
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Use -S to strip just the debug symbols. Lower case = all symbols, upper case = just debug symbols.
tjd
Posts: 23
Joined: Thu May 27, 2004 1:54 am
Location: Austin, TX
Contact:

Post 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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post 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)
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post 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.
"He was warned..."
tjd
Posts: 23
Joined: Thu May 27, 2004 1:54 am
Location: Austin, TX
Contact:

Post 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.
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

gcc manual wrote: -s Remove all symbol table and relocation information from the executable.
Shoot Pixels Not People!
Makeshift Development
blackdroid
Posts: 564
Joined: Sat Jan 17, 2004 10:22 am
Location: Sweden
Contact:

Post 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.
Kung VU
tjd
Posts: 23
Joined: Thu May 27, 2004 1:54 am
Location: Austin, TX
Contact:

Post 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)
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post 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.
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
tjd
Posts: 23
Joined: Thu May 27, 2004 1:54 am
Location: Austin, TX
Contact:

Post by tjd »

Well, thanks. But objcopy to a raw file and zip/unzip works nicely too ;-)
Post Reply