authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-21 14:11:56+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-01-21 14:11:56+01:00
log02db9933a4a0a99836f33757932f07263945166a
treee50c82d038f70815f9f753071a91fcec85e17ebd
parent3dff040ca58effc5aaf1c7313a7baa28ec2ac6dd

macho: properly relocate target symbol address in __eh_frame


2 files changed, 12 insertions(+), 4 deletions(-)

src/link/MachO/eh_frame.zig+9-1
...@@ -159,6 +159,14 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {...@@ -159,6 +159,14 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void {
159 switch (cpu_arch) {159 switch (cpu_arch) {
160 .aarch64 => {}, // relocs take care of LSDA pointers160 .aarch64 => {}, // relocs take care of LSDA pointers
161 .x86_64 => {161 .x86_64 => {
162 // We need to relocate target symbol address ourselves.
163 const atom = zld.getAtom(atom_index);
164 const atom_sym = zld.getSymbol(atom.getSymbolWithLoc());
165 try fde_record.setTargetSymbolAddress(atom_sym.n_value, .{
166 .base_addr = sect.addr,
167 .base_offset = eh_frame_offset,
168 });
169
162 // We need to parse LSDA pointer and relocate ourselves.170 // We need to parse LSDA pointer and relocate ourselves.
163 const cie_record = eh_records.get(171 const cie_record = eh_records.get(
164 eh_frame_offset + 4 - fde_record.getCiePointer(),172 eh_frame_offset + 4 - fde_record.getCiePointer(),
...@@ -267,7 +275,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {...@@ -267,7 +275,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
267 }) !void {275 }) !void {
268 assert(rec.tag == .fde);276 assert(rec.tag == .fde);
269 const addend = @intCast(i64, value) - @intCast(i64, ctx.base_addr + ctx.base_offset + 8);277 const addend = @intCast(i64, value) - @intCast(i64, ctx.base_addr + ctx.base_offset + 8);
270 mem.writeIntLittle(i64, addend, rec.data[4..][0..8]);278 mem.writeIntLittle(i64, rec.data[4..][0..8], addend);
271 }279 }
272280
273 pub fn getPersonalityPointerReloc(281 pub fn getPersonalityPointerReloc(
test/link/macho/uuid/build.zig+3-3
...@@ -21,9 +21,9 @@ pub fn build(b: *Builder) void {...@@ -21,9 +21,9 @@ pub fn build(b: *Builder) void {
21 .os_tag = .macos,21 .os_tag = .macos,
22 };22 };
2323
24 testUuid(b, test_step, .ReleaseSafe, x86_64_macos, "63f47191c7153f5fba48bd63cb2f5f57");24 testUuid(b, test_step, .ReleaseSafe, x86_64_macos, "5b7071b4587c3071b0d2352fadce0e48");
25 testUuid(b, test_step, .ReleaseFast, x86_64_macos, "63f47191c7153f5fba48bd63cb2f5f57");25 testUuid(b, test_step, .ReleaseFast, x86_64_macos, "5b7071b4587c3071b0d2352fadce0e48");
26 testUuid(b, test_step, .ReleaseSmall, x86_64_macos, "e7bba66220e33eda9e73ab293ccf93d2");26 testUuid(b, test_step, .ReleaseSmall, x86_64_macos, "4b58f2583c383169bbe3a716bd240048");
27}27}
2828
29fn testUuid(29fn testUuid(