Opened 14 years ago

Closed 14 years ago

#2525 closed Bugs (fixed)

More architectures that do not support __sync_fetch_and_add_4

Reported by: Steven Robbins <smr@…> Owned by: Peter Dimov
Milestone: Boost 1.39.0 Component: smart_ptr
Version: Boost 1.37.0 Severity: Problem
Keywords: Cc:

Description

Hi,

As noted in #2263, Boost makes the incorrect assumption that if the following condition is true:

defined( GNUC ) && ( GNUC * 100 + GNUC_MINOR >= 401 )

then GCC sync primitives (e.g. sync_lock_test_and_set, sync_fetch_and_add) are available.

Currently, hppa and arm are listed as exceptions. However, building Boost on Debian's 14 architectures suggests that some more exceptions are needed: armel (ARM in little endian mode), m68k and sparc. I'm attaching a patch to atomic_count.hpp to this effect.

When using GNU C++ however, that patch means that all those machines fall through to atomic_count_gcc.hpp, which is known to be broken for GCC > 4.1 (c.f. #1084, never applied). I'm attaching a patch for this problem, too.

Note that these patches are only for the problems I noticed while building Boost, and only because we also build "tools/bcp", which happens to use shared_ptr. From grepping the sources it appears that there are a few others.

Attachments (3)

atomic_count.patch (795 bytes ) - added by Steven Robbins <smr@…> 14 years ago.
atomic_count_gcc.patch (381 bytes ) - added by Steven Robbins <smr@…> 14 years ago.
sp_counted_base.patch (914 bytes ) - added by smr@… 14 years ago.

Download all attachments as: .zip

Change History (10)

by Steven Robbins <smr@…>, 14 years ago

Attachment: atomic_count.patch added

by Steven Robbins <smr@…>, 14 years ago

Attachment: atomic_count_gcc.patch added

by smr@…, 14 years ago

Attachment: sp_counted_base.patch added

comment:1 by smr@…, 14 years ago

Added sp_counted_base.patch to address another manifestation in sp_counted_base.hpp.

comment:2 by Peter Dimov, 14 years ago

Milestone: Boost 1.38.0Boost 1.39.0
Status: newassigned

comment:3 by Peter Dimov, 14 years ago

(In [51517]) Refs #2525 (fixed in trunk.)

comment:4 by Peter Dimov, 14 years ago

Resolution: fixed
Status: assignedclosed

(In [51538]) Merge [51517] to release. Closes #2525.

comment:5 by Peter Dimov, 14 years ago

Resolution: fixed
Status: closedreopened

Reopening due to the claim in

http://lists.boost.org/Archives/boost/2007/11/130479.php

that g++ 4.2 has __sync operations on __sparc__. Steven, can you please confirm or deny it?

comment:6 by smr@…, 14 years ago

On the sparc to which I have access (a sparc64 running Debian Linux), I can attest that g++ 4.2 does *not* have all the __sync primitives used in Boost. I created a test program using all the primitives I could find with "rgrep __sync_ *" in the Boost root source directory (SVN head).

Here is the transcript.

(sid)smr@smetana:~$ uname -a
Linux smetana 2.6.26-1-sparc64-smp #1 SMP Sat Jan 10 18:53:17 UTC 2009 sparc64 GNU/Linux

(sid)smr@smetana:~$ cat sync-primitives.cc
/* Test that uses all the __sync primitives found
   by grepping the boost sources.
*/

int main( int ac, char* av[] )
{
    long value = 0;

    __sync_lock_release( &value );

    return __sync_fetch_and_add( &value, 1 )
        +  __sync_val_compare_and_swap( &value, 1, 2 )
        +  __sync_add_and_fetch( &value, 1 )
        +  __sync_lock_test_and_set( &value, 1 );
}

(sid)smr@smetana:~$ g++-4.1 sync-primitives.cc
/tmp/ccGOFRyI.o: In function `main':
sync-primitives.cc:(.text+0x24): undefined reference to `__sync_fetch_and_add_4'
sync-primitives.cc:(.text+0x44): undefined reference to `__sync_val_compare_and_swap_4'
sync-primitives.cc:(.text+0x60): undefined reference to `__sync_add_and_fetch_4'
sync-primitives.cc:(.text+0x7c): undefined reference to `__sync_lock_test_and_set_4'
collect2: ld returned 1 exit status

(sid)smr@smetana:~$ g++-4.2 sync-primitives.cc
/tmp/ccQg4NKe.o: In function `main':
sync-primitives.cc:(.text+0x28): undefined reference to `__sync_fetch_and_add_4'
sync-primitives.cc:(.text+0x48): undefined reference to `__sync_val_compare_and_swap_4'
sync-primitives.cc:(.text+0x64): undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status

(sid)smr@smetana:~$ g++-4.3 sync-primitives.cc
/tmp/cc8anhqk.o: In function `main':
sync-primitives.cc:(.text+0x28): undefined reference to `__sync_fetch_and_add_4'
sync-primitives.cc:(.text+0x48): undefined reference to `__sync_val_compare_and_swap_4'
sync-primitives.cc:(.text+0x64): undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status

comment:7 by Peter Dimov, 14 years ago

Resolution: fixed
Status: reopenedclosed

OK, closing as fixed, thanks.

Note: See TracTickets for help on using tickets.