golang/go · error

read descsize failed: %v

Error message

read descsize failed: %v

What it means

After reading a note's `namesize`, the linker reads the 4-byte `descsize` field that gives the descriptor length. A failure here (other than the EOF that terminates the section) means the note record is truncated mid-header: namesize was consumed but the descriptor-length word is missing or unreadable, so the note cannot be sized and the link aborts.

Source

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

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, &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
			}
		}
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Rebuild all cgo/C objects with `-a` to regenerate archives.
  2. Validate the object: `readelf -n` should list notes without error; if it errors, the object is corrupt.
  3. Re-acquire the object from a known-good source (re-`go mod download`, reinstall the C dependency).
Defensive patterns

Strategy: validation

Validate before calling

# Confirm note sections parse cleanly (no truncated headers)
for obj in $(find build -name '*.o'); do
  readelf -n "$obj" >/dev/null 2>&1 || echo "bad notes: $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 `SHT_NOTE` section whose total length is not a multiple of the note header (12 bytes), leaving a stray `namesize` with no `descsize`; an archive member truncated by a failed write; an object emitted by a tool that writes a non-conforming note record.

Common situations: Truncated `.o` from an interrupted `cc` compile; corrupted build cache; object hand-edited or transferred with size corruption (e.g. FTP text-mode conversion).

Related errors


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