PR 34558: BPF assembler fixes `gotol` misassembly with signed offsets
BPF assembler now correctly assembles `gotol` with signed offsets, preventing silent misassembly into an unconditional jump.
This commit resolves a bug in the BPF assembler (PR 34558) where gotol instructions with signed offsets were silently misassembled. Due to the order of unconditional jump mnemonics in the opcode table, gotol +1 was incorrectly parsed as goto l +1, resulting in the JA opcode with a 16-bit offset and an invalid relocation instead of the intended JAL opcode with a 32-bit immediate. The fix modifies the assembler’s template matching to correctly distinguish gotol from goto, especially with signed offsets.
In Details
The BPF_INSN_JAR template (goto%w%d16) appears before BPF_INSN_JAL (gotol%w%d32) in the opcode table. This causes gotol +1 to be matched as goto with a label l and a 16-bit offset, generating JA (0x05) and an R_BPF_GNU_64_16 relocation. The correct instruction is JAL (0x06) with a 32-bit immediate. This commit corrects the templates and adds test cases to ensure correct assembly for signed offsets, aligning with LLVM output and ISA documentation.
- PR 34558
- Problem Report 34558, a bug filed against the GNU Assembler concerning incorrect assembly of BPF
gotolinstructions. - BPF assembler
- The component of binutils responsible for translating BPF assembly language into machine code.
- Opcode table
- A data structure used by an assembler or disassembler that maps instruction mnemonics to their corresponding numerical opcodes and defines how operands are parsed.
- Relocation
- Information in an object file that describes how to modify parts of the code or data when linking, typically to resolve addresses of external symbols or relative offsets.