Set bfd_error to no_symbols if the symbols could not be read.
[deliverable/binutils-gdb.git] / bfd / elf32-h8300.c
index 5ca695520a99deb1faf24253fb43b878fec4f566..48e2960998d980216520bdc6409f82e1e4457fa1 100644 (file)
@@ -1,5 +1,6 @@
 /* Generic support for 32-bit ELF
-   Copyright 1993, 1995, 1998, 1999, 2001 Free Software Foundation, Inc.
+   Copyright 1993, 1995, 1998, 1999, 2001, 2002
+   Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -42,7 +43,7 @@ static boolean elf32_h8_relax_section
 static boolean elf32_h8_relax_delete_bytes
   PARAMS ((bfd *, asection *, bfd_vma, int));
 static boolean elf32_h8_symbol_address_p
-  PARAMS ((bfd *, asection *, Elf32_External_Sym *, bfd_vma));
+  PARAMS ((bfd *, asection *, bfd_vma));
 static bfd_byte *elf32_h8_get_relocated_section_contents
   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
           bfd_byte *, boolean, asymbol **));
@@ -428,6 +429,9 @@ elf32_h8_relocate_section (output_bfd, info, input_bfd, input_section,
   struct elf_link_hash_entry **sym_hashes;
   Elf_Internal_Rela *rel, *relend;
 
+  if (info->relocateable)
+    return true;
+
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
 
@@ -443,29 +447,9 @@ elf32_h8_relocate_section (output_bfd, info, input_bfd, input_section,
       bfd_vma relocation;
       bfd_reloc_status_type r;
 
+      /* This is a final link.  */
       r_symndx = ELF32_R_SYM (rel->r_info);
       r_type = ELF32_R_TYPE (rel->r_info);
-
-      if (info->relocateable)
-       {
-         /* This is a relocateable link.  We don't have to change
-             anything, unless the reloc is against a section symbol,
-             in which case we have to adjust according to where the
-             section symbol winds up in the output section.  */
-         if (r_symndx < symtab_hdr->sh_info)
-           {
-             sym = local_syms + r_symndx;
-             if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-               {
-                 sec = local_sections[r_symndx];
-                 rel->r_addend += sec->output_offset + sym->st_value;
-               }
-           }
-
-         continue;
-       }
-
-      /* This is a final link.  */
       h = NULL;
       sym = NULL;
       sec = NULL;
@@ -677,10 +661,7 @@ elf32_h8_merge_private_bfd_data (ibfd, obfd)
      mov.b:16       ->    mov.b:8                2 bytes
      mov.b:24/32     ->    mov.b:8                4 bytes
 
-     mov.[bwl]:24/32 ->    mov.[bwl]:16           2 bytes
-
-
-*/
+     mov.[bwl]:24/32 ->    mov.[bwl]:16           2 bytes */
 
 static boolean
 elf32_h8_relax_section (abfd, sec, link_info, again)
@@ -691,12 +672,9 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
 {
   Elf_Internal_Shdr *symtab_hdr;
   Elf_Internal_Rela *internal_relocs;
-  Elf_Internal_Rela *free_relocs = NULL;
   Elf_Internal_Rela *irel, *irelend;
   bfd_byte *contents = NULL;
-  bfd_byte *free_contents = NULL;
-  Elf32_External_Sym *extsyms = NULL;
-  Elf32_External_Sym *free_extsyms = NULL;
+  Elf_Internal_Sym *isymbuf = NULL;
   static asection *last_input_section = NULL;
   static Elf_Internal_Rela *last_reloc = NULL;
 
@@ -725,8 +703,6 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                      link_info->keep_memory));
   if (internal_relocs == NULL)
     goto error_return;
-  if (! link_info->keep_memory)
-    free_relocs = internal_relocs;
 
   if (sec != last_input_section)
     last_reloc = NULL;
@@ -744,6 +720,13 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
       if (irel != internal_relocs)
        last_reloc = irel - 1;
 
+      if (ELF32_R_TYPE (irel->r_info) != R_H8_DIR24R8
+         && ELF32_R_TYPE (irel->r_info) != R_H8_PCREL16
+         && ELF32_R_TYPE (irel->r_info) != R_H8_DIR16A8
+         && ELF32_R_TYPE (irel->r_info) != R_H8_DIR24A8
+         && ELF32_R_TYPE (irel->r_info) != R_H8_DIR32A16)
+       continue;
+
       /* Get the section contents if we haven't done so already.  */
       if (contents == NULL)
        {
@@ -756,7 +739,6 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
              contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
              if (contents == NULL)
                goto error_return;
-             free_contents = contents;
 
              if (! bfd_get_section_contents (abfd, sec, contents,
                                              (file_ptr) 0, sec->_raw_size))
@@ -764,40 +746,28 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
            }
        }
 
-      /* Read this BFD's symbols if we haven't done so already.  */
-      if (extsyms == NULL)
+      /* Read this BFD's local symbols if we haven't done so already.  */
+      if (isymbuf == NULL && symtab_hdr->sh_info != 0)
        {
-         /* Get cached copy if it exists.  */
-         if (symtab_hdr->contents != NULL)
-           extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
-         else
-           {
-             /* Go get them off disk.  */
-             extsyms = ((Elf32_External_Sym *)
-                        bfd_malloc (symtab_hdr->sh_size));
-             if (extsyms == NULL)
-               goto error_return;
-             free_extsyms = extsyms;
-             if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
-                 || (bfd_bread (extsyms, symtab_hdr->sh_size, abfd)
-                     != symtab_hdr->sh_size))
-               goto error_return;
-           }
+         isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+         if (isymbuf == NULL)
+           isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+                                           symtab_hdr->sh_info, 0,
+                                           NULL, NULL, NULL);
+         if (isymbuf == NULL)
+           goto error_return;
        }
 
       /* Get the value of the symbol referred to by the reloc.  */
       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
        {
-         Elf_Internal_Sym isym;
-         asection *sym_sec;
-
          /* A local symbol.  */
-         bfd_elf32_swap_symbol_in (abfd,
-                                   extsyms + ELF32_R_SYM (irel->r_info),
-                                   &isym);
+         Elf_Internal_Sym *isym;
+         asection *sym_sec;
 
-         sym_sec = bfd_section_from_elf_index (abfd, isym.st_shndx);
-         symval = (isym.st_value
+         isym = isymbuf + ELF64_R_SYM (irel->r_info);
+         sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
+         symval = (isym->st_value
                    + sym_sec->output_section->vma
                    + sym_sec->output_offset);
        }
@@ -857,13 +827,8 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                /* Note that we've changed the relocs, section contents,
                   etc.  */
                elf_section_data (sec)->relocs = internal_relocs;
-               free_relocs = NULL;
-
                elf_section_data (sec)->this_hdr.contents = contents;
-               free_contents = NULL;
-
-               symtab_hdr->contents = (bfd_byte *) extsyms;
-               free_extsyms = NULL;
+               symtab_hdr->contents = (unsigned char *) isymbuf;
 
                /* If the previous instruction conditionally jumped around
                   this instruction, we may be able to reverse the condition
@@ -880,18 +845,15 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                  {
                    bfd_vma last_value;
                    asection *last_sym_sec;
-                   Elf_Internal_Sym last_symbol;
+                   Elf_Internal_Sym *last_sym;
 
                    /* We will need to examine the symbol used by the
                       previous relocation.  */
 
-                   bfd_elf32_swap_symbol_in (abfd,
-                                             (extsyms + ELF32_R_SYM (last_reloc->r_info)),
-                                             &last_symbol);
-
+                   last_sym = isymbuf + ELF32_R_SYM (last_reloc->r_info);
                    last_sym_sec
-                     = bfd_section_from_elf_index (abfd, last_symbol.st_shndx);
-                   last_value = (last_symbol.st_value
+                     = bfd_section_from_elf_index (abfd, last_sym->st_shndx);
+                   last_value = (last_sym->st_value
                                  + last_sym_sec->output_section->vma
                                  + last_sym_sec->output_offset);
 
@@ -900,8 +862,7 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                       exists at the current location.  */
                    if (last_value == dot + 4
                        && last_reloc->r_offset + 2 == irel->r_offset
-                       && ! elf32_h8_symbol_address_p (abfd, sec,
-                                                       extsyms, dot))
+                       && ! elf32_h8_symbol_address_p (abfd, sec, dot))
                      {
                        /* We can eliminate this jump.  Twiddle the
                           previous relocation as necessary.  */
@@ -984,13 +945,8 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                /* Note that we've changed the relocs, section contents,
                   etc.  */
                elf_section_data (sec)->relocs = internal_relocs;
-               free_relocs = NULL;
-
                elf_section_data (sec)->this_hdr.contents = contents;
-               free_contents = NULL;
-
-               symtab_hdr->contents = (bfd_byte *) extsyms;
-               free_extsyms = NULL;
+               symtab_hdr->contents = (unsigned char *) isymbuf;
 
                /* Get the opcode.  */
                code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
@@ -1046,13 +1002,8 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                /* Note that we've changed the relocs, section contents,
                   etc.  */
                elf_section_data (sec)->relocs = internal_relocs;
-               free_relocs = NULL;
-
                elf_section_data (sec)->this_hdr.contents = contents;
-               free_contents = NULL;
-
-               symtab_hdr->contents = (bfd_byte *) extsyms;
-               free_extsyms = NULL;
+               symtab_hdr->contents = (unsigned char *) isymbuf;
 
                /* Get the opcode.  */
                code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
@@ -1109,13 +1060,8 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                /* Note that we've changed the relocs, section contents,
                   etc.  */
                elf_section_data (sec)->relocs = internal_relocs;
-               free_relocs = NULL;
-
                elf_section_data (sec)->this_hdr.contents = contents;
-               free_contents = NULL;
-
-               symtab_hdr->contents = (bfd_byte *) extsyms;
-               free_extsyms = NULL;
+               symtab_hdr->contents = (unsigned char *) isymbuf;
 
                /* Get the opcode.  */
                code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
@@ -1166,13 +1112,8 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
                /* Note that we've changed the relocs, section contents,
                   etc.  */
                elf_section_data (sec)->relocs = internal_relocs;
-               free_relocs = NULL;
-
                elf_section_data (sec)->this_hdr.contents = contents;
-               free_contents = NULL;
-
-               symtab_hdr->contents = (bfd_byte *) extsyms;
-               free_extsyms = NULL;
+               symtab_hdr->contents = (unsigned char *) isymbuf;
 
                /* Get the opcode.  */
                code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
@@ -1203,45 +1144,43 @@ elf32_h8_relax_section (abfd, sec, link_info, again)
        }
     }
 
-  if (free_relocs != NULL)
+  if (isymbuf != NULL
+      && symtab_hdr->contents != (unsigned char *) isymbuf)
     {
-      free (free_relocs);
-      free_relocs = NULL;
+      if (! link_info->keep_memory)
+       free (isymbuf);
+      else
+       symtab_hdr->contents = (unsigned char *) isymbuf;
     }
 
-  if (free_contents != NULL)
+  if (contents != NULL
+      && elf_section_data (sec)->this_hdr.contents != contents)
     {
       if (! link_info->keep_memory)
-       free (free_contents);
+       free (contents);
       else
        {
          /* Cache the section contents for elf_link_input_bfd.  */
          elf_section_data (sec)->this_hdr.contents = contents;
        }
-      free_contents = NULL;
     }
 
-  if (free_extsyms != NULL)
-    {
-      if (! link_info->keep_memory)
-       free (free_extsyms);
-      else
-       {
-         /* Cache the symbols for elf_link_input_bfd.  */
-         symtab_hdr->contents = (unsigned char *) extsyms;
-       }
-      free_extsyms = NULL;
-    }
+  if (internal_relocs != NULL
+      && elf_section_data (sec)->relocs != internal_relocs)
+    free (internal_relocs);
 
   return true;
 
  error_return:
-  if (free_relocs != NULL)
-    free (free_relocs);
-  if (free_contents != NULL)
-    free (free_contents);
-  if (free_extsyms != NULL)
-    free (free_extsyms);
+  if (isymbuf != NULL
+      && symtab_hdr->contents != (unsigned char *) isymbuf)
+    free (isymbuf);
+  if (contents != NULL
+      && elf_section_data (sec)->this_hdr.contents != contents)
+    free (contents);
+  if (internal_relocs != NULL
+      && elf_section_data (sec)->relocs != internal_relocs)
+    free (internal_relocs);
   return false;
 }
 
@@ -1255,19 +1194,18 @@ elf32_h8_relax_delete_bytes (abfd, sec, addr, count)
      int count;
 {
   Elf_Internal_Shdr *symtab_hdr;
-  Elf32_External_Sym *extsyms;
-  int shndx, index;
+  unsigned int sec_shndx;
   bfd_byte *contents;
   Elf_Internal_Rela *irel, *irelend;
   Elf_Internal_Rela *irelalign;
+  Elf_Internal_Sym *isym;
+  Elf_Internal_Sym *isymend;
   bfd_vma toaddr;
-  Elf32_External_Sym *esym, *esymend;
-  struct elf_link_hash_entry *sym_hash;
-
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-  extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
+  struct elf_link_hash_entry **sym_hashes;
+  struct elf_link_hash_entry **end_hashes;
+  unsigned int symcount;
 
-  shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
+  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
 
   contents = elf_section_data (sec)->this_hdr.contents;
 
@@ -1295,40 +1233,32 @@ elf32_h8_relax_delete_bytes (abfd, sec, addr, count)
     }
 
   /* Adjust the local symbols defined in this section.  */
-  esym = extsyms;
-  esymend = esym + symtab_hdr->sh_info;
-  for (; esym < esymend; esym++)
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
+  isymend = isym + symtab_hdr->sh_info;
+  for (; isym < isymend; isym++)
     {
-      Elf_Internal_Sym isym;
-
-      bfd_elf32_swap_symbol_in (abfd, esym, &isym);
-
-      if (isym.st_shndx == shndx
-         && isym.st_value > addr
-         && isym.st_value < toaddr)
-       {
-         isym.st_value -= count;
-         bfd_elf32_swap_symbol_out (abfd, &isym, esym);
-       }
+      if (isym->st_shndx == sec_shndx
+         && isym->st_value > addr
+         && isym->st_value < toaddr)
+       isym->st_value -= count;
     }
 
   /* Now adjust the global symbols defined in this section.  */
-  esym = extsyms + symtab_hdr->sh_info;
-  esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
-  for (index = 0; esym < esymend; esym++, index++)
+  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
+             - symtab_hdr->sh_info);
+  sym_hashes = elf_sym_hashes (abfd);
+  end_hashes = sym_hashes + symcount;
+  for (; sym_hashes < end_hashes; sym_hashes++)
     {
-      Elf_Internal_Sym isym;
-
-      bfd_elf32_swap_symbol_in (abfd, esym, &isym);
-      sym_hash = elf_sym_hashes (abfd)[index];
-      if (isym.st_shndx == shndx
-         && ((sym_hash)->root.type == bfd_link_hash_defined
-             || (sym_hash)->root.type == bfd_link_hash_defweak)
-         && (sym_hash)->root.u.def.section == sec
-         && (sym_hash)->root.u.def.value > addr
-         && (sym_hash)->root.u.def.value < toaddr)
+      struct elf_link_hash_entry *sym_hash = *sym_hashes;
+      if ((sym_hash->root.type == bfd_link_hash_defined
+          || sym_hash->root.type == bfd_link_hash_defweak)
+         && sym_hash->root.u.def.section == sec
+         && sym_hash->root.u.def.value > addr
+         && sym_hash->root.u.def.value < toaddr)
        {
-         (sym_hash)->root.u.def.value -= count;
+         sym_hash->root.u.def.value -= count;
        }
     }
 
@@ -1338,46 +1268,46 @@ elf32_h8_relax_delete_bytes (abfd, sec, addr, count)
 /* Return true if a symbol exists at the given address, else return
    false.  */
 static boolean
-elf32_h8_symbol_address_p (abfd, sec, extsyms, addr)
+elf32_h8_symbol_address_p (abfd, sec, addr)
      bfd *abfd;
      asection *sec;
-     Elf32_External_Sym *extsyms;
      bfd_vma addr;
 {
   Elf_Internal_Shdr *symtab_hdr;
-  int shndx;
-  Elf32_External_Sym *esym, *esymend;
-  struct elf_link_hash_entry **sym_hash, **sym_hash_end;
+  unsigned int sec_shndx;
+  Elf_Internal_Sym *isym;
+  Elf_Internal_Sym *isymend;
+  struct elf_link_hash_entry **sym_hashes;
+  struct elf_link_hash_entry **end_hashes;
+  unsigned int symcount;
 
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-  shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
+  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
 
   /* Examine all the symbols.  */
-  esym = extsyms;
-  esymend = esym + symtab_hdr->sh_info;
-  for (; esym < esymend; esym++)
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
+  isymend = isym + symtab_hdr->sh_info;
+  for (; isym < isymend; isym++)
     {
-      Elf_Internal_Sym isym;
-
-      bfd_elf32_swap_symbol_in (abfd, esym, &isym);
-
-      if (isym.st_shndx == shndx
-         && isym.st_value == addr)
+      if (isym->st_shndx == sec_shndx
+         && isym->st_value == addr)
        return true;
     }
 
-  sym_hash = elf_sym_hashes (abfd);
-  sym_hash_end = (sym_hash
-                 + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
-                    - symtab_hdr->sh_info));
-  for (; sym_hash < sym_hash_end; sym_hash++)
+  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
+             - symtab_hdr->sh_info);
+  sym_hashes = elf_sym_hashes (abfd);
+  end_hashes = sym_hashes + symcount;
+  for (; sym_hashes < end_hashes; sym_hashes++)
     {
-      if (((*sym_hash)->root.type == bfd_link_hash_defined
-          || (*sym_hash)->root.type == bfd_link_hash_defweak)
-         && (*sym_hash)->root.u.def.section == sec
-         && (*sym_hash)->root.u.def.value == addr)
+      struct elf_link_hash_entry *sym_hash = *sym_hashes;
+      if ((sym_hash->root.type == bfd_link_hash_defined
+          || sym_hash->root.type == bfd_link_hash_defweak)
+         && sym_hash->root.u.def.section == sec
+         && sym_hash->root.u.def.value == addr)
        return true;
     }
+
   return false;
 }
 
@@ -1399,8 +1329,7 @@ elf32_h8_get_relocated_section_contents (output_bfd, link_info, link_order,
   bfd *input_bfd = input_section->owner;
   asection **sections = NULL;
   Elf_Internal_Rela *internal_relocs = NULL;
-  Elf32_External_Sym *external_syms = NULL;
-  Elf_Internal_Sym *internal_syms = NULL;
+  Elf_Internal_Sym *isymbuf = NULL;
 
   /* We only need to handle the case of relaxing, or of having a
      particular set of section contents, specially.  */
@@ -1419,25 +1348,9 @@ elf32_h8_get_relocated_section_contents (output_bfd, link_info, link_order,
   if ((input_section->flags & SEC_RELOC) != 0
       && input_section->reloc_count > 0)
     {
-      Elf_Internal_Sym *isymp;
       asection **secpp;
-      Elf32_External_Sym *esym, *esymend;
-
-      if (symtab_hdr->contents != NULL)
-       external_syms = (Elf32_External_Sym *) symtab_hdr->contents;
-      else
-       {
-         bfd_size_type amt;
-
-         amt = symtab_hdr->sh_info;
-         amt *= sizeof (Elf32_External_Sym);
-         external_syms = (Elf32_External_Sym *) bfd_malloc (amt);
-         if (external_syms == NULL && symtab_hdr->sh_info > 0)
-           goto error_return;
-         if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
-             || bfd_bread (external_syms, amt, input_bfd) != amt)
-           goto error_return;
-       }
+      Elf_Internal_Sym *isym, *isymend;
+      bfd_size_type amt;
 
       internal_relocs = (_bfd_elf32_link_read_relocs
                         (input_bfd, input_section, (PTR) NULL,
@@ -1445,75 +1358,65 @@ elf32_h8_get_relocated_section_contents (output_bfd, link_info, link_order,
       if (internal_relocs == NULL)
        goto error_return;
 
-      internal_syms = ((Elf_Internal_Sym *)
-                      bfd_malloc ((bfd_size_type) symtab_hdr->sh_info
-                                  * sizeof (Elf_Internal_Sym)));
-      if (internal_syms == NULL && symtab_hdr->sh_info > 0)
-       goto error_return;
+      if (symtab_hdr->sh_info != 0)
+       {
+         isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+         if (isymbuf == NULL)
+           isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+                                           symtab_hdr->sh_info, 0,
+                                           NULL, NULL, NULL);
+         if (isymbuf == NULL)
+           goto error_return;
+       }
 
-      sections = (asection **) bfd_malloc ((bfd_size_type) symtab_hdr->sh_info
-                                          * sizeof (asection *));
-      if (sections == NULL && symtab_hdr->sh_info > 0)
+      amt = symtab_hdr->sh_info;
+      amt *= sizeof (asection *);
+      sections = (asection **) bfd_malloc (amt);
+      if (sections == NULL && amt != 0)
        goto error_return;
 
-      isymp = internal_syms;
-      secpp = sections;
-      esym = external_syms;
-      esymend = esym + symtab_hdr->sh_info;
-      for (; esym < esymend; ++esym, ++isymp, ++secpp)
+      isymend = isymbuf + symtab_hdr->sh_info;
+      for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
        {
          asection *isec;
 
-         bfd_elf32_swap_symbol_in (input_bfd, esym, isymp);
-
-         if (isymp->st_shndx == SHN_UNDEF)
+         if (isym->st_shndx == SHN_UNDEF)
            isec = bfd_und_section_ptr;
-         else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)
-           isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
-         else if (isymp->st_shndx == SHN_ABS)
+         else if (isym->st_shndx == SHN_ABS)
            isec = bfd_abs_section_ptr;
-         else if (isymp->st_shndx == SHN_COMMON)
+         else if (isym->st_shndx == SHN_COMMON)
            isec = bfd_com_section_ptr;
          else
-           {
-             /* Who knows?  */
-             isec = NULL;
-           }
+           isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
 
          *secpp = isec;
        }
 
       if (! elf32_h8_relocate_section (output_bfd, link_info, input_bfd,
                                       input_section, data, internal_relocs,
-                                      internal_syms, sections))
+                                      isymbuf, sections))
        goto error_return;
 
       if (sections != NULL)
        free (sections);
-      sections = NULL;
-      if (internal_syms != NULL)
-       free (internal_syms);
-      internal_syms = NULL;
-      if (external_syms != NULL && symtab_hdr->contents == NULL)
-       free (external_syms);
-      external_syms = NULL;
-      if (internal_relocs != elf_section_data (input_section)->relocs)
+      if (isymbuf != NULL
+         && symtab_hdr->contents != (unsigned char *) isymbuf)
+       free (isymbuf);
+      if (elf_section_data (input_section)->relocs != internal_relocs)
        free (internal_relocs);
-      internal_relocs = NULL;
     }
 
   return data;
 
  error_return:
-  if (internal_relocs != NULL
-      && internal_relocs != elf_section_data (input_section)->relocs)
-    free (internal_relocs);
-  if (external_syms != NULL && symtab_hdr->contents == NULL)
-    free (external_syms);
-  if (internal_syms != NULL)
-    free (internal_syms);
   if (sections != NULL)
     free (sections);
+  if (isymbuf != NULL
+      && symtab_hdr->contents != (unsigned char *) isymbuf)
+    free (isymbuf);
+  if (internal_relocs != NULL
+      && elf_section_data (input_section)->relocs != internal_relocs)
+    free (internal_relocs);
   return NULL;
 }
 
@@ -1545,6 +1448,7 @@ elf32_h8_get_relocated_section_contents (output_bfd, link_info, link_order,
 
 /* Use an H8 specific linker, not the ELF generic linker.  */
 #define elf_backend_relocate_section elf32_h8_relocate_section
+#define elf_backend_rela_normal                1
 
 /* And relaxing stuff.  */
 #define bfd_elf32_bfd_relax_section     elf32_h8_relax_section
This page took 0.03233 seconds and 4 git commands to generate.