On Linux, I'm trying to strip a statically linked ELF file to the bare essentials. When I run:
strip --strip-unneeded foo
or
strip --strip-all foo
The resulting file still has a fat .notes section that appears to be full of funky strings.
Is the .notes section really needed or can I safely force it out with --remove-section?
Thanks for any help.
From experience and from looking at the man page for
strip
, it looks likestrip
isn't supposed to get rid of any and all sections and strings that aren't needed; just symbols. Quoth the man page:That being said, from experience,
strip
, even without--strip-all
, removes sections unneeded for loading, such as.symtab
and.strtab
, and you can, as you note, remove sections you want it with--remove-section
.As an example of a
.notes
section, I took/bin/ls
from my Ubuntu 11.10 64-bit box:That encompasses the
.note.ABI-tag
section and the.note.gnu.build-id
section. It looks like they contain data that isn't necessary to load the program, but also isn't standard, and isn't known bystrip
to not be necessary for the proper running of the program, since an ELF can have any number of additional "unknown" sections that aren't safe to remove. So rather using a virtual whitelist (which would fail miserably), it uses a blacklist of sections that it knows it can get rid of, and does so.Short version: these sections don't seem to be standard and could be used for various things, so
strip
can't know it's safe to remove them. But based on the info inside the one I took above, if it's your own program, it's almost certainly safe to remove it.