guix_mirror_bot pushed a commit to branch core-packages-team
in repository guix.

commit 13547d13cf85dd566db889ce41eb44c0a4aa7c5a
Author: Ludovic Courtès <[email protected]>
AuthorDate: Tue Mar 17 23:01:15 2026 +0100

    gnu: commencement: Build “mesboot” toolchain with ‘_FILE_OFFSET_BITS=64’.
    
    Fixes a bug whereby, for example, ‘gcc-mesboot0’ would fail to read its own
    spec file because the ‘stat’ function would return EOVERFLOW when 
encountering
    an inode number or timestamps that does not fit in 32 bits (on Btrfs inode
    numbers greater than 2^32 are not uncommon), a UID/GID that does not fit in 
16
    bits, etc.
    
    Internally, when ‘_FILE_OFFSET_BITS’ is unset, the ‘stat’ function in glibc
    invokes the ‘stat64’ syscall and then converts the result to a 32-bit 
‘struct
    stat’, failing with EOVERFLOW if one of the field from ‘struct stat64’ 
doesn’t
    fit in the corresponding field of ‘struct stat’.
    
    In Mes-Libc, the choice between ‘stat’ and ‘stat64’ (and the corresponding
    struct layout), ‘getdents’ and ‘getdents64’, etc. is dictated by the value 
of
    ‘__SIZEOF_LONG_LONG__’, which ‘mescc’ sets to 8 but ‘tcc’ leaves
    unset (equivalent to 0).  This change forces use of ‘stat64’ & co. for
    Mes-Libc users, including when using ‘tcc’.
    
    * gnu/packages/commencement.scm (mes-boot)[arguments]: Add
    ‘use-64-bit-file-offsets’ phase.
    (binutils-mesboot0)[arguments]: Add ‘-D_FILE_OFFSET_BITS=64’ to ‘cppflags’.
    (gcc-core-mesboot0)[arguments]: Likewise.
    (gcc-mesboot0)[arguments]: Likewise.
    
    Fixes: guix/guix#7194
    Change-Id: I05d5b8f5aee78ca0e95d7c89ba93b2729791a66a
    Signed-off-by: Ludovic Courtès <[email protected]>
---
 gnu/packages/commencement.scm | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 2c35f9ebaaa..3fc80a2ce67 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -503,7 +503,19 @@ MesCC-Tools), and finally M2-Planet.")
                 (for-each (lambda (x) (install-file x cache))
                           (append (objects-in-dir "m2")
                                   (objects-in-dir ".")
-                                  (objects-in-dir "mescc-lib")))))))))
+                                  (objects-in-dir "mescc-lib"))))))
+          (add-after 'install 'use-64-bit-file-offsets
+            (lambda _
+              ;; In Mes-Libc headers such as 'kernel-stat.h',
+              ;; __SIZEOF_LONG_LONG__ determines the layout of structures like
+              ;; 'struct stat' in the same way _FILE_OFFSET_BITS normally
+              ;; does.  While 'mescc' defines this macro, 'tcc' does not,
+              ;; which leads to discrepancies.  Thus hardcode it.
+              (substitute* (find-files (string-append #$output "/include")
+                                       (lambda (file stat)
+                                         (string-suffix? ".h" file)))
+                (("__SIZEOF_LONG_LONG__ == 8") "1")
+                (("__SIZEOF_LONG_LONG__ != 8") "0")))))))
     (native-search-paths
      (list (search-path-specification
             (variable "C_INCLUDE_PATH")
@@ -926,8 +938,9 @@ MesCC-Tools), and finally M2-Planet.")
            #:strip-binaries? #f ; no strip yet
            #:configure-flags
            #~(let ((cppflags (string-append
-                              " -D __GLIBC_MINOR__=6"
-                              " -D MES_BOOTSTRAP=1"))
+                              " -D__GLIBC_MINOR__=6"
+                              " -DMES_BOOTSTRAP=1"
+                              " -D_FILE_OFFSET_BITS=64"))
                    (bash (search-input-file %build-inputs "/bin/sh")))
                (list (string-append "CONFIG_SHELL=" bash)
                      (string-append "CPPFLAGS=" cppflags)
@@ -1006,7 +1019,8 @@ MesCC-Tools), and finally M2-Planet.")
                (add-before 'configure 'setenv
                  (lambda _
                    (let ((shell (search-input-file %build-inputs "/bin/bash"))
-                         (cppflags " -D __GLIBC_MINOR__=6"))
+                         (cppflags (string-append " -D __GLIBC_MINOR__=6"
+                                                  " -D_FILE_OFFSET_BITS=64")))
                      (setenv "CONFIG_SHELL" shell)
                      (setenv "CPPFLAGS" cppflags)
                      (setenv "CC" (string-append "tcc" cppflags))
@@ -1198,6 +1212,7 @@ ac_cv_c_float_format='IEEE (little-endian)'
             (replace 'setenv
               (lambda _
                 (setenv "CONFIG_SHELL" (which "sh"))
+                (setenv "CPPFLAGS" "-D_FILE_OFFSET_BITS=64")
                 (with-output-to-file "config.cache"
                   (lambda _
                     (display "

Reply via email to