Bug 40144

Summary: checking for __sync_bool_compare_and_swap... no
Product: [Mono] Runtime Reporter: malat
Component: JITAssignee: Alex Rønne Petersen <alexrp>
Status: RESOLVED FIXED    
Severity: normal CC: masafa, mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description malat 2016-04-06 09:29:34 UTC
Using clang-3.8 on debian/sid I see the following in mono configuration:

checking for __sync_bool_compare_and_swap... no

Inspecting the config.log I see:

configure:5200: checking for __sync_bool_compare_and_swap
configure:5219: clang-3.8 -c  -Wno-deprecated-declarations -g -DGC_LINUX_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP -DUSE_MUNMAP -g -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes -Qunused-arguments -Wno-unused-function -Wno-tautological-compare -Wno-parentheses-equality -Wno-self-assign -Wno-return-stack-address -Wno-constant-logical-operand -D_FILE_OFFSET_BITS=64 -D__mono_ppc__ -DUSE_COMPILER_TLS conftest.c >&5
conftest.c:19:33: error: function definition is not allowed here
int main(int argc, char** argv) {
                                ^
1 error generated.
configure:5219: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libgc-mono"
| #define PACKAGE_TARNAME "libgc-mono"
| #define PACKAGE_VERSION "6.6"
| #define PACKAGE_STRING "libgc-mono 6.6"
| #define PACKAGE_BUGREPORT "Hans_Boehm@hp.com"
| #define PACKAGE_URL ""
| #define GC_LINUX_THREADS 1
| #define _REENTRANT 1
| #define PARALLEL_MARK 1
| #define THREAD_LOCAL_ALLOC 1
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
| volatile unsigned int foo = 0;
| int main(int argc, char** argv) {
|     unsigned int r1 = __sync_bool_compare_and_swap(&foo, 0, 1);
|     return 0;
| }
|
|   ;
|   return 0;
| }
configure:5228: result: no


I suspect something is not quite right here since clang-3.8 does support `__sync_bool_compare_and_swap`
Comment 1 Alex Rønne Petersen 2016-04-06 17:16:06 UTC
I think the problem is that we should not be defining main in the call to AC_TRY_COMPILE. Could you try changing it to

> # Check if the GCC builtin __sync_bool_compare_and_swap is available.
> # It is preferred in gc_locks.h for PPC as GCC 4.4 has a problem with the inline assembly there.
> AC_MSG_CHECKING(for __sync_bool_compare_and_swap)
> AC_TRY_COMPILE([],[
> volatile unsigned int foo = 0;
> unsigned int r1 = __sync_bool_compare_and_swap(&foo, 0, 1);
> return 0;
> ], [
> AC_MSG_RESULT(yes)
> AC_DEFINE(HAS___SYNC_BOOL_COMPARE_AND_SWAP)
> ], [
> AC_MSG_RESULT(no)
> ])

and see if that works? (It's in libgc/configure.ac, btw.)
Comment 2 malat 2016-04-07 06:09:12 UTC
Yes that works:

$ export CC=clang-3.8
$ ./autogen.sh --prefix=$HOME/blah    
[...]
checking for __sync_bool_compare_and_swap... yes


Patch is:

% git diff libgc/configure.ac
diff --git a/libgc/configure.ac b/libgc/configure.ac
index ac992ab..7f5aa03 100644
--- a/libgc/configure.ac
+++ b/libgc/configure.ac
@@ -233,10 +233,8 @@ AM_CONDITIONAL(POWERPC_DARWIN,test x$powerpc_darwin = xtrue)
 AC_MSG_CHECKING(for __sync_bool_compare_and_swap)
 AC_TRY_COMPILE([],[
 volatile unsigned int foo = 0;
-int main(int argc, char** argv) {
-    unsigned int r1 = __sync_bool_compare_and_swap(&foo, 0, 1);
-    return 0;
-}
+unsigned int r1 = __sync_bool_compare_and_swap(&foo, 0, 1);
+return 0;
 ], [
 AC_MSG_RESULT(yes)
 AC_DEFINE(HAS___SYNC_BOOL_COMPARE_AND_SWAP)
Comment 3 Alex Rønne Petersen 2016-04-07 06:43:38 UTC
Thanks!

Posted the fix as a pull request, will be merged once green: https://github.com/mono/mono/pull/2848
Comment 4 Alex Rønne Petersen 2016-04-07 17:39:27 UTC
PR merged, marking as fixed.