~ubuntu-branches/debian/squeeze/binutils/squeeze

« back to all changes in this revision

Viewing changes to bfd/coff-stgo32.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-09-10 17:05:30 UTC
  • mfrom: (1.4.5 upstream) (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090910170530-wa6gpju9pq5c56on
Tags: 2.19.91.20090910-1
* Snapshot, taken from the 2.20 release branch 20090910, corresponding
  to the 2.19.90 upstream snapshot.
* Fix Thumb-2 shared libraries (Daniel Jacobowitz), patch taken
  from the trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* BFD back-end for Intel 386 COFF files (DJGPP variant with a stub).
2
 
   Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2006, 2007
 
2
   Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2005, 2006, 2007, 2009
3
3
   Free Software Foundation, Inc.
4
4
   Written by Robert Hoehne.
5
5
 
102
102
 
103
103
#include "coff-i386.c"
104
104
 
105
 
/* I hold in the usrdata the stub.  */
106
 
#define bfd_coff_go32stub bfd_usrdata
107
 
 
108
105
/* This macro is used, because I cannot assume the endianess of the
109
106
   host system.  */
110
107
#define _H(index) (H_GET_16 (abfd, (header+index*2)))
112
109
/* These bytes are a 2048-byte DOS executable, which loads the COFF
113
110
   image into memory and then runs it. It is called 'stub'.  */
114
111
 
115
 
static const unsigned char stub_bytes[STUBSIZE] =
 
112
static const unsigned char stub_bytes[GO32_STUBSIZE] =
116
113
{
117
114
#include "go32stub.h"
118
115
};
120
117
/*
121
118
   I have not commented each swap function below, because the
122
119
   technique is in any function the same. For the ...in function,
123
 
   all the pointers are adjusted by adding STUBSIZE and for the
 
120
   all the pointers are adjusted by adding GO32_STUBSIZE and for the
124
121
   ...out function, it is subtracted first and after calling the
125
122
   standard swap function it is reset to the old value.  */
126
123
 
132
129
 
133
130
static void
134
131
adjust_filehdr_in_post  (abfd, src, dst)
135
 
     bfd *abfd;
 
132
     bfd *abfd ATTRIBUTE_UNUSED;
136
133
     PTR src;
137
134
     PTR dst;
138
135
{
139
136
  FILHDR *filehdr_src = (FILHDR *) src;
140
137
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
141
138
 
142
 
  ADJUST_VAL (filehdr_dst->f_symptr, STUBSIZE);
143
 
 
144
 
  /* Save now the stub to be used later.  */
145
 
  bfd_coff_go32stub (abfd) = (PTR) bfd_alloc (abfd, (bfd_size_type) STUBSIZE);
146
 
 
147
 
  /* Since this function returns no status, I do not set here
148
 
     any bfd_error_...
149
 
     That means, before the use of bfd_coff_go32stub (), this value
150
 
     should be checked if it is != NULL.  */
151
 
  if (bfd_coff_go32stub (abfd) == NULL)
152
 
    return;
153
 
  memcpy (bfd_coff_go32stub (abfd), filehdr_src->stub, STUBSIZE);
 
139
  ADJUST_VAL (filehdr_dst->f_symptr, GO32_STUBSIZE);
 
140
 
 
141
  /* Save now the stub to be used later.  Put the stub data to FILEHDR_DST
 
142
     first as coff_data (abfd) still does not exist.  It may not even be ever
 
143
     created as we are just checking the file format of ABFD.  */
 
144
  memcpy (filehdr_dst->go32stub, filehdr_src->stub, GO32_STUBSIZE);
 
145
  filehdr_dst->f_flags |= F_GO32STUB;
154
146
}
155
147
 
156
148
static void
166
158
  create_go32_stub (abfd);
167
159
 
168
160
  /* Copy the stub to the file header.  */
169
 
  if (bfd_coff_go32stub (abfd) != NULL)
170
 
    memcpy (filehdr_out->stub, bfd_coff_go32stub (abfd), STUBSIZE);
 
161
  if (coff_data (abfd)->go32stub != NULL)
 
162
    memcpy (filehdr_out->stub, coff_data (abfd)->go32stub, GO32_STUBSIZE);
171
163
  else
172
164
    /* Use the default.  */
173
 
    memcpy (filehdr_out->stub, stub_bytes, STUBSIZE);
 
165
    memcpy (filehdr_out->stub, stub_bytes, GO32_STUBSIZE);
174
166
 
175
 
  ADJUST_VAL (filehdr_in->f_symptr, -STUBSIZE);
 
167
  ADJUST_VAL (filehdr_in->f_symptr, -GO32_STUBSIZE);
176
168
}
177
169
 
178
170
static void
183
175
{
184
176
  struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
185
177
  /* Undo the above change.  */
186
 
  ADJUST_VAL (filehdr_in->f_symptr, STUBSIZE);
 
178
  ADJUST_VAL (filehdr_in->f_symptr, GO32_STUBSIZE);
187
179
}
188
180
 
189
181
static void
194
186
{
195
187
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
196
188
 
197
 
  ADJUST_VAL (scnhdr_int->s_scnptr, STUBSIZE);
198
 
  ADJUST_VAL (scnhdr_int->s_relptr, STUBSIZE);
199
 
  ADJUST_VAL (scnhdr_int->s_lnnoptr, STUBSIZE);
 
189
  ADJUST_VAL (scnhdr_int->s_scnptr, GO32_STUBSIZE);
 
190
  ADJUST_VAL (scnhdr_int->s_relptr, GO32_STUBSIZE);
 
191
  ADJUST_VAL (scnhdr_int->s_lnnoptr, GO32_STUBSIZE);
200
192
}
201
193
 
202
194
static void
207
199
{
208
200
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
201
 
210
 
  ADJUST_VAL (scnhdr_int->s_scnptr, -STUBSIZE);
211
 
  ADJUST_VAL (scnhdr_int->s_relptr, -STUBSIZE);
212
 
  ADJUST_VAL (scnhdr_int->s_lnnoptr, -STUBSIZE);
 
202
  ADJUST_VAL (scnhdr_int->s_scnptr, -GO32_STUBSIZE);
 
203
  ADJUST_VAL (scnhdr_int->s_relptr, -GO32_STUBSIZE);
 
204
  ADJUST_VAL (scnhdr_int->s_lnnoptr, -GO32_STUBSIZE);
213
205
}
214
206
 
215
207
static void
220
212
{
221
213
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
222
214
 
223
 
  ADJUST_VAL (scnhdr_int->s_scnptr, STUBSIZE);
224
 
  ADJUST_VAL (scnhdr_int->s_relptr, STUBSIZE);
225
 
  ADJUST_VAL (scnhdr_int->s_lnnoptr, STUBSIZE);
 
215
  ADJUST_VAL (scnhdr_int->s_scnptr, GO32_STUBSIZE);
 
216
  ADJUST_VAL (scnhdr_int->s_relptr, GO32_STUBSIZE);
 
217
  ADJUST_VAL (scnhdr_int->s_lnnoptr, GO32_STUBSIZE);
226
218
}
227
219
 
228
220
static void
229
 
adjust_aux_in_post  (abfd, ext1, type, class, indx, numaux, in1)
 
221
adjust_aux_in_post  (abfd, ext1, type, in_class, indx, numaux, in1)
230
222
     bfd *abfd ATTRIBUTE_UNUSED;
231
223
     PTR ext1 ATTRIBUTE_UNUSED;
232
224
     int type;
233
 
     int class;
 
225
     int in_class;
234
226
     int indx ATTRIBUTE_UNUSED;
235
227
     int numaux ATTRIBUTE_UNUSED;
236
228
     PTR in1;
237
229
{
238
230
  union internal_auxent *in = (union internal_auxent *) in1;
239
231
 
240
 
  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
241
 
    {
242
 
      ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, STUBSIZE);
243
 
    }
244
 
}
245
 
 
246
 
static void
247
 
adjust_aux_out_pre  (abfd, inp, type, class, indx, numaux, extp)
248
 
     bfd *abfd ATTRIBUTE_UNUSED;
249
 
     PTR inp;
250
 
     int type;
251
 
     int class;
252
 
     int indx ATTRIBUTE_UNUSED;
253
 
     int numaux ATTRIBUTE_UNUSED;
254
 
     PTR extp ATTRIBUTE_UNUSED;
255
 
{
256
 
  union internal_auxent *in = (union internal_auxent *) inp;
257
 
 
258
 
  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
259
 
    {
260
 
      ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, -STUBSIZE);
261
 
    }
262
 
}
263
 
 
264
 
static void
265
 
adjust_aux_out_post (abfd, inp, type, class, indx, numaux, extp)
266
 
     bfd *abfd ATTRIBUTE_UNUSED;
267
 
     PTR inp;
268
 
     int type;
269
 
     int class;
270
 
     int indx ATTRIBUTE_UNUSED;
271
 
     int numaux ATTRIBUTE_UNUSED;
272
 
     PTR extp ATTRIBUTE_UNUSED;
273
 
{
274
 
  union internal_auxent *in = (union internal_auxent *) inp;
275
 
 
276
 
  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
277
 
    {
278
 
      ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, STUBSIZE);
 
232
  if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
 
233
      || ISTAG (in_class))
 
234
    {
 
235
      ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, GO32_STUBSIZE);
 
236
    }
 
237
}
 
238
 
 
239
static void
 
240
adjust_aux_out_pre  (abfd, inp, type, in_class, indx, numaux, extp)
 
241
     bfd *abfd ATTRIBUTE_UNUSED;
 
242
     PTR inp;
 
243
     int type;
 
244
     int in_class;
 
245
     int indx ATTRIBUTE_UNUSED;
 
246
     int numaux ATTRIBUTE_UNUSED;
 
247
     PTR extp ATTRIBUTE_UNUSED;
 
248
{
 
249
  union internal_auxent *in = (union internal_auxent *) inp;
 
250
 
 
251
  if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
 
252
      || ISTAG (in_class))
 
253
    {
 
254
      ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, -GO32_STUBSIZE);
 
255
    }
 
256
}
 
257
 
 
258
static void
 
259
adjust_aux_out_post (abfd, inp, type, in_class, indx, numaux, extp)
 
260
     bfd *abfd ATTRIBUTE_UNUSED;
 
261
     PTR inp;
 
262
     int type;
 
263
     int in_class;
 
264
     int indx ATTRIBUTE_UNUSED;
 
265
     int numaux ATTRIBUTE_UNUSED;
 
266
     PTR extp ATTRIBUTE_UNUSED;
 
267
{
 
268
  union internal_auxent *in = (union internal_auxent *) inp;
 
269
 
 
270
  if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
 
271
      || ISTAG (in_class))
 
272
    {
 
273
      ADJUST_VAL (in->x_sym.x_fcnary.x_fcn.x_lnnoptr, GO32_STUBSIZE);
279
274
    }
280
275
}
281
276
 
296
291
     bfd *abfd;
297
292
{
298
293
  /* Do it only once.  */
299
 
  if (bfd_coff_go32stub (abfd) == NULL)
 
294
  if (coff_data (abfd)->go32stub == NULL)
300
295
    {
301
296
      char *stub;
302
297
      struct stat st;
362
357
          goto stub_end;
363
358
        }
364
359
      /* Now we found a correct stub (hopefully).  */
365
 
      bfd_coff_go32stub (abfd)
366
 
        = (PTR) bfd_alloc (abfd, (bfd_size_type) coff_start);
367
 
      if (bfd_coff_go32stub (abfd) == NULL)
 
360
      coff_data (abfd)->go32stub = bfd_alloc (abfd, (bfd_size_type) coff_start);
 
361
      if (coff_data (abfd)->go32stub == NULL)
368
362
        {
369
363
          close (f);
370
364
          return;
371
365
        }
372
366
      lseek (f, 0L, SEEK_SET);
373
 
      if ((unsigned long) read (f, bfd_coff_go32stub (abfd), coff_start)
 
367
      if ((unsigned long) read (f, coff_data (abfd)->go32stub, coff_start)
374
368
          != coff_start)
375
369
        {
376
 
          bfd_release (abfd, bfd_coff_go32stub (abfd));
377
 
          bfd_coff_go32stub (abfd) = NULL;
 
370
          bfd_release (abfd, coff_data (abfd)->go32stub);
 
371
          coff_data (abfd)->go32stub = NULL;
378
372
        }
379
373
      close (f);
380
374
    }
381
375
stub_end:
382
376
  /* There was something wrong above, so use now the standard builtin
383
377
     stub.  */
384
 
  if (bfd_coff_go32stub (abfd) == NULL)
 
378
  if (coff_data (abfd)->go32stub == NULL)
385
379
    {
386
 
      bfd_coff_go32stub (abfd)
387
 
        = (PTR) bfd_alloc (abfd, (bfd_size_type) STUBSIZE);
388
 
      if (bfd_coff_go32stub (abfd) == NULL)
 
380
      coff_data (abfd)->go32stub
 
381
        = bfd_alloc (abfd, (bfd_size_type) GO32_STUBSIZE);
 
382
      if (coff_data (abfd)->go32stub == NULL)
389
383
        return;
390
 
      memcpy (bfd_coff_go32stub (abfd), stub_bytes, STUBSIZE);
 
384
      memcpy (coff_data (abfd)->go32stub, stub_bytes, GO32_STUBSIZE);
391
385
    }
392
386
}
393
387
 
403
397
  if (ibfd->xvec != obfd->xvec)
404
398
    return TRUE;
405
399
 
406
 
  /* Check if both have a valid stub.  */
407
 
  if (bfd_coff_go32stub (ibfd) == NULL
408
 
      || bfd_coff_go32stub (obfd) == NULL)
 
400
  /* Check if we have a source stub.  */
 
401
  if (coff_data (ibfd)->go32stub == NULL)
409
402
    return TRUE;
410
403
 
 
404
  /* As adjust_filehdr_out_pre may get called only after this function,
 
405
     optionally allocate the output stub.  */
 
406
  if (coff_data (obfd)->go32stub == NULL)
 
407
    coff_data (obfd)->go32stub = bfd_alloc (obfd,
 
408
                                          (bfd_size_type) GO32_STUBSIZE);
 
409
 
411
410
  /* Now copy the stub.  */
412
 
  memcpy (bfd_coff_go32stub (obfd), bfd_coff_go32stub (ibfd), STUBSIZE);
 
411
  if (coff_data (obfd)->go32stub != NULL)
 
412
    memcpy (coff_data (obfd)->go32stub, coff_data (ibfd)->go32stub,
 
413
            GO32_STUBSIZE);
413
414
 
414
415
  return TRUE;
415
416
}