Coverage Report

Created: 2026-03-10 08:46

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