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
40 , enableCETRuntimeDefault ? false
41 , extraBuildInputs ? []
42 , extraNativeBuildInputs ? []
49 sha256 = "sha256-GaiQF16SY9dI9ieZPeb0sa+c0h4D8IDkv7Oh+sECBaI=";
52 assert withLinuxHeaders -> linuxHeaders != null;
53 assert withGd -> gd != null && libpng != null;
54 assert enableCET == false -> !enableCETRuntimeDefault;
56 stdenv.mkDerivation ({
57 version = version + patchSuffix;
59 enableParallelBuilding = true;
63 /* No tarballs for stable upstream branch, only https://sourceware.org/git/glibc.git and using git would complicate bootstrapping.
64 $ git fetch --all -p && git checkout origin/release/2.39/master && git describe
65 glibc-2.40-36-g7073164add
66 $ git show --minimal --reverse glibc-2.40.. ':!ADVISORIES' > 2.40-master.patch
68 To compare the archive contents zdiff can be used.
69 $ diff -u 2.40-master.patch ../nixpkgs/pkgs/development/libraries/glibc/2.40-master.patch
71 Please note that each commit has changes to the file ADVISORIES excluded since
72 that conflicts with the directory advisories/ making cross-builds from
73 hosts with case-insensitive file-systems impossible.
77 /* Allow NixOS and Nix to handle the locale-archive. */
78 ./nix-locale-archive.patch
80 /* Don't use /etc/ld.so.cache, for non-NixOS systems. */
81 ./dont-use-system-ld-so-cache.patch
83 /* Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. */
84 ./dont-use-system-ld-so-preload.patch
86 /* The command "getconf CS_PATH" returns the default search path
87 "/bin:/usr/bin", which is inappropriate on NixOS machines. This
88 patch extends the search path by "/run/current-system/sw/bin". */
89 ./fix_path_attribute_in_getconf.patch
93 /* https://github.com/NixOS/nixpkgs/pull/137601 */
94 ./nix-nss-open-files.patch
96 ./0001-Revert-Remove-all-usage-of-BASH-or-BASH-in-installed.patch
98 /* Patch derived from archlinux,
99 https://gitlab.archlinux.org/archlinux/packaging/packages/glibc/-/blob/e54d98e2d1aae4930ecad9404ef12234922d9dfd/reenable_DT_HASH.patch
101 See also https://github.com/ValveSoftware/Proton/issues/6051
102 & https://github.com/NixOS/nixpkgs/pull/188492#issuecomment-1233802991
104 ./reenable_DT_HASH.patch
106 /* NVCC does not support ARM intrinsics. Since <math.h> is pulled in by almost
107 every HPC piece of software, without this patch CUDA compilation on ARM
108 is effectively broken. See
109 https://forums.developer.nvidia.com/t/nvcc-fails-to-build-with-arm-neon-instructions-cpp-vs-cu/248355/2.
113 isAarch64 = stdenv.buildPlatform.isAarch64 || stdenv.hostPlatform.isAarch64;
114 isLinux = stdenv.buildPlatform.isLinux || stdenv.hostPlatform.isLinux;
116 lib.optional (isAarch64 && isLinux) ./0001-aarch64-math-vector.h-add-NVCC-include-guard.patch
118 ++ lib.optional stdenv.hostPlatform.isMusl ./fix-rpc-types-musl-conflicts.patch
119 ++ lib.optional stdenv.buildPlatform.isDarwin ./darwin-cross-build.patch
120 ++ lib.optional enableCETRuntimeDefault ./2.39-revert-cet-default-disable.patch;
124 # Needed for glibc to build with the gnumake 3.82
125 # http://comments.gmane.org/gmane.linux.lfs.support/31227
126 sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile
128 # nscd needs libgcc, and we don't want it dynamically linked
129 # because we don't want it to depend on bootstrap-tools libs.
130 echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile
132 # Ensure that `__nss_files_fopen` can still be wrapped by `libredirect`.
133 sed -i -e '/libc_hidden_def (__nss_files_fopen)/d' nss/nss_files_fopen.c
134 sed -i -e '/libc_hidden_proto (__nss_files_fopen)/d' include/nss_files.h
136 # FIXME: find a solution for infinite recursion in cross builds.
137 # For now it's hopefully acceptable that IDN from libc doesn't reliably work.
138 + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
140 # Ensure that libidn2 is found.
145 -#define LIBIDN2_SONAME "libidn2.so.0"
146 +#define LIBIDN2_SONAME "${lib.getLib libidn2}/lib/libidn2.so.0"
154 "--enable-stack-protector=strong"
156 (lib.withFeatureAs withLinuxHeaders "headers" "${linuxHeaders}/include")
157 (lib.enableFeature profilingLibraries "profile")
158 "--enable-fortify-source"
159 ] ++ lib.optionals (stdenv.hostPlatform.isx86 || stdenv.hostPlatform.isAarch64) [
160 # This feature is currently supported on
161 # i386, x86_64 and x32 with binutils 2.29 or later,
162 # and on aarch64 with binutils 2.30 or later.
163 # https://sourceware.org/glibc/wiki/PortStatus
164 "--enable-static-pie"
165 ] ++ lib.optionals (enableCET != false) [
166 # Enable Intel Control-flow Enforcement Technology (CET) support
167 "--enable-cet${if builtins.isString enableCET then "=${enableCET}" else ""}"
168 ] ++ lib.optionals withLinuxHeaders [
169 "--enable-kernel=3.10.0" # RHEL 7 and derivatives, seems oldest still supported kernel
170 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
171 (lib.flip lib.withFeature "fp"
172 (stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft"))
174 ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform && stdenv.hostPlatform.isAarch32) [
175 "--host=arm-linux-gnueabi"
176 "--build=arm-linux-gnueabi"
178 # To avoid linking with -lgcc_s (dynamic link)
179 # so the glibc does not depend on its compiler store path
180 "libc_cv_as_needed=no"
182 ++ lib.optional withGd "--with-gd";
184 makeFlags = (args.makeFlags or []) ++ [
185 "OBJCOPY=${stdenv.cc.targetPrefix}objcopy"
188 postInstall = (args.postInstall or "") + ''
189 moveToOutput bin/getent $getent
192 installFlags = [ "sysconfdir=$(out)/etc" ];
194 # out as the first output is an exception exclusive to glibc
196 # getent is its own output, not kept in bin, since many things
197 # depend on getent but not on the locale generation tools in the bin
198 # output. This saves a couple of megabytes of closure size in many cases.
199 outputs = [ "out" "bin" "dev" "static" "getent" ];
202 depsBuildBuild = [ buildPackages.stdenv.cc ];
203 nativeBuildInputs = [ bison python3Minimal ] ++ extraNativeBuildInputs;
204 buildInputs = [ linuxHeaders ] ++ lib.optionals withGd [ gd libpng ] ++ extraBuildInputs;
207 linuxHeaders = lib.optionalString withLinuxHeaders linuxHeaders;
208 inherit (stdenv.hostPlatform) is64bit;
209 # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
210 # prevent a retained dependency on the bootstrap tools in the stdenv-linux
212 BASH_SHELL = "/bin/sh";
215 # Used by libgcc, elf-header, and others to determine ABI
216 passthru = { inherit version; minorRelease = version; };
219 // (removeAttrs args [ "withLinuxHeaders" "withGd" "enableCET" "postInstall" "makeFlags" ]) //
223 url = "mirror://gnu/glibc/glibc-${version}.tar.xz";
227 # Remove absolute paths from `configure' & co.; build out-of-tree.
229 export PWD_P=$(type -tP pwd)
230 for i in configure io/ftwtest-sh; do
231 # Can't use substituteInPlace here because replace hasn't been
232 # built yet in the bootstrap.
233 sed -i "$i" -e "s^/bin/pwd^$PWD_P^g"
239 configureScript="`pwd`/../$sourceRoot/configure"
241 ${lib.optionalString (stdenv.cc.libc != null)
242 ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib OBJDUMP=${stdenv.cc.bintools.bintools}/bin/objdump"''
246 '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
247 sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig"
249 cat > config.cache << "EOF"
250 libc_cv_forced_unwind=yes
251 libc_cv_c_cleanup=yes
252 libc_cv_gnu89_inline=yes
255 # ./configure has logic like
257 # AR=`$CC -print-prog-name=ar`
259 # This searches various directories in the gcc and its wrapper. In nixpkgs,
260 # this returns the bare string "ar", which is build ar. This can result as
261 # a build failure with the following message:
263 # libc_pic.a: error adding symbols: archive has no index; run ranlib to add one
265 # (Observed cross compiling from aarch64-linux -> armv7l-linux).
267 # Nixpkgs passes a correct value for AR and friends, so to use the correct
268 # set of tools, we only need to delete this special handling.
278 preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH";
280 doCheck = false; # fails
283 homepage = "https://www.gnu.org/software/libc/";
284 description = "GNU C Library";
287 Any Unix-like operating system needs a C library: the library which
288 defines the "system calls" and other basic facilities such as
289 open, malloc, printf, exit...
291 The GNU C library is used as the C library in the GNU system and
292 most systems with the Linux kernel.
295 license = licenses.lgpl2Plus;
297 maintainers = with maintainers; [ ma27 connorbaker ];
298 platforms = platforms.linux;
299 } // (args.meta or {});