conda-forge / ctng-compilers-feedstock

A conda-smithy repository for ctng-compilers.
BSD 3-Clause "New" or "Revised" License
12 stars 28 forks source link

Wrong RPATH on many shared libraries #73

Closed mattgodbolt closed 3 years ago

mattgodbolt commented 3 years ago

Issue: all the lib*.so files installed by libgcc-ng, and libgomp, have an unpatched RPATH which means (for example), linking against libasan.so can yield linker errors (e.g. unable to find the libstdc++.so.6 that libasan requires, as it doesn't look in $ORIGIN etc).

$ for f in *.so; echo $f; readelf -d $f | grep 'rpath'; end
libasan.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803321475/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/../lib]
libatomic.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803324264/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib]
libcc1.so
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/.]
libgcc_s.so
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
libgomp.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803324264/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib]
libitm.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803324264/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib]
liblsan.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803321475/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/../lib]
libquadmath.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803324264/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib]
libstdc++.so
libtsan.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803321475/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/../lib]
libubsan.so
 0x000000000000000f (RPATH)              Library rpath: [/home/conda/feedstock_root/build_artifacts/gcc_compilers_1632803321475/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/../lib]


Environment (conda list):

``` $ conda list # packages in environment at /tmp/moo: # # Name Version Build Channel _libgcc_mutex 0.1 conda_forge conda-forge _openmp_mutex 4.5 1_gnu conda-forge binutils_impl_linux-64 2.36.1 h193b22a_2 conda-forge binutils_linux-64 2.36 hf3e587d_1 conda-forge gcc_impl_linux-64 9.4.0 h03d3576_9 conda-forge gcc_linux-64 9.4.0 h391b98a_1 conda-forge kernel-headers_linux-64 2.6.32 he073ed8_14 conda-forge ld_impl_linux-64 2.36.1 hea4e1c9_2 conda-forge libgcc-devel_linux-64 9.4.0 hd854feb_9 conda-forge libgcc-ng 11.2.0 h1d223b6_9 conda-forge libgomp 11.2.0 h1d223b6_9 conda-forge libsanitizer 9.4.0 h79bfe98_9 conda-forge libstdcxx-ng 11.2.0 he4da1e4_9 conda-forge sysroot_linux-64 2.12 he073ed8_14 conda-forge ```


Details about conda and system ( conda info ):

``` $ conda info active environment : None user config file : /home/mgodbolt/.condarc populated config files : conda version : 4.10.3 conda-build version : 3.21.4 python version : 3.7.7.final.0 virtual packages : __linux=4.15.0=0 __glibc=2.27=0 __unix=0=0 __archspec=1=x86_64 base environment : /home/mgodbolt/.cache/ozy/conda/4.8.3 (writable) conda av data dir : /home/mgodbolt/.cache/ozy/conda/4.8.3/etc/conda conda av metadata url : None channel URLs : https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /home/mgodbolt/.cache/ozy/conda/4.8.3/pkgs /home/mgodbolt/.conda/pkgs envs directories : /home/mgodbolt/.cache/ozy/conda/4.8.3/envs /home/mgodbolt/.conda/envs platform : linux-64 user-agent : conda/4.10.3 requests/2.23.0 CPython/3.7.7 Linux/4.15.0-159-generic ubuntu/18.04.6 glibc/2.27 UID:GID : 5011:5011 netrc file : None offline mode : False ```
mattgodbolt commented 3 years ago

Example of the problem:

$ echo 'void main(){}' | bin/x86_64-conda_cos6-linux-gnu-gcc -fsanitize=address -x c -
/tmp/moo/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: warning: libstdc++.so.6, needed by /tmp/moo/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/lib/../lib/libasan.so, not found (try using -rpath or -rpath-link)

but it the rpath is actually set:

$ patchelf --set-rpath '$ORIGIN' lib/libasan.so 
$ echo 'void main(){}' | bin/x86_64-conda_cos6-linux-gnu-gcc -fsanitize=address -x c -
$

it compiles without error. It seems the recipe goes out of its way to disable conda's default rpath patching: https://github.com/conda-forge/ctng-compilers-feedstock/blob/7a4f650a775b7248246631a4f94726e50d2df35f/recipe/meta.yaml#L317 - there's not a clear reason why this is not enabled (though there's some other things that are enabled for binary relocation, and indeed some patchelf things going on too)

isuruf commented 3 years ago

I'm not sure why binary_relocation is disabled. Let's try enabling them.

isuruf commented 3 years ago

See https://github.com/conda-forge/ctng-compilers-feedstock/pull/74

isuruf commented 3 years ago

Fixed in #74

mattgodbolt commented 3 years ago

Confirmed fixed! Thank you so much!