Compiling a trivial Ada application fails due to invalid command line options added by some nix-specific wrapper scripts.
In other Linux distributions 'gnatmake' is a binary file, in nix however it`s a wrapper script.
$ gnatmake hello.adb
gcc -c -I/nix/store/2dam02rdvc2bp5ghcd7x8ivrd2dwsl3p-gnat-4.5.4/lib/gcc/x86_64-unknown-linux-gnu/4.5.4/adainclude hello.adb
/nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/bin/gnatbind -aI/nix/store/2dam02rdvc2bp5ghcd7x8ivrd2dwsl3p-gnat-4.5.4/lib/gcc/x86_64-unknown-linux-gnu/4.5.4/adainclude -aO/nix/store/2dam02rdvc2bp5ghcd7x8ivrd2dwsl3p-gnat-4.5.4/lib/gcc/x86_64-unknown-linux-gnu/4.5.4/adalib -x hello.ali
/nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/bin/gnatlink hello.ali
gnat1: warning: command line option "-Wformat" is valid for C/C++/ObjC/ObjC++ but not for Ada
gnat1: warning: command line option "-Wformat-security" is valid for C/C++/ObjC/ObjC++ but not for Ada
gnat1: error: unrecognized command line option "-fstack-protector-strong"
gnatmake: *** link failed.
where 'hello.adb' is a simple "hello world" program with the following contents:
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line("Hello");
end;
$ nixos-version
17.09.1756.c99239bca0 (Hummingbird)
$ nix-env --version
nix-env (Nix) 1.11.15
$ nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion
"17.09.1756.c99239bca0"
$ grep build-use-sandbox /etc/nix/nix.conf
build-use-sandbox = false
Additional information
As can be seen in the trail below it's the hardning script that adds the invalid command line options.
/nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/bin/gnatlink
extraAfter=("--GCC=/nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/bin/gcc")
/nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/bin/gcc
source /nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/nix-support/add-hardening.sh
/nix/store/w7n604zqlncab02gxyf5kld19wl5v8k6-gnat-wrapper-4.5.4/nix-support/add-hardening.sh
hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
In nixpkgs these files are:
nixpkgs/pkgs/build-support/cc-wrapper/gnatlink-wrapper.sh
nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh
nixpkgs/pkgs/build-support/cc-wrapper/add-hardening.sh
TL;DR: work around via export hardeningDisable=all
Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
Our default gnat is in version 9 now, so these errors shouldn't happen. To be sure, gnatmake hello.adb works for me.
Most helpful comment
TL;DR: work around via
export hardeningDisable=all