Commit f2dce0c337

Jakub Konka <kubkon@jakubkonka.com>
2024-01-22 18:54:00
macho: exclude symbols from empty sections when parsing unwind info
1 parent 82628dd
Changed files (1)
src
link
src/link/MachO/Object.zig
@@ -156,10 +156,12 @@ pub fn parse(self: *Object, macho_file: *MachO) !void {
     try self.initSymbolStabs(nlists.items, macho_file);
     try self.initRelocs(macho_file);
 
+    // Parse DWARF __TEXT,__eh_frame section
     if (self.eh_frame_sect_index) |index| {
         try self.initEhFrameRecords(index, macho_file);
     }
 
+    // Parse Apple's __LD,__compact_unwind section
     if (self.compact_unwind_sect_index) |index| {
         try self.initUnwindRecords(index, macho_file);
     }
@@ -841,7 +843,7 @@ fn parseUnwindRecords(self: *Object, macho_file: *MachO) !void {
         if (nlist.stab()) continue;
         if (!nlist.sect()) continue;
         const sect = self.sections.items(.header)[nlist.n_sect - 1];
-        if (sect.isCode()) {
+        if (sect.isCode() and sect.size > 0) {
             try superposition.ensureUnusedCapacity(1);
             const gop = superposition.getOrPutAssumeCapacity(nlist.n_value);
             if (gop.found_existing) {