ยง2024-12-03
Summary of Differences
Feature | --strip-all | --strip-debug |
---|---|---|
Symbols Removed | Removes all symbols, including the symbol table. | Removes only debugging symbols (e.g., file names, line numbers). |
Debugging Information | Removed (including symbol table, debugging data, etc.). | Removed (e.g., gdb info), but keeps the symbol table and relocation data. |
Use Case | Reduce the binary to a minimal size with no debugging or symbol information. | Remove debugging info but keep symbols needed for dynamic linking or symbol resolution. |
Impact on Linker/Debugger | Breaks symbolic debugging and dynamic linking. | Keeps dynamic linking intact; allows limited symbolic debugging. |
Example Scenario:
- If you're building a production executable and want to maximize performance and minimize size, you might use --strip-all to remove all symbols.
- If you're building an executable for release but you still want to allow post-mortem debugging with gdb or retain dynamic linking information (for example, you may need to debug it later but don't want to ship debugging symbols), you would use --strip-debug to remove just the debugging information.
In general, --strip-all is more aggressive and will make the binary harder to debug, whereas --strip-debug removes only the debug info but retains other symbolic and linkage-related data.
Example:
alexlai@opi516G:~/build/src$ ls -l
total 8324592
-rwxrwxr-x 1 alexlai alexlai 5230313280 Dec 3 04:54 mongod <-- before
-rwxrwxr-x 1 alexlai alexlai 3294059048 Dec 3 05:05 mongos
alexlai@opi516G:~/build/src$ strip --strip-all mongo*
alexlai@opi516G:~/build/src$ ls -l
total 247700
-rwxrwxr-x 1 alexlai alexlai 142498320 Dec 3 05:52 mongod
-rwxrwxr-x 1 alexlai alexlai 111141520 Dec 3 05:52 mongos