blob: 18d37caf57ee494a42d7bb262134fc91e543758f [file] [log] [blame]
Adrian McCarthydb2736d2018-01-09 23:49:30 +00001//===-- 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
27using namespace llvm;
28
29WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {}
30
31WinCFGuard::~WinCFGuard() {}
32
33void 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}