I have some compiled libraries i.e. shared library (*.so) on x86 Linux and I want to quickly determine whether they were compiled with debugging symbols (i.e with -g/debug option) or not.
How to check it?
Note that not stripped
doesn't imply debug symbols.
Library code:
//myshared.c
#include <stdio.h>
void print_from_lib()
{
printf("Printed from shared library\n");
}
Compiling with and without debug flags:
gcc -c -Wall -Werror -fpic myshared.c
gcc -shared -o libmyshared.so myshared.o
gcc -g -c -Wall -Werror -fpic myshared.c -o myshared-g.o
gcc -g -shared -o libmyshared-g.so myshared-g.o
Checking with file
$ file libmyshared.so
libmyshared.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=1ad3b94d5c8a7392c2140a647254753221a152cd, not stripped
$ file libmyshared-g.so
libmyshared-g.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0268eaf97e5a670d2f7e767a011be6f06a83090a, not stripped
Both claim they aren't stripped. However only libmyshared-g.so
shows the symbols:
$ objdump --syms libmyshared.so | grep debug
$ objdump --syms libmyshared-g.so | grep debug
0000000000000000 l d .debug_aranges 0000000000000000 .debug_aranges
0000000000000000 l d .debug_info 0000000000000000 .debug_info
0000000000000000 l d .debug_abbrev 0000000000000000 .debug_abbrev
0000000000000000 l d .debug_line 0000000000000000 .debug_line
0000000000000000 l d .debug_str 0000000000000000 .debug_str
You can use the file command to see if a file is stripped
. Basically, this means that the debugging symbols are there or not.
Here's one file from my system:
$ file libjsd.so
libjsd.so: ELF 32-bit LSB shared object, \
Intel 80386, version 1 (SYSV), dynamically linked,
stripped
Notice the stripped.
Here's something I compiled:
$ file libprofile_rt.so
libprofile_rt.so: ELF 64-bit LSB shared object, x86-64,
version 1 (SYSV), dynamically linked,
BuildID[sha1]=0x..., not stripped
see the 'not stripped', that indicates it has debugging symbols.
It's also possible to separate debug symbols from the shared object itself using objcopy. This would extract symbols in another file and then you'd need to know the link to get them back. You can see instructions for doing this with gdb using build-ids. This is helpful if you want to deliver something without the symbols but then be able to debug it in a pinch from a dump.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With