Skip to content

Commit 6ffcb29

Browse files
nagisadwblaikie
authored andcommitted
[llvm-dwp] Join dwo paths correctly when DWOPath is absolute
When the `DWOPath` is absolute, we want to use `DWOPath` as is, without prepending any other components to the path. The `sys::path::append` does not join, but rather unconditionally appends the paths, so something like `sys::path::append("/tmp", "/tmp/banana")` will result in `/tmp/tmp/banana` rather than the desired `/tmp/banana`. This then causes `llvm-dwp` to fail in a following situation: ``` $ clang -gsplit-dwarf /tmp/banana/test.c -c -o /tmp/outdir/foo.o $ clang outdir/foo.o -o outdir/hm $ llvm-dwarfdump outdir/hm | grep -C2 foo.dwo DW_AT_comp_dir ("/tmp") DW_AT_GNU_pubnames (true) DW_AT_GNU_dwo_name ("/tmp/outdir/foo.dwo") DW_AT_GNU_dwo_id (0xde4d396f3bf0e257) DW_AT_low_pc (0x0000000000401100) $ strace -o trace llvm-dwp -e outdir/hm -o outdir/hm.dwp error: No such file or directory $ cat trace | grep foo.dwo openat(AT_FDCWD, "/tmp/tmp/outdir/foo.dwo", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) ``` Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D96678
1 parent f8af06d commit 6ffcb29

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: rm -rf %t
2+
; RUN: mkdir -p %t
3+
; RUN: llc %s -mtriple=x86_64-linux --split-dwarf-file=%t/test.dwo --split-dwarf-output=%t/test.dwo --filetype=obj -o %t/test.o
4+
; RUN: llvm-dwarfdump -v %t/test.dwo | FileCheck %s -DPATH=%t
5+
; RUN: llvm-dwp -e %t/test.o -o %t/test.dwp
6+
; RUN: llvm-dwarfdump -v %t/test.dwp | FileCheck %s -DPATH=%t
7+
8+
; CHECK-LABEL: .debug_abbrev.dwo contents:
9+
; CHECK: DW_AT_name
10+
; CHECK: DW_AT_GNU_dwo_name
11+
; CHECK: DW_AT_name
12+
; CHECK-LABEL: .debug_str.dwo contents:
13+
; CHECK: "banana"
14+
; CHECK: "/tmp/test.c"
15+
; CHECK: "[[PATH]]/test.dwo"
16+
17+
define void @banana() !dbg !8 {
18+
ret void, !dbg !12
19+
}
20+
21+
!llvm.dbg.cu = !{!0}
22+
!llvm.module.flags = !{!3, !4, !5, !6}
23+
!llvm.ident = !{!7}
24+
25+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.1", isOptimized: true, runtimeVersion: 0, splitDebugFilename: "test.dwo", emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: GNU)
26+
!1 = !DIFile(filename: "/tmp/test.c", directory: "/tmp")
27+
!2 = !{}
28+
!3 = !{i32 7, !"Dwarf Version", i32 4}
29+
!4 = !{i32 2, !"Debug Info Version", i32 3}
30+
!5 = !{i32 1, !"wchar_size", i32 4}
31+
!6 = !{i32 7, !"PIC Level", i32 2}
32+
!7 = !{!"clang version 11.0.1"}
33+
!8 = distinct !DISubprogram(name: "banana", scope: !9, file: !9, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
34+
!9 = !DIFile(filename: "test.c", directory: "/tmp")
35+
!10 = !DISubroutineType(types: !11)
36+
!11 = !{null}
37+
!12 = !DILocation(line: 1, column: 20, scope: !8)

llvm/tools/llvm-dwp/llvm-dwp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ getDWOFilenames(StringRef ExecFilename) {
526526
std::string DWOCompDir =
527527
dwarf::toString(Die.find(dwarf::DW_AT_comp_dir), "");
528528
if (!DWOCompDir.empty()) {
529-
SmallString<16> DWOPath;
530-
sys::path::append(DWOPath, DWOCompDir, DWOName);
529+
SmallString<16> DWOPath(std::move(DWOName));
530+
sys::fs::make_absolute(DWOCompDir, DWOPath);
531531
DWOPaths.emplace_back(DWOPath.data(), DWOPath.size());
532532
} else {
533533
DWOPaths.push_back(std::move(DWOName));

0 commit comments

Comments
 (0)