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

Sanitizer build options #34

Merged
merged 9 commits into from
Sep 2, 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
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
gcc_v: [9, 10, 11, 12]
sanitizer: [none, asan, msan, tsan]
buildtype: [debug]

include:
- os: ubuntu-22.04
gcc_v: 12
sanitizer: none
buildtype: release

env:
FC: gfortran
Expand All @@ -59,6 +67,12 @@ jobs:
ln -s /usr/local/bin/g++-${{ env.GCC_V }} /usr/local/bin/g++

- name: Install GCC (Linux)
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-${{ env.GCC_V }} g++-${{ env.GCC_V }} gfortran-${{ env.GCC_V }}

- name: Set GCC Version (Linux)
if: contains(matrix.os, 'ubuntu')
run: >-
sudo update-alternatives
Expand All @@ -76,10 +90,11 @@ jobs:
- name: Configure build
run: >-
meson setup ${{ env.M_BUILD_DIR }}
--buildtype=debug
--buildtype=${{ matrix.buildtype }}
--prefix=$PWD/_dist
--libdir=lib
--warnlevel=0
-Dsanitizer=${{ matrix.sanitizer }}
-Db_coverage=${{ env.COVERAGE }}
env:
COVERAGE: ${{ contains(matrix.os, 'ubuntu') && 'true' || 'false' }}
Expand Down
38 changes: 38 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,49 @@ project(
meson_version: '>=0.51',
default_options: [
'default_library=both',
'warning_level=3',
],
)

cxx = meson.get_compiler('cpp')


if get_option('buildtype') == 'debug'
add_project_arguments(
[
'-Wzero-as-null-pointer-constant',
'-Wlogical-not-parentheses',
'-Db_sanitize=address,undefined'
],
language: 'cpp'
)

add_project_arguments('-fno-omit-frame-pointer', language: 'cpp')
add_project_link_arguments('-fno-omit-frame-pointer', language: 'cpp')

sanitizer = get_option('sanitizer')
if sanitizer == 'asan'
message('Enabling ASan + UBSan + LSan')
add_project_arguments('-Db_sanitize=address,undefined', language: 'cpp')

message('Adding "-fsanitize-address-use-after-scope" argument (ignore the subsequent warnings).')
add_project_arguments('-fsanitize-address-use-after-scope', language: 'cpp')
add_project_link_arguments('-fsanitize-address-use-after-scope', '-fno-omit-frame-pointer', language: 'cpp')

elif sanitizer == 'msan'
message('Enabling Memory Sanitizer (MSan)')
add_project_arguments('-Db_sanitize=memory', language: 'cpp')

elif sanitizer == 'tsan'
message('Enabling Thread Sanitizer (TSan)')
add_project_arguments('-Db_sanitize=thread', language: 'cpp')

else
message('No sanitizers enabled')
endif
endif


deps = []
foreach lib: ['cblas', 'lapacke']
this_dep = dependency(lib, required: false)
Expand Down
8 changes: 8 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
option(
'sanitizer',
type: 'combo',
choices: ['none', 'asan', 'msan', 'tsan'],
value: 'none',
description:
'Choose a set of sanitizers to enable'
)
Loading