The RFC intends to kick off the discussion on how to support
user defined address_space attributes in dwarf for linux kernel.
The use case:
In linux kernel, under certain make flags, pointers may be
annotated with additional address_space information. The source
code is below:
https://github.com/torvalds/linux/blob/master/include/linux/compiler_types.h
For example, we have
- define user attribute__((noderef, address_space(1)))
- define kernel attribute__((address_space(0)))
- define iomem attribute__((noderef, address_space(2)))
- define percpu attribute__((noderef, address_space(3)))
- define rcu attribute__((noderef, address_space(4)))
Currently, the address_space annotation is not used when compiling
a normal (production) kernel. It is typically used during development
and used by 'sparse' tool to check proper pointer usage.
Now there is a growing need to put address_space info into debug info,
e.g., dwarf, in linux binary to help automatically differentiate
pointers accessing kernel and user memories in order to avoid
explicit user annotations like below:
http://lkml.iu.edu/hypermail/linux/kernel/1905.1/05750.html
Other tracing tools like bpftrace, bcc would have similar issues.
The current patch
The proposal here is for user specified address_space, just add it
to DebugInfo and then later it will be automatically inserted into
dwarf. For example,
-bash-4.4$ cat t.c #define __user __attribute__((noderef, address_space(1))) void __user *g; extern int __user *foo(int *a, int __user *b); int __user *foo(int *a, int __user *b) { return b; } -bash-4.4$ clang -O2 -g -c t.c -bash-4.4$ llvm-dwarfdump t.o ... 0x0000002a: DW_TAG_variable DW_AT_name ("g") DW_AT_type (0x00000042 "*") 0x00000042: DW_TAG_pointer_type DW_AT_address_class (0x00000001) 0x00000060: DW_TAG_formal_parameter DW_AT_name ("a") DW_AT_type (0x00000091 "int*") 0x00000071: DW_TAG_formal_parameter DW_AT_name ("b") DW_AT_type (0x00000081 "int*") 0x00000081: DW_TAG_pointer_type DW_AT_type (0x0000008a "int") DW_AT_address_class (0x00000001) 0x00000091: DW_TAG_pointer_type DW_AT_type (0x0000008a "int") DW_AT_address_class (0x00000000)
The DW_AT_address_class attribute tells debugger how to
dereference the pointer on linux kernel platform.
Note that on linux, kernel and user address
dereference may require different pre-setting of
certain registers.
Question:
The here introduced new DW_AT_address_class 0x1 for BPF
and X86 is really at OS level, but I do not know how to
express it. Currently, it is specified at each target level
which also allows more flexibility of DW_AT_address_class values.