From a0032480d6707cdfda75987178a7c8ec0c33cbe9 Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Sat, 11 Jun 2022 00:50:28 +0900 Subject: clang: Support ThinLTO with mold --- mesonbuild/compilers/mixins/clang.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index 4ac9b92..f9b66d5 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -19,7 +19,8 @@ import shutil import typing as T from ... import mesonlib -from ...linkers import AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker +from ...linkers import AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker, \ + MoldDynamicLinker from ...mesonlib import OptionKey from ..compilers import CompileCheckMode from .gnu import GnuLikeCompiler @@ -149,9 +150,13 @@ class ClangCompiler(GnuLikeCompiler): def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]: args: T.List[str] = [] if mode == 'thin': - # Thin LTO requires the use of gold, lld, ld64, or lld-link - if not isinstance(self.linker, (AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker)): - raise mesonlib.MesonException(f"LLVM's thinLTO only works with gnu gold, lld, lld-link, and ld64, not {self.linker.id}") + # ThinLTO requires the use of gold, lld, ld64, lld-link or mold 1.1+ + if isinstance(self.linker, (MoldDynamicLinker)): + # https://github.com/rui314/mold/commit/46995bcfc3e3113133620bf16445c5f13cd76a18 + if not mesonlib.version_compare(self.linker.version, '>=1.1'): + raise mesonlib.MesonException("LLVM's ThinLTO requires mold 1.1+") + elif not isinstance(self.linker, (AppleDynamicLinker, ClangClDynamicLinker, LLVMDynamicLinker, GnuGoldDynamicLinker)): + raise mesonlib.MesonException(f"LLVM's ThinLTO only works with gold, lld, lld-link, ld64 or mold, not {self.linker.id}") args.append(f'-flto={mode}') else: assert mode == 'default', 'someone forgot to wire something up' -- cgit v1.1