From dad1d14ef833bf4b39fd65bc026a3e346fd0a48a Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Thu, 26 May 2022 08:04:54 +0100 Subject: [PATCH] wasm: make host file relocatable --- compiler/build/src/link.rs | 4 ++-- compiler/test_gen/build.rs | 18 +++++++++++++----- repl_wasm/build.rs | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index cd011243da..5b3c31b019 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -1155,7 +1155,7 @@ pub fn preprocess_host_wasm32(host_input_path: &Path, preprocessed_host_path: &P Notes: zig build-obj just gives you back the first input file, doesn't combine them! zig build-lib works but doesn't emit relocations, even with --emit-relocs (bug?) - (gen_wasm needs relocs to adjust stack size by changing the __heap_base constant) + (gen_wasm needs relocs for host-to-app calls and stack size adjustment) zig wasm-ld is a wrapper around wasm-ld and gives us maximum flexiblity (but seems to be an unofficial API) */ @@ -1172,7 +1172,7 @@ pub fn preprocess_host_wasm32(host_input_path: &Path, preprocessed_host_path: &P "--export-all", "--no-entry", "--import-undefined", - // "--relocatable", // enable this when gen_wasm can handle Custom sections in any order + "--relocatable", ]; command.args(args); diff --git a/compiler/test_gen/build.rs b/compiler/test_gen/build.rs index 1f9e9f8f38..480b57b110 100644 --- a/compiler/test_gen/build.rs +++ b/compiler/test_gen/build.rs @@ -45,7 +45,7 @@ fn build_wasm() { &format!("{}/{}.o", out_dir, PLATFORM_FILENAME), "--export-all", "--no-entry", - // "--emit-relocs", // TODO: resize stack by relocating __heap_base (issue #2480) here and in repl_test build + "--relocatable", ]; let zig = zig_executable(); @@ -98,10 +98,18 @@ fn build_wasm_libc_compilerrt(out_dir: &str, source_path: &str) -> (String, Stri ], ); - ( - run_command("find", &[&zig_cache_dir, "-name", "libc.a"]), - run_command("find", &[&zig_cache_dir, "-name", "compiler_rt.o"]), - ) + let libc_path = run_command("find", &[&zig_cache_dir, "-name", "libc.a"]) + .split('\n') + .next() + .unwrap() + .into(); + let compiler_rt_path = run_command("find", &[&zig_cache_dir, "-name", "compiler_rt.o"]) + .split('\n') + .next() + .unwrap() + .into(); + + (libc_path, compiler_rt_path) } fn feature_is_enabled(feature_name: &str) -> bool { diff --git a/repl_wasm/build.rs b/repl_wasm/build.rs index 832a1b7c56..492f6e15a1 100644 --- a/repl_wasm/build.rs +++ b/repl_wasm/build.rs @@ -40,6 +40,7 @@ fn main() { PRE_LINKED_BINARY, "--export-all", "--no-entry", + "--relocatable", ]; let zig = zig_executable();