This is an archive of the discontinued LLVM Phabricator instance.

[BPF] Fix a BTF type pruning bug
ClosedPublic

Authored by yonghong-song on Feb 16 2022, 3:28 PM.

Details

Summary

In BPF backend, BTF type generation may skip
some debuginfo types if they are the pointee
type of a struct member. For example,

struct task_struct {
  ...
  struct mm_struct                *mm;
  ...
};

BPF backend may generate a forward decl for
'struct mm_struct' instead of full type if
there are no other usage of 'struct mm_struct'.
The reason is to avoid bringing too much unneeded types
in BTF.

Alexei found a pruning bug where we may miss
some full type generation. The following is an illustrating
example:

struct t1 { ... }
struct t2 { struct t1 *p; };
struct t2 g;
void foo(struct t1 *arg) { ... }

In the above case, we will have partial debuginfo chain like below:

struct t2 -> member p
                     \ -> ptr -> struct t1
                     /
  foo -> argument arg

During traversing

   struct t2 -> member p -> ptr -> struct t1
The corresponding BTF types are generated except 'struct t1' which

will be in FixUp stage. Later, when traversing

foo -> argument arg -> ptr -> struct t1

The 'ptr' BTF type has been generated and currently implementation
ignores 'pointer' type hence 'struct t1' is not generated.

This patch fixed the issue not just for the above case, but for
general case with multiple derived types, e.g.,

struct t2 -> member p
                     \ -> const -> ptr -> volatile -> struct t1
                     /
  foo -> argument arg

Diff Detail

Event Timeline

yonghong-song created this revision.Feb 16 2022, 3:28 PM
yonghong-song requested review of this revision.Feb 16 2022, 3:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2022, 3:28 PM
ast accepted this revision.Feb 16 2022, 4:53 PM
This revision is now accepted and ready to land.Feb 16 2022, 4:53 PM
This revision was landed with ongoing or failed builds.Feb 16 2022, 5:23 PM
This revision was automatically updated to reflect the committed changes.