Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/elf-m10300.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Matsushita 10300 specific support for 32-bit ELF
    2    Copyright 1996, 1997, 1998, 1999, 2000, 2001
     2   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44
     
    2424#include "elf-bfd.h"
    2525#include "elf/mn10300.h"
     26
     27static bfd_reloc_status_type mn10300_elf_final_link_relocate
     28  PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
     29           bfd_vma, bfd_vma, bfd_vma, struct bfd_link_info *,
     30           asection *, int));
     31static bfd_boolean mn10300_elf_relocate_section
     32  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
     33           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
     34static bfd_boolean mn10300_elf_relax_section
     35  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
     36static bfd_byte * mn10300_elf_get_relocated_section_contents
     37  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
     38           bfd_byte *, bfd_boolean, asymbol **));
     39static unsigned long elf_mn10300_mach
     40  PARAMS ((flagword));
     41void _bfd_mn10300_elf_final_write_processing
     42  PARAMS ((bfd *, bfd_boolean));
     43bfd_boolean _bfd_mn10300_elf_object_p
     44  PARAMS ((bfd *));
     45bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data
     46  PARAMS ((bfd *,bfd *));
    2647
    2748struct elf32_mn10300_link_hash_entry {
     
    87108  (elf_link_hash_traverse                                               \
    88109   (&(table)->root,                                                     \
    89     (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func),  \
     110    (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
    90111    (info)))
    91112
     
    94115static struct bfd_link_hash_table *elf32_mn10300_link_hash_table_create
    95116  PARAMS ((bfd *));
     117static void elf32_mn10300_link_hash_table_free
     118  PARAMS ((struct bfd_link_hash_table *));
    96119
    97120static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
    98121  PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
    99122static void mn10300_info_to_howto
    100   PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
    101 static boolean mn10300_elf_check_relocs
     123  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
     124static bfd_boolean mn10300_elf_check_relocs
    102125  PARAMS ((bfd *, struct bfd_link_info *, asection *,
    103126           const Elf_Internal_Rela *));
    104127static asection *mn10300_elf_gc_mark_hook
    105   PARAMS ((bfd *, struct bfd_link_info *info, Elf_Internal_Rela *,
     128  PARAMS ((asection *, struct bfd_link_info *info, Elf_Internal_Rela *,
    106129           struct elf_link_hash_entry *, Elf_Internal_Sym *));
    107 static boolean mn10300_elf_relax_delete_bytes
     130static bfd_boolean mn10300_elf_relax_delete_bytes
    108131  PARAMS ((bfd *, asection *, bfd_vma, int));
    109 static boolean mn10300_elf_symbol_address_p
    110   PARAMS ((bfd *, asection *, Elf32_External_Sym *, bfd_vma));
    111 static boolean elf32_mn10300_finish_hash_table_entry
     132static bfd_boolean mn10300_elf_symbol_address_p
     133  PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
     134static bfd_boolean elf32_mn10300_finish_hash_table_entry
    112135  PARAMS ((struct bfd_hash_entry *, PTR));
    113136static void compute_function_info
    114137  PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *,
    115138           bfd_vma, unsigned char *));
    116 
    117 /* We have to use RELA instructions since md_apply_fix3 in the assembler
    118    does absolutely nothing.  */
    119 #define USE_RELA
    120139
    121140static reloc_howto_type elf_mn10300_howto_table[] = {
     
    125144         2,
    126145         16,
    127          false,
     146         FALSE,
    128147         0,
    129148         complain_overflow_bitfield,
    130149         bfd_elf_generic_reloc,
    131150         "R_MN10300_NONE",
    132          false,
     151         FALSE,
    133152         0,
    134153         0,
    135          false),
     154         FALSE),
    136155  /* Standard 32 bit reloc.  */
    137156  HOWTO (R_MN10300_32,
     
    139158         2,
    140159         32,
    141          false,
     160         FALSE,
    142161         0,
    143162         complain_overflow_bitfield,
    144163         bfd_elf_generic_reloc,
    145164         "R_MN10300_32",
    146          false,
     165         FALSE,
    147166         0xffffffff,
    148167         0xffffffff,
    149          false),
     168         FALSE),
    150169  /* Standard 16 bit reloc.  */
    151170  HOWTO (R_MN10300_16,
     
    153172         1,
    154173         16,
    155          false,
     174         FALSE,
    156175         0,
    157176         complain_overflow_bitfield,
    158177         bfd_elf_generic_reloc,
    159178         "R_MN10300_16",
    160          false,
     179         FALSE,
    161180         0xffff,
    162181         0xffff,
    163          false),
     182         FALSE),
    164183  /* Standard 8 bit reloc.  */
    165184  HOWTO (R_MN10300_8,
     
    167186         0,
    168187         8,
    169          false,
     188         FALSE,
    170189         0,
    171190         complain_overflow_bitfield,
    172191         bfd_elf_generic_reloc,
    173192         "R_MN10300_8",
    174          false,
     193         FALSE,
    175194         0xff,
    176195         0xff,
    177          false),
     196         FALSE),
    178197  /* Standard 32bit pc-relative reloc.  */
    179198  HOWTO (R_MN10300_PCREL32,
     
    181200         2,
    182201         32,
    183          true,
     202         TRUE,
    184203         0,
    185204         complain_overflow_bitfield,
    186205         bfd_elf_generic_reloc,
    187206         "R_MN10300_PCREL32",
    188          false,
     207         FALSE,
    189208         0xffffffff,
    190209         0xffffffff,
    191          true),
     210         TRUE),
    192211  /* Standard 16bit pc-relative reloc.  */
    193212  HOWTO (R_MN10300_PCREL16,
     
    195214         1,
    196215         16,
    197          true,
     216         TRUE,
    198217         0,
    199218         complain_overflow_bitfield,
    200219         bfd_elf_generic_reloc,
    201220         "R_MN10300_PCREL16",
    202          false,
     221         FALSE,
    203222         0xffff,
    204223         0xffff,
    205          true),
     224         TRUE),
    206225  /* Standard 8 pc-relative reloc.  */
    207226  HOWTO (R_MN10300_PCREL8,
     
    209228         0,
    210229         8,
    211          true,
     230         TRUE,
    212231         0,
    213232         complain_overflow_bitfield,
    214233         bfd_elf_generic_reloc,
    215234         "R_MN10300_PCREL8",
    216          false,
     235         FALSE,
    217236         0xff,
    218237         0xff,
    219          true),
     238         TRUE),
    220239
    221240  /* GNU extension to record C++ vtable hierarchy */
     
    224243         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    225244         0,                     /* bitsize */
    226          false,                 /* pc_relative */
     245         FALSE,                 /* pc_relative */
    227246         0,                     /* bitpos */
    228247         complain_overflow_dont, /* complain_on_overflow */
    229248         NULL,                  /* special_function */
    230249         "R_MN10300_GNU_VTINHERIT", /* name */
    231          false,                 /* partial_inplace */
     250         FALSE,                 /* partial_inplace */
    232251         0,                     /* src_mask */
    233252         0,                     /* dst_mask */
    234          false),                /* pcrel_offset */
     253         FALSE),                /* pcrel_offset */
    235254
    236255  /* GNU extension to record C++ vtable member usage */
     
    239258         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    240259         0,                     /* bitsize */
    241          false,                 /* pc_relative */
     260         FALSE,                 /* pc_relative */
    242261         0,                     /* bitpos */
    243262         complain_overflow_dont, /* complain_on_overflow */
    244263         NULL,                  /* special_function */
    245264         "R_MN10300_GNU_VTENTRY", /* name */
    246          false,                 /* partial_inplace */
     265         FALSE,                 /* partial_inplace */
    247266         0,                     /* src_mask */
    248267         0,                     /* dst_mask */
    249          false),                /* pcrel_offset */
     268         FALSE),                /* pcrel_offset */
    250269
    251270  /* Standard 24 bit reloc.  */
     
    254273         2,
    255274         24,
    256          false,
     275         FALSE,
    257276         0,
    258277         complain_overflow_bitfield,
    259278         bfd_elf_generic_reloc,
    260279         "R_MN10300_24",
    261          false,
     280         FALSE,
    262281         0xffffff,
    263282         0xffffff,
    264          false),
     283         FALSE),
    265284};
    266285
     
    307326     bfd *abfd ATTRIBUTE_UNUSED;
    308327     arelent *cache_ptr;
    309      Elf32_Internal_Rela *dst;
     328     Elf_Internal_Rela *dst;
    310329{
    311330  unsigned int r_type;
     
    320339   virtual table relocs for gc.  */
    321340
    322 static boolean
     341static bfd_boolean
    323342mn10300_elf_check_relocs (abfd, info, sec, relocs)
    324343     bfd *abfd;
     
    333352
    334353  if (info->relocateable)
    335     return true;
     354    return TRUE;
    336355
    337356  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     
    359378        case R_MN10300_GNU_VTINHERIT:
    360379          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    361             return false;
     380            return FALSE;
    362381          break;
    363382
     
    366385        case R_MN10300_GNU_VTENTRY:
    367386          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    368             return false;
     387            return FALSE;
    369388          break;
    370389        }
    371390    }
    372391
    373   return true;
     392  return TRUE;
    374393}
    375394
     
    378397
    379398static asection *
    380 mn10300_elf_gc_mark_hook (abfd, info, rel, h, sym)
    381      bfd *abfd;
     399mn10300_elf_gc_mark_hook (sec, info, rel, h, sym)
     400     asection *sec;
    382401     struct bfd_link_info *info ATTRIBUTE_UNUSED;
    383402     Elf_Internal_Rela *rel;
     
    409428    }
    410429  else
    411     {
    412       if (!(elf_bad_symtab (abfd)
    413             && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    414           && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    415                 && sym->st_shndx != SHN_COMMON))
    416         {
    417           return bfd_section_from_elf_index (abfd, sym->st_shndx);
    418         }
    419     }
     430    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
    420431
    421432  return NULL;
     
    525536
    526537/* Relocate an MN10300 ELF section.  */
    527 static boolean
     538static bfd_boolean
    528539mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    529540                              contents, relocs, local_syms, local_sections)
     
    541552  Elf_Internal_Rela *rel, *relend;
    542553
     554  if (info->relocateable)
     555    return TRUE;
     556
    543557  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
    544558  sym_hashes = (struct elf32_mn10300_link_hash_entry **)
     
    567581        continue;
    568582
    569       if (info->relocateable)
    570         {
    571           /* This is a relocateable link.  We don't have to change
    572              anything, unless the reloc is against a section symbol,
    573              in which case we have to adjust according to where the
    574              section symbol winds up in the output section.  */
    575           if (r_symndx < symtab_hdr->sh_info)
    576             {
    577               sym = local_syms + r_symndx;
    578               if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    579                 {
    580                   sec = local_sections[r_symndx];
    581                   rel->r_addend += sec->output_offset + sym->st_value;
    582                 }
    583             }
    584 
    585           continue;
    586         }
    587 
    588       /* This is a final link.  */
    589583      h = NULL;
    590584      sym = NULL;
     
    594588          sym = local_syms + r_symndx;
    595589          sec = local_sections[r_symndx];
    596           relocation = (sec->output_section->vma
    597                         + sec->output_offset
    598                         + sym->st_value);
     590          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
    599591        }
    600592      else
    601593        {
    602594          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    603           while (h->root.type == bfd_link_hash_indirect
    604                  || h->root.type == bfd_link_hash_warning)
     595          while (h->root.root.type == bfd_link_hash_indirect
     596                 || h->root.root.type == bfd_link_hash_warning)
    605597            h = (struct elf32_mn10300_link_hash_entry *) h->root.root.u.i.link;
    606598          if (h->root.root.type == bfd_link_hash_defined
     
    618610              if (! ((*info->callbacks->undefined_symbol)
    619611                     (info, h->root.root.root.string, input_bfd,
    620                       input_section, rel->r_offset, true)))
    621                 return false;
     612                      input_section, rel->r_offset, TRUE)))
     613                return FALSE;
    622614              relocation = 0;
    623615            }
     
    651643                     (info, name, howto->name, (bfd_vma) 0,
    652644                      input_bfd, input_section, rel->r_offset)))
    653                 return false;
     645                return FALSE;
    654646              break;
    655647
     
    657649              if (! ((*info->callbacks->undefined_symbol)
    658650                     (info, name, input_bfd, input_section,
    659                       rel->r_offset, true)))
    660                 return false;
     651                      rel->r_offset, TRUE)))
     652                return FALSE;
    661653              break;
    662654
     
    681673                    (info, msg, name, input_bfd, input_section,
    682674                     rel->r_offset)))
    683                 return false;
     675                return FALSE;
    684676              break;
    685677            }
     
    687679    }
    688680
    689   return true;
     681  return TRUE;
    690682}
    691683
    692684/* Finish initializing one hash table entry.  */
    693 static boolean
     685static bfd_boolean
    694686elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
    695687     struct bfd_hash_entry *gen_entry;
     
    701693  entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
    702694
     695  if (entry->root.root.type == bfd_link_hash_warning)
     696    entry = (struct elf32_mn10300_link_hash_entry *) entry->root.root.u.i.link;
     697
    703698  /* If we already know we want to convert "call" to "calls" for calls
    704699     to this symbol, then return now.  */
    705700  if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
    706     return true;
     701    return TRUE;
    707702
    708703  /* If there are no named calls to this symbol, or there's nothing we
     
    716711         instructions for calls to this symbol.  */
    717712      entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
    718       return true;
     713      return TRUE;
    719714    }
    720715
     
    739734
    740735  /* This routine never fails.  */
    741   return true;
     736  return TRUE;
    742737}
    743738
     
    781776        and somewhat more difficult to support.  */
    782777
    783 static boolean
     778static bfd_boolean
    784779mn10300_elf_relax_section (abfd, sec, link_info, again)
    785780     bfd *abfd;
    786781     asection *sec;
    787782     struct bfd_link_info *link_info;
    788      boolean *again;
     783     bfd_boolean *again;
    789784{
    790785  Elf_Internal_Shdr *symtab_hdr;
    791786  Elf_Internal_Rela *internal_relocs = NULL;
    792   Elf_Internal_Rela *free_relocs = NULL;
    793787  Elf_Internal_Rela *irel, *irelend;
    794788  bfd_byte *contents = NULL;
    795   bfd_byte *free_contents = NULL;
    796   Elf32_External_Sym *extsyms = NULL;
    797   Elf32_External_Sym *free_extsyms = NULL;
     789  Elf_Internal_Sym *isymbuf = NULL;
    798790  struct elf32_mn10300_link_hash_table *hash_table;
     791  asection *section = sec;
    799792
    800793  /* Assume nothing changes.  */
    801   *again = false;
     794  *again = FALSE;
    802795
    803796  /* We need a pointer to the mn10300 specific hash table.  */
     
    814807           input_bfd = input_bfd->link_next)
    815808        {
    816           asection *section;
    817 
    818809          /* We're going to need all the symbols for each bfd.  */
    819810          symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
    820 
    821           /* Get cached copy if it exists.  */
    822           if (symtab_hdr->contents != NULL)
    823             extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    824           else
     811          if (symtab_hdr->sh_info != 0)
    825812            {
    826               /* Go get them off disk.  */
    827               extsyms = ((Elf32_External_Sym *)
    828                          bfd_malloc (symtab_hdr->sh_size));
    829               if (extsyms == NULL)
    830                 goto error_return;
    831               free_extsyms = extsyms;
    832               if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    833                   || (bfd_read (extsyms, 1, symtab_hdr->sh_size, input_bfd)
    834                       != symtab_hdr->sh_size))
     813              isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     814              if (isymbuf == NULL)
     815                isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
     816                                                symtab_hdr->sh_info, 0,
     817                                                NULL, NULL, NULL);
     818              if (isymbuf == NULL)
    835819                goto error_return;
    836820            }
     
    847831              char *new_name;
    848832
     833              /* If there's nothing to do in this section, skip it.  */
     834              if (! (((section->flags & SEC_RELOC) != 0
     835                      && section->reloc_count != 0)
     836                     || (section->flags & SEC_CODE) != 0))
     837                continue;
     838
    849839              /* Get cached copy of section contents if it exists.  */
    850840              if (elf_section_data (section)->this_hdr.contents != NULL)
     
    856846                  if (contents == NULL)
    857847                    goto error_return;
    858                   free_contents = contents;
    859848
    860849                  if (!bfd_get_section_contents (input_bfd, section,
     
    864853                }
    865854              else
    866                 {
    867                   contents = NULL;
    868                   free_contents = NULL;
    869                 }
     855                contents = NULL;
    870856
    871857              /* If there aren't any relocs, then there's nothing to do.  */
     
    881867                  if (internal_relocs == NULL)
    882868                    goto error_return;
    883                   if (! link_info->keep_memory)
    884                     free_relocs = internal_relocs;
    885869
    886870                  /* Now examine each relocation.  */
     
    908892                        {
    909893                          /* A local symbol.  */
    910                           Elf_Internal_Sym isym;
    911 
    912                           bfd_elf32_swap_symbol_in (input_bfd,
    913                                                     extsyms + r_index, &isym);
    914 
    915                           if (isym.st_shndx == SHN_UNDEF)
     894                          Elf_Internal_Sym *isym;
     895                          struct elf_link_hash_table *elftab;
     896                          bfd_size_type amt;
     897
     898                          isym = isymbuf + r_index;
     899                          if (isym->st_shndx == SHN_UNDEF)
    916900                            sym_sec = bfd_und_section_ptr;
    917                           else if (isym.st_shndx > 0
    918                                    && isym.st_shndx < SHN_LORESERVE)
     901                          else if (isym->st_shndx == SHN_ABS)
     902                            sym_sec = bfd_abs_section_ptr;
     903                          else if (isym->st_shndx == SHN_COMMON)
     904                            sym_sec = bfd_com_section_ptr;
     905                          else
    919906                            sym_sec
    920907                              = bfd_section_from_elf_index (input_bfd,
    921                                                             isym.st_shndx);
    922                           else if (isym.st_shndx == SHN_ABS)
    923                             sym_sec = bfd_abs_section_ptr;
    924                           else if (isym.st_shndx == SHN_COMMON)
    925                             sym_sec = bfd_com_section_ptr;
    926 
    927                           sym_name = bfd_elf_string_from_elf_section (input_bfd,
    928                                                            symtab_hdr->sh_link,
    929                                                            isym.st_name);
     908                                                            isym->st_shndx);
     909
     910                          sym_name
     911                            = bfd_elf_string_from_elf_section (input_bfd,
     912                                                               (symtab_hdr
     913                                                                ->sh_link),
     914                                                               isym->st_name);
    930915
    931916                          /* If it isn't a function, then we don't care
    932917                             about it.  */
    933                           if (r_index < symtab_hdr->sh_info
    934                               && ELF_ST_TYPE (isym.st_info) != STT_FUNC)
     918                          if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
    935919                            continue;
    936920
    937921                          /* Tack on an ID so we can uniquely identify this
    938922                             local symbol in the global hash table.  */
    939                           new_name = bfd_malloc (strlen (sym_name) + 10);
     923                          amt = strlen (sym_name) + 10;
     924                          new_name = bfd_malloc (amt);
    940925                          if (new_name == 0)
    941926                            goto error_return;
     
    945930                          sym_name = new_name;
    946931
    947                           hash = (struct elf32_mn10300_link_hash_entry *)
    948                                    elf_link_hash_lookup (&hash_table->static_hash_table->root,
    949                                                          sym_name, true,
    950                                                          true, false);
     932                          elftab = &hash_table->static_hash_table->root;
     933                          hash = ((struct elf32_mn10300_link_hash_entry *)
     934                                  elf_link_hash_lookup (elftab, sym_name,
     935                                                        TRUE, TRUE, FALSE));
    951936                          free (new_name);
    952937                        }
     
    966951                        hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
    967952
    968                       /* If this is a jump/call, then bump the direct_calls
    969                          counter.  Else force "call" to "calls" conversions.  */
     953                      /* If this is a jump/call, then bump the
     954                         direct_calls counter.  Else force "call" to
     955                         "calls" conversions.  */
    970956                      if (r_type == R_MN10300_PCREL32
    971957                          || r_type == R_MN10300_PCREL16)
     
    981967              if ((section->flags & SEC_CODE) != 0)
    982968                {
    983 
    984                   Elf32_External_Sym *esym, *esymend;
    985                   int idx, shndx;
    986 
    987                   shndx = _bfd_elf_section_from_bfd_section (input_bfd,
    988                                                              section);
     969                  Elf_Internal_Sym *isym, *isymend;
     970                  unsigned int sec_shndx;
     971                  struct elf_link_hash_entry **hashes;
     972                  struct elf_link_hash_entry **end_hashes;
     973                  unsigned int symcount;
     974
     975                  sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
     976                                                                 section);
    989977
    990978                  /* Look at each function defined in this section and
    991979                     update info for that function.  */
    992                   esym = extsyms;
    993                   esymend = esym + symtab_hdr->sh_info;
    994                   for (; esym < esymend; esym++)
     980                  isymend = isymbuf + symtab_hdr->sh_info;
     981                  for (isym = isymbuf; isym < isymend; isym++)
    995982                    {
    996                       Elf_Internal_Sym isym;
    997 
    998                       bfd_elf32_swap_symbol_in (input_bfd, esym, &isym);
    999                       if (isym.st_shndx == shndx
    1000                           && ELF_ST_TYPE (isym.st_info) == STT_FUNC)
     983                      if (isym->st_shndx == sec_shndx
     984                          && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
    1001985                        {
    1002                           if (isym.st_shndx == SHN_UNDEF)
     986                          struct elf_link_hash_table *elftab;
     987                          bfd_size_type amt;
     988
     989                          if (isym->st_shndx == SHN_UNDEF)
    1003990                            sym_sec = bfd_und_section_ptr;
    1004                           else if (isym.st_shndx > 0
    1005                                    && isym.st_shndx < SHN_LORESERVE)
     991                          else if (isym->st_shndx == SHN_ABS)
     992                            sym_sec = bfd_abs_section_ptr;
     993                          else if (isym->st_shndx == SHN_COMMON)
     994                            sym_sec = bfd_com_section_ptr;
     995                          else
    1006996                            sym_sec
    1007997                              = bfd_section_from_elf_index (input_bfd,
    1008                                                             isym.st_shndx);
    1009                           else if (isym.st_shndx == SHN_ABS)
    1010                             sym_sec = bfd_abs_section_ptr;
    1011                           else if (isym.st_shndx == SHN_COMMON)
    1012                             sym_sec = bfd_com_section_ptr;
    1013 
    1014                           sym_name = bfd_elf_string_from_elf_section (input_bfd,
    1015                                                         symtab_hdr->sh_link,
    1016                                                         isym.st_name);
     998                                                            isym->st_shndx);
     999
     1000                          sym_name = (bfd_elf_string_from_elf_section
     1001                                      (input_bfd, symtab_hdr->sh_link,
     1002                                       isym->st_name));
    10171003
    10181004                          /* Tack on an ID so we can uniquely identify this
    10191005                             local symbol in the global hash table.  */
    1020                           new_name = bfd_malloc (strlen (sym_name) + 10);
     1006                          amt = strlen (sym_name) + 10;
     1007                          new_name = bfd_malloc (amt);
    10211008                          if (new_name == 0)
    10221009                            goto error_return;
     
    10261013                          sym_name = new_name;
    10271014
    1028                           hash = (struct elf32_mn10300_link_hash_entry *)
    1029                                     elf_link_hash_lookup (&hash_table->static_hash_table->root,
    1030                                                           sym_name, true,
    1031                                                           true, false);
     1015                          elftab = &hash_table->static_hash_table->root;
     1016                          hash = ((struct elf32_mn10300_link_hash_entry *)
     1017                                  elf_link_hash_lookup (elftab, sym_name,
     1018                                                        TRUE, TRUE, FALSE));
    10321019                          free (new_name);
    10331020                          compute_function_info (input_bfd, hash,
    1034                                                  isym.st_value, contents);
     1021                                                 isym->st_value, contents);
    10351022                        }
    10361023                    }
    10371024
    1038                   esym = extsyms + symtab_hdr->sh_info;
    1039                   esymend = extsyms + (symtab_hdr->sh_size
    1040                                        / sizeof (Elf32_External_Sym));
    1041                   for (idx = 0; esym < esymend; esym++, idx++)
     1025                  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     1026                              - symtab_hdr->sh_info);
     1027                  hashes = elf_sym_hashes (abfd);
     1028                  end_hashes = hashes + symcount;
     1029                  for (; hashes < end_hashes; hashes++)
    10421030                    {
    1043                       Elf_Internal_Sym isym;
    1044 
    1045                       bfd_elf32_swap_symbol_in (input_bfd, esym, &isym);
    1046                       hash = (struct elf32_mn10300_link_hash_entry *)
    1047                                elf_sym_hashes (input_bfd)[idx];
    1048                       if (isym.st_shndx == shndx
    1049                           && ELF_ST_TYPE (isym.st_info) == STT_FUNC
    1050                           && (hash)->root.root.u.def.section == section
    1051                           && ((hash)->root.root.type == bfd_link_hash_defined
    1052                               || (hash)->root.root.type == bfd_link_hash_defweak))
     1031                      hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
     1032                      if ((hash->root.root.type == bfd_link_hash_defined
     1033                           || hash->root.root.type == bfd_link_hash_defweak)
     1034                          && hash->root.root.u.def.section == section
     1035                          && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
    10531036                        compute_function_info (input_bfd, hash,
    10541037                                               (hash)->root.root.u.def.value,
     
    10581041
    10591042              /* Cache or free any memory we allocated for the relocs.  */
    1060               if (free_relocs != NULL)
    1061                 {
    1062                   free (free_relocs);
    1063                   free_relocs = NULL;
    1064                 }
     1043              if (internal_relocs != NULL
     1044                  && elf_section_data (section)->relocs != internal_relocs)
     1045                free (internal_relocs);
     1046              internal_relocs = NULL;
    10651047
    10661048              /* Cache or free any memory we allocated for the contents.  */
    1067               if (free_contents != NULL)
     1049              if (contents != NULL
     1050                  && elf_section_data (section)->this_hdr.contents != contents)
    10681051                {
    10691052                  if (! link_info->keep_memory)
    1070                     free (free_contents);
     1053                    free (contents);
    10711054                  else
    10721055                    {
     
    10741057                      elf_section_data (section)->this_hdr.contents = contents;
    10751058                    }
    1076                   free_contents = NULL;
    10771059                }
     1060              contents = NULL;
    10781061            }
    10791062
    10801063          /* Cache or free any memory we allocated for the symbols.  */
    1081           if (free_extsyms != NULL)
     1064          if (isymbuf != NULL
     1065              && symtab_hdr->contents != (unsigned char *) isymbuf)
    10821066            {
    10831067              if (! link_info->keep_memory)
    1084                 free (free_extsyms);
     1068                free (isymbuf);
    10851069              else
    10861070                {
    10871071                  /* Cache the symbols for elf_link_input_bfd.  */
    1088                   symtab_hdr->contents = extsyms;
     1072                  symtab_hdr->contents = (unsigned char *) isymbuf;
    10891073                }
    1090               free_extsyms = NULL;
    10911074            }
     1075          isymbuf = NULL;
    10921076        }
    10931077
     
    11121096           input_bfd = input_bfd->link_next)
    11131097        {
    1114           asection *section;
    1115 
    1116           /* We're going to need all the symbols for each bfd.  */
     1098          /* We're going to need all the local symbols for each bfd.  */
    11171099          symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
    1118 
    1119           /* Get cached copy if it exists.  */
    1120           if (symtab_hdr->contents != NULL)
    1121             extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    1122           else
     1100          if (symtab_hdr->sh_info != 0)
    11231101            {
    1124               /* Go get them off disk.  */
    1125               extsyms = ((Elf32_External_Sym *)
    1126                          bfd_malloc (symtab_hdr->sh_size));
    1127               if (extsyms == NULL)
    1128                 goto error_return;
    1129               free_extsyms = extsyms;
    1130               if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    1131                   || (bfd_read (extsyms, 1, symtab_hdr->sh_size, input_bfd)
    1132                       != symtab_hdr->sh_size))
     1102              isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     1103              if (isymbuf == NULL)
     1104                isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
     1105                                                symtab_hdr->sh_info, 0,
     1106                                                NULL, NULL, NULL);
     1107              if (isymbuf == NULL)
    11331108                goto error_return;
    11341109            }
     
    11391114               section = section->next)
    11401115            {
    1141               int shndx;
    1142               Elf32_External_Sym *esym, *esymend;
    1143               int idx;
     1116              unsigned int sec_shndx;
     1117              Elf_Internal_Sym *isym, *isymend;
     1118              struct elf_link_hash_entry **hashes;
     1119              struct elf_link_hash_entry **end_hashes;
     1120              unsigned int symcount;
    11441121
    11451122              /* Skip non-code sections and empty sections.  */
     
    11561133                  if (internal_relocs == NULL)
    11571134                    goto error_return;
    1158                   if (! link_info->keep_memory)
    1159                     free_relocs = internal_relocs;
    11601135                }
    11611136
     
    11691144                  if (contents == NULL)
    11701145                    goto error_return;
    1171                   free_contents = contents;
    11721146
    11731147                  if (!bfd_get_section_contents (input_bfd, section,
     
    11771151                }
    11781152
    1179               shndx = _bfd_elf_section_from_bfd_section (input_bfd, section);
     1153              sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
     1154                                                             section);
    11801155
    11811156              /* Now look for any function in this section which needs
    11821157                 insns deleted from its prologue.  */
    1183               esym = extsyms;
    1184               esymend = esym + symtab_hdr->sh_info;
    1185               for (; esym < esymend; esym++)
     1158              isymend = isymbuf + symtab_hdr->sh_info;
     1159              for (isym = isymbuf; isym < isymend; isym++)
    11861160                {
    1187                   Elf_Internal_Sym isym;
    11881161                  struct elf32_mn10300_link_hash_entry *sym_hash;
    11891162                  asection *sym_sec = NULL;
    11901163                  const char *sym_name;
    11911164                  char *new_name;
    1192 
    1193                   bfd_elf32_swap_symbol_in (input_bfd, esym, &isym);
    1194 
    1195                   if (isym.st_shndx != shndx)
     1165                  struct elf_link_hash_table *elftab;
     1166                  bfd_size_type amt;
     1167
     1168                  if (isym->st_shndx != sec_shndx)
    11961169                    continue;
    11971170
    1198                   if (isym.st_shndx == SHN_UNDEF)
     1171                  if (isym->st_shndx == SHN_UNDEF)
    11991172                    sym_sec = bfd_und_section_ptr;
    1200                   else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE)
    1201                     sym_sec
    1202                       = bfd_section_from_elf_index (input_bfd, isym.st_shndx);
    1203                   else if (isym.st_shndx == SHN_ABS)
     1173                  else if (isym->st_shndx == SHN_ABS)
    12041174                    sym_sec = bfd_abs_section_ptr;
    1205                   else if (isym.st_shndx == SHN_COMMON)
     1175                  else if (isym->st_shndx == SHN_COMMON)
    12061176                    sym_sec = bfd_com_section_ptr;
    12071177                  else
    1208                     abort ();
    1209 
    1210                   sym_name = bfd_elf_string_from_elf_section (input_bfd,
    1211                                                         symtab_hdr->sh_link,
    1212                                                         isym.st_name);
     1178                    sym_sec
     1179                      = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
     1180
     1181                  sym_name
     1182                    = bfd_elf_string_from_elf_section (input_bfd,
     1183                                                       symtab_hdr->sh_link,
     1184                                                       isym->st_name);
    12131185
    12141186                  /* Tack on an ID so we can uniquely identify this
    12151187                     local symbol in the global hash table.  */
    1216                   new_name = bfd_malloc (strlen (sym_name) + 10);
     1188                  amt = strlen (sym_name) + 10;
     1189                  new_name = bfd_malloc (amt);
    12171190                  if (new_name == 0)
    12181191                    goto error_return;
     
    12201193                  sym_name = new_name;
    12211194
    1222                   sym_hash = (struct elf32_mn10300_link_hash_entry *)
    1223                             elf_link_hash_lookup (&hash_table->static_hash_table->root,
    1224                                                   sym_name, false,
    1225                                                   false, false);
     1195                  elftab = &hash_table->static_hash_table->root;
     1196                  sym_hash = ((struct elf32_mn10300_link_hash_entry *)
     1197                              elf_link_hash_lookup (elftab, sym_name,
     1198                                                    FALSE, FALSE, FALSE));
    12261199
    12271200                  free (new_name);
     
    12291202                    continue;
    12301203
    1231                   if (! ((sym_hash)->flags & MN10300_CONVERT_CALL_TO_CALLS)
    1232                       && ! ((sym_hash)->flags & MN10300_DELETED_PROLOGUE_BYTES))
     1204                  if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
     1205                      && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
    12331206                    {
    12341207                      int bytes = 0;
     
    12361209                      /* Note that we've changed things.  */
    12371210                      elf_section_data (section)->relocs = internal_relocs;
    1238                       free_relocs = NULL;
    1239 
    12401211                      elf_section_data (section)->this_hdr.contents = contents;
    1241                       free_contents = NULL;
    1242 
    1243                       symtab_hdr->contents = (bfd_byte *) extsyms;
    1244                       free_extsyms = NULL;
     1212                      symtab_hdr->contents = (unsigned char *) isymbuf;
    12451213
    12461214                      /* Count how many bytes we're going to delete.  */
     
    12611229                      if (!mn10300_elf_relax_delete_bytes (input_bfd,
    12621230                                                           section,
    1263                                                            isym.st_value,
     1231                                                           isym->st_value,
    12641232                                                           bytes))
    12651233                        goto error_return;
     
    12671235                      /* Something changed.  Not strictly necessary, but
    12681236                         may lead to more relaxing opportunities.  */
    1269                       *again = true;
     1237                      *again = TRUE;
    12701238                    }
    12711239                }
     
    12731241              /* Look for any global functions in this section which
    12741242                 need insns deleted from their prologues.  */
    1275               esym = extsyms + symtab_hdr->sh_info;
    1276               esymend = extsyms + (symtab_hdr->sh_size
    1277                                    / sizeof (Elf32_External_Sym));
    1278               for (idx = 0; esym < esymend; esym++, idx++)
     1243              symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     1244                          - symtab_hdr->sh_info);
     1245              hashes = elf_sym_hashes (abfd);
     1246              end_hashes = hashes + symcount;
     1247              for (; hashes < end_hashes; hashes++)
    12791248                {
    1280                   Elf_Internal_Sym isym;
    12811249                  struct elf32_mn10300_link_hash_entry *sym_hash;
    12821250
    1283                   bfd_elf32_swap_symbol_in (input_bfd, esym, &isym);
    1284                   sym_hash = (struct elf32_mn10300_link_hash_entry *)
    1285                                (elf_sym_hashes (input_bfd)[idx]);
    1286                   if (isym.st_shndx == shndx
    1287                       && (sym_hash)->root.root.u.def.section == section
    1288                       && ! ((sym_hash)->flags & MN10300_CONVERT_CALL_TO_CALLS)
    1289                       && ! ((sym_hash)->flags & MN10300_DELETED_PROLOGUE_BYTES))
     1251                  sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
     1252                  if ((sym_hash->root.root.type == bfd_link_hash_defined
     1253                       || sym_hash->root.root.type == bfd_link_hash_defweak)
     1254                      && sym_hash->root.root.u.def.section == section
     1255                      && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
     1256                      && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
    12901257                    {
    12911258                      int bytes = 0;
     1259                      bfd_vma symval;
    12921260
    12931261                      /* Note that we've changed things.  */
    12941262                      elf_section_data (section)->relocs = internal_relocs;
    1295                       free_relocs = NULL;
    1296 
    12971263                      elf_section_data (section)->this_hdr.contents = contents;
    1298                       free_contents = NULL;
    1299 
    1300                       symtab_hdr->contents = (bfd_byte *) extsyms;
    1301                       free_extsyms = NULL;
     1264                      symtab_hdr->contents = (unsigned char *) isymbuf;
    13021265
    13031266                      /* Count how many bytes we're going to delete.  */
     
    13161279
    13171280                      /* Actually delete the bytes.  */
     1281                      symval = sym_hash->root.root.u.def.value;
    13181282                      if (!mn10300_elf_relax_delete_bytes (input_bfd,
    13191283                                                           section,
    1320                                                            (sym_hash)->root.root.u.def.value,
     1284                                                           symval,
    13211285                                                           bytes))
    13221286                        goto error_return;
     
    13241288                      /* Something changed.  Not strictly necessary, but
    13251289                         may lead to more relaxing opportunities.  */
    1326                       *again = true;
     1290                      *again = TRUE;
    13271291                    }
    13281292                }
    13291293
    13301294              /* Cache or free any memory we allocated for the relocs.  */
    1331               if (free_relocs != NULL)
    1332                 {
    1333                   free (free_relocs);
    1334                   free_relocs = NULL;
    1335                 }
     1295              if (internal_relocs != NULL
     1296                  && elf_section_data (section)->relocs != internal_relocs)
     1297                free (internal_relocs);
     1298              internal_relocs = NULL;
    13361299
    13371300              /* Cache or free any memory we allocated for the contents.  */
    1338               if (free_contents != NULL)
     1301              if (contents != NULL
     1302                  && elf_section_data (section)->this_hdr.contents != contents)
    13391303                {
    13401304                  if (! link_info->keep_memory)
    1341                     free (free_contents);
     1305                    free (contents);
    13421306                  else
    13431307                    {
     
    13451309                      elf_section_data (section)->this_hdr.contents = contents;
    13461310                    }
    1347                   free_contents = NULL;
    13481311                }
     1312              contents = NULL;
    13491313            }
    13501314
    13511315          /* Cache or free any memory we allocated for the symbols.  */
    1352           if (free_extsyms != NULL)
     1316          if (isymbuf != NULL
     1317              && symtab_hdr->contents != (unsigned char *) isymbuf)
    13531318            {
    13541319              if (! link_info->keep_memory)
    1355                 free (free_extsyms);
     1320                free (isymbuf);
    13561321              else
    13571322                {
    13581323                  /* Cache the symbols for elf_link_input_bfd.  */
    1359                   symtab_hdr->contents = extsyms;
     1324                  symtab_hdr->contents = (unsigned char *) isymbuf;
    13601325                }
    1361               free_extsyms = NULL;
    13621326            }
     1327          isymbuf = NULL;
    13631328        }
    13641329    }
     
    13661331  /* (Re)initialize for the basic instruction shortening/relaxing pass.  */
    13671332  contents = NULL;
    1368   extsyms = NULL;
    13691333  internal_relocs = NULL;
    1370   free_relocs = NULL;
    1371   free_contents = NULL;
    1372   free_extsyms = NULL;
     1334  isymbuf = NULL;
     1335  /* For error_return.  */
     1336  section = sec;
    13731337
    13741338  /* We don't have to do anything for a relocateable link, if
     
    13791343      || sec->reloc_count == 0
    13801344      || (sec->flags & SEC_CODE) == 0)
    1381     return true;
     1345    return TRUE;
    13821346
    13831347  /* If this is the first time we have been called for this section,
     
    13941358  if (internal_relocs == NULL)
    13951359    goto error_return;
    1396   if (! link_info->keep_memory)
    1397     free_relocs = internal_relocs;
    13981360
    13991361  /* Walk through them looking for relaxing opportunities.  */
     
    14231385              if (contents == NULL)
    14241386                goto error_return;
    1425               free_contents = contents;
    14261387
    14271388              if (! bfd_get_section_contents (abfd, sec, contents,
     
    14321393
    14331394      /* Read this BFD's symbols if we haven't done so already.  */
    1434       if (extsyms == NULL)
     1395      if (isymbuf == NULL && symtab_hdr->sh_info != 0)
    14351396        {
    1436           /* Get cached copy if it exists.  */
    1437           if (symtab_hdr->contents != NULL)
    1438             extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    1439           else
    1440             {
    1441               /* Go get them off disk.  */
    1442               extsyms = ((Elf32_External_Sym *)
    1443                          bfd_malloc (symtab_hdr->sh_size));
    1444               if (extsyms == NULL)
    1445                 goto error_return;
    1446               free_extsyms = extsyms;
    1447               if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    1448                   || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
    1449                       != symtab_hdr->sh_size))
    1450                 goto error_return;
    1451             }
     1397          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     1398          if (isymbuf == NULL)
     1399            isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
     1400                                            symtab_hdr->sh_info, 0,
     1401                                            NULL, NULL, NULL);
     1402          if (isymbuf == NULL)
     1403            goto error_return;
    14521404        }
    14531405
     
    14551407      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
    14561408        {
    1457           Elf_Internal_Sym isym;
     1409          Elf_Internal_Sym *isym;
    14581410          asection *sym_sec = NULL;
    14591411          const char *sym_name;
     
    14611413
    14621414          /* A local symbol.  */
    1463           bfd_elf32_swap_symbol_in (abfd,
    1464                                     extsyms + ELF32_R_SYM (irel->r_info),
    1465                                     &isym);
    1466 
    1467           if (isym.st_shndx == SHN_UNDEF)
     1415          isym = isymbuf + ELF32_R_SYM (irel->r_info);
     1416          if (isym->st_shndx == SHN_UNDEF)
    14681417            sym_sec = bfd_und_section_ptr;
    1469           else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE)
    1470             sym_sec = bfd_section_from_elf_index (abfd, isym.st_shndx);
    1471           else if (isym.st_shndx == SHN_ABS)
     1418          else if (isym->st_shndx == SHN_ABS)
    14721419            sym_sec = bfd_abs_section_ptr;
    1473           else if (isym.st_shndx == SHN_COMMON)
     1420          else if (isym->st_shndx == SHN_COMMON)
    14741421            sym_sec = bfd_com_section_ptr;
    14751422          else
    1476             abort ();
    1477 
    1478           symval = (isym.st_value
     1423            sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
     1424
     1425          symval = (isym->st_value
    14791426                    + sym_sec->output_section->vma
    14801427                    + sym_sec->output_offset);
    14811428          sym_name = bfd_elf_string_from_elf_section (abfd,
    14821429                                                      symtab_hdr->sh_link,
    1483                                                       isym.st_name);
     1430                                                      isym->st_name);
    14841431
    14851432          /* Tack on an ID so we can uniquely identify this
    14861433             local symbol in the global hash table.  */
    1487           new_name = bfd_malloc (strlen (sym_name) + 10);
     1434          new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
    14881435          if (new_name == 0)
    14891436            goto error_return;
     
    14931440          h = (struct elf32_mn10300_link_hash_entry *)
    14941441                elf_link_hash_lookup (&hash_table->static_hash_table->root,
    1495                                       sym_name, false, false, false);
     1442                                      sym_name, FALSE, FALSE, FALSE);
    14961443          free (new_name);
    14971444        }
     
    15491496                     etc.  */
    15501497                  elf_section_data (sec)->relocs = internal_relocs;
    1551                   free_relocs = NULL;
    1552 
    15531498                  elf_section_data (sec)->this_hdr.contents = contents;
    1554                   free_contents = NULL;
    1555 
    1556                   symtab_hdr->contents = (bfd_byte *) extsyms;
    1557                   free_extsyms = NULL;
     1499                  symtab_hdr->contents = (unsigned char *) isymbuf;
    15581500
    15591501                  /* Fix the opcode.  */
     
    15721514                  /* That will change things, so, we should relax again.
    15731515                     Note that this is not required, and it may be slow.  */
    1574                   *again = true;
     1516                  *again = TRUE;
    15751517                }
    15761518            }
     
    16141556              /* Note that we've changed the relocs, section contents, etc.  */
    16151557              elf_section_data (sec)->relocs = internal_relocs;
    1616               free_relocs = NULL;
    1617 
    16181558              elf_section_data (sec)->this_hdr.contents = contents;
    1619               free_contents = NULL;
    1620 
    1621               symtab_hdr->contents = (bfd_byte *) extsyms;
    1622               free_extsyms = NULL;
     1559              symtab_hdr->contents = (unsigned char *) isymbuf;
    16231560
    16241561              /* Fix the opcode.  */
     
    16411578              /* That will change things, so, we should relax again.
    16421579                 Note that this is not required, and it may be slow.  */
    1643               *again = true;
     1580              *again = TRUE;
    16441581            }
    16451582        }
     
    16661603                     etc.  */
    16671604                  elf_section_data (sec)->relocs = internal_relocs;
    1668                   free_relocs = NULL;
    1669 
    16701605                  elf_section_data (sec)->this_hdr.contents = contents;
    1671                   free_contents = NULL;
    1672 
    1673                   symtab_hdr->contents = (bfd_byte *) extsyms;
    1674                   free_extsyms = NULL;
     1606                  symtab_hdr->contents = (unsigned char *) isymbuf;
    16751607
    16761608                  /* Fix the opcode.  */
     
    16891621                  /* That will change things, so, we should relax again.
    16901622                     Note that this is not required, and it may be slow.  */
    1691                   *again = true;
     1623                  *again = TRUE;
    16921624                }
    16931625            }
     
    17291661              /* Note that we've changed the relocs, section contents, etc.  */
    17301662              elf_section_data (sec)->relocs = internal_relocs;
    1731               free_relocs = NULL;
    1732 
    17331663              elf_section_data (sec)->this_hdr.contents = contents;
    1734               free_contents = NULL;
    1735 
    1736               symtab_hdr->contents = (bfd_byte *) extsyms;
    1737               free_extsyms = NULL;
     1664              symtab_hdr->contents = (unsigned char *) isymbuf;
    17381665
    17391666              /* Fix the opcode.  */
     
    17511678              /* That will change things, so, we should relax again.
    17521679                 Note that this is not required, and it may be slow.  */
    1753               *again = true;
     1680              *again = TRUE;
    17541681            }
    17551682        }
     
    18191746          /* We also have to be sure there is no symbol/label
    18201747             at the unconditional branch.  */
    1821           if (mn10300_elf_symbol_address_p (abfd, sec, extsyms,
     1748          if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
    18221749                                            irel->r_offset + 1))
    18231750            continue;
     
    18251752          /* Note that we've changed the relocs, section contents, etc.  */
    18261753          elf_section_data (sec)->relocs = internal_relocs;
    1827           free_relocs = NULL;
    1828 
    18291754          elf_section_data (sec)->this_hdr.contents = contents;
    1830           free_contents = NULL;
    1831 
    1832           symtab_hdr->contents = (bfd_byte *) extsyms;
    1833           free_extsyms = NULL;
     1755          symtab_hdr->contents = (unsigned char *) isymbuf;
    18341756
    18351757          /* Reverse the condition of the first branch.  */
     
    18961818          /* That will change things, so, we should relax again.
    18971819             Note that this is not required, and it may be slow.  */
    1898           *again = true;
     1820          *again = TRUE;
    18991821        }
    19001822
     
    19391861                             etc.  */
    19401862                          elf_section_data (sec)->relocs = internal_relocs;
    1941                           free_relocs = NULL;
    1942 
    19431863                          elf_section_data (sec)->this_hdr.contents = contents;
    1944                           free_contents = NULL;
    1945 
    1946                           symtab_hdr->contents = (bfd_byte *) extsyms;
    1947                           free_extsyms = NULL;
     1864                          symtab_hdr->contents = (unsigned char *) isymbuf;
    19481865
    19491866                          /* Fix the opcode.  */
     
    19641881                             again.  Note that this is not required, and it
    19651882                             may be slow.  */
    1966                           *again = true;
     1883                          *again = TRUE;
    19671884                          break;
    19681885                        }
     
    20151932                             etc.  */
    20161933                          elf_section_data (sec)->relocs = internal_relocs;
    2017                           free_relocs = NULL;
    2018 
    20191934                          elf_section_data (sec)->this_hdr.contents = contents;
    2020                           free_contents = NULL;
    2021 
    2022                           symtab_hdr->contents = (bfd_byte *) extsyms;
    2023                           free_extsyms = NULL;
     1935                          symtab_hdr->contents = (unsigned char *) isymbuf;
    20241936
    20251937                          /* Fix the opcode.  */
     
    20401952                             again.  Note that this is not required, and it
    20411953                             may be slow.  */
    2042                           *again = true;
     1954                          *again = TRUE;
    20431955                          break;
    20441956                        }
     
    20992011                    /* Note that we've changed the relocation contents, etc.  */
    21002012                    elf_section_data (sec)->relocs = internal_relocs;
    2101                     free_relocs = NULL;
    2102 
    21032013                    elf_section_data (sec)->this_hdr.contents = contents;
    2104                     free_contents = NULL;
    2105 
    2106                     symtab_hdr->contents = (bfd_byte *) extsyms;
    2107                     free_extsyms = NULL;
     2014                    symtab_hdr->contents = (unsigned char *) isymbuf;
    21082015
    21092016                    /* Fix the opcode.  */
     
    21222029                    /* That will change things, so, we should relax again.
    21232030                       Note that this is not required, and it may be slow.  */
    2124                     *again = true;
     2031                    *again = TRUE;
    21252032                    break;
    21262033                  }
     
    21372044                    /* Note that we've changed the relocation contents, etc.  */
    21382045                    elf_section_data (sec)->relocs = internal_relocs;
    2139                     free_relocs = NULL;
    2140 
    21412046                    elf_section_data (sec)->this_hdr.contents = contents;
    2142                     free_contents = NULL;
    2143 
    2144                     symtab_hdr->contents = (bfd_byte *) extsyms;
    2145                     free_extsyms = NULL;
     2047                    symtab_hdr->contents = (unsigned char *) isymbuf;
    21462048
    21472049                    if ((code & 0xf3) == 0x81)
     
    21722074                    /* That will change things, so, we should relax again.
    21732075                       Note that this is not required, and it may be slow.  */
    2174                     *again = true;
     2076                    *again = TRUE;
    21752077                    break;
    21762078
     
    21922094                    /* Note that we've changed the relocation contents, etc.  */
    21932095                    elf_section_data (sec)->relocs = internal_relocs;
    2194                     free_relocs = NULL;
    2195 
    21962096                    elf_section_data (sec)->this_hdr.contents = contents;
    2197                     free_contents = NULL;
    2198 
    2199                     symtab_hdr->contents = (bfd_byte *) extsyms;
    2200                     free_extsyms = NULL;
     2097                    symtab_hdr->contents = (unsigned char *) isymbuf;
    22012098
    22022099                    /* Fix the opcode.  */
     
    22152112                    /* That will change things, so, we should relax again.
    22162113                       Note that this is not required, and it may be slow.  */
    2217                     *again = true;
     2114                    *again = TRUE;
    22182115                    break;
    22192116                  }
     
    22452142                    /* Note that we've changed the relocation contents, etc.  */
    22462143                    elf_section_data (sec)->relocs = internal_relocs;
    2247                     free_relocs = NULL;
    2248 
    22492144                    elf_section_data (sec)->this_hdr.contents = contents;
    2250                     free_contents = NULL;
    2251 
    2252                     symtab_hdr->contents = (bfd_byte *) extsyms;
    2253                     free_extsyms = NULL;
     2145                    symtab_hdr->contents = (unsigned char *) isymbuf;
    22542146
    22552147                    if ((code & 0xfc) == 0xcc)
     
    22842176                    /* That will change things, so, we should relax again.
    22852177                       Note that this is not required, and it may be slow.  */
    2286                     *again = true;
     2178                    *again = TRUE;
    22872179                    break;
    22882180
     
    23272219                    /* Note that we've changed the relocation contents, etc.  */
    23282220                    elf_section_data (sec)->relocs = internal_relocs;
    2329                     free_relocs = NULL;
    2330 
    23312221                    elf_section_data (sec)->this_hdr.contents = contents;
    2332                     free_contents = NULL;
    2333 
    2334                     symtab_hdr->contents = (bfd_byte *) extsyms;
    2335                     free_extsyms = NULL;
     2222                    symtab_hdr->contents = (unsigned char *) isymbuf;
    23362223
    23372224                    /* Fix the opcode.  */
     
    23502237                    /* That will change things, so, we should relax again.
    23512238                       Note that this is not required, and it may be slow.  */
    2352                     *again = true;
     2239                    *again = TRUE;
    23532240                    break;
    23542241                  }
     
    23592246                  /* Note that we've changed the relocation contents, etc.  */
    23602247                  elf_section_data (sec)->relocs = internal_relocs;
    2361                   free_relocs = NULL;
    2362 
    23632248                  elf_section_data (sec)->this_hdr.contents = contents;
    2364                   free_contents = NULL;
    2365 
    2366                   symtab_hdr->contents = (bfd_byte *) extsyms;
    2367                   free_extsyms = NULL;
     2249                  symtab_hdr->contents = (unsigned char *) isymbuf;
    23682250
    23692251                  /* Fix the opcode.  */
     
    23822264                  /* That will change things, so, we should relax again.
    23832265                     Note that this is not required, and it may be slow.  */
    2384                   *again = true;
     2266                  *again = TRUE;
    23852267                  break;
    23862268                }
     
    23892271    }
    23902272
    2391   if (free_relocs != NULL)
    2392     {
    2393       free (free_relocs);
    2394       free_relocs = NULL;
    2395     }
    2396 
    2397   if (free_contents != NULL)
     2273  if (isymbuf != NULL
     2274      && symtab_hdr->contents != (unsigned char *) isymbuf)
    23982275    {
    23992276      if (! link_info->keep_memory)
    2400         free (free_contents);
     2277        free (isymbuf);
     2278      else
     2279        {
     2280          /* Cache the symbols for elf_link_input_bfd.  */
     2281          symtab_hdr->contents = (unsigned char *) isymbuf;
     2282        }
     2283    }
     2284
     2285  if (contents != NULL
     2286      && elf_section_data (sec)->this_hdr.contents != contents)
     2287    {
     2288      if (! link_info->keep_memory)
     2289        free (contents);
    24012290      else
    24022291        {
     
    24042293          elf_section_data (sec)->this_hdr.contents = contents;
    24052294        }
    2406       free_contents = NULL;
    24072295    }
    24082296
    2409   if (free_extsyms != NULL)
    2410     {
    2411       if (! link_info->keep_memory)
    2412         free (free_extsyms);
    2413       else
    2414         {
    2415           /* Cache the symbols for elf_link_input_bfd.  */
    2416           symtab_hdr->contents = extsyms;
    2417         }
    2418       free_extsyms = NULL;
    2419     }
    2420 
    2421   return true;
     2297  if (internal_relocs != NULL
     2298      && elf_section_data (sec)->relocs != internal_relocs)
     2299    free (internal_relocs);
     2300
     2301  return TRUE;
    24222302
    24232303 error_return:
    2424   if (free_relocs != NULL)
    2425     free (free_relocs);
    2426   if (free_contents != NULL)
    2427     free (free_contents);
    2428   if (free_extsyms != NULL)
    2429     free (free_extsyms);
    2430   return false;
     2304  if (isymbuf != NULL
     2305      && symtab_hdr->contents != (unsigned char *) isymbuf)
     2306    free (isymbuf);
     2307  if (contents != NULL
     2308      && elf_section_data (section)->this_hdr.contents != contents)
     2309    free (contents);
     2310  if (internal_relocs != NULL
     2311      && elf_section_data (section)->relocs != internal_relocs)
     2312    free (internal_relocs);
     2313
     2314  return FALSE;
    24312315}
    24322316
     
    25332417/* Delete some bytes from a section while relaxing.  */
    25342418
    2535 static boolean
     2419static bfd_boolean
    25362420mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
    25372421     bfd *abfd;
     
    25412425{
    25422426  Elf_Internal_Shdr *symtab_hdr;
    2543   Elf32_External_Sym *extsyms;
    2544   int shndx, index;
     2427  unsigned int sec_shndx;
    25452428  bfd_byte *contents;
    25462429  Elf_Internal_Rela *irel, *irelend;
    25472430  Elf_Internal_Rela *irelalign;
    25482431  bfd_vma toaddr;
    2549   Elf32_External_Sym *esym, *esymend;
    2550   struct elf32_mn10300_link_hash_entry *sym_hash;
    2551 
    2552   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    2553   extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    2554 
    2555   shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     2432  Elf_Internal_Sym *isym, *isymend;
     2433  struct elf_link_hash_entry **sym_hashes;
     2434  struct elf_link_hash_entry **end_hashes;
     2435  unsigned int symcount;
     2436
     2437  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
    25562438
    25572439  contents = elf_section_data (sec)->this_hdr.contents;
     
    25672449
    25682450  /* Actually delete the bytes.  */
    2569   memmove (contents + addr, contents + addr + count, toaddr - addr - count);
     2451  memmove (contents + addr, contents + addr + count,
     2452           (size_t) (toaddr - addr - count));
    25702453  sec->_cooked_size -= count;
    25712454
     
    25802463
    25812464  /* Adjust the local symbols defined in this section.  */
    2582   esym = extsyms;
    2583   esymend = esym + symtab_hdr->sh_info;
    2584   for (; esym < esymend; esym++)
     2465  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     2466  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
     2467  for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
    25852468    {
    2586       Elf_Internal_Sym isym;
    2587 
    2588       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    2589 
    2590       if (isym.st_shndx == shndx
    2591           && isym.st_value > addr
    2592           && isym.st_value < toaddr)
     2469      if (isym->st_shndx == sec_shndx
     2470          && isym->st_value > addr
     2471          && isym->st_value < toaddr)
     2472        isym->st_value -= count;
     2473    }
     2474
     2475  /* Now adjust the global symbols defined in this section.  */
     2476  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     2477              - symtab_hdr->sh_info);
     2478  sym_hashes = elf_sym_hashes (abfd);
     2479  end_hashes = sym_hashes + symcount;
     2480  for (; sym_hashes < end_hashes; sym_hashes++)
     2481    {
     2482      struct elf_link_hash_entry *sym_hash = *sym_hashes;
     2483      if ((sym_hash->root.type == bfd_link_hash_defined
     2484           || sym_hash->root.type == bfd_link_hash_defweak)
     2485          && sym_hash->root.u.def.section == sec
     2486          && sym_hash->root.u.def.value > addr
     2487          && sym_hash->root.u.def.value < toaddr)
    25932488        {
    2594           isym.st_value -= count;
    2595           bfd_elf32_swap_symbol_out (abfd, &isym, esym);
     2489          sym_hash->root.u.def.value -= count;
    25962490        }
    25972491    }
    25982492
    2599   /* Now adjust the global symbols defined in this section.  */
    2600   esym = extsyms + symtab_hdr->sh_info;
    2601   esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
    2602   for (index = 0; esym < esymend; esym++, index++)
    2603     {
    2604       Elf_Internal_Sym isym;
    2605 
    2606       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    2607       sym_hash = (struct elf32_mn10300_link_hash_entry *)
    2608                    (elf_sym_hashes (abfd)[index]);
    2609       if (isym.st_shndx == shndx
    2610           && ((sym_hash)->root.root.type == bfd_link_hash_defined
    2611               || (sym_hash)->root.root.type == bfd_link_hash_defweak)
    2612           && (sym_hash)->root.root.u.def.section == sec
    2613           && (sym_hash)->root.root.u.def.value > addr
    2614           && (sym_hash)->root.root.u.def.value < toaddr)
    2615         {
    2616           (sym_hash)->root.root.u.def.value -= count;
    2617         }
    2618     }
    2619 
    2620   return true;
     2493  return TRUE;
    26212494}
    26222495
    2623 /* Return true if a symbol exists at the given address, else return
    2624    false.  */
    2625 static boolean
    2626 mn10300_elf_symbol_address_p (abfd, sec, extsyms, addr)
     2496/* Return TRUE if a symbol exists at the given address, else return
     2497   FALSE.  */
     2498static bfd_boolean
     2499mn10300_elf_symbol_address_p (abfd, sec, isym, addr)
    26272500     bfd *abfd;
    26282501     asection *sec;
    2629      Elf32_External_Sym *extsyms;
     2502     Elf_Internal_Sym *isym;
    26302503     bfd_vma addr;
    26312504{
    26322505  Elf_Internal_Shdr *symtab_hdr;
    2633   int shndx;
    2634   Elf32_External_Sym *esym, *esymend;
    2635   struct elf32_mn10300_link_hash_entry **sym_hash, **sym_hash_end;
    2636 
     2506  unsigned int sec_shndx;
     2507  Elf_Internal_Sym *isymend;
     2508  struct elf_link_hash_entry **sym_hashes;
     2509  struct elf_link_hash_entry **end_hashes;
     2510  unsigned int symcount;
     2511
     2512  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     2513
     2514  /* Examine all the symbols.  */
    26372515  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    2638   shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
    2639 
    2640   /* Examine all the symbols.  */
    2641   esym = extsyms;
    2642   esymend = esym + symtab_hdr->sh_info;
    2643   for (; esym < esymend; esym++)
     2516  for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
    26442517    {
    2645       Elf_Internal_Sym isym;
    2646 
    2647       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    2648 
    2649       if (isym.st_shndx == shndx
    2650           && isym.st_value == addr)
    2651         return true;
     2518      if (isym->st_shndx == sec_shndx
     2519          && isym->st_value == addr)
     2520        return TRUE;
    26522521    }
    26532522
    2654   sym_hash = (struct elf32_mn10300_link_hash_entry **) (elf_sym_hashes (abfd));
    2655   sym_hash_end = (sym_hash
    2656                   + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
    2657                      - symtab_hdr->sh_info));
    2658   for (; sym_hash < sym_hash_end; sym_hash++)
     2523  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     2524              - symtab_hdr->sh_info);
     2525  sym_hashes = elf_sym_hashes (abfd);
     2526  end_hashes = sym_hashes + symcount;
     2527  for (; sym_hashes < end_hashes; sym_hashes++)
    26592528    {
    2660       if (((*sym_hash)->root.root.type == bfd_link_hash_defined
    2661            || (*sym_hash)->root.root.type == bfd_link_hash_defweak)
    2662           && (*sym_hash)->root.root.u.def.section == sec
    2663           && (*sym_hash)->root.root.u.def.value == addr)
    2664         return true;
     2529      struct elf_link_hash_entry *sym_hash = *sym_hashes;
     2530      if ((sym_hash->root.type == bfd_link_hash_defined
     2531           || sym_hash->root.type == bfd_link_hash_defweak)
     2532          && sym_hash->root.u.def.section == sec
     2533          && sym_hash->root.u.def.value == addr)
     2534        return TRUE;
    26652535    }
    2666   return false;
     2536
     2537  return FALSE;
    26672538}
    26682539
     
    26772548     struct bfd_link_order *link_order;
    26782549     bfd_byte *data;
    2679      boolean relocateable;
     2550     bfd_boolean relocateable;
    26802551     asymbol **symbols;
    26812552{
     
    26852556  asection **sections = NULL;
    26862557  Elf_Internal_Rela *internal_relocs = NULL;
    2687   Elf32_External_Sym *external_syms = NULL;
    2688   Elf_Internal_Sym *internal_syms = NULL;
     2558  Elf_Internal_Sym *isymbuf = NULL;
    26892559
    26902560  /* We only need to handle the case of relaxing, or of having a
     
    27002570
    27012571  memcpy (data, elf_section_data (input_section)->this_hdr.contents,
    2702           input_section->_raw_size);
     2572          (size_t) input_section->_raw_size);
    27032573
    27042574  if ((input_section->flags & SEC_RELOC) != 0
    27052575      && input_section->reloc_count > 0)
    27062576    {
    2707       Elf_Internal_Sym *isymp;
    27082577      asection **secpp;
    2709       Elf32_External_Sym *esym, *esymend;
    2710 
    2711       if (symtab_hdr->contents != NULL)
    2712         external_syms = (Elf32_External_Sym *) symtab_hdr->contents;
    2713       else
     2578      Elf_Internal_Sym *isym, *isymend;
     2579      bfd_size_type amt;
     2580
     2581      internal_relocs = (_bfd_elf32_link_read_relocs
     2582                         (input_bfd, input_section, (PTR) NULL,
     2583                          (Elf_Internal_Rela *) NULL, FALSE));
     2584      if (internal_relocs == NULL)
     2585        goto error_return;
     2586
     2587      if (symtab_hdr->sh_info != 0)
    27142588        {
    2715           external_syms = ((Elf32_External_Sym *)
    2716                            bfd_malloc (symtab_hdr->sh_info
    2717                                        * sizeof (Elf32_External_Sym)));
    2718           if (external_syms == NULL && symtab_hdr->sh_info > 0)
    2719             goto error_return;
    2720           if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    2721               || (bfd_read (external_syms, sizeof (Elf32_External_Sym),
    2722                             symtab_hdr->sh_info, input_bfd)
    2723                   != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym))))
     2589          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     2590          if (isymbuf == NULL)
     2591            isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
     2592                                            symtab_hdr->sh_info, 0,
     2593                                            NULL, NULL, NULL);
     2594          if (isymbuf == NULL)
    27242595            goto error_return;
    27252596        }
    27262597
    2727       internal_relocs = (_bfd_elf32_link_read_relocs
    2728                          (input_bfd, input_section, (PTR) NULL,
    2729                           (Elf_Internal_Rela *) NULL, false));
    2730       if (internal_relocs == NULL)
     2598      amt = symtab_hdr->sh_info;
     2599      amt *= sizeof (asection *);
     2600      sections = (asection **) bfd_malloc (amt);
     2601      if (sections == NULL && amt != 0)
    27312602        goto error_return;
    27322603
    2733       internal_syms = ((Elf_Internal_Sym *)
    2734                        bfd_malloc (symtab_hdr->sh_info
    2735                                    * sizeof (Elf_Internal_Sym)));
    2736       if (internal_syms == NULL && symtab_hdr->sh_info > 0)
    2737         goto error_return;
    2738 
    2739       sections = (asection **) bfd_malloc (symtab_hdr->sh_info
    2740                                            * sizeof (asection *));
    2741       if (sections == NULL && symtab_hdr->sh_info > 0)
    2742         goto error_return;
    2743 
    2744       isymp = internal_syms;
    2745       secpp = sections;
    2746       esym = external_syms;
    2747       esymend = esym + symtab_hdr->sh_info;
    2748       for (; esym < esymend; ++esym, ++isymp, ++secpp)
     2604      isymend = isymbuf + symtab_hdr->sh_info;
     2605      for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
    27492606        {
    27502607          asection *isec;
    27512608
    2752           bfd_elf32_swap_symbol_in (input_bfd, esym, isymp);
    2753 
    2754           if (isymp->st_shndx == SHN_UNDEF)
     2609          if (isym->st_shndx == SHN_UNDEF)
    27552610            isec = bfd_und_section_ptr;
    2756           else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)
    2757             isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
    2758           else if (isymp->st_shndx == SHN_ABS)
     2611          else if (isym->st_shndx == SHN_ABS)
    27592612            isec = bfd_abs_section_ptr;
    2760           else if (isymp->st_shndx == SHN_COMMON)
     2613          else if (isym->st_shndx == SHN_COMMON)
    27612614            isec = bfd_com_section_ptr;
    27622615          else
    2763             {
    2764               /* Who knows?  */
    2765               isec = NULL;
    2766             }
     2616            isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
    27672617
    27682618          *secpp = isec;
     
    27712621      if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
    27722622                                     input_section, data, internal_relocs,
    2773                                      internal_syms, sections))
     2623                                     isymbuf, sections))
    27742624        goto error_return;
    27752625
    27762626      if (sections != NULL)
    27772627        free (sections);
    2778       sections = NULL;
    2779       if (internal_syms != NULL)
    2780         free (internal_syms);
    2781       internal_syms = NULL;
    2782       if (external_syms != NULL && symtab_hdr->contents == NULL)
    2783         free (external_syms);
    2784       external_syms = NULL;
     2628      if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
     2629        free (isymbuf);
    27852630      if (internal_relocs != elf_section_data (input_section)->relocs)
    27862631        free (internal_relocs);
    2787       internal_relocs = NULL;
    27882632    }
    27892633
     
    27912635
    27922636 error_return:
     2637  if (sections != NULL)
     2638    free (sections);
     2639  if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
     2640    free (isymbuf);
    27932641  if (internal_relocs != NULL
    27942642      && internal_relocs != elf_section_data (input_section)->relocs)
    27952643    free (internal_relocs);
    2796   if (external_syms != NULL && symtab_hdr->contents == NULL)
    2797     free (external_syms);
    2798   if (internal_syms != NULL)
    2799     free (internal_syms);
    2800   if (sections != NULL)
    2801     free (sections);
    28022644  return NULL;
    28032645}
     
    28352677      ret->direct_calls = 0;
    28362678      ret->stack_size = 0;
     2679      ret->movm_args = 0;
    28372680      ret->movm_stack_size = 0;
    28382681      ret->flags = 0;
    2839       ret->movm_args = 0;
    28402682    }
    28412683
     
    28502692{
    28512693  struct elf32_mn10300_link_hash_table *ret;
    2852 
    2853   ret = ((struct elf32_mn10300_link_hash_table *)
    2854          bfd_alloc (abfd, sizeof (struct elf32_mn10300_link_hash_table)));
     2694  bfd_size_type amt = sizeof (struct elf32_mn10300_link_hash_table);
     2695
     2696  ret = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
    28552697  if (ret == (struct elf32_mn10300_link_hash_table *) NULL)
    28562698    return NULL;
     
    28592701                                       elf32_mn10300_link_hash_newfunc))
    28602702    {
    2861       bfd_release (abfd, ret);
     2703      free (ret);
    28622704      return NULL;
    28632705    }
    28642706
    28652707  ret->flags = 0;
     2708  amt = sizeof (struct elf_link_hash_table);
    28662709  ret->static_hash_table
    2867     = ((struct elf32_mn10300_link_hash_table *)
    2868        bfd_alloc (abfd, sizeof (struct elf_link_hash_table)));
     2710    = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
    28692711  if (ret->static_hash_table == NULL)
    28702712    {
    2871       bfd_release (abfd, ret);
     2713      free (ret);
    28722714      return NULL;
    28732715    }
     
    28762718                                       elf32_mn10300_link_hash_newfunc))
    28772719    {
    2878       bfd_release (abfd, ret->static_hash_table);
    2879       bfd_release (abfd, ret);
     2720      free (ret->static_hash_table);
     2721      free (ret);
    28802722      return NULL;
    28812723    }
     
    28832725}
    28842726
    2885 static int
     2727/* Free an mn10300 ELF linker hash table.  */
     2728
     2729static void
     2730elf32_mn10300_link_hash_table_free (hash)
     2731     struct bfd_link_hash_table *hash;
     2732{
     2733  struct elf32_mn10300_link_hash_table *ret
     2734    = (struct elf32_mn10300_link_hash_table *) hash;
     2735
     2736  _bfd_generic_link_hash_table_free
     2737    ((struct bfd_link_hash_table *) ret->static_hash_table);
     2738  _bfd_generic_link_hash_table_free
     2739    ((struct bfd_link_hash_table *) ret);
     2740}
     2741
     2742static unsigned long
    28862743elf_mn10300_mach (flags)
    28872744     flagword flags;
     
    29052762_bfd_mn10300_elf_final_write_processing (abfd, linker)
    29062763     bfd *abfd;
    2907      boolean linker ATTRIBUTE_UNUSED;
     2764     bfd_boolean linker ATTRIBUTE_UNUSED;
    29082765{
    29092766  unsigned long val;
     
    29252782}
    29262783
    2927 boolean
     2784bfd_boolean
    29282785_bfd_mn10300_elf_object_p (abfd)
    29292786     bfd *abfd;
     
    29312788  bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
    29322789                             elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
    2933   return true;
     2790  return TRUE;
    29342791}
    29352792
     
    29372794   object file when linking.  */
    29382795
    2939 boolean
     2796bfd_boolean
    29402797_bfd_mn10300_elf_merge_private_bfd_data (ibfd, obfd)
    29412798     bfd *ibfd;
     
    29442801  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    29452802      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    2946     return true;
     2803    return TRUE;
    29472804
    29482805  if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
     
    29512808      if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
    29522809                               bfd_get_mach (ibfd)))
    2953         return false;
     2810        return FALSE;
    29542811    }
    29552812
    2956   return true;
     2813  return TRUE;
    29572814}
    29582815
     
    29602817#define TARGET_LITTLE_NAME      "elf32-mn10300"
    29612818#define ELF_ARCH                bfd_arch_mn10300
    2962 #define ELF_MACHINE_CODE        EM_CYGNUS_MN10300
     2819#define ELF_MACHINE_CODE        EM_MN10300
     2820#define ELF_MACHINE_ALT1        EM_CYGNUS_MN10300
    29632821#define ELF_MAXPAGESIZE         0x1000
    29642822
     
    29662824#define elf_info_to_howto_rel           0
    29672825#define elf_backend_can_gc_sections     1
     2826#define elf_backend_rela_normal         1
    29682827#define elf_backend_check_relocs        mn10300_elf_check_relocs
    29692828#define elf_backend_gc_mark_hook        mn10300_elf_gc_mark_hook
     
    29742833#define bfd_elf32_bfd_link_hash_table_create \
    29752834                                elf32_mn10300_link_hash_table_create
     2835#define bfd_elf32_bfd_link_hash_table_free \
     2836                                elf32_mn10300_link_hash_table_free
    29762837
    29772838#define elf_symbol_leading_char '_'
Note: See TracChangeset for help on using the changeset viewer.