binutils Newspaper
NOVEMBER 30, 2026
bpf — Proposed — Sentiment 10 / 10

bpf: accept any spelling of the addr_space_cast address spaces

Binutils assembler now accepts hex or decimal spellings for address spaces in bpf addr_space_cast instructions, fixing kernel selftests.

This patch addresses an issue where the Binutils assembler (gas) failed to assemble BPF programs using the ‘addr_space_cast’ instruction when address spaces were specified in hexadecimal. The kernel’s BPF arena selftests were failing because gas was treating hex values as literal characters. The solution introduces a new %N tag to parse these operands as numbers, allowing for correct comparison and assembly. This change ensures compatibility with GCC’s ‘addr_space_cast()’ support.

In the Thread 2 participants
  1. Vineet Gupta <vineet.gupta@linux.dev> proposer

    Submits a patch to fix gas's handling of BPF addr_space_cast by introducing a %N tag to parse address spaces as numbers, resolving assembly errors for kernel selftests.

    “gas matches the address space characters as literal `0' and `1' and trips over the hex form. Introduce a %N tag for a constant the opcode already encodes, and parse the operand as a number so the two are compared by value.”
  2. Jose E. Marchesi <jemarch@gnu.org> reviewer

    Acknowledges the patch and thanks the author, indicating it is ready for merging.

    “Hi Vineet. Thanks for the patch. > Building the kernel's BPF arena selftests fails to assemble: > ... > gas matches the address space characters as literal `0' and `1' and > trips over the hex form.”

Technical Tradeoffs

  • Introducing a new tag (%N) increases assembler complexity but improves flexibility.
  • Ensures compatibility with compiler features that use hex for address spaces.

In Details

The bpf subsystem in binutils is being updated to correctly parse hexadecimal representations of address spaces within the addr_space_cast instruction for BPF programs. Previously, the assembler (gas) incorrectly treated hex digits as literal characters, causing assembly failures for certain BPF selftests. This patch modifies tc-bpf.c and related files to introduce a %N tag, enabling numerical parsing of these operands.

For Context
BPF
Berkeley Packet Filter, a technology that allows sandboxed programs to make direct use of Linux kernel functions, primarily for networking and security.
addr_space_cast
An instruction in some BPF variants used to cast a value between different address spaces.
gas
The GNU Assembler, part of the GNU Binutils project, responsible for converting assembly language code into machine code.
%N tag
A new format specifier introduced in this patch to instruct the gas assembler to parse a subsequent operand as a numerical value, specifically for address space values.
Filed Under: bpfassemblerselftestshexadecimal