Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Feb 20, 2025

Unlike -lpthread this flag should not be suppressed by -nostdlib.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Feb 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Sam Clegg (sbc100)

Changes

Unlike -lpthread this flag should not be suppressed by -nostdlib.


Full diff: https://github.com/llvm/llvm-project/pull/127939.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+4-3)
  • (modified) clang/test/Driver/wasm-toolchain.c (+1-1)
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index bd25fd1a8933a..93f17a03c580f 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -150,14 +150,15 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  if (Args.hasArg(options::OPT_pthread))
+    CmdArgs.push_back("--shared-memory");
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
     if (ToolChain.ShouldLinkCXXStdlib(Args))
       ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
 
-    if (Args.hasArg(options::OPT_pthread)) {
+    if (Args.hasArg(options::OPT_pthread))
       CmdArgs.push_back("-lpthread");
-      CmdArgs.push_back("--shared-memory");
-    }
 
     CmdArgs.push_back("-lc");
     AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
diff --git a/clang/test/Driver/wasm-toolchain.c b/clang/test/Driver/wasm-toolchain.c
index f516a4e457da7..7d9c8c6ac5c9b 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -79,7 +79,7 @@
 // RUN:    --sysroot=/foo %s -pthread 2>&1 \
 // RUN:  | FileCheck -check-prefix=PTHREAD %s
 // PTHREAD: "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
-// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory"
+// PTHREAD: wasm-ld{{.*}}" "--shared-memory" "-lpthread"
 
 // '-pthread' not allowed with '-mno-atomics'
 // RUN: not %clang -### --target=wasm32-unknown-unknown \

…inker flag

Unlike `-lpthread` this flag should not be suppressed by `-nostdlib`.
@sbc100 sbc100 merged commit 1e85e5a into llvm:main Feb 24, 2025
11 checks passed
@sbc100 sbc100 deleted the wasm_pthread_flag branch February 24, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants