[llvm] [dsymutil] Add option to copy swiftmodules built from interface (PR #165293)
Roy Shi via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 27 11:43:04 PDT 2025
https://github.com/royitaqi created https://github.com/llvm/llvm-project/pull/165293
The default behavior is to _not_ copy such swiftmodules into the dSYM, as perviously set by 96f95c9d89d8a1784d3865fa941fb1c510f4e2d7.
This patch adds the option to override the behavior, so that such swiftmodules _are_ copied into the dSYM. This is useful when the dSYM will be used on a machine which has a different Xcode/SDK.
>From ba2e0fee2c08294862e85cbd81f8e8cbb2ea377f Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Mon, 27 Oct 2025 11:34:11 -0700
Subject: [PATCH 1/3] [dsymutil] Add option to include swiftmodules built from
interface
---
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp | 6 +++---
llvm/tools/dsymutil/LinkUtils.h | 7 +++++++
llvm/tools/dsymutil/Options.td | 8 ++++++++
llvm/tools/dsymutil/dsymutil.cpp | 3 +++
4 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index b91c27e6a0f86..7f7fce49d3e71 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -794,9 +794,9 @@ bool DwarfLinkerForBinary::linkImpl(
reportWarning("Could not parse binary Swift module: " +
toString(FromInterfaceOrErr.takeError()),
Obj->getObjectFilename());
- // Only skip swiftmodules that could be parsed and are
- // positively identified as textual.
- } else if (*FromInterfaceOrErr) {
+ // Only skip swiftmodules that could be parsed and are positively
+ // identified as textual. Do so only when the option allows.
+ } else if (*FromInterfaceOrErr && !Options.IncludeSwiftModulesFromInterface) {
if (Options.Verbose)
outs() << "Skipping compiled textual Swift interface: "
<< Obj->getObjectFilename() << "\n";
diff --git a/llvm/tools/dsymutil/LinkUtils.h b/llvm/tools/dsymutil/LinkUtils.h
index ad5515a04333e..c333a3d4afee0 100644
--- a/llvm/tools/dsymutil/LinkUtils.h
+++ b/llvm/tools/dsymutil/LinkUtils.h
@@ -114,6 +114,13 @@ struct LinkOptions {
/// Whether all remarks should be kept or only remarks with valid debug
/// locations.
bool RemarksKeepAll = true;
+
+ /// Whether or not to copy binary swiftmodules built from textual
+ /// .swiftinterface files into the dSYM bundle. These typically come only
+ /// from the SDK (since textual interfaces require library evolution) and
+ /// thus are a waste of space to copy into the bundle. Turn this on if the
+ /// swiftmodules are different from those in the SDK.
+ bool IncludeSwiftModulesFromInterface = false;
/// @}
LinkOptions() = default;
diff --git a/llvm/tools/dsymutil/Options.td b/llvm/tools/dsymutil/Options.td
index ad35e55e33b12..e99bc12fa7fd8 100644
--- a/llvm/tools/dsymutil/Options.td
+++ b/llvm/tools/dsymutil/Options.td
@@ -202,6 +202,14 @@ def remarks_drop_without_debug: Flag<["--", "-"], "remarks-drop-without-debug">,
"all remarks are kept.">,
Group<grp_general>;
+def include_swiftmodules_from_interface: Flag<["--", "-"], "include-swiftmodules-from-interface">,
+ HelpText<"Whether or not to copy binary swiftmodules built from textual "
+ ".swiftinterface files into the dSYM bundle. These typically come only "
+ "from the SDK (since textual interfaces require library evolution) and "
+ "thus are a waste of space to copy into the bundle. Turn this on if the "
+ "swiftmodules are different from those in the SDK.">,
+ Group<grp_general>;
+
def linker: Separate<["--", "-"], "linker">,
MetaVarName<"<DWARF linker type>">,
HelpText<"Specify the desired type of DWARF linker. Defaults to 'classic'">,
diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 913077eb0b06d..688f6aaf3d0c9 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -391,6 +391,9 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
Options.LinkOpts.RemarksKeepAll =
!Args.hasArg(OPT_remarks_drop_without_debug);
+ Options.LinkOpts.IncludeSwiftModulesFromInterface =
+ Args.hasArg(OPT_include_swiftmodules_from_interface);
+
if (opt::Arg *BuildVariantSuffix = Args.getLastArg(OPT_build_variant_suffix))
Options.LinkOpts.BuildVariantSuffix = BuildVariantSuffix->getValue();
>From 1c3fba579db64cda96c00a2bbc87b571871ac845 Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Mon, 27 Oct 2025 11:41:46 -0700
Subject: [PATCH 2/3] Add to cmdline.test
---
llvm/test/tools/dsymutil/cmdline.test | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/test/tools/dsymutil/cmdline.test b/llvm/test/tools/dsymutil/cmdline.test
index 1574fe35f5254..0b0bce194d575 100644
--- a/llvm/test/tools/dsymutil/cmdline.test
+++ b/llvm/test/tools/dsymutil/cmdline.test
@@ -14,6 +14,7 @@ CHECK: -fat64
CHECK: -flat
CHECK: -gen-reproducer
CHECK: -help
+CHECK: -include-swiftmodules-from-interface
CHECK: -keep-function-for-static
CHECK: -no-object-timestamp
CHECK: -no-odr
>From 1945d6a40506342b7ea47a325f151268437673bd Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Mon, 27 Oct 2025 11:42:19 -0700
Subject: [PATCH 3/3] Fix format
---
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 7f7fce49d3e71..ee1e9060657b0 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -796,7 +796,8 @@ bool DwarfLinkerForBinary::linkImpl(
Obj->getObjectFilename());
// Only skip swiftmodules that could be parsed and are positively
// identified as textual. Do so only when the option allows.
- } else if (*FromInterfaceOrErr && !Options.IncludeSwiftModulesFromInterface) {
+ } else if (*FromInterfaceOrErr &&
+ !Options.IncludeSwiftModulesFromInterface) {
if (Options.Verbose)
outs() << "Skipping compiled textual Swift interface: "
<< Obj->getObjectFilename() << "\n";
More information about the llvm-commits
mailing list