Skip to content

Commit 62fad66

Browse files
committed
Coff: handle ref to an extern in getDeclVAddr
1 parent 8f82a66 commit 62fad66

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/link/Coff.zig

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,11 +1856,23 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
18561856
assert(!self.imports_count_dirty);
18571857
}
18581858

1859-
pub fn getDeclVAddr(self: *Coff, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
1859+
pub fn getDeclVAddr(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 {
18601860
assert(self.llvm_object == null);
1861-
1862-
const this_atom_index = try self.getOrCreateAtomForDecl(decl_index);
1863-
const sym_index = self.getAtom(this_atom_index).getSymbolIndex().?;
1861+
const zcu = pt.zcu;
1862+
const ip = &zcu.intern_pool;
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+
};
18641876
const atom_index = self.getAtomIndexForSymbol(.{ .sym_index = reloc_info.parent_atom_index, .file = null }).?;
18651877
const target = SymbolWithLoc{ .sym_index = sym_index, .file = null };
18661878
try Atom.addRelocation(self, atom_index, .{

0 commit comments

Comments
 (0)