mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Revert "[CFGuard] Add address-taken IAT tables and delay-load support"
This reverts commit ef4e971e5e18ae796466623df8f26265ba6bdfb5.
This commit is contained in:
parent
65ea3c84f4
commit
920d09ef67
@ -215,7 +215,6 @@ protected:
|
||||
MCSection *XDataSection = nullptr;
|
||||
MCSection *SXDataSection = nullptr;
|
||||
MCSection *GFIDsSection = nullptr;
|
||||
MCSection *GIATsSection = nullptr;
|
||||
MCSection *GLJMPSection = nullptr;
|
||||
|
||||
// XCOFF specific sections
|
||||
@ -399,7 +398,6 @@ public:
|
||||
MCSection *getXDataSection() const { return XDataSection; }
|
||||
MCSection *getSXDataSection() const { return SXDataSection; }
|
||||
MCSection *getGFIDsSection() const { return GFIDsSection; }
|
||||
MCSection *getGIATsSection() const { return GIATsSection; }
|
||||
MCSection *getGLJMPSection() const { return GLJMPSection; }
|
||||
|
||||
// XCOFF specific sections
|
||||
|
@ -7,7 +7,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains support for writing the metadata for Windows Control Flow
|
||||
// Guard, including address-taken functions and valid longjmp targets.
|
||||
// Guard, including address-taken functions, and valid longjmp targets.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@ -17,8 +17,8 @@
|
||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||
#include "llvm/CodeGen/MachineOperand.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCObjectFileInfo.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
@ -78,49 +78,20 @@ static bool isPossibleIndirectCallTarget(const Function *F) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns true if this function should be added to the Guard Address Taken IAT
|
||||
/// Entry Table (GIATs) instead of the Guard Function ID Table (GFIDs).
|
||||
static bool isIATAddressTaken(const Function *F) {
|
||||
if (F->hasDLLImportStorageClass()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WinCFGuard::endModule() {
|
||||
const Module *M = Asm->MMI->getModule();
|
||||
std::vector<const Function *> GFIDsEntries;
|
||||
std::vector<const Function *> GIATsEntries;
|
||||
for (const Function &F : *M) {
|
||||
if (isPossibleIndirectCallTarget(&F)) {
|
||||
if (isIATAddressTaken(&F)) {
|
||||
// If the possible call target is reached via the IAT, add it to the
|
||||
// GIATs table instead of the GFIDs table.
|
||||
GIATsEntries.push_back(&F);
|
||||
} else {
|
||||
// Otherwise add it to the GFIDs table.
|
||||
GFIDsEntries.push_back(&F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GFIDsEntries.empty() && GIATsEntries.empty() && LongjmpTargets.empty())
|
||||
std::vector<const Function *> Functions;
|
||||
for (const Function &F : *M)
|
||||
if (isPossibleIndirectCallTarget(&F))
|
||||
Functions.push_back(&F);
|
||||
if (Functions.empty() && LongjmpTargets.empty())
|
||||
return;
|
||||
|
||||
// Emit the symbol index of each GFIDs entry to form the GFIDs table.
|
||||
auto &OS = *Asm->OutStreamer;
|
||||
OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGFIDsSection());
|
||||
for (const Function *F : GFIDsEntries)
|
||||
for (const Function *F : Functions)
|
||||
OS.EmitCOFFSymbolIndex(Asm->getSymbol(F));
|
||||
|
||||
// Emit the symbol index of each GIATs entry to form the GIATs table.
|
||||
OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGIATsSection());
|
||||
for (const Function *F : GIATsEntries) {
|
||||
OS.EmitCOFFSymbolIndex(Asm->OutContext.getOrCreateSymbol(
|
||||
Twine("__imp_") + Asm->getSymbol(F)->getName()));
|
||||
}
|
||||
|
||||
// Emit the symbol index of each longjmp target to form the GLJMP table.
|
||||
// Emit the symbol index of each longjmp target.
|
||||
OS.SwitchSection(Asm->OutContext.getObjectFileInfo()->getGLJMPSection());
|
||||
for (const MCSymbol *S : LongjmpTargets) {
|
||||
OS.EmitCOFFSymbolIndex(S);
|
||||
|
@ -752,11 +752,6 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
|
||||
COFF::IMAGE_SCN_MEM_READ,
|
||||
SectionKind::getMetadata());
|
||||
|
||||
GIATsSection = Ctx->getCOFFSection(".giats$y",
|
||||
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
|
||||
COFF::IMAGE_SCN_MEM_READ,
|
||||
SectionKind::getMetadata());
|
||||
|
||||
GLJMPSection = Ctx->getCOFFSection(".gljmp$y",
|
||||
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
|
||||
COFF::IMAGE_SCN_MEM_READ,
|
||||
|
@ -1,22 +0,0 @@
|
||||
; RUN: llc < %s -mtriple=x86_64-pc-windows-msvc | FileCheck %s
|
||||
; Control Flow Guard is currently only available on Windows
|
||||
|
||||
declare dllimport i32 @target_func()
|
||||
|
||||
; Test address-taken functions from imported DLLs are added to the
|
||||
; Guard Address-Taken IAT Entry table (.giats).
|
||||
define i32 @func_cf_giats() {
|
||||
entry:
|
||||
%func_ptr = alloca i32 ()*, align 8
|
||||
store i32 ()* @target_func, i32 ()** %func_ptr, align 8
|
||||
%0 = load i32 ()*, i32 ()** %func_ptr, align 8
|
||||
%1 = call i32 %0()
|
||||
ret i32 %1
|
||||
}
|
||||
|
||||
!llvm.module.flags = !{!0}
|
||||
!0 = !{i32 2, !"cfguard", i32 2}
|
||||
|
||||
; CHECK-LABEL: .section .giats$y,"dr"
|
||||
; CHECK-NEXT: .symidx __imp_target_func
|
||||
; CHECK-NOT: .symidx
|
@ -67,8 +67,6 @@ struct LoadConfigTables {
|
||||
uint32_t GuardFlags = 0;
|
||||
uint64_t GuardFidTableVA = 0;
|
||||
uint64_t GuardFidTableCount = 0;
|
||||
uint64_t GuardIatTableVA = 0;
|
||||
uint64_t GuardIatTableCount = 0;
|
||||
uint64_t GuardLJmpTableVA = 0;
|
||||
uint64_t GuardLJmpTableCount = 0;
|
||||
};
|
||||
@ -806,11 +804,6 @@ void COFFDumper::printCOFFLoadConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
if (Tables.GuardIatTableVA) {
|
||||
ListScope LS(W, "GuardIatTable");
|
||||
printRVATable(Tables.GuardIatTableVA, Tables.GuardIatTableCount, 4);
|
||||
}
|
||||
|
||||
if (Tables.GuardLJmpTableVA) {
|
||||
ListScope LS(W, "GuardLJmpTable");
|
||||
printRVATable(Tables.GuardLJmpTableVA, Tables.GuardLJmpTableCount, 4);
|
||||
@ -895,9 +888,6 @@ void COFFDumper::printCOFFLoadConfig(const T *Conf, LoadConfigTables &Tables) {
|
||||
Conf->GuardRFVerifyStackPointerFunctionPointer);
|
||||
W.printHex("HotPatchTableOffset", Conf->HotPatchTableOffset);
|
||||
|
||||
Tables.GuardIatTableVA = Conf->GuardAddressTakenIatEntryTable;
|
||||
Tables.GuardIatTableCount = Conf->GuardAddressTakenIatEntryCount;
|
||||
|
||||
Tables.GuardLJmpTableVA = Conf->GuardLongJumpTargetTable;
|
||||
Tables.GuardLJmpTableCount = Conf->GuardLongJumpTargetCount;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user