Also check GOT PLT for R_X86_64_PLTOFF64
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 14 Nov 2016 18:13:03 +0000 (10:13 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 14 Nov 2016 18:13:03 +0000 (10:13 -0800)
Since "-z now" replaces PLT with GOT PLT, we should also check GOT PLT
for R_X86_64_PLTOFF64 relocation.

bfd/

PR ld/20800
* elf64-x86-64.c (elf_x86_64_relocate_section): Also check
plt_got.offset for R_X86_64_PLTOFF64.

ld/

PR ld/20800
* testsuite/ld-x86-64/pr20800a.S: New file.
* testsuite/ld-x86-64/pr20800b.S: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/20800 test.

bfd/ChangeLog
bfd/elf64-x86-64.c
ld/ChangeLog
ld/testsuite/ld-x86-64/pr20800a.S [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr20800b.S [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 521e319b12f6a09a1d880c63e6717ba57b189c9b..b8ae63404e06203ad68bf5798f57eba0b7ec9323 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-14  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20800
+       * elf64-x86-64.c (elf_x86_64_relocate_section): Also check
+       plt_got.offset for R_X86_64_PLTOFF64.
+
 2016-11-14  Nick Clifton  <nickc@redhat.com>
 
        * coffcode.h (coff_slurp_symbol_table): Fix typo: Faal -> Fall.
index 76f09bd4ceb42efe3f5c37d55f74ddfa5d3278ab..05a4776c5a2c91bae5434a1c4f44a7c2e10c1d7f 100644 (file)
@@ -4693,10 +4693,17 @@ do_ifunc_pointer:
             symbols it's the symbol itself relative to GOT.  */
          if (h != NULL
              /* See PLT32 handling.  */
-             && h->plt.offset != (bfd_vma) -1
+             && (h->plt.offset != (bfd_vma) -1
+                 || eh->plt_got.offset != (bfd_vma) -1)
              && htab->elf.splt != NULL)
            {
-             if (htab->plt_bnd != NULL)
+             if (eh->plt_got.offset != (bfd_vma) -1)
+               {
+                 /* Use the GOT PLT.  */
+                 resolved_plt = htab->plt_got;
+                 plt_offset = eh->plt_got.offset;
+               }
+             else if (htab->plt_bnd != NULL)
                {
                  resolved_plt = htab->plt_bnd;
                  plt_offset = eh->plt_bnd.offset;
index e027201188f5f281b6e807fd6d1a87deac357c68..f0f6694138bd3886acf15734571f384728054e41 100644 (file)
@@ -1,3 +1,10 @@
+2016-11-14  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20800
+       * testsuite/ld-x86-64/pr20800a.S: New file.
+       * testsuite/ld-x86-64/pr20800b.S: Likewise.
+       * testsuite/ld-x86-64/x86-64.exp: Run PR ld/20800 test.
+
 2016-11-14  Nick Clifton  <nickc@redhat.com>
 
        * lexsup.c (parse_args): Add break at end of default case.
diff --git a/ld/testsuite/ld-x86-64/pr20800a.S b/ld/testsuite/ld-x86-64/pr20800a.S
new file mode 100644 (file)
index 0000000..c4bcd80
--- /dev/null
@@ -0,0 +1,17 @@
+       .text
+       .globl  main
+       .type   main, @function
+main:
+.L2:
+       leaq    .L2(%rip), %rax
+       movabsq $_GLOBAL_OFFSET_TABLE_-.L2, %r11
+       movabsq $bar@PLTOFF, %rdx
+       pushq   %r15
+       addq    %r11, %rax
+       movq    %rax, %r15
+       addq    %rax, %rdx
+       call    *%rdx
+       xorl    %eax, %eax
+       popq    %r15
+       ret
+       .size   main, .-main
diff --git a/ld/testsuite/ld-x86-64/pr20800b.S b/ld/testsuite/ld-x86-64/pr20800b.S
new file mode 100644 (file)
index 0000000..c4eeb4f
--- /dev/null
@@ -0,0 +1,21 @@
+       .section        .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+       .string "PASS\n"
+       .text
+       .globl  bar
+       .type   bar, @function
+bar:
+.L2:
+       leaq    .L2(%rip), %rdx
+       movabsq $_GLOBAL_OFFSET_TABLE_-.L2, %r11
+       movabsq $.LC0@GOTOFF, %rax
+       pushq   %r15
+       movabsq $printf@PLTOFF, %rcx
+       addq    %r11, %rdx
+       popq    %r15
+       leaq    (%rdx,%rax), %rdi
+       addq    %rdx, %rcx
+       xorl    %eax, %eax
+       jmp     *%rcx
+       .size   bar, .-bar
+       .section        .note.GNU-stack,"",@progbits
index c84bdf12d8e768404136c85aa5e5c8971ee9be4c..9a4bdb9cb327df5d568d8d21cb4a853626ec7026 100644 (file)
@@ -991,6 +991,14 @@ if { [isnative] && [which $CC] != 0 } {
                "plt-main.out" \
                "-fPIC" \
            ] \
+           [list \
+               "Run pr20800" \
+               "-pie -z now" \
+               "" \
+               { pr20800a.S pr20800b.S } \
+               "pr20800" \
+               "pass.out" \
+           ] \
        ]
     }