[llvm] r352952 - [BPF] [BTF] Process FileName with absolute path correctly
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 1 21:54:59 PST 2019
Author: yhs
Date: Fri Feb 1 21:54:59 2019
New Revision: 352952
URL: http://llvm.org/viewvc/llvm-project?rev=352952&view=rev
Log:
[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 <ast at kernel.org>
Signed-off-by: Yonghong Song <yhs at fb.com>
Added:
llvm/trunk/test/CodeGen/BPF/BTF/filename.ll
Modified:
llvm/trunk/lib/Target/BPF/BTFDebug.cpp
Modified: llvm/trunk/lib/Target/BPF/BTFDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BTFDebug.cpp?rev=352952&r1=352951&r2=352952&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BTFDebug.cpp (original)
+++ llvm/trunk/lib/Target/BPF/BTFDebug.cpp Fri Feb 1 21:54:59 2019
@@ -493,7 +493,7 @@ std::string BTFDebug::populateFileConten
auto File = SP->getFile();
std::string FileName;
- if (File->getDirectory().size())
+ if (!File->getFilename().startswith("/") && File->getDirectory().size())
FileName = File->getDirectory().str() + "/" + File->getFilename().str();
else
FileName = File->getFilename();
Added: llvm/trunk/test/CodeGen/BPF/BTF/filename.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/BTF/filename.ll?rev=352952&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/filename.ll (added)
+++ llvm/trunk/test/CodeGen/BPF/BTF/filename.ll Fri Feb 1 21:54:59 2019
@@ -0,0 +1,81 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+
+; Source code:
+; int test() { return 0; }
+; Compilation flag:
+; clang -target bpf -O2 -g -S -emit-llvm t.c
+
+; Function Attrs: norecurse nounwind readnone uwtable
+define dso_local i32 @test() local_unnamed_addr #0 !dbg !7 {
+ ret i32 0, !dbg !11
+}
+
+; CHECK: .section .BTF,"", at progbits
+; CHECK-NEXT: .short 60319 # 0xeb9f
+; CHECK-NEXT: .byte 1
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .long 24
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 40
+; CHECK-NEXT: .long 40
+; CHECK-NEXT: .long 35
+; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 1)
+; CHECK-NEXT: .long 218103808 # 0xd000000
+; CHECK-NEXT: .long 2
+; CHECK-NEXT: .long 26 # BTF_KIND_INT(id = 2)
+; CHECK-NEXT: .long 16777216 # 0x1000000
+; CHECK-NEXT: .long 4
+; CHECK-NEXT: .long 16777248 # 0x1000020
+; CHECK-NEXT: .long 30 # BTF_KIND_FUNC(id = 3)
+; CHECK-NEXT: .long 201326592 # 0xc000000
+; CHECK-NEXT: .long 1
+; CHECK-NEXT: .byte 0 # string offset=0
+; CHECK-NEXT: .ascii ".text" # string offset=1
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .ascii "/home/yhs/ttmp/t.c" # string offset=7
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .ascii "int" # string offset=26
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .ascii "test" # string offset=30
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .section .BTF.ext,"", at progbits
+; CHECK-NEXT: .short 60319 # 0xeb9f
+; CHECK-NEXT: .byte 1
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .long 24
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 20
+; CHECK-NEXT: .long 20
+; CHECK-NEXT: .long 28
+; CHECK-NEXT: .long 8 # FuncInfo
+; CHECK-NEXT: .long 1 # FuncInfo section string offset=1
+; CHECK-NEXT: .long 1
+; CHECK-NEXT: .long .Lfunc_begin{{[0-9]+}}
+; CHECK-NEXT: .long 3
+; CHECK-NEXT: .long 16 # LineInfo
+; CHECK-NEXT: .long 1 # LineInfo section string offset=1
+; CHECK-NEXT: .long 1
+; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
+; CHECK-NEXT: .long 7
+; CHECK-NEXT: .long 0
+; CHECK-NEXT: .long 1038 # Line 1 Col 14
+
+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" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!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)
+!1 = !DIFile(filename: "/home/yhs/ttmp/t.c", directory: "/home/yhs/ttmp")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 8.0.20181009 "}
+!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)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocation(line: 1, column: 14, scope: !7)
More information about the llvm-commits
mailing list