GNOME Bugzilla – Bug 752731
glib gthread-posix compilation issues on arches with limited atomic support
Last modified: 2018-05-24 17:58:10 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__) #define USE_NATIVE_MUTEX #endif =================== 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 libglib-2.0.la CCLD gtester ./.libs/libglib-2.0.so: 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.
Did you mean to attach a patch?
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.
(In reply to Emmanuele Bassi (:ebassi) from comment #1) > Did you mean to attach a patch? Sorry Emmanuele - patch now added.
-- 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: https://gitlab.gnome.org/GNOME/glib/issues/1063.