| author | |
| committer | |
| log | 84ab03a875b2a1b9d38f094242ddbd54f133c1a5 |
| tree | 177803b056903400b587cda7172482f3723d520a |
| parent | 4cb2d6bc3e3ab7c27cabdc7318abaea1afc34654 |
2 files changed, 22 insertions(+), 8 deletions(-)
src/codegen.zig+3| ... | @@ -2965,6 +2965,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2965,6 +2965,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2965 | } | 2965 | } |
| 2966 | if (self.air.value(callee)) |func_value| { | 2966 | if (self.air.value(callee)) |func_value| { |
| 2967 | if (func_value.castTag(.function)) |func_payload| { | 2967 | if (func_value.castTag(.function)) |func_payload| { |
| 2968 | try p9.seeDecl(func_payload.data.owner_decl); | ||
| 2968 | const ptr_bits = self.target.cpu.arch.ptrBitWidth(); | 2969 | const ptr_bits = self.target.cpu.arch.ptrBitWidth(); |
| 2969 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); | 2970 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); |
| 2970 | const got_addr = p9.bases.data; | 2971 | const got_addr = p9.bases.data; |
| ... | @@ -3012,6 +3013,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -3012,6 +3013,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 3012 | } | 3013 | } |
| 3013 | if (self.air.value(callee)) |func_value| { | 3014 | if (self.air.value(callee)) |func_value| { |
| 3014 | if (func_value.castTag(.function)) |func_payload| { | 3015 | if (func_value.castTag(.function)) |func_payload| { |
| 3016 | try p9.seeDecl(func_payload.data.owner_decl); | ||
| 3015 | const ptr_bits = self.target.cpu.arch.ptrBitWidth(); | 3017 | const ptr_bits = self.target.cpu.arch.ptrBitWidth(); |
| 3016 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); | 3018 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); |
| 3017 | const got_addr = p9.bases.data; | 3019 | const got_addr = p9.bases.data; |
| ... | @@ -4939,6 +4941,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -4939,6 +4941,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 4939 | const got_addr = coff_file.offset_table_virtual_address + decl.link.coff.offset_table_index * ptr_bytes; | 4941 | const got_addr = coff_file.offset_table_virtual_address + decl.link.coff.offset_table_index * ptr_bytes; |
| 4940 | return MCValue{ .memory = got_addr }; | 4942 | return MCValue{ .memory = got_addr }; |
| 4941 | } else if (self.bin_file.cast(link.File.Plan9)) |p9| { | 4943 | } else if (self.bin_file.cast(link.File.Plan9)) |p9| { |
| 4944 | try p9.seeDecl(decl); | ||
| 4942 | const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes; | 4945 | const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes; |
| 4943 | return MCValue{ .memory = got_addr }; | 4946 | return MCValue{ .memory = got_addr }; |
| 4944 | } else { | 4947 | } else { |
src/link/Plan9.zig+19-8| ... | @@ -131,6 +131,8 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv | ... | @@ -131,6 +131,8 @@ pub fn updateFunc(self: *Plan9, module: *Module, func: *Module.Fn, air: Air, liv |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | const decl = func.owner_decl; | 133 | const decl = func.owner_decl; |
| 134 | |||
| 135 | try self.seeDecl(decl); | ||
| 134 | log.debug("codegen decl {*} ({s})", .{ decl, decl.name }); | 136 | log.debug("codegen decl {*} ({s})", .{ decl, decl.name }); |
| 135 | 137 | ||
| 136 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); | 138 | 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 { | ... | @@ -176,6 +178,8 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void { |
| 176 | } | 178 | } |
| 177 | } | 179 | } |
| 178 | 180 | ||
| 181 | try self.seeDecl(decl); | ||
| 182 | |||
| 179 | log.debug("codegen decl {*} ({s})", .{ decl, decl.name }); | 183 | log.debug("codegen decl {*} ({s})", .{ decl, decl.name }); |
| 180 | 184 | ||
| 181 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); | 185 | var code_buffer = std.ArrayList(u8).init(self.base.allocator); |
| ... | @@ -407,12 +411,24 @@ pub fn freeDecl(self: *Plan9, decl: *Module.Decl) void { | ... | @@ -407,12 +411,24 @@ pub fn freeDecl(self: *Plan9, decl: *Module.Decl) void { |
| 407 | } | 411 | } |
| 408 | } | 412 | } |
| 409 | 413 | ||
| 414 | pub fn seeDecl(self: *Plan9, decl: *Module.Decl) !void { | ||
| 415 | if (decl.link.plan9.got_index == null) { | ||
| 416 | if (self.got_index_free_list.popOrNull()) |i| { | ||
| 417 | decl.link.plan9.got_index = i; | ||
| 418 | } else { | ||
| 419 | self.got_len += 1; | ||
| 420 | decl.link.plan9.got_index = self.got_len - 1; | ||
| 421 | } | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 410 | pub fn updateDeclExports( | 425 | pub fn updateDeclExports( |
| 411 | self: *Plan9, | 426 | self: *Plan9, |
| 412 | module: *Module, | 427 | module: *Module, |
| 413 | decl: *Module.Decl, | 428 | decl: *Module.Decl, |
| 414 | exports: []const *Module.Export, | 429 | exports: []const *Module.Export, |
| 415 | ) !void { | 430 | ) !void { |
| 431 | try self.seeDecl(decl); | ||
| 416 | // we do all the things in flush | 432 | // we do all the things in flush |
| 417 | _ = self; | 433 | _ = self; |
| 418 | _ = module; | 434 | _ = module; |
| ... | @@ -494,13 +510,8 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void { | ... | @@ -494,13 +510,8 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void { |
| 494 | } | 510 | } |
| 495 | } | 511 | } |
| 496 | 512 | ||
| 513 | /// this will be removed, moved to updateFinish | ||
| 497 | pub fn allocateDeclIndexes(self: *Plan9, decl: *Module.Decl) !void { | 514 | pub fn allocateDeclIndexes(self: *Plan9, decl: *Module.Decl) !void { |
| 498 | if (decl.link.plan9.got_index == null) { | 515 | _ = self; |
| 499 | if (self.got_index_free_list.popOrNull()) |i| { | 516 | _ = decl; |
| 500 | decl.link.plan9.got_index = i; | ||
| 501 | } else { | ||
| 502 | self.got_len += 1; | ||
| 503 | decl.link.plan9.got_index = self.got_len - 1; | ||
| 504 | } | ||
| 505 | } | ||
| 506 | } | 517 | } |