Re: Bug#1052144: ghc: Needs to link against libatomic on at least m68k

John Paul Adrian Glaubitz <[email protected]>
Newsgroups gmane.linux.debian.ports.68k
Message-ID <4d9ab811d97e049492b33c1446b9174e49125052.camel@physik.fu-berlin.de>
Control: tags -1 +patch

Hi!

The attached patch fixes the issue for me. The underlying problem is
the use of legacy atomic functions for which no 64-bit variants exist
on some architectures [1]. See also the upstream discussion here [2].

While this patch fixes the original problem, the stage2 build later
fails due to memory exhaustion for which I haven't found a solution
yet.

Thanks,
Adrian

> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63368
> [2] https://gitlab.haskell.org/ghc/ghc/-/issues/23974

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
use-modern-atomics.patch (text/x-patch, 1.7 KB)
Index: ghc-9.4.6/libraries/ghc-prim/cbits/atomic.c
===================================================================
--- ghc-9.4.6.orig/libraries/ghc-prim/cbits/atomic.c
+++ ghc-9.4.6/libraries/ghc-prim/cbits/atomic.c
@@ -291,28 +291,28 @@ extern StgWord hs_cmpxchg8(StgWord x, St
 StgWord
 hs_cmpxchg8(StgWord x, StgWord old, StgWord new)
 {
-  return __sync_val_compare_and_swap((volatile StgWord8 *) x, (StgWord8) old, (StgWord8) new);
+  return __atomic_compare_exchange((volatile StgWord8 *) x, (StgWord8 *) &old, (StgWord8 *) &new, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
 }
 
 extern StgWord hs_cmpxchg16(StgWord x, StgWord old, StgWord new);
 StgWord
 hs_cmpxchg16(StgWord x, StgWord old, StgWord new)
 {
-  return __sync_val_compare_and_swap((volatile StgWord16 *) x, (StgWord16) old, (StgWord16) new);
+  return __atomic_compare_exchange((volatile StgWord16 *) x, (StgWord16 *) &old, (StgWord16 *) &new, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
 }
 
 extern StgWord hs_cmpxchg32(StgWord x, StgWord old, StgWord new);
 StgWord
 hs_cmpxchg32(StgWord x, StgWord old, StgWord new)
 {
-  return __sync_val_compare_and_swap((volatile StgWord32 *) x, (StgWord32) old, (StgWord32) new);
+  return __atomic_compare_exchange((volatile StgWord32 *) x, (StgWord32 *) &old, (StgWord32 *) &new, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
 }
 
 extern StgWord hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new);
 StgWord
 hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new)
 {
-  return __sync_val_compare_and_swap((volatile StgWord64 *) x, old, new);
+  return __atomic_compare_exchange((volatile StgWord64 *) x, (StgWord64 *) &old, (StgWord64 *) &new, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
 }
 
 // Atomic exchange operations
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.