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.
pull/12277/merge
Dylan Baker 1 month ago committed by Eli Schwartz
parent 42a8cfc32b
commit e629d191b9
  1. 16
      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:

Loading…
Cancel
Save