[armel] Atomic intrinsics are not implemented correctly

Bug #491872 reported by Dave Martin
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Fix Released
High
gcc-4.4 (Ubuntu)
Fix Released
High
Unassigned
glib2.0 (Ubuntu)
Fix Released
High
Unassigned

Bug Description

Binary package hint: gcc-4.4

Observed in gcc 4.4.2-3ubuntu1
Believed to affect all versions

__sync_synchronnize() should perform a memory barrier, but is a noop (at least with -O2)
__sync_lock_release() should place a memory barrier before the compare-exchange operation, but actually puts the barrier after, which may cause unsafe spinlock release

Implications: packages built with unfixed gcc which use these intrinsics may not be multicore-safe on armel.

Upstream bug link and further information to follow shortly, when available.

Tags: armel armv7
Revision history for this message
Alexander Sack (asac) wrote :

 milestoning glib part for alpha-3 so this comes back and we remember to verify that a respin has happened after gcc is fixed.

Changed in glib2.0 (Ubuntu):
importance: Undecided → High
milestone: none → lucid-alpha-3
status: New → Triaged
Revision history for this message
Alexander Sack (asac) wrote :

confirming gcc issue. and tentatively putting on alpha-3 milestone. Not sure how to proceed. If its not known upstream we should probably file a bug there etc. Leaving to doko to drive this bug.

Changed in gcc-4.4 (Ubuntu):
importance: Undecided → High
milestone: none → lucid-alpha-3
status: New → Confirmed
Revision history for this message
Dave Martin (dave-martin-arm) wrote :

I expect to be able to post a patch soon; it may be simplest to leave this unfixed until then.

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

This patch should fix the issue with __sync_lock_release(): http://gcc.gnu.org/ml/gcc-patches/2009-12/msg00198.html

The __sync_synchronize() is not fixed by this— another patch should follow soon.

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

This patch should fix the __sync_synchronize() issue, by making sure GCC does not optimise away the call to the libgcc function which implements this:
http://gcc.gnu.org/ml/gcc-patches/2009-08/msg00600.html

These should now be fixed on the GCC trunk and await backporting to the upstream 4.4 branch.

I've referenced the relevant GCC bugzilla entry from this bug.

Changed in gcc:
status: Unknown → In Progress
Matthias Klose (doko)
Changed in gcc-4.4 (Ubuntu):
status: Confirmed → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package gcc-4.4 - 4.4.2-3ubuntu2

---------------
gcc-4.4 (4.4.2-3ubuntu2) lucid; urgency=low

  * Update to SVN 20091203 from the gcc-4_4-branch (r154951), Fixes:
    PR middle-end/42049, PR c++/42234, PR fortran/41278.
  * PR target/42263, fix wrong code bugs in SMP support on ARM, backport from
    the trunk. LP: #491872 .
  * Pass -mimplicit-it=thumb to as by default on ARM. LP: #488302.
 -- Matthias Klose <email address hidden> Fri, 04 Dec 2009 10:06:17 +0100

Changed in gcc-4.4 (Ubuntu):
status: In Progress → Fix Released
Changed in gcc-4.4 (Ubuntu):
status: Fix Released → Confirmed
Revision history for this message
Dave Martin (dave-martin-arm) wrote :

Unfortunately, the __sync_synchronize() bug appears still to be present in the updated GCC.
A call to this intrinsic still disappears in the compiler's output.

The __sync_lock_test_and_set() bug may still be present; however it is also possible that the __sync_synchronize() bug is masking the fix.

$ apt-cache policy gcc-4.4 cpp-4.4
gcc-4.4:
  Installed: 4.4.2-3ubuntu2
  Candidate: 4.4.2-3ubuntu2
  Version table:
 *** 4.4.2-3ubuntu2 0
        500 http://arm-ports-ubuntu lucid/main Packages
        100 /var/lib/dpkg/status
cpp-4.4:
  Installed: 4.4.2-3ubuntu2
  Candidate: 4.4.2-3ubuntu2
  Version table:
 *** 4.4.2-3ubuntu2 0
        500 http://arm-ports-ubuntu lucid/main Packages
        100 /var/lib/dpkg/status

$ echo 'void f(void) { __sync_synchronize(); }' | gcc -S -o- -xc -
 .syntax unified
 .arch armv7-a
 .eabi_attribute 27, 3
 .fpu vfpv3-d16
 .eabi_attribute 20, 1
 .eabi_attribute 21, 1
 .eabi_attribute 23, 3
 .eabi_attribute 24, 1
 .eabi_attribute 25, 1
 .eabi_attribute 26, 2
 .eabi_attribute 30, 6
 .eabi_attribute 18, 4
 .thumb
 .file ""
 .text
 .align 2
 .global f
 .thumb
 .thumb_func
 .type f, %function
f:
 @ args = 0, pretend = 0, frame = 0
 @ frame_needed = 1, uses_anonymous_args = 0
 @ link register save eliminated.
 push {r7}
 add r7, sp, #0
 mov sp, r7
 pop {r7}
 bx lr
 .size f, .-f
 .ident "GCC: (Ubuntu 4.4.2-3ubuntu2) 4.4.2"
 .section .note.GNU-stack,"",%progbits

__sync_lock_test_and_set_* still don't contain a barrier in the right place, though this may be due to the above bug.

00008e04 <__sync_lock_test_and_set_4>:
    8e04: e92d 41f0 stmdb sp!, {r4, r5, r6, r7, r8, lr}
    8e08: f640 76c0 movw r6, #4032 ; 0xfc0
    8e0c: 4605 mov r5, r0
    8e0e: 460f mov r7, r1
    8e10: f6cf 76ff movt r6, #65535 ; 0xffff
    8e14: 682c ldr r4, [r5, #0]
    8e16: 4639 mov r1, r7
    8e18: 462a mov r2, r5
    8e1a: 4620 mov r0, r4
    8e1c: 47b0 blx r6
    8e1e: 2800 cmp r0, #0
    8e20: d1f8 bne.n 8e14 <__sync_lock_test_and_set_4+0x10>
    8e22: 4620 mov r0, r4
    8e24: e8bd 81f0 ldmia.w sp!, {r4, r5, r6, r7, r8, pc}

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

-mimplicit-it=thumb does now seem to be passed correctly to the assembler, though:

$ echo 'void f(void) { asm volatile("moveq r0, #1"); }' | gcc -c -o tmp.o -xc - && objdump -d tmp.o

00000000 <f>:
...
   4: bf08 it eq
   6: 2001 moveq r0, #1

Revision history for this message
Matthias Klose (doko) wrote :

according to https://launchpad.net/ubuntu/+source/gcc-4.4/4.4.2-3ubuntu2/+build/1378632

the patch (attached here is well) is applied. I'll update it to include the testcase, which I missed in the backport.

Revision history for this message
Matthias Klose (doko) wrote :

confirmed, the testcase in the GCC testsuite still fails

Changed in gcc:
status: In Progress → Fix Released
Revision history for this message
Matthias Klose (doko) wrote :

fixed in 4.4.2-5ubuntu1

Changed in gcc-4.4 (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package glib2.0 - 2.23.0-1ubuntu3

---------------
glib2.0 (2.23.0-1ubuntu3) lucid; urgency=low

  * Rebuild with gcc 4.4.2-5ubuntu1. LP: #491872.
 -- Matthias Klose <email address hidden> Mon, 14 Dec 2009 15:57:11 +0000

Changed in glib2.0 (Ubuntu):
status: Triaged → Fix Released
Revision history for this message
Dave Martin (dave-martin-arm) wrote :

FIx confirmed in fixed in 4.4.2-5ubuntu1

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

Thanks!

Changed in gcc:
importance: Unknown → High
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.