Skip to content
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

missing commands: gcov, gcc-ar, gcc-ranlib and others #86272

Open
sorokin opened this issue Apr 29, 2020 · 9 comments
Open

missing commands: gcov, gcc-ar, gcc-ranlib and others #86272

sorokin opened this issue Apr 29, 2020 · 9 comments
Labels
0.kind: bug Something is broken

Comments

@sorokin
Copy link
Contributor

sorokin commented Apr 29, 2020

Describe the bug
gcc/g++ are not the only commands that are produced by gcc package. There are others. gcov is useful when code coverage need to be computed. gcc-ar/gcc-ranlib are needed when link-time optimization is used.

Apparently newer versions of NixOS don't add these and others gcc commands to system-path/bin.

From what I can see the problem is caused by gcc-wrapper package as it wraps only cpp/gcc/g++ leaving others commands inaccessible.

To Reproduce
In shell running gcov prints "gcov: command not found". Same for other commands provided by gcc package.

Expected behavior
The expected result of running gcov is: "Usage: gcov [OPTION...] SOURCE|OBJ...". Same for other commands.

Metadata
$ shell -p nix-info --run "nix-info -m"
error: attribute 'system' missing, at (string):1:1

  • system: 0
  • host os: Linux 4.19.90, NixOS, 19.09.git.dc8a496 (Loris)
  • multi-user?: no
  • sandbox: yes
  • version: nix-env (Nix) 2.3
  • channels(root): "nixos-14.12.335.676e8d7"
  • channels(ivan): "nixos-14.12.801.221101a"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

The NixOS version I run is 19.09 based on commit 83c8fe6.

@sorokin sorokin added the 0.kind: bug Something is broken label Apr 29, 2020
@sorokin sorokin changed the title missing commands from gcc missing commands: gcov, gcc-ar, gcc-ranlib and others Apr 29, 2020
@matthewbauer
Copy link
Member

You can get access to these through gcc.cc and clang.cc. Maybe we should switch these so that "unwrapped" gcc is "gcc" and "wrapped" gcc is known as "gcc-wrapped".

@sorokin
Copy link
Contributor Author

sorokin commented Apr 29, 2020

Thank you for your suggestion. I didn't know I can refer to unwrapped gcc as gcc.cc. I think now I can configure my environment correctly.

Using gcc.cc instead of gcc fixes the problem with gcov program. gcov is installed correctly now. Unfortunately g++ form unwrapped gcc doesn't work (somewhat expectedly). Compiling a simple hello world program prints this linker error:

$ LANG=en_US g++ main.cpp 
/nix/store/ajrrkivdfvp8dp4vdg5hp1h5hblmanc9-binutils-2.31.1/bin/ld: cannot find crt1.o: No such file or directory
/nix/store/ajrrkivdfvp8dp4vdg5hp1h5hblmanc9-binutils-2.31.1/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

If I build system with both gcc.cc and gcc the same linker error remains. Quick googling showed a thing called package priority. I'll take a look at it. I think using priorities I can configure my system in a way both g++ and gcov work.

In any case I believe the user experience can be improved here. As a user I believe the best name for the package is gcc and it should provide both wrapped gcc/g++ and gcov.

@sorokin
Copy link
Contributor Author

sorokin commented Apr 29, 2020

After reading cc-wrapper/default.nix, I think perhaps something like this would fix my problem:

diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 9851602179c..a2709bcb310 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -209,6 +209,14 @@ stdenv.mkDerivation {
 
     + optionalString cc.langGo or false ''
       wrap ${targetPrefix}gccgo ${./cc-wrapper.sh} $ccPath/${targetPrefix}gccgo
+    ''
+    + optionalString cc.isGNU or false ''
+      ln -s ${targetPrefix}gcc-ar $out/bin/${targetPrefix}gcc-ar
+      ln -s ${targetPrefix}gcc-nm $out/bin/${targetPrefix}gcc-nm
+      ln -s ${targetPrefix}gcc-ranlib $out/bin/${targetPrefix}gcc-ranlib
+      ln -s ${targetPrefix}gcov $out/bin/${targetPrefix}gcov
+      ln -s ${targetPrefix}gcov-dump $out/bin/${targetPrefix}gcov-dump
+      ln -s ${targetPrefix}gcov-tool $out/bin/${targetPrefix}gcov-tool
     '';
 
   strictDeps = true;

Could somebody more familiar with cc-wrapper, comment if this is a reasonable approach?

@stale
Copy link

stale bot commented Oct 26, 2020

Nixpkgs stale bot info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 26, 2020
@siraben
Copy link
Member

siraben commented Nov 25, 2020

ping

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 25, 2020
@stale
Copy link

stale bot commented Jun 3, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 3, 2021
@alarsyo
Copy link
Contributor

alarsyo commented Dec 9, 2021

Still relevant

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 9, 2021
@melg8
Copy link

melg8 commented Apr 14, 2022

I've encountered same issue while building docker image with nix. Still relevant.

@barracuda156
Copy link

After reading cc-wrapper/default.nix, I think perhaps something like this would fix my problem:

diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 9851602179c..a2709bcb310 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -209,6 +209,14 @@ stdenv.mkDerivation {
 
     + optionalString cc.langGo or false ''
       wrap ${targetPrefix}gccgo ${./cc-wrapper.sh} $ccPath/${targetPrefix}gccgo
+    ''
+    + optionalString cc.isGNU or false ''
+      ln -s ${targetPrefix}gcc-ar $out/bin/${targetPrefix}gcc-ar
+      ln -s ${targetPrefix}gcc-nm $out/bin/${targetPrefix}gcc-nm
+      ln -s ${targetPrefix}gcc-ranlib $out/bin/${targetPrefix}gcc-ranlib
+      ln -s ${targetPrefix}gcov $out/bin/${targetPrefix}gcov
+      ln -s ${targetPrefix}gcov-dump $out/bin/${targetPrefix}gcov-dump
+      ln -s ${targetPrefix}gcov-tool $out/bin/${targetPrefix}gcov-tool
     '';
 
   strictDeps = true;

Could somebody more familiar with cc-wrapper, comment if this is a reasonable approach?

What to do if these are not available at all, i.e. GCC has been installed that way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants