The next step for GCC BPF arena support is the arena itself. A BPF
arena is memory that a program shares with user space. A pointer into
an arena holds the user-space address, and the addr_space_cast
instruction converts it to the kernel address that the program can
dereference. This series models the arena as named address space 1,
spelled __arena, the number clang uses.
- 1/2: target/124974: the __arena address space
- 2/2: target/124974: require assembler support for addr_space_cast
With these,
int
load (int __arena *p)
{
return *p;
}
compiles to
r1 = addr_space_cast(r1, 0, 1)
r0 = *(u32 *) (r1+0)
exit
Note:
1. GCC defines __BPF_FEATURE_ARENA, and not clang's
__BPF_FEATURE_ADDR_SPACE_CAST. The clang macro also promises the
clang spelling, __attribute__((address_space(1))), which GCC accepts
only with the next series, #4. The kernel's arena headers test
__BPF_FEATURE_ADDR_SPACE_CAST, so with this series alone they need
to test __BPF_FEATURE_ARENA too and use the keyword.
2. addr_space_cast is in binutils master since 2026-10-12, but in no
release. With an older assembler, configure leaves the arena off:
__BPF_FEATURE_ARENA is not defined, and __arena is an error.
3. This series applies on top of
dwarf: do not clone a typedef for a tagged use of it [PR128441]
https://inbox.sourceware.org/gcc-patches/[email protected]/
bpf arena gcc support #1: GCC btf tag supports in the kernel
https://inbox.sourceware.org/gcc-patches/[email protected]/
bpf arena gcc support #2: btf tags on typedefs
https://inbox.sourceware.org/gcc-patches/[email protected]/
Regression tested on bpf-unknown-none with binutils master: no new
FAILs in bpf.exp, and 17 new PASSes. Bootstrapped and regression
tested on x86_64-pc-linux-gnu together with #4: stage2 and stage3
compare successfully, with no new FAILs.
Changes in v3:
- 1/2: assert in bpf_lower_arena_ref that an arena variable is static
or external, instead of testing it in the condition (Jose E.
Marchesi).
- Link to v2:
https://inbox.sourceware.org/gcc-patches/[email protected]/
Changes in v2:
- 1/2: lower the arguments of a call too. An aggregate passed by value
out of the arena was read straight through the arena pointer, with no
addr_space_cast. New test arena-arg-1.c (Jose E. Marchesi).
- 1/2: say in bpf_lower_arena_ref that the front end rejects __arena on
automatics and parameters (Jose E. Marchesi).
- 2/2: make the bpf_arena effective target an assembly probe, like tls:
it asks whether the compiler accepts __arena, and does not run the
assembler (Uros Bizjak).
- Link to v1:
https://inbox.sourceware.org/gcc-patches/[email protected]/
Vineet Gupta (2):
bpf: support the arena address space [PR124974]
bpf: require assembler support for the arena address space [PR124974]
gcc/config.in | 7 +
gcc/config/bpf/bpf-c.cc | 15 +
gcc/config/bpf/bpf-passes.def | 1 +
gcc/config/bpf/bpf-protos.h | 3 +
gcc/config/bpf/bpf.cc | 297 ++++++++++++++++++
gcc/config/bpf/bpf.h | 15 +
gcc/config/bpf/bpf.md | 20 ++
gcc/configure | 36 +++
gcc/configure.ac | 11 +
gcc/doc/extend.texi | 30 +-
.../dwarf2/dwarf-addr-space-typedef-bpf.c | 46 +++
gcc/testsuite/gcc.target/bpf/arena-1.c | 30 ++
gcc/testsuite/gcc.target/bpf/arena-2.c | 21 ++
gcc/testsuite/gcc.target/bpf/arena-3.c | 41 +++
gcc/testsuite/gcc.target/bpf/arena-arg-1.c | 26 ++
gcc/testsuite/gcc.target/bpf/arena-btf-1.c | 31 ++
gcc/testsuite/lib/target-supports.exp | 13 +
17 files changed, 642 insertions(+), 1 deletion(-)
create mode 100644
gcc/testsuite/gcc.dg/debug/dwarf2/dwarf-addr-space-typedef-bpf.c
create mode 100644 gcc/testsuite/gcc.target/bpf/arena-1.c
create mode 100644 gcc/testsuite/gcc.target/bpf/arena-2.c
create mode 100644 gcc/testsuite/gcc.target/bpf/arena-3.c
create mode 100644 gcc/testsuite/gcc.target/bpf/arena-arg-1.c
create mode 100644 gcc/testsuite/gcc.target/bpf/arena-btf-1.c
--
2.53.1-Meta