From b342dcb13bae24e81c55327d4c5276c7ed73f8c8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 24 Oct 2006 18:26:23 +0000 Subject: [PATCH] * gcc-wrapper: separately store the flags necessary to find GCC and Glibc. This is useful when building GCC. * gcc-wrapper: the dynamic linker has a different name on x86_64 and powerpc. * gcc-wrapper: "glibc" -> "libc", because someday we might support different C libraries. * gcc: don't do a multilib build (e.g., 32-bit support on x86_64), don't need it. * gcc: merge in support for static builds. * gcc: various simplifications in the compiler/linker flags, hope they work. svn path=/nixpkgs/trunk/; revision=6823 --- pkgs/build-support/gcc-wrapper/add-flags | 29 ++++++++++-- pkgs/build-support/gcc-wrapper/builder.sh | 47 +++++++++---------- pkgs/build-support/gcc-wrapper/default.nix | 19 ++++++-- pkgs/build-support/gcc-wrapper/gcc-wrapper.sh | 6 +-- pkgs/build-support/gcc-wrapper/ld-wrapper.sh | 6 +-- pkgs/build-support/gcc-wrapper/setup-hook.sh | 4 +- pkgs/development/compilers/gcc-4.1/builder.sh | 43 +++++------------ .../development/compilers/gcc-4.1/default.nix | 30 ++++++++++-- pkgs/stdenv/linux/make-bootstrap-tools.nix | 6 ++- pkgs/stdenv/linux/new.nix | 16 +++++-- pkgs/stdenv/native/default.nix | 2 +- pkgs/stdenv/nix/default.nix | 2 +- pkgs/top-level/all-packages.nix | 18 +++---- 13 files changed, 135 insertions(+), 93 deletions(-) diff --git a/pkgs/build-support/gcc-wrapper/add-flags b/pkgs/build-support/gcc-wrapper/add-flags index ac1e58ebb81..63a48346001 100644 --- a/pkgs/build-support/gcc-wrapper/add-flags +++ b/pkgs/build-support/gcc-wrapper/add-flags @@ -1,5 +1,24 @@ -export NIX_CFLAGS_COMPILE="@cflagsCompile@ $NIX_CFLAGS_COMPILE" -export NIX_CFLAGS_LINK="@cflagsLink@ $NIX_CFLAGS_LINK" -export NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS" -export NIX_LDFLAGS_BEFORE="@ldflagsBefore@ $NIX_LDFLAGS_BEFORE" -export NIX_GLIBC_FLAGS_SET=1 +# `-B@out@/bin' forces gcc to use ld-wrapper.sh when calling ld. +export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE" + +if test -e @out@/nix-support/libc-cflags; then + export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE" +fi + +if test -e @out@/nix-support/libc-ldflags; then + export NIX_LDFLAGS="$(cat @out@/nix-support/libc-ldflags) $NIX_LDFLAGS" +fi + +if test -e @out@/nix-support/gcc-ldflags; then + export NIX_LDFLAGS="$(cat @out@/nix-support/gcc-ldflags) $NIX_LDFLAGS" +fi + +if test -e @out@/nix-support/gcc-ldflags; then + export NIX_LDFLAGS="$(cat @out@/nix-support/gcc-ldflags) $NIX_LDFLAGS" +fi + +if test -e @out@/nix-support/libc-ldflags-before; then + export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE" +fi + +export NIX_GCC_WRAPPER_FLAGS_SET=1 diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh index b9a811dd747..c0b124fec0c 100644 --- a/pkgs/build-support/gcc-wrapper/builder.sh +++ b/pkgs/build-support/gcc-wrapper/builder.sh @@ -2,20 +2,27 @@ source $stdenv/setup source $substitute -# Force gcc to use ld-wrapper.sh when calling ld. -cflagsCompile="-B$out/bin/" +mkdir $out +mkdir $out/bin +mkdir $out/nix-support -if test -z "$nativeGlibc"; then - # The "-B$glibc/lib/" flag is a quick hack to force gcc to link + +if test -z "$nativeLibc"; then + dynamicLinker="$libc/lib/$dynamicLinker" + echo $dynamicLinker > $out/nix-support/dynamic-linker + + # The "-B$libc/lib/" flag is a quick hack to force gcc to link # against the crt1.o from our own glibc, rather than the one in - # /usr/lib. The real solution is of course to prevent those paths - # from being used by gcc in the first place. + # /usr/lib. (This is only an issue when using an `impure' + # compiler/linker, i.e., one that searches /usr/lib and so on.) + echo "-B$libc/lib/ -isystem $libc/include" > $out/nix-support/libc-cflags + + echo "-L$libc/lib" > $out/nix-support/libc-ldflags + # The dynamic linker is passed in `ldflagsBefore' to allow # explicit overrides of the dynamic linker by callers to gcc/ld # (the *last* value counts, so ours should come first). - cflagsCompile="$cflagsCompile -B$glibc/lib/ -isystem $glibc/include" - ldflags="$ldflags -L$glibc/lib" - ldflagsBefore="-dynamic-linker $glibc/lib/ld-linux.so.2" + echo "-dynamic-linker $dynamicLinker" > $out/nix-support/libc-ldflags-before fi if test -n "$nativeTools"; then @@ -23,19 +30,15 @@ if test -n "$nativeTools"; then ldPath="$nativePrefix/bin" else if test -e "$gcc/lib64"; then - ldflags="$ldflags -L$gcc/lib64" + gccLDFlags="$gccLDFlags -L$gcc/lib64" fi - ldflags="$ldflags -L$gcc/lib" + gccLDFlags="$gccLDFlags -L$gcc/lib" + echo "$gccLDFlags" > $out/nix-support/gcc-ldflags gccPath="$gcc/bin" ldPath="$binutils/bin" fi -mkdir $out -mkdir $out/bin -mkdir $out/nix-support - - doSubstitute() { local src=$1 local dst=$2 @@ -45,11 +48,7 @@ doSubstitute() { --subst-var "gcc" \ --subst-var "gccProg" \ --subst-var "binutils" \ - --subst-var "glibc" \ - --subst-var "cflagsCompile" \ - --subst-var "cflagsLink" \ - --subst-var "ldflags" \ - --subst-var "ldflagsBefore" \ + --subst-var "libc" \ --subst-var-by "ld" "$ldPath/ld" } @@ -88,10 +87,10 @@ chmod +x "$out/bin/ld" # Emit a setup hook. Also store the path to the original GCC and # Glibc. test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc -test -n "$glibc" && echo $glibc > $out/nix-support/orig-glibc +test -n "$libc" && echo $libc > $out/nix-support/orig-libc -doSubstitute "$addFlags" "$out/nix-support/add-flags" +doSubstitute "$addFlags" "$out/nix-support/add-flags.sh" doSubstitute "$setupHook" "$out/nix-support/setup-hook" -cp -p $utils $out/nix-support/utils +cp -p $utils $out/nix-support/utils.sh diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix index c48ee635f37..2edd0049dc1 100644 --- a/pkgs/build-support/gcc-wrapper/default.nix +++ b/pkgs/build-support/gcc-wrapper/default.nix @@ -5,13 +5,13 @@ # stdenv.mkDerivation provides a wrapper that sets up the right environment # variables so that the compiler and the linker just "work". -{ name ? "", stdenv, nativeTools, nativeGlibc, nativePrefix ? "" -, gcc ? null, glibc ? null, binutils ? null, shell ? "" +{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? "" +, gcc ? null, libc ? null, binutils ? null, shell ? "" }: assert nativeTools -> nativePrefix != ""; assert !nativeTools -> gcc != null && binutils != null; -assert !nativeGlibc -> glibc != null; +assert !nativeLibc -> libc != null; stdenv.mkDerivation { builder = ./builder.sh; @@ -21,7 +21,7 @@ stdenv.mkDerivation { ldWrapper = ./ld-wrapper.sh; utils = ./utils.sh; addFlags = ./add-flags; - inherit nativeTools nativeGlibc nativePrefix gcc glibc binutils; + inherit nativeTools nativeLibc nativePrefix gcc libc binutils; name = if name == "" then gcc.name else name; langC = if nativeTools then true else gcc.langC; langCC = if nativeTools then true else gcc.langCC; @@ -30,4 +30,13 @@ stdenv.mkDerivation { meta = if gcc != null && (gcc ? meta) then gcc.meta else { description = "System C compiler wrapper"; }; -} \ No newline at end of file + + # The dynamic linker has different names on different Linux platforms. + dynamicLinker = + if !nativeLibc then + (if stdenv.system == "i686-linux" then "ld-linux.so.2" else + if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else + if stdenv.system == "powerpc-linux" then "ld.so.1" else + abort "don't know the name of the dynamic linker for this platform") + else ""; +} diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh index 51916ccdd4a..fda6b65c525 100644 --- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh @@ -4,11 +4,11 @@ if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then source "$NIX_GCC_WRAPPER_START_HOOK" fi -if test -z "$NIX_GLIBC_FLAGS_SET"; then - source @out@/nix-support/add-flags +if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then + source @out@/nix-support/add-flags.sh fi -source @out@/nix-support/utils +source @out@/nix-support/utils.sh # Figure out if linker flags should be passed. GCC prints annoying diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh index cc1b125804a..94241e42ce9 100644 --- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh @@ -4,11 +4,11 @@ if test -n "$NIX_LD_WRAPPER_START_HOOK"; then source "$NIX_LD_WRAPPER_START_HOOK" fi -if test -z "$NIX_GLIBC_FLAGS_SET"; then - source @out@/nix-support/add-flags +if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then + source @out@/nix-support/add-flags.sh fi -source @out@/nix-support/utils +source @out@/nix-support/utils.sh # Optionally filter out paths not refering to the store. diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh index 1739d8dcae5..60aad0fe4dc 100644 --- a/pkgs/build-support/gcc-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh @@ -24,6 +24,6 @@ if test -n "@binutils@"; then PATH=$PATH:@binutils@/bin fi -if test -n "@glibc@"; then - PATH=$PATH:@glibc@/bin +if test -n "@libc@"; then + PATH=$PATH:@libc@/bin fi diff --git a/pkgs/development/compilers/gcc-4.1/builder.sh b/pkgs/development/compilers/gcc-4.1/builder.sh index 4ff75309ea7..5ba0dcfdbbd 100644 --- a/pkgs/development/compilers/gcc-4.1/builder.sh +++ b/pkgs/development/compilers/gcc-4.1/builder.sh @@ -10,44 +10,25 @@ mkdir $NIX_FIXINC_DUMMY export CPP="gcc -E" -if test "$noSysDirs" = "1"; then +if test "$noSysDirs" = "1" -a -e $NIX_GCC/nix-support/orig-libc; then # Figure out what extra flags to pass to the gcc compilers being # generated to make sure that they use our glibc. - if test -e $NIX_GCC/nix-support/orig-glibc; then - glibc=$(cat $NIX_GCC/nix-support/orig-glibc) + extraCFlags="$(cat $NIX_GCC/nix-support/libc-cflags)" + extraLDFlags="$(cat $NIX_GCC/nix-support/libc-ldflags) $(cat $NIX_GCC/nix-support/libc-ldflags-before)" - # Ugh. Copied from gcc-wrapper/builder.sh. We can't just - # source in $NIX_GCC/nix-support/add-flags, since that would - # cause *this* GCC to be linked against the *previous* GCC. - # Need some more modularity there. - extraCFlags="-B$glibc/lib -isystem $glibc/include" - extraLDFlags="-B$glibc/lib -L$glibc/lib -Wl,-s \ - -Wl,-dynamic-linker,$glibc/lib/ld-linux.so.2" - - # Oh, what a hack. I should be shot for this. In stage 1, we - # should link against the previous GCC, but not afterwards. - # Otherwise we retain a dependency. However, ld-wrapper, - # which adds the linker flags for the previous GCC, is also - # used in stage 2/3. We can prevent it from adding them by - # NIX_GLIBC_FLAGS_SET, but then gcc-wrapper will also not add - # them, thereby causing stage 1 to fail. So we use a trick to - # only set the flags in gcc-wrapper. - hook=$(pwd)/ld-wrapper-hook - echo "NIX_GLIBC_FLAGS_SET=1" > $hook - export NIX_LD_WRAPPER_START_HOOK=$hook - - # Use *real* header files, otherwise a limits.h is generated - # that does not include Glibc's limits.h (notably missing - # SSIZE_MAX, which breaks the build). - export NIX_FIXINC_DUMMY=$glibc/include - fi + # Use *real* header files, otherwise a limits.h is generated that + # does not include Glibc's limits.h (notably missing SSIZE_MAX, + # which breaks the build). + export NIX_FIXINC_DUMMY=$(cat $NIX_GCC/nix-support/orig-libc)/include export NIX_EXTRA_CFLAGS=$extraCFlags - export NIX_EXTRA_LDFLAGS=$extraLDFlags + for i in $extraLDFlags; do + export NIX_EXTRA_LDFLAGS="$NIX_EXTRA_LDFLAGS -Wl,$i" + done export CFLAGS=$extraCFlags export CXXFLAGS=$extraCFlags - export LDFLAGS=$extraLDFlags +# export LDFLAGS=$extraLDFlags fi @@ -68,7 +49,7 @@ preConfigure() { cd ../build configureScript=../$sourceRoot/configure - configureFlags="--enable-languages=$langs --disable-libstdcxx-pch" + configureFlags="--enable-languages=$langs $configureFlags" } diff --git a/pkgs/development/compilers/gcc-4.1/default.nix b/pkgs/development/compilers/gcc-4.1/default.nix index 63265241f53..0883bb7558a 100644 --- a/pkgs/development/compilers/gcc-4.1/default.nix +++ b/pkgs/development/compilers/gcc-4.1/default.nix @@ -1,6 +1,7 @@ { stdenv, fetchurl, noSysDirs , langC ? true, langCC ? true, langF77 ? false , profiledCompiler ? false +, staticCompiler ? false }: assert langC; @@ -8,15 +9,36 @@ assert langC; stdenv.mkDerivation { name = "gcc-4.1.1"; builder = ./builder.sh; - src = fetchurl { - url = http://nix.cs.uu.nl/dist/tarballs/gcc-4.1.1.tar.bz2; - md5 = "ad9f97a4d04982ccf4fd67cb464879f3"; - }; + + src = + [(fetchurl { + url = http://ftp.gnu.org/pub/gnu/gcc/gcc-4.1.1/gcc-core-4.1.1.tar.bz2; + md5 = "a1b189c98aa7d7f164036bbe89b9b2a2"; + })] ++ + (if langCC then [(fetchurl { + url = http://ftp.gnu.org/pub/gnu/gcc/gcc-4.1.1/gcc-g++-4.1.1.tar.bz2; + md5 = "70c786bf8ca042e880a87fecb9e4dfcd"; + })] else []) ++ + (if langF77 then [(fetchurl { + url = http://ftp.gnu.org/pub/gnu/gcc/gcc-4.1.1/gcc-fortran-4.1.1.tar.bz2; + md5 = "b088a28a1963d16bf505262f8bfd09db"; + })] else []); + patches = [./pass-cxxcpp.patch] ++ (if noSysDirs then [./no-sys-dirs.patch] else []); + inherit noSysDirs langC langCC langF77 profiledCompiler; + configureFlags = " + --disable-multilib + --disable-libstdcxx-pch + --disable-libmudflap + --disable-libssp + "; + + makeFlags = if staticCompiler then "LDFLAGS=-static" else ""; + meta = { homepage = "http://gcc.gnu.org/"; license = "GPL/LGPL"; diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix index c0de7032a8b..2792c42472b 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix @@ -48,10 +48,12 @@ let binutils = pkgsDiet.binutils217; - gcc = import ../../development/compilers/gcc-static-4.1 { + gcc = import ../../development/compilers/gcc-4.1 { inherit (pkgs) fetchurl stdenv; - profiledCompiler = false; + noSysDirs = true; + profiledCompiler = true; langCC = false; + staticCompiler = true; }; curl = pkgsDiet.realCurl; diff --git a/pkgs/stdenv/linux/new.nix b/pkgs/stdenv/linux/new.nix index c3867392b4d..50305dcfe2f 100644 --- a/pkgs/stdenv/linux/new.nix +++ b/pkgs/stdenv/linux/new.nix @@ -65,11 +65,21 @@ rec { {gcc ? staticGCC, glibc, binutils, shell ? ""}: (import ../../build-support/gcc-wrapper) { nativeTools = false; - nativeGlibc = false; + nativeLibc = false; inherit gcc binutils glibc shell; stdenv = stdenvInitial; }; + wrapGCC2 = + {gcc ? staticGCC, glibc, binutils, shell ? ""}: + (import ../../build-support/gcc-wrapper-new) { + nativeTools = false; + nativeLibc = false; + inherit gcc binutils shell; + libc = glibc; + stdenv = stdenvInitial; + }; + # The "fake" standard environment used to build "real" standard # environments. It consists of just the basic statically linked @@ -140,7 +150,7 @@ rec { # statically linked tools. stdenvLinuxBoot2 = removeAttrs (stdenvBootFun { staticGlibc = false; - gcc = wrapGCC {binutils = staticBinutils; glibc = stdenvLinuxGlibc;}; + gcc = wrapGCC2 {binutils = staticBinutils; glibc = stdenvLinuxGlibc;}; extraAttrs = {inherit curl; glibc = stdenvLinuxGlibc;}; }) ["gcc" "binutils"]; @@ -157,7 +167,7 @@ rec { # 5. The other tools (e.g. coreutils) are still static. stdenvLinuxBoot3 = stdenvBootFun { staticGlibc = false; - gcc = wrapGCC { + gcc = wrapGCC2 { # inherit (stdenvLinuxBoot2Pkgs) binutils; binutils = stdenvLinuxBoot2Pkgs.binutils217; glibc = stdenvLinuxGlibc; diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index a94533edfaf..22e223ca6cc 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -10,7 +10,7 @@ genericStdenv { gcc = gccWrapper { name = "gcc-native"; nativeTools = true; - nativeGlibc = true; + nativeLibc = true; nativePrefix = "/usr"; inherit stdenv; }; diff --git a/pkgs/stdenv/nix/default.nix b/pkgs/stdenv/nix/default.nix index 0c9b0c8027a..227cb876a97 100644 --- a/pkgs/stdenv/nix/default.nix +++ b/pkgs/stdenv/nix/default.nix @@ -9,7 +9,7 @@ import ../generic { gcc = import ../../build-support/gcc-wrapper { nativeTools = false; - nativeGlibc = true; + nativeLibc = true; inherit stdenv; binutils = if stdenv.isDarwin then diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 3fe56954ebd..739b149a099 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -95,9 +95,9 @@ rec { NIX_GCC = import ../build-support/gcc-wrapper { inherit stdenv; - glibc = dietlibc; + libc = dietlibc; inherit (gcc) gcc binutils name nativeTools nativePrefix; - nativeGlibc = false; + nativeLibc = false; }; }); isDietLibC = true; @@ -536,7 +536,7 @@ rec { dietgcc = import ../build-support/gcc-wrapper { nativeTools = false; - nativeGlibc = false; + nativeLibc = false; gcc = gcc34; #inherit (stdenv.gcc) binutils glibc; inherit (gcc34) binutils; @@ -555,7 +555,7 @@ rec { g77 = import ../build-support/gcc-wrapper { name = "g77"; nativeTools = false; - nativeGlibc = false; + nativeLibc = false; gcc = import ../development/compilers/gcc-3.3 { inherit fetchurl stdenv noSysDirs; langF77 = true; @@ -586,7 +586,7 @@ rec { gcc40arm = import ../build-support/gcc-cross-wrapper { nativeTools = false; - nativeGlibc = false; + nativeLibc = false; cross = "arm-linux"; gcc = import ../development/compilers/gcc-4.0-cross { inherit fetchurl stdenv noSysDirs; @@ -603,7 +603,7 @@ rec { gcc40mips = import ../build-support/gcc-cross-wrapper { nativeTools = false; - nativeGlibc = false; + nativeLibc = false; cross = "mips-linux"; gcc = gcc40mipsboot; #inherit (stdenv.gcc) glibc; @@ -623,7 +623,7 @@ rec { gcc40sparc = import ../build-support/gcc-cross-wrapper { nativeTools = false; - nativeGlibc = false; + nativeLibc = false; cross = "sparc-linux"; gcc = import ../development/compilers/gcc-4.0-cross { inherit fetchurl stdenv noSysDirs; @@ -722,7 +722,7 @@ rec { gcj = import ../build-support/gcc-wrapper/default2.nix { name = "gcj"; nativeTools = false; - nativeGlibc = false; + nativeLibc = false; gcc = import ../development/compilers/gcc-4.0 { inherit fetchurl stdenv noSysDirs; langJava = true; @@ -786,7 +786,7 @@ rec { wrapGCC = baseGCC: import ../build-support/gcc-wrapper { nativeTools = false; - nativeGlibc = false; + nativeLibc = false; gcc = baseGCC; inherit stdenv binutils glibc; };