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 {...@@ -1881,14 +1881,22 @@ const riscv = struct {
1881 => {1881 => {
1882 assert(A == 0); // according to the spec1882 assert(A == 0); // according to the spec
1883 // We need to find the paired reloc for this relocation.1883 // We need to find the paired reloc for this relocation.
1884 // TODO: should we search forward too?
1885 const file_ptr = atom.file(elf_file).?;1884 const file_ptr = atom.file(elf_file).?;
1885 const atom_addr = atom.address(elf_file);
1886 const pos = it.pos;1886 const pos = it.pos;
1887 const pair = while (it.prev()) |pair| {1887 const pair = while (it.prev()) |pair| {
1888 if (target.address(.{}, elf_file) == atom.address(elf_file) + pair.r_offset) {1888 if (S == atom_addr + pair.r_offset) break pair;
1889 break pair;1889 } else {
1890 }1890 // TODO: implement searching forward
1891 } else unreachable; // TODO error1891 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 };
1892 it.pos = pos;1900 it.pos = pos;
1893 const target_ = switch (file_ptr) {1901 const target_ = switch (file_ptr) {
1894 .zig_object => |x| elf_file.symbol(x.symbol(pair.r_sym())),1902 .zig_object => |x| elf_file.symbol(x.symbol(pair.r_sym())),
...@@ -1897,7 +1905,7 @@ const riscv = struct {...@@ -1897,7 +1905,7 @@ const riscv = struct {
1897 };1905 };
1898 const S_ = @as(i64, @intCast(target_.address(.{}, elf_file)));1906 const S_ = @as(i64, @intCast(target_.address(.{}, elf_file)));
1899 const A_ = pair.r_addend;1907 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));
1901 const G_ = @as(i64, @intCast(target_.gotAddress(elf_file))) - GOT;1909 const G_ = @as(i64, @intCast(target_.gotAddress(elf_file))) - GOT;
1902 const disp = switch (@as(elf.R_RISCV, @enumFromInt(pair.r_type()))) {1910 const disp = switch (@as(elf.R_RISCV, @enumFromInt(pair.r_type()))) {
1903 .PCREL_HI20 => math.cast(i32, S_ + A_ - P_) orelse return error.Overflow,1911 .PCREL_HI20 => math.cast(i32, S_ + A_ - P_) orelse return error.Overflow,