This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Allow pie links to create PLT entries


Hi,

    Here is a simple example that fails to link with -pie but which
should work just fine without having to use -fPIE.

foo.cc
======
int extern_func();
int main()
{
  extern_func();
  return 0;
}

bar.cc
=====
int extern_func()
{
  return 1;
}

$ g++ -fPIC -shared bar.cc -o libbar.so
$ g++ foo.cc -lbar -pie

ld: error: foo.o: requires dynamic R_X86_64_PC32 reloc against
'_Z11extern_funcv' which may overflow at runtime; recompile with -fPIC

It fails because the linker disallows creating a PLT for
R_X86_64_PC32 reloc when it is perfectly fine to do so.  Note that I
could have recompiled foo.cc with -fPIE or -fPIC but I still think
this can be allowed.  With support for copy relocations in pie in gold
and with this support, the cases where we would need to use -fPIE to
get working pie links is smaller.  This would help us link non-PIE
objects into pie executables.


Attached patch to fix this. I have only tested this patch on X86_64.

Please review.

Thanks
Sri

Attachment: allow_plt_for_pie.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]