From a4e6291fbdf83dec0d353af745c241bc7e01b3f2 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 10 Jan 2022 16:02:07 +0100 Subject: stage2: enable zig test on x86_64-macos (#10551) * stage2: put decls in different MachO sections Use `getDeclVAddrWithReloc` when targeting MachO backend rather than `getDeclVAddr` - this fn returns a zero vaddr and instead creates a relocation on the linker side which will get automatically updated whenever the target decl is moved in memory. This fn also records a rebase of the target pointer so that its value is correctly slid in presence of ASLR. This commit enables `zig test` on x86_64-macos. * stage2: fix output section selection for type,val pairs --- src/codegen.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index e385158ba6..1d20c4bc74 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -465,9 +465,15 @@ fn lowerDeclRef( if (decl.analysis != .complete) return error.AnalysisFail; markDeclAlive(decl); - // TODO handle the dependency of this symbol on the decl's vaddr. - // If the decl changes vaddr, then this symbol needs to get regenerated. - const vaddr = bin_file.getDeclVAddr(decl); + const vaddr = vaddr: { + if (bin_file.cast(link.File.MachO)) |macho_file| { + break :vaddr try macho_file.getDeclVAddrWithReloc(decl, code.items.len); + } + // TODO handle the dependency of this symbol on the decl's vaddr. + // If the decl changes vaddr, then this symbol needs to get regenerated. + break :vaddr bin_file.getDeclVAddr(decl); + }; + const endian = bin_file.options.target.cpu.arch.endian(); switch (bin_file.options.target.cpu.arch.ptrBitWidth()) { 16 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(u16, vaddr), endian), -- cgit v1.2.3