aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorCupertino Miranda <cupertino.miranda@oracle.com>2023-04-06 15:22:48 +0100
committerCupertino Miranda <cupertino.miranda@oracle.com>2023-08-03 19:46:44 +0100
commite0a81559c198153923f0a1a3be7c25df545f3964 (patch)
treeb2cbda050b2b9d05e79e1c59168cfb9f507ac0d5 /gcc/doc
parent9fedc3c010ff81f290e4e97cbcd0847ca803dcc4 (diff)
downloadgcc-e0a81559c198153923f0a1a3be7c25df545f3964.zip
gcc-e0a81559c198153923f0a1a3be7c25df545f3964.tar.gz
gcc-e0a81559c198153923f0a1a3be7c25df545f3964.tar.bz2
bpf: Implementation of BPF CO-RE builtins
This patch updates the support for the BPF CO-RE builtins __builtin_preserve_access_index and __builtin_preserve_field_info, and adds support for the CO-RE builtins __builtin_btf_type_id, __builtin_preserve_type_info and __builtin_preserve_enum_value. These CO-RE relocations are now converted to __builtin_core_reloc which abstracts all of the original builtins in a polymorphic relocation specific builtin. The builtin processing is now split in 2 stages, the first (pack) is executed right after the front-end and the second (process) right before the asm output. In expand pass the __builtin_core_reloc is converted to a unspec:UNSPEC_CORE_RELOC rtx entry. The data required to process the builtin is now collected in the packing stage (after front-end), not allowing the compiler to optimize any of the relevant information required to compose the relocation when necessary. At expansion, that information is recovered and CTF/BTF is queried to construct the information that will be used in the relocation. At this point the relocation is added to specific section and the builtin is expanded to the expected default value for the builtin. In order to process __builtin_preserve_enum_value, it was necessary to hook the front-end to collect the original enum value reference. This is needed since the parser folds all the enum values to its integer_cst representation. More details can be found within the core-builtins.cc. Regtested in host x86_64-linux-gnu and target bpf-unknown-none. gcc/ChangeLog: PR target/107844 PR target/107479 PR target/107480 PR target/107481 * config.gcc: Added core-builtins.cc and .o files. * config/bpf/bpf-passes.def: Removed file. * config/bpf/bpf-protos.h (bpf_add_core_reloc, bpf_replace_core_move_operands): New prototypes. * config/bpf/bpf.cc (enum bpf_builtins, is_attr_preserve_access, maybe_make_core_relo, bpf_core_field_info, bpf_core_compute, bpf_core_get_index, bpf_core_new_decl, bpf_core_walk, bpf_is_valid_preserve_field_info_arg, is_attr_preserve_access, handle_attr_preserve, pass_data_bpf_core_attr, pass_bpf_core_attr): Removed. (def_builtin, bpf_expand_builtin, bpf_resolve_overloaded_builtin): Changed. * config/bpf/bpf.md (define_expand mov<MM:mode>): Changed. (mov_reloc_core<mode>): Added. * config/bpf/core-builtins.cc (struct cr_builtin, enum cr_decision struct cr_local, struct cr_final, struct core_builtin_helpers, enum bpf_plugin_states): Added types. (builtins_data, core_builtin_helpers, core_builtin_type_defs): Added variables. (allocate_builtin_data, get_builtin-data, search_builtin_data, remove_parser_plugin, compare_same_kind, compare_same_ptr_expr, compare_same_ptr_type, is_attr_preserve_access, core_field_info, bpf_core_get_index, compute_field_expr, pack_field_expr_for_access_index, pack_field_expr_for_preserve_field, process_field_expr, pack_enum_value, process_enum_value, pack_type, process_type, bpf_require_core_support, make_core_relo, read_kind, kind_access_index, kind_preserve_field_info, kind_enum_value, kind_type_id, kind_preserve_type_info, get_core_builtin_fndecl_for_type, bpf_handle_plugin_finish_type, bpf_init_core_builtins, construct_builtin_core_reloc, bpf_resolve_overloaded_core_builtin, bpf_expand_core_builtin, bpf_add_core_reloc, bpf_replace_core_move_operands): Added functions. * config/bpf/core-builtins.h (enum bpf_builtins): Added. (bpf_init_core_builtins, bpf_expand_core_builtin, bpf_resolve_overloaded_core_builtin): Added functions. * config/bpf/coreout.cc (struct bpf_core_extra): Added. (bpf_core_reloc_add, output_asm_btfext_core_reloc): Changed. * config/bpf/coreout.h (bpf_core_reloc_add) Changed prototype. * config/bpf/t-bpf: Added core-builtins.o. * doc/extend.texi: Added documentation for new BPF builtins.
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/extend.texi51
1 files changed, 51 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 97eaacf..e06caf3 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -16015,6 +16015,57 @@ read_y (struct S *arg)
@end smallexample
@enddefbuiltin
+@defbuiltin{{unsigned int} __builtin_preserve_enum_value (@var{type}, @var{enum}, unsigned int @var{kind})}
+BPF Compile Once-Run Everywhere (CO-RE) support. This builtin collects enum
+information and creates a CO-RE relocation relative to @var{enum} that should
+be of @var{type}. The @var{kind} specifies the action performed.
+
+The following values are supported for @var{kind}:
+@table @code
+@item ENUM_VALUE_EXISTS = 0
+The return value is either 0 or 1 depending if the enum value exists in the
+target.
+
+@item ENUM_VALUE = 1
+The return value is the enum value in the target kernel.
+@end table
+@enddefbuiltin
+
+@defbuiltin{{unsigned int} __builtin_btf_type_id (@var{type}, unsigned int @var{kind})}
+BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to get
+the BTF type ID of a specified type. Depending on the @var{kind} argument, it
+will either return the ID of the local BTF information, or the BTF type ID in
+the target kernel.
+
+The following values are supported for @var{kind}:
+@table @code
+@item BTF_TYPE_ID_LOCAL = 0
+Return the local BTF type ID. Always succeeds.
+
+@item BTF_TYPE_ID_TARGET = 1
+Return the target BTF type ID. If type does not exist in the target, returns 0.
+@end table
+@enddefbuiltin
+
+@defbuiltin{{unsigned int} __builtin_preserve_type_info (@var{type}, unsigned int @var{kind})}
+BPF Compile Once-Run Everywhere (CO-RE) support. This builtin performs named
+type (struct/union/enum/typedef) verifications. The type of verification
+dependents on the @var{kind} argument provided. This builtin will always
+return 0 if type does not exists in the target kernel.
+
+The following values are supported for @var{kind}:
+@table @code
+@item BTF_TYPE_EXISTS = 0
+Checks if type exists in the target.
+
+@item BTF_TYPE_MATCHES = 1
+Checks if type matches the local definition in the target kernel.
+
+@item BTF_TYPE_SIZE = 2
+Returns the size of the type within the target.
+@end table
+@enddefbuiltin
+
@node FR-V Built-in Functions
@subsection FR-V Built-in Functions