golang/go · error
text section not found
Error message
text section not found
What it means
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.
Source
Thrown at src/cmd/internal/objfile/pe.go:146
// We didn't find the symbols, so look for the names used in 1.3 and earlier.
// TODO: Remove code looking for the old symbols when we no longer care about 1.3.
var err2 error
if pclntab, err2 = loadPETable(f.pe, "pclntab", "epclntab"); err2 != nil {
return 0, nil, err
}
}
return textStart, pclntab, nil
}
func (f *peFile) text() (textStart uint64, text []byte, err error) {
imageBase, err := f.imageBase()
if err != nil {
return 0, nil, err
}
sect := f.pe.Section(".text")
if sect == nil {
return 0, nil, fmt.Errorf("text section not found")
}
textStart = imageBase + uint64(sect.VirtualAddress)
text, err = sect.Data()
return
}
func findPESymbol(f *pe.File, name string) (*pe.Symbol, error) {
for _, s := range f.Symbols {
if s.Name != name {
continue
}
if s.SectionNumber <= 0 {
return nil, fmt.Errorf("symbol %s: invalid section number %d", name, s.SectionNumber)
}
if len(f.Sections) < int(s.SectionNumber) {
return nil, fmt.Errorf("symbol %s: section number %d is larger than max %d", name, s.SectionNumber, len(f.Sections))
}
return s, nilView on GitHub (pinned to b6b368adc5)
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.
Example fix
// before — packed PE with renamed sections
f, err := objfile.Open("packed.exe")
_, _, err := f.Text() // fails: no .text section
// after — unpack first or rebuild
$ upx -d packed.exe # decompress
f, err := objfile.Open("packed.exe")
_, _, err := f.Text() // succeeds Defensive patterns
Strategy: try-catch
Validate before calling
// Check for .text section in PE
func hasPETextSection(path string) bool {
f, err := pe.Open(path)
if err != nil { return false }
defer f.Close()
for _, s := range f.Sections {
if s.Name == ".text" { return true }
}
return false
} Try / catch
_, text, err := f.Text()
if err != nil && strings.Contains(err.Error(), "text section not found") {
return analyzeSymbolsOnly(f)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- text section not found
- text section not found
- invalid section number in symbol table
- symbol %s: invalid section number %d
- symbol %s: section number %d is larger than max %d
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/ca4284557d8a2ec7.
Report an issue: GitHub.