Using otool to list dependencies of a system library in dynamic library cache

I realize that recent versions of MacOS ship with a dynamic library cache. I am looking for inputs on how to list the dependencies of one such system library that's part of this cache.

Consider the case where I have a libfoo library which when inspected through "otool -L libfoo.dylib" shows this output:

otool -L libfoo.dylib
/home/me/lib/libjli.dylib:
	@rpath/libjli.dylib (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 60157.60.19)
	/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 56.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1856.105.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1856.105.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

One of the dependencies in that library is the /usr/lib/libSystem.B.dylib. Previously, I could just do otool -L /usr/lib/libSystem.B.dylib to find the dependencies of libSystem.B.dylib, but now with the dynamic library cache in picture, if I do:

otool -L /usr/lib/libSystem.B.dylib
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool-classic: can't open file: /usr/lib/libSystem.B.dylib (No such file or directory)

So how do I get otool to show the dependencies of this cache library. Are there any other tools instead of otool which can do this in recent versions of MacOS?

I'm on 12.3.1 of macOS

Answered by jaikiran in 712746022

On a different thread, Quinn pointed me to the right tool to get this information. Details are available in the reply here - https://developer.apple.com/forums/thread/655588?answerId=712400022#712400022.

In short, using dyld_info -dependents <library> will list the dependencies.

Accepted Answer

I didn't find a way to get this working with otool. Nor could I find a tool which would seamlessly work against dependency paths of the system libraries which don't represent a file system path but instead are in within the dynamic library cache.

However, I did find a workaround. I found this useful tool https://github.com/keith/dyld-shared-cache-extractor which extracts the dynamic cache library to a directory. The dynamic library cache is available on the filesystem as a file under /System/Library/dyld/ directory. For example, /System/Library/dyld/dyld_shared_cache_arm64e. So you can pass that file as an argument to the tool to extract the contents.

Once you extract the cache, you can then use otool to list the dependencies of the system library of your choice, as usual. Do note though that the extracted content is around 2.7 GB.

On a different thread, Quinn pointed me to the right tool to get this information. Details are available in the reply here - https://developer.apple.com/forums/thread/655588?answerId=712400022#712400022.

In short, using dyld_info -dependents <library> will list the dependencies.

Using otool to list dependencies of a system library in dynamic library cache
 
 
Q