3
0
Fork 0
forked from mirrors/nixpkgs

ghc binary: Fix interpreter than patch RPATH

The newer to-be-added binaries have relative RPATHs that we'll break if
we try to `patchelf` before installation. We instead us LD_LOAD_LIBRARY
during the installation, which avoids needing to change the RPATH
temporarily.
This commit is contained in:
John Ericson 2017-09-22 14:29:04 -04:00 committed by Domen Kožar
parent 26a46295eb
commit 150255e318
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
3 changed files with 95 additions and 54 deletions

View file

@ -24,6 +24,10 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ perl ];
# Cannot patchelf beforehand due to relative RPATHs that anticipate
# the final install location/
LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath [ libedit ncurses5 gmp ];
postUnpack =
# Strip is harmful, see also below. It's important that this happens
# first. The GHC Cabal build system makes use of strip by default and
@ -40,9 +44,9 @@ stdenv.mkDerivation rec {
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
stdenv.lib.optionalString stdenv.hostPlatform.isLinux ''
find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${stdenv.lib.makeLibraryPath [ libedit ncurses5 gmp ]}" {} \;
find . -type f -perm -0100 -exec patchelf \
--interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
for prog in ld ar gcc strip ranlib; do
find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
done
@ -67,6 +71,13 @@ stdenv.mkDerivation rec {
sed -i "s@^\(.*pkgName = PackageName \"rts\".*\libraryDirs = \\[\)\(.*\)@\\1\"${gmp.out}/lib\",\2@" $out/lib/ghc-${version}/package.conf
'';
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
preFixup = stdenv.lib.optionalString stdenv.isLinux ''
find "$out" -type f -executable \
-exec patchelf --set-rpath "${LD_LIBRARY_PATH}" {} \;
'';
doInstallCheck = true;
installCheckPhase = ''
# Sanity check, can ghc create executables?

View file

@ -3,6 +3,16 @@
, ncurses5, gmp, libiconv
}:
let
libPath = stdenv.lib.makeLibraryPath ([
ncurses5 gmp
] ++ stdenv.lib.optional (stdenv.hostPlatform.isDarwin) libiconv);
libEnvVar = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin "DY"
+ "LD_LIBRARY_PATH";
in
stdenv.mkDerivation rec {
version = "7.0.4";
@ -30,6 +40,10 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ perl ];
# Cannot patchelf beforehand due to relative RPATHs that anticipate
# the final install location/
${libEnvVar} = libPath;
postUnpack =
# GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
# during linking
@ -57,34 +71,18 @@ stdenv.mkDerivation rec {
find . -name base.buildinfo \
-exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
'' +
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
# Rename needed libraries and binaries, fix interpreter
stdenv.lib.optionalString stdenv.isLinux ''
find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${stdenv.lib.makeLibraryPath [ ncurses5 gmp ]}" {} \;
find . -type f -perm -0100 -exec patchelf \
--interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
paxmark m ./ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
sed -i "s|/usr/bin/gcc|gcc\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
for prog in ld ar gcc strip ranlib; do
find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
done
'' + stdenv.lib.optionalString stdenv.isDarwin ''
# not enough room in the object files for the full path to libiconv :(
fix () {
install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
}
ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/ghc-pwd/dist/build/tmp
ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/hpc/dist/build/tmp
ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/ghc/stage2/build/tmp
for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
fix $(find . -type f -name $file)
done
for file in $(find . -name setup-config); do
substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
done
'';
configurePlatforms = [ ];
@ -101,6 +99,29 @@ stdenv.mkDerivation rec {
# calls install-strip ...
dontBuild = true;
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
preFixup = stdenv.lib.optionalString stdenv.isLinux ''
find "$out" -type f -executable \
-exec patchelf --set-rpath "${libPath}" {} \;
'' + stdenv.lib.optionalString stdenv.isDarwin ''
# not enough room in the object files for the full path to libiconv :(
ln -s ${libiconv}/lib/libiconv.dylib $out/bin
ln -s ${libiconv}/lib/libiconv.dylib $out/lib/ghc-${version}/libiconv.dylib
fix () {
install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
}
for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
fix $(find "$out" -type f -name $file)
done
for file in $(find "$out" -name setup-config); do
substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
done
'';
doInstallCheck = true;
installCheckPhase = ''
# Sanity check, can ghc create executables?

View file

@ -1,8 +1,18 @@
{ stdenv
, fetchurl, perl, makeWrapper
, fetchurl, perl
, ncurses5, gmp, libiconv
}:
let
libPath = stdenv.lib.makeLibraryPath ([
ncurses5 gmp
] ++ stdenv.lib.optional (stdenv.hostPlatform.isDarwin) libiconv);
libEnvVar = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin "DY"
+ "LD_LIBRARY_PATH";
in
stdenv.mkDerivation rec {
version = "7.4.2";
@ -30,6 +40,10 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ perl ];
# Cannot patchelf beforehand due to relative RPATHs that anticipate
# the final install location/
${libEnvVar} = libPath;
postUnpack =
# GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
# during linking
@ -57,14 +71,11 @@ stdenv.mkDerivation rec {
find . -name base.buildinfo \
-exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
'' +
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
# Rename needed libraries and binaries, fix interpreter
stdenv.lib.optionalString stdenv.isLinux ''
mkdir -p "$out/lib"
ln -sv "${ncurses5.out}/lib/libncurses.so" "$out/lib/libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5"
find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${stdenv.lib.makeLibraryPath [ "$out" gmp ]}" {} \;
find . -type f -perm -0100 -exec patchelf \
--replace-needed libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5 libncurses.so \
--interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
paxmark m ./ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
@ -73,23 +84,6 @@ stdenv.mkDerivation rec {
for prog in ld ar gcc strip ranlib; do
find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
done
'' + stdenv.lib.optionalString stdenv.isDarwin ''
# not enough room in the object files for the full path to libiconv :(
fix () {
install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
}
ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/ghc-pwd/dist-install/build/tmp
ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/utils/hpc/dist-install/build/tmp
ln -s ${libiconv}/lib/libiconv.dylib ghc-${version}/ghc/stage2/build/tmp
for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
fix $(find . -type f -name $file)
done
for file in $(find . -name setup-config); do
substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
done
'';
configurePlatforms = [ ];
@ -106,12 +100,27 @@ stdenv.mkDerivation rec {
# calls install-strip ...
dontBuild = true;
preInstall = stdenv.lib.optionalString stdenv.isDarwin ''
mkdir -p $out/lib/ghc-${version}
mkdir -p $out/bin
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
preFixup = stdenv.lib.optionalString stdenv.isLinux ''
find "$out" -type f -executable \
-exec patchelf --set-rpath "${libPath}" {} \;
'' + stdenv.lib.optionalString stdenv.isDarwin ''
# not enough room in the object files for the full path to libiconv :(
ln -s ${libiconv}/lib/libiconv.dylib $out/bin
ln -s ${libiconv}/lib/libiconv.dylib $out/lib/ghc-${version}/libiconv.dylib
ln -s ${libiconv}/lib/libiconv.dylib utils/ghc-cabal/dist-install/build/tmp
fix () {
install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
}
for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
fix $(find "$out" -type f -name $file)
done
for file in $(find "$out" -name setup-config); do
substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
done
'';
doInstallCheck = true;