Merge branch 'master' into merge-job
[deliverable/binutils-gdb.git] / bfd / elf32-nds32.c
index b8a61471bd0e1e5a615a8cae02acf901f001a82a..3168587560a945eba927573adbf74de89c44f750 100644 (file)
@@ -1,5 +1,5 @@
 /* NDS32-specific support for 32-bit ELF.
 /* NDS32-specific support for 32-bit ELF.
-   Copyright (C) 2012-2019 Free Software Foundation, Inc.
+   Copyright (C) 2012-2020 Free Software Foundation, Inc.
    Contributed by Andes Technology Corporation.
 
    This file is part of BFD, the Binary File Descriptor library.
    Contributed by Andes Technology Corporation.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -32,6 +32,9 @@
 #include "opcode/cgen.h"
 #include "../opcodes/nds32-opc.h"
 
 #include "opcode/cgen.h"
 #include "../opcodes/nds32-opc.h"
 
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
+
 /* Relocation HOWTO functions.  */
 static bfd_reloc_status_type nds32_elf_ignore_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 /* Relocation HOWTO functions.  */
 static bfd_reloc_status_type nds32_elf_ignore_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
@@ -2526,7 +2529,9 @@ nds32_insertion_sort (void *base, size_t nmemb, size_t size,
 {
   char *ptr = (char *) base;
   int i, j;
 {
   char *ptr = (char *) base;
   int i, j;
-  char *tmp = xmalloc (size);
+  char tmp[sizeof (Elf_Internal_Rela)];
+
+  BFD_ASSERT (size <= sizeof (tmp));
 
   /* If i is less than j, i is inserted before j.
 
 
   /* If i is less than j, i is inserted before j.
 
@@ -2550,7 +2555,6 @@ nds32_insertion_sort (void *base, size_t nmemb, size_t size,
       memmove (ptr + (j + 1) * size, ptr + j * size, (i - j) * size);
       memcpy (ptr + j * size, tmp, size);
     }
       memmove (ptr + (j + 1) * size, ptr + j * size, (i - j) * size);
       memcpy (ptr + j * size, tmp, size);
     }
-  free (tmp);
 }
 
 /* Sort relocation by r_offset.
 }
 
 /* Sort relocation by r_offset.
@@ -3723,11 +3727,11 @@ create_got_section (bfd *dynobj, struct bfd_link_info *info)
   /* _bfd_elf_create_got_section will create it for us.  */
   ehtab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
   if (ehtab->srelgot == NULL
   /* _bfd_elf_create_got_section will create it for us.  */
   ehtab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
   if (ehtab->srelgot == NULL
-      || !bfd_set_section_flags (dynobj, ehtab->srelgot,
+      || !bfd_set_section_flags (ehtab->srelgot,
                                 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
                                  | SEC_IN_MEMORY | SEC_LINKER_CREATED
                                  | SEC_READONLY))
                                 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
                                  | SEC_IN_MEMORY | SEC_LINKER_CREATED
                                  | SEC_READONLY))
-      || !bfd_set_section_alignment (dynobj, ehtab->srelgot, 2))
+      || !bfd_set_section_alignment (ehtab->srelgot, 2))
     return FALSE;
 
   return TRUE;
     return FALSE;
 
   return TRUE;
@@ -3769,8 +3773,8 @@ nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   s = bfd_make_section (abfd, ".plt");
   ehtab->splt = s;
   if (s == NULL
   s = bfd_make_section (abfd, ".plt");
   ehtab->splt = s;
   if (s == NULL
-      || !bfd_set_section_flags (abfd, s, pltflags)
-      || !bfd_set_section_alignment (abfd, s, bed->plt_alignment))
+      || !bfd_set_section_flags (s, pltflags)
+      || !bfd_set_section_alignment (s, bed->plt_alignment))
     return FALSE;
 
   if (bed->want_plt_sym)
     return FALSE;
 
   if (bed->want_plt_sym)
@@ -3798,8 +3802,8 @@ nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
                        bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
   ehtab->srelplt = s;
   if (s == NULL
                        bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
   ehtab->srelplt = s;
   if (s == NULL
-      || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
-      || !bfd_set_section_alignment (abfd, s, ptralign))
+      || !bfd_set_section_flags (s, flags | SEC_READONLY)
+      || !bfd_set_section_alignment (s, ptralign))
     return FALSE;
 
   if (ehtab->sgot == NULL && !create_got_section (abfd, info))
     return FALSE;
 
   if (ehtab->sgot == NULL && !create_got_section (abfd, info))
@@ -3807,11 +3811,11 @@ nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
 
   for (sec = abfd->sections; sec; sec = sec->next)
     {
 
   for (sec = abfd->sections; sec; sec = sec->next)
     {
-      secflags = bfd_get_section_flags (abfd, sec);
+      secflags = bfd_section_flags (sec);
       if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
          || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
        continue;
       if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
          || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
        continue;
-      secname = bfd_get_section_name (abfd, sec);
+      secname = bfd_section_name (sec);
       relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
       strcpy (relname, ".rela");
       strcat (relname, secname);
       relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
       strcpy (relname, ".rela");
       strcat (relname, secname);
@@ -3819,8 +3823,8 @@ nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
        continue;
       s = bfd_make_section (abfd, relname);
       if (s == NULL
        continue;
       s = bfd_make_section (abfd, relname);
       if (s == NULL
-         || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
-         || !bfd_set_section_alignment (abfd, s, ptralign))
+         || !bfd_set_section_flags (s, flags | SEC_READONLY)
+         || !bfd_set_section_alignment (s, ptralign))
        return FALSE;
     }
 
        return FALSE;
     }
 
@@ -3835,7 +3839,7 @@ nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
       s = bfd_make_section (abfd, ".dynbss");
       htab->sdynbss = s;
       if (s == NULL
       s = bfd_make_section (abfd, ".dynbss");
       htab->sdynbss = s;
       if (s == NULL
-         || !bfd_set_section_flags (abfd, s, SEC_ALLOC | SEC_LINKER_CREATED))
+         || !bfd_set_section_flags (s, SEC_ALLOC | SEC_LINKER_CREATED))
        return FALSE;
       /* The .rel[a].bss section holds copy relocs.  This section is not
         normally needed.  We need to create it here, though, so that the
        return FALSE;
       /* The .rel[a].bss section holds copy relocs.  This section is not
         normally needed.  We need to create it here, though, so that the
@@ -3854,8 +3858,8 @@ nds32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
                                       ? ".rela.bss" : ".rel.bss"));
          htab->srelbss = s;
          if (s == NULL
                                       ? ".rela.bss" : ".rel.bss"));
          htab->srelbss = s;
          if (s == NULL
-             || !bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
-             || !bfd_set_section_alignment (abfd, s, ptralign))
+             || !bfd_set_section_flags (s, flags | SEC_READONLY)
+             || !bfd_set_section_alignment (s, ptralign))
            return FALSE;
        }
     }
            return FALSE;
        }
     }
@@ -4065,9 +4069,9 @@ nds32_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   /* Apply the required alignment.  */
   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
 
   /* Apply the required alignment.  */
   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
+  if (power_of_two > bfd_section_alignment (s))
     {
     {
-      if (!bfd_set_section_alignment (dynobj, s, power_of_two))
+      if (!bfd_set_section_alignment (s, power_of_two))
        return FALSE;
     }
 
        return FALSE;
     }
 
@@ -4525,7 +4529,7 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        {
          got_size += s->size;
        }
        {
          got_size += s->size;
        }
-      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
+      else if (strncmp (bfd_section_name (s), ".rela", 5) == 0)
        {
          if (s->size != 0 && s != elf_hash_table (info)->srelplt)
            relocs = TRUE;
        {
          if (s->size != 0 && s != elf_hash_table (info)->srelplt)
            relocs = TRUE;
@@ -5571,8 +5575,7 @@ nds32_elf_relocate_section (bfd *            output_bfd ATTRIBUTE_UNUSED,
                    return FALSE;
 
                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
                    return FALSE;
 
                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
+                             && strcmp (bfd_section_name (input_section),
                                         name + 5) == 0);
 
                  sreloc = bfd_get_section_by_name (dynobj, name);
                                         name + 5) == 0);
 
                  sreloc = bfd_get_section_by_name (dynobj, name);
@@ -5636,7 +5639,7 @@ nds32_elf_relocate_section (bfd *            output_bfd ATTRIBUTE_UNUSED,
                      if (h->dynindx == -1)
                        {
                          _bfd_error_handler
                      if (h->dynindx == -1)
                        {
                          _bfd_error_handler
-                           (_("%pB: relocation %s against `%s' can not be used when"
+                           (_("%pB: relocation %s against `%s' can not be used when "
                               "making a shared object; recompile with -fPIC"),
                             input_bfd, nds32_elf_howto_table[r_type].name, h->root.root.string);
                          bfd_set_error (bfd_error_bad_value);
                               "making a shared object; recompile with -fPIC"),
                             input_bfd, nds32_elf_howto_table[r_type].name, h->root.root.string);
                          bfd_set_error (bfd_error_bad_value);
@@ -6166,7 +6169,7 @@ check_reloc:
              name = bfd_elf_string_from_elf_section
                      (input_bfd, symtab_hdr->sh_link, sym->st_name);
              if (name == NULL || *name == '\0')
              name = bfd_elf_string_from_elf_section
                      (input_bfd, symtab_hdr->sh_link, sym->st_name);
              if (name == NULL || *name == '\0')
-               name = bfd_section_name (input_bfd, sec);
+               name = bfd_section_name (sec);
            }
 
          if (errmsg != NULL)
            }
 
          if (errmsg != NULL)
@@ -6672,9 +6675,8 @@ nds32_elf_object_p (bfd *abfd)
 
 /* Store the machine number in the flags field.  */
 
 
 /* Store the machine number in the flags field.  */
 
-static void
-nds32_elf_final_write_processing (bfd *abfd,
-                                 bfd_boolean linker ATTRIBUTE_UNUSED)
+static bfd_boolean
+nds32_elf_final_write_processing (bfd *abfd)
 {
   unsigned long val;
   static unsigned int cur_mach = 0;
 {
   unsigned long val;
   static unsigned int cur_mach = 0;
@@ -6711,6 +6713,7 @@ nds32_elf_final_write_processing (bfd *abfd,
 
   elf_elfheader (abfd)->e_flags &= ~EF_NDS_ARCH;
   elf_elfheader (abfd)->e_flags |= val;
 
   elf_elfheader (abfd)->e_flags &= ~EF_NDS_ARCH;
   elf_elfheader (abfd)->e_flags |= val;
+  return _bfd_elf_final_write_processing (abfd);
 }
 
 /* Function to keep NDS32 specific file flags.  */
 }
 
 /* Function to keep NDS32 specific file flags.  */
@@ -7390,7 +7393,7 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                    return FALSE;
 
                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
                    return FALSE;
 
                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (abfd, sec),
+                             && strcmp (bfd_section_name (sec),
                                         name + 5) == 0);
 
                  sreloc = bfd_get_section_by_name (dynobj, name);
                                         name + 5) == 0);
 
                  sreloc = bfd_get_section_by_name (dynobj, name);
@@ -7404,8 +7407,8 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
                      if ((sec->flags & SEC_ALLOC) != 0)
                        flags |= SEC_ALLOC | SEC_LOAD;
                      if (sreloc == NULL
                      if ((sec->flags & SEC_ALLOC) != 0)
                        flags |= SEC_ALLOC | SEC_LOAD;
                      if (sreloc == NULL
-                         || !bfd_set_section_flags (dynobj, sreloc, flags)
-                         || !bfd_set_section_alignment (dynobj, sreloc, 2))
+                         || !bfd_set_section_flags (sreloc, flags)
+                         || !bfd_set_section_alignment (sreloc, 2))
                        return FALSE;
 
                      elf_section_type (sreloc) = SHT_RELA;
                        return FALSE;
 
                      elf_section_type (sreloc) = SHT_RELA;
@@ -13220,7 +13223,8 @@ nds32_elf_get_relocated_section_contents (bfd *abfd,
                = HOWTO (0, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL,
                         "unused", FALSE, 0, 0, FALSE);
 
                = HOWTO (0, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL,
                         "unused", FALSE, 0, 0, FALSE);
 
-             off = (*parent)->address * bfd_octets_per_byte (input_bfd);
+             off = (*parent)->address * OCTETS_PER_BYTE (input_bfd,
+                                                         input_section);
              _bfd_clear_contents ((*parent)->howto, input_bfd,
                                   input_section, data, off);
              (*parent)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
              _bfd_clear_contents ((*parent)->howto, input_bfd,
                                   input_section, data, off);
              (*parent)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
This page took 0.045523 seconds and 4 git commands to generate.