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
pull/13047/head
L. E. Segovia 2 years ago committed by Dylan Baker
parent 06bc8a8d37
commit 8239912379
  1. 12
      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

Loading…
Cancel
Save