5

When I compile my program gcc -o myprog myprog.c, the produced binary is not stripped:

myprog: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically 
linked (uses shared libs), for GNU/Linux 2.6.26, 
BuildID[sha1]=0x2697ed96b65e8a11239af0a44abc7896954b6e20, not stripped

I am wondering why gcc produces non-stripped binaries by default, when I did not provide any debuging parameter.

Should all binaries be stripped after being compiled, i.e. using strip myprog? Or is there an advantage of having a binary non-stripped?

AFAICS, most binaries in /bin/, /usr/bin/ are stripped.

Martin Vegter
  • 136
  • 9
  • 32
  • 56
  • 1
    AFAIK on Linux stripping is usually done via `install` command – Anycorn May 18 '14 at 18:33
  • @Anycorn - in which situation would I use the `install` command? I have never heard about it up until now. – Martin Vegter May 18 '14 at 18:40
  • 1
    `install` is usually used to move files from build directory into its final destination, `/usr/bin`, `/bin`, etc. It has options to strip binary, set permissions, etc: http://linux.die.net/man/1/install – Anycorn May 18 '14 at 18:44
  • 1
    [Related](http://stackoverflow.com/questions/1349166/gcc-s-and-bash-command-strip). Symbols that gcc doesn't strip by default are not debugging information, they are relocation information (something that is needed for linking). – n. m. could be an AI May 18 '14 at 19:07
  • No need to strip them. IIUC: the loader ignores them, VM is you friend, and diskspace is for free. – wildplasser May 18 '14 at 23:33
  • Very valid concern and we usually assume that GCC would strip this information by default. – Zeeshan Aug 22 '16 at 07:26

1 Answers1

0

AFAIK Once the binary is stripped you wont be able to get the stripped information back until or unless you regenerate the binary. stripping is useful when you have memory constraints to look after. This might be the reason strip is not enabled by default in GCC.

neo
  • 969
  • 1
  • 11
  • 23
  • OK, but almost all binaries on my linux system are stripped. So why does gcc leave the extra symbols? – Martin Vegter May 18 '14 at 21:31
  • As you already knowing strip is useful to save space after a program has been debugged and to limit dynamically bound symbols. You may want to debug your program for possible errors. – neo May 19 '14 at 05:11
  • The extra symbol is useful while debugging the program. – neo May 19 '14 at 05:12