Coverage Report

Created: 2026-09-14 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/coff-alpha.c
Line
Count
Source
1
/* BFD back-end for ALPHA Extended-Coff files.
2
   Copyright (C) 1993-2026 Free Software Foundation, Inc.
3
   Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and
4
   Ian Lance Taylor <ian@cygnus.com>.
5
6
   This file is part of BFD, the Binary File Descriptor library.
7
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
   MA 02110-1301, USA.  */
22
23
#include "sysdep.h"
24
#include "bfd.h"
25
#include "bfdlink.h"
26
#include "libbfd.h"
27
#include "coff/internal.h"
28
#include "coff/sym.h"
29
#include "coff/symconst.h"
30
#include "coff/ecoff.h"
31
#include "coff/alpha.h"
32
#include "aout/ar.h"
33
#include "libcoff.h"
34
#include "libecoff.h"
35

36
/* Prototypes for static functions.  */
37
38
39

40
/* ECOFF has COFF sections, but the debugging information is stored in
41
   a completely different format.  ECOFF targets use some of the
42
   swapping routines from coffswap.h, and some of the generic COFF
43
   routines in coffgen.c, but, unlike the real COFF targets, do not
44
   use coffcode.h itself.
45
46
   Get the generic COFF swapping routines, except for the reloc,
47
   symbol, and lineno ones.  Give them ecoff names.  Define some
48
   accessor macros for the large sizes used for Alpha ECOFF.  */
49
50
179k
#define GET_FILEHDR_SYMPTR H_GET_64
51
28
#define PUT_FILEHDR_SYMPTR H_PUT_64
52
712
#define GET_AOUTHDR_TSIZE H_GET_64
53
28
#define PUT_AOUTHDR_TSIZE H_PUT_64
54
712
#define GET_AOUTHDR_DSIZE H_GET_64
55
28
#define PUT_AOUTHDR_DSIZE H_PUT_64
56
712
#define GET_AOUTHDR_BSIZE H_GET_64
57
28
#define PUT_AOUTHDR_BSIZE H_PUT_64
58
712
#define GET_AOUTHDR_ENTRY H_GET_64
59
28
#define PUT_AOUTHDR_ENTRY H_PUT_64
60
712
#define GET_AOUTHDR_TEXT_START H_GET_64
61
28
#define PUT_AOUTHDR_TEXT_START H_PUT_64
62
712
#define GET_AOUTHDR_DATA_START H_GET_64
63
28
#define PUT_AOUTHDR_DATA_START H_PUT_64
64
14.4k
#define GET_SCNHDR_PADDR H_GET_64
65
25
#define PUT_SCNHDR_PADDR H_PUT_64
66
14.4k
#define GET_SCNHDR_VADDR H_GET_64
67
25
#define PUT_SCNHDR_VADDR H_PUT_64
68
14.4k
#define GET_SCNHDR_SIZE H_GET_64
69
25
#define PUT_SCNHDR_SIZE H_PUT_64
70
14.4k
#define GET_SCNHDR_SCNPTR H_GET_64
71
25
#define PUT_SCNHDR_SCNPTR H_PUT_64
72
14.4k
#define GET_SCNHDR_RELPTR H_GET_64
73
25
#define PUT_SCNHDR_RELPTR H_PUT_64
74
14.4k
#define GET_SCNHDR_LNNOPTR H_GET_64
75
25
#define PUT_SCNHDR_LNNOPTR H_PUT_64
76
77
#define ALPHAECOFF
78
79
#define NO_COFF_RELOCS
80
#define NO_COFF_SYMBOLS
81
#define NO_COFF_LINENOS
82
#define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
83
#define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
84
#define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
85
#define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
86
#define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
87
#define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
88
#include "coffswap.h"
89
90
/* Get the ECOFF swapping routines.  */
91
#define ECOFF_64
92
#include "ecoffswap.h"
93

94
/* How to process the various reloc types.  */
95
96
static bfd_reloc_status_type
97
reloc_nil (bfd *abfd ATTRIBUTE_UNUSED,
98
     arelent *reloc ATTRIBUTE_UNUSED,
99
     asymbol *sym ATTRIBUTE_UNUSED,
100
     void *data ATTRIBUTE_UNUSED,
101
     asection *sec ATTRIBUTE_UNUSED,
102
     bfd *output_bfd ATTRIBUTE_UNUSED,
103
     char **error_message ATTRIBUTE_UNUSED)
104
0
{
105
0
  return bfd_reloc_ok;
106
0
}
107
108
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
109
   from smaller values.  Start with zero, widen, *then* decrement.  */
110
#define MINUS_ONE (((bfd_vma)0) - 1)
111
112
static reloc_howto_type alpha_howto_table[] =
113
{
114
  /* Reloc type 0 is ignored by itself.  However, it appears after a
115
     GPDISP reloc to identify the location where the low order 16 bits
116
     of the gp register are loaded.  */
117
  HOWTO (ALPHA_R_IGNORE,  /* type */
118
   0,     /* rightshift */
119
   1,     /* size */
120
   8,     /* bitsize */
121
   true,      /* pc_relative */
122
   0,     /* bitpos */
123
   complain_overflow_dont, /* complain_on_overflow */
124
   reloc_nil,   /* special_function */
125
   "IGNORE",    /* name */
126
   true,      /* partial_inplace */
127
   0,     /* src_mask */
128
   0,     /* dst_mask */
129
   true),     /* pcrel_offset */
130
131
  /* A 32 bit reference to a symbol.  */
132
  HOWTO (ALPHA_R_REFLONG, /* type */
133
   0,     /* rightshift */
134
   4,     /* size */
135
   32,      /* bitsize */
136
   false,     /* pc_relative */
137
   0,     /* bitpos */
138
   complain_overflow_bitfield, /* complain_on_overflow */
139
   0,     /* special_function */
140
   "REFLONG",   /* name */
141
   true,      /* partial_inplace */
142
   0xffffffff,    /* src_mask */
143
   0xffffffff,    /* dst_mask */
144
   false),    /* pcrel_offset */
145
146
  /* A 64 bit reference to a symbol.  */
147
  HOWTO (ALPHA_R_REFQUAD, /* type */
148
   0,     /* rightshift */
149
   8,     /* size */
150
   64,      /* bitsize */
151
   false,     /* pc_relative */
152
   0,     /* bitpos */
153
   complain_overflow_bitfield, /* complain_on_overflow */
154
   0,     /* special_function */
155
   "REFQUAD",   /* name */
156
   true,      /* partial_inplace */
157
   MINUS_ONE,   /* src_mask */
158
   MINUS_ONE,   /* dst_mask */
159
   false),    /* pcrel_offset */
160
161
  /* A 32 bit GP relative offset.  This is just like REFLONG except
162
     that when the value is used the value of the gp register will be
163
     added in.  */
164
  HOWTO (ALPHA_R_GPREL32, /* type */
165
   0,     /* rightshift */
166
   4,     /* size */
167
   32,      /* bitsize */
168
   false,     /* pc_relative */
169
   0,     /* bitpos */
170
   complain_overflow_bitfield, /* complain_on_overflow */
171
   0,     /* special_function */
172
   "GPREL32",   /* name */
173
   true,      /* partial_inplace */
174
   0xffffffff,    /* src_mask */
175
   0xffffffff,    /* dst_mask */
176
   false),    /* pcrel_offset */
177
178
  /* Used for an instruction that refers to memory off the GP
179
     register.  The offset is 16 bits of the 32 bit instruction.  This
180
     reloc always seems to be against the .lita section.  */
181
  HOWTO (ALPHA_R_LITERAL, /* type */
182
   0,     /* rightshift */
183
   4,     /* size */
184
   16,      /* bitsize */
185
   false,     /* pc_relative */
186
   0,     /* bitpos */
187
   complain_overflow_signed, /* complain_on_overflow */
188
   0,     /* special_function */
189
   "LITERAL",   /* name */
190
   true,      /* partial_inplace */
191
   0xffff,    /* src_mask */
192
   0xffff,    /* dst_mask */
193
   false),    /* pcrel_offset */
194
195
  /* This reloc only appears immediately following a LITERAL reloc.
196
     It identifies a use of the literal.  It seems that the linker can
197
     use this to eliminate a portion of the .lita section.  The symbol
198
     index is special: 1 means the literal address is in the base
199
     register of a memory format instruction; 2 means the literal
200
     address is in the byte offset register of a byte-manipulation
201
     instruction; 3 means the literal address is in the target
202
     register of a jsr instruction.  This does not actually do any
203
     relocation.  */
204
  HOWTO (ALPHA_R_LITUSE,  /* type */
205
   0,     /* rightshift */
206
   4,     /* size */
207
   32,      /* bitsize */
208
   false,     /* pc_relative */
209
   0,     /* bitpos */
210
   complain_overflow_dont, /* complain_on_overflow */
211
   reloc_nil,   /* special_function */
212
   "LITUSE",    /* name */
213
   false,     /* partial_inplace */
214
   0,     /* src_mask */
215
   0,     /* dst_mask */
216
   false),    /* pcrel_offset */
217
218
  /* Load the gp register.  This is always used for a ldah instruction
219
     which loads the upper 16 bits of the gp register.  The next reloc
220
     will be an IGNORE reloc which identifies the location of the lda
221
     instruction which loads the lower 16 bits.  The symbol index of
222
     the GPDISP instruction appears to actually be the number of bytes
223
     between the ldah and lda instructions.  This gives two different
224
     ways to determine where the lda instruction is; I don't know why
225
     both are used.  The value to use for the relocation is the
226
     difference between the GP value and the current location; the
227
     load will always be done against a register holding the current
228
     address.  */
229
  HOWTO (ALPHA_R_GPDISP,  /* type */
230
   16,      /* rightshift */
231
   4,     /* size */
232
   16,      /* bitsize */
233
   true,      /* pc_relative */
234
   0,     /* bitpos */
235
   complain_overflow_dont, /* complain_on_overflow */
236
   reloc_nil,   /* special_function */
237
   "GPDISP",    /* name */
238
   true,      /* partial_inplace */
239
   0xffff,    /* src_mask */
240
   0xffff,    /* dst_mask */
241
   true),     /* pcrel_offset */
242
243
  /* A 21 bit branch.  The native assembler generates these for
244
     branches within the text segment, and also fills in the PC
245
     relative offset in the instruction.  */
246
  HOWTO (ALPHA_R_BRADDR,  /* type */
247
   2,     /* rightshift */
248
   4,     /* size */
249
   21,      /* bitsize */
250
   true,      /* pc_relative */
251
   0,     /* bitpos */
252
   complain_overflow_signed, /* complain_on_overflow */
253
   0,     /* special_function */
254
   "BRADDR",    /* name */
255
   true,      /* partial_inplace */
256
   0x1fffff,    /* src_mask */
257
   0x1fffff,    /* dst_mask */
258
   false),    /* pcrel_offset */
259
260
  /* A hint for a jump to a register.  */
261
  HOWTO (ALPHA_R_HINT,    /* type */
262
   2,     /* rightshift */
263
   4,     /* size */
264
   14,      /* bitsize */
265
   true,      /* pc_relative */
266
   0,     /* bitpos */
267
   complain_overflow_dont, /* complain_on_overflow */
268
   0,     /* special_function */
269
   "HINT",    /* name */
270
   true,      /* partial_inplace */
271
   0x3fff,    /* src_mask */
272
   0x3fff,    /* dst_mask */
273
   false),    /* pcrel_offset */
274
275
  /* 16 bit PC relative offset.  */
276
  HOWTO (ALPHA_R_SREL16,  /* type */
277
   0,     /* rightshift */
278
   2,     /* size */
279
   16,      /* bitsize */
280
   true,      /* pc_relative */
281
   0,     /* bitpos */
282
   complain_overflow_signed, /* complain_on_overflow */
283
   0,     /* special_function */
284
   "SREL16",    /* name */
285
   true,      /* partial_inplace */
286
   0xffff,    /* src_mask */
287
   0xffff,    /* dst_mask */
288
   false),    /* pcrel_offset */
289
290
  /* 32 bit PC relative offset.  */
291
  HOWTO (ALPHA_R_SREL32,  /* type */
292
   0,     /* rightshift */
293
   4,     /* size */
294
   32,      /* bitsize */
295
   true,      /* pc_relative */
296
   0,     /* bitpos */
297
   complain_overflow_signed, /* complain_on_overflow */
298
   0,     /* special_function */
299
   "SREL32",    /* name */
300
   true,      /* partial_inplace */
301
   0xffffffff,    /* src_mask */
302
   0xffffffff,    /* dst_mask */
303
   false),    /* pcrel_offset */
304
305
  /* A 64 bit PC relative offset.  */
306
  HOWTO (ALPHA_R_SREL64,  /* type */
307
   0,     /* rightshift */
308
   8,     /* size */
309
   64,      /* bitsize */
310
   true,      /* pc_relative */
311
   0,     /* bitpos */
312
   complain_overflow_signed, /* complain_on_overflow */
313
   0,     /* special_function */
314
   "SREL64",    /* name */
315
   true,      /* partial_inplace */
316
   MINUS_ONE,   /* src_mask */
317
   MINUS_ONE,   /* dst_mask */
318
   false),    /* pcrel_offset */
319
320
  /* Push a value on the reloc evaluation stack.  */
321
  HOWTO (ALPHA_R_OP_PUSH, /* type */
322
   0,     /* rightshift */
323
   0,     /* size */
324
   0,     /* bitsize */
325
   false,     /* pc_relative */
326
   0,     /* bitpos */
327
   complain_overflow_dont, /* complain_on_overflow */
328
   0,     /* special_function */
329
   "OP_PUSH",   /* name */
330
   false,     /* partial_inplace */
331
   0,     /* src_mask */
332
   0,     /* dst_mask */
333
   false),    /* pcrel_offset */
334
335
  /* Store the value from the stack at the given address.  Store it in
336
     a bitfield of size r_size starting at bit position r_offset.  */
337
  HOWTO (ALPHA_R_OP_STORE,  /* type */
338
   0,     /* rightshift */
339
   8,     /* size */
340
   64,      /* bitsize */
341
   false,     /* pc_relative */
342
   0,     /* bitpos */
343
   complain_overflow_dont, /* complain_on_overflow */
344
   0,     /* special_function */
345
   "OP_STORE",    /* name */
346
   false,     /* partial_inplace */
347
   0,     /* src_mask */
348
   MINUS_ONE,   /* dst_mask */
349
   false),    /* pcrel_offset */
350
351
  /* Subtract the reloc address from the value on the top of the
352
     relocation stack.  */
353
  HOWTO (ALPHA_R_OP_PSUB, /* type */
354
   0,     /* rightshift */
355
   0,     /* size */
356
   0,     /* bitsize */
357
   false,     /* pc_relative */
358
   0,     /* bitpos */
359
   complain_overflow_dont, /* complain_on_overflow */
360
   0,     /* special_function */
361
   "OP_PSUB",   /* name */
362
   false,     /* partial_inplace */
363
   0,     /* src_mask */
364
   0,     /* dst_mask */
365
   false),    /* pcrel_offset */
366
367
  /* Shift the value on the top of the relocation stack right by the
368
     given value.  */
369
  HOWTO (ALPHA_R_OP_PRSHIFT,  /* type */
370
   0,     /* rightshift */
371
   0,     /* size */
372
   0,     /* bitsize */
373
   false,     /* pc_relative */
374
   0,     /* bitpos */
375
   complain_overflow_dont, /* complain_on_overflow */
376
   0,     /* special_function */
377
   "OP_PRSHIFT",    /* name */
378
   false,     /* partial_inplace */
379
   0,     /* src_mask */
380
   0,     /* dst_mask */
381
   false),    /* pcrel_offset */
382
383
  /* Adjust the GP value for a new range in the object file.  */
384
  HOWTO (ALPHA_R_GPVALUE, /* type */
385
   0,     /* rightshift */
386
   0,     /* size */
387
   0,     /* bitsize */
388
   false,     /* pc_relative */
389
   0,     /* bitpos */
390
   complain_overflow_dont, /* complain_on_overflow */
391
   0,     /* special_function */
392
   "GPVALUE",   /* name */
393
   false,     /* partial_inplace */
394
   0,     /* src_mask */
395
   0,     /* dst_mask */
396
   false)     /* pcrel_offset */
397
};
398

399
/* Recognize an Alpha ECOFF file.  */
400
401
static bfd_cleanup
402
alpha_ecoff_object_p (bfd *abfd)
403
189k
{
404
189k
  bfd_cleanup ret;
405
406
189k
  ret = coff_object_p (abfd);
407
408
189k
  if (ret != NULL)
409
2.84k
    {
410
2.84k
      asection *sec;
411
412
      /* Alpha ECOFF has a .pdata section.  The lnnoptr field of the
413
   .pdata section is the number of entries it contains.  Each
414
   entry takes up 8 bytes.  The number of entries is required
415
   since the section is aligned to a 16 byte boundary.  When we
416
   link .pdata sections together, we do not want to include the
417
   alignment bytes.  We handle this on input by faking the size
418
   of the .pdata section to remove the unwanted alignment bytes.
419
   On output we will set the lnnoptr field and force the
420
   alignment.  */
421
2.84k
      sec = bfd_get_section_by_name (abfd, _PDATA);
422
2.84k
      if (sec != NULL)
423
441
  {
424
441
    bfd_size_type size;
425
426
441
    size = (bfd_size_type) sec->line_filepos * 8;
427
441
    BFD_ASSERT (size == sec->size
428
441
          || size + 8 == sec->size);
429
441
    if (!bfd_set_section_size (sec, size))
430
0
      return NULL;
431
441
  }
432
2.84k
    }
433
434
189k
  return ret;
435
189k
}
436
437
/* See whether the magic number matches.  */
438
439
static bool
440
alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED,
441
           void *filehdr)
442
179k
{
443
179k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
444
445
179k
  if (! ALPHA_ECOFF_BADMAG (*internal_f))
446
2.89k
    return true;
447
448
176k
  if (ALPHA_ECOFF_COMPRESSEDMAG (*internal_f))
449
6
    _bfd_error_handler
450
6
      (_("%pB: cannot handle compressed Alpha binaries; "
451
6
   "use compiler flags, or objZ, to generate uncompressed binaries"),
452
6
       abfd);
453
454
176k
  return false;
455
179k
}
456
457
/* This is a hook called by coff_real_object_p to create any backend
458
   specific information.  */
459
460
static void *
461
alpha_ecoff_mkobject_hook (bfd *abfd, void *filehdr, void *aouthdr)
462
2.88k
{
463
2.88k
  void *ecoff;
464
465
2.88k
  ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr);
466
467
2.88k
  if (ecoff != NULL)
468
2.88k
    {
469
2.88k
      struct internal_filehdr *internal_f = filehdr;
470
471
      /* Set additional BFD flags according to the object type from the
472
   machine specific file header flags.  */
473
2.88k
      switch (internal_f->f_flags & F_ALPHA_OBJECT_TYPE_MASK)
474
2.88k
  {
475
458
  case F_ALPHA_SHARABLE:
476
458
    abfd->flags |= DYNAMIC;
477
458
    break;
478
245
  case F_ALPHA_CALL_SHARED:
479
    /* Always executable if using shared libraries as the run time
480
       loader might resolve undefined references.  */
481
245
    abfd->flags |= (DYNAMIC | EXEC_P);
482
245
    break;
483
2.88k
  }
484
2.88k
    }
485
2.88k
  return ecoff;
486
2.88k
}
487

488
/* Reloc handling.  */
489
490
/* Swap a reloc in.  */
491
492
static void
493
alpha_ecoff_swap_reloc_in (bfd *abfd,
494
         void *ext_ptr,
495
         struct internal_reloc *intern)
496
41.6k
{
497
41.6k
  const RELOC *ext = ext_ptr;
498
499
41.6k
  memset (intern, 0, sizeof (*intern));
500
41.6k
  intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr);
501
41.6k
  intern->r_symndx = H_GET_32 (abfd, ext->r_symndx);
502
503
41.6k
  BFD_ASSERT (bfd_header_little_endian (abfd));
504
505
41.6k
  intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
506
41.6k
        >> RELOC_BITS0_TYPE_SH_LITTLE);
507
41.6k
  intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
508
41.6k
  intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
509
41.6k
          >> RELOC_BITS1_OFFSET_SH_LITTLE);
510
  /* Ignored the reserved bits.  */
511
41.6k
  intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
512
41.6k
        >> RELOC_BITS3_SIZE_SH_LITTLE);
513
514
41.6k
  if (intern->r_type == ALPHA_R_LITUSE
515
41.2k
      || intern->r_type == ALPHA_R_GPDISP)
516
1.03k
    {
517
      /* Handle the LITUSE and GPDISP relocs specially.  Its symndx
518
   value is not actually a symbol index, but is instead a
519
   special code.  We put the code in the r_size field, and
520
   clobber the symndx.  */
521
1.03k
      BFD_ASSERT (intern->r_size == 0);
522
1.03k
      intern->r_size = intern->r_symndx;
523
1.03k
      intern->r_symndx = RELOC_SECTION_NONE;
524
1.03k
    }
525
40.6k
  else if (intern->r_type == ALPHA_R_IGNORE)
526
17.6k
    {
527
      /* The IGNORE reloc generally follows a GPDISP reloc, and is
528
   against the .lita section.  The section is irrelevant.  */
529
17.6k
      BFD_ASSERT (intern->r_extern || intern->r_symndx != RELOC_SECTION_ABS);
530
17.6k
      if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
531
66
  intern->r_symndx = RELOC_SECTION_ABS;
532
17.6k
    }
533
22.9k
  else if (intern->r_type == ALPHA_R_OP_STORE)
534
402
    {
535
      /* Size of 64 bits is encoded as 0 in this 6-bit field.  */
536
402
      if (intern->r_size == 0)
537
131
  intern->r_size = 64;
538
402
    }
539
41.6k
}
540
541
/* Swap a reloc out.  */
542
543
static void
544
alpha_ecoff_swap_reloc_out (bfd *abfd,
545
          const struct internal_reloc *intern,
546
          void *dst)
547
374
{
548
374
  RELOC *ext = dst;
549
374
  long symndx;
550
374
  unsigned char size;
551
552
  /* Undo the hackery done in swap_reloc_in.  */
553
374
  if (intern->r_type == ALPHA_R_LITUSE
554
365
      || intern->r_type == ALPHA_R_GPDISP)
555
12
    {
556
12
      symndx = intern->r_size;
557
12
      size = 0;
558
12
    }
559
362
  else if (intern->r_type == ALPHA_R_IGNORE
560
298
     && ! intern->r_extern
561
298
     && intern->r_symndx == RELOC_SECTION_ABS)
562
298
    {
563
298
      symndx = RELOC_SECTION_LITA;
564
298
      size = intern->r_size;
565
298
    }
566
64
  else
567
64
    {
568
64
      symndx = intern->r_symndx;
569
64
      size = intern->r_size;
570
64
    }
571
572
  /* XXX FIXME:  The maximum symndx value used to be 14 but this
573
     fails with object files produced by DEC's C++ compiler.
574
     Where does the value 14 (or 15) come from anyway ?  */
575
374
  BFD_ASSERT (intern->r_extern
576
374
        || (intern->r_symndx >= 0 && intern->r_symndx <= 15));
577
578
374
  H_PUT_64 (abfd, intern->r_vaddr, ext->r_vaddr);
579
374
  H_PUT_32 (abfd, symndx, ext->r_symndx);
580
581
374
  BFD_ASSERT (bfd_header_little_endian (abfd));
582
583
374
  ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE)
584
374
        & RELOC_BITS0_TYPE_LITTLE);
585
374
  ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0)
586
374
        | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE)
587
374
           & RELOC_BITS1_OFFSET_LITTLE));
588
374
  ext->r_bits[2] = 0;
589
374
  ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE)
590
374
        & RELOC_BITS3_SIZE_LITTLE);
591
374
}
592
593
/* Finish canonicalizing a reloc.  Part of this is generic to all
594
   ECOFF targets, and that part is in ecoff.c.  The rest is done in
595
   this backend routine.  It must fill in the howto field.  */
596
597
static void
598
alpha_adjust_reloc_in (bfd *abfd,
599
           const struct internal_reloc *intern,
600
           arelent *rptr)
601
41.6k
{
602
41.6k
  if (intern->r_type > ALPHA_R_GPVALUE)
603
15.7k
    {
604
      /* xgettext:c-format */
605
15.7k
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
606
15.7k
        abfd, intern->r_type);
607
15.7k
      bfd_set_error (bfd_error_bad_value);
608
15.7k
      rptr->addend = 0;
609
15.7k
      rptr->howto = NULL;
610
15.7k
      return;
611
15.7k
    }
612
613
25.9k
  switch (intern->r_type)
614
25.9k
    {
615
229
    case ALPHA_R_BRADDR:
616
683
    case ALPHA_R_SREL16:
617
1.14k
    case ALPHA_R_SREL32:
618
1.68k
    case ALPHA_R_SREL64:
619
      /* This relocs appear to be fully resolved when they are against
620
   internal symbols.  Against external symbols, BRADDR at least
621
   appears to be resolved against the next instruction.  */
622
1.68k
      if (! intern->r_extern)
623
688
  rptr->addend = 0;
624
995
      else
625
995
  rptr->addend = - (intern->r_vaddr + 4);
626
1.68k
      break;
627
628
605
    case ALPHA_R_GPREL32:
629
1.46k
    case ALPHA_R_LITERAL:
630
      /* Copy the gp value for this object file into the addend, to
631
   ensure that we are not confused by the linker.  */
632
1.46k
      if (! intern->r_extern)
633
1.04k
  rptr->addend += ecoff_data (abfd)->gp;
634
1.46k
      break;
635
636
394
    case ALPHA_R_LITUSE:
637
1.03k
    case ALPHA_R_GPDISP:
638
      /* The LITUSE and GPDISP relocs do not use a symbol, or an
639
   addend, but they do use a special code.  Put this code in the
640
   addend field.  */
641
1.03k
      rptr->addend = intern->r_size;
642
1.03k
      break;
643
644
402
    case ALPHA_R_OP_STORE:
645
      /* The STORE reloc needs the size and offset fields.  We store
646
   them in the addend.  */
647
402
      BFD_ASSERT (intern->r_offset <= 256);
648
402
      rptr->addend = (intern->r_offset << 8) + intern->r_size;
649
402
      break;
650
651
663
    case ALPHA_R_OP_PUSH:
652
871
    case ALPHA_R_OP_PSUB:
653
1.22k
    case ALPHA_R_OP_PRSHIFT:
654
      /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
655
   address.  I believe that the address supplied is really an
656
   addend.  */
657
1.22k
      rptr->addend = intern->r_vaddr;
658
1.22k
      break;
659
660
363
    case ALPHA_R_GPVALUE:
661
      /* Set the addend field to the new GP value.  */
662
363
      rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp;
663
363
      break;
664
665
17.6k
    case ALPHA_R_IGNORE:
666
      /* If the type is ALPHA_R_IGNORE, make sure this is a reference
667
   to the absolute section so that the reloc is ignored.  For
668
   some reason the address of this reloc type is not adjusted by
669
   the section vma.  We record the gp value for this object file
670
   here, for convenience when doing the GPDISP relocation.  */
671
17.6k
      rptr->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
672
17.6k
      rptr->address = intern->r_vaddr;
673
17.6k
      rptr->addend = ecoff_data (abfd)->gp;
674
17.6k
      break;
675
676
2.11k
    default:
677
2.11k
      break;
678
25.9k
    }
679
680
25.9k
  rptr->howto = &alpha_howto_table[intern->r_type];
681
25.9k
}
682
683
/* When writing out a reloc we need to pull some values back out of
684
   the addend field into the reloc.  This is roughly the reverse of
685
   alpha_adjust_reloc_in, except that there are several changes we do
686
   not need to undo.  */
687
688
static void
689
alpha_adjust_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
690
      const arelent *rel,
691
      struct internal_reloc *intern)
692
374
{
693
374
  switch (intern->r_type)
694
374
    {
695
9
    case ALPHA_R_LITUSE:
696
12
    case ALPHA_R_GPDISP:
697
12
      intern->r_size = rel->addend;
698
12
      break;
699
700
0
    case ALPHA_R_OP_STORE:
701
0
      intern->r_size = rel->addend & 0xff;
702
0
      intern->r_offset = (rel->addend >> 8) & 0xff;
703
0
      break;
704
705
3
    case ALPHA_R_OP_PUSH:
706
5
    case ALPHA_R_OP_PSUB:
707
8
    case ALPHA_R_OP_PRSHIFT:
708
8
      intern->r_vaddr = rel->addend;
709
8
      break;
710
711
298
    case ALPHA_R_IGNORE:
712
298
      intern->r_vaddr = rel->address;
713
298
      break;
714
715
56
    default:
716
56
      break;
717
374
    }
718
374
}
719
720
/* Write VAL to a little-endian bitfield specified by BITOFFSET and
721
   BITSIZE at CONTENTS + SECOFFSET.  Verify that these parameter are
722
   valid for SEC in ABFD.  */
723
724
static bool
725
write_bit_field (bfd *abfd, asection *sec,
726
     bfd_byte *contents, bfd_size_type secoffset,
727
     unsigned int bitoffset, unsigned int bitsize, uint64_t val)
728
0
{
729
0
  if (bitsize == 0)
730
0
    return true;
731
732
0
  bfd_size_type secsize = bfd_get_section_limit_octets (abfd, sec);
733
0
  unsigned int startbyte = bitoffset >> 3;
734
0
  unsigned int endbyte = (bitoffset + bitsize - 1) >> 3;
735
736
0
  if (secoffset > secsize || secsize - secoffset <= endbyte)
737
0
    return false;
738
739
0
  unsigned int startbit = bitoffset & 7;
740
0
  unsigned int endbit = (bitoffset + bitsize - 1) & 7;
741
0
  unsigned int mask = -1u << startbit;
742
0
  unsigned char *p = contents + secoffset;
743
0
  if (startbyte != endbyte)
744
0
    {
745
0
      p[startbyte] = (p[startbyte] & ~mask) | ((val << startbit) & mask);
746
0
      val = val >> (8 - startbit);
747
748
0
      for (unsigned int off = startbyte + 1; off < endbyte; ++off)
749
0
  {
750
0
    p[off] = val;
751
0
    val >>= 8;
752
0
  }
753
0
      mask = ~(-1u << (1 + endbit));
754
0
    }
755
0
  else
756
0
    {
757
0
      val = val << startbit;
758
0
      mask = mask & ~(-1u << (1 + endbit));
759
0
    }
760
0
  p[endbyte] = (p[endbyte] & ~mask) | (val & mask);
761
0
  return true;
762
0
}
763
764
/* The size of the stack for the relocation evaluator.  */
765
1
#define RELOC_STACKSIZE (10)
766
767
/* Alpha ECOFF relocs have a built in expression evaluator as well as
768
   other interdependencies.  Rather than use a bunch of special
769
   functions and global variables, we use a single routine to do all
770
   the relocation for a section.  I haven't yet worked out how the
771
   assembler is going to handle this.  */
772
773
static bfd_byte *
774
alpha_ecoff_get_relocated_section_contents
775
  (bfd *abfd,
776
   struct bfd_link_info *link_info,
777
   const struct bfd_link_order *link_order,
778
   bfd_byte *data,
779
   bool relocatable,
780
   asymbol **symbols)
781
13
{
782
13
  bfd *input_bfd = link_order->u.indirect.section->owner;
783
13
  asection *input_section = link_order->u.indirect.section;
784
13
  long reloc_size;
785
13
  arelent **reloc_vector;
786
13
  long reloc_count;
787
13
  bfd *output_bfd = relocatable ? abfd : NULL;
788
13
  bfd_vma gp;
789
13
  bool gp_undefined;
790
13
  bfd_vma stack[RELOC_STACKSIZE];
791
13
  int tos = 0;
792
793
13
  reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
794
13
  if (reloc_size < 0)
795
0
    return NULL;
796
797
13
  bfd_byte *orig_data = data;
798
13
  if (!bfd_get_full_section_contents (input_bfd, input_section, &data))
799
0
    return NULL;
800
801
13
  if (data == NULL)
802
0
    return NULL;
803
804
13
  if (reloc_size == 0)
805
0
    return data;
806
807
13
  reloc_vector = bfd_malloc (reloc_size);
808
13
  if (reloc_vector == NULL)
809
0
    goto error_return;
810
811
13
  reloc_count = bfd_canonicalize_reloc (input_bfd, input_section,
812
13
          reloc_vector, symbols);
813
13
  if (reloc_count < 0)
814
0
    goto error_return;
815
13
  if (reloc_count == 0)
816
0
    goto successful_return;
817
818
  /* Get the GP value for the output BFD.  */
819
13
  gp_undefined = false;
820
13
  gp = _bfd_get_gp_value (abfd);
821
13
  if (gp == 0)
822
13
    {
823
13
      if (relocatable)
824
0
  {
825
0
    asection *sec;
826
0
    bfd_vma lo;
827
828
    /* Make up a value.  */
829
0
    lo = -1;
830
0
    for (sec = abfd->sections; sec != NULL; sec = sec->next)
831
0
      {
832
0
        if (sec->vma < lo
833
0
      && (strcmp (sec->name, ".sbss") == 0
834
0
          || strcmp (sec->name, ".sdata") == 0
835
0
          || strcmp (sec->name, ".lit4") == 0
836
0
          || strcmp (sec->name, ".lit8") == 0
837
0
          || strcmp (sec->name, ".lita") == 0))
838
0
    lo = sec->vma;
839
0
      }
840
0
    gp = lo + 0x8000;
841
0
    _bfd_set_gp_value (abfd, gp);
842
0
  }
843
13
      else
844
13
  {
845
13
    struct bfd_link_hash_entry *h;
846
847
13
    h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
848
13
            true);
849
13
    if (h == NULL
850
0
        || h->type != bfd_link_hash_defined)
851
13
      gp_undefined = true;
852
0
    else
853
0
      {
854
0
        gp = (h->u.def.value
855
0
        + h->u.def.section->output_section->vma
856
0
        + h->u.def.section->output_offset);
857
0
        _bfd_set_gp_value (abfd, gp);
858
0
      }
859
13
  }
860
13
    }
861
862
103
  for (arelent **relp = reloc_vector; *relp != NULL; relp++)
863
103
    {
864
103
      arelent *rel;
865
103
      bfd_reloc_status_type r;
866
103
      char *err = NULL;
867
103
      unsigned int r_type;
868
869
103
      rel = *relp;
870
103
      if (rel->howto == NULL)
871
1
  {
872
1
    r = bfd_reloc_notsupported;
873
1
    r_type = ALPHA_R_IGNORE;
874
1
  }
875
102
      else
876
102
  {
877
102
    r = bfd_reloc_ok;
878
102
    r_type = rel->howto->type;
879
102
  }
880
103
      switch (r_type)
881
103
  {
882
86
  case ALPHA_R_IGNORE:
883
86
    rel->address += input_section->output_offset;
884
86
    break;
885
886
0
  case ALPHA_R_REFLONG:
887
0
  case ALPHA_R_REFQUAD:
888
0
  case ALPHA_R_BRADDR:
889
1
  case ALPHA_R_HINT:
890
1
  case ALPHA_R_SREL16:
891
1
  case ALPHA_R_SREL32:
892
2
  case ALPHA_R_SREL64:
893
2
    if (relocatable
894
0
        && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
895
0
      {
896
0
        rel->address += input_section->output_offset;
897
0
        break;
898
0
      }
899
2
    r = bfd_perform_relocation (input_bfd, rel, data, input_section,
900
2
              output_bfd, &err);
901
2
    break;
902
903
0
  case ALPHA_R_GPREL32:
904
    /* This relocation is used in a switch table.  It is a 32
905
       bit offset from the current GP value.  We must adjust it
906
       by the different between the original GP value and the
907
       current GP value.  The original GP value is stored in the
908
       addend.  We adjust the addend and let
909
       bfd_perform_relocation finish the job.  */
910
0
    rel->addend -= gp;
911
0
    r = bfd_perform_relocation (input_bfd, rel, data, input_section,
912
0
              output_bfd, &err);
913
0
    if (r == bfd_reloc_ok && gp_undefined)
914
0
      {
915
0
        r = bfd_reloc_dangerous;
916
0
        err = (char *) _("GP relative relocation used when GP not defined");
917
0
      }
918
0
    break;
919
920
0
  case ALPHA_R_LITERAL:
921
    /* This is a reference to a literal value, generally
922
       (always?) in the .lita section.  This is a 16 bit GP
923
       relative relocation.  Sometimes the subsequent reloc is a
924
       LITUSE reloc, which indicates how this reloc is used.
925
       This sometimes permits rewriting the two instructions
926
       referred to by the LITERAL and the LITUSE into different
927
       instructions which do not refer to .lita.  This can save
928
       a memory reference, and permits removing a value from
929
       .lita thus saving GP relative space.
930
931
       We do not these optimizations.  To do them we would need
932
       to arrange to link the .lita section first, so that by
933
       the time we got here we would know the final values to
934
       use.  This would not be particularly difficult, but it is
935
       not currently implemented.  */
936
937
0
    rel->addend -= gp;
938
0
    r = bfd_perform_relocation (input_bfd, rel, data, input_section,
939
0
              output_bfd, &err);
940
0
    if (r == bfd_reloc_ok && gp_undefined)
941
0
      {
942
0
        r = bfd_reloc_dangerous;
943
0
        err = (char *) _("GP relative relocation used"
944
0
             " when GP not defined");
945
0
      }
946
0
    break;
947
948
0
  case ALPHA_R_LITUSE:
949
    /* See ALPHA_R_LITERAL above for the uses of this reloc.  It
950
       does not cause anything to happen, itself.  */
951
0
    rel->address += input_section->output_offset;
952
0
    break;
953
954
0
  case ALPHA_R_GPDISP:
955
    /* This marks the ldah of an ldah/lda pair which loads the
956
       gp register with the difference of the gp value and the
957
       current location.  The second of the pair is r_size bytes
958
       ahead; it used to be marked with an ALPHA_R_IGNORE reloc,
959
       but that no longer happens in OSF/1 3.2.  */
960
0
    if (bfd_reloc_offset_in_range (rel->howto, input_bfd, input_section,
961
0
           rel->address)
962
0
        && bfd_reloc_offset_in_range (rel->howto, input_bfd, input_section,
963
0
              rel->address + rel->addend))
964
0
      {
965
        /* Get the two instructions.  */
966
0
        bfd_byte *p = data + rel->address;
967
0
        bfd_vma insn1 = bfd_get_32 (input_bfd, p);
968
0
        bfd_vma insn2 = bfd_get_32 (input_bfd, p + rel->addend);
969
970
0
        BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
971
0
        BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
972
973
        /* Get the existing addend.  We must account for the sign
974
     extension done by lda and ldah.  */
975
0
        bfd_vma addend = (((((insn1 & 0xffff) ^ 0x8000) - 0x8000) << 16)
976
0
        + ((((insn2 & 0xffff) ^ 0x8000) - 0x8000)));
977
978
        /* The existing addend includes the different between the
979
     gp of the input BFD and the address in the input BFD.
980
     Subtract this out.  */
981
0
        addend -= ecoff_data (input_bfd)->gp - input_section->vma;
982
983
        /* Now add in the final gp value, and subtract out the
984
     final address.  */
985
0
        addend += gp - (input_section->output_section->vma
986
0
            + input_section->output_offset);
987
988
        /* Change the instructions, accounting for the sign
989
     extension, and write them out.  */
990
0
        insn1 = (insn1 & ~0xffff) | (((addend + 0x8000) >> 16) & 0xffff);
991
0
        insn2 = (insn2 & ~0xffff) | (addend & 0xffff);
992
993
0
        bfd_put_32 (input_bfd, insn1, p);
994
0
        bfd_put_32 (input_bfd, insn2, p + rel->addend);
995
0
      }
996
0
    else
997
0
      r = bfd_reloc_outofrange;
998
999
0
    rel->address += input_section->output_offset;
1000
0
    break;
1001
1002
1
  case ALPHA_R_OP_PUSH:
1003
    /* Push a value on the reloc evaluation stack.  */
1004
1
    {
1005
1
      asymbol *symbol;
1006
1
      bfd_vma relocation;
1007
1008
1
      if (relocatable)
1009
0
        {
1010
0
    rel->address += input_section->output_offset;
1011
0
    break;
1012
0
        }
1013
1014
      /* Figure out the relocation of this symbol.  */
1015
1
      symbol = *rel->sym_ptr_ptr;
1016
1017
1
      if (bfd_is_und_section (symbol->section))
1018
0
        r = bfd_reloc_undefined;
1019
1020
1
      if (bfd_is_com_section (symbol->section))
1021
0
        relocation = 0;
1022
1
      else
1023
1
        relocation = symbol->value;
1024
1
      relocation += symbol->section->output_section->vma;
1025
1
      relocation += symbol->section->output_offset;
1026
1
      relocation += rel->addend;
1027
1028
1
      if (tos >= RELOC_STACKSIZE)
1029
0
        {
1030
0
    r = bfd_reloc_notsupported;
1031
0
    break;
1032
0
        }
1033
1034
1
      stack[tos++] = relocation;
1035
1
    }
1036
0
    break;
1037
1038
9
  case ALPHA_R_OP_STORE:
1039
    /* Store a value from the reloc stack into a bitfield.  */
1040
9
    {
1041
9
      if (relocatable)
1042
0
        {
1043
0
    rel->address += input_section->output_offset;
1044
0
    break;
1045
0
        }
1046
1047
9
      if (tos == 0)
1048
9
        {
1049
9
    r = bfd_reloc_notsupported;
1050
9
    break;
1051
9
        }
1052
1053
      /* The offset and size in bits for this reloc are encoded
1054
         into the addend field by alpha_adjust_reloc_in.  */
1055
0
      unsigned int offset = (rel->addend >> 8) & 0xff;
1056
0
      unsigned int size = rel->addend & 0xff;
1057
1058
0
      if (!write_bit_field (input_bfd, input_section,
1059
0
          data, rel->address,
1060
0
          offset, size, stack[--tos]))
1061
0
        r = bfd_reloc_outofrange;
1062
0
    }
1063
0
    break;
1064
1065
3
  case ALPHA_R_OP_PSUB:
1066
    /* Subtract a value from the top of the stack.  */
1067
3
    {
1068
3
      asymbol *symbol;
1069
3
      bfd_vma relocation;
1070
1071
3
      if (relocatable)
1072
0
        {
1073
0
    rel->address += input_section->output_offset;
1074
0
    break;
1075
0
        }
1076
1077
      /* Figure out the relocation of this symbol.  */
1078
3
      symbol = *rel->sym_ptr_ptr;
1079
1080
3
      if (bfd_is_und_section (symbol->section))
1081
0
        r = bfd_reloc_undefined;
1082
1083
3
      if (bfd_is_com_section (symbol->section))
1084
0
        relocation = 0;
1085
3
      else
1086
3
        relocation = symbol->value;
1087
3
      relocation += symbol->section->output_section->vma;
1088
3
      relocation += symbol->section->output_offset;
1089
3
      relocation += rel->addend;
1090
1091
3
      if (tos == 0)
1092
0
        {
1093
0
    r = bfd_reloc_notsupported;
1094
0
    break;
1095
0
        }
1096
1097
3
      stack[tos - 1] -= relocation;
1098
3
    }
1099
0
    break;
1100
1101
1
  case ALPHA_R_OP_PRSHIFT:
1102
    /* Shift the value on the top of the stack.  */
1103
1
    {
1104
1
      asymbol *symbol;
1105
1
      bfd_vma relocation;
1106
1107
1
      if (relocatable)
1108
0
        {
1109
0
    rel->address += input_section->output_offset;
1110
0
    break;
1111
0
        }
1112
1113
      /* Figure out the relocation of this symbol.  */
1114
1
      symbol = *rel->sym_ptr_ptr;
1115
1116
1
      if (bfd_is_und_section (symbol->section))
1117
0
        r = bfd_reloc_undefined;
1118
1119
1
      if (bfd_is_com_section (symbol->section))
1120
0
        relocation = 0;
1121
1
      else
1122
1
        relocation = symbol->value;
1123
1
      relocation += symbol->section->output_section->vma;
1124
1
      relocation += symbol->section->output_offset;
1125
1
      relocation += rel->addend;
1126
1127
1
      if (tos == 0)
1128
1
        {
1129
1
    r = bfd_reloc_notsupported;
1130
1
    break;
1131
1
        }
1132
1133
0
      if (relocation >= 64)
1134
0
        stack[tos - 1] = 0;
1135
0
      else
1136
0
        stack[tos - 1] >>= relocation;
1137
0
    }
1138
0
    break;
1139
1140
1
  case ALPHA_R_GPVALUE:
1141
    /* I really don't know if this does the right thing.  */
1142
1
    gp = rel->addend;
1143
1
    gp_undefined = false;
1144
1
    break;
1145
1146
0
  default:
1147
0
    r = bfd_reloc_notsupported;
1148
0
    break;
1149
103
  }
1150
1151
103
      if (relocatable)
1152
0
  {
1153
0
    asection *os = input_section->output_section;
1154
1155
    /* A partial link, so keep the relocs.  */
1156
0
    os->orelocation[os->reloc_count] = rel;
1157
0
    os->reloc_count++;
1158
0
  }
1159
1160
103
      if (r != bfd_reloc_ok)
1161
13
  {
1162
13
    _bfd_link_reloc_status_error (abfd, link_info, input_section,
1163
13
          rel, err, r);
1164
13
    if (r == bfd_reloc_outofrange || r == bfd_reloc_notsupported)
1165
13
      goto error_return;
1166
13
  }
1167
103
    }
1168
1169
0
  if (tos != 0)
1170
0
    goto error_return;
1171
1172
0
 successful_return:
1173
0
  free (reloc_vector);
1174
0
  return data;
1175
1176
13
 error_return:
1177
13
  free (reloc_vector);
1178
13
  if (orig_data == NULL)
1179
0
    free (data);
1180
13
  return NULL;
1181
0
}
1182
1183
/* Get the howto structure for a generic reloc type.  */
1184
1185
static reloc_howto_type *
1186
alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1187
           bfd_reloc_code_real_type code)
1188
0
{
1189
0
  int alpha_type;
1190
1191
0
  switch (code)
1192
0
    {
1193
0
    case BFD_RELOC_32:
1194
0
      alpha_type = ALPHA_R_REFLONG;
1195
0
      break;
1196
0
    case BFD_RELOC_64:
1197
0
    case BFD_RELOC_CTOR:
1198
0
      alpha_type = ALPHA_R_REFQUAD;
1199
0
      break;
1200
0
    case BFD_RELOC_GPREL32:
1201
0
      alpha_type = ALPHA_R_GPREL32;
1202
0
      break;
1203
0
    case BFD_RELOC_ALPHA_LITERAL:
1204
0
      alpha_type = ALPHA_R_LITERAL;
1205
0
      break;
1206
0
    case BFD_RELOC_ALPHA_LITUSE:
1207
0
      alpha_type = ALPHA_R_LITUSE;
1208
0
      break;
1209
0
    case BFD_RELOC_ALPHA_GPDISP_HI16:
1210
0
      alpha_type = ALPHA_R_GPDISP;
1211
0
      break;
1212
0
    case BFD_RELOC_ALPHA_GPDISP_LO16:
1213
0
      alpha_type = ALPHA_R_IGNORE;
1214
0
      break;
1215
0
    case BFD_RELOC_23_PCREL_S2:
1216
0
      alpha_type = ALPHA_R_BRADDR;
1217
0
      break;
1218
0
    case BFD_RELOC_ALPHA_HINT:
1219
0
      alpha_type = ALPHA_R_HINT;
1220
0
      break;
1221
0
    case BFD_RELOC_16_PCREL:
1222
0
      alpha_type = ALPHA_R_SREL16;
1223
0
      break;
1224
0
    case BFD_RELOC_32_PCREL:
1225
0
      alpha_type = ALPHA_R_SREL32;
1226
0
      break;
1227
0
    case BFD_RELOC_64_PCREL:
1228
0
      alpha_type = ALPHA_R_SREL64;
1229
0
      break;
1230
0
    default:
1231
0
      return NULL;
1232
0
    }
1233
1234
0
  return &alpha_howto_table[alpha_type];
1235
0
}
1236
1237
static reloc_howto_type *
1238
alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1239
           const char *r_name)
1240
0
{
1241
0
  unsigned int i;
1242
1243
0
  for (i = 0;
1244
0
       i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
1245
0
       i++)
1246
0
    if (alpha_howto_table[i].name != NULL
1247
0
  && strcasecmp (alpha_howto_table[i].name, r_name) == 0)
1248
0
      return &alpha_howto_table[i];
1249
1250
0
  return NULL;
1251
0
}
1252

1253
/* A helper routine for alpha_relocate_section which converts an
1254
   external reloc when generating relocatable output.  Returns the
1255
   relocation amount.  */
1256
1257
static bfd_vma
1258
alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED,
1259
            struct bfd_link_info *info,
1260
            bfd *input_bfd,
1261
            struct external_reloc *ext_rel,
1262
            struct ecoff_link_hash_entry *h)
1263
0
{
1264
0
  unsigned long r_symndx;
1265
0
  bfd_vma relocation;
1266
1267
0
  BFD_ASSERT (bfd_link_relocatable (info));
1268
1269
0
  if (h->root.type == bfd_link_hash_defined
1270
0
      || h->root.type == bfd_link_hash_defweak)
1271
0
    {
1272
0
      asection *hsec;
1273
0
      const char *name;
1274
1275
      /* This symbol is defined in the output.  Convert the reloc from
1276
   being against the symbol to being against the section.  */
1277
1278
      /* Clear the r_extern bit.  */
1279
0
      ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE;
1280
1281
      /* Compute a new r_symndx value.  */
1282
0
      hsec = h->root.u.def.section;
1283
0
      name = bfd_section_name (hsec->output_section);
1284
1285
0
      r_symndx = -1ul;
1286
0
      switch (name[1])
1287
0
  {
1288
0
  case 'A':
1289
0
    if (strcmp (name, "*ABS*") == 0)
1290
0
      r_symndx = RELOC_SECTION_ABS;
1291
0
    break;
1292
0
  case 'b':
1293
0
    if (strcmp (name, ".bss") == 0)
1294
0
      r_symndx = RELOC_SECTION_BSS;
1295
0
    break;
1296
0
  case 'd':
1297
0
    if (strcmp (name, ".data") == 0)
1298
0
      r_symndx = RELOC_SECTION_DATA;
1299
0
    break;
1300
0
  case 'f':
1301
0
    if (strcmp (name, ".fini") == 0)
1302
0
      r_symndx = RELOC_SECTION_FINI;
1303
0
    break;
1304
0
  case 'i':
1305
0
    if (strcmp (name, ".init") == 0)
1306
0
      r_symndx = RELOC_SECTION_INIT;
1307
0
    break;
1308
0
  case 'l':
1309
0
    if (strcmp (name, ".lita") == 0)
1310
0
      r_symndx = RELOC_SECTION_LITA;
1311
0
    else if (strcmp (name, ".lit8") == 0)
1312
0
      r_symndx = RELOC_SECTION_LIT8;
1313
0
    else if (strcmp (name, ".lit4") == 0)
1314
0
      r_symndx = RELOC_SECTION_LIT4;
1315
0
    break;
1316
0
  case 'p':
1317
0
    if (strcmp (name, ".pdata") == 0)
1318
0
      r_symndx = RELOC_SECTION_PDATA;
1319
0
    break;
1320
0
  case 'r':
1321
0
    if (strcmp (name, ".rdata") == 0)
1322
0
      r_symndx = RELOC_SECTION_RDATA;
1323
0
    else if (strcmp (name, ".rconst") == 0)
1324
0
      r_symndx = RELOC_SECTION_RCONST;
1325
0
    break;
1326
0
  case 's':
1327
0
    if (strcmp (name, ".sdata") == 0)
1328
0
      r_symndx = RELOC_SECTION_SDATA;
1329
0
    else if (strcmp (name, ".sbss") == 0)
1330
0
      r_symndx = RELOC_SECTION_SBSS;
1331
0
    break;
1332
0
  case 't':
1333
0
    if (strcmp (name, ".text") == 0)
1334
0
      r_symndx = RELOC_SECTION_TEXT;
1335
0
    break;
1336
0
  case 'x':
1337
0
    if (strcmp (name, ".xdata") == 0)
1338
0
      r_symndx = RELOC_SECTION_XDATA;
1339
0
    break;
1340
0
  }
1341
1342
0
      if (r_symndx == -1ul)
1343
0
  abort ();
1344
1345
      /* Add the section VMA and the symbol value.  */
1346
0
      relocation = (h->root.u.def.value
1347
0
        + hsec->output_section->vma
1348
0
        + hsec->output_offset);
1349
0
    }
1350
0
  else
1351
0
    {
1352
      /* Change the symndx value to the right one for
1353
   the output BFD.  */
1354
0
      r_symndx = h->indx;
1355
0
      if (r_symndx == -1ul)
1356
0
  {
1357
    /* Caller must give an error.  */
1358
0
    r_symndx = 0;
1359
0
  }
1360
0
      relocation = 0;
1361
0
    }
1362
1363
  /* Write out the new r_symndx value.  */
1364
0
  H_PUT_32 (input_bfd, r_symndx, ext_rel->r_symndx);
1365
1366
0
  return relocation;
1367
0
}
1368
1369
/* Relocate a section while linking an Alpha ECOFF file.  This is
1370
   quite similar to get_relocated_section_contents.  Perhaps they
1371
   could be combined somehow.  */
1372
1373
static bool
1374
alpha_relocate_section (bfd *output_bfd,
1375
      struct bfd_link_info *info,
1376
      bfd *input_bfd,
1377
      asection *input_section,
1378
      bfd_byte *contents,
1379
      void *external_relocs)
1380
0
{
1381
0
  asection **symndx_to_section, *lita_sec;
1382
0
  struct ecoff_link_hash_entry **sym_hashes;
1383
0
  bfd_vma gp;
1384
0
  bool gp_undefined;
1385
0
  bfd_vma stack[RELOC_STACKSIZE];
1386
0
  int tos = 0;
1387
0
  struct external_reloc *ext_rel;
1388
0
  struct external_reloc *ext_rel_end;
1389
0
  bfd_size_type amt;
1390
0
  bool ret = true;
1391
1392
  /* We keep a table mapping the symndx found in an internal reloc to
1393
     the appropriate section.  This is faster than looking up the
1394
     section by name each time.  */
1395
0
  symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
1396
0
  if (symndx_to_section == NULL)
1397
0
    {
1398
0
      amt = NUM_RELOC_SECTIONS * sizeof (asection *);
1399
0
      symndx_to_section = bfd_alloc (input_bfd, amt);
1400
0
      if (!symndx_to_section)
1401
0
  return false;
1402
1403
0
      symndx_to_section[RELOC_SECTION_NONE] = NULL;
1404
0
      symndx_to_section[RELOC_SECTION_TEXT] =
1405
0
  bfd_get_section_by_name (input_bfd, ".text");
1406
0
      symndx_to_section[RELOC_SECTION_RDATA] =
1407
0
  bfd_get_section_by_name (input_bfd, ".rdata");
1408
0
      symndx_to_section[RELOC_SECTION_DATA] =
1409
0
  bfd_get_section_by_name (input_bfd, ".data");
1410
0
      symndx_to_section[RELOC_SECTION_SDATA] =
1411
0
  bfd_get_section_by_name (input_bfd, ".sdata");
1412
0
      symndx_to_section[RELOC_SECTION_SBSS] =
1413
0
  bfd_get_section_by_name (input_bfd, ".sbss");
1414
0
      symndx_to_section[RELOC_SECTION_BSS] =
1415
0
  bfd_get_section_by_name (input_bfd, ".bss");
1416
0
      symndx_to_section[RELOC_SECTION_INIT] =
1417
0
  bfd_get_section_by_name (input_bfd, ".init");
1418
0
      symndx_to_section[RELOC_SECTION_LIT8] =
1419
0
  bfd_get_section_by_name (input_bfd, ".lit8");
1420
0
      symndx_to_section[RELOC_SECTION_LIT4] =
1421
0
  bfd_get_section_by_name (input_bfd, ".lit4");
1422
0
      symndx_to_section[RELOC_SECTION_XDATA] =
1423
0
  bfd_get_section_by_name (input_bfd, ".xdata");
1424
0
      symndx_to_section[RELOC_SECTION_PDATA] =
1425
0
  bfd_get_section_by_name (input_bfd, ".pdata");
1426
0
      symndx_to_section[RELOC_SECTION_FINI] =
1427
0
  bfd_get_section_by_name (input_bfd, ".fini");
1428
0
      symndx_to_section[RELOC_SECTION_LITA] =
1429
0
  bfd_get_section_by_name (input_bfd, ".lita");
1430
0
      symndx_to_section[RELOC_SECTION_ABS] = bfd_abs_section_ptr;
1431
0
      symndx_to_section[RELOC_SECTION_RCONST] =
1432
0
  bfd_get_section_by_name (input_bfd, ".rconst");
1433
1434
0
      ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
1435
0
    }
1436
1437
0
  sym_hashes = ecoff_data (input_bfd)->sym_hashes;
1438
1439
  /* On the Alpha, the .lita section must be addressable by the global
1440
     pointer.  To support large programs, we need to allow multiple
1441
     global pointers.  This works as long as each input .lita section
1442
     is <64KB big.  This implies that when producing relocatable
1443
     output, the .lita section is limited to 64KB. .  */
1444
1445
0
  lita_sec = symndx_to_section[RELOC_SECTION_LITA];
1446
0
  gp = _bfd_get_gp_value (output_bfd);
1447
0
  if (! bfd_link_relocatable (info) && lita_sec != NULL)
1448
0
    {
1449
0
      struct ecoff_section_tdata *lita_sec_data;
1450
1451
      /* Make sure we have a section data structure to which we can
1452
   hang on to the gp value we pick for the section.  */
1453
0
      lita_sec_data = ecoff_section_data (lita_sec);
1454
0
      if (lita_sec_data == NULL)
1455
0
  {
1456
0
    lita_sec_data = bfd_zalloc (input_bfd, sizeof (*lita_sec_data));
1457
0
    lita_sec->used_by_bfd = lita_sec_data;
1458
0
  }
1459
1460
0
      if (lita_sec_data->gp != 0)
1461
0
  {
1462
    /* If we already assigned a gp to this section, we better
1463
       stick with that value.  */
1464
0
    gp = lita_sec_data->gp;
1465
0
  }
1466
0
      else
1467
0
  {
1468
0
    bfd_vma lita_vma;
1469
0
    bfd_size_type lita_size;
1470
1471
0
    lita_vma = lita_sec->output_offset + lita_sec->output_section->vma;
1472
0
    lita_size = lita_sec->size;
1473
1474
0
    if (gp == 0
1475
0
        || lita_vma < gp - 0x8000
1476
0
        || lita_vma + lita_size >= gp + 0x8000)
1477
0
      {
1478
        /* Either gp hasn't been set at all or the current gp
1479
     cannot address this .lita section.  In both cases we
1480
     reset the gp to point into the "middle" of the
1481
     current input .lita section.  */
1482
0
        if (gp && !ecoff_data (output_bfd)->issued_multiple_gp_warning)
1483
0
    {
1484
0
      (*info->callbacks->warning) (info,
1485
0
                 _("using multiple gp values"),
1486
0
                 NULL, output_bfd, NULL, 0);
1487
0
      ecoff_data (output_bfd)->issued_multiple_gp_warning = true;
1488
0
    }
1489
0
        if (lita_vma < gp - 0x8000)
1490
0
    gp = lita_vma + lita_size - 0x8000;
1491
0
        else
1492
0
    gp = lita_vma + 0x8000;
1493
1494
0
      }
1495
1496
0
    lita_sec_data->gp = gp;
1497
0
  }
1498
1499
0
      _bfd_set_gp_value (output_bfd, gp);
1500
0
    }
1501
1502
0
  gp_undefined = (gp == 0);
1503
1504
0
  BFD_ASSERT (bfd_header_little_endian (output_bfd));
1505
0
  BFD_ASSERT (bfd_header_little_endian (input_bfd));
1506
1507
0
  ext_rel = external_relocs;
1508
0
  ext_rel_end = ext_rel + input_section->reloc_count;
1509
0
  for (; ext_rel < ext_rel_end; ext_rel++)
1510
0
    {
1511
0
      bfd_vma r_vaddr;
1512
0
      unsigned long r_symndx;
1513
0
      int r_type;
1514
0
      int r_extern;
1515
0
      int r_offset;
1516
0
      int r_size;
1517
0
      bool relocatep;
1518
0
      bool adjust_addrp;
1519
0
      bool gp_usedp;
1520
0
      bfd_vma addend;
1521
0
      bfd_reloc_status_type r;
1522
1523
0
      r_vaddr = H_GET_64 (input_bfd, ext_rel->r_vaddr);
1524
0
      r_symndx = H_GET_32 (input_bfd, ext_rel->r_symndx);
1525
1526
0
      r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
1527
0
    >> RELOC_BITS0_TYPE_SH_LITTLE);
1528
0
      r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
1529
0
      r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
1530
0
      >> RELOC_BITS1_OFFSET_SH_LITTLE);
1531
      /* Ignored the reserved bits.  */
1532
0
      r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
1533
0
    >> RELOC_BITS3_SIZE_SH_LITTLE);
1534
1535
0
      relocatep = false;
1536
0
      adjust_addrp = true;
1537
0
      gp_usedp = false;
1538
0
      addend = 0;
1539
0
      r = bfd_reloc_ok;
1540
1541
0
      switch (r_type)
1542
0
  {
1543
0
  default:
1544
0
    r = bfd_reloc_notsupported;
1545
0
    break;
1546
1547
0
  case ALPHA_R_IGNORE:
1548
    /* This reloc appears after a GPDISP reloc.  On earlier
1549
       versions of OSF/1, It marked the position of the second
1550
       instruction to be altered by the GPDISP reloc, but it is
1551
       not otherwise used for anything.  For some reason, the
1552
       address of the relocation does not appear to include the
1553
       section VMA, unlike the other relocation types.  */
1554
0
    if (bfd_link_relocatable (info))
1555
0
      H_PUT_64 (input_bfd, input_section->output_offset + r_vaddr,
1556
0
          ext_rel->r_vaddr);
1557
0
    adjust_addrp = false;
1558
0
    break;
1559
1560
0
  case ALPHA_R_REFLONG:
1561
0
  case ALPHA_R_REFQUAD:
1562
0
  case ALPHA_R_HINT:
1563
0
    relocatep = true;
1564
0
    break;
1565
1566
0
  case ALPHA_R_BRADDR:
1567
0
  case ALPHA_R_SREL16:
1568
0
  case ALPHA_R_SREL32:
1569
0
  case ALPHA_R_SREL64:
1570
0
    if (r_extern)
1571
0
      addend += - (r_vaddr + 4);
1572
0
    relocatep = true;
1573
0
    break;
1574
1575
0
  case ALPHA_R_GPREL32:
1576
    /* This relocation is used in a switch table.  It is a 32
1577
       bit offset from the current GP value.  We must adjust it
1578
       by the different between the original GP value and the
1579
       current GP value.  */
1580
0
    relocatep = true;
1581
0
    addend = ecoff_data (input_bfd)->gp - gp;
1582
0
    gp_usedp = true;
1583
0
    break;
1584
1585
0
  case ALPHA_R_LITERAL:
1586
    /* This is a reference to a literal value, generally
1587
       (always?) in the .lita section.  This is a 16 bit GP
1588
       relative relocation.  Sometimes the subsequent reloc is a
1589
       LITUSE reloc, which indicates how this reloc is used.
1590
       This sometimes permits rewriting the two instructions
1591
       referred to by the LITERAL and the LITUSE into different
1592
       instructions which do not refer to .lita.  This can save
1593
       a memory reference, and permits removing a value from
1594
       .lita thus saving GP relative space.
1595
1596
       We do not these optimizations.  To do them we would need
1597
       to arrange to link the .lita section first, so that by
1598
       the time we got here we would know the final values to
1599
       use.  This would not be particularly difficult, but it is
1600
       not currently implemented.  */
1601
1602
0
    relocatep = true;
1603
0
    addend = ecoff_data (input_bfd)->gp - gp;
1604
0
    gp_usedp = true;
1605
0
    break;
1606
1607
0
  case ALPHA_R_LITUSE:
1608
    /* See ALPHA_R_LITERAL above for the uses of this reloc.  It
1609
       does not cause anything to happen, itself.  */
1610
0
    break;
1611
1612
0
  case ALPHA_R_GPDISP:
1613
    /* This marks the ldah of an ldah/lda pair which loads the
1614
       gp register with the difference of the gp value and the
1615
       current location.  The second of the pair is r_symndx
1616
       bytes ahead.  It used to be marked with an ALPHA_R_IGNORE
1617
       reloc, but OSF/1 3.2 no longer does that.  */
1618
0
    if (r_vaddr >= input_section->vma
1619
0
        && r_vaddr - input_section->vma < input_section->size
1620
0
        && input_section->size - (r_vaddr - input_section->vma) > r_symndx
1621
0
        && (input_section->size - (r_vaddr - input_section->vma)
1622
0
      - r_symndx >= 4))
1623
0
      {
1624
        /* Get the two instructions.  */
1625
0
        bfd_byte *p = contents + r_vaddr - input_section->vma;
1626
0
        bfd_vma insn1 = bfd_get_32 (input_bfd, p);
1627
0
        bfd_vma insn2 = bfd_get_32 (input_bfd, p + r_symndx);
1628
1629
0
        BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
1630
0
        BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
1631
1632
        /* Get the existing addend.  We must account for the sign
1633
     extension done by lda and ldah.  */
1634
0
        addend = (((((insn1 & 0xffff) ^ 0x8000) - 0x8000) << 16)
1635
0
      + (((insn2 & 0xffff) ^ 0x8000) - 0x8000));
1636
1637
        /* The existing addend includes the difference between the
1638
     gp of the input BFD and the address in the input BFD.
1639
     We want to change this to the difference between the
1640
     final GP and the final address.  */
1641
0
        addend -= ecoff_data (input_bfd)->gp - input_section->vma;
1642
0
        addend += gp - (input_section->output_section->vma
1643
0
            + input_section->output_offset);
1644
1645
        /* Change the instructions, accounting for the sign
1646
     extension, and write them out.  */
1647
0
        insn1 = (insn1 & ~0xffff) | (((addend + 0x8000) >> 16) & 0xffff);
1648
0
        insn2 = (insn2 & ~0xffff) | (addend & 0xffff);
1649
1650
0
        bfd_put_32 (input_bfd, insn1, p);
1651
0
        bfd_put_32 (input_bfd, insn2, p + r_symndx);
1652
1653
0
        gp_usedp = true;
1654
0
      }
1655
0
    else
1656
0
      r = bfd_reloc_outofrange;
1657
0
    break;
1658
1659
0
  case ALPHA_R_OP_PUSH:
1660
0
  case ALPHA_R_OP_PSUB:
1661
0
  case ALPHA_R_OP_PRSHIFT:
1662
    /* Manipulate values on the reloc evaluation stack.  The
1663
       r_vaddr field is not an address in input_section, it is
1664
       the current value (including any addend) of the object
1665
       being used.  */
1666
0
    if (! r_extern)
1667
0
      {
1668
0
        asection *s;
1669
1670
0
        s = symndx_to_section[r_symndx];
1671
0
        if (s == NULL)
1672
0
    {
1673
0
      r = bfd_reloc_notsupported;
1674
0
      break;
1675
0
    }
1676
0
        addend = s->output_section->vma + s->output_offset - s->vma;
1677
0
      }
1678
0
    else
1679
0
      {
1680
0
        struct ecoff_link_hash_entry *h;
1681
1682
0
        h = sym_hashes[r_symndx];
1683
0
        if (h == NULL)
1684
0
    {
1685
0
      r = bfd_reloc_notsupported;
1686
0
      break;
1687
0
    }
1688
1689
0
        if (! bfd_link_relocatable (info))
1690
0
    {
1691
0
      if (h->root.type == bfd_link_hash_defined
1692
0
          || h->root.type == bfd_link_hash_defweak)
1693
0
        addend = (h->root.u.def.value
1694
0
            + h->root.u.def.section->output_section->vma
1695
0
            + h->root.u.def.section->output_offset);
1696
0
      else
1697
0
        {
1698
          /* Note that we pass the address as 0, since we
1699
       do not have a meaningful number for the
1700
       location within the section that is being
1701
       relocated.  */
1702
0
          (*info->callbacks->undefined_symbol)
1703
0
      (info, h->root.root.string, input_bfd,
1704
0
       input_section, 0, true);
1705
0
          addend = 0;
1706
0
        }
1707
0
    }
1708
0
        else
1709
0
    {
1710
0
      if (h->root.type != bfd_link_hash_defined
1711
0
          && h->root.type != bfd_link_hash_defweak
1712
0
          && h->indx == -1)
1713
0
        {
1714
          /* This symbol is not being written out.  Pass
1715
       the address as 0, as with undefined_symbol,
1716
       above.  */
1717
0
          (*info->callbacks->unattached_reloc)
1718
0
      (info, h->root.root.string,
1719
0
       input_bfd, input_section, 0);
1720
0
        }
1721
1722
0
      addend = alpha_convert_external_reloc (output_bfd, info,
1723
0
               input_bfd,
1724
0
               ext_rel, h);
1725
0
    }
1726
0
      }
1727
1728
0
    addend += r_vaddr;
1729
1730
0
    if (bfd_link_relocatable (info))
1731
0
      {
1732
        /* Adjust r_vaddr by the addend.  */
1733
0
        H_PUT_64 (input_bfd, addend, ext_rel->r_vaddr);
1734
0
      }
1735
0
    else
1736
0
      {
1737
0
        switch (r_type)
1738
0
    {
1739
0
    case ALPHA_R_OP_PUSH:
1740
0
      if (tos >= RELOC_STACKSIZE)
1741
0
        {
1742
0
          r = bfd_reloc_notsupported;
1743
0
          break;
1744
0
        }
1745
0
      stack[tos++] = addend;
1746
0
      break;
1747
1748
0
    case ALPHA_R_OP_PSUB:
1749
0
      if (tos == 0)
1750
0
        {
1751
0
          r = bfd_reloc_notsupported;
1752
0
          break;
1753
0
        }
1754
0
      stack[tos - 1] -= addend;
1755
0
      break;
1756
1757
0
    case ALPHA_R_OP_PRSHIFT:
1758
0
      if (tos == 0)
1759
0
        {
1760
0
          r = bfd_reloc_notsupported;
1761
0
          break;
1762
0
        }
1763
0
      if (addend >= 64)
1764
0
        stack[tos - 1] = 0;
1765
0
      else
1766
0
        stack[tos - 1] >>= addend;
1767
0
      break;
1768
0
    }
1769
0
      }
1770
1771
0
    adjust_addrp = false;
1772
0
    break;
1773
1774
0
  case ALPHA_R_OP_STORE:
1775
    /* Store a value from the reloc stack into a bitfield.  If
1776
       we are generating relocatable output, all we do is
1777
       adjust the address of the reloc.  */
1778
0
    if (! bfd_link_relocatable (info))
1779
0
      {
1780
0
        if (tos == 0)
1781
0
    r = bfd_reloc_notsupported;
1782
0
        else if (!write_bit_field (input_bfd, input_section,
1783
0
           contents,
1784
0
           r_vaddr - input_section->vma,
1785
0
           r_offset, r_size, stack[--tos]))
1786
0
    r = bfd_reloc_outofrange;
1787
0
      }
1788
0
    break;
1789
1790
0
  case ALPHA_R_GPVALUE:
1791
    /* I really don't know if this does the right thing.  */
1792
0
    gp = ecoff_data (input_bfd)->gp + r_symndx;
1793
0
    gp_undefined = false;
1794
0
    break;
1795
0
  }
1796
1797
0
      if (relocatep && r == bfd_reloc_ok)
1798
0
  {
1799
0
    reloc_howto_type *howto;
1800
0
    struct ecoff_link_hash_entry *h = NULL;
1801
0
    asection *s = NULL;
1802
0
    bfd_vma relocation;
1803
1804
    /* Perform a relocation.  */
1805
1806
0
    howto = &alpha_howto_table[r_type];
1807
1808
0
    if (r_extern)
1809
0
      {
1810
0
        h = sym_hashes[r_symndx];
1811
        /* If h is NULL, that means that there is a reloc
1812
     against an external symbol which we thought was just
1813
     a debugging symbol.  This should not happen.  */
1814
0
        if (h == NULL)
1815
0
    r = bfd_reloc_notsupported;
1816
0
      }
1817
0
    else
1818
0
      {
1819
0
        if (r_symndx >= NUM_RELOC_SECTIONS)
1820
0
    s = NULL;
1821
0
        else
1822
0
    s = symndx_to_section[r_symndx];
1823
1824
0
        if (s == NULL)
1825
0
    r = bfd_reloc_notsupported;
1826
1827
0
      }
1828
1829
0
    if (r != bfd_reloc_ok)
1830
0
      ;
1831
0
    else if (bfd_link_relocatable (info))
1832
0
      {
1833
        /* We are generating relocatable output, and must
1834
     convert the existing reloc.  */
1835
0
        if (r_extern)
1836
0
    {
1837
0
      if (h->root.type != bfd_link_hash_defined
1838
0
          && h->root.type != bfd_link_hash_defweak
1839
0
          && h->indx == -1)
1840
0
        {
1841
          /* This symbol is not being written out.  */
1842
0
          (*info->callbacks->unattached_reloc)
1843
0
      (info, h->root.root.string, input_bfd,
1844
0
       input_section, r_vaddr - input_section->vma);
1845
0
        }
1846
1847
0
      relocation = alpha_convert_external_reloc (output_bfd,
1848
0
                   info,
1849
0
                   input_bfd,
1850
0
                   ext_rel,
1851
0
                   h);
1852
0
    }
1853
0
        else
1854
0
    {
1855
      /* This is a relocation against a section.  Adjust
1856
         the value by the amount the section moved.  */
1857
0
      relocation = (s->output_section->vma
1858
0
        + s->output_offset
1859
0
        - s->vma);
1860
0
    }
1861
1862
        /* If this is PC relative, the existing object file
1863
     appears to already have the reloc worked out.  We
1864
     must subtract out the old value and add in the new
1865
     one.  */
1866
0
        if (howto->pc_relative)
1867
0
    relocation -= (input_section->output_section->vma
1868
0
             + input_section->output_offset
1869
0
             - input_section->vma);
1870
1871
        /* Put in any addend.  */
1872
0
        relocation += addend;
1873
1874
        /* Adjust the contents.  */
1875
0
        r = _bfd_relocate_contents (howto, input_bfd, relocation,
1876
0
            (contents
1877
0
             + r_vaddr
1878
0
             - input_section->vma));
1879
0
      }
1880
0
    else
1881
0
      {
1882
        /* We are producing a final executable.  */
1883
0
        if (r_extern)
1884
0
    {
1885
      /* This is a reloc against a symbol.  */
1886
0
      if (h->root.type == bfd_link_hash_defined
1887
0
          || h->root.type == bfd_link_hash_defweak)
1888
0
        {
1889
0
          asection *hsec;
1890
1891
0
          hsec = h->root.u.def.section;
1892
0
          relocation = (h->root.u.def.value
1893
0
            + hsec->output_section->vma
1894
0
            + hsec->output_offset);
1895
0
        }
1896
0
      else
1897
0
        r = bfd_reloc_undefined;
1898
0
    }
1899
0
        else
1900
0
    {
1901
      /* This is a reloc against a section.  */
1902
0
      relocation = (s->output_section->vma
1903
0
        + s->output_offset
1904
0
        - s->vma);
1905
1906
      /* Adjust a PC relative relocation by removing the
1907
         reference to the original source section.  */
1908
0
      if (howto->pc_relative)
1909
0
        relocation += input_section->vma;
1910
0
    }
1911
1912
0
        if (r == bfd_reloc_ok)
1913
0
    r = _bfd_final_link_relocate (howto,
1914
0
                input_bfd,
1915
0
                input_section,
1916
0
                contents,
1917
0
                r_vaddr - input_section->vma,
1918
0
                relocation,
1919
0
                addend);
1920
0
      }
1921
0
  }
1922
1923
0
      if (bfd_link_relocatable (info) && adjust_addrp)
1924
0
  {
1925
    /* Change the address of the relocation.  */
1926
0
    H_PUT_64 (input_bfd,
1927
0
        (input_section->output_section->vma
1928
0
         + input_section->output_offset
1929
0
         - input_section->vma
1930
0
         + r_vaddr),
1931
0
        ext_rel->r_vaddr);
1932
0
  }
1933
1934
0
      if (gp_usedp && gp_undefined)
1935
0
  {
1936
0
    r = bfd_reloc_dangerous;
1937
    /* Only give the error once per link.  */
1938
0
    gp = 4;
1939
0
    _bfd_set_gp_value (output_bfd, gp);
1940
0
    gp_undefined = false;
1941
0
  }
1942
1943
0
      if (r != bfd_reloc_ok)
1944
0
  {
1945
0
    switch (r)
1946
0
      {
1947
0
      case bfd_reloc_overflow:
1948
0
        {
1949
0
    const char *name;
1950
1951
0
    if (r_extern)
1952
0
      name = sym_hashes[r_symndx]->root.root.string;
1953
0
    else
1954
0
      name = bfd_section_name (symndx_to_section[r_symndx]);
1955
0
    (*info->callbacks->reloc_overflow)
1956
0
      (info, NULL, name, alpha_howto_table[r_type].name,
1957
0
       0, input_bfd, input_section, r_vaddr - input_section->vma);
1958
0
        }
1959
0
        break;
1960
0
      case bfd_reloc_outofrange:
1961
0
        (*info->callbacks->einfo)
1962
    /* xgettext:c-format */
1963
0
    (_("%X%P: %pB(%pA): relocation out of range\n"),
1964
0
     input_bfd, input_section);
1965
0
        break;
1966
0
      case bfd_reloc_undefined:
1967
0
        (*info->callbacks->undefined_symbol)
1968
0
    (info, sym_hashes[r_symndx]->root.root.string,
1969
0
     input_bfd, input_section,
1970
0
     r_vaddr - input_section->vma, true);
1971
0
        break;
1972
0
      case bfd_reloc_notsupported:
1973
0
        (*info->callbacks->einfo)
1974
    /* xgettext:c-format */
1975
0
    (_("%X%P: %pB(%pA): relocation is not supported\n"),
1976
0
     input_bfd, input_section);
1977
0
        break;
1978
0
      case bfd_reloc_dangerous:
1979
0
        (*info->callbacks->reloc_dangerous)
1980
0
    (info, _("GP relative relocation used when GP not defined"),
1981
0
     input_bfd, input_section, r_vaddr - input_section->vma);
1982
0
        break;
1983
0
      default:
1984
0
        abort ();
1985
0
      }
1986
0
    ret = false;
1987
0
  }
1988
0
    }
1989
1990
0
  if (tos != 0)
1991
0
    ret = false;
1992
1993
0
  return ret;
1994
0
}
1995

1996
/* Do final adjustments to the filehdr and the aouthdr.  This routine
1997
   sets the dynamic bits in the file header.  */
1998
1999
static bool
2000
alpha_adjust_headers (bfd *abfd,
2001
          struct internal_filehdr *fhdr,
2002
          struct internal_aouthdr *ahdr ATTRIBUTE_UNUSED)
2003
28
{
2004
28
  if ((abfd->flags & (DYNAMIC | EXEC_P)) == (DYNAMIC | EXEC_P))
2005
0
    fhdr->f_flags |= F_ALPHA_CALL_SHARED;
2006
28
  else if ((abfd->flags & DYNAMIC) != 0)
2007
0
    fhdr->f_flags |= F_ALPHA_SHARABLE;
2008
28
  return true;
2009
28
}
2010

2011
/* Archive handling.  In OSF/1 (or Digital Unix) v3.2, Digital
2012
   introduced archive packing, in which the elements in an archive are
2013
   optionally compressed using a simple dictionary scheme.  We know
2014
   how to read such archives, but we don't write them.  */
2015
2016
#define alpha_ecoff_slurp_armap _bfd_ecoff_slurp_armap
2017
#define alpha_ecoff_slurp_extended_name_table \
2018
  _bfd_ecoff_slurp_extended_name_table
2019
#define alpha_ecoff_construct_extended_name_table \
2020
  _bfd_ecoff_construct_extended_name_table
2021
#define alpha_ecoff_truncate_arname _bfd_ecoff_truncate_arname
2022
#define alpha_ecoff_write_armap _bfd_ecoff_write_armap
2023
#define alpha_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr
2024
#define alpha_ecoff_generic_stat_arch_elt _bfd_ecoff_generic_stat_arch_elt
2025
#define alpha_ecoff_update_armap_timestamp _bfd_ecoff_update_armap_timestamp
2026
2027
/* A compressed file uses this instead of ARFMAG.  */
2028
2029
170k
#define ARFZMAG "Z\012"
2030
2031
/* Read an archive header.  This is like the standard routine, but it
2032
   also accepts ARFZMAG.  */
2033
2034
static void *
2035
alpha_ecoff_read_ar_hdr (bfd *abfd)
2036
61.4k
{
2037
61.4k
  struct areltdata *ret;
2038
61.4k
  struct ar_hdr *h;
2039
2040
61.4k
  ret = _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG);
2041
61.4k
  if (ret == NULL)
2042
1.14k
    return NULL;
2043
2044
60.2k
  h = (struct ar_hdr *) ret->arch_header;
2045
60.2k
  if (strncmp (h->ar_fmag, ARFZMAG, 2) == 0)
2046
1.09k
    {
2047
1.09k
      bfd_byte ab[8];
2048
2049
      /* This is a compressed file.  We must set the size correctly.
2050
   The size is the eight bytes after the dummy file header.  */
2051
1.09k
      if (bfd_seek (abfd, FILHSZ, SEEK_CUR) != 0
2052
1.09k
    || bfd_read (ab, 8, abfd) != 8
2053
1.07k
    || bfd_seek (abfd, -(FILHSZ + 8), SEEK_CUR) != 0)
2054
25
  {
2055
25
    free (ret);
2056
25
    return NULL;
2057
25
  }
2058
2059
1.07k
      ret->parsed_size = H_GET_64 (abfd, ab);
2060
1.07k
    }
2061
2062
60.2k
  return ret;
2063
60.2k
}
2064
2065
/* Get an archive element at a specified file position.  This is where
2066
   we uncompress the archive element if necessary.  */
2067
2068
static bfd *
2069
alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos,
2070
        struct bfd_link_info *info)
2071
49.2k
{
2072
49.2k
  bfd *nbfd = NULL;
2073
49.2k
  struct areltdata *tdata;
2074
49.2k
  struct ar_hdr *hdr;
2075
49.2k
  bfd_byte ab[8];
2076
49.2k
  bfd_size_type size;
2077
49.2k
  bfd_byte *buf;
2078
49.2k
  struct bfd_in_memory *bim;
2079
49.2k
  ufile_ptr filesize;
2080
2081
49.2k
  buf = NULL;
2082
49.2k
  nbfd = _bfd_get_elt_at_filepos (archive, filepos, info);
2083
49.2k
  if (nbfd == NULL)
2084
794
    goto error_return;
2085
2086
48.4k
  if ((nbfd->flags & BFD_IN_MEMORY) != 0)
2087
0
    {
2088
      /* We have already expanded this BFD.  */
2089
0
      return nbfd;
2090
0
    }
2091
2092
48.4k
  tdata = nbfd->arelt_data;
2093
48.4k
  hdr = (struct ar_hdr *) tdata->arch_header;
2094
48.4k
  if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0)
2095
47.9k
    return nbfd;
2096
2097
  /* We must uncompress this element.  We do this by copying it into a
2098
     memory buffer, and making bfd_read and bfd_seek use that buffer.
2099
     This can use a lot of memory, but it's simpler than getting a
2100
     temporary file, making that work with the file descriptor caching
2101
     code, and making sure that it is deleted at all appropriate
2102
     times.  It can be changed if it ever becomes important.  */
2103
2104
  /* The compressed file starts with a dummy ECOFF file header.  */
2105
476
  if (bfd_seek (nbfd, FILHSZ, SEEK_SET) != 0)
2106
0
    goto error_return;
2107
2108
  /* The next eight bytes are the real file size.  */
2109
476
  if (bfd_read (ab, 8, nbfd) != 8)
2110
9
    goto error_return;
2111
467
  size = H_GET_64 (nbfd, ab);
2112
2113
  /* The decompression algorithm will at most expand by eight times.  */
2114
467
  filesize = bfd_get_file_size (archive);
2115
467
  if (filesize != 0 && size / 8 > filesize)
2116
297
    {
2117
297
      bfd_set_error (bfd_error_malformed_archive);
2118
297
      goto error_return;
2119
297
    }
2120
2121
170
  if (size != 0)
2122
170
    {
2123
170
      bfd_byte *p;
2124
170
      bfd_size_type left;
2125
170
      bfd_byte dict[4096];
2126
170
      unsigned int h;
2127
2128
170
      buf = bfd_malloc (size);
2129
170
      if (buf == NULL)
2130
0
  goto error_return;
2131
170
      p = buf;
2132
2133
170
      left = size;
2134
2135
      /* I don't know what the next eight bytes are for.  */
2136
170
      if (bfd_read (ab, 8, nbfd) != 8)
2137
12
  goto error_return;
2138
2139
      /* This is the uncompression algorithm.  It's a simple
2140
   dictionary based scheme in which each character is predicted
2141
   by a hash of the previous three characters.  A control byte
2142
   indicates whether the character is predicted or whether it
2143
   appears in the input stream; each control byte manages the
2144
   next eight bytes in the output stream.  */
2145
158
      memset (dict, 0, sizeof dict);
2146
158
      h = 0;
2147
158
      do
2148
21.3k
  {
2149
21.3k
    bfd_byte b;
2150
21.3k
    if (bfd_read (&b, 1, nbfd) != 1)
2151
45
      goto error_return;
2152
2153
191k
    for (unsigned int i = 0; i < 8; i++, b >>= 1)
2154
170k
      {
2155
170k
        bfd_byte n;
2156
2157
170k
        if ((b & 1) == 0)
2158
135k
    n = dict[h];
2159
34.5k
        else
2160
34.5k
    {
2161
34.5k
      if (bfd_read (&n, 1, nbfd) != 1)
2162
61
        goto error_return;
2163
34.4k
      dict[h] = n;
2164
34.4k
    }
2165
2166
170k
        *p++ = n;
2167
2168
170k
        --left;
2169
170k
        if (left == 0)
2170
52
    break;
2171
2172
170k
        h <<= 4;
2173
170k
        h ^= n;
2174
170k
        h &= sizeof dict - 1;
2175
170k
      }
2176
21.3k
  }
2177
21.2k
      while (left != 0);
2178
158
    }
2179
2180
  /* Now the uncompressed file contents are in buf.  */
2181
52
  bim = bfd_malloc (sizeof (*bim));
2182
52
  if (bim == NULL)
2183
0
    goto error_return;
2184
52
  bim->size = size;
2185
52
  bim->buffer = buf;
2186
2187
52
  nbfd->mtime_set = true;
2188
52
  nbfd->mtime = strtol (hdr->ar_date, NULL, 10);
2189
2190
52
  nbfd->flags |= BFD_IN_MEMORY;
2191
52
  nbfd->iostream = bim;
2192
52
  nbfd->iovec = &_bfd_memory_iovec;
2193
52
  nbfd->origin = 0;
2194
52
  nbfd->size = 0;
2195
52
  BFD_ASSERT (! nbfd->cacheable);
2196
2197
52
  return nbfd;
2198
2199
1.21k
 error_return:
2200
1.21k
  free (buf);
2201
1.21k
  if (nbfd != NULL)
2202
424
    bfd_close (nbfd);
2203
1.21k
  return NULL;
2204
52
}
2205
2206
/* Open the next archived file.  */
2207
2208
static bfd *
2209
alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
2210
49.2k
{
2211
49.2k
  ufile_ptr filestart;
2212
2213
49.2k
  BFD_ASSERT (!bfd_is_fake_archive (archive));
2214
2215
49.2k
  if (last_file == NULL)
2216
47.5k
    filestart = bfd_ardata (archive)->first_file.file_offset;
2217
1.73k
  else
2218
1.73k
    {
2219
1.73k
      struct areltdata *t;
2220
1.73k
      struct ar_hdr *h;
2221
1.73k
      bfd_size_type size;
2222
2223
      /* We can't use arelt_size here, because that uses parsed_size,
2224
   which is the uncompressed size.  We need the compressed size.  */
2225
1.73k
      t = (struct areltdata *) last_file->arelt_data;
2226
1.73k
      h = (struct ar_hdr *) t->arch_header;
2227
1.73k
      size = strtol (h->ar_size, NULL, 10);
2228
2229
      /* Pad to an even boundary...
2230
   Note that last_file->origin can be odd in the case of
2231
   BSD-4.4-style element with a long odd size.  */
2232
1.73k
      filestart = last_file->proxy_handle.file_offset + size;
2233
1.73k
      filestart += filestart % 2;
2234
1.73k
      if (filestart < last_file->proxy_handle.file_offset)
2235
32
  {
2236
    /* Prevent looping.  See PR19256.  */
2237
32
    bfd_set_error (bfd_error_malformed_archive);
2238
32
    return NULL;
2239
32
  }
2240
1.73k
    }
2241
2242
49.2k
  return alpha_ecoff_get_elt_at_filepos (archive, filestart, NULL);
2243
49.2k
}
2244
2245
/* Open the archive file given an index into the armap.  */
2246
2247
static bfd *
2248
alpha_ecoff_get_elt_at_index (bfd *abfd, symindex sym_index)
2249
0
{
2250
0
  carsym *entry;
2251
2252
0
  entry = bfd_ardata (abfd)->symdefs + sym_index;
2253
0
  if (bfd_ardata (abfd)->symdef_use_bfd)
2254
0
    return entry->u.abfd;
2255
0
  else
2256
0
    return alpha_ecoff_get_elt_at_filepos (abfd, entry->u.file_offset, NULL);
2257
0
}
2258
2259
static void
2260
alpha_ecoff_swap_coff_aux_in (bfd *abfd ATTRIBUTE_UNUSED,
2261
            void *ext1 ATTRIBUTE_UNUSED,
2262
            int type ATTRIBUTE_UNUSED,
2263
            int in_class ATTRIBUTE_UNUSED,
2264
            int indx ATTRIBUTE_UNUSED,
2265
            int numaux ATTRIBUTE_UNUSED,
2266
            void *in1 ATTRIBUTE_UNUSED)
2267
0
{
2268
0
}
2269
2270
static void
2271
alpha_ecoff_swap_coff_sym_in (bfd *abfd ATTRIBUTE_UNUSED,
2272
            void *ext1 ATTRIBUTE_UNUSED,
2273
            void *in1 ATTRIBUTE_UNUSED)
2274
0
{
2275
0
}
2276
2277
static void
2278
alpha_ecoff_swap_coff_lineno_in (bfd *abfd ATTRIBUTE_UNUSED,
2279
         void *ext1 ATTRIBUTE_UNUSED,
2280
         void *in1 ATTRIBUTE_UNUSED)
2281
0
{
2282
0
}
2283
2284
static unsigned int
2285
alpha_ecoff_swap_coff_aux_out (bfd *abfd ATTRIBUTE_UNUSED,
2286
             void *inp ATTRIBUTE_UNUSED,
2287
             int type ATTRIBUTE_UNUSED,
2288
             int in_class ATTRIBUTE_UNUSED,
2289
             int indx ATTRIBUTE_UNUSED,
2290
             int numaux ATTRIBUTE_UNUSED,
2291
             void *extp ATTRIBUTE_UNUSED)
2292
0
{
2293
0
  return 0;
2294
0
}
2295
2296
static unsigned int
2297
alpha_ecoff_swap_coff_sym_out (bfd *abfd ATTRIBUTE_UNUSED,
2298
             void *inp ATTRIBUTE_UNUSED,
2299
             void *extp ATTRIBUTE_UNUSED)
2300
0
{
2301
0
  return 0;
2302
0
}
2303
2304
static unsigned int
2305
alpha_ecoff_swap_coff_lineno_out (bfd *abfd ATTRIBUTE_UNUSED,
2306
          void *inp ATTRIBUTE_UNUSED,
2307
          void *extp ATTRIBUTE_UNUSED)
2308
0
{
2309
0
  return 0;
2310
0
}
2311
2312
static unsigned int
2313
alpha_ecoff_swap_coff_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
2314
         void *inp ATTRIBUTE_UNUSED,
2315
         void *extp ATTRIBUTE_UNUSED)
2316
0
{
2317
0
  return 0;
2318
0
}
2319

2320
/* This is the ECOFF backend structure.  The backend field of the
2321
   target vector points to this.  */
2322
2323
static const struct ecoff_backend_data alpha_ecoff_backend_data =
2324
{
2325
  /* COFF backend structure.  */
2326
  {
2327
    alpha_ecoff_swap_coff_aux_in, alpha_ecoff_swap_coff_sym_in,
2328
    alpha_ecoff_swap_coff_lineno_in, alpha_ecoff_swap_coff_aux_out,
2329
    alpha_ecoff_swap_coff_sym_out, alpha_ecoff_swap_coff_lineno_out,
2330
    alpha_ecoff_swap_coff_reloc_out,
2331
    alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
2332
    alpha_ecoff_swap_scnhdr_out,
2333
    FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, FILNMLEN, true,
2334
    ECOFF_NO_LONG_SECTION_NAMES, 4, false, 2, 32768,
2335
    alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
2336
    alpha_ecoff_swap_scnhdr_in, NULL,
2337
    alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
2338
    alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
2339
    _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
2340
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2341
    NULL, NULL, NULL,
2342
  },
2343
  /* Supported architecture.  */
2344
  bfd_arch_alpha,
2345
  /* Initial portion of armap string.  */
2346
  "________64",
2347
  /* The page boundary used to align sections in a demand-paged
2348
     executable file.  E.g., 0x1000.  */
2349
  0x2000,
2350
  /* TRUE if the .rdata section is part of the text segment, as on the
2351
     Alpha.  FALSE if .rdata is part of the data segment, as on the
2352
     MIPS.  */
2353
  true,
2354
  /* Bitsize of constructor entries.  */
2355
  64,
2356
  /* Reloc to use for constructor entries.  */
2357
  &alpha_howto_table[ALPHA_R_REFQUAD],
2358
  {
2359
    /* Symbol table magic number.  */
2360
    magicSym2,
2361
    /* Alignment of debugging information.  E.g., 4.  */
2362
    8,
2363
    /* Sizes of external symbolic information.  */
2364
    sizeof (struct hdr_ext),
2365
    sizeof (struct dnr_ext),
2366
    sizeof (struct pdr_ext),
2367
    sizeof (struct sym_ext),
2368
    sizeof (struct opt_ext),
2369
    sizeof (struct fdr_ext),
2370
    sizeof (struct rfd_ext),
2371
    sizeof (struct ext_ext),
2372
    /* Functions to swap in external symbolic data.  */
2373
    ecoff_swap_hdr_in,
2374
    ecoff_swap_dnr_in,
2375
    ecoff_swap_pdr_in,
2376
    ecoff_swap_sym_in,
2377
    ecoff_swap_opt_in,
2378
    ecoff_swap_fdr_in,
2379
    ecoff_swap_rfd_in,
2380
    ecoff_swap_ext_in,
2381
    _bfd_ecoff_swap_tir_in,
2382
    _bfd_ecoff_swap_rndx_in,
2383
    /* Functions to swap out external symbolic data.  */
2384
    ecoff_swap_hdr_out,
2385
    ecoff_swap_dnr_out,
2386
    ecoff_swap_pdr_out,
2387
    ecoff_swap_sym_out,
2388
    ecoff_swap_opt_out,
2389
    ecoff_swap_fdr_out,
2390
    ecoff_swap_rfd_out,
2391
    ecoff_swap_ext_out,
2392
    _bfd_ecoff_swap_tir_out,
2393
    _bfd_ecoff_swap_rndx_out,
2394
    /* Function to read in symbolic data.  */
2395
    _bfd_ecoff_slurp_symbolic_info
2396
  },
2397
  /* External reloc size.  */
2398
  RELSZ,
2399
  /* Reloc swapping functions.  */
2400
  alpha_ecoff_swap_reloc_in,
2401
  alpha_ecoff_swap_reloc_out,
2402
  /* Backend reloc tweaking.  */
2403
  alpha_adjust_reloc_in,
2404
  alpha_adjust_reloc_out,
2405
  /* Relocate section contents while linking.  */
2406
  alpha_relocate_section,
2407
  /* Do final adjustments to filehdr and aouthdr.  */
2408
  alpha_adjust_headers,
2409
  /* Read an element from an archive at a given file position.  */
2410
  alpha_ecoff_get_elt_at_filepos
2411
};
2412
2413
/* Looking up a reloc type is Alpha specific.  */
2414
#define _bfd_ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
2415
#define _bfd_ecoff_bfd_reloc_name_lookup \
2416
  alpha_bfd_reloc_name_lookup
2417
2418
/* So is getting relocated section contents.  */
2419
#define _bfd_ecoff_bfd_get_relocated_section_contents \
2420
  alpha_ecoff_get_relocated_section_contents
2421
2422
/* Input section flag lookup is generic.  */
2423
#define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
2424
2425
/* Relaxing sections is generic.  */
2426
#define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section
2427
#define _bfd_ecoff_bfd_gc_sections bfd_generic_gc_sections
2428
#define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section
2429
#define _bfd_ecoff_bfd_group_name bfd_generic_group_name
2430
#define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
2431
#define _bfd_ecoff_section_already_linked \
2432
  _bfd_coff_section_already_linked
2433
#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
2434
#define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
2435
#define _bfd_ecoff_bfd_define_start_stop    bfd_generic_define_start_stop
2436
#define _bfd_ecoff_bfd_link_check_relocs    _bfd_generic_link_check_relocs
2437
2438
/* Installing internal relocations in a section is also generic.  */
2439
#define _bfd_ecoff_finalize_section_relocs _bfd_generic_finalize_section_relocs
2440
2441
const bfd_target alpha_ecoff_le_vec =
2442
{
2443
  "ecoff-littlealpha",    /* name */
2444
  bfd_target_ecoff_flavour,
2445
  BFD_ENDIAN_LITTLE,    /* data byte order is little */
2446
  BFD_ENDIAN_LITTLE,    /* header byte order is little */
2447
2448
  (HAS_RELOC | EXEC_P   /* object flags */
2449
   | HAS_LINENO | HAS_DEBUG
2450
   | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2451
2452
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE
2453
   | SEC_DATA | SEC_SMALL_DATA),
2454
  0,        /* leading underscore */
2455
  ' ',        /* ar_pad_char */
2456
  15,       /* ar_max_namelen */
2457
  0,        /* match priority.  */
2458
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
2459
  TARGET_MERGE_SECTIONS,
2460
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2461
     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2462
     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
2463
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2464
     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2465
     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
2466
2467
  {       /* bfd_check_format */
2468
    _bfd_dummy_target,
2469
    alpha_ecoff_object_p,
2470
    bfd_generic_archive_p,
2471
    _bfd_dummy_target
2472
  },
2473
  {       /* bfd_set_format */
2474
    _bfd_bool_bfd_false_error,
2475
    _bfd_ecoff_mkobject,
2476
    _bfd_generic_mkarchive,
2477
    _bfd_bool_bfd_false_error
2478
  },
2479
  {       /* bfd_write_contents */
2480
    _bfd_bool_bfd_false_error,
2481
    _bfd_ecoff_write_object_contents,
2482
    _bfd_write_archive_contents,
2483
    _bfd_bool_bfd_false_error
2484
  },
2485
2486
  BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
2487
  BFD_JUMP_TABLE_COPY (_bfd_ecoff),
2488
  BFD_JUMP_TABLE_CORE (_bfd_nocore),
2489
  BFD_JUMP_TABLE_ARCHIVE (alpha_ecoff),
2490
  BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
2491
  BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
2492
  BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
2493
  BFD_JUMP_TABLE_LINK (_bfd_ecoff),
2494
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2495
2496
  NULL,
2497
2498
  &alpha_ecoff_backend_data
2499
};