Skip to content

Commit

Permalink
[CN-Exec] Add UBSan (w/o alignment) to CI (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZippeyKeys12 authored Jan 9, 2025
1 parent 6c3ad3f commit 8b22b2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 10 additions & 4 deletions runtime/libcn/libexec/cn-runtime-single-file.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/bin/bash
set -euo pipefail -o noclobber

USAGE="USAGE: $0 -h\n $0 [-nvq] FILE.c"
USAGE="USAGE: $0 -h\n $0 [-nqu] FILE.c"

function echo_and_err() {
printf "$1\n"
exit 1
}

QUIET=""
UBSAN=""
NO_CHECK_OWNERSHIP=""

while getopts "hnq" flag; do
while getopts "hnqu" flag; do
case "$flag" in
h)
printf "${USAGE}"
Expand All @@ -23,6 +24,11 @@ while getopts "hnq" flag; do
q)
QUIET=1
;;
u)
export UBSAN_OPTIONS=halt_on_error=1
# FIXME: https://github.com/rems-project/cerberus/issues/821
UBSAN="-fsanitize=undefined -fno-sanitize=alignment"
;;
\?)
echo_and_err "${USAGE}"
;;
Expand Down Expand Up @@ -65,14 +71,14 @@ fi

# Compile
cd "${EXEC_DIR}"
if cc -g -c "-I${RUNTIME_PREFIX}"/include/ ./"${INPUT_BASENAME}-exec.c" cn.c; then
if cc -g -c ${UBSAN} "-I${RUNTIME_PREFIX}"/include/ ./"${INPUT_BASENAME}-exec.c" cn.c; then
[ "${QUIET}" ] || echo "Compiled C files."
else
echo_and_err "Failed to compile C files in ${EXEC_DIR}."
fi

# Link
if cc "-I${RUNTIME_PREFIX}/include" -o "${INPUT_BASENAME}-exec-output.bin" ./*.o "${RUNTIME_PREFIX}/libcn.a"; then
if cc ${UBSAN} "-I${RUNTIME_PREFIX}/include" -o "${INPUT_BASENAME}-exec-output.bin" ./*.o "${RUNTIME_PREFIX}/libcn.a"; then
[ "${QUIET}" ] || echo "Linked C .o files."
else
echo_and_err "Failed to link .o files in ${EXEC_DIR}."
Expand Down
2 changes: 1 addition & 1 deletion tests/run-cn-exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CHECK_SCRIPT="${RUNTIME_PREFIX}/libexec/cn-runtime-single-file.sh"

[ -f "${CHECK_SCRIPT}" ] || echo_and_err "Could not find single file helper script: ${CHECK_SCRIPT}"

SCRIPT_OPT="-q"
SCRIPT_OPT="-qu"

function exits_with_code() {
local file=$1
Expand Down
3 changes: 3 additions & 0 deletions tests/run-cn-test-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ cd "$DIRNAME"/cn-test-gen || exit
rm -rf build decorated test
mkdir build decorated test

# For UBSan
export UBSAN_OPTIONS=halt_on_error=1

# Get `*.c` files
FILES=$(find "$DIRNAME"/src -name '*.c')

Expand Down

0 comments on commit 8b22b2b

Please sign in to comment.