-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV][Zicfilp] Enable Zicfilp CFI compiler behaviors by looking at module flags #152121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
614f475
1f761cd
968e250
8f601dd
876c7ca
32ee08d
fc0bfdf
c8a374d
3b92223
cb9940d
f9f6bba
ef32dbc
20db445
c583a62
303f8a7
314fef8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,14 @@ | |
| #include "llvm/CodeGen/MachineFunctionPass.h" | ||
| #include "llvm/CodeGen/MachineInstrBuilder.h" | ||
| #include "llvm/CodeGen/MachineModuleInfo.h" | ||
| #include "llvm/IR/Module.h" | ||
| #include "llvm/Support/RISCVISAUtils.h" | ||
|
|
||
| #define DEBUG_TYPE "riscv-indrect-branch-tracking" | ||
| #define PASS_NAME "RISC-V Indirect Branch Tracking" | ||
|
|
||
| using namespace llvm; | ||
| using namespace llvm::RISCVISAUtils; | ||
|
|
||
| cl::opt<uint32_t> PreferredLandingPadLabel( | ||
| "riscv-landing-pad-label", cl::ReallyHidden, | ||
|
|
@@ -64,9 +67,25 @@ static void emitLpad(MachineBasicBlock &MBB, const RISCVInstrInfo *TII, | |
| bool RISCVIndirectBranchTracking::runOnMachineFunction(MachineFunction &MF) { | ||
| const auto &Subtarget = MF.getSubtarget<RISCVSubtarget>(); | ||
| const RISCVInstrInfo *TII = Subtarget.getInstrInfo(); | ||
| if (!Subtarget.hasStdExtZicfilp()) | ||
|
|
||
| const Module *const M = MF.getFunction().getParent(); | ||
| if (!M) | ||
| return false; | ||
| if (const Metadata *const Flag = M->getModuleFlag("cf-protection-branch"); | ||
| !Flag || mdconst::extract<ConstantInt>(Flag)->isZero()) | ||
| return false; | ||
|
|
||
| StringRef CFBranchLabelScheme; | ||
| if (const Metadata *const MD = M->getModuleFlag("cf-branch-label-scheme")) | ||
| CFBranchLabelScheme = cast<MDString>(MD)->getString(); | ||
| else | ||
| report_fatal_error("missing cf-branch-label-scheme module flag"); | ||
|
||
|
|
||
| const ZicfilpLabelSchemeKind Scheme = | ||
| getZicfilpLabelScheme(CFBranchLabelScheme); | ||
| if (Scheme != ZicfilpLabelSchemeKind::Unlabeled) | ||
| report_fatal_error("unsupported cf-branch-label-scheme module flag"); | ||
mylai-mtk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| uint32_t FixedLabel = 0; | ||
| if (PreferredLandingPadLabel.getNumOccurrences() > 0) { | ||
| if (!isUInt<20>(PreferredLandingPadLabel)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.