| ... | @@ -3047,6 +3047,9 @@ fn createMhExecuteHeaderAtom(self: *MachO) !void { | ... | @@ -3047,6 +3047,9 @@ fn createMhExecuteHeaderAtom(self: *MachO) !void { |
| 3047 | .seg = self.text_segment_cmd_index.?, | 3047 | .seg = self.text_segment_cmd_index.?, |
| 3048 | .sect = self.text_section_index.?, | 3048 | .sect = self.text_section_index.?, |
| 3049 | }; | 3049 | }; |
| | 3050 | const seg = self.load_commands.items[match.seg].segment; |
| | 3051 | const sect = seg.sections.items[match.sect]; |
| | 3052 | |
| 3050 | const n_strx = try self.makeString("__mh_execute_header"); | 3053 | const n_strx = try self.makeString("__mh_execute_header"); |
| 3051 | const local_sym_index = @intCast(u32, self.locals.items.len); | 3054 | const local_sym_index = @intCast(u32, self.locals.items.len); |
| 3052 | var nlist = macho.nlist_64{ | 3055 | var nlist = macho.nlist_64{ |
| ... | @@ -3054,29 +3057,42 @@ fn createMhExecuteHeaderAtom(self: *MachO) !void { | ... | @@ -3054,29 +3057,42 @@ fn createMhExecuteHeaderAtom(self: *MachO) !void { |
| 3054 | .n_type = macho.N_SECT, | 3057 | .n_type = macho.N_SECT, |
| 3055 | .n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1), | 3058 | .n_sect = @intCast(u8, self.section_ordinals.getIndex(match).? + 1), |
| 3056 | .n_desc = 0, | 3059 | .n_desc = 0, |
| 3057 | .n_value = 0, | 3060 | .n_value = sect.addr, |
| 3058 | }; | 3061 | }; |
| 3059 | try self.locals.append(self.base.allocator, nlist); | 3062 | try self.locals.append(self.base.allocator, nlist); |
| | 3063 | self.mh_execute_header_index = local_sym_index; |
| 3060 | | 3064 | |
| 3061 | nlist.n_type |= macho.N_EXT; | 3065 | if (self.symbol_resolver.getPtr(n_strx)) |resolv| { |
| 3062 | const global_sym_index = @intCast(u32, self.globals.items.len); | 3066 | const global = &self.globals.items[resolv.where_index]; |
| 3063 | try self.globals.append(self.base.allocator, nlist); | 3067 | if (!(global.weakDef() or !global.pext())) { |
| 3064 | try self.symbol_resolver.putNoClobber(self.base.allocator, n_strx, .{ | 3068 | log.err("symbol '__mh_execute_header' defined multiple times", .{}); |
| 3065 | .where = .global, | 3069 | return error.MultipleSymbolDefinitions; |
| 3066 | .where_index = global_sym_index, | 3070 | } |
| 3067 | .local_sym_index = local_sym_index, | 3071 | resolv.local_sym_index = local_sym_index; |
| 3068 | .file = null, | 3072 | } else { |
| 3069 | }); | 3073 | const global_sym_index = @intCast(u32, self.globals.items.len); |
| | 3074 | nlist.n_type |= macho.N_EXT; |
| | 3075 | try self.globals.append(self.base.allocator, nlist); |
| | 3076 | try self.symbol_resolver.putNoClobber(self.base.allocator, n_strx, .{ |
| | 3077 | .where = .global, |
| | 3078 | .where_index = global_sym_index, |
| | 3079 | .local_sym_index = local_sym_index, |
| | 3080 | .file = null, |
| | 3081 | }); |
| | 3082 | } |
| 3070 | | 3083 | |
| | 3084 | // We always set the __mh_execute_header to point to the beginning of the __TEXT,__text section |
| 3071 | const atom = try self.createEmptyAtom(local_sym_index, 0, 0); | 3085 | const atom = try self.createEmptyAtom(local_sym_index, 0, 0); |
| 3072 | | 3086 | if (self.atoms.get(match)) |last| { |
| 3073 | if (self.needs_prealloc) { | 3087 | var first = last; |
| 3074 | const sym = &self.locals.items[local_sym_index]; | 3088 | while (first.prev) |prev| { |
| 3075 | const vaddr = try self.allocateAtom(atom, 0, 1, match); | 3089 | first = prev; |
| 3076 | sym.n_value = vaddr; | 3090 | } |
| 3077 | } else try self.addAtomToSection(atom, match); | 3091 | atom.next = first; |
| 3078 | | 3092 | first.prev = atom; |
| 3079 | self.mh_execute_header_index = local_sym_index; | 3093 | } else { |
| | 3094 | try self.atoms.putNoClobber(self.base.allocator, match, atom); |
| | 3095 | } |
| 3080 | } | 3096 | } |
| 3081 | | 3097 | |
| 3082 | fn resolveDyldStubBinder(self: *MachO) !void { | 3098 | fn resolveDyldStubBinder(self: *MachO) !void { |