{"record":{"id":"700c172e05f1a570","repo":"golang/go","slug":"read-type-failed-v-700c17","errorCode":null,"errorMessage":"read type failed: %v","messagePattern":"read type failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/lib.go","lineNumber":2682,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\tr := sect.Open()\n\t\tfor {\n\t\t\tvar namesize, descsize, noteType int32\n\t\t\terr := binary.Read(r, f.ByteOrder, &namesize)\n\t\t\tif err != nil {\n\t\t\t\tif err == io.EOF {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"read namesize failed: %v\", err)\n\t\t\t}\n\t\t\terr = binary.Read(r, f.ByteOrder, &descsize)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read descsize failed: %v\", err)\n\t\t\t}\n\t\t\terr = binary.Read(r, f.ByteOrder, &noteType)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read type failed: %v\", err)\n\t\t\t}\n\t\t\tnoteName, err := readwithpad(r, namesize)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read name failed: %v\", err)\n\t\t\t}\n\t\t\tdesc, err := readwithpad(r, descsize)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"read desc failed: %v\", err)\n\t\t\t}\n\t\t\tif string(name) == string(noteName) && typ == noteType {\n\t\t\t\treturn desc, nil\n\t\t\t}\n\t\t}\n\t}\n\treturn nil, nil\n}\n\nfunc findshlib(ctxt *Link, shlib string) string {","sourceCodeStart":2664,"sourceCodeEnd":2700,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/lib.go#L2664-L2700","documentation":"The third header word of an ELF note is the 4-byte `noteType`. After `namesize` and `descsize` are read successfully, a failure reading `noteType` indicates a note record whose header is incomplete (e.g. a section length claiming room for two notes but only fitting part of a third). The linker refuses to guess the type and aborts.","triggerScenarios":"A `SHT_NOTE` section length not aligned to full note records, leaving a partial trailing header; an object generated by a compiler/assembler that miscalculated note sizes; filesystem corruption altering the section's contents.","commonSituations":"Object built with a buggy nightly/binutils snapshot; corrupt cache after a hard reset; mixing objects from different endianness toolchains.","solutions":["`go clean -cache && go build -a` to rebuild objects.","Cross-check with `readelf -n <object>` — a clean object yields a parseable note list.","Reinstall/upgrade the C toolchain if its objects consistently produce malformed notes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# readelf -n exits non-zero / reports errors on malformed notes\nfor obj in $(find build -name '*.o'); do\n  readelf -n \"$obj\" >/dev/null 2>&1 || echo \"note header corrupt: $obj\"\ndone","typeGuard":null,"tryCatchPattern":"set +e\ngo build ./...\nrc=$?\nset -e\n[ $rc -ne 0 ] && { go clean -cache; go build -a ./...; }","preventionTips":["Use a stable, mainstream binutils to assemble objects.","Validate note sections in CI with `readelf -n`.","Do not hand-edit ELF sections."],"tags":["linker","go-toolchain","elf","cgo","note-section"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}