You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
compiler_types: define __user as __attribute__((btf_type_tag("user")))
If pahole and compiler supports btf_type_tag attributes,
during kernel build, we can define __user as
__attribute__((btf_type_tag("user"))). This will encode __user
information in BTF. Such information, encoded in BTF
as BTF_KIND_TYPE_TAG, can help bpf verifier to
ensure proper memory dereference mechanism depending
on user memory or kernel memory.
The encoded __user info is also useful for other tracing
facility where instead of to require user to specify
kernel/user address type, the kernel can detect it
by itself with btf.
The following is an example with latest upstream clang
(clang14, [1]) and latest pahole:
[$ ~] cat test.c
#define __tag1 __attribute__((btf_type_tag("tag1")))
int foo(int __tag1 *arg) {
return *arg;
}
[$ ~] clang -O2 -g -c test.c
[$ ~] pahole -JV test.o
...
[1] INT int size=4 nr_bits=32 encoding=SIGNED
[2] TYPE_TAG tag1 type_id=1
[3] PTR (anon) type_id=2
[4] FUNC_PROTO (anon) return=1 args=(3 arg)
[5] FUNC foo type_id=4
[$ ~]
You can see for the function argument "int __tag1 *arg",
its type is described as
PTR -> TYPE_TAG(tag1) -> INT
The kernel can take advantage of this information
to bpf verification or other use cases.
Current btf_type_tag is only supported in clang (>= clang14).
gcc support is also proposed and under development ([2]).
[1] https://reviews.llvm.org/D111199
[2] https://www.spinics.net/lists/bpf/msg45773.html
Signed-off-by: Yonghong Song <[email protected]>
0 commit comments