From 9b84055eefbebba50cbbd61b3496fb57fa28d251 Mon Sep 17 00:00:00 2001 From: Mark Plesko Date: Thu, 10 Nov 2022 15:54:20 -0800 Subject: [PATCH 1/3] TARGET_AMD64 -> WINDOWS_AMD64_ABI --- src/coreclr/jit/codegen.h | 4 ++-- src/coreclr/jit/codegencommon.cpp | 6 +++--- src/coreclr/jit/emit.cpp | 4 ++-- src/coreclr/jit/emitpub.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index 8676dd22aaff..1def454ab95e 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -522,9 +522,9 @@ class CodeGen final : public CodeGenInterface void genReserveProlog(BasicBlock* block); // currently unused void genReserveEpilog(BasicBlock* block); -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void genFnPreProlog(); -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) void genFnProlog(); void genFnEpilog(BasicBlock* block); diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index be481b46b8f5..6b8ad1a7843f 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5483,11 +5483,11 @@ void CodeGen::genFinalizeFrame() * genFnPreProlog is optional (currently only on for x64 but eventually * some frames will likely skip it). * - * Although currently only being used for TARGET_AMD64, this is eventually + * Although currently only being used for WINDOWS_AMD64_ABI, this is eventually * intended for all architectures, so it is not in codegenxarch.cpp. */ -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void CodeGen::genFnPreProlog() { ScopedSetVariable _setGeneratingPreProlog(&compiler->compGeneratingPreProlog, true); @@ -5545,7 +5545,7 @@ void CodeGen::genFnPreProlog() emit->emitEndPreProlog(); } -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) /***************************************************************************** * diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 751525a3ba38..1503a478e6b0 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -1641,7 +1641,7 @@ void emitter::emitCheckIGoffsets() #endif // DEBUG -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void emitter::emitBegPreProlog() { @@ -1710,7 +1710,7 @@ void emitter::emitEndPreProlog() } } -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) /***************************************************************************** diff --git a/src/coreclr/jit/emitpub.h b/src/coreclr/jit/emitpub.h index c6e9ca41d370..f2818b5f34da 100644 --- a/src/coreclr/jit/emitpub.h +++ b/src/coreclr/jit/emitpub.h @@ -43,10 +43,10 @@ unsigned emitGetEpilogCnt(); template bool emitGenNoGCLst(Callback& cb); -#if defined(TARGET_AMD64) +#if defined(WINDOWS_AMD64_ABI) void emitBegPreProlog(); void emitEndPreProlog(); -#endif // defined(TARGET_AMD64) +#endif // defined(WINDOWS_AMD64_ABI) void emitBegProlog(); unsigned emitGetPrologOffsetEstimate(); void emitMarkPrologEnd(); From 72c3d393c4fe6058d02f95f142f08fd0e10a887c Mon Sep 17 00:00:00 2001 From: Mark Plesko Date: Thu, 10 Nov 2022 16:05:35 -0800 Subject: [PATCH 2/3] Unused --- src/coreclr/jit/emit.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 1503a478e6b0..035387f89917 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -1700,7 +1700,6 @@ void emitter::emitEndPreProlog() auto unwindCodeStart = (UNWIND_CODE*)&func->unwindCodes[func->unwindCodeSlot]; auto unwindCodeEnd = (UNWIND_CODE*)&func->unwindCodes[sizeof(func->unwindCodes)]; - int unwindCodeNodeSize = 1; for (auto unwindCodeCurrent = unwindCodeStart; unwindCodeCurrent != unwindCodeEnd; unwindCodeCurrent += UnwindCodeNodeSize(*unwindCodeCurrent)) { uint8_t oldCodeOffset = unwindCodeCurrent->CodeOffset; From 6faca5742f6fa18eba28d49d883232fc23f4db79 Mon Sep 17 00:00:00 2001 From: Mark Plesko Date: Thu, 10 Nov 2022 16:46:17 -0800 Subject: [PATCH 3/3] cleanup --- src/coreclr/jit/emit.cpp | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 035387f89917..41d44bb470e0 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -1666,27 +1666,13 @@ void emitter::emitBegPreProlog() int UnwindCodeNodeSize(UNWIND_CODE code) { - int unwindCodeNodeSize = 1; - switch (code.UnwindOp) + if (code.UnwindOp == UWOP_ALLOC_LARGE) { - case UWOP_ALLOC_LARGE: - if (code.OpInfo == 0) - unwindCodeNodeSize = 2; - else - unwindCodeNodeSize = 3; - break; - - case UWOP_SAVE_XMM128: - case UWOP_SAVE_NONVOL: - unwindCodeNodeSize = 2; - break; - - case UWOP_SAVE_NONVOL_FAR: - case UWOP_SAVE_XMM128_FAR: - unwindCodeNodeSize = 3; - break; + return (code.OpInfo == 0) ? 2 : 3; } - return unwindCodeNodeSize; + + // Since table gives -extra- slots, we add one for the actual size + return UnwindOpExtraSlotTable[code.UnwindOp] + 1; } void emitter::emitEndPreProlog() @@ -1697,11 +1683,12 @@ void emitter::emitEndPreProlog() FuncInfoDsc* func = emitComp->funCurrentFunc(); assert(func->unwindHeader.CountOfUnwindCodes == 0); // Can't call this after unwindReserve - auto unwindCodeStart = (UNWIND_CODE*)&func->unwindCodes[func->unwindCodeSlot]; - auto unwindCodeEnd = (UNWIND_CODE*)&func->unwindCodes[sizeof(func->unwindCodes)]; + auto unwindCodeStart = reinterpret_cast(&func->unwindCodes[func->unwindCodeSlot]); + auto unwindCodeEnd = reinterpret_cast(&func->unwindCodes[sizeof(func->unwindCodes)]); for (auto unwindCodeCurrent = unwindCodeStart; unwindCodeCurrent != unwindCodeEnd; unwindCodeCurrent += UnwindCodeNodeSize(*unwindCodeCurrent)) { + assert(unwindCodeCurrent < unwindCodeEnd); // Avoid a corrupted size leading to overrun by skipping the end uint8_t oldCodeOffset = unwindCodeCurrent->CodeOffset; uint8_t newCodeOffset = (uint8_t)(oldCodeOffset + prePrologSize); assert(newCodeOffset > oldCodeOffset); // I'm not sure if we can overflow here, but an assert should help