| ... | ... | @@ -167,6 +167,7 @@ pub fn createAtomForDecl(self: *ZigObject, allocator: Allocator, macho_file: *Ma |
| 167 | 167 | relocs.* = .{}; |
| 168 | 168 | const atom = self.getAtom(atom_index).?; |
| 169 | 169 | atom.addExtra(.{ .rel_index = relocs_index, .rel_count = 0 }, macho_file); |
| 170 | try self.globals.append(allocator, 0); |
| 170 | 171 | return symbol_index; |
| 171 | 172 | } |
| 172 | 173 | |
| ... | ... | @@ -1315,22 +1316,30 @@ pub fn updateExports( |
| 1315 | 1316 | break :blk global_nlist_index; |
| 1316 | 1317 | }; |
| 1317 | 1318 | const global_nlist = &self.symtab.items(.nlist)[global_nlist_index]; |
| 1319 | const atom_index = self.symtab.items(.atom)[nlist_idx]; |
| 1320 | const global_sym = &self.symbols.items[global_nlist_index]; |
| 1318 | 1321 | global_nlist.n_value = nlist.n_value; |
| 1319 | 1322 | global_nlist.n_sect = nlist.n_sect; |
| 1320 | 1323 | global_nlist.n_type = macho.N_EXT | macho.N_SECT; |
| 1321 | 1324 | self.symtab.items(.size)[global_nlist_index] = self.symtab.items(.size)[nlist_idx]; |
| 1322 | | self.symtab.items(.atom)[global_nlist_index] = self.symtab.items(.atom)[nlist_idx]; |
| 1325 | self.symtab.items(.atom)[global_nlist_index] = atom_index; |
| 1326 | global_sym.atom_ref = .{ .index = atom_index, .file = self.index }; |
| 1323 | 1327 | |
| 1324 | 1328 | switch (exp.opts.linkage) { |
| 1325 | 1329 | .internal => { |
| 1326 | 1330 | // Symbol should be hidden, or in MachO lingo, private extern. |
| 1327 | 1331 | global_nlist.n_type |= macho.N_PEXT; |
| 1332 | global_sym.visibility = .hidden; |
| 1333 | }, |
| 1334 | .strong => { |
| 1335 | global_sym.visibility = .global; |
| 1328 | 1336 | }, |
| 1329 | | .strong => {}, |
| 1330 | 1337 | .weak => { |
| 1331 | 1338 | // Weak linkage is specified as part of n_desc field. |
| 1332 | 1339 | // Symbol's n_type is like for a symbol with strong linkage. |
| 1333 | 1340 | global_nlist.n_desc |= macho.N_WEAK_DEF; |
| 1341 | global_sym.visibility = .global; |
| 1342 | global_sym.flags.weak = true; |
| 1334 | 1343 | }, |
| 1335 | 1344 | else => unreachable, |
| 1336 | 1345 | } |
| ... | ... | @@ -1460,16 +1469,17 @@ pub fn getGlobalSymbol(self: *ZigObject, macho_file: *MachO, name: []const u8, l |
| 1460 | 1469 | const off = try self.strtab.insert(gpa, sym_name); |
| 1461 | 1470 | const lookup_gop = try self.globals_lookup.getOrPut(gpa, off); |
| 1462 | 1471 | if (!lookup_gop.found_existing) { |
| 1472 | const sym_index = try self.addSymbol(gpa); |
| 1473 | const sym = &self.symbols.items[sym_index]; |
| 1463 | 1474 | const nlist_index = try self.addNlist(gpa); |
| 1464 | 1475 | const nlist = &self.symtab.items(.nlist)[nlist_index]; |
| 1465 | 1476 | nlist.n_strx = off; |
| 1466 | 1477 | nlist.n_type = macho.N_EXT; |
| 1478 | sym.name = off; |
| 1479 | sym.nlist_idx = nlist_index; |
| 1480 | sym.extra = try self.addSymbolExtra(gpa, .{}); |
| 1467 | 1481 | lookup_gop.value_ptr.* = nlist_index; |
| 1468 | | _ = try macho_file.resolver.getOrPut(gpa, .{ |
| 1469 | | .index = nlist_index, |
| 1470 | | .file = self.index, |
| 1471 | | }, macho_file); |
| 1472 | | try self.globals.append(gpa, nlist_index); |
| 1482 | try self.globals.append(gpa, 0); |
| 1473 | 1483 | } |
| 1474 | 1484 | return lookup_gop.value_ptr.*; |
| 1475 | 1485 | } |
| ... | ... | @@ -1692,7 +1702,7 @@ fn formatSymtab( |
| 1692 | 1702 | try writer.writeAll(" symbols\n"); |
| 1693 | 1703 | const self = ctx.self; |
| 1694 | 1704 | const macho_file = ctx.macho_file; |
| 1695 | | for (self.symbols.items, 0) |sym, i| { |
| 1705 | for (self.symbols.items, 0..) |sym, i| { |
| 1696 | 1706 | const ref = self.getSymbolRef(@intCast(i), macho_file); |
| 1697 | 1707 | if (ref.getFile(macho_file) == null) { |
| 1698 | 1708 | // TODO any better way of handling this? |