golang/go · error

%s: unknown relocation type %d; compiled without -fpic?

Error message

%s: unknown relocation type %d; compiled without -fpic?

What it means

Error "%s: unknown relocation type %d; compiled without -fpic?" thrown in golang/go.

Source

Thrown at src/cmd/link/internal/loadelf/ldelf.go:1021

	// once golang.org/issue/15164 is fixed or found to not impair cmd/link
	// performance.

	const (
		AMD64   = uint32(sys.AMD64)
		ARM     = uint32(sys.ARM)
		ARM64   = uint32(sys.ARM64)
		I386    = uint32(sys.I386)
		LOONG64 = uint32(sys.Loong64)
		MIPS    = uint32(sys.MIPS)
		MIPS64  = uint32(sys.MIPS64)
		PPC64   = uint32(sys.PPC64)
		RISCV64 = uint32(sys.RISCV64)
		S390X   = uint32(sys.S390X)
	)

	switch uint32(arch.Family) | elftype<<16 {
	default:
		return 0, 0, fmt.Errorf("%s: unknown relocation type %d; compiled without -fpic?", pn, elftype)

	case MIPS | uint32(elf.R_MIPS_HI16)<<16,
		MIPS | uint32(elf.R_MIPS_LO16)<<16,
		MIPS | uint32(elf.R_MIPS_GOT16)<<16,
		MIPS | uint32(elf.R_MIPS_GOT_HI16)<<16,
		MIPS | uint32(elf.R_MIPS_GOT_LO16)<<16,
		MIPS | uint32(elf.R_MIPS_GPREL16)<<16,
		MIPS | uint32(elf.R_MIPS_GOT_PAGE)<<16,
		MIPS | uint32(elf.R_MIPS_JALR)<<16,
		MIPS | uint32(elf.R_MIPS_GOT_OFST)<<16,
		MIPS64 | uint32(elf.R_MIPS_HI16)<<16,
		MIPS64 | uint32(elf.R_MIPS_LO16)<<16,
		MIPS64 | uint32(elf.R_MIPS_GOT16)<<16,
		MIPS64 | uint32(elf.R_MIPS_GOT_HI16)<<16,
		MIPS64 | uint32(elf.R_MIPS_GOT_LO16)<<16,
		MIPS64 | uint32(elf.R_MIPS_GPREL16)<<16,
		MIPS64 | uint32(elf.R_MIPS_GOT_PAGE)<<16,
		MIPS64 | uint32(elf.R_MIPS_JALR)<<16,

View on GitHub (pinned to b6b368adc5)

When it happens

Trigger: Thrown at src/cmd/link/internal/loadelf/ldelf.go:1021 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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