Skip to content

Commit

Permalink
native: fix macho header for amd64 macOS 'Big Sur' (#10304)
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae committed Jun 2, 2021
1 parent 452a51c commit 4b2319f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
10 changes: 4 additions & 6 deletions vlib/v/gen/native/amd64.v
Expand Up @@ -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()
}

Expand Down
14 changes: 7 additions & 7 deletions vlib/v/gen/native/macho.v
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4b2319f

Please sign in to comment.