phunix/minix/llvm/build.llvm
Koustubha Bhat 5ba302fdea Bridging Minix & llvm-apps repos for instrumentating Minix
Allows instrumentation of Minix components using LLVM passes from
"llvm-apps" repository

In addition, the change does the following:
 1. Move releasetools/generate_gold_plugin.sh to minix/llvm
 2. Move external/bsd/llvm/passes to minix/llvm/passes
 3. libLTO.so, LLVMgold.so and WeakAliasModuleOverride.so files
    now get installed in minix/llvm/bin
2014-07-28 17:06:03 +02:00

159 lines
3.5 KiB
Bash
Executable File

#!/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=
OPTFLAGS=" "
TARGET_MODULES=
MINIX_MODS=
# Set default values for essential variables
: ${GENERATE_MAP="no"}
: ${C="hello"}
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 ] && [ -d ./drivers ] && [ -d ./servers ] ; then
MINIX_ROOT="${MYPWD}"
elif [ -d ../../minix ] && [ -d ../../drivers ] && [ -d ../../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
echo "The LLVM pass file ${llvmpass}.so doesn't exit."
exit_flag=1
fi
LLVMPASS_PATHS+=" -load=${llvmpass_path} -${llvmpass}"
done
if [ ${exit_flag} == 1 ]; then
echo "Searched in:"
echo " ${INSTALL_DIR}"
echo " and"
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
. ${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
# If we are really instrumenting with some pass...
if [ "${LLVMPASS_PATHS}" != "" ]; then
OPTFLAGS=" -disable-opt ${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 SLOPPY_FLIST=yes \
${TOOLDIR}/nbmake-${ARCH} -C $m all install && echo "INFO: $m successfully instrumented." ) || echo "ERROR: Failed instrumenting $m"
echo
done
cd ${MYPWD}