Unable to find symbol from the GSL library
I'm finding an issue with a symbol:
python: symbol lookup error: /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2025-06-07/x86_64-ubuntu24.04-gcc13.3.0-opt/gsl/2.8-6zs23h/lib/libgsl.so.28: undefined symbol: cblas_dnrm2
This issue happens when linking with mold (by setting LDFLAGS=-fuse-ld=mold), but doesn't happen when I link with ld. I'm testing on several Linux (Ubuntu 24.04, Almalinux 9 and Arch Linux) and it only happens on Ubuntu 24.04. I'm using mold 2.40.0, but yesterday I tried compiling main and I could reproduce the same issue. I have no idea what's going on, the symbol is present in the library:
$ nm -C libgsl.so | grep dnrm2
U cblas_dnrm2
000000000007a3a0 T gsl_blas_dnrm2
I have created the following reproducer from a clean Ubuntu 24.04 image:
apt update
apt install -y git make cmake g++ binutils
wget "https://mirror.ibcp.fr/pub/gnu/gsl/gsl-latest.tar.gz"
tar xvf gsl-latest.tar.gz
cd gsl-2.8/
./configure --prefix=$PWD/install
make -j 8
make install
cd install
export PATH=$PWD/bin:$PATH
export LD_LIBRARY_PATH=$PWD/lib:$PWD/lib64:$LD_LIBRARY_PATH
export CMAKE_PREFIX_PATH=$PWD:$CMAKE_PREFIX_PATH
cd ../../
git clone https://github.com/rui314/mold --depth 1
cd mold
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_CXX_STANDARD=20
make -j 16
make install
cd ../install
export PATH=$PWD/bin:$PATH
export LDFLAGS=-fuse-ld=mold
cd ../../
git clone https://github.com/jmcarcell/mold-issue
cd mold-issue
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=20
make
./main
And I get:
./main: symbol lookup error: /gsl-2.8/install/lib/libgsl.so.28: undefined symbol: cblas_dnrm2
which I don't get without mold.
I can't reproduce the issue with your reproducer. Maybe that particular function (cblas_dnrm2) is called only when you have some particular hardware or something.
However, I found the following difference after running your reproducer.
$ ldd /lib/x86_64-linux-gnu/libgsl.so.27
linux-vdso.so.1 (0x000075a3f3cef000)
libgslcblas.so.0 => /lib/x86_64-linux-gnu/libgslcblas.so.0 (0x000075a3f39f9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000075a3f3910000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000075a3f36fe000)
/lib64/ld-linux-x86-64.so.2 (0x000075a3f3cf1000)
$ ldd /tmp/gsl-2.8/install/lib/libgsl.so
linux-vdso.so.1 (0x0000739e8ccf6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x0000739e8c903000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000739e8c6f1000)
/lib64/ld-linux-x86-64.so.2 (0x0000739e8ccf8000)
I believe this is the cause of your issue. Do you have any idea why? Note that /lib/x86_64-linux-gnu/libgsl.so.27 was built before mold, so mold was not involved how it was built.
Weird, I can reproduce in my PC which isn't very special (AMD 5700G). The original issue appeared when running CI on Github runners and after I reproduced in some VMs that we have that use Intel Xeons.
I noticed libgslcblas was not being linked to, but this is actually also the case in the original issue that I had when not using mold, and since the symbol is in libgsl I thought it would be OK. However, I have just installed an external cblas and made gsl link to it (this seems to be how Ubuntu and Arch Linux install it) and then the problem disappears (and it's linking to libgslcblas). So now I have a way to fix it, but nonetheless, this is something that only happens when using mold. Feel free to close since I have a fix and if you can't reproduce it's going to be hard to investigate.