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 {...@@ -1415,9 +1415,8 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
1415 .ty = enum_ty,1415 .ty = enum_ty,
1416 }) catch |err|1416 }) catch |err|
1417 return func.fail("{s} creating lazy symbol", .{@errorName(err)});1417 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
1422 const cmp_reg, const cmp_lock = try func.allocReg(.int);1421 const cmp_reg, const cmp_lock = try func.allocReg(.int);
1423 defer func.register_manager.unlockReg(cmp_lock);1422 defer func.register_manager.unlockReg(cmp_lock);
...@@ -4949,12 +4948,11 @@ fn genCall(...@@ -4949,12 +4948,11 @@ fn genCall(
4949 if (func.bin_file.cast(link.File.Elf)) |elf_file| {4948 if (func.bin_file.cast(link.File.Elf)) |elf_file| {
4950 const zo = elf_file.zigObjectPtr().?;4949 const zo = elf_file.zigObjectPtr().?;
4951 const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func_val.owner_decl);4950 const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func_val.owner_decl);
4952 const sym = zo.symbol(sym_index);
49534951
4954 if (func.mod.pic) {4952 if (func.mod.pic) {
4955 return func.fail("TODO: genCall pic", .{});4953 return func.fail("TODO: genCall pic", .{});
4956 } else {4954 } 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 } });
4958 _ = try func.addInst(.{4956 _ = try func.addInst(.{
4959 .tag = .jalr,4957 .tag = .jalr,
4960 .data = .{ .i_type = .{4958 .data = .{ .i_type = .{
...@@ -7827,12 +7825,11 @@ fn airTagName(func: *Func, inst: Air.Inst.Index) !void {...@@ -7827,12 +7825,11 @@ fn airTagName(func: *Func, inst: Air.Inst.Index) !void {
7827 const zo = elf_file.zigObjectPtr().?;7825 const zo = elf_file.zigObjectPtr().?;
7828 const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|7826 const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|
7829 return func.fail("{s} creating lazy symbol", .{@errorName(err)});7827 return func.fail("{s} creating lazy symbol", .{@errorName(err)});
7830 const sym = zo.symbol(sym_index);
78317828
7832 if (func.mod.pic) {7829 if (func.mod.pic) {
7833 return func.fail("TODO: airTagName pic", .{});7830 return func.fail("TODO: airTagName pic", .{});
7834 } else {7831 } 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 } });
7836 _ = try func.addInst(.{7833 _ = try func.addInst(.{
7837 .tag = .jalr,7834 .tag = .jalr,
7838 .data = .{ .i_type = .{7835 .data = .{ .i_type = .{
...@@ -8050,12 +8047,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {...@@ -8050,12 +8047,7 @@ fn genTypedValue(func: *Func, val: Value) InnerError!MCValue {
8050 return error.CodegenFail;8047 return error.CodegenFail;
8051 };8048 };
8052 switch (lf.tag) {8049 switch (lf.tag) {
8053 .elf => {8050 .elf => return MCValue{ .undef = local_sym_index },
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 },
8059 else => unreachable,8051 else => unreachable,
8060 }8052 }
8061 }8053 }
src/arch/x86_64/CodeGen.zig+5-7
...@@ -12329,7 +12329,6 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12329,7 +12329,6 @@ fn genCall(self: *Self, info: union(enum) {
12329 if (self.bin_file.cast(link.File.Elf)) |elf_file| {12329 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
12330 const zo = elf_file.zigObjectPtr().?;12330 const zo = elf_file.zigObjectPtr().?;
12331 const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func.owner_decl);12331 const sym_index = try zo.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
12332 const sym = zo.symbol(sym_index);
12333 if (self.mod.pic) {12332 if (self.mod.pic) {
12334 const callee_reg: Register = switch (resolved_cc) {12333 const callee_reg: Register = switch (resolved_cc) {
12335 .SysV => callee: {12334 .SysV => callee: {
...@@ -12346,14 +12345,14 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12346,14 +12345,14 @@ fn genCall(self: *Self, info: union(enum) {
12346 try self.genSetReg(12345 try self.genSetReg(
12347 callee_reg,12346 callee_reg,
12348 Type.usize,12347 Type.usize,
12349 .{ .load_symbol = .{ .sym = sym.esym_index } },12348 .{ .load_symbol = .{ .sym = sym_index } },
12350 .{},12349 .{},
12351 );12350 );
12352 try self.asmRegister(.{ ._, .call }, callee_reg);12351 try self.asmRegister(.{ ._, .call }, callee_reg);
12353 } else try self.asmMemory(.{ ._, .call }, .{12352 } else try self.asmMemory(.{ ._, .call }, .{
12354 .base = .{ .reloc = .{12353 .base = .{ .reloc = .{
12355 .atom_index = try self.owner.getSymbolIndex(self),12354 .atom_index = try self.owner.getSymbolIndex(self),
12356 .sym_index = sym.esym_index,12355 .sym_index = sym_index,
12357 } },12356 } },
12358 .mod = .{ .rm = .{ .size = .qword } },12357 .mod = .{ .rm = .{ .size = .qword } },
12359 });12358 });
...@@ -15324,14 +15323,13 @@ fn genLazySymbolRef(...@@ -15324,14 +15323,13 @@ fn genLazySymbolRef(
15324 const zo = elf_file.zigObjectPtr().?;15323 const zo = elf_file.zigObjectPtr().?;
15325 const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|15324 const sym_index = zo.getOrCreateMetadataForLazySymbol(elf_file, pt, lazy_sym) catch |err|
15326 return self.fail("{s} creating lazy symbol", .{@errorName(err)});15325 return self.fail("{s} creating lazy symbol", .{@errorName(err)});
15327 const sym = zo.symbol(sym_index);
15328 if (self.mod.pic) {15326 if (self.mod.pic) {
15329 switch (tag) {15327 switch (tag) {
15330 .lea, .call => try self.genSetReg(reg, Type.usize, .{15328 .lea, .call => try self.genSetReg(reg, Type.usize, .{
15331 .load_symbol = .{ .sym = sym.esym_index },15329 .load_symbol = .{ .sym = sym_index },
15332 }, .{}),15330 }, .{}),
15333 .mov => try self.genSetReg(reg, Type.usize, .{15331 .mov => try self.genSetReg(reg, Type.usize, .{
15334 .load_symbol = .{ .sym = sym.esym_index },15332 .load_symbol = .{ .sym = sym_index },
15335 }, .{}),15333 }, .{}),
15336 else => unreachable,15334 else => unreachable,
15337 }15335 }
...@@ -15343,7 +15341,7 @@ fn genLazySymbolRef(...@@ -15343,7 +15341,7 @@ fn genLazySymbolRef(
15343 } else {15341 } else {
15344 const reloc = bits.Symbol{15342 const reloc = bits.Symbol{
15345 .atom_index = try self.owner.getSymbolIndex(self),15343 .atom_index = try self.owner.getSymbolIndex(self),
15346 .sym_index = sym.esym_index,15344 .sym_index = sym_index,
15347 };15345 };
15348 switch (tag) {15346 switch (tag) {
15349 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), .{15347 .lea, .mov => try self.asmRegisterMemory(.{ ._, .mov }, reg.to64(), .{