Coverage Report

Created: 2025-06-24 06:45

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