summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@amyspark.me>2022-11-30 18:14:42 -0300
committerDylan Baker <dylan@pnwbakers.com>2024-04-05 15:11:52 -0700
commit82399123797a838d92b60cdc0e56e1b34536aea6 (patch)
treec19e800bb0e271204531b665a48d4735b0493238
parent06bc8a8d37620506ec5d176577fdc9f6ae5f011b (diff)
downloadmeson-82399123797a838d92b60cdc0e56e1b34536aea6.tar.gz
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
-rw-r--r--mesonbuild/compilers/mixins/clike.py12
1 files 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