fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{ lib, stdenv, callPackage
2, withLinuxHeaders ? true
3, profilingLibraries ? false
4, withGd ? false
5, buildPackages
6}:
7
8let
9 gdCflags = [
10 "-Wno-error=stringop-truncation"
11 "-Wno-error=missing-attributes"
12 "-Wno-error=array-bounds"
13 ];
14in
15
16callPackage ./common.nix { inherit stdenv; } {
17 pname = "glibc" + lib.optionalString withGd "-gd";
18
19 inherit withLinuxHeaders profilingLibraries withGd;
20
21 # Note:
22 # Things you write here override, and do not add to,
23 # the values in `common.nix`.
24 # (For example, if you define `patches = [...]` here, it will
25 # override the patches in `common.nix`.)
26
27 NIX_NO_SELF_RPATH = true;
28
29 postConfigure = ''
30 # Hack: get rid of the `-static' flag set by the bootstrap stdenv.
31 # This has to be done *after* `configure' because it builds some
32 # test binaries.
33 export NIX_CFLAGS_LINK=
34 export NIX_LDFLAGS_BEFORE=
35
36 export NIX_DONT_SET_RPATH=1
37 unset CFLAGS
38
39 # Apparently --bindir is not respected.
40 makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin")
41 '';
42
43 # The stackprotector and fortify hardening flags are autodetected by glibc
44 # and enabled by default if supported. Setting it for every gcc invocation
45 # does not work.
46 hardeningDisable = [ "stackprotector" "fortify" ]
47 # XXX: Not actually musl-speciic but since only musl enables pie by default,
48 # limit rebuilds by only disabling pie w/musl
49 ++ lib.optional stdenv.hostPlatform.isMusl "pie";
50
51 NIX_CFLAGS_COMPILE = lib.concatStringsSep " "
52 (builtins.concatLists [
53 (lib.optionals withGd gdCflags)
54 # Fix -Werror build failure when building glibc with musl with GCC >= 8, see:
55 # https://github.com/NixOS/nixpkgs/pull/68244#issuecomment-544307798
56 (lib.optional stdenv.hostPlatform.isMusl "-Wno-error=attribute-alias")
57 (lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) || stdenv.hostPlatform.isMusl) [
58 # Ignore "error: '__EI___errno_location' specifies less restrictive attributes than its target '__errno_location'"
59 # New warning as of GCC 9
60 # Same for musl: https://github.com/NixOS/nixpkgs/issues/78805
61 "-Wno-error=missing-attributes"
62 ])
63 ]);
64
65 # When building glibc from bootstrap-tools, we need libgcc_s at RPATH for
66 # any program we run, because the gcc will have been placed at a new
67 # store path than that determined when built (as a source for the
68 # bootstrap-tools tarball)
69 # Building from a proper gcc staying in the path where it was installed,
70 # libgcc_s will not be at {gcc}/lib, and gcc's libgcc will be found without
71 # any special hack.
72 preInstall = ''
73 if [ -f ${stdenv.cc.cc}/lib/libgcc_s.so.1 ]; then
74 mkdir -p $out/lib
75 cp ${stdenv.cc.cc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1
76 # the .so It used to be a symlink, but now it is a script
77 cp -a ${stdenv.cc.cc}/lib/libgcc_s.so $out/lib/libgcc_s.so
78 fi
79 '';
80
81 postInstall = (if stdenv.hostPlatform == stdenv.buildPlatform then ''
82 echo SUPPORTED-LOCALES=C.UTF-8/UTF-8 > ../glibc-2*/localedata/SUPPORTED
83 make -j''${NIX_BUILD_CORES:-1} -l''${NIX_BUILD_CORES:-1} localedata/install-locales
84 '' else lib.optionalString stdenv.buildPlatform.isLinux ''
85 # This is based on http://www.linuxfromscratch.org/lfs/view/development/chapter06/glibc.html
86 # Instead of using their patch to build a build-native localedef,
87 # we simply use the one from buildPackages
88 pushd ../glibc-2*/localedata
89 export I18NPATH=$PWD GCONV_PATH=$PWD/../iconvdata
90 mkdir -p $NIX_BUILD_TOP/${buildPackages.glibc}/lib/locale
91 ${lib.getBin buildPackages.glibc}/bin/localedef \
92 --alias-file=../intl/locale.alias \
93 -i locales/C \
94 -f charmaps/UTF-8 \
95 --prefix $NIX_BUILD_TOP \
96 ${if stdenv.hostPlatform.parsed.cpu.significantByte.name == "littleEndian" then
97 "--little-endian"
98 else
99 "--big-endian"} \
100 C.UTF-8
101 cp -r $NIX_BUILD_TOP/${buildPackages.glibc}/lib/locale $out/lib
102 popd
103 '') + ''
104
105 test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache
106
107 if test -n "$linuxHeaders"; then
108 # Include the Linux kernel headers in Glibc, except the `scsi'
109 # subdirectory, which Glibc provides itself.
110 (cd $dev/include && \
111 ln -sv $(ls -d $linuxHeaders/include/* | grep -v scsi\$) .)
112 fi
113
114 # Fix for NIXOS-54 (ldd not working on x86_64). Make a symlink
115 # "lib64" to "lib".
116 if test -n "$is64bit"; then
117 ln -s lib $out/lib64
118 fi
119
120 # Get rid of more unnecessary stuff.
121 rm -rf $out/var $bin/bin/sln
122 ''
123 # For some reason these aren't stripped otherwise and retain reference
124 # to bootstrap-tools; on cross-arm this stripping would break objects.
125 + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
126
127 for i in "$out"/lib/*.a; do
128 [ "$i" = "$out/lib/libm.a" ] || $STRIP -S "$i"
129 done
130 '' + ''
131
132 # Put libraries for static linking in a separate output. Note
133 # that libc_nonshared.a and libpthread_nonshared.a are required
134 # for dynamically-linked applications.
135 mkdir -p $static/lib
136 mv $out/lib/*.a $static/lib
137 mv $static/lib/lib*_nonshared.a $out/lib
138 # Some of *.a files are linker scripts where moving broke the paths.
139 sed "/^GROUP/s|$out/lib/lib|$static/lib/lib|g" \
140 -i "$static"/lib/*.a
141
142 # Work around a Nix bug: hard links across outputs cause a build failure.
143 cp $bin/bin/getconf $bin/bin/getconf_
144 mv $bin/bin/getconf_ $bin/bin/getconf
145 '';
146
147 separateDebugInfo = true;
148
149 meta.description = "The GNU C Library";
150 }