HomePhabricator

BPF: generate BTF info for LD_imm64 loaded function pointer

Authored by yonghong-song on Apr 14 2021, 1:08 PM.

Description

BPF: generate BTF info for LD_imm64 loaded function pointer

For an example like below,

extern int do_work(int);
long bpf_helper(void *callback_fn);
long prog() {
    return bpf_helper(&do_work);
}

The final generated codes look like:

r1 = do_work ll
call bpf_helper
exit

where we have debuginfo for do_work() extern function:

!17 = !DISubprogram(name: "do_work", ...)

This patch implemented to add additional checking
in processing LD_imm64 operands for possible function pointers
so BTF for bpf function do_work() can be properly generated.
The original llvm function name processReloc() is renamed to
processGlobalValue() to better reflect what the function is doing.

Differential Revision: https://reviews.llvm.org/D100568