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

Update symbol visibility control #19057

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ else()
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Distribution")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
if(UNIX AND NOT APPLE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_INSTALL_RPATH $\{ORIGIN\})
Expand Down Expand Up @@ -659,15 +661,12 @@ if(UNIX)
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")
if(NOT APPLE)
# Do not export symbols from statically linked dependencies such as zmq, opencv, etc.
set_target_properties(mxnet PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
else()
set_target_properties(mxnet PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/cmake/libmxnet.ver")
# Apple does not support -Wl,--exclude-libs,ALL
set_target_properties(mxnet PROPERTIES LINK_FLAGS "-Wl,-exported_symbols_list,${PROJECT_SOURCE_DIR}/cmake/libmxnet.sym")
szha marked this conversation as resolved.
Show resolved Hide resolved
endif()
endif()
elseif(MSVC)
Expand Down
11 changes: 2 additions & 9 deletions cmake/libmxnet.sym
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
*MX*
*NN*
*mx*
*nn*
*NDArray*
*Engine*Get*
*Storage*Get*
*on_enter_api*
*on_exit_api*
MX*
NN*
13 changes: 0 additions & 13 deletions cmake/libmxnet.ver

This file was deleted.

2 changes: 1 addition & 1 deletion include/mxnet/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern "C" {
#define MXNET_DLL __declspec(dllimport)
#endif
#else
#define MXNET_DLL
#define MXNET_DLL __attribute__((visibility("default")))
#endif

/*! \brief manually define unsigned int */
Expand Down
10 changes: 5 additions & 5 deletions include/mxnet/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ class PrimExpr : public BaseExpr {
* \brief construct from integer.
* \param value The value to be constructed.
*/
MXNET_DLL PrimExpr(int32_t value); // NOLINT(*)
PrimExpr(int32_t value); // NOLINT(*)
/*!
* \brief construct from float.
* \param value The value to be constructed.
*/
MXNET_DLL PrimExpr(float value); // NOLINT(*)
PrimExpr(float value); // NOLINT(*)
/*!
* \brief construct from string.
* \param str The value to be constructed.
*/
MXNET_DLL PrimExpr(std::string str); // NOLINT(*)
PrimExpr(std::string str); // NOLINT(*)

/*! \return the data type of this expression. */
MXNetDataType dtype() const {
Expand Down Expand Up @@ -164,7 +164,7 @@ class IntImm : public PrimExpr {
* \param dtype The data type of the value.
* \param value The internal value.
*/
MXNET_DLL IntImm(MXNetDataType dtype, int64_t value);
IntImm(MXNetDataType dtype, int64_t value);
/*!
* \brief Get pointer to the internal value.
* \return the content of the integer.
Expand Down Expand Up @@ -209,7 +209,7 @@ class FloatImm : public PrimExpr {
* \param dtype The data type of the value.
* \param value The internal value.
*/
MXNET_DLL FloatImm(MXNetDataType dtype, double value);
FloatImm(MXNetDataType dtype, double value);
/*!
* \brief Get pointer to the container.
* \return The pointer.
Expand Down
10 changes: 5 additions & 5 deletions include/mxnet/runtime/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,19 @@ class Object {
* \param tindex The type index.
* \return the result.
*/
MXNET_DLL static std::string TypeIndex2Key(uint32_t tindex);
static std::string TypeIndex2Key(uint32_t tindex);
/*!
* \brief Get the type key hash of the corresponding index from runtime.
* \param tindex The type index.
* \return the related key-hash.
*/
MXNET_DLL static size_t TypeIndex2KeyHash(uint32_t tindex);
static size_t TypeIndex2KeyHash(uint32_t tindex);
/*!
* \brief Get the type index of the corresponding key from runtime.
* \param key The type key.
* \return the result.
*/
MXNET_DLL static uint32_t TypeKey2Index(const std::string& key);
static uint32_t TypeKey2Index(const std::string& key);

#if MXNET_OBJECT_ATOMIC_REF_COUNTER
using RefCounterType = std::atomic<int32_t>;
Expand Down Expand Up @@ -274,7 +274,7 @@ class Object {
* \param type_child_slots_can_overflow Whether to allow child to overflow the slots.
* \return The allocated type index.
*/
MXNET_DLL static uint32_t GetOrAllocRuntimeTypeIndex(
static uint32_t GetOrAllocRuntimeTypeIndex(
const std::string& key,
uint32_t static_tindex,
uint32_t parent_tindex,
Expand All @@ -301,7 +301,7 @@ class Object {
* \param parent_tindex The parent type index.
* \return The derivation results.
*/
MXNET_DLL bool DerivedFrom(uint32_t parent_tindex) const;
bool DerivedFrom(uint32_t parent_tindex) const;
// friend classes
template<typename>
friend class ObjAllocatorBase;
Expand Down
10 changes: 5 additions & 5 deletions include/mxnet/runtime/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Registry {
* \brief set the body of the function to be f
* \param f The body of the function.
*/
MXNET_DLL Registry& set_body(PackedFunc f); // NOLINT(*)
Registry& set_body(PackedFunc f); // NOLINT(*)
/*!
* \brief set the body of the function to be f
* \param f The body of the function.
Expand Down Expand Up @@ -253,25 +253,25 @@ class Registry {
* \param override Whether allow oveeride existing function.
* \return Reference to theregistry.
*/
MXNET_DLL static Registry& Register(const std::string& name, bool override = false); // NOLINT(*)
static Registry& Register(const std::string& name, bool override = false); // NOLINT(*)
/*!
* \brief Erase global function from registry, if exist.
* \param name The name of the function.
* \return Whether function exist.
*/
MXNET_DLL static bool Remove(const std::string& name);
static bool Remove(const std::string& name);
/*!
* \brief Get the global function by name.
* \param name The name of the function.
* \return pointer to the registered function,
* nullptr if it does not exist.
*/
MXNET_DLL static const PackedFunc* Get(const std::string& name); // NOLINT(*)
static const PackedFunc* Get(const std::string& name); // NOLINT(*)
/*!
* \brief Get the names of currently registered global function.
* \return The names
*/
MXNET_DLL static std::vector<std::string> ListNames();
static std::vector<std::string> ListNames();

// Internal class.
struct Manager;
Expand Down
5 changes: 5 additions & 0 deletions tools/dependencies/protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
# This script builds the static library of protobuf along with protoc, that can be used as dependency of mxnet.
set -ex
PROTOBUF_VERSION=3.5.1
if [[ $PLATFORM == 'darwin' ]]; then
DY_EXT="dylib"
else
DY_EXT="so"
fi

LIBPROTOBUF="$DEPS_PATH/lib/libprotobuf.$DY_EXT"
LIBPROTOC="$DEPS_PATH/lib/libprotoc.$DY_EXT"
Expand Down