diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 32b004fd83b..b41520c5773 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -797,6 +797,15 @@ if(USE_LLVM AND LLVM_FOUND) support core analysis executionengine instcombine scalaropts transformutils ${LLVM_TARGETS_TO_BUILD} orcjit) target_link_libraries(torch_cpu PRIVATE ${LLVM_LINK_LIBS}) + if(APPLE) + set(LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/unexported_symbols.lds") + set_target_properties(torch_cpu PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT}) + set_target_properties(torch_cpu PROPERTIES LINK_FLAGS "-Wl,-unexported_symbols_list,${LINKER_SCRIPT}") + elseif(UNIX) + set(LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/version_script.lds") + set_target_properties(torch_cpu PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT}) + set_target_properties(torch_cpu PROPERTIES LINK_FLAGS "-Wl,--version-script=${LINKER_SCRIPT}") + endif() endif(USE_LLVM AND LLVM_FOUND) # This is required for older versions of CMake, which don't allow diff --git a/caffe2/unexported_symbols.lds b/caffe2/unexported_symbols.lds new file mode 100644 index 00000000000..7c05d205ae7 --- /dev/null +++ b/caffe2/unexported_symbols.lds @@ -0,0 +1,2 @@ +__ZN4llvm* +__ZNK4llvm* diff --git a/caffe2/version_script.lds b/caffe2/version_script.lds new file mode 100644 index 00000000000..900c6b87832 --- /dev/null +++ b/caffe2/version_script.lds @@ -0,0 +1,7 @@ +pytorch { + global: + *; + local: + _ZN4llvm*; + _ZNK4llvm*; +};