[PATCH] D82041: [BPF] fix a bug for BTF pointee type pruning

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 17 12:24:18 PDT 2020


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

In BTF, pointee type pruning is used to reduce cluttering
too many unused types into prog BTF. For example,

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

If bpf program does not access members of "struct mm_struct",
there is no need to bring types for "struct mm_struct" to BTF.

This patch fixed a bug where an incorrect pruning happened.
The test case like below:

  struct t;
  typedef struct t _t; 
  struct s1 { _t *c; };
  int test1(struct s1 *arg) { ... }
  
  struct t { int a; int b; };
  struct s2 { _t c; }
  int test2(struct s2 *arg) { ... }

After processing test1(), among others, BPF backend generates BTF types for

  "struct s1", "_t" and a placeholder for "struct t". 

Note that "struct t" is not really generated. If later a direct access
to "struct t" member happened, "struct t" BTF type will be generated
properly.

During processing test2(), when processing member type "_t c", 
BPF backend sees type "_t" already generated, so returned.
This caused the problem that "struct t" BTF type is never generated and 
eventually causing incorrect type definition for "struct s2".

To fix the issue, during DebugInfo type traversal, even if a
typedef/const/volatile/restrict derived type has been recorded in BTF,
if it is not a type pruning candidate, type traversal of its base type continues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82041

Files:
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/test/CodeGen/BPF/BTF/pruning-const.ll
  llvm/test/CodeGen/BPF/BTF/pruning-typedef.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82041.271441.patch
Type: text/x-patch
Size: 15800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200617/93b520ea/attachment.bin>


More information about the llvm-commits mailing list