Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 callPackage, 5 withLinuxHeaders ? true, 6 linuxHeaders ? null, 7 profilingLibraries ? false, 8 withGd ? false, 9 enableCET ? if stdenv.hostPlatform.isx86_64 then "permissive" else false, 10 enableCETRuntimeDefault ? false, 11 pkgsBuildBuild, 12 libgcc, 13}: 14 15let 16 gdCflags = [ 17 "-Wno-error=stringop-truncation" 18 "-Wno-error=missing-attributes" 19 "-Wno-error=array-bounds" 20 ]; 21in 22 23(callPackage ./common.nix { inherit stdenv linuxHeaders; } { 24 inherit 25 withLinuxHeaders 26 withGd 27 profilingLibraries 28 enableCET 29 enableCETRuntimeDefault 30 ; 31 pname = 32 "glibc" 33 + lib.optionalString withGd "-gd" 34 + lib.optionalString (stdenv.cc.isGNU && libgcc == null) "-nolibgcc"; 35}).overrideAttrs 36 (previousAttrs: { 37 38 # Note: 39 # Things you write here override, and do not add to, 40 # the values in `common.nix`. 41 # (For example, if you define `patches = [...]` here, it will 42 # override the patches in `common.nix` -- so instead you should 43 # write `patches = (previousAttrs.patches or []) ++ [ ... ]`. 44 45 NIX_NO_SELF_RPATH = true; 46 47 postConfigure = '' 48 # Hack: get rid of the `-static' flag set by the bootstrap stdenv. 49 # This has to be done *after* `configure' because it builds some 50 # test binaries. 51 export NIX_CFLAGS_LINK= 52 export NIX_LDFLAGS_BEFORE= 53 54 export NIX_DONT_SET_RPATH=1 55 unset CFLAGS 56 57 # Apparently --bindir is not respected. 58 makeFlagsArray+=("bindir=$bin/bin" "sbindir=$bin/sbin" "rootsbindir=$bin/sbin") 59 ''; 60 61 # The pie, stackprotector and fortify hardening flags are autodetected by 62 # glibc and enabled by default if supported. Setting it for every gcc 63 # invocation does not work. 64 hardeningDisable = [ 65 "fortify" 66 "pie" 67 "stackprotector" 68 "strictflexarrays3" 69 ]; 70 71 env = (previousAttrs.env or { }) // { 72 NIX_CFLAGS_COMPILE = 73 (previousAttrs.env.NIX_CFLAGS_COMPILE or "") 74 + lib.concatStringsSep " " ( 75 builtins.concatLists [ 76 (lib.optionals withGd gdCflags) 77 # Fix -Werror build failure when building glibc with musl with GCC >= 8, see: 78 # https://github.com/NixOS/nixpkgs/pull/68244#issuecomment-544307798 79 (lib.optional stdenv.hostPlatform.isMusl "-Wno-error=attribute-alias") 80 (lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) || stdenv.hostPlatform.isMusl) [ 81 # Ignore "error: '__EI___errno_location' specifies less restrictive attributes than its target '__errno_location'" 82 # New warning as of GCC 9 83 # Same for musl: https://github.com/NixOS/nixpkgs/issues/78805 84 "-Wno-error=missing-attributes" 85 ]) 86 (lib.optionals (stdenv.hostPlatform.isPower64) [ 87 # Do not complain about the Processor Specific ABI (i.e. the 88 # choice to use IEEE-standard `long double`). We pass this 89 # flag in order to mute a `-Werror=psabi` passed by glibc; 90 # hopefully future glibc releases will not pass that flag. 91 "-Wno-error=psabi" 92 ]) 93 ] 94 ); 95 }; 96 97 # glibc needs to `dlopen()` `libgcc_s.so` but does not link 98 # against it. Furthermore, glibc doesn't use the ordinary 99 # `dlopen()` call to do this; instead it uses one which ignores 100 # most paths: 101 # 102 # https://sourceware.org/legacy-ml/libc-help/2013-11/msg00026.html 103 # 104 # In order to get it to not ignore `libgcc_s.so`, we have to add its path to 105 # `user-defined-trusted-dirs`: 106 # 107 # https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/Makefile;h=b509b3eada1fb77bf81e2a0ca5740b94ad185764#l1355 108 # 109 # Conveniently, this will also inform Nix of the fact that glibc depends on 110 # gcc.libgcc, since the path will be embedded in the resulting binary. 111 # 112 makeFlags = 113 (previousAttrs.makeFlags or [ ]) 114 ++ lib.optionals (libgcc != null) [ 115 "user-defined-trusted-dirs=${libgcc}/lib" 116 ]; 117 118 postInstall = 119 previousAttrs.postInstall 120 + ( 121 if stdenv.buildPlatform.canExecute stdenv.hostPlatform then 122 '' 123 echo SUPPORTED-LOCALES=C.UTF-8/UTF-8 > ../glibc-2*/localedata/SUPPORTED 124 # Don't install C.utf-8 into the archive, but into $out/lib/locale: on non-NixOS 125 # systems with an empty /usr/lib/locale/locale-archive, glibc would fall back to 126 # $libdir/locale/C.utf-8 instead of the locale archive of pkgs.glibc. See also #347965. 127 make -j''${NIX_BUILD_CORES:-1} localedata/install-locale-files 128 '' 129 else 130 lib.optionalString stdenv.buildPlatform.isLinux 131 # This is based on http://www.linuxfromscratch.org/lfs/view/development/chapter06/glibc.html 132 # Instead of using their patch to build a build-native localedef, 133 # we simply use the one from pkgsBuildBuild. 134 # 135 # Note that we can't use pkgsBuildHost (aka buildPackages) here, because 136 # that will cause an eval-time infinite recursion: "buildPackages.glibc 137 # depended on buildPackages.libgcc, which, since it's GCC, depends on the 138 # target's bintools, which depend on the target's glibc, which, again, 139 # depends on buildPackages.glibc, causing an infinute recursion when 140 # evaluating buildPackages.glibc when glibc hasn't come from stdenv 141 # (e.g. on musl)." https://github.com/NixOS/nixpkgs/pull/259964 142 '' 143 pushd ../glibc-2*/localedata 144 export I18NPATH=$PWD GCONV_PATH=$PWD/../iconvdata 145 mkdir -p $NIX_BUILD_TOP/${pkgsBuildBuild.glibc}/lib/locale 146 ${lib.getBin pkgsBuildBuild.glibc}/bin/localedef \ 147 --alias-file=../intl/locale.alias \ 148 -i locales/C \ 149 -f charmaps/UTF-8 \ 150 --prefix $NIX_BUILD_TOP \ 151 ${ 152 if stdenv.hostPlatform.parsed.cpu.significantByte.name == "littleEndian" then 153 "--little-endian" 154 else 155 "--big-endian" 156 } \ 157 C.UTF-8 158 cp -r $NIX_BUILD_TOP/${pkgsBuildBuild.glibc}/lib/locale $out/lib 159 popd 160 '' 161 ) 162 + '' 163 164 test -f $out/etc/ld.so.cache && rm $out/etc/ld.so.cache 165 166 if test -n "$linuxHeaders"; then 167 # Include the Linux kernel headers in Glibc, except the `scsi' 168 # subdirectory, which Glibc provides itself. 169 (cd $dev/include && \ 170 ln -sv $(ls -d $linuxHeaders/include/* | grep -v scsi\$) .) 171 fi 172 173 # Fix for NIXOS-54 (ldd not working on x86_64). Make a symlink 174 # "lib64" to "lib". 175 if test -n "$is64bit"; then 176 ln -s lib $out/lib64 177 fi 178 179 # Get rid of more unnecessary stuff. 180 rm -rf $out/var $bin/bin/sln 181 182 # Backwards-compatibility to fix e.g. 183 # "configure: error: Pthreads are required to build libgomp" during `gcc`-build 184 # because it's not actually needed anymore to link against `pthreads` since 185 # it's now part of `libc.so.6` itself, but the gcc build breaks if 186 # this doesn't work. 187 ln -sf $out/lib/libpthread.so.0 $out/lib/libpthread.so 188 ln -sf $out/lib/librt.so.1 $out/lib/librt.so 189 ln -sf $out/lib/libdl.so.2 $out/lib/libdl.so 190 test -f $out/lib/libutil.so.1 && ln -sf $out/lib/libutil.so.1 $out/lib/libutil.so 191 touch $out/lib/libpthread.a 192 193 # Put libraries for static linking in a separate output. Note 194 # that libc_nonshared.a and libpthread_nonshared.a are required 195 # for dynamically-linked applications. 196 mkdir -p $static/lib 197 mv $out/lib/*.a $static/lib 198 mv $static/lib/lib*_nonshared.a $out/lib 199 # If libutil.so.1 is missing, libutil.a is required. 200 test -f $out/lib/libutil.so.1 || mv $static/lib/libutil.a $out/lib 201 # Some of *.a files are linker scripts where moving broke the paths. 202 sed "/^GROUP/s|$out/lib/lib|$static/lib/lib|g" \ 203 -i "$static"/lib/*.a 204 205 # Work around a Nix bug: hard links across outputs cause a build failure. 206 cp $bin/bin/getconf $bin/bin/getconf_ 207 mv $bin/bin/getconf_ $bin/bin/getconf 208 ''; 209 210 separateDebugInfo = true; 211 212 passthru = 213 (previousAttrs.passthru or { }) 214 // lib.optionalAttrs (libgcc != null) { 215 inherit libgcc; 216 }; 217 218 meta = (previousAttrs.meta or { }) // { 219 description = "GNU C Library"; 220 }; 221 })