public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ELF: Don't check relocations in non-loaded, non-alloced sections
@ 2020-06-02 20:38 H.J. Lu
  2020-06-03  0:05 ` Fangrui Song
       [not found] ` <MWHPR12MB14567E24AED5430AAE2497A8CB880@MWHPR12MB1456.namprd12.prod.outlook.com>
  0 siblings, 2 replies; 10+ messages in thread
From: H.J. Lu @ 2020-06-02 20:38 UTC (permalink / raw)
  To: binutils

Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.

I will check it in if there are no objections.

H.J.
---
	* elf32-i386.c (elf_i386_check_relocs): Remove SEC_ALLOC check.
	* elf32-lm32.c (lm32_elf_check_relocs): Likewise.
	* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
	* elf32-nds32.c (nds32_elf_check_relocs): Likewise.
	* elf32-or1k.c (or1k_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
	* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elflink.c (_bfd_elf_link_check_relocs): Skip non-loaded,
	non-alloced sections.
---
 bfd/elf32-i386.c   |  9 ---------
 bfd/elf32-lm32.c   |  9 ---------
 bfd/elf32-m32r.c   |  9 ---------
 bfd/elf32-nds32.c  |  9 ---------
 bfd/elf32-or1k.c   |  9 ---------
 bfd/elf32-ppc.c    |  9 ---------
 bfd/elf32-sh.c     |  9 ---------
 bfd/elf32-xtensa.c |  2 +-
 bfd/elf64-alpha.c  |  9 ---------
 bfd/elf64-ppc.c    |  9 ---------
 bfd/elf64-x86-64.c |  9 ---------
 bfd/elflink.c      | 12 ++++++++++--
 12 files changed, 11 insertions(+), 93 deletions(-)

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 544b931552..f6f669957c 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1487,15 +1487,6 @@ elf_i386_check_relocs (bfd *abfd,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   htab = elf_x86_hash_table (info, I386_ELF_DATA);
   if (htab == NULL)
     {
diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c
index 5d09f2d350..acef37af5d 100644
--- a/bfd/elf32-lm32.c
+++ b/bfd/elf32-lm32.c
@@ -1128,15 +1128,6 @@ lm32_elf_check_relocs (bfd *abfd,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
   sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index afe0ee899c..9b8e5cd124 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -3450,15 +3450,6 @@ m32r_elf_check_relocs (bfd *abfd,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   sreloc = NULL;
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 4f7ea76469..3e094f6270 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -7081,15 +7081,6 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       return TRUE;
     }
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
   sym_hashes_end =
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index b141b45886..3ed44ccceb 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -1880,15 +1880,6 @@ or1k_elf_check_relocs (bfd *abfd,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
 
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 588b79781d..62c6270329 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -2888,15 +2888,6 @@ ppc_elf_check_relocs (bfd *abfd,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
 #ifdef DEBUG
   _bfd_error_handler ("ppc_elf_check_relocs called for section %pA in %pB",
 		      sec, abfd);
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 0428829757..7c9e695981 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -5376,15 +5376,6 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   BFD_ASSERT (is_sh_elf (abfd));
 
   symtab_hdr = &elf_symtab_hdr (abfd);
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 05c4f8430a..9dc815edbb 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -1039,7 +1039,7 @@ elf_xtensa_check_relocs (bfd *abfd,
   const Elf_Internal_Rela *rel;
   const Elf_Internal_Rela *rel_end;
 
-  if (bfd_link_relocatable (info) || (sec->flags & SEC_ALLOC) == 0)
+  if (bfd_link_relocatable (info))
     return TRUE;
 
   BFD_ASSERT (is_xtensa_elf (abfd));
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index 4e4efae0b1..0b31d450dc 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -1782,15 +1782,6 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   BFD_ASSERT (is_alpha_elf (abfd));
 
   dynobj = elf_hash_table (info)->dynobj;
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 49fda96be7..3941addd57 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -4536,15 +4536,6 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   BFD_ASSERT (is_ppc64_elf (abfd));
 
   htab = ppc_hash_table (info);
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 183c808346..eada0e53ed 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1862,15 +1862,6 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
   if (bfd_link_relocatable (info))
     return TRUE;
 
-  /* Don't do anything special with non-loaded, non-alloced sections.
-     In particular, any relocs in such sections should not affect GOT
-     and PLT reference counting (ie. we don't allow them to create GOT
-     or PLT entries), there's no possibility or desire to optimize TLS
-     relocs, and there's not much point in propagating relocs to shared
-     libs that the dynamic linker won't relocate.  */
-  if ((sec->flags & SEC_ALLOC) == 0)
-    return TRUE;
-
   htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
   if (htab == NULL)
     {
diff --git a/bfd/elflink.c b/bfd/elflink.c
index a2b40ccb04..7cee0afac0 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3956,8 +3956,16 @@ _bfd_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
 	  Elf_Internal_Rela *internal_relocs;
 	  bfd_boolean ok;
 
-	  /* Don't check relocations in excluded sections.  */
-	  if ((o->flags & SEC_RELOC) == 0
+	  /* Don't check relocations in excluded sections.  Don't do
+	     anything special with non-loaded, non-alloced sections.
+	     In particular, any relocs in such sections should not
+	     affect GOT and PLT reference counting (ie.  we don't
+	     allow them to create GOT or PLT entries), there's no
+	     possibility or desire to optimize TLS relocs, and
+	     there's not much point in propagating relocs to shared
+	     libs that the dynamic linker won't relocate.  */
+	  if ((o->flags & SEC_ALLOC) == 0
+	      || (o->flags & SEC_RELOC) == 0
 	      || (o->flags & SEC_EXCLUDE) != 0
 	      || o->reloc_count == 0
 	      || ((info->strip == strip_all || info->strip == strip_debugger)
-- 
2.26.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-06-05 12:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 20:38 [PATCH] ELF: Don't check relocations in non-loaded, non-alloced sections H.J. Lu
2020-06-03  0:05 ` Fangrui Song
     [not found] ` <MWHPR12MB14567E24AED5430AAE2497A8CB880@MWHPR12MB1456.namprd12.prod.outlook.com>
2020-06-03  1:29   ` H.J. Lu
2020-06-03 16:48     ` V2 " H.J. Lu
2020-06-03 18:55       ` V3 " H.J. Lu
2020-06-04  7:47         ` Alan Modra
2020-06-04 11:24           ` V4 " H.J. Lu
2020-06-04 12:41             ` Alan Modra
2020-06-05  3:07               ` Alan Modra
2020-06-05 12:32                 ` [PATCH] bfin: Skip non SEC_ALLOC section H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).