Re: arm-linux-gnueabihf-ld: kernel/rcu/update.o:update.c:(.text+0x1cc4): more undefined references to `__bad_cmpxchg' follow

From: Arnd Bergmann
Date: Thu May 30 2024 - 09:29:04 EST


On Thu, May 30, 2024, at 14:26, Russell King (Oracle) wrote:
> On Thu, May 30, 2024 at 05:50:52PM +0530, Naresh Kamboju wrote:
>> The arm builds failed on Linux next with gcc-13 and clang-18.
>>
>> Config: arm imx_v6_v7_defconfig - failed
>>
>> Reported-by: Linux Kernel Functional Testing <lkft@xxxxxxxxxx>
>>
>> Build log:
>> -----
>> arm-linux-gnueabihf-ld: kernel/rcu/update.o: in function
>> `rcu_trc_cmpxchg_need_qs':
>> update.c:(.text+0x348): undefined reference to `__bad_cmpxchg'
>> arm-linux-gnueabihf-ld: kernel/rcu/update.o: in function
>> `rcu_read_unlock_trace_special':
>> update.c:(.text+0x41c): undefined reference to `__bad_cmpxchg'
>> arm-linux-gnueabihf-ld: kernel/rcu/update.o: in function
>> `trc_read_check_handler':
>> update.c:(.text+0x4b0): undefined reference to `__bad_cmpxchg'
>> arm-linux-gnueabihf-ld: kernel/rcu/update.o: in function `trc_inspect_reader':
>> update.c:(.text+0x1518): undefined reference to `__bad_cmpxchg'
>> arm-linux-gnueabihf-ld: update.c:(.text+0x1548): undefined reference
>> to `__bad_cmpxchg'
>> arm-linux-gnueabihf-ld: kernel/rcu/update.o:update.c:(.text+0x1cc4):
>> more undefined references to `__bad_cmpxchg' follow
>> make[3]: *** [/builds/linux/scripts/Makefile.vmlinux:34: vmlinux] Error 1
>
> You get a reference to __bad_cmpxchg() when someone uses cmpxchg() on
> a datatype that there are no CPU instructions to perform the atomic
> compare-and-exchange.
>
> As we support 8-bit, 16-bit and 32-bit, I would expect that we're now
> seeing cmpxchg() being used on 64-bit values, which are unsupportable
> on 32-bit Arm.

A 64-bit cmpxchg() would fail on most 32-bit architectures,
other than armv6k+ and i686+. Since this one fails on
an armv6 (non-6k) build, it's probably the added 8-bit
cmpxchg() that Paul talked about using for RCU, though I
don't see that in linux-next here.

I htink we need to use the emulated cmpxchg8() in
__cmpxchg() for this case, just like we do on other
architectures that only have word size atomics.

Arnd