LLVM  9.0.0svn
Go to the documentation of this file.
1 //===-- CodeGen/AsmPrinter/WinCFGuard.cpp - Control Flow Guard Impl ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for writing Win64 exception info into asm files.
10 //
11 //===----------------------------------------------------------------------===//
13 #include "WinCFGuard.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCStreamer.h"
24 #include <vector>
26 using namespace llvm;
33  const Module *M = Asm->MMI->getModule();
34  std::vector<const Function *> Functions;
35  for (const Function &F : *M)
36  if (F.hasAddressTaken())
37  Functions.push_back(&F);
38  if (Functions.empty())
39  return;
40  auto &OS = *Asm->OutStreamer;
41  OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection());
42  for (const Function *F : Functions)
43  OS.EmitCOFFSymbolIndex(Asm->getSymbol(F));
44 }
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:64
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
Collects and handles AsmPrinter objects required to build debug or EH information.
This file contains the declarations for metadata subclasses.
void endModule() override
Emit the Control Flow Guard function ID table.
Definition: WinCFGuard.cpp:32
MCSection * getGFIDsSection() const
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:99
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:78
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:296
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:430
~WinCFGuard() override
Definition: WinCFGuard.cpp:30
WinCFGuard(AsmPrinter *A)
Definition: WinCFGuard.cpp:28
const Module * getModule() const