Bug 1903036 - Move check for libstdc++ static linkage from old-configure to moz.configure r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D213953
This commit is contained in:
serge-sans-paille 2024-06-28 11:16:39 +00:00
parent cac3778e44
commit be5707afd4
2 changed files with 74 additions and 34 deletions

View File

@ -7,39 +7,5 @@ dnl Add compiler specific options
dnl A high level macro for selecting compiler options.
AC_DEFUN([MOZ_COMPILER_OPTS],
[
dnl ========================================================
dnl = Detect static linkage of libstdc++
dnl ========================================================
if test "$OS_TARGET" = Linux; then
AC_CACHE_CHECK([whether we're trying to statically link with libstdc++],
moz_cv_opt_static_libstdcxx,
[moz_cv_opt_static_libstdcxx=no
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
cat > conftest.$ac_ext <<EOF
#include <iostream>
int main() { std::cout << 1; }
EOF
dnl This test is quite conservative: it assumes dynamic linkage if the compilation step fails or if
dnl the binary format is not supported. But it still detects basic issues.
if AC_TRY_EVAL([ac_link]) && test -s conftest${ac_exeext} && $LLVM_OBJDUMP --private-headers conftest${ac_exeext} 2> conftest.err 1> conftest.out
then
if test -s conftest.err
then :
elif grep -q -E 'NEEDED.*lib(std)?c\+\+' conftest.out
then :
else moz_cv_opt_static_libstdcxx=yes
fi
fi
AC_LANG_RESTORE
rm -f conftest*
])
if test "$moz_cv_opt_static_libstdcxx" = "yes"; then
AC_MSG_ERROR([Firefox does not support linking statically with libstdc++])
fi
fi
])

View File

@ -11,6 +11,80 @@ check_and_add_flag("-fno-sized-deallocation", compiler=cxx_compiler)
# from the clang and GCC documentation, but they both support this.
check_and_add_flag("-fno-aligned-new", compiler=cxx_compiler)
# Detect static linkage of libstdc++
# ==============================================================
@depends(
cxx_compiler,
extra_toolchain_flags,
linker_ldflags,
llvm_objdump,
when=target_has_linux_kernel,
)
@checking("whether we're trying to statically link with libstdc++")
@imports("os")
@imports("re")
@imports(_from="tempfile", _import="mkstemp")
@imports(_from="mozbuild.shellutil", _import="split", _as="shell_split")
def link_libstdcxx_statically(
cxx_compiler,
extra_toolchain_flags,
linker_ldflags,
llvm_objdump,
):
fd, bin_path = mkstemp(prefix="conftest.", suffix=".out")
os.close(fd)
try:
# This test is quite conservative: it assumes dynamic linkage if the
# compilation step fails or if the binary format is not supported. But
# it still detects basic issues.
# FIXME: At some point we should make these dependencies explicit.
# See #1903233.
env_flags = []
if "CXXFLAGS" in os.environ:
env_flags.extend(shell_split(os.environ["CXXFLAGS"]))
if "LDFLAGS" in os.environ:
env_flags.extend(shell_split(os.environ["LDFLAGS"]))
if (
try_invoke_compiler(
None,
[cxx_compiler.compiler]
+ env_flags
+ cxx_compiler.flags
+ linker_ldflags,
cxx_compiler.language,
"""
#include <iostream>
int main() { std::cout << 1;}
""",
["-o", bin_path] + (extra_toolchain_flags or []),
wrapper=cxx_compiler.wrapper,
onerror=lambda: None,
)
is not None
):
objdump_command = [llvm_objdump, "--private-headers", bin_path]
result, stdout, stderr = get_cmd_output(*objdump_command)
# This is very conservative :-).
return (
result == 0
and not stderr
and not re.search("NEEDED.*lib(std)?c\\+\\+", stdout)
)
finally:
if os.path.exists(bin_path):
os.remove(bin_path)
@depends(when=link_libstdcxx_statically)
def check_libstdcxx_linkage():
die("Firefox does not support linking statically with libstdc++")
# Identical Code Folding
option(
"--enable-icf",