| ... | ... | @@ -164,6 +164,16 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 164 | 164 | if (metadata.rodata_state != .unused) metadata.rodata_state = .flushed; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | if (build_options.enable_logging) { |
| 168 | const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid }; |
| 169 | for (self.navs.keys(), self.navs.values()) |nav_index, meta| { |
| 170 | checkNavAllocated(pt, nav_index, meta); |
| 171 | } |
| 172 | for (self.uavs.keys(), self.uavs.values()) |uav_index, meta| { |
| 173 | checkUavAllocated(pt, uav_index, meta); |
| 174 | } |
| 175 | } |
| 176 | |
| 167 | 177 | if (self.dwarf) |*dw| { |
| 168 | 178 | const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid }; |
| 169 | 179 | try dw.flushModule(pt); |
| ... | ... | @@ -701,6 +711,7 @@ pub fn lowerUav( |
| 701 | 711 | else => explicit_alignment, |
| 702 | 712 | }; |
| 703 | 713 | if (self.uavs.get(uav)) |metadata| { |
| 714 | assert(metadata.allocated); |
| 704 | 715 | const sym = self.symbol(metadata.symbol_index); |
| 705 | 716 | const existing_alignment = sym.atom(elf_file).?.alignment; |
| 706 | 717 | if (uav_alignment.order(existing_alignment).compare(.lte)) |
| ... | ... | @@ -732,7 +743,7 @@ pub fn lowerUav( |
| 732 | 743 | .ok => |sym_index| sym_index, |
| 733 | 744 | .fail => |em| return .{ .fail = em }, |
| 734 | 745 | }; |
| 735 | | try self.uavs.put(gpa, uav, .{ .symbol_index = sym_index }); |
| 746 | try self.uavs.put(gpa, uav, .{ .symbol_index = sym_index, .allocated = true }); |
| 736 | 747 | return .{ .mcv = .{ .load_symbol = sym_index } }; |
| 737 | 748 | } |
| 738 | 749 | |
| ... | ... | @@ -921,6 +932,8 @@ fn updateNavCode( |
| 921 | 932 | esym.st_value = 0; |
| 922 | 933 | } |
| 923 | 934 | |
| 935 | self.navs.getPtr(nav_index).?.allocated = true; |
| 936 | |
| 924 | 937 | if (elf_file.base.child_pid) |pid| { |
| 925 | 938 | switch (builtin.os.tag) { |
| 926 | 939 | .linux => { |
| ... | ... | @@ -988,6 +1001,8 @@ fn updateTlv( |
| 988 | 1001 | atom_ptr.alignment = required_alignment; |
| 989 | 1002 | atom_ptr.size = code.len; |
| 990 | 1003 | |
| 1004 | self.navs.getPtr(nav_index).?.allocated = true; |
| 1005 | |
| 991 | 1006 | { |
| 992 | 1007 | const gop = try self.tls_variables.getOrPut(gpa, atom_ptr.atom_index); |
| 993 | 1008 | assert(!gop.found_existing); // TODO incremental updates |
| ... | ... | @@ -1695,6 +1710,8 @@ const AvMetadata = struct { |
| 1695 | 1710 | symbol_index: Symbol.Index, |
| 1696 | 1711 | /// A list of all exports aliases of this Av. |
| 1697 | 1712 | exports: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 1713 | /// Set to true if the AV has been initialized and allocated. |
| 1714 | allocated: bool = false, |
| 1698 | 1715 | |
| 1699 | 1716 | fn @"export"(m: AvMetadata, zig_object: *ZigObject, name: []const u8) ?*u32 { |
| 1700 | 1717 | for (m.exports.items) |*exp| { |
| ... | ... | @@ -1705,6 +1722,32 @@ const AvMetadata = struct { |
| 1705 | 1722 | } |
| 1706 | 1723 | }; |
| 1707 | 1724 | |
| 1725 | fn checkNavAllocated(pt: Zcu.PerThread, index: InternPool.Nav.Index, meta: AvMetadata) void { |
| 1726 | if (!meta.allocated) { |
| 1727 | const zcu = pt.zcu; |
| 1728 | const ip = &zcu.intern_pool; |
| 1729 | const nav = ip.getNav(index); |
| 1730 | log.err("NAV {}({d}) assigned symbol {d} but not allocated!", .{ |
| 1731 | nav.fqn.fmt(ip), |
| 1732 | index, |
| 1733 | meta.symbol_index, |
| 1734 | }); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | fn checkUavAllocated(pt: Zcu.PerThread, index: InternPool.Index, meta: AvMetadata) void { |
| 1739 | if (!meta.allocated) { |
| 1740 | const zcu = pt.zcu; |
| 1741 | const uav = Value.fromInterned(index); |
| 1742 | const ty = uav.typeOf(zcu); |
| 1743 | log.err("UAV {}({d}) assigned symbol {d} but not allocated!", .{ |
| 1744 | ty.fmt(pt), |
| 1745 | index, |
| 1746 | meta.symbol_index, |
| 1747 | }); |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1708 | 1751 | const TlsVariable = struct { |
| 1709 | 1752 | symbol_index: Symbol.Index, |
| 1710 | 1753 | code: []const u8 = &[0]u8{}, |
| ... | ... | @@ -1881,6 +1924,7 @@ pub const OffsetTable = struct { |
| 1881 | 1924 | }; |
| 1882 | 1925 | |
| 1883 | 1926 | const assert = std.debug.assert; |
| 1927 | const build_options = @import("build_options"); |
| 1884 | 1928 | const builtin = @import("builtin"); |
| 1885 | 1929 | const codegen = @import("../../codegen.zig"); |
| 1886 | 1930 | const elf = std.elf; |