mattn / go-sqlite3

sqlite3 driver for go using database/sql

Home Page:http://mattn.github.io/go-sqlite3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fail to build - relocation R_X86_64_32 against `main.initdone·' can not be used when making a shared object; recompile with -fPIC

zaibon opened this issue · comments

When tying to compile a project that imports this package I get this error :

LC_ALL=EN go install -x .
WORK=/tmp/go-build323209142
mkdir -p $WORK/github.com/Zaibon/yarnouch/_obj/
mkdir -p $WORK/github.com/Zaibon/yarnouch/_obj/exe/
cd /home/zaibon/dev/go/src/github.com/Zaibon/yarnouch
/usr/lib/go/pkg/tool/linux_amd64/6g -o $WORK/github.com/Zaibon/yarnouch/_obj/_go_.6 -p github.com/Zaibon/yarnouch -complete -D _/home/zaibon/dev/go/src/github.com/Zaibon/yarnouch -I $WORK -I /home/zaibon/dev/go/pkg/linux_amd64 ./yarnouch.go
/usr/lib/go/pkg/tool/linux_amd64/pack grcP $WORK $WORK/github.com/Zaibon/yarnouch.a $WORK/github.com/Zaibon/yarnouch/_obj/_go_.6
cd .
/usr/lib/go/pkg/tool/linux_amd64/6l -o $WORK/github.com/Zaibon/yarnouch/_obj/exe/a.out -L $WORK -L /home/zaibon/dev/go/pkg/linux_amd64 $WORK/github.com/Zaibon/yarnouch.a
# github.com/Zaibon/yarnouch
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/go-link-dWUrCZ/go.o: relocation R_X86_64_32 against `main.initdone·' can not be used when making a shared object; recompile with -fPIC
/var/tmp/go-link-dWUrCZ/go.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
/usr/lib/go/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful exit status 0x100
go version
go version go1.2 linux/amd64
gcc --version
gcc (Gentoo Hardened 4.7.3-r1 p1.4, pie-0.5.5) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I tried to passed the argument '-fPIC' with -ldflags but it doesn't work.

Hmm I can't reproduce it.

I hit the same issue today and has happened to me with other Go programs that include C code.
It is due to Zalbon using a hardened system. Go linker doesn't support linking to PIE objects.

A workaround is to build your project like this:
go build -ldflags '-extldflags=-fno-PIC'

Reference and Go bug report: https://code.google.com/p/go/issues/detail?id=6940