golang/go · error
read namesize failed: %v
Error message
read namesize failed: %v
What it means
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.
Source
Thrown at src/cmd/link/internal/ld/lib.go:2674
}
data = data[:sz]
return data, nil
}
func readnote(f *elf.File, name []byte, typ int32) ([]byte, error) {
for _, sect := range f.Sections {
if sect.Type != elf.SHT_NOTE {
continue
}
r := sect.Open()
for {
var namesize, descsize, noteType int32
err := binary.Read(r, f.ByteOrder, &namesize)
if err != nil {
if err == io.EOF {
break
}
return nil, fmt.Errorf("read namesize failed: %v", err)
}
err = binary.Read(r, f.ByteOrder, &descsize)
if err != nil {
return nil, fmt.Errorf("read descsize failed: %v", err)
}
err = binary.Read(r, f.ByteOrder, ¬eType)
if err != nil {
return nil, fmt.Errorf("read type failed: %v", err)
}
noteName, err := readwithpad(r, namesize)
if err != nil {
return nil, fmt.Errorf("read name failed: %v", err)
}
desc, err := readwithpad(r, descsize)
if err != nil {
return nil, fmt.Errorf("read desc failed: %v", err)
}
if string(name) == string(noteName) && typ == noteType {View on GitHub (pinned to b6b368adc5)
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.
Example fix
# before: stale archive triggers malformed note read go build ./... # after go clean -cache go build -a ./...
Defensive patterns
Strategy: validation
Validate before calling
# Validate every ELF object's note sections before linking
for obj in $(find /root/.cache/go-build build -name '*.o' -o -name '*.a'); do
if readelf -S "$obj" 2>/dev/null | grep -q NOTE; then
readelf -n "$obj" >/dev/null 2>&1 || echo "malformed note in $obj"
fi
done Try / catch
set +e go build ./... rc=$? set -e if [ $rc -ne 0 ]; then go clean -cache go build -a ./... fi
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/7ad7e645e2b6f1c3.
Report an issue: GitHub.