Skip to content

Commit 96f0937

Browse files
authored
[dsymutil] Add option to copy swiftmodules built from interface (#165293)
The default behavior is to _not_ copy such swiftmodules into the dSYM, as perviously implemented in 96f95c9. This patch adds the option to override the behavior, so that such swiftmodules can be copied into the dSYM. This is useful when the dSYM will be used on a machine which has a different Xcode/SDK than where the swiftmodules were built. Without this, when LLDB is asked to "p/po" a Swift variable, the underlying Swift compiler code would rebuild the dependent `.swiftmodule` files of the Swift stdlibs, which takes ~1 minute in some cases. See PR for tests.
1 parent 346da3d commit 96f0937

File tree

7 files changed

+64
-3
lines changed

7 files changed

+64
-3
lines changed

llvm/docs/CommandGuide/dsymutil.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ OPTIONS
7070

7171
Print this help output.
7272

73+
.. option:: --include-swiftmodules-from-interface
74+
75+
Whether or not to copy binary swiftmodules built from textual .swiftinterface
76+
files into the dSYM bundle. These typically come only from the SDK (since
77+
textual interfaces require library evolution) and thus are a waste of space to
78+
copy into the bundle. Turn this on if the swiftmodules are different from
79+
those in the SDK.
80+
7381
.. option:: --keep-function-for-static
7482

7583
Make a static variable keep the enclosing function even if it would have been
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# RUN: dsymutil -include-swiftmodules-from-interface -verbose -oso-prepend-path=%p -y -o %t.dSYM %s | FileCheck %s
2+
#
3+
# RUN: dsymutil -include-swiftmodules-from-interface --linker parallel -verbose -oso-prepend-path=%p -y %s -o %t-parallel.dSYM | FileCheck %s
4+
#
5+
# To regenerate:
6+
# echo ''>I.swift
7+
# echo ''>B.swift
8+
# echo 'import I'>main.swift
9+
# xcrun swiftc -emit-module-interface-path I.swiftinterface -enable-library-evolution I.swift
10+
# xcrun swiftc -emit-module-path B.swiftmodule B.swift -Xfrontend -no-serialize-debugging-options
11+
# xcrun swiftc -explicit-module-build main.swift -I. -module-cache-path cache -g -Xfrontend -no-serialize-debugging-options
12+
# output is "B.swiftmodule" and "cache/I*.swiftmodule"
13+
#
14+
# CHECK-NOT: Skipping compiled textual Swift interface: {{.*}}/Inputs/Binary.swiftmodule
15+
# CHECK-NOT: Skipping compiled textual Swift interface: {{.*}}/Inputs/FromInterface.swiftmodule
16+
17+
#
18+
---
19+
triple: 'arm64-apple-darwin'
20+
objects:
21+
- filename: '../Inputs/Binary.swiftmodule'
22+
timestamp: 0
23+
type: 50
24+
symbols: []
25+
- filename: '../Inputs/FromInterface.swiftmodule'
26+
timestamp: 0
27+
type: 50
28+
symbols: []
29+
- filename: '../Inputs/FromInterface.swiftmodule'
30+
timestamp: 0
31+
type: 50
32+
symbols: []
33+
...

llvm/test/tools/dsymutil/cmdline.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHECK: -fat64
1414
CHECK: -flat
1515
CHECK: -gen-reproducer
1616
CHECK: -help
17+
CHECK: -include-swiftmodules-from-interface
1718
CHECK: -keep-function-for-static
1819
CHECK: -no-object-timestamp
1920
CHECK: -no-odr

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,10 @@ bool DwarfLinkerForBinary::linkImpl(
794794
reportWarning("Could not parse binary Swift module: " +
795795
toString(FromInterfaceOrErr.takeError()),
796796
Obj->getObjectFilename());
797-
// Only skip swiftmodules that could be parsed and are
798-
// positively identified as textual.
799-
} else if (*FromInterfaceOrErr) {
797+
// Only skip swiftmodules that could be parsed and are positively
798+
// identified as textual. Do so only when the option allows.
799+
} else if (*FromInterfaceOrErr &&
800+
!Options.IncludeSwiftModulesFromInterface) {
800801
if (Options.Verbose)
801802
outs() << "Skipping compiled textual Swift interface: "
802803
<< Obj->getObjectFilename() << "\n";

llvm/tools/dsymutil/LinkUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ struct LinkOptions {
114114
/// Whether all remarks should be kept or only remarks with valid debug
115115
/// locations.
116116
bool RemarksKeepAll = true;
117+
118+
/// Whether or not to copy binary swiftmodules built from textual
119+
/// .swiftinterface files into the dSYM bundle. These typically come only
120+
/// from the SDK (since textual interfaces require library evolution) and
121+
/// thus are a waste of space to copy into the bundle. Turn this on if the
122+
/// swiftmodules are different from those in the SDK.
123+
bool IncludeSwiftModulesFromInterface = false;
117124
/// @}
118125

119126
LinkOptions() = default;

llvm/tools/dsymutil/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ def remarks_drop_without_debug: Flag<["--", "-"], "remarks-drop-without-debug">,
202202
"all remarks are kept.">,
203203
Group<grp_general>;
204204

205+
def include_swiftmodules_from_interface: Flag<["--", "-"], "include-swiftmodules-from-interface">,
206+
HelpText<"Whether or not to copy binary swiftmodules built from textual "
207+
".swiftinterface files into the dSYM bundle. These typically come only "
208+
"from the SDK (since textual interfaces require library evolution) and "
209+
"thus are a waste of space to copy into the bundle. Turn this on if the "
210+
"swiftmodules are different from those in the SDK.">,
211+
Group<grp_general>;
212+
205213
def linker: Separate<["--", "-"], "linker">,
206214
MetaVarName<"<DWARF linker type>">,
207215
HelpText<"Specify the desired type of DWARF linker. Defaults to 'classic'">,

llvm/tools/dsymutil/dsymutil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
391391
Options.LinkOpts.RemarksKeepAll =
392392
!Args.hasArg(OPT_remarks_drop_without_debug);
393393

394+
Options.LinkOpts.IncludeSwiftModulesFromInterface =
395+
Args.hasArg(OPT_include_swiftmodules_from_interface);
396+
394397
if (opt::Arg *BuildVariantSuffix = Args.getLastArg(OPT_build_variant_suffix))
395398
Options.LinkOpts.BuildVariantSuffix = BuildVariantSuffix->getValue();
396399

0 commit comments

Comments
 (0)