* emultempl/elf32.em (gld${EMULATION_NAME}_layout_sections_again):
authorAlan Modra <amodra@gmail.com>
Tue, 29 Mar 2005 11:07:38 +0000 (11:07 +0000)
committerAlan Modra <amodra@gmail.com>
Tue, 29 Mar 2005 11:07:38 +0000 (11:07 +0000)
New function, extracted from static void gld${EMULATION_NAME}_finish.
(gld${EMULATION_NAME}_strip_empty_sections): Likewise.
(gld${EMULATION_NAME}_provide_init_fini_syms): Likewise.
* emultempl/ppc64elf.em: Revert last change.
(ppc_layout_sections_again): Use
gld${EMULATION_NAME}_layout_sections_again.
(ppc_finish): Don't call gld${EMULATION_NAME}_finish.  Instead call
gld${EMULATION_NAME}_strip_empty_sections and
gld${EMULATION_NAME}_provide_init_fini_syms.
* emultempl/hppaelf.em: Similarly.

ld/ChangeLog
ld/emultempl/elf32.em
ld/emultempl/hppaelf.em
ld/emultempl/ppc64elf.em

index 3e2b01f0ab56a853c6ae7c10d837a699f41072da..4066d1e83acbea0d1240af6aa4605bc28cf75797 100644 (file)
@@ -1,3 +1,17 @@
+2005-03-29  Alan Modra  <amodra@bigpond.net.au>
+
+       * emultempl/elf32.em (gld${EMULATION_NAME}_layout_sections_again):
+       New function, extracted from static void gld${EMULATION_NAME}_finish.
+       (gld${EMULATION_NAME}_strip_empty_sections): Likewise.
+       (gld${EMULATION_NAME}_provide_init_fini_syms): Likewise.
+       * emultempl/ppc64elf.em: Revert last change.
+       (ppc_layout_sections_again): Use
+       gld${EMULATION_NAME}_layout_sections_again.
+       (ppc_finish): Don't call gld${EMULATION_NAME}_finish.  Instead call
+       gld${EMULATION_NAME}_strip_empty_sections and
+       gld${EMULATION_NAME}_provide_init_fini_syms.
+       * emultempl/hppaelf.em: Similarly.
+
 2005-03-29  Alan Modra  <amodra@bigpond.net.au>
 
        * emultempl/ppc64elf.em (need_laying_out): Delete.  Remove all refs.
@@ -15,7 +29,7 @@
        implementation, not just the GNU C library.
        * configure.tgt: Likewise.
        * emultempl/elf32.em: Likewise.
-               
+
 2005-03-22  H.J. Lu  <hongjiu.lu@intel.com>
 
        * emultempl/elf32.em (gld${EMULATION_NAME}_provide_bound_symbols): New
index ca5eafdff93d2675d5c5a81d59628d1920b84cf7..3b9cdd785694aa5be5c781524ef9c2b17509b60f 100644 (file)
@@ -59,7 +59,10 @@ static void gld${EMULATION_NAME}_after_open (void);
 static void gld${EMULATION_NAME}_before_allocation (void);
 static bfd_boolean gld${EMULATION_NAME}_place_orphan
   (lang_input_statement_type *file, asection *s);
-static void gld${EMULATION_NAME}_finish (void);
+static void gld${EMULATION_NAME}_layout_sections_again (void);
+static void gld${EMULATION_NAME}_strip_empty_sections (void);
+static void gld${EMULATION_NAME}_provide_init_fini_syms (void);
+static void gld${EMULATION_NAME}_finish (void) ATTRIBUTE_UNUSED;
 
 EOF
 
@@ -1450,25 +1453,58 @@ gld${EMULATION_NAME}_provide_bound_symbols (const char *sec,
   _bfd_elf_provide_symbol (&link_info, end, end_val);
 }
 
+/* If not building a shared library, provide
+
+   __preinit_array_start
+   __preinit_array_end
+   __init_array_start
+   __init_array_end
+   __fini_array_start
+   __fini_array_end
+
+   They are set here rather than via PROVIDE in the linker
+   script, because using PROVIDE inside an output section
+   statement results in unnecessary output sections.  Using
+   PROVIDE outside an output section statement runs the risk of
+   section alignment affecting where the section starts.  */
+
 static void
-gld${EMULATION_NAME}_finish (void)
+gld${EMULATION_NAME}_provide_init_fini_syms (void)
 {
-  if (bfd_elf_discard_info (output_bfd, &link_info))
+  if (!link_info.relocatable && !link_info.shared)
     {
-      lang_reset_memory_regions ();
+      gld${EMULATION_NAME}_provide_bound_symbols (".preinit_array",
+                                                 "__preinit_array_start",
+                                                 "__preinit_array_end");
+      gld${EMULATION_NAME}_provide_bound_symbols (".init_array",
+                                                 "__init_array_start",
+                                                 "__init_array_end");
+      gld${EMULATION_NAME}_provide_bound_symbols (".fini_array",
+                                                 "__fini_array_start",
+                                                 "__fini_array_end");
+    }
+}
 
-      /* Resize the sections.  */
-      lang_size_sections (stat_ptr->head, abs_output_section,
-                         &stat_ptr->head, 0, (bfd_vma) 0, NULL, TRUE);
+static void
+gld${EMULATION_NAME}_layout_sections_again (void)
+{
+  lang_reset_memory_regions ();
 
-      /* Redo special stuff.  */
-      ldemul_after_allocation ();
+  /* Resize the sections.  */
+  lang_size_sections (stat_ptr->head, abs_output_section,
+                     &stat_ptr->head, 0, (bfd_vma) 0, NULL, TRUE);
 
-      /* Do the assignments again.  */
-      lang_do_assignments (stat_ptr->head, abs_output_section,
-                          (fill_type *) 0, (bfd_vma) 0);
-    }
+  /* Redo special stuff.  */
+  ldemul_after_allocation ();
 
+  /* Do the assignments again.  */
+  lang_do_assignments (stat_ptr->head, abs_output_section,
+                      (fill_type *) 0, (bfd_vma) 0);
+}
+
+static void
+gld${EMULATION_NAME}_strip_empty_sections (void)
+{
   if (!link_info.relocatable)
     {
       lang_output_section_statement_type *os;
@@ -1495,35 +1531,17 @@ gld${EMULATION_NAME}_finish (void)
                  }
            }
        }
+    }
+}
 
-      /* If not building shared library, provide
-
-        __preinit_array_start
-        __preinit_array_end
-        __init_array_start
-        __init_array_end
-        __fini_array_start
-        __fini_array_end
-
-        They are set here rather than via PROVIDE in the linker
-        script, because using PROVIDE inside an output section
-        statement results in unnecessary output sections.  Using
-        PROVIDE outside an output section statement runs the risk of
-        section alignment affecting where the section starts.  */
+static void
+gld${EMULATION_NAME}_finish (void)
+{
+  if (bfd_elf_discard_info (output_bfd, &link_info))
+    gld${EMULATION_NAME}_layout_sections_again ();
 
-      if (!link_info.shared)
-       {
-         gld${EMULATION_NAME}_provide_bound_symbols
-           (".preinit_array", "__preinit_array_start",
-            "__preinit_array_end");
-         gld${EMULATION_NAME}_provide_bound_symbols
-           (".init_array", "__init_array_start",
-            "__init_array_end");
-         gld${EMULATION_NAME}_provide_bound_symbols
-           (".fini_array", "__fini_array_start",
-            "__fini_array_end");
-       }
-    }
+  gld${EMULATION_NAME}_strip_empty_sections ();
+  gld${EMULATION_NAME}_provide_init_fini_syms ();
 }
 EOF
 fi
index 058998495fc9fdc7e4d049ba59e04a4cb2b3d893..0843bc35f6c7fc7f4f3d2e01d9bb201a7cfb4978 100644 (file)
@@ -36,6 +36,9 @@ static lang_input_statement_type *stub_file;
    stubs.  */
 static int multi_subspace = 0;
 
+/* Whether we need to call hppa_layout_sections_again.  */
+static int need_laying_out = 0;
+
 /* Maximum size of a group of input sections that can be handled by
    one stub section.  A value of +/-1 indicates the bfd back-end
    should use a suitable default size.  */
@@ -217,18 +220,9 @@ hppaelf_layout_sections_again (void)
   /* If we have changed sizes of the stub sections, then we need
      to recalculate all the section offsets.  This may mean we need to
      add even more stubs.  */
-  lang_reset_memory_regions ();
-
-  /* Resize the sections.  */
-  lang_size_sections (stat_ptr->head, abs_output_section,
-                     &stat_ptr->head, 0, (bfd_vma) 0, NULL, TRUE);
+  need_laying_out = 0;
 
-  /* Redo special stuff.  */
-  ldemul_after_allocation ();
-
-  /* Do the assignments again.  */
-  lang_do_assignments (stat_ptr->head, abs_output_section,
-                      (fill_type *) 0, (bfd_vma) 0);
+  gld${EMULATION_NAME}_layout_sections_again ();
 }
 
 
@@ -253,6 +247,13 @@ build_section_lists (lang_statement_union_type *statement)
 static void
 hppaelf_finish (void)
 {
+  /* bfd_elf_discard_info just plays with debugging sections,
+     ie. doesn't affect any code, so we can delay resizing the
+     sections.  It's likely we'll resize everything in the process of
+     adding stubs.  */
+  if (bfd_elf_discard_info (output_bfd, &link_info))
+    need_laying_out = 1;
+
   /* If generating a relocatable output file, then we don't
      have to examine the relocs.  */
   if (stub_file != NULL && !link_info.relocatable)
@@ -284,6 +285,9 @@ hppaelf_finish (void)
        }
     }
 
+  if (need_laying_out)
+    hppaelf_layout_sections_again ();
+
   if (! link_info.relocatable)
     {
       /* Set the global data pointer.  */
@@ -297,14 +301,12 @@ hppaelf_finish (void)
       if (stub_file != NULL && stub_file->the_bfd->sections != NULL)
        {
          if (! elf32_hppa_build_stubs (&link_info))
-           {
-             einfo ("%X%P: can not build stubs: %E\n");
-             return;
-           }
+           einfo ("%X%P: can not build stubs: %E\n");
        }
     }
 
-  gld${EMULATION_NAME}_finish ();
+  gld${EMULATION_NAME}_strip_empty_sections ();
+  gld${EMULATION_NAME}_provide_init_fini_syms ();
 }
 
 
index a334c9f6bc53f15c98207864480688bbf6f6fb7c..d468e8c2746220a5fe8758707a1305ab853fa7fe 100644 (file)
@@ -32,6 +32,9 @@ cat >>e${EMULATION_NAME}.c <<EOF
 static lang_input_statement_type *stub_file;
 static int stub_added = 0;
 
+/* Whether we need to call ppc_layout_sections_again.  */
+static int need_laying_out = 0;
+
 /* Maximum size of a group of input sections that can be handled by
    one stub section.  A value of +/-1 indicates the bfd back-end
    should use a suitable default size.  */
@@ -255,17 +258,9 @@ ppc_layout_sections_again (void)
   /* If we have changed sizes of the stub sections, then we need
      to recalculate all the section offsets.  This may mean we need to
      add even more stubs.  */
-  lang_reset_memory_regions ();
-
-  /* Resize the sections.  */
-  lang_size_sections (stat_ptr->head, abs_output_section,
-                     &stat_ptr->head, 0, 0, NULL, TRUE);
-
-  /* Recalculate TOC base.  */
-  ldemul_after_allocation ();
+  need_laying_out = 0;
 
-  /* Do the assignments again.  */
-  lang_do_assignments (stat_ptr->head, abs_output_section, NULL, 0);
+  gld${EMULATION_NAME}_layout_sections_again ();
 }
 
 
@@ -316,6 +311,13 @@ ppc_finish (void)
      descriptor in the .opd section.  */
   entry_section = ".opd";
 
+  /* bfd_elf_discard_info just plays with debugging sections,
+     ie. doesn't affect any code, so we can delay resizing the
+     sections.  It's likely we'll resize everything in the process of
+     adding stubs.  */
+  if (bfd_elf_discard_info (output_bfd, &link_info))
+    need_laying_out = 1;
+
   /* If generating a relocatable output file, then we don't have any
      stubs.  */
   if (stub_file != NULL && !link_info.relocatable)
@@ -344,6 +346,9 @@ ppc_finish (void)
        }
     }
 
+  if (need_laying_out)
+    ppc_layout_sections_again ();
+
   if (link_info.relocatable)
     {
       asection *toc = bfd_get_section_by_name (output_bfd, ".toc");
@@ -374,7 +379,8 @@ ppc_finish (void)
     }
 
   ppc64_elf_restore_symbols (&link_info);
-  gld${EMULATION_NAME}_finish ();
+  gld${EMULATION_NAME}_strip_empty_sections ();
+  gld${EMULATION_NAME}_provide_init_fini_syms ();
 }