Commit 8f82a66019
Changed files (2)
src
link
src/link/MachO/ZigObject.zig
@@ -694,10 +694,22 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id)
pub fn getDeclVAddr(
self: *ZigObject,
macho_file: *MachO,
+ pt: Zcu.PerThread,
decl_index: InternPool.DeclIndex,
reloc_info: link.File.RelocInfo,
) !u64 {
- const sym_index = try self.getOrCreateMetadataForDecl(macho_file, decl_index);
+ const zcu = pt.zcu;
+ const ip = &zcu.intern_pool;
+ const decl = zcu.declPtr(decl_index);
+ log.debug("getDeclVAddr {}({d})", .{ decl.fqn.fmt(ip), decl_index });
+ const sym_index = if (decl.isExtern(zcu)) blk: {
+ const name = decl.name.toSlice(ip);
+ const lib_name = if (decl.getOwnedExternFunc(zcu)) |ext_fn|
+ ext_fn.lib_name.toSlice(ip)
+ else
+ decl.getOwnedVariable(zcu).?.lib_name.toSlice(ip);
+ break :blk try self.getGlobalSymbol(macho_file, name, lib_name);
+ } else try self.getOrCreateMetadataForDecl(macho_file, decl_index);
const sym = self.symbols.items[sym_index];
const vaddr = sym.getAddress(.{}, macho_file);
const parent_atom = self.symbols.items[reloc_info.parent_atom_index].getAtom(macho_file).?;
src/link/MachO.zig
@@ -3042,9 +3042,9 @@ pub fn freeDecl(self: *MachO, decl_index: InternPool.DeclIndex) void {
return self.getZigObject().?.freeDecl(decl_index);
}
-pub fn getDeclVAddr(self: *MachO, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
+pub fn getDeclVAddr(self: *MachO, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
assert(self.llvm_object == null);
- return self.getZigObject().?.getDeclVAddr(self, decl_index, reloc_info);
+ return self.getZigObject().?.getDeclVAddr(self, pt, decl_index, reloc_info);
}
pub fn lowerAnonDecl(