authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-10 11:23:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-10 11:23:39-07:00
logda7e4fb31a05f2063eb829c4c383a44b38ed21e1
treea038ac670ba752adea3293c65bd0a06d864cb9d0
parent33ef01d16b91a537696272ca286d6423abbdd632

revert compiler_rt: no need to put it in a static library

This mostly reverts 6e0904504155d3cba80955c108116170fd739aec however it leaves intact the linker supporting both obj and lib files, and the frontend choosing which one to create.

5 files changed, 41 insertions(+), 18 deletions(-)

src/Compilation.zig+18-1
......@@ -112,6 +112,7 @@ unwind_tables: bool,
112112test_evented_io: bool,
113113debug_compiler_runtime_libs: bool,
114114debug_compile_errors: bool,
115job_queued_compiler_rt_lib: bool = false,
115116job_queued_compiler_rt_obj: bool = false,
116117alloc_failure_occurred: bool = false,
117118formatted_panics: bool = false,
......@@ -157,6 +158,9 @@ libssp_static_lib: ?CRTFile = null,
157158/// Populated when we build the libc static library. A Job to build this is placed in the queue
158159/// and resolved before calling linker.flush().
159160libc_static_lib: ?CRTFile = null,
161/// Populated when we build the libcompiler_rt static library. A Job to build this is indicated
162/// by setting `job_queued_compiler_rt_lib` and resolved before calling linker.flush().
163compiler_rt_lib: ?CRTFile = null,
160164/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated
161165/// by setting `job_queued_compiler_rt_obj` and resolved before calling linker.flush().
162166compiler_rt_obj: ?CRTFile = null,
......@@ -1879,8 +1883,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
18791883 }
18801884
18811885 if (comp.bin_file.options.include_compiler_rt and capable_of_building_compiler_rt) {
1882 if (is_exe_or_dyn_lib or options.output_mode != .Obj) {
1886 if (is_exe_or_dyn_lib) {
1887 log.debug("queuing a job to build compiler_rt_lib", .{});
1888 comp.job_queued_compiler_rt_lib = true;
1889 } else if (options.output_mode != .Obj) {
18831890 log.debug("queuing a job to build compiler_rt_obj", .{});
1891 // In this case we are making a static library, so we ask
1892 // for a compiler-rt object to put in it.
18841893 comp.job_queued_compiler_rt_obj = true;
18851894 }
18861895 }
......@@ -1935,6 +1944,9 @@ pub fn destroy(self: *Compilation) void {
19351944 if (self.libcxxabi_static_lib) |*crt_file| {
19361945 crt_file.deinit(gpa);
19371946 }
1947 if (self.compiler_rt_lib) |*crt_file| {
1948 crt_file.deinit(gpa);
1949 }
19381950 if (self.compiler_rt_obj) |*crt_file| {
19391951 crt_file.deinit(gpa);
19401952 }
......@@ -3401,6 +3413,11 @@ pub fn performAllTheWork(
34013413 break;
34023414 }
34033415
3416 if (comp.job_queued_compiler_rt_lib) {
3417 comp.job_queued_compiler_rt_lib = false;
3418 buildCompilerRtOneShot(comp, .Lib, &comp.compiler_rt_lib, main_progress_node);
3419 }
3420
34043421 if (comp.job_queued_compiler_rt_obj) {
34053422 comp.job_queued_compiler_rt_obj = false;
34063423 buildCompilerRtOneShot(comp, .Obj, &comp.compiler_rt_obj, main_progress_node);
src/link/Coff/lld.zig+2-3
......@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
491491 }
492492 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but
493493 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
494 if (comp.compiler_rt_obj) |obj| {
495 try argv.append(obj.full_object_path);
496 }
494 if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
495 if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
497496 }
498497
499498 try argv.ensureUnusedCapacity(self.base.options.system_libs.count());
src/link/Elf.zig+2
......@@ -1257,6 +1257,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12571257 // to be after the shared libraries, so they are picked up from the shared
12581258 // libraries, not libcompiler_rt.
12591259 const compiler_rt_path: ?[]const u8 = blk: {
1260 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
12601261 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
12611262 break :blk null;
12621263 };
......@@ -1956,6 +1957,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
19561957 const stack_size = self.base.options.stack_size_override orelse 16777216;
19571958 const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;
19581959 const compiler_rt_path: ?[]const u8 = blk: {
1960 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
19591961 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
19601962 break :blk null;
19611963 };
src/link/MachO/zld.zig+4-6
......@@ -186,9 +186,8 @@ pub fn linkWithZld(
186186 try positionals.append(.{ .path = p });
187187 }
188188
189 if (comp.compiler_rt_obj) |obj| {
190 try positionals.append(.{ .path = obj.full_object_path });
191 }
189 if (comp.compiler_rt_lib) |lib| try positionals.append(.{ .path = lib.full_object_path });
190 if (comp.compiler_rt_obj) |obj| try positionals.append(.{ .path = obj.full_object_path });
192191
193192 // libc++ dep
194193 if (options.link_libcpp) {
......@@ -301,9 +300,8 @@ pub fn linkWithZld(
301300 try argv.append(p);
302301 }
303302
304 if (comp.compiler_rt_obj) |obj| {
305 try argv.append(obj.full_object_path);
306 }
303 if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
304 if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
307305
308306 if (options.link_libcpp) {
309307 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
src/link/Wasm.zig+15-8
......@@ -3257,7 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
32573257 sub_prog_node.activate();
32583258 defer sub_prog_node.end();
32593259
3260 const compiler_rt_path: ?[]const u8 = if (comp.compiler_rt_obj) |o| o.full_object_path else null;
3260 const compiler_rt_path: ?[]const u8 = blk: {
3261 if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
3262 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
3263 break :blk null;
3264 };
3265
32613266 const id_symlink_basename = "zld.id";
32623267
32633268 var man: Cache.Manifest = undefined;
......@@ -3372,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
33723377 try positionals.append(c_object.status.success.object_path);
33733378 }
33743379
3375 if (comp.compiler_rt_obj) |obj| {
3376 try positionals.append(obj.full_object_path);
3377 }
3380 if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3381 if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
33783382
33793383 try wasm.parseInputFiles(positionals.items);
33803384
......@@ -3459,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
34593463 try positionals.append(c_object.status.success.object_path);
34603464 }
34613465
3462 if (comp.compiler_rt_obj) |obj| {
3463 try positionals.append(obj.full_object_path);
3464 }
3466 if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3467 if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
34653468
34663469 try wasm.parseInputFiles(positionals.items);
34673470
......@@ -4321,7 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
43214324 defer sub_prog_node.end();
43224325
43234326 const is_obj = wasm.base.options.output_mode == .Obj;
4324 const compiler_rt_path: ?[]const u8 = if (comp.compiler_rt_obj) |o| o.full_object_path else null;
4327 const compiler_rt_path: ?[]const u8 = blk: {
4328 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
4329 if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
4330 break :blk null;
4331 };
43254332
43264333 const target = wasm.base.options.target;
43274334