golang/go · error

read namesize failed: %v

Error message

read namesize failed: %v

What it means

Returned while iterating ELF SHT_NOTE sections in note.go: binary.Read of the 4-byte namesize field failed with a non-EOF error. EOF cleanly terminates the note loop; any other read error (UnexpectedEOF, I/O error) is wrapped as 'read namesize failed'. This indicates the note section is truncated or unreadable.

Source

Thrown at src/cmd/internal/buildid/note.go:47

func ReadELFNote(filename, name string, typ int32) ([]byte, error) {
	f, err := elf.Open(filename)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	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, &noteType)
			if err != nil {
				return nil, fmt.Errorf("read type failed: %v", err)
			}
			noteName, err := readAligned4(r, namesize)
			if err != nil {
				return nil, fmt.Errorf("read name failed: %v", err)
			}
			desc, err := readAligned4(r, descsize)
			if err != nil {
				return nil, fmt.Errorf("read desc failed: %v", err)
			}
			if name == string(noteName) && typ == noteType {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Rebuild/relink the binary cleanly to eliminate truncation.
  2. Verify file integrity (checksums, `file <bin>`, size vs expected).
  3. Confirm the binary was produced by the Go linker and not stripped/mangled by an external tool.
  4. If on the buildid path, run `go clean -cache` and rebuild.
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := buildid.ReadFile(bin); err != nil {
    if strings.Contains(err.Error(), "read namesize failed") {
        // binary note section truncated; rebuild
        return rebuild(bin)
    }
    return err
}

Prevention

When it happens

Trigger: Calling the ELF note reader (used to extract the Go build ID from a Go-built ELF binary) on a binary whose SHT_NOTE section is shorter than the minimum 12-byte note header, or whose underlying Reader returns an error mid-read.

Common situations: Truncated/corrupted Go binaries (interrupted link step, partial download, rsync cut short), object files from a foreign linker, or reading a Go binary built for a different platform whose note layout differs.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/b212b8cd0071caf8. Report an issue: GitHub.