Skip to content

Commit 6746979

Browse files
Zaburunierdcbaker
authored andcommitted
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']
1 parent c8a7fd7 commit 6746979

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mesonbuild/compilers/mixins/clike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def _get_basic_compiler_args(self, mode: CompileCheckMode) -> T.Tuple[T.List[str
385385
sys_ld_args = self.environment.coredata.get_external_link_args(self.for_machine, self.language)
386386
# CFLAGS and CXXFLAGS go to both linking and compiling, but we want them
387387
# to only appear on the command line once. Remove dupes.
388-
largs += [x for x in sys_ld_args if x not in sys_args]
388+
largs += [x for x in sys_ld_args if x not in cleaned_sys_args]
389389

390390
cargs += self.get_compiler_args_for_mode(mode)
391391
return cargs, largs

0 commit comments

Comments
 (0)