{"record":{"id":"c37ab98f689d60af","repo":"golang/go","slug":"text-section-not-found-c37ab9","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/macho.go","lineNumber":97,"sourceCode":"\treturn syms, nil\n}\n\nfunc (f *machoFile) pcln() (textStart uint64, pclntab []byte, err error) {\n\tif sect := f.macho.Section(\"__text\"); sect != nil {\n\t\ttextStart = sect.Addr\n\t}\n\tif sect := f.macho.Section(\"__gopclntab\"); sect != nil {\n\t\tif pclntab, err = sect.Data(); err != nil {\n\t\t\treturn 0, nil, err\n\t\t}\n\t}\n\treturn textStart, pclntab, nil\n}\n\nfunc (f *machoFile) text() (textStart uint64, text []byte, err error) {\n\tsect := f.macho.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 *machoFile) goarch() string {\n\tswitch f.macho.Cpu {\n\tcase macho.Cpu386:\n\t\treturn \"386\"\n\tcase macho.CpuAmd64:\n\t\treturn \"amd64\"\n\tcase macho.CpuArm:\n\t\treturn \"arm\"\n\tcase macho.CpuArm64:\n\t\treturn \"arm64\"\n\tcase macho.CpuPpc64:\n\t\treturn \"ppc64\"","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/macho.go#L79-L115","documentation":"When analyzing a Mach-O binary (macOS/iOS), `machoFile.text()` retrieves the `__text` section (the machine code segment). If the Mach-O file has no `__text` section, this error is returned. All standard macOS executables and dylibs contain a `__TEXT` segment with a `__text` section; its absence indicates a non-standard or corrupt binary.","triggerScenarios":"Calling `objfile.Open` and then `File.Text()` on a Mach-O file that lacks the `__text` section. This can occur with stripped macOS binaries, non-standard Mach-O layouts, or when analyzing Mach-O files that are not standard executables (e.g., KC files, firmware, or custom Mach-O variants).","commonSituations":"Using `go tool objdump` or pprof on a macOS binary that was processed by a tool that strips or renames sections. Analyzing a non-Go Mach-O binary with an unusual section layout. Pointing the tool at a Mach-O bundle or KC file instead of an executable.","solutions":["Verify the `__text` section exists: `otool -l <file> | grep __text` or `size -m <file>`.","Rebuild the binary without aggressive section stripping.","Ensure the file is a standard Mach-O executable, not a bundle or KC.","Use a macOS-native disassembler for non-standard Mach-O files."],"exampleFix":"// before — analyzing a stripped Mach-O\nf, err := objfile.Open(\"stripped_macos_bin\")\n_, _, err := f.Text()  // fails: no __text section\n\n// after — use a properly linked macOS binary\nf, err := objfile.Open(\"normal_macos_bin\")\n_, _, err := f.Text()  // succeeds","handlingStrategy":"try-catch","validationCode":"// Check for __text section in Mach-O\nfunc hasTextSection(path string) bool {\n    f, err := macho.Open(path)\n    if err != nil { return false }\n    defer f.Close()\n    return f.Section(\"__text\") != nil\n}","typeGuard":null,"tryCatchPattern":"textStart, text, err := f.Text()\nif err != nil && strings.Contains(err.Error(), \"text section not found\") {\n    // Not a standard Mach-O executable\n    return analyzeSymbolsOnly(f)\n}","preventionTips":["Verify __text section exists with 'otool -l <file>' before analysis.","Avoid stripping or renaming sections in binaries meant for profiling.","Ensure the Mach-O file is a standard executable, not a bundle or stub."],"tags":["macho","binary-analysis","section","macos","objfile"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}