diff options
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/glibc')
20 files changed, 1308 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/glibc/0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch b/nixpkgs/pkgs/development/libraries/glibc/0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch new file mode 100644 index 000000000000..b7658b59fb1e --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch @@ -0,0 +1,134 @@ +From cdd0c4b168fe228de97778556cea5c0f936e0e79 Mon Sep 17 00:00:00 2001 +From: Bernardo Meurer <bernardo@meurer.org> +Date: Fri, 22 Jul 2022 22:11:07 -0700 +Subject: [PATCH] Revert "Remove all usage of @BASH@ or ${BASH} in installed + files, and hardcode /bin/bash instead" + +We need the ability to override to use `/bin/sh` here to avoid having +some bootstrap tools in a final build product. + +This reverts commit 5188a9d0265cc6f7235a8af1d31ab02e4a24853d. + +Co-authored-by: Maximilian Bosch <maximilian@mbosch.me> +--- + debug/Makefile | 5 +++-- + debug/xtrace.sh | 2 +- + elf/Makefile | 4 +++- + elf/ldd.bash.in | 2 +- + elf/sotruss.sh | 2 +- + malloc/Makefile | 5 +++-- + malloc/memusage.sh | 2 +- + timezone/Makefile | 3 ++- + 8 files changed, 15 insertions(+), 10 deletions(-) + +diff --git a/debug/Makefile b/debug/Makefile +index 52f9a7852c..22e4ae5461 100644 +--- a/debug/Makefile ++++ b/debug/Makefile +@@ -265,8 +265,9 @@ $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o + + $(objpfx)xtrace: xtrace.sh + rm -f $@.new +- sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \ +- -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \ ++ sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \ ++ -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' \ ++ -e 's|@PKGVERSION@|$(PKGVERSION)|' \ + -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \ + && rm -f $@ && mv $@.new $@ && chmod +x $@ + +diff --git a/debug/xtrace.sh b/debug/xtrace.sh +index 3d1f2af43a..eb2ba7ad4a 100755 +--- a/debug/xtrace.sh ++++ b/debug/xtrace.sh +@@ -1,4 +1,4 @@ +-#!/bin/bash ++#! @BASH@ + # Copyright (C) 1999-2023 Free Software Foundation, Inc. + # This file is part of the GNU C Library. + +diff --git a/elf/Makefile b/elf/Makefile +index 0d19964d42..ee8ee1cd41 100644 +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -250,7 +250,8 @@ $(objpfx)sotruss-lib.so: $(common-objpfx)libc.so $(objpfx)ld.so \ + $(common-objpfx)libc_nonshared.a + + $(objpfx)sotruss: sotruss.sh $(common-objpfx)config.make +- sed -e 's%@VERSION@%$(version)%g' \ ++ sed -e 's%@BASH@%$(BASH)%g' \ ++ -e 's%@VERSION@%$(version)%g' \ + -e 's%@TEXTDOMAINDIR@%$(localedir)%g' \ + -e 's%@PREFIX@%$(prefix)%g' \ + -e 's|@PKGVERSION@|$(PKGVERSION)|g' \ +@@ -1396,6 +1397,7 @@ ldd-rewrite = -e 's%@RTLD@%$(rtlddir)/$(rtld-installed-name)%g' \ + -e 's%@VERSION@%$(version)%g' \ + -e 's|@PKGVERSION@|$(PKGVERSION)|g' \ + -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|g' \ ++ -e 's%@BASH@%$(BASH)%g' \ + -e 's%@TEXTDOMAINDIR@%$(localedir)%g' + + ifeq ($(ldd-rewrite-script),no) +diff --git a/elf/ldd.bash.in b/elf/ldd.bash.in +index e45dec5894..e09428506e 100644 +--- a/elf/ldd.bash.in ++++ b/elf/ldd.bash.in +@@ -1,4 +1,4 @@ +-#!/bin/bash ++#! @BASH@ + # Copyright (C) 1996-2023 Free Software Foundation, Inc. + # This file is part of the GNU C Library. + +diff --git a/elf/sotruss.sh b/elf/sotruss.sh +index 874a6bed3f..7cc154561e 100755 +--- a/elf/sotruss.sh ++++ b/elf/sotruss.sh +@@ -1,4 +1,4 @@ +-#!/bin/bash ++#! @BASH@ + # Copyright (C) 2011-2023 Free Software Foundation, Inc. + # This file is part of the GNU C Library. + +diff --git a/malloc/Makefile b/malloc/Makefile +index dfb51d344c..574b5e9579 100644 +--- a/malloc/Makefile ++++ b/malloc/Makefile +@@ -306,8 +306,9 @@ $(objpfx)mtrace: mtrace.pl + + $(objpfx)memusage: memusage.sh + rm -f $@.new +- sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \ +- -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \ ++ sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \ ++ -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' \ ++ -e 's|@PKGVERSION@|$(PKGVERSION)|' \ + -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \ + && rm -f $@ && mv $@.new $@ && chmod +x $@ + +diff --git a/malloc/memusage.sh b/malloc/memusage.sh +index b1f5848b74..329e36ef8a 100755 +--- a/malloc/memusage.sh ++++ b/malloc/memusage.sh +@@ -1,4 +1,4 @@ +-#!/bin/bash ++#! @BASH@ + # Copyright (C) 1999-2023 Free Software Foundation, Inc. + # This file is part of the GNU C Library. + +diff --git a/timezone/Makefile b/timezone/Makefile +index 0306c0bca9..de9bbcc815 100644 +--- a/timezone/Makefile ++++ b/timezone/Makefile +@@ -132,7 +132,8 @@ $(testdata)/XT5: testdata/gen-XT5.sh + mv $@.tmp $@ + + $(objpfx)tzselect: tzselect.ksh $(common-objpfx)config.make +- sed -e 's|TZDIR=[^}]*|TZDIR=$(zonedir)|' \ ++ sed -e 's|/bin/bash|$(BASH)|' \ ++ -e 's|TZDIR=[^}]*|TZDIR=$(zonedir)|' \ + -e '/TZVERSION=/s|see_Makefile|"$(version)"|' \ + -e '/PKGVERSION=/s|=.*|="$(PKGVERSION)"|' \ + -e '/REPORT_BUGS_TO=/s|=.*|="$(REPORT_BUGS_TO)"|' \ +-- +2.38.4 + diff --git a/nixpkgs/pkgs/development/libraries/glibc/0001-aarch64-math-vector.h-add-NVCC-include-guard.patch b/nixpkgs/pkgs/development/libraries/glibc/0001-aarch64-math-vector.h-add-NVCC-include-guard.patch new file mode 100644 index 000000000000..234bc1943c9a --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/0001-aarch64-math-vector.h-add-NVCC-include-guard.patch @@ -0,0 +1,37 @@ +From 44d0a3a9bd8c6fe59f6ccb44206a50a900bfcf4a Mon Sep 17 00:00:00 2001 +From: Connor Baker <connor.baker@tweag.io> +Date: Tue, 31 Oct 2023 14:30:24 +0000 +Subject: [PATCH] aarch64/math-vector.h: add NVCC include guard + +--- + sysdeps/aarch64/fpu/bits/math-vector.h | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/sysdeps/aarch64/fpu/bits/math-vector.h b/sysdeps/aarch64/fpu/bits/math-vector.h +index 7c200599c1..583a426494 100644 +--- a/sysdeps/aarch64/fpu/bits/math-vector.h ++++ b/sysdeps/aarch64/fpu/bits/math-vector.h +@@ -25,17 +25,17 @@ + /* Get default empty definitions for simd declarations. */ + #include <bits/libm-simd-decl-stubs.h> + +-#if __GNUC_PREREQ(9, 0) ++#if __GNUC_PREREQ(9, 0) && !defined(__CUDACC__) + # define __ADVSIMD_VEC_MATH_SUPPORTED + typedef __Float32x4_t __f32x4_t; + typedef __Float64x2_t __f64x2_t; +-#elif __glibc_clang_prereq(8, 0) ++#elif __glibc_clang_prereq(8, 0) && !defined(__CUDACC__) + # define __ADVSIMD_VEC_MATH_SUPPORTED + typedef __attribute__ ((__neon_vector_type__ (4))) float __f32x4_t; + typedef __attribute__ ((__neon_vector_type__ (2))) double __f64x2_t; + #endif + +-#if __GNUC_PREREQ(10, 0) || __glibc_clang_prereq(11, 0) ++#if (__GNUC_PREREQ(10, 0) || __glibc_clang_prereq(11, 0)) && !defined(__CUDACC__) + # define __SVE_VEC_MATH_SUPPORTED + typedef __SVFloat32_t __sv_f32_t; + typedef __SVFloat64_t __sv_f64_t; +-- +2.42.0 + diff --git a/nixpkgs/pkgs/development/libraries/glibc/2.38-master.patch.gz b/nixpkgs/pkgs/development/libraries/glibc/2.38-master.patch.gz new file mode 100644 index 000000000000..a07e4f8e1d50 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/2.38-master.patch.gz Binary files differdiff --git a/nixpkgs/pkgs/development/libraries/glibc/common.nix b/nixpkgs/pkgs/development/libraries/glibc/common.nix new file mode 100644 index 000000000000..826d1e9c8389 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/common.nix @@ -0,0 +1,299 @@ +/* Build configuration used to build glibc, Info files, and locale + information. + + Note that this derivation has multiple outputs and does not respect the + standard convention of putting the executables into the first output. The + first output is `lib` so that the libraries provided by this derivation + can be accessed directly, e.g. + + "${pkgs.glibc}/lib/ld-linux-x86_64.so.2" + + The executables are put into `bin` output and need to be referenced via + the `bin` attribute of the main package, e.g. + + "${pkgs.glibc.bin}/bin/ldd". + + The executables provided by glibc typically include `ldd`, `locale`, `iconv` + but the exact set depends on the library version and the configuration. +*/ + +# Note: this package is used for bootstrapping fetchurl, and thus +# cannot use fetchpatch! All mutable patches (generated by GitHub or +# cgit) that are needed here should be included directly in Nixpkgs as +# files. + +{ stdenv, lib +, buildPackages +, fetchurl +, linuxHeaders ? null +, gd ? null, libpng ? null +, libidn2 +, bison +, python3Minimal +}: + +{ pname +, withLinuxHeaders ? false +, profilingLibraries ? false +, withGd ? false +, withLibcrypt ? false +, extraBuildInputs ? [] +, extraNativeBuildInputs ? [] +, ... +} @ args: + +let + version = "2.38"; + patchSuffix = "-44"; + sha256 = "sha256-+4KZiZiyspllRnvBtp0VLpwwfSzzAcnq+0VVt3DvP9I="; +in + +assert withLinuxHeaders -> linuxHeaders != null; +assert withGd -> gd != null && libpng != null; + +stdenv.mkDerivation ({ + version = version + patchSuffix; + + enableParallelBuilding = true; + + patches = + [ + /* No tarballs for stable upstream branch, only https://sourceware.org/git/glibc.git and using git would complicate bootstrapping. + $ git fetch --all -p && git checkout origin/release/2.38/master && git describe + glibc-2.38-44-gd37c2b20a4 + $ git show --minimal --reverse glibc-2.38.. | gzip -9n --rsyncable - > 2.38-master.patch.gz + + To compare the archive contents zdiff can be used. + $ zdiff -u 2.38-master.patch.gz ../nixpkgs/pkgs/development/libraries/glibc/2.38-master.patch.gz + */ + ./2.38-master.patch.gz + + /* Allow NixOS and Nix to handle the locale-archive. */ + ./nix-locale-archive.patch + + /* Don't use /etc/ld.so.cache, for non-NixOS systems. */ + ./dont-use-system-ld-so-cache.patch + + /* Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. */ + ./dont-use-system-ld-so-preload.patch + + /* The command "getconf CS_PATH" returns the default search path + "/bin:/usr/bin", which is inappropriate on NixOS machines. This + patch extends the search path by "/run/current-system/sw/bin". */ + ./fix_path_attribute_in_getconf.patch + + ./fix-x64-abi.patch + + /* https://github.com/NixOS/nixpkgs/pull/137601 */ + ./nix-nss-open-files.patch + + ./0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch + + /* Patch derived from archlinux, + https://gitlab.archlinux.org/archlinux/packaging/packages/glibc/-/blob/e54d98e2d1aae4930ecad9404ef12234922d9dfd/reenable_DT_HASH.patch + + See also https://github.com/ValveSoftware/Proton/issues/6051 + & https://github.com/NixOS/nixpkgs/pull/188492#issuecomment-1233802991 + */ + ./reenable_DT_HASH.patch + + /* Retrieved from https://salsa.debian.org/glibc-team/glibc/-/commit/662dbc4f9287139a0d9c91df328a5ba6cc6abee1#0f3c6d67cb8cf5bb35c421c20f828fea97b68edf + Qualys advisory: https://www.qualys.com/2024/01/30/qsort.txt + */ + ./local-qsort-memory-corruption.patch + ] + /* NVCC does not support ARM intrinsics. Since <math.h> is pulled in by almost + every HPC piece of software, without this patch CUDA compilation on ARM + is effectively broken. See + https://forums.developer.nvidia.com/t/nvcc-fails-to-build-with-arm-neon-instructions-cpp-vs-cu/248355/2. + */ + ++ ( + let + isAarch64 = stdenv.buildPlatform.isAarch64 || stdenv.hostPlatform.isAarch64; + isLinux = stdenv.buildPlatform.isLinux || stdenv.hostPlatform.isLinux; + in + lib.optional (isAarch64 && isLinux) ./0001-aarch64-math-vector.h-add-NVCC-include-guard.patch + ) + ++ lib.optional stdenv.hostPlatform.isMusl ./fix-rpc-types-musl-conflicts.patch + ++ lib.optional stdenv.buildPlatform.isDarwin ./darwin-cross-build.patch; + + postPatch = + '' + # Needed for glibc to build with the gnumake 3.82 + # http://comments.gmane.org/gmane.linux.lfs.support/31227 + sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile + + # nscd needs libgcc, and we don't want it dynamically linked + # because we don't want it to depend on bootstrap-tools libs. + echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile + + # Ensure that `__nss_files_fopen` can still be wrapped by `libredirect`. + sed -i -e '/libc_hidden_def (__nss_files_fopen)/d' nss/nss_files_fopen.c + sed -i -e '/libc_hidden_proto (__nss_files_fopen)/d' include/nss_files.h + '' + # FIXME: find a solution for infinite recursion in cross builds. + # For now it's hopefully acceptable that IDN from libc doesn't reliably work. + + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) '' + + # Ensure that libidn2 is found. + patch -p 1 <<EOF + --- a/inet/idna.c + +++ b/inet/idna.c + @@ -25,1 +25,1 @@ + -#define LIBIDN2_SONAME "libidn2.so.0" + +#define LIBIDN2_SONAME "${lib.getLib libidn2}/lib/libidn2.so.0" + EOF + ''; + + configureFlags = + [ "-C" + "--enable-add-ons" + "--sysconfdir=/etc" + "--enable-stack-protector=strong" + "--enable-bind-now" + (lib.withFeatureAs withLinuxHeaders "headers" "${linuxHeaders}/include") + (lib.enableFeature profilingLibraries "profile") + "--enable-fortify-source" + ] ++ lib.optionals (stdenv.hostPlatform.isx86 || stdenv.hostPlatform.isAarch64) [ + # This feature is currently supported on + # i386, x86_64 and x32 with binutils 2.29 or later, + # and on aarch64 with binutils 2.30 or later. + # https://sourceware.org/glibc/wiki/PortStatus + "--enable-static-pie" + ] ++ lib.optionals stdenv.hostPlatform.isx86_64 [ + # Enable Intel Control-flow Enforcement Technology (CET) support + "--enable-cet" + ] ++ lib.optionals withLinuxHeaders [ + "--enable-kernel=3.10.0" # RHEL 7 and derivatives, seems oldest still supported kernel + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + (lib.flip lib.withFeature "fp" + (stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft")) + "--with-__thread" + ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform && stdenv.hostPlatform.isAarch32) [ + "--host=arm-linux-gnueabi" + "--build=arm-linux-gnueabi" + + # To avoid linking with -lgcc_s (dynamic link) + # so the glibc does not depend on its compiler store path + "libc_cv_as_needed=no" + ] + ++ lib.optional withGd "--with-gd" + ++ lib.optional withLibcrypt "--enable-crypt"; + + makeFlags = (args.makeFlags or []) ++ [ + "OBJCOPY=${stdenv.cc.targetPrefix}objcopy" + ]; + + postInstall = (args.postInstall or "") + '' + moveToOutput bin/getent $getent + ''; + + installFlags = [ "sysconfdir=$(out)/etc" ]; + + # out as the first output is an exception exclusive to glibc + + # getent is its own output, not kept in bin, since many things + # depend on getent but not on the locale generation tools in the bin + # output. This saves a couple of megabytes of closure size in many cases. + outputs = [ "out" "bin" "dev" "static" "getent" ]; + + strictDeps = true; + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ bison python3Minimal ] ++ extraNativeBuildInputs; + buildInputs = [ linuxHeaders ] ++ lib.optionals withGd [ gd libpng ] ++ extraBuildInputs; + + env = { + linuxHeaders = lib.optionalString withLinuxHeaders linuxHeaders; + inherit (stdenv) is64bit; + # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to + # prevent a retained dependency on the bootstrap tools in the stdenv-linux + # bootstrap. + BASH_SHELL = "/bin/sh"; + }; + + # Used by libgcc, elf-header, and others to determine ABI + passthru = { inherit version; minorRelease = version; }; +} + +// (removeAttrs args [ "withLinuxHeaders" "withGd" "postInstall" "makeFlags" ]) // + +{ + src = fetchurl { + url = "mirror://gnu/glibc/glibc-${version}.tar.xz"; + inherit sha256; + }; + + # Remove absolute paths from `configure' & co.; build out-of-tree. + preConfigure = '' + export PWD_P=$(type -tP pwd) + for i in configure io/ftwtest-sh; do + # Can't use substituteInPlace here because replace hasn't been + # built yet in the bootstrap. + sed -i "$i" -e "s^/bin/pwd^$PWD_P^g" + done + + mkdir ../build + cd ../build + + configureScript="`pwd`/../$sourceRoot/configure" + + ${lib.optionalString (stdenv.cc.libc != null) + ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib OBJDUMP=${stdenv.cc.bintools.bintools}/bin/objdump"'' + } + + + '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' + sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig" + + cat > config.cache << "EOF" + libc_cv_forced_unwind=yes + libc_cv_c_cleanup=yes + libc_cv_gnu89_inline=yes + EOF + + # ./configure has logic like + # + # AR=`$CC -print-prog-name=ar` + # + # This searches various directories in the gcc and its wrapper. In nixpkgs, + # this returns the bare string "ar", which is build ar. This can result as + # a build failure with the following message: + # + # libc_pic.a: error adding symbols: archive has no index; run ranlib to add one + # + # (Observed cross compiling from aarch64-linux -> armv7l-linux). + # + # Nixpkgs passes a correct value for AR and friends, so to use the correct + # set of tools, we only need to delete this special handling. + sed -i \ + -e '/^AR=/d' \ + -e '/^AS=/d' \ + -e '/^LD=/d' \ + -e '/^OBJCOPY=/d' \ + -e '/^OBJDUMP=/d' \ + $configureScript + ''; + + preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH"; + + doCheck = false; # fails + + meta = with lib; { + homepage = "https://www.gnu.org/software/libc/"; + description = "The GNU C Library"; + + longDescription = + '' Any Unix-like operating system needs a C library: the library which + defines the "system calls" and other basic facilities such as + open, malloc, printf, exit... + + The GNU C library is used as the C library in the GNU system and + most systems with the Linux kernel. + ''; + + license = licenses.lgpl2Plus; + + maintainers = with maintainers; [ eelco ma27 connorbaker ]; + platforms = platforms.linux; + } // (args.meta or {}); +}) diff --git a/nixpkgs/pkgs/development/libraries/glibc/darwin-cross-build.patch b/nixpkgs/pkgs/development/libraries/glibc/darwin-cross-build.patch new file mode 100644 index 000000000000..b746e6369a07 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/darwin-cross-build.patch @@ -0,0 +1,77 @@ +enable cross-compilation of glibc on Darwin (build=Darwin, host=Linux) +* increase ulimit for open files: macOS default of 256 is too low for glibc build system +* use host version of ar, which is given by environment variable +* build system uses stamp.os and stamp.oS files, which only differ in case; + this fails on macOS, so replace .oS with .o_S +--- glibc-2.32/Makefile.in 2018-02-01 17:17:18.000000000 +0100 ++++ glibc-2.32/Makefile.in 2020-12-27 18:21:30.000000000 +0100 +@@ -6,9 +6,11 @@ + .PHONY: all install bench + + all .DEFAULT: +- $(MAKE) -r PARALLELMFLAGS="$(PARALLELMFLAGS)" -C $(srcdir) objdir=`pwd` $@ ++ ulimit -n 1024; \ ++ $(MAKE) -r AR=$$AR PARALLELMFLAGS="$(PARALLELMFLAGS)" -C $(srcdir) objdir=`pwd` $@ + + install: ++ ulimit -n 1024; \ + LC_ALL=C; export LC_ALL; \ + $(MAKE) -r PARALLELMFLAGS="$(PARALLELMFLAGS)" -C $(srcdir) objdir=`pwd` $@ + +--- glibc-2.32/Makerules 2018-02-01 17:17:18.000000000 +0100 ++++ glibc-2.32/Makerules 2020-12-27 18:21:30.000000000 +0100 +@@ -847,8 +847,8 @@ + ifndef objects + + # Create the stamp$o files to keep the parent makefile happy. +-subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o) +-$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o): ++subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$(subst .oS,.o_S,$o)) ++$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$(subst .oS,.o_S,$o)): + $(make-target-directory) + rm -f $@; > $@ + else +@@ -859,7 +859,7 @@ + # The parent will then actually add them all to the archive in the + # archive rule, below. + define o-iterator-doit +-$(objpfx)stamp$o: $(o-objects); $$(do-stamp) ++$(objpfx)stamp$(subst .oS,.o_S,$o): $(o-objects); $$(do-stamp) + endef + define do-stamp + $(make-target-directory) +@@ -875,14 +875,14 @@ + # on the stamp files built above. + define o-iterator-doit + $(common-objpfx)$(patsubst %,$(libtype$o),c): \ +- $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib) ++ $(subdirs-stamp-o) $(common-objpfx)stamp$(subst .oS,.o_S,$o); $$(do-makelib) + endef + define do-makelib + cd $(common-objdir) && \ + $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)` + endef + subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%) +-subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps)) ++subdirs-stamp-o = $(subst %,$(subst .oS,.o_S,$o),$(subdirs-stamps)) + ifndef subdir + $(subdirs-stamps): subdir_lib; + endif +@@ -893,7 +893,7 @@ + # This makes all the object files. + .PHONY: objects objs libobjs extra-objs + objects objs: libobjs extra-objs +-libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o) ++libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$(subst .oS,.o_S,$o)) + extra-objs: $(addprefix $(objpfx),$(extra-objs)) + + # Canned sequence for building an extra library archive. +@@ -1499,7 +1499,7 @@ + $(rmobjs) + define rmobjs + $(foreach o,$(object-suffixes-for-libc), +--rm -f $(objpfx)stamp$o $(o-objects)) ++-rm -f $(objpfx)stamp$(subst .oS,.o_S,$o) $(o-objects)) + endef + + # Also remove the dependencies and generated source files. diff --git a/nixpkgs/pkgs/development/libraries/glibc/default.nix b/nixpkgs/pkgs/development/libraries/glibc/default.nix new file mode 100644 index 000000000000..be3bee081e73 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/default.nix @@ -0,0 +1,187 @@ +{ lib, stdenv, callPackage +, withLinuxHeaders ? true +, profilingLibraries ? false +, withGd ? false +, withLibcrypt? false +, pkgsBuildBuild +, libgcc +}: + +let + gdCflags = [ + "-Wno-error=stringop-truncation" + "-Wno-error=missing-attributes" + "-Wno-error=array-bounds" + ]; +in + +(callPackage ./common.nix { inherit stdenv; } { + inherit withLinuxHeaders withGd profilingLibraries withLibcrypt; + pname = "glibc" + lib.optionalString withGd "-gd" + lib.optionalString (stdenv.cc.isGNU && libgcc==null) "-nolibgcc"; +}).overrideAttrs(previousAttrs: { + + # Note: + # Things you write here override, and do not add to, + # the values in `common.nix`. + # (For example, if you define `patches = [...]` here, it will + # override the patches in `common.nix` -- so instead you should + # write `patches = (previousAttrs.patches or []) ++ [ ... ]`. + + NIX_NO_SELF_RPATH = true; + + postConfigure = '' + # Hack: get rid of the `-static' flag set by the bootstrap stdenv. + # This has to be done *after* `configure' because it builds some + # test binaries. + export NIX_CFLAGS_LINK= + export NIX_LDFLAGS_BEFORE= + + export NIX_DONT_SET_RPATH=1 + unset CFLAGS + + # Apparently --bindir is not respected. + makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin") + '' + lib.optionalString stdenv.buildPlatform.isDarwin '' + # ld-wrapper will otherwise attempt to inject CoreFoundation into ld-linux's RUNPATH + export NIX_COREFOUNDATION_RPATH= + ''; + + # The pie, stackprotector and fortify hardening flags are autodetected by + # glibc and enabled by default if supported. Setting it for every gcc + # invocation does not work. + hardeningDisable = [ "fortify" "pie" "stackprotector" ]; + + env = (previousAttrs.env or { }) // { + NIX_CFLAGS_COMPILE = (previousAttrs.env.NIX_CFLAGS_COMPILE or "") + lib.concatStringsSep " " + (builtins.concatLists [ + (lib.optionals withGd gdCflags) + # Fix -Werror build failure when building glibc with musl with GCC >= 8, see: + # https://github.com/NixOS/nixpkgs/pull/68244#issuecomment-544307798 + (lib.optional stdenv.hostPlatform.isMusl "-Wno-error=attribute-alias") + (lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) || stdenv.hostPlatform.isMusl) [ + # Ignore "error: '__EI___errno_location' specifies less restrictive attributes than its target '__errno_location'" + # New warning as of GCC 9 + # Same for musl: https://github.com/NixOS/nixpkgs/issues/78805 + "-Wno-error=missing-attributes" + ]) + (lib.optionals (stdenv.hostPlatform.isPower64) [ + # Do not complain about the Processor Specific ABI (i.e. the + # choice to use IEEE-standard `long double`). We pass this + # flag in order to mute a `-Werror=psabi` passed by glibc; + # hopefully future glibc releases will not pass that flag. + "-Wno-error=psabi" + ]) + ]); + }; + + # glibc needs to `dlopen()` `libgcc_s.so` but does not link + # against it. Furthermore, glibc doesn't use the ordinary + # `dlopen()` call to do this; instead it uses one which ignores + # most paths: + # + # https://sourceware.org/legacy-ml/libc-help/2013-11/msg00026.html + # + # In order to get it to not ignore `libgcc_s.so`, we have to add its path to + # `user-defined-trusted-dirs`: + # + # https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/Makefile;h=b509b3eada1fb77bf81e2a0ca5740b94ad185764#l1355 + # + # Conveniently, this will also inform Nix of the fact that glibc depends on + # gcc.libgcc, since the path will be embedded in the resulting binary. + # + makeFlags = + (previousAttrs.makeFlags or []) + ++ lib.optionals (libgcc != null) [ + "user-defined-trusted-dirs=${libgcc}/lib" + ]; + + postInstall = previousAttrs.postInstall + (if stdenv.buildPlatform.canExecute stdenv.hostPlatform then '' + echo SUPPORTED-LOCALES=C.UTF-8/UTF-8 > ../glibc-2*/localedata/SUPPORTED + make -j''${NIX_BUILD_CORES:-1} localedata/install-locales + '' else lib.optionalString stdenv.buildPlatform.isLinux + # This is based on http://www.linuxfromscratch.org/lfs/view/development/chapter06/glibc.html + # Instead of using their patch to build a build-native localedef, + # we simply use the one from pkgsBuildBuild. + # + # Note that we can't use pkgsBuildHost (aka buildPackages) here, because + # that will cause an eval-time infinite recursion: "buildPackages.glibc + # depended on buildPackages.libgcc, which, since it's GCC, depends on the + # target's bintools, which depend on the target's glibc, which, again, + # depends on buildPackages.glibc, causing an infinute recursion when + # evaluating buildPackages.glibc when glibc hasn't come from stdenv + # (e.g. on musl)." https://github.com/NixOS/nixpkgs/pull/259964 + '' + pushd ../glibc-2*/localedata + export I18NPATH=$PWD GCONV_PATH=$PWD/../iconvdata + mkdir -p $NIX_BUILD_TOP/${pkgsBuildBuild.glibc}/lib/locale + ${lib.getBin pkgsBuildBuild.glibc}/bin/localedef \ + --alias-file=../intl/locale.alias \ + -i locales/C \ + -f charmaps/UTF-8 \ + --prefix $NIX_BUILD_TOP \ + ${if stdenv.hostPlatform.parsed.cpu.significantByte.name == "littleEndian" then + "--little-endian" + else + "--big-endian"} \ + C.UTF-8 + cp -r $NIX_BUILD_TOP/${pkgsBuildBuild.glibc}/lib/locale $out/lib + popd + '') + '' + + test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache + + if test -n "$linuxHeaders"; then + # Include the Linux kernel headers in Glibc, except the `scsi' + # subdirectory, which Glibc provides itself. + (cd $dev/include && \ + ln -sv $(ls -d $linuxHeaders/include/* | grep -v scsi\$) .) + fi + + # Fix for NIXOS-54 (ldd not working on x86_64). Make a symlink + # "lib64" to "lib". + if test -n "$is64bit"; then + ln -s lib $out/lib64 + fi + + # Get rid of more unnecessary stuff. + rm -rf $out/var $bin/bin/sln + + # Backwards-compatibility to fix e.g. + # "configure: error: Pthreads are required to build libgomp" during `gcc`-build + # because it's not actually needed anymore to link against `pthreads` since + # it's now part of `libc.so.6` itself, but the gcc build breaks if + # this doesn't work. + ln -sf $out/lib/libpthread.so.0 $out/lib/libpthread.so + ln -sf $out/lib/librt.so.1 $out/lib/librt.so + ln -sf $out/lib/libdl.so.2 $out/lib/libdl.so + test -f $out/lib/libutil.so.1 && ln -sf $out/lib/libutil.so.1 $out/lib/libutil.so + touch $out/lib/libpthread.a + + # Put libraries for static linking in a separate output. Note + # that libc_nonshared.a and libpthread_nonshared.a are required + # for dynamically-linked applications. + mkdir -p $static/lib + mv $out/lib/*.a $static/lib + mv $static/lib/lib*_nonshared.a $out/lib + # If libutil.so.1 is missing, libutil.a is required. + test -f $out/lib/libutil.so.1 || mv $static/lib/libutil.a $out/lib + # Some of *.a files are linker scripts where moving broke the paths. + sed "/^GROUP/s|$out/lib/lib|$static/lib/lib|g" \ + -i "$static"/lib/*.a + + # Work around a Nix bug: hard links across outputs cause a build failure. + cp $bin/bin/getconf $bin/bin/getconf_ + mv $bin/bin/getconf_ $bin/bin/getconf + ''; + + separateDebugInfo = true; + + passthru = + (previousAttrs.passthru or {}) + // lib.optionalAttrs (libgcc != null) { + inherit libgcc; + }; + + meta = (previousAttrs.meta or {}) // { description = "The GNU C Library"; }; +}) + diff --git a/nixpkgs/pkgs/development/libraries/glibc/dont-use-system-ld-so-cache.patch b/nixpkgs/pkgs/development/libraries/glibc/dont-use-system-ld-so-cache.patch new file mode 100644 index 000000000000..0e0315aca270 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/dont-use-system-ld-so-cache.patch @@ -0,0 +1,64 @@ +diff --git a/elf/Makefile b/elf/Makefile +index 5d666b1b..a5017e9c 100644 +--- a/elf/Makefile ++++ b/elf/Makefile +@@ -669,14 +669,14 @@ $(objpfx)sln: $(sln-modules:%=$(objpfx)%.o) + + $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o) + +-SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"' +-CFLAGS-ldconfig.c += $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' \ ++PREFIX-FLAGS := -D'PREFIX="$(prefix)"' ++CFLAGS-ldconfig.c += $(PREFIX-FLAGS) -D'LIBDIR="$(libdir)"' \ + -D'SLIBDIR="$(slibdir)"' + libof-ldconfig = ldconfig +-CFLAGS-dl-cache.c += $(SYSCONF-FLAGS) +-CFLAGS-cache.c += $(SYSCONF-FLAGS) +-CFLAGS-rtld.c += $(SYSCONF-FLAGS) +-CFLAGS-dl-usage.c += $(SYSCONF-FLAGS) \ ++CFLAGS-dl-cache.c += $(PREFIX-FLAGS) ++CFLAGS-cache.c += $(PREFIX-FLAGS) ++CFLAGS-rtld.c += $(PREFIX-FLAGS) ++CFLAGS-dl-usage.c += $(PREFIX-FLAGS) \ + -D'RTLD="$(rtlddir)/$(rtld-installed-name)"' + + cpp-srcs-left := $(all-rtld-routines:=.os) +diff --git a/elf/dl-diagnostics.c b/elf/dl-diagnostics.c +index bef224b3..8e166b12 100644 +--- a/elf/dl-diagnostics.c ++++ b/elf/dl-diagnostics.c +@@ -205,7 +205,7 @@ print_paths (void) + { + _dl_diagnostics_print_labeled_string ("path.prefix", PREFIX); + _dl_diagnostics_print_labeled_string ("path.rtld", RTLD); +- _dl_diagnostics_print_labeled_string ("path.sysconfdir", SYSCONFDIR); ++ _dl_diagnostics_print_labeled_string ("path.sysconfdir", PREFIX "/etc"); + + unsigned int index = 0; + static const char *system_dirs = SYSTEM_DIRS "\0"; +diff --git a/elf/ldconfig.c b/elf/ldconfig.c +index 28ed637a..6f07b79a 100644 +--- a/elf/ldconfig.c ++++ b/elf/ldconfig.c +@@ -57,7 +57,7 @@ + #define TLS_HWCAP_BIT 63 + + #ifndef LD_SO_CONF +-# define LD_SO_CONF SYSCONFDIR "/ld.so.conf" ++# define LD_SO_CONF PREFIX "/etc/ld.so.conf" + #endif + + /* Get libc version number. */ +diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h +index 964d50a4..2224d651 100644 +--- a/sysdeps/generic/dl-cache.h ++++ b/sysdeps/generic/dl-cache.h +@@ -35,7 +35,7 @@ + #endif + + #ifndef LD_SO_CACHE +-# define LD_SO_CACHE SYSCONFDIR "/ld.so.cache" ++# define LD_SO_CACHE PREFIX "/etc/ld.so.cache" + #endif + + #ifndef add_system_dir diff --git a/nixpkgs/pkgs/development/libraries/glibc/dont-use-system-ld-so-preload.patch b/nixpkgs/pkgs/development/libraries/glibc/dont-use-system-ld-so-preload.patch new file mode 100644 index 000000000000..894e2a11cf87 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/dont-use-system-ld-so-preload.patch @@ -0,0 +1,12 @@ +diff -ru glibc-2.20-orig/elf/rtld.c glibc-2.20/elf/rtld.c +--- glibc-2.20-orig/elf/rtld.c 2014-09-07 10:09:09.000000000 +0200 ++++ glibc-2.20/elf/rtld.c 2014-10-27 11:32:25.203043157 +0100 +@@ -1513,7 +1513,7 @@ + open(). So we do this first. If it succeeds we do almost twice + the work but this does not matter, since it is not for production + use. */ +- static const char preload_file[] = "/etc/ld.so.preload"; ++ static const char preload_file[] = "/etc/ld-nix.so.preload"; + if (__glibc_unlikely (__access (preload_file, R_OK) == 0)) + { + /* Read the contents of the file. */ diff --git a/nixpkgs/pkgs/development/libraries/glibc/fix-rpc-types-musl-conflicts.patch b/nixpkgs/pkgs/development/libraries/glibc/fix-rpc-types-musl-conflicts.patch new file mode 100644 index 000000000000..19f8bfc7cce8 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/fix-rpc-types-musl-conflicts.patch @@ -0,0 +1,38 @@ +@@ -, +, @@ +--- + sunrpc/rpc/types.h | 22 ++++++---------------- + 1 file changed, 6 insertions(+), 16 deletions(-) +--- a/sunrpc/rpc/types.h ++++ a/sunrpc/rpc/types.h +@@ -69,24 +69,14 @@ typedef unsigned long rpcport_t; + #include <sys/types.h> + #endif + +-#if defined __APPLE_CC__ || defined __FreeBSD__ +-# define __u_char_defined +-# define __daddr_t_defined +-#endif +- +-#ifndef __u_char_defined +-typedef __u_char u_char; +-typedef __u_short u_short; +-typedef __u_int u_int; +-typedef __u_long u_long; +-typedef __quad_t quad_t; +-typedef __u_quad_t u_quad_t; +-typedef __fsid_t fsid_t; ++/* IMPORTANT NOTE: This has been modified to build against the musl C ++ * library and it probably now ONLY builds with the musl C library. ++ * ++ * See: https://sourceware.org/bugzilla/show_bug.cgi?id=21604 ++ */ + # define __u_char_defined +-#endif + #ifndef __daddr_t_defined +-typedef __daddr_t daddr_t; +-typedef __caddr_t caddr_t; ++typedef int daddr_t; + # define __daddr_t_defined + #endif + +-- diff --git a/nixpkgs/pkgs/development/libraries/glibc/fix-x64-abi.patch b/nixpkgs/pkgs/development/libraries/glibc/fix-x64-abi.patch new file mode 100644 index 000000000000..1d60dcd7988b --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/fix-x64-abi.patch @@ -0,0 +1,35 @@ +From 3288c6da64add3b4561b8c10fff522027caea01c Mon Sep 17 00:00:00 2001 +From: Nicholas Miell <nmiell@gmail.com> +Date: Sat, 17 Jun 2017 18:21:07 -0700 +Subject: [PATCH] Align the stack on entry to __tls_get_addr() + +Old versions of gcc (4 & 5) didn't align the stack according to the +AMD64 psABI when calling __tls_get_addr(). Apparently new versions of +gcc (7) got much more aggressive about vectorizing and generating MOVAPS +instructions, which means old binaries built with the buggy versions of +gcc are much more likely to crash when using versions of glibc built +using gcc 7. + +For example, a large number of Linux games built using the Unity game +engine and available for purchase on Steam. +--- + elf/dl-tls.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/elf/dl-tls.c b/elf/dl-tls.c +index 5aba33b3fa..3f3cb917de 100644 +--- a/elf/dl-tls.c ++++ b/elf/dl-tls.c +@@ -827,6 +827,10 @@ rtld_hidden_proto (__tls_get_addr) + rtld_hidden_def (__tls_get_addr) + #endif + ++#ifdef __x86_64__ ++/* Old versions of gcc didn't align the stack. */ ++__attribute__((force_align_arg_pointer)) ++#endif + /* The generic dynamic and local dynamic model cannot be used in + statically linked applications. */ + void * +-- +2.13.0 diff --git a/nixpkgs/pkgs/development/libraries/glibc/fix_path_attribute_in_getconf.patch b/nixpkgs/pkgs/development/libraries/glibc/fix_path_attribute_in_getconf.patch new file mode 100644 index 000000000000..714e49db5607 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/fix_path_attribute_in_getconf.patch @@ -0,0 +1,6 @@ +diff -ubr glibc-2.17-orig/sysdeps/unix/confstr.h glibc-2.17/sysdeps/unix/confstr.h +--- glibc-2.17-orig/sysdeps/unix/confstr.h 2013-06-03 22:01:44.829726968 +0200 ++++ glibc-2.17/sysdeps/unix/confstr.h 2013-06-03 22:04:39.469376740 +0200 +@@ -1 +1 @@ +-#define CS_PATH "/bin:/usr/bin" ++#define CS_PATH "/run/current-system/sw/bin:/bin:/usr/bin" diff --git a/nixpkgs/pkgs/development/libraries/glibc/info.nix b/nixpkgs/pkgs/development/libraries/glibc/info.nix new file mode 100644 index 000000000000..d643d8a6ba09 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/info.nix @@ -0,0 +1,23 @@ +{ callPackage, texinfo, perl }: + +callPackage ./common.nix {} { + pname = "glibc-info"; + + outputs = [ "out" ]; + + configureFlags = [ "--enable-add-ons" ]; + + extraNativeBuildInputs = [ texinfo perl ]; + + makeFlags = [ "info" ]; + + # I don't know why the info is not generated in 'build' + # Somehow building the info still does not work, because the final + # libc.info hasn't a Top node. + installPhase = '' + mkdir -p "$out/share/info" + cp -v "manual/"*.info* "$out/share/info" + ''; + + meta.description = "GNU Info manual of the GNU C Library"; +} diff --git a/nixpkgs/pkgs/development/libraries/glibc/local-qsort-memory-corruption.patch b/nixpkgs/pkgs/development/libraries/glibc/local-qsort-memory-corruption.patch new file mode 100644 index 000000000000..f7e25c72a61c --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/local-qsort-memory-corruption.patch @@ -0,0 +1,14 @@ +diff -rup a/stdlib/qsort.c b/stdlib/qsort.c +--- a/stdlib/qsort.c 2023-07-31 10:54:16.000000000 -0700 ++++ b/stdlib/qsort.c 2024-01-15 09:08:25.596167959 -0800 +@@ -224,7 +224,8 @@ _quicksort (void *const pbase, size_t to + while ((run_ptr += size) <= end_ptr) + { + tmp_ptr = run_ptr - size; +- while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) ++ while (tmp_ptr != base_ptr ++ && (*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) + tmp_ptr -= size; + + tmp_ptr += size; + diff --git a/nixpkgs/pkgs/development/libraries/glibc/locales-builder.sh b/nixpkgs/pkgs/development/libraries/glibc/locales-builder.sh new file mode 100644 index 000000000000..27894b09b91c --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/locales-builder.sh @@ -0,0 +1,18 @@ +if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi +# Glibc cannot have itself in its RPATH. +export NIX_NO_SELF_RPATH=1 + +source $stdenv/setup + +postConfigure() { + # Hack: get rid of the `-static' flag set by the bootstrap stdenv. + # This has to be done *after* `configure' because it builds some + # test binaries. + export NIX_CFLAGS_LINK= + export NIX_LDFLAGS_BEFORE= + + export NIX_DONT_SET_RPATH=1 + unset CFLAGS +} + +genericBuild diff --git a/nixpkgs/pkgs/development/libraries/glibc/locales.nix b/nixpkgs/pkgs/development/libraries/glibc/locales.nix new file mode 100644 index 000000000000..eddeb5e3ec4b --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/locales.nix @@ -0,0 +1,86 @@ +/* This function builds just the `lib/locale/locale-archive' file from + Glibc and nothing else. If `allLocales' is true, all supported + locales are included; otherwise, just the locales listed in + `locales'. See localedata/SUPPORTED in the Glibc source tree for + the list of all supported locales: + https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED +*/ + +{ lib, stdenv, buildPackages, callPackage, writeText, glibc +, allLocales ? true, locales ? [ "en_US.UTF-8/UTF-8" ] +}: + +(callPackage ./common.nix { inherit stdenv; } { + pname = "glibc-locales"; + extraNativeBuildInputs = [ glibc ]; +}).overrideAttrs(finalAttrs: previousAttrs: { + + builder = ./locales-builder.sh; + + outputs = [ "out" ]; + + LOCALEDEF_FLAGS = [ + (if stdenv.hostPlatform.isLittleEndian + then "--little-endian" + else "--big-endian") + ]; + + preBuild = (previousAttrs.preBuild or "") + '' + # Awful hack: `localedef' doesn't allow the path to `locale-archive' + # to be overriden, but you *can* specify a prefix, i.e. it will use + # <prefix>/<path-to-glibc>/lib/locale/locale-archive. So we use + # $TMPDIR as a prefix, meaning that the locale-archive is placed in + # $TMPDIR/nix/store/...-glibc-.../lib/locale/locale-archive. + LOCALEDEF_FLAGS+=" --prefix=$TMPDIR" + + mkdir -p $TMPDIR/"${buildPackages.glibc.out}/lib/locale" + + echo 'C.UTF-8/UTF-8 \' >> ../glibc-2*/localedata/SUPPORTED + + # Hack to allow building of the locales (needed since glibc-2.12) + sed -i -e 's,^$(rtld-prefix) $(common-objpfx)locale/localedef,localedef $(LOCALEDEF_FLAGS),' ../glibc-2*/localedata/Makefile + '' + + lib.optionalString (!allLocales) '' + # Check that all locales to be built are supported + echo -n '${lib.concatMapStrings (s: s + " \\\n") locales}' \ + | sort -u > locales-to-build.txt + cat ../glibc-2*/localedata/SUPPORTED | grep ' \\' \ + | sort -u > locales-supported.txt + comm -13 locales-supported.txt locales-to-build.txt \ + > locales-unsupported.txt + if [[ $(wc -c locales-unsupported.txt) != "0 locales-unsupported.txt" ]]; then + cat locales-supported.txt + echo "Error: unsupported locales detected:" + cat locales-unsupported.txt + echo "You should choose from the list above the error." + false + fi + + echo SUPPORTED-LOCALES='${toString locales}' > ../glibc-2*/localedata/SUPPORTED + ''; + + # Current `nixpkgs` way of building locales is not compatible with + # parallel install. `locale-archive` is updated in parallel with + # multiple `localedef` processes and causes non-deterministic result: + # https://github.com/NixOS/nixpkgs/issues/245360 + enableParallelBuilding = false; + + makeFlags = (previousAttrs.makeFlags or []) ++ [ + "localedata/install-locales" + "localedir=${builtins.placeholder "out"}/lib/locale" + ]; + + installPhase = + '' + mkdir -p "$out/lib/locale" "$out/share/i18n" + cp -v "$TMPDIR/$NIX_STORE/"*"/lib/locale/locale-archive" "$out/lib/locale" + cp -v ../glibc-2*/localedata/SUPPORTED "$out/share/i18n/SUPPORTED" + ''; + + setupHook = writeText "locales-setup-hook.sh" + '' + export LOCALE_ARCHIVE=@out@/lib/locale/locale-archive + ''; + + meta.description = "Locale information for the GNU C Library"; +}) diff --git a/nixpkgs/pkgs/development/libraries/glibc/mtrace.nix b/nixpkgs/pkgs/development/libraries/glibc/mtrace.nix new file mode 100644 index 000000000000..4dbcb19af2a4 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/mtrace.nix @@ -0,0 +1,40 @@ +{ glibc, perl }: + +# Small wrapper which only exposes `mtrace(3)` from `glibc`. This can't be placed +# into `glibc` itself because it depends on Perl which would mean that the final +# `glibc` inside a stdenv bootstrap has a dependency `glibc -> perl -> bootstrap tools`, +# so this is now in its own package that isn't used for bootstrapping. +# +# `glibc` needs to be overridden here because it's still needed to `./configure` the source in order +# to have a build environment where we can call the needed make target. + +glibc.overrideAttrs (oldAttrs: { + pname = "glibc-mtrace"; + + buildPhase = '' + runHook preBuild + + mkdir malloc + make -C ../glibc-${glibc.minorRelease}/malloc objdir=`pwd` `pwd`/malloc/mtrace; + + runHook postBuild + ''; + + installPhase = '' + mkdir -p $out/bin + mv malloc/mtrace $out/bin/ + ''; + + # Perl checked during configure + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ perl ]; + # Perl shebang used for `mtrace`. + buildInputs = oldAttrs.buildInputs ++ [ perl ]; + + # Reset a few things declared by `pkgs.glibc`. + outputs = [ "out" ]; + separateDebugInfo = false; + + meta = oldAttrs.meta // { + description = "Perl script used to interpret and provide human readable output of the trace log contained in the file mtracedata, whose contents were produced by mtrace(3)."; + }; +}) diff --git a/nixpkgs/pkgs/development/libraries/glibc/multi.nix b/nixpkgs/pkgs/development/libraries/glibc/multi.nix new file mode 100644 index 000000000000..5cd48958ec2c --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/multi.nix @@ -0,0 +1,38 @@ +{ lib +, runCommand, glibc, glibc32 +}: + +let + nameVersion = builtins.parseDrvName glibc.name; + glibc64 = glibc; +in +runCommand "${nameVersion.name}-multi-${nameVersion.version}" + # out as the first output is an exception exclusive to glibc + { + outputs = [ "out" "bin" "dev" ]; # TODO: no static version here (yet) + passthru = { + libgcc = lib.lists.filter (x: x!=null) [ + (glibc64.libgcc or null) + (glibc32.libgcc or null) + ]; + }; + } + '' + mkdir -p "$out/lib" + ln -s '${glibc64.out}'/lib/* "$out/lib" + ln -s '${glibc32.out}/lib' "$out/lib/32" + ln -s lib "$out/lib64" + + # fixing ldd RLTDLIST + mkdir -p "$bin/bin" + cp -s '${glibc64.bin}'/bin/* "$bin/bin/" + rm "$bin/bin/ldd" + sed -e "s|^RTLDLIST=.*$|RTLDLIST=\"$out/lib/ld-linux-x86-64.so.2 $out/lib/32/ld-linux.so.2\"|g" \ + '${glibc64.bin}/bin/ldd' > "$bin/bin/ldd" + chmod +x "$bin/bin/ldd" + + mkdir "$dev" + cp -rs '${glibc32.dev}'/include "$dev/" + chmod +w -R "$dev" + cp -rsf '${glibc64.dev}'/include "$dev/" + '' diff --git a/nixpkgs/pkgs/development/libraries/glibc/nix-locale-archive.patch b/nixpkgs/pkgs/development/libraries/glibc/nix-locale-archive.patch new file mode 100644 index 000000000000..2fedf2a7a7db --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/nix-locale-archive.patch @@ -0,0 +1,121 @@ +diff --git a/locale/loadarchive.c b/locale/loadarchive.c +index 512769eaec..171dbb4ad9 100644 +--- a/locale/loadarchive.c ++++ b/locale/loadarchive.c +@@ -123,6 +123,23 @@ calculate_head_size (const struct locarhead *h) + return MAX (namehash_end, MAX (string_end, locrectab_end)); + } + ++static int ++open_locale_archive (void) ++{ ++ int fd = -1; ++ char *versioned_path = getenv ("LOCALE_ARCHIVE_2_27"); ++ char *path = getenv ("LOCALE_ARCHIVE"); ++ if (versioned_path) ++ fd = __open_nocancel (versioned_path, O_RDONLY|O_LARGEFILE|O_CLOEXEC); ++ if (path && fd < 0) ++ fd = __open_nocancel (path, O_RDONLY|O_LARGEFILE|O_CLOEXEC); ++ if (fd < 0) ++ fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); ++ if (fd < 0) ++ fd = __open_nocancel ("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC); ++ return fd; ++} ++ + + /* Find the locale *NAMEP in the locale archive, and return the + internalized data structure for its CATEGORY data. If this locale has +@@ -202,7 +219,7 @@ _nl_load_locale_from_archive (int category, const char **namep) + archmapped = &headmap; + + /* The archive has never been opened. */ +- fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC); ++ fd = open_locale_archive (); + if (fd < 0) + /* Cannot open the archive, for whatever reason. */ + return NULL; +@@ -397,8 +414,7 @@ _nl_load_locale_from_archive (int category, const char **namep) + if (fd == -1) + { + struct __stat64_t64 st; +- fd = __open_nocancel (archfname, +- O_RDONLY|O_LARGEFILE|O_CLOEXEC); ++ fd = open_locale_archive(); + if (fd == -1) + /* Cannot open the archive, for whatever reason. */ + return NULL; +diff --git a/locale/programs/locale.c b/locale/programs/locale.c +index ca0a95be99..e484783402 100644 +--- a/locale/programs/locale.c ++++ b/locale/programs/locale.c +@@ -633,6 +633,24 @@ nameentcmp (const void *a, const void *b) + } + + ++static int ++open_locale_archive (void) ++{ ++ int fd = -1; ++ char *versioned_path = getenv ("LOCALE_ARCHIVE_2_27"); ++ char *path = getenv ("LOCALE_ARCHIVE"); ++ if (versioned_path) ++ fd = open64 (versioned_path, O_RDONLY); ++ if (path && fd < 0) ++ fd = open64 (path, O_RDONLY); ++ if (fd < 0) ++ fd = open64 (ARCHIVE_NAME, O_RDONLY); ++ if (fd < 0) ++ fd = open64 ("/usr/lib/locale/locale-archive", O_RDONLY); ++ return fd; ++} ++ ++ + static int + write_archive_locales (void **all_datap, char *linebuf) + { +@@ -645,7 +663,7 @@ write_archive_locales (void **all_datap, char *linebuf) + int fd, ret = 0; + uint32_t cnt; + +- fd = open64 (ARCHIVE_NAME, O_RDONLY); ++ fd = open_locale_archive (); + if (fd < 0) + return 0; + +diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c +index f38e835c52..779a3199fc 100644 +--- a/locale/programs/locarchive.c ++++ b/locale/programs/locarchive.c +@@ -117,6 +117,22 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags, + } + + ++static int ++open_locale_archive (const char * archivefname, int flags) ++{ ++ int fd = -1; ++ char *versioned_path = getenv ("LOCALE_ARCHIVE_2_27"); ++ char *path = getenv ("LOCALE_ARCHIVE"); ++ if (versioned_path) ++ fd = open64 (versioned_path, flags); ++ if (path && fd < 0) ++ fd = open64 (path, flags); ++ if (fd < 0) ++ fd = open64 (archivefname, flags); ++ return fd; ++} ++ ++ + static void + create_archive (const char *archivefname, struct locarhandle *ah) + { +@@ -578,7 +594,7 @@ open_archive (struct locarhandle *ah, bool readonly) + while (1) + { + /* Open the archive. We must have exclusive write access. */ +- fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR); ++ fd = open_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR); + if (fd == -1) + { + /* Maybe the file does not yet exist? If we are opening diff --git a/nixpkgs/pkgs/development/libraries/glibc/nix-nss-open-files.patch b/nixpkgs/pkgs/development/libraries/glibc/nix-nss-open-files.patch new file mode 100644 index 000000000000..9a515c4662e2 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/nix-nss-open-files.patch @@ -0,0 +1,51 @@ +diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c +index 1db9e46127..3a567e0224 100644 +--- a/nss/nss_files/files-XXX.c ++++ b/nss/nss_files/files-XXX.c +@@ -75,8 +75,20 @@ internal_setent (FILE **stream) + + if (*stream == NULL) + { +- *stream = __nss_files_fopen (DATAFILE); +- ++ const char *file = DATAFILE; ++ ++ #ifdef NIX_DATAFILE ++ // use the Nix environment variable such as `NIX_ETC_PROTOCOLS` ++ char *path = secure_getenv (NIX_DATAFILE); ++ ++ // if the environment variable is set, then read from the /nix/store entry instead ++ if (path && path[0]) { ++ file = path; ++ } ++ #endif ++ ++ *stream = __nss_files_fopen (file); ++ + if (*stream == NULL) + status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; + } +diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c +index c30bedc0aa..b321e68d3c 100644 +--- a/nss/nss_files/files-proto.c ++++ b/nss/nss_files/files-proto.c +@@ -23,6 +23,7 @@ NSS_DECLARE_MODULE_FUNCTIONS (files) + + #define ENTNAME protoent + #define DATABASE "protocols" ++#define NIX_DATAFILE "NIX_ETC_PROTOCOLS" + + struct protoent_data {}; + +diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c +index bfc2590699..0bff36aee5 100644 +--- a/nss/nss_files/files-service.c ++++ b/nss/nss_files/files-service.c +@@ -24,6 +24,7 @@ NSS_DECLARE_MODULE_FUNCTIONS (files) + + #define ENTNAME servent + #define DATABASE "services" ++#define NIX_DATAFILE "NIX_ETC_SERVICES" + + struct servent_data {}; + diff --git a/nixpkgs/pkgs/development/libraries/glibc/reenable_DT_HASH.patch b/nixpkgs/pkgs/development/libraries/glibc/reenable_DT_HASH.patch new file mode 100644 index 000000000000..87a2329d8240 --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/glibc/reenable_DT_HASH.patch @@ -0,0 +1,28 @@ +From 31915e55f9c34f6137ab1c5ac002375a2d5d4589 Mon Sep 17 00:00:00 2001 +From: Frederik Schwan <frederik.schwan@linux.com> +Date: Fri, 4 Aug 2023 15:19:57 +0200 +Subject: [PATCH] force --hash-style=both to keep compatibility with old niche + software + +--- + Makeconfig | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/Makeconfig b/Makeconfig +index 77d7fd14df..2ae67c4beb 100644 +--- a/Makeconfig ++++ b/Makeconfig +@@ -378,6 +378,10 @@ relro-LDFLAGS = -Wl,-z,relro + LDFLAGS.so += $(relro-LDFLAGS) + LDFLAGS-rtld += $(relro-LDFLAGS) + ++hashstyle-LDFLAGS = -Wl,--hash-style=both ++LDFLAGS.so += $(hashstyle-LDFLAGS) ++LDFLAGS-rtld += $(hashstyle-LDFLAGS) ++ + # Linker options to enable and disable DT_RELR. + ifeq ($(have-dt-relr),yes) + dt-relr-ldflag = -Wl,-z,pack-relative-relocs +-- +2.41.0 + |