[all-commits] [llvm/llvm-project] f41902: [BPF] Fix a bug in BTF_KIND_TYPE_TAG generation

yonghong-song via All-commits all-commits at lists.llvm.org
Mon Feb 14 19:45:58 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f419029fcdace7673c42ac01703eaaf36813356a
      https://github.com/llvm/llvm-project/commit/f419029fcdace7673c42ac01703eaaf36813356a
  Author: Yonghong Song <yhs at fb.com>
  Date:   2022-02-14 (Mon, 14 Feb 2022)

  Changed paths:
    M llvm/lib/Target/BPF/BTFDebug.cpp
    M llvm/lib/Target/BPF/BTFDebug.h
    A llvm/test/CodeGen/BPF/BTF/type-tag-fixup-fwd.ll
    A llvm/test/CodeGen/BPF/BTF/type-tag-fixup-resolved.ll

  Log Message:
  -----------
  [BPF] Fix a bug in BTF_KIND_TYPE_TAG generation

Kumar Kartikeya Dwivedi reported a bug ([1]) where BTF_KIND_TYPE_TAG types
are not generated.

Currently, BPF backend only generates BTF types which are used by
the program, e.g., global variables, functions and some builtin functions.
For example, suppose we have
  struct task_struct {
    ...
    struct task_group               *sched_task_group;
    struct mm_struct                *mm;
    ...
    pid_t                           pid;
    pid_t                           tgid;
    ...
  }
If BPF program intends to access task_struct->pid and task_struct->tgid,
there really no need to generate BTF types for struct task_group
and mm_struct.

In BPF backend, during BTF generation, when generating BTF for struct
task_struct, if types for task_group and mm_struct have not been generated
yet, a Fixup structure will be created, which will be reexamined later
to instantiate into either a full type or a forward type.

In current implementation, if we have something like
  struct foo {
     struct bar  __tag1    *f;
  };
and when generating types for struct foo, struct bar type
has not been generated, the __tag1 will be lost during later
Fixup instantiation. This patch fixed this issue by properly
handling btf_type_tag's during Fixup instantiation stage.

  [1] https://lore.kernel.org/bpf/20220210232411.pmhzj7v5uptqby7r@apollo.legion/

Differential Revision: https://reviews.llvm.org/D119799




More information about the All-commits mailing list