From ee7066d3c83211bf38378d6cb4c8b0dae7f5f361 Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Thu, 30 Jul 2015 23:27:24 +0000 Subject: [PATCH] Cut more IDA calls to FuncInfo stack frame methods; reduce spurious ERROR log messages. Former-commit-id: e355967cb4990540b6fecf66ba6d54c24070ce67 --- src/base/SMPFunction.cpp | 57 ++++++++++++++++++++++------------------ src/base/SMPInstr.cpp | 2 +- src/base/SMPProgram.cpp | 6 ++--- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index dc6d99c3..015f59d7 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -197,6 +197,7 @@ SMPFunction::SMPFunction(STARS_Function_t *Info, SMPProgram* pgm) { this->UnsafeBlocks = 0; this->Size = 0; +#if 0 // The sizes of the three regions of the stack frame other than the // return address are stored in the function structure. this->LocalVarsSize = this->FuncInfo->GetFrameSize(); @@ -207,6 +208,12 @@ SMPFunction::SMPFunction(STARS_Function_t *Info, SMPProgram* pgm) { // way by calling get_frame_retsize(). this->RetAddrSize = /* get_frame_retsize(this->GetFuncInfo()); */ this->GetFuncInfo()->GetFrameReturnAddressSize(); +#else // compute values in MDFixFrameInfo() before their first use; avoid IDA Pro calls + this->LocalVarsSize = 0; + this->CalleeSavedRegsSize = 0; + this->IncomingArgsSize = 0; // unused + this->RetAddrSize = global_STARS_program->GetSTARS_ISA_Bytewidth(); +#endif this->OutgoingArgsSize = 0; this->LocalVarsAllocInstr = STARS_BADADDR; @@ -1768,7 +1775,7 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { } else if (FoundAllocInstr) { // We can now start searching for the DeallocInstr. - if (CurrInst->MDIsFrameDeallocInstr(UseFP, this->LocalVarsSize)) { + if (CurrInst->MDIsFrameDeallocInstr(UseFP, this->GetLocalVarsSize())) { // Keep saving the most recent addr that looks // like the DeallocInstr until we reach the // end of the function. Last one to look like @@ -1805,7 +1812,7 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { // by matching LocalVarsSize to the immediate value in the allocation // instruction. However, IDA Pro is sometimes a little off on this // number. **!!** - if (0 < this->LocalVarsSize) { + if (0 < this->GetLocalVarsSize()) { if (DebugFlag) SMP_msg("Searching for alloc and dealloc\n"); list<SMPInstr *>::iterator InstIter = this->Instrs.begin(); #if SMP_USE_SSA_FNOP_MARKER @@ -1831,7 +1838,7 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { } else if (FoundAllocInstr) { // We can now start searching for the DeallocInstr. - if (CurrInst->MDIsFrameDeallocInstr(UseFP, this->LocalVarsSize)) { + if (CurrInst->MDIsFrameDeallocInstr(UseFP, this->GetLocalVarsSize())) { // Keep saving the most recent addr that looks // like the DeallocInstr until we reach the // end of the function. Last one to look like @@ -1861,7 +1868,7 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { SMP_msg("WARNING: Could not find stack frame allocation in %s\n", this->GetFuncName()); SMP_msg("LocalVarsSize: %lu SavedRegsSize: %u ArgsSize: %llu\n", - (unsigned long) LocalVarsSize, CalleeSavedRegsSize, (unsigned long long) IncomingArgsSize); + (unsigned long) this->GetLocalVarsSize(), CalleeSavedRegsSize, (unsigned long long) IncomingArgsSize); } else { SMP_msg("FindAllocPoint found %lx for function %s\n", @@ -1923,7 +1930,7 @@ void SMPFunction::FindAllAllocsAndDeallocs(void) { #endif } // end if (LocalVarsSize > 0) ... else ... - if (!FoundAllocInstr && (0 < this->LocalVarsSize) && this->IsLeaf()) { + if (!FoundAllocInstr && (0 < this->GetLocalVarsSize()) && this->IsLeaf()) { // 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. @@ -2312,7 +2319,7 @@ STARS_ea_t SMPFunction::FindAllocPoint(STARS_asize_t OriginalLocSize) { // NOTE As of July, 2015, this logic was incorporated into MDFixFrameInfo(). bool SMPFunction::MDFixUseFP(void) { bool OldUseFP = this->UsesFramePointer(); - bool HasLocals = (0 < this->LocalVarsSize); + bool HasLocals = (0 < this->GetLocalVarsSize()); list<SMPInstr *>::iterator InstIter = this->Instrs.begin(); STARS_ea_t addr; @@ -3172,7 +3179,7 @@ void SMPFunction::SemiNaiveLocalVarID(void) { assert(this->LocalVarTable.size() > 0); for (std::size_t VarIndex = 0; VarIndex < VarLimit; ++VarIndex) { struct LocalVar TempLocEntry = this->LocalVarTable[VarIndex]; - bool AboveLocalsRegion = (TempLocEntry.offset >= this->LocalVarsSize); + bool AboveLocalsRegion = (TempLocEntry.offset >= this->GetLocalVarsSize()); std::size_t TempSize = this->LocalVarTable[VarIndex + 1].offset - TempLocEntry.offset; int DiffSize = ((int) TempSize) - ((int) TempLocEntry.size); // We don't have IDA Pro stack frame members for callee saved registers. This @@ -3180,16 +3187,16 @@ void SMPFunction::SemiNaiveLocalVarID(void) { // variable and the return address or saved frame pointer. Avoid expanding the // last local variable into the callee saved registers region. if (DiffSize > 0) { // We are expanding the size. - if (!AboveLocalsRegion && ((TempLocEntry.offset + TempLocEntry.size + DiffSize) > this->LocalVarsSize)) { + if (!AboveLocalsRegion && ((TempLocEntry.offset + TempLocEntry.size + DiffSize) > this->GetLocalVarsSize())) { // Current local does not start above the locals region, but its new size will // carry it above the locals region. - if ((TempLocEntry.offset + TempLocEntry.size) > this->LocalVarsSize) { + if ((TempLocEntry.offset + TempLocEntry.size) > this->GetLocalVarsSize()) { // Weird. It already overlapped the callee saved regs region. SMP_msg("WARNING: Local var at offset %ld size %zu in %s extends above local vars region.\n", TempLocEntry.offset, TempLocEntry.size, this->GetFuncName()); } // Limit DiffSize to avoid overlapping callee saved regs. - DiffSize = this->LocalVarsSize - (TempLocEntry.offset + TempLocEntry.size); + DiffSize = this->GetLocalVarsSize() - (TempLocEntry.offset + TempLocEntry.size); if (DiffSize < 0) DiffSize = 0; // started out positive, cap it at zero. } @@ -3220,7 +3227,7 @@ void SMPFunction::SemiNaiveLocalVarID(void) { #if 0 SavedRegsSpace = this->CalleeSavedRegsSize - this->FuncInfo->GetSavedRegSize(); #else - SavedRegsSpace = this->FuncInfo->GetFrameSize() - this->LocalVarsSize; + SavedRegsSpace = this->FuncInfo->GetFrameSize() - this->GetLocalVarsSize(); #endif } @@ -3239,7 +3246,7 @@ void SMPFunction::SemiNaiveLocalVarID(void) { this->LocalVarTable.clear(); this->GoodLocalVarTable = false; SMP_msg("WARNING: Bad frsize %d for %s OffsetLimit: %d AboveLocalsSize: %d LocalVarsSize: %d ; abandoning SemiNaiveLocalVarID.\n", - this->FuncInfo->GetFrameSize(), this->GetFuncName(), this->GetLocalVarOffsetLimit(), AboveLocalsSize, this->LocalVarsSize); + this->FuncInfo->GetFrameSize(), this->GetFuncName(), this->GetLocalVarOffsetLimit(), AboveLocalsSize, this->GetLocalVarsSize()); return; } assert((this->GetLocalVarOffsetLimit() - AboveLocalsSize) <= (STARS_adiff_t) this->FuncInfo->GetFrameSize()); @@ -3810,7 +3817,7 @@ bool SMPFunction::MDGetStackOffsetAndSize(SMPInstr *Instr, const STARSOpndTypePt return true; } else if (this->UseFP && ((BaseReg == MD_FRAME_POINTER_REG) || (IndexReg == MD_FRAME_POINTER_REG))) { - SignedOffset -= this->FuncInfo->GetSavedRegSize(); // base offsets from entry ESP value + SignedOffset += this->GetFramePtrStackDelta(); // base offsets from entry ESP value, e.g. ebp-4 == esp-8 SignedOffset -= BaseValue; // convert to StackFrameMap index offset = (STARS_ea_t) SignedOffset; DataSize = GetOpDataSize(TempOp); @@ -3830,7 +3837,7 @@ bool SMPFunction::MDGetStackOffsetAndSize(SMPInstr *Instr, const STARSOpndTypePt if ((0 > SignedOffset) && (!Indexed) && (BaseValue == this->MinStackAccessOffset)) { // Consider asserting here. SMP_msg("ERROR: Negative offset %d in MDGetStackOffsetAndSize: frregs: %d MinStackDelta: %ld Inst dump: \n", - SignedOffset, this->FuncInfo->GetSavedRegSize(), (long) this->MinStackDelta); + SignedOffset, this->CalleeSavedRegsSize, (long) this->MinStackDelta); Instr->Dump(); } return true; @@ -4316,13 +4323,13 @@ void SMPFunction::EmitStackFrameAnnotations(FILE *AnnotFile, SMPInstr *Instr) { if (0 < IncomingArgsSize) { SMP_fprintf(AnnotFile, "%18llx %6llu INARGS STACK esp + %ld %s \n", (unsigned long long) addr, (unsigned long long) IncomingArgsSize, - (long) (LocalVarsSize + CalleeSavedRegsSize + RetAddrSize), + (long) (this->GetLocalVarsSize() + CalleeSavedRegsSize + RetAddrSize), Instr->GetDisasm()); } #endif if (0 < this->RetAddrSize) { SMP_fprintf(AnnotFile, "%18llx %6d MEMORYHOLE STACK esp + %lu ReturnAddress \n", - (unsigned long long) addr, RetAddrSize, (unsigned long)(this->LocalVarsSize + this->CalleeSavedRegsSize)); + (unsigned long long) addr, RetAddrSize, (unsigned long)(this->GetLocalVarsSize() + this->CalleeSavedRegsSize)); } if (this->GoodLocalVarTable && (!this->NegativeOffsetStackFrameMap.empty())) { // Walk through the NegativeOffsetStackFrameMap and emit annotations for the regions. @@ -4350,9 +4357,9 @@ void SMPFunction::EmitStackFrameAnnotations(FILE *AnnotFile, SMPInstr *Instr) { else if (CurrentRegionType == STARS_STACK_LOCAL_FRAME) { ParentReferentID = global_STARS_program->GetDataReferentID(); global_STARS_program->IncrementDataReferentID(); - if (this->LocalVarsSize != (CurrentRegionBytes + this->OutgoingArgsSize)) { + if (this->GetLocalVarsSize() != (CurrentRegionBytes + this->OutgoingArgsSize)) { SMP_msg("ERROR: LocalVarsSize: %lu not sum of CurrentRegionBytes: %u and OutArgsSize: %zu at %llu\n", - this->LocalVarsSize, CurrentRegionBytes, this->OutgoingArgsSize, (unsigned long long) addr); + this->GetLocalVarsSize(), CurrentRegionBytes, this->OutgoingArgsSize, (unsigned long long) addr); } SMP_fprintf(AnnotFile, "%18llx %6u DATAREF STACK %lu esp + 0 PARENT LocalFrame LOCALFRAME\n", (unsigned long long) addr, CurrentRegionBytes + this->OutgoingArgsSize, (unsigned long) ParentReferentID); @@ -4420,23 +4427,23 @@ void SMPFunction::EmitStackFrameAnnotations(FILE *AnnotFile, SMPInstr *Instr) { if (0 < IncomingArgsSize) { SMP_fprintf(AnnotFile, "%18llx %6llu INARGS STACK esp + %ld %s \n", (unsigned long long) addr, (unsigned long long) IncomingArgsSize, - (long) (LocalVarsSize + CalleeSavedRegsSize + RetAddrSize), + (long) (this->GetLocalVarsSize() + CalleeSavedRegsSize + RetAddrSize), Instr->GetDisasm()); } #endif if (0 < this->RetAddrSize) { SMP_fprintf(AnnotFile, "%18llx %6d MEMORYHOLE STACK esp + %lu ReturnAddress \n", - (unsigned long long) addr, RetAddrSize, (unsigned long) (this->LocalVarsSize + this->CalleeSavedRegsSize)); + (unsigned long long) addr, RetAddrSize, (unsigned long) (this->GetLocalVarsSize() + this->CalleeSavedRegsSize)); } if (0 < this->CalleeSavedRegsSize) { SMP_fprintf(AnnotFile, "%18llx %6u MEMORYHOLE STACK esp + %lu CalleeSavedRegs \n", - (unsigned long long) addr, this->CalleeSavedRegsSize, (unsigned long) this->LocalVarsSize); + (unsigned long long) addr, this->CalleeSavedRegsSize, (unsigned long) this->GetLocalVarsSize()); } - if ((0 < this->LocalVarsSize) && this->GoodLocalVarTable) { + if ((0 < this->GetLocalVarsSize()) && this->GoodLocalVarTable) { unsigned long ParentReferentID = global_STARS_program->GetDataReferentID(); global_STARS_program->IncrementDataReferentID(); SMP_fprintf(AnnotFile, "%18llx %6lu DATAREF STACK %lu esp + %d PARENT LocalFrame LOCALFRAME\n", - (unsigned long long) addr, (unsigned long) this->LocalVarsSize, ParentReferentID, 0); + (unsigned long long) addr, (unsigned long) this->GetLocalVarsSize(), ParentReferentID, 0); if (this->AnalyzedSP && !this->CallsAlloca && (STARS_BADADDR != this->LocalVarsAllocInstr)) { // We can only fine-grain the stack frame if we were able to analyze the stack if (this->OutgoingArgsSize > 0) { @@ -8881,7 +8888,7 @@ void SMPFunction::EmitAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { } else if (DeallocTrigger) { // Time for annotation SMP_fprintf(AnnotFile, "%18llx %6lu DEALLOC STACK esp - %lu %s\n", (unsigned long long) addr, - (unsigned long) this->LocalVarsSize, (unsigned long) this->LocalVarsSize, CurrInst->GetDisasm()); + (unsigned long) this->GetLocalVarsSize(), (unsigned long) this->GetLocalVarsSize(), CurrInst->GetDisasm()); DeallocTrigger = false; } CurrInst->EmitAnnotations(this->UseFP, AllocSeen, this->NeedsStackReferent, AnnotFile, InfoAnnotFile); @@ -8977,7 +8984,7 @@ void SMPFunction::EmitAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { } else if (DeallocTrigger) { // Time for annotation SMP_fprintf(AnnotFile, "%18llx %6lu DEALLOC STACK esp - %lu %s\n", (unsigned long long) addr, - (unsigned long) this->LocalVarsSize, (unsigned long) this->LocalVarsSize, CurrInst->GetDisasm()); + (unsigned long) this->GetLocalVarsSize(), (unsigned long) this->GetLocalVarsSize(), CurrInst->GetDisasm()); DeallocTrigger = false; } diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp index 1b847b2f..b6e07711 100644 --- a/src/base/SMPInstr.cpp +++ b/src/base/SMPInstr.cpp @@ -4282,7 +4282,7 @@ void SMPInstr::Analyze(void) { this->CallTarget = CurrUse->GetOp()->GetAddr(); } } - if (STARS_BADADDR == this->CallTarget) { + if ((STARS_BADADDR == this->CallTarget) && (STARS_NN_syscall != opcode)) { SMP_msg("ERROR: Target not found for direct call at %llx\n", (unsigned long long) this->GetAddr()); } } diff --git a/src/base/SMPProgram.cpp b/src/base/SMPProgram.cpp index a14ba9cf..cbbbd26b 100644 --- a/src/base/SMPProgram.cpp +++ b/src/base/SMPProgram.cpp @@ -502,8 +502,8 @@ void SMPProgram::Analyze(ProfilerInformation *pi, FILE *AnnotFile, FILE *InfoAnn SMPFunction *ChildInstance = this->FindFunction(CallAddr); if (!ChildInstance) { #if SMP_DEBUG_FUNC - // if a call target doesnt have a SMPFunction instance note it down - if (!CurrFunc->IsLinkerStub()) { + // if a call target doesn't have a SMPFunction instance note it down + if (!CurrFunc->IsLinkerStub() && (STARS_BADADDR != CallAddr)) { SMP_msg("ERROR: Function does not have SMPFunction instance at %llx from %s\n", (unsigned long long) CallAddr, CurrFunc->GetFuncName()); } #endif @@ -855,7 +855,7 @@ FuncType SMPProgram::RecurseAndMarkRetAdd(SMPFunction* FuncAttrib) { for (size_t i = 0; i < CallTargets.size(); i++) { STARS_ea_t CallAddr = CallTargets[i]; SMPFunction* ChildInstance = this->FindFunction(CallAddr); - if (!ChildInstance) { + if (!ChildInstance && (STARS_BADADDR != CallAddr)) { #if SMP_DEBUG_FUNC // if a call target doesnt have a SMPFunction instance note it down SMP_msg("ERROR: Function does not have SMPFunction instance at %llx from %s\n", -- GitLab