Does gcc enable -fPIC by default?

Alexander Monakov amonakov@ispras.ru
Thu Jan 24 15:02:00 GMT 2019


On Thu, 24 Jan 2019, Peng Yu wrote:

> Is it because gcc enables -fPIC by default, but clang does not? I
> don't see this documented. Or it is due to some other reasons. On what
> systems gcc enables -fPIC by default?

There are platforms (e.g. Darwin) where all code is implicitly PIC by
convention (but there Clang will emit position-independent code as well),
but in your case the issue is likely because in your distribution GCC
is configured to produce PIE by default (see --enable-default-pie in
output of gcc -v):

> configure:3772: gcc -g -finstrument-functions
> -L/root/linux/bin/wrappercomposite/src/xplat/llvmxplat/src/mkvar/bin/Linux
> conftest.c -ltrace >&5
> /usr/bin/ld: /root/linux/bin/wrappercomposite/src/xplat/llvmxplat/src/mkvar/bin/Linux/libtrace.a(trace.o):
> relocation R_X86_64_32S against `.bss' can not be used when making a
> PIE object; recompile with -fPIC

   ^^^^^^^^^
   (as the error message hints)

Hope that helps.
Alexander



More information about the Gcc-help mailing list