[boost.atomic] linker error with gcc 4.1.2

With gcc 4.1.2 (gcc 4.3.x is fine) I am seeing this linker error: .build/debug/working/SourceOne.o: In function `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)': /thirdparty/boost/boost_1_42/boost/smart_ptr/detail/shared_count.hpp:229: multiple definition of `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)' .build/debug/working/SourceTwo.o: /thirdparty/boost/boost_1_42/boost/atomic/detail/gcc-x86.hpp:63: first defined here Which doesn't make a lot of sense at first glance, but on closer inspection I see that: boost/atomic/detail/base.hpp defines platform_atomic_thread_fence as: template<typename T> static inline void platform_atomic_thread_fence(T order) { /* FIXME: this does not provide sequential consistency, need one global variable for that... */ platform_atomic<int> a; a.exchange(0, order); } and then it is defined as a specialisation in: boost/atomic/detail/gcc-x86.hpp as: template<> void platform_atomic_thread_fence(memory_order order) { switch(order) { case memory_order_seq_cst: full_fence(); case memory_order_acquire: case memory_order_consume: case memory_order_acq_rel: case memory_order_release: __asm__ __volatile__ ("" ::: "memory"); default:; } } Is this a compiler error or should the specialisation be declared as: template<> inline void platform_atomic_thread_fence(memory_order order) (which will work) Suggestions? Jamie

Jamie Allsop schrieb:
With gcc 4.1.2 (gcc 4.3.x is fine) I am seeing this linker error:
.build/debug/working/SourceOne.o: In function `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)':
/thirdparty/boost/boost_1_42/boost/smart_ptr/detail/shared_count.hpp:229: multiple definition of `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)'
.build/debug/working/SourceTwo.o: /thirdparty/boost/boost_1_42/boost/atomic/detail/gcc-x86.hpp:63: first defined here
Which doesn't make a lot of sense at first glance, but on closer inspection I see that:
boost/atomic/detail/base.hpp defines platform_atomic_thread_fence as:
template<typename T> static inline void platform_atomic_thread_fence(T order) { /* FIXME: this does not provide sequential consistency, need one global variable for that... */ platform_atomic<int> a; a.exchange(0, order); }
and then it is defined as a specialisation in:
boost/atomic/detail/gcc-x86.hpp as:
template<> void platform_atomic_thread_fence(memory_order order) { switch(order) { case memory_order_seq_cst: full_fence(); case memory_order_acquire: case memory_order_consume: case memory_order_acq_rel: case memory_order_release: __asm__ __volatile__ ("" ::: "memory"); default:; } }
Is this a compiler error or should the specialisation be declared as:
template<> inline void platform_atomic_thread_fence(memory_order order)
(which will work)
Suggestions? Jamie
use static inline void platform_atomic_thread_fence(memory_order order) { ... }

Hi Jamie, On Wed, 3 Mar 2010, Jamie Allsop wrote:
With gcc 4.1.2 (gcc 4.3.x is fine) I am seeing this linker error:
.build/debug/working/SourceOne.o: In function `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)': /thirdparty/boost/boost_1_42/boost/smart_ptr/detail/shared_count.hpp:229: multiple definition of `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)' .build/debug/working/SourceTwo.o: /thirdparty/boost/boost_1_42/boost/atomic/detail/gcc-x86.hpp:63: first defined here
[...]
Is this a compiler error or should the specialisation be declared as:
template<> inline void platform_atomic_thread_fence(memory_order order)
you are right, it should have been specialized this way. I have however reorganized my development tree such that this is now handled differently (macros instead of via template specialization), so if you are patient until saturday, this will be resolved. Best regards Helge

Helge Bahmann wrote:
Hi Jamie,
On Wed, 3 Mar 2010, Jamie Allsop wrote:
With gcc 4.1.2 (gcc 4.3.x is fine) I am seeing this linker error:
.build/debug/working/SourceOne.o: In function `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)':
/thirdparty/boost/boost_1_42/boost/smart_ptr/detail/shared_count.hpp:229: multiple definition of `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)'
.build/debug/working/SourceTwo.o: /thirdparty/boost/boost_1_42/boost/atomic/detail/gcc-x86.hpp:63: first defined here
[...]
Is this a compiler error or should the specialisation be declared as:
template<> inline void platform_atomic_thread_fence(memory_order order)
you are right, it should have been specialized this way. I have however reorganized my development tree such that this is now handled differently (macros instead of via template specialization), so if you are patient until saturday, this will be resolved.
I patched my copy locally so no rush for me. However I'm curious as to why you'd use a macro when a template would do? Or is it that your changes preclude using templates or other language facilities? I guess I can have a look on Saturday ;) Thanks for the response, Jamie

On Fri, 5 Mar 2010, Jamie Allsop wrote:
Helge Bahmann wrote:
Hi Jamie,
On Wed, 3 Mar 2010, Jamie Allsop wrote:
With gcc 4.1.2 (gcc 4.3.x is fine) I am seeing this linker error:
.build/debug/working/SourceOne.o: In function `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)': /thirdparty/boost/boost_1_42/boost/smart_ptr/detail/shared_count.hpp:229: multiple definition of `void boost::detail::atomic::platform_atomic_thread_fence<boost::memory_order>(boost::memory_order)' .build/debug/working/SourceTwo.o: /thirdparty/boost/boost_1_42/boost/atomic/detail/gcc-x86.hpp:63: first defined here
[...]
Is this a compiler error or should the specialisation be declared as:
template<> inline void platform_atomic_thread_fence(memory_order order)
you are right, it should have been specialized this way. I have however reorganized my development tree such that this is now handled differently (macros instead of via template specialization), so if you are patient until saturday, this will be resolved.
I patched my copy locally so no rush for me. However I'm curious as to why you'd use a macro when a template would do? Or is it that your changes preclude using templates or other language facilities? I guess I can have a look on Saturday ;)
there has been a request for the abilitiy to detect at compile-time the lock-freedom of atomic data types, in order to being able to pick different data structures and code paths. If I have to define macros for this purpose anyway, there is no good reason anymore to "abuse" templates as much as I do currently. Best regards Helge
participants (3)
-
Helge Bahmann
-
Jamie Allsop
-
Oliver Kowalke