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

exception catch clause does work on Linux arm/arm64 for .net 6.0 release #62702

Closed
oldzhu opened this issue Dec 13, 2021 · 11 comments
Closed

exception catch clause does work on Linux arm/arm64 for .net 6.0 release #62702

oldzhu opened this issue Dec 13, 2021 · 11 comments
Labels
arch-arm64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner

Comments

@oldzhu
Copy link
Contributor

oldzhu commented Dec 13, 2021

Description

exception catch clause does work on Linux arm/arm64 as expected for .net 6.0 release

Reproduction Steps

  1. wrote a program as the below:
using System;

namespace dotnethello
{
        class Program
        {
                static void Main(string[] args)
                {
                        var coreAssemblyInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
                        Console.WriteLine($"Hello World from .NET {coreAssemblyInfo.ProductVersion}");
                        Console.WriteLine($"The location is {typeof(object).Assembly.Location}");
                        try
                        {
                                func3();
                        }
                        catch (Exception ex)
                        {
                        }
                        Console.WriteLine("press anykey to exit...");
                        Console.ReadLine();
                }
                static void func3()
                {
                        throw new System.IO.IOException();
                }
        }
}
  1. Publish as self-contained program using
dotnet publish -r linux-arm64 -c Release

or

dotnet publish -r linux-arm -c Release
  1. Found a linux arm/arm64 system and copy the self-contained publish folder to the box.
  2. Run the program on the linux arm/arm64 system.

Expected behavior

The exception is caught and discarded silently

(lldb) r
Process 124 launched: '/root/dotnethello/dotnethello' (aarch64)
warning: (aarch64) /usr/lib64/libstdc++.so.6 unsupported DW_FORM value: 0x1e
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Hello World from .NET 6.0.0-dev
The location is /root/dotnethello/System.Private.CoreLib.dll
press anykey to exit...

Actual behavior

The exception is not caught and cause the program terminated.

(lldb) r
Process 124 launched: '/root/dotnethello/dotnethello' (aarch64)
warning: (aarch64) /usr/lib64/libstdc++.so.6 unsupported DW_FORM value: 0x1e
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Hello World from .NET 6.0.0-dev
The location is /root/dotnethello/System.Private.CoreLib.dll
Unhandled exception. System.IO.IOException: I/O error occurred.
   at dotnethello.Program.func3() in /home/oldzhu/buildroot/output/build/dotnethello-1.0/Program.cs:line 33
   at dotnethello.Program.Main(String[] args) in /home/oldzhu/buildroot/output/build/dotnethello-1.0/Program.cs:line 13
Process 124 stopped
* thread #1, name = 'dotnethello', stop reason = signal SIGABRT
...

Regression?

seems there is no such issue at .net 6.0 rc releases...

Known Workarounds

no

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Dec 13, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@danmoseley danmoseley added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 13, 2021
@ghost
Copy link

ghost commented Dec 13, 2021

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

exception catch clause does work on Linux arm/arm64 as expected for .net 6.0 release

Reproduction Steps

  1. wrote a program as the below:
using System;

namespace dotnethello
{
        class Program
        {
                static void Main(string[] args)
                {
                        var coreAssemblyInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
                        Console.WriteLine($"Hello World from .NET {coreAssemblyInfo.ProductVersion}");
                        Console.WriteLine($"The location is {typeof(object).Assembly.Location}");
                        try
                        {
                                func3();
                        }
                        catch (Exception ex)
                        {
                        }
                        Console.WriteLine("press anykey to exit...");
                        Console.ReadLine();
                }
                static void func3()
                {
                        throw new System.IO.IOException();
                }
        }
}
  1. Publish as self-contained program using
dotnet publish -r linux-arm64 -c Release

or

dotnet publish -r linux-arm -c Release
  1. Found a linux rm/arm64 system and copy the self-contained publish folder to the box.
  2. Run the program on the linux arm/arm64 system.

Expected behavior

The exception is caught and discarded silently

(lldb) r
Process 124 launched: '/root/dotnethello/dotnethello' (aarch64)
warning: (aarch64) /usr/lib64/libstdc++.so.6 unsupported DW_FORM value: 0x1e
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Hello World from .NET 6.0.0-dev
The location is /root/dotnethello/System.Private.CoreLib.dll
press anykey to exit...

Actual behavior

The exception is not caught and cause the problem terminated.

(lldb) r
Process 124 launched: '/root/dotnethello/dotnethello' (aarch64)
warning: (aarch64) /usr/lib64/libstdc++.so.6 unsupported DW_FORM value: 0x1e
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Process 124 stopped and restarted: thread 1 received signal: SIGCHLD
Hello World from .NET 6.0.0-dev
The location is /root/dotnethello/System.Private.CoreLib.dll
Unhandled exception. System.IO.IOException: I/O error occurred.
   at dotnethello.Program.func3() in /home/oldzhu/buildroot/output/build/dotnethello-1.0/Program.cs:line 33
   at dotnethello.Program.Main(String[] args) in /home/oldzhu/buildroot/output/build/dotnethello-1.0/Program.cs:line 13
Process 124 stopped
* thread #1, name = 'dotnethello', stop reason = signal SIGABRT
...

Regression?

seems there is no such issue at .net 6.0 rc releases...

Known Workarounds

no

Configuration

No response

Other information

No response

Author: oldzhu
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@danmoseley
Copy link
Member

@JulieLeeMSFT not the comment above suggests this is a regression.

@oldzhu
Copy link
Contributor Author

oldzhu commented Dec 13, 2021

One interesting observation is that if throw exception directly in Main() but in func3(), then it can be caught without any problem.

@AndyAyersMS
Copy link
Member

This doesn't repro for me, though I may not be following what you did exactly -- I built on an arm64 machine and did not copy the published app.

Just running is ok:

andy@ubuntu:~/bugs/r62702/ex$ dotnet run -c Release
/home/andy/bugs/r62702/ex/Program.cs(16,42): warning CS0168: The variable 'ex' is declared but never used [/home/andy/bugs/r62702/ex/ex.csproj]
Hello World from .NET 6.0.1+3a25a7f1cc446b60678ed25c9d829420d6321eba
The location is /home/andy/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Private.CoreLib.dll
press anykey to exit...

Publishing then running is ok:

andy@ubuntu:~/bugs/r62702/ex$ dotnet publish -r linux-arm64 -c Release
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/andy/bugs/r62702/ex/ex.csproj (in 21.88 sec).
/home/andy/dotnet/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1110,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/home/andy/bugs/r62702/ex/ex.csproj]
/home/andy/bugs/r62702/ex/Program.cs(16,42): warning CS0168: The variable 'ex' is declared but never used [/home/andy/bugs/r62702/ex/ex.csproj]
  ex -> /home/andy/bugs/r62702/ex/bin/Release/net6.0/linux-arm64/ex.dll
  ex -> /home/andy/bugs/r62702/ex/bin/Release/net6.0/linux-arm64/publish/

andy@ubuntu:~/bugs/r62702/ex$ bin/Release/net6.0/linux-arm64/publish/ex
Hello World from .NET 6.0.1+3a25a7f1cc446b60678ed25c9d829420d6321eba
The location is /home/andy/bugs/r62702/ex/bin/Release/net6.0/linux-arm64/publish/System.Private.CoreLib.dll
press anykey to exit...

Can you give more details about the environment where you build and the environment where you run?

@oldzhu
Copy link
Contributor Author

oldzhu commented Dec 18, 2021

This doesn't repro for me, though I may not be following what you did exactly -- I built on an arm64 machine and did not copy the published app.

Just running is ok:

andy@ubuntu:~/bugs/r62702/ex$ dotnet run -c Release
/home/andy/bugs/r62702/ex/Program.cs(16,42): warning CS0168: The variable 'ex' is declared but never used [/home/andy/bugs/r62702/ex/ex.csproj]
Hello World from .NET 6.0.1+3a25a7f1cc446b60678ed25c9d829420d6321eba
The location is /home/andy/dotnet/shared/Microsoft.NETCore.App/6.0.1/System.Private.CoreLib.dll
press anykey to exit...

Publishing then running is ok:

andy@ubuntu:~/bugs/r62702/ex$ dotnet publish -r linux-arm64 -c Release
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/andy/bugs/r62702/ex/ex.csproj (in 21.88 sec).
/home/andy/dotnet/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1110,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/home/andy/bugs/r62702/ex/ex.csproj]
/home/andy/bugs/r62702/ex/Program.cs(16,42): warning CS0168: The variable 'ex' is declared but never used [/home/andy/bugs/r62702/ex/ex.csproj]
  ex -> /home/andy/bugs/r62702/ex/bin/Release/net6.0/linux-arm64/ex.dll
  ex -> /home/andy/bugs/r62702/ex/bin/Release/net6.0/linux-arm64/publish/

andy@ubuntu:~/bugs/r62702/ex$ bin/Release/net6.0/linux-arm64/publish/ex
Hello World from .NET 6.0.1+3a25a7f1cc446b60678ed25c9d829420d6321eba
The location is /home/andy/bugs/r62702/ex/bin/Release/net6.0/linux-arm64/publish/System.Private.CoreLib.dll
press anykey to exit...

Can you give more details about the environment where you build and the environment where you run?

Thanks for your taking a look. I just found it only can be reproduced with my local build using my project at https://gitbub.com/oldzhu/4dotnet with buildroot system. Another observation is that the issue also gone if I built the .net core master branch with my buildroot project 4dotnet. I am performing live debugging for my local repro and so far found the EHInfo ( phdrJitEHInfo) is null for the function main (seems like the EHInfo is not filled when the main was jitted). I will continue to investigate to figure out why or provide a repro which is not rely on my buildroot project.

@oldzhu
Copy link
Contributor Author

oldzhu commented Dec 28, 2021

Update on the debugging progress.

The issue looks like caused by the incorrect instructions generated for the below lines of the code in corhlpr.cpp and corhlpr.h:

    frame #0: 0x0000007ff77599f0 libcoreclr.so`::DecoderInit(pThis=0x0000007fffffe3c8, header=0x0000007ff28f42d4) at corhlpr.cpp:59:45
   56               if (header->Fat.GetSize() >= (sizeof(COR_ILMETHOD_FAT) / 4))        // Size if valid
   57               {
   58                   decoder->Sect = header->Fat.GetSect();
-> 59                   if ((decoder->Sect != NULL) && (decoder->Sect->Kind() == CorILMethod_Sect_EHTable))
                                                    ^
   60                   {
   61                       decoder->EH = (COR_ILMETHOD_SECT_EH *)decoder->Sect;
...
    const COR_ILMETHOD_SECT* GetSect() const {
        if (!More()) return (0);
        return(((COR_ILMETHOD_SECT*) (GetCode() + GetCodeSize()))->Align());
    }
...
    const COR_ILMETHOD_SECT* Align() const
    {
        return((COR_ILMETHOD_SECT*) ((((UINT_PTR) this) + 3) & ~3));
    }

good working instructions:

    0x7ff783b58c <+144>: 0xb9400429   ldr    w9, [x1, #0x4]
    0x7ff783b590 <+148>: 0x53047d08   lsr    w8, w8, #4
    0x7ff783b594 <+152>: 0x531e7508   lsl    w8, w8, #2
    0x7ff783b598 <+156>: 0x8b080028   add    x8, x1, x8
    0x7ff783b59c <+160>: 0x8b090108   add    x8, x8, x9
    0x7ff783b5a0 <+164>: 0x91000d08   add    x8, x8, #0x3
    0x7ff783b5a4 <+168>: 0xf27ef508   ands   x8, x8, #0xfffffffffffffffc
    0x7ff783b5a8 <+172>: 0xf9001808   str    x8, [x0, #0x30]

incorrect nonworking instructions:

    0x7ff77599d4 <+136>: 0xb940042a   ldr    w10, [x1, #0x4]
    0x7ff77599d8 <+140>: 0x121e0d08   and    w8, w8, #0x3c
    0x7ff77599dc <+144>: 0x8b080028   add    x8, x1, x8
    0x7ff77599e0 <+148>: 0x721d013f   tst    w9, #0x8
    0x7ff77599e4 <+152>: 0x8b0a0108   add    x8, x8, x10
    0x7ff77599e8 <+156>: 0x9a8803e8   csel   x8, xzr, x8, eq
    0x7ff77599ec <+160>: 0xf9001808   str    x8, [x0, #0x30]

comparing the working and nonworking instructions generated, could see the instructions for Align() function was not generated in the nonworking scenario, so that it read the EHTable from an incorrect un-aligned address. Suspect it is a bug in LLVM compiler toolchain, continue to investigate to see if can find a simple repro.

@jkotas
Copy link
Member

jkotas commented Dec 28, 2021

This looks like a duplicate of #61671. It was fixed by #62170

@oldzhu
Copy link
Contributor Author

oldzhu commented Dec 28, 2021

This looks like a duplicate of #61671. It was fixed by #62170

it looks exactly the issue, I will apply the patch to confirm and update the result.

@oldzhu
Copy link
Contributor Author

oldzhu commented Dec 28, 2021

This looks like a duplicate of #61671. It was fixed by #62170

it looks exactly the issue, I will apply the patch to confirm and update the result.

rebuilt the new ARM linux vm with the .net runtime 6.0.1 + the patch to corhlpr.h in #62170, the exception gone. Will build ARM64 linux vm with the same too to confirm the issue also gone...

@oldzhu
Copy link
Contributor Author

oldzhu commented Dec 29, 2021

Rebuilt the new ARM64 linux vm with the .net runtime 6.0.1 + the patch to corhlpr.h in #62170 and confirmed the issue gone too.

The arm instructions for COR_ILMETHOD_SECT::Align() after the patch

(lldb) disas -A thumbv7  -b -n COR_ILMETHOD_SECT::Align
libcoreclr.so`::DecoderInit(void *, COR_ILMETHOD *):
    0xb697da9a <+230>: 0x3103       adds   r1, #0x3
    0xb697da9c <+232>: 0xf0210103   bic    r1, r1, #0x3 
    0xb697daa0 <+236>: 0xe7ce       b      0xb697da40                ; <+140> at corhlpr.h

The arm64 instructions for COR_ILMETHOD_SECT::Align() after the patch

(lldb) disas -b -n COR_ILMETHOD_SECT::Align
...
libcoreclr.so`::DecoderInit(void *, COR_ILMETHOD *):
    0x7ff775a388 <+336>: 0x91000d08   add    x8, x8, #0x3
    0x7ff775a38c <+340>: 0x927ef508   and    x8, x8, #0xfffffffffffffffc
...

This issue can be closed

@oldzhu oldzhu closed this as completed Dec 29, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-arm64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

4 participants