Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9041 closed Bugs (fixed)

[thread] Boost.Thread DSO's may need to link with Boost.Atomic

Reported by: Petr Machata <pmachata@…> Owned by: viboes
Milestone: Boost 1.55.0 Component: atomic
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

libs/thread/src/pthread/once.cpp includes libs/thread/src/pthread/once_atomic.cpp, which includes boost/atomic.hpp, which (transitively) includes boost/atomic/detail/lockpool.hpp, which, depending on whether BOOST_ATOMIC_FLAG_LOCK_FREE is set, may need external reference to boost::atomics::detail::lockpool::get_lock_for(void const volatile *), defined in libbost_atomic.so.1.54.0.

On most targets, BOOST_ATOMIC_FLAG_LOCK_FREE is set and the external reference is not necessary. On some, such as s390, it's not, and when linking to libboost_thread.so.1.54.0, the linker complains about unsatisfied references to above-mentioned symbol, such as:

/lib64/libboost_thread.so.1.54.0: undefined reference to `boost::atomics::detail::lockpool::get_lock_for(void const volatile*)'

In attached patch, I resolve this by testing whether BOOST_ATOMIC_FLAG_LOCK_FREE is defined. If not, I set up linking of libboost_atomic.so.1.54.0.

Attachments (2)

boost-1.54.0-thread-link_atomic.patch (1.8 KB ) - added by Petr Machata <pmachata@…> 9 years ago.
A fix.
boost-1.55.0-atomic-check_lock_free_flag.patch (875 bytes ) - added by Peter Vingelmann <peter@…> 9 years ago.
Fix for gcc 4.7+ cross-compilers.

Download all attachments as: .zip

Change History (19)

by Petr Machata <pmachata@…>, 9 years ago

A fix.

comment:1 by Petr Machata <pmachata@…>, 9 years ago

Note that this seems to work--on x86_64 this produces no additional DT_NEEDED entry, on a short-circuit build of just Boost.Thread on s390x, this produces additional DT_NEEDED on Boost.Atomic. However, full s390x bootstrap has not yet finished, so I couldn't actually test whether that resolves the original problem (though I expect it to).

comment:2 by Petr Machata <pmachata@…>, 9 years ago

The bootstrap has finished and I verified that the fix is effective.

comment:3 by viboes, 9 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

Hi, thanks for the patch. I didn't know that we could configure the build in this way. Very interesting.

comment:4 by viboes, 9 years ago

BTW, how this path works when cross-compiling?

comment:5 by viboes, 9 years ago

For the time been I will link always with boost_atomic

Committed revision [85464].

comment:6 by viboes, 9 years ago

Milestone: To Be DeterminedBoost 1.55.0

in reply to:  4 ; comment:7 by Petr Machata <pmachata@…>, 9 years ago

Replying to viboes:

BTW, how this path works when cross-compiling?

I don't know the details, I'm relying on configure.compile to pick the configured compiler. This is how all the configure checks are done FWIW, so I would certainly hope it just does the right thing here.

in reply to:  7 ; comment:8 by viboes, 9 years ago

Replying to Petr Machata <pmachata@…>:

Replying to viboes:

BTW, how this path works when cross-compiling?

I don't know the details, I'm relying on configure.compile to pick the configured compiler. This is how all the configure checks are done FWIW, so I would certainly hope it just does the right thing here.

The problem I see is that you can not always run the cross compiled exe on the host. Am I missing something?

in reply to:  8 ; comment:9 by Petr Machata <pmachata@…>, 9 years ago

Replying to viboes:

The problem I see is that you can not always run the cross compiled exe on the host.

We're just building it, not running it. Even simply compiling the source (sans linking) would be enough, as all the magic is in a static assert, but I couldn't find how to request that.

comment:10 by viboes, 9 years ago

Committed revision [85603] on release branch.

in reply to:  9 comment:11 by viboes, 9 years ago

Replying to Petr Machata <pmachata@…>:

Replying to viboes:

The problem I see is that you can not always run the cross compiled exe on the host.

We're just building it, not running it. Even simply compiling the source (sans linking) would be enough, as all the magic is in a static assert, but I couldn't find how to request that.

I understand it now.

comment:12 by Petr Machata <pmachata@…>, 9 years ago

So, do you intend to add the configure check? It seems like an overkill to link with Boost.Atomic just in case, as most platforms won't need it.

in reply to:  12 ; comment:13 by viboes, 9 years ago

Replying to Petr Machata <pmachata@…>:

So, do you intend to add the configure check? It seems like an overkill to link with Boost.Atomic just in case, as most platforms won't need it.

yes, see [85616].

in reply to:  13 comment:14 by Petr Machata <pmachata@…>, 9 years ago

Replying to viboes:

yes, see [85616].

Awesome, thanks.

comment:15 by viboes, 9 years ago

Resolution: fixed
Status: assignedclosed

Committed revision [85666].

comment:16 by Peter Vingelmann <peter@…>, 9 years ago

Sorry for reviving this old issue, but we encountered the same problem again with several gcc 4.7+ cross-compilers. The problem is that atomic/detail/platform.hpp relies on __atomic* intrinsics for certain compiler versions (gcc 4.7+ and clang 3.2+). However, if __GCC_ATOMIC_BOOL_LOCK_FREE is not defined or its value is 1 (where 2 indicates always lock-free, and 1 indicates sometimes lock-free), then BOOST_ATOMIC_FLAG_LOCK_FREE will not be defined in gcc-atomic.hpp, and the external reference to atomic becomes necessary again.

For example, consider this listing of defines for an Android cross-compiler: http://slowbutdeadly.blogspot.hu/2013/09/android-prebuilt-gcc-47-builtin-macro.html where __GCC_ATOMIC_BOOL_LOCK_FREE is 1.

We would like to avoid linking with atomic, so I attached a patch which checks if __GCC_ATOMIC_BOOL_LOCK_FREE is 2, before including gcc-atomic.hpp. If the value is not 2, then the other include options are exhausted, before we have to link with atomic (depending on platform support). This solution works well for us on a range of cross-compilers.

Perhaps the issue should also be raised in atomic.

by Peter Vingelmann <peter@…>, 9 years ago

Fix for gcc 4.7+ cross-compilers.

comment:17 by viboes, 9 years ago

Component: threadatomic

Moving to Boost.Atomic.

Note: See TracTickets for help on using tickets.