Skip to content

Commit 7268640

Browse files
authored
Merge pull request #74731 from al45tair/eng/PR-116525111
[Build][Linux] Set `--build-id=sha1` for the linker.
2 parents f27139e + 35f123b commit 7268640

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

cmake/modules/AddPureSwift.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ function(add_pure_swift_host_library name)
291291

292292
_set_pure_swift_profile_flags(${name})
293293

294+
# Enable build IDs
295+
if(SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_USE_BUILD_ID)
296+
target_link_options(${name} PRIVATE
297+
"SHELL:-Xlinker --build-id=sha1")
298+
endif()
299+
294300
# Export this target.
295301
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
296302
endfunction()
@@ -392,6 +398,12 @@ function(add_pure_swift_host_tool name)
392398
)
393399
endif()
394400

401+
# Enable build IDs
402+
if(SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_USE_BUILD_ID)
403+
target_link_options(${name} PRIVATE
404+
"SHELL:-Xlinker --build-id=sha1")
405+
endif()
406+
395407
# Workaround to touch the library and its objects so that we don't
396408
# continually rebuild (again, see corresponding change in swift-syntax).
397409
add_custom_command(

cmake/modules/AddSwift.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,12 @@ function(_add_host_variant_link_flags target)
447447
"SHELL:-Xlinker -no_warn_duplicate_libraries")
448448
endif()
449449

450+
# Enable build IDs
451+
if(SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_USE_BUILD_ID)
452+
target_link_options(${target} PRIVATE
453+
"SHELL:-Xlinker --build-id=sha1")
454+
endif()
455+
450456
endfunction()
451457

452458
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)

cmake/modules/SwiftConfigureSDK.cmake

+14
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ endfunction()
168168
# SWIFT_SDK_${prefix}_IS_SIMULATOR Whether this is a simulator target.
169169
# SWIFT_SDK_${prefix}_ARCH_${ARCH}_TRIPLE Triple name
170170
# SWIFT_SDK_${prefix}_ARCH_${ARCH}_MODULE Module triple name for this SDK
171+
# SWIFT_SDK_${prefix}_USE_BUILD_ID Whether to pass --build-id to the linker
171172
macro(configure_sdk_darwin
172173
prefix name deployment_version xcrun_name
173174
triple_name module_name architectures)
@@ -216,6 +217,9 @@ macro(configure_sdk_darwin
216217
set(SWIFT_SDK_${prefix}_STATIC_ONLY FALSE)
217218
get_threading_package(${prefix} "darwin" SWIFT_SDK_${prefix}_THREADING_PACKAGE)
218219

220+
# On Darwin we get UUIDs automatically, without the --build-id flag
221+
set(SWIFT_SDK_${prefix}_USE_BUILD_ID FALSE)
222+
219223
set(SWIFT_SDK_${prefix}_ARCHITECTURES ${architectures})
220224
if(SWIFT_DARWIN_SUPPORTED_ARCHS)
221225
list_intersect(
@@ -335,6 +339,15 @@ macro(configure_sdk_unix name architectures)
335339
set(SWIFT_SDK_${prefix}_STATIC_ONLY FALSE)
336340
endif()
337341

342+
if("${prefix}" STREQUAL "LINUX"
343+
OR "${prefix}" STREQUAL "ANDROID"
344+
OR "${prefix}" STREQUAL "FREEBSD"
345+
OR "${prefix}" STREQUAL "OPENBSD")
346+
set(SWIFT_SDK_${prefix}_USE_BUILD_ID TRUE)
347+
else()
348+
set(SWIFT_SDK_${prefix}_USE_BUILD_ID FALSE)
349+
endif()
350+
338351
# GCC on Linux is usually located under `/usr`.
339352
# However, Ubuntu 20.04 ships with another GCC installation under `/`, which
340353
# does not include libstdc++. Swift build scripts pass `--sysroot=/` to
@@ -494,6 +507,7 @@ macro(configure_sdk_windows name environment architectures)
494507
set(SWIFT_SDK_${prefix}_IMPORT_LIBRARY_SUFFIX ".lib")
495508
set(SWIFT_SDK_${prefix}_STATIC_LINKING_SUPPORTED FALSE)
496509
set(SWIFT_SDK_${prefix}_STATIC_ONLY FALSE)
510+
set(SWIFT_SDK_${prefix}_USE_BUILD_ID FALSE)
497511
get_threading_package(${prefix} "win32" SWIFT_SDK_${prefix}_THREADING_PACKAGE)
498512

499513
foreach(arch ${architectures})

stdlib/cmake/modules/AddSwiftStdlib.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,11 @@ function(_add_target_variant_link_flags)
599599
endif()
600600
endif()
601601

602+
# Enable build-ids on non-Windows non-Darwin platforms
603+
if(SWIFT_SDK_${LFLAGS_SDK}_USE_BUILD_ID)
604+
list(APPEND result "-Wl,--build-id=sha1")
605+
endif()
606+
602607
# Enable dead stripping. Portions of this logic were copied from llvm's
603608
# `add_link_opts` function (which, perhaps, should have been used here in the
604609
# first place, but at this point it's hard to say whether that's feasible).

0 commit comments

Comments
 (0)