From 58618afaee7c14feedad4f115e9a4468bac4c529 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Thu, 31 Aug 2023 17:12:12 +0200 Subject: wasm-linker: correctly pass --shared and --pie When linking a WebAssembly binary using wasm-ld, we will now correctly pass --shared when building a dynamic library and --pie when `-fpic` is given. This is a breaking change and users who currently build dynamic libraries for WebAssembly but wish to have an executable without a main, should use build-exe instead while supplying `-fno-entry`. We also verify the user does not supply --export-memory when -dynamic is enabled. By default we set this flag now to 'false' when `-dynamic` is used to ensure we do not enable it as it's enabled by default for regular WebAssembly binaries. --- src/link/Wasm.zig | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/link') diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 135803007a..ad9f8266f0 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -4548,6 +4548,13 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) ! try argv.append("--no-entry"); } + if (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic) { + try argv.append("--shared"); + } + if (wasm.base.options.pie) { + try argv.append("--pie"); + } + // XXX - TODO: add when wasm-ld supports --build-id. // if (wasm.base.options.build_id) { // try argv.append("--build-id=tree"); -- cgit v1.2.3