Skip to content

Commit 65962f1

Browse files
authored
Merge pull request #31953 from compnerd/invisibility
build: hide symbols using CMake
2 parents dec5d06 + 941681f commit 65962f1

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

stdlib/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
2424
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "")
2525
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
2626

27+
set(CMAKE_C_VISIBILITY_PRESET hidden)
28+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
29+
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
30+
2731
if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
2832
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
2933
message(FATAL_ERROR "Building the swift runtime is not supported with ${CMAKE_C_COMPILER_ID}. Use the just-built clang instead.")

stdlib/public/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ if(CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
4848
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wexit-time-destructors")
4949
endif()
5050

51-
# We don't want runtime C++ code to export symbols we didn't explicitly
52-
# choose to.
53-
check_cxx_compiler_flag("-fvisibility=hidden" CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY)
54-
if(CXX_SUPPORTS_DEFAULT_HIDDEN_VISIBILITY)
55-
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-fvisibility=hidden")
56-
endif()
57-
5851
add_subdirectory(SwiftShims)
5952

6053
if(SWIFT_BUILD_STDLIB)

stdlib/toolchain/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ set(compile_flags
1515
# C++ code in the runtime and standard library should generally avoid
1616
# introducing static constructors or destructors.
1717
"-Wglobal-constructors"
18-
"-Wexit-time-destructors"
19-
20-
# We don't want runtime C++ code to export symbols we didn't explicitly
21-
# choose to.
22-
"-fvisibility=hidden")
18+
"-Wexit-time-destructors")
2319

2420

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

0 commit comments

Comments
 (0)