crystal
crystal copied to clipboard
Can't use Atomic with Int128 or UInt128
Bug Report
When I try to use Atomic#get
, Atomic#set
, or Atomic#compare_and_set
with a type of Int128 or UInt128, I get this at compile time:
/usr/bin/ld: A-tomic40I-nt12841.o0.o: in function `get':
/usr/share/crystal/src/atomic.cr:310: undefined reference to `__sync_val_compare_and_swap_16'
/usr/bin/ld: /usr/share/crystal/src/atomic.cr:312: undefined reference to `__sync_val_compare_and_swap_16'
/usr/bin/ld: /usr/share/crystal/src/atomic.cr:314: undefined reference to `__sync_val_compare_and_swap_16'
/usr/bin/ld: A-tomic40I-nt12841.o0.o: in function `set':
/usr/share/crystal/src/atomic.cr:283: undefined reference to `__atomic_store'
/usr/bin/ld: /usr/share/crystal/src/atomic.cr:285: undefined reference to `__atomic_store'
/usr/bin/ld: /usr/share/crystal/src/atomic.cr:287: undefined reference to `__atomic_store'
collect2: error: ld returned 1 exit status
Error: execution of command failed with exit status 1: cc "${@}" -o /home/alexa/.cache/crystal/crystal-run-test.tmp -rdynamic -L/usr/bin/../lib/crystal -lpcre2-8 -lgc -lpthread -ldl -lpthread -levent -lrt -lpthread -ldl
Here's some reduced example code:
atomic = Atomic(Int128).new(0i128)
puts atomic.get
atomic.set(42i128)
puts atomic.get
Crystal version output:
Crystal 1.12.0-dev [47bb15b02] (2024-04-03)
LLVM: 13.0.0
Default target: x86_64-unknown-linux-gnu
What if you enable support for DWCAS which is disabled by default by LLVM. For example it's --mattr=+cx16
for x86_64.
Hum, the linker doesn't need the __sync_val_compare_and_swap_16
symbol anymore, but still misses the __atomic_store
symbol:
$ crystal build --mattr=+cx16 x.cr
/usr/bin/ld : A-tomic40I-nt12841.o0.o : dans la fonction « set » :
/home/julien/src/crystal-1.11.2/src/atomic.cr:204 : référence indéfinie vers « __atomic_store »
collect2: error: ld returned 1 exit status
Error: execution of command failed with exit status 1: cc "${@}" -o /tmp/x -rdynamic -L/usr/lib/crystal -lpcre2-8 -L/usr/local/lib -lgc -lpthread -ldl -lpthread -levent -lrt -lpthread -ldl
Yeah, I get different error message now, also referring to __atomic_store
:
[alexa@lain ~]$ crystal run --mattr=+cx16 test.cr
/usr/bin/ld: A-tomic40I-nt12841.o0.o: in function `set':
/usr/share/crystal/src/atomic.cr:283: undefined reference to `__atomic_store'
/usr/bin/ld: /usr/share/crystal/src/atomic.cr:285: undefined reference to `__atomic_store'
/usr/bin/ld: /usr/share/crystal/src/atomic.cr:287: undefined reference to `__atomic_store'
collect2: error: ld returned 1 exit status
Error: execution of command failed with exit status 1: cc "${@}" -o /home/alexa/.cache/crystal/crystal-run-test.tmp -rdynamic -L/usr/bin/../lib/crystal -lpcre2-8 -lgc -lpthread -ldl -lpthread -levent -lrt -lpthread -ldl
This is when running on my Slackware 15.0 system (x86-64), which ships with LLVM 13 as a system package. When I run it on my aarch64 laptop running Slackware-Current (the unstable development version of Slackware, which has LLVM 18.1.2), I don't get my original error, but I do still get the same undefined reference to '__atomic_store'
error as when I use --mattr=+cx16
on my x86-64 machine.