| ... | ... | @@ -154,6 +154,7 @@ tentatives: std.AutoArrayHashMapUnmanaged(u32, void) = .{}, |
| 154 | 154 | locals_free_list: std.ArrayListUnmanaged(u32) = .{}, |
| 155 | 155 | globals_free_list: std.ArrayListUnmanaged(u32) = .{}, |
| 156 | 156 | |
| 157 | mh_execute_header_index: ?u32 = null, |
| 157 | 158 | dyld_stub_binder_index: ?u32 = null, |
| 158 | 159 | dyld_private_atom: ?*Atom = null, |
| 159 | 160 | stub_helper_preamble_atom: ?*Atom = null, |
| ... | ... | @@ -863,6 +864,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 863 | 864 | sect.offset = self.tlv_bss_file_offset; |
| 864 | 865 | } |
| 865 | 866 | |
| 867 | try self.createMhExecuteHeaderAtom(); |
| 866 | 868 | for (self.objects.items) |*object, object_id| { |
| 867 | 869 | if (object.analyzed) continue; |
| 868 | 870 | try self.resolveSymbolsInObject(@intCast(u16, object_id)); |
| ... | ... | @@ -2725,6 +2727,42 @@ fn resolveSymbolsInDylibs(self: *MachO) !void { |
| 2725 | 2727 | } |
| 2726 | 2728 | } |
| 2727 | 2729 | |
| 2730 | fn createMhExecuteHeaderAtom(self: *MachO) !void { |
| 2731 | if (self.mh_execute_header_index != null) return; |
| 2732 | |
| 2733 | const match: MatchingSection = .{ |
| 2734 | .seg = self.text_segment_cmd_index.?, |
| 2735 | .sect = self.text_section_index.?, |
| 2736 | }; |
| 2737 | const n_strx = try self.makeString("__mh_execute_header"); |
| 2738 | const local_sym_index = @intCast(u32, self.locals.items.len); |
| 2739 | var nlist = macho.nlist_64{ |
| 2740 | .n_strx = n_strx, |
| 2741 | .n_type = macho.N_SECT, |
| 2742 | .n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1), |
| 2743 | .n_desc = 0, |
| 2744 | .n_value = 0, |
| 2745 | }; |
| 2746 | try self.locals.append(self.base.allocator, nlist); |
| 2747 | |
| 2748 | nlist.n_type |= macho.N_EXT; |
| 2749 | const global_sym_index = @intCast(u32, self.globals.items.len); |
| 2750 | try self.globals.append(self.base.allocator, nlist); |
| 2751 | try self.symbol_resolver.putNoClobber(self.base.allocator, n_strx, .{ |
| 2752 | .where = .global, |
| 2753 | .where_index = global_sym_index, |
| 2754 | .local_sym_index = local_sym_index, |
| 2755 | .file = null, |
| 2756 | }); |
| 2757 | |
| 2758 | const atom = try self.createEmptyAtom(local_sym_index, 0, 0); |
| 2759 | const sym = &self.locals.items[local_sym_index]; |
| 2760 | const vaddr = try self.allocateAtom(atom, 0, 1, match); |
| 2761 | sym.n_value = vaddr; |
| 2762 | atom.dirty = false; |
| 2763 | self.mh_execute_header_index = local_sym_index; |
| 2764 | } |
| 2765 | |
| 2728 | 2766 | fn resolveDyldStubBinder(self: *MachO) !void { |
| 2729 | 2767 | if (self.dyld_stub_binder_index != null) return; |
| 2730 | 2768 | |