This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
init.py
executable file
·215 lines (180 loc) · 5.92 KB
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env python3
import grp
import json
import os
import shutil
import stat
from pathlib import Path
from typing import Any
from dead_instrumenter.utils import Binary, find_binary
import utils
def main() -> None:
print(
"Have you installed the following programs/projects: llvm, clang, compiler-rt, gcc, cmake, ccomp, csmith and creduce?"
)
print("Press enter to continue if you believe you have")
input()
not_found = []
for p in ["clang", "gcc", "cmake", "ccomp", "csmith", "creduce"]:
if not shutil.which(p):
not_found.append(p)
if not_found:
print("Can't find", " ".join(not_found), " in $PATH.")
if not Path("/usr/include/llvm/").exists():
print("Can't find /usr/include/llvm/")
not_found.append("kill")
if not_found:
exit(1)
print("Creating default ~/.config/dead/config.json...")
path = Path.home() / ".config/dead/config.json"
if path.exists():
print(f"{path} already exists! Aborting to prevent overriding data...")
exit(1)
config: dict[Any, Any] = {}
# ====== GCC ======
gcc: dict[str, Any] = {}
gcc["name"] = "gcc"
gcc["main_branch"] = "master"
# Git clone repo
print("Cloning gcc to ./gcc ...")
if not Path("./gcc").exists():
utils.run_cmd("git clone git://gcc.gnu.org/git/gcc.git")
gcc["repo"] = "./gcc"
if shutil.which("gcc"):
gcc["sane_version"] = "gcc"
else:
gcc["sane_version"] = "???"
print(
"gcc is not in $PATH, you have to specify the executable yourself in gcc.sane_version"
)
gcc["releases"] = [
"trunk",
"releases/gcc-12.1.0",
"releases/gcc-11.3.0",
"releases/gcc-11.2.0",
"releases/gcc-11.1.0",
"releases/gcc-10.3.0",
"releases/gcc-10.2.0",
"releases/gcc-10.1.0",
"releases/gcc-9.4.0",
"releases/gcc-9.3.0",
"releases/gcc-9.2.0",
"releases/gcc-9.1.0",
"releases/gcc-8.5.0",
"releases/gcc-8.4.0",
"releases/gcc-8.3.0",
"releases/gcc-8.2.0",
"releases/gcc-8.1.0",
"releases/gcc-7.5.0",
"releases/gcc-7.4.0",
"releases/gcc-7.3.0",
"releases/gcc-7.2.0",
]
config["gcc"] = gcc
# ====== LLVM ======
llvm: dict[str, Any] = {}
llvm["name"] = "clang"
llvm["main_branch"] = "main"
# Git clone repo
print("Cloning llvm to ./llvm-project ...")
if not Path("./llvm-project").exists():
utils.run_cmd("git clone https://github.com/llvm/llvm-project")
llvm["repo"] = "./llvm-project"
if shutil.which("clang"):
llvm["sane_version"] = "clang"
else:
llvm["sane_version"] = "???"
print(
"clang is not in $PATH, you have to specify the executable yourself in llvm.sane_version"
)
llvm["releases"] = [
"trunk",
"llvmorg-14.0.3",
"llvmorg-14.0.2",
"llvmorg-14.0.1",
"llvmorg-14.0.0",
"llvmorg-13.0.1",
"llvmorg-13.0.0",
"llvmorg-12.0.1",
"llvmorg-12.0.0",
"llvmorg-11.1.0",
"llvmorg-11.0.1",
"llvmorg-11.0.0",
"llvmorg-10.0.1",
"llvmorg-10.0.0",
"llvmorg-9.0.1",
"llvmorg-9.0.0",
"llvmorg-8.0.1",
"llvmorg-8.0.0",
"llvmorg-7.1.0",
"llvmorg-7.0.1",
"llvmorg-7.0.0",
"llvmorg-6.0.1",
"llvmorg-6.0.0",
"llvmorg-5.0.2",
"llvmorg-5.0.1",
"llvmorg-5.0.0",
"llvmorg-4.0.1",
"llvmorg-4.0.0",
]
config["llvm"] = llvm
config["repodir"] = str(Path(os.getcwd()).absolute())
# ====== CSmith ======
csmith: dict[str, Any] = {}
csmith["max_size"] = 50000
csmith["min_size"] = 10000
if shutil.which("csmith"):
csmith["executable"] = "csmith"
res = utils.run_cmd("csmith --version")
# $ csmith --version csmith 2.3.0
# Git version: 30dccd7
version = res.split("\n")[0].split()[1]
if Path("/usr/include/csmith").exists():
csmith["include_path"] = "/usr/include/csmith"
else:
csmith["include_path"] = "/usr/include/csmith-" + version
else:
print(
"Can't find csmith in $PATH. You have to specify the executable and the include path yourself"
)
csmith["executable"] = "???"
csmith["include_path"] = "???"
config["csmith"] = csmith
# ====== Cpp programs ======
print("Building instrumenter...")
find_binary(Binary.INSTRUMENTER, no_questions=True)
config["dcei"] = "dead-instrument"
print("Compiling callchain checker (ccc)...")
os.makedirs("./callchain_checker/build", exist_ok=True)
utils.run_cmd("cmake ..", working_dir=Path("./callchain_checker/build/"))
utils.run_cmd("make -j", working_dir=Path("./callchain_checker/build/"))
config["ccc"] = "./callchain_checker/build/bin/ccc"
# ====== Rest ======
config["patchdb"] = "./patches/patchdb.json"
os.makedirs("logs", exist_ok=True)
config["logdir"] = "./logs"
os.makedirs("compiler_cache", exist_ok=True)
os.chmod("compiler_cache", 0o770 | stat.S_ISGID)
config["cachedir"] = "./compiler_cache"
config["creduce"] = "creduce"
if not shutil.which("creduce"):
print(
"creduce was not found in $PATH. You have to specify the executable yourself"
)
config["creduce"] = "???"
config["ccomp"] = "ccomp"
if not shutil.which("ccomp"):
print(
"ccomp was not found in $PATH. You have to specify the executable yourself"
)
config["ccomp"] = "???"
config["casedb"] = "./casedb.sqlite3"
Path(config["casedb"]).touch()
os.chmod(config["casedb"], 0o660)
print("Saving config...")
os.makedirs(path.parent, exist_ok=True)
with open(path, "w") as f:
json.dump(config, f, indent=4)
print("Done!")
if __name__ == "__main__":
main()