You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2020/08/07 21:17:32 UTC
[incubator-mxnet] branch master updated: Re-enable the linker
version scripts for binary distribution (#18872)
This is an automated email from the ASF dual-hosted git repository.
zhasheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new dde635f Re-enable the linker version scripts for binary distribution (#18872)
dde635f is described below
commit dde635f8c7666e205816da8ca4e519d0d213523f
Author: Leonard Lausen <la...@amazon.com>
AuthorDate: Fri Aug 7 21:16:24 2020 +0000
Re-enable the linker version scripts for binary distribution (#18872)
* Symbol visibility
* Fix
---
CMakeLists.txt | 35 ++++++++++++++++++++---------------
cmake/libmxnet.sym | 15 +++++++++++++++
cmake/libmxnet.ver | 19 +++++++++++++++++++
3 files changed, 54 insertions(+), 15 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3082e26..63c25ac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
@@ -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)
@@ -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})
@@ -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)
diff --git a/cmake/libmxnet.sym b/cmake/libmxnet.sym
new file mode 100644
index 0000000..0ddf63f
--- /dev/null
+++ b/cmake/libmxnet.sym
@@ -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*
diff --git a/cmake/libmxnet.ver b/cmake/libmxnet.ver
new file mode 100644
index 0000000..560549c
--- /dev/null
+++ b/cmake/libmxnet.ver
@@ -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: *;
+};