Bug 31412 - GCC 6 failed to build i386 glibc on Fedora 39
Summary: GCC 6 failed to build i386 glibc on Fedora 39
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: build (show other bugs)
Version: 2.40
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-24 18:41 UTC by H.J. Lu
Modified: 2024-02-25 12:17 UTC (History)
4 users (show)

See Also:
Host:
Target: i386
Build:
Last reconfirmed:
fw: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2024-02-24 18:41:09 UTC
[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?
Comment 1 Florian Weimer 2024-02-24 23:27:41 UTC
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?
Comment 2 H.J. Lu 2024-02-25 12:17:43 UTC
(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.