| ... | ... | @@ -4016,10 +4016,14 @@ const ErrorWithNotes = struct { |
| 4016 | 4016 | }; |
| 4017 | 4017 | |
| 4018 | 4018 | fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
| 4019 | | const gpa = self.base.allocator; |
| 4019 | try self.misc_errors.ensureUnusedCapacity(self.base.allocator, 1); |
| 4020 | return self.addErrorWithNotesAssumeCapacity(note_count); |
| 4021 | } |
| 4022 | |
| 4023 | fn addErrorWithNotesAssumeCapacity(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
| 4020 | 4024 | const index = self.misc_errors.items.len; |
| 4021 | | const err = try self.misc_errors.addOne(gpa); |
| 4022 | | err.* = .{ .msg = undefined, .notes = try gpa.alloc(link.File.ErrorMsg, note_count) }; |
| 4025 | const err = self.misc_errors.addOneAssumeCapacity(); |
| 4026 | err.* = .{ .msg = undefined, .notes = try self.base.allocator.alloc(link.File.ErrorMsg, note_count) }; |
| 4023 | 4027 | return .{ .index = index }; |
| 4024 | 4028 | } |
| 4025 | 4029 | |
| ... | ... | @@ -4033,33 +4037,22 @@ fn reportUndefined(self: *Elf, undefs: anytype) !void { |
| 4033 | 4037 | while (it.next()) |entry| { |
| 4034 | 4038 | const undef_index = entry.key_ptr.*; |
| 4035 | 4039 | const atoms = entry.value_ptr.*.items; |
| 4036 | | const nnotes = @min(atoms.len, max_notes); |
| 4040 | const natoms = @min(atoms.len, max_notes); |
| 4041 | const nnotes = natoms + @intFromBool(atoms.len > max_notes); |
| 4037 | 4042 | |
| 4038 | | var notes = try std.ArrayList(link.File.ErrorMsg).initCapacity(gpa, max_notes + 1); |
| 4039 | | defer notes.deinit(); |
| 4043 | var err = try self.addErrorWithNotesAssumeCapacity(nnotes); |
| 4044 | try err.addMsg(self, "undefined symbol: {s}", .{self.symbol(undef_index).name(self)}); |
| 4040 | 4045 | |
| 4041 | | for (atoms[0..nnotes]) |atom_index| { |
| 4046 | for (atoms[0..natoms]) |atom_index| { |
| 4042 | 4047 | const atom_ptr = self.atom(atom_index).?; |
| 4043 | 4048 | const file_ptr = self.file(atom_ptr.file_index).?; |
| 4044 | | const note = try std.fmt.allocPrint(gpa, "referenced by {s}:{s}", .{ |
| 4045 | | file_ptr.fmtPath(), |
| 4046 | | atom_ptr.name(self), |
| 4047 | | }); |
| 4048 | | notes.appendAssumeCapacity(.{ .msg = note }); |
| 4049 | try err.addNote(self, "referenced by {s}:{s}", .{ file_ptr.fmtPath(), atom_ptr.name(self) }); |
| 4049 | 4050 | } |
| 4050 | 4051 | |
| 4051 | 4052 | if (atoms.len > max_notes) { |
| 4052 | 4053 | const remaining = atoms.len - max_notes; |
| 4053 | | const note = try std.fmt.allocPrint(gpa, "referenced {d} more times", .{remaining}); |
| 4054 | | notes.appendAssumeCapacity(.{ .msg = note }); |
| 4054 | try err.addNote(self, "referenced {d} more times", .{remaining}); |
| 4055 | 4055 | } |
| 4056 | | |
| 4057 | | var err_msg = link.File.ErrorMsg{ |
| 4058 | | .msg = try std.fmt.allocPrint(gpa, "undefined symbol: {s}", .{self.symbol(undef_index).name(self)}), |
| 4059 | | }; |
| 4060 | | err_msg.notes = try notes.toOwnedSlice(); |
| 4061 | | |
| 4062 | | self.misc_errors.appendAssumeCapacity(err_msg); |
| 4063 | 4056 | } |
| 4064 | 4057 | } |
| 4065 | 4058 | |
| ... | ... | @@ -4095,15 +4088,9 @@ fn reportParseError( |
| 4095 | 4088 | comptime format: []const u8, |
| 4096 | 4089 | args: anytype, |
| 4097 | 4090 | ) error{OutOfMemory}!void { |
| 4098 | | const gpa = self.base.allocator; |
| 4099 | | try self.misc_errors.ensureUnusedCapacity(gpa, 1); |
| 4100 | | var notes = try gpa.alloc(link.File.ErrorMsg, 1); |
| 4101 | | errdefer gpa.free(notes); |
| 4102 | | notes[0] = .{ .msg = try std.fmt.allocPrint(gpa, "while parsing {s}", .{path}) }; |
| 4103 | | self.misc_errors.appendAssumeCapacity(.{ |
| 4104 | | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 4105 | | .notes = notes, |
| 4106 | | }); |
| 4091 | var err = try self.addErrorWithNotes(1); |
| 4092 | try err.addMsg(self, format, args); |
| 4093 | try err.addNote(self, "while parsing {s}", .{path}); |
| 4107 | 4094 | } |
| 4108 | 4095 | |
| 4109 | 4096 | fn fmtShdrs(self: *Elf) std.fmt.Formatter(formatShdrs) { |