diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-02-27 08:36:47 +0100 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-03-09 18:06:14 -0400 |
| commit | e629d191b99119c360605b056b954fff0905c83f (patch) | |
| tree | d8120f57b96f0d8c854c2f3a653ee62e6808209a /mesonbuild/compilers | |
| parent | 42a8cfc32b71b0d0c8c75e1337482b4a86922efa (diff) | |
| download | meson-e629d191b99119c360605b056b954fff0905c83f.tar.gz | |
compilers: check for sanitizer arguments via a compiler check
The `b_sanitize` option is used to specify which sanitizers to use. This
option is implemented as a combo option, where it only allows a specific
set of hardcoded choices. This implementation isn't quite scalable:
- The number of available sanitizers is steadily growing, so we have
to always catch up with what sanitizers exist out there.
- Sanitizers can be combined more freely nowadays, but we only allow
to combine the "address" and "undefined" sanitizers.
- A hardcoded list is not a good match given that a choice existing as
an option does not mean that it is supported by the compiler in the
first place.
Instead of hardcoding available options, it is way more future proof to
instead allow arbitrary values and perform a compiler check. This makes
us support new sanitizers readily while also providing good feedback to
our users why a specific option might not be allowed.
Implement the compiler checks for sanitizers as a first step. Note that
this does not yet loosen the set of allowed sanitizers as we only accept
hardcoded values as specified by the combo option. This restriction will
be lifted in the next commit.
Diffstat (limited to 'mesonbuild/compilers')
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 5b640781e..27bc44b41 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -308,7 +308,13 @@ def get_base_compile_args(target: 'BuildTarget', compiler: 'Compiler', env: 'Env try: sanitize = env.coredata.get_option_for_target(target, 'b_sanitize') assert isinstance(sanitize, str) - args += compiler.sanitizer_compile_args(sanitize) + sanitize_args = compiler.sanitizer_compile_args(sanitize) + # We consider that if there are no sanitizer arguments returned, then + # the language doesn't support them. + if sanitize_args: + if not compiler.has_multi_arguments(sanitize_args, env)[0]: + raise MesonException(f'Compiler {compiler.name_string()} does not support sanitizer arguments {sanitize_args}') + args.extend(sanitize_args) except KeyError: pass try: @@ -371,7 +377,13 @@ def get_base_link_args(target: 'BuildTarget', try: sanitizer = env.coredata.get_option_for_target(target, 'b_sanitize') assert isinstance(sanitizer, str) - args += linker.sanitizer_link_args(sanitizer) + sanitizer_args = linker.sanitizer_link_args(sanitizer) + # We consider that if there are no sanitizer arguments returned, then + # the language doesn't support them. + if sanitizer_args: + if not linker.has_multi_link_arguments(sanitizer_args, env)[0]: + raise MesonException(f'Linker {linker.name_string()} does not support sanitizer arguments {sanitizer_args}') + args.extend(sanitizer_args) except KeyError: pass try: |
