From: Uros Bizjak Date: Mon, 8 Sep 2025 12:38:22 +0000 (+0200) Subject: x86: Define atomic_exchange_acq using __atomic_exchange_n X-Git-Tag: glibc-2.43~555 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=935ee691bce7aa8c957714deea4868e5aefb52c9;p=thirdparty%2Fglibc.git x86: Define atomic_exchange_acq using __atomic_exchange_n The resulting libc.so is identical on both x86_64 and i386 targets compared to unpatched builds: $ sha1sum libc-x86_64-old.so libc-x86_64-new.so 74eca1b87f2ecc9757a984c089a582b7615d93e7 libc-x86_64-old.so 74eca1b87f2ecc9757a984c089a582b7615d93e7 libc-x86_64-new.so $ sha1sum libc-i386-old.so libc-i386-new.so 882bbab8324f79f4fbc85224c4c914fc6822ece7 libc-i386-old.so 882bbab8324f79f4fbc85224c4c914fc6822ece7 libc-i386-new.so Signed-off-by: Uros Bizjak Cc: Florian Weimer Cc: Adhemerval Zanella Netto Cc: Wilco Dijkstra Cc: Collin Funk Cc: H.J.Lu Cc: Carlos O'Donell Reviewed-by: Adhemerval Zanella --- diff --git a/sysdeps/x86/atomic-machine.h b/sysdeps/x86/atomic-machine.h index c0c2c3437a..ebe8e978e5 100644 --- a/sysdeps/x86/atomic-machine.h +++ b/sysdeps/x86/atomic-machine.h @@ -19,9 +19,6 @@ #ifndef _X86_ATOMIC_MACHINE_H #define _X86_ATOMIC_MACHINE_H 1 -#include -#include /* For cast_to_integer. */ - #define USE_ATOMIC_COMPILER_BUILTINS 1 #ifdef __x86_64__ @@ -41,32 +38,8 @@ #define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \ (! __sync_bool_compare_and_swap (mem, oldval, newval)) -/* Note that we need no lock prefix. */ #define atomic_exchange_acq(mem, newvalue) \ - ({ __typeof (*mem) result; \ - if (sizeof (*mem) == 1) \ - __asm __volatile ("xchgb %b0, %1" \ - : "=q" (result), "=m" (*mem) \ - : "0" (newvalue), "m" (*mem)); \ - else if (sizeof (*mem) == 2) \ - __asm __volatile ("xchgw %w0, %1" \ - : "=r" (result), "=m" (*mem) \ - : "0" (newvalue), "m" (*mem)); \ - else if (sizeof (*mem) == 4) \ - __asm __volatile ("xchgl %0, %1" \ - : "=r" (result), "=m" (*mem) \ - : "0" (newvalue), "m" (*mem)); \ - else if (__HAVE_64B_ATOMICS) \ - __asm __volatile ("xchgq %q0, %1" \ - : "=r" (result), "=m" (*mem) \ - : "0" ((int64_t) cast_to_integer (newvalue)), \ - "m" (*mem)); \ - else \ - { \ - result = 0; \ - __atomic_link_error (); \ - } \ - result; }) + __atomic_exchange_n (mem, newvalue, __ATOMIC_ACQUIRE) /* ??? Remove when catomic_exchange_and_add fallback uses __atomic_fetch_add. */