golang/go · error

read name failed: %v

Error message

read name failed: %v

What it means

Returned when readAligned4 fails reading the note name (e.g. "Go\x00\x00" or "GNU\x00") after the three header words parsed successfully. namesize bytes (padded to 4-byte alignment) could not be read, meaning the note's declared namesize extends past the section's actual bytes.

Source

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

			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 {
				return desc, nil
			}
		}
	}
	return nil, nil
}

var elfGoNote = []byte("Go\x00\x00")
var elfGNUNote = []byte("GNU\x00")

// The Go build ID is stored in a note described by an ELF PT_NOTE prog
// header. The caller has already opened filename, to get f, and read

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Rebuild the affected binary from a clean source tree.
  2. Run `go clean -cache` to discard corrupt cached objects.
  3. Verify binary integrity (checksum, `file <bin>`).
  4. Eliminate any binary post-processing steps that rewrite note sections.
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := buildid.ReadFile(bin); err != nil {
    if strings.Contains(err.Error(), "read name failed") {
        return rebuild(bin)
    }
    return err
}

Prevention

When it happens

Trigger: An ELF note header advertises a namesize larger than the remaining section data, so readAligned4 returns an error. Common when namesize is garbage (corruption) or the section is truncated right after the header.

Common situations: Corrupt Go binaries where note header fields are inconsistent with section length; objects modified by a faulty post-link tool; mismatches between note producer and consumer expectations.

Related errors


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