codegen: fix Elf symbol refs

This commit is contained in:
Jakub Konka 2024-08-07 06:50:54 +02:00
parent 89db24ec6d
commit 02f38d7749
2 changed files with 9 additions and 19 deletions

View File

@ -1415,9 +1415,8 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
.ty = enum_ty,
}) catch |err|
return func.fail("{s} creating lazy symbol", .{@errorName(err)});
const sym = zo.symbol(sym_index);
try func.genSetReg(Type.u64, data_reg, .{ .lea_symbol = .{ .sym = sym.esym_index } });
try func.genSetReg(Type.u64, data_reg, .{ .lea_symbol = .{ .sym = sym_index } });
const cmp_reg, const cmp_lock = try func.allocReg(.int);
defer func.register_manager.unlockReg(cmp_lock);
@ -4949,12 +4948,11 @@ fn genCall(
if (func.bin_file.cast(link.File.Elf)) |elf_file| {
const zo = elf_file.zigObjectPtr().?;
const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func_val.owner_decl);
const sym = zo.symbol(sym_index);
if (func.mod.pic) {
return func.fail("TODO: genCall pic", .{});
} else {
try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym.esym_index } });
try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym_index } });
_ = try func.addInst(.{
.tag = .jalr,
.data = .{ .i_type = .{
@ -7827,12 +7825,11 @@ fn airTagName(func: *Func, inst: Air.Inst.Index) !void {
const zo = elf_file.zigObjectPtr().?;
const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|
return func.fail("{s} creating lazy symbol", .{@errorName(err)});
const sym = zo.symbol(sym_index);
if (func.mod.pic) {
return func.fail("TODO: airTagName pic", .{});
} else {
try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym.esym_index } });
try func.genSetReg(Type.u64, .ra, .{ .load_symbol = .{ .sym = sym_index } });
_ = try func.addInst(.{
.tag = .jalr,
.data = .{ .i_type = .{
@ -8050,12 +8047,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
return error.CodegenFail;
};
switch (lf.tag) {
.elf => {
const elf_file = lf.cast(link.File.Elf).?;
const zo = elf_file.zigObjectPtr().?;
const local = zo.symbol(local_sym_index);
return MCValue{ .undef = local.esym_index };
},
.elf => return MCValue{ .undef = local_sym_index },
else => unreachable,
}
}

View File

@ -12329,7 +12329,6 @@ fn genCall(self: *Self, info: union(enum) {
if (self.bin_file.cast(link.File.Elf)) |elf_file| {
const zo = elf_file.zigObjectPtr().?;
const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
const sym = zo.symbol(sym_index);
if (self.mod.pic) {
const callee_reg: Register = switch (resolved_cc) {
.SysV => callee: {
@ -12346,14 +12345,14 @@ fn genCall(self: *Self, info: union(enum) {
try self.genSetReg(
callee_reg,
Type.usize,
.{ .load_symbol = .{ .sym = sym.esym_index } },
.{ .load_symbol = .{ .sym = sym_index } },
.{},
);
try self.asmRegister(.{ ._, .call }, callee_reg);
} else try self.asmMemory(.{ ._, .call }, .{
.base = .{ .reloc = .{
.atom_index = try self.owner.getSymbolIndex(self),
.sym_index = sym.esym_index,
.sym_index = sym_index,
} },
.mod = .{ .rm = .{ .size = .qword } },
});
@ -15324,14 +15323,13 @@ fn genLazySymbolRef(
const zo = elf_file.zigObjectPtr().?;
const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|
return self.fail("{s} creating lazy symbol", .{@errorName(err)});
const sym = zo.symbol(sym_index);
if (self.mod.pic) {
switch (tag) {
.lea, .call => try self.genSetReg(reg, Type.usize, .{
.load_symbol = .{ .sym = sym.esym_index },
.load_symbol = .{ .sym = sym_index },
}, .{}),
.mov => try self.genSetReg(reg, Type.usize, .{
.load_symbol = .{ .sym = sym.esym_index },
.load_symbol = .{ .sym = sym_index },
}, .{}),
else => unreachable,
}
@ -15343,7 +15341,7 @@ fn genLazySymbolRef(
} else {
const reloc = bits.Symbol{
.atom_index = try self.owner.getSymbolIndex(self),
.sym_index = sym.esym_index,
.sym_index = sym_index,
};
switch (tag) {
.lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), .{