Don't convert R_386_GOT32 relocation
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 19 May 2016 19:56:55 +0000 (12:56 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 19 May 2016 19:57:11 +0000 (12:57 -0700)
Don't convert R_386_GOT32 since we can't tell if it is applied
to "mov $foo@GOT, %reg" which isn't a load via GOT.

bfd/

PR ld/20117
* elf32-i386.c (elf_i386_convert_load_reloc): Don't check
R_386_GOT32X.
(elf_i386_convert_load): Don't convert R_386_GOT32.

ld/

PR ld/20117
* testsuite/ld-i386/i386.exp: Run pr20117.
* testsuite/ld-i386/pr19609-1i.d: Updated.
* testsuite/ld-i386/pr20117.d: New file.
* testsuite/ld-i386/pr20117.s: Likewise.

bfd/ChangeLog
bfd/elf32-i386.c
ld/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr19609-1i.d
ld/testsuite/ld-i386/pr20117.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr20117.s [new file with mode: 0644]

index 878f22f54e35e613ec07823586710aa71d9c1365..64aac63487cbd044d45aeb190098a0ff6b73d0c6 100644 (file)
@@ -1,3 +1,10 @@
+2016-05-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20117
+       * elf32-i386.c (elf_i386_convert_load_reloc): Don't check
+       R_386_GOT32X.
+       (elf_i386_convert_load): Don't convert R_386_GOT32.
+
 2016-05-20  Alan Modra  <amodra@gmail.com>
 
        PR gas/20118
index fcb22c431c5d4f499ccc06ffe21ec6da44a77386..c7e08aabbe1b299553f686b25d9b5630b739ea04 100644 (file)
@@ -1544,7 +1544,7 @@ elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
   if (roff < 2)
     return TRUE;
 
-  /* Addend for R_386_GOT32 and R_386_GOT32X relocations must be 0.  */
+  /* Addend for R_386_GOT32X relocations must be 0.  */
   addend = bfd_get_32 (abfd, contents + roff);
   if (addend != 0)
     return TRUE;
@@ -1558,11 +1558,10 @@ elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
   modrm = bfd_get_8 (abfd, contents + roff - 1);
   baseless = (modrm & 0xc7) == 0x5;
 
-  if (r_type == R_386_GOT32X && baseless && is_pic)
+  if (baseless && is_pic)
     {
       /* For PIC, disallow R_386_GOT32X without a base register
-        since we don't know what the GOT base is.   Allow
-        R_386_GOT32 for existing object files.  */
+        since we don't know what the GOT base is.  */
       const char *name;
 
       if (h == NULL)
@@ -1582,22 +1581,12 @@ elf_i386_convert_load_reloc (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
 
   opcode = bfd_get_8 (abfd, contents + roff - 2);
 
-  /* Convert mov to lea since it has been done for a while.  */
-  if (opcode != 0x8b)
-    {
-      /* Only convert R_386_GOT32X relocation for call, jmp or
-        one of adc, add, and, cmp, or, sbb, sub, test, xor
-        instructions.  */
-      if (r_type != R_386_GOT32X)
-       return TRUE;
-    }
-
   /* Convert to R_386_32 if PIC is false or there is no base
      register.  */
   to_reloc_32 = !is_pic || baseless;
 
-  /* Try to convert R_386_GOT32 and R_386_GOT32X.  Get the symbol
-     referred to by the reloc.  */
+  /* Try to convert R_386_GOT32X.  Get the symbol referred to by the
+     reloc.  */
   if (h == NULL)
     {
       if (opcode == 0x0ff)
@@ -3021,7 +3010,9 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
       struct elf_link_hash_entry *h;
       bfd_boolean converted;
 
-      if (r_type != R_386_GOT32 && r_type != R_386_GOT32X)
+      /* Don't convert R_386_GOT32 since we can't tell if it is applied
+        to "mov $foo@GOT, %reg" which isn't a load via GOT.  */
+      if (r_type != R_386_GOT32X)
        continue;
 
       r_symndx = ELF32_R_SYM (irel->r_info);
index 0619b8d89c21f9ec7e9a50a0e8cb8f55dc253f6d..638f38b0c182c1b5f0313f825e7af21814fc8116 100644 (file)
@@ -1,3 +1,11 @@
+2016-05-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20117
+       * testsuite/ld-i386/i386.exp: Run pr20117.
+       * testsuite/ld-i386/pr19609-1i.d: Updated.
+       * testsuite/ld-i386/pr20117.d: New file.
+       * testsuite/ld-i386/pr20117.s: Likewise.
+
 2016-05-19  Cupertino Miranda  <cmiranda@synopsys.com>
 
        * testsuite/ld-elf/compressed1d.d: Removed from notarget.
index ba53c9107a5358e9d3361c35bd28515f02ec5272..8e662806b8ce1e3aec2abf873f3131d4fca5d97e 100644 (file)
@@ -373,6 +373,7 @@ run_dump_test "pr19609-2c"
 run_dump_test "undefweaka"
 run_dump_test "undefweakb"
 run_dump_test "pr19539"
+run_dump_test "pr20117"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
index ce15bc90e1133a226b36a20443c5d1862411df09..2a6d0c0a1f0957584282e0f05288442b44a6bcb7 100644 (file)
@@ -11,7 +11,7 @@ Disassembly of section .text:
 [a-f0-9]+ <_start>:
 [      ]*[a-f0-9]+:    3b 82 fc ff ff ff       cmp    -0x4\(%edx\),%eax
 [      ]*[a-f0-9]+:    3b 8a fc ff ff ff       cmp    -0x4\(%edx\),%ecx
-[      ]*[a-f0-9]+:    c7 c0 00 00 00 00       mov    \$0x0,%eax
-[      ]*[a-f0-9]+:    c7 c1 00 00 00 00       mov    \$0x0,%ecx
+[      ]*[a-f0-9]+:    8b 82 fc ff ff ff       mov    -0x4\(%edx\),%eax
+[      ]*[a-f0-9]+:    8b 8a fc ff ff ff       mov    -0x4\(%edx\),%ecx
 [      ]*[a-f0-9]+:    85 82 fc ff ff ff       test   %eax,-0x4\(%edx\)
 [      ]*[a-f0-9]+:    85 8a fc ff ff ff       test   %ecx,-0x4\(%edx\)
diff --git a/ld/testsuite/ld-i386/pr20117.d b/ld/testsuite/ld-i386/pr20117.d
new file mode 100644 (file)
index 0000000..59c77ee
--- /dev/null
@@ -0,0 +1,12 @@
+#as: --32
+#ld: -melf_i386
+#objdump: -dw
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <_start>:
+[      ]*[a-f0-9]+:    eb 8b                   jmp    [a-f0-9]+ <_start\-0x[a-f0-9]+>
+[      ]*[a-f0-9]+:    bd ([0-9a-f]{2} ){4} *  mov    \$0x[a-f0-9]+\,%ebp
diff --git a/ld/testsuite/ld-i386/pr20117.s b/ld/testsuite/ld-i386/pr20117.s
new file mode 100644 (file)
index 0000000..de2dd28
--- /dev/null
@@ -0,0 +1,7 @@
+       .comm   DEBUGLEVEL,4,4
+       .text
+       .globl  _start
+       .type   _start, @function
+_start:
+       .byte 0xeb, 0x8b
+       movl      $DEBUGLEVEL@GOT, %ebp
This page took 0.034718 seconds and 4 git commands to generate.