`bcc_procutils_which_so` finds wrong library if query matches a prefix of another library
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
I'm trying to use `bcc` to trace a program that uses NVIDIA's NCCL library. NCCL includes both a `libnccl.so` and a `libnccl-net.so`. The matching logic in `` unfortunately means that querying for a library of "nccl" finds the wrong library if both are loaded.
I've attached a test that uses `bcc_procutils_which_so` and prints the result before and after loading `libnccl` and `libnccl-net`; on my machine, I see this output:
```
Before load:
'nccl' -> /usr/local/lib/libnccl.so.2
After load libnccl:
'nccl' -> /usr/local/lib/libnccl.so.2.18.5
After load libnccl-net:
'nccl' -> /usr/local/lib/libnccl-net.so
```
Loading `libnccl-net.so` has caused the library name of "nccl" to switch from correctly naming `libnccl.so` to incorrectly refer to `libnccl-net.so`.
The issue appears to be that [`which_so_in_process`](https://github.com/iovisor/bcc/blob/b1bd28e785b4231aba99dd02a239102db56564af/src/cc/bcc_proc.c#L465) uses a simplistic substring match on the query [followed by either `.` or `-`](https://github.com/iovisor/bcc/blob/b1bd28e785b4231aba99dd02a239102db56564af/src/cc/bcc_proc.c#L478-L479); but the path "libnccl-net.so" matches `"nccl" + "-"` and so is incorrectly found for the "nccl" query.
I imagine preserving the substring-match may be important for backwards compatibility, but potentially `which_so_in_process` could be made to prefer an exact match if found.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/cc/bcc_proc.c at which_so_in_process and inspect the matching logic around the referenced lines. Use the attached test that calls bcc_procutils_which_so before and after loading libnccl.so and libnccl-net.so. Done means an exact nccl library match remains selected while preserving the existing substring behavior where needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100