Skip to content

Commit

Permalink
compilers: check for sanitizer arguments via a compiler check
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Sep 20, 2024
1 parent 5cc38ff commit 87bf44a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3444,7 +3444,7 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.
commands += compilers.get_base_link_args(target.get_options(),
linker,
isinstance(target, build.SharedModule),
self.environment.get_build_dir())
self.environment)
# Add -nostdlib if needed; can't be overridden
commands += self.get_no_stdlib_link_args(target, linker)
# Add things like /NOLOGO; usually can't be overridden
Expand Down
21 changes: 17 additions & 4 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,14 @@ def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler',
except (KeyError, AttributeError):
pass
try:
args += compiler.sanitizer_compile_args(options.get_value(OptionKey('b_sanitize')))
sani_opt = options.get_value(OptionKey('b_sanitize'))
assert isinstance(sani_opt, str), 'for mypy'
sani_args = compiler.sanitizer_compile_args(sani_opt)
# We consider that if there are no sanitizer arguments returned, then the language doesn't support them
if sani_args:
if not compiler.has_multi_arguments(sani_args, env)[0]:
raise MesonException(f'Compiler {compiler.name_string()} does not support sanitizer arguments {sani_args}')
args.extend(sani_args)
except (KeyError, AttributeError):
pass
try:
Expand Down Expand Up @@ -335,7 +342,7 @@ def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler',
return args

def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
is_shared_module: bool, build_dir: str) -> T.List[str]:
is_shared_module: bool, env: Environment) -> T.List[str]:
args: T.List[str] = []
try:
if options.get_value('b_lto'):
Expand All @@ -346,15 +353,21 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
if get_option_value(options, OptionKey('b_thinlto_cache'), False):
thinlto_cache_dir = get_option_value(options, OptionKey('b_thinlto_cache_dir'), '')
if thinlto_cache_dir == '':
thinlto_cache_dir = os.path.join(build_dir, 'meson-private', 'thinlto-cache')
thinlto_cache_dir = os.path.join(env.get_build_dir(), 'meson-private', 'thinlto-cache')
args.extend(linker.get_lto_link_args(
threads=get_option_value(options, OptionKey('b_lto_threads'), 0),
mode=get_option_value(options, OptionKey('b_lto_mode'), 'default'),
thinlto_cache_dir=thinlto_cache_dir))
except (KeyError, AttributeError):
pass
try:
args += linker.sanitizer_link_args(options.get_value('b_sanitize'))
sani_opt = options.get_value(OptionKey('b_sanitize'))
sani_args = linker.sanitizer_link_args(sani_opt)
# We consider that if there are no sanitizer arguments returned, then the language doesn't support them
if sani_args:
if not linker.has_multi_link_arguments(sani_args, env)[0]:
raise MesonException(f'Linker {linker.name_string()} does not support sanitizer arguments {sani_args}')
args.extend(sani_args)
except (KeyError, AttributeError):
pass
try:
Expand Down

0 comments on commit 87bf44a

Please sign in to comment.