authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-27 16:12:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 19:49:07-07:00
log6509c492ad7908c515a0c00751e1348b26dda4e7
tree4424e28452be76d1ad081d6284e1f625955efbee
parent791e83c22396e029e0f2bc19b75fd86f8cd7851f

move misc_errors from linker to Compilation

So that they can be referenced by getAllErrorsAlloc(). Fixes missing compile errors.

5 files changed, 130 insertions(+), 125 deletions(-)

src/Compilation.zig+68-65
......@@ -28,7 +28,9 @@ const libcxx = @import("libcxx.zig");
2828const wasi_libc = @import("wasi_libc.zig");
2929const fatal = @import("main.zig").fatal;
3030const clangMain = @import("main.zig").clangMain;
31const Module = @import("Module.zig");
31const Zcu = @import("Module.zig");
32/// Deprecated; use `Zcu`.
33const Module = Zcu;
3234const InternPool = @import("InternPool.zig");
3335const Cache = std.Build.Cache;
3436const c_codegen = @import("codegen/c.zig");
......@@ -97,6 +99,7 @@ win32_resource_table: if (build_options.only_core_functionality) void else std.A
9799 if (build_options.only_core_functionality) {} else .{},
98100
99101link_error_flags: link.File.ErrorFlags = .{},
102link_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{},
100103lld_errors: std.ArrayListUnmanaged(LldError) = .{},
101104
102105work_queue: std.fifo.LinearFifo(Job, .Dynamic),
......@@ -1874,87 +1877,90 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {
18741877 return comp;
18751878}
18761879
1877pub fn destroy(self: *Compilation) void {
1878 if (self.bin_file) |lf| lf.destroy();
1879 if (self.module) |zcu| zcu.deinit();
1880 self.cache_use.deinit();
1881 self.work_queue.deinit();
1882 self.anon_work_queue.deinit();
1883 self.c_object_work_queue.deinit();
1880pub fn destroy(comp: *Compilation) void {
1881 if (comp.bin_file) |lf| lf.destroy();
1882 if (comp.module) |zcu| zcu.deinit();
1883 comp.cache_use.deinit();
1884 comp.work_queue.deinit();
1885 comp.anon_work_queue.deinit();
1886 comp.c_object_work_queue.deinit();
18841887 if (!build_options.only_core_functionality) {
1885 self.win32_resource_work_queue.deinit();
1888 comp.win32_resource_work_queue.deinit();
18861889 }
1887 self.astgen_work_queue.deinit();
1888 self.embed_file_work_queue.deinit();
1890 comp.astgen_work_queue.deinit();
1891 comp.embed_file_work_queue.deinit();
18891892
1890 const gpa = self.gpa;
1891 self.system_libs.deinit(gpa);
1893 const gpa = comp.gpa;
1894 comp.system_libs.deinit(gpa);
18921895
18931896 {
1894 var it = self.crt_files.iterator();
1897 var it = comp.crt_files.iterator();
18951898 while (it.next()) |entry| {
18961899 gpa.free(entry.key_ptr.*);
18971900 entry.value_ptr.deinit(gpa);
18981901 }
1899 self.crt_files.deinit(gpa);
1902 comp.crt_files.deinit(gpa);
19001903 }
19011904
1902 if (self.libunwind_static_lib) |*crt_file| {
1905 if (comp.libunwind_static_lib) |*crt_file| {
19031906 crt_file.deinit(gpa);
19041907 }
1905 if (self.libcxx_static_lib) |*crt_file| {
1908 if (comp.libcxx_static_lib) |*crt_file| {
19061909 crt_file.deinit(gpa);
19071910 }
1908 if (self.libcxxabi_static_lib) |*crt_file| {
1911 if (comp.libcxxabi_static_lib) |*crt_file| {
19091912 crt_file.deinit(gpa);
19101913 }
1911 if (self.compiler_rt_lib) |*crt_file| {
1914 if (comp.compiler_rt_lib) |*crt_file| {
19121915 crt_file.deinit(gpa);
19131916 }
1914 if (self.compiler_rt_obj) |*crt_file| {
1917 if (comp.compiler_rt_obj) |*crt_file| {
19151918 crt_file.deinit(gpa);
19161919 }
1917 if (self.libc_static_lib) |*crt_file| {
1920 if (comp.libc_static_lib) |*crt_file| {
19181921 crt_file.deinit(gpa);
19191922 }
19201923
1921 if (self.glibc_so_files) |*glibc_file| {
1924 if (comp.glibc_so_files) |*glibc_file| {
19221925 glibc_file.deinit(gpa);
19231926 }
19241927
1925 for (self.c_object_table.keys()) |key| {
1928 for (comp.c_object_table.keys()) |key| {
19261929 key.destroy(gpa);
19271930 }
1928 self.c_object_table.deinit(gpa);
1931 comp.c_object_table.deinit(gpa);
19291932
1930 for (self.failed_c_objects.values()) |bundle| {
1933 for (comp.failed_c_objects.values()) |bundle| {
19311934 bundle.destroy(gpa);
19321935 }
1933 self.failed_c_objects.deinit(gpa);
1936 comp.failed_c_objects.deinit(gpa);
19341937
19351938 if (!build_options.only_core_functionality) {
1936 for (self.win32_resource_table.keys()) |key| {
1939 for (comp.win32_resource_table.keys()) |key| {
19371940 key.destroy(gpa);
19381941 }
1939 self.win32_resource_table.deinit(gpa);
1942 comp.win32_resource_table.deinit(gpa);
19401943
1941 for (self.failed_win32_resources.values()) |*value| {
1944 for (comp.failed_win32_resources.values()) |*value| {
19421945 value.deinit(gpa);
19431946 }
1944 self.failed_win32_resources.deinit(gpa);
1947 comp.failed_win32_resources.deinit(gpa);
19451948 }
19461949
1947 for (self.lld_errors.items) |*lld_error| {
1950 for (comp.link_errors.items) |*item| item.deinit(gpa);
1951 comp.link_errors.deinit(gpa);
1952
1953 for (comp.lld_errors.items) |*lld_error| {
19481954 lld_error.deinit(gpa);
19491955 }
1950 self.lld_errors.deinit(gpa);
1956 comp.lld_errors.deinit(gpa);
19511957
1952 self.clearMiscFailures();
1958 comp.clearMiscFailures();
19531959
1954 self.cache_parent.manifest_dir.close();
1960 comp.cache_parent.manifest_dir.close();
19551961
1956 // This destroys `self`.
1957 var arena_instance = self.arena;
1962 // This destroys `comp`.
1963 var arena_instance = comp.arena;
19581964 arena_instance.deinit();
19591965}
19601966
......@@ -2214,7 +2220,6 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
22142220 error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr
22152221 else => |e| return e,
22162222 };
2217 comp.link_error_flags = lf.error_flags;
22182223 }
22192224
22202225 if (comp.module) |module| {
......@@ -2745,23 +2750,23 @@ fn addBuf(bufs_list: []std.os.iovec_const, bufs_len: *usize, buf: []const u8) vo
27452750}
27462751
27472752/// This function is temporally single-threaded.
2748pub fn totalErrorCount(self: *Compilation) u32 {
2753pub fn totalErrorCount(comp: *Compilation) u32 {
27492754 var total: usize =
2750 self.misc_failures.count() +
2751 @intFromBool(self.alloc_failure_occurred) +
2752 self.lld_errors.items.len;
2755 comp.misc_failures.count() +
2756 @intFromBool(comp.alloc_failure_occurred) +
2757 comp.lld_errors.items.len;
27532758
2754 for (self.failed_c_objects.values()) |bundle| {
2759 for (comp.failed_c_objects.values()) |bundle| {
27552760 total += bundle.diags.len;
27562761 }
27572762
27582763 if (!build_options.only_core_functionality) {
2759 for (self.failed_win32_resources.values()) |errs| {
2764 for (comp.failed_win32_resources.values()) |errs| {
27602765 total += errs.errorMessageCount();
27612766 }
27622767 }
27632768
2764 if (self.module) |module| {
2769 if (comp.module) |module| {
27652770 total += module.failed_exports.count();
27662771 total += module.failed_embed_files.count();
27672772
......@@ -2804,17 +2809,15 @@ pub fn totalErrorCount(self: *Compilation) u32 {
28042809
28052810 // The "no entry point found" error only counts if there are no semantic analysis errors.
28062811 if (total == 0) {
2807 total += @intFromBool(self.link_error_flags.no_entry_point_found);
2812 total += @intFromBool(comp.link_error_flags.no_entry_point_found);
28082813 }
2809 total += @intFromBool(self.link_error_flags.missing_libc);
2814 total += @intFromBool(comp.link_error_flags.missing_libc);
28102815
2811 if (self.bin_file) |lf| {
2812 total += lf.misc_errors.items.len;
2813 }
2816 total += comp.link_errors.items.len;
28142817
28152818 // Compile log errors only count if there are no other errors.
28162819 if (total == 0) {
2817 if (self.module) |module| {
2820 if (comp.module) |module| {
28182821 total += @intFromBool(module.compile_log_decls.count() != 0);
28192822 }
28202823 }
......@@ -2823,24 +2826,24 @@ pub fn totalErrorCount(self: *Compilation) u32 {
28232826}
28242827
28252828/// This function is temporally single-threaded.
2826pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
2827 const gpa = self.gpa;
2829pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
2830 const gpa = comp.gpa;
28282831
28292832 var bundle: ErrorBundle.Wip = undefined;
28302833 try bundle.init(gpa);
28312834 defer bundle.deinit();
28322835
2833 for (self.failed_c_objects.values()) |diag_bundle| {
2836 for (comp.failed_c_objects.values()) |diag_bundle| {
28342837 try diag_bundle.addToErrorBundle(&bundle);
28352838 }
28362839
28372840 if (!build_options.only_core_functionality) {
2838 for (self.failed_win32_resources.values()) |error_bundle| {
2841 for (comp.failed_win32_resources.values()) |error_bundle| {
28392842 try bundle.addBundleAsRoots(error_bundle);
28402843 }
28412844 }
28422845
2843 for (self.lld_errors.items) |lld_error| {
2846 for (comp.lld_errors.items) |lld_error| {
28442847 const notes_len = @as(u32, @intCast(lld_error.context_lines.len));
28452848
28462849 try bundle.addRootErrorMessage(.{
......@@ -2854,19 +2857,19 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
28542857 }));
28552858 }
28562859 }
2857 for (self.misc_failures.values()) |*value| {
2860 for (comp.misc_failures.values()) |*value| {
28582861 try bundle.addRootErrorMessage(.{
28592862 .msg = try bundle.addString(value.msg),
28602863 .notes_len = if (value.children) |b| b.errorMessageCount() else 0,
28612864 });
28622865 if (value.children) |b| try bundle.addBundleAsNotes(b);
28632866 }
2864 if (self.alloc_failure_occurred) {
2867 if (comp.alloc_failure_occurred) {
28652868 try bundle.addRootErrorMessage(.{
28662869 .msg = try bundle.addString("memory allocation failure"),
28672870 });
28682871 }
2869 if (self.module) |module| {
2872 if (comp.module) |module| {
28702873 for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| {
28712874 if (error_msg) |msg| {
28722875 try addModuleErrorMsg(module, &bundle, msg.*);
......@@ -2938,14 +2941,14 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
29382941 }
29392942
29402943 if (bundle.root_list.items.len == 0) {
2941 if (self.link_error_flags.no_entry_point_found) {
2944 if (comp.link_error_flags.no_entry_point_found) {
29422945 try bundle.addRootErrorMessage(.{
29432946 .msg = try bundle.addString("no entry point found"),
29442947 });
29452948 }
29462949 }
29472950
2948 if (self.link_error_flags.missing_libc) {
2951 if (comp.link_error_flags.missing_libc) {
29492952 try bundle.addRootErrorMessage(.{
29502953 .msg = try bundle.addString("libc not available"),
29512954 .notes_len = 2,
......@@ -2959,7 +2962,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
29592962 }));
29602963 }
29612964
2962 if (self.bin_file) |lf| for (lf.misc_errors.items) |link_err| {
2965 for (comp.link_errors.items) |link_err| {
29632966 try bundle.addRootErrorMessage(.{
29642967 .msg = try bundle.addString(link_err.msg),
29652968 .notes_len = @intCast(link_err.notes.len),
......@@ -2970,9 +2973,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
29702973 .msg = try bundle.addString(note.msg),
29712974 }));
29722975 }
2973 };
2976 }
29742977
2975 if (self.module) |module| {
2978 if (comp.module) |module| {
29762979 if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) {
29772980 const keys = module.compile_log_decls.keys();
29782981 const values = module.compile_log_decls.values();
......@@ -2998,9 +3001,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
29983001 }
29993002 }
30003003
3001 assert(self.totalErrorCount() == bundle.root_list.items.len);
3004 assert(comp.totalErrorCount() == bundle.root_list.items.len);
30023005
3003 const compile_log_text = if (self.module) |m| m.compile_log_text.items else "";
3006 const compile_log_text = if (comp.module) |m| m.compile_log_text.items else "";
30043007 return bundle.toOwnedBundle(compile_log_text);
30053008}
30063009
src/link.zig-8
......@@ -67,9 +67,6 @@ pub const File = struct {
6767 allow_shlib_undefined: bool,
6868 stack_size: u64,
6969
70 error_flags: ErrorFlags = .{},
71 misc_errors: std.ArrayListUnmanaged(ErrorMsg) = .{},
72
7370 /// Prevents other processes from clobbering files in the output directory
7471 /// of this linking operation.
7572 lock: ?Cache.Lock = null,
......@@ -465,13 +462,8 @@ pub const File = struct {
465462 }
466463
467464 pub fn destroy(base: *File) void {
468 const gpa = base.comp.gpa;
469465 base.releaseLock();
470466 if (base.file) |f| f.close();
471 {
472 for (base.misc_errors.items) |*item| item.deinit(gpa);
473 base.misc_errors.deinit(gpa);
474 }
475467 switch (base.tag) {
476468 .c => @fieldParentPtr(C, "base", base).deinit(),
477469
src/link/Coff.zig+2-2
......@@ -1839,10 +1839,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
18391839
18401840 if (self.entry_addr == null and comp.config.output_mode == .Exe) {
18411841 log.debug("flushing. no_entry_point_found = true\n", .{});
1842 self.base.error_flags.no_entry_point_found = true;
1842 comp.link_error_flags.no_entry_point_found = true;
18431843 } else {
18441844 log.debug("flushing. no_entry_point_found = false\n", .{});
1845 self.base.error_flags.no_entry_point_found = false;
1845 comp.link_error_flags.no_entry_point_found = false;
18461846 try self.writeHeader();
18471847 }
18481848
src/link/Elf.zig+29-26
......@@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11701170 }
11711171
11721172 // libc dep
1173 self.base.error_flags.missing_libc = false;
1173 comp.link_error_flags.missing_libc = false;
11741174 if (comp.config.link_libc) {
11751175 if (comp.libc_installation) |lc| {
11761176 const flags = target_util.libcFullLinkFlags(target);
......@@ -1221,7 +1221,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12211221 });
12221222 try system_libs.append(.{ .path = path });
12231223 } else {
1224 self.base.error_flags.missing_libc = true;
1224 comp.link_error_flags.missing_libc = true;
12251225 }
12261226 }
12271227
......@@ -1259,7 +1259,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12591259 };
12601260 }
12611261
1262 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1262 if (comp.link_errors.items.len > 0) return error.FlushFailure;
12631263
12641264 // Init all objects
12651265 for (self.objects.items) |index| {
......@@ -1269,7 +1269,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12691269 try self.file(index).?.shared_object.init(self);
12701270 }
12711271
1272 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1272 if (comp.link_errors.items.len > 0) return error.FlushFailure;
12731273
12741274 // Dedup shared objects
12751275 {
......@@ -1388,14 +1388,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
13881388
13891389 if (self.entry_index == null and self.base.isExe()) {
13901390 log.debug("flushing. no_entry_point_found = true", .{});
1391 self.base.error_flags.no_entry_point_found = true;
1391 comp.link_error_flags.no_entry_point_found = true;
13921392 } else {
13931393 log.debug("flushing. no_entry_point_found = false", .{});
1394 self.base.error_flags.no_entry_point_found = false;
1394 comp.link_error_flags.no_entry_point_found = false;
13951395 try self.writeElfHeader();
13961396 }
13971397
1398 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1398 if (comp.link_errors.items.len > 0) return error.FlushFailure;
13991399}
14001400
14011401pub 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
14271427 };
14281428 }
14291429
1430 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1430 if (comp.link_errors.items.len > 0) return error.FlushFailure;
14311431
14321432 // First, we flush relocatable object file generated with our backends.
14331433 if (self.zigObjectPtr()) |zig_object| {
......@@ -1539,7 +1539,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const
15391539 try self.base.file.?.setEndPos(total_size);
15401540 try self.base.file.?.pwriteAll(buffer.items, 0);
15411541
1542 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1542 if (comp.link_errors.items.len > 0) return error.FlushFailure;
15431543}
15441544
15451545pub 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)
15701570 };
15711571 }
15721572
1573 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1573 if (comp.link_errors.items.len > 0) return error.FlushFailure;
15741574
15751575 // Init all objects
15761576 for (self.objects.items) |index| {
15771577 try self.file(index).?.object.init(self);
15781578 }
15791579
1580 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1580 if (comp.link_errors.items.len > 0) return error.FlushFailure;
15811581
15821582 // Now, we are ready to resolve the symbols across all input files.
15831583 // 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)
16111611 try self.writeShdrTable();
16121612 try self.writeElfHeader();
16131613
1614 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
1614 if (comp.link_errors.items.len > 0) return error.FlushFailure;
16151615}
16161616
16171617/// --verbose-link output
......@@ -2888,7 +2888,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
28882888 }
28892889
28902890 // libc dep
2891 self.base.error_flags.missing_libc = false;
2891 comp.link_error_flags.missing_libc = false;
28922892 if (comp.config.link_libc) {
28932893 if (self.base.comp.libc_installation != null) {
28942894 const needs_grouping = link_mode == .Static;
......@@ -2909,7 +2909,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
29092909 .Dynamic => "libc.so",
29102910 }));
29112911 } else {
2912 self.base.error_flags.missing_libc = true;
2912 comp.link_error_flags.missing_libc = true;
29132913 }
29142914 }
29152915 }
......@@ -3132,7 +3132,8 @@ fn writePhdrTable(self: *Elf) !void {
31323132}
31333133
31343134fn writeElfHeader(self: *Elf) !void {
3135 if (self.base.misc_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable
3135 const comp = self.base.comp;
3136 if (comp.link_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable
31363137
31373138 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined;
31383139
......@@ -3146,7 +3147,6 @@ fn writeElfHeader(self: *Elf) !void {
31463147 };
31473148 index += 1;
31483149
3149 const comp = self.base.comp;
31503150 const target = comp.root_mod.resolved_target.result;
31513151 const endian = target.cpu.arch.endian();
31523152 hdr_buf[index] = switch (endian) {
......@@ -6055,7 +6055,7 @@ pub fn tlsAddress(self: *Elf) u64 {
60556055}
60566056
60576057const ErrorWithNotes = struct {
6058 /// Allocated index in misc_errors array.
6058 /// Allocated index in comp.link_errors array.
60596059 index: usize,
60606060
60616061 /// Next available note slot.
......@@ -6069,7 +6069,7 @@ const ErrorWithNotes = struct {
60696069 ) error{OutOfMemory}!void {
60706070 const comp = elf_file.base.comp;
60716071 const gpa = comp.gpa;
6072 const err_msg = &elf_file.base.misc_errors.items[err.index];
6072 const err_msg = &comp.link_errors.items[err.index];
60736073 err_msg.msg = try std.fmt.allocPrint(gpa, format, args);
60746074 }
60756075
......@@ -6081,7 +6081,7 @@ const ErrorWithNotes = struct {
60816081 ) error{OutOfMemory}!void {
60826082 const comp = elf_file.base.comp;
60836083 const gpa = comp.gpa;
6084 const err_msg = &elf_file.base.misc_errors.items[err.index];
6084 const err_msg = &comp.link_errors.items[err.index];
60856085 assert(err.note_slot < err_msg.notes.len);
60866086 err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) };
60876087 err.note_slot += 1;
......@@ -6089,15 +6089,17 @@ const ErrorWithNotes = struct {
60896089};
60906090
60916091pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
6092 const gpa = self.base.comp.gpa;
6093 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
6092 const comp = self.base.comp;
6093 const gpa = comp.gpa;
6094 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
60946095 return self.addErrorWithNotesAssumeCapacity(note_count);
60956096}
60966097
60976098fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
6098 const gpa = self.base.comp.gpa;
6099 const index = self.base.misc_errors.items.len;
6100 const err = self.base.misc_errors.addOneAssumeCapacity();
6099 const comp = self.base.comp;
6100 const gpa = comp.gpa;
6101 const index = comp.link_errors.items.len;
6102 const err = comp.link_errors.addOneAssumeCapacity();
61016103 err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) };
61026104 return .{ .index = index };
61036105}
......@@ -6129,10 +6131,11 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 {
61296131}
61306132
61316133fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void {
6132 const gpa = self.base.comp.gpa;
6134 const comp = self.base.comp;
6135 const gpa = comp.gpa;
61336136 const max_notes = 4;
61346137
6135 try self.base.misc_errors.ensureUnusedCapacity(gpa, undefs.count());
6138 try comp.link_errors.ensureUnusedCapacity(gpa, undefs.count());
61366139
61376140 var it = undefs.iterator();
61386141 while (it.next()) |entry| {
src/link/MachO.zig+31-24
......@@ -323,8 +323,8 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li
323323 if (build_options.have_llvm) {
324324 return self.base.linkAsArchive(comp, prog_node);
325325 } else {
326 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
327 self.base.misc_errors.appendAssumeCapacity(.{
326 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
327 comp.link_errors.appendAssumeCapacity(.{
328328 .msg = try gpa.dupe(u8, "TODO: non-LLVM archiver for MachO object files"),
329329 });
330330 return error.FlushFailure;
......@@ -426,7 +426,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
426426 try self.resolveSymbols();
427427
428428 if (self.getEntryPoint() == null) {
429 self.base.error_flags.no_entry_point_found = true;
429 comp.link_error_flags.no_entry_point_found = true;
430430 }
431431 if (self.unresolved.count() > 0) {
432432 try self.reportUndefined();
......@@ -5254,14 +5254,15 @@ fn reportMissingLibraryError(
52545254 comptime format: []const u8,
52555255 args: anytype,
52565256) error{OutOfMemory}!void {
5257 const gpa = self.base.comp.gpa;
5258 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
5257 const comp = self.base.comp;
5258 const gpa = comp.gpa;
5259 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
52595260 const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len);
52605261 errdefer gpa.free(notes);
52615262 for (checked_paths, notes) |path, *note| {
52625263 note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) };
52635264 }
5264 self.base.misc_errors.appendAssumeCapacity(.{
5265 comp.link_errors.appendAssumeCapacity(.{
52655266 .msg = try std.fmt.allocPrint(gpa, format, args),
52665267 .notes = notes,
52675268 });
......@@ -5274,15 +5275,16 @@ fn reportDependencyError(
52745275 comptime format: []const u8,
52755276 args: anytype,
52765277) error{OutOfMemory}!void {
5277 const gpa = self.base.comp.gpa;
5278 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
5278 const comp = self.base.comp;
5279 const gpa = comp.gpa;
5280 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
52795281 var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2);
52805282 defer notes.deinit();
52815283 if (path) |p| {
52825284 notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{p}) });
52835285 }
52845286 notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "a dependency of {s}", .{parent}) });
5285 self.base.misc_errors.appendAssumeCapacity(.{
5287 comp.link_errors.appendAssumeCapacity(.{
52865288 .msg = try std.fmt.allocPrint(gpa, format, args),
52875289 .notes = try notes.toOwnedSlice(),
52885290 });
......@@ -5294,12 +5296,13 @@ pub fn reportParseError(
52945296 comptime format: []const u8,
52955297 args: anytype,
52965298) error{OutOfMemory}!void {
5297 const gpa = self.base.comp.gpa;
5298 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
5299 const comp = self.base.comp;
5300 const gpa = comp.gpa;
5301 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
52995302 var notes = try gpa.alloc(File.ErrorMsg, 1);
53005303 errdefer gpa.free(notes);
53015304 notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) };
5302 self.base.misc_errors.appendAssumeCapacity(.{
5305 comp.link_errors.appendAssumeCapacity(.{
53035306 .msg = try std.fmt.allocPrint(gpa, format, args),
53045307 .notes = notes,
53055308 });
......@@ -5311,21 +5314,23 @@ pub fn reportUnresolvedBoundarySymbol(
53115314 comptime format: []const u8,
53125315 args: anytype,
53135316) error{OutOfMemory}!void {
5314 const gpa = self.base.comp.gpa;
5315 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
5317 const comp = self.base.comp;
5318 const gpa = comp.gpa;
5319 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
53165320 var notes = try gpa.alloc(File.ErrorMsg, 1);
53175321 errdefer gpa.free(notes);
53185322 notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while resolving {s}", .{sym_name}) };
5319 self.base.misc_errors.appendAssumeCapacity(.{
5323 comp.link_errors.appendAssumeCapacity(.{
53205324 .msg = try std.fmt.allocPrint(gpa, format, args),
53215325 .notes = notes,
53225326 });
53235327}
53245328
53255329pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void {
5326 const gpa = self.base.comp.gpa;
5330 const comp = self.base.comp;
5331 const gpa = comp.gpa;
53275332 const count = self.unresolved.count();
5328 try self.base.misc_errors.ensureUnusedCapacity(gpa, count);
5333 try comp.link_errors.ensureUnusedCapacity(gpa, count);
53295334
53305335 for (self.unresolved.keys()) |global_index| {
53315336 const global = self.globals.items[global_index];
......@@ -5346,7 +5351,7 @@ pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void {
53465351 };
53475352 err_msg.notes = try notes.toOwnedSlice();
53485353
5349 self.base.misc_errors.appendAssumeCapacity(err_msg);
5354 comp.link_errors.appendAssumeCapacity(err_msg);
53505355 }
53515356}
53525357
......@@ -5355,8 +5360,9 @@ fn reportSymbolCollision(
53555360 first: SymbolWithLoc,
53565361 other: SymbolWithLoc,
53575362) error{OutOfMemory}!void {
5358 const gpa = self.base.comp.gpa;
5359 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
5363 const comp = self.base.comp;
5364 const gpa = comp.gpa;
5365 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
53605366
53615367 var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2);
53625368 defer notes.deinit();
......@@ -5379,12 +5385,13 @@ fn reportSymbolCollision(
53795385 }) };
53805386 err_msg.notes = try notes.toOwnedSlice();
53815387
5382 self.base.misc_errors.appendAssumeCapacity(err_msg);
5388 comp.link_errors.appendAssumeCapacity(err_msg);
53835389}
53845390
53855391fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{OutOfMemory}!void {
5386 const gpa = self.base.comp.gpa;
5387 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
5392 const comp = self.base.comp;
5393 const gpa = comp.gpa;
5394 try comp.link_errors.ensureUnusedCapacity(gpa, 1);
53885395
53895396 const notes = try gpa.alloc(File.ErrorMsg, 1);
53905397 errdefer gpa.free(notes);
......@@ -5402,7 +5409,7 @@ fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{Ou
54025409 else
54035410 unreachable;
54045411
5405 self.base.misc_errors.appendAssumeCapacity(.{
5412 comp.link_errors.appendAssumeCapacity(.{
54065413 .msg = try std.fmt.allocPrint(gpa, "unhandled symbol type: '{s}' has type {s}", .{
54075414 self.getSymbolName(sym_with_loc),
54085415 sym_type,