From b82130709d121222f793c082dbbe6c29e7f2ec41 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sat, 15 Apr 2023 11:10:20 +0200 Subject: x86_64: cleanup different memory load types Split `MCValue.linker_load` into `.load_got`, `.load_direct`, and `.lea_direct`. --- src/codegen.zig | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index 15f4440788..6d6238ceda 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -931,11 +931,17 @@ pub const GenResult = union(enum) { /// 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, - linker_load: LinkerLoad, /// Threadlocal variable with address deferred until the linker allocates /// everything in virtual memory. /// Payload is a symbol index. load_tlv: u32, + /// Decl with address deferred until the linker allocates everything in virtual memory. + /// Payload is a symbol index. + load_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, }; @@ -1007,17 +1013,11 @@ fn genDeclRef( if (is_threadlocal) { return GenResult.mcv(.{ .load_tlv = sym_index }); } - return GenResult.mcv(.{ .linker_load = .{ - .type = .got, - .sym_index = sym_index, - } }); + return GenResult.mcv(.{ .load_got = sym_index }); } else if (bin_file.cast(link.File.Coff)) |coff_file| { const atom_index = try coff_file.getOrCreateAtomForDecl(decl_index); const sym_index = coff_file.getAtom(atom_index).getSymbolIndex().?; - return GenResult.mcv(.{ .linker_load = .{ - .type = .got, - .sym_index = sym_index, - } }); + return GenResult.mcv(.{ .load_got = sym_index }); } else if (bin_file.cast(link.File.Plan9)) |p9| { const decl_block_index = try p9.seeDecl(decl_index); const decl_block = p9.getDeclBlock(decl_block_index); @@ -1044,15 +1044,9 @@ fn genUnnamedConst( if (bin_file.cast(link.File.Elf)) |elf_file| { return GenResult.mcv(.{ .memory = elf_file.getSymbol(local_sym_index).st_value }); } else if (bin_file.cast(link.File.MachO)) |_| { - return GenResult.mcv(.{ .linker_load = .{ - .type = .direct, - .sym_index = local_sym_index, - } }); + return GenResult.mcv(.{ .load_direct = local_sym_index }); } else if (bin_file.cast(link.File.Coff)) |_| { - return GenResult.mcv(.{ .linker_load = .{ - .type = .direct, - .sym_index = local_sym_index, - } }); + return GenResult.mcv(.{ .load_direct = local_sym_index }); } else if (bin_file.cast(link.File.Plan9)) |p9| { const ptr_bits = target.cpu.arch.ptrBitWidth(); const ptr_bytes: u64 = @divExact(ptr_bits, 8); -- cgit v1.2.3