minix/minix/llvm/build.llvm
David van Moolenbroek 76b68f9f99 Disable malloc instrumentation for VM (#1)
This patch changes the VM makefile to specify that the magic pass is
to skip memory function instrumentation, and to transfer the data
variables of the malloc code (thus overriding the exception we made
for all other system services).  We add two magic pass flags to
achieve this.  Since the magic pass is a big bowl of spaghetti code,
ignoring whitespace changes while viewing this patch is recommended.

Change-Id: I5ab83b23d8437b37c44dea99537bc202469c9df6
2015-09-17 14:05:14 +00:00

163 lines
3.6 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=
LLVMARGS=
LLVMPASS_PATHS=
TARGET_MODULES=
MINIX_MODS=
# Set default values for essential variables
: ${GENERATE_MAP="no"}
: ${C="servers,fs,net,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
. ${MINIX_LLVM_DIR}/minix.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" -e "s/ rd / ramdisk memory /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 : $@"
echo "LLVM pass arguments : ${LLVMARGS}"
echo "Target Minix modules : ${MINIX_MODS}"
echo "OPTFLAGS value : ${OPTFLAGS}"
echo
cd ${MINIX_ROOT}
OPTFLAGS=`echo ${OPTFLAGS} | sed -e 's/\\$/$$/g'`
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
if [ "$n" == "ramdisk" ] || [ "$n" == "memory" ]; then
(cd minix/llvm && C=$n ./relink.llvm)
continue
fi
clean_module $n $m
( ${TOOLDIR}/nbmake-${ARCH} -C $m all install MKBITCODE=yes OPTFLAGS="${OPTFLAGS}" \
&& echo "INFO: $m successfully instrumented."
)
echo
done
cd ${MYPWD}