authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-14 18:47:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
logc49957dbe82d7f0db555160b50306335bfa03165
tree529e84e430b27c3e6f13cb7a2c956b0ee445339c
parentf54471b54c471bb6f8e51a1383be09d01c24d0c3

fix a round of compile errors caused by this branch


26 files changed, 411 insertions(+), 313 deletions(-)

src/Compilation.zig+95-58
......@@ -884,12 +884,32 @@ const CacheUse = union(CacheMode) {
884884 docs_sub_path: ?[]u8,
885885 lf_open_opts: link.File.OpenOptions,
886886 tmp_artifact_directory: ?Cache.Directory,
887 /// Prevents other processes from clobbering files in the output directory.
888 lock: ?Cache.Lock,
889
890 fn releaseLock(whole: *Whole) void {
891 if (whole.lock) |*lock| {
892 lock.release();
893 whole.lock = null;
894 }
895 }
887896 };
888897
889898 const Incremental = struct {
890899 /// Where build artifacts and incremental compilation metadata serialization go.
891900 artifact_directory: Compilation.Directory,
892901 };
902
903 fn deinit(cu: CacheUse) void {
904 switch (cu) {
905 .incremental => |incremental| {
906 incremental.artifact_directory.handle.close();
907 },
908 .whole => |whole| {
909 whole.releaseLock();
910 },
911 }
912 }
893913};
894914
895915pub const LinkObject = struct {
......@@ -916,7 +936,7 @@ pub const InitOptions = struct {
916936 /// Normally, `main_mod` and `root_mod` are the same. The exception is `zig
917937 /// test`, in which `root_mod` is the test runner, and `main_mod` is the
918938 /// user's source file which has the tests.
919 main_mod: ?*Package.Module,
939 main_mod: ?*Package.Module = null,
920940 /// This is provided so that the API user has a chance to tweak the
921941 /// per-module settings of the standard library.
922942 std_mod: *Package.Module,
......@@ -1615,6 +1635,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16151635 .implib_sub_path = try prepareWholeEmitSubPath(arena, options.emit_implib),
16161636 .docs_sub_path = try prepareWholeEmitSubPath(arena, options.emit_docs),
16171637 .tmp_artifact_directory = null,
1638 .lock = null,
16181639 };
16191640 comp.cache_use = .{ .whole = whole };
16201641 },
......@@ -1822,13 +1843,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
18221843pub fn destroy(self: *Compilation) void {
18231844 if (self.bin_file) |lf| lf.destroy();
18241845 if (self.module) |zcu| zcu.deinit();
1825 switch (self.cache_use) {
1826 .incremental => |incremental| {
1827 incremental.artifact_directory.handle.close();
1828 },
1829 .whole => {},
1830 }
1831
1846 self.cache_use.deinit();
18321847 self.work_queue.deinit();
18331848 self.anon_work_queue.deinit();
18341849 self.c_object_work_queue.deinit();
......@@ -1922,11 +1937,17 @@ pub fn getTarget(self: Compilation) Target {
19221937 return self.root_mod.resolved_target.result;
19231938}
19241939
1925pub fn hotCodeSwap(comp: *Compilation, prog_node: *std.Progress.Node, pid: std.ChildProcess.Id) !void {
1926 comp.bin_file.child_pid = pid;
1927 try comp.makeBinFileWritable();
1940/// Only legal to call when cache mode is incremental and a link file is present.
1941pub fn hotCodeSwap(
1942 comp: *Compilation,
1943 prog_node: *std.Progress.Node,
1944 pid: std.ChildProcess.Id,
1945) !void {
1946 const lf = comp.bin_file.?;
1947 lf.child_pid = pid;
1948 try lf.makeWritable();
19281949 try comp.update(prog_node);
1929 try comp.makeBinFileExecutable();
1950 try lf.makeExecutable();
19301951}
19311952
19321953fn cleanupAfterUpdate(comp: *Compilation) void {
......@@ -1941,7 +1962,7 @@ fn cleanupAfterUpdate(comp: *Compilation) void {
19411962 lf.destroy();
19421963 comp.bin_file = null;
19431964 }
1944 if (whole.tmp_artifact_directory) |directory| {
1965 if (whole.tmp_artifact_directory) |*directory| {
19451966 directory.handle.close();
19461967 if (directory.path) |p| comp.gpa.free(p);
19471968 whole.tmp_artifact_directory = null;
......@@ -1967,8 +1988,9 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
19671988 // C source files.
19681989 switch (comp.cache_use) {
19691990 .whole => |whole| {
1970 // We are about to obtain this lock, so here we give other processes a chance first.
19711991 assert(comp.bin_file == null);
1992 // We are about to obtain this lock, so here we give other processes a chance first.
1993 whole.releaseLock();
19721994
19731995 man = comp.cache_parent.obtain();
19741996 whole.cache_manifest = &man;
......@@ -1989,8 +2011,8 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
19892011
19902012 comp.wholeCacheModeSetBinFilePath(whole, &digest);
19912013
1992 assert(comp.bin_file.lock == null);
1993 comp.bin_file.lock = man.toOwnedLock();
2014 assert(whole.lock == null);
2015 whole.lock = man.toOwnedLock();
19942016 return;
19952017 }
19962018 log.debug("CacheMode.whole cache miss for {s}", .{comp.root_name});
......@@ -2158,7 +2180,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
21582180
21592181 // Rename the temporary directory into place.
21602182 // Close tmp dir and link.File to avoid open handle during rename.
2161 if (whole.tmp_artifact_directory) |tmp_directory| {
2183 if (whole.tmp_artifact_directory) |*tmp_directory| {
21622184 tmp_directory.handle.close();
21632185 if (tmp_directory.path) |p| comp.gpa.free(p);
21642186 whole.tmp_artifact_directory = null;
......@@ -2181,8 +2203,8 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void
21812203 log.warn("failed to write cache manifest: {s}", .{@errorName(err)});
21822204 };
21832205
2184 assert(comp.bin_file.lock == null);
2185 comp.bin_file.lock = man.toOwnedLock();
2206 assert(whole.lock == null);
2207 whole.lock = man.toOwnedLock();
21862208 },
21872209 .incremental => {},
21882210 }
......@@ -2263,13 +2285,15 @@ fn maybeGenerateAutodocs(comp: *Compilation, prog_node: *std.Progress.Node) !voi
22632285}
22642286
22652287fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void {
2266 // This is needed before reading the error flags.
2267 comp.bin_file.flush(comp, prog_node) catch |err| switch (err) {
2268 error.FlushFailure => {}, // error reported through link_error_flags
2269 error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr
2270 else => |e| return e,
2271 };
2272 comp.link_error_flags = comp.bin_file.errorFlags();
2288 if (comp.bin_file) |lf| {
2289 // This is needed before reading the error flags.
2290 lf.flush(comp, prog_node) catch |err| switch (err) {
2291 error.FlushFailure => {}, // error reported through link_error_flags
2292 error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr
2293 else => |e| return e,
2294 };
2295 comp.link_error_flags = lf.error_flags;
2296 }
22732297
22742298 if (comp.module) |module| {
22752299 try link.File.C.flushEmitH(module);
......@@ -2445,9 +2469,9 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24452469 .wasm => {
24462470 const wasm = lf.cast(link.File.Wasm).?;
24472471 man.hash.add(wasm.rdynamic);
2448 man.hash.add(wasm.initial_memory);
2449 man.hash.add(wasm.max_memory);
2450 man.hash.add(wasm.global_base);
2472 man.hash.addOptional(wasm.initial_memory);
2473 man.hash.addOptional(wasm.max_memory);
2474 man.hash.addOptional(wasm.global_base);
24512475 },
24522476 .macho => {
24532477 const macho = lf.cast(link.File.MachO).?;
......@@ -2626,12 +2650,14 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26262650/// binary is concerned. This will remove the write flag, or close the file,
26272651/// or whatever is needed so that it can be executed.
26282652/// After this, one must call` makeFileWritable` before calling `update`.
2629pub fn makeBinFileExecutable(self: *Compilation) !void {
2630 return self.bin_file.makeExecutable();
2653pub fn makeBinFileExecutable(comp: *Compilation) !void {
2654 const lf = comp.bin_file orelse return;
2655 return lf.makeExecutable();
26312656}
26322657
2633pub fn makeBinFileWritable(self: *Compilation) !void {
2634 return self.bin_file.makeWritable();
2658pub fn makeBinFileWritable(comp: *Compilation) !void {
2659 const lf = comp.bin_file orelse return;
2660 return lf.makeWritable();
26352661}
26362662
26372663const Header = extern struct {
......@@ -2764,8 +2790,9 @@ pub fn totalErrorCount(self: *Compilation) u32 {
27642790 }
27652791 total += @intFromBool(self.link_error_flags.missing_libc);
27662792
2767 // Misc linker errors
2768 total += self.bin_file.miscErrors().len;
2793 if (self.bin_file) |lf| {
2794 total += lf.misc_errors.items.len;
2795 }
27692796
27702797 // Compile log errors only count if there are no other errors.
27712798 if (total == 0) {
......@@ -2914,7 +2941,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
29142941 }));
29152942 }
29162943
2917 for (self.bin_file.miscErrors()) |link_err| {
2944 if (self.bin_file) |lf| for (lf.misc_errors.items) |link_err| {
29182945 try bundle.addRootErrorMessage(.{
29192946 .msg = try bundle.addString(link_err.msg),
29202947 .notes_len = @intCast(link_err.notes.len),
......@@ -2925,7 +2952,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle {
29252952 .msg = try bundle.addString(note.msg),
29262953 }));
29272954 }
2928 }
2955 };
29292956
29302957 if (self.module) |module| {
29312958 if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) {
......@@ -3246,12 +3273,12 @@ pub fn performAllTheWork(
32463273 // TODO put all the modules in a flat array to make them easy to iterate.
32473274 var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{};
32483275 defer seen.deinit(comp.gpa);
3249 try seen.put(comp.gpa, comp.root_mod);
3276 try seen.put(comp.gpa, comp.root_mod, {});
32503277 var i: usize = 0;
32513278 while (i < seen.count()) : (i += 1) {
32523279 const mod = seen.keys()[i];
32533280 for (mod.deps.values()) |dep|
3254 try seen.put(comp.gpa, dep);
3281 try seen.put(comp.gpa, dep, {});
32553282
32563283 const file = mod.builtin_file orelse continue;
32573284
......@@ -3459,7 +3486,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
34593486 const gpa = comp.gpa;
34603487 const module = comp.module.?;
34613488 const decl = module.declPtr(decl_index);
3462 comp.bin_file.updateDeclLineNumber(module, decl_index) catch |err| {
3489 const lf = comp.bin_file.?;
3490 lf.updateDeclLineNumber(module, decl_index) catch |err| {
34633491 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
34643492 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
34653493 gpa,
......@@ -3782,7 +3810,7 @@ pub fn obtainCObjectCacheManifest(
37823810 // that apply both to @cImport and compiling C objects. No linking stuff here!
37833811 // Also nothing that applies only to compiling .zig code.
37843812 man.hash.add(owner_mod.sanitize_c);
3785 man.hash.addListOfBytes(owner_mod.clang_argv);
3813 man.hash.addListOfBytes(owner_mod.cc_argv);
37863814 man.hash.add(comp.config.link_libcpp);
37873815
37883816 // When libc_installation is null it means that Zig generated this dir list
......@@ -6099,7 +6127,8 @@ fn buildOutputFromZig(
60996127 const tracy_trace = trace(@src());
61006128 defer tracy_trace.end();
61016129
6102 var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);
6130 const gpa = comp.gpa;
6131 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
61036132 defer arena_allocator.deinit();
61046133 const arena = arena_allocator.allocator();
61056134
......@@ -6110,6 +6139,7 @@ fn buildOutputFromZig(
61106139
61116140 const config = try Config.resolve(.{
61126141 .output_mode = output_mode,
6142 .link_mode = .Static,
61136143 .resolved_target = comp.root_mod.resolved_target,
61146144 .is_test = false,
61156145 .have_zcu = true,
......@@ -6120,7 +6150,8 @@ fn buildOutputFromZig(
61206150 .any_unwind_tables = unwind_tables,
61216151 });
61226152
6123 const root_mod = Package.Module.create(.{
6153 const root_mod = try Package.Module.create(arena, .{
6154 .global_cache_directory = comp.global_cache_directory,
61246155 .paths = .{
61256156 .root = .{ .root_dir = comp.zig_lib_directory },
61266157 .root_src_path = src_basename,
......@@ -6139,6 +6170,8 @@ fn buildOutputFromZig(
61396170 },
61406171 .global = config,
61416172 .cc_argv = &.{},
6173 .parent = null,
6174 .builtin_mod = null,
61426175 });
61436176 const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len];
61446177 const target = comp.getTarget();
......@@ -6148,23 +6181,21 @@ fn buildOutputFromZig(
61486181 .output_mode = output_mode,
61496182 });
61506183
6151 const emit_bin = Compilation.EmitLoc{
6152 .directory = null, // Put it in the cache directory.
6153 .basename = bin_basename,
6154 };
6155 const sub_compilation = try Compilation.create(comp.gpa, .{
6184 const sub_compilation = try Compilation.create(gpa, .{
61566185 .global_cache_directory = comp.global_cache_directory,
61576186 .local_cache_directory = comp.global_cache_directory,
61586187 .zig_lib_directory = comp.zig_lib_directory,
61596188 .self_exe_path = comp.self_exe_path,
6160 .resolved = config,
6189 .config = config,
61616190 .root_mod = root_mod,
61626191 .cache_mode = .whole,
61636192 .root_name = root_name,
61646193 .thread_pool = comp.thread_pool,
61656194 .libc_installation = comp.libc_installation,
6166 .emit_bin = emit_bin,
6167 .link_mode = .Static,
6195 .emit_bin = .{
6196 .directory = null, // Put it in the cache directory.
6197 .basename = bin_basename,
6198 },
61686199 .function_sections = true,
61696200 .data_sections = true,
61706201 .no_builtin = true,
......@@ -6186,8 +6217,8 @@ fn buildOutputFromZig(
61866217 try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node);
61876218
61886219 assert(out.* == null);
6189 out.* = Compilation.CRTFile{
6190 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
6220 out.* = .{
6221 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &.{
61916222 sub_compilation.bin_file.?.emit.sub_path,
61926223 }),
61936224 .lock = sub_compilation.bin_file.toOwnedLock(),
......@@ -6206,12 +6237,15 @@ pub fn build_crt_file(
62066237 defer tracy_trace.end();
62076238
62086239 const gpa = comp.gpa;
6209 const basename = try std.zig.binNameAlloc(gpa, .{
6240 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
6241 defer arena_allocator.deinit();
6242 const arena = arena_allocator.allocator();
6243
6244 const basename = try std.zig.binNameAlloc(arena, .{
62106245 .root_name = root_name,
62116246 .target = comp.root_mod.resolved_target.result,
62126247 .output_mode = output_mode,
62136248 });
6214 errdefer gpa.free(basename);
62156249
62166250 const config = try Config.resolve(.{
62176251 .output_mode = output_mode,
......@@ -6227,7 +6261,8 @@ pub fn build_crt_file(
62276261 .Obj, .Exe => false,
62286262 },
62296263 });
6230 const root_mod = Package.Module.create(.{
6264 const root_mod = try Package.Module.create(arena, .{
6265 .global_cache_directory = comp.global_cache_directory,
62316266 .paths = .{
62326267 .root = .{ .root_dir = comp.zig_lib_directory },
62336268 .root_src_path = "",
......@@ -6249,6 +6284,8 @@ pub fn build_crt_file(
62496284 },
62506285 .global = config,
62516286 .cc_argv = &.{},
6287 .parent = null,
6288 .builtin_mod = null,
62526289 });
62536290
62546291 const sub_compilation = try Compilation.create(gpa, .{
......@@ -6257,7 +6294,7 @@ pub fn build_crt_file(
62576294 .zig_lib_directory = comp.zig_lib_directory,
62586295 .self_exe_path = comp.self_exe_path,
62596296 .cache_mode = .whole,
6260 .resolved = config,
6297 .config = config,
62616298 .root_mod = root_mod,
62626299 .root_name = root_name,
62636300 .thread_pool = comp.thread_pool,
......@@ -6287,7 +6324,7 @@ pub fn build_crt_file(
62876324 try comp.crt_files.ensureUnusedCapacity(gpa, 1);
62886325
62896326 comp.crt_files.putAssumeCapacityNoClobber(basename, .{
6290 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &[_][]const u8{
6327 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &.{
62916328 sub_compilation.bin_file.?.emit.sub_path,
62926329 }),
62936330 .lock = sub_compilation.bin_file.toOwnedLock(),
src/Module.zig+71-56
......@@ -619,7 +619,7 @@ pub const Decl = struct {
619619 // Sanitize the name for nvptx which is more restrictive.
620620 // TODO This should be handled by the backend, not the frontend. Have a
621621 // look at how the C backend does it for inspiration.
622 const cpu_arch = mod.root_mod.resolved_target.cpu.arch;
622 const cpu_arch = mod.root_mod.resolved_target.result.cpu.arch;
623623 if (cpu_arch.isNvptx()) {
624624 for (ip.string_bytes.items[start..]) |*byte| switch (byte.*) {
625625 '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_',
......@@ -3313,7 +3313,8 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr
33133313
33143314 if (no_bin_file and !dump_llvm_ir) return;
33153315
3316 comp.bin_file.updateFunc(mod, func_index, air, liveness) catch |err| switch (err) {
3316 const lf = comp.bin_file.?;
3317 lf.updateFunc(mod, func_index, air, liveness) catch |err| switch (err) {
33173318 error.OutOfMemory => return error.OutOfMemory,
33183319 error.AnalysisFail => {
33193320 decl.analysis = .codegen_failure;
......@@ -3488,25 +3489,29 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
34883489 new_decl.owns_tv = true;
34893490 new_decl.analysis = .complete;
34903491
3491 if (mod.comp.whole_cache_manifest) |whole_cache_manifest| {
3492 const source = file.getSource(gpa) catch |err| {
3493 try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)});
3494 return error.AnalysisFail;
3495 };
3492 const comp = mod.comp;
3493 switch (comp.cache_use) {
3494 .whole => |whole| if (whole.cache_manifest) |man| {
3495 const source = file.getSource(gpa) catch |err| {
3496 try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)});
3497 return error.AnalysisFail;
3498 };
34963499
3497 const resolved_path = std.fs.path.resolve(gpa, &.{
3498 file.mod.root.root_dir.path orelse ".",
3499 file.mod.root.sub_path,
3500 file.sub_file_path,
3501 }) catch |err| {
3502 try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)});
3503 return error.AnalysisFail;
3504 };
3505 errdefer gpa.free(resolved_path);
3500 const resolved_path = std.fs.path.resolve(gpa, &.{
3501 file.mod.root.root_dir.path orelse ".",
3502 file.mod.root.sub_path,
3503 file.sub_file_path,
3504 }) catch |err| {
3505 try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)});
3506 return error.AnalysisFail;
3507 };
3508 errdefer gpa.free(resolved_path);
35063509
3507 mod.comp.whole_cache_manifest_mutex.lock();
3508 defer mod.comp.whole_cache_manifest_mutex.unlock();
3509 try whole_cache_manifest.addFilePostContents(resolved_path, source.bytes, source.stat);
3510 whole.cache_manifest_mutex.lock();
3511 defer whole.cache_manifest_mutex.unlock();
3512 try man.addFilePostContents(resolved_path, source.bytes, source.stat);
3513 },
3514 .incremental => {},
35103515 }
35113516}
35123517
......@@ -4045,12 +4050,16 @@ fn newEmbedFile(
40454050 const actual_read = try file.readAll(ptr);
40464051 if (actual_read != size) return error.UnexpectedEndOfFile;
40474052
4048 if (mod.comp.whole_cache_manifest) |whole_cache_manifest| {
4049 const copied_resolved_path = try gpa.dupe(u8, resolved_path);
4050 errdefer gpa.free(copied_resolved_path);
4051 mod.comp.whole_cache_manifest_mutex.lock();
4052 defer mod.comp.whole_cache_manifest_mutex.unlock();
4053 try whole_cache_manifest.addFilePostContents(copied_resolved_path, ptr, stat);
4053 const comp = mod.comp;
4054 switch (comp.cache_use) {
4055 .whole => |whole| if (whole.cache_manifest) |man| {
4056 const copied_resolved_path = try gpa.dupe(u8, resolved_path);
4057 errdefer gpa.free(copied_resolved_path);
4058 whole.cache_manifest_mutex.lock();
4059 defer whole.cache_manifest_mutex.unlock();
4060 try man.addFilePostContents(copied_resolved_path, ptr, stat);
4061 },
4062 .incremental => {},
40544063 }
40554064
40564065 const array_ty = try ip.get(gpa, .{ .array_type = .{
......@@ -4393,7 +4402,9 @@ fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void
43934402 }
43944403 },
43954404 }
4396 try mod.comp.bin_file.deleteDeclExport(decl_index, exp.opts.name);
4405 if (mod.comp.bin_file) |lf| {
4406 try lf.deleteDeclExport(decl_index, exp.opts.name);
4407 }
43974408 if (mod.failed_exports.fetchSwapRemove(exp)) |failed_kv| {
43984409 failed_kv.value.destroy(mod.gpa);
43994410 }
......@@ -5247,7 +5258,8 @@ fn processExportsInner(
52475258 gop.value_ptr.* = new_export;
52485259 }
52495260 }
5250 mod.comp.bin_file.updateExports(mod, exported, exports) catch |err| switch (err) {
5261 const lf = mod.comp.bin_file orelse return;
5262 lf.updateExports(mod, exported, exports) catch |err| switch (err) {
52515263 error.OutOfMemory => return error.OutOfMemory,
52525264 else => {
52535265 const new_export = exports[0];
......@@ -5403,36 +5415,39 @@ pub fn populateTestFunctions(
54035415pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void {
54045416 const comp = mod.comp;
54055417
5406 const no_bin_file = (comp.bin_file == null and
5407 comp.emit_asm == null and
5408 comp.emit_llvm_ir == null and
5409 comp.emit_llvm_bc == null);
5410
5411 const dump_llvm_ir = builtin.mode == .Debug and (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null);
5412
5413 if (no_bin_file and !dump_llvm_ir) return;
5414
5415 const decl = mod.declPtr(decl_index);
5418 if (comp.bin_file) |lf| {
5419 const decl = mod.declPtr(decl_index);
5420 lf.updateDecl(mod, decl_index) catch |err| switch (err) {
5421 error.OutOfMemory => return error.OutOfMemory,
5422 error.AnalysisFail => {
5423 decl.analysis = .codegen_failure;
5424 return;
5425 },
5426 else => {
5427 const gpa = mod.gpa;
5428 try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
5429 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
5430 gpa,
5431 decl.srcLoc(mod),
5432 "unable to codegen: {s}",
5433 .{@errorName(err)},
5434 ));
5435 decl.analysis = .codegen_failure_retryable;
5436 return;
5437 },
5438 };
5439 } else {
5440 const dump_llvm_ir = builtin.mode == .Debug and
5441 (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null);
54165442
5417 comp.bin_file.updateDecl(mod, decl_index) catch |err| switch (err) {
5418 error.OutOfMemory => return error.OutOfMemory,
5419 error.AnalysisFail => {
5420 decl.analysis = .codegen_failure;
5421 return;
5422 },
5423 else => {
5424 const gpa = mod.gpa;
5425 try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
5426 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
5427 gpa,
5428 decl.srcLoc(mod),
5429 "unable to codegen: {s}",
5430 .{@errorName(err)},
5431 ));
5432 decl.analysis = .codegen_failure_retryable;
5433 return;
5434 },
5435 };
5443 if (comp.emit_asm != null or
5444 comp.emit_llvm_ir != null or
5445 comp.emit_llvm_bc != null or
5446 dump_llvm_ir)
5447 {
5448 @panic("TODO handle emit_asm, emit_llvm_ir, and emit_llvm_bc along with -fno-emit-bin");
5449 }
5450 }
54365451}
54375452
54385453fn reportRetryableFileError(
src/arch/aarch64/CodeGen.zig+3-3
......@@ -344,7 +344,7 @@ pub fn generate(
344344 assert(fn_owner_decl.has_tv);
345345 const fn_type = fn_owner_decl.ty;
346346 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
347 const target = &namespace.file_scope.mod.target;
347 const target = &namespace.file_scope.mod.resolved_target.result;
348348
349349 var branch_stack = std.ArrayList(Branch).init(gpa);
350350 defer {
......@@ -6343,14 +6343,14 @@ fn wantSafety(self: *Self) bool {
63436343fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
63446344 @setCold(true);
63456345 assert(self.err_msg == null);
6346 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
6346 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
63476347 return error.CodegenFail;
63486348}
63496349
63506350fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
63516351 @setCold(true);
63526352 assert(self.err_msg == null);
6353 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
6353 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
63546354 return error.CodegenFail;
63556355}
63566356
src/arch/aarch64/Emit.zig+17-12
......@@ -218,14 +218,16 @@ pub fn emitMir(
218218}
219219
220220pub fn deinit(emit: *Emit) void {
221 const comp = emit.bin_file.comp;
222 const gpa = comp.gpa;
221223 var iter = emit.branch_forward_origins.valueIterator();
222224 while (iter.next()) |origin_list| {
223 origin_list.deinit(emit.bin_file.allocator);
225 origin_list.deinit(gpa);
224226 }
225227
226 emit.branch_types.deinit(emit.bin_file.allocator);
227 emit.branch_forward_origins.deinit(emit.bin_file.allocator);
228 emit.code_offset_mapping.deinit(emit.bin_file.allocator);
228 emit.branch_types.deinit(gpa);
229 emit.branch_forward_origins.deinit(gpa);
230 emit.code_offset_mapping.deinit(gpa);
229231 emit.* = undefined;
230232}
231233
......@@ -314,8 +316,9 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index {
314316}
315317
316318fn lowerBranches(emit: *Emit) !void {
319 const comp = emit.bin_file.comp;
320 const gpa = comp.gpa;
317321 const mir_tags = emit.mir.instructions.items(.tag);
318 const allocator = emit.bin_file.allocator;
319322
320323 // First pass: Note down all branches and their target
321324 // instructions, i.e. populate branch_types,
......@@ -329,7 +332,7 @@ fn lowerBranches(emit: *Emit) !void {
329332 const target_inst = emit.branchTarget(inst);
330333
331334 // Remember this branch instruction
332 try emit.branch_types.put(allocator, inst, BranchType.default(tag));
335 try emit.branch_types.put(gpa, inst, BranchType.default(tag));
333336
334337 // Forward branches require some extra stuff: We only
335338 // know their offset once we arrive at the target
......@@ -339,14 +342,14 @@ fn lowerBranches(emit: *Emit) !void {
339342 // etc.
340343 if (target_inst > inst) {
341344 // Remember the branch instruction index
342 try emit.code_offset_mapping.put(allocator, inst, 0);
345 try emit.code_offset_mapping.put(gpa, inst, 0);
343346
344347 if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| {
345 try origin_list.append(allocator, inst);
348 try origin_list.append(gpa, inst);
346349 } else {
347350 var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{};
348 try origin_list.append(allocator, inst);
349 try emit.branch_forward_origins.put(allocator, target_inst, origin_list);
351 try origin_list.append(gpa, inst);
352 try emit.branch_forward_origins.put(gpa, target_inst, origin_list);
350353 }
351354 }
352355
......@@ -356,7 +359,7 @@ fn lowerBranches(emit: *Emit) !void {
356359 // putNoClobber may not be used as the put operation
357360 // may clobber the entry when multiple branches branch
358361 // to the same target instruction
359 try emit.code_offset_mapping.put(allocator, target_inst, 0);
362 try emit.code_offset_mapping.put(gpa, target_inst, 0);
360363 }
361364 }
362365
......@@ -429,7 +432,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
429432fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
430433 @setCold(true);
431434 assert(emit.err_msg == null);
432 emit.err_msg = try ErrorMsg.create(emit.bin_file.allocator, emit.src_loc, format, args);
435 const comp = emit.bin_file.comp;
436 const gpa = comp.gpa;
437 emit.err_msg = try ErrorMsg.create(gpa, emit.src_loc, format, args);
433438 return error.EmitFail;
434439}
435440
src/arch/arm/CodeGen.zig+5-3
......@@ -351,7 +351,7 @@ pub fn generate(
351351 assert(fn_owner_decl.has_tv);
352352 const fn_type = fn_owner_decl.ty;
353353 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
354 const target = &namespace.file_scope.mod.target;
354 const target = &namespace.file_scope.mod.resolved_target.result;
355355
356356 var branch_stack = std.ArrayList(Branch).init(gpa);
357357 defer {
......@@ -6292,14 +6292,16 @@ fn wantSafety(self: *Self) bool {
62926292fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
62936293 @setCold(true);
62946294 assert(self.err_msg == null);
6295 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
6295 const gpa = self.gpa;
6296 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
62966297 return error.CodegenFail;
62976298}
62986299
62996300fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
63006301 @setCold(true);
63016302 assert(self.err_msg == null);
6302 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
6303 const gpa = self.gpa;
6304 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
63036305 return error.CodegenFail;
63046306}
63056307
src/arch/arm/Emit.zig+18-12
......@@ -152,14 +152,17 @@ pub fn emitMir(
152152}
153153
154154pub fn deinit(emit: *Emit) void {
155 const comp = emit.bin_file.comp;
156 const gpa = comp.gpa;
157
155158 var iter = emit.branch_forward_origins.valueIterator();
156159 while (iter.next()) |origin_list| {
157 origin_list.deinit(emit.bin_file.allocator);
160 origin_list.deinit(gpa);
158161 }
159162
160 emit.branch_types.deinit(emit.bin_file.allocator);
161 emit.branch_forward_origins.deinit(emit.bin_file.allocator);
162 emit.code_offset_mapping.deinit(emit.bin_file.allocator);
163 emit.branch_types.deinit(gpa);
164 emit.branch_forward_origins.deinit(gpa);
165 emit.code_offset_mapping.deinit(gpa);
163166 emit.* = undefined;
164167}
165168
......@@ -231,8 +234,9 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index {
231234}
232235
233236fn lowerBranches(emit: *Emit) !void {
237 const comp = emit.bin_file.comp;
238 const gpa = comp.gpa;
234239 const mir_tags = emit.mir.instructions.items(.tag);
235 const allocator = emit.bin_file.allocator;
236240
237241 // First pass: Note down all branches and their target
238242 // instructions, i.e. populate branch_types,
......@@ -246,7 +250,7 @@ fn lowerBranches(emit: *Emit) !void {
246250 const target_inst = emit.branchTarget(inst);
247251
248252 // Remember this branch instruction
249 try emit.branch_types.put(allocator, inst, BranchType.default(tag));
253 try emit.branch_types.put(gpa, inst, BranchType.default(tag));
250254
251255 // Forward branches require some extra stuff: We only
252256 // know their offset once we arrive at the target
......@@ -256,14 +260,14 @@ fn lowerBranches(emit: *Emit) !void {
256260 // etc.
257261 if (target_inst > inst) {
258262 // Remember the branch instruction index
259 try emit.code_offset_mapping.put(allocator, inst, 0);
263 try emit.code_offset_mapping.put(gpa, inst, 0);
260264
261265 if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| {
262 try origin_list.append(allocator, inst);
266 try origin_list.append(gpa, inst);
263267 } else {
264268 var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{};
265 try origin_list.append(allocator, inst);
266 try emit.branch_forward_origins.put(allocator, target_inst, origin_list);
269 try origin_list.append(gpa, inst);
270 try emit.branch_forward_origins.put(gpa, target_inst, origin_list);
267271 }
268272 }
269273
......@@ -273,7 +277,7 @@ fn lowerBranches(emit: *Emit) !void {
273277 // putNoClobber may not be used as the put operation
274278 // may clobber the entry when multiple branches branch
275279 // to the same target instruction
276 try emit.code_offset_mapping.put(allocator, target_inst, 0);
280 try emit.code_offset_mapping.put(gpa, target_inst, 0);
277281 }
278282 }
279283
......@@ -346,7 +350,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
346350fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
347351 @setCold(true);
348352 assert(emit.err_msg == null);
349 emit.err_msg = try ErrorMsg.create(emit.bin_file.allocator, emit.src_loc, format, args);
353 const comp = emit.bin_file.comp;
354 const gpa = comp.gpa;
355 emit.err_msg = try ErrorMsg.create(gpa, emit.src_loc, format, args);
350356 return error.EmitFail;
351357}
352358
src/arch/riscv64/CodeGen.zig+3-3
......@@ -232,7 +232,7 @@ pub fn generate(
232232 assert(fn_owner_decl.has_tv);
233233 const fn_type = fn_owner_decl.ty;
234234 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
235 const target = &namespace.file_scope.mod.target;
235 const target = &namespace.file_scope.mod.resolved_target.result;
236236
237237 var branch_stack = std.ArrayList(Branch).init(gpa);
238238 defer {
......@@ -2719,14 +2719,14 @@ fn wantSafety(self: *Self) bool {
27192719fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
27202720 @setCold(true);
27212721 assert(self.err_msg == null);
2722 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
2722 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
27232723 return error.CodegenFail;
27242724}
27252725
27262726fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
27272727 @setCold(true);
27282728 assert(self.err_msg == null);
2729 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
2729 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
27302730 return error.CodegenFail;
27312731}
27322732
src/arch/riscv64/Emit.zig+3-1
......@@ -80,7 +80,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
8080fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
8181 @setCold(true);
8282 assert(emit.err_msg == null);
83 emit.err_msg = try ErrorMsg.create(emit.bin_file.allocator, emit.src_loc, format, args);
83 const comp = emit.bin_file.comp;
84 const gpa = comp.gpa;
85 emit.err_msg = try ErrorMsg.create(gpa, emit.src_loc, format, args);
8486 return error.EmitFail;
8587}
8688
src/arch/sparc64/CodeGen.zig+3-2
......@@ -275,7 +275,7 @@ pub fn generate(
275275 assert(fn_owner_decl.has_tv);
276276 const fn_type = fn_owner_decl.ty;
277277 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
278 const target = &namespace.file_scope.mod.target;
278 const target = &namespace.file_scope.mod.resolved_target.result;
279279
280280 var branch_stack = std.ArrayList(Branch).init(gpa);
281281 defer {
......@@ -3546,7 +3546,8 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
35463546fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
35473547 @setCold(true);
35483548 assert(self.err_msg == null);
3549 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
3549 const gpa = self.gpa;
3550 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
35503551 return error.CodegenFail;
35513552}
35523553
src/arch/sparc64/Emit.zig+17-12
......@@ -152,14 +152,16 @@ pub fn emitMir(
152152}
153153
154154pub fn deinit(emit: *Emit) void {
155 const comp = emit.bin_file.comp;
156 const gpa = comp.gpa;
155157 var iter = emit.branch_forward_origins.valueIterator();
156158 while (iter.next()) |origin_list| {
157 origin_list.deinit(emit.bin_file.allocator);
159 origin_list.deinit(gpa);
158160 }
159161
160 emit.branch_types.deinit(emit.bin_file.allocator);
161 emit.branch_forward_origins.deinit(emit.bin_file.allocator);
162 emit.code_offset_mapping.deinit(emit.bin_file.allocator);
162 emit.branch_types.deinit(gpa);
163 emit.branch_forward_origins.deinit(gpa);
164 emit.code_offset_mapping.deinit(gpa);
163165 emit.* = undefined;
164166}
165167
......@@ -511,7 +513,9 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
511513fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
512514 @setCold(true);
513515 assert(emit.err_msg == null);
514 emit.err_msg = try ErrorMsg.create(emit.bin_file.allocator, emit.src_loc, format, args);
516 const comp = emit.bin_file.comp;
517 const gpa = comp.gpa;
518 emit.err_msg = try ErrorMsg.create(gpa, emit.src_loc, format, args);
515519 return error.EmitFail;
516520}
517521
......@@ -537,8 +541,9 @@ fn isBranch(tag: Mir.Inst.Tag) bool {
537541}
538542
539543fn lowerBranches(emit: *Emit) !void {
544 const comp = emit.bin_file.comp;
545 const gpa = comp.gpa;
540546 const mir_tags = emit.mir.instructions.items(.tag);
541 const allocator = emit.bin_file.allocator;
542547
543548 // First pass: Note down all branches and their target
544549 // instructions, i.e. populate branch_types,
......@@ -552,7 +557,7 @@ fn lowerBranches(emit: *Emit) !void {
552557 const target_inst = emit.branchTarget(inst);
553558
554559 // Remember this branch instruction
555 try emit.branch_types.put(allocator, inst, BranchType.default(tag));
560 try emit.branch_types.put(gpa, inst, BranchType.default(tag));
556561
557562 // Forward branches require some extra stuff: We only
558563 // know their offset once we arrive at the target
......@@ -562,14 +567,14 @@ fn lowerBranches(emit: *Emit) !void {
562567 // etc.
563568 if (target_inst > inst) {
564569 // Remember the branch instruction index
565 try emit.code_offset_mapping.put(allocator, inst, 0);
570 try emit.code_offset_mapping.put(gpa, inst, 0);
566571
567572 if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| {
568 try origin_list.append(allocator, inst);
573 try origin_list.append(gpa, inst);
569574 } else {
570575 var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{};
571 try origin_list.append(allocator, inst);
572 try emit.branch_forward_origins.put(allocator, target_inst, origin_list);
576 try origin_list.append(gpa, inst);
577 try emit.branch_forward_origins.put(gpa, target_inst, origin_list);
573578 }
574579 }
575580
......@@ -579,7 +584,7 @@ fn lowerBranches(emit: *Emit) !void {
579584 // putNoClobber may not be used as the put operation
580585 // may clobber the entry when multiple branches branch
581586 // to the same target instruction
582 try emit.code_offset_mapping.put(allocator, target_inst, 0);
587 try emit.code_offset_mapping.put(gpa, target_inst, 0);
583588 }
584589 }
585590
src/arch/wasm/CodeGen.zig+6-4
......@@ -1210,13 +1210,15 @@ pub fn generate(
12101210 debug_output: codegen.DebugInfoOutput,
12111211) codegen.CodeGenError!codegen.Result {
12121212 _ = src_loc;
1213 const mod = bin_file.comp.module.?;
1213 const comp = bin_file.comp;
1214 const gpa = comp.gpa;
1215 const mod = comp.module.?;
12141216 const func = mod.funcInfo(func_index);
12151217 const decl = mod.declPtr(func.owner_decl);
12161218 const namespace = mod.namespacePtr(decl.src_namespace);
1217 const target = namespace.file_scope.mod.target;
1219 const target = namespace.file_scope.mod.resolved_target.result;
12181220 var code_gen: CodeGen = .{
1219 .gpa = bin_file.allocator,
1221 .gpa = gpa,
12201222 .air = air,
12211223 .liveness = liveness,
12221224 .code = code,
......@@ -7731,7 +7733,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77317733 // Only when the atomic feature is enabled, and we're not building
77327734 // for a single-threaded build, can we emit the `fence` instruction.
77337735 // In all other cases, we emit no instructions for a fence.
7734 const func_namespace = zcu.namespacePtr(zcu.declPtr(func.decl).namespace);
7736 const func_namespace = zcu.namespacePtr(func.decl.src_namespace);
77357737 const single_threaded = func_namespace.file_scope.mod.single_threaded;
77367738 if (func.useAtomicFeature() and !single_threaded) {
77377739 try func.addAtomicTag(.atomic_fence);
src/arch/wasm/Emit.zig+17-7
......@@ -254,8 +254,10 @@ fn offset(self: Emit) u32 {
254254fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
255255 @setCold(true);
256256 std.debug.assert(emit.error_msg == null);
257 const mod = emit.bin_file.base.comp.module.?;
258 emit.error_msg = try Module.ErrorMsg.create(emit.bin_file.base.allocator, mod.declPtr(emit.decl_index).srcLoc(mod), format, args);
257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.module.?;
259 const gpa = comp.gpa;
260 emit.error_msg = try Module.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).srcLoc(zcu), format, args);
259261 return error.EmitFail;
260262}
261263
......@@ -299,6 +301,8 @@ fn emitLabel(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void {
299301}
300302
301303fn emitGlobal(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void {
304 const comp = emit.bin_file.base.comp;
305 const gpa = comp.gpa;
302306 const label = emit.mir.instructions.items(.data)[inst].label;
303307 try emit.code.append(@intFromEnum(tag));
304308 var buf: [5]u8 = undefined;
......@@ -308,7 +312,7 @@ fn emitGlobal(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void {
308312
309313 const atom_index = emit.bin_file.decls.get(emit.decl_index).?;
310314 const atom = emit.bin_file.getAtomPtr(atom_index);
311 try atom.relocs.append(emit.bin_file.base.allocator, .{
315 try atom.relocs.append(gpa, .{
312316 .index = label,
313317 .offset = global_offset,
314318 .relocation_type = .R_WASM_GLOBAL_INDEX_LEB,
......@@ -356,6 +360,8 @@ fn encodeMemArg(mem_arg: Mir.MemArg, writer: anytype) !void {
356360}
357361
358362fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void {
363 const comp = emit.bin_file.base.comp;
364 const gpa = comp.gpa;
359365 const label = emit.mir.instructions.items(.data)[inst].label;
360366 try emit.code.append(std.wasm.opcode(.call));
361367 const call_offset = emit.offset();
......@@ -366,7 +372,7 @@ fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void {
366372 if (label != 0) {
367373 const atom_index = emit.bin_file.decls.get(emit.decl_index).?;
368374 const atom = emit.bin_file.getAtomPtr(atom_index);
369 try atom.relocs.append(emit.bin_file.base.allocator, .{
375 try atom.relocs.append(gpa, .{
370376 .offset = call_offset,
371377 .index = label,
372378 .relocation_type = .R_WASM_FUNCTION_INDEX_LEB,
......@@ -384,6 +390,8 @@ fn emitCallIndirect(emit: *Emit, inst: Mir.Inst.Index) !void {
384390}
385391
386392fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void {
393 const comp = emit.bin_file.base.comp;
394 const gpa = comp.gpa;
387395 const symbol_index = emit.mir.instructions.items(.data)[inst].label;
388396 try emit.code.append(std.wasm.opcode(.i32_const));
389397 const index_offset = emit.offset();
......@@ -394,7 +402,7 @@ fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void {
394402 if (symbol_index != 0) {
395403 const atom_index = emit.bin_file.decls.get(emit.decl_index).?;
396404 const atom = emit.bin_file.getAtomPtr(atom_index);
397 try atom.relocs.append(emit.bin_file.base.allocator, .{
405 try atom.relocs.append(gpa, .{
398406 .offset = index_offset,
399407 .index = symbol_index,
400408 .relocation_type = .R_WASM_TABLE_INDEX_SLEB,
......@@ -406,7 +414,9 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void {
406414 const extra_index = emit.mir.instructions.items(.data)[inst].payload;
407415 const mem = emit.mir.extraData(Mir.Memory, extra_index).data;
408416 const mem_offset = emit.offset() + 1;
409 const target = emit.bin_file.comp.root_mod.resolved_target.result;
417 const comp = emit.bin_file.base.comp;
418 const gpa = comp.gpa;
419 const target = comp.root_mod.resolved_target.result;
410420 const is_wasm32 = target.cpu.arch == .wasm32;
411421 if (is_wasm32) {
412422 try emit.code.append(std.wasm.opcode(.i32_const));
......@@ -423,7 +433,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void {
423433 if (mem.pointer != 0) {
424434 const atom_index = emit.bin_file.decls.get(emit.decl_index).?;
425435 const atom = emit.bin_file.getAtomPtr(atom_index);
426 try atom.relocs.append(emit.bin_file.base.allocator, .{
436 try atom.relocs.append(gpa, .{
427437 .offset = mem_offset,
428438 .index = mem.pointer,
429439 .relocation_type = if (is_wasm32) .R_WASM_MEMORY_ADDR_LEB else .R_WASM_MEMORY_ADDR_LEB64,
src/arch/x86_64/CodeGen.zig+23-19
......@@ -795,15 +795,16 @@ pub fn generate(
795795 code: *std.ArrayList(u8),
796796 debug_output: DebugInfoOutput,
797797) CodeGenError!Result {
798 const mod = bin_file.comp.module.?;
798 const comp = bin_file.comp;
799 const gpa = comp.gpa;
800 const mod = comp.module.?;
799801 const func = mod.funcInfo(func_index);
800802 const fn_owner_decl = mod.declPtr(func.owner_decl);
801803 assert(fn_owner_decl.has_tv);
802804 const fn_type = fn_owner_decl.ty;
803805 const namespace = mod.namespacePtr(fn_owner_decl.src_namespace);
804 const target = namespace.file_scope.mod.target;
806 const target = namespace.file_scope.mod.resolved_target.result;
805807
806 const gpa = bin_file.allocator;
807808 var function = Self{
808809 .gpa = gpa,
809810 .air = air,
......@@ -860,7 +861,7 @@ pub fn generate(
860861 error.CodegenFail => return Result{ .fail = function.err_msg.? },
861862 error.OutOfRegisters => return Result{
862863 .fail = try ErrorMsg.create(
863 bin_file.allocator,
864 gpa,
864865 src_loc,
865866 "CodeGen ran out of registers. This is a bug in the Zig compiler.",
866867 .{},
......@@ -904,22 +905,22 @@ pub fn generate(
904905 function.gen() catch |err| switch (err) {
905906 error.CodegenFail => return Result{ .fail = function.err_msg.? },
906907 error.OutOfRegisters => return Result{
907 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
908 .fail = try ErrorMsg.create(gpa, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
908909 },
909910 else => |e| return e,
910911 };
911912
912913 var mir = Mir{
913914 .instructions = function.mir_instructions.toOwnedSlice(),
914 .extra = try function.mir_extra.toOwnedSlice(bin_file.allocator),
915 .extra = try function.mir_extra.toOwnedSlice(gpa),
915916 .frame_locs = function.frame_locs.toOwnedSlice(),
916917 };
917 defer mir.deinit(bin_file.allocator);
918 defer mir.deinit(gpa);
918919
919920 var emit = Emit{
920921 .lower = .{
921922 .bin_file = bin_file,
922 .allocator = bin_file.allocator,
923 .allocator = gpa,
923924 .mir = mir,
924925 .cc = cc,
925926 .src_loc = src_loc,
......@@ -940,7 +941,7 @@ pub fn generate(
940941 };
941942 return Result{
942943 .fail = try ErrorMsg.create(
943 bin_file.allocator,
944 gpa,
944945 src_loc,
945946 "{s} This is a bug in the Zig compiler.",
946947 .{msg},
......@@ -964,12 +965,13 @@ pub fn generateLazy(
964965 code: *std.ArrayList(u8),
965966 debug_output: DebugInfoOutput,
966967) CodeGenError!Result {
967 const gpa = bin_file.allocator;
968 const zcu = bin_file.comp.module.?;
968 const comp = bin_file.comp;
969 const gpa = comp.gpa;
970 const zcu = comp.module.?;
969971 const decl_index = lazy_sym.ty.getOwnerDecl(zcu);
970972 const decl = zcu.declPtr(decl_index);
971973 const namespace = zcu.namespacePtr(decl.src_namespace);
972 const target = namespace.file_scope.mod.target;
974 const target = namespace.file_scope.mod.resolved_target.result;
973975 var function = Self{
974976 .gpa = gpa,
975977 .air = undefined,
......@@ -996,22 +998,22 @@ pub fn generateLazy(
996998 function.genLazy(lazy_sym) catch |err| switch (err) {
997999 error.CodegenFail => return Result{ .fail = function.err_msg.? },
9981000 error.OutOfRegisters => return Result{
999 .fail = try ErrorMsg.create(bin_file.allocator, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
1001 .fail = try ErrorMsg.create(gpa, src_loc, "CodeGen ran out of registers. This is a bug in the Zig compiler.", .{}),
10001002 },
10011003 else => |e| return e,
10021004 };
10031005
10041006 var mir = Mir{
10051007 .instructions = function.mir_instructions.toOwnedSlice(),
1006 .extra = try function.mir_extra.toOwnedSlice(bin_file.allocator),
1008 .extra = try function.mir_extra.toOwnedSlice(gpa),
10071009 .frame_locs = function.frame_locs.toOwnedSlice(),
10081010 };
1009 defer mir.deinit(bin_file.allocator);
1011 defer mir.deinit(gpa);
10101012
10111013 var emit = Emit{
10121014 .lower = .{
10131015 .bin_file = bin_file,
1014 .allocator = bin_file.allocator,
1016 .allocator = gpa,
10151017 .mir = mir,
10161018 .cc = abi.resolveCallingConvention(.Unspecified, function.target.*),
10171019 .src_loc = src_loc,
......@@ -1032,7 +1034,7 @@ pub fn generateLazy(
10321034 };
10331035 return Result{
10341036 .fail = try ErrorMsg.create(
1035 bin_file.allocator,
1037 gpa,
10361038 src_loc,
10371039 "{s} This is a bug in the Zig compiler.",
10381040 .{msg},
......@@ -16416,14 +16418,16 @@ fn resolveCallingConventionValues(
1641616418fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
1641716419 @setCold(true);
1641816420 assert(self.err_msg == null);
16419 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
16421 const gpa = self.gpa;
16422 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
1642016423 return error.CodegenFail;
1642116424}
1642216425
1642316426fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
1642416427 @setCold(true);
1642516428 assert(self.err_msg == null);
16426 self.err_msg = try ErrorMsg.create(self.bin_file.allocator, self.src_loc, format, args);
16429 const gpa = self.gpa;
16430 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
1642716431 return error.CodegenFail;
1642816432}
1642916433
src/codegen.zig+19-14
......@@ -57,7 +57,7 @@ pub fn generateFunction(
5757 const func = zcu.funcInfo(func_index);
5858 const decl = zcu.declPtr(func.owner_decl);
5959 const namespace = zcu.namespacePtr(decl.src_namespace);
60 const target = namespace.file_scope.mod.target;
60 const target = namespace.file_scope.mod.resolved_target.result;
6161 switch (target.cpu.arch) {
6262 .arm,
6363 .armeb,
......@@ -87,7 +87,7 @@ pub fn generateLazyFunction(
8787 const decl_index = lazy_sym.ty.getOwnerDecl(zcu);
8888 const decl = zcu.declPtr(decl_index);
8989 const namespace = zcu.namespacePtr(decl.src_namespace);
90 const target = namespace.file_scope.mod.target;
90 const target = namespace.file_scope.mod.resolved_target.result;
9191 switch (target.cpu.arch) {
9292 .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, src_loc, lazy_sym, code, debug_output),
9393 else => unreachable,
......@@ -117,12 +117,14 @@ pub fn generateLazySymbol(
117117 const tracy = trace(@src());
118118 defer tracy.end();
119119
120 const zcu = bin_file.comp.module.?;
120 const comp = bin_file.comp;
121 const zcu = comp.module.?;
121122 const decl_index = lazy_sym.ty.getOwnerDecl(zcu);
122123 const decl = zcu.declPtr(decl_index);
123124 const namespace = zcu.namespacePtr(decl.src_namespace);
124 const target = namespace.file_scope.mod.target;
125 const target = namespace.file_scope.mod.resolved_target.result;
125126 const endian = target.cpu.arch.endian();
127 const gpa = comp.gpa;
126128
127129 log.debug("generateLazySymbol: kind = {s}, ty = {}", .{
128130 @tagName(lazy_sym.kind),
......@@ -160,7 +162,7 @@ pub fn generateLazySymbol(
160162 }
161163 return Result.ok;
162164 } else return .{ .fail = try ErrorMsg.create(
163 bin_file.allocator,
165 gpa,
164166 src_loc,
165167 "TODO implement generateLazySymbol for {s} {}",
166168 .{ @tagName(lazy_sym.kind), lazy_sym.ty.fmt(zcu) },
......@@ -827,7 +829,7 @@ fn lowerDeclRef(
827829 const zcu = lf.comp.module.?;
828830 const decl = zcu.declPtr(decl_index);
829831 const namespace = zcu.namespacePtr(decl.src_namespace);
830 const target = namespace.file_scope.mod.target;
832 const target = namespace.file_scope.mod.resolved_target.result;
831833
832834 const ptr_width = target.ptrBitWidth();
833835 const is_fn_body = decl.ty.zigTypeTag(zcu) == .Fn;
......@@ -921,7 +923,7 @@ fn genDeclRef(
921923
922924 const ptr_decl = zcu.declPtr(ptr_decl_index);
923925 const namespace = zcu.namespacePtr(ptr_decl.src_namespace);
924 const target = namespace.file_scope.mod.target;
926 const target = namespace.file_scope.mod.resolved_target.result;
925927
926928 const ptr_bits = target.ptrBitWidth();
927929 const ptr_bytes: u64 = @divExact(ptr_bits, 8);
......@@ -944,6 +946,9 @@ fn genDeclRef(
944946 return GenResult.mcv(.{ .immediate = imm });
945947 }
946948
949 const comp = lf.comp;
950 const gpa = comp.gpa;
951
947952 // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`?
948953 if (tv.ty.castPtrToFn(zcu)) |fn_ty| {
949954 if (zcu.typeToFunc(fn_ty).?.is_generic) {
......@@ -958,8 +963,8 @@ fn genDeclRef(
958963
959964 try zcu.markDeclAlive(decl);
960965
961 const decl_namespace = zcu.namespacePtr(decl.namespace_index);
962 const single_threaded = decl_namespace.file_scope.zcu.single_threaded;
966 const decl_namespace = zcu.namespacePtr(decl.src_namespace);
967 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
963968 const is_threadlocal = tv.val.isPtrToThreadLocal(zcu) and !single_threaded;
964969 const is_extern = decl.isExtern(zcu);
965970
......@@ -985,8 +990,8 @@ fn genDeclRef(
985990 if (is_extern) {
986991 // TODO make this part of getGlobalSymbol
987992 const name = zcu.intern_pool.stringToSlice(decl.name);
988 const sym_name = try std.fmt.allocPrint(lf.allocator, "_{s}", .{name});
989 defer lf.allocator.free(sym_name);
993 const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name});
994 defer gpa.free(sym_name);
990995 const global_index = try macho_file.addUndefined(sym_name, .{ .add_got = true });
991996 return GenResult.mcv(.{ .load_got = link.File.MachO.global_symbol_bit | global_index });
992997 }
......@@ -1005,7 +1010,7 @@ fn genDeclRef(
10051010 else
10061011 null;
10071012 const global_index = try coff_file.getGlobalSymbol(name, lib_name);
1008 try coff_file.need_got_table.put(lf.allocator, global_index, {}); // needs GOT
1013 try coff_file.need_got_table.put(gpa, global_index, {}); // needs GOT
10091014 return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index });
10101015 }
10111016 const atom_index = try coff_file.getOrCreateAtomForDecl(decl_index);
......@@ -1016,7 +1021,7 @@ fn genDeclRef(
10161021 const atom = p9.getAtom(atom_index);
10171022 return GenResult.mcv(.{ .memory = atom.getOffsetTableAddress(p9) });
10181023 } else {
1019 return GenResult.fail(lf.allocator, src_loc, "TODO genDeclRef for target {}", .{target});
1024 return GenResult.fail(gpa, src_loc, "TODO genDeclRef for target {}", .{target});
10201025 }
10211026}
10221027
......@@ -1073,7 +1078,7 @@ pub fn genTypedValue(
10731078
10741079 const owner_decl = zcu.declPtr(owner_decl_index);
10751080 const namespace = zcu.namespacePtr(owner_decl.src_namespace);
1076 const target = namespace.file_scope.mod.target;
1081 const target = namespace.file_scope.mod.resolved_target.result;
10771082 const ptr_bits = target.ptrBitWidth();
10781083
10791084 if (!typed_value.ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(typed_value.val.toIntern())) {
src/codegen/llvm.zig+2-2
......@@ -1785,7 +1785,7 @@ pub const Object = struct {
17851785 if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder);
17861786 global_index.setUnnamedAddr(.unnamed_addr, &self.builder);
17871787 if (decl.val.getVariable(mod)) |decl_var| {
1788 const decl_namespace = mod.namespacePtr(decl.namespace_index);
1788 const decl_namespace = mod.namespacePtr(decl.src_namespace);
17891789 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
17901790 global_index.ptrConst(&self.builder).kind.variable.setThreadLocal(
17911791 if (decl_var.is_threadlocal and !single_threaded)
......@@ -3173,7 +3173,7 @@ pub const Object = struct {
31733173 variable_index.setLinkage(.external, &o.builder);
31743174 variable_index.setUnnamedAddr(.default, &o.builder);
31753175 if (decl.val.getVariable(mod)) |decl_var| {
3176 const decl_namespace = mod.namespacePtr(decl.namespace_index);
3176 const decl_namespace = mod.namespacePtr(decl.src_namespace);
31773177 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
31783178 variable_index.setThreadLocal(
31793179 if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default,
src/libunwind.zig+1-1
......@@ -123,7 +123,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
123123 .local_cache_directory = comp.global_cache_directory,
124124 .global_cache_directory = comp.global_cache_directory,
125125 .zig_lib_directory = comp.zig_lib_directory,
126 .resolved = config,
126 .config = config,
127127 .root_mod = root_mod,
128128 .cache_mode = .whole,
129129 .root_name = root_name,
src/link.zig+28-35
......@@ -69,10 +69,12 @@ pub const File = struct {
6969 allow_shlib_undefined: bool,
7070 stack_size: u64,
7171
72 error_flags: ErrorFlags = .{},
73 misc_errors: std.ArrayListUnmanaged(ErrorMsg) = .{},
74
7275 /// Prevents other processes from clobbering files in the output directory
7376 /// of this linking operation.
7477 lock: ?Cache.Lock = null,
75
7678 child_pid: ?std.ChildProcess.Id = null,
7779
7880 pub const OpenOptions = struct {
......@@ -210,6 +212,8 @@ pub const File = struct {
210212 }
211213
212214 pub fn makeWritable(base: *File) !void {
215 const comp = base.comp;
216 const gpa = comp.gpa;
213217 switch (base.tag) {
214218 .coff, .elf, .macho, .plan9, .wasm => {
215219 if (build_options.only_c) unreachable;
......@@ -225,9 +229,10 @@ pub const File = struct {
225229 // it will return ETXTBSY. So instead, we copy the file, atomically rename it
226230 // over top of the exe path, and then proceed normally. This changes the inode,
227231 // avoiding the error.
228 const tmp_sub_path = try std.fmt.allocPrint(base.allocator, "{s}-{x}", .{
232 const tmp_sub_path = try std.fmt.allocPrint(gpa, "{s}-{x}", .{
229233 emit.sub_path, std.crypto.random.int(u32),
230234 });
235 defer gpa.free(tmp_sub_path);
231236 try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{});
232237 try emit.directory.handle.rename(tmp_sub_path, emit.sub_path);
233238 switch (builtin.os.tag) {
......@@ -242,9 +247,9 @@ pub const File = struct {
242247 }
243248 }
244249 }
245 const use_lld = build_options.have_llvm and base.comp.config.use_lld;
246 const output_mode = base.comp.config.output_mode;
247 const link_mode = base.comp.config.link_mode;
250 const use_lld = build_options.have_llvm and comp.config.use_lld;
251 const output_mode = comp.config.output_mode;
252 const link_mode = comp.config.link_mode;
248253 base.file = try emit.directory.handle.createFile(emit.sub_path, .{
249254 .truncate = false,
250255 .read = true,
......@@ -256,9 +261,10 @@ pub const File = struct {
256261 }
257262
258263 pub fn makeExecutable(base: *File) !void {
259 const output_mode = base.comp.config.output_mode;
260 const link_mode = base.comp.config.link_mode;
261 const use_lld = build_options.have_llvm and base.comp.config.use_lld;
264 const comp = base.comp;
265 const output_mode = comp.config.output_mode;
266 const link_mode = comp.config.link_mode;
267 const use_lld = build_options.have_llvm and comp.config.use_lld;
262268
263269 switch (output_mode) {
264270 .Obj => return,
......@@ -464,8 +470,13 @@ pub const File = struct {
464470 }
465471
466472 pub fn destroy(base: *File) void {
473 const gpa = base.comp.gpa;
467474 base.releaseLock();
468475 if (base.file) |f| f.close();
476 {
477 for (base.misc_errors.items) |*item| item.deinit(gpa);
478 base.misc_errors.deinit(gpa);
479 }
469480 switch (base.tag) {
470481 .coff => {
471482 if (build_options.only_c) unreachable;
......@@ -602,9 +613,9 @@ pub const File = struct {
602613 return;
603614 }
604615
605 const use_lld = build_options.have_llvm and base.comp.config.use_lld;
606 const output_mode = base.comp.config.output_mode;
607 const link_mode = base.comp.config.link_mode;
616 const use_lld = build_options.have_llvm and comp.config.use_lld;
617 const output_mode = comp.config.output_mode;
618 const link_mode = comp.config.link_mode;
608619 if (use_lld and output_mode == .Lib and link_mode == .Static) {
609620 return base.linkAsArchive(comp, prog_node);
610621 }
......@@ -657,25 +668,6 @@ pub const File = struct {
657668 }
658669 }
659670
660 pub fn errorFlags(base: *File) ErrorFlags {
661 switch (base.tag) {
662 .coff => return @fieldParentPtr(Coff, "base", base).error_flags,
663 .elf => return @fieldParentPtr(Elf, "base", base).error_flags,
664 .macho => return @fieldParentPtr(MachO, "base", base).error_flags,
665 .plan9 => return @fieldParentPtr(Plan9, "base", base).error_flags,
666 .c => return .{ .no_entry_point_found = false },
667 .wasm, .spirv, .nvptx => return ErrorFlags{},
668 }
669 }
670
671 pub fn miscErrors(base: *File) []const ErrorMsg {
672 switch (base.tag) {
673 .elf => return @fieldParentPtr(Elf, "base", base).misc_errors.items,
674 .macho => return @fieldParentPtr(MachO, "base", base).misc_errors.items,
675 else => return &.{},
676 }
677 }
678
679671 pub const UpdateExportsError = error{
680672 OutOfMemory,
681673 AnalysisFail,
......@@ -781,14 +773,15 @@ pub const File = struct {
781773 const tracy = trace(@src());
782774 defer tracy.end();
783775
784 var arena_allocator = std.heap.ArenaAllocator.init(base.allocator);
776 const gpa = comp.gpa;
777 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
785778 defer arena_allocator.deinit();
786779 const arena = arena_allocator.allocator();
787780
788781 const directory = base.emit.directory; // Just an alias to make it shorter to type.
789782 const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path});
790783 const full_out_path_z = try arena.dupeZ(u8, full_out_path);
791 const opt_zcu = base.comp.module;
784 const opt_zcu = comp.module;
792785
793786 // If there is no Zig code to compile, then we should skip flushing the output file
794787 // because it will not be part of the linker line anyway.
......@@ -801,7 +794,7 @@ pub const File = struct {
801794
802795 log.debug("zcu_obj_path={s}", .{if (zcu_obj_path) |s| s else "(null)"});
803796
804 const compiler_rt_path: ?[]const u8 = if (base.comp.include_compiler_rt)
797 const compiler_rt_path: ?[]const u8 = if (comp.include_compiler_rt)
805798 comp.compiler_rt_obj.?.full_object_path
806799 else
807800 null;
......@@ -815,7 +808,7 @@ pub const File = struct {
815808 var man: Cache.Manifest = undefined;
816809 defer if (!base.disable_lld_caching) man.deinit();
817810
818 const objects = base.comp.objects;
811 const objects = comp.objects;
819812
820813 var digest: [Cache.hex_digest_len]u8 = undefined;
821814
......@@ -869,7 +862,7 @@ pub const File = struct {
869862
870863 const win32_resource_table_len = if (build_options.only_core_functionality) 0 else comp.win32_resource_table.count();
871864 const num_object_files = objects.len + comp.c_object_table.count() + win32_resource_table_len + 2;
872 var object_files = try std.ArrayList([*:0]const u8).initCapacity(base.allocator, num_object_files);
865 var object_files = try std.ArrayList([*:0]const u8).initCapacity(gpa, num_object_files);
873866 defer object_files.deinit();
874867
875868 for (objects) |obj| {
src/link/C.zig+11-1
......@@ -84,7 +84,8 @@ pub fn getString(this: C, s: String) []const u8 {
8484}
8585
8686pub fn addString(this: *C, s: []const u8) Allocator.Error!String {
87 const gpa = this.base.allocator;
87 const comp = this.base.comp;
88 const gpa = comp.gpa;
8889 try this.string_bytes.appendSlice(gpa, s);
8990 return .{
9091 .start = @intCast(this.string_bytes.items.len - s.len),
......@@ -97,6 +98,15 @@ pub fn open(
9798 comp: *Compilation,
9899 emit: Compilation.Emit,
99100 options: link.File.OpenOptions,
101) !*C {
102 return createEmpty(arena, comp, emit, options);
103}
104
105pub fn createEmpty(
106 arena: Allocator,
107 comp: *Compilation,
108 emit: Compilation.Emit,
109 options: link.File.OpenOptions,
100110) !*C {
101111 const target = comp.root_mod.resolved_target.result;
102112 assert(target.ofmt == .c);
src/link/Coff.zig+2-3
......@@ -8,7 +8,6 @@ llvm_object: ?*LlvmObject = null,
88
99base: link.File,
1010image_base: u64,
11error_flags: link.File.ErrorFlags = .{},
1211dll_export_fns: bool,
1312subsystem: ?std.Target.SubSystem,
1413tsaware: bool,
......@@ -1825,10 +1824,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
18251824
18261825 if (self.entry_addr == null and self.base.comp.config.output_mode == .Exe) {
18271826 log.debug("flushing. no_entry_point_found = true\n", .{});
1828 self.error_flags.no_entry_point_found = true;
1827 self.base.error_flags.no_entry_point_found = true;
18291828 } else {
18301829 log.debug("flushing. no_entry_point_found = false\n", .{});
1831 self.error_flags.no_entry_point_found = false;
1830 self.base.error_flags.no_entry_point_found = false;
18321831 try self.writeHeader();
18331832 }
18341833
src/link/Coff/Atom.zig+6-3
......@@ -94,7 +94,8 @@ pub fn freeListEligible(self: Atom, coff_file: *const Coff) bool {
9494}
9595
9696pub fn addRelocation(coff_file: *Coff, atom_index: Index, reloc: Relocation) !void {
97 const gpa = coff_file.base.allocator;
97 const comp = coff_file.base.comp;
98 const gpa = comp.gpa;
9899 log.debug(" (adding reloc of type {s} to target %{d})", .{ @tagName(reloc.type), reloc.target.sym_index });
99100 const gop = try coff_file.relocs.getOrPut(gpa, atom_index);
100101 if (!gop.found_existing) {
......@@ -104,7 +105,8 @@ pub fn addRelocation(coff_file: *Coff, atom_index: Index, reloc: Relocation) !vo
104105}
105106
106107pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void {
107 const gpa = coff_file.base.allocator;
108 const comp = coff_file.base.comp;
109 const gpa = comp.gpa;
108110 log.debug(" (adding base relocation at offset 0x{x} in %{d})", .{
109111 offset,
110112 coff_file.getAtom(atom_index).getSymbolIndex().?,
......@@ -117,7 +119,8 @@ pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void
117119}
118120
119121pub fn freeRelocations(coff_file: *Coff, atom_index: Index) void {
120 const gpa = coff_file.base.allocator;
122 const comp = coff_file.base.comp;
123 const gpa = comp.gpa;
121124 var removed_relocs = coff_file.relocs.fetchOrderedRemove(atom_index);
122125 if (removed_relocs) |*relocs| relocs.value.deinit(gpa);
123126 var removed_base_relocs = coff_file.base_relocs.fetchOrderedRemove(atom_index);
src/link/Dwarf.zig+1-1
......@@ -1205,7 +1205,7 @@ pub fn commitDeclState(
12051205 const decl = zcu.declPtr(decl_index);
12061206 const ip = &zcu.intern_pool;
12071207 const namespace = zcu.namespacePtr(decl.src_namespace);
1208 const target = namespace.file_scope.mod.target;
1208 const target = namespace.file_scope.mod.resolved_target.result;
12091209 const target_endian = target.cpu.arch.endian();
12101210
12111211 var dbg_line_buffer = &decl_state.dbg_line;
src/link/Elf.zig+25-27
......@@ -196,9 +196,6 @@ resolver: std.AutoArrayHashMapUnmanaged(u32, Symbol.Index) = .{},
196196has_text_reloc: bool = false,
197197num_ifunc_dynrelocs: usize = 0,
198198
199error_flags: link.File.ErrorFlags = link.File.ErrorFlags{},
200misc_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{},
201
202199/// List of atoms that are owned directly by the linker.
203200atoms: std.ArrayListUnmanaged(Atom) = .{},
204201
......@@ -477,7 +474,6 @@ pub fn deinit(self: *Elf) void {
477474 }
478475 self.last_atom_and_free_list_table.deinit(gpa);
479476
480 self.misc_errors.deinit(gpa);
481477 self.comdat_groups.deinit(gpa);
482478 self.comdat_groups_owners.deinit(gpa);
483479 self.comdat_groups_table.deinit(gpa);
......@@ -1168,7 +1164,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11681164 }
11691165
11701166 // libc dep
1171 self.error_flags.missing_libc = false;
1167 self.base.error_flags.missing_libc = false;
11721168 if (self.base.comp.config.link_libc) {
11731169 if (self.base.comp.libc_installation) |lc| {
11741170 const flags = target_util.libcFullLinkFlags(target);
......@@ -1219,7 +1215,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12191215 });
12201216 try system_libs.append(.{ .path = path });
12211217 } else {
1222 self.error_flags.missing_libc = true;
1218 self.base.error_flags.missing_libc = true;
12231219 }
12241220 }
12251221
......@@ -1257,7 +1253,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12571253 };
12581254 }
12591255
1260 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1256 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
12611257
12621258 // Init all objects
12631259 for (self.objects.items) |index| {
......@@ -1267,7 +1263,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
12671263 try self.file(index).?.shared_object.init(self);
12681264 }
12691265
1270 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1266 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
12711267
12721268 // Dedup shared objects
12731269 {
......@@ -1389,14 +1385,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
13891385
13901386 if (self.entry_index == null and self.base.isExe()) {
13911387 log.debug("flushing. no_entry_point_found = true", .{});
1392 self.error_flags.no_entry_point_found = true;
1388 self.base.error_flags.no_entry_point_found = true;
13931389 } else {
13941390 log.debug("flushing. no_entry_point_found = false", .{});
1395 self.error_flags.no_entry_point_found = false;
1391 self.base.error_flags.no_entry_point_found = false;
13961392 try self.writeElfHeader();
13971393 }
13981394
1399 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1395 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
14001396}
14011397
14021398pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void {
......@@ -1428,7 +1424,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const
14281424 };
14291425 }
14301426
1431 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1427 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
14321428
14331429 // First, we flush relocatable object file generated with our backends.
14341430 if (self.zigObjectPtr()) |zig_object| {
......@@ -1540,7 +1536,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const
15401536 try self.base.file.?.setEndPos(total_size);
15411537 try self.base.file.?.pwriteAll(buffer.items, 0);
15421538
1543 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1539 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
15441540}
15451541
15461542pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void {
......@@ -1571,14 +1567,14 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8)
15711567 };
15721568 }
15731569
1574 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1570 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
15751571
15761572 // Init all objects
15771573 for (self.objects.items) |index| {
15781574 try self.file(index).?.object.init(self);
15791575 }
15801576
1581 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1577 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
15821578
15831579 // Now, we are ready to resolve the symbols across all input files.
15841580 // We will first resolve the files in the ZigObject, next in the parsed
......@@ -1612,7 +1608,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8)
16121608 try self.writeShdrTable();
16131609 try self.writeElfHeader();
16141610
1615 if (self.misc_errors.items.len > 0) return error.FlushFailure;
1611 if (self.base.misc_errors.items.len > 0) return error.FlushFailure;
16161612}
16171613
16181614/// --verbose-link output
......@@ -2891,7 +2887,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
28912887 }
28922888
28932889 // libc dep
2894 self.error_flags.missing_libc = false;
2890 self.base.error_flags.missing_libc = false;
28952891 if (comp.config.link_libc) {
28962892 if (self.base.comp.libc_installation != null) {
28972893 const needs_grouping = link_mode == .Static;
......@@ -2912,7 +2908,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
29122908 .Dynamic => "libc.so",
29132909 }));
29142910 } else {
2915 self.error_flags.missing_libc = true;
2911 self.base.error_flags.missing_libc = true;
29162912 }
29172913 }
29182914 }
......@@ -3135,7 +3131,7 @@ fn writePhdrTable(self: *Elf) !void {
31353131}
31363132
31373133fn writeElfHeader(self: *Elf) !void {
3138 if (self.misc_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable
3134 if (self.base.misc_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable
31393135
31403136 var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined;
31413137
......@@ -6067,8 +6063,9 @@ const ErrorWithNotes = struct {
60676063 comptime format: []const u8,
60686064 args: anytype,
60696065 ) error{OutOfMemory}!void {
6070 const gpa = elf_file.base.allocator;
6071 const err_msg = &elf_file.misc_errors.items[err.index];
6066 const comp = elf_file.base.comp;
6067 const gpa = comp.gpa;
6068 const err_msg = &elf_file.base.misc_errors.items[err.index];
60726069 err_msg.msg = try std.fmt.allocPrint(gpa, format, args);
60736070 }
60746071
......@@ -6078,8 +6075,9 @@ const ErrorWithNotes = struct {
60786075 comptime format: []const u8,
60796076 args: anytype,
60806077 ) error{OutOfMemory}!void {
6081 const gpa = elf_file.base.allocator;
6082 const err_msg = &elf_file.misc_errors.items[err.index];
6078 const comp = elf_file.base.comp;
6079 const gpa = comp.gpa;
6080 const err_msg = &elf_file.base.misc_errors.items[err.index];
60836081 assert(err.note_slot < err_msg.notes.len);
60846082 err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) };
60856083 err.note_slot += 1;
......@@ -6088,14 +6086,14 @@ const ErrorWithNotes = struct {
60886086
60896087pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
60906088 const gpa = self.base.comp.gpa;
6091 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
6089 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
60926090 return self.addErrorWithNotesAssumeCapacity(note_count);
60936091}
60946092
60956093fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
60966094 const gpa = self.base.comp.gpa;
6097 const index = self.misc_errors.items.len;
6098 const err = self.misc_errors.addOneAssumeCapacity();
6095 const index = self.base.misc_errors.items.len;
6096 const err = self.base.misc_errors.addOneAssumeCapacity();
60996097 err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) };
61006098 return .{ .index = index };
61016099}
......@@ -6130,7 +6128,7 @@ fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void {
61306128 const gpa = self.base.comp.gpa;
61316129 const max_notes = 4;
61326130
6133 try self.misc_errors.ensureUnusedCapacity(gpa, undefs.count());
6131 try self.base.misc_errors.ensureUnusedCapacity(gpa, undefs.count());
61346132
61356133 var it = undefs.iterator();
61366134 while (it.next()) |entry| {
src/link/Elf/Atom.zig+10-4
......@@ -227,7 +227,8 @@ pub fn grow(self: *Atom, elf_file: *Elf) !void {
227227pub fn free(self: *Atom, elf_file: *Elf) void {
228228 log.debug("freeAtom {d} ({s})", .{ self.atom_index, self.name(elf_file) });
229229
230 const gpa = elf_file.base.allocator;
230 const comp = elf_file.base.comp;
231 const gpa = comp.gpa;
231232 const shndx = self.outputShndx().?;
232233 const meta = elf_file.last_atom_and_free_list_table.getPtr(shndx).?;
233234 const free_list = &meta.free_list;
......@@ -352,7 +353,8 @@ pub fn markFdesDead(self: Atom, elf_file: *Elf) void {
352353}
353354
354355pub fn addReloc(self: Atom, elf_file: *Elf, reloc: elf.Elf64_Rela) !void {
355 const gpa = elf_file.base.allocator;
356 const comp = elf_file.base.comp;
357 const gpa = comp.gpa;
356358 const file_ptr = self.file(elf_file).?;
357359 assert(file_ptr == .zig_object);
358360 const zig_object = file_ptr.zig_object;
......@@ -747,6 +749,8 @@ fn reportUndefined(
747749 rel: elf.Elf64_Rela,
748750 undefs: anytype,
749751) !void {
752 const comp = elf_file.base.comp;
753 const gpa = comp.gpa;
750754 const rel_esym = switch (self.file(elf_file).?) {
751755 .zig_object => |x| x.elfSym(rel.r_sym()).*,
752756 .object => |x| x.symtab.items[rel.r_sym()],
......@@ -761,7 +765,7 @@ fn reportUndefined(
761765 {
762766 const gop = try undefs.getOrPut(sym_index);
763767 if (!gop.found_existing) {
764 gop.value_ptr.* = std.ArrayList(Atom.Index).init(elf_file.base.allocator);
768 gop.value_ptr.* = std.ArrayList(Atom.Index).init(gpa);
765769 }
766770 try gop.value_ptr.append(self.atom_index);
767771 }
......@@ -957,6 +961,8 @@ fn resolveDynAbsReloc(
957961 elf_file: *Elf,
958962 writer: anytype,
959963) !void {
964 const comp = elf_file.base.comp;
965 const gpa = comp.gpa;
960966 const P = self.value + rel.r_offset;
961967 const A = rel.r_addend;
962968 const S = @as(i64, @intCast(target.address(.{}, elf_file)));
......@@ -967,7 +973,7 @@ fn resolveDynAbsReloc(
967973 .shared_object => unreachable,
968974 inline else => |x| x.num_dynrelocs,
969975 };
970 try elf_file.rela_dyn.ensureUnusedCapacity(elf_file.base.allocator, num_dynrelocs);
976 try elf_file.rela_dyn.ensureUnusedCapacity(gpa, num_dynrelocs);
971977
972978 switch (action) {
973979 .@"error",
src/link/MachO.zig+17-25
......@@ -67,9 +67,6 @@ tlv_ptr_table: TableSection(SymbolWithLoc) = .{},
6767thunk_table: std.AutoHashMapUnmanaged(Atom.Index, thunks.Thunk.Index) = .{},
6868thunks: std.ArrayListUnmanaged(thunks.Thunk) = .{},
6969
70error_flags: File.ErrorFlags = File.ErrorFlags{},
71misc_errors: std.ArrayListUnmanaged(File.ErrorMsg) = .{},
72
7370segment_table_dirty: bool = false,
7471got_table_count_dirty: bool = false,
7572got_table_contents_dirty: bool = false,
......@@ -337,8 +334,8 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li
337334 if (build_options.have_llvm) {
338335 return self.base.linkAsArchive(comp, prog_node);
339336 } else {
340 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
341 self.misc_errors.appendAssumeCapacity(.{
337 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
338 self.base.misc_errors.appendAssumeCapacity(.{
342339 .msg = try gpa.dupe(u8, "TODO: non-LLVM archiver for MachO object files"),
343340 });
344341 return error.FlushFailure;
......@@ -492,7 +489,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
492489 try self.resolveSymbols();
493490
494491 if (self.getEntryPoint() == null) {
495 self.error_flags.no_entry_point_found = true;
492 self.base.error_flags.no_entry_point_found = true;
496493 }
497494 if (self.unresolved.count() > 0) {
498495 try self.reportUndefined();
......@@ -2097,11 +2094,6 @@ pub fn deinit(self: *MachO) void {
20972094 bindings.deinit(gpa);
20982095 }
20992096 self.bindings.deinit(gpa);
2100
2101 for (self.misc_errors.items) |*err| {
2102 err.deinit(gpa);
2103 }
2104 self.misc_errors.deinit(gpa);
21052097}
21062098
21072099fn freeAtom(self: *MachO, atom_index: Atom.Index) void {
......@@ -5341,13 +5333,13 @@ fn reportMissingLibraryError(
53415333 args: anytype,
53425334) error{OutOfMemory}!void {
53435335 const gpa = self.base.comp.gpa;
5344 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5336 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
53455337 const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len);
53465338 errdefer gpa.free(notes);
53475339 for (checked_paths, notes) |path, *note| {
53485340 note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) };
53495341 }
5350 self.misc_errors.appendAssumeCapacity(.{
5342 self.base.misc_errors.appendAssumeCapacity(.{
53515343 .msg = try std.fmt.allocPrint(gpa, format, args),
53525344 .notes = notes,
53535345 });
......@@ -5361,14 +5353,14 @@ fn reportDependencyError(
53615353 args: anytype,
53625354) error{OutOfMemory}!void {
53635355 const gpa = self.base.comp.gpa;
5364 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5356 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
53655357 var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2);
53665358 defer notes.deinit();
53675359 if (path) |p| {
53685360 notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{p}) });
53695361 }
53705362 notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "a dependency of {s}", .{parent}) });
5371 self.misc_errors.appendAssumeCapacity(.{
5363 self.base.misc_errors.appendAssumeCapacity(.{
53725364 .msg = try std.fmt.allocPrint(gpa, format, args),
53735365 .notes = try notes.toOwnedSlice(),
53745366 });
......@@ -5381,11 +5373,11 @@ pub fn reportParseError(
53815373 args: anytype,
53825374) error{OutOfMemory}!void {
53835375 const gpa = self.base.comp.gpa;
5384 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5376 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
53855377 var notes = try gpa.alloc(File.ErrorMsg, 1);
53865378 errdefer gpa.free(notes);
53875379 notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) };
5388 self.misc_errors.appendAssumeCapacity(.{
5380 self.base.misc_errors.appendAssumeCapacity(.{
53895381 .msg = try std.fmt.allocPrint(gpa, format, args),
53905382 .notes = notes,
53915383 });
......@@ -5398,11 +5390,11 @@ pub fn reportUnresolvedBoundarySymbol(
53985390 args: anytype,
53995391) error{OutOfMemory}!void {
54005392 const gpa = self.base.comp.gpa;
5401 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5393 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
54025394 var notes = try gpa.alloc(File.ErrorMsg, 1);
54035395 errdefer gpa.free(notes);
54045396 notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while resolving {s}", .{sym_name}) };
5405 self.misc_errors.appendAssumeCapacity(.{
5397 self.base.misc_errors.appendAssumeCapacity(.{
54065398 .msg = try std.fmt.allocPrint(gpa, format, args),
54075399 .notes = notes,
54085400 });
......@@ -5411,7 +5403,7 @@ pub fn reportUnresolvedBoundarySymbol(
54115403pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void {
54125404 const gpa = self.base.comp.gpa;
54135405 const count = self.unresolved.count();
5414 try self.misc_errors.ensureUnusedCapacity(gpa, count);
5406 try self.base.misc_errors.ensureUnusedCapacity(gpa, count);
54155407
54165408 for (self.unresolved.keys()) |global_index| {
54175409 const global = self.globals.items[global_index];
......@@ -5432,7 +5424,7 @@ pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void {
54325424 };
54335425 err_msg.notes = try notes.toOwnedSlice();
54345426
5435 self.misc_errors.appendAssumeCapacity(err_msg);
5427 self.base.misc_errors.appendAssumeCapacity(err_msg);
54365428 }
54375429}
54385430
......@@ -5442,7 +5434,7 @@ fn reportSymbolCollision(
54425434 other: SymbolWithLoc,
54435435) error{OutOfMemory}!void {
54445436 const gpa = self.base.comp.gpa;
5445 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5437 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
54465438
54475439 var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2);
54485440 defer notes.deinit();
......@@ -5465,12 +5457,12 @@ fn reportSymbolCollision(
54655457 }) };
54665458 err_msg.notes = try notes.toOwnedSlice();
54675459
5468 self.misc_errors.appendAssumeCapacity(err_msg);
5460 self.base.misc_errors.appendAssumeCapacity(err_msg);
54695461}
54705462
54715463fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{OutOfMemory}!void {
54725464 const gpa = self.base.comp.gpa;
5473 try self.misc_errors.ensureUnusedCapacity(gpa, 1);
5465 try self.base.misc_errors.ensureUnusedCapacity(gpa, 1);
54745466
54755467 const notes = try gpa.alloc(File.ErrorMsg, 1);
54765468 errdefer gpa.free(notes);
......@@ -5488,7 +5480,7 @@ fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{Ou
54885480 else
54895481 unreachable;
54905482
5491 self.misc_errors.appendAssumeCapacity(.{
5483 self.base.misc_errors.appendAssumeCapacity(.{
54925484 .msg = try std.fmt.allocPrint(gpa, "unhandled symbol type: '{s}' has type {s}", .{
54935485 self.getSymbolName(sym_with_loc),
54945486 sym_type,
src/link/MachO/Atom.zig+8-4
......@@ -253,7 +253,8 @@ pub fn addRelocation(macho_file: *MachO, atom_index: Index, reloc: Relocation) !
253253}
254254
255255pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []const Relocation) !void {
256 const gpa = macho_file.base.allocator;
256 const comp = macho_file.base.comp;
257 const gpa = comp.gpa;
257258 const gop = try macho_file.relocs.getOrPut(gpa, atom_index);
258259 if (!gop.found_existing) {
259260 gop.value_ptr.* = .{};
......@@ -269,7 +270,8 @@ pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []const Rel
269270}
270271
271272pub fn addRebase(macho_file: *MachO, atom_index: Index, offset: u32) !void {
272 const gpa = macho_file.base.allocator;
273 const comp = macho_file.base.comp;
274 const gpa = comp.gpa;
273275 const atom = macho_file.getAtom(atom_index);
274276 log.debug(" (adding rebase at offset 0x{x} in %{?d})", .{ offset, atom.getSymbolIndex() });
275277 const gop = try macho_file.rebases.getOrPut(gpa, atom_index);
......@@ -280,7 +282,8 @@ pub fn addRebase(macho_file: *MachO, atom_index: Index, offset: u32) !void {
280282}
281283
282284pub fn addBinding(macho_file: *MachO, atom_index: Index, binding: Binding) !void {
283 const gpa = macho_file.base.allocator;
285 const comp = macho_file.base.comp;
286 const gpa = comp.gpa;
284287 const atom = macho_file.getAtom(atom_index);
285288 log.debug(" (adding binding to symbol {s} at offset 0x{x} in %{?d})", .{
286289 macho_file.getSymbolName(binding.target),
......@@ -307,7 +310,8 @@ pub fn resolveRelocations(
307310}
308311
309312pub fn freeRelocations(macho_file: *MachO, atom_index: Index) void {
310 const gpa = macho_file.base.allocator;
313 const comp = macho_file.base.comp;
314 const gpa = comp.gpa;
311315 var removed_relocs = macho_file.relocs.fetchOrderedRemove(atom_index);
312316 if (removed_relocs) |*relocs| relocs.value.deinit(gpa);
313317 var removed_rebases = macho_file.rebases.fetchOrderedRemove(atom_index);
src/link/Plan9.zig-1
......@@ -28,7 +28,6 @@ pub const base_tag = .plan9;
2828
2929base: link.File,
3030sixtyfour_bit: bool,
31error_flags: File.ErrorFlags = File.ErrorFlags{},
3231bases: Bases,
3332
3433/// A symbol's value is just casted down when compiling