Subject: [PATCH 1/2] gnu: Add mimalloc.

From: phodina <[email-masked]>
Date: Fri, 28 Jan 2022 10:50:17 +0000

Hi,

here is a patch set to add mold linker.

I've temporarily put the package definition into gnu/packages/raspberry-pi.scm as I'm unsure if it should go to gnu/packages/commencement.scm or somewhere else.

It would be be interesting to test it as a new default linker on such a large scale project.

Also there is currently one test failing so I've disabled the tests for now:

Testing mold-wrapper ... execl: No such file or directory
make[1]: *** [Makefile.linux:6: elf/mold-wrapper.sh] Error 1
make[1]: *** Waiting for unfinished jobs....

----
Petr

From 67fd2d0a9ffa2a13e5b289c9f4cd7f9dd85a91c6 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Wed, 29 Dec 2021 22:41:47 +0100
Subject: [PATCH 1/2] gnu: Add mimalloc.

* gnu/packages/WIP (mimalloc): Add new variable.

diff --git a/gnu/packages/raspberry-pi.scm b/gnu/packages/raspberry-pi.scm
index bb38b8b218..a0142c2333 100644
--- a/gnu/packages/raspberry-pi.scm
+++ b/gnu/packages/raspberry-pi.scm
@@ -29,6 +29,7 @@ (define-module (gnu packages raspberry-pi)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages embedded)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system cmake)
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module ((guix licenses) #:prefix license:)
@@ -42,6 +43,37 @@ (define-module (gnu packages raspberry-pi)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 match))
 
+(define-public mimalloc
+  (package
+    (name "mimalloc")
+    (version "2.0.3")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/microsoft/mimalloc")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0avamijn2dcrkba291rmdiv6z0kjzkhc1vigcwmhk9h0cvsc0q44"))))
+    (build-system cmake-build-system)
+    (synopsis "Compact general purpose allocator")
+    (description "This package provides a drop-in replacement for malloc.
+It provides the following benefits:
+@enumerate
+@item small and consistent
+@item free list sharding
+@item free list multi-sharding
+@item eager page reset
+@item secure
+@item first-class heaps
+@item bounded
+@item fast
+@end enumerate
+")
+    (home-page "https://github.com/microsoft/mimalloc")
+    (license license:expat)))
+
 (define-public bcm2835
   (package
     (name "bcm2835")
-- 
2.34.0

From a1928e92512915a6d041da0195d6c2bb164f505d Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Wed, 29 Dec 2021 22:42:48 +0100
Subject: [PATCH 2/2] gnu: Add mold.

* gnu/packages/WIP (mold): New variable.

diff --git a/gnu/packages/raspberry-pi.scm b/gnu/packages/raspberry-pi.scm
index a0142c2333..b59ec822c9 100644
--- a/gnu/packages/raspberry-pi.scm
+++ b/gnu/packages/raspberry-pi.scm
@@ -22,11 +22,21 @@ (define-module (gnu packages raspberry-pi)
   #:use-module (gnu packages algebra)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
+  #:use-module (gnu packages llvm)
+  #:use-module (gnu packages cmake)
   #:use-module (gnu packages commencement)
+  #:use-module (gnu packages compression)
   #:use-module (gnu packages cross-base)
+  #:use-module (gnu packages digest)
   #:use-module (gnu packages documentation)
   #:use-module (gnu packages file)
+  #:use-module (gnu packages linux)
   #:use-module (gnu packages gcc)
+  #:use-module (gnu packages tbb)
+  #:use-module (gnu packages tls)
+  #:use-module (gnu packages perl)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages python)
   #:use-module (gnu packages embedded)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system cmake)
@@ -74,6 +84,57 @@ (define-public mimalloc
     (home-page "https://github.com/microsoft/mimalloc")
     (license license:expat)))
 
+(define-public mold
+  (package
+    (name "mold")
+    (version "1.0.2")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/rui314/mold")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (modules '((guix build utils)))
+              (snippet '(begin
+                          (delete-file-recursively "third-party")))
+              (sha256
+               (base32
+                "08iiycbzb4324mnzph6m4y5kf700zhr66c0sq93k5sajm3xy8dfi"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:make-flags (list "SYSTEM_MIMALLOC=true" "SYSTEM_TBB=true"
+                          "SYSTEM_XXHASH=true"
+                          (string-append "PREFIX=" %output))
+       #:tests? #f ; failing test mold-wrapper
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'patch-reference-to-cc
+           ;; This prevents errors like 'error: linker `cc` not found' when
+           ;; "cc" is not found on PATH.
+           (lambda* (#:key outputs inputs #:allow-other-keys)
+             (let ((gcc (assoc-ref inputs "gcc")) (util-linux (assoc-ref
+                                                               inputs
+                                                               "util-linux")))
+               (substitute* "test/elf/exception.sh"
+                 (("`pwd`/../../mold") (string-append (getcwd) "/mold")))
+               (substitute* "test/elf/gc-sections.sh"
+                 (("`pwd`/../../mold") (string-append (getcwd) "/mold")))
+               (substitute* "test/elf/filler.sh"
+                 (("hexdump") (string-append util-linux "/bin/hexdump")))
+               (mkdir-p "/tmp/bin")
+               (symlink (string-append gcc "/bin/gcc") "/tmp/bin/cc")
+               (setenv "PATH"
+                       (string-append "/tmp/bin:"
+                                      (getenv "PATH"))))))
+         (delete 'configure))))
+    (native-inputs (list clang-12 gcc grep pkg-config util-linux xxhash))
+    (inputs (list mimalloc openssl python tbb zlib))
+    (synopsis "Modern Linker")
+    (description "This package provides a faster drop-in replacement for
+existing Unix linkers.")
+    (home-page "https://savannah.gnu.org/projects/patch/")
+    (license license:gpl3+)))
+
 (define-public bcm2835
   (package
     (name "bcm2835")
-- 
2.34.0