Search code examples
xcodemacosstripmicro-optimizationdebug-symbols

How to strip debug symbols for real in Xcode?


I have included the following in an Xcode Application project:

void very_specific_symbol_that_will_never_appear_by_accident(void) {

}

I proceeded to disable all 'debug symbol' related settings and enable all 'strip' related settings I could find, for both Debug and Release, including:

  • Strip Debug Symbols During Copy (Yes)
  • Generate Debug Symbols (No)
  • Reflection Metadata Level (None)
  • Optimization Level (Fastest, Smallest [-Os])

The Problem

If I go to Products, find the application, Show Package Contents, and find the executable in MacOS, and then use the cat command or view with a text editor, I can still find very_specific_symbol_that_will_never_appear_by_accident in the executable file.

If all the symbols were being properly stripped, the function name would not appear in the executable file. The example was not declared static so the optimizer would not remove the function, but I can even see the names of static symbols in the executable of similar projects.

How can I strip symbols for real in a MacOS application in Xcode, so function/global/static names will not appear in the resulting executable?

In case it matters I am using Xcode 11.0 and MacOS 10.15.7.


Solution

  • You also need to enable Deployment Postprocessing in your build settings.

    Also, make sure to build in release mode (you can change that by editing your scheme if needed).

    EDIT

    Symbols may not be stripped in debug mode because of other build settings, like Enable Testability.
    You can change them, although I don't really see the point of stripping symbols on a debug build.