aboutsummaryrefslogtreecommitdiff
path: root/src/arch/riscv64/CodeGen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-08-30 14:29:41 +0200
committerGitHub <noreply@github.com>2022-08-30 14:29:41 +0200
commit7ef0c9d298d5645b4b6d1ffdfd34c69c04423ed2 (patch)
tree12b54077e1533b1abcb8d9a9cd1222b24478f5fc /src/arch/riscv64/CodeGen.zig
parentb64e4c5bf28286091ff97245e61f08b897e3eb5e (diff)
parente57fbe8069e672483b0c9ae1fa28c00812596306 (diff)
downloadzig-7ef0c9d298d5645b4b6d1ffdfd34c69c04423ed2.tar.gz
zig-7ef0c9d298d5645b4b6d1ffdfd34c69c04423ed2.zip
Merge pull request #12677 from ziglang/coff-linker
coff: initial rewrite of the COFF/PE linker
Diffstat (limited to 'src/arch/riscv64/CodeGen.zig')
-rw-r--r--src/arch/riscv64/CodeGen.zig16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig
index 06adcff6d4..cd1d0e4050 100644
--- a/src/arch/riscv64/CodeGen.zig
+++ b/src/arch/riscv64/CodeGen.zig
@@ -1718,7 +1718,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
// Due to incremental compilation, how function calls are generated depends
// on linking.
- if (self.bin_file.tag == link.File.Elf.base_tag or self.bin_file.tag == link.File.Coff.base_tag) {
+ if (self.bin_file.cast(link.File.Elf)) |elf_file| {
for (info.args) |mc_arg, arg_i| {
const arg = args[arg_i];
const arg_ty = self.air.typeOf(arg);
@@ -1752,13 +1752,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
const ptr_bytes: u64 = @divExact(ptr_bits, 8);
const mod = self.bin_file.options.module.?;
const fn_owner_decl = mod.declPtr(func.owner_decl);
- const got_addr = if (self.bin_file.cast(link.File.Elf)) |elf_file| blk: {
+ const got_addr = blk: {
const got = &elf_file.program_headers.items[elf_file.phdr_got_index.?];
break :blk @intCast(u32, got.p_vaddr + fn_owner_decl.link.elf.offset_table_index * ptr_bytes);
- } else if (self.bin_file.cast(link.File.Coff)) |coff_file|
- coff_file.offset_table_virtual_address + fn_owner_decl.link.coff.offset_table_index * ptr_bytes
- else
- unreachable;
+ };
try self.genSetReg(Type.initTag(.usize), .ra, .{ .memory = got_addr });
_ = try self.addInst(.{
@@ -1777,6 +1774,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
} else {
return self.fail("TODO implement calling runtime known function pointer", .{});
}
+ } else if (self.bin_file.cast(link.File.Coff)) |_| {
+ return self.fail("TODO implement calling in COFF for {}", .{self.target.cpu.arch});
} else if (self.bin_file.cast(link.File.MachO)) |_| {
unreachable; // unsupported architecture for MachO
} else if (self.bin_file.cast(link.File.Plan9)) |_| {
@@ -2591,9 +2590,8 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl_index: Module.Decl.Index) Inne
// TODO I'm hacking my way through here by repurposing .memory for storing
// index to the GOT target symbol index.
return MCValue{ .memory = decl.link.macho.sym_index };
- } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
- 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.Coff)) |_| {
+ return self.fail("TODO codegen COFF const Decl pointer", .{});
} else if (self.bin_file.cast(link.File.Plan9)) |p9| {
try p9.seeDecl(decl_index);
const got_addr = p9.bases.data + decl.link.plan9.got_index.? * ptr_bytes;