Ticket #15555 (closed defect: fixed)
if CFLAGS contains -O 32-bit builds misdetect gcc atomics
|Reported by:||saurik||Owned by:|
Back in 2007 there was a bug #4542, wherein it was determined that gcc's sync_sub_and_fetch builtin is only "half" available: if you use the return value, gcc cannot implement it, but if you just need the side effect it will still compile. As configure did not use the return value but the code did, this feature would be detected and then would fail while linking. However, if you pass -Os as part of CFLAGS, gcc 4.8.1 seems to realize "oh, you while you got the return value for this function, you store it in a variable I've helpfully optimized away" and then the issue resurfaces. (Note: this is a regression since 2.9.4 for some reason I don't quite understand.)
A sufficient fix for this issue seems to be to modify the configure check to store the value into a volatile variable.
volatile unsigned int r2 = sync_sub_and_fetch(&value, 1);