Linking failure on RISC-V with GCC 11.2.1
infiWang opened this issue · comments
libtorrent version (or branch): 2.0.5
Platform/Architecture: RISC-V, Gentoo Linux, with lp64d systemd
profile
Compiler and compiler version: gcc (Gentoo 11.2.1_p20220115 p4) 11.2.1 20220115
Encountered the problem while trying to compile the qBittorrent 4.4.2 ebuild with latest portage tree. libtorrent-rasterbar
was built successfully, but during linking of qBittorrent it would fail due to missing __atomic_*
symbol from libtorrent
.
/usr/lib/gcc/riscv64-unknown-linux-gnu/11.2.1/../../../../riscv64-unknown-linux-gnu/bin/ld: /usr/lib64/libtorrent-rasterbar.
so.2.0.5: undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
distcc[2276441] ERROR: compile (null) on localhost failed
ninja: build stopped: subcommand failed.
AFAIK, this is because CMake script fails to detect missing subword atomic, as RISC-V doesn't have 1/2 byte atomic instruction.
- GCC should provide subword atomic inlining IMO, but currently they don't.
- This was bypassed by prefer
pthread
, hints linking tolatomic
previously (#6722). However, after glibc 2.34,-pthread
is nolonger needed to usepthread
libraries, hence no more linking tolatomic
.
Since replying on -pthread
for atomic is sementically incorrect, plus we already have a detection mechanism here, a possible fix could be enhance the detection.
Build log:
libtorrent-rasterbar-2.0.5-r1.log
qbittorrent-4.4.2.log