mercredi 22 septembre 2021

Atomic linking in Raspbian Bullseye (11) error

For this minimal program that uses atomics:

#include <atomic>
#include <stdint.h>
int main() 
{
    std::atomic<int64_t> x;
    x.store(1);
    x--;
    return x.load();
}

I'm unable to get the linking correctly on my Raspberry Pi 4, on Raspbian Bullseye. I compile it with:

g++ -L/usr/lib/arm-linux-gnueabihf -latomic main.cpp

I get the errors:

$ g++ -L/usr/lib/arm-linux-gnueabihf -latomic main.cpp
/usr/bin/ld: /tmp/ccEoFsKg.o: in function `main':
main.cpp:(.text+0x40): undefined reference to `__atomic_store_8'
/usr/bin/ld: main.cpp:(.text+0x80): undefined reference to `__atomic_load_8'
/usr/bin/ld: /tmp/ccEoFsKg.o: in function `std::__atomic_base<long long>::operator--(int)':
main.cpp:(.text._ZNSt13__atomic_baseIxEmmEi[_ZNSt13__atomic_baseIxEmmEi]+0x40): undefined reference to `__atomic_fetch_sub_8'
collect2: error: ld returned 1 exit status

and btw, that directory contains libatomic (it's not the first time I link like this... but now this came out of the blue, and I'm not sure what's going on):

$ ll /usr/lib/arm-linux-gnueabihf/libatomic.so.1*
lrwxrwxrwx 1 root root  18 Jan 21  2021 /usr/lib/arm-linux-gnueabihf/libatomic.so.1 -> libatomic.so.1.2.0
-rw-r--r-- 1 root root 30K Jan 21  2021 /usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0

And that library does contain these functions!

$ nm -D /usr/lib/arm-linux-gnueabihf/libatomic.so.1 | grep -i fetch_sub
0000269c i __atomic_fetch_sub_1@@LIBATOMIC_1.0
00003118 i __atomic_fetch_sub_2@@LIBATOMIC_1.0
00003a74 i __atomic_fetch_sub_4@@LIBATOMIC_1.0
00004348 i __atomic_fetch_sub_8@@LIBATOMIC_1.0
$ nm -D /usr/lib/arm-linux-gnueabihf/libatomic.so.1 | grep -i __atomic_load
0000164c T __atomic_load@@LIBATOMIC_1.0
00002270 i __atomic_load_1@@LIBATOMIC_1.0
00002cd8 i __atomic_load_2@@LIBATOMIC_1.0
0000375c i __atomic_load_4@@LIBATOMIC_1.0
00003fa4 i __atomic_load_8@@LIBATOMIC_1.0

g++ specs:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/10/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 10.2.1-6+rpi1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20210110 (Raspbian 10.2.1-6+rpi1)

System specs:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

What am I missing?

Aucun commentaire:

Enregistrer un commentaire