golang/go · error

text section not found

Error message

text section not found

What it means

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.

Source

Thrown at src/cmd/internal/objfile/macho.go:97

	return syms, nil
}

func (f *machoFile) pcln() (textStart uint64, pclntab []byte, err error) {
	if sect := f.macho.Section("__text"); sect != nil {
		textStart = sect.Addr
	}
	if sect := f.macho.Section("__gopclntab"); sect != nil {
		if pclntab, err = sect.Data(); err != nil {
			return 0, nil, err
		}
	}
	return textStart, pclntab, nil
}

func (f *machoFile) text() (textStart uint64, text []byte, err error) {
	sect := f.macho.Section("__text")
	if sect == nil {
		return 0, nil, fmt.Errorf("text section not found")
	}
	textStart = sect.Addr
	text, err = sect.Data()
	return
}

func (f *machoFile) goarch() string {
	switch f.macho.Cpu {
	case macho.Cpu386:
		return "386"
	case macho.CpuAmd64:
		return "amd64"
	case macho.CpuArm:
		return "arm"
	case macho.CpuArm64:
		return "arm64"
	case macho.CpuPpc64:
		return "ppc64"

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Verify the `__text` section exists: `otool -l <file> | grep __text` or `size -m <file>`.
  2. Rebuild the binary without aggressive section stripping.
  3. Ensure the file is a standard Mach-O executable, not a bundle or KC.
  4. Use a macOS-native disassembler for non-standard Mach-O files.

Example fix

// before — analyzing a stripped Mach-O
f, err := objfile.Open("stripped_macos_bin")
_, _, err := f.Text()  // fails: no __text section

// after — use a properly linked macOS binary
f, err := objfile.Open("normal_macos_bin")
_, _, err := f.Text()  // succeeds
Defensive patterns

Strategy: try-catch

Validate before calling

// Check for __text section in Mach-O
func hasTextSection(path string) bool {
    f, err := macho.Open(path)
    if err != nil { return false }
    defer f.Close()
    return f.Section("__text") != nil
}

Try / catch

textStart, text, err := f.Text()
if err != nil && strings.Contains(err.Error(), "text section not found") {
    // Not a standard Mach-O executable
    return analyzeSymbolsOnly(f)
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/c37ab98f689d60af. Report an issue: GitHub.