How to correctly use {ld, nm, ar, ranlib} with LTO in nix develop shell

I use g++ with -flto to compile two .o file and try to link them together to create a executable.

ld -flto main.o functions.o -o myprogram

it outputs:

/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: main.o: plugin needed to handle lto object
/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: main.o: plugin needed to handle lto object
/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: functions.o: plugin needed to handle lto object
/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: functions.o: plugin needed to handle lto object
/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000

Run nm main.o, it outputs

nm: main.o: plugin needed to handle lto object
0000000000000001 C __gnu_lto_slim

However, when I switch to g++ and gcc-nm, it works correctly.

For ar, ranlib, it is the same.

It seems that the plugin is not loaded by these tools. Is there any workaround?

My flake.nix:

{
  description = "C/C++ development environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, ... }@inputs: inputs.utils.lib.eachSystem [
    "x86_64-linux"
    "i686-linux"
    "aarch64-linux"
    "x86_64-darwin"
  ]
    (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
      in
      {
        devShells.default = pkgs.mkShell {
          packages = with pkgs; [
            autoconf
            automake
            pkg-config
            cmake
            bear
            clang-tools_16
          ];
        };
      });
}

main.cc

#include "functions.h"

int main() {
    int result = addNumbers(5, 10);
    return 0;
}

functions.cc:

#include "functions.h"

int addNumbers(int a, int b) {
    return a + b;
}

functions.h

#ifndef _FUNCTIONS_H
#define _FUNCTIONS_H

int addNumbers(int a, int b);

#endif

It seems that I can only use gcc, gcc-nm, gcc-ar, gcc-ranlib or clang, llvm-nm, llvm-ar, llvm-ranlib instead.

nixpkgs does not install gcc LTO plugin to binutils. It should. There was a PoC in binutils-unwrapped: install gcc LTO plugin by trofi · Pull Request #188544 · NixOS/nixpkgs · GitHub but it needs a bit more work.