llvm-project/llvm/test/CodeGen/BPF/CORE
Yonghong Song 6e6c1efe04 [BPF] Handle anon record for CO-RE relocations
When doing experiment in kernel, for kernel data structure sockptr_t
in CO-RE operation, I hit an assertion error. The sockptr_t definition
and usage look like below:
  #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
  typedef struct {
        union {
                void    *kernel;
                void    *user;
        };
        unsigned is_kernel : 1;
  } sockptr_t;
  #pragma clang attribute pop
  int test(sockptr_t *arg) {
    return arg->is_kernel;
  }
The assertion error looks like
  clang: ../lib/Target/BPF/BPFAbstractMemberAccess.cpp:878: llvm::Value*
   {anonymous}::BPFAbstractMemberAccess::computeBaseAndAccessKey(llvm::CallInst*,
   {anonymous}::BPFAbstractMemberAccess::CallInfo&, std::__cxx11::string&,
   llvm::MDNode*&): Assertion `TypeName.size()' failed.

In this particular, the clang frontend attach the debuginfo metadata associated
with anon structure with the preserve_access_info IR intrinsic. But the first
debuginfo type has to be a named type so libbpf can have a sound start to
do CO-RE relocation.

Besides the above approach using pragma to push attribute, the below typedef/struct
definition can have preserve_access_index directly applying to the anon struct.
  typedef struct {
        union {
                void    *kernel;
                void    *user;
        };
        unsigned is_kernel : 1;
  } __attribute__((preserve_access_index) sockptr_t;

This patch fixed the issue by preprocessing function argument/return types
and local variable types used by other CO-RE intrinsics. For any
   typedef struct/union { ... } typedef_name
an association of <anon struct/union, typedef> is recorded to replace
the IR intrinsic metadata 'anon struct/union' to 'typedef'.
It is possible that two different 'typedef' types may have identical
anon struct/union type. For such a case, the association will be
<anon struct/union, nullptr> to indicate the invalid case.

Differential Revision: https://reviews.llvm.org/D129621
2022-07-13 15:16:16 -07:00
..
anon-struct-argument-pragma.ll [BPF] Handle anon record for CO-RE relocations 2022-07-13 15:16:16 -07:00
anon-union-localvar-attr.ll [BPF] Handle anon record for CO-RE relocations 2022-07-13 15:16:16 -07:00
anon-union-localvar-pragma.ll [BPF] Handle anon record for CO-RE relocations 2022-07-13 15:16:16 -07:00
btf-id-duplicate.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
field-reloc-alu32.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
field-reloc-bitfield-1-bpfeb.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
field-reloc-bitfield-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
field-reloc-bitfield-2-bpfeb.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
field-reloc-bitfield-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
field-reloc-bitfield-record-align16.ll [BPF] fix a CO-RE bitfield relocation error with >8 record alignment 2022-03-16 12:16:46 -07:00
field-reloc-duplicate.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-array-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-array.ll [OpaquePtr] Forbid mixing typed and opaque pointers 2021-09-10 15:18:23 +02:00
intrinsic-fieldinfo-byte-size-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-byte-size-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-byte-size-3.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-byte-size-4.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-existence-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-existence-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-existence-3.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-existence-4.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-lshift-1-bpfeb.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-lshift-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-lshift-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-rshift-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-rshift-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-rshift-3.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-signedness-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-signedness-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-fieldinfo-signedness-3.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-struct.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
intrinsic-typeinfo-enum-value-opaque-pointer.ll [BPF] Add BTF 64bit enum value support 2022-06-06 11:35:50 -07:00
intrinsic-typeinfo-enum-value.ll [BPF] Add BTF 64bit enum value support 2022-06-06 11:35:50 -07:00
intrinsic-typeinfo-type-exist.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
intrinsic-typeinfo-type-match.ll [BPF] Introduce support for type match relocations 2022-06-29 18:23:08 -07:00
intrinsic-typeinfo-type-size-1.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
intrinsic-typeinfo-type-size-2.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
intrinsic-union.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
no-elf-ama-symbol.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
no-narrow-load.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-access-str.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-basic.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-cast-array-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-cast-array-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-cast-struct-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-cast-struct-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-cast-struct-3.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-cast-union-1.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
offset-reloc-cast-union-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-end-load.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-end-ret.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-fieldinfo-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-fieldinfo-2-bpfeb.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-fieldinfo-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-global-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-global-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-global-3.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-ignore.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-middle-chain.ll [FileCheck] Catch missspelled directives. 2022-05-26 11:37:19 +01:00
offset-reloc-multi-array-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-multi-array-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-multilevel.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-pointer-1.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-pointer-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-struct-anonymous.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-struct-array.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-typedef-array.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-typedef-struct-2.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-typedef-struct.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-typedef-union-2.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
offset-reloc-typedef-union.ll Revert "[NFC] remove explicit default value for strboolattr attribute in tests" 2021-05-24 19:43:40 +02:00
offset-reloc-typedef.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
offset-reloc-union.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00
simplifypatable-nullptr.ll [BPF] Fix a bug in BPFMISimplifyPatchable pass 2022-04-19 15:24:26 -07:00
store-addr.ll [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics 2021-07-17 11:09:18 +02:00