Skip to content

Commit a92e614

Browse files
committed
elf+riscv: return an error for unimplemented HI20 forward lookup
1 parent 6236f5b commit a92e614

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/link/Elf/Atom.zig

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

0 commit comments

Comments
 (0)