Search code examples
c++linkershared-librariesbazelelf

Ldd shows a weird library "do_not_link_against_nvinfer_builder_resource" that doesn't match linker logs


I'm trying to link a new library to my project libnvinfer_builder_resource.so.8.5.1, but I got this error when running it.

bazel-out/host/bin/gen_trt_ops_py_wrappers_cc: error while loading shared libraries: do_not_link_against_nvinfer_builder_resource: cannot open shared object file: No such file or directory

and ldd shows that it's actually linking a strange library instead of the one I added do_not_link_against_nvinfer_builder_resource => not found .

I debugged this a bit by enabling verbose logging for linker (tried both lld and gold), and they both show the correct library is found and linked.

/usr/bin/ld.gold: Attempt to open bazel-out/k8-fastbuild/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccufft___Ucuda_Slib64/libnvinfer_builder_resource.so.8.5.1 failed
/usr/bin/ld.gold: Attempt to open bazel-out/k8-fastbuild/bin/_solib_local/_U@local_Uconfig_Ucuda_S_Scuda_Ccurand___Ucuda_Slib64/libnvinfer_builder_resource.so.8.5.1 failed
/usr/bin/ld.gold: Opened new descriptor 9 for "bazel-out/k8-fastbuild/bin/_solib_local/_U@tensor_Urt_S_S_Ctensor_Urt___Ulib/libnvinfer_builder_resource.so.8.5.1"
/usr/bin/ld.gold: Attempt to open bazel-out/k8-fastbuild/bin/_solib_local/_U@tensor_Urt_S_S_Ctensor_Urt___Ulib/libnvinfer_builder_resource.so.8.5.1 succeeded
/usr/bin/ld.gold: Unlocking file "bazel-out/k8-fastbuild/bin/_solib_local/_U@tensor_Urt_S_S_Ctensor_Urt___Ulib/libnvinfer_builder_resource.so.8.5.1"
/usr/bin/ld.gold: Released descriptor 9 for "bazel-out/k8-fastbuild/bin/_solib_local/_U@tensor_Urt_S_S_Ctensor_Urt___Ulib/libnvinfer_builder_resource.so.8.5.1"
/usr/bin/ld.gold: Closed descriptor 9 for "bazel-out/k8-fastbuild/bin/_solib_local/_U@tensor_Urt_S_S_Ctensor_Urt___Ulib/libnvinfer_builder_resource.so.8.5.1"

And by searching I can't find any log about do_not_link_against_nvinfer_builder_resource .

So I'm wondering why linker links the correct libnvinfer_builder_resource.so.8.5.1, but it becomes do_not_link_against_nvinfer_builder_resource in the ldd?


Solution

  • It's because the author of TensorRT used a hack to add a do_not_link_against_nvinfer_builder_resource to libnvinfer_builder_resource.so.8.5.1. We can confirm this with readelf -d libnvinfer_builder_resource.so.8.5.1