From: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 26 Aug 2021 17:34:56 +0000 (-0700) Subject: X86 Debug Stack offsets are encoded divided by 4 - Fix the encoding (#58094) X-Git-Tag: accepted/tizen/unified/20220110.054933~222^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0669a539416b71c07074953fa8a1b6747ed57b29;p=platform%2Fupstream%2Fdotnet%2Fruntime.git X86 Debug Stack offsets are encoded divided by 4 - Fix the encoding (#58094) Fixes #57951 Co-authored-by: David Wrighton --- diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index a0ccb44..841b6a9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -392,7 +392,7 @@ namespace Internal.JitInterface _methodCodeNode.InitializeEHInfo(ehInfo); _methodCodeNode.InitializeDebugLocInfos(_debugLocInfos); - _methodCodeNode.InitializeDebugVarInfos(_debugVarInfos); + _methodCodeNode.InitializeDebugVarInfos(_debugVarInfos, _compilation.TypeSystemContext.Target); #if READYTORUN _methodCodeNode.InitializeInliningInfo(_inlinedMethods.ToArray()); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugInfoTableNode.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugInfoTableNode.cs index fd628b6..24f5409 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugInfoTableNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugInfoTableNode.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using Internal.JitInterface; @@ -149,11 +150,13 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun return writer.ToArray(); } - public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos) + public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos, TargetDetails target) { if (varInfos == null || varInfos.Length == 0) return null; + bool isX86 = target.Architecture == TargetArchitecture.X86; + NibbleWriter writer = new NibbleWriter(); writer.WriteUInt((uint)varInfos.Length); @@ -177,7 +180,7 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun case VarLocType.VLT_STK: case VarLocType.VLT_STK_BYREF: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); - writer.WriteInt(nativeVarInfo.varLoc.C); + WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.C, assume4ByteAligned : isX86); break; case VarLocType.VLT_REG_REG: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); @@ -186,16 +189,16 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun case VarLocType.VLT_REG_STK: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); - writer.WriteInt(nativeVarInfo.varLoc.D); + WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.D, assume4ByteAligned : isX86); break; case VarLocType.VLT_STK_REG: - writer.WriteInt(nativeVarInfo.varLoc.B); + WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.B, assume4ByteAligned : isX86); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); writer.WriteUInt((uint)nativeVarInfo.varLoc.D); break; case VarLocType.VLT_STK2: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); - writer.WriteInt(nativeVarInfo.varLoc.C); + WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.C, assume4ByteAligned : isX86); break; case VarLocType.VLT_FPSTK: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); @@ -206,6 +209,19 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun default: throw new BadImageFormatException("Unexpected var loc type"); } + + static void WriteEncodedStackOffset(NibbleWriter _writer, int offset, bool assume4ByteAligned) + { + if (assume4ByteAligned) + { + Debug.Assert(offset % 4 == 0); + _writer.WriteInt(offset / 4); + } + else + { + _writer.WriteInt(offset); + } + } } return writer.ToArray(); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs index 9dc2907..720cce1 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/MethodWithGCInfo.cs @@ -296,12 +296,12 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun _debugLocInfos = DebugInfoTableNode.CreateBoundsBlobForMethod(debugLocInfos); } - public void InitializeDebugVarInfos(NativeVarInfo[] debugVarInfos) + public void InitializeDebugVarInfos(NativeVarInfo[] debugVarInfos, TargetDetails target) { Debug.Assert(_debugVarInfos == null); // Process the debug info from JIT format to R2R format immediately as it is large // and not used in the rest of the process except to emit. - _debugVarInfos = DebugInfoTableNode.CreateVarBlobForMethod(debugVarInfos); + _debugVarInfos = DebugInfoTableNode.CreateVarBlobForMethod(debugVarInfos, target); } public void InitializeDebugEHClauseInfos(DebugEHClauseInfo[] debugEHClauseInfos)