diff --git a/contrib/guix/manifest.scm b/contrib/guix/manifest.scm index 695265921..9f08617af 100644 --- a/contrib/guix/manifest.scm +++ b/contrib/guix/manifest.scm @@ -1,623 +1,623 @@ (use-modules (gnu) (gnu packages) (gnu packages autotools) (gnu packages base) (gnu packages bash) (gnu packages bison) (gnu packages certs) (gnu packages cdrom) (gnu packages check) (gnu packages cmake) (gnu packages commencement) (gnu packages compression) (gnu packages cross-base) (gnu packages curl) (gnu packages file) (gnu packages gawk) (gnu packages gcc) (gnu packages gperf) (gnu packages gnome) (gnu packages installers) (gnu packages linux) (gnu packages llvm) (gnu packages mingw) (gnu packages moreutils) (gnu packages ninja) (gnu packages perl) (gnu packages pkg-config) (gnu packages python) (gnu packages python-crypto) (gnu packages python-web) (gnu packages shells) (gnu packages tls) (gnu packages version-control) (guix build-system gnu) (guix build-system python) (guix build-system trivial) (guix download) (guix gexp) (guix git-download) ((guix licenses) #:prefix license:) (guix packages) (guix profiles) (guix utils)) (define-syntax-rule (search-our-patches file-name ...) "Return the list of absolute file names corresponding to each FILE-NAME found in ./patches relative to the current file." (parameterize ((%patch-path (list (string-append (dirname (current-filename)) "/patches")))) (list (search-patch file-name) ...))) (define (make-ssp-fixed-gcc xgcc) "Given a XGCC package, return a modified package that uses the SSP function from glibc instead of from libssp.so. Our `symbol-check' script will complain if we link against libssp.so, and thus will ensure that this works properly. Taken from: http://www.linuxfromscratch.org/hlfs/view/development/chapter05/gcc-pass1.html" (package (inherit xgcc) (arguments (substitute-keyword-arguments (package-arguments xgcc) ((#:make-flags flags) `(cons "gcc_cv_libc_provides_ssp=yes" ,flags)))))) (define (make-gcc-rpath-link xgcc) "Given a XGCC package, return a modified package that replace each instance of -rpath in the default system spec that's inserted by Guix with -rpath-link" (package (inherit xgcc) (arguments (substitute-keyword-arguments (package-arguments xgcc) ((#:phases phases) `(modify-phases ,phases (add-after 'pre-configure 'replace-rpath-with-rpath-link (lambda _ (substitute* (cons "gcc/config/rs6000/sysv4.h" (find-files "gcc/config" "^gnu-user.*\\.h$")) (("-rpath=") "-rpath-link=")) #t)))))))) (define building-on (string-append (list-ref (string-split (%current-system) #\-) 0) "-guix-linux-gnu")) (define (explicit-cross-configure package) (package-with-extra-configure-variable package "--build" building-on)) (define (make-cross-toolchain target base-gcc-for-libc base-kernel-headers base-libc base-gcc) "Create a cross-compilation toolchain package for TARGET" (let* ((xbinutils (cross-binutils target)) ;; 1. Build a cross-compiling gcc without targeting any libc, derived ;; from BASE-GCC-FOR-LIBC (xgcc-sans-libc (explicit-cross-configure (cross-gcc target #:xgcc base-gcc-for-libc #:xbinutils xbinutils))) ;; 2. Build cross-compiled kernel headers with XGCC-SANS-LIBC, derived ;; from BASE-KERNEL-HEADERS (xkernel (cross-kernel-headers target base-kernel-headers xgcc-sans-libc xbinutils)) ;; 3. Build a cross-compiled libc with XGCC-SANS-LIBC and XKERNEL, ;; derived from BASE-LIBC (xlibc (explicit-cross-configure (cross-libc target base-libc xgcc-sans-libc xbinutils xkernel))) ;; 4. Build a cross-compiling gcc targeting XLIBC, derived from ;; BASE-GCC (xgcc (explicit-cross-configure (cross-gcc target #:xgcc base-gcc #:xbinutils xbinutils #:libc xlibc)))) ;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and ;; XGCC (package (name (string-append target "-toolchain")) (version (package-version xgcc)) (source #f) (build-system trivial-build-system) (arguments '(#:builder (begin (mkdir %output) #t))) (propagated-inputs `(("binutils" ,xbinutils) ("libc" ,xlibc) ("libc:static" ,xlibc "static") ("gcc" ,xgcc) ("gcc-lib" ,xgcc "lib"))) (synopsis (string-append "Complete GCC tool chain for " target)) (description (string-append "This package provides a complete GCC tool chain for " target " development.")) (home-page (package-home-page xgcc)) (license (package-license xgcc))))) (define base-gcc gcc-10) (define base-linux-kernel-headers linux-libre-headers-5.15) ;; https://gcc.gnu.org/install/configure.html (define (hardened-gcc gcc) (package-with-extra-configure-variable ( package-with-extra-configure-variable ( package-with-extra-configure-variable gcc "--enable-initfini-array" "yes") "--enable-default-ssp" "yes") "--enable-default-pie" "yes")) (define* (make-bitcoin-cross-toolchain target #:key (base-gcc-for-libc base-gcc) (base-kernel-headers base-linux-kernel-headers) - (base-libc (hardened-glibc (make-glibc-without-werror glibc-2.27))) + (base-libc (hardened-glibc (make-glibc-without-werror glibc-2.28))) (base-gcc (make-gcc-rpath-link (hardened-gcc base-gcc)))) "Convenience wrapper around MAKE-CROSS-TOOLCHAIN with default values desirable for building Bitcoin ABC release binaries." (make-cross-toolchain target base-gcc-for-libc base-kernel-headers base-libc base-gcc)) (define (make-gcc-with-pthreads gcc) (package-with-extra-configure-variable (package-with-extra-patches gcc (search-our-patches "gcc-10-remap-guix-store.patch")) "--enable-threads" "posix")) (define (make-mingw-w64-cross-gcc cross-gcc) (package-with-extra-patches cross-gcc (search-our-patches "vmov-alignment.patch" "gcc-broken-longjmp.patch"))) (define (make-mingw-pthreads-cross-toolchain target) "Create a cross-compilation toolchain package for TARGET" (let* ((xbinutils (cross-binutils target)) (pthreads-xlibc mingw-w64-x86_64-winpthreads) (pthreads-xgcc (make-gcc-with-pthreads (cross-gcc target #:xgcc (make-ssp-fixed-gcc (make-mingw-w64-cross-gcc base-gcc)) #:xbinutils xbinutils #:libc pthreads-xlibc)))) ;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and ;; XGCC (package (name (string-append target "-posix-toolchain")) (version (package-version pthreads-xgcc)) (source #f) (build-system trivial-build-system) (arguments '(#:builder (begin (mkdir %output) #t))) (propagated-inputs `(("binutils" ,xbinutils) ("libc" ,pthreads-xlibc) ("gcc" ,pthreads-xgcc) ("gcc-lib" ,pthreads-xgcc "lib"))) (synopsis (string-append "Complete GCC tool chain for " target)) (description (string-append "This package provides a complete GCC tool chain for " target " development.")) (home-page (package-home-page pthreads-xgcc)) (license (package-license pthreads-xgcc))))) (define (make-nsis-for-gcc-10 base-nsis) (package-with-extra-patches base-nsis (search-our-patches "nsis-gcc-10-memmove.patch" "nsis-disable-installer-reloc.patch"))) (define (fix-ppc64-nx-default lief) (package-with-extra-patches lief (search-our-patches "lief-fix-ppc64-nx-default.patch"))) (define-public lief (package (name "python-lief") (version "0.12.1") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/lief-project/LIEF.git") (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "1xzbh3bxy4rw1yamnx68da1v5s56ay4g081cyamv67256g0qy2i1")))) (build-system python-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'unpack 'parallel-jobs ;; build with multiple cores (lambda _ (substitute* "setup.py" (("self.parallel if self.parallel else 1") (number->string (parallel-job-count))))))))) (native-inputs `(("cmake" ,cmake))) (home-page "https://github.com/lief-project/LIEF") (synopsis "Library to Instrument Executable Formats") (description "Python library to to provide a cross platform library which can parse, modify and abstract ELF, PE and MachO formats.") (license license:asl2.0))) (define osslsigncode (package (name "osslsigncode") (version "2.0") (source (origin (method url-fetch) (uri (string-append "https://github.com/mtrojnar/" name "/archive/" version ".tar.gz")) (sha256 (base32 "0byri6xny770wwb2nciq44j5071122l14bvv65axdd70nfjf0q2s")))) (build-system gnu-build-system) (native-inputs `(("pkg-config" ,pkg-config) ("autoconf" ,autoconf) ("automake" ,automake) ("libtool" ,libtool))) (inputs `(("openssl" ,openssl))) (arguments `(#:configure-flags `("--without-gsf" "--without-curl" "--disable-dependency-tracking"))) (home-page "https://github.com/mtrojnar/osslsigncode") (synopsis "Authenticode signing and timestamping tool") (description "osslsigncode is a small tool that implements part of the functionality of the Microsoft tool signtool.exe - more exactly the Authenticode signing and timestamping. But osslsigncode is based on OpenSSL and cURL, and thus should be able to compile on most platforms where these exist.") (license license:gpl3+))) ; license is with openssl exception (define-public python-elfesteem (let ((commit "2eb1e5384ff7a220fd1afacd4a0170acff54fe56")) (package (name "python-elfesteem") (version (git-version "0.1" "1" commit)) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/LRGH/elfesteem") (commit commit))) (file-name (git-file-name name commit)) (sha256 (base32 "07x6p8clh11z8s1n2kdxrqwqm2almgc5qpkcr9ckb6y5ivjdr5r6")))) (build-system python-build-system) ;; There are no tests, but attempting to run python setup.py test leads to ;; PYTHONPATH problems, just disable the test (arguments '(#:tests? #f)) (home-page "https://github.com/LRGH/elfesteem") (synopsis "ELF/PE/Mach-O parsing library") (description "elfesteem parses ELF, PE and Mach-O files.") (license license:lgpl2.1)))) (define-public python-oscrypto (package (name "python-oscrypto") (version "1.2.1") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/wbond/oscrypto") (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "1d4d8s4z340qhvb3g5m5v3436y3a71yc26wk4749q64m09kxqc3l")) (patches (search-our-patches "oscrypto-hard-code-openssl.patch")))) (build-system python-build-system) (native-search-paths (list (search-path-specification (variable "SSL_CERT_FILE") (file-type 'regular) (separator #f) ;single entry (files '("etc/ssl/certs/ca-certificates.crt"))))) (propagated-inputs `(("python-asn1crypto" ,python-asn1crypto) ("openssl" ,openssl))) (arguments `(#:phases (modify-phases %standard-phases (add-after 'unpack 'hard-code-path-to-libscrypt (lambda* (#:key inputs #:allow-other-keys) (let ((openssl (assoc-ref inputs "openssl"))) (substitute* "oscrypto/__init__.py" (("@GUIX_OSCRYPTO_USE_OPENSSL@") (string-append openssl "/lib/libcrypto.so" "," openssl "/lib/libssl.so"))) #t))) (add-after 'unpack 'disable-broken-tests (lambda _ ;; This test is broken as there is no keyboard interrupt. (substitute* "tests/test_trust_list.py" (("^(.*)class TrustListTests" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "tests/test_tls.py" (("^(.*)class TLSTests" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) #t)) (replace 'check (lambda _ (invoke "python" "run.py" "tests") #t))))) (home-page "https://github.com/wbond/oscrypto") (synopsis "Compiler-free Python crypto library backed by the OS") (description "oscrypto is a compilation-free, always up-to-date encryption library for Python.") (license license:expat))) (define-public python-oscryptotests (package (inherit python-oscrypto) (name "python-oscryptotests") (propagated-inputs `(("python-oscrypto" ,python-oscrypto))) (arguments `(#:tests? #f #:phases (modify-phases %standard-phases (add-after 'unpack 'hard-code-path-to-libscrypt (lambda* (#:key inputs #:allow-other-keys) (chdir "tests") #t))))))) (define-public python-certvalidator (let ((commit "a145bf25eb75a9f014b3e7678826132efbba6213")) (package (name "python-certvalidator") (version (git-version "0.1" "1" commit)) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/achow101/certvalidator") (commit commit))) (file-name (git-file-name name commit)) (sha256 (base32 "1qw2k7xis53179lpqdqyylbcmp76lj7sagp883wmxg5i7chhc96k")))) (build-system python-build-system) (propagated-inputs `(("python-asn1crypto" ,python-asn1crypto) ("python-oscrypto" ,python-oscrypto) ("python-oscryptotests", python-oscryptotests))) ;; certvalidator tests import oscryptotests (arguments `(#:phases (modify-phases %standard-phases (add-after 'unpack 'disable-broken-tests (lambda _ (substitute* "tests/test_certificate_validator.py" (("^(.*)class CertificateValidatorTests" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "tests/test_crl_client.py" (("^(.*)def test_fetch_crl" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "tests/test_ocsp_client.py" (("^(.*)def test_fetch_ocsp" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "tests/test_registry.py" (("^(.*)def test_build_paths" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "tests/test_validate.py" (("^(.*)def test_revocation_mode_hard" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "tests/test_validate.py" (("^(.*)def test_revocation_mode_soft" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) #t)) (replace 'check (lambda _ (invoke "python" "run.py" "tests") #t))))) (home-page "https://github.com/wbond/certvalidator") (synopsis "Python library for validating X.509 certificates and paths") (description "certvalidator is a Python library for validating X.509 certificates or paths. Supports various options, including: validation at a specific moment in time, whitelisting and revocation checks.") (license license:expat)))) (define-public python-altgraph (package (name "python-altgraph") (version "0.17") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/ronaldoussoren/altgraph") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "09sm4srvvkw458pn48ga9q7ykr4xlz7q8gh1h9w7nxpf001qgpwb")))) (build-system python-build-system) (home-page "https://github.com/ronaldoussoren/altgraph") (synopsis "Python graph (network) package") (description "altgraph is a fork of graphlib: a graph (network) package for constructing graphs, BFS and DFS traversals, topological sort, shortest paths, etc. with graphviz output.") (license license:expat))) (define-public python-macholib (package (name "python-macholib") (version "1.14") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/ronaldoussoren/macholib") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "0aislnnfsza9wl4f0vp45ivzlc0pzhp9d4r08700slrypn5flg42")))) (build-system python-build-system) (propagated-inputs `(("python-altgraph" ,python-altgraph))) (arguments '(#:phases (modify-phases %standard-phases (add-after 'unpack 'disable-broken-tests (lambda _ ;; This test is broken as there is no keyboard interrupt. (substitute* "macholib_tests/test_command_line.py" (("^(.*)class TestCmdLine" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line))) (substitute* "macholib_tests/test_dyld.py" (("^(.*)def test_\\S+_find" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line)) (("^(.*)def testBasic" line indent) (string-append indent "@unittest.skip(\"Disabled by Guix\")\n" line)) ) #t))))) (home-page "https://github.com/ronaldoussoren/macholib") (synopsis "Python library for analyzing and editing Mach-O headers") (description "macholib is a Macho-O header analyzer and editor. It's typically used as a dependency analysis tool, and also to rewrite dylib references in Mach-O headers to be @executable_path relative. Though this tool targets a platform specific file format, it is pure python code that is platform and endian independent.") (license license:expat))) (define-public python-signapple (let ((commit "8a945a2e7583be2665cf3a6a89d665b70ecd1ab6")) (package (name "python-signapple") (version (git-version "0.1" "1" commit)) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/achow101/signapple") (commit commit))) (file-name (git-file-name name commit)) (sha256 (base32 "0fr1hangvfyiwflca6jg5g8zvg3jc9qr7vd2c12ff89pznf38dlg")))) (build-system python-build-system) (propagated-inputs `(("python-asn1crypto" ,python-asn1crypto) ("python-oscrypto" ,python-oscrypto) ("python-certvalidator" ,python-certvalidator) ("python-elfesteem" ,python-elfesteem) ("python-requests" ,python-requests) ("python-macholib" ,python-macholib))) ;; There are no tests, but attempting to run python setup.py test leads to ;; problems, just disable the test (arguments '(#:tests? #f)) (home-page "https://github.com/achow101/signapple") (synopsis "Mach-O binary signature tool") (description "signapple is a Python tool for creating, verifying, and inspecting signatures in Mach-O binaries.") (license license:expat)))) (define (make-glibc-without-werror glibc) (package-with-extra-configure-variable glibc "enable_werror" "no")) ;; https://www.gnu.org/software/libc/manual/html_node/Configuring-and-compiling.html (define (hardened-glibc glibc) (package-with-extra-configure-variable ( package-with-extra-configure-variable glibc "--enable-stack-protector" "all") "--enable-bind-now" "yes")) -(define-public glibc-2.27 +(define-public glibc-2.28 (package (inherit glibc-2.31) - (version "2.27") + (version "2.28") (source (origin (method git-fetch) (uri (git-reference (url "https://sourceware.org/git/glibc.git") - (commit "73886db6218e613bd6d4edf529f11e008a6c2fa6"))) - (file-name (git-file-name "glibc" "73886db6218e613bd6d4edf529f11e008a6c2fa6")) + (commit "c9e58ae23402eb82877de90fd8a18519c086ed87"))) + (file-name (git-file-name "glibc" "c9e58ae23402eb82877de90fd8a18519c086ed87")) (sha256 (base32 - "0azpb9cvnbv25zg8019rqz48h8i2257ngyjg566dlnp74ivrs9vq")) + "0wm0if2n4z48kpn85va6yb4iac34crds2f55ddpz1hykx6jp1pb6")) (patches (search-our-patches "glibc-ldd-x86_64.patch" "glibc-versioned-locpath.patch" - "glibc-2.27-fcommon.patch" - "glibc-2.27-guix-prefix.patch")))))) + "glibc-2.28-fcommon.patch" + "glibc-2.28-guix-prefix.patch")))))) (packages->manifest (append (list ;; The Basics bash-minimal which coreutils-minimal util-linux gperf ;; File(system) inspection file grep diffutils findutils ;; File transformation patch gawk sed moreutils ;; Compression and archiving tar bzip2 gzip xz ;; Build tools cmake ninja gnu-make libtool-2.4.7 autoconf-2.71 automake pkg-config bison ;; Native GCC 10 toolchain gcc-toolchain-10 (list gcc-toolchain-10 "static") ;; Scripting python-3 perl ;; Git git-minimal ;; Tests lief) (let ((target (getenv "HOST"))) (cond ((string-suffix? "-mingw32" target) ;; Windows (list zip (make-mingw-pthreads-cross-toolchain "x86_64-w64-mingw32") (make-nsis-for-gcc-10 nsis-x86_64) osslsigncode)) ((string-contains target "-linux-") (list (make-bitcoin-cross-toolchain target))) ((string-contains target "darwin") (list clang-toolchain-10 binutils xorriso python-signapple)) (else '()))))) diff --git a/contrib/guix/patches/glibc-2.27-fcommon.patch b/contrib/guix/patches/glibc-2.28-fcommon.patch similarity index 96% rename from contrib/guix/patches/glibc-2.27-fcommon.patch rename to contrib/guix/patches/glibc-2.28-fcommon.patch index 3b78e093f..1d730164e 100644 --- a/contrib/guix/patches/glibc-2.27-fcommon.patch +++ b/contrib/guix/patches/glibc-2.28-fcommon.patch @@ -1,32 +1,32 @@ commit 264a4a0dbe1f4369db315080034b500bed66016c Author: fanquake Date: Fri May 6 11:03:04 2022 +0100 build: use -fcommon to retain legacy behaviour with GCC 10 GCC 10 started using -fno-common by default, which causes issues with the powerpc builds using gibc 2.24. A patch was committed to glibc to fix the issue, 18363b4f010da9ba459b13310b113ac0647c2fcc but is non-trvial to backport, and was broken in at least one way, see the followup in commit 7650321ce037302bfc2f026aa19e0213b8d02fe6. For now, retain the legacy GCC behaviour by passing -fcommon when building glibc. https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html. https://sourceware.org/git/?p=glibc.git;a=commit;h=18363b4f010da9ba459b13310b113ac0647c2fcc https://sourceware.org/git/?p=glibc.git;a=commit;h=7650321ce037302bfc2f026aa19e0213b8d02fe6 diff --git a/Makeconfig b/Makeconfig index 86a71e5802..aa2166be60 100644 --- a/Makeconfig +++ b/Makeconfig -@@ -896,7 +896,7 @@ ifeq "$(strip $(+cflags))" "" +@@ -901,7 +901,7 @@ ifeq "$(strip $(+cflags))" "" endif # $(+cflags) == "" +cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags) \ - $(+stack-protector) + $(+stack-protector) -fcommon +gcc-nowarn := -w # Don't duplicate options if we inherited variables from the parent. diff --git a/contrib/guix/patches/glibc-2.27-guix-prefix.patch b/contrib/guix/patches/glibc-2.28-guix-prefix.patch similarity index 95% rename from contrib/guix/patches/glibc-2.27-guix-prefix.patch rename to contrib/guix/patches/glibc-2.28-guix-prefix.patch index 6648bc6c0..f73e7cb4d 100644 --- a/contrib/guix/patches/glibc-2.27-guix-prefix.patch +++ b/contrib/guix/patches/glibc-2.28-guix-prefix.patch @@ -1,22 +1,22 @@ Without ffile-prefix-map, the debug symbols will contain paths for the guix store which will include the hashes of each package. However, the hash for the same package will differ when on different architectures. In order to be reproducible regardless of the architecture used to build the package, map all guix store prefixes to something fixed, e.g. /usr. We might be able to drop this in favour of using --with-nonshared-cflags when we being using newer versions of glibc. --- a/Makeconfig +++ b/Makeconfig -@@ -992,6 +992,10 @@ object-suffixes := +@@ -998,6 +998,10 @@ object-suffixes := CPPFLAGS-.o = $(pic-default) # libc.a must be compiled with -fPIE/-fpie for static PIE. CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) $(pie-default) + +# Map Guix store paths to /usr +CFLAGS-.o += `find /gnu/store -maxdepth 1 -mindepth 1 -type d -exec echo -n " -ffile-prefix-map={}=/usr" \;` + libtype.o := lib%.a object-suffixes += .o ifeq (yes,$(build-shared)) diff --git a/contrib/guix/patches/glibc-versioned-locpath.patch b/contrib/guix/patches/glibc-versioned-locpath.patch index bc7652127..01b8ee397 100644 --- a/contrib/guix/patches/glibc-versioned-locpath.patch +++ b/contrib/guix/patches/glibc-versioned-locpath.patch @@ -1,240 +1,240 @@ The format of locale data can be incompatible between libc versions, and loading incompatible data can lead to 'setlocale' returning EINVAL at best or triggering an assertion failure at worst. See https://lists.gnu.org/archive/html/guix-devel/2015-09/msg00717.html for background information. To address that, this patch changes libc to honor a new 'GUIX_LOCPATH' variable, and to look for locale data in version-specific sub-directories of that variable. So, if GUIX_LOCPATH=/foo:/bar, locale data is searched for in /foo/X.Y and /bar/X.Y, where X.Y is the libc version number. That way, a single 'GUIX_LOCPATH' setting can work even if different libc versions coexist on the system. --- a/locale/newlocale.c +++ b/locale/newlocale.c @@ -30,6 +30,7 @@ /* Lock for protecting global data. */ __libc_rwlock_define (extern , __libc_setlocale_lock attribute_hidden) +extern error_t compute_locale_search_path (char **, size_t *); /* Use this when we come along an error. */ #define ERROR_RETURN \ @@ -48,7 +49,6 @@ __newlocale (int category_mask, const char *locale, __locale_t base) __locale_t result_ptr; char *locale_path; size_t locale_path_len; - const char *locpath_var; int cnt; size_t names_len; @@ -102,17 +102,8 @@ __newlocale (int category_mask, const char *locale, __locale_t base) locale_path = NULL; locale_path_len = 0; - locpath_var = getenv ("LOCPATH"); - if (locpath_var != NULL && locpath_var[0] != '\0') - { - if (__argz_create_sep (locpath_var, ':', - &locale_path, &locale_path_len) != 0) - return NULL; - - if (__argz_add_sep (&locale_path, &locale_path_len, - _nl_default_locale_path, ':') != 0) - return NULL; - } + if (compute_locale_search_path (&locale_path, &locale_path_len) != 0) + return NULL; /* Get the names for the locales we are interested in. We either allow a composite name or a single name. */ diff --git a/locale/setlocale.c b/locale/setlocale.c index ead030d..0c0e314 100644 --- a/locale/setlocale.c +++ b/locale/setlocale.c @@ -215,12 +215,65 @@ setdata (int category, struct __locale_data *data) } } +/* Return in *LOCALE_PATH and *LOCALE_PATH_LEN the locale data search path as + a colon-separated list. Return ENOMEN on error, zero otherwise. */ +error_t +compute_locale_search_path (char **locale_path, size_t *locale_path_len) +{ + char* guix_locpath_var = getenv ("GUIX_LOCPATH"); + char *locpath_var = getenv ("LOCPATH"); + + if (guix_locpath_var != NULL && guix_locpath_var[0] != '\0') + { + /* Entries in 'GUIX_LOCPATH' take precedence over 'LOCPATH'. These + entries are systematically prefixed with "/X.Y" where "X.Y" is the + libc version. */ + if (__argz_create_sep (guix_locpath_var, ':', + locale_path, locale_path_len) != 0 + || __argz_suffix_entries (locale_path, locale_path_len, + "/" VERSION) != 0) + goto bail_out; + } + + if (locpath_var != NULL && locpath_var[0] != '\0') + { + char *reg_locale_path = NULL; + size_t reg_locale_path_len = 0; + + if (__argz_create_sep (locpath_var, ':', + ®_locale_path, ®_locale_path_len) != 0) + goto bail_out; + + if (__argz_append (locale_path, locale_path_len, + reg_locale_path, reg_locale_path_len) != 0) + goto bail_out; + + free (reg_locale_path); + } + + if (*locale_path != NULL) + { + /* Append the system default locale directory. */ + if (__argz_add_sep (locale_path, locale_path_len, + _nl_default_locale_path, ':') != 0) + goto bail_out; + } + + return 0; + + bail_out: + free (*locale_path); + *locale_path = NULL; + *locale_path_len = 0; + + return ENOMEM; +} + char * setlocale (int category, const char *locale) { char *locale_path; size_t locale_path_len; - const char *locpath_var; char *composite; /* Sanity check for CATEGORY argument. */ @@ -251,17 +304,10 @@ setlocale (int category, const char *locale) locale_path = NULL; locale_path_len = 0; - locpath_var = getenv ("LOCPATH"); - if (locpath_var != NULL && locpath_var[0] != '\0') + if (compute_locale_search_path (&locale_path, &locale_path_len) != 0) { - if (__argz_create_sep (locpath_var, ':', - &locale_path, &locale_path_len) != 0 - || __argz_add_sep (&locale_path, &locale_path_len, - _nl_default_locale_path, ':') != 0) - { - __libc_rwlock_unlock (__libc_setlocale_lock); - return NULL; - } + __libc_rwlock_unlock (__libc_setlocale_lock); + return NULL; } if (category == LC_ALL) diff --git a/string/Makefile b/string/Makefile -index 8424a61..f925503 100644 +index aa2da9ca72..f273c2611d 100644 --- a/string/Makefile +++ b/string/Makefile -@@ -38,7 +38,7 @@ routines := strcat strchr strcmp strcoll strcpy strcspn \ +@@ -40,7 +40,7 @@ routines := strcat strchr strcmp strcoll strcpy strcspn \ swab strfry memfrob memmem rawmemchr strchrnul \ $(addprefix argz-,append count create ctsep next \ delete extract insert stringify \ - addsep replace) \ + addsep replace suffix) \ envz basename \ strcoll_l strxfrm_l string-inlines memrchr \ xpg-strerror strerror_l diff --git a/string/argz-suffix.c b/string/argz-suffix.c new file mode 100644 index 0000000..505b0f2 --- /dev/null +++ b/string/argz-suffix.c @@ -0,0 +1,56 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ludovic Courtès . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + + +error_t +__argz_suffix_entries (char **argz, size_t *argz_len, const char *suffix) + +{ + size_t suffix_len = strlen (suffix); + size_t count = __argz_count (*argz, *argz_len); + size_t new_argz_len = *argz_len + count * suffix_len; + char *new_argz = malloc (new_argz_len); + + if (new_argz) + { + char *p = new_argz, *entry; + + for (entry = *argz; + entry != NULL; + entry = argz_next (*argz, *argz_len, entry)) + { + p = stpcpy (p, entry); + p = stpcpy (p, suffix); + p++; + } + + free (*argz); + *argz = new_argz; + *argz_len = new_argz_len; + + return 0; + } + else + return ENOMEM; +} +weak_alias (__argz_suffix_entries, argz_suffix_entries) diff --git a/string/argz.h b/string/argz.h -index bb62a31..d276a35 100644 +index 9c496f5ef5..1010a439d8 100644 --- a/string/argz.h +++ b/string/argz.h -@@ -134,6 +134,16 @@ extern error_t argz_replace (char **__restrict __argz, +@@ -108,6 +108,16 @@ extern error_t argz_replace (char **__restrict __argz, const char *__restrict __str, const char *__restrict __with, unsigned int *__restrict __replace_count); + +/* Suffix each entry of ARGZ & ARGZ_LEN with SUFFIX. Return 0 on success, + and ENOMEN if memory cannot be allocated. */ +extern error_t __argz_suffix_entries (char **__restrict __argz, + size_t *__restrict __argz_len, + const char *__restrict __suffix); +extern error_t argz_suffix_entries (char **__restrict __argz, + size_t *__restrict __argz_len, + const char *__restrict __suffix); + /* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there are no more. If entry is NULL, then the first entry is returned. This