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...@@ -4352,24 +4352,10 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4352 // on linking.4352 // on linking.
4353 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {4353 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {
4354 .func => |func| {4354 .func => |func| {
4355 if (self.bin_file.cast(.elf)) |elf_file| {4355 if (self.bin_file.cast(.elf)) |_| {
4356 const zo = elf_file.zigObjectPtr().?;4356 return self.fail("TODO implement calling functions for Elf", .{});
4357 const sym_index = try zo.getOrCreateMetadataForNav(elf_file, func.owner_nav);4357 } else if (self.bin_file.cast(.macho)) |_| {
4358 const sym = zo.symbol(sym_index);4358 return self.fail("TODO implement calling functions for MachO", .{});
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 // });
4373 } else if (self.bin_file.cast(.coff)) |coff_file| {4359 } else if (self.bin_file.cast(.coff)) |coff_file| {
4374 const atom = try coff_file.getOrCreateAtomForNav(func.owner_nav);4360 const atom = try coff_file.getOrCreateAtomForNav(func.owner_nav);
4375 const sym_index = coff_file.getAtom(atom).getSymbolIndex().?;4361 const sym_index = coff_file.getAtom(atom).getSymbolIndex().?;
...@@ -4393,21 +4379,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4393,21 +4379,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4393 .@"extern" => |@"extern"| {4379 .@"extern" => |@"extern"| {
4394 const nav_name = ip.getNav(@"extern".owner_nav).name.toSlice(ip);4380 const nav_name = ip.getNav(@"extern".owner_nav).name.toSlice(ip);
4395 const lib_name = @"extern".lib_name.toSlice(ip);4381 const lib_name = @"extern".lib_name.toSlice(ip);
4396 if (self.bin_file.cast(.macho)) |macho_file| {4382 if (self.bin_file.cast(.macho)) |_| {
4397 _ = macho_file;4383 return self.fail("TODO implement calling extern functions for MachO", .{});
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 // });
4411 } else if (self.bin_file.cast(.coff)) |coff_file| {4384 } else if (self.bin_file.cast(.coff)) |coff_file| {
4412 const sym_index = try coff_file.getGlobalSymbol(nav_name, lib_name);4385 const sym_index = try coff_file.getGlobalSymbol(nav_name, lib_name);
4413 try self.genSetReg(Type.u64, .x30, .{4386 try self.genSetReg(Type.u64, .x30, .{
...@@ -6234,7 +6207,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {...@@ -6234,7 +6207,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
6234 .memory => |addr| .{ .memory = addr },6207 .memory => |addr| .{ .memory = addr },
6235 .load_got => |sym_index| .{ .linker_load = .{ .type = .got, .sym_index = sym_index } },6208 .load_got => |sym_index| .{ .linker_load = .{ .type = .got, .sym_index = sym_index } },
6236 .load_direct => |sym_index| .{ .linker_load = .{ .type = .direct, .sym_index = sym_index } },6209 .load_direct => |sym_index| .{ .linker_load = .{ .type = .direct, .sym_index = sym_index } },
6237 .load_symbol, .load_tlv => unreachable, // TODO6210 .load_symbol, .load_tlv, .lea_symbol => unreachable, // TODO
6238 },6211 },
6239 .fail => |msg| {6212 .fail => |msg| {
6240 self.err_msg = msg;6213 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...@@ -4333,22 +4333,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4333 // Due to incremental compilation, how function calls are generated depends4333 // Due to incremental compilation, how function calls are generated depends
4334 // on linking.4334 // on linking.
4335 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {4335 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {
4336 .func => |func| {4336 .func => {
4337 if (self.bin_file.cast(.elf)) |elf_file| {4337 return self.fail("TODO implement calling functions", .{});
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 }
4352 },4338 },
4353 .@"extern" => {4339 .@"extern" => {
4354 return self.fail("TODO implement calling extern functions", .{});4340 return self.fail("TODO implement calling extern functions", .{});
...@@ -6184,7 +6170,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {...@@ -6184,7 +6170,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
6184 .mcv => |mcv| switch (mcv) {6170 .mcv => |mcv| switch (mcv) {
6185 .none => .none,6171 .none => .none,
6186 .undef => .undef,6172 .undef => .undef,
6187 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO6173 .load_got, .load_symbol, .load_direct, .load_tlv, .lea_symbol => unreachable, // TODO
6188 .immediate => |imm| .{ .immediate = @truncate(imm) },6174 .immediate => |imm| .{ .immediate = @truncate(imm) },
6189 .memory => |addr| .{ .memory = addr },6175 .memory => |addr| .{ .memory = addr },
6190 },6176 },
src/arch/riscv64/CodeGen.zig+1
...@@ -8026,6 +8026,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {...@@ -8026,6 +8026,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
8026 .mcv => |mcv| switch (mcv) {8026 .mcv => |mcv| switch (mcv) {
8027 .none => .none,8027 .none => .none,
8028 .undef => unreachable,8028 .undef => unreachable,
8029 .lea_symbol => |sym_index| .{ .lea_symbol = .{ .sym = sym_index } },
8029 .load_symbol => |sym_index| .{ .load_symbol = .{ .sym = sym_index } },8030 .load_symbol => |sym_index| .{ .load_symbol = .{ .sym = sym_index } },
8030 .load_tlv => |sym_index| .{ .lea_tlv = sym_index },8031 .load_tlv => |sym_index| .{ .lea_tlv = sym_index },
8031 .immediate => |imm| .{ .immediate = imm },8032 .immediate => |imm| .{ .immediate = imm },
src/arch/riscv64/Emit.zig+1-12
...@@ -43,12 +43,6 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -43,12 +43,6 @@ pub fn emitMir(emit: *Emit) Error!void {
43 .fmt = std.meta.activeTag(lowered_inst),43 .fmt = std.meta.activeTag(lowered_inst),
44 }),44 }),
45 .load_symbol_reloc => |symbol| {45 .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
52 const elf_file = emit.bin_file.cast(.elf).?;46 const elf_file = emit.bin_file.cast(.elf).?;
53 const zo = elf_file.zigObjectPtr().?;47 const zo = elf_file.zigObjectPtr().?;
5448
...@@ -58,12 +52,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -58,12 +52,7 @@ pub fn emitMir(emit: *Emit) Error!void {
58 var hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20);52 var hi_r_type: u32 = @intFromEnum(std.elf.R_RISCV.HI20);
59 var lo_r_type: u32 = @intFromEnum(std.elf.R_RISCV.LO12_I);53 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) {55 if (sym.flags.needs_got) {
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) {
67 hi_r_type = Elf.R_GOT_HI20_STATIC; // TODO: rework this #2088756 hi_r_type = Elf.R_GOT_HI20_STATIC; // TODO: rework this #20887
68 lo_r_type = Elf.R_GOT_LO12_I_STATIC; // TODO: rework this #2088757 lo_r_type = Elf.R_GOT_LO12_I_STATIC; // TODO: rework this #20887
69 }58 }
src/arch/sparc64/CodeGen.zig+3-29
...@@ -1349,34 +1349,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1349,34 +1349,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1349 // Due to incremental compilation, how function calls are generated depends1349 // Due to incremental compilation, how function calls are generated depends
1350 // on linking.1350 // on linking.
1351 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {1351 if (try self.air.value(callee, pt)) |func_value| switch (ip.indexToKey(func_value.toIntern())) {
1352 .func => |func| {1352 .func => {
1353 const got_addr = if (self.bin_file.cast(.elf)) |elf_file| blk: {1353 return self.fail("TODO implement calling functions", .{});
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 });
1380 },1354 },
1381 .@"extern" => {1355 .@"extern" => {
1382 return self.fail("TODO implement calling extern functions", .{});1356 return self.fail("TODO implement calling extern functions", .{});
...@@ -4153,7 +4127,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {...@@ -4153,7 +4127,7 @@ fn genTypedValue(self: *Self, val: Value) InnerError!MCValue {
4153 .mcv => |mcv| switch (mcv) {4127 .mcv => |mcv| switch (mcv) {
4154 .none => .none,4128 .none => .none,
4155 .undef => .undef,4129 .undef => .undef,
4156 .load_got, .load_symbol, .load_direct, .load_tlv => unreachable, // TODO4130 .load_got, .load_symbol, .load_direct, .load_tlv, .lea_symbol => unreachable, // TODO
4157 .immediate => |imm| .{ .immediate = imm },4131 .immediate => |imm| .{ .immediate = imm },
4158 .memory => |addr| .{ .memory = addr },4132 .memory => |addr| .{ .memory = addr },
4159 },4133 },
src/link/Elf/ZigObject.zig+1-1
...@@ -1036,7 +1036,7 @@ pub fn updateFunc(...@@ -1036,7 +1036,7 @@ pub fn updateFunc(
1036 const ip = &zcu.intern_pool;1036 const ip = &zcu.intern_pool;
1037 const gpa = elf_file.base.comp.gpa;1037 const gpa = elf_file.base.comp.gpa;
1038 const func = zcu.funcInfo(func_index);1038 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) {
1040 try self.initJumpTable(gpa, elf_file);1040 try self.initJumpTable(gpa, elf_file);
1041 }1041 }
10421042