| ... | ... | @@ -55,6 +55,8 @@ debug_str_section_zig_size: u64 = 0, |
| 55 | 55 | debug_aranges_section_zig_size: u64 = 0, |
| 56 | 56 | debug_line_section_zig_size: u64 = 0, |
| 57 | 57 | |
| 58 | func_offset_table: ?OffsetTable = null, |
| 59 | |
| 58 | 60 | pub const global_symbol_bit: u32 = 0x80000000; |
| 59 | 61 | pub const symbol_mask: u32 = 0x7fffffff; |
| 60 | 62 | pub const SHN_ATOM: u16 = 0x100; |
| ... | ... | @@ -128,6 +130,10 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void { |
| 128 | 130 | if (self.dwarf) |*dw| { |
| 129 | 131 | dw.deinit(); |
| 130 | 132 | } |
| 133 | |
| 134 | if (self.func_offset_table) |*ot| { |
| 135 | ot.deinit(allocator); |
| 136 | } |
| 131 | 137 | } |
| 132 | 138 | |
| 133 | 139 | pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void { |
| ... | ... | @@ -1687,6 +1693,58 @@ const UavTable = std.AutoHashMapUnmanaged(InternPool.Index, AvMetadata); |
| 1687 | 1693 | const LazySymbolTable = std.AutoArrayHashMapUnmanaged(InternPool.Index, LazySymbolMetadata); |
| 1688 | 1694 | const TlsTable = std.AutoArrayHashMapUnmanaged(Atom.Index, TlsVariable); |
| 1689 | 1695 | |
| 1696 | pub const OffsetTable = struct { |
| 1697 | atom_index: Atom.Index, |
| 1698 | entries: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 1699 | |
| 1700 | pub fn deinit(ot: *OffsetTable, allocator: Allocator) void { |
| 1701 | ot.entries.deinit(allocator); |
| 1702 | } |
| 1703 | |
| 1704 | pub fn size(ot: OffsetTable, elf_file: *Elf) usize { |
| 1705 | return ot.entries.items.len * switch (elf_file.ptr_width) { |
| 1706 | .p32 => @as(usize, 4), |
| 1707 | .p64 => 8, |
| 1708 | }; |
| 1709 | } |
| 1710 | |
| 1711 | const OffsetTableFormatContext = struct { OffsetTable, *ZigObject, *Elf }; |
| 1712 | |
| 1713 | pub fn format( |
| 1714 | ot: OffsetTable, |
| 1715 | comptime unused_fmt_string: []const u8, |
| 1716 | options: std.fmt.FormatOptions, |
| 1717 | writer: anytype, |
| 1718 | ) !void { |
| 1719 | _ = ot; |
| 1720 | _ = unused_fmt_string; |
| 1721 | _ = options; |
| 1722 | _ = writer; |
| 1723 | @compileError("do not format OffsetTable directly"); |
| 1724 | } |
| 1725 | |
| 1726 | pub fn fmt(ot: OffsetTable, zo: *ZigObject, elf_file: *Elf) std.fmt.Formatter(format2) { |
| 1727 | return .{ .data = .{ ot, zo, elf_file } }; |
| 1728 | } |
| 1729 | |
| 1730 | fn format2( |
| 1731 | ctx: OffsetTableFormatContext, |
| 1732 | comptime unused_fmt_string: []const u8, |
| 1733 | options: std.fmt.FormatOptions, |
| 1734 | writer: anytype, |
| 1735 | ) !void { |
| 1736 | _ = options; |
| 1737 | _ = unused_fmt_string; |
| 1738 | const ot, const zo, const ef = ctx; |
| 1739 | const atom_ptr = zo.atom(ot.atom_index).?; |
| 1740 | try writer.print("@{x} : size({x})\n", .{ atom_ptr.address(ef), ot.size(ef) }); |
| 1741 | for (ot.entries.items) |sym_index| { |
| 1742 | const sym = zo.symbol(sym_index); |
| 1743 | try writer.print(" %{d} : {s} : @{x}\n", .{ sym_index, sym.name(ef), sym.value }); |
| 1744 | } |
| 1745 | } |
| 1746 | }; |
| 1747 | |
| 1690 | 1748 | const assert = std.debug.assert; |
| 1691 | 1749 | const builtin = @import("builtin"); |
| 1692 | 1750 | const codegen = @import("../../codegen.zig"); |