{"record":{"id":"ca4284557d8a2ec7","repo":"golang/go","slug":"text-section-not-found-ca4284","errorCode":null,"errorMessage":"text section not found","messagePattern":"text section not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objfile/pe.go","lineNumber":146,"sourceCode":"\t\t// We didn't find the symbols, so look for the names used in 1.3 and earlier.\n\t\t// TODO: Remove code looking for the old symbols when we no longer care about 1.3.\n\t\tvar err2 error\n\t\tif pclntab, err2 = loadPETable(f.pe, \"pclntab\", \"epclntab\"); err2 != nil {\n\t\t\treturn 0, nil, err\n\t\t}\n\t}\n\treturn textStart, pclntab, nil\n}\n\nfunc (f *peFile) text() (textStart uint64, text []byte, err error) {\n\timageBase, err := f.imageBase()\n\tif err != nil {\n\t\treturn 0, nil, err\n\t}\n\n\tsect := f.pe.Section(\".text\")\n\tif sect == nil {\n\t\treturn 0, nil, fmt.Errorf(\"text section not found\")\n\t}\n\ttextStart = imageBase + uint64(sect.VirtualAddress)\n\ttext, err = sect.Data()\n\treturn\n}\n\nfunc findPESymbol(f *pe.File, name string) (*pe.Symbol, error) {\n\tfor _, s := range f.Symbols {\n\t\tif s.Name != name {\n\t\t\tcontinue\n\t\t}\n\t\tif s.SectionNumber <= 0 {\n\t\t\treturn nil, fmt.Errorf(\"symbol %s: invalid section number %d\", name, s.SectionNumber)\n\t\t}\n\t\tif len(f.Sections) < int(s.SectionNumber) {\n\t\t\treturn nil, fmt.Errorf(\"symbol %s: section number %d is larger than max %d\", name, s.SectionNumber, len(f.Sections))\n\t\t}\n\t\treturn s, nil","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/pe.go#L128-L164","documentation":"When analyzing a PE (Windows) binary, `peFile.text()` retrieves the `.text` section containing machine code. Before that it calls `imageBase()` which can itself fail. If `.text` section does not exist in the PE file, this error is returned. Standard Windows executables always have a `.text` section.","triggerScenarios":"Calling `objfile.Open` on a PE binary and then `File.Text()`, where the PE file has no `.text` section. This happens with stripped PE binaries, resource-only DLLs, or PE files with non-standard section naming.","commonSituations":"Analyzing a resource-only DLL that has no code section. Using `go tool objdump` or pprof on a PE binary that was processed by a packer or obfuscator that renames sections. Pointing at a PE file that is not a normal executable (e.g., a `.cpl` with non-standard layout).","solutions":["Verify the `.text` section exists: `dumpbin /headers <file>` or use a PE viewer.","Rebuild the binary without packers/obfuscators that rename sections.","If analyzing a resource DLL or non-code PE, use the appropriate tool rather than `objfile`.","Unpack or restore original section names if the binary was processed by UPX or similar."],"exampleFix":"// before — packed PE with renamed sections\nf, err := objfile.Open(\"packed.exe\")\n_, _, err := f.Text()  // fails: no .text section\n\n// after — unpack first or rebuild\n$ upx -d packed.exe  # decompress\nf, err := objfile.Open(\"packed.exe\")\n_, _, err := f.Text()  // succeeds","handlingStrategy":"try-catch","validationCode":"// Check for .text section in PE\nfunc hasPETextSection(path string) bool {\n    f, err := pe.Open(path)\n    if err != nil { return false }\n    defer f.Close()\n    for _, s := range f.Sections {\n        if s.Name == \".text\" { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"_, text, err := f.Text()\nif err != nil && strings.Contains(err.Error(), \"text section not found\") {\n    return analyzeSymbolsOnly(f)\n}","preventionTips":["Use 'dumpbin /headers <file>' to verify .text section exists.","Avoid using PE packers/obfuscators on binaries meant for analysis.","Unpack UPX-compressed binaries before running objfile tools."],"tags":["pe","windows","binary-analysis","section","objfile"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}