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 {...@@ -981,16 +981,20 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
981 // Once it is capable this condition should be removed.981 // Once it is capable this condition should be removed.
982 if (build_options.is_stage1) {982 if (build_options.is_stage1) {
983 if (comp.bin_file.options.include_compiler_rt) {983 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()) {
985 try comp.work_queue.writeItem(.{ .compiler_rt_lib = {} });985 try comp.work_queue.writeItem(.{ .compiler_rt_lib = {} });
986 } else {986 } else {
987 try comp.work_queue.writeItem(.{ .compiler_rt_obj = {} });987 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 {
989 // For ELF we can rely on using -r to link multiple objects together into one,991 // For ELF we can rely on using -r to link multiple objects together into one,
990 // but to truly support `build-obj -fcompiler-rt` will require virtually992 // but to truly support `build-obj -fcompiler-rt` will require virtually
991 // injecting `_ = @import("compiler_rt.zig")` into the root source file of993 // injecting `_ = @import("compiler_rt.zig")` into the root source file of
992 // the compilation.994 // 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 });
994 }998 }
995 }999 }
996 }1000 }
src/link/Wasm.zig+15-5
...@@ -282,6 +282,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -282,6 +282,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
282 break :blk full_obj_path;282 break :blk full_obj_path;
283 } else null;283 } 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
285 const target = self.base.options.target;290 const target = self.base.options.target;
286291
287 const id_symlink_basename = "lld.id";292 const id_symlink_basename = "lld.id";
...@@ -302,6 +307,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -302,6 +307,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
302 _ = try man.addFile(entry.key.status.success.object_path, null);307 _ = try man.addFile(entry.key.status.success.object_path, null);
303 }308 }
304 try man.addOptionalFile(module_obj_path);309 try man.addOptionalFile(module_obj_path);
310 try man.addOptionalFile(compiler_rt_path);
305 man.hash.addOptional(self.base.options.stack_size_override);311 man.hash.addOptional(self.base.options.stack_size_override);
306 man.hash.addListOfBytes(self.base.options.extra_lld_args);312 man.hash.addListOfBytes(self.base.options.extra_lld_args);
307313
...@@ -381,11 +387,15 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {...@@ -381,11 +387,15 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
381 try argv.append(p);387 try argv.append(p);
382 }388 }
383389
384 if (self.base.options.output_mode != .Obj and !self.base.options.is_compiler_rt_or_libc) {390 if (self.base.options.output_mode != .Obj and
385 if (!self.base.options.link_libc) {391 !self.base.options.is_compiler_rt_or_libc and
386 try argv.append(comp.libc_static_lib.?.full_object_path);392 !self.base.options.link_libc)
387 }393 {
388 try argv.append(comp.compiler_rt_static_lib.?.full_object_path);394 try argv.append(comp.libc_static_lib.?.full_object_path);
395 }
396
397 if (compiler_rt_path) |p| {
398 try argv.append(p);
389 }399 }
390400
391 if (self.base.options.verbose_link) {401 if (self.base.options.verbose_link) {