{"record":{"id":"d51dfebc5251a08f","repo":"golang/go","slug":"missing-text-section","errorCode":null,"errorMessage":"missing __text section","messagePattern":"missing __text section","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/macho_combine_dwarf.go","lineNumber":145,"sourceCode":"\t\tdwarfsize = realdwarf.Filesz\n\t}\n\n\t// And finally the linkedit section.\n\tif _, err := exef.Seek(int64(linkseg.Offset), 0); err != nil {\n\t\treturn err\n\t}\n\tlinkstart := Rnd(dwarfstart+int64(dwarfsize), *FlagRound)\n\tif _, err := outf.Seek(linkstart, 0); err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.Copy(outf, exef); err != nil {\n\t\treturn err\n\t}\n\n\t// Now we need to update the headers.\n\ttextsect := exem.Section(\"__text\")\n\tif textsect == nil {\n\t\treturn fmt.Errorf(\"missing __text section\")\n\t}\n\n\tcmdOffset := imacho.FileHeaderSize(exem)\n\tdwarfCmdOffset := uint32(cmdOffset) + exem.FileHeader.Cmdsz\n\tavailablePadding := textsect.Offset - dwarfCmdOffset\n\tif availablePadding < realdwarf.Len {\n\t\treturn fmt.Errorf(\"no room to add dwarf info. Need at least %d padding bytes, found %d\", realdwarf.Len, availablePadding)\n\t}\n\t// First, copy the dwarf load command into the header. It will be\n\t// updated later with new offsets and lengths as necessary.\n\tif _, err := outf.Seek(int64(dwarfCmdOffset), 0); err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.CopyN(outf, bytes.NewReader(realdwarf.Raw()), int64(realdwarf.Len)); err != nil {\n\t\treturn err\n\t}\n\tif _, err := outf.Seek(int64(unsafe.Offsetof(exem.FileHeader.Ncmd)), 0); err != nil {\n\t\treturn err","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/macho_combine_dwarf.go#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"Wrong file handed to combineDwarf; binary mutated by an obfuscator/packer that strips `__text`; experimental linker output missing standard sections.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Confirm the input is a main executable with a __text section\nfile bin/app | grep -q 'executable' && otool -l bin/app | grep -q __text && echo 'valid executable' || echo 'not a valid executable for combineDwarf'","typeGuard":null,"tryCatchPattern":"set +e\ngo build -o bin/app ./...\nrc=$?\nset -e\nif [ $rc -ne 0 ]; then\n  rm -f bin/app && go build -o bin/app ./...\nfi","preventionTips":["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."],"tags":["linker","go-toolchain","macos","dwarf","mach-o"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}