| ... | ... | @@ -3406,39 +3406,14 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) ! |
| 3406 | 3406 | try argv.append("--stack-first"); |
| 3407 | 3407 | } |
| 3408 | 3408 | |
| 3409 | | var auto_export_symbols = true; |
| 3410 | 3409 | // Users are allowed to specify which symbols they want to export to the wasm host. |
| 3411 | 3410 | for (wasm.base.options.export_symbol_names) |symbol_name| { |
| 3412 | 3411 | const arg = try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}); |
| 3413 | 3412 | try argv.append(arg); |
| 3414 | | auto_export_symbols = false; |
| 3415 | 3413 | } |
| 3416 | 3414 | |
| 3417 | 3415 | if (wasm.base.options.rdynamic) { |
| 3418 | 3416 | try argv.append("--export-dynamic"); |
| 3419 | | auto_export_symbols = false; |
| 3420 | | } |
| 3421 | | |
| 3422 | | if (auto_export_symbols) { |
| 3423 | | if (wasm.base.options.module) |mod| { |
| 3424 | | // when we use stage1, we use the exports that stage1 provided us. |
| 3425 | | // For stage2, we can directly retrieve them from the module. |
| 3426 | | const skip_export_non_fn = target.os.tag == .wasi and |
| 3427 | | wasm.base.options.wasi_exec_model == .command; |
| 3428 | | for (mod.decl_exports.values()) |exports| { |
| 3429 | | for (exports.items) |exprt| { |
| 3430 | | const exported_decl = mod.declPtr(exprt.exported_decl); |
| 3431 | | if (skip_export_non_fn and exported_decl.ty.zigTypeTag() != .Fn) { |
| 3432 | | // skip exporting symbols when we're building a WASI command |
| 3433 | | // and the symbol is not a function |
| 3434 | | continue; |
| 3435 | | } |
| 3436 | | const symbol_name = exported_decl.name; |
| 3437 | | const arg = try std.fmt.allocPrint(arena, "--export={s}", .{symbol_name}); |
| 3438 | | try argv.append(arg); |
| 3439 | | } |
| 3440 | | } |
| 3441 | | } |
| 3442 | 3417 | } |
| 3443 | 3418 | |
| 3444 | 3419 | if (wasm.base.options.entry) |entry| { |
| ... | ... | @@ -3457,6 +3432,12 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) ! |
| 3457 | 3432 | if (wasm.base.options.wasi_exec_model == .reactor) { |
| 3458 | 3433 | // Reactor execution model does not have _start so lld doesn't look for it. |
| 3459 | 3434 | try argv.append("--no-entry"); |
| 3435 | // Make sure "_initialize" and other used-defined functions are exported if this is WASI reactor. |
| 3436 | // If rdynamic is true, it will already be appended, so only verify if the user did not specify |
| 3437 | // the flag in which case, we ensure `--export-dynamic` is called. |
| 3438 | if (!wasm.base.options.rdynamic) { |
| 3439 | try argv.append("--export-dynamic"); |
| 3440 | } |
| 3460 | 3441 | } |
| 3461 | 3442 | } else if (wasm.base.options.entry == null) { |
| 3462 | 3443 | try argv.append("--no-entry"); // So lld doesn't look for _start. |