From: Thomas Lively Date: Fri, 22 Mar 2019 22:25:37 +0000 (+0000) Subject: [WebAssembly] Make driver -pthread imply linker --shared-memory X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9970c8c78fa268e40cd28ea37decff2db4f5729;p=clang [WebAssembly] Make driver -pthread imply linker --shared-memory Summary: This eliminates a linker error the user might otherwise see about how using the 'atomics' feature requires --shared-memory. Reviewers: sbc100, aheejin Subscribers: dschuff, jgravelle-google, sunfish, jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59721 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356817 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/WebAssembly.cpp b/lib/Driver/ToolChains/WebAssembly.cpp index 0104cbbbf4..b69588d4c1 100644 --- a/lib/Driver/ToolChains/WebAssembly.cpp +++ b/lib/Driver/ToolChains/WebAssembly.cpp @@ -62,8 +62,10 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA, 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/test/Driver/wasm-toolchain.c b/test/Driver/wasm-toolchain.c index 9c217ef2e9..c47e24fa94 100644 --- a/test/Driver/wasm-toolchain.c +++ b/test/Driver/wasm-toolchain.c @@ -41,9 +41,10 @@ // Thread-related command line tests. -// '-pthread' sets '-target-feature +atomics' +// '-pthread' sets '-target-feature +atomics' and '--shared-memory' // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s -pthread 2>&1 | FileCheck -check-prefix=PTHREAD %s // PTHREAD: clang{{.*}}" "-cc1" {{.*}} "-target-feature" "+atomics" +// PTHREAD: wasm-ld{{.*}}" "-lpthread" "--shared-memory" // '-pthread' not allowed with '-mno-atomics' // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s -pthread -mno-atomics 2>&1 | FileCheck -check-prefix=PTHREAD_NO_ATOMICS %s