authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-12 23:23:39+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-13 13:30:24+02:00
log78b1c736026443c937145ba85e1de52c11c9a44e
tree78dc76d86639d1f0604667c787ac1b78b2b98b63
parente1ce9a7065e92e3e9b61229c7903f82c3684f489

elf: rename OffsetTable to JumpTable


4 files changed, 91 insertions(+), 91 deletions(-)

src/link/Elf.zig+2-2
...@@ -5599,8 +5599,8 @@ fn fmtDumpState(...@@ -5599,8 +5599,8 @@ fn fmtDumpState(
5599 zig_object.fmtAtoms(self),5599 zig_object.fmtAtoms(self),
5600 zig_object.fmtSymtab(self),5600 zig_object.fmtSymtab(self),
5601 });5601 });
5602 if (zig_object.offset_table) |ot| {5602 if (zig_object.jump_table) |jt| {
5603 try writer.print("{}", .{ot.fmt(zig_object, self)});5603 try writer.print("{}", .{jt.fmt(zig_object, self)});
5604 }5604 }
5605 try writer.writeByte('\n');5605 try writer.writeByte('\n');
5606 }5606 }
src/link/Elf/Atom.zig+12-12
...@@ -750,8 +750,8 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi...@@ -750,8 +750,8 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi
750 const S = target.address(.{}, elf_file);750 const S = target.address(.{}, elf_file);
751 // Address of the global offset table.751 // Address of the global offset table.
752 const GOT = elf_file.gotAddress();752 const GOT = elf_file.gotAddress();
753 // Address of the offset table entry if any.753 // Address of the zig jump table entry if any.
754 const ZIG_GOT = target.zigOffsetTableAddress(elf_file);754 const ZJT = target.zigJumpTableAddress(elf_file);
755 // Relative offset to the start of the global offset table.755 // Relative offset to the start of the global offset table.
756 const G = target.gotAddress(elf_file) - GOT;756 const G = target.gotAddress(elf_file) - GOT;
757 // // Address of the thread pointer.757 // // Address of the thread pointer.
...@@ -759,19 +759,19 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi...@@ -759,19 +759,19 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi
759 // Address of the dynamic thread pointer.759 // Address of the dynamic thread pointer.
760 const DTP = elf_file.dtpAddress();760 const DTP = elf_file.dtpAddress();
761761
762 relocs_log.debug(" {s}: {x}: [{x} => {x}] G({x}) ZG({x}) ({s})", .{762 relocs_log.debug(" {s}: {x}: [{x} => {x}] GOT({x}) ZJT({x}) ({s})", .{
763 relocation.fmtRelocType(rel.r_type(), cpu_arch),763 relocation.fmtRelocType(rel.r_type(), cpu_arch),
764 r_offset,764 r_offset,
765 P,765 P,
766 S + A,766 S + A,
767 G + GOT + A,767 G + GOT + A,
768 ZIG_GOT + A,768 ZJT + A,
769 target.name(elf_file),769 target.name(elf_file),
770 });770 });
771771
772 try stream.seekTo(r_offset);772 try stream.seekTo(r_offset);
773773
774 const args = ResolveArgs{ P, A, S, GOT, G, TP, DTP, ZIG_GOT };774 const args = ResolveArgs{ P, A, S, GOT, G, TP, DTP, ZJT };
775775
776 switch (cpu_arch) {776 switch (cpu_arch) {
777 .x86_64 => x86_64.resolveRelocAlloc(self, elf_file, rel, target, args, &it, code, &stream) catch |err| switch (err) {777 .x86_64 => x86_64.resolveRelocAlloc(self, elf_file, rel, target, args, &it, code, &stream) catch |err| switch (err) {
...@@ -1200,7 +1200,7 @@ const x86_64 = struct {...@@ -1200,7 +1200,7 @@ const x86_64 = struct {
12001200
1201 const cwriter = stream.writer();1201 const cwriter = stream.writer();
12021202
1203 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args;1203 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZJT = args;
12041204
1205 switch (r_type) {1205 switch (r_type) {
1206 .NONE => unreachable,1206 .NONE => unreachable,
...@@ -1218,7 +1218,7 @@ const x86_64 = struct {...@@ -1218,7 +1218,7 @@ const x86_64 = struct {
1218 .PLT32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little),1218 .PLT32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little),
12191219
1220 .PC32 => {1220 .PC32 => {
1221 const S_ = if (target.flags.zig_offset_table) ZIG_GOT else S;1221 const S_ = if (target.flags.zig_jump_table) ZJT else S;
1222 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);1222 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
1223 },1223 },
12241224
...@@ -1245,7 +1245,7 @@ const x86_64 = struct {...@@ -1245,7 +1245,7 @@ const x86_64 = struct {
1245 },1245 },
12461246
1247 .@"32" => {1247 .@"32" => {
1248 const S_ = if (target.flags.zig_offset_table) ZIG_GOT else S;1248 const S_ = if (target.flags.zig_jump_table) ZJT else S;
1249 try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S_ + A)))), .little);1249 try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S_ + A)))), .little);
1250 },1250 },
1251 .@"32S" => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little),1251 .@"32S" => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little),
...@@ -1729,9 +1729,9 @@ const aarch64 = struct {...@@ -1729,9 +1729,9 @@ const aarch64 = struct {
1729 const code = code_buffer[r_offset..][0..4];1729 const code = code_buffer[r_offset..][0..4];
1730 const file_ptr = atom.file(elf_file).?;1730 const file_ptr = atom.file(elf_file).?;
17311731
1732 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args;1732 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZJT = args;
1733 _ = DTP;1733 _ = DTP;
1734 _ = ZIG_GOT;1734 _ = ZJT;
17351735
1736 switch (r_type) {1736 switch (r_type) {
1737 .NONE => unreachable,1737 .NONE => unreachable,
...@@ -2013,10 +2013,10 @@ const riscv = struct {...@@ -2013,10 +2013,10 @@ const riscv = struct {
2013 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;2013 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
2014 const cwriter = stream.writer();2014 const cwriter = stream.writer();
20152015
2016 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZIG_GOT = args;2016 const P, const A, const S, const GOT, const G, const TP, const DTP, const ZJT = args;
2017 _ = TP;2017 _ = TP;
2018 _ = DTP;2018 _ = DTP;
2019 _ = ZIG_GOT;2019 _ = ZJT;
20202020
2021 switch (r_type) {2021 switch (r_type) {
2022 .NONE => unreachable,2022 .NONE => unreachable,
src/link/Elf/Symbol.zig+9-9
...@@ -217,12 +217,12 @@ pub fn tlsDescAddress(symbol: Symbol, elf_file: *Elf) i64 {...@@ -217,12 +217,12 @@ pub fn tlsDescAddress(symbol: Symbol, elf_file: *Elf) i64 {
217 return entry.address(elf_file);217 return entry.address(elf_file);
218}218}
219219
220pub fn zigOffsetTableAddress(symbol: Symbol, elf_file: *Elf) i64 {220pub fn zigJumpTableAddress(symbol: Symbol, elf_file: *Elf) i64 {
221 if (!symbol.flags.zig_offset_table) return 0;221 if (!symbol.flags.zig_jump_table) return 0;
222 const zo = elf_file.zigObjectPtr().?;222 const zo = elf_file.zigObjectPtr().?;
223 const offset_table = zo.offsetTablePtr().?;223 const jump_table = zo.jumpTablePtr().?;
224 const ot_index = symbol.extra(elf_file).zig_offset_table;224 const jt_index = symbol.extra(elf_file).zig_jump_table;
225 return offset_table.entryAddress(ot_index, zo, elf_file);225 return jump_table.entryAddress(jt_index, zo, elf_file);
226}226}
227227
228pub fn dsoAlignment(symbol: Symbol, elf_file: *Elf) !u64 {228pub fn dsoAlignment(symbol: Symbol, elf_file: *Elf) !u64 {
...@@ -248,7 +248,7 @@ const AddExtraOpts = struct {...@@ -248,7 +248,7 @@ const AddExtraOpts = struct {
248 tlsgd: ?u32 = null,248 tlsgd: ?u32 = null,
249 gottp: ?u32 = null,249 gottp: ?u32 = null,
250 tlsdesc: ?u32 = null,250 tlsdesc: ?u32 = null,
251 zig_offset_table: ?u32 = null,251 zig_jump_table: ?u32 = null,
252};252};
253253
254pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) void {254pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) void {
...@@ -453,8 +453,8 @@ pub const Flags = packed struct {...@@ -453,8 +453,8 @@ pub const Flags = packed struct {
453 /// Whether the symbol is a merge subsection.453 /// Whether the symbol is a merge subsection.
454 merge_subsection: bool = false,454 merge_subsection: bool = false,
455455
456 /// Whether the symbol has __zig_offset_table indirection.456 /// Whether the symbol has __zig_jump_table indirection.
457 zig_offset_table: bool = false,457 zig_jump_table: bool = false,
458};458};
459459
460pub const Extra = struct {460pub const Extra = struct {
...@@ -468,7 +468,7 @@ pub const Extra = struct {...@@ -468,7 +468,7 @@ pub const Extra = struct {
468 gottp: u32 = 0,468 gottp: u32 = 0,
469 tlsdesc: u32 = 0,469 tlsdesc: u32 = 0,
470 merge_section: u32 = 0,470 merge_section: u32 = 0,
471 zig_offset_table: u32 = 0,471 zig_jump_table: u32 = 0,
472};472};
473473
474pub const Index = u32;474pub const Index = u32;
src/link/Elf/ZigObject.zig+68-68
...@@ -55,10 +55,10 @@ debug_str_section_zig_size: u64 = 0,...@@ -55,10 +55,10 @@ debug_str_section_zig_size: u64 = 0,
55debug_aranges_section_zig_size: u64 = 0,55debug_aranges_section_zig_size: u64 = 0,
56debug_line_section_zig_size: u64 = 0,56debug_line_section_zig_size: u64 = 0,
5757
58/// Function offset table containing pointers to Zig generated functions.58/// Function jump table containing trampolines to Zcu functions.
59/// The table is used for Zig's incremental compilation and is embedded with59/// The table is used for Zig's incremental compilation and is embedded with
60/// the machine code section.60/// the machine code section.
61offset_table: ?OffsetTable = null,61jump_table: ?JumpTable = null,
6262
63pub const global_symbol_bit: u32 = 0x80000000;63pub const global_symbol_bit: u32 = 0x80000000;
64pub const symbol_mask: u32 = 0x7fffffff;64pub const symbol_mask: u32 = 0x7fffffff;
...@@ -128,8 +128,8 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {...@@ -128,8 +128,8 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
128 dw.deinit();128 dw.deinit();
129 }129 }
130130
131 if (self.offset_table) |*ot| {131 if (self.jump_table) |*jt| {
132 ot.deinit(allocator);132 jt.deinit(allocator);
133 }133 }
134}134}
135135
...@@ -917,8 +917,8 @@ fn updateNavCode(...@@ -917,8 +917,8 @@ fn updateNavCode(
917917
918 if (stt_bits == elf.STT_FUNC) {918 if (stt_bits == elf.STT_FUNC) {
919 const extra = sym.extra(elf_file);919 const extra = sym.extra(elf_file);
920 const offset_table = self.offsetTablePtr().?;920 const jump_table = self.jumpTablePtr().?;
921 offset_table.entries.items(.dirty)[extra.zig_offset_table] = true;921 jump_table.entries.items(.dirty)[extra.zig_jump_table] = true;
922 }922 }
923 }923 }
924 } else if (code.len < old_size) {924 } else if (code.len < old_size) {
...@@ -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 const offset_table = self.offsetTablePtr() orelse try self.initOffsetTable(gpa, elf_file);1039 const jump_table = self.jumpTablePtr() orelse try self.initJumpTable(gpa, elf_file);
10401040
1041 log.debug("updateFunc {}({d})", .{ ip.getNav(func.owner_nav).fqn.fmt(ip), func.owner_nav });1041 log.debug("updateFunc {}({d})", .{ ip.getNav(func.owner_nav).fqn.fmt(ip), func.owner_nav });
10421042
...@@ -1045,16 +1045,16 @@ pub fn updateFunc(...@@ -1045,16 +1045,16 @@ pub fn updateFunc(
10451045
1046 {1046 {
1047 const sym = self.symbol(sym_index);1047 const sym = self.symbol(sym_index);
1048 if (!sym.flags.zig_offset_table) {1048 if (!sym.flags.zig_jump_table) {
1049 const index = try offset_table.addSymbol(gpa, sym_index);1049 const index = try jump_table.addSymbol(gpa, sym_index);
1050 sym.flags.zig_offset_table = true;1050 sym.flags.zig_jump_table = true;
1051 sym.addExtra(.{ .zig_offset_table = index }, elf_file);1051 sym.addExtra(.{ .zig_jump_table = index }, elf_file);
1052 try offset_table.updateSize(self, elf_file);1052 try jump_table.updateSize(self, elf_file);
1053 const old_vaddr = offset_table.address(self, elf_file);1053 const old_vaddr = jump_table.address(self, elf_file);
1054 try self.symbol(offset_table.sym_index).atom(elf_file).?.allocate(elf_file);1054 try self.symbol(jump_table.sym_index).atom(elf_file).?.allocate(elf_file);
1055 const new_vaddr = offset_table.address(self, elf_file);1055 const new_vaddr = jump_table.address(self, elf_file);
1056 if (old_vaddr != new_vaddr) {1056 if (old_vaddr != new_vaddr) {
1057 offset_table.dirty = true;1057 jump_table.dirty = true;
1058 }1058 }
1059 }1059 }
1060 }1060 }
...@@ -1100,21 +1100,21 @@ pub fn updateFunc(...@@ -1100,21 +1100,21 @@ pub fn updateFunc(
11001100
1101 // Exports will be updated by `Zcu.processExports` after the update.1101 // Exports will be updated by `Zcu.processExports` after the update.
11021102
1103 if (offset_table.dirty) {1103 if (jump_table.dirty) {
1104 // TODO write in bulk1104 // TODO write in bulk
1105 for (offset_table.entries.items(.dirty), 0..) |*dirty, i| {1105 for (jump_table.entries.items(.dirty), 0..) |*dirty, i| {
1106 try offset_table.writeEntry(@intCast(i), self, elf_file);1106 try jump_table.writeEntry(@intCast(i), self, elf_file);
1107 dirty.* = false;1107 dirty.* = false;
1108 }1108 }
1109 } else {1109 } else {
1110 const sym = self.symbol(sym_index);1110 const sym = self.symbol(sym_index);
1111 const ot_index = sym.extra(elf_file).zig_offset_table;1111 const jt_index = sym.extra(elf_file).zig_jump_table;
1112 var ot_entry = offset_table.entries.get(ot_index);1112 var jt_entry = jump_table.entries.get(jt_index);
1113 if (ot_entry.dirty) {1113 if (jt_entry.dirty) {
1114 try offset_table.writeEntry(ot_index, self, elf_file);1114 try jump_table.writeEntry(jt_index, self, elf_file);
1115 ot_entry.dirty = false;1115 jt_entry.dirty = false;
1116 }1116 }
1117 offset_table.entries.set(ot_index, ot_entry);1117 jump_table.entries.set(jt_index, jt_entry);
1118 }1118 }
1119}1119}
11201120
...@@ -1470,22 +1470,22 @@ pub fn getGlobalSymbol(self: *ZigObject, elf_file: *Elf, name: []const u8, lib_n...@@ -1470,22 +1470,22 @@ pub fn getGlobalSymbol(self: *ZigObject, elf_file: *Elf, name: []const u8, lib_n
1470 return lookup_gop.value_ptr.*;1470 return lookup_gop.value_ptr.*;
1471}1471}
14721472
1473pub fn offsetTablePtr(self: *ZigObject) ?*OffsetTable {1473pub fn jumpTablePtr(self: *ZigObject) ?*JumpTable {
1474 return if (self.offset_table) |*ot| ot else null;1474 return if (self.jump_table) |*jt| jt else null;
1475}1475}
14761476
1477fn initOffsetTable(self: *ZigObject, allocator: Allocator, elf_file: *Elf) error{OutOfMemory}!*OffsetTable {1477fn initJumpTable(self: *ZigObject, allocator: Allocator, elf_file: *Elf) error{OutOfMemory}!*JumpTable {
1478 const name_off = try self.addString(allocator, "__zig_offset_table");1478 const name_off = try self.addString(allocator, "__zig_jump_table");
1479 const sym_index = try self.newSymbolWithAtom(allocator, name_off);1479 const sym_index = try self.newSymbolWithAtom(allocator, name_off);
1480 const sym = self.symbol(sym_index);1480 const sym = self.symbol(sym_index);
1481 const esym = &self.symtab.items(.elf_sym)[sym.esym_index];1481 const esym = &self.symtab.items(.elf_sym)[sym.esym_index];
1482 esym.st_info |= elf.STT_OBJECT;1482 esym.st_info |= elf.STT_OBJECT;
1483 const atom_ptr = sym.atom(elf_file).?;1483 const atom_ptr = sym.atom(elf_file).?;
1484 atom_ptr.alive = true;1484 atom_ptr.alive = true;
1485 atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(OffsetTable.alignment(elf_file.getTarget().cpu.arch));1485 atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(JumpTable.alignment(elf_file.getTarget().cpu.arch));
1486 atom_ptr.output_section_index = elf_file.zig_text_section_index.?;1486 atom_ptr.output_section_index = elf_file.zig_text_section_index.?;
1487 self.offset_table = OffsetTable{ .sym_index = sym_index };1487 self.jump_table = JumpTable{ .sym_index = sym_index };
1488 return &(self.offset_table.?);1488 return &(self.jump_table.?);
1489}1489}
14901490
1491pub fn asFile(self: *ZigObject) File {1491pub fn asFile(self: *ZigObject) File {
...@@ -1763,28 +1763,28 @@ const UavTable = std.AutoArrayHashMapUnmanaged(InternPool.Index, AvMetadata);...@@ -1763,28 +1763,28 @@ const UavTable = std.AutoArrayHashMapUnmanaged(InternPool.Index, AvMetadata);
1763const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.Index, LazySymbolMetadata);1763const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.Index, LazySymbolMetadata);
1764const TlsTable = std.AutoArrayHashMapUnmanaged(Atom.Index, TlsVariable);1764const TlsTable = std.AutoArrayHashMapUnmanaged(Atom.Index, TlsVariable);
17651765
1766pub const OffsetTable = struct {1766pub const JumpTable = struct {
1767 sym_index: Symbol.Index,1767 sym_index: Symbol.Index,
1768 entries: std.MultiArrayList(Entry) = .{},1768 entries: std.MultiArrayList(Entry) = .{},
1769 dirty: bool = false,1769 dirty: bool = false,
17701770
1771 pub fn deinit(ot: *OffsetTable, allocator: Allocator) void {1771 pub fn deinit(jt: *JumpTable, allocator: Allocator) void {
1772 ot.entries.deinit(allocator);1772 jt.entries.deinit(allocator);
1773 }1773 }
17741774
1775 pub fn addSymbol(ot: *OffsetTable, allocator: Allocator, sym_index: Symbol.Index) !Index {1775 pub fn addSymbol(jt: *JumpTable, allocator: Allocator, sym_index: Symbol.Index) !Index {
1776 const index: Index = @intCast(try ot.entries.addOne(allocator));1776 const index: Index = @intCast(try jt.entries.addOne(allocator));
1777 ot.entries.set(index, .{ .sym_index = sym_index });1777 jt.entries.set(index, .{ .sym_index = sym_index });
1778 return index;1778 return index;
1779 }1779 }
17801780
1781 pub fn address(ot: OffsetTable, zo: *ZigObject, elf_file: *Elf) i64 {1781 pub fn address(jt: JumpTable, zo: *ZigObject, elf_file: *Elf) i64 {
1782 const sym = zo.symbol(ot.sym_index);1782 const sym = zo.symbol(jt.sym_index);
1783 return sym.address(.{}, elf_file);1783 return sym.address(.{}, elf_file);
1784 }1784 }
17851785
1786 pub fn size(ot: OffsetTable, zo: *ZigObject, elf_file: *Elf) u64 {1786 pub fn size(jt: JumpTable, zo: *ZigObject, elf_file: *Elf) u64 {
1787 const sym = zo.symbol(ot.sym_index);1787 const sym = zo.symbol(jt.sym_index);
1788 return sym.atom(elf_file).?.size;1788 return sym.atom(elf_file).?.size;
1789 }1789 }
17901790
...@@ -1795,12 +1795,12 @@ pub const OffsetTable = struct {...@@ -1795,12 +1795,12 @@ pub const OffsetTable = struct {
1795 };1795 };
1796 }1796 }
17971797
1798 pub fn entryAddress(ot: OffsetTable, index: Index, zo: *ZigObject, elf_file: *Elf) i64 {1798 pub fn entryAddress(jt: JumpTable, index: Index, zo: *ZigObject, elf_file: *Elf) i64 {
1799 return ot.address(zo, elf_file) + @as(i64, @intCast(index * entrySize(elf_file.getTarget().cpu.arch)));1799 return jt.address(zo, elf_file) + @as(i64, @intCast(index * entrySize(elf_file.getTarget().cpu.arch)));
1800 }1800 }
18011801
1802 pub fn entryOffset(ot: OffsetTable, index: Index, zo: *ZigObject, elf_file: *Elf) u64 {1802 pub fn entryOffset(jt: JumpTable, index: Index, zo: *ZigObject, elf_file: *Elf) u64 {
1803 const sym = zo.symbol(ot.sym_index);1803 const sym = zo.symbol(jt.sym_index);
1804 const atom_ptr = sym.atom(elf_file).?;1804 const atom_ptr = sym.atom(elf_file).?;
1805 const shdr = elf_file.shdrs.items[atom_ptr.output_section_index];1805 const shdr = elf_file.shdrs.items[atom_ptr.output_section_index];
1806 return shdr.sh_offset + @as(u64, @intCast(atom_ptr.value)) + index * entrySize(elf_file.getTarget().cpu.arch);1806 return shdr.sh_offset + @as(u64, @intCast(atom_ptr.value)) + index * entrySize(elf_file.getTarget().cpu.arch);
...@@ -1815,17 +1815,17 @@ pub const OffsetTable = struct {...@@ -1815,17 +1815,17 @@ pub const OffsetTable = struct {
1815 return seq_len;1815 return seq_len;
1816 }1816 }
18171817
1818 pub fn targetAddress(ot: OffsetTable, index: Index, zo: *ZigObject, elf_file: *Elf) i64 {1818 pub fn targetAddress(jt: JumpTable, index: Index, zo: *ZigObject, elf_file: *Elf) i64 {
1819 const sym_index = ot.entries.items(.sym_index)[index];1819 const sym_index = jt.entries.items(.sym_index)[index];
1820 return zo.symbol(sym_index).address(.{}, elf_file);1820 return zo.symbol(sym_index).address(.{}, elf_file);
1821 }1821 }
18221822
1823 const max_jump_seq_len = 12;1823 const max_jump_seq_len = 12;
18241824
1825 pub fn writeEntry(ot: OffsetTable, index: Index, zo: *ZigObject, elf_file: *Elf) !void {1825 pub fn writeEntry(jt: JumpTable, index: Index, zo: *ZigObject, elf_file: *Elf) !void {
1826 const fileoff = ot.entryOffset(index, zo, elf_file);1826 const fileoff = jt.entryOffset(index, zo, elf_file);
1827 const source_addr = ot.entryAddress(index, zo, elf_file);1827 const source_addr = jt.entryAddress(index, zo, elf_file);
1828 const target_addr = @as(i64, @intCast(ot.targetAddress(index, zo, elf_file)));1828 const target_addr = @as(i64, @intCast(jt.targetAddress(index, zo, elf_file)));
1829 var buf: [max_jump_seq_len]u8 = undefined;1829 var buf: [max_jump_seq_len]u8 = undefined;
1830 const out = switch (elf_file.getTarget().cpu.arch) {1830 const out = switch (elf_file.getTarget().cpu.arch) {
1831 .x86_64 => try x86_64.writeEntry(source_addr, target_addr, &buf),1831 .x86_64 => try x86_64.writeEntry(source_addr, target_addr, &buf),
...@@ -1855,46 +1855,46 @@ pub const OffsetTable = struct {...@@ -1855,46 +1855,46 @@ pub const OffsetTable = struct {
1855 }1855 }
1856 }1856 }
18571857
1858 pub fn updateSize(ot: OffsetTable, zo: *ZigObject, elf_file: *Elf) !void {1858 pub fn updateSize(jt: JumpTable, zo: *ZigObject, elf_file: *Elf) !void {
1859 const ot_size: u64 = @intCast(ot.entries.items(.sym_index).len * entrySize(elf_file.getTarget().cpu.arch));1859 const jt_size: u64 = @intCast(jt.entries.items(.sym_index).len * entrySize(elf_file.getTarget().cpu.arch));
1860 const sym = zo.symbol(ot.sym_index);1860 const sym = zo.symbol(jt.sym_index);
1861 const esym = &zo.symtab.items(.elf_sym)[sym.esym_index];1861 const esym = &zo.symtab.items(.elf_sym)[sym.esym_index];
1862 esym.st_size = ot_size;1862 esym.st_size = jt_size;
1863 const atom_ptr = sym.atom(elf_file).?;1863 const atom_ptr = sym.atom(elf_file).?;
1864 atom_ptr.size = ot_size;1864 atom_ptr.size = jt_size;
1865 }1865 }
18661866
1867 const OffsetTableFormatContext = struct { OffsetTable, *ZigObject, *Elf };1867 const JumpTableFormatContext = struct { JumpTable, *ZigObject, *Elf };
18681868
1869 pub fn format(1869 pub fn format(
1870 ot: OffsetTable,1870 jt: JumpTable,
1871 comptime unused_fmt_string: []const u8,1871 comptime unused_fmt_string: []const u8,
1872 options: std.fmt.FormatOptions,1872 options: std.fmt.FormatOptions,
1873 writer: anytype,1873 writer: anytype,
1874 ) !void {1874 ) !void {
1875 _ = ot;1875 _ = jt;
1876 _ = unused_fmt_string;1876 _ = unused_fmt_string;
1877 _ = options;1877 _ = options;
1878 _ = writer;1878 _ = writer;
1879 @compileError("do not format OffsetTable directly");1879 @compileError("do not format JumpTable directly");
1880 }1880 }
18811881
1882 pub fn fmt(ot: OffsetTable, zo: *ZigObject, elf_file: *Elf) std.fmt.Formatter(format2) {1882 pub fn fmt(jt: JumpTable, zo: *ZigObject, elf_file: *Elf) std.fmt.Formatter(format2) {
1883 return .{ .data = .{ ot, zo, elf_file } };1883 return .{ .data = .{ jt, zo, elf_file } };
1884 }1884 }
18851885
1886 fn format2(1886 fn format2(
1887 ctx: OffsetTableFormatContext,1887 ctx: JumpTableFormatContext,
1888 comptime unused_fmt_string: []const u8,1888 comptime unused_fmt_string: []const u8,
1889 options: std.fmt.FormatOptions,1889 options: std.fmt.FormatOptions,
1890 writer: anytype,1890 writer: anytype,
1891 ) !void {1891 ) !void {
1892 _ = options;1892 _ = options;
1893 _ = unused_fmt_string;1893 _ = unused_fmt_string;
1894 const ot, const zo, const ef = ctx;1894 const jt, const zo, const ef = ctx;
1895 try writer.writeAll("offset table\n");1895 try writer.writeAll("__zig_jump_table\n");
1896 try writer.print(" @{x} : size({x})\n", .{ ot.address(zo, ef), ot.size(zo, ef) });1896 try writer.print(" @{x} : size({x})\n", .{ jt.address(zo, ef), jt.size(zo, ef) });
1897 for (ot.entries.items(.sym_index), ot.entries.items(.dirty)) |sym_index, dirty| {1897 for (jt.entries.items(.sym_index), jt.entries.items(.dirty)) |sym_index, dirty| {
1898 const sym = zo.symbol(sym_index);1898 const sym = zo.symbol(sym_index);
1899 try writer.print(" %{d} : {s} : @{x}", .{ sym_index, sym.name(ef), sym.address(.{}, ef) });1899 try writer.print(" %{d} : {s} : @{x}", .{ sym_index, sym.name(ef), sym.address(.{}, ef) });
1900 if (dirty) try writer.writeAll(" : [!]");1900 if (dirty) try writer.writeAll(" : [!]");