Skip to content

Commit 960d0e3

Browse files
committed
Linux: Fix -static-executable and remove swiftImageInspectionShared
- Remove references to swiftImageInspectionShared on Linux and dont have split libraries between static/non-static linked executables. - -static-executable now links correctly Linux. Note: swift::lookupSymbol() will not work on statically linked executables but this can be worked around by using the https://github.com/swift-server/swift-backtrace package.
1 parent 6c72664 commit 960d0e3

File tree

5 files changed

+14
-64
lines changed

5 files changed

+14
-64
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL FREEBSD)
274274
${SWIFTLIB_DIR}/clang/lib/freebsd/libclang_rt.builtins-${SWIFT_PRIMARY_VARIANT_ARCH}.a)
275275
elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL LINUX)
276276
if(SWIFT_BUILD_STATIC_STDLIB)
277-
list(APPEND swift_core_private_link_libraries swiftImageInspectionShared)
277+
list(APPEND swift_core_private_link_libraries)
278278
endif()
279279
elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL WINDOWS)
280280
list(APPEND swift_core_private_link_libraries shell32;DbgHelp)

stdlib/public/runtime/CMakeLists.txt

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,9 @@ list(APPEND swift_runtime_library_compile_flags -I${SWIFT_SOURCE_DIR}/stdlib/inc
8181

8282
set(sdk "${SWIFT_HOST_VARIANT_SDK}")
8383
if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
84-
list(REMOVE_ITEM swift_runtime_sources ImageInspectionELF.cpp)
8584
set(static_binary_lnk_file_list)
8685
string(TOLOWER "${sdk}" lowercase_sdk)
8786

88-
# These two libraries are only used with the static swiftcore
89-
add_swift_target_library(swiftImageInspectionShared STATIC
90-
ImageInspectionELF.cpp
91-
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
92-
LINK_FLAGS ${swift_runtime_linker_flags}
93-
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
94-
INSTALL_IN_COMPONENT stdlib)
95-
96-
foreach(arch IN LISTS SWIFT_SDK_${sdk}_ARCHITECTURES)
97-
set(FragileSupportLibrary swiftImageInspectionShared-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch})
98-
set(LibraryLocation ${SWIFTSTATICLIB_DIR}/${lowercase_sdk}/${arch})
99-
add_custom_command_target(swift_image_inspection_${arch}_static
100-
COMMAND
101-
"${CMAKE_COMMAND}" -E copy $<TARGET_FILE:${FragileSupportLibrary}> ${LibraryLocation}
102-
OUTPUT
103-
"${LibraryLocation}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
104-
DEPENDS
105-
${FragileSupportLibrary})
106-
add_dependencies(stdlib ${FragileSupportLibrary})
107-
swift_install_in_component(FILES $<TARGET_FILE:${FragileSupportLibrary}>
108-
DESTINATION "lib/swift_static/${lowercase_sdk}/${arch}"
109-
COMPONENT stdlib)
110-
endforeach()
111-
112-
set(FragileSupportLibraryPrimary swiftImageInspectionShared-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${SWIFT_PRIMARY_VARIANT_ARCH})
113-
set(LibraryLocationPrimary ${SWIFTSTATICLIB_DIR}/${lowercase_sdk})
114-
add_custom_command_target(swift_image_inspection_static_primary_arch
115-
COMMAND
116-
"${CMAKE_COMMAND}" -E copy $<TARGET_FILE:${FragileSupportLibraryPrimary}> ${LibraryLocationPrimary}
117-
OUTPUT
118-
"${LibraryLocationPrimary}/${CMAKE_STATIC_LIBRARY_PREFIX}swiftImageInspectionShared${CMAKE_STATIC_LIBRARY_SUFFIX}"
119-
DEPENDS
120-
${FragileSupportLibraryPrimary})
121-
add_dependencies(stdlib ${FragileSupportLibraryPrimary})
122-
swift_install_in_component(FILES $<TARGET_FILE:${FragileSupportLibraryPrimary}>
123-
DESTINATION "lib/swift_static/${lowercase_sdk}"
124-
COMPONENT stdlib)
125-
12687
# Generate the static-executable-args.lnk file used for ELF systems (eg linux)
12788
set(linkfile "${lowercase_sdk}/static-executable-args.lnk")
12889
add_custom_command_target(swift_static_binary_${sdk}_args
@@ -140,18 +101,6 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
140101
DESTINATION "lib/swift_static/${lowercase_sdk}"
141102
COMPONENT stdlib)
142103
add_custom_target(static_binary_magic ALL DEPENDS ${static_binary_lnk_file_list})
143-
foreach(arch IN LISTS SWIFT_SDK_LINUX_ARCHITECTURES)
144-
add_dependencies(static_binary_magic ${swift_image_inspection_${arch}_static})
145-
endforeach()
146-
add_dependencies(static_binary_magic ${swift_image_inspection_static_primary_arch})
147-
add_dependencies(stdlib static_binary_magic)
148-
149-
add_swift_target_library(swiftImageInspectionSharedObject OBJECT_LIBRARY
150-
ImageInspectionELF.cpp
151-
C_COMPILE_FLAGS ${swift_runtime_library_compile_flags}
152-
LINK_FLAGS ${swift_runtime_linker_flags}
153-
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
154-
INSTALL_IN_COMPONENT never_install)
155104
endif()
156105

157106
add_swift_target_library(swiftRuntime OBJECT_LIBRARY
@@ -280,7 +229,6 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
280229
-ldl
281230
-lpthread
282231
-lswiftCore
283-
-lswiftImageInspectionShared
284232
${libicu_i18n_a}
285233
${libicu_uc_a}
286234
${libicu_data_a}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Build a static executable "hello world" program
2+
// REQUIRES: OS=linux-gnu
3+
// REQUIRES: static_stdlib
4+
print("hello world!")
5+
// RUN: %empty-directory(%t)
6+
// RUN: %target-swiftc_driver -static-executable -o %t/static-executable %s
7+
// RUN: %t/static-executable | %FileCheck %s
8+
// RUN: file %t/static-executable | %FileCheck %s --check-prefix=FILE
9+
// CHECK: hello world!
10+
// FILE: , statically linked,

unittests/runtime/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
2828
endif()
2929
endif()
3030

31-
set(swift_runtime_test_extra_libraries)
32-
if(SWIFT_BUILD_STATIC_STDLIB AND "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "LINUX")
33-
list(APPEND swift_runtime_test_extra_libraries
34-
$<TARGET_FILE:swiftImageInspectionShared-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}>)
35-
endif()
36-
3731
add_subdirectory(LongTests)
3832

3933
set(PLATFORM_SOURCES)
@@ -94,7 +88,6 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
9488
PRIVATE
9589
swiftCore${SWIFT_PRIMARY_VARIANT_SUFFIX}
9690
${PLATFORM_TARGET_LINK_LIBRARIES}
97-
${swift_runtime_test_extra_libraries}
9891
)
9992
endif()
10093

utils/static-executable-args.lnk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
-static
22
-lswiftCore
3-
-lswiftImageInspectionShared
43
-Xlinker
5-
--defsym=__import_pthread_self=pthread_self
4+
-undefined=pthread_self
65
-Xlinker
7-
--defsym=__import_pthread_once=pthread_once
6+
-undefined=pthread_once
87
-Xlinker
9-
--defsym=__import_pthread_key_create=pthread_key_create
8+
-undefined=pthread_key_create
109
-lpthread
1110
-licui18nswift
1211
-licuucswift

0 commit comments

Comments
 (0)