[PATCH] D136041: [clang][DebugInfo] Emit DISubprogram for extern functions with reserved names
Yonghong Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 17 09:25:45 PDT 2022
yonghong-song added a comment.
@aprantl The following example shows the difference between gcc and clang w.r.t. reserved names.
[$ ~/tmp3] cat t.c
extern void *__bpf_kptr_new(int, int, void *)
__attribute__((section(".ksyms")));
#define bpf_kptr_new(x) __bpf_kptr_new(x, 0, 0)
struct foo {
int data;
};
int main(void)
{
struct foo *f;
f = bpf_kptr_new(0);
return f->data;
}
[$ ~/tmp3] clang -target bpf -O2 -g -c t.c
[$ ~/tmp3] llvm-dwarfdump t.o | grep bpf_kptr_new
[$ ~/tmp3] gcc -O2 -g -c t.c
[$ ~/tmp3] llvm-dwarfdump t.o | grep bpf_kptr_new
DW_AT_abstract_origin (0x000000a3 "__bpf_kptr_new")
DW_AT_linkage_name ("__bpf_kptr_new")
DW_AT_name ("__bpf_kptr_new")
[$ ~/tmp3]
If not using reserved name, the function will appear in debuginfo/dwarf:
[$ ~/tmp3] cat t1.c
extern void *bpf_kptr_new_(int, int, void *)
__attribute__((section(".ksyms")));
#define bpf_kptr_new(x) bpf_kptr_new_(x, 0, 0)
struct foo {
int data;
};
int main(void)
{
struct foo *f;
f = bpf_kptr_new(0);
return f->data;
}
[$ ~/tmp3] clang -target bpf -O2 -g -c t1.c
[$ ~/tmp3] llvm-dwarfdump t1.o | grep bpf_kptr_new
DW_AT_name ("bpf_kptr_new_")
[$~/tmp3] gcc -O2 -g -c t1.c
[$ ~/tmp3] llvm-dwarfdump t1.o | grep bpf_kptr_new
DW_AT_abstract_origin (0x000000a3 "bpf_kptr_new_")
DW_AT_linkage_name ("bpf_kptr_new_")
DW_AT_name ("bpf_kptr_new_")
[$ ~/tmp3]
In BPF, we need the above extern function in debuginfo. This happens when a bpf program is calling a function defined in kernel. For example,
in kernel we have function
int tcp_drop(struct sk_buff *skb, ...) { ...
}
/* allow tcp_drop() function accessible to bpf programs */
In bpf program, we could have
extern int tcp_drop(struct sk_buff *sbk, ...);
BPF_PROG(...) {
tcp_drop(...)
BPF verifier will need to check whether the signature of tcp_drop() in bpf program matched the one in kernel or not. In kernel, we DO have some global functions with '__' prefix in the function name. Although no reserved function name works, we want all legal names working so user won't be surprised why some kernel functions are not available to them.
}
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136041/new/
https://reviews.llvm.org/D136041
More information about the cfe-commits
mailing list