From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Benc Subject: Re: problem with building gcc-cross-4.8.3 for i686-pc-gnu Date: Sat, 31 Jan 2015 23:13:06 +0100 Message-ID: <54CD5372.5090103@gmail.com> References: CAFtzXzN3Tu4+n5ku7wNqxKXm4e1D5O64OamZWN2-Gni8Aza_eA@mail.gmail.com <54CCADF7.6090708@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060601000608010109090801" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHgHt-0007cc-84 for guix-devel@gnu.org; Sat, 31 Jan 2015 17:13:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHgHo-0004LK-3w for guix-devel@gnu.org; Sat, 31 Jan 2015 17:13:09 -0500 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:64764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHgHn-0004LG-Oe for guix-devel@gnu.org; Sat, 31 Jan 2015 17:13:04 -0500 Received: by mail-wi0-f177.google.com with SMTP id r20so8675346wiv.4 for ; Sat, 31 Jan 2015 14:13:03 -0800 (PST) In-Reply-To: <54CCADF7.6090708@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: manolis837@gmail.com Cc: guix-devel@gnu.org This is a multi-part message in MIME format. --------------060601000608010109090801 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------060601000608010109090801 Content-Type: text/x-patch; name="hurd-branch-gcc-ld_so-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hurd-branch-gcc-ld_so-fix.patch" --- 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 + ;; + ;; 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 - ;; - ;; 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" --------------060601000608010109090801--