[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug gold/25437] New: Invalid combination --as-needed and -pthread optio
From: |
laurent.stacul at amadeus dot com |
Subject: |
[Bug gold/25437] New: Invalid combination --as-needed and -pthread options |
Date: |
Wed, 22 Jan 2020 09:27:27 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=25437
Bug ID: 25437
Summary: Invalid combination --as-needed and -pthread options
Product: binutils
Version: 2.33
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gold
Assignee: ccoutant at gmail dot com
Reporter: laurent.stacul at amadeus dot com
CC: ian at airs dot com
Target Milestone: ---
I have a program that compiles fine. As soon as I try to use the linker option
`--as-needed`, the program builds but crases at runtime. I investigated this
issue and managed to build a reproducer.
The reproducer:
#include <mutex>
#include <iostream>
std::once_flag flag;
int main(int argc, const char *argv[])
{
std::call_once(flag, [](){ std::cout << "Simple example: called once\n";
});
return 0;
}
There is a difference if I use bfd and gold/lld when the -pthread and
-Wl,--as-needed options are used as you can see in the following results:
* With BFD
--------
g++ -g -c test_call_once.cpp -o test_call_once.o
g++ -g -fuse-ld=bfd -Wl,--as-needed -pthread test_call_once.o -lm
readelf -d a.out | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
* With Gold
---------
g++ -g -c test_call_once.cpp -o test_call_once.o
g++ -g -fuse-ld=gold -Wl,--as-needed -pthread test_call_once.o -lm
readelf -d a.out | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
* With lld (to be exhaustive)
--------------------------
g++ -g -c test_call_once.cpp -o test_call_once.o
g++ -g -fuse-ld=lld -Wl,--as-needed -pthread test_call_once.o -lm
readelf -d a.out | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
In the two last cases, when I run the program, it crash with SIGABRT and
following backtrace:
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007f2cbfb05899 in __GI_abort () at abort.c:79
#2 0x00007f2cbfd6f5f6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007f2cbfd7b9ec in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007f2cbfd7ba47 in std::terminate() () from
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007f2cbfd7bca9 in __cxa_throw () from
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007f2cbfd722cc in std::__throw_system_error(int) () from
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x000055bf57ea93a5 in std::call_once<main(int, char const**)::<lambda()>
>(std::once_flag &, <lambda()> &&) (__once=..., __f=...) at
/usr/include/c++/9/mutex:697
#8 0x000055bf57ea929b in main (argc=1, argv=0x7ffffc66be48) at
test_call_once.cpp:8
Here are the versions of the used tools but I can reproduce with older ones
too.
OS: Ubuntu 19.10
GCC: gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008
binutils: GNU Binutils for Ubuntu 2.33
lld: LLD 9.0.0 (compatible with GNU linkers)
My first thought was that it was because of the libc++. But as I have different
behaviours with different linker, I was wondering what was the official
expected behaviour.
Thanks in advance for you help,
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug gold/25437] New: Invalid combination --as-needed and -pthread options,
laurent.stacul at amadeus dot com <=