LLVM  8.0.1
WinCFGuard.cpp
Go to the documentation of this file.
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"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/Metadata.h"
21 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCStreamer.h"
24 
25 #include <vector>
26 
27 using namespace llvm;
28 
30 
32 
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 }
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:94
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:89
Collects and handles AsmPrinter objects required to build debug or EH information.
This file contains the declarations for metadata subclasses.
F(f)
void endModule() override
Emit the Control Flow Guard function ID table.
Definition: WinCFGuard.cpp:33
MCSection * getGFIDsSection() const
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:100
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:79
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:430
~WinCFGuard() override
Definition: WinCFGuard.cpp:31
WinCFGuard(AsmPrinter *A)
Definition: WinCFGuard.cpp:29
const Module * getModule() const