From 6a70ad2c1d800c1acaf6bc703dc258b2cc81a48c Mon Sep 17 00:00:00 2001 From: Lev Stipakov Date: Tue, 29 Aug 2023 14:08:05 +0300 Subject: [PATCH] CMake: add ASAN build configuration Add ASAN build configuration, based on debug with ASAN enabled. This might help finding crashes like in https://github.com/OpenVPN/openvpn-gui/issues/548 Signed-off-by: Lev Stipakov --- .github/workflows/msbuild.yml | 19 +++++++++++++------ CMakeLists.txt | 23 ++++++++++++++++++++--- CMakePresets.json | 5 +++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index e766bad5..31351e8d 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -31,6 +31,9 @@ jobs: strategy: matrix: arch: [x86, x64, arm64] + conf: + - name: "" + value: "release" ovpn3: - preset: "" name: "" @@ -38,8 +41,13 @@ jobs: - preset: -ovpn3 name: "- ovpn3" upload_name: "_ovpn3" + include: + - conf: + name: " ASAN" + value: "asan" + arch: x64 - name: 'msvc - ${{matrix.arch}} ${{ matrix.ovpn3.name }}' + name: 'msvc - ${{matrix.arch}} ${{ matrix.ovpn3.name }}${{ matrix.conf.name }}' runs-on: windows-latest steps: - uses: actions/checkout@v3 @@ -55,14 +63,14 @@ jobs: uses: lukka/run-cmake@v10 with: configurePreset: '${{ matrix.arch }}${{ matrix.ovpn3.preset }}' - buildPreset: '${{ matrix.arch }}-release${{ matrix.ovpn3.preset }}' + buildPreset: '${{ matrix.arch }}-${{ matrix.conf.value }}${{ matrix.ovpn3.preset }}' - uses: actions/upload-artifact@v3 with: - name: openvpn-gui_${{ matrix.arch }}${{ matrix.ovpn3.upload_name }} + name: openvpn-gui_${{ matrix.arch }}_${{ matrix.conf }}${{ matrix.ovpn3.upload_name }} path: | - out/build/${{ matrix.arch }}${{ matrix.ovpn3.preset }}/Release/*.dll - out/build/${{ matrix.arch }}${{ matrix.ovpn3.preset }}/Release/*.exe + out/build/${{ matrix.arch }}${{ matrix.ovpn3.preset }}/${{ matrix.conf.value }}/*.dll + out/build/${{ matrix.arch }}${{ matrix.ovpn3.preset }}/${{ matrix.conf.value }}/*.exe mingw: strategy: @@ -107,4 +115,3 @@ jobs: - name: make run: make working-directory: openvpn-gui - diff --git a/CMakeLists.txt b/CMakeLists.txt index a686c3ff..051783fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,24 @@ add_executable(${PROJECT_NAME} WIN32 res/openvpn-gui-res.rc) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} /guard:cf /Qspectre") + +if(MSVC) + list(APPEND CMAKE_CONFIGURATION_TYPES Asan) +endif(MSVC) + +set(CMAKE_C_FLAGS_ASAN + "${CMAKE_C_FLAGS_DEBUG} /fsanitize=address" CACHE STRING + "Flags used by the C compiler during AddressSanitizer builds." FORCE) + +set(CMAKE_EXE_LINKER_FLAGS_ASAN + "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING + "Flags used by the linker during AddressSanitizer builds." FORCE) + +set(CMAKE_SHARED_LINKER_FLAGS_ASAN + "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING + "Flags used by the linker during AddressSanitizer builds." FORCE) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf /Qspectre") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf /DYNAMICBASE") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /wd4267 /wd4244") @@ -160,5 +176,6 @@ if(MSVC) "$<$:/OPT:ICF>") endif(MSVC) -set_target_properties(${TEST_PLAP_EXE} PROPERTIES - LINK_FLAGS " /MANIFEST:EMBED /MANIFESTINPUT:${CMAKE_SOURCE_DIR}/plap/test-plap.manifest ") +target_link_options(${TEST_PLAP_EXE} PRIVATE + "/MANIFEST:EMBED" + "/MANIFESTINPUT:${CMAKE_SOURCE_DIR}/plap/test-plap.manifest") diff --git a/CMakePresets.json b/CMakePresets.json index 8654f084..87f1ecbd 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -76,6 +76,11 @@ "configurePreset": "x64", "configuration": "Debug" }, + { + "name": "x64-asan", + "configurePreset": "x64", + "configuration": "Asan" + }, { "name": "x86-debug", "configurePreset": "x86",