@@ -995,12 +995,12 @@ pub fn growAllocSection(self: *Elf, shdr_index: u32, needed_size: u64) !void {
995
995
if (maybe_phdr ) | phdr | {
996
996
const mem_capacity = self .allocatedVirtualSize (phdr .p_vaddr );
997
997
if (needed_size > mem_capacity ) {
998
- var err = try self .addErrorWithNotes (2 );
999
- try err .addMsg (self , "fatal linker error: cannot expand load segment phdr({d}) in virtual memory" , .{
998
+ var err = try self .base . addErrorWithNotes (2 );
999
+ try err .addMsg ("fatal linker error: cannot expand load segment phdr({d}) in virtual memory" , .{
1000
1000
self .phdr_to_shdr_table .get (shdr_index ).? ,
1001
1001
});
1002
- try err .addNote (self , "TODO: emit relocations to memory locations in self-hosted backends" , .{});
1003
- try err .addNote (self , "as a workaround, try increasing pre-allocated virtual memory of each segment" , .{});
1002
+ try err .addNote ("TODO: emit relocations to memory locations in self-hosted backends" , .{});
1003
+ try err .addNote ("as a workaround, try increasing pre-allocated virtual memory of each segment" , .{});
1004
1004
}
1005
1005
1006
1006
phdr .p_memsz = needed_size ;
@@ -1276,7 +1276,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
1276
1276
};
1277
1277
}
1278
1278
1279
- if (comp . link_errors . items . len > 0 ) return error .FlushFailure ;
1279
+ if (self . base . hasErrors () ) return error .FlushFailure ;
1280
1280
1281
1281
// Dedup shared objects
1282
1282
{
@@ -1423,7 +1423,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
1423
1423
try self .writeElfHeader ();
1424
1424
}
1425
1425
1426
- if (comp . link_errors . items . len > 0 ) return error .FlushFailure ;
1426
+ if (self . base . hasErrors () ) return error .FlushFailure ;
1427
1427
}
1428
1428
1429
1429
/// --verbose-link output
@@ -2852,9 +2852,9 @@ fn writePhdrTable(self: *Elf) !void {
2852
2852
}
2853
2853
2854
2854
pub fn writeElfHeader (self : * Elf ) ! void {
2855
- const comp = self .base .comp ;
2856
- if (comp .link_errors .items .len > 0 ) return ; // We had errors, so skip flushing to render the output unusable
2855
+ if (self .base .hasErrors ()) return ; // We had errors, so skip flushing to render the output unusable
2857
2856
2857
+ const comp = self .base .comp ;
2858
2858
var hdr_buf : [@sizeOf (elf .Elf64_Ehdr )]u8 = undefined ;
2859
2859
2860
2860
var index : usize = 0 ;
@@ -4298,9 +4298,9 @@ fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void {
4298
4298
// (revisit getMaxNumberOfPhdrs())
4299
4299
// 2. shift everything in file to free more space for EHDR + PHDR table
4300
4300
// TODO verify `getMaxNumberOfPhdrs()` is accurate and convert this into no-op
4301
- var err = try self .addErrorWithNotes (1 );
4302
- try err .addMsg (self , "fatal linker error: not enough space reserved for EHDR and PHDR table" , .{});
4303
- try err .addNote (self , "required 0x{x}, available 0x{x}" , .{ needed_size , available_space });
4301
+ var err = try self .base . addErrorWithNotes (1 );
4302
+ try err .addMsg ("fatal linker error: not enough space reserved for EHDR and PHDR table" , .{});
4303
+ try err .addNote ("required 0x{x}, available 0x{x}" , .{ needed_size , available_space });
4304
4304
}
4305
4305
4306
4306
phdr_table_load .p_filesz = needed_size + ehsize ;
@@ -5863,56 +5863,6 @@ pub fn tlsAddress(self: *Elf) i64 {
5863
5863
return @intCast (phdr .p_vaddr );
5864
5864
}
5865
5865
5866
- const ErrorWithNotes = struct {
5867
- /// Allocated index in comp.link_errors array.
5868
- index : usize ,
5869
-
5870
- /// Next available note slot.
5871
- note_slot : usize = 0 ,
5872
-
5873
- pub fn addMsg (
5874
- err : ErrorWithNotes ,
5875
- elf_file : * Elf ,
5876
- comptime format : []const u8 ,
5877
- args : anytype ,
5878
- ) error {OutOfMemory }! void {
5879
- const comp = elf_file .base .comp ;
5880
- const gpa = comp .gpa ;
5881
- const err_msg = & comp .link_errors .items [err .index ];
5882
- err_msg .msg = try std .fmt .allocPrint (gpa , format , args );
5883
- }
5884
-
5885
- pub fn addNote (
5886
- err : * ErrorWithNotes ,
5887
- elf_file : * Elf ,
5888
- comptime format : []const u8 ,
5889
- args : anytype ,
5890
- ) error {OutOfMemory }! void {
5891
- const comp = elf_file .base .comp ;
5892
- const gpa = comp .gpa ;
5893
- const err_msg = & comp .link_errors .items [err .index ];
5894
- assert (err .note_slot < err_msg .notes .len );
5895
- err_msg .notes [err .note_slot ] = .{ .msg = try std .fmt .allocPrint (gpa , format , args ) };
5896
- err .note_slot += 1 ;
5897
- }
5898
- };
5899
-
5900
- pub fn addErrorWithNotes (self : * Elf , note_count : usize ) error {OutOfMemory }! ErrorWithNotes {
5901
- const comp = self .base .comp ;
5902
- const gpa = comp .gpa ;
5903
- try comp .link_errors .ensureUnusedCapacity (gpa , 1 );
5904
- return self .addErrorWithNotesAssumeCapacity (note_count );
5905
- }
5906
-
5907
- fn addErrorWithNotesAssumeCapacity (self : * Elf , note_count : usize ) error {OutOfMemory }! ErrorWithNotes {
5908
- const comp = self .base .comp ;
5909
- const gpa = comp .gpa ;
5910
- const index = comp .link_errors .items .len ;
5911
- const err = comp .link_errors .addOneAssumeCapacity ();
5912
- err .* = .{ .msg = undefined , .notes = try gpa .alloc (link .File .ErrorMsg , note_count ) };
5913
- return .{ .index = index };
5914
- }
5915
-
5916
5866
pub fn getShString (self : Elf , off : u32 ) [:0 ]const u8 {
5917
5867
assert (off < self .shstrtab .items .len );
5918
5868
return mem .sliceTo (@as ([* :0 ]const u8 , @ptrCast (self .shstrtab .items .ptr + off )), 0 );
@@ -5940,11 +5890,10 @@ pub fn insertDynString(self: *Elf, name: []const u8) error{OutOfMemory}!u32 {
5940
5890
}
5941
5891
5942
5892
fn reportUndefinedSymbols (self : * Elf , undefs : anytype ) ! void {
5943
- const comp = self .base .comp ;
5944
- const gpa = comp .gpa ;
5893
+ const gpa = self .base .comp .gpa ;
5945
5894
const max_notes = 4 ;
5946
5895
5947
- try comp .link_errors .ensureUnusedCapacity (gpa , undefs .count ());
5896
+ try self . base . comp .link_errors .ensureUnusedCapacity (gpa , undefs .count ());
5948
5897
5949
5898
var it = undefs .iterator ();
5950
5899
while (it .next ()) | entry | {
@@ -5953,18 +5902,18 @@ fn reportUndefinedSymbols(self: *Elf, undefs: anytype) !void {
5953
5902
const natoms = @min (atoms .len , max_notes );
5954
5903
const nnotes = natoms + @intFromBool (atoms .len > max_notes );
5955
5904
5956
- var err = try self .addErrorWithNotesAssumeCapacity (nnotes );
5957
- try err .addMsg (self , "undefined symbol: {s}" , .{self .symbol (undef_index ).name (self )});
5905
+ var err = try self .base . addErrorWithNotesAssumeCapacity (nnotes );
5906
+ try err .addMsg ("undefined symbol: {s}" , .{self .symbol (undef_index ).name (self )});
5958
5907
5959
5908
for (atoms [0.. natoms ]) | atom_index | {
5960
5909
const atom_ptr = self .atom (atom_index ).? ;
5961
5910
const file_ptr = self .file (atom_ptr .file_index ).? ;
5962
- try err .addNote (self , "referenced by {s}:{s}" , .{ file_ptr .fmtPath (), atom_ptr .name (self ) });
5911
+ try err .addNote ("referenced by {s}:{s}" , .{ file_ptr .fmtPath (), atom_ptr .name (self ) });
5963
5912
}
5964
5913
5965
5914
if (atoms .len > max_notes ) {
5966
5915
const remaining = atoms .len - max_notes ;
5967
- try err .addNote (self , "referenced {d} more times" , .{remaining });
5916
+ try err .addNote ("referenced {d} more times" , .{remaining });
5968
5917
}
5969
5918
}
5970
5919
}
@@ -5978,19 +5927,19 @@ fn reportDuplicates(self: *Elf, dupes: anytype) error{ HasDuplicates, OutOfMemor
5978
5927
const notes = entry .value_ptr .* ;
5979
5928
const nnotes = @min (notes .items .len , max_notes ) + @intFromBool (notes .items .len > max_notes );
5980
5929
5981
- var err = try self .addErrorWithNotes (nnotes + 1 );
5982
- try err .addMsg (self , "duplicate symbol definition: {s}" , .{sym .name (self )});
5983
- try err .addNote (self , "defined by {}" , .{sym .file (self ).? .fmtPath ()});
5930
+ var err = try self .base . addErrorWithNotes (nnotes + 1 );
5931
+ try err .addMsg ("duplicate symbol definition: {s}" , .{sym .name (self )});
5932
+ try err .addNote ("defined by {}" , .{sym .file (self ).? .fmtPath ()});
5984
5933
5985
5934
var inote : usize = 0 ;
5986
5935
while (inote < @min (notes .items .len , max_notes )) : (inote += 1 ) {
5987
5936
const file_ptr = self .file (notes .items [inote ]).? ;
5988
- try err .addNote (self , "defined by {}" , .{file_ptr .fmtPath ()});
5937
+ try err .addNote ("defined by {}" , .{file_ptr .fmtPath ()});
5989
5938
}
5990
5939
5991
5940
if (notes .items .len > max_notes ) {
5992
5941
const remaining = notes .items .len - max_notes ;
5993
- try err .addNote (self , "defined {d} more times" , .{remaining });
5942
+ try err .addNote ("defined {d} more times" , .{remaining });
5994
5943
}
5995
5944
5996
5945
has_dupes = true ;
@@ -6005,16 +5954,16 @@ fn reportMissingLibraryError(
6005
5954
comptime format : []const u8 ,
6006
5955
args : anytype ,
6007
5956
) error {OutOfMemory }! void {
6008
- var err = try self .addErrorWithNotes (checked_paths .len );
6009
- try err .addMsg (self , format , args );
5957
+ var err = try self .base . addErrorWithNotes (checked_paths .len );
5958
+ try err .addMsg (format , args );
6010
5959
for (checked_paths ) | path | {
6011
- try err .addNote (self , "tried {s}" , .{path });
5960
+ try err .addNote ("tried {s}" , .{path });
6012
5961
}
6013
5962
}
6014
5963
6015
5964
pub fn reportUnsupportedCpuArch (self : * Elf ) error {OutOfMemory }! void {
6016
- var err = try self .addErrorWithNotes (0 );
6017
- try err .addMsg (self , "fatal linker error: unsupported CPU architecture {s}" , .{
5965
+ var err = try self .base . addErrorWithNotes (0 );
5966
+ try err .addMsg ("fatal linker error: unsupported CPU architecture {s}" , .{
6018
5967
@tagName (self .getTarget ().cpu .arch ),
6019
5968
});
6020
5969
}
@@ -6025,9 +5974,9 @@ pub fn reportParseError(
6025
5974
comptime format : []const u8 ,
6026
5975
args : anytype ,
6027
5976
) error {OutOfMemory }! void {
6028
- var err = try self .addErrorWithNotes (1 );
6029
- try err .addMsg (self , format , args );
6030
- try err .addNote (self , "while parsing {s}" , .{path });
5977
+ var err = try self .base . addErrorWithNotes (1 );
5978
+ try err .addMsg (format , args );
5979
+ try err .addNote ("while parsing {s}" , .{path });
6031
5980
}
6032
5981
6033
5982
pub fn reportParseError2 (
@@ -6036,9 +5985,9 @@ pub fn reportParseError2(
6036
5985
comptime format : []const u8 ,
6037
5986
args : anytype ,
6038
5987
) error {OutOfMemory }! void {
6039
- var err = try self .addErrorWithNotes (1 );
6040
- try err .addMsg (self , format , args );
6041
- try err .addNote (self , "while parsing {}" , .{self .file (file_index ).? .fmtPath ()});
5988
+ var err = try self .base . addErrorWithNotes (1 );
5989
+ try err .addMsg (format , args );
5990
+ try err .addNote ("while parsing {}" , .{self .file (file_index ).? .fmtPath ()});
6042
5991
}
6043
5992
6044
5993
const FormatShdrCtx = struct {
0 commit comments