aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-12-03 13:41:31 -0800
committerGitHub <noreply@github.com>2020-12-03 13:41:31 -0800
commitecf7dfcd3a3e575ee525487687a0b7607a6a7481 (patch)
tree56cf2bfa237e4fdb0f13230983184e86b2f9b501 /src/codegen.zig
parenta2cd9dc3bd1e6a5f4e6a3c593b05b0f7bd2943ce (diff)
parentd3be4992708e7e6631df52fb5f4ccb0f521a77de (diff)
downloadzig-ecf7dfcd3a3e575ee525487687a0b7607a6a7481.tar.gz
zig-ecf7dfcd3a3e575ee525487687a0b7607a6a7481.zip
Merge pull request #7273 from kubkon/lld-codesig-poc
lld+macho: patch lld output on Apple Silicon by calculating and embedding adhoc code signature
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index c5bf3c1249..f1e1d2b8e4 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -1795,7 +1795,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
if (inst.func.cast(ir.Inst.Constant)) |func_inst| {
if (func_inst.val.cast(Value.Payload.Function)) |func_val| {
const func = func_val.func;
- const got = &macho_file.sections.items[macho_file.got_section_index.?];
+ const text_segment = &macho_file.load_commands.items[macho_file.text_segment_cmd_index.?].Segment;
+ const got = &text_segment.sections.items[macho_file.got_section_index.?];
const got_addr = got.addr + func.owner_decl.link.macho.offset_table_index * @sizeOf(u64);
switch (arch) {
.x86_64 => {
@@ -3196,7 +3197,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
return MCValue{ .memory = got_addr };
} else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
const decl = payload.decl;
- const got = &macho_file.sections.items[macho_file.got_section_index.?];
+ const text_segment = &macho_file.load_commands.items[macho_file.text_segment_cmd_index.?].Segment;
+ const got = &text_segment.sections.items[macho_file.got_section_index.?];
const got_addr = got.addr + decl.link.macho.offset_table_index * ptr_bytes;
return MCValue{ .memory = got_addr };
} else if (self.bin_file.cast(link.File.Coff)) |coff_file| {