Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#15555 closed defect (fixed)

if CFLAGS contains -O 32-bit builds misdetect gcc atomics

Reported by: saurik Owned by:
Priority: normal Milestone:
Component: build Version: stable-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: yes

Description

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);

Attachments (1)

wxWidgets-atomic-i386-Os.diff download (1.0 KB) - added by saurik 10 months ago.

Download all attachments as: .zip

Change History (4)

Changed 10 months ago by saurik

comment:1 Changed 10 months ago by vadz

Very strange, I don't totally understand what's going on here neither. But I'll apply your fix, it doesn't seem like it could break anything (am I going to regret saying this?) and if it fixes the issue, all the better.

Thanks for debugging and finding solution for this problem!

comment:2 Changed 10 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [74934]) Work around g++ atomic builtins detection in configure when -Os is used.

Assigning sync_sub_and_fetch() result to an unused variable can result in it
being optimized away and the function support is then not really tested for,
see #4542. So do make sure this variable is kept by making it volatile.

Closes #15555.

comment:3 Changed 10 months ago by paulclinger

I ran into the same issue recently. One of the recommended solutions was to use "-march pentium" in CFLAGS (or something similar, like i686), but I couldn't make it to work because of a what looked like (another) GCC issue (25672).

I've tried various versions of gcc (4.7, 4.8), but the only one that compiled my wxwidgets project without this issue was the latest gcc-tdm (4.8.x). Nice to see it fixed.

Note: See TracTickets for help on using tickets.