{"record":{"id":"a1f6cff7bc841a47","repo":"golang/go","slug":"s-missing-go-export-section","errorCode":null,"errorMessage":"%s: missing .go_export section","messagePattern":"(.+?): missing \\.go_export section","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/action.go","lineNumber":409,"sourceCode":"\tb.objdirSeq++\n\treturn str.WithFilePathSeparator(filepath.Join(b.WorkDir, fmt.Sprintf(\"b%03d\", b.objdirSeq)))\n}\n\n// readpkglist returns the list of packages that were built into the shared library\n// at shlibpath. For the native toolchain this list is stored, newline separated, in\n// an ELF note with name \"Go\\x00\\x00\" and type 1. For GCCGO it is extracted from the\n// .go_export section.\nfunc readpkglist(s *modload.Loader, shlibpath string) (pkgs []*load.Package) {\n\tvar stk load.ImportStack\n\tif cfg.BuildToolchainName == \"gccgo\" {\n\t\tf, err := elf.Open(shlibpath)\n\t\tif err != nil {\n\t\t\tbase.Fatal(fmt.Errorf(\"failed to open shared library: %v\", err))\n\t\t}\n\t\tdefer f.Close()\n\t\tsect := f.Section(\".go_export\")\n\t\tif sect == nil {\n\t\t\tbase.Fatal(fmt.Errorf(\"%s: missing .go_export section\", shlibpath))\n\t\t}\n\t\tdata, err := sect.Data()\n\t\tif err != nil {\n\t\t\tbase.Fatal(fmt.Errorf(\"%s: failed to read .go_export section: %v\", shlibpath, err))\n\t\t}\n\t\tpkgpath := []byte(\"pkgpath \")\n\t\tfor _, line := range bytes.Split(data, []byte{'\\n'}) {\n\t\t\tif path, found := bytes.CutPrefix(line, pkgpath); found {\n\t\t\t\tpath = bytes.TrimSuffix(path, []byte{';'})\n\t\t\t\tpkgs = append(pkgs, load.LoadPackageWithFlags(s, string(path), base.Cwd(), &stk, nil, 0))\n\t\t\t}\n\t\t}\n\t} else {\n\t\tpkglistbytes, err := buildid.ReadELFNote(shlibpath, \"Go\\x00\\x00\", 1)\n\t\tif err != nil {\n\t\t\tbase.Fatalf(\"readELFNote failed: %v\", err)\n\t\t}\n\t\tscanner := bufio.NewScanner(bytes.NewBuffer(pkglistbytes))","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/action.go#L391-L427","documentation":"After elf.Open succeeds on a gccgo shared library, the code looks for the .go_export section, which gccgo writes to record embedded package metadata. If the section is nil, the file is ELF but not a gccgo-produced shared library, and readpkglist aborts via base.Fatal.","triggerScenarios":"A non-gccgo ELF shared library (e.g. one produced by the gc compiler's -buildmode=shared, or a plain C .so) is referenced where a gccgo .so is expected. Cache corruption mixing toolchains can also do this.","commonSituations":"Switching between gc and gccgo without 'go clean -cache'; pointing -pkgdir at a tree built by the other compiler; a hand-written makefile that mixes toolchains.","solutions":["Run 'go clean -cache' to remove cross-toolchain artifacts.","Rebuild all shared libraries with the same gccgo toolchain you're building with now.","Confirm with 'readelf -S <path>' whether .go_export is present.","Avoid mixing -buildmode=shared outputs between gc and gccgo in the same GOCACHE."],"exampleFix":"// before: cache has gc-produced .so but build is gccgo\n$ go build -compiler=gccgo -buildmode=shared -linkshared ./...\n// error: libstd.so: missing .go_export section\n\n// after\n$ go clean -cache\n$ go build -compiler=gccgo -buildmode=shared std\n$ go build -compiler=gccgo -linkshared ./...","handlingStrategy":"validation","validationCode":"// Confirm an ELF is gccgo-produced by checking for .go_export.\nfunc isGccgoShlib(path string) bool {\n    f, err := elf.Open(path)\n    if err != nil { return false }\n    defer f.Close()\n    return f.Section(\".go_export\") != nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mix gc and gccgo outputs in the same GOCACHE.","Run 'go clean -cache' after switching compilers.","Verify shared libraries with 'readelf -S' before referencing them."],"tags":["gccgo","shared-library","elf","build-cache"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}