Compiler lacks asm-goto support in ccache stdenv

Hello everyone, because my configuration enables the extension pack for virtualbox and have extra config for kernel so I have to compile virtualbox and the kernel every time the channel updates. I heard of ccache recently and I want to use it to speed up the upgrading task. I add these lines in my configuration:

  programs.ccache.enable = true;
  programs.ccache.packageNames =
  let
    versionNums = splitString "." (import <nixpkgs> {}).linuxPackages_latest.kernel.version;
    kernelPackageName = concatStringsSep "_" ([ "linux" ] ++ (take 2 versionNums));
  in [ kernelPackageName "virtualbox" ];

But the compilation for kernel fails with:

Compiler lacks asm-goto support

Is that fixable?

BTW, is there any way to get the version of the latest kernel without refer to linuxPacakges_latest.kernel.version, which will cause an infinite recursion?

EDIT:
Add nix.sandboxPaths = [ config.programs.ccache.cacheDir ] and the compilation for linux kernel seems to be OK, but compiling virtualbox fails because configure could not find header files needed for 32bit support:

***** Checking 32-bit support *****                                                                                                                                       
compiling the following source file:                                                                                                                                      
#include <stdint.h>                                                                                                                                                       
int main(void)                                                                                                                                                            
{                                                                                                                                                                         
  return 0;                                                                                                                                                               
}                                                                                                                                                                         
using the following command line:                                                                                                                                         
gcc -m32 -O -Wall -o /build/VirtualBox-6.0.12/.tmp_out /build/VirtualBox-6.0.12/.tmp_src.c                                                                                
In file included from /nix/store/zg3y0jq36pd8xf8rd8rhj8bcpinyrs3s-glibc-2.27-dev/include/features.h:452,                                                                  
                 from /nix/store/zg3y0jq36pd8xf8rd8rhj8bcpinyrs3s-glibc-2.27-dev/include/bits/libc-header-start.h:33,                                                     
                 from /nix/store/zg3y0jq36pd8xf8rd8rhj8bcpinyrs3s-glibc-2.27-dev/include/stdint.h:26,                                                                     
                 from /nix/store/yvzq185jfr4vj74a9h4ap4dj4nnqbx7l-gcc-8.3.0/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/include/stdint.h:9,                                    
                 from /build/VirtualBox-6.0.12/.tmp_src.c:1:                                                                                                              
/nix/store/zg3y0jq36pd8xf8rd8rhj8bcpinyrs3s-glibc-2.27-dev/include/gnu/stubs.h:7:11: fatal error: gnu/stubs-32.h: No such file or directory                               
# include <gnu/stubs-32.h>                                                                                                                                               
           ^~~~~~~~~~~~~~~~                                                                                                                                               
compilation terminated.

Any clues? I’m digging it but I don’t know where to check now.

Compiling virtualbox failed with:

cannot execute ‘gcc -dumpversion’!

is there something wrong with the ccache wrapper?