From 8b22b2b144b26ddc116445740ad28835379b6d53 Mon Sep 17 00:00:00 2001 From: Zain K Aamer Date: Thu, 9 Jan 2025 12:41:25 -0500 Subject: [PATCH] [CN-Exec] Add UBSan (w/o alignment) to CI (#825) --- runtime/libcn/libexec/cn-runtime-single-file.sh | 14 ++++++++++---- tests/run-cn-exec.sh | 2 +- tests/run-cn-test-gen.sh | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime/libcn/libexec/cn-runtime-single-file.sh b/runtime/libcn/libexec/cn-runtime-single-file.sh index cdf35555c..e43642757 100755 --- a/runtime/libcn/libexec/cn-runtime-single-file.sh +++ b/runtime/libcn/libexec/cn-runtime-single-file.sh @@ -1,7 +1,7 @@ #!/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" @@ -9,9 +9,10 @@ function echo_and_err() { } QUIET="" +UBSAN="" NO_CHECK_OWNERSHIP="" -while getopts "hnq" flag; do +while getopts "hnqu" flag; do case "$flag" in h) printf "${USAGE}" @@ -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}" ;; @@ -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}." diff --git a/tests/run-cn-exec.sh b/tests/run-cn-exec.sh index 1f7319fd6..903da7a57 100755 --- a/tests/run-cn-exec.sh +++ b/tests/run-cn-exec.sh @@ -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 diff --git a/tests/run-cn-test-gen.sh b/tests/run-cn-test-gen.sh index 2ab15f444..a7753b316 100755 --- a/tests/run-cn-test-gen.sh +++ b/tests/run-cn-test-gen.sh @@ -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')