| author | |
| committer | |
| log | 9509fadbe38e77bc0f8b079c4d9def2937d81322 |
| tree | cd2501bd022c7bab315944c7839165db63ac6011 |
| parent | b66911370b3a5376c8f383dc0a187ffe9c3bbeb2 |
6 files changed, 94 insertions(+), 15 deletions(-)
src/link/MachO.zig+3-3| ... | ... | @@ -1601,18 +1601,18 @@ fn scanRelocs(self: *MachO) !void { |
| 1601 | 1601 | |
| 1602 | 1602 | if (self.dyld_stub_binder_index) |index| { |
| 1603 | 1603 | const sym = self.getSymbol(index); |
| 1604 | if (sym.getFile(self) != null) sym.flags.got = true; | |
| 1604 | if (sym.getFile(self) != null) sym.flags.needs_got = true; | |
| 1605 | 1605 | } |
| 1606 | 1606 | |
| 1607 | 1607 | if (self.objc_msg_send_index) |index| { |
| 1608 | 1608 | const sym = self.getSymbol(index); |
| 1609 | 1609 | if (sym.getFile(self) != null) |
| 1610 | sym.flags.got = true; // TODO is it always needed, or only if we are synthesising fast stubs? | |
| 1610 | sym.flags.needs_got = true; // TODO is it always needed, or only if we are synthesising fast stubs? | |
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | for (self.symbols.items, 0..) |*symbol, i| { |
| 1614 | 1614 | const index = @as(Symbol.Index, @intCast(i)); |
| 1615 | if (symbol.flags.got) { | |
| 1615 | if (symbol.flags.needs_got) { | |
| 1616 | 1616 | log.debug("'{s}' needs GOT", .{symbol.getName(self)}); |
| 1617 | 1617 | try self.got.addSymbol(index, self); |
| 1618 | 1618 | } |
src/link/MachO/Atom.zig+3-3| ... | ... | @@ -204,7 +204,7 @@ pub fn scanRelocs(self: Atom, macho_file: *MachO) !void { |
| 204 | 204 | (symbol.flags.@"export" and (symbol.flags.weak or symbol.flags.interposable)) or |
| 205 | 205 | macho_file.getTarget().cpu.arch == .aarch64) // TODO relax on arm64 |
| 206 | 206 | { |
| 207 | symbol.flags.got = true; | |
| 207 | symbol.flags.needs_got = true; | |
| 208 | 208 | if (symbol.flags.weak) { |
| 209 | 209 | macho_file.binds_to_weak = true; |
| 210 | 210 | } |
| ... | ... | @@ -212,7 +212,7 @@ pub fn scanRelocs(self: Atom, macho_file: *MachO) !void { |
| 212 | 212 | }, |
| 213 | 213 | |
| 214 | 214 | .got => { |
| 215 | rel.getTargetSymbol(macho_file).flags.got = true; | |
| 215 | rel.getTargetSymbol(macho_file).flags.needs_got = true; | |
| 216 | 216 | }, |
| 217 | 217 | |
| 218 | 218 | .tlv, |
| ... | ... | @@ -452,7 +452,7 @@ fn resolveRelocInner( |
| 452 | 452 | assert(rel.tag == .@"extern"); |
| 453 | 453 | assert(rel.meta.length == 2); |
| 454 | 454 | assert(rel.meta.pcrel); |
| 455 | if (rel.getTargetSymbol(macho_file).flags.got) { | |
| 455 | if (rel.getTargetSymbol(macho_file).flags.has_got) { | |
| 456 | 456 | try writer.writeInt(i32, @intCast(G + A - P), .little); |
| 457 | 457 | } else { |
| 458 | 458 | try x86_64.relaxGotLoad(code[rel_offset - 3 ..]); |
src/link/MachO/Object.zig+2-2| ... | ... | @@ -1105,10 +1105,10 @@ pub fn scanRelocs(self: Object, macho_file: *MachO) !void { |
| 1105 | 1105 | if (!rec.alive) continue; |
| 1106 | 1106 | if (rec.getFde(macho_file)) |fde| { |
| 1107 | 1107 | if (fde.getCie(macho_file).getPersonality(macho_file)) |sym| { |
| 1108 | sym.flags.got = true; | |
| 1108 | sym.flags.needs_got = true; | |
| 1109 | 1109 | } |
| 1110 | 1110 | } else if (rec.getPersonality(macho_file)) |sym| { |
| 1111 | sym.flags.got = true; | |
| 1111 | sym.flags.needs_got = true; | |
| 1112 | 1112 | } |
| 1113 | 1113 | } |
| 1114 | 1114 | } |
src/link/MachO/Symbol.zig+3-2| ... | ... | @@ -118,7 +118,7 @@ pub fn getAddress(symbol: Symbol, opts: struct { |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | pub fn getGotAddress(symbol: Symbol, macho_file: *MachO) u64 { |
| 121 | if (!symbol.flags.got) return 0; | |
| 121 | if (!symbol.flags.has_got) return 0; | |
| 122 | 122 | const extra = symbol.getExtra(macho_file).?; |
| 123 | 123 | return macho_file.got.getAddress(extra.got, macho_file); |
| 124 | 124 | } |
| ... | ... | @@ -349,7 +349,8 @@ pub const Flags = packed struct { |
| 349 | 349 | output_symtab: bool = false, |
| 350 | 350 | |
| 351 | 351 | /// Whether the symbol contains __got indirection. |
| 352 | got: bool = false, | |
| 352 | needs_got: bool = false, | |
| 353 | has_got: bool = false, | |
| 353 | 354 | |
| 354 | 355 | /// Whether the symbols contains __stubs indirection. |
| 355 | 356 | stubs: bool = false, |
src/link/MachO/ZigObject.zig+82-5| ... | ... | @@ -197,11 +197,88 @@ pub fn updateDecl( |
| 197 | 197 | mod: *Module, |
| 198 | 198 | decl_index: InternPool.DeclIndex, |
| 199 | 199 | ) link.File.UpdateDeclError!void { |
| 200 | _ = self; | |
| 201 | _ = macho_file; | |
| 202 | _ = mod; | |
| 203 | _ = decl_index; | |
| 204 | @panic("TODO updateDecl"); | |
| 200 | const tracy = trace(@src()); | |
| 201 | defer tracy.end(); | |
| 202 | ||
| 203 | const decl = mod.declPtr(decl_index); | |
| 204 | ||
| 205 | if (decl.val.getExternFunc(mod)) |_| { | |
| 206 | return; | |
| 207 | } | |
| 208 | ||
| 209 | if (decl.isExtern(mod)) { | |
| 210 | // Extern variable gets a __got entry only | |
| 211 | const variable = decl.getOwnedVariable(mod).?; | |
| 212 | const name = mod.intern_pool.stringToSlice(decl.name); | |
| 213 | const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name); | |
| 214 | const index = try self.getGlobalSymbol(macho_file, name, lib_name); | |
| 215 | macho_file.getSymbol(index).flags.needs_got = true; | |
| 216 | return; | |
| 217 | } | |
| 218 | ||
| 219 | // const is_threadlocal = if (decl.val.getVariable(mod)) |variable| | |
| 220 | // variable.is_threadlocal and comp.config.any_non_single_threaded | |
| 221 | // else | |
| 222 | // false; | |
| 223 | // if (is_threadlocal) return self.updateThreadlocalVariable(mod, decl_index); | |
| 224 | ||
| 225 | // const atom_index = try self.getOrCreateAtomForDecl(decl_index); | |
| 226 | // const sym_index = self.getAtom(atom_index).getSymbolIndex().?; | |
| 227 | // Atom.freeRelocations(self, atom_index); | |
| 228 | ||
| 229 | // const comp = macho_file.base.comp; | |
| 230 | // const gpa = comp.gpa; | |
| 231 | ||
| 232 | // var code_buffer = std.ArrayList(u8).init(gpa); | |
| 233 | // defer code_buffer.deinit(); | |
| 234 | ||
| 235 | // var decl_state: ?Dwarf.DeclState = if (self.d_sym) |*d_sym| | |
| 236 | // try d_sym.dwarf.initDeclState(mod, decl_index) | |
| 237 | // else | |
| 238 | // null; | |
| 239 | // defer if (decl_state) |*ds| ds.deinit(); | |
| 240 | ||
| 241 | // const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; | |
| 242 | // const res = if (decl_state) |*ds| | |
| 243 | // try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ | |
| 244 | // .ty = decl.ty, | |
| 245 | // .val = decl_val, | |
| 246 | // }, &code_buffer, .{ | |
| 247 | // .dwarf = ds, | |
| 248 | // }, .{ | |
| 249 | // .parent_atom_index = sym_index, | |
| 250 | // }) | |
| 251 | // else | |
| 252 | // try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{ | |
| 253 | // .ty = decl.ty, | |
| 254 | // .val = decl_val, | |
| 255 | // }, &code_buffer, .none, .{ | |
| 256 | // .parent_atom_index = sym_index, | |
| 257 | // }); | |
| 258 | ||
| 259 | // const code = switch (res) { | |
| 260 | // .ok => code_buffer.items, | |
| 261 | // .fail => |em| { | |
| 262 | // decl.analysis = .codegen_failure; | |
| 263 | // try mod.failed_decls.put(mod.gpa, decl_index, em); | |
| 264 | // return; | |
| 265 | // }, | |
| 266 | // }; | |
| 267 | // const addr = try self.updateDeclCode(decl_index, code); | |
| 268 | ||
| 269 | // if (decl_state) |*ds| { | |
| 270 | // try self.d_sym.?.dwarf.commitDeclState( | |
| 271 | // mod, | |
| 272 | // decl_index, | |
| 273 | // addr, | |
| 274 | // self.getAtom(atom_index).size, | |
| 275 | // ds, | |
| 276 | // ); | |
| 277 | // } | |
| 278 | ||
| 279 | // // Since we updated the vaddr and the size, each corresponding export symbol also | |
| 280 | // // needs to be updated. | |
| 281 | // try self.updateExports(mod, .{ .decl_index = decl_index }, mod.getDeclExports(decl_index)); | |
| 205 | 282 | } |
| 206 | 283 | |
| 207 | 284 | pub fn lowerUnnamedConst( |
src/link/MachO/synthetic.zig+1| ... | ... | @@ -13,6 +13,7 @@ pub const GotSection = struct { |
| 13 | 13 | const entry = try got.symbols.addOne(gpa); |
| 14 | 14 | entry.* = sym_index; |
| 15 | 15 | const symbol = macho_file.getSymbol(sym_index); |
| 16 | symbol.flags.has_got = true; | |
| 16 | 17 | try symbol.addExtra(.{ .got = index }, macho_file); |
| 17 | 18 | } |
| 18 | 19 |