Weak linking of frameworks with greater deployment targets

:) Yep! Good catch! Going too fast… :)
Well, in the mean time, I now have a simple test program to demonstrate it…

Hmmm. Still seeing the issue.

Confirmed from build log that it's using the Dec 3 master trunk snapshot:

/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-12-03-a.xctoolchain/usr/bin/swiftc

repo is here if you want to try:

https://github.com/haikusw/testwlbug

I just build it (inside Xcode so as to make selecting the toolchain easy) and then execute the built object in Terminal from within the DerivedData Build folder.

You have to build and run it (or at least run it…) on macOS 10.14.6 (or macOS < 10.15.x) for the CryptoKit dylib to be missing and thus see the problem which is:

dyld: Library not loaded: /System/Library/Frameworks/CryptoKit.framework/Versions/A/CryptoKit
Referenced from: /Users/haikuty/Desktop/testwlbug 2019-12-04 13-18-42/Products/usr/local/bin/testwlbug
Reason: image not found
Abort trap: 6

I'm using Xcode Version 11.2.1 (11B500) running in macOS 10.14.6 (18G103).

Quite possible I'm using if #available() incorrectly. The "*" at the end isn't something I wanted to include but Xcode wouldn't compile without it and suggested it as the "fix-it". ¯_(ツ)_/¯

Think I may have found the issue?

I disassembled the generated binary with Hopper and there appears to be a lazy witness table accessor for a CryptoKit stuff that the compiler seems to have generated that is outside the test for #available os; that seems like it could make the linker think weak linking was not possible... ???
(I haven't looked at what the Swift compiler is doing before so it's likely I'm out in left field here, but it's the only thing I can see in the binary that looks suspicious…).

Here's the routine as Hopper disassembled it into code:

int _$s9CryptoKit8InsecureO10SHA1DigestVAeA0E0AAWl() {
    rax = *lazy protocol witness table cache variable for type CryptoKit.Insecure.SHA1Digest and conformance CryptoKit.Insecure.SHA1Digest : CryptoKit.Digest in CryptoKit;
    var_8 = rax;
    if (rax == 0x0) {
            rax = type metadata accessor for CryptoKit.Insecure.SHA1Digest(0xff);
            rax = swift_getWitnessTable(*protocol conformance descriptor for CryptoKit.Insecure.SHA1Digest : CryptoKit.Digest in CryptoKit, rax, rax);
            *lazy protocol witness table cache variable for type CryptoKit.Insecure.SHA1Digest and conformance CryptoKit.Insecure.SHA1Digest : CryptoKit.Digest in CryptoKit = rax;
            var_8 = rax;
    }
    rax = var_8;
    return rax;
}

UPDATE: (since this forum doesn't allow more than 3 replies in a row by the same person (o.O)):

Filed a bug at bugs . swift . org since it seems like that might be a better place:

https://bugs.swift.org/browse/SR-11907

Terms of Service

Privacy Policy

Cookie Policy