Bug 1802228 - Select a host linker in the same manner we do for the target linker. r=firefox-build-system-reviewers,ahochheiden

Differential Revision: https://phabricator.services.mozilla.com/D162912
This commit is contained in:
Mike Hommey 2022-11-25 01:56:38 +00:00
parent 29ab6a0f40
commit b2cc8ec2c0
3 changed files with 215 additions and 171 deletions

View file

@ -1545,18 +1545,33 @@ def enable_linker(linker):
return linker
@depends(
@template
def select_linker_tmpl(host_or_target):
if host_or_target is target:
deps = depends(
"--enable-linker",
c_compiler,
developer_options,
extra_toolchain_flags,
target,
when=is_linker_option_enabled,
)
@checking("for linker", lambda x: x.KIND)
@imports("os")
@imports("shutil")
def select_linker(linker, c_compiler, developer_options, toolchain_flags, target):
)
host_or_target_str = "target"
else:
deps = depends(
dependable(None),
host_c_compiler,
developer_options,
dependable(None),
host,
)
host_or_target_str = "host"
@deps
@checking(f"for {host_or_target_str} linker", lambda x: x.KIND)
@imports("os")
@imports("shutil")
def select_linker(linker, c_compiler, developer_options, toolchain_flags, target):
if linker:
linker = linker[0]
@ -1673,11 +1688,17 @@ def select_linker(linker, c_compiler, developer_options, toolchain_flags, target
return result
return select_linker
select_linker = select_linker_tmpl(target)
set_config("LINKER_KIND", select_linker.KIND)
@depends_if(
@template
def linker_ldflags_tmpl(host_or_target):
if host_or_target is target:
deps = depends_if(
select_linker,
target,
target_sysroot,
@ -1685,9 +1706,21 @@ set_config("LINKER_KIND", select_linker.KIND)
android_platform,
c_compiler,
developer_options,
)
@imports("os")
def linker_ldflags(
)
else:
deps = depends_if(
select_linker_tmpl(host),
host,
host_sysroot,
host_multiarch_dir,
dependable(None),
host_c_compiler,
developer_options,
)
@deps
@imports("os")
def linker_ldflags(
linker,
target,
sysroot,
@ -1695,7 +1728,7 @@ def linker_ldflags(
android_platform,
c_compiler,
developer_options,
):
):
flags = list((linker and linker.LINKER_FLAG) or [])
# rpath-link is irrelevant to wasm, see for more info https://github.com/emscripten-core/emscripten/issues/11076.
if sysroot.path and multiarch_dir and target.os != "WASI":
@ -1708,7 +1741,11 @@ def linker_ldflags(
# GCC also needs -L.
if c_compiler.type == "gcc":
flags.append("-L%s" % multiarch_lib_dir)
if c_compiler.type == "gcc" and sysroot.bootstrapped and sysroot.stdcxx_version:
if (
c_compiler.type == "gcc"
and sysroot.bootstrapped
and sysroot.stdcxx_version
):
flags.append(
"-L{}/usr/lib/gcc/{}/{}".format(
sysroot.path, multiarch_dir, sysroot.stdcxx_version
@ -1728,9 +1765,14 @@ def linker_ldflags(
flags.append("-Wl,-O0")
return flags
return linker_ldflags
linker_ldflags = linker_ldflags_tmpl(target)
add_old_configure_assignment("LINKER_LDFLAGS", linker_ldflags)
add_old_configure_assignment("HOST_LINKER_LDFLAGS", linker_ldflags_tmpl(host))
# There's a wrinkle with MinGW: linker configuration is not enabled, so
# `select_linker` is never invoked. Hard-code around it.

View file

@ -58,6 +58,7 @@ USE_PTHREADS=
_PTHREAD_LDFLAGS=""
LDFLAGS="$LDFLAGS $LINKER_LDFLAGS"
HOST_LDFLAGS="$HOST_LDFLAGS $HOST_LINKER_LDFLAGS"
if test -z "$JS_STANDALONE"; then
autoconfmk=autoconf-js.mk

View file

@ -58,6 +58,7 @@ MOZ_USE_PTHREADS=
_PTHREAD_LDFLAGS=""
LDFLAGS="$LDFLAGS $LINKER_LDFLAGS"
HOST_LDFLAGS="$HOST_LDFLAGS $HOST_LINKER_LDFLAGS"
if test "$COMPILE_ENVIRONMENT"; then
MOZ_ANDROID_NDK