]> git.ipfire.org Git - thirdparty/gcc.git/commit
bpf,btf: enable BTF pruning by default for BPF
authorDavid Faust <david.faust@oracle.com>
Mon, 10 Jun 2024 17:59:05 +0000 (10:59 -0700)
committerDavid Faust <david.faust@oracle.com>
Tue, 2 Jul 2024 17:16:13 +0000 (10:16 -0700)
commit189d0f1fc2cd2de1815ce5ead8ac87f3cba32010
tree02a3ae321882ee94d77dbd4a9885314ea2ab73fd
parentb8977d928a7a261913dd89db55d4123b6a54ba46
bpf,btf: enable BTF pruning by default for BPF

This patch enables -gprune-btf by default in the BPF backend when
generating BTF information, and fixes BPF CO-RE generation when using
-gprune-btf.

When generating BPF CO-RE information, we must ensure that types used
in CO-RE relocations always have sufficient BTF information emited so
that the CO-RE relocations can be processed by a BPF loader.  The BTF
pruning algorithm on its own does not have sufficient information to
determine which types are used in a BPF CO-RE relocation, so this
information must be supplied by the BPF backend, using a new
btf_mark_type_used function.

Co-authored-by: Cupertino Miranda <cupertino.miranda@oracle.com>
gcc/
* btfout.cc (btf_mark_type_used): New.
* ctfc.h (btf_mark_type_used): Declare it here.
* config/bpf/bpf.cc (bpf_option_override): Enable -gprune-btf
by default if -gbtf is enabled.
* config/bpf/core-builtins.cc (extra_fn): New typedef.
(compute_field_expr): Add callback parameter, and call it if supplied.
Fix computation for MEM_REF.
(mark_component_type_as_used): New.
(bpf_mark_types_as_used): Likewise.
(bpf_expand_core_builtin): Call here.
* doc/invoke.texi (Debugging Options): Note that -gprune-btf is
enabled by default for BPF target when generating BTF.

gcc/testsuite/
* gcc.dg/debug/btf/btf-variables-5.c: Adjust one test for bpf-*-*
target.
gcc/btfout.cc
gcc/config/bpf/bpf.cc
gcc/config/bpf/core-builtins.cc
gcc/ctfc.h
gcc/doc/invoke.texi
gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c