Skip to content

Commit

Permalink
Revert: "[Stack Protection] Add diagnostic information for why stack …
Browse files Browse the repository at this point in the history
…protection was applied to a function"

this reverts revision r294590 as it broke some buildbots.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294593 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
bigboze committed Feb 9, 2017
1 parent 2105006 commit 32e76df
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 160 deletions.
31 changes: 0 additions & 31 deletions include/llvm/CodeGen/StackProtector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/ValueMap.h"
#include "llvm/Pass.h"
Expand Down Expand Up @@ -135,36 +134,6 @@ class StackProtector : public FunctionPass {

bool runOnFunction(Function &Fn) override;
};

/// Diagnostic information for why SSP was applied.
class DiagnosticInfoSSP : public DiagnosticInfoWithDebugLocBase {
public:
enum SSPReason {
Alloca = 0,
BufferOrStruct = 1,
AddressTaken = 2,
Attribute = 3,
LastUsedValue = 3
};

/// \p Fn is the function where the diagnostic is being emitted. \p Reason is
/// an enum value representing why the function has stack protection.
DiagnosticInfoSSP(const Function &Fn, SSPReason Reason)
: DiagnosticInfoWithDebugLocBase(DK_SSPReason, DS_Remark, Fn, DebugLoc()),
Func(Fn), Why(Reason) {}

static bool classof(const DiagnosticInfo *DI) {
return DI->getKind() == DK_SSPReason;
}

void print(DiagnosticPrinter &DP) const override;

SSPReason Reason() const { return Why; }

private:
const Function &Func;
const SSPReason Why;
};
} // end namespace llvm

#endif // LLVM_CODEGEN_STACKPROTECTOR_H
1 change: 0 additions & 1 deletion include/llvm/IR/DiagnosticInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ enum DiagnosticKind {
DK_MIRParser,
DK_PGOProfile,
DK_Unsupported,
DK_SSPReason,
DK_FirstPluginKind
};

Expand Down
42 changes: 1 addition & 41 deletions lib/CodeGen/StackProtector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
Expand All @@ -52,7 +51,7 @@ static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",

char StackProtector::ID = 0;
INITIALIZE_TM_PASS(StackProtector, "stack-protector", "Insert stack protectors",
false, true)
false, true)

FunctionPass *llvm::createStackProtectorPass(const TargetMachine *TM) {
return new StackProtector(TM);
Expand Down Expand Up @@ -224,8 +223,6 @@ bool StackProtector::RequiresStackProtector() {
return false;

if (F->hasFnAttribute(Attribute::StackProtectReq)) {
F->getContext().diagnose(
DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Attribute));
NeedsProtector = true;
Strong = true; // Use the same heuristic as strong to determine SSPLayout
} else if (F->hasFnAttribute(Attribute::StackProtectStrong))
Expand All @@ -244,21 +241,15 @@ bool StackProtector::RequiresStackProtector() {
// A call to alloca with size >= SSPBufferSize requires
// stack protectors.
Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
F->getContext().diagnose(
DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Alloca));
NeedsProtector = true;
} else if (Strong) {
// Require protectors for all alloca calls in strong mode.
Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
F->getContext().diagnose(
DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Alloca));
NeedsProtector = true;
}
} else {
// A call to alloca with a variable size requires protectors.
Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
F->getContext().diagnose(
DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Alloca));
NeedsProtector = true;
}
continue;
Expand All @@ -268,17 +259,13 @@ bool StackProtector::RequiresStackProtector() {
if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
: SSPLK_SmallArray));
F->getContext().diagnose(DiagnosticInfoSSP(
*F, DiagnosticInfoSSP::SSPReason::BufferOrStruct));
NeedsProtector = true;
continue;
}

if (Strong && HasAddressTaken(AI)) {
++NumAddrTaken;
Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
F->getContext().diagnose(DiagnosticInfoSSP(
*F, DiagnosticInfoSSP::SSPReason::AddressTaken));
NeedsProtector = true;
}
}
Expand Down Expand Up @@ -477,30 +464,3 @@ BasicBlock *StackProtector::CreateFailBB() {
bool StackProtector::shouldEmitSDCheck(const BasicBlock &BB) const {
return HasPrologue && !HasIRCheck && dyn_cast<ReturnInst>(BB.getTerminator());
}

void DiagnosticInfoSSP::print(DiagnosticPrinter &DP) const {
std::string Str;
raw_string_ostream OS(Str);

StringRef ReasonStr;
switch (Reason())
{
case Alloca:
ReasonStr = "a call to alloca or use of a variable length array";
break;
case BufferOrStruct:
ReasonStr = "a stack allocated buffer or struct containing a buffer";
break;
case AddressTaken:
ReasonStr = "the address of a local variable being taken";
break;
case Attribute:
ReasonStr = "a function attribute or command-line switch";
break;
}

OS << getLocationStr() << ": SSP applied to function " << Func.getName()
<< " due to " << ReasonStr << '\n';
OS.flush();
DP << Str;
}
87 changes: 0 additions & 87 deletions test/CodeGen/X86/stack-protector-remarks.ll

This file was deleted.

0 comments on commit 32e76df

Please sign in to comment.