public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/65697] New: __atomic memory barriers not strong enough for __sync builtins
@ 2015-04-08 11:25 matthew.wahab at arm dot com
  2015-04-08 11:33 ` [Bug target/65697] " matthew.wahab at arm dot com
                   ` (68 more replies)
  0 siblings, 69 replies; 70+ messages in thread
From: matthew.wahab at arm dot com @ 2015-04-08 11:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65697

            Bug ID: 65697
           Summary: __atomic memory barriers not strong enough for __sync
                    builtins
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matthew.wahab at arm dot com

The __sync builtins are implemented by expanding them to the equivalent
__atomic builtins, using MEMMODEL_SEQ_CST for those that are full barriers.
This is too weak since __atomic operations with MEMMODEL_SEQ_CST still allow
some data references to move across the operation (see
https://gcc.gnu.org/ml/gcc/2014-02/msg00058.html) while a __sync full barrier
should block all movement
(https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html#_005f_005fsync-Builtins).

This is problem for Aarch64 where data references after the barrier could be
speculated ahead of it.

For example, compiling with aarch64-none-linux-gnu at -O2,
-----
int foo = 0;
int bar = 0;

int T1(void)
{
  int x = __sync_fetch_and_add(&foo, 1);
  return bar;
}
----
produces
----
T1:
    adrp    x0, .LANCHOR0
    add    x0, x0, :lo12:.LANCHOR0
.L2:
    ldaxr    w1, [x0]       ; load-acquire (__sync_fetch_and_add)
    add    w1, w1, 1
    stlxr    w2, w1, [x0]   ; store-release  (__sync_fetch_and_add)
    cbnz    w2, .L2
    ldr    w0, [x0, 4]    ; load (return bar)
    ret
----
With this code, the load can be executed ahead of the store-release which ends
the __sync_fetch_and_add. A correct implementation should emit a dmb
instruction after the cbnz.

GCC info:
gcc version 5.0.0 20150407 (experimental) 
Target: aarch64-none-linux-gnu


^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~2015-10-05  8:30 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-08 11:25 [Bug target/65697] New: __atomic memory barriers not strong enough for __sync builtins matthew.wahab at arm dot com
2015-04-08 11:33 ` [Bug target/65697] " matthew.wahab at arm dot com
2015-04-08 16:16 ` jakub at gcc dot gnu.org
2015-04-09  9:53 ` matthew.wahab at arm dot com
2015-04-09 10:08 ` torvald at gcc dot gnu.org
2015-04-09 10:11 ` torvald at gcc dot gnu.org
2015-04-09 10:47 ` matthew.wahab at arm dot com
2015-04-09 11:10 ` redi at gcc dot gnu.org
2015-04-09 11:25 ` matthew.wahab at arm dot com
2015-04-09 11:51 ` amacleod at redhat dot com
2015-04-09 14:03 ` matthew.wahab at arm dot com
2015-04-10 15:09 ` jgreenhalgh at gcc dot gnu.org
2015-04-15 10:16 ` aph at gcc dot gnu.org
2015-04-15 11:11 ` mwahab at gcc dot gnu.org
2015-04-15 11:54 ` jakub at gcc dot gnu.org
2015-04-15 12:43 ` aph at gcc dot gnu.org
2015-04-15 13:01 ` mwahab at gcc dot gnu.org
2015-04-15 14:10 ` aph at gcc dot gnu.org
2015-04-15 14:33 ` mwahab at gcc dot gnu.org
2015-04-15 14:49 ` aph at gcc dot gnu.org
2015-04-15 15:49 ` torvald at gcc dot gnu.org
2015-04-15 20:05 ` torvald at gcc dot gnu.org
2015-04-15 20:49 ` jgreenhalgh at gcc dot gnu.org
2015-04-15 22:13 ` torvald at gcc dot gnu.org
2015-04-16  3:45 ` amacleod at redhat dot com
2015-04-16  8:11 ` mwahab at gcc dot gnu.org
2015-04-16  8:50 ` mwahab at gcc dot gnu.org
2015-04-16  9:01 ` jgreenhalgh at gcc dot gnu.org
2015-04-16  9:18 ` mwahab at gcc dot gnu.org
2015-04-16 11:37 ` amacleod at redhat dot com
2015-04-16 11:54 ` torvald at gcc dot gnu.org
2015-04-16 12:13 ` mwahab at gcc dot gnu.org
2015-04-16 13:27 ` jgreenhalgh at gcc dot gnu.org
2015-04-17 15:38 ` torvald at gcc dot gnu.org
2015-04-17 15:48 ` torvald at gcc dot gnu.org
2015-04-17 18:00 ` amacleod at redhat dot com
2015-04-20 13:42 ` mwahab at gcc dot gnu.org
2015-04-20 15:17 ` mwahab at gcc dot gnu.org
2015-04-21 18:51 ` rth at gcc dot gnu.org
2015-04-28 15:32 ` jgreenhalgh at gcc dot gnu.org
2015-04-29  8:47 ` mwahab at gcc dot gnu.org
2015-04-29 12:20 ` jgreenhalgh at gcc dot gnu.org
2015-04-29 13:26 ` mwahab at gcc dot gnu.org
2015-04-29 16:04 ` amacleod at redhat dot com
2015-04-30  8:20 ` mwahab at gcc dot gnu.org
2015-05-01 12:53 ` torvald at gcc dot gnu.org
2015-05-06 14:25 ` amacleod at redhat dot com
2015-05-06 15:58 ` mwahab at gcc dot gnu.org
2015-05-07 13:25 ` mwahab at gcc dot gnu.org
2015-05-08  8:01 ` mwahab at gcc dot gnu.org
2015-05-11 13:44 ` jgreenhalgh at gcc dot gnu.org
2015-05-11 15:58 ` mwahab at gcc dot gnu.org
2015-05-12 20:02 ` amacleod at redhat dot com
2015-06-01 15:19 ` mwahab at gcc dot gnu.org
2015-06-01 15:21 ` mwahab at gcc dot gnu.org
2015-06-01 15:25 ` mwahab at gcc dot gnu.org
2015-06-11  7:35 ` ramana at gcc dot gnu.org
2015-06-29 16:04 ` mwahab at gcc dot gnu.org
2015-06-29 16:09 ` mwahab at gcc dot gnu.org
2015-06-29 16:12 ` mwahab at gcc dot gnu.org
2015-08-05 11:21 ` mwahab at gcc dot gnu.org
2015-08-05 11:30 ` mwahab at gcc dot gnu.org
2015-08-05 11:41 ` mwahab at gcc dot gnu.org
2015-08-05 11:49 ` mwahab at gcc dot gnu.org
2015-08-05 13:28 ` mwahab at gcc dot gnu.org
2015-08-05 13:40 ` mwahab at gcc dot gnu.org
2015-08-05 13:43 ` mwahab at gcc dot gnu.org
2015-09-30  3:07 ` ramana at gcc dot gnu.org
2015-10-05  8:08 ` mwahab at gcc dot gnu.org
2015-10-05  8:30 ` ramana at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).