Skip to content

[dsymutil] Deduplicate Swift modules by path before copying them #10663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/test/tools/dsymutil/ARM/swiftmodule.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
# CHECK-NOT: Skipping compiled textual Swift interface: {{.*}}/Inputs/Binary.swiftmodule
# CHECK: Skipping compiled textual Swift interface: {{.*}}/Inputs/FromInterface.swiftmodule
# CHECK-NOT: Skipping compiled textual Swift interface: {{.*}}/Inputs/FromInterface.swiftmodule

#
---
Expand All @@ -26,4 +27,8 @@ objects:
timestamp: 0
type: 50
symbols: []
- filename: '../Inputs/FromInterface.swiftmodule'
timestamp: 0
type: 50
symbols: []
...
5 changes: 5 additions & 0 deletions llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/BinaryFormat/MachO.h"
Expand Down Expand Up @@ -771,6 +772,7 @@ bool DwarfLinkerForBinary::linkImpl(
MaxDWARFVersion = std::max(Unit.getVersion(), MaxDWARFVersion);
};

llvm::StringSet<> SwiftModules;
for (const auto &Obj : Map.objects()) {
// N_AST objects (swiftmodule files) should get dumped directly into the
// appropriate DWARF section.
Expand All @@ -779,6 +781,9 @@ bool DwarfLinkerForBinary::linkImpl(
outs() << "DEBUG MAP OBJECT: " << Obj->getObjectFilename() << "\n";

StringRef File = Obj->getObjectFilename();
if (!SwiftModules.insert(File).second)
continue;

auto ErrorOrMem = MemoryBuffer::getFile(File);
if (!ErrorOrMem) {
reportWarning("Could not open '" + File + "'");
Expand Down