[PATCH] D111199: [POC][BTF] support btf_type_tag attribute

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 5 17:29:30 PDT 2021


yonghong-song created this revision.
yonghong-song added a reviewer: aaron.ballman.
Herald added subscribers: dexonsmith, hiraditya.
yonghong-song requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Commit [1] introduced btf_tag attribute which
is used for declarations. Later we tried to compile
linux kernel by simply replacing __user definition
from attribute address_space to attribute btf_tag,
we hit two major issues:

  (1). btf_tag won't support type conversion, and 
  (2). btf_tag is not supported for typedef.

Commit [2] changed btf_tag attribute to be a
decl or type, i.e., can be applied to either declaration
or type, but actually does not do anything meaningful
for those type conversions. But typedef is still not 
resolved.

Patch [3] intended to address typedef issue. But through
discussion making btf_tag for both declaration and type
is not desirable. For example, making attributes in

  typedef int __user *__intp;
  int foo(int __user *arg, ...)

applying to declaration (__intp or arg) is not really
desirable. Further, we have code in kernel like:

  static int do_execve(struct filename *filename,
          const char __user *const __user *__argv,
          const char __user *const __user *__envp)

If __user is applied to declaration, we will lose
information that second-level dereference is also
user memory.

So it looks like it is good idea to introduce
a new type attribute. This patch introduced
btf_type_tag applying to type only. In the current
implementation, I only focus on pointers which is what
kernel is needed. Please see an dwarf generation example
in the patch.

If this approach is desirable, we can do the following:

  step 1: revert commit [2].
  step 2: I would like to rename current btf_tag
     to be btf_decl_tag to make it clear it is for 
     declaration.
  step 3: Introduce btf_type_tag as a type attribute.

This patch contains a hack in AttributedType to store
the btf_type_tag string. It is certainly not an acceptable
way. It would be great if I can get some advice on
where to store btf_type_tag string in AST.

  [1] https://reviews.llvm.org/D106614
  [2] https://reviews.llvm.org/D110116
  [3] https://reviews.llvm.org/D110127


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111199

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Attr.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-conv-var.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/Sema/attr-btf_type_tag.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/attr-btf_type_tag.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111199.377397.patch
Type: text/x-patch
Size: 19673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211006/b10134b5/attachment-0001.bin>


More information about the cfe-commits mailing list