From 82399123797a838d92b60cdc0e56e1b34536aea6 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Wed, 30 Nov 2022 18:14:42 -0300 Subject: compilers: Ensure -L flags do not get reordered when used with MSVC If -L flags get into CLikeCompiler::build_wrapper_args, they will be correctly detected and the /LINK flag added to the list. However, CompilerArgs::__iadd__ will reorder them to the front, thinking they're GNU-style flags, and this will cause MSVC to ignore them after conversion. The fix is twofold: 1. Convert all the linker args into their compiler form, making sure the /LINK argument is dropped (see 2) 2. Insert /LINK into extra_args if not already present 3. Execute in situ the unix_to_native replacement, ensuring no further reordering occurs. Fixes #11113 --- mesonbuild/compilers/mixins/clike.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index b58b163a6..ac2344bf8 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -440,14 +440,20 @@ class CLikeCompiler(Compiler): ca, la = self._get_basic_compiler_args(env, mode) cargs += ca - largs += la cargs += self.get_compiler_check_args(mode) # on MSVC compiler and linker flags must be separated by the "/link" argument # at this point, the '/link' argument may already be part of extra_args, otherwise, it is added here - if self.linker_to_compiler_args([]) == ['/link'] and largs != [] and '/link' not in extra_args: - extra_args += ['/link'] + largs += [l for l in self.linker_to_compiler_args(la) if l != '/link'] + + if self.linker_to_compiler_args([]) == ['/link']: + if largs != [] and '/link' not in extra_args: + extra_args += ['/link'] + # all linker flags must be converted now, otherwise the reordering + # of arglist will apply and -L flags will be reordered into + # breaking form. See arglist._should_prepend + largs = self.unix_args_to_native(largs) args = cargs + extra_args + largs return args -- cgit v1.2.3