This is the mail archive of the
mailing list for the binutils project.
Re: call gcc no -fpic/-fpie only -pie?
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: zet <feqin1023 at gmail dot com>, Binutils <binutils at sourceware dot org>
- Date: Fri, 1 Jul 2016 08:08:35 -0700
- Subject: Re: call gcc no -fpic/-fpie only -pie?
- Authentication-results: sourceware.org; auth=none
- References: <CAOfAq_pfpczZjjoMjAF_HGczNxhJQ+tbSwu_y56DpGyh=+wJEw at mail dot gmail dot com> <b885fee7-ef0f-2c5b-2b60-f8e3f5953f66 at redhat dot com>
>> But the ld manual said if specify -pie should specify -fpic etc.
> Where does it say this ? I tried looking for it, but did not find it
It's actually the GCC manual that says this. For -shared, you should
use -fpic, and for -pie, you should use -fpie.
>> static relocation type only has R_386_32/R_386_PC32, they should be
>> changed to dynamic relocation type R_386_COPY/R_386_GLOB_DAT etc by
>> ld. If so why not manual said that( if specify -pie should specify
>> -fpic etc) ? If not , what the details that cannot be changed to
>> dynamic link?
I'm not really sure I understand what the question is.
If you're wondering why your program worked even though you didn't
also specify -fpie, it's probably because the 32-bit x86 ABI allows
dynamic text relocations. The reason for the recommendation is to make
sure that the text segment can be fully sharable, and text relocations
will result in a per-process copy of each page that has a relocation
applied. Try adding the -Wl,--warn-shared-textrel option. (It could
also be that your test program is simple enough that no dynamic text
relocations were needed.)