extern variable usage in BPF is different from traditional
pure user space application. Recent discussion in linux bpf
mailing list has two use cases where debug info types are
required to use extern variables:
- extern types are required to have a suitable interface in libbpf (bpf loader) to provide kernel config parameters to bpf programs. https://lore.kernel.org/bpf/CAEf4BzYCNo5GeVGMhp3fhysQ=_axAf=23PtwaZs-yAyafmXC9g@mail.gmail.com/T/#t
- extern types are required so kernel bpf verifier can verify program which uses external functions more precisely. This will make later link with actual external function no need to reverify. https://lore.kernel.org/bpf/87eez4odqp.fsf@toke.dk/T/#m8d5c3e87ffe7f2764e02d722cb0d8cbc136880ed
This patch added clang support to emit debuginfo for extern variables,
and bpf support to consume such info into BTF, which can then be used
by bpf loader.
A few more things need to do:
- currently, I added clang EmitGlobalDeclVariable() to emit debuginfo for extern variables. It might be possible to reuse existing EmitGlobalVariable(). Need double check.
- BPF is C only, so I only tested C. I am not sure whether adding other language support is necessary at this point.
- add clang test cases and a few more bpf backend tests.
But some early feedback will be great!