compilers: convert `b_sanitize` to a free-form array option
In the preceding commit we have started to perform compiler checks for the value of `b_sanitize`, which allows us to detect sanitizers that aren't supported by the compiler toolchain. But we haven't yet loosened the option itself to accept arbitrary values, so until now it's still only possible to pass sanitizer combinations known by Meson, which is quite restrictive. Lift that restriction by adapting the `b_sanitize` option to become a free-form array. Like this, users can pass whatever combination of comma-separated sanitizers to Meson, which will then figure out whether that combination is supported via the compiler checks. This lifts a couple of restrictions and makes the supporting infrastructure way more future proof. A couple of notes regarding backwards compatibility: - All previous values of `b_sanitize` will remain valid as the syntax for free-form array values and valid combo choices is the same. We also treat 'none' specially so that we know to convert it into an empty array. - Even though the option has been converted into a free-form array, callers of `get_option('b_sanitize')` continue to get a string as value. We may eventually want to introduce a kwarg to alter this behaviour, but for now it is expected to be good enough for most use cases. Fixes #8283 Fixes #7761 Fixes #5154 Fixes #1582 Co-authored-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Patrick Steinhardt <ps@pks.im>
This commit is contained in:
parent
e629d191b9
commit
43ea11ea49
|
@ -231,10 +231,20 @@ available on all platforms or with all compilers:
|
||||||
| b_pie | false | true, false | Build position-independent executables (since 0.49.0) |
|
| b_pie | false | true, false | Build position-independent executables (since 0.49.0) |
|
||||||
| b_vscrt | from_buildtype | none, md, mdd, mt, mtd, from_buildtype, static_from_buildtype | VS runtime library to use (since 0.48.0) (static_from_buildtype since 0.56.0) |
|
| b_vscrt | from_buildtype | none, md, mdd, mt, mtd, from_buildtype, static_from_buildtype | VS runtime library to use (since 0.48.0) (static_from_buildtype since 0.56.0) |
|
||||||
|
|
||||||
The value of `b_sanitize` can be one of: `none`, `address`, `thread`,
|
The default and possible values of sanitizers changed in 1.8. Before 1.8 they
|
||||||
`undefined`, `memory`, `leak`, `address,undefined`, but note that some
|
were string values, and restricted to a specific subset of values: `none`,
|
||||||
compilers might not support all of them. For example Visual Studio
|
`address`, `thread`, `undefined`, `memory`, `leak`, or `address,undefined`. In
|
||||||
only supports the address sanitizer.
|
1.8 it was changed to a free form array of sanitizers, which are checked by a
|
||||||
|
compiler and linker check. For backwards compatibility reasons
|
||||||
|
`get_option('b_sanitize')` continues to return a string with the array values
|
||||||
|
separated by a comma. Furthermore:
|
||||||
|
|
||||||
|
- If the `b_sanitize` option is empty, the `'none'` string is returned.
|
||||||
|
|
||||||
|
- If it contains only the values `'address'` and `'undefined'`, they are
|
||||||
|
always returned as the `'address,undefined'` string, in this order.
|
||||||
|
|
||||||
|
- Otherwise, the array elements are returned in undefined order.
|
||||||
|
|
||||||
\* < 0 means disable, == 0 means automatic selection, > 0 sets a specific number to use
|
\* < 0 means disable, == 0 means automatic selection, > 0 sets a specific number to use
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
## Changes to the b_sanitize option
|
||||||
|
|
||||||
|
Before 1.8 the `b_sanitize` option was a combo option, which is an enumerated
|
||||||
|
set of values. In 1.8 this was changed to a free-form array of options where
|
||||||
|
available sanitizers are not hardcoded anymore but instead verified via a
|
||||||
|
compiler check.
|
||||||
|
|
||||||
|
This solves a number of longstanding issues such as:
|
||||||
|
|
||||||
|
- Sanitizers may be supported by a compiler, but not on a specific platform
|
||||||
|
(OpenBSD).
|
||||||
|
- New sanitizers are not recognized by Meson.
|
||||||
|
- Using sanitizers in previously-unsupported combinations.
|
||||||
|
|
||||||
|
To not break backwards compatibility, calling `get_option('b_sanitize')`
|
||||||
|
continues to return the configured value as a string, with a guarantee that
|
||||||
|
`address,undefined` remains ordered.
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2014-2016 The Meson development team
|
# Copyright 2014-2016 The Meson development team
|
||||||
|
# Copyright © 2023-2024 Intel Corporation
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import copy
|
import copy
|
||||||
|
@ -272,7 +273,7 @@ class Vs2010Backend(backends.Backend):
|
||||||
try:
|
try:
|
||||||
self.sanitize = self.environment.coredata.get_option(OptionKey('b_sanitize'))
|
self.sanitize = self.environment.coredata.get_option(OptionKey('b_sanitize'))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.sanitize = 'none'
|
self.sanitize = []
|
||||||
sln_filename = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.sln')
|
sln_filename = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.sln')
|
||||||
projlist = self.generate_projects(vslite_ctx)
|
projlist = self.generate_projects(vslite_ctx)
|
||||||
self.gen_testproj()
|
self.gen_testproj()
|
||||||
|
|
|
@ -222,9 +222,7 @@ BASE_OPTIONS: T.Mapping[OptionKey, options.AnyOptionType] = {
|
||||||
options.UserComboOption('b_lto_mode', 'Select between different LTO modes.', 'default', choices=['default', 'thin']),
|
options.UserComboOption('b_lto_mode', 'Select between different LTO modes.', 'default', choices=['default', 'thin']),
|
||||||
options.UserBooleanOption('b_thinlto_cache', 'Use LLVM ThinLTO caching for faster incremental builds', False),
|
options.UserBooleanOption('b_thinlto_cache', 'Use LLVM ThinLTO caching for faster incremental builds', False),
|
||||||
options.UserStringOption('b_thinlto_cache_dir', 'Directory to store ThinLTO cache objects', ''),
|
options.UserStringOption('b_thinlto_cache_dir', 'Directory to store ThinLTO cache objects', ''),
|
||||||
options.UserComboOption(
|
options.UserStringArrayOption('b_sanitize', 'Code sanitizer to use', []),
|
||||||
'b_sanitize', 'Code sanitizer to use', 'none',
|
|
||||||
choices=['none', 'address', 'thread', 'undefined', 'memory', 'leak', 'address,undefined']),
|
|
||||||
options.UserBooleanOption('b_lundef', 'Use -Wl,--no-undefined when linking', True),
|
options.UserBooleanOption('b_lundef', 'Use -Wl,--no-undefined when linking', True),
|
||||||
options.UserBooleanOption('b_asneeded', 'Use -Wl,--as-needed when linking', True),
|
options.UserBooleanOption('b_asneeded', 'Use -Wl,--as-needed when linking', True),
|
||||||
options.UserComboOption(
|
options.UserComboOption(
|
||||||
|
@ -307,7 +305,9 @@ def get_base_compile_args(target: 'BuildTarget', compiler: 'Compiler', env: 'Env
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
sanitize = env.coredata.get_option_for_target(target, 'b_sanitize')
|
sanitize = env.coredata.get_option_for_target(target, 'b_sanitize')
|
||||||
assert isinstance(sanitize, str)
|
assert isinstance(sanitize, list)
|
||||||
|
if sanitize == ['none']:
|
||||||
|
sanitize = []
|
||||||
sanitize_args = compiler.sanitizer_compile_args(sanitize)
|
sanitize_args = compiler.sanitizer_compile_args(sanitize)
|
||||||
# We consider that if there are no sanitizer arguments returned, then
|
# We consider that if there are no sanitizer arguments returned, then
|
||||||
# the language doesn't support them.
|
# the language doesn't support them.
|
||||||
|
@ -376,7 +376,9 @@ def get_base_link_args(target: 'BuildTarget',
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
sanitizer = env.coredata.get_option_for_target(target, 'b_sanitize')
|
sanitizer = env.coredata.get_option_for_target(target, 'b_sanitize')
|
||||||
assert isinstance(sanitizer, str)
|
assert isinstance(sanitizer, list)
|
||||||
|
if sanitizer == ['none']:
|
||||||
|
sanitizer = []
|
||||||
sanitizer_args = linker.sanitizer_link_args(sanitizer)
|
sanitizer_args = linker.sanitizer_link_args(sanitizer)
|
||||||
# We consider that if there are no sanitizer arguments returned, then
|
# We consider that if there are no sanitizer arguments returned, then
|
||||||
# the language doesn't support them.
|
# the language doesn't support them.
|
||||||
|
@ -1044,10 +1046,10 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
|
||||||
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
|
thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
|
||||||
return self.linker.get_lto_args()
|
return self.linker.get_lto_args()
|
||||||
|
|
||||||
def sanitizer_compile_args(self, value: str) -> T.List[str]:
|
def sanitizer_compile_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def sanitizer_link_args(self, value: str) -> T.List[str]:
|
def sanitizer_link_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
return self.linker.sanitizer_args(value)
|
return self.linker.sanitizer_args(value)
|
||||||
|
|
||||||
def get_asneeded_args(self) -> T.List[str]:
|
def get_asneeded_args(self) -> T.List[str]:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2012-2017 The Meson development team
|
# Copyright 2012-2017 The Meson development team
|
||||||
# Copyright © 2024 Intel Corporation
|
# Copyright © 2023-2024 Intel Corporation
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
@ -700,10 +700,10 @@ class CudaCompiler(Compiler):
|
||||||
# return self._to_host_flags(self.host_compiler.get_optimization_args(optimization_level))
|
# return self._to_host_flags(self.host_compiler.get_optimization_args(optimization_level))
|
||||||
return cuda_optimization_args[optimization_level]
|
return cuda_optimization_args[optimization_level]
|
||||||
|
|
||||||
def sanitizer_compile_args(self, value: str) -> T.List[str]:
|
def sanitizer_compile_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
return self._to_host_flags(self.host_compiler.sanitizer_compile_args(value))
|
return self._to_host_flags(self.host_compiler.sanitizer_compile_args(value))
|
||||||
|
|
||||||
def sanitizer_link_args(self, value: str) -> T.List[str]:
|
def sanitizer_link_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
return self._to_host_flags(self.host_compiler.sanitizer_link_args(value))
|
return self._to_host_flags(self.host_compiler.sanitizer_link_args(value))
|
||||||
|
|
||||||
def get_debug_args(self, is_debug: bool) -> T.List[str]:
|
def get_debug_args(self, is_debug: bool) -> T.List[str]:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2019-2022 The meson development team
|
# Copyright 2019-2022 The meson development team
|
||||||
|
# Copyright © 2023 Intel Corporation
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
@ -495,11 +496,11 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta):
|
||||||
# for their specific arguments
|
# for their specific arguments
|
||||||
return ['-flto']
|
return ['-flto']
|
||||||
|
|
||||||
def sanitizer_compile_args(self, value: str) -> T.List[str]:
|
def sanitizer_compile_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
if value == 'none':
|
if not value:
|
||||||
return []
|
return value
|
||||||
args = ['-fsanitize=' + value]
|
args = ['-fsanitize=' + ','.join(value)]
|
||||||
if 'address' in value: # for -fsanitize=address,undefined
|
if 'address' in value:
|
||||||
args.append('-fno-omit-frame-pointer')
|
args.append('-fno-omit-frame-pointer')
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2019 The Meson development team
|
# Copyright 2019 The Meson development team
|
||||||
|
# Copyright © 2023 Intel Corporation
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ class BasicLinkerIsCompilerMixin(Compiler):
|
||||||
functionality itself.
|
functionality itself.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def sanitizer_link_args(self, value: str) -> T.List[str]:
|
def sanitizer_link_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
|
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2019 The meson development team
|
# Copyright 2019 The meson development team
|
||||||
|
# Copyright © 2023 Intel Corporation
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
@ -166,12 +167,10 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
|
||||||
def get_no_optimization_args(self) -> T.List[str]:
|
def get_no_optimization_args(self) -> T.List[str]:
|
||||||
return ['/Od', '/Oi-']
|
return ['/Od', '/Oi-']
|
||||||
|
|
||||||
def sanitizer_compile_args(self, value: str) -> T.List[str]:
|
def sanitizer_compile_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
if value == 'none':
|
if not value:
|
||||||
return []
|
return value
|
||||||
if value != 'address':
|
return [f'/fsanitize={",".join(value)}']
|
||||||
raise mesonlib.MesonException('VS only supports address sanitizer at the moment.')
|
|
||||||
return ['/fsanitize=address']
|
|
||||||
|
|
||||||
def get_output_args(self, outputname: str) -> T.List[str]:
|
def get_output_args(self, outputname: str) -> T.List[str]:
|
||||||
if self.mode == 'PREPROCESSOR':
|
if self.mode == 'PREPROCESSOR':
|
||||||
|
|
|
@ -1068,14 +1068,14 @@ class Interpreter(InterpreterBase, HoldableObject):
|
||||||
|
|
||||||
@typed_pos_args('get_option', str)
|
@typed_pos_args('get_option', str)
|
||||||
@noKwargs
|
@noKwargs
|
||||||
def func_get_option(self, nodes: mparser.BaseNode, args: T.Tuple[str],
|
def func_get_option(self, node: mparser.BaseNode, args: T.Tuple[str],
|
||||||
kwargs: 'TYPE_kwargs') -> T.Union[options.UserOption, 'TYPE_var']:
|
kwargs: kwtypes.FuncGetOption) -> T.Union[options.UserOption, 'TYPE_var']:
|
||||||
optname = args[0]
|
optname = args[0]
|
||||||
|
|
||||||
if ':' in optname:
|
if ':' in optname:
|
||||||
raise InterpreterException('Having a colon in option name is forbidden, '
|
raise InterpreterException('Having a colon in option name is forbidden, '
|
||||||
'projects are not allowed to directly access '
|
'projects are not allowed to directly access '
|
||||||
'options of other subprojects.')
|
'options of other subprojects.')
|
||||||
|
|
||||||
if optname_regex.search(optname.split('.', maxsplit=1)[-1]) is not None:
|
if optname_regex.search(optname.split('.', maxsplit=1)[-1]) is not None:
|
||||||
raise InterpreterException(f'Invalid option name {optname!r}')
|
raise InterpreterException(f'Invalid option name {optname!r}')
|
||||||
|
|
||||||
|
@ -1096,6 +1096,15 @@ class Interpreter(InterpreterBase, HoldableObject):
|
||||||
ocopy.name = optname
|
ocopy.name = optname
|
||||||
ocopy.value = value
|
ocopy.value = value
|
||||||
return ocopy
|
return ocopy
|
||||||
|
elif optname == 'b_sanitize':
|
||||||
|
assert isinstance(value_object, options.UserStringArrayOption)
|
||||||
|
# To ensure backwards compatibility this always returns a string.
|
||||||
|
# We may eventually want to introduce a new "format" kwarg that
|
||||||
|
# allows the user to modify this behaviour, but for now this is
|
||||||
|
# likely good enough for most usecases.
|
||||||
|
if not value:
|
||||||
|
return 'none'
|
||||||
|
return ','.join(sorted(value))
|
||||||
elif isinstance(value_object, options.UserOption):
|
elif isinstance(value_object, options.UserOption):
|
||||||
if isinstance(value_object.value, str):
|
if isinstance(value_object.value, str):
|
||||||
return P_OBJ.OptionString(value, f'{{{optname}}}')
|
return P_OBJ.OptionString(value, f'{{{optname}}}')
|
||||||
|
@ -3090,7 +3099,7 @@ class Interpreter(InterpreterBase, HoldableObject):
|
||||||
if OptionKey('b_sanitize') not in self.coredata.optstore:
|
if OptionKey('b_sanitize') not in self.coredata.optstore:
|
||||||
return
|
return
|
||||||
if (self.coredata.optstore.get_value('b_lundef') and
|
if (self.coredata.optstore.get_value('b_lundef') and
|
||||||
self.coredata.optstore.get_value('b_sanitize') != 'none'):
|
self.coredata.optstore.get_value('b_sanitize')):
|
||||||
value = self.coredata.optstore.get_value('b_sanitize')
|
value = self.coredata.optstore.get_value('b_sanitize')
|
||||||
mlog.warning(textwrap.dedent(f'''\
|
mlog.warning(textwrap.dedent(f'''\
|
||||||
Trying to use {value} sanitizer on Clang with b_lundef.
|
Trying to use {value} sanitizer on Clang with b_lundef.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2012-2022 The Meson development team
|
# Copyright 2012-2022 The Meson development team
|
||||||
|
# Copyright © 2023 Intel Corporation
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
@ -223,7 +224,7 @@ class DynamicLinker(metaclass=abc.ABCMeta):
|
||||||
def get_thinlto_cache_args(self, path: str) -> T.List[str]:
|
def get_thinlto_cache_args(self, path: str) -> T.List[str]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def sanitizer_args(self, value: str) -> T.List[str]:
|
def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_asneeded_args(self) -> T.List[str]:
|
def get_asneeded_args(self) -> T.List[str]:
|
||||||
|
@ -599,6 +600,9 @@ class PosixDynamicLinkerMixin(DynamicLinkerBase):
|
||||||
def get_search_args(self, dirname: str) -> T.List[str]:
|
def get_search_args(self, dirname: str) -> T.List[str]:
|
||||||
return ['-L' + dirname]
|
return ['-L' + dirname]
|
||||||
|
|
||||||
|
def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class GnuLikeDynamicLinkerMixin(DynamicLinkerBase):
|
class GnuLikeDynamicLinkerMixin(DynamicLinkerBase):
|
||||||
|
|
||||||
|
@ -654,10 +658,10 @@ class GnuLikeDynamicLinkerMixin(DynamicLinkerBase):
|
||||||
def get_lto_args(self) -> T.List[str]:
|
def get_lto_args(self) -> T.List[str]:
|
||||||
return ['-flto']
|
return ['-flto']
|
||||||
|
|
||||||
def sanitizer_args(self, value: str) -> T.List[str]:
|
def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
if value == 'none':
|
if not value:
|
||||||
return []
|
return value
|
||||||
return ['-fsanitize=' + value]
|
return [f'-fsanitize={",".join(value)}']
|
||||||
|
|
||||||
def get_coverage_args(self) -> T.List[str]:
|
def get_coverage_args(self) -> T.List[str]:
|
||||||
return ['--coverage']
|
return ['--coverage']
|
||||||
|
@ -811,10 +815,10 @@ class AppleDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
|
||||||
def get_coverage_args(self) -> T.List[str]:
|
def get_coverage_args(self) -> T.List[str]:
|
||||||
return ['--coverage']
|
return ['--coverage']
|
||||||
|
|
||||||
def sanitizer_args(self, value: str) -> T.List[str]:
|
def sanitizer_args(self, value: T.List[str]) -> T.List[str]:
|
||||||
if value == 'none':
|
if not value:
|
||||||
return []
|
return value
|
||||||
return ['-fsanitize=' + value]
|
return [f'-fsanitize={",".join(value)}']
|
||||||
|
|
||||||
def no_undefined_args(self) -> T.List[str]:
|
def no_undefined_args(self) -> T.List[str]:
|
||||||
# We used to emit -undefined,error, but starting with Xcode 15 /
|
# We used to emit -undefined,error, but starting with Xcode 15 /
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2015-2016 The Meson development team
|
# Copyright 2015-2016 The Meson development team
|
||||||
|
# Copyright © 2023-2024 Intel Corporation
|
||||||
|
|
||||||
'''This module provides helper functions for Gnome/GLib related
|
'''This module provides helper functions for Gnome/GLib related
|
||||||
functionality such as gobject-introspection, gresources and gtk-doc'''
|
functionality such as gobject-introspection, gresources and gtk-doc'''
|
||||||
|
@ -912,9 +913,8 @@ class GnomeModule(ExtensionModule):
|
||||||
cflags += state.project_args[lang]
|
cflags += state.project_args[lang]
|
||||||
if OptionKey('b_sanitize') in compiler.base_options:
|
if OptionKey('b_sanitize') in compiler.base_options:
|
||||||
sanitize = state.environment.coredata.optstore.get_value('b_sanitize')
|
sanitize = state.environment.coredata.optstore.get_value('b_sanitize')
|
||||||
assert isinstance(sanitize, str)
|
assert isinstance(sanitize, list)
|
||||||
cflags += compiler.sanitizer_compile_args(sanitize)
|
cflags += compiler.sanitizer_compile_args(sanitize)
|
||||||
sanitize = sanitize.split(',')
|
|
||||||
# These must be first in ldflags
|
# These must be first in ldflags
|
||||||
if 'address' in sanitize:
|
if 'address' in sanitize:
|
||||||
internal_ldflags += ['-lasan']
|
internal_ldflags += ['-lasan']
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
# Copyright © 2023-2024 Intel Corporation
|
||||||
|
|
||||||
|
project('sanitizer', 'c', meson_version : '>= 1.8')
|
||||||
|
|
||||||
|
summary({
|
||||||
|
'value': get_option('b_sanitize'),
|
||||||
|
}, section: 'summary')
|
|
@ -1,5 +1,6 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright 2016-2021 The Meson development team
|
# Copyright 2016-2021 The Meson development team
|
||||||
|
# Copyright © 2023-2024 Intel Corporation
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
@ -2770,7 +2771,7 @@ class AllPlatformTests(BasePlatformTests):
|
||||||
obj = mesonbuild.coredata.load(self.builddir)
|
obj = mesonbuild.coredata.load(self.builddir)
|
||||||
self.assertEqual(obj.optstore.get_value('bindir'), 'bar')
|
self.assertEqual(obj.optstore.get_value('bindir'), 'bar')
|
||||||
self.assertEqual(obj.optstore.get_value('buildtype'), 'release')
|
self.assertEqual(obj.optstore.get_value('buildtype'), 'release')
|
||||||
self.assertEqual(obj.optstore.get_value('b_sanitize'), 'thread')
|
self.assertEqual(obj.optstore.get_value('b_sanitize'), ['thread'])
|
||||||
self.assertEqual(obj.optstore.get_value(OptionKey('c_args')), ['-Dbar'])
|
self.assertEqual(obj.optstore.get_value(OptionKey('c_args')), ['-Dbar'])
|
||||||
self.setconf(['--bindir=bar', '--bindir=foo',
|
self.setconf(['--bindir=bar', '--bindir=foo',
|
||||||
'-Dbuildtype=release', '-Dbuildtype=plain',
|
'-Dbuildtype=release', '-Dbuildtype=plain',
|
||||||
|
@ -2779,7 +2780,7 @@ class AllPlatformTests(BasePlatformTests):
|
||||||
obj = mesonbuild.coredata.load(self.builddir)
|
obj = mesonbuild.coredata.load(self.builddir)
|
||||||
self.assertEqual(obj.optstore.get_value('bindir'), 'foo')
|
self.assertEqual(obj.optstore.get_value('bindir'), 'foo')
|
||||||
self.assertEqual(obj.optstore.get_value('buildtype'), 'plain')
|
self.assertEqual(obj.optstore.get_value('buildtype'), 'plain')
|
||||||
self.assertEqual(obj.optstore.get_value('b_sanitize'), 'address')
|
self.assertEqual(obj.optstore.get_value('b_sanitize'), ['address'])
|
||||||
self.assertEqual(obj.optstore.get_value(OptionKey('c_args')), ['-Dfoo'])
|
self.assertEqual(obj.optstore.get_value(OptionKey('c_args')), ['-Dfoo'])
|
||||||
self.wipe()
|
self.wipe()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -1930,3 +1930,25 @@ class LinuxlikeTests(BasePlatformTests):
|
||||||
self.check_has_flag(compdb, mainsrc, '-O3')
|
self.check_has_flag(compdb, mainsrc, '-O3')
|
||||||
self.check_has_flag(compdb, sub1src, '-O2')
|
self.check_has_flag(compdb, sub1src, '-O2')
|
||||||
self.check_has_flag(compdb, sub2src, '-O2')
|
self.check_has_flag(compdb, sub2src, '-O2')
|
||||||
|
|
||||||
|
def test_sanitizers(self):
|
||||||
|
testdir = os.path.join(self.unit_test_dir, '125 sanitizers')
|
||||||
|
|
||||||
|
with self.subTest('no b_sanitize value'):
|
||||||
|
try:
|
||||||
|
out = self.init(testdir)
|
||||||
|
self.assertRegex(out, 'value *: *none')
|
||||||
|
finally:
|
||||||
|
self.wipe()
|
||||||
|
|
||||||
|
for value, expected in { '': 'none',
|
||||||
|
'none': 'none',
|
||||||
|
'address': 'address',
|
||||||
|
'undefined,address': 'address,undefined',
|
||||||
|
'address,undefined': 'address,undefined' }.items():
|
||||||
|
with self.subTest('b_sanitize=' + value):
|
||||||
|
try:
|
||||||
|
out = self.init(testdir, extra_args=['-Db_sanitize=' + value])
|
||||||
|
self.assertRegex(out, 'value *: *' + expected)
|
||||||
|
finally:
|
||||||
|
self.wipe()
|
||||||
|
|
Loading…
Reference in New Issue