tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

libgomp linked twice

Open danieldk opened this issue 4 years ago • 1 comments

When building against tch-sys, libgomp is linked twice:

$ ldd target/release/syntaxdot | grep libgomp
	libgomp.so.1 => /nix/store/9ilyrqidrjbqvmnn8ykjc7lygdd86g7q-gcc-10.2.0-lib/lib/libgomp.so.1 (0x00007f8bc2423000)
	libgomp-75eea7e8.so.1 => /nix/store/kmwv690gyslwrf9ymqwv9q2xadnhs7hr-libtorch-1.8.1/lib/libgomp-75eea7e8.so.1 (0x00007f8bc17d1000)

The first occurrence is added through the -lgomp flag added through build.rs. The second occurrence is the libgomp provided by libtorch itself:

$ readelf -d ${LIBTORCH}/lib/libtorch_cpu.so | grep libgomp
 0x0000000000000001 (NEEDED)             Shared library: [libgomp-75eea7e8.so.1]

However, I am wondering what the purpose of adding the -lgomp flag is. Because even when libtorch is built against system libraries, it will already have libgomp as one of its needed shared libraries:

$ readelf -d $(nix-build '<nixpkgs>' -A python3Packages.pytorch.lib)/lib/libtorch_cpu.so | grep gomp
 0x0000000000000001 (NEEDED)             Shared library: [libgomp.so.1]

So, adding the -lgomp linker flag only seems to have a negative side-effect that the OpenMP runtime is linked twice when it's already provided (such as in the upstream libtorch library).

danieldk avatar May 19 '21 18:05 danieldk

I don't really remember why we need this. If you can test it for both the cpu and cuda version without this flag for the msvc period, happy to have it removed.

LaurentMazare avatar May 20 '21 04:05 LaurentMazare