bfd/
[deliverable/binutils-gdb.git] / ld / emultempl / sh64elf.em
index 066cab86d8b1c4b74e013b91af412a80a77f3c5e..0682f5ca9809e2001a9972e72ef9d13b56d66d91 100644 (file)
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+#   Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 #
 # This file is part of GLD, the Gnu Linker.
 #
@@ -33,9 +33,6 @@ cat >>e${EMULATION_NAME}.c <<EOF
 #include "elf/sh.h"
 #include "elf32-sh64.h"
 
-static void sh64_elf_${EMULATION_NAME}_before_allocation PARAMS ((void));
-static void sh64_elf_${EMULATION_NAME}_after_allocation PARAMS ((void));
-
 /* Check if we need a .cranges section and create it if it's not in any
    input file.  It might seem better to always create it and if unneeded,
    discard it, but I don't find a simple way to discard it totally from
@@ -47,7 +44,7 @@ static void sh64_elf_${EMULATION_NAME}_after_allocation PARAMS ((void));
    they will be linked.  */
 
 static void
-sh64_elf_${EMULATION_NAME}_before_allocation ()
+sh64_elf_${EMULATION_NAME}_before_allocation (void)
 {
   asection *cranges;
   asection *osec;
@@ -155,7 +152,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation ()
                 isec = isec->next)
              {
                if (isec->output_section == osec
-                   && isec->_raw_size != 0
+                   && isec->size != 0
                    && (bfd_get_section_flags (isec->owner, isec)
                        & SEC_EXCLUDE) == 0)
                  {
@@ -182,7 +179,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation ()
                 isec = isec->next)
              {
                if (isec->output_section == osec
-                   && isec->_raw_size != 0
+                   && isec->size != 0
                    && (bfd_get_section_flags (isec->owner, isec)
                        & SEC_EXCLUDE) == 0)
                  {
@@ -240,7 +237,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation ()
 /* Size up and extend the .cranges section, merging generated entries.  */
 
 static void
-sh64_elf_${EMULATION_NAME}_after_allocation ()
+sh64_elf_${EMULATION_NAME}_after_allocation (void)
 {
   bfd_vma new_cranges = 0;
   bfd_vma cranges_growth = 0;
@@ -286,7 +283,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                 isec = isec->next)
              {
                if (isec->output_section == osec
-                   && isec->_raw_size != 0
+                   && isec->size != 0
                    && (bfd_get_section_flags (isec->owner, isec)
                        & SEC_EXCLUDE) == 0)
                  {
@@ -313,7 +310,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                 isec = isec->next)
              {
                if (isec->output_section == osec
-                   && isec->_raw_size != 0
+                   && isec->size != 0
                    && (bfd_get_section_flags (isec->owner, isec)
                        & SEC_EXCLUDE) == 0)
                  {
@@ -366,7 +363,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                 isec = isec->next)
              {
                if (isec->output_section == osec
-                   && isec->_raw_size != 0
+                   && isec->size != 0
                    && (bfd_get_section_flags (isec->owner, isec)
                        & SEC_EXCLUDE) == 0
                    && ((elf_section_data (isec)->this_hdr.sh_flags
@@ -378,14 +375,20 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
       }
     }
 
-  BFD_ASSERT (cranges->contents == NULL);
+  /* 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);
+
   BFD_ASSERT (sh64_elf_section_data (cranges)->sh64_info != NULL);
 
   /* Make sure we have .cranges in memory even if there were only
      assembler-generated .cranges.  */
   cranges_growth = new_cranges * SH64_CRANGE_SIZE;
-  cranges->contents
-    = (bfd_byte *) xcalloc (cranges->_raw_size + cranges_growth, 1);
+  cranges->contents = xcalloc (cranges->size + cranges_growth, 1);
   bfd_set_section_flags (cranges->owner, cranges,
                         bfd_get_section_flags (cranges->owner, cranges)
                         | SEC_IN_MEMORY);
@@ -400,7 +403,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
       return;
     }
 
-  crangesp = cranges->contents + cranges->_raw_size;
+  crangesp = cranges->contents + cranges->size;
 
   /* Now pass over the sections again, and make reloc orders for the new
      .cranges entries.  Constants are set as we go.  */
@@ -434,7 +437,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                   as containing mixed data, thus already having .cranges
                   entries.  */
                if (isec->output_section == osec
-                   && isec->_raw_size != 0
+                   && isec->size != 0
                    && (bfd_get_section_flags (isec->owner, isec)
                        & SEC_EXCLUDE) == 0
                    && ((elf_section_data (isec)->this_hdr.sh_flags
@@ -455,9 +458,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                    else
                      cr_type = CRT_SH5_ISA16;
 
-                   cr_size
-                     = (isec->_cooked_size
-                        ? isec->_cooked_size : isec->_raw_size);
+                   cr_size = isec->size;
 
                    /* Sections can be empty, like .text in a file that
                       only contains other sections.  Ranges shouldn't be
@@ -483,9 +484,9 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                        continue;
                      }
 
-                   /* If we emit relocateable contents, we need a
+                   /* If we emit relocatable contents, we need a
                       relocation for the start address.  */
-                   if (link_info.relocateable || link_info.emitrelocations)
+                   if (link_info.relocatable || link_info.emitrelocations)
                      {
                        /* FIXME: We could perhaps use lang_add_reloc and
                           friends here, but I'm not really sure that
@@ -507,8 +508,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                             - cranges->contents);
                        cr_addr_order->size = 4;
                        cr_addr_order->u.reloc.p
-                         = ((struct bfd_link_order_reloc *)
-                            xmalloc (sizeof (struct bfd_link_order_reloc)));
+                         = xmalloc (sizeof (struct bfd_link_order_reloc));
 
                        cr_addr_order->u.reloc.p->reloc = BFD_RELOC_32;
                        cr_addr_order->u.reloc.p->u.section = osec;
@@ -540,7 +540,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
                    bfd_put_32 (output_bfd, cr_size,
                                crangesp + SH64_CRANGE_CR_SIZE_OFFSET);
 
-                   bfd_put_16 (output_bfd, (bfd_vma) cr_type,
+                   bfd_put_16 (output_bfd, cr_type,
                                crangesp + SH64_CRANGE_CR_TYPE_OFFSET);
 
                    last_cr_type = cr_type;
@@ -555,14 +555,13 @@ sh64_elf_${EMULATION_NAME}_after_allocation ()
     }
 
   /* The .cranges section will have this size, no larger or smaller.
-     Since relocs (if relocateable linking) will be emitted into the
+     Since relocs (if relocatable linking) will be emitted into the
      "extended" size, we must set the raw size to the total.  We have to
      keep track of the number of new .cranges entries.
 
      Sorting before writing is done by sh64_elf_final_write_processing.  */
 
-  cranges->_cooked_size = crangesp - cranges->contents;
   sh64_elf_section_data (cranges)->sh64_info->cranges_growth
-    = cranges->_cooked_size - cranges->_raw_size;
-  cranges->_raw_size = cranges->_cooked_size;
+    = crangesp - cranges->contents - cranges->size;
+  cranges->size = crangesp - cranges->contents;
 }
This page took 0.025411 seconds and 4 git commands to generate.