https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59708 Manuel López-Ibáñez changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |noloader at gmail dot com --- Comment #10 from Manuel López-Ibáñez --- *** Bug 49467 has been marked as a duplicate of this bug. *** >From gcc-bugs-return-459167-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Aug 24 18:40:06 2014 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 7322 invoked by alias); 24 Aug 2014 18:40:06 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 7236 invoked by uid 48); 24 Aug 2014 18:39:59 -0000 From: "manu at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/49467] Enhancement: Intrinsic to read CARRY and OVERFLOW flags (where applicable) Date: Sun, 24 Aug 2014 18:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: manu at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01664.txt.bz2 Content-length: 481 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49467 Manuel López-Ibáñez changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |manu at gcc dot gnu.org --- Comment #3 from Manuel López-Ibáñez --- *** This bug has been marked as a duplicate of bug 59708 *** >From gcc-bugs-return-459168-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Aug 24 18:46:15 2014 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 9987 invoked by alias); 24 Aug 2014 18:46:15 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 9951 invoked by uid 48); 24 Aug 2014 18:46:05 -0000 From: "mikulas at artax dot karlin.mff.cuni.cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/62253] New: gcc incorrectly mixes direct atomic instructions with calls to atomic library Date: Sun, 24 Aug 2014 18:46:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mikulas at artax dot karlin.mff.cuni.cz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cf_gcchost cf_gcctarget cf_gccbuild attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01665.txt.bz2 Content-length: 2111 https://gcc.gnu.org/bugzilla/show_bug.cgi?idb253 Bug ID: 62253 Summary: gcc incorrectly mixes direct atomic instructions with calls to atomic library Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: mikulas at artax dot karlin.mff.cuni.cz Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu Build: x86_64-unknown-linux-gnu Created attachment 33390 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id3390&actioníit a test case for broken atomicity on 386. Compile with -O3 -m32 -march=i386 The 386 processor lacks some atomic instructions, thus they must be emulated using calls to a library. The library is supposed to take a lock (possibly hashed by the address or the atomic variable), perform the operation non-atomically, and drop the lock. However, for some atomic operations, gcc still generates atomic instructions, even on 386 (lock add, lock sub, lock or, lock and, lock xor, lock inc, lock dec, xchg). The problem is that when these instructions race with the library implementation, they break atomicity. For example, to emulate cmpxchg, the library takes the lock, reads the value, compares the value, writes the new value, drops the lock. If this sequence races with directly generated "lock add" instruction, atomicity is broken, because the lock add instruction can be executed between the read and write in the cmpxchg library implementation. To maintain atomicity, gcc must for each data type either always use atomic instructions or always use calls to the library. It must not mix atomic instructions and library calls. To see the bug, compile the attached file with -O3 -m32 -march=i386 . You see that functions test1, test3, test5 generate direct atomic instructions and functions test2 and test4 generate calls to the library. When these functions race with each other, atomicity is not guaranteed.