authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-30 07:30:32-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-01 19:22:52-04:00
log19bd7d12b0186f0e45c77c564251d6355966b2ef
tree3baaa33fc62f7857b264e2ffea96dac616c5a57b
parent372bc960b8315ea1ff17b369b0b33485d5e34cfb

x86_64: factor out lazy_sym


1 files changed, 10 insertions(+), 18 deletions(-)

src/arch/x86_64/CodeGen.zig+10-18
...@@ -6413,10 +6413,10 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -6413,10 +6413,10 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
6413 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);6413 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
6414 defer self.register_manager.unlockReg(addr_lock);6414 defer self.register_manager.unlockReg(addr_lock);
64156415
6416 const mod = self.bin_file.options.module.?;
6417 const lazy_sym = link.File.LazySymbol.initDecl(.const_data, null, mod);
6416 if (self.bin_file.cast(link.File.Elf)) |elf_file| {6418 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
6417 const atom_index = try elf_file.getOrCreateAtomForLazySymbol(6419 const atom_index = try elf_file.getOrCreateAtomForLazySymbol(lazy_sym);
6418 .{ .kind = .const_data, .ty = Type.anyerror },
6419 );
6420 const atom = elf_file.getAtom(atom_index);6420 const atom = elf_file.getAtom(atom_index);
6421 _ = try atom.getOrCreateOffsetTableEntry(elf_file);6421 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
6422 const got_addr = atom.getOffsetTableAddress(elf_file);6422 const got_addr = atom.getOffsetTableAddress(elf_file);
...@@ -6426,15 +6426,11 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -6426,15 +6426,11 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
6426 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(i32, got_addr) }),6426 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(i32, got_addr) }),
6427 );6427 );
6428 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {6428 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
6429 const atom_index = try coff_file.getOrCreateAtomForLazySymbol(6429 const atom_index = try coff_file.getOrCreateAtomForLazySymbol(lazy_sym);
6430 .{ .kind = .const_data, .ty = Type.anyerror },
6431 );
6432 const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?;6430 const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?;
6433 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });6431 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });
6434 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {6432 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
6435 const atom_index = try macho_file.getOrCreateAtomForLazySymbol(6433 const atom_index = try macho_file.getOrCreateAtomForLazySymbol(lazy_sym);
6436 .{ .kind = .const_data, .ty = Type.anyerror },
6437 );
6438 const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;6434 const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;
6439 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });6435 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });
6440 } else {6436 } else {
...@@ -8498,10 +8494,10 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -8498,10 +8494,10 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
8498 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);8494 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
8499 defer self.register_manager.unlockReg(addr_lock);8495 defer self.register_manager.unlockReg(addr_lock);
85008496
8497 const mod = self.bin_file.options.module.?;
8498 const lazy_sym = link.File.LazySymbol.initDecl(.const_data, null, mod);
8501 if (self.bin_file.cast(link.File.Elf)) |elf_file| {8499 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
8502 const atom_index = try elf_file.getOrCreateAtomForLazySymbol(8500 const atom_index = try elf_file.getOrCreateAtomForLazySymbol(lazy_sym);
8503 .{ .kind = .const_data, .ty = Type.anyerror },
8504 );
8505 const atom = elf_file.getAtom(atom_index);8501 const atom = elf_file.getAtom(atom_index);
8506 _ = try atom.getOrCreateOffsetTableEntry(elf_file);8502 _ = try atom.getOrCreateOffsetTableEntry(elf_file);
8507 const got_addr = atom.getOffsetTableAddress(elf_file);8503 const got_addr = atom.getOffsetTableAddress(elf_file);
...@@ -8511,15 +8507,11 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -8511,15 +8507,11 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
8511 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(i32, got_addr) }),8507 Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(i32, got_addr) }),
8512 );8508 );
8513 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {8509 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
8514 const atom_index = try coff_file.getOrCreateAtomForLazySymbol(8510 const atom_index = try coff_file.getOrCreateAtomForLazySymbol(lazy_sym);
8515 .{ .kind = .const_data, .ty = Type.anyerror },
8516 );
8517 const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?;8511 const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?;
8518 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });8512 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });
8519 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {8513 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
8520 const atom_index = try macho_file.getOrCreateAtomForLazySymbol(8514 const atom_index = try macho_file.getOrCreateAtomForLazySymbol(lazy_sym);
8521 .{ .kind = .const_data, .ty = Type.anyerror },
8522 );
8523 const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;8515 const sym_index = macho_file.getAtom(atom_index).getSymbolIndex().?;
8524 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });8516 try self.genSetReg(addr_reg, Type.usize, .{ .lea_got = sym_index });
8525 } else {8517 } else {