-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·87 lines (81 loc) · 2.11 KB
/
build.sh
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
#!/bin/bash
DEBUG=
OPTIMIZE="-O2"
EXTRA_OPTS=
for OPTION in $@
do
case $OPTION in
--debug)
DEBUG=".debug"
OPTIMIZE="-O0 -g"
;;
--aslr=*)
VAL="${OPTION#*=}"
EXTRA_OPTS="$EXTRA_OPTS -DREDFAT_ASLR=$VAL"
;;
--canary=*)
VAL="${OPTION#*=}"
EXTRA_OPTS="$EXTRA_OPTS -DREDFAT_CANARY=$VAL"
;;
--zero=*)
VAL="${OPTION#*=}"
EXTRA_OPTS="$EXTRA_OPTS -DREDFAT_ZERO=$VAL"
;;
--quarantine=*)
VAL="${OPTION#*=}"
EXTRA_OPTS="$EXTRA_OPTS -DREDFAT_QUARANTINE=$VAL"
;;
--help)
echo "usage: $0 [OPTIONS]"
echo
echo "OPTIONS:"
echo " --debug"
echo " Compile with debug symbols"
echo " --aslr={1,0}"
echo " Enable (disable) ASLR"
echo " --canary={1,0}"
echo " Enable (disable) upper canary"
echo " --quarantine=N"
echo " Use a N-byte quarantine"
echo " --zero={1,0}"
echo " Enable (disable) zero-on-free"
echo
exit 0
;;
*)
echo "$0: unknown option \`$OPTION'" 2>&1
echo "$0: try \`--help' for more information" 2>&1
exit 1
;;
esac
done
if [ "$1" = --debug ]
then
DEBUG=".debug"
OPTIMIZE="-O0 -g"
else
DEBUG=
OPTIMIZE="-O2"
fi
CC=gcc
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BOLD="\033[1m"
OFF="\033[0m"
echo -e "${GREEN}$0${OFF}: creating libredfat$DEBUG.so..."
OPTIONS="-m64 -mbmi -mbmi2 -mlzcnt -msse4.2 \
-std=gnu99 -fPIC -Wall -I . $OPTIMIZE -pthread \
-D_GNU_SOURCE -D__NO_STRING_INLINES -DREDFAT_LINUX $EXTRA_OPTS"
COMMAND="$CC $OPTIONS -shared -o libredfat$DEBUG.so redfat.c"
echo $COMMAND
$COMMAND
if [ "$DEBUG" = "" ]
then
strip libredfat.so
fi
echo -e "${GREEN}$0${OFF}: creating libredfat$DEBUG.a..."
COMMAND="$CC $OPTIONS -pie -c redfat.c"
echo $COMMAND
$COMMAND
ar -crs libredfat$DEBUG.a redfat.o