diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-12-27 16:12:06 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-01-01 19:49:07 -0700 |
| commit | 6509c492ad7908c515a0c00751e1348b26dda4e7 (patch) | |
| tree | 4424e28452be76d1ad081d6284e1f625955efbee /src | |
| parent | 791e83c22396e029e0f2bc19b75fd86f8cd7851f (diff) | |
| download | zig-6509c492ad7908c515a0c00751e1348b26dda4e7.tar.gz zig-6509c492ad7908c515a0c00751e1348b26dda4e7.zip | |
move misc_errors from linker to Compilation
So that they can be referenced by getAllErrorsAlloc(). Fixes missing
compile errors.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 133 | ||||
| -rw-r--r-- | src/link.zig | 8 | ||||
| -rw-r--r-- | src/link/Coff.zig | 4 | ||||
| -rw-r--r-- | src/link/Elf.zig | 55 | ||||
| -rw-r--r-- | src/link/MachO.zig | 55 |
5 files changed, 130 insertions, 125 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 6b0bd7345c..cb47a5d88a 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -28,7 +28,9 @@ const libcxx = @import("libcxx.zig"); const wasi_libc = @import("wasi_libc.zig"); const fatal = @import("main.zig").fatal; const clangMain = @import("main.zig").clangMain; -const Module = @import("Module.zig"); +const Zcu = @import("Module.zig"); +/// Deprecated; use `Zcu`. +const Module = Zcu; const InternPool = @import("InternPool.zig"); const Cache = std.Build.Cache; const c_codegen = @import("codegen/c.zig"); @@ -97,6 +99,7 @@ win32_resource_table: if (build_options.only_core_functionality) void else std.A if (build_options.only_core_functionality) {} else .{}, link_error_flags: link.File.ErrorFlags = .{}, +link_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{}, lld_errors: std.ArrayListUnmanaged(LldError) = .{}, work_queue: std.fifo.LinearFifo(Job, .Dynamic), @@ -1874,87 +1877,90 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation { return comp; } -pub fn destroy(self: *Compilation) void { - if (self.bin_file) |lf| lf.destroy(); - if (self.module) |zcu| zcu.deinit(); - self.cache_use.deinit(); - self.work_queue.deinit(); - self.anon_work_queue.deinit(); - self.c_object_work_queue.deinit(); +pub fn destroy(comp: *Compilation) void { + if (comp.bin_file) |lf| lf.destroy(); + if (comp.module) |zcu| zcu.deinit(); + comp.cache_use.deinit(); + comp.work_queue.deinit(); + comp.anon_work_queue.deinit(); + comp.c_object_work_queue.deinit(); if (!build_options.only_core_functionality) { - self.win32_resource_work_queue.deinit(); + comp.win32_resource_work_queue.deinit(); } - self.astgen_work_queue.deinit(); - self.embed_file_work_queue.deinit(); + comp.astgen_work_queue.deinit(); + comp.embed_file_work_queue.deinit(); - const gpa = self.gpa; - self.system_libs.deinit(gpa); + const gpa = comp.gpa; + comp.system_libs.deinit(gpa); { - var it = self.crt_files.iterator(); + var it = comp.crt_files.iterator(); while (it.next()) |entry| { gpa.free(entry.key_ptr.*); entry.value_ptr.deinit(gpa); } - self.crt_files.deinit(gpa); + comp.crt_files.deinit(gpa); } - if (self.libunwind_static_lib) |*crt_file| { + if (comp.libunwind_static_lib) |*crt_file| { crt_file.deinit(gpa); } - if (self.libcxx_static_lib) |*crt_file| { + if (comp.libcxx_static_lib) |*crt_file| { crt_file.deinit(gpa); } - if (self.libcxxabi_static_lib) |*crt_file| { + if (comp.libcxxabi_static_lib) |*crt_file| { crt_file.deinit(gpa); } - if (self.compiler_rt_lib) |*crt_file| { + if (comp.compiler_rt_lib) |*crt_file| { crt_file.deinit(gpa); } - if (self.compiler_rt_obj) |*crt_file| { + if (comp.compiler_rt_obj) |*crt_file| { crt_file.deinit(gpa); } - if (self.libc_static_lib) |*crt_file| { + if (comp.libc_static_lib) |*crt_file| { crt_file.deinit(gpa); } - if (self.glibc_so_files) |*glibc_file| { + if (comp.glibc_so_files) |*glibc_file| { glibc_file.deinit(gpa); } - for (self.c_object_table.keys()) |key| { + for (comp.c_object_table.keys()) |key| { key.destroy(gpa); } - self.c_object_table.deinit(gpa); + comp.c_object_table.deinit(gpa); - for (self.failed_c_objects.values()) |bundle| { + for (comp.failed_c_objects.values()) |bundle| { bundle.destroy(gpa); } - self.failed_c_objects.deinit(gpa); + comp.failed_c_objects.deinit(gpa); if (!build_options.only_core_functionality) { - for (self.win32_resource_table.keys()) |key| { + for (comp.win32_resource_table.keys()) |key| { key.destroy(gpa); } - self.win32_resource_table.deinit(gpa); + comp.win32_resource_table.deinit(gpa); - for (self.failed_win32_resources.values()) |*value| { + for (comp.failed_win32_resources.values()) |*value| { value.deinit(gpa); } - self.failed_win32_resources.deinit(gpa); + comp.failed_win32_resources.deinit(gpa); } - for (self.lld_errors.items) |*lld_error| { + for (comp.link_errors.items) |*item| item.deinit(gpa); + comp.link_errors.deinit(gpa); + + for (comp.lld_errors.items) |*lld_error| { lld_error.deinit(gpa); } - self.lld_errors.deinit(gpa); + comp.lld_errors.deinit(gpa); - self.clearMiscFailures(); + comp.clearMiscFailures(); - self.cache_parent.manifest_dir.close(); + comp.cache_parent.manifest_dir.close(); - // This destroys `self`. - var arena_instance = self.arena; + // This destroys `comp`. + var arena_instance = comp.arena; arena_instance.deinit(); } @@ -2214,7 +2220,6 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr else => |e| return e, }; - comp.link_error_flags = lf.error_flags; } if (comp.module) |module| { @@ -2745,23 +2750,23 @@ fn addBuf(bufs_list: []std.os.iovec_const, bufs_len: *usize, buf: []const u8) vo } /// This function is temporally single-threaded. -pub fn totalErrorCount(self: *Compilation) u32 { +pub fn totalErrorCount(comp: *Compilation) u32 { var total: usize = - self.misc_failures.count() + - @intFromBool(self.alloc_failure_occurred) + - self.lld_errors.items.len; + comp.misc_failures.count() + + @intFromBool(comp.alloc_failure_occurred) + + comp.lld_errors.items.len; - for (self.failed_c_objects.values()) |bundle| { + for (comp.failed_c_objects.values()) |bundle| { total += bundle.diags.len; } if (!build_options.only_core_functionality) { - for (self.failed_win32_resources.values()) |errs| { + for (comp.failed_win32_resources.values()) |errs| { total += errs.errorMessageCount(); } } - if (self.module) |module| { + if (comp.module) |module| { total += module.failed_exports.count(); total += module.failed_embed_files.count(); @@ -2804,17 +2809,15 @@ pub fn totalErrorCount(self: *Compilation) u32 { // The "no entry point found" error only counts if there are no semantic analysis errors. if (total == 0) { - total += @intFromBool(self.link_error_flags.no_entry_point_found); + total += @intFromBool(comp.link_error_flags.no_entry_point_found); } - total += @intFromBool(self.link_error_flags.missing_libc); + total += @intFromBool(comp.link_error_flags.missing_libc); - if (self.bin_file) |lf| { - total += lf.misc_errors.items.len; - } + total += comp.link_errors.items.len; // Compile log errors only count if there are no other errors. if (total == 0) { - if (self.module) |module| { + if (comp.module) |module| { total += @intFromBool(module.compile_log_decls.count() != 0); } } @@ -2823,24 +2826,24 @@ pub fn totalErrorCount(self: *Compilation) u32 { } /// This function is temporally single-threaded. -pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { - const gpa = self.gpa; +pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { + const gpa = comp.gpa; var bundle: ErrorBundle.Wip = undefined; try bundle.init(gpa); defer bundle.deinit(); - for (self.failed_c_objects.values()) |diag_bundle| { + for (comp.failed_c_objects.values()) |diag_bundle| { try diag_bundle.addToErrorBundle(&bundle); } if (!build_options.only_core_functionality) { - for (self.failed_win32_resources.values()) |error_bundle| { + for (comp.failed_win32_resources.values()) |error_bundle| { try bundle.addBundleAsRoots(error_bundle); } } - for (self.lld_errors.items) |lld_error| { + for (comp.lld_errors.items) |lld_error| { const notes_len = @as(u32, @intCast(lld_error.context_lines.len)); try bundle.addRootErrorMessage(.{ @@ -2854,19 +2857,19 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { })); } } - for (self.misc_failures.values()) |*value| { + for (comp.misc_failures.values()) |*value| { try bundle.addRootErrorMessage(.{ .msg = try bundle.addString(value.msg), .notes_len = if (value.children) |b| b.errorMessageCount() else 0, }); if (value.children) |b| try bundle.addBundleAsNotes(b); } - if (self.alloc_failure_occurred) { + if (comp.alloc_failure_occurred) { try bundle.addRootErrorMessage(.{ .msg = try bundle.addString("memory allocation failure"), }); } - if (self.module) |module| { + if (comp.module) |module| { for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| { if (error_msg) |msg| { try addModuleErrorMsg(module, &bundle, msg.*); @@ -2938,14 +2941,14 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { } if (bundle.root_list.items.len == 0) { - if (self.link_error_flags.no_entry_point_found) { + if (comp.link_error_flags.no_entry_point_found) { try bundle.addRootErrorMessage(.{ .msg = try bundle.addString("no entry point found"), }); } } - if (self.link_error_flags.missing_libc) { + if (comp.link_error_flags.missing_libc) { try bundle.addRootErrorMessage(.{ .msg = try bundle.addString("libc not available"), .notes_len = 2, @@ -2959,7 +2962,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { })); } - if (self.bin_file) |lf| for (lf.misc_errors.items) |link_err| { + for (comp.link_errors.items) |link_err| { try bundle.addRootErrorMessage(.{ .msg = try bundle.addString(link_err.msg), .notes_len = @intCast(link_err.notes.len), @@ -2970,9 +2973,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { .msg = try bundle.addString(note.msg), })); } - }; + } - if (self.module) |module| { + if (comp.module) |module| { if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) { const keys = module.compile_log_decls.keys(); const values = module.compile_log_decls.values(); @@ -2998,9 +3001,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { } } - assert(self.totalErrorCount() == bundle.root_list.items.len); + assert(comp.totalErrorCount() == bundle.root_list.items.len); - const compile_log_text = if (self.module) |m| m.compile_log_text.items else ""; + const compile_log_text = if (comp.module) |m| m.compile_log_text.items else ""; return bundle.toOwnedBundle(compile_log_text); } diff --git a/src/link.zig b/src/link.zig index 065779177e..e60571a473 100644 --- a/src/link.zig +++ b/src/link.zig @@ -67,9 +67,6 @@ pub const File = struct { allow_shlib_undefined: bool, stack_size: u64, - error_flags: ErrorFlags = .{}, - misc_errors: std.ArrayListUnmanaged(ErrorMsg) = .{}, - /// Prevents other processes from clobbering files in the output directory /// of this linking operation. lock: ?Cache.Lock = null, @@ -465,13 +462,8 @@ pub const File = struct { } pub fn destroy(base: *File) void { - const gpa = base.comp.gpa; base.releaseLock(); if (base.file) |f| f.close(); - { - for (base.misc_errors.items) |*item| item.deinit(gpa); - base.misc_errors.deinit(gpa); - } switch (base.tag) { .c => @fieldParentPtr(C, "base", base).deinit(), diff --git a/src/link/Coff.zig b/src/link/Coff.zig index aefecb014e..7c95c3803e 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1839,10 +1839,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod if (self.entry_addr == null and comp.config.output_mode == .Exe) { log.debug("flushing. no_entry_point_found = true\n", .{}); - self.base.error_flags.no_entry_point_found = true; + comp.link_error_flags.no_entry_point_found = true; } else { log.debug("flushing. no_entry_point_found = false\n", .{}); - self.base.error_flags.no_entry_point_found = false; + comp.link_error_flags.no_entry_point_found = false; try self.writeHeader(); } diff --git a/src/link/Elf.zig b/src/link/Elf.zig index f20282a802..a74b4b5ae6 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node } // libc dep - self.base.error_flags.missing_libc = false; + comp.link_error_flags.missing_libc = false; if (comp.config.link_libc) { if (comp.libc_installation) |lc| { const flags = target_util.libcFullLinkFlags(target); @@ -1221,7 +1221,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node }); try system_libs.append(.{ .path = path }); } else { - self.base.error_flags.missing_libc = true; + comp.link_error_flags.missing_libc = true; } } @@ -1259,7 +1259,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node }; } - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; // Init all objects for (self.objects.items) |index| { @@ -1269,7 +1269,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node try self.file(index).?.shared_object.init(self); } - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; // Dedup shared objects { @@ -1388,14 +1388,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node if (self.entry_index == null and self.base.isExe()) { log.debug("flushing. no_entry_point_found = true", .{}); - self.base.error_flags.no_entry_point_found = true; + comp.link_error_flags.no_entry_point_found = true; } else { log.debug("flushing. no_entry_point_found = false", .{}); - self.base.error_flags.no_entry_point_found = false; + comp.link_error_flags.no_entry_point_found = false; try self.writeElfHeader(); } - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; } pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { @@ -1427,7 +1427,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const }; } - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; // First, we flush relocatable object file generated with our backends. if (self.zigObjectPtr()) |zig_object| { @@ -1539,7 +1539,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const try self.base.file.?.setEndPos(total_size); try self.base.file.?.pwriteAll(buffer.items, 0); - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; } pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { @@ -1570,14 +1570,14 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) }; } - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; // Init all objects for (self.objects.items) |index| { try self.file(index).?.object.init(self); } - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; // Now, we are ready to resolve the symbols across all input files. // We will first resolve the files in the ZigObject, next in the parsed @@ -1611,7 +1611,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) try self.writeShdrTable(); try self.writeElfHeader(); - if (self.base.misc_errors.items.len > 0) return error.FlushFailure; + if (comp.link_errors.items.len > 0) return error.FlushFailure; } /// --verbose-link output @@ -2888,7 +2888,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v } // libc dep - self.base.error_flags.missing_libc = false; + comp.link_error_flags.missing_libc = false; if (comp.config.link_libc) { if (self.base.comp.libc_installation != null) { const needs_grouping = link_mode == .Static; @@ -2909,7 +2909,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v .Dynamic => "libc.so", })); } else { - self.base.error_flags.missing_libc = true; + comp.link_error_flags.missing_libc = true; } } } @@ -3132,7 +3132,8 @@ fn writePhdrTable(self: *Elf) !void { } fn writeElfHeader(self: *Elf) !void { - if (self.base.misc_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable + const comp = self.base.comp; + if (comp.link_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined; @@ -3146,7 +3147,6 @@ fn writeElfHeader(self: *Elf) !void { }; index += 1; - const comp = self.base.comp; const target = comp.root_mod.resolved_target.result; const endian = target.cpu.arch.endian(); hdr_buf[index] = switch (endian) { @@ -6055,7 +6055,7 @@ pub fn tlsAddress(self: *Elf) u64 { } const ErrorWithNotes = struct { - /// Allocated index in misc_errors array. + /// Allocated index in comp.link_errors array. index: usize, /// Next available note slot. @@ -6069,7 +6069,7 @@ const ErrorWithNotes = struct { ) error{OutOfMemory}!void { const comp = elf_file.base.comp; const gpa = comp.gpa; - const err_msg = &elf_file.base.misc_errors.items[err.index]; + const err_msg = &comp.link_errors.items[err.index]; err_msg.msg = try std.fmt.allocPrint(gpa, format, args); } @@ -6081,7 +6081,7 @@ const ErrorWithNotes = struct { ) error{OutOfMemory}!void { const comp = elf_file.base.comp; const gpa = comp.gpa; - const err_msg = &elf_file.base.misc_errors.items[err.index]; + const err_msg = &comp.link_errors.items[err.index]; assert(err.note_slot < err_msg.notes.len); err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) }; err.note_slot += 1; @@ -6089,15 +6089,17 @@ const ErrorWithNotes = struct { }; pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); return self.addErrorWithNotesAssumeCapacity(note_count); } fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { - const gpa = self.base.comp.gpa; - const index = self.base.misc_errors.items.len; - const err = self.base.misc_errors.addOneAssumeCapacity(); + const comp = self.base.comp; + const gpa = comp.gpa; + const index = comp.link_errors.items.len; + const err = comp.link_errors.addOneAssumeCapacity(); err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) }; return .{ .index = index }; } @@ -6129,10 +6131,11 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 { } fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void { - const gpa = self.base.comp.gpa; + const comp = self.base.comp; + const gpa = comp.gpa; const max_notes = 4; - try self.base.misc_errors.ensureUnusedCapacity(gpa, undefs.count()); + try comp.link_errors.ensureUnusedCapacity(gpa, undefs.count()); var it = undefs.iterator(); while (it.next()) |entry| { diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 6bf4d95ef4..c0a259d982 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -323,8 +323,8 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li if (build_options.have_llvm) { return self.base.linkAsArchive(comp, prog_node); } else { - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); - self.base.misc_errors.appendAssumeCapacity(.{ + try comp.link_errors.ensureUnusedCapacity(gpa, 1); + comp.link_errors.appendAssumeCapacity(.{ .msg = try gpa.dupe(u8, "TODO: non-LLVM archiver for MachO object files"), }); return error.FlushFailure; @@ -426,7 +426,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No try self.resolveSymbols(); if (self.getEntryPoint() == null) { - self.base.error_flags.no_entry_point_found = true; + comp.link_error_flags.no_entry_point_found = true; } if (self.unresolved.count() > 0) { try self.reportUndefined(); @@ -5254,14 +5254,15 @@ fn reportMissingLibraryError( comptime format: []const u8, args: anytype, ) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); errdefer gpa.free(notes); for (checked_paths, notes) |path, *note| { note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; } - self.base.misc_errors.appendAssumeCapacity(.{ + comp.link_errors.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, format, args), .notes = notes, }); @@ -5274,15 +5275,16 @@ fn reportDependencyError( comptime format: []const u8, args: anytype, ) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); defer notes.deinit(); if (path) |p| { notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{p}) }); } notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "a dependency of {s}", .{parent}) }); - self.base.misc_errors.appendAssumeCapacity(.{ + comp.link_errors.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, format, args), .notes = try notes.toOwnedSlice(), }); @@ -5294,12 +5296,13 @@ pub fn reportParseError( comptime format: []const u8, args: anytype, ) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); var notes = try gpa.alloc(File.ErrorMsg, 1); errdefer gpa.free(notes); notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) }; - self.base.misc_errors.appendAssumeCapacity(.{ + comp.link_errors.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, format, args), .notes = notes, }); @@ -5311,21 +5314,23 @@ pub fn reportUnresolvedBoundarySymbol( comptime format: []const u8, args: anytype, ) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); var notes = try gpa.alloc(File.ErrorMsg, 1); errdefer gpa.free(notes); notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while resolving {s}", .{sym_name}) }; - self.base.misc_errors.appendAssumeCapacity(.{ + comp.link_errors.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, format, args), .notes = notes, }); } pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; + const comp = self.base.comp; + const gpa = comp.gpa; const count = self.unresolved.count(); - try self.base.misc_errors.ensureUnusedCapacity(gpa, count); + try comp.link_errors.ensureUnusedCapacity(gpa, count); for (self.unresolved.keys()) |global_index| { const global = self.globals.items[global_index]; @@ -5346,7 +5351,7 @@ pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { }; err_msg.notes = try notes.toOwnedSlice(); - self.base.misc_errors.appendAssumeCapacity(err_msg); + comp.link_errors.appendAssumeCapacity(err_msg); } } @@ -5355,8 +5360,9 @@ fn reportSymbolCollision( first: SymbolWithLoc, other: SymbolWithLoc, ) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); defer notes.deinit(); @@ -5379,12 +5385,13 @@ fn reportSymbolCollision( }) }; err_msg.notes = try notes.toOwnedSlice(); - self.base.misc_errors.appendAssumeCapacity(err_msg); + comp.link_errors.appendAssumeCapacity(err_msg); } fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{OutOfMemory}!void { - const gpa = self.base.comp.gpa; - try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); + const comp = self.base.comp; + const gpa = comp.gpa; + try comp.link_errors.ensureUnusedCapacity(gpa, 1); const notes = try gpa.alloc(File.ErrorMsg, 1); errdefer gpa.free(notes); @@ -5402,7 +5409,7 @@ fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{Ou else unreachable; - self.base.misc_errors.appendAssumeCapacity(.{ + comp.link_errors.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "unhandled symbol type: '{s}' has type {s}", .{ self.getSymbolName(sym_with_loc), sym_type, |
