How do I know if a given shared library is built using debugging symbols or not?

I have some compiled libraries, i.e. a shared library (e.g. * .so) on x86 Linux, and I want to quickly determine if they were compiled using debugging symbols (i.e. using the -g / debug build option) or not.

How to check it?

+6
source share
2 answers

You can use the file command to see if the file is stripped . This basically means that there are debugging symbols there or not.

Here is one file from my system:

 $ file libjsd.so libjsd.so: ELF 32-bit LSB shared object, \ Intel 80386, version 1 (SYSV), dynamically linked, stripped 

Pay attention to the separation.

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 "no strip" section, which indicates that it has debugging symbols.

You can also separate debugging symbols from the most common object using objcopy . This will extract the characters in another file, and then you will need to find out the link in order to return them. You can see instructions for doing this with gdb using build-ids. This is useful if you want to deliver something without characters, but then you can debug it as a last resort from a dump.

+10
source

Note that not stripped does not imply debugging characters.

Library Code:

 //myshared.c #include <stdio.h> void print_from_lib() { printf("Printed from shared library\n"); } 

Compilation with flag flags and without them:

 gcc -c -Wall -Werror -fpic myshared.c gcc -shared -o libmyshared.so myshared.o gcc -g -c -Wall -Werror -fpic myshared.c -o myshared-go gcc -g -shared -o libmyshared-g.so myshared-go 

Validation 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 that they are not without. However, only libmyshared-g.so shows the characters:

 $ objdump --syms libmyshared.so | grep debug $ objdump --syms libmyshared-g.so | grep debug 0000000000000000 ld .debug_aranges 0000000000000000 .debug_aranges 0000000000000000 ld .debug_info 0000000000000000 .debug_info 0000000000000000 ld .debug_abbrev 0000000000000000 .debug_abbrev 0000000000000000 ld .debug_line 0000000000000000 .debug_line 0000000000000000 ld .debug_str 0000000000000000 .debug_str 
+5
source

Source: https://habr.com/ru/post/958637/


All Articles