Skip to content

Commit

Permalink
Sanitizer build options (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinfriede authored Sep 2, 2024
1 parent da5613b commit c0eb2d1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
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'
)

0 comments on commit c0eb2d1

Please sign in to comment.