From 4b2319fd67631e06ab655f445d3b3cfcb18d3714 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 2 Jun 2021 15:09:57 +0200 Subject: [PATCH] native: fix macho header for amd64 macOS 'Big Sur' (#10304) --- vlib/v/gen/native/amd64.v | 10 ++++------ vlib/v/gen/native/macho.v | 14 +++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/vlib/v/gen/native/amd64.v b/vlib/v/gen/native/amd64.v index 1f421e6085..99c8d5a9d9 100644 --- a/vlib/v/gen/native/amd64.v +++ b/vlib/v/gen/native/amd64.v @@ -664,13 +664,11 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) { // println('end of main: gen exit') zero := ast.IntegerLiteral{} g.gen_exit(zero) - // return - } - if !is_main { - // g.leave() - g.add8(.rsp, 0x10) - g.pop(.rbp) + return } + // g.leave() + g.add8(.rsp, 0x10) + g.pop(.rbp) g.ret() } diff --git a/vlib/v/gen/native/macho.v b/vlib/v/gen/native/macho.v index a61b5d424e..6e7ebd3648 100644 --- a/vlib/v/gen/native/macho.v +++ b/vlib/v/gen/native/macho.v @@ -11,14 +11,14 @@ const ( // macho_symcmd_size = 0x18 macho_d_size = 0x50 - lc_symtab = 0x2 - lc_dysymtab = 0xb mh_object = 1 mh_execute = 2 + lc_dysymtab = 0xb + lc_load_dylib = 0xc + lc_load_dylinker = 0xe lc_main = 0x80000028 lc_segment_64 = 0x19 - lc_load_dylinker = 0xe - lc_load_dylib = 0xc + lc_symtab = 0x2 ) struct Symbol { @@ -95,7 +95,7 @@ fn (mut g Gen) macho_segment64_text() []int { g.write32(native.lc_segment_64) // LC_SEGMENT_64 g.write32(152) // 152 g.write_string_with_padding('__TEXT', 16) // section name - g.write64(0x100001000) // vmaddr + g.write64(0x100000000) // vmaddr patch << g.buf.len g.write64(0x00001000) // + codesize) // vmsize g.write64(0x00000000) // filesize @@ -109,7 +109,7 @@ fn (mut g Gen) macho_segment64_text() []int { g.write_string_with_padding('__text', 16) // section name g.write_string_with_padding('__TEXT', 16) // segment name - g.write64(0x0000000100002000) // vmaddr + g.write64(0x0000000100001000) // vmaddr patch << g.buf.len g.write64(0) // vmsize g.write32(4096) // offset @@ -395,7 +395,7 @@ fn (mut g Gen) write_symbol(s Symbol) { fn (mut g Gen) sym_string_table() int { begin := g.buf.len g.zeroes(1) - at := i64(0x100001000) + at := i64(0x100000000) for i, s in g.strings { g.write64_at(at + g.buf.len, int(g.str_pos[i])) g.write_string(s)