]> granicus.if.org Git - llvm/commitdiff
[BPF] emit BTF sections only if debuginfo available
authorYonghong Song <yhs@fb.com>
Mon, 13 May 2019 05:00:23 +0000 (05:00 +0000)
committerYonghong Song <yhs@fb.com>
Mon, 13 May 2019 05:00:23 +0000 (05:00 +0000)
Currently, without -g, BTF sections may still be emitted with
data sections, e.g., for linux kernel bpf selftest
test_tcp_check_syncookie_kern.c issue discovered by Martin
as shown below.

-bash-4.4$ bpftool btf dump file test_tcp_check_syncookie_kern.o
[1] VAR 'results' type_id=0, linkage=global-alloc
[2] VAR '_license' type_id=0, linkage=global-alloc
[3] DATASEC 'license' size=0 vlen=1
        type_id=2 offset=0 size=4
[4] DATASEC 'maps' size=0 vlen=1
        type_id=1 offset=0 size=28

Let disable BTF generation if no debuginfo, which is
the original design.

Signed-off-by: Yonghong Song <yhs@fb.com>
Differential Revision: https://reviews.llvm.org/D61826

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360556 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/BPF/BPFAsmPrinter.cpp
test/CodeGen/BPF/BTF/char-no-debuginfo.ll [new file with mode: 0644]

index fa114b257dab35d06d320969ff3e66d33a5d1dba..76b22056e5d98d2ae3140b0b6e315dab99fd0f9b 100644 (file)
@@ -54,7 +54,8 @@ public:
 bool BPFAsmPrinter::doInitialization(Module &M) {
   AsmPrinter::doInitialization(M);
 
-  if (MAI->doesSupportDebugInformation()) {
+  // Only emit BTF when debuginfo available.
+  if (MAI->doesSupportDebugInformation() && !empty(M.debug_compile_units())) {
     Handlers.emplace_back(llvm::make_unique<BTFDebug>(this), "emit",
                           "Debug Info Emission", "BTF", "BTF Emission");
   }
diff --git a/test/CodeGen/BPF/BTF/char-no-debuginfo.ll b/test/CodeGen/BPF/BTF/char-no-debuginfo.ll
new file mode 100644 (file)
index 0000000..38d5e09
--- /dev/null
@@ -0,0 +1,31 @@
+; 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 g __attribute__((section("maps"))) = 5;
+;   int test() { return g; }
+; Compilation flag:
+;   clang -target bpf -O2 -S -emit-llvm t.c
+
+@g = dso_local local_unnamed_addr global i32 5, section "maps", align 4
+
+; Function Attrs: norecurse nounwind readonly
+define dso_local i32 @test() local_unnamed_addr #0 {
+  %1 = load i32, i32* @g, align 4, !tbaa !2
+  ret i32 %1
+}
+
+; CHECK-NOT:         .section        .BTF
+; CHECK-NOT:         .section        .BTF.ext
+
+attributes #0 = { norecurse nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{!"clang version 8.0.20181009 "}
+!2 = !{!3, !3, i64 0}
+!3 = !{!"int", !4, i64 0}
+!4 = !{!"omnipotent char", !5, i64 0}
+!5 = !{!"Simple C/C++ TBAA"}