When distributing compiled programs on Linux, embedded metadata inside the binary may reveal compiler version or build details. One common example is the comment section, which often stores information such as the GCC version used during compilation. In security-sensitive or production environments, exposing this information can be undesirable. Removing the comment section helps reduce unnecessary metadata and slightly minimizes the binary size. This tutorial provides 2 methods how to remove comment section in binary file on Linux.
Before modifying the file, confirm whether the .comment section exists. To inspect the .comment section in a binary named myapp, run:
readelf -p .comment myapp
Example output:
String dump of section '.comment':
[ 0] GCC: (Ubuntu 13.2.0-23ubuntu4) 13.2.0
If the section is not present, the following message will appear:
readelf: Warning: Section '.comment' was not dumped because it does not exist
Method 1 - strip command
The strip utility (part of the Binutils suite) is commonly used to remove symbols and debugging information from executables. It can also delete specific sections. To remove the .comment section, run the command:
strip --remove-section=.comment myapp
Method 2 - objcopy command
Another tool from Binutils is objcopy for manipulating the contents of executable. It also supports removing individual sections. To eliminate the .comment section, execute the following command:
objcopy --remove-section=.comment myapp
Leave a Comment
Cancel reply