]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/WinCFGuard.cpp
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / CodeGen / AsmPrinter / WinCFGuard.cpp
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 //===----------------------------------------------------------------------===//
12
13 #include "WinCFGuard.h"
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/MachineModuleInfo.h"
17 #include "llvm/CodeGen/MachineOperand.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCObjectFileInfo.h"
22 #include "llvm/MC/MCStreamer.h"
23
24 #include <vector>
25
26 using namespace llvm;
27
28 WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {}
29
30 WinCFGuard::~WinCFGuard() {}
31
32 void WinCFGuard::endModule() {
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 }