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 {
996996 docs,
997997 pdb,
998998 h,
999 compiler_rt_dyn_lib,
1000999
10011000 /// If using `Server` to communicate with the compiler, it will place requested artifacts in
10021001 /// paths under the output directory, where those paths are named according to this function.
10031002 /// Returned string is allocated with `gpa` and owned by the caller.
10041003 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";
10071004 const suffix: []const u8 = switch (ea) {
10081005 .bin => return binNameAlloc(gpa, opts),
10091006 .@"asm" => ".s",
......@@ -1013,7 +1010,6 @@ pub const EmitArtifact = enum {
10131010 .docs => "-docs",
10141011 .pdb => ".pdb",
10151012 .h => ".h",
1016 .compiler_rt_dyn_lib => unreachable,
10171013 };
10181014 return std.fmt.allocPrint(gpa, "{s}{s}", .{ opts.root_name, suffix });
10191015 }
src/Compilation.zig+2-37
......@@ -223,8 +223,6 @@ compiler_rt_lib: ?CrtFile = null,
223223/// Populated when we build the compiler_rt_obj object. A Job to build this is indicated
224224/// by setting `queued_jobs.compiler_rt_obj` and resolved before calling linker.flush().
225225compiler_rt_obj: ?CrtFile = null,
226/// hack for stage2_x86_64 + coff
227compiler_rt_dyn_lib: ?CrtFile = null,
228226/// Populated when we build the libfuzzer static library. A Job to build this
229227/// is indicated by setting `queued_jobs.fuzzer_lib` and resolved before
230228/// calling linker.flush().
......@@ -287,8 +285,6 @@ emit_llvm_bc: ?[]const u8,
287285emit_docs: ?[]const u8,
288286
289287const QueuedJobs = struct {
290 /// hack for stage2_x86_64 + coff
291 compiler_rt_dyn_lib: bool = false,
292288 compiler_rt_lib: bool = false,
293289 compiler_rt_obj: bool = false,
294290 ubsan_rt_lib: bool = false,
......@@ -1781,7 +1777,7 @@ fn addModuleTableToCacheHash(
17811777 }
17821778}
17831779
1784const RtStrat = enum { none, lib, obj, zcu, dyn_lib };
1780const RtStrat = enum { none, lib, obj, zcu };
17851781
17861782pub const CreateDiagnostic = union(enum) {
17871783 export_table_import_table_conflict,
......@@ -1902,12 +1898,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
19021898 };
19031899 if (have_zcu and (!need_llvm or use_llvm)) {
19041900 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 }
19111901 }
19121902 if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm
19131903 if (is_exe_or_dyn_lib) break :s .lib;
......@@ -2628,11 +2618,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
26282618 log.debug("queuing a job to build compiler_rt_obj", .{});
26292619 comp.queued_jobs.compiler_rt_obj = true;
26302620 },
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 },
26362621 }
26372622
26382623 switch (comp.ubsan_rt_strat) {
......@@ -2645,7 +2630,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
26452630 log.debug("queuing a job to build ubsan_rt_obj", .{});
26462631 comp.queued_jobs.ubsan_rt_obj = true;
26472632 },
2648 .dyn_lib => unreachable, // hack for compiler_rt only
26492633 }
26502634
26512635 switch (comp.zigc_strat) {
......@@ -2654,7 +2638,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
26542638 log.debug("queuing a job to build libzigc", .{});
26552639 comp.queued_jobs.zigc_lib = true;
26562640 },
2657 .obj, .dyn_lib => unreachable, // only available as a static library or inside an existing ZCU
2641 .obj => unreachable, // only available as a static library or inside an existing ZCU
26582642 }
26592643
26602644 if (is_exe_or_dyn_lib and comp.config.any_fuzz) {
......@@ -2713,7 +2697,6 @@ pub fn destroy(comp: *Compilation) void {
27132697 if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa, io);
27142698 if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa, io);
27152699 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);
27172700 if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa, io);
27182701
27192702 if (comp.glibc_so_files) |*glibc_file| {
......@@ -4566,24 +4549,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node
45664549 });
45674550 }
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
45874552 if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) {
45884553 prelink_group.async(io, buildRt, .{
45894554 comp,
src/codegen/x86_64/Emit.zig-8
......@@ -154,19 +154,11 @@ pub fn emitMir(emit: *Emit) Error!void {
154154 @enumFromInt(try elf_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null))
155155 else if (emit.bin_file.cast(.elf2)) |elf| try elf.externSymbol(.{
156156 .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 },
161157 .type = .FUNC,
162158 }) else if (emit.bin_file.cast(.macho)) |macho_file|
163159 @enumFromInt(try macho_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null))
164160 else if (emit.bin_file.cast(.coff2)) |coff| @enumFromInt(@intFromEnum(try coff.globalSymbol(.{
165161 .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 },
170162 }))) else return emit.fail("external symbol unimplemented for {s}", .{@tagName(emit.bin_file.tag)}),
171163 .is_extern = true,
172164 } },
src/link/Coff.zig+3-23
......@@ -3283,7 +3283,7 @@ fn loadObject(
32833283 header.machine,
32843284 });
32853285 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)
32873287 return diags.failParse(path, "invalid section table", .{});
32883288 const unexpected_header_flags: []const std.meta.FieldEnum(std.coff.Header.Flags) = &.{
32893289 .RELOCS_STRIPPED,
......@@ -4507,26 +4507,6 @@ pub fn flush(
45074507 coff.flushImplib(implib_file) catch |err|
45084508 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
45304510 coff.mf.flush() catch |err| switch (err) {
45314511 error.Canceled => |e| return e,
45324512 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 {
45584538 }
45594539 if (coff.pending_input) |pending_iami| {
45604540 // TODO: Prog node?
4541 coff.pending_input = null;
45614542 coff.flushInputMember(pending_iami) catch |err| switch (err) {
45624543 error.OutOfMemory => return error.OutOfMemory,
45634544 else => |e| return comp.link_diags.fail(
4564 "linker failed to archive member: {t}",
4545 "linker failed to load archive member: {t}",
45654546 .{e},
45664547 ),
45674548 };
4568 coff.pending_input = null;
45694549 break :task;
45704550 }
45714551 if (coff.global_pending_index < coff.globals.count()) {