Big Sur has moved the system libraries to a cache that is no longer in the file system. Eskimo from Apple answered how to figure it out for my 'how to link to the libraries in C' question in another thread, and that answer should work for a Nasm generated .o file as well.
I also figured out how to do it using the gnu assembler that comes with XCode and this is how I did it:
Using this gnu assembler assembly language source code:
Code Block .text |
|
_helloworldmsg:.asciz "Hello World!\n" |
|
.globl _myhelloworldstart |
_myhelloworldstart: |
|
// syscall is deprecated. |
// Last I checked, if you use syscall, the assembler compiles an imported function call. |
// If you hard code the syscall opcode, macos will not execute it and will give you an error |
// so I am using imported function calls to access the system library functions. |
|
andq $0xfffffffffffffff0, %rsp // Force alignment. Without this exit will seg fault. |
// In other words, the system functions require that the return stack is 16 byte aligned before you call them. |
|
movq $1, %rdi |
leaq _helloworldmsg(%rip), %rsi |
movq $13, %rdx |
call _write |
|
xorq %rdi, %rdi // clear rdi to return success |
call _exit |
I was able to compile and link using these commands:
as -mmacosx-version-min=10.11 ./helloworldbigsur.s -o helloworldbigsur.o
ld -e myhelloworldstart -nouuid -noehlabels -demangle -dynamic -arch x8664 -platformversion macos 11.0.0 11.1 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o helloworldbigsur -L/usr/local/lib helloworldbigsur.o -lSystem
It looks like /usr/local/lib is the path to the dynamic library cache even though the files are not in the file system. When I used otool to look at the executable, it looks like the system loads dyld from /usr/lib and then adds /usr/local/lib to the library search path.