{"record":{"id":"1f38056b1491bfea","repo":"golang/go","slug":"could-not-map-s-symbol-with-no-section","errorCode":null,"errorMessage":"could not map %s symbol with no section","messagePattern":"could not map (.+?) symbol with no section","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/pe.go","lineNumber":850,"sourceCode":"\t\tout.WriteStringN(name, 8)\n\t}\n\tout.Write32(uint32(value))\n\tout.Write16(uint16(sectidx))\n\tout.Write16(typ)\n\tout.Write8(class)\n\tout.Write8(0) // no aux entries\n\n\tldr.SetSymDynid(s, int32(f.symbolCount))\n\n\tf.symbolCount++\n}\n\n// mapToPESection searches peFile f for s symbol's location.\n// It returns PE section index, and offset within that section.\nfunc (f *peFile) mapToPESection(ldr *loader.Loader, s loader.Sym, linkmode LinkMode) (pesectidx int, offset int64, err error) {\n\tsect := ldr.SymSect(s)\n\tif sect == nil {\n\t\treturn 0, 0, fmt.Errorf(\"could not map %s symbol with no section\", ldr.SymName(s))\n\t}\n\tif sect.Seg == &Segtext {\n\t\treturn f.textSect.index, int64(uint64(ldr.SymValue(s)) - Segtext.Vaddr), nil\n\t}\n\tif sect.Seg == &Segrodata {\n\t\treturn f.rdataSect.index, int64(uint64(ldr.SymValue(s)) - Segrodata.Vaddr), nil\n\t}\n\tif sect.Seg != &Segdata {\n\t\treturn 0, 0, fmt.Errorf(\"could not map %s symbol with non .text or .rdata or .data section\", ldr.SymName(s))\n\t}\n\tv := uint64(ldr.SymValue(s)) - Segdata.Vaddr\n\tif linkmode != LinkExternal {\n\t\treturn f.dataSect.index, int64(v), nil\n\t}\n\tif ldr.SymType(s).IsDATA() {\n\t\treturn f.dataSect.index, int64(v), nil\n\t}\n\t// Note: although address of runtime.edata (type sym.SDATA) is at the start of .bss section","sourceCodeStart":832,"sourceCodeEnd":868,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/pe.go#L832-L868","documentation":"`mapToPESection` places a symbol into the PE (Windows) output by reading its associated section (`ldr.SymSect(s)`). If a symbol that needs a PE section mapping has a `nil` section, the linker has no way to compute its file offset and aborts. This typically indicates an internal inconsistency: a symbol reached the PE symbol table without ever being assigned to an output section.","triggerScenarios":"Exporting (`-ldflags='-H windowsgui'` plus `//export`) a symbol that was never defined or was dead-code-eliminated; cgo on Windows referencing an undefined external symbol; a linker bug where a symbol's section was not set during layout; mixing objects from incompatible Go versions in one binary.","commonSituations":"Cross-compiling for Windows from a non-Windows host with mismatched toolchain/cache; exporting a symbol from a package whose build tags excluded its definition; corrupt build cache after a Go upgrade.","solutions":["`go clean -cache && go build -a` to eliminate stale/inconsistent objects.","Confirm every exported (`//export`) symbol has a definition compiled in under the current build tags.","Update to a current Go release if hitting this on an older version — several such inconsistencies were fixed.","Reduce the reproducer and file a Go bug with the symbol name from the error message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Verify every //export symbol has a compiled definition\nfor pkg in $(go list ./...); do\n  grep -rn '^//export' \"$(go list -f '{{.Dir}}' \"$pkg\")\" 2>/dev/null | while read -r line; do\n    sym=$(echo \"$line\" | sed 's/.*\\/\\/export //')\n    go tool nm bin/app 2>/dev/null | grep -q \" $sym$\" || echo \"exported symbol missing: $sym\"\n  done\ndone","typeGuard":null,"tryCatchPattern":"set +e\ngo build ./...\nrc=$?\nset -e\nif [ $rc -ne 0 ]; then\n  go clean -cache && go build -a ./...\nfi","preventionTips":["Ensure every `//export` symbol's package is included under the active build tags.","Pin a single Go toolchain version for all objects.","Run `go clean -cache` after a Go upgrade before Windows/cgo builds.","Upgrade Go — several PE section-mapping bugs were fixed."],"tags":["linker","go-toolchain","windows","pe","symbols","cgo"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}