authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-07 06:50:54+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-07 10:21:03+02:00
log02f38d7749e5260dc2f48caef10390dd8d3cede5
treeb20c72678ae41e51bfd6b9c1e10ab5aaa3112297
parent89db24ec6d6195cc10f17bf21dd9bf23e6ff1bf1

codegen: fix Elf symbol refs


2 files changed, 9 insertions(+), 19 deletions(-)

src/arch/riscv64/CodeGen.zig+4-12
......@@ -1415,9 +1415,8 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
14151415 .ty = enum_ty,
14161416 }) catch |err|
14171417 return func.fail("{s} creating lazy symbol", .{@errorName(err)});
1418 const sym = zo.symbol(sym_index);
14191418
1420 try func.genSetReg(Type.u64, data_reg, .{ .lea_symbol = .{ .sym = sym.esym_index } });
1419 try func.genSetReg(Type.u64, data_reg, .{ .lea_symbol = .{ .sym = sym_index } });
14211420
14221421 const cmp_reg, const cmp_lock = try func.allocReg(.int);
14231422 defer func.register_manager.unlockReg(cmp_lock);
......@@ -4949,12 +4948,11 @@ fn genCall(
49494948 if (func.bin_file.cast(link.File.Elf)) |elf_file| {
49504949 const zo = elf_file.zigObjectPtr().?;
49514950 const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func_val.owner_decl);
4952 const sym = zo.symbol(sym_index);
49534951
49544952 if (func.mod.pic) {
49554953 return func.fail("TODO: genCall pic", .{});
49564954 } else {
4957 try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym.esym_index } });
4955 try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym_index } });
49584956 _ = try func.addInst(.{
49594957 .tag = .jalr,
49604958 .data = .{ .i_type = .{
......@@ -7827,12 +7825,11 @@ fn airTagName(func: *Func, inst: Air.Inst.Index) !void {
78277825 const zo = elf_file.zigObjectPtr().?;
78287826 const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|
78297827 return func.fail("{s} creating lazy symbol", .{@errorName(err)});
7830 const sym = zo.symbol(sym_index);
78317828
78327829 if (func.mod.pic) {
78337830 return func.fail("TODO: airTagName pic", .{});
78347831 } else {
7835 try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym.esym_index } });
7832 try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym_index } });
78367833 _ = try func.addInst(.{
78377834 .tag = .jalr,
78387835 .data = .{ .i_type = .{
......@@ -8050,12 +8047,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
80508047 return error.CodegenFail;
80518048 };
80528049 switch (lf.tag) {
8053 .elf => {
8054 const elf_file = lf.cast(link.File.Elf).?;
8055 const zo = elf_file.zigObjectPtr().?;
8056 const local = zo.symbol(local_sym_index);
8057 return MCValue{ .undef = local.esym_index };
8058 },
8050 .elf => return MCValue{ .undef = local_sym_index },
80598051 else => unreachable,
80608052 }
80618053 }
src/arch/x86_64/CodeGen.zig+5-7
......@@ -12329,7 +12329,6 @@ fn genCall(self: *Self, info: union(enum) {
1232912329 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
1233012330 const zo = elf_file.zigObjectPtr().?;
1233112331 const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
12332 const sym = zo.symbol(sym_index);
1233312332 if (self.mod.pic) {
1233412333 const callee_reg: Register = switch (resolved_cc) {
1233512334 .SysV => callee: {
......@@ -12346,14 +12345,14 @@ fn genCall(self: *Self, info: union(enum) {
1234612345 try self.genSetReg(
1234712346 callee_reg,
1234812347 Type.usize,
12349 .{ .load_symbol = .{ .sym = sym.esym_index } },
12348 .{ .load_symbol = .{ .sym = sym_index } },
1235012349 .{},
1235112350 );
1235212351 try self.asmRegister(.{ ._, .call }, callee_reg);
1235312352 } else try self.asmMemory(.{ ._, .call }, .{
1235412353 .base = .{ .reloc = .{
1235512354 .atom_index = try self.owner.getSymbolIndex(self),
12356 .sym_index = sym.esym_index,
12355 .sym_index = sym_index,
1235712356 } },
1235812357 .mod = .{ .rm = .{ .size = .qword } },
1235912358 });
......@@ -15324,14 +15323,13 @@ fn genLazySymbolRef(
1532415323 const zo = elf_file.zigObjectPtr().?;
1532515324 const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|
1532615325 return self.fail("{s} creating lazy symbol", .{@errorName(err)});
15327 const sym = zo.symbol(sym_index);
1532815326 if (self.mod.pic) {
1532915327 switch (tag) {
1533015328 .lea, .call => try self.genSetReg(reg, Type.usize, .{
15331 .load_symbol = .{ .sym = sym.esym_index },
15329 .load_symbol = .{ .sym = sym_index },
1533215330 }, .{}),
1533315331 .mov => try self.genSetReg(reg, Type.usize, .{
15334 .load_symbol = .{ .sym = sym.esym_index },
15332 .load_symbol = .{ .sym = sym_index },
1533515333 }, .{}),
1533615334 else => unreachable,
1533715335 }
......@@ -15343,7 +15341,7 @@ fn genLazySymbolRef(
1534315341 } else {
1534415342 const reloc = bits.Symbol{
1534515343 .atom_index = try self.owner.getSymbolIndex(self),
15346 .sym_index = sym.esym_index,
15344 .sym_index = sym_index,
1534715345 };
1534815346 switch (tag) {
1534915347 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), .{