[llvm] r350637 - [BPF] Fix .BTF.ext reloc type assigment issue

Yonghong Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 8 08:36:06 PST 2019


Author: yhs
Date: Tue Jan  8 08:36:06 2019
New Revision: 350637

URL: http://llvm.org/viewvc/llvm-project?rev=350637&view=rev
Log:
[BPF] Fix .BTF.ext reloc type assigment issue

Commit f1db33c5c1a9 ("[BPF] Disable relocation for .BTF.ext section")
assigned relocation type R_BPF_NONE if the fixup type
is FK_Data_4 and the symbol is temporary.
The reason is we use FK_Data_4 as a fixup type
for insn offsets in .BTF.ext section.

Just checking whether the symbol is temporary is not enough.
For example, .debug_info may reference some strings whose
fixup is FK_Data_4 with a temporary symbol as well.

To truely reflect the case for .BTF.ext section,
this patch further checks that the section associateed with the symbol
must be SHF_ALLOC and SHF_EXECINSTR, i.e., in the text section.
This fixed the above-mentioned problem.

Signed-off-by: Yonghong Song <yhs at fb.com>

Added:
    llvm/trunk/test/CodeGen/BPF/reloc-btf.ll
Modified:
    llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp

Modified: llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp?rev=350637&r1=350636&r2=350637&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp Tue Jan  8 08:36:06 2019
@@ -57,8 +57,16 @@ unsigned BPFELFObjectWriter::getRelocTyp
     // already been fulfilled by applyFixup(). No
     // further relocation is needed.
     if (const MCSymbolRefExpr *A = Target.getSymA()) {
-      if (A->getSymbol().isTemporary())
-        return ELF::R_BPF_NONE;
+      if (A->getSymbol().isTemporary()) {
+        MCSection &Section = A->getSymbol().getSection();
+        const MCSectionELF *SectionELF = dyn_cast<MCSectionELF>(&Section);
+        assert(SectionELF && "Null section for reloc symbol");
+
+        // The reloc symbol should be in text section.
+        unsigned Flags = SectionELF->getFlags();
+        if ((Flags & ELF::SHF_ALLOC) && (Flags & ELF::SHF_EXECINSTR))
+          return ELF::R_BPF_NONE;
+      }
     }
     return ELF::R_BPF_64_32;
   }

Added: llvm/trunk/test/CodeGen/BPF/reloc-btf.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/reloc-btf.ll?rev=350637&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/reloc-btf.ll (added)
+++ llvm/trunk/test/CodeGen/BPF/reloc-btf.ll Tue Jan  8 08:36:06 2019
@@ -0,0 +1,33 @@
+; RUN: llc -march=bpfel -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s
+
+; Function Attrs: norecurse nounwind readnone
+define dso_local i32 @test() local_unnamed_addr #0 !dbg !7 {
+entry:
+  ret i32 0, !dbg !11
+}
+
+; CHECK-RELOC: file format ELF64-BPF
+; CHECK-RELOC: RELOCATION RECORDS FOR [.rel.debug_info]:
+; CHECK-RELOC: R_BPF_64_32 .debug_abbrev
+; CHECK-RELOC: R_BPF_64_64 .text
+; CHECK-RELOC: RELOCATION RECORDS FOR [.rel.BTF.ext]:
+; CHECK-RELOC: R_BPF_NONE .text
+
+attributes #0 = { norecurse nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "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.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.0 (trunk 350573) (llvm/trunk 350569)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "tt.c", directory: "/home/yhs/tmp")
+!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.0 (trunk 350573) (llvm/trunk 350569)"}
+!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, 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