Symbol hiding in static libraries built with Xcode

Hiding internal names requires a few simple Xcode build settings, and it is not generally necessary to modify source or change the type of the built product.

  1. Eliminate any internal symbols required between modules by performing a single-object prelink. Set the Xcode build setting named “Perform Single-Object Prelink” to Yes (GENERATE_MASTER_OBJECT_FILE=YES). This causes ld to be run with the “-r” flag.
  2. Make sure that the setting “Strip Style” is set to “Non-global symbols” (STRIP_STYLE=non-global), this passes “-x” to ld.
  3. Stripping is only actually performed on static libraries if post-processing is enabled (and this is not the default). Set Xcode build setting “Deployment Postprocessing” to yes. (DEPLOYMENT_POSTPROCESSING=YES). Also make sure that “Use separate strip” is set to Yes (not always the default) (SEPARATE_STRIP=YES).
  4. If, in addition to local symbols, if you need to remove some of the global symbols you can supply additional options to the strip command, under the Xcode build setting “Additional strip flags”. E.g. I commonly use the strip “-R somefile” option to provide a file with an additional list of symbols which I want removed from the global symbol table.

Leave a Comment