aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp
diff options
context:
space:
mode:
authorAdrian McCarthy <amccarth@google.com>2018-01-08 16:33:42 +0000
committerAdrian McCarthy <amccarth@google.com>2018-01-08 16:33:42 +0000
commitcf6e6c82c1ca243c3be191c59409d26f76ec8d38 (patch)
tree5c0a022d0d1b2d1c574af89040a379b6227deb0e /llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp
parentf02ad15ff1dd84c73958c002966e3b61f8539f18 (diff)
downloadllvm-cf6e6c82c1ca243c3be191c59409d26f76ec8d38.zip
llvm-cf6e6c82c1ca243c3be191c59409d26f76ec8d38.tar.gz
llvm-cf6e6c82c1ca243c3be191c59409d26f76ec8d38.tar.bz2
Emit Function IDs table for Control Flow Guard
Adds option /guard:cf to clang-cl and -cfguard to cc1 to emit function IDs of functions that have their address taken into a section named .gfids$y for compatibility with Microsoft's Control Flow Guard feature. Differential Revision: https://reviews.llvm.org/D40531 llvm-svn: 322005
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp b/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp
new file mode 100644
index 0000000..18d37ca
--- /dev/null
+++ b/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp
@@ -0,0 +1,45 @@
+//===-- CodeGen/AsmPrinter/WinCFGuard.cpp - Control Flow Guard Impl ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains support for writing Win64 exception info into asm files.
+//
+//===----------------------------------------------------------------------===//
+
+#include "WinCFGuard.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCObjectFileInfo.h"
+#include "llvm/MC/MCStreamer.h"
+
+#include <vector>
+
+using namespace llvm;
+
+WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {}
+
+WinCFGuard::~WinCFGuard() {}
+
+void WinCFGuard::endModule() {
+ const Module *M = Asm->MMI->getModule();
+ std::vector<const Function *> Functions;
+ for (const Function &F : *M)
+ if (F.hasAddressTaken())
+ Functions.push_back(&F);
+ if (Functions.empty())
+ return;
+ auto &OS = *Asm->OutStreamer;
+ OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection());
+ for (const Function *F : Functions)
+ OS.EmitCOFFSymbolIndex(Asm->getSymbol(F));
+}