After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 752731 - glib gthread-posix compilation issues on arches with limited atomic support
glib gthread-posix compilation issues on arches with limited atomic support
Product: glib
Classification: Platform
Component: gthread
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
Depends on:
Reported: 2015-07-22 15:19 UTC by Brendan Heading
Modified: 2018-05-24 17:58 UTC
See Also:
GNOME target: ---
GNOME version: ---

detect if compiler indicates hw atomic compare & swap support (938 bytes, patch)
2015-07-22 15:23 UTC, Brendan Heading
none Details | Review

Description Brendan Heading 2015-07-22 15:19:51 UTC
Hi guys,

gthread-posix.c contains the following check to determine whether or not native mutex support can be enabled : 

/* clang defines __ATOMIC_SEQ_CST but doesn't support the GCC extension */
#if defined(HAVE_FUTEX) && defined(__ATOMIC_SEQ_CST) && !defined(__clang__)

However, some architectures - specifically sparc v8, but possibly others - define __ATOMIC_SEQ_CST even though they do not support the full set of atomic instructions. This leads to the following compilation error. 

  CC       gspawn.lo
  CC       gtester.o
  GEN      glib-public-headers.txt
  CCLD     gtester
./.libs/ undefined reference to `__atomic_compare_exchange_4'
collect2: error: ld returned 1 exit status
Makefile:1439: recipe for target 'gtester' failed
make[6]: *** [gtester] Error 1
Makefile:2455: recipe for target 'all-recursive' failed
make[5]: *** [all-recursive] Error 1
Makefile:1168: recipe for target 'all' failed
make[4]: *** [all] Error 2
Makefile:1207: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
Makefile:849: recipe for target 'all' failed
make[2]: *** [all] Error 2


The choices are to either allow the compiler to use libatomic to substitute the missing instructions; or to allow the application to determine what to do at compile time. 

My guess is the best fix is for glib to detect this and disable USE_NATIVE_MUTEX. I propose that an additional check be added for __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, since we seem to need __atomic_compare_exchange_4(). With this patch applied, libglib2 compiles successfully.
Comment 1 Emmanuele Bassi (:ebassi) 2015-07-22 15:22:58 UTC
Did you mean to attach a patch?
Comment 2 Brendan Heading 2015-07-22 15:23:52 UTC
Created attachment 307916 [details] [review]
detect if compiler indicates hw atomic compare & swap support

Add an additional check before enabling USE_NATIVE_MUTEX - confirm that the __atomic_compare_exchange_4 function is supplied by the compiler.
Comment 3 Brendan Heading 2015-07-22 15:24:27 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #1)
> Did you mean to attach a patch?

Sorry Emmanuele - patch now added.
Comment 4 GNOME Infrastructure Team 2018-05-24 17:58:10 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: