From 381ac5b7acb126c458a431d42bc3c131d582d2f1 Mon Sep 17 00:00:00 2001 From: iakov Date: Tue, 30 Jul 2024 14:29:26 +0300 Subject: [PATCH] Use UBSan for release builds (#1733) * Always build with UBSan * Disable some advanced UBSan sub-options ... not recognized by GCC 8.1 * Use GCC 7.3 compatible option for USan * Allow global TRIK_SANITIZE_UNDEFINED_FLAGS * Add UbSan for Windows and rename main.yml to windows_build_with_installer.yml --- ...n.yml => windows_build_with_installer.yml} | 4 +- global.pri | 42 +++++++++++-------- .../robots/thirdparty/trikRuntime/trikRuntime | 2 +- .../thirdparty/trikRuntime/trikRuntime.pro | 6 ++- 4 files changed, 31 insertions(+), 23 deletions(-) rename .github/workflows/{main.yml => windows_build_with_installer.yml} (98%) diff --git a/.github/workflows/main.yml b/.github/workflows/windows_build_with_installer.yml similarity index 98% rename from .github/workflows/main.yml rename to .github/workflows/windows_build_with_installer.yml index 550ddf7104..9fc2b72b0c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/windows_build_with_installer.yml @@ -1,4 +1,4 @@ -name: GHA CI +name: Windows build on: push: branches-ignore: @@ -138,7 +138,7 @@ jobs: timeout-minutes: 1 run: | cd ${{ env.BUILD_DIR }} - qmake $GITHUB_WORKSPACE/studio.pro -spec win32-g++ CONFIG+=release CONFIG+=tests CONFIG+=noPch PYTHON_PATH="${pythonLocation}" # CONFIG+=silent + qmake $GITHUB_WORKSPACE/studio.pro -spec win32-g++ CONFIG+=release CONFIG+=sanitizer CONFIG+=sanitize_undefined CONFIG+=tests CONFIG+=noPch PYTHON_PATH="${pythonLocation}" # CONFIG+=silent - name: QMake all timeout-minutes: 5 diff --git a/global.pri b/global.pri index 5f010bcdb8..5f5575be56 100644 --- a/global.pri +++ b/global.pri @@ -133,7 +133,7 @@ equals(TEMPLATE, lib) { CONFIG += sanitizer } -unix:!nosanitizers { +!nosanitizers { # seems like we want USan always, but are afraid of .... !CONFIG(sanitize_address):!CONFIG(sanitize_thread):!CONFIG(sanitize_memory):!CONFIG(sanitize_kernel_address) { @@ -143,20 +143,25 @@ unix:!nosanitizers { #LSan can be used without performance degrade even in release build - #But at the moment we can not, because of Qt problems - !macx-clang:CONFIG(debug):!CONFIG(sanitize_address):!CONFIG(sanitize_memory):!CONFIG(sanitize_thread) { CONFIG += sanitize_leak } + #But at the moment we can not, because of Qt and MinGW problems + !win32:!macx-clang:CONFIG(debug):!CONFIG(sanitize_address):!CONFIG(sanitize_memory):!CONFIG(sanitize_thread) { CONFIG += sanitize_leak } sanitize_leak { - QMAKE_CFLAGS += -fsanitize=leak - QMAKE_CXXFLAGS += -fsanitize=leak - QMAKE_LFLAGS += -fsanitize=leak + QMAKE_CFLAGS *= -fsanitize=leak + QMAKE_CXXFLAGS *= -fsanitize=leak + QMAKE_LFLAGS *= -fsanitize=leak } - sanitize_undefined:macx-clang { - # sometimes runtime is missing in clang. this hack allows to avoid runtime dependency. - #QMAKE_SANITIZE_UNDEFINED_CFLAGS += -fsanitize-trap=undefined - #QMAKE_SANITIZE_UNDEFINED_CXXFLAGS += -fsanitize-trap=undefined - #QMAKE_SANITIZE_UNDEFINED_LFLAGS += -fsanitize-trap=undefined + sanitize_undefined { + #TRIK_SANITIZE_UNDEFINED_FLAGS += \ + #-fsanitize=undefined,float-divide-by-zero,unsigned-integer-overflow,implicit-conversion,local-bounds + + # This hack allows to avoid runtime dependency. + win32:isEmpty(TRIK_SANITIZE_UNDEFINED_FLAGS):TRIK_SANITIZE_UNDEFINED_FLAGS = -fsanitize-undefined-trap-on-error + + QMAKE_SANITIZE_UNDEFINED_CFLAGS *= $$TRIK_SANITIZE_UNDEFINED_FLAGS + QMAKE_SANITIZE_UNDEFINED_CXXFLAGS *= $$TRIK_SANITIZE_UNDEFINED_FLAGS + QMAKE_SANITIZE_UNDEFINED_LFLAGS *= $$TRIK_SANITIZE_UNDEFINED_FLAGS } sanitize_memory { @@ -165,15 +170,16 @@ unix:!nosanitizers { } + unix { + QMAKE_CFLAGS_RELEASE += -fsanitize-recover=all + QMAKE_CXXFLAGS_RELEASE += -fsanitize-recover=all - QMAKE_CFLAGS_RELEASE += -fsanitize-recover=all - QMAKE_CXXFLAGS_RELEASE += -fsanitize-recover=all + QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -fno-sanitize-recover=all + QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -fno-sanitize-recover=all - QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -fno-sanitize-recover=all - QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -fno-sanitize-recover=all - - QMAKE_CFLAGS_DEBUG += -fno-sanitize-recover=all - QMAKE_CXXFLAGS_DEBUG += -fno-sanitize-recover=all + QMAKE_CFLAGS_DEBUG += -fno-sanitize-recover=all + QMAKE_CXXFLAGS_DEBUG += -fno-sanitize-recover=all + } } OBJECTS_DIR = .build/$$CONFIGURATION/obj diff --git a/plugins/robots/thirdparty/trikRuntime/trikRuntime b/plugins/robots/thirdparty/trikRuntime/trikRuntime index 29b4ecd8fa..7e6b41b8a9 160000 --- a/plugins/robots/thirdparty/trikRuntime/trikRuntime +++ b/plugins/robots/thirdparty/trikRuntime/trikRuntime @@ -1 +1 @@ -Subproject commit 29b4ecd8fa527fea8e3abbc719966f4e7a88b2fa +Subproject commit 7e6b41b8a98d8edb5bfafaa0c00bb139eb9dc122 diff --git a/plugins/robots/thirdparty/trikRuntime/trikRuntime.pro b/plugins/robots/thirdparty/trikRuntime/trikRuntime.pro index caba42f9c7..0046f60924 100644 --- a/plugins/robots/thirdparty/trikRuntime/trikRuntime.pro +++ b/plugins/robots/thirdparty/trikRuntime/trikRuntime.pro @@ -16,6 +16,7 @@ TEMPLATE = subdirs include(../../../../global.pri) SUBDIRS += \ + trikRuntimeQsLog \ trikKernel \ trikNetwork \ trikControl \ @@ -26,7 +27,7 @@ SUBDIRS += \ tests { SUBDIRS *= tests - tests.depends = trikScriptRunner trikCommunicator trikKernel + tests.depends = trikScriptRunner trikCommunicator trikKernel trikRuntimeQsLog tests.subdir = $$PWD/trikRuntime/tests } @@ -43,8 +44,9 @@ trikNetwork.subdir = $$PWD/trikRuntime/trikNetwork trikControl.subdir = $$PWD/trikRuntime/trikControl translations.subdir = $$PWD/trikRuntime/translations trikHal.subdir = $$PWD/trikRuntime/trikHal +trikRuntimeQsLog.file = $$PWD/trikRuntime/qslog/QsLogSharedLibrary.pro trikControl.depends = trikKernel trikHal -trikKernel.depends = +trikKernel.depends = trikRuntimeQsLog trikNetwork.depends = trikKernel trikScriptRunner.depends += trikControl trikKernel trikNetwork trikHal.depends = trikKernel