runtime icon indicating copy to clipboard operation
runtime copied to clipboard

NullReferenceException during 'dotnet build' on ubuntu arm32

Open eerhardt opened this issue 9 years ago • 13 comments

It appears there is a JIT bug on ubuntu arm machines. While trying to get a .NET Core SDK that runs on my Raspberry Pi, I encountered an error:

Microsoft (R) Build Engine version 15.2.93.5465
Copyright (C) Microsoft Corporation. All rights reserved.

/home/ubuntu/dotnet/sdk/2.0.0-preview1-005720/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(93,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/home/ubuntu/HelloWorld/HelloWorld.csproj]
/home/ubuntu/dotnet/sdk/2.0.0-preview1-005720/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(93,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/home/ubuntu/HelloWorld/HelloWorld.csproj]
/home/ubuntu/dotnet/sdk/2.0.0-preview1-005720/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(93,5): error MSB4018:    at Microsoft.NET.Build.Tasks.LockFileLookup..ctor(LockFile lockFile) [/home/ubuntu/HelloWorld/HelloWorld.csproj]
/home/ubuntu/dotnet/sdk/2.0.0-preview1-005720/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(93,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.Build() [/home/ubuntu/HelloWorld/HelloWorld.csproj]

Looking into that code, there was no way a NullReferenceException was coming from that method.

Using Console.WriteLines, I traced it down to this exact line that was failing. Note that LibraryType is a struct.

I have 2 repos of this bug, one is the long way and one is the short way.

Short Repo

  • Clone https://github.com/eerhardt/ArmJITBug
  • Using the latest 2.0 SDK (on a non-linux-arm machine or else you will run into this bug 😀)
    • dotnet restore
    • dotnet publish -c Release
  • Copy the contents of bin\Release\netcoreapp2.0\publish to a Raspberry Pi running a recent ubuntu (14 or 16) arm32 build of dotnet.
  • On the Pi: dotnet App.dll.

result

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at TestIt.LockFileLookup..ctor(LockFile lockFile) in F:\DotNetTest\TestIt\App\Program.cs:line 30
   at TestIt.Program.Main(String[] args) in F:\DotNetTest\TestIt\App\Program.cs:line 14

Long Repo

  • Extract an ubuntu arm32 shared framework tarball onto your Raspberry Pi/arm machine.
  • Build the dotnet/cli repo using --configuration Release /p:DISABLE_CROSSGEN=1.
  • Extract the artifacts/RID/packages/dotnet-sdk-RID.VERSION.tar.gz archive into the same folder as the shared framework on your arm machine. This will get you the SDK installed on your machine.
  1. dotnet new console
  2. dotnet restore
  3. dotnet run

result

Same error as above with GenerateDepsFile task failing during the build.

Notes

This only happens when I build the managed assembly for Release. The error doesn't repro when I build for Debug.

/cc @Petermarcu @jaredpar @VSadov @RussKeldorph

eerhardt avatar Apr 06 '17 22:04 eerhardt

@BruceForstall @dotnet/samsung

/cc @dotnet/jit-contrib

RussKeldorph avatar Apr 06 '17 22:04 RussKeldorph

I forgot to attach the ILDASM of the method in question.

LockFileLookup.Debug.txt LockFileLookup.Release.txt

eerhardt avatar Apr 06 '17 22:04 eerhardt

I'm trying to test dotnet cli in Raspberry PI3. But dotnet build occurs the same error in PI3 board. When I added ArgumentNullException in LockFileLookup.cs file, this issue seems to be resolved. But I'm not sure if my changes are right or not. In my case, this issue occurs debug build.

https://github.com/dotnet/sdk/issues/1094

jyoungyun avatar Apr 07 '17 03:04 jyoungyun

The NuGet.Config in https://github.com/eerhardt/ArmJITBug should be added <add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" /> source to restore NuGet.ProjectModel. :)

jyoungyun avatar Apr 07 '17 09:04 jyoungyun

@jyoungyun Thanks! :) I was facing same problem.

hqueue avatar Apr 07 '17 09:04 hqueue

After some investigation, I found that a hoisted copy in preheader of loop contains invalid value which is used to load loop invariant variable. I've used the example @eerhardt shared and the loop is at https://github.com/eerhardt/ArmJITBug/blob/master/Program.cs#L30.

However I have to go out now and will start debugging again next week if this issue is still live next week.

hqueue avatar Apr 07 '17 13:04 hqueue

The NuGet.Config in https://github.com/eerhardt/ArmJITBug should be added source to restore NuGet.ProjectModel. :)

Thanks for letting me know. I've pushed a change to fix it.

eerhardt avatar Apr 07 '17 14:04 eerhardt

Doing a little more narrowing down the line causing the issue:

        public LockFileLookup(LockFile lockFile)
        {
            _packages = new Dictionary<KeyValuePair<string, NuGetVersion>, LockFileLibrary>();
            _projects = new Dictionary<string, LockFileLibrary>(StringComparer.OrdinalIgnoreCase);

            foreach (var library in lockFile.Libraries)
            {
                Console.WriteLine("Got Here");

                var libraryType = LibraryType.Parse(library.Type);
                Console.WriteLine($"Got Here2 {libraryType}");

                var package = LibraryType.Package;
                Console.WriteLine($"Got Here3 {package}");
                
                if (libraryType == package)
                {
                    Console.WriteLine("Got Here4");
                    _packages[new KeyValuePair<string, NuGetVersion>(library.Name, library.Version)] = library;
                }
                
                Console.WriteLine("Got Here5");

Outputs:

ubuntu@ubuntu:~/TestIt$ ~/dotnet/dotnet App.dll
Got Here
Got Here2 package

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at TestIt.LockFileLookup..ctor(LockFile lockFile) in F:\git\ArmJITBug\Program.cs:line 37
   at TestIt.Program.Main(String[] args) in F:\git\ArmJITBug\Program.cs:line 14

Potential Workaround

Also, as pointed out in @jyoungyun's PR https://github.com/dotnet/sdk/pull/1095, a potential workaround here is to add a throw statement into the code. Adding a fake if check and a throw causes the problem not to repro:

            foreach (var library in lockFile.Libraries)
            {
                if (string.Empty == null)
                {
                    throw new ArgumentNullException();
                }
                
                Console.WriteLine("Got Here");

                var libraryType = LibraryType.Parse(library.Type);

eerhardt avatar Apr 07 '17 15:04 eerhardt

@RussKeldorph Is this on track for 2.0?

gkhanna79 avatar May 05 '17 18:05 gkhanna79

@gkhanna79 I do not expect to block 2.0 for it if that's what you mean. We are still trying to determine if we can create a fix that will meet the risk/reward bar.

RussKeldorph avatar May 05 '17 19:05 RussKeldorph

Should this be moved to 2.1 then?

gkhanna79 avatar May 05 '17 19:05 gkhanna79

Not until we either determine it cannot affect x86 and x64 or we determine we can't come up with an acceptable fix.

RussKeldorph avatar May 05 '17 19:05 RussKeldorph

@hseok-oh is analyzing this issue. Related PR is https://github.com/dotnet/coreclr/pull/11198.

jyoungyun avatar May 08 '17 06:05 jyoungyun