golang/go · error

gccgo -importcfg does not support shared libraries

Error message

gccgo -importcfg does not support shared libraries

What it means

The gccgo importcfg reader encounters a `packageshlib` directive, which is only valid for the gc toolchain's shared-library mode (-buildmode=shared / -linkshared). gccgo does not support this directive through importcfg, so any occurrence returns this error immediately.

Source

Thrown at src/cmd/go/internal/work/gccgo.go:192

				return err
			}
		case "importmap":
			if before == "" || after == "" {
				return fmt.Errorf(`importcfg:%d: invalid importmap: syntax is "importmap old=new": %s`, lineNum, line)
			}
			beforeA := gccgoArchive(root, before)
			afterA := gccgoArchive(root, after)
			if err := sh.Mkdir(filepath.Dir(beforeA)); err != nil {
				return err
			}
			if err := sh.Mkdir(filepath.Dir(afterA)); err != nil {
				return err
			}
			if err := sh.Symlink(afterA, beforeA); err != nil {
				return err
			}
		case "packageshlib":
			return fmt.Errorf("gccgo -importcfg does not support shared libraries")
		}
	}
	return nil
}

func (tools gccgoToolchain) asm(b *Builder, a *Action, sfiles []string) ([]string, error) {
	p := a.Package
	var ofiles []string
	for _, sfile := range sfiles {
		base := filepath.Base(sfile)
		ofile := a.Objdir + base[:len(base)-len(".s")] + ".o"
		ofiles = append(ofiles, ofile)
		sfile = fsys.Actual(mkAbs(p.Dir, sfile))
		defs := []string{"-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch}
		if pkgpath := tools.gccgoCleanPkgpath(b, p); pkgpath != "" {
			defs = append(defs, `-D`, `GOPKGPATH=`+pkgpath)
		}
		defs = tools.maybePIC(defs)

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Do not use -buildmode=shared or -linkshared with gccgo
  2. Switch to the gc toolchain if shared-library mode is required
  3. Build statically with gccgo instead

Example fix

// before (unsupported with gccgo)
go build -buildmode=shared -compiler=gccgo std
// after (use gc for shared mode)
go build -buildmode=shared std
Defensive patterns

Strategy: validation

Validate before calling

// Reject shared-library buildmode when using gccgo before building
if os.Getenv("GOCompiler") == "gccgo" || strings.Contains(buildmode, "shared") {
    if strings.Contains(buildmode, "shared") && compilerIsGccgo {
        return fmt.Errorf("gccgo does not support shared-library mode via importcfg")
    }
}

Prevention

When it happens

Trigger: Fires in the gccgo importcfg reader's `case "packageshlib"` branch - any presence of that directive when compiling/linking with -compiler=gccgo.

Common situations: Passing -buildmode=shared or -linkshared together with -compiler=gccgo, or mixing gc-built shared libraries into a gccgo build.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/f7556c0eb5441a40. Report an issue: GitHub.