PR 10474
authorAlan Modra <amodra@gmail.com>
Mon, 10 Aug 2009 07:50:56 +0000 (07:50 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 10 Aug 2009 07:50:56 +0000 (07:50 +0000)
* ldemul.c (after_allocation_default): Run lang_relax_sections.
* ldlang.h (lang_relax_sections): Declare.
* ldlang.c (relax_sections): Delete.
(lang_relax_sections): New function.
(lang_process): Don't relax directly from here.
* emultempl/alphaelf.em (alpha_finish): Call finish_default.
* emultempl/armelf.em (arm_elf_after_allocation): Delete.  Move body..
(gld${EMULATION_NAME}_finish): ..to here.  Move existing code..
(gld${EMULATION_NAME}_after_allocation): ..to here.  New function.
(LDEMUL_AFTER_ALLOCATION): Update.
* emultempl/avrelf.em (avr_elf_finish, LDEMUL_FINISH): Delete.
(avr_elf_after_allocation): New function.
(LDEMUL_AFTER_ALLOCATION): Define.
* emultempl/elf-generic.em (gld${EMULATION_NAME}_map_segments): Call
lang_relax_sections.
* emultempl/elf32.em (gld${EMULATION_NAME}_finish): Delete.  Move..
(gld${EMULATION_NAME}_after_allocation): ..code to here.  New function.
(LDEMUL_AFTER_ALLOCATION, LDEMUL_FINISH): Update.
* emultempl/genelf.em (gld${EMULATION_NAME}_finish): Delete.  Move..
(gld${EMULATION_NAME}_after_allocation): ..code to here.  New function.
(LDEMUL_FINISH): Delete.
(LDEMUL_AFTER_ALLOCATION): Define.
* emultempl/hppaelf.em (gld${EMULATION_NAME}_finish): Delete.  Move..
(gld${EMULATION_NAME}_after_allocation): ..to here.  New function.
(LDEMUL_FINISH): Delete.
(LDEMUL_AFTER_ALLOCATION): Define.
* emultempl/m68hc1xelf.em (m68hc11elf_finish): Delete.  Move..
(m68hc11elf_after_allocation): ..to here.  New function.
(LDEMUL_FINISH): Delete.
(LDEMUL_AFTER_ALLOCATION): Define.
* emultempl/m68kelf.em (m68k_elf_after_allocation): Call
gld${EMULATION_NAME}_after_allocation.
* emultempl/mmix-elfnmmo.em (mmix_after_allocation): Call
gld${EMULATION_NAME}_after_allocation.
* emultempl/mmo.em (mmo_finish): Delete.  Move body..
(gld${EMULATION_NAME}_after_allocation): ..to here.  New function.
(LDEMUL_FINISH): Define.
* emultempl/ppc64elf.em (ppc_layout_sections_again): Set elf_gp.
(gld${EMULATION_NAME}_finish): Move code sizing sections..
(gld${EMULATION_NAME}_after_allocation): ..to here.
* emultempl/sh64elf.em (sh64_elf_${EMULATION_NAME}_after_allocation):
Call gld${EMULATION_NAME}_after_allocation.
* emultempl/spuelf.em (gld${EMULATION_NAME}_finish): Delete
bfd_elf_discard_info and map_segments call.

18 files changed:
ld/ChangeLog
ld/emultempl/alphaelf.em
ld/emultempl/armelf.em
ld/emultempl/avrelf.em
ld/emultempl/elf-generic.em
ld/emultempl/elf32.em
ld/emultempl/genelf.em
ld/emultempl/hppaelf.em
ld/emultempl/m68hc1xelf.em
ld/emultempl/m68kelf.em
ld/emultempl/mmix-elfnmmo.em
ld/emultempl/mmo.em
ld/emultempl/ppc64elf.em
ld/emultempl/sh64elf.em
ld/emultempl/spuelf.em
ld/ldemul.c
ld/ldlang.c
ld/ldlang.h

index 554687f457e00d8e73df5fd2654528d04926711b..e6897fc3047de36e1e413f1f7c18fbdf9b738512 100644 (file)
@@ -1,3 +1,51 @@
+2009-08-10  Alan Modra  <amodra@bigpond.net.au>
+
+       PR 10474
+       * ldemul.c (after_allocation_default): Run lang_relax_sections.
+       * ldlang.h (lang_relax_sections): Declare.
+       * ldlang.c (relax_sections): Delete.
+       (lang_relax_sections): New function.
+       (lang_process): Don't relax directly from here.
+       * emultempl/alphaelf.em (alpha_finish): Call finish_default.
+       * emultempl/armelf.em (arm_elf_after_allocation): Delete.  Move body..
+       (gld${EMULATION_NAME}_finish): ..to here.  Move existing code..
+       (gld${EMULATION_NAME}_after_allocation): ..to here.  New function.
+       (LDEMUL_AFTER_ALLOCATION): Update.
+       * emultempl/avrelf.em (avr_elf_finish, LDEMUL_FINISH): Delete.
+       (avr_elf_after_allocation): New function.
+       (LDEMUL_AFTER_ALLOCATION): Define.
+       * emultempl/elf-generic.em (gld${EMULATION_NAME}_map_segments): Call
+       lang_relax_sections.
+       * emultempl/elf32.em (gld${EMULATION_NAME}_finish): Delete.  Move..
+       (gld${EMULATION_NAME}_after_allocation): ..code to here.  New function.
+       (LDEMUL_AFTER_ALLOCATION, LDEMUL_FINISH): Update.
+       * emultempl/genelf.em (gld${EMULATION_NAME}_finish): Delete.  Move..
+       (gld${EMULATION_NAME}_after_allocation): ..code to here.  New function.
+       (LDEMUL_FINISH): Delete.
+       (LDEMUL_AFTER_ALLOCATION): Define.
+       * emultempl/hppaelf.em (gld${EMULATION_NAME}_finish): Delete.  Move..
+       (gld${EMULATION_NAME}_after_allocation): ..to here.  New function.
+       (LDEMUL_FINISH): Delete.
+       (LDEMUL_AFTER_ALLOCATION): Define.
+       * emultempl/m68hc1xelf.em (m68hc11elf_finish): Delete.  Move..
+       (m68hc11elf_after_allocation): ..to here.  New function.
+       (LDEMUL_FINISH): Delete.
+       (LDEMUL_AFTER_ALLOCATION): Define.
+       * emultempl/m68kelf.em (m68k_elf_after_allocation): Call
+       gld${EMULATION_NAME}_after_allocation.
+       * emultempl/mmix-elfnmmo.em (mmix_after_allocation): Call
+       gld${EMULATION_NAME}_after_allocation.
+       * emultempl/mmo.em (mmo_finish): Delete.  Move body..
+       (gld${EMULATION_NAME}_after_allocation): ..to here.  New function.
+       (LDEMUL_FINISH): Define.
+       * emultempl/ppc64elf.em (ppc_layout_sections_again): Set elf_gp.
+       (gld${EMULATION_NAME}_finish): Move code sizing sections..
+       (gld${EMULATION_NAME}_after_allocation): ..to here.
+       * emultempl/sh64elf.em (sh64_elf_${EMULATION_NAME}_after_allocation):
+       Call gld${EMULATION_NAME}_after_allocation.
+       * emultempl/spuelf.em (gld${EMULATION_NAME}_finish): Delete
+       bfd_elf_discard_info and map_segments call.
+
 2009-08-06  Michael Eager <eager@eagercon.com>
 
        * Makefile.am: Add eelf32mb_linux.o, eelf32microblaze.o to 
index d6766ba51ff920068273eef8f1aac67396d92116..a2f460f14ae3bbd610f62271c41549c7ab10d665 100644 (file)
@@ -98,7 +98,7 @@ alpha_finish (void)
   if (limit_32bit)
     elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
 
-  gld${EMULATION_NAME}_finish ();
+  finish_default ();
 }
 EOF
 
index 0713c728d2b6506d8ea6b906c85e2e1f516a9deb..fffffd9ced243f4dabc91c9dc610f9f6acb56ab7 100644 (file)
@@ -89,22 +89,6 @@ arm_elf_before_allocation (void)
   gld${EMULATION_NAME}_before_allocation ();
 }
 
-static void
-arm_elf_after_allocation (void)
-{
-  /* Call the standard elf routine.  */
-  after_allocation_default ();
-
-  {
-    LANG_FOR_EACH_INPUT_STATEMENT (is)
-      {
-        /* Figure out where VFP11 erratum veneers (and the labels returning
-           from same) have been placed.  */
-        bfd_elf32_arm_vfp11_fix_veneer_locations (is->the_bfd, &link_info);
-      }
-  }
-}
-
 /* Fake input file for stubs.  */
 static lang_input_statement_type *stub_file;
 
@@ -285,17 +269,16 @@ compare_output_sec_vma (const void *a, const void *b)
 }
 
 static void
-gld${EMULATION_NAME}_finish (void)
+gld${EMULATION_NAME}_after_allocation (void)
 {
-  struct bfd_link_hash_entry * h;
-  unsigned int list_size = 10;
-  asection **sec_list = xmalloc (list_size * sizeof (asection *));
-  unsigned int sec_count = 0;
-
   if (!link_info.relocatable)
     {
       /* Build a sorted list of input text sections, then use that to process
         the unwind table index.  */
+      unsigned int list_size = 10;
+      asection **sec_list = xmalloc (list_size * sizeof (asection *));
+      unsigned int sec_count = 0;
+
       LANG_FOR_EACH_INPUT_STATEMENT (is)
        {
          bfd *abfd = is->the_bfd;
@@ -375,6 +358,21 @@ gld${EMULATION_NAME}_finish (void)
 
   if (need_laying_out != -1)
     gld${EMULATION_NAME}_map_segments (need_laying_out);
+}
+
+static void
+gld${EMULATION_NAME}_finish (void)
+{
+  struct bfd_link_hash_entry * h;
+
+  {
+    LANG_FOR_EACH_INPUT_STATEMENT (is)
+      {
+        /* Figure out where VFP11 erratum veneers (and the labels returning
+           from same) have been placed.  */
+        bfd_elf32_arm_vfp11_fix_veneer_locations (is->the_bfd, &link_info);
+      }
+  }
 
   if (! link_info.relocatable)
     {
@@ -659,7 +657,7 @@ PARSE_AND_LIST_ARGS_CASES='
 # We have our own before_allocation etc. functions, but they call
 # the standard routines, so give them a different name.
 LDEMUL_BEFORE_ALLOCATION=arm_elf_before_allocation
-LDEMUL_AFTER_ALLOCATION=arm_elf_after_allocation
+LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=arm_elf_create_output_section_statements
 
 # Replace the elf before_parse function with our own.
index 1bd7bb3cae4873a40414667e22948e1b49ad842f..9ab5a4604796500ef03823bc7f2f3ea2876fcafe 100644 (file)
@@ -144,29 +144,24 @@ avr_elf_create_output_section_statements (void)
 /* Re-calculates the size of the stubs so that we won't waste space.  */
 
 static void
-avr_elf_finish (void)
+avr_elf_after_allocation (void)
 {
-  if (!avr_no_stubs)
+  if (!avr_no_stubs && !command_line.relax)
     {
-      /* Now build the linker stubs.  */
-      if (stub_file->the_bfd->sections != NULL)
-       {
-         /* Call again the trampoline analyzer to initialize the trampoline
-            stubs with the correct symbol addresses.  Since there could have
-            been relaxation, the symbol addresses that were found during
-            first call may no longer be correct.  */
-         if (!elf32_avr_size_stubs (link_info.output_bfd, &link_info, FALSE))
-           {
-             einfo ("%X%P: can not size stub section: %E\n");
-             return;
-           }
-
-         if (!elf32_avr_build_stubs (&link_info))
-           einfo ("%X%P: can not build stubs: %E\n");
-       }
+      /* If relaxing, elf32_avr_size_stubs will be called from
+        elf32_avr_relax_section.  */
+      if (!elf32_avr_size_stubs (link_info.output_bfd, &link_info, FALSE))
+       einfo ("%X%P: can not size stub section: %E\n");
     }
 
-  gld${EMULATION_NAME}_finish ();
+  gld${EMULATION_NAME}_after_allocation ();
+
+  /* Now build the linker stubs.  */
+  if (!avr_no_stubs)
+    {
+      if (!elf32_avr_build_stubs (&link_info))
+       einfo ("%X%P: can not build stubs: %E\n");
+    }
 }
 
 
@@ -266,5 +261,5 @@ PARSE_AND_LIST_ARGS_CASES='
 # Put these extra avr-elf routines in ld_${EMULATION_NAME}_emulation
 #
 LDEMUL_BEFORE_ALLOCATION=avr_elf_${EMULATION_NAME}_before_allocation
-LDEMUL_FINISH=avr_elf_finish
+LDEMUL_AFTER_ALLOCATION=avr_elf_after_allocation
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=avr_elf_create_output_section_statements
index d286bb837c69982d658665a5c6733cd541c751f8..0f191351de35b9605088b3f6d1cd2504cc71b0d0 100644 (file)
@@ -31,21 +31,8 @@ gld${EMULATION_NAME}_map_segments (bfd_boolean need_layout)
 
   do
     {
-      if (need_layout)
-       {
-         lang_reset_memory_regions ();
-
-         /* Resize the sections.  */
-         lang_size_sections (NULL, TRUE);
-
-         /* Redo special stuff.  */
-         ldemul_after_allocation ();
-
-         /* Do the assignments again.  */
-         lang_do_assignments ();
-
-         need_layout = FALSE;
-       }
+      lang_relax_sections (need_layout);
+      need_layout = FALSE;
 
       if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour
          && !link_info.relocatable)
index 2d7a88d3bfaf16d119a6dff0e6ea202ede0db662..cd7f2d4e38d22ed714f69c5e0bf522d4a0633cf1 100644 (file)
@@ -62,10 +62,9 @@ fragment <<EOF
 static void gld${EMULATION_NAME}_before_parse (void);
 static void gld${EMULATION_NAME}_after_open (void);
 static void gld${EMULATION_NAME}_before_allocation (void);
+static void gld${EMULATION_NAME}_after_allocation (void);
 static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
   (asection *, const char *, int);
-static void gld${EMULATION_NAME}_finish (void);
-
 EOF
 
 if [ "x${USE_LIBPATH}" = xyes ] ; then
@@ -1830,17 +1829,15 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
 EOF
 fi
 
-if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then
+if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
 fragment <<EOF
 
 static void
-gld${EMULATION_NAME}_finish (void)
+gld${EMULATION_NAME}_after_allocation (void)
 {
   bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
                                                  &link_info);
-
   gld${EMULATION_NAME}_map_segments (need_layout);
-  finish_default ();
 }
 EOF
 fi
@@ -2327,14 +2324,14 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   ${LDEMUL_HLL-hll_default},
   ${LDEMUL_AFTER_PARSE-after_parse_default},
   ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
-  ${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
+  ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
   ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
   ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
   ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
   ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
   "${EMULATION_NAME}",
   "${OUTPUT_FORMAT}",
-  ${LDEMUL_FINISH-gld${EMULATION_NAME}_finish},
+  ${LDEMUL_FINISH-finish_default},
   ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
   ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
   ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
index e6e8841f0d3ae0c0f01df2e145e9ae4a99f1f5fb..cfb8f11cfbbb9023dbb1aeb55d1735b145357a55 100644 (file)
@@ -28,13 +28,6 @@ EOF
 source_em ${srcdir}/emultempl/elf-generic.em
 fragment <<EOF
 
-static void
-gld${EMULATION_NAME}_finish (void)
-{
-  gld${EMULATION_NAME}_map_segments (FALSE);
-  finish_default ();
-}
-
 static void
 gld${EMULATION_NAME}_after_open (void)
 {
@@ -53,8 +46,14 @@ gld${EMULATION_NAME}_after_open (void)
              elf_group_id (sec) = syms[sec_data->this_hdr.sh_info - 1];
            }
 }
+
+static void
+gld${EMULATION_NAME}_after_allocation (void)
+{
+  gld${EMULATION_NAME}_map_segments (FALSE);
+}
 EOF
 # Put these extra routines in ld_${EMULATION_NAME}_emulation
 #
-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
 LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open
+LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
index 6186cb97213e36e68fe0bc79031d1472d3a61642..a38fc840d5080ff9057e98e8611023707099b6fa 100644 (file)
@@ -237,14 +237,13 @@ build_section_lists (lang_statement_union_type *statement)
 }
 
 
-/* Final emulation specific call.  For the PA we use this opportunity
-   to build linker stubs.  */
+/* For the PA we use this opportunity to size and build linker stubs.  */
 
 static void
-gld${EMULATION_NAME}_finish (void)
+gld${EMULATION_NAME}_after_allocation (void)
 {
-  /* bfd_elf_discard_info just plays with debugging sections,
-     ie. doesn't affect any code, so we can delay resizing the
+  /* bfd_elf_discard_info just plays with data and debugging sections,
+     ie. doesn't affect code size, 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 (link_info.output_bfd, &link_info))
@@ -301,8 +300,6 @@ gld${EMULATION_NAME}_finish (void)
            einfo ("%X%P: can not build stubs: %E\n");
        }
     }
-
-  finish_default ();
 }
 
 
@@ -376,5 +373,5 @@ PARSE_AND_LIST_ARGS_CASES='
 # Put these extra hppaelf routines in ld_${EMULATION_NAME}_emulation
 #
 LDEMUL_AFTER_PARSE=hppaelf_after_parse
-LDEMUL_FINISH=gld${EMULATION_NAME}_finish
+LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=hppaelf_create_output_section_statements
index 0c1305b62d18fae8d44b17a9efc3f8bb9dc6ed93..01d2d83aa88dd1643df8a742fd5ea4468581ade9 100644 (file)
@@ -284,11 +284,10 @@ m68hc11elf_add_stub_section (const char *stub_sec_name,
   return NULL;
 }
 
-/* Final emulation specific call.  For the 68HC12 we use this opportunity
-   to build linker stubs.  */
+/* For the 68HC12 we use this opportunity to build linker stubs.  */
 
 static void
-m68hc11elf_finish (void)
+m68hc11elf_after_allocation (void)
 {
   /* Now build the linker stubs.  */
   if (stub_file->the_bfd->sections != NULL)
@@ -308,7 +307,7 @@ m68hc11elf_finish (void)
        einfo ("%X%P: can not build stubs: %E\n");
     }
 
-  gld${EMULATION_NAME}_finish ();
+  gld${EMULATION_NAME}_after_allocation ();
 }
 
 
@@ -370,5 +369,5 @@ PARSE_AND_LIST_ARGS_CASES='
 # Put these extra m68hc11elf routines in ld_${EMULATION_NAME}_emulation
 #
 LDEMUL_BEFORE_ALLOCATION=m68hc11_elf_${EMULATION_NAME}_before_allocation
-LDEMUL_FINISH=m68hc11elf_finish
+LDEMUL_AFTER_ALLOCATION=m68hc11elf_after_allocation
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=m68hc11elf_create_output_section_statements
index 441b4897fc8868116cdcd5715ee2d2ba5d2e9e46..38d8ec5fa168f1c5256667f8091fbfee6df6b5ad 100644 (file)
@@ -143,7 +143,7 @@ static void
 m68k_elf_after_allocation (void)
 {
   /* Call the standard elf routine.  */
-  after_allocation_default ();
+  gld${EMULATION_NAME}_after_allocation ();
 
 #ifdef SUPPORT_EMBEDDED_RELOCS
   if (command_line.embedded_relocs
index 909c3c46dd2d7f53c98b61044a05a39f5edab47a..be4a279b7dd62a5083a939a9844dbefda1869913 100644 (file)
@@ -56,11 +56,11 @@ mmix_before_allocation (void)
 static void
 mmix_after_allocation (void)
 {
-  asection *sec
-    = bfd_get_section_by_name (link_info.output_bfd,
-                              MMIX_REG_CONTENTS_SECTION_NAME);
+  asection *sec;
   bfd_signed_vma regvma;
 
+  gld${EMULATION_NAME}_after_allocation ();
+
   /* If there's no register section, we don't need to do anything.  On the
      other hand, if there's a non-standard linker-script without a mapping
      from MMIX_LD_ALLOCATED_REG_CONTENTS_SECTION_NAME when that section is
@@ -72,6 +72,8 @@ mmix_after_allocation (void)
      that's expected when you play tricks with linker scripts.  The
      "NOCROSSREFS 2" test does not run the output so it does not matter
      there.  */
+  sec = bfd_get_section_by_name (link_info.output_bfd,
+                                MMIX_REG_CONTENTS_SECTION_NAME);
   if (sec == NULL)
     sec
       = bfd_get_section_by_name (link_info.output_bfd,
index f5ba6dd974c427ab52304e467ef7e328d4e4348a..9568be328b088818f7da772dff56cd5463d8e522 100644 (file)
@@ -35,6 +35,8 @@ fragment <<EOF
    get a weird testcase right; ld-mmix/bpo-22, forcing ELF to be
    output from the mmo emulation: -m mmo --oformat elf64-mmix!  */
 #include "elf-bfd.h"
+
+static void gld${EMULATION_NAME}_after_allocation (void);
 EOF
 
 source_em ${srcdir}/emultempl/elf-generic.em
@@ -119,11 +121,10 @@ mmo_wipe_sec_reloc_flag (bfd *abfd, asection *sec, void *ptr ATTRIBUTE_UNUSED)
 /* Iterate with bfd_map_over_sections over mmo_wipe_sec_reloc_flag... */
 
 static void
-mmo_finish (void)
+gld${EMULATION_NAME}_after_allocation (void)
 {
   bfd_map_over_sections (link_info.output_bfd, mmo_wipe_sec_reloc_flag, NULL);
   gld${EMULATION_NAME}_map_segments (FALSE);
-  finish_default ();
 }
 \f
 /* To get on-demand global register allocation right, we need to parse the
@@ -154,5 +155,4 @@ mmo_after_open (void)
 EOF
 
 LDEMUL_PLACE_ORPHAN=mmo_place_orphan
-LDEMUL_FINISH=mmo_finish
 LDEMUL_AFTER_OPEN=mmo_after_open
index eff8dff4a5635586551a556ee2d438db9911942b..1518dac15fd6f51f248cc91f47fe3ff248abcafc 100644 (file)
@@ -258,18 +258,12 @@ ppc_layout_sections_again (void)
      to recalculate all the section offsets.  This may mean we need to
      add even more stubs.  */
   gld${EMULATION_NAME}_map_segments (TRUE);
-  need_laying_out = -1;
-}
-
 
-/* Call the back-end function to set TOC base after we have placed all
-   the sections.  */
-static void
-gld${EMULATION_NAME}_after_allocation (void)
-{
   if (!link_info.relocatable)
     _bfd_set_gp_value (link_info.output_bfd,
                       ppc64_elf_toc (link_info.output_bfd));
+
+  need_laying_out = -1;
 }
 
 
@@ -307,18 +301,13 @@ build_section_lists (lang_statement_union_type *statement)
 }
 
 
-/* Final emulation specific call.  */
-
+/* Call the back-end function to set TOC base after we have placed all
+   the sections.  */
 static void
-gld${EMULATION_NAME}_finish (void)
+gld${EMULATION_NAME}_after_allocation (void)
 {
-  /* e_entry on PowerPC64 points to the function descriptor for
-     _start.  If _start is missing, default to the first function
-     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
+  /* bfd_elf_discard_info just plays with data and debugging sections,
+     ie. doesn't affect code size, 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 (link_info.output_bfd, &link_info))
@@ -354,7 +343,25 @@ gld${EMULATION_NAME}_finish (void)
     }
 
   if (need_laying_out != -1)
-    gld${EMULATION_NAME}_map_segments (need_laying_out);
+    {
+      gld${EMULATION_NAME}_map_segments (need_laying_out);
+
+      if (!link_info.relocatable)
+       _bfd_set_gp_value (link_info.output_bfd,
+                          ppc64_elf_toc (link_info.output_bfd));
+    }
+}
+
+
+/* Final emulation specific call.  */
+
+static void
+gld${EMULATION_NAME}_finish (void)
+{
+  /* e_entry on PowerPC64 points to the function descriptor for
+     _start.  If _start is missing, default to the first function
+     descriptor in the .opd section.  */
+  entry_section = ".opd";
 
   if (link_info.relocatable)
     {
index 5c588ce2c128d380cf07c85eab628a4c7bce31de..a2b82f92bed9286b834373146e54feb00bf97a13 100644 (file)
@@ -244,12 +244,12 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
   bfd_vma cranges_growth = 0;
   asection *osec;
   bfd_byte *crangesp;
+  asection *cranges;
 
-  asection *cranges = bfd_get_section_by_name (link_info.output_bfd,
-                                              SH64_CRANGES_SECTION_NAME);
+  gld${EMULATION_NAME}_after_allocation ();
 
-  /* If this ever starts doing something, we will pick it up.  */
-  after_allocation_default ();
+  cranges = bfd_get_section_by_name (link_info.output_bfd,
+                                    SH64_CRANGES_SECTION_NAME);
 
   /* If there is no .cranges section, it is because it was seen earlier on
      that none was needed.  Otherwise it must have been created then, or
@@ -376,11 +376,6 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
       }
     }
 
-  /* ldemul_after_allocation may be called twice.  First directly from
-     lang_process, and the second time when lang_process calls ldemul_finish,
-     which calls gld${EMULATION_NAME}_finish, e.g. gldshelf32_finish, which
-     is defined in emultempl/elf32.em and calls ldemul_after_allocation,
-     if bfd_elf_discard_info returned true.  */
   if (cranges->contents != NULL)
     free (cranges->contents);
 
index 1f4fbec66a10a11899bfc15c5d85d329016dfba1..2ea760a7f0b3033ef5b3ffe0451a81bea5d98d57 100644 (file)
@@ -406,12 +406,6 @@ spu_elf_relink (void)
 static void
 gld${EMULATION_NAME}_finish (void)
 {
-  int need_laying_out;
-
-  need_laying_out = bfd_elf_discard_info (link_info.output_bfd, &link_info);
-
-  gld${EMULATION_NAME}_map_segments (need_laying_out);
-
   if (is_spu_target ())
     {
       if (params.local_store_lo < params.local_store_hi)
index 826129d0a150fec121a64da8e0c6fe7d8213434c..3436c6100c6007498327ec70d994b7048fc8f7e3 100644 (file)
@@ -1,6 +1,6 @@
 /* ldemul.c -- clearing house for ld emulation states
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2005, 2007, 2008
+   2001, 2002, 2003, 2005, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
@@ -205,6 +205,7 @@ after_open_default (void)
 void
 after_allocation_default (void)
 {
+  lang_relax_sections (FALSE);
 }
 
 void
index bc03374a6dc797bef01dcca3f30466b41199370e..a1bd2e3fe9365456ae79a24f87ce75bb79ea2c54 100644 (file)
@@ -6159,35 +6159,58 @@ lang_find_relro_sections (void)
 
 /* Relax all sections until bfd_relax_section gives up.  */
 
-static void
-relax_sections (void)
+void
+lang_relax_sections (bfd_boolean need_layout)
 {
-  /* Keep relaxing until bfd_relax_section gives up.  */
-  bfd_boolean relax_again;
-
-  link_info.relax_trip = -1;
-  do
+  if (command_line.relax)
     {
-      relax_again = FALSE;
-      link_info.relax_trip++;
+      /* We may need more than one relaxation pass.  */
+      int i = link_info.relax_pass;
 
-      /* Note: pe-dll.c does something like this also.  If you find
-        you need to change this code, you probably need to change
-        pe-dll.c also.  DJ  */
+      /* The backend can use it to determine the current pass.  */
+      link_info.relax_pass = 0;
 
-      /* Do all the assignments with our current guesses as to
-        section sizes.  */
-      lang_do_assignments ();
+      while (i--)
+       {
+         /* Keep relaxing until bfd_relax_section gives up.  */
+         bfd_boolean relax_again;
 
-      /* We must do this after lang_do_assignments, because it uses
-        size.  */
-      lang_reset_memory_regions ();
+         link_info.relax_trip = -1;
+         do
+           {
+             link_info.relax_trip++;
+
+             /* Note: pe-dll.c does something like this also.  If you find
+                you need to change this code, you probably need to change
+                pe-dll.c also.  DJ  */
+
+             /* Do all the assignments with our current guesses as to
+                section sizes.  */
+             lang_do_assignments ();
+
+             /* We must do this after lang_do_assignments, because it uses
+                size.  */
+             lang_reset_memory_regions ();
+
+             /* Perform another relax pass - this time we know where the
+                globals are, so can make a better guess.  */
+             relax_again = FALSE;
+             lang_size_sections (&relax_again, FALSE);
+           }
+         while (relax_again);
+
+         link_info.relax_pass++;
+       }
+      need_layout = TRUE;
+    }
 
-      /* Perform another relax pass - this time we know where the
-        globals are, so can make a better guess.  */
-      lang_size_sections (&relax_again, FALSE);
+  if (need_layout)
+    {
+      /* Final extra sizing to report errors.  */
+      lang_do_assignments ();
+      lang_reset_memory_regions ();
+      lang_size_sections (NULL, TRUE);
     }
-  while (relax_again);
 }
 
 void
@@ -6293,29 +6316,8 @@ lang_process (void)
   /* Size up the sections.  */
   lang_size_sections (NULL, !command_line.relax);
 
-  /* Now run around and relax if we can.  */
-  if (command_line.relax)
-    {
-      /* We may need more than one relaxation pass.  */
-      int i = link_info.relax_pass;
-
-      /* The backend can use it to determine the current pass.  */
-      link_info.relax_pass = 0;
-
-      while (i--)
-       {
-         relax_sections ();
-         link_info.relax_pass++;
-       }
-
-      /* Final extra sizing to report errors.  */
-      lang_do_assignments ();
-      lang_reset_memory_regions ();
-      lang_size_sections (NULL, TRUE);
-    }
-
   /* See if anything special should be done now we know how big
-     everything is.  */
+     everything is.  This is where relaxation is done.  */
   ldemul_after_allocation ();
 
   /* Fix any .startof. or .sizeof. symbols.  */
index f9a11433539db3049a2e830deb1607fff25b47e1..4629883bcc4bec88422000d8445a1cb2014fc7fd 100644 (file)
@@ -483,6 +483,8 @@ extern lang_output_section_statement_type *lang_enter_output_section_statement
    etree_type *, int);
 extern void lang_final
   (void);
+extern void lang_relax_sections
+  (bfd_boolean);
 extern void lang_process
   (void);
 extern void lang_section_start