Ripping and Stripping Debug Symbols with Binutil tools
In the world of software development, compiled binaries often come packed debug symbols. These symbols provide valuable information for debugging purposes, like function names and variable locations and in some scenarios even the source code. But for final deployments, they're unnecessary and can significantly increase file size and security risks.
This is where binutil tools comes in, the GNU Binutils are a collection of programming tools maintained by the GNU Project for working with executable code including assembly, linking and many other development operations. This collection contains tools like:
- ld
- objdump
- strip
- objcopy
- as
In this post, we'll explore how to use objcopy
and strip
tools to achieve our two key goals:
What is objcopy and strip?
-
objdump
is a tool in the GNU Binutils package for manipulating object files. It can be used to copy object files, removing unnecessary sections like debug symbols to create leaner binaries. It can also extract specific sections, like debug information only, into separate files for potential debugging needs. -
strip
is another tool in the Binutils package, it is like a file slimmer for executables. It removes debug symbols, information helpful for programmers but not needed for the program to run.
Difference between Ripping and Stripping
- Ripping Debug Symbols:
- Extracting the debug information into a separate file for potential future debugging needs.
- Stripping Debug Symbols:
- Removing unnecessary symbols to create a leaner, more efficient binary.
1. Ripping off debug symbols off a binary (objcopy)
If you want to keep the debug information for potential future use, you can extract it into a separate file using the --only-keep-debug
flag
objcopy --only-keep-debug myprogram debug_symbols.dbg
This creates a file named debug_symbols.dbg that contains only the stripped debug symbols. After ripping the symbol file from the binary the symbol file is still in the binary we only extracted a copy of the symbol file.
Demo:
2. Stripping off debug symbols off a binary (strip)
Stripping will remove the symbols from the binary without taking a copy of it
strip --strip-debug myprogram -o myprogram_without_symbols
Demo:
In the above demo we can see that even though we stripped debug symbols, some information like function names are still in the non-debugging symbols section.
In order to get rid of that info too, we can strip off everything including default sysmbols except the necessary things to load a binary using the --strip-unneeded
flag.
strip --strip-debug --strip-unneeded myprogram -o myprogram_without_any_symbols
Demo:
Benefits of Stripping:
There are several advantages to stripping debug symbols:
- Reduced File Size: Smaller binaries mean faster downloads, less storage consumption, and potentially better performance.
- Improved Security: Stripped binaries offer a slight layer of protection against reverse engineering efforts that rely on symbol information.