From 931aa3756b1e9640a1f671545e80716c241ad239 Mon Sep 17 00:00:00 2001 From: Jonghyun Park Date: Thu, 29 Jun 2017 12:50:36 +0900 Subject: [PATCH] [x86/Linux] Adjust SP in throwing helper block (dotnet/coreclr#12504) * [x86/Linux] Adjust SP in throwing helper block * Fix format error * Use funKind intead of siInFuncletRegion * Use genSPtoFPdelta (and add some comments) * Fix a typo * Revert irrelevant changes Commit migrated from https://github.com/dotnet/coreclr/commit/cee0765158694f0715440987974d34dea8e6edd9 --- src/coreclr/src/jit/codegencommon.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/codegencommon.cpp b/src/coreclr/src/jit/codegencommon.cpp index a428d4f..fafb030 100644 --- a/src/coreclr/src/jit/codegencommon.cpp +++ b/src/coreclr/src/jit/codegencommon.cpp @@ -1642,6 +1642,18 @@ void CodeGen::genAdjustStackLevel(BasicBlock* block) { #if !FEATURE_FIXED_OUT_ARGS // Check for inserted throw blocks and adjust genStackLevel. + CLANG_FORMAT_COMMENT_ANCHOR; + +#if defined(UNIX_X86_ABI) + if (isFramePointerUsed() && compiler->fgIsThrowHlpBlk(block)) + { + // x86/Linux requires stack frames to be 16-byte aligned, but SP may be unaligned + // at this point if a jump to this block is made in the middle of pushing arugments. + // + // Here we restore SP to prevent potential stack alignment issues. + getEmitter()->emitIns_R_AR(INS_lea, EA_PTRSIZE, REG_SPBASE, REG_FPBASE, -genSPtoFPdelta()); + } +#endif if (!isFramePointerUsed() && compiler->fgIsThrowHlpBlk(block)) { @@ -2698,7 +2710,14 @@ void CodeGen::genExitCode(BasicBlock* block) void CodeGen::genJumpToThrowHlpBlk(emitJumpKind jumpKind, SpecialCodeKind codeKind, GenTreePtr failBlk) { - if (!compiler->opts.compDbgCode) + bool useThrowHlpBlk = !compiler->opts.compDbgCode; + +#if defined(UNIX_X86_ABI) && FEATURE_EH_FUNCLETS + // Inline exception-throwing code in funclet to make it possible to unwind funclet frames. + useThrowHlpBlk = useThrowHlpBlk && (compiler->funCurrentFunc()->funKind == FUNC_ROOT); +#endif // UNIX_X86_ABI && FEATURE_EH_FUNCLETS + + if (useThrowHlpBlk) { /* For non-debuggable code, find and use the helper block for raising the exception. The block may be shared by other trees too. */ -- 2.7.4