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

Linker fails for F# projects in .NET 5+ #1448

Closed
jonathanpeppers opened this issue Aug 24, 2020 · 1 comment
Closed

Linker fails for F# projects in .NET 5+ #1448

jonathanpeppers opened this issue Aug 24, 2020 · 1 comment

Comments

@jonathanpeppers
Copy link
Member

Context: dotnet/android#5040

Some F# tests we have that use the linker fail with:

Errors
    ILLink error IL1012: IL Linker has encountered an unexpected error. Please report the issue at https://github.com/mono/linker/issues [C:\src\xamarin-android\bin\TestDebug\temp\CheckResourceDesignerIsCreatedTrueFSharp\UnnamedProject.fsproj]
Fatal error in IL Linker
Unhandled exception. System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')
    at System.String.Substring(Int32 startIndex, Int32 length)
    at Mono.Linker.TypeReferenceExtensions.GetDisplayNameWithoutNamespace(TypeReference type)
    at Mono.Linker.TypeReferenceExtensions.GetDisplayName(TypeReference type)
    at Mono.Linker.Dataflow.DiagnosticUtilities.GetGenericParameterDescriptionForErrorMessage(GenericParameter genericParameter)
    at Mono.Linker.Dataflow.DiagnosticUtilities.GetMetadataTokenDescriptionForErrorMessage(IMetadataTokenProvider targetContext)
    at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.GetValueDescriptionForErrorMessage(ValueNode value)
    at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.RequireDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, DynamicallyAccessedMemberTypes requiredMemberTypes, ValueNode value, IMetadataTokenProvider targetContext)
    at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.ProcessGenericArgumentDataFlow(GenericParameter genericParameter, TypeReference genericArgument, IMemberDefinition source)
    at Mono.Linker.Steps.MarkStep.MarkGenericArgumentConstructors(IGenericInstance instance, IMemberDefinition sourceLocationMember)
    at Mono.Linker.Steps.MarkStep.MarkGenericArguments(IGenericInstance instance, IMemberDefinition sourceLocationMember)
    at Mono.Linker.Steps.MarkStep.GetOriginalType(TypeReference type, DependencyInfo reason, IMemberDefinition sourceLocationMember)
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason)
    at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, Boolean includeBaseTypes, DependencyInfo& reason, IMemberDefinition sourceLocationMember)
    at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, Boolean includeBaseTypes, DependencyInfo& reason, IMemberDefinition sourceLocationMember)
    at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at Mono.Linker.Driver.Run(ILogger customLogger)
    at Mono.Linker.Driver.Main(String[] args)
The command exited with code -532462766.

I think this may have been introduced here: 095f30a

It might be related to F# generics, maybe their types do not include a ` character?

@jonathanpeppers
Copy link
Member Author

/cc @marek-safar

jonathanpeppers added a commit to dotnet/android that referenced this issue Sep 2, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.

The second workaround is for:

dotnet/linker#1448

F# generics are causing an NRE in the linker.
@marek-safar marek-safar added this to the .NET 5.0 milestone Sep 3, 2020
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 28, 2022
Fixes: dotnet/runtime#64269

An F# test was failing in AOT builds with:

    Microsoft.Android.Sdk.Aot.targets(74,5): Precompiling failed for C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\obj\Release\android-arm\aot-in\FSharp.Core.resources.dll.
    AOT of image obj\Release\android-arm\aot-in\FSharp.Core.resources.dll failed.
    Mono Ahead of Time compiler - compiling assembly C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\obj\Release\android-arm\aot-in\FSharp.Core.resources.dll
    AOTID 302CA46D-4000-DCAD-1A9F-642D849470DE
    Using profile data file 'C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\targets\dotnet.aotprofile'
    Added 0 methods from profile.
    Compiled: 0/0
    Executing the native assembler: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-as"   -mfpu=vfp3 -o obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s.o obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s
    Executing the native linker: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-ld" -Bsymbolic -shared -o obj\Release\android-arm\aot\FSharp.Core.resources.dll.so.tmp  obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s.o
    Stripping the binary: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-strip" --strip-symbol=\$a --strip-symbol=\$d obj\Release\android-arm\aot\FSharp.Core.resources.dll.so.tmp [C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\UnnamedProject.fsproj]

It turns out we shouldn't be passing satellite assemblies to the AOT
compiler, they appear to be included in `@(ResolvedFileToPublish)`:

    <ItemGroup>
      <_AndroidAotInputs Include="@(ResolvedFileToPublish)" Condition=" '%(Extension)' == '.dll' " />
    </ItemGroup>

Viewing these assemblies, I see the metadata
`%(ResolvedFileToPublish.AssetType)` is equal to `resources`. I think
we can simply check for this and ignore these files.

The F# test I parameterized to include an AOT build.

I also removed a `TODO` on F# tests, since this is fixed now:

dotnet/linker#1448
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 31, 2022
Fixes: dotnet/runtime#64269

An F# test was failing in AOT builds with:

    Microsoft.Android.Sdk.Aot.targets(74,5): Precompiling failed for C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\obj\Release\android-arm\aot-in\FSharp.Core.resources.dll.
    AOT of image obj\Release\android-arm\aot-in\FSharp.Core.resources.dll failed.
    Mono Ahead of Time compiler - compiling assembly C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\obj\Release\android-arm\aot-in\FSharp.Core.resources.dll
    AOTID 302CA46D-4000-DCAD-1A9F-642D849470DE
    Using profile data file 'C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\targets\dotnet.aotprofile'
    Added 0 methods from profile.
    Compiled: 0/0
    Executing the native assembler: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-as"   -mfpu=vfp3 -o obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s.o obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s
    Executing the native linker: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-ld" -Bsymbolic -shared -o obj\Release\android-arm\aot\FSharp.Core.resources.dll.so.tmp  obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s.o
    Stripping the binary: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-strip" --strip-symbol=\$a --strip-symbol=\$d obj\Release\android-arm\aot\FSharp.Core.resources.dll.so.tmp [C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\UnnamedProject.fsproj]

It turns out we shouldn't be passing satellite assemblies to the AOT
compiler, they appear to be included in `@(ResolvedFileToPublish)`:

    <ItemGroup>
      <_AndroidAotInputs Include="@(ResolvedFileToPublish)" Condition=" '%(Extension)' == '.dll' " />
    </ItemGroup>

Viewing these assemblies, I see the metadata
`%(ResolvedFileToPublish.AssetType)` is equal to `resources`. I think
we can simply check for this and ignore these files.

The F# test I parameterized to include an AOT build.

I also removed a `TODO` on F# tests, since this is fixed now:

dotnet/linker#1448
jonathanpeppers added a commit to dotnet/android that referenced this issue Jan 31, 2022
Fixes: dotnet/runtime#64269

An F# test was failing in AOT builds with:

    Microsoft.Android.Sdk.Aot.targets(74,5): Precompiling failed for C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\obj\Release\android-arm\aot-in\FSharp.Core.resources.dll.
    AOT of image obj\Release\android-arm\aot-in\FSharp.Core.resources.dll failed.
    Mono Ahead of Time compiler - compiling assembly C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\obj\Release\android-arm\aot-in\FSharp.Core.resources.dll
    AOTID 302CA46D-4000-DCAD-1A9F-642D849470DE
    Using profile data file 'C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\targets\dotnet.aotprofile'
    Added 0 methods from profile.
    Compiled: 0/0
    Executing the native assembler: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-as"   -mfpu=vfp3 -o obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s.o obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s
    Executing the native linker: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-ld" -Bsymbolic -shared -o obj\Release\android-arm\aot\FSharp.Core.resources.dll.so.tmp  obj\Release\android-arm\aot\armeabi-v7a\FSharp.Core.resources\temp.s.o
    Stripping the binary: "C:\Program Files\dotnet\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-ci.dotnet-release-aot-by-default.36\tools\binutils\arm-linux-androideabi-strip" --strip-symbol=\$a --strip-symbol=\$d obj\Release\android-arm\aot\FSharp.Core.resources.dll.so.tmp [C:\src\xamarin-android\bin\TestDebug\temp\BuildBasicApplicationFSharpTrue\UnnamedProject.fsproj]

It turns out we shouldn't be passing satellite assemblies to the AOT
compiler, they appear to be included in `@(ResolvedFileToPublish)`:

    <ItemGroup>
      <_AndroidAotInputs Include="@(ResolvedFileToPublish)" Condition=" '%(Extension)' == '.dll' " />
    </ItemGroup>

Viewing these assemblies, I see the metadata
`%(ResolvedFileToPublish.AssetType)` is equal to `resources`. I think
we can simply check for this and ignore these files.

The F# test I parameterized to include an AOT build.

I also removed a `TODO` on F# tests, since this is fixed now:

dotnet/linker#1448
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants