Repository: go
Issue: cmd/go: `-toolexec` program inconsistently used for C toolchain
Labels: NeedsFix,GoCommand

### Go version

go version devel go1.22-098f059d Mon Dec 4 23:03:04 2023 +0000 linux/amd64

### What operating system and processor architecture are you using (`go env`)?

```shell
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/usr/local/google/home/bcmills/.cache/go-build'
GOENV='/usr/local/google/home/bcmills/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/usr/local/google/home/bcmills/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/google/home/bcmills'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/google/home/bcmills/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/google/home/bcmills/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.22-098f059d Mon Dec 4 23:03:04 2023 +0000'
GCCGO='/usr/bin/gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4055144386=/tmp/go-build -gno-record-gcc-switches'
```


### What did you do?

1. Note that in the `cmd/go/internal/work` package, both `Builder.toolID` and `Builder.gccToolID` wrap the invocation of the tool with `cfg.BuildToolexec`:
   - https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/work/buildid.go;l=162;drc=4c31dfe850165979bbcf0510c35576d022f26eb3
   - https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/work/buildid.go;l=229;drc=4c31dfe850165979bbcf0510c35576d022f26eb3
2. Run `CC=gcc gotip build -toolexec='/bin/time --format "%E %C"' -x -a runtime/cgo`.
3. Grep the output of (2) for `gcc` invocations.

### What did you expect to see?

`/bin/time` output for `gcc` commands executed while building `runtime/cgo`, or `gcc` commands consistently _not_ wrapped with the `-toolexec` command.

### What did you see instead?

- The `/bin/time … gcc` invocation in `Builder.gccToolID` is not included in the `-x` log, and its output is not printed like other `toolexec` output.
- The `gcc` invocations elsewhere in the build process are not wrapped with `/bin/time` as requested.

<details><summary><code>CC=gcc gotip build -toolexec='/bin/time --format "%E %C"' -x -a runtime/cgo 2&gt;&amp;1 | grep gcc</code></summary>

```
TERM='dumb' gcc -I /usr/local/google/home/bcmills/sdk/gotip/src/runtime/cgo -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x001.o -c _cgo_export.c
TERM='dumb' gcc -I /usr/local/google/home/bcmills/sdk/gotip/src/runtime/cgo -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x002.o -c cgo.cgo2.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x003.o -c gcc_context.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x004.o -c gcc_fatalf.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x005.o -c gcc_libinit.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x006.o -c gcc_linux_amd64.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x007.o -c gcc_mmap.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x008.o -c gcc_setenv.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x009.o -c gcc_sigaction.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x010.o -c gcc_stack_unix.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x011.o -c gcc_traceback.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x012.o -c gcc_util.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x013.o -c linux_syscall.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_x014.o -c gcc_amd64.S
TERM='dumb' gcc -I /usr/local/google/home/bcmills/sdk/gotip/src/runtime/cgo -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I $WORK/b001/ -O2 -g -Wall -Werror -fno-stack-protector -ffile-prefix-map=/usr/local/google/home/bcmills/sdk/gotip=/_/GOROOT -frandom-seed=q-EwsxrCJu7ItAw7sEU- -o $WORK/b001/_cgo_main.o -c _cgo_main.c
TERM='dumb' gcc -I ./sdk/gotip/src/runtime/cgo -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -o $WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o $WORK/b001/_x003.o $WORK/b001/_x004.o $WORK/b001/_x005.o $WORK/b001/_x006.o $WORK/b001/_x007.o $WORK/b001/_x008.o $WORK/b001/_x009.o $WORK/b001/_x010.o $WORK/b001/_x011.o $WORK/b001/_x012.o $WORK/b001/_x013.o $WORK/b001/_x014.o -O2 -g -lpthread
```

</details>