This is an archive of the discontinued LLVM Phabricator instance.

[BPF] Fix a bug for __builtin_preserve_field_info() processing
ClosedPublic

Authored by yonghong-song on Jun 30 2020, 10:20 PM.

Details

Summary

Andrii discovered a problem where a simple case similar to below
will generate wrong relocation kind:

enum { FIELD_EXISTENCE = 2, };
struct s1 { int a1; };
int test() {
  struct s1 *v = 0;
  return __builtin_preserve_field_info(v[0], FIELD_EXISTENCE);
}

The expected relocation kind should be FIELD_EXISTENCE, but
recorded reloc kind in the final object file is FIELD_BYTE_OFFSET,
which is incorrect.

This exposed a bug in generating access strings from intrinsics.
The current access string generation has two steps:

step 1: find the base struct/union type,
step 2: traverse members in the base type.

The current implementation relies on at lease one member access
in step 2 to get the correct relocation kind, which is true
in typical cases. But if there is no member accesses, the current
implementation falls to the default info kind FIELD_BYTE_OFFSET.
This is incorrect, we should still record the reloc kind
based on the user input. This patch fixed this issue by properly
recording the reloc kind in such cases.

Diff Detail

Event Timeline

yonghong-song created this revision.Jun 30 2020, 10:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2020, 10:20 PM
ast accepted this revision.Jun 30 2020, 10:54 PM
This revision is now accepted and ready to land.Jun 30 2020, 10:54 PM
This revision was automatically updated to reflect the committed changes.