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