binutils Newspaper
OCTOBER 6, 2026
bpf — Proposed

BPF gas: Use %t for literal mnemonics

BPF gas mnemonics now use %t specifier for precise parsing, preventing accidental instruction extension.

This patch modifies the BPF assembler’s opcode table to use the %t specifier after literal mnemonics. This change, prompted by a previous bug (PR gas/34558), ensures that mnemonics like if, lock, call, etc., are treated as distinct tokens and prevent subsequent tokens from being misinterpreted as part of the mnemonic. This improves parsing accuracy and future-proofs the opcode table against new instruction additions.

In the Thread 2 participants
  1. Jose E. Marchesi reviewer

    Approves the patch for the master branch, acknowledging its fix for a latent parsing problem.

    “OK for master. Thanks!”
  2. Vineet Gupta proposer

    Submitted a patch to use the `%t` specifier for remaining BPF literal mnemonics in the opcode table.

    “Convert the remaining 65 sites: `if', `lock', `gotol', `call', `callx', `may_goto', `le16'/`le32'/`le64', `be16'/`be32'/`be64' and `bswap16'/`bswap32'/`bswap64'.”

Technical Tradeoffs

  • Improves parsing robustness and prevents future bugs related to mnemonic ambiguity.
  • Introduces stricter parsing, potentially breaking existing assembly files that relied on the previous flexible spacing (though mitigated by test cases).
  • Increases accuracy in distinguishing mnemonics from immediate operands.

In Details

This patch refactors the BPF assembler's tc-bpf.c and bpf-opc.c to use the %t (token boundary) specifier after literal mnemonics in the opcode table. Previously, %w was used, which allowed mnemonics to be extended by immediately following characters (e.g., goto followed by l in gotol). The %t specifier enforces a stricter token boundary, preventing such ambiguities and aligning with the fix for PR gas/34558. This change affects 65 sites and adds new test cases to verify spacing rules.

For Context
BPF
Berkeley Packet Filter, a technology that allows sandboxed programs to safely execute code in the Linux kernel, often used for networking and tracing.
gas
The GNU Assembler, part of the GNU Binutils package, responsible for converting assembly language code into machine code.
opcode table
A data structure used by an assembler or compiler that maps instruction mnemonics and operands to their corresponding machine code representations.
%t specifier
A format specifier in the gas opcode table that signifies a token boundary, ensuring that the preceding text is treated as a complete mnemonic and not extended by subsequent characters.
PR gas/34558
A bug report filed against the GNU Assembler, specifically concerning incorrect parsing of BPF instructions due to ambiguous mnemonic boundaries.

Part of a Series

Filed Under: BPFgasassemblerparsingopcode table