Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asan option #529

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ build_freebsd_task:
else
httplib=none
fi
CXXFLAGS=-fsanitize=address cmake -S . --preset base -D TREMOTESF_QT6=ON -D TREMOTESF_WITH_HTTPLIB="$httplib"
cmake -S . --preset base -D TREMOTESF_QT6=ON -D TREMOTESF_WITH_HTTPLIB="$httplib" -D TREMOTESF_ASAN=ON
echo 'Building Debug'
cmake --build --preset base-debug
echo 'Testing Debug'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ jobs:
id: build
uses: equeim/action-cmake-build@v10
with:
cmake-arguments: --preset macos-${{ matrix.architecture }}-vcpkg
cmake-arguments: --preset macos-${{ matrix.architecture }}-vcpkg -D TREMOTESF_ASAN=${{ inputs.release-tag == '' && 'ON' || 'OFF' }}
package: true
env:
CXXFLAGS: ${{ inputs.release-tag == '' && '-fsanitize=address' || '' }}
ASAN_OPTIONS: detect_leaks=0

- name: Archive packages
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build-windows-msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ jobs:
id: build
uses: equeim/action-cmake-build@v10
with:
cmake-arguments: --preset ${{ inputs.build-with-msvc-clang-toolchain == 'true' && 'windows-msvc-clang-vcpkg' || 'windows-msvc-vcpkg' }} -D VCPKG_INSTALLED_DIR=${{ github.workspace }}/vcpkg_installed
cmake-arguments: --preset ${{ inputs.build-with-msvc-clang-toolchain == 'true' && 'windows-msvc-clang-vcpkg' || 'windows-msvc-vcpkg' }} -D VCPKG_INSTALLED_DIR=${{ github.workspace }}/vcpkg_installed -D TREMOTESF_ASAN=${{ inputs.release-tag == '' && inputs.build-with-msvc-clang-toolchain == 'false' && 'ON' || 'OFF' }}
package: true
env:
CXXFLAGS: ${{ inputs.release-tag == '' && inputs.build-with-msvc-clang-toolchain == 'false' && '/fsanitize=address /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION' || '' }}

- name: Archive packages
if: inputs.release-tag == ''
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

- name: Install build dependencies
run: |
readarray -t dependencies < <(rpmspec ${{steps.fedora-compiler.outputs.rpm-macro}} -q --srpm --qf '[%{REQUIRES}\n]' packaging/rpm/tremotesf.spec)
readarray -t dependencies < <(rpmspec ${{steps.fedora-compiler.outputs.rpm-macro}} --define 'with_asan 1' -q --srpm --qf '[%{REQUIRES}\n]' packaging/rpm/tremotesf.spec)
${{env.INSTALL_PACKAGES}} "${dependencies[@]}"

- name: Make source archive
Expand All @@ -76,7 +76,7 @@ jobs:

- name: Build RPM
run: |
rpmbuild ${{steps.fedora-compiler.outputs.rpm-macro}} -bb packaging/rpm/tremotesf.spec
rpmbuild ${{steps.fedora-compiler.outputs.rpm-macro}} -bb --with asan packaging/rpm/tremotesf.spec

- name: Install RPM
run: |
Expand Down Expand Up @@ -208,8 +208,8 @@ jobs:
run: |
set -e -o pipefail
echo '::group::Configuring CMake'
# Not enabling ASAN here since it causes linker crash
cmake -S . --preset base -D TREMOTESF_QT6=ON -D TREMOTESF_WITH_HTTPLIB=bundled
# ASAN + LTO causes linker crash
cmake -S . --preset base -D TREMOTESF_QT6=ON -D TREMOTESF_WITH_HTTPLIB=bundled -D TREMOTESF_ASAN=ON -D CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE=OFF
echo '::endgroup'
echo '::group::Building Debug'
cmake --build --preset base-debug
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]
### Added
- Dialog is shown when fatal error occurs on Windows
- TREMOTESF_ASAN CMake option to build with AddressSanitizer (off by default)

### Fixed
- Performance regression on Windows (and potential performance improvements on other platforms)
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ endif ()
project(tremotesf VERSION 2.7.0 LANGUAGES ${languages})

option(TREMOTESF_QT6 "Build with Qt 6" ON)
option(TREMOTESF_ASAN "Build with AddressSanitizer" OFF)

set(TREMOTESF_WITH_HTTPLIB "auto" CACHE STRING "Where to find cpp-httplib dependency for unit tests. Possible values are: auto, system, bundled, none")
if (NOT TREMOTESF_WITH_HTTPLIB MATCHES "^(auto|system|bundled|none)$")
Expand Down
11 changes: 11 additions & 0 deletions cmake/CommonOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,25 @@ function(set_common_options_on_targets)
/we4906
/w45204
)
if (TREMOTESF_ASAN)
list(APPEND common_compile_options /fsanitize=address /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(TRANSFORM gcc_style_warnings PREPEND "/clang:")
list(APPEND common_compile_options ${gcc_style_warnings})
if (TREMOTESF_ASAN)
message(WARNING "Ignoring TREMOTESF_ASAN=ON with clang-cl, it doesn't work out of the box")
endif()
endif()
else()
set(
common_compile_options
${gcc_style_warnings}
)
if (TREMOTESF_ASAN)
list(APPEND common_compile_options -fsanitize=address)
list(APPEND common_link_options -fsanitize=address)
endif()
endif()

if (DEFINED TREMOTESF_COMMON_COMPILE_OPTIONS)
Expand Down Expand Up @@ -154,6 +164,7 @@ function(set_common_options_on_targets)
target_compile_options(${target} PRIVATE ${common_compile_options})
target_compile_definitions(${target} PRIVATE ${common_compile_definitions})
target_compile_features(${target} PUBLIC ${common_public_compile_features})
target_link_options(${target} PRIVATE ${common_link_options})
set_target_properties(${target} PROPERTIES ${common_target_properties})
endif()
endforeach()
Expand Down
8 changes: 4 additions & 4 deletions org.equeim.Tremotesf.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
"env": {
"CTEST_OUTPUT_ON_FAILURE": "1",
"ASAN_OPTIONS": "detect_leaks=0"
},
"cxxflags": "-fsanitize=address"
}
},
"config-opts": [
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON",
"-DTREMOTESF_WITH_HTTPLIB=system"
"-DTREMOTESF_WITH_HTTPLIB=system",
"-DTREMOTESF_ASAN=ON"
],
"run-tests": true,
"sources": [
Expand All @@ -99,4 +99,4 @@
]
}
]
}
}
23 changes: 16 additions & 7 deletions packaging/rpm/tremotesf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: CC0-1.0

%bcond asan 0

%global app_id org.equeim.Tremotesf

%if %{defined suse_version} || 0%{?fedora} >= 40
Expand Down Expand Up @@ -47,17 +49,23 @@ BuildRequires: openssl-devel
%if %{defined fedora}
BuildRequires: cmake(httplib)
BuildRequires: libappstream-glib
%if "%{toolchain}" == "clang"
%if "%{toolchain}" == "clang"
BuildRequires: clang
%else
%if %{with asan}
BuildRequires: compiler-rt
%endif
%else
BuildRequires: gcc-c++
%endif
%if %{with asan}
BuildRequires: libasan
%endif
%endif
Requires: qt%{qt_version}-qtsvg
Requires: breeze-icon-theme
%if %{qt_version} == 5
%if %{qt_version} == 5
Requires: kwayland-integration
%endif
%global tremotesf_with_httplib system
%endif
%global tremotesf_with_httplib system
%endif

%if %{defined suse_version}
Expand Down Expand Up @@ -90,10 +98,11 @@ Remote GUI for Transmission BitTorrent client.


%build
%cmake -D TREMOTESF_QT6=%[%{qt_version} == 6 ? "ON" : "OFF"] -D TREMOTESF_WITH_HTTPLIB=%{tremotesf_with_httplib}
%cmake -D TREMOTESF_QT6=%[%{qt_version} == 6 ? "ON" : "OFF"] -D TREMOTESF_WITH_HTTPLIB=%{tremotesf_with_httplib} -D TREMOTESF_ASAN=%{with asan}
%cmake_build

%check
export ASAN_OPTIONS=detect_leaks=0
%ctest

%install
Expand Down
24 changes: 12 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,53 +402,53 @@ if (BUILD_TESTING)

add_executable(itemlistupdater_test itemlistupdater_test.cpp)
add_test(NAME itemlistupdater_test COMMAND itemlistupdater_test)
target_link_libraries(itemlistupdater_test tremotesf_objects Qt::Test)
target_link_libraries(itemlistupdater_test PRIVATE tremotesf_objects Qt::Test)

add_executable(log_test log/log_test.cpp)
add_test(NAME log_test COMMAND log_test)
target_link_libraries(log_test tremotesf_objects Qt::Test)
target_link_libraries(log_test PRIVATE tremotesf_objects Qt::Test)

add_executable(demangle_test log/demangle_test.cpp)
add_test(NAME demangle_test COMMAND demangle_test)
target_link_libraries(demangle_test tremotesf_objects Qt::Test)
target_link_libraries(demangle_test PRIVATE tremotesf_objects Qt::Test)

if (NOT TREMOTESF_WITH_HTTPLIB STREQUAL "none")
include("${CMAKE_SOURCE_DIR}/cmake/FindCppHttplib.cmake")
find_cpp_httplib()
add_executable(requestrouter_test rpc/requestrouter_test.cpp)
target_compile_definitions(requestrouter_test PRIVATE TEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/rpc/test-data" CPPHTTPLIB_OPENSSL_SUPPORT)
add_test(NAME requestrouter_test COMMAND requestrouter_test)
target_link_libraries(requestrouter_test tremotesf_objects Qt::Test)
target_link_libraries(requestrouter_test PRIVATE tremotesf_objects Qt::Test)
if (TARGET PkgConfig::httplib)
target_link_libraries(requestrouter_test PkgConfig::httplib)
target_link_libraries(requestrouter_test PRIVATE PkgConfig::httplib)
else ()
target_link_libraries(requestrouter_test httplib::httplib)
target_link_libraries(requestrouter_test PRIVATE httplib::httplib)
endif ()
endif()

add_executable(pathutils_test rpc/pathutils_test.cpp)
add_test(NAME pathutils_test COMMAND pathutils_test)
target_link_libraries(pathutils_test tremotesf_objects Qt::Test)
target_link_libraries(pathutils_test PRIVATE tremotesf_objects Qt::Test)

add_executable(tracker_test rpc/tracker_test.cpp)
add_test(NAME tracker_test COMMAND tracker_test)
target_link_libraries(tracker_test tremotesf_objects Qt::Test)
target_link_libraries(tracker_test PRIVATE tremotesf_objects Qt::Test)

add_executable(servers_test rpc/servers_test.cpp)
add_test(NAME servers_test COMMAND servers_test)
target_link_libraries(servers_test tremotesf_objects Qt::Test)
target_link_libraries(servers_test PRIVATE tremotesf_objects Qt::Test)

add_executable(coroutines_test coroutines/coroutines_test.cpp)
add_test(NAME coroutines_test COMMAND coroutines_test)
target_link_libraries(coroutines_test tremotesf_objects Qt::Test)
target_link_libraries(coroutines_test PRIVATE tremotesf_objects Qt::Test)

add_executable(magnetlinkparser_test magnetlinkparser_test.cpp)
add_test(NAME magnetlinkparser_test COMMAND magnetlinkparser_test)
target_link_libraries(magnetlinkparser_test tremotesf_objects Qt::Test)
target_link_libraries(magnetlinkparser_test PRIVATE tremotesf_objects Qt::Test)

add_executable(torrentfileparser_test torrentfileparser_test.cpp)
add_test(NAME torrentfileparser_test COMMAND torrentfileparser_test WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test-torrents")
target_link_libraries(torrentfileparser_test tremotesf_objects Qt::Test)
target_link_libraries(torrentfileparser_test PRIVATE tremotesf_objects Qt::Test)
endif ()

set_common_options_on_targets()
Loading