Linker version script to hide LLVM symbols (#62906)

Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/62906

Test Plan: Imported from OSS

Reviewed By: navahgar

Differential Revision: D30193893

Pulled By: bertmaher

fbshipit-source-id: 9b189bfd8d4c52e8dc4296a4bed517ff44994ba0
This commit is contained in:
Bert Maher 2021-08-09 11:22:24 -07:00 committed by Facebook GitHub Bot
parent 1b1f1e36b4
commit 3eeaffc7c5
3 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,2 @@
__ZN4llvm*
__ZNK4llvm*

View file

@ -0,0 +1,7 @@
pytorch {
global:
*;
local:
_ZN4llvm*;
_ZNK4llvm*;
};