aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-01-21 14:11:56 +0100
committerJakub Konka <kubkon@jakubkonka.com>2023-01-21 14:11:56 +0100
commit02db9933a4a0a99836f33757932f07263945166a (patch)
treee50c82d038f70815f9f753071a91fcec85e17ebd /src/link
parent3dff040ca58effc5aaf1c7313a7baa28ec2ac6dd (diff)
downloadzig-02db9933a4a0a99836f33757932f07263945166a.tar.gz
zig-02db9933a4a0a99836f33757932f07263945166a.zip
macho: properly relocate target symbol address in __eh_frame
Diffstat (limited to 'src/link')
-rw-r--r--src/link/MachO/eh_frame.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/link/MachO/eh_frame.zig b/src/link/MachO/eh_frame.zig
index bc11766953..8345a8e4f3 100644
--- a/src/link/MachO/eh_frame.zig
+++ b/src/link/MachO/eh_frame.zig
@@ -159,6 +159,14 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
switch (cpu_arch) {
.aarch64 => {}, // relocs take care of LSDA pointers
.x86_64 => {
+ // We need to relocate target symbol address ourselves.
+ const atom = zld.getAtom(atom_index);
+ const atom_sym = zld.getSymbol(atom.getSymbolWithLoc());
+ try fde_record.setTargetSymbolAddress(atom_sym.n_value, .{
+ .base_addr = sect.addr,
+ .base_offset = eh_frame_offset,
+ });
+
// We need to parse LSDA pointer and relocate ourselves.
const cie_record = eh_records.get(
eh_frame_offset + 4 - fde_record.getCiePointer(),
@@ -267,7 +275,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
}) !void {
assert(rec.tag == .fde);
const addend = @intCast(i64, value) - @intCast(i64, ctx.base_addr + ctx.base_offset + 8);
- mem.writeIntLittle(i64, addend, rec.data[4..][0..8]);
+ mem.writeIntLittle(i64, rec.data[4..][0..8], addend);
}
pub fn getPersonalityPointerReloc(