-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opting out of libc on Apple Silicon #5
Comments
That's cool to know! Although now that I have solved the issue of in the makefile, I will continue to work on that! |
I lied, that code is likely outdated/not complete. I know of at least one statically linked binary running. |
Most interesting, the documentation I could find is also that Mach-O doesn't do static binaries. That said, currently I am happy as long as I can easily build and deploy assembler source from the command line, and I might come back to the issue of building a Mach-O binary later ;) |
Oh, no, Mach-O totally does static binaries. In fact, here's how to make one you can run on your Intel machine: $ clang -x assembler-with-cpp -static -nostdlib -
.intel_syntax noprefix
#include <sys/syscall.h>
#define UNIX_SYSCALL 0x2000000
.globl start
start:
mov rax, UNIX_SYSCALL | SYS_write
mov rdi, 1
lea rsi, text[rip]
lea rdx, length
syscall
mov rax, UNIX_SYSCALL | SYS_exit
xor rdi, rdi
syscall
text:
.asciz "Hello, world!\n"
.equ length, . - text
$ ./a.out
Hello, world! |
Most interesting! Any idea why the documentation would claim such a thing? |
System call numbers on macOS are not stable, so Apple would like you to go through libc. Go used to create static binaries on macOS but they would constantly break whenever an update came out, so they've starting linking against the system libraries. The only reason you should be making system calls yourself is curiosity or if you have an extremely good reason that you cannot link against libSystem ;) |
While you can create static binaries, the macOS kernel (XNU) allows the execution of static binaries on x86_64 only (or with debug kernels, which probably nobody outside Apple is using). On all other platforms (ARM64), the kernel enforces that an executable must use the dynamic linker (this was already linked to in the issue above). It's a restriction that cannot be bypassed. However, you can create a dynamically linked executable and simply not link to any library/framework. |
Embedded platforms don't do static. However, if you're still curious here's how you can convince Xcode to make those files:
If you put an underscore in front of
main
in both places and give up on static linking:The text was updated successfully, but these errors were encountered: