authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 23:49:22+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 23:49:22+01:00
loga92e6146da4613c406c4b333295e9c02c92eae78
tree71e86bd716cea13a622bbbd1ec1da0e514ece951
parent6236f5b8105f4f5ae773190d18ebff2db90e34e5

elf+riscv: return an error for unimplemented HI20 forward lookup


1 files changed, 14 insertions(+), 6 deletions(-)

src/link/Elf/Atom.zig+14-6
......@@ -1881,14 +1881,22 @@ const riscv = struct {
18811881 => {
18821882 assert(A == 0); // according to the spec
18831883 // We need to find the paired reloc for this relocation.
1884 // TODO: should we search forward too?
18851884 const file_ptr = atom.file(elf_file).?;
1885 const atom_addr = atom.address(elf_file);
18861886 const pos = it.pos;
18871887 const pair = while (it.prev()) |pair| {
1888 if (target.address(.{}, elf_file) == atom.address(elf_file) + pair.r_offset) {
1889 break pair;
1890 }
1891 } else unreachable; // TODO error
1888 if (S == atom_addr + pair.r_offset) break pair;
1889 } else {
1890 // TODO: implement searching forward
1891 var err = try elf_file.addErrorWithNotes(1);
1892 try err.addMsg(elf_file, "TODO: find HI20 paired reloc scanning forward", .{});
1893 try err.addNote(elf_file, "in {}:{s} at offset 0x{x}", .{
1894 atom.file(elf_file).?.fmtPath(),
1895 atom.name(elf_file),
1896 rel.r_offset,
1897 });
1898 return error.RelocFailure;
1899 };
18921900 it.pos = pos;
18931901 const target_ = switch (file_ptr) {
18941902 .zig_object => |x| elf_file.symbol(x.symbol(pair.r_sym())),
......@@ -1897,7 +1905,7 @@ const riscv = struct {
18971905 };
18981906 const S_ = @as(i64, @intCast(target_.address(.{}, elf_file)));
18991907 const A_ = pair.r_addend;
1900 const P_ = @as(i64, @intCast(atom.address(elf_file) + pair.r_offset));
1908 const P_ = @as(i64, @intCast(atom_addr + pair.r_offset));
19011909 const G_ = @as(i64, @intCast(target_.gotAddress(elf_file))) - GOT;
19021910 const disp = switch (@as(elf.R_RISCV, @enumFromInt(pair.r_type()))) {
19031911 .PCREL_HI20 => math.cast(i32, S_ + A_ - P_) orelse return error.Overflow,