You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deterministic MVIDs is needed for assemblies referencing System.Private.CoreLib across different architectures #67660
We're hitting an issue where the MVID of assemblies is different depending on the architecture of the runtime pack, e.g. x64 vs. arm64, for assemblies that are 100% managed code like System.Collections.dll or System.Private.Uri.dll but compile against System.Private.CoreLib.
This causes an issue for Xamarin Android and other internal teams that use the MVID to deduplicate assemblies that are the same across architectures (right now only System.Private.CoreLib.dll is actually architecture-specific).
The reason this is showing up now is because of a linker/Cecil fix (dotnet/linker#2203, dotnet/cecil#31) which fixes the PDB ID calculation which in turn affects the MVID calculation (we actually just got lucky in net6 since we run the linker against all assemblies in the libraries build which "unified" the MVID).
There is interest to backport the linker/Cecil fix to net6 so I discussed with @vitek-karas and we agreed the least invasive change is to simply hardcode System.Private.CoreLib.dll as the only architecture-specific assembly in Xamarin Android for net6. EDIT it turns out this plan won't work since the Mono AOT compiler verifies the MVIDs of assembly references and will error out if they don't match with the actual assembly.
For net7/net8 we'd like to come up with a "proper" fix though, some ideas:
Create a reference assembly for System.Private.CoreLib and compile against that one, instead of the real assembly
I tried using Roslyn's /refout feature but the reference assembly created by it still differs between architectures since Roslyn includes private fields like Padding.cs#L9-L16, so this'd likely need to be a real reference assembly
Make System.Private.CoreLib architecture-agnostic by removing all of the TARGET_64BIT and TARGET_32BIT ifdefs.
Tweak the (official) build so we only ever build the non-architecture-specific assemblies once and copy them into the respective runtime packs, ensuring that we only have a single version of the assemblies
As an extension we could split out the assemblies into another package, so they're not duplicated in the runtime packs. This would also help reducing download size.
We had a meeting on Friday and discussed this a bit more, here are the results:
Creating a reference assembly for System.Private.CoreLib.dll looks like the best/easiest option for unblocking the Android team
We discussed making CoreLib architecture-agnostic as it would help save a lot of size for Android apps (CoreLib needs to be duplicated across four architectures right now), but it's not fully clear yet how much work this entails and it's dependent on the runtime team supporting this approach. In addition to that we'll likely run into issues with the "library trimming" mode that we use in the build, we'd need to make sure it doesn't optimize code for one architecture. It can be done independently and/or in addition to the reference assembly work.
@ViktorHofer also explained that having a CoreLib reference assembly has other benefits too:
Improves developer innerloop when libraries build against CoreLib since a change no longer triggers rebuilding libs
Removes the current hack in our build system that allows an AnyCPU libs to reference an arch specific lib.
Keeps the MVID not just between different architectures in sync but also between diferent OS specific implementations.
A downside is that we'll need to manually build and maintain the reference assembly since the /refout switch doesn't work here. We also don't know yet whether we have mismatches in the public API surface area between OS/arch that we need to reconcile.
changed the title [-]Discussion: Deterministic MVIDs for assemblies referencing System.Private.CoreLib across different architectures[/-][+]Deterministic MVIDs is needed for assemblies referencing System.Private.CoreLib across different architectures[/+]on May 10, 2022
We explicitly had to disable an msbuild check to be able to reference an arch specific assembly from an AnyCPU assembly. When doing the proposed set of work (either introducing a reference assembly or making CoreLib arch agnostic), we should also eliminate this hack
@jonathanpeppers I think the answer is yes - the linker would produce different MVIDs for different archs of framework assemblies since they would be .NET 6 framework which would have internally different assemblies per arch (if nothing else, due to the CoreLib difference).
Activity
Bump to dotnet/installer@c7afae69 7.0.100-preview.4.22174.1 (#6598)
akoeplinger commentedon May 9, 2022
We had a meeting on Friday and discussed this a bit more, here are the results:
@ViktorHofer also explained that having a CoreLib reference assembly has other benefits too:
A downside is that we'll need to manually build and maintain the reference assembly since the /refout switch doesn't work here. We also don't know yet whether we have mismatches in the public API surface area between OS/arch that we need to reconcile.
/cc @jkotas @ericstj
[-]Discussion: Deterministic MVIDs for assemblies referencing System.Private.CoreLib across different architectures[/-][+]Deterministic MVIDs is needed for assemblies referencing System.Private.CoreLib across different architectures[/+]ViktorHofer commentedon May 10, 2022
runtime/eng/references.targets
Lines 32 to 39 in 6762f54
jonathanpeppers commentedon Jun 28, 2022
One issue that came up, is when using a .NET 7 SDK to build a
net6.0-androidapp:System.Private.CoreLib.dllSo if there was a ref assembly for
System.Private.CoreLib.dll, it wouldn't fix buildingnet6.0apps in .NET 7?vitek-karas commentedon Jun 28, 2022
@jonathanpeppers I think the answer is yes - the linker would produce different MVIDs for different archs of framework assemblies since they would be .NET 6 framework which would have internally different assemblies per arch (if nothing else, due to the CoreLib difference).
Add reference assembly for System.Private.CoreLib.dll (#72143)