[Clang][Attr] Support btf_type_tag attribute
authorYonghong Song <yhs@fb.com>
Thu, 4 Nov 2021 20:23:19 +0000 (13:23 -0700)
committerYonghong Song <yhs@fb.com>
Thu, 4 Nov 2021 20:59:18 +0000 (13:59 -0700)
commiteb0fa8bfa356d49198f98b878b004bce59232bb0
treebd4cbdd23e33e4cbca6d78d408e9f289ae8b231f
parent76cbe62262a3ccd0604599a1103ce5d38ac0164b
[Clang][Attr] Support btf_type_tag attribute

This patch introduced btf_type_tag attribute. The attribute
is a type attribute and intends to address the below
linux use cases.
    typedef int __user *__intp;
    int foo(int __user *arg, ...)
    static int do_execve(struct filename *filename,
        const char __user *const __user *__argv,
        const char __user *const __user *__envp)

Here __user in the kernel defined as
    __attribute__((noderef, address_space(__user)))
for sparse ([1]) type checking mode.

For normal clang compilation, we intend to replace it with
    __attribute__((btf_type_tag("user")))
and record such informaiton in dwarf and BTF so such
information later can be used in kernel for bpf verification
or for other tracing functionalities.

  [1] https://www.kernel.org/doc/html/v4.11/dev-tools/sparse.html

Differential Revision: https://reviews.llvm.org/D111199
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Sema/attr-btf_type_tag.c [new file with mode: 0644]