fix ubsan for `test_libnimbus_lc` (#5258)

Pass `-fsanitize=undefined` flag when compiling `test_libnimbus_lc`
when building in ubsan mode.
This commit is contained in:
Etan Kissling 2023-08-07 07:57:56 +02:00 committed by GitHub
parent 6d24e73f8d
commit c26e8132fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -106,6 +106,7 @@ jobs:
# Stack usage test and UBSAN on recent enough gcc: # Stack usage test and UBSAN on recent enough gcc:
if [[ '${{ runner.os }}' == 'Linux' && '${{ matrix.target.cpu }}' == 'amd64' ]]; then if [[ '${{ runner.os }}' == 'Linux' && '${{ matrix.target.cpu }}' == 'amd64' ]]; then
if [[ '${{ github.sha }}' =~ ^7 ]]; then if [[ '${{ github.sha }}' =~ ^7 ]]; then
export WITH_UBSAN=1 >> $GITHUB_ENV
export NIMFLAGS="${NIMFLAGS} -d:limitStackUsage --passC:-fsanitize=undefined --passL:-fsanitize=undefined" export NIMFLAGS="${NIMFLAGS} -d:limitStackUsage --passC:-fsanitize=undefined --passL:-fsanitize=undefined"
else else
export NIMFLAGS="${NIMFLAGS} -d:limitStackUsage" export NIMFLAGS="${NIMFLAGS} -d:limitStackUsage"

View File

@ -756,18 +756,29 @@ libnimbus_lc.a: | build deps
echo -e $(BUILD_END_MSG) "build/$@" echo -e $(BUILD_END_MSG) "build/$@"
# `-Wno-maybe-uninitialized` in Linux: https://github.com/nim-lang/Nim/issues/22246 # `-Wno-maybe-uninitialized` in Linux: https://github.com/nim-lang/Nim/issues/22246
# `-fsanitize=undefined` in Windows: https://github.com/msys2/MINGW-packages/issues/3163
test_libnimbus_lc: libnimbus_lc.a test_libnimbus_lc: libnimbus_lc.a
+ echo -e $(BUILD_MSG) "build/$@" && \ + echo -e $(BUILD_MSG) "build/$@" && \
set -x && \ set -x && \
EXTRA_FLAGS=() && \
case "$$(uname)" in \ case "$$(uname)" in \
Darwin) \ Darwin) \
clang -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Weverything -Werror -Wno-declaration-after-statement -Wno-nullability-extension -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o build/test_libnimbus_lc beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a -framework Security; \ if (( $${WITH_UBSAN:-0} )); then \
EXTRA_FLAGS+=('-fsanitize=undefined'); \
fi; \
clang -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Weverything -Werror -Wno-declaration-after-statement -Wno-nullability-extension -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o build/test_libnimbus_lc beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a -framework Security "$${EXTRA_FLAGS[@]}"; \
;; \ ;; \
MINGW64_*) \ MINGW64_*) \
gcc -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Wall -Wextra -pedantic -Werror -pedantic-errors -flto -o build/test_libnimbus_lc -D_CRT_SECURE_NO_WARNINGS beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a; \ if (( $${WITH_UBSAN:-0} )); then \
echo "MINGW cannot find -lubsan." && exit 1; \
fi; \
gcc -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Wall -Wextra -pedantic -Werror -pedantic-errors -flto -o build/test_libnimbus_lc -D_CRT_SECURE_NO_WARNINGS beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a "$${EXTRA_FLAGS[@]}"; \
;; \ ;; \
*) \ *) \
gcc -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Wall -Wextra -pedantic -Werror -pedantic-errors -Wno-maybe-uninitialized -flto -o build/test_libnimbus_lc beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a; \ if (( $${WITH_UBSAN:-0} )); then \
EXTRA_FLAGS+=('-fsanitize=undefined'); \
fi; \
gcc -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Wall -Wextra -pedantic -Werror -pedantic-errors -Wno-maybe-uninitialized -flto -o build/test_libnimbus_lc beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a "$${EXTRA_FLAGS[@]}"; \
;; \ ;; \
esac && \ esac && \
echo -e $(BUILD_END_MSG) "build/$@" echo -e $(BUILD_END_MSG) "build/$@"