/
crunchsbcc
executable file
·82 lines (71 loc) · 3.59 KB
/
crunchsbcc
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
#!/usr/bin/env python
# ... or for debugging, use something like
#!/home/stephen/bin/gdbrun python
# Compiler wrapper for libcrunch.
import os, sys, re, subprocess, tempfile
# HACK
if "LIBALLOCS" in os.environ:
liballocs_base = os.path.realpath(os.environ["LIBALLOCS"])
else:
liballocs_base = os.path.realpath(os.path.dirname(sys.argv[0]) + "/../../../../liballocs/")
sys.path.append(liballocs_base + "/tools")
sys.path.append(liballocs_base + "/tools/lang/c/lib")
from allocscc import AllocsCC
sys.path.append(os.path.realpath(os.path.dirname(__file__) + "/../lib"))
from crunchcc import CrunchCC
class CrunchSBCC(CrunchCC):
def getStubGenCompileArgs(self):
# We have to include the CIL inlines with the appropriate flags
# and then define the init, fini and argwise hooks
# so that they do the shadow bounds stack stuff
return ["-include", self.getLibAllocsBaseDir() + "/include/uniqtype.h", \
"-DLIBCRUNCH_EMULATE_SOFTBOUND", \
"-DLIBCRUNCH_WORDSIZE_BOUNDS", \
"-include", \
os.path.dirname(__file__) + "/../../../include/libcrunch_cil_inlines.h", \
"-include", \
os.path.dirname(__file__) + "/../../../include/stubgen_softbound.h" \
]
def getCillyArgs(self, sourceFiles):
# PROBLEM: we only want to -include if we're compiling a C file.
# Note that normally cilly will figure out when we're compiling
# a .S file, say, and only pass options that are relevant. But
# it would be asking too much in this case.
allSourceFilesAreC = True
for sourceFile in sourceFiles:
if sourceFile.lang != "c" and not sourceFile.endswith(".c"):
allSourceFilesAreC = False
includeArgs = []
# "--load=%s" % (os.path.dirname(sys.argv[0]) + "/../vsimplemem/vsimplemem.cmxs"), "--dovsimpleMem", \
# "--load=%s" % (os.path.dirname(sys.argv[0]) + "/../vsimpleaddr/vsimpleaddr.cmxs"), "--dovsimpleAddr", \
if len(sourceFiles) > 0 and allSourceFilesAreC:
#"-DLIBCRUNCH_TRACE_BOUNDS_STACK", \
# We can only do trumptr, and anything else that involves -include,
# if we're compiling only C files.
# temporary HACK to strip line numbers after preprocess
#"--commPrintLn",
includeArgs = [ \
"-include", self.getLibAllocsBaseDir() + "/include/uniqtype-defs.h", \
"-DLIBCRUNCH_EMULATE_SOFTBOUND", \
"-DLIBCRUNCH_WORDSIZE_BOUNDS", \
"-include", \
os.path.dirname(__file__) + "/../../../include/libcrunch_cil_inlines.h", \
"--load=%s" % (os.path.dirname(sys.argv[0]) + "/../ptrintarith/ptrintarith.cmxs"), "--doptrintarith", \
"--load=%s" % (os.path.dirname(sys.argv[0]) + "/../crunchbound/crunchbound.cmxs"), "--docrunchbound", \
"--emulate-softbound" \
]
else:
self.debugMsg("No source files, or not all (only %d) are C files\n" % len(sourceFiles))
# do dumpallocs et al *and* trumptr
return AllocsCC.getCillyArgs(self, sourceFiles) + \
["--keepunused"] \
+ includeArgs + \
["-Wno-unused-variable", "-Wno-unused-label"]
# We need the above -Wno-unused-... because CIL creates
# some unused stuff (unavoidably, I believe) which will
# make compilation done with -Werror barf if we don't
# silence them.
if __name__ == '__main__':
wrapper = CrunchSBCC()
ret = wrapper.main()
exit(ret)