Bug 40144 - checking for __sync_bool_compare_and_swap... no
Summary: checking for __sync_bool_compare_and_swap... no
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Alex Rønne Petersen
URL:
Depends on:
Blocks:
 
Reported: 2016-04-06 09:29 UTC by malat
Modified: 2016-04-07 17:39 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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.