Skip to content

Commit

Permalink
Merge branch 'cf_branch' into unreachable_code
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Nov 29, 2020
2 parents 761424d + 0925640 commit 0df87ed
Show file tree
Hide file tree
Showing 10 changed files with 820 additions and 68 deletions.
20 changes: 18 additions & 2 deletions docker/Dockerfile.perf-taint
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM mcopik/clang-dfsan:dfsan-9.0
FROM mcopik/clang-dfsan:cfsan-9.0
ENV PATH="/opt/llvm/bin:${PATH}"

USER docker

ADD . ${HOME}/perf-taint
RUN mkdir ${HOME}/build

RUN sudo apt-get update\
# Basic developer tools
&& sudo apt-get install -y --no-install-recommends\
ninja-build\
make\
cmake\
git\
# OpenMPI
Expand All @@ -19,4 +23,16 @@ RUN sudo apt-get update\
python3-pip\
&& pip3 install wheel\
&& pip3 install lit

RUN cd ${HOME}/build && cmake\
-DCMAKE_C_COMPILER=clang\
-DCMAKE_CXX_COMPILER=clang++\
-DLLVM_DIR=/opt/llvm/\
-DWITH_MPI=ON\
-DLIBCXX_PATH=/opt/llvm/\
-DWITH_REGRESSION_TESTS=ON\
-DWITH_UNIT_TESTS=On\
-DLLVM_WITH_CFSAN=On\
-DCMAKE_INSTALL_PREFIX=${HOME}/install\
../perf-taint && make

8 changes: 8 additions & 0 deletions include/perf-taint/llvm-pass/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ namespace perf_taint {
{}
};

struct LoopBranch
{
uint32_t nested_loop_idx;
llvm::Instruction * branch;
};

struct Function
{
int idx;
Expand All @@ -42,6 +48,8 @@ namespace perf_taint {
llvm::SmallVector<ImplicitCall, 10> implicit_loops;
typedef std::vector< std::vector<int> > vec_t;

llvm::SmallVector<LoopBranch, 5> loop_cf_branches;

Function(int _idx, llvm::StringRef _name, bool _overriden = false):
idx(_idx),
name(_name),
Expand Down
21 changes: 21 additions & 0 deletions include/perf-taint/llvm-pass/PerfTaintPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ namespace perf_taint {
llvm::GlobalVariable * glob_loops_sizes_offsets;
llvm::GlobalVariable * glob_loops_number;

// branches
llvm::GlobalVariable * glob_branches_offsets;
llvm::GlobalVariable * glob_branches_counts;
llvm::GlobalVariable * glob_branches_data;
static constexpr const char * glob_branches_offsets_name
= "__perf_taint_loop_branches_offsets";
static constexpr const char * glob_branches_counts_name
= "__perf_taint_loop_branches_counts";
static constexpr const char * glob_branches_data_name
= "__perf_taint_loop_branches_data";
static constexpr const char * glob_branches_enabled_name
= "__perf_taint_loop_branches_enabled";

static constexpr const char * glob_retval_tls_name
= "__dfsan_retval_tls";
static constexpr const char * glob_labels_name
Expand Down Expand Up @@ -217,6 +230,9 @@ namespace perf_taint {
// void __dfsw_EXTRAP_WRITE_PARAMETER(int8_t *, size_t, int32_t)
llvm::Function * write_parameter_function;

// void __dfsw_perf_taint_branch(int16, int32, int32, int32)
llvm::Function * taint_branch_function;

Instrumenter(llvm::Module & _m):
m(_m),
builder(m.getContext()),
Expand Down Expand Up @@ -292,6 +308,9 @@ namespace perf_taint {
);
llvm::Function * getAtExit();
uint64_t size_of(llvm::Value * val);

void instrumentLoopBranch(llvm::Instruction * branch, int32_t function_idx,
int32_t nested_loop_idx, int32_t branch_idx);
};

struct LabelAnnotator : public llvm::InstVisitor<LabelAnnotator, bool>
Expand Down Expand Up @@ -377,6 +396,8 @@ namespace perf_taint {

std::set<llvm::Function*> recursive_functions;

void analyzeLoopBranches(Function & f, llvm::Loop & l, int & nested_loop_idx);

DfsanInstr():
ModulePass(ID),
m(nullptr),
Expand Down
7 changes: 7 additions & 0 deletions include/perf-taint/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ typedef struct _nested_call_vec {
nested_call * data;
} nested_call_vec;

extern bool __perf_taint_loop_branches_enabled;

extern int32_t __EXTRAP_INSTRUMENTATION_RESULTS[];
extern const char * __EXTRAP_INSTRUMENTATION_FUNCS_NAMES[];
extern const char * __EXTRAP_INSTRUMENTATION_FUNCS_MANGLED_NAMES[];
Expand Down Expand Up @@ -163,5 +165,10 @@ EXTERN dependencies * __dfsw_EXTRAP_DEPS_FUNC(int func_idx);
EXTERN dependencies * __dfsw_EXTRAP_GET_DEPS(int32_t loop_idx, int32_t depth,
int32_t function_idx);

extern int32_t __perf_taint_loop_branches_offsets[];
extern int32_t __perf_taint_loop_branches_counts[];
extern int16_t __perf_taint_loop_branches_data[];


#endif

Loading

0 comments on commit 0df87ed

Please sign in to comment.