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.
(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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.