At the same time, I checked clang for riscv (64-bit) without patch — it works,
e.g.:
unsigned /**/ short
AO_char_fetch_and_add( volatile unsigned /**/ short *addr, unsigned /**/
short incr)
{
return __atomic_fetch_add(addr, incr, __ATOMIC_RELEASE);
}
->
AO_char_fetch_and_add(unsigned short volatile*, unsigned short):
addi sp , sp , - 32
sd ra , 24 ( sp )
sd s0 , 16 ( sp )
addi s0 , sp , 32
add a2 , zero , a1
sd a0 , - 24 ( s0 )
sh a1 , - 26 ( s0 )
ld a0 , - 24 ( s0 )
lh a1 , - 26 ( s0 )
sh a1 , - 28 ( s0 )
lhu a1 , - 28 ( s0 )
andi a3 , a0 , - 4
andi a0 , a0 , 3
slli a0 , a0 , 3
lui a4 , 16
addiw a4 , a4 , - 1
sllw a4 , a4 , a0
sllw a1 , a1 , a0
.LBB0_1:
lr.w a5 , ( a3 )
add a6 , a5 , a1
xor a6 , a5 , a6
and a6 , a6 , a4
xor a6 , a5 , a6
sc.w.rl a6 , a6 , ( a3 )
bnez a6 , .LBB0_1
srlw a0 , a5 , a0
sh a0 , - 30 ( s0 )
lhu a0 , - 30 ( s0 )
ld s0 , 16 ( sp )
ld ra , 24 ( sp )
addi sp , sp , 32
ret
So, probably the root cause of this linker issue is that -latomic should be
passed, and my assumption was wrong that pthread-based implementation.