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

* Ensure that when building gcc, libstdc++ is linked against the libgcc of the gcc being built, not the gcc building it. * Only include a directory in the rpath of an executable/library if it is actually used. Before, the `/lib' directory of every build input was added to the rpath, causing many unnecessary retained dependencies. For instance, Perl has a `/lib' directory, but most applications whose build process uses Perl don't actually link against Perl. (Also added a test for this.) * After building glibc, remove glibcbug, to prevent a retained dependency on gcc. * Add a newline after `building X' in GNU Make.

svn path=/nixpkgs/trunk/; revision=911

+235 -47
+2 -28
pkgs/TODO
··· 8 8 9 9 * Inform freedesktop people that Xaw requires Xpm. 10 10 11 - * Only add --rpath FOO/lib if FOO/lib is actually used, otherwise we 12 - get lots of unneccesarily retained dependencies. 13 - 14 - * After building gcc, filter out this sillyness in .../lib/libsupc++.la and .../lib/libstdc++.la: 15 - 16 - /nix/store/fd3dba2a24f0242af8ea7e896380be7e-gcc-3.3.3/lib/libsupc++.la:dependency_libs=' 17 - -L/tmp/nix-26124-33/build/i686-pc-linux-gnu/libstdc++-v3/src 18 - -L/tmp/nix-26124-33/build/i686-pc-linux-gnu/libstdc++-v3/src/.libs -lm 19 - -L/tmp/nix-26124-33/build/gcc 20 - -L/nix/store/e173bb830ba5f727ae63e0673d929bc7-gcc-3.3.3/bin 21 - -L/nix/store/23ef1e01b61105fee5ef8b47faf30675-glibc-2.3.2/lib 22 - -L/nix/store/6d3bf84aeb18d6d92a25ce9692b0f4d2-gcc-3.3.3/lib -lgcc_s 23 - -lc -lgcc_s' 24 - 25 - /nix/store/fd3dba2a24f0242af8ea7e896380be7e-gcc-3.3.3/lib/libstdc++.la:dependency_libs=' 26 - -L/tmp/nix-26124-33/build/i686-pc-linux-gnu/libstdc++-v3/src 27 - -L/tmp/nix-26124-33/build/i686-pc-linux-gnu/libstdc++-v3/src/.libs -lm 28 - -lm -lm -L/tmp/nix-26124-33/build/gcc 29 - -L/nix/store/e173bb830ba5f727ae63e0673d929bc7-gcc-3.3.3/bin 30 - -L/nix/store/23ef1e01b61105fee5ef8b47faf30675-glibc-2.3.2/lib 31 - -L/nix/store/6d3bf84aeb18d6d92a25ce9692b0f4d2-gcc-3.3.3/lib -lgcc_s 32 - -lc -lgcc_s -lm -lgcc_s -lc -lgcc_s' 33 - 34 - in particular references to /tmp/nix... and to /nix/store/...- 35 - 36 - i.e., basically all -L... switches 37 - 38 - this causes lots of unneccesarily retained dependencies 11 + * After building gcc, filter out references to /tmp/nix... in 12 + .../lib/libsupc++.la and .../lib/libstdc++.la
+2 -2
pkgs/build-support/gcc-wrapper/builder.sh
··· 10 10 # /usr/lib. The real solution is of course to prevent those paths 11 11 # from being used by gcc in the first place. 12 12 cflagsCompile="$cflagsCompile -B$glibc/lib -isystem $glibc/include" 13 - ldflags="$ldflags -L$glibc/lib -rpath $glibc/lib -dynamic-linker $glibc/lib/ld-linux.so.2" 13 + ldflags="$ldflags -L$glibc/lib -dynamic-linker $glibc/lib/ld-linux.so.2" 14 14 fi 15 15 16 16 if test -n "$nativeTools"; then 17 17 gccPath="$nativePrefix/bin" 18 18 ldPath="$nativePrefix/bin" 19 19 else 20 - ldflags="$ldflags -L$gcc/lib -rpath $gcc/lib" 20 + ldflags="$ldflags -L$gcc/lib" 21 21 gccPath="$gcc/bin" 22 22 ldPath="$binutils/bin" 23 23 fi
+78
pkgs/build-support/gcc-wrapper/ld-wrapper.sh
··· 47 47 extra=(${extra[@]} $NIX_LDFLAGS) 48 48 fi 49 49 50 + 51 + # Add all used dynamic libraries to the rpath. 52 + if test "$NIX_DONT_SET_RPATH" != "1"; then 53 + 54 + # First, find all -L... switches. 55 + allParams=("${params[@]}" ${extra[@]}) 56 + libPath="" 57 + addToLibPath() { 58 + local path="$1" 59 + if test "${path:0:1}" != "/"; then return 0; fi 60 + case "$path" in 61 + *..*|*./*|*/.*|*//*) 62 + local path2 63 + if path2=$(readlink -f "$path"); then 64 + path="$path2" 65 + fi 66 + ;; 67 + esac 68 + case $libPath in 69 + *\ $path\ *) return 0 ;; 70 + esac 71 + libPath="$libPath $path " 72 + } 73 + n=0 74 + while test $n -lt ${#allParams[*]}; do 75 + p=${allParams[n]} 76 + p2=${allParams[$((n+1))]} 77 + if test "${p:0:3}" = "-L/"; then 78 + addToLibPath ${p:2} 79 + elif test "$p" = "-L"; then 80 + addToLibPath ${p2} 81 + n=$((n + 1)) 82 + fi 83 + n=$((n + 1)) 84 + done 85 + 86 + # Second, for each -l... switch, find the directory containing the 87 + # library and add it to the rpath. 88 + rpath="" 89 + addToRPath() { 90 + # If the path is not in the store, don't add it to the rpath. 91 + # This typically happens for libraries in /tmp that are later 92 + # copied to $out/lib. If not, we're screwed. 93 + if test "${1:0:${#NIX_STORE}}" != "$NIX_STORE"; then return 0; fi 94 + case $rpath in 95 + *\ $1\ *) return 0 ;; 96 + esac 97 + rpath="$rpath $1 " 98 + } 99 + findLib() { 100 + for i in $libPath; do 101 + if test -f $i/lib$1.so; then 102 + addToRPath $i 103 + fi 104 + done 105 + } 106 + n=0 107 + while test $n -lt ${#allParams[*]}; do 108 + p=${allParams[n]} 109 + p2=${allParams[$((n+1))]} 110 + if test "${p:0:2}" = "-l"; then 111 + findLib ${p:2} 112 + elif test "$p" = "-l"; then 113 + # I haven't seen `-l foo', but you never know... 114 + findLib ${p2} 115 + n=$((n + 1)) 116 + fi 117 + n=$((n + 1)) 118 + done 119 + 120 + # Finally, add `-rpath' switches. 121 + for i in $rpath; do 122 + extra=(${extra[@]} -rpath $i) 123 + done 124 + 125 + fi 126 + 127 + 50 128 # Optionally print debug info. 51 129 if test "$NIX_DEBUG" = "1"; then 52 130 echo "original flags to @ld@:" >&2
+1 -1
pkgs/build-support/gcc-wrapper/setup-hook.sh
··· 4 4 fi 5 5 6 6 if test -d $1/lib; then 7 - export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib -rpath $1/lib" 7 + export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib" 8 8 fi 9 9 } 10 10
+24 -7
pkgs/development/compilers/gcc/builder.sh
··· 40 40 if test "$noSysDirs" = "1"; then 41 41 # Patch some of the makefiles to force linking against our own 42 42 # glibc. 43 - . $NIX_GCC/nix-support/add-flags # add glibc/gcc flags 44 - extraflags="-Wl,-s $NIX_CFLAGS_COMPILE $NIX_CFLAGS_LINK" 45 - for i in $NIX_LDFLAGS; do 46 - extraflags="$extraflags -Wl,$i" 47 - done 43 + if test -e $NIX_GCC/nix-support/orig-glibc; then 44 + glibc=$(cat $NIX_GCC/nix-support/orig-glibc) 45 + # Ugh. Copied from gcc-wrapper/builder.sh. We can't just 46 + # source in $NIX_GCC/nix-support/add-flags, since that 47 + # would cause *this* GCC to be linked against the 48 + # *previous* GCC. Need some more modularity there. 49 + extraFlags="-Wl,-s -B$glibc/lib -isystem $glibc/include \ 50 + -L$glibc/lib -Wl,-dynamic-linker -Wl,$glibc/lib/ld-linux.so.2" 51 + 52 + # Oh, what a hack. I should be shot for this. 53 + # In stage 1, we should link against the previous GCC, but 54 + # not afterwards. Otherwise we retain a dependency. 55 + # However, ld-wrapper, which adds the linker flags for the 56 + # previous GCC, is also used in stage 2/3. We can prevent 57 + # it from adding them by NIX_GLIBC_FLAGS_SET, but then 58 + # gcc-wrapper will also not add them, thereby causing 59 + # stage 1 to fail. So we use a trick to only set the 60 + # flags in gcc-wrapper. 61 + hook=$(pwd)/ld-wrapper-hook 62 + echo "NIX_GLIBC_FLAGS_SET=1" > $hook 63 + export NIX_LD_WRAPPER_START_HOOK=$hook 64 + fi 48 65 49 66 mf=Makefile 50 67 sed \ 51 - -e "s^FLAGS_FOR_TARGET =\(.*\)^FLAGS_FOR_TARGET = \1 $extraflags^" \ 68 + -e "s^FLAGS_FOR_TARGET =\(.*\)^FLAGS_FOR_TARGET = \1 $extraFlags^" \ 52 69 < $mf > $mf.tmp 53 70 mv $mf.tmp $mf 54 71 55 72 mf=gcc/Makefile 56 73 sed \ 57 - -e "s^X_CFLAGS =\(.*\)^X_CFLAGS = \1 $extraflags^" \ 74 + -e "s^X_CFLAGS =\(.*\)^X_CFLAGS = \1 $extraFlags^" \ 58 75 < $mf > $mf.tmp 59 76 mv $mf.tmp $mf 60 77
+2 -7
pkgs/development/libraries/glibc/builder.sh
··· 4 4 . $stdenv/setup 5 5 6 6 7 - # !!! Toss the linker flags. Any sort of rpath is fatal. 8 - # This probably will cause a failure when building in a pure Nix 9 - # environment. 10 - export NIX_LDFLAGS= 11 - export NIX_GLIBC_FLAGS_SET=1 12 - 13 - 14 7 postUnpack() { 15 8 cd $sourceRoot 16 9 unpackFile $linuxthreadsSrc ··· 35 28 make localedata/install-locales 36 29 rm $out/etc/ld.so.cache 37 30 (cd $out/include && ln -s $kernelHeaders/include/* .) || exit 1 31 + # `glibcbug' causes a retained dependency on the C compiler. 32 + rm $out/bin/glibcbug 38 33 } 39 34 40 35 postInstall=postInstall
+2 -2
pkgs/development/tools/build-managers/gnumake/log.diff
··· 108 108 + extern int logNestingStderr; 109 109 diff -rc make-3.80-orig/remake.c make-3.80/remake.c 110 110 *** make-3.80-orig/remake.c 2002-08-08 02:11:19.000000000 +0200 111 - --- make-3.80/remake.c 2004-04-02 17:43:00.000000000 +0200 111 + --- make-3.80/remake.c 2004-04-04 23:10:19.000000000 +0200 112 112 *************** 113 113 *** 1049,1055 **** 114 114 --- 1049,1059 ---- 115 115 /* The normal case: start some commands. */ 116 116 if (!touch_flag || file->cmds->any_recurse) 117 117 { 118 - + fprintf(stderr, "\e[pbuilding %s", file->name); 118 + + fprintf(stderr, "\e[pbuilding %s\n", file->name); 119 119 + logNestingStderr++; 120 120 execute_file_commands (file); 121 121 + fprintf(stderr, "\e[q");
+79
pkgs/test/rpath/builder.sh
··· 1 + export NIX_DEBUG=1 2 + 3 + . $stdenv/setup 4 + 5 + mkdir $out 6 + mkdir $out/bin 7 + 8 + 9 + # 1: link statically against glibc. 10 + res=$out/bin/hello1 11 + gcc -static $src/hello1.c -o $res 12 + 13 + case $(ldd $res) in 14 + *"not a dynamic executable"*) 15 + ;; 16 + *) 17 + echo "$res not statically linked!" 18 + exit 1 19 + esac 20 + 21 + 22 + # 2: link dynamically against glibc. 23 + res=$out/bin/hello2 24 + gcc $src/hello1.c -o $res 25 + 26 + case $(ldd $res) in 27 + */store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*) 28 + ;; 29 + *) 30 + echo "$res not dynamically linked / bad rpath!" 31 + exit 1 32 + ;; 33 + esac 34 + 35 + 36 + # 3: link C++ dynamically against glibc / libstdc++. 37 + res=$out/bin/hello3 38 + g++ $src/hello2.cc -o $res 39 + 40 + case $(ldd $res) in 41 + */store/*gcc*/lib/*libstdc++*/store/*glibc*/lib/libm*/store/*gcc*/lib/libgcc_s*/store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*) 42 + ;; 43 + *) 44 + echo "$res not dynamically linked / bad rpath!" 45 + exit 1 46 + ;; 47 + esac 48 + 49 + 50 + # 4: build dynamic library locally, link against it, copy it. 51 + res=$out/bin/hello4 52 + mkdir bla 53 + gcc -shared $src/text.c -o bla/libtext.so 54 + gcc $src/hello3.c -o $res -L$(pwd)/bla -ltext 55 + mkdir $out/lib 56 + 57 + case $(ldd $res) in 58 + */tmp*) 59 + echo "$res depends on file in /tmp!" 60 + exit 1 61 + ;; 62 + esac 63 + 64 + cp bla/libtext.so $out/lib 65 + 66 + case $(ldd $res) in 67 + */store/*glibc*/lib/libc.so*/store/*glibc*/lib/ld-linux.so*) 68 + ;; 69 + *) 70 + echo "$res not dynamically linked / bad rpath!" 71 + exit 1 72 + ;; 73 + esac 74 + 75 + 76 + # Run the programs we just made. 77 + for i in $out/bin/*; do 78 + $i 79 + done
+18
pkgs/test/rpath/default.nix
··· 1 + let { 2 + system = "i686-linux"; 3 + 4 + stdenvs = (import ../../system/stdenvs.nix) { 5 + inherit system; 6 + allPackages = import ../../system/all-packages-generic.nix; 7 + }; 8 + 9 + stdenv = stdenvs.stdenvLinuxBoot2; 10 + 11 + test = stdenv.mkDerivation { 12 + name = "rpath-test"; 13 + builder = ./builder.sh; 14 + src = ./src; 15 + }; 16 + 17 + body = test; 18 + }
+7
pkgs/test/rpath/src/hello1.c
··· 1 + #include <stdio.h> 2 + 3 + int main(int argc, char * * argv) 4 + { 5 + printf("Hello World!\n"); 6 + return 0; 7 + }
+7
pkgs/test/rpath/src/hello2.cc
··· 1 + #include <iostream> 2 + 3 + int main(int argc, char * * argv) 4 + { 5 + std::cout << "Hello World!\n"; 6 + return 0; 7 + }
+9
pkgs/test/rpath/src/hello3.c
··· 1 + #include <stdio.h> 2 + 3 + char * text(); 4 + 5 + int main(int argc, char * * argv) 6 + { 7 + printf(text()); 8 + return 0; 9 + }
+4
pkgs/test/rpath/src/text.c
··· 1 + char * text() 2 + { 3 + return "Hello World!\n"; 4 + }