Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtool: fix /usr/bin/file impurity affecting cross-compilation #166722

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkgs/development/libraries/gmp/6.x.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, cxx ? !stdenv.hostPlatform.useAndroidPrebuilt && !stdenv.hostPlatform.isWasm
, buildPackages
, withStatic ? stdenv.hostPlatform.isStatic
, autoreconfHook
}:

# Note: this package is used for bootstrapping fetchurl, and thus
Expand Down Expand Up @@ -29,7 +30,7 @@ let self = stdenv.mkDerivation rec {
passthru.static = self.out;

depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ m4 ];
nativeBuildInputs = [ m4 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ autoreconfHook ];

configureFlags = [
"--with-pic"
Expand Down
3 changes: 3 additions & 0 deletions pkgs/development/libraries/isl/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
}:

{ lib, stdenv, fetchurl, gmp
, autoreconfHook
}:

stdenv.mkDerivation {
Expand All @@ -17,6 +18,8 @@ stdenv.mkDerivation {

inherit patches;

nativeBuildInputs = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ autoreconfHook ];

buildInputs = [ gmp ];

inherit configureFlags;
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/libraries/libmpc/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib, stdenv, fetchurl
, gmp, mpfr
, fixPathToUsrBinFileInConfigureScript
}:

# Note: this package is used for bootstrapping fetchurl, and thus
Expand All @@ -16,7 +17,7 @@ stdenv.mkDerivation rec {
sha256 = "0n846hqfqvmsmim7qdlms0qr86f1hck19p12nq3g3z2x74n3sl0p";
};

buildInputs = [ gmp mpfr ];
buildInputs = [ gmp mpfr ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ fixPathToUsrBinFileInConfigureScript ];

doCheck = true; # not cross;

Expand Down
5 changes: 4 additions & 1 deletion pkgs/development/libraries/mpfr/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenv, fetchurl, gmp }:
{ lib, stdenv, fetchurl, gmp, fixPathToUsrBinFileInConfigureScript }:

# Note: this package is used for bootstrapping fetchurl, and thus
# cannot use fetchpatch! All mutable patches (generated by GitHub or
Expand All @@ -22,6 +22,9 @@ stdenv.mkDerivation rec {
# mpfr.h requires gmp.h
propagatedBuildInputs = [ gmp ];

# autoreconf with latest autotools will break mpfr
nativeBuildInputs = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ fixPathToUsrBinFileInConfigureScript ];

configureFlags =
lib.optional stdenv.hostPlatform.isSunOS "--disable-thread-safe" ++
lib.optional stdenv.hostPlatform.is64bit "--with-pic";
Expand Down
3 changes: 3 additions & 0 deletions pkgs/development/libraries/pcre/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib, stdenv, fetchurl
, pcre, windows ? null
, autoreconfHook
, variant ? null
}:

Expand All @@ -20,6 +21,8 @@ stdenv.mkDerivation rec {

outputs = [ "bin" "dev" "out" "doc" "man" ];

nativeBuildInputs = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ autoreconfHook ];

# Disable jit on Apple Silicon, https://github.com/zherczeg/sljit/issues/51
configureFlags = optional (!stdenv.hostPlatform.isRiscV && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) "--enable-jit" ++ [
"--enable-unicode-properties"
Expand Down
20 changes: 20 additions & 0 deletions pkgs/development/tools/misc/libtool/libtool2.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib, stdenv, fetchurl, fetchpatch, autoconf, automake, m4, perl, help2man
, buildPackages
}:

# Note: this package is used for bootstrapping fetchurl, and thus
Expand Down Expand Up @@ -36,6 +37,25 @@ stdenv.mkDerivation rec {
popd
'';

# When detecting the `LD` (linker) command and flags for cross
# compiling, libtool.m4 expects to be able to use "/usr/bin/file" to
# detect host details like ABI and linker flags. Unfortunately this
# detection code hardwires the path to /usr/bin/file, which is
# inaccessible for sandboxed builds. This causes the `LD` flag to
# be detected incorrectly when cross-compiling to the following
# hostPlatforms: {x86_64, powerpc, s390, sparc, mips64*}-linux,
# x86_64-kfreebsd, *-solaris, *-irix, and *-hpux.
#
# This substitution is performed only for cross-compilation in order
# to avoid a mass-rebuild. A separate PR will be submitted to
# staging, not to be merged until after nixpkgs-22.05 branch-off,
# which deletes this conditional and this comment.
#
preBuild = if stdenv.buildPlatform == stdenv.targetPlatform
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate a review of this line in particular. I think of libtool as being a "compiler-like" package that has a targetPlatform but I'm not sure if nixpkgs thinks of it this way. Please let me know if I should change this from build==target to build==host.

then null
else ''substituteInPlace m4/libtool.m4 \
--replace "/usr/bin/file" "${buildPackages.file}/bin/file"'';

nativeBuildInputs = [ perl help2man m4 ] ++ [ autoconf automake ];
propagatedBuildInputs = [ m4 ];

Expand Down
11 changes: 11 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ with pkgs;
}
'');

# libtool.m4 invokes "/usr/bin/file", and is vendored into many ./configure scripts
fixPathToUsrBinFileInConfigureScript = makeSetupHook {}
(writeScript "fix-path-to-user-bin-file.sh" ''
postUnpackHooks+=(_fixPathToUserBinFile)
_fixPathToUserBinFile() {
if [ -e $sourceRoot/configure ]; then
substituteInPlace $sourceRoot/configure --replace /usr/bin/file ${buildPackages.file}/bin/file
fi
}
'');

addOpenGLRunpath = callPackage ../build-support/add-opengl-runpath { };

quickemu = callPackage ../development/quickemu { };
Expand Down