-
Notifications
You must be signed in to change notification settings - Fork 519
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
[dotnet] Change the order of the linker steps. Fixes #17347. #17360
Conversation
The bug manifests like this: > Could not create an native instance of the type WindowsAzure.Messaging.SBNotificationHub: the native class hasn't been loaded. which happens because the SBNotificationHub doesn't exist in the final executable. We asked the linker to link with the static library containing this type, but the linker didn't link with the library because it didn't need any of the symbols in it. We should have collected all the exported Objective-C types from this library and asked the native linker to keep them, but that didn't happen because: 1. We collect bound Objective-C classes from binding libraries here (the ListExportedSymbolsStep): https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs#L148-L157 2. That only happens for attributes with a LinkWith attribute. * We compute if an assembly has a LinkWith attribute here: https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/common/Assembly.cs#L266 * Which is called from here: https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/common/Assembly.cs#L198 * Which is called from here (the ExtractBindingLibrariesStep): https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs#L18 Now, we must obviously compute if an assembly has a LinkWith attribute before doing anything that depends on that value, but we weren't doing things in that order. Changing the custom linker steps to run the ListExportedSymbols step *after* the ExtractBindingLibrariesStep fixes this logic problem. Fixes dotnet#17347.
16c0ca1
to
355bc66
Compare
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes)
NET (empty diffs)
✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)✅ Generator diffGenerator diff is empty Pipeline on Agent |
💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻✅ All tests on macOS M1 - Mac Big Sur (11.5) passed. Pipeline on Agent |
🚀 [CI Build] Test results 🚀Test results✅ All tests passed on VSTS: simulator tests. 🎉 All 225 tests passed 🎉 Tests counts✅ bcl: All 69 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
/sudo backport release/7.0.2xx |
Backport Job to branch release/7.0.2xx Created! The magic is happening here |
The bug manifests like this:
which happens because the SBNotificationHub doesn't exist in the final
executable. We asked the linker to link with the static library containing
this type, but the linker didn't link with the library because it didn't need
any of the symbols in it.
We should have collected all the exported Objective-C types from this library
and asked the native linker to keep them, but that didn't happen because:
We collect bound Objective-C classes from binding libraries here (the
ListExportedSymbolsStep): https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs#L148-L157
That only happens for attributes with a LinkWith attribute.
https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/common/Assembly.cs#L266
https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/common/Assembly.cs#L198
https://github.com/xamarin/xamarin-macios/blob/608765e2c9e474c494958844a94354f90fa42f36/tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs#L18
Now, we must obviously compute if an assembly has a LinkWith attribute before
doing anything that depends on that value, but we weren't doing things in that
order.
Changing the custom linker steps to run the ListExportedSymbols step after
the ExtractBindingLibrariesStep fixes this logic problem.
Fixes #17347.