]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Non-alloc sections don't belong in PT_LOAD segments
authorAlan Modra <amodra@gmail.com>
Fri, 24 Apr 2015 09:49:37 +0000 (19:19 +0930)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 24 Aug 2017 12:47:12 +0000 (09:47 -0300)
Taking them out showed a bug in the powerpc64 backend with .branch_lt
being removed from output_bfd but not from previously set up segment
section maps.  Removing the bfd sections meant their sh_flags (and
practically everything else) remaining zero, ie. not SHF_ALLOC,
triggering complaints about "`.branch_lt' can't be allocated in
segment".

include/elf/
* internal.h (ELF_SECTION_IN_SEGMENT_1): Ensure PT_LOAD and
similar segments only contain alloc sections.
ld/
* emultempl/ppc64elf.em (gld${EMULATION_NAME}_after_allocation):
Call gld${EMULATION_NAME}_map_segments regardless of need_laying_out.

include/elf/ChangeLog
include/elf/internal.h
ld/ChangeLog
ld/emultempl/ppc64elf.em

index 17978ba3fef9be8f5aad9a8d8b76dafd094918e8..4b9e0aee8203a249b9c7701d594c3b4c4355650d 100644 (file)
@@ -1,3 +1,10 @@
+2015-07-10  Alan Modra  <amodra@gmail.com>
+
+       Apply from master
+       2015-04-24  Alan Modra  <amodra@gmail.com>
+       * internal.h (ELF_SECTION_IN_SEGMENT_1): Ensure PT_LOAD and
+       similar segments only contain alloc sections.
+
 2014-10-09  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * sparc.h (Tag_GNU_Sparc_HWCAPS2): New object attribute.
index 310c1d9e47d52e32f1e928e11fb726ec1043296d..eb062df6e12d96135acd0dc5448f4d10ce761640 100644 (file)
@@ -317,6 +317,13 @@ struct elf_segment_map
     || (((sec_hdr)->sh_flags & SHF_TLS) == 0                           \
        && (segment)->p_type != PT_TLS                                  \
        && (segment)->p_type != PT_PHDR))                               \
+   /* PT_LOAD and similar segments only have SHF_ALLOC sections.  */   \
+   && !(((sec_hdr)->sh_flags & SHF_ALLOC) == 0                         \
+       && ((segment)->p_type == PT_LOAD                                \
+           || (segment)->p_type == PT_DYNAMIC                          \
+           || (segment)->p_type == PT_GNU_EH_FRAME                     \
+           || (segment)->p_type == PT_GNU_RELRO                        \
+           || (segment)->p_type == PT_GNU_STACK))                      \
    /* Any section besides one of type SHT_NOBITS must have file                \
       offsets within the segment.  */                                  \
    && ((sec_hdr)->sh_type == SHT_NOBITS                                        \
index 40193ba5b138ef746355de8ae01d23757543f2e3..0794b2582766d999337ed6102e2a70c28089542b 100644 (file)
@@ -1,6 +1,10 @@
 2015-07-10  Alan Modra  <amodra@gmail.com>
 
        Apply from master.
+       2015-04-24  Alan Modra  <amodra@gmail.com>
+       * emultempl/ppc64elf.em (gld${EMULATION_NAME}_after_allocation):
+       Call gld${EMULATION_NAME}_map_segments regardless of need_laying_out.
+
        2015-04-23  Alan Modra  <amodra@gmail.com>
        * emulparams/elf64ppc.sh (GOT): Align.
 
index 9646903d33e10560080d573f12147f7ee208dcd4..63a2e5d0d435d78019cb34d635c7a31ccb492023 100644 (file)
@@ -509,13 +509,16 @@ gld${EMULATION_NAME}_after_allocation (void)
   else if (ret > 0)
     need_laying_out = 1;
 
-  if (need_laying_out != -1)
-    {
-      gld${EMULATION_NAME}_map_segments (need_laying_out);
-
-      if (!link_info.relocatable)
-       ppc64_elf_set_toc (&link_info, link_info.output_bfd);
-    }
+  /* Call map_segments regardless of the state of need_laying_out.
+     need_laying_out set to -1 means we have just laid everything out,
+     but ppc64_elf_size_stubs strips .branch_lt and .eh_frame if
+     unneeded, after ppc_layout_sections_again.  Another call removes
+     these sections from the segment map.  Their presence is
+     innocuous except for confusing ELF_SECTION_IN_SEGMENT.  */
+  gld${EMULATION_NAME}_map_segments (need_laying_out > 0);
+
+  if (need_laying_out != -1 && !link_info.relocatable)
+    ppc64_elf_set_toc (&link_info, link_info.output_bfd);
 }