mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-04 14:16:09 +00:00

Adds option /guard:cf to clang-cl and -cfguard to cc1 to emit function IDs of functions that have their address taken into a section named .gfids$y for compatibility with Microsoft's Control Flow Guard feature. The original patch didn't have the lit.local.cfg file that restricts the new test to x86, thus the new test was failing on the non-x86 bots. Differential Revision: https://reviews.llvm.org/D40531 The reverts r322008, which was a revert of r322005. This reverts commit a05b89f9aca70597dc79fe97bc49b50b51f525ba. llvm-svn: 322136
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
//===-- CodeGen/AsmPrinter/WinCFGuard.cpp - Control Flow Guard Impl ------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains support for writing Win64 exception info into asm files.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "WinCFGuard.h"
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
|
#include "llvm/IR/Constants.h"
|
|
#include "llvm/IR/Metadata.h"
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include <vector>
|
|
|
|
using namespace llvm;
|
|
|
|
WinCFGuard::WinCFGuard(AsmPrinter *A) : AsmPrinterHandler(), Asm(A) {}
|
|
|
|
WinCFGuard::~WinCFGuard() {}
|
|
|
|
void WinCFGuard::endModule() {
|
|
const Module *M = Asm->MMI->getModule();
|
|
std::vector<const Function *> Functions;
|
|
for (const Function &F : *M)
|
|
if (F.hasAddressTaken())
|
|
Functions.push_back(&F);
|
|
if (Functions.empty())
|
|
return;
|
|
auto &OS = *Asm->OutStreamer;
|
|
OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection());
|
|
for (const Function *F : Functions)
|
|
OS.EmitCOFFSymbolIndex(Asm->getSymbol(F));
|
|
}
|