Add support for non-contiguous memory regions
[deliverable/binutils-gdb.git] / ld / emultempl / xtensaelf.em
index 0ae0d1c0d70b3ae1a95e964af3f33c463b7a88a4..74bd11c6b00092ce08e0f626b358c5928bf60c7d 100644 (file)
@@ -1,6 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009
-#   Free Software Foundation, Inc.
+#   Copyright (C) 2003-2020 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
 # MA 02110-1301, USA.
 #
 
-# This file is sourced from elf32.em, and defines extra xtensa-elf
+# This file is sourced from elf.em, and defines extra xtensa-elf
 # specific routines.
 #
 fragment <<EOF
 
 #include <xtensa-config.h>
 #include "../bfd/elf-bfd.h"
-#include "../bfd/libbfd.h"
 #include "elf/xtensa.h"
 #include "bfd.h"
 
@@ -98,7 +96,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
   bfd_byte *insn_contents = NULL;
   unsigned entry_count;
   unsigned entry;
-  Elf_Internal_Shdr *symtab_hdr;
+  Elf_Internal_Shdr *rel_hdr;
   Elf_Internal_Rela *internal_relocs = NULL;
   unsigned reloc_count;
 
@@ -117,12 +115,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
 
   if (insn_sec->size != 0)
     {
-      insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size);
-      if (insn_contents == NULL)
-       {
-         *error_message = _("out of memory");
-         goto cleanup;
-       }
+      insn_contents = (bfd_byte *) xmalloc (insn_sec->size);
       if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
                                      (file_ptr) 0, insn_sec->size))
        {
@@ -134,9 +127,9 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
   /* Create a property table section for it.  */
   prop_sec_name = strdup (prop_sec_name);
   prop_sec = bfd_make_section_with_flags
-    (abfd, prop_sec_name, bfd_get_section_flags (abfd, insn_sec));
+    (abfd, prop_sec_name, bfd_section_flags (insn_sec));
   if (prop_sec == NULL
-      || ! bfd_set_section_alignment (abfd, prop_sec, 2))
+      || !bfd_set_section_alignment (prop_sec, 2))
     {
       *error_message = _("could not create new section");
       goto cleanup;
@@ -148,10 +141,9 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
 
   /* The entry size and size must be set to allow the linker to compute
      the number of relocations since it does not use reloc_count.  */
-  elf_section_data (prop_sec)->rel_hdr.sh_entsize =
-    sizeof (Elf32_External_Rela);
-  elf_section_data (prop_sec)->rel_hdr.sh_size =
-    elf_section_data (insn_sec)->rel_hdr.sh_size;
+  rel_hdr = _bfd_elf_single_rel_hdr (prop_sec);
+  rel_hdr->sh_entsize = sizeof (Elf32_External_Rela);
+  rel_hdr->sh_size = _bfd_elf_single_rel_hdr (insn_sec)->sh_size;
 
   if (prop_contents == NULL && prop_sec->size != 0)
     {
@@ -206,7 +198,6 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
   if (internal_relocs)
     {
       unsigned i;
-      symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
 
       for (i = 0; i < reloc_count; i++)
        {
@@ -256,7 +247,7 @@ replace_instruction_table_sections (bfd *abfd, asection *sec)
   char *owned_prop_sec_name = NULL;
   const char *sec_name;
 
-  sec_name = bfd_get_section_name (abfd, sec);
+  sec_name = bfd_section_name (sec);
   if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
     {
       insn_sec_name = INSN_SEC_BASE_NAME;
@@ -276,7 +267,7 @@ replace_instruction_table_sections (bfd *abfd, asection *sec)
       if (! replace_insn_sec_with_prop_sec (abfd, insn_sec_name, prop_sec_name,
                                            &message))
        {
-         einfo (_("%P: warning: failed to convert %s table in %B (%s); subsequent disassembly may be incomplete\n"),
+         einfo (_("%P: warning: failed to convert %s table in %pB (%s); subsequent disassembly may be incomplete\n"),
                 insn_sec_name, abfd, message);
        }
     }
@@ -393,7 +384,7 @@ check_xtensa_info (bfd *abfd, asection *info_sec)
 
   data = xmalloc (info_sec->size);
   if (! bfd_get_section_contents (abfd, info_sec, data, 0, info_sec->size))
-    einfo (_("%F%P:%B: cannot read contents of section %A\n"), abfd, info_sec);
+    einfo (_("%F%P: %pB: cannot read contents of section %pA\n"), abfd, info_sec);
 
   if (info_sec->size > 24
       && info_sec->size >= 24 + bfd_get_32 (abfd, data + 4)
@@ -404,11 +395,11 @@ check_xtensa_info (bfd *abfd, asection *info_sec)
                                          &mismatch, &errmsg))
     {
       if (mismatch)
-       einfo (_("%P:%B: warning: incompatible Xtensa configuration (%s)\n"),
+       einfo (_("%P: %pB: warning: incompatible Xtensa configuration (%s)\n"),
               abfd, errmsg);
     }
   else
-    einfo (_("%P:%B: warning: cannot parse .xtensa.info section\n"), abfd);
+    einfo (_("%P: %pB: warning: cannot parse .xtensa.info section\n"), abfd);
 
   free (data);
 }
@@ -459,7 +450,7 @@ elf_xtensa_before_allocation (void)
         cannot go any further if there are any mismatches.  */
       if ((is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
          || (!is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_BIG))
-       einfo (_("%F%P: cross-endian linking for %B not supported\n"),
+       einfo (_("%F%P: cross-endian linking for %pB not supported\n"),
               f->the_bfd);
 
       if (! first_bfd)
@@ -598,59 +589,6 @@ static size_t ld_count_children (lang_statement_union_type *);
 
 extern lang_statement_list_type constructor_list;
 
-/*  Begin verbatim code from ldlang.c:
-    the following are copied from ldlang.c because they are defined
-    there statically.  */
-
-static void
-lang_for_each_statement_worker (void (*func) (lang_statement_union_type *),
-                               lang_statement_union_type *s)
-{
-  for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
-    {
-      func (s);
-
-      switch (s->header.type)
-       {
-       case lang_constructors_statement_enum:
-         lang_for_each_statement_worker (func, constructor_list.head);
-         break;
-       case lang_output_section_statement_enum:
-         lang_for_each_statement_worker
-           (func,
-            s->output_section_statement.children.head);
-         break;
-       case lang_wild_statement_enum:
-         lang_for_each_statement_worker
-           (func,
-            s->wild_statement.children.head);
-         break;
-       case lang_group_statement_enum:
-         lang_for_each_statement_worker (func,
-                                         s->group_statement.children.head);
-         break;
-       case lang_data_statement_enum:
-       case lang_reloc_statement_enum:
-       case lang_object_symbols_statement_enum:
-       case lang_output_statement_enum:
-       case lang_target_statement_enum:
-       case lang_input_section_enum:
-       case lang_input_statement_enum:
-       case lang_assignment_statement_enum:
-       case lang_padding_statement_enum:
-       case lang_address_statement_enum:
-       case lang_fill_statement_enum:
-         break;
-       default:
-         FAIL ();
-         break;
-       }
-    }
-}
-
-/* End of verbatim code from ldlang.c.  */
-
-
 static reloc_deps_section *
 xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
                         asection *sec)
@@ -658,8 +596,12 @@ xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
   /* We have a separate function for this so that
      we could in the future keep a completely independent
      structure that maps a section to its dependence edges.
-     For now, we place these in the sec->userdata field.  */
-  reloc_deps_section *sec_deps = sec->userdata;
+     For now, we place these in the sec->userdata field.
+     This doesn't clash with ldlang.c use of userdata for output
+     sections, and during map output for input sections, since the
+     xtensa use is only for input sections and only extant in
+     before_allocation.  */
+  reloc_deps_section *sec_deps = bfd_section_userdata (sec);
   return sec_deps;
 }
 
@@ -668,7 +610,7 @@ xtensa_set_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
                         asection *sec,
                         reloc_deps_section *deps_section)
 {
-  sec->userdata = deps_section;
+  bfd_set_section_userdata (sec, deps_section);
 }
 
 
@@ -1282,6 +1224,12 @@ ld_build_required_section_dependence (lang_statement_union_type *s)
     {
       lang_statement_union_type *l = iter_stack_current (&stack);
 
+      if (l == NULL && link_info.non_contiguous_regions)
+       {
+         einfo (_("Relaxation not supported with --enable-non-contiguous-regions.\n"));
+         abort();
+       }
+
       if (l->header.type == lang_input_section_enum)
        {
          lang_input_section_type *input;
@@ -1355,10 +1303,10 @@ static bfd_boolean
 is_inconsistent_linkonce_section (asection *sec)
 {
   bfd *abfd = sec->owner;
-  const char *sec_name = bfd_get_section_name (abfd, sec);
+  const char *sec_name = bfd_section_name (sec);
   const char *name;
 
-  if ((bfd_get_section_flags (abfd, sec) & SEC_LINK_ONCE) == 0
+  if ((bfd_section_flags (sec) & SEC_LINK_ONCE) == 0
       || strncmp (sec_name, ".gnu.linkonce.", linkonce_len) != 0)
     return FALSE;
 
@@ -1366,7 +1314,7 @@ is_inconsistent_linkonce_section (asection *sec)
      for Tensilica's XCC compiler.  */
   name = sec_name + linkonce_len;
   if (CONST_STRNEQ (name, "prop."))
-    name = strchr (name + 5, '.') + 1;
+    name = strchr (name + 5, '.') ? strchr (name + 5, '.') + 1 : name + 5;
   else if (name[1] == '.'
           && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
     name += 2;
@@ -1494,7 +1442,7 @@ xtensa_wild_group_interleave_callback (lang_statement_union_type *statement)
          struct wildcard_list *l;
          for (l = w->section_list; l != NULL; l = l->next)
            {
-             if (l->spec.sorted == TRUE)
+             if (l->spec.sorted == by_name)
                {
                  no_reorder = TRUE;
                  break;
@@ -1669,7 +1617,6 @@ xtensa_layout_wild (const reloc_deps_graph *deps, lang_wild_statement_type *w)
 static void
 xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
 {
-  lang_output_section_statement_type *os;
   reloc_deps_graph *deps;
   if (statement->header.type == lang_output_section_statement_enum)
     {
@@ -1691,8 +1638,6 @@ xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
 #endif
       bfd_boolean no_reorder = FALSE;
 
-      os = &statement->output_section_statement;
-
 #if EXTRA_VALIDATION
       old_child_count = ld_count_children (statement);
 #endif
@@ -1875,8 +1820,10 @@ ld_local_file_relocations_fit (lang_statement_union_type *statement,
                  bfd_vma target_addr = e->tgt->output_offset & ~3;
                  if (l32r_addr < target_addr)
                    {
+                     fflush (stdout);
                      fprintf (stderr, "Warning: "
                               "l32r target section before l32r\n");
+                     fflush (stderr);
                      return FALSE;
                    }
 
@@ -1943,7 +1890,7 @@ ld_xtensa_insert_page_offsets (bfd_vma dot,
                etree_type *name_op = exp_nameop (NAME, ".");
                etree_type *addend_op = exp_intop (1 << xtensa_page_power);
                etree_type *add_op = exp_binop ('+', name_op, addend_op);
-               etree_type *assign_op = exp_assop ('=', ".", add_op);
+               etree_type *assign_op = exp_assign (".", add_op, FALSE);
 
                lang_assignment_statement_type *assign_stmt;
                lang_statement_union_type *assign_union;
This page took 0.030356 seconds and 4 git commands to generate.