golang/go · error

Examiner.FileRef: malformed file reference %d

Error message

Examiner.FileRef: malformed file reference %d

What it means

Thrown by Examiner.FileRef (dwtest.go:180-182) when the numeric file reference (typically from a decl_file/call_file attribute) is out of range for the line reader's file table: either negative or greater than len(files)-1. The file index cannot be resolved to a name, indicating the DWARF producer emitted an inconsistent index.

Source

Thrown at src/cmd/link/internal/dwtest/dwtest.go:181

// (presumably from a decl_file or call_file attribute), looks up the
// reference in the .debug_line file table, and returns the proper
// string for it. We need to know which DIE is making the reference
// so as to find the right compilation unit.
func (ex *Examiner) FileRef(dw *dwarf.Data, dieIdx int, fileRef int64) (string, error) {

	// Find the parent compilation unit DIE for the specified DIE.
	cuDie := ex.ParentCU(dieIdx)
	if cuDie == nil {
		return "", fmt.Errorf("no parent CU DIE for DIE with idx %d?", dieIdx)
	}
	// Construct a line reader and then use it to get the file string.
	lr, lrerr := dw.LineReader(cuDie)
	if lrerr != nil {
		return "", fmt.Errorf("d.LineReader: %v", lrerr)
	}
	files := lr.Files()
	if fileRef < 0 || int(fileRef) > len(files)-1 {
		return "", fmt.Errorf("Examiner.FileRef: malformed file reference %d", fileRef)
	}
	return files[fileRef].Name, nil
}

// Return a list of all DIEs with name 'name'. When searching for DIEs
// by name, keep in mind that the returned results will include child
// DIEs such as params/variables. For example, asking for all DIEs named
// "p" for even a small program will give you 400-500 entries.
func (ex *Examiner) Named(name string) []*dwarf.Entry {
	sl := ex.byname[name]
	ret := make([]*dwarf.Entry, len(sl))
	for i, k := range sl {
		ret[i] = ex.entryFromIdx(k)
	}
	return ret
}

// SubprogLoAndHighPc returns the values of the lo_pc and high_pc

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Verify the DWARF producer's file index against the .debug_line file_names table length.
  2. Check whether the index should be 0-based or 1-based for the DWARF version in use.
  3. Inspect the line reader's Files() slice length and the offending fileRef to confirm the mismatch.
  4. If examining an inlined-subroutine, ensure you are reading call_file (not decl_file) and that the CU's line program includes the relevant file entries.
Defensive patterns

Strategy: validation

Validate before calling

lr, _ := dw.LineReader(cuDie)
if lr == nil { return "", nil }
files := lr.Files()
if fileRef < 0 || int(fileRef) > len(files)-1 {
    return "", nil // or handle as malformed upstream
}

Prevention

When it happens

Trigger: A subprogram or inlined-call DIE has a DW_AT_decl_file / DW_AT_call_file value that exceeds the number of entries in the CU's .debug_line file table; a zero-based vs one-based index mismatch; fileRef computed from a malformed attribute.

Common situations: Linker emits a file index referencing an entry dropped during optimization; DWARF version where file table indexing differs from the reader's expectation; corrupted attribute encoding.

Understand the failure class

Related errors


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