Jakub Jelinek d60190
2012-03-09  H.J. Lu  <hongjiu.lu@intel.com>
Jakub Jelinek d60190
Jakub Jelinek d60190
	PR ld/13817
Jakub Jelinek d60190
	* bfd/elf32-i386.c (elf_i386_relocate_section): Restore
Jakub Jelinek d60190
	R_386_IRELATIVE.
Jakub Jelinek d60190
Jakub Jelinek d60190
	* * elf64-x86-64.c (elf_x86_64_relocate_section): Restore
Jakub Jelinek d60190
	R_X86_64_IRELATIVE.
Jakub Jelinek d60190
Jakub Jelinek d60190
	* ld-i386/pr13302.d: Updated.
Jakub Jelinek d60190
	* ld-x86-64/pr13082-5b.d: Likewise.
Jakub Jelinek d60190
	* ld-x86-64/pr13082-6a.d: Likewise.
Jakub Jelinek d60190
	* ld-x86-64/pr13082-6b.d: Likewise.
Jakub Jelinek d60190
Jakub Jelinek d60190
--- bfd/elf32-i386.c	21 Oct 2011 19:37:14 -0000	1.265
Jakub Jelinek d60190
+++ bfd/elf32-i386.c	9 Mar 2012 16:28:36 -0000	1.266
Jakub Jelinek d60190
@@ -3257,7 +3257,6 @@ elf_i386_relocate_section (bfd *output_b
Jakub Jelinek d60190
 		  bfd_byte *loc;
Jakub Jelinek d60190
 		  asection *sreloc;
Jakub Jelinek d60190
 		  bfd_vma offset;
Jakub Jelinek d60190
-		  bfd_boolean relocate;
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 		  /* Need a dynamic relocation to get the real function
Jakub Jelinek d60190
 		     adddress.  */
Jakub Jelinek d60190
@@ -3278,14 +3277,15 @@ elf_i386_relocate_section (bfd *output_b
Jakub Jelinek d60190
 		      || info->executable)
Jakub Jelinek d60190
 		    {
Jakub Jelinek d60190
 		      /* This symbol is resolved locally.  */
Jakub Jelinek d60190
-		      outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
Jakub Jelinek d60190
-		      relocate = TRUE;
Jakub Jelinek d60190
+		      outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
Jakub Jelinek d60190
+		      bfd_put_32 (output_bfd,
Jakub Jelinek d60190
+				  (h->root.u.def.value
Jakub Jelinek d60190
+				   + h->root.u.def.section->output_section->vma
Jakub Jelinek d60190
+				   + h->root.u.def.section->output_offset),
Jakub Jelinek d60190
+				  contents + offset);
Jakub Jelinek d60190
 		    }
Jakub Jelinek d60190
 		  else
Jakub Jelinek d60190
-		    {
Jakub Jelinek d60190
-		      outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
Jakub Jelinek d60190
-		      relocate = FALSE;
Jakub Jelinek d60190
-		    }
Jakub Jelinek d60190
+		    outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 		  sreloc = htab->elf.irelifunc;
Jakub Jelinek d60190
 		  loc = sreloc->contents;
Jakub Jelinek d60190
@@ -3298,8 +3298,7 @@ elf_i386_relocate_section (bfd *output_b
Jakub Jelinek d60190
 		     we need to include the symbol value so that it
Jakub Jelinek d60190
 		     becomes an addend for the dynamic reloc.  For an
Jakub Jelinek d60190
 		     internal symbol, we have updated addend.  */
Jakub Jelinek d60190
-		  if (! relocate)
Jakub Jelinek d60190
-		    continue;
Jakub Jelinek d60190
+		  continue;
Jakub Jelinek d60190
 		}
Jakub Jelinek d60190
 	      /* FALLTHROUGH */
Jakub Jelinek d60190
 	    case R_386_PC32:
Jakub Jelinek d60190
--- bfd/elf64-x86-64.c	6 Mar 2012 20:15:56 -0000	1.248
Jakub Jelinek d60190
+++ bfd/elf64-x86-64.c	9 Mar 2012 16:28:36 -0000	1.249
Jakub Jelinek d60190
@@ -3156,7 +3156,6 @@ elf_x86_64_relocate_section (bfd *output
Jakub Jelinek d60190
 		{
Jakub Jelinek d60190
 		  Elf_Internal_Rela outrel;
Jakub Jelinek d60190
 		  asection *sreloc;
Jakub Jelinek d60190
-		  bfd_boolean relocate;
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 		  /* Need a dynamic relocation to get the real function
Jakub Jelinek d60190
 		     address.  */
Jakub Jelinek d60190
@@ -3176,15 +3175,15 @@ elf_x86_64_relocate_section (bfd *output
Jakub Jelinek d60190
 		      || info->executable)
Jakub Jelinek d60190
 		    {
Jakub Jelinek d60190
 		      /* This symbol is resolved locally.  */
Jakub Jelinek d60190
-		      outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
Jakub Jelinek d60190
-		      outrel.r_addend = relocation;
Jakub Jelinek d60190
-		      relocate = TRUE;
Jakub Jelinek d60190
+		      outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
Jakub Jelinek d60190
+		      outrel.r_addend = (h->root.u.def.value
Jakub Jelinek d60190
+					 + h->root.u.def.section->output_section->vma
Jakub Jelinek d60190
+					 + h->root.u.def.section->output_offset);
Jakub Jelinek d60190
 		    }
Jakub Jelinek d60190
 		  else
Jakub Jelinek d60190
 		    {
Jakub Jelinek d60190
 		      outrel.r_info = htab->r_info (h->dynindx, r_type);
Jakub Jelinek d60190
 		      outrel.r_addend = 0;
Jakub Jelinek d60190
-		      relocate = FALSE;
Jakub Jelinek d60190
 		    }
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 		  sreloc = htab->elf.irelifunc;
Jakub Jelinek d60190
@@ -3195,8 +3194,7 @@ elf_x86_64_relocate_section (bfd *output
Jakub Jelinek d60190
 		     we need to include the symbol value so that it
Jakub Jelinek d60190
 		     becomes an addend for the dynamic reloc.  For an
Jakub Jelinek d60190
 		     internal symbol, we have updated addend.  */
Jakub Jelinek d60190
-		  if (! relocate)
Jakub Jelinek d60190
-		    continue;
Jakub Jelinek d60190
+		  continue;
Jakub Jelinek d60190
 		}
Jakub Jelinek d60190
 	      /* FALLTHROUGH */
Jakub Jelinek d60190
 	    case R_X86_64_PC32:
Jakub Jelinek d60190
Jakub Jelinek d60190
--- ld/testsuite/ld-i386/pr13302.d	21 Oct 2011 19:37:15 -0000	1.1
Jakub Jelinek d60190
+++ ld/testsuite/ld-i386/pr13302.d	9 Mar 2012 16:28:37 -0000	1.2
Jakub Jelinek d60190
@@ -5,7 +5,7 @@
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name
Jakub Jelinek d60190
-[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE +
Jakub Jelinek d60190
+[0-9a-f]+ +[0-9a-f]+ +R_386_IRELATIVE +
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name
Jakub Jelinek d60190
--- ld/testsuite/ld-x86-64/pr13082-5b.d	21 Oct 2011 19:37:15 -0000	1.2
Jakub Jelinek d60190
+++ ld/testsuite/ld-x86-64/pr13082-5b.d	9 Mar 2012 16:28:38 -0000	1.3
Jakub Jelinek d60190
@@ -6,7 +6,7 @@
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
Jakub Jelinek d60190
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
Jakub Jelinek d60190
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
Jakub Jelinek d60190
--- ld/testsuite/ld-x86-64/pr13082-6a.d	21 Oct 2011 19:37:15 -0000	1.2
Jakub Jelinek d60190
+++ ld/testsuite/ld-x86-64/pr13082-6a.d	9 Mar 2012 16:28:38 -0000	1.3
Jakub Jelinek d60190
@@ -6,7 +6,7 @@
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
Jakub Jelinek d60190
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
Jakub Jelinek d60190
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
Jakub Jelinek d60190
--- ld/testsuite/ld-x86-64/pr13082-6b.d	21 Oct 2011 19:37:15 -0000	1.2
Jakub Jelinek d60190
+++ ld/testsuite/ld-x86-64/pr13082-6b.d	9 Mar 2012 16:28:38 -0000	1.3
Jakub Jelinek d60190
@@ -6,7 +6,7 @@
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
Jakub Jelinek d60190
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
Jakub Jelinek d60190
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
Jakub Jelinek d60190
 
Jakub Jelinek d60190
 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
Jakub Jelinek d60190
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend