Prebuilt compiler binaries can't link

I’m working on resolving the “gnat problem” as I call it, where a full Ada development environment can’t be installed because Gnat can’t be built. To do this, I’ve replaced the gnatboot package with this:

{ stdenv, lib, autoPatchelfHook, fetchzip, lzma, ncurses5, readline, gmp, mpfr
, expat, libipt, zlib, dejagnu, sourceHighlight, python3, elfutils, guile, glibc
}:

stdenv.mkDerivation rec {
  pname = "gnatboot";
  version = "11.2.0-4";
  src = fetchzip {
    url =
      "https://github.com/alire-project/GNAT-FSF-builds/releases/download/gnat-"
      + version + "/gnat-x86_64-linux-" + version + ".tar.gz";
    hash = "sha256-8fMBJp6igH+Md5jE4LMubDmC4GLt4A+bZG/Xcz2LAJQ=";
  };

  nativeBuildInputs = [
    autoPatchelfHook
    lzma
    ncurses5
    readline
    gmp
    mpfr
    expat
    libipt
    zlib
    dejagnu
    sourceHighlight
    python3
    elfutils
    guile
    glibc
  ];

  propagatedNativeBuildInputs = [
    autoPatchelfHook
    lzma
    ncurses5
    readline
    gmp
    mpfr
    expat
    libipt
    zlib
    dejagnu
    sourceHighlight
    python3
    elfutils
    guile
    glibc
  ];

  buildInputs = [
    autoPatchelfHook
    lzma
    ncurses5
    readline
    gmp
    mpfr
    expat
    libipt
    zlib
    dejagnu
    sourceHighlight
    python3
    elfutils
    guile
    glibc
  ];

  propagatedBuildInputs = [
    autoPatchelfHook
    lzma
    ncurses5
    readline
    gmp
    mpfr
    expat
    libipt
    zlib
    dejagnu
    sourceHighlight
    python3
    elfutils
    guile
    glibc
  ];

  installPhase = ''
    mkdir -p $out
      cp -var * $out/
  '';

  meta = with lib; {
    description = "GNAT, the GNU Ada Translator";
    homepage = "https://www.gnu.org/software/gnat";
    license = licenses.gpl3;
    maintainers = with maintainers; [ ethindp ];
    platforms = platforms.linux;
  };
}

This is because the Alire project (which develops the Alire package manager) releases prebuilt versions of gnat and related tools. My goal is to use these prebuilt versions of gnat (and later gprbuild) to bootstrap GCC compiled with Ada support so that a full Gnat build can be achieved. However, though the toolchain fully compiles Ada code, it is unable to link it, complaining that it can’t find crt1.o, crti.o, -ldl, -lc, etc. The entry for gnatboot remains unmodified in nixpkgs top-level listing of all packages:

  gnatboot = wrapCC (callPackage ../development/compilers/gnatboot { });

I’m completely stumped as to what could be missing. What am I doing wrong? I’ve looked at the GCC nixpkgs entry but its not all that helpful. I’ve also tried looking at other packages like ghc, rust, etc., which also require bootstrapping in some form, and they don’t appear to do anything special.

FHS systems keep crt1.o and -lc in /usr/lib. Those are usually default search paths for gcc and gnat drivers. nixpkgs uses slightly different strategy and does not set default seach paths. Instead it relies on a gcc wrapper to inject those paths.

Current nixpkgs gnatboot uses patchelf to make the binary run at all against nixpkgs glibc and specifies a few passthrus to influence gcc-wrapper:

AFAIU you have removed that from your derivation. How do you plan to do the equivalent?

1 Like

I’m not sure. The lines:

    mv $out/bin/gnatgcc_2wrap $out/bin/gnatgcc
    ln -s $out/bin/gnatgcc $out/bin/gcc

Don’t work because this binary doesn’t contain either of those files.

I think that what you wrote solved it. I had to remove a couple lines but its gone far further than I’ve ever see it go before. I’ll post here if something breaks. Thank you so much!

1 Like
Hosted by Flying Circus.