Using `stdenv.cc.cc.lib` while cross-compiling

With localSystem = x86-64-linux / crossSystem = aarch64-linux, I’m having trouble with finding libstdc++.so.6.

I can see in the nix log that the GCC lib path is wrong - it’s .../lib/ when it needs to be .../aarch64-unknown-linux-gnu/lib.

I’m using flake-utils.lib.eachDefaultSystem with crossSystem = "aarch64-linux".

Package file is like so:

{
  src,
  lib,
  stdenv,
  autoPatchelfHook,
  llvmPackages_17,
}:
llvmPackages_17.stdenv.mkDerivation rec {
  name = "mypkg";
  inherit src;

  nativeBuildInputs = [autoPatchelfHook];
  buildInputs = [stdenv.cc.cc.lib];
}

Changing stdenv.cc.cc.lib to "${stdenv.cc.cc.lib}/aarch64-unknown-linux-gnu" works, but is clearly not right.

Am I missing something obvious here or is there something special I need to do for authPatchelfHook when cross-compiling?

  'libs': [PosixPath('/nix/store/garx7rbwr0i9if5sn2q3gaswwraywx08-compiler-rt-libc-aarch64-unknown-linux-gnu-17.0.6-dev/lib'),
           PosixPath('/nix/store/84dpxzkp68lznd6ll5i6ilz5yjkjnvc7-compiler-rt-libc-aarch64-unknown-linux-gnu-17.0.6/lib'),
           PosixPath('/nix/store/srygzvlbvr4drgqylx83hr9jd0g47swn-aarch64-unknown-linux-gnu-gcc-13.2.0-lib/lib')],
  'paths': [PosixPath('/nix/store/7110z5rh9dqx21qrgvn1f6hwflyasb1n-mypkg-aarch64-unknown-linux-gnu')],
  'recursive': True,
  'runtime_dependencies': []}
 searching for dependencies of /nix/store/7110z5rh9dqx21qrgvn1f6hwflyasb1n-mypkg-aarch64-unknown-linux-gnu/lib/libmypkg.so
     libstdc++.so.6 -> not found!
     libgcc_s.so.1 -> not found!
 auto-patchelf: 2 dependencies could not be satisfied

/nix/store/srygzvlbvr4drgqylx83hr9jd0g47swn-aarch64-unknown-linux-gnu-gcc-13.2.0-lib/lib
:arrow_up: does not exist

/nix/store/srygzvlbvr4drgqylx83hr9jd0g47swn-aarch64-unknown-linux-gnu-gcc-13.2.0-lib/aarch64-unknown-linux-gnu/lib
:arrow_up: does exist