From ae40c45f2de14e1e670c5af7b0533da838d7cc68 Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Tue, 14 Jul 2015 02:06:16 +0000 Subject: [PATCH] Move MDFixUseFP() logic earlier, don't depend on IDA Pro numbers, just compute UseFP or not. Former-commit-id: e96a39edd1965be394c86ca7a75cc69ac4012773 --- src/base/SMPFunction.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index 5acf6406..00bd3f84 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -1780,11 +1780,13 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { // we can try to fix incorrect sets of UseFP by IDA. // NOTE: We might want to extend this in the future to // handle functions that have no locals. **!!** +#if 0 bool FixedUseFP = MDFixUseFP(); #if SMP_DEBUG_FRAMEFIXUP if (FixedUseFP) { SMP_msg("Fixed UseFP in %s\n", this->GetFuncName()); } +#endif #endif if (this->UsesFramePointer()) { // now that MDFixUseFP() has validated this flag ... this->FindFramePointerDelta(); // find stack delta that is saved in frame pointer in function prologue @@ -1874,11 +1876,13 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { // we can try to fix incorrect sets of UseFP by IDA. // NOTE: We might want to extend this in the future to // handle functions that have no locals. **!!** +#if 0 bool FixedUseFP = this->MDFixUseFP(); #if SMP_DEBUG_FRAMEFIXUP if (FixedUseFP) { SMP_msg("Fixed UseFP in %s\n", this->GetFuncName()); } +#endif #endif if (this->UsesFramePointer()) { // now that MDFixUseFP() has validated this flag ... this->FindFramePointerDelta(); // find stack delta that is saved in frame pointer in function prologue @@ -1889,11 +1893,13 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { // The x86-64 ABI saves time by not allocating a local frame for some leaf functions, // and just accesses locations below the stack as if they were allocated local vars. // We still want the UseFP and FramePointerDelta members to be properly set. +#if 0 bool FixedUseFP = MDFixUseFP(); #if SMP_DEBUG_FRAMEFIXUP if (FixedUseFP) { SMP_msg("Fixed UseFP in %s\n", this->GetFuncName()); } +#endif #endif if (this->UsesFramePointer()) { // now that MDFixUseFP() has validated this flag ... this->FindFramePointerDelta(); // find stack delta that is saved in frame pointer in function prologue @@ -2050,6 +2056,8 @@ bool SMPFunction::MDFixFrameInfo(void) { int NewLocalsSize = 0; int OldFrameTotal = this->CalleeSavedRegsSize + this->LocalVarsSize; bool Changed = false; + bool EBPSaved = false; // detected push of frame pointer reg + bool ESPintoEBP = false; // detected initialization of frame pointer reg with stack pointer reg value bool DebugFlag = (0 == strcmp("__libc_csu_init", this->GetFuncName())); // Iterate through the first basic block in the function. If we find @@ -2088,6 +2096,11 @@ bool SMPFunction::MDFixFrameInfo(void) { if (DebugFlag) SMP_msg("libc_csu_init OtherPushesSize: %d %s\n", OtherPushesSize, CurrInstr->GetDisasm()); } + if (!EBPSaved) { // still looking for "push ebp" + if (CurrInstr->GetOperand(0)->MatchesReg(MD_FRAME_POINTER_REG)) { + EBPSaved = true; + } + } } else if (CurrInstr->MDIsFrameAllocInstr()) { if (DebugFlag) SMP_msg("libc_csu_init allocinstr: %s\n", CurrInstr->GetDisasm()); @@ -2149,6 +2162,13 @@ bool SMPFunction::MDFixFrameInfo(void) { SMP_msg("INFO: Miscellaneous stack pointer delta of %d found at %lx in MDFixFrameInfo\n", (unsigned long) CurrInstr->GetAddr()); } } + else if (EBPSaved && (!ESPintoEBP)) { // found "push ebp", looking for "mov ebp,esp" + if ((CurrInstr->GetIDAOpcode() == STARS_NN_mov) + && (CurrInstr->GetFirstDef()->GetOp()->MatchesReg(MD_FRAME_POINTER_REG)) + && (CurrInstr->GetFirstUse()->GetOp()->MatchesReg(MD_STACK_POINTER_REG))) { + ESPintoEBP = true; + } + } } // end for all instructions in the first basic block // If we did not find an allocating instruction, see if it would keep @@ -2193,6 +2213,10 @@ bool SMPFunction::MDFixFrameInfo(void) { } #endif + // If we found ESPintoEBP, we also found EBPSaved first, and we need to set + // this->UseFP to true. + this->UseFP = ESPintoEBP; + return Changed; } // end of SMPFunction::MDFixFrameInfo() -- GitLab