| author | |
| committer | |
| log | c49957dbe82d7f0db555160b50306335bfa03165 |
| tree | 529e84e430b27c3e6f13cb7a2c956b0ee445339c |
| parent | f54471b54c471bb6f8e51a1383be09d01c24d0c3 |
26 files changed, 411 insertions(+), 313 deletions(-)
src/Compilation.zig+95-58| ... | @@ -884,12 +884,32 @@ const CacheUse = union(CacheMode) { | ... | @@ -884,12 +884,32 @@ const CacheUse = union(CacheMode) { |
| 884 | docs_sub_path: ?[]u8, | 884 | docs_sub_path: ?[]u8, |
| 885 | lf_open_opts: link.File.OpenOptions, | 885 | lf_open_opts: link.File.OpenOptions, |
| 886 | tmp_artifact_directory: ?Cache.Directory, | 886 | 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 | } | ||
| 887 | }; | 896 | }; |
| 888 | 897 | ||
| 889 | const Incremental = struct { | 898 | const Incremental = struct { |
| 890 | /// Where build artifacts and incremental compilation metadata serialization go. | 899 | /// Where build artifacts and incremental compilation metadata serialization go. |
| 891 | artifact_directory: Compilation.Directory, | 900 | artifact_directory: Compilation.Directory, |
| 892 | }; | 901 | }; |
| 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 | } | ||
| 893 | }; | 913 | }; |
| 894 | 914 | ||
| 895 | pub const LinkObject = struct { | 915 | pub const LinkObject = struct { |
| ... | @@ -916,7 +936,7 @@ pub const InitOptions = struct { | ... | @@ -916,7 +936,7 @@ pub const InitOptions = struct { |
| 916 | /// Normally, `main_mod` and `root_mod` are the same. The exception is `zig | 936 | /// Normally, `main_mod` and `root_mod` are the same. The exception is `zig |
| 917 | /// test`, in which `root_mod` is the test runner, and `main_mod` is the | 937 | /// test`, in which `root_mod` is the test runner, and `main_mod` is the |
| 918 | /// user's source file which has the tests. | 938 | /// user's source file which has the tests. |
| 919 | main_mod: ?*Package.Module, | 939 | main_mod: ?*Package.Module = null, |
| 920 | /// This is provided so that the API user has a chance to tweak the | 940 | /// This is provided so that the API user has a chance to tweak the |
| 921 | /// per-module settings of the standard library. | 941 | /// per-module settings of the standard library. |
| 922 | std_mod: *Package.Module, | 942 | std_mod: *Package.Module, |
| ... | @@ -1615,6 +1635,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1615,6 +1635,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1615 | .implib_sub_path = try prepareWholeEmitSubPath(arena, options.emit_implib), | 1635 | .implib_sub_path = try prepareWholeEmitSubPath(arena, options.emit_implib), |
| 1616 | .docs_sub_path = try prepareWholeEmitSubPath(arena, options.emit_docs), | 1636 | .docs_sub_path = try prepareWholeEmitSubPath(arena, options.emit_docs), |
| 1617 | .tmp_artifact_directory = null, | 1637 | .tmp_artifact_directory = null, |
| 1638 | .lock = null, | ||
| 1618 | }; | 1639 | }; |
| 1619 | comp.cache_use = .{ .whole = whole }; | 1640 | comp.cache_use = .{ .whole = whole }; |
| 1620 | }, | 1641 | }, |
| ... | @@ -1822,13 +1843,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1822,13 +1843,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1822 | pub fn destroy(self: *Compilation) void { | 1843 | pub fn destroy(self: *Compilation) void { |
| 1823 | if (self.bin_file) |lf| lf.destroy(); | 1844 | if (self.bin_file) |lf| lf.destroy(); |
| 1824 | if (self.module) |zcu| zcu.deinit(); | 1845 | if (self.module) |zcu| zcu.deinit(); |
| 1825 | switch (self.cache_use) { | 1846 | self.cache_use.deinit(); |
| 1826 | .incremental => |incremental| { | ||
| 1827 | incremental.artifact_directory.handle.close(); | ||
| 1828 | }, | ||
| 1829 | .whole => {}, | ||
| 1830 | } | ||
| 1831 | |||
| 1832 | self.work_queue.deinit(); | 1847 | self.work_queue.deinit(); |
| 1833 | self.anon_work_queue.deinit(); | 1848 | self.anon_work_queue.deinit(); |
| 1834 | self.c_object_work_queue.deinit(); | 1849 | self.c_object_work_queue.deinit(); |
| ... | @@ -1922,11 +1937,17 @@ pub fn getTarget(self: Compilation) Target { | ... | @@ -1922,11 +1937,17 @@ pub fn getTarget(self: Compilation) Target { |
| 1922 | return self.root_mod.resolved_target.result; | 1937 | return self.root_mod.resolved_target.result; |
| 1923 | } | 1938 | } |
| 1924 | 1939 | ||
| 1925 | pub fn hotCodeSwap(comp: *Compilation, prog_node: *std.Progress.Node, pid: std.ChildProcess.Id) !void { | 1940 | /// Only legal to call when cache mode is incremental and a link file is present. |
| 1926 | comp.bin_file.child_pid = pid; | 1941 | pub fn hotCodeSwap( |
| 1927 | try comp.makeBinFileWritable(); | 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(); | ||
| 1928 | try comp.update(prog_node); | 1949 | try comp.update(prog_node); |
| 1929 | try comp.makeBinFileExecutable(); | 1950 | try lf.makeExecutable(); |
| 1930 | } | 1951 | } |
| 1931 | 1952 | ||
| 1932 | fn cleanupAfterUpdate(comp: *Compilation) void { | 1953 | fn cleanupAfterUpdate(comp: *Compilation) void { |
| ... | @@ -1941,7 +1962,7 @@ fn cleanupAfterUpdate(comp: *Compilation) void { | ... | @@ -1941,7 +1962,7 @@ fn cleanupAfterUpdate(comp: *Compilation) void { |
| 1941 | lf.destroy(); | 1962 | lf.destroy(); |
| 1942 | comp.bin_file = null; | 1963 | comp.bin_file = null; |
| 1943 | } | 1964 | } |
| 1944 | if (whole.tmp_artifact_directory) |directory| { | 1965 | if (whole.tmp_artifact_directory) |*directory| { |
| 1945 | directory.handle.close(); | 1966 | directory.handle.close(); |
| 1946 | if (directory.path) |p| comp.gpa.free(p); | 1967 | if (directory.path) |p| comp.gpa.free(p); |
| 1947 | whole.tmp_artifact_directory = null; | 1968 | whole.tmp_artifact_directory = null; |
| ... | @@ -1967,8 +1988,9 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -1967,8 +1988,9 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 1967 | // C source files. | 1988 | // C source files. |
| 1968 | switch (comp.cache_use) { | 1989 | switch (comp.cache_use) { |
| 1969 | .whole => |whole| { | 1990 | .whole => |whole| { |
| 1970 | // We are about to obtain this lock, so here we give other processes a chance first. | ||
| 1971 | assert(comp.bin_file == null); | 1991 | 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(); | ||
| 1972 | 1994 | ||
| 1973 | man = comp.cache_parent.obtain(); | 1995 | man = comp.cache_parent.obtain(); |
| 1974 | whole.cache_manifest = &man; | 1996 | whole.cache_manifest = &man; |
| ... | @@ -1989,8 +2011,8 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -1989,8 +2011,8 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 1989 | 2011 | ||
| 1990 | comp.wholeCacheModeSetBinFilePath(whole, &digest); | 2012 | comp.wholeCacheModeSetBinFilePath(whole, &digest); |
| 1991 | 2013 | ||
| 1992 | assert(comp.bin_file.lock == null); | 2014 | assert(whole.lock == null); |
| 1993 | comp.bin_file.lock = man.toOwnedLock(); | 2015 | whole.lock = man.toOwnedLock(); |
| 1994 | return; | 2016 | return; |
| 1995 | } | 2017 | } |
| 1996 | log.debug("CacheMode.whole cache miss for {s}", .{comp.root_name}); | 2018 | 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 | ... | @@ -2158,7 +2180,7 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2158 | 2180 | ||
| 2159 | // Rename the temporary directory into place. | 2181 | // Rename the temporary directory into place. |
| 2160 | // Close tmp dir and link.File to avoid open handle during rename. | 2182 | // 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| { |
| 2162 | tmp_directory.handle.close(); | 2184 | tmp_directory.handle.close(); |
| 2163 | if (tmp_directory.path) |p| comp.gpa.free(p); | 2185 | if (tmp_directory.path) |p| comp.gpa.free(p); |
| 2164 | whole.tmp_artifact_directory = null; | 2186 | whole.tmp_artifact_directory = null; |
| ... | @@ -2181,8 +2203,8 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void | ... | @@ -2181,8 +2203,8 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2181 | log.warn("failed to write cache manifest: {s}", .{@errorName(err)}); | 2203 | log.warn("failed to write cache manifest: {s}", .{@errorName(err)}); |
| 2182 | }; | 2204 | }; |
| 2183 | 2205 | ||
| 2184 | assert(comp.bin_file.lock == null); | 2206 | assert(whole.lock == null); |
| 2185 | comp.bin_file.lock = man.toOwnedLock(); | 2207 | whole.lock = man.toOwnedLock(); |
| 2186 | }, | 2208 | }, |
| 2187 | .incremental => {}, | 2209 | .incremental => {}, |
| 2188 | } | 2210 | } |
| ... | @@ -2263,13 +2285,15 @@ fn maybeGenerateAutodocs(comp: *Compilation, prog_node: *std.Progress.Node) !voi | ... | @@ -2263,13 +2285,15 @@ fn maybeGenerateAutodocs(comp: *Compilation, prog_node: *std.Progress.Node) !voi |
| 2263 | } | 2285 | } |
| 2264 | 2286 | ||
| 2265 | fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void { | 2287 | fn flush(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 2266 | // This is needed before reading the error flags. | 2288 | if (comp.bin_file) |lf| { |
| 2267 | comp.bin_file.flush(comp, prog_node) catch |err| switch (err) { | 2289 | // This is needed before reading the error flags. |
| 2268 | error.FlushFailure => {}, // error reported through link_error_flags | 2290 | lf.flush(comp, prog_node) catch |err| switch (err) { |
| 2269 | error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr | 2291 | error.FlushFailure => {}, // error reported through link_error_flags |
| 2270 | else => |e| return e, | 2292 | error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr |
| 2271 | }; | 2293 | else => |e| return e, |
| 2272 | comp.link_error_flags = comp.bin_file.errorFlags(); | 2294 | }; |
| 2295 | comp.link_error_flags = lf.error_flags; | ||
| 2296 | } | ||
| 2273 | 2297 | ||
| 2274 | if (comp.module) |module| { | 2298 | if (comp.module) |module| { |
| 2275 | try link.File.C.flushEmitH(module); | 2299 | try link.File.C.flushEmitH(module); |
| ... | @@ -2445,9 +2469,9 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes | ... | @@ -2445,9 +2469,9 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes |
| 2445 | .wasm => { | 2469 | .wasm => { |
| 2446 | const wasm = lf.cast(link.File.Wasm).?; | 2470 | const wasm = lf.cast(link.File.Wasm).?; |
| 2447 | man.hash.add(wasm.rdynamic); | 2471 | man.hash.add(wasm.rdynamic); |
| 2448 | man.hash.add(wasm.initial_memory); | 2472 | man.hash.addOptional(wasm.initial_memory); |
| 2449 | man.hash.add(wasm.max_memory); | 2473 | man.hash.addOptional(wasm.max_memory); |
| 2450 | man.hash.add(wasm.global_base); | 2474 | man.hash.addOptional(wasm.global_base); |
| 2451 | }, | 2475 | }, |
| 2452 | .macho => { | 2476 | .macho => { |
| 2453 | const macho = lf.cast(link.File.MachO).?; | 2477 | const macho = lf.cast(link.File.MachO).?; |
| ... | @@ -2626,12 +2650,14 @@ fn reportMultiModuleErrors(mod: *Module) !void { | ... | @@ -2626,12 +2650,14 @@ fn reportMultiModuleErrors(mod: *Module) !void { |
| 2626 | /// binary is concerned. This will remove the write flag, or close the file, | 2650 | /// binary is concerned. This will remove the write flag, or close the file, |
| 2627 | /// or whatever is needed so that it can be executed. | 2651 | /// or whatever is needed so that it can be executed. |
| 2628 | /// After this, one must call` makeFileWritable` before calling `update`. | 2652 | /// After this, one must call` makeFileWritable` before calling `update`. |
| 2629 | pub fn makeBinFileExecutable(self: *Compilation) !void { | 2653 | pub fn makeBinFileExecutable(comp: *Compilation) !void { |
| 2630 | return self.bin_file.makeExecutable(); | 2654 | const lf = comp.bin_file orelse return; |
| 2655 | return lf.makeExecutable(); | ||
| 2631 | } | 2656 | } |
| 2632 | 2657 | ||
| 2633 | pub fn makeBinFileWritable(self: *Compilation) !void { | 2658 | pub fn makeBinFileWritable(comp: *Compilation) !void { |
| 2634 | return self.bin_file.makeWritable(); | 2659 | const lf = comp.bin_file orelse return; |
| 2660 | return lf.makeWritable(); | ||
| 2635 | } | 2661 | } |
| 2636 | 2662 | ||
| 2637 | const Header = extern struct { | 2663 | const Header = extern struct { |
| ... | @@ -2764,8 +2790,9 @@ pub fn totalErrorCount(self: *Compilation) u32 { | ... | @@ -2764,8 +2790,9 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 2764 | } | 2790 | } |
| 2765 | total += @intFromBool(self.link_error_flags.missing_libc); | 2791 | total += @intFromBool(self.link_error_flags.missing_libc); |
| 2766 | 2792 | ||
| 2767 | // Misc linker errors | 2793 | if (self.bin_file) |lf| { |
| 2768 | total += self.bin_file.miscErrors().len; | 2794 | total += lf.misc_errors.items.len; |
| 2795 | } | ||
| 2769 | 2796 | ||
| 2770 | // Compile log errors only count if there are no other errors. | 2797 | // Compile log errors only count if there are no other errors. |
| 2771 | if (total == 0) { | 2798 | if (total == 0) { |
| ... | @@ -2914,7 +2941,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | ... | @@ -2914,7 +2941,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2914 | })); | 2941 | })); |
| 2915 | } | 2942 | } |
| 2916 | 2943 | ||
| 2917 | for (self.bin_file.miscErrors()) |link_err| { | 2944 | if (self.bin_file) |lf| for (lf.misc_errors.items) |link_err| { |
| 2918 | try bundle.addRootErrorMessage(.{ | 2945 | try bundle.addRootErrorMessage(.{ |
| 2919 | .msg = try bundle.addString(link_err.msg), | 2946 | .msg = try bundle.addString(link_err.msg), |
| 2920 | .notes_len = @intCast(link_err.notes.len), | 2947 | .notes_len = @intCast(link_err.notes.len), |
| ... | @@ -2925,7 +2952,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | ... | @@ -2925,7 +2952,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2925 | .msg = try bundle.addString(note.msg), | 2952 | .msg = try bundle.addString(note.msg), |
| 2926 | })); | 2953 | })); |
| 2927 | } | 2954 | } |
| 2928 | } | 2955 | }; |
| 2929 | 2956 | ||
| 2930 | if (self.module) |module| { | 2957 | if (self.module) |module| { |
| 2931 | if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) { | 2958 | if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) { |
| ... | @@ -3246,12 +3273,12 @@ pub fn performAllTheWork( | ... | @@ -3246,12 +3273,12 @@ pub fn performAllTheWork( |
| 3246 | // TODO put all the modules in a flat array to make them easy to iterate. | 3273 | // TODO put all the modules in a flat array to make them easy to iterate. |
| 3247 | var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{}; | 3274 | var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{}; |
| 3248 | defer seen.deinit(comp.gpa); | 3275 | defer seen.deinit(comp.gpa); |
| 3249 | try seen.put(comp.gpa, comp.root_mod); | 3276 | try seen.put(comp.gpa, comp.root_mod, {}); |
| 3250 | var i: usize = 0; | 3277 | var i: usize = 0; |
| 3251 | while (i < seen.count()) : (i += 1) { | 3278 | while (i < seen.count()) : (i += 1) { |
| 3252 | const mod = seen.keys()[i]; | 3279 | const mod = seen.keys()[i]; |
| 3253 | for (mod.deps.values()) |dep| | 3280 | for (mod.deps.values()) |dep| |
| 3254 | try seen.put(comp.gpa, dep); | 3281 | try seen.put(comp.gpa, dep, {}); |
| 3255 | 3282 | ||
| 3256 | const file = mod.builtin_file orelse continue; | 3283 | const file = mod.builtin_file orelse continue; |
| 3257 | 3284 | ||
| ... | @@ -3459,7 +3486,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v | ... | @@ -3459,7 +3486,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v |
| 3459 | const gpa = comp.gpa; | 3486 | const gpa = comp.gpa; |
| 3460 | const module = comp.module.?; | 3487 | const module = comp.module.?; |
| 3461 | const decl = module.declPtr(decl_index); | 3488 | 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| { | ||
| 3463 | try module.failed_decls.ensureUnusedCapacity(gpa, 1); | 3491 | try module.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 3464 | module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( | 3492 | module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( |
| 3465 | gpa, | 3493 | gpa, |
| ... | @@ -3782,7 +3810,7 @@ pub fn obtainCObjectCacheManifest( | ... | @@ -3782,7 +3810,7 @@ pub fn obtainCObjectCacheManifest( |
| 3782 | // that apply both to @cImport and compiling C objects. No linking stuff here! | 3810 | // that apply both to @cImport and compiling C objects. No linking stuff here! |
| 3783 | // Also nothing that applies only to compiling .zig code. | 3811 | // Also nothing that applies only to compiling .zig code. |
| 3784 | man.hash.add(owner_mod.sanitize_c); | 3812 | man.hash.add(owner_mod.sanitize_c); |
| 3785 | man.hash.addListOfBytes(owner_mod.clang_argv); | 3813 | man.hash.addListOfBytes(owner_mod.cc_argv); |
| 3786 | man.hash.add(comp.config.link_libcpp); | 3814 | man.hash.add(comp.config.link_libcpp); |
| 3787 | 3815 | ||
| 3788 | // When libc_installation is null it means that Zig generated this dir list | 3816 | // When libc_installation is null it means that Zig generated this dir list |
| ... | @@ -6099,7 +6127,8 @@ fn buildOutputFromZig( | ... | @@ -6099,7 +6127,8 @@ fn buildOutputFromZig( |
| 6099 | const tracy_trace = trace(@src()); | 6127 | const tracy_trace = trace(@src()); |
| 6100 | defer tracy_trace.end(); | 6128 | defer tracy_trace.end(); |
| 6101 | 6129 | ||
| 6102 | var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa); | 6130 | const gpa = comp.gpa; |
| 6131 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); | ||
| 6103 | defer arena_allocator.deinit(); | 6132 | defer arena_allocator.deinit(); |
| 6104 | const arena = arena_allocator.allocator(); | 6133 | const arena = arena_allocator.allocator(); |
| 6105 | 6134 | ||
| ... | @@ -6110,6 +6139,7 @@ fn buildOutputFromZig( | ... | @@ -6110,6 +6139,7 @@ fn buildOutputFromZig( |
| 6110 | 6139 | ||
| 6111 | const config = try Config.resolve(.{ | 6140 | const config = try Config.resolve(.{ |
| 6112 | .output_mode = output_mode, | 6141 | .output_mode = output_mode, |
| 6142 | .link_mode = .Static, | ||
| 6113 | .resolved_target = comp.root_mod.resolved_target, | 6143 | .resolved_target = comp.root_mod.resolved_target, |
| 6114 | .is_test = false, | 6144 | .is_test = false, |
| 6115 | .have_zcu = true, | 6145 | .have_zcu = true, |
| ... | @@ -6120,7 +6150,8 @@ fn buildOutputFromZig( | ... | @@ -6120,7 +6150,8 @@ fn buildOutputFromZig( |
| 6120 | .any_unwind_tables = unwind_tables, | 6150 | .any_unwind_tables = unwind_tables, |
| 6121 | }); | 6151 | }); |
| 6122 | 6152 | ||
| 6123 | const root_mod = Package.Module.create(.{ | 6153 | const root_mod = try Package.Module.create(arena, .{ |
| 6154 | .global_cache_directory = comp.global_cache_directory, | ||
| 6124 | .paths = .{ | 6155 | .paths = .{ |
| 6125 | .root = .{ .root_dir = comp.zig_lib_directory }, | 6156 | .root = .{ .root_dir = comp.zig_lib_directory }, |
| 6126 | .root_src_path = src_basename, | 6157 | .root_src_path = src_basename, |
| ... | @@ -6139,6 +6170,8 @@ fn buildOutputFromZig( | ... | @@ -6139,6 +6170,8 @@ fn buildOutputFromZig( |
| 6139 | }, | 6170 | }, |
| 6140 | .global = config, | 6171 | .global = config, |
| 6141 | .cc_argv = &.{}, | 6172 | .cc_argv = &.{}, |
| 6173 | .parent = null, | ||
| 6174 | .builtin_mod = null, | ||
| 6142 | }); | 6175 | }); |
| 6143 | const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; | 6176 | const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; |
| 6144 | const target = comp.getTarget(); | 6177 | const target = comp.getTarget(); |
| ... | @@ -6148,23 +6181,21 @@ fn buildOutputFromZig( | ... | @@ -6148,23 +6181,21 @@ fn buildOutputFromZig( |
| 6148 | .output_mode = output_mode, | 6181 | .output_mode = output_mode, |
| 6149 | }); | 6182 | }); |
| 6150 | 6183 | ||
| 6151 | const emit_bin = Compilation.EmitLoc{ | 6184 | const sub_compilation = try Compilation.create(gpa, .{ |
| 6152 | .directory = null, // Put it in the cache directory. | ||
| 6153 | .basename = bin_basename, | ||
| 6154 | }; | ||
| 6155 | const sub_compilation = try Compilation.create(comp.gpa, .{ | ||
| 6156 | .global_cache_directory = comp.global_cache_directory, | 6185 | .global_cache_directory = comp.global_cache_directory, |
| 6157 | .local_cache_directory = comp.global_cache_directory, | 6186 | .local_cache_directory = comp.global_cache_directory, |
| 6158 | .zig_lib_directory = comp.zig_lib_directory, | 6187 | .zig_lib_directory = comp.zig_lib_directory, |
| 6159 | .self_exe_path = comp.self_exe_path, | 6188 | .self_exe_path = comp.self_exe_path, |
| 6160 | .resolved = config, | 6189 | .config = config, |
| 6161 | .root_mod = root_mod, | 6190 | .root_mod = root_mod, |
| 6162 | .cache_mode = .whole, | 6191 | .cache_mode = .whole, |
| 6163 | .root_name = root_name, | 6192 | .root_name = root_name, |
| 6164 | .thread_pool = comp.thread_pool, | 6193 | .thread_pool = comp.thread_pool, |
| 6165 | .libc_installation = comp.libc_installation, | 6194 | .libc_installation = comp.libc_installation, |
| 6166 | .emit_bin = emit_bin, | 6195 | .emit_bin = .{ |
| 6167 | .link_mode = .Static, | 6196 | .directory = null, // Put it in the cache directory. |
| 6197 | .basename = bin_basename, | ||
| 6198 | }, | ||
| 6168 | .function_sections = true, | 6199 | .function_sections = true, |
| 6169 | .data_sections = true, | 6200 | .data_sections = true, |
| 6170 | .no_builtin = true, | 6201 | .no_builtin = true, |
| ... | @@ -6186,8 +6217,8 @@ fn buildOutputFromZig( | ... | @@ -6186,8 +6217,8 @@ fn buildOutputFromZig( |
| 6186 | try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node); | 6217 | try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node); |
| 6187 | 6218 | ||
| 6188 | assert(out.* == null); | 6219 | assert(out.* == null); |
| 6189 | out.* = Compilation.CRTFile{ | 6220 | out.* = .{ |
| 6190 | .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{ | 6221 | .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &.{ |
| 6191 | sub_compilation.bin_file.?.emit.sub_path, | 6222 | sub_compilation.bin_file.?.emit.sub_path, |
| 6192 | }), | 6223 | }), |
| 6193 | .lock = sub_compilation.bin_file.toOwnedLock(), | 6224 | .lock = sub_compilation.bin_file.toOwnedLock(), |
| ... | @@ -6206,12 +6237,15 @@ pub fn build_crt_file( | ... | @@ -6206,12 +6237,15 @@ pub fn build_crt_file( |
| 6206 | defer tracy_trace.end(); | 6237 | defer tracy_trace.end(); |
| 6207 | 6238 | ||
| 6208 | const gpa = comp.gpa; | 6239 | 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, .{ | ||
| 6210 | .root_name = root_name, | 6245 | .root_name = root_name, |
| 6211 | .target = comp.root_mod.resolved_target.result, | 6246 | .target = comp.root_mod.resolved_target.result, |
| 6212 | .output_mode = output_mode, | 6247 | .output_mode = output_mode, |
| 6213 | }); | 6248 | }); |
| 6214 | errdefer gpa.free(basename); | ||
| 6215 | 6249 | ||
| 6216 | const config = try Config.resolve(.{ | 6250 | const config = try Config.resolve(.{ |
| 6217 | .output_mode = output_mode, | 6251 | .output_mode = output_mode, |
| ... | @@ -6227,7 +6261,8 @@ pub fn build_crt_file( | ... | @@ -6227,7 +6261,8 @@ pub fn build_crt_file( |
| 6227 | .Obj, .Exe => false, | 6261 | .Obj, .Exe => false, |
| 6228 | }, | 6262 | }, |
| 6229 | }); | 6263 | }); |
| 6230 | const root_mod = Package.Module.create(.{ | 6264 | const root_mod = try Package.Module.create(arena, .{ |
| 6265 | .global_cache_directory = comp.global_cache_directory, | ||
| 6231 | .paths = .{ | 6266 | .paths = .{ |
| 6232 | .root = .{ .root_dir = comp.zig_lib_directory }, | 6267 | .root = .{ .root_dir = comp.zig_lib_directory }, |
| 6233 | .root_src_path = "", | 6268 | .root_src_path = "", |
| ... | @@ -6249,6 +6284,8 @@ pub fn build_crt_file( | ... | @@ -6249,6 +6284,8 @@ pub fn build_crt_file( |
| 6249 | }, | 6284 | }, |
| 6250 | .global = config, | 6285 | .global = config, |
| 6251 | .cc_argv = &.{}, | 6286 | .cc_argv = &.{}, |
| 6287 | .parent = null, | ||
| 6288 | .builtin_mod = null, | ||
| 6252 | }); | 6289 | }); |
| 6253 | 6290 | ||
| 6254 | const sub_compilation = try Compilation.create(gpa, .{ | 6291 | const sub_compilation = try Compilation.create(gpa, .{ |
| ... | @@ -6257,7 +6294,7 @@ pub fn build_crt_file( | ... | @@ -6257,7 +6294,7 @@ pub fn build_crt_file( |
| 6257 | .zig_lib_directory = comp.zig_lib_directory, | 6294 | .zig_lib_directory = comp.zig_lib_directory, |
| 6258 | .self_exe_path = comp.self_exe_path, | 6295 | .self_exe_path = comp.self_exe_path, |
| 6259 | .cache_mode = .whole, | 6296 | .cache_mode = .whole, |
| 6260 | .resolved = config, | 6297 | .config = config, |
| 6261 | .root_mod = root_mod, | 6298 | .root_mod = root_mod, |
| 6262 | .root_name = root_name, | 6299 | .root_name = root_name, |
| 6263 | .thread_pool = comp.thread_pool, | 6300 | .thread_pool = comp.thread_pool, |
| ... | @@ -6287,7 +6324,7 @@ pub fn build_crt_file( | ... | @@ -6287,7 +6324,7 @@ pub fn build_crt_file( |
| 6287 | try comp.crt_files.ensureUnusedCapacity(gpa, 1); | 6324 | try comp.crt_files.ensureUnusedCapacity(gpa, 1); |
| 6288 | 6325 | ||
| 6289 | comp.crt_files.putAssumeCapacityNoClobber(basename, .{ | 6326 | 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, &.{ |
| 6291 | sub_compilation.bin_file.?.emit.sub_path, | 6328 | sub_compilation.bin_file.?.emit.sub_path, |
| 6292 | }), | 6329 | }), |
| 6293 | .lock = sub_compilation.bin_file.toOwnedLock(), | 6330 | .lock = sub_compilation.bin_file.toOwnedLock(), |
src/Module.zig+71-56| ... | @@ -619,7 +619,7 @@ pub const Decl = struct { | ... | @@ -619,7 +619,7 @@ pub const Decl = struct { |
| 619 | // Sanitize the name for nvptx which is more restrictive. | 619 | // Sanitize the name for nvptx which is more restrictive. |
| 620 | // TODO This should be handled by the backend, not the frontend. Have a | 620 | // TODO This should be handled by the backend, not the frontend. Have a |
| 621 | // look at how the C backend does it for inspiration. | 621 | // 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; |
| 623 | if (cpu_arch.isNvptx()) { | 623 | if (cpu_arch.isNvptx()) { |
| 624 | for (ip.string_bytes.items[start..]) |*byte| switch (byte.*) { | 624 | for (ip.string_bytes.items[start..]) |*byte| switch (byte.*) { |
| 625 | '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_', | 625 | '{', '}', '*', '[', ']', '(', ')', ',', ' ', '\'' => byte.* = '_', |
| ... | @@ -3313,7 +3313,8 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr | ... | @@ -3313,7 +3313,8 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr |
| 3313 | 3313 | ||
| 3314 | if (no_bin_file and !dump_llvm_ir) return; | 3314 | if (no_bin_file and !dump_llvm_ir) return; |
| 3315 | 3315 | ||
| 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) { | ||
| 3317 | error.OutOfMemory => return error.OutOfMemory, | 3318 | error.OutOfMemory => return error.OutOfMemory, |
| 3318 | error.AnalysisFail => { | 3319 | error.AnalysisFail => { |
| 3319 | decl.analysis = .codegen_failure; | 3320 | decl.analysis = .codegen_failure; |
| ... | @@ -3488,25 +3489,29 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { | ... | @@ -3488,25 +3489,29 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void { |
| 3488 | new_decl.owns_tv = true; | 3489 | new_decl.owns_tv = true; |
| 3489 | new_decl.analysis = .complete; | 3490 | new_decl.analysis = .complete; |
| 3490 | 3491 | ||
| 3491 | if (mod.comp.whole_cache_manifest) |whole_cache_manifest| { | 3492 | const comp = mod.comp; |
| 3492 | const source = file.getSource(gpa) catch |err| { | 3493 | switch (comp.cache_use) { |
| 3493 | try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)}); | 3494 | .whole => |whole| if (whole.cache_manifest) |man| { |
| 3494 | return error.AnalysisFail; | 3495 | const source = file.getSource(gpa) catch |err| { |
| 3495 | }; | 3496 | try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)}); |
| 3497 | return error.AnalysisFail; | ||
| 3498 | }; | ||
| 3496 | 3499 | ||
| 3497 | const resolved_path = std.fs.path.resolve(gpa, &.{ | 3500 | const resolved_path = std.fs.path.resolve(gpa, &.{ |
| 3498 | file.mod.root.root_dir.path orelse ".", | 3501 | file.mod.root.root_dir.path orelse ".", |
| 3499 | file.mod.root.sub_path, | 3502 | file.mod.root.sub_path, |
| 3500 | file.sub_file_path, | 3503 | file.sub_file_path, |
| 3501 | }) catch |err| { | 3504 | }) catch |err| { |
| 3502 | try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)}); | 3505 | try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)}); |
| 3503 | return error.AnalysisFail; | 3506 | return error.AnalysisFail; |
| 3504 | }; | 3507 | }; |
| 3505 | errdefer gpa.free(resolved_path); | 3508 | errdefer gpa.free(resolved_path); |
| 3506 | 3509 | ||
| 3507 | mod.comp.whole_cache_manifest_mutex.lock(); | 3510 | whole.cache_manifest_mutex.lock(); |
| 3508 | defer mod.comp.whole_cache_manifest_mutex.unlock(); | 3511 | defer whole.cache_manifest_mutex.unlock(); |
| 3509 | try whole_cache_manifest.addFilePostContents(resolved_path, source.bytes, source.stat); | 3512 | try man.addFilePostContents(resolved_path, source.bytes, source.stat); |
| 3513 | }, | ||
| 3514 | .incremental => {}, | ||
| 3510 | } | 3515 | } |
| 3511 | } | 3516 | } |
| 3512 | 3517 | ||
| ... | @@ -4045,12 +4050,16 @@ fn newEmbedFile( | ... | @@ -4045,12 +4050,16 @@ fn newEmbedFile( |
| 4045 | const actual_read = try file.readAll(ptr); | 4050 | const actual_read = try file.readAll(ptr); |
| 4046 | if (actual_read != size) return error.UnexpectedEndOfFile; | 4051 | if (actual_read != size) return error.UnexpectedEndOfFile; |
| 4047 | 4052 | ||
| 4048 | if (mod.comp.whole_cache_manifest) |whole_cache_manifest| { | 4053 | const comp = mod.comp; |
| 4049 | const copied_resolved_path = try gpa.dupe(u8, resolved_path); | 4054 | switch (comp.cache_use) { |
| 4050 | errdefer gpa.free(copied_resolved_path); | 4055 | .whole => |whole| if (whole.cache_manifest) |man| { |
| 4051 | mod.comp.whole_cache_manifest_mutex.lock(); | 4056 | const copied_resolved_path = try gpa.dupe(u8, resolved_path); |
| 4052 | defer mod.comp.whole_cache_manifest_mutex.unlock(); | 4057 | errdefer gpa.free(copied_resolved_path); |
| 4053 | try whole_cache_manifest.addFilePostContents(copied_resolved_path, ptr, stat); | 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 => {}, | ||
| 4054 | } | 4063 | } |
| 4055 | 4064 | ||
| 4056 | const array_ty = try ip.get(gpa, .{ .array_type = .{ | 4065 | const array_ty = try ip.get(gpa, .{ .array_type = .{ |
| ... | @@ -4393,7 +4402,9 @@ fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void | ... | @@ -4393,7 +4402,9 @@ fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void |
| 4393 | } | 4402 | } |
| 4394 | }, | 4403 | }, |
| 4395 | } | 4404 | } |
| 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 | } | ||
| 4397 | if (mod.failed_exports.fetchSwapRemove(exp)) |failed_kv| { | 4408 | if (mod.failed_exports.fetchSwapRemove(exp)) |failed_kv| { |
| 4398 | failed_kv.value.destroy(mod.gpa); | 4409 | failed_kv.value.destroy(mod.gpa); |
| 4399 | } | 4410 | } |
| ... | @@ -5247,7 +5258,8 @@ fn processExportsInner( | ... | @@ -5247,7 +5258,8 @@ fn processExportsInner( |
| 5247 | gop.value_ptr.* = new_export; | 5258 | gop.value_ptr.* = new_export; |
| 5248 | } | 5259 | } |
| 5249 | } | 5260 | } |
| 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) { | ||
| 5251 | error.OutOfMemory => return error.OutOfMemory, | 5263 | error.OutOfMemory => return error.OutOfMemory, |
| 5252 | else => { | 5264 | else => { |
| 5253 | const new_export = exports[0]; | 5265 | const new_export = exports[0]; |
| ... | @@ -5403,36 +5415,39 @@ pub fn populateTestFunctions( | ... | @@ -5403,36 +5415,39 @@ pub fn populateTestFunctions( |
| 5403 | pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void { | 5415 | pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void { |
| 5404 | const comp = mod.comp; | 5416 | const comp = mod.comp; |
| 5405 | 5417 | ||
| 5406 | const no_bin_file = (comp.bin_file == null and | 5418 | if (comp.bin_file) |lf| { |
| 5407 | comp.emit_asm == null and | 5419 | const decl = mod.declPtr(decl_index); |
| 5408 | comp.emit_llvm_ir == null and | 5420 | lf.updateDecl(mod, decl_index) catch |err| switch (err) { |
| 5409 | comp.emit_llvm_bc == null); | 5421 | error.OutOfMemory => return error.OutOfMemory, |
| 5410 | 5422 | error.AnalysisFail => { | |
| 5411 | const dump_llvm_ir = builtin.mode == .Debug and (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null); | 5423 | decl.analysis = .codegen_failure; |
| 5412 | 5424 | return; | |
| 5413 | if (no_bin_file and !dump_llvm_ir) return; | 5425 | }, |
| 5414 | 5426 | else => { | |
| 5415 | const decl = mod.declPtr(decl_index); | 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); | ||
| 5416 | 5442 | ||
| 5417 | comp.bin_file.updateDecl(mod, decl_index) catch |err| switch (err) { | 5443 | if (comp.emit_asm != null or |
| 5418 | error.OutOfMemory => return error.OutOfMemory, | 5444 | comp.emit_llvm_ir != null or |
| 5419 | error.AnalysisFail => { | 5445 | comp.emit_llvm_bc != null or |
| 5420 | decl.analysis = .codegen_failure; | 5446 | dump_llvm_ir) |
| 5421 | return; | 5447 | { |
| 5422 | }, | 5448 | @panic("TODO handle emit_asm, emit_llvm_ir, and emit_llvm_bc along with -fno-emit-bin"); |
| 5423 | else => { | 5449 | } |
| 5424 | const gpa = mod.gpa; | 5450 | } |
| 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 | }; | ||
| 5436 | } | 5451 | } |
| 5437 | 5452 | ||
| 5438 | fn reportRetryableFileError( | 5453 | fn reportRetryableFileError( |
src/arch/aarch64/CodeGen.zig+3-3| ... | @@ -344,7 +344,7 @@ pub fn generate( | ... | @@ -344,7 +344,7 @@ pub fn generate( |
| 344 | assert(fn_owner_decl.has_tv); | 344 | assert(fn_owner_decl.has_tv); |
| 345 | const fn_type = fn_owner_decl.ty; | 345 | const fn_type = fn_owner_decl.ty; |
| 346 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 346 | 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; |
| 348 | 348 | ||
| 349 | var branch_stack = std.ArrayList(Branch).init(gpa); | 349 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 350 | defer { | 350 | defer { |
| ... | @@ -6343,14 +6343,14 @@ fn wantSafety(self: *Self) bool { | ... | @@ -6343,14 +6343,14 @@ fn wantSafety(self: *Self) bool { |
| 6343 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 6343 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 6344 | @setCold(true); | 6344 | @setCold(true); |
| 6345 | assert(self.err_msg == null); | 6345 | 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); |
| 6347 | return error.CodegenFail; | 6347 | return error.CodegenFail; |
| 6348 | } | 6348 | } |
| 6349 | 6349 | ||
| 6350 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 6350 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 6351 | @setCold(true); | 6351 | @setCold(true); |
| 6352 | assert(self.err_msg == null); | 6352 | 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); |
| 6354 | return error.CodegenFail; | 6354 | return error.CodegenFail; |
| 6355 | } | 6355 | } |
| 6356 | 6356 |
src/arch/aarch64/Emit.zig+17-12| ... | @@ -218,14 +218,16 @@ pub fn emitMir( | ... | @@ -218,14 +218,16 @@ pub fn emitMir( |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | pub fn deinit(emit: *Emit) void { | 220 | pub fn deinit(emit: *Emit) void { |
| 221 | const comp = emit.bin_file.comp; | ||
| 222 | const gpa = comp.gpa; | ||
| 221 | var iter = emit.branch_forward_origins.valueIterator(); | 223 | var iter = emit.branch_forward_origins.valueIterator(); |
| 222 | while (iter.next()) |origin_list| { | 224 | while (iter.next()) |origin_list| { |
| 223 | origin_list.deinit(emit.bin_file.allocator); | 225 | origin_list.deinit(gpa); |
| 224 | } | 226 | } |
| 225 | 227 | ||
| 226 | emit.branch_types.deinit(emit.bin_file.allocator); | 228 | emit.branch_types.deinit(gpa); |
| 227 | emit.branch_forward_origins.deinit(emit.bin_file.allocator); | 229 | emit.branch_forward_origins.deinit(gpa); |
| 228 | emit.code_offset_mapping.deinit(emit.bin_file.allocator); | 230 | emit.code_offset_mapping.deinit(gpa); |
| 229 | emit.* = undefined; | 231 | emit.* = undefined; |
| 230 | } | 232 | } |
| 231 | 233 | ||
| ... | @@ -314,8 +316,9 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index { | ... | @@ -314,8 +316,9 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index { |
| 314 | } | 316 | } |
| 315 | 317 | ||
| 316 | fn lowerBranches(emit: *Emit) !void { | 318 | fn lowerBranches(emit: *Emit) !void { |
| 319 | const comp = emit.bin_file.comp; | ||
| 320 | const gpa = comp.gpa; | ||
| 317 | const mir_tags = emit.mir.instructions.items(.tag); | 321 | const mir_tags = emit.mir.instructions.items(.tag); |
| 318 | const allocator = emit.bin_file.allocator; | ||
| 319 | 322 | ||
| 320 | // First pass: Note down all branches and their target | 323 | // First pass: Note down all branches and their target |
| 321 | // instructions, i.e. populate branch_types, | 324 | // instructions, i.e. populate branch_types, |
| ... | @@ -329,7 +332,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -329,7 +332,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 329 | const target_inst = emit.branchTarget(inst); | 332 | const target_inst = emit.branchTarget(inst); |
| 330 | 333 | ||
| 331 | // Remember this branch instruction | 334 | // 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)); |
| 333 | 336 | ||
| 334 | // Forward branches require some extra stuff: We only | 337 | // Forward branches require some extra stuff: We only |
| 335 | // know their offset once we arrive at the target | 338 | // know their offset once we arrive at the target |
| ... | @@ -339,14 +342,14 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -339,14 +342,14 @@ fn lowerBranches(emit: *Emit) !void { |
| 339 | // etc. | 342 | // etc. |
| 340 | if (target_inst > inst) { | 343 | if (target_inst > inst) { |
| 341 | // Remember the branch instruction index | 344 | // 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); |
| 343 | 346 | ||
| 344 | if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| { | 347 | if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| { |
| 345 | try origin_list.append(allocator, inst); | 348 | try origin_list.append(gpa, inst); |
| 346 | } else { | 349 | } else { |
| 347 | var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{}; | 350 | var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{}; |
| 348 | try origin_list.append(allocator, inst); | 351 | try origin_list.append(gpa, inst); |
| 349 | try emit.branch_forward_origins.put(allocator, target_inst, origin_list); | 352 | try emit.branch_forward_origins.put(gpa, target_inst, origin_list); |
| 350 | } | 353 | } |
| 351 | } | 354 | } |
| 352 | 355 | ||
| ... | @@ -356,7 +359,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -356,7 +359,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 356 | // putNoClobber may not be used as the put operation | 359 | // putNoClobber may not be used as the put operation |
| 357 | // may clobber the entry when multiple branches branch | 360 | // may clobber the entry when multiple branches branch |
| 358 | // to the same target instruction | 361 | // 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); |
| 360 | } | 363 | } |
| 361 | } | 364 | } |
| 362 | 365 | ||
| ... | @@ -429,7 +432,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | ... | @@ -429,7 +432,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 429 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 432 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 430 | @setCold(true); | 433 | @setCold(true); |
| 431 | assert(emit.err_msg == null); | 434 | 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); | ||
| 433 | return error.EmitFail; | 438 | return error.EmitFail; |
| 434 | } | 439 | } |
| 435 | 440 |
src/arch/arm/CodeGen.zig+5-3| ... | @@ -351,7 +351,7 @@ pub fn generate( | ... | @@ -351,7 +351,7 @@ pub fn generate( |
| 351 | assert(fn_owner_decl.has_tv); | 351 | assert(fn_owner_decl.has_tv); |
| 352 | const fn_type = fn_owner_decl.ty; | 352 | const fn_type = fn_owner_decl.ty; |
| 353 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 353 | 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; |
| 355 | 355 | ||
| 356 | var branch_stack = std.ArrayList(Branch).init(gpa); | 356 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 357 | defer { | 357 | defer { |
| ... | @@ -6292,14 +6292,16 @@ fn wantSafety(self: *Self) bool { | ... | @@ -6292,14 +6292,16 @@ fn wantSafety(self: *Self) bool { |
| 6292 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 6292 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 6293 | @setCold(true); | 6293 | @setCold(true); |
| 6294 | assert(self.err_msg == null); | 6294 | 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); | ||
| 6296 | return error.CodegenFail; | 6297 | return error.CodegenFail; |
| 6297 | } | 6298 | } |
| 6298 | 6299 | ||
| 6299 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 6300 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 6300 | @setCold(true); | 6301 | @setCold(true); |
| 6301 | assert(self.err_msg == null); | 6302 | 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); | ||
| 6303 | return error.CodegenFail; | 6305 | return error.CodegenFail; |
| 6304 | } | 6306 | } |
| 6305 | 6307 |
src/arch/arm/Emit.zig+18-12| ... | @@ -152,14 +152,17 @@ pub fn emitMir( | ... | @@ -152,14 +152,17 @@ pub fn emitMir( |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | pub fn deinit(emit: *Emit) void { | 154 | pub fn deinit(emit: *Emit) void { |
| 155 | const comp = emit.bin_file.comp; | ||
| 156 | const gpa = comp.gpa; | ||
| 157 | |||
| 155 | var iter = emit.branch_forward_origins.valueIterator(); | 158 | var iter = emit.branch_forward_origins.valueIterator(); |
| 156 | while (iter.next()) |origin_list| { | 159 | while (iter.next()) |origin_list| { |
| 157 | origin_list.deinit(emit.bin_file.allocator); | 160 | origin_list.deinit(gpa); |
| 158 | } | 161 | } |
| 159 | 162 | ||
| 160 | emit.branch_types.deinit(emit.bin_file.allocator); | 163 | emit.branch_types.deinit(gpa); |
| 161 | emit.branch_forward_origins.deinit(emit.bin_file.allocator); | 164 | emit.branch_forward_origins.deinit(gpa); |
| 162 | emit.code_offset_mapping.deinit(emit.bin_file.allocator); | 165 | emit.code_offset_mapping.deinit(gpa); |
| 163 | emit.* = undefined; | 166 | emit.* = undefined; |
| 164 | } | 167 | } |
| 165 | 168 | ||
| ... | @@ -231,8 +234,9 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index { | ... | @@ -231,8 +234,9 @@ fn branchTarget(emit: *Emit, inst: Mir.Inst.Index) Mir.Inst.Index { |
| 231 | } | 234 | } |
| 232 | 235 | ||
| 233 | fn lowerBranches(emit: *Emit) !void { | 236 | fn lowerBranches(emit: *Emit) !void { |
| 237 | const comp = emit.bin_file.comp; | ||
| 238 | const gpa = comp.gpa; | ||
| 234 | const mir_tags = emit.mir.instructions.items(.tag); | 239 | const mir_tags = emit.mir.instructions.items(.tag); |
| 235 | const allocator = emit.bin_file.allocator; | ||
| 236 | 240 | ||
| 237 | // First pass: Note down all branches and their target | 241 | // First pass: Note down all branches and their target |
| 238 | // instructions, i.e. populate branch_types, | 242 | // instructions, i.e. populate branch_types, |
| ... | @@ -246,7 +250,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -246,7 +250,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 246 | const target_inst = emit.branchTarget(inst); | 250 | const target_inst = emit.branchTarget(inst); |
| 247 | 251 | ||
| 248 | // Remember this branch instruction | 252 | // 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)); |
| 250 | 254 | ||
| 251 | // Forward branches require some extra stuff: We only | 255 | // Forward branches require some extra stuff: We only |
| 252 | // know their offset once we arrive at the target | 256 | // know their offset once we arrive at the target |
| ... | @@ -256,14 +260,14 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -256,14 +260,14 @@ fn lowerBranches(emit: *Emit) !void { |
| 256 | // etc. | 260 | // etc. |
| 257 | if (target_inst > inst) { | 261 | if (target_inst > inst) { |
| 258 | // Remember the branch instruction index | 262 | // 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); |
| 260 | 264 | ||
| 261 | if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| { | 265 | if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| { |
| 262 | try origin_list.append(allocator, inst); | 266 | try origin_list.append(gpa, inst); |
| 263 | } else { | 267 | } else { |
| 264 | var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{}; | 268 | var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{}; |
| 265 | try origin_list.append(allocator, inst); | 269 | try origin_list.append(gpa, inst); |
| 266 | try emit.branch_forward_origins.put(allocator, target_inst, origin_list); | 270 | try emit.branch_forward_origins.put(gpa, target_inst, origin_list); |
| 267 | } | 271 | } |
| 268 | } | 272 | } |
| 269 | 273 | ||
| ... | @@ -273,7 +277,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -273,7 +277,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 273 | // putNoClobber may not be used as the put operation | 277 | // putNoClobber may not be used as the put operation |
| 274 | // may clobber the entry when multiple branches branch | 278 | // may clobber the entry when multiple branches branch |
| 275 | // to the same target instruction | 279 | // 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); |
| 277 | } | 281 | } |
| 278 | } | 282 | } |
| 279 | 283 | ||
| ... | @@ -346,7 +350,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | ... | @@ -346,7 +350,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 346 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 350 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 347 | @setCold(true); | 351 | @setCold(true); |
| 348 | assert(emit.err_msg == null); | 352 | 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); | ||
| 350 | return error.EmitFail; | 356 | return error.EmitFail; |
| 351 | } | 357 | } |
| 352 | 358 |
src/arch/riscv64/CodeGen.zig+3-3| ... | @@ -232,7 +232,7 @@ pub fn generate( | ... | @@ -232,7 +232,7 @@ pub fn generate( |
| 232 | assert(fn_owner_decl.has_tv); | 232 | assert(fn_owner_decl.has_tv); |
| 233 | const fn_type = fn_owner_decl.ty; | 233 | const fn_type = fn_owner_decl.ty; |
| 234 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 234 | 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; |
| 236 | 236 | ||
| 237 | var branch_stack = std.ArrayList(Branch).init(gpa); | 237 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 238 | defer { | 238 | defer { |
| ... | @@ -2719,14 +2719,14 @@ fn wantSafety(self: *Self) bool { | ... | @@ -2719,14 +2719,14 @@ fn wantSafety(self: *Self) bool { |
| 2719 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 2719 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 2720 | @setCold(true); | 2720 | @setCold(true); |
| 2721 | assert(self.err_msg == null); | 2721 | 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); |
| 2723 | return error.CodegenFail; | 2723 | return error.CodegenFail; |
| 2724 | } | 2724 | } |
| 2725 | 2725 | ||
| 2726 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 2726 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 2727 | @setCold(true); | 2727 | @setCold(true); |
| 2728 | assert(self.err_msg == null); | 2728 | 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); |
| 2730 | return error.CodegenFail; | 2730 | return error.CodegenFail; |
| 2731 | } | 2731 | } |
| 2732 | 2732 |
src/arch/riscv64/Emit.zig+3-1| ... | @@ -80,7 +80,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | ... | @@ -80,7 +80,9 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 80 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 80 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 81 | @setCold(true); | 81 | @setCold(true); |
| 82 | assert(emit.err_msg == null); | 82 | 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); | ||
| 84 | return error.EmitFail; | 86 | return error.EmitFail; |
| 85 | } | 87 | } |
| 86 | 88 |
src/arch/sparc64/CodeGen.zig+3-2| ... | @@ -275,7 +275,7 @@ pub fn generate( | ... | @@ -275,7 +275,7 @@ pub fn generate( |
| 275 | assert(fn_owner_decl.has_tv); | 275 | assert(fn_owner_decl.has_tv); |
| 276 | const fn_type = fn_owner_decl.ty; | 276 | const fn_type = fn_owner_decl.ty; |
| 277 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 277 | 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; |
| 279 | 279 | ||
| 280 | var branch_stack = std.ArrayList(Branch).init(gpa); | 280 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 281 | defer { | 281 | defer { |
| ... | @@ -3546,7 +3546,8 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) | ... | @@ -3546,7 +3546,8 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) |
| 3546 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 3546 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 3547 | @setCold(true); | 3547 | @setCold(true); |
| 3548 | assert(self.err_msg == null); | 3548 | 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); | ||
| 3550 | return error.CodegenFail; | 3551 | return error.CodegenFail; |
| 3551 | } | 3552 | } |
| 3552 | 3553 |
src/arch/sparc64/Emit.zig+17-12| ... | @@ -152,14 +152,16 @@ pub fn emitMir( | ... | @@ -152,14 +152,16 @@ pub fn emitMir( |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | pub fn deinit(emit: *Emit) void { | 154 | pub fn deinit(emit: *Emit) void { |
| 155 | const comp = emit.bin_file.comp; | ||
| 156 | const gpa = comp.gpa; | ||
| 155 | var iter = emit.branch_forward_origins.valueIterator(); | 157 | var iter = emit.branch_forward_origins.valueIterator(); |
| 156 | while (iter.next()) |origin_list| { | 158 | while (iter.next()) |origin_list| { |
| 157 | origin_list.deinit(emit.bin_file.allocator); | 159 | origin_list.deinit(gpa); |
| 158 | } | 160 | } |
| 159 | 161 | ||
| 160 | emit.branch_types.deinit(emit.bin_file.allocator); | 162 | emit.branch_types.deinit(gpa); |
| 161 | emit.branch_forward_origins.deinit(emit.bin_file.allocator); | 163 | emit.branch_forward_origins.deinit(gpa); |
| 162 | emit.code_offset_mapping.deinit(emit.bin_file.allocator); | 164 | emit.code_offset_mapping.deinit(gpa); |
| 163 | emit.* = undefined; | 165 | emit.* = undefined; |
| 164 | } | 166 | } |
| 165 | 167 | ||
| ... | @@ -511,7 +513,9 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void { | ... | @@ -511,7 +513,9 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void { |
| 511 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 513 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 512 | @setCold(true); | 514 | @setCold(true); |
| 513 | assert(emit.err_msg == null); | 515 | 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); | ||
| 515 | return error.EmitFail; | 519 | return error.EmitFail; |
| 516 | } | 520 | } |
| 517 | 521 | ||
| ... | @@ -537,8 +541,9 @@ fn isBranch(tag: Mir.Inst.Tag) bool { | ... | @@ -537,8 +541,9 @@ fn isBranch(tag: Mir.Inst.Tag) bool { |
| 537 | } | 541 | } |
| 538 | 542 | ||
| 539 | fn lowerBranches(emit: *Emit) !void { | 543 | fn lowerBranches(emit: *Emit) !void { |
| 544 | const comp = emit.bin_file.comp; | ||
| 545 | const gpa = comp.gpa; | ||
| 540 | const mir_tags = emit.mir.instructions.items(.tag); | 546 | const mir_tags = emit.mir.instructions.items(.tag); |
| 541 | const allocator = emit.bin_file.allocator; | ||
| 542 | 547 | ||
| 543 | // First pass: Note down all branches and their target | 548 | // First pass: Note down all branches and their target |
| 544 | // instructions, i.e. populate branch_types, | 549 | // instructions, i.e. populate branch_types, |
| ... | @@ -552,7 +557,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -552,7 +557,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 552 | const target_inst = emit.branchTarget(inst); | 557 | const target_inst = emit.branchTarget(inst); |
| 553 | 558 | ||
| 554 | // Remember this branch instruction | 559 | // 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)); |
| 556 | 561 | ||
| 557 | // Forward branches require some extra stuff: We only | 562 | // Forward branches require some extra stuff: We only |
| 558 | // know their offset once we arrive at the target | 563 | // know their offset once we arrive at the target |
| ... | @@ -562,14 +567,14 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -562,14 +567,14 @@ fn lowerBranches(emit: *Emit) !void { |
| 562 | // etc. | 567 | // etc. |
| 563 | if (target_inst > inst) { | 568 | if (target_inst > inst) { |
| 564 | // Remember the branch instruction index | 569 | // 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); |
| 566 | 571 | ||
| 567 | if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| { | 572 | if (emit.branch_forward_origins.getPtr(target_inst)) |origin_list| { |
| 568 | try origin_list.append(allocator, inst); | 573 | try origin_list.append(gpa, inst); |
| 569 | } else { | 574 | } else { |
| 570 | var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{}; | 575 | var origin_list: std.ArrayListUnmanaged(Mir.Inst.Index) = .{}; |
| 571 | try origin_list.append(allocator, inst); | 576 | try origin_list.append(gpa, inst); |
| 572 | try emit.branch_forward_origins.put(allocator, target_inst, origin_list); | 577 | try emit.branch_forward_origins.put(gpa, target_inst, origin_list); |
| 573 | } | 578 | } |
| 574 | } | 579 | } |
| 575 | 580 | ||
| ... | @@ -579,7 +584,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -579,7 +584,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 579 | // putNoClobber may not be used as the put operation | 584 | // putNoClobber may not be used as the put operation |
| 580 | // may clobber the entry when multiple branches branch | 585 | // may clobber the entry when multiple branches branch |
| 581 | // to the same target instruction | 586 | // 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); |
| 583 | } | 588 | } |
| 584 | } | 589 | } |
| 585 | 590 |
src/arch/wasm/CodeGen.zig+6-4| ... | @@ -1210,13 +1210,15 @@ pub fn generate( | ... | @@ -1210,13 +1210,15 @@ pub fn generate( |
| 1210 | debug_output: codegen.DebugInfoOutput, | 1210 | debug_output: codegen.DebugInfoOutput, |
| 1211 | ) codegen.CodeGenError!codegen.Result { | 1211 | ) codegen.CodeGenError!codegen.Result { |
| 1212 | _ = src_loc; | 1212 | _ = 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.?; | ||
| 1214 | const func = mod.funcInfo(func_index); | 1216 | const func = mod.funcInfo(func_index); |
| 1215 | const decl = mod.declPtr(func.owner_decl); | 1217 | const decl = mod.declPtr(func.owner_decl); |
| 1216 | const namespace = mod.namespacePtr(decl.src_namespace); | 1218 | 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; |
| 1218 | var code_gen: CodeGen = .{ | 1220 | var code_gen: CodeGen = .{ |
| 1219 | .gpa = bin_file.allocator, | 1221 | .gpa = gpa, |
| 1220 | .air = air, | 1222 | .air = air, |
| 1221 | .liveness = liveness, | 1223 | .liveness = liveness, |
| 1222 | .code = code, | 1224 | .code = code, |
| ... | @@ -7731,7 +7733,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -7731,7 +7733,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7731 | // Only when the atomic feature is enabled, and we're not building | 7733 | // Only when the atomic feature is enabled, and we're not building |
| 7732 | // for a single-threaded build, can we emit the `fence` instruction. | 7734 | // for a single-threaded build, can we emit the `fence` instruction. |
| 7733 | // In all other cases, we emit no instructions for a fence. | 7735 | // 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); |
| 7735 | const single_threaded = func_namespace.file_scope.mod.single_threaded; | 7737 | const single_threaded = func_namespace.file_scope.mod.single_threaded; |
| 7736 | if (func.useAtomicFeature() and !single_threaded) { | 7738 | if (func.useAtomicFeature() and !single_threaded) { |
| 7737 | try func.addAtomicTag(.atomic_fence); | 7739 | try func.addAtomicTag(.atomic_fence); |
src/arch/wasm/Emit.zig+17-7| ... | @@ -254,8 +254,10 @@ fn offset(self: Emit) u32 { | ... | @@ -254,8 +254,10 @@ fn offset(self: Emit) u32 { |
| 254 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { | 254 | fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError { |
| 255 | @setCold(true); | 255 | @setCold(true); |
| 256 | std.debug.assert(emit.error_msg == null); | 256 | std.debug.assert(emit.error_msg == null); |
| 257 | const mod = emit.bin_file.base.comp.module.?; | 257 | const comp = emit.bin_file.base.comp; |
| 258 | emit.error_msg = try Module.ErrorMsg.create(emit.bin_file.base.allocator, mod.declPtr(emit.decl_index).srcLoc(mod), format, args); | 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); | ||
| 259 | return error.EmitFail; | 261 | return error.EmitFail; |
| 260 | } | 262 | } |
| 261 | 263 | ||
| ... | @@ -299,6 +301,8 @@ fn emitLabel(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { | ... | @@ -299,6 +301,8 @@ fn emitLabel(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { |
| 299 | } | 301 | } |
| 300 | 302 | ||
| 301 | fn emitGlobal(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { | 303 | fn 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; | ||
| 302 | const label = emit.mir.instructions.items(.data)[inst].label; | 306 | const label = emit.mir.instructions.items(.data)[inst].label; |
| 303 | try emit.code.append(@intFromEnum(tag)); | 307 | try emit.code.append(@intFromEnum(tag)); |
| 304 | var buf: [5]u8 = undefined; | 308 | var buf: [5]u8 = undefined; |
| ... | @@ -308,7 +312,7 @@ fn emitGlobal(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { | ... | @@ -308,7 +312,7 @@ fn emitGlobal(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { |
| 308 | 312 | ||
| 309 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; | 313 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; |
| 310 | const atom = emit.bin_file.getAtomPtr(atom_index); | 314 | const atom = emit.bin_file.getAtomPtr(atom_index); |
| 311 | try atom.relocs.append(emit.bin_file.base.allocator, .{ | 315 | try atom.relocs.append(gpa, .{ |
| 312 | .index = label, | 316 | .index = label, |
| 313 | .offset = global_offset, | 317 | .offset = global_offset, |
| 314 | .relocation_type = .R_WASM_GLOBAL_INDEX_LEB, | 318 | .relocation_type = .R_WASM_GLOBAL_INDEX_LEB, |
| ... | @@ -356,6 +360,8 @@ fn encodeMemArg(mem_arg: Mir.MemArg, writer: anytype) !void { | ... | @@ -356,6 +360,8 @@ fn encodeMemArg(mem_arg: Mir.MemArg, writer: anytype) !void { |
| 356 | } | 360 | } |
| 357 | 361 | ||
| 358 | fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void { | 362 | fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 363 | const comp = emit.bin_file.base.comp; | ||
| 364 | const gpa = comp.gpa; | ||
| 359 | const label = emit.mir.instructions.items(.data)[inst].label; | 365 | const label = emit.mir.instructions.items(.data)[inst].label; |
| 360 | try emit.code.append(std.wasm.opcode(.call)); | 366 | try emit.code.append(std.wasm.opcode(.call)); |
| 361 | const call_offset = emit.offset(); | 367 | const call_offset = emit.offset(); |
| ... | @@ -366,7 +372,7 @@ fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -366,7 +372,7 @@ fn emitCall(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 366 | if (label != 0) { | 372 | if (label != 0) { |
| 367 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; | 373 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; |
| 368 | const atom = emit.bin_file.getAtomPtr(atom_index); | 374 | const atom = emit.bin_file.getAtomPtr(atom_index); |
| 369 | try atom.relocs.append(emit.bin_file.base.allocator, .{ | 375 | try atom.relocs.append(gpa, .{ |
| 370 | .offset = call_offset, | 376 | .offset = call_offset, |
| 371 | .index = label, | 377 | .index = label, |
| 372 | .relocation_type = .R_WASM_FUNCTION_INDEX_LEB, | 378 | .relocation_type = .R_WASM_FUNCTION_INDEX_LEB, |
| ... | @@ -384,6 +390,8 @@ fn emitCallIndirect(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -384,6 +390,8 @@ fn emitCallIndirect(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 384 | } | 390 | } |
| 385 | 391 | ||
| 386 | fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void { | 392 | fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 393 | const comp = emit.bin_file.base.comp; | ||
| 394 | const gpa = comp.gpa; | ||
| 387 | const symbol_index = emit.mir.instructions.items(.data)[inst].label; | 395 | const symbol_index = emit.mir.instructions.items(.data)[inst].label; |
| 388 | try emit.code.append(std.wasm.opcode(.i32_const)); | 396 | try emit.code.append(std.wasm.opcode(.i32_const)); |
| 389 | const index_offset = emit.offset(); | 397 | const index_offset = emit.offset(); |
| ... | @@ -394,7 +402,7 @@ fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -394,7 +402,7 @@ fn emitFunctionIndex(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 394 | if (symbol_index != 0) { | 402 | if (symbol_index != 0) { |
| 395 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; | 403 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; |
| 396 | const atom = emit.bin_file.getAtomPtr(atom_index); | 404 | const atom = emit.bin_file.getAtomPtr(atom_index); |
| 397 | try atom.relocs.append(emit.bin_file.base.allocator, .{ | 405 | try atom.relocs.append(gpa, .{ |
| 398 | .offset = index_offset, | 406 | .offset = index_offset, |
| 399 | .index = symbol_index, | 407 | .index = symbol_index, |
| 400 | .relocation_type = .R_WASM_TABLE_INDEX_SLEB, | 408 | .relocation_type = .R_WASM_TABLE_INDEX_SLEB, |
| ... | @@ -406,7 +414,9 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -406,7 +414,9 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 406 | const extra_index = emit.mir.instructions.items(.data)[inst].payload; | 414 | const extra_index = emit.mir.instructions.items(.data)[inst].payload; |
| 407 | const mem = emit.mir.extraData(Mir.Memory, extra_index).data; | 415 | const mem = emit.mir.extraData(Mir.Memory, extra_index).data; |
| 408 | const mem_offset = emit.offset() + 1; | 416 | 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; | ||
| 410 | const is_wasm32 = target.cpu.arch == .wasm32; | 420 | const is_wasm32 = target.cpu.arch == .wasm32; |
| 411 | if (is_wasm32) { | 421 | if (is_wasm32) { |
| 412 | try emit.code.append(std.wasm.opcode(.i32_const)); | 422 | try emit.code.append(std.wasm.opcode(.i32_const)); |
| ... | @@ -423,7 +433,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -423,7 +433,7 @@ fn emitMemAddress(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 423 | if (mem.pointer != 0) { | 433 | if (mem.pointer != 0) { |
| 424 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; | 434 | const atom_index = emit.bin_file.decls.get(emit.decl_index).?; |
| 425 | const atom = emit.bin_file.getAtomPtr(atom_index); | 435 | const atom = emit.bin_file.getAtomPtr(atom_index); |
| 426 | try atom.relocs.append(emit.bin_file.base.allocator, .{ | 436 | try atom.relocs.append(gpa, .{ |
| 427 | .offset = mem_offset, | 437 | .offset = mem_offset, |
| 428 | .index = mem.pointer, | 438 | .index = mem.pointer, |
| 429 | .relocation_type = if (is_wasm32) .R_WASM_MEMORY_ADDR_LEB else .R_WASM_MEMORY_ADDR_LEB64, | 439 | .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( | ... | @@ -795,15 +795,16 @@ pub fn generate( |
| 795 | code: *std.ArrayList(u8), | 795 | code: *std.ArrayList(u8), |
| 796 | debug_output: DebugInfoOutput, | 796 | debug_output: DebugInfoOutput, |
| 797 | ) CodeGenError!Result { | 797 | ) 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.?; | ||
| 799 | const func = mod.funcInfo(func_index); | 801 | const func = mod.funcInfo(func_index); |
| 800 | const fn_owner_decl = mod.declPtr(func.owner_decl); | 802 | const fn_owner_decl = mod.declPtr(func.owner_decl); |
| 801 | assert(fn_owner_decl.has_tv); | 803 | assert(fn_owner_decl.has_tv); |
| 802 | const fn_type = fn_owner_decl.ty; | 804 | const fn_type = fn_owner_decl.ty; |
| 803 | const namespace = mod.namespacePtr(fn_owner_decl.src_namespace); | 805 | 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; |
| 805 | 807 | ||
| 806 | const gpa = bin_file.allocator; | ||
| 807 | var function = Self{ | 808 | var function = Self{ |
| 808 | .gpa = gpa, | 809 | .gpa = gpa, |
| 809 | .air = air, | 810 | .air = air, |
| ... | @@ -860,7 +861,7 @@ pub fn generate( | ... | @@ -860,7 +861,7 @@ pub fn generate( |
| 860 | error.CodegenFail => return Result{ .fail = function.err_msg.? }, | 861 | error.CodegenFail => return Result{ .fail = function.err_msg.? }, |
| 861 | error.OutOfRegisters => return Result{ | 862 | error.OutOfRegisters => return Result{ |
| 862 | .fail = try ErrorMsg.create( | 863 | .fail = try ErrorMsg.create( |
| 863 | bin_file.allocator, | 864 | gpa, |
| 864 | src_loc, | 865 | src_loc, |
| 865 | "CodeGen ran out of registers. This is a bug in the Zig compiler.", | 866 | "CodeGen ran out of registers. This is a bug in the Zig compiler.", |
| 866 | .{}, | 867 | .{}, |
| ... | @@ -904,22 +905,22 @@ pub fn generate( | ... | @@ -904,22 +905,22 @@ pub fn generate( |
| 904 | function.gen() catch |err| switch (err) { | 905 | function.gen() catch |err| switch (err) { |
| 905 | error.CodegenFail => return Result{ .fail = function.err_msg.? }, | 906 | error.CodegenFail => return Result{ .fail = function.err_msg.? }, |
| 906 | error.OutOfRegisters => return Result{ | 907 | 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.", .{}), |
| 908 | }, | 909 | }, |
| 909 | else => |e| return e, | 910 | else => |e| return e, |
| 910 | }; | 911 | }; |
| 911 | 912 | ||
| 912 | var mir = Mir{ | 913 | var mir = Mir{ |
| 913 | .instructions = function.mir_instructions.toOwnedSlice(), | 914 | .instructions = function.mir_instructions.toOwnedSlice(), |
| 914 | .extra = try function.mir_extra.toOwnedSlice(bin_file.allocator), | 915 | .extra = try function.mir_extra.toOwnedSlice(gpa), |
| 915 | .frame_locs = function.frame_locs.toOwnedSlice(), | 916 | .frame_locs = function.frame_locs.toOwnedSlice(), |
| 916 | }; | 917 | }; |
| 917 | defer mir.deinit(bin_file.allocator); | 918 | defer mir.deinit(gpa); |
| 918 | 919 | ||
| 919 | var emit = Emit{ | 920 | var emit = Emit{ |
| 920 | .lower = .{ | 921 | .lower = .{ |
| 921 | .bin_file = bin_file, | 922 | .bin_file = bin_file, |
| 922 | .allocator = bin_file.allocator, | 923 | .allocator = gpa, |
| 923 | .mir = mir, | 924 | .mir = mir, |
| 924 | .cc = cc, | 925 | .cc = cc, |
| 925 | .src_loc = src_loc, | 926 | .src_loc = src_loc, |
| ... | @@ -940,7 +941,7 @@ pub fn generate( | ... | @@ -940,7 +941,7 @@ pub fn generate( |
| 940 | }; | 941 | }; |
| 941 | return Result{ | 942 | return Result{ |
| 942 | .fail = try ErrorMsg.create( | 943 | .fail = try ErrorMsg.create( |
| 943 | bin_file.allocator, | 944 | gpa, |
| 944 | src_loc, | 945 | src_loc, |
| 945 | "{s} This is a bug in the Zig compiler.", | 946 | "{s} This is a bug in the Zig compiler.", |
| 946 | .{msg}, | 947 | .{msg}, |
| ... | @@ -964,12 +965,13 @@ pub fn generateLazy( | ... | @@ -964,12 +965,13 @@ pub fn generateLazy( |
| 964 | code: *std.ArrayList(u8), | 965 | code: *std.ArrayList(u8), |
| 965 | debug_output: DebugInfoOutput, | 966 | debug_output: DebugInfoOutput, |
| 966 | ) CodeGenError!Result { | 967 | ) CodeGenError!Result { |
| 967 | const gpa = bin_file.allocator; | 968 | const comp = bin_file.comp; |
| 968 | const zcu = bin_file.comp.module.?; | 969 | const gpa = comp.gpa; |
| 970 | const zcu = comp.module.?; | ||
| 969 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); | 971 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); |
| 970 | const decl = zcu.declPtr(decl_index); | 972 | const decl = zcu.declPtr(decl_index); |
| 971 | const namespace = zcu.namespacePtr(decl.src_namespace); | 973 | 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; |
| 973 | var function = Self{ | 975 | var function = Self{ |
| 974 | .gpa = gpa, | 976 | .gpa = gpa, |
| 975 | .air = undefined, | 977 | .air = undefined, |
| ... | @@ -996,22 +998,22 @@ pub fn generateLazy( | ... | @@ -996,22 +998,22 @@ pub fn generateLazy( |
| 996 | function.genLazy(lazy_sym) catch |err| switch (err) { | 998 | function.genLazy(lazy_sym) catch |err| switch (err) { |
| 997 | error.CodegenFail => return Result{ .fail = function.err_msg.? }, | 999 | error.CodegenFail => return Result{ .fail = function.err_msg.? }, |
| 998 | error.OutOfRegisters => return Result{ | 1000 | 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.", .{}), |
| 1000 | }, | 1002 | }, |
| 1001 | else => |e| return e, | 1003 | else => |e| return e, |
| 1002 | }; | 1004 | }; |
| 1003 | 1005 | ||
| 1004 | var mir = Mir{ | 1006 | var mir = Mir{ |
| 1005 | .instructions = function.mir_instructions.toOwnedSlice(), | 1007 | .instructions = function.mir_instructions.toOwnedSlice(), |
| 1006 | .extra = try function.mir_extra.toOwnedSlice(bin_file.allocator), | 1008 | .extra = try function.mir_extra.toOwnedSlice(gpa), |
| 1007 | .frame_locs = function.frame_locs.toOwnedSlice(), | 1009 | .frame_locs = function.frame_locs.toOwnedSlice(), |
| 1008 | }; | 1010 | }; |
| 1009 | defer mir.deinit(bin_file.allocator); | 1011 | defer mir.deinit(gpa); |
| 1010 | 1012 | ||
| 1011 | var emit = Emit{ | 1013 | var emit = Emit{ |
| 1012 | .lower = .{ | 1014 | .lower = .{ |
| 1013 | .bin_file = bin_file, | 1015 | .bin_file = bin_file, |
| 1014 | .allocator = bin_file.allocator, | 1016 | .allocator = gpa, |
| 1015 | .mir = mir, | 1017 | .mir = mir, |
| 1016 | .cc = abi.resolveCallingConvention(.Unspecified, function.target.*), | 1018 | .cc = abi.resolveCallingConvention(.Unspecified, function.target.*), |
| 1017 | .src_loc = src_loc, | 1019 | .src_loc = src_loc, |
| ... | @@ -1032,7 +1034,7 @@ pub fn generateLazy( | ... | @@ -1032,7 +1034,7 @@ pub fn generateLazy( |
| 1032 | }; | 1034 | }; |
| 1033 | return Result{ | 1035 | return Result{ |
| 1034 | .fail = try ErrorMsg.create( | 1036 | .fail = try ErrorMsg.create( |
| 1035 | bin_file.allocator, | 1037 | gpa, |
| 1036 | src_loc, | 1038 | src_loc, |
| 1037 | "{s} This is a bug in the Zig compiler.", | 1039 | "{s} This is a bug in the Zig compiler.", |
| 1038 | .{msg}, | 1040 | .{msg}, |
| ... | @@ -16416,14 +16418,16 @@ fn resolveCallingConventionValues( | ... | @@ -16416,14 +16418,16 @@ fn resolveCallingConventionValues( |
| 16416 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 16418 | fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 16417 | @setCold(true); | 16419 | @setCold(true); |
| 16418 | assert(self.err_msg == null); | 16420 | 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); | ||
| 16420 | return error.CodegenFail; | 16423 | return error.CodegenFail; |
| 16421 | } | 16424 | } |
| 16422 | 16425 | ||
| 16423 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { | 16426 | fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError { |
| 16424 | @setCold(true); | 16427 | @setCold(true); |
| 16425 | assert(self.err_msg == null); | 16428 | 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); | ||
| 16427 | return error.CodegenFail; | 16431 | return error.CodegenFail; |
| 16428 | } | 16432 | } |
| 16429 | 16433 |
src/codegen.zig+19-14| ... | @@ -57,7 +57,7 @@ pub fn generateFunction( | ... | @@ -57,7 +57,7 @@ pub fn generateFunction( |
| 57 | const func = zcu.funcInfo(func_index); | 57 | const func = zcu.funcInfo(func_index); |
| 58 | const decl = zcu.declPtr(func.owner_decl); | 58 | const decl = zcu.declPtr(func.owner_decl); |
| 59 | const namespace = zcu.namespacePtr(decl.src_namespace); | 59 | 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; |
| 61 | switch (target.cpu.arch) { | 61 | switch (target.cpu.arch) { |
| 62 | .arm, | 62 | .arm, |
| 63 | .armeb, | 63 | .armeb, |
| ... | @@ -87,7 +87,7 @@ pub fn generateLazyFunction( | ... | @@ -87,7 +87,7 @@ pub fn generateLazyFunction( |
| 87 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); | 87 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); |
| 88 | const decl = zcu.declPtr(decl_index); | 88 | const decl = zcu.declPtr(decl_index); |
| 89 | const namespace = zcu.namespacePtr(decl.src_namespace); | 89 | 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; |
| 91 | switch (target.cpu.arch) { | 91 | switch (target.cpu.arch) { |
| 92 | .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, src_loc, lazy_sym, code, debug_output), | 92 | .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, src_loc, lazy_sym, code, debug_output), |
| 93 | else => unreachable, | 93 | else => unreachable, |
| ... | @@ -117,12 +117,14 @@ pub fn generateLazySymbol( | ... | @@ -117,12 +117,14 @@ pub fn generateLazySymbol( |
| 117 | const tracy = trace(@src()); | 117 | const tracy = trace(@src()); |
| 118 | defer tracy.end(); | 118 | defer tracy.end(); |
| 119 | 119 | ||
| 120 | const zcu = bin_file.comp.module.?; | 120 | const comp = bin_file.comp; |
| 121 | const zcu = comp.module.?; | ||
| 121 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); | 122 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); |
| 122 | const decl = zcu.declPtr(decl_index); | 123 | const decl = zcu.declPtr(decl_index); |
| 123 | const namespace = zcu.namespacePtr(decl.src_namespace); | 124 | 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; |
| 125 | const endian = target.cpu.arch.endian(); | 126 | const endian = target.cpu.arch.endian(); |
| 127 | const gpa = comp.gpa; | ||
| 126 | 128 | ||
| 127 | log.debug("generateLazySymbol: kind = {s}, ty = {}", .{ | 129 | log.debug("generateLazySymbol: kind = {s}, ty = {}", .{ |
| 128 | @tagName(lazy_sym.kind), | 130 | @tagName(lazy_sym.kind), |
| ... | @@ -160,7 +162,7 @@ pub fn generateLazySymbol( | ... | @@ -160,7 +162,7 @@ pub fn generateLazySymbol( |
| 160 | } | 162 | } |
| 161 | return Result.ok; | 163 | return Result.ok; |
| 162 | } else return .{ .fail = try ErrorMsg.create( | 164 | } else return .{ .fail = try ErrorMsg.create( |
| 163 | bin_file.allocator, | 165 | gpa, |
| 164 | src_loc, | 166 | src_loc, |
| 165 | "TODO implement generateLazySymbol for {s} {}", | 167 | "TODO implement generateLazySymbol for {s} {}", |
| 166 | .{ @tagName(lazy_sym.kind), lazy_sym.ty.fmt(zcu) }, | 168 | .{ @tagName(lazy_sym.kind), lazy_sym.ty.fmt(zcu) }, |
| ... | @@ -827,7 +829,7 @@ fn lowerDeclRef( | ... | @@ -827,7 +829,7 @@ fn lowerDeclRef( |
| 827 | const zcu = lf.comp.module.?; | 829 | const zcu = lf.comp.module.?; |
| 828 | const decl = zcu.declPtr(decl_index); | 830 | const decl = zcu.declPtr(decl_index); |
| 829 | const namespace = zcu.namespacePtr(decl.src_namespace); | 831 | 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; |
| 831 | 833 | ||
| 832 | const ptr_width = target.ptrBitWidth(); | 834 | const ptr_width = target.ptrBitWidth(); |
| 833 | const is_fn_body = decl.ty.zigTypeTag(zcu) == .Fn; | 835 | const is_fn_body = decl.ty.zigTypeTag(zcu) == .Fn; |
| ... | @@ -921,7 +923,7 @@ fn genDeclRef( | ... | @@ -921,7 +923,7 @@ fn genDeclRef( |
| 921 | 923 | ||
| 922 | const ptr_decl = zcu.declPtr(ptr_decl_index); | 924 | const ptr_decl = zcu.declPtr(ptr_decl_index); |
| 923 | const namespace = zcu.namespacePtr(ptr_decl.src_namespace); | 925 | 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; |
| 925 | 927 | ||
| 926 | const ptr_bits = target.ptrBitWidth(); | 928 | const ptr_bits = target.ptrBitWidth(); |
| 927 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); | 929 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); |
| ... | @@ -944,6 +946,9 @@ fn genDeclRef( | ... | @@ -944,6 +946,9 @@ fn genDeclRef( |
| 944 | return GenResult.mcv(.{ .immediate = imm }); | 946 | return GenResult.mcv(.{ .immediate = imm }); |
| 945 | } | 947 | } |
| 946 | 948 | ||
| 949 | const comp = lf.comp; | ||
| 950 | const gpa = comp.gpa; | ||
| 951 | |||
| 947 | // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`? | 952 | // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`? |
| 948 | if (tv.ty.castPtrToFn(zcu)) |fn_ty| { | 953 | if (tv.ty.castPtrToFn(zcu)) |fn_ty| { |
| 949 | if (zcu.typeToFunc(fn_ty).?.is_generic) { | 954 | if (zcu.typeToFunc(fn_ty).?.is_generic) { |
| ... | @@ -958,8 +963,8 @@ fn genDeclRef( | ... | @@ -958,8 +963,8 @@ fn genDeclRef( |
| 958 | 963 | ||
| 959 | try zcu.markDeclAlive(decl); | 964 | try zcu.markDeclAlive(decl); |
| 960 | 965 | ||
| 961 | const decl_namespace = zcu.namespacePtr(decl.namespace_index); | 966 | const decl_namespace = zcu.namespacePtr(decl.src_namespace); |
| 962 | const single_threaded = decl_namespace.file_scope.zcu.single_threaded; | 967 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; |
| 963 | const is_threadlocal = tv.val.isPtrToThreadLocal(zcu) and !single_threaded; | 968 | const is_threadlocal = tv.val.isPtrToThreadLocal(zcu) and !single_threaded; |
| 964 | const is_extern = decl.isExtern(zcu); | 969 | const is_extern = decl.isExtern(zcu); |
| 965 | 970 | ||
| ... | @@ -985,8 +990,8 @@ fn genDeclRef( | ... | @@ -985,8 +990,8 @@ fn genDeclRef( |
| 985 | if (is_extern) { | 990 | if (is_extern) { |
| 986 | // TODO make this part of getGlobalSymbol | 991 | // TODO make this part of getGlobalSymbol |
| 987 | const name = zcu.intern_pool.stringToSlice(decl.name); | 992 | const name = zcu.intern_pool.stringToSlice(decl.name); |
| 988 | const sym_name = try std.fmt.allocPrint(lf.allocator, "_{s}", .{name}); | 993 | const sym_name = try std.fmt.allocPrint(gpa, "_{s}", .{name}); |
| 989 | defer lf.allocator.free(sym_name); | 994 | defer gpa.free(sym_name); |
| 990 | const global_index = try macho_file.addUndefined(sym_name, .{ .add_got = true }); | 995 | const global_index = try macho_file.addUndefined(sym_name, .{ .add_got = true }); |
| 991 | return GenResult.mcv(.{ .load_got = link.File.MachO.global_symbol_bit | global_index }); | 996 | return GenResult.mcv(.{ .load_got = link.File.MachO.global_symbol_bit | global_index }); |
| 992 | } | 997 | } |
| ... | @@ -1005,7 +1010,7 @@ fn genDeclRef( | ... | @@ -1005,7 +1010,7 @@ fn genDeclRef( |
| 1005 | else | 1010 | else |
| 1006 | null; | 1011 | null; |
| 1007 | const global_index = try coff_file.getGlobalSymbol(name, lib_name); | 1012 | 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 |
| 1009 | return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index }); | 1014 | return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index }); |
| 1010 | } | 1015 | } |
| 1011 | const atom_index = try coff_file.getOrCreateAtomForDecl(decl_index); | 1016 | const atom_index = try coff_file.getOrCreateAtomForDecl(decl_index); |
| ... | @@ -1016,7 +1021,7 @@ fn genDeclRef( | ... | @@ -1016,7 +1021,7 @@ fn genDeclRef( |
| 1016 | const atom = p9.getAtom(atom_index); | 1021 | const atom = p9.getAtom(atom_index); |
| 1017 | return GenResult.mcv(.{ .memory = atom.getOffsetTableAddress(p9) }); | 1022 | return GenResult.mcv(.{ .memory = atom.getOffsetTableAddress(p9) }); |
| 1018 | } else { | 1023 | } 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}); |
| 1020 | } | 1025 | } |
| 1021 | } | 1026 | } |
| 1022 | 1027 | ||
| ... | @@ -1073,7 +1078,7 @@ pub fn genTypedValue( | ... | @@ -1073,7 +1078,7 @@ pub fn genTypedValue( |
| 1073 | 1078 | ||
| 1074 | const owner_decl = zcu.declPtr(owner_decl_index); | 1079 | const owner_decl = zcu.declPtr(owner_decl_index); |
| 1075 | const namespace = zcu.namespacePtr(owner_decl.src_namespace); | 1080 | 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; |
| 1077 | const ptr_bits = target.ptrBitWidth(); | 1082 | const ptr_bits = target.ptrBitWidth(); |
| 1078 | 1083 | ||
| 1079 | if (!typed_value.ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(typed_value.val.toIntern())) { | 1084 | 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 { | ... | @@ -1785,7 +1785,7 @@ pub const Object = struct { |
| 1785 | if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder); | 1785 | if (wantDllExports(mod)) global_index.setDllStorageClass(.default, &self.builder); |
| 1786 | global_index.setUnnamedAddr(.unnamed_addr, &self.builder); | 1786 | global_index.setUnnamedAddr(.unnamed_addr, &self.builder); |
| 1787 | if (decl.val.getVariable(mod)) |decl_var| { | 1787 | 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); |
| 1789 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; | 1789 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; |
| 1790 | global_index.ptrConst(&self.builder).kind.variable.setThreadLocal( | 1790 | global_index.ptrConst(&self.builder).kind.variable.setThreadLocal( |
| 1791 | if (decl_var.is_threadlocal and !single_threaded) | 1791 | if (decl_var.is_threadlocal and !single_threaded) |
| ... | @@ -3173,7 +3173,7 @@ pub const Object = struct { | ... | @@ -3173,7 +3173,7 @@ pub const Object = struct { |
| 3173 | variable_index.setLinkage(.external, &o.builder); | 3173 | variable_index.setLinkage(.external, &o.builder); |
| 3174 | variable_index.setUnnamedAddr(.default, &o.builder); | 3174 | variable_index.setUnnamedAddr(.default, &o.builder); |
| 3175 | if (decl.val.getVariable(mod)) |decl_var| { | 3175 | 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); |
| 3177 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; | 3177 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; |
| 3178 | variable_index.setThreadLocal( | 3178 | variable_index.setThreadLocal( |
| 3179 | if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default, | 3179 | 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 { | ... | @@ -123,7 +123,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void { |
| 123 | .local_cache_directory = comp.global_cache_directory, | 123 | .local_cache_directory = comp.global_cache_directory, |
| 124 | .global_cache_directory = comp.global_cache_directory, | 124 | .global_cache_directory = comp.global_cache_directory, |
| 125 | .zig_lib_directory = comp.zig_lib_directory, | 125 | .zig_lib_directory = comp.zig_lib_directory, |
| 126 | .resolved = config, | 126 | .config = config, |
| 127 | .root_mod = root_mod, | 127 | .root_mod = root_mod, |
| 128 | .cache_mode = .whole, | 128 | .cache_mode = .whole, |
| 129 | .root_name = root_name, | 129 | .root_name = root_name, |
src/link.zig+28-35| ... | @@ -69,10 +69,12 @@ pub const File = struct { | ... | @@ -69,10 +69,12 @@ pub const File = struct { |
| 69 | allow_shlib_undefined: bool, | 69 | allow_shlib_undefined: bool, |
| 70 | stack_size: u64, | 70 | stack_size: u64, |
| 71 | 71 | ||
| 72 | error_flags: ErrorFlags = .{}, | ||
| 73 | misc_errors: std.ArrayListUnmanaged(ErrorMsg) = .{}, | ||
| 74 | |||
| 72 | /// Prevents other processes from clobbering files in the output directory | 75 | /// Prevents other processes from clobbering files in the output directory |
| 73 | /// of this linking operation. | 76 | /// of this linking operation. |
| 74 | lock: ?Cache.Lock = null, | 77 | lock: ?Cache.Lock = null, |
| 75 | |||
| 76 | child_pid: ?std.ChildProcess.Id = null, | 78 | child_pid: ?std.ChildProcess.Id = null, |
| 77 | 79 | ||
| 78 | pub const OpenOptions = struct { | 80 | pub const OpenOptions = struct { |
| ... | @@ -210,6 +212,8 @@ pub const File = struct { | ... | @@ -210,6 +212,8 @@ pub const File = struct { |
| 210 | } | 212 | } |
| 211 | 213 | ||
| 212 | pub fn makeWritable(base: *File) !void { | 214 | pub fn makeWritable(base: *File) !void { |
| 215 | const comp = base.comp; | ||
| 216 | const gpa = comp.gpa; | ||
| 213 | switch (base.tag) { | 217 | switch (base.tag) { |
| 214 | .coff, .elf, .macho, .plan9, .wasm => { | 218 | .coff, .elf, .macho, .plan9, .wasm => { |
| 215 | if (build_options.only_c) unreachable; | 219 | if (build_options.only_c) unreachable; |
| ... | @@ -225,9 +229,10 @@ pub const File = struct { | ... | @@ -225,9 +229,10 @@ pub const File = struct { |
| 225 | // it will return ETXTBSY. So instead, we copy the file, atomically rename it | 229 | // it will return ETXTBSY. So instead, we copy the file, atomically rename it |
| 226 | // over top of the exe path, and then proceed normally. This changes the inode, | 230 | // over top of the exe path, and then proceed normally. This changes the inode, |
| 227 | // avoiding the error. | 231 | // 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}", .{ |
| 229 | emit.sub_path, std.crypto.random.int(u32), | 233 | emit.sub_path, std.crypto.random.int(u32), |
| 230 | }); | 234 | }); |
| 235 | defer gpa.free(tmp_sub_path); | ||
| 231 | try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{}); | 236 | try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, tmp_sub_path, .{}); |
| 232 | try emit.directory.handle.rename(tmp_sub_path, emit.sub_path); | 237 | try emit.directory.handle.rename(tmp_sub_path, emit.sub_path); |
| 233 | switch (builtin.os.tag) { | 238 | switch (builtin.os.tag) { |
| ... | @@ -242,9 +247,9 @@ pub const File = struct { | ... | @@ -242,9 +247,9 @@ pub const File = struct { |
| 242 | } | 247 | } |
| 243 | } | 248 | } |
| 244 | } | 249 | } |
| 245 | const use_lld = build_options.have_llvm and base.comp.config.use_lld; | 250 | const use_lld = build_options.have_llvm and comp.config.use_lld; |
| 246 | const output_mode = base.comp.config.output_mode; | 251 | const output_mode = comp.config.output_mode; |
| 247 | const link_mode = base.comp.config.link_mode; | 252 | const link_mode = comp.config.link_mode; |
| 248 | base.file = try emit.directory.handle.createFile(emit.sub_path, .{ | 253 | base.file = try emit.directory.handle.createFile(emit.sub_path, .{ |
| 249 | .truncate = false, | 254 | .truncate = false, |
| 250 | .read = true, | 255 | .read = true, |
| ... | @@ -256,9 +261,10 @@ pub const File = struct { | ... | @@ -256,9 +261,10 @@ pub const File = struct { |
| 256 | } | 261 | } |
| 257 | 262 | ||
| 258 | pub fn makeExecutable(base: *File) !void { | 263 | pub fn makeExecutable(base: *File) !void { |
| 259 | const output_mode = base.comp.config.output_mode; | 264 | const comp = base.comp; |
| 260 | const link_mode = base.comp.config.link_mode; | 265 | const output_mode = comp.config.output_mode; |
| 261 | const use_lld = build_options.have_llvm and base.comp.config.use_lld; | 266 | const link_mode = comp.config.link_mode; |
| 267 | const use_lld = build_options.have_llvm and comp.config.use_lld; | ||
| 262 | 268 | ||
| 263 | switch (output_mode) { | 269 | switch (output_mode) { |
| 264 | .Obj => return, | 270 | .Obj => return, |
| ... | @@ -464,8 +470,13 @@ pub const File = struct { | ... | @@ -464,8 +470,13 @@ pub const File = struct { |
| 464 | } | 470 | } |
| 465 | 471 | ||
| 466 | pub fn destroy(base: *File) void { | 472 | pub fn destroy(base: *File) void { |
| 473 | const gpa = base.comp.gpa; | ||
| 467 | base.releaseLock(); | 474 | base.releaseLock(); |
| 468 | if (base.file) |f| f.close(); | 475 | if (base.file) |f| f.close(); |
| 476 | { | ||
| 477 | for (base.misc_errors.items) |*item| item.deinit(gpa); | ||
| 478 | base.misc_errors.deinit(gpa); | ||
| 479 | } | ||
| 469 | switch (base.tag) { | 480 | switch (base.tag) { |
| 470 | .coff => { | 481 | .coff => { |
| 471 | if (build_options.only_c) unreachable; | 482 | if (build_options.only_c) unreachable; |
| ... | @@ -602,9 +613,9 @@ pub const File = struct { | ... | @@ -602,9 +613,9 @@ pub const File = struct { |
| 602 | return; | 613 | return; |
| 603 | } | 614 | } |
| 604 | 615 | ||
| 605 | const use_lld = build_options.have_llvm and base.comp.config.use_lld; | 616 | const use_lld = build_options.have_llvm and comp.config.use_lld; |
| 606 | const output_mode = base.comp.config.output_mode; | 617 | const output_mode = comp.config.output_mode; |
| 607 | const link_mode = base.comp.config.link_mode; | 618 | const link_mode = comp.config.link_mode; |
| 608 | if (use_lld and output_mode == .Lib and link_mode == .Static) { | 619 | if (use_lld and output_mode == .Lib and link_mode == .Static) { |
| 609 | return base.linkAsArchive(comp, prog_node); | 620 | return base.linkAsArchive(comp, prog_node); |
| 610 | } | 621 | } |
| ... | @@ -657,25 +668,6 @@ pub const File = struct { | ... | @@ -657,25 +668,6 @@ pub const File = struct { |
| 657 | } | 668 | } |
| 658 | } | 669 | } |
| 659 | 670 | ||
| 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 | |||
| 679 | pub const UpdateExportsError = error{ | 671 | pub const UpdateExportsError = error{ |
| 680 | OutOfMemory, | 672 | OutOfMemory, |
| 681 | AnalysisFail, | 673 | AnalysisFail, |
| ... | @@ -781,14 +773,15 @@ pub const File = struct { | ... | @@ -781,14 +773,15 @@ pub const File = struct { |
| 781 | const tracy = trace(@src()); | 773 | const tracy = trace(@src()); |
| 782 | defer tracy.end(); | 774 | defer tracy.end(); |
| 783 | 775 | ||
| 784 | var arena_allocator = std.heap.ArenaAllocator.init(base.allocator); | 776 | const gpa = comp.gpa; |
| 777 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); | ||
| 785 | defer arena_allocator.deinit(); | 778 | defer arena_allocator.deinit(); |
| 786 | const arena = arena_allocator.allocator(); | 779 | const arena = arena_allocator.allocator(); |
| 787 | 780 | ||
| 788 | const directory = base.emit.directory; // Just an alias to make it shorter to type. | 781 | const directory = base.emit.directory; // Just an alias to make it shorter to type. |
| 789 | const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path}); | 782 | const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path}); |
| 790 | const full_out_path_z = try arena.dupeZ(u8, full_out_path); | 783 | 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; |
| 792 | 785 | ||
| 793 | // If there is no Zig code to compile, then we should skip flushing the output file | 786 | // If there is no Zig code to compile, then we should skip flushing the output file |
| 794 | // because it will not be part of the linker line anyway. | 787 | // because it will not be part of the linker line anyway. |
| ... | @@ -801,7 +794,7 @@ pub const File = struct { | ... | @@ -801,7 +794,7 @@ pub const File = struct { |
| 801 | 794 | ||
| 802 | log.debug("zcu_obj_path={s}", .{if (zcu_obj_path) |s| s else "(null)"}); | 795 | log.debug("zcu_obj_path={s}", .{if (zcu_obj_path) |s| s else "(null)"}); |
| 803 | 796 | ||
| 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) |
| 805 | comp.compiler_rt_obj.?.full_object_path | 798 | comp.compiler_rt_obj.?.full_object_path |
| 806 | else | 799 | else |
| 807 | null; | 800 | null; |
| ... | @@ -815,7 +808,7 @@ pub const File = struct { | ... | @@ -815,7 +808,7 @@ pub const File = struct { |
| 815 | var man: Cache.Manifest = undefined; | 808 | var man: Cache.Manifest = undefined; |
| 816 | defer if (!base.disable_lld_caching) man.deinit(); | 809 | defer if (!base.disable_lld_caching) man.deinit(); |
| 817 | 810 | ||
| 818 | const objects = base.comp.objects; | 811 | const objects = comp.objects; |
| 819 | 812 | ||
| 820 | var digest: [Cache.hex_digest_len]u8 = undefined; | 813 | var digest: [Cache.hex_digest_len]u8 = undefined; |
| 821 | 814 | ||
| ... | @@ -869,7 +862,7 @@ pub const File = struct { | ... | @@ -869,7 +862,7 @@ pub const File = struct { |
| 869 | 862 | ||
| 870 | const win32_resource_table_len = if (build_options.only_core_functionality) 0 else comp.win32_resource_table.count(); | 863 | const win32_resource_table_len = if (build_options.only_core_functionality) 0 else comp.win32_resource_table.count(); |
| 871 | const num_object_files = objects.len + comp.c_object_table.count() + win32_resource_table_len + 2; | 864 | 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); |
| 873 | defer object_files.deinit(); | 866 | defer object_files.deinit(); |
| 874 | 867 | ||
| 875 | for (objects) |obj| { | 868 | for (objects) |obj| { |
src/link/C.zig+11-1| ... | @@ -84,7 +84,8 @@ pub fn getString(this: C, s: String) []const u8 { | ... | @@ -84,7 +84,8 @@ pub fn getString(this: C, s: String) []const u8 { |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | pub fn addString(this: *C, s: []const u8) Allocator.Error!String { | 86 | pub 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; | ||
| 88 | try this.string_bytes.appendSlice(gpa, s); | 89 | try this.string_bytes.appendSlice(gpa, s); |
| 89 | return .{ | 90 | return .{ |
| 90 | .start = @intCast(this.string_bytes.items.len - s.len), | 91 | .start = @intCast(this.string_bytes.items.len - s.len), |
| ... | @@ -97,6 +98,15 @@ pub fn open( | ... | @@ -97,6 +98,15 @@ pub fn open( |
| 97 | comp: *Compilation, | 98 | comp: *Compilation, |
| 98 | emit: Compilation.Emit, | 99 | emit: Compilation.Emit, |
| 99 | options: link.File.OpenOptions, | 100 | options: link.File.OpenOptions, |
| 101 | ) !*C { | ||
| 102 | return createEmpty(arena, comp, emit, options); | ||
| 103 | } | ||
| 104 | |||
| 105 | pub fn createEmpty( | ||
| 106 | arena: Allocator, | ||
| 107 | comp: *Compilation, | ||
| 108 | emit: Compilation.Emit, | ||
| 109 | options: link.File.OpenOptions, | ||
| 100 | ) !*C { | 110 | ) !*C { |
| 101 | const target = comp.root_mod.resolved_target.result; | 111 | const target = comp.root_mod.resolved_target.result; |
| 102 | assert(target.ofmt == .c); | 112 | assert(target.ofmt == .c); |
src/link/Coff.zig+2-3| ... | @@ -8,7 +8,6 @@ llvm_object: ?*LlvmObject = null, | ... | @@ -8,7 +8,6 @@ llvm_object: ?*LlvmObject = null, |
| 8 | 8 | ||
| 9 | base: link.File, | 9 | base: link.File, |
| 10 | image_base: u64, | 10 | image_base: u64, |
| 11 | error_flags: link.File.ErrorFlags = .{}, | ||
| 12 | dll_export_fns: bool, | 11 | dll_export_fns: bool, |
| 13 | subsystem: ?std.Target.SubSystem, | 12 | subsystem: ?std.Target.SubSystem, |
| 14 | tsaware: bool, | 13 | tsaware: bool, |
| ... | @@ -1825,10 +1824,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -1825,10 +1824,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 1825 | 1824 | ||
| 1826 | if (self.entry_addr == null and self.base.comp.config.output_mode == .Exe) { | 1825 | if (self.entry_addr == null and self.base.comp.config.output_mode == .Exe) { |
| 1827 | log.debug("flushing. no_entry_point_found = true\n", .{}); | 1826 | 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; |
| 1829 | } else { | 1828 | } else { |
| 1830 | log.debug("flushing. no_entry_point_found = false\n", .{}); | 1829 | 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; |
| 1832 | try self.writeHeader(); | 1831 | try self.writeHeader(); |
| 1833 | } | 1832 | } |
| 1834 | 1833 |
src/link/Coff/Atom.zig+6-3| ... | @@ -94,7 +94,8 @@ pub fn freeListEligible(self: Atom, coff_file: *const Coff) bool { | ... | @@ -94,7 +94,8 @@ pub fn freeListEligible(self: Atom, coff_file: *const Coff) bool { |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | pub fn addRelocation(coff_file: *Coff, atom_index: Index, reloc: Relocation) !void { | 96 | pub 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; | ||
| 98 | log.debug(" (adding reloc of type {s} to target %{d})", .{ @tagName(reloc.type), reloc.target.sym_index }); | 99 | log.debug(" (adding reloc of type {s} to target %{d})", .{ @tagName(reloc.type), reloc.target.sym_index }); |
| 99 | const gop = try coff_file.relocs.getOrPut(gpa, atom_index); | 100 | const gop = try coff_file.relocs.getOrPut(gpa, atom_index); |
| 100 | if (!gop.found_existing) { | 101 | if (!gop.found_existing) { |
| ... | @@ -104,7 +105,8 @@ pub fn addRelocation(coff_file: *Coff, atom_index: Index, reloc: Relocation) !vo | ... | @@ -104,7 +105,8 @@ pub fn addRelocation(coff_file: *Coff, atom_index: Index, reloc: Relocation) !vo |
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void { | 107 | pub 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; | ||
| 108 | log.debug(" (adding base relocation at offset 0x{x} in %{d})", .{ | 110 | log.debug(" (adding base relocation at offset 0x{x} in %{d})", .{ |
| 109 | offset, | 111 | offset, |
| 110 | coff_file.getAtom(atom_index).getSymbolIndex().?, | 112 | coff_file.getAtom(atom_index).getSymbolIndex().?, |
| ... | @@ -117,7 +119,8 @@ pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void | ... | @@ -117,7 +119,8 @@ pub fn addBaseRelocation(coff_file: *Coff, atom_index: Index, offset: u32) !void |
| 117 | } | 119 | } |
| 118 | 120 | ||
| 119 | pub fn freeRelocations(coff_file: *Coff, atom_index: Index) void { | 121 | pub 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; | ||
| 121 | var removed_relocs = coff_file.relocs.fetchOrderedRemove(atom_index); | 124 | var removed_relocs = coff_file.relocs.fetchOrderedRemove(atom_index); |
| 122 | if (removed_relocs) |*relocs| relocs.value.deinit(gpa); | 125 | if (removed_relocs) |*relocs| relocs.value.deinit(gpa); |
| 123 | var removed_base_relocs = coff_file.base_relocs.fetchOrderedRemove(atom_index); | 126 | var removed_base_relocs = coff_file.base_relocs.fetchOrderedRemove(atom_index); |
src/link/Dwarf.zig+1-1| ... | @@ -1205,7 +1205,7 @@ pub fn commitDeclState( | ... | @@ -1205,7 +1205,7 @@ pub fn commitDeclState( |
| 1205 | const decl = zcu.declPtr(decl_index); | 1205 | const decl = zcu.declPtr(decl_index); |
| 1206 | const ip = &zcu.intern_pool; | 1206 | const ip = &zcu.intern_pool; |
| 1207 | const namespace = zcu.namespacePtr(decl.src_namespace); | 1207 | 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; |
| 1209 | const target_endian = target.cpu.arch.endian(); | 1209 | const target_endian = target.cpu.arch.endian(); |
| 1210 | 1210 | ||
| 1211 | var dbg_line_buffer = &decl_state.dbg_line; | 1211 | var dbg_line_buffer = &decl_state.dbg_line; |
src/link/Elf.zig+25-27| ... | @@ -196,9 +196,6 @@ resolver: std.AutoArrayHashMapUnmanaged(u32, Symbol.Index) = .{}, | ... | @@ -196,9 +196,6 @@ resolver: std.AutoArrayHashMapUnmanaged(u32, Symbol.Index) = .{}, |
| 196 | has_text_reloc: bool = false, | 196 | has_text_reloc: bool = false, |
| 197 | num_ifunc_dynrelocs: usize = 0, | 197 | num_ifunc_dynrelocs: usize = 0, |
| 198 | 198 | ||
| 199 | error_flags: link.File.ErrorFlags = link.File.ErrorFlags{}, | ||
| 200 | misc_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{}, | ||
| 201 | |||
| 202 | /// List of atoms that are owned directly by the linker. | 199 | /// List of atoms that are owned directly by the linker. |
| 203 | atoms: std.ArrayListUnmanaged(Atom) = .{}, | 200 | atoms: std.ArrayListUnmanaged(Atom) = .{}, |
| 204 | 201 | ||
| ... | @@ -477,7 +474,6 @@ pub fn deinit(self: *Elf) void { | ... | @@ -477,7 +474,6 @@ pub fn deinit(self: *Elf) void { |
| 477 | } | 474 | } |
| 478 | self.last_atom_and_free_list_table.deinit(gpa); | 475 | self.last_atom_and_free_list_table.deinit(gpa); |
| 479 | 476 | ||
| 480 | self.misc_errors.deinit(gpa); | ||
| 481 | self.comdat_groups.deinit(gpa); | 477 | self.comdat_groups.deinit(gpa); |
| 482 | self.comdat_groups_owners.deinit(gpa); | 478 | self.comdat_groups_owners.deinit(gpa); |
| 483 | self.comdat_groups_table.deinit(gpa); | 479 | self.comdat_groups_table.deinit(gpa); |
| ... | @@ -1168,7 +1164,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1168,7 +1164,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1168 | } | 1164 | } |
| 1169 | 1165 | ||
| 1170 | // libc dep | 1166 | // libc dep |
| 1171 | self.error_flags.missing_libc = false; | 1167 | self.base.error_flags.missing_libc = false; |
| 1172 | if (self.base.comp.config.link_libc) { | 1168 | if (self.base.comp.config.link_libc) { |
| 1173 | if (self.base.comp.libc_installation) |lc| { | 1169 | if (self.base.comp.libc_installation) |lc| { |
| 1174 | const flags = target_util.libcFullLinkFlags(target); | 1170 | const flags = target_util.libcFullLinkFlags(target); |
| ... | @@ -1219,7 +1215,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1219,7 +1215,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1219 | }); | 1215 | }); |
| 1220 | try system_libs.append(.{ .path = path }); | 1216 | try system_libs.append(.{ .path = path }); |
| 1221 | } else { | 1217 | } else { |
| 1222 | self.error_flags.missing_libc = true; | 1218 | self.base.error_flags.missing_libc = true; |
| 1223 | } | 1219 | } |
| 1224 | } | 1220 | } |
| 1225 | 1221 | ||
| ... | @@ -1257,7 +1253,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1257,7 +1253,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1257 | }; | 1253 | }; |
| 1258 | } | 1254 | } |
| 1259 | 1255 | ||
| 1260 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1256 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1261 | 1257 | ||
| 1262 | // Init all objects | 1258 | // Init all objects |
| 1263 | for (self.objects.items) |index| { | 1259 | for (self.objects.items) |index| { |
| ... | @@ -1267,7 +1263,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1267,7 +1263,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1267 | try self.file(index).?.shared_object.init(self); | 1263 | try self.file(index).?.shared_object.init(self); |
| 1268 | } | 1264 | } |
| 1269 | 1265 | ||
| 1270 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1266 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1271 | 1267 | ||
| 1272 | // Dedup shared objects | 1268 | // Dedup shared objects |
| 1273 | { | 1269 | { |
| ... | @@ -1389,14 +1385,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1389,14 +1385,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1389 | 1385 | ||
| 1390 | if (self.entry_index == null and self.base.isExe()) { | 1386 | if (self.entry_index == null and self.base.isExe()) { |
| 1391 | log.debug("flushing. no_entry_point_found = true", .{}); | 1387 | 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; |
| 1393 | } else { | 1389 | } else { |
| 1394 | log.debug("flushing. no_entry_point_found = false", .{}); | 1390 | 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; |
| 1396 | try self.writeElfHeader(); | 1392 | try self.writeElfHeader(); |
| 1397 | } | 1393 | } |
| 1398 | 1394 | ||
| 1399 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1395 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1400 | } | 1396 | } |
| 1401 | 1397 | ||
| 1402 | pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { | 1398 | pub 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 | ... | @@ -1428,7 +1424,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const |
| 1428 | }; | 1424 | }; |
| 1429 | } | 1425 | } |
| 1430 | 1426 | ||
| 1431 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1427 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1432 | 1428 | ||
| 1433 | // First, we flush relocatable object file generated with our backends. | 1429 | // First, we flush relocatable object file generated with our backends. |
| 1434 | if (self.zigObjectPtr()) |zig_object| { | 1430 | if (self.zigObjectPtr()) |zig_object| { |
| ... | @@ -1540,7 +1536,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const | ... | @@ -1540,7 +1536,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const |
| 1540 | try self.base.file.?.setEndPos(total_size); | 1536 | try self.base.file.?.setEndPos(total_size); |
| 1541 | try self.base.file.?.pwriteAll(buffer.items, 0); | 1537 | try self.base.file.?.pwriteAll(buffer.items, 0); |
| 1542 | 1538 | ||
| 1543 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1539 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1544 | } | 1540 | } |
| 1545 | 1541 | ||
| 1546 | pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { | 1542 | pub 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) | ... | @@ -1571,14 +1567,14 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) |
| 1571 | }; | 1567 | }; |
| 1572 | } | 1568 | } |
| 1573 | 1569 | ||
| 1574 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1570 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1575 | 1571 | ||
| 1576 | // Init all objects | 1572 | // Init all objects |
| 1577 | for (self.objects.items) |index| { | 1573 | for (self.objects.items) |index| { |
| 1578 | try self.file(index).?.object.init(self); | 1574 | try self.file(index).?.object.init(self); |
| 1579 | } | 1575 | } |
| 1580 | 1576 | ||
| 1581 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1577 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1582 | 1578 | ||
| 1583 | // Now, we are ready to resolve the symbols across all input files. | 1579 | // Now, we are ready to resolve the symbols across all input files. |
| 1584 | // We will first resolve the files in the ZigObject, next in the parsed | 1580 | // 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) | ... | @@ -1612,7 +1608,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) |
| 1612 | try self.writeShdrTable(); | 1608 | try self.writeShdrTable(); |
| 1613 | try self.writeElfHeader(); | 1609 | try self.writeElfHeader(); |
| 1614 | 1610 | ||
| 1615 | if (self.misc_errors.items.len > 0) return error.FlushFailure; | 1611 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; |
| 1616 | } | 1612 | } |
| 1617 | 1613 | ||
| 1618 | /// --verbose-link output | 1614 | /// --verbose-link output |
| ... | @@ -2891,7 +2887,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v | ... | @@ -2891,7 +2887,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 2891 | } | 2887 | } |
| 2892 | 2888 | ||
| 2893 | // libc dep | 2889 | // libc dep |
| 2894 | self.error_flags.missing_libc = false; | 2890 | self.base.error_flags.missing_libc = false; |
| 2895 | if (comp.config.link_libc) { | 2891 | if (comp.config.link_libc) { |
| 2896 | if (self.base.comp.libc_installation != null) { | 2892 | if (self.base.comp.libc_installation != null) { |
| 2897 | const needs_grouping = link_mode == .Static; | 2893 | const needs_grouping = link_mode == .Static; |
| ... | @@ -2912,7 +2908,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v | ... | @@ -2912,7 +2908,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 2912 | .Dynamic => "libc.so", | 2908 | .Dynamic => "libc.so", |
| 2913 | })); | 2909 | })); |
| 2914 | } else { | 2910 | } else { |
| 2915 | self.error_flags.missing_libc = true; | 2911 | self.base.error_flags.missing_libc = true; |
| 2916 | } | 2912 | } |
| 2917 | } | 2913 | } |
| 2918 | } | 2914 | } |
| ... | @@ -3135,7 +3131,7 @@ fn writePhdrTable(self: *Elf) !void { | ... | @@ -3135,7 +3131,7 @@ fn writePhdrTable(self: *Elf) !void { |
| 3135 | } | 3131 | } |
| 3136 | 3132 | ||
| 3137 | fn writeElfHeader(self: *Elf) !void { | 3133 | fn 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 |
| 3139 | 3135 | ||
| 3140 | var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined; | 3136 | var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined; |
| 3141 | 3137 | ||
| ... | @@ -6067,8 +6063,9 @@ const ErrorWithNotes = struct { | ... | @@ -6067,8 +6063,9 @@ const ErrorWithNotes = struct { |
| 6067 | comptime format: []const u8, | 6063 | comptime format: []const u8, |
| 6068 | args: anytype, | 6064 | args: anytype, |
| 6069 | ) error{OutOfMemory}!void { | 6065 | ) error{OutOfMemory}!void { |
| 6070 | const gpa = elf_file.base.allocator; | 6066 | const comp = elf_file.base.comp; |
| 6071 | const err_msg = &elf_file.misc_errors.items[err.index]; | 6067 | const gpa = comp.gpa; |
| 6068 | const err_msg = &elf_file.base.misc_errors.items[err.index]; | ||
| 6072 | err_msg.msg = try std.fmt.allocPrint(gpa, format, args); | 6069 | err_msg.msg = try std.fmt.allocPrint(gpa, format, args); |
| 6073 | } | 6070 | } |
| 6074 | 6071 | ||
| ... | @@ -6078,8 +6075,9 @@ const ErrorWithNotes = struct { | ... | @@ -6078,8 +6075,9 @@ const ErrorWithNotes = struct { |
| 6078 | comptime format: []const u8, | 6075 | comptime format: []const u8, |
| 6079 | args: anytype, | 6076 | args: anytype, |
| 6080 | ) error{OutOfMemory}!void { | 6077 | ) error{OutOfMemory}!void { |
| 6081 | const gpa = elf_file.base.allocator; | 6078 | const comp = elf_file.base.comp; |
| 6082 | const err_msg = &elf_file.misc_errors.items[err.index]; | 6079 | const gpa = comp.gpa; |
| 6080 | const err_msg = &elf_file.base.misc_errors.items[err.index]; | ||
| 6083 | assert(err.note_slot < err_msg.notes.len); | 6081 | assert(err.note_slot < err_msg.notes.len); |
| 6084 | err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) }; | 6082 | err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) }; |
| 6085 | err.note_slot += 1; | 6083 | err.note_slot += 1; |
| ... | @@ -6088,14 +6086,14 @@ const ErrorWithNotes = struct { | ... | @@ -6088,14 +6086,14 @@ const ErrorWithNotes = struct { |
| 6088 | 6086 | ||
| 6089 | pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { | 6087 | pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
| 6090 | const gpa = self.base.comp.gpa; | 6088 | const gpa = self.base.comp.gpa; |
| 6091 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 6089 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 6092 | return self.addErrorWithNotesAssumeCapacity(note_count); | 6090 | return self.addErrorWithNotesAssumeCapacity(note_count); |
| 6093 | } | 6091 | } |
| 6094 | 6092 | ||
| 6095 | fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { | 6093 | fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
| 6096 | const gpa = self.base.comp.gpa; | 6094 | const gpa = self.base.comp.gpa; |
| 6097 | const index = self.misc_errors.items.len; | 6095 | const index = self.base.misc_errors.items.len; |
| 6098 | const err = self.misc_errors.addOneAssumeCapacity(); | 6096 | const err = self.base.misc_errors.addOneAssumeCapacity(); |
| 6099 | err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) }; | 6097 | err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) }; |
| 6100 | return .{ .index = index }; | 6098 | return .{ .index = index }; |
| 6101 | } | 6099 | } |
| ... | @@ -6130,7 +6128,7 @@ fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void { | ... | @@ -6130,7 +6128,7 @@ fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void { |
| 6130 | const gpa = self.base.comp.gpa; | 6128 | const gpa = self.base.comp.gpa; |
| 6131 | const max_notes = 4; | 6129 | const max_notes = 4; |
| 6132 | 6130 | ||
| 6133 | try self.misc_errors.ensureUnusedCapacity(gpa, undefs.count()); | 6131 | try self.base.misc_errors.ensureUnusedCapacity(gpa, undefs.count()); |
| 6134 | 6132 | ||
| 6135 | var it = undefs.iterator(); | 6133 | var it = undefs.iterator(); |
| 6136 | while (it.next()) |entry| { | 6134 | while (it.next()) |entry| { |
src/link/Elf/Atom.zig+10-4| ... | @@ -227,7 +227,8 @@ pub fn grow(self: *Atom, elf_file: *Elf) !void { | ... | @@ -227,7 +227,8 @@ pub fn grow(self: *Atom, elf_file: *Elf) !void { |
| 227 | pub fn free(self: *Atom, elf_file: *Elf) void { | 227 | pub fn free(self: *Atom, elf_file: *Elf) void { |
| 228 | log.debug("freeAtom {d} ({s})", .{ self.atom_index, self.name(elf_file) }); | 228 | log.debug("freeAtom {d} ({s})", .{ self.atom_index, self.name(elf_file) }); |
| 229 | 229 | ||
| 230 | const gpa = elf_file.base.allocator; | 230 | const comp = elf_file.base.comp; |
| 231 | const gpa = comp.gpa; | ||
| 231 | const shndx = self.outputShndx().?; | 232 | const shndx = self.outputShndx().?; |
| 232 | const meta = elf_file.last_atom_and_free_list_table.getPtr(shndx).?; | 233 | const meta = elf_file.last_atom_and_free_list_table.getPtr(shndx).?; |
| 233 | const free_list = &meta.free_list; | 234 | const free_list = &meta.free_list; |
| ... | @@ -352,7 +353,8 @@ pub fn markFdesDead(self: Atom, elf_file: *Elf) void { | ... | @@ -352,7 +353,8 @@ pub fn markFdesDead(self: Atom, elf_file: *Elf) void { |
| 352 | } | 353 | } |
| 353 | 354 | ||
| 354 | pub fn addReloc(self: Atom, elf_file: *Elf, reloc: elf.Elf64_Rela) !void { | 355 | pub 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; | ||
| 356 | const file_ptr = self.file(elf_file).?; | 358 | const file_ptr = self.file(elf_file).?; |
| 357 | assert(file_ptr == .zig_object); | 359 | assert(file_ptr == .zig_object); |
| 358 | const zig_object = file_ptr.zig_object; | 360 | const zig_object = file_ptr.zig_object; |
| ... | @@ -747,6 +749,8 @@ fn reportUndefined( | ... | @@ -747,6 +749,8 @@ fn reportUndefined( |
| 747 | rel: elf.Elf64_Rela, | 749 | rel: elf.Elf64_Rela, |
| 748 | undefs: anytype, | 750 | undefs: anytype, |
| 749 | ) !void { | 751 | ) !void { |
| 752 | const comp = elf_file.base.comp; | ||
| 753 | const gpa = comp.gpa; | ||
| 750 | const rel_esym = switch (self.file(elf_file).?) { | 754 | const rel_esym = switch (self.file(elf_file).?) { |
| 751 | .zig_object => |x| x.elfSym(rel.r_sym()).*, | 755 | .zig_object => |x| x.elfSym(rel.r_sym()).*, |
| 752 | .object => |x| x.symtab.items[rel.r_sym()], | 756 | .object => |x| x.symtab.items[rel.r_sym()], |
| ... | @@ -761,7 +765,7 @@ fn reportUndefined( | ... | @@ -761,7 +765,7 @@ fn reportUndefined( |
| 761 | { | 765 | { |
| 762 | const gop = try undefs.getOrPut(sym_index); | 766 | const gop = try undefs.getOrPut(sym_index); |
| 763 | if (!gop.found_existing) { | 767 | 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); |
| 765 | } | 769 | } |
| 766 | try gop.value_ptr.append(self.atom_index); | 770 | try gop.value_ptr.append(self.atom_index); |
| 767 | } | 771 | } |
| ... | @@ -957,6 +961,8 @@ fn resolveDynAbsReloc( | ... | @@ -957,6 +961,8 @@ fn resolveDynAbsReloc( |
| 957 | elf_file: *Elf, | 961 | elf_file: *Elf, |
| 958 | writer: anytype, | 962 | writer: anytype, |
| 959 | ) !void { | 963 | ) !void { |
| 964 | const comp = elf_file.base.comp; | ||
| 965 | const gpa = comp.gpa; | ||
| 960 | const P = self.value + rel.r_offset; | 966 | const P = self.value + rel.r_offset; |
| 961 | const A = rel.r_addend; | 967 | const A = rel.r_addend; |
| 962 | const S = @as(i64, @intCast(target.address(.{}, elf_file))); | 968 | const S = @as(i64, @intCast(target.address(.{}, elf_file))); |
| ... | @@ -967,7 +973,7 @@ fn resolveDynAbsReloc( | ... | @@ -967,7 +973,7 @@ fn resolveDynAbsReloc( |
| 967 | .shared_object => unreachable, | 973 | .shared_object => unreachable, |
| 968 | inline else => |x| x.num_dynrelocs, | 974 | inline else => |x| x.num_dynrelocs, |
| 969 | }; | 975 | }; |
| 970 | try elf_file.rela_dyn.ensureUnusedCapacity(elf_file.base.allocator, num_dynrelocs); | 976 | try elf_file.rela_dyn.ensureUnusedCapacity(gpa, num_dynrelocs); |
| 971 | 977 | ||
| 972 | switch (action) { | 978 | switch (action) { |
| 973 | .@"error", | 979 | .@"error", |
src/link/MachO.zig+17-25| ... | @@ -67,9 +67,6 @@ tlv_ptr_table: TableSection(SymbolWithLoc) = .{}, | ... | @@ -67,9 +67,6 @@ tlv_ptr_table: TableSection(SymbolWithLoc) = .{}, |
| 67 | thunk_table: std.AutoHashMapUnmanaged(Atom.Index, thunks.Thunk.Index) = .{}, | 67 | thunk_table: std.AutoHashMapUnmanaged(Atom.Index, thunks.Thunk.Index) = .{}, |
| 68 | thunks: std.ArrayListUnmanaged(thunks.Thunk) = .{}, | 68 | thunks: std.ArrayListUnmanaged(thunks.Thunk) = .{}, |
| 69 | 69 | ||
| 70 | error_flags: File.ErrorFlags = File.ErrorFlags{}, | ||
| 71 | misc_errors: std.ArrayListUnmanaged(File.ErrorMsg) = .{}, | ||
| 72 | |||
| 73 | segment_table_dirty: bool = false, | 70 | segment_table_dirty: bool = false, |
| 74 | got_table_count_dirty: bool = false, | 71 | got_table_count_dirty: bool = false, |
| 75 | got_table_contents_dirty: bool = false, | 72 | got_table_contents_dirty: bool = false, |
| ... | @@ -337,8 +334,8 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li | ... | @@ -337,8 +334,8 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li |
| 337 | if (build_options.have_llvm) { | 334 | if (build_options.have_llvm) { |
| 338 | return self.base.linkAsArchive(comp, prog_node); | 335 | return self.base.linkAsArchive(comp, prog_node); |
| 339 | } else { | 336 | } else { |
| 340 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 337 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 341 | self.misc_errors.appendAssumeCapacity(.{ | 338 | self.base.misc_errors.appendAssumeCapacity(.{ |
| 342 | .msg = try gpa.dupe(u8, "TODO: non-LLVM archiver for MachO object files"), | 339 | .msg = try gpa.dupe(u8, "TODO: non-LLVM archiver for MachO object files"), |
| 343 | }); | 340 | }); |
| 344 | return error.FlushFailure; | 341 | return error.FlushFailure; |
| ... | @@ -492,7 +489,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No | ... | @@ -492,7 +489,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 492 | try self.resolveSymbols(); | 489 | try self.resolveSymbols(); |
| 493 | 490 | ||
| 494 | if (self.getEntryPoint() == null) { | 491 | if (self.getEntryPoint() == null) { |
| 495 | self.error_flags.no_entry_point_found = true; | 492 | self.base.error_flags.no_entry_point_found = true; |
| 496 | } | 493 | } |
| 497 | if (self.unresolved.count() > 0) { | 494 | if (self.unresolved.count() > 0) { |
| 498 | try self.reportUndefined(); | 495 | try self.reportUndefined(); |
| ... | @@ -2097,11 +2094,6 @@ pub fn deinit(self: *MachO) void { | ... | @@ -2097,11 +2094,6 @@ pub fn deinit(self: *MachO) void { |
| 2097 | bindings.deinit(gpa); | 2094 | bindings.deinit(gpa); |
| 2098 | } | 2095 | } |
| 2099 | self.bindings.deinit(gpa); | 2096 | self.bindings.deinit(gpa); |
| 2100 | |||
| 2101 | for (self.misc_errors.items) |*err| { | ||
| 2102 | err.deinit(gpa); | ||
| 2103 | } | ||
| 2104 | self.misc_errors.deinit(gpa); | ||
| 2105 | } | 2097 | } |
| 2106 | 2098 | ||
| 2107 | fn freeAtom(self: *MachO, atom_index: Atom.Index) void { | 2099 | fn freeAtom(self: *MachO, atom_index: Atom.Index) void { |
| ... | @@ -5341,13 +5333,13 @@ fn reportMissingLibraryError( | ... | @@ -5341,13 +5333,13 @@ fn reportMissingLibraryError( |
| 5341 | args: anytype, | 5333 | args: anytype, |
| 5342 | ) error{OutOfMemory}!void { | 5334 | ) error{OutOfMemory}!void { |
| 5343 | const gpa = self.base.comp.gpa; | 5335 | const gpa = self.base.comp.gpa; |
| 5344 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5336 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5345 | const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); | 5337 | const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); |
| 5346 | errdefer gpa.free(notes); | 5338 | errdefer gpa.free(notes); |
| 5347 | for (checked_paths, notes) |path, *note| { | 5339 | for (checked_paths, notes) |path, *note| { |
| 5348 | note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; | 5340 | note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; |
| 5349 | } | 5341 | } |
| 5350 | self.misc_errors.appendAssumeCapacity(.{ | 5342 | self.base.misc_errors.appendAssumeCapacity(.{ |
| 5351 | .msg = try std.fmt.allocPrint(gpa, format, args), | 5343 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5352 | .notes = notes, | 5344 | .notes = notes, |
| 5353 | }); | 5345 | }); |
| ... | @@ -5361,14 +5353,14 @@ fn reportDependencyError( | ... | @@ -5361,14 +5353,14 @@ fn reportDependencyError( |
| 5361 | args: anytype, | 5353 | args: anytype, |
| 5362 | ) error{OutOfMemory}!void { | 5354 | ) error{OutOfMemory}!void { |
| 5363 | const gpa = self.base.comp.gpa; | 5355 | const gpa = self.base.comp.gpa; |
| 5364 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5356 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5365 | var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); | 5357 | var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); |
| 5366 | defer notes.deinit(); | 5358 | defer notes.deinit(); |
| 5367 | if (path) |p| { | 5359 | if (path) |p| { |
| 5368 | notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{p}) }); | 5360 | notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{p}) }); |
| 5369 | } | 5361 | } |
| 5370 | notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "a dependency of {s}", .{parent}) }); | 5362 | notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "a dependency of {s}", .{parent}) }); |
| 5371 | self.misc_errors.appendAssumeCapacity(.{ | 5363 | self.base.misc_errors.appendAssumeCapacity(.{ |
| 5372 | .msg = try std.fmt.allocPrint(gpa, format, args), | 5364 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5373 | .notes = try notes.toOwnedSlice(), | 5365 | .notes = try notes.toOwnedSlice(), |
| 5374 | }); | 5366 | }); |
| ... | @@ -5381,11 +5373,11 @@ pub fn reportParseError( | ... | @@ -5381,11 +5373,11 @@ pub fn reportParseError( |
| 5381 | args: anytype, | 5373 | args: anytype, |
| 5382 | ) error{OutOfMemory}!void { | 5374 | ) error{OutOfMemory}!void { |
| 5383 | const gpa = self.base.comp.gpa; | 5375 | const gpa = self.base.comp.gpa; |
| 5384 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5376 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5385 | var notes = try gpa.alloc(File.ErrorMsg, 1); | 5377 | var notes = try gpa.alloc(File.ErrorMsg, 1); |
| 5386 | errdefer gpa.free(notes); | 5378 | errdefer gpa.free(notes); |
| 5387 | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) }; | 5379 | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) }; |
| 5388 | self.misc_errors.appendAssumeCapacity(.{ | 5380 | self.base.misc_errors.appendAssumeCapacity(.{ |
| 5389 | .msg = try std.fmt.allocPrint(gpa, format, args), | 5381 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5390 | .notes = notes, | 5382 | .notes = notes, |
| 5391 | }); | 5383 | }); |
| ... | @@ -5398,11 +5390,11 @@ pub fn reportUnresolvedBoundarySymbol( | ... | @@ -5398,11 +5390,11 @@ pub fn reportUnresolvedBoundarySymbol( |
| 5398 | args: anytype, | 5390 | args: anytype, |
| 5399 | ) error{OutOfMemory}!void { | 5391 | ) error{OutOfMemory}!void { |
| 5400 | const gpa = self.base.comp.gpa; | 5392 | const gpa = self.base.comp.gpa; |
| 5401 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5393 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5402 | var notes = try gpa.alloc(File.ErrorMsg, 1); | 5394 | var notes = try gpa.alloc(File.ErrorMsg, 1); |
| 5403 | errdefer gpa.free(notes); | 5395 | errdefer gpa.free(notes); |
| 5404 | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while resolving {s}", .{sym_name}) }; | 5396 | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while resolving {s}", .{sym_name}) }; |
| 5405 | self.misc_errors.appendAssumeCapacity(.{ | 5397 | self.base.misc_errors.appendAssumeCapacity(.{ |
| 5406 | .msg = try std.fmt.allocPrint(gpa, format, args), | 5398 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5407 | .notes = notes, | 5399 | .notes = notes, |
| 5408 | }); | 5400 | }); |
| ... | @@ -5411,7 +5403,7 @@ pub fn reportUnresolvedBoundarySymbol( | ... | @@ -5411,7 +5403,7 @@ pub fn reportUnresolvedBoundarySymbol( |
| 5411 | pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { | 5403 | pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { |
| 5412 | const gpa = self.base.comp.gpa; | 5404 | const gpa = self.base.comp.gpa; |
| 5413 | const count = self.unresolved.count(); | 5405 | const count = self.unresolved.count(); |
| 5414 | try self.misc_errors.ensureUnusedCapacity(gpa, count); | 5406 | try self.base.misc_errors.ensureUnusedCapacity(gpa, count); |
| 5415 | 5407 | ||
| 5416 | for (self.unresolved.keys()) |global_index| { | 5408 | for (self.unresolved.keys()) |global_index| { |
| 5417 | const global = self.globals.items[global_index]; | 5409 | const global = self.globals.items[global_index]; |
| ... | @@ -5432,7 +5424,7 @@ pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { | ... | @@ -5432,7 +5424,7 @@ pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { |
| 5432 | }; | 5424 | }; |
| 5433 | err_msg.notes = try notes.toOwnedSlice(); | 5425 | err_msg.notes = try notes.toOwnedSlice(); |
| 5434 | 5426 | ||
| 5435 | self.misc_errors.appendAssumeCapacity(err_msg); | 5427 | self.base.misc_errors.appendAssumeCapacity(err_msg); |
| 5436 | } | 5428 | } |
| 5437 | } | 5429 | } |
| 5438 | 5430 | ||
| ... | @@ -5442,7 +5434,7 @@ fn reportSymbolCollision( | ... | @@ -5442,7 +5434,7 @@ fn reportSymbolCollision( |
| 5442 | other: SymbolWithLoc, | 5434 | other: SymbolWithLoc, |
| 5443 | ) error{OutOfMemory}!void { | 5435 | ) error{OutOfMemory}!void { |
| 5444 | const gpa = self.base.comp.gpa; | 5436 | const gpa = self.base.comp.gpa; |
| 5445 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5437 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5446 | 5438 | ||
| 5447 | var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); | 5439 | var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); |
| 5448 | defer notes.deinit(); | 5440 | defer notes.deinit(); |
| ... | @@ -5465,12 +5457,12 @@ fn reportSymbolCollision( | ... | @@ -5465,12 +5457,12 @@ fn reportSymbolCollision( |
| 5465 | }) }; | 5457 | }) }; |
| 5466 | err_msg.notes = try notes.toOwnedSlice(); | 5458 | err_msg.notes = try notes.toOwnedSlice(); |
| 5467 | 5459 | ||
| 5468 | self.misc_errors.appendAssumeCapacity(err_msg); | 5460 | self.base.misc_errors.appendAssumeCapacity(err_msg); |
| 5469 | } | 5461 | } |
| 5470 | 5462 | ||
| 5471 | fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{OutOfMemory}!void { | 5463 | fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{OutOfMemory}!void { |
| 5472 | const gpa = self.base.comp.gpa; | 5464 | const gpa = self.base.comp.gpa; |
| 5473 | try self.misc_errors.ensureUnusedCapacity(gpa, 1); | 5465 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 5474 | 5466 | ||
| 5475 | const notes = try gpa.alloc(File.ErrorMsg, 1); | 5467 | const notes = try gpa.alloc(File.ErrorMsg, 1); |
| 5476 | errdefer gpa.free(notes); | 5468 | errdefer gpa.free(notes); |
| ... | @@ -5488,7 +5480,7 @@ fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{Ou | ... | @@ -5488,7 +5480,7 @@ fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{Ou |
| 5488 | else | 5480 | else |
| 5489 | unreachable; | 5481 | unreachable; |
| 5490 | 5482 | ||
| 5491 | self.misc_errors.appendAssumeCapacity(.{ | 5483 | self.base.misc_errors.appendAssumeCapacity(.{ |
| 5492 | .msg = try std.fmt.allocPrint(gpa, "unhandled symbol type: '{s}' has type {s}", .{ | 5484 | .msg = try std.fmt.allocPrint(gpa, "unhandled symbol type: '{s}' has type {s}", .{ |
| 5493 | self.getSymbolName(sym_with_loc), | 5485 | self.getSymbolName(sym_with_loc), |
| 5494 | sym_type, | 5486 | sym_type, |
src/link/MachO/Atom.zig+8-4| ... | @@ -253,7 +253,8 @@ pub fn addRelocation(macho_file: *MachO, atom_index: Index, reloc: Relocation) ! | ... | @@ -253,7 +253,8 @@ pub fn addRelocation(macho_file: *MachO, atom_index: Index, reloc: Relocation) ! |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []const Relocation) !void { | 255 | pub 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; | ||
| 257 | const gop = try macho_file.relocs.getOrPut(gpa, atom_index); | 258 | const gop = try macho_file.relocs.getOrPut(gpa, atom_index); |
| 258 | if (!gop.found_existing) { | 259 | if (!gop.found_existing) { |
| 259 | gop.value_ptr.* = .{}; | 260 | gop.value_ptr.* = .{}; |
| ... | @@ -269,7 +270,8 @@ pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []const Rel | ... | @@ -269,7 +270,8 @@ pub fn addRelocations(macho_file: *MachO, atom_index: Index, relocs: []const Rel |
| 269 | } | 270 | } |
| 270 | 271 | ||
| 271 | pub fn addRebase(macho_file: *MachO, atom_index: Index, offset: u32) !void { | 272 | pub 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; | ||
| 273 | const atom = macho_file.getAtom(atom_index); | 275 | const atom = macho_file.getAtom(atom_index); |
| 274 | log.debug(" (adding rebase at offset 0x{x} in %{?d})", .{ offset, atom.getSymbolIndex() }); | 276 | log.debug(" (adding rebase at offset 0x{x} in %{?d})", .{ offset, atom.getSymbolIndex() }); |
| 275 | const gop = try macho_file.rebases.getOrPut(gpa, atom_index); | 277 | 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 { | ... | @@ -280,7 +282,8 @@ pub fn addRebase(macho_file: *MachO, atom_index: Index, offset: u32) !void { |
| 280 | } | 282 | } |
| 281 | 283 | ||
| 282 | pub fn addBinding(macho_file: *MachO, atom_index: Index, binding: Binding) !void { | 284 | pub 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; | ||
| 284 | const atom = macho_file.getAtom(atom_index); | 287 | const atom = macho_file.getAtom(atom_index); |
| 285 | log.debug(" (adding binding to symbol {s} at offset 0x{x} in %{?d})", .{ | 288 | log.debug(" (adding binding to symbol {s} at offset 0x{x} in %{?d})", .{ |
| 286 | macho_file.getSymbolName(binding.target), | 289 | macho_file.getSymbolName(binding.target), |
| ... | @@ -307,7 +310,8 @@ pub fn resolveRelocations( | ... | @@ -307,7 +310,8 @@ pub fn resolveRelocations( |
| 307 | } | 310 | } |
| 308 | 311 | ||
| 309 | pub fn freeRelocations(macho_file: *MachO, atom_index: Index) void { | 312 | pub 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; | ||
| 311 | var removed_relocs = macho_file.relocs.fetchOrderedRemove(atom_index); | 315 | var removed_relocs = macho_file.relocs.fetchOrderedRemove(atom_index); |
| 312 | if (removed_relocs) |*relocs| relocs.value.deinit(gpa); | 316 | if (removed_relocs) |*relocs| relocs.value.deinit(gpa); |
| 313 | var removed_rebases = macho_file.rebases.fetchOrderedRemove(atom_index); | 317 | var removed_rebases = macho_file.rebases.fetchOrderedRemove(atom_index); |
src/link/Plan9.zig-1| ... | @@ -28,7 +28,6 @@ pub const base_tag = .plan9; | ... | @@ -28,7 +28,6 @@ pub const base_tag = .plan9; |
| 28 | 28 | ||
| 29 | base: link.File, | 29 | base: link.File, |
| 30 | sixtyfour_bit: bool, | 30 | sixtyfour_bit: bool, |
| 31 | error_flags: File.ErrorFlags = File.ErrorFlags{}, | ||
| 32 | bases: Bases, | 31 | bases: Bases, |
| 33 | 32 | ||
| 34 | /// A symbol's value is just casted down when compiling | 33 | /// A symbol's value is just casted down when compiling |