This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [committed, PATCH] Convert mov to lea for loading address of local common symbol


On Fri, Oct 16, 2015 at 03:28:45AM -0700, H.J. Lu wrote:
> 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.
> 

We need to check if symbol is defined when converting mov to lea since
SYMBOL_REFERENCES_LOCAL may return true on hidden undefined symbols.

Checked in.

H.J.
---
	* elf32-i386.c (elf_i386_convert_mov_to_lea): Check if symbol
	is defined.
	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
---
 bfd/ChangeLog      | 6 ++++++
 bfd/elf32-i386.c   | 4 +++-
 bfd/elf64-x86-64.c | 4 +++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index d26a526..d371594 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
 2015-10-16  H.J. Lu  <hongjiu.lu@intel.com>
 
+	* elf32-i386.c (elf_i386_convert_mov_to_lea): Check if symbol
+	is defined.
+	* elf64-x86-64.c (elf_x86_64_convert_mov_to_lea): Likewise.
+
+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.
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 2e5c04d..8c1dadb 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2815,7 +2815,9 @@ 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->type != STT_GNU_IFUNC
+      if ((h->root.type == bfd_link_hash_defined
+	   || h->root.type == bfd_link_hash_defweak)
+	  && 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 aad3244..dc5fd0d 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3074,7 +3074,9 @@ 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->type != STT_GNU_IFUNC
+	  if ((h->root.type == bfd_link_hash_defined
+	       || h->root.type == bfd_link_hash_defweak)
+	      && h->type != STT_GNU_IFUNC
 	      && h != htab->elf.hdynamic
 	      && SYMBOL_REFERENCES_LOCAL (link_info, h))
 	    {
-- 
2.4.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]