[llvm] r329849 - bpf: signal error instead of silent drop for certain invalid asm insn
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 11 13:24:52 PDT 2018
Author: yhs
Date: Wed Apr 11 13:24:52 2018
New Revision: 329849
URL: http://llvm.org/viewvc/llvm-project?rev=329849&view=rev
Log:
bpf: signal error instead of silent drop for certain invalid asm insn
Currently, an invalid asm insn, either in an asm file or
in an inline asm format, might be silently dropped. This patch
fixed two places where this may happen by
signaling the error so user knows what goes wrong.
The following is an example to demonstrate error messages:
-bash-4.2$ cat t.c
int test(void *ctx) {
#if defined(NO_ERROR)
asm volatile("r0 = *(u16 *)skb[%0]" : : "i"(2));
#elif defined(ERROR_1)
asm volatile("r20 = *(u16 *)skb[%0]" : : "i"(2));
#elif defined(ERROR_2)
asm volatile("r0 = *(u16 *)(r1 + ?)" : :);
#endif
return 0;
}
-bash-4.2$ cat run.sh
for macro in NO_ERROR ERROR_1 ERROR_2; do
echo "===== compile for macro" $macro
clang -D${macro} -O2 -target bpf -emit-llvm -S t.c
echo "==llc=="
llc -march=bpf -filetype=obj t.ll
done
-bash-4.2$ ./run.sh
===== compile for macro NO_ERROR
==llc==
===== compile for macro ERROR_1
==llc==
<inline asm>:1:2: error: invalid register/token name
r20 = *(u16 *)skb[2]
^
note: !srcloc = 135
===== compile for macro ERROR_2
==llc==
<inline asm>:1:21: error: unexpected token
r0 = *(u16 *)(r1 + ?)
^
note: !srcloc = 210
-bash-4.2$
Acked-by: Alexei Starovoitov <ast at kernel.org>
Signed-off-by: Yonghong Song <yhs at fb.com>
Modified:
llvm/trunk/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
Modified: llvm/trunk/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/AsmParser/BPFAsmParser.cpp?rev=329849&r1=329848&r2=329849&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/AsmParser/BPFAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/BPF/AsmParser/BPFAsmParser.cpp Wed Apr 11 13:24:52 2018
@@ -460,7 +460,7 @@ bool BPFAsmParser::ParseInstruction(Pars
} else if (BPFOperand::isValidIdAtStart (Name))
Operands.push_back(BPFOperand::createToken(Name, NameLoc));
else
- return true;
+ return Error(NameLoc, "invalid register/token name");
while (!getLexer().is(AsmToken::EndOfStatement)) {
// Attempt to parse token as operator
@@ -472,8 +472,10 @@ bool BPFAsmParser::ParseInstruction(Pars
continue;
// Attempt to parse token as an immediate
- if (parseImmediate(Operands) != MatchOperand_Success)
- return true;
+ if (parseImmediate(Operands) != MatchOperand_Success) {
+ SMLoc Loc = getLexer().getLoc();
+ return Error(Loc, "unexpected token");
+ }
}
if (getLexer().isNot(AsmToken::EndOfStatement)) {
More information about the llvm-commits
mailing list