From 67469792363663f90468eb2a07c8d84ae8dc5c04 Mon Sep 17 00:00:00 2001 From: Leonid Zaburunov Date: Tue, 5 Aug 2025 20:51:24 +0300 Subject: compilers: clike: Deduplicate compile and link args from actually used arg list Current behaviour is to loop over 'sys_args' list which contains both included and ignored compiler arguments. This could produce unexpected results when argument is both ignored and deduplicated. With the following changes, 'cleaned_sys_args' is used to ensure only included args are deduplicated. Example: CFLAGS (or 'c_args' as Meson option) has '-I${includedir} -L${libdir}' and LDFLAGS ('c_link_args') has '-L${libdir}'. Given CFLAGS value is wrong: -L entry belongs to LDFLAGS and thus should not be included in compiler argument list. Since we have -L in 'sys_args' list this entry will not be included as linker flag too! This is definitely not our goal: wrong entry should just be ignored. Some debug prints from Meson: C_ARGS: ['-I/opt/x64-compile/include', '-L/opt/x64-compile/lib'] LINKER_ARGS: ['-L/opt/x64-compile/lib'] RESULT_CARGS: ['-I/opt/x64-compile/include', '-D_FILE_OFFSET_BITS=64'] RESULT_LDARGS: [] (this is captured during compiler.find_library() call) And this is what we see after applying patch: C_ARGS: ['-I/opt/x64-compile/include', '-L/opt/x64-compile/lib'] LINKER_ARGS: ['-L/opt/x64-compile/lib'] RESULT_CARGS: ['-I/opt/x64-compile/include', '-D_FILE_OFFSET_BITS=64'] RESULT_LDARGS: ['-L/opt/x64-compile/lib'] --- mesonbuild/compilers/mixins/clike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index e6637cb1c..ef189124a 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -385,7 +385,7 @@ class CLikeCompiler(Compiler): sys_ld_args = self.environment.coredata.get_external_link_args(self.for_machine, self.language) # CFLAGS and CXXFLAGS go to both linking and compiling, but we want them # to only appear on the command line once. Remove dupes. - largs += [x for x in sys_ld_args if x not in sys_args] + largs += [x for x in sys_ld_args if x not in cleaned_sys_args] cargs += self.get_compiler_args_for_mode(mode) return cargs, largs -- cgit v1.2.3