summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2025-03-11 04:55:11 +0000
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-11-09 12:37:40 +0200
commitaf3c6dd72a3e55598150cd3e922b11cc3a00b95e (patch)
tree0949533af7b5dd33f810cf11067faf8f591443ad
parent906f376b52730ab3721d17d749a44dee9efcd633 (diff)
downloadmeson-af3c6dd72a3e55598150cd3e922b11cc3a00b95e.tar.gz
compilers: gnu: implement get_lto_link_args
Without this, we pass (say) `-flto=auto` at compile-time, but just `-flto` at link-time. See also https://gcc.gnu.org/PR114655 and the linked r12-824-g3cbcb5d0cfcd17, i.e. before GCC 12, we'd end up linking with 1 job. The clang mixin looks correct already. Closes: https://github.com/mesonbuild/meson/issues/9536
-rw-r--r--mesonbuild/compilers/mixins/gnu.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index 239d7ef3a..fa34bb4ca 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -623,7 +623,7 @@ class GnuCompiler(GnuLikeCompiler):
if threads == 0:
if self._has_lto_auto_support:
return ['-flto=auto']
- # This matches clang's behavior of using the number of cpus, but
+ # This matches gcc's behavior of using the number of cpus, but
# obeying meson's MESON_NUM_PROCESSES convention.
return [f'-flto={mesonlib.determine_worker_count()}']
elif threads > 0:
@@ -636,6 +636,22 @@ class GnuCompiler(GnuLikeCompiler):
return ['-fuse-ld=mold']
return super().use_linker_args(linker, version)
+ def get_lto_link_args(self, *, threads: int = 0, mode: str = 'default',
+ thinlto_cache_dir: T.Optional[str] = None) -> T.List[str]:
+ args: T.List[str] = []
+ if threads == 0:
+ if self._has_lto_auto_support:
+ args.append('-flto=auto')
+ else:
+ # This matches gcc's behavior of using the number of cpus, but
+ # obeying meson's MESON_NUM_PROCESSES convention.
+ args.append(f'-flto={mesonlib.determine_worker_count()}')
+ elif threads > 0:
+ args.append(f'-flto={threads}')
+ else:
+ args.extend(super().get_lto_compile_args(threads=threads))
+ return args
+
def get_profile_use_args(self) -> T.List[str]:
return super().get_profile_use_args() + ['-fprofile-correction']