GNOME Bugzilla – Bug 651959
gbitlock: "asm goto" is not available in gcc < 4.5
Last modified: 2011-06-09 02:48:24 UTC
Building glib 2.29.6 for -arch i386 on Mac OS X 10.6.7 with Xcode 3.2.6 fails with: Making all in . CC garray.lo CC gasyncqueue.lo CC gatomic.lo CC gbacktrace.lo CC gbase64.lo CC gbitlock.lo gbitlock.c: In function 'g_bit_lock': gbitlock.c:211: error: expected '(' before 'goto' gbitlock.c:211: error: expected identifier or '*' before '(' token gbitlock.c:219: warning: label 'contended' defined but not used gbitlock.c: In function 'g_pointer_bit_lock': gbitlock.c:398: error: expected '(' before 'goto' gbitlock.c:398: error: expected identifier or '*' before '(' token gbitlock.c:406: warning: label 'contended' defined but not used make[4]: *** [gbitlock.lo] Error 1 make[3]: *** [all-recursive] Error 1 make[2]: *** [all] Error 2 make[1]: *** [all-recursive] Error 1 make: *** [all] Error 2
It happens with -arch x86_64 too. glib2 2.29.4 and 2.28.7 build fine on the same system.
What compiler is being used here? Can we get "make V=1" output as well as gcc --version (if GCC)?
Sounds like Xcode claims to be gcc but is not quite up to it after all... The code in question is: #if defined (__GNUC__) && (defined (i386) || defined (__amd64__)) retry: asm volatile goto ("lock bts %1, (%0)\n" "jc %l[contended]" : /* no output */ : "r" (address), "r" (lock_bit) : "cc", "memory" : contended); return; contended: ...
I should have been clearer: I'm using a standard command-line configure and make build process (using MacPorts; I am the MacPorts maintainer for the glib2 ports), using the version of gcc provided by Xcode 3.2.6, which is Apple gcc 4.2.1: $ gcc --version i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. I'll attach the verbose build output for you shortly.
Created attachment 189370 [details] log with V=1
asm goto is new in gcc 4.5: "An asm goto feature has been added to allow asm statements that jump to C labels." (from http://gcc.gnu.org/gcc-4.5/changes.html ) I assume the volatile has no incidence here. See also http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Extended-Asm.html#Extended-asm-with-goto
Created attachment 189452 [details] [review] proposed patch Here is one way of fixing this bug, though I haven't tested it yet on an older gcc, hopefully I'll have time for that in the next hours.
I can confirm this fixes compilation for me on osx, but then my test app crashes, I'm not sure yet if this is caused by the bitlocks or something else (reverting to the commit right before the use of asm goto in bitlocks gives me a non-crashing app)
I'm also seeing regressions in the tests/refcount testsuite, going from one failure to 3, not sure if this is related to this patch or not.
Hmm, it seems to randomly fail actually, running the test suite several times in a row results in a different number of failures, unrelated to this bug anyway :)
Comment on attachment 189452 [details] [review] proposed patch This patch looks quite fine. After your testing, please commit it. Thanks for the catch.
Thanks, it builds for me, and I've committed it to MacPorts: https://trac.macports.org/changeset/79309
The following fix has been pushed: 602f8ba bitlock: don't use asm goto on older gcc
Created attachment 189518 [details] [review] bitlock: don't use asm goto on older gcc asm goto was addded in gcc 4.5 so don't try to use it on gcc versions older than this one. This is achieved by explicitly checking gcc version, an alternative would be to try to compile a program using asm volatile in configure.