authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-13 21:52:40+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-13 21:52:40+02:00
log1bd54a55fa40db9f91d8a0c1cf5244ff51be6081
tree975ed120696f9561ed82f083d575006f25be2ca8
parent97ab420dcf9bdfe954d6bff730a7492abaeb90bb

fix compile errors in other codegen backends


6 files changed, 16 insertions(+), 93 deletions(-)

src/arch/aarch64/CodeGen.zig+7-34
......@@ -4352,24 +4352,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43524352 // on linking.
43534353 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {
43544354 .func => |func| {
4355 if (self.bin_file.cast(.elf)) |elf_file| {
4356 const zo = elf_file.zigObjectPtr().?;
4357 const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav);
4358 const sym = zo.symbol(sym_index);
4359 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
4360 const got_addr = @as(u32, @intCast(sym.zigGotAddress(elf_file)));
4361 try self.genSetReg(Type.usize, .x30, .{ .memory = got_addr });
4362 } else if (self.bin_file.cast(.macho)) |macho_file| {
4363 _ = macho_file;
4364 @panic("TODO airCall");
4365 // const atom = try macho_file.getOrCreateAtomForNav(func.owner_nav);
4366 // const sym_index = macho_file.getAtom(atom).getSymbolIndex().?;
4367 // try self.genSetReg(Type.u64, .x30, .{
4368 // .linker_load = .{
4369 // .type = .got,
4370 // .sym_index = sym_index,
4371 // },
4372 // });
4355 if (self.bin_file.cast(.elf)) |_| {
4356 return self.fail("TODO implement calling functions for Elf", .{});
4357 } else if (self.bin_file.cast(.macho)) |_| {
4358 return self.fail("TODO implement calling functions for MachO", .{});
43734359 } else if (self.bin_file.cast(.coff)) |coff_file| {
43744360 const atom = try coff_file.getOrCreateAtomForNav(func.owner_nav);
43754361 const sym_index = coff_file.getAtom(atom).getSymbolIndex().?;
......@@ -4393,21 +4379,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43934379 .@"extern" => |@"extern"| {
43944380 const nav_name = ip.getNav(@"extern".owner_nav).name.toSlice(ip);
43954381 const lib_name = @"extern".lib_name.toSlice(ip);
4396 if (self.bin_file.cast(.macho)) |macho_file| {
4397 _ = macho_file;
4398 @panic("TODO airCall");
4399 // const sym_index = try macho_file.getGlobalSymbol(nav_name, lib_name);
4400 // const atom = try macho_file.getOrCreateAtomForNav(self.owner_nav);
4401 // const atom_index = macho_file.getAtom(atom).getSymbolIndex().?;
4402 // _ = try self.addInst(.{
4403 // .tag = .call_extern,
4404 // .data = .{
4405 // .relocation = .{
4406 // .atom_index = atom_index,
4407 // .sym_index = sym_index,
4408 // },
4409 // },
4410 // });
4382 if (self.bin_file.cast(.macho)) |_| {
4383 return self.fail("TODO implement calling extern functions for MachO", .{});
44114384 } else if (self.bin_file.cast(.coff)) |coff_file| {
44124385 const sym_index = try coff_file.getGlobalSymbol(nav_name, lib_name);
44134386 try self.genSetReg(Type.u64, .x30, .{
......@@ -6234,7 +6207,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
62346207 .memory => |addr| .{ .memory = addr },
62356208 .load_got => |sym_index| .{ .linker_load = .{ .type = .got, .sym_index = sym_index } },
62366209 .load_direct => |sym_index| .{ .linker_load = .{ .type = .direct, .sym_index = sym_index } },
6237 .load_symbol, .load_tlv => unreachable, // TODO
6210 .load_symbol, .load_tlv, .lea_symbol => unreachable, // TODO
62386211 },
62396212 .fail => |msg| {
62406213 self.err_msg = msg;
src/arch/arm/CodeGen.zig+3-17
......@@ -4333,22 +4333,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43334333 // Due to incremental compilation, how function calls are generated depends
43344334 // on linking.
43354335 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {
4336 .func => |func| {
4337 if (self.bin_file.cast(.elf)) |elf_file| {
4338 const zo = elf_file.zigObjectPtr().?;
4339 const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav);
4340 const sym = zo.symbol(sym_index);
4341 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
4342 const got_addr: u32 = @intCast(sym.zigGotAddress(elf_file));
4343 try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr });
4344 } else if (self.bin_file.cast(.macho)) |_| {
4345 unreachable; // unsupported architecture for MachO
4346 } else {
4347 return self.fail("TODO implement call on {s} for {s}", .{
4348 @tagName(self.bin_file.tag),
4349 @tagName(self.target.cpu.arch),
4350 });
4351 }
4336 .func => {
4337 return self.fail("TODO implement calling functions", .{});
43524338 },
43534339 .@"extern" => {
43544340 return self.fail("TODO implement calling extern functions", .{});
......@@ -6184,7 +6170,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
61846170 .mcv => |mcv| switch (mcv) {
61856171 .none => .none,
61866172 .undef => .undef,
6187 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO
6173 .load_got, .load_symbol, .load_direct, .load_tlv, .lea_symbol => unreachable, // TODO
61886174 .immediate => |imm| .{ .immediate = @truncate(imm) },
61896175 .memory => |addr| .{ .memory = addr },
61906176 },
src/arch/riscv64/CodeGen.zig+1
......@@ -8026,6 +8026,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
80268026 .mcv => |mcv| switch (mcv) {
80278027 .none => .none,
80288028 .undef => unreachable,
8029 .lea_symbol => |sym_index| .{ .lea_symbol = .{ .sym = sym_index } },
80298030 .load_symbol => |sym_index| .{ .load_symbol = .{ .sym = sym_index } },
80308031 .load_tlv => |sym_index| .{ .lea_tlv = sym_index },
80318032 .immediate => |imm| .{ .immediate = imm },
src/arch/riscv64/Emit.zig+1-12
......@@ -43,12 +43,6 @@ pub fn emitMir(emit: *Emit) Error!void {
4343 .fmt = std.meta.activeTag(lowered_inst),
4444 }),
4545 .load_symbol_reloc => |symbol| {
46 const is_obj_or_static_lib = switch (emit.lower.output_mode) {
47 .Exe => false,
48 .Obj => true,
49 .Lib => emit.lower.link_mode == .static,
50 };
51
5246 const elf_file = emit.bin_file.cast(.elf).?;
5347 const zo = elf_file.zigObjectPtr().?;
5448
......@@ -58,12 +52,7 @@ pub fn emitMir(emit: *Emit) Error!void {
5852 var hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20);
5953 var lo_r_type: u32 = @intFromEnum(std.elf.R_RISCV.LO12_I);
6054
61 if (sym.flags.needs_zig_got and !is_obj_or_static_lib) {
62 _ = try sym.getOrCreateZigGotEntry(symbol.sym_index, elf_file);
63
64 hi_r_type = Elf.R_ZIG_GOT_HI20;
65 lo_r_type = Elf.R_ZIG_GOT_LO12;
66 } else if (sym.flags.needs_got) {
55 if (sym.flags.needs_got) {
6756 hi_r_type = Elf.R_GOT_HI20_STATIC; // TODO: rework this #20887
6857 lo_r_type = Elf.R_GOT_LO12_I_STATIC; // TODO: rework this #20887
6958 }
src/arch/sparc64/CodeGen.zig+3-29
......@@ -1349,34 +1349,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13491349 // Due to incremental compilation, how function calls are generated depends
13501350 // on linking.
13511351 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {
1352 .func => |func| {
1353 const got_addr = if (self.bin_file.cast(.elf)) |elf_file| blk: {
1354 const zo = elf_file.zigObjectPtr().?;
1355 const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav);
1356 const sym = zo.symbol(sym_index);
1357 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
1358 break :blk @as(u32, @intCast(sym.zigGotAddress(elf_file)));
1359 } else @panic("TODO SPARCv9 currently does not support non-ELF binaries");
1360
1361 try self.genSetReg(Type.usize, .o7, .{ .memory = got_addr });
1362
1363 _ = try self.addInst(.{
1364 .tag = .jmpl,
1365 .data = .{
1366 .arithmetic_3op = .{
1367 .is_imm = false,
1368 .rd = .o7,
1369 .rs1 = .o7,
1370 .rs2_or_imm = .{ .rs2 = .g0 },
1371 },
1372 },
1373 });
1374
1375 // TODO Find a way to fill this delay slot
1376 _ = try self.addInst(.{
1377 .tag = .nop,
1378 .data = .{ .nop = {} },
1379 });
1352 .func => {
1353 return self.fail("TODO implement calling functions", .{});
13801354 },
13811355 .@"extern" => {
13821356 return self.fail("TODO implement calling extern functions", .{});
......@@ -4153,7 +4127,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
41534127 .mcv => |mcv| switch (mcv) {
41544128 .none => .none,
41554129 .undef => .undef,
4156 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO
4130 .load_got, .load_symbol, .load_direct, .load_tlv, .lea_symbol => unreachable, // TODO
41574131 .immediate => |imm| .{ .immediate = imm },
41584132 .memory => |addr| .{ .memory = addr },
41594133 },
src/link/Elf/ZigObject.zig+1-1
......@@ -1036,7 +1036,7 @@ pub fn updateFunc(
10361036 const ip = &zcu.intern_pool;
10371037 const gpa = elf_file.base.comp.gpa;
10381038 const func = zcu.funcInfo(func_index);
1039 if (elf_file.base.isRelocatable() and self.jumpTablePtr() == null) {
1039 if (!elf_file.base.isRelocatable() and self.jumpTablePtr() == null) {
10401040 try self.initJumpTable(gpa, elf_file);
10411041 }
10421042