Allow pie links to create PLT entries
Sriraman Tallam
tmsriram@google.com
Thu Jan 29 19:00:00 GMT 2015
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
-------------- next part --------------
* symtab.h (needs_plt_entry): Allow pie links to generate PLT
entries.
(needs_dynamic_reloc): Remove check for position independence
when disallowing dynamic relocation for PLT entry.
diff --git a/gold/symtab.h b/gold/symtab.h
index aa0cb68..7de5e99 100644
--- a/gold/symtab.h
+++ b/gold/symtab.h
@@ -639,10 +639,8 @@ class Symbol
if (!this->is_func())
return false;
- // If we're doing a static link or a -pie link, we don't create
- // PLT entries.
- if (parameters->doing_static_link()
- || parameters->options().pie())
+ // If we're doing a static link we don't create PLT entries.
+ if (parameters->doing_static_link())
return false;
// We need a PLT entry if the function is defined in a dynamic
@@ -706,10 +704,9 @@ class Symbol
if ((flags & FUNCTION_CALL) && this->has_plt_offset())
return false;
- // A reference to any PLT entry in a non-position-independent executable
- // does not need a dynamic relocation.
+ // A reference to any PLT entry in an executable does not need a dynamic
+ // relocation.
if (!(flags & FUNC_DESC_ABI)
- && !parameters->options().output_is_position_independent()
&& this->has_plt_offset())
return false;
More information about the Binutils
mailing list