bpf_usdt_readarg can't be used in static helper functions
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 3
Description
Repro code:
```python
from bcc import BPF, USDT
import os
text = """
static int probe1(struct pt_regs *ctx) {
int arg1;
bpf_usdt_readarg(1, ctx, &arg1);
return 0;
}
int probe(struct pt_regs *ctx) {
return probe1(ctx);
}
"""
usdt = USDT(pid=os.getpid())
usdt.enable_probe("memory_mallopt", "probe")
bpf = BPF(text=text, usdt_contexts=[usdt], debug=4)
```
Run:
```
# python usdtrepro.py
LLVM ERROR: Program used external function '_bpf_readarg__1' which could not be resolved!
```
This is caused by https://github.com/iovisor/bcc/blob/master/src/cc/frontends/clang/b_frontend_action.cc#L460 which uses `current_fn_`, which is not initialized if we're parsing a static helper function (see https://github.com/iovisor/bcc/blob/master/src/cc/frontends/clang/b_frontend_action.cc#L221 which conditionally initializes it).
@vmg @drzaeus77 Not sure what the fix here should be; the code generated in usdt.cc uses the calling function's name when generating the readarg helpers, but we don't have the calling function's name in the frontend action.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the static-helper handling in src/cc/frontends/clang/b_frontend_action.cc, especially the current_fn_ initialization near the referenced lines, then compare it with the readarg helper naming in usdt.cc. Run the provided Python reproducer and verify that a static helper using bpf_usdt_readarg compiles without the unresolved _bpf_readarg__1 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- compilers, devtools, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100