1 /* BFD back-end for ALPHA Extended-Coff files.
2 Copyright 1993, 1994 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
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 2 of the License, or
11 (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "coff/internal.h"
28 #include "coff/symconst.h"
29 #include "coff/ecoff.h"
30 #include "coff/alpha.h"
34 /* Prototypes for static functions. */
36 static bfd_target *alpha_ecoff_object_p PARAMS ((bfd *));
37 static boolean alpha_ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
38 static void alpha_ecoff_swap_reloc_in PARAMS ((bfd *, PTR,
39 struct internal_reloc *));
40 static void alpha_ecoff_swap_reloc_out PARAMS ((bfd *,
41 const struct internal_reloc *,
43 static void alpha_adjust_reloc_in PARAMS ((bfd *,
44 const struct internal_reloc *,
46 static void alpha_adjust_reloc_out PARAMS ((bfd *, const arelent *,
47 struct internal_reloc *));
48 static bfd_byte *alpha_ecoff_get_relocated_section_contents
49 PARAMS ((bfd *abfd, struct bfd_link_info *, struct bfd_link_order *,
50 bfd_byte *data, boolean relocateable, asymbol **symbols));
51 static bfd_vma alpha_convert_external_reloc
52 PARAMS ((bfd *, struct bfd_link_info *, bfd *, struct external_reloc *,
53 struct ecoff_link_hash_entry *));
54 static boolean alpha_relocate_section PARAMS ((bfd *, struct bfd_link_info *,
58 /* ECOFF has COFF sections, but the debugging information is stored in
59 a completely different format. ECOFF targets use some of the
60 swapping routines from coffswap.h, and some of the generic COFF
61 routines in coffgen.c, but, unlike the real COFF targets, do not
62 use coffcode.h itself.
64 Get the generic COFF swapping routines, except for the reloc,
65 symbol, and lineno ones. Give them ecoff names. Define some
66 accessor macros for the large sizes used for Alpha ECOFF. */
68 #define GET_FILEHDR_SYMPTR bfd_h_get_64
69 #define PUT_FILEHDR_SYMPTR bfd_h_put_64
70 #define GET_AOUTHDR_TSIZE bfd_h_get_64
71 #define PUT_AOUTHDR_TSIZE bfd_h_put_64
72 #define GET_AOUTHDR_DSIZE bfd_h_get_64
73 #define PUT_AOUTHDR_DSIZE bfd_h_put_64
74 #define GET_AOUTHDR_BSIZE bfd_h_get_64
75 #define PUT_AOUTHDR_BSIZE bfd_h_put_64
76 #define GET_AOUTHDR_ENTRY bfd_h_get_64
77 #define PUT_AOUTHDR_ENTRY bfd_h_put_64
78 #define GET_AOUTHDR_TEXT_START bfd_h_get_64
79 #define PUT_AOUTHDR_TEXT_START bfd_h_put_64
80 #define GET_AOUTHDR_DATA_START bfd_h_get_64
81 #define PUT_AOUTHDR_DATA_START bfd_h_put_64
82 #define GET_SCNHDR_PADDR bfd_h_get_64
83 #define PUT_SCNHDR_PADDR bfd_h_put_64
84 #define GET_SCNHDR_VADDR bfd_h_get_64
85 #define PUT_SCNHDR_VADDR bfd_h_put_64
86 #define GET_SCNHDR_SIZE bfd_h_get_64
87 #define PUT_SCNHDR_SIZE bfd_h_put_64
88 #define GET_SCNHDR_SCNPTR bfd_h_get_64
89 #define PUT_SCNHDR_SCNPTR bfd_h_put_64
90 #define GET_SCNHDR_RELPTR bfd_h_get_64
91 #define PUT_SCNHDR_RELPTR bfd_h_put_64
92 #define GET_SCNHDR_LNNOPTR bfd_h_get_64
93 #define PUT_SCNHDR_LNNOPTR bfd_h_put_64
97 #define NO_COFF_RELOCS
98 #define NO_COFF_SYMBOLS
99 #define NO_COFF_LINENOS
100 #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
101 #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
102 #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
103 #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
104 #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
105 #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
106 #include "coffswap.h"
108 /* Get the ECOFF swapping routines. */
110 #include "ecoffswap.h"
112 /* How to process the various reloc types. */
114 static bfd_reloc_status_type
115 reloc_nil (abfd, reloc, sym, data, sec, output_bfd)
126 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
127 from smaller values. Start with zero, widen, *then* decrement. */
128 #define MINUS_ONE (((bfd_vma)0) - 1)
130 static reloc_howto_type alpha_howto_table[] =
132 /* Reloc type 0 is ignored by itself. However, it appears after a
133 GPDISP reloc to identify the location where the low order 16 bits
134 of the gp register are loaded. */
135 HOWTO (ALPHA_R_IGNORE, /* type */
137 0, /* size (0 = byte, 1 = short, 2 = long) */
139 true, /* pc_relative */
141 complain_overflow_dont, /* complain_on_overflow */
142 reloc_nil, /* special_function */
144 true, /* partial_inplace */
147 true), /* pcrel_offset */
149 /* A 32 bit reference to a symbol. */
150 HOWTO (ALPHA_R_REFLONG, /* type */
152 2, /* size (0 = byte, 1 = short, 2 = long) */
154 false, /* pc_relative */
156 complain_overflow_bitfield, /* complain_on_overflow */
157 0, /* special_function */
158 "REFLONG", /* name */
159 true, /* partial_inplace */
160 0xffffffff, /* src_mask */
161 0xffffffff, /* dst_mask */
162 false), /* pcrel_offset */
164 /* A 64 bit reference to a symbol. */
165 HOWTO (ALPHA_R_REFQUAD, /* type */
167 4, /* size (0 = byte, 1 = short, 2 = long) */
169 false, /* pc_relative */
171 complain_overflow_bitfield, /* complain_on_overflow */
172 0, /* special_function */
173 "REFQUAD", /* name */
174 true, /* partial_inplace */
175 MINUS_ONE, /* src_mask */
176 MINUS_ONE, /* dst_mask */
177 false), /* pcrel_offset */
179 /* A 32 bit GP relative offset. This is just like REFLONG except
180 that when the value is used the value of the gp register will be
182 HOWTO (ALPHA_R_GPREL32, /* type */
184 2, /* size (0 = byte, 1 = short, 2 = long) */
186 false, /* pc_relative */
188 complain_overflow_bitfield, /* complain_on_overflow */
189 0, /* special_function */
190 "GPREL32", /* name */
191 true, /* partial_inplace */
192 0xffffffff, /* src_mask */
193 0xffffffff, /* dst_mask */
194 false), /* pcrel_offset */
196 /* Used for an instruction that refers to memory off the GP
197 register. The offset is 16 bits of the 32 bit instruction. This
198 reloc always seems to be against the .lita section. */
199 HOWTO (ALPHA_R_LITERAL, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 false, /* pc_relative */
205 complain_overflow_signed, /* complain_on_overflow */
206 0, /* special_function */
207 "LITERAL", /* name */
208 true, /* partial_inplace */
209 0xffff, /* src_mask */
210 0xffff, /* dst_mask */
211 false), /* pcrel_offset */
213 /* This reloc only appears immediately following a LITERAL reloc.
214 It identifies a use of the literal. It seems that the linker can
215 use this to eliminate a portion of the .lita section. The symbol
216 index is special: 1 means the literal address is in the base
217 register of a memory format instruction; 2 means the literal
218 address is in the byte offset register of a byte-manipulation
219 instruction; 3 means the literal address is in the target
220 register of a jsr instruction. This does not actually do any
222 HOWTO (ALPHA_R_LITUSE, /* type */
224 2, /* size (0 = byte, 1 = short, 2 = long) */
226 false, /* pc_relative */
228 complain_overflow_dont, /* complain_on_overflow */
229 reloc_nil, /* special_function */
231 false, /* partial_inplace */
234 false), /* pcrel_offset */
236 /* Load the gp register. This is always used for a ldah instruction
237 which loads the upper 16 bits of the gp register. The next reloc
238 will be an IGNORE reloc which identifies the location of the lda
239 instruction which loads the lower 16 bits. The symbol index of
240 the GPDISP instruction appears to actually be the number of bytes
241 between the ldah and lda instructions. This gives two different
242 ways to determine where the lda instruction is; I don't know why
243 both are used. The value to use for the relocation is the
244 difference between the GP value and the current location; the
245 load will always be done against a register holding the current
247 HOWTO (ALPHA_R_GPDISP, /* type */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
251 true, /* pc_relative */
253 complain_overflow_dont, /* complain_on_overflow */
254 reloc_nil, /* special_function */
256 true, /* partial_inplace */
257 0xffff, /* src_mask */
258 0xffff, /* dst_mask */
259 true), /* pcrel_offset */
261 /* A 21 bit branch. The native assembler generates these for
262 branches within the text segment, and also fills in the PC
263 relative offset in the instruction. */
264 HOWTO (ALPHA_R_BRADDR, /* type */
266 2, /* size (0 = byte, 1 = short, 2 = long) */
268 true, /* pc_relative */
270 complain_overflow_signed, /* complain_on_overflow */
271 0, /* special_function */
273 true, /* partial_inplace */
274 0x1fffff, /* src_mask */
275 0x1fffff, /* dst_mask */
276 false), /* pcrel_offset */
278 /* A hint for a jump to a register. */
279 HOWTO (ALPHA_R_HINT, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 true, /* pc_relative */
285 complain_overflow_dont, /* complain_on_overflow */
286 0, /* special_function */
288 true, /* partial_inplace */
289 0x3fff, /* src_mask */
290 0x3fff, /* dst_mask */
291 false), /* pcrel_offset */
293 /* 16 bit PC relative offset. */
294 HOWTO (ALPHA_R_SREL16, /* type */
296 1, /* size (0 = byte, 1 = short, 2 = long) */
298 true, /* pc_relative */
300 complain_overflow_signed, /* complain_on_overflow */
301 0, /* special_function */
303 true, /* partial_inplace */
304 0xffff, /* src_mask */
305 0xffff, /* dst_mask */
306 false), /* pcrel_offset */
308 /* 32 bit PC relative offset. */
309 HOWTO (ALPHA_R_SREL32, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 true, /* pc_relative */
315 complain_overflow_signed, /* complain_on_overflow */
316 0, /* special_function */
318 true, /* partial_inplace */
319 0xffffffff, /* src_mask */
320 0xffffffff, /* dst_mask */
321 false), /* pcrel_offset */
323 /* A 64 bit PC relative offset. */
324 HOWTO (ALPHA_R_SREL64, /* type */
326 4, /* size (0 = byte, 1 = short, 2 = long) */
328 true, /* pc_relative */
330 complain_overflow_signed, /* complain_on_overflow */
331 0, /* special_function */
333 true, /* partial_inplace */
334 MINUS_ONE, /* src_mask */
335 MINUS_ONE, /* dst_mask */
336 false), /* pcrel_offset */
338 /* Push a value on the reloc evaluation stack. */
339 HOWTO (ALPHA_R_OP_PUSH, /* type */
341 0, /* size (0 = byte, 1 = short, 2 = long) */
343 false, /* pc_relative */
345 complain_overflow_dont, /* complain_on_overflow */
346 0, /* special_function */
347 "OP_PUSH", /* name */
348 false, /* partial_inplace */
351 false), /* pcrel_offset */
353 /* Store the value from the stack at the given address. Store it in
354 a bitfield of size r_size starting at bit position r_offset. */
355 HOWTO (ALPHA_R_OP_STORE, /* type */
357 4, /* size (0 = byte, 1 = short, 2 = long) */
359 false, /* pc_relative */
361 complain_overflow_dont, /* complain_on_overflow */
362 0, /* special_function */
363 "OP_STORE", /* name */
364 false, /* partial_inplace */
366 MINUS_ONE, /* dst_mask */
367 false), /* pcrel_offset */
369 /* Subtract the reloc address from the value on the top of the
371 HOWTO (ALPHA_R_OP_PSUB, /* type */
373 0, /* size (0 = byte, 1 = short, 2 = long) */
375 false, /* pc_relative */
377 complain_overflow_dont, /* complain_on_overflow */
378 0, /* special_function */
379 "OP_PSUB", /* name */
380 false, /* partial_inplace */
383 false), /* pcrel_offset */
385 /* Shift the value on the top of the relocation stack right by the
387 HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
389 0, /* size (0 = byte, 1 = short, 2 = long) */
391 false, /* pc_relative */
393 complain_overflow_dont, /* complain_on_overflow */
394 0, /* special_function */
395 "OP_PRSHIFT", /* name */
396 false, /* partial_inplace */
399 false), /* pcrel_offset */
401 /* Adjust the GP value for a new range in the object file. */
402 HOWTO (ALPHA_R_GPVALUE, /* type */
404 0, /* size (0 = byte, 1 = short, 2 = long) */
406 false, /* pc_relative */
408 complain_overflow_dont, /* complain_on_overflow */
409 0, /* special_function */
410 "GPVALUE", /* name */
411 false, /* partial_inplace */
414 false) /* pcrel_offset */
417 /* Recognize an Alpha ECOFF file. */
420 alpha_ecoff_object_p (abfd)
423 static bfd_target *ret;
425 ret = coff_object_p (abfd);
427 if (ret != (bfd_target *) NULL)
431 /* Alpha ECOFF has a .pdata section. The lnnoptr field of the
432 .pdata section is the number of entries it contains. Each
433 entry takes up 8 bytes. The number of entries is required
434 since the section is aligned to a 16 byte boundary. When we
435 link .pdata sections together, we do not want to include the
436 alignment bytes. We handle this on input by faking the size
437 of the .pdata section to remove the unwanted alignment bytes.
438 On output we will set the lnnoptr field and force the
440 sec = bfd_get_section_by_name (abfd, _PDATA);
441 if (sec != (asection *) NULL)
445 size = sec->line_filepos * 8;
446 BFD_ASSERT (size == bfd_section_size (abfd, sec)
447 || size + 8 == bfd_section_size (abfd, sec));
448 if (! bfd_set_section_size (abfd, sec, size))
456 /* See whether the magic number matches. */
459 alpha_ecoff_bad_format_hook (abfd, filehdr)
463 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
465 if (ALPHA_ECOFF_BADMAG (*internal_f))
471 /* Reloc handling. */
473 /* Swap a reloc in. */
476 alpha_ecoff_swap_reloc_in (abfd, ext_ptr, intern)
479 struct internal_reloc *intern;
481 const RELOC *ext = (RELOC *) ext_ptr;
483 intern->r_vaddr = bfd_h_get_64 (abfd, (bfd_byte *) ext->r_vaddr);
484 intern->r_symndx = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_symndx);
486 BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false);
488 intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
489 >> RELOC_BITS0_TYPE_SH_LITTLE);
490 intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
491 intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
492 >> RELOC_BITS1_OFFSET_SH_LITTLE);
493 /* Ignored the reserved bits. */
494 intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
495 >> RELOC_BITS3_SIZE_SH_LITTLE);
497 if (intern->r_type == ALPHA_R_LITUSE
498 || intern->r_type == ALPHA_R_GPDISP)
500 /* Handle the LITUSE and GPDISP relocs specially. Its symndx
501 value is not actually a symbol index, but is instead a
502 special code. We put the code in the r_size field, and
503 clobber the symndx. */
504 if (intern->r_size != 0)
506 intern->r_size = intern->r_symndx;
507 intern->r_symndx = RELOC_SECTION_NONE;
509 else if (intern->r_type == ALPHA_R_IGNORE)
511 /* The IGNORE reloc generally follows a GPDISP reloc, and is
512 against the .lita section. The section is irrelevant. */
513 if (! intern->r_extern &&
514 (intern->r_symndx == RELOC_SECTION_NONE
515 || intern->r_symndx == RELOC_SECTION_ABS))
517 if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
518 intern->r_symndx = RELOC_SECTION_NONE;
522 /* Swap a reloc out. */
525 alpha_ecoff_swap_reloc_out (abfd, intern, dst)
527 const struct internal_reloc *intern;
530 RELOC *ext = (RELOC *) dst;
534 /* Undo the hackery done in swap_reloc_in. */
535 if (intern->r_type == ALPHA_R_LITUSE
536 || intern->r_type == ALPHA_R_GPDISP)
538 symndx = intern->r_size;
541 else if (intern->r_type == ALPHA_R_IGNORE
542 && ! intern->r_extern
543 && intern->r_symndx == RELOC_SECTION_NONE)
545 symndx = RELOC_SECTION_LITA;
546 size = intern->r_size;
550 symndx = intern->r_symndx;
551 size = intern->r_size;
554 BFD_ASSERT (intern->r_extern
555 || (intern->r_symndx >= 0 && intern->r_symndx <= 14));
557 bfd_h_put_64 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
558 bfd_h_put_32 (abfd, symndx, (bfd_byte *) ext->r_symndx);
560 BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false);
562 ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE)
563 & RELOC_BITS0_TYPE_LITTLE);
564 ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0)
565 | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE)
566 & RELOC_BITS1_OFFSET_LITTLE));
568 ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE)
569 & RELOC_BITS3_SIZE_LITTLE);
572 /* Finish canonicalizing a reloc. Part of this is generic to all
573 ECOFF targets, and that part is in ecoff.c. The rest is done in
574 this backend routine. It must fill in the howto field. */
577 alpha_adjust_reloc_in (abfd, intern, rptr)
579 const struct internal_reloc *intern;
582 if (intern->r_type > ALPHA_R_GPVALUE)
585 switch (intern->r_type)
591 /* The PC relative relocs do not seem to use the section VMA as
592 a negative addend. */
596 case ALPHA_R_GPREL32:
597 case ALPHA_R_LITERAL:
598 /* Copy the gp value for this object file into the addend, to
599 ensure that we are not confused by the linker. */
600 if (! intern->r_extern)
601 rptr->addend += ecoff_data (abfd)->gp;
606 /* The LITUSE and GPDISP relocs do not use a symbol, or an
607 addend, but they do use a special code. Put this code in the
609 rptr->addend = intern->r_size;
612 case ALPHA_R_OP_STORE:
613 /* The STORE reloc needs the size and offset fields. We store
614 them in the addend. */
615 BFD_ASSERT (intern->r_offset <= 256 && intern->r_size <= 256);
616 rptr->addend = (intern->r_offset << 8) + intern->r_size;
619 case ALPHA_R_OP_PUSH:
620 case ALPHA_R_OP_PSUB:
621 case ALPHA_R_OP_PRSHIFT:
622 /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
623 address. I believe that the address supplied is really an
625 rptr->addend = intern->r_vaddr;
628 case ALPHA_R_GPVALUE:
629 /* Set the addend field to the new GP value. */
630 rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp;
634 /* If the type is ALPHA_R_IGNORE, make sure this is a reference
635 to the absolute section so that the reloc is ignored. For
636 some reason the address of this reloc type is not adjusted by
637 the section vma. We record the gp value for this object file
638 here, for convenience when doing the GPDISP relocation. */
639 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
640 rptr->address = intern->r_vaddr;
641 rptr->addend = ecoff_data (abfd)->gp;
648 rptr->howto = &alpha_howto_table[intern->r_type];
651 /* When writing out a reloc we need to pull some values back out of
652 the addend field into the reloc. This is roughly the reverse of
653 alpha_adjust_reloc_in, except that there are several changes we do
657 alpha_adjust_reloc_out (abfd, rel, intern)
660 struct internal_reloc *intern;
662 switch (intern->r_type)
666 intern->r_size = rel->addend;
669 case ALPHA_R_OP_STORE:
670 intern->r_size = rel->addend & 0xff;
671 intern->r_offset = (rel->addend >> 8) & 0xff;
674 case ALPHA_R_OP_PUSH:
675 case ALPHA_R_OP_PSUB:
676 case ALPHA_R_OP_PRSHIFT:
677 intern->r_vaddr = rel->addend;
681 intern->r_vaddr = rel->address;
682 if (intern->r_symndx == RELOC_SECTION_ABS)
683 intern->r_symndx = RELOC_SECTION_NONE;
691 /* The size of the stack for the relocation evaluator. */
692 #define RELOC_STACKSIZE (10)
694 /* Alpha ECOFF relocs have a built in expression evaluator as well as
695 other interdependencies. Rather than use a bunch of special
696 functions and global variables, we use a single routine to do all
697 the relocation for a section. I haven't yet worked out how the
698 assembler is going to handle this. */
701 alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
702 data, relocateable, symbols)
704 struct bfd_link_info *link_info;
705 struct bfd_link_order *link_order;
707 boolean relocateable;
710 bfd *input_bfd = link_order->u.indirect.section->owner;
711 asection *input_section = link_order->u.indirect.section;
712 size_t reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
713 arelent **reloc_vector = (arelent **) alloca (reloc_size);
714 bfd *output_bfd = relocateable ? abfd : (bfd *) NULL;
716 boolean gp_undefined;
717 bfd_vma stack[RELOC_STACKSIZE];
720 if (! bfd_get_section_contents (input_bfd, input_section, data,
721 (file_ptr) 0, input_section->_raw_size))
724 /* The section size is not going to change. */
725 input_section->_cooked_size = input_section->_raw_size;
726 input_section->reloc_done = true;
728 if (bfd_canonicalize_reloc (input_bfd, input_section, reloc_vector,
733 /* Get the GP value for the output BFD. */
734 gp_undefined = false;
735 if (ecoff_data (abfd)->gp == 0)
737 if (relocateable != false)
742 /* Make up a value. */
744 for (sec = abfd->sections; sec != NULL; sec = sec->next)
747 && (strcmp (sec->name, ".sbss") == 0
748 || strcmp (sec->name, ".sdata") == 0
749 || strcmp (sec->name, ".lit4") == 0
750 || strcmp (sec->name, ".lit8") == 0
751 || strcmp (sec->name, ".lita") == 0))
754 ecoff_data (abfd)->gp = lo + 0x8000;
758 struct bfd_link_hash_entry *h;
760 h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
762 if (h == (struct bfd_link_hash_entry *) NULL
763 || h->type != bfd_link_hash_defined)
766 ecoff_data (abfd)->gp = (h->u.def.value
767 + h->u.def.section->output_section->vma
768 + h->u.def.section->output_offset);
771 gp = ecoff_data (abfd)->gp;
773 for (; *reloc_vector != (arelent *) NULL; reloc_vector++)
776 bfd_reloc_status_type r;
781 switch (rel->howto->type)
784 rel->address += input_section->output_offset;
787 case ALPHA_R_REFLONG:
788 case ALPHA_R_REFQUAD:
795 && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
797 rel->address += input_section->output_offset;
800 r = bfd_perform_relocation (input_bfd, rel, data, input_section,
804 case ALPHA_R_GPREL32:
805 /* This relocation is used in a switch table. It is a 32
806 bit offset from the current GP value. We must adjust it
807 by the different between the original GP value and the
808 current GP value. The original GP value is stored in the
809 addend. We adjust the addend and let
810 bfd_perform_relocation finish the job. */
812 r = bfd_perform_relocation (input_bfd, rel, data, input_section,
814 if (r == bfd_reloc_ok && gp_undefined)
816 r = bfd_reloc_dangerous;
817 err = (char *) "GP relative relocation used when GP not defined";
821 case ALPHA_R_LITERAL:
822 /* This is a reference to a literal value, generally
823 (always?) in the .lita section. This is a 16 bit GP
824 relative relocation. Sometimes the subsequent reloc is a
825 LITUSE reloc, which indicates how this reloc is used.
826 This sometimes permits rewriting the two instructions
827 referred to by the LITERAL and the LITUSE into different
828 instructions which do not refer to .lita. This can save
829 a memory reference, and permits removing a value from
830 .lita thus saving GP relative space.
832 We do not these optimizations. To do them we would need
833 to arrange to link the .lita section first, so that by
834 the time we got here we would know the final values to
835 use. This would not be particularly difficult, but it is
836 not currently implemented. */
841 /* I believe that the LITERAL reloc will only apply to a
842 ldq or ldl instruction, so check my assumption. */
843 insn = bfd_get_32 (input_bfd, data + rel->address);
844 BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29
845 || ((insn >> 26) & 0x3f) == 0x28);
848 r = bfd_perform_relocation (input_bfd, rel, data, input_section,
850 if (r == bfd_reloc_ok && gp_undefined)
852 r = bfd_reloc_dangerous;
854 (char *) "GP relative relocation used when GP not defined";
860 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
861 does not cause anything to happen, itself. */
862 rel->address += input_section->output_offset;
866 /* This marks the ldah of an ldah/lda pair which loads the
867 gp register with the difference of the gp value and the
868 current location. The second of the pair is r_size bytes
869 ahead, and is marked with an ALPHA_R_IGNORE reloc. */
871 unsigned long insn1, insn2;
874 BFD_ASSERT (reloc_vector[1] != NULL
875 && reloc_vector[1]->howto->type == ALPHA_R_IGNORE
876 && (rel->address + rel->addend
877 == reloc_vector[1]->address));
879 /* Get the two instructions. */
880 insn1 = bfd_get_32 (input_bfd, data + rel->address);
881 insn2 = bfd_get_32 (input_bfd, data + rel->address + rel->addend);
883 BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
884 BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
886 /* Get the existing addend. We must account for the sign
887 extension done by lda and ldah. */
888 addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
891 addend -= 0x80000000;
892 addend -= 0x80000000;
897 /* The existing addend includes the different between the
898 gp of the input BFD and the address in the input BFD.
899 Subtract this out. */
900 addend -= (reloc_vector[1]->addend
901 - (input_section->vma + rel->address));
903 /* Now add in the final gp value, and subtract out the
906 - (input_section->output_section->vma
907 + input_section->output_offset
910 /* Change the instructions, accounting for the sign
911 extension, and write them out. */
914 insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
915 insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
917 bfd_put_32 (input_bfd, (bfd_vma) insn1, data + rel->address);
918 bfd_put_32 (input_bfd, (bfd_vma) insn2,
919 data + rel->address + rel->addend);
921 rel->address += input_section->output_offset;
925 case ALPHA_R_OP_PUSH:
926 /* Push a value on the reloc evaluation stack. */
933 rel->address += input_section->output_offset;
937 /* Figure out the relocation of this symbol. */
938 symbol = *rel->sym_ptr_ptr;
940 if (symbol->section == &bfd_und_section)
941 r = bfd_reloc_undefined;
943 if (bfd_is_com_section (symbol->section))
946 relocation = symbol->value;
947 relocation += symbol->section->output_section->vma;
948 relocation += symbol->section->output_offset;
949 relocation += rel->addend;
951 if (tos >= RELOC_STACKSIZE)
954 stack[tos++] = relocation;
958 case ALPHA_R_OP_STORE:
959 /* Store a value from the reloc stack into a bitfield. */
966 rel->address += input_section->output_offset;
973 /* The offset and size for this reloc are encoded into the
974 addend field by alpha_adjust_reloc_in. */
975 offset = (rel->addend >> 8) & 0xff;
976 size = rel->addend & 0xff;
978 val = bfd_get_64 (abfd, data + rel->address);
979 val &=~ (((1 << size) - 1) << offset);
980 val |= (stack[--tos] & ((1 << size) - 1)) << offset;
981 bfd_put_64 (abfd, val, data + rel->address);
985 case ALPHA_R_OP_PSUB:
986 /* Subtract a value from the top of the stack. */
993 rel->address += input_section->output_offset;
997 /* Figure out the relocation of this symbol. */
998 symbol = *rel->sym_ptr_ptr;
1000 if (symbol->section == &bfd_und_section)
1001 r = bfd_reloc_undefined;
1003 if (bfd_is_com_section (symbol->section))
1006 relocation = symbol->value;
1007 relocation += symbol->section->output_section->vma;
1008 relocation += symbol->section->output_offset;
1009 relocation += rel->addend;
1014 stack[tos - 1] -= relocation;
1018 case ALPHA_R_OP_PRSHIFT:
1019 /* Shift the value on the top of the stack. */
1026 rel->address += input_section->output_offset;
1030 /* Figure out the relocation of this symbol. */
1031 symbol = *rel->sym_ptr_ptr;
1033 if (symbol->section == &bfd_und_section)
1034 r = bfd_reloc_undefined;
1036 if (bfd_is_com_section (symbol->section))
1039 relocation = symbol->value;
1040 relocation += symbol->section->output_section->vma;
1041 relocation += symbol->section->output_offset;
1042 relocation += rel->addend;
1047 stack[tos - 1] >>= relocation;
1051 case ALPHA_R_GPVALUE:
1052 /* I really don't know if this does the right thing. */
1054 gp_undefined = false;
1063 asection *os = input_section->output_section;
1065 /* A partial link, so keep the relocs. */
1066 os->orelocation[os->reloc_count] = rel;
1070 if (r != bfd_reloc_ok)
1074 case bfd_reloc_undefined:
1075 if (! ((*link_info->callbacks->undefined_symbol)
1076 (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
1077 input_bfd, input_section, rel->address)))
1080 case bfd_reloc_dangerous:
1081 if (! ((*link_info->callbacks->reloc_dangerous)
1082 (link_info, err, input_bfd, input_section,
1086 case bfd_reloc_overflow:
1087 if (! ((*link_info->callbacks->reloc_overflow)
1088 (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
1089 rel->howto->name, rel->addend, input_bfd,
1090 input_section, rel->address)))
1093 case bfd_reloc_outofrange:
1107 /* Get the howto structure for a generic reloc type. */
1109 static CONST struct reloc_howto_struct *
1110 alpha_bfd_reloc_type_lookup (abfd, code)
1112 bfd_reloc_code_real_type code;
1119 alpha_type = ALPHA_R_REFLONG;
1122 alpha_type = ALPHA_R_REFQUAD;
1124 case BFD_RELOC_GPREL32:
1125 alpha_type = ALPHA_R_GPREL32;
1127 case BFD_RELOC_ALPHA_LITERAL:
1128 alpha_type = ALPHA_R_LITERAL;
1130 case BFD_RELOC_ALPHA_LITUSE:
1131 alpha_type = ALPHA_R_LITUSE;
1133 case BFD_RELOC_ALPHA_GPDISP_HI16:
1134 alpha_type = ALPHA_R_GPDISP;
1136 case BFD_RELOC_ALPHA_GPDISP_LO16:
1137 alpha_type = ALPHA_R_IGNORE;
1139 case BFD_RELOC_23_PCREL_S2:
1140 alpha_type = ALPHA_R_BRADDR;
1142 case BFD_RELOC_ALPHA_HINT:
1143 alpha_type = ALPHA_R_HINT;
1145 case BFD_RELOC_16_PCREL:
1146 alpha_type = ALPHA_R_SREL16;
1148 case BFD_RELOC_32_PCREL:
1149 alpha_type = ALPHA_R_SREL32;
1151 case BFD_RELOC_64_PCREL:
1152 alpha_type = ALPHA_R_SREL64;
1156 alpha_type = ALPHA_R_OP_PUSH;
1159 alpha_type = ALPHA_R_OP_STORE;
1162 alpha_type = ALPHA_R_OP_PSUB;
1165 alpha_type = ALPHA_R_OP_PRSHIFT;
1168 alpha_type = ALPHA_R_GPVALUE;
1172 return (CONST struct reloc_howto_struct *) NULL;
1175 return &alpha_howto_table[alpha_type];
1178 /* A helper routine for alpha_relocate_section which converts an
1179 external reloc when generating relocateable output. Returns the
1180 relocation amount. */
1183 alpha_convert_external_reloc (output_bfd, info, input_bfd, ext_rel, h)
1185 struct bfd_link_info *info;
1187 struct external_reloc *ext_rel;
1188 struct ecoff_link_hash_entry *h;
1190 unsigned long r_symndx;
1193 BFD_ASSERT (info->relocateable);
1195 if (h->root.type == bfd_link_hash_defined)
1200 /* This symbol is defined in the output. Convert the reloc from
1201 being against the symbol to being against the section. */
1203 /* Clear the r_extern bit. */
1204 ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE;
1206 /* Compute a new r_symndx value. */
1207 hsec = h->root.u.def.section;
1208 name = bfd_get_section_name (output_bfd, hsec->output_section);
1214 if (strcmp (name, "*ABS*") == 0)
1215 r_symndx = RELOC_SECTION_ABS;
1218 if (strcmp (name, ".bss") == 0)
1219 r_symndx = RELOC_SECTION_BSS;
1222 if (strcmp (name, ".data") == 0)
1223 r_symndx = RELOC_SECTION_DATA;
1226 if (strcmp (name, ".fini") == 0)
1227 r_symndx = RELOC_SECTION_FINI;
1230 if (strcmp (name, ".init") == 0)
1231 r_symndx = RELOC_SECTION_INIT;
1234 if (strcmp (name, ".lita") == 0)
1235 r_symndx = RELOC_SECTION_LITA;
1236 else if (strcmp (name, ".lit8") == 0)
1237 r_symndx = RELOC_SECTION_LIT8;
1238 else if (strcmp (name, ".lit4") == 0)
1239 r_symndx = RELOC_SECTION_LIT4;
1242 if (strcmp (name, ".pdata") == 0)
1243 r_symndx = RELOC_SECTION_PDATA;
1246 if (strcmp (name, ".rdata") == 0)
1247 r_symndx = RELOC_SECTION_RDATA;
1250 if (strcmp (name, ".sdata") == 0)
1251 r_symndx = RELOC_SECTION_SDATA;
1252 else if (strcmp (name, ".sbss") == 0)
1253 r_symndx = RELOC_SECTION_SBSS;
1256 if (strcmp (name, ".text") == 0)
1257 r_symndx = RELOC_SECTION_TEXT;
1260 if (strcmp (name, ".xdata") == 0)
1261 r_symndx = RELOC_SECTION_XDATA;
1268 /* Add the section VMA and the symbol value. */
1269 relocation = (h->root.u.def.value
1270 + hsec->output_section->vma
1271 + hsec->output_offset);
1275 /* Change the symndx value to the right one for
1280 /* Caller must give an error. */
1286 /* Write out the new r_symndx value. */
1287 bfd_h_put_32 (input_bfd, (bfd_vma) r_symndx,
1288 (bfd_byte *) ext_rel->r_symndx);
1293 /* Relocate a section while linking an Alpha ECOFF file. This is
1294 quite similar to get_relocated_section_contents. Perhaps they
1295 could be combined somehow. */
1298 alpha_relocate_section (output_bfd, info, input_bfd, input_section,
1299 contents, external_relocs)
1301 struct bfd_link_info *info;
1303 asection *input_section;
1305 PTR external_relocs;
1307 asection **symndx_to_section;
1308 struct ecoff_link_hash_entry **sym_hashes;
1310 boolean gp_undefined;
1311 bfd_vma stack[RELOC_STACKSIZE];
1313 struct external_reloc *ext_rel;
1314 struct external_reloc *ext_rel_end;
1316 /* We keep a table mapping the symndx found in an internal reloc to
1317 the appropriate section. This is faster than looking up the
1318 section by name each time. */
1319 symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
1320 if (symndx_to_section == (asection **) NULL)
1322 symndx_to_section = ((asection **)
1323 bfd_alloc (input_bfd,
1325 * sizeof (asection *))));
1326 if (!symndx_to_section)
1328 bfd_set_error (bfd_error_no_memory);
1332 symndx_to_section[RELOC_SECTION_NONE] = NULL;
1333 symndx_to_section[RELOC_SECTION_TEXT] =
1334 bfd_get_section_by_name (input_bfd, ".text");
1335 symndx_to_section[RELOC_SECTION_RDATA] =
1336 bfd_get_section_by_name (input_bfd, ".rdata");
1337 symndx_to_section[RELOC_SECTION_DATA] =
1338 bfd_get_section_by_name (input_bfd, ".data");
1339 symndx_to_section[RELOC_SECTION_SDATA] =
1340 bfd_get_section_by_name (input_bfd, ".sdata");
1341 symndx_to_section[RELOC_SECTION_SBSS] =
1342 bfd_get_section_by_name (input_bfd, ".sbss");
1343 symndx_to_section[RELOC_SECTION_BSS] =
1344 bfd_get_section_by_name (input_bfd, ".bss");
1345 symndx_to_section[RELOC_SECTION_INIT] =
1346 bfd_get_section_by_name (input_bfd, ".init");
1347 symndx_to_section[RELOC_SECTION_LIT8] =
1348 bfd_get_section_by_name (input_bfd, ".lit8");
1349 symndx_to_section[RELOC_SECTION_LIT4] =
1350 bfd_get_section_by_name (input_bfd, ".lit4");
1351 symndx_to_section[RELOC_SECTION_XDATA] =
1352 bfd_get_section_by_name (input_bfd, ".xdata");
1353 symndx_to_section[RELOC_SECTION_PDATA] =
1354 bfd_get_section_by_name (input_bfd, ".pdata");
1355 symndx_to_section[RELOC_SECTION_FINI] =
1356 bfd_get_section_by_name (input_bfd, ".fini");
1357 symndx_to_section[RELOC_SECTION_LITA] =
1358 bfd_get_section_by_name (input_bfd, ".lita");
1359 symndx_to_section[RELOC_SECTION_ABS] = &bfd_abs_section;
1361 ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
1364 sym_hashes = ecoff_data (input_bfd)->sym_hashes;
1366 gp = ecoff_data (output_bfd)->gp;
1368 gp_undefined = true;
1370 gp_undefined = false;
1372 BFD_ASSERT (output_bfd->xvec->header_byteorder_big_p == false);
1373 BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p == false);
1375 ext_rel = (struct external_reloc *) external_relocs;
1376 ext_rel_end = ext_rel + input_section->reloc_count;
1377 for (; ext_rel < ext_rel_end; ext_rel++)
1380 unsigned long r_symndx;
1386 boolean adjust_addrp;
1390 r_vaddr = bfd_h_get_64 (input_bfd, (bfd_byte *) ext_rel->r_vaddr);
1391 r_symndx = bfd_h_get_32 (input_bfd, (bfd_byte *) ext_rel->r_symndx);
1393 r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
1394 >> RELOC_BITS0_TYPE_SH_LITTLE);
1395 r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
1396 r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
1397 >> RELOC_BITS1_OFFSET_SH_LITTLE);
1398 /* Ignored the reserved bits. */
1399 r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
1400 >> RELOC_BITS3_SIZE_SH_LITTLE);
1403 adjust_addrp = true;
1412 case ALPHA_R_IGNORE:
1413 /* This reloc appears after a GPDISP reloc. It marks the
1414 position of the second instruction to be altered by the
1415 GPDISP reloc, but is not otherwise used for anything.
1416 For some reason, the address of the relocation does not
1417 appear to include the section VMA, unlike the other
1418 relocation types. */
1419 if (info->relocateable)
1420 bfd_h_put_64 (input_bfd,
1421 input_section->output_offset + r_vaddr,
1422 (bfd_byte *) ext_rel->r_vaddr);
1423 adjust_addrp = false;
1426 case ALPHA_R_REFLONG:
1427 case ALPHA_R_REFQUAD:
1428 case ALPHA_R_BRADDR:
1430 case ALPHA_R_SREL16:
1431 case ALPHA_R_SREL32:
1432 case ALPHA_R_SREL64:
1436 case ALPHA_R_GPREL32:
1437 /* This relocation is used in a switch table. It is a 32
1438 bit offset from the current GP value. We must adjust it
1439 by the different between the original GP value and the
1440 current GP value. */
1442 addend = ecoff_data (input_bfd)->gp - gp;
1446 case ALPHA_R_LITERAL:
1447 /* This is a reference to a literal value, generally
1448 (always?) in the .lita section. This is a 16 bit GP
1449 relative relocation. Sometimes the subsequent reloc is a
1450 LITUSE reloc, which indicates how this reloc is used.
1451 This sometimes permits rewriting the two instructions
1452 referred to by the LITERAL and the LITUSE into different
1453 instructions which do not refer to .lita. This can save
1454 a memory reference, and permits removing a value from
1455 .lita thus saving GP relative space.
1457 We do not these optimizations. To do them we would need
1458 to arrange to link the .lita section first, so that by
1459 the time we got here we would know the final values to
1460 use. This would not be particularly difficult, but it is
1461 not currently implemented. */
1463 /* I believe that the LITERAL reloc will only apply to a ldq
1464 or ldl instruction, so check my assumption. */
1468 insn = bfd_get_32 (input_bfd,
1469 contents + r_vaddr - input_section->vma);
1470 BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29
1471 || ((insn >> 26) & 0x3f) == 0x28);
1475 addend = ecoff_data (input_bfd)->gp - gp;
1479 case ALPHA_R_LITUSE:
1480 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
1481 does not cause anything to happen, itself. */
1484 case ALPHA_R_GPDISP:
1485 /* This marks the ldah of an ldah/lda pair which loads the
1486 gp register with the difference of the gp value and the
1487 current location. The second of the pair is r_symndx
1488 bytes ahead, and is also marked with an ALPHA_R_IGNORE
1491 unsigned long insn1, insn2;
1493 BFD_ASSERT (ext_rel + 1 < ext_rel_end
1494 && (((ext_rel + 1)->r_bits[0]
1495 & RELOC_BITS0_TYPE_LITTLE)
1496 >> RELOC_BITS0_TYPE_SH_LITTLE) == ALPHA_R_IGNORE
1497 && (bfd_h_get_64 (input_bfd,
1498 (bfd_byte *) (ext_rel + 1)->r_vaddr)
1499 == r_vaddr - input_section->vma + r_symndx));
1501 /* Get the two instructions. */
1502 insn1 = bfd_get_32 (input_bfd,
1503 contents + r_vaddr - input_section->vma);
1504 insn2 = bfd_get_32 (input_bfd,
1507 - input_section->vma
1510 BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
1511 BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
1513 /* Get the existing addend. We must account for the sign
1514 extension done by lda and ldah. */
1515 addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
1518 /* This is addend -= 0x100000000 without causing an
1519 integer overflow on a 32 bit host. */
1520 addend -= 0x80000000;
1521 addend -= 0x80000000;
1526 /* The existing addend includes the difference between the
1527 gp of the input BFD and the address in the input BFD.
1528 We want to change this to the difference between the
1529 final GP and the final address. */
1531 - ecoff_data (input_bfd)->gp
1532 + input_section->vma
1533 - (input_section->output_section->vma
1534 + input_section->output_offset));
1536 /* Change the instructions, accounting for the sign
1537 extension, and write them out. */
1538 if (addend & 0x8000)
1540 insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
1541 insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
1543 bfd_put_32 (input_bfd, (bfd_vma) insn1,
1544 contents + r_vaddr - input_section->vma);
1545 bfd_put_32 (input_bfd, (bfd_vma) insn2,
1546 contents + r_vaddr - input_section->vma + r_symndx);
1552 case ALPHA_R_OP_PUSH:
1553 case ALPHA_R_OP_PSUB:
1554 case ALPHA_R_OP_PRSHIFT:
1555 /* Manipulate values on the reloc evaluation stack. The
1556 r_vaddr field is not an address in input_section, it is
1557 the current value (including any addend) of the object
1563 s = symndx_to_section[r_symndx];
1564 if (s == (asection *) NULL)
1566 addend = s->output_section->vma + s->output_offset - s->vma;
1570 struct ecoff_link_hash_entry *h;
1572 h = sym_hashes[r_symndx];
1573 if (h == (struct ecoff_link_hash_entry *) NULL)
1576 if (! info->relocateable)
1578 if (h->root.type == bfd_link_hash_defined)
1579 addend = (h->root.u.def.value
1580 + h->root.u.def.section->output_section->vma
1581 + h->root.u.def.section->output_offset);
1584 /* Note that we pass the address as 0, since we
1585 do not have a meaningful number for the
1586 location within the section that is being
1588 if (! ((*info->callbacks->undefined_symbol)
1589 (info, h->root.root.string, input_bfd,
1590 input_section, (bfd_vma) 0)))
1597 if (h->root.type != bfd_link_hash_defined
1600 /* This symbol is not being written out. Pass
1601 the address as 0, as with undefined_symbol,
1603 if (! ((*info->callbacks->unattached_reloc)
1604 (info, h->root.root.string, input_bfd,
1605 input_section, (bfd_vma) 0)))
1609 addend = alpha_convert_external_reloc (output_bfd, info,
1617 if (info->relocateable)
1619 /* Adjust r_vaddr by the addend. */
1620 bfd_h_put_64 (input_bfd, addend,
1621 (bfd_byte *) ext_rel->r_vaddr);
1627 case ALPHA_R_OP_PUSH:
1628 if (tos >= RELOC_STACKSIZE)
1630 stack[tos++] = addend;
1633 case ALPHA_R_OP_PSUB:
1636 stack[tos - 1] -= addend;
1639 case ALPHA_R_OP_PRSHIFT:
1642 stack[tos - 1] >>= addend;
1647 adjust_addrp = false;
1650 case ALPHA_R_OP_STORE:
1651 /* Store a value from the reloc stack into a bitfield. If
1652 we are generating relocateable output, all we do is
1653 adjust the address of the reloc. */
1654 if (! info->relocateable)
1661 /* FIXME: I don't know what kind of overflow checking,
1662 if any, should be done here. */
1663 val = bfd_get_64 (input_bfd,
1664 contents + r_vaddr - input_section->vma);
1665 val &=~ (((1 << r_size) - 1) << r_offset);
1666 val |= (stack[--tos] & ((1 << r_size) - 1)) << r_offset;
1667 bfd_put_64 (input_bfd, val,
1668 contents + r_vaddr - input_section->vma);
1672 case ALPHA_R_GPVALUE:
1673 /* I really don't know if this does the right thing. */
1674 gp = ecoff_data (input_bfd)->gp + r_symndx;
1675 gp_undefined = false;
1681 reloc_howto_type *howto;
1682 struct ecoff_link_hash_entry *h = NULL;
1685 bfd_reloc_status_type r;
1687 /* Perform a relocation. */
1689 howto = &alpha_howto_table[r_type];
1693 h = sym_hashes[r_symndx];
1694 /* If h is NULL, that means that there is a reloc
1695 against an external symbol which we thought was just
1696 a debugging symbol. This should not happen. */
1697 if (h == (struct ecoff_link_hash_entry *) NULL)
1702 if (r_symndx >= NUM_RELOC_SECTIONS)
1705 s = symndx_to_section[r_symndx];
1707 if (s == (asection *) NULL)
1711 if (info->relocateable)
1713 /* We are generating relocateable output, and must
1714 convert the existing reloc. */
1717 if (h->root.type != bfd_link_hash_defined
1720 /* This symbol is not being written out. */
1721 if (! ((*info->callbacks->unattached_reloc)
1722 (info, h->root.root.string, input_bfd,
1723 input_section, r_vaddr - input_section->vma)))
1727 relocation = alpha_convert_external_reloc (output_bfd,
1735 /* This is a relocation against a section. Adjust
1736 the value by the amount the section moved. */
1737 relocation = (s->output_section->vma
1742 /* If this is PC relative, the existing object file
1743 appears to already have the reloc worked out. We
1744 must subtract out the old value and add in the new
1746 if (howto->pc_relative)
1747 relocation -= (input_section->output_section->vma
1748 + input_section->output_offset
1749 - input_section->vma);
1751 /* Put in any addend. */
1752 relocation += addend;
1754 /* Adjust the contents. */
1755 r = _bfd_relocate_contents (howto, input_bfd, relocation,
1758 - input_section->vma));
1762 /* We are producing a final executable. */
1765 /* This is a reloc against a symbol. */
1766 if (h->root.type == bfd_link_hash_defined)
1770 hsec = h->root.u.def.section;
1771 relocation = (h->root.u.def.value
1772 + hsec->output_section->vma
1773 + hsec->output_offset);
1777 if (! ((*info->callbacks->undefined_symbol)
1778 (info, h->root.root.string, input_bfd,
1780 r_vaddr - input_section->vma)))
1787 /* This is a reloc against a section. */
1788 relocation = (s->output_section->vma
1792 /* Adjust a PC relative relocation by removing the
1793 reference to the original source section. */
1794 if (howto->pc_relative)
1795 relocation += input_section->vma;
1798 r = _bfd_final_link_relocate (howto,
1802 r_vaddr - input_section->vma,
1807 if (r != bfd_reloc_ok)
1812 case bfd_reloc_outofrange:
1814 case bfd_reloc_overflow:
1819 name = sym_hashes[r_symndx]->root.root.string;
1821 name = bfd_section_name (input_bfd,
1822 symndx_to_section[r_symndx]);
1823 if (! ((*info->callbacks->reloc_overflow)
1824 (info, name, alpha_howto_table[r_type].name,
1825 (bfd_vma) 0, input_bfd, input_section,
1826 r_vaddr - input_section->vma)))
1834 if (info->relocateable && adjust_addrp)
1836 /* Change the address of the relocation. */
1837 bfd_h_put_64 (input_bfd,
1838 (input_section->output_section->vma
1839 + input_section->output_offset
1840 - input_section->vma
1842 (bfd_byte *) ext_rel->r_vaddr);
1845 if (gp_usedp && gp_undefined)
1847 if (! ((*info->callbacks->reloc_dangerous)
1848 (info, "GP relative relocation when GP not defined",
1849 input_bfd, input_section, r_vaddr - input_section->vma)))
1851 /* Only give the error once per link. */
1852 ecoff_data (output_bfd)->gp = gp = 4;
1853 gp_undefined = false;
1863 #define ecoff_core_file_p _bfd_dummy_target
1864 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
1865 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1866 #define ecoff_core_file_matches_executable_p \
1867 _bfd_dummy_core_file_matches_executable_p
1869 /* This is the ECOFF backend structure. The backend field of the
1870 target vector points to this. */
1872 static const struct ecoff_backend_data alpha_ecoff_backend_data =
1874 /* COFF backend structure. */
1876 (void (*) PARAMS ((bfd *,PTR,int,int,int,int,PTR))) bfd_void, /* aux_in */
1877 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
1878 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
1879 (unsigned (*) PARAMS ((bfd *,PTR,int,int,int,int,PTR)))bfd_void,/*aux_out*/
1880 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
1881 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
1882 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* reloc_out */
1883 alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
1884 alpha_ecoff_swap_scnhdr_out,
1885 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
1886 alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
1887 alpha_ecoff_swap_scnhdr_in, alpha_ecoff_bad_format_hook,
1888 ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
1889 ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
1890 ecoff_slurp_symbol_table, NULL, NULL
1892 /* Supported architecture. */
1894 /* Initial portion of armap string. */
1896 /* The page boundary used to align sections in a demand-paged
1897 executable file. E.g., 0x1000. */
1899 /* True if the .rdata section is part of the text segment, as on the
1900 Alpha. False if .rdata is part of the data segment, as on the
1903 /* Bitsize of constructor entries. */
1905 /* Reloc to use for constructor entries. */
1906 &alpha_howto_table[ALPHA_R_REFQUAD],
1908 /* Symbol table magic number. */
1910 /* Alignment of debugging information. E.g., 4. */
1912 /* Sizes of external symbolic information. */
1913 sizeof (struct hdr_ext),
1914 sizeof (struct dnr_ext),
1915 sizeof (struct pdr_ext),
1916 sizeof (struct sym_ext),
1917 sizeof (struct opt_ext),
1918 sizeof (struct fdr_ext),
1919 sizeof (struct rfd_ext),
1920 sizeof (struct ext_ext),
1921 /* Functions to swap in external symbolic data. */
1930 /* Functions to swap out external symbolic data. */
1940 /* External reloc size. */
1942 /* Reloc swapping functions. */
1943 alpha_ecoff_swap_reloc_in,
1944 alpha_ecoff_swap_reloc_out,
1945 /* Backend reloc tweaking. */
1946 alpha_adjust_reloc_in,
1947 alpha_adjust_reloc_out,
1948 /* Relocate section contents while linking. */
1949 alpha_relocate_section
1952 /* Looking up a reloc type is Alpha specific. */
1953 #define ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
1955 /* So is getting relocated section contents. */
1956 #define ecoff_bfd_get_relocated_section_contents \
1957 alpha_ecoff_get_relocated_section_contents
1959 bfd_target ecoffalpha_little_vec =
1961 "ecoff-littlealpha", /* name */
1962 bfd_target_ecoff_flavour,
1963 false, /* data byte order is little */
1964 false, /* header byte order is little */
1966 (HAS_RELOC | EXEC_P | /* object flags */
1967 HAS_LINENO | HAS_DEBUG |
1968 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1970 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
1972 0, /* leading underscore */
1973 ' ', /* ar_pad_char */
1974 15, /* ar_max_namelen */
1975 4, /* minimum alignment power */
1976 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1977 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1978 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
1979 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1980 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1981 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
1983 {_bfd_dummy_target, alpha_ecoff_object_p, /* bfd_check_format */
1984 ecoff_archive_p, _bfd_dummy_target},
1985 {bfd_false, ecoff_mkobject, /* bfd_set_format */
1986 _bfd_generic_mkarchive, bfd_false},
1987 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
1988 _bfd_write_archive_contents, bfd_false},
1990 (PTR) &alpha_ecoff_backend_data