Skip to content

Commit dafcec6

Browse files
authored
Merge pull request swiftlang#1641 from al45tair/eng/PR-116798309
[Linux] Add build-id support.
2 parents 661e0bc + 87d48ea commit dafcec6

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
3131
set(CMAKE_Swift_LANGUAGE_VERSION 5)
3232
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
3333

34+
# Generate build-ids
35+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin"
36+
AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
37+
add_link_options("LINKER:--build-id=sha1")
38+
endif()
39+
3440
# ensure Swift compiler can find _CSwiftScan
3541
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/CSwiftScan/include>)
3642

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

+13
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ extension GenericUnixToolchain {
106106
commandLine.appendFlag("-pie")
107107
}
108108

109+
// On some platforms we want to enable --build-id
110+
if targetTriple.os == .linux
111+
|| targetTriple.os == .freeBSD
112+
|| targetTriple.os == .openbsd
113+
|| parsedOptions.hasArgument(.buildId) {
114+
commandLine.appendFlag("-Xlinker")
115+
if let buildId = parsedOptions.getLastArgument(.buildId)?.asSingle {
116+
commandLine.appendFlag("--build-id=\(buildId)")
117+
} else {
118+
commandLine.appendFlag("--build-id")
119+
}
120+
}
121+
109122
let staticStdlib = parsedOptions.hasFlag(positive: .staticStdlib,
110123
negative: .noStaticStdlib,
111124
default: false)

Sources/SwiftOptions/Options.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ extension Option {
6060
public static let bridgingHeaderDirectoryForPrint: Option = Option("-bridging-header-directory-for-print", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<path>", helpText: "Directory for bridging header to be printed in compatibility header")
6161
public static let bridgingHeaderPchKey: Option = Option("-bridging-header-pch-key", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Cache Key for bridging header pch")
6262
public static let bsdk: Option = Option("-bsdk", .joinedOrSeparate, attributes: [.noDriver, .argumentIsPath], helpText: "path to the baseline SDK to import frameworks")
63+
public static let buildIdEQ: Option = Option("-build-id=", .joined, alias: Option.buildId, attributes: [])
64+
public static let buildId: Option = Option("-build-id", .joinedOrSeparate, attributes: [], metaVar: "<build-id>", helpText: "Specify the build ID argument passed to the linker")
6365
public static let buildModuleFromParseableInterface: Option = Option("-build-module-from-parseable-interface", .flag, alias: Option.compileModuleFromInterface, attributes: [.helpHidden, .frontend, .noDriver], group: .modes)
6466
public static let bypassBatchModeChecks: Option = Option("-bypass-batch-mode-checks", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Bypass checks for batch-mode errors.")
6567
public static let bypassResilience: Option = Option("-bypass-resilience-checks", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Ignore all checks for module resilience.")
@@ -118,7 +120,7 @@ extension Option {
118120
public static let debugGenericSignatures: Option = Option("-debug-generic-signatures", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Debug generic signatures")
119121
public static let debugInfoFormat: Option = Option("-debug-info-format=", .joined, attributes: [.frontend], helpText: "Specify the debug info format type to either 'dwarf' or 'codeview'")
120122
public static let debugInfoStoreInvocation: Option = Option("-debug-info-store-invocation", .flag, attributes: [.frontend], helpText: "Emit the compiler invocation in the debug info.")
121-
public static let debugInverseRequirements: Option = Option("-debug-inverse-requirements", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Print real requirements in -debug_generic_signatures output")
123+
public static let debugInverseRequirements: Option = Option("-debug-inverse-requirements", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Print real requirements in -debug-generic-signatures output")
122124
public static let debugMapping: Option = Option("-debug-mapping", .flag, attributes: [.noDriver], helpText: "Dumping information for debug purposes")
123125
public static let debugMapping_: Option = Option("--debug-mapping", .flag, alias: Option.debugMapping, attributes: [.noDriver], helpText: "Dumping information for debug purposes")
124126
public static let debugPrefixMap: Option = Option("-debug-prefix-map", .separate, attributes: [.frontend], metaVar: "<prefix=replacement>", helpText: "Remap source paths in debug info")
@@ -800,7 +802,7 @@ extension Option {
800802
public static let targetSdkName: Option = Option("-target-sdk-name", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Canonical name of the target SDK used for compilation")
801803
public static let targetSdkVersion: Option = Option("-target-sdk-version", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "The version of target SDK used for compilation")
802804
public static let targetVariantSdkVersion: Option = Option("-target-variant-sdk-version", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "The version of target variant SDK used for compilation")
803-
public static let targetVariant: Option = Option("-target-variant", .separate, attributes: [.frontend], helpText: "Generate 'zippered' code for macCatalyst that can run on the specified variant target triple in addition to the main -target triple")
805+
public static let targetVariant: Option = Option("-target-variant", .separate, attributes: [.frontend, .moduleInterface], helpText: "Generate 'zippered' code for macCatalyst that can run on the specified variant target triple in addition to the main -target triple")
804806
public static let targetLegacySpelling: Option = Option("--target=", .joined, alias: Option.target, attributes: [.frontend])
805807
public static let target: Option = Option("-target", .separate, attributes: [.frontend, .moduleWrap, .moduleInterface], metaVar: "<triple>", helpText: "Generate code for the given target <triple>, such as x86_64-apple-macos10.9")
806808
public static let tbdCompatibilityVersionEQ: Option = Option("-tbd-compatibility-version=", .joined, alias: Option.tbdCompatibilityVersion, attributes: [.frontend, .noDriver])
@@ -859,7 +861,7 @@ extension Option {
859861
public static let warnConcurrency: Option = Option("-warn-concurrency", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Warn about code that is unsafe according to the Swift Concurrency model and will become ill-formed in a future language version")
860862
public static let warnImplicitOverrides: Option = Option("-warn-implicit-overrides", .flag, attributes: [.frontend, .doesNotAffectIncrementalBuild], helpText: "Warn about implicit overrides of protocol members")
861863
public static let warnLongExpressionTypeCheckingEQ: Option = Option("-warn-long-expression-type-checking=", .joined, alias: Option.warnLongExpressionTypeChecking, attributes: [.helpHidden, .frontend, .noDriver])
862-
public static let warnLongExpressionTypeChecking: Option = Option("-warn-long-expression-type-checking", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking a function takes longer than <n> ms")
864+
public static let warnLongExpressionTypeChecking: Option = Option("-warn-long-expression-type-checking", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking an expression takes longer than <n> ms")
863865
public static let warnLongFunctionBodiesEQ: Option = Option("-warn-long-function-bodies=", .joined, alias: Option.warnLongFunctionBodies, attributes: [.helpHidden, .frontend, .noDriver])
864866
public static let warnLongFunctionBodies: Option = Option("-warn-long-function-bodies", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<n>", helpText: "Warns when type-checking a function takes longer than <n> ms")
865867
public static let warnOnEditorPlaceholder: Option = Option("-warn-on-editor-placeholder", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Downgrade the editor placeholder error to a warning")
@@ -929,6 +931,8 @@ extension Option {
929931
Option.bridgingHeaderDirectoryForPrint,
930932
Option.bridgingHeaderPchKey,
931933
Option.bsdk,
934+
Option.buildIdEQ,
935+
Option.buildId,
932936
Option.buildModuleFromParseableInterface,
933937
Option.bypassBatchModeChecks,
934938
Option.bypassResilience,

0 commit comments

Comments
 (0)