{"record":{"id":"9b5cbdcbb345376e","repo":"golang/go","slug":"text-section-not-found","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/elf.go","lineNumber":96,"sourceCode":"\t\t// try .data.rel.ro.gopclntab, for PIE binaries\n\t\tsect = f.elf.Section(\".data.rel.ro.gopclntab\")\n\t}\n\tif sect != nil {\n\t\tif pclntab, err = sect.Data(); err != nil {\n\t\t\treturn 0, nil, err\n\t\t}\n\t} else {\n\t\t// if both sections failed, try the symbol\n\t\tpclntab = f.symbolData(\"runtime.pclntab\", \"runtime.epclntab\")\n\t}\n\n\treturn textStart, pclntab, nil\n}\n\nfunc (f *elfFile) text() (textStart uint64, text []byte, err error) {\n\tsect := f.elf.Section(\".text\")\n\tif sect == nil {\n\t\treturn 0, nil, fmt.Errorf(\"text section not found\")\n\t}\n\ttextStart = sect.Addr\n\ttext, err = sect.Data()\n\treturn\n}\n\nfunc (f *elfFile) goarch() string {\n\tswitch f.elf.Machine {\n\tcase elf.EM_386:\n\t\treturn \"386\"\n\tcase elf.EM_X86_64:\n\t\treturn \"amd64\"\n\tcase elf.EM_ARM:\n\t\treturn \"arm\"\n\tcase elf.EM_AARCH64:\n\t\treturn \"arm64\"\n\tcase elf.EM_LOONGARCH:\n\t\treturn \"loong64\"","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/elf.go#L78-L114","documentation":"When analyzing an ELF binary, `elfFile.text()` retrieves the `.text` section (the machine code). It calls `f.elf.Section(\".text\")` and if the section does not exist in the ELF file, returns this error. This means the ELF binary lacks the standard executable code section that the Go toolchain expects.","triggerScenarios":"Calling `objfile.Open` or any downstream function (`File.Text()`, `File.PCLineTable()`) on an ELF binary that has no `.text` section. This can happen with stripped binaries, custom ELF layouts, relocatable object files (.o) that use non-standard section naming, or partially-linked binaries.","commonSituations":"Using `go tool objdump` or pprof on a binary that has been heavily stripped or post-processed with a tool that renames or removes sections. Pointing the tool at a relocatable `.o` file instead of a linked executable. Analyzing a non-Go ELF binary that uses a different section layout.","solutions":["Verify the file is a fully-linked ELF executable, not a relocatable `.o` object.","Check that `.text` section exists: `readelf -S <file> | grep .text`.","Rebuild the binary without aggressive stripping or section renaming.","If analyzing a third-party binary, ensure it follows standard ELF section conventions."],"exampleFix":"// before — pointing at a stripped/non-standard ELF\nf, err := objfile.Open(\"stripped_binary\")\ntextStart, text, err := f.Text()  // fails: no .text section\n\n// after — use a properly linked binary\nf, err := objfile.Open(\"normal_binary\")\ntextStart, text, err := f.Text()  // succeeds","handlingStrategy":"try-catch","validationCode":"// Check for .text section before using objfile\nfunc hasTextSection(path string) bool {\n    f, err := elf.Open(path)\n    if err != nil {\n        return false\n    }\n    defer f.Close()\n    return f.Section(\".text\") != nil\n}","typeGuard":null,"tryCatchPattern":"f, err := objfile.Open(path)\nif err != nil { return err }\ntextStart, text, err := f.Text()\nif err != nil {\n    if strings.Contains(err.Error(), \"text section not found\") {\n        // Not a standard ELF executable; fall back to symbol-only analysis\n        return analyzeSymbolsOnly(f)\n    }\n    return err\n}","preventionTips":["Verify the file is a fully linked ELF executable, not a relocatable .o.","Use 'readelf -S <file>' to check for .text before analysis.","Avoid stripping section headers from binaries meant for debugging/profiling."],"tags":["elf","binary-analysis","section","objfile"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}