Commit ba710ec09d

Jakub Konka <kubkon@jakubkonka.com>
2023-08-30 20:34:16
macho: remove obsolete error.FailedToResolveRelocationTarget
1 parent 5144132
src/link/MachO/Archive.zig
@@ -128,7 +128,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
     defer allocator.free(symtab);
 
     reader.readNoEof(symtab) catch {
-        log.err("incomplete symbol table: expected symbol table of length 0x{x}", .{symtab_size});
+        log.debug("incomplete symbol table: expected symbol table of length 0x{x}", .{symtab_size});
         return error.MalformedArchive;
     };
 
@@ -137,7 +137,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
     defer allocator.free(strtab);
 
     reader.readNoEof(strtab) catch {
-        log.err("incomplete symbol table: expected string table of length 0x{x}", .{strtab_size});
+        log.debug("incomplete symbol table: expected string table of length 0x{x}", .{strtab_size});
         return error.MalformedArchive;
     };
 
src/link/MachO/Atom.zig
@@ -615,7 +615,7 @@ pub fn resolveRelocs(
     };
 }
 
-pub fn getRelocTargetAddress(macho_file: *MachO, target: SymbolWithLoc, is_tlv: bool) !u64 {
+pub fn getRelocTargetAddress(macho_file: *MachO, target: SymbolWithLoc, is_tlv: bool) u64 {
     const target_atom_index = getRelocTargetAtomIndex(macho_file, target) orelse {
         // If there is no atom for target, we still need to check for special, atom-less
         // symbols such as `___dso_handle`.
@@ -648,17 +648,13 @@ pub fn getRelocTargetAddress(macho_file: *MachO, target: SymbolWithLoc, is_tlv:
         // defined TLV template init section in the following order:
         // * wrt to __thread_data if defined, then
         // * wrt to __thread_bss
+        // TODO remember to check what the mechanism was prior to HAS_TLV_INITIALIZERS in earlier versions of macOS
         const sect_id: u16 = sect_id: {
             if (macho_file.thread_data_section_index) |i| {
                 break :sect_id i;
             } else if (macho_file.thread_bss_section_index) |i| {
                 break :sect_id i;
-            } else {
-                log.err("threadlocal variables present but no initializer sections found", .{});
-                log.err("  __thread_data not found", .{});
-                log.err("  __thread_bss not found", .{});
-                return error.FailedToResolveRelocationTarget;
-            }
+            } else break :base_address 0;
         };
         break :base_address macho_file.sections.items(.header)[sect_id].addr;
     } else 0;
@@ -744,7 +740,7 @@ fn resolveRelocsArm64(
                 const header = macho_file.sections.items(.header)[source_sym.n_sect - 1];
                 break :is_tlv header.type() == macho.S_THREAD_LOCAL_VARIABLES;
             };
-            break :blk try getRelocTargetAddress(macho_file, target, is_tlv);
+            break :blk getRelocTargetAddress(macho_file, target, is_tlv);
         };
 
         log.debug("    | source_addr = 0x{x}", .{source_addr});
@@ -1040,7 +1036,7 @@ fn resolveRelocsX86(
                 const header = macho_file.sections.items(.header)[source_sym.n_sect - 1];
                 break :is_tlv header.type() == macho.S_THREAD_LOCAL_VARIABLES;
             };
-            break :blk try getRelocTargetAddress(macho_file, target, is_tlv);
+            break :blk getRelocTargetAddress(macho_file, target, is_tlv);
         };
 
         log.debug("    | source_addr = 0x{x}", .{source_addr});
src/link/MachO/eh_frame.zig
@@ -347,7 +347,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
                             },
                             .ARM64_RELOC_UNSIGNED => {
                                 assert(rel.r_extern == 1);
-                                const target_addr = try Atom.getRelocTargetAddress(macho_file, target, false);
+                                const target_addr = Atom.getRelocTargetAddress(macho_file, target, false);
                                 const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr));
                                 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)));
                             },
src/link/MachO/thunks.zig
@@ -317,7 +317,7 @@ fn isReachable(
     const target_addr = if (Atom.relocRequiresGot(macho_file, rel))
         macho_file.getGotEntryAddress(target).?
     else
-        Atom.getRelocTargetAddress(macho_file, target, false) catch unreachable;
+        Atom.getRelocTargetAddress(macho_file, target, false);
     _ = Relocation.calcPcRelativeDisplacementArm64(source_addr, target_addr) catch
         return false;
 
src/link.zig
@@ -700,7 +700,6 @@ pub const File = struct {
         DllImportLibraryNotFound,
         ExpectedFuncType,
         FailedToEmit,
-        FailedToResolveRelocationTarget,
         FileSystem,
         FilesOpenedWithWrongFlags,
         FlushFailure,