diff mbox series

[bug#49025,[PATCH,v2,core-updates] 36/37] cross-base: Fix cross-compiler for i686-linux-gnu.

Message ID 20210618160936.18972-36-maximedevos@telenet.be
State Accepted
Headers show
Series [bug#49025,[PATCH,v2,core-updates] 36/37] cross-base: Fix cross-compiler for i686-linux-gnu. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

M June 18, 2021, 4:09 p.m. UTC
GCC doesn't find libgcc_s.so anymore and looks in the wrong
location.  Fix this (well, more a work-around really).

* gnu/packages/cross-base.scm
  (cross-gcc-arguments)<#:configure-flags>:
  Add --with-toolexecdir, such that libstdc++ ends up in the right
  place. Add --with-slibdir such that libgcc_s.so end up in the right place.
  (cross-gcc-arguments)<#:phases>{move-shared-libraries}:
  New phase, moving libraries in the correct place.
  Delete .la files, libasan.so and libusan.so to prevent circular
  references. Likewise, fix a reference in libstdc++.so.VERSION-gdb.py.
---
 gnu/packages/cross-base.scm | 63 +++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 9487ac9238..995b4ae065 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -7,6 +7,7 @@ 
 ;;; Copyright © 2019, 2020, 2021 Marius Bakke <marius@gnu.org>
 ;;; Copyright © 2019 Carl Dong <contact@carldong.me>
 ;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -33,6 +34,7 @@ 
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix utils)
+  #:use-module (guix gexp)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system trivial)
   #:use-module (srfi srfi-1)
@@ -169,9 +171,26 @@  base compiler and using LIBC (which may be either a libc package or #f.)"
                                 ))
 
                        ;; Install cross-built libraries such as libgcc_s.so in
-                       ;; the "lib" output.
+                       ;; the "lib" output. At least for version 8.4.0, GCC
+                       ;; will put libstdc++ in ${toolexecdir}/lib instead.
+                       ;; (A bug?) So set --with-toolexecdir as well.
+
                        ,@(if libc
-                             `((string-append "--with-toolexeclibdir="
+                             `((string-append "--with-toolexecdir="
+                                              (assoc-ref %outputs "lib"))
+                               (string-append "--with-toolexeclibdir="
+                                              (assoc-ref %outputs "lib")
+                                              "/" ,target "/lib"))
+                             '())
+                       ;; At least for GCC 8.0, libgcc_s.so and libstdc++.so
+                       ;; are not installed in the location specified in
+                       ;; --with-toolexeclibdir so GCC will not find it
+                       ;; when cross-compiling, say, GNU Hello.
+                       ;;
+                       ;; Work-around by specifying slibdir. This is not
+                       ;; sufficient, see move-shared-libraries below.
+                       ,@(if (and libc (version>=? (package-version xgcc) "8.0"))
+                             `((string-append "--with-slibdir="
                                               (assoc-ref %outputs "lib")
                                               "/" ,target "/lib"))
                              '())
@@ -193,7 +212,45 @@  base compiler and using LIBC (which may be either a libc package or #f.)"
                      ,flags))
             flags))
        ((#:phases phases)
-        `(cross-gcc-build-phases ,target ,phases))))))
+        (if (and libc (version>=? (package-version xgcc) "8.0"))
+            #~(modify-phases (cross-gcc-build-phases #$target #$phases)
+                (add-after 'install 'move-shared-libraries
+                  (lambda _
+                    (let* ((slib (format #f "~a/~a/lib/" #$output:lib #$target))
+                           (badlib (format #f "~a/~a/lib/" #$output #$target))
+                           (libs (map basename (find-files badlib #:fail-on-error? #t))))
+                      (for-each
+                       (lambda (lib)
+                         (let ((from (string-append badlib lib))
+                               (to   (string-append slib lib)))
+                           (when (file-exists? to)
+                             (error "~a was found twice, refusing to overwrite!"
+                                    lib))
+                           ;; The debugging script libstdc++.so.VERSION-gdb.py has
+                           ;; reference to #$output. Correct it.
+                           (when (string-suffix? "-gdb.py" lib)
+                             (substitute* from
+                               (("libdir = '(.*)'")
+                                (string-append "libdir = '" slib "'")))
+                             (system* "cat" from))
+                           ;; The .la files have references to BADLIB,
+                           ;; leading to cyclic references between
+                           ;; the outputs of the package. Remove them
+                           ;; and hope noone notices.
+                           ;;
+                           ;; Likewise, libasan.so.* and libubsan.so.*
+                           ;; have references to #$output.
+                           (if (or (string-suffix? ".la" lib)
+                                   (string-prefix? "libasan.so" lib)
+                                   (string-prefix? "libubsan.so" lib))
+                               (delete-file from)
+                               (rename-file from to))))
+                       libs)
+                      ;; If you have "cyclic references" problems,
+                      ;; uncomment this and use --keep-failed to figure
+                      ;; things out.
+                      (copy-recursively #$output:lib "out-test")))))
+            #~(cross-gcc-build-phases #$target #$phases)))))))
 
 (define (cross-gcc-patches xgcc target)
   "Return GCC patches needed for XGCC and TARGET."