Skip to content

Commit ccee9b7

Browse files
committed
[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
1 parent 6576726 commit ccee9b7

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,8 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
15891589
if (!AttrInfo.Name)
15901590
AttrInfo.Name = StringPool.getEntry("(anonymous namespace)");
15911591
Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
1592+
} else if (Tag == dwarf::DW_TAG_imported_declaration && AttrInfo.Name) {
1593+
Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
15921594
} else if (isTypeTag(Tag) && !AttrInfo.IsDeclaration &&
15931595
getDIENames(InputDIE, AttrInfo, StringPool) && AttrInfo.Name &&
15941596
AttrInfo.Name.getString()[0]) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
RUN: dsymutil -accelerator=Dwarf %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM
2+
RUN: dsymutil -accelerator=Apple %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM
3+
4+
RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON
5+
RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON
6+
7+
COMMON: .debug_info contents
8+
COMMON: {{.*}}DW_TAG_namespace
9+
COMMON: DW_AT_name{{.*}}"A"
10+
COMMON: {{.*}}DW_TAG_namespace
11+
COMMON: DW_AT_name{{.*}}"B"
12+
COMMON: [[NAMESPACE:0x[0-9a-f]*]]:{{.*}}DW_TAG_namespace
13+
COMMON: DW_AT_name{{.*}}"C"
14+
COMMON: [[IMPORTED:0x[0-9a-f]*]]:{{.*}}DW_TAG_imported_declaration
15+
COMMON: DW_AT_name{{.*}}"C"
16+
17+
DWARF: .debug_names contents:
18+
DWARF: Bucket 0 [
19+
DWARF-NEXT: Name {{.*}} {
20+
DWARF-NEXT: Hash: {{.*}}
21+
DWARF-NEXT: String: {{.*}} "C"
22+
DWARF-NEXT: Entry {{.*}} {
23+
DWARF-NEXT: Abbrev: {{.*}}
24+
DWARF-NEXT: Tag: DW_TAG_namespace
25+
DWARF-NEXT: DW_IDX_die_offset: [[NAMESPACE]]
26+
DWARF-NEXT: }
27+
DWARF-NEXT: Entry {{.*}} {
28+
DWARF-NEXT: Abbrev: {{.*}}
29+
DWARF-NEXT: Tag: DW_TAG_imported_declaration
30+
DWARF-NEXT: DW_IDX_die_offset: [[IMPORTED]]
31+
DWARF-NEXT: }
32+
DWARF-NEXT: }
33+
34+
APPLE: .apple_namespaces contents:
35+
APPLE: Bucket 1 [
36+
APPLE-NEXT: Hash {{.*}} [
37+
APPLE-NEXT: Name@{{.*}} {
38+
APPLE-NEXT: String: {{.*}} "C"
39+
APPLE-NEXT: Data 0 [
40+
APPLE-NEXT: Atom[0]: [[NAMESPACE]]
41+
APPLE-NEXT: ]
42+
APPLE-NEXT: Data 1 [
43+
APPLE-NEXT: Atom[0]: [[IMPORTED]]
44+
APPLE-NEXT: ]
45+
APPLE-NEXT: }
46+
APPLE-NEXT: ]
47+
APPLE-NEXT: ]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Compiled on macOS using:
2+
// clang++ -c -std=c++2a -gdwarf-4 -O0 -o accel-imported-declaration.macho-arm64.o
3+
4+
namespace A {
5+
namespace B {
6+
namespace C {
7+
int a = -1;
8+
} // namespace C
9+
} // namespace B
10+
11+
namespace C = B::C;
12+
13+
using namespace B::C;
14+
using B::C::a;
15+
} // namespace A
16+
17+
int main() { return A::a; }
Binary file not shown.

0 commit comments

Comments
 (0)