]> granicus.if.org Git - llvm/commit
[BPF] fix typedef issue for offset relocation
authorYonghong Song <yhs@fb.com>
Thu, 25 Jul 2019 21:47:27 +0000 (21:47 +0000)
committerYonghong Song <yhs@fb.com>
Thu, 25 Jul 2019 21:47:27 +0000 (21:47 +0000)
commit99818ae847feb7f1599aca161be34e60dd16d1f4
tree0ef494ffac184eb365824f8c0d0d2308ad04065e
parent52b7e93f00b2eb28e03574b2a6e3a834330996c6
[BPF] fix typedef issue for offset relocation

Currently, the CO-RE offset relocation does not work
if any struct/union member or array element is a typedef.
For example,
  typedef const int arr_t[7];
  struct input {
      arr_t a;
  };
  func(...) {
       struct input *in = ...;
       ... __builtin_preserve_access_index(&in->a[1]) ...
  }
The BPF backend calculated default offset is 0 while
4 is the correct answer. Similar issues exist for struct/union
typedef's.

When getting struct/union member or array element type,
we should trace down to the type by skipping typedef
and qualifiers const/volatile as this is what clang did
to generate getelementptr instructions.
(const/volatile member type qualifiers are already
ignored by clang.)

This patch fixed this issue, for each access index,
skipping typedef and const/volatile/restrict BTF types.

Signed-off-by: Yonghong Song <yhs@fb.com>
Differential Revision: https://reviews.llvm.org/D65259

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367062 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/BPF/BTFDebug.cpp
lib/Target/BPF/BTFDebug.h
test/CodeGen/BPF/CORE/offset-reloc-typedef-array.ll [new file with mode: 0644]
test/CodeGen/BPF/CORE/offset-reloc-typedef-struct.ll [new file with mode: 0644]
test/CodeGen/BPF/CORE/offset-reloc-typedef-union.ll [new file with mode: 0644]
test/CodeGen/BPF/CORE/offset-reloc-typedef.ll [new file with mode: 0644]