runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[ARM32] Exception filter failed to catch exception

Open parjong opened this issue 10 years ago • 1 comments

It seems that exception filter does not work correctly on ARM32. Currently, running the following program results in unhandled exception error:

namespace ConsoleApplication { public class Program {

  public static void Main(string[] args) {
    try {
      throw new System.Exception("Throw");
    } catch (System.Exception e)  when ( true ) {
      System.Console.WriteLine("Hello World!");
    }
  }

} }

CoreCLR is expected to work as follows:

Hello World!

However, it currently shows the following output:

Unhandled Exception: System.Exception: Throw
   at ConsoleApplication.Program.Main(String[] args)

parjong avatar Apr 21 '16 23:04 parjong

It looks like that I found the reason why it fails.

Here is the code generated from JIT:

G_M31466_IG04:                                                                           
000046  BF00           nop
000048  F642 20CC      movw    r0, 0x2acc
00004C  F2C7 10D8      movt    r0, 0x71d8
000050  F245 5381      movw    r3, 0x5581
000054  F2C7 6347      movt    r3, 0x7647
000058  4798           blx     r3               // CORINFO_HELP_NEWSFAST
00005A  9005           str     r0, [sp+0x14]    // [V03 tmp0]
00005C  2001           movs    r0, 1
00005E  F644 217C      movw    r1, 0x4a7c
000062  F2C7 5195      movt    r1, 0x7595
000066  F246 0369      movw    r3, 0x6069
00006A  F2C7 6347      movt    r3, 0x7647
00006E  4798           blx     r3               // CORINFO_HELP_STRCNS
000070  9000           str     r0, [sp] // [V09 tmp6]
000072  9900           ldr     r1, [sp] // [V09 tmp6]
000074  9805           ldr     r0, [sp+0x14]    // [V03 tmp0]
000076  F246 0325      movw    r3, 0x6025
00007A  F2C7 13DD      movt    r3, 0x71dd
00007E  4798           blx     r3               // System.Exception:.ctor(ref):this
000080  9805           ldr     r0, [sp+0x14]    // [V03 tmp0]
000082  F24F 6355      movw    r3, 0xf655
000086  F2C7 6347      movt    r3, 0x7647
00008A  4798           blx     r3               // CORINFO_HELP_THROW

G_M31466_IG05:
00008C  BF00           nop

When CORINFO_HELP_TRHOW is called, PC will points to some instruction that corresponds to 00008C.

However, the exception handling region covers only for [0046..008C)

*************** EH table for ConsoleApplication.Program:Main(ref)
1 EH table entries, 0 duplicate clauses, 1 total EH entries reported to VM
EH#0: try [0046..008C) handled by [0104..013A) filter at [0096..0104)

Actually, this issue is already known and AMD64 and ARM64 codegen have a workaround. Unfortunately, it seems that this workaround is not applied to ARM32 codegen, yet.

parjong avatar Apr 22 '16 08:04 parjong