ld: Create test object files based on source file name
[deliverable/binutils-gdb.git] / ld / emultempl / sh64elf.em
index 83bfe676bb1de03dbec43912ebd39e2ecbb8e239..0d42510115513bf167687de2a0e15c639eba66f7 100644 (file)
@@ -1,11 +1,11 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+#   Copyright (C) 2000-2016 Free Software Foundation, Inc.
 #
-# This file is part of GLD, the Gnu Linker.
+# This file is part of the GNU Binutils.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
@@ -15,7 +15,8 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
 #
 
 # This file is sourced from elf32.em, and defines extra sh64
 LDEMUL_AFTER_ALLOCATION=sh64_elf_${EMULATION_NAME}_after_allocation
 LDEMUL_BEFORE_ALLOCATION=sh64_elf_${EMULATION_NAME}_before_allocation
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include "libiberty.h"
-#include "libbfd.h"
 #include "elf-bfd.h"
 #include "elf/sh.h"
 #include "elf32-sh64.h"
@@ -52,11 +52,12 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
   /* Call main function; we're just extending it.  */
   gld${EMULATION_NAME}_before_allocation ();
 
-  cranges = bfd_get_section_by_name (output_bfd, SH64_CRANGES_SECTION_NAME);
+  cranges = bfd_get_section_by_name (link_info.output_bfd,
+                                    SH64_CRANGES_SECTION_NAME);
 
   if (cranges != NULL)
     {
-      if (command_line.relax)
+      if (RELAXATION_ENABLED)
        {
          /* FIXME: Look through incoming sections with .cranges
             descriptors, build up some kind of descriptors that the
@@ -79,7 +80,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
              }
          }
 
-         command_line.relax = FALSE;
+         DISABLE_RELAXATION;
        }
 
       /* We wouldn't need to do anything when there's already a .cranges
@@ -88,13 +89,14 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
         .cranges section.  */
     }
 
-  if (command_line.relax)
+  if (RELAXATION_ENABLED)
     {
       LANG_FOR_EACH_INPUT_STATEMENT (f)
        {
          if (bfd_get_flavour (f->the_bfd) == bfd_target_elf_flavour)
            {
              asection *isec;
+
              for (isec = f->the_bfd->sections;
                   isec != NULL;
                   isec = isec->next)
@@ -104,7 +106,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
                    {
                      einfo (_("%P: Sorry, turning off relaxing: SHmedia sections present.\n"));
                      einfo ("  %I\n", f);
-                     command_line.relax = FALSE;
+                     DISABLE_RELAXATION;
                      goto done_scanning_shmedia_sections;
                    }
                }
@@ -116,7 +118,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
   /* For each non-empty input section in each output section, check if it
      has the same SH64-specific flags.  If some input section differs, we
      need a .cranges section.  */
-  for (osec = output_bfd->sections;
+  for (osec = link_info.output_bfd->sections;
        osec != NULL;
        osec = osec->next)
     {
@@ -124,13 +126,13 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
       bfd_vma oflags_isa = 0;
       bfd_vma iflags_isa = 0;
 
-      if (bfd_get_flavour (output_bfd) != bfd_target_elf_flavour)
+      if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
        einfo (_("%FError: non-ELF output formats are not supported by this target's linker.\n"));
 
       sh64_sec_data = sh64_elf_section_data (osec)->sh64_info;
 
       /* Omit excluded or garbage-collected sections.  */
-      if (bfd_get_section_flags (output_bfd, osec) & SEC_EXCLUDE)
+      if (bfd_get_section_flags (link_info.output_bfd, osec) & SEC_EXCLUDE)
        continue;
 
       /* Make sure we have the target section data initialized.  */
@@ -152,7 +154,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
                 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)
                  {
@@ -179,7 +181,7 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
                 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)
                  {
@@ -200,15 +202,13 @@ sh64_elf_${EMULATION_NAME}_before_allocation (void)
                               sh64_elf_section_data; no need to set it
                               specifically here.  */
                            cranges
-                             = bfd_make_section (output_bfd,
-                                                 SH64_CRANGES_SECTION_NAME);
-                           if (cranges == NULL
-                               || !bfd_set_section_flags (output_bfd,
-                                                          cranges,
-                                                          SEC_LINKER_CREATED
-                                                          | SEC_KEEP
-                                                          | SEC_HAS_CONTENTS
-                                                          | SEC_DEBUGGING))
+                             = bfd_make_section_with_flags (link_info.output_bfd,
+                                                            SH64_CRANGES_SECTION_NAME,
+                                                            SEC_LINKER_CREATED
+                                                            | SEC_KEEP
+                                                            | SEC_HAS_CONTENTS
+                                                            | SEC_DEBUGGING);
+                           if (cranges == NULL)
                              einfo
                                (_("%P%E%F: Can't make .cranges section\n"));
                          }
@@ -243,12 +243,15 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
   bfd_vma cranges_growth = 0;
   asection *osec;
   bfd_byte *crangesp;
+  asection *cranges;
+
+  gld${EMULATION_NAME}_after_allocation ();
 
-  asection *cranges
-    = bfd_get_section_by_name (output_bfd, SH64_CRANGES_SECTION_NAME);
+  /* Needed, since we create link_orders here.  */
+  lang_clear_os_map ();
 
-  /* 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
@@ -260,7 +263,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
      first non-discarded section.  For each input section in osec, we
      check if it has the same flags.  If it does not, we set flags to mark
      a mixed section (and exit the loop early).  */
-  for (osec = output_bfd->sections;
+  for (osec = link_info.output_bfd->sections;
        osec != NULL;
        osec = osec->next)
     {
@@ -268,7 +271,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
       bfd_boolean need_check_cranges = FALSE;
 
       /* Omit excluded or garbage-collected sections.  */
-      if (bfd_get_section_flags (output_bfd, osec) & SEC_EXCLUDE)
+      if (bfd_get_section_flags (link_info.output_bfd, osec) & SEC_EXCLUDE)
        continue;
 
       /* First find an input section so we have flags to compare with; the
@@ -283,7 +286,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                 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)
                  {
@@ -310,7 +313,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                 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)
                  {
@@ -328,7 +331,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                      {
                        oflags_isa = SHF_SH5_ISA32_MIXED;
 
-                       BFD_ASSERT (sh64_elf_section_data (osec)->sh64_info);
+                       ASSERT (sh64_elf_section_data (osec)->sh64_info);
 
                        sh64_elf_section_data (osec)->sh64_info->contents_flags
                          = SHF_SH5_ISA32_MIXED;
@@ -363,7 +366,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                 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
@@ -375,20 +378,15 @@ 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);
 
-  BFD_ASSERT (sh64_elf_section_data (cranges)->sh64_info != NULL);
+  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 = 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);
@@ -403,11 +401,11 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
       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.  */
-  for (osec = output_bfd->sections;
+  for (osec = link_info.output_bfd->sections;
        osec != NULL;
        osec = osec->next)
     {
@@ -418,7 +416,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
 
       /* Omit excluded or garbage-collected sections, and output sections
         which were not marked as needing further processing.  */
-      if ((bfd_get_section_flags (output_bfd, osec) & SEC_EXCLUDE) != 0
+      if ((bfd_get_section_flags (link_info.output_bfd, osec) & SEC_EXCLUDE) != 0
          || (sh64_elf_section_data (osec)->sh64_info->contents_flags
              != SHF_SH5_ISA32_MIXED))
        continue;
@@ -437,7 +435,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                   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
@@ -458,9 +456,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                    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
@@ -478,7 +474,7 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                            == osec->vma + isec->output_offset))
                      {
                        last_cr_size += cr_size;
-                       bfd_put_32 (output_bfd, last_cr_size,
+                       bfd_put_32 (link_info.output_bfd, last_cr_size,
                                    crangesp - SH64_CRANGE_SIZE
                                    + SH64_CRANGE_CR_SIZE_OFFSET);
 
@@ -488,14 +484,15 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
 
                    /* If we emit relocatable contents, we need a
                       relocation for the start address.  */
-                   if (link_info.relocatable || link_info.emitrelocations)
+                   if (bfd_link_relocatable (&link_info)
+                       || link_info.emitrelocations)
                      {
                        /* FIXME: We could perhaps use lang_add_reloc and
                           friends here, but I'm not really sure that
                           would leave us free to do some optimizations
                           later.  */
                        cr_addr_order
-                         = bfd_new_link_order (output_bfd, cranges);
+                         = bfd_new_link_order (link_info.output_bfd, cranges);
 
                        if (cr_addr_order == NULL)
                          {
@@ -519,19 +516,12 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                           "partial inplace" REL-like relocation for this,
                           we put the addend in the contents and specify 0
                           for the reloc.  */
-                       bfd_put_32 (output_bfd, isec->output_offset,
+                       bfd_put_32 (link_info.output_bfd, isec->output_offset,
                                    crangesp + SH64_CRANGE_CR_ADDR_OFFSET);
                        cr_addr_order->u.reloc.p->addend = 0;
-
-                       /* We must update the number of relocations here,
-                          since the elf linker does not take link orders
-                          into account when setting header sizes.  The
-                          actual relocation orders are however executed
-                          correctly.  */
-                       elf_section_data(cranges)->rel_count++;
                      }
                    else
-                     bfd_put_32 (output_bfd,
+                     bfd_put_32 (link_info.output_bfd,
                                  osec->vma + isec->output_offset,
                                  crangesp + SH64_CRANGE_CR_ADDR_OFFSET);
 
@@ -539,10 +529,10 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
                       it, but we would have to have a symbol for the size
                       of the _input_ section and there's no way to
                       generate that.  */
-                   bfd_put_32 (output_bfd, cr_size,
+                   bfd_put_32 (link_info.output_bfd, cr_size,
                                crangesp + SH64_CRANGE_CR_SIZE_OFFSET);
 
-                   bfd_put_16 (output_bfd, cr_type,
+                   bfd_put_16 (link_info.output_bfd, cr_type,
                                crangesp + SH64_CRANGE_CR_TYPE_OFFSET);
 
                    last_cr_type = cr_type;
@@ -563,8 +553,11 @@ sh64_elf_${EMULATION_NAME}_after_allocation (void)
 
      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;
+  cranges->rawsize = cranges->size;
 }
+EOF
+
+
This page took 0.031464 seconds and 4 git commands to generate.