Subject: [bug#67921] [PATCH v3 01/24] gnu: ghc: More robust build with binutils ≥ 2.39.

From: Nicolas Graves <[email-masked]>
Date: Thu, 31 Oct 2024 13:46:40 +0100

Future versions of ghc will have more occurrences of the execstack
warning.  Instead of modifying the tests for each new version, a more
robust approach is to explicitely make ghc pass -Wl,-z,noexecstack to
its ld invocations during all tests.  This is what this patch does.

* gnu/packages/patches/ghc-testsuite-recomp015-execstack.patch: New patches.
* gnu/local.mk (disp_path_DATA): Deregister patch.
* gnu/packages/haskell.scm (ghc-8.6, ghc-8.8, ghc-9.0, ghc-9.2,
ghc-9.4): Deregister patch use. Add phase [email-masked].
---
 gnu/local.mk                                  |  1 -
 gnu/packages/haskell.scm                      | 24 ++++++++++---------
 .../ghc-testsuite-recomp015-execstack.patch   | 10 --------
 3 files changed, 13 insertions(+), 22 deletions(-)
 delete mode 100644 gnu/packages/patches/ghc-testsuite-recomp015-execstack.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index b0b3d2ea2b..2292577c86 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1381,7 +1381,6 @@ dist_patch_DATA =						\
   %D%/packages/patches/ghc-basement-fix-32-bit.patch		\
   %D%/packages/patches/ghc-testsuite-dlopen-pie.patch		\
   %D%/packages/patches/ghc-testsuite-grep-compat.patch		\
-  %D%/packages/patches/ghc-testsuite-recomp015-execstack.patch	\
   %D%/packages/patches/ghc-aeson-encodeDouble.patch		\
   %D%/packages/patches/ghc-basement-fix-32bit.patch		\
   %D%/packages/patches/ghc-bytestring-handle-ghc9.patch	\
diff --git a/gnu/packages/haskell.scm b/gnu/packages/haskell.scm
index 10803f5afe..c580c660f1 100644
--- a/gnu/packages/haskell.scm
+++ b/gnu/packages/haskell.scm
@@ -1174,8 +1174,7 @@ (define-public ghc-8.6
                  "https://www.haskell.org/ghc/dist/"
                  version "/" name "-" version "-testsuite.tar.xz"))
            (patches (search-patches "ghc-testsuite-dlopen-pie.patch"
-                                    "ghc-testsuite-grep-compat.patch"
-                                    "ghc-testsuite-recomp015-execstack.patch"))
+                                    "ghc-testsuite-grep-compat.patch"))
            (sha256
             (base32
              "0pw9r91g2np3i806g2f4f8z4jfdd7mx226cmdizk4swa7av1qf91"))
@@ -1229,7 +1228,14 @@ (define-public ghc-8.6
                (substitute* "libraries/unix/tests/all.T"
                  (("^test\\('T8108'") "# guix skipped: test('T8108'"))
                (substitute* "libraries/unix/tests/libposix/all.T"
-                 (("^test\\('posix010'") "# guix skipped: test('posix010'"))))))))
+                 (("^test\\('posix010'") "# guix skipped: test('posix010'"))))
+           ;; [email-masked] warns for execstack deprecation by default, causing
+           ;; some tests to fail ; explicitely disable during linking instead.
+           (add-after 'unpack-testsuite [email-masked]
+             (lambda _
+               (substitute* "testsuite/mk/test.mk"
+                 (("^TEST_HC_OPTS = ")
+                  "TEST_HC_OPTS = -optl -Wl,-z,noexecstack "))))))))
     (native-search-paths (list (search-path-specification
                                 (variable "GHC_PACKAGE_PATH")
                                 (files (list
@@ -1257,8 +1263,7 @@ (define-public ghc-8.8
                  "https://www.haskell.org/ghc/dist/"
                  version "/ghc-" version "-testsuite.tar.xz"))
            (patches (search-patches "ghc-testsuite-dlopen-pie.patch"
-                                    "ghc-testsuite-grep-compat.patch"
-                                    "ghc-testsuite-recomp015-execstack.patch"))
+                                    "ghc-testsuite-grep-compat.patch"))
            (sha256
             (base32
              "0c55pj2820q26rikhpf636sn4mjgqsxjrl94vsywrh79dxp3k14z"))
@@ -1317,8 +1322,7 @@ (define-public ghc-8.10
                  "https://www.haskell.org/ghc/dist/"
                  version "/ghc-" version "-testsuite.tar.xz"))
            (patches (search-patches "ghc-testsuite-dlopen-pie.patch"
-                                    "ghc-testsuite-grep-compat.patch"
-                                    "ghc-testsuite-recomp015-execstack.patch"))
+                                    "ghc-testsuite-grep-compat.patch"))
            (sha256
             (base32
              "1zl25gg6bpx5601k8h3cqnns1xfc0nqgwnh8jvn2s65ra3f2g1nz"))
@@ -1415,8 +1419,7 @@ (define-public ghc-9.0
            (sha256
             (base32
              "1m5fzhr4gjn9ni8gxx7ag3fkbw1rspjzgv39mnfb0nkm5mw70v3s"))
-           (patches (search-patches "ghc-9.2-grep-warnings.patch"
-                                    "ghc-testsuite-recomp015-execstack.patch"))
+           (patches (search-patches "ghc-9.2-grep-warnings.patch"))
            (modules '((guix build utils)))
            (snippet
             ;; collections.Iterable was moved to collections.abc in Python 3.10.
@@ -1481,8 +1484,7 @@ (define-public ghc-9.2
              (sha256
               (base32
                "0cmmwhcwv9fjzvmgjj85d354858qqbmqfzaz5160xqj4yl9zk225"))
-             (patches (search-patches "ghc-9.2-grep-warnings.patch"
-                                      "ghc-testsuite-recomp015-execstack.patch"))))
+             (patches (search-patches "ghc-9.2-grep-warnings.patch"))))
          ,@(filter (match-lambda
                      (("ghc-bootstrap" . _) #f)
                      (("ghc-testsuite" . _) #f)
diff --git a/gnu/packages/patches/ghc-testsuite-recomp015-execstack.patch b/gnu/packages/patches/ghc-testsuite-recomp015-execstack.patch
deleted file mode 100644
index cdaf5b180d..0000000000
--- a/gnu/packages/patches/ghc-testsuite-recomp015-execstack.patch
+++ /dev/null
@@ -1,10 +0,0 @@
---- a/testsuite/tests/driver/recomp015/Makefile   2024-01-13 16:22:42.643106725 +0100
-+++ b/testsuite/tests/driver/recomp015/Makefile   2024-01-13 16:23:18.406867917 +0100
-@@ -26,6 +26,7 @@
- 	# number of sections)
- 	'$(TEST_HC)' $(TEST_HC_OPTS) Generate.hs
- 	./Generate > ManySections.s
-+	echo '.section .note.GNU-stack,"",@progbits' > ManySections.s
- 	echo 'main = putStrLn "Running main..."' > Main.hs
- 	'$(TEST_HC)' $(TEST_HC_OPTS) -c ManySections.s
- 	'$(TEST_HC)' $(TEST_HC_OPTS) --make -O Main.hs ManySections.o
-- 
2.46.0