compilers: Only insert -flto-jobs in clang's link arguments

Clang has a hand `-Wunused-command-line-argument` switch, which when
turned to an error, gets very grump about `-flto-jobs=0` being set in
the compiler arguments (although `-flto=` belongs there). We'll refactor
a bit to put that only in the link arguments.

GCC doesn't have this probably because, a) it doesn't have an equivalent
warning, and b) it uses `-flto=<$numthreads.

Fixes: #8347
pull/8380/head
Dylan Baker 4 years ago committed by Jussi Pakkanen
parent 867963f131
commit 6c1467db27
  1. 6
      mesonbuild/compilers/compilers.py
  2. 4
      mesonbuild/compilers/mixins/clang.py
  3. 2
      mesonbuild/compilers/mixins/islinker.py
  4. 14
      run_unittests.py

@ -375,7 +375,9 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
args = [] # type: T.List[str]
try:
if options[OptionKey('b_lto')].value:
args.extend(linker.get_lto_link_args())
args.extend(linker.get_lto_link_args(
threads=get_option_value(options, OptionKey('b_lto_threads'), 0),
mode=get_option_value(options, OptionKey('b_lto_mode'), 'default')))
except KeyError:
pass
try:
@ -950,7 +952,7 @@ class Compiler(metaclass=abc.ABCMeta):
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
return []
def get_lto_link_args(self) -> T.List[str]:
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
return self.linker.get_lto_args()
def sanitizer_compile_args(self, value: str) -> T.List[str]:

@ -148,6 +148,10 @@ class ClangCompiler(GnuLikeCompiler):
else:
assert mode == 'default', 'someone forgot to wire something up'
args.extend(super().get_lto_compile_args(threads=threads))
return args
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
args = self.get_lto_compile_args(threads=threads, mode=mode)
# In clang -flto=0 means auto
if threads >= 0:
args.append(f'-flto-jobs={threads}')

@ -48,7 +48,7 @@ class BasicLinkerIsCompilerMixin(Compiler):
def sanitizer_link_args(self, value: str) -> T.List[str]:
return []
def get_lto_link_args(self) -> T.List[str]:
def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
return []
def can_linker_accept_rsp(self) -> bool:

@ -3062,10 +3062,14 @@ class AllPlatformTests(BasePlatformTests):
env = get_fake_env(testdir, self.builddir, self.prefix)
cc = env.detect_c_compiler(MachineChoice.HOST)
if cc.get_id() == 'clang' and is_windows():
raise unittest.SkipTest('LTO not (yet) supported by windows clang')
extra_args: T.List[str] = []
if cc.get_id() == 'clang':
if is_windows():
raise unittest.SkipTest('LTO not (yet) supported by windows clang')
else:
extra_args.append('-D_cargs=-Werror=unused-command-line-argument')
self.init(testdir, extra_args=['-Db_lto=true', '-Db_lto_threads=8'])
self.init(testdir, extra_args=['-Db_lto=true', '-Db_lto_threads=8'] + extra_args)
self.build()
self.run_tests()
@ -3091,7 +3095,7 @@ class AllPlatformTests(BasePlatformTests):
elif is_windows():
raise unittest.SkipTest('LTO not (yet) supported by windows clang')
self.init(testdir, extra_args=['-Db_lto=true', '-Db_lto_mode=thin', '-Db_lto_threads=8'])
self.init(testdir, extra_args=['-Db_lto=true', '-Db_lto_mode=thin', '-Db_lto_threads=8', '-Dc_args=-Werror=unused-command-line-argument'])
self.build()
self.run_tests()
@ -3100,7 +3104,7 @@ class AllPlatformTests(BasePlatformTests):
# This assumes all of the targets support lto
for t in targets:
for s in t['target_sources']:
assert expected.issubset(set(s['parameters'])), f'Incorrect values for {t["name"]}'
self.assertTrue(expected.issubset(set(s['parameters'])), f'Incorrect values for {t["name"]}')
def test_dist_git(self):
if not shutil.which('git'):

Loading…
Cancel
Save