mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-13 14:46:53 +00:00
63dea2c952
This commit adds a new pass that can inject checks before indirect calls to make sure that these calls target known locations. It supports three types of checks and, at compile time, it can take the name of a custom function to call when an indirect call check fails. The default failure function ignores the error and continues. This pass incidentally moves the function JumpInstrTables::transformType from private to public and makes it static (with a new argument that specifies the table type to use); this is so that the CFI code can transform function types at call sites to determine which jump-instruction table to use for the check at that site. Also, this removes support for jumptables in ARM, pending further performance analysis and discussion. Review: http://reviews.llvm.org/D4167 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221708 91177308-0d34-0410-b5e6-96231b3b80d8
56 lines
1.9 KiB
C++
56 lines
1.9 KiB
C++
//===-- JumpInstrTableInfo.cpp: Info for Jump-Instruction Tables ----------===//
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// \brief Information about jump-instruction tables that have been created by
|
|
/// JumpInstrTables pass.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#define DEBUG_TYPE "jiti"
|
|
|
|
#include "llvm/Analysis/JumpInstrTableInfo.h"
|
|
#include "llvm/Analysis/Passes.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Type.h"
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
using namespace llvm;
|
|
|
|
INITIALIZE_PASS(JumpInstrTableInfo, "jump-instr-table-info",
|
|
"Jump-Instruction Table Info", true, true)
|
|
char JumpInstrTableInfo::ID = 0;
|
|
|
|
ImmutablePass *llvm::createJumpInstrTableInfoPass() {
|
|
return new JumpInstrTableInfo();
|
|
}
|
|
|
|
ModulePass *llvm::createJumpInstrTableInfoPass(unsigned Bound) {
|
|
// This cast is always safe, since Bound is always in a subset of uint64_t.
|
|
uint64_t B = static_cast<uint64_t>(Bound);
|
|
return new JumpInstrTableInfo(B);
|
|
}
|
|
|
|
JumpInstrTableInfo::JumpInstrTableInfo(uint64_t ByteAlign)
|
|
: ImmutablePass(ID), Tables(), ByteAlignment(ByteAlign) {
|
|
if (!llvm::isPowerOf2_64(ByteAlign)) {
|
|
// Note that we don't explicitly handle overflow here, since we handle the 0
|
|
// case explicitly when a caller actually tries to create jumptable entries,
|
|
// and this is the return value on overflow.
|
|
ByteAlignment = llvm::NextPowerOf2(ByteAlign);
|
|
}
|
|
|
|
initializeJumpInstrTableInfoPass(*PassRegistry::getPassRegistry());
|
|
}
|
|
|
|
JumpInstrTableInfo::~JumpInstrTableInfo() {}
|
|
|
|
void JumpInstrTableInfo::insertEntry(FunctionType *TableFunTy, Function *Target,
|
|
Function *Jump) {
|
|
Tables[TableFunTy].push_back(JumpPair(Target, Jump));
|
|
}
|