1/* Build configuration used to build glibc, Info files, and locale
2 information. */
3
4{ stdenv, lib
5, buildPlatform, hostPlatform
6, buildPackages
7, fetchurl
8, linuxHeaders ? null
9, gd ? null, libpng ? null
10}:
11
12{ name
13, withLinuxHeaders ? false
14, profilingLibraries ? false
15, installLocales ? false
16, withGd ? false
17, meta
18, ...
19} @ args:
20
21let
22 version = "2.26";
23 patchSuffix = "-131";
24 sha256 = "1ggnj1hzjym7sn93rbwydcqd562q73lsb7g7kd199g6j9j9hlkp5";
25 cross = if buildPlatform != hostPlatform then hostPlatform else null;
26in
27
28assert withLinuxHeaders -> linuxHeaders != null;
29assert withGd -> gd != null && libpng != null;
30
31stdenv.mkDerivation ({
32 inherit installLocales;
33 linuxHeaders = if withLinuxHeaders then linuxHeaders else null;
34
35 # The host/target system.
36 crossConfig = if cross != null then cross.config else null;
37
38 inherit (stdenv) is64bit;
39
40 enableParallelBuilding = true;
41
42 patches =
43 [
44 /* No tarballs for stable upstream branch, only https://sourceware.org/git/?p=glibc.git
45 $ git co release/2.25/master; git describe
46 glibc-2.25-49-gbc5ace67fe
47 $ git show --reverse glibc-2.25..release/2.25/master | gzip -n -9 --rsyncable - > 2.25-49.patch.gz
48 */
49 ./2.26-75.patch.gz
50 ./2.26-75to115.diff.gz
51 # contains fix for CVE-2018-1000001 as the last commit:
52 # https://sourceware.org/git/?p=glibc.git;a=commit;h=fabef2edbc
53 ./2.26-115to131.diff.gz
54
55 /* Have rpcgen(1) look for cpp(1) in $PATH. */
56 ./rpcgen-path.patch
57
58 /* Allow NixOS and Nix to handle the locale-archive. */
59 ./nix-locale-archive.patch
60
61 /* Don't use /etc/ld.so.cache, for non-NixOS systems. */
62 ./dont-use-system-ld-so-cache.patch
63
64 /* Don't use /etc/ld.so.preload, but /etc/ld-nix.so.preload. */
65 ./dont-use-system-ld-so-preload.patch
66
67 /* The command "getconf CS_PATH" returns the default search path
68 "/bin:/usr/bin", which is inappropriate on NixOS machines. This
69 patch extends the search path by "/run/current-system/sw/bin". */
70 ./fix_path_attribute_in_getconf.patch
71
72 /* Allow running with RHEL 6 -like kernels. The patch adds an exception
73 for glibc to accept 2.6.32 and to tag the ELFs as 2.6.32-compatible
74 (otherwise the loader would refuse libc).
75 Note that glibc will fully work only on their heavily patched kernels
76 and we lose early mismatch detection on 2.6.32.
77
78 On major glibc updates we should check that the patched kernel supports
79 all the required features. ATM it's verified up to glibc-2.26-131.
80 # HOWTO: check glibc sources for changes in kernel requirements
81 git log -p glibc-2.25.. sysdeps/unix/sysv/linux/x86_64/kernel-features.h sysdeps/unix/sysv/linux/kernel-features.h
82 # get kernel sources (update the URL)
83 mkdir tmp && cd tmp
84 curl http://vault.centos.org/6.9/os/Source/SPackages/kernel-2.6.32-696.el6.src.rpm | rpm2cpio - | cpio -idmv
85 tar xf linux-*.bz2
86 # check syscall presence, for example
87 less linux-*?/arch/x86/kernel/syscall_table_32.S
88 */
89 ./allow-kernel-2.6.32.patch
90 ]
91 ++ lib.optional stdenv.isx86_64 ./fix-x64-abi.patch;
92
93 postPatch =
94 # Needed for glibc to build with the gnumake 3.82
95 # http://comments.gmane.org/gmane.linux.lfs.support/31227
96 ''
97 sed -i 's/ot \$/ot:\n\ttouch $@\n$/' manual/Makefile
98 ''
99 # nscd needs libgcc, and we don't want it dynamically linked
100 # because we don't want it to depend on bootstrap-tools libs.
101 + ''
102 echo "LDFLAGS-nscd += -static-libgcc" >> nscd/Makefile
103 ''
104 # Replace the date and time in nscd by a prefix of $out.
105 # It is used as a protocol compatibility check.
106 # Note: the size of the struct changes, but using only a part
107 # would break hash-rewriting. When receiving stats it does check
108 # that the struct sizes match and can't cause overflow or something.
109 + ''
110 cat ${./glibc-remove-datetime-from-nscd.patch} \
111 | sed "s,@out@,$out," | patch -p1
112 '';
113
114 configureFlags =
115 [ "-C"
116 "--enable-add-ons"
117 "--enable-obsolete-nsl"
118 "--enable-obsolete-rpc"
119 "--sysconfdir=/etc"
120 "--enable-stackguard-randomization"
121 (if withLinuxHeaders
122 then "--with-headers=${linuxHeaders}/include"
123 else "--without-headers")
124 (if profilingLibraries
125 then "--enable-profile"
126 else "--disable-profile")
127 ] ++ lib.optionals withLinuxHeaders [
128 "--enable-kernel=3.2.0" # can't get below with glibc >= 2.26
129 ] ++ lib.optionals (cross != null) [
130 (if cross ? float && cross.float == "soft" then "--without-fp" else "--with-fp")
131 ] ++ lib.optionals (cross != null) [
132 "--with-__thread"
133 ] ++ lib.optionals (cross == null && stdenv.isArm) [
134 "--host=arm-linux-gnueabi"
135 "--build=arm-linux-gnueabi"
136
137 # To avoid linking with -lgcc_s (dynamic link)
138 # so the glibc does not depend on its compiler store path
139 "libc_cv_as_needed=no"
140 ] ++ lib.optional withGd "--with-gd";
141
142 installFlags = [ "sysconfdir=$(out)/etc" ];
143
144 outputs = [ "out" "bin" "dev" "static" ];
145
146 depsBuildBuild = [ buildPackages.stdenv.cc ];
147 buildInputs = lib.optionals withGd [ gd libpng ];
148
149 # Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
150 # prevent a retained dependency on the bootstrap tools in the stdenv-linux
151 # bootstrap.
152 BASH_SHELL = "/bin/sh";
153}
154
155// (removeAttrs args [ "withLinuxHeaders" "withGd" ]) //
156
157{
158 name = name + "-${version}${patchSuffix}";
159
160 src = fetchurl {
161 url = "mirror://gnu/glibc/glibc-${version}.tar.xz";
162 inherit sha256;
163 };
164
165 # Remove absolute paths from `configure' & co.; build out-of-tree.
166 preConfigure = ''
167 export PWD_P=$(type -tP pwd)
168 for i in configure io/ftwtest-sh; do
169 # Can't use substituteInPlace here because replace hasn't been
170 # built yet in the bootstrap.
171 sed -i "$i" -e "s^/bin/pwd^$PWD_P^g"
172 done
173
174 mkdir ../build
175 cd ../build
176
177 configureScript="`pwd`/../$sourceRoot/configure"
178
179 ${lib.optionalString (stdenv.cc.libc != null)
180 ''makeFlags="$makeFlags BUILD_LDFLAGS=-Wl,-rpath,${stdenv.cc.libc}/lib"''
181 }
182
183
184 '' + lib.optionalString (cross != null) ''
185 sed -i s/-lgcc_eh//g "../$sourceRoot/Makeconfig"
186
187 cat > config.cache << "EOF"
188 libc_cv_forced_unwind=yes
189 libc_cv_c_cleanup=yes
190 libc_cv_gnu89_inline=yes
191 EOF
192 '';
193
194 preBuild = lib.optionalString withGd "unset NIX_DONT_SET_RPATH";
195
196 meta = {
197 homepage = http://www.gnu.org/software/libc/;
198 description = "The GNU C Library";
199
200 longDescription =
201 '' Any Unix-like operating system needs a C library: the library which
202 defines the "system calls" and other basic facilities such as
203 open, malloc, printf, exit...
204
205 The GNU C library is used as the C library in the GNU system and
206 most systems with the Linux kernel.
207 '';
208
209 license = lib.licenses.lgpl2Plus;
210
211 maintainers = [ lib.maintainers.eelco ];
212 platforms = lib.platforms.linux;
213 } // meta;
214}
215
216// lib.optionalAttrs (cross != null) {
217 preInstall = null; # clobber the native hook
218
219 dontStrip = true;
220
221 separateDebugInfo = false; # this is currently broken for crossDrv
222
223 # To avoid a dependency on the build system 'bash'.
224 preFixup = ''
225 rm -f $bin/bin/{ldd,tzselect,catchsegv,xtrace}
226 '';
227})