diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2025-06-13 04:41:21 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2025-06-19 18:41:12 -0400 |
| commit | 1f98c98fffb09bf15a9fc04ecd5f1fa38a4bd4b8 (patch) | |
| tree | 23d82265b3a4500514063f0fa13533b255f88f64 /src/codegen.zig | |
| parent | ed37a1a33c2576c00697643463a4720728e04023 (diff) | |
| download | zig-1f98c98fffb09bf15a9fc04ecd5f1fa38a4bd4b8.tar.gz zig-1f98c98fffb09bf15a9fc04ecd5f1fa38a4bd4b8.zip | |
x86_64: increase passing test coverage on windows
Now that codegen has no references to linker state this is much easier.
Closes #24153
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index d1b62e352e..11b6eedc86 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -810,7 +810,7 @@ fn lowerUavRef( const uav_align = ip.indexToKey(uav.orig_ty).ptr_type.flags.alignment; switch (try lf.lowerUav(pt, uav_val, uav_align, src_loc)) { - .mcv => {}, + .sym_index => {}, .fail => |em| std.debug.panic("TODO rework lowerUav. internal error: {s}", .{em.msg}), } @@ -920,36 +920,7 @@ pub const LinkerLoad = struct { sym_index: u32, }; -pub const GenResult = union(enum) { - mcv: MCValue, - fail: *ErrorMsg, - - const MCValue = union(enum) { - none, - undef, - /// The bit-width of the immediate may be smaller than `u64`. For example, on 32-bit targets - /// such as ARM, the immediate will never exceed 32-bits. - immediate: u64, - /// Decl with address deferred until the linker allocates everything in virtual memory. - /// Payload is a symbol index. - load_direct: u32, - /// Decl with address deferred until the linker allocates everything in virtual memory. - /// Payload is a symbol index. - lea_direct: u32, - /// Decl referenced via GOT with address deferred until the linker allocates - /// everything in virtual memory. - /// Payload is a symbol index. - load_got: u32, - /// Direct by-address reference to memory location. - memory: u64, - /// Reference to memory location but deferred until linker allocated the Decl in memory. - /// Traditionally, this corresponds to emitting a relocation in a relocatable object file. - load_symbol: u32, - /// Reference to memory location but deferred until linker allocated the Decl in memory. - /// Traditionally, this corresponds to emitting a relocation in a relocatable object file. - lea_symbol: u32, - }; -}; +pub const SymbolResult = union(enum) { sym_index: u32, fail: *ErrorMsg }; pub fn genNavRef( lf: *link.File, @@ -957,7 +928,7 @@ pub fn genNavRef( src_loc: Zcu.LazySrcLoc, nav_index: InternPool.Nav.Index, target: *const std.Target, -) CodeGenError!GenResult { +) CodeGenError!SymbolResult { const zcu = pt.zcu; const ip = &zcu.intern_pool; const nav = ip.getNav(nav_index); @@ -973,7 +944,7 @@ pub fn genNavRef( .internal => { const sym_index = try zo.getOrCreateMetadataForNav(zcu, nav_index); if (is_threadlocal) zo.symbol(sym_index).flags.is_tls = true; - return .{ .mcv = .{ .lea_symbol = sym_index } }; + return .{ .sym_index = sym_index }; }, .strong, .weak => { const sym_index = try elf_file.getGlobalSymbol(nav.name.toSlice(ip), lib_name.toSlice(ip)); @@ -984,7 +955,7 @@ pub fn genNavRef( .link_once => unreachable, } if (is_threadlocal) zo.symbol(sym_index).flags.is_tls = true; - return .{ .mcv = .{ .lea_symbol = sym_index } }; + return .{ .sym_index = sym_index }; }, .link_once => unreachable, } @@ -994,7 +965,7 @@ pub fn genNavRef( .internal => { const sym_index = try zo.getOrCreateMetadataForNav(macho_file, nav_index); if (is_threadlocal) zo.symbols.items[sym_index].flags.tlv = true; - return .{ .mcv = .{ .lea_symbol = sym_index } }; + return .{ .sym_index = sym_index }; }, .strong, .weak => { const sym_index = try macho_file.getGlobalSymbol(nav.name.toSlice(ip), lib_name.toSlice(ip)); @@ -1005,7 +976,7 @@ pub fn genNavRef( .link_once => unreachable, } if (is_threadlocal) zo.symbols.items[sym_index].flags.tlv = true; - return .{ .mcv = .{ .lea_symbol = sym_index } }; + return .{ .sym_index = sym_index }; }, .link_once => unreachable, } @@ -1015,25 +986,55 @@ pub fn genNavRef( .internal => { const atom_index = try coff_file.getOrCreateAtomForNav(nav_index); const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?; - return .{ .mcv = .{ .lea_symbol = sym_index } }; + return .{ .sym_index = sym_index }; }, .strong, .weak => { const global_index = try coff_file.getGlobalSymbol(nav.name.toSlice(ip), lib_name.toSlice(ip)); try coff_file.need_got_table.put(zcu.gpa, global_index, {}); // needs GOT - return .{ .mcv = .{ .lea_symbol = global_index } }; + return .{ .sym_index = global_index }; }, .link_once => unreachable, } } else if (lf.cast(.plan9)) |p9| { - const atom_index = try p9.seeNav(pt, nav_index); - const atom = p9.getAtom(atom_index); - return .{ .mcv = .{ .memory = atom.getOffsetTableAddress(p9) } }; + return .{ .sym_index = try p9.seeNav(pt, nav_index) }; } else { const msg = try ErrorMsg.create(zcu.gpa, src_loc, "TODO genNavRef for target {}", .{target}); return .{ .fail = msg }; } } +/// deprecated legacy type +pub const GenResult = union(enum) { + mcv: MCValue, + fail: *ErrorMsg, + + const MCValue = union(enum) { + none, + undef, + /// The bit-width of the immediate may be smaller than `u64`. For example, on 32-bit targets + /// such as ARM, the immediate will never exceed 32-bits. + immediate: u64, + /// Decl with address deferred until the linker allocates everything in virtual memory. + /// Payload is a symbol index. + load_direct: u32, + /// Decl with address deferred until the linker allocates everything in virtual memory. + /// Payload is a symbol index. + lea_direct: u32, + /// Decl referenced via GOT with address deferred until the linker allocates + /// everything in virtual memory. + /// Payload is a symbol index. + load_got: u32, + /// Direct by-address reference to memory location. + memory: u64, + /// Reference to memory location but deferred until linker allocated the Decl in memory. + /// Traditionally, this corresponds to emitting a relocation in a relocatable object file. + load_symbol: u32, + /// Reference to memory location but deferred until linker allocated the Decl in memory. + /// Traditionally, this corresponds to emitting a relocation in a relocatable object file. + lea_symbol: u32, + }; +}; + /// deprecated legacy code path pub fn genTypedValue( lf: *link.File, @@ -1042,30 +1043,28 @@ pub fn genTypedValue( val: Value, target: *const std.Target, ) CodeGenError!GenResult { - return switch (try lowerValue(pt, val, target)) { + const res = try lowerValue(pt, val, target); + return switch (res) { .none => .{ .mcv = .none }, .undef => .{ .mcv = .undef }, .immediate => |imm| .{ .mcv = .{ .immediate = imm } }, - .lea_nav => |nav| genNavRef(lf, pt, src_loc, nav, target), - .lea_uav => |uav| switch (try lf.lowerUav( + .lea_nav => |nav| switch (try genNavRef(lf, pt, src_loc, nav, target)) { + .sym_index => |sym_index| .{ .mcv = .{ .lea_symbol = sym_index } }, + .fail => |em| .{ .fail = em }, + }, + .load_uav, .lea_uav => |uav| switch (try lf.lowerUav( pt, uav.val, Type.fromInterned(uav.orig_ty).ptrAlignment(pt.zcu), src_loc, )) { - .mcv => |mcv| .{ .mcv = switch (mcv) { + .sym_index => |sym_index| .{ .mcv = switch (res) { else => unreachable, - .load_direct => |sym_index| .{ .lea_direct = sym_index }, - .load_symbol => |sym_index| .{ .lea_symbol = sym_index }, + .load_uav => .{ .load_symbol = sym_index }, + .lea_uav => .{ .lea_symbol = sym_index }, } }, .fail => |em| .{ .fail = em }, }, - .load_uav => |uav| lf.lowerUav( - pt, - uav.val, - Type.fromInterned(uav.orig_ty).ptrAlignment(pt.zcu), - src_loc, - ), }; } @@ -1076,8 +1075,8 @@ const LowerResult = union(enum) { /// such as ARM, the immediate will never exceed 32-bits. immediate: u64, lea_nav: InternPool.Nav.Index, - lea_uav: InternPool.Key.Ptr.BaseAddr.Uav, load_uav: InternPool.Key.Ptr.BaseAddr.Uav, + lea_uav: InternPool.Key.Ptr.BaseAddr.Uav, }; pub fn lowerValue(pt: Zcu.PerThread, val: Value, target: *const std.Target) Allocator.Error!LowerResult { |
