From da1ffd041276ad87787be0c5cbcd7841082e3619 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Thu, 24 Feb 2022 15:06:28 +0000 Subject: [PATCH] cc/gcc: Remove -lstdc++ and -lm from gcc LDFLAGS In Bryan Hundven's patch 1ad439907 from 2010, the author added -lstdc++ and -lm to the host gcc build's LDFLAGS, because at the time the linker did not correctly include these libraries causing the build to fail. In modern builds, this causes a problem for canadian gcc builds where the host machine is mingw32-w64 Windows. Within the gcc build there is the liblto_plugin module. On Windows this must be built as the "liblto_plugin.dll" dynamic library. However, libtool cannot produce a dynamic library unless every library dependency is also a dynamic library, and falls back to producing a libstdc++.a static library. liblto_plugin does not require libstdc++ - it does not contain any C++ code, and the dependency would usually be elided by the linker. Unfortunately, in this case, crosstool-ng will never build a libstdc++.dll dynamic library - only a libstdc++.a static library. Therefore, there will never be a dynamic library version of stdc++ for libtool to load and then discard. This patch corrects the issue by removing "-lstdc++" from LDFLAGS, because modern versions of gcc are able to correctly include libstdc++ where necessary. It also remove "-lm" for similar reasons. Signed-off-by: Joel Holdsworth --- scripts/build/cc/gcc.sh | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh index 0f369a47..59666160 100644 --- a/scripts/build/cc/gcc.sh +++ b/scripts/build/cc/gcc.sh @@ -396,12 +396,6 @@ do_gcc_core_backend() { host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++") host_libstdcxx_flags+=("-lm") fi - # Companion libraries are build static (eg !shared), so - # the libstdc++ is not pulled automatically, although it - # is needed. Shoe-horn it in our LDFLAGS - # Ditto libm on some Fedora boxen - core_LDFLAGS+=("-lstdc++") - core_LDFLAGS+=("-lm") else if [ "${CT_CC_GCC_STATIC_LIBSTDCXX}" = "y" -a "${CT_GCC_older_than_6}" = "y" ]; then # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2 @@ -412,12 +406,6 @@ do_gcc_core_backend() { host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic") host_libstdcxx_flags+=("-lm") fi - # When companion libraries are build static (eg !shared), - # the libstdc++ is not pulled automatically, although it - # is needed. Shoe-horn it in our LDFLAGS - # Ditto libm on some Fedora boxen - core_LDFLAGS+=("-lstdc++") - core_LDFLAGS+=("-lm") fi extra_config+=("--with-gmp=${complibs}") @@ -1036,12 +1024,6 @@ do_gcc_backend() { host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++") host_libstdcxx_flags+=("-lm") fi - # Companion libraries are build static (eg !shared), so - # the libstdc++ is not pulled automatically, although it - # is needed. Shoe-horn it in our LDFLAGS - # Ditto libm on some Fedora boxen - final_LDFLAGS+=("-lstdc++") - final_LDFLAGS+=("-lm") else if [ "${CT_CC_GCC_STATIC_LIBSTDCXX}" = "y" -a "${CT_GCC_older_than_6}" = "y" ]; then # this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2 @@ -1052,12 +1034,6 @@ do_gcc_backend() { host_libstdcxx_flags+=("-Wl,-Bstatic,-lstdc++,-Bdynamic") host_libstdcxx_flags+=("-lm") fi - # When companion libraries are build static (eg !shared), - # the libstdc++ is not pulled automatically, although it - # is needed. Shoe-horn it in our LDFLAGS - # Ditto libm on some Fedora boxen - final_LDFLAGS+=("-lstdc++") - final_LDFLAGS+=("-lm") fi extra_config+=("--with-gmp=${complibs}")