{"record":{"id":"732cdbba2e616f03","repo":"golang/go","slug":"fail-to-seek-732cdb","errorCode":null,"errorMessage":"fail to seek","messagePattern":"fail to seek","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/loadxcoff/ldxcoff.go","lineNumber":33,"sourceCode":"\t\"fmt\"\n\t\"internal/xcoff\"\n)\n\n// ldSection is an XCOFF section with its symbols.\ntype ldSection struct {\n\txcoff.Section\n\tsym loader.Sym\n}\n\n// TODO(brainman): maybe just add ReadAt method to bio.Reader instead of creating xcoffBiobuf\n\n// xcoffBiobuf makes bio.Reader look like io.ReaderAt.\ntype xcoffBiobuf bio.Reader\n\nfunc (f *xcoffBiobuf) ReadAt(p []byte, off int64) (int, error) {\n\tret := ((*bio.Reader)(f)).MustSeek(off, 0)\n\tif ret < 0 {\n\t\treturn 0, errors.New(\"fail to seek\")\n\t}\n\tn, err := f.Read(p)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn n, nil\n}\n\n// loads the Xcoff file pn from f.\n// Symbols are written into loader, and a slice of the text symbols is returned.\nfunc Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []loader.Sym, err error) {\n\terrorf := func(str string, args ...any) ([]loader.Sym, error) {\n\t\treturn nil, fmt.Errorf(\"loadxcoff: %v: %v\", pn, fmt.Sprintf(str, args...))\n\t}\n\n\tvar ldSections []*ldSection\n\n\tf, err := xcoff.NewFile((*xcoffBiobuf)(input))","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/loadxcoff/ldxcoff.go#L15-L51","documentation":"Returned by xcoffBiobuf.ReadAt when the underlying bio.Reader.MustSeek returns a negative value. xcoffBiobuf adapts a buffered I/O reader to io.ReaderAt so XCOFF (AIX) section readers can random-access the linker's input. A failed seek means the requested offset is unreachable on the stream backing the XCOFF file.","triggerScenarios":"The XCOFF loader (loadxcoff) calls ReadAt on a section/symbol offset outside the buffered reader's valid range — a truncated file, malformed XCOFF header pointing past EOF, or corrupted reader position. MustSeek(off,0) < 0 triggers the error.","commonSituations":"Cross-building for AIX (GOOS=aix) against a truncated or corrupt XCOFF object/archive; a build-cache artifact left by an interrupted write; an XCOFF import library downloaded incompletely.","solutions":["Rebuild or re-fetch the offending XCOFF input; truncation is the usual cause.","Inspect the file with an XCOFF tool (dump on AIX, or `go tool nm`) to confirm section offsets are within EOF.","Clean the build cache (`go clean -cache`) and rebuild to discard stale partial objects.","If the file is valid, verify the linker resolves the same path (check library search paths)."],"exampleFix":"// before: GOOS=aix build against a truncated .a\ngoos=aix go build\n// ldxcoff: fail to seek\n\n// after\ngo clean -cache\n# ensure the XCOFF archive is complete, then rebuild\ngoos=aix go build","handlingStrategy":"validation","validationCode":"// Verify the XCOFF input is complete and its sections are within EOF before linking.\nfunc xcoffSectionsWithinEOF(path string) error {\n    f, err := os.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    fi, _ := f.Stat()\n    xf, err := xcoff.NewFile(f)\n    if err != nil { return err }\n    for _, s := range xf.Sections {\n        if int64(s.Offset)+int64(s.Size) > fi.Size() {\n            return fmt.Errorf(\"section %s extends past EOF\", s.Name)\n        }\n    }\n    return nil\n}","typeGuard":"func isSeekFail(err error) bool {\n    return err != nil && err.Error() == \"fail to seek\"\n}","tryCatchPattern":"if err := loadxcoff.Load(...); err != nil && err.Error() == \"fail to seek\" {\n    return fmt.Errorf(\"XCOFF input %s appears truncated: %w\", pn, err)\n}","preventionTips":["Validate XCOFF section offsets against file size before linking.","Re-fetch truncated AIX objects/archives.","Clean the build cache after interrupted builds."],"tags":["xcoff","aix","linker","binary-parsing","seek"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}