This is an archive of the discontinued LLVM Phabricator instance.

[BPF] extend BTF_KIND_FUNC to cover global, static and extern funcs
ClosedPublic

Authored by yonghong-song on Dec 17 2019, 4:44 PM.

Details

Summary
Previously extern function is added as BTF_KIND_VAR. This does not work
well with existing BTF infrastructure as function expected to use
BTF_KIND_FUNC and BTF_KIND_FUNC_PROTO.

This patch added extern function to BTF_KIND_FUNC. The two bits 0:1
of btf_type.info are used to indicate what kind of function it is:
  0: static
  1: global
  2: extern

Diff Detail

Event Timeline

yonghong-song created this revision.Dec 17 2019, 4:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2019, 4:44 PM
yonghong-song retitled this revision from [WIP][BPF] extern BTF_KIND_FUNC to cover global, static and extern funcs to [BPF] extern BTF_KIND_FUNC to cover global, static and extern funcs.
yonghong-song edited the summary of this revision. (Show Details)

use bpf_type.info lower two bits to encode func scope info

ast accepted this revision.Dec 17 2019, 7:25 PM

lgtm. please don't land it yet. Let me test with corresponding kernel and libbpf changes first.

This revision is now accepted and ready to land.Dec 17 2019, 7:25 PM
yonghong-song retitled this revision from [BPF] extern BTF_KIND_FUNC to cover global, static and extern funcs to [BPF] extend BTF_KIND_FUNC to cover global, static and extern funcs.Jan 2 2020, 10:57 AM
yonghong-song edited the summary of this revision. (Show Details)

add a test case for extern function with arguments.

To handle cases (exposed when running linux kernel samples/bpf/sockex1) like below:

unsigned long long load_byte(void *skb, unsigned long long off) asm("llvm.bpf.load.byte");
unsigned long long test(void *skb) {
  return load_byte(skb, 10);
}

previous approach emits load_byte as load_byte function is in module function reference list.
But actually this function is not called so we should not emit extern func BTF for this.

Change to check all JAL instructions and emit extern func if necessary.

This revision was automatically updated to reflect the committed changes.