authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-30 20:34:16+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-30 20:34:16+02:00
logba710ec09dd3df4cd0ee8de9a5299aeaed53a847
tree99e2e5aa645ea7d73c5beae28bdb3b7cf4947af3
parent5144132320ae86320e9a6bf335bfbdccf52e2621

macho: remove obsolete error.FailedToResolveRelocationTarget


5 files changed, 9 insertions(+), 14 deletions(-)

src/link.zig-1
......@@ -700,7 +700,6 @@ pub const File = struct {
700700 DllImportLibraryNotFound,
701701 ExpectedFuncType,
702702 FailedToEmit,
703 FailedToResolveRelocationTarget,
704703 FileSystem,
705704 FilesOpenedWithWrongFlags,
706705 FlushFailure,
src/link/MachO/Archive.zig+2-2
......@@ -128,7 +128,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
128128 defer allocator.free(symtab);
129129
130130 reader.readNoEof(symtab) catch {
131 log.err("incomplete symbol table: expected symbol table of length 0x{x}", .{symtab_size});
131 log.debug("incomplete symbol table: expected symbol table of length 0x{x}", .{symtab_size});
132132 return error.MalformedArchive;
133133 };
134134
......@@ -137,7 +137,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
137137 defer allocator.free(strtab);
138138
139139 reader.readNoEof(strtab) catch {
140 log.err("incomplete symbol table: expected string table of length 0x{x}", .{strtab_size});
140 log.debug("incomplete symbol table: expected string table of length 0x{x}", .{strtab_size});
141141 return error.MalformedArchive;
142142 };
143143
src/link/MachO/Atom.zig+5-9
......@@ -615,7 +615,7 @@ pub fn resolveRelocs(
615615 };
616616}
617617
618pub fn getRelocTargetAddress(macho_file: *MachO, target: SymbolWithLoc, is_tlv: bool) !u64 {
618pub fn getRelocTargetAddress(macho_file: *MachO, target: SymbolWithLoc, is_tlv: bool) u64 {
619619 const target_atom_index = getRelocTargetAtomIndex(macho_file, target) orelse {
620620 // If there is no atom for target, we still need to check for special, atom-less
621621 // symbols such as `___dso_handle`.
......@@ -648,17 +648,13 @@ pub fn getRelocTargetAddress(macho_file: *MachO, target: SymbolWithLoc, is_tlv:
648648 // defined TLV template init section in the following order:
649649 // * wrt to __thread_data if defined, then
650650 // * wrt to __thread_bss
651 // TODO remember to check what the mechanism was prior to HAS_TLV_INITIALIZERS in earlier versions of macOS
651652 const sect_id: u16 = sect_id: {
652653 if (macho_file.thread_data_section_index) |i| {
653654 break :sect_id i;
654655 } else if (macho_file.thread_bss_section_index) |i| {
655656 break :sect_id i;
656 } else {
657 log.err("threadlocal variables present but no initializer sections found", .{});
658 log.err(" __thread_data not found", .{});
659 log.err(" __thread_bss not found", .{});
660 return error.FailedToResolveRelocationTarget;
661 }
657 } else break :base_address 0;
662658 };
663659 break :base_address macho_file.sections.items(.header)[sect_id].addr;
664660 } else 0;
......@@ -744,7 +740,7 @@ fn resolveRelocsArm64(
744740 const header = macho_file.sections.items(.header)[source_sym.n_sect - 1];
745741 break :is_tlv header.type() == macho.S_THREAD_LOCAL_VARIABLES;
746742 };
747 break :blk try getRelocTargetAddress(macho_file, target, is_tlv);
743 break :blk getRelocTargetAddress(macho_file, target, is_tlv);
748744 };
749745
750746 log.debug(" | source_addr = 0x{x}", .{source_addr});
......@@ -1040,7 +1036,7 @@ fn resolveRelocsX86(
10401036 const header = macho_file.sections.items(.header)[source_sym.n_sect - 1];
10411037 break :is_tlv header.type() == macho.S_THREAD_LOCAL_VARIABLES;
10421038 };
1043 break :blk try getRelocTargetAddress(macho_file, target, is_tlv);
1039 break :blk getRelocTargetAddress(macho_file, target, is_tlv);
10441040 };
10451041
10461042 log.debug(" | source_addr = 0x{x}", .{source_addr});
src/link/MachO/eh_frame.zig+1-1
......@@ -347,7 +347,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
347347 },
348348 .ARM64_RELOC_UNSIGNED => {
349349 assert(rel.r_extern == 1);
350 const target_addr = try Atom.getRelocTargetAddress(macho_file, target, false);
350 const target_addr = Atom.getRelocTargetAddress(macho_file, target, false);
351351 const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr));
352352 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)));
353353 },
src/link/MachO/thunks.zig+1-1
......@@ -317,7 +317,7 @@ fn isReachable(
317317 const target_addr = if (Atom.relocRequiresGot(macho_file, rel))
318318 macho_file.getGotEntryAddress(target).?
319319 else
320 Atom.getRelocTargetAddress(macho_file, target, false) catch unreachable;
320 Atom.getRelocTargetAddress(macho_file, target, false);
321321 _ = Relocation.calcPcRelativeDisplacementArm64(source_addr, target_addr) catch
322322 return false;
323323