This is an archive of the discontinued LLVM Phabricator instance.

BPF: generate BTF info for LD_imm64 loaded function pointer
ClosedPublic

Authored by yonghong-song on Apr 15 2021, 8:28 AM.

Details

Summary

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.

Diff Detail

Event Timeline

yonghong-song created this revision.Apr 15 2021, 8:28 AM
yonghong-song requested review of this revision.Apr 15 2021, 8:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2021, 8:28 AM

The corresponding clang patch is here: https://reviews.llvm.org/D100567

ast accepted this revision.Apr 15 2021, 8:34 AM
This revision is now accepted and ready to land.Apr 15 2021, 8:34 AM
  • change the test case to have a section name for the extern func which should be the most common use case. We already have tests for extern func (direct call instead of callback) which called the same internal llvm function, so the case without section name should be covered as well.
anakryiko accepted this revision.Apr 19 2021, 10:28 AM
This revision was landed with ongoing or failed builds.Apr 26 2021, 5:23 PM
This revision was automatically updated to reflect the committed changes.