llvm-project/llvm/lib/Target/BPF
Yonghong Song 48883142de bpf: fix an assertion in BPFAsmBackend applyFixup()
Fix bug https://bugs.llvm.org/show_bug.cgi?id=38643

In BPFAsmBackend applyFixup(), there is an assertion for FixedValue to be 0.
This may not be true, esp. for optimiation level 0.
For example, in the above bug, for the following two
static variables:
  @bpf_map_lookup_elem = internal global i8* (i8*, i8*)*
      inttoptr (i64 1 to i8* (i8*, i8*)*), align 8
  @bpf_map_update_elem = internal global i32 (i8*, i8*, i8*, i64)*
      inttoptr (i64 2 to i32 (i8*, i8*, i8*, i64)*), align 8

The static variable @bpf_map_update_elem will have a symbol
offset of 8 and a FK_SecRel_8 with FixupValue 8 will cause
the assertion if llvm is built with -DLLVM_ENABLE_ASSERTIONS=ON.

The above relocations will not exist if the program is compiled
with optimization level -O1 and above as the compiler optimizes
those static variables away. In the below error message, -O2
is suggested as this is the common practice.

Note that FixedValue = 0 in applyFixup() does exist and is valid,
e.g., for the global variable my_map in the above bug. The bpf
loader will process them properly for map_id's before loading
the program into the kernel.

The static variables, which are not optimized away by compiler,
may have FK_SecRel_8 relocation with non-zero FixedValue.

The patch removed the offending assertion and will issue
a hard error as below if the FixedValue in applyFixup()
is not 0.
  $ llc -march=bpf -filetype=obj fixup.ll
  LLVM ERROR: Unsupported relocation: try to compile with -O2 or above,
      or check your static variable usage

Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 340455
2018-08-22 21:21:03 +00:00
..
AsmParser bpf: signal error instead of silent drop for certain invalid asm insn 2018-04-11 20:24:52 +00:00
Disassembler bpf: New decoder namespace for 32-bit subregister load/store 2018-02-23 23:49:31 +00:00
InstPrinter Remove some unused includes to fix layering. 2018-03-29 00:29:45 +00:00
MCTargetDesc bpf: fix an assertion in BPFAsmBackend applyFixup() 2018-08-22 21:21:03 +00:00
TargetInfo Add backend name to Target to enable runtime info to be fed back into TableGen 2017-11-15 23:55:44 +00:00
BPF.h bpf: New post-RA peephole optimization pass to eliminate bad RA codegen 2018-03-13 06:47:06 +00:00
BPF.td bpf: introduce -mattr=dwarfris to disable DwarfUsesRelocationsAcrossSections 2018-03-01 23:04:59 +00:00
BPFAsmPrinter.cpp
BPFCallingConv.td bpf: New calling convention for 32-bit subregisters 2018-02-23 23:49:23 +00:00
BPFFrameLowering.cpp
BPFFrameLowering.h Move TargetFrameLowering.h to CodeGen where it's implemented 2017-11-03 22:32:11 +00:00
BPFISelDAGToDAG.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
BPFISelLowering.cpp bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFISelLowering.h bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFInstrFormats.td bpf: add new insns for bswap_to_le and negation 2017-09-28 02:46:11 +00:00
BPFInstrInfo.cpp bpf: add missing RegState to notify MachineInstr verifier necessary register usage 2018-07-27 16:58:52 +00:00
BPFInstrInfo.h bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFInstrInfo.td bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFMCInstLower.cpp
BPFMCInstLower.h
BPFMIPeephole.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
BPFRegisterInfo.cpp bpf: Use markSuperRegs to mark reserved registers 2018-02-23 23:49:18 +00:00
BPFRegisterInfo.h [BPF] Return true in enableMultipleCopyHints(). 2018-02-18 10:09:54 +00:00
BPFRegisterInfo.td bpf: add 32bit register set 2017-09-22 04:36:35 +00:00
BPFSelectionDAGInfo.cpp bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFSelectionDAGInfo.h bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFSubtarget.cpp bpf: introduce -mattr=dwarfris to disable DwarfUsesRelocationsAcrossSections 2018-03-01 23:04:59 +00:00
BPFSubtarget.h bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
BPFTargetMachine.cpp bpf: New post-RA peephole optimization pass to eliminate bad RA codegen 2018-03-13 06:47:06 +00:00
BPFTargetMachine.h Revert "TargetMachine: Merge TargetMachine and LLVMTargetMachine" 2017-10-12 22:57:28 +00:00
CMakeLists.txt bpf: new option -bpf-expand-memcpy-in-order to expand memcpy in order 2018-07-25 22:40:02 +00:00
LLVMBuild.txt