golang/go · error

text section not found

Error message

text section not found

What it means

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.

Source

Thrown at src/cmd/internal/objfile/elf.go:96

		// try .data.rel.ro.gopclntab, for PIE binaries
		sect = f.elf.Section(".data.rel.ro.gopclntab")
	}
	if sect != nil {
		if pclntab, err = sect.Data(); err != nil {
			return 0, nil, err
		}
	} else {
		// if both sections failed, try the symbol
		pclntab = f.symbolData("runtime.pclntab", "runtime.epclntab")
	}

	return textStart, pclntab, nil
}

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

func (f *elfFile) goarch() string {
	switch f.elf.Machine {
	case elf.EM_386:
		return "386"
	case elf.EM_X86_64:
		return "amd64"
	case elf.EM_ARM:
		return "arm"
	case elf.EM_AARCH64:
		return "arm64"
	case elf.EM_LOONGARCH:
		return "loong64"

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Verify the file is a fully-linked ELF executable, not a relocatable `.o` object.
  2. Check that `.text` section exists: `readelf -S <file> | grep .text`.
  3. Rebuild the binary without aggressive stripping or section renaming.
  4. If analyzing a third-party binary, ensure it follows standard ELF section conventions.

Example fix

// before — pointing at a stripped/non-standard ELF
f, err := objfile.Open("stripped_binary")
textStart, text, err := f.Text()  // fails: no .text section

// after — use a properly linked binary
f, err := objfile.Open("normal_binary")
textStart, text, err := f.Text()  // succeeds
Defensive patterns

Strategy: try-catch

Validate before calling

// Check for .text section before using objfile
func hasTextSection(path string) bool {
    f, err := elf.Open(path)
    if err != nil {
        return false
    }
    defer f.Close()
    return f.Section(".text") != nil
}

Try / catch

f, err := objfile.Open(path)
if err != nil { return err }
textStart, text, err := f.Text()
if err != nil {
    if strings.Contains(err.Error(), "text section not found") {
        // Not a standard ELF executable; fall back to symbol-only analysis
        return analyzeSymbolsOnly(f)
    }
    return err
}

Prevention

When it happens

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

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

Related errors


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