[PATCH] D119986: [BPF] Fix a BTF type pruning bug

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 15:28:51 PST 2022


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added a subscriber: hiraditya.
yonghong-song requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119986

Files:
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/test/CodeGen/BPF/BTF/pruning-multi-derived-type.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119986.409437.patch
Type: text/x-patch
Size: 6915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220216/6e776874/attachment.bin>


More information about the llvm-commits mailing list