-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
ldWrapper tries to call non-existent binary when cross compiling #11834
Comments
I'm not convinced I'm doing things correctly, as |
This is the erroneous line https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/cc-wrapper/default.nix#L160 It seems as though gcc has https://github.com/NixOS/nixpkgs/tree/master/pkgs/build-support/gcc-cross-wrapper but there's nothing similar for clang. |
Sorry, I have no useful input. (I don't use Nix for cross-compilation, but I want to.) |
Here's an example clang cross toolchain I built: with import ../../../nixpkgs {};
let
pkgsCross = import ../../../nixpkgs {
inherit system;
crossSystem = rec {
config = "armv7-unknown-linux-musleabihf";
arch = "arm";
libc = "musl";
gcc = {
arch = "armv7-a";
fpu = "neon";
float = "hard";
};
};
};
libgcc = system.pkgsCross.libgcc.crossDrv;
clang = callPackage ../../../nixpkgs/pkgs/build-support/cc-wrapper {
cc = llvmPackages.clang-unwrapped;
isClang = true;
stdenv = llvmPackages.stdenv;
libc = pkgsCross.muslCross;
extraPackages = [ libgcc libcxx libcxxabi ];
nativeTools = false;
nativeLibc = false;
binutils = pkgsCross.binutilsCross;
};
libcxxStdenv = overrideCC stdenv clang;
in
libcxxStdenv.mkDerivation rec {
name = "bug";
version = "0.0.1";
src = ./.;
CFLAGS = "-B${libgcc}/lib -target armv7-unknown-linux-musl-eabihf";
phases = ["unpackPhase" "buildPhase" "installPhase"];
installPhase = ''
mkdir -p $out/bin
cp hello $out/bin
'';
} You'll also need #16217, #15867, gcc6, this binutils patch (clang is surprisingly unflexible in specifying the linker to use, this commit hasn't landed yet llvm-mirror/clang@635bc7f) and my libgcc hack diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix
index 80b5643..b969ab4 100644
--- a/pkgs/development/tools/misc/binutils/default.nix
+++ b/pkgs/development/tools/misc/binutils/default.nix
@@ -75,7 +75,11 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true;
- postFixup = optionalString (cross == null) "ln -s $out/bin $dev/bin"; # tools needed for development
+ postFixup =
+ if cross == null then
+ "ln -s $out/bin $dev/bin" # tools needed for development
+ else
+ "ln -s $out/bin/${cross.config}-ld $out/bin/ld";
meta = with stdenv.lib; {
description = "Tools for manipulating binaries (linker, assembler, etc.)"; { stdenv, gcc, glibc, cross ? null, gccCrossStageFinal ? null }:
let
arch = "x86_64-unknown-linux-gnu";
path =
if cross == null
then "${gcc.cc}/lib/gcc/${arch}/${gcc.cc.version}"
else "${gccCrossStageFinal.gcc}/lib/gcc/${cross.config}/${gccCrossStageFinal.gcc.version}";
path-libgcc_s =
if cross == null
then "${glibc.out}"
else "${gccCrossStageFinal.gcc}/${cross.config}";
in
stdenv.mkDerivation rec {
name = "libgcc";
buildCommand = ''
mkdir -p "$out/lib"
cp ${path}/libgcc.a $out/lib
cp ${path}/crtbegin.o $out/lib
cp ${path}/crtbeginS.o $out/lib
cp ${path}/crtbeginT.o $out/lib
cp ${path}/crtendS.o $out/lib
cp ${path}/crtend.o $out/lib
cp ${path}/crtfastmath.o $out/lib
cp ${path}/libgcc_eh.a $out/lib
cp ${path-libgcc_s}/lib/libgcc_s.so $out/lib/libgcc_s.so
cp ${path-libgcc_s}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1
'';
} |
@dvc94ch did you look at what we do on darwin to use clang/llvm systemwide? I think we have quite a bit of badly conditioned logic in individual derivations that asks for |
Actually #26007 fixed this |
In an environment with
clang.override {binutils = binutils.override{cross.target = "arm-none-eabi";}
clang-wrapper/bin/ld
tries to callbinutils-arm-none-eabi/bin/ld
when the file is actually located atbinutils-arm-none-eabi/bin/arm-none-eabi-ld
.I'm not entirely sure that I'm going about this the right way, please let me know if there's a better way to cross compile with clang.
To reproduce:
default.nix
main.c
Run
Output:
The text was updated successfully, but these errors were encountered: