diff options
author | Paul Kirth <paulkirth@google.com> | 2022-04-19 16:34:23 +0000 |
---|---|---|
committer | Paul Kirth <paulkirth@google.com> | 2022-04-20 18:29:40 +0000 |
commit | 61e36e87df1a4ad11f752d66c90e124101fe4023 (patch) | |
tree | dea1d2f021d07819b05d67764c3f1949467f3376 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | 340654e0f246cddb3fb6ebddb843ade9bfcff0a5 (diff) | |
download | llvm-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/MachineFunction.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index db91088..06830e8 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -107,6 +107,27 @@ static const char *getPropertyName(MachineFunctionProperties::Property Prop) { llvm_unreachable("Invalid machine function property"); } +void setUnsafeStackSize(const Function &F, MachineFrameInfo &FrameInfo) { + if (!F.hasFnAttribute(Attribute::SafeStack)) + return; + + auto *Existing = + dyn_cast_or_null<MDTuple>(F.getMetadata(LLVMContext::MD_annotation)); + + if (!Existing || Existing->getNumOperands() != 2) + return; + + auto *MetadataName = "unsafe-stack-size"; + if (auto &N = Existing->getOperand(0)) { + if (cast<MDString>(N.get())->getString() == MetadataName) { + if (auto &Op = Existing->getOperand(1)) { + auto Val = mdconst::extract<ConstantInt>(Op)->getZExtValue(); + FrameInfo.setUnsafeStackSize(Val); + } + } + } +} + // Pin the vtable to this file. void MachineFunction::Delegate::anchor() {} @@ -175,6 +196,8 @@ void MachineFunction::init() { /*ForcedRealign=*/CanRealignSP && F.hasFnAttribute(Attribute::StackAlignment)); + setUnsafeStackSize(F, *FrameInfo); + if (F.hasFnAttribute(Attribute::StackAlignment)) FrameInfo->ensureMaxAlignment(*F.getFnStackAlign()); |