1 /* Build configuration used to build glibc, Info files, and locale
4 Note that this derivation has multiple outputs and does not respect the
5 standard convention of putting the executables into the first output. The
6 first output is `lib` so that the libraries provided by this derivation
7 can be accessed directly, e.g.
9 "${pkgs.glibc}/lib/ld-linux-x86_64.so.2"
11 The executables are put into `bin` output and need to be referenced via
12 the `bin` attribute of the main package, e.g.
14 "${pkgs.glibc.bin}/bin/ldd".
16 The executables provided by glibc typically include `ldd`, `locale`, `iconv`
17 but the exact set depends on the library version and the configuration.
20 # Note: this package is used for bootstrapping fetchurl, and thus
21 # cannot use fetchpatch! All mutable patches (generated by GitHub or
22 # cgit) that are needed here should be included directly in Nixpkgs as
29 , gd ? null, libpng ? null
36 , withLinuxHeaders ? false
37 , profilingLibraries ? false
39 , withLibcrypt ? false
41 , extraBuildInputs ? []
42 , extraNativeBuildInputs ? []
49 sha256 = "sha256-USNzL2tnzNMZMF79OZlx1YWSEivMKmUYob0lEN0M9S4=";
52 assert withLinuxHeaders -> linuxHeaders != null;
53 assert withGd -> gd != null && libpng != null;
55 stdenv.mkDerivation ({
56 version = version + patchSuffix;
57 linuxHeaders = if withLinuxHeaders then linuxHeaders else null;
59 inherit (stdenv) is64bit;
61 enableParallelBuilding = true;
65 /* No tarballs for stable upstream branch, only https://sourceware.org/git/glibc.git and using git would complicate bootstrapping.
66 $ git fetch --all -p && git checkout origin/release/2.35/master && git describe
67 glibc-2.35-210-ge123f08ad5
68 $ git show --minimal --reverse glibc-2.35.. | gzip -9n --rsyncable - > 2.35-master.patch.gz
70 To compare the archive contents zdiff can be used.
71 $ zdiff -u 2.35-master.patch.gz ../nixpkgs/pkgs/development/libraries/glibc/2.35-master.patch.gz
73 ./2.35-master.patch.gz
75 /* Allow NixOS and Nix to handle the locale-archive. */
76 ./nix-locale-archive.patch
78 /* Don't use /etc/ld.so.cache, for non-NixOS systems. */
79 ./dont-use-system-ld-so-cache.patch
81 /* Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. */
82 ./dont-use-system-ld-so-preload.patch
84 /* The command "getconf CS_PATH" returns the default search path
85 "/bin:/usr/bin", which is inappropriate on NixOS machines. This
86 patch extends the search path by "/run/current-system/sw/bin". */
87 ./fix_path_attribute_in_getconf.patch
89 /* Allow running with RHEL 6 -like kernels. The patch adds an exception
90 for glibc to accept 2.6.32 and to tag the ELFs as 2.6.32-compatible
91 (otherwise the loader would refuse libc).
92 Note that glibc will fully work only on their heavily patched kernels
93 and we lose early mismatch detection on 2.6.32.
95 On major glibc updates we should check that the patched kernel supports
96 all the required features. ATM it's verified up to glibc-2.26-131.
97 # HOWTO: check glibc sources for changes in kernel requirements
98 git log -p glibc-2.25.. sysdeps/unix/sysv/linux/x86_64/kernel-features.h sysdeps/unix/sysv/linux/kernel-features.h
99 # get kernel sources (update the URL)
101 curl http://vault.centos.org/6.9/os/Source/SPackages/kernel-2.6.32-696.el6.src.rpm | rpm2cpio - | cpio -idmv
103 # check syscall presence, for example
104 less linux-*?/arch/x86/kernel/syscall_table_32.S
106 ./allow-kernel-2.6.32.patch
108 /* Provide a fallback for missing prlimit64 syscall on RHEL 6 -like
111 This patch is maintained by @veprbl. If it gives you trouble, feel
112 free to ping me, I'd be happy to help.
115 url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/glibc-reinstate-prlimit64-fallback.patch?id=eab07e78b691ae7866267fc04d31c7c3ad6b0eeb";
116 sha256 = "091bk3kyrx1gc380gryrxjzgcmh1ajcj8s2rjhp2d2yzd5mpd5ps";
121 /* https://github.com/NixOS/nixpkgs/pull/137601 */
122 ./nix-nss-open-files.patch
124 ./0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch
126 ++ lib.optional stdenv.hostPlatform.isMusl ./fix-rpc-types-musl-conflicts.patch
127 ++ lib.optional stdenv.buildPlatform.isDarwin ./darwin-cross-build.patch;
131 # Needed for glibc to build with the gnumake 3.82
132 # http://comments.gmane.org/gmane.linux.lfs.support/31227
133 sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile
135 # nscd needs libgcc, and we don't want it dynamically linked
136 # because we don't want it to depend on bootstrap-tools libs.
137 echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile
139 # Ensure that `__nss_files_fopen` can still be wrapped by `libredirect`.
140 sed -i -e '/libc_hidden_def (__nss_files_fopen)/d' nss/nss_files_fopen.c
141 sed -i -e '/libc_hidden_proto (__nss_files_fopen)/d' include/nss_files.h
143 # FIXME: find a solution for infinite recursion in cross builds.
144 # For now it's hopefully acceptable that IDN from libc doesn't reliably work.
145 + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
147 # Ensure that libidn2 is found.
152 -#define LIBIDN2_SONAME "libidn2.so.0"
153 +#define LIBIDN2_SONAME "${lib.getLib libidn2}/lib/libidn2.so.0"
161 "--enable-stack-protector=strong"
163 (lib.withFeatureAs withLinuxHeaders "headers" "${linuxHeaders}/include")
164 (lib.enableFeature profilingLibraries "profile")
165 ] ++ lib.optionals (stdenv.hostPlatform.isx86 || stdenv.hostPlatform.isAarch64) [
166 # This feature is currently supported on
167 # i386, x86_64 and x32 with binutils 2.29 or later,
168 # and on aarch64 with binutils 2.30 or later.
169 # https://sourceware.org/glibc/wiki/PortStatus
170 "--enable-static-pie"
171 ] ++ lib.optionals stdenv.hostPlatform.isx86 [
172 # Enable Intel Control-flow Enforcement Technology (CET) support
174 ] ++ lib.optionals withLinuxHeaders [
175 "--enable-kernel=3.2.0" # can't get below with glibc >= 2.26
176 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
177 (lib.flip lib.withFeature "fp"
178 (stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft"))
180 ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform && stdenv.hostPlatform.isAarch32) [
181 "--host=arm-linux-gnueabi"
182 "--build=arm-linux-gnueabi"
184 # To avoid linking with -lgcc_s (dynamic link)
185 # so the glibc does not depend on its compiler store path
186 "libc_cv_as_needed=no"
188 ++ lib.optional withGd "--with-gd"
189 ++ lib.optional (!withLibcrypt) "--disable-crypt";
192 "OBJCOPY=${stdenv.cc.targetPrefix}objcopy"
195 installFlags = [ "sysconfdir=$(out)/etc" ];
197 # out as the first output is an exception exclusive to glibc
198 outputs = [ "out" "bin" "dev" "static" ];
201 depsBuildBuild = [ buildPackages.stdenv.cc ];
202 nativeBuildInputs = [ bison python3Minimal ] ++ extraNativeBuildInputs;
203 buildInputs = [ linuxHeaders ] ++ lib.optionals withGd [ gd libpng ] ++ extraBuildInputs;
205 # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
206 # prevent a retained dependency on the bootstrap tools in the stdenv-linux
208 BASH_SHELL = "/bin/sh";
210 # Used by libgcc, elf-header, and others to determine ABI
211 passthru = { inherit version; minorRelease = version; };
214 // (removeAttrs args [ "withLinuxHeaders" "withGd" ]) //
218 url = "mirror://gnu/glibc/glibc-${version}.tar.xz";
222 # Remove absolute paths from `configure' & co.; build out-of-tree.
224 export PWD_P=$(type -tP pwd)
225 for i in configure io/ftwtest-sh; do
226 # Can't use substituteInPlace here because replace hasn't been
227 # built yet in the bootstrap.
228 sed -i "$i" -e "s^/bin/pwd^$PWD_P^g"
234 configureScript="`pwd`/../$sourceRoot/configure"
236 ${lib.optionalString (stdenv.cc.libc != null)
237 ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib OBJDUMP=${stdenv.cc.bintools.bintools}/bin/objdump"''
241 '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
242 sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig"
244 cat > config.cache << "EOF"
245 libc_cv_forced_unwind=yes
246 libc_cv_c_cleanup=yes
247 libc_cv_gnu89_inline=yes
250 # ./configure has logic like
252 # AR=`$CC -print-prog-name=ar`
254 # This searches various directories in the gcc and its wrapper. In nixpkgs,
255 # this returns the bare string "ar", which is build ar. This can result as
256 # a build failure with the following message:
258 # libc_pic.a: error adding symbols: archive has no index; run ranlib to add one
260 # (Observed cross compiling from aarch64-linux -> armv7l-linux).
262 # Nixpkgs passes a correct value for AR and friends, so to use the correct
263 # set of tools, we only need to delete this special handling.
273 preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH";
275 doCheck = false; # fails
278 homepage = "https://www.gnu.org/software/libc/";
279 description = "The GNU C Library";
282 '' Any Unix-like operating system needs a C library: the library which
283 defines the "system calls" and other basic facilities such as
284 open, malloc, printf, exit...
286 The GNU C library is used as the C library in the GNU system and
287 most systems with the Linux kernel.
290 license = licenses.lgpl2Plus;
292 maintainers = with maintainers; [ eelco ma27 ];
293 platforms = platforms.linux;
297 // lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) {
298 preInstall = null; # clobber the native hook