[clang] d496437 - [WebAssembly] Add support for -mexec-model=reactor
Dan Gohman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 3 14:03:23 PDT 2020
Author: Dan Gohman
Date: 2020-06-03T14:02:47-07:00
New Revision: d496437a0bfd6d135343026cdb7b6a69cb6af536
URL: https://github.com/llvm/llvm-project/commit/d496437a0bfd6d135343026cdb7b6a69cb6af536
DIFF: https://github.com/llvm/llvm-project/commit/d496437a0bfd6d135343026cdb7b6a69cb6af536.diff
LOG: [WebAssembly] Add support for -mexec-model=reactor
This adds a -mexec-model= command-line flag. The default value is "command"
which is no change from the current behavior. The other option is "reactor"
which enables the WASI Reactor ABI:
https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md
Differential Revision: https://reviews.llvm.org/D62922
Added:
Modified:
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/test/Driver/wasm-toolchain.c
Removed:
################################################################################
diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst
index 4fde6034975e..1ebcab1651d0 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -3051,6 +3051,12 @@ WebAssembly
.. option:: -munimplemented-simd128, -mno-unimplemented-simd128
+.. option:: -mexec-model=<arg>
+
+Select between "command" and "reactor" executable models. Commands have a main
+function which scopes the lifetime of the program. Reactors are activated and
+remain active until explicitly terminated.
+
X86
---
.. option:: -m3dnow, -mno-3dnow
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 05a9121592ef..add71fb7dfd7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -171,6 +171,10 @@ def m_ppc_Features_Group : OptionGroup<"<ppc features group>">,
Group<m_Group>, DocName<"PowerPC">;
def m_wasm_Features_Group : OptionGroup<"<wasm features group>">,
Group<m_Group>, DocName<"WebAssembly">;
+// The features added by this group will not be added to target features.
+// These are explicitly handled.
+def m_wasm_Features_Driver_Group : OptionGroup<"<wasm driver features group>">,
+ Group<m_Group>, DocName<"WebAssembly Driver">;
def m_x86_Features_Group : OptionGroup<"<x86 features group>">,
Group<m_Group>, Flags<[CoreOption]>, DocName<"X86">;
def m_riscv_Features_Group : OptionGroup<"<riscv features group>">,
@@ -2456,6 +2460,9 @@ def mtail_call : Flag<["-"], "mtail-call">, Group<m_wasm_Features_Group>;
def mno_tail_call : Flag<["-"], "mno-tail-call">, Group<m_wasm_Features_Group>;
def mreference_types : Flag<["-"], "mreference-types">, Group<m_wasm_Features_Group>;
def mno_reference_types : Flag<["-"], "mno-reference-types">, Group<m_wasm_Features_Group>;
+def mexec_model_EQ : Joined<["-"], "mexec-model=">, Group<m_wasm_Features_Driver_Group>,
+ Values<"command,reactor">,
+ HelpText<"Execution model (WebAssembly only)">;
def mamdgpu_debugger_abi : Joined<["-"], "mamdgpu-debugger-abi=">,
Flags<[HelpHidden]>,
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 461ec75d17f6..48f9a9b603db 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -69,8 +69,26 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddAllArgs(CmdArgs, options::OPT_u);
ToolChain.AddFilePathLibArgs(Args, CmdArgs);
+ const char *Crt1 = "crt1.o";
+ const char *Entry = NULL;
+ if (const Arg *A = Args.getLastArg(options::OPT_mexec_model_EQ)) {
+ StringRef CM = A->getValue();
+ if (CM == "command") {
+ // Use default values.
+ } else if (CM == "reactor") {
+ Crt1 = "crt1-reactor.o";
+ Entry = "_initialize";
+ } else {
+ ToolChain.getDriver().Diag(diag::err_drv_invalid_argument_to_option)
+ << CM << A->getOption().getName();
+ }
+ }
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
- CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1)));
+ if (Entry) {
+ CmdArgs.push_back(Args.MakeArgString("--entry"));
+ CmdArgs.push_back(Args.MakeArgString(Entry));
+ }
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
diff --git a/clang/test/Driver/wasm-toolchain.c b/clang/test/Driver/wasm-toolchain.c
index 343c1b001ef8..8300a81614e3 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -107,3 +107,14 @@
// RUN: %clang %s -### -fsanitize=address -target wasm32-unknown-emscripten 2>&1 | FileCheck -check-prefix=CHECK-ASAN-EMSCRIPTEN %s
// CHECK-ASAN-EMSCRIPTEN: "-fsanitize=address"
// CHECK-ASAN-EMSCRIPTEN: "-fsanitize-address-globals-dead-stripping"
+
+// Basic exec-model tests.
+
+// RUN: %clang %s -### -no-canonical-prefixes -target wasm32-unknown-unknown -mexec-model=command 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-COMMAND %s
+// CHECK-COMMAND: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// CHECK-COMMAND: wasm-ld{{.*}}" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+
+// RUN: %clang %s -### -no-canonical-prefixes -target wasm32-unknown-unknown -mexec-model=reactor 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-REACTOR %s
+// CHECK-REACTOR: wasm-ld{{.*}}" {{.*}} "--entry" "_initialize" {{.*}}
More information about the cfe-commits
mailing list