Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions passes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
add_subdirectory(Utils Utils)

# EDDI
# EDDI
add_library(EDDI SHARED
DuplicateGlobals.cpp
EDDI.cpp
FuncRetToRef.cpp
Utils/Utils.cpp
DuplicateGlobals.cpp
EDDI.cpp
FuncRetToRef.cpp
Utils/Utils.cpp
)
target_compile_definitions(EDDI PRIVATE SELECTIVE_CHECKING=0 CHECK_AT_STORES CHECK_AT_CALLS CHECK_AT_BRANCH)

# FDSC
add_library(FDSC SHARED
DuplicateGlobals.cpp
EDDI.cpp
FuncRetToRef.cpp
Utils/Utils.cpp
DuplicateGlobals.cpp
EDDI.cpp
FuncRetToRef.cpp
Utils/Utils.cpp
)
target_compile_definitions(FDSC PRIVATE SELECTIVE_CHECKING=1 CHECK_AT_STORES CHECK_AT_CALLS CHECK_AT_BRANCH)

# sEDDI
add_library(SEDDI SHARED
DuplicateGlobals.cpp
EDDI.cpp
FuncRetToRef.cpp
Utils/Utils.cpp
DuplicateGlobals.cpp
EDDI.cpp
FuncRetToRef.cpp
Utils/Utils.cpp
)
target_compile_definitions(SEDDI PRIVATE SELECTIVE_CHECKING=0 CHECK_AT_CALLS CHECK_AT_BRANCH)


# CFCSS
add_library(CFCSS SHARED
CFCSS.cpp
Utils/Utils.cpp
CFCSS.cpp
Utils/Utils.cpp
)

# RASM
add_library(RASM SHARED
RASM.cpp
Utils/Utils.cpp
RASM.cpp
Utils/Utils.cpp
)
target_compile_definitions(RASM PRIVATE INTRA_FUNCTION_CFC=0)
target_compile_definitions(RASM PRIVATE INTER_FUNCTION_CFC=0)


# inter-RASM
add_library(INTER_RASM SHARED
RASM.cpp
Utils/Utils.cpp
RASM.cpp
Utils/Utils.cpp
)
target_compile_definitions(INTER_RASM PRIVATE INTRA_FUNCTION_CFC=1)
target_compile_definitions(INTER_RASM PRIVATE INTER_FUNCTION_CFC=1)

# RACFED
add_library(RACFED SHARED
RACFED.cpp
Utils/Utils.cpp
RACFED.cpp
Utils/Utils.cpp
)

add_library(PROFILER SHARED
Profiling/ASPISCheckProfiler.cpp
Utils/Utils.cpp
)
Profiling/ASPISCheckProfiler.cpp
Utils/Utils.cpp
)
64 changes: 40 additions & 24 deletions passes/RACFED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,21 +491,37 @@ Instruction *RACFED::checkOnReturn(BasicBlock &BB,
}

PreservedAnalyses RACFED::run(Module &Md, ModuleAnalysisManager &AM) {
createFtFuncs(Md);
getFuncAnnotations(Md, FuncAnnotations);
LinkageMap linkageMap = mapFunctionLinkageNames((Md));

auto *I64 = llvm::Type::getInt64Ty(Md.getContext());

// Runtime signature defined as a global variable
GlobalVariable *RuntimeSig = new GlobalVariable(
Md, I64,
/*isConstant=*/false,
GlobalValue::ExternalLinkage,
ConstantInt::get(I64, 0),
"signature"
);
GlobalVariable *RuntimeSig;

{
bool initialized_runtimesig = false;

for (GlobalVariable &GV : Md.globals()) {
if (!isa<Function>(GV) && FuncAnnotations.find(&GV) != FuncAnnotations.end()) {
if ((FuncAnnotations.find(&GV))->second.starts_with("runtime_sig")) {
RuntimeSig = &GV;
initialized_runtimesig = true;
}
}
}

if (!initialized_runtimesig)
RuntimeSig = new GlobalVariable(
Md, I64,
/*isConstant=*/false,
GlobalValue::ExternalLinkage,
ConstantInt::get(I64, 0),
"runtime_sig"
);
}

createFtFuncs(Md);
getFuncAnnotations(Md, FuncAnnotations);
LinkageMap linkageMap = mapFunctionLinkageNames((Md));

for (Function &Fn: Md) {
if (!shouldCompile(Fn, FuncAnnotations)) continue;

Expand All @@ -517,8 +533,8 @@ PreservedAnalyses RACFED::run(Module &Md, ModuleAnalysisManager &AM) {
DebugLoc debugLoc;
for (auto &I : Fn.front()) {
if (I.getDebugLoc()) {
debugLoc = I.getDebugLoc();
break;
debugLoc = I.getDebugLoc();
break;
}
}

Expand All @@ -527,7 +543,7 @@ PreservedAnalyses RACFED::run(Module &Md, ModuleAnalysisManager &AM) {
#endif

assert(!getLinkageName(linkageMap,"SigMismatch_Handler").empty()
&& "Function SigMismatch_Handler is missing!");
&& "Function SigMismatch_Handler is missing!");

// Create error basic block
BasicBlock *ErrBB = BasicBlock::Create(Fn.getContext(), "ErrBB", &Fn);
Expand All @@ -552,14 +568,14 @@ PreservedAnalyses RACFED::run(Module &Md, ModuleAnalysisManager &AM) {
// Backup of compile time sign when entering a function
if ( BB.isEntryBlock() ) {
IRBuilder<> InstrIR(&*BB.getFirstInsertionPt());
if ( Fn.getName() != "main" ) {
runtime_sign_bkup =
InstrIR.CreateLoad(I64, RuntimeSig, "backup_run_sig");
}
// Set runtime signature to compile time signature
// of the function's entry block.
InstrIR.CreateStore(llvm::ConstantInt::get(I64, compileTimeSig[&BB]),
RuntimeSig);
if ( Fn.getName() != "main" ) {
runtime_sign_bkup =
InstrIR.CreateLoad(I64, RuntimeSig, "backup_run_sig");
}
// Set runtime signature to compile time signature
// of the function's entry block.
InstrIR.CreateStore(llvm::ConstantInt::get(I64, compileTimeSig[&BB]),
RuntimeSig);
}

checkJumpSignature(BB, RuntimeSig, I64, *ErrBB);
Expand All @@ -568,8 +584,8 @@ PreservedAnalyses RACFED::run(Module &Md, ModuleAnalysisManager &AM) {

// Restore signature on return
if ( ret_inst != nullptr && Fn.getName() != "main") {
IRBuilder<> RetInstIR(ret_inst);
RetInstIR.CreateStore(runtime_sign_bkup, RuntimeSig);
IRBuilder<> RetInstIR(ret_inst);
RetInstIR.CreateStore(runtime_sign_bkup, RuntimeSig);
}
}
}
Expand Down
66 changes: 45 additions & 21 deletions passes/RASM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
#include "Utils/Utils.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/PassPlugin.h"
#include <list>
#include <map>
#include <iostream>
#include <fstream>

using namespace llvm;

#define DEBUG_TYPE "rasm-verify"
Expand All @@ -30,7 +28,7 @@ using namespace llvm;
* - 0: Disabled
* - 1: Enabled
*/
//#define INTRA_FUNCTION_CFC 1
// #define INTER_FUNCTION_CFC 1
#define INIT_SIGNATURE -0xDEAD // The same value has to be used as initializer for the signatures in the code

void RASM::initializeBlocksSignatures(Module &Md, std::map<BasicBlock*, int> &RandomNumberBBs, std::map<BasicBlock*, int> &SubRanPrevVals) {
Expand All @@ -49,7 +47,7 @@ void RASM::initializeBlocksSignatures(Module &Md, std::map<BasicBlock*, int> &Ra
return;
}

#if (INTRA_FUNCTION_CFC == 1)
#if (INTER_FUNCTION_CFC == 1)

std::map<BasicBlock*, CallBase *> CallBBs;
std::map<Function*, BasicBlock*> FuncEntryBlocks;
Expand Down Expand Up @@ -193,7 +191,7 @@ void RASM::createCFGVerificationBB ( BasicBlock &BB,
* C) all the other cases
*/

#if (INTRA_FUNCTION_CFC == 1)
#if (INTER_FUNCTION_CFC == 1)
// Case A, we need to update the RetSig
CallBase *CallIn = isCallBB(BB);
if (CallIn != nullptr && (*CallIn).getCalledFunction() != nullptr && shouldCompile(*(*CallIn).getCalledFunction(), FuncAnnotations)) {
Expand Down Expand Up @@ -341,26 +339,52 @@ PreservedAnalyses RASM::run(Module &Md, ModuleAnalysisManager &AM) {

auto *IntType = llvm::Type::getInt32Ty(Md.getContext());

#if (INTRA_FUNCTION_CFC == 1)
#if (INTER_FUNCTION_CFC == 1)
splitBBsAtCalls(Md);
GlobalVariable *RuntimeSig;
GlobalVariable *RetSig;
// find the global variables required for the runtime signatures
for (GlobalVariable &GV : Md.globals()) {
if (!isa<Function>(GV) && FuncAnnotations.find(&GV) != FuncAnnotations.end()) {
if ((FuncAnnotations.find(&GV))->second.starts_with("runtime_sig")) {
RuntimeSig = &GV;
}
else if ((FuncAnnotations.find(&GV))->second.starts_with("run_adj_sig")) {
RetSig = &GV;
GlobalVariable *RuntimeSig ;
GlobalVariable *RetSig ;

{
bool initialized_runtimesig = false;
bool initialized_retsig = false;

// find the global variables required for the runtime signatures
for (GlobalVariable &GV : Md.globals()) {
if (!isa<Function>(GV) && FuncAnnotations.find(&GV) != FuncAnnotations.end()) {
if ((FuncAnnotations.find(&GV))->second.starts_with("runtime_sig")) {
RuntimeSig = &GV;
initialized_runtimesig = true;
} else if ((FuncAnnotations.find(&GV))->second.starts_with("run_adj_sig")) {
RetSig = &GV;
initialized_retsig = true;
}
}
}
}

if (!initialized_runtimesig) {
RuntimeSig = new GlobalVariable(
Md, IntType, /*isConstant=*/false,
GlobalVariable::ExternalLinkage,
ConstantInt::get(IntType, INIT_SIGNATURE),
"runtime_sig"
);
}

if (!initialized_retsig) {
RetSig = new GlobalVariable(
Md, IntType, /*isConstant=*/false,
GlobalVariable::ExternalLinkage,
ConstantInt::get(IntType, INIT_SIGNATURE),
"run_adj_sig"
);
}
}

#endif

initializeBlocksSignatures(Md, RandomNumberBBs, SubRanPrevVals);

#if (INTRA_FUNCTION_CFC == 1)
#if (INTER_FUNCTION_CFC == 1)
initializeEntryBlocksMap(Md);
#endif

Expand All @@ -377,14 +401,14 @@ PreservedAnalyses RASM::run(Module &Md, ModuleAnalysisManager &AM) {
CompiledFuncs.insert(&Fn);
#endif
int currSig = RandomNumberBBs.find(&Fn.front())->second;
#if (INTRA_FUNCTION_CFC == 0)
#if (INTER_FUNCTION_CFC == 0)
IRBuilder<> B(&*(Fn.front().getFirstInsertionPt()));
// initialize the runtime signature for the first basic block of the function
Value *RuntimeSig = B.CreateAlloca(IntType);
Value *RetSig = B.CreateAlloca(IntType);
B.CreateStore(llvm::ConstantInt::get(IntType, currSig), RuntimeSig, true);
B.CreateStore(llvm::ConstantInt::get(IntType, RandomNumberBBs.size() + currSig), RetSig, true);
#elif (INTRA_FUNCTION_CFC == 1)
#elif (INTER_FUNCTION_CFC == 1)
int subCurrSig = SubRanPrevVals.find(&Fn.front())->second;
// add instructions for initializing the runtime signatures in case they have not been initialized

Expand Down
Loading