This code works but isn't what I want. I'd like to build from linux which will complain it can't find _write. On my mac I can compile this just fine. Notice the bl _write after the svc. Without it the code doesnt work (crashes on run)
.global _main
.align 2
_main:
stp x29, x30, [sp, #-16]!
mov x29, sp
mov X0, #1
adr X1, hello
mov x2, #6
; bl hello+0x120 ;Stubs+0x3C
; bl _write
bl hello+8
mov X0, #0
mov X16, #1
svc 0
bl _write
hello:
.ascii "Hello\n"
.extern _malloc
.extern _realloc
.extern _free
.extern _write
I dumped the stub and got section and wrote the below before the .extern
.section __TEXT,__stubs
.align 2
.p2align 12, 0x00, 4095
Stubs:
.incbin "stubs"
.section __DATA_CONST,__got
.align 3
.incbin "got"
.global _main
.align 2
The code seems correct, but the GOT section no longer gets replaced with valid values (it's the raw data in the got binary, in the original code it's updated with valid function pointers)
How do I get this loading correctly without depending _write? Or rather, what do I need to do so I can build this on linux without having libs and dylibs on the linux system? If I use the write svc I can build from linux and run on mac just fine. I'd like to use the dynamic function of malloc/free/realloc since it's more efficient than what I can do with mmap. I'm using write as a test