-
- Downloads
bpf: add preserve_field_info builtin
Add BPF __builtin_preserve_field_info. This builtin is used to extract information to facilitate struct and union relocations performed by the BPF loader, especially for bitfields. The builtin has the following signature: unsigned int __builtin_preserve_field_info (EXPR, unsigned int KIND); Where EXPR is an expression accessing a field of a struct or union. Depending on KIND, different information is returned to the program. The supported values for KIND are as follows: enum { FIELD_BYTE_OFFSET = 0, FIELD_BYTE_SIZE, FIELD_EXISTENCE, FIELD_SIGNEDNESS, FIELD_LSHIFT_U64, FIELD_RSHIFT_U64 }; If -mco-re is in effect (explicitly or implicitly specified), a CO-RE relocation is added for the access in EXPR recording the relevant information according to KIND. gcc/ * config/bpf/bpf.cc: Support __builtin_preserve_field_info. (enum bpf_builtins): Add new builtin. (bpf_init_builtins): Likewise. (bpf_core_field_info): New function. (bpf_expand_builtin): Accomodate new builtin. Refactor adding new relocation to... (maybe_make_core_relo): ... here. New function. (bpf_resolve_overloaded_builtin): Accomodate new builtin. (bpf_core_newdecl): Likewise. (bpf_core_walk): Likewise. (bpf_core_is_maybe_aggregate_access): Improve logic. (struct core_walk_data): New. * config/bpf/coreout.cc (bpf_core_reloc_add): Allow adding different relocation kinds. * config/bpf/coreout.h: Analogous change. * doc/extend.texi: Document BPF __builtin_preserve_field_info. gcc/testsuite/ * gcc.target/bpf/core-builtin-fieldinfo-errors-1.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-errors-2.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-existence-1.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-lshift-1-be.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-lshift-1-le.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-lshift-2.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-rshift-1.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-rshift-2.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-sign-1.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-sign-2.c: New test. * gcc.target/bpf/core-builtin-fieldinfo-size-1.c: New test.
Showing
- gcc/config/bpf/bpf.cc 330 additions, 72 deletionsgcc/config/bpf/bpf.cc
- gcc/config/bpf/coreout.cc 3 additions, 2 deletionsgcc/config/bpf/coreout.cc
- gcc/config/bpf/coreout.h 1 addition, 1 deletiongcc/config/bpf/coreout.h
- gcc/doc/extend.texi 77 additions, 0 deletionsgcc/doc/extend.texi
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-errors-1.c 23 additions, 0 deletions...estsuite/gcc.target/bpf/core-builtin-fieldinfo-errors-1.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-errors-2.c 23 additions, 0 deletions...estsuite/gcc.target/bpf/core-builtin-fieldinfo-errors-2.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-existence-1.c 34 additions, 0 deletions...suite/gcc.target/bpf/core-builtin-fieldinfo-existence-1.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-lshift-1-be.c 37 additions, 0 deletions...suite/gcc.target/bpf/core-builtin-fieldinfo-lshift-1-be.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-lshift-1-le.c 37 additions, 0 deletions...suite/gcc.target/bpf/core-builtin-fieldinfo-lshift-1-le.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-lshift-2.c 37 additions, 0 deletions...estsuite/gcc.target/bpf/core-builtin-fieldinfo-lshift-2.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c 56 additions, 0 deletions...estsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-rshift-1.c 36 additions, 0 deletions...estsuite/gcc.target/bpf/core-builtin-fieldinfo-rshift-1.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-rshift-2.c 35 additions, 0 deletions...estsuite/gcc.target/bpf/core-builtin-fieldinfo-rshift-2.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-sign-1.c 33 additions, 0 deletionsgcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-sign-1.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-sign-2.c 45 additions, 0 deletionsgcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-sign-2.c
- gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-size-1.c 43 additions, 0 deletionsgcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-size-1.c
Loading