authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-21 18:20:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-21 18:21:42-07:00
log2cbeb85a96af25f2718a604aa2bec4f76dd85018
treeefc5b9f311f53440d656b006d7c5ecec3a0443f6
parent2e887452d5cd8e912f6bdb36bd0da6faee383465

stage2: error check for mixing --import-table and --export-table

is moved from the linker to the frontend. This is a follow-up from 4cb2f11693b1bf13770b8ad6a8b8a1e37101a516.

3 files changed, 9 insertions(+), 4 deletions(-)

src/Compilation.zig+4
...@@ -852,6 +852,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -852,6 +852,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
852 // WASI-only. Resolve the optional exec-model option, defaults to command.852 // WASI-only. Resolve the optional exec-model option, defaults to command.
853 const wasi_exec_model = if (options.target.os.tag != .wasi) undefined else options.wasi_exec_model orelse .command;853 const wasi_exec_model = if (options.target.os.tag != .wasi) undefined else options.wasi_exec_model orelse .command;
854854
855 if (options.linker_export_table and options.linker_import_table) {
856 return error.ExportTableAndImportTableConflict;
857 }
858
855 const comp: *Compilation = comp: {859 const comp: *Compilation = comp: {
856 // For allocations that have the same lifetime as Compilation. This arena is used only during this860 // For allocations that have the same lifetime as Compilation. This arena is used only during this
857 // initialization and then is freed in deinit().861 // initialization and then is freed in deinit().
src/link/Wasm.zig+2-4
...@@ -1123,14 +1123,12 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -1123,14 +1123,12 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
1123 }1123 }
11241124
1125 if (self.base.options.import_table) {1125 if (self.base.options.import_table) {
1126 if (self.base.options.export_table) {1126 assert(self.base.options.export_table);
1127 log.err("--import-table and --export-table may not be used together", .{});
1128 return error.InvalidArgs;
1129 }
1130 try argv.append("--import-table");1127 try argv.append("--import-table");
1131 }1128 }
11321129
1133 if (self.base.options.export_table) {1130 if (self.base.options.export_table) {
1131 assert(!self.base.options.import_table);
1134 try argv.append("--export-table");1132 try argv.append("--export-table");
1135 }1133 }
11361134
src/main.zig+3
...@@ -2543,6 +2543,9 @@ fn buildOutputType(...@@ -2543,6 +2543,9 @@ fn buildOutputType(
2543 }2543 }
2544 process.exit(1);2544 process.exit(1);
2545 },2545 },
2546 error.ExportTableAndImportTableConflict => {
2547 fatal("--import-table and --export-table may not be used together", .{});
2548 },
2546 else => fatal("unable to create compilation: {s}", .{@errorName(err)}),2549 else => fatal("unable to create compilation: {s}", .{@errorName(err)}),
2547 };2550 };
2548 var comp_destroyed = false;2551 var comp_destroyed = false;