summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/BPF/BPFTargetMachine.cpp
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2018-09-20 22:24:27 +0000
committerYonghong Song <yhs@fb.com>2018-09-20 22:24:27 +0000
commit150ca5143be586e81befc7ab689e1c058ab31710 (patch)
treec50ffdbc836adab4235b004535bc5272aa30d7aa /llvm/lib/Target/BPF/BPFTargetMachine.cpp
parentbb993db080391241b390f8408ff12c16b1e29a84 (diff)
downloadbcm5719-llvm-150ca5143be586e81befc7ab689e1c058ab31710.tar.gz
bcm5719-llvm-150ca5143be586e81befc7ab689e1c058ab31710.zip
bpf: check illegal usage of XADD insn return value
Currently, BPF has XADD (locked add) insn support and the asm looks like: lock *(u32 *)(r1 + 0) += r2 lock *(u64 *)(r1 + 0) += r2 The instruction itself does not have a return value. At the source code level, users often use __sync_fetch_and_add() which eventually translates to XADD. The return value of __sync_fetch_and_add() is supposed to be the old value in the xadd memory location. Since BPF::XADD insn does not support such a return value, this patch added a PreEmit phase to check such a usage. If such an illegal usage pattern is detected, a fatal error will be reported like line 4: Invalid usage of the XADD return value if compiled with -g, or Invalid usage of the XADD return value if compiled without -g. Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> llvm-svn: 342692
Diffstat (limited to 'llvm/lib/Target/BPF/BPFTargetMachine.cpp')
-rw-r--r--llvm/lib/Target/BPF/BPFTargetMachine.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
index 84d89bff74f..ffcb1302533 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
@@ -115,6 +115,7 @@ void BPFPassConfig::addMachineSSAOptimization() {
void BPFPassConfig::addPreEmitPass() {
const BPFSubtarget *Subtarget = getBPFTargetMachine().getSubtargetImpl();
+ addPass(createBPFMIPreEmitCheckingPass());
if (getOptLevel() != CodeGenOpt::None)
if (Subtarget->getHasAlu32() && !DisableMIPeephole)
addPass(createBPFMIPreEmitPeepholePass());
OpenPOWER on IntegriCloud