Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zaibon opened this issue Jun 10, 2014 · 2 comments

Comments

@zaibon
Copy link

zaibon commented Jun 10, 2014

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.

@mattn
Copy link
Owner

mattn commented Jun 25, 2014

Hmm I can't reproduce it.

@andmarios
Copy link

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

@mattn mattn closed this as completed in 3526997 May 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants