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

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for a.out files encapsulated with COFF headers.
    2    Copyright 1990, 1991, 1994, 1995, 2000 Free Software Foundation, Inc.
     2   Copyright 1990, 1991, 1994, 1995, 2000, 2001, 2002, 2003
     3   Free Software Foundation, Inc.
    34
    45This file is part of BFD, the Binary File Descriptor library.
     
    2425#define SEGMENT_SIZE    TARGET_PAGE_SIZE
    2526#define TEXT_START_ADDR 0
    26 #define BYTES_IN_WORD 4
    2727#endif
    2828
    2929#include "bfd.h"
    30 #include <sysdep.h>
     30#include "sysdep.h"
    3131#include "libbfd.h"
    32 #include <aout/aout64.h>
     32#include "aout/aout64.h"
    3333#include "aout/stab_gnu.h"
    3434#include "aout/ar.h"
     
    4646  struct external_exec exec_bytes;
    4747  struct internal_exec exec;
    48 
    49   if (bfd_read ((PTR)magicbuf, 1, sizeof (magicbuf), abfd) !=
    50       sizeof (magicbuf))
     48  bfd_size_type amt = sizeof (magicbuf);
     49
     50  if (bfd_bread ((PTR) magicbuf, amt, abfd) != amt)
    5151    {
    5252      if (bfd_get_error () != bfd_error_system_call)
     
    5555    }
    5656
    57   coff_magic = bfd_h_get_16 (abfd, magicbuf);
     57  coff_magic = H_GET_16 (abfd, magicbuf);
    5858  if (coff_magic != COFF_MAGIC)
    5959    return 0;                   /* Not an encap coff file */
    6060
    61   __header_offset_temp==COFF_MAGIC ? sizeof (struct coffheader) : 0)
    62   (fseek ((f), HEADER_OFFSET((f)), 1))
    63 
    64   magic = bfd_h_get_32 (abfd, magicbuf);
    65 
    66   if (N_BADMAG (*((struct internal_exec *) &magic))) return 0;
    67 
    68   struct external_exec exec_bytes;
    69   if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
    70       != EXEC_BYTES_SIZE) {
    71     if (bfd_get_error () != bfd_error_system_call)
    72       bfd_set_error (bfd_error_wrong_format);
     61  magic = H_GET_32 (abfd, magicbuf);
     62
     63  if (N_BADMAG (*((struct internal_exec *) &magic)))
    7364    return 0;
    74   }
     65
     66  if (bfd_seek (abfd, (file_ptr) sizeof (struct coffheader), SEEK_SET) != 0)
     67    return 0;
     68
     69  amt = EXEC_BYTES_SIZE;
     70  if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
     71    {
     72      if (bfd_get_error () != bfd_error_system_call)
     73        bfd_set_error (bfd_error_wrong_format);
     74      return 0;
     75    }
    7576  NAME(aout,swap_exec_header_in) (abfd, &exec_bytes, &exec);
    7677
     
    7879}
    7980
    80 /* Finish up the reading of a encapsulated-coff a.out file header */
     81/* Finish up the reading of an encapsulated-coff a.out file header. */
    8182const bfd_target *
    8283encap_real_callback (abfd)
     
    9192     for remote debugging of embedded systems.  */
    9293  if (N_FLAGS(exec_aouthdr) & N_FLAGS_COFF_ENCAPSULATE)
    93   {
    94           struct coffheader ch;
    95           int val;
    96           val = lseek (execchan, -(sizeof (AOUTHDR) + sizeof (ch)), 1);
    97           if (val == -1)
    98                   perror_with_name (filename);
    99           val = myread (execchan, &ch, sizeof (ch));
    100           if (val < 0)
    101                   perror_with_name (filename);
    102           text_start = ch.text_start;
    103           exec_data_start = ch.data_start;
    104   } else
    105          {
    106           text_start =
    107             IS_OBJECT_FILE (exec_aouthdr) ? 0 : N_TXTADDR (exec_aouthdr);
    108           exec_data_start = IS_OBJECT_FILE (exec_aouthdr)
    109             ? exec_aouthdr.a_text : N_DATADDR (exec_aouthdr);
    110   }
     94    {
     95      struct coffheader ch;
     96      int val;
     97      val = lseek (execchan, -(sizeof (AOUTHDR) + sizeof (ch)), 1);
     98      if (val == -1)
     99        perror_with_name (filename);
     100      val = myread (execchan, &ch, sizeof (ch));
     101      if (val < 0)
     102        perror_with_name (filename);
     103      text_start = ch.text_start;
     104      exec_data_start = ch.data_start;
     105    }
     106  else
     107    {
     108      text_start =
     109        IS_OBJECT_FILE (exec_aouthdr) ? 0 : N_TXTADDR (exec_aouthdr);
     110      exec_data_start = (IS_OBJECT_FILE (exec_aouthdr)
     111                         ? exec_aouthdr.a_text
     112                         : N_DATADDR (exec_aouthdr));
     113    }
    111114
    112115  /* Determine the architecture and machine type of the object file.  */
     
    120123   file header, symbols, and relocation.  */
    121124
    122 boolean
     125bfd_boolean
    123126encap_write_object_contents (abfd)
    124127     bfd *abfd;
     
    128131  struct internal_exec *execp = exec_hdr (abfd);
    129132
    130 /****** FIXME:  Fragments from the old GNU LD program for dealing with
    131         encap coff.  */
    132 struct coffheader coffheader;
    133 int need_coff_header;
     133  /* FIXME:  Fragments from the old GNU LD program for dealing with
     134     encap coff.  */
     135  struct coffheader coffheader;
     136  int need_coff_header;
    134137
    135138  /* Determine whether to count the header as part of
     
    227230  text_size -= N_TXTOFF (outheader);
    228231  WRITE_HEADERS(abfd, execp);
    229   return true;
     232  return TRUE;
    230233}
    231234
Note: See TracChangeset for help on using the changeset viewer.