aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-01-10 16:02:07 +0100
committerGitHub <noreply@github.com>2022-01-10 16:02:07 +0100
commita4e6291fbdf83dec0d353af745c241bc7e01b3f2 (patch)
treed7815bde6915af53e27531c5f1b3737c7fd61a5a /src/codegen.zig
parent42ef95d79d9cb60fde8c83bfb2eef49969e7c8e3 (diff)
downloadzig-a4e6291fbdf83dec0d353af745c241bc7e01b3f2.tar.gz
zig-a4e6291fbdf83dec0d353af745c241bc7e01b3f2.zip
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
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig12
1 files changed, 9 insertions, 3 deletions
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),