We need to pass --sysroot and --gcc-toolchain explicitly for cross compiling with glibc
because when the lld tries to link libc, it will read the gcc libc linker script which
includes absolute paths to actual libc files and without the sysroot argument it picks
the host ones, even though it discovered the linker script in the sysroot already.
linker-script = /usr/aarch64-linux-gnu/lib64/libc.so
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -725,6 +725,10 @@
             flags.append("--target=%s" % toolchain)
             has_target = True
 
+    if info.type == "clang" and not target.os == "WASI" and (info.cpu != target.cpu):
+        flags.append("--sysroot=/usr/%s" % toolchain)
+        flags.append("--gcc-toolchain=/usr")
+
     if not has_target and (not info.cpu or info.cpu != target.cpu):
         same_arch = same_arch_different_bits()
         if (target.cpu, info.cpu) in same_arch:
