Subject: [bug#68212] [PATCH] gnu: openssh: fix build one ppc64le.

From: Jack Hill <[email-masked]>
Date: Tue, 2 Jan 2024 11:53:28 -0500

* gnu/packages/ssh.scm (openssh)[source]:
Use 'openssh-gcc-13-ppc64le-fzero-call-used-regs.patch'.
* gnu/packages/patches/openssh-gcc-13-ppc64le-fzero-call-used-regs.patch:
New file.
* gnu/local.mk (dist_patch_DATA): Add it.

Reported by Marcel van der Boom <[email-masked]>.

Change-Id: I41b1350b2cdd1487a8fd69b13b64f63c0dc166c9
---
 gnu/local.mk                                  |  1 +
 ...-gcc-13-ppc64le-fzero-call-used-regs.patch | 61 +++++++++++++++++++
 gnu/packages/ssh.scm                          |  5 +-
 3 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/openssh-gcc-13-ppc64le-fzero-call-used-regs.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 4b2393bfdd..b52134e34e 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1735,6 +1735,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/openjdk-15-xcursor-no-dynamic.patch	\
   %D%/packages/patches/openjdk-21-fix-rpath.patch		\
   %D%/packages/patches/openmpi-mtl-priorities.patch		\
+  %D%/packages/patches/openssh-gcc-13-ppc64le-fzero-call-used-regs.patch	\
   %D%/packages/patches/openssh-trust-guix-store-directory.patch	\
   %D%/packages/patches/openresolv-restartcmd-guix.patch	\
   %D%/packages/patches/openrgb-unbundle-hueplusplus.patch	\
diff --git a/gnu/packages/patches/openssh-gcc-13-ppc64le-fzero-call-used-regs.patch b/gnu/packages/patches/openssh-gcc-13-ppc64le-fzero-call-used-regs.patch
new file mode 100644
index 0000000000..1af9868b9a
--- /dev/null
+++ b/gnu/packages/patches/openssh-gcc-13-ppc64le-fzero-call-used-regs.patch
@@ -0,0 +1,61 @@
+From 1036d77b34a5fa15e56f516b81b9928006848cbd Mon Sep 17 00:00:00 2001
+From: Damien Miller <[email-masked]>
+Date: Fri, 22 Dec 2023 17:56:26 +1100
+Subject: [PATCH] better detection of broken -fzero-call-used-regs
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+gcc 13.2.0 on ppc64le refuses to compile some function, including
+cipher.c:compression_alg_list() with an error:
+
+> sorry, unimplemented: argument ‘used’ is not supportedcw
+> for ‘-fzero-call-used-regs’ on this target
+
+This extends the autoconf will-it-work test with a similarly-
+structured function that seems to catch this.
+
+Spotted/tested by Colin Watson; bz3645
+---
+
+Taken from upsteam, and for Guix by [email-masked]
+Thanks Marcel van der Boom for noticing: https://issues.guix.gnu.org/67948#2
+
+m4/openssh.m4 | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/m4/openssh.m4 b/m4/openssh.m4
+index 5d4c56280..033df501c 100644
+--- a/m4/openssh.m4
++++ b/m4/openssh.m4
+@@ -20,18 +20,24 @@ char *f2(char *s, ...) {
+ 	va_end(args);
+ 	return strdup(ret);
+ }
++const char *f3(int s) {
++	return s ? "good" : "gooder";
++}
+ int main(int argc, char **argv) {
+-	(void)argv;
+ 	char b[256], *cp;
++	const char *s;
+ 	/* Some math to catch -ftrapv problems in the toolchain */
+ 	int i = 123 * argc, j = 456 + argc, k = 789 - argc;
+ 	float l = i * 2.1;
+ 	double m = l / 0.5;
+ 	long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
++	(void)argv;
+ 	f(1);
+-	snprintf(b, sizeof b, "%d %d %d %f %f %lld %lld\n", i,j,k,l,m,n,o);
++	s = f3(f(2));
++	snprintf(b, sizeof b, "%d %d %d %f %f %lld %lld %s\n", i,j,k,l,m,n,o,s);
+ 	if (write(1, b, 0) == -1) exit(0);
+-	cp = f2("%d %d %d %f %f %lld %lld\n", i,j,k,l,m,n,o);
++	cp = f2("%d %d %d %f %f %lld %lld %s\n", i,j,k,l,m,n,o,s);
++	if (write(1, cp, 0) == -1) exit(0);
+ 	free(cp);
+ 	/*
+ 	 * Test fallthrough behaviour.  clang 10's -Wimplicit-fallthrough does
+-- 
+2.41.0
+
diff --git a/gnu/packages/ssh.scm b/gnu/packages/ssh.scm
index 0b364bbe90..e33a18f408 100644
--- a/gnu/packages/ssh.scm
+++ b/gnu/packages/ssh.scm
@@ -204,7 +204,10 @@ (define-public openssh
       (method url-fetch)
       (uri (string-append "mirror://openbsd/OpenSSH/portable/"
                           "openssh-" version ".tar.gz"))
-      (patches (search-patches "openssh-trust-guix-store-directory.patch"))
+      (patches (search-patches "openssh-trust-guix-store-directory.patch"
+                               ;; Can be removed with next openssh update
+                               ;; https://issues.guix.gnu.org/67948#2
+                               "openssh-gcc-13-ppc64le-fzero-call-used-regs.patch"))
       (sha256
        (base32 "0z3pgam8b4z05lvdb78iv06p204qwl7b94a3cnnwba2mfb0120li"))))
    (build-system gnu-build-system)

base-commit: 8f03c69b428923dc4d51cda23b10aa7fa7d89f05
-- 
2.41.0