diff --git a/lib/std/zig.zig b/lib/std/zig.zig index cdb2e857cd3aff3019476837147c57c50318de7e..05891c582e38646da978177e34a3e8b26ac7f0af 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -996,14 +996,11 @@ pub const EmitArtifact = enum { docs, pdb, h, - compiler_rt_dyn_lib, /// If using `Server` to communicate with the compiler, it will place requested artifacts in /// paths under the output directory, where those paths are named according to this function. /// Returned string is allocated with `gpa` and owned by the caller. pub fn cacheName(ea: EmitArtifact, gpa: Allocator, opts: BinNameOptions) Allocator.Error![]const u8 { - // hack for stage2_x86_64 + coff. See Coff.flush. - if (ea == .compiler_rt_dyn_lib) return "compiler_rt.dll"; const suffix: []const u8 = switch (ea) { .bin => return binNameAlloc(gpa, opts), .@"asm" => ".s", @@ -1013,7 +1010,6 @@ pub const EmitArtifact = enum { .docs => "-docs", .pdb => ".pdb", .h => ".h", - .compiler_rt_dyn_lib => unreachable, }; return std.fmt.allocPrint(gpa, "{s}{s}", .{ opts.root_name, suffix }); } diff --git a/src/Compilation.zig b/src/Compilation.zig index 684889f2d021ea78587078d62468c85e1e4a971d..0d10f21b03939405aab6f9031100ec1cdfc68f7e 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -223,8 +223,6 @@ compiler_rt_lib: ?CrtFile = null, /// Populated when we build the compiler_rt_obj object. A Job to build this is indicated /// by setting `queued_jobs.compiler_rt_obj` and resolved before calling linker.flush(). compiler_rt_obj: ?CrtFile = null, -/// hack for stage2_x86_64 + coff -compiler_rt_dyn_lib: ?CrtFile = null, /// Populated when we build the libfuzzer static library. A Job to build this /// is indicated by setting `queued_jobs.fuzzer_lib` and resolved before /// calling linker.flush(). @@ -287,8 +285,6 @@ emit_llvm_bc: ?[]const u8, emit_docs: ?[]const u8, const QueuedJobs = struct { - /// hack for stage2_x86_64 + coff - compiler_rt_dyn_lib: bool = false, compiler_rt_lib: bool = false, compiler_rt_obj: bool = false, ubsan_rt_lib: bool = false, @@ -1781,7 +1777,7 @@ fn addModuleTableToCacheHash( } } -const RtStrat = enum { none, lib, obj, zcu, dyn_lib }; +const RtStrat = enum { none, lib, obj, zcu }; pub const CreateDiagnostic = union(enum) { export_table_import_table_conflict, @@ -1902,12 +1898,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, }; if (have_zcu and (!need_llvm or use_llvm)) { if (output_mode == .Obj) break :s .zcu; - switch (target_util.zigBackend(target, use_llvm)) { - else => {}, - .stage2_aarch64, .stage2_x86_64 => if (target.ofmt == .coff) { - break :s if (is_exe_or_dyn_lib and build_options.have_llvm) .dyn_lib else .zcu; - }, - } } if (need_llvm and !build_options.have_llvm) break :s .none; // impossible to build without llvm if (is_exe_or_dyn_lib) break :s .lib; @@ -2628,11 +2618,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, log.debug("queuing a job to build compiler_rt_obj", .{}); comp.queued_jobs.compiler_rt_obj = true; }, - .dyn_lib => { - // hack for stage2_x86_64 + coff - log.debug("queuing a job to build compiler_rt_dyn_lib", .{}); - comp.queued_jobs.compiler_rt_dyn_lib = true; - }, } switch (comp.ubsan_rt_strat) { @@ -2645,7 +2630,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, log.debug("queuing a job to build ubsan_rt_obj", .{}); comp.queued_jobs.ubsan_rt_obj = true; }, - .dyn_lib => unreachable, // hack for compiler_rt only } switch (comp.zigc_strat) { @@ -2654,7 +2638,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, log.debug("queuing a job to build libzigc", .{}); comp.queued_jobs.zigc_lib = true; }, - .obj, .dyn_lib => unreachable, // only available as a static library or inside an existing ZCU + .obj => unreachable, // only available as a static library or inside an existing ZCU } if (is_exe_or_dyn_lib and comp.config.any_fuzz) { @@ -2713,7 +2697,6 @@ pub fn destroy(comp: *Compilation) void { if (comp.zigc_static_lib) |*crt_file| crt_file.deinit(gpa, io); if (comp.compiler_rt_lib) |*crt_file| crt_file.deinit(gpa, io); if (comp.compiler_rt_obj) |*crt_file| crt_file.deinit(gpa, io); - if (comp.compiler_rt_dyn_lib) |*crt_file| crt_file.deinit(gpa, io); if (comp.fuzzer_lib) |*crt_file| crt_file.deinit(gpa, io); if (comp.glibc_so_files) |*glibc_file| { @@ -4566,24 +4549,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node }); } - // hack for stage2_x86_64 + coff - if (comp.queued_jobs.compiler_rt_dyn_lib and comp.compiler_rt_dyn_lib == null) { - prelink_group.async(io, buildRt, .{ - comp, - "compiler_rt.zig", - "compiler_rt", - .Lib, - .dynamic, - .compiler_rt, - main_progress_node, - RtOptions{ - .checks_valgrind = true, - .allow_lto = false, - }, - &comp.compiler_rt_dyn_lib, - }); - } - if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) { prelink_group.async(io, buildRt, .{ comp, diff --git a/src/codegen/x86_64/Emit.zig b/src/codegen/x86_64/Emit.zig index 3d0d3c1829d72bc4a297a8817aedc550e00f7396..304bde522aa2328d0f8ee7e8f4728767c14e08c7 100644 --- a/src/codegen/x86_64/Emit.zig +++ b/src/codegen/x86_64/Emit.zig @@ -154,19 +154,11 @@ pub fn emitMir(emit: *Emit) Error!void { @enumFromInt(try elf_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null)) else if (emit.bin_file.cast(.elf2)) |elf| try elf.externSymbol(.{ .name = extern_func.toSlice(&emit.lower.mir).?, - .lib_name = switch (comp.compiler_rt_strat) { - .none, .lib, .obj, .zcu => null, - .dyn_lib => "compiler_rt", - }, .type = .FUNC, }) else if (emit.bin_file.cast(.macho)) |macho_file| @enumFromInt(try macho_file.getGlobalSymbol(extern_func.toSlice(&emit.lower.mir).?, null)) else if (emit.bin_file.cast(.coff2)) |coff| @enumFromInt(@intFromEnum(try coff.globalSymbol(.{ .name = extern_func.toSlice(&emit.lower.mir).?, - .lib_name = switch (comp.compiler_rt_strat) { - .none, .lib, .obj, .zcu => null, - .dyn_lib => "compiler_rt", - }, }))) else return emit.fail("external symbol unimplemented for {s}", .{@tagName(emit.bin_file.tag)}), .is_extern = true, } }, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index ec4c301057fabda514f2e43b959b28230b5551ee..de1c7e474432cd7b867bb7defdd352bdeef11e4a 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -3283,7 +3283,7 @@ fn loadObject( header.machine, }); if (header.number_of_sections == 0) return; - if (@sizeOf(std.coff.Header) + header.number_of_sections * @sizeOf(std.coff.SectionHeader) > fl.size) + if (@sizeOf(std.coff.Header) + @as(usize, header.number_of_sections) * @sizeOf(std.coff.SectionHeader) > fl.size) return diags.failParse(path, "invalid section table", .{}); const unexpected_header_flags: []const std.meta.FieldEnum(std.coff.Header.Flags) = &.{ .RELOCS_STRIPPED, @@ -4507,26 +4507,6 @@ pub fn flush( coff.flushImplib(implib_file) catch |err| return comp.link_diags.fail("flushing implib '{s}' failed: {t}", .{ implib_file, err }); - // hack for stage2_x86_64 + coff - if (comp.compiler_rt_dyn_lib) |crt_file| { - const io = comp.io; - const gpa = comp.gpa; - - const compiler_rt_sub_path = try std.fs.path.join(gpa, &.{ - std.fs.path.dirname(coff.base.emit.sub_path) orelse "", - std.fs.path.basename(crt_file.full_object_path.sub_path), - }); - defer gpa.free(compiler_rt_sub_path); - std.Io.Dir.copyFile( - crt_file.full_object_path.root_dir.handle, - crt_file.full_object_path.sub_path, - coff.base.emit.root_dir.handle, - compiler_rt_sub_path, - io, - .{}, - ) catch |err| return comp.link_diags.fail("copy '{s}' failed: {t}", .{ compiler_rt_sub_path, err }); - } - coff.mf.flush() catch |err| switch (err) { error.Canceled => |e| return e, 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 { } if (coff.pending_input) |pending_iami| { // TODO: Prog node? - coff.flushInputMember(pending_iami) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - else => |e| return comp.link_diags.fail( - "linker failed to archive member: {t}", - .{e}, - ), - }; coff.pending_input = null; + coff.flushInputMember(pending_iami) catch |err| switch (err) { + error.OutOfMemory => return error.OutOfMemory, + else => |e| return comp.link_diags.fail( + "linker failed to load archive member: {t}", + .{e}, + ), + }; break :task; } if (coff.global_pending_index < coff.globals.count()) {