Merge pull request #25232 from obsidiansystems/cross-binutils

Cross binutils

Changed files
+119 -71
lib
systems
pkgs
development
compilers
tools
misc
binutils
os-specific
darwin
binutils
cctools
stdenv
top-level
+3
lib/systems/parse.nix
···
solaris = { execFormat = elf; families = { inherit unix; }; };
windows = { execFormat = pe; families = { }; };
} // { # aliases
win32 = kernels.windows;
};
···
solaris = { execFormat = elf; families = { inherit unix; }; };
windows = { execFormat = pe; families = { }; };
} // { # aliases
+
# TODO(@Ericson2314): Handle these Darwin version suffixes more generally.
+
darwin10 = kernels.darwin;
+
darwin14 = kernels.darwin;
win32 = kernels.windows;
};
+3
pkgs/development/compilers/gcc/4.5/default.nix
···
withArch +
withCpu +
withAbi +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
withArch +
withCpu +
withAbi +
+
# Ensure that -print-prog-name is able to find the correct programs.
+
" --with-as=${binutils}/bin/${cross.config}-as" +
+
" --with-ld=${binutils}/bin/${cross.config}-ld" +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
+3 -4
pkgs/development/compilers/gcc/4.8/default.nix
···
withFpu +
withFloat +
withMode +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
(if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot"
else " --with-headers=${libcCross.dev}/include") +
# Ensure that -print-prog-name is able to find the correct programs.
-
(stdenv.lib.optionalString (crossMingw || crossDarwin) (
-
" --with-as=${binutils}/bin/${cross.config}-as" +
-
" --with-ld=${binutils}/bin/${cross.config}-ld"
-
)) +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
···
withFpu +
withFloat +
withMode +
+
# Ensure that -print-prog-name is able to find the correct programs.
+
" --with-as=${binutils}/bin/${cross.config}-as" +
+
" --with-ld=${binutils}/bin/${cross.config}-ld" +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
(if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot"
else " --with-headers=${libcCross.dev}/include") +
# Ensure that -print-prog-name is able to find the correct programs.
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
+3 -5
pkgs/development/compilers/gcc/4.9/default.nix
···
withFpu +
withFloat +
withMode +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
else
(if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot"
else " --with-headers=${libcCross.dev}/include") +
-
# Ensure that -print-prog-name is able to find the correct programs.
-
(stdenv.lib.optionalString (crossMingw || crossDarwin) (
-
" --with-as=${binutils}/bin/${cross.config}-as" +
-
" --with-ld=${binutils}/bin/${cross.config}-ld"
-
)) +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
···
withFpu +
withFloat +
withMode +
+
# Ensure that -print-prog-name is able to find the correct programs.
+
" --with-as=${binutils}/bin/${cross.config}-as" +
+
" --with-ld=${binutils}/bin/${cross.config}-ld" +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
else
(if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot"
else " --with-headers=${libcCross.dev}/include") +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
+3 -5
pkgs/development/compilers/gcc/5/default.nix
···
withFpu +
withFloat +
withMode +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
else
(if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
else " --with-headers=${getDev libcCross}/include") +
-
# Ensure that -print-prog-name is able to find the correct programs.
-
(stdenv.lib.optionalString (crossMingw || crossDarwin) (
-
" --with-as=${binutils}/bin/${cross.config}-as" +
-
" --with-ld=${binutils}/bin/${cross.config}-ld"
-
)) +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
···
withFpu +
withFloat +
withMode +
+
# Ensure that -print-prog-name is able to find the correct programs.
+
" --with-as=${binutils}/bin/${cross.config}-as" +
+
" --with-ld=${binutils}/bin/${cross.config}-ld" +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
else
(if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
else " --with-headers=${getDev libcCross}/include") +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
+3 -5
pkgs/development/compilers/gcc/6/default.nix
···
withFpu +
withFloat +
withMode +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
else
(if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
else " --with-headers=${getDev libcCross}/include") +
-
# Ensure that -print-prog-name is able to find the correct programs.
-
(stdenv.lib.optionalString (crossMingw || crossDarwin) (
-
" --with-as=${binutils}/bin/${cross.config}-as" +
-
" --with-ld=${binutils}/bin/${cross.config}-ld"
-
)) +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
···
withFpu +
withFloat +
withMode +
+
# Ensure that -print-prog-name is able to find the correct programs.
+
" --with-as=${binutils}/bin/${cross.config}-as" +
+
" --with-ld=${binutils}/bin/${cross.config}-ld" +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
else
(if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
else " --with-headers=${getDev libcCross}/include") +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
+3 -4
pkgs/development/compilers/gcc/snapshot/default.nix
···
withFpu +
withFloat +
withMode +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
(if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
else " --with-headers=${getDev libcCross}/include") +
# Ensure that -print-prog-name is able to find the correct programs.
-
(stdenv.lib.optionalString (crossMingw || crossDarwin) (
-
" --with-as=${binutils}/bin/${cross.config}-as" +
-
" --with-ld=${binutils}/bin/${cross.config}-ld"
-
)) +
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
···
withFpu +
withFloat +
withMode +
+
# Ensure that -print-prog-name is able to find the correct programs.
+
" --with-as=${binutils}/bin/${cross.config}-as" +
+
" --with-ld=${binutils}/bin/${cross.config}-ld" +
(if crossMingw && crossStageStatic then
" --with-headers=${libcCross}/include" +
" --with-gcc" +
···
(if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot"
else " --with-headers=${getDev libcCross}/include") +
# Ensure that -print-prog-name is able to find the correct programs.
" --enable-__cxa_atexit" +
" --enable-long-long" +
(if crossMingw then
+3 -2
pkgs/development/tools/misc/binutils/default.nix
···
let inherit (stdenv.lib) optional optionals optionalString; in
stdenv.mkDerivation rec {
-
name = basename + optionalString (cross != null) "-${cross.config}";
src = fetchurl {
url = "mirror://gnu/binutils/${basename}.tar.bz2";
···
./no-plugins.patch
];
outputs = [ "out" ]
++ optional (cross == null && !stdenv.isDarwin) "lib" # problems in Darwin stdenv
++ [ "info" ]
···
configureFlags =
[ "--enable-shared" "--enable-deterministic-archives" "--disable-werror" ]
++ optional (stdenv.system == "mips64el-linux") "--enable-fix-loongson2f-nop"
-
++ optional (cross != null) "--target=${cross.config}"
++ optionals gold [ "--enable-gold" "--enable-plugins" ]
++ optional (stdenv.system == "i686-linux") "--enable-targets=x86_64-linux-gnu";
···
let inherit (stdenv.lib) optional optionals optionalString; in
stdenv.mkDerivation rec {
+
name = optionalString (cross != null) "${cross.config}-" + basename;
src = fetchurl {
url = "mirror://gnu/binutils/${basename}.tar.bz2";
···
./no-plugins.patch
];
+
# TODO: all outputs on all platform
outputs = [ "out" ]
++ optional (cross == null && !stdenv.isDarwin) "lib" # problems in Darwin stdenv
++ [ "info" ]
···
configureFlags =
[ "--enable-shared" "--enable-deterministic-archives" "--disable-werror" ]
++ optional (stdenv.system == "mips64el-linux") "--enable-fix-loongson2f-nop"
+
++ optional (cross != null) "--target=${cross.config}" # TODO: make this unconditional
++ optionals gold [ "--enable-gold" "--enable-plugins" ]
++ optional (stdenv.system == "i686-linux") "--enable-targets=x86_64-linux-gnu";
+19 -5
pkgs/os-specific/darwin/binutils/default.nix
···
-
{ stdenv, binutils-raw, cctools }:
stdenv.mkDerivation {
-
name = "cctools-binutils-darwin";
buildCommand = ''
mkdir -p $out/bin $out/include
-
ln -s ${binutils-raw.out}/bin/c++filt $out/bin/c++filt
# We specifically need:
# - ld: binutils doesn't provide it on darwin
···
# - strip: the binutils one seems to break mach-o files
# - lipo: gcc build assumes it exists
# - nm: the gnu one doesn't understand many new load commands
-
for i in ar ranlib as dsymutil install_name_tool ld strip otool lipo nm strings size; do
ln -sf "${cctools}/bin/$i" "$out/bin/$i"
done
-
for i in ${binutils-raw.dev}/include/*.h; do
ln -s "$i" "$out/include/$(basename $i)"
done
···
+
{ stdenv, binutils-raw, cctools
+
, hostPlatform, targetPlatform
+
}:
+
let
+
prefix = stdenv.lib.optionalString
+
(targetPlatform != hostPlatform)
+
"${targetPlatform.config}-";
+
+
cmds = [
+
"ar" "ranlib" "as" "dsymutil" "install_name_tool"
+
"ld" "strip" "otool" "lipo" "nm" "strings" "size"
+
];
+
in
+
+
# TODO loop over prefixed binaries too
stdenv.mkDerivation {
+
name = "${prefix}cctools-binutils-darwin";
buildCommand = ''
mkdir -p $out/bin $out/include
+
ln -s ${binutils-raw.out}/bin/${prefix}c++filt $out/bin/${prefix}c++filt
# We specifically need:
# - ld: binutils doesn't provide it on darwin
···
# - strip: the binutils one seems to break mach-o files
# - lipo: gcc build assumes it exists
# - nm: the gnu one doesn't understand many new load commands
+
for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: prefix + e) cmds)}; do
ln -sf "${cctools}/bin/$i" "$out/bin/$i"
done
+
for i in ${binutils-raw.dev or binutils-raw.out}/include/*.h; do
ln -s "$i" "$out/include/$(basename $i)"
done
+42 -28
pkgs/os-specific/darwin/cctools/port.nix
···
-
{ stdenv, fetchFromGitHub, autoconf, automake, libtool_2
, llvm, libcxx, libcxxabi, clang, libuuid
-
, libobjc ? null
}:
let
baseParams = rec {
-
name = "cctools-port-${version}";
version = "895";
src = fetchFromGitHub {
···
enableParallelBuilding = true;
-
configureFlags = stdenv.lib.optionals (!stdenv.isDarwin) [ "CXXFLAGS=-I${libcxx}/include/c++/v1" ];
postPatch = ''
sed -i -e 's/addStandardLibraryDirectories = true/addStandardLibraryDirectories = false/' cctools/ld64/src/ld/Options.cpp
···
popd
'';
meta = {
homepage = "http://www.opensource.apple.com/source/cctools/";
description = "Mac OS X Compiler Tools (cross-platform port)";
license = stdenv.lib.licenses.apsl20;
};
};
-
in {
-
native = stdenv.mkDerivation (baseParams // {
-
# A hack for now...
-
postInstall = ''
-
cat >$out/bin/dsymutil << EOF
-
#!${stdenv.shell}
-
EOF
-
chmod +x $out/bin/dsymutil
-
'';
-
});
-
-
cross =
-
{ cross, maloader, makeWrapper, xctoolchain}: stdenv.mkDerivation (baseParams // {
-
configureFlags = baseParams.configureFlags ++ [ "--target=${cross.config}" ];
-
-
postInstall = ''
-
for tool in dyldinfo dwarfdump dsymutil; do
-
${makeWrapper}/bin/makeWrapper "${maloader}/bin/ld-mac" "$out/bin/${cross.config}-$tool" \
-
--add-flags "${xctoolchain}/bin/$tool"
-
ln -s "$out/bin/${cross.config}-$tool" "$out/bin/$tool"
-
done
-
'';
-
});
-
}
···
+
{ stdenv, fetchFromGitHub, makeWrapper, autoconf, automake, libtool_2
, llvm, libcxx, libcxxabi, clang, libuuid
+
, libobjc ? null, maloader ? null, xctoolchain ? null
+
, buildPlatform, hostPlatform, targetPlatform
}:
+
+
let
+
inherit (stdenv.lib.systems.parse) isDarwin;
+
+
prefix = stdenv.lib.optionalString
+
(targetPlatform != hostPlatform)
+
"${targetPlatform.config}-";
+
in
+
+
assert isDarwin targetPlatform.parsed;
+
+
# Non-Darwin alternatives
+
assert (!isDarwin hostPlatform.parsed) -> (maloader != null && xctoolchain != null);
let
baseParams = rec {
+
name = "${prefix}cctools-port-${version}";
version = "895";
src = fetchFromGitHub {
···
enableParallelBuilding = true;
+
configureFlags = stdenv.lib.optionals (!stdenv.isDarwin) [
+
"CXXFLAGS=-I${libcxx}/include/c++/v1"
+
] ++ stdenv.lib.optionals (targetPlatform != buildPlatform) [
+
# TODO make unconditional next hash break
+
"--build=${buildPlatform.config}"
+
"--host=${hostPlatform.config}"
+
"--target=${targetPlatform.config}"
+
];
postPatch = ''
sed -i -e 's/addStandardLibraryDirectories = true/addStandardLibraryDirectories = false/' cctools/ld64/src/ld/Options.cpp
···
popd
'';
+
postInstall =
+
if isDarwin hostPlatform.parsed
+
then ''
+
cat >$out/bin/dsymutil << EOF
+
#!${stdenv.shell}
+
EOF
+
chmod +x $out/bin/dsymutil
+
''
+
else ''
+
for tool in dyldinfo dwarfdump dsymutil; do
+
${makeWrapper}/bin/makeWrapper "${maloader}/bin/ld-mac" "$out/bin/${targetPlatform.config}-$tool" \
+
--add-flags "${xctoolchain}/bin/$tool"
+
ln -s "$out/bin/${targetPlatform.config}-$tool" "$out/bin/$tool"
+
done
+
'';
+
meta = {
homepage = "http://www.opensource.apple.com/source/cctools/";
description = "Mac OS X Compiler Tools (cross-platform port)";
license = stdenv.lib.licenses.apsl20;
};
};
+
in stdenv.mkDerivation baseParams
+3 -3
pkgs/stdenv/linux/make-bootstrap-tools-cross.nix
···
build =
-
pkgs.buildPackages.stdenv.mkDerivation {
name = "stdenv-bootstrap-tools-cross";
crossConfig = pkgs.hostPlatform.config;
-
buildInputs = [
pkgs.buildPackages.nukeReferences
pkgs.buildPackages.cpio
pkgs.buildPackages.binutils
···
allowedReferences = [];
};
-
dist = pkgs.buildPackages.stdenv.mkDerivation {
name = "stdenv-bootstrap-tools-cross";
buildCommand = ''
···
build =
+
pkgs.stdenv.mkDerivation {
name = "stdenv-bootstrap-tools-cross";
crossConfig = pkgs.hostPlatform.config;
+
nativeBuildInputs = [
pkgs.buildPackages.nukeReferences
pkgs.buildPackages.cpio
pkgs.buildPackages.binutils
···
allowedReferences = [];
};
+
dist = pkgs.stdenv.mkDerivation {
name = "stdenv-bootstrap-tools-cross";
buildCommand = ''
+7 -8
pkgs/top-level/all-packages.nix
···
bin_replace_string = callPackage ../development/tools/misc/bin_replace_string { };
-
binutils = if stdenv.isDarwin then darwin.binutils else binutils-raw;
binutils-raw = callPackage ../development/tools/misc/binutils {
# FHS sys dirs presumably only have stuff for the build platform
···
darwin = let
apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { };
in apple-source-releases // rec {
-
cctools_cross = callPackage (forcedNativePackages.callPackage ../os-specific/darwin/cctools/port.nix {}).cross {
-
cross = assert targetPlatform != buildPlatform; targetPlatform;
inherit maloader;
xctoolchain = xcode.toolchain;
};
-
-
cctools = (callPackage ../os-specific/darwin/cctools/port.nix {
-
inherit libobjc;
-
stdenv = if stdenv.isDarwin then stdenv else libcxxStdenv;
-
}).native;
cf-private = callPackage ../os-specific/darwin/cf-private {
inherit (apple-source-releases) CF;
···
bin_replace_string = callPackage ../development/tools/misc/bin_replace_string { };
+
binutils =
+
if lib.systems.parse.isDarwin targetPlatform.parsed
+
then darwin.binutils
+
else binutils-raw;
binutils-raw = callPackage ../development/tools/misc/binutils {
# FHS sys dirs presumably only have stuff for the build platform
···
darwin = let
apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { };
in apple-source-releases // rec {
+
cctools = callPackage ../os-specific/darwin/cctools/port.nix {
+
inherit libobjc;
+
stdenv = if stdenv.isDarwin then stdenv else libcxxStdenv;
inherit maloader;
xctoolchain = xcode.toolchain;
};
cf-private = callPackage ../os-specific/darwin/cf-private {
inherit (apple-source-releases) CF;
+24 -2
pkgs/top-level/release-cross.nix
···
-
{ # The platforms for which we build Nixpkgs.
-
supportedSystems ? [ builtins.currentSystem ]
, # Strip most of attributes when evaluating to spare memory usage
scrubJobs ? true
}:
···
guile = nativePlatforms;
};
/* Test some cross builds to the Sheevaplug */
crossSheevaplugLinux = let
···
+
/* This file defines some basic smoke tests for cross compilation.
+
*/
+
+
{ # The platforms *from* which we cross compile.
+
supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
, # Strip most of attributes when evaluating to spare memory usage
scrubJobs ? true
}:
···
guile = nativePlatforms;
};
+
darwinToAarch64 = let
+
crossSystem = {
+
config = "aarch64-apple-darwin14";
+
arch = "arm64";
+
libc = "libSystem";
+
};
+
in mapTestOnCross crossSystem {
+
buildPackages.binutils = darwin;
+
};
+
+
darwinToArm = let
+
crossSystem = {
+
config = "arm-apple-darwin10";
+
arch = "armv7-a";
+
libc = "libSystem";
+
};
+
in mapTestOnCross crossSystem {
+
buildPackages.binutils = darwin;
+
};
/* Test some cross builds to the Sheevaplug */
crossSheevaplugLinux = let