authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-09 19:59:43+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
log882ff3ae31a39edf23db00b558db60ee574d9859
tree85945b14ab7ba5151d4da5fa3ba84560726b263a
parentb96339f6f6ed368d04639c1d6c67eb85c5eb3c7b

macho: migrate eh_frame module


1 files changed, 11 insertions(+), 6 deletions(-)

src/link/MachO/eh_frame.zig+11-6
......@@ -68,7 +68,8 @@ pub const Cie = struct {
6868
6969 pub fn getPersonality(cie: Cie, macho_file: *MachO) ?*Symbol {
7070 const personality = cie.personality orelse return null;
71 return macho_file.getSymbol(personality.index);
71 const object = cie.getObject(macho_file);
72 return object.getSymbolRef(personality.index, macho_file).getSymbol(macho_file);
7273 }
7374
7475 pub fn eql(cie: Cie, other: Cie, macho_file: *MachO) bool {
......@@ -223,11 +224,11 @@ pub const Fde = struct {
223224 }
224225
225226 pub fn getAtom(fde: Fde, macho_file: *MachO) *Atom {
226 return macho_file.getAtom(fde.atom).?;
227 return fde.getObject(macho_file).getAtom(fde.atom).?;
227228 }
228229
229230 pub fn getLsdaAtom(fde: Fde, macho_file: *MachO) ?*Atom {
230 return macho_file.getAtom(fde.lsda);
231 return fde.getObject(macho_file).getAtom(fde.lsda);
231232 }
232233
233234 pub fn format(
......@@ -448,7 +449,7 @@ pub fn write(macho_file: *MachO, buffer: []u8) void {
448449 }
449450}
450451
451pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: *std.ArrayList(macho.relocation_info)) error{Overflow}!void {
452pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: []macho.relocation_info) error{Overflow}!void {
452453 const tracy = trace(@src());
453454 defer tracy.end();
454455
......@@ -459,6 +460,7 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: *std.ArrayList(macho.
459460 else => 0,
460461 };
461462
463 var i: usize = 0;
462464 for (macho_file.objects.items) |index| {
463465 const object = macho_file.getFile(index).?.object;
464466 for (object.cies.items) |cie| {
......@@ -469,7 +471,7 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: *std.ArrayList(macho.
469471 if (cie.getPersonality(macho_file)) |sym| {
470472 const r_address = math.cast(i32, cie.out_offset + cie.personality.?.offset) orelse return error.Overflow;
471473 const r_symbolnum = math.cast(u24, sym.getOutputSymtabIndex(macho_file).?) orelse return error.Overflow;
472 relocs.appendAssumeCapacity(.{
474 relocs[i] = .{
473475 .r_address = r_address,
474476 .r_symbolnum = r_symbolnum,
475477 .r_length = 2,
......@@ -480,7 +482,8 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: *std.ArrayList(macho.
480482 .x86_64 => @intFromEnum(macho.reloc_type_x86_64.X86_64_RELOC_GOT),
481483 else => unreachable,
482484 },
483 });
485 };
486 i += 1;
484487 }
485488 }
486489 }
......@@ -531,6 +534,8 @@ pub fn writeRelocs(macho_file: *MachO, code: []u8, relocs: *std.ArrayList(macho.
531534 }
532535 }
533536 }
537
538 assert(relocs.len == i);
534539}
535540
536541pub const EH_PE = struct {