]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Don't convert R_386_GOT32 relocation
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 20 May 2016 16:41:50 +0000 (09:41 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 20 May 2016 16:42:27 +0000 (09:42 -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/

Backport from master
* elf32-i386.c (elf_i386_check_relocs): Don't check R_386_GOT32
when setting need_convert_load.

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

ld/

Backport from master
PR ld/20117
* testsuite/ld-i386/i386.exp: Run pr20117.
* 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/pr20117.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr20117.s [new file with mode: 0644]

index f56dca37d1cdeabb6e4c7effc3c70816e55d3ae1..fbb875365c5ae5bf6ad067e32c41ebb7e9702bde 100644 (file)
@@ -1,3 +1,17 @@
+2016-05-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       Backport from master
+       2016-05-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf32-i386.c (elf_i386_check_relocs): Don't check R_386_GOT32
+       when setting need_convert_load.
+
+       2016-05-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20117
+       * elf32-i386.c (elf_i386_convert_load): Don't convert
+       R_386_GOT32.
+
 2016-05-18  Christophe Monat  <christophe.monat@st.com>
 
        Backport from master
index 79f339e53ee5c3beee6c20876f5ab9ac8c9b61fb..a3a241fe2f92eb49f77237f8bcd0ffe147bac1f3 100644 (file)
@@ -1962,7 +1962,7 @@ do_size:
            return FALSE;
        }
 
-      if ((r_type == R_386_GOT32 || r_type == R_386_GOT32X)
+      if (r_type == R_386_GOT32X
          && (h == NULL || h->type != STT_GNU_IFUNC))
        sec->need_convert_load = 1;
     }
@@ -2816,14 +2816,16 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
       unsigned int nop;
       bfd_vma nop_offset;
 
-      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;
 
       roff = irel->r_offset;
       if (roff < 2)
        continue;
 
-      /* Addend for R_386_GOT32 and R_386_GOT32X relocations must be 0.  */
+      /* Addend for R_386_GOT32X relocation must be 0.  */
       addend = bfd_get_32 (abfd, contents + roff);
       if (addend != 0)
        continue;
@@ -2831,13 +2833,11 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
       modrm = bfd_get_8 (abfd, contents + roff - 1);
       baseless = (modrm & 0xc7) == 0x5;
 
-      if (r_type == R_386_GOT32X
-         && baseless
+      if (baseless
          && bfd_link_pic (link_info))
        {
          /* 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 (r_symndx < symtab_hdr->sh_info)
@@ -2865,12 +2865,6 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
       /* It is OK to convert mov to lea.  */
       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)
-           continue;
-
          /* It is OK to convert indirect branch to direct branch.  It
             is OK to convert adc, add, and, cmp, or, sbb, sub, test,
             xor only when PIC is false.   */
@@ -2878,8 +2872,8 @@ elf_i386_convert_load (bfd *abfd, asection *sec,
            continue;
        }
 
-      /* 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 (r_symndx < symtab_hdr->sh_info)
        {
          isym = bfd_sym_from_r_symndx (&htab->sym_cache,
@@ -2991,8 +2985,7 @@ convert_load:
                {
                  /* Convert "mov foo@GOT(%reg1), %reg2" to
                     "lea foo@GOTOFF(%reg1), %reg2".  */
-                 if (r_type == R_386_GOT32X
-                     && (baseless || !bfd_link_pic (link_info)))
+                 if (baseless || !bfd_link_pic (link_info))
                    {
                      r_type = R_386_32;
                      /* For R_386_32, convert
index c8ce258fff896255977e1db2943a1e08e6910929..5a6b5bddc3af7ffbb55e52777f110390b8b1bfc8 100644 (file)
@@ -1,3 +1,13 @@
+2016-05-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       Backport from master
+       2016-05-19  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20117
+       * testsuite/ld-i386/i386.exp: Run pr20117.
+       * testsuite/ld-i386/pr20117.d: New file.
+       * testsuite/ld-i386/pr20117.s: Likewise.
+
 2016-05-18  Christophe Monat  <christophe.monat@st.com>
 
        Backport from master
index 1916c24b6c00cb6159c15617278933099b8d5fe3..b1332ffe211c5ccbd9aa06a40795fab05f6abb24 100644 (file)
@@ -328,6 +328,7 @@ run_dump_test "load5b"
 run_dump_test "load6"
 run_dump_test "pr19175"
 run_dump_test "pr19615"
+run_dump_test "pr20117"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
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