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)
committerAlan Modra <amodra@gmail.com>
Fri, 24 Apr 2015 23:45:49 +0000 (09:15 +0930)
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.
ld/testsuite/
* ld-powerpc/tocnovar.d: Revert last change.

include/elf/ChangeLog
include/elf/internal.h
ld/ChangeLog
ld/emultempl/ppc64elf.em
ld/testsuite/ChangeLog
ld/testsuite/ld-powerpc/tocnovar.d

index 2f2fc803caa5c01f3cc21423306abccad3fc584b..e4e094b231ade9a01765f877a2489504ba6f17d9 100644 (file)
@@ -1,3 +1,8 @@
+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.
+
 2015-04-24  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/18316
index b2492f55a2fbd9955a118ab9c0e8d1194e0dba0a..b49dd61394065dbdde0b65ded15c659a472657cf 100644 (file)
@@ -325,6 +325,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 e58963e9bfa21dbf889bdb8a7d3b8f195ec8db34..de594c05a5fc323a70d78749483dc7a433ed6928 100644 (file)
@@ -1,3 +1,8 @@
+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-24  DJ Delorie  <dj@redhat.com>
 
        * Makefile.am (msp430): Rename primary emulation to msp430elf.
index fd9a3cece5ea7500f83a934aa12dff5107f4abfa..2d26a957bd9c695bd6de09b71a475f14265fd31d 100644 (file)
@@ -546,13 +546,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);
 }
 
 
index 18516a2bc2ca797fed0f28ec097d815a0e4187ec..db467a9d89c08b10def98afa812221da8c72a667 100644 (file)
@@ -1,3 +1,7 @@
+2015-04-24  Alan Modra  <amodra@gmail.com>
+
+       * ld-powerpc/tocnovar.d: Revert last change.
+
 2015-04-24  Richard Earnshaw  <rearnsha@arm.com>
 
        * ld-arm/armthumb-lib.d: Regenerate expected output.
index 475617a2777202ce3ac354a99a0a670a96fdc31c..d1fd258b4fea4cee662b54e4637b4b795cddc1ed 100644 (file)
@@ -11,4 +11,4 @@
 #...
  +00 +\.text 
  +01 +\.opd \.got 
- +02 +\.opd \.got .*
+ +02 +\.opd \.got