ARM platform: undefined reference to __sync_fetch_and_add_4

I cannot link against Boost libraries 1.35.0 built with CodeSourcery's ARM/GNU toolchain, although the build is successful. I built Boost with: bjam --with-regex --with-serialization --with-thread stage And tried to link to the test program from the 'Getting Started (Unix)' guide I get: $ arm-none-linux-gnueabi-g++ test-regex.cpp -I. stage/lib/libboost_regex-gcc42-mt-1_35.so /tmp/ccVow1Eq.o: In function `boost::detail::atomic_decrement(int*)': test-regex.cpp:(.text._ZN5boost6detail16atomic_decrementEPi[boost::detail::atomic_decrement(int*)]+0x18): undefined reference to `__sync_fetch_and_add_4' collect2: ld returned 1 exit status With assistance on the boost-build list I've ascertained that the problem is that GCC doesn't support __sync_fetch_and_add and the other atomic built-ins on ARM. An additional case for this may need to be added to boost/detail/sp_counted_base.hpp I don't know enough to patch boost for this, short-term or otherwise; can anyone offer any advice? TIA, --rob

Rob Desbois wrote:
I cannot link against Boost libraries 1.35.0 built with CodeSourcery's ARM/GNU toolchain, although the build is successful. ...
undefined reference to `__sync_fetch_and_add_4' collect2: ld returned 1 exit status
With assistance on the boost-build list I've ascertained that the problem is that GCC doesn't support __sync_fetch_and_add and the other atomic built-ins on ARM. An additional case for this may need to be added to boost/detail/sp_counted_base.hpp
I don't know enough to patch boost for this, short-term or otherwise; can anyone offer any advice?
Two workarounds are available: define BOOST_SP_DISABLE_THREADS to disable MT-safety for the reference count, or define BOOST_SP_USE_PTHREADS to use a pthread_mutex.

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: Thursday, April 03, 2008 1:42 PM To: boost@lists.boost.org Subject: Re: [boost] ARM platform: undefined reference to __sync_fetch_and_add_4
Rob Desbois wrote:
I cannot link against Boost libraries 1.35.0 built with CodeSourcery's ARM/GNU toolchain, although the build is successful. ...
undefined reference to `__sync_fetch_and_add_4' collect2: ld returned 1 exit status
With assistance on the boost-build list I've ascertained that the problem is that GCC doesn't support __sync_fetch_and_add and the other atomic built-ins on ARM. An additional case for this may need to be added to boost/detail/sp_counted_base.hpp
I don't know enough to patch boost for this, short-term or otherwise; can anyone offer any advice?
Two workarounds are available: define BOOST_SP_DISABLE_THREADS to disable MT-safety for the reference count, or define BOOST_SP_USE_PTHREADS to use a pthread_mutex.
Another option would be to just supply the __sync_fetch_and_add_4 function that gcc is trying to link in. When gcc doesn't support the builtin it assumes that a function exists with that name. A snippet of ARM assembly to implement the atomic operation shouldn't be that difficult.

Schrader, Glenn wrote:
With assistance on the boost-build list I've ascertained that the problem is that GCC doesn't support __sync_fetch_and_add and the other atomic built-ins on ARM.
Two workarounds are available: define BOOST_SP_DISABLE_THREADS to disable MT-safety for the reference count, or define BOOST_SP_USE_PTHREADS to use a pthread_mutex.
Another option would be to just supply the __sync_fetch_and_add_4 function that gcc is trying to link in. When gcc doesn't support the builtin it assumes that a function exists with that name. A snippet of ARM assembly to implement the atomic operation shouldn't be that difficult.
Are you volunteering to write such a "snippet"? - Volodya

On Fri, Apr 4, 2008 at 1:35 PM, Schrader, Glenn <gschrad@ll.mit.edu> wrote:
I cannot link against Boost libraries 1.35.0 built with CodeSourcery's ARM/GNU toolchain, although the build is successful. ...
undefined reference to `__sync_fetch_and_add_4' collect2: ld returned 1 exit status
With assistance on the boost-build list I've ascertained that the problem is that GCC doesn't support __sync_fetch_and_add and the other atomic built-ins on ARM. An additional case for this may need to be added to boost/detail/sp_counted_base.hpp
I don't know enough to patch boost for this, short-term or otherwise; can anyone offer any advice?
Two workarounds are available: define BOOST_SP_DISABLE_THREADS to disable MT-safety for the reference count, or define BOOST_SP_USE_PTHREADS to use a pthread_mutex.
Another option would be to just supply the __sync_fetch_and_add_4 function that gcc is trying to link in. When gcc doesn't support the builtin it assumes that a function exists with that name. A snippet of ARM assembly to implement the atomic operation shouldn't be that difficult.
Perhaps not for you. I am a novice when it comes to any assembly, and have never even touched ARM assembly. If you can provide the ARM equivalent operation I would be extremely grateful, but I am unable to code it myself unfortunately.

Rob Desbois:
If you can provide the ARM equivalent operation I would be extremely grateful, but I am unable to code it myself unfortunately.
I think that ARM (pre-v6) doesn't have an atomic fetch-and-add operation. It only has an atomic swap. We'll have to use a spinlock. It would be helpful if you can try whether libs/smart_ptr/test/spinlock_test.cpp from the current SVN trunk compiles and works for you.

On Thu, Apr 3, 2008 at 6:42 PM, Peter Dimov <pdimov@pdimov.com> wrote:
I cannot link against Boost libraries 1.35.0 built with CodeSourcery's ARM/GNU toolchain, although the build is successful. ...
undefined reference to `__sync_fetch_and_add_4' collect2: ld returned 1 exit status
With assistance on the boost-build list I've ascertained that the problem is that GCC doesn't support __sync_fetch_and_add and the other atomic built-ins on ARM. An additional case for this may need to be added to boost/detail/sp_counted_base.hpp
I don't know enough to patch boost for this, short-term or otherwise; can anyone offer any advice?
Two workarounds are available: define BOOST_SP_DISABLE_THREADS to disable MT-safety for the reference count, or define BOOST_SP_USE_PTHREADS to use a pthread_mutex.
Thanks Peter that compiles now.
participants (4)
-
Peter Dimov
-
Rob Desbois
-
Schrader, Glenn
-
Vladimir Prus