authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-30 17:46:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-30 17:46:10-07:00
log8c9919ec7b409d11ca73ca5764f44282dec0fe25
tree159a7fb087adc240a9b72602d07e3a63f5b121b8
parent205af5b14828d64c10f5c67e05cebf32b882c646

fix regression on wasm targets

The previous commit broke wasm targets because the linking step would look for the compiler-rt lib in the wrong place. Fixed in this commit.

2 files changed, 22 insertions(+), 8 deletions(-)

src/Compilation.zig+7-3
......@@ -981,16 +981,20 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
981981 // Once it is capable this condition should be removed.
982982 if (build_options.is_stage1) {
983983 if (comp.bin_file.options.include_compiler_rt) {
984 if (is_exe_or_dyn_lib) {
984 if (is_exe_or_dyn_lib or comp.getTarget().isWasm()) {
985985 try comp.work_queue.writeItem(.{ .compiler_rt_lib = {} });
986986 } else {
987987 try comp.work_queue.writeItem(.{ .compiler_rt_obj = {} });
988 if (comp.bin_file.options.object_format != .elf) {
988 if (comp.bin_file.options.object_format != .elf and
989 comp.bin_file.options.output_mode == .Obj)
990 {
989991 // For ELF we can rely on using -r to link multiple objects together into one,
990992 // but to truly support `build-obj -fcompiler-rt` will require virtually
991993 // injecting `_ = @import("compiler_rt.zig")` into the root source file of
992994 // the compilation.
993 fatal("Embedding compiler-rt into non-ELF objects is not yet implemented.", .{});
995 fatal("Embedding compiler-rt into {s} objects is not yet implemented.", .{
996 @tagName(comp.bin_file.options.object_format),
997 });
994998 }
995999 }
9961000 }
src/link/Wasm.zig+15-5
......@@ -282,6 +282,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
282282 break :blk full_obj_path;
283283 } else null;
284284
285 const compiler_rt_path: ?[]const u8 = if (self.base.options.include_compiler_rt)
286 comp.compiler_rt_static_lib.?.full_object_path
287 else
288 null;
289
285290 const target = self.base.options.target;
286291
287292 const id_symlink_basename = "lld.id";
......@@ -302,6 +307,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
302307 _ = try man.addFile(entry.key.status.success.object_path, null);
303308 }
304309 try man.addOptionalFile(module_obj_path);
310 try man.addOptionalFile(compiler_rt_path);
305311 man.hash.addOptional(self.base.options.stack_size_override);
306312 man.hash.addListOfBytes(self.base.options.extra_lld_args);
307313
......@@ -381,11 +387,15 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
381387 try argv.append(p);
382388 }
383389
384 if (self.base.options.output_mode != .Obj and !self.base.options.is_compiler_rt_or_libc) {
385 if (!self.base.options.link_libc) {
386 try argv.append(comp.libc_static_lib.?.full_object_path);
387 }
388 try argv.append(comp.compiler_rt_static_lib.?.full_object_path);
390 if (self.base.options.output_mode != .Obj and
391 !self.base.options.is_compiler_rt_or_libc and
392 !self.base.options.link_libc)
393 {
394 try argv.append(comp.libc_static_lib.?.full_object_path);
395 }
396
397 if (compiler_rt_path) |p| {
398 try argv.append(p);
389399 }
390400
391401 if (self.base.options.verbose_link) {