clang hello.c -c -o hello.o
ld hello.o -o hello
Undefined symbols for architecture arm64: "_printf", referenced from: _main in hello.o ld: symbol(s) not found for architecture arm64
xcrun -sdk macosx --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk
ld hello.o -o hello -l System -e _main -arch arm64 -syslibroot `xcrun -sdk macosx --show-sdk-path`
as --version
Apple clang version 15.0.0 (clang-1500.3.9.4) Target: arm64-apple-darwin23.5.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
// hello.s
.global _main
.align 2
helloworld: .ascii "hello world\n" // output string
// entry point
_main:
b _printf
b _terminate
_printf: // 4 AUE_NULL ALL { user_ssize_t write(int fd, user_addr_t cbuf, user_size_t nbyte); }
mov X0, #0 // stdout ---------------------------------------------+ | |
adr X1, helloworld // address of output string --------------------------------------------+ |
mov X2, #12 // length of output string in bytes --------------------------------------------------------+
mov X16, #4 // write to stdout
svc 0 // syscall
_terminate:
mov X0, #0 // return 0
mov X16, #1 // exit
svc 0 // syscall
as hello.s -o hello.o
ld hello.o -o hello -l System -e _main -arch arm64 -syslibroot `xcrun -sdk macosx --show-sdk-path`