Commit 5b9eaf2938

Jakub Konka <kubkon@jakubkonka.com>
2022-10-19 18:14:38
macho: do not assume __la_symbol_ptr was created
1 parent 33d1942
Changed files (2)
src
src/link/MachO/Object.zig
@@ -287,7 +287,7 @@ pub fn splitIntoAtoms(self: *Object, zld: *Zld, object_id: u31) !void {
     for (sections) |sect, id| {
         if (sect.isDebug()) continue;
         const out_sect_id = (try zld.getOutputSection(sect)) orelse {
-            log.debug("  unhandled section", .{});
+            log.debug("  unhandled section '{s},{s}'", .{ sect.segName(), sect.sectName() });
             continue;
         };
         if (sect.size == 0) continue;
@@ -306,10 +306,7 @@ pub fn splitIntoAtoms(self: *Object, zld: *Zld, object_id: u31) !void {
     if (self.in_symtab == null) {
         for (sections) |sect, id| {
             if (sect.isDebug()) continue;
-            const out_sect_id = (try zld.getOutputSection(sect)) orelse {
-                log.debug("  unhandled section", .{});
-                continue;
-            };
+            const out_sect_id = (try zld.getOutputSection(sect)) orelse continue;
             if (sect.size == 0) continue;
 
             const sect_id = @intCast(u8, id);
@@ -367,10 +364,7 @@ pub fn splitIntoAtoms(self: *Object, zld: *Zld, object_id: u31) !void {
         log.debug("splitting section '{s},{s}' into atoms", .{ sect.segName(), sect.sectName() });
 
         // Get output segment/section in the final artifact.
-        const out_sect_id = (try zld.getOutputSection(sect)) orelse {
-            log.debug("  unhandled section", .{});
-            continue;
-        };
+        const out_sect_id = (try zld.getOutputSection(sect)) orelse continue;
 
         log.debug("  output sect({d}, '{s},{s}')", .{
             out_sect_id + 1,
src/link/MachO/zld.zig
@@ -2527,6 +2527,8 @@ pub const Zld = struct {
         const gpa = self.gpa;
 
         const stub_helper_section_index = self.getSectionByName("__TEXT", "__stub_helper") orelse return;
+        const la_symbol_ptr_section_index = self.getSectionByName("__DATA", "__la_symbol_ptr") orelse return;
+
         if (self.stub_helper_preamble_sym_index == null) return;
 
         const section = self.sections.get(stub_helper_section_index);
@@ -2537,7 +2539,6 @@ pub const Zld = struct {
 
         {
             var stub_atom_index = last_atom_index;
-            const la_symbol_ptr_section_index = self.getSectionByName("__DATA", "__la_symbol_ptr").?;
             var laptr_atom_index = self.sections.items(.last_atom_index)[la_symbol_ptr_section_index];
 
             const base_addr = blk: {