| ... | @@ -137,9 +137,60 @@ pub fn freeAtomRelocs(self: *ZigObject, atom: Atom) void { | ... | @@ -137,9 +137,60 @@ pub fn freeAtomRelocs(self: *ZigObject, atom: Atom) void { |
| 137 | } | 137 | } |
| 138 | | 138 | |
| 139 | pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) void { | 139 | pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) void { |
| 140 | _ = self; | 140 | const tracy = trace(@src()); |
| 141 | _ = macho_file; | 141 | defer tracy.end(); |
| 142 | @panic("TODO resolveSymbols"); | 142 | |
| | 143 | for (self.symbols.items, 0..) |index, i| { |
| | 144 | const nlist_idx = @as(Symbol.Index, @intCast(i)); |
| | 145 | const nlist = self.symtab.items(.nlist)[nlist_idx]; |
| | 146 | const atom_index = self.symtab.items(.atom)[nlist_idx]; |
| | 147 | |
| | 148 | if (!nlist.ext()) continue; |
| | 149 | if (nlist.undf() and !nlist.tentative()) continue; |
| | 150 | if (nlist.sect()) { |
| | 151 | const atom = macho_file.getAtom(atom_index).?; |
| | 152 | if (!atom.flags.alive) continue; |
| | 153 | } |
| | 154 | |
| | 155 | const symbol = macho_file.getSymbol(index); |
| | 156 | if (self.asFile().getSymbolRank(.{ |
| | 157 | .archive = false, |
| | 158 | .weak = nlist.weakDef(), |
| | 159 | .tentative = nlist.tentative(), |
| | 160 | }) < symbol.getSymbolRank(macho_file)) { |
| | 161 | const value = if (nlist.sect()) blk: { |
| | 162 | const atom = macho_file.getAtom(atom_index).?; |
| | 163 | break :blk nlist.n_value - atom.getInputAddress(macho_file); |
| | 164 | } else nlist.n_value; |
| | 165 | symbol.value = value; |
| | 166 | symbol.atom = atom_index; |
| | 167 | symbol.nlist_idx = nlist_idx; |
| | 168 | symbol.file = self.index; |
| | 169 | symbol.flags.weak = nlist.weakDef(); |
| | 170 | symbol.flags.abs = nlist.abs(); |
| | 171 | symbol.flags.tentative = nlist.tentative(); |
| | 172 | symbol.flags.weak_ref = false; |
| | 173 | symbol.flags.dyn_ref = nlist.n_desc & macho.REFERENCED_DYNAMICALLY != 0; |
| | 174 | symbol.flags.no_dead_strip = symbol.flags.no_dead_strip or nlist.noDeadStrip(); |
| | 175 | // TODO: symbol.flags.interposable = macho_file.base.isDynLib() and macho_file.options.namespace == .flat and !nlist.pext(); |
| | 176 | symbol.flags.interposable = false; |
| | 177 | |
| | 178 | if (nlist.sect() and |
| | 179 | macho_file.sections.items(.header)[nlist.n_sect - 1].type() == macho.S_THREAD_LOCAL_VARIABLES) |
| | 180 | { |
| | 181 | symbol.flags.tlv = true; |
| | 182 | } |
| | 183 | } |
| | 184 | |
| | 185 | // Regardless of who the winner is, we still merge symbol visibility here. |
| | 186 | if (nlist.pext() or (nlist.weakDef() and nlist.weakRef())) { |
| | 187 | if (symbol.visibility != .global) { |
| | 188 | symbol.visibility = .hidden; |
| | 189 | } |
| | 190 | } else { |
| | 191 | symbol.visibility = .global; |
| | 192 | } |
| | 193 | } |
| 143 | } | 194 | } |
| 144 | | 195 | |
| 145 | pub fn resetGlobals(self: *ZigObject, macho_file: *MachO) void { | 196 | pub fn resetGlobals(self: *ZigObject, macho_file: *MachO) void { |
| ... | @@ -170,6 +221,13 @@ pub fn markLive(self: *ZigObject, macho_file: *MachO) void { | ... | @@ -170,6 +221,13 @@ pub fn markLive(self: *ZigObject, macho_file: *MachO) void { |
| 170 | } | 221 | } |
| 171 | } | 222 | } |
| 172 | | 223 | |
| | 224 | pub fn checkDuplicates(self: *ZigObject, dupes: anytype, macho_file: *MachO) !void { |
| | 225 | _ = self; |
| | 226 | _ = dupes; |
| | 227 | _ = macho_file; |
| | 228 | @panic("TODO checkDuplicates"); |
| | 229 | } |
| | 230 | |
| 173 | pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) !void { | 231 | pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) !void { |
| 174 | const tracy = trace(@src()); | 232 | const tracy = trace(@src()); |
| 175 | defer tracy.end(); | 233 | defer tracy.end(); |