authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-10 22:19:36+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-10 22:26:02+02:00
log62fad66d648f8eb9d734a8d8aa36ea56f398c0f2
tree1b29dc2ed033869fedce53ca8095901d624443b6
parent8f82a66019dac33ee1065ffe9e4520949203a9a6

Coff: handle ref to an extern in getDeclVAddr


1 files changed, 16 insertions(+), 4 deletions(-)

src/link/Coff.zig+16-4
...@@ -1856,11 +1856,23 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no...@@ -1856,11 +1856,23 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
1856 assert(!self.imports_count_dirty);1856 assert(!self.imports_count_dirty);
1857}1857}
18581858
1859pub fn getDeclVAddr(self: *Coff, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {1859pub fn getDeclVAddr(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
1860 assert(self.llvm_object == null);1860 assert(self.llvm_object == null);
18611861 const zcu = pt.zcu;
1862 const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);1862 const ip = &zcu.intern_pool;
1863 const sym_index = self.getAtom(this_atom_index).getSymbolIndex().?;1863 const decl = zcu.declPtr(decl_index);
1864 log.debug("getDeclVAddr {}({d})", .{ decl.fqn.fmt(ip), decl_index });
1865 const sym_index = if (decl.isExtern(zcu)) blk: {
1866 const name = decl.name.toSlice(ip);
1867 const lib_name = if (decl.getOwnedExternFunc(zcu)) |ext_fn|
1868 ext_fn.lib_name.toSlice(ip)
1869 else
1870 decl.getOwnedVariable(zcu).?.lib_name.toSlice(ip);
1871 break :blk try self.getGlobalSymbol(name, lib_name);
1872 } else blk: {
1873 const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);
1874 break :blk self.getAtom(this_atom_index).getSymbolIndex().?;
1875 };
1864 const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?;1876 const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?;
1865 const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };1877 const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };
1866 try Atom.addRelocation(self, atom_index, .{1878 try Atom.addRelocation(self, atom_index, .{