How to override current GCC7 for recompiling gcc7.3?

Hi,I am a beginner for nixos. And I am going to recompile a specify version of gcc,eg:gcc7.3。I overridden the gcc version and src attribute using overlay,like below:

self: pkgs:
with pkgs;
   gcc7 = rec {
       version = "7.3.0";
       src = [ ./gcc-7.3.0.tar.gz ];
let pkgs = import <nixpkgs> { overlays= [(import ./overlay1.nix)]; };
in pkgs.gcc7

the build error log show as follow:
these derivations will be built:
building ‘/nix/store/29mhv9glx2zkjjrgyqv0skphkdmcwm9f-gcc-7.3.0.drv’…
$CPATH is /nix/store/5rrw5av331ddxnjvlb6ay9wjnfi30xl3-zlib-1.2.11-dev/include' $LIBRARY_PATH is /nix/store/h3gdlnj633hagpq59zn7lhkfmfclcbb3-zlib-1.2.11/lib’
/nix/store/ line 39: /nix/store/579l1jpqmwjfghmlh9mnj6ykx06q2g38-binutils-wrapper-2.35.1/nix-support/libc-ldflags-before: No such file or directory
/nix/store/ line 39: /nix/store/579l1jpqmwjfghmlh9mnj6ykx06q2g38-binutils-wrapper-2.35.1/nix-support/libc-ldflags-before: No such file or directory
unpacking sources
unpacking source archive /nix/store/i1kj8n31aan2bmidg5rwqasw42mbrzff-gcc-7.3.0.tar.gz
source root is gcc-7.3.0
setting SOURCE_DATE_EPOCH to timestamp 1516870173 of file gcc-7.3.0/MD5SUMS
patching sources
applying patch /nix/store/s6lavkpjqzihfs0vjfnnz7lizpsfmgnl-riscv-pthread-reentrant.patch
patching file gcc/config/riscv/linux.h
applying patch /nix/store/6m27y27zvzsjn1ir4y8mm9nc9xnh2sgx-riscv-no-relax.patch
patching file gcc/config/riscv/riscv.c
Hunk #1 succeeded at 3676 (offset -303 lines).
patching file gcc/config/riscv/riscv.opt
Hunk #1 succeeded at 102 (offset -4 lines).
patching file gcc/doc/invoke.texi
Hunk #1 succeeded at 976 (offset -66 lines).
Hunk #2 succeeded at 20976 (offset -2127 lines).
applying patch /nix/store/jgs1i4b4liw39b7i7mfp6z0bisz543ri-0001-Fix-build-for-glibc-2.31.patch
patching file libsanitizer/sanitizer_common/
Hunk #1 succeeded at 1134 (offset -11 lines).
patching file libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
applying patch /nix/store/pz03lhak99nzyyni72m14zsjzfjvqvr8-no-sys-dirs.patch
patching file gcc/cppdefault.c
patching file gcc/gcc.c
Hunk #1 succeeded at 1464 (offset 302 lines).
applying patch /nix/store/bqdcpm73hcngcsk8081ray23fznlah0h-libsanitizer-no-cyclades-9.patch
patching file libsanitizer/sanitizer_common/
Hunk #1 succeeded at 361 (offset -4 lines).
patching file libsanitizer/sanitizer_common/
Hunk #1 FAILED at 157.
Hunk #2 succeeded at 443 (offset -23 lines).
Hunk #3 succeeded at 809 (offset -23 lines).
1 out of 3 hunks FAILED – saving rejects to file libsanitizer/sanitizer_common/
patching file libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
Hunk #1 succeeded at 987 (offset -53 lines).
Hunk #2 succeeded at 1331 (offset -53 lines).
builder for ‘/nix/store/29mhv9glx2zkjjrgyqv0skphkdmcwm9f-gcc-7.3.0.drv’ failed with exit code 1
error: build of ‘/nix/store/29mhv9glx2zkjjrgyqv0skphkdmcwm9f-gcc-7.3.0.drv’ failed

so how can I fix it? thanks!

I resolve the problem by manually comment out the ustat.h in gcc-x.x.x/libsanitizer/sanitizer-common/ (line number 157 and 250). Because archlinux deprecated the ustat.h in glibc.

As far as I know so far,the nixpkgs provides multiple version of gcc,for each version,it patches gcc fed in patch options。If I want to support gcc version of each commit,what is the best adaptation solution

1 Like

You can consider using stdenv.mkDerivation from older nixpkgs by using import combined with fetchTarball to download an older version of nixpkgs.

Thanks for you answer, it can help me some parts.To be honest, I’ve successfully built the version of gcc 6.4 and gcc 7.3 by using overlays for overriding the src,version and patches attributes. Among these, since the gcc versions not provided by nixpkg currently still need some compatibility patches to work in other gcc version(nixpkg now only provides gcc 6.5 and 7.5 .nix files), I need to manully add extra patches in order to build successfully.
And my real requirement is to support bisect gcc commits for locating performance problems caused by GCC, so, in order to build any commit version of gcc, we resort to nix to help me to automatically build any gcc version. Any suggestions about this? thanks~