{"record":{"id":"7ad7e645e2b6f1c3","repo":"golang/go","slug":"read-namesize-failed-v-7ad7e6","errorCode":null,"errorMessage":"read namesize failed: %v","messagePattern":"read namesize failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/lib.go","lineNumber":2674,"sourceCode":"\t}\n\tdata = data[:sz]\n\treturn data, nil\n}\n\nfunc readnote(f *elf.File, name []byte, typ int32) ([]byte, error) {\n\tfor _, sect := range f.Sections {\n\t\tif sect.Type != elf.SHT_NOTE {\n\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 {","sourceCodeStart":2656,"sourceCodeEnd":2692,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/lib.go#L2656-L2692","documentation":"The linker scans every `SHT_NOTE` section in an ELF host object (a C-compiled `.o`/`.a` pulled in via cgo) looking for a note with a given name and type. Each ELF note begins with a 4-byte `namesize` field read via `binary.Read`. `io.EOF` cleanly ends the section; any other read failure (truncated note, I/O error, unreadable archive member) is reported as a namesize read failure and aborts the link.","triggerScenarios":"Linking a cgo program whose `.a`/`.o` contains a malformed, zero-length, or truncated `SHT_NOTE` section; an archive member that was partially overwritten or extracted with a broken `ar`; a disk/filesystem read error during linking; an object produced by a buggy or very old binutils.","commonSituations":"Corrupted dependency archive in the build cache; `ar`/`ranlib` version mismatch between C toolchain and Go; flaky network filesystem hosting the object files; object produced by a cross-compiler emitting non-standard notes.","solutions":["Rebuild the C/cgo objects from source (`go build -a`) to regenerate the archive cleanly.","Inspect the suspect object with `readelf -n <obj>` or `objdump --notes <obj>` to confirm the note section is malformed.","Re-`ar` the archive with a current `ar`/`ranlib` matching the C compiler.","If the object is read from a network mount, copy it locally and rebuild."],"exampleFix":"# before: stale archive triggers malformed note read\ngo build ./...\n\n# after\ngo clean -cache\ngo build -a ./...","handlingStrategy":"validation","validationCode":"# Validate every ELF object's note sections before linking\nfor obj in $(find /root/.cache/go-build build -name '*.o' -o -name '*.a'); do\n  if readelf -S \"$obj\" 2>/dev/null | grep -q NOTE; then\n    readelf -n \"$obj\" >/dev/null 2>&1 || echo \"malformed note in $obj\"\n  fi\ndone","typeGuard":null,"tryCatchPattern":"set +e\ngo build ./...\nrc=$?\nset -e\nif [ $rc -ne 0 ]; then\n  go clean -cache\n  go build -a ./...\nfi","preventionTips":["Rebuild cgo objects after any C-toolchain upgrade.","Validate host objects with `readelf -n` in CI before linking.","Keep the build cache on a reliable local filesystem, not a flaky network mount.","Pin consistent `ar`/`ranlib` and C compiler versions."],"tags":["linker","go-toolchain","elf","cgo","note-section"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}