Line data Source code
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 :
29 1 : WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {}
30 :
31 1 : WinCFGuard::~WinCFGuard() {}
32 :
33 1 : void WinCFGuard::endModule() {
34 1 : const Module *M = Asm->MMI->getModule();
35 : std::vector<const Function *> Functions;
36 10 : for (const Function &F : *M)
37 9 : if (F.hasAddressTaken())
38 4 : Functions.push_back(&F);
39 1 : if (Functions.empty())
40 : return;
41 1 : auto &OS = *Asm->OutStreamer;
42 1 : OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection());
43 5 : for (const Function *F : Functions)
44 4 : OS.EmitCOFFSymbolIndex(Asm->getSymbol(F));
45 : }
|