aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-03-10 23:45:29 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-03-12 13:16:11 +0100
commitb1eba5a996ed862aefae49a1a7d1480a788095ff (patch)
tree2debf6d50e93317831634489ce135d31d45cae2e /src/link
parentda5b16f9e2b76534b1cab9093566693482084360 (diff)
downloadzig-b1eba5a996ed862aefae49a1a7d1480a788095ff.tar.gz
zig-b1eba5a996ed862aefae49a1a7d1480a788095ff.zip
elf+aarch64: actually write out thunks, and add a proper link test
Diffstat (limited to 'src/link')
-rw-r--r--src/link/Elf.zig10
-rw-r--r--src/link/Elf/thunks.zig2
2 files changed, 11 insertions, 1 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index d26f49ca09..ed6ffbcd08 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -4565,6 +4565,16 @@ fn writeAtoms(self: *Elf) !void {
try self.base.file.?.pwriteAll(buffer, sh_offset);
}
+ for (self.thunks.items) |th| {
+ const shdr = self.shdrs.items[th.output_section_index];
+ const offset = th.value + shdr.sh_offset;
+ const buffer = try gpa.alloc(u8, th.size(self));
+ defer gpa.free(buffer);
+ var stream = std.io.fixedBufferStream(buffer);
+ try th.write(self, stream.writer());
+ try self.base.file.?.pwriteAll(buffer, offset);
+ }
+
try self.reportUndefinedSymbols(&undefs);
if (has_reloc_errors) return error.FlushFailure;
diff --git a/src/link/Elf/thunks.zig b/src/link/Elf/thunks.zig
index 398a2acd93..586cbed236 100644
--- a/src/link/Elf/thunks.zig
+++ b/src/link/Elf/thunks.zig
@@ -103,7 +103,7 @@ pub const Thunk = struct {
}
pub fn write(thunk: Thunk, elf_file: *Elf, writer: anytype) !void {
- switch (elf_file.options.cpu_arch.?) {
+ switch (elf_file.getTarget().cpu.arch) {
.aarch64 => try aarch64.write(thunk, elf_file, writer),
.x86_64, .riscv64 => unreachable,
else => @panic("unhandled arch"),