Show AIX gc'd symbol address adjustments in map file
[deliverable/binutils-gdb.git] / ld / emultempl / xtensaelf.em
index 04f870a7e7ac8764a9c466f3c8a02279ca66f36d..2d9f594969f54a3e6a8065e72e731fa0342a1a93 100644 (file)
@@ -1,6 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2003, 2004, 2005, 2006, 2007
-#   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.
 #
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 #include <xtensa-config.h>
 #include "../bfd/elf-bfd.h"
-#include "../bfd/libbfd.h"
 #include "elf/xtensa.h"
 #include "bfd.h"
 
@@ -42,9 +40,6 @@ static void xtensa_strip_inconsistent_linkonce_sections
   (lang_statement_list_type *);
 
 
-/* Flag for the emulation-specific "--no-relax" option.  */
-static bfd_boolean disable_relaxation = FALSE;
-
 /* This number is irrelevant until we turn on use_literal_pages */
 static bfd_vma xtensa_page_power = 12; /* 4K pages.  */
 
@@ -101,10 +96,10 @@ 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;
+
   *error_message = "";
   insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
   if (insn_sec == NULL)
@@ -117,15 +112,10 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
       *error_message = _("file already has property tables");
       return FALSE;
     }
-  
+
   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))
        {
@@ -137,24 +127,23 @@ 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;
     }
-  
+
   prop_sec->size = entry_count * 12;
   prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
   elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
 
   /* 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)
     {
@@ -169,12 +158,12 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
       /* If there is already an internal_reloc, then save it so that the
         read_relocs function freshly allocates a copy.  */
       Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
-      
+
       elf_section_data (insn_sec)->relocs = NULL;
-      internal_relocs = 
+      internal_relocs =
        _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE);
       elf_section_data (insn_sec)->relocs = saved_relocs;
-      
+
       if (internal_relocs == NULL)
        {
          *error_message = _("out of memory");
@@ -188,7 +177,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
       elf_section_data (prop_sec)->relocs = internal_relocs;
       prop_sec->reloc_count = reloc_count;
     }
-  
+
   /* Now copy each insn table entry to the prop table entry with
      appropriate flags.  */
   for (entry = 0; entry < entry_count; ++entry)
@@ -209,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++)
        {
@@ -218,7 +206,7 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
 
          rela = &internal_relocs[i];
 
-         /* If this relocation is to the .xt.insn section, 
+         /* If this relocation is to the .xt.insn section,
             change the section number and the offset.  */
          r_offset = rela->r_offset;
          r_offset += 4 * (r_offset / 8);
@@ -227,10 +215,10 @@ replace_insn_sec_with_prop_sec (bfd *abfd,
     }
 
   remove_section (abfd, insn_sec);
-  
+
   if (insn_contents)
     free (insn_contents);
-  
+
   return TRUE;
 
  cleanup:
@@ -258,8 +246,8 @@ replace_instruction_table_sections (bfd *abfd, asection *sec)
   char *prop_sec_name = NULL;
   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;
@@ -279,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);
        }
     }
@@ -297,7 +285,7 @@ elf_xtensa_after_open (void)
 {
   /* First call the ELF version.  */
   gld${EMULATION_NAME}_after_open ();
-  
+
   /* Now search the input files looking for instruction table sections.  */
   LANG_FOR_EACH_INPUT_STATEMENT (f)
     {
@@ -396,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)
@@ -407,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);
 }
@@ -434,12 +422,14 @@ elf_xtensa_before_allocation (void)
      required to process relocations) for the selected Xtensa
      configuration.  */
 
-  if (is_big_endian && output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
+  if (is_big_endian
+      && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
     {
       einfo (_("%F%P: little endian output does not match "
               "Xtensa configuration\n"));
     }
-  if (!is_big_endian && output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
+  if (!is_big_endian
+      && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
     {
       einfo (_("%F%P: big endian output does not match "
               "Xtensa configuration\n"));
@@ -460,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)
@@ -525,16 +515,16 @@ elf_xtensa_before_allocation (void)
      specified.  This is done here instead of in the before_parse hook
      because there is a check in main() to prohibit use of --relax and
      -r together and that combination should be allowed for Xtensa.  */
-
-  if (!disable_relaxation)
-    command_line.relax = TRUE;
+  if (RELAXATION_DISABLED_BY_DEFAULT)
+    ENABLE_RELAXATION;
 
   xtensa_strip_inconsistent_linkonce_sections (stat_ptr);
 
   gld${EMULATION_NAME}_before_allocation ();
 
   xtensa_wild_group_interleave (stat_ptr->head);
-  if (command_line.relax)
+
+  if (RELAXATION_ENABLED)
     xtensa_colocate_output_literals (stat_ptr->head);
 
   /* TBD: We need to force the page alignments to here and only do
@@ -599,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)
@@ -659,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;
 }
 
@@ -669,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);
 }
 
 
@@ -1283,6 +1224,10 @@ 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 (_("%F%P: Relaxation not supported with "
+                "--enable-non-contiguous-regions.\n"));
+
       if (l->header.type == lang_input_section_enum)
        {
          lang_input_section_type *input;
@@ -1356,10 +1301,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;
 
@@ -1367,7 +1312,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;
@@ -1495,7 +1440,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;
@@ -1670,7 +1615,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)
     {
@@ -1692,8 +1636,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
@@ -1876,8 +1818,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;
                    }
 
@@ -1944,25 +1888,22 @@ 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;
                lang_statement_list_type tmplist;
-               lang_statement_list_type *old_stat_ptr = stat_ptr;
 
                /* There is hidden state in "lang_add_assignment".  It
                   appends the new assignment statement to the stat_ptr
                   list.  Thus, we swap it before and after the call.  */
 
-               tmplist.head = NULL;
-               tmplist.tail = &tmplist.head;
-
-               stat_ptr = &tmplist;
+               lang_list_init (&tmplist);
+               push_stat_ptr (&tmplist);
                /* Warning: side effect; statement appended to stat_ptr.  */
                assign_stmt = lang_add_assignment (assign_op);
                assign_union = (lang_statement_union_type *) assign_stmt;
-               stat_ptr = old_stat_ptr;
+               pop_stat_ptr ();
 
                assign_union->header.next = l;
                *(*stack_p)->iterloc.loc = assign_union;
@@ -1984,8 +1925,7 @@ EOF
 #
 PARSE_AND_LIST_PROLOGUE='
 #define OPTION_OPT_SIZEOPT              (300)
-#define OPTION_NO_RELAX                        (OPTION_OPT_SIZEOPT + 1)
-#define OPTION_LITERAL_MOVEMENT                (OPTION_NO_RELAX + 1)
+#define OPTION_LITERAL_MOVEMENT                (OPTION_OPT_SIZEOPT + 1)
 #define OPTION_NO_LITERAL_MOVEMENT     (OPTION_LITERAL_MOVEMENT + 1)
 extern int elf32xtensa_size_opt;
 extern int elf32xtensa_no_literal_movement;
@@ -1993,23 +1933,20 @@ extern int elf32xtensa_no_literal_movement;
 
 PARSE_AND_LIST_LONGOPTS='
   { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
-  { "no-relax", no_argument, NULL, OPTION_NO_RELAX},
   { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
   { "no-literal-movement", no_argument, NULL, OPTION_NO_LITERAL_MOVEMENT},
 '
 
 PARSE_AND_LIST_OPTIONS='
-  fprintf (file, _("  --size-opt\t\tWhen relaxing longcalls, prefer size optimization\n\t\t\t  over branch target alignment\n"));
-  fprintf (file, _("  --no-relax\t\tDo not relax branches or coalesce literals\n"));
+  fprintf (file, _("\
+  --size-opt                  When relaxing longcalls, prefer size\n\
+                                optimization over branch target alignment\n"));
 '
 
 PARSE_AND_LIST_ARGS_CASES='
     case OPTION_OPT_SIZEOPT:
       elf32xtensa_size_opt = 1;
       break;
-    case OPTION_NO_RELAX:
-      disable_relaxation = TRUE;
-      break;
     case OPTION_LITERAL_MOVEMENT:
       elf32xtensa_no_literal_movement = 0;
       break;
@@ -2024,4 +1961,3 @@ LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse
 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation
-
This page took 0.031504 seconds and 4 git commands to generate.