[Bug go/65616] New: libgobegin.a not compiled with -fPIC
nyh at math dot technion.ac.il
gcc-bugzilla@gcc.gnu.org
Sun Mar 29 13:41:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65616
Bug ID: 65616
Summary: libgobegin.a not compiled with -fPIC
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: go
Assignee: ian at airs dot com
Reporter: nyh at math dot technion.ac.il
CC: cmang at google dot com
When one tries to build a position-independent executable (PIE or shared
object) with gccgo, the final linking stage fails. For example:
$ gccgo -pie -fpie hello.go
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgobegin.a(go-main.o):
relocation R_X86_64_32 against `runtime_main' can not be used when making a
shared object; recompile with -fPIC
The problem is that libgobegin.a was not compiled with -fPIC, so the main() it
contains is not usable to produce a shared object or PIE. That could easily be
rectified - go-main.c should be compiled with -fPIC. The main() function is
obviously not performance sensitive, so there is no downside in compiling it
with -fPIC.
When I compile go-main.o myself with -fPIC, and do "gccgo -pie -fpic hello.go
go-main.o", things work correctly.
There are many reasons why someone might want to produce a PIE or shared
object. My personal interest is for the OSv operating system (http://osv.io),
which can run Linux executables, but only position-independent ones (because
OSv is a single-address-space operating system).
More information about the Gcc-bugs
mailing list