Page MenuHomePhabricator

fix typedef issue for offset relocation

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



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

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


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.
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.
55 ↗(On Diff #211660)

thanks for spotting this. will fix.

This revision was automatically updated to reflect the committed changes.