authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-08-31 17:12:12+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-11-03 12:48:52+01:00
log58618afaee7c14feedad4f115e9a4468bac4c529
tree90a4a16f016817ec171c49b4f5e1b42dc504e0bd
parent1cb7a01b25349c42dbe207b68f9e19b92890b3d2
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 17 insertions(+), 0 deletions(-)

src/link/Wasm.zig+7
...@@ -4548,6 +4548,13 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4548,6 +4548,13 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4548 try argv.append("--no-entry");4548 try argv.append("--no-entry");
4549 }4549 }
45504550
4551 if (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic) {
4552 try argv.append("--shared");
4553 }
4554 if (wasm.base.options.pie) {
4555 try argv.append("--pie");
4556 }
4557
4551 // XXX - TODO: add when wasm-ld supports --build-id.4558 // XXX - TODO: add when wasm-ld supports --build-id.
4552 // if (wasm.base.options.build_id) {4559 // if (wasm.base.options.build_id) {
4553 // try argv.append("--build-id=tree");4560 // try argv.append("--build-id=tree");
src/main.zig+10
...@@ -2627,6 +2627,16 @@ fn buildOutputType(...@@ -2627,6 +2627,16 @@ fn buildOutputType(
2627 if (single_threaded == null) {2627 if (single_threaded == null) {
2628 single_threaded = true;2628 single_threaded = true;
2629 }2629 }
2630 if (link_mode) |mode| {
2631 if (mode == .Dynamic) {
2632 if (linker_export_memory != null and linker_export_memory.?) {
2633 fatal("flags '-dynamic' and '--export-memory' are incompatible", .{});
2634 }
2635 // User did not supply `--export-memory` which is incompatible with -dynamic, therefore
2636 // set the flag to false to ensure it does not get enabled by default.
2637 linker_export_memory = false;
2638 }
2639 }
2630 if (wasi_exec_model) |model| {2640 if (wasi_exec_model) |model| {
2631 if (model == .reactor) {2641 if (model == .reactor) {
2632 if (linker_no_entry != null and !linker_no_entry.?) {2642 if (linker_no_entry != null and !linker_no_entry.?) {