{"record":{"id":"37772212030271fe","repo":"golang/go","slug":"corrupt-object-file","errorCode":null,"errorMessage":"corrupt object file","messagePattern":"corrupt object file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/archive/archive.go","lineNumber":106,"sourceCode":"\tArch       string\n\tData\n}\n\nconst (\n\tentryHeader = \"%s%-12d%-6d%-6d%-8o%-10d`\\n\"\n\t// In entryHeader the first entry, the name, is always printed as 16 bytes right-padded.\n\tentryLen   = 16 + 12 + 6 + 6 + 8 + 10 + 1 + 1\n\ttimeFormat = \"Jan _2 15:04 2006\"\n)\n\nvar (\n\tarchiveHeader = []byte(\"!<arch>\\n\")\n\tarchiveMagic  = []byte(\"`\\n\")\n\tgoobjHeader   = []byte(\"go objec\") // truncated to size of archiveHeader\n\n\terrCorruptArchive   = errors.New(\"corrupt archive\")\n\terrTruncatedArchive = errors.New(\"truncated archive\")\n\terrCorruptObject    = errors.New(\"corrupt object file\")\n\terrNotObject        = errors.New(\"unrecognized object file format\")\n)\n\ntype ErrGoObjOtherVersion struct{ magic []byte }\n\nfunc (e ErrGoObjOtherVersion) Error() string {\n\treturn fmt.Sprintf(\"go object of a different version: %q\", e.magic)\n}\n\n// An objReader is an object file reader.\ntype objReader struct {\n\ta      *Archive\n\tb      *bio.Reader\n\terr    error\n\toffset int64\n\tlimit  int64\n\ttmp    [256]byte\n}","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/archive/archive.go#L88-L124","documentation":"Defined as errCorruptObject in cmd/internal/archive. Returned while parsing an individual object file inside an archive (or a standalone object) when the Go object file format is recognized as a Go object (via the goobj magic) but its internal structure — symbol table, relocation records, section headers — fails to parse. The container was fine; the contents are malformed.","triggerScenarios":"An object file generated by one Go version being consumed by a different, incompatible Go version's linker (cache poisoning across versions). A partially-overwritten object in the build cache. A hand-edited or byte-corrupted .o file. Mixing GOEXPERIMENT or GOARCH incompatibly within one build.","commonSituations":"Switching Go versions without clearing the build cache. Concurrent builds with different GOFLAGS/GOARCH writing the same cache slot (rare with modern cache keys but possible with custom -gcflags). Disk corruption. Copying object files between machines with different endianness.","solutions":["Run `go clean -cache` and rebuild — the most common cause is a stale cross-version cache entry.","Make sure every contributor and CI step uses the same Go version (pin via go.mod's `go` directive and `toolchain` line).","If linking prebuilt objects, rebuild them with the current toolchain.","Check for filesystem corruption with `fsck` or by reading the file twice and comparing checksums."],"exampleFix":"# before\n$ go1.20 build ./...\n$ go1.23 build ./...\n# -> corrupt object file\n\n# after\n$ go clean -cache\n$ go1.23 build ./...","handlingStrategy":"retry","validationCode":"// Reject cross-version cache reuse up front.\nfunc cacheVersionMatches(goroot, cacheTag string) error {\n    v := runtime.Version()\n    if !strings.HasPrefix(cacheTag, v) {\n        return fmt.Errorf(\"cache tagged %q but toolchain is %q — run go clean -cache\", cacheTag, v)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"corrupt object file\") {\n    // most common fix: clear cache and rebuild with the current toolchain\n    exec.Command(\"go\", \"clean\", \"-cache\").Run()\n    // retry build\n}","preventionTips":["Pin a single Go version across the team (go.mod `go` + `toolchain` directives).","Run `go clean -cache` whenever you switch Go versions.","Never copy object files between machines of different GOARCH/GOOS or Go versions."],"tags":["go-toolchain","object-file","linker","corruption","build-cache"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}