[llvm] ccee9b7 - [llvm][dsymutil] Add DW_TAG_imported_declaration to accelerator table
Michael Buch via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 9 17:34:26 PST 2023
Author: Michael Buch
Date: 2023-02-10T01:33:51Z
New Revision: ccee9b7839a182fc692a65f563abf76f81dd436c
URL: https://github.com/llvm/llvm-project/commit/ccee9b7839a182fc692a65f563abf76f81dd436c
DIFF: https://github.com/llvm/llvm-project/commit/ccee9b7839a182fc692a65f563abf76f81dd436c.diff
LOG: [llvm][dsymutil] Add DW_TAG_imported_declaration to accelerator table
**Summary**
After this patch, `dsymutil` will preserve `DW_TAG_imported_declarations`
entries in accelerator tables.
This allows consumers to resolve imported declarations even on
executables processsed through dsymutil.
This helps consumers, particularly LLDB's expression evaluator,
to resolve imported declarations (i.e., useful for namespace aliases
in C++) more efficiently.
**Testing**
* Added unit-test
Differential Revision: https://reviews.llvm.org/D143458
Added:
llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp
llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64
Modified:
llvm/lib/DWARFLinker/DWARFLinker.cpp
Removed:
################################################################################
diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index d302d61894fa6..6d6bd3385dfc2 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -1589,6 +1589,8 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
if (!AttrInfo.Name)
AttrInfo.Name = StringPool.getEntry("(anonymous namespace)");
Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
+ } else if (Tag == dwarf::DW_TAG_imported_declaration && AttrInfo.Name) {
+ Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
} else if (isTypeTag(Tag) && !AttrInfo.IsDeclaration &&
getDIENames(InputDIE, AttrInfo, StringPool) && AttrInfo.Name &&
AttrInfo.Name.getString()[0]) {
diff --git a/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test b/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
new file mode 100644
index 0000000000000..1c5916712dc71
--- /dev/null
+++ b/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
@@ -0,0 +1,47 @@
+RUN: dsymutil -accelerator=Dwarf %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM
+RUN: dsymutil -accelerator=Apple %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM
+
+RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON
+RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON
+
+COMMON: .debug_info contents
+COMMON: {{.*}}DW_TAG_namespace
+COMMON: DW_AT_name{{.*}}"A"
+COMMON: {{.*}}DW_TAG_namespace
+COMMON: DW_AT_name{{.*}}"B"
+COMMON: [[NAMESPACE:0x[0-9a-f]*]]:{{.*}}DW_TAG_namespace
+COMMON: DW_AT_name{{.*}}"C"
+COMMON: [[IMPORTED:0x[0-9a-f]*]]:{{.*}}DW_TAG_imported_declaration
+COMMON: DW_AT_name{{.*}}"C"
+
+DWARF: .debug_names contents:
+DWARF: Bucket 0 [
+DWARF-NEXT: Name {{.*}} {
+DWARF-NEXT: Hash: {{.*}}
+DWARF-NEXT: String: {{.*}} "C"
+DWARF-NEXT: Entry {{.*}} {
+DWARF-NEXT: Abbrev: {{.*}}
+DWARF-NEXT: Tag: DW_TAG_namespace
+DWARF-NEXT: DW_IDX_die_offset: [[NAMESPACE]]
+DWARF-NEXT: }
+DWARF-NEXT: Entry {{.*}} {
+DWARF-NEXT: Abbrev: {{.*}}
+DWARF-NEXT: Tag: DW_TAG_imported_declaration
+DWARF-NEXT: DW_IDX_die_offset: [[IMPORTED]]
+DWARF-NEXT: }
+DWARF-NEXT: }
+
+APPLE: .apple_namespaces contents:
+APPLE: Bucket 1 [
+APPLE-NEXT: Hash {{.*}} [
+APPLE-NEXT: Name@{{.*}} {
+APPLE-NEXT: String: {{.*}} "C"
+APPLE-NEXT: Data 0 [
+APPLE-NEXT: Atom[0]: [[NAMESPACE]]
+APPLE-NEXT: ]
+APPLE-NEXT: Data 1 [
+APPLE-NEXT: Atom[0]: [[IMPORTED]]
+APPLE-NEXT: ]
+APPLE-NEXT: }
+APPLE-NEXT: ]
+APPLE-NEXT: ]
diff --git a/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp
new file mode 100644
index 0000000000000..2ee98ce0319d8
--- /dev/null
+++ b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp
@@ -0,0 +1,17 @@
+// Compiled on macOS using:
+// clang++ -c -std=c++2a -gdwarf-4 -O0 -o accel-imported-declaration.macho-arm64.o
+
+namespace A {
+namespace B {
+namespace C {
+int a = -1;
+} // namespace C
+} // namespace B
+
+namespace C = B::C;
+
+using namespace B::C;
+using B::C::a;
+} // namespace A
+
+int main() { return A::a; }
diff --git a/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64 b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64
new file mode 100755
index 0000000000000..691d553892e13
Binary files /dev/null and b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64
diff er
More information about the llvm-commits
mailing list