aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SafeStack.cpp
diff options
context:
space:
mode:
authorPaul Kirth <paulkirth@google.com>2022-04-19 16:34:23 +0000
committerPaul Kirth <paulkirth@google.com>2022-04-20 18:29:40 +0000
commit61e36e87df1a4ad11f752d66c90e124101fe4023 (patch)
treedea1d2f021d07819b05d67764c3f1949467f3376 /llvm/lib/CodeGen/SafeStack.cpp
parent340654e0f246cddb3fb6ebddb843ade9bfcff0a5 (diff)
downloadllvm-61e36e87df1a4ad11f752d66c90e124101fe4023.zip
llvm-61e36e87df1a4ad11f752d66c90e124101fe4023.tar.gz
llvm-61e36e87df1a4ad11f752d66c90e124101fe4023.tar.bz2
[safestack] Support safestack in stack size diagnostics
Current stack size diagnostics ignore the size of the unsafe stack. This patch attaches the size of the static portion of the unsafe stack to the function as metadata, which can be used by the backend to emit diagnostics regarding stack usage. Reviewed By: phosek, mcgrathr Differential Revision: https://reviews.llvm.org/D119996
Diffstat (limited to 'llvm/lib/CodeGen/SafeStack.cpp')
-rw-r--r--llvm/lib/CodeGen/SafeStack.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index 1f7eac4..2c16c191 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -48,6 +48,7 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
@@ -633,6 +634,13 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
// FIXME: no need to update BasePointer in leaf functions.
unsigned FrameSize = alignTo(SSL.getFrameSize(), StackAlignment);
+ MDBuilder MDB(F.getContext());
+ SmallVector<Metadata *, 2> Data;
+ Data.push_back(MDB.createString("unsafe-stack-size"));
+ Data.push_back(MDB.createConstant(ConstantInt::get(Int32Ty, FrameSize)));
+ MDNode *MD = MDTuple::get(F.getContext(), Data);
+ F.setMetadata(LLVMContext::MD_annotation, MD);
+
// Update shadow stack pointer in the function epilogue.
IRB.SetInsertPoint(BasePointer->getNextNode());