{"record":{"id":"07e660f487bbc41e","repo":"golang/go","slug":"symbol-s-invalid-section-number-d","errorCode":null,"errorMessage":"symbol %s: invalid section number %d","messagePattern":"symbol (.+?): invalid section number (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objfile/pe.go","lineNumber":159,"sourceCode":"\t\treturn 0, nil, err\n\t}\n\n\tsect := f.pe.Section(\".text\")\n\tif sect == nil {\n\t\treturn 0, nil, fmt.Errorf(\"text section not found\")\n\t}\n\ttextStart = imageBase + uint64(sect.VirtualAddress)\n\ttext, err = sect.Data()\n\treturn\n}\n\nfunc findPESymbol(f *pe.File, name string) (*pe.Symbol, error) {\n\tfor _, s := range f.Symbols {\n\t\tif s.Name != name {\n\t\t\tcontinue\n\t\t}\n\t\tif s.SectionNumber <= 0 {\n\t\t\treturn nil, fmt.Errorf(\"symbol %s: invalid section number %d\", name, s.SectionNumber)\n\t\t}\n\t\tif len(f.Sections) < int(s.SectionNumber) {\n\t\t\treturn nil, fmt.Errorf(\"symbol %s: section number %d is larger than max %d\", name, s.SectionNumber, len(f.Sections))\n\t\t}\n\t\treturn s, nil\n\t}\n\treturn nil, fmt.Errorf(\"no %s symbol found\", name)\n}\n\nfunc loadPETable(f *pe.File, sname, ename string) ([]byte, error) {\n\tssym, err := findPESymbol(f, sname)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tesym, err := findPESymbol(f, ename)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objfile/pe.go#L141-L177","documentation":"In `findPESymbol`, when iterating the PE symbol table, each symbol's `SectionNumber` must be positive (> 0) to reference a real section. Values ≤ 0 have special meaning (N_UNDEF = 0, N_ABS = -1, N_DEBUG = -2) and do not point to a section. This error fires when `findPESymbol` is looking up a specific named symbol that has one of these special section numbers, making it impossible to resolve its section-relative address.","triggerScenarios":"Calling `findPESymbol` (internally during `loadPETable` or `pcln`) for a symbol that exists in the PE symbol table but has `SectionNumber <= 0`, indicating it is undefined, absolute, or a debug symbol. This is common when looking for runtime tables (e.g., `runtime.pclntab`) in a binary where those symbols are marked as undefined.","commonSituations":"Analyzing a Windows `.exe` or `.dll` where the Go runtime tables were stripped or marked undefined. Linking issues where the linker did not resolve all symbols. Examining a PE binary compiled with `-ldflags=-s` that strips symbol information. Using a PE binary built by an older or non-standard Go linker.","solutions":["Rebuild the binary without symbol stripping: remove `-ldflags=-s -w`.","Verify the symbol exists and has a valid section: `dumpbin /symbols <file> | grep pclntab`.","Ensure the Go linker version matches the compiler version.","If the binary must be stripped, accept that some symbol lookups will fail and handle the error gracefully."],"exampleFix":"// before — binary built with stripping\n$ go build -ldflags=\"-s -w\" -o app.exe\n// findPESymbol(\"runtime.pclntab\") fails: SectionNumber <= 0\n\n// after — build without stripping for analysis\n$ go build -o app.exe\n// findPESymbol(\"runtime.pclntab\") succeeds","handlingStrategy":"validation","validationCode":"// Check symbol section number validity before lookup\nfunc findPESymbolSafe(f *pe.File, name string) (*pe.Symbol, error) {\n    for _, s := range f.Symbols {\n        if s.Name != name { continue }\n        if s.SectionNumber <= 0 {\n            return nil, fmt.Errorf(\"symbol %s has special section number %d (undefined/absolute/debug)\", name, s.SectionNumber)\n        }\n        if int(s.SectionNumber) > len(f.Sections) {\n            return nil, fmt.Errorf(\"symbol %s section %d exceeds section count %d\", name, s.SectionNumber, len(f.Sections))\n        }\n        return s, nil\n    }\n    return nil, fmt.Errorf(\"symbol %s not found\", name)\n}","typeGuard":null,"tryCatchPattern":"sym, err := findPESymbol(pe, \"runtime.pclntab\")\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid section number\") {\n        // Symbol is undefined/debug — binary may be stripped\n        return fmt.Errorf(\"runtime symbol is undefined — rebuild without -ldflags=-s\")\n    }\n    return err\n}","preventionTips":["Do not build with -ldflags=-s if the binary needs runtime symbol access.","Verify symbols with 'go tool nm' or 'dumpbin /symbols' before analysis.","Use consistent Go toolchain versions for compiling and linking."],"tags":["pe","windows","symbol-table","objfile","pclntab"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}