Skip to content

std: Remove the wasm_syscall feature #63979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,6 @@
# This is the name of the directory in which codegen backends will get installed
#codegen-backends-dir = "codegen-backends"

# Flag indicating whether `libstd` calls an imported function to handle basic IO
# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown`
# target, as without this option the test output will not be captured.
#wasm-syscall = false

# Indicates whether LLD will be compiled and made available in the sysroot for
# rustc to execute.
#lld = false
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ pub struct Config {

// libstd features
pub backtrace: bool, // support for RUST_BACKTRACE
pub wasm_syscall: bool,

// misc
pub low_priority: bool,
Expand Down Expand Up @@ -318,7 +317,6 @@ struct Rust {
save_toolstates: Option<String>,
codegen_backends: Option<Vec<String>>,
codegen_backends_dir: Option<String>,
wasm_syscall: Option<bool>,
lld: Option<bool>,
lldb: Option<bool>,
llvm_tools: Option<bool>,
Expand Down Expand Up @@ -558,7 +556,6 @@ impl Config {
if let Some(true) = rust.incremental {
config.incremental = true;
}
set(&mut config.wasm_syscall, rust.wasm_syscall);
set(&mut config.lld_enabled, rust.lld);
set(&mut config.lldb_enabled, rust.lldb);
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ impl Build {
if self.config.profiler {
features.push_str(" profiler");
}
if self.config.wasm_syscall {
features.push_str(" wasm_syscall");
}
features
}

Expand Down
10 changes: 0 additions & 10 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,16 +1811,6 @@ impl Step for Crate {
.expect("nodejs not configured"),
);
} else if target.starts_with("wasm32") {
// Warn about running tests without the `wasm_syscall` feature enabled.
// The javascript shim implements the syscall interface so that test
// output can be correctly reported.
if !builder.config.wasm_syscall {
builder.info(
"Libstd was built without `wasm_syscall` feature enabled: \
test output may not be visible."
);
}

// On the wasm32-unknown-unknown target we're using LTO which is
// incompatible with `-C prefer-dynamic`, so disable that here
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
Expand Down
108 changes: 1 addition & 107 deletions src/etc/wasm32-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,113 +15,7 @@ const buffer = fs.readFileSync(process.argv[2]);
Error.stackTraceLimit = 20;

let m = new WebAssembly.Module(buffer);

let memory = null;

function viewstruct(data, fields) {
return new Uint32Array(memory.buffer).subarray(data/4, data/4 + fields);
}

function copystr(a, b) {
let view = new Uint8Array(memory.buffer).subarray(a, a + b);
return String.fromCharCode.apply(null, view);
}

function syscall_write([fd, ptr, len]) {
let s = copystr(ptr, len);
switch (fd) {
case 1: process.stdout.write(s); break;
case 2: process.stderr.write(s); break;
}
}

function syscall_exit([code]) {
process.exit(code);
}

function syscall_args(params) {
let [ptr, len] = params;

// Calculate total required buffer size
let totalLen = -1;
for (let i = 2; i < process.argv.length; ++i) {
totalLen += Buffer.byteLength(process.argv[i]) + 1;
}
if (totalLen < 0) { totalLen = 0; }
params[2] = totalLen;

// If buffer is large enough, copy data
if (len >= totalLen) {
let view = new Uint8Array(memory.buffer);
for (let i = 2; i < process.argv.length; ++i) {
let value = process.argv[i];
Buffer.from(value).copy(view, ptr);
ptr += Buffer.byteLength(process.argv[i]) + 1;
}
}
}

function syscall_getenv(params) {
let [keyPtr, keyLen, valuePtr, valueLen] = params;

let key = copystr(keyPtr, keyLen);
let value = process.env[key];

if (value == null) {
params[4] = 0xFFFFFFFF;
} else {
let view = new Uint8Array(memory.buffer);
let totalLen = Buffer.byteLength(value);
params[4] = totalLen;
if (valueLen >= totalLen) {
Buffer.from(value).copy(view, valuePtr);
}
}
}

function syscall_time(params) {
let t = Date.now();
let secs = Math.floor(t / 1000);
let millis = t % 1000;
params[1] = Math.floor(secs / 0x100000000);
params[2] = secs % 0x100000000;
params[3] = Math.floor(millis * 1000000);
}

let imports = {};
imports.env = {
// These are generated by LLVM itself for various intrinsic calls. Hopefully
// one day this is not necessary and something will automatically do this.
fmod: function(x, y) { return x % y; },
exp2: function(x) { return Math.pow(2, x); },
exp2f: function(x) { return Math.pow(2, x); },
ldexp: function(x, y) { return x * Math.pow(2, y); },
ldexpf: function(x, y) { return x * Math.pow(2, y); },
sin: Math.sin,
sinf: Math.sin,
cos: Math.cos,
cosf: Math.cos,
log: Math.log,
log2: Math.log2,
log10: Math.log10,
log10f: Math.log10,

rust_wasm_syscall: function(index, data) {
switch (index) {
case 1: syscall_write(viewstruct(data, 3)); return true;
case 2: syscall_exit(viewstruct(data, 1)); return true;
case 3: syscall_args(viewstruct(data, 3)); return true;
case 4: syscall_getenv(viewstruct(data, 5)); return true;
case 6: syscall_time(viewstruct(data, 4)); return true;
default:
console.log("Unsupported syscall: " + index);
return false;
}
}
};

let instance = new WebAssembly.Instance(m, imports);
memory = instance.exports.memory;
let instance = new WebAssembly.Instance(m, {});
try {
instance.exports.main();
} catch (e) {
Expand Down
5 changes: 0 additions & 5 deletions src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ llvm-libunwind = ["unwind/llvm-libunwind"]
# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = ["core/panic_immediate_abort"]

# An off-by-default feature which enables a linux-syscall-like ABI for libstd to
# interoperate with the host environment. Currently not well documented and
# requires rebuilding the standard library to use it.
wasm_syscall = []

# Enable std_detect default features for stdarch/crates/std_detect:
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
std_detect_file_io = []
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/sys/wasm/args.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::ffi::OsString;
use crate::marker::PhantomData;
use crate::vec;
use crate::sys::ArgsSysCall;

pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
// On wasm these should always be null, so there's nothing for us to do here
Expand All @@ -11,9 +10,8 @@ pub unsafe fn cleanup() {
}

pub fn args() -> Args {
let v = ArgsSysCall::perform();
Args {
iter: v.into_iter(),
iter: Vec::new().into_iter(),
_dont_send_or_sync_me: PhantomData,
}
}
Expand Down
Loading