aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBasicBlock.cpp
diff options
context:
space:
mode:
authorArlo Siemsen <arsiem@microsoft.com>2021-02-15 09:23:40 +0800
committerWang, Pengfei <pengfei.wang@intel.com>2021-02-15 14:27:12 +0800
commit080866470d3e32f2e5e0e4842b68c44777d189bb (patch)
tree45ac8f53377d977e67c39730a40689de20697329 /llvm/lib/CodeGen/MachineBasicBlock.cpp
parente764e9e32c20914948787cc28996ecaab257628d (diff)
downloadllvm-080866470d3e32f2e5e0e4842b68c44777d189bb.zip
llvm-080866470d3e32f2e5e0e4842b68c44777d189bb.tar.gz
llvm-080866470d3e32f2e5e0e4842b68c44777d189bb.tar.bz2
Add ehcont section support
In the future Windows will enable Control-flow Enforcement Technology (CET aka shadow stacks). To protect the path where the context is updated during exception handling, the binary is required to enumerate valid unwind entrypoints in a dedicated section which is validated when the context is being set during exception handling. This change allows llvm to generate the section that contains the appropriate symbol references in the form expected by the msvc linker. This feature is enabled through a new module flag, ehcontguard, which was modelled on the cfguard flag. The change includes a test that when the module flag is enabled the section is correctly generated. The set of exception continuation information includes returns from exceptional control flow (catchret in llvm). In order to collect catchret we: 1) Includes an additional flag on machine basic blocks to indicate that the given block is the target of a catchret operation, 2) Introduces a new machine function pass to insert and collect symbols at the start of each block, and 3) Combines these targets with the other EHCont targets that were already being collected. Change originally authored by Daniel Frampton <dframpto@microsoft.com> For more details, see MSVC documentation for `/guard:ehcont` https://docs.microsoft.com/en-us/cpp/build/reference/guard-enable-eh-continuation-metadata Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D94835
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBasicBlock.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index b4187af..eafc826 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -87,6 +87,17 @@ MCSymbol *MachineBasicBlock::getSymbol() const {
return CachedMCSymbol;
}
+MCSymbol *MachineBasicBlock::getEHCatchretSymbol() const {
+ if (!CachedEHCatchretMCSymbol) {
+ const MachineFunction *MF = getParent();
+ SmallString<128> SymbolName;
+ raw_svector_ostream(SymbolName)
+ << "$ehgcr_" << MF->getFunctionNumber() << '_' << getNumber();
+ CachedEHCatchretMCSymbol = MF->getContext().getOrCreateSymbol(SymbolName);
+ }
+ return CachedEHCatchretMCSymbol;
+}
+
MCSymbol *MachineBasicBlock::getEndSymbol() const {
if (!CachedEndMCSymbol) {
const MachineFunction *MF = getParent();