golang/go · error

read name failed: %v

Error message

read name failed: %v

What it means

Once the note header is read, the linker reads `namesize` bytes of name (plus padding to a 4-byte boundary) via `readwithpad`. A failure here means the section claims a name longer than the bytes actually remaining, or the underlying reader errored — the note's name cannot be recovered and the link aborts.

Source

Thrown at src/cmd/link/internal/ld/lib.go:2686

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

func findshlib(ctxt *Link, shlib string) string {
	if filepath.IsAbs(shlib) {
		return shlib
	}
	for _, libdir := range ctxt.Libdir {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Rebuild the offending cgo package from source.
  2. Inspect with `readelf -x .note.<name> <obj>` to see if the section bytes match the declared `namesize`.
  3. Replace the object from a trusted source (re-fetch the module, reinstall the C library).
Defensive patterns

Strategy: validation

Validate before calling

# Verify note name lengths fit within their section
for obj in $(find build -name '*.o'); do
  readelf -n "$obj" >/dev/null 2>&1 || echo "note name unreadable: $obj"
done

Try / catch

set +e
go build ./...
rc=$?
set -e
[ $rc -ne 0 ] && { go clean -cache; go build -a ./...; }

Prevention

When it happens

Trigger: A `namesize` value larger than the remaining section bytes (corrupt or maliciously crafted object); a section whose declared length is shorter than its note header implies; I/O error reading the archive member.

Common situations: Corrupted dependency archive; object patched by hand or by a faulty code-generation tool; NFS/network filesystem returning short reads.

Related errors


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