Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2e3ef19

Browse files
committed
[BPF] [BTF] Process FileName with absolute path correctly
In IR, sometimes the following attributes for DIFile may be generated: filename: /home/yhs/test.c directory: /tmp The /tmp may represent the working directory of the compilation process. In such cases, since filename is with absolute path, the directory should be ignored by BTF. The filename alone is enough to get the source. Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Yonghong Song <[email protected]> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352952 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d9a8f32 commit 2e3ef19

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

lib/Target/BPF/BTFDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ std::string BTFDebug::populateFileContent(const DISubprogram *SP) {
493493
auto File = SP->getFile();
494494
std::string FileName;
495495

496-
if (File->getDirectory().size())
496+
if (!File->getFilename().startswith("/") && File->getDirectory().size())
497497
FileName = File->getDirectory().str() + "/" + File->getFilename().str();
498498
else
499499
FileName = File->getFilename();

test/CodeGen/BPF/BTF/filename.ll

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
2+
; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
3+
4+
; Source code:
5+
; int test() { return 0; }
6+
; Compilation flag:
7+
; clang -target bpf -O2 -g -S -emit-llvm t.c
8+
9+
; Function Attrs: norecurse nounwind readnone uwtable
10+
define dso_local i32 @test() local_unnamed_addr #0 !dbg !7 {
11+
ret i32 0, !dbg !11
12+
}
13+
14+
; CHECK: .section .BTF,"",@progbits
15+
; CHECK-NEXT: .short 60319 # 0xeb9f
16+
; CHECK-NEXT: .byte 1
17+
; CHECK-NEXT: .byte 0
18+
; CHECK-NEXT: .long 24
19+
; CHECK-NEXT: .long 0
20+
; CHECK-NEXT: .long 40
21+
; CHECK-NEXT: .long 40
22+
; CHECK-NEXT: .long 35
23+
; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
24+
; CHECK-NEXT: .long 218103808 # 0xd000000
25+
; CHECK-NEXT: .long 2
26+
; CHECK-NEXT: .long 26 # BTF_KIND_INT(id = 2)
27+
; CHECK-NEXT: .long 16777216 # 0x1000000
28+
; CHECK-NEXT: .long 4
29+
; CHECK-NEXT: .long 16777248 # 0x1000020
30+
; CHECK-NEXT: .long 30 # BTF_KIND_FUNC(id = 3)
31+
; CHECK-NEXT: .long 201326592 # 0xc000000
32+
; CHECK-NEXT: .long 1
33+
; CHECK-NEXT: .byte 0 # string offset=0
34+
; CHECK-NEXT: .ascii ".text" # string offset=1
35+
; CHECK-NEXT: .byte 0
36+
; CHECK-NEXT: .ascii "/home/yhs/ttmp/t.c" # string offset=7
37+
; CHECK-NEXT: .byte 0
38+
; CHECK-NEXT: .ascii "int" # string offset=26
39+
; CHECK-NEXT: .byte 0
40+
; CHECK-NEXT: .ascii "test" # string offset=30
41+
; CHECK-NEXT: .byte 0
42+
; CHECK-NEXT: .section .BTF.ext,"",@progbits
43+
; CHECK-NEXT: .short 60319 # 0xeb9f
44+
; CHECK-NEXT: .byte 1
45+
; CHECK-NEXT: .byte 0
46+
; CHECK-NEXT: .long 24
47+
; CHECK-NEXT: .long 0
48+
; CHECK-NEXT: .long 20
49+
; CHECK-NEXT: .long 20
50+
; CHECK-NEXT: .long 28
51+
; CHECK-NEXT: .long 8 # FuncInfo
52+
; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
53+
; CHECK-NEXT: .long 1
54+
; CHECK-NEXT: .long .Lfunc_begin{{[0-9]+}}
55+
; CHECK-NEXT: .long 3
56+
; CHECK-NEXT: .long 16 # LineInfo
57+
; CHECK-NEXT: .long 1 # LineInfo section string offset=1
58+
; CHECK-NEXT: .long 1
59+
; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
60+
; CHECK-NEXT: .long 7
61+
; CHECK-NEXT: .long 0
62+
; CHECK-NEXT: .long 1038 # Line 1 Col 14
63+
64+
attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
65+
66+
!llvm.dbg.cu = !{!0}
67+
!llvm.module.flags = !{!3, !4, !5}
68+
!llvm.ident = !{!6}
69+
70+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
71+
!1 = !DIFile(filename: "/home/yhs/ttmp/t.c", directory: "/home/yhs/ttmp")
72+
!2 = !{}
73+
!3 = !{i32 2, !"Dwarf Version", i32 4}
74+
!4 = !{i32 2, !"Debug Info Version", i32 3}
75+
!5 = !{i32 1, !"wchar_size", i32 4}
76+
!6 = !{!"clang version 8.0.20181009 "}
77+
!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !2)
78+
!8 = !DISubroutineType(types: !9)
79+
!9 = !{!10}
80+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
81+
!11 = !DILocation(line: 1, column: 14, scope: !7)

0 commit comments

Comments
 (0)