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] x86: Add GENERATE_RELATIVE_RELOC_P


On Fri, Oct 06, 2017 at 12:32:19AM -0700, H.J. Lu wrote:
> Add GENERATE_RELATIVE_RELOC_P which returns TRUE if dynamic relative
> relocation should be generated.
> 
> 	* elfxx-x86.h (GENERATE_RELATIVE_RELOC_P): New.
> 	* elf32-i386.c (elf_i386_relocate_section): Use it.
> 	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.

Here is the actual change.

H.J.
---
Add GENERATE_RELATIVE_RELOC_P which returns TRUE if dynamic relative
relocation should be generated.

	* elfxx-x86.h (GENERATE_RELATIVE_RELOC_P): New.
	* elf32-i386.c (elf_i386_relocate_section): Use it.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
---
 bfd/ChangeLog      |  6 ++++++
 bfd/elf32-i386.c   |  5 +----
 bfd/elf64-x86-64.c |  5 +----
 bfd/elfxx-x86.h    | 12 ++++++++++++
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index b43cdfac9b..afd14b8740 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
 2017-10-06  H.J. Lu  <hongjiu.lu@intel.com>
 
+	* elfxx-x86.h (GENERATE_RELATIVE_RELOC_P): New.
+	* elf32-i386.c (elf_i386_relocate_section): Use it.
+	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
+
+2017-10-06  H.J. Lu  <hongjiu.lu@intel.com>
+
 	* elfxx-x86.h (RESOLVED_LOCALLY_P): New.
 	* elf32-i386.c (elf_i386_relocate_section): Use it.
 	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 25d349ce00..198732cec3 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2531,10 +2531,7 @@ r_386_got32:
 				  htab->elf.sgot->contents + off);
 		      h->got.offset |= 1;
 
-		      if (h->dynindx == -1
-			  && !h->forced_local
-			  && h->root.type != bfd_link_hash_undefweak
-			  && bfd_link_pic (info))
+		      if (GENERATE_RELATIVE_RELOC_P (info, h))
 			{
 			  /* PR ld/21402: If this symbol isn't dynamic
 			     in PIC, generate R_386_RELATIVE here.  */
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 5a9e3fd614..d443551b44 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2797,10 +2797,7 @@ do_ifunc_pointer:
 			 as -1 | 1 still is -1.  */
 		      h->got.offset |= 1;
 
-		      if (h->dynindx == -1
-			  && !h->forced_local
-			  && h->root.type != bfd_link_hash_undefweak
-			  && bfd_link_pic (info))
+		      if (GENERATE_RELATIVE_RELOC_P (info, h))
 			{
 			  /* If this symbol isn't dynamic in PIC,
 			     generate R_X86_64_RELATIVE here.  */
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 317c86ea75..02a388a368 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -124,6 +124,18 @@
        || (ELF_ST_VISIBILITY ((H)->other) \
 	   && (H)->root.type == bfd_link_hash_undefweak))
 
+/* TRUE if relative relocation should be generated.  GOT reference to
+   global symbol in PIC will lead to dynamic symbol.  It becomes a
+   problem when "time" or "times" is defined as a variable in an
+   executable, clashing with functions of the same name in libc.  If a
+   symbol isn't undefined weak symbol, don't make it dynamic in PIC and
+   generate relative relocation.  */
+#define GENERATE_RELATIVE_RELOC_P(INFO, H) \
+  ((H)->dynindx == -1 \
+   && !(H)->forced_local \
+   && (H)->root.type != bfd_link_hash_undefweak \
+   && bfd_link_pic (INFO))
+
 /* TRUE if TLS IE->LE transition is OK.  */
 #define TLS_TRANSITION_IE_TO_LE_P(INFO, H, TLS_TYPE) \
   (bfd_link_executable (INFO) \
-- 
2.13.6


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