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/coff-stgo32.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for Intel 386 COFF files (DJGPP variant with a stub).
    2    Copyright 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
     2   Copyright 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    33   Written by Robert Hoehne.
    44
     
    3333
    3434   To be compatible with any existing executables I have fixed this
    35    here and NOT in the DJGPP startup code.
    36  */
     35   here and NOT in the DJGPP startup code.  */
    3736
    3837#define TARGET_SYM              go32stubbedcoff_vec
     
    4847  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
    4948{ COFF_SECTION_NAME_EXACT_MATCH (".text"), \
    50   COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }
     49  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
     50{ COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
     51  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
     52{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi"), \
     53  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
    5154
    5255#include "bfd.h"
    5356
    54 /* At first the prototypes */
    55 
    56 static void
    57 adjust_filehdr_in_post PARAMS ((bfd * abfd, PTR src, PTR dst));
    58 static void
    59 adjust_filehdr_out_pre PARAMS ((bfd * abfd, PTR in, PTR out));
    60 static void
    61 adjust_filehdr_out_post PARAMS ((bfd * abfd, PTR in, PTR out));
    62 
    63 static void
    64 adjust_scnhdr_in_post PARAMS ((bfd * abfd, PTR ext, PTR in));
    65 static void
    66 adjust_scnhdr_out_pre PARAMS ((bfd * abfd, PTR in, PTR out));
    67 static void
    68 adjust_scnhdr_out_post PARAMS ((bfd * abfd, PTR in, PTR out));
    69 
    70 static void
    71 adjust_aux_in_post PARAMS ((bfd * abfd, PTR ext1, int type, int class, int indx,
    72                             int numaux, PTR in1));
    73 static void
    74 adjust_aux_out_pre PARAMS ((bfd * abfd, PTR inp, int type, int class, int indx,
    75                             int numaux, PTR extp));
    76 static void
    77 adjust_aux_out_post PARAMS ((bfd * abfd, PTR inp, int type, int class, int indx,
    78                              int numaux, PTR extp));
    79 
    80 static void
    81 create_go32_stub PARAMS ((bfd * abfd));
    82 
    83 /*
    84    All that ..._PRE and ...POST functions are called from the corresponding
     57/* At first the prototypes.  */
     58
     59static void
     60adjust_filehdr_in_post PARAMS ((bfd *, PTR, PTR));
     61static void
     62adjust_filehdr_out_pre PARAMS ((bfd *, PTR, PTR));
     63static void
     64adjust_filehdr_out_post PARAMS ((bfd *, PTR, PTR));
     65static void
     66adjust_scnhdr_in_post PARAMS ((bfd *, PTR, PTR));
     67static void
     68adjust_scnhdr_out_pre PARAMS ((bfd *, PTR, PTR));
     69static void
     70adjust_scnhdr_out_post PARAMS ((bfd *, PTR, PTR));
     71static void
     72adjust_aux_in_post PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     73static void
     74adjust_aux_out_pre PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     75static void
     76adjust_aux_out_post PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     77static void
     78create_go32_stub PARAMS ((bfd *));
     79
     80/* All that ..._PRE and ...POST functions are called from the corresponding
    8581   coff_swap... functions. The ...PRE functions are called at the beginning
    86    of the function and the ...POST functions at the end of the swap routines.
    87  */
     82   of the function and the ...POST functions at the end of the swap routines.  */
    8883
    8984#define COFF_ADJUST_FILEHDR_IN_POST adjust_filehdr_in_post
     
    9994#define COFF_ADJUST_AUX_OUT_POST adjust_aux_out_post
    10095
    101 static boolean
    102   go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd * ibfd, bfd * obfd));
     96static bfd_boolean
     97  go32_stubbed_coff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
    10398
    10499#define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data
     
    106101#include "coff-i386.c"
    107102
    108 /* I hold in the usrdata the stub */
     103/* I hold in the usrdata the stub. */
    109104#define bfd_coff_go32stub bfd_usrdata
    110105
    111106/* This macro is used, because I cannot assume the endianess of the
    112    host system */
    113 #define _H(index) (bfd_h_get_16(abfd, (bfd_byte *) (header+index*2)))
     107   host system. */
     108#define _H(index) (H_GET_16 (abfd, (header+index*2)))
    114109
    115110/* These bytes are a 2048-byte DOS executable, which loads the COFF
    116    image into memory and then runs it. It is called 'stub' */
    117 
    118 static unsigned char stub_bytes[STUBSIZE] =
     111   image into memory and then runs it. It is called 'stub'. */
     112
     113static const unsigned char stub_bytes[STUBSIZE] =
    119114{
    120115#include "go32stub.h"
     
    126121   all the pointers are adjusted by adding STUBSIZE and for the
    127122   ...out function, it is subtracted first and after calling the
    128    standard swap function it is reset to the old value */
     123   standard swap function it is reset to the old value. */
    129124
    130125/* This macro is used for adjusting the filepointers, which
    131    is done only, if the pointer is nonzero */
     126   is done only, if the pointer is nonzero. */
    132127
    133128#define ADJUST_VAL(val,diff) \
     
    145140  ADJUST_VAL (filehdr_dst->f_symptr, STUBSIZE);
    146141
    147   /* Save now the stub to be used later */
    148   bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, STUBSIZE);
     142  /* Save now the stub to be used later. */
     143  bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, (bfd_size_type) STUBSIZE);
    149144
    150145  /* Since this function returns no status, I do not set here
    151146     any bfd_error_...
    152147     That means, before the use of bfd_coff_go32stub (), this value
    153      should be checked if it is != NULL */
     148     should be checked if it is != NULL. */
    154149  if (bfd_coff_go32stub (abfd) == NULL)
    155150    return;
     
    166161  FILHDR *filehdr_out = (FILHDR *) out;
    167162
    168   /* Generate the stub */
     163  /* Generate the stub. */
    169164  create_go32_stub (abfd);
    170165
    171   /* Copy the stub to the file header */
     166  /* Copy the stub to the file header. */
    172167  if (bfd_coff_go32stub (abfd) != NULL)
    173168    memcpy (filehdr_out->stub, bfd_coff_go32stub (abfd), STUBSIZE);
    174169  else
    175     /* use the default */
     170    /* Use the default. */
    176171    memcpy (filehdr_out->stub, stub_bytes, STUBSIZE);
    177172
     
    186181{
    187182  struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
    188   /* undo the above change */
     183  /* Undo the above change. */
    189184  ADJUST_VAL (filehdr_in->f_symptr, STUBSIZE);
    190185}
     
    283278}
    284279
    285 /*
    286    That's the function, which creates the stub. There are
     280/* That's the function, which creates the stub. There are
    287281   different cases from where the stub is taken.
    288282   At first the environment variable $(GO32STUB) is checked and then
     
    294288
    295289   If there was any error, the standard stub (compiled in this file)
    296    is taken.
    297  */
     290   is taken.  */
    298291
    299292static void
     
    301294     bfd *abfd;
    302295{
    303   /* Do it only once */
     296  /* Do it only once. */
    304297  if (bfd_coff_go32stub (abfd) == NULL)
    305298    {
     
    309302      unsigned char header[10];
    310303      char magic[8];
    311       unsigned long coff_start, exe_start;
    312 
    313       /* Check at first the environment variable $(GO32STUB) */
     304      unsigned long coff_start;
     305      long exe_start;
     306
     307      /* Check at first the environment variable $(GO32STUB).  */
    314308      stub = getenv ("GO32STUB");
    315       /* Now check the environment variable $(STUB) */
     309      /* Now check the environment variable $(STUB). */
    316310      if (stub == NULL)
    317311        stub = getenv ("STUB");
     
    332326          goto stub_end;
    333327        }
    334       if (_H (0) != 0x5a4d)     /* it is not an exe file */
     328      if (_H (0) != 0x5a4d)     /* It is not an exe file. */
    335329        {
    336330          close (f);
     
    338332        }
    339333      /* Compute the size of the stub (it is every thing up
    340          to the beginning of the coff image) */
     334         to the beginning of the coff image). */
    341335      coff_start = (long) _H (2) * 512L;
    342336      if (_H (1))
     
    344338
    345339      /* Currently there is only a fixed stub size of 2048 bytes
    346          supported */
     340         supported. */
    347341      if (coff_start != 2048)
    348342        {
     
    351345        }
    352346      exe_start = _H (4) * 16;
    353       if ((unsigned long) lseek (f, exe_start, SEEK_SET) != exe_start)
     347      if ((long) lseek (f, exe_start, SEEK_SET) != exe_start)
    354348        {
    355349          close (f);
     
    366360          goto stub_end;
    367361        }
    368       /* Now we found a correct stub (hopefully) */
    369       bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, coff_start);
     362      /* Now we found a correct stub (hopefully).  */
     363      bfd_coff_go32stub (abfd)
     364        = (PTR) bfd_alloc (abfd, (bfd_size_type) coff_start);
    370365      if (bfd_coff_go32stub (abfd) == NULL)
    371366        {
     
    384379stub_end:
    385380  /* There was something wrong above, so use now the standard builtin
    386      stub */
     381     stub. */
    387382  if (bfd_coff_go32stub (abfd) == NULL)
    388383    {
    389       bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, STUBSIZE);
     384      bfd_coff_go32stub (abfd)
     385        = (PTR) bfd_alloc (abfd, (bfd_size_type) STUBSIZE);
    390386      if (bfd_coff_go32stub (abfd) == NULL)
    391         {
    392           return;
    393         }
    394 
     387        return;
    395388      memcpy (bfd_coff_go32stub (abfd), stub_bytes, STUBSIZE);
    396389    }
     
    398391
    399392/* If ibfd was a stubbed coff image, copy the stub from that bfd
    400    to the new obfd.
    401  */
    402 
    403 static boolean
     393   to the new obfd.  */
     394
     395static bfd_boolean
    404396go32_stubbed_coff_bfd_copy_private_bfd_data  (ibfd, obfd)
    405397     bfd *ibfd;
    406398     bfd *obfd;
    407399{
    408   /* check if both are the same targets */
     400  /* Check if both are the same targets. */
    409401  if (ibfd->xvec != obfd->xvec)
    410     return true;
    411 
    412   /* check if both have a valid stub */
     402    return TRUE;
     403
     404  /* Check if both have a valid stub. */
    413405  if (bfd_coff_go32stub (ibfd) == NULL
    414406      || bfd_coff_go32stub (obfd) == NULL)
    415     return true;
    416 
    417   /* Now copy the stub */
     407    return TRUE;
     408
     409  /* Now copy the stub. */
    418410  memcpy (bfd_coff_go32stub (obfd), bfd_coff_go32stub (ibfd), STUBSIZE);
    419411
    420   return true;
    421 }
     412  return TRUE;
     413}
Note: See TracChangeset for help on using the changeset viewer.