glib gthread-posix compilation issues on arches with limited atomic support
Submitted by Brendan Heading
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: *** [gtester] Error 1 Makefile:2455: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1 Makefile:1168: recipe for target 'all' failed make: *** [all] Error 2 Makefile:1207: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1 Makefile:849: recipe for target 'all' failed make: *** [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.