Disregard the previous mail, I figured most of it out.

The attached patch does the following:
  1.) Adds the name of the dynamic linker to gnu/packages/bootstrap.scm
2.) Adds code to gnu/package/gcc to substitute the default dynamic linker in gcc/config/arch/gnu.h for the one to be used.
  3.) Changes how the build system arguments for cross-gcc are created:
A.) They're now in a separate procedure, reflecting how it's done in vanilla guix. B.) A bug is fixed that caused the native ld.so to be picked over the target one. C.) Fixed the 'set-cross-path phase so that it also checks for hurd-related packages, and checks package existence before passing anything to the string-handling functions.

The current issue is that, when building cross-gcc, when it reaches libgomp, configure fails when trying to create a dummy binary. For some reason, the compiled cross-compiler needs --rpath to specify where shared libraries are, as without it, it can't find libmachuser.so and libhurduser.so, which causes it to fail.

--
Marek.
--- guix.old/gnu/packages/bootstrap.scm	2015-01-31 11:06:42.020984113 +0100
+++ guix/gnu/packages/bootstrap.scm	2015-01-29 19:58:36.376427673 +0100
@@ -156,6 +156,7 @@
   (cond ((string=? system "x86_64-linux") "/lib/ld-linux-x86-64.so.2")
         ((string=? system "i686-linux") "/lib/ld-linux.so.2")
         ((string=? system "mips64el-linux") "/lib/ld.so.1")
+        ((string=? system "i686-gnu") "/lib/ld.so.1")
         (else (error "dynamic linker name not known for this system"
                      system))))
 
--- guix.old/gnu/packages/cross-base.scm	2015-01-31 11:06:42.025984113 +0100
+++ guix/gnu/packages/cross-base.scm	2015-01-31 12:16:33.365984113 +0100
@@ -67,6 +67,117 @@
                         `(cons "--with-sysroot=/" ,flags)))))))
     (cross binutils target)))
 
+(define (cross-gcc-arguments target libc)
+  "Return build system arguments for a cross-gcc for TARGET, using LIBC (which
+may be either a libc package or #f.)"
+  ;; Set the current target system so that 'glibc-dynamic-linker' returns the
+  ;; right name.
+  (parameterize ((%current-target-system target))
+    (substitute-keyword-arguments (package-arguments gcc-4.8)
+      ((#:configure-flags flags)
+       `(append (list ,(string-append "--target=" target)
+                      ,@(if libc
+                            '()
+                            `( ;; Disable features not needed at this stage.
+                              "--disable-shared" "--enable-static"
+
+                              ;; Disable C++ because libstdc++'s configure
+                              ;; script otherwise fails with "Link tests are not
+                              ;; allowed after GCC_NO_EXECUTABLES."
+                              "--enable-languages=c"
+
+                              "--disable-threads"  ;libgcc, would need libc
+                              "--disable-libatomic"
+                              "--disable-libmudflap"
+                              "--disable-libgomp"
+                              "--disable-libssp"
+                              "--disable-libquadmath"
+                              "--disable-decimal-float" ;would need libc
+                              )))
+
+                ,(if libc
+                     flags
+                     `(remove (cut string-match "--enable-languages.*" <>)
+                              ,flags))))
+      ((#:make-flags flags)
+       (if libc
+           `(let ((libc (assoc-ref %build-inputs "libc")))
+              ;; FLAGS_FOR_TARGET are needed for the target libraries to receive
+              ;; the -Bxxx for the startfiles.
+              (cons (string-append "FLAGS_FOR_TARGET=-B" libc "/lib")
+                    ,flags))
+           flags))
+      ((#:phases phases)
+       (let ((phases
+              `(alist-cons-after
+                'install 'make-cross-binutils-visible
+                (lambda* (#:key outputs inputs #:allow-other-keys)
+                  (let* ((out      (assoc-ref outputs "out"))
+                         (libexec  (string-append out "/libexec/gcc/"
+                                                  ,target))
+                         (binutils (string-append
+                                    (assoc-ref inputs "binutils-cross")
+                                    "/bin/" ,target "-")))
+                    (for-each (lambda (file)
+                                (symlink (string-append binutils file)
+                                         (string-append libexec "/"
+                                                        file)))
+                              '("as" "ld" "nm"))
+                    #t))
+                ,phases)))
+         (if libc
+             `(alist-cons-before
+               'configure 'set-cross-path
+               (lambda* (#:key inputs #:allow-other-keys)
+                 ;; Add the cross-kernel headers to CROSS_CPATH, and remove them
+                 ;; from CPATH.
+                 (let ((libc  (assoc-ref inputs "libc"))
+                       (linux (assoc-ref inputs
+                                         "libc/cross-linux-headers"))
+                       (mach  (assoc-ref inputs
+                                         "libc/cross-gnumach-headers"))
+                       (hurd  (assoc-ref inputs
+                                         "libc/cross-hurd-headers"))
+                       (hurd-minimal (assoc-ref inputs
+                                         "libc/cross-hurd-minimal")))
+
+                   (define (cross? x)
+                     ;; Return #t if X is a cross-libc or a cross-kernel.
+                     (or (string-prefix? libc x)
+                         (if linux        (string-prefix? linux x) #f)
+                         (if hurd         (string-prefix? hurd  x) #f)
+                         (if mach         (string-prefix? mach  x) #f)
+                         (if hurd-minimal (string-prefix? hurd-minimal x) #f)))
+
+                   (setenv "CROSS_CPATH"
+                           (string-append libc "/include"
+                                          (if linux (string-append ":" linux "/include") "")
+                                          (if hurd  (string-append ":" hurd  "/include"
+                                                                   ":" mach  "/include") "")))
+                   (setenv "CROSS_LIBRARY_PATH"
+                           (string-append libc "/lib"
+                                          (if hurd-minimal (string-append ":" hurd-minimal "/lib") "")))
+
+                   (let ((cpath   (search-path-as-string->list
+                                   (getenv "CPATH")))
+                         (libpath (search-path-as-string->list
+                                   (getenv "LIBRARY_PATH"))))
+                     (setenv "CPATH"
+                             (list->search-path-as-string
+                              (remove cross? cpath) ":"))
+                     (setenv "LIBRARY_PATH"
+                             (list->search-path-as-string
+                              (remove cross? libpath) ":"))
+                     #t)))
+               ,phases)
+             phases)))
+      ((#:strip-binaries? _)
+       ;; Disable stripping as this can break binaries, with object files of
+       ;; libgcc.a showing up as having an unknown architecture.  See
+       ;; <http://lists.fedoraproject.org/pipermail/arm/2010-August/000663.html>
+       ;; for instance.
+       #f))))
+
 (define* (cross-gcc target
                     #:optional (xbinutils (cross-binutils target)) libc)
   "Return a cross-compiler for TARGET, where TARGET is a GNU triplet.  Use
@@ -93,99 +204,7 @@
                   (srfi srfi-1)
                   (srfi srfi-26))
 
-       ,@(substitute-keyword-arguments (package-arguments gcc-4.8)
-           ((#:configure-flags flags)
-            `(append (list ,(string-append "--target=" target)
-                           ,@(gcc-configure-flags-for-triplet target)
-                           ,@(if libc
-                                 '()
-                                 `( ;; Disable features not needed at this stage.
-                                   "--disable-shared" "--enable-static"
-
-                                   ;; Disable C++ because libstdc++'s
-                                   ;; configure script otherwise fails with
-                                   ;; "Link tests are not allowed after
-                                   ;; GCC_NO_EXECUTABLES."
-                                   "--enable-languages=c"
-
-                                   "--disable-threads" ; libgcc, would need libc
-                                   "--disable-libatomic"
-                                   "--disable-libmudflap"
-                                   "--disable-libgomp"
-                                   "--disable-libssp"
-                                   "--disable-libquadmath"
-                                   "--disable-decimal-float" ; would need libc
-                                   )))
-
-                     ,(if libc
-                          flags
-                          `(remove (cut string-match "--enable-languages.*" <>)
-                                   ,flags))))
-           ((#:make-flags flags)
-            (if libc
-                `(let ((libc (assoc-ref %build-inputs "libc")))
-                   ;; FLAGS_FOR_TARGET are needed for the target libraries to
-                   ;; receive the -Bxxx for the startfiles.
-                   (cons (string-append "FLAGS_FOR_TARGET=-B" libc "/lib")
-                         ,flags))
-                flags))
-           ((#:phases phases)
-            (let ((phases
-                   `(alist-cons-after
-                     'install 'make-cross-binutils-visible
-                     (lambda* (#:key outputs inputs #:allow-other-keys)
-                       (let* ((out      (assoc-ref outputs "out"))
-                              (libexec  (string-append out "/libexec/gcc/"
-                                                       ,target))
-                              (binutils (string-append
-                                         (assoc-ref inputs "binutils-cross")
-                                         "/bin/" ,target "-")))
-                         (for-each (lambda (file)
-                                     (symlink (string-append binutils file)
-                                              (string-append libexec "/"
-                                                             file)))
-                                   '("as" "ld" "nm"))
-                         #t))
-                     ,phases)))
-             (if libc
-                 `(alist-cons-before
-                   'configure 'set-cross-path
-                   (lambda* (#:key inputs #:allow-other-keys)
-                     ;; Add the cross Linux headers to CROSS_CPATH, and remove
-                     ;; them from CPATH.
-                     (let ((libc  (assoc-ref inputs "libc"))
-                           (linux (assoc-ref inputs
-                                             "libc/cross-linux-headers")))
-                       (define (cross? x)
-                         ;; Return #t if X is a cross-libc or cross Linux.
-                         (or (string-prefix? libc x)
-                             (string-prefix? linux x)))
-
-                       (setenv "CROSS_CPATH"
-                               (string-append libc "/include:"
-                                              linux "/include"))
-                       (setenv "CROSS_LIBRARY_PATH"
-                               (string-append libc "/lib"))
-
-                       (let ((cpath   (search-path-as-string->list
-                                       (getenv "CPATH")))
-                             (libpath (search-path-as-string->list
-                                       (getenv "LIBRARY_PATH"))))
-                         (setenv "CPATH"
-                                 (list->search-path-as-string
-                                  (remove cross? cpath) ":"))
-                         (setenv "LIBRARY_PATH"
-                                 (list->search-path-as-string
-                                  (remove cross? libpath) ":"))
-                         #t)))
-                   ,phases)
-                 phases)))
-           ((#:strip-binaries? _)
-            ;; Disable stripping as this can break binaries, with object files
-            ;; of libgcc.a showing up as having an unknown architecture.  See
-            ;; <http://lists.fedoraproject.org/pipermail/arm/2010-August/000663.html>
-            ;; for instance.
-            #f))))
+       ,@(cross-gcc-arguments target libc)))
 
     (native-inputs
      `(("binutils-cross" ,xbinutils)
--- guix.old/gnu/packages/gcc.scm	2015-01-31 11:06:42.031984113 +0100
+++ guix/gnu/packages/gcc.scm	2015-01-31 13:51:30.949984113 +0100
@@ -186,6 +186,13 @@
                            suffix
                            (string-append libc ,(glibc-dynamic-linker)))))
 
+                (substitute* (find-files "gcc/config"
+                                         "^gnu(64|-elf)?\\.h$")
+                  (("#define GNU_USER_DYNAMIC_LINKER([^ ]*).*$" _ suffix)
+                   (format #f "#define GNU_USER_DYNAMIC_LINKER~a \"~a\"~%"
+                           suffix
+                           (string-append libc ,(glibc-dynamic-linker)))))
+
                 ;; Tell where to find libstdc++, libc, and `?crt*.o', except
                 ;; `crt{begin,end}.o', which come with GCC.
                 (substitute* (find-files "gcc/config"

Reply via email to