forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.llvm
More file actions
executable file
·160 lines (132 loc) · 3.73 KB
/
Copy pathbuild.llvm
File metadata and controls
executable file
·160 lines (132 loc) · 3.73 KB
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
#!/bin/bash
############################
#
# Author: Koustubha Bhat
# Date : 3-April-2014
# VU University, Amsterdam.
#
############################
set -o errexit
MYPWD=`pwd`
MINIX_ROOT=
MINIX_LLVM_DIR=
LLVMPASS=
LLVMARGS=
LLVMPASS_PATHS=
TARGET_MODULES=
MINIX_MODS=
# Set default values for essential variables
: ${GENERATE_MAP="no"}
: ${C="servers,drivers"}
function usage()
{
echo "C=<target Minix module(s)> $0 [<LLVM-pass name> ...]"
echo
echo "Examples:"
echo "C=pm,vfs ./$0 dummy"
echo "C=drivers ./$0 dummy"
echo
echo "Additional arguments to the passes may be passed through \${LLVM_PASS_ARGS}."
echo
}
function check_current_dir()
{
#Make sure we are running from the root dir of the Minix sources
if [ -d ./minix/drivers ] && [ -d ./minix/servers ] ; then
MINIX_ROOT="${MYPWD}"
elif [ -d ../../minix/drivers ] && [ -d ../../minix/servers ]; then
MINIX_ROOT="${MYPWD}/../.."
else
echo "Please run the script from either of the following locations:"
echo "> Root of the Minix sources."
echo " OR"
echo "> minix/llvm directory of the Minix sources."
exit 1
fi
MINIX_LLVM_DIR="${MINIX_ROOT}/minix/llvm"
}
function check_args()
{
local llvmpass=
local llvmpass_path=
local exit_flag=0
if [ $# -ge 1 ]; then
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
usage
exit 1
fi
for p in "$@" ;
do
llvmpass=$p
# Default value for llvmargs not specified deliberately
if [ -f "${INSTALL_DIR}/${llvmpass}.so" ]; then
llvmpass_path="${INSTALL_DIR}/${llvmpass}.so"
elif [ -f "${MINIX_LLVM_BIN_DIR}/${llvmpass}.so" ]; then
llvmpass_path="${MINIX_LLVM_BIN_DIR}/${llvmpass}.so"
else
llvmpass_path=""
fi
if [ "$llvmpass_path" != "" ]; then
LLVMPASS_PATHS+=" -load=${llvmpass_path}"
fi
LLVMPASS_PATHS+=" -${llvmpass}"
done
if [ ${exit_flag} == 1 ]; then
echo "Searched in the following location(s):"
echo " ${INSTALL_DIR}"
echo " ${MINIX_LLVM_BIN_DIR}"
exit 1
fi
LLVMARGS=" ${LLVM_PASS_ARGS}"
fi
}
#Make sure we are running from the root dir of the Minix sources
check_current_dir
# set up the bridge to llvm-apps repository and initialize
. ${MINIX_LLVM_DIR}/minix.inc
[ ! -f ${ROOT}/apps/scripts/include/configure.llvm.inc ] || . ${ROOT}/apps/scripts/include/configure.llvm.inc
# Arguments check
check_args "$@"
if [ "$C" == "" ]; then
C="hello"
fi
if [ "${GENERATE_MAP}" != "" ] && [[ ${GENERATE_MAP} =~ [yY][eE][sS] ]]; then
generate_modules_map
fi
: ${OPTFLAGS="-disable-opt -disable-internalize -disable-inlining -load ${MINIX_LLVM_DIR}/bin/weak-alias-module-override.so -weak-alias-module-override"}
# If we are really instrumenting with some pass...
if [ "${LLVMPASS_PATHS}" != "" ]; then
OPTFLAGS=" ${OPTFLAGS} ${LLVMPASS_PATHS} ${LLVMARGS}"
fi
TARGET_MODULES=`echo $C | sed -e "s/,/ /g"`
for m in ${TARGET_MODULES}
do
for p in `get_modules_path $m`
do
MINIX_MODS="${MINIX_MODS} $p"
done
done
# Show info
echo "Build.llvm: Executing with following parameters..."
echo "LLVM pass : ${LLVMPASS}"
echo "LLVM pass arguments : ${LLVMARGS}"
echo "Target Minix modules : ${MINIX_MODS}"
echo "OPTFLAGS value : ${OPTFLAGS}"
echo
cd ${MINIX_ROOT}
for m in ${MINIX_MODS}
do
echo "Instrumenting $m ..."
n=`get_module_name $m`
if [ "" == "$n" ]; then
echo "Error: Couldn't fetch the module name for $m"
continue
fi
clean_module $n $m
OPTFLAGS=`echo ${OPTFLAGS} | sed -e "s/\ /\\\ /g"`
OPTFLAGS_PLACEHOLDER="OPTFLAGS.$n=${OPTFLAGS}"
(env "`echo ${OPTFLAGS_PLACEHOLDER}`" MKBITCODE=yes \
${TOOLDIR}/nbmake-${ARCH} -C $m all install && echo "INFO: $m successfully instrumented." ) || echo "ERROR: Failed instrumenting $m"
echo
done
cd ${MYPWD}