1 { lib, stdenv, callPackage
2 , withLinuxHeaders ? true
3 , profilingLibraries ? false
11 "-Wno-error=stringop-truncation"
12 "-Wno-error=missing-attributes"
13 "-Wno-error=array-bounds"
17 callPackage ./common.nix { inherit stdenv; } {
18 pname = "glibc" + lib.optionalString withGd "-gd";
20 inherit withLinuxHeaders profilingLibraries withGd withLibcrypt;
23 # Things you write here override, and do not add to,
24 # the values in `common.nix`.
25 # (For example, if you define `patches = [...]` here, it will
26 # override the patches in `common.nix`.)
28 NIX_NO_SELF_RPATH = true;
31 # Hack: get rid of the `-static' flag set by the bootstrap stdenv.
32 # This has to be done *after* `configure' because it builds some
34 export NIX_CFLAGS_LINK=
35 export NIX_LDFLAGS_BEFORE=
37 export NIX_DONT_SET_RPATH=1
40 # Apparently --bindir is not respected.
41 makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin")
42 '' + lib.optionalString stdenv.buildPlatform.isDarwin ''
43 # ld-wrapper will otherwise attempt to inject CoreFoundation into ld-linux's RUNPATH
44 export NIX_COREFOUNDATION_RPATH=
47 # The pie, stackprotector and fortify hardening flags are autodetected by
48 # glibc and enabled by default if supported. Setting it for every gcc
49 # invocation does not work.
50 hardeningDisable = [ "fortify" "pie" "stackprotector" ];
52 NIX_CFLAGS_COMPILE = lib.concatStringsSep " "
53 (builtins.concatLists [
54 (lib.optionals withGd gdCflags)
55 # Fix -Werror build failure when building glibc with musl with GCC >= 8, see:
56 # https://github.com/NixOS/nixpkgs/pull/68244#issuecomment-544307798
57 (lib.optional stdenv.hostPlatform.isMusl "-Wno-error=attribute-alias")
58 (lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) || stdenv.hostPlatform.isMusl) [
59 # Ignore "error: '__EI___errno_location' specifies less restrictive attributes than its target '__errno_location'"
60 # New warning as of GCC 9
61 # Same for musl: https://github.com/NixOS/nixpkgs/issues/78805
62 "-Wno-error=missing-attributes"
66 # When building glibc from bootstrap-tools, we need libgcc_s at RPATH for
67 # any program we run, because the gcc will have been placed at a new
68 # store path than that determined when built (as a source for the
69 # bootstrap-tools tarball)
70 # Building from a proper gcc staying in the path where it was installed,
71 # libgcc_s will now be at {gcc}/lib, and gcc's libgcc will be found without
73 # TODO: remove this hack. Things that rely on this hack today:
74 # - dejagnu: during linux bootstrap tcl SIGSEGVs
75 # - clang-wrapper in cross-compilation
76 # Last attempt: https://github.com/NixOS/nixpkgs/pull/36948
78 if [ -f ${stdenv.cc.cc}/lib/libgcc_s.so.1 ]; then
80 cp ${stdenv.cc.cc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1
81 # the .so It used to be a symlink, but now it is a script
82 cp -a ${stdenv.cc.cc}/lib/libgcc_s.so $out/lib/libgcc_s.so
86 postInstall = (if stdenv.hostPlatform == stdenv.buildPlatform then ''
87 echo SUPPORTED-LOCALES=C.UTF-8/UTF-8 > ../glibc-2*/localedata/SUPPORTED
88 make -j''${NIX_BUILD_CORES:-1} localedata/install-locales
89 '' else lib.optionalString stdenv.buildPlatform.isLinux ''
90 # This is based on http://www.linuxfromscratch.org/lfs/view/development/chapter06/glibc.html
91 # Instead of using their patch to build a build-native localedef,
92 # we simply use the one from buildPackages
93 pushd ../glibc-2*/localedata
94 export I18NPATH=$PWD GCONV_PATH=$PWD/../iconvdata
95 mkdir -p $NIX_BUILD_TOP/${buildPackages.glibc}/lib/locale
96 ${lib.getBin buildPackages.glibc}/bin/localedef \
97 --alias-file=../intl/locale.alias \
100 --prefix $NIX_BUILD_TOP \
101 ${if stdenv.hostPlatform.parsed.cpu.significantByte.name == "littleEndian" then
106 cp -r $NIX_BUILD_TOP/${buildPackages.glibc}/lib/locale $out/lib
110 test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache
112 if test -n "$linuxHeaders"; then
113 # Include the Linux kernel headers in Glibc, except the `scsi'
114 # subdirectory, which Glibc provides itself.
115 (cd $dev/include && \
116 ln -sv $(ls -d $linuxHeaders/include/* | grep -v scsi\$) .)
119 # Fix for NIXOS-54 (ldd not working on x86_64). Make a symlink
121 if test -n "$is64bit"; then
125 # Get rid of more unnecessary stuff.
126 rm -rf $out/var $bin/bin/sln
128 # Backwards-compatibility to fix e.g.
129 # "configure: error: Pthreads are required to build libgomp" during `gcc`-build
130 # because it's not actually needed anymore to link against `pthreads` since
131 # it's now part of `libc.so.6` itself, but the gcc build breaks if
133 ln -sf $out/lib/libpthread.so.0 $out/lib/libpthread.so
134 ln -sf $out/lib/librt.so.1 $out/lib/librt.so
135 ln -sf $out/lib/libdl.so.2 $out/lib/libdl.so
136 ln -sf $out/lib/libutil.so.1 $out/lib/libutil.so
137 touch $out/lib/libpthread.a
139 # Put libraries for static linking in a separate output. Note
140 # that libc_nonshared.a and libpthread_nonshared.a are required
141 # for dynamically-linked applications.
143 mv $out/lib/*.a $static/lib
144 mv $static/lib/lib*_nonshared.a $out/lib
145 # Some of *.a files are linker scripts where moving broke the paths.
146 sed "/^GROUP/s|$out/lib/lib|$static/lib/lib|g" \
149 # Work around a Nix bug: hard links across outputs cause a build failure.
150 cp $bin/bin/getconf $bin/bin/getconf_
151 mv $bin/bin/getconf_ $bin/bin/getconf
154 separateDebugInfo = true;
156 meta.description = "The GNU C Library";