| ... | @@ -1042,7 +1042,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1042,7 +1042,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1042 | | 1042 | |
| 1043 | for (positionals.items) |obj| { | 1043 | for (positionals.items) |obj| { |
| 1044 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 1044 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 1045 | error.LinkFail, error.InvalidCpuArch => {}, // already reported | 1045 | error.MalformedObject, error.InvalidCpuArch => {}, // already reported |
| 1046 | else => |e| try self.reportParseError( | 1046 | else => |e| try self.reportParseError( |
| 1047 | obj.path, | 1047 | obj.path, |
| 1048 | "unexpected error: parsing input file failed with error {s}", | 1048 | "unexpected error: parsing input file failed with error {s}", |
| ... | @@ -1128,7 +1128,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1128,7 +1128,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1128 | | 1128 | |
| 1129 | for (system_libs.items) |lib| { | 1129 | for (system_libs.items) |lib| { |
| 1130 | self.parseLibrary(lib, false) catch |err| switch (err) { | 1130 | self.parseLibrary(lib, false) catch |err| switch (err) { |
| 1131 | error.LinkFail, error.InvalidCpuArch => {}, // already reported | 1131 | error.MalformedObject, error.InvalidCpuArch => {}, // already reported |
| 1132 | else => |e| try self.reportParseError( | 1132 | else => |e| try self.reportParseError( |
| 1133 | lib.path, | 1133 | lib.path, |
| 1134 | "unexpected error: parsing library failed with error {s}", | 1134 | "unexpected error: parsing library failed with error {s}", |
| ... | @@ -1151,7 +1151,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1151,7 +1151,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1151 | | 1151 | |
| 1152 | for (positionals.items) |obj| { | 1152 | for (positionals.items) |obj| { |
| 1153 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 1153 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 1154 | error.LinkFail, error.InvalidCpuArch => {}, // already reported | 1154 | error.MalformedObject, error.InvalidCpuArch => {}, // already reported |
| 1155 | else => |e| try self.reportParseError( | 1155 | else => |e| try self.reportParseError( |
| 1156 | obj.path, | 1156 | obj.path, |
| 1157 | "unexpected error: parsing input file failed with error {s}", | 1157 | "unexpected error: parsing input file failed with error {s}", |
| ... | @@ -1316,7 +1316,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const | ... | @@ -1316,7 +1316,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation, module_obj_path: ?[]const |
| 1316 | | 1316 | |
| 1317 | for (positionals.items) |obj| { | 1317 | for (positionals.items) |obj| { |
| 1318 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 1318 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 1319 | error.LinkFail, error.InvalidCpuArch => {}, // already reported | 1319 | error.MalformedObject, error.InvalidCpuArch => {}, // already reported |
| 1320 | else => |e| try self.reportParseError( | 1320 | else => |e| try self.reportParseError( |
| 1321 | obj.path, | 1321 | obj.path, |
| 1322 | "unexpected error: parsing input file failed with error {s}", | 1322 | "unexpected error: parsing input file failed with error {s}", |
| ... | @@ -1453,7 +1453,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) | ... | @@ -1453,7 +1453,7 @@ pub fn flushObject(self: *Elf, comp: *Compilation, module_obj_path: ?[]const u8) |
| 1453 | | 1453 | |
| 1454 | for (positionals.items) |obj| { | 1454 | for (positionals.items) |obj| { |
| 1455 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 1455 | self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 1456 | error.LinkFail, error.InvalidCpuArch => {}, // already reported | 1456 | error.MalformedObject, error.InvalidCpuArch => {}, // already reported |
| 1457 | else => |e| try self.reportParseError( | 1457 | else => |e| try self.reportParseError( |
| 1458 | obj.path, | 1458 | obj.path, |
| 1459 | "unexpected error: parsing input file failed with error {s}", | 1459 | "unexpected error: parsing input file failed with error {s}", |
| ... | @@ -1785,8 +1785,8 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { | ... | @@ -1785,8 +1785,8 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { |
| 1785 | } | 1785 | } |
| 1786 | | 1786 | |
| 1787 | const ParseError = error{ | 1787 | const ParseError = error{ |
| 1788 | LinkFail, | 1788 | MalformedObject, |
| 1789 | UnknownFileType, | 1789 | MalformedArchive, |
| 1790 | InvalidCpuArch, | 1790 | InvalidCpuArch, |
| 1791 | OutOfMemory, | 1791 | OutOfMemory, |
| 1792 | Overflow, | 1792 | Overflow, |
| ... | @@ -1816,11 +1816,7 @@ fn parseLibrary(self: *Elf, lib: SystemLib, must_link: bool) ParseError!void { | ... | @@ -1816,11 +1816,7 @@ fn parseLibrary(self: *Elf, lib: SystemLib, must_link: bool) ParseError!void { |
| 1816 | } else if (try SharedObject.isSharedObject(lib.path)) { | 1816 | } else if (try SharedObject.isSharedObject(lib.path)) { |
| 1817 | try self.parseSharedObject(lib); | 1817 | try self.parseSharedObject(lib); |
| 1818 | } else { | 1818 | } else { |
| 1819 | // TODO if the script has a top-level comment identifying it as GNU ld script, | 1819 | try self.parseLdScript(lib); |
| 1820 | // then report parse errors. Otherwise return UnknownFileType. | | |
| 1821 | self.parseLdScript(lib) catch |err| switch (err) { | | |
| 1822 | else => return error.UnknownFileType, | | |
| 1823 | }; | | |
| 1824 | } | 1820 | } |
| 1825 | } | 1821 | } |
| 1826 | | 1822 | |
| ... | @@ -1902,7 +1898,7 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void { | ... | @@ -1902,7 +1898,7 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void { |
| 1902 | const data = try in_file.readToEndAlloc(gpa, std.math.maxInt(u32)); | 1898 | const data = try in_file.readToEndAlloc(gpa, std.math.maxInt(u32)); |
| 1903 | defer gpa.free(data); | 1899 | defer gpa.free(data); |
| 1904 | | 1900 | |
| 1905 | var script = LdScript{}; | 1901 | var script = LdScript{ .path = lib.path }; |
| 1906 | defer script.deinit(gpa); | 1902 | defer script.deinit(gpa); |
| 1907 | try script.parse(data, self); | 1903 | try script.parse(data, self); |
| 1908 | | 1904 | |
| ... | @@ -1963,7 +1959,7 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void { | ... | @@ -1963,7 +1959,7 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void { |
| 1963 | .needed = scr_obj.needed, | 1959 | .needed = scr_obj.needed, |
| 1964 | .path = full_path, | 1960 | .path = full_path, |
| 1965 | }, false) catch |err| switch (err) { | 1961 | }, false) catch |err| switch (err) { |
| 1966 | error.LinkFail, error.InvalidCpuArch => {}, // already reported | 1962 | error.MalformedObject, error.InvalidCpuArch => {}, // already reported |
| 1967 | else => |e| try self.reportParseError( | 1963 | else => |e| try self.reportParseError( |
| 1968 | full_path, | 1964 | full_path, |
| 1969 | "unexpected error: parsing library failed with error {s}", | 1965 | "unexpected error: parsing library failed with error {s}", |
| ... | @@ -2195,7 +2191,7 @@ fn scanRelocs(self: *Elf) !void { | ... | @@ -2195,7 +2191,7 @@ fn scanRelocs(self: *Elf) !void { |
| 2195 | try object.scanRelocs(self, &undefs); | 2191 | try object.scanRelocs(self, &undefs); |
| 2196 | } | 2192 | } |
| 2197 | | 2193 | |
| 2198 | try self.reportUndefined(&undefs); | 2194 | try self.reportUndefinedSymbols(&undefs); |
| 2199 | | 2195 | |
| 2200 | for (self.symbols.items, 0..) |*sym, i| { | 2196 | for (self.symbols.items, 0..) |*sym, i| { |
| 2201 | const index = @as(u32, @intCast(i)); | 2197 | const index = @as(u32, @intCast(i)); |
| ... | @@ -4760,7 +4756,7 @@ fn writeAtoms(self: *Elf) !void { | ... | @@ -4760,7 +4756,7 @@ fn writeAtoms(self: *Elf) !void { |
| 4760 | try self.base.file.?.pwriteAll(buffer, sh_offset); | 4756 | try self.base.file.?.pwriteAll(buffer, sh_offset); |
| 4761 | } | 4757 | } |
| 4762 | | 4758 | |
| 4763 | try self.reportUndefined(&undefs); | 4759 | try self.reportUndefinedSymbols(&undefs); |
| 4764 | } | 4760 | } |
| 4765 | | 4761 | |
| 4766 | fn writeAtomsObject(self: *Elf) !void { | 4762 | fn writeAtomsObject(self: *Elf) !void { |
| ... | @@ -6023,7 +6019,7 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 { | ... | @@ -6023,7 +6019,7 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 { |
| 6023 | return off; | 6019 | return off; |
| 6024 | } | 6020 | } |
| 6025 | | 6021 | |
| 6026 | fn reportUndefined(self: *Elf, undefs: anytype) !void { | 6022 | fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void { |
| 6027 | const gpa = self.base.allocator; | 6023 | const gpa = self.base.allocator; |
| 6028 | const max_notes = 4; | 6024 | const max_notes = 4; |
| 6029 | | 6025 | |
| ... | @@ -6065,7 +6061,7 @@ fn reportMissingLibraryError( | ... | @@ -6065,7 +6061,7 @@ fn reportMissingLibraryError( |
| 6065 | } | 6061 | } |
| 6066 | } | 6062 | } |
| 6067 | | 6063 | |
| 6068 | fn reportParseError( | 6064 | pub fn reportParseError( |
| 6069 | self: *Elf, | 6065 | self: *Elf, |
| 6070 | path: []const u8, | 6066 | path: []const u8, |
| 6071 | comptime format: []const u8, | 6067 | comptime format: []const u8, |