Reputation: 12983
My c/obj-c code (an iOS app built with clang) has some functions excluded by #ifdefs
. I want to make sure that code that gets called from those functions, but not from others (dead code) gets stripped out (eliminated) at link time.
I tried:
strings
on the executable.Before you ask, I'm building for release, and all strip settings (including dead-code stripping, obviously) are enabled.
The question is not really xcode/apple/iOS specific; I assume the answer should be pretty much the same on any POSIX development platform.
Upvotes: 5
Views: 2377
Reputation: 980
(EDIT)
In binutils, ld
has the --gc-sections
option which does what you want for sections on object level. You have several options:
use gcc
's flags -ffunction-sections
and -fdata-sections
to isolate each symbol into its own section, then use --gc-sections
;
put all candidates for removal into a separate file and the linker will be able to strip the whole section;
disassemble the resulting binary, remove dead code, assemble again;
use strip
with appropriate -N
options to discard the offending symbols from the
symbol table - this will leave the code and data there, but it won't show up in the symbol table.
Upvotes: 2