Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Linking Fails For Release Builds, Even When Linker Is Off #10855

Closed
Axemasta opened this issue Mar 12, 2021 · 7 comments
Closed

Native Linking Fails For Release Builds, Even When Linker Is Off #10855

Axemasta opened this issue Mar 12, 2021 · 7 comments
Labels
iOS Issues affecting iOS need-info Waiting for more information before the bug can be investigated support The issue is related to support

Comments

@Axemasta
Copy link

Axemasta commented Mar 12, 2021

This is probably a me issue, however I've noticed my release builds have stopped working. I've tried rolling back to a commit i've previously built and released but the issue is persisting so I'm wondering if there is something else going on

Steps to Reproduce

  1. Try to build my project... (I am completely unable to reproduce in another project, I can build other apps fine)
  2. Wait...

Expected Behavior

The app builds and runs

Actual Behavior

The build fails, all errors are related to the linker. The errors are different depending on the linker settings, I've provided a table of behaviours below:

Linker Setting Behaviour
Off 53 errors, 32 warnings.
SDK Only 19 errors, 22 warnings.
All App builds successfully, crashes when loaded. I see a type load exception from Prism DryIoc.ContainerException: code: Error.RegisteringImplementationNotAssignableToServiceType;

All of the warnings and errors following the general format:
Errors: Error MT5210: Native linking failed, undefined symbol: $(SYMBOL). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.

image

Warnings: Warning MT5215: References to '$(SYMBOL)' might require additional -framework=XXX or -lXXX instructions to the native linker (MT5215)

image

I have enabled the verbose build output, I'm not well versed in these logs but I did spot the following output:

"_SetThreadToken", referenced from:
          wrapper_managed_to_native_Interop_mincore_SetThreadToken_intptr_Microsoft_Win32_SafeHandles_SafeTokenHandle in System.Security.AccessControl.dll.o
    ld: symbol(s) not found for architecture arm64

I've provided build logs below, obfuscating details of my machine

Environment

=== Visual Studio Enterprise 2019 for Mac ===

Version 8.9.1 (build 34)
Installation UUID: 91a19b18-b4a0-4bb4-8527-0a5dd9d12778
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000122

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.122 (2020-02/c621c35ffa0) (64-bit)
	Package version: 612000122

=== Roslyn (Language Service) ===

3.9.0-6.21152.10+c10f884b30737542ddd84ca889a4aad9281ce210

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.201/Sdks
SDK Versions:
	5.0.201
	5.0.103
	5.0.102
	5.0.101
	5.0.100
	3.1.407
	3.1.406
	3.1.405
	3.1.404
	3.1.403
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.4
	5.0.3
	5.0.2
	5.0.1
	5.0.0
	3.1.13
	3.1.12
	3.1.11
	3.1.10
	3.1.9
	2.1.23

=== .NET Core 3.1 SDK ===

SDK: 3.1.407

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 11.2.0.21 (Visual Studio Enterprise)
Commit: xamarin-android/d16-9/93eab59
Android SDK: /Users/alex.duffell/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.5
SDK Build Tools Version: 29.0.2

Build Information: 
Mono: 5e9cb6d
Java.Interop: xamarin/java.interop/d16-9@d6d86b2
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.34.1@daff8f4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@9d8924d

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/alex.duffell/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.22
Hash: a391de2
Branch: remotes/origin/d16-9
Build date: 2021-02-18 03:14:56 UTC

=== Android Device Manager ===

Version: 16.9.0.17
Hash: fc2b3db
Branch: remotes/origin/d16-9
Build date: 2021-02-18 03:15:18 UTC

=== Xamarin Designer ===

Version: 16.9.0.316
Hash: bd2705417
Branch: remotes/origin/d16-9
Build date: 2021-02-24 00:16:08 UTC

=== Apple Developer Tools ===

Xcode 12.4 (17801)
Build 12D4e

=== Xamarin.Mac ===

Version: 7.8.2.5 (Visual Studio Enterprise)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:43-0500

=== Xamarin.iOS ===

Version: 14.14.2.5 (Visual Studio Enterprise)
Hash: 3836759d4
Branch: d16-9
Build date: 2021-02-10 17:56:44-0500

=== Build Information ===

Release ID: 809010034
Git revision: 33bce2b7f3d45d05865cd3282f1c2cdc3a112aa0
Build date: 2021-03-04 11:21:38-05
Build branch: release-8.9
Xamarin extensions: 33bce2b7f3d45d05865cd3282f1c2cdc3a112aa0

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.3.0 Darwin Kernel Version 20.3.0
    Thu Jan 21 00:07:06 PST 2021
    root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

DeepClean 1.2.5
Code Coverage 1.1
Code Distribution Extension 1.1
LightSwitch 💡 1.0
MFractor 4.4.7


Build Logs

Complete build logs here

Example Project (If Possible)

Not possible to provide the source code, sorry 🙁

As an aside, I'm happy if you close this as a non issue but I'm interested to know if this is an issue with my Xamarin.iOS version. I am unable to build a commit that I have previously built and released. Would you be able to provide me with a Xamarin.iOS version to downgrade to for testing?

When I see this warning Warning MT5215: References to 'kernel32' might require additional -framework=XXX or -lXXX instructions to the native linker (MT5215) I wonder why on earth my app is trying to reference kernel32!!

Update 1:
I tested applying the linker to debug builds and they work fine, both link sdk & all will result in a successful build and a runnable app.

@spouliot spouliot added iOS Issues affecting iOS need-info Waiting for more information before the bug can be investigated support The issue is related to support labels Mar 12, 2021
@spouliot
Copy link
Contributor

The managed linker (don't link, link sdk and link all) is not the same as the native linker (Apple toolchain). Your errors comes from the latter.

Both are largely unrelated - but if the managed linker can remove something then it's not present later to cause (potential) issues. That's why you're seeing less errors when increasing the use of the managed linker. IOW it does not fix the issues, its just remove the offending piece of code.

Warning MT5215: References to 'kernel32'

Yes, that't the key information here. Other symbol/libraries names suggest native Windows API (p/invokes).

I am unable to build a commit that I have previously built and released.

I suspect something else (e.g. nuget) was updated and you are now referencing a Windows (e.g. .net desktop) assembly instead of a NETStandard2.x assembly (or one built against the Xamarin.iOS SDK).

I tested applying the linker to debug builds and they work fine

Is it possible the errors are older than you thought ? E.g. You might have been using debug builds for a while and not notice the problem.

Try to compare your build options between the Release and Debug configurations. If nothing stands out please attach the working logs too.

@Axemasta
Copy link
Author

@spouliot Thanks for the advice and the info about the native and managed linker. I was not aware of the difference, so its nice to get some more insight into how it all works 🙂

I'll have a look for windows references, it could possibly be coming from my controls library which uses multi-targeting. What is strange is that I noticed this failure on my build pipeline which has worked for months and suddenly broken this week. I can categorically confirm i've been building it for release because my final ipa's are 1/4 the size of the debug builds. I'll have a look and report back!

@Axemasta
Copy link
Author

Axemasta commented Mar 14, 2021

I've been able to reproduce the issue in a seperate project. The offending library is System.IO.Abstractions, I have previously had issues with this project (#8028). I think for the time being I'm just going to have to remove it and let my unit tests take a hit 😔

@Axemasta
Copy link
Author

I've removed the System.IO.Abstractions NuGet package from my app, cleaned up any affected code and now my app is able to build for release. I'm closing this issue as I am now able to work, I'm just leaving this warning here for any developers looking to use this package on xamarin, don't!

@jahmai-ca
Copy link

After updating to 14.14, I get the following linking errors, which seems related to this issue:

  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CertDuplicateCertificateContext. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CertFreeCertificateContext. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CertGetCertificateContextProperty. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptDecodeObject. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptEncodeObject. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptFindOIDInfo. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptMsgClose. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptMsgGetParam. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptMsgOpenToDecode. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptMsgOpenToEncode. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _CryptMsgUpdate. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _FormatMessageW. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _GetProcessHeap. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _HeapAlloc. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5210: Native linking failed, undefined symbol: _HeapFree. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  MTOUCH : error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: -ObjC -ObjC -ObjC -lc++ -lz -ObjC -ObjC -ObjC -lc++ -lz [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
  clang : error : linker command failed with exit code 1 (use -v to see invocation) [/Users/ank/dev/ca/criticalarc/Source/Applications/iOS/OmniGuard/OmniGuard.csproj]
    28 Warning(s)
    17 Error(s)

No dependencies have changed. Is 14.14. just surfacing a pre-existing bad reference?

@jahmai-ca
Copy link

Turns out a reference to the System.Security.Cryptography.Pkcs package via MailKit/MimeKit was causing the issue. Even though the package supports netstandard targetting, somehow the net46 TFM version was being copied to the output directory.
I think this wasn't a problem before because we weren't actually calling code in this assembly from iOS, but a recent change in Xamarin.iOS where it preserves PInvoke links seems to leave the references in there and they make it to the native linker, which it doesn't like.
So I've just moved this package reference to another project in the solution to work around the issue.

@lassana
Copy link

lassana commented May 3, 2021

Same issue with 14.14.2.5, build was working with 14.8.0.3. --dlsym:System.Security.Cryptography.Pkcs.dll.o in MtouchExtraArgs fixes the issue for us.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Issues affecting iOS need-info Waiting for more information before the bug can be investigated support The issue is related to support
Projects
None yet
Development

No branches or pull requests

4 participants