1 /* BFD back-end for ALPHA Extended-Coff files.
2 Copyright 1993 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 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
115 from smaller values. Start with zero, widen, *then* decrement. */
116 #define MINUS_ONE (((bfd_vma)0) - 1)
118 static reloc_howto_type alpha_howto_table[] =
120 /* Reloc type 0 is ignored by itself. However, it appears after a
121 GPDISP reloc to identify the location where the low order 16 bits
122 of the gp register are loaded. */
123 HOWTO (ALPHA_R_IGNORE, /* type */
125 0, /* size (0 = byte, 1 = short, 2 = long) */
127 true, /* pc_relative */
129 complain_overflow_dont, /* complain_on_overflow */
130 0, /* special_function */
132 false, /* partial_inplace */
135 true), /* pcrel_offset */
137 /* A 32 bit reference to a symbol. */
138 HOWTO (ALPHA_R_REFLONG, /* type */
140 2, /* size (0 = byte, 1 = short, 2 = long) */
142 false, /* pc_relative */
144 complain_overflow_bitfield, /* complain_on_overflow */
145 0, /* special_function */
146 "REFLONG", /* name */
147 true, /* partial_inplace */
148 0xffffffff, /* src_mask */
149 0xffffffff, /* dst_mask */
150 false), /* pcrel_offset */
152 /* A 64 bit reference to a symbol. */
153 HOWTO (ALPHA_R_REFQUAD, /* type */
155 4, /* size (0 = byte, 1 = short, 2 = long) */
157 false, /* pc_relative */
159 complain_overflow_bitfield, /* complain_on_overflow */
160 0, /* special_function */
161 "REFQUAD", /* name */
162 true, /* partial_inplace */
163 MINUS_ONE, /* src_mask */
164 MINUS_ONE, /* dst_mask */
165 false), /* pcrel_offset */
167 /* A 32 bit GP relative offset. This is just like REFLONG except
168 that when the value is used the value of the gp register will be
170 HOWTO (ALPHA_R_GPREL32, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 false, /* pc_relative */
176 complain_overflow_bitfield, /* complain_on_overflow */
177 0, /* special_function */
178 "GPREL32", /* name */
179 true, /* partial_inplace */
180 0xffffffff, /* src_mask */
181 0xffffffff, /* dst_mask */
182 false), /* pcrel_offset */
184 /* Used for an instruction that refers to memory off the GP
185 register. The offset is 16 bits of the 32 bit instruction. This
186 reloc always seems to be against the .lita section. */
187 HOWTO (ALPHA_R_LITERAL, /* type */
189 2, /* size (0 = byte, 1 = short, 2 = long) */
191 false, /* pc_relative */
193 complain_overflow_signed, /* complain_on_overflow */
194 0, /* special_function */
195 "LITERAL", /* name */
196 true, /* partial_inplace */
197 0xffff, /* src_mask */
198 0xffff, /* dst_mask */
199 false), /* pcrel_offset */
201 /* This reloc only appears immediately following a LITERAL reloc.
202 It identifies a use of the literal. It seems that the linker can
203 use this to eliminate a portion of the .lita section. The symbol
204 index is special: 1 means the literal address is in the base
205 register of a memory format instruction; 2 means the literal
206 address is in the byte offset register of a byte-manipulation
207 instruction; 3 means the literal address is in the target
208 register of a jsr instruction. This does not actually do any
210 HOWTO (ALPHA_R_LITUSE, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 false, /* pc_relative */
216 complain_overflow_dont, /* complain_on_overflow */
217 0, /* special_function */
219 false, /* partial_inplace */
222 false), /* pcrel_offset */
224 /* Load the gp register. This is always used for a ldah instruction
225 which loads the upper 16 bits of the gp register. The next reloc
226 will be an IGNORE reloc which identifies the location of the lda
227 instruction which loads the lower 16 bits. The symbol index of
228 the GPDISP instruction appears to actually be the number of bytes
229 between the ldah and lda instructions. This gives two different
230 ways to determine where the lda instruction is; I don't know why
231 both are used. The value to use for the relocation is the
232 difference between the GP value and the current location; the
233 load will always be done against a register holding the current
235 HOWTO (ALPHA_R_GPDISP, /* type */
237 2, /* size (0 = byte, 1 = short, 2 = long) */
239 true, /* pc_relative */
241 complain_overflow_dont, /* complain_on_overflow */
242 0, /* special_function */
244 true, /* partial_inplace */
245 0xffff, /* src_mask */
246 0xffff, /* dst_mask */
247 true), /* pcrel_offset */
249 /* A 21 bit branch. The native assembler generates these for
250 branches within the text segment, and also fills in the PC
251 relative offset in the instruction. */
252 HOWTO (ALPHA_R_BRADDR, /* type */
254 2, /* size (0 = byte, 1 = short, 2 = long) */
256 true, /* pc_relative */
258 complain_overflow_signed, /* complain_on_overflow */
259 0, /* special_function */
261 true, /* partial_inplace */
262 0x1fffff, /* src_mask */
263 0x1fffff, /* dst_mask */
264 false), /* pcrel_offset */
266 /* A hint for a jump to a register. */
267 HOWTO (ALPHA_R_HINT, /* type */
269 2, /* size (0 = byte, 1 = short, 2 = long) */
271 true, /* pc_relative */
273 complain_overflow_dont, /* complain_on_overflow */
274 0, /* special_function */
276 true, /* partial_inplace */
277 0x3fff, /* src_mask */
278 0x3fff, /* dst_mask */
279 false), /* pcrel_offset */
281 /* 16 bit PC relative offset. */
282 HOWTO (ALPHA_R_SREL16, /* type */
284 1, /* size (0 = byte, 1 = short, 2 = long) */
286 true, /* pc_relative */
288 complain_overflow_signed, /* complain_on_overflow */
289 0, /* special_function */
291 true, /* partial_inplace */
292 0xffff, /* src_mask */
293 0xffff, /* dst_mask */
294 false), /* pcrel_offset */
296 /* 32 bit PC relative offset. */
297 HOWTO (ALPHA_R_SREL32, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 true, /* pc_relative */
303 complain_overflow_signed, /* complain_on_overflow */
304 0, /* special_function */
306 true, /* partial_inplace */
307 0xffffffff, /* src_mask */
308 0xffffffff, /* dst_mask */
309 false), /* pcrel_offset */
311 /* A 64 bit PC relative offset. */
312 HOWTO (ALPHA_R_SREL64, /* type */
314 4, /* size (0 = byte, 1 = short, 2 = long) */
316 true, /* pc_relative */
318 complain_overflow_signed, /* complain_on_overflow */
319 0, /* special_function */
321 true, /* partial_inplace */
322 MINUS_ONE, /* src_mask */
323 MINUS_ONE, /* dst_mask */
324 false), /* pcrel_offset */
326 /* Push a value on the reloc evaluation stack. */
327 HOWTO (ALPHA_R_OP_PUSH, /* type */
329 0, /* size (0 = byte, 1 = short, 2 = long) */
331 false, /* pc_relative */
333 complain_overflow_dont, /* complain_on_overflow */
334 0, /* special_function */
335 "OP_PUSH", /* name */
336 false, /* partial_inplace */
339 false), /* pcrel_offset */
341 /* Store the value from the stack at the given address. Store it in
342 a bitfield of size r_size starting at bit position r_offset. */
343 HOWTO (ALPHA_R_OP_STORE, /* type */
345 4, /* size (0 = byte, 1 = short, 2 = long) */
347 false, /* pc_relative */
349 complain_overflow_dont, /* complain_on_overflow */
350 0, /* special_function */
351 "OP_STORE", /* name */
352 false, /* partial_inplace */
354 MINUS_ONE, /* dst_mask */
355 false), /* pcrel_offset */
357 /* Subtract the reloc address from the value on the top of the
359 HOWTO (ALPHA_R_OP_PSUB, /* type */
361 0, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_dont, /* complain_on_overflow */
366 0, /* special_function */
367 "OP_PSUB", /* name */
368 false, /* partial_inplace */
371 false), /* pcrel_offset */
373 /* Shift the value on the top of the relocation stack right by the
375 HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
377 0, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_dont, /* complain_on_overflow */
382 0, /* special_function */
383 "OP_PRSHIFT", /* name */
384 false, /* partial_inplace */
387 false), /* pcrel_offset */
389 /* Adjust the GP value for a new range in the object file. */
390 HOWTO (ALPHA_R_GPVALUE, /* type */
392 0, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_dont, /* complain_on_overflow */
397 0, /* special_function */
398 "GPVALUE", /* name */
399 false, /* partial_inplace */
402 false) /* pcrel_offset */
405 /* Recognize an Alpha ECOFF file. */
408 alpha_ecoff_object_p (abfd)
411 static bfd_target *ret;
413 ret = coff_object_p (abfd);
415 if (ret != (bfd_target *) NULL)
419 /* Alpha ECOFF has a .pdata section. The lnnoptr field of the
420 .pdata section is the number of entries it contains. Each
421 entry takes up 8 bytes. The number of entries is required
422 since the section is aligned to a 16 byte boundary. When we
423 link .pdata sections together, we do not want to include the
424 alignment bytes. We handle this on input by faking the size
425 of the .pdata section to remove the unwanted alignment bytes.
426 On output we will set the lnnoptr field and force the
428 sec = bfd_get_section_by_name (abfd, _PDATA);
429 if (sec != (asection *) NULL)
433 size = sec->line_filepos * 8;
434 BFD_ASSERT (size == bfd_section_size (abfd, sec)
435 || size + 8 == bfd_section_size (abfd, sec));
436 if (! bfd_set_section_size (abfd, sec, size))
444 /* See whether the magic number matches. */
447 alpha_ecoff_bad_format_hook (abfd, filehdr)
451 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
453 if (ALPHA_ECOFF_BADMAG (*internal_f))
459 /* Reloc handling. */
461 /* Swap a reloc in. */
464 alpha_ecoff_swap_reloc_in (abfd, ext_ptr, intern)
467 struct internal_reloc *intern;
469 const RELOC *ext = (RELOC *) ext_ptr;
471 intern->r_vaddr = bfd_h_get_64 (abfd, (bfd_byte *) ext->r_vaddr);
472 intern->r_symndx = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_symndx);
474 BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false);
476 intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
477 >> RELOC_BITS0_TYPE_SH_LITTLE);
478 intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
479 intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
480 >> RELOC_BITS1_OFFSET_SH_LITTLE);
481 /* Ignored the reserved bits. */
482 intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
483 >> RELOC_BITS3_SIZE_SH_LITTLE);
485 if (intern->r_type == ALPHA_R_LITUSE
486 || intern->r_type == ALPHA_R_GPDISP)
488 /* Handle the LITUSE and GPDISP relocs specially. Its symndx
489 value is not actually a symbol index, but is instead a
490 special code. We put the code in the r_size field, and
491 clobber the symndx. */
492 if (intern->r_size != 0)
494 intern->r_size = intern->r_symndx;
495 intern->r_symndx = RELOC_SECTION_NONE;
497 else if (intern->r_type == ALPHA_R_IGNORE)
499 /* The IGNORE reloc generally follows a GPDISP reloc, and is
500 against the .lita section. The section is irrelevant. */
501 if (! intern->r_extern &&
502 (intern->r_symndx == RELOC_SECTION_NONE
503 || intern->r_symndx == RELOC_SECTION_ABS))
505 if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
506 intern->r_symndx = RELOC_SECTION_NONE;
510 /* Swap a reloc out. */
513 alpha_ecoff_swap_reloc_out (abfd, intern, dst)
515 const struct internal_reloc *intern;
518 RELOC *ext = (RELOC *) dst;
522 /* Undo the hackery done in swap_reloc_in. */
523 if (intern->r_type == ALPHA_R_LITUSE
524 || intern->r_type == ALPHA_R_GPDISP)
526 symndx = intern->r_size;
529 else if (intern->r_type == ALPHA_R_IGNORE
530 && ! intern->r_extern
531 && intern->r_symndx == RELOC_SECTION_NONE)
533 symndx = RELOC_SECTION_LITA;
534 size = intern->r_size;
538 symndx = intern->r_symndx;
539 size = intern->r_size;
542 BFD_ASSERT (intern->r_extern
543 || (intern->r_symndx >= 0 && intern->r_symndx <= 14));
545 bfd_h_put_64 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
546 bfd_h_put_32 (abfd, symndx, (bfd_byte *) ext->r_symndx);
548 BFD_ASSERT (abfd->xvec->header_byteorder_big_p == false);
550 ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE)
551 & RELOC_BITS0_TYPE_LITTLE);
552 ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0)
553 | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE)
554 & RELOC_BITS1_OFFSET_LITTLE));
556 ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE)
557 & RELOC_BITS3_SIZE_LITTLE);
560 /* Finish canonicalizing a reloc. Part of this is generic to all
561 ECOFF targets, and that part is in ecoff.c. The rest is done in
562 this backend routine. It must fill in the howto field. */
565 alpha_adjust_reloc_in (abfd, intern, rptr)
567 const struct internal_reloc *intern;
570 if (intern->r_type > ALPHA_R_GPVALUE)
573 switch (intern->r_type)
579 /* The PC relative relocs do not seem to use the section VMA as
580 a negative addend. */
584 case ALPHA_R_GPREL32:
585 case ALPHA_R_LITERAL:
586 /* Copy the gp value for this object file into the addend, to
587 ensure that we are not confused by the linker. */
588 if (! intern->r_extern)
589 rptr->addend += ecoff_data (abfd)->gp;
594 /* The LITUSE and GPDISP relocs do not use a symbol, or an
595 addend, but they do use a special code. Put this code in the
597 rptr->addend = intern->r_size;
600 case ALPHA_R_OP_STORE:
601 /* The STORE reloc needs the size and offset fields. We store
602 them in the addend. */
603 BFD_ASSERT (intern->r_offset <= 256 && intern->r_size <= 256);
604 rptr->addend = (intern->r_offset << 8) + intern->r_size;
607 case ALPHA_R_OP_PUSH:
608 case ALPHA_R_OP_PSUB:
609 case ALPHA_R_OP_PRSHIFT:
610 /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
611 address. I believe that the address supplied is really an
613 rptr->addend = intern->r_vaddr;
616 case ALPHA_R_GPVALUE:
617 /* Set the addend field to the new GP value. */
618 rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp;
622 /* If the type is ALPHA_R_IGNORE, make sure this is a reference
623 to the absolute section so that the reloc is ignored. For
624 some reason the address of this reloc type is not adjusted by
625 the section vma. We record the gp value for this object file
626 here, for convenience when doing the GPDISP relocation. */
627 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
628 rptr->address = intern->r_vaddr;
629 rptr->addend = ecoff_data (abfd)->gp;
636 rptr->howto = &alpha_howto_table[intern->r_type];
639 /* When writing out a reloc we need to pull some values back out of
640 the addend field into the reloc. This is roughly the reverse of
641 alpha_adjust_reloc_in, except that there are several changes we do
645 alpha_adjust_reloc_out (abfd, rel, intern)
648 struct internal_reloc *intern;
650 switch (intern->r_type)
654 intern->r_size = rel->addend;
657 case ALPHA_R_OP_STORE:
658 intern->r_size = rel->addend & 0xff;
659 intern->r_offset = (rel->addend >> 8) & 0xff;
662 case ALPHA_R_OP_PUSH:
663 case ALPHA_R_OP_PSUB:
664 case ALPHA_R_OP_PRSHIFT:
665 intern->r_vaddr = rel->addend;
669 intern->r_vaddr = rel->address;
670 if (intern->r_symndx == RELOC_SECTION_ABS)
671 intern->r_symndx = RELOC_SECTION_NONE;
679 /* The size of the stack for the relocation evaluator. */
680 #define RELOC_STACKSIZE (10)
682 /* Alpha ECOFF relocs have a built in expression evaluator as well as
683 other interdependencies. Rather than use a bunch of special
684 functions and global variables, we use a single routine to do all
685 the relocation for a section. I haven't yet worked out how the
686 assembler is going to handle this. */
689 alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
690 data, relocateable, symbols)
692 struct bfd_link_info *link_info;
693 struct bfd_link_order *link_order;
695 boolean relocateable;
698 bfd *input_bfd = link_order->u.indirect.section->owner;
699 asection *input_section = link_order->u.indirect.section;
700 size_t reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section);
701 arelent **reloc_vector = (arelent **) alloca (reloc_size);
702 bfd *output_bfd = relocateable ? abfd : (bfd *) NULL;
704 boolean gp_undefined;
705 bfd_vma stack[RELOC_STACKSIZE];
708 if (! bfd_get_section_contents (input_bfd, input_section, data,
709 (file_ptr) 0, input_section->_raw_size))
712 /* The section size is not going to change. */
713 input_section->_cooked_size = input_section->_raw_size;
714 input_section->reloc_done = true;
716 if (bfd_canonicalize_reloc (input_bfd, input_section, reloc_vector,
721 /* Get the GP value for the output BFD. */
722 gp_undefined = false;
723 if (ecoff_data (abfd)->gp == 0)
725 if (relocateable != false)
730 /* Make up a value. */
732 for (sec = abfd->sections; sec != NULL; sec = sec->next)
735 && (strcmp (sec->name, ".sbss") == 0
736 || strcmp (sec->name, ".sdata") == 0
737 || strcmp (sec->name, ".lit4") == 0
738 || strcmp (sec->name, ".lit8") == 0
739 || strcmp (sec->name, ".lita") == 0))
742 ecoff_data (abfd)->gp = lo + 0x8000;
746 struct bfd_link_hash_entry *h;
748 h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false,
750 if (h == (struct bfd_link_hash_entry *) NULL
751 || h->type != bfd_link_hash_defined)
754 ecoff_data (abfd)->gp = (h->u.def.value
755 + h->u.def.section->output_section->vma
756 + h->u.def.section->output_offset);
759 gp = ecoff_data (abfd)->gp;
761 for (; *reloc_vector != (arelent *) NULL; reloc_vector++)
764 bfd_reloc_status_type r;
769 switch (rel->howto->type)
772 rel->address += input_section->output_offset;
775 case ALPHA_R_REFLONG:
776 case ALPHA_R_REFQUAD:
783 && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
785 rel->address += input_section->output_offset;
788 r = bfd_perform_relocation (input_bfd, rel, data, input_section,
792 case ALPHA_R_GPREL32:
793 /* This relocation is used in a switch table. It is a 32
794 bit offset from the current GP value. We must adjust it
795 by the different between the original GP value and the
796 current GP value. The original GP value is stored in the
797 addend. We adjust the addend and let
798 bfd_perform_relocation finish the job. */
800 r = bfd_perform_relocation (input_bfd, rel, data, input_section,
802 if (r == bfd_reloc_ok && gp_undefined)
804 r = bfd_reloc_dangerous;
805 err = (char *) "GP relative relocation used when GP not defined";
809 case ALPHA_R_LITERAL:
810 /* This is a reference to a literal value, generally
811 (always?) in the .lita section. This is a 16 bit GP
812 relative relocation. Sometimes the subsequent reloc is a
813 LITUSE reloc, which indicates how this reloc is used.
814 This sometimes permits rewriting the two instructions
815 referred to by the LITERAL and the LITUSE into different
816 instructions which do not refer to .lita. This can save
817 a memory reference, and permits removing a value from
818 .lita thus saving GP relative space.
820 We do not these optimizations. To do them we would need
821 to arrange to link the .lita section first, so that by
822 the time we got here we would know the final values to
823 use. This would not be particularly difficult, but it is
824 not currently implemented. */
829 /* I believe that the LITERAL reloc will only apply to a
830 ldq instruction, so check my assumption. */
831 insn = bfd_get_32 (input_bfd, data + rel->address);
832 BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29);
835 r = bfd_perform_relocation (input_bfd, rel, data, input_section,
837 if (r == bfd_reloc_ok && gp_undefined)
839 r = bfd_reloc_dangerous;
841 (char *) "GP relative relocation used when GP not defined";
847 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
848 does not cause anything to happen, itself. */
849 rel->address += input_section->output_offset;
853 /* This marks the ldah of an ldah/lda pair which loads the
854 gp register with the difference of the gp value and the
855 current location. The second of the pair is r_size bytes
856 ahead, and is marked with an ALPHA_R_IGNORE reloc. */
858 unsigned long insn1, insn2;
861 BFD_ASSERT (reloc_vector[1] != NULL
862 && reloc_vector[1]->howto->type == ALPHA_R_IGNORE
863 && (rel->address + rel->addend
864 == reloc_vector[1]->address));
866 /* Get the two instructions. */
867 insn1 = bfd_get_32 (input_bfd, data + rel->address);
868 insn2 = bfd_get_32 (input_bfd, data + rel->address + rel->addend);
870 BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
871 BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
873 /* Get the existing addend. We must account for the sign
874 extension done by lda and ldah. */
875 addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
878 addend -= 0x80000000;
879 addend -= 0x80000000;
884 /* The existing addend includes the different between the
885 gp of the input BFD and the address in the input BFD.
886 Subtract this out. */
887 addend -= (reloc_vector[1]->addend
888 - (input_section->vma + rel->address));
890 /* Now add in the final gp value, and subtract out the
893 - (input_section->output_section->vma
894 + input_section->output_offset
897 /* Change the instructions, accounting for the sign
898 extension, and write them out. */
901 insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
902 insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
904 bfd_put_32 (input_bfd, (bfd_vma) insn1, data + rel->address);
905 bfd_put_32 (input_bfd, (bfd_vma) insn2,
906 data + rel->address + rel->addend);
908 rel->address += input_section->output_offset;
912 case ALPHA_R_OP_PUSH:
913 /* Push a value on the reloc evaluation stack. */
920 rel->address += input_section->output_offset;
924 /* Figure out the relocation of this symbol. */
925 symbol = *rel->sym_ptr_ptr;
927 if (symbol->section == &bfd_und_section)
928 r = bfd_reloc_undefined;
930 if (bfd_is_com_section (symbol->section))
933 relocation = symbol->value;
934 relocation += symbol->section->output_section->vma;
935 relocation += symbol->section->output_offset;
936 relocation += rel->addend;
938 if (tos >= RELOC_STACKSIZE)
941 stack[tos++] = relocation;
945 case ALPHA_R_OP_STORE:
946 /* Store a value from the reloc stack into a bitfield. */
953 rel->address += input_section->output_offset;
960 /* The offset and size for this reloc are encoded into the
961 addend field by alpha_adjust_reloc_in. */
962 offset = (rel->addend >> 8) & 0xff;
963 size = rel->addend & 0xff;
965 val = bfd_get_64 (abfd, data + rel->address);
966 val &=~ (((1 << size) - 1) << offset);
967 val |= (stack[--tos] & ((1 << size) - 1)) << offset;
968 bfd_put_64 (abfd, val, data + rel->address);
972 case ALPHA_R_OP_PSUB:
973 /* Subtract a value from the top of the stack. */
980 rel->address += input_section->output_offset;
984 /* Figure out the relocation of this symbol. */
985 symbol = *rel->sym_ptr_ptr;
987 if (symbol->section == &bfd_und_section)
988 r = bfd_reloc_undefined;
990 if (bfd_is_com_section (symbol->section))
993 relocation = symbol->value;
994 relocation += symbol->section->output_section->vma;
995 relocation += symbol->section->output_offset;
996 relocation += rel->addend;
1001 stack[tos - 1] -= relocation;
1005 case ALPHA_R_OP_PRSHIFT:
1006 /* Shift the value on the top of the stack. */
1013 rel->address += input_section->output_offset;
1017 /* Figure out the relocation of this symbol. */
1018 symbol = *rel->sym_ptr_ptr;
1020 if (symbol->section == &bfd_und_section)
1021 r = bfd_reloc_undefined;
1023 if (bfd_is_com_section (symbol->section))
1026 relocation = symbol->value;
1027 relocation += symbol->section->output_section->vma;
1028 relocation += symbol->section->output_offset;
1029 relocation += rel->addend;
1034 stack[tos - 1] >>= relocation;
1038 case ALPHA_R_GPVALUE:
1039 /* I really don't know if this does the right thing. */
1041 gp_undefined = false;
1050 asection *os = input_section->output_section;
1052 /* A partial link, so keep the relocs. */
1053 os->orelocation[os->reloc_count] = rel;
1057 if (r != bfd_reloc_ok)
1061 case bfd_reloc_undefined:
1062 if (! ((*link_info->callbacks->undefined_symbol)
1063 (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
1064 input_bfd, input_section, rel->address)))
1067 case bfd_reloc_dangerous:
1068 if (! ((*link_info->callbacks->reloc_dangerous)
1069 (link_info, err, input_bfd, input_section,
1073 case bfd_reloc_overflow:
1074 if (! ((*link_info->callbacks->reloc_overflow)
1075 (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr),
1076 rel->howto->name, rel->addend, input_bfd,
1077 input_section, rel->address)))
1080 case bfd_reloc_outofrange:
1094 /* Get the howto structure for a generic reloc type. */
1096 static CONST struct reloc_howto_struct *
1097 alpha_bfd_reloc_type_lookup (abfd, code)
1099 bfd_reloc_code_real_type code;
1106 alpha_type = ALPHA_R_REFLONG;
1109 alpha_type = ALPHA_R_REFQUAD;
1111 case BFD_RELOC_GPREL32:
1112 alpha_type = ALPHA_R_GPREL32;
1114 case BFD_RELOC_ALPHA_LITERAL:
1115 alpha_type = ALPHA_R_LITERAL;
1117 case BFD_RELOC_ALPHA_LITUSE:
1118 alpha_type = ALPHA_R_LITUSE;
1120 case BFD_RELOC_ALPHA_GPDISP_HI16:
1121 alpha_type = ALPHA_R_GPDISP;
1123 case BFD_RELOC_ALPHA_GPDISP_LO16:
1124 alpha_type = ALPHA_R_IGNORE;
1126 case BFD_RELOC_23_PCREL_S2:
1127 alpha_type = ALPHA_R_BRADDR;
1129 case BFD_RELOC_ALPHA_HINT:
1130 alpha_type = ALPHA_R_HINT;
1132 case BFD_RELOC_16_PCREL:
1133 alpha_type = ALPHA_R_SREL16;
1135 case BFD_RELOC_32_PCREL:
1136 alpha_type = ALPHA_R_SREL32;
1138 case BFD_RELOC_64_PCREL:
1139 alpha_type = ALPHA_R_SREL64;
1143 alpha_type = ALPHA_R_OP_PUSH;
1146 alpha_type = ALPHA_R_OP_STORE;
1149 alpha_type = ALPHA_R_OP_PSUB;
1152 alpha_type = ALPHA_R_OP_PRSHIFT;
1155 alpha_type = ALPHA_R_GPVALUE;
1159 return (CONST struct reloc_howto_struct *) NULL;
1162 return &alpha_howto_table[alpha_type];
1165 /* A helper routine for alpha_relocate_section which converts an
1166 external reloc when generating relocateable output. Returns the
1167 relocation amount. */
1170 alpha_convert_external_reloc (output_bfd, info, input_bfd, ext_rel, h)
1172 struct bfd_link_info *info;
1174 struct external_reloc *ext_rel;
1175 struct ecoff_link_hash_entry *h;
1177 unsigned long r_symndx;
1180 BFD_ASSERT (info->relocateable);
1182 if (h->root.type == bfd_link_hash_defined)
1187 /* This symbol is defined in the output. Convert the reloc from
1188 being against the symbol to being against the section. */
1190 /* Clear the r_extern bit. */
1191 ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE;
1193 /* Compute a new r_symndx value. */
1194 hsec = h->root.u.def.section;
1195 name = bfd_get_section_name (output_bfd, hsec->output_section);
1201 if (strcmp (name, "*ABS*") == 0)
1202 r_symndx = RELOC_SECTION_ABS;
1205 if (strcmp (name, ".bss") == 0)
1206 r_symndx = RELOC_SECTION_BSS;
1209 if (strcmp (name, ".data") == 0)
1210 r_symndx = RELOC_SECTION_DATA;
1213 if (strcmp (name, ".fini") == 0)
1214 r_symndx = RELOC_SECTION_FINI;
1217 if (strcmp (name, ".init") == 0)
1218 r_symndx = RELOC_SECTION_INIT;
1221 if (strcmp (name, ".lita") == 0)
1222 r_symndx = RELOC_SECTION_LITA;
1223 else if (strcmp (name, ".lit8") == 0)
1224 r_symndx = RELOC_SECTION_LIT8;
1225 else if (strcmp (name, ".lit4") == 0)
1226 r_symndx = RELOC_SECTION_LIT4;
1229 if (strcmp (name, ".pdata") == 0)
1230 r_symndx = RELOC_SECTION_PDATA;
1233 if (strcmp (name, ".rdata") == 0)
1234 r_symndx = RELOC_SECTION_RDATA;
1237 if (strcmp (name, ".sdata") == 0)
1238 r_symndx = RELOC_SECTION_SDATA;
1239 else if (strcmp (name, ".sbss") == 0)
1240 r_symndx = RELOC_SECTION_SBSS;
1243 if (strcmp (name, ".text") == 0)
1244 r_symndx = RELOC_SECTION_TEXT;
1247 if (strcmp (name, ".xdata") == 0)
1248 r_symndx = RELOC_SECTION_XDATA;
1255 /* Add the section VMA and the symbol value. */
1256 relocation = (h->root.u.def.value
1257 + hsec->output_section->vma
1258 + hsec->output_offset);
1262 /* Change the symndx value to the right one for
1267 /* Caller must give an error. */
1273 /* Write out the new r_symndx value. */
1274 bfd_h_put_32 (input_bfd, (bfd_vma) r_symndx,
1275 (bfd_byte *) ext_rel->r_symndx);
1280 /* Relocate a section while linking an Alpha ECOFF file. This is
1281 quite similar to get_relocated_section_contents. Perhaps they
1282 could be combined somehow. */
1285 alpha_relocate_section (output_bfd, info, input_bfd, input_section,
1286 contents, external_relocs)
1288 struct bfd_link_info *info;
1290 asection *input_section;
1292 PTR external_relocs;
1294 asection **symndx_to_section;
1295 struct ecoff_link_hash_entry **sym_hashes;
1297 boolean gp_undefined;
1298 bfd_vma stack[RELOC_STACKSIZE];
1300 struct external_reloc *ext_rel;
1301 struct external_reloc *ext_rel_end;
1303 /* We keep a table mapping the symndx found in an internal reloc to
1304 the appropriate section. This is faster than looking up the
1305 section by name each time. */
1306 symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
1307 if (symndx_to_section == (asection **) NULL)
1309 symndx_to_section = ((asection **)
1310 bfd_alloc (input_bfd,
1312 * sizeof (asection *))));
1314 symndx_to_section[RELOC_SECTION_NONE] = NULL;
1315 symndx_to_section[RELOC_SECTION_TEXT] =
1316 bfd_get_section_by_name (input_bfd, ".text");
1317 symndx_to_section[RELOC_SECTION_RDATA] =
1318 bfd_get_section_by_name (input_bfd, ".rdata");
1319 symndx_to_section[RELOC_SECTION_DATA] =
1320 bfd_get_section_by_name (input_bfd, ".data");
1321 symndx_to_section[RELOC_SECTION_SDATA] =
1322 bfd_get_section_by_name (input_bfd, ".sdata");
1323 symndx_to_section[RELOC_SECTION_SBSS] =
1324 bfd_get_section_by_name (input_bfd, ".sbss");
1325 symndx_to_section[RELOC_SECTION_BSS] =
1326 bfd_get_section_by_name (input_bfd, ".bss");
1327 symndx_to_section[RELOC_SECTION_INIT] =
1328 bfd_get_section_by_name (input_bfd, ".init");
1329 symndx_to_section[RELOC_SECTION_LIT8] =
1330 bfd_get_section_by_name (input_bfd, ".lit8");
1331 symndx_to_section[RELOC_SECTION_LIT4] =
1332 bfd_get_section_by_name (input_bfd, ".lit4");
1333 symndx_to_section[RELOC_SECTION_XDATA] =
1334 bfd_get_section_by_name (input_bfd, ".xdata");
1335 symndx_to_section[RELOC_SECTION_PDATA] =
1336 bfd_get_section_by_name (input_bfd, ".pdata");
1337 symndx_to_section[RELOC_SECTION_FINI] =
1338 bfd_get_section_by_name (input_bfd, ".fini");
1339 symndx_to_section[RELOC_SECTION_LITA] =
1340 bfd_get_section_by_name (input_bfd, ".lita");
1341 symndx_to_section[RELOC_SECTION_ABS] = &bfd_abs_section;
1343 ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
1346 sym_hashes = ecoff_data (input_bfd)->sym_hashes;
1348 gp = ecoff_data (output_bfd)->gp;
1350 gp_undefined = true;
1352 gp_undefined = false;
1354 BFD_ASSERT (output_bfd->xvec->header_byteorder_big_p == false);
1355 BFD_ASSERT (input_bfd->xvec->header_byteorder_big_p == false);
1357 ext_rel = (struct external_reloc *) external_relocs;
1358 ext_rel_end = ext_rel + input_section->reloc_count;
1359 for (; ext_rel < ext_rel_end; ext_rel++)
1362 unsigned long r_symndx;
1368 boolean adjust_addrp;
1372 r_vaddr = bfd_h_get_64 (input_bfd, (bfd_byte *) ext_rel->r_vaddr);
1373 r_symndx = bfd_h_get_32 (input_bfd, (bfd_byte *) ext_rel->r_symndx);
1375 r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE)
1376 >> RELOC_BITS0_TYPE_SH_LITTLE);
1377 r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0;
1378 r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE)
1379 >> RELOC_BITS1_OFFSET_SH_LITTLE);
1380 /* Ignored the reserved bits. */
1381 r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE)
1382 >> RELOC_BITS3_SIZE_SH_LITTLE);
1385 adjust_addrp = true;
1394 case ALPHA_R_IGNORE:
1395 /* This reloc appears after a GPDISP reloc. It marks the
1396 position of the second instruction to be altered by the
1397 GPDISP reloc, but is not otherwise used for anything.
1398 For some reason, the address of the relocation does not
1399 appear to include the section VMA, unlike the other
1400 relocation types. */
1401 if (info->relocateable)
1402 bfd_h_put_64 (input_bfd,
1403 input_section->output_offset + r_vaddr,
1404 (bfd_byte *) ext_rel->r_vaddr);
1405 adjust_addrp = false;
1408 case ALPHA_R_REFLONG:
1409 case ALPHA_R_REFQUAD:
1410 case ALPHA_R_BRADDR:
1412 case ALPHA_R_SREL16:
1413 case ALPHA_R_SREL32:
1414 case ALPHA_R_SREL64:
1418 case ALPHA_R_GPREL32:
1419 /* This relocation is used in a switch table. It is a 32
1420 bit offset from the current GP value. We must adjust it
1421 by the different between the original GP value and the
1422 current GP value. */
1424 addend = ecoff_data (input_bfd)->gp - gp;
1428 case ALPHA_R_LITERAL:
1429 /* This is a reference to a literal value, generally
1430 (always?) in the .lita section. This is a 16 bit GP
1431 relative relocation. Sometimes the subsequent reloc is a
1432 LITUSE reloc, which indicates how this reloc is used.
1433 This sometimes permits rewriting the two instructions
1434 referred to by the LITERAL and the LITUSE into different
1435 instructions which do not refer to .lita. This can save
1436 a memory reference, and permits removing a value from
1437 .lita thus saving GP relative space.
1439 We do not these optimizations. To do them we would need
1440 to arrange to link the .lita section first, so that by
1441 the time we got here we would know the final values to
1442 use. This would not be particularly difficult, but it is
1443 not currently implemented. */
1445 /* I believe that the LITERAL reloc will only apply to a ldq
1446 instruction, so check my assumption. */
1447 BFD_ASSERT (((bfd_get_32 (input_bfd,
1448 contents + r_vaddr - input_section->vma)
1454 addend = ecoff_data (input_bfd)->gp - gp;
1458 case ALPHA_R_LITUSE:
1459 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
1460 does not cause anything to happen, itself. */
1463 case ALPHA_R_GPDISP:
1464 /* This marks the ldah of an ldah/lda pair which loads the
1465 gp register with the difference of the gp value and the
1466 current location. The second of the pair is r_symndx
1467 bytes ahead, and is also marked with an ALPHA_R_IGNORE
1470 unsigned long insn1, insn2;
1472 BFD_ASSERT (ext_rel + 1 < ext_rel_end
1473 && (((ext_rel + 1)->r_bits[0]
1474 & RELOC_BITS0_TYPE_LITTLE)
1475 >> RELOC_BITS0_TYPE_SH_LITTLE) == ALPHA_R_IGNORE
1476 && (bfd_h_get_64 (input_bfd,
1477 (bfd_byte *) (ext_rel + 1)->r_vaddr)
1478 == r_vaddr - input_section->vma + r_symndx));
1480 /* Get the two instructions. */
1481 insn1 = bfd_get_32 (input_bfd,
1482 contents + r_vaddr - input_section->vma);
1483 insn2 = bfd_get_32 (input_bfd,
1486 - input_section->vma
1489 BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */
1490 BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */
1492 /* Get the existing addend. We must account for the sign
1493 extension done by lda and ldah. */
1494 addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff);
1497 /* This is addend -= 0x100000000 without causing an
1498 integer overflow on a 32 bit host. */
1499 addend -= 0x80000000;
1500 addend -= 0x80000000;
1505 /* The existing addend includes the difference between the
1506 gp of the input BFD and the address in the input BFD.
1507 We want to change this to the difference between the
1508 final GP and the final address. */
1510 - ecoff_data (input_bfd)->gp
1511 + input_section->vma
1512 - (input_section->output_section->vma
1513 + input_section->output_offset));
1515 /* Change the instructions, accounting for the sign
1516 extension, and write them out. */
1517 if (addend & 0x8000)
1519 insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff);
1520 insn2 = (insn2 & 0xffff0000) | (addend & 0xffff);
1522 bfd_put_32 (input_bfd, (bfd_vma) insn1,
1523 contents + r_vaddr - input_section->vma);
1524 bfd_put_32 (input_bfd, (bfd_vma) insn2,
1525 contents + r_vaddr - input_section->vma + r_symndx);
1531 case ALPHA_R_OP_PUSH:
1532 case ALPHA_R_OP_PSUB:
1533 case ALPHA_R_OP_PRSHIFT:
1534 /* Manipulate values on the reloc evaluation stack. The
1535 r_vaddr field is not an address in input_section, it is
1536 the current value (including any addend) of the object
1542 s = symndx_to_section[r_symndx];
1543 if (s == (asection *) NULL)
1545 addend = s->output_section->vma + s->output_offset - s->vma;
1549 struct ecoff_link_hash_entry *h;
1551 h = sym_hashes[r_symndx];
1552 if (h == (struct ecoff_link_hash_entry *) NULL)
1555 if (! info->relocateable)
1557 if (h->root.type == bfd_link_hash_defined)
1558 addend = (h->root.u.def.value
1559 + h->root.u.def.section->output_section->vma
1560 + h->root.u.def.section->output_offset);
1563 /* Note that we pass the address as 0, since we
1564 do not have a meaningful number for the
1565 location within the section that is being
1567 if (! ((*info->callbacks->undefined_symbol)
1568 (info, h->root.root.string, input_bfd,
1569 input_section, (bfd_vma) 0)))
1576 if (h->root.type != bfd_link_hash_defined
1579 /* This symbol is not being written out. Pass
1580 the address as 0, as with undefined_symbol,
1582 if (! ((*info->callbacks->unattached_reloc)
1583 (info, h->root.root.string, input_bfd,
1584 input_section, (bfd_vma) 0)))
1588 addend = alpha_convert_external_reloc (output_bfd, info,
1596 if (info->relocateable)
1598 /* Adjust r_vaddr by the addend. */
1599 bfd_h_put_64 (input_bfd, addend,
1600 (bfd_byte *) ext_rel->r_vaddr);
1606 case ALPHA_R_OP_PUSH:
1607 if (tos >= RELOC_STACKSIZE)
1609 stack[tos++] = addend;
1612 case ALPHA_R_OP_PSUB:
1615 stack[tos - 1] -= addend;
1618 case ALPHA_R_OP_PRSHIFT:
1621 stack[tos - 1] >>= addend;
1626 adjust_addrp = false;
1629 case ALPHA_R_OP_STORE:
1630 /* Store a value from the reloc stack into a bitfield. If
1631 we are generating relocateable output, all we do is
1632 adjust the address of the reloc. */
1633 if (! info->relocateable)
1640 /* FIXME: I don't know what kind of overflow checking,
1641 if any, should be done here. */
1642 val = bfd_get_64 (input_bfd,
1643 contents + r_vaddr - input_section->vma);
1644 val &=~ (((1 << r_size) - 1) << r_offset);
1645 val |= (stack[--tos] & ((1 << r_size) - 1)) << r_offset;
1646 bfd_put_64 (input_bfd, val,
1647 contents + r_vaddr - input_section->vma);
1651 case ALPHA_R_GPVALUE:
1652 /* I really don't know if this does the right thing. */
1653 gp = ecoff_data (input_bfd)->gp + r_symndx;
1654 gp_undefined = false;
1660 reloc_howto_type *howto;
1661 struct ecoff_link_hash_entry *h = NULL;
1664 bfd_reloc_status_type r;
1666 /* Perform a relocation. */
1668 howto = &alpha_howto_table[r_type];
1672 h = sym_hashes[r_symndx];
1673 /* If h is NULL, that means that there is a reloc
1674 against an external symbol which we thought was just
1675 a debugging symbol. This should not happen. */
1676 if (h == (struct ecoff_link_hash_entry *) NULL)
1681 if (r_symndx >= NUM_RELOC_SECTIONS)
1684 s = symndx_to_section[r_symndx];
1686 if (s == (asection *) NULL)
1690 if (info->relocateable)
1692 /* We are generating relocateable output, and must
1693 convert the existing reloc. */
1696 if (h->root.type != bfd_link_hash_defined
1699 /* This symbol is not being written out. */
1700 if (! ((*info->callbacks->unattached_reloc)
1701 (info, h->root.root.string, input_bfd,
1702 input_section, r_vaddr - input_section->vma)))
1706 relocation = alpha_convert_external_reloc (output_bfd,
1714 /* This is a relocation against a section. Adjust
1715 the value by the amount the section moved. */
1716 relocation = (s->output_section->vma
1721 /* If this is PC relative, the existing object file
1722 appears to already have the reloc worked out. We
1723 must subtract out the old value and add in the new
1725 if (howto->pc_relative)
1726 relocation -= (input_section->output_section->vma
1727 + input_section->output_offset
1728 - input_section->vma);
1730 /* Put in any addend. */
1731 relocation += addend;
1733 /* Adjust the contents. */
1734 r = _bfd_relocate_contents (howto, input_bfd, relocation,
1737 - input_section->vma));
1741 /* We are producing a final executable. */
1744 /* This is a reloc against a symbol. */
1745 if (h->root.type == bfd_link_hash_defined)
1749 hsec = h->root.u.def.section;
1750 relocation = (h->root.u.def.value
1751 + hsec->output_section->vma
1752 + hsec->output_offset);
1756 if (! ((*info->callbacks->undefined_symbol)
1757 (info, h->root.root.string, input_bfd,
1759 r_vaddr - input_section->vma)))
1766 /* This is a reloc against a section. */
1767 relocation = (s->output_section->vma
1771 /* Adjust a PC relative relocation by removing the
1772 reference to the original source section. */
1773 if (howto->pc_relative)
1774 relocation += input_section->vma;
1777 r = _bfd_final_link_relocate (howto,
1781 r_vaddr - input_section->vma,
1786 if (r != bfd_reloc_ok)
1791 case bfd_reloc_outofrange:
1793 case bfd_reloc_overflow:
1798 name = sym_hashes[r_symndx]->root.root.string;
1800 name = bfd_section_name (input_bfd,
1801 symndx_to_section[r_symndx]);
1802 if (! ((*info->callbacks->reloc_overflow)
1803 (info, name, alpha_howto_table[r_type].name,
1804 (bfd_vma) 0, input_bfd, input_section,
1805 r_vaddr - input_section->vma)))
1813 if (info->relocateable && adjust_addrp)
1815 /* Change the address of the relocation. */
1816 bfd_h_put_64 (input_bfd,
1817 (input_section->output_section->vma
1818 + input_section->output_offset
1819 - input_section->vma
1821 (bfd_byte *) ext_rel->r_vaddr);
1824 if (gp_usedp && gp_undefined)
1826 if (! ((*info->callbacks->reloc_dangerous)
1827 (info, "GP relative relocation when GP not defined",
1828 input_bfd, input_section, r_vaddr - input_section->vma)))
1830 /* Only give the error once per link. */
1831 ecoff_data (output_bfd)->gp = gp = 4;
1832 gp_undefined = false;
1842 #define ecoff_core_file_p _bfd_dummy_target
1843 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
1844 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1845 #define ecoff_core_file_matches_executable_p \
1846 _bfd_dummy_core_file_matches_executable_p
1848 /* This is the ECOFF backend structure. The backend field of the
1849 target vector points to this. */
1851 static const struct ecoff_backend_data alpha_ecoff_backend_data =
1853 /* COFF backend structure. */
1855 (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
1856 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
1857 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
1858 (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
1859 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
1860 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
1861 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* reloc_out */
1862 alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
1863 alpha_ecoff_swap_scnhdr_out,
1864 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
1865 alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
1866 alpha_ecoff_swap_scnhdr_in, alpha_ecoff_bad_format_hook,
1867 ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
1868 ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
1869 ecoff_slurp_symbol_table, NULL, NULL
1871 /* Supported architecture. */
1873 /* Initial portion of armap string. */
1875 /* The page boundary used to align sections in a demand-paged
1876 executable file. E.g., 0x1000. */
1878 /* True if the .rdata section is part of the text segment, as on the
1879 Alpha. False if .rdata is part of the data segment, as on the
1882 /* Bitsize of constructor entries. */
1884 /* Reloc to use for constructor entries. */
1885 &alpha_howto_table[ALPHA_R_REFQUAD],
1887 /* Symbol table magic number. */
1889 /* Alignment of debugging information. E.g., 4. */
1891 /* Sizes of external symbolic information. */
1892 sizeof (struct hdr_ext),
1893 sizeof (struct dnr_ext),
1894 sizeof (struct pdr_ext),
1895 sizeof (struct sym_ext),
1896 sizeof (struct opt_ext),
1897 sizeof (struct fdr_ext),
1898 sizeof (struct rfd_ext),
1899 sizeof (struct ext_ext),
1900 /* Functions to swap in external symbolic data. */
1909 /* Functions to swap out external symbolic data. */
1919 /* External reloc size. */
1921 /* Reloc swapping functions. */
1922 alpha_ecoff_swap_reloc_in,
1923 alpha_ecoff_swap_reloc_out,
1924 /* Backend reloc tweaking. */
1925 alpha_adjust_reloc_in,
1926 alpha_adjust_reloc_out,
1927 /* Relocate section contents while linking. */
1928 alpha_relocate_section
1931 /* Looking up a reloc type is Alpha specific. */
1932 #define ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
1934 /* So is getting relocated section contents. */
1935 #define ecoff_bfd_get_relocated_section_contents \
1936 alpha_ecoff_get_relocated_section_contents
1938 bfd_target ecoffalpha_little_vec =
1940 "ecoff-littlealpha", /* name */
1941 bfd_target_ecoff_flavour,
1942 false, /* data byte order is little */
1943 false, /* header byte order is little */
1945 (HAS_RELOC | EXEC_P | /* object flags */
1946 HAS_LINENO | HAS_DEBUG |
1947 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1949 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
1951 0, /* leading underscore */
1952 ' ', /* ar_pad_char */
1953 15, /* ar_max_namelen */
1954 4, /* minimum alignment power */
1955 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1956 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1957 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
1958 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1959 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1960 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
1962 {_bfd_dummy_target, alpha_ecoff_object_p, /* bfd_check_format */
1963 ecoff_archive_p, _bfd_dummy_target},
1964 {bfd_false, ecoff_mkobject, /* bfd_set_format */
1965 _bfd_generic_mkarchive, bfd_false},
1966 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
1967 _bfd_write_archive_contents, bfd_false},
1969 (PTR) &alpha_ecoff_backend_data