darling icon indicating copy to clipboard operation
darling copied to clipboard

Xcode 12.5.1 missing /usr/lib/libMobileGuestalt.dylib

Open awakecoding opened this issue 4 years ago • 7 comments

Library /usr/lib/libMobileGuestalt.dylib

Test Application Xcode 12.5.1

Steps To Reproduce Extract Xcode_12.5.1.xip, copy to /Applications/Xcode.app, run xcode-select --switch /Applications/Xcode.app

System Information This is Ubuntu 20.04 inside WSL2, I have built the latest Darling sources myself.

When trying to run any of the Xcode command-line tools (clang, otool, lipo) I get the following error:

Darling [/usr/lib]$ clang --version
dyld: Library not loaded: /usr/lib/libMobileGestalt.dylib
  Referenced from: /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation
  Reason: image not found
abort_with_payload: reason: Library not loaded: /usr/lib/libMobileGestalt.dylib
  Referenced from: /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation
  Reason: image not found; code: 1
Abort trap: 6

I googled and found that libMobileGuestalt.dylib was part of the dyld cache in recent macOS versions, so I used dyld-shared-cache-extractor to grab it from a mac. I manually copied it over to see if it would work (it was worth a shot I guess), with the following result:

Darling [/usr/lib]$ mv libMobileGestalt.dylib2 libMobileGestalt.dylib Darling [/usr/lib]$ clang --version dyld: Library not loaded: /usr/lib/libMobileGestalt.dylib Referenced from: /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation Reason: no suitable image found. Did find: /usr/lib/libMobileGestalt.dylib: overlapping segments /usr/lib/libMobileGestalt.dylib: stat() failed with errno=22 /usr/lib/libMobileGestalt.dylib: overlapping segments abort_with_payload: reason: Library not loaded: /usr/lib/libMobileGestalt.dylib Referenced from: /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation Reason: no suitable image found. Did find: /usr/lib/libMobileGestalt.dylib: overlapping segments /usr/lib/libMobileGestalt.dylib: stat() failed with errno=22 /usr/lib/libMobileGestalt.dylib: overlapping segments; code: 1 Abort trap: 6

The docs say there is some level of support for Xcode, so was it broken recently?

awakecoding avatar Aug 11 '21 20:08 awakecoding

This is the same issue I mentioned in #1003; namely, they're missing a library that newer Xcode versions use. You can try an older version though; I only had patience to try latest when I last tried.

If you have a version of macOS that has libMobileGestalt.dylib, you could talk with the developers and get stubs made.

rdrpenguin04 avatar Aug 16 '21 07:08 rdrpenguin04

@rdrpenguin04 I just tried following the instructions for generating the stubs on libMobileGestalt.dylib on a mac, it unfortunately fails. I guess this is a case where you need an experienced darling developer, not just someone poking around like me:

image

awakecoding avatar Aug 16 '21 12:08 awakecoding

Could @facekapow or one of the other devs maybe help with this some?

rdrpenguin04 avatar Aug 17 '21 21:08 rdrpenguin04

Is this issue still there? I've been blocked on my initial Xcode-in-darling experimentation because of this, and I have no idea which version of Xcode was the last to work. I need at least XCode 12.x, and Xcode 13 is coming out soon.

awakecoding avatar Sep 24 '21 23:09 awakecoding

Not sure, if libMobileGuestalt really is needed: I don't have that library on my Mac Mini with macOS 11.6, but even XCode 13.1 is running flawlessly. The tools in /Application/XCode of XCode 12.5.1 also don't seem to need that library. Rather seems to me like Darling is building compiler-rt or DVTFoundation with invalid compiler flags.

hasselmm avatar Nov 19 '21 22:11 hasselmm

Actually, you do have that library on your Mac; the thing is that from macOS 11 onward, all system libraries are kept in a "dyld shared cache". Basically, all the system libraries are combined into one large binary that dyld (the dynamic linker) searches through, and they're no longer separate files on your disk. See https://iphonedev.wiki/index.php/Dyld_shared_cache, https://developer.apple.com/forums/thread/692383, and https://mjtsai.com/blog/2020/06/26/reverse-engineering-macos-11-0/ for more information.

This also poses a problem for us since our simple stub generator no longer works on macOS 11 and onward.

facekapow avatar Nov 19 '21 22:11 facekapow