As discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122078 GCC defines the __atomic_test_and_set builtin in gcc/sync-builtins.def On architectures without atomic operations this builtin gets implemented as a call to a function with the same name. Libatomic does not provide a symbol named __atomic_test_and_set resulting in an "undefined reference to `__atomic_test_and_set'" link-time error.
This bug affects different targets such as m68k-rtems and microblaze who filed separate bug reports https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118977 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118280 It also affects armv6-m (cortex-m0), as we discovered testing our target, arm-miosix-eabi which is for the Miosix RTOS for which we maintain patches outside of the GCC repository. This patch modifies libatomic to provide the __atomic_test_and_setsymbol as an alias to __atomic_test_and_set_1, a compatible symbol already present in libatomic.
We tested against our target (arm-miosix-eabi). The patch was also tested on rtems for both ARM and m68k:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118977#c9 PS: This is the first patch I propose to GCC, comments welcome. Best regards, Federico
From 4d715a78eed8a51dd363e0daafefb6a00170d03d Mon Sep 17 00:00:00 2001 From: Terraneo Federico <[email protected]> Date: Thu, 6 Nov 2025 18:36:03 +0100 Subject: [PATCH] libatomic: provide missing symbol __atomic_test_and_set [PR122078] --- libatomic/tas_n.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libatomic/tas_n.c b/libatomic/tas_n.c index 036a3d23307..2ee7fca07ca 100644 --- a/libatomic/tas_n.c +++ b/libatomic/tas_n.c @@ -115,3 +115,10 @@ SIZE(libat_test_and_set) (UTYPE *mptr, int smodel UNUSED) EXPORT_ALIAS (SIZE(test_and_set)); #undef LAT_TAS_N + +/* Provide __atomic_test_and_set, see + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122078 */ +#if N == 1 && !SIZE(HAVE_ATOMIC_TAS) +extern bool __atomic_test_and_set (void *mptr, int smodel) + __attribute__((alias("libat_test_and_set_1"))); +#endif -- 2.25.1
OpenPGP_signature.asc
Description: OpenPGP digital signature
