From b31bcacc489d6ede2e9bdfa9905de0ebfd919454 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 16 Oct 2015 03:14:40 -0700 Subject: Convert mov to lea for loading address of local common symbol 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. --- bfd/ChangeLog | 6 ++++++ bfd/elf32-i386.c | 3 +-- bfd/elf64-x86-64.c | 3 +-- ld/testsuite/ChangeLog | 15 +++++++++++++++ ld/testsuite/ld-i386/lea1.s | 3 +++ ld/testsuite/ld-i386/lea1a.d | 1 + ld/testsuite/ld-i386/lea1b.d | 1 + ld/testsuite/ld-i386/lea1c.d | 1 + ld/testsuite/ld-x86-64/lea1.s | 3 +++ ld/testsuite/ld-x86-64/lea1a.d | 1 + ld/testsuite/ld-x86-64/lea1b.d | 1 + ld/testsuite/ld-x86-64/lea1c.d | 1 + ld/testsuite/ld-x86-64/lea1d.d | 1 + ld/testsuite/ld-x86-64/lea1e.d | 1 + ld/testsuite/ld-x86-64/lea1f.d | 1 + 15 files changed, 38 insertions(+), 4 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8400cf645fb..d26a526d424 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2015-10-16 H.J. Lu + + * 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 * elflink.c (_bfd_elf_merge_symbol): Fix typos in comments diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 0a06191f98e..2e5c04da634 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -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 diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 29639d81d53..aad324490c9 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -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)) { diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index af8a69fd017..83d28f03010 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2015-10-16 H.J. Lu + + * 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 * config/default.exp (size): New global. diff --git a/ld/testsuite/ld-i386/lea1.s b/ld/testsuite/ld-i386/lea1.s index 6afad884d1a..f754ec03374 100644 --- a/ld/testsuite/ld-i386/lea1.s +++ b/ld/testsuite/ld-i386/lea1.s @@ -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 diff --git a/ld/testsuite/ld-i386/lea1a.d b/ld/testsuite/ld-i386/lea1a.d index 45b4965a94c..0435d3495b9 100644 --- a/ld/testsuite/ld-i386/lea1a.d +++ b/ld/testsuite/ld-i386/lea1a.d @@ -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 diff --git a/ld/testsuite/ld-i386/lea1b.d b/ld/testsuite/ld-i386/lea1b.d index 9ad4464ff31..8cef2c4f64a 100644 --- a/ld/testsuite/ld-i386/lea1b.d +++ b/ld/testsuite/ld-i386/lea1b.d @@ -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 diff --git a/ld/testsuite/ld-i386/lea1c.d b/ld/testsuite/ld-i386/lea1c.d index 5ba82753243..c84f4137d3d 100644 --- a/ld/testsuite/ld-i386/lea1c.d +++ b/ld/testsuite/ld-i386/lea1c.d @@ -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 diff --git a/ld/testsuite/ld-x86-64/lea1.s b/ld/testsuite/ld-x86-64/lea1.s index 4dce487c3fc..c2a499c5bf1 100644 --- a/ld/testsuite/ld-x86-64/lea1.s +++ b/ld/testsuite/ld-x86-64/lea1.s @@ -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 diff --git a/ld/testsuite/ld-x86-64/lea1a.d b/ld/testsuite/ld-x86-64/lea1a.d index b48f253d0f8..75dad702da0 100644 --- a/ld/testsuite/ld-x86-64/lea1a.d +++ b/ld/testsuite/ld-x86-64/lea1a.d @@ -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]+ +[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ #pass diff --git a/ld/testsuite/ld-x86-64/lea1b.d b/ld/testsuite/ld-x86-64/lea1b.d index 9ee7220a49d..d968ca29dfb 100644 --- a/ld/testsuite/ld-x86-64/lea1b.d +++ b/ld/testsuite/ld-x86-64/lea1b.d @@ -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]+ +[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ #pass diff --git a/ld/testsuite/ld-x86-64/lea1c.d b/ld/testsuite/ld-x86-64/lea1c.d index 6ff16181351..5f7e6c36977 100644 --- a/ld/testsuite/ld-x86-64/lea1c.d +++ b/ld/testsuite/ld-x86-64/lea1c.d @@ -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]+ +[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ #pass diff --git a/ld/testsuite/ld-x86-64/lea1d.d b/ld/testsuite/ld-x86-64/lea1d.d index d117f6b6906..524980f9b98 100644 --- a/ld/testsuite/ld-x86-64/lea1d.d +++ b/ld/testsuite/ld-x86-64/lea1d.d @@ -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]+ +[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ #pass diff --git a/ld/testsuite/ld-x86-64/lea1e.d b/ld/testsuite/ld-x86-64/lea1e.d index bde3e6f6941..22e6dcc04df 100644 --- a/ld/testsuite/ld-x86-64/lea1e.d +++ b/ld/testsuite/ld-x86-64/lea1e.d @@ -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]+ +[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ #pass diff --git a/ld/testsuite/ld-x86-64/lea1f.d b/ld/testsuite/ld-x86-64/lea1f.d index 568143a294d..9aff34d0b82 100644 --- a/ld/testsuite/ld-x86-64/lea1f.d +++ b/ld/testsuite/ld-x86-64/lea1f.d @@ -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]+ +[ ]*[a-f0-9]+: 48 8d 05 ([0-9a-f]{2} ){4} * lea 0x[a-f0-9]+\(%rip\),%rax # [a-f0-9]+ #pass -- cgit v1.2.1