| Issue |
244366
|
| Summary |
[BPF] Assertion in BPFMCCodeEmitter on `ld_imm64` with `symbol + offset`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
caniko
|
An assertion-enabled clang aborts on an `ld_imm64` whose operand is a symbol plus an offset:
```c
// t.c
void f(void) { asm volatile("r2 = tbl + 8 ll; exit;" ::: "r2"); }
long tbl[2];
```
```
$ clang --target=bpfel -O2 -c t.c
clang: llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp:106: unsigned int (anonymous namespace)::BPFMCCodeEmitter::getMachineOpValue(...) const: Assertion `Expr->getKind() == MCExpr::SymbolRef' failed.
...
#10 BPFMCCodeEmitter::getMachineOpValue
#11 BPFMCCodeEmitter::getBinaryCodeForInstr
#12 BPFMCCodeEmitter::encodeInstruction
#13 MCObjectStreamer::emitInstToData
#14 BPFAsmParser::matchAndEmitInstruction
```
This is with main at 3bfae959fb6f and `+assertions`. Release builds don't assert. clang 21.1.8 emits `r2 = 0x8 ll` with an `R_BPF_64_64` relocation against `tbl`, which is what the program expects.
The kernel now relies on this: `callx_rodata_elem_addr` in `tools/testing/selftests/bpf/progs/verifier_callx_rodata.c` (bpf-next d14f973f15, added on 2026-11-07) uses `r2 = tbl_%= + 8 ll`, so selftests/bpf no longer builds with an assertion-enabled clang.
#74035 made the backend reject operands like `1 + w3` in release builds too. A symbol plus a constant is different, since it is an ordinary relocatable _expression_. I think the assertion should accept `MCBinaryExpr` of a symbol and a constant for `LD_imm64`, or the asm parser should reject it in all builds if it isn't meant to be supported. Given the kernel selftest, accepting it looks like the right fix.
Assisted-by: Claude Code (Claude Opus 5.5)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs