Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonZhongZexin committed Jan 4, 2021
1 parent bee8680 commit c1d737a
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUILD/
build/
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.4.3)
if (DEFINED LLVM_DIR)
set(ENV{LLVM_DIR} "${LLVM_DIR}")
endif()
if (DEFINED ENV{LLVM_DIR})
# We need to match the build environment for LLVM:
# In particular, we need C++11 and the -fno-rtti flag
set(CMAKE_CXX_STANDARD 14)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++14 -O0 -fno-rtti -Wno-deprecated")
else()
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++14 -O3 -fno-rtti -Wno-deprecated")
endif()
set(CMAKE_C_FLAGS "-fPIC")

find_package(LLVM REQUIRED CONFIG)

list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})

else()
message(FATAL_ERROR "\
WARNING: The LLVM_DIR var was not set (required for an out-of-source build)!\n\
Please set this to environment variable to point to the LLVM build directory\
(e.g. on linux: export LLVM_DIR=/path/to/llvm/build/dir)")
endif()

if (EXISTS "${SVF_DIR}")
else()
set(SVF_DIR $ENV{SVF_DIR})
if(EXISTS "${SVF_DIR}")
else()
message(FATAL_ERROR "\
WARNING: The SVF_DIR var was not set (required for an out-of-source build)!\n\
Please set this to environment variable to point to the SVF_DIR directory or set this variable to cmake configuration\n
(e.g. on linux: export SVF_DIR=/path/to/SVF/dir) \n or \n \n(make the project via: cmake -DSVF_DIR=your_path_to_SVF) ")
endif()
endif()

if(CMAKE_BUILD_TYPE MATCHES "Debug")
MESSAGE (STATUS "building SVF in debug mode")
set(SVF_LIB "${SVF_DIR}/Debug-build/lib/libSvf.a")
set(LLVMCudd "${SVF_DIR}/Debug-build/lib/CUDD/libCudd.a")
else()
MESSAGE (STATUS "building SVF in release mode")
set(SVF_LIB "${SVF_DIR}/Release-build/lib/libSvf.a")
set(LLVMCudd "${SVF_DIR}/Release-build/lib/CUDD/libCudd.a")
endif()
set(SVF_HEADER "${SVF_DIR}/include")
include_directories(${SVF_HEADER})



add_subdirectory(src)
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# SVF-Teaching
Teaching Software Analysis via SVF
# Control Flow Reachability Assignment
In this assignment, you are requested to complete a function which will output the path between the source node and sink node.

## 1. Setup the assignment environment
This assignment requested the supports of the svf library. To compile the execuateable, you need to setup the svf library on your device.


<summary> Install svf-lib using npm (tested on both Ubuntu and MacOS)</summary>
```
npm i --silent svf-lib --prefix ${HOME}
```


After the svf-lib has been installed, you can run the **env. sh** script which is in your assignment folder to setup the environment.
```
source ./env.sh
```

While the environment has been setup, you are now able to start your assignment.

## 2. Coding your solution
For this assignment, you are requested to design a function which will query all reachable paths between the source and sink function.
```
src() is the source function.
sink() is the sink function.
```
## 3. Build and submit your solution
Your submission requests 2 components which are your solution codes and the execuateable file of your solution.

Once you complete the assignment, you need to run the **build. sh** script. This script will build your solution automatically and generate the execuateable file which called **svf-ex**.
```
./build.sh
```

Finally, you are requested to commit and push your code and the execuateable file via the git command.
```
git add <source code and the execuateable file>
git commit -m'<commit message>'
git push
```
*Note: It is important to submit the execuateable file. Otherwise, your submission will not be marked by the system.*

After the submission, you work will be automatically mark by the system and you are able to checked your mark at the assignment github repository.
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir build
cd build
cmake ..
make
cd ..
mv ./build/bin/svf-ex ./
21 changes: 21 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

PROJECTHOME=$(pwd)
sysOS=`uname -s`
LLVMHome="llvm-10.0.0.obj"
install_path=`npm root`
export LLVM_DIR=$HOME/$LLVMHome
export PATH=$LLVM_DIR/bin:$PATH
export PATH=$PROJECTHOME/bin:$PATH
echo "export LLVM_DIR=$HOME/$LLVMHome" >> ~/.bashrc
echo "export PATH=$LLVM_DIR/bin:$PROJECTHOME/bin:$PATH" >> ~/.bashrc
if [[ $sysOS == "Darwin" ]]
then
export SVF_DIR=$install_path/SVF/
elif [[ $sysOS == "Linux" ]]
then
export SVF_DIR=$install_path/SVF/
fi

echo "LLVM_DIR="$LLVM_DIR
echo "SVF_DIR="$SVF_DIR
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support )
file (GLOB SOURCES
*.cpp
)
add_executable(svf-ex ${SOURCES})

target_link_libraries(svf-ex ${SVF_LIB} ${LLVMCudd} ${llvm_libs})

set_target_properties( svf-ex PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
68 changes: 68 additions & 0 deletions src/svf-ex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//===- svf-ex.cpp -- A driver example of SVF-------------------------------------//
//
// SVF: Static Value-Flow Analysis
//
// Copyright (C) <2013-> <Yulei Sui>
//

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//===-----------------------------------------------------------------------===//

/*
// A driver program of SVF including usages of SVF APIs
//
// Author: Yulei Sui,
*/

#include "SVF-FE/LLVMUtil.h"
#include "Graphs/SVFG.h"
#include "WPA/Andersen.h"
#include "SABER/LeakChecker.h"
#include "SVF-FE/PAGBuilder.h"

using namespace SVF;
using namespace llvm;
using namespace std;

static llvm::cl::opt<std::string> InputFilename(cl::Positional,
llvm::cl::desc("<input bitcode>"), llvm::cl::init("-"));

static llvm::cl::opt<bool> LEAKCHECKER("leak", llvm::cl::init(false),
llvm::cl::desc("Memory Leak Detection"));

ICFGNode *srcNode = NULL;
ICFGNode *sinkNode = NULL;
PAG *pag;
std::set<const NodeID*> path_worklist;

int main(int argc, char ** argv) {

int arg_num = 0;
char **arg_value = new char*[argc];
std::vector<std::string> moduleNameVec;
SVFUtil::processArguments(argc, argv, arg_num, arg_value, moduleNameVec);
cl::ParseCommandLineOptions(arg_num, arg_value,
"Whole Program Points-to Analysis\n");

SVFModule* svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);

/// Build Program Assignment Graph (PAG)
PAGBuilder builder;
pag = builder.build (svfModule);
pag->dump ("pag");


return 0;
}

0 comments on commit c1d737a

Please sign in to comment.