[dsymutil] Fall back to compatible triple in BinaryHolder#186893
Open
JDevlieghere wants to merge 1 commit intollvm:mainfrom
Open
[dsymutil] Fall back to compatible triple in BinaryHolder#186893JDevlieghere wants to merge 1 commit intollvm:mainfrom
JDevlieghere wants to merge 1 commit intollvm:mainfrom
Conversation
When dsymutil can't find an exact match in its BinaryHolder, fall back to a compatible triple instead of erroring out completely. rdar://171676213
Member
|
@llvm/pr-subscribers-debuginfo Author: Jonas Devlieghere (JDevlieghere) ChangesWhen dsymutil can't find an exact match in its BinaryHolder, fall back to a compatible triple instead of erroring out completely. rdar://171676213 Full diff: https://github.com/llvm/llvm-project/pull/186893.diff 2 Files Affected:
diff --git a/llvm/test/tools/dsymutil/X86/fat-object-compatible-triple.test b/llvm/test/tools/dsymutil/X86/fat-object-compatible-triple.test
new file mode 100644
index 0000000000000..e5f15c79ae130
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/fat-object-compatible-triple.test
@@ -0,0 +1,23 @@
+# Verify that dsymutil can match an object file by compatible triple when there
+# is no exact string match (e.g. the debug map triple has a version suffix that
+# the object file triple lacks).
+
+# RUN: dsymutil -f -oso-prepend-path=%p/../Inputs -y %s -o - | llvm-dwarfdump -debug-info - | FileCheck %s
+
+# RUN: dsymutil --linker parallel -f -oso-prepend-path=%p/../Inputs -y %s -o - | llvm-dwarfdump -debug-info - | FileCheck %s
+
+# The fat-test.o object reports its x86_64 slice as "x86_64-apple-darwin".
+# Using "x86_64-apple-darwin20" here exercises the compatible-triple fallback:
+# the strings differ, but the triples are compatible (same arch, vendor, OS kind).
+---
+triple: 'x86_64-apple-darwin20'
+objects:
+ - filename: fat-test.o
+ symbols:
+ - { sym: _x86_64_var, objAddr: 0x0, binAddr: 0x1000, size: 0x4 }
+...
+
+# CHECK: .debug_info contents:
+# CHECK: DW_TAG_variable
+# CHECK-NOT: {{DW_TAG|NULL}}
+# CHECK: DW_AT_name{{.*}}"x86_64_var"
diff --git a/llvm/tools/dsymutil/BinaryHolder.cpp b/llvm/tools/dsymutil/BinaryHolder.cpp
index 58751bddd3ba7..c4eec36c8b161 100644
--- a/llvm/tools/dsymutil/BinaryHolder.cpp
+++ b/llvm/tools/dsymutil/BinaryHolder.cpp
@@ -155,13 +155,25 @@ BinaryHolder::ObjectEntry::getObjects() const {
}
Expected<const object::ObjectFile &>
BinaryHolder::ObjectEntry::getObject(const Triple &T) const {
+ // Prefer an exact match, but settle for a compatible match if there is one.
+ object::ObjectFile const *CompatibleMatch = nullptr;
for (const auto &Obj : Objects) {
if (const auto *MachO = dyn_cast<object::MachOObjectFile>(Obj.get())) {
- if (MachO->getArchTriple().str() == T.str())
+ llvm::Triple ObjTriple = MachO->getArchTriple();
+ if (ObjTriple.str() == T.str())
return *MachO;
- } else if (Obj->getArch() == T.getArch())
- return *Obj;
+ if (ObjTriple.isCompatibleWith(T) && !CompatibleMatch)
+ CompatibleMatch = MachO;
+ } else {
+ llvm::Triple ObjTriple = Obj->makeTriple();
+ if (ObjTriple.str() == T.str())
+ return *Obj;
+ if (!CompatibleMatch && ObjTriple.isCompatibleWith(T))
+ CompatibleMatch = Obj.get();
+ }
}
+ if (CompatibleMatch)
+ return *CompatibleMatch;
return errorCodeToError(object::object_error::arch_not_found);
}
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When dsymutil can't find an exact match in its BinaryHolder, fall back to a compatible triple instead of erroring out completely.
rdar://171676213