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

            Bug ID: 107590
           Summary: __atomic_test_and_set broken on PowerPC
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vital.had at gmail dot com
                CC: iains at gcc dot gnu.org
  Target Milestone: ---
            Target: powerpc-apple-darwin

The bug was discovered while trying to build i2pd on Darwin PPC. Build itself
succeeded, but the binary failed with Bus error. I thought it was caused by
Boost, however it turned out that Boost was fine, while Bus error was a result
of broken GCC builtin.

Details here:
https://github.com/PurpleI2P/i2pd/issues/1726#issuecomment-1305536144

In particular, simple spin lock tests fail with Bus error when built with
default usage of GCC atomics. Like this:
https://github.com/boostorg/smart_ptr/blob/develop/test/spinlock_test.cpp

36-87:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_test.cpp
-I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o
spinlock_test
36-87:boost svacchanda$ /Users/svacchanda/Dev/boost/spinlock_test 
Bus error
36-87:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_test.cpp
-DBOOST_SP_USE_STD_ATOMIC -I/opt/local/libexec/boost/1.76/include
-L/opt/local/libexec/boost/1.76/lib -o spinlock_test
36-87:boost svacchanda$ /Users/svacchanda/Dev/boost/spinlock_test

No error when Boost is forced to use its own atomics instead of GCC builtins.

Boost developer suggested that __atomic_test_and_set is broken on PPC, and GDB
output proved that:

(gdb) run
Starting program: /Users/svacchanda/Dev/boost/a.out 
Reading symbols for shared libraries +++..... done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 259 at address: 0x0000208d
0x00001b2c in boost::detail::spinlock::try_lock (this=0x208d) at
spinlock_gcc_atomic.hpp:39
39              return __atomic_test_and_set( &v_, __ATOMIC_ACQUIRE ) == 0;
(gdb) quit

Same failure confirmed on 10.5.8 and 10.6. gcc11 and gcc7 were tried, likely to
apply to other versions.

GCC output from 10.5.8:

Using built-in specs.
COLLECT_GCC=/opt/local/bin/gcc-mp-11
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/ppc-apple-darwin9/11.3.0/lto-wrapper
Target: ppc-apple-darwin9
Configured with:
/opt/local/var/macports/build/_opt_PPCLeopardPorts_lang_gcc11/gcc11/work/gcc-11.3.0/configure
--prefix=/opt/local --build=ppc-apple-darwin9
--enable-languages=c,c++,objc,obj-c++,lto,fortran --libdir=/opt/local/lib/gcc11
--includedir=/opt/local/include/gcc11 --infodir=/opt/local/share/info
--mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-11
--with-local-prefix=/opt/local --with-system-zlib --disable-nls
--program-suffix=-mp-11 --with-gxx-include-dir=/opt/local/include/gcc11/c++/
--with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local
--with-isl=/opt/local --with-zstd=/opt/local --enable-stage1-checking
--enable-lto --enable-libstdcxx-time --with-build-config=bootstrap-debug
--with-bugurl=https://trac.macports.org/newticket --enable-host-shared
--with-tune-cpu=G5 --disable-tls --with-as=/opt/local/bin/as
--with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar
--with-pkgversion='MacPorts gcc11 11.3.0_1+universal'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (MacPorts gcc11 11.3.0_1+universal)

Reply via email to