-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Symbol stripping on OSX fails for release build #595
Description
Hi all,
at least since commit 0f294e2, there's symbol stripping functionality in the file tools/pybind11Tools.cmake:
...
if(CMAKE_STRIP)
if(APPLE)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_STRIP} -u -r $<TARGET_FILE:${target_name}>)
else()
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${target_name}>)
endif()
endif()
...
For some reason this step fails for me on OSX version 10.12. What does work, is if I execute
$ strip -x mylib.so
This strips off about 3MB (going from 21MB to 18MB). I'm not an expert on symbol stripping, so I'm not sure what to do in this situation. The stripped library with the -x options seems to work fine in practice. The problem has something to do with other libraries that I link against. Here's the full error when I apply the -u -r option:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: symbols referenced by indirect symbol table entries that can't be stripped in: /Users/rwols/dev/llvm/build/release/lib/Clara.so
_llvm_regcomp
_llvm_regerror
_llvm_regexec
_llvm_regfree
_llvm_strlcpy
I'm using pybind11 in a "tools" project sitting inside LLVM/Clang, so it's hard for me to come up with a minimal example.
I think a solution for now would be to change -u -r into -x in the if(APPLE) block, but I don't know the ramifications of that change. The man page of strip on OSX also tells me:
For dynamic shared libraries, the maximum level of stripping is usually -x (to remove all non-global symbols).
Finally I'd like to note that the stripping functionality as it is now works fine on Ubuntu both for debug and release builds, and it also works on OSX for debug builds. It fails on OSX for release builds.