简体   繁体   中英

gcc -O2 is smaller then gcc -O2 -g followed by strip --strip-all

I am building code that I want to produce release versions. However I also want to be able to debug cores if they crash.

So I read that building with debug symbols can be used followed by producing a copy of the binary that you run strip on. Then you can take the core produced by the stripped binary (the released/customer binary) and then gdb this against your copy of the binary with debug symbols...

So step one for me was to generate the binary, I do:

  • gcc -O2 ... -o testbin_release_orig (original release bin without symbols)
  • gcc -O2 -g ... -o testbin_debug (full debug binary)
  • cp testbin_debug testbin_release
  • strip --strip-all testbin_release (stripped debug binary)

This produces three files with different sizes:

  • testbin_release_orig: ~1.7Mb
  • testbin_debug: ~13Mb
  • testbin_release: ~2.1Mb

My question is, why is testbin_release not exactly the same size as testbin_release_orig ? I am guessing that strip can't strip all the debug symbols that gcc adds. But there is about 0.4Mb of "extra stuff" - what does that consist of?

The difference is from the debug code.

For an 1.7 MB executable you are probably using a library or two. Usually they have something like:

#ifdef _DEBUG
    // some debug code
#endif

Also common practice for big projects, so some of it may be your code as well.

strip removes only the symbols. The debug code stays.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM