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,...@@ -112,6 +112,7 @@ unwind_tables: bool,
112test_evented_io: bool,112test_evented_io: bool,
113debug_compiler_runtime_libs: bool,113debug_compiler_runtime_libs: bool,
114debug_compile_errors: bool,114debug_compile_errors: bool,
115job_queued_compiler_rt_lib: bool = false,
115job_queued_compiler_rt_obj: bool = false,116job_queued_compiler_rt_obj: bool = false,
116alloc_failure_occurred: bool = false,117alloc_failure_occurred: bool = false,
117formatted_panics: bool = false,118formatted_panics: bool = false,
...@@ -157,6 +158,9 @@ libssp_static_lib: ?CRTFile = null,...@@ -157,6 +158,9 @@ libssp_static_lib: ?CRTFile = null,
157/// Populated when we build the libc static library. A Job to build this is placed in the queue158/// Populated when we build the libc static library. A Job to build this is placed in the queue
158/// and resolved before calling linker.flush().159/// and resolved before calling linker.flush().
159libc_static_lib: ?CRTFile = null,160libc_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,
160/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated164/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated
161/// by setting `job_queued_compiler_rt_obj` and resolved before calling linker.flush().165/// by setting `job_queued_compiler_rt_obj` and resolved before calling linker.flush().
162compiler_rt_obj: ?CRTFile = null,166compiler_rt_obj: ?CRTFile = null,
...@@ -1879,8 +1883,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1879,8 +1883,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1879 }1883 }
18801884
1881 if (comp.bin_file.options.include_compiler_rt and capable_of_building_compiler_rt) {1885 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) {
1883 log.debug("queuing a job to build compiler_rt_obj", .{});1890 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.
1884 comp.job_queued_compiler_rt_obj = true;1893 comp.job_queued_compiler_rt_obj = true;
1885 }1894 }
1886 }1895 }
...@@ -1935,6 +1944,9 @@ pub fn destroy(self: *Compilation) void {...@@ -1935,6 +1944,9 @@ pub fn destroy(self: *Compilation) void {
1935 if (self.libcxxabi_static_lib) |*crt_file| {1944 if (self.libcxxabi_static_lib) |*crt_file| {
1936 crt_file.deinit(gpa);1945 crt_file.deinit(gpa);
1937 }1946 }
1947 if (self.compiler_rt_lib) |*crt_file| {
1948 crt_file.deinit(gpa);
1949 }
1938 if (self.compiler_rt_obj) |*crt_file| {1950 if (self.compiler_rt_obj) |*crt_file| {
1939 crt_file.deinit(gpa);1951 crt_file.deinit(gpa);
1940 }1952 }
...@@ -3401,6 +3413,11 @@ pub fn performAllTheWork(...@@ -3401,6 +3413,11 @@ pub fn performAllTheWork(
3401 break;3413 break;
3402 }3414 }
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
3404 if (comp.job_queued_compiler_rt_obj) {3421 if (comp.job_queued_compiler_rt_obj) {
3405 comp.job_queued_compiler_rt_obj = false;3422 comp.job_queued_compiler_rt_obj = false;
3406 buildCompilerRtOneShot(comp, .Obj, &comp.compiler_rt_obj, main_progress_node);3423 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...@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
491 }491 }
492 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but492 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but
493 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.493 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
494 if (comp.compiler_rt_obj) |obj| {494 if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
495 try argv.append(obj.full_object_path);495 if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
496 }
497 }496 }
498497
499 try argv.ensureUnusedCapacity(self.base.options.system_libs.count());498 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...@@ -1257,6 +1257,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1257 // to be after the shared libraries, so they are picked up from the shared1257 // to be after the shared libraries, so they are picked up from the shared
1258 // libraries, not libcompiler_rt.1258 // libraries, not libcompiler_rt.
1259 const compiler_rt_path: ?[]const u8 = blk: {1259 const compiler_rt_path: ?[]const u8 = blk: {
1260 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
1260 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;1261 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
1261 break :blk null;1262 break :blk null;
1262 };1263 };
...@@ -1956,6 +1957,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -1956,6 +1957,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1956 const stack_size = self.base.options.stack_size_override orelse 16777216;1957 const stack_size = self.base.options.stack_size_override orelse 16777216;
1957 const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;1958 const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;
1958 const compiler_rt_path: ?[]const u8 = blk: {1959 const compiler_rt_path: ?[]const u8 = blk: {
1960 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
1959 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;1961 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
1960 break :blk null;1962 break :blk null;
1961 };1963 };
src/link/MachO/zld.zig+4-6
...@@ -186,9 +186,8 @@ pub fn linkWithZld(...@@ -186,9 +186,8 @@ pub fn linkWithZld(
186 try positionals.append(.{ .path = p });186 try positionals.append(.{ .path = p });
187 }187 }
188188
189 if (comp.compiler_rt_obj) |obj| {189 if (comp.compiler_rt_lib) |lib| try positionals.append(.{ .path = lib.full_object_path });
190 try positionals.append(.{ .path = obj.full_object_path });190 if (comp.compiler_rt_obj) |obj| try positionals.append(.{ .path = obj.full_object_path });
191 }
192191
193 // libc++ dep192 // libc++ dep
194 if (options.link_libcpp) {193 if (options.link_libcpp) {
...@@ -301,9 +300,8 @@ pub fn linkWithZld(...@@ -301,9 +300,8 @@ pub fn linkWithZld(
301 try argv.append(p);300 try argv.append(p);
302 }301 }
303302
304 if (comp.compiler_rt_obj) |obj| {303 if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
305 try argv.append(obj.full_object_path);304 if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
306 }
307305
308 if (options.link_libcpp) {306 if (options.link_libcpp) {
309 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);307 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...@@ -3257,7 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3257 sub_prog_node.activate();3257 sub_prog_node.activate();
3258 defer sub_prog_node.end();3258 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
3261 const id_symlink_basename = "zld.id";3266 const id_symlink_basename = "zld.id";
32623267
3263 var man: Cache.Manifest = undefined;3268 var man: Cache.Manifest = undefined;
...@@ -3372,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l...@@ -3372,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3372 try positionals.append(c_object.status.success.object_path);3377 try positionals.append(c_object.status.success.object_path);
3373 }3378 }
33743379
3375 if (comp.compiler_rt_obj) |obj| {3380 if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3376 try positionals.append(obj.full_object_path);3381 if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
3377 }
33783382
3379 try wasm.parseInputFiles(positionals.items);3383 try wasm.parseInputFiles(positionals.items);
33803384
...@@ -3459,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -3459,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3459 try positionals.append(c_object.status.success.object_path);3463 try positionals.append(c_object.status.success.object_path);
3460 }3464 }
34613465
3462 if (comp.compiler_rt_obj) |obj| {3466 if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3463 try positionals.append(obj.full_object_path);3467 if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
3464 }
34653468
3466 try wasm.parseInputFiles(positionals.items);3469 try wasm.parseInputFiles(positionals.items);
34673470
...@@ -4321,7 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4321,7 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4321 defer sub_prog_node.end();4324 defer sub_prog_node.end();
43224325
4323 const is_obj = wasm.base.options.output_mode == .Obj;4326 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
4326 const target = wasm.base.options.target;4333 const target = wasm.base.options.target;
43274334