This is the mail archive of the binutils-cvs@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]

[binutils-gdb] PR23850, strip should not discard/move .rela.plt in executable


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a4bcd733712abd892aa7fe0d79a3f999b461f119

commit a4bcd733712abd892aa7fe0d79a3f999b461f119
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Nov 2 11:47:07 2018 +1030

    PR23850, strip should not discard/move .rela.plt in executable
    
    strip/objcopy can't deal with alloc reloc sections, not .rela.dyn or
    .rela.plt in a dynamic executable, or .rela.plt/.rela.iplt in a static
    executable.  So, don't have BFD treat them as side-channel data
    associated with the section they are relocating.
    
    	PR 23850
    	* elf.c (bfd_section_from_shdr): Treat SHF_ALLOC SHT_REL* sections
    	in an executable or shared library as normal sections.

Diff:
---
 bfd/ChangeLog |  6 ++++++
 bfd/elf.c     | 19 +++++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 383ad44..d8b50f5 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-02  Alan Modra  <amodra@gmail.com>
+
+	PR 23850
+	* elf.c (bfd_section_from_shdr): Treat SHF_ALLOC SHT_REL* sections
+	in an executable or shared library as normal sections.
+
 2018-10-31  Renlin Li  <renlin.li@arm.com>
 
 	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Don't create got
diff --git a/bfd/elf.c b/bfd/elf.c
index 764c61f..bebda20 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2384,15 +2384,18 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 	    && ! bfd_section_from_shdr (abfd, hdr->sh_link))
 	  goto fail;
 
-	/* If this reloc section does not use the main symbol table we
-	   don't treat it as a reloc section.  BFD can't adequately
-	   represent such a section, so at least for now, we don't
-	   try.  We just present it as a normal section.  We also
-	   can't use it as a reloc section if it points to the null
-	   section, an invalid section, another reloc section, or its
-	   sh_link points to the null section.  */
-	if (hdr->sh_link != elf_onesymtab (abfd)
+	/* If this is an alloc section in an executable or shared
+	   library, or the reloc section does not use the main symbol
+	   table we don't treat it as a reloc section.  BFD can't
+	   adequately represent such a section, so at least for now,
+	   we don't try.  We just present it as a normal section.  We
+	   also can't use it as a reloc section if it points to the
+	   null section, an invalid section, another reloc section, or
+	   its sh_link points to the null section.  */
+	if (((abfd->flags & (DYNAMIC | EXEC_P)) != 0
+	     && (hdr->sh_flags & SHF_ALLOC) != 0)
 	    || hdr->sh_link == SHN_UNDEF
+	    || hdr->sh_link != elf_onesymtab (abfd)
 	    || hdr->sh_info == SHN_UNDEF
 	    || hdr->sh_info >= num_sec
 	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL


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