Skip to content

build: hide symbols using CMake #31953

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

Merged
merged 1 commit into from
May 22, 2020
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
4 changes: 4 additions & 0 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
message(FATAL_ERROR "Building the swift runtime is not supported with ${CMAKE_C_COMPILER_ID}. Use the just-built clang instead.")
Expand Down
7 changes: 0 additions & 7 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ if(CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wexit-time-destructors")
endif()

# We don't want runtime C++ code to export symbols we didn't explicitly
# choose to.
check_cxx_compiler_flag("-fvisibility=hidden" CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY)
if(CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY)
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-fvisibility=hidden")
endif()

add_subdirectory(SwiftShims)

if(SWIFT_BUILD_STDLIB)
Expand Down
6 changes: 1 addition & 5 deletions stdlib/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ set(compile_flags
# C++ code in the runtime and standard library should generally avoid
# introducing static constructors or destructors.
"-Wglobal-constructors"
"-Wexit-time-destructors"

# We don't want runtime C++ code to export symbols we didn't explicitly
# choose to.
"-fvisibility=hidden")
"-Wexit-time-destructors")


# Build the runtime with -Wall to catch, e.g., uninitialized variables
Expand Down