https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124974

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Vineet Gupta <[email protected]>:

https://gcc.gnu.org/g:f5701b9ae40876b0cfe562b02b9600c2b05ba832

commit r17-6854-gf5701b9ae40876b0cfe562b02b9600c2b05ba832
Author: Vineet Gupta <[email protected]>
Date:   Mon Nov 30 10:49:26 2026 -0800

    bpf: support the arena address space [PR124974]

    A BPF arena is memory that a program shares with user space.  A pointer
    into an arena holds the user-space address.  The addr_space_cast
    instruction converts it to the kernel address, which the program can
    dereference.  Model the arena as named address space 1, spelled
    __arena, the number clang uses.

    No instruction dereferences an arena pointer.  An access is a cast to
    the generic address space, then an ordinary load or store.  So an arena
    MEM has no RTL form: the cast is a separate instruction that must come
    first.  Lower arena accesses in gimple instead, right after the CFG is
    built.  No non-generic reference reaches RTL, and the casts get the
    usual redundancy elimination and loop-invariant motion.

    Objects declared in the arena go to section .addr_space.1, where libbpf
    looks for the arena's initial contents.  The section is set on the
    declaration so that the BTF DATASEC agrees.  Otherwise BTF says .bss
    and libbpf fails to link the object.

    Also add BPF versions of the x86 debug info tests for a typedef of an
    address space qualified type.

    __BPF_FEATURE_ARENA is defined so that source can test for the arena.
    clang's __BPF_FEATURE_ADDR_SPACE_CAST is not defined, because it also
    promises __attribute__((address_space(1))), which GCC does not accept.

            PR target/124974

    gcc/ChangeLog:

            * config/bpf/bpf.h (enum bpf_addr_space): New.
            (REGISTER_TARGET_PRAGMAS): Define.
            * config/bpf/bpf-protos.h (bpf_register_pragmas): New prototype.
            (make_pass_lower_bpf_arena): Likewise.
            * config/bpf/bpf-c.cc (bpf_register_pragmas): New function.
            (bpf_target_macros): Define __BPF_FEATURE_ARENA.
            * doc/extend.texi (Named Address Spaces): Add BPF to the list of
            targets with named address spaces, and a BPF section documenting
            __arena.
            * config/bpf/bpf.cc (bpf_addr_space_subset_p): New function.
            (bpf_addr_space_convert): New function.
            (bpf_addr_space_section_name): New function.
            (bpf_encode_section_info): New function.
            (bpf_strip_addr_space): New function.
            (bpf_lower_arena_ref): New function.
            (execute_lower_bpf_arena): New function.
            (pass_lower_bpf_arena): New pass.
            (make_pass_lower_bpf_arena): New function.
            (TARGET_ADDR_SPACE_SUBSET_P): Define.
            (TARGET_ADDR_SPACE_CONVERT): Define.
            (TARGET_ENCODE_SECTION_INFO): Define.
            * config/bpf/bpf-passes.def: Add pass_lower_bpf_arena.
            * config/bpf/bpf.md (UNSPEC_ADDR_SPACE_CAST): New unspec.
            (addr_space_cast): New insn.

    gcc/testsuite/ChangeLog:

            * gcc.target/bpf/arena-1.c: New test.
            * gcc.target/bpf/arena-2.c: New test.
            * gcc.target/bpf/arena-3.c: New test.
            * gcc.target/bpf/arena-btf-1.c: New test.
            * gcc.target/bpf/arena-arg-1.c: New test.
            * gcc.dg/debug/dwarf2/dwarf-addr-space-typedef-bpf.c: New test.

    Signed-off-by: Vineet Gupta <[email protected]>

Reply via email to