golang/go · error
missing __text section
Error message
missing __text section
What it means
After copying the DWARF and `__LINKEDIT` data into the combined output, the linker needs the executable's `__text` section offset to compute where load-command header padding ends and executable code begins (it must insert the DWARF load command in that gap). A Mach-O executable without a `__text` section is not a valid executable, so the combine aborts.
Source
Thrown at src/cmd/link/internal/ld/macho_combine_dwarf.go:145
dwarfsize = realdwarf.Filesz
}
// And finally the linkedit section.
if _, err := exef.Seek(int64(linkseg.Offset), 0); err != nil {
return err
}
linkstart := Rnd(dwarfstart+int64(dwarfsize), *FlagRound)
if _, err := outf.Seek(linkstart, 0); err != nil {
return err
}
if _, err := io.Copy(outf, exef); err != nil {
return err
}
// Now we need to update the headers.
textsect := exem.Section("__text")
if textsect == nil {
return fmt.Errorf("missing __text section")
}
cmdOffset := imacho.FileHeaderSize(exem)
dwarfCmdOffset := uint32(cmdOffset) + exem.FileHeader.Cmdsz
availablePadding := textsect.Offset - dwarfCmdOffset
if availablePadding < realdwarf.Len {
return fmt.Errorf("no room to add dwarf info. Need at least %d padding bytes, found %d", realdwarf.Len, availablePadding)
}
// First, copy the dwarf load command into the header. It will be
// updated later with new offsets and lengths as necessary.
if _, err := outf.Seek(int64(dwarfCmdOffset), 0); err != nil {
return err
}
if _, err := io.CopyN(outf, bytes.NewReader(realdwarf.Raw()), int64(realdwarf.Len)); err != nil {
return err
}
if _, err := outf.Seek(int64(unsafe.Offsetof(exem.FileHeader.Ncmd)), 0); err != nil {
return errView on GitHub (pinned to b6b368adc5)
Solutions
- Confirm the input is a main executable: `file bin` should report `Mach-O ... executable`.
- Re-link with the standard Go/Apple linker to restore `__text`.
- Avoid running packers/obfuscators before the DWARF-combine step.
Defensive patterns
Strategy: validation
Validate before calling
# Confirm the input is a main executable with a __text section file bin/app | grep -q 'executable' && otool -l bin/app | grep -q __text && echo 'valid executable' || echo 'not a valid executable for combineDwarf'
Try / catch
set +e go build -o bin/app ./... rc=$? set -e if [ $rc -ne 0 ]; then rm -f bin/app && go build -o bin/app ./... fi
Prevention
- Confirm `file bin` reports an executable before combineDwarf.
- Do not pass dylibs, bundles, or relocatable objects to the combine path.
- Avoid packers/obfuscators that strip `__text` before combining.
When it happens
Trigger: Passing a non-executable Mach-O (a dylib, a relocatable object, a bundle) to the combine-DWARF flow; a corrupt or hand-edited Mach-O whose `__TEXT,__text` section was removed; linking with a tool that emits a non-standard `__TEXT` segment layout.
Common situations: Wrong file handed to combineDwarf; binary mutated by an obfuscator/packer that strips `__text`; experimental linker output missing standard sections.
Related errors
- missing __LINKEDIT segment
- no room to add dwarf info. Need at least %d padding bytes, f
- unexpected content after code signature
- missing __DWARF segment
- unknown load command 0x%x (%s)
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/d51dfebc5251a08f.
Report an issue: GitHub.