Skip to content

Commit 1f11627

Browse files
committed
Driver: do not generate a dSYM bundle for static archives
When building a static library with debug information, do not create a dSYM generation job as it cannot be executed on a non-image target. This is important for the case where the single invocation is both the compile and link job. This was detected in conjunction with @gottesmm.
1 parent f69dfc2 commit 1f11627

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/Driver/Driver.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,13 +2222,25 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
22222222
}
22232223
TopLevelActions.push_back(LinkAction);
22242224

2225-
if (TC.getTriple().isOSDarwin() &&
2226-
OI.DebugInfoLevel > IRGenDebugInfoLevel::None) {
2227-
auto *dSYMAction = C.createAction<GenerateDSYMJobAction>(LinkAction);
2228-
TopLevelActions.push_back(dSYMAction);
2229-
if (Args.hasArg(options::OPT_verify_debug_info)) {
2230-
TopLevelActions.push_back(
2231-
C.createAction<VerifyDebugInfoJobAction>(dSYMAction));
2225+
if (TC.getTriple().isOSDarwin()) {
2226+
switch (OI.LinkAction) {
2227+
case LinkKind::Executable:
2228+
case LinkKind::DynamicLibrary:
2229+
if (OI.DebugInfoLevel > IRGenDebugInfoLevel::None) {
2230+
auto *dSYMAction = C.createAction<GenerateDSYMJobAction>(LinkAction);
2231+
TopLevelActions.push_back(dSYMAction);
2232+
if (Args.hasArg(options::OPT_verify_debug_info)) {
2233+
TopLevelActions.push_back(
2234+
C.createAction<VerifyDebugInfoJobAction>(dSYMAction));
2235+
}
2236+
}
2237+
break;
2238+
2239+
case LinkKind::None:
2240+
LLVM_FALLTHROUGH;
2241+
case LinkKind::StaticLibrary:
2242+
// Cannot build the DSYM bundle for non-image targets.
2243+
break;
22322244
}
22332245
}
22342246
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %swiftc_driver -driver-print-actions -target x86_64-apple-macosx10.15 -g -emit-library -static -o library.a %s 2>&1 | %FileCheck %s -check-prefix CHECK -check-prefix CHECK-STATIC
2+
// RUN: %swiftc_driver -driver-print-actions -target x86_64-apple-macosx10.15 -g -emit-library -o library.a %s 2>&1 | %FileCheck %s -check-prefix CHECK -check-prefix CHECK-SHARED
3+
// RUN: %swiftc_driver -driver-print-actions -target x86_64-apple-macosx10.15 -g -o a.out %s 2>&1 | %FileCheck %s -check-prefix CHECK -check-prefix CHECK-EXEC
4+
5+
// CHECK: 0: input, "{{.*}}darwin-static-library-debug.swift", swift
6+
// CHECK: 1: compile, {0}, object
7+
// CHECK: 2: merge-module, {1}, swiftmodule
8+
// CHECK-STATIC: 3: static-link, {1, 2}, image
9+
// CHECK-STATIC-NOT: 4: generate-dSYM, {3}, dSYM
10+
// CHECK-SHARED: 3: link, {1, 2}, image
11+
// CHECK-SHARED: 4: generate-dSYM, {3}, dSYM
12+
// CHECK-EXEC: 3: link, {1, 2}, image
13+
// CHECK-EXEC: 4: generate-dSYM, {3}, dSYM
14+

0 commit comments

Comments
 (0)