Merge pull request #119625 from sternenseemann/binutils-force-prefix

binutils-unwrapped, gcc, gdb: force targetPrefix if cross compiling
This commit is contained in:
John Ericson 2021-04-16 17:36:20 -04:00 committed by GitHub
commit e87d88d86c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 19 deletions

View File

@ -186,8 +186,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -196,8 +196,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -209,8 +209,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -232,8 +232,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -197,8 +197,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -182,8 +182,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -199,8 +199,7 @@ stdenv.mkDerivation ({
dontDisableStatic = true;
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (targetPlatform != hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags = import ../common/configure-flags.nix {
inherit

View File

@ -44,6 +44,9 @@ let
crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
crossDarwin = targetPlatform != hostPlatform && targetPlatform.libc == "libSystem";
targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
"${stdenv.targetPlatform.config}-";
crossConfigureFlags =
# Ensure that -print-prog-name is able to find the correct programs.
[
@ -112,6 +115,18 @@ let
# Basic configuration
++ [
# Force target prefix. The behavior if `--target` and `--host`
# are specified is inconsistent: Sometimes specifying `--target`
# always causes a prefix to be generated, sometimes it's only
# added if the `--host` and `--target` differ. This means that
# sometimes there may be a prefix even though nixpkgs doesn't
# expect one and sometimes there may be none even though nixpkgs
# expects one (since not all information is serialized into the
# config attribute). The easiest way out of these problems is to
# always set the program prefix, so gcc will conform to our
# expectations.
"--program-prefix=${targetPrefix}"
(lib.enableFeature enableLTO "lto")
"--disable-libstdcxx-pch"
"--without-included-gettext"

View File

@ -107,8 +107,7 @@ stdenv.mkDerivation {
hardeningDisable = [ "format" "pie" ];
# TODO(@Ericson2314): Always pass "--target" and always targetPrefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
configureFlags =
(if enableShared then [ "--enable-shared" "--disable-static" ]
@ -126,7 +125,19 @@ stdenv.mkDerivation {
# RUNPATH instead of RPATH on binaries. This is important because
# RUNPATH can be overriden using LD_LIBRARY_PATH at runtime.
"--enable-new-dtags"
] ++ lib.optionals gold [ "--enable-gold" "--enable-plugins" ];
# force target prefix. Some versions of binutils will make it empty
# if `--host` and `--target` are too close, even if Nixpkgs thinks
# the platforms are different (e.g. because not all the info makes
# the `config`). Other versions of binutils will always prefix if
# `--target` is passed, even if `--host` and `--target` are the same.
# The easiest thing for us to do is not leave it to chance, and force
# the program prefix to be what we want it to be.
"--program-prefix=${targetPrefix}"
] ++ lib.optionals gold [
"--enable-gold"
"--enable-plugins"
];
doCheck = false; # fails

View File

@ -61,8 +61,7 @@ stdenv.mkDerivation rec {
NIX_CFLAGS_COMPILE = "-Wno-format-nonliteral";
# TODO(@Ericson2314): Always pass "--target" and always prefix.
configurePlatforms = [ "build" "host" ] ++ lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target";
configurePlatforms = [ "build" "host" "target" ];
# GDB have to be built out of tree.
preConfigure = ''
@ -72,6 +71,13 @@ stdenv.mkDerivation rec {
configureScript = "../configure";
configureFlags = with lib; [
# Set the program prefix to the current targetPrefix.
# This ensures that the prefix always conforms to
# nixpkgs' expectations instead of relying on the build
# system which only receives `config` which is merely a
# subset of the platform description.
"--program-prefix=${targetPrefix}"
"--enable-targets=all" "--enable-64-bit-bfd"
"--disable-install-libbfd"
"--disable-shared" "--enable-static"