Skip to content

Commit d42f46f

Browse files
committed
compilers: check for sanitizer arguments via a compiler check
1 parent 4d20e05 commit d42f46f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

mesonbuild/backend/ninjabackend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3507,7 +3507,7 @@ def generate_link(self, target: build.BuildTarget, outname, obj_list, linker: T.
35073507
commands += compilers.get_base_link_args(target.get_options(),
35083508
linker,
35093509
isinstance(target, build.SharedModule),
3510-
self.environment.get_build_dir())
3510+
self.environment)
35113511
# Add -nostdlib if needed; can't be overridden
35123512
commands += self.get_no_stdlib_link_args(target, linker)
35133513
# Add things like /NOLOGO; usually can't be overridden

mesonbuild/compilers/compilers.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,14 @@ def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler',
305305
except (KeyError, AttributeError):
306306
pass
307307
try:
308-
args += compiler.sanitizer_compile_args(options.get_value(OptionKey('b_sanitize')))
308+
sani_opt = options.get_value(OptionKey('b_sanitize'))
309+
assert isinstance(sani_opt, str), 'for mypy'
310+
sani_args = compiler.sanitizer_compile_args(sani_opt)
311+
# We consider that if there are no sanitizer arguments returned, then the language doesn't support them
312+
if sani_args:
313+
if not compiler.has_multi_arguments(sani_args, env)[0]:
314+
raise MesonException(f'Compiler {compiler.name_string()} does not support sanitizer arguments {sani_args}')
315+
args.extend(sani_args)
309316
except (KeyError, AttributeError):
310317
pass
311318
try:
@@ -340,7 +347,7 @@ def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler',
340347
return args
341348

342349
def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
343-
is_shared_module: bool, build_dir: str) -> T.List[str]:
350+
is_shared_module: bool, env: Environment) -> T.List[str]:
344351
args: T.List[str] = []
345352
try:
346353
if options.get_value('b_lto'):
@@ -351,15 +358,21 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
351358
if get_option_value(options, OptionKey('b_thinlto_cache'), False):
352359
thinlto_cache_dir = get_option_value(options, OptionKey('b_thinlto_cache_dir'), '')
353360
if thinlto_cache_dir == '':
354-
thinlto_cache_dir = os.path.join(build_dir, 'meson-private', 'thinlto-cache')
361+
thinlto_cache_dir = os.path.join(env.get_build_dir(), 'meson-private', 'thinlto-cache')
355362
args.extend(linker.get_lto_link_args(
356363
threads=get_option_value(options, OptionKey('b_lto_threads'), 0),
357364
mode=get_option_value(options, OptionKey('b_lto_mode'), 'default'),
358365
thinlto_cache_dir=thinlto_cache_dir))
359366
except (KeyError, AttributeError):
360367
pass
361368
try:
362-
args += linker.sanitizer_link_args(options.get_value('b_sanitize'))
369+
sani_opt = options.get_value(OptionKey('b_sanitize'))
370+
sani_args = linker.sanitizer_link_args(sani_opt)
371+
# We consider that if there are no sanitizer arguments returned, then the language doesn't support them
372+
if sani_args:
373+
if not linker.has_multi_link_arguments(sani_args, env)[0]:
374+
raise MesonException(f'Linker {linker.name_string()} does not support sanitizer arguments {sani_args}')
375+
args.extend(sani_args)
363376
except (KeyError, AttributeError):
364377
pass
365378
try:

0 commit comments

Comments
 (0)