From d67fd0cab1887c6a1c1407b2d23b076c1605607f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 11 Apr 2024 11:22:11 +0000 Subject: [PATCH] Disable Ctrl-C handling on WASM WASM fundamentally doesn't support signals. If WASI ever gets support for notifying the guest process of a Ctrl-C that happened, this would have to be done through the guest process polling for the signal, which will require thread support in WASI too to be compatible with the api provided by the ctrlc crate. remove linker wrapper script --- comment.txt | 2 +- compiler/rustc_driver_impl/Cargo.toml | 4 ++- compiler/rustc_driver_impl/src/lib.rs | 1 + .../src/spec/targets/wasm32_wasip1_threads.rs | 4 ++- config.llvm.toml | 3 +- wrapper_linker_clang.sh | 34 ------------------- 6 files changed, 9 insertions(+), 39 deletions(-) delete mode 100755 wrapper_linker_clang.sh diff --git a/comment.txt b/comment.txt index 5cf693f094817..df2b9ca0ed9ab 100644 --- a/comment.txt +++ b/comment.txt @@ -19,7 +19,7 @@ Hello World! use LLVM Install example: -WASI_SDK_PATH=`pwd`/wasi-sdk-22.0 WASI_SYSROOT=`pwd`/wasi-sdk-22.0/share/wasi-sysroot WASI_CLANG_WRAPPER_LINKER="`pwd`/wrapper_linker_clang++.sh" ./x.py install +WASI_SDK_PATH=`pwd`/wasi-sdk-22.0 WASI_SYSROOT=`pwd`/wasi-sdk-22.0/share/wasi-sysroot ./x.py install If you just want to run it, https://github.com/oligamiq/rust_wasm/tree/main/rustc_llvm ``` diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index e4fb13822f81e..7fdf6cfa5a891 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -ctrlc = "3.4.4" rustc_ast = { path = "../rustc_ast" } rustc_ast_lowering = { path = "../rustc_ast_lowering" } rustc_ast_passes = { path = "../rustc_ast_passes" } @@ -66,6 +65,9 @@ features = [ "Win32_System_Diagnostics_Debug", ] +[target.'cfg(not(target_family = "wasm"))'.dependencies] +ctrlc = "3.4.4" + [features] # tidy-alphabetical-start llvm = ['rustc_interface/llvm'] diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 1f44621736cdb..b3cba4dbfc20e 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1500,6 +1500,7 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) { /// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`]. /// Making this handler optional lets tools can install a different handler, if they wish. pub fn install_ctrlc_handler() { + #[cfg(not(target_family = "wasm"))] ctrlc::set_handler(move || { // Indicate that we have been signaled to stop. If we were already signaled, exit // immediately. In our interpreter loop we try to consult this value often, but if for diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs index c592b944d44a8..9eb9c8051a319 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs @@ -16,7 +16,7 @@ pub fn target() -> Target { options.add_pre_link_args( LinkerFlavor::WasmLld(Cc::No), - &["--import-memory", "--export-memory", "--shared-memory"], + &["--import-memory", "--export-memory", "--shared-memory", "-Wl,--max-memory=1073741824", "-lwasi-emulated-mman"], ); options.add_pre_link_args( LinkerFlavor::WasmLld(Cc::Yes), @@ -25,6 +25,8 @@ pub fn target() -> Target { "-Wl,--import-memory", "-Wl,--export-memory,", "-Wl,--shared-memory", + "-Wl,--max-memory=1073741824", + "-lwasi-emulated-mman", ], ); diff --git a/config.llvm.toml b/config.llvm.toml index 1cb9588bd3efc..94eaa19cea71c 100644 --- a/config.llvm.toml +++ b/config.llvm.toml @@ -32,9 +32,8 @@ sysconfdir = "etc" [target.'wasm32-wasip1-threads'] wasi-root = "wasi-sdk-22.0/share/wasi-sysroot" -# linker = "wasi-sdk-22.0/bin/wasm-ld" -linker = "./wrapper_linker_clang.sh" # codegen-backends = ["cranelift"] +linker = "wasi-sdk-22.0/bin/clang" codegen-backends = ["llvm"] [target.'x86_64-unknown-linux-gnu'] diff --git a/wrapper_linker_clang.sh b/wrapper_linker_clang.sh deleted file mode 100755 index b77ece82cfd8e..0000000000000 --- a/wrapper_linker_clang.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -# log file -echo "wrapper_linker.sh: $@" >> /tmp/wrapper_linker.log - -# new args -filtered_args=() - -# check args -while [[ $# -gt 0 ]]; do - if [[ $1 == "-flavor" ]]; then - # skip "-flavor" and its argument - shift 2 - continue - fi - #note: wasm-ld: error: unknown argument: -Wl,--max-memory=1073741824 - if [[ $1 == "-Wl,--max-memory=1073741824" ]]; then - # skip "-Wl,--max-memory=1073741824" because it is not supported by wasm-ld - shift 1 - continue - fi - # add arg to new args - filtered_args+=("$1") - shift -done - -# get script directory -DIR=$(cd $(dirname $0); pwd) - -# call wasm-ld with new args -$DIR/wasi-sdk-22.0/bin/wasm-ld -lwasi-emulated-mman "${filtered_args[@]}" - -# return wasm-ld exit code -exit $?