Coverage Report

Created: 2026-07-25 10:20

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