plan9 linker: get ready to delete allocateDeclIndexes

This commit is contained in:
Jacob G-W 2021-08-30 08:52:29 -04:00
parent 4cb2d6bc3e
commit 84ab03a875
2 changed files with 22 additions and 8 deletions

View File

@ -2965,6 +2965,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
if (self.air.value(callee)) |func_value| {
if (func_value.castTag(.function)) |func_payload| {
try p9.seeDecl(func_payload.data.owner_decl);
const ptr_bits = self.target.cpu.arch.ptrBitWidth();
const ptr_bytes: u64 = @divExact(ptr_bits, 8);
const got_addr = p9.bases.data;
@ -3012,6 +3013,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
if (self.air.value(callee)) |func_value| {
if (func_value.castTag(.function)) |func_payload| {
try p9.seeDecl(func_payload.data.owner_decl);
const ptr_bits = self.target.cpu.arch.ptrBitWidth();
const ptr_bytes: u64 = @divExact(ptr_bits, 8);
const got_addr = p9.bases.data;
@ -4939,6 +4941,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
const got_addr = coff_file.offset_table_virtual_address + decl.link.coff.offset_table_index * ptr_bytes;
return MCValue{ .memory = got_addr };
} else if (self.bin_file.cast(link.File.Plan9)) |p9| {
try p9.seeDecl(decl);
const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes;
return MCValue{ .memory = got_addr };
} else {

View File

@ -131,6 +131,8 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv
}
const decl = func.owner_decl;
try self.seeDecl(decl);
log.debug("codegen decl {*} ({s})", .{ decl, decl.name });
var code_buffer = std.ArrayList(u8).init(self.base.allocator);
@ -176,6 +178,8 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {
}
}
try self.seeDecl(decl);
log.debug("codegen decl {*} ({s})", .{ decl, decl.name });
var code_buffer = std.ArrayList(u8).init(self.base.allocator);
@ -407,12 +411,24 @@ pub fn freeDecl(self: *Plan9, decl: *Module.Decl) void {
}
}
pub fn seeDecl(self: *Plan9, decl: *Module.Decl) !void {
if (decl.link.plan9.got_index == null) {
if (self.got_index_free_list.popOrNull()) |i| {
decl.link.plan9.got_index = i;
} else {
self.got_len += 1;
decl.link.plan9.got_index = self.got_len - 1;
}
}
}
pub fn updateDeclExports(
self: *Plan9,
module: *Module,
decl: *Module.Decl,
exports: []const *Module.Export,
) !void {
try self.seeDecl(decl);
// we do all the things in flush
_ = self;
_ = module;
@ -494,13 +510,8 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
}
}
/// this will be removed, moved to updateFinish
pub fn allocateDeclIndexes(self: *Plan9, decl: *Module.Decl) !void {
if (decl.link.plan9.got_index == null) {
if (self.got_index_free_list.popOrNull()) |i| {
decl.link.plan9.got_index = i;
} else {
self.got_len += 1;
decl.link.plan9.got_index = self.got_len - 1;
}
}
_ = self;
_ = decl;
}