aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-02-21 20:11:32 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-02-21 20:11:32 +0100
commit4cde47a169efc3d2dc70f057742e65b088e139a3 (patch)
tree26901a8c10681769372c72c6a6cd6e2602033920 /src/link/Elf.zig
parent60bc2e7616b0fd42c98ba8b9e0b212439b6ea1a0 (diff)
downloadzig-4cde47a169efc3d2dc70f057742e65b088e139a3.tar.gz
zig-4cde47a169efc3d2dc70f057742e65b088e139a3.zip
elf: simplify logic for resolving alloc relocs on different arches
Diffstat (limited to 'src/link/Elf.zig')
-rw-r--r--src/link/Elf.zig15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index be86b84018..10f0ce0655 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -1344,6 +1344,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
// Beyond this point, everything has been allocated a virtual address and we can resolve
// the relocations, and commit objects to file.
if (self.zigObjectPtr()) |zig_object| {
+ var has_reloc_errors = false;
for (zig_object.atoms.items) |atom_index| {
const atom_ptr = self.atom(atom_index) orelse continue;
if (!atom_ptr.flags.alive) continue;
@@ -1354,10 +1355,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
defer gpa.free(code);
const file_offset = shdr.sh_offset + atom_ptr.value;
atom_ptr.resolveRelocsAlloc(self, code) catch |err| switch (err) {
- // TODO
- error.RelaxFail, error.InvalidInstruction, error.CannotEncode => {
- log.err("relaxing intructions failed; TODO this should be a fatal linker error", .{});
- },
+ error.RelocFailure, error.RelaxFailure => has_reloc_errors = true,
error.UnsupportedCpuArch => {
try self.reportUnsupportedCpuArch();
return error.FlushFailure;
@@ -1366,6 +1364,8 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
};
try self.base.file.?.pwriteAll(code, file_offset);
}
+
+ if (has_reloc_errors) return error.FlushFailure;
}
try self.writePhdrTable();
@@ -2052,6 +2052,7 @@ fn scanRelocs(self: *Elf) !void {
var has_reloc_errors = false;
for (objects.items) |index| {
self.file(index).?.scanRelocs(self, &undefs) catch |err| switch (err) {
+ error.RelaxFailure => unreachable,
error.UnsupportedCpuArch => {
try self.reportUnsupportedCpuArch();
return error.FlushFailure;
@@ -4517,15 +4518,11 @@ fn writeAtoms(self: *Elf) !void {
else
atom_ptr.resolveRelocsAlloc(self, out_code);
_ = res catch |err| switch (err) {
- // TODO
- error.RelaxFail, error.InvalidInstruction, error.CannotEncode => {
- log.err("relaxing intructions failed; TODO this should be a fatal linker error", .{});
- },
error.UnsupportedCpuArch => {
try self.reportUnsupportedCpuArch();
return error.FlushFailure;
},
- error.RelocFailure => has_reloc_errors = true,
+ error.RelocFailure, error.RelaxFailure => has_reloc_errors = true,
else => |e| return e,
};
}