DMD Fails with fPIC error

Reuben via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 17 23:51:17 PDT 2014


On Sunday, 15 June 2014 at 09:08:10 UTC, Mike Wey wrote:
> On 06/14/2014 06:37 PM, Reuben wrote:
>> It looks like the only difference is which version of Phobos 
>> we link. I
>> think the reason for this might be that since my version of 
>> gcc is
>> hardened, it uses -fPIE by default for linking.
>> (http://wiki.gentoo.org/wiki/Hardened/Toolchain#Automatic_generation_of_Position_Independent_Executables_.28PIEs.29)
>
> In that case the static Phobos needs to be build with -fPIC, 
> which currently isn't the case looking at the Ebuild.

Compiling DMD with PIC=1 doesn't seem to do the trick. -fPIC is 
used for the C files, but when linking Phobos the following 
appears:
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>generated/linux/release/64/libphobos2.so.0..o: warning: 
>relocation in readonly section `.deh_eh'.
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>warning: creating a DT_TEXTREL in object.

Compiling with it then gives the following:
> $ ./dmd test.d
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>test.o: warning: relocation in readonly section 
>`.text._D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv'.
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>test.o: relocation R_X86_64_PC32 against undefined symbol 
>`fprintf@@GLIBC_2.2.5' can not be used when making a shared 
>object; recompile with -fPIC
>/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/../../../../x86_64-pc-linux-gnu/bin/ld: 
>>final link failed: Bad value
>collect2: error: ld returned 1 exit status
>--- errorlevel 1

readelf doesn't show any TEXTRELs in libc, so I assume it is also 
hardened.


More information about the Digitalmars-d-learn mailing list