Hacker Newsnew | past | comments | ask | show | jobs | submit | bobrippling's commentslogin

A few extra things to note for enthusiasts:

> The MacOS linker/loader doesn’t like doing relocations, so you need to use the ADR rather than LDR instruction to load addresses. You could use ADR in Linux and if you do this it will work in both.

I think this is more the assembler - the linker's perfectly happy performing relocations

> In MacOS you need to link in the System library even if you don’t make a system call from it or you get a linker error. This sample Hello World program uses software interrupts to make the system calls rather than the API in the System library and so shouldn’t need to link to it.

You can get around this by creating a statically linked executable, which requires a bit of wrangling, but is supported (and perhaps handy if you're going on to write a kernel).

> In MacOS the default entry point is _main whereas in Linux it is _start. This is changed via a command line argument to the linker.

In macOS the default entry point is start (linux is still _start), the C runtime still needs to be setup - the kernel can't jump a program straight to main.


> In macOS the default entry point is start (linux is still _start), the C runtime still needs to be setup - the kernel can't jump a program straight to main.

macOS has no interest in what the symbol is called; it pulls the initial PC from the LC_MAIN command in the Mach-o header.

ld64 (the linker) will by default populate that load command by looking up “_start”, but that’s a separate thing...


> I think this is more the assembler - the linker's perfectly happy performing relocations

No, this is “all executables are PIE because applying relocations to shared code is stupid and inefficient in the presence of ASLR”.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: