Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge #60860: gcc9: init at 9.1.0

(cherry picked from commits f7d3fb876a 5964b3a 64f7cb24d)
I think C(++) devs may appreciate this, including myself :-)

authored by Eelco Dolstra and committed by Vladimír Čunát 8e99c9eb 096e2f13

+397
+384
pkgs/development/compilers/gcc/9/default.nix
··· 1 + { stdenv, targetPackages, fetchurl, noSysDirs 2 + , langC ? true, langCC ? true, langFortran ? false 3 + , langObjC ? stdenv.targetPlatform.isDarwin 4 + , langObjCpp ? stdenv.targetPlatform.isDarwin 5 + , langGo ? false 6 + , profiledCompiler ? false 7 + , staticCompiler ? false 8 + , enableShared ? true 9 + , texinfo ? null 10 + , perl ? null # optional, for texi2pod (then pod2man) 11 + , gmp, mpfr, libmpc, gettext, which 12 + , libelf # optional, for link-time optimizations (LTO) 13 + , isl ? null # optional, for the Graphite optimization framework. 14 + , zlib ? null 15 + , enableMultilib ? false 16 + , enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins 17 + , name ? "gcc" 18 + , libcCross ? null 19 + , crossStageStatic ? false 20 + , # Strip kills static libs of other archs (hence no cross) 21 + stripped ? stdenv.hostPlatform == stdenv.buildPlatform 22 + && stdenv.targetPlatform == stdenv.hostPlatform 23 + , gnused ? null 24 + , cloog # unused; just for compat with gcc4, as we override the parameter on some places 25 + , buildPackages 26 + }: 27 + 28 + # LTO needs libelf and zlib. 29 + assert libelf != null -> zlib != null; 30 + 31 + # Make sure we get GNU sed. 32 + assert stdenv.hostPlatform.isDarwin -> gnused != null; 33 + 34 + # The go frontend is written in c++ 35 + assert langGo -> langCC; 36 + 37 + with stdenv.lib; 38 + with builtins; 39 + 40 + let version = "9.1.0"; 41 + 42 + inherit (stdenv) buildPlatform hostPlatform targetPlatform; 43 + 44 + patches = 45 + optional (targetPlatform != hostPlatform) ../libstdc++-target.patch 46 + ++ optional noSysDirs ../no-sys-dirs.patch 47 + /* ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied 48 + url = "https://git.busybox.net/buildroot/plain/package/gcc/${version}/0900-remove-selftests.patch?id=11271540bfe6adafbc133caf6b5b902a816f5f02"; 49 + sha256 = ""; # TODO: uncomment and check hash when available. 50 + }) */ 51 + ++ optional langFortran ../gfortran-driving.patch 52 + ++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch; 53 + 54 + /* Cross-gcc settings (build == host != target) */ 55 + crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; 56 + crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem"; 57 + crossConfigureFlags = 58 + # Ensure that -print-prog-name is able to find the correct programs. 59 + [ "--with-as=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as" 60 + "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] ++ 61 + (if crossMingw && crossStageStatic then [ 62 + "--with-headers=${libcCross}/include" 63 + "--with-gcc" 64 + "--with-gnu-as" 65 + "--with-gnu-ld" 66 + "--with-gnu-ld" 67 + "--disable-shared" 68 + "--disable-nls" 69 + "--disable-debug" 70 + "--enable-sjlj-exceptions" 71 + "--enable-threads=win32" 72 + "--disable-win32-registry" 73 + "--disable-libmpx" # requires libc 74 + ] else if crossStageStatic then [ 75 + "--disable-libssp" 76 + "--disable-nls" 77 + "--without-headers" 78 + "--disable-threads" 79 + "--disable-libgomp" 80 + "--disable-libquadmath" 81 + "--disable-shared" 82 + "--disable-libatomic" # requires libc 83 + "--disable-decimal-float" # requires libc 84 + "--disable-libmpx" # requires libc 85 + ] else [ 86 + (if crossDarwin then "--with-sysroot=${getLib libcCross}/share/sysroot" 87 + else "--with-headers=${getDev libcCross}${libcCross.incdir or "/include"}") 88 + "--enable-__cxa_atexit" 89 + "--enable-long-long" 90 + ] ++ 91 + (if crossMingw then [ 92 + "--enable-threads=win32" 93 + "--enable-sjlj-exceptions" 94 + "--enable-hash-synchronization" 95 + "--enable-libssp" 96 + "--disable-nls" 97 + "--with-dwarf2" 98 + # To keep ABI compatibility with upstream mingw-w64 99 + "--enable-fully-dynamic-string" 100 + ] else 101 + optionals (targetPlatform.libc == "uclibc" || targetPlatform.libc == "musl") [ 102 + # libsanitizer requires netrom/netrom.h which is not 103 + # available in uclibc. 104 + "--disable-libsanitizer" 105 + # In uclibc cases, libgomp needs an additional '-ldl' 106 + # and as I don't know how to pass it, I disable libgomp. 107 + "--disable-libgomp" 108 + # musl at least, disable: https://git.buildroot.net/buildroot/commit/?id=873d4019f7fb00f6a80592224236b3ba7d657865 109 + "--disable-libmpx" 110 + ] 111 + ++ optional (targetPlatform.libc == "newlib") "--with-newlib" 112 + ++ optional (targetPlatform.libc == "avrlibc") "--with-avrlibc" 113 + ++ [ 114 + "--enable-threads=${if targetPlatform.isUnix then "posix" 115 + else if targetPlatform.isWindows then "win32" 116 + else "single"}" 117 + "--enable-nls" 118 + "--disable-decimal-float" # No final libdecnumber (it may work only in 386) 119 + ])); 120 + stageNameAddon = if crossStageStatic then "-stage-static" else "-stage-final"; 121 + crossNameAddon = if targetPlatform != hostPlatform then "-${targetPlatform.config}" + stageNameAddon else ""; 122 + 123 + bootstrap = targetPlatform == hostPlatform; 124 + 125 + in 126 + 127 + stdenv.mkDerivation ({ 128 + name = "${name}${if stripped then "" else "-debug"}-${version}" + crossNameAddon; 129 + 130 + builder = ../builder.sh; 131 + 132 + src = fetchurl { 133 + url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz"; 134 + sha256 = "1817nc2bqdc251k0lpc51cimna7v68xjrnvqzvc50q3ax4s6i9kr"; 135 + }; 136 + 137 + inherit patches; 138 + 139 + outputs = [ "out" "lib" "man" "info" ]; 140 + setOutputFlags = false; 141 + NIX_NO_SELF_RPATH = true; 142 + 143 + libc_dev = stdenv.cc.libc_dev; 144 + 145 + hardeningDisable = [ "format" "pie" ]; 146 + 147 + # This should kill all the stdinc frameworks that gcc and friends like to 148 + # insert into default search paths. 149 + prePatch = stdenv.lib.optionalString hostPlatform.isDarwin '' 150 + substituteInPlace gcc/config/darwin-c.c \ 151 + --replace 'if (stdinc)' 'if (0)' 152 + 153 + substituteInPlace libgcc/config/t-slibgcc-darwin \ 154 + --replace "-install_name @shlib_slibdir@/\$(SHLIB_INSTALL_NAME)" "-install_name $lib/lib/\$(SHLIB_INSTALL_NAME)" 155 + 156 + substituteInPlace libgfortran/configure \ 157 + --replace "-install_name \\\$rpath/\\\$soname" "-install_name $lib/lib/\\\$soname" 158 + ''; 159 + 160 + postPatch = '' 161 + configureScripts=$(find . -name configure) 162 + for configureScript in $configureScripts; do 163 + patchShebangs $configureScript 164 + done 165 + '' + ( 166 + if targetPlatform != hostPlatform || stdenv.cc.libc != null then 167 + # On NixOS, use the right path to the dynamic linker instead of 168 + # `/lib/ld*.so'. 169 + let 170 + libc = if libcCross != null then libcCross else stdenv.cc.libc; 171 + in 172 + ( 173 + '' echo "fixing the \`GLIBC_DYNAMIC_LINKER', \`UCLIBC_DYNAMIC_LINKER', and \`MUSL_DYNAMIC_LINKER' macros..." 174 + for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 175 + do 176 + grep -q _DYNAMIC_LINKER "$header" || continue 177 + echo " fixing \`$header'..." 178 + sed -i "$header" \ 179 + -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \ 180 + -e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g' 181 + done 182 + '' 183 + + stdenv.lib.optionalString (targetPlatform.libc == "musl") 184 + '' 185 + sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR' 186 + '' 187 + ) 188 + else ""); 189 + 190 + inherit noSysDirs staticCompiler crossStageStatic 191 + libcCross crossMingw; 192 + 193 + depsBuildBuild = [ buildPackages.stdenv.cc ]; 194 + nativeBuildInputs = [ texinfo which gettext ] 195 + ++ (optional (perl != null) perl); 196 + 197 + # For building runtime libs 198 + depsBuildTarget = 199 + if hostPlatform == buildPlatform then [ 200 + targetPackages.stdenv.cc.bintools # newly-built gcc will be used 201 + ] else assert targetPlatform == hostPlatform; [ # build != host == target 202 + stdenv.cc 203 + ]; 204 + 205 + buildInputs = [ 206 + gmp mpfr libmpc libelf 207 + targetPackages.stdenv.cc.bintools # For linking code at run-time 208 + ] ++ (optional (isl != null) isl) 209 + ++ (optional (zlib != null) zlib) 210 + # The builder relies on GNU sed (for instance, Darwin's `sed' fails with 211 + # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it. 212 + ++ (optional hostPlatform.isDarwin gnused) 213 + ; 214 + 215 + NIX_LDFLAGS = stdenv.lib.optionalString hostPlatform.isSunOS "-lm -ldl"; 216 + 217 + preConfigure = stdenv.lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) '' 218 + export NIX_LDFLAGS=`echo $NIX_LDFLAGS | sed -e s~$prefix/lib~$prefix/lib/amd64~g` 219 + export LDFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $LDFLAGS_FOR_TARGET" 220 + export CXXFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CXXFLAGS_FOR_TARGET" 221 + export CFLAGS_FOR_TARGET="-Wl,-rpath,$prefix/lib/amd64 $CFLAGS_FOR_TARGET" 222 + ''; 223 + 224 + dontDisableStatic = true; 225 + 226 + # TODO(@Ericson2314): Always pass "--target" and always prefix. 227 + configurePlatforms = [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target"; 228 + 229 + configureFlags = 230 + # Basic dependencies 231 + [ 232 + "--with-gmp-include=${gmp.dev}/include" 233 + "--with-gmp-lib=${gmp.out}/lib" 234 + "--with-mpfr-include=${mpfr.dev}/include" 235 + "--with-mpfr-lib=${mpfr.out}/lib" 236 + "--with-mpc=${libmpc}" 237 + ] ++ 238 + optional (libelf != null) "--with-libelf=${libelf}" ++ 239 + optional (!(crossMingw && crossStageStatic)) 240 + "--with-native-system-header-dir=${getDev stdenv.cc.libc}/include" ++ 241 + 242 + # Basic configuration 243 + [ 244 + "--enable-lto" 245 + "--disable-libstdcxx-pch" 246 + "--without-included-gettext" 247 + "--with-system-zlib" 248 + "--enable-static" 249 + "--enable-languages=${ 250 + concatStrings (intersperse "," 251 + ( optional langC "c" 252 + ++ optional langCC "c++" 253 + ++ optional langFortran "fortran" 254 + ++ optional langGo "go" 255 + ++ optional langObjC "objc" 256 + ++ optional langObjCpp "obj-c++" 257 + ++ optionals crossDarwin [ "objc" "obj-c++" ] 258 + ) 259 + ) 260 + }" 261 + ] ++ 262 + 263 + (if (enableMultilib || targetPlatform.isAvr) 264 + then ["--enable-multilib" "--disable-libquadmath"] 265 + else ["--disable-multilib"]) ++ 266 + optional (!enableShared) "--disable-shared" ++ 267 + (if enablePlugin 268 + then ["--enable-plugin"] 269 + else ["--disable-plugin"]) ++ 270 + 271 + # Optional features 272 + optional (isl != null) "--with-isl=${isl}" ++ 273 + 274 + (import ../common/platform-flags.nix { inherit (stdenv) lib targetPlatform; }) ++ 275 + optional (targetPlatform != hostPlatform) crossConfigureFlags ++ 276 + optional (!bootstrap) "--disable-bootstrap" ++ 277 + 278 + # Platform-specific flags 279 + optional (targetPlatform == hostPlatform && targetPlatform.isx86_32) "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}" ++ 280 + optionals hostPlatform.isSunOS [ 281 + "--enable-long-long" "--enable-libssp" "--enable-threads=posix" "--disable-nls" "--enable-__cxa_atexit" 282 + # On Illumos/Solaris GNU as is preferred 283 + "--with-gnu-as" "--without-gnu-ld" 284 + ] 285 + ++ optionals (targetPlatform == hostPlatform && targetPlatform.libc == "musl") [ 286 + "--disable-libsanitizer" 287 + "--disable-symvers" 288 + "libat_cv_have_ifunc=no" 289 + "--disable-gnu-indirect-function" 290 + ] 291 + ; 292 + 293 + targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null; 294 + 295 + buildFlags = optional 296 + (bootstrap && hostPlatform == buildPlatform) 297 + (if profiledCompiler then "profiledbootstrap" else "bootstrap"); 298 + 299 + dontStrip = !stripped; 300 + 301 + installTargets = 302 + if stripped 303 + then "install-strip" 304 + else "install"; 305 + 306 + # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 307 + ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; 308 + 309 + # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the 310 + # library headers and binaries, regarless of the language being compiled. 311 + # 312 + # Likewise, the LTO code doesn't find zlib. 313 + # 314 + # Cross-compiling, we need gcc not to read ./specs in order to build the g++ 315 + # compiler (after the specs for the cross-gcc are created). Having 316 + # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. 317 + 318 + CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] 319 + ++ optional (zlib != null) zlib 320 + )); 321 + 322 + LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (optional (zlib != null) zlib)); 323 + 324 + EXTRA_TARGET_FLAGS = optionals 325 + (targetPlatform != hostPlatform && libcCross != null) 326 + ([ 327 + "-idirafter ${getDev libcCross}${libcCross.incdir or "/include"}" 328 + ] ++ optionals (! crossStageStatic) [ 329 + "-B${libcCross.out}${libcCross.libdir or "/lib"}" 330 + ]); 331 + 332 + EXTRA_TARGET_LDFLAGS = optionals 333 + (targetPlatform != hostPlatform && libcCross != null) 334 + ([ 335 + "-Wl,-L${libcCross.out}${libcCross.libdir or "/lib"}" 336 + ] ++ (if crossStageStatic then [ 337 + "-B${libcCross.out}${libcCross.libdir or "/lib"}" 338 + ] else [ 339 + "-Wl,-rpath,${libcCross.out}${libcCross.libdir or "/lib"}" 340 + "-Wl,-rpath-link,${libcCross.out}${libcCross.libdir or "/lib"}" 341 + ])); 342 + 343 + passthru = { 344 + inherit langC langCC langObjC langObjCpp langFortran langGo version; 345 + isGNU = true; 346 + }; 347 + 348 + enableParallelBuilding = true; 349 + inherit enableMultilib; 350 + 351 + inherit (stdenv) is64bit; 352 + 353 + meta = { 354 + homepage = https://gcc.gnu.org/; 355 + license = stdenv.lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ 356 + description = "GNU Compiler Collection, version ${version}" 357 + + (if stripped then "" else " (with debugging info)"); 358 + 359 + longDescription = '' 360 + The GNU Compiler Collection includes compiler front ends for C, C++, 361 + Objective-C, Fortran, OpenMP for C/C++/Fortran, and Ada, as well as 362 + libraries for these languages (libstdc++, libgomp,...). 363 + 364 + GCC development is a part of the GNU Project, aiming to improve the 365 + compiler used in the GNU system including the GNU/Linux variant. 366 + ''; 367 + 368 + maintainers = with stdenv.lib.maintainers; [ synthetica ]; 369 + 370 + platforms = 371 + stdenv.lib.platforms.linux ++ 372 + stdenv.lib.platforms.freebsd ++ 373 + stdenv.lib.platforms.illumos ++ 374 + stdenv.lib.platforms.darwin; 375 + }; 376 + } 377 + 378 + // optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { 379 + makeFlags = [ "all-gcc" "all-target-libgcc" ]; 380 + installTargets = "install-gcc install-target-libgcc"; 381 + } 382 + 383 + // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } 384 + )
+1
pkgs/test/default.nix
··· 7 7 cc-wrapper-gcc = callPackage ./cc-wrapper { stdenv = gccStdenv; }; 8 8 cc-wrapper-gcc7 = callPackage ./cc-wrapper { stdenv = gcc7Stdenv; }; 9 9 cc-wrapper-gcc8 = callPackage ./cc-wrapper { stdenv = gcc8Stdenv; }; 10 + cc-wrapper-gcc9 = callPackage ./cc-wrapper { stdenv = gcc9Stdenv; }; 10 11 cc-wrapper-clang = callPackage ./cc-wrapper { stdenv = llvmPackages.stdenv; }; 11 12 cc-wrapper-libcxx = callPackage ./cc-wrapper { stdenv = llvmPackages.libcxxStdenv; }; 12 13 cc-wrapper-clang-39 = callPackage ./cc-wrapper { stdenv = llvmPackages_39.stdenv; };
+12
pkgs/top-level/all-packages.nix
··· 6853 6853 6854 6854 gcc7Stdenv = overrideCC gccStdenv gcc7; 6855 6855 gcc8Stdenv = overrideCC gccStdenv gcc8; 6856 + gcc9Stdenv = overrideCC gccStdenv gcc9; 6856 6857 6857 6858 wrapCCMulti = cc: 6858 6859 if stdenv.targetPlatform.system == "x86_64-linux" then let ··· 6993 6994 })); 6994 6995 6995 6996 gcc8 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/8 { 6997 + inherit noSysDirs; 6998 + 6999 + # PGO seems to speed up compilation by gcc by ~10%, see #445 discussion 7000 + profiledCompiler = with stdenv; (!isDarwin && (isi686 || isx86_64)); 7001 + 7002 + libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; 7003 + 7004 + isl = if !stdenv.isDarwin then isl_0_17 else null; 7005 + })); 7006 + 7007 + gcc9 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/9 { 6996 7008 inherit noSysDirs; 6997 7009 6998 7010 # PGO seems to speed up compilation by gcc by ~10%, see #445 discussion