| author | |
| committer | |
| log | 6509c492ad7908c515a0c00751e1348b26dda4e7 |
| tree | 4424e28452be76d1ad081d6284e1f625955efbee |
| parent | 791e83c22396e029e0f2bc19b75fd86f8cd7851f |
So that they can be referenced by getAllErrorsAlloc(). Fixes missing
compile errors.5 files changed, 130 insertions(+), 125 deletions(-)
src/Compilation.zig+68-65| ... | ... | @@ -28,7 +28,9 @@ const libcxx = @import("libcxx.zig"); |
| 28 | 28 | const wasi_libc = @import("wasi_libc.zig"); |
| 29 | 29 | const fatal = @import("main.zig").fatal; |
| 30 | 30 | const clangMain = @import("main.zig").clangMain; |
| 31 | const Module = @import("Module.zig"); | |
| 31 | const Zcu = @import("Module.zig"); | |
| 32 | /// Deprecated; use `Zcu`. | |
| 33 | const Module = Zcu; | |
| 32 | 34 | const InternPool = @import("InternPool.zig"); |
| 33 | 35 | const Cache = std.Build.Cache; |
| 34 | 36 | const c_codegen = @import("codegen/c.zig"); |
| ... | ... | @@ -97,6 +99,7 @@ win32_resource_table: if (build_options.only_core_functionality) void else std.A |
| 97 | 99 | if (build_options.only_core_functionality) {} else .{}, |
| 98 | 100 | |
| 99 | 101 | link_error_flags: link.File.ErrorFlags = .{}, |
| 102 | link_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{}, | |
| 100 | 103 | lld_errors: std.ArrayListUnmanaged(LldError) = .{}, |
| 101 | 104 | |
| 102 | 105 | work_queue: std.fifo.LinearFifo(Job, .Dynamic), |
| ... | ... | @@ -1874,87 +1877,90 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation { |
| 1874 | 1877 | return comp; |
| 1875 | 1878 | } |
| 1876 | 1879 | |
| 1877 | pub fn destroy(self: *Compilation) void { | |
| 1878 | if (self.bin_file) |lf| lf.destroy(); | |
| 1879 | if (self.module) |zcu| zcu.deinit(); | |
| 1880 | self.cache_use.deinit(); | |
| 1881 | self.work_queue.deinit(); | |
| 1882 | self.anon_work_queue.deinit(); | |
| 1883 | self.c_object_work_queue.deinit(); | |
| 1880 | pub fn destroy(comp: *Compilation) void { | |
| 1881 | if (comp.bin_file) |lf| lf.destroy(); | |
| 1882 | if (comp.module) |zcu| zcu.deinit(); | |
| 1883 | comp.cache_use.deinit(); | |
| 1884 | comp.work_queue.deinit(); | |
| 1885 | comp.anon_work_queue.deinit(); | |
| 1886 | comp.c_object_work_queue.deinit(); | |
| 1884 | 1887 | if (!build_options.only_core_functionality) { |
| 1885 | self.win32_resource_work_queue.deinit(); | |
| 1888 | comp.win32_resource_work_queue.deinit(); | |
| 1886 | 1889 | } |
| 1887 | self.astgen_work_queue.deinit(); | |
| 1888 | self.embed_file_work_queue.deinit(); | |
| 1890 | comp.astgen_work_queue.deinit(); | |
| 1891 | comp.embed_file_work_queue.deinit(); | |
| 1889 | 1892 | |
| 1890 | const gpa = self.gpa; | |
| 1891 | self.system_libs.deinit(gpa); | |
| 1893 | const gpa = comp.gpa; | |
| 1894 | comp.system_libs.deinit(gpa); | |
| 1892 | 1895 | |
| 1893 | 1896 | { |
| 1894 | var it = self.crt_files.iterator(); | |
| 1897 | var it = comp.crt_files.iterator(); | |
| 1895 | 1898 | while (it.next()) |entry| { |
| 1896 | 1899 | gpa.free(entry.key_ptr.*); |
| 1897 | 1900 | entry.value_ptr.deinit(gpa); |
| 1898 | 1901 | } |
| 1899 | self.crt_files.deinit(gpa); | |
| 1902 | comp.crt_files.deinit(gpa); | |
| 1900 | 1903 | } |
| 1901 | 1904 | |
| 1902 | if (self.libunwind_static_lib) |*crt_file| { | |
| 1905 | if (comp.libunwind_static_lib) |*crt_file| { | |
| 1903 | 1906 | crt_file.deinit(gpa); |
| 1904 | 1907 | } |
| 1905 | if (self.libcxx_static_lib) |*crt_file| { | |
| 1908 | if (comp.libcxx_static_lib) |*crt_file| { | |
| 1906 | 1909 | crt_file.deinit(gpa); |
| 1907 | 1910 | } |
| 1908 | if (self.libcxxabi_static_lib) |*crt_file| { | |
| 1911 | if (comp.libcxxabi_static_lib) |*crt_file| { | |
| 1909 | 1912 | crt_file.deinit(gpa); |
| 1910 | 1913 | } |
| 1911 | if (self.compiler_rt_lib) |*crt_file| { | |
| 1914 | if (comp.compiler_rt_lib) |*crt_file| { | |
| 1912 | 1915 | crt_file.deinit(gpa); |
| 1913 | 1916 | } |
| 1914 | if (self.compiler_rt_obj) |*crt_file| { | |
| 1917 | if (comp.compiler_rt_obj) |*crt_file| { | |
| 1915 | 1918 | crt_file.deinit(gpa); |
| 1916 | 1919 | } |
| 1917 | if (self.libc_static_lib) |*crt_file| { | |
| 1920 | if (comp.libc_static_lib) |*crt_file| { | |
| 1918 | 1921 | crt_file.deinit(gpa); |
| 1919 | 1922 | } |
| 1920 | 1923 | |
| 1921 | if (self.glibc_so_files) |*glibc_file| { | |
| 1924 | if (comp.glibc_so_files) |*glibc_file| { | |
| 1922 | 1925 | glibc_file.deinit(gpa); |
| 1923 | 1926 | } |
| 1924 | 1927 | |
| 1925 | for (self.c_object_table.keys()) |key| { | |
| 1928 | for (comp.c_object_table.keys()) |key| { | |
| 1926 | 1929 | key.destroy(gpa); |
| 1927 | 1930 | } |
| 1928 | self.c_object_table.deinit(gpa); | |
| 1931 | comp.c_object_table.deinit(gpa); | |
| 1929 | 1932 | |
| 1930 | for (self.failed_c_objects.values()) |bundle| { | |
| 1933 | for (comp.failed_c_objects.values()) |bundle| { | |
| 1931 | 1934 | bundle.destroy(gpa); |
| 1932 | 1935 | } |
| 1933 | self.failed_c_objects.deinit(gpa); | |
| 1936 | comp.failed_c_objects.deinit(gpa); | |
| 1934 | 1937 | |
| 1935 | 1938 | if (!build_options.only_core_functionality) { |
| 1936 | for (self.win32_resource_table.keys()) |key| { | |
| 1939 | for (comp.win32_resource_table.keys()) |key| { | |
| 1937 | 1940 | key.destroy(gpa); |
| 1938 | 1941 | } |
| 1939 | self.win32_resource_table.deinit(gpa); | |
| 1942 | comp.win32_resource_table.deinit(gpa); | |
| 1940 | 1943 | |
| 1941 | for (self.failed_win32_resources.values()) |*value| { | |
| 1944 | for (comp.failed_win32_resources.values()) |*value| { | |
| 1942 | 1945 | value.deinit(gpa); |
| 1943 | 1946 | } |
| 1944 | self.failed_win32_resources.deinit(gpa); | |
| 1947 | comp.failed_win32_resources.deinit(gpa); | |
| 1945 | 1948 | } |
| 1946 | 1949 | |
| 1947 | for (self.lld_errors.items) |*lld_error| { | |
| 1950 | for (comp.link_errors.items) |*item| item.deinit(gpa); | |
| 1951 | comp.link_errors.deinit(gpa); | |
| 1952 | ||
| 1953 | for (comp.lld_errors.items) |*lld_error| { | |
| 1948 | 1954 | lld_error.deinit(gpa); |
| 1949 | 1955 | } |
| 1950 | self.lld_errors.deinit(gpa); | |
| 1956 | comp.lld_errors.deinit(gpa); | |
| 1951 | 1957 | |
| 1952 | self.clearMiscFailures(); | |
| 1958 | comp.clearMiscFailures(); | |
| 1953 | 1959 | |
| 1954 | self.cache_parent.manifest_dir.close(); | |
| 1960 | comp.cache_parent.manifest_dir.close(); | |
| 1955 | 1961 | |
| 1956 | // This destroys `self`. | |
| 1957 | var arena_instance = self.arena; | |
| 1962 | // This destroys `comp`. | |
| 1963 | var arena_instance = comp.arena; | |
| 1958 | 1964 | arena_instance.deinit(); |
| 1959 | 1965 | } |
| 1960 | 1966 | |
| ... | ... | @@ -2214,7 +2220,6 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2214 | 2220 | error.LLDReportedFailure => {}, // error reported via lockAndParseLldStderr |
| 2215 | 2221 | else => |e| return e, |
| 2216 | 2222 | }; |
| 2217 | comp.link_error_flags = lf.error_flags; | |
| 2218 | 2223 | } |
| 2219 | 2224 | |
| 2220 | 2225 | if (comp.module) |module| { |
| ... | ... | @@ -2745,23 +2750,23 @@ fn addBuf(bufs_list: []std.os.iovec_const, bufs_len: *usize, buf: []const u8) vo |
| 2745 | 2750 | } |
| 2746 | 2751 | |
| 2747 | 2752 | /// This function is temporally single-threaded. |
| 2748 | pub fn totalErrorCount(self: *Compilation) u32 { | |
| 2753 | pub fn totalErrorCount(comp: *Compilation) u32 { | |
| 2749 | 2754 | var total: usize = |
| 2750 | self.misc_failures.count() + | |
| 2751 | @intFromBool(self.alloc_failure_occurred) + | |
| 2752 | self.lld_errors.items.len; | |
| 2755 | comp.misc_failures.count() + | |
| 2756 | @intFromBool(comp.alloc_failure_occurred) + | |
| 2757 | comp.lld_errors.items.len; | |
| 2753 | 2758 | |
| 2754 | for (self.failed_c_objects.values()) |bundle| { | |
| 2759 | for (comp.failed_c_objects.values()) |bundle| { | |
| 2755 | 2760 | total += bundle.diags.len; |
| 2756 | 2761 | } |
| 2757 | 2762 | |
| 2758 | 2763 | if (!build_options.only_core_functionality) { |
| 2759 | for (self.failed_win32_resources.values()) |errs| { | |
| 2764 | for (comp.failed_win32_resources.values()) |errs| { | |
| 2760 | 2765 | total += errs.errorMessageCount(); |
| 2761 | 2766 | } |
| 2762 | 2767 | } |
| 2763 | 2768 | |
| 2764 | if (self.module) |module| { | |
| 2769 | if (comp.module) |module| { | |
| 2765 | 2770 | total += module.failed_exports.count(); |
| 2766 | 2771 | total += module.failed_embed_files.count(); |
| 2767 | 2772 | |
| ... | ... | @@ -2804,17 +2809,15 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 2804 | 2809 | |
| 2805 | 2810 | // The "no entry point found" error only counts if there are no semantic analysis errors. |
| 2806 | 2811 | if (total == 0) { |
| 2807 | total += @intFromBool(self.link_error_flags.no_entry_point_found); | |
| 2812 | total += @intFromBool(comp.link_error_flags.no_entry_point_found); | |
| 2808 | 2813 | } |
| 2809 | total += @intFromBool(self.link_error_flags.missing_libc); | |
| 2814 | total += @intFromBool(comp.link_error_flags.missing_libc); | |
| 2810 | 2815 | |
| 2811 | if (self.bin_file) |lf| { | |
| 2812 | total += lf.misc_errors.items.len; | |
| 2813 | } | |
| 2816 | total += comp.link_errors.items.len; | |
| 2814 | 2817 | |
| 2815 | 2818 | // Compile log errors only count if there are no other errors. |
| 2816 | 2819 | if (total == 0) { |
| 2817 | if (self.module) |module| { | |
| 2820 | if (comp.module) |module| { | |
| 2818 | 2821 | total += @intFromBool(module.compile_log_decls.count() != 0); |
| 2819 | 2822 | } |
| 2820 | 2823 | } |
| ... | ... | @@ -2823,24 +2826,24 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 2823 | 2826 | } |
| 2824 | 2827 | |
| 2825 | 2828 | /// This function is temporally single-threaded. |
| 2826 | pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { | |
| 2827 | const gpa = self.gpa; | |
| 2829 | pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | |
| 2830 | const gpa = comp.gpa; | |
| 2828 | 2831 | |
| 2829 | 2832 | var bundle: ErrorBundle.Wip = undefined; |
| 2830 | 2833 | try bundle.init(gpa); |
| 2831 | 2834 | defer bundle.deinit(); |
| 2832 | 2835 | |
| 2833 | for (self.failed_c_objects.values()) |diag_bundle| { | |
| 2836 | for (comp.failed_c_objects.values()) |diag_bundle| { | |
| 2834 | 2837 | try diag_bundle.addToErrorBundle(&bundle); |
| 2835 | 2838 | } |
| 2836 | 2839 | |
| 2837 | 2840 | if (!build_options.only_core_functionality) { |
| 2838 | for (self.failed_win32_resources.values()) |error_bundle| { | |
| 2841 | for (comp.failed_win32_resources.values()) |error_bundle| { | |
| 2839 | 2842 | try bundle.addBundleAsRoots(error_bundle); |
| 2840 | 2843 | } |
| 2841 | 2844 | } |
| 2842 | 2845 | |
| 2843 | for (self.lld_errors.items) |lld_error| { | |
| 2846 | for (comp.lld_errors.items) |lld_error| { | |
| 2844 | 2847 | const notes_len = @as(u32, @intCast(lld_error.context_lines.len)); |
| 2845 | 2848 | |
| 2846 | 2849 | try bundle.addRootErrorMessage(.{ |
| ... | ... | @@ -2854,19 +2857,19 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2854 | 2857 | })); |
| 2855 | 2858 | } |
| 2856 | 2859 | } |
| 2857 | for (self.misc_failures.values()) |*value| { | |
| 2860 | for (comp.misc_failures.values()) |*value| { | |
| 2858 | 2861 | try bundle.addRootErrorMessage(.{ |
| 2859 | 2862 | .msg = try bundle.addString(value.msg), |
| 2860 | 2863 | .notes_len = if (value.children) |b| b.errorMessageCount() else 0, |
| 2861 | 2864 | }); |
| 2862 | 2865 | if (value.children) |b| try bundle.addBundleAsNotes(b); |
| 2863 | 2866 | } |
| 2864 | if (self.alloc_failure_occurred) { | |
| 2867 | if (comp.alloc_failure_occurred) { | |
| 2865 | 2868 | try bundle.addRootErrorMessage(.{ |
| 2866 | 2869 | .msg = try bundle.addString("memory allocation failure"), |
| 2867 | 2870 | }); |
| 2868 | 2871 | } |
| 2869 | if (self.module) |module| { | |
| 2872 | if (comp.module) |module| { | |
| 2870 | 2873 | for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| { |
| 2871 | 2874 | if (error_msg) |msg| { |
| 2872 | 2875 | try addModuleErrorMsg(module, &bundle, msg.*); |
| ... | ... | @@ -2938,14 +2941,14 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2938 | 2941 | } |
| 2939 | 2942 | |
| 2940 | 2943 | if (bundle.root_list.items.len == 0) { |
| 2941 | if (self.link_error_flags.no_entry_point_found) { | |
| 2944 | if (comp.link_error_flags.no_entry_point_found) { | |
| 2942 | 2945 | try bundle.addRootErrorMessage(.{ |
| 2943 | 2946 | .msg = try bundle.addString("no entry point found"), |
| 2944 | 2947 | }); |
| 2945 | 2948 | } |
| 2946 | 2949 | } |
| 2947 | 2950 | |
| 2948 | if (self.link_error_flags.missing_libc) { | |
| 2951 | if (comp.link_error_flags.missing_libc) { | |
| 2949 | 2952 | try bundle.addRootErrorMessage(.{ |
| 2950 | 2953 | .msg = try bundle.addString("libc not available"), |
| 2951 | 2954 | .notes_len = 2, |
| ... | ... | @@ -2959,7 +2962,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2959 | 2962 | })); |
| 2960 | 2963 | } |
| 2961 | 2964 | |
| 2962 | if (self.bin_file) |lf| for (lf.misc_errors.items) |link_err| { | |
| 2965 | for (comp.link_errors.items) |link_err| { | |
| 2963 | 2966 | try bundle.addRootErrorMessage(.{ |
| 2964 | 2967 | .msg = try bundle.addString(link_err.msg), |
| 2965 | 2968 | .notes_len = @intCast(link_err.notes.len), |
| ... | ... | @@ -2970,9 +2973,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2970 | 2973 | .msg = try bundle.addString(note.msg), |
| 2971 | 2974 | })); |
| 2972 | 2975 | } |
| 2973 | }; | |
| 2976 | } | |
| 2974 | 2977 | |
| 2975 | if (self.module) |module| { | |
| 2978 | if (comp.module) |module| { | |
| 2976 | 2979 | if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) { |
| 2977 | 2980 | const keys = module.compile_log_decls.keys(); |
| 2978 | 2981 | const values = module.compile_log_decls.values(); |
| ... | ... | @@ -2998,9 +3001,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2998 | 3001 | } |
| 2999 | 3002 | } |
| 3000 | 3003 | |
| 3001 | assert(self.totalErrorCount() == bundle.root_list.items.len); | |
| 3004 | assert(comp.totalErrorCount() == bundle.root_list.items.len); | |
| 3002 | 3005 | |
| 3003 | const compile_log_text = if (self.module) |m| m.compile_log_text.items else ""; | |
| 3006 | const compile_log_text = if (comp.module) |m| m.compile_log_text.items else ""; | |
| 3004 | 3007 | return bundle.toOwnedBundle(compile_log_text); |
| 3005 | 3008 | } |
| 3006 | 3009 |
src/link.zig-8| ... | ... | @@ -67,9 +67,6 @@ pub const File = struct { |
| 67 | 67 | allow_shlib_undefined: bool, |
| 68 | 68 | stack_size: u64, |
| 69 | 69 | |
| 70 | error_flags: ErrorFlags = .{}, | |
| 71 | misc_errors: std.ArrayListUnmanaged(ErrorMsg) = .{}, | |
| 72 | ||
| 73 | 70 | /// Prevents other processes from clobbering files in the output directory |
| 74 | 71 | /// of this linking operation. |
| 75 | 72 | lock: ?Cache.Lock = null, |
| ... | ... | @@ -465,13 +462,8 @@ pub const File = struct { |
| 465 | 462 | } |
| 466 | 463 | |
| 467 | 464 | pub fn destroy(base: *File) void { |
| 468 | const gpa = base.comp.gpa; | |
| 469 | 465 | base.releaseLock(); |
| 470 | 466 | if (base.file) |f| f.close(); |
| 471 | { | |
| 472 | for (base.misc_errors.items) |*item| item.deinit(gpa); | |
| 473 | base.misc_errors.deinit(gpa); | |
| 474 | } | |
| 475 | 467 | switch (base.tag) { |
| 476 | 468 | .c => @fieldParentPtr(C, "base", base).deinit(), |
| 477 | 469 |
src/link/Coff.zig+2-2| ... | ... | @@ -1839,10 +1839,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 1839 | 1839 | |
| 1840 | 1840 | if (self.entry_addr == null and comp.config.output_mode == .Exe) { |
| 1841 | 1841 | log.debug("flushing. no_entry_point_found = true\n", .{}); |
| 1842 | self.base.error_flags.no_entry_point_found = true; | |
| 1842 | comp.link_error_flags.no_entry_point_found = true; | |
| 1843 | 1843 | } else { |
| 1844 | 1844 | log.debug("flushing. no_entry_point_found = false\n", .{}); |
| 1845 | self.base.error_flags.no_entry_point_found = false; | |
| 1845 | comp.link_error_flags.no_entry_point_found = false; | |
| 1846 | 1846 | try self.writeHeader(); |
| 1847 | 1847 | } |
| 1848 | 1848 |
src/link/Elf.zig+29-26| ... | ... | @@ -1170,7 +1170,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | // libc dep |
| 1173 | self.base.error_flags.missing_libc = false; | |
| 1173 | comp.link_error_flags.missing_libc = false; | |
| 1174 | 1174 | if (comp.config.link_libc) { |
| 1175 | 1175 | if (comp.libc_installation) |lc| { |
| 1176 | 1176 | const flags = target_util.libcFullLinkFlags(target); |
| ... | ... | @@ -1221,7 +1221,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1221 | 1221 | }); |
| 1222 | 1222 | try system_libs.append(.{ .path = path }); |
| 1223 | 1223 | } else { |
| 1224 | self.base.error_flags.missing_libc = true; | |
| 1224 | comp.link_error_flags.missing_libc = true; | |
| 1225 | 1225 | } |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| ... | ... | @@ -1259,7 +1259,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1259 | 1259 | }; |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1262 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1263 | 1263 | |
| 1264 | 1264 | // Init all objects |
| 1265 | 1265 | for (self.objects.items) |index| { |
| ... | ... | @@ -1269,7 +1269,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1269 | 1269 | try self.file(index).?.shared_object.init(self); |
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1272 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1273 | 1273 | |
| 1274 | 1274 | // Dedup shared objects |
| 1275 | 1275 | { |
| ... | ... | @@ -1388,14 +1388,14 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1388 | 1388 | |
| 1389 | 1389 | if (self.entry_index == null and self.base.isExe()) { |
| 1390 | 1390 | log.debug("flushing. no_entry_point_found = true", .{}); |
| 1391 | self.base.error_flags.no_entry_point_found = true; | |
| 1391 | comp.link_error_flags.no_entry_point_found = true; | |
| 1392 | 1392 | } else { |
| 1393 | 1393 | log.debug("flushing. no_entry_point_found = false", .{}); |
| 1394 | self.base.error_flags.no_entry_point_found = false; | |
| 1394 | comp.link_error_flags.no_entry_point_found = false; | |
| 1395 | 1395 | try self.writeElfHeader(); |
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1398 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | 1401 | pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { |
| ... | ... | @@ -1427,7 +1427,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const |
| 1427 | 1427 | }; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1430 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1431 | 1431 | |
| 1432 | 1432 | // First, we flush relocatable object file generated with our backends. |
| 1433 | 1433 | if (self.zigObjectPtr()) |zig_object| { |
| ... | ... | @@ -1539,7 +1539,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const |
| 1539 | 1539 | try self.base.file.?.setEndPos(total_size); |
| 1540 | 1540 | try self.base.file.?.pwriteAll(buffer.items, 0); |
| 1541 | 1541 | |
| 1542 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1542 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { |
| ... | ... | @@ -1570,14 +1570,14 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) |
| 1570 | 1570 | }; |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1573 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1574 | 1574 | |
| 1575 | 1575 | // Init all objects |
| 1576 | 1576 | for (self.objects.items) |index| { |
| 1577 | 1577 | try self.file(index).?.object.init(self); |
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1580 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1581 | 1581 | |
| 1582 | 1582 | // Now, we are ready to resolve the symbols across all input files. |
| 1583 | 1583 | // We will first resolve the files in the ZigObject, next in the parsed |
| ... | ... | @@ -1611,7 +1611,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) |
| 1611 | 1611 | try self.writeShdrTable(); |
| 1612 | 1612 | try self.writeElfHeader(); |
| 1613 | 1613 | |
| 1614 | if (self.base.misc_errors.items.len > 0) return error.FlushFailure; | |
| 1614 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | |
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | /// --verbose-link output |
| ... | ... | @@ -2888,7 +2888,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 2888 | 2888 | } |
| 2889 | 2889 | |
| 2890 | 2890 | // libc dep |
| 2891 | self.base.error_flags.missing_libc = false; | |
| 2891 | comp.link_error_flags.missing_libc = false; | |
| 2892 | 2892 | if (comp.config.link_libc) { |
| 2893 | 2893 | if (self.base.comp.libc_installation != null) { |
| 2894 | 2894 | const needs_grouping = link_mode == .Static; |
| ... | ... | @@ -2909,7 +2909,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 2909 | 2909 | .Dynamic => "libc.so", |
| 2910 | 2910 | })); |
| 2911 | 2911 | } else { |
| 2912 | self.base.error_flags.missing_libc = true; | |
| 2912 | comp.link_error_flags.missing_libc = true; | |
| 2913 | 2913 | } |
| 2914 | 2914 | } |
| 2915 | 2915 | } |
| ... | ... | @@ -3132,7 +3132,8 @@ fn writePhdrTable(self: *Elf) !void { |
| 3132 | 3132 | } |
| 3133 | 3133 | |
| 3134 | 3134 | fn writeElfHeader(self: *Elf) !void { |
| 3135 | if (self.base.misc_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable | |
| 3135 | const comp = self.base.comp; | |
| 3136 | if (comp.link_errors.items.len > 0) return; // We had errors, so skip flushing to render the output unusable | |
| 3136 | 3137 | |
| 3137 | 3138 | var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 = undefined; |
| 3138 | 3139 | |
| ... | ... | @@ -3146,7 +3147,6 @@ fn writeElfHeader(self: *Elf) !void { |
| 3146 | 3147 | }; |
| 3147 | 3148 | index += 1; |
| 3148 | 3149 | |
| 3149 | const comp = self.base.comp; | |
| 3150 | 3150 | const target = comp.root_mod.resolved_target.result; |
| 3151 | 3151 | const endian = target.cpu.arch.endian(); |
| 3152 | 3152 | hdr_buf[index] = switch (endian) { |
| ... | ... | @@ -6055,7 +6055,7 @@ pub fn tlsAddress(self: *Elf) u64 { |
| 6055 | 6055 | } |
| 6056 | 6056 | |
| 6057 | 6057 | const ErrorWithNotes = struct { |
| 6058 | /// Allocated index in misc_errors array. | |
| 6058 | /// Allocated index in comp.link_errors array. | |
| 6059 | 6059 | index: usize, |
| 6060 | 6060 | |
| 6061 | 6061 | /// Next available note slot. |
| ... | ... | @@ -6069,7 +6069,7 @@ const ErrorWithNotes = struct { |
| 6069 | 6069 | ) error{OutOfMemory}!void { |
| 6070 | 6070 | const comp = elf_file.base.comp; |
| 6071 | 6071 | const gpa = comp.gpa; |
| 6072 | const err_msg = &elf_file.base.misc_errors.items[err.index]; | |
| 6072 | const err_msg = &comp.link_errors.items[err.index]; | |
| 6073 | 6073 | err_msg.msg = try std.fmt.allocPrint(gpa, format, args); |
| 6074 | 6074 | } |
| 6075 | 6075 | |
| ... | ... | @@ -6081,7 +6081,7 @@ const ErrorWithNotes = struct { |
| 6081 | 6081 | ) error{OutOfMemory}!void { |
| 6082 | 6082 | const comp = elf_file.base.comp; |
| 6083 | 6083 | const gpa = comp.gpa; |
| 6084 | const err_msg = &elf_file.base.misc_errors.items[err.index]; | |
| 6084 | const err_msg = &comp.link_errors.items[err.index]; | |
| 6085 | 6085 | assert(err.note_slot < err_msg.notes.len); |
| 6086 | 6086 | err_msg.notes[err.note_slot] = .{ .msg = try std.fmt.allocPrint(gpa, format, args) }; |
| 6087 | 6087 | err.note_slot += 1; |
| ... | ... | @@ -6089,15 +6089,17 @@ const ErrorWithNotes = struct { |
| 6089 | 6089 | }; |
| 6090 | 6090 | |
| 6091 | 6091 | pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
| 6092 | const gpa = self.base.comp.gpa; | |
| 6093 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 6092 | const comp = self.base.comp; | |
| 6093 | const gpa = comp.gpa; | |
| 6094 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 6094 | 6095 | return self.addErrorWithNotesAssumeCapacity(note_count); |
| 6095 | 6096 | } |
| 6096 | 6097 | |
| 6097 | 6098 | fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
| 6098 | const gpa = self.base.comp.gpa; | |
| 6099 | const index = self.base.misc_errors.items.len; | |
| 6100 | const err = self.base.misc_errors.addOneAssumeCapacity(); | |
| 6099 | const comp = self.base.comp; | |
| 6100 | const gpa = comp.gpa; | |
| 6101 | const index = comp.link_errors.items.len; | |
| 6102 | const err = comp.link_errors.addOneAssumeCapacity(); | |
| 6101 | 6103 | err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) }; |
| 6102 | 6104 | return .{ .index = index }; |
| 6103 | 6105 | } |
| ... | ... | @@ -6129,10 +6131,11 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 { |
| 6129 | 6131 | } |
| 6130 | 6132 | |
| 6131 | 6133 | fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void { |
| 6132 | const gpa = self.base.comp.gpa; | |
| 6134 | const comp = self.base.comp; | |
| 6135 | const gpa = comp.gpa; | |
| 6133 | 6136 | const max_notes = 4; |
| 6134 | 6137 | |
| 6135 | try self.base.misc_errors.ensureUnusedCapacity(gpa, undefs.count()); | |
| 6138 | try comp.link_errors.ensureUnusedCapacity(gpa, undefs.count()); | |
| 6136 | 6139 | |
| 6137 | 6140 | var it = undefs.iterator(); |
| 6138 | 6141 | while (it.next()) |entry| { |
src/link/MachO.zig+31-24| ... | ... | @@ -323,8 +323,8 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li |
| 323 | 323 | if (build_options.have_llvm) { |
| 324 | 324 | return self.base.linkAsArchive(comp, prog_node); |
| 325 | 325 | } else { |
| 326 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 327 | self.base.misc_errors.appendAssumeCapacity(.{ | |
| 326 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 327 | comp.link_errors.appendAssumeCapacity(.{ | |
| 328 | 328 | .msg = try gpa.dupe(u8, "TODO: non-LLVM archiver for MachO object files"), |
| 329 | 329 | }); |
| 330 | 330 | return error.FlushFailure; |
| ... | ... | @@ -426,7 +426,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 426 | 426 | try self.resolveSymbols(); |
| 427 | 427 | |
| 428 | 428 | if (self.getEntryPoint() == null) { |
| 429 | self.base.error_flags.no_entry_point_found = true; | |
| 429 | comp.link_error_flags.no_entry_point_found = true; | |
| 430 | 430 | } |
| 431 | 431 | if (self.unresolved.count() > 0) { |
| 432 | 432 | try self.reportUndefined(); |
| ... | ... | @@ -5254,14 +5254,15 @@ fn reportMissingLibraryError( |
| 5254 | 5254 | comptime format: []const u8, |
| 5255 | 5255 | args: anytype, |
| 5256 | 5256 | ) error{OutOfMemory}!void { |
| 5257 | const gpa = self.base.comp.gpa; | |
| 5258 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 5257 | const comp = self.base.comp; | |
| 5258 | const gpa = comp.gpa; | |
| 5259 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 5259 | 5260 | const notes = try gpa.alloc(File.ErrorMsg, checked_paths.len); |
| 5260 | 5261 | errdefer gpa.free(notes); |
| 5261 | 5262 | for (checked_paths, notes) |path, *note| { |
| 5262 | 5263 | note.* = .{ .msg = try std.fmt.allocPrint(gpa, "tried {s}", .{path}) }; |
| 5263 | 5264 | } |
| 5264 | self.base.misc_errors.appendAssumeCapacity(.{ | |
| 5265 | comp.link_errors.appendAssumeCapacity(.{ | |
| 5265 | 5266 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5266 | 5267 | .notes = notes, |
| 5267 | 5268 | }); |
| ... | ... | @@ -5274,15 +5275,16 @@ fn reportDependencyError( |
| 5274 | 5275 | comptime format: []const u8, |
| 5275 | 5276 | args: anytype, |
| 5276 | 5277 | ) error{OutOfMemory}!void { |
| 5277 | const gpa = self.base.comp.gpa; | |
| 5278 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 5278 | const comp = self.base.comp; | |
| 5279 | const gpa = comp.gpa; | |
| 5280 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 5279 | 5281 | var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); |
| 5280 | 5282 | defer notes.deinit(); |
| 5281 | 5283 | if (path) |p| { |
| 5282 | 5284 | notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{p}) }); |
| 5283 | 5285 | } |
| 5284 | 5286 | notes.appendAssumeCapacity(.{ .msg = try std.fmt.allocPrint(gpa, "a dependency of {s}", .{parent}) }); |
| 5285 | self.base.misc_errors.appendAssumeCapacity(.{ | |
| 5287 | comp.link_errors.appendAssumeCapacity(.{ | |
| 5286 | 5288 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5287 | 5289 | .notes = try notes.toOwnedSlice(), |
| 5288 | 5290 | }); |
| ... | ... | @@ -5294,12 +5296,13 @@ pub fn reportParseError( |
| 5294 | 5296 | comptime format: []const u8, |
| 5295 | 5297 | args: anytype, |
| 5296 | 5298 | ) error{OutOfMemory}!void { |
| 5297 | const gpa = self.base.comp.gpa; | |
| 5298 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 5299 | const comp = self.base.comp; | |
| 5300 | const gpa = comp.gpa; | |
| 5301 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 5299 | 5302 | var notes = try gpa.alloc(File.ErrorMsg, 1); |
| 5300 | 5303 | errdefer gpa.free(notes); |
| 5301 | 5304 | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) }; |
| 5302 | self.base.misc_errors.appendAssumeCapacity(.{ | |
| 5305 | comp.link_errors.appendAssumeCapacity(.{ | |
| 5303 | 5306 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5304 | 5307 | .notes = notes, |
| 5305 | 5308 | }); |
| ... | ... | @@ -5311,21 +5314,23 @@ pub fn reportUnresolvedBoundarySymbol( |
| 5311 | 5314 | comptime format: []const u8, |
| 5312 | 5315 | args: anytype, |
| 5313 | 5316 | ) error{OutOfMemory}!void { |
| 5314 | const gpa = self.base.comp.gpa; | |
| 5315 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 5317 | const comp = self.base.comp; | |
| 5318 | const gpa = comp.gpa; | |
| 5319 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 5316 | 5320 | var notes = try gpa.alloc(File.ErrorMsg, 1); |
| 5317 | 5321 | errdefer gpa.free(notes); |
| 5318 | 5322 | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while resolving {s}", .{sym_name}) }; |
| 5319 | self.base.misc_errors.appendAssumeCapacity(.{ | |
| 5323 | comp.link_errors.appendAssumeCapacity(.{ | |
| 5320 | 5324 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 5321 | 5325 | .notes = notes, |
| 5322 | 5326 | }); |
| 5323 | 5327 | } |
| 5324 | 5328 | |
| 5325 | 5329 | pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { |
| 5326 | const gpa = self.base.comp.gpa; | |
| 5330 | const comp = self.base.comp; | |
| 5331 | const gpa = comp.gpa; | |
| 5327 | 5332 | const count = self.unresolved.count(); |
| 5328 | try self.base.misc_errors.ensureUnusedCapacity(gpa, count); | |
| 5333 | try comp.link_errors.ensureUnusedCapacity(gpa, count); | |
| 5329 | 5334 | |
| 5330 | 5335 | for (self.unresolved.keys()) |global_index| { |
| 5331 | 5336 | const global = self.globals.items[global_index]; |
| ... | ... | @@ -5346,7 +5351,7 @@ pub fn reportUndefined(self: *MachO) error{OutOfMemory}!void { |
| 5346 | 5351 | }; |
| 5347 | 5352 | err_msg.notes = try notes.toOwnedSlice(); |
| 5348 | 5353 | |
| 5349 | self.base.misc_errors.appendAssumeCapacity(err_msg); | |
| 5354 | comp.link_errors.appendAssumeCapacity(err_msg); | |
| 5350 | 5355 | } |
| 5351 | 5356 | } |
| 5352 | 5357 | |
| ... | ... | @@ -5355,8 +5360,9 @@ fn reportSymbolCollision( |
| 5355 | 5360 | first: SymbolWithLoc, |
| 5356 | 5361 | other: SymbolWithLoc, |
| 5357 | 5362 | ) error{OutOfMemory}!void { |
| 5358 | const gpa = self.base.comp.gpa; | |
| 5359 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 5363 | const comp = self.base.comp; | |
| 5364 | const gpa = comp.gpa; | |
| 5365 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 5360 | 5366 | |
| 5361 | 5367 | var notes = try std.ArrayList(File.ErrorMsg).initCapacity(gpa, 2); |
| 5362 | 5368 | defer notes.deinit(); |
| ... | ... | @@ -5379,12 +5385,13 @@ fn reportSymbolCollision( |
| 5379 | 5385 | }) }; |
| 5380 | 5386 | err_msg.notes = try notes.toOwnedSlice(); |
| 5381 | 5387 | |
| 5382 | self.base.misc_errors.appendAssumeCapacity(err_msg); | |
| 5388 | comp.link_errors.appendAssumeCapacity(err_msg); | |
| 5383 | 5389 | } |
| 5384 | 5390 | |
| 5385 | 5391 | fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{OutOfMemory}!void { |
| 5386 | const gpa = self.base.comp.gpa; | |
| 5387 | try self.base.misc_errors.ensureUnusedCapacity(gpa, 1); | |
| 5392 | const comp = self.base.comp; | |
| 5393 | const gpa = comp.gpa; | |
| 5394 | try comp.link_errors.ensureUnusedCapacity(gpa, 1); | |
| 5388 | 5395 | |
| 5389 | 5396 | const notes = try gpa.alloc(File.ErrorMsg, 1); |
| 5390 | 5397 | errdefer gpa.free(notes); |
| ... | ... | @@ -5402,7 +5409,7 @@ fn reportUnhandledSymbolType(self: *MachO, sym_with_loc: SymbolWithLoc) error{Ou |
| 5402 | 5409 | else |
| 5403 | 5410 | unreachable; |
| 5404 | 5411 | |
| 5405 | self.base.misc_errors.appendAssumeCapacity(.{ | |
| 5412 | comp.link_errors.appendAssumeCapacity(.{ | |
| 5406 | 5413 | .msg = try std.fmt.allocPrint(gpa, "unhandled symbol type: '{s}' has type {s}", .{ |
| 5407 | 5414 | self.getSymbolName(sym_with_loc), |
| 5408 | 5415 | sym_type, |