Skip to content

Commit 4988194

Browse files
authored
Update README.md
1 parent 25f2c63 commit 4988194

File tree

1 file changed

+147
-1
lines changed

1 file changed

+147
-1
lines changed

README.md

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,150 @@ This custom-llvm has been forked for implementing fault-injector.
1010

1111
[Register Tracing](https://github.com/rollrat/runnable-llvm/blob/master/TraceRegister.md)
1212

13-
[Sample Codes](https://github.com/rollrat/runnable-llvm/tree/master/1samples)
13+
[Sample Codes](https://github.com/rollrat/runnable-llvm/tree/master/1samples)
14+
15+
## Build
16+
17+
```
18+
git clone https://github.com/HPCL-INHA/fault-injector
19+
cd fault-injector
20+
mkdir build
21+
cd build
22+
cmake ../
23+
cmake --build tools/opt -- -j32
24+
cmake --build tools/llc -- -j32
25+
```
26+
27+
## How to use
28+
29+
### Fault Injector Legacy
30+
31+
```
32+
Copy files in test directory to your test codes
33+
34+
clang -S -emit-llvm test.c
35+
./opt -faultinjectlegacy test.ll -S -o test-injected.ll
36+
llc -filetype=obj test-injected.ll -o test-injected.obj
37+
38+
clang -S -emit-llvm rtl-core.c
39+
llc -filetype=obj rtl-core.ll -o rtl-core.obj
40+
41+
clang rtl-core.obj test-injected.obj
42+
```
43+
44+
#### Test
45+
46+
Sample: https://github.com/HPCL-INHA/fault-injector/releases/download/binary/x86_64-linux.tar.xz
47+
48+
##### Profile Mode
49+
50+
1. Set `setting` file like this
51+
52+
```
53+
run_fault_injection 0
54+
count_of_determine 54
55+
```
56+
57+
If `run_fault_injection` set to zero, then faultinjected binary is run as profile mode.
58+
`count_of_determine` is used to faultinjection processing
59+
60+
2. Run `./a.out`
61+
62+
3. You can get outputs from `result` file
63+
64+
```
65+
[Fault Injector] RTL-Core Init!
66+
[Fault Injector] trace: f_index=00, index=01, reg_num=-1, dependency=-1, opcode= load, size=32, value=00000001
67+
[Fault Injector] trace: f_index=00, index=00, reg_num=-1, dependency=-1, opcode= load, size=32, value=00000000
68+
.
69+
.
70+
.
71+
[Fault Injector] trace: f_index=00, index=00, reg_num=-1, dependency=-1, opcode= load, size=32, value=00000001
72+
[Fault Injector] trace: f_index=00, index=08, reg_num=-1, dependency=-1, opcode= load, size=32, value=00000000
73+
[Fault Injector] RTL-Core Finish!
74+
[Fault Injector] determine=14
75+
```
76+
77+
##### Fault Injection Mode
78+
79+
1. Set `run_fault_injection` to `1`
80+
81+
2. Set `count_of_determine` to `determine` that can get from profile mode
82+
83+
You can get the `determine` from the result in profile mode.
84+
`determine` is a list of all variables that can be specified at program execution time.
85+
By setting `count_of_determine`, you can specify the probability of a bitflip occurring.
86+
87+
### Fault Injector to Minimize the Impact of Binary Code
88+
89+
```
90+
import sys
91+
import os
92+
import os.path
93+
from subprocess import Popen, PIPE
94+
95+
96+
if len(sys.argv) == 1:
97+
print "LLVM Based FaultInjector"
98+
print "run.py <Code File .c or .cpp>"
99+
exit(1)
100+
101+
if os.path.isfile(sys.argv[1]) == False:
102+
print "no such file or directory: " + sys.argv[1]
103+
exit(1)
104+
105+
clang_addr = "clang"
106+
opt_addr = "../opt" <= Set your opt binary path
107+
llc_addr = "../llc" <= Set your llc binary path
108+
109+
filename = os.path.splitext(sys.argv[1])[0]
110+
clang_result = filename + "-1-clang.ll"
111+
process = Popen([clang_addr, sys.argv[1], "-S", "-emit-llvm", "-o", clang_result, "-mllvm", "-disable-llvm-optzns", "-disable-llvm-passes", "-O1"])
112+
process.wait()
113+
114+
# Run faultinject pass
115+
opt_faultinject = filename + "-2-faultinject.ll"
116+
process = Popen([opt_addr, "-S", clang_result, "-o", opt_faultinject, "-faultinject"])
117+
process.wait()
118+
119+
# Run O2 optimizing
120+
o2_result = filename + "-3-o2.ll"
121+
process = Popen([opt_addr, "-S", opt_faultinject, "-o", o2_result, "-O2"])
122+
process.wait()
123+
124+
# 1. Run injectfault
125+
if_result = filename + "-4-injectfault.ll"
126+
process = Popen([opt_addr, "-S", o2_result, "-o", if_result, "-injectfault"])
127+
process.wait()
128+
129+
# 2. Run deleteinjectfunc
130+
dif_result = filename + "-4-deleteinjectfault.ll"
131+
process = Popen([opt_addr, "-S", o2_result, "-o", dif_result, "-deleteinjectfunc"])
132+
process.wait()
133+
134+
# 1-1. Run llc
135+
llc_1 = filename + "-5-llc-injectfault.s"
136+
process = Popen([llc_addr, if_result, "-o", llc_1])
137+
process.wait()
138+
139+
# 2-1. Run llc
140+
llc_2 = filename + "-5-llc-none.s"
141+
process = Popen([llc_addr, dif_result, "-o", llc_2])
142+
process.wait()
143+
144+
# 1-3. Extract binary
145+
obj_name1 = filename + "-6-bin-injectfault.obj"
146+
bin_name1 = filename + "-6-bin-injectfault"
147+
process = Popen([llc_addr, "-filetype=obj", if_result, "-o", obj_name1])
148+
process.wait()
149+
process = Popen([clang_addr, obj_name1, "-o", bin_name1])
150+
process.wait()
151+
152+
# 2-3. Extract binary
153+
obj_name2 = filename + "-6-bin-none.obj"
154+
bin_name2 = filename + "-6-bin-none"
155+
process = Popen([llc_addr, "-filetype=obj", dif_result, "-o", obj_name2])
156+
process.wait()
157+
process = Popen([clang_addr, obj_name2, "-o", bin_name2])
158+
process.wait()
159+
```

0 commit comments

Comments
 (0)