From 2e39be8fde911fcff9b12ac7f18a4df7560c01cc Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 1 Oct 2020 17:00:57 +0900 Subject: [PATCH 1/3] add wasm_abi field in TargeSpec and set generic by default for WASI Signed-off-by: mathetake --- builder/build.go | 5 ++++- compileopts/target.go | 1 + main.go | 2 +- main_test.go | 6 +----- targets/wasi.json | 3 ++- targets/wasm.json | 3 ++- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/builder/build.go b/builder/build.go index 67c09df0ab..2e26b21b11 100644 --- a/builder/build.go +++ b/builder/build.go @@ -79,7 +79,10 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil // keep functions interoperable, pass int64 types as pointers to // stack-allocated values. // Use -wasm-abi=generic to disable this behaviour. - if config.Options.WasmAbi == "js" && strings.HasPrefix(config.Triple(), "wasm") { + if config.Options.WasmAbi != "" { + config.Target.WasmAbi = config.Options.WasmAbi + } + if config.Target.WasmAbi == "js" { err := transform.ExternalInt64AsPtr(mod) if err != nil { return err diff --git a/compileopts/target.go b/compileopts/target.go index f95ecfd88d..96a8543814 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -55,6 +55,7 @@ type TargetSpec struct { JLinkDevice string `json:"jlink-device"` CodeModel string `json:"code-model"` RelocationModel string `json:"relocation-model"` + WasmAbi string `json:"wasm_abi"` } // overrideProperties overrides all properties that are set in child into itself using reflection. diff --git a/main.go b/main.go index 6650196560..5df5f6e986 100644 --- a/main.go +++ b/main.go @@ -816,7 +816,7 @@ func main() { programmer := flag.String("programmer", "", "which hardware programmer to use") cFlags := flag.String("cflags", "", "additional cflags for compiler") ldFlags := flag.String("ldflags", "", "additional ldflags for linker") - wasmAbi := flag.String("wasm-abi", "js", "WebAssembly ABI conventions: js (no i64 params) or generic") + wasmAbi := flag.String("wasm-abi", "", "WebAssembly ABI conventions: js (no i64 params) or generic") heapSize := flag.String("heap-size", "1M", "default heap size in bytes (only supported by WebAssembly)") var flagJSON, flagDeps *bool diff --git a/main_test.go b/main_test.go index ac01baafaa..aecf2da894 100644 --- a/main_test.go +++ b/main_test.go @@ -162,11 +162,7 @@ func runTest(path, target string, t *testing.T) { VerifyIR: true, Debug: true, PrintSizes: "", - WasmAbi: "js", - } - - if target == "wasi" { - config.WasmAbi = "generic" + WasmAbi: "", } binary := filepath.Join(tmpdir, "test") diff --git a/targets/wasi.json b/targets/wasi.json index 97f7848f9b..274acf26a2 100644 --- a/targets/wasi.json +++ b/targets/wasi.json @@ -18,5 +18,6 @@ "--no-demangle", "{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" ], - "emulator": ["wasmtime"] + "emulator": ["wasmtime"], + "wasm_abi": "generic" } diff --git a/targets/wasm.json b/targets/wasm.json index df4d5ee3a4..b9250c708b 100644 --- a/targets/wasm.json +++ b/targets/wasm.json @@ -17,5 +17,6 @@ "--no-demangle", "{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" ], - "emulator": ["node", "targets/wasm_exec.js"] + "emulator": ["node", "targets/wasm_exec.js"], + "wasm_abi": "js" } From 6d87bc63c90907363a6e8c10e49d588c87ac850b Mon Sep 17 00:00:00 2001 From: mathetake Date: Thu, 1 Oct 2020 17:14:08 +0900 Subject: [PATCH 2/3] change wasm_abi -> wasm-abi Signed-off-by: mathetake --- compileopts/target.go | 2 +- targets/wasi.json | 2 +- targets/wasm.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go index 96a8543814..583036e08b 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -55,7 +55,7 @@ type TargetSpec struct { JLinkDevice string `json:"jlink-device"` CodeModel string `json:"code-model"` RelocationModel string `json:"relocation-model"` - WasmAbi string `json:"wasm_abi"` + WasmAbi string `json:"wasm-abi"` } // overrideProperties overrides all properties that are set in child into itself using reflection. diff --git a/targets/wasi.json b/targets/wasi.json index 274acf26a2..521e467d68 100644 --- a/targets/wasi.json +++ b/targets/wasi.json @@ -19,5 +19,5 @@ "{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" ], "emulator": ["wasmtime"], - "wasm_abi": "generic" + "wasm-abi": "generic" } diff --git a/targets/wasm.json b/targets/wasm.json index b9250c708b..7767cd96b4 100644 --- a/targets/wasm.json +++ b/targets/wasm.json @@ -18,5 +18,5 @@ "{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" ], "emulator": ["node", "targets/wasm_exec.js"], - "wasm_abi": "js" + "wasm-abi": "js" } From d61d49c69b4ce0032b527089db852d8984bcf331 Mon Sep 17 00:00:00 2001 From: mathetake Date: Fri, 2 Oct 2020 10:24:17 +0900 Subject: [PATCH 3/3] add getter for wasm-abi in *compileopts.Config Signed-off-by: mathetake --- builder/build.go | 5 +---- compileopts/config.go | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builder/build.go b/builder/build.go index 2e26b21b11..aa9205abc7 100644 --- a/builder/build.go +++ b/builder/build.go @@ -79,10 +79,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil // keep functions interoperable, pass int64 types as pointers to // stack-allocated values. // Use -wasm-abi=generic to disable this behaviour. - if config.Options.WasmAbi != "" { - config.Target.WasmAbi = config.Options.WasmAbi - } - if config.Target.WasmAbi == "js" { + if config.WasmAbi() == "js" { err := transform.ExternalInt64AsPtr(mod) if err != nil { return err diff --git a/compileopts/config.go b/compileopts/config.go index a08a9ba16a..6004f080a3 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -329,6 +329,15 @@ func (c *Config) RelocationModel() string { return "static" } +// WasmAbi returns the WASM ABI which is specified in the target JSON file, and +// the value is overridden by `-wasm-abi` flag if it is provided +func (c *Config) WasmAbi() string { + if c.Options.WasmAbi != "" { + return c.Options.WasmAbi + } + return c.Target.WasmAbi +} + type TestConfig struct { CompileTestBinary bool // TODO: Filter the test functions to run, include verbose flag, etc