-
Notifications
You must be signed in to change notification settings - Fork 7
Exercises
cxreet edited this page Aug 4, 2020
·
10 revisions
There are 10 programs under directory /root/workspace/razor/benchmarks/core-utilities. For each program, run Razor with/without applying heuristics to get the results: (1) code reduction rate (CRR); (2) number of failed testing inputs.
Let's take bzip2 as an example.
- bzip2-1.0.5.c.orig.c : the source code.
- bzip2.orig : the binary.
- train : the directory that contains training inputs for profiling.
- test : the directory that contains testing inputs for evaluating the debloated binary.
-
run_razor.py : the helper script for running Razor, it takes commands:
-
train
: Trace the original binary with the inputs under train, get the traces → ./logs. -
debloat
:- Merge the logs → %program-trace.log
- Dump the executed instructions → instr.s
- Instrument the executed instructions → %program.s
- Rewrite the binary → %program.orig_temp/%program.orig.debloated
-
test
: Run the debloated binary with the inputs under test. -
extend_debloat [1|2|3|4]
: Use heuristics (1 → zCode, 2 → zCall, 3 → zLib, 4 → zFunc) to extend the merged log (i.e., %program-trace.log) and debloat the binary (i.e., dumping the executed instruction, instrumentation, rewriting the binary). The newly debloated binary would overwrite %program.orig_temp/%program.orig.debloated. -
clean
: Clean the outputs under current directory.
-
The following are an example to get the code reduction rates (CRRs) and the numbers of failed testing inputs for bzip2.
- Run and trace the binary with inputs under train :
python run_razor.py train
. - Debloat the binary without applying heuristics :
python run_razor.py debloat
. - Run the debloated binary with inputs under test :
python run_razor.py test
.- To focus on the failed cases with
Floating point exception
:python run_razor.py test | grep "Floating point exception"
- As we can see, there are 6 failed testing inputs without applying any heuristics.
- To focus on the failed cases with
- Get CRR:
- Get the code size of the original binary :
python ../../../tools/get_code_size.py ./bzip2.orig
- Get the code size of the debloated binary :
python ../../../tools/get_code_size.py ./bzip2.orig_temp/bzip2.orig.debloated
- Calculate the CRR :
python -c "print (old_size-new_size)/float(old_size)"
- As we can see, the CRR without applying any heuristics is 62.4% .
- Get the code size of the original binary :
- Apply heuristic zCode:
python run_razor.py extend_debloat 1
- Get failed cases when running the new debloated binary:
python run_razor.py test | grep "Floating point"
- As we can see, there are 5 failed testing inputs with applying heuristic zCode.
- Get the code size of the original binary :
python ../../../tools/get_code_size.py ./bzip2.orig
- Get the code size of the debloated binary :
python ../../../tools/get_code_size.py ./bzip2.orig_temp/bzip2.orig.debloated
- Calculate the CRR :
python -c "print (old_size-new_size)/float(old_size)"
- As we can see, the CRR with applying heuristics zCode is 62.4% .
- Apply heuristic zCall:
python run_razor.py extend_debloat 2
- Get failed cases when running the new debloated binary:
python run_razor.py test | grep "Floating point"
- As we can see, there are 1 failed testing inputs with applying heuristic zCall.
- Get the code size of the original binary :
python ../../../tools/get_code_size.py ./bzip2.orig
- Get the code size of the debloated binary :
python ../../../tools/get_code_size.py ./bzip2.orig_temp/bzip2.orig.debloated
- Calculate the CRR :
python -c "print (old_size-new_size)/float(old_size)"
- As we can see, the CRR with applying heuristics zCall is 59.9% .
- Apply heuristic zLib:
python run_razor.py extend_debloat 3
- Get failed cases when running the new debloated binary:
python run_razor.py test | grep "Floating point"
- As we can see, there are 0 failed testing inputs with applying heuristic zLib.
- Get the code size of the original binary :
python ../../../tools/get_code_size.py ./bzip2.orig
- Get the code size of the debloated binary :
python ../../../tools/get_code_size.py ./bzip2.orig_temp/bzip2.orig.debloated
- Calculate the CRR :
python -c "print (old_size-new_size)/float(old_size)"
- As we can see, the CRR with applying heuristics zLib is 24.8% .
- Since there are no failed cases, you might stop here.
- Apply heuristic zFunc:
python run_razor.py extend_debloat 4
- Get failed cases when running the new debloated binary:
python run_razor.py test | grep "Floating point"
- As we can see, there are 0 failed testing inputs with applying heuristic zFunc.
- Get the code size of the original binary :
python ../../../tools/get_code_size.py ./bzip2.orig
- Get the code size of the debloated binary :
python ../../../tools/get_code_size.py ./bzip2.orig_temp/bzip2.orig.debloated
- Calculate the CRR :
python -c "print (old_size-new_size)/float(old_size)"
- As we can see, the CRR with applying heuristics zFunc is 24.8% .
- So the CRRs and the numbers of failed testing inputs for bzip2 are: