authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-09 10:23:46+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-09 11:11:55+02:00
log9f8de83d931f1f59ffa7010afc52a1bd54778447
tree177ff2d1a4a011a47b320f6726bf9ddfd47a9005
parentbf568ec62a06fcea5f09c725529635425f1b8a76

cc,wasi: use wasi_libc.CRTFile directly instead of WasiExecModel


5 files changed, 20 insertions(+), 24 deletions(-)

src/Compilation.zig+2-13
...@@ -603,11 +603,6 @@ pub const ClangPreprocessorMode = enum {...@@ -603,11 +603,6 @@ pub const ClangPreprocessorMode = enum {
603 stdout,603 stdout,
604};604};
605605
606pub const WasiExecModel = enum {
607 command,
608 reactor,
609};
610
611pub const InitOptions = struct {606pub const InitOptions = struct {
612 zig_lib_directory: Directory,607 zig_lib_directory: Directory,
613 local_cache_directory: Directory,608 local_cache_directory: Directory,
...@@ -731,7 +726,7 @@ pub const InitOptions = struct {...@@ -731,7 +726,7 @@ pub const InitOptions = struct {
731 test_name_prefix: ?[]const u8 = null,726 test_name_prefix: ?[]const u8 = null,
732 subsystem: ?std.Target.SubSystem = null,727 subsystem: ?std.Target.SubSystem = null,
733 /// WASI-only. Type of WASI execution model ("command" or "reactor").728 /// WASI-only. Type of WASI execution model ("command" or "reactor").
734 wasi_exec_model: ?WasiExecModel = null,729 wasi_exec_model: ?wasi_libc.CRTFile = null,
735};730};
736731
737fn addPackageTableToCacheHash(732fn addPackageTableToCacheHash(
...@@ -1449,14 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1449,14 +1444,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1449 .wasi_libc_crt_file = crt_file,1444 .wasi_libc_crt_file = crt_file,
1450 });1445 });
1451 }1446 }
1452 const crt_file: wasi_libc.CRTFile = if (comp.bin_file.options.wasi_exec_model) |exec_model| crt_file: {
1453 switch (exec_model) {
1454 .command => break :crt_file wasi_libc.CRTFile.crt1_command_o,
1455 .reactor => break :crt_file wasi_libc.CRTFile.crt1_reactor_o,
1456 }
1457 } else .crt1_o;
1458 comp.work_queue.writeAssumeCapacity(&[_]Job{1447 comp.work_queue.writeAssumeCapacity(&[_]Job{
1459 .{ .wasi_libc_crt_file = crt_file },1448 .{ .wasi_libc_crt_file = comp.bin_file.options.wasi_exec_model orelse .crt1_o },
1460 .{ .wasi_libc_crt_file = .libc_a },1449 .{ .wasi_libc_crt_file = .libc_a },
1461 });1450 });
1462 }1451 }
src/link.zig+1-1
...@@ -119,7 +119,7 @@ pub const Options = struct {...@@ -119,7 +119,7 @@ pub const Options = struct {
119 libc_installation: ?*const LibCInstallation,119 libc_installation: ?*const LibCInstallation,
120120
121 /// WASI-only. Type of WASI execution model ("command" or "reactor").121 /// WASI-only. Type of WASI execution model ("command" or "reactor").
122 wasi_exec_model: ?Compilation.WasiExecModel = null,122 wasi_exec_model: ?wasi_libc.CRTFile = null,
123123
124 pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode {124 pub fn effectiveOutputMode(options: Options) std.builtin.OutputMode {
125 return if (options.use_lld) .Obj else options.output_mode;125 return if (options.use_lld) .Obj else options.output_mode;
src/link/Wasm.zig+5-7
...@@ -684,7 +684,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -684,7 +684,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
684684
685 // Reactor execution model does not have _start so lld doesn't look for it.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: {686 if (self.base.options.wasi_exec_model) |exec_model| blk: {
687 if (exec_model != .reactor) break :blk;687 if (exec_model != .crt1_reactor_o) break :blk;
688 try argv.append("--no-entry");688 try argv.append("--no-entry");
689 }689 }
690 } else {690 } else {
...@@ -698,12 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -698,12 +698,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
698 });698 });
699699
700 if (target.os.tag == .wasi) {700 if (target.os.tag == .wasi) {
701 const crt_name = if (self.base.options.wasi_exec_model) |exec_model|
702 try std.fmt.allocPrint(arena, "crt1-{s}.o", .{@tagName(exec_model)})
703 else
704 "crt1.o";
705 try argv.append(try comp.get_libc_crt_file(arena, crt_name));
706
707 const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or701 const is_exe_or_dyn_lib = self.base.options.output_mode == .Exe or
708 (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);
709 if (is_exe_or_dyn_lib) {703 if (is_exe_or_dyn_lib) {
...@@ -727,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -727,6 +721,10 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
727 }721 }
728722
729 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 ));
730 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"));
731 }729 }
732 }730 }
src/main.zig+3-3
...@@ -613,7 +613,7 @@ fn buildOutputType(...@@ -613,7 +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: ?Compilation.WasiExecModel = null;616 var wasi_exec_model: ?wasi_libc.CRTFile = null;
617617
618 var system_libs = std.ArrayList([]const u8).init(gpa);618 var system_libs = std.ArrayList([]const u8).init(gpa);
619 defer system_libs.deinit();619 defer system_libs.deinit();
...@@ -1257,9 +1257,9 @@ fn buildOutputType(...@@ -1257,9 +1257,9 @@ fn buildOutputType(
1257 .strip => strip = true,1257 .strip => strip = true,
1258 .exec_model => {1258 .exec_model => {
1259 if (std.mem.eql(u8, it.only_arg, "reactor")) {1259 if (std.mem.eql(u8, it.only_arg, "reactor")) {
1260 wasi_exec_model = Compilation.WasiExecModel.reactor;1260 wasi_exec_model = .crt1_reactor_o;
1261 } else if (std.mem.eql(u8, it.only_arg, "command")) {1261 } else if (std.mem.eql(u8, it.only_arg, "command")) {
1262 wasi_exec_model = Compilation.WasiExecModel.command;1262 wasi_exec_model = .crt1_command_o;
1263 }1263 }
1264 },1264 },
1265 }1265 }
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}
4747
48pub 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
48pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {57pub 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;