golang/go · error

pe file format not recognized

Error message

pe file format not recognized

What it means

imageBase() reads the PE optional header to recover the image load base address, switching on *pe.OptionalHeader32 and *pe.OptionalHeader64. Any other optional-header type (or nil/missing) means the file is not a recognizable PE executable, so the loader declines to guess. This is the loadAddress path used when computing virtual addresses for symbols.

Source

Thrown at src/cmd/internal/objfile/pe.go:213

	case pe.IMAGE_FILE_MACHINE_ARM64:
		return "arm64"
	default:
		return ""
	}
}

func (f *peFile) loadAddress() (uint64, error) {
	return f.imageBase()
}

func (f *peFile) imageBase() (uint64, error) {
	switch oh := f.pe.OptionalHeader.(type) {
	case *pe.OptionalHeader32:
		return uint64(oh.ImageBase), nil
	case *pe.OptionalHeader64:
		return oh.ImageBase, nil
	default:
		return 0, fmt.Errorf("pe file format not recognized")
	}
}

func (f *peFile) dwarf() (*dwarf.Data, error) {
	return f.pe.DWARF()
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Verify the file is actually a PE/COFF executable (run 'file <binary>').
  2. Rebuild the binary; if it is genuinely PE, ensure it was not truncated.
  3. Let the objfile format detector pick the right backend rather than forcing PE.
Defensive patterns

Strategy: validation

Validate before calling

// Before treating a file as PE, confirm its magic.
// import "debug/pe"
// f, err := pe.Open(path)
// if err != nil { /* not PE */ }
// if f.OptionalHeader == nil { /* not a recognizable PE */ }

Try / catch

// base, err := pf.loadAddress()
// if err != nil {
//     // 'pe file format not recognized' -> wrong backend or corrupt PE
//     return 0, err
// }

Prevention

When it happens

Trigger: Calling peFile.loadAddress() (or any code that needs the image base) on a pe.File whose OptionalHeader is neither *pe.OptionalHeader32 nor *pe.OptionalHeader64.

Common situations: A non-PE file was opened through the PE code path (wrong format detection), a truncated/corrupted PE, or an unusual PE-like image (EFI/ROM) with headers the debug/pe package does not model.

Related errors


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