├── prototype ├── .gitignore ├── hie.yaml ├── Setup.hs ├── test │ ├── mu.json │ ├── comp.json │ ├── comp.lif │ └── mu.lif ├── stack.yaml.lock ├── src │ ├── Internal │ │ ├── Map.hs │ │ ├── Constraint.hs │ │ └── Dot.hs │ ├── Core │ │ └── Error.hs │ └── Flow │ │ ├── DomTree.hs │ │ ├── Cfg.hs │ │ └── Block.hs ├── package.yaml ├── stack.yaml ├── lif-lang.cabal ├── README.md └── app │ └── Main.hs ├── lif ├── test │ ├── benchmarks │ │ ├── mu │ │ │ ├── input │ │ │ │ ├── 1.bin │ │ │ │ ├── 1.txt │ │ │ │ ├── 2.bin │ │ │ │ └── 2.txt │ │ │ ├── include │ │ │ │ └── mu.h │ │ │ ├── lib │ │ │ │ └── mu.c │ │ │ ├── src │ │ │ │ └── main.c │ │ │ └── llvm-ir │ │ │ │ ├── main.ll │ │ │ │ └── main.ctgrind.ll │ │ ├── log-redactor │ │ │ ├── input │ │ │ │ ├── 2.bin │ │ │ │ ├── 1.bin │ │ │ │ ├── 2.txt │ │ │ │ └── 1.txt │ │ │ ├── include │ │ │ │ └── log_redactor.h │ │ │ ├── lib │ │ │ │ └── log_redactor.c │ │ │ └── src │ │ │ │ └── main.c │ │ ├── scelim-2018 │ │ │ ├── applied-crypto │ │ │ │ ├── 3way │ │ │ │ │ ├── input │ │ │ │ │ │ ├── 1.txt │ │ │ │ │ │ ├── 2.txt │ │ │ │ │ │ ├── 1.bin │ │ │ │ │ │ └── 2.bin │ │ │ │ │ ├── include │ │ │ │ │ │ └── 3way.h │ │ │ │ │ ├── src │ │ │ │ │ │ └── main.c │ │ │ │ │ └── llvm-ir │ │ │ │ │ │ └── main.ll │ │ │ │ ├── des │ │ │ │ │ ├── input │ │ │ │ │ │ ├── 1.bin │ │ │ │ │ │ ├── 2.bin │ │ │ │ │ │ ├── 2.txt │ │ │ │ │ │ └── 1.txt │ │ │ │ │ ├── include │ │ │ │ │ │ └── des.h │ │ │ │ │ └── src │ │ │ │ │ │ └── main.c │ │ │ │ └── loki91 │ │ │ │ │ ├── input │ │ │ │ │ ├── 2.bin │ │ │ │ │ ├── 1.bin │ │ │ │ │ ├── 2.txt │ │ │ │ │ └── 1.txt │ │ │ │ │ ├── include │ │ │ │ │ └── loki91.h │ │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ │ └── llvm-ir │ │ │ │ │ └── main.ll │ │ │ ├── chronos │ │ │ │ └── cast5 │ │ │ │ │ ├── input │ │ │ │ │ ├── 2.bin │ │ │ │ │ ├── 1.bin │ │ │ │ │ ├── 2.txt │ │ │ │ │ └── 1.txt │ │ │ │ │ ├── include │ │ │ │ │ └── cast5.h │ │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ │ └── llvm-ir │ │ │ │ │ └── main.ll │ │ │ └── ghostrider │ │ │ │ ├── findmax │ │ │ │ ├── input │ │ │ │ │ ├── 1.bin │ │ │ │ │ ├── 2.bin │ │ │ │ │ ├── 1.txt │ │ │ │ │ └── 2.txt │ │ │ │ ├── include │ │ │ │ │ └── findmax.h │ │ │ │ ├── lib │ │ │ │ │ └── findmax.c │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ └── llvm-ir │ │ │ │ │ ├── findmax.ll │ │ │ │ │ ├── findmax.ctgrind.ll │ │ │ │ │ └── main.ll │ │ │ │ ├── histogram │ │ │ │ ├── include │ │ │ │ │ └── histogram.h │ │ │ │ ├── lib │ │ │ │ │ └── histogram.c │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ ├── input │ │ │ │ │ ├── 2.txt │ │ │ │ │ ├── 1.txt │ │ │ │ │ ├── 2.bin │ │ │ │ │ └── 1.bin │ │ │ │ └── llvm-ir │ │ │ │ │ ├── main.ll │ │ │ │ │ ├── histogram.ll │ │ │ │ │ └── histogram.ctgrind.ll │ │ │ │ └── dijkstra │ │ │ │ ├── include │ │ │ │ └── dijkstra.h │ │ │ │ ├── src │ │ │ │ └── main.c │ │ │ │ ├── input │ │ │ │ ├── 2.txt │ │ │ │ ├── 2.bin │ │ │ │ ├── 1.txt │ │ │ │ └── 1.bin │ │ │ │ └── lib │ │ │ │ └── dijkstra.c │ │ ├── fact-2019 │ │ │ ├── donna │ │ │ │ ├── input │ │ │ │ │ ├── 1.bin │ │ │ │ │ ├── 2.bin │ │ │ │ │ ├── 1.txt │ │ │ │ │ └── 2.txt │ │ │ │ ├── include │ │ │ │ │ └── curve25519_c64.h │ │ │ │ └── src │ │ │ │ │ └── main.c │ │ │ ├── crypto │ │ │ │ ├── include │ │ │ │ │ ├── _stdlib.h │ │ │ │ │ ├── salsa20.h │ │ │ │ │ ├── crypto_poly1305.h │ │ │ │ │ └── crypto_secretbox.h │ │ │ │ ├── lib │ │ │ │ │ └── _stdlib.c │ │ │ │ ├── input │ │ │ │ │ ├── 1.bin │ │ │ │ │ ├── 2.bin │ │ │ │ │ ├── 2.txt │ │ │ │ │ └── 1.txt │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ └── llvm-ir │ │ │ │ │ └── _stdlib.ll │ │ │ ├── ssl3 │ │ │ │ ├── include │ │ │ │ │ └── ssl3.h │ │ │ │ ├── input │ │ │ │ │ ├── 2.bin │ │ │ │ │ ├── 1.bin │ │ │ │ │ ├── 1.txt │ │ │ │ │ └── 2.txt │ │ │ │ └── src │ │ │ │ │ └── main.c │ │ │ └── include │ │ │ │ └── fact.h │ │ ├── comp │ │ │ ├── plain-one │ │ │ │ ├── include │ │ │ │ │ └── comp.h │ │ │ │ ├── lib │ │ │ │ │ └── comp.c │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ ├── llvm-ir │ │ │ │ │ ├── comp.ll │ │ │ │ │ ├── comp.ctgrind.ll │ │ │ │ │ └── main.ll │ │ │ │ └── input │ │ │ │ │ └── 2.txt │ │ │ ├── hash-one │ │ │ │ ├── include │ │ │ │ │ └── comp.h │ │ │ │ ├── lib │ │ │ │ │ └── comp.c │ │ │ │ ├── src │ │ │ │ │ └── main.c │ │ │ │ └── llvm-ir │ │ │ │ │ └── main.ll │ │ │ └── plain-many │ │ │ │ ├── include │ │ │ │ └── comp.h │ │ │ │ ├── lib │ │ │ │ └── comp.c │ │ │ │ ├── src │ │ │ │ └── main.c │ │ │ │ └── llvm-ir │ │ │ │ ├── comp.ll │ │ │ │ └── comp.ctgrind.ll │ │ └── include │ │ │ └── taint.h │ ├── ansi.clj │ ├── benchmarks.txt │ ├── convert.py │ ├── README.md │ └── compile.clj ├── .clang-format ├── .dockerignore ├── .gitignore ├── tool │ └── CMakeLists.txt ├── README.md ├── include │ ├── Transform │ │ ├── Isochronous.h │ │ └── Loop.h │ └── Analysis │ │ └── Taint.h ├── CMakeLists.txt └── lib │ └── Transform │ └── Loop.cpp └── images ├── PCFL.png ├── PosterPicture.png └── SummaryCharts.png /prototype/.gitignore: -------------------------------------------------------------------------------- 1 | .stack-work/ 2 | *~ -------------------------------------------------------------------------------- /prototype/hie.yaml: -------------------------------------------------------------------------------- 1 | cradle: 2 | stack: 3 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/input/1.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/input/1.txt: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/input/2.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/input/2.txt: -------------------------------------------------------------------------------- 1 | 1 3 5 2 | -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/input/2.bin: -------------------------------------------------------------------------------- 1 | ab1cd24x1abc23abj43jj1ababc2 -------------------------------------------------------------------------------- /prototype/Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /images/PCFL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/images/PCFL.png -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/input/1.bin: -------------------------------------------------------------------------------- 1 | abcdABCD1xabcxABCx1xaxcxABxD1xABxD -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/input/1.txt: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 1 1 1 3 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/input/2.txt: -------------------------------------------------------------------------------- 1 | 1 3 5 2 | 1 1 1 3 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/input/1.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/input/2.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/input/2.txt: -------------------------------------------------------------------------------- 1 | ab1cd24x 2 | 1abc23ab 3 | j43jj1ab 4 | abc2 5 | -------------------------------------------------------------------------------- /images/PosterPicture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/images/PosterPicture.png -------------------------------------------------------------------------------- /images/SummaryCharts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/images/SummaryCharts.png -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/input/1.txt: -------------------------------------------------------------------------------- 1 | abcdABCD1x 2 | abcxABCx1x 3 | axcxABxD1x 4 | ABxD 5 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/donna/input/1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/fact-2019/donna/input/1.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/donna/input/2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/fact-2019/donna/input/2.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/input/2.bin: -------------------------------------------------------------------------------- 1 | , -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/include/mu.h: -------------------------------------------------------------------------------- 1 | #ifndef MU_H 2 | #define MU_H 3 | 4 | #include 5 | 6 | void mu(int32_t *a); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/input/1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/scelim-2018/chronos/cast5/input/1.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/donna/input/1.txt: -------------------------------------------------------------------------------- 1 | 147 102 91 253 121 4 8 86 219 154 82 13 27 30 70 192 2 | 243 92 179 227 122 41 79 45 245 137 163 64 61 53 119 164 3 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/donna/input/2.txt: -------------------------------------------------------------------------------- 1 | 145 69 238 12 138 186 19 197 174 235 164 220 188 63 228 48 88 2 | 123 127 53 171 9 150 166 65 73 23 244 210 113 106 214 3 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/des/input/1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/scelim-2018/applied-crypto/des/input/1.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/des/input/2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/scelim-2018/applied-crypto/des/input/2.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/input/1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/scelim-2018/ghostrider/findmax/input/1.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/input/2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lac-dcc/lif/HEAD/lif/test/benchmarks/scelim-2018/ghostrider/findmax/input/2.bin -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/input/2.bin: -------------------------------------------------------------------------------- 1 | 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xe7234 14 117 90 92 46 130 16 36 42 8 231 7 143 127 137 56 94 176148 35 85 81 130 -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/input/1.bin: -------------------------------------------------------------------------------- 1 | 0x01 0x33 0x40 0x67 0x79 0xab 0xcd 0xe76 102 118 207 176 180 235 137 2 196 66 105 218 28 246 186102 211 248 182 212 177 0 169 -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/input/2.txt: -------------------------------------------------------------------------------- 1 | 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xe7 2 | 234 14 117 90 92 46 130 16 36 42 8 231 7 143 127 137 56 94 176 3 | 148 35 85 81 130 4 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/input/1.txt: -------------------------------------------------------------------------------- 1 | 0x01 0x33 0x40 0x67 0x79 0xab 0xcd 0xe7 2 | 6 102 118 207 176 180 235 137 2 196 66 105 218 28 246 186 3 | 102 211 248 182 212 177 0 169 4 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/des/input/2.txt: -------------------------------------------------------------------------------- 1 | 51 35 85 5 110 132 156 31 225 45 14 19 138 13 31 52 143 235 4 109 27 78 2 | 90 68 119 3 147 103 42 157 54 10 3 | 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xe7 4 | -------------------------------------------------------------------------------- /lif/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 4 3 | AllowShortIfStatementsOnASingleLine: true 4 | AllowShortFunctionsOnASingleLine: true 5 | AllowShortLambdasOnASingleLine: true 6 | AllowShortLoopsOnASingleLine: true 7 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/des/input/1.txt: -------------------------------------------------------------------------------- 1 | 21 135 185 105 110 132 146 231 225 45 146 19 138 13 31 42 43 135 184 109 27 2 | 69 99 68 119 3 147 103 42 162 54 8 3 | 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xe7 4 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/include/histogram.h: -------------------------------------------------------------------------------- 1 | #ifndef HISTOGRAM_H 2 | #define HISTOGRAM_H 3 | 4 | #define INPUT_SIZE 1000 5 | 6 | void histogram(int a[], int c[]); 7 | 8 | #endif // HISTOGRAM_H 9 | -------------------------------------------------------------------------------- /prototype/test/mu.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mu", 3 | "params": { 4 | "a": 0 5 | }, 6 | "mem": [ 7 | [0, 0, 0], 8 | [0, 0, 1], 9 | [0, 1, 1], 10 | [1, 1, 1] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /lif/.dockerignore: -------------------------------------------------------------------------------- 1 | # Benchmark binaries. 2 | bench/**/bin/ 3 | 4 | # Benchmark intermediate files. 5 | bench/**/*.ll 6 | bench/**/*.s 7 | 8 | # Result files. 9 | bench/**/*.cachegrind 10 | bench/**/*.csv 11 | bench/**/*.pdf 12 | bench/**/*.jpg 13 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/input/2.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 2 | 8 8 8 5 8 8 1 1 1 3 2 1 0 0 3 2 1 0 0 0 44 0 0 0 1 1 1 3 2 1 0 0 3 | 4 7 0 0 0 0 1 1 1 3 2 1 0 0 3 2 1 0 0 0 21 0 0 0 1 1 1 3 2 1 0 3 4 | -------------------------------------------------------------------------------- /prototype/test/comp.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "comp", 3 | "params": { 4 | "in": 0, 5 | "pw" : 2 6 | }, 7 | "mem": [ 8 | [0, 0, 0, 0], 9 | [0, 0, 1, 1], 10 | [0, 1, 1, 1], 11 | [1, 1, 1, 1] 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/include/comp.h: -------------------------------------------------------------------------------- 1 | #ifndef COMP_H 2 | #define COMP_H 3 | 4 | #ifdef ENABLE_UNROLL 5 | #ifndef N 6 | #define N 1024 7 | #endif 8 | 9 | int comp(int *a, int *b); 10 | #else 11 | int comp(int *a, int *b, int n); 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/include/findmax.h: -------------------------------------------------------------------------------- 1 | #ifndef FINDMAX_H 2 | #define FINDMAX_H 3 | 4 | #define INPUT_SIZE 1000 5 | 6 | #ifdef ENABLE_UNROLL 7 | int max(int h[]); 8 | #else 9 | int max(int n, int h[]); 10 | #endif 11 | 12 | #endif // FINDMAX_H 13 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/hash-one/include/comp.h: -------------------------------------------------------------------------------- 1 | #ifndef COMP_H 2 | #define COMP_H 3 | 4 | #define HASH_SIZE 1024 5 | 6 | #ifdef ENABLE_UNROLL 7 | #ifndef N 8 | #define N 1024 9 | #endif 10 | 11 | int comp(int *a, int *b); 12 | #else 13 | int comp(int *a, int *b, int n); 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/input/1.txt: -------------------------------------------------------------------------------- 1 | 106 139 57 242 5 13 124 149 252 59 194 2 | 98 165 48 191 40 221 2 119 113 100 238 3 | 122 54 46 137 193 175 230 116 196 110 4 | 0 0 0 0 0 0 1 1 1 3 2 1 0 0 3 2 1 0 0 0 0 0 0 0 1 1 1 3 2 1 0 0 5 | 4 7 0 0 0 0 1 1 1 3 2 1 0 0 3 2 1 0 0 0 0 0 0 0 1 1 1 3 2 1 0 3 6 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-many/include/comp.h: -------------------------------------------------------------------------------- 1 | #ifndef COMP_H 2 | #define COMP_H 3 | 4 | #ifdef ENABLE_UNROLL 5 | #ifndef N 6 | #define N 5 7 | #endif 8 | 9 | #ifndef M 10 | #define M 1024 11 | #endif 12 | 13 | int comp(int **a, int *b); 14 | #else 15 | int comp(int **a, int *b, int n, int m); 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /prototype/test/comp.lif: -------------------------------------------------------------------------------- 1 | begin: 2 | load(x0, in, 0) 3 | load(y0, pw, 0) 4 | mov(p0, x0 != y0) 5 | br(p0, end, next) 6 | 7 | next: 8 | load(x1, in, 1) 9 | load(y1, pw, 1) 10 | mov(p1, x1 != y1) 11 | br(p1, end, true) 12 | 13 | true: 14 | jmp(end) 15 | 16 | end: 17 | phi(z, 0: begin, 0: next, 1: true) 18 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/include/_stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDLIB_H_ 2 | #define _STDLIB_H_ 3 | 4 | #include "../../../include/taint.h" 5 | 6 | #include 7 | #include 8 | 9 | // @return SECRET 10 | bool _crypto_verify_16( 11 | secret uint8_t x[16], 12 | secret uint8_t y[16] 13 | ); 14 | 15 | #endif // _STDLIB_H_ 16 | -------------------------------------------------------------------------------- /lif/.gitignore: -------------------------------------------------------------------------------- 1 | # Cmake 2 | compile_commands.json 3 | cmake_install.cmake 4 | CMakeCache.txt 5 | CMakeFiles/ 6 | 7 | # Ninja 8 | *ninja* 9 | 10 | # Clang 11 | .clangd 12 | 13 | # Python 14 | __pycache__/ 15 | 16 | # Exec 17 | bin/ 18 | 19 | # Benchmark generated files 20 | test/**/asm 21 | test/**/bin 22 | # test/**/llvm-ir 23 | test/**/results 24 | test/.nrepl-port 25 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/donna/include/curve25519_c64.h: -------------------------------------------------------------------------------- 1 | #ifndef CURVE25519_C64_H 2 | #define CURVE25519_C64_H 3 | 4 | #include 5 | 6 | int32_t curve25519_donna( 7 | uint8_t *mypublic, // secret (why??), len = 32 8 | uint8_t *_secret, // secret (obviously), len = 32 9 | uint8_t *basepoint // public, len = 32 10 | ); 11 | 12 | #endif // CURVE25519_C64_H 13 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/include/dijkstra.h: -------------------------------------------------------------------------------- 1 | #ifndef DIJKSTRA_H 2 | #define DIJKSTRA_H 3 | 4 | #include "../../../../include/taint.h" 5 | 6 | #define INPUT_SIZE 16 // num edges -> 16 * 16 = 256 7 | 8 | __attribute__((noinline)) 9 | int dijkstra(int n, int s, int t, int e[][INPUT_SIZE]); 10 | 11 | extern secret int x; 12 | 13 | #endif // DIJKSTRA_H 14 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/lib/comp.c: -------------------------------------------------------------------------------- 1 | #include "../include/comp.h" 2 | 3 | #ifdef ENABLE_UNROLL 4 | int comp(int *a, int *b) { 5 | // Unrollable version requires a loop with constant bound. 6 | for (int i = 0; i < N; i++) 7 | #else 8 | int comp(int *a, int *b, int n) { 9 | for (int i = 0; i < n; i++) 10 | #endif 11 | if (a[i] != b[i]) return 0; 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /lif/test/ansi.clj: -------------------------------------------------------------------------------- 1 | (def ansi-reset "\033[0m") 2 | (def ansi-red "\033[0;31m") 3 | (def ansi-green "\033[0;32m") 4 | (def ansi-color {:red ansi-red :green ansi-green}) 5 | 6 | (defn with-color 7 | "Takes keyword of a color (e.g. :green), one or more texts (strings), 8 | and returns the (concatenated) text with the given color." 9 | [color text & texts] 10 | (str (color ansi-color) text (apply str texts) ansi-reset)) 11 | -------------------------------------------------------------------------------- /lif/test/benchmarks/include/taint.h: -------------------------------------------------------------------------------- 1 | #ifndef TAINT_H 2 | #define TAINT_H 3 | 4 | #include 5 | 6 | #define secret __attribute__((annotate("secret"))) 7 | 8 | #ifdef ENABLE_CTGRIND 9 | #define ct_secret(addr, len) VALGRIND_MAKE_MEM_UNDEFINED(addr, len) 10 | #define ct_public(addr, len) VALGRIND_MAKE_MEM_DEFINED(addr, len) 11 | #else 12 | #define ct_secret(addr, len) 13 | #define ct_public(addr, len) 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/include/loki91.h: -------------------------------------------------------------------------------- 1 | #ifndef LOKI91_H 2 | #define LOKI91_H 3 | 4 | #include 5 | 6 | #define LOKIBLK 8 /* No of bytes in a LOKI data-block */ 7 | #define ROUNDS 16 /* No of LOKI rounds */ 8 | 9 | typedef struct { 10 | int32_t loki_subkeys[ROUNDS]; 11 | } loki_ctx; 12 | 13 | void setlokikey(unsigned char *key, loki_ctx *c); 14 | void enloki(loki_ctx *c, unsigned char *b); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /prototype/stack.yaml.lock: -------------------------------------------------------------------------------- 1 | # This file was autogenerated by Stack. 2 | # You should not edit this file by hand. 3 | # For more information, please see the documentation at: 4 | # https://docs.haskellstack.org/en/stable/lock_files 5 | 6 | packages: [] 7 | snapshots: 8 | - completed: 9 | size: 492015 10 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/8.yaml 11 | sha256: 926bc3d70249dd0ba05277ff00943c0addb35b627cb641752669e7cf771310d0 12 | original: lts-15.8 13 | -------------------------------------------------------------------------------- /lif/tool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(lif 2 | Lif.cpp 3 | ../lib/Transform/CCFG.cpp 4 | ../lib/Transform/Cond.cpp 5 | ../lib/Transform/Loop.cpp 6 | ../lib/Transform/Func.cpp 7 | ../lib/Transform/Isochronous.cpp 8 | ../lib/Analysis/Taint.cpp 9 | ) 10 | 11 | target_link_libraries(lif 12 | LLVMCore 13 | LLVMIRReader 14 | LLVMSupport 15 | LLVMPasses 16 | LLVMAnalysis 17 | LLVMTransformUtils) 18 | target_include_directories(lif PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include") 19 | -------------------------------------------------------------------------------- /lif/test/benchmarks.txt: -------------------------------------------------------------------------------- 1 | benchmarks/comp/plain-one 2 | benchmarks/comp/plain-many 3 | benchmarks/comp/hash-one 4 | benchmarks/log-redactor 5 | benchmarks/mu 6 | benchmarks/scelim-2018/applied-crypto/3way 7 | benchmarks/scelim-2018/applied-crypto/des 8 | benchmarks/scelim-2018/applied-crypto/loki91 9 | benchmarks/scelim-2018/chronos/cast5 10 | benchmarks/scelim-2018/ghostrider/dijkstra 11 | benchmarks/scelim-2018/ghostrider/findmax 12 | benchmarks/scelim-2018/ghostrider/histogram 13 | benchmarks/fact-2019/ssl3 14 | benchmarks/fact-2019/donna 15 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/lib/mu.c: -------------------------------------------------------------------------------- 1 | #include "../include/mu.h" 2 | 3 | void mu(int32_t *a) { 4 | int i; 5 | int32_t b[3]; 6 | b[0] = b[1] = b[2] = 0; 7 | for (i = 0; i < 32; i++) { 8 | b[0] <<= 1; 9 | b[1] <<= 1; 10 | b[2] <<= 1; 11 | if (a[0] & 1) b[2] |= 1; // leak 12 | if (a[1] & 1) b[1] |= 1; // leak 13 | if (a[2] & 1) b[0] |= 1; // leak 14 | a[0] >>= 1; 15 | a[1] >>= 1; 16 | a[2] >>= 1; 17 | } 18 | a[0] = b[0]; 19 | a[1] = b[1]; 20 | a[2] = b[2]; 21 | } 22 | -------------------------------------------------------------------------------- /lif/test/convert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import struct 3 | import sys 4 | 5 | input_file = sys.argv[1] + '.txt' 6 | output_file = sys.argv[1] + '.bin' 7 | 8 | binary = [] 9 | with open(input_file, 'r') as f: 10 | for line in f: 11 | if line.isspace(): continue 12 | binary += list(map( 13 | # lambda x: struct.pack('i', int(x, 0)), 14 | # line.strip().split() 15 | lambda x: struct.pack('c', x.encode('ascii')), 16 | line.strip() 17 | )) 18 | 19 | with open(output_file, 'wb') as f: 20 | for x in binary: f.write(x) 21 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/include/cast5.h: -------------------------------------------------------------------------------- 1 | #ifndef CAST5_H 2 | #define CAST5_H 3 | 4 | #include 5 | 6 | #define CAST5_BLOCK_SIZE 8 7 | #define CAST5_MIN_KEY_SIZE 5 8 | #define CAST5_MAX_KEY_SIZE 16 9 | 10 | struct cast5_ctx { 11 | uint32_t Km[16]; 12 | uint8_t Kr[16]; 13 | int rr; /* rr?number of rounds = 16:number of rounds = 12; (rfc 2144) */ 14 | }; 15 | 16 | int cast5_setkey(uint8_t *key, struct cast5_ctx *c, unsigned key_len); 17 | void cast5_encrypt( 18 | struct cast5_ctx *c, uint8_t *outbuf, const uint8_t *inbuf, int rr 19 | ); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/lib/findmax.c: -------------------------------------------------------------------------------- 1 | #include "../include/findmax.h" 2 | 3 | #define CHECK_INST_COUNT 1 // ADDED TO CHECK OP INVARIANCE 4 | #ifdef CHECK_INST_COUNT // ADDED TO CHECK OP INVARIANCE 5 | volatile int foo = 0; 6 | #endif 7 | 8 | #ifdef ENABLE_UNROLL 9 | int max(int h[]) { 10 | #else 11 | int max(int n, int h[]) { 12 | #endif 13 | int i = 0; 14 | int m = 0; 15 | #ifdef ENABLE_UNROLL 16 | while (i < INPUT_SIZE) { 17 | #else 18 | while (i < n) { 19 | #endif 20 | if (h[i] > m) m = h[i]; 21 | i++; 22 | } 23 | return m; 24 | } 25 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-many/lib/comp.c: -------------------------------------------------------------------------------- 1 | #include "../include/comp.h" 2 | 3 | #ifdef ENABLE_UNROLL 4 | int comp(int **a, int *b) { 5 | for (int i = 0; i < N; i++) { 6 | int j = 0; 7 | while (j < M) { 8 | #else 9 | int comp(int **a, int *b, int n, int m) { 10 | for (int i = 0; i < n; i++) { 11 | int j = 0; 12 | while (j < m) { 13 | #endif 14 | if (a[i][j] != b[j]) break; 15 | else j++; 16 | } 17 | #ifdef ENABLE_UNROLL 18 | if (j == M) return 1; 19 | #else 20 | if (j == m) return 1; 21 | #endif 22 | 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/ssl3/include/ssl3.h: -------------------------------------------------------------------------------- 1 | #ifndef SSL3_H 2 | #define SSL3_H 3 | 4 | #include "../../include/fact.h" 5 | #include 6 | 7 | // We annotate the indices of the arguments whose types we don't want 8 | // lif to wrap (because they're already wrapped). 9 | __attribute__((annotate("nowrap:0,1,2,3"))) 10 | int32_t __ssl3_cbc_digest_record( 11 | uint8ptr_wrapped_ty *md_state, uint8ptr_wrapped_ty *mac_out, 12 | // ~~~ 13 | uint8ptr_wrapped_ty *header, uint8ptr_wrapped_ty *data, 14 | // `data_plus_mac_plus_padding_size` is len data 15 | uint64_t data_plus_mac_size 16 | ); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/lib/_stdlib.c: -------------------------------------------------------------------------------- 1 | #include "../include/_stdlib.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | 6 | /************************************************************************** 7 | * Ported from: 8 | * github.com/PLSysSec/fact-eval/blob/master/crypto_secretbox/stdlib.fact 9 | **************************************************************************/ 10 | 11 | bool _crypto_verify_16( 12 | secret uint8_t x[16], 13 | secret uint8_t y[16] 14 | ) { 15 | for (uint32_t i = 0; i < 16; i++) { 16 | if (x[i] != y[i]) { // TAINTED 17 | return false; 18 | } 19 | } 20 | 21 | return true; 22 | } 23 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/ssl3/input/2.bin: -------------------------------------------------------------------------------- 1 | 93 70 195 203 40 205 59 8 8 86 113 216 93 64 80 55 113 241 134 164 152 169 240 91 141 78 169 168 117 233 197 221 98 93 84 222 146 202 114 80 237 244 8 250 131 224 145 148 57 192 245 244 150 137 246 14 161 21 197 244 61 92 126 177 134 194 22 20 243 190 1533 182 133 82 151 96 15 38 194 98 210 1 28 108 243 229 26 93 193 112 137 187 226 121 15 80 63 55 215 152 253 224 34 41 129 51 203 183 199 2 245 0 71 146 227 190 163 157 253 166 175 4 60 12 87 28 110 79 92 231 221 172 100 108 32 83 201 126 28 185 215 9 41 156 44 250 246 198 88 96 21 153 43 188 72 189 157 240 60 239 95 87 230 235 82 235 207 12 29 203 234 119 199 191 28 108 154 197 75 149 245 139 28 78 230 167 28 192 230 161 224 90 184 78 81 37 113 94 -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/input/1.bin: -------------------------------------------------------------------------------- 1 | 29 145 187 43 46 41 238 77 140 167 210 13 228 75 169 6 22 182 45 15 41 72 113 43 90 113 229 17 213 5 143 171 209 45 177 81 155 32 175 68 23 115 184 80 109 247 86 214 125 166 70 91 144 201 109 154 165 31 225 112 145 26 252 246 123 46 196 88 207 13 991 9 18 212 245 190 1 193 12 0 81 117 220 26 130 28 227 179 229 253 161 241 247 253 181 86 156 226 148 135 70 172 144 245 167 180 23 201 217 35 214 118 99 214 96 244 122 209 67 123 190 75 156 32 106 46 148 59 152 102 171 83 171 83 17 251 143 82 222 254 178 212 181 122 193 9 8 159 202 131 189 115 72 76 158 79 21 45 75 193 27 170 255 71 159 241 197 133 230 32 116 211 234 128 200 224 37 179 253 249 123 136 120 238 187 71 43 82 7 111 155 39 62 112 53 217 205 39 -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/input/2.bin: -------------------------------------------------------------------------------- 1 | 93 70 195 203 40 205 59 8 8 86 113 216 93 64 80 55 113 241 134 164 152 169 240 91 141 78 169 168 117 233 197 221 98 93 84 222 146 202 114 80 237 244 8 250 131 224 145 148 57 192 245 244 150 137 246 14 161 21 197 244 61 92 126 177 134 194 22 20 243 190 1533 182 133 82 151 96 15 38 194 98 210 1 28 108 243 229 26 93 193 112 137 187 226 121 15 80 63 55 215 152 253 224 34 41 129 51 203 183 199 2 245 0 71 146 227 190 163 157 253 166 175 4 60 12 87 28 110 79 92 231 221 172 100 108 32 83 201 126 28 185 215 9 41 156 44 250 246 198 88 96 21 153 43 188 72 189 157 240 60 239 95 87 230 235 82 235 207 12 29 203 234 119 199 191 28 108 154 197 75 149 245 139 28 78 230 167 28 192 230 161 224 90 184 78 81 37 113 94 -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/ssl3/input/1.bin: -------------------------------------------------------------------------------- 1 | 29 145 187 43 46 41 238 77 140 167 210 13 228 75 169 6 22 182 45 15 41 72 113 43 90 113 229 17 213 5 143 171 209 45 177 81 155 32 175 68 23 115 184 80 109 247 86 214 125 166 70 91 144 201 109 154 165 31 225 112 145 26 252 246 123 46 196 88 207 13 991 9 18 212 245 190 1 193 12 0 81 117 220 26 130 28 227 179 229 253 161 241 247 253 181 86 156 226 148 135 70 172 144 245 167 180 23 201 217 35 214 118 99 214 96 244 122 209 67 123 190 75 156 32 106 46 148 59 152 102 171 83 171 83 17 251 143 82 222 254 178 212 181 122 193 9 8 159 202 131 189 115 72 76 158 79 21 45 75 193 27 170 255 71 159 241 197 133 230 32 116 211 234 128 200 224 37 179 253 249 123 136 120 238 187 71 43 82 7 111 155 39 62 112 53 217 205 39 -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/hash-one/lib/comp.c: -------------------------------------------------------------------------------- 1 | #include "../include/comp.h" 2 | 3 | #ifdef ENABLE_UNROLL 4 | int comp(int *a, int *b) { 5 | #else 6 | int comp(int *a, int *b, int n) { 7 | #endif 8 | int ha = 1; 9 | int hb = 1; 10 | 11 | #ifdef ENABLE_UNROLL 12 | for (int i = 0; i < N; i++) { 13 | #else 14 | for (int i = 0; i < n; i++) { 15 | #endif 16 | if (a[i]) ha = (ha * a[i]) % HASH_SIZE; 17 | else ha++; 18 | } 19 | 20 | #ifdef ENABLE_UNROLL 21 | for (int i = 0; i < N; i++) { 22 | #else 23 | for (int i = 0; i < n; i++) { 24 | #endif 25 | if (b[i]) hb = (hb * b[i]) % HASH_SIZE; 26 | else hb++; 27 | } 28 | 29 | if (ha == hb) return 1; 30 | else return 0; 31 | } 32 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/input/2.txt: -------------------------------------------------------------------------------- 1 | 93 70 195 203 40 205 59 8 8 86 113 216 93 64 80 55 113 241 134 164 152 2 | 169 240 91 141 78 169 168 117 233 197 221 98 93 84 222 146 202 114 80 3 | 237 244 8 250 131 224 145 148 57 192 245 244 150 137 246 14 161 21 197 4 | 244 61 92 126 177 134 194 22 20 243 190 153 3 182 133 82 151 96 15 38 5 | 194 98 210 1 28 108 243 229 26 93 193 112 137 187 226 121 15 80 63 55 6 | 215 152 253 224 34 41 129 51 203 183 199 2 245 0 71 146 227 190 163 7 | 157 253 166 175 4 60 12 87 28 110 79 92 231 221 172 100 108 32 83 201 8 | 126 28 185 215 9 41 156 44 250 246 198 88 96 21 153 43 188 72 189 157 9 | 240 60 239 95 87 230 235 82 235 207 12 29 203 234 119 199 191 28 108 10 | 154 197 75 149 245 139 28 78 230 167 28 192 230 161 224 90 184 78 81 11 | 37 113 94 12 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/ssl3/input/1.txt: -------------------------------------------------------------------------------- 1 | 29 145 187 43 46 41 238 77 140 167 210 13 228 75 169 6 22 182 45 15 41 2 | 72 113 43 90 113 229 17 213 5 143 171 209 45 177 81 155 32 175 68 23 3 | 115 184 80 109 247 86 214 125 166 70 91 144 201 109 154 165 31 225 112 4 | 145 26 252 246 123 46 196 88 207 13 99 1 9 18 212 245 190 1 193 12 0 5 | 81 117 220 26 130 28 227 179 229 253 161 241 247 253 181 86 156 226 6 | 148 135 70 172 144 245 167 180 23 201 217 35 214 118 99 214 96 244 122 7 | 209 67 123 190 75 156 32 106 46 148 59 152 102 171 83 171 83 17 251 8 | 143 82 222 254 178 212 181 122 193 9 8 159 202 131 189 115 72 76 158 9 | 79 21 45 75 193 27 170 255 71 159 241 197 133 230 32 116 211 234 128 10 | 200 224 37 179 253 249 123 136 120 238 187 71 43 82 7 111 155 39 62 11 | 112 53 217 205 39 12 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/ssl3/input/2.txt: -------------------------------------------------------------------------------- 1 | 93 70 195 203 40 205 59 8 8 86 113 216 93 64 80 55 113 241 134 164 152 2 | 169 240 91 141 78 169 168 117 233 197 221 98 93 84 222 146 202 114 80 3 | 237 244 8 250 131 224 145 148 57 192 245 244 150 137 246 14 161 21 197 4 | 244 61 92 126 177 134 194 22 20 243 190 153 3 182 133 82 151 96 15 38 5 | 194 98 210 1 28 108 243 229 26 93 193 112 137 187 226 121 15 80 63 55 6 | 215 152 253 224 34 41 129 51 203 183 199 2 245 0 71 146 227 190 163 7 | 157 253 166 175 4 60 12 87 28 110 79 92 231 221 172 100 108 32 83 201 8 | 126 28 185 215 9 41 156 44 250 246 198 88 96 21 153 43 188 72 189 157 9 | 240 60 239 95 87 230 235 82 235 207 12 29 203 234 119 199 191 28 108 10 | 154 197 75 149 245 139 28 78 230 167 28 192 230 161 224 90 184 78 81 11 | 37 113 94 12 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/input/1.txt: -------------------------------------------------------------------------------- 1 | 29 145 187 43 46 41 238 77 140 167 210 13 228 75 169 6 22 182 45 15 41 2 | 72 113 43 90 113 229 17 213 5 143 171 209 45 177 81 155 32 175 68 23 3 | 115 184 80 109 247 86 214 125 166 70 91 144 201 109 154 165 31 225 112 4 | 145 26 252 246 123 46 196 88 207 13 99 1 9 18 212 245 190 1 193 12 0 5 | 81 117 220 26 130 28 227 179 229 253 161 241 247 253 181 86 156 226 6 | 148 135 70 172 144 245 167 180 23 201 217 35 214 118 99 214 96 244 122 7 | 209 67 123 190 75 156 32 106 46 148 59 152 102 171 83 171 83 17 251 8 | 143 82 222 254 178 212 181 122 193 9 8 159 202 131 189 115 72 76 158 9 | 79 21 45 75 193 27 170 255 71 159 241 197 133 230 32 116 211 234 128 10 | 200 224 37 179 253 249 123 136 120 238 187 71 43 82 7 111 155 39 62 11 | 112 53 217 205 39 12 | -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/include/log_redactor.h: -------------------------------------------------------------------------------- 1 | #ifndef LOG_REDACTOR_H 2 | #define LOG_REDACTOR_H 3 | 4 | #ifdef ENABLE_UNROLL 5 | #ifndef L0 6 | #define L0 3 7 | #endif 8 | 9 | #ifndef L1 10 | #define L1 10 11 | #endif 12 | 13 | #ifndef P 14 | #define P 4 15 | #endif 16 | 17 | void log_redactor(char *log[], char *pattern); 18 | 19 | #else 20 | /** 21 | * This function will do the following: 22 | * - For each array A in log[] that contains pattern, it will replace every 23 | * number in A by a star symbol (*). 24 | * L0: The number of arrays in log 25 | * L1: The size of each array withing log 26 | * P: The size of the pattern. 27 | */ 28 | void log_redactor( 29 | char *log[], char *pattern, const unsigned L0, 30 | const int L1, const int P 31 | ); 32 | #endif 33 | 34 | #endif // LOG_REDACTOR_H 35 | -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/lib/log_redactor.c: -------------------------------------------------------------------------------- 1 | #include "../include/log_redactor.h" 2 | #include "../../include/taint.h" 3 | 4 | #ifdef ENABLE_UNROLL 5 | void log_redactor(char *log[], char *pattern) { 6 | #else 7 | void log_redactor( 8 | char *log[], char *pattern, const unsigned L0, 9 | const int L1, const int P 10 | ) { 11 | #endif 12 | for (unsigned i = 0; i < L0; i++) { 13 | unsigned found = 0; 14 | 15 | for (unsigned j = 0; j < L1 - P + 1; j++) { 16 | unsigned k = 0; 17 | while (k < P) { 18 | if (pattern[k] != log[i][j + k]) break; 19 | k++; 20 | } 21 | if (k == P) found = 1; 22 | } 23 | 24 | if (!found) continue; 25 | for (unsigned j = 0; j < L1; j++) { 26 | if (log[i][j] >= '0' && log[i][j] <= '9') 27 | log[i][j] = '*'; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /prototype/src/Internal/Map.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ScopedTypeVariables #-} 2 | ----------------------------------------------------------------------------- 3 | -- | 4 | -- Module : Internal.Map 5 | -- Copyright : (c) Luigi D. C. Soares 2020 6 | -- License : GPL-3 7 | -- 8 | -- Maintainer : luigidcsoares@gmail.com 9 | -- Stability : experimental 10 | -- Portability : portable 11 | ---------------------------------------------------------------------------- 12 | module Internal.Map 13 | ( fromMap 14 | ) 15 | where 16 | 17 | import Data.Map ( Map 18 | , foldrWithKey 19 | ) 20 | import Data.Bool ( bool ) 21 | 22 | -- | Takes a list of keys and a map, and returns a list of values 23 | -- corresponding to these keys. 24 | fromMap :: forall a b . Ord a => [a] -> Map a b -> [b] 25 | fromMap keys = 26 | foldrWithKey (\k v accum -> bool accum (v : accum) $ k `elem` keys) [] 27 | -------------------------------------------------------------------------------- /prototype/src/Core/Error.hs: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- | 3 | -- Module : Core.Error 4 | -- Copyright : (c) Luigi D. C. Soares 2020 5 | -- License : GPL-3 6 | -- 7 | -- Maintainer : luigidcsoares@gmail.com 8 | -- Stability : experimental 9 | -- Portability : portable 10 | ---------------------------------------------------------------------------- 11 | module Core.Error 12 | ( Error(..) 13 | , Throws 14 | ) 15 | where 16 | 17 | import Text.ParserCombinators.Parsec ( ParseError ) 18 | 19 | import Core.Lang ( Label 20 | , Var 21 | ) 22 | 23 | data Error = UndefVar Var 24 | | UndefLabel [Label] 25 | | Parser ParseError 26 | 27 | instance Show Error where 28 | show (UndefVar x ) = "Use of variable before definition: " ++ x 29 | show (UndefLabel l ) = "Use of nonexistent label: " ++ show l 30 | show (Parser parseErr) = "Parse error at: " ++ show parseErr 31 | 32 | type Throws = Either Error 33 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/lib/histogram.c: -------------------------------------------------------------------------------- 1 | #include "../include/histogram.h" 2 | 3 | /* #define CHECK_INST_COUNT 1 // ADDED TO CHECK OP INVARIANCE */ 4 | #ifdef CHECK_INST_COUNT // ADDED TO CHECK OP INVARIANCE 5 | #include 6 | 7 | #define ENABLE_CTGRIND 1 8 | #include "../../../../include/taint.h" 9 | #endif 10 | 11 | void histogram(int a[], int c[]) { 12 | int i; 13 | int t, v; 14 | 15 | for (i = 0; i < INPUT_SIZE; i++) c[i] = 0; 16 | 17 | for (i = 0; i < INPUT_SIZE; i++) { 18 | v = a[i]; 19 | 20 | #ifdef CHECK_INST_COUNT // ADDED TO CHECK OP INVARIANCE 21 | int foo = 0; 22 | #endif 23 | 24 | if (v > 0) { 25 | #ifdef CHECK_INST_COUNT // ADDED TO CHECK OP INVARIANCE 26 | foo++; 27 | #endif 28 | t = v % INPUT_SIZE; 29 | } else { 30 | t = (0 - v) % INPUT_SIZE; 31 | } 32 | 33 | #ifdef CHECK_INST_COUNT // ADDED TO CHECK OP INVARIANCE 34 | // Mark foo as public to eliminate false positives due 35 | // to non constant-time implementation of printf. 36 | ct_public(&foo, sizeof(int)); 37 | printf("%d\n", foo); 38 | #endif 39 | 40 | c[t] = c[t] + 1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/histogram.h" 2 | #include "../../../../include/taint.h" 3 | 4 | #include 5 | 6 | #ifdef ENABLE_MEASURE_TIME 7 | #include 8 | #include 9 | 10 | #define _NS_PER_SECO_ND 1000000000 11 | #define INLINE __attribute__((__always_inline__)) inline 12 | INLINE uint64_t nanoseconds(struct timespec t) { 13 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 14 | } 15 | #endif 16 | 17 | int main() { 18 | secret int in[INPUT_SIZE]; 19 | int out[INPUT_SIZE]; 20 | 21 | for (int i = 0; i < INPUT_SIZE; i++) 22 | read(0, &in[i], sizeof(int)); 23 | 24 | // Mark input as secret for ct_grind check: 25 | ct_secret(in, sizeof(int) * INPUT_SIZE); 26 | 27 | #ifdef ENABLE_MEASURE_TIME 28 | struct timespec start, end; 29 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 30 | #endif 31 | 32 | histogram(in, out); 33 | 34 | #ifdef ENABLE_MEASURE_TIME 35 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 36 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 37 | printf("\nTime: %ld\n", delta); 38 | #endif 39 | 40 | write(1, out, sizeof(int) * INPUT_SIZE); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/findmax.h" 2 | #include "../../../../include/taint.h" 3 | 4 | #include 5 | 6 | #ifdef ENABLE_MEASURE_TIME 7 | #include 8 | #include 9 | 10 | #define _NS_PER_SECO_ND 1000000000 11 | #define INLINE __attribute__((__always_inline__)) inline 12 | INLINE uint64_t nanoseconds(struct timespec t) { 13 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 14 | } 15 | #endif 16 | 17 | int main() { 18 | secret int in[INPUT_SIZE]; 19 | 20 | for (int i = 0; i < INPUT_SIZE; i++) 21 | read(0, &in[i], sizeof(int)); 22 | 23 | // Mark input as secret for ct_grind check: 24 | ct_secret(in, sizeof(int) * INPUT_SIZE); 25 | 26 | #ifdef ENABLE_MEASURE_TIME 27 | struct timespec start, end; 28 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 29 | #endif 30 | 31 | #ifdef ENABLE_UNROLL 32 | int r = max(in); 33 | #else 34 | int r = max(INPUT_SIZE, in); 35 | #endif 36 | 37 | #ifdef ENABLE_MEASURE_TIME 38 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 39 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 40 | printf("\nTime: %ld\n", delta); 41 | #endif 42 | 43 | write(1, &r, sizeof(int)); 44 | } 45 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/include/salsa20.h: -------------------------------------------------------------------------------- 1 | #ifndef SALSA20_H_ 2 | #define SALSA20_H_ 3 | 4 | #include "../../../include/taint.h" 5 | #include "../../include/fact.h" 6 | 7 | #include 8 | 9 | void _crypto_core_salsa20( // crypto_core_salsa in core_salsa_ref.c 10 | secret uint8_t output[64], // MUTABLE 11 | secret uint8_t input[16], 12 | secret uint8_t k[32] 13 | ); 14 | 15 | // We annotate the indices of the arguments whose types we don't want 16 | // lif to wrap (because they're already wrapped). 17 | __attribute__((annotate("nowrap:0"))) 18 | int32_t _crypto_stream_salsa20( // stream_ref in salsa20_ref.c 19 | uint8ptr_wrapped_ty *c, // MUTABLE, SECRET (buffer) 20 | uint8_t n[8], 21 | secret uint8_t k[32] 22 | ); 23 | 24 | // We annotate the indices of the arguments whose types we don't want 25 | // lif to wrap (because they're already wrapped). 26 | __attribute__((annotate("nowrap:0,1"))) 27 | int32_t _crypto_stream_salsa20_xor_ic( // stream_ref_xor_ic in salsa20_ref.c 28 | uint8ptr_wrapped_ty *c, // MUTABLE, SECRET (buffer) 29 | uint8ptr_wrapped_ty *m, // SECRET (buffer) 30 | secret uint8_t n[8], 31 | uint64_t ic_val, 32 | secret uint8_t k[32] 33 | ); 34 | 35 | #endif // SALSA20_H_ 36 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/donna/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/curve25519_c64.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | 7 | #ifdef ENABLE_MEASURE_TIME 8 | #include 9 | #include 10 | 11 | #define _NS_PER_SECO_ND 1000000000 12 | #define INLINE __attribute__((__always_inline__)) inline 13 | INLINE uint64_t nanoseconds(struct timespec t) { 14 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 15 | } 16 | #endif 17 | 18 | int main() { 19 | secret uint8_t data[32]; 20 | read(0, data, 32); 21 | 22 | // Mark input as secret for ct_grind check: 23 | ct_secret(data, sizeof(uint8_t) * 32); 24 | 25 | uint8_t out[32] = {0}; 26 | uint8_t ret = 0; 27 | 28 | uint8_t basepoint[32] = {9}; 29 | 30 | #ifdef ENABLE_MEASURE_TIME 31 | struct timespec start, end; 32 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 33 | #endif 34 | 35 | curve25519_donna(out, data, basepoint); 36 | 37 | #ifdef ENABLE_MEASURE_TIME 38 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 39 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 40 | printf("\nTime: %ld\n", delta); 41 | #endif 42 | 43 | memcpy(data, out, 32); 44 | ret ^= out[0]; 45 | write(1, &ret, 1); 46 | } 47 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/mu.h" 2 | #include "../../include/taint.h" 3 | 4 | #include 5 | #include 6 | 7 | #ifdef ENABLE_MEASURE_TIME 8 | #include 9 | #include 10 | 11 | #define _NS_PER_SECO_ND 1000000000 12 | #define INLINE __attribute__((__always_inline__)) inline 13 | INLINE uint64_t nanoseconds(struct timespec t) { 14 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 15 | } 16 | #endif 17 | 18 | int main() { 19 | secret int32_t a[3]; 20 | 21 | /* for (int i = 0; i < 3; i++) scanf("%d", &a[i]); */ 22 | 23 | // Read like Constantine: 24 | read(0, a, sizeof(int32_t) * 3); 25 | 26 | // Mark input as secret for ct_grind check: 27 | ct_secret(a, sizeof(int32_t) * 3); 28 | 29 | #ifdef ENABLE_MEASURE_TIME 30 | struct timespec start, end; 31 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 32 | #endif 33 | 34 | mu(a); 35 | 36 | #ifdef ENABLE_MEASURE_TIME 37 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 38 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 39 | printf("\nTime: %ld\n", delta); 40 | #endif 41 | 42 | /* printf("%d\t%d\t%d\n", a[0], a[1], a[2]); */ 43 | 44 | // Write like Constantine: 45 | write(1, a, sizeof(int32_t) * 3); 46 | } 47 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/des/include/des.h: -------------------------------------------------------------------------------- 1 | #ifndef DES_H 2 | #define DES_H 3 | 4 | #define EN0 0 /* MODE == encrypt */ 5 | #define DE1 1 /* MODE == decrypt */ 6 | 7 | typedef struct { 8 | unsigned long ek[32]; 9 | unsigned long dk[32]; 10 | } des_ctx; 11 | 12 | void deskey(unsigned char *, short); 13 | /* hexkey[8] MODE 14 | * Sets the internal key register according to the hexadecimal 15 | * key contained in the 8 bytes of hexkey, according to the DES, 16 | * for encryption or decryption according to MODE. 17 | */ 18 | void usekey(unsigned long *); 19 | /* cookedkey[32] 20 | * Loads the internal key register with the data in cookedkey. 21 | */ 22 | void cpkey(unsigned long *); 23 | /* cookedkey[32] 24 | * Copies the contents of the internal key register into the storage 25 | * located at &cookedkey[0]. 26 | */ 27 | void des(unsigned char *, unsigned char *); 28 | /* from[8] to[8] 29 | * Encrypts/Decrypts (according to the key currently loaded in the 30 | * internal key register) one block of eight bytes at address 鈥榝rom->* into 31 | * the block at address 鈥榯o-> They can be the same. 32 | */ 33 | void scrunch(unsigned char *, unsigned long *); 34 | void unscrun(unsigned long *, unsigned char *); 35 | void desfunc(unsigned long *, unsigned long *); 36 | void cookey(unsigned long *); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/include/3way.h: -------------------------------------------------------------------------------- 1 | #ifndef _3WAY_H 2 | #define _3WAY_H 3 | 4 | #include 5 | 6 | #define STRT_E 0x0b0b /* round constant of first encryption round */ 7 | #define STRT_D 0xb1b1 /* round constant of first decryption round */ 8 | #define NMBR 11 /* number of rounds is 11 */ 9 | 10 | typedef struct { 11 | int32_t k[3], ki[3], ercon[NMBR + 1], drcon[NMBR + 1]; 12 | } twy_ctx; 13 | /* Note: encrypt and decrypt expect full blocks--padding blocks is 14 | caller’s responsibility. All bulk encryption is done in 15 | ECB mode by these calls. Other modes may be added easily 16 | enough. */ 17 | /* destroy: Context. */ 18 | /* Scrub context of all sensitive data. */ 19 | void twy_destroy(twy_ctx *); 20 | /* encrypt: Context, ptr to data block, # of blocks. */ 21 | void twy_enc(twy_ctx *, int32_t *, int); 22 | /* decrypt: Context, ptr to data block, # of blocks. */ 23 | void twy_dec(twy_ctx *, int32_t *, int); 24 | /* key: Context, ptr to key data. */ 25 | void twy_key(int32_t *, twy_ctx *); 26 | /* ACCODE----------------------------------------------------------- */ 27 | /* End of AC code prototypes and structures. */ 28 | /* ----------------------------------------------------------------- */ 29 | 30 | void encrypt(twy_ctx *c, int32_t *a); 31 | void decrypt(twy_ctx *c, int32_t *a); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /prototype/package.yaml: -------------------------------------------------------------------------------- 1 | name: lif-lang 2 | version: 0.1.0.0 3 | github: "luigidcsoares/lif/tree/master/lang" 4 | license: GPL-3 5 | license-file: LICENSE.txt 6 | author: "Luigi D. C. Soares" 7 | maintainer: "luigidcsoares@gmail.com" 8 | copyright: "2020 Luigi D. C. Soares" 9 | 10 | extra-source-files: 11 | - README.md 12 | 13 | # Metadata used when publishing your package 14 | # synopsis: Short description of your package 15 | # category: Web 16 | 17 | # To avoid duplicated efforts in documentation and dealing with the 18 | # complications of embedding Haddock markup inside cabal files, it is 19 | # common to point users to the README.md file. 20 | description: Please see the README on GitHub at 21 | 22 | dependencies: 23 | - base >= 4.7 && < 5 24 | - containers 25 | - parsec 26 | - mtl 27 | - aeson 28 | - bytestring 29 | - hspec 30 | 31 | library: 32 | source-dirs: src 33 | 34 | executables: 35 | lif-exe: 36 | main: Main.hs 37 | source-dirs: app 38 | ghc-options: 39 | - -threaded 40 | - -rtsopts 41 | - -with-rtsopts=-N 42 | dependencies: 43 | - lif-lang 44 | 45 | tests: 46 | lif-test: 47 | main: Spec.hs 48 | source-dirs: test 49 | ghc-options: 50 | - -threaded 51 | - -rtsopts 52 | - -with-rtsopts=-N 53 | dependencies: 54 | - lif-lang 55 | -------------------------------------------------------------------------------- /prototype/src/Internal/Constraint.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ExistentialQuantification #-} 2 | {-# LANGUAGE ScopedTypeVariables #-} 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Internal.Constraint 6 | -- Copyright : (c) Luigi D. C. Soares 2020 7 | -- License : GPL-3 8 | -- 9 | -- Maintainer : luigidcsoares@gmail.com 10 | -- Stability : experimental 11 | -- Portability : portable 12 | ---------------------------------------------------------------------------- 13 | module Internal.Constraint where 14 | 15 | import qualified Data.Map as Map 16 | 17 | -- | Solve a constraint system using chaotic iterations method. 18 | -- 19 | -- Takes a queue of items to be analyzed, a function to be applied 20 | -- to each item, and a map key x result corresponding to the initial 21 | -- state, where result is an element of a (semi) lattice. 22 | -- 23 | -- The function 'f' should return the updated map as well as a boolean 24 | -- indicating whether some change happened or not. 25 | -- 26 | -- Returns a final map after reaching a fixed point. 27 | solve 28 | :: forall a b c 29 | . [a] 30 | -> (a -> Map.Map b c -> (Map.Map b c, Bool)) 31 | -> Map.Map b c 32 | -> Map.Map b c 33 | solve xs f = go xs [] 34 | where 35 | go :: [a] -> [a] -> Map.Map b c -> Map.Map b c 36 | go [] _ m = m 37 | go (y : ys) ys' m | changed = go (ys ++ y : ys') [] m' 38 | | otherwise = go ys (y : ys') m' 39 | where (m', changed) = f y m 40 | -------------------------------------------------------------------------------- /lif/test/README.md: -------------------------------------------------------------------------------- 1 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 2 | ![stability-wip](https://img.shields.io/badge/stability-work_in_progress-lightgrey.svg) 3 | 4 | # Test Framework 5 | 6 | We implemented a test framework to check if the transformed programs are 7 | correct. The benchmarks can be found at the folder `benchmarks/`. There's 8 | a list with the paths of all benchmarks in the file `benchmarks.txt`. 9 | The test framework is implemented in `Clojure`, with the help of 10 | [`babashka`](https://github.com/babashka/babashka). We're currently using 11 | versions 1.10.3.1040 of Clojure and 0.3.7 of babashka. 12 | 13 | The scrip accepts a flag `--help` that shows detailed information on 14 | how to use it: 15 | 16 | ``` sh 17 | $ bb run.clj --help 18 | ``` 19 | 20 | To compile a single benchmark: 21 | 22 | ``` sh 23 | $ bb run.clj compile -b path/to/benchmark 24 | ``` 25 | 26 | To run a single benchmark and check its output: 27 | 28 | ``` sh 29 | $ bb run.clj verify -b path/to/benchmark 30 | ``` 31 | 32 | To compile and run at the same time: 33 | 34 | ``` sh 35 | $ bb run.clj both -b path/to/benchmark 36 | ``` 37 | 38 | To perform an action on every benchmark listed in a file: 39 | 40 | ``` sh 41 | $ bb run.clj -f benchmarks.txt 42 | ``` 43 | 44 | The folder of every benchmarks must contain: 45 | 46 | 1. A lib folder with the source code; 47 | 2. An include folder with the headers; 48 | 3. A main folder with a main.c file; 49 | 4. An input folder with n > 0 files; and 50 | 5. A config.yaml file with the tainted arguments. 51 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/dijkstra.h" 2 | 3 | #include 4 | 5 | #ifdef ENABLE_MEASURE_TIME 6 | #include 7 | #include 8 | 9 | #define _NS_PER_SECO_ND 1000000000 10 | #define INLINE __attribute__((__always_inline__)) inline 11 | INLINE uint64_t nanoseconds(struct timespec t) { 12 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 13 | } 14 | #endif 15 | 16 | int x; 17 | int main() { 18 | read(0, &x, sizeof(int)); 19 | x -= (unsigned char) x; 20 | 21 | // Mark input as secret for ct_grind check: 22 | ct_secret(x, sizeof(int)); 23 | 24 | // Graph edges (distance): 25 | secret int in[INPUT_SIZE][INPUT_SIZE]; 26 | 27 | for (int i = 0; i < INPUT_SIZE; i++) { 28 | for (int j = 0; j < INPUT_SIZE; j++) { 29 | // Constantine will taint this, due to "read", so let's just 30 | // consider log as secret too... 31 | read(0, &in[i][j], sizeof(int)); 32 | } 33 | } 34 | 35 | // Mark input as secret for ct_grind check: 36 | ct_secret(&x, sizeof(int)); 37 | ct_secret(in, INPUT_SIZE * INPUT_SIZE * sizeof(int)); 38 | 39 | #ifdef ENABLE_MEASURE_TIME 40 | struct timespec start, end; 41 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 42 | #endif 43 | 44 | int r = dijkstra(INPUT_SIZE, 0, INPUT_SIZE - 1, in); 45 | 46 | #ifdef ENABLE_MEASURE_TIME 47 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 48 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 49 | printf("\nTime: %ld\n", delta); 50 | #endif 51 | 52 | write(1, &r, sizeof(int)); 53 | } 54 | -------------------------------------------------------------------------------- /lif/README.md: -------------------------------------------------------------------------------- 1 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 2 | ![stability-wip](https://img.shields.io/badge/stability-work_in_progress-lightgrey.svg) 3 | 4 | ## Requirements 5 | - CMake >= 3.18.4 6 | - LLVM == 13.0.0 7 | - Clang >= 13.0.0 8 | - A generator for CMake (GNU Make, Ninja, etc) 9 | 10 | ## Build 11 | This project is built with CMake. You can choose the generator you prefer. You 12 | also need to set the path for the LLVM install directory. The following 13 | commands illustrate the building process: 14 | 15 | ``` 16 | $ cd /path/to/lif/ 17 | $ cmake -DLLVM_INSTALL_DIR="/usr" -G Ninja -B build/ . 18 | $ ninja -C build 19 | ``` 20 | 21 | ## Usage 22 | `$ bin/lif [options] -o ` 23 | 24 | First, you need to generate an LLVM IR representation of some source code. 25 | For that, you can proceed as follows: 26 | 27 | #### **`comp.c`** 28 | ``` c 29 | #include 30 | 31 | int comp(int *a, int *b, int n) { 32 | for (int i = 0; i < n; i++) { 33 | // "b" is secret => conditional is tainted 34 | if (a[i] != b[i]) return 0; 35 | } 36 | return 1; 37 | } 38 | 39 | int main() { 40 | int a[4] = {0, 0, 0, 0}; 41 | // Define array "b" as secret 42 | __attribute__((annotate("secret"))) int b[4] = {0, 0, 0, 0}; 43 | printf("%d\n", comp(a, b, 4)); 44 | return 0; 45 | } 46 | ``` 47 | 48 | ``` 49 | $ clang -S -emit-llvm -Xclang -disable-O0-optnone comp.c -o comp.ll 50 | ``` 51 | 52 | ## Options 53 | - `o=`: Transformed module 54 | - `O<0..3>`: Optimization level 55 | -------------------------------------------------------------------------------- /lif/test/benchmarks/log-redactor/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/log_redactor.h" 2 | #include "../../include/taint.h" 3 | 4 | #include 5 | #include 6 | 7 | #ifdef ENABLE_MEASURE_TIME 8 | #include 9 | #include 10 | 11 | #define _NS_PER_SECO_ND 1000000000 12 | #define INLINE __attribute__((__always_inline__)) inline 13 | INLINE uint64_t nanoseconds(struct timespec t) { 14 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 15 | } 16 | #endif 17 | 18 | int main () { 19 | #ifndef ENABLE_UNROLL 20 | const unsigned L0 = 3; 21 | const unsigned L1 = 10; 22 | const unsigned P = 4; 23 | #endif 24 | 25 | secret char *log[L0]; 26 | secret char pattern[P]; 27 | 28 | for (unsigned i = 0; i < L0; i++) { 29 | log[i] = (char *) malloc(L1); 30 | // Constantine will taint this, due to "read", so let's just 31 | // consider log as secret too... 32 | read(0, log[i], L1); 33 | } 34 | 35 | read(0, pattern, P); 36 | 37 | // Mark input as secret for ct_grind check: 38 | ct_secret(pattern, sizeof(char) * P); 39 | ct_secret(log, sizeof(char) * L0 * L1); 40 | 41 | #ifdef ENABLE_MEASURE_TIME 42 | struct timespec start, end; 43 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 44 | #endif 45 | 46 | #ifdef ENABLE_UNROLL 47 | log_redactor(log, pattern); 48 | #else 49 | log_redactor(log, pattern, L0, L1, P); 50 | #endif 51 | 52 | #ifdef ENABLE_MEASURE_TIME 53 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 54 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 55 | printf("\nTime: %ld\n", delta); 56 | #endif 57 | 58 | for (unsigned j = 0; j < L0; j++) { 59 | // Write like Constantine: 60 | write(1, log[j], L1); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/input/2.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 63 5 15 9 84 84 76 33 90 98 79 38 91 93 20 65 57 55 33 39 53 53 16 63 16 91 3 | 45 62 17 8 23 12 13 39 53 97 23 61 31 13 60 42 84 83 36 36 80 25 23 14 65 4 | 77 99 81 40 15 4 85 9 53 93 33 66 39 72 51 36 27 13 99 73 73 42 89 88 10 5 | 25 68 35 48 14 32 57 46 45 97 61 81 15 71 35 40 36 33 79 40 84 48 67 29 47 6 | 72 34 21 61 22 31 18 23 67 67 69 31 24 15 77 54 9 58 1 12 25 41 48 58 21 88 7 | 75 69 87 36 48 60 71 70 53 25 1 72 80 0 71 50 32 27 97 41 81 6 99 14 18 25 8 | 56 98 15 9 18 22 10 6 91 58 98 62 60 51 19 94 23 0 94 26 50 58 54 79 99 67 9 | 86 31 82 36 88 38 67 35 79 85 90 89 23 81 79 21 75 40 73 94 34 28 26 60 55 10 | 8 51 41 88 82 8 6 13 22 42 33 92 41 1 71 27 91 60 50 4 40 72 11 12 77 37 46 11 | 5 64 38 92 4 89 33 92 72 74 98 17 96 73 51 89 14 52 92 73 75 53 24 11 25 28 12 | 22 37 5 59 15 42 55 85 67 60 75 0 84 79 6 15 96 3 88 79 24 34 63 16 8 38 1 13 | 64 49 58 92 3 27 29 95 74 3 82 60 70 42 67 71 59 46 9 74 42 12 94 22 68 28 14 | 85 17 68 56 50 64 37 41 56 41 68 17 68 43 21 50 35 91 25 2 94 84 48 4 58 15 | 22 48 52 44 49 12 62 66 81 18 48 45 87 89 34 60 90 83 28 65 4 79 0 28 4 34 16 | 22 88 82 26 78 4 75 30 81 56 74 75 22 55 93 2 33 12 92 99 73 82 14 1 47 19 17 | 12 79 47 48 13 1 68 95 28 46 31 35 8 44 91 83 19 45 70 44 47 35 57 71 66 18 | 30 85 81 63 32 32 8 43 11 88 56 12 57 83 40 35 15 7 76 59 30 91 11 7 61 55 19 | 87 29 12 58 95 74 44 8 70 8 40 78 52 51 98 40 64 55 24 36 23 39 76 99 30 20 | 38 90 41 46 83 97 33 12 41 23 40 16 99 48 18 40 21 28 92 72 26 32 68 14 88 21 | 5 69 27 13 68 90 51 90 63 97 5 60 62 50 34 18 90 82 17 70 0 57 91 60 81 96 22 | 86 46 64 32 34 1 1 94 14 69 84 66 91 47 95 29 40 90 79 6 8 69 88 25 71 20 23 | 15 63 80 28 59 66 74 55 99 9 57 0 35 71 2 51 69 25 98 97 54 24 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/hash-one/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/comp.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef ENABLE_MEASURE_TIME 9 | #include 10 | #include 11 | 12 | #define _NS_PER_SECO_ND 1000000000 13 | #define INLINE __attribute__((__always_inline__)) inline 14 | INLINE uint64_t nanoseconds(struct timespec t) { 15 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 16 | } 17 | #endif 18 | 19 | int main() { 20 | int n, m; 21 | 22 | // For constantine, we will need another way to define n and m; 23 | // otherwise, "read" will taint them. 24 | read(0, &n, sizeof(int)); 25 | read(0, &m, sizeof(int)); 26 | 27 | int *a = (int *) malloc(n * sizeof(int)); 28 | secret int *b = (int *) malloc(n * sizeof(int)); 29 | 30 | /* for (int i = 0; i < n ; i++) scanf("%d", &a[i]); */ 31 | /* for (int i = 0; i < n ; i++) scanf("%d", &b[i]); */ 32 | 33 | // Read like Constantine: 34 | read(0, a, sizeof(int) * n); 35 | read(0, b, sizeof(int) * n); 36 | 37 | // Mark input as secret for ct_grind check: 38 | ct_secret(b, sizeof(int) * n); 39 | 40 | /* printf("%d\n", comp(a, b, m)); */ 41 | 42 | #ifdef ENABLE_MEASURE_TIME 43 | struct timespec start, end; 44 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 45 | #endif 46 | 47 | #ifdef ENABLE_UNROLL 48 | int r = comp(a, b); 49 | #else 50 | int r = comp(a, b, m); 51 | #endif 52 | 53 | #ifdef ENABLE_MEASURE_TIME 54 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 55 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 56 | printf("\nTime: %ld\n", delta); 57 | #endif 58 | 59 | // Write like Constantine: 60 | write(1, &r, sizeof(int)); 61 | } 62 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/comp.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef ENABLE_MEASURE_TIME 9 | #include 10 | #include 11 | 12 | #define _NS_PER_SECO_ND 1000000000 13 | #define INLINE __attribute__((__always_inline__)) inline 14 | INLINE uint64_t nanoseconds(struct timespec t) { 15 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 16 | } 17 | #endif 18 | 19 | int main() { 20 | int n, m; 21 | 22 | // For constantine, we will need another way to define n and m; 23 | // otherwise, "read" will taint them. 24 | read(0, &n, sizeof(int)); 25 | read(0, &m, sizeof(int)); 26 | 27 | int *a = (int *) malloc(n * sizeof(int)); 28 | secret int *b = (int *) malloc(n * sizeof(int)); 29 | 30 | /* for (int i = 0; i < n ; i++) scanf("%d", &a[i]); */ 31 | /* for (int i = 0; i < n ; i++) scanf("%d", &b[i]); */ 32 | 33 | // Read like Constantine: 34 | read(0, a, sizeof(int) * n); 35 | read(0, b, sizeof(int) * n); 36 | 37 | // Mark input as secret for ct_grind check: 38 | ct_secret(b, sizeof(int) * n); 39 | 40 | /* printf("%d\n", comp(a, b, m)); */ 41 | 42 | #ifdef ENABLE_MEASURE_TIME 43 | struct timespec start, end; 44 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 45 | #endif 46 | 47 | #ifdef ENABLE_UNROLL 48 | int r = comp(a, b); 49 | #else 50 | int r = comp(a, b, m); 51 | #endif 52 | 53 | #ifdef ENABLE_MEASURE_TIME 54 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 55 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 56 | printf("\nTime: %ld\n", delta); 57 | #endif 58 | 59 | // Write like Constantine: 60 | write(1, &r, sizeof(int)); 61 | } 62 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/cast5.h" 2 | #include "../../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef ENABLE_MEASURE_TIME 11 | #include 12 | #include 13 | 14 | #define _NS_PER_SECO_ND 1000000000 15 | #define INLINE __attribute__((__always_inline__)) inline 16 | INLINE uint64_t nanoseconds(struct timespec t) { 17 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 18 | } 19 | #endif 20 | 21 | int main() { 22 | secret uint8_t in_key[32]; 23 | secret uint8_t in[64]; 24 | 25 | /* for (int i = 0; i < 32; i++) scanf("%" SCNu8, &in_key[i]); */ 26 | /* for (int i = 0; i < 64; i++) scanf("%" SCNu8, &in[i]); */ 27 | 28 | // Read like Constantine: 29 | read(0, in_key, sizeof(uint8_t) * 32); 30 | read(0, in, sizeof(uint8_t) * 64); 31 | 32 | // Mark input as secret for ct_grind check: 33 | ct_secret(in_key, sizeof(uint8_t) * 32); 34 | ct_secret(in, sizeof(uint8_t) * 64); 35 | 36 | struct cast5_ctx ctx; 37 | 38 | uint8_t out[64] = {0}; 39 | 40 | #ifdef ENABLE_MEASURE_TIME 41 | struct timespec start, end; 42 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 43 | #endif 44 | 45 | cast5_setkey(in_key, &ctx, 16); 46 | cast5_encrypt(&ctx, out, in, ctx.rr); 47 | 48 | #ifdef ENABLE_MEASURE_TIME 49 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 50 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 51 | printf("\nTime: %ld\n", delta); 52 | #endif 53 | 54 | /* for (size_t i = 0; i < 64; i++) printf("%d ", out[i]); */ 55 | /* printf("\n"); */ 56 | 57 | // Write like Constantine: 58 | write(1, out, sizeof(uint8_t) * 64); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /prototype/src/Flow/DomTree.hs: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- | 3 | -- Module : Flow.DomTree 4 | -- Copyright : (c) Luigi D. C. Soares 2020 5 | -- License : GPL-3 6 | -- 7 | -- Maintainer : luigidcsoares@gmail.com 8 | -- Stability : experimental 9 | -- Portability : portable 10 | ---------------------------------------------------------------------------- 11 | module Flow.DomTree 12 | ( Node(..) 13 | , Context 14 | , Edge 15 | , DomTree 16 | , mkDomTree 17 | , dot 18 | ) 19 | where 20 | 21 | import Data.Maybe ( fromJust ) 22 | import Data.Tuple ( swap ) 23 | 24 | import qualified Flow.Cfg as Cfg 25 | import qualified Internal.Dot as Dot 26 | import qualified Internal.Graph as Graph 27 | import Core.Lang ( showStm ) 28 | import Flow.Block ( Block(..) ) 29 | 30 | newtype Node = Node {node :: Block} deriving (Eq, Ord, Show) 31 | instance Dot.Dot Node where 32 | label = show . label . node 33 | stringify = unwords . map ((++ "\\l") . showStm) . block . node 34 | 35 | type Context = Graph.Context Node 36 | type Edge = Graph.Edge Node 37 | type DomTree = Graph.Graph Node 38 | 39 | mkDomTree :: Cfg.Node -> Cfg.Cfg -> DomTree 40 | mkDomTree root cfg = Graph.mkGraph vs es 41 | where 42 | mkNode :: Cfg.Node -> Node 43 | mkNode = Node . Cfg.block . fromJust . fst . (`Graph.match` cfg) 44 | (from, to) = unzip $ map swap $ Graph.iDom root cfg 45 | es = zip (map mkNode from) (map mkNode to) 46 | vs = Graph.dfs (Node . Cfg.block) root cfg 47 | 48 | dot :: Node -> DomTree -> String 49 | dot = Dot.dot (`Dot.formatNode` "") Dot.formatAdj "digraph \"Dominance Tree\" " 50 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/loki91.h" 2 | #include "../../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef ENABLE_MEASURE_TIME 9 | #include 10 | #include 11 | 12 | #define _NS_PER_SECO_ND 1000000000 13 | #define INLINE __attribute__((__always_inline__)) inline 14 | INLINE uint64_t nanoseconds(struct timespec t) { 15 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 16 | } 17 | #endif 18 | 19 | int main(void) { 20 | secret unsigned char in[8]; 21 | secret unsigned char in_key[24]; 22 | 23 | /* for (int i = 0; i < 8; i++) { */ 24 | /* int x; */ 25 | /* scanf("%x", &x); */ 26 | /* key[i] = (uint8_t) x; */ 27 | /* } */ 28 | 29 | /* for (int i = 0; i < 24; i++) { */ 30 | /* int x; */ 31 | /* scanf("%d", &x); */ 32 | /* data[i] = (unsigned char) x; */ 33 | /* } */ 34 | 35 | // Read like Constantine: 36 | read(0, in, sizeof(unsigned char) * 8); 37 | read(0, in_key, sizeof(unsigned char) * 24); 38 | 39 | // Mark input as secret for ct_grind check: 40 | ct_secret(in, 3); 41 | ct_secret(in_key, 3); 42 | 43 | loki_ctx lc; 44 | 45 | #ifdef ENABLE_MEASURE_TIME 46 | struct timespec start, end; 47 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 48 | #endif 49 | 50 | setlokikey(in_key, &lc); 51 | enloki(&lc, in); 52 | 53 | #ifdef ENABLE_MEASURE_TIME 54 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 55 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 56 | printf("\nTime: %ld\n", delta); 57 | #endif 58 | 59 | /* for (size_t i = 0; i < 24; i++) printf("%d ", data[i]); */ 60 | /* printf("\n"); */ 61 | 62 | // Write like Constantine: 63 | write(1, in, sizeof(unsigned char) * 8); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/crypto_secretbox.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #define _NS_PER_SECO_ND 1000000000 14 | #define INLINE __attribute__((__always_inline__)) inline 15 | INLINE uint64_t nanoseconds(struct timespec t) { 16 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 17 | } 18 | 19 | int main() { 20 | uint8ptr_wrapped_ty c; 21 | uint8ptr_wrapped_ty m; 22 | 23 | c.len = 163; 24 | c.buf = (uint8_t *)malloc(c.len * sizeof(uint8_t)); 25 | 26 | m.len = 163; 27 | m.buf = (uint8_t *)malloc(m.len * sizeof(uint8_t)); 28 | 29 | uint8_t nonce[24]; 30 | uint8_t data[32]; 31 | 32 | // API requires first 32 bytes to be 0 33 | memset(m.buf, 0, 32); 34 | 35 | read(0, m.buf + 32, (m.len - 32) * sizeof(uint8_t)); 36 | read(0, nonce, sizeof nonce); 37 | read(0, data, sizeof data); 38 | 39 | // Mark input as secret for ct_grind check: 40 | ct_secret(c.buf, sizeof(uint8_t) * c.len); 41 | ct_secret(m.buf, sizeof(uint8_t) * m.len); 42 | ct_secret(data, sizeof data); 43 | 44 | #ifdef ENABLE_MEASURE_TIME 45 | struct timespec start, end; 46 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 47 | #endif 48 | 49 | bool r1 = __crypto_secretbox(&c, &m, nonce, data); 50 | bool r2 = __crypto_secretbox_open(&m, &c, nonce, data); 51 | 52 | #ifdef ENABLE_MEASURE_TIME 53 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 54 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 55 | printf("\nTime: %ld\n", delta); 56 | #endif 57 | 58 | /* printf("%d -- %d\n", r1, r2); */ 59 | write(1, &r1, sizeof(bool)); 60 | write(1, &r2, sizeof(bool)); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-many/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/comp.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef ENABLE_MEASURE_TIME 9 | #include 10 | #include 11 | 12 | #define _NS_PER_SECO_ND 1000000000 13 | #define INLINE __attribute__((__always_inline__)) inline 14 | INLINE uint64_t nanoseconds(struct timespec t) { 15 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 16 | } 17 | #endif 18 | 19 | int main() { 20 | int n, m; 21 | 22 | // For constantine, we will need another way to define n and m; 23 | // otherwise, "read" will taint them. 24 | read(0, &n, sizeof(int)); 25 | read(0, &m, sizeof(int)); 26 | 27 | int **a = (int **) malloc(5 * sizeof(int *)); 28 | for (int i = 0; i < 5; i++) a[i] = (int *) malloc(n * sizeof(int)); 29 | 30 | secret int *b = (int *) malloc(n * sizeof(int)); 31 | 32 | /* for (int i = 0; i < n ; i++) scanf("%d", &a[i]); */ 33 | /* for (int i = 0; i < n ; i++) scanf("%d", &b[i]); */ 34 | 35 | // Read like Constantine: 36 | for (int i = 0; i < 5; i++) read(0, a[i], sizeof(int) * n); 37 | read(0, b, sizeof(int) * n); 38 | 39 | // Mark input as secret for ct_grind check: 40 | ct_secret(b, sizeof(int) * n); 41 | 42 | /* printf("%d\n", comp(a, b, 5, m)); */ 43 | 44 | #ifdef ENABLE_MEASURE_TIME 45 | struct timespec start, end; 46 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 47 | #endif 48 | 49 | #ifdef ENABLE_UNROLL 50 | int r = comp(a, b); 51 | #else 52 | int r = comp(a, b, 5, m); 53 | #endif 54 | 55 | #ifdef ENABLE_MEASURE_TIME 56 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 57 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 58 | printf("\nTime: %ld\n", delta); 59 | #endif 60 | 61 | // Write like Constantine: 62 | write(1, &r, sizeof(int)); 63 | } 64 | -------------------------------------------------------------------------------- /lif/test/compile.clj: -------------------------------------------------------------------------------- 1 | (require '[clojure.java.shell :as shell]) 2 | 3 | (defn emit-asm 4 | "Takes a LLVM IR file and converts to asm. It also takes a 5 | name for the output file, as well as additional arguments." 6 | [src out & args] 7 | (apply shell/sh "llc" "-filetype=asm" src "-o" out args)) 8 | 9 | (defn emit-bin 10 | "Takes an assembly file and produces an executable from it, with 11 | debug information. It also takes a name for the output file." 12 | [src out & args] 13 | (apply shell/sh "clang" src "-o" out "-no-pie" args)) 14 | 15 | (defn emit-llvm 16 | "Takes a source file and compiles it to its LLVM IR representation. 17 | The only optimization applied is --mem2reg, to promote memory to register. 18 | It also takes a name for the output file." 19 | [src out & args] 20 | (let [{:keys [exit] :as clang-result} 21 | (apply shell/sh "clang" src "-o" out "-emit-llvm" "-S" "-Xclang" 22 | "-disable-O0-optnone" "-fno-discard-value-names" args)] 23 | (if (zero? exit) 24 | (shell/sh "opt" "-S" "-mem2reg" out "-o" out) 25 | clang-result))) 26 | 27 | (defn llvm-link 28 | "Takes a list of LLVM IR files and links them together into a 29 | single LLVM IR file. It also takes a name for the output file." 30 | [srcs out] 31 | (apply shell/sh "llvm-link" "-S" "-o" out srcs)) 32 | 33 | (defn opt 34 | "Takes a LLVM IR file and a sequence of optimization flags. It 35 | also takes a name for the output file." 36 | [src out & args] 37 | (apply shell/sh "opt" src "-o" out "-S" args)) 38 | 39 | (defn lif 40 | "Takes a LLVM IR file, a name for the output file, and an (optional) 41 | optimization level (integer 0, 1, 2, or 3)." 42 | ([src out opt] 43 | (let [;; TODO: change for a non-hardcoded path. 44 | lif-bin "/home/luigi/workspace/lif/lif/bin/lif"] 45 | (shell/sh lif-bin src (str "-O" opt) "-o" out))) 46 | ([src out] (lif src out 0))) 47 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/des/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/des.h" 2 | #include "../../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef ENABLE_MEASURE_TIME 10 | #include 11 | #include 12 | 13 | #define _NS_PER_SECO_ND 1000000000 14 | #define INLINE __attribute__((__always_inline__)) inline 15 | INLINE uint64_t nanoseconds(struct timespec t) { 16 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 17 | } 18 | #endif 19 | 20 | int main() { 21 | secret uint8_t in_key[32]; 22 | secret unsigned char in[8]; 23 | 24 | /* for (int i = 0; i < 32; i++) { */ 25 | /* int x; */ 26 | /* scanf("%d", &x); */ 27 | /* in_key[i] = (uint8_t) x; */ 28 | /* } */ 29 | 30 | /* for (int i = 0; i < 8; i++) { */ 31 | /* int x; */ 32 | /* scanf("%x", &x); */ 33 | /* in[i] = (unsigned char) x; */ 34 | /* } */ 35 | 36 | // Read like Constantine: 37 | read(0, in_key, sizeof(uint8_t) * 32); 38 | read(0, in, sizeof(unsigned char) * 8); 39 | 40 | // Mark input as secret for ct_grind check: 41 | ct_secret(in_key, 3); 42 | ct_secret(in, 3); 43 | 44 | unsigned char out[8] = {0}; 45 | 46 | des_ctx dc; 47 | unsigned long work[2] = {0}; 48 | 49 | #ifdef ENABLE_MEASURE_TIME 50 | struct timespec start, end; 51 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 52 | #endif 53 | 54 | // des_key(&dc,key); 55 | deskey(in_key, EN0); 56 | cpkey(dc.ek); 57 | scrunch(in, work); 58 | desfunc(dc.ek, work); 59 | unscrun(work, out); 60 | 61 | #ifdef ENABLE_MEASURE_TIME 62 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 63 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 64 | printf("\nTime: %ld\n", delta); 65 | #endif 66 | 67 | /* for (size_t i = 0; i < 8; i++) printf("%d ", out[i]); */ 68 | /* printf("\n"); */ 69 | 70 | // Write like Constantine: 71 | write(1, out, sizeof(unsigned char) * 8); 72 | } 73 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/lib/dijkstra.c: -------------------------------------------------------------------------------- 1 | #include "../include/dijkstra.h" 2 | #include "../../../../include/taint.h" 3 | 4 | int dijkstra(int n, int s, int t, int e[][INPUT_SIZE]) { 5 | // =========================================================== 6 | // || LIF: we should consider control dependence for pairs || 7 | // || of store + load, but we haven't implemented that yet. || 8 | // || Thus, we manually mark vis and dis as tainted. || 9 | // =========================================================== 10 | secret int vis[INPUT_SIZE] = {0}; 11 | secret int dis[INPUT_SIZE] = {0}; 12 | int bestj = -1; 13 | vis[s] = 1; 14 | 15 | // Mark arrays as secret for ct_grind check: 16 | ct_secret(vis, INPUT_SIZE * sizeof(int)); 17 | ct_secret(dis, INPUT_SIZE * sizeof(int)); 18 | 19 | #ifdef ENABLE_UNROLL 20 | for (int i = 0; i < INPUT_SIZE; ++i) dis[i] = e[s][i]; 21 | for (int i = 0; i < INPUT_SIZE; ++i) { 22 | for (int j = 0; j < INPUT_SIZE; ++j) { 23 | #else 24 | for (int i = 0; i < n; ++i) dis[i] = e[s][i]; 25 | for (int i = 0; i < n; ++i) { 26 | for (int j = 0; j < n; ++j) { 27 | #endif 28 | if (!vis[j] && (bestj < 0 || dis[j] < dis[bestj])) { 29 | bestj = j + x; // fix implicit flow here, x is secret (.h) 30 | // =========================================================== 31 | // || LIF: tainted due to control dependence. || 32 | // =========================================================== 33 | vis[bestj] = 1; 34 | } 35 | } 36 | 37 | #ifdef ENABLE_UNROLL 38 | for (int j = 0; j < INPUT_SIZE; ++j) { 39 | #else 40 | for (int j = 0; j < n; ++j) { 41 | #endif 42 | if (!vis[j] && (dis[bestj] + e[bestj][j] < dis[j])) { 43 | // =========================================================== 44 | // || LIF: tainted due to control dependence. || 45 | // =========================================================== 46 | dis[j] = dis[bestj] + e[bestj][j]; 47 | } 48 | } 49 | } 50 | return dis[t]; 51 | } 52 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/input/2.bin: -------------------------------------------------------------------------------- 1 | ? TTL!ZbO&[]A97!'55?[-> '5a= <*TS$$PAMcQ(U 5]!B'H3$ cII*YX 2 | D#0 9.-a=QG#($!O(T0C/H"=CCEM6 : )0:XKEW$0<GF5HPG2 a)Qc8b  3 | [:b><3^^2:6OcCVR$X&C#OUZYQOK(I^"<73)XR *!\)G[<2(H M%.@&\Y!\HJb`I3Y4\IK5 %;*7UC<KTO`XO"?&@1:\_JR<F*CG;. J* ^DUD82@%)8)DD+2#[^T0:04,1 >BQ0-WY"<ZSAO"XRNKQ8JK7]! \cIR/ O/0 D_.#,[S-F,/#9GBUQ? + X8 9S(#L;[ =7W :_J,F(N43b(@7$'Lc&Z).Sa! )(c0(\H DXE DZ3Z?a<>2"ZRF9[<Q`V.@ "^ETB[/_(ZOEXG?P;BJ7c 9#G3Eba6 -------------------------------------------------------------------------------- /lif/include/Transform/Isochronous.h: -------------------------------------------------------------------------------- 1 | //===-- Isochronous.h -------------------------------------------*- C++ -*-===// 2 | // Copyright (C) 2020 Luigi D. C. Soares 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | //===----------------------------------------------------------------------===// 17 | /// 18 | /// \file 19 | /// This file contains the declaration of the Isochronous Pass, which 20 | /// transforms some LLVM IR into a version that executes the same set 21 | /// of instructions regardless of the inputs. 22 | /// 23 | //===----------------------------------------------------------------------===// 24 | #ifndef LIF_TRANSFORM_ISOCHRONOUS_H 25 | #define LIF_TRANSFORM_ISOCHRONOUS_H 26 | 27 | #include 28 | #include 29 | 30 | namespace lif::transform { 31 | /// A pass that transforms a function into an isochronous version. 32 | /// 33 | /// An isochronous function executes the same set of instructions regardless of 34 | /// its inputs. Hence, this property can be used, e.g., for the mitigation of 35 | /// side channel leaks on a cryptography library. 36 | /// 37 | /// Requirement: functions must have unique exit points. 38 | class IsochronousPass : public llvm::PassInfoMixin { 39 | public: 40 | /// Traverses the module \p M transforming functions into isochronous 41 | /// versions. 42 | /// 43 | /// \returns the set of analyses preserved after running this pass. 44 | llvm::PreservedAnalyses run(llvm::Module &M, 45 | llvm::ModuleAnalysisManager &MAM); 46 | }; 47 | } // namespace lif::transform 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/llvm-ir/findmax.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/findmax.ll' 2 | source_filename = "lib/findmax.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @foo = dso_local global i32 0, align 4 7 | 8 | ; Function Attrs: noinline nounwind sspstrong uwtable 9 | define dso_local i32 @max(i32 noundef %n, i32* noundef %h) #0 { 10 | entry: 11 | br label %while.cond 12 | 13 | while.cond: ; preds = %if.end, %entry 14 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ] 15 | %m.0 = phi i32 [ 0, %entry ], [ %m.1, %if.end ] 16 | %cmp = icmp slt i32 %i.0, %n 17 | br i1 %cmp, label %while.body, label %while.end 18 | 19 | while.body: ; preds = %while.cond 20 | %idxprom = sext i32 %i.0 to i64 21 | %arrayidx = getelementptr inbounds i32, i32* %h, i64 %idxprom 22 | %0 = load i32, i32* %arrayidx, align 4 23 | %cmp1 = icmp sgt i32 %0, %m.0 24 | br i1 %cmp1, label %if.then, label %if.end 25 | 26 | if.then: ; preds = %while.body 27 | %idxprom2 = sext i32 %i.0 to i64 28 | %arrayidx3 = getelementptr inbounds i32, i32* %h, i64 %idxprom2 29 | %1 = load i32, i32* %arrayidx3, align 4 30 | br label %if.end 31 | 32 | if.end: ; preds = %if.then, %while.body 33 | %m.1 = phi i32 [ %1, %if.then ], [ %m.0, %while.body ] 34 | %inc = add nsw i32 %i.0, 1 35 | br label %while.cond, !llvm.loop !6 36 | 37 | while.end: ; preds = %while.cond 38 | ret i32 %m.0 39 | } 40 | 41 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 42 | 43 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 44 | !llvm.ident = !{!5} 45 | 46 | !0 = !{i32 1, !"wchar_size", i32 4} 47 | !1 = !{i32 7, !"PIC Level", i32 2} 48 | !2 = !{i32 7, !"PIE Level", i32 2} 49 | !3 = !{i32 7, !"uwtable", i32 1} 50 | !4 = !{i32 7, !"frame-pointer", i32 2} 51 | !5 = !{!"clang version 14.0.6"} 52 | !6 = distinct !{!6, !7} 53 | !7 = !{!"llvm.loop.mustprogress"} 54 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/include/crypto_poly1305.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTO_POLY1305_H_ 2 | #define CRYPTO_POLY1305_H_ 3 | 4 | #include "../../include/fact.h" 5 | #include "../../../include/taint.h" 6 | 7 | #include 8 | #include 9 | 10 | // using 64-bit implementation (poly1305_donna64.h) 11 | // #define poly1305_block_size 16 12 | typedef struct poly1305_state_internal_t { 13 | secret uint64_t r[3]; 14 | secret uint64_t h[3]; 15 | secret uint64_t pad[2]; 16 | uint64_t leftover; 17 | secret uint8_t buffer[16]; // poly1305_block_size 18 | secret uint8_t final; 19 | } poly1305_state_internal_t; 20 | 21 | // We annotate the indices of the arguments whose types we don't want 22 | // lif to wrap (because they're already wrapped). 23 | __attribute__((annotate("nowrap:1"))) 24 | void _poly1305_blocks( 25 | poly1305_state_internal_t *state, // MUTABLE 26 | uint8ptr_wrapped_ty *m // SECRET (buffer) 27 | ); 28 | 29 | void _poly1305_init( 30 | poly1305_state_internal_t *state, // MUTABLE 31 | secret uint8_t key[32] 32 | ); 33 | 34 | // We annotate the indices of the arguments whose types we don't want 35 | // lif to wrap (because they're already wrapped). 36 | __attribute__((annotate("nowrap:1"))) 37 | void _poly1305_update( 38 | poly1305_state_internal_t *state, // MUTABLE 39 | uint8ptr_wrapped_ty *m // SECRET (buffer) 40 | ); 41 | 42 | void _poly1305_finish( 43 | poly1305_state_internal_t *state, // MUTABLE 44 | secret uint8_t mac[16] 45 | ); 46 | 47 | // We annotate the indices of the arguments whose types we don't want 48 | // lif to wrap (because they're already wrapped). 49 | __attribute__((annotate("nowrap:1"))) 50 | int32_t _crypto_onetimeauth_poly1305( // crypto_onetimeauth_poly1305_donna from poly1305_donna.c 51 | secret uint8_t out[16], // MUTABLE 52 | uint8ptr_wrapped_ty *m, // SECRET (buffer) 53 | secret uint8_t key[32] 54 | ); 55 | 56 | // We annotate the indices of the arguments whose types we don't want 57 | // lif to wrap (because they're already wrapped). 58 | __attribute__((annotate("nowrap:1"))) 59 | bool _crypto_onetimeauth_poly1305_verify( // crypto_onetimeauth_poly1305_donna_verify from poly1305.c 60 | uint8_t h[16], 61 | uint8ptr_wrapped_ty *input, 62 | secret uint8_t k[32] 63 | ); 64 | 65 | #endif // CRYPTO_POLY1305_H_ 66 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/llvm-ir/findmax.ctgrind.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/findmax.ctgrind.ll' 2 | source_filename = "lib/findmax.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @foo = dso_local global i32 0, align 4 7 | 8 | ; Function Attrs: noinline nounwind sspstrong uwtable 9 | define dso_local i32 @max(i32 noundef %n, i32* noundef %h) #0 { 10 | entry: 11 | br label %while.cond 12 | 13 | while.cond: ; preds = %if.end, %entry 14 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ] 15 | %m.0 = phi i32 [ 0, %entry ], [ %m.1, %if.end ] 16 | %cmp = icmp slt i32 %i.0, %n 17 | br i1 %cmp, label %while.body, label %while.end 18 | 19 | while.body: ; preds = %while.cond 20 | %idxprom = sext i32 %i.0 to i64 21 | %arrayidx = getelementptr inbounds i32, i32* %h, i64 %idxprom 22 | %0 = load i32, i32* %arrayidx, align 4 23 | %cmp1 = icmp sgt i32 %0, %m.0 24 | br i1 %cmp1, label %if.then, label %if.end 25 | 26 | if.then: ; preds = %while.body 27 | %idxprom2 = sext i32 %i.0 to i64 28 | %arrayidx3 = getelementptr inbounds i32, i32* %h, i64 %idxprom2 29 | %1 = load i32, i32* %arrayidx3, align 4 30 | br label %if.end 31 | 32 | if.end: ; preds = %if.then, %while.body 33 | %m.1 = phi i32 [ %1, %if.then ], [ %m.0, %while.body ] 34 | %inc = add nsw i32 %i.0, 1 35 | br label %while.cond, !llvm.loop !6 36 | 37 | while.end: ; preds = %while.cond 38 | ret i32 %m.0 39 | } 40 | 41 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 42 | 43 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 44 | !llvm.ident = !{!5} 45 | 46 | !0 = !{i32 1, !"wchar_size", i32 4} 47 | !1 = !{i32 7, !"PIC Level", i32 2} 48 | !2 = !{i32 7, !"PIE Level", i32 2} 49 | !3 = !{i32 7, !"uwtable", i32 1} 50 | !4 = !{i32 7, !"frame-pointer", i32 2} 51 | !5 = !{!"clang version 14.0.6"} 52 | !6 = distinct !{!6, !7} 53 | !7 = !{!"llvm.loop.mustprogress"} 54 | -------------------------------------------------------------------------------- /prototype/stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by 'stack init' 2 | # 3 | # Some commonly used options have been documented as comments in this file. 4 | # For advanced use and comprehensive documentation of the format, please see: 5 | # https://docs.haskellstack.org/en/stable/yaml_configuration/ 6 | 7 | # Resolver to choose a 'specific' stackage snapshot or a compiler version. 8 | # A snapshot resolver dictates the compiler version and the set of packages 9 | # to be used for project dependencies. For example: 10 | # 11 | # resolver: lts-3.5 12 | # resolver: nightly-2015-09-21 13 | # resolver: ghc-7.10.2 14 | # 15 | # The location of a snapshot can be provided as a file or url. Stack assumes 16 | # a snapshot provided as a file might change, whereas a url resource does not. 17 | # 18 | # resolver: ./custom-snapshot.yaml 19 | # resolver: https://example.com/snapshots/2018-01-01.yaml 20 | resolver: lts-15.8 21 | 22 | # User packages to be built. 23 | # Various formats can be used as shown in the example below. 24 | # 25 | # packages: 26 | # - some-directory 27 | # - https://example.com/foo/bar/baz-0.0.2.tar.gz 28 | # subdirs: 29 | # - auto-update 30 | # - wai 31 | packages: 32 | - . 33 | # Dependency packages to be pulled from upstream that are not in the resolver. 34 | # These entries can reference officially published versions as well as 35 | # forks / in-progress versions pinned to a git hash. For example: 36 | # 37 | # extra-deps: 38 | # - acme-missiles-0.3 39 | # - git: https://github.com/commercialhaskell/stack.git 40 | # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a 41 | # 42 | # extra-deps: [] 43 | 44 | # Override default flag values for local packages and extra-deps 45 | # flags: {} 46 | 47 | # Extra package databases containing global packages 48 | # extra-package-dbs: [] 49 | 50 | # Control whether we use the GHC we find on the path 51 | # system-ghc: true 52 | # 53 | # Require a specific version of stack, using version ranges 54 | # require-stack-version: -any # Default 55 | # require-stack-version: ">=2.1" 56 | # 57 | # Override the architecture used by stack, especially useful on Windows 58 | # arch: i386 59 | # arch: x86_64 60 | # 61 | # Extra directories used by stack for building 62 | # extra-include-dirs: [/path/to/dir] 63 | # extra-lib-dirs: [/path/to/dir] 64 | # 65 | # Allow a newer minor version of GHC than the snapshot specifies 66 | # compiler-check: newer-minor 67 | -------------------------------------------------------------------------------- /prototype/lif-lang.cabal: -------------------------------------------------------------------------------- 1 | cabal-version: 1.12 2 | 3 | -- This file has been generated from package.yaml by hpack version 0.33.0. 4 | -- 5 | -- see: https://github.com/sol/hpack 6 | -- 7 | -- hash: 534e623f0a1d10fa91239a40b4816d5ba621c2e8e095701ee76ed13e2542b5a0 8 | 9 | name: lif-lang 10 | version: 0.1.0.0 11 | description: Please see the README on GitHub at 12 | homepage: https://github.com/luigidcsoares/lif/tree/master/lang#readme 13 | bug-reports: https://github.com/luigidcsoares/lif/tree/master/lang/issues 14 | author: Luigi D. C. Soares 15 | maintainer: luigidcsoares@gmail.com 16 | copyright: 2020 Luigi D. C. Soares 17 | license: GPL-3 18 | license-file: LICENSE.txt 19 | build-type: Simple 20 | extra-source-files: 21 | README.md 22 | 23 | source-repository head 24 | type: git 25 | location: https://github.com/luigidcsoares/lif/tree/master/lang 26 | 27 | library 28 | exposed-modules: 29 | Core.Error 30 | Core.Eval 31 | Core.Lang 32 | Core.Parser 33 | Flow.Block 34 | Flow.Cfg 35 | Flow.DomTree 36 | Internal.Constraint 37 | Internal.Dot 38 | Internal.Graph 39 | Internal.Map 40 | Pass.Invariant 41 | other-modules: 42 | Paths_lif_lang 43 | hs-source-dirs: 44 | src 45 | build-depends: 46 | aeson 47 | , base >=4.7 && <5 48 | , bytestring 49 | , containers 50 | , hspec 51 | , mtl 52 | , parsec 53 | default-language: Haskell2010 54 | 55 | executable lif-exe 56 | main-is: Main.hs 57 | other-modules: 58 | Paths_lif_lang 59 | hs-source-dirs: 60 | app 61 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 62 | build-depends: 63 | aeson 64 | , base >=4.7 && <5 65 | , bytestring 66 | , containers 67 | , hspec 68 | , lif-lang 69 | , mtl 70 | , parsec 71 | default-language: Haskell2010 72 | 73 | test-suite lif-test 74 | type: exitcode-stdio-1.0 75 | main-is: Spec.hs 76 | other-modules: 77 | Paths_lif_lang 78 | hs-source-dirs: 79 | test 80 | ghc-options: -threaded -rtsopts -with-rtsopts=-N 81 | build-depends: 82 | aeson 83 | , base >=4.7 && <5 84 | , bytestring 85 | , containers 86 | , hspec 87 | , lif-lang 88 | , mtl 89 | , parsec 90 | default-language: Haskell2010 91 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/llvm-ir/comp.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/comp.ll' 2 | source_filename = "lib/comp.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind sspstrong uwtable 7 | define dso_local i32 @comp(i32* noundef %a, i32* noundef %b, i32 noundef %n) #0 { 8 | entry: 9 | br label %for.cond 10 | 11 | for.cond: ; preds = %for.inc, %entry 12 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 13 | %cmp = icmp slt i32 %i.0, %n 14 | br i1 %cmp, label %for.body, label %for.end 15 | 16 | for.body: ; preds = %for.cond 17 | %idxprom = sext i32 %i.0 to i64 18 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 19 | %0 = load i32, i32* %arrayidx, align 4 20 | %idxprom1 = sext i32 %i.0 to i64 21 | %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %idxprom1 22 | %1 = load i32, i32* %arrayidx2, align 4 23 | %cmp3 = icmp ne i32 %0, %1 24 | br i1 %cmp3, label %if.then, label %if.end 25 | 26 | if.then: ; preds = %for.body 27 | br label %return 28 | 29 | if.end: ; preds = %for.body 30 | br label %for.inc 31 | 32 | for.inc: ; preds = %if.end 33 | %inc = add nsw i32 %i.0, 1 34 | br label %for.cond, !llvm.loop !6 35 | 36 | for.end: ; preds = %for.cond 37 | br label %return 38 | 39 | return: ; preds = %for.end, %if.then 40 | %retval.0 = phi i32 [ 0, %if.then ], [ 1, %for.end ] 41 | ret i32 %retval.0 42 | } 43 | 44 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 45 | 46 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 47 | !llvm.ident = !{!5} 48 | 49 | !0 = !{i32 1, !"wchar_size", i32 4} 50 | !1 = !{i32 7, !"PIC Level", i32 2} 51 | !2 = !{i32 7, !"PIE Level", i32 2} 52 | !3 = !{i32 7, !"uwtable", i32 1} 53 | !4 = !{i32 7, !"frame-pointer", i32 2} 54 | !5 = !{!"clang version 14.0.6"} 55 | !6 = distinct !{!6, !7} 56 | !7 = !{!"llvm.loop.mustprogress"} 57 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/llvm-ir/comp.ctgrind.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/comp.ctgrind.ll' 2 | source_filename = "lib/comp.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind sspstrong uwtable 7 | define dso_local i32 @comp(i32* noundef %a, i32* noundef %b, i32 noundef %n) #0 { 8 | entry: 9 | br label %for.cond 10 | 11 | for.cond: ; preds = %for.inc, %entry 12 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 13 | %cmp = icmp slt i32 %i.0, %n 14 | br i1 %cmp, label %for.body, label %for.end 15 | 16 | for.body: ; preds = %for.cond 17 | %idxprom = sext i32 %i.0 to i64 18 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 19 | %0 = load i32, i32* %arrayidx, align 4 20 | %idxprom1 = sext i32 %i.0 to i64 21 | %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %idxprom1 22 | %1 = load i32, i32* %arrayidx2, align 4 23 | %cmp3 = icmp ne i32 %0, %1 24 | br i1 %cmp3, label %if.then, label %if.end 25 | 26 | if.then: ; preds = %for.body 27 | br label %return 28 | 29 | if.end: ; preds = %for.body 30 | br label %for.inc 31 | 32 | for.inc: ; preds = %if.end 33 | %inc = add nsw i32 %i.0, 1 34 | br label %for.cond, !llvm.loop !6 35 | 36 | for.end: ; preds = %for.cond 37 | br label %return 38 | 39 | return: ; preds = %for.end, %if.then 40 | %retval.0 = phi i32 [ 0, %if.then ], [ 1, %for.end ] 41 | ret i32 %retval.0 42 | } 43 | 44 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 45 | 46 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 47 | !llvm.ident = !{!5} 48 | 49 | !0 = !{i32 1, !"wchar_size", i32 4} 50 | !1 = !{i32 7, !"PIC Level", i32 2} 51 | !2 = !{i32 7, !"PIE Level", i32 2} 52 | !3 = !{i32 7, !"uwtable", i32 1} 53 | !4 = !{i32 7, !"frame-pointer", i32 2} 54 | !5 = !{!"clang version 14.0.6"} 55 | !6 = distinct !{!6, !7} 56 | !7 = !{!"llvm.loop.mustprogress"} 57 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/3way.h" 2 | #include "../../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | 7 | #ifdef ENABLE_MEASURE_TIME 8 | #include 9 | #include 10 | 11 | #define _NS_PER_SECO_ND 1000000000 12 | #define INLINE __attribute__((__always_inline__)) inline 13 | INLINE uint64_t nanoseconds(struct timespec t) { 14 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 15 | } 16 | #endif 17 | 18 | /* void printvec(const char *chrs, int32_t *d) { */ 19 | /* printf("%20s : %08x %08x %08x \n", chrs, d[2], d[1], d[0]); */ 20 | /* } */ 21 | 22 | int main() { 23 | /* twy_ctx gc; */ 24 | /* int32_t a[9], k[3]; */ 25 | 26 | /* for (int i = 0; i < 3; i++) scanf("%d", &k[i]); */ 27 | /* for (int i = 0; i < 3; i++) scanf("%d", &a[i]); */ 28 | 29 | /* twy_key(k, &gc); */ 30 | /* printf("**********\n"); */ 31 | /* printvec("KEY = ", k); */ 32 | /* printvec("PLAIN = ",a); */ 33 | /* encrypt(&gc, a); */ 34 | /* printvec("CIPHER = ",a); */ 35 | 36 | /* Enc/dec test: */ 37 | /* for(int i = 0; i < 9; i++) a[i]=i; */ 38 | /* twy_enc(&gc,a,3); */ 39 | 40 | /* for(int i = 0; i < 9; i += 3) */ 41 | /* printf("Block %01d encrypts to %08x %08x %08x\n", */ 42 | /* i/3, a[i], a[i+1], a[i+2]); */ 43 | 44 | /* twy_dec(&gc,a,2); */ 45 | /* twy_dec(&gc,a+6,1); */ 46 | 47 | /* for(int i = 0; i < 9; i += 3) */ 48 | /* printf("Block %01d decrypts to %08x %08x %08x\n", */ 49 | /* i/3, a[i], a[i+1], a[i+2]); */ 50 | 51 | // Main from Constantine: 52 | twy_ctx gc; 53 | 54 | secret int32_t in_key[3]; 55 | secret int32_t in[3]; 56 | 57 | read(0, in_key, sizeof(int32_t) * 3); 58 | read(0, in, sizeof(int32_t) * 3); 59 | 60 | // Mark input as secret for ct_grind check: 61 | ct_secret(in_key, 3); 62 | ct_secret(in, 3); 63 | 64 | #ifdef ENABLE_MEASURE_TIME 65 | struct timespec start, end; 66 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 67 | #endif 68 | 69 | twy_key(in_key, &gc); 70 | encrypt(&gc, in); 71 | 72 | #ifdef ENABLE_MEASURE_TIME 73 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 74 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 75 | printf("\nTime: %ld\n", delta); 76 | #endif 77 | 78 | write(1, in, sizeof(int32_t) * 3); 79 | 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %a = alloca [3 x i32], align 4 13 | %a1 = bitcast [3 x i32]* %a to i8* 14 | call void @llvm.var.annotation(i8* %a1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 19, i8* null) 15 | %arraydecay = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 16 | %0 = bitcast i32* %arraydecay to i8* 17 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 12) 18 | %arraydecay2 = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 19 | call void @mu(i32* noundef %arraydecay2) 20 | %arraydecay3 = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 21 | %1 = bitcast i32* %arraydecay3 to i8* 22 | %call4 = call i64 @write(i32 noundef 1, i8* noundef %1, i64 noundef 12) 23 | ret i32 0 24 | } 25 | 26 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 27 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 28 | 29 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 30 | 31 | declare void @mu(i32* noundef) #2 32 | 33 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 34 | 35 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 36 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 37 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 38 | 39 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 40 | !llvm.ident = !{!5} 41 | 42 | !0 = !{i32 1, !"wchar_size", i32 4} 43 | !1 = !{i32 7, !"PIC Level", i32 2} 44 | !2 = !{i32 7, !"PIE Level", i32 2} 45 | !3 = !{i32 7, !"uwtable", i32 1} 46 | !4 = !{i32 7, !"frame-pointer", i32 2} 47 | !5 = !{!"clang version 14.0.6"} 48 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/include/fact.h: -------------------------------------------------------------------------------- 1 | #ifndef FACT_H_ 2 | #define FACT_H_ 3 | 4 | #include 5 | #include 6 | 7 | /**************************************************************** 8 | ********************** Help porting to C *********************** 9 | ****************************************************************/ 10 | typedef struct uint8ptr_wrapped_ty { 11 | uint8_t *buf; 12 | uint64_t len; 13 | } uint8ptr_wrapped_ty; 14 | 15 | /**************************************************************** 16 | ************************** FaCT stuff ************************** 17 | ****************************************************************/ 18 | 19 | #define view(dest, src, offset, len) memcpy(dest, src + offset, len) 20 | 21 | static inline uint32_t load32_le(const uint8_t src[4]) { 22 | #ifdef NATIVE_LITTLE_ENDIAN 23 | uint32_t w; 24 | memcpy(&w, src, sizeof w); 25 | return w; 26 | #else 27 | uint32_t w = (uint32_t) src[0]; 28 | w |= (uint32_t) src[1] << 8; 29 | w |= (uint32_t) src[2] << 16; 30 | w |= (uint32_t) src[3] << 24; 31 | return w; 32 | #endif 33 | } 34 | 35 | static inline uint64_t load64_le(const uint8_t src[8]) { 36 | #ifdef NATIVE_LITTLE_ENDIAN 37 | uint64_t w; 38 | memcpy(&w, src, sizeof w); 39 | return w; 40 | #else 41 | uint64_t w = (uint64_t) src[0]; 42 | w |= (uint64_t) src[1] << 8; 43 | w |= (uint64_t) src[2] << 16; 44 | w |= (uint64_t) src[3] << 24; 45 | w |= (uint64_t) src[4] << 32; 46 | w |= (uint64_t) src[5] << 40; 47 | w |= (uint64_t) src[6] << 48; 48 | w |= (uint64_t) src[7] << 56; 49 | return w; 50 | #endif 51 | } 52 | 53 | static inline void store32_le(uint8_t dst[4], uint32_t w) { 54 | #ifdef NATIVE_LITTLE_ENDIAN 55 | memcpy(dst, &w, sizeof w); 56 | #else 57 | dst[0] = (uint8_t) w; w >>= 8; 58 | dst[1] = (uint8_t) w; w >>= 8; 59 | dst[2] = (uint8_t) w; w >>= 8; 60 | dst[3] = (uint8_t) w; 61 | #endif 62 | } 63 | 64 | static inline void store64_le(uint8_t dst[8], uint64_t w) { 65 | #ifdef NATIVE_LITTLE_ENDIAN 66 | memcpy(dst, &w, sizeof w); 67 | #else 68 | dst[0] = (uint8_t) w; w >>= 8; 69 | dst[1] = (uint8_t) w; w >>= 8; 70 | dst[2] = (uint8_t) w; w >>= 8; 71 | dst[3] = (uint8_t) w; w >>= 8; 72 | dst[4] = (uint8_t) w; w >>= 8; 73 | dst[5] = (uint8_t) w; w >>= 8; 74 | dst[6] = (uint8_t) w; w >>= 8; 75 | dst[7] = (uint8_t) w; 76 | #endif 77 | } 78 | 79 | static inline uint32_t rotl32(const uint32_t x, const int b) { 80 | return (x << b) | (x >> (32 - b)); 81 | } 82 | #endif // FACT_H_ 83 | -------------------------------------------------------------------------------- /prototype/README.md: -------------------------------------------------------------------------------- 1 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 2 | ![stability-wip](https://img.shields.io/badge/stability-work_in_progress-lightgrey.svg) 3 | 4 | # Tiny 5 | This is intended to be a small and simple language used primarily 6 | with the purpose of implementing a first skeleton of compiler 7 | optimizations (passes). This repository contains the 8 | implementation of a tool that, currently, has the following 9 | features: evaluate a given program (`-r`), generate a dot 10 | representation of the Control-flow Graph (CFG) (`--cfg`) and 11 | generate a dot representation of the Dominance Tree (`--dtree`). 12 | 13 | ## Grammar 14 | Below is the grammar of the language. It is written in the BNF notation, extended with the following symbols: 15 | 16 | - { }: repetition (zero or more) 17 | - { }+: repetition (one or more) 18 | - [ ]: optional 19 | 20 | We use quotes (") on strings that conflict with special symbols. 21 | 22 |
23 | Unop       ::= - | ! | ~
24 | Binop      ::= + | - | * | & | "|" | >> | << | = | != | < | > | <= | >=
25 | Const      ::= { digit }+
26 | Value      ::= Const | id
27 | Expr       ::= Value | Unop Value | Value Binop Value
28 | Terminator ::= jmp(label) | br(Value, label, label)
29 | Inst       ::= alloc(id, Expr) | mov(id, Expr) | load(id, id, Value) | store(Value, id, Value)
30 |             | phi(id, Value : label { , Value : label }+ | out(Expr)
31 | Block      ::= { [label:] Inst } [label:] Terminator
32 | Exit       ::= { [label:] Inst }
33 | Prog       ::= { Block } Exit
34 | 
35 | 36 | ## Requirements 37 | - [Stack](https://docs.haskellstack.org/en/stable/README/) >= 2.3.1 38 | 39 | ## Usage 40 | - `stack run -- [opt]`, where opt can be one of the following: 41 | - -h: shows a help page with the commands available 42 | - -r : evaluates a given program 43 | - --cfg : generates a dot representation for the CFG 44 | of the given program 45 | - --dtree : generates a dot representation for the 46 | Dominance Tree of the given program 47 | - `stack test`: runs a set of predefined tests, which can be 48 | found at folder _test_. Currently, the existing tests are 49 | related to the implementation of the invariant pass. Each 50 | one of those tests consists of two files: a source code 51 | _file.lif_ and a json _file.json_ that contains the 52 | initial state of the corresponding program as well as 53 | additional infos. 54 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/ssl3/src/main.c: -------------------------------------------------------------------------------- 1 | #include "../include/ssl3.h" 2 | #include "../../../include/taint.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #ifdef ENABLE_MEASURE_TIME 11 | #include 12 | #include 13 | 14 | #define _NS_PER_SECO_ND 1000000000 15 | #define INLINE __attribute__((__always_inline__)) inline 16 | INLINE uint64_t nanoseconds(struct timespec t) { 17 | return t.tv_sec * _NS_PER_SECO_ND + t.tv_nsec; 18 | } 19 | #endif 20 | 21 | int main() { 22 | uint8ptr_wrapped_ty md_state; 23 | uint8ptr_wrapped_ty mac_out; 24 | uint8ptr_wrapped_ty header; 25 | uint8ptr_wrapped_ty data; 26 | 27 | size_t mac_secret_length = 20; 28 | size_t sslv3_pad_length = 40; 29 | 30 | md_state.len = sizeof(SHA_CTX); 31 | mac_out.len = 20; 32 | header.len = mac_secret_length + sslv3_pad_length 33 | + 8 /* sequence number */ 34 | + 1 /* record type */ 35 | + 2 /* record length */; 36 | data.len = 128; 37 | 38 | // All of these buffers are secret, but we mark them as secret inside 39 | // function __ssl3_cbc_digest_record as a workaround for Lif's 40 | // taint analysis' overapproximation; otherwise, the entire struct would 41 | // be considered as tainted, including the length field. 42 | md_state.buf = (uint8_t *) malloc(md_state.len * sizeof(uint8_t)); 43 | mac_out.buf = (uint8_t *) malloc(mac_out.len * sizeof(uint8_t)); 44 | header.buf = (uint8_t *) malloc(header.len * sizeof(uint8_t)); 45 | data.buf = (uint8_t *) malloc(data.len * sizeof(uint8_t)); 46 | 47 | SHA1_Init((SHA_CTX *) md_state.buf); 48 | 49 | read(0, header.buf, header.len * sizeof(uint8_t)); 50 | read(0, data.buf, data.len * sizeof(uint8_t)); 51 | 52 | secret uint64_t data_plus_mac_size = data.len - data.buf[127]; 53 | 54 | // Mark input as secret for ct_grind check: 55 | ct_secret(md_state.buf, sizeof(uint8_t) * md_state.len); 56 | ct_secret(mac_out.buf, sizeof(uint8_t) * mac_out.len); 57 | ct_secret(header.buf, sizeof(uint8_t) * header.len); 58 | ct_secret(data.buf, sizeof(uint8_t) * data.len); 59 | ct_secret(&data_plus_mac_size, sizeof(uint8_t) * 1); 60 | 61 | #ifdef ENABLE_MEASURE_TIME 62 | struct timespec start, end; 63 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start); 64 | #endif 65 | 66 | __ssl3_cbc_digest_record( 67 | &md_state, &mac_out, &header, &data, data_plus_mac_size); 68 | 69 | #ifdef ENABLE_MEASURE_TIME 70 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end); 71 | uint64_t delta = nanoseconds(end) - nanoseconds(start); 72 | printf("\nTime: %ld\n", delta); 73 | #endif 74 | 75 | write(1, mac_out.buf, mac_out.len * sizeof(uint8_t)); 76 | } 77 | -------------------------------------------------------------------------------- /prototype/src/Flow/Cfg.hs: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- | 3 | -- Module : Flow.Cfg 4 | -- Copyright : (c) Luigi D. C. Soares 2020 5 | -- License : GPL-3 6 | -- 7 | -- Maintainer : luigidcsoares@gmail.com 8 | -- Stability : experimental 9 | -- Portability : portable 10 | ---------------------------------------------------------------------------- 11 | module Flow.Cfg 12 | ( Node(..) 13 | , Adj 14 | , Context 15 | , Edge 16 | , Cfg 17 | , block 18 | , edges 19 | , mkCfg 20 | , fromBlocks 21 | , dot 22 | ) 23 | where 24 | 25 | import Data.Maybe ( fromJust ) 26 | 27 | import qualified Flow.Block as Block 28 | import qualified Internal.Dot as Dot 29 | import qualified Internal.Graph as Graph 30 | import Core.Lang ( Inst(..) 31 | , Prog 32 | , showStm 33 | ) 34 | 35 | newtype Node = Node {node :: Block.Block} deriving (Eq, Ord, Show) 36 | instance Dot.Dot Node where 37 | label = show . Block.label . node 38 | stringify = unwords . map ((++ "\\l") . showStm) . Block.block . node 39 | 40 | type Adj = Graph.Adj Node 41 | type Context = Graph.Context Node 42 | type Edge = Graph.Edge Node 43 | type Cfg = Graph.Graph Node 44 | 45 | block :: Context -> Block.Block 46 | block = node . Graph.node 47 | 48 | mkCfg :: Prog -> (Node, Cfg) 49 | mkCfg = fromBlocks . Block.fromProg 50 | 51 | fromBlocks :: [Block.Block] -> (Node, Cfg) 52 | fromBlocks bs = (root, cfg) 53 | where 54 | vs@(root : _) = map Node bs 55 | es = concatMap (edges vs) vs 56 | cfg = Graph.mkGraph vs es 57 | 58 | dot :: Node -> Cfg -> String 59 | dot = Dot.dot formatNode Dot.formatAdj "digraph \"CFG\" " 60 | where 61 | formatNode :: Node -> String 62 | formatNode v = Dot.formatNode v $ case snd . Block.terminator $ node v of 63 | Br{} -> " | {F|T}" 64 | _ -> "" 65 | 66 | edges :: [Node] -> Node -> [Edge] 67 | edges vs v@(Node b) = case snd $ Block.terminator b of 68 | -- Jmp has only one successor 69 | Jmp l -> [(v, v')] 70 | where 71 | v' = 72 | Node 73 | . fromJust 74 | . flip Block.findBlock bs 75 | . fromJust 76 | $ Block.findLeader l bs 77 | 78 | -- Br has two successors 79 | Br _ l1 l2 -> zip [v, v] 80 | $ map (Node . fromJust . flip Block.findBlock bs) leaders 81 | where leaders = map (fromJust . flip Block.findLeader bs) [l1, l2] 82 | 83 | -- No terminator => exit block 84 | _ -> [] 85 | where bs = map node vs 86 | -------------------------------------------------------------------------------- /prototype/test/mu.lif: -------------------------------------------------------------------------------- 1 | begin: 2 | alloc(b, 3) 3 | store(0, b, 0) 4 | store(0, b, 1) 5 | store(0, b, 2) 6 | jmp(loop.0) 7 | 8 | loop.0: 9 | load(b0, b, 0) 10 | mov(x0, b0 << 1) 11 | store(x0, b, 0) 12 | 13 | load(b1, b, 1) 14 | mov(x1, b1 << 1) 15 | store(x1, b, 1) 16 | 17 | load(b2, b, 2) 18 | mov(x2, b2 << 1) 19 | store(x2, b, 2) 20 | jmp(if.0) 21 | 22 | if.0: 23 | load(a0, a, 0) 24 | mov(y0, a0 & 1) 25 | mov(p0, y0 != 0) 26 | br(p0, body.0, if.1) 27 | 28 | body.0: 29 | load(b3, b, 2) 30 | mov(x3, b3 | 1) 31 | store(x3, b, 2) 32 | jmp(if.1) 33 | 34 | if.1: 35 | load(a1, a, 1) 36 | mov(y1, a1 & 1) 37 | mov(p1, y1 != 0) 38 | br(p1, body.1, if.2) 39 | 40 | body.1: 41 | load(b4, b, 1) 42 | mov(x4, b4 | 1) 43 | store(x4, b, 1) 44 | jmp(if.2) 45 | 46 | if.2: 47 | load(a2, a, 2) 48 | mov(y2, a2 & 1) 49 | mov(p2, y2 != 0) 50 | br(p2, body.2, endloop.0) 51 | 52 | body.2: 53 | load(b5, b, 0) 54 | mov(x5, b5 | 1) 55 | store(x5, b, 0) 56 | jmp(endloop.0) 57 | 58 | endloop.0: 59 | load(a3, a, 0) 60 | mov(y3, a3 >> 1) 61 | store(y3, a, 0) 62 | 63 | load(a4, a, 1) 64 | mov(y4, a4 >> 1) 65 | store(y4, a, 1) 66 | 67 | load(a5, a, 2) 68 | mov(y5, a5 >> 1) 69 | store(y5, a, 2) 70 | jmp(loop.1) 71 | 72 | loop.1: 73 | load(b6, b, 0) 74 | mov(x6, b6 << 1) 75 | store(x6, b, 0) 76 | 77 | load(b7, b, 1) 78 | mov(x7, b7 << 1) 79 | store(x7, b, 1) 80 | 81 | load(b8, b, 2) 82 | mov(x8, b8 << 1) 83 | store(x8, b, 2) 84 | jmp(if.3) 85 | 86 | if.3: 87 | load(a6, a, 0) 88 | mov(y6, a6 & 1) 89 | mov(p3, y6 != 0) 90 | br(p3, body.3, if.4) 91 | 92 | body.3: 93 | load(b9, b, 2) 94 | mov(x9, b9 | 1) 95 | store(x9, b, 2) 96 | jmp(if.4) 97 | 98 | if.4: 99 | load(a7, a, 1) 100 | mov(y7, a7 & 1) 101 | mov(p4, y7 != 0) 102 | br(p4, body.4, if.5) 103 | 104 | body.4: 105 | load(b10, b, 1) 106 | mov(x10, b10 | 1) 107 | store(x10, b, 1) 108 | jmp(if.5) 109 | 110 | if.5: 111 | load(a8, a, 1) 112 | mov(y8, a8 & 1) 113 | mov(p5, y8 != 0) 114 | br(p5, body.5, endloop.1) 115 | 116 | body.5: 117 | load(b11, b, 0) 118 | mov(x11, b11 | 1) 119 | store(x11, b, 0) 120 | jmp(endloop.1) 121 | 122 | endloop.1: 123 | load(a9, a, 0) 124 | mov(y9, a9 >> 1) 125 | store(y9, a, 0) 126 | 127 | load(a10, a, 1) 128 | mov(y10, a10 >> 1) 129 | store(y10, a, 1) 130 | 131 | load(a11, a, 2) 132 | mov(y11, a11 >> 1) 133 | store(y11, a, 2) 134 | jmp(end) 135 | 136 | end: 137 | load(b12, b, 0) 138 | store(b12, a, 0) 139 | 140 | load(b13, b, 1) 141 | store(b13, a, 1) 142 | 143 | load(b14, b, 2) 144 | store(b14, a, 2) 145 | -------------------------------------------------------------------------------- /prototype/src/Internal/Dot.hs: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- | 3 | -- Module : Internal.Dot 4 | -- Copyright : (c) Luigi D. C. Soares 2020 5 | -- License : GPL-3 6 | -- 7 | -- Maintainer : luigidcsoares@gmail.com 8 | -- Stability : experimental 9 | -- Portability : portable 10 | ---------------------------------------------------------------------------- 11 | module Internal.Dot 12 | ( Dot(..) 13 | , formatNode 14 | , formatAdj 15 | , formatCtx 16 | , dot 17 | , replaceOr 18 | ) 19 | where 20 | 21 | import Internal.Graph ( Node 22 | , Adj 23 | , Context(..) 24 | , Graph(..) 25 | , dfs 26 | ) 27 | 28 | class Dot a where 29 | -- | Takes a node and returns a label representing it. 30 | label :: Node a -> String 31 | 32 | -- | Takes a node and returns a stringified node formatted 33 | -- as dot record. 34 | stringify :: Node a -> String 35 | 36 | -- | Takes a node plus and extra info (e.g. F | T), and generates 37 | -- a dot representation with shape=record. 38 | formatNode :: Dot a => a -> String -> String 39 | formatNode v extra = 40 | label v 41 | ++ " [shape=record, label=\"{" 42 | ++ label v 43 | ++ ":\\l " 44 | ++ replaceOr (stringify v) 45 | ++ extra 46 | ++ "}\"];\n" 47 | 48 | -- | Takes a node and a list of adj nodes, and transforms them 49 | -- into dot edges. 50 | formatAdj :: Dot a => Node a -> Adj a -> String 51 | formatAdj v adj = 52 | unlines $ map ((label v ++) . (" -> " ++) . (++ ";") . label) adj 53 | 54 | -- | Takes a context, a transform fn for nodes and a transform fn 55 | -- for edgess, and transforms it into dot representation 56 | -- (default node + edges). 57 | formatCtx 58 | :: (Node a -> String) -> (Node a -> Adj a -> String) -> Context a -> String 59 | formatCtx fn fa ctx = fn (node ctx) ++ fa (node ctx) (succs ctx) 60 | 61 | -- | Takes a header, a root node plus a graph, a transform fn for 62 | -- nodes and a transform fn for edges, and transform them into a 63 | -- dot representation of the entire graph. 64 | dot 65 | :: Eq a 66 | => (Node a -> String) 67 | -> (Node a -> Adj a -> String) 68 | -> String 69 | -> Node a 70 | -> Graph a 71 | -> String 72 | dot fn fa header root g = 73 | header ++ "{\n\n" ++ unlines (dfs (formatCtx fn fa) root g) ++ "}" 74 | 75 | -- | Takes a string and replace all occurrences of the vertical bar (or) 76 | -- character since '|' is a special character in dot language. 77 | replaceOr :: String -> String 78 | replaceOr [] = [] 79 | replaceOr ('|' : str) = "\\|" ++ replaceOr str 80 | replaceOr (c : str) = c : replaceOr str 81 | -------------------------------------------------------------------------------- /prototype/app/Main.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | {-# LANGUAGE ViewPatterns #-} 3 | ----------------------------------------------------------------------------- 4 | -- | 5 | -- Module : Main 6 | -- Copyright : (c) Luigi D. C. Soares 2020 7 | -- License : GPL-3 8 | -- 9 | -- Maintainer : luigidcsoares@gmail.com 10 | -- Stability : experimental 11 | -- Portability : portable 12 | -- 13 | -- Program entry point. 14 | ---------------------------------------------------------------------------- 15 | module Main where 16 | 17 | import Data.Functor ( ($>) ) 18 | import System.Environment ( getArgs ) 19 | 20 | import qualified Flow.Cfg as Cfg 21 | import qualified Flow.DomTree as DomTree 22 | import Core.Eval ( State 23 | , evalProg 24 | , initState 25 | ) 26 | import Core.Lang ( Prog ) 27 | import Core.Parser ( readProg ) 28 | 29 | main :: IO () 30 | main = getArgs >>= parse 31 | 32 | parse :: [String] -> IO () 33 | parse ["-h"] = 34 | putStr 35 | (unlines 36 | [ "============================== Líf ===============================" 37 | , "-h\t\thelp" 38 | , "-r \trun " 39 | , "--cfg \tgenerate the CFG and print it as DOT format" 40 | , "--dtree \tsame as cfg but for the dominance tree" 41 | ] 42 | ) 43 | $> () 44 | parse ["-r" , file] = run file $> () 45 | parse ["--cfg" , file] = cfg file $> () 46 | parse ["--dtree", file] = dtree file $> () 47 | 48 | run :: String -> IO () 49 | run source = readProg source >>= \case 50 | Left err -> putStr (show err ++ "\n") $> () 51 | Right prog -> putStr (interp initState) $> () 52 | where 53 | interp :: State -> String 54 | interp (evalProg prog -> Left err ) = show err ++ "\n" 55 | interp (evalProg prog -> Right (_, _, _, _, out)) = out 56 | 57 | -- | Takes a file name, parses the code, generates the corresponding 58 | -- cfg and prints it in DOT format 59 | cfg :: String -> IO () 60 | cfg source = readProg source >>= \case 61 | Left err -> putStr (show err ++ "\n") $> () 62 | Right prog -> do 63 | let (root, cfg) = Cfg.mkCfg prog 64 | putStrLn $ Cfg.dot root cfg 65 | pure () 66 | 67 | -- | Takes a file name, parses the code, generates the corresponding 68 | -- dominance tree and prints it in DOT format 69 | dtree source = readProg source >>= \case 70 | Left err -> putStr (show err ++ "\n") $> () 71 | Right prog -> do 72 | let (root, cfg) = Cfg.mkCfg prog 73 | let tree = DomTree.mkDomTree root cfg 74 | putStrLn $ DomTree.dot (DomTree.Node $ Cfg.node root) tree 75 | pure () 76 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/input/2.txt: -------------------------------------------------------------------------------- 1 | 38 38 58 68 40 18 61 76 76 85 10 98 72 25 29 79 59 92 80 9 21 35 78 16 78 2 | 31 13 16 82 61 94 20 31 52 89 3 3 50 11 79 67 22 9 40 79 38 19 39 63 31 80 3 | 84 99 90 32 9 21 45 25 3 38 20 24 1 4 45 36 39 27 48 19 26 2 60 66 13 31 18 4 | 52 94 49 64 10 80 54 42 89 76 19 15 11 90 67 67 91 3 12 28 43 71 8 94 98 42 5 | 86 96 55 17 14 40 43 96 4 53 76 59 27 98 67 47 13 78 37 12 46 60 47 90 20 6 | 22 62 28 48 92 2 35 88 58 52 35 30 96 63 34 81 71 25 9 69 92 56 14 3 25 58 7 | 81 85 6 3 6 28 97 66 77 89 69 44 10 59 96 45 21 24 40 55 38 11 81 47 81 5 8 | 35 27 40 60 86 21 77 92 25 15 52 54 82 61 44 83 5 54 74 34 31 95 90 3 82 28 9 | 14 95 75 27 1 42 55 41 2 41 95 12 65 52 27 49 6 9 11 50 24 48 36 30 82 99 10 | 25 73 2 40 33 17 35 9 76 36 51 63 10 86 36 5 98 1 57 57 83 63 99 94 46 23 11 | 42 14 54 57 14 11 30 48 51 63 97 87 4 74 55 88 37 97 6 74 2 36 7 91 93 90 12 | 87 92 16 65 48 59 79 34 16 25 45 78 74 29 73 71 16 10 45 3 30 15 1 68 21 35 13 | 4 28 59 29 51 78 54 67 43 2 58 54 36 74 80 13 84 54 42 90 25 90 0 3 26 62 14 | 50 27 30 71 94 34 99 85 95 82 63 49 50 6 51 8 61 19 15 73 33 31 27 7 21 84 15 | 30 53 19 56 15 69 15 77 40 9 11 72 95 39 54 90 88 36 29 72 45 90 91 60 63 16 | 56 91 22 96 45 6 26 98 58 82 46 27 97 23 0 38 67 72 65 6 58 56 94 95 85 98 17 | 40 7 90 32 2 78 55 24 74 0 62 0 31 52 14 77 80 43 32 80 82 99 84 79 5 42 35 18 | 32 69 52 30 9 59 52 73 93 63 29 49 37 61 44 70 92 96 16 1 76 60 34 88 42 33 19 | 72 21 71 47 89 35 16 41 97 58 33 82 63 58 45 24 8 14 86 52 16 10 80 33 12 20 | 89 93 46 77 35 11 82 88 14 29 77 49 77 51 47 67 16 29 31 74 6 55 82 20 73 21 | 66 37 84 47 70 96 36 63 74 45 30 17 27 50 32 88 60 81 98 11 60 65 27 21 28 22 | 33 59 84 16 80 89 14 49 73 93 51 1 61 46 7 7 8 25 66 58 57 87 18 70 85 29 23 | 63 82 88 84 11 22 44 27 70 56 16 16 5 90 10 88 23 71 34 31 10 42 56 77 32 24 | 45 64 51 47 81 12 10 63 33 95 74 87 71 1 57 27 50 5 64 40 15 52 95 19 18 26 25 | 29 92 14 38 24 91 34 7 39 15 52 49 11 85 76 85 4 47 19 93 6 69 98 2 41 14 26 | 86 36 33 4 95 94 28 41 33 85 33 67 24 4 15 76 53 26 93 62 43 97 41 94 90 80 27 | 63 21 82 36 67 69 73 32 5 0 26 66 41 59 51 74 59 75 10 6 84 64 32 77 58 7 7 28 | 99 2 29 11 97 50 94 34 49 95 39 81 0 39 8 66 80 99 49 87 90 57 97 96 41 93 29 | 60 50 83 68 89 15 2 51 26 99 33 20 33 83 15 72 64 48 11 72 46 24 4 96 43 94 30 | 85 40 91 58 66 51 40 49 51 30 64 53 13 91 53 46 43 18 29 91 91 26 39 34 98 31 | 85 58 34 13 1 29 98 74 20 56 40 3 97 21 87 27 86 72 40 9 25 18 84 44 80 75 32 | 67 6 14 1 36 32 60 71 45 93 0 44 99 52 0 39 87 97 93 74 56 11 47 28 20 4 47 33 | 36 80 27 12 47 33 58 49 1 90 41 72 36 66 72 80 66 56 80 37 44 10 30 50 66 34 | 41 97 27 93 34 6 30 14 33 74 62 98 32 43 99 23 84 4 59 82 8 39 48 65 51 86 35 | 9 93 48 59 60 90 89 19 15 55 25 45 69 90 19 63 20 52 6 19 7 22 55 66 5 64 36 | 37 53 29 20 71 70 14 20 61 6 10 82 25 25 37 82 3 7 72 54 70 92 38 9 43 45 37 | 31 99 43 36 95 80 22 24 33 93 26 47 13 19 85 55 2 10 13 71 92 48 10 96 2 81 38 | 88 41 22 31 86 53 62 30 22 57 42 44 13 75 37 39 54 83 59 39 38 93 81 83 64 39 | 5 31 75 1 34 88 89 7 10 53 25 95 15 55 17 73 30 61 18 40 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/input/1.txt: -------------------------------------------------------------------------------- 1 | 60 96 11 65 18 22 42 90 17 41 31 85 30 62 4 84 54 55 35 3 49 10 97 26 25 20 2 | 82 94 96 93 40 57 21 51 22 39 6 96 30 23 69 93 40 0 55 76 84 9 64 20 44 13 3 | 62 73 40 87 93 54 13 89 79 53 78 0 37 33 72 43 61 2 98 31 27 38 31 82 47 47 4 | 23 11 99 67 56 93 40 96 80 65 82 26 54 61 79 65 62 48 98 34 91 91 68 89 22 5 | 95 60 85 9 7 33 32 50 64 31 38 58 3 67 70 68 49 96 54 43 8 51 37 56 81 3 48 6 | 73 3 69 95 98 29 13 39 68 78 3 50 42 34 89 32 69 88 3 69 69 31 55 12 39 7 7 | 49 28 88 84 8 61 87 77 89 17 39 2 56 39 80 59 22 22 25 43 55 94 31 90 63 0 8 | 21 19 45 93 58 94 21 46 79 61 8 66 70 29 16 41 31 72 81 11 32 3 33 89 78 20 9 | 84 9 10 79 41 64 30 86 57 88 13 10 67 92 71 7 90 73 36 6 15 67 11 96 78 75 10 | 31 43 64 9 96 80 50 6 60 91 2 22 10 59 43 23 1 10 47 72 49 69 46 85 76 93 11 | 84 19 89 62 94 52 37 58 93 33 39 43 72 31 66 74 85 76 66 28 31 67 70 78 72 12 | 19 48 18 36 56 43 20 75 32 14 69 16 52 59 9 17 30 84 89 93 82 96 79 91 62 13 | 39 22 29 42 1 1 93 49 51 30 5 94 82 12 58 97 13 74 81 72 15 30 35 99 20 28 14 | 82 48 39 73 10 79 27 39 53 28 73 46 9 24 76 46 19 91 58 9 88 71 84 1 44 99 15 | 31 11 99 83 39 13 31 79 18 73 90 45 13 43 6 86 89 15 42 98 62 93 89 52 3 9 16 | 24 87 42 0 18 73 11 49 89 50 62 52 61 12 26 83 90 71 58 96 89 80 43 31 78 17 | 37 25 99 90 28 40 14 47 82 14 65 87 57 15 8 39 9 61 1 54 87 16 44 90 75 72 18 | 79 55 15 10 65 53 67 64 43 27 36 89 74 50 3 72 69 92 19 78 31 60 71 64 14 19 | 90 81 58 80 56 30 59 11 46 1 76 31 69 72 74 28 40 95 35 22 30 7 91 22 58 1 20 | 53 18 72 18 33 94 99 91 6 87 54 97 30 32 99 6 63 0 10 69 28 82 64 95 4 94 2 21 | 95 16 60 29 1 79 33 19 44 28 50 35 66 37 89 64 99 21 63 37 16 95 47 85 55 22 | 61 49 51 65 75 85 93 91 78 22 93 57 87 44 1 47 95 68 14 64 90 78 64 43 73 23 | 33 60 68 81 77 55 74 59 6 40 34 24 65 26 2 19 51 91 6 95 92 54 22 92 68 19 24 | 14 46 15 58 19 48 50 19 61 27 74 36 86 13 76 21 37 73 79 39 92 30 30 98 25 25 | 54 52 80 78 52 99 93 98 14 51 49 94 33 0 56 60 7 92 79 20 0 0 89 73 11 60 26 | 65 41 22 95 98 8 48 78 86 32 9 79 31 23 62 12 50 95 45 6 88 52 98 67 4 30 27 | 99 93 3 10 85 0 83 39 95 81 47 75 92 65 8 1 77 71 57 39 15 7 67 60 13 87 12 28 | 43 86 16 73 85 41 8 27 58 40 10 97 35 91 44 43 15 10 83 17 87 54 6 58 69 13 29 | 57 62 58 44 74 1 62 23 6 47 64 46 74 55 86 16 52 21 40 29 96 55 71 79 4 90 30 | 65 10 48 67 55 38 29 13 14 3 46 77 58 84 56 55 30 31 10 16 79 62 70 19 23 31 | 66 75 94 78 79 84 43 22 65 10 77 3 39 23 49 75 69 26 33 54 83 88 16 46 30 32 | 33 25 93 3 77 48 1 84 43 79 95 27 23 17 24 33 27 27 5 50 77 12 51 35 45 5 33 | 50 66 22 28 96 87 86 21 90 63 70 91 47 45 71 42 72 26 60 29 91 87 56 96 69 34 | 65 8 20 33 86 58 83 52 12 12 48 99 30 2 89 93 72 12 40 49 15 14 21 41 6 50 35 | 33 25 39 61 94 36 70 15 69 56 73 85 40 85 29 20 84 59 22 5 84 26 49 56 75 36 | 65 70 29 6 77 11 71 2 82 33 29 51 3 44 20 91 49 37 63 66 98 83 82 89 38 87 37 | 73 64 36 29 72 33 0 33 40 9 44 43 43 59 76 72 10 11 16 62 2 97 32 65 63 30 38 | 81 45 20 19 64 93 15 33 23 87 66 55 20 38 64 97 82 7 88 58 80 98 2 28 92 4 39 | 58 24 2 21 55 83 99 75 34 63 0 49 96 55 69 95 10 21 65 6 50 47 40 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/include/crypto_secretbox.h: -------------------------------------------------------------------------------- 1 | #ifndef CRYPTO_SECRETBOX_H_ 2 | #define CRYPTO_SECRETBOX_H_ 3 | 4 | #include "../../include/fact.h" 5 | #include "../../../include/taint.h" 6 | 7 | #include 8 | #include 9 | 10 | void __crypto_core_hsalsa20( 11 | secret uint8_t out[32], // MUTABLE 12 | secret uint8_t input[16], 13 | secret uint8_t k[32] 14 | ); 15 | 16 | // We annotate the indices of the arguments whose types we don't want 17 | // lif to wrap (because they're already wrapped). 18 | __attribute__((annotate("nowrap:0"))) 19 | int32_t __crypto_stream_xsalsa20( 20 | uint8ptr_wrapped_ty *c, // SECRET (buffer) 21 | uint8_t n[24], 22 | secret uint8_t k[32] 23 | ); 24 | 25 | // We annotate the indices of the arguments whose types we don't want 26 | // lif to wrap (because they're already wrapped). 27 | __attribute__((annotate("nowrap:0,1"))) 28 | int32_t __crypto_stream_xsalsa20_xor_ic( 29 | uint8ptr_wrapped_ty *c, // SECRET (buffer), MUTABLE 30 | uint8ptr_wrapped_ty *m, // SECRET (buffer) 31 | uint8_t n[24], 32 | uint64_t ic, 33 | secret uint8_t k[32] 34 | ); 35 | 36 | // We annotate the indices of the arguments whose types we don't want 37 | // lif to wrap (because they're already wrapped). 38 | __attribute__((annotate("nowrap:0,1"))) 39 | int32_t __crypto_stream_xsalsa20_xor( 40 | uint8ptr_wrapped_ty *c, // SECRET (buffer), MUTABLE 41 | uint8ptr_wrapped_ty *m, // SECRET (buffer) 42 | uint8_t n[24], 43 | secret uint8_t k[32] 44 | ); 45 | 46 | // We annotate the indices of the arguments whose types we don't want 47 | // lif to wrap (because they're already wrapped). 48 | __attribute__((annotate("nowrap:0,1"))) 49 | bool __crypto_secretbox_xsalsa20poly1305( 50 | uint8ptr_wrapped_ty *c, // SECRET (buffer), MUTABLE 51 | uint8ptr_wrapped_ty *m, // SECRET (buffer) 52 | uint8_t n[24], 53 | secret uint8_t k[32] 54 | ); 55 | 56 | // We annotate the indices of the arguments whose types we don't want 57 | // lif to wrap (because they're already wrapped). 58 | __attribute__((annotate("nowrap:0,1"))) 59 | bool __crypto_secretbox_xsalsa20poly1305_open( 60 | uint8ptr_wrapped_ty *m, // SECRET (buffer), MUTABLE 61 | uint8ptr_wrapped_ty *c, // SECRET (buffer) 62 | uint8_t n[24], 63 | secret uint8_t k[32] 64 | ); 65 | 66 | // We annotate the indices of the arguments whose types we don't want 67 | // lif to wrap (because they're already wrapped). 68 | __attribute__((annotate("nowrap:0,1"))) 69 | bool __crypto_secretbox( 70 | uint8ptr_wrapped_ty *c, // SECRET (buffer), MUTABLE 71 | uint8ptr_wrapped_ty *m, // SECRET (buffer) 72 | uint8_t n[24], 73 | secret uint8_t k[32] 74 | ); 75 | 76 | // We annotate the indices of the arguments whose types we don't want 77 | // lif to wrap (because they're already wrapped). 78 | __attribute__((annotate("nowrap:0,1"))) 79 | bool __crypto_secretbox_open( 80 | uint8ptr_wrapped_ty *m, // SECRET (buffer), MUTABLE 81 | uint8ptr_wrapped_ty *c, // SECRET (buffer) 82 | uint8_t n[24], 83 | secret uint8_t k[32] 84 | ); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /lif/include/Analysis/Taint.h: -------------------------------------------------------------------------------- 1 | //===-- Taint.h -------------------------------------------------*- C++ -*-===// 2 | // Copyright (C) 2021 Luigi D. C. Soares 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | //===----------------------------------------------------------------------===// 17 | /// 18 | /// \file 19 | /// This file contains the declaration of the Taint analysis pass. 20 | /// 21 | //===----------------------------------------------------------------------===// 22 | #ifndef LIF_ANALYSIS_TAINT_H 23 | #define LIF_ANALYSIS_TAINT_H 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace lif::analysis { 31 | /// Set of values that are depend on sensitive information. 32 | using TaintedInfo = llvm::DenseSet; 33 | 34 | /// A pass that traverses the call graph of the module to taint values, 35 | /// following control and data dependencies. 36 | struct TaintAnalysis : public llvm::AnalysisInfoMixin { 37 | using Result = TaintedInfo; 38 | 39 | /// Traverses the call graph of a module \p M, tainting values that 40 | /// somehow depend on any secret data. We assume that secret data 41 | /// is annotated with the key "secret". For example: 42 | /// 43 | /// \code{.c} 44 | /// __attribute__((annotate("secret"))) int *key; 45 | /// \endcode 46 | /// 47 | /// \returns the set of values that are tainted. 48 | TaintedInfo run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM); 49 | 50 | // A special type used by analysis passes to provide an address that 51 | // identifies that particular analysis pass type. 52 | static llvm::AnalysisKey Key; 53 | }; 54 | 55 | /// Inspects the global variables to search for data annotated as secret. 56 | void taintGlobals(llvm::Module &M, TaintedInfo &T); 57 | 58 | /// Inspects a call instruction to search for data annotated as secret. 59 | void taintLocal(llvm::CallInst *Call, TaintedInfo &T); 60 | 61 | /// Traverses the dominance tree of a function \p F, marking variables 62 | /// as tainted. We run a sort of "look-ahead" analysis, making use of 63 | /// the information that a branch will be linearized to decide whether 64 | /// to propagate control dependence or not: control dependence is only 65 | /// propagated to values that escape the influence region of a tainted 66 | /// predicate (through a phi function or store + load). 67 | void taintFunction( 68 | llvm::Function &F, TaintedInfo &T, llvm::FunctionAnalysisManager &FAM); 69 | }; // namespace lif::analysis 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/input/2.txt: -------------------------------------------------------------------------------- 1 | 512 1024 2 | 3 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 | 19 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 23 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 27 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 29 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 31 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 34 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 35 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 39 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 40 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 42 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 43 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 46 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 | 0 0 0 0 0 0 0 0 0 49 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %in = alloca [1000 x i32], align 16 13 | %r = alloca i32, align 4 14 | %in1 = bitcast [1000 x i32]* %in to i8* 15 | call void @llvm.var.annotation(i8* %in1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 18, i8* null) 16 | br label %for.cond 17 | 18 | for.cond: ; preds = %for.inc, %entry 19 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 20 | %cmp = icmp slt i32 %i.0, 1000 21 | br i1 %cmp, label %for.body, label %for.end 22 | 23 | for.body: ; preds = %for.cond 24 | %idxprom = sext i32 %i.0 to i64 25 | %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %in, i64 0, i64 %idxprom 26 | %0 = bitcast i32* %arrayidx to i8* 27 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 4) 28 | br label %for.inc 29 | 30 | for.inc: ; preds = %for.body 31 | %inc = add nsw i32 %i.0, 1 32 | br label %for.cond, !llvm.loop !6 33 | 34 | for.end: ; preds = %for.cond 35 | %arraydecay = getelementptr inbounds [1000 x i32], [1000 x i32]* %in, i64 0, i64 0 36 | %call2 = call i32 @max(i32 noundef 1000, i32* noundef %arraydecay) 37 | store i32 %call2, i32* %r, align 4 38 | %1 = bitcast i32* %r to i8* 39 | %call3 = call i64 @write(i32 noundef 1, i8* noundef %1, i64 noundef 4) 40 | ret i32 0 41 | } 42 | 43 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 44 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 45 | 46 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 47 | 48 | declare i32 @max(i32 noundef, i32* noundef) #2 49 | 50 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 51 | 52 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 53 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 54 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 55 | 56 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 57 | !llvm.ident = !{!5} 58 | 59 | !0 = !{i32 1, !"wchar_size", i32 4} 60 | !1 = !{i32 7, !"PIC Level", i32 2} 61 | !2 = !{i32 7, !"PIE Level", i32 2} 62 | !3 = !{i32 7, !"uwtable", i32 1} 63 | !4 = !{i32 7, !"frame-pointer", i32 2} 64 | !5 = !{!"clang version 14.0.6"} 65 | !6 = distinct !{!6, !7} 66 | !7 = !{!"llvm.loop.mustprogress"} 67 | -------------------------------------------------------------------------------- /prototype/src/Flow/Block.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TupleSections #-} 2 | ----------------------------------------------------------------------------- 3 | -- | 4 | -- Module : Flow.Block 5 | -- Copyright : (c) Luigi D. C. Soares 2020, 6 | -- License : GPL-3 7 | -- 8 | -- Maintainer : luigidcsoares@gmail.com 9 | -- Stability : experimental 10 | -- Portability : portable 11 | ---------------------------------------------------------------------------- 12 | module Flow.Block 13 | ( Label(..) 14 | , Block(..) 15 | , isEntry 16 | , isExit 17 | , isMid 18 | , leader 19 | , terminator 20 | , findBlock 21 | , findLeader 22 | , fromProg 23 | ) 24 | where 25 | 26 | import Data.Maybe ( maybe ) 27 | import Data.List ( find ) 28 | 29 | import qualified Internal.Dot as Dot 30 | import qualified Core.Lang as Lang 31 | 32 | -- | A label to either some intermediate block B, the entry or 33 | -- the exit block. 34 | data Label = Entry | Exit | Mid Int deriving (Eq, Ord) 35 | instance Show Label where 36 | show Entry = "Entry" 37 | show Exit = "Exit" 38 | show (Mid n) = "B" ++ show n 39 | 40 | isEntry :: Label -> Bool 41 | isEntry Entry = True 42 | isEntry _ = False 43 | 44 | isExit :: Label -> Bool 45 | isExit Exit = True 46 | isExit _ = False 47 | 48 | isMid :: Label -> Bool 49 | isMid l = not (isEntry l) && not (isExit l) 50 | 51 | -- | A basic block represented by a label and the block itself 52 | data Block = Block {label :: Label, block :: [Lang.Stm] } deriving (Eq, Ord, Show) 53 | 54 | leader :: Block -> Lang.Stm 55 | leader = head . block 56 | 57 | terminator :: Block -> Lang.Stm 58 | terminator = last . block 59 | 60 | findBlock :: Lang.Stm -> [Block] -> Maybe Block 61 | findBlock leader = find ((== leader) . head . block) 62 | 63 | findLeader :: Lang.Label -> [Block] -> Maybe Lang.Stm 64 | findLeader l = fmap (Just l, ) . lookup (Just l) . toProg 65 | 66 | toProg :: [Block] -> Lang.Prog 67 | toProg = concatMap block 68 | 69 | fromProg :: Lang.Prog -> [Block] 70 | fromProg [] = [] 71 | fromProg prog@(first : rest) = bs' 72 | where 73 | go :: Lang.Prog -> Int -> [Lang.Stm] -> [Block] -> [Block] 74 | go [] n b bs = reverse $ Block { label = Mid n, block = reverse b } : bs 75 | go (stm : stms) n b bs 76 | | isLeader prog stm 77 | = go stms (n + 1) [stm] 78 | $ Block { label = Mid n, block = reverse b } 79 | : bs 80 | | otherwise 81 | = go stms n (stm : b) bs 82 | 83 | (b : bs) = go rest 0 [first] [] 84 | b' = last bs 85 | bs' = b { label = Entry } : init bs ++ [b' { label = Exit }] 86 | 87 | isLeader :: Lang.Prog -> Lang.Stm -> Bool 88 | isLeader prog stm@(l, i) 89 | | 90 | -- First statement of the program 91 | stm == head prog 92 | = True 93 | | 94 | -- First instruction following a br/jmp 95 | Lang.isControl . snd . head $ reverse $ takeWhile (/= stm) prog 96 | = True 97 | | 98 | -- There is some br/jmp moving the control to stm 99 | otherwise 100 | = let isLabUsed l = elem l . Lang.labelFrom $ map snd prog 101 | in maybe False isLabUsed l 102 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/input/1.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 83 20 28 27 63 23 27 62 40 21 24 62 56 5 89 63 18 71 98 88 42 83 12 55 96 3 | 63 74 62 10 12 19 25 33 47 52 28 2 11 91 42 33 15 37 21 52 26 16 71 29 47 4 | 59 71 30 71 58 26 67 32 88 77 44 39 34 9 19 86 38 21 30 61 96 95 8 33 16 5 | 61 91 64 64 20 43 23 23 73 26 81 31 93 13 52 2 89 91 68 31 10 55 69 32 85 6 | 62 60 80 70 25 28 31 16 24 95 68 68 50 91 73 9 72 5 34 17 57 37 38 48 37 69 7 | 91 92 70 55 9 32 15 21 35 40 81 98 88 38 94 56 6 76 47 11 85 51 16 20 68 5 8 | 89 38 86 26 8 77 51 78 32 92 43 47 46 78 19 27 76 7 65 2 95 3 79 74 47 96 9 | 25 95 48 25 1 69 63 87 28 71 64 79 82 96 3 25 75 49 3 26 9 79 65 6 82 60 10 | 42 93 34 89 21 91 84 70 16 85 39 11 4 67 15 68 78 97 96 82 22 3 63 57 29 72 11 | 68 26 79 82 86 21 75 52 42 29 43 26 99 91 44 70 3 48 70 18 49 80 47 77 62 12 | 69 81 58 58 42 30 26 69 41 9 87 94 16 72 36 45 15 95 76 39 39 47 42 19 49 13 | 92 68 29 39 78 24 40 91 82 98 33 44 56 34 18 97 54 12 14 26 81 59 73 8 68 14 | 44 47 47 86 98 96 10 67 57 49 77 81 21 68 95 19 33 72 8 0 90 5 54 34 19 12 15 | 47 11 17 55 11 62 34 58 80 33 54 91 32 43 40 9 25 94 9 52 13 42 56 53 42 78 16 | 59 96 13 10 40 92 53 58 80 64 20 14 22 0 79 8 91 11 52 64 52 9 58 61 61 3 17 | 4 50 89 46 28 48 75 73 58 47 66 12 5 46 8 57 92 31 90 72 39 13 83 91 77 36 18 | 0 67 29 94 3 33 44 24 12 72 72 19 46 62 66 44 6 4 22 15 93 14 78 83 86 17 19 | 97 2 41 6 70 73 6 99 67 41 33 43 65 77 48 69 28 26 31 94 70 70 30 24 17 24 20 | 38 95 7 57 44 36 59 85 43 29 59 49 28 26 90 93 2 55 2 50 24 30 8 87 57 10 21 | 89 87 34 6 43 4 33 83 61 78 19 20 63 62 81 22 43 10 81 33 35 15 20 38 97 22 | 76 0 5 96 57 47 17 77 81 56 20 85 89 35 79 99 55 99 63 49 13 17 93 23 30 23 | 58 90 77 79 60 74 87 61 11 83 18 58 1 27 71 89 48 89 78 83 68 78 70 99 73 24 | 20 12 22 13 67 85 71 90 62 82 50 69 2 43 80 85 62 71 18 89 74 7 69 63 18 85 25 | 63 28 55 95 1 7 39 55 20 39 40 24 29 3 38 11 72 40 55 84 58 49 87 8 70 62 26 | 48 40 57 66 57 53 94 44 80 27 52 19 82 4 58 55 60 19 90 99 31 94 39 18 78 27 | 29 67 98 38 37 60 86 9 49 84 98 2 10 43 82 37 27 34 51 31 92 38 24 44 28 28 | 23 7 22 94 25 33 24 92 31 94 61 91 80 71 72 96 69 75 6 44 57 75 71 91 26 35 29 | 16 97 59 92 25 14 99 80 40 24 13 96 16 44 90 77 67 2 80 39 98 82 46 4 26 30 | 36 79 98 59 38 65 7 35 24 99 92 70 98 72 10 22 85 7 70 61 97 80 60 0 92 32 31 | 30 74 78 67 1 46 46 31 6 16 96 13 83 52 13 76 22 43 48 32 98 66 39 0 27 69 32 | 80 88 1 73 52 31 79 30 98 80 77 77 43 15 93 71 28 77 23 73 85 77 49 33 10 33 | 47 99 81 79 59 82 92 79 83 97 31 47 76 93 45 89 2 54 32 17 80 36 46 89 59 34 | 51 74 69 32 7 11 11 39 92 91 98 75 83 9 90 80 40 37 56 33 15 77 36 69 10 35 | 53 49 78 31 70 69 15 44 38 47 84 49 59 55 74 50 53 49 65 94 71 45 34 9 33 36 | 99 24 11 35 25 53 21 75 31 84 45 0 31 22 39 11 6 20 70 61 94 52 46 75 49 37 | 40 47 94 6 56 59 5 12 2 73 37 55 26 44 18 10 22 19 74 44 90 85 82 42 87 75 38 | 37 71 53 44 20 25 91 46 31 79 5 68 91 8 41 61 95 99 5 14 42 27 65 16 3 87 39 | 1 17 29 20 92 98 91 77 43 11 2 34 57 65 46 62 34 69 2 7 30 98 7 36 44 49 40 | 95 9 97 31 96 30 48 57 50 73 56 41 50 31 52 53 97 41 18 43 35 84 13 38 24 41 | 43 68 31 11 12 12 39 21 9 70 49 71 50 38 21 23 94 62 74 57 46 27 55 87 77 42 | 98 22 94 43 92 18 19 60 81 62 4 93 1 57 34 3 6 5 54 45 58 77 71 20 51 29 43 | 66 10 16 85 20 14 39 14 90 32 64 9 24 45 71 29 70 5 86 36 8 25 41 94 2 99 44 | 72 73 51 55 34 49 98 82 66 18 97 5 64 19 37 28 28 45 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/loki91/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | %struct.loki_ctx = type { [16 x i32] } 7 | 8 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 9 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 10 | 11 | ; Function Attrs: noinline nounwind sspstrong uwtable 12 | define dso_local i32 @main() #0 { 13 | entry: 14 | %in = alloca [8 x i8], align 1 15 | %in_key = alloca [24 x i8], align 16 16 | %lc = alloca %struct.loki_ctx, align 4 17 | %in1 = bitcast [8 x i8]* %in to i8* 18 | call void @llvm.var.annotation(i8* %in1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 20, i8* null) 19 | %in_key2 = bitcast [24 x i8]* %in_key to i8* 20 | call void @llvm.var.annotation(i8* %in_key2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 21, i8* null) 21 | %arraydecay = getelementptr inbounds [8 x i8], [8 x i8]* %in, i64 0, i64 0 22 | %call = call i64 @read(i32 noundef 0, i8* noundef %arraydecay, i64 noundef 8) 23 | %arraydecay3 = getelementptr inbounds [24 x i8], [24 x i8]* %in_key, i64 0, i64 0 24 | %call4 = call i64 @read(i32 noundef 0, i8* noundef %arraydecay3, i64 noundef 24) 25 | %arraydecay5 = getelementptr inbounds [24 x i8], [24 x i8]* %in_key, i64 0, i64 0 26 | call void @setlokikey(i8* noundef %arraydecay5, %struct.loki_ctx* noundef %lc) 27 | %arraydecay6 = getelementptr inbounds [8 x i8], [8 x i8]* %in, i64 0, i64 0 28 | call void @enloki(%struct.loki_ctx* noundef %lc, i8* noundef %arraydecay6) 29 | %arraydecay7 = getelementptr inbounds [8 x i8], [8 x i8]* %in, i64 0, i64 0 30 | %call8 = call i64 @write(i32 noundef 1, i8* noundef %arraydecay7, i64 noundef 8) 31 | ret i32 0 32 | } 33 | 34 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 35 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 36 | 37 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 38 | 39 | declare void @setlokikey(i8* noundef, %struct.loki_ctx* noundef) #2 40 | 41 | declare void @enloki(%struct.loki_ctx* noundef, i8* noundef) #2 42 | 43 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 44 | 45 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 46 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 47 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 48 | 49 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 50 | !llvm.ident = !{!5} 51 | 52 | !0 = !{i32 1, !"wchar_size", i32 4} 53 | !1 = !{i32 7, !"PIC Level", i32 2} 54 | !2 = !{i32 7, !"PIE Level", i32 2} 55 | !3 = !{i32 7, !"uwtable", i32 1} 56 | !4 = !{i32 7, !"frame-pointer", i32 2} 57 | !5 = !{!"clang version 14.0.6"} 58 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %in = alloca [1000 x i32], align 16 13 | %out = alloca [1000 x i32], align 16 14 | %in1 = bitcast [1000 x i32]* %in to i8* 15 | call void @llvm.var.annotation(i8* %in1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 18, i8* null) 16 | br label %for.cond 17 | 18 | for.cond: ; preds = %for.inc, %entry 19 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 20 | %cmp = icmp slt i32 %i.0, 1000 21 | br i1 %cmp, label %for.body, label %for.end 22 | 23 | for.body: ; preds = %for.cond 24 | %idxprom = sext i32 %i.0 to i64 25 | %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %in, i64 0, i64 %idxprom 26 | %0 = bitcast i32* %arrayidx to i8* 27 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 4) 28 | br label %for.inc 29 | 30 | for.inc: ; preds = %for.body 31 | %inc = add nsw i32 %i.0, 1 32 | br label %for.cond, !llvm.loop !6 33 | 34 | for.end: ; preds = %for.cond 35 | %arraydecay = getelementptr inbounds [1000 x i32], [1000 x i32]* %in, i64 0, i64 0 36 | %arraydecay2 = getelementptr inbounds [1000 x i32], [1000 x i32]* %out, i64 0, i64 0 37 | call void @histogram(i32* noundef %arraydecay, i32* noundef %arraydecay2) 38 | %arraydecay3 = getelementptr inbounds [1000 x i32], [1000 x i32]* %out, i64 0, i64 0 39 | %1 = bitcast i32* %arraydecay3 to i8* 40 | %call4 = call i64 @write(i32 noundef 1, i8* noundef %1, i64 noundef 4000) 41 | ret i32 0 42 | } 43 | 44 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 45 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 46 | 47 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 48 | 49 | declare void @histogram(i32* noundef, i32* noundef) #2 50 | 51 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 52 | 53 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 54 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 55 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 56 | 57 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 58 | !llvm.ident = !{!5} 59 | 60 | !0 = !{i32 1, !"wchar_size", i32 4} 61 | !1 = !{i32 7, !"PIC Level", i32 2} 62 | !2 = !{i32 7, !"PIE Level", i32 2} 63 | !3 = !{i32 7, !"uwtable", i32 1} 64 | !4 = !{i32 7, !"frame-pointer", i32 2} 65 | !5 = !{!"clang version 14.0.6"} 66 | !6 = distinct !{!6, !7} 67 | !7 = !{!"llvm.loop.mustprogress"} 68 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-many/llvm-ir/comp.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/comp.ll' 2 | source_filename = "lib/comp.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind sspstrong uwtable 7 | define dso_local i32 @comp(i32** noundef %a, i32* noundef %b, i32 noundef %n, i32 noundef %m) #0 { 8 | entry: 9 | br label %for.cond 10 | 11 | for.cond: ; preds = %for.inc, %entry 12 | %i.0 = phi i32 [ 0, %entry ], [ %inc10, %for.inc ] 13 | %cmp = icmp slt i32 %i.0, %n 14 | br i1 %cmp, label %for.body, label %for.end 15 | 16 | for.body: ; preds = %for.cond 17 | br label %while.cond 18 | 19 | while.cond: ; preds = %if.end, %for.body 20 | %j.0 = phi i32 [ 0, %for.body ], [ %inc, %if.end ] 21 | %cmp1 = icmp slt i32 %j.0, %m 22 | br i1 %cmp1, label %while.body, label %while.end 23 | 24 | while.body: ; preds = %while.cond 25 | %idxprom = sext i32 %i.0 to i64 26 | %arrayidx = getelementptr inbounds i32*, i32** %a, i64 %idxprom 27 | %0 = load i32*, i32** %arrayidx, align 8 28 | %idxprom2 = sext i32 %j.0 to i64 29 | %arrayidx3 = getelementptr inbounds i32, i32* %0, i64 %idxprom2 30 | %1 = load i32, i32* %arrayidx3, align 4 31 | %idxprom4 = sext i32 %j.0 to i64 32 | %arrayidx5 = getelementptr inbounds i32, i32* %b, i64 %idxprom4 33 | %2 = load i32, i32* %arrayidx5, align 4 34 | %cmp6 = icmp ne i32 %1, %2 35 | br i1 %cmp6, label %if.then, label %if.else 36 | 37 | if.then: ; preds = %while.body 38 | br label %while.end 39 | 40 | if.else: ; preds = %while.body 41 | %inc = add nsw i32 %j.0, 1 42 | br label %if.end 43 | 44 | if.end: ; preds = %if.else 45 | br label %while.cond, !llvm.loop !6 46 | 47 | while.end: ; preds = %if.then, %while.cond 48 | %cmp7 = icmp eq i32 %j.0, %m 49 | br i1 %cmp7, label %if.then8, label %if.end9 50 | 51 | if.then8: ; preds = %while.end 52 | br label %return 53 | 54 | if.end9: ; preds = %while.end 55 | br label %for.inc 56 | 57 | for.inc: ; preds = %if.end9 58 | %inc10 = add nsw i32 %i.0, 1 59 | br label %for.cond, !llvm.loop !8 60 | 61 | for.end: ; preds = %for.cond 62 | br label %return 63 | 64 | return: ; preds = %for.end, %if.then8 65 | %retval.0 = phi i32 [ 1, %if.then8 ], [ 0, %for.end ] 66 | ret i32 %retval.0 67 | } 68 | 69 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 70 | 71 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 72 | !llvm.ident = !{!5} 73 | 74 | !0 = !{i32 1, !"wchar_size", i32 4} 75 | !1 = !{i32 7, !"PIC Level", i32 2} 76 | !2 = !{i32 7, !"PIE Level", i32 2} 77 | !3 = !{i32 7, !"uwtable", i32 1} 78 | !4 = !{i32 7, !"frame-pointer", i32 2} 79 | !5 = !{!"clang version 14.0.6"} 80 | !6 = distinct !{!6, !7} 81 | !7 = !{!"llvm.loop.mustprogress"} 82 | !8 = distinct !{!8, !7} 83 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/llvm-ir/histogram.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/histogram.ll' 2 | source_filename = "lib/histogram.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind sspstrong uwtable 7 | define dso_local void @histogram(i32* noundef %a, i32* noundef %c) #0 { 8 | entry: 9 | br label %for.cond 10 | 11 | for.cond: ; preds = %for.inc, %entry 12 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 13 | %cmp = icmp slt i32 %i.0, 1000 14 | br i1 %cmp, label %for.body, label %for.end 15 | 16 | for.body: ; preds = %for.cond 17 | %idxprom = sext i32 %i.0 to i64 18 | %arrayidx = getelementptr inbounds i32, i32* %c, i64 %idxprom 19 | store i32 0, i32* %arrayidx, align 4 20 | br label %for.inc 21 | 22 | for.inc: ; preds = %for.body 23 | %inc = add nsw i32 %i.0, 1 24 | br label %for.cond, !llvm.loop !6 25 | 26 | for.end: ; preds = %for.cond 27 | br label %for.cond1 28 | 29 | for.cond1: ; preds = %for.inc12, %for.end 30 | %i.1 = phi i32 [ 0, %for.end ], [ %inc13, %for.inc12 ] 31 | %cmp2 = icmp slt i32 %i.1, 1000 32 | br i1 %cmp2, label %for.body3, label %for.end14 33 | 34 | for.body3: ; preds = %for.cond1 35 | %idxprom4 = sext i32 %i.1 to i64 36 | %arrayidx5 = getelementptr inbounds i32, i32* %a, i64 %idxprom4 37 | %0 = load i32, i32* %arrayidx5, align 4 38 | %cmp6 = icmp sgt i32 %0, 0 39 | br i1 %cmp6, label %if.then, label %if.else 40 | 41 | if.then: ; preds = %for.body3 42 | %rem = srem i32 %0, 1000 43 | br label %if.end 44 | 45 | if.else: ; preds = %for.body3 46 | %sub = sub nsw i32 0, %0 47 | %rem7 = srem i32 %sub, 1000 48 | br label %if.end 49 | 50 | if.end: ; preds = %if.else, %if.then 51 | %t.0 = phi i32 [ %rem, %if.then ], [ %rem7, %if.else ] 52 | %idxprom8 = sext i32 %t.0 to i64 53 | %arrayidx9 = getelementptr inbounds i32, i32* %c, i64 %idxprom8 54 | %1 = load i32, i32* %arrayidx9, align 4 55 | %add = add nsw i32 %1, 1 56 | %idxprom10 = sext i32 %t.0 to i64 57 | %arrayidx11 = getelementptr inbounds i32, i32* %c, i64 %idxprom10 58 | store i32 %add, i32* %arrayidx11, align 4 59 | br label %for.inc12 60 | 61 | for.inc12: ; preds = %if.end 62 | %inc13 = add nsw i32 %i.1, 1 63 | br label %for.cond1, !llvm.loop !8 64 | 65 | for.end14: ; preds = %for.cond1 66 | ret void 67 | } 68 | 69 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 70 | 71 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 72 | !llvm.ident = !{!5} 73 | 74 | !0 = !{i32 1, !"wchar_size", i32 4} 75 | !1 = !{i32 7, !"PIC Level", i32 2} 76 | !2 = !{i32 7, !"PIE Level", i32 2} 77 | !3 = !{i32 7, !"uwtable", i32 1} 78 | !4 = !{i32 7, !"frame-pointer", i32 2} 79 | !5 = !{!"clang version 14.0.6"} 80 | !6 = distinct !{!6, !7} 81 | !7 = !{!"llvm.loop.mustprogress"} 82 | !8 = distinct !{!8, !7} 83 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-many/llvm-ir/comp.ctgrind.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/comp.ctgrind.ll' 2 | source_filename = "lib/comp.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind sspstrong uwtable 7 | define dso_local i32 @comp(i32** noundef %a, i32* noundef %b, i32 noundef %n, i32 noundef %m) #0 { 8 | entry: 9 | br label %for.cond 10 | 11 | for.cond: ; preds = %for.inc, %entry 12 | %i.0 = phi i32 [ 0, %entry ], [ %inc10, %for.inc ] 13 | %cmp = icmp slt i32 %i.0, %n 14 | br i1 %cmp, label %for.body, label %for.end 15 | 16 | for.body: ; preds = %for.cond 17 | br label %while.cond 18 | 19 | while.cond: ; preds = %if.end, %for.body 20 | %j.0 = phi i32 [ 0, %for.body ], [ %inc, %if.end ] 21 | %cmp1 = icmp slt i32 %j.0, %m 22 | br i1 %cmp1, label %while.body, label %while.end 23 | 24 | while.body: ; preds = %while.cond 25 | %idxprom = sext i32 %i.0 to i64 26 | %arrayidx = getelementptr inbounds i32*, i32** %a, i64 %idxprom 27 | %0 = load i32*, i32** %arrayidx, align 8 28 | %idxprom2 = sext i32 %j.0 to i64 29 | %arrayidx3 = getelementptr inbounds i32, i32* %0, i64 %idxprom2 30 | %1 = load i32, i32* %arrayidx3, align 4 31 | %idxprom4 = sext i32 %j.0 to i64 32 | %arrayidx5 = getelementptr inbounds i32, i32* %b, i64 %idxprom4 33 | %2 = load i32, i32* %arrayidx5, align 4 34 | %cmp6 = icmp ne i32 %1, %2 35 | br i1 %cmp6, label %if.then, label %if.else 36 | 37 | if.then: ; preds = %while.body 38 | br label %while.end 39 | 40 | if.else: ; preds = %while.body 41 | %inc = add nsw i32 %j.0, 1 42 | br label %if.end 43 | 44 | if.end: ; preds = %if.else 45 | br label %while.cond, !llvm.loop !6 46 | 47 | while.end: ; preds = %if.then, %while.cond 48 | %cmp7 = icmp eq i32 %j.0, %m 49 | br i1 %cmp7, label %if.then8, label %if.end9 50 | 51 | if.then8: ; preds = %while.end 52 | br label %return 53 | 54 | if.end9: ; preds = %while.end 55 | br label %for.inc 56 | 57 | for.inc: ; preds = %if.end9 58 | %inc10 = add nsw i32 %i.0, 1 59 | br label %for.cond, !llvm.loop !8 60 | 61 | for.end: ; preds = %for.cond 62 | br label %return 63 | 64 | return: ; preds = %for.end, %if.then8 65 | %retval.0 = phi i32 [ 1, %if.then8 ], [ 0, %for.end ] 66 | ret i32 %retval.0 67 | } 68 | 69 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 70 | 71 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 72 | !llvm.ident = !{!5} 73 | 74 | !0 = !{i32 1, !"wchar_size", i32 4} 75 | !1 = !{i32 7, !"PIC Level", i32 2} 76 | !2 = !{i32 7, !"PIE Level", i32 2} 77 | !3 = !{i32 7, !"uwtable", i32 1} 78 | !4 = !{i32 7, !"frame-pointer", i32 2} 79 | !5 = !{!"clang version 14.0.6"} 80 | !6 = distinct !{!6, !7} 81 | !7 = !{!"llvm.loop.mustprogress"} 82 | !8 = distinct !{!8, !7} 83 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/llvm-ir/histogram.ctgrind.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/histogram.ctgrind.ll' 2 | source_filename = "lib/histogram.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | ; Function Attrs: noinline nounwind sspstrong uwtable 7 | define dso_local void @histogram(i32* noundef %a, i32* noundef %c) #0 { 8 | entry: 9 | br label %for.cond 10 | 11 | for.cond: ; preds = %for.inc, %entry 12 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 13 | %cmp = icmp slt i32 %i.0, 1000 14 | br i1 %cmp, label %for.body, label %for.end 15 | 16 | for.body: ; preds = %for.cond 17 | %idxprom = sext i32 %i.0 to i64 18 | %arrayidx = getelementptr inbounds i32, i32* %c, i64 %idxprom 19 | store i32 0, i32* %arrayidx, align 4 20 | br label %for.inc 21 | 22 | for.inc: ; preds = %for.body 23 | %inc = add nsw i32 %i.0, 1 24 | br label %for.cond, !llvm.loop !6 25 | 26 | for.end: ; preds = %for.cond 27 | br label %for.cond1 28 | 29 | for.cond1: ; preds = %for.inc12, %for.end 30 | %i.1 = phi i32 [ 0, %for.end ], [ %inc13, %for.inc12 ] 31 | %cmp2 = icmp slt i32 %i.1, 1000 32 | br i1 %cmp2, label %for.body3, label %for.end14 33 | 34 | for.body3: ; preds = %for.cond1 35 | %idxprom4 = sext i32 %i.1 to i64 36 | %arrayidx5 = getelementptr inbounds i32, i32* %a, i64 %idxprom4 37 | %0 = load i32, i32* %arrayidx5, align 4 38 | %cmp6 = icmp sgt i32 %0, 0 39 | br i1 %cmp6, label %if.then, label %if.else 40 | 41 | if.then: ; preds = %for.body3 42 | %rem = srem i32 %0, 1000 43 | br label %if.end 44 | 45 | if.else: ; preds = %for.body3 46 | %sub = sub nsw i32 0, %0 47 | %rem7 = srem i32 %sub, 1000 48 | br label %if.end 49 | 50 | if.end: ; preds = %if.else, %if.then 51 | %t.0 = phi i32 [ %rem, %if.then ], [ %rem7, %if.else ] 52 | %idxprom8 = sext i32 %t.0 to i64 53 | %arrayidx9 = getelementptr inbounds i32, i32* %c, i64 %idxprom8 54 | %1 = load i32, i32* %arrayidx9, align 4 55 | %add = add nsw i32 %1, 1 56 | %idxprom10 = sext i32 %t.0 to i64 57 | %arrayidx11 = getelementptr inbounds i32, i32* %c, i64 %idxprom10 58 | store i32 %add, i32* %arrayidx11, align 4 59 | br label %for.inc12 60 | 61 | for.inc12: ; preds = %if.end 62 | %inc13 = add nsw i32 %i.1, 1 63 | br label %for.cond1, !llvm.loop !8 64 | 65 | for.end14: ; preds = %for.cond1 66 | ret void 67 | } 68 | 69 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 70 | 71 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 72 | !llvm.ident = !{!5} 73 | 74 | !0 = !{i32 1, !"wchar_size", i32 4} 75 | !1 = !{i32 7, !"PIC Level", i32 2} 76 | !2 = !{i32 7, !"PIE Level", i32 2} 77 | !3 = !{i32 7, !"uwtable", i32 1} 78 | !4 = !{i32 7, !"frame-pointer", i32 2} 79 | !5 = !{!"clang version 14.0.6"} 80 | !6 = distinct !{!6, !7} 81 | !7 = !{!"llvm.loop.mustprogress"} 82 | !8 = distinct !{!8, !7} 83 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/applied-crypto/3way/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | %struct.twy_ctx = type { [3 x i32], [3 x i32], [12 x i32], [12 x i32] } 7 | 8 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 9 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 10 | 11 | ; Function Attrs: noinline nounwind sspstrong uwtable 12 | define dso_local i32 @main() #0 { 13 | entry: 14 | %gc = alloca %struct.twy_ctx, align 4 15 | %in_key = alloca [3 x i32], align 4 16 | %in = alloca [3 x i32], align 4 17 | %in_key1 = bitcast [3 x i32]* %in_key to i8* 18 | call void @llvm.var.annotation(i8* %in_key1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 54, i8* null) 19 | %in2 = bitcast [3 x i32]* %in to i8* 20 | call void @llvm.var.annotation(i8* %in2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 55, i8* null) 21 | %arraydecay = getelementptr inbounds [3 x i32], [3 x i32]* %in_key, i64 0, i64 0 22 | %0 = bitcast i32* %arraydecay to i8* 23 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 12) 24 | %arraydecay3 = getelementptr inbounds [3 x i32], [3 x i32]* %in, i64 0, i64 0 25 | %1 = bitcast i32* %arraydecay3 to i8* 26 | %call4 = call i64 @read(i32 noundef 0, i8* noundef %1, i64 noundef 12) 27 | %arraydecay5 = getelementptr inbounds [3 x i32], [3 x i32]* %in_key, i64 0, i64 0 28 | call void @twy_key(i32* noundef %arraydecay5, %struct.twy_ctx* noundef %gc) 29 | %arraydecay6 = getelementptr inbounds [3 x i32], [3 x i32]* %in, i64 0, i64 0 30 | call void @encrypt(%struct.twy_ctx* noundef %gc, i32* noundef %arraydecay6) 31 | %arraydecay7 = getelementptr inbounds [3 x i32], [3 x i32]* %in, i64 0, i64 0 32 | %2 = bitcast i32* %arraydecay7 to i8* 33 | %call8 = call i64 @write(i32 noundef 1, i8* noundef %2, i64 noundef 12) 34 | ret i32 0 35 | } 36 | 37 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 38 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 39 | 40 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 41 | 42 | declare void @twy_key(i32* noundef, %struct.twy_ctx* noundef) #2 43 | 44 | declare void @encrypt(%struct.twy_ctx* noundef, i32* noundef) #2 45 | 46 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 47 | 48 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 49 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 50 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 51 | 52 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 53 | !llvm.ident = !{!5} 54 | 55 | !0 = !{i32 1, !"wchar_size", i32 4} 56 | !1 = !{i32 7, !"PIC Level", i32 2} 57 | !2 = !{i32 7, !"PIE Level", i32 2} 58 | !3 = !{i32 7, !"uwtable", i32 1} 59 | !4 = !{i32 7, !"frame-pointer", i32 2} 60 | !5 = !{!"clang version 14.0.6"} 61 | -------------------------------------------------------------------------------- /lif/test/benchmarks/fact-2019/crypto/llvm-ir/_stdlib.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/_stdlib.ll' 2 | source_filename = "lib/_stdlib.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [14 x i8] c"lib/_stdlib.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local zeroext i1 @_crypto_verify_16(i8* noundef %x, i8* noundef %y) #0 { 11 | entry: 12 | %x.addr = alloca i8*, align 8 13 | %y.addr = alloca i8*, align 8 14 | store i8* %x, i8** %x.addr, align 8 15 | %x.addr1 = bitcast i8** %x.addr to i8* 16 | call void @llvm.var.annotation(i8* %x.addr1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i32 12, i8* null) 17 | store i8* %y, i8** %y.addr, align 8 18 | %y.addr2 = bitcast i8** %y.addr to i8* 19 | call void @llvm.var.annotation(i8* %y.addr2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i32 13, i8* null) 20 | br label %for.cond 21 | 22 | for.cond: ; preds = %for.inc, %entry 23 | %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 24 | %cmp = icmp ult i32 %i.0, 16 25 | br i1 %cmp, label %for.body, label %for.end 26 | 27 | for.body: ; preds = %for.cond 28 | %0 = load i8*, i8** %x.addr, align 8 29 | %idxprom = zext i32 %i.0 to i64 30 | %arrayidx = getelementptr inbounds i8, i8* %0, i64 %idxprom 31 | %1 = load i8, i8* %arrayidx, align 1 32 | %conv = zext i8 %1 to i32 33 | %2 = load i8*, i8** %y.addr, align 8 34 | %idxprom3 = zext i32 %i.0 to i64 35 | %arrayidx4 = getelementptr inbounds i8, i8* %2, i64 %idxprom3 36 | %3 = load i8, i8* %arrayidx4, align 1 37 | %conv5 = zext i8 %3 to i32 38 | %cmp6 = icmp ne i32 %conv, %conv5 39 | br i1 %cmp6, label %if.then, label %if.end 40 | 41 | if.then: ; preds = %for.body 42 | br label %return 43 | 44 | if.end: ; preds = %for.body 45 | br label %for.inc 46 | 47 | for.inc: ; preds = %if.end 48 | %inc = add i32 %i.0, 1 49 | br label %for.cond, !llvm.loop !6 50 | 51 | for.end: ; preds = %for.cond 52 | br label %return 53 | 54 | return: ; preds = %for.end, %if.then 55 | %retval.0 = phi i1 [ false, %if.then ], [ true, %for.end ] 56 | ret i1 %retval.0 57 | } 58 | 59 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 60 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 61 | 62 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 63 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 64 | 65 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 66 | !llvm.ident = !{!5} 67 | 68 | !0 = !{i32 1, !"wchar_size", i32 4} 69 | !1 = !{i32 7, !"PIC Level", i32 2} 70 | !2 = !{i32 7, !"PIE Level", i32 2} 71 | !3 = !{i32 7, !"uwtable", i32 1} 72 | !4 = !{i32 7, !"frame-pointer", i32 2} 73 | !5 = !{!"clang version 14.0.6"} 74 | !6 = distinct !{!6, !7} 75 | !7 = !{!"llvm.loop.mustprogress"} 76 | -------------------------------------------------------------------------------- /lif/include/Transform/Loop.h: -------------------------------------------------------------------------------- 1 | //===-- Loop.h --------------------------------------------------*- C++ -*-===// 2 | // Copyright (C) 2020 Luigi D. C. Soares 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | //===----------------------------------------------------------------------===// 17 | /// 18 | /// \file 19 | /// This file contains loop-related types and functions used by both the 20 | /// data-flow analysis that binds conditions to basic blocks and the 21 | /// isochronous pass. 22 | /// 23 | //===----------------------------------------------------------------------===// 24 | #ifndef LIF_TRANSFORM_LOOP_H 25 | #define LIF_TRANSFORM_LOOP_H 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace lif::transform { 36 | /// Contains useful information to be used by the data-flow analysis and the 37 | /// isochronous pass, such as the phi-functions associated with predicates that 38 | /// branch to outside the loop (see function prepare). 39 | struct LoopWrapper { 40 | /// LoopInfo produced by running LoopAnalysis. 41 | llvm::LoopInfo &LI; 42 | /// A map between the predicate that governs the outcome of a loop exiting, 43 | /// and the associated phi-functions inserted at the loop header. 44 | llvm::DenseMap ExitPredPhi; 45 | /// A map between a loop header and its corresponding phi function that says 46 | /// whether the forward edge was taken or not. 47 | llvm::DenseMap FwedgeTakenPhi; 48 | /// A set containing all the loop latches, so it is easy to check if a 49 | /// basic block is one of them. 50 | llvm::SmallPtrSet Latches; 51 | /// A set containing all the loop headers, so it is easy to check if a 52 | /// basic block is one of them. 53 | llvm::SmallPtrSet Headers; 54 | /// A set containing all the loop exiting blocks, so it is easy to check 55 | /// if a basic block is one of them. 56 | llvm::SmallPtrSet ExitingBlocks; 57 | /// A set containing all the loop exit blocks, so it is easy to check if a 58 | /// basic block is one of them. 59 | llvm::SmallPtrSet ExitBlocks; 60 | /// Takes LoopInfo and produces a wrapper to extend \p LI with useful 61 | /// information. 62 | LoopWrapper(llvm::LoopInfo &LI) : LI(LI) {} 63 | }; 64 | 65 | /// In order to handle loops properly, we must insert a phi-function at the 66 | /// loop header for each predicate that branches out the loop. We assume that 67 | /// (i) the loop is in canonical form; and (ii) the loop is rotated. From (ii), 68 | /// we can guarantee that the loop latch will contain the loop condition. 69 | /// 70 | /// \returns a map between the predicates and the phi-functions created, a 71 | /// a set containing the loop latches, and sets containing the exiting and 72 | /// exit blocks. 73 | LoopWrapper wrapLoop(llvm::LoopInfo &LI, llvm::LLVMContext &Ctx); 74 | } // namespace lif::transform 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /lif/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #=============================================================================== 2 | # See: https://github.com/banach-space/llvm-tutor/blob/master/CMakeLists.txt 3 | #=============================================================================== 4 | cmake_minimum_required(VERSION 3.13.4) 5 | project(llvm-lif) 6 | 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | #=============================================================================== 10 | # 1. VERIFY LLVM INSTALLATION DIR 11 | #=============================================================================== 12 | # Set this to a valid LLVM installation dir: 13 | set(LLVM_INSTALL_DIR "" CACHE PATH "LLVM installation directory") 14 | 15 | # A bit of a sanity checking: 16 | set(LLVM_INSTALL_INCLUDE "${LLVM_INSTALL_DIR}/include/llvm") 17 | if(NOT EXISTS "${LLVM_INSTALL_INCLUDE}") 18 | message(FATAL_ERROR 19 | " LLVM_INSTALL_INCLUDE (${LLVM_INSTALL_INCLUDE}) is invalid.") 20 | endif() 21 | 22 | set(LLVM_INSTALL_CMAKE "${LLVM_INSTALL_DIR}/lib/cmake/llvm/LLVMConfig.cmake") 23 | if(NOT EXISTS "${LLVM_INSTALL_CMAKE}") 24 | message(FATAL_ERROR 25 | " LLVM_INSTALL_CMAKE (${LLVM_INSTALL_CMAKE}) is invalid.") 26 | endif() 27 | 28 | #=============================================================================== 29 | # 2. LOAD LLVM CONFIGURATION 30 | # For more: http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project 31 | #=============================================================================== 32 | # Add the location of LLVMConfig.cmake to CMake search paths (so that 33 | # find_package can locate it): 34 | list(APPEND CMAKE_PREFIX_PATH "${LLVM_INSTALL_DIR}/lib/cmake/llvm/") 35 | 36 | find_package(LLVM REQUIRED CONFIG) 37 | message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 38 | message(STATUS "Using LLVMConfig.cmake in: ${LT_LLVM_INSTALL_DIR}") 39 | 40 | message("LLVM STATUS: 41 | Definitions ${LLVM_DEFINITIONS} 42 | Includes ${LLVM_INCLUDE_DIRS} 43 | Libraries ${LLVM_LIBRARY_DIRS} 44 | Targets ${LLVM_TARGETS_TO_BUILD}" 45 | ) 46 | 47 | # Set the LLVM header and library paths 48 | include_directories(${LLVM_INCLUDE_DIRS}) 49 | link_directories(${LLVM_LIBRARY_DIRS}) 50 | add_definitions(${LLVM_DEFINITIONS}) 51 | 52 | #=============================================================================== 53 | # 3. LIF BUILD CONFIGURATION 54 | #=============================================================================== 55 | set(CMAKE_CXX_STANDARD 17 CACHE STRING "") 56 | 57 | # Build type 58 | if (NOT CMAKE_BUILD_TYPE) 59 | set(CMAKE_BUILD_TYPE Debug CACHE 60 | STRING "Build type (default Debug):" FORCE) 61 | endif() 62 | 63 | # Compiler flags 64 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall\ 65 | -Wno-mismatched-new-delete\ 66 | -fdiagnostics-color=always") 67 | 68 | # LLVM is normally built without RTTI. Be consistent with that. 69 | if(NOT LLVM_ENABLE_RTTI) 70 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") 71 | endif() 72 | 73 | # -fvisibility-inlines-hidden is set when building LLVM and on Darwin warnings 74 | # are triggered if llvm-lif is built without this flag (though otherwise it 75 | # builds fine). For consistency, add it here too. 76 | include(CheckCXXCompilerFlag) 77 | check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG) 78 | if (${SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG} EQUAL "1") 79 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden") 80 | endif() 81 | 82 | # Set the build directories 83 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin") 84 | 85 | #=============================================================================== 86 | # 4. ADD SUB-TARGETS 87 | # Doing this at the end so that all definitions and link/include paths are 88 | # available for the sub-projects. 89 | #=============================================================================== 90 | add_subdirectory(tool) 91 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/hash-one/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %n = alloca i32, align 4 13 | %m = alloca i32, align 4 14 | %b = alloca i32*, align 8 15 | %r = alloca i32, align 4 16 | %0 = bitcast i32* %n to i8* 17 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 4) 18 | %1 = bitcast i32* %m to i8* 19 | %call1 = call i64 @read(i32 noundef 0, i8* noundef %1, i64 noundef 4) 20 | %2 = load i32, i32* %n, align 4 21 | %conv = sext i32 %2 to i64 22 | %mul = mul i64 %conv, 4 23 | %call2 = call noalias i8* @malloc(i64 noundef %mul) #4 24 | %3 = bitcast i8* %call2 to i32* 25 | %b3 = bitcast i32** %b to i8* 26 | call void @llvm.var.annotation(i8* %b3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 28, i8* null) 27 | %4 = load i32, i32* %n, align 4 28 | %conv4 = sext i32 %4 to i64 29 | %mul5 = mul i64 %conv4, 4 30 | %call6 = call noalias i8* @malloc(i64 noundef %mul5) #4 31 | %5 = bitcast i8* %call6 to i32* 32 | store i32* %5, i32** %b, align 8 33 | %6 = bitcast i32* %3 to i8* 34 | %7 = load i32, i32* %n, align 4 35 | %conv7 = sext i32 %7 to i64 36 | %mul8 = mul i64 4, %conv7 37 | %call9 = call i64 @read(i32 noundef 0, i8* noundef %6, i64 noundef %mul8) 38 | %8 = load i32*, i32** %b, align 8 39 | %9 = bitcast i32* %8 to i8* 40 | %10 = load i32, i32* %n, align 4 41 | %conv10 = sext i32 %10 to i64 42 | %mul11 = mul i64 4, %conv10 43 | %call12 = call i64 @read(i32 noundef 0, i8* noundef %9, i64 noundef %mul11) 44 | %11 = load i32*, i32** %b, align 8 45 | %12 = load i32, i32* %m, align 4 46 | %call13 = call i32 @comp(i32* noundef %3, i32* noundef %11, i32 noundef %12) 47 | store i32 %call13, i32* %r, align 4 48 | %13 = bitcast i32* %r to i8* 49 | %call14 = call i64 @write(i32 noundef 1, i8* noundef %13, i64 noundef 4) 50 | ret i32 0 51 | } 52 | 53 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #1 54 | 55 | ; Function Attrs: nounwind 56 | declare noalias i8* @malloc(i64 noundef) #2 57 | 58 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 59 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #3 60 | 61 | declare i32 @comp(i32* noundef, i32* noundef, i32 noundef) #1 62 | 63 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #1 64 | 65 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 66 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 67 | attributes #2 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 68 | attributes #3 = { inaccessiblememonly nofree nosync nounwind willreturn } 69 | attributes #4 = { nounwind } 70 | 71 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 72 | !llvm.ident = !{!5} 73 | 74 | !0 = !{i32 1, !"wchar_size", i32 4} 75 | !1 = !{i32 7, !"PIC Level", i32 2} 76 | !2 = !{i32 7, !"PIE Level", i32 2} 77 | !3 = !{i32 7, !"uwtable", i32 1} 78 | !4 = !{i32 7, !"frame-pointer", i32 2} 79 | !5 = !{!"clang version 14.0.6"} 80 | -------------------------------------------------------------------------------- /lif/test/benchmarks/comp/plain-one/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %n = alloca i32, align 4 13 | %m = alloca i32, align 4 14 | %b = alloca i32*, align 8 15 | %r = alloca i32, align 4 16 | %0 = bitcast i32* %n to i8* 17 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 4) 18 | %1 = bitcast i32* %m to i8* 19 | %call1 = call i64 @read(i32 noundef 0, i8* noundef %1, i64 noundef 4) 20 | %2 = load i32, i32* %n, align 4 21 | %conv = sext i32 %2 to i64 22 | %mul = mul i64 %conv, 4 23 | %call2 = call noalias i8* @malloc(i64 noundef %mul) #4 24 | %3 = bitcast i8* %call2 to i32* 25 | %b3 = bitcast i32** %b to i8* 26 | call void @llvm.var.annotation(i8* %b3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 28, i8* null) 27 | %4 = load i32, i32* %n, align 4 28 | %conv4 = sext i32 %4 to i64 29 | %mul5 = mul i64 %conv4, 4 30 | %call6 = call noalias i8* @malloc(i64 noundef %mul5) #4 31 | %5 = bitcast i8* %call6 to i32* 32 | store i32* %5, i32** %b, align 8 33 | %6 = bitcast i32* %3 to i8* 34 | %7 = load i32, i32* %n, align 4 35 | %conv7 = sext i32 %7 to i64 36 | %mul8 = mul i64 4, %conv7 37 | %call9 = call i64 @read(i32 noundef 0, i8* noundef %6, i64 noundef %mul8) 38 | %8 = load i32*, i32** %b, align 8 39 | %9 = bitcast i32* %8 to i8* 40 | %10 = load i32, i32* %n, align 4 41 | %conv10 = sext i32 %10 to i64 42 | %mul11 = mul i64 4, %conv10 43 | %call12 = call i64 @read(i32 noundef 0, i8* noundef %9, i64 noundef %mul11) 44 | %11 = load i32*, i32** %b, align 8 45 | %12 = load i32, i32* %m, align 4 46 | %call13 = call i32 @comp(i32* noundef %3, i32* noundef %11, i32 noundef %12) 47 | store i32 %call13, i32* %r, align 4 48 | %13 = bitcast i32* %r to i8* 49 | %call14 = call i64 @write(i32 noundef 1, i8* noundef %13, i64 noundef 4) 50 | ret i32 0 51 | } 52 | 53 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #1 54 | 55 | ; Function Attrs: nounwind 56 | declare noalias i8* @malloc(i64 noundef) #2 57 | 58 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 59 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #3 60 | 61 | declare i32 @comp(i32* noundef, i32* noundef, i32 noundef) #1 62 | 63 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #1 64 | 65 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 66 | attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 67 | attributes #2 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 68 | attributes #3 = { inaccessiblememonly nofree nosync nounwind willreturn } 69 | attributes #4 = { nounwind } 70 | 71 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 72 | !llvm.ident = !{!5} 73 | 74 | !0 = !{i32 1, !"wchar_size", i32 4} 75 | !1 = !{i32 7, !"PIC Level", i32 2} 76 | !2 = !{i32 7, !"PIE Level", i32 2} 77 | !3 = !{i32 7, !"uwtable", i32 1} 78 | !4 = !{i32 7, !"frame-pointer", i32 2} 79 | !5 = !{!"clang version 14.0.6"} 80 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/input/2.bin: -------------------------------------------------------------------------------- 1 | &&:D(=LLU 2 | bHO;\P #NN R=^4Y2 OC (O&'?PTcZ -&-$'0<B 4^1@ 3 | P6*YL ZCC[ +G^b*V`7(+`5L;bC/ N% .</Z>0\#X:4#`?"QG E\8:QUaBMYE, 4 | ;`-(7& Q/Q#(<VM\46R=,S6J"_ZR_K*7))_ A41 20$RcI(!# L$3? 5 | V$b99S?c^.*69 03?aWJ7X%aJ$[]ZW\A0;O"-NJIG 6 | -D#;3N6C+:6$JP T6*ZZ>2G^"cU_R?123=I!T58EM( H_'6ZX$H-Z[<?8[`-b:R.a&CHA:8^_Ub(Z N7J>4MP+ PRcTO*# E4 ;4I]?1%=,F\`L<"X*!HG/Y#)a:!R?:-V4 7 | P! Y].M# RXM1M3/CJ7RIB%T/F`$?J-2 X<Qb <A!;TPY1I]3=.B:9WFU?RXT ,F8Z 8 | XG" 9 | *8M -@3/Q 10 | ?!_JWG92@(4_\&["'41 ULU/]Eb)V$!_^)!U!CL5]>+a)^ZP?R$CEI B);3J;K 11 | T@ M:c a2^"1_'Q'BPc1WZ9a`)]<2SDY3c!!SH@0 H.`+^U([:B3(13@5 [5.+[['"bU:" bJ8(aWVH( T,PKC$ <G-],c4'Wa]J8 //$P /!:1Z)H$BHPB8P%, 12 | 2B)a]"!J>b +cT;R'0A3V ]0;<ZY7-EZ?47B@%5GF= 13 | R%RH6F\& +-c+$_P!]/ U7 14 | G\0 15 | `QX)V5>9*, K%'6S;'&]QS@K"XY 16 | 5_7I= -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/histogram/input/1.bin: -------------------------------------------------------------------------------- 1 | <` A*Z)U>T67#1 2 | aR^`](93'`E](7LT @, >I(W]6 YO5N%!H+=b&R// cC8](`PAR6=OA>0b"[[DY_<U ! 2@&:CFD1`6+3%8Q0IE_b 'DN2*"Y EXEE7 '1XT=WMY'8'P;+7^Z?-]:^.O=BF)HQ !YNT 3 | O)@V9X 4 | C\GZI$C `NK+@ `P2<[ 5 | ;+ 6 | /H1E.UL]TY>^4%:]!'+HBJULBCFNH0$8+K E4; TY]R`O[>'*]13^R :a JQH#cR0'I 7 | O'5I. L.[: XGT,c cS' OIZ- +VY*b>]Y4 W*I 1Y2>4= SZG:`YP+N%cZ(/RAW9' =6W,ZKHO7 8 | A5C@+$YJ2HE\N<G@ZQ:P8; .LEHJ(_#[:5H!^c[W6a c? 9 | ER@_^_<O!,2#B%Y@c?%_/U7=13AKU][N]9W,/_D@ZN@+I!<DQM7J;("A3[_\6\D.:02=J$V L%IO'\b64PN4c]b31^!8<\OYI <A)_b0NV O> 2_-X4bCc] 10 | US'_Q/K\AMG9'C< W +VIU):( 11 | a#[,+ 12 | SW6:E 9>:,J>/@.J7V4(`7GOZA 13 | 0C7& .M:T87 14 | O>FBK^NOT+A 15 | M'1KE!6SX.!]M0T+O_!2M 3#-2B`WVZ?F[/-G*H<[W8`EA!V:S4 0cY]H (1)2!'=^$FE8IU(UT;T18KAFM GR!3,[1%?BbSRY&WI@$H!!( ,++;LH 16 | >a A?Q-@]!WB7&@aRX:Pb\:7ScK"?1`7E_ 17 | A2/ -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/input/1.txt: -------------------------------------------------------------------------------- 1 | 499 868 635 279 672 396 48 415 58 203 438 2 334 304 94 401 845 735 578 385 2 | 188 432 930 117 42 261 345 648 563 275 900 62 376 767 574 48 163 622 695 3 | 453 57 133 455 392 437 781 25 514 516 603 132 705 267 62 822 309 556 399 4 | 957 351 907 89 645 283 89 219 563 484 74 490 938 363 855 625 987 292 639 5 | 244 39 155 80 171 92 579 465 147 121 21 546 78 604 453 400 250 968 489 701 6 | 763 205 7 253 143 371 108 1 590 633 640 835 904 27 147 75 352 726 772 499 7 | 847 26 277 158 630 731 790 880 931 511 582 927 716 589 412 92 192 753 93 15 8 | 386 965 850 522 992 229 597 344 187 601 75 35 627 353 425 258 316 447 138 9 | 479 958 952 406 674 774 819 998 198 572 91 213 190 288 295 712 513 524 541 10 | 857 712 142 165 979 770 750 636 260 66 83 398 777 273 583 184 947 589 235 11 | 178 787 807 269 233 229 558 528 173 71 285 714 160 229 88 557 440 90 307 12 | 308 350 605 391 981 383 664 564 567 843 385 34 21 404 73 523 637 302 313 13 | 398 475 616 915 421 8 144 509 566 816 832 873 124 182 479 747 163 94 643 14 | 959 893 718 576 927 740 981 0 495 850 302 808 248 9 656 163 430 664 539 171 15 | 230 587 3 336 943 186 47 690 581 141 565 541 34 284 117 193 256 330 193 751 16 | 181 495 791 429 504 447 825 166 343 596 337 806 184 341 374 127 759 421 50 17 | 340 794 615 113 60 131 463 253 387 793 446 138 206 173 161 636 909 840 693 18 | 75 184 521 644 222 937 217 596 297 976 17 347 549 43 194 894 335 326 357 19 | 588 713 383 266 84 589 439 477 457 580 318 382 887 734 904 531 956 841 981 20 | 552 138 189 801 717 738 76 912 865 411 470 454 231 415 837 497 731 659 168 21 | 209 348 748 759 731 867 725 635 398 681 708 611 465 79 801 498 796 771 806 22 | 940 636 217 410 91 448 58 160 177 789 819 577 998 168 325 989 131 424 714 23 | 998 54 395 706 666 92 17 467 822 814 238 628 986 107 845 629 198 525 687 24 | 358 934 476 410 511 707 810 68 696 173 492 411 171 547 38 109 213 131 127 25 | 680 953 173 150 814 159 257 659 788 687 417 475 278 351 184 920 95 891 730 26 | 163 587 903 656 998 306 203 269 415 648 400 542 560 585 947 710 399 107 200 27 | 291 127 887 940 603 165 523 19 85 618 910 47 782 729 182 438 960 488 873 28 | 229 904 521 861 678 81 446 626 23 78 733 223 601 92 343 773 927 740 296 946 29 | 58 915 856 105 929 818 520 599 778 8 472 7 912 225 868 823 538 546 449 793 30 | 856 414 249 457 506 592 230 434 564 759 612 622 906 469 960 835 519 480 434 31 | 297 488 138 536 633 595 636 456 365 182 137 158 271 551 407 728 289 231 191 32 | 955 796 182 568 418 88 269 378 155 788 858 589 317 579 959 853 212 786 489 33 | 900 151 903 37 309 174 820 949 135 341 180 558 297 976 740 97 627 60 366 34 | 237 215 386 328 36 703 907 227 788 351 13 509 251 164 412 288 705 819 340 35 | 654 186 681 835 976 210 43 948 307 670 8 905 908 455 291 236 491 226 375 36 | 950 14 726 963 523 977 359 168 497 64 219 69 719 405 982 786 613 425 829 37 | 561 732 732 569 870 640 256 393 108 747 852 715 929 866 441 892 622 650 483 38 | 22 379 547 241 680 498 878 662 284 491 87 114 284 52 78 853 154 718 109 547 39 | 58 88 399 5 17 498 678 141 352 328 624 606 939 403 79 619 902 957 513 186 40 | 680 833 532 964 885 610 49 271 560 390 818 850 710 450 87 959 180 765 100 41 | 764 325 956 370 264 359 449 115 261 638 861 680 318 694 444 514 811 287 795 42 | 82 79 417 132 162 127 814 249 318 994 15 418 758 340 374 128 837 965 809 43 | 184 227 447 277 139 765 971 583 511 14 870 538 96 182 955 461 344 314 275 44 | 593 632 502 840 282 492 181 888 621 250 854 662 666 81 110 944 452 875 147 45 | 35 619 162 138 389 258 320 345 719 896 891 227 489 524 729 330 806 221 743 46 | 695 74 225 781 737 891 94 847 835 546 954 983 813 805 145 951 195 635 503 47 | 772 587 399 663 814 121 419 543 683 226 996 426 153 71 883 166 40 774 260 48 | 119 842 806 73 57 619 879 434 803 306 69 538 78 888 938 741 702 291 161 477 49 | 206 619 706 632 4 9 747 170 49 521 430 168 595 468 473 652 87 584 86 122 50 | 890 388 661 968 276 831 710 211 122 103 920 328 722 626 192 958 867 939 128 51 | 916 692 790 316 288 258 22 172 577 606 491 700 497 879 361 697 387 192 639 52 | 830 546 742 983 874 696 609 298 654 477 469 14 625 161 804 174 681 294 196 53 | 854 54 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/findmax/input/2.txt: -------------------------------------------------------------------------------- 1 | 345 572 763 456 933 461 75 357 100 906 903 75 889 777 3 730 307 890 439 776 2 | 904 297 169 941 703 851 235 899 937 339 165 282 911 929 970 76 390 45 433 3 | 722 183 568 29 304 577 33 267 884 155 938 660 291 235 830 232 938 913 700 4 | 69 850 39 235 132 183 396 334 491 786 611 157 740 795 725 770 331 303 35 5 | 598 187 422 537 80 713 4 142 178 175 55 878 476 905 149 943 269 332 339 603 6 | 56 357 446 213 98 473 938 100 805 241 367 635 661 789 404 741 734 409 115 7 | 912 816 170 790 292 75 172 236 576 736 807 411 792 165 857 5 263 331 944 8 | 595 136 417 962 3 310 983 408 283 717 49 398 630 865 568 652 389 875 824 9 | 625 451 561 433 862 585 830 720 591 93 283 767 920 651 416 114 654 727 97 10 | 294 10 814 343 409 676 440 977 329 830 85 385 455 536 178 120 631 764 950 11 | 583 355 275 866 354 427 749 770 541 403 497 638 698 508 685 273 149 361 714 12 | 358 922 544 443 540 231 212 718 584 843 482 766 658 69 274 756 423 701 505 13 | 194 243 908 923 881 838 663 798 112 812 392 826 403 314 602 846 86 833 290 14 | 805 417 365 287 184 23 357 690 779 780 391 516 206 634 425 130 748 495 793 15 | 546 607 838 170 665 241 717 267 319 803 333 610 608 982 975 896 398 999 485 16 | 88 10 497 480 527 936 346 184 66 94 679 91 873 519 929 43 416 402 760 916 17 | 722 564 481 332 172 463 307 300 862 538 17 182 781 747 662 540 683 9 724 18 | 981 335 635 72 208 386 234 484 35 868 476 951 590 40 432 154 445 127 694 19 | 977 221 464 227 404 245 974 298 785 889 539 741 870 107 377 174 547 995 408 20 | 31 30 509 508 213 99 780 877 254 457 5 180 667 458 644 894 862 890 100 393 21 | 907 989 932 649 859 39 258 33 587 253 674 850 516 183 590 729 514 603 607 0 22 | 60 844 180 727 302 825 853 397 715 185 790 854 174 954 503 265 226 761 531 23 | 45 247 205 127 763 620 718 724 366 321 331 367 613 407 547 573 710 604 426 24 | 339 319 612 361 406 18 315 909 284 773 903 815 50 382 252 178 145 104 128 25 | 101 470 681 433 837 294 72 617 867 14 221 526 353 773 370 714 179 388 262 26 | 88 904 267 223 719 318 605 203 728 982 307 88 84 10 769 749 79 295 821 696 27 | 395 836 918 153 421 923 523 136 102 143 630 422 48 897 646 999 447 483 435 28 | 407 466 974 495 550 984 496 531 64 24 352 992 419 420 142 572 842 65 327 29 | 210 167 470 840 822 750 737 700 982 185 183 417 592 881 391 320 663 608 48 30 | 194 904 72 779 896 723 199 39 527 273 104 854 483 504 557 323 326 539 61 31 | 258 521 478 441 938 302 323 562 622 218 170 903 413 74 975 192 202 699 623 32 | 241 226 897 578 313 380 82 102 704 640 641 997 898 163 707 571 333 9 126 33 | 895 864 345 297 767 758 603 742 182 806 673 805 47 132 934 857 445 315 939 34 | 779 251 811 420 480 709 815 187 281 149 196 407 276 292 984 806 59 742 409 35 | 34 924 447 939 962 727 71 896 584 748 443 524 527 926 335 180 406 277 995 36 | 593 790 376 22 429 653 314 414 459 606 388 100 640 545 548 811 507 275 883 37 | 635 859 863 311 615 391 237 183 571 876 692 566 701 482 175 723 143 828 270 38 | 789 519 108 178 851 980 723 631 791 462 906 674 329 998 538 640 845 161 110 39 | 28 964 986 720 762 687 434 937 643 810 997 145 599 516 253 777 600 465 732 40 | 231 256 426 138 163 756 368 933 628 213 326 738 474 290 956 426 52 644 93 41 | 990 519 903 219 896 502 736 381 512 336 846 476 567 102 903 937 497 659 537 42 | 430 519 751 756 258 457 46 214 883 331 90 976 553 841 879 772 737 614 740 43 | 118 126 308 196 602 876 531 737 45 28 628 583 691 148 566 447 406 23 726 44 | 852 906 289 175 115 842 16 994 846 986 840 587 336 198 895 533 33 3 296 770 45 | 281 324 399 864 15 547 662 695 185 685 421 269 823 710 444 938 784 693 165 46 | 630 911 5 449 247 436 345 12 469 580 308 239 861 865 870 957 880 649 619 47 | 807 66 536 228 336 360 170 12 530 186 937 695 49 80 933 498 560 369 843 572 48 | 70 656 113 309 517 210 412 475 322 61 94 130 360 863 358 928 223 761 172 49 | 985 947 110 681 996 190 846 727 750 447 570 555 517 458 900 58 976 342 702 50 | 451 664 764 777 794 356 640 385 284 95 146 456 81 325 798 994 554 989 72 51 | 281 971 519 83 758 268 542 890 558 518 232 261 201 897 257 210 691 613 83 52 | 308 897 178 686 353 491 12 152 717 798 373 789 79 576 540 394 567 40 168 53 | 689 599 686 922 92 54 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/chronos/cast5/llvm-ir/main.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | %struct.cast5_ctx = type { [16 x i32], [16 x i8], i32 } 7 | 8 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 9 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 10 | 11 | ; Function Attrs: noinline nounwind sspstrong uwtable 12 | define dso_local i32 @main() #0 { 13 | entry: 14 | %in_key = alloca [32 x i8], align 16 15 | %in = alloca [64 x i8], align 16 16 | %ctx = alloca %struct.cast5_ctx, align 4 17 | %out = alloca [64 x i8], align 16 18 | %in_key1 = bitcast [32 x i8]* %in_key to i8* 19 | call void @llvm.var.annotation(i8* %in_key1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 22, i8* null) 20 | %in2 = bitcast [64 x i8]* %in to i8* 21 | call void @llvm.var.annotation(i8* %in2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 23, i8* null) 22 | %arraydecay = getelementptr inbounds [32 x i8], [32 x i8]* %in_key, i64 0, i64 0 23 | %call = call i64 @read(i32 noundef 0, i8* noundef %arraydecay, i64 noundef 32) 24 | %arraydecay3 = getelementptr inbounds [64 x i8], [64 x i8]* %in, i64 0, i64 0 25 | %call4 = call i64 @read(i32 noundef 0, i8* noundef %arraydecay3, i64 noundef 64) 26 | %0 = bitcast [64 x i8]* %out to i8* 27 | call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 0, i64 64, i1 false) 28 | %arraydecay5 = getelementptr inbounds [32 x i8], [32 x i8]* %in_key, i64 0, i64 0 29 | %call6 = call i32 @cast5_setkey(i8* noundef %arraydecay5, %struct.cast5_ctx* noundef %ctx, i32 noundef 16) 30 | %arraydecay7 = getelementptr inbounds [64 x i8], [64 x i8]* %out, i64 0, i64 0 31 | %arraydecay8 = getelementptr inbounds [64 x i8], [64 x i8]* %in, i64 0, i64 0 32 | %rr = getelementptr inbounds %struct.cast5_ctx, %struct.cast5_ctx* %ctx, i32 0, i32 2 33 | %1 = load i32, i32* %rr, align 4 34 | call void @cast5_encrypt(%struct.cast5_ctx* noundef %ctx, i8* noundef %arraydecay7, i8* noundef %arraydecay8, i32 noundef %1) 35 | %arraydecay9 = getelementptr inbounds [64 x i8], [64 x i8]* %out, i64 0, i64 0 36 | %call10 = call i64 @write(i32 noundef 1, i8* noundef %arraydecay9, i64 noundef 64) 37 | ret i32 0 38 | } 39 | 40 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 41 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 42 | 43 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 44 | 45 | ; Function Attrs: argmemonly nofree nounwind willreturn writeonly 46 | declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #3 47 | 48 | declare i32 @cast5_setkey(i8* noundef, %struct.cast5_ctx* noundef, i32 noundef) #2 49 | 50 | declare void @cast5_encrypt(%struct.cast5_ctx* noundef, i8* noundef, i8* noundef, i32 noundef) #2 51 | 52 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 53 | 54 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 55 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 56 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 57 | attributes #3 = { argmemonly nofree nounwind willreturn writeonly } 58 | 59 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 60 | !llvm.ident = !{!5} 61 | 62 | !0 = !{i32 1, !"wchar_size", i32 4} 63 | !1 = !{i32 7, !"PIC Level", i32 2} 64 | !2 = !{i32 7, !"PIE Level", i32 2} 65 | !3 = !{i32 7, !"uwtable", i32 1} 66 | !4 = !{i32 7, !"frame-pointer", i32 2} 67 | !5 = !{!"clang version 14.0.6"} 68 | -------------------------------------------------------------------------------- /lif/test/benchmarks/mu/llvm-ir/main.ctgrind.ll: -------------------------------------------------------------------------------- 1 | ; ModuleID = 'llvm-ir/main.ctgrind.ll' 2 | source_filename = "src/main.c" 3 | target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 4 | target triple = "x86_64-pc-linux-gnu" 5 | 6 | @.str = private unnamed_addr constant [7 x i8] c"secret\00", section "llvm.metadata" 7 | @.str.1 = private unnamed_addr constant [11 x i8] c"src/main.c\00", section "llvm.metadata" 8 | 9 | ; Function Attrs: noinline nounwind sspstrong uwtable 10 | define dso_local i32 @main() #0 { 11 | entry: 12 | %a = alloca [3 x i32], align 4 13 | %_zzq_args = alloca [6 x i64], align 16 14 | %_zzq_result = alloca i64, align 8 15 | %a1 = bitcast [3 x i32]* %a to i8* 16 | call void @llvm.var.annotation(i8* %a1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i32 19, i8* null) 17 | %arraydecay = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 18 | %0 = bitcast i32* %arraydecay to i8* 19 | %call = call i64 @read(i32 noundef 0, i8* noundef %0, i64 noundef 12) 20 | %arrayidx = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 0 21 | store volatile i64 1296236545, i64* %arrayidx, align 16 22 | %arraydecay2 = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 23 | %1 = ptrtoint i32* %arraydecay2 to i64 24 | %arrayidx3 = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 1 25 | store volatile i64 %1, i64* %arrayidx3, align 8 26 | %arrayidx4 = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 2 27 | store volatile i64 12, i64* %arrayidx4, align 16 28 | %arrayidx5 = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 3 29 | store volatile i64 0, i64* %arrayidx5, align 8 30 | %arrayidx6 = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 4 31 | store volatile i64 0, i64* %arrayidx6, align 16 32 | %arrayidx7 = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 5 33 | store volatile i64 0, i64* %arrayidx7, align 8 34 | %arrayidx8 = getelementptr inbounds [6 x i64], [6 x i64]* %_zzq_args, i64 0, i64 0 35 | %2 = call i64 asm sideeffect "rolq $$3, %rdi ; rolq $$13, %rdi\0A\09rolq $$61, %rdi ; rolq $$51, %rdi\0A\09xchgq %rbx,%rbx", "={dx},{ax},0,~{cc},~{memory},~{dirflag},~{fpsr},~{flags}"(i64* %arrayidx8, i64 0) #3, !srcloc !6 36 | store volatile i64 %2, i64* %_zzq_result, align 8 37 | %3 = load volatile i64, i64* %_zzq_result, align 8 38 | %arraydecay9 = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 39 | call void @mu(i32* noundef %arraydecay9) 40 | %arraydecay10 = getelementptr inbounds [3 x i32], [3 x i32]* %a, i64 0, i64 0 41 | %4 = bitcast i32* %arraydecay10 to i8* 42 | %call11 = call i64 @write(i32 noundef 1, i8* noundef %4, i64 noundef 12) 43 | ret i32 0 44 | } 45 | 46 | ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn 47 | declare void @llvm.var.annotation(i8*, i8*, i8*, i32, i8*) #1 48 | 49 | declare i64 @read(i32 noundef, i8* noundef, i64 noundef) #2 50 | 51 | declare void @mu(i32* noundef) #2 52 | 53 | declare i64 @write(i32 noundef, i8* noundef, i64 noundef) #2 54 | 55 | attributes #0 = { noinline nounwind sspstrong uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 56 | attributes #1 = { inaccessiblememonly nofree nosync nounwind willreturn } 57 | attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } 58 | attributes #3 = { nounwind } 59 | 60 | !llvm.module.flags = !{!0, !1, !2, !3, !4} 61 | !llvm.ident = !{!5} 62 | 63 | !0 = !{i32 1, !"wchar_size", i32 4} 64 | !1 = !{i32 7, !"PIC Level", i32 2} 65 | !2 = !{i32 7, !"PIE Level", i32 2} 66 | !3 = !{i32 7, !"uwtable", i32 1} 67 | !4 = !{i32 7, !"frame-pointer", i32 2} 68 | !5 = !{!"clang version 14.0.6"} 69 | !6 = !{i64 2148182272, i64 2148182308, i64 2148182376} 70 | -------------------------------------------------------------------------------- /lif/lib/Transform/Loop.cpp: -------------------------------------------------------------------------------- 1 | //===-- Loop.cpp ----------------------------------------------------------===// 2 | // Copyright (C) 2020 Luigi D. C. Soares 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | //===----------------------------------------------------------------------===// 17 | /// 18 | /// \file 19 | /// This file contains the implementation of some loop-related utilities used 20 | /// by both the data-flow analysis that binds conditions to basic blocks and 21 | /// the isochronous pass. 22 | /// 23 | //===----------------------------------------------------------------------===// 24 | 25 | #include "Transform/Loop.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace lif::transform; 35 | 36 | LoopWrapper lif::transform::wrapLoop( 37 | llvm::LoopInfo &LI, llvm::LLVMContext &Ctx 38 | ) { 39 | LoopWrapper LW(LI); 40 | 41 | auto BoolTy = llvm::IntegerType::getInt1Ty(Ctx); 42 | auto True = llvm::ConstantInt::getTrue(BoolTy); 43 | auto False = llvm::ConstantInt::getFalse(BoolTy); 44 | 45 | for (auto L : LI.getLoopsInPreorder()) { 46 | auto Header = L->getHeader(); 47 | LW.Headers.insert(Header); 48 | 49 | assert(L->getLoopPreheader() && 50 | "error: we require loops to have a preheader! please, run the " 51 | "--loop-simplify pass."); 52 | 53 | auto Latch = L->getLoopLatch(); 54 | assert( 55 | Latch && 56 | "error: we require loops to have a unique latch! please, run the " 57 | "--loop-simplify pass."); 58 | 59 | // Save every loop latch for future use, if necessary. 60 | LW.Latches.insert(Latch); 61 | 62 | // Insert a phi function to identify, during the execution, whether the 63 | // backedge was taken or not. 64 | auto NumHeaderPred = llvm::pred_size(Header); 65 | auto InsertionPoint = Header->getFirstNonPHI(); 66 | LW.FwedgeTakenPhi[Header] = llvm::PHINode::Create( 67 | BoolTy, NumHeaderPred, "fwedge.taken", InsertionPoint); 68 | 69 | LW.FwedgeTakenPhi[Header]->addIncoming(True, L->getLoopPreheader()); 70 | LW.FwedgeTakenPhi[Header]->addIncoming(False, Latch); 71 | 72 | llvm::SmallVector ExitingBlocks; 73 | L->getExitingBlocks(ExitingBlocks); 74 | 75 | for (auto Exiting : ExitingBlocks) { 76 | LW.ExitingBlocks.insert(Exiting); 77 | // For each exiting block LE, insert a phi-function at the LH 78 | // associated with the predicate of LE. 79 | auto T = llvm::cast(Exiting->getTerminator()); 80 | auto C = T->getCondition(); 81 | auto Phi = llvm::PHINode::Create( 82 | BoolTy, NumHeaderPred, 83 | (T->hasName() ? T->getName() : "exitpred") + ".frozen", 84 | InsertionPoint); 85 | 86 | for (auto Pred : llvm::predecessors(Header)) { 87 | Phi->addIncoming(LW.Latches.count(Pred) ? C : False, Pred); 88 | LW.ExitPredPhi[C] = Phi; 89 | } 90 | } 91 | 92 | // Save every loop exit block as well. 93 | llvm::SmallVector ExitBlocks; 94 | L->getExitBlocks(ExitBlocks); 95 | for (auto Exit : ExitBlocks) LW.ExitBlocks.insert(Exit); 96 | } 97 | 98 | return LW; 99 | } 100 | -------------------------------------------------------------------------------- /lif/test/benchmarks/scelim-2018/ghostrider/dijkstra/input/1.bin: -------------------------------------------------------------------------------- 1 | S?>(>8Y?GbX*S 7`?J> 2 | !/4 [*!%4G/;GG:C XM,'" V&=`_!=[@@+IQ] 4Y[D 3 | 7E U><PF_DD2[I H"9%&0%E[\F7 #(QbX&^8L/ U3DY&VM3N \+/.NLA_OJ/`_0E?WG@OR`K1 OAR<*]"Y[TFU' CDNa`R?9HDORVK4*+c[,F0F1P/M>EQ::*E) W^H$-_L''/*1\D'N([Rb!,8"a6 Q;ID,//Vb` 4 | C91MQD_!HZ6" / 7 >":P!6[ +( ^ 4 *85*N;` 5 | (\5:P@O[ 4@4 :==2Y.0KI:/B .9\ZH' S[M$C^!, HH.>B,]NSVa)FIcC)!+AM0E^FF&_9,$;U+;1Z]72W9 6 | YW"+!S=N?>Q+ 7 | Q!#&aL`9/MQ8UY#Oc7c?1 ]:ZMO<JW= S:GY0YNSDNFcI  CUGZ>R2E+PU>GYJE?U?7_'7'(& H(7T:1WF>0(9B95^,P4R:7<Zc^'NCb&%<V 1Tb 8 | +R%"3\&,^!\^=[PGH`EK,9KG[#a;\cP( `,ZMCP'bR.$Ob;&A#c\FbH 9 | UF=aP<\ JNC..` S4 L+0 bB'EPXI4ObPMM+]GMIUM1! 10 | /cQO;R\OSa/L]-Y6 P$.Y;3JE  '\[bKS ZP(%8!M$E 11 | 51NFE,&/T1;7J251A^G-" !c #5KT-' F=^4.K1(/^8; I%7, 12 | J,ZUR*WK%G5,[.OD[)=_c*AW\b[M+ "9A.>"Eb$,1_ a`092I8)245a)+#T &+D ' F1G2&^>J9.7WMb^+\<Q>]9"6-:MG3B 13 | U'Z @ -GFV$)^cHI37"1bRBa@% --------------------------------------------------------------------------------