GNU bug report logs - #28336
[PATCH 0/1] core-updates: Add "static" output to glibc

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Sun, 3 Sep 2017 12:33:01 UTC

Severity: normal

Tags: patch

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 28336 in the body.
You can then email your comments to 28336 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#28336; Package guix-patches. (Sun, 03 Sep 2017 12:33:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ludovic Courtès <ludo <at> gnu.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sun, 03 Sep 2017 12:33:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: guix-patches <at> gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 0/1] core-updates: Add "static" output to glibc
Date: Sun,  3 Sep 2017 14:32:03 +0200
Hello Guix!

This patch for ‘core-updates’ adds a “static” output to glibc, which
shaves 9 MiB out of it.

“glibc:static” is always part of the implicit inputs of
‘gnu-build-system’ though, such that building a statically-linked
package does not require any modification.

I’d like to apply it shortly if there are no issues.

Thanks,
Ludo’.

Ludovic Courtès (1):
  gnu: glibc: Add "static" output.

 gnu/packages/base.scm         | 49 +++++++++++++++++++++++++++++++++++++++++--
 gnu/packages/commencement.scm | 22 +++++++++++++++----
 gnu/packages/cross-base.scm   |  1 +
 3 files changed, 66 insertions(+), 6 deletions(-)

-- 
2.14.1





Information forwarded to guix-patches <at> gnu.org:
bug#28336; Package guix-patches. (Sun, 03 Sep 2017 12:34:01 GMT) Full text and rfc822 format available.

Message #8 received at 28336 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 28336 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 1/1] gnu: glibc: Add "static" output.
Date: Sun,  3 Sep 2017 14:33:36 +0200
This shrinks glibc:out from 37 MiB to 29 MiB.

* gnu/packages/base.scm (glibc/linux)[outputs]: Add "static".
[arguments]: Add #:modules.  Add 'move-static-libs' phase.
* gnu/packages/commencement.scm (static-bash-for-glibc): Augment
 #:configure-flags to pass "-L LIBC:STATIC".  Add the "static" output of
GLIBC-FINAL to 'inputs'.
(%boot2-inputs, %final-inputs): Likewise.
(canonical-package): Adjust to deal with multiple-output packages.
* gnu/packages/cross-base.scm (cross-gcc): Add the "static" output of
LIBC to 'native-inputs'.
---
 gnu/packages/base.scm         | 49 +++++++++++++++++++++++++++++++++++++++++--
 gnu/packages/commencement.scm | 22 +++++++++++++++----
 gnu/packages/cross-base.scm   |  1 +
 3 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm
index 532bb3e95..ef81f2069 100644
--- a/gnu/packages/base.scm
+++ b/gnu/packages/base.scm
@@ -542,7 +542,8 @@ store.")
    ;; users should automatically pull Linux headers as well.
    (propagated-inputs `(("kernel-headers" ,linux-libre-headers)))
 
-   (outputs '("out" "debug"))
+   (outputs '("out" "debug"
+              "static"))                          ;9 MiB of .a files
 
    (arguments
     `(#:out-of-source? #t
@@ -553,6 +554,11 @@ store.")
       ;; RUNPATH checks.
       #:validate-runpath? #f
 
+      #:modules ((ice-9 ftw)
+                 (srfi srfi-26)
+                 (guix build utils)
+                 (guix build gnu-build-system))
+
       #:configure-flags
       (list "--enable-add-ons"
             "--sysconfdir=/etc"
@@ -657,7 +663,46 @@ store.")
                          ;; "bilingual" eval/exec magic at the top of the file.
                          "")
                         (("exec @PERL@")
-                         "exec perl"))))))))
+                         "exec perl")))))
+
+                 (add-after 'install 'move-static-libs
+                   (lambda* (#:key outputs #:allow-other-keys)
+                     ;; Move static libraries to the "static" output.
+                     (define (static-library? file)
+                       ;; Return true if FILE is a static library.  The
+                       ;; "_nonshared.a" files are referred to by libc.so,
+                       ;; libpthread.so, etc., which are in fact linker
+                       ;; scripts.
+                       (and (string-suffix? ".a" file)
+                            (not (string-contains file "_nonshared"))))
+
+                     (define (linker-script? file)
+                       ;; Guess whether FILE, a ".a" file, is actually a
+                       ;; linker script.
+                       (and (not (ar-file? file))
+                            (not (elf-file? file))))
+
+                     (let* ((out    (assoc-ref outputs "out"))
+                            (lib    (string-append out "/lib"))
+                            (files  (scandir lib static-library?))
+                            (static (assoc-ref outputs "static"))
+                            (slib   (string-append static "/lib")))
+                       (mkdir-p slib)
+                       (for-each (lambda (base)
+                                   (rename-file (string-append lib "/" base)
+                                                (string-append slib "/" base)))
+                                 files)
+
+                       ;; Usually libm.a is a linker script so we need to
+                       ;; change the file names in there to refer to STATIC
+                       ;; instead of OUT.
+                       (for-each (lambda (ld-script)
+                                   (substitute* ld-script
+                                     ((out) static)))
+                                 (filter linker-script?
+                                         (map (cut string-append slib "/" <>)
+                                              files)))
+                       #t))))))
 
    (inputs `(("static-bash" ,static-bash)))
 
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 2b67881ed..318a2795b 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -583,12 +583,24 @@ exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
   (let* ((gcc  (cross-gcc-wrapper gcc-boot0 binutils-boot0
                                   glibc-final-with-bootstrap-bash
                                   (car (assoc-ref %boot1-inputs "bash"))))
-         (bash (package (inherit static-bash)
+         (bash (package
+                 (inherit static-bash)
                  (arguments
-                  `(#:guile ,%bootstrap-guile
-                    ,@(package-arguments static-bash)))))
+                  (substitute-keyword-arguments
+                      (package-arguments static-bash)
+                    ((#:guile _ #f)
+                     '%bootstrap-guile)
+                    ((#:configure-flags flags '())
+                     ;; Add a '-L' flag so that the pseudo-cross-ld of
+                     ;; BINUTILS-BOOT0 can find libc.a.
+                     `(append ,flags
+                              (list (string-append "LDFLAGS=-static -L"
+                                                   (assoc-ref %build-inputs
+                                                              "libc:static")
+                                                   "/lib"))))))))
          (inputs `(("gcc" ,gcc)
                    ("libc" ,glibc-final-with-bootstrap-bash)
+                   ("libc:static" ,glibc-final-with-bootstrap-bash "static")
                    ,@(fold alist-delete %boot1-inputs
                            '("gcc" "libc")))))
     (package-with-bootstrap-guile
@@ -663,6 +675,7 @@ exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
 (define %boot2-inputs
   ;; 3rd stage inputs.
   `(("libc" ,glibc-final)
+    ("libc:static" ,glibc-final "static")
     ("gcc" ,gcc-boot0-wrapped)
     ,@(fold alist-delete %boot1-inputs '("libc" "gcc"))))
 
@@ -923,12 +936,13 @@ exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
       ("binutils" ,binutils-final)
       ("gcc" ,gcc-final)
       ("libc" ,glibc-final)
+      ("libc:static" ,glibc-final "static")
       ("locales" ,glibc-utf8-locales-final))))
 
 (define-public canonical-package
   (let ((name->package (fold (lambda (input result)
                                (match input
-                                 ((_ package)
+                                 ((_ package . outputs)
                                   (vhash-cons (package-full-name package)
                                               package result))))
                              vlist-null
diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index abc3a2821..369083eab 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -248,6 +248,7 @@ target that libc."
                    ,@inputs)))
             (libc
              `(("libc" ,libc)
+               ("libc:static" ,libc "static")
                ("xkernel-headers"                ;the target headers
                 ,@(assoc-ref (package-propagated-inputs libc)
                              "kernel-headers"))
-- 
2.14.1





Reply sent to ludo <at> gnu.org (Ludovic Courtès):
You have taken responsibility. (Tue, 05 Sep 2017 08:20:02 GMT) Full text and rfc822 format available.

Notification sent to Ludovic Courtès <ludo <at> gnu.org>:
bug acknowledged by developer. (Tue, 05 Sep 2017 08:20:02 GMT) Full text and rfc822 format available.

Message #13 received at 28336-done <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: 28336-done <at> debbugs.gnu.org
Subject: Re: [bug#28336] [PATCH 0/1] core-updates: Add "static" output to glibc
Date: Tue, 05 Sep 2017 10:19:42 +0200
Ludovic Courtès <ludo <at> gnu.org> skribis:

> This patch for ‘core-updates’ adds a “static” output to glibc, which
> shaves 9 MiB out of it.
>
> “glibc:static” is always part of the implicit inputs of
> ‘gnu-build-system’ though, such that building a statically-linked
> package does not require any modification.
>
> I’d like to apply it shortly if there are no issues.

Pushed as 6dff905e51202bbdebbad8811b6509584d12a796.

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 03 Oct 2017 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 261 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.