{"record":{"id":"11af8cc668883567","repo":"golang/go","slug":"open-s-unrecognized-object-file","errorCode":null,"errorMessage":"open %s: unrecognized object file","messagePattern":"open (.+?): unrecognized object file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objfile/objfile.go","lineNumber":87,"sourceCode":"// Open opens the named file.\n// The caller must call f.Close when the file is no longer needed.\nfunc Open(name string) (*File, error) {\n\tr, err := os.Open(name)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif f, err := openGoFile(r); err == nil {\n\t\treturn f, nil\n\t} else if _, ok := err.(archive.ErrGoObjOtherVersion); ok {\n\t\treturn nil, fmt.Errorf(\"open %s: %v\", name, err)\n\t}\n\tfor _, try := range openers {\n\t\tif raw, err := try(r); err == nil {\n\t\t\treturn &File{r, []*Entry{{raw: raw}}}, nil\n\t\t}\n\t}\n\tr.Close()\n\treturn nil, fmt.Errorf(\"open %s: unrecognized object file\", name)\n}\n\nfunc (f *File) Close() error {\n\treturn f.r.Close()\n}\n\nfunc (f *File) Entries() []*Entry {\n\treturn f.entries\n}\n\nfunc (f *File) Symbols() ([]Sym, error) {\n\treturn f.entries[0].Symbols()\n}\n\nfunc (f *File) PCLineTable() (Liner, error) {\n\treturn f.entries[0].PCLineTable()\n}\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/objfile.go#L69-L105","documentation":"`objfile.Open` tries to parse the input as a Go object file, then tries all registered openers (ELF, Mach-O, PE, Plan9, XCOFF). If every opener fails, the file is unrecognizable as any known object or executable format, and this error is returned. The file either is not a binary object at all or uses an unsupported format.","triggerScenarios":"Calling `objfile.Open` on a file that is not a Go object, archive, ELF, Mach-O, PE, Plan9, or XCOFF binary. For example, a text file, a script, a WebAssembly binary, a Java `.class` file, or a binary in an unsupported format.","commonSituations":"Passing the wrong file path to a tool that expects a binary (e.g., passing a source file to `go tool objdump`). Pointing at a compressed or archive-wrapped binary without extracting first. Analyzing a binary format that the Go `objfile` package does not support (e.g., WASM, which has its own separate reader). Corrupted or truncated binaries.","solutions":["Verify the file is actually a binary: `file <path>` to see its format.","Ensure the binary format is one of ELF, Mach-O, PE, Plan9, or XCOFF — or a Go `.o`/`.a` file.","If the file is compressed or in a container (e.g., .tar.gz, .zip), extract it first.","For WebAssembly, use `go tool wasm` or the appropriate WASM reader, not `objfile.Open`."],"exampleFix":"// before — wrong file type\nf, err := objfile.Open(\"main.go\")  // fails: not a binary\n\n// after — use the compiled binary\n$ go build -o main main.go\nf, err := objfile.Open(\"main\")  // succeeds","handlingStrategy":"validation","validationCode":"// Validate file is a recognized binary format\nfunc isRecognizedBinary(path string) bool {\n    f, err := os.Open(path)\n    if err != nil { return false }\n    defer f.Close()\n    magic := make([]byte, 16)\n    n, _ := f.Read(magic)\n    magic = magic[:n]\n    // ELF\n    if bytes.HasPrefix(magic, []byte{0x7f, 'E', 'L', 'F'}) { return true }\n    // Mach-O 64\n    if bytes.HasPrefix(magic, []byte{0xfe, 0xed, 0xfa, 0xcf}) { return true }\n    // Mach-O 32\n    if bytes.HasPrefix(magic, []byte{0xce, 0xfa, 0xed, 0xfe}) { return true }\n    // PE\n    if bytes.HasPrefix(magic, []byte{'M', 'Z'}) { return true }\n    // Plan9\n    if len(magic) >= 4 && (magic[0] == 0x00 || magic[0] == 0x80) { return true }\n    // Go object\n    if bytes.HasPrefix(magic, []byte(\"goobj\")) || bytes.HasPrefix(magic, []byte(\"!<arch>\")) { return true }\n    return false\n}","typeGuard":null,"tryCatchPattern":"f, err := objfile.Open(path)\nif err != nil && strings.Contains(err.Error(), \"unrecognized object file\") {\n    out, _ := exec.Command(\"file\", path).Output()\n    return fmt.Errorf(\"%s is not a recognized binary format: %s\", path, out)\n}","preventionTips":["Run 'file <path>' before passing to objfile-based tools.","Extract binaries from archives (.zip, .tar.gz) before analysis.","Ensure the file is a linked binary, not a source file or script."],"tags":["objfile","binary-format","file-type","unrecognized"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}