Skip to content

Commit a7d5b4a

Browse files
committed
Darwin: do not export symbols for host executables by default
This should help reduce the size of the `bin` folder by about 2%. Executables that do need these symbols for plugins or similar can opt out of this by passing `EXPORT_SYMBOLS_WITH_APPLE_LINKER` to `add_swift_host_tool` -- for instance that's needed by `swift-frontend` and `swift-remoteast-test`. Addresses rdar://147888376
1 parent c84493e commit a7d5b4a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

cmake/modules/AddSwift.cmake

+16-2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ endmacro()
843843
# add_swift_host_tool(name
844844
# [HAS_SWIFT_MODULES | DOES_NOT_USE_SWIFT]
845845
# [THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY]
846+
# [EXPORT_SYMBOLS_WITH_APPLE_LINKER]
846847
#
847848
# [BOOTSTRAPPING 0|1]
848849
# [SWIFT_COMPONENT component]
@@ -861,6 +862,9 @@ endmacro()
861862
# THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
862863
# Opt-out of LLVM IR optimizations when linking ThinLTO with ld64
863864
#
865+
# EXPORT_SYMBOLS_WITH_APPLE_LINKER
866+
# Export symbols when using ld on Apple platforms
867+
#
864868
# BOOTSTRAPPING
865869
# Bootstrapping stage.
866870
#
@@ -873,7 +877,7 @@ endmacro()
873877
# source1 ...
874878
# Sources to add into this executable.
875879
function(add_swift_host_tool executable)
876-
set(options HAS_SWIFT_MODULES DOES_NOT_USE_SWIFT THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
880+
set(options HAS_SWIFT_MODULES DOES_NOT_USE_SWIFT THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY EXPORT_SYMBOLS_WITH_APPLE_LINKER)
877881
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
878882
set(multiple_parameter_options LLVM_LINK_COMPONENTS)
879883

@@ -998,7 +1002,7 @@ function(add_swift_host_tool executable)
9981002
string(CONCAT lto_codegen_only_link_options
9991003
"$<"
10001004
"$<AND:"
1001-
"$<BOOL:${LLVM_LINKER_IS_LD64}>,"
1005+
"$<BOOL:${LLVM_LINKER_IS_APPLE}>,"
10021006
"$<BOOL:${SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS}>,"
10031007
"$<STREQUAL:${SWIFT_TOOLS_ENABLE_LTO},thin>"
10041008
">:"
@@ -1007,6 +1011,16 @@ function(add_swift_host_tool executable)
10071011
target_link_options(${executable} PRIVATE "${lto_codegen_only_link_options}")
10081012
endif()
10091013

1014+
string(CONCAT no_exported_symbols_link_option
1015+
"$<"
1016+
"$<AND:"
1017+
"$<BOOL:${LLVM_LINKER_IS_APPLE}>,"
1018+
"$<NOT:$<BOOL:${ASHT_EXPORT_SYMBOLS_WITH_APPLE_LINKER}>>"
1019+
">:"
1020+
"LINKER:-no_exported_symbols"
1021+
">")
1022+
target_link_options(${executable} PRIVATE "${no_exported_symbols_link_option}")
1023+
10101024
if(NOT ASHT_SWIFT_COMPONENT STREQUAL "no_component")
10111025
add_dependencies(${ASHT_SWIFT_COMPONENT} ${executable})
10121026
swift_install_in_component(TARGETS ${executable}

tools/driver/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ add_swift_host_tool(swift-frontend
6666
driver.cpp
6767
SWIFT_COMPONENT compiler
6868
HAS_SWIFT_MODULES
69+
EXPORT_SYMBOLS_WITH_APPLE_LINKER
6970
)
7071
target_link_libraries(swift-frontend
7172
PUBLIC

tools/swift-remoteast-test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_swift_host_tool(swift-remoteast-test
22
swift-remoteast-test.cpp
33
SWIFT_COMPONENT testsuite-tools
44
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
5+
EXPORT_SYMBOLS_WITH_APPLE_LINKER
56
)
67
target_link_libraries(swift-remoteast-test
78
PRIVATE

0 commit comments

Comments
 (0)