Open tapthaker opened 1 year ago
With 1136fda7277fb0d199ebf41e09fbd46fb7bfe725, the test program now links fine. However, the generated test program runs into an infinite loop which mysteriously finishes only when running under lldb, which is very hard to debug. Could you try again and try to reduce the testcase for me?
Hmm, in my case I am running into the following symbols not found:
dyld[58930]: Symbol not found: (_$s10Foundation14LocalizedErrorMp)
Referenced from: '/Users/mobileci/sold-repro-libswift-StringProcessing/a.out'
Expected in: '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation'
Actually it works just fine on my Intel Mac, and it falls into an infinite loop on an ARM Mac.
On my Intel Mac, symbol _$s10Foundation14LocalizedErrorMp
seems to be resolved just fine from /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
.
What macOS version are you on your intel mac. Here is mine:
sold-repro-libswift-StringProcessing % sw_vers
ProductName: macOS
ProductVersion: 12.6.1
BuildVersion: 21G217
Both my M2 and Intel Macs are at this version:
$ sw_vers
ProductName: macOS
ProductVersion: 13.2.1
BuildVersion: 22D68
Ive seen what i think is the same error in the case that folks used a minimum macOS version to link a binary that is larger than the OS they're running. In this case using macOS 13 to link and then running on macOS 12. Specifically because foundation changed their overlays wrt swift
Sorry I have been busy last couple of days. I'll get to this near the end of next week.
I was trying to downgrade my Intel Mac to Monterey and accidentally bricked it. I'm now trying to fix it...
So I downgraded my Intel Mac to Monterey and tried to reproduce the problem. However, the test just passed on my machine. Is this still a problem for you? This is my environment:
$ sw_vers
ProductName: macOS
ProductVersion: 12.3
BuildVersion: 21E230
So I tried executing on latest version, this is still a problem for me:
sold-repro-libswift-StringProcessing % ./ld64.mold -v
mold (sold) 1.11.0 (daf2cf3c28eeb8bf081895c94360a14c48c8e4d0; compatible with GNU ld)
sold-repro-libswift-StringProcessing %
sold-repro-libswift-StringProcessing % ./ld64.mold -v
mold (sold) 1.11.0 (daf2cf3c28eeb8bf081895c94360a14c48c8e4d0; compatible with GNU ld)
sold-repro-libswift-StringProcessing % sw_vers
ProductName: macOS
ProductVersion: 12.6.1
BuildVersion: 21G217
sold-repro-libswift-StringProcessing % bash test.sh
dyld[23235]: Symbol not found: (_$s10Foundation14LocalizedErrorMp)
Referenced from: '/Users/mobileci/sold-repro-libswift-StringProcessing/a.out'
Expected in: '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation'
test.sh: line 10: 23235 Abort trap: 6 ./a.out
@keith's suggestion is spot on !! Things executed successfully after I downgraded to Xcode 13.4 and executed it on macOS 12.6.1. However, I think my setup is correct and sold, or the compiler should handle this since I am setting minimum SDK to 10.15
cmd LC_BUILD_VERSION
cmdsize 24
platform 1
minos 10.15
sdk 13.0
If I understand the folliowing symbol correctly:
$ld$previous$/usr/lib/swift/libswiftFoundation.dylib$1.0.0$1$10.15$13.0$_$s10Foundation14LocalizedErrorMp
I think we should be replacing the install_name: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
with /usr/lib/swift/libswiftFoundation.dylib
sold-repro-libswift-StringProcessing % otool -L a.out.ld64
a.out.ld64:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.32.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
/usr/lib/swift/libswiftCore.dylib (compatibility version 1.0.0, current version 5.7.1)
/usr/lib/swift/libswiftCoreFoundation.dylib (compatibility version 1.0.0, current version 120.100.0, weak)
/usr/lib/swift/libswiftDarwin.dylib (compatibility version 1.0.0, current version 0.0.0)
/usr/lib/swift/libswiftDispatch.dylib (compatibility version 1.0.0, current version 17.0.0, weak)
/usr/lib/swift/libswiftIOKit.dylib (compatibility version 1.0.0, current version 1.0.0, weak)
/usr/lib/swift/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 6.0.0, weak)
/usr/lib/swift/libswiftXPC.dylib (compatibility version 1.0.0, current version 6.0.0, weak)
/usr/lib/swift/libswiftFoundation.dylib (compatibility version 1.0.0, current version 1.0.0)
sold-repro-libswift-StringProcessing % otool -L a.out.sold
a.out.sold:
/usr/lib/libc++.1.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libobjc.A.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftCore.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftDarwin.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftObjectiveC.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftCoreFoundation.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftDispatch.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftXPC.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/swift/libswiftIOKit.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 0.0.0, current version 0.0.0)
@tapthaker Thank you for pointing that out. It looks like sold indeed handled $ld$previous
symbols incorrectly. I'll fix it.
Swift's argument parser has the following load command:
And the libswift_StringProcessing.tbd has the install_name:
So, SOLD is right in setting the load command:
However, the file
/usr/lib/swift/libswift_StringProcessing.dylib
doesn't exist and this results in the error:Interestingly, LD64 or LLD doesn't run into this or add
libswift_StringProcessing.dylib
to the load command.Here is a reproducer: sold-repro-libswift-StringProcessing-x86_64.tar.gz