Skip to content

cmd/go: gccCompilerID cache validation always fails due to a trailing NUL field #81553

Open

Description

@nnnkkk7

Go version

go version go1.27.1 darwin/arm64 (also present on tip)

Output of go env in your module/workspace:

CC='cc'
CGO_ENABLED='1'
GOARCH='arm64'
GOOS='darwin'
GOVERSION='go1.27.1'

What did you do?

Read the compiler ID cache validation in gccCompilerID (src/cmd/go/internal/work/exec.go). The cache entry is written as pairs of filename \x00 statinfo \x00 followed by the compiler ID, and validated on read like this:

stats := strings.Split(string(data[:len(data)-len(id)]), "\x00")
if len(stats)%2 != 0 {
	goto Miss
}

What did you see happen?

The payload itself ends with a NUL byte, so the split always produces a trailing empty field and an odd number of fields, and validation always takes goto Miss. The cached compiler ID is never reused: every go process that needs it re-runs the C compiler via gccToolID, which is the expense this cache was added to avoid (CL 392454, Go 1.19).

The loop below the parity check also advances by one over the name/stat pairs (i++ rather than i += 2), so an entry recording two files would fail validation even with the parity check fixed.

What did you expect to see?

A cache hit: repeated go invocations should validate the entry with os.Stat and reuse the stored compiler ID without re-running the compiler.

Activity

  1. gopherbot commented on Sep 15, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/833424 mentions this issue: cmd/go: fix gccCompilerID cache validation

  2. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Sep 18, 2026
  3. added this to the Backlog milestone on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.GoCommandcmd/go

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions