CoreDisTools and R2RDump support Arm Thumb2 disassembling (#42964)
authorEgor Chesakov <Egor.Chesakov@microsoft.com>
Tue, 6 Oct 2020 19:27:20 +0000 (12:27 -0700)
committerGitHub <noreply@github.com>
Tue, 6 Oct 2020 19:27:20 +0000 (12:27 -0700)
* Clear the low bit of "Function Start RVA" on Arm Thumb2 machines in ReadyToRunMethod.cs

* Remove restrictions on InputArchitecture in ReadyToRunReader.cs and R2RDump.cs

src/coreclr/src/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs
src/coreclr/src/tools/r2rdump/R2RDump.cs

index b8c825e..10b4af9 100644 (file)
@@ -465,6 +465,12 @@ namespace ILCompiler.Reflection.ReadyToRun
             for (int i = 0; i < RuntimeFunctionCount; i++)
             {
                 int startRva = NativeReader.ReadInt32(_readyToRunReader.Image, ref curOffset);
+                if (_readyToRunReader.Machine == Machine.ArmThumb2)
+                {
+                    // The low bit of this address is set since the function contains thumb code.
+                    // Clear this bit in order to get the "real" RVA of the start of the function.
+                    startRva = (int)(startRva & ~1);
+                }
                 int endRva = -1;
                 if (_readyToRunReader.Machine == Machine.Amd64)
                 {
index 91dbf91..fa21ad4 100644 (file)
@@ -542,11 +542,6 @@ namespace R2RDump
             return null;
         }
 
-        private static bool InputArchitectureSupported(Machine machine)
-        {
-            return machine != Machine.ArmThumb2; // CoreDisTools often fails to decode when disassembling ARM images (see https://github.com/dotnet/runtime/issues/10959)
-        }
-
         // TODO: Fix R2RDump issue where an R2R image cannot be dissassembled with the x86 CoreDisTools
         // For the short term, we want to error out with a decent message explaining the unexpected error
         // Issue https://github.com/dotnet/runtime/issues/10928
@@ -581,7 +576,7 @@ namespace R2RDump
 
                     if (_options.Disasm)
                     {
-                        if (InputArchitectureSupported(r2r.Machine) && DisassemblerArchitectureSupported())
+                        if (DisassemblerArchitectureSupported())
                         {
                             disassembler = new Disassembler(r2r, _options);
                         }