diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-08-13 21:52:40 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-08-13 21:52:40 +0200 |
| commit | 1bd54a55fa40db9f91d8a0c1cf5244ff51be6081 (patch) | |
| tree | 975ed120696f9561ed82f083d575006f25be2ca8 /src | |
| parent | 97ab420dcf9bdfe954d6bff730a7492abaeb90bb (diff) | |
| download | zig-1bd54a55fa40db9f91d8a0c1cf5244ff51be6081.tar.gz zig-1bd54a55fa40db9f91d8a0c1cf5244ff51be6081.zip | |
fix compile errors in other codegen backends
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/aarch64/CodeGen.zig | 41 | ||||
| -rw-r--r-- | src/arch/arm/CodeGen.zig | 20 | ||||
| -rw-r--r-- | src/arch/riscv64/CodeGen.zig | 1 | ||||
| -rw-r--r-- | src/arch/riscv64/Emit.zig | 13 | ||||
| -rw-r--r-- | src/arch/sparc64/CodeGen.zig | 32 | ||||
| -rw-r--r-- | src/link/Elf/ZigObject.zig | 2 |
6 files changed, 16 insertions, 93 deletions
diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 2810b6b521..231db8e98c 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -4352,24 +4352,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier // on linking. if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) { .func => |func| { - if (self.bin_file.cast(.elf)) |elf_file| { - const zo = elf_file.zigObjectPtr().?; - const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav); - const sym = zo.symbol(sym_index); - _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); - const got_addr = @as(u32, @intCast(sym.zigGotAddress(elf_file))); - try self.genSetReg(Type.usize, .x30, .{ .memory = got_addr }); - } else if (self.bin_file.cast(.macho)) |macho_file| { - _ = macho_file; - @panic("TODO airCall"); - // const atom = try macho_file.getOrCreateAtomForNav(func.owner_nav); - // const sym_index = macho_file.getAtom(atom).getSymbolIndex().?; - // try self.genSetReg(Type.u64, .x30, .{ - // .linker_load = .{ - // .type = .got, - // .sym_index = sym_index, - // }, - // }); + if (self.bin_file.cast(.elf)) |_| { + return self.fail("TODO implement calling functions for Elf", .{}); + } else if (self.bin_file.cast(.macho)) |_| { + return self.fail("TODO implement calling functions for MachO", .{}); } else if (self.bin_file.cast(.coff)) |coff_file| { const atom = try coff_file.getOrCreateAtomForNav(func.owner_nav); const sym_index = coff_file.getAtom(atom).getSymbolIndex().?; @@ -4393,21 +4379,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier .@"extern" => |@"extern"| { const nav_name = ip.getNav(@"extern".owner_nav).name.toSlice(ip); const lib_name = @"extern".lib_name.toSlice(ip); - if (self.bin_file.cast(.macho)) |macho_file| { - _ = macho_file; - @panic("TODO airCall"); - // const sym_index = try macho_file.getGlobalSymbol(nav_name, lib_name); - // const atom = try macho_file.getOrCreateAtomForNav(self.owner_nav); - // const atom_index = macho_file.getAtom(atom).getSymbolIndex().?; - // _ = try self.addInst(.{ - // .tag = .call_extern, - // .data = .{ - // .relocation = .{ - // .atom_index = atom_index, - // .sym_index = sym_index, - // }, - // }, - // }); + if (self.bin_file.cast(.macho)) |_| { + return self.fail("TODO implement calling extern functions for MachO", .{}); } else if (self.bin_file.cast(.coff)) |coff_file| { const sym_index = try coff_file.getGlobalSymbol(nav_name, lib_name); try self.genSetReg(Type.u64, .x30, .{ @@ -6234,7 +6207,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { .memory => |addr| .{ .memory = addr }, .load_got => |sym_index| .{ .linker_load = .{ .type = .got, .sym_index = sym_index } }, .load_direct => |sym_index| .{ .linker_load = .{ .type = .direct, .sym_index = sym_index } }, - .load_symbol, .load_tlv => unreachable, // TODO + .load_symbol, .load_tlv, .lea_symbol => unreachable, // TODO }, .fail => |msg| { self.err_msg = msg; diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index e4d106921e..1c03699552 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4333,22 +4333,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier // Due to incremental compilation, how function calls are generated depends // on linking. if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) { - .func => |func| { - if (self.bin_file.cast(.elf)) |elf_file| { - const zo = elf_file.zigObjectPtr().?; - const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav); - const sym = zo.symbol(sym_index); - _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); - const got_addr: u32 = @intCast(sym.zigGotAddress(elf_file)); - try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr }); - } else if (self.bin_file.cast(.macho)) |_| { - unreachable; // unsupported architecture for MachO - } else { - return self.fail("TODO implement call on {s} for {s}", .{ - @tagName(self.bin_file.tag), - @tagName(self.target.cpu.arch), - }); - } + .func => { + return self.fail("TODO implement calling functions", .{}); }, .@"extern" => { return self.fail("TODO implement calling extern functions", .{}); @@ -6184,7 +6170,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { .mcv => |mcv| switch (mcv) { .none => .none, .undef => .undef, - .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO + .load_got, .load_symbol, .load_direct, .load_tlv, .lea_symbol => unreachable, // TODO .immediate => |imm| .{ .immediate = @truncate(imm) }, .memory => |addr| .{ .memory = addr }, }, diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index b5384542e7..e9f593485f 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -8026,6 +8026,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue { .mcv => |mcv| switch (mcv) { .none => .none, .undef => unreachable, + .lea_symbol => |sym_index| .{ .lea_symbol = .{ .sym = sym_index } }, .load_symbol => |sym_index| .{ .load_symbol = .{ .sym = sym_index } }, .load_tlv => |sym_index| .{ .lea_tlv = sym_index }, .immediate => |imm| .{ .immediate = imm }, diff --git a/src/arch/riscv64/Emit.zig b/src/arch/riscv64/Emit.zig index 137bc39572..c1e7565c0b 100644 --- a/src/arch/riscv64/Emit.zig +++ b/src/arch/riscv64/Emit.zig @@ -43,12 +43,6 @@ pub fn emitMir(emit: *Emit) Error!void { .fmt = std.meta.activeTag(lowered_inst), }), .load_symbol_reloc => |symbol| { - const is_obj_or_static_lib = switch (emit.lower.output_mode) { - .Exe => false, - .Obj => true, - .Lib => emit.lower.link_mode == .static, - }; - const elf_file = emit.bin_file.cast(.elf).?; const zo = elf_file.zigObjectPtr().?; @@ -58,12 +52,7 @@ pub fn emitMir(emit: *Emit) Error!void { var hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20); var lo_r_type: u32 = @intFromEnum(std.elf.R_RISCV.LO12_I); - if (sym.flags.needs_zig_got and !is_obj_or_static_lib) { - _ = try sym.getOrCreateZigGotEntry(symbol.sym_index, elf_file); - - hi_r_type = Elf.R_ZIG_GOT_HI20; - lo_r_type = Elf.R_ZIG_GOT_LO12; - } else if (sym.flags.needs_got) { + if (sym.flags.needs_got) { hi_r_type = Elf.R_GOT_HI20_STATIC; // TODO: rework this #20887 lo_r_type = Elf.R_GOT_LO12_I_STATIC; // TODO: rework this #20887 } diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index bba8cdec34..d0b0eedc57 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -1349,34 +1349,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier // Due to incremental compilation, how function calls are generated depends // on linking. if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) { - .func => |func| { - const got_addr = if (self.bin_file.cast(.elf)) |elf_file| blk: { - const zo = elf_file.zigObjectPtr().?; - const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav); - const sym = zo.symbol(sym_index); - _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); - break :blk @as(u32, @intCast(sym.zigGotAddress(elf_file))); - } else @panic("TODO SPARCv9 currently does not support non-ELF binaries"); - - try self.genSetReg(Type.usize, .o7, .{ .memory = got_addr }); - - _ = try self.addInst(.{ - .tag = .jmpl, - .data = .{ - .arithmetic_3op = .{ - .is_imm = false, - .rd = .o7, - .rs1 = .o7, - .rs2_or_imm = .{ .rs2 = .g0 }, - }, - }, - }); - - // TODO Find a way to fill this delay slot - _ = try self.addInst(.{ - .tag = .nop, - .data = .{ .nop = {} }, - }); + .func => { + return self.fail("TODO implement calling functions", .{}); }, .@"extern" => { return self.fail("TODO implement calling extern functions", .{}); @@ -4153,7 +4127,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue { .mcv => |mcv| switch (mcv) { .none => .none, .undef => .undef, - .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO + .load_got, .load_symbol, .load_direct, .load_tlv, .lea_symbol => unreachable, // TODO .immediate => |imm| .{ .immediate = imm }, .memory => |addr| .{ .memory = addr }, }, diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 4a3bdd6049..2adf2532c7 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -1036,7 +1036,7 @@ pub fn updateFunc( const ip = &zcu.intern_pool; const gpa = elf_file.base.comp.gpa; const func = zcu.funcInfo(func_index); - if (elf_file.base.isRelocatable() and self.jumpTablePtr() == null) { + if (!elf_file.base.isRelocatable() and self.jumpTablePtr() == null) { try self.initJumpTable(gpa, elf_file); } |
