Skip to content

Commit f667b6d

Browse files
compnerdgottesmm
authored andcommitted
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 dc34c13 commit f667b6d

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
@@ -2223,13 +2223,25 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
22232223
}
22242224
TopLevelActions.push_back(LinkAction);
22252225

2226-
if (TC.getTriple().isOSDarwin() &&
2227-
OI.DebugInfoLevel > IRGenDebugInfoLevel::None) {
2228-
auto *dSYMAction = C.createAction<GenerateDSYMJobAction>(LinkAction);
2229-
TopLevelActions.push_back(dSYMAction);
2230-
if (Args.hasArg(options::OPT_verify_debug_info)) {
2231-
TopLevelActions.push_back(
2232-
C.createAction<VerifyDebugInfoJobAction>(dSYMAction));
2226+
if (TC.getTriple().isOSDarwin()) {
2227+
switch (OI.LinkAction) {
2228+
case LinkKind::Executable:
2229+
case LinkKind::DynamicLibrary:
2230+
if (OI.DebugInfoLevel > IRGenDebugInfoLevel::None) {
2231+
auto *dSYMAction = C.createAction<GenerateDSYMJobAction>(LinkAction);
2232+
TopLevelActions.push_back(dSYMAction);
2233+
if (Args.hasArg(options::OPT_verify_debug_info)) {
2234+
TopLevelActions.push_back(
2235+
C.createAction<VerifyDebugInfoJobAction>(dSYMAction));
2236+
}
2237+
}
2238+
break;
2239+
2240+
case LinkKind::None:
2241+
LLVM_FALLTHROUGH;
2242+
case LinkKind::StaticLibrary:
2243+
// Cannot build the DSYM bundle for non-image targets.
2244+
break;
22332245
}
22342246
}
22352247
} 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)