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/aout-adobe.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for a.out.adobe binaries.
    2    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000
     2   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
     3   2002
    34   Free Software Foundation, Inc.
    45   Written by Cygnus Support.  Based on bout.c.
     
    2728
    2829#include "aout/stab_gnu.h"
    29 #include "libaout.h"            /* BFD a.out internal data structures */
     30#include "libaout.h"            /* BFD a.out internal data structures. */
    3031
    3132/* Forward decl.  */
    3233extern const bfd_target a_out_adobe_vec;
    3334
    34 static const bfd_target *aout_adobe_callback PARAMS ((bfd *));
    35 
    36 extern boolean aout_32_slurp_symbol_table PARAMS ((bfd *abfd));
    37 extern boolean aout_32_write_syms PARAMS ((bfd *));
    38 static void aout_adobe_write_section PARAMS ((bfd *abfd, sec_ptr sect));
     35static const bfd_target *aout_adobe_callback
     36  PARAMS ((bfd *));
     37extern bfd_boolean aout_32_slurp_symbol_table
     38  PARAMS ((bfd *abfd));
     39extern bfd_boolean aout_32_write_syms
     40  PARAMS ((bfd *));
     41static void aout_adobe_write_section
     42  PARAMS ((bfd *abfd, sec_ptr sect));
     43static const bfd_target * aout_adobe_object_p
     44  PARAMS ((bfd *));
     45static bfd_boolean aout_adobe_mkobject
     46  PARAMS ((bfd *));
     47static bfd_boolean aout_adobe_write_object_contents
     48  PARAMS ((bfd *));
     49static bfd_boolean aout_adobe_set_section_contents
     50  PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
     51static bfd_boolean aout_adobe_set_arch_mach
     52  PARAMS ((bfd *, enum bfd_architecture, unsigned long));
     53static int     aout_adobe_sizeof_headers
     54  PARAMS ((bfd *, bfd_boolean));
    3955
    4056/* Swaps the information in an executable header taken from a raw byte
     
    4258
    4359void aout_adobe_swap_exec_header_in
    44   PARAMS ((bfd *abfd, struct external_exec *raw_bytes,
    45            struct internal_exec *execp));
     60  PARAMS ((bfd *, struct external_exec *, struct internal_exec *));
    4661
    4762void
     
    5469
    5570  /* Now fill in fields in the execp, from the bytes in the raw data.  */
    56   execp->a_info   = bfd_h_get_32 (abfd, bytes->e_info);
     71  execp->a_info   = H_GET_32 (abfd, bytes->e_info);
    5772  execp->a_text   = GET_WORD (abfd, bytes->e_text);
    5873  execp->a_data   = GET_WORD (abfd, bytes->e_data);
     
    6782   supplied buffer ready for writing to disk.  */
    6883
    69 PROTO(void, aout_adobe_swap_exec_header_out,
    70           (bfd *abfd,
    71            struct internal_exec *execp,
    72            struct external_exec *raw_bytes));
     84void aout_adobe_swap_exec_header_out
     85  PARAMS ((bfd *, struct internal_exec *, struct external_exec *));
     86
    7387void
    7488aout_adobe_swap_exec_header_out (abfd, execp, raw_bytes)
     
    8195  /* Now fill in fields in the raw data, from the fields in the exec
    8296     struct.  */
    83   bfd_h_put_32 (abfd, execp->a_info  , bytes->e_info);
     97  H_PUT_32 (abfd, execp->a_info  , bytes->e_info);
    8498  PUT_WORD (abfd, execp->a_text  , bytes->e_text);
    8599  PUT_WORD (abfd, execp->a_data  , bytes->e_data);
     
    98112  struct external_exec exec_bytes;
    99113  char *targ;
    100 
    101   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
    102       != EXEC_BYTES_SIZE)
     114  bfd_size_type amt = EXEC_BYTES_SIZE;
     115
     116  if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
    103117    {
    104118      if (bfd_get_error () != bfd_error_system_call)
     
    107121    }
    108122
    109   anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
     123  anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
    110124
    111125  /* Normally we just compare for the magic number.
     
    143157  struct external_segdesc ext[1];
    144158  char *section_name;
    145   char try_again[30];   /* name and number */
     159  char try_again[30];   /* Name and number. */
    146160  char *newname;
    147161  int trynum;
     
    149163
    150164  /* Architecture and machine type -- unknown in this format.  */
    151   bfd_set_arch_mach (abfd, bfd_arch_unknown, 0);
     165  bfd_set_arch_mach (abfd, bfd_arch_unknown, 0L);
    152166
    153167  /* The positions of the string table and symbol table.  */
     
    156170
    157171  /* Suck up the section information from the file, one section at a time.  */
    158 
    159172  for (;;)
    160173    {
    161       if (bfd_read ((PTR) ext, 1, sizeof (*ext), abfd) != sizeof (*ext))
     174      bfd_size_type amt = sizeof (*ext);
     175      if (bfd_bread ((PTR) ext, amt, abfd) != amt)
    162176        {
    163177          if (bfd_get_error () != bfd_error_system_call)
    164178            bfd_set_error (bfd_error_wrong_format);
     179
    165180          return 0;
    166181        }
     
    188203          (*_bfd_error_handler)
    189204            (_("%s: Unknown section type in a.out.adobe file: %x\n"),
    190              bfd_get_filename (abfd), ext->e_type[0]);
     205             bfd_archive_filename (abfd), ext->e_type[0]);
    191206          goto no_more_sections;
    192207        }
     
    194209      /* First one is called ".text" or whatever; subsequent ones are
    195210         ".text1", ".text2", ...  */
    196 
    197211      bfd_set_error (bfd_error_no_error);
    198212      sect = bfd_make_section (abfd, section_name);
    199213      trynum = 0;
     214
    200215      while (!sect)
    201216        {
     
    210225      if (sect->name == try_again)
    211226        {
    212           newname = (char *) bfd_zalloc (abfd, strlen (sect->name));
     227          amt = strlen (sect->name);
     228          newname = (char *) bfd_zalloc (abfd, amt);
    213229          if (newname == NULL)
    214230            return 0;
     
    221237      /* Assumed big-endian.  */
    222238      sect->_raw_size = ((ext->e_size[0] << 8)
    223                          | ext->e_size[1] << 8)
    224         | ext->e_size[2];
     239                         | ext->e_size[1] << 8
     240                         | ext->e_size[2]);
    225241      sect->_cooked_size = sect->_raw_size;
    226       sect->vma = bfd_h_get_32 (abfd, ext->e_virtbase);
    227       sect->filepos = bfd_h_get_32 (abfd, ext->e_filebase);
     242      sect->vma = H_GET_32 (abfd, ext->e_virtbase);
     243      sect->filepos = H_GET_32 (abfd, ext->e_filebase);
    228244      /* FIXME XXX alignment?  */
    229245
     
    241257            sect->reloc_count = execp->a_drsize;
    242258            break;
     259
     260          default:
     261            break;
    243262          }
    244263    }
     
    254273}
    255274
    256 struct bout_data_struct {
    257   struct aoutdata a;
    258   struct internal_exec e;
    259 };
    260 
    261 static boolean
     275struct bout_data_struct
     276  {
     277    struct aoutdata a;
     278    struct internal_exec e;
     279  };
     280
     281static bfd_boolean
    262282aout_adobe_mkobject (abfd)
    263283     bfd *abfd;
    264284{
    265285  struct bout_data_struct *rawptr;
    266 
    267   rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
     286  bfd_size_type amt = sizeof (struct bout_data_struct);
     287
     288  rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, amt);
    268289  if (rawptr == NULL)
    269     return false;
     290    return FALSE;
    270291
    271292  abfd->tdata.bout_data = rawptr;
     
    278299  adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
    279300
    280   return true;
    281 }
    282 
    283 static boolean
     301  return TRUE;
     302}
     303
     304static bfd_boolean
    284305aout_adobe_write_object_contents (abfd)
    285306     bfd *abfd;
     
    288309  static struct external_segdesc sentinel[1];   /* Initialized to zero.  */
    289310  asection *sect;
     311  bfd_size_type amt;
    290312
    291313  exec_hdr (abfd)->a_info = ZMAGIC;
     
    325347  aout_adobe_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
    326348
     349  amt = EXEC_BYTES_SIZE;
    327350  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
    328       || (bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd)
    329           != EXEC_BYTES_SIZE))
    330     return false;
     351      || bfd_bwrite ((PTR) &swapped_hdr, amt, abfd) != amt)
     352    return FALSE;
    331353
    332354  /* Now write out the section information.  Text first, data next, rest
     
    334356
    335357  for (sect = abfd->sections; sect; sect = sect->next)
    336     {
    337       if (sect->flags & SEC_CODE)
    338         {
    339           aout_adobe_write_section (abfd, sect);
    340         }
    341     }
     358    if (sect->flags & SEC_CODE)
     359      aout_adobe_write_section (abfd, sect);
     360
    342361  for (sect = abfd->sections; sect; sect = sect->next)
    343     {
    344       if (sect->flags & SEC_DATA)
    345         {
    346           aout_adobe_write_section (abfd, sect);
    347         }
    348     }
     362    if (sect->flags & SEC_DATA)
     363      aout_adobe_write_section (abfd, sect);
     364
    349365  for (sect = abfd->sections; sect; sect = sect->next)
    350     {
    351       if (!(sect->flags & (SEC_CODE | SEC_DATA)))
    352         {
    353           aout_adobe_write_section (abfd, sect);
    354         }
    355     }
     366    if (!(sect->flags & (SEC_CODE | SEC_DATA)))
     367      aout_adobe_write_section (abfd, sect);
    356368
    357369  /* Write final `sentinel` section header (with type of 0).  */
    358   if (bfd_write ((PTR) sentinel, 1, sizeof (*sentinel), abfd)
    359       != sizeof (*sentinel))
    360     return false;
     370  amt = sizeof (*sentinel);
     371  if (bfd_bwrite ((PTR) sentinel, amt, abfd) != amt)
     372    return FALSE;
    361373
    362374  /* Now write out reloc info, followed by syms and strings.  */
     
    365377      if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET)
    366378          != 0)
    367         return false;
     379        return FALSE;
    368380
    369381      if (! aout_32_write_syms (abfd))
    370         return false;
     382        return FALSE;
    371383
    372384      if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*exec_hdr (abfd))), SEEK_SET)
    373385          != 0)
    374         return false;
     386        return FALSE;
    375387
    376388      for (sect = abfd->sections; sect; sect = sect->next)
    377         {
    378           if (sect->flags & SEC_CODE)
    379             {
    380               if (!aout_32_squirt_out_relocs (abfd, sect))
    381                 return false;
    382             }
    383         }
     389        if (sect->flags & SEC_CODE)
     390          if (!aout_32_squirt_out_relocs (abfd, sect))
     391            return FALSE;
    384392
    385393      if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*exec_hdr (abfd))), SEEK_SET)
    386394          != 0)
    387         return false;
     395        return FALSE;
    388396
    389397      for (sect = abfd->sections; sect; sect = sect->next)
    390         {
    391           if (sect->flags & SEC_DATA)
    392             {
    393               if (!aout_32_squirt_out_relocs (abfd, sect))
    394                 return false;
    395             }
    396         }
     398        if (sect->flags & SEC_DATA)
     399          if (!aout_32_squirt_out_relocs (abfd, sect))
     400            return FALSE;
    397401    }
    398   return true;
     402
     403  return TRUE;
    399404}
    400405
     
    408413
    409414
    410 static boolean
     415static bfd_boolean
    411416aout_adobe_set_section_contents (abfd, section, location, offset, count)
    412417     bfd *abfd;
     
    420425
    421426  /* Set by bfd.c handler.  */
    422   if (abfd->output_has_begun == false)
     427  if (! abfd->output_has_begun)
    423428    {
    424429      /* Assign file offsets to sections.  Text sections are first, and
    425430         are contiguous.  Then data sections.  Everything else at the end.  */
    426 
    427431      section_start = N_TXTOFF (ignore<-->me);
    428432
     
    462466     going.  */
    463467  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
    464     return false;
    465 
    466   if (count != 0)
    467     {
    468       return (bfd_write ((PTR) location, 1, count, abfd) == count) ? true : false;
    469     }
    470   return true;
    471 }
    472 
    473 static boolean
     468    return FALSE;
     469
     470  if (count == 0)
     471    return TRUE;
     472
     473  return bfd_bwrite ((PTR) location, count, abfd) == count;
     474}
     475
     476static bfd_boolean
    474477aout_adobe_set_arch_mach (abfd, arch, machine)
    475478     bfd *abfd;
     
    478481{
    479482  if (! bfd_default_set_arch_mach (abfd, arch, machine))
    480     return false;
     483    return FALSE;
    481484
    482485  if (arch == bfd_arch_unknown
    483486      || arch == bfd_arch_m68k)
    484     return true;
    485 
    486   return false;
     487    return TRUE;
     488
     489  return FALSE;
    487490}
    488491
     
    490493aout_adobe_sizeof_headers (ignore_abfd, ignore)
    491494     bfd *ignore_abfd ATTRIBUTE_UNUSED;
    492      boolean ignore ATTRIBUTE_UNUSED;
     495     bfd_boolean ignore ATTRIBUTE_UNUSED;
    493496{
    494497  return sizeof (struct internal_exec);
     
    515518#define aout_32_bfd_relax_section       bfd_generic_relax_section
    516519#define aout_32_bfd_gc_sections         bfd_generic_gc_sections
     520#define aout_32_bfd_merge_sections      bfd_generic_merge_sections
     521#define aout_32_bfd_discard_group       bfd_generic_discard_group
    517522#define aout_32_bfd_link_hash_table_create \
    518523  _bfd_generic_link_hash_table_create
     524#define aout_32_bfd_link_hash_table_free \
     525  _bfd_generic_link_hash_table_free
    519526#define aout_32_bfd_link_add_symbols    _bfd_generic_link_add_symbols
     527#define aout_32_bfd_link_just_syms      _bfd_generic_link_just_syms
    520528#define aout_32_bfd_final_link          _bfd_generic_final_link
    521529#define aout_32_bfd_link_split_section  _bfd_generic_link_split_section
    522530
    523 const bfd_target a_out_adobe_vec = {
    524   "a.out.adobe",                /* name */
    525   bfd_target_aout_flavour,
    526   BFD_ENDIAN_BIG,               /* data byte order is unknown (big assumed) */
    527   BFD_ENDIAN_BIG,               /* hdr byte order is big */
    528   (HAS_RELOC | EXEC_P |         /* object flags */
    529    HAS_LINENO | HAS_DEBUG |
    530    HAS_SYMS | HAS_LOCALS | WP_TEXT ),
    531   /* section flags */
    532   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC),
    533   '_',                          /*  symbol leading char */
    534   ' ',                          /* ar_pad_char */
    535   16,                           /* ar_max_namelen */
    536 
    537   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
    538   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
    539   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* data */
    540   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
    541   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
    542   bfd_getb16, bfd_getb_signed_16, bfd_putb16,   /* hdrs */
    543   {_bfd_dummy_target, aout_adobe_object_p,      /* bfd_check_format */
    544    bfd_generic_archive_p, _bfd_dummy_target},
    545   {bfd_false, aout_adobe_mkobject,      /* bfd_set_format */
    546    _bfd_generic_mkarchive, bfd_false},
    547   {bfd_false, aout_adobe_write_object_contents, /* bfd_write_contents */
    548    _bfd_write_archive_contents, bfd_false},
    549 
    550   BFD_JUMP_TABLE_GENERIC (aout_32),
    551   BFD_JUMP_TABLE_COPY (_bfd_generic),
    552   BFD_JUMP_TABLE_CORE (_bfd_nocore),
    553   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
    554   BFD_JUMP_TABLE_SYMBOLS (aout_32),
    555   BFD_JUMP_TABLE_RELOCS (aout_32),
    556   BFD_JUMP_TABLE_WRITE (aout_32),
    557   BFD_JUMP_TABLE_LINK (aout_32),
    558   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
    559 
    560   NULL,
    561 
    562   (PTR) 0
    563 };
     531const bfd_target a_out_adobe_vec =
     532  {
     533    "a.out.adobe",              /* name */
     534    bfd_target_aout_flavour,
     535    BFD_ENDIAN_BIG,             /* data byte order is unknown (big assumed) */
     536    BFD_ENDIAN_BIG,             /* hdr byte order is big */
     537    (HAS_RELOC | EXEC_P |       /* object flags */
     538     HAS_LINENO | HAS_DEBUG |
     539     HAS_SYMS | HAS_LOCALS | WP_TEXT ),
     540    /* section flags */
     541    (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC),
     542    '_',                                /*  symbol leading char */
     543    ' ',                                /* ar_pad_char */
     544    16,                                 /* ar_max_namelen */
     545
     546    bfd_getb64, bfd_getb_signed_64, bfd_putb64,
     547    bfd_getb32, bfd_getb_signed_32, bfd_putb32,
     548    bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
     549    bfd_getb64, bfd_getb_signed_64, bfd_putb64,
     550    bfd_getb32, bfd_getb_signed_32, bfd_putb32,
     551    bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
     552    {_bfd_dummy_target, aout_adobe_object_p,    /* bfd_check_format */
     553     bfd_generic_archive_p, _bfd_dummy_target},
     554    {bfd_false, aout_adobe_mkobject,            /* bfd_set_format */
     555     _bfd_generic_mkarchive, bfd_false},
     556    {bfd_false, aout_adobe_write_object_contents,/* bfd_write_contents */
     557     _bfd_write_archive_contents, bfd_false},
     558
     559    BFD_JUMP_TABLE_GENERIC (aout_32),
     560    BFD_JUMP_TABLE_COPY (_bfd_generic),
     561    BFD_JUMP_TABLE_CORE (_bfd_nocore),
     562    BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
     563    BFD_JUMP_TABLE_SYMBOLS (aout_32),
     564    BFD_JUMP_TABLE_RELOCS (aout_32),
     565    BFD_JUMP_TABLE_WRITE (aout_32),
     566    BFD_JUMP_TABLE_LINK (aout_32),
     567    BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
     568
     569    NULL,
     570
     571    (PTR) 0
     572  };
Note: See TracChangeset for help on using the changeset viewer.