Replace IRELATIVE relocations with RELATIVE in .rel.dyn.
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 21 Oct 2011 19:37:15 +0000 (19:37 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 21 Oct 2011 19:37:15 +0000 (19:37 +0000)
bfd/

2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/13302
* elf32-i386.c (elf_i386_relocate_section): Replace
R_386_IRELATIVE with R_386_RELATIVE.

* elf64-x86-64.c (elf_x86_64_relocate_section): Replace
R_X86_64_IRELATIVE with R_X86_64_RELATIVE.

ld/testsuite/

2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/13302
* ld-i386/i386.exp: Run pr13302.

* ld-i386/pr13302.d: New.
* ld-i386/pr13302.s: Likewise.

* ld-x86-64/pr13082-5b.d: Updated.
* ld-x86-64/pr13082-6a.d: Likewise.
* ld-x86-64/pr13082-6b.d: Likewise.

bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr13302.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr13302.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr13082-5b.d
ld/testsuite/ld-x86-64/pr13082-6a.d
ld/testsuite/ld-x86-64/pr13082-6b.d

index a20a75db9980ff48d69255bcdebc5009242b51e1..39f1a2a98a17bf4ab422ae02af2bed26a648e611 100644 (file)
@@ -1,3 +1,12 @@
+2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/13302
+       * elf32-i386.c (elf_i386_relocate_section): Replace
+       R_386_IRELATIVE with R_386_RELATIVE.
+
+       * elf64-x86-64.c (elf_x86_64_relocate_section): Replace
+       R_X86_64_IRELATIVE with R_X86_64_RELATIVE.
+
 2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>.
 
        * elf32-i386.c (elf_i386_relocate_section): Fix a typo in
index 01c06695956ad0c3714a60b6e6f156f2ed3f475e..d1873051b4d9bc692b86b23b6277e3718f00864f 100644 (file)
@@ -3257,6 +3257,7 @@ elf_i386_relocate_section (bfd *output_bfd,
                  bfd_byte *loc;
                  asection *sreloc;
                  bfd_vma offset;
+                 bfd_boolean relocate;
 
                  /* Need a dynamic relocation to get the real function
                     adddress.  */
@@ -3277,15 +3278,14 @@ elf_i386_relocate_section (bfd *output_bfd,
                      || info->executable)
                    {
                      /* This symbol is resolved locally.  */
-                     outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
-                     bfd_put_32 (output_bfd,
-                                 (h->root.u.def.value
-                                  + h->root.u.def.section->output_section->vma
-                                  + h->root.u.def.section->output_offset),
-                                 contents + offset);
+                     outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
+                     relocate = TRUE;
                    }
                  else
-                   outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+                   {
+                     outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+                     relocate = FALSE;
+                   }
 
                  sreloc = htab->elf.irelifunc;
                  loc = sreloc->contents;
@@ -3298,7 +3298,8 @@ elf_i386_relocate_section (bfd *output_bfd,
                     we need to include the symbol value so that it
                     becomes an addend for the dynamic reloc.  For an
                     internal symbol, we have updated addend.  */
-                 continue;
+                 if (! relocate)
+                   continue;
                }
              /* FALLTHROUGH */
            case R_386_PC32:
index 645e5a24348605678d88fbb912a067698f1913a3..2206dd4754b72f55a60bd7c12ccff5fc3af5bbb2 100644 (file)
@@ -3161,6 +3161,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
                {
                  Elf_Internal_Rela outrel;
                  asection *sreloc;
+                 bfd_boolean relocate;
 
                  /* Need a dynamic relocation to get the real function
                     address.  */
@@ -3180,15 +3181,15 @@ elf_x86_64_relocate_section (bfd *output_bfd,
                      || info->executable)
                    {
                      /* This symbol is resolved locally.  */
-                     outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
-                     outrel.r_addend = (h->root.u.def.value
-                                        + h->root.u.def.section->output_section->vma
-                                        + h->root.u.def.section->output_offset);
+                     outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
+                     outrel.r_addend = relocation;
+                     relocate = FALSE;
                    }
                  else
                    {
                      outrel.r_info = htab->r_info (h->dynindx, r_type);
                      outrel.r_addend = 0;
+                     relocate = FALSE;
                    }
 
                  sreloc = htab->elf.irelifunc;
@@ -3199,7 +3200,8 @@ elf_x86_64_relocate_section (bfd *output_bfd,
                     we need to include the symbol value so that it
                     becomes an addend for the dynamic reloc.  For an
                     internal symbol, we have updated addend.  */
-                 continue;
+                 if (! relocate)
+                   continue;
                }
              /* FALLTHROUGH */
            case R_X86_64_PC32:
index 8480fee44196f11410bcc3d25bfce9776f7f8748..2b444ac2a876d6bd58123f25ab4d1fefc83f629b 100644 (file)
@@ -1,3 +1,15 @@
+2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/13302
+       * ld-i386/i386.exp: Run pr13302.
+
+       * ld-i386/pr13302.d: New.
+       * ld-i386/pr13302.s: Likewise.
+
+       * ld-x86-64/pr13082-5b.d: Updated.
+       * ld-x86-64/pr13082-6a.d: Likewise.
+       * ld-x86-64/pr13082-6b.d: Likewise.
+
 2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/13302
index 68b71fbcbab436b4d51cd0fc1ae3900bb7c4c702..17279224006487b7cdb10549989fb5ff10bd7ad5 100644 (file)
@@ -210,3 +210,4 @@ if { !([istarget "i?86-*-linux*"]
 
 run_dump_test "compressed1"
 run_dump_test "pr12627"
+run_dump_test "pr13302"
diff --git a/ld/testsuite/ld-i386/pr13302.d b/ld/testsuite/ld-i386/pr13302.d
new file mode 100644 (file)
index 0000000..3d85d08
--- /dev/null
@@ -0,0 +1,12 @@
+#name: PR ld/13302
+#as: --32
+#ld: -pie -melf_i386
+#readelf: -r --wide
+
+Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
+ Offset     Info    Type                Sym. Value  Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE +
+
+Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ Offset     Info    Type                Sym. Value  Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_IRELATIVE +
diff --git a/ld/testsuite/ld-i386/pr13302.s b/ld/testsuite/ld-i386/pr13302.s
new file mode 100644 (file)
index 0000000..cfd2717
--- /dev/null
@@ -0,0 +1,11 @@
+       .text
+       .globl _start
+       .type ifunc, @gnu_indirect_function
+_start:
+       lea     .Ljmp@GOTOFF(%ebx), %eax
+ifunc:
+       jmp     *(%eax)
+       .section        .data.rel.ro.local,"aw",@progbits
+       .align  4
+.Ljmp:
+       .long ifunc
index 1c5a5e79b536b97da25444e98f4e0e394d6eecab..48e37c3eedc93d0ea108d911296c58c43234cfc9 100644 (file)
@@ -6,7 +6,7 @@
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
 
 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
index 9a1a6551853fcff556283701c3e2bb7f9a3353b0..de90bb85e9929b38e1c874262bbbecac3f650746 100644 (file)
@@ -6,7 +6,7 @@
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
 
 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
index 792c3483eba3406a71fb2ecaa253fc70375fc206..66ff59b01495a118b53eacc9de1ed2f80e398559 100644 (file)
@@ -6,7 +6,7 @@
 
 Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
 
 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
  Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend