From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gQU0GATCwF+aEQAA0tVLHw (envelope-from ) for ; Fri, 27 Nov 2020 09:08:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id YBqBEwTCwF94LQAA1q6Kng (envelope-from ) for ; Fri, 27 Nov 2020 09:08:20 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BC6C99403A9 for ; Fri, 27 Nov 2020 09:08:19 +0000 (UTC) Received: from localhost ([::1]:35512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kiZjm-0000Gp-JT for larch@yhetil.org; Fri, 27 Nov 2020 04:08:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiZha-0006gG-WA for guix-patches@gnu.org; Fri, 27 Nov 2020 04:06:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kiZha-000660-OS for guix-patches@gnu.org; Fri, 27 Nov 2020 04:06:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kiZha-0005De-J2 for guix-patches@gnu.org; Fri, 27 Nov 2020 04:06:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#44899] [PATCH 3/3] build-system/gnu: Add 'make-dynamic-linker-cache' phase. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 27 Nov 2020 09:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44899 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44899@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 44899-submit@debbugs.gnu.org id=B44899.160646795920040 (code B ref 44899); Fri, 27 Nov 2020 09:06:02 +0000 Received: (at 44899) by debbugs.gnu.org; 27 Nov 2020 09:05:59 +0000 Received: from localhost ([127.0.0.1]:43940 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kiZhX-0005D9-Bo for submit@debbugs.gnu.org; Fri, 27 Nov 2020 04:05:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43310) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kiZhQ-0005CU-C4 for 44899@debbugs.gnu.org; Fri, 27 Nov 2020 04:05:52 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34175) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kiZhL-0005vC-7u; Fri, 27 Nov 2020 04:05:47 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=46474 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kiZhJ-0006Z5-SE; Fri, 27 Nov 2020 04:05:46 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 27 Nov 2020 10:05:23 +0100 Message-Id: <20201127090523.3853-3-ludo@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201127090523.3853-1-ludo@gnu.org> References: <20201127090523.3853-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 2.24 X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-TUID: 3xn5hVfrqWny * guix/build/gnu-build-system.scm (make-dynamic-linker-cache): New procedure. (%standard-phases): Add it. * guix/build-system/gnu.scm (gnu-build, gnu-cross-build): Add #:make-dynamic-linker-cache? and honor it. --- guix/build-system/gnu.scm | 4 ++ guix/build/gnu-build-system.scm | 73 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm index 2c23197e77..d6c4dc9bbc 100644 --- a/guix/build-system/gnu.scm +++ b/guix/build-system/gnu.scm @@ -342,6 +342,7 @@ standard packages used as implicit inputs of the GNU build system." (strip-directories ''("lib" "lib64" "libexec" "bin" "sbin")) (validate-runpath? #t) + (make-dynamic-linker-cache? #t) (license-file-regexp %license-file-regexp) (phases '%standard-phases) (locale "en_US.utf8") @@ -410,6 +411,7 @@ packages that must not be referenced." #:patch-shebangs? ,patch-shebangs? #:strip-binaries? ,strip-binaries? #:validate-runpath? ,validate-runpath? + #:make-dynamic-linker-cache? ,make-dynamic-linker-cache? #:license-file-regexp ,license-file-regexp #:strip-flags ,strip-flags #:strip-directories ,strip-directories))) @@ -497,6 +499,7 @@ is one of `host' or `target'." (strip-directories ''("lib" "lib64" "libexec" "bin" "sbin")) (validate-runpath? #t) + (make-dynamic-linker-cache? #t) (license-file-regexp %license-file-regexp) (phases '%standard-phases) (locale "en_US.utf8") @@ -577,6 +580,7 @@ platform." #:patch-shebangs? ,patch-shebangs? #:strip-binaries? ,strip-binaries? #:validate-runpath? ,validate-runpath? + #:make-dynamic-linker-cache? ,make-dynamic-linker-cache? #:license-file-regexp ,license-file-regexp #:strip-flags ,strip-flags #:strip-directories ,strip-directories)))) diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm index 8fa11f4ea9..194cddc047 100644 --- a/guix/build/gnu-build-system.scm +++ b/guix/build/gnu-build-system.scm @@ -712,6 +712,78 @@ which cannot be found~%" (which binary) rest))))))))) outputs)) +(define* (make-dynamic-linker-cache #:key outputs + (make-dynamic-linker-cache? #t) + #:allow-other-keys) + "Create a dynamic linker cache under 'etc/ld.so.cache' in each of the +OUTPUTS. This reduces application startup time by avoiding the 'stat' storm +that traversing all the RUNPATH entries entails." + (define (make-cache-for-output directory) + (define bin-directories + (filter-map (lambda (sub-directory) + (let ((directory (string-append directory "/" + sub-directory))) + (and (directory-exists? directory) + directory))) + '("bin" "sbin"))) + + (define programs + ;; Programs that can benefit from the ld.so cache. These programs must + ;; be in a directory such that: + ;; + ;; (string-append (dirname PROGRAM) "../etc/ld.so.cache") + ;; + ;; potentially exists since that's what ld.so will look for. Thus, + ;; something like 'libexec/foo/PROGRAM' is not a valid candidate. + (append-map (lambda (directory) + (if (directory-exists? directory) + (filter-map (lambda (file) + (let ((file (string-append + directory "/" file))) + (and (executable-file? file) + (not (file-is-directory? file)) + (elf-file? file) + file))) + (scandir directory)) + '())) + bin-directories)) + + (define runpaths + ;; The union of RUNPATH entries. + (delete-duplicates + (append-map (lambda (program) + (or (file-runpath program) '())) + programs))) + + (define cache-file + (string-append directory "/etc/ld.so.cache")) + + (unless (null? runpaths) + (mkdir-p (dirname cache-file)) + (guard (c ((invoke-error? c) + ;; Do not treat 'ldconfig' failure as an error. + (format (current-error-port) + "warning: 'ldconfig' failed:~%") + (report-invoke-error c (current-error-port)))) + ;; Create a config file to tell 'ldconfig' where to look for the + ;; libraries that PROGRAMS need. + (call-with-output-file "/tmp/ld.so.conf" + (lambda (port) + (for-each (lambda (directory) + (display directory port) + (newline port)) + runpaths))) + + (invoke "ldconfig" "-f" "/tmp/ld.so.conf" "-C" cache-file) + (format #t "created '~a' from ~a library search path entries~%" + cache-file (length runpaths))))) + + (if make-dynamic-linker-cache? + (match outputs + (((_ . directories) ...) + (for-each make-cache-for-output directories))) + (format #t "ld.so cache not built~%"))) + (define %license-file-regexp ;; Regexp matching license files. "^(COPYING.*|LICEN[CS]E.*|[Ll]icen[cs]e.*|Copy[Rr]ight(\\.(txt|md))?)$") @@ -791,6 +863,7 @@ which cannot be found~%" validate-documentation-location delete-info-dir-file patch-dot-desktop-files + make-dynamic-linker-cache install-license-files reset-gzip-timestamps compress-documentation))) -- 2.29.2