{"record":{"id":"939fe215b5c2168d","repo":"golang/go","slug":"missing-linkedit-segment","errorCode":null,"errorMessage":"missing __LINKEDIT segment","messagePattern":"missing __LINKEDIT segment","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/macho_combine_dwarf.go","lineNumber":81,"sourceCode":"\t}\n\tdefer dwarff.Close()\n\toutf, err := os.OpenFile(outexe, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outf.Close()\n\tdwarfm, err := macho.NewFile(dwarff)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer dwarfm.Close()\n\n\t// The string table needs to be the last thing in the file\n\t// for code signing to work. So we'll need to move the\n\t// linkedit section, but all the others can be copied directly.\n\tlinkseg := exem.Segment(\"__LINKEDIT\")\n\tif linkseg == nil {\n\t\treturn fmt.Errorf(\"missing __LINKEDIT segment\")\n\t}\n\n\tif _, err := exef.Seek(0, 0); err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.CopyN(outf, exef, int64(linkseg.Offset)); err != nil {\n\t\treturn err\n\t}\n\n\trealdwarf := dwarfm.Segment(\"__DWARF\")\n\tif realdwarf == nil {\n\t\treturn fmt.Errorf(\"missing __DWARF segment\")\n\t}\n\n\t// Try to compress the DWARF sections. This includes some Apple\n\t// proprietary sections like __apple_types.\n\tcompressedSects, compressedBytes, err := machoCompressSections(ctxt, dwarfm)\n\tif err != nil {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/macho_combine_dwarf.go#L63-L99","documentation":"`machoCombineDwarf` (the flow that merges DWARF from `dsymutil` back into a Mach-O executable for `-gcflags=-l` debugging) requires the executable to have a `__LINKEDIT` segment, because the string table — which must remain last for code signing — lives there and must be relocated to the end of the combined file. An executable without `__LINKEDIT` cannot be safely extended.","triggerScenarios":"Combining DWARF into a Mach-O that is not a standard executable (a dylib, a kernel extension, a stripped/corrupt binary, or an object produced by a non-Apple `ld`); passing a pre-stripped binary to the combine-DWARF step; a toolchain bug that dropped `__LINKEDIT`.","commonSituations":"Running `strip` on the binary before combineDwarf; linking with an experimental/alternative linker; building a non-executable Mach-O (bundle, object) and invoking the DWARF-combine path.","solutions":["Feed `machoCombineDwarf` a freshly linked, unstripped executable produced by the standard Apple `ld`.","Run combineDwarf before any `strip`/post-processing step.","Verify with `otool -l bin | grep -A2 LINKEDIT` that the segment exists."],"exampleFix":"# before\nstrip bin/app            # removes/alters layout\n# combineDwarf then fails\ngo build -o bin/app ./...\n\n# after: combine DWARF on the raw linker output, strip later\ngo build -o bin/app ./...\n# (combineDwarf runs internally here on the pristine binary)\nstrip bin/app","handlingStrategy":"validation","validationCode":"# Confirm the executable has a __LINKEDIT segment before combineDwarf\notool -l bin/app 2>/dev/null | grep -q 'LC_SEGMENT_64$' && otool -l bin/app | grep -A1 '__LINKEDIT' | grep -q __LINKEDIT && echo 'LINKEDIT present' || echo 'missing LINKEDIT'","typeGuard":null,"tryCatchPattern":"# Strip only after combineDwarf succeeds\nset +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":["Feed combineDwarf a freshly linked, unstripped executable.","Run combineDwarf before `strip` or any post-processor.","Verify the binary is a main executable with `file`."],"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"}