bcc icon indicating copy to clipboard operation
bcc copied to clipboard

`bcc_procutils_which_so` finds wrong library if query matches a prefix of another library

Open nelhage opened this issue 2 years ago • 0 comments

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 uses a simplistic substring match on the query followed by either . or -; 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.

nelhage avatar Oct 16 '23 18:10 nelhage