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-m10200.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* Matsushita 10200 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
     
    2727  PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
    2828static void mn10200_info_to_howto
    29   PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
    30 static boolean mn10200_elf_relax_delete_bytes
     29  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
     30static bfd_boolean mn10200_elf_relax_delete_bytes
    3131  PARAMS ((bfd *, asection *, bfd_vma, int));
    32 static boolean mn10200_elf_symbol_address_p
    33   PARAMS ((bfd *, asection *, Elf32_External_Sym *, bfd_vma));
    34 
    35 /* We have to use RELA instructions since md_apply_fix3 in the assembler
    36    does absolutely nothing.  */
    37 #define USE_RELA
     32static bfd_boolean mn10200_elf_symbol_address_p
     33  PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
     34static bfd_reloc_status_type mn10200_elf_final_link_relocate
     35  PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *,
     36           bfd_byte *, bfd_vma, bfd_vma, bfd_vma,
     37           struct bfd_link_info *, asection *, int));
     38static bfd_boolean mn10200_elf_relocate_section
     39  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
     40           bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *,
     41           asection **));
     42static bfd_boolean mn10200_elf_relax_section
     43  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
     44static bfd_byte * mn10200_elf_get_relocated_section_contents
     45  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
     46           bfd_byte *, bfd_boolean, asymbol **));
    3847
    3948enum reloc_type {
     
    5564         2,
    5665         16,
    57          false,
     66         FALSE,
    5867         0,
    5968         complain_overflow_bitfield,
    6069         bfd_elf_generic_reloc,
    6170         "R_MN10200_NONE",
    62          false,
    63          0,
    64          0,
    65          false),
     71         FALSE,
     72         0,
     73         0,
     74         FALSE),
    6675  /* Standard 32 bit reloc.  */
    6776  HOWTO (R_MN10200_32,
     
    6978         2,
    7079         32,
    71          false,
     80         FALSE,
    7281         0,
    7382         complain_overflow_bitfield,
    7483         bfd_elf_generic_reloc,
    7584         "R_MN10200_32",
    76          false,
     85         FALSE,
    7786         0xffffffff,
    7887         0xffffffff,
    79          false),
     88         FALSE),
    8089  /* Standard 16 bit reloc.  */
    8190  HOWTO (R_MN10200_16,
     
    8392         1,
    8493         16,
    85          false,
     94         FALSE,
    8695         0,
    8796         complain_overflow_bitfield,
    8897         bfd_elf_generic_reloc,
    8998         "R_MN10200_16",
    90          false,
     99         FALSE,
    91100         0xffff,
    92101         0xffff,
    93          false),
     102         FALSE),
    94103  /* Standard 8 bit reloc.  */
    95104  HOWTO (R_MN10200_8,
     
    97106         0,
    98107         8,
    99          false,
     108         FALSE,
    100109         0,
    101110         complain_overflow_bitfield,
    102111         bfd_elf_generic_reloc,
    103112         "R_MN10200_8",
    104          false,
     113         FALSE,
    105114         0xff,
    106115         0xff,
    107          false),
     116         FALSE),
    108117  /* Standard 24 bit reloc.  */
    109118  HOWTO (R_MN10200_24,
     
    111120         2,
    112121         24,
    113          false,
     122         FALSE,
    114123         0,
    115124         complain_overflow_bitfield,
    116125         bfd_elf_generic_reloc,
    117126         "R_MN10200_24",
    118          false,
     127         FALSE,
    119128         0xffffff,
    120129         0xffffff,
    121          false),
     130         FALSE),
    122131  /* Simple 8 pc-relative reloc.  */
    123132  HOWTO (R_MN10200_PCREL8,
     
    125134         0,
    126135         8,
    127          true,
     136         TRUE,
    128137         0,
    129138         complain_overflow_bitfield,
    130139         bfd_elf_generic_reloc,
    131140         "R_MN10200_PCREL8",
    132          false,
     141         FALSE,
    133142         0xff,
    134143         0xff,
    135          true),
     144         TRUE),
    136145  /* Simple 16 pc-relative reloc.  */
    137146  HOWTO (R_MN10200_PCREL16,
     
    139148         1,
    140149         16,
    141          true,
     150         TRUE,
    142151         0,
    143152         complain_overflow_bitfield,
    144153         bfd_elf_generic_reloc,
    145154         "R_MN10200_PCREL16",
    146          false,
     155         FALSE,
    147156         0xffff,
    148157         0xffff,
    149          true),
     158         TRUE),
    150159  /* Simple 32bit pc-relative reloc with a 1 byte adjustment
    151160     to get the pc-relative offset correct.  */
     
    154163         2,
    155164         24,
    156          true,
     165         TRUE,
    157166         0,
    158167         complain_overflow_bitfield,
    159168         bfd_elf_generic_reloc,
    160169         "R_MN10200_PCREL24",
    161          false,
     170         FALSE,
    162171         0xffffff,
    163172         0xffffff,
    164          true),
     173         TRUE),
    165174};
    166175
     
    205214     bfd *abfd ATTRIBUTE_UNUSED;
    206215     arelent *cache_ptr;
    207      Elf32_Internal_Rela *dst;
     216     Elf_Internal_Rela *dst;
    208217{
    209218  unsigned int r_type;
     
    215224
    216225/* Perform a relocation as part of a final link.  */
     226
    217227static bfd_reloc_status_type
    218228mn10200_elf_final_link_relocate (howto, input_bfd, output_bfd,
     
    319329
    320330/* Relocate an MN10200 ELF section.  */
    321 static boolean
     331static bfd_boolean
    322332mn10200_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    323333                              contents, relocs, local_syms, local_sections)
     
    335345  Elf_Internal_Rela *rel, *relend;
    336346
     347  if (info->relocateable)
     348    return TRUE;
     349
    337350  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
    338351  sym_hashes = elf_sym_hashes (input_bfd);
     
    355368      howto = elf_mn10200_howto_table + r_type;
    356369
    357       if (info->relocateable)
    358         {
    359           /* This is a relocateable link.  We don't have to change
    360              anything, unless the reloc is against a section symbol,
    361              in which case we have to adjust according to where the
    362              section symbol winds up in the output section.  */
    363           if (r_symndx < symtab_hdr->sh_info)
    364             {
    365               sym = local_syms + r_symndx;
    366               if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    367                 {
    368                   sec = local_sections[r_symndx];
    369                   rel->r_addend += sec->output_offset + sym->st_value;
    370                 }
    371             }
    372 
    373           continue;
    374         }
    375 
    376       /* This is a final link.  */
    377370      h = NULL;
    378371      sym = NULL;
     
    382375          sym = local_syms + r_symndx;
    383376          sec = local_sections[r_symndx];
    384           relocation = (sec->output_section->vma
    385                         + sec->output_offset
    386                         + sym->st_value);
     377          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
    387378        }
    388379      else
     
    406397              if (! ((*info->callbacks->undefined_symbol)
    407398                     (info, h->root.root.string, input_bfd,
    408                       input_section, rel->r_offset, true)))
    409                 return false;
     399                      input_section, rel->r_offset, TRUE)))
     400                return FALSE;
    410401              relocation = 0;
    411402            }
     
    439430                     (info, name, howto->name, (bfd_vma) 0,
    440431                      input_bfd, input_section, rel->r_offset)))
    441                 return false;
     432                return FALSE;
    442433              break;
    443434
     
    445436              if (! ((*info->callbacks->undefined_symbol)
    446437                     (info, name, input_bfd, input_section,
    447                       rel->r_offset, true)))
    448                 return false;
     438                      rel->r_offset, TRUE)))
     439                return FALSE;
    449440              break;
    450441
     
    469460                    (info, msg, name, input_bfd, input_section,
    470461                     rel->r_offset)))
    471                 return false;
     462                return FALSE;
    472463              break;
    473464            }
     
    475466    }
    476467
    477   return true;
     468  return TRUE;
    478469}
    479470
     
    507498        and somewhat more difficult to support.  */
    508499
    509 static boolean
     500static bfd_boolean
    510501mn10200_elf_relax_section (abfd, sec, link_info, again)
    511502     bfd *abfd;
    512503     asection *sec;
    513504     struct bfd_link_info *link_info;
    514      boolean *again;
     505     bfd_boolean *again;
    515506{
    516507  Elf_Internal_Shdr *symtab_hdr;
    517508  Elf_Internal_Rela *internal_relocs;
    518   Elf_Internal_Rela *free_relocs = NULL;
    519509  Elf_Internal_Rela *irel, *irelend;
    520510  bfd_byte *contents = NULL;
    521   bfd_byte *free_contents = NULL;
    522   Elf32_External_Sym *extsyms = NULL;
    523   Elf32_External_Sym *free_extsyms = NULL;
     511  Elf_Internal_Sym *isymbuf = NULL;
    524512
    525513  /* Assume nothing changes.  */
    526   *again = false;
     514  *again = FALSE;
    527515
    528516  /* We don't have to do anything for a relocateable link, if
     
    533521      || sec->reloc_count == 0
    534522      || (sec->flags & SEC_CODE) == 0)
    535     return true;
     523    return TRUE;
    536524
    537525  /* If this is the first time we have been called for this section,
     
    548536  if (internal_relocs == NULL)
    549537    goto error_return;
    550   if (! link_info->keep_memory)
    551     free_relocs = internal_relocs;
    552538
    553539  /* Walk through them looking for relaxing opportunities.  */
     
    576562              if (contents == NULL)
    577563                goto error_return;
    578               free_contents = contents;
    579564
    580565              if (! bfd_get_section_contents (abfd, sec, contents,
     
    584569        }
    585570
    586       /* Read this BFD's symbols if we haven't done so already.  */
    587       if (extsyms == NULL)
    588         {
    589           /* Get cached copy if it exists.  */
    590           if (symtab_hdr->contents != NULL)
    591             extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    592           else
    593             {
    594               /* Go get them off disk.  */
    595               extsyms = ((Elf32_External_Sym *)
    596                          bfd_malloc (symtab_hdr->sh_size));
    597               if (extsyms == NULL)
    598                 goto error_return;
    599               free_extsyms = extsyms;
    600               if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    601                   || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
    602                       != symtab_hdr->sh_size))
    603                 goto error_return;
    604             }
     571      /* Read this BFD's local symbols if we haven't done so already.  */
     572      if (isymbuf == NULL && symtab_hdr->sh_info != 0)
     573        {
     574          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     575          if (isymbuf == NULL)
     576            isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
     577                                            symtab_hdr->sh_info, 0,
     578                                            NULL, NULL, NULL);
     579          if (isymbuf == NULL)
     580            goto error_return;
    605581        }
    606582
     
    608584      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
    609585        {
    610           Elf_Internal_Sym isym;
     586          /* A local symbol.  */
     587          Elf_Internal_Sym *isym;
    611588          asection *sym_sec;
    612589
    613           /* A local symbol.  */
    614           bfd_elf32_swap_symbol_in (abfd,
    615                                     extsyms + ELF32_R_SYM (irel->r_info),
    616                                     &isym);
    617 
    618           sym_sec = bfd_section_from_elf_index (abfd, isym.st_shndx);
    619           symval = (isym.st_value
     590          isym = isymbuf + ELF32_R_SYM (irel->r_info);
     591          if (isym->st_shndx == SHN_UNDEF)
     592            sym_sec = bfd_und_section_ptr;
     593          else if (isym->st_shndx == SHN_ABS)
     594            sym_sec = bfd_abs_section_ptr;
     595          else if (isym->st_shndx == SHN_COMMON)
     596            sym_sec = bfd_com_section_ptr;
     597          else
     598            sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
     599          symval = (isym->st_value
    620600                    + sym_sec->output_section->vma
    621601                    + sym_sec->output_offset);
     
    678658              /* Note that we've changed the relocs, section contents, etc.  */
    679659              elf_section_data (sec)->relocs = internal_relocs;
    680               free_relocs = NULL;
    681 
    682660              elf_section_data (sec)->this_hdr.contents = contents;
    683               free_contents = NULL;
    684 
    685               symtab_hdr->contents = (bfd_byte *) extsyms;
    686               free_extsyms = NULL;
     661              symtab_hdr->contents = (unsigned char *) isymbuf;
    687662
    688663              /* Fix the opcode.  */
     
    706681              /* That will change things, so, we should relax again.
    707682                 Note that this is not required, and it may be slow.  */
    708               *again = true;
     683              *again = TRUE;
    709684            }
    710685        }
     
    736711              /* Note that we've changed the relocs, section contents, etc.  */
    737712              elf_section_data (sec)->relocs = internal_relocs;
    738               free_relocs = NULL;
    739 
    740713              elf_section_data (sec)->this_hdr.contents = contents;
    741               free_contents = NULL;
    742 
    743               symtab_hdr->contents = (bfd_byte *) extsyms;
    744               free_extsyms = NULL;
     714              symtab_hdr->contents = (unsigned char *) isymbuf;
    745715
    746716              /* Fix the opcode.  */
     
    758728              /* That will change things, so, we should relax again.
    759729                 Note that this is not required, and it may be slow.  */
    760               *again = true;
     730              *again = TRUE;
    761731            }
    762732        }
     
    827797          /* We also have to be sure there is no symbol/label
    828798             at the unconditional branch.  */
    829           if (mn10200_elf_symbol_address_p (abfd, sec, extsyms,
     799          if (mn10200_elf_symbol_address_p (abfd, sec, isymbuf,
    830800                                            irel->r_offset + 1))
    831801            continue;
     
    833803          /* Note that we've changed the relocs, section contents, etc.  */
    834804          elf_section_data (sec)->relocs = internal_relocs;
    835           free_relocs = NULL;
    836 
    837805          elf_section_data (sec)->this_hdr.contents = contents;
    838           free_contents = NULL;
    839 
    840           symtab_hdr->contents = (bfd_byte *) extsyms;
    841           free_extsyms = NULL;
     806          symtab_hdr->contents = (unsigned char *) isymbuf;
    842807
    843808          /* Reverse the condition of the first branch.  */
     
    916881          /* That will change things, so, we should relax again.
    917882             Note that this is not required, and it may be slow.  */
    918           *again = true;
     883          *again = TRUE;
    919884        }
    920885
     
    957922                  /* Note that we've changed the reldection contents, etc.  */
    958923                  elf_section_data (sec)->relocs = internal_relocs;
    959                   free_relocs = NULL;
    960 
    961924                  elf_section_data (sec)->this_hdr.contents = contents;
    962                   free_contents = NULL;
    963 
    964                   symtab_hdr->contents = (bfd_byte *) extsyms;
    965                   free_extsyms = NULL;
     925                  symtab_hdr->contents = (unsigned char *) isymbuf;
    966926
    967927                  /* Fix the opcode.  */
     
    984944                  /* That will change things, so, we should relax again.
    985945                     Note that this is not required, and it may be slow.  */
    986                   *again = true;
     946                  *again = TRUE;
    987947                  break;
    988948
     
    1001961                  /* Note that we've changed the reldection contents, etc.  */
    1002962                  elf_section_data (sec)->relocs = internal_relocs;
    1003                   free_relocs = NULL;
    1004 
    1005963                  elf_section_data (sec)->this_hdr.contents = contents;
    1006                   free_contents = NULL;
    1007 
    1008                   symtab_hdr->contents = (bfd_byte *) extsyms;
    1009                   free_extsyms = NULL;
     964                  symtab_hdr->contents = (unsigned char *) isymbuf;
    1010965
    1011966                  if ((code & 0xfc) == 0x74)
     
    1040995                  /* That will change things, so, we should relax again.
    1041996                     Note that this is not required, and it may be slow.  */
    1042                   *again = true;
     997                  *again = TRUE;
    1043998                  break;
    1044999
     
    10891044                  /* Note that we've changed the reldection contents, etc.  */
    10901045                  elf_section_data (sec)->relocs = internal_relocs;
    1091                   free_relocs = NULL;
    1092 
    10931046                  elf_section_data (sec)->this_hdr.contents = contents;
    1094                   free_contents = NULL;
    1095 
    1096                   symtab_hdr->contents = (bfd_byte *) extsyms;
    1097                   free_extsyms = NULL;
     1047                  symtab_hdr->contents = (unsigned char *) isymbuf;
    10981048
    10991049                  /* Fix the opcode.  */
     
    11461096                  /* That will change things, so, we should relax again.
    11471097                     Note that this is not required, and it may be slow.  */
    1148                   *again = true;
     1098                  *again = TRUE;
    11491099                  break;
    11501100
     
    11531103                  /* Note that we've changed the reldection contents, etc.  */
    11541104                  elf_section_data (sec)->relocs = internal_relocs;
    1155                   free_relocs = NULL;
    1156 
    11571105                  elf_section_data (sec)->this_hdr.contents = contents;
    1158                   free_contents = NULL;
    1159 
    1160                   symtab_hdr->contents = (bfd_byte *) extsyms;
    1161                   free_extsyms = NULL;
     1106                  symtab_hdr->contents = (unsigned char *) isymbuf;
    11621107
    11631108                  bfd_put_8 (abfd, 0xcc + (code & 0x03),
     
    11821127                  /* That will change things, so, we should relax again.
    11831128                     Note that this is not required, and it may be slow.  */
    1184                   *again = true;
     1129                  *again = TRUE;
    11851130                  break;
    11861131                }
     
    11891134    }
    11901135
    1191   if (free_relocs != NULL)
    1192     {
    1193       free (free_relocs);
    1194       free_relocs = NULL;
    1195     }
    1196 
    1197   if (free_contents != NULL)
     1136  if (isymbuf != NULL
     1137      && symtab_hdr->contents != (unsigned char *) isymbuf)
    11981138    {
    11991139      if (! link_info->keep_memory)
    1200         free (free_contents);
     1140        free (isymbuf);
     1141      else
     1142        {
     1143          /* Cache the symbols for elf_link_input_bfd.  */
     1144          symtab_hdr->contents = (unsigned char *) isymbuf;
     1145        }
     1146    }
     1147
     1148  if (contents != NULL
     1149      && elf_section_data (sec)->this_hdr.contents != contents)
     1150    {
     1151      if (! link_info->keep_memory)
     1152        free (contents);
    12011153      else
    12021154        {
     
    12041156          elf_section_data (sec)->this_hdr.contents = contents;
    12051157        }
    1206       free_contents = NULL;
    12071158    }
    12081159
    1209   if (free_extsyms != NULL)
    1210     {
    1211       if (! link_info->keep_memory)
    1212         free (free_extsyms);
    1213       else
    1214         {
    1215           /* Cache the symbols for elf_link_input_bfd.  */
    1216           symtab_hdr->contents = extsyms;
    1217         }
    1218       free_extsyms = NULL;
    1219     }
    1220 
    1221   return true;
     1160  if (internal_relocs != NULL
     1161      && elf_section_data (sec)->relocs != internal_relocs)
     1162    free (internal_relocs);
     1163
     1164  return TRUE;
    12221165
    12231166 error_return:
    1224   if (free_relocs != NULL)
    1225     free (free_relocs);
    1226   if (free_contents != NULL)
    1227     free (free_contents);
    1228   if (free_extsyms != NULL)
    1229     free (free_extsyms);
    1230   return false;
     1167  if (isymbuf != NULL
     1168      && symtab_hdr->contents != (unsigned char *) isymbuf)
     1169    free (isymbuf);
     1170  if (contents != NULL
     1171      && elf_section_data (sec)->this_hdr.contents != contents)
     1172    free (contents);
     1173  if (internal_relocs != NULL
     1174      && elf_section_data (sec)->relocs != internal_relocs)
     1175    free (internal_relocs);
     1176
     1177  return FALSE;
    12311178}
    12321179
    12331180/* Delete some bytes from a section while relaxing.  */
    12341181
    1235 static boolean
     1182static bfd_boolean
    12361183mn10200_elf_relax_delete_bytes (abfd, sec, addr, count)
    12371184     bfd *abfd;
     
    12411188{
    12421189  Elf_Internal_Shdr *symtab_hdr;
    1243   Elf32_External_Sym *extsyms;
    1244   int shndx, index;
     1190  unsigned int sec_shndx;
    12451191  bfd_byte *contents;
    12461192  Elf_Internal_Rela *irel, *irelend;
    12471193  Elf_Internal_Rela *irelalign;
    12481194  bfd_vma toaddr;
    1249   Elf32_External_Sym *esym, *esymend;
    1250   struct elf_link_hash_entry *sym_hash;
    1251 
    1252   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    1253   extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
    1254 
    1255   shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     1195  Elf_Internal_Sym *isym;
     1196  Elf_Internal_Sym *isymend;
     1197  struct elf_link_hash_entry **sym_hashes;
     1198  struct elf_link_hash_entry **end_hashes;
     1199  unsigned int symcount;
     1200
     1201  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
    12561202
    12571203  contents = elf_section_data (sec)->this_hdr.contents;
     
    12671213
    12681214  /* Actually delete the bytes.  */
    1269   memmove (contents + addr, contents + addr + count, toaddr - addr - count);
     1215  memmove (contents + addr, contents + addr + count,
     1216           (size_t) (toaddr - addr - count));
    12701217  sec->_cooked_size -= count;
    12711218
     
    12801227
    12811228  /* Adjust the local symbols defined in this section.  */
    1282   esym = extsyms;
    1283   esymend = esym + symtab_hdr->sh_info;
    1284   for (; esym < esymend; esym++)
     1229  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     1230  isym = (Elf_Internal_Sym *) symtab_hdr->contents;
     1231  for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
    12851232    {
    1286       Elf_Internal_Sym isym;
    1287 
    1288       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    1289 
    1290       if (isym.st_shndx == shndx
    1291           && isym.st_value > addr
    1292           && isym.st_value < toaddr)
    1293         {
    1294           isym.st_value -= count;
    1295           bfd_elf32_swap_symbol_out (abfd, &isym, esym);
    1296         }
     1233      if (isym->st_shndx == sec_shndx
     1234          && isym->st_value > addr
     1235          && isym->st_value < toaddr)
     1236        isym->st_value -= count;
    12971237    }
    12981238
    12991239  /* Now adjust the global symbols defined in this section.  */
    1300   esym = extsyms + symtab_hdr->sh_info;
    1301   esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
    1302   for (index = 0; esym < esymend; esym++, index++)
     1240  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     1241              - symtab_hdr->sh_info);
     1242  sym_hashes = elf_sym_hashes (abfd);
     1243  end_hashes = sym_hashes + symcount;
     1244  for (; sym_hashes < end_hashes; sym_hashes++)
    13031245    {
    1304       Elf_Internal_Sym isym;
    1305 
    1306       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    1307       sym_hash = elf_sym_hashes (abfd)[index];
    1308       if (isym.st_shndx == shndx
    1309           && ((sym_hash)->root.type == bfd_link_hash_defined
    1310               || (sym_hash)->root.type == bfd_link_hash_defweak)
    1311           && (sym_hash)->root.u.def.section == sec
    1312           && (sym_hash)->root.u.def.value > addr
    1313           && (sym_hash)->root.u.def.value < toaddr)
    1314         {
    1315           (sym_hash)->root.u.def.value -= count;
     1246      struct elf_link_hash_entry *sym_hash = *sym_hashes;
     1247      if ((sym_hash->root.type == bfd_link_hash_defined
     1248           || sym_hash->root.type == bfd_link_hash_defweak)
     1249          && sym_hash->root.u.def.section == sec
     1250          && sym_hash->root.u.def.value > addr
     1251          && sym_hash->root.u.def.value < toaddr)
     1252        {
     1253          sym_hash->root.u.def.value -= count;
    13161254        }
    13171255    }
    13181256
    1319   return true;
     1257  return TRUE;
    13201258}
    13211259
    1322 /* Return true if a symbol exists at the given address, else return
    1323    false.  */
    1324 static boolean
    1325 mn10200_elf_symbol_address_p (abfd, sec, extsyms, addr)
     1260/* Return TRUE if a symbol exists at the given address, else return
     1261   FALSE.  */
     1262static bfd_boolean
     1263mn10200_elf_symbol_address_p (abfd, sec, isym, addr)
    13261264     bfd *abfd;
    13271265     asection *sec;
    1328      Elf32_External_Sym *extsyms;
     1266     Elf_Internal_Sym *isym;
    13291267     bfd_vma addr;
    13301268{
    13311269  Elf_Internal_Shdr *symtab_hdr;
    1332   int shndx;
    1333   Elf32_External_Sym *esym, *esymend;
    1334   struct elf_link_hash_entry **sym_hash, **sym_hash_end;
    1335 
     1270  unsigned int sec_shndx;
     1271  Elf_Internal_Sym *isymend;
     1272  struct elf_link_hash_entry **sym_hashes;
     1273  struct elf_link_hash_entry **end_hashes;
     1274  unsigned int symcount;
     1275
     1276  sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     1277
     1278  /* Examine all the local symbols.  */
    13361279  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    1337   shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
    1338 
    1339   /* Examine all the symbols.  */
    1340   esym = extsyms;
    1341   esymend = esym + symtab_hdr->sh_info;
    1342   for (; esym < esymend; esym++)
     1280  for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
    13431281    {
    1344       Elf_Internal_Sym isym;
    1345 
    1346       bfd_elf32_swap_symbol_in (abfd, esym, &isym);
    1347 
    1348       if (isym.st_shndx == shndx
    1349           && isym.st_value == addr)
    1350         return true;
     1282      if (isym->st_shndx == sec_shndx
     1283          && isym->st_value == addr)
     1284        return TRUE;
    13511285    }
    13521286
    1353   sym_hash = elf_sym_hashes (abfd);
    1354   sym_hash_end = (sym_hash
    1355                   + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
    1356                      - symtab_hdr->sh_info));
    1357   for (; sym_hash < sym_hash_end; sym_hash++)
     1287  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
     1288              - symtab_hdr->sh_info);
     1289  sym_hashes = elf_sym_hashes (abfd);
     1290  end_hashes = sym_hashes + symcount;
     1291  for (; sym_hashes < end_hashes; sym_hashes++)
    13581292    {
    1359       if (((*sym_hash)->root.type == bfd_link_hash_defined
    1360            || (*sym_hash)->root.type == bfd_link_hash_defweak)
    1361           && (*sym_hash)->root.u.def.section == sec
    1362           && (*sym_hash)->root.u.def.value == addr)
    1363         return true;
     1293      struct elf_link_hash_entry *sym_hash = *sym_hashes;
     1294      if ((sym_hash->root.type == bfd_link_hash_defined
     1295           || sym_hash->root.type == bfd_link_hash_defweak)
     1296          && sym_hash->root.u.def.section == sec
     1297          && sym_hash->root.u.def.value == addr)
     1298        return TRUE;
    13641299    }
    1365   return false;
     1300
     1301  return FALSE;
    13661302}
    13671303
     
    13761312     struct bfd_link_order *link_order;
    13771313     bfd_byte *data;
    1378      boolean relocateable;
     1314     bfd_boolean relocateable;
    13791315     asymbol **symbols;
    13801316{
     
    13841320  asection **sections = NULL;
    13851321  Elf_Internal_Rela *internal_relocs = NULL;
    1386   Elf32_External_Sym *external_syms = NULL;
    1387   Elf_Internal_Sym *internal_syms = NULL;
     1322  Elf_Internal_Sym *isymbuf = NULL;
    13881323
    13891324  /* We only need to handle the case of relaxing, or of having a
     
    13991334
    14001335  memcpy (data, elf_section_data (input_section)->this_hdr.contents,
    1401           input_section->_raw_size);
     1336          (size_t) input_section->_raw_size);
    14021337
    14031338  if ((input_section->flags & SEC_RELOC) != 0
    14041339      && input_section->reloc_count > 0)
    14051340    {
    1406       Elf_Internal_Sym *isymp;
     1341      Elf_Internal_Sym *isym;
     1342      Elf_Internal_Sym *isymend;
    14071343      asection **secpp;
    1408       Elf32_External_Sym *esym, *esymend;
    1409 
    1410       if (symtab_hdr->contents != NULL)
    1411         external_syms = (Elf32_External_Sym *) symtab_hdr->contents;
    1412       else
    1413         {
    1414           external_syms = ((Elf32_External_Sym *)
    1415                            bfd_malloc (symtab_hdr->sh_info
    1416                                        * sizeof (Elf32_External_Sym)));
    1417           if (external_syms == NULL && symtab_hdr->sh_info > 0)
    1418             goto error_return;
    1419           if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    1420               || (bfd_read (external_syms, sizeof (Elf32_External_Sym),
    1421                             symtab_hdr->sh_info, input_bfd)
    1422                   != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym))))
    1423             goto error_return;
    1424         }
     1344      bfd_size_type amt;
    14251345
    14261346      internal_relocs = (_bfd_elf32_link_read_relocs
    14271347                         (input_bfd, input_section, (PTR) NULL,
    1428                           (Elf_Internal_Rela *) NULL, false));
     1348                          (Elf_Internal_Rela *) NULL, FALSE));
    14291349      if (internal_relocs == NULL)
    14301350        goto error_return;
    14311351
    1432       internal_syms = ((Elf_Internal_Sym *)
    1433                        bfd_malloc (symtab_hdr->sh_info
    1434                                    * sizeof (Elf_Internal_Sym)));
    1435       if (internal_syms == NULL && symtab_hdr->sh_info > 0)
     1352      if (symtab_hdr->sh_info != 0)
     1353        {
     1354          isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     1355          if (isymbuf == NULL)
     1356            isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
     1357                                            symtab_hdr->sh_info, 0,
     1358                                            NULL, NULL, NULL);
     1359          if (isymbuf == NULL)
     1360            goto error_return;
     1361        }
     1362
     1363      amt = symtab_hdr->sh_info;
     1364      amt *= sizeof (asection *);
     1365      sections = (asection **) bfd_malloc (amt);
     1366      if (sections == NULL && amt != 0)
    14361367        goto error_return;
    14371368
    1438       sections = (asection **) bfd_malloc (symtab_hdr->sh_info
    1439                                            * sizeof (asection *));
    1440       if (sections == NULL && symtab_hdr->sh_info > 0)
    1441         goto error_return;
    1442 
    1443       isymp = internal_syms;
    1444       secpp = sections;
    1445       esym = external_syms;
    1446       esymend = esym + symtab_hdr->sh_info;
    1447       for (; esym < esymend; ++esym, ++isymp, ++secpp)
     1369      isymend = isymbuf + symtab_hdr->sh_info;
     1370      for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
    14481371        {
    14491372          asection *isec;
    14501373
    1451           bfd_elf32_swap_symbol_in (input_bfd, esym, isymp);
    1452 
    1453           if (isymp->st_shndx == SHN_UNDEF)
     1374          if (isym->st_shndx == SHN_UNDEF)
    14541375            isec = bfd_und_section_ptr;
    1455           else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)
    1456             isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);
    1457           else if (isymp->st_shndx == SHN_ABS)
     1376          else if (isym->st_shndx == SHN_ABS)
    14581377            isec = bfd_abs_section_ptr;
    1459           else if (isymp->st_shndx == SHN_COMMON)
     1378          else if (isym->st_shndx == SHN_COMMON)
    14601379            isec = bfd_com_section_ptr;
    14611380          else
    1462             {
    1463               /* Who knows?  */
    1464               isec = NULL;
    1465             }
     1381            isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
    14661382
    14671383          *secpp = isec;
     
    14701386      if (! mn10200_elf_relocate_section (output_bfd, link_info, input_bfd,
    14711387                                     input_section, data, internal_relocs,
    1472                                      internal_syms, sections))
     1388                                     isymbuf, sections))
    14731389        goto error_return;
    14741390
    14751391      if (sections != NULL)
    14761392        free (sections);
    1477       sections = NULL;
    1478       if (internal_syms != NULL)
    1479         free (internal_syms);
    1480       internal_syms = NULL;
    1481       if (external_syms != NULL && symtab_hdr->contents == NULL)
    1482         free (external_syms);
    1483       external_syms = NULL;
    1484       if (internal_relocs != elf_section_data (input_section)->relocs)
     1393      if (isymbuf != NULL
     1394          && symtab_hdr->contents != (unsigned char *) isymbuf)
     1395        free (isymbuf);
     1396      if (elf_section_data (input_section)->relocs != internal_relocs)
    14851397        free (internal_relocs);
    1486       internal_relocs = NULL;
    14871398    }
    14881399
     
    14901401
    14911402 error_return:
    1492   if (internal_relocs != NULL
    1493       && internal_relocs != elf_section_data (input_section)->relocs)
    1494     free (internal_relocs);
    1495   if (external_syms != NULL && symtab_hdr->contents == NULL)
    1496     free (external_syms);
    1497   if (internal_syms != NULL)
    1498     free (internal_syms);
    14991403  if (sections != NULL)
    15001404    free (sections);
     1405  if (isymbuf != NULL
     1406      && symtab_hdr->contents != (unsigned char *) isymbuf)
     1407    free (isymbuf);
     1408  if (internal_relocs != NULL
     1409      && elf_section_data (input_section)->relocs != internal_relocs)
     1410    free (internal_relocs);
    15011411  return NULL;
    15021412}
     
    15051415#define TARGET_LITTLE_NAME      "elf32-mn10200"
    15061416#define ELF_ARCH                bfd_arch_mn10200
    1507 #define ELF_MACHINE_CODE        EM_CYGNUS_MN10200
     1417#define ELF_MACHINE_CODE        EM_MN10200
     1418#define ELF_MACHINE_ALT1        EM_CYGNUS_MN10200
    15081419#define ELF_MAXPAGESIZE         0x1000
    15091420
     1421#define elf_backend_rela_normal 1
    15101422#define elf_info_to_howto       mn10200_info_to_howto
    15111423#define elf_info_to_howto_rel   0
Note: See TracChangeset for help on using the changeset viewer.