You are not logged in.
The program below compiled and linked statically with
g++ -static -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive cv.cpp
segfaults in the condition_variable destructor on my machine with latest updates to the arch toolchain. It works with the previous version. Can anyone else duplicate this or have insight into where the problem lies?
Thank you!
#include <condition_variable>
int main() {
std::condition_variable v;
return 0;
}
Last edited by lopster (2022-02-15 23:42:40)
Offline
More details: Compiling it with
g++ -static -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive cv.cpp
is necessary to get it to work with the old toolchain. That doesn't work with the new toolchain, however. Perhaps the pthread library is not built right in the new stuff?
Offline
Can anyone else duplicate this ...
Yes, I can confirm duplication of the problem as described. But I have no insight to offer towards a solution.
EDIT: I see most of my pacman mirrors recently dropped off the supported list and I didn't have the newest gcc. I've updated now and re-confirmed the symptoms. However this suggests it is not just with the newest toolchain as I saw the same results with both gcc 11.1.0-3 and 11.2.0-3.
Last edited by Trilby (2022-02-15 19:17:44)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
EDIT: I see most of my pacman mirrors recently dropped off the supported list and I didn't have the newest gcc. I've updated now and re-confirmed the symptoms. However this suggests it is not just with the newest toolchain as I saw the same results with both gcc 11.1.0-3 and 11.2.0-3.
Thanks for checking. I had the original build command wrong and edited it. The corrected command should work with the old toolchain.
It looks like the problem is that /usr/lib/libpthread.a in the new toolchain is 8 bytes long containing just
!<arch>
I'll file a bug about that.
Offline
Check the release notes for glibc 2.34 for more info. That is not your problem.
Offline
Check the release notes for glibc 2.34 for more info. That is not your problem.
Thank you for pointing me to the glibc release notes.
If anyone else comes across this, more details about this change are here: Why glibc 2.34 removed libpthread
This issue with condition_variable and static linking has been around for almost 10 years: C++11's condition variables fail with static linking
I attempted to --whole-archive glibc but that resulted in linker errors.
Putting unused pthread calls in the program as mentioned in the gcc bug report fixes this example and the larger program where I originally encountered this issue. The working code is:
#include <condition_variable>
#include <pthread.h>
void pthread_cond_bug() {
pthread_cond_signal((pthread_cond_t *) nullptr);
pthread_cond_init((pthread_cond_t *) nullptr,
(const pthread_condattr_t *) nullptr);
pthread_cond_destroy((pthread_cond_t *) nullptr);
pthread_cond_timedwait((pthread_cond_t *) nullptr, (pthread_mutex_t *)
nullptr, (const struct timespec *) nullptr);
pthread_cond_wait((pthread_cond_t *) nullptr, (pthread_mutex_t *) nullptr);
}
int main() {
std::condition_variable v;
return 0;
}
Offline