x86: Change PLT32 reloc against section to PC32
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 19 Jul 2020 13:51:19 +0000 (06:51 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 19 Jul 2020 13:51:32 +0000 (06:51 -0700)
Commit 292676c1 resolved PLT32 reloc aganst local symbol to section.
Since PLT32 relocation must be against symbols, turn such PLT32
relocation into PC32 relocation.

gas/

PR gas/26263
* config/tc-i386.c (i386_validate_fix): Change PLT32 reloc
against section to PC32 reloc.
* testsuite/gas/i386/relax-5.d: Updated.
* testsuite/gas/i386/x86-64-relax-4.d: Likewise.

ld/

PR gas/26263
* testsuite/ld-i386/i386.exp: Run PR gas/26263 test.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr26263.d: New file.
* testsuite/ld-x86-64/pr26263.d: Likewise.
* testsuite/ld-x86-64/pr26263.s: Likewise.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/relax-5.d
gas/testsuite/gas/i386/x86-64-relax-4.d
ld/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr26263.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr26263.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr26263.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 2336fb57e15e3d7dae1fc7cc41b11e2b18b94240..e07e4eea1d09a1f8f221bf7d721c9768192ec4e1 100644 (file)
@@ -1,3 +1,11 @@
+2020-07-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gas/26263
+       * config/tc-i386.c (i386_validate_fix): Change PLT32 reloc
+       against section to PC32 reloc.
+       * testsuite/gas/i386/relax-5.d: Updated.
+       * testsuite/gas/i386/x86-64-relax-4.d: Likewise.
+
 2020-07-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/26237
index 192c5e1ae3af154de36abd6cbb0e07f4f088b40b..a9c79f1550bed3beebcf8049dce46b928f29de8c 100644 (file)
@@ -13849,11 +13849,22 @@ i386_validate_fix (fixS *fixp)
        }
     }
 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
-  else if (!object_64bit)
+  else
     {
-      if (fixp->fx_r_type == BFD_RELOC_386_GOT32
-         && fixp->fx_tcbit2)
-       fixp->fx_r_type = BFD_RELOC_386_GOT32X;
+      /* NB: Commit 292676c1 resolved PLT32 reloc aganst local symbol
+        to section.  Since PLT32 relocation must be against symbols,
+        turn such PLT32 relocation into PC32 relocation.  */
+      if (fixp->fx_addsy
+         && (fixp->fx_r_type == BFD_RELOC_386_PLT32
+             || fixp->fx_r_type == BFD_RELOC_X86_64_PLT32)
+         && symbol_section_p (fixp->fx_addsy))
+       fixp->fx_r_type = BFD_RELOC_32_PCREL;
+      if (!object_64bit)
+       {
+         if (fixp->fx_r_type == BFD_RELOC_386_GOT32
+             && fixp->fx_tcbit2)
+           fixp->fx_r_type = BFD_RELOC_386_GOT32X;
+       }
     }
 #endif
 }
index bccfe681a0e127f528405a5ebfb18d02fb97ed0d..c3771330b28556e4159c719f5df1bdbf88c705ae 100644 (file)
@@ -10,6 +10,6 @@ Disassembly of section .text:
 Disassembly of section .init.text:
 
 0+ <foo>:
- +[a-f0-9]+:   e8 fb ff ff ff          call   0 <foo>  1: R_386_PLT32  .text
+ +[a-f0-9]+:   e8 fc ff ff ff          call   1 <foo\+0x1>     1: R_386_PC32   .text
  +[a-f0-9]+:   e8 fc ff ff ff          call   6 <foo\+0x6>     6: R_386_PC32   .text
 #pass
index 594f95ae3e3e11091d4674edac9c07ca8f834fa4..ca12c0383bed6d911cedaa56268f53d0aecb15b7 100644 (file)
@@ -12,6 +12,6 @@ Disassembly of section .text:
 Disassembly of section .init.text:
 
 0+ <foo>:
- +[a-f0-9]+:   e8 00 00 00 00          call   5 <foo\+0x5>     1: R_X86_64_PLT32       .text-0x4
+ +[a-f0-9]+:   e8 00 00 00 00          call   5 <foo\+0x5>     1: R_X86_64_PC32        .text-0x4
  +[a-f0-9]+:   48 8d 05 00 00 00 00    lea    0x0\(%rip\),%rax        # c <foo\+0xc>   8: R_X86_64_PC32        .text-0x4
 #pass
index 37a94aa88068dbb356d3dce403ee06100a3df13e..747856868ab5f3eedf416a67d02920f3e3cb1fb5 100644 (file)
@@ -1,3 +1,12 @@
+2020-07-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gas/26263
+       * testsuite/ld-i386/i386.exp: Run PR gas/26263 test.
+       * testsuite/ld-x86-64/x86-64.exp: Likewise.
+       * testsuite/ld-i386/pr26263.d: New file.
+       * testsuite/ld-x86-64/pr26263.d: Likewise.
+       * testsuite/ld-x86-64/pr26263.s: Likewise.
+
 2020-07-19  Hans-Peter Nilsson  <hp@bitrange.com>
 
        * scripttempl/elf.sc (ETEXT_LAST_IN_RODATA_SEGMENT): New variable.
index e51981a38da36651c77da09e8b159c522f9d8f79..164c099cbbb90fb28c10c28a6213959ae14fabdb 100644 (file)
@@ -469,6 +469,7 @@ run_dump_test "pr24322a"
 run_dump_test "pr24322b"
 run_dump_test "align-branch-1"
 run_dump_test "pr26018"
+run_dump_test "pr26263"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr26263.d b/ld/testsuite/ld-i386/pr26263.d
new file mode 100644 (file)
index 0000000..8cf7c15
--- /dev/null
@@ -0,0 +1,19 @@
+#source: ../ld-x86-64/pr26263.s
+#as: --32
+#ld: -shared -melf_i386
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+1000 <printk>:
+ +[a-f0-9]+:   c3                      ret    
+
+Disassembly of section .init.text:
+
+0+1001 <foo>:
+ +[a-f0-9]+:   e8 fa ff ff ff          call   1000 <printk>
+ +[a-f0-9]+:   e8 f5 ff ff ff          call   1000 <printk>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr26263.d b/ld/testsuite/ld-x86-64/pr26263.d
new file mode 100644 (file)
index 0000000..375218c
--- /dev/null
@@ -0,0 +1,18 @@
+#as: --64
+#ld: -m elf_x86_64 -shared
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+0+1000 <printk>:
+ +[a-f0-9]+:   c3                      ret    
+
+Disassembly of section .init.text:
+
+0+1001 <foo>:
+ +[a-f0-9]+:   e8 fa ff ff ff          call   1000 <printk>
+ +[a-f0-9]+:   e8 f5 ff ff ff          call   1000 <printk>
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr26263.s b/ld/testsuite/ld-x86-64/pr26263.s
new file mode 100644 (file)
index 0000000..5a3332c
--- /dev/null
@@ -0,0 +1,8 @@
+       .section .init.text,"ax",@progbits
+       .global foo
+foo:
+       call    printk
+       call    printk@PLT
+       .text
+printk:
+       ret
index e687c42a695bb189d9e8a11ff5b653be131ffdbf..21aa6a06effdb87a1a7208cac39b9b23d66c0b35 100644 (file)
@@ -640,6 +640,7 @@ run_dump_test "pr20253-5b"
 run_dump_test "tlsdesc2"
 run_dump_test "pr22048"
 run_dump_test "pr22929"
+run_dump_test "pr26263"
 
 proc undefined_weak {cflags ldflags} {
     set testname "Undefined weak symbol"