Undefined symbol: ___isOSVersionAtLeast

Perhaps this topic would be more relevant on SO, but the circumstances in which I get the issue may make it relevant in the Swift forum.

I have a sample project in which I play with all kinds of goodness of SwiftUI, property wrappers, Firebase and combining all these things.

I wanted to try out the latest master toolchain snapshot (from Oct. 10th) on this project, and got a linker error.
The linker error is with a third party framework written in Objective-C.
The error is:

Undefined symbols for architecture x86_64:
  "___isOSVersionAtLeast", referenced from:
      _FIRInstanceIDCurrentLocale in FirebaseInstanceID(FIRInstanceIDUtilities.o)
ld: symbol(s) not found for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

The reason I am posting in the Swift forums is that I do not get this linker error using the toolchain that comes with Xcode 11.1.

So I am guessing that the missing symbol is something that the compiler injects?
From what I could gather on Stack Overflow, the reference to the symbol comes whenever a framework uses availability macros.

So my questions are:
What is this symbol?
Where is it supposed to originate from?
Is it expected that there is a linker error using the latest snapshot toolchain, while the linker error is not occurring when I build with the Xcode 11.1 toolchain?
Are there any workarounds that I could apply. :slight_smile:

This symbol is runtime support for platform version checking. It is vended by CompilerRT's builtins, which on macOS is re-exported through libSystem. I believe this is a bug in Apple's system.

$ otool -l /usr/lib/libSystem.dylib | grep -A2 LC_REEXPORT_DYLIB
...
          cmd LC_REEXPORT_DYLIB
      cmdsize 64
         name /usr/lib/system/libcompiler_rt.dylib (offset 24)
...
$ nm -g -U /usr/lib/system/libcompiler_rt.dylib | grep OSVersion
$ $ grep OSVersion /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/System.framework/System.tbd
$ grep OSVersion /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/system/libcompiler_rt.tbd

This indicates the desired symbol is missing in the system image, and as a result, in the TBDs in the SDK content. Both linking to System as a framework and linking against it as a library will not yield the desired symbol.

If you are setting your minimum deployment version higher than whatever value you are using for the checked API, the compiler should be able to fold away the check.

The workaround may not be viable: bump your minimum deployment version to the newest API that you are using. In this case, you would need to bump that and then rebuild Firebase.

1 Like

Thanks so much for replying!
So do you think it would be correct of me to create a radar (or feedback) - or rather a bug on bugs.swift.org?
From what I understand I would guess the former.
Thanks again! :slight_smile:

The ___isOSVersionAtLeast symbol is not vended by libSystem, it's vended by the compiler-rt builtin archives provided by the toolchain. There's no bug in libSystem here.

It looks like the toolchain has the right symbol for macOS:

swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/lib/clang/7.0.0/lib/darwin/libclang_rt.osx.a:os_version_check.c.o: 0000000000000000 T ___isOSVersionAtLeast

Are you building your project for macOS? If yes, can you paste the linker invocation that you get by re-running the clang command that called the linker (it should be the one that failed in your Xcode build logs) with -v to see what happened.

It is not directly vended by libSystem, but libSystem does re-export compiler-rt. Or is that not supposed to be re-exported? Yes, adding a static copy of the compiler-rt would also work (the linker will defer to the local definition over the shared version from libSystem's re-exported dylib).

That particular symbol is not and has never been vended by libcompiler_rt.dylib. It was always vended by the static archive in the toolchain.

Hi Alex,
I am building for the iOS simulator, so I don't know if that counts for building for macOS?
Anyways, here is the linker command and output when I run it with -v:

Mortens-MBP:SwiftUIFirebaseTest mortenbekditlevsen$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/bin/clang -v -target x86_64-apple-ios13.1-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.1.sdk -L/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Products/Debug-iphonesimulator -F/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Products/Debug-iphonesimulator -F/Users/mortenbekditlevsen/Desktop/Fra\ MacOS\ beta/Projects/SwiftUIFirebaseTest/Carthage/Build/iOS -filelist /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest.swiftmodule -ObjC -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/SwiftUIFirebaseTest.app-Simulated.xcent -framework Firebase -framework FirebaseCore -framework FirebaseInstanceID -framework FireSwift_Paths -framework StoreKit -lc++ -framework nanopb -framework FireSwift_DecodeResult -lsqlite3 -framework FireSwift_StructureCoding -framework FirebaseDatabase -framework GoogleUtilities -framework FireSwift_Database -framework leveldb-library -Xlinker -dependency_info -Xlinker /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest_dependency_info.dat -o /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Products/Debug-iphonesimulator/SwiftUIFirebaseTest.app/SwiftUIFirebaseTest

Apple clang version 7.0.0 (git@github.com:apple/swift-clang.git fadd0451ab9262145fbb55a186ccdb41fd4326fd) (git@github.com:apple/swift-llvm.git 6e04008c7fded8f5f3a9978620d5c54069ab5cc2) (based on LLVM 7.0.0)

Target: x86_64-apple-ios13.1-simulator

Thread model: posix

InstalledDir: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/bin

"/usr/bin/ld" -demangle -lto_library /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -dead_strip -ios_simulator_version_min 13.1.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.1.sdk -ObjC -o /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Products/Debug-iphonesimulator/SwiftUIFirebaseTest.app/SwiftUIFirebaseTest -L/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Products/Debug-iphonesimulator -L/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-10-10-a.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -filelist /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest.LinkFileList -rpath /usr/lib/swift -rpath @executable_path/Frameworks -object_path_lto /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest_lto.o -export_dynamic -no_deduplicate -objc_abi_version 2 -add_ast_path /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest.swiftmodule -sectcreate __TEXT __entitlements /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/SwiftUIFirebaseTest.app-Simulated.xcent -framework Firebase -framework FirebaseCore -framework FirebaseInstanceID -framework FireSwift_Paths -framework StoreKit -lc++ -framework nanopb -framework FireSwift_DecodeResult -lsqlite3 -framework FireSwift_StructureCoding -framework FirebaseDatabase -framework GoogleUtilities -framework FireSwift_Database -framework leveldb-library -dependency_info /Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Intermediates.noindex/SwiftUIFirebaseTest.build/Debug-iphonesimulator/SwiftUIFirebaseTest.build/Objects-normal/x86_64/SwiftUIFirebaseTest_dependency_info.dat -framework Foundation -lobjc -lSystem -F/Users/mortenbekditlevsen/Library/Developer/Xcode/DerivedData/SwiftUIFirebaseTest-aqgterdkoaztueapgzkaxeugnrul/Build/Products/Debug-iphonesimulator "-F/Users/mortenbekditlevsen/Desktop/Fra MacOS beta/Projects/SwiftUIFirebaseTest/Carthage/Build/iOS"

Undefined symbols for architecture x86_64:

"___isOSVersionAtLeast", referenced from:

_FIRInstanceIDCurrentLocale in FirebaseInstanceID(FIRInstanceIDUtilities.o)

ld: symbol(s) not found for architecture x86_64

clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

The toolchain from Swift.org doesn't have a static archive for the iOS simulator, so that explains why you're getting the error. I'm not 100% sure why the Swift toolchain doesn't build compiler-rt for the iOS simulator though. @mishal_shah do you have any idea why?

2 Likes

Hi @Alex_L,
Thanks for your reply - I get the same issue when building for an actual iOS device.
Can you determine whether this is a case of 'works as intended'? Or should I perhaps file a bug for the issue?

Sincerely,
/morten

Hi there,
Sorry for bumping, but do you have any comments as to wether this is an oversight or if it works as intended @mishal_shah?
Sincerely,
Morten

@Mike_Ash might be a better person to answer this question.

We had an issue where the compiler-rt from Xcode wasn't being copied properly in some circumstances, which could cause this. That was fixed in this PR: https://github.com/apple/swift/pull/27575

If you still experience this problem with that fix, maybe that copying code is still going wrong. If you can't figure it out, let me know.

Hi @Mike_Ash,
The linker issue still appears with the master branch toolchain from November 1st.
It happens for both the iOS simulator and when building for iOS.

Here is the debug output from when I try linking on the simulator:

Undefined symbols for architecture x86_64:
  "___isOSVersionAtLeast", referenced from:
      _FIRInstanceIDCurrentLocale in FirebaseInstanceID(FIRInstanceIDUtilities.o)
ld: symbol(s) not found for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

Is there any other information I can provide to help?

Sincerely,
/morten

1 Like

@Morten_Bek_Ditlevsen I am also experiencing this issue. Using Xcode Version 11.2 (11B52), and attempting to build for simulator with either Toolchain: Swift 5.1 Release 2019-09-19 (a) or Toolchain: Swift 5.1.1 Release 2019-10-11 (a), I receive the below error during linker invocation.

This issue does not occur when using the Swift 5.1.2 compiler included in Xcode 11.2

Looks like we are using the same Objective-C Library as well

Undefined symbols for architecture arm64:
  "___isOSVersionAtLeast", referenced from:
      -[CCTUIKitAXUtils initPrivate] in FirebasePerformance(CCTUIKitAXUtils_911abdd4bc813e022ac3a52c1f0261af.o)
      -[CCTUIKitAXUtils isAssistiveTouchRunning] in FirebasePerformance(CCTUIKitAXUtils_911abdd4bc813e022ac3a52c1f0261af.o)
      -[CCTUIKitAXUtils isShakeToUndoEnabled] in FirebasePerformance(CCTUIKitAXUtils_911abdd4bc813e022ac3a52c1f0261af.o)
      -[CCTUIKitAXUtils updateAccessibilityStateCache] in FirebasePerformance(CCTUIKitAXUtils_911abdd4bc813e022ac3a52c1f0261af.o)
      -[APMMeasurement sendDeepLinkURLToAppDelegateOnMainThread:extraInfo:] in GoogleAppMeasurement(APMMeasurement_77d66481554a3daf14fde66dd9edd8c4.o)
      -[APMSqliteStore prepareSQL:error:] in GoogleAppMeasurement(APMSqliteStore_0ed784bc5f04451d45128745e2fe2383.o)
      -[GDTApplication init] in GoogleDataTransport(GDTPlatform.o)
      ...
ld: symbol(s) not found for architecture arm64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
1 Like

It is also still present in the master branch toolchain from November 18th.

Is there anything I can do to help with the issue? Should I perhaps create a bug report for this?

Sincerely,
/morten

Also hitting this with November/December toolchains (cc @Mike_Ash); reproducible via:

git clone https://github.com/airbnb/lottie-ios lottie && cd lottie

git checkout --quiet 5a54b18137b3b03247138e929ac5760e1af7eadd

TOOLCHAINS='org.swift.50201912011a' /usr/bin/xcrun xcodebuild -project Lottie.xcodeproj -scheme Lottie -configuration Release -derivedDataPath ${PWD}/build/DerivedData-lottie-$RANDOM -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= archive -archivePath ${PWD}/build/ArchivePath-lottie-$RANDOM/ SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO

1 Like

Sorry for taking so long to follow up on this. I was able to replicate the problem locally. It looks like the toolchains still aren't getting the iOS compiler-rt copied in when they're built. @mishal_shah Do you know what might be going on with that? I'm not too familiar with how we built toolchains. Maybe that process just needs something like the copying code I modified in https://github.com/apple/swift/pull/27575.

In the meantime, you can work around this by manually copying Xcode's compiler-rt libraries into your toolchain. A command like this will do it:

sudo cp `xcode-select -p`/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/*/lib/darwin/libclang_rt.*.a /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-12-03-a.xctoolchain/usr/lib/clang/7.0.0/lib/darwin

I checked here and that fixed it for me. If you still have trouble, let me know!

2 Likes

Thank you so much for the work-around, @Mike_Ash !
It works like a charm - and now I have some really fun code running using property wrapper composition which I have been toying with since the first glimpse of the possibility of composing property wrappers. Yay!

Terms of Service

Privacy Policy

Cookie Policy