Only discard space for pc-relative relocs symbols
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 11 Jan 2015 16:04:27 +0000 (08:04 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 11 Jan 2015 16:04:27 +0000 (08:04 -0800)
When building PIE, we should only discard space for pc-relative relocs
symbols which turn out to need copy relocs.

bfd/

PR ld/17827
* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): For PIE,
only discard space for pc-relative relocs symbols which turn
out to need copy relocs.

ld/testsuite/

PR ld/17827
* ld-x86-64/pr17689.out: Updated.
* ld-x86-64/pr17689b.S: Likewise.

* ld-x86-64/pr17827.rd: New file.

* ld-x86-64/x86-64.exp: Run PR ld/17827 test.

bfd/ChangeLog
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-x86-64/pr17689.out
ld/testsuite/ld-x86-64/pr17689b.S
ld/testsuite/ld-x86-64/pr17827.rd [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 70b138b2d053482ef36b2579eb91709b00362f3f..234d559c1eca02c2976e111359659aa63e7f8b5a 100644 (file)
@@ -1,3 +1,10 @@
+2015-01-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/17827
+       * elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): For PIE,
+       only discard space for pc-relative relocs symbols which turn
+       out to need copy relocs.
+
 2015-01-09  Nick Clifton  <nickc@redhat.com>
 
        * tekhex.c (getvalue): Fix thinko in test for correct extraction
index 581ee171773f243ccf952037e91cebf81f275ea1..6b7d3c9a56846bf4c622609b7ce77afbaeab94e3 100644 (file)
@@ -2742,13 +2742,23 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
                       && ! bfd_elf_link_record_dynamic_symbol (info, h))
                return FALSE;
            }
-         /* For PIE, discard space for relocs against symbols which
-            turn out to need copy relocs.  */
+         /* For PIE, discard space for pc-relative relocs against
+            symbols which turn out to need copy relocs.  */
          else if (info->executable
                   && (h->needs_copy || eh->needs_copy)
                   && h->def_dynamic
                   && !h->def_regular)
-           eh->dyn_relocs = NULL;
+           {
+             struct elf_dyn_relocs **pp;
+
+             for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+               {
+                 if (p->pc_count != 0)
+                   *pp = p->next;
+                 else
+                   pp = &p->next;
+               }
+           }
        }
     }
   else if (ELIMINATE_COPY_RELOCS)
index 229e006fc65dcf9337b665ed601326538994e3fd..e6903f7f21063dfbf32055c50eab85d26520d683 100644 (file)
@@ -1,3 +1,13 @@
+2015-01-11  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/17827
+       * ld-x86-64/pr17689.out: Updated.
+       * ld-x86-64/pr17689b.S: Likewise.
+
+       * ld-x86-64/pr17827.rd: New file.
+
+       * ld-x86-64/x86-64.exp: Run PR ld/17827 test.
+
 2015-01-08  Jan Beulich  <jbeulich@suse.com>
 
        * ld-x86-64/pr14207.d: Adjust expecations to cover the
index 7ef22e9a431ad0272713b71fdc8794016c8ef12f..38e03525155c1bd2cd6485de235edb42d54afa1f 100644 (file)
@@ -1 +1,2 @@
 PASS
+PASS
index c95f891057a082c2c05c66851de22a68bdba4528..64485c7e9164071c639c0f451f36d89fa9a83802 100644 (file)
@@ -5,8 +5,18 @@ main:
        subq    $8, %rsp
        movq    bar_alias(%rip), %rdi
        call    foo@PLT
+       movq    ptr(%rip), %rax
+       movq    (%rax), %rdi
+       call    foo@PLT
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
        .size   main, .-main
+       .globl  ptr
+       .section        .data.rel,"aw",@progbits
+       .align 8
+       .type   ptr, @object
+       .size   ptr, 8
+ptr:
+       .quad   bar_alias
        .section        .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/pr17827.rd b/ld/testsuite/ld-x86-64/pr17827.rd
new file mode 100644 (file)
index 0000000..d78ea2f
--- /dev/null
@@ -0,0 +1,4 @@
+#failif
+#...
+[0-9a-f ]+R_X86_64_NONE.*
+#...
index aa8555ff3edacc63ea6d79a49b4cbe8469f50324..5b49bffe6603f58e88799a99c1e623c9cff86c98 100644 (file)
@@ -432,6 +432,14 @@ if { [isnative] && [which $CC] != 0 } {
            {{readelf {-Wr} pr17689.rd}} \
            "pr17689" \
        ] \
+       [list \
+           "Build pr17827 with PIE without -fPIE" \
+           "tmpdir/pr17689.so -pie" \
+           "" \
+           { pr17689b.S } \
+           {{readelf {-Wr} pr17827.rd}} \
+           "pr17827" \
+       ] \
     ]
 
     run_ld_link_exec_tests [] [list \
This page took 0.03641 seconds and 4 git commands to generate.