-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[loader] Add use of threads so -lpthread works when building #797
Conversation
I am using gcc-9.4.0 and in this version the definition of
This bug is documented here https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55394 So in the cmake for ur_adapter, Threads are required. But this translates to -lpthread when linking. The linker then seems to do some scanning of the module, and if it only sees call_once and no other mentions of threads, it will not link to pthreads. (presumably because other versions of gcc don't require linking with pthreads in order for call_once to work)(Aside: a heavier version of -lpthread is -pthread which will force link with pthreads as well as define some macros etc and make it work)
Whereas if we have some use of threads we get:
So in my case the libur_adapter.so was not getting linked with pthreads which was causing an error out on call_once
With this change the new output is:
|
Ping @ldrumm |
One other solution to this would be conditionally adding |
Aha silly me thanks @veselypeta @callumfare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT, just one suggestion 👍
I think this would be a preferable workaround to me. |
Change made |
@kbenzie can we merge this? |
Looks good. The cmake approach is the right one, and it makes it clear that this the extra flag is a workaround for a specific compiler, so it can be removed later Definitely a fun bug to track down! |
Can someone with merge privileges merge this please? |
This patch makes
libur_loader.so
force link againstpthreads
by adding some trivial use of threads. Linking against pthreads is necessary forstd::call_once
to work for gcc 9.4, but it doesn't happen automatically, as even when specifying-lpthread
, the linker doesn't know that pthreads are necessary forcall_once
(pthreads isn't necessary for call_once for other versions of gcc) so it may elide the linking.