Post

Replies

Boosts

Views

Activity

Reply to Mac OS 11.0.1 Linking X64 system calls to System Library
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: .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.
Dec ’20
Reply to How does a C program compiled from the command line link against a library in the Big Sur dynamic library cache?
I was also able to get this assembly language hello world to work: // Hello World for Big Sur .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.     movq $1, %rdi     leaq _helloworldmsg(%rip), %rsi     movq $13, %rdx     call _write      xorq %rdi, %rdi // clear rdi to return success     call _exit 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
Dec ’20
Reply to How does a C program compiled from the command line link against a library in the Big Sur dynamic library cache?
If you want to explicitly run the linker, you’ll need to tell it what SDK to use. A good way to work out the exact syntax is to run the compiler driver with -v: Code Block "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -ltolibrary /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x8664 -platformversion macos 11.0.0 11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o test -L/usr/local/lib test.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclangrt.osx.a The ‘secret sauce’ here is -syslibroot. You can inspect that with "otool -L". Thanks Quinn and etresoft. I was able to link the clang generated helloworld.o file using this command: ld -demangle -dynamic -arch x8664 -platformversion macos 11.0.0 11.1 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o testcprogram -L/usr/local/lib testcprogram.o -lSystem I also verified with otool that the only library path for dyld and the system library in the executable is /usr/lib I was also able to link a helloworld .o file generated using an assembler I wrote. I noticed that -execute is no longer required for ld, and that -platform_version has replaced -mmacosx-version-min. I also couldn't find any documentation on -syslibroot. I'm guessing that the documentation for these changes will come sometime in the future.
Dec ’20