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/bout.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for Intel 960 b.out binaries.
    22   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    3    2000
     3   2000, 2001, 2002
    44   Free Software Foundation, Inc.
    55   Written by Cygnus Support.
     
    2929
    3030#include "aout/stab_gnu.h"
    31 #include "libaout.h"            /* BFD a.out internal data structures */
    32 
    33 static int aligncode PARAMS ((bfd *abfd, asection *input_section,
    34                               arelent *r, unsigned int shrink));
    35 static void perform_slip PARAMS ((bfd *abfd, unsigned int slip,
    36                                   asection *input_section, bfd_vma value));
    37 static boolean b_out_squirt_out_relocs PARAMS ((bfd *abfd, asection *section));
    38 static const bfd_target *b_out_callback PARAMS ((bfd *));
     31#include "libaout.h"            /* BFD a.out internal data structures.  */
     32
     33static int aligncode
     34  PARAMS ((bfd *abfd, asection *input_section, arelent *r,
     35           unsigned int shrink));
     36static void perform_slip
     37  PARAMS ((bfd *abfd, unsigned int slip, asection *input_section,
     38           bfd_vma value));
     39static bfd_boolean b_out_squirt_out_relocs
     40  PARAMS ((bfd *abfd, asection *section));
     41static const bfd_target *b_out_callback
     42  PARAMS ((bfd *));
    3943static bfd_reloc_status_type calljx_callback
    4044  PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR src, PTR dst,
     
    4246static bfd_reloc_status_type callj_callback
    4347  PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR data,
    44            unsigned int srcidx, unsigned int dstidx, asection *, boolean));
    45 static bfd_vma get_value PARAMS ((arelent *, struct bfd_link_info *,
    46                                   asection *));
    47 static int abs32code PARAMS ((bfd *, asection *, arelent *,
    48                               unsigned int, struct bfd_link_info *));
    49 static boolean b_out_bfd_relax_section PARAMS ((bfd *, asection *,
    50                                                 struct bfd_link_info *,
    51                                                 boolean *));
     48           unsigned int srcidx, unsigned int dstidx, asection *, bfd_boolean));
     49static bfd_vma get_value
     50  PARAMS ((arelent *, struct bfd_link_info *, asection *));
     51static int abs32code
     52  PARAMS ((bfd *, asection *, arelent *, unsigned int,
     53           struct bfd_link_info *));
     54static bfd_boolean b_out_bfd_relax_section
     55  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
    5256static bfd_byte *b_out_bfd_get_relocated_section_contents
    53   PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
    54            bfd_byte *, boolean, asymbol **));
     57  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
     58           bfd_boolean, asymbol **));
     59static int b_out_sizeof_headers
     60  PARAMS ((bfd *, bfd_boolean));
     61static bfd_boolean b_out_set_arch_mach
     62  PARAMS ((bfd *, enum bfd_architecture, unsigned long));
     63static bfd_boolean b_out_set_section_contents
     64  PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
     65static long b_out_get_reloc_upper_bound
     66  PARAMS ((bfd *, sec_ptr));
     67static long b_out_canonicalize_reloc
     68  PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
     69static bfd_boolean b_out_slurp_reloc_table
     70  PARAMS ((bfd *, sec_ptr, asymbol **));
     71static reloc_howto_type *b_out_bfd_reloc_type_lookup
     72  PARAMS ((bfd *, bfd_reloc_code_real_type));
     73static bfd_boolean b_out_write_object_contents
     74  PARAMS ((bfd *));
     75static int b_out_symbol_cmp
     76  PARAMS ((const void *, const void *));
     77static bfd_boolean b_out_mkobject
     78  PARAMS ((bfd *));
     79static const bfd_target *b_out_object_p
     80  PARAMS ((bfd *));
     81
     82void bout_swap_exec_header_in
     83  PARAMS ((bfd *, struct external_exec *, struct internal_exec *));
     84void bout_swap_exec_header_out
     85  PARAMS ((bfd *, struct internal_exec *, struct external_exec *));
    5586
    5687/* Swaps the information in an executable header taken from a raw byte
     
    6697
    6798  /* Now fill in fields in the execp, from the bytes in the raw data.  */
    68   execp->a_info   = bfd_h_get_32 (abfd, bytes->e_info);
     99  execp->a_info   = H_GET_32 (abfd, bytes->e_info);
    69100  execp->a_text   = GET_WORD (abfd, bytes->e_text);
    70101  execp->a_data   = GET_WORD (abfd, bytes->e_data);
     
    85116   supplied buffer ready for writing to disk.  */
    86117
    87 PROTO(void, bout_swap_exec_header_out,
    88           (bfd *abfd,
    89            struct internal_exec *execp,
    90            struct external_exec *raw_bytes));
    91118void
    92119bout_swap_exec_header_out (abfd, execp, raw_bytes)
     
    98125
    99126  /* Now fill in fields in the raw data, from the fields in the exec struct.  */
    100   bfd_h_put_32 (abfd, execp->a_info  , bytes->e_info);
     127  H_PUT_32 (abfd, execp->a_info  , bytes->e_info);
    101128  PUT_WORD (abfd, execp->a_text  , bytes->e_text);
    102129  PUT_WORD (abfd, execp->a_data  , bytes->e_data);
     
    120147  struct internal_exec anexec;
    121148  struct external_exec exec_bytes;
    122 
    123   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
    124       != EXEC_BYTES_SIZE) {
    125     if (bfd_get_error () != bfd_error_system_call)
     149  bfd_size_type amt = EXEC_BYTES_SIZE;
     150
     151  if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
     152    {
     153      if (bfd_get_error () != bfd_error_system_call)
     154        bfd_set_error (bfd_error_wrong_format);
     155      return 0;
     156    }
     157
     158  anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
     159
     160  if (N_BADMAG (anexec))
     161    {
    126162      bfd_set_error (bfd_error_wrong_format);
    127     return 0;
    128   }
    129 
    130   anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
    131 
    132   if (N_BADMAG (anexec)) {
    133     bfd_set_error (bfd_error_wrong_format);
    134     return 0;
    135   }
     163      return 0;
     164    }
    136165
    137166  bout_swap_exec_header_in (abfd, &exec_bytes, &anexec);
     
    149178  unsigned long bss_start;
    150179
    151   /* Architecture and machine type */
     180  /* Architecture and machine type. */
    152181  bfd_set_arch_mach(abfd,
    153182                    bfd_arch_i960, /* B.out only used on i960 */
     
    159188  obj_sym_filepos (abfd) = N_SYMOFF (*execp);
    160189
    161   /* The alignments of the sections */
     190  /* The alignments of the sections. */
    162191  obj_textsec (abfd)->alignment_power = execp->a_talign;
    163192  obj_datasec (abfd)->alignment_power = execp->a_dalign;
     
    171200  obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
    172201
    173   /* And reload the sizes, since the aout module zaps them */
     202  /* And reload the sizes, since the aout module zaps them. */
    174203  obj_textsec (abfd)->_raw_size = execp->a_text;
    175204
     
    179208  obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
    180209
    181   /* The file positions of the sections */
     210  /* The file positions of the sections. */
    182211  obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
    183212  obj_datasec (abfd)->filepos = N_DATOFF(*execp);
    184213
    185   /* The file positions of the relocation info */
     214  /* The file positions of the relocation info. */
    186215  obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
    187216  obj_datasec (abfd)->rel_filepos =  N_DROFF(*execp);
     
    196225}
    197226
    198 struct bout_data_struct {
     227struct bout_data_struct
     228  {
    199229    struct aoutdata a;
    200230    struct internal_exec e;
    201 };
    202 
    203 static boolean
     231  };
     232
     233static bfd_boolean
    204234b_out_mkobject (abfd)
    205235     bfd *abfd;
    206236{
    207237  struct bout_data_struct *rawptr;
    208 
    209   rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
     238  bfd_size_type amt = sizeof (struct bout_data_struct);
     239
     240  rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, amt);
    210241  if (rawptr == NULL)
    211     return false;
     242    return FALSE;
    212243
    213244  abfd->tdata.bout_data = rawptr;
    214245  exec_hdr (abfd) = &rawptr->e;
    215246
    216   obj_textsec (abfd) = (asection *)NULL;
    217   obj_datasec (abfd) = (asection *)NULL;
    218   obj_bsssec (abfd) = (asection *)NULL;
    219 
    220   return true;
     247  obj_textsec (abfd) = (asection *) NULL;
     248  obj_datasec (abfd) = (asection *) NULL;
     249  obj_bsssec (abfd) = (asection *) NULL;
     250
     251  return TRUE;
    221252}
    222253
    223254static int
    224 b_out_symbol_cmp (a, b)
    225      struct aout_symbol **a, **b;
    226 {
     255b_out_symbol_cmp (a_ptr, b_ptr)
     256     const void * a_ptr;
     257     const void * b_ptr;
     258{
     259  struct aout_symbol ** a = (struct aout_symbol **) a_ptr;
     260  struct aout_symbol ** b = (struct aout_symbol **) b_ptr;
    227261  asection *sec;
    228262  bfd_vma av, bv;
    229263
    230   /* Primary key is address */
     264  /* Primary key is address. */
    231265  sec = bfd_get_section (&(*a)->symbol);
    232266  av = sec->output_section->vma + sec->output_offset + (*a)->symbol.value;
     
    249283}
    250284
    251 static boolean
     285static bfd_boolean
    252286b_out_write_object_contents (abfd)
    253287     bfd *abfd;
    254288{
    255289  struct external_exec swapped_hdr;
     290  bfd_size_type amt;
    256291
    257292  if (! aout_32_make_sections (abfd))
    258     return false;
     293    return FALSE;
    259294
    260295  exec_hdr (abfd)->a_info = BMAGIC;
     
    279314  bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
    280315
     316  amt = EXEC_BYTES_SIZE;
    281317  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
    282       || (bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd)
    283           != EXEC_BYTES_SIZE))
    284     return false;
     318      || bfd_bwrite ((PTR) &swapped_hdr, amt, abfd) != amt)
     319    return FALSE;
    285320
    286321  /* Now write out reloc info, followed by syms and strings */
     
    308343
    309344      if (q > outsyms)
    310         qsort (outsyms, q - outsyms, sizeof (asymbol*), b_out_symbol_cmp);
     345        qsort (outsyms, (size_t) (q - outsyms), sizeof (asymbol*),
     346               b_out_symbol_cmp);
    311347
    312348      /* Back to your regularly scheduled program.  */
    313 
    314349      if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*exec_hdr(abfd))), SEEK_SET)
    315350          != 0)
    316         return false;
     351        return FALSE;
    317352
    318353      if (! aout_32_write_syms (abfd))
    319         return false;
    320 
    321       if (bfd_seek (abfd, (file_ptr) (N_TROFF(*exec_hdr(abfd))), SEEK_SET) != 0)
    322         return false;
    323 
    324       if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false;
     354        return FALSE;
     355
     356      if (bfd_seek (abfd, (file_ptr) (N_TROFF(*exec_hdr(abfd))), SEEK_SET)
     357          != 0)
     358        return FALSE;
     359
     360      if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd)))
     361        return FALSE;
    325362      if (bfd_seek (abfd, (file_ptr) (N_DROFF(*exec_hdr(abfd))), SEEK_SET)
    326363          != 0)
    327         return false;
    328 
    329       if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false;
    330     }
    331   return true;
    332 }
    333 
    334 
    335 /** Some reloc hackery */
     364        return FALSE;
     365
     366      if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd)))
     367        return FALSE;
     368    }
     369  return TRUE;
     370}
     371
     372
     373/* Some reloc hackery.  */
    336374
    337375#define CALLS     0x66003800    /* Template for 'calls' instruction     */
    338 #define BAL       0x0b000000    /* Template for 'bal' instruction */
     376#define BAL       0x0b000000    /* Template for 'bal' instruction       */
    339377#define BAL_MASK  0x00ffffff
    340378#define BALX      0x85f00000    /* Template for 'balx' instruction      */
     
    345383#define output_addr(sec) ((sec)->output_offset+(sec)->output_section->vma)
    346384
    347 /* Magic to turn callx into calljx */
     385/* Magic to turn callx into calljx.  */
     386
    348387static bfd_reloc_status_type
    349388calljx_callback (abfd, link_info, reloc_entry, src, dst, input_section)
     
    366405      aout_symbol_type *balsym = symbol+1;
    367406      int inst = bfd_get_32 (abfd, (bfd_byte *) src-4);
    368       /* The next symbol should be an N_BALNAME */
     407      /* The next symbol should be an N_BALNAME. */
    369408      BFD_ASSERT (IS_BALNAME (balsym->other));
    370409      inst &= BALX_MASK;
    371410      inst |= BALX;
    372       bfd_put_32 (abfd, inst, (bfd_byte *) dst-4);
     411      bfd_put_32 (abfd, (bfd_vma) inst, (bfd_byte *) dst-4);
    373412      symbol = balsym;
    374413      value = (symbol->symbol.value
     
    378417  word += value + reloc_entry->addend;
    379418
    380   bfd_put_32 (abfd, word, dst);
     419  bfd_put_32 (abfd, (bfd_vma) word, dst);
    381420  return bfd_reloc_ok;
    382421}
    383422
    384 /* Magic to turn call into callj */
     423/* Magic to turn call into callj.  */
     424
    385425static bfd_reloc_status_type
    386426callj_callback (abfd, link_info, reloc_entry,  data, srcidx, dstidx,
     
    393433     unsigned int dstidx;
    394434     asection *input_section;
    395      boolean shrinking;
     435     bfd_boolean shrinking;
    396436{
    397437  int word = bfd_get_32 (abfd, (bfd_byte *) data + srcidx);
     
    442482                     & BAL_MASK);
    443483    }
    444   bfd_put_32 (abfd, word, (bfd_byte *) data + dstidx);
     484  bfd_put_32 (abfd, (bfd_vma) word, (bfd_byte *) data + dstidx);
    445485  return bfd_reloc_ok;
    446486}
     
    460500#define ALIGNDONE 11
    461501static reloc_howto_type howto_reloc_callj =
    462 HOWTO(CALLJ, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callj", true, 0x00ffffff, 0x00ffffff,false);
     502HOWTO(CALLJ, 0, 2, 24, TRUE, 0, complain_overflow_signed, 0,"callj", TRUE, 0x00ffffff, 0x00ffffff,FALSE);
    463503static  reloc_howto_type howto_reloc_abs32 =
    464 HOWTO(ABS32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"abs32", true, 0xffffffff,0xffffffff,false);
     504HOWTO(ABS32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"abs32", TRUE, 0xffffffff,0xffffffff,FALSE);
    465505static reloc_howto_type howto_reloc_pcrel24 =
    466 HOWTO(PCREL24, 0, 2, 24, true, 0, complain_overflow_signed,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false);
     506HOWTO(PCREL24, 0, 2, 24, TRUE, 0, complain_overflow_signed,0,"pcrel24", TRUE, 0x00ffffff,0x00ffffff,FALSE);
    467507
    468508static reloc_howto_type howto_reloc_pcrel13 =
    469 HOWTO(PCREL13, 0, 2, 13, true, 0, complain_overflow_signed,0,"pcrel13", true, 0x00001fff,0x00001fff,false);
     509HOWTO(PCREL13, 0, 2, 13, TRUE, 0, complain_overflow_signed,0,"pcrel13", TRUE, 0x00001fff,0x00001fff,FALSE);
    470510
    471511static reloc_howto_type howto_reloc_abs32codeshrunk =
    472 HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callx->callj", true, 0x00ffffff, 0x00ffffff,false);
     512HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, TRUE, 0, complain_overflow_signed, 0,"callx->callj", TRUE, 0x00ffffff, 0x00ffffff,FALSE);
    473513
    474514static  reloc_howto_type howto_reloc_abs32code =
    475 HOWTO(ABS32CODE, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"callx", true, 0xffffffff,0xffffffff,false);
     515HOWTO(ABS32CODE, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,0,"callx", TRUE, 0xffffffff,0xffffffff,FALSE);
    476516
    477517static reloc_howto_type howto_align_table[] = {
    478   HOWTO (ALIGNER, 0, 0x1, 0, false, 0, complain_overflow_dont, 0, "align16", false, 0, 0, false),
    479   HOWTO (ALIGNER, 0, 0x3, 0, false, 0, complain_overflow_dont, 0, "align32", false, 0, 0, false),
    480   HOWTO (ALIGNER, 0, 0x7, 0, false, 0, complain_overflow_dont, 0, "align64", false, 0, 0, false),
    481   HOWTO (ALIGNER, 0, 0xf, 0, false, 0, complain_overflow_dont, 0, "align128", false, 0, 0, false),
     518  HOWTO (ALIGNER, 0, 0x1, 0, FALSE, 0, complain_overflow_dont, 0, "align16", FALSE, 0, 0, FALSE),
     519  HOWTO (ALIGNER, 0, 0x3, 0, FALSE, 0, complain_overflow_dont, 0, "align32", FALSE, 0, 0, FALSE),
     520  HOWTO (ALIGNER, 0, 0x7, 0, FALSE, 0, complain_overflow_dont, 0, "align64", FALSE, 0, 0, FALSE),
     521  HOWTO (ALIGNER, 0, 0xf, 0, FALSE, 0, complain_overflow_dont, 0, "align128", FALSE, 0, 0, FALSE),
    482522};
    483523
    484524static reloc_howto_type howto_done_align_table[] = {
    485   HOWTO (ALIGNDONE, 0x1, 0x1, 0, false, 0, complain_overflow_dont, 0, "donealign16", false, 0, 0, false),
    486   HOWTO (ALIGNDONE, 0x3, 0x3, 0, false, 0, complain_overflow_dont, 0, "donealign32", false, 0, 0, false),
    487   HOWTO (ALIGNDONE, 0x7, 0x7, 0, false, 0, complain_overflow_dont, 0, "donealign64", false, 0, 0, false),
    488   HOWTO (ALIGNDONE, 0xf, 0xf, 0, false, 0, complain_overflow_dont, 0, "donealign128", false, 0, 0, false),
     525  HOWTO (ALIGNDONE, 0x1, 0x1, 0, FALSE, 0, complain_overflow_dont, 0, "donealign16", FALSE, 0, 0, FALSE),
     526  HOWTO (ALIGNDONE, 0x3, 0x3, 0, FALSE, 0, complain_overflow_dont, 0, "donealign32", FALSE, 0, 0, FALSE),
     527  HOWTO (ALIGNDONE, 0x7, 0x7, 0, FALSE, 0, complain_overflow_dont, 0, "donealign64", FALSE, 0, 0, FALSE),
     528  HOWTO (ALIGNDONE, 0xf, 0xf, 0, FALSE, 0, complain_overflow_dont, 0, "donealign128", FALSE, 0, 0, FALSE),
    489529};
    490530
     
    508548}
    509549
    510 /* Allocate enough room for all the reloc entries, plus pointers to them all */
    511 
    512 static boolean
     550/* Allocate enough room for all the reloc entries, plus pointers to them all. */
     551
     552static bfd_boolean
    513553b_out_slurp_reloc_table (abfd, asect, symbols)
    514554     bfd *abfd;
     
    517557{
    518558  register struct relocation_info *rptr;
    519   unsigned int counter ;
    520   arelent *cache_ptr ;
     559  unsigned int counter;
     560  arelent *cache_ptr;
    521561  int extern_mask, pcrel_mask, callj_mask, length_shift;
    522562  int incode_mask;
     
    524564  bfd_vma prev_addr = 0;
    525565  unsigned int count;
    526   size_t  reloc_size;
     566  bfd_size_type reloc_size, amt;
    527567  struct relocation_info *relocs;
    528568  arelent *reloc_cache;
    529569
    530570  if (asect->relocation)
    531     return true;
     571    return TRUE;
     572
    532573  if (!aout_32_slurp_symbol_table (abfd))
    533     return false;
    534 
    535   if (asect == obj_datasec (abfd)) {
    536     reloc_size = exec_hdr(abfd)->a_drsize;
    537     goto doit;
    538   }
    539 
    540   if (asect == obj_textsec (abfd)) {
    541     reloc_size = exec_hdr(abfd)->a_trsize;
    542     goto doit;
    543   }
    544 
    545   if (asect == obj_bsssec (abfd)) {
    546     reloc_size = 0;
    547     goto doit;
    548   }
     574    return FALSE;
     575
     576  if (asect == obj_datasec (abfd))
     577    {
     578      reloc_size = exec_hdr(abfd)->a_drsize;
     579      goto doit;
     580    }
     581
     582  if (asect == obj_textsec (abfd))
     583    {
     584      reloc_size = exec_hdr(abfd)->a_trsize;
     585      goto doit;
     586    }
     587
     588  if (asect == obj_bsssec (abfd))
     589    {
     590      reloc_size = 0;
     591      goto doit;
     592    }
    549593
    550594  bfd_set_error (bfd_error_invalid_operation);
    551   return false;
     595  return FALSE;
    552596
    553597 doit:
    554   if (bfd_seek (abfd, (file_ptr) (asect->rel_filepos), SEEK_SET) != 0)
    555     return false;
     598  if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
     599    return FALSE;
    556600  count = reloc_size / sizeof (struct relocation_info);
    557601
    558602  relocs = (struct relocation_info *) bfd_malloc (reloc_size);
    559603  if (!relocs && reloc_size != 0)
    560     return false;
    561   reloc_cache = (arelent *) bfd_malloc ((count+1) * sizeof (arelent));
    562   if (!reloc_cache) {
    563     if (relocs != NULL)
    564       free ((char*)relocs);
    565     return false;
    566   }
    567 
    568   if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) {
    569     free (reloc_cache);
    570     if (relocs != NULL)
    571       free (relocs);
    572     return false;
    573   }
    574 
    575   if (bfd_header_big_endian (abfd)) {
    576     /* big-endian bit field allocation order */
    577     pcrel_mask  = 0x80;
    578     extern_mask = 0x10;
    579     incode_mask = 0x08;
    580     callj_mask  = 0x02;
    581     size_mask =   0x20;
    582     length_shift = 5;
    583   } else {
    584     /* little-endian bit field allocation order */
    585     pcrel_mask  = 0x01;
    586     extern_mask = 0x08;
    587     incode_mask = 0x10;
    588     callj_mask  = 0x40;
    589     size_mask   = 0x02;
    590     length_shift = 1;
    591   }
     604    return FALSE;
     605
     606  amt = ((bfd_size_type) count + 1) * sizeof (arelent);
     607  reloc_cache = (arelent *) bfd_malloc (amt);
     608  if (!reloc_cache)
     609    {
     610      if (relocs != NULL)
     611        free (relocs);
     612      return FALSE;
     613    }
     614
     615  if (bfd_bread ((PTR) relocs, reloc_size, abfd) != reloc_size)
     616    {
     617      free (reloc_cache);
     618      if (relocs != NULL)
     619        free (relocs);
     620      return FALSE;
     621    }
     622
     623  if (bfd_header_big_endian (abfd))
     624    {
     625      /* Big-endian bit field allocation order.  */
     626      pcrel_mask  = 0x80;
     627      extern_mask = 0x10;
     628      incode_mask = 0x08;
     629      callj_mask  = 0x02;
     630      size_mask =   0x20;
     631      length_shift = 5;
     632    }
     633  else
     634    {
     635      /* Little-endian bit field allocation order.  */
     636      pcrel_mask  = 0x01;
     637      extern_mask = 0x08;
     638      incode_mask = 0x10;
     639      callj_mask  = 0x40;
     640      size_mask   = 0x02;
     641      length_shift = 1;
     642    }
    592643
    593644  for (rptr = relocs, cache_ptr = reloc_cache, counter = 0;
     
    597648    unsigned char *raw = (unsigned char *)rptr;
    598649    unsigned int symnum;
    599     cache_ptr->address = bfd_h_get_32 (abfd, raw + 0);
     650
     651    cache_ptr->address = H_GET_32 (abfd, raw + 0);
    600652    cache_ptr->howto = 0;
     653
    601654    if (bfd_header_big_endian (abfd))
    602     {
    603655      symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6];
    604     }
    605656    else
    606     {
    607657      symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4];
    608     }
    609658
    610659    if (raw[7] & extern_mask)
    611     {
    612       /* if this is set then the r_index is a index into the symbol table;
    613        * if the bit is not set then r_index contains a section map.
    614        * we either fill in the sym entry with a pointer to the symbol,
    615        * or point to the correct section
    616        */
     660      {
     661        /* If this is set then the r_index is an index into the symbol table;
     662           if the bit is not set then r_index contains a section map.
     663           We either fill in the sym entry with a pointer to the symbol,
     664           or point to the correct section.  */
    617665      cache_ptr->sym_ptr_ptr = symbols + symnum;
    618666      cache_ptr->addend = 0;
    619     } else
    620     {
    621       /* in a.out symbols are relative to the beginning of the
    622        * file rather than sections ?
    623        * (look in translate_from_native_sym_flags)
    624        * the reloc entry addend has added to it the offset into the
    625        * file of the data, so subtract the base to make the reloc
    626        * section relative */
    627       int s;
     667      }
     668    else
    628669      {
    629         /* sign-extend symnum from 24 bits to whatever host uses */
     670        /* In a.out symbols are relative to the beginning of the
     671           file rather than sections ?
     672           (look in translate_from_native_sym_flags)
     673           The reloc entry addend has added to it the offset into the
     674           file of the data, so subtract the base to make the reloc
     675           section relative.  */
     676        int s;
     677
     678        /* Sign-extend symnum from 24 bits to whatever host uses.  */
    630679        s = symnum;
    631680        if (s & (1 << 23))
    632681          s |= (~0) << 24;
     682
     683        cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
     684        switch (s)
     685          {
     686          case N_TEXT:
     687          case N_TEXT | N_EXT:
     688            cache_ptr->sym_ptr_ptr = obj_textsec (abfd)->symbol_ptr_ptr;
     689            cache_ptr->addend = - obj_textsec (abfd)->vma;
     690            break;
     691          case N_DATA:
     692          case N_DATA | N_EXT:
     693            cache_ptr->sym_ptr_ptr = obj_datasec (abfd)->symbol_ptr_ptr;
     694            cache_ptr->addend = - obj_datasec (abfd)->vma;
     695            break;
     696          case N_BSS:
     697          case N_BSS | N_EXT:
     698            cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr;
     699            cache_ptr->addend =  - obj_bsssec (abfd)->vma;
     700            break;
     701          case N_ABS:
     702          case N_ABS | N_EXT:
     703            cache_ptr->sym_ptr_ptr = obj_bsssec (abfd)->symbol_ptr_ptr;
     704            cache_ptr->addend = 0;
     705            break;
     706          case -2: /* .align */
     707            if (raw[7] & pcrel_mask)
     708              {
     709                cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3];
     710                cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
     711              }
     712            else
     713              {
     714                /* .org? */
     715                abort ();
     716              }
     717            cache_ptr->addend = 0;
     718            break;
     719          default:
     720            BFD_ASSERT(0);
     721            break;
     722          }
    633723      }
    634       cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
    635       switch (s)
    636       {
    637        case N_TEXT:
    638        case N_TEXT | N_EXT:
    639         cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr;
    640         cache_ptr->addend = - obj_textsec(abfd)->vma;
    641         break;
    642        case N_DATA:
    643        case N_DATA | N_EXT:
    644         cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr;
    645         cache_ptr->addend = - obj_datasec(abfd)->vma;
    646         break;
    647        case N_BSS:
    648        case N_BSS | N_EXT:
    649         cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
    650         cache_ptr->addend =  - obj_bsssec(abfd)->vma;
    651         break;
    652        case N_ABS:
    653        case N_ABS | N_EXT:
    654         cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
    655         cache_ptr->addend = 0;
    656         break;
    657       case -2: /* .align */
    658         if (raw[7] & pcrel_mask)
    659           {
    660             cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3];
    661             cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
    662           }
    663         else
    664           {
    665             /* .org? */
    666             abort ();
    667           }
    668         cache_ptr->addend = 0;
    669         break;
    670        default:
    671         BFD_ASSERT(0);
    672         break;
    673       }
    674 
    675     }
    676 
    677     /* the i960 only has a few relocation types:
     724
     725    /* The i960 only has a few relocation types:
    678726       abs 32-bit and pcrel 24bit.   except for callj's!  */
    679727    if (cache_ptr->howto != 0)
    680728      ;
    681729    else if (raw[7] & callj_mask)
    682     {
    683       cache_ptr->howto = &howto_reloc_callj;
    684     }
     730      {
     731        cache_ptr->howto = &howto_reloc_callj;
     732      }
    685733    else if ( raw[7] & pcrel_mask)
    686     {
    687       if (raw[7] & size_mask)
    688        cache_ptr->howto = &howto_reloc_pcrel13;
    689       else
    690        cache_ptr->howto = &howto_reloc_pcrel24;
    691     }
     734      {
     735        if (raw[7] & size_mask)
     736          cache_ptr->howto = &howto_reloc_pcrel13;
     737        else
     738          cache_ptr->howto = &howto_reloc_pcrel24;
     739      }
    692740    else
    693     {
    694       if (raw[7] & incode_mask)
    695741      {
    696         cache_ptr->howto = &howto_reloc_abs32code;
     742        if (raw[7] & incode_mask)
     743          cache_ptr->howto = &howto_reloc_abs32code;
     744        else
     745          cache_ptr->howto = &howto_reloc_abs32;
    697746      }
    698       else
     747
     748    if (cache_ptr->address < prev_addr)
    699749      {
    700         cache_ptr->howto = &howto_reloc_abs32;
     750        /* Ouch! this reloc is out of order, insert into the right place.  */
     751        arelent tmp;
     752        arelent *cursor = cache_ptr-1;
     753        bfd_vma stop = cache_ptr->address;
     754
     755        tmp  = *cache_ptr;
     756        while (cursor->address > stop && cursor >= reloc_cache)
     757          {
     758            cursor[1] = cursor[0];
     759            cursor--;
     760          }
     761
     762        cursor[1] = tmp;
    701763      }
    702     }
    703     if (cache_ptr->address < prev_addr)
    704     {
    705       /* Ouch! this reloc is out of order, insert into the right place
    706        */
    707       arelent tmp;
    708       arelent *cursor = cache_ptr-1;
    709       bfd_vma stop = cache_ptr->address;
    710       tmp  = *cache_ptr;
    711       while (cursor->address > stop && cursor >= reloc_cache)
     764    else
    712765      {
    713         cursor[1] = cursor[0];
    714         cursor--;
     766        prev_addr = cache_ptr->address;
    715767      }
    716       cursor[1] = tmp;
    717     }
    718     else
    719     {
    720       prev_addr = cache_ptr->address;
    721     }
    722768  }
    723769
     
    727773  asect->reloc_count = count;
    728774
    729   return true;
    730 }
    731 
    732 static boolean
     775  return TRUE;
     776}
     777
     778static bfd_boolean
    733779b_out_squirt_out_relocs (abfd, section)
    734780     bfd *abfd;
     
    742788  unsigned int count = section->reloc_count;
    743789  struct relocation_info *native, *natptr;
    744   size_t natsize = count * sizeof (struct relocation_info);
    745   int extern_mask, pcrel_mask,  len_2, callj_mask;
    746   if (count == 0) return true;
    747   generic   = section->orelocation;
     790  bfd_size_type natsize;
     791  int extern_mask, pcrel_mask, len_2, callj_mask;
     792
     793  if (count == 0)
     794    return TRUE;
     795
     796  generic = section->orelocation;
     797  natsize = (bfd_size_type) count * sizeof (struct relocation_info);
    748798  native = ((struct relocation_info *) bfd_malloc (natsize));
    749799  if (!native && natsize != 0)
    750     return false;
     800    return FALSE;
    751801
    752802  if (bfd_header_big_endian (abfd))
    753   {
    754     /* Big-endian bit field allocation order */
    755     pcrel_mask  = 0x80;
    756     extern_mask = 0x10;
    757     len_2       = 0x40;
    758     len_1       = 0x20;
    759     callj_mask  = 0x02;
    760     incode_mask = 0x08;
    761   }
     803    {
     804      /* Big-endian bit field allocation order. */
     805      pcrel_mask  = 0x80;
     806      extern_mask = 0x10;
     807      len_2       = 0x40;
     808      len_1       = 0x20;
     809      callj_mask  = 0x02;
     810      incode_mask = 0x08;
     811    }
    762812  else
    763   {
    764     /* Little-endian bit field allocation order */
    765     pcrel_mask  = 0x01;
    766     extern_mask = 0x08;
    767     len_2       = 0x04;
    768     len_1       = 0x02;
    769     callj_mask  = 0x40;
    770     incode_mask = 0x10;
    771   }
     813    {
     814      /* Little-endian bit field allocation order. */
     815      pcrel_mask  = 0x01;
     816      extern_mask = 0x08;
     817      len_2       = 0x04;
     818      len_1       = 0x02;
     819      callj_mask  = 0x40;
     820      incode_mask = 0x10;
     821    }
    772822
    773823  for (natptr = native; count > 0; --count, ++natptr, ++generic)
    774   {
    775     arelent *g = *generic;
    776     unsigned char *raw = (unsigned char *)natptr;
    777     asymbol *sym = *(g->sym_ptr_ptr);
    778 
    779     asection *output_section = sym->section->output_section;
    780 
    781     bfd_h_put_32(abfd, g->address, raw);
    782     /* Find a type in the output format which matches the input howto -
    783      * at the moment we assume input format == output format FIXME!!
    784      */
    785     r_idx = 0;
    786     /* FIXME:  Need callj stuff here, and to check the howto entries to
    787        be sure they are real for this architecture.  */
    788     if (g->howto== &howto_reloc_callj)
    789     {
    790       raw[7] = callj_mask + pcrel_mask + len_2;
    791     }
    792     else if (g->howto == &howto_reloc_pcrel24)
    793     {
    794       raw[7] = pcrel_mask + len_2;
    795     }
    796     else if (g->howto == &howto_reloc_pcrel13)
    797     {
    798       raw[7] = pcrel_mask + len_1;
    799     }
    800     else if (g->howto == &howto_reloc_abs32code)
    801     {
    802       raw[7] = len_2 + incode_mask;
    803     }
    804     else if (g->howto >= howto_align_table
    805              && g->howto <= (howto_align_table
    806                             + sizeof (howto_align_table) / sizeof (howto_align_table[0])
    807                             - 1))
    808       {
    809         /* symnum == -2; extern_mask not set, pcrel_mask set */
    810         r_idx = -2;
    811         r_extern = 0;
    812         raw[7] = (pcrel_mask
    813                   | ((g->howto - howto_align_table) << 1));
    814       }
    815     else {
    816       raw[7] = len_2;
    817     }
    818 
    819     if (r_idx != 0)
    820       /* already mucked with r_extern, r_idx */;
    821     else if (bfd_is_com_section (output_section)
    822              || bfd_is_abs_section (output_section)
    823              || bfd_is_und_section (output_section))
    824     {
    825 
    826       if (bfd_abs_section_ptr->symbol == sym)
    827       {
    828         /* Whoops, looked like an abs symbol, but is really an offset
    829            from the abs section */
    830         r_idx = 0;
    831         r_extern = 0;
    832        }
     824    {
     825      arelent *g = *generic;
     826      unsigned char *raw = (unsigned char *)natptr;
     827      asymbol *sym = *(g->sym_ptr_ptr);
     828      asection *output_section = sym->section->output_section;
     829
     830      H_PUT_32 (abfd, g->address, raw);
     831      /* Find a type in the output format which matches the input howto -
     832         at the moment we assume input format == output format FIXME!!  */
     833      r_idx = 0;
     834      /* FIXME:  Need callj stuff here, and to check the howto entries to
     835         be sure they are real for this architecture.  */
     836      if (g->howto== &howto_reloc_callj)
     837        raw[7] = callj_mask + pcrel_mask + len_2;
     838      else if (g->howto == &howto_reloc_pcrel24)
     839        raw[7] = pcrel_mask + len_2;
     840      else if (g->howto == &howto_reloc_pcrel13)
     841        raw[7] = pcrel_mask + len_1;
     842      else if (g->howto == &howto_reloc_abs32code)
     843        raw[7] = len_2 + incode_mask;
     844      else if (g->howto >= howto_align_table
     845               && g->howto <= (howto_align_table
     846                               + sizeof (howto_align_table) / sizeof (howto_align_table[0])
     847                               - 1))
     848        {
     849          /* symnum == -2; extern_mask not set, pcrel_mask set.  */
     850          r_idx = -2;
     851          r_extern = 0;
     852          raw[7] = (pcrel_mask
     853                    | ((g->howto - howto_align_table) << 1));
     854        }
    833855      else
    834       {
    835         /* Fill in symbol */
    836 
    837         r_extern = 1;
    838         r_idx = (*g->sym_ptr_ptr)->udata.i;
    839       }
    840     }
    841     else
    842     {
    843       /* Just an ordinary section */
    844       r_extern = 0;
    845       r_idx  = output_section->target_index;
    846     }
    847 
    848     if (bfd_header_big_endian (abfd)) {
    849       raw[4] = (unsigned char) (r_idx >> 16);
    850       raw[5] = (unsigned char) (r_idx >>  8);
    851       raw[6] = (unsigned char) (r_idx     );
    852     } else {
    853       raw[6] = (unsigned char) (r_idx >> 16);
    854       raw[5] = (unsigned char) (r_idx>>  8);
    855       raw[4] = (unsigned char) (r_idx     );
    856     }
    857     if (r_extern)
    858      raw[7] |= extern_mask;
    859   }
    860 
    861   if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
    862     free((PTR)native);
    863     return false;
    864   }
     856        raw[7] = len_2;
     857
     858      if (r_idx != 0)
     859        /* Already mucked with r_extern, r_idx.  */;
     860      else if (bfd_is_com_section (output_section)
     861               || bfd_is_abs_section (output_section)
     862               || bfd_is_und_section (output_section))
     863        {
     864          if (bfd_abs_section_ptr->symbol == sym)
     865            {
     866              /* Whoops, looked like an abs symbol, but is really an offset
     867                 from the abs section.  */
     868              r_idx = 0;
     869              r_extern = 0;
     870            }
     871          else
     872            {
     873              /* Fill in symbol.  */
     874              r_extern = 1;
     875              r_idx = (*g->sym_ptr_ptr)->udata.i;
     876            }
     877        }
     878      else
     879        {
     880          /* Just an ordinary section.  */
     881          r_extern = 0;
     882          r_idx  = output_section->target_index;
     883        }
     884
     885      if (bfd_header_big_endian (abfd))
     886        {
     887          raw[4] = (unsigned char) (r_idx >> 16);
     888          raw[5] = (unsigned char) (r_idx >>  8);
     889          raw[6] = (unsigned char) (r_idx      );
     890        }
     891      else
     892        {
     893          raw[6] = (unsigned char) (r_idx >> 16);
     894          raw[5] = (unsigned char) (r_idx>>   8);
     895          raw[4] = (unsigned char) (r_idx      );
     896        }
     897
     898      if (r_extern)
     899        raw[7] |= extern_mask;
     900    }
     901
     902  if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
     903    {
     904      free ((PTR)native);
     905      return FALSE;
     906    }
     907
    865908  free ((PTR)native);
    866909
    867   return true;
    868 }
    869 
    870 /* This is stupid.  This function should be a boolean predicate */
     910  return TRUE;
     911}
     912
     913/* This is stupid.  This function should be a boolean predicate.  */
     914
    871915static long
    872916b_out_canonicalize_reloc (abfd, section, relptr, symbols)
     
    882926    {
    883927      arelent_chain *chain = section->constructor_chain;
     928
    884929      for (count = 0; count < section->reloc_count; count++)
    885930        {
     
    909954     sec_ptr asect;
    910955{
    911   if (bfd_get_format (abfd) != bfd_object) {
    912     bfd_set_error (bfd_error_invalid_operation);
    913     return -1;
    914   }
     956  if (bfd_get_format (abfd) != bfd_object)
     957    {
     958      bfd_set_error (bfd_error_invalid_operation);
     959      return -1;
     960    }
    915961
    916962  if (asect->flags & SEC_CONSTRUCTOR)
     
    935981
    936982
    937 static boolean
     983
     984static bfd_boolean
    938985b_out_set_section_contents (abfd, section, location, offset, count)
    939986     bfd *abfd;
     
    943990     bfd_size_type count;
    944991{
    945 
    946   if (abfd->output_has_begun == false) { /* set by bfd.c handler */
    947     if (! aout_32_make_sections (abfd))
    948       return false;
    949 
    950     obj_textsec (abfd)->filepos = sizeof (struct internal_exec);
    951     obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos
    952                                  +  obj_textsec (abfd)->_raw_size;
    953 
    954   }
    955   /* regardless, once we know what we're doing, we might as well get going */
     992  if (! abfd->output_has_begun)
     993    {
     994      /* Set by bfd.c handler.  */
     995      if (! aout_32_make_sections (abfd))
     996        return FALSE;
     997
     998      obj_textsec (abfd)->filepos = sizeof (struct internal_exec);
     999      obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos
     1000        +  obj_textsec (abfd)->_raw_size;
     1001    }
     1002
     1003  /* Regardless, once we know what we're doing, we might as well get going.  */
    9561004  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
    957     return false;
    958 
    959   if (count != 0) {
    960     return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false;
    961   }
    962   return true;
    963 }
    964 
    965 static boolean
     1005    return FALSE;
     1006
     1007  if (count == 0)
     1008    return TRUE;
     1009
     1010  return bfd_bwrite ((PTR) location, count, abfd) == count;
     1011}
     1012
     1013static bfd_boolean
    9661014b_out_set_arch_mach (abfd, arch, machine)
    9671015     bfd *abfd;
     
    9711019  bfd_default_set_arch_mach(abfd, arch, machine);
    9721020
    973   if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */
    974     return true;
    975   if (arch == bfd_arch_i960)    /* i960 default is OK */
    976     switch (machine) {
    977     case bfd_mach_i960_core:
    978     case bfd_mach_i960_kb_sb:
    979     case bfd_mach_i960_mc:
    980     case bfd_mach_i960_xa:
    981     case bfd_mach_i960_ca:
    982     case bfd_mach_i960_ka_sa:
    983     case bfd_mach_i960_jx:
    984     case bfd_mach_i960_hx:
    985     case 0:
    986       return true;
    987     default:
    988       return false;
    989     }
    990 
    991   return false;
     1021  if (arch == bfd_arch_unknown) /* Unknown machine arch is OK.  */
     1022    return TRUE;
     1023
     1024  if (arch == bfd_arch_i960)    /* i960 default is OK.  */
     1025    switch (machine)
     1026      {
     1027      case bfd_mach_i960_core:
     1028      case bfd_mach_i960_kb_sb:
     1029      case bfd_mach_i960_mc:
     1030      case bfd_mach_i960_xa:
     1031      case bfd_mach_i960_ca:
     1032      case bfd_mach_i960_ka_sa:
     1033      case bfd_mach_i960_jx:
     1034      case bfd_mach_i960_hx:
     1035      case 0:
     1036        return TRUE;
     1037      default:
     1038        return FALSE;
     1039      }
     1040
     1041  return FALSE;
    9921042}
    9931043
     
    9951045b_out_sizeof_headers (ignore_abfd, ignore)
    9961046     bfd *ignore_abfd ATTRIBUTE_UNUSED;
    997      boolean ignore ATTRIBUTE_UNUSED;
     1047     bfd_boolean ignore ATTRIBUTE_UNUSED;
    9981048{
    9991049  return sizeof (struct internal_exec);
    10001050}
    10011051
    1002 /************************************************************************/
     1052
     1053
    10031054static bfd_vma
    10041055get_value (reloc, link_info, input_section)
     
    10121063  /* A symbol holds a pointer to a section, and an offset from the
    10131064     base of the section.  To relocate, we find where the section will
    1014      live in the output and add that in */
    1015 
     1065     live in the output and add that in.  */
    10161066  if (bfd_is_und_section (symbol->section))
    10171067    {
     
    10251075      h = bfd_wrapped_link_hash_lookup (input_section->owner, link_info,
    10261076                                        bfd_asymbol_name (symbol),
    1027                                         false, false, true);
     1077                                        FALSE, FALSE, TRUE);
    10281078      if (h != (struct bfd_link_hash_entry *) NULL
    10291079          && (h->type == bfd_link_hash_defined
     
    10381088                 (link_info, bfd_asymbol_name (symbol),
    10391089                  input_section->owner, input_section, reloc->address,
    1040                   true)))
     1090                  TRUE)))
    10411091            abort ();
    10421092          value = 0;
     
    10481098    }
    10491099
    1050   /* Add the value contained in the relocation */
     1100  /* Add the value contained in the relocation. */
    10511101  value += reloc->addend;
    10521102
     
    10671117
    10681118  /* Find all symbols past this point, and make them know
    1069      what's happened */
     1119     what's happened. */
    10701120  while (*s)
    1071   {
    1072     asymbol *p = *s;
    1073     if (p->section == input_section)
    1074     {
    1075       /* This was pointing into this section, so mangle it */
    1076       if (p->value > value)
    1077       {
    1078         p->value -=slip;
    1079         if (p->udata.p != NULL)
    1080           {
    1081             struct generic_link_hash_entry *h;
    1082 
    1083             h = (struct generic_link_hash_entry *) p->udata.p;
    1084             BFD_ASSERT (h->root.type == bfd_link_hash_defined);
    1085             h->root.u.def.value -= slip;
    1086             BFD_ASSERT (h->root.u.def.value == p->value);
    1087           }
    1088       }
    1089     }
    1090     s++;
    1091 
    1092   }
     1121    {
     1122      asymbol *p = *s;
     1123
     1124      if (p->section == input_section)
     1125        {
     1126          /* This was pointing into this section, so mangle it.  */
     1127          if (p->value > value)
     1128            {
     1129              p->value -=slip;
     1130
     1131              if (p->udata.p != NULL)
     1132                {
     1133                  struct generic_link_hash_entry *h;
     1134
     1135                  h = (struct generic_link_hash_entry *) p->udata.p;
     1136                  BFD_ASSERT (h->root.type == bfd_link_hash_defined);
     1137                  h->root.u.def.value -= slip;
     1138                  BFD_ASSERT (h->root.u.def.value == p->value);
     1139                }
     1140            }
     1141        }
     1142      s++;
     1143    }
    10931144}
    10941145
    10951146/* This routine works out if the thing we want to get to can be
    10961147   reached with a 24bit offset instead of a 32 bit one.
    1097    If it can, then it changes the amode */
     1148   If it can, then it changes the amode. */
    10981149
    10991150static int
     
    11111162  /* See if the address we're looking at within 2^23 bytes of where
    11121163     we are, if so then we can use a small branch rather than the
    1113      jump we were going to */
    1114 
     1164     jump we were going to.  */
    11151165  gap = value - (dot - shrink);
    11161166
    1117   if (-1<<23 < (long)gap && (long)gap < 1<<23 )
    1118   {
    1119     /* Change the reloc type from 32bitcode possible 24, to 24bit
    1120        possible 32 */
    1121 
    1122     r->howto = &howto_reloc_abs32codeshrunk;
    1123     /* The place to relc moves back by four bytes */
    1124     r->address -=4;
    1125 
    1126     /* This will be four bytes smaller in the long run */
    1127     shrink += 4 ;
    1128     perform_slip (abfd, 4, input_section, r->address-shrink + 4);
    1129   }
     1167  if (-1 << 23 < (long)gap && (long)gap < 1 << 23)
     1168    {
     1169      /* Change the reloc type from 32bitcode possible 24, to 24bit
     1170         possible 32. */
     1171      r->howto = &howto_reloc_abs32codeshrunk;
     1172      /* The place to relc moves back by four bytes.  */
     1173      r->address -=4;
     1174
     1175      /* This will be four bytes smaller in the long run.  */
     1176      shrink += 4 ;
     1177      perform_slip (abfd, 4, input_section, r->address-shrink + 4);
     1178    }
     1179
    11301180  return shrink;
    11311181}
     
    11421192  bfd_vma old_end;
    11431193  bfd_vma new_end;
    1144   int shrink_delta;
     1194  unsigned int shrink_delta;
    11451195  int size = r->howto->size;
    11461196
     
    11491199     than the alignment required.  */
    11501200
    1151   /* calculate the first byte following the padding before we optimize */
     1201  /* Calculate the first byte following the padding before we optimize. */
    11521202  old_end = ((dot + size ) & ~size) + size+1;
    1153   /* work out where the new end will be - remember that we're smaller
    1154      than we used to be */
     1203  /* Work out where the new end will be - remember that we're smaller
     1204     than we used to be. */
    11551205  new_end = ((dot - shrink + size) & ~size);
    11561206
    1157   /* This is the new end */
     1207  /* This is the new end. */
    11581208  gap = old_end - ((dot + size) & ~size);
    11591209
     
    11611211
    11621212  if (shrink_delta)
    1163   {
    1164     /* Change the reloc so that it knows how far to align to */
    1165     r->howto = howto_done_align_table + (r->howto - howto_align_table);
    1166 
    1167     /* Encode the stuff into the addend - for future use we need to
    1168        know how big the reloc used to be */
    1169     r->addend = old_end - dot + r->address;
    1170 
    1171     /* This will be N bytes smaller in the long run, adjust all the symbols */
    1172     perform_slip (abfd, shrink_delta, input_section, r->address - shrink);
    1173     shrink += shrink_delta;
    1174   }
     1213    {
     1214      /* Change the reloc so that it knows how far to align to.  */
     1215      r->howto = howto_done_align_table + (r->howto - howto_align_table);
     1216
     1217      /* Encode the stuff into the addend - for future use we need to
     1218         know how big the reloc used to be.  */
     1219      r->addend = old_end - dot + r->address;
     1220
     1221      /* This will be N bytes smaller in the long run, adjust all the symbols.  */
     1222      perform_slip (abfd, shrink_delta, input_section, r->address - shrink);
     1223      shrink += shrink_delta;
     1224    }
     1225
    11751226  return shrink;
    11761227}
    11771228
    1178 static boolean
     1229static bfd_boolean
    11791230b_out_bfd_relax_section (abfd, i, link_info, again)
    11801231     bfd *abfd;
    11811232     asection *i;
    11821233     struct bfd_link_info *link_info;
    1183      boolean *again;
    1184 {
    1185   /* Get enough memory to hold the stuff */
     1234     bfd_boolean *again;
     1235{
     1236  /* Get enough memory to hold the stuff. */
    11861237  bfd *input_bfd = i->owner;
    11871238  asection *input_section = i;
    1188   int shrink = 0 ;
     1239  unsigned int shrink = 0 ;
    11891240  arelent **reloc_vector = NULL;
    1190   long reloc_size = bfd_get_reloc_upper_bound(input_bfd,
    1191                                               input_section);
     1241  long reloc_size = bfd_get_reloc_upper_bound (input_bfd,
     1242                                               input_section);
    11921243
    11931244  if (reloc_size < 0)
    1194     return false;
     1245    return FALSE;
    11951246
    11961247  /* We only run this relaxation once.  It might work to run it
    11971248     multiple times, but it hasn't been tested.  */
    1198   *again = false;
     1249  *again = FALSE;
    11991250
    12001251  if (reloc_size)
     
    12021253      long reloc_count;
    12031254
    1204       reloc_vector = (arelent **) bfd_malloc (reloc_size);
     1255      reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);
    12051256      if (reloc_vector == NULL && reloc_size != 0)
    12061257        goto error_return;
    12071258
    1208       /* Get the relocs and think about them */
     1259      /* Get the relocs and think about them. */
    12091260      reloc_count =
    12101261        bfd_canonicalize_reloc (input_bfd, input_section, reloc_vector,
     
    12151266        {
    12161267          arelent **parent;
     1268
    12171269          for (parent = reloc_vector; *parent; parent++)
    12181270            {
    12191271              arelent *r = *parent;
     1272
    12201273              switch (r->howto->type)
    12211274                {
    12221275                case ALIGNER:
    1223                   /* An alignment reloc */
     1276                  /* An alignment reloc. */
    12241277                  shrink = aligncode (abfd, input_section, r, shrink);
    12251278                  break;
    12261279                case ABS32CODE:
    1227                   /* A 32bit reloc in an addressing mode */
     1280                  /* A 32bit reloc in an addressing mode. */
    12281281                  shrink = abs32code (input_bfd, input_section, r, shrink,
    12291282                                      link_info);
    12301283                  break;
    12311284                case ABS32CODE_SHRUNK:
    1232                   shrink+=4;
     1285                  shrink += 4;
    12331286                  break;
    12341287                }
     
    12401293  if (reloc_vector != NULL)
    12411294    free (reloc_vector);
    1242   return true;
     1295  return TRUE;
    12431296 error_return:
    12441297  if (reloc_vector != NULL)
    12451298    free (reloc_vector);
    1246   return false;
     1299  return FALSE;
    12471300}
    12481301
     
    12541307     struct bfd_link_order *link_order;
    12551308     bfd_byte *data;
    1256      boolean relocateable;
     1309     bfd_boolean relocateable;
    12571310     asymbol **symbols;
    12581311{
    1259   /* Get enough memory to hold the stuff */
     1312  /* Get enough memory to hold the stuff. */
    12601313  bfd *input_bfd = link_order->u.indirect.section->owner;
    12611314  asection *input_section = link_order->u.indirect.section;
     
    12751328                                                       symbols);
    12761329
    1277   reloc_vector = (arelent **) bfd_malloc (reloc_size);
     1330  reloc_vector = (arelent **) bfd_malloc ((bfd_size_type) reloc_size);
    12781331  if (reloc_vector == NULL && reloc_size != 0)
    12791332    goto error_return;
     
    12811334  input_section->reloc_done = 1;
    12821335
    1283   /* read in the section */
    1284   BFD_ASSERT (true == bfd_get_section_contents (input_bfd,
    1285                                                 input_section,
    1286                                                 data,
    1287                                                 0,
    1288                                                 input_section->_raw_size));
     1336  /* Read in the section. */
     1337  BFD_ASSERT (bfd_get_section_contents (input_bfd,
     1338                                        input_section,
     1339                                        data,
     1340                                        (bfd_vma) 0,
     1341                                        input_section->_raw_size));
    12891342
    12901343  reloc_count = bfd_canonicalize_reloc (input_bfd,
     
    12981351      arelent **parent = reloc_vector;
    12991352      arelent *reloc ;
    1300 
    13011353      unsigned int dst_address = 0;
    13021354      unsigned int src_address = 0;
     
    13041356      unsigned int idx;
    13051357
    1306       /* Find how long a run we can do */
     1358      /* Find how long a run we can do. */
    13071359      while (dst_address < link_order->size)
    13081360        {
     
    13121364              /* Note that the relaxing didn't tie up the addresses in the
    13131365                 relocation, so we use the original address to work out the
    1314                  run of non-relocated data */
     1366                 run of non-relocated data. */
    13151367              BFD_ASSERT (reloc->address >= src_address);
    13161368              run = reloc->address - src_address;
     
    13211373              run = link_order->size - dst_address;
    13221374            }
    1323           /* Copy the bytes */
     1375
     1376          /* Copy the bytes.  */
    13241377          for (idx = 0; idx < run; idx++)
    1325             {
    1326               data[dst_address++] = data[src_address++];
    1327             }
    1328 
    1329           /* Now do the relocation */
    1330 
     1378            data[dst_address++] = data[src_address++];
     1379
     1380          /* Now do the relocation.  */
    13311381          if (reloc)
    13321382            {
     
    13371387                                   src_address + data, dst_address + data,
    13381388                                   input_section);
    1339                   src_address+=4;
    1340                   dst_address+=4;
     1389                  src_address += 4;
     1390                  dst_address += 4;
    13411391                  break;
    13421392                case ABS32:
     
    13451395                               + get_value (reloc, link_info, input_section)),
    13461396                              data + dst_address);
    1347                   src_address+=4;
    1348                   dst_address+=4;
     1397                  src_address += 4;
     1398                  dst_address += 4;
    13491399                  break;
    13501400                case CALLJ:
    13511401                  callj_callback (input_bfd, link_info, reloc, data,
    13521402                                  src_address, dst_address, input_section,
    1353                                   false);
    1354                   src_address+=4;
    1355                   dst_address+=4;
     1403                                  FALSE);
     1404                  src_address += 4;
     1405                  dst_address += 4;
    13561406                  break;
    13571407                case ALIGNDONE:
    13581408                  BFD_ASSERT (reloc->addend >= src_address);
    1359                   BFD_ASSERT (reloc->addend <= input_section->_raw_size);
     1409                  BFD_ASSERT ((bfd_vma) reloc->addend
     1410                              <= input_section->_raw_size);
    13601411                  src_address = reloc->addend;
    13611412                  dst_address = ((dst_address + reloc->howto->size)
     
    13671418                  callj_callback (input_bfd, link_info, reloc, data,
    13681419                                  src_address + 4, dst_address, input_section,
    1369                                   true);
    1370                   dst_address+=4;
    1371                   src_address+=8;
     1420                                  TRUE);
     1421                  dst_address += 4;
     1422                  src_address += 8;
    13721423                  break;
    13731424                case PCREL24:
     
    13851436                               & BAL_MASK));
    13861437
    1387                     bfd_put_32 (input_bfd, word, data + dst_address);
    1388                     dst_address+=4;
    1389                     src_address+=4;
     1438                    bfd_put_32 (input_bfd, (bfd_vma) word, data + dst_address);
     1439                    dst_address += 4;
     1440                    src_address += 4;
    13901441
    13911442                  }
    13921443                  break;
    1393 
    13941444                case PCREL13:
    13951445                  {
     
    14061456                               & PCREL13_MASK));
    14071457
    1408                     bfd_put_32 (input_bfd, word, data + dst_address);
    1409                     dst_address+=4;
    1410                     src_address+=4;
    1411 
     1458                    bfd_put_32 (input_bfd, (bfd_vma) word, data + dst_address);
     1459                    dst_address += 4;
     1460                    src_address += 4;
    14121461                  }
    14131462                  break;
     
    14271476  return NULL;
    14281477}
    1429 /***********************************************************************/
     1478
     1479
    14301480
    14311481/* Build the transfer vectors for Big and Little-Endian B.OUT files.  */
     
    14351485
    14361486#define b_out_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
     1487#define b_out_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
    14371488#define b_out_bfd_link_add_symbols _bfd_generic_link_add_symbols
     1489#define b_out_bfd_link_just_syms _bfd_generic_link_just_syms
    14381490#define b_out_bfd_final_link _bfd_generic_final_link
    14391491#define b_out_bfd_link_split_section  _bfd_generic_link_split_section
    14401492#define b_out_bfd_gc_sections  bfd_generic_gc_sections
     1493#define b_out_bfd_merge_sections  bfd_generic_merge_sections
     1494#define b_out_bfd_discard_group bfd_generic_discard_group
    14411495
    14421496#define aout_32_get_section_contents_in_window \
Note: See TracChangeset for help on using the changeset viewer.