Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] Default symbol visibility to hidden for all targets #4545

Merged
merged 1 commit into from
Mar 16, 2022
Merged
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: 8 additions & 7 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ option(TI_WITH_CC "Build with the C backend" ON)
option(TI_WITH_VULKAN "Build with the Vulkan backend" OFF)
option(TI_WITH_DX11 "Build with the DX11 backend" OFF)
option(TI_EMSCRIPTENED "Build using emscripten" OFF)
set(_TI_SYMBOL_VISIBILITY default)

# Force symbols to be 'hidden' by default so nothing is exported from the Taichi
# library including the third-party dependencies.
# As Taichi can be used by external projects, some of the internal dependencies
# such as Vulkan, ImGui, etc. could be in conflict with the dependencies of those
# projects.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

if(TI_EMSCRIPTENED)
set(TI_WITH_LLVM OFF)
Expand Down Expand Up @@ -225,7 +232,6 @@ endif()
# everywhere in python.
set(CORE_LIBRARY_NAME taichi_isolated_core)
add_library(${CORE_LIBRARY_NAME} OBJECT ${TAICHI_CORE_SOURCE})
set_target_properties(${CORE_LIBRARY_NAME} PROPERTIES CXX_VISIBILITY_PRESET ${_TI_SYMBOL_VISIBILITY})

if (APPLE)
# Ask OS X to minic Linux dynamic linking behavior
Expand Down Expand Up @@ -390,10 +396,6 @@ if (NOT WIN32)
# Linux
target_link_libraries(${CORE_LIBRARY_NAME} stdc++fs X11)
target_link_libraries(${CORE_LIBRARY_NAME} -static-libgcc -static-libstdc++)
if ((NOT TI_EXPORT_CORE) AND (NOT ${_TI_SYMBOL_VISIBILITY} STREQUAL hidden)) # expose api for CHI IR Builder
message(WARNING "Using linker.map to hide symbols!")
target_link_libraries(${CORE_LIBRARY_NAME} -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/misc/linker.map)
endif ()
# Avoid glibc dependencies
if (TI_WITH_VULKAN)
target_link_libraries(${CORE_LIBRARY_NAME} -Wl,--wrap=log2f)
Expand Down Expand Up @@ -426,7 +428,6 @@ if(NOT TI_EMSCRIPTENED)
add_library(${CORE_WITH_PYBIND_LIBRARY_NAME} SHARED)
endif ()

set_target_properties(${CORE_WITH_PYBIND_LIBRARY_NAME} PROPERTIES CXX_VISIBILITY_PRESET ${_TI_SYMBOL_VISIBILITY})
# Remove symbols from static libs: https://stackoverflow.com/a/14863432/12003165
if (LINUX)
target_link_options(${CORE_WITH_PYBIND_LIBRARY_NAME} PUBLIC -Wl,--exclude-libs=ALL)
Expand Down
13 changes: 0 additions & 13 deletions misc/linker.map

This file was deleted.