Skip to content

Commit 4b25b7f

Browse files
committed
[clang][WebAssembly] Always have -pthread imply --shared-memory linker flag
Unlike `-lpthread` this flag should not be suppressed by `-nostdlib`.
1 parent 86f0e6d commit 4b25b7f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
150150

151151
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
152152

153+
if (Args.hasArg(options::OPT_pthread))
154+
CmdArgs.push_back("--shared-memory");
155+
153156
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
154157
if (ToolChain.ShouldLinkCXXStdlib(Args))
155158
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
156159

157-
if (Args.hasArg(options::OPT_pthread)) {
160+
if (Args.hasArg(options::OPT_pthread))
158161
CmdArgs.push_back("-lpthread");
159-
CmdArgs.push_back("--shared-memory");
160-
}
161162

162163
CmdArgs.push_back("-lc");
163164
AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);

clang/test/Driver/wasm-toolchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
// RUN: --sysroot=/foo %s -pthread 2>&1 \
8080
// RUN: | FileCheck -check-prefix=PTHREAD %s
8181
// PTHREAD: "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
82-
// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
82+
// PTHREAD: wasm-ld{{.*}}" "--shared-memory" "-lpthread"
8383

8484
// '-pthread' not allowed with '-mno-atomics'
8585
// RUN: not %clang -### --target=wasm32-unknown-unknown \

0 commit comments

Comments
 (0)