Skip to content

Commit cede236

Browse files
authored
[llvm][DebugInfo] Drop \01 mangling prefix when inserting linkage name into accelerator table (#138852)
On some platforms (particularly macOS), a `\01` prefix gets added to the name in an `asm` label. This gets stripped when we emit the [`DW_AT_linkage_name`](https://github.com/llvm/llvm-project/blob/2f877c2722e882fe6aaaab44d25b7a49ba0612e1/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp#L531). But we weren't stripping this prefix when inserting the linkage name into accelerator tables. This manifested in an issue where LLDB tried to look up a name in the index by linkage name, but wasn't able to find it because we indexed it with the `\01` unstripped. This patch strips the prefix before indexing.
1 parent d78ff5f commit cede236

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,17 @@ void DwarfDebug::addSubprogramNames(
489489
if (SP->getName() != "")
490490
addAccelName(Unit, NameTableKind, SP->getName(), Die);
491491

492+
// We drop the mangling escape prefix when emitting the DW_AT_linkage_name. So
493+
// ensure we don't include it when inserting into the accelerator tables.
494+
llvm::StringRef LinkageName =
495+
GlobalValue::dropLLVMManglingEscape(SP->getLinkageName());
496+
492497
// If the linkage name is different than the name, go ahead and output that as
493498
// well into the name table. Only do that if we are going to actually emit
494499
// that name.
495-
if (SP->getLinkageName() != "" && SP->getName() != SP->getLinkageName() &&
500+
if (LinkageName != "" && SP->getName() != LinkageName &&
496501
(useAllLinkageNames() || InfoHolder.getAbstractScopeDIEs().lookup(SP)))
497-
addAccelName(Unit, NameTableKind, SP->getLinkageName(), Die);
502+
addAccelName(Unit, NameTableKind, LinkageName, Die);
498503

499504
// If this is an Objective-C selector name add it to the ObjC accelerator
500505
// too.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; Tests the mangling escape prefix gets stripped from the linkage name.
2+
;
3+
; RUN: %llc_dwarf -accel-tables=Dwarf -dwarf-linkage-names=All -filetype=obj -o %t < %s
4+
;
5+
; RUN: llvm-dwarfdump -debug-info -debug-names %t | FileCheck %s
6+
; RUN: llvm-dwarfdump -debug-names -verify %t | FileCheck --check-prefix=VERIFY %s
7+
8+
; CHECK: .debug_info contents:
9+
; CHECK: DW_AT_linkage_name ("bar")
10+
; CHECK: .debug_names contents:
11+
; CHECK: String: {{.*}} "bar"
12+
13+
; VERIFY: No errors.
14+
15+
; Input generated from the following C++ code using
16+
; clang -g -S -emit-llvm -target aarch64-apple-macos
17+
18+
; void foo() asm("bar");
19+
; void foo() {}
20+
;
21+
; void g() { foo(); }
22+
23+
define void @"\01bar"() !dbg !9 {
24+
entry:
25+
ret void, !dbg !13
26+
}
27+
28+
define void @_Z1gv() !dbg !14 {
29+
entry:
30+
call void @"\01bar"(), !dbg !15
31+
ret void, !dbg !16
32+
}
33+
34+
!llvm.dbg.cu = !{!0}
35+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
36+
!llvm.ident = !{!8}
37+
38+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
39+
!1 = !DIFile(filename: "asm.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "d053f9249cc5548d446ceb58411ad625")
40+
!2 = !{i32 7, !"Dwarf Version", i32 5}
41+
!3 = !{i32 2, !"Debug Info Version", i32 3}
42+
!4 = !{i32 1, !"wchar_size", i32 4}
43+
!5 = !{i32 8, !"PIC Level", i32 2}
44+
!6 = !{i32 7, !"uwtable", i32 1}
45+
!7 = !{i32 7, !"frame-pointer", i32 1}
46+
!8 = !{!"clang version 21.0.0git"}
47+
!9 = distinct !DISubprogram(name: "foo", linkageName: "\01bar", scope: !10, file: !10, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
48+
!10 = !DIFile(filename: "asm.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "d053f9249cc5548d446ceb58411ad625")
49+
!11 = !DISubroutineType(types: !12)
50+
!12 = !{null}
51+
!13 = !DILocation(line: 2, column: 13, scope: !9)
52+
!14 = distinct !DISubprogram(name: "g", linkageName: "_Z1gv", scope: !10, file: !10, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
53+
!15 = !DILocation(line: 4, column: 12, scope: !14)
54+
!16 = !DILocation(line: 4, column: 19, scope: !14)

0 commit comments

Comments
 (0)