Convert mov to lea for loading address of local common symbol
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 16 Oct 2015 10:14:40 +0000 (03:14 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 16 Oct 2015 10:14:40 +0000 (03:14 -0700)
There is no need to check def_regular when converting mov to lea for
loading address of local symbols since def_regular may be false for
common symbols and SYMBOL_REFERENCES_LOCAL is sufficient.

bfd/

* elf32-i386.c (elf_i386_convert_mov_to_lea): Don't check
def_regular.
* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.

ld/testsuite/

* ld-i386/lea1.s: Add a test for loading address of local common
symbol.
* ld-x86-64/lea1.s: Likewise.
* ld-i386/lea1a.d: Updated.
* ld-i386/lea1b.d: Likewise.
* ld-i386/lea1c.d: Likewise.
* ld-x86-64/lea1a.d: Likewise.
* ld-x86-64/lea1b.d: Likewise.
* ld-x86-64/lea1c.d: Likewise.
* ld-x86-64/lea1d.d: Likewise.
* ld-x86-64/lea1e.d: Likewise.
* ld-x86-64/lea1f.d: Likewise.

15 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-i386/lea1.s
ld/testsuite/ld-i386/lea1a.d
ld/testsuite/ld-i386/lea1b.d
ld/testsuite/ld-i386/lea1c.d
ld/testsuite/ld-x86-64/lea1.s
ld/testsuite/ld-x86-64/lea1a.d
ld/testsuite/ld-x86-64/lea1b.d
ld/testsuite/ld-x86-64/lea1c.d
ld/testsuite/ld-x86-64/lea1d.d
ld/testsuite/ld-x86-64/lea1e.d
ld/testsuite/ld-x86-64/lea1f.d

index 8400cf645fbc9efb6f3b07f6dfe0f9d092ef2bad..d26a526d424bed1f6a23766cff6415a5c8a2d92c 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf32-i386.c (elf_i386_convert_mov_to_lea): Don't check
+       def_regular.
+       * elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
+
 2015-10-15  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elflink.c (_bfd_elf_merge_symbol): Fix typos in comments
index 0a06191f98e7af8f3ab5c576071c1dd9d49c97c0..2e5c04da6348a095ccd80988a163a9fe9aae87b2 100644 (file)
@@ -2815,8 +2815,7 @@ elf_i386_convert_mov_to_lea (bfd *abfd, asection *sec,
 
       /* STT_GNU_IFUNC must keep R_386_GOT32 relocation.  We also avoid
         optimizing _DYNAMIC since ld.so may use its link-time address.  */
-      if (h->def_regular
-         && h->type != STT_GNU_IFUNC
+      if (h->type != STT_GNU_IFUNC
          && h != htab->elf.hdynamic
          && SYMBOL_REFERENCES_LOCAL (link_info, h)
          && irel->r_offset >= 2
index 29639d81d53238885c3c559c22cb49611424f14f..aad324490c994ca271eba2ee02d01f57b5d79d8b 100644 (file)
@@ -3074,8 +3074,7 @@ elf_x86_64_convert_mov_to_lea (bfd *abfd, asection *sec,
          /* STT_GNU_IFUNC must keep R_X86_64_GOTPCREL relocation.  We also
             avoid optimizing _DYNAMIC since ld.so may use its link-time
             address.  */
-         if (h->def_regular
-             && h->type != STT_GNU_IFUNC
+         if (h->type != STT_GNU_IFUNC
              && h != htab->elf.hdynamic
              && SYMBOL_REFERENCES_LOCAL (link_info, h))
            {
index af8a69fd01763b656914292a6f9523bf986cc112..83d28f03010e4a656d3f9930743dcbfac38cc380 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-16  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * ld-i386/lea1.s: Add a test for loading address of local common
+       symbol.
+       * ld-x86-64/lea1.s: Likewise.
+       * ld-i386/lea1a.d: Updated.
+       * ld-i386/lea1b.d: Likewise.
+       * ld-i386/lea1c.d: Likewise.
+       * ld-x86-64/lea1a.d: Likewise.
+       * ld-x86-64/lea1b.d: Likewise.
+       * ld-x86-64/lea1c.d: Likewise.
+       * ld-x86-64/lea1d.d: Likewise.
+       * ld-x86-64/lea1e.d: Likewise.
+       * ld-x86-64/lea1f.d: Likewise.
+
 2015-10-15  Alan Modra  <amodra@gmail.com>
 
        * config/default.exp (size): New global.
index 6afad884d1a625c9c011eb6351179af3ffb37618..f754ec03374f9d9e02315bf976f1df2d8258729d 100644 (file)
@@ -8,4 +8,7 @@ foo:
        .type   _start, @function
 _start:
        movl    foo@GOT(%ecx), %eax
+       movl    bar@GOT(%ecx), %eax
        .size   _start, .-_start
+       .comm   pad,4,4
+       .comm   bar,4,4
index 45b4965a94c515193bc0a10118c91da7e049b2f9..0435d3495b9f5a786b26f04f940ec8075f5c8307 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    8d 81 ([0-9a-f]{2} ){4} *       lea    -0x[a-f0-9]+\(%ecx\),%eax
+[      ]*[a-f0-9]+:    8d 81 ([0-9a-f]{2} ){4} *       lea    0x[a-f0-9]+\(%ecx\),%eax
 #pass
index 9ad4464ff31961c4fb4f62622f120a8653c1f2b5..8cef2c4f64a5b6720a20583b49b3f8003f30ae6c 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    8d 81 ([0-9a-f]{2} ){4} *       lea    -0x[a-f0-9]+\(%ecx\),%eax
+[      ]*[a-f0-9]+:    8d 81 ([0-9a-f]{2} ){4} *       lea    0x[a-f0-9]+\(%ecx\),%eax
 #pass
index 5ba8275324369ab6f8c2a3ad3adbc9fd648de9d2..c84f4137d3d28b1cd74f98da397942d13cd031cc 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    8d 81 ([0-9a-f]{2} ){4} *       lea    -0x[a-f0-9]+\(%ecx\),%eax
+[      ]*[a-f0-9]+:    8d 81 ([0-9a-f]{2} ){4} *       lea    0x[a-f0-9]+\(%ecx\),%eax
 #pass
index 4dce487c3fcf21fda8bb865fe1d444a34a076ee7..c2a499c5bf16b28735e97fb5fce77c7b30a938b9 100644 (file)
@@ -8,4 +8,7 @@ foo:
        .type   _start, @function
 _start:
        movq    foo@GOTPCREL(%rip), %rax
+       movq    bar@GOTPCREL(%rip), %rax
        .size   _start, .-_start
+       .comm   pad,4,4
+       .comm   bar,4,4
index b48f253d0f8cc0949615f75320f3297e24ad9ed5..75dad702da097530218b716d1d703438606eb8d2 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
+[      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <bar>
 #pass
index 9ee7220a49d612f50cb8561be9aa3157370d1108..d968ca29dfb8d12173a6e6a0a54450ea7dc7309c 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
+[      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <bar>
 #pass
index 6ff1618135154603521df7243b9521f91372772e..5f7e6c36977f27544d4cab025812694a3a2f6681 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
+[      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <bar>
 #pass
index d117f6b690646c91cab515ce132ea0912550c220..524980f9b980f3b7a083376ce066851e00a5febe 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
+[      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <bar>
 #pass
index bde3e6f69419dd47176ad803aad808fa8f79be28..22e6dcc04df54d1c1a0a98b6c794a88dc98ecf1a 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
+[      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <bar>
 #pass
index 568143a294dd0f1ee2707ed1a0c25c171281dd9c..9aff34d0b825acc0840db7573437833d3e616956 100644 (file)
@@ -10,4 +10,5 @@ Disassembly of section .text:
 
 #...
 [      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
+[      ]*[a-f0-9]+:    48 8d 05 ([0-9a-f]{2} ){4} *    lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <bar>
 #pass