Skip to content

Commit

Permalink
Fix errors for stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jul 15, 2024
1 parent 8e5f443 commit f00a621
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
11 changes: 11 additions & 0 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,17 @@ void LinkerDriver::link(opt::InputArgList &args) {
invokeELFT(markLive,);
demoteSharedAndLazySymbols();


for (const Symbol *sb : symtab.getSymbols()) {
if (sb->getName().ends_with("::stack_overflow")) {
const StringRef FuncName = sb->getName().substr(0, sb->getName().size());
report_fatal_error("Function " + FuncName +
" utilizes too much stack space and will cause "
"undefined behavior in the program. Refer to a"
"previously emitted warning for more information.");
}
}

// Make copies of any input sections that need to be copied into each
// partition.
copySectionsIntoPartitions();
Expand Down
31 changes: 27 additions & 4 deletions llvm/lib/Target/SBF/SBFRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,27 @@ static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL)
OldMF = &(MF.getFunction());

if (MF.getSubtarget<SBFSubtarget>().isSolana()) {
dbgs() << "Error:";
Function &OffendingFunction = MF.getFunction();

std::string MessageType;
std::string MessageExtra;
std::string NewName;
switch (OffendingFunction.getLinkage()) {
case GlobalValue::LinkageTypes::InternalLinkage:
case GlobalValue::LinkageTypes::PrivateLinkage:
MessageType = "Error:";
MessageExtra =
"The program is very likely to misbehave during execution "
"with unexpected consequences.";
break;
default:
MessageType = "Warning:";
MessageExtra = "The program may misbehave during execution.";
NewName = OffendingFunction.getName().str() + "::stack_overflow";
break;
}

dbgs() << MessageType;
if (DL) {
dbgs() << " ";
DL.print(dbgs());
Expand All @@ -65,9 +85,12 @@ static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL)
<< " Stack offset of " << -Offset << " exceeded max offset of "
<< -MaxOffset << " by " << MaxOffset - Offset
<< " bytes, please minimize large stack variables. "
<< "Estimated function frame size: " << StackSize << " bytes.\n\n";
report_fatal_error("Exceeding the maximum stack offset may cause "
"undefined behavior, including the loss of funds.");
<< "Estimated function frame size: " << StackSize << " bytes. "
<< MessageExtra << "\n\n";

if (!NewName.empty()) {
OffendingFunction.setName(NewName);
}
} else {
DiagnosticInfoUnsupported DiagStackSize(
MF.getFunction(),
Expand Down

0 comments on commit f00a621

Please sign in to comment.