Subject: bug#45214: guile segfaults on 32-bit big-endian targets

From: Efraim Flashner <[email-masked]>
Date: Wed, 14 Apr 2021 17:18:36 +0300

On Thu, Feb 25, 2021 at 05:24:04PM +0200, Efraim Flashner wrote:
> On Sat, Dec 12, 2020 at 11:02:47PM +0100, John Paul Adrian Glaubitz wrote:
> > Hi!
> > 
> > On 12/12/20 11:00 PM, John David Anglin wrote:
> > > Trying to bisect.
> > 
> > Bisecting lead me to this which I guess is just painting over the real
> > problem:
> > 
> > (sid_powerpc-dchroot)glaubitz@perotto:~/guile-git$ git bisect good
> > a68c80c747a2a8ec92fa84684ebd60b4ecb7ffa0 is the first bad commit
> > commit a68c80c747a2a8ec92fa84684ebd60b4ecb7ffa0
> > Author: Andy Wingo <[email-masked]>
> > Date:   Mon May 11 15:22:29 2020 +0200
> > 
> >     Switch to baseline compiler for bootstrap/
> > 
> >     * bootstrap/Makefile.am (GUILE_OPTIMIZATIONS): Add -Ono-cps so that we
> >       use the baseline compiler when bootstrapping.
> > 
> >  bootstrap/Makefile.am | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > (sid_powerpc-dchroot)glaubitz@perotto:~/guile-git$
> > 
> 
> I came to the same conclusion when I tried to bisect the git repo
> between 3.0.2 and 3.0.3 on my powerpc machine. By reverting that commit
> I was able to build 44ad8fbde55df452ac1c88427662403e7af5b9bb (3.0.2-70,
> 6 commit later) but wasn't able to build 3.0.3. I started the build
> without any precompiled bootstrap .go files.
> 

I spent some more time bisecting guile so I could create a diff against
3.0.5 and then spent another two weeks or so bootstrapping Guix from my
custom bootstrap binaries out to mesa.

I've attached the patch that's likely to go into Guix to add powerpc
support. Other than the mysterious failing test I've changed the
GUILE_OPTIMIZATIONS in bootstrap/Makefile.in to '-O1
-Oresolve-primitives -Ocps' on powerpc and it seems to be working fine.

-- 
Efraim Flashner   <[email-masked]>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
From c11ad7faa3690b2dfef924a31137f6ced5aab23f Mon Sep 17 00:00:00 2001
Message-Id: <[email-masked]>
In-Reply-To: <[email-masked]>
References: <[email-masked]>
From: Efraim Flashner <[email-masked]>
Date: Mon, 8 Mar 2021 22:13:56 +0200
Subject: [PATCH 2/9] gnu: guile-3.0: Fix building on powerpc-linux.

* gnu/packages/guile.scm (guile-3.0)[arguments]: On powerpc add two
phases to adjust for 32-bit big-endian systems.
---
 gnu/packages/guile.scm | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/guile.scm b/gnu/packages/guile.scm
index f63322794d..dca1b1c16f 100644
--- a/gnu/packages/guile.scm
+++ b/gnu/packages/guile.scm
@@ -305,7 +305,26 @@ without requiring the source code to be rewritten.")
          (substitute-keyword-arguments (package-arguments guile-2.2)
            ((#:configure-flags flags ''())
             `(cons "--disable-jit" ,flags)))
-         (package-arguments guile-2.2)))
+         (if (string-prefix? "powerpc-" (%current-system))
+           (substitute-keyword-arguments (package-arguments guile-2.2)
+             ((#:phases phases)
+              `(modify-phases ,phases
+                 (add-after 'unpack 'adjust-bootstrap-flags
+                   (lambda _
+                     ;; Upstream not yet notified about suggested solution.
+                     ;; See existing bug reports:
+                     ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45214
+                     ;; https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=977223
+                     (substitute* "bootstrap/Makefile.in"
+                       (("^GUILE_OPTIMIZATIONS.*")
+                        "GUILE_OPTIMIZATIONS = -O1 -Oresolve-primitives -Ocps\n"))
+                     #t))
+                 (add-after 'unpack 'remove-failing-tests
+                   (lambda _
+                     ;; TODO: Discover why this test fails on powerpc-linux
+                     (delete-file "test-suite/standalone/test-out-of-memory")
+                     #t)))))
+           (package-arguments guile-2.2))))
     (native-search-paths
      (list (search-path-specification
             (variable "GUILE_LOAD_PATH")
-- 
2.31.1