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