diff options
author | Nick Desaulniers <ndesaulniers@google.com> | 2021-05-21 15:53:21 -0700 |
---|---|---|
committer | Nick Desaulniers <ndesaulniers@google.com> | 2021-05-21 15:53:30 -0700 |
commit | 033138ea452f5f493fb5095e5963419905ad12e1 (patch) | |
tree | cc4bb3cf5aa64b9a508d8e879f217d079a429185 /llvm/lib/IR/Module.cpp | |
parent | ab3cd2601bac99b26952c6f1015387d60800d2e2 (diff) | |
download | llvm-033138ea452f5f493fb5095e5963419905ad12e1.zip llvm-033138ea452f5f493fb5095e5963419905ad12e1.tar.gz llvm-033138ea452f5f493fb5095e5963419905ad12e1.tar.bz2 |
[IR] make stack-protector-guard-* flags into module attrs
D88631 added initial support for:
- -mstack-protector-guard=
- -mstack-protector-guard-reg=
- -mstack-protector-guard-offset=
flags, and D100919 extended these to AArch64. Unfortunately, these flags
aren't retained for LTO. Make them module attributes rather than
TargetOptions.
Link: https://github.com/ClangBuiltLinux/linux/issues/1378
Reviewed By: tejohnson
Differential Revision: https://reviews.llvm.org/D102742
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 726ac6a..d38b2d1 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -686,6 +686,41 @@ void Module::setFramePointer(FramePointerKind Kind) { addModuleFlag(ModFlagBehavior::Max, "frame-pointer", static_cast<int>(Kind)); } +StringRef Module::getStackProtectorGuard() const { + Metadata *MD = getModuleFlag("stack-protector-guard"); + if (auto *MDS = dyn_cast_or_null<MDString>(MD)) + return MDS->getString(); + return {}; +} + +void Module::setStackProtectorGuard(StringRef Kind) { + MDString *ID = MDString::get(getContext(), Kind); + addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard", ID); +} + +StringRef Module::getStackProtectorGuardReg() const { + Metadata *MD = getModuleFlag("stack-protector-guard-reg"); + if (auto *MDS = dyn_cast_or_null<MDString>(MD)) + return MDS->getString(); + return {}; +} + +void Module::setStackProtectorGuardReg(StringRef Reg) { + MDString *ID = MDString::get(getContext(), Reg); + addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-reg", ID); +} + +int Module::getStackProtectorGuardOffset() const { + Metadata *MD = getModuleFlag("stack-protector-guard-offset"); + if (auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD)) + return CI->getSExtValue(); + return INT_MAX; +} + +void Module::setStackProtectorGuardOffset(int Offset) { + addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-offset", Offset); +} + void Module::setSDKVersion(const VersionTuple &V) { SmallVector<unsigned, 3> Entries; Entries.push_back(V.getMajor()); |