mirror of
https://github.com/topjohnwu/CPI.git
synced 2025-02-17 02:09:40 +00:00
Update building method
This commit is contained in:
parent
129e29b9d2
commit
199b9a8e75
@ -13,10 +13,4 @@ if (APPLE)
|
||||
list (APPEND CMAKE_CXX_FLAGS "-undefined dynamic_lookup")
|
||||
endif(APPLE)
|
||||
|
||||
add_library(
|
||||
safe_rt
|
||||
STATIC
|
||||
safe_rt/rt.c
|
||||
)
|
||||
|
||||
add_subdirectory(pass)
|
||||
|
@ -34,10 +34,10 @@ struct CPI : public ModulePass {
|
||||
nop = BinaryOperator::Create(Instruction::Add, zero, zero, "NOP",
|
||||
M.getFunctionList().front().getEntryBlock().getFirstNonPHIOrDbg());
|
||||
|
||||
// Add global variables in libsafe_rt
|
||||
// Add global variables rt.c
|
||||
smSp = new GlobalVariable(M, intT, false, GlobalValue::ExternalLinkage, nullptr, "__sm_sp");
|
||||
|
||||
// Add function references in libsafe_rt
|
||||
// Add function references in rt.c
|
||||
smAlloca = cast<Function>(M.getOrInsertFunction("__sm_alloca", voidPPT));
|
||||
smMalloc = cast<Function>(M.getOrInsertFunction("__sm_malloc", voidPPT, voidPPT));
|
||||
smLoad = cast<Function>(M.getOrInsertFunction("__sm_load", voidPT, voidPPT, voidPPT));
|
||||
|
@ -10,6 +10,7 @@ int __sm_sp = 0;
|
||||
static void ***block_table;
|
||||
static int table_sz = 0;
|
||||
|
||||
__attribute__((always_inline))
|
||||
static inline void **sm_alloca() {
|
||||
int block_num = __sm_sp >> 4;
|
||||
if (block_num == table_sz) {
|
||||
@ -35,6 +36,7 @@ void **__sm_malloc(void **ua) {
|
||||
return sa;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void *__sm_load(void **sa, void **ua) {
|
||||
assert(*sa == *ua);
|
||||
return *sa;
|
11
tests/run.sh
11
tests/run.sh
@ -38,10 +38,15 @@ name=${src%.*}.llvm
|
||||
|
||||
# Compile test program with alloca-hoisting and mem2reg
|
||||
clang -emit-llvm -O1 -mllvm -disable-llvm-optzns -c $src -o - | opt -S -alloca-hoisting -mem2reg -o ${name}.ll || exit 1
|
||||
clang ${name}.ll -o ${name}.out
|
||||
clang -O2 ${name}.ll -o ${name}.out
|
||||
|
||||
# Run CPI pass
|
||||
opt -S -o ${name}.p.ll -load ../build/pass/LLVMCPI.${dll} $CPI_FLAG ${name}.ll || exit 1
|
||||
|
||||
# Build patched code and link to libsafe_rt
|
||||
clang ${name}.p.ll -L../build -lsafe_rt -o ${name}.p.out
|
||||
# Build patched code
|
||||
clang -O2 ${name}.p.ll ../rt.c -o ${name}.p.out
|
||||
exit
|
||||
|
||||
# Generate combined bitcode
|
||||
clang -S -emit-llvm -c ../safe_rt/rt.c -o rt.llvm.ll
|
||||
llvm-link ${name}.p.ll rt.llvm.ll | opt -S -O2 -o ${name}.o.ll
|
||||
|
Loading…
x
Reference in New Issue
Block a user