| author | |
| committer | |
| log | 58618afaee7c14feedad4f115e9a4468bac4c529 |
| tree | 90a4a16f016817ec171c49b4f5e1b42dc504e0bd |
| parent | 1cb7a01b25349c42dbe207b68f9e19b92890b3d2 |
| signature |
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 | 4548 | try argv.append("--no-entry"); |
| 4549 | 4549 | } |
| 4550 | 4550 | |
| 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 | 4558 | // XXX - TODO: add when wasm-ld supports --build-id. |
| 4552 | 4559 | // if (wasm.base.options.build_id) { |
| 4553 | 4560 | // try argv.append("--build-id=tree"); |
src/main.zig+10| ... | ... | @@ -2627,6 +2627,16 @@ fn buildOutputType( |
| 2627 | 2627 | if (single_threaded == null) { |
| 2628 | 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 | 2640 | if (wasi_exec_model) |model| { |
| 2631 | 2641 | if (model == .reactor) { |
| 2632 | 2642 | if (linker_no_entry != null and !linker_no_entry.?) { |