This is an archive of the discontinued LLVM Phabricator instance.

fix typedef issue for offset relocation
ClosedPublic

Authored by yonghong-song on Jul 24 2019, 7:35 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

yonghong-song created this revision.Jul 24 2019, 7:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2019, 7:35 PM
ast accepted this revision.Jul 24 2019, 9:13 PM
ast added inline comments.
lib/Target/BPF/BTFDebug.cpp
55 ↗(On Diff #211660)

unnecessary empty line

This revision is now accepted and ready to land.Jul 24 2019, 9:13 PM
yonghong-song marked an inline comment as done.Jul 24 2019, 9:58 PM
yonghong-song added inline comments.
lib/Target/BPF/BTFDebug.cpp
55 ↗(On Diff #211660)

thanks for spotting this. will fix.

This revision was automatically updated to reflect the committed changes.