macho: properly relocate target symbol address in __eh_frame

This commit is contained in:
Jakub Konka 2023-01-21 14:11:56 +01:00
parent 3dff040ca5
commit 02db9933a4
2 changed files with 12 additions and 4 deletions

View File

@ -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(

View File

@ -21,9 +21,9 @@ pub fn build(b: *Builder) void {
.os_tag = .macos,
};
testUuid(b, test_step, .ReleaseSafe, x86_64_macos, "63f47191c7153f5fba48bd63cb2f5f57");
testUuid(b, test_step, .ReleaseFast, x86_64_macos, "63f47191c7153f5fba48bd63cb2f5f57");
testUuid(b, test_step, .ReleaseSmall, x86_64_macos, "e7bba66220e33eda9e73ab293ccf93d2");
testUuid(b, test_step, .ReleaseSafe, x86_64_macos, "5b7071b4587c3071b0d2352fadce0e48");
testUuid(b, test_step, .ReleaseFast, x86_64_macos, "5b7071b4587c3071b0d2352fadce0e48");
testUuid(b, test_step, .ReleaseSmall, x86_64_macos, "4b58f2583c383169bbe3a716bd240048");
}
fn testUuid(