[PATCH] D52878: [test-suite] Add flags for stdthreadbug.cpp when building static
Simon Atanasyan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 16 10:06:03 PST 2019
atanasyan added a comment.
The problem (if we forget that static linking is usually not a good idea) is not MIPS specific so maybe the following patch solves the problem generally and better?
--- a/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -513,8 +513,18 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
- if (WantPthread && !isAndroid)
- CmdArgs.push_back("-lpthread");
+ if (WantPthread && !isAndroid) {
+ // Link whole libpthread.a to prevent std::thread
+ // segmentation fault in case of static linking.
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52590
+ if (Args.hasArg(options::OPT_static)) {
+ CmdArgs.push_back("--whole-archive");
+ CmdArgs.push_back("-lpthread");
+ CmdArgs.push_back("--no-whole-archive");
+ } else {
+ CmdArgs.push_back("-lpthread");
+ }
+ }
if (Args.hasArg(options::OPT_fsplit_stack))
CmdArgs.push_back("--wrap=pthread_create");
Sure we need to add a test case.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D52878/new/
https://reviews.llvm.org/D52878
More information about the llvm-commits
mailing list