| author | |
| committer | |
| log | 5fa5fba3ce57b128b37b371eb3daa8ca39221613 |
| tree | 177ff2d1a4a011a47b320f6726bf9ddfd47a9005 |
| parent | a6ae5a77dac6466617cdf57357aa79c2b79403b3 |
| parent | 9f8de83d931f1f59ffa7010afc52a1bd54778447 |
7 files changed, 49 insertions(+), 9 deletions(-)
src/Compilation.zig+5-3| ... | @@ -725,6 +725,8 @@ pub const InitOptions = struct { | ... | @@ -725,6 +725,8 @@ pub const InitOptions = struct { |
| 725 | test_filter: ?[]const u8 = null, | 725 | test_filter: ?[]const u8 = null, |
| 726 | test_name_prefix: ?[]const u8 = null, | 726 | test_name_prefix: ?[]const u8 = null, |
| 727 | subsystem: ?std.Target.SubSystem = null, | 727 | subsystem: ?std.Target.SubSystem = null, |
| 728 | /// WASI-only. Type of WASI execution model ("command" or "reactor"). | ||
| 729 | wasi_exec_model: ?wasi_libc.CRTFile = null, | ||
| 728 | }; | 730 | }; |
| 729 | 731 | ||
| 730 | fn addPackageTableToCacheHash( | 732 | fn addPackageTableToCacheHash( |
| ... | @@ -1340,6 +1342,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1340,6 +1342,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1340 | .disable_lld_caching = options.disable_lld_caching, | 1342 | .disable_lld_caching = options.disable_lld_caching, |
| 1341 | .subsystem = options.subsystem, | 1343 | .subsystem = options.subsystem, |
| 1342 | .is_test = options.is_test, | 1344 | .is_test = options.is_test, |
| 1345 | .wasi_exec_model = options.wasi_exec_model, | ||
| 1343 | }); | 1346 | }); |
| 1344 | errdefer bin_file.destroy(); | 1347 | errdefer bin_file.destroy(); |
| 1345 | comp.* = .{ | 1348 | comp.* = .{ |
| ... | @@ -1441,9 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1441,9 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1441 | .wasi_libc_crt_file = crt_file, | 1444 | .wasi_libc_crt_file = crt_file, |
| 1442 | }); | 1445 | }); |
| 1443 | } | 1446 | } |
| 1444 | // TODO add logic deciding which crt1 we want here. | ||
| 1445 | comp.work_queue.writeAssumeCapacity(&[_]Job{ | 1447 | comp.work_queue.writeAssumeCapacity(&[_]Job{ |
| 1446 | .{ .wasi_libc_crt_file = .crt1_o }, | 1448 | .{ .wasi_libc_crt_file = comp.bin_file.options.wasi_exec_model orelse .crt1_o }, |
| 1447 | .{ .wasi_libc_crt_file = .libc_a }, | 1449 | .{ .wasi_libc_crt_file = .libc_a }, |
| 1448 | }); | 1450 | }); |
| 1449 | } | 1451 | } |
| ... | @@ -1868,7 +1870,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -1868,7 +1870,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 1868 | 1870 | ||
| 1869 | for (keys[1..]) |key, i| { | 1871 | for (keys[1..]) |key, i| { |
| 1870 | err_msg.notes[i] = .{ | 1872 | err_msg.notes[i] = .{ |
| 1871 | .src_loc = key.nodeOffsetSrcLoc(values[i+1]), | 1873 | .src_loc = key.nodeOffsetSrcLoc(values[i + 1]), |
| 1872 | .msg = "also here", | 1874 | .msg = "also here", |
| 1873 | }; | 1875 | }; |
| 1874 | } | 1876 | } |
src/clang_options_data.zig+8-1| ... | @@ -5257,7 +5257,14 @@ jspd1("fxray-modes="), | ... | @@ -5257,7 +5257,14 @@ jspd1("fxray-modes="), |
| 5257 | .psl = false, | 5257 | .psl = false, |
| 5258 | }, | 5258 | }, |
| 5259 | jspd1("iwithsysroot"), | 5259 | jspd1("iwithsysroot"), |
| 5260 | joinpd1("mexec-model="), | 5260 | .{ |
| 5261 | .name = "mexec-model=", | ||
| 5262 | .syntax = .joined, | ||
| 5263 | .zig_equivalent = .exec_model, | ||
| 5264 | .pd1 = true, | ||
| 5265 | .pd2 = false, | ||
| 5266 | .psl = false, | ||
| 5267 | }, | ||
| 5261 | joinpd1("mharden-sls="), | 5268 | joinpd1("mharden-sls="), |
| 5262 | joinpd1("mhvx-length="), | 5269 | joinpd1("mhvx-length="), |
| 5263 | jspd1("objc-isystem"), | 5270 | jspd1("objc-isystem"), |
src/link.zig+3| ... | @@ -118,6 +118,9 @@ pub const Options = struct { | ... | @@ -118,6 +118,9 @@ pub const Options = struct { |
| 118 | version: ?std.builtin.Version, | 118 | version: ?std.builtin.Version, |
| 119 | libc_installation: ?*const LibCInstallation, | 119 | libc_installation: ?*const LibCInstallation, |
| 120 | 120 | ||
| 121 | /// WASI-only. Type of WASI execution model ("command" or "reactor"). | ||
| 122 | wasi_exec_model: ?wasi_libc.CRTFile = null, | ||
| 123 | |||
| 121 | pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode { | 124 | pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode { |
| 122 | return if (options.use_lld) .Obj else options.output_mode; | 125 | return if (options.use_lld) .Obj else options.output_mode; |
| 123 | } | 126 | } |
src/link/Wasm.zig+10-5| ... | @@ -681,6 +681,12 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -681,6 +681,12 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 681 | // Put stack before globals so that stack overflow results in segfault immediately | 681 | // Put stack before globals so that stack overflow results in segfault immediately |
| 682 | // before corrupting globals. See https://github.com/ziglang/zig/issues/4496 | 682 | // before corrupting globals. See https://github.com/ziglang/zig/issues/4496 |
| 683 | try argv.append("--stack-first"); | 683 | try argv.append("--stack-first"); |
| 684 | |||
| 685 | // Reactor execution model does not have _start so lld doesn't look for it. | ||
| 686 | if (self.base.options.wasi_exec_model) |exec_model| blk: { | ||
| 687 | if (exec_model != .crt1_reactor_o) break :blk; | ||
| 688 | try argv.append("--no-entry"); | ||
| 689 | } | ||
| 684 | } else { | 690 | } else { |
| 685 | try argv.append("--no-entry"); // So lld doesn't look for _start. | 691 | try argv.append("--no-entry"); // So lld doesn't look for _start. |
| 686 | try argv.append("--export-all"); | 692 | try argv.append("--export-all"); |
| ... | @@ -692,11 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -692,11 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 692 | }); | 698 | }); |
| 693 | 699 | ||
| 694 | if (target.os.tag == .wasi) { | 700 | if (target.os.tag == .wasi) { |
| 695 | if (self.base.options.link_libc and self.base.options.output_mode == .Exe) { | ||
| 696 | // TODO work out if we want standard crt, a reactor or a command | ||
| 697 | try argv.append(try comp.get_libc_crt_file(arena, "crt1.o")); | ||
| 698 | } | ||
| 699 | |||
| 700 | const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or | 701 | const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or |
| 701 | (self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic); | 702 | (self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic); |
| 702 | if (is_exe_or_dyn_lib) { | 703 | if (is_exe_or_dyn_lib) { |
| ... | @@ -720,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -720,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 720 | } | 721 | } |
| 721 | 722 | ||
| 722 | if (self.base.options.link_libc) { | 723 | if (self.base.options.link_libc) { |
| 724 | try argv.append(try comp.get_libc_crt_file( | ||
| 725 | arena, | ||
| 726 | wasi_libc.crtFileFullName(self.base.options.wasi_exec_model orelse .crt1_o), | ||
| 727 | )); | ||
| 723 | try argv.append(try comp.get_libc_crt_file(arena, "libc.a")); | 728 | try argv.append(try comp.get_libc_crt_file(arena, "libc.a")); |
| 724 | } | 729 | } |
| 725 | } | 730 | } |
src/main.zig+10| ... | @@ -613,6 +613,7 @@ fn buildOutputType( | ... | @@ -613,6 +613,7 @@ fn buildOutputType( |
| 613 | var subsystem: ?std.Target.SubSystem = null; | 613 | var subsystem: ?std.Target.SubSystem = null; |
| 614 | var major_subsystem_version: ?u32 = null; | 614 | var major_subsystem_version: ?u32 = null; |
| 615 | var minor_subsystem_version: ?u32 = null; | 615 | var minor_subsystem_version: ?u32 = null; |
| 616 | var wasi_exec_model: ?wasi_libc.CRTFile = null; | ||
| 616 | 617 | ||
| 617 | var system_libs = std.ArrayList([]const u8).init(gpa); | 618 | var system_libs = std.ArrayList([]const u8).init(gpa); |
| 618 | defer system_libs.deinit(); | 619 | defer system_libs.deinit(); |
| ... | @@ -1254,6 +1255,13 @@ fn buildOutputType( | ... | @@ -1254,6 +1255,13 @@ fn buildOutputType( |
| 1254 | .framework => try frameworks.append(it.only_arg), | 1255 | .framework => try frameworks.append(it.only_arg), |
| 1255 | .nostdlibinc => want_native_include_dirs = false, | 1256 | .nostdlibinc => want_native_include_dirs = false, |
| 1256 | .strip => strip = true, | 1257 | .strip => strip = true, |
| 1258 | .exec_model => { | ||
| 1259 | if (std.mem.eql(u8, it.only_arg, "reactor")) { | ||
| 1260 | wasi_exec_model = .crt1_reactor_o; | ||
| 1261 | } else if (std.mem.eql(u8, it.only_arg, "command")) { | ||
| 1262 | wasi_exec_model = .crt1_command_o; | ||
| 1263 | } | ||
| 1264 | }, | ||
| 1257 | } | 1265 | } |
| 1258 | } | 1266 | } |
| 1259 | // Parse linker args. | 1267 | // Parse linker args. |
| ... | @@ -1969,6 +1977,7 @@ fn buildOutputType( | ... | @@ -1969,6 +1977,7 @@ fn buildOutputType( |
| 1969 | .test_name_prefix = test_name_prefix, | 1977 | .test_name_prefix = test_name_prefix, |
| 1970 | .disable_lld_caching = !have_enable_cache, | 1978 | .disable_lld_caching = !have_enable_cache, |
| 1971 | .subsystem = subsystem, | 1979 | .subsystem = subsystem, |
| 1980 | .wasi_exec_model = wasi_exec_model, | ||
| 1972 | }) catch |err| { | 1981 | }) catch |err| { |
| 1973 | fatal("unable to create compilation: {s}", .{@errorName(err)}); | 1982 | fatal("unable to create compilation: {s}", .{@errorName(err)}); |
| 1974 | }; | 1983 | }; |
| ... | @@ -3341,6 +3350,7 @@ pub const ClangArgIterator = struct { | ... | @@ -3341,6 +3350,7 @@ pub const ClangArgIterator = struct { |
| 3341 | red_zone, | 3350 | red_zone, |
| 3342 | no_red_zone, | 3351 | no_red_zone, |
| 3343 | strip, | 3352 | strip, |
| 3353 | exec_model, | ||
| 3344 | }; | 3354 | }; |
| 3345 | 3355 | ||
| 3346 | const Args = struct { | 3356 | const Args = struct { |
src/wasi_libc.zig+9| ... | @@ -45,6 +45,15 @@ pub fn emulatedLibCRFileLibName(crt_file: CRTFile) []const u8 { | ... | @@ -45,6 +45,15 @@ pub fn emulatedLibCRFileLibName(crt_file: CRTFile) []const u8 { |
| 45 | }; | 45 | }; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | pub fn crtFileFullName(crt_file: CRTFile) []const u8 { | ||
| 49 | return switch (crt_file) { | ||
| 50 | .crt1_o => "crt1.o", | ||
| 51 | .crt1_reactor_o => "crt1-reactor.o", | ||
| 52 | .crt1_command_o => "crt1-command.o", | ||
| 53 | else => unreachable, | ||
| 54 | }; | ||
| 55 | } | ||
| 56 | |||
| 48 | pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | 57 | pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 49 | if (!build_options.have_llvm) { | 58 | if (!build_options.have_llvm) { |
| 50 | return error.ZigCompilerNotBuiltWithLLVMExtensions; | 59 | return error.ZigCompilerNotBuiltWithLLVMExtensions; |
tools/update_clang_options.zig+4| ... | @@ -336,6 +336,10 @@ const known_options = [_]KnownOpt{ | ... | @@ -336,6 +336,10 @@ const known_options = [_]KnownOpt{ |
| 336 | .name = "dynamiclib", | 336 | .name = "dynamiclib", |
| 337 | .ident = "shared", | 337 | .ident = "shared", |
| 338 | }, | 338 | }, |
| 339 | .{ | ||
| 340 | .name = "mexec-model", | ||
| 341 | .ident = "exec_model", | ||
| 342 | } | ||
| 339 | }; | 343 | }; |
| 340 | 344 | ||
| 341 | const blacklisted_options = [_][]const u8{}; | 345 | const blacklisted_options = [_][]const u8{}; |