| author | |
| committer | |
| log | 6b617afe2a3904ad3d5c9e3542a30bd7f35ed54e |
| tree | 823e1748d5e8e763e5ce78fc96c396b3a77bcd76 |
| parent | 8a1311733b313a59afa2ea354ca9b342a935d869 |
2 files changed, 54 insertions(+), 6 deletions(-)
src/link/MachO.zig+48| ... | ... | @@ -498,6 +498,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node |
| 498 | 498 | |
| 499 | 499 | try self.addUndefinedGlobals(); |
| 500 | 500 | try self.resolveSymbols(); |
| 501 | try self.resolveSyntheticSymbols(); | |
| 501 | 502 | |
| 502 | 503 | state_log.debug("{}", .{self.dumpState()}); |
| 503 | 504 | |
| ... | ... | @@ -1215,6 +1216,53 @@ fn markLive(self: *MachO) void { |
| 1215 | 1216 | } |
| 1216 | 1217 | } |
| 1217 | 1218 | |
| 1219 | fn resolveSyntheticSymbols(self: *MachO) !void { | |
| 1220 | const internal = self.getInternalObject() orelse return; | |
| 1221 | ||
| 1222 | if (!self.base.isDynLib()) { | |
| 1223 | self.mh_execute_header_index = try internal.addSymbol("__mh_execute_header", self); | |
| 1224 | const sym = self.getSymbol(self.mh_execute_header_index.?); | |
| 1225 | sym.flags.@"export" = true; | |
| 1226 | sym.flags.dyn_ref = true; | |
| 1227 | sym.visibility = .global; | |
| 1228 | } else { | |
| 1229 | self.mh_dylib_header_index = try internal.addSymbol("__mh_dylib_header", self); | |
| 1230 | } | |
| 1231 | ||
| 1232 | self.dso_handle_index = try internal.addSymbol("___dso_handle", self); | |
| 1233 | self.dyld_private_index = try internal.addSymbol("dyld_private", self); | |
| 1234 | ||
| 1235 | { | |
| 1236 | const gpa = self.base.comp.gpa; | |
| 1237 | var boundary_symbols = std.AutoHashMap(Symbol.Index, void).init(gpa); | |
| 1238 | defer boundary_symbols.deinit(); | |
| 1239 | ||
| 1240 | for (self.objects.items) |index| { | |
| 1241 | const object = self.getFile(index).?.object; | |
| 1242 | for (object.symbols.items, 0..) |sym_index, i| { | |
| 1243 | const nlist = object.symtab.items(.nlist)[i]; | |
| 1244 | const name = self.getSymbol(sym_index).getName(self); | |
| 1245 | if (!nlist.undf() or !nlist.ext()) continue; | |
| 1246 | if (mem.startsWith(u8, name, "segment$start$") or | |
| 1247 | mem.startsWith(u8, name, "segment$stop$") or | |
| 1248 | mem.startsWith(u8, name, "section$start$") or | |
| 1249 | mem.startsWith(u8, name, "section$stop$")) | |
| 1250 | { | |
| 1251 | _ = try boundary_symbols.put(sym_index, {}); | |
| 1252 | } | |
| 1253 | } | |
| 1254 | } | |
| 1255 | ||
| 1256 | try self.boundary_symbols.ensureTotalCapacityPrecise(gpa, boundary_symbols.count()); | |
| 1257 | ||
| 1258 | var it = boundary_symbols.iterator(); | |
| 1259 | while (it.next()) |entry| { | |
| 1260 | _ = try internal.addSymbol(self.getSymbol(entry.key_ptr.*).getName(self), self); | |
| 1261 | self.boundary_symbols.appendAssumeCapacity(entry.key_ptr.*); | |
| 1262 | } | |
| 1263 | } | |
| 1264 | } | |
| 1265 | ||
| 1218 | 1266 | fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void { |
| 1219 | 1267 | _ = self; |
| 1220 | 1268 | _ = atom_index; |
src/link/MachO/InternalObject.zig+6-6| ... | ... | @@ -20,9 +20,9 @@ pub fn deinit(self: *InternalObject, allocator: Allocator) void { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | pub fn addSymbol(self: *InternalObject, name: [:0]const u8, macho_file: *MachO) !Symbol.Index { |
| 23 | const gpa = macho_file.base.allocator; | |
| 23 | const gpa = macho_file.base.comp.gpa; | |
| 24 | 24 | try self.symbols.ensureUnusedCapacity(gpa, 1); |
| 25 | const off = try macho_file.string_intern.insert(gpa, name); | |
| 25 | const off = try macho_file.strings.insert(gpa, name); | |
| 26 | 26 | const gop = try macho_file.getOrCreateGlobal(off); |
| 27 | 27 | self.symbols.addOneAssumeCapacity().* = gop.index; |
| 28 | 28 | const sym = macho_file.getSymbol(gop.index); |
| ... | ... | @@ -37,7 +37,7 @@ pub fn addObjcMsgsendSections(self: *InternalObject, sym_name: []const u8, macho |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_file: *MachO) !Atom.Index { |
| 40 | const gpa = macho_file.base.allocator; | |
| 40 | const gpa = macho_file.base.comp.gpa; | |
| 41 | 41 | const atom_index = try macho_file.addAtom(); |
| 42 | 42 | try self.atoms.append(gpa, atom_index); |
| 43 | 43 | |
| ... | ... | @@ -45,7 +45,7 @@ fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_fil |
| 45 | 45 | defer gpa.free(name); |
| 46 | 46 | const atom = macho_file.getAtom(atom_index).?; |
| 47 | 47 | atom.atom_index = atom_index; |
| 48 | atom.name = try macho_file.string_intern.insert(gpa, name); | |
| 48 | atom.name = try macho_file.strings.insert(gpa, name); | |
| 49 | 49 | atom.file = self.index; |
| 50 | 50 | atom.size = methname.len + 1; |
| 51 | 51 | atom.alignment = 0; |
| ... | ... | @@ -71,7 +71,7 @@ fn addObjcSelrefsSection( |
| 71 | 71 | methname_atom_index: Atom.Index, |
| 72 | 72 | macho_file: *MachO, |
| 73 | 73 | ) !Atom.Index { |
| 74 | const gpa = macho_file.base.allocator; | |
| 74 | const gpa = macho_file.base.comp.gpa; | |
| 75 | 75 | const atom_index = try macho_file.addAtom(); |
| 76 | 76 | try self.atoms.append(gpa, atom_index); |
| 77 | 77 | |
| ... | ... | @@ -79,7 +79,7 @@ fn addObjcSelrefsSection( |
| 79 | 79 | defer gpa.free(name); |
| 80 | 80 | const atom = macho_file.getAtom(atom_index).?; |
| 81 | 81 | atom.atom_index = atom_index; |
| 82 | atom.name = try macho_file.string_intern.insert(gpa, name); | |
| 82 | atom.name = try macho_file.strings.insert(gpa, name); | |
| 83 | 83 | atom.file = self.index; |
| 84 | 84 | atom.size = @sizeOf(u64); |
| 85 | 85 | atom.alignment = 3; |