• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- CodeGen/AsmPrinter/WinCFGuard.cpp - Control Flow Guard Impl ------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for writing Win64 exception info into asm files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "WinCFGuard.h"
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineModuleInfo.h"
18 #include "llvm/CodeGen/MachineOperand.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/Metadata.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCObjectFileInfo.h"
23 #include "llvm/MC/MCStreamer.h"
24 
25 #include <vector>
26 
27 using namespace llvm;
28 
WinCFGuard(AsmPrinter * A)29 WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {}
30 
~WinCFGuard()31 WinCFGuard::~WinCFGuard() {}
32 
endModule()33 void WinCFGuard::endModule() {
34   const Module *M = Asm->MMI->getModule();
35   std::vector<const Function *> Functions;
36   for (const Function &F : *M)
37     if (F.hasAddressTaken())
38       Functions.push_back(&F);
39   if (Functions.empty())
40     return;
41   auto &OS = *Asm->OutStreamer;
42   OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection());
43   for (const Function *F : Functions)
44     OS.EmitCOFFSymbolIndex(Asm->getSymbol(F));
45 }
46