authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:34-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:22:42-04:00
logc7c1d65372019199824d5f2284a63031383f0512
tree70b83be3ca5e2f08da71a59731cc55f3d0a9baf2
parent3ee12f3a2aeab1aff5852466cf0c654222e034cc

- Remove the compiler_rt_dyn_lib hack


4 files changed, 5 insertions(+), 72 deletions(-)

lib/std/zig.zig-4
...@@ -996,14 +996,11 @@ pub const EmitArtifact = enum {...@@ -996,14 +996,11 @@ pub const EmitArtifact = enum {
996 docs,996 docs,
997 pdb,997 pdb,
998 h,998 h,
999 compiler_rt_dyn_lib,
1000999
1001 /// If using `Server` to communicate with the compiler, it will place requested artifacts in1000 /// If using `Server` to communicate with the compiler, it will place requested artifacts in
1002 /// paths under the output directory, where those paths are named according to this function.1001 /// paths under the output directory, where those paths are named according to this function.
1003 /// Returned string is allocated with `gpa` and owned by the caller.1002 /// Returned string is allocated with `gpa` and owned by the caller.
1004 pub fn cacheName(ea: EmitArtifact, gpa: Allocator, opts: BinNameOptions) Allocator.Error![]const u8 {1003 pub fn cacheName(ea: EmitArtifact, gpa: Allocator, opts: BinNameOptions) Allocator.Error![]const u8 {
1005 // hack for stage2_x86_64 + coff. See Coff.flush.
1006 if (ea == .compiler_rt_dyn_lib) return "compiler_rt.dll";
1007 const suffix: []const u8 = switch (ea) {1004 const suffix: []const u8 = switch (ea) {
1008 .bin => return binNameAlloc(gpa, opts),1005 .bin => return binNameAlloc(gpa, opts),
1009 .@"asm" => ".s",1006 .@"asm" => ".s",
...@@ -1013,7 +1010,6 @@ pub const EmitArtifact = enum {...@@ -1013,7 +1010,6 @@ pub const EmitArtifact = enum {
1013 .docs => "-docs",1010 .docs => "-docs",
1014 .pdb => ".pdb",1011 .pdb => ".pdb",
1015 .h => ".h",1012 .h => ".h",
1016 .compiler_rt_dyn_lib => unreachable,
1017 };1013 };
1018 return std.fmt.allocPrint(gpa, "{s}{s}", .{ opts.root_name, suffix });1014 return std.fmt.allocPrint(gpa, "{s}{s}", .{ opts.root_name, suffix });
1019 }1015 }
src/Compilation.zig+2-37
...@@ -223,8 +223,6 @@ compiler_rt_lib: ?CrtFile = null,...@@ -223,8 +223,6 @@ compiler_rt_lib: ?CrtFile = null,
223/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated223/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated
224/// by setting `queued_jobs.compiler_rt_obj` and resolved before calling linker.flush().224/// by setting `queued_jobs.compiler_rt_obj` and resolved before calling linker.flush().
225compiler_rt_obj: ?CrtFile = null,225compiler_rt_obj: ?CrtFile = null,
226/// hack for stage2_x86_64 + coff
227compiler_rt_dyn_lib: ?CrtFile = null,
228/// Populated when we build the libfuzzer static library. A Job to build this226/// Populated when we build the libfuzzer static library. A Job to build this
229/// is indicated by setting `queued_jobs.fuzzer_lib` and resolved before227/// is indicated by setting `queued_jobs.fuzzer_lib` and resolved before
230/// calling linker.flush().228/// calling linker.flush().
...@@ -287,8 +285,6 @@ emit_llvm_bc: ?[]const u8,...@@ -287,8 +285,6 @@ emit_llvm_bc: ?[]const u8,
287emit_docs: ?[]const u8,285emit_docs: ?[]const u8,
288286
289const QueuedJobs = struct {287const QueuedJobs = struct {
290 /// hack for stage2_x86_64 + coff
291 compiler_rt_dyn_lib: bool = false,
292 compiler_rt_lib: bool = false,288 compiler_rt_lib: bool = false,
293 compiler_rt_obj: bool = false,289 compiler_rt_obj: bool = false,
294 ubsan_rt_lib: bool = false,290 ubsan_rt_lib: bool = false,
...@@ -1781,7 +1777,7 @@ fn addModuleTableToCacheHash(...@@ -1781,7 +1777,7 @@ fn addModuleTableToCacheHash(
1781 }1777 }
1782}1778}
17831779
1784const RtStrat = enum { none, lib, obj, zcu, dyn_lib };1780const RtStrat = enum { none, lib, obj, zcu };
17851781
1786pub const CreateDiagnostic = union(enum) {1782pub const CreateDiagnostic = union(enum) {
1787 export_table_import_table_conflict,1783 export_table_import_table_conflict,
...@@ -1902,12 +1898,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -1902,12 +1898,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
1902 };1898 };
1903 if (have_zcu and (!need_llvm or use_llvm)) {1899 if (have_zcu and (!need_llvm or use_llvm)) {
1904 if (output_mode == .Obj) break :s .zcu;1900 if (output_mode == .Obj) break :s .zcu;
1905 switch (target_util.zigBackend(target, use_llvm)) {
1906 else => {},
1907 .stage2_aarch64, .stage2_x86_64 => if (target.ofmt == .coff) {
1908 break :s if (is_exe_or_dyn_lib and build_options.have_llvm) .dyn_lib else .zcu;
1909 },
1910 }
1911 }1901 }
1912 if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm1902 if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm
1913 if (is_exe_or_dyn_lib) break :s .lib;1903 if (is_exe_or_dyn_lib) break :s .lib;
...@@ -2628,11 +2618,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2628,11 +2618,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2628 log.debug("queuing a job to build compiler_rt_obj", .{});2618 log.debug("queuing a job to build compiler_rt_obj", .{});
2629 comp.queued_jobs.compiler_rt_obj = true;2619 comp.queued_jobs.compiler_rt_obj = true;
2630 },2620 },
2631 .dyn_lib => {
2632 // hack for stage2_x86_64 + coff
2633 log.debug("queuing a job to build compiler_rt_dyn_lib", .{});
2634 comp.queued_jobs.compiler_rt_dyn_lib = true;
2635 },
2636 }2621 }
26372622
2638 switch (comp.ubsan_rt_strat) {2623 switch (comp.ubsan_rt_strat) {
...@@ -2645,7 +2630,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2645,7 +2630,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2645 log.debug("queuing a job to build ubsan_rt_obj", .{});2630 log.debug("queuing a job to build ubsan_rt_obj", .{});
2646 comp.queued_jobs.ubsan_rt_obj = true;2631 comp.queued_jobs.ubsan_rt_obj = true;
2647 },2632 },
2648 .dyn_lib => unreachable, // hack for compiler_rt only
2649 }2633 }
26502634
2651 switch (comp.zigc_strat) {2635 switch (comp.zigc_strat) {
...@@ -2654,7 +2638,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2654,7 +2638,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2654 log.debug("queuing a job to build libzigc", .{});2638 log.debug("queuing a job to build libzigc", .{});
2655 comp.queued_jobs.zigc_lib = true;2639 comp.queued_jobs.zigc_lib = true;
2656 },2640 },
2657 .obj, .dyn_lib => unreachable, // only available as a static library or inside an existing ZCU2641 .obj => unreachable, // only available as a static library or inside an existing ZCU
2658 }2642 }
26592643
2660 if (is_exe_or_dyn_lib and comp.config.any_fuzz) {2644 if (is_exe_or_dyn_lib and comp.config.any_fuzz) {
...@@ -2713,7 +2697,6 @@ pub fn destroy(comp: *Compilation) void {...@@ -2713,7 +2697,6 @@ pub fn destroy(comp: *Compilation) void {
2713 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa, io);2697 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa, io);
2714 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa, io);2698 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa, io);
2715 if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa, io);2699 if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa, io);
2716 if (comp.compiler_rt_dyn_lib) |*crt_file| crt_file.deinit(gpa, io);
2717 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa, io);2700 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa, io);
27182701
2719 if (comp.glibc_so_files) |*glibc_file| {2702 if (comp.glibc_so_files) |*glibc_file| {
...@@ -4566,24 +4549,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node...@@ -4566,24 +4549,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node
4566 });4549 });
4567 }4550 }
45684551
4569 // hack for stage2_x86_64 + coff
4570 if (comp.queued_jobs.compiler_rt_dyn_lib and comp.compiler_rt_dyn_lib == null) {
4571 prelink_group.async(io, buildRt, .{
4572 comp,
4573 "compiler_rt.zig",
4574 "compiler_rt",
4575 .Lib,
4576 .dynamic,
4577 .compiler_rt,
4578 main_progress_node,
4579 RtOptions{
4580 .checks_valgrind = true,
4581 .allow_lto = false,
4582 },
4583 &comp.compiler_rt_dyn_lib,
4584 });
4585 }
4586
4587 if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) {4552 if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) {
4588 prelink_group.async(io, buildRt, .{4553 prelink_group.async(io, buildRt, .{
4589 comp,4554 comp,
src/codegen/x86_64/Emit.zig-8
...@@ -154,19 +154,11 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -154,19 +154,11 @@ pub fn emitMir(emit: *Emit) Error!void {
154 @enumFromInt(try elf_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null))154 @enumFromInt(try elf_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null))
155 else if (emit.bin_file.cast(.elf2)) |elf| try elf.externSymbol(.{155 else if (emit.bin_file.cast(.elf2)) |elf| try elf.externSymbol(.{
156 .name = extern_func.toSlice(&emit.lower.mir).?,156 .name = extern_func.toSlice(&emit.lower.mir).?,
157 .lib_name = switch (comp.compiler_rt_strat) {
158 .none, .lib, .obj, .zcu => null,
159 .dyn_lib => "compiler_rt",
160 },
161 .type = .FUNC,157 .type = .FUNC,
162 }) else if (emit.bin_file.cast(.macho)) |macho_file|158 }) else if (emit.bin_file.cast(.macho)) |macho_file|
163 @enumFromInt(try macho_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null))159 @enumFromInt(try macho_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null))
164 else if (emit.bin_file.cast(.coff2)) |coff| @enumFromInt(@intFromEnum(try coff.globalSymbol(.{160 else if (emit.bin_file.cast(.coff2)) |coff| @enumFromInt(@intFromEnum(try coff.globalSymbol(.{
165 .name = extern_func.toSlice(&emit.lower.mir).?,161 .name = extern_func.toSlice(&emit.lower.mir).?,
166 .lib_name = switch (comp.compiler_rt_strat) {
167 .none, .lib, .obj, .zcu => null,
168 .dyn_lib => "compiler_rt",
169 },
170 }))) else return emit.fail("external symbol unimplemented for {s}", .{@tagName(emit.bin_file.tag)}),162 }))) else return emit.fail("external symbol unimplemented for {s}", .{@tagName(emit.bin_file.tag)}),
171 .is_extern = true,163 .is_extern = true,
172 } },164 } },
src/link/Coff.zig+3-23
...@@ -3283,7 +3283,7 @@ fn loadObject(...@@ -3283,7 +3283,7 @@ fn loadObject(
3283 header.machine,3283 header.machine,
3284 });3284 });
3285 if (header.number_of_sections == 0) return;3285 if (header.number_of_sections == 0) return;
3286 if (@sizeOf(std.coff.Header) + header.number_of_sections * @sizeOf(std.coff.SectionHeader) > fl.size)3286 if (@sizeOf(std.coff.Header) + @as(usize, header.number_of_sections) * @sizeOf(std.coff.SectionHeader) > fl.size)
3287 return diags.failParse(path, "invalid section table", .{});3287 return diags.failParse(path, "invalid section table", .{});
3288 const unexpected_header_flags: []const std.meta.FieldEnum(std.coff.Header.Flags) = &.{3288 const unexpected_header_flags: []const std.meta.FieldEnum(std.coff.Header.Flags) = &.{
3289 .RELOCS_STRIPPED,3289 .RELOCS_STRIPPED,
...@@ -4507,26 +4507,6 @@ pub fn flush(...@@ -4507,26 +4507,6 @@ pub fn flush(
4507 coff.flushImplib(implib_file) catch |err|4507 coff.flushImplib(implib_file) catch |err|
4508 return comp.link_diags.fail("flushing implib '{s}' failed: {t}", .{ implib_file, err });4508 return comp.link_diags.fail("flushing implib '{s}' failed: {t}", .{ implib_file, err });
45094509
4510 // hack for stage2_x86_64 + coff
4511 if (comp.compiler_rt_dyn_lib) |crt_file| {
4512 const io = comp.io;
4513 const gpa = comp.gpa;
4514
4515 const compiler_rt_sub_path = try std.fs.path.join(gpa, &.{
4516 std.fs.path.dirname(coff.base.emit.sub_path) orelse "",
4517 std.fs.path.basename(crt_file.full_object_path.sub_path),
4518 });
4519 defer gpa.free(compiler_rt_sub_path);
4520 std.Io.Dir.copyFile(
4521 crt_file.full_object_path.root_dir.handle,
4522 crt_file.full_object_path.sub_path,
4523 coff.base.emit.root_dir.handle,
4524 compiler_rt_sub_path,
4525 io,
4526 .{},
4527 ) catch |err| return comp.link_diags.fail("copy '{s}' failed: {t}", .{ compiler_rt_sub_path, err });
4528 }
4529
4530 coff.mf.flush() catch |err| switch (err) {4510 coff.mf.flush() catch |err| switch (err) {
4531 error.Canceled => |e| return e,4511 error.Canceled => |e| return e,
4532 else => |e| return comp.link_diags.fail("flush write failed: {t}", .{e}),4512 else => |e| return comp.link_diags.fail("flush write failed: {t}", .{e}),
...@@ -4558,14 +4538,14 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -4558,14 +4538,14 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
4558 }4538 }
4559 if (coff.pending_input) |pending_iami| {4539 if (coff.pending_input) |pending_iami| {
4560 // TODO: Prog node?4540 // TODO: Prog node?
4541 coff.pending_input = null;
4561 coff.flushInputMember(pending_iami) catch |err| switch (err) {4542 coff.flushInputMember(pending_iami) catch |err| switch (err) {
4562 error.OutOfMemory => return error.OutOfMemory,4543 error.OutOfMemory => return error.OutOfMemory,
4563 else => |e| return comp.link_diags.fail(4544 else => |e| return comp.link_diags.fail(
4564 "linker failed to archive member: {t}",4545 "linker failed to load archive member: {t}",
4565 .{e},4546 .{e},
4566 ),4547 ),
4567 };4548 };
4568 coff.pending_input = null;
4569 break :task;4549 break :task;
4570 }4550 }
4571 if (coff.global_pending_index < coff.globals.count()) {4551 if (coff.global_pending_index < coff.globals.count()) {