This is an archive of the discontinued LLVM Phabricator instance.

BPF: permit .maps section variables with typedef type
ClosedPublic

Authored by yonghong-song on Jul 11 2020, 11:02 PM.

Details

Summary

Currently, llvm when see a global variable in .maps section,
it ensures its type must be a struct type. Then pointee
will be further evaluated for the structure members.
In normal cases, the pointee type will be skipped.

Although this is what current all bpf programs are doing,
but it is a little bit restrictive. For example, it is legitimate
for users to have:
typedef struct { int key_size; int value_size; } map_t;
map_t map attribute((section(".maps")));

This patch lifts this restriction and typedef of
a struct type is also allowed for .maps section variables.
To avoid create unnecessary fixup entries when traversal
started with typedef/struct type, the new implementation
first traverse all map struct members and then traverse
the typedef/struct type. This way, in internal BTFDebug
implementation, no fixup entries are generated.

Two new unit tests are added for typedef and const
struct in .maps section. Also tested with kernel bpf selftests.

Diff Detail

Event Timeline

yonghong-song created this revision.Jul 11 2020, 11:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2020, 11:02 PM

maybe let's just remove special-casing of .maps section? It's just like any other global variable, should be handled in exactly the same way, no?

maybe let's just remove special-casing of .maps section? It's just like any other global variable, should be handled in exactly the same way, no?

for .maps, we need to trace pointee types. For general globals, functional arguments, etc., we do not trace pointee types like in struct t { struct task_struct *p; } the task_struct won't be traced. That is why we need to handle .maps specially.

anakryiko accepted this revision.Jul 12 2020, 12:31 AM

ah, makes sense. LGTM then :)

This revision is now accepted and ready to land.Jul 12 2020, 12:31 AM
This revision was automatically updated to reflect the committed changes.