Best way to strip off symbols

21,854

Solution 1

With Visual C++ (and other Microsoft compilers) on Windows, symbols aren't part of the binaries. Instead, they are stored in separate files called "Program Database" files (.pdb files). Just don't provide the .pdb files.

With the GNU toolchain you would use strip to remove symbols from the binaries.

Solution 2

For the GNU toolchain, there exists a cool sleight of hand:

objcopy --only-keep-debug yourprogram ../somepath/yourprogram.dbg
strip yourprogram
objcopy --add-gnu-debuglink=../somepath/yourprogram.dbg yourprogram

Now you can zip the folder your program is in (or pack it into an installer or whatever), there will be no more debug symbols in it.
BUT : If you launch the debugger or if you run a tool like addr2line or obdump, the tool will (thanks to the debuglink info) automagically know where to find the symbols and load them.

Which is awesome, because it means you have the benefits of having symbols on your end, without distributing them to the user.

Share:
21,854
Alphaneo
Author by

Alphaneo

An electrical engineer, who is a programmer by profession

Updated on May 05, 2020

Comments

  • Alphaneo
    Alphaneo about 4 years

    Last week I released the Linux and windows version of an application.

    And after the release we realized that the symbols were not stripped off, and my manager thinks (and I disagree) that it might allow the user to understand our algorithm.

    Anyway, now, I will have to clean-up the symbols and re-release the application.

    My question,

    1. What is the best way to strip symbols in Linux?
    2. What is the best way to strip symbols in Windows?