[PATCH] X86-64: Allow copy relocs for building PIE

H.J. Lu hongjiu.lu@intel.com
Wed Dec 3 00:59:00 GMT 2014


On Tue, Dec 02, 2014 at 04:53:19PM -0800, H.J. Lu wrote:
> On Tue, Dec 02, 2014 at 03:20:07PM -0800, H.J. Lu wrote:
> > I am checking in this patch to allow copy relocs for non-GOT pc-relative
> > relocation in PIE.  It makes bfd linker compatible with gold.
> > 
> > 
> > H.J.
> > ----
> > bfd/
> > 
> > 	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Always
> > 	allow copy relocs for building executables.
> > 	(elf_x86_64_check_relocs): Allow copy relocs for non-GOT
> > 	pc-relative relocation in shared object.
> > 	(elf_x86_64_adjust_dynamic_symbol): Allocate copy relocs for
> > 	PIE.
> > 	(elf_x86_64_relocate_section): Don't copy a pc-relative
> > 	relocation into the output file if the symbol needs copy reloc.
> > 
> 
> This patch reverts the change in elf_x86_64_check_relocs and the partial
> change in elf_x86_64_adjust_dynamic_symbol.  Instead, we discard space
> in PIE for relocs against symbols which turn out to need copy relocs.
> 
> 	* elf64-x86-64.c (elf_x86_64_check_relocs): Revert the last
> 	change.
> 	(elf_x86_64_adjust_dynamic_symbol): Don't check !info->shared
> 	with ELIMINATE_COPY_RELOCS.
> 	(elf_x86_64_allocate_dynrelocs): For PIE, discard space for
> 	relocs against symbols which turn out to need copy relocs.
> ---
>  bfd/ChangeLog      |  9 +++++++++
>  bfd/elf64-x86-64.c | 36 +++++++++++++++++++++---------------
>  2 files changed, 30 insertions(+), 15 deletions(-)
> 
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 434db31..91245b9 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,5 +1,14 @@
>  2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
>  
> +	* elf64-x86-64.c (elf_x86_64_check_relocs): Revert the last
> +	change.
> +	(elf_x86_64_adjust_dynamic_symbol): Don't check !info->shared
> +	with ELIMINATE_COPY_RELOCS.
> +	(elf_x86_64_allocate_dynrelocs): For PIE, discard space for
> +	relocs against symbols which turn out to need copy relocs.
> +
> +2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
> +
>  	* elf64-x86-64.c (elf_x86_64_create_dynamic_sections): Always
>  	allow copy relocs for building executables.
>  	(elf_x86_64_check_relocs): Allow copy relocs for non-GOT


I checked in another small update.

H.J.
---
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 91245b9..f7caed5 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,10 @@
 2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
 
+	* elf64-x86-64.c (elf_x86_64_relocate_section): Check
+	info->executable for symbols which need copy relocs.
+
+2014-12-02  H.J. Lu  <hongjiu.lu@intel.com>
+
 	* elf64-x86-64.c (elf_x86_64_check_relocs): Revert the last
 	change.
 	(elf_x86_64_adjust_dynamic_symbol): Don't check !info->shared
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 58db76a..8b0b8bf 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4059,7 +4059,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
 		     defined locally or for a branch.  */
 		  fail = !h->def_regular && !branch;
 		}
-	      else if (!h->needs_copy)
+	      else if (!(info->executable && h->needs_copy))
 		{
 		  /* Symbol doesn't need copy reloc and isn't referenced
 		     locally.  We only allow branch to symbol with
@@ -4120,7 +4120,8 @@ direct:
 	   /* Don't copy a pc-relative relocation into the output file
 	      if the symbol needs copy reloc.  */
 	  if ((info->shared
-	       && !(h != NULL
+	       && !(info->executable
+		    && h != NULL
 		    && h->needs_copy
 		    && IS_X86_64_PCREL_TYPE (r_type))
 	       && (h == NULL



More information about the Binutils mailing list