[hjl@gnu-cfl-3 tmp]$ cat x.c #include <iostream> int main () { std::cout << "Hello, world!"; return 0; } [hjl@gnu-cfl-3 tmp]$ /usr/gcc-6.4.1-x32/bin/g++ -m32 x.c -static /usr/local/bin/ld: /lib/../lib/libc.a(offtime.o): in function `__offtime': (.text+0x3c): undefined reference to `__divmoddi4' /usr/local/bin/ld: (.text+0xa2): undefined reference to `__divmoddi4' /usr/local/bin/ld: (.text+0x22e): undefined reference to `__divmoddi4' collect2: error: ld returned 1 exit status [hjl@gnu-cfl-3 tmp]$ /usr/gcc-7.4.1-x32/bin/g++ -m32 x.c -static [hjl@gnu-cfl-3 tmp]$ Since /lib/libc.a on Fedora 39 was compiled with GCC 13, it uses __divmoddi4 which was added to GCC 7 and GCC 6 won't be able to create static binary on Fedora 39. Why is static linking required here?
H.J., what do you mean by static linking in this context? I think your GCC 6 environment is misconfigured. Shouldn't it use system libgcc.a?
(In reply to Florian Weimer from comment #1) > H.J., what do you mean by static linking in this context? $ gcc -static .... > I think your GCC 6 environment is misconfigured. Shouldn't it use system > libgcc.a? [hjl@gnu-cfl-1 tmp]$ gcc -print-file-name=libgcc.a /usr/lib/gcc/x86_64-redhat-linux/13/libgcc.a [hjl@gnu-cfl-1 tmp]$ /usr/gcc-14.0.1-x32/bin/gcc -print-file-name=libgcc.a /usr/gcc-14.0.1-x32/lib/gcc/x86_64-pc-linux-gnu/14.0.1/libgcc.a [hjl@gnu-cfl-1 tmp]$ /usr/gcc-6.3.1-x32/bin/gcc -print-file-name=libgcc.a /usr/gcc-6.3.1-x32/lib/gcc/x86_64-pc-linux-gnu/6.3.1/libgcc.a [hjl@gnu-cfl-1 tmp]$ All versions of GCC should use /usr/lib/gcc/x86_64-redhat-linux/13/libgcc.a? It won't work for GCC 14 or higher. The configure.ac change: ommit d337ceb76d898935560dc264cf2ad36b17017db7 Author: Florian Weimer <fweimer@redhat.com> Date: Mon Oct 26 09:41:10 2015 +0100 Use the CXX compiler only if it can create dynamic and static programs * configure.ac (CXX): Clear the variable if the C++ toolchain does not support static linking. * configure: Regenerate. diff --git a/configure.ac b/configure.ac index e502aa5db2..3c7f6c0096 100644 --- a/configure.ac +++ b/configure.ac @@ -57,9 +57,26 @@ AC_PROG_CXX # It's useless to us if it can't link programs (e.g. missing -lstdc++). AC_CACHE_CHECK([whether $CXX can link programs], libc_cv_cxx_link_ok, [dnl AC_LANG_PUSH([C++]) +# Default, dynamic case. AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [libc_cv_cxx_link_ok=yes], [libc_cv_cxx_link_ok=no]) +# Static case. +old_LDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS -static" +AC_LINK_IFELSE([AC_LANG_SOURCE([ +#include <iostream> + +int +main() +{ + std::cout << "Hello, world!"; + return 0; +} +])], + [], + [libc_cv_cxx_link_ok=no]) +LDFLAGS="$old_LDFLAGS" AC_LANG_POP([C++])]) AS_IF([test $libc_cv_cxx_link_ok != yes], [CXX=]) makes it impossible to properly build i386 glibc with GCC 6 on Fedora 39.