Skip to content

Commit 8dd6e63

Browse files
bors[bot]Mark McCaskeyxmclark
committed
Merge #328
328: fix master; add some emscripten calls r=MarkMcCaskey a=MarkMcCaskey notified by #327 ; that program when compiled now outputs `"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"` ; which may have been broken by #326 Co-authored-by: Mark McCaskey <mark@wasmer.io> Co-authored-by: Mackenzie Clark <mackenzie.a.z.c@gmail.com>
2 parents d9114e4 + 221e909 commit 8dd6e63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+271
-89
lines changed

Cargo.lock

+56-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/emscripten/a.txt

Whitespace-only changes.

lib/emscripten/build/emtests.rs

+36-20
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,42 @@ pub fn compile(file: &str, ignores: &Vec<String>) -> Option<String> {
4646
output_path.set_extension("js");
4747
let output_str = output_path.to_str().unwrap();
4848

49-
// Compile to wasm
50-
let _wasm_compilation = Command::new("emcc")
51-
.arg(file)
52-
.arg("-s")
53-
.arg("WASM=1")
54-
.arg("-o")
55-
.arg(output_str)
56-
.output()
57-
.expect("failed to execute process");
58-
59-
// panic!("{:?}", wasm_compilation);
60-
// if output.stderr {
61-
// panic!("{}", output.stderr);
62-
// }
63-
// Remove js file
64-
65-
if Path::new(output_str).is_file() {
66-
fs::remove_file(output_str).unwrap();
67-
} else {
68-
println!("Output JS not found: {}", output_str);
49+
let wasm_file_metadata = {
50+
let mut wasm_file_path = PathBuf::from(file);
51+
wasm_file_path.set_extension("wasm");
52+
if let Ok(wasm_file) = File::open(wasm_file_path) {
53+
Some(wasm_file.metadata().unwrap())
54+
} else {
55+
None
56+
}
57+
};
58+
59+
let real_file = File::open(file).unwrap();
60+
let file_metadata = real_file.metadata().unwrap();
61+
if wasm_file_metadata.is_none()
62+
|| file_metadata.modified().unwrap() >= wasm_file_metadata.unwrap().modified().unwrap()
63+
{
64+
// Compile to wasm
65+
let _wasm_compilation = Command::new("emcc")
66+
.arg(file)
67+
.arg("-s")
68+
.arg("WASM=1")
69+
.arg("-o")
70+
.arg(output_str)
71+
.output()
72+
.expect("failed to execute process");
73+
74+
// panic!("{:?}", wasm_compilation);
75+
// if output.stderr {
76+
// panic!("{}", output.stderr);
77+
// }
78+
// Remove js file
79+
80+
if Path::new(output_str).is_file() {
81+
fs::remove_file(output_str).unwrap();
82+
} else {
83+
println!("Output JS not found: {}", output_str);
84+
}
6985
}
7086

7187
let mut output_path = PathBuf::from(file);

lib/emscripten/emtests/hello.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <iostream>
2+
int main() {
3+
std::cout << "hello world\n";
4+
}

lib/emscripten/emtests/hello.out

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hello world
2+

lib/emscripten/emtests/hello.wasm

311 KB
Binary file not shown.

lib/emscripten/emtests/ignores.txt

+44-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,47 @@ test_wprintf
7171
test_std_cout_new
7272
test_strptime_reentrant
7373
test_gmtime
74-
test_time_c
74+
test_time_c
75+
test_execvp
76+
test_nl_types
77+
test_phiundef
78+
test_pipe
79+
test_printf_2
80+
test_printf_more
81+
test_regex
82+
test_relocatable_void_function
83+
test_rounding
84+
test_set_align
85+
test_sintvars
86+
test_sizeof
87+
test_sscanf
88+
test_sscanf_3
89+
test_sscanf_4
90+
test_sscanf_5
91+
test_sscanf_6
92+
test_sscanf_caps
93+
test_sscanf_float
94+
test_sscanf_n
95+
test_strcasecmp
96+
test_strcmp_uni
97+
test_strndup
98+
test_strstr
99+
test_strtod
100+
test_strtok
101+
test_strtol_bin
102+
test_strtol_dec
103+
test_strtol_hex
104+
test_strtol_oct
105+
test_strtoll_bin
106+
test_strtoll_dec
107+
test_strtoll_hex
108+
test_strtoll_oct
109+
test_struct_varargs
110+
test_transtrcase
111+
test_trickystring
112+
test_unary_literal
113+
test_vfs
114+
test_vprintf
115+
test_vsnprintf
116+
test_write_stdout_fileno
117+
test_zerodiv

lib/emscripten/foo.txt

Whitespace-only changes.

lib/emscripten/src/exception.rs

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 {
2323
pub fn ___cxa_end_catch(_ctx: &mut Ctx) {
2424
debug!("emscripten::___cxa_end_catch");
2525
}
26+
27+
pub fn ___cxa_uncaught_exception(_ctx: &mut Ctx) -> i32 {
28+
debug!("emscripten::___cxa_uncaught_exception");
29+
-1
30+
}

lib/emscripten/src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ pub fn run_emscripten_instance(
247247
let data_ptr = &mut data as *mut _ as *mut c_void;
248248
instance.context_mut().data = data_ptr;
249249

250+
// ATINIT
251+
// (used by C++)
252+
if let Ok(_func) = instance.dyn_func("globalCtors") {
253+
instance.call("globalCtors", &[])?;
254+
}
255+
250256
if let Ok(_func) = instance.dyn_func("___emscripten_environ_constructor") {
251257
instance.call("___emscripten_environ_constructor", &[])?;
252258
}
@@ -269,7 +275,7 @@ pub fn run_emscripten_instance(
269275
),
270276
};
271277

272-
// TODO atinit and atexit for emscripten
278+
// TODO atexit for emscripten
273279
// println!("{:?}", data);
274280
Ok(())
275281
}
@@ -607,6 +613,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
607613
"___cxa_throw" => func!(crate::exception::___cxa_throw),
608614
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
609615
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
616+
"___cxa_uncaught_exception" => func!(crate::exception::___cxa_uncaught_exception),
610617

611618
// Time
612619
"_gettimeofday" => func!(crate::time::_gettimeofday),
@@ -619,6 +626,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
619626
"_localtime" => func!(crate::time::_localtime),
620627
"_time" => func!(crate::time::_time),
621628
"_strftime" => func!(crate::time::_strftime),
629+
"_strftime_l" => func!(crate::time::_strftime_l),
622630
"_localtime_r" => func!(crate::time::_localtime_r),
623631
"_gmtime_r" => func!(crate::time::_gmtime_r),
624632
"_mktime" => func!(crate::time::_mktime),

lib/emscripten/src/time.rs

+17
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,20 @@ pub fn _strftime(
310310
);
311311
0
312312
}
313+
314+
/// emscripten: _strftime_l
315+
pub fn _strftime_l(
316+
ctx: &mut Ctx,
317+
s_ptr: c_int,
318+
maxsize: u32,
319+
format_ptr: c_int,
320+
tm_ptr: c_int,
321+
_last: c_int,
322+
) -> i32 {
323+
debug!(
324+
"emscripten::_strftime_l {} {} {} {}",
325+
s_ptr, maxsize, format_ptr, tm_ptr
326+
);
327+
328+
_strftime(ctx, s_ptr, maxsize, format_ptr, tm_ptr)
329+
}

0 commit comments

Comments
 (0)