has_multi_link_arguments: Some compilers needs -Wl,--fatal-warnings

ld does not treat wrong -z options as fatal by default.
pull/3510/head
Xavier Claessens 7 years ago committed by Nirbheek Chauhan
parent d52f892de9
commit 8c381e1786
  1. 14
      mesonbuild/compilers/c.py
  2. 2
      test cases/common/191 has link arg/meson.build

@ -59,6 +59,9 @@ class CCompiler(Compiler):
else:
self.exe_wrapper = exe_wrapper
# Set to None until we actually need to check this
self.has_fatal_warnings_link_arg = None
def needs_static_linker(self):
return True # When compiling static libraries, so yes.
@ -871,6 +874,17 @@ class CCompiler(Compiler):
return self.has_arguments(args, env, code, mode='compile')
def has_multi_link_arguments(self, args, env):
# First time we check for link flags we need to first check if we have
# --fatal-warnings, otherwise some linker checks could give some
# false positive.
fatal_warnings_args = ['-Wl,--fatal-warnings']
if self.has_fatal_warnings_link_arg is None:
self.has_fatal_warnings_link_arg = False
self.has_fatal_warnings_link_arg = self.has_multi_link_arguments(fatal_warnings_args, env)
if self.has_fatal_warnings_link_arg:
args = fatal_warnings_args + args
args = self.linker_to_compiler_args(args)
code = 'int main(int argc, char **argv) { return 0; }'
return self.has_arguments(args, env, code, mode='link')

@ -40,3 +40,5 @@ assert(l2.length() == 0, 'First supported did not return empty array.')
assert(not cc.has_multi_link_arguments([isnt_arg, is_arg]), 'Arg that should be broken is not.')
assert(cc.has_multi_link_arguments(is_arg), 'Arg that should have worked does not work.')
assert(cc.has_multi_link_arguments([useless, is_arg]), 'Arg that should have worked does not work.')
assert(not cc.has_link_argument('-Wl,-z,nodelete42'), 'Did not detect wrong -z linker argument')

Loading…
Cancel
Save