aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-02-16 12:01:36 -0800
committerJussi Pakkanen <jpakkane@gmail.com>2021-02-17 18:06:52 +0200
commit6c1467db272c4700ae79f74c3541f6ccc4814138 (patch)
tree4602952f770ad183039983aae59ac99791f175a1
parent867963f1315023673abbe3cc823eb6d332ed8f86 (diff)
downloadmeson-6c1467db272c4700ae79f74c3541f6ccc4814138.zip
meson-6c1467db272c4700ae79f74c3541f6ccc4814138.tar.gz
meson-6c1467db272c4700ae79f74c3541f6ccc4814138.tar.bz2
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
-rw-r--r--mesonbuild/compilers/compilers.py6
-rw-r--r--mesonbuild/compilers/mixins/clang.py4
-rw-r--r--mesonbuild/compilers/mixins/islinker.py2
-rwxr-xr-xrun_unittests.py14
4 files changed, 18 insertions, 8 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 8171758..a4823e2 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.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]:
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 1778c31..7531e57 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -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}')
diff --git a/mesonbuild/compilers/mixins/islinker.py b/mesonbuild/compilers/mixins/islinker.py
index 3fe3382..298d47f 100644
--- a/mesonbuild/compilers/mixins/islinker.py
+++ b/mesonbuild/compilers/mixins/islinker.py
@@ -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:
diff --git a/run_unittests.py b/run_unittests.py
index 73be9b7..a41559f 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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'):