Bug 1851078 - Simplify how the linker is chosen during configure. r=firefox-build-system-reviewers,sergesanspaille

Differential Revision: https://phabricator.services.mozilla.com/D187247
This commit is contained in:
Mike Hommey 2023-09-04 22:22:35 +00:00
parent 4d663c191b
commit 88b82d1ac2
2 changed files with 27 additions and 29 deletions

View File

@ -1634,7 +1634,7 @@ set_config("CXX_IS_ICECREAM", cxx_is_icecream)
# The policy is as follows:
# For Windows:
# - the linker is picked via the LINKER environment variable per windows.configure,
# but ought to be llvm-lld in any case.
# but ought to be lld-link in any case.
# For macOS:
# - the linker is lld if the clang used is >= 15 (per LLVM version, not Xcode version).
# - the linker is also lld on local developer builds if the clang used is >= 13 (per LLVM
@ -1642,8 +1642,8 @@ set_config("CXX_IS_ICECREAM", cxx_is_icecream)
# - otherwise the linker is ld64, either from XCode on macOS, or from cctools-ports when
# cross-compiling.
# For other OSes:
# - on local developer builds: lld is used if present. Otherwise gold is used if present
# otherwise, BFD ld is used.
# - on local developer builds: lld is used if present and the compiler is clang. Otherwise
# gold is used if present, otherwise, BFD ld is used.
# - on release/official builds: whatever the compiler uses by default, except on Android
# (see enable_linker_default below). Usually what the compiler uses by default is BFD
# ld, except with the Android NDK compiler, where the default varies depending on the
@ -1808,38 +1808,36 @@ def select_linker_tmpl(host_or_target):
LINKER_FLAG=linker_flag,
)
result = try_linker(linker)
if result is None and linker:
die("Could not use {} as linker".format(linker))
result = None
if linker:
result = try_linker(linker)
if result is None:
die("Could not use {} as linker".format(linker))
if (
linker is None
and target.kernel == "Darwin"
result is None
and c_compiler.type == "clang"
and (
(developer_options and c_compiler.version >= "13.0")
or c_compiler.version >= "15.0"
(
target.kernel != "Darwin"
and (developer_options or host_or_target_str == "host")
)
or (
target.kernel == "Darwin"
and (
(developer_options and c_compiler.version >= "13.0")
or c_compiler.version >= "15.0"
)
)
)
):
result = try_linker("lld")
elif (
linker is None
and (
developer_options
or (host_or_target_str == "host" and c_compiler.type == "clang")
)
and (result is None or result.KIND in ("bfd", "gold"))
):
# try and use lld if available.
tried = try_linker("lld")
if (result is None or result.KIND != "gold") and (
tried is None or tried.KIND != "lld"
):
tried = try_linker("gold")
if tried is None or tried.KIND != "gold":
tried = None
if tried:
result = tried
if result is None and developer_options:
result = try_linker("gold")
if result is None:
result = try_linker(None)
if result is None:
die("Failed to find an adequate linker")

View File

@ -153,7 +153,7 @@ class TestToolkitMozConfigure(BaseConfigureTest):
# Trick the sandbox into not running too much
dep = sandbox._depends[sandbox["c_compiler"]]
value_for_depends[(dep,)] = CompilerResult(
compiler="/usr/bin/mockcc", language="C", flags=[]
compiler="/usr/bin/mockcc", language="C", type="clang", flags=[]
)
dep = sandbox._depends[sandbox["readelf"]]
value_for_depends[(dep,)] = "/usr/bin/readelf"