]> granicus.if.org Git - llvm/commit
Merging r367062:
authorHans Wennborg <hans@hanshq.net>
Mon, 29 Jul 2019 09:01:42 +0000 (09:01 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 29 Jul 2019 09:01:42 +0000 (09:01 +0000)
commit2bf02e6e83742a8757e61564bfc1b5372f323d6e
tree525483034b99574d19f68229cc21030309d16e7d
parent50d67a2d298303b051f644bbbbf8e9eb7b2dd66e
Merging r367062:
------------------------------------------------------------------------
r367062 | yhs | 2019-07-25 23:47:27 +0200 (Thu, 25 Jul 2019) | 30 lines

[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/branches/release_90@367211 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]