how can I verify that dead code was stripped from the binary? how can I verify that dead code was stripped from the binary? unix unix

how can I verify that dead code was stripped from the binary?


(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.