Commit da7e4fb31a
Changed files (5)
src
src/link/Coff/lld.zig
@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
}
// MSVC compiler_rt is missing some stuff, so we build it unconditionally but
// and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
- if (comp.compiler_rt_obj) |obj| {
- try argv.append(obj.full_object_path);
- }
+ if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
+ if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
}
try argv.ensureUnusedCapacity(self.base.options.system_libs.count());
src/link/MachO/zld.zig
@@ -186,9 +186,8 @@ pub fn linkWithZld(
try positionals.append(.{ .path = p });
}
- if (comp.compiler_rt_obj) |obj| {
- try positionals.append(.{ .path = obj.full_object_path });
- }
+ if (comp.compiler_rt_lib) |lib| try positionals.append(.{ .path = lib.full_object_path });
+ if (comp.compiler_rt_obj) |obj| try positionals.append(.{ .path = obj.full_object_path });
// libc++ dep
if (options.link_libcpp) {
@@ -301,9 +300,8 @@ pub fn linkWithZld(
try argv.append(p);
}
- if (comp.compiler_rt_obj) |obj| {
- try argv.append(obj.full_object_path);
- }
+ if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
+ if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
if (options.link_libcpp) {
try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
src/link/Elf.zig
@@ -1257,6 +1257,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
// to be after the shared libraries, so they are picked up from the shared
// libraries, not libcompiler_rt.
const compiler_rt_path: ?[]const u8 = blk: {
+ if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
break :blk null;
};
@@ -1956,6 +1957,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
const stack_size = self.base.options.stack_size_override orelse 16777216;
const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;
const compiler_rt_path: ?[]const u8 = blk: {
+ if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
break :blk null;
};
src/link/Wasm.zig
@@ -3257,7 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
sub_prog_node.activate();
defer sub_prog_node.end();
- const compiler_rt_path: ?[]const u8 = if (comp.compiler_rt_obj) |o| o.full_object_path else null;
+ const compiler_rt_path: ?[]const u8 = blk: {
+ if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
+ if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
+ break :blk null;
+ };
+
const id_symlink_basename = "zld.id";
var man: Cache.Manifest = undefined;
@@ -3372,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
try positionals.append(c_object.status.success.object_path);
}
- if (comp.compiler_rt_obj) |obj| {
- try positionals.append(obj.full_object_path);
- }
+ if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
+ if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
try wasm.parseInputFiles(positionals.items);
@@ -3459,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
try positionals.append(c_object.status.success.object_path);
}
- if (comp.compiler_rt_obj) |obj| {
- try positionals.append(obj.full_object_path);
- }
+ if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
+ if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
try wasm.parseInputFiles(positionals.items);
@@ -4321,7 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
defer sub_prog_node.end();
const is_obj = wasm.base.options.output_mode == .Obj;
- const compiler_rt_path: ?[]const u8 = if (comp.compiler_rt_obj) |o| o.full_object_path else null;
+ const compiler_rt_path: ?[]const u8 = blk: {
+ if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
+ if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
+ break :blk null;
+ };
const target = wasm.base.options.target;
src/Compilation.zig
@@ -112,6 +112,7 @@ unwind_tables: bool,
test_evented_io: bool,
debug_compiler_runtime_libs: bool,
debug_compile_errors: bool,
+job_queued_compiler_rt_lib: bool = false,
job_queued_compiler_rt_obj: bool = false,
alloc_failure_occurred: bool = false,
formatted_panics: bool = false,
@@ -157,6 +158,9 @@ libssp_static_lib: ?CRTFile = null,
/// Populated when we build the libc static library. A Job to build this is placed in the queue
/// and resolved before calling linker.flush().
libc_static_lib: ?CRTFile = null,
+/// Populated when we build the libcompiler_rt static library. A Job to build this is indicated
+/// by setting `job_queued_compiler_rt_lib` and resolved before calling linker.flush().
+compiler_rt_lib: ?CRTFile = null,
/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated
/// by setting `job_queued_compiler_rt_obj` and resolved before calling linker.flush().
compiler_rt_obj: ?CRTFile = null,
@@ -1879,8 +1883,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
}
if (comp.bin_file.options.include_compiler_rt and capable_of_building_compiler_rt) {
- if (is_exe_or_dyn_lib or options.output_mode != .Obj) {
+ if (is_exe_or_dyn_lib) {
+ log.debug("queuing a job to build compiler_rt_lib", .{});
+ comp.job_queued_compiler_rt_lib = true;
+ } else if (options.output_mode != .Obj) {
log.debug("queuing a job to build compiler_rt_obj", .{});
+ // In this case we are making a static library, so we ask
+ // for a compiler-rt object to put in it.
comp.job_queued_compiler_rt_obj = true;
}
}
@@ -1935,6 +1944,9 @@ pub fn destroy(self: *Compilation) void {
if (self.libcxxabi_static_lib) |*crt_file| {
crt_file.deinit(gpa);
}
+ if (self.compiler_rt_lib) |*crt_file| {
+ crt_file.deinit(gpa);
+ }
if (self.compiler_rt_obj) |*crt_file| {
crt_file.deinit(gpa);
}
@@ -3401,6 +3413,11 @@ pub fn performAllTheWork(
break;
}
+ if (comp.job_queued_compiler_rt_lib) {
+ comp.job_queued_compiler_rt_lib = false;
+ buildCompilerRtOneShot(comp, .Lib, &comp.compiler_rt_lib, main_progress_node);
+ }
+
if (comp.job_queued_compiler_rt_obj) {
comp.job_queued_compiler_rt_obj = false;
buildCompilerRtOneShot(comp, .Obj, &comp.compiler_rt_obj, main_progress_node);