Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/SMPStaticAnalyzer
1 result
Show changes
Commits on Source (9)
......@@ -19,11 +19,6 @@ after_script:
- ./cicd_testing/starstest2.sh
# per os items
test-ubuntu18:
<<: *test
tags:
- ubuntu18
test-ubuntu20:
<<: *test
tags:
......
......@@ -1069,7 +1069,8 @@ public:
// Trace UseOp through register moves back to its stack location or immediate value source.
// Return true if we are passing an immediate or stack location back in UltSource.
bool TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSANum, STARSOpndTypePtr &UltSource, bool &FPRelative);
bool TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSANum, STARSOpndTypePtr &UltSource, bool &FPRelative);
bool TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSANum, STARSOpndTypePtr &UltSource, bool &FPRelative, SMPInstr* &SourceInstr);
bool HasNoCodeXrefs(void); // inst has no code xrefs
bool IsLoopExitStatement(bool &InvertedExit); // true => jump is used to exit a loop
inline bool AnalyzeSwitchInfo(struct SwitchTableInfo &TableInfo) { return STARSInstPtr->AnalyzeSwitchStatement(this, TableInfo); };
......
......@@ -2047,11 +2047,15 @@ STARS_ea_t SMPBasicBlock::GetDefAddrFromUseAddr(const STARSOpndTypePtr &UseOp, S
// Global DEF for this SSANum must be in the Phi functions or within a block.
DefAddr = this->MyFunc->GetGlobalDefAddr(UseOp, SSANum); // only works on registers and stack locations
if (DefAddr == STARS_BADADDR) { // Could not find it anywhere.
this->GetFunc()->Dump(false);
if(getenv("DEBUG")){
this->GetFunc()->Dump(false);
} else {
SMP_msg("ERROR: Failure while analyzing DefUse chains in function %s\n", this->MyFunc->GetFuncName());
}
SMP_msg("ERROR: Failure in GetDefAddrFromUseAddr(): InstAddr %lx SSANum %d\n",
(unsigned long) InstAddr, SSANum);
SMP_msg(" LocalName: %d UseOp.reg: %d\n", LocalName, UseOp->GetReg());
assert(DefAddr != STARS_BADADDR); // kablooey!
return DefAddr;
}
}
else if (LocalName || PhiUse) {
......
......@@ -14002,8 +14002,22 @@ void SMPInstr::SCCPFetchConstDefValue(const STARSOpndTypePtr &DefOp, STARS_SCCP_
// Trace UseOp through register moves back to its stack location or immediate value source.
// Return true if we are passing an immediate or stack location back in UltSource.
bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSANum, STARSOpndTypePtr &UltSource, bool &FPRelative) {
// If we hit an immediate value or a stack location, we are done.
bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer();
SMPInstr *discard = nullptr;
return this->TraceUltimateMoveSource(UseOp, UseSSANum, UltSource, FPRelative, discard);
}
// Trace UseOp through register moves back to its stack location or immediate value source.
// Return true if we are passing an immediate or stack location back in UltSource.
// SourceInstr will contain the source instruction if we were able to find it. If not, it is set to nullptr
bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSANum, STARSOpndTypePtr &UltSource, bool &FPRelative, SMPInstr* &SourceInstr) {
if(this->GetBlock() == nullptr || this->GetBlock()->GetFunc() == nullptr){
// We don't have enough info
UltSource = nullptr;
SourceInstr = nullptr;
return false;
}
// If we hit an immediate value or a stack location, we are done.
bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer();
STARSOpndTypePtr DefOp = nullptr, ImmOp = nullptr;
int NewUseSSANum;
set<DefOrUse,LessDefUse>::iterator UseIter;
......@@ -14011,18 +14025,21 @@ bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSA
STARS_ea_t DefAddr;
SMPInstr *DefInst;
 
SourceInstr = nullptr;
UltSource = nullptr;
bool StackOp = MDIsDirectStackAccessOpnd(UseOp, UseFP);
bool RegisterOp = (UseOp->IsRegOp());
 
if (this->GetOptType() == 3) { // move instruction
if (UseOp->IsImmedOp()) {
SourceInstr = this;
UltSource = UseOp;
return true;
}
else if ((!RegisterOp) && (!StackOp)) {
// We only trace the move chain through registers or stack locations to an ultimate
// load-effective-address of a stack location, or a move of an immediate value.
SourceInstr = this;
return false;
}
}
......@@ -14074,6 +14091,7 @@ bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSA
}
else if (DefInst->MDIsLoadEffectiveAddressInstr()) {
NewUseOp = DefInst->GetLeaMemUseOp();
SourceInstr = DefInst;
if (MDIsDirectStackAccessOpnd(NewUseOp, UseFP)) {
UltSource = NewUseOp;
FPRelative = DefInst->HasFPNormalizedToSP();
......@@ -14089,6 +14107,7 @@ bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSA
// Case 1: A register is cleared. Same as assigning immediate value zero to the reg.
else if (DefInst->IsRegClearIdiom()) {
UltSource = this->STARSInstPtr->MakeImmediateOpnd(0);
SourceInstr = DefInst;
// why would we memset a zero byte region?
return true;
}
......@@ -14105,6 +14124,7 @@ bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSA
return false;
}
NewDefInst = DefInst->GetBlock()->GetFunc()->GetInstFromAddr(DefAddr);
SourceInstr = NewDefInst;
if (NewDefInst->MDIsLoadEffectiveAddressInstr()) {
NewUseOp = NewDefInst->GetLeaMemUseOp()->clone();
if (MDIsDirectStackAccessOpnd(NewUseOp, UseFP)) {
......@@ -14135,7 +14155,13 @@ bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSA
}
else {
// Not the kind of instruction we need; cut short the recursion.
return false;
if(!DefInst->IsMarkerInst()) {
SourceInstr = DefInst;
} else {
// Ensure that we do not return a pseudo instruction
SourceInstr = nullptr;
}
return false;
}
 
// NewUseOp is the move source operand that we seek.
......@@ -14144,7 +14170,7 @@ bool SMPInstr::TraceUltimateMoveSource(const STARSOpndTypePtr &UseOp, int UseSSA
assert(UseIter != DefInst->GetLastUse());
NewUseSSANum = UseIter->GetSSANum(); // unused for immediates, used for regs and stack
// Recurse
return DefInst->TraceUltimateMoveSource(NewUseOp, NewUseSSANum, UltSource, FPRelative);
return DefInst->TraceUltimateMoveSource(NewUseOp, NewUseSSANum, UltSource, FPRelative, SourceInstr);
 
} // end of SMPInstr::TraceUltimateMoveSource()
 
......@@ -27279,9 +27305,17 @@ bool SMPInstr::BuildX86RTL(void)
case STARS_NN_wrussq: // Write (8 bytes) to User Shadow Stack
case STARS_NN_setssbsy: // Mark Shadow Stack Busy
case STARS_NN_clrssbsy: // Clear Shadow Stack Busy Flag
return false;
break;
case STARS_NN_endbr64: // Terminate an Indirect Branch in 64-bit Mode
case STARS_NN_endbr32: // Terminate an Indirect Branch in 32-bit and Compatibility Mode
return false;
NopRT = new SMPRegTransfer;
NopRT->SetParentInst(this);
NopRT->SetOperator(SMP_NULL_OPERATOR);
this->RTL.push_back(NopRT);
NopRT = nullptr;
return true;
break;
 
// Undefined Instruction