Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Re-enable the linker version scripts for binary distribution (#18872)
Browse files Browse the repository at this point in the history
* Symbol visibility

* Fix
  • Loading branch information
leezu committed Aug 7, 2020
1 parent 1694d2f commit dde635f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
35 changes: 20 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,6 @@ include_directories("3rdparty/tvm/include")
include_directories("3rdparty/dmlc-core/include")
include_directories("3rdparty/dlpack/include")

# commented out until PR goes through
#if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dlpack)
# add_subdirectory(3rdparty/dlpack)
#endif()

# Prevent stripping out symbols (operator registrations, for example)
if(NOT MSVC AND NOT APPLE)
set(BEGIN_WHOLE_ARCHIVE -Wl,--whole-archive)
set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang
set(BEGIN_WHOLE_ARCHIVE -Wl,-force_load)
endif()

if(UNIX)
find_library(RTLIB rt)
if(RTLIB)
Expand Down Expand Up @@ -664,6 +650,18 @@ if(UNIX)
target_compile_options(mxnet PUBLIC "--coverage")
target_link_libraries(mxnet PUBLIC gcov)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Distribution")
# TODO For handling mxnet's symbols the following can be replace by
# annotating symbol visibility in source code, specifying
# set(CMAKE_CXX_VISIBILITY_PRESET hidden) and
# set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# Symbols from statically linked libraries can be discarded via -Wl,--exclude-libs,ALL
if(APPLE)
set_target_properties(mxnet PROPERTIES LINK_FLAGS "-Wl,-exported_symbols_list,${PROJECT_SOURCE_DIR}/cmake/libmxnet.sym")
else()
set_target_properties(mxnet PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/cmake/libmxnet.ver")
endif()
endif()
elseif(MSVC)
if(USE_CUDA)
if(USE_SPLIT_ARCH_DLL)
Expand Down Expand Up @@ -834,8 +832,12 @@ endif()
include(GNUInstallDirs)
install(TARGETS mxnet
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT MXNET_Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT MXNET_Runtime
NAMELINK_COMPONENT MXNET_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT MXNET_Development
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dlpack/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dmlc-core/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand Down Expand Up @@ -876,7 +878,10 @@ if(INSTALL_PYTHON_VERSIONS)
endforeach()
endif()

add_subdirectory(tests)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Distribution")
# Staticbuild applies linker version script to hide private symbols, breaking unit tests
add_subdirectory(tests)
endif()

# ---[ Linter target
find_package(Python3)
Expand Down
15 changes: 15 additions & 0 deletions cmake/libmxnet.sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MX*
NN*
_MX*
_NN*
mx*
nn*
_mx*
_nn*
Java_org_apache_mxnet*
*NDArray*
*Engine*Get*
*Storage*Get*
*on_enter_api*
*on_exit_api*
*MXAPISetLastError*
19 changes: 19 additions & 0 deletions cmake/libmxnet.ver
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
global:
NN*;
MX*;
_NN*;
_MX*;
nn*;
mx*;
_nn*;
_mx*;
Java_org_apache_mxnet*;
*NDArray*;
*Engine*Get*;
*Storage*Get*;
*on_enter_api*;
*on_exit_api*;
*MXAPISetLastError*;
local: *;
};

0 comments on commit dde635f

Please sign in to comment.