1 /* BFD back-end for ALPHA Extended-Coff files.
2 Copyright 1993 Free Software Foundation, Inc.
3 Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and
4 Ian Lance Taylor <ian@cygnus.com>.
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 boolean alpha_ecoff_bad_format_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
37 static void alpha_ecoff_swap_reloc_in
PARAMS ((bfd
*, PTR
,
38 struct internal_reloc
*));
39 static void alpha_ecoff_swap_reloc_out
PARAMS ((bfd
*,
40 const struct internal_reloc
*,
42 static void alpha_adjust_reloc_in
PARAMS ((bfd
*,
43 const struct internal_reloc
*,
45 static void alpha_adjust_reloc_out
PARAMS ((bfd
*, const arelent
*,
46 struct internal_reloc
*));
47 static bfd_byte
*alpha_ecoff_get_relocated_section_contents
48 PARAMS ((bfd
*abfd
, struct bfd_link_info
*, struct bfd_link_order
*,
49 bfd_byte
*data
, boolean relocateable
, asymbol
**symbols
));
50 static bfd_vma alpha_convert_external_reloc
51 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, struct external_reloc
*,
52 struct ecoff_link_hash_entry
*));
53 static boolean alpha_relocate_section
PARAMS ((bfd
*, struct bfd_link_info
*,
57 /* ECOFF has COFF sections, but the debugging information is stored in
58 a completely different format. ECOFF targets use some of the
59 swapping routines from coffswap.h, and some of the generic COFF
60 routines in coffgen.c, but, unlike the real COFF targets, do not
61 use coffcode.h itself.
63 Get the generic COFF swapping routines, except for the reloc,
64 symbol, and lineno ones. Give them ecoff names. Define some
65 accessor macros for the large sizes used for Alpha ECOFF. */
67 #define GET_FILEHDR_SYMPTR bfd_h_get_64
68 #define PUT_FILEHDR_SYMPTR bfd_h_put_64
69 #define GET_AOUTHDR_TSIZE bfd_h_get_64
70 #define PUT_AOUTHDR_TSIZE bfd_h_put_64
71 #define GET_AOUTHDR_DSIZE bfd_h_get_64
72 #define PUT_AOUTHDR_DSIZE bfd_h_put_64
73 #define GET_AOUTHDR_BSIZE bfd_h_get_64
74 #define PUT_AOUTHDR_BSIZE bfd_h_put_64
75 #define GET_AOUTHDR_ENTRY bfd_h_get_64
76 #define PUT_AOUTHDR_ENTRY bfd_h_put_64
77 #define GET_AOUTHDR_TEXT_START bfd_h_get_64
78 #define PUT_AOUTHDR_TEXT_START bfd_h_put_64
79 #define GET_AOUTHDR_DATA_START bfd_h_get_64
80 #define PUT_AOUTHDR_DATA_START bfd_h_put_64
81 #define GET_SCNHDR_PADDR bfd_h_get_64
82 #define PUT_SCNHDR_PADDR bfd_h_put_64
83 #define GET_SCNHDR_VADDR bfd_h_get_64
84 #define PUT_SCNHDR_VADDR bfd_h_put_64
85 #define GET_SCNHDR_SIZE bfd_h_get_64
86 #define PUT_SCNHDR_SIZE bfd_h_put_64
87 #define GET_SCNHDR_SCNPTR bfd_h_get_64
88 #define PUT_SCNHDR_SCNPTR bfd_h_put_64
89 #define GET_SCNHDR_RELPTR bfd_h_get_64
90 #define PUT_SCNHDR_RELPTR bfd_h_put_64
91 #define GET_SCNHDR_LNNOPTR bfd_h_get_64
92 #define PUT_SCNHDR_LNNOPTR bfd_h_put_64
96 #define NO_COFF_RELOCS
97 #define NO_COFF_SYMBOLS
98 #define NO_COFF_LINENOS
99 #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
100 #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
101 #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
102 #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
103 #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
104 #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
105 #include "coffswap.h"
107 /* Get the ECOFF swapping routines. */
109 #include "ecoffswap.h"
111 /* How to process the various reloc types. */
113 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
114 from smaller values. Start with zero, widen, *then* decrement. */
115 #define MINUS_ONE (((bfd_vma)0) - 1)
117 static reloc_howto_type alpha_howto_table
[] =
119 /* Reloc type 0 is ignored by itself. However, it appears after a
120 GPDISP reloc to identify the location where the low order 16 bits
121 of the gp register are loaded. */
122 HOWTO (ALPHA_R_IGNORE
, /* type */
124 0, /* size (0 = byte, 1 = short, 2 = long) */
126 true, /* pc_relative */
128 complain_overflow_dont
, /* complain_on_overflow */
129 0, /* special_function */
131 false, /* partial_inplace */
134 true), /* pcrel_offset */
136 /* A 32 bit reference to a symbol. */
137 HOWTO (ALPHA_R_REFLONG
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 false, /* pc_relative */
143 complain_overflow_bitfield
, /* complain_on_overflow */
144 0, /* special_function */
145 "REFLONG", /* name */
146 true, /* partial_inplace */
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
149 false), /* pcrel_offset */
151 /* A 64 bit reference to a symbol. */
152 HOWTO (ALPHA_R_REFQUAD
, /* type */
154 4, /* size (0 = byte, 1 = short, 2 = long) */
156 false, /* pc_relative */
158 complain_overflow_bitfield
, /* complain_on_overflow */
159 0, /* special_function */
160 "REFQUAD", /* name */
161 true, /* partial_inplace */
162 MINUS_ONE
, /* src_mask */
163 MINUS_ONE
, /* dst_mask */
164 false), /* pcrel_offset */
166 /* A 32 bit GP relative offset. This is just like REFLONG except
167 that when the value is used the value of the gp register will be
169 HOWTO (ALPHA_R_GPREL32
, /* type */
171 2, /* size (0 = byte, 1 = short, 2 = long) */
173 false, /* pc_relative */
175 complain_overflow_bitfield
, /* complain_on_overflow */
176 0, /* special_function */
177 "GPREL32", /* name */
178 true, /* partial_inplace */
179 0xffffffff, /* src_mask */
180 0xffffffff, /* dst_mask */
181 false), /* pcrel_offset */
183 /* Used for an instruction that refers to memory off the GP
184 register. The offset is 16 bits of the 32 bit instruction. This
185 reloc always seems to be against the .lita section. */
186 HOWTO (ALPHA_R_LITERAL
, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 false, /* pc_relative */
192 complain_overflow_signed
, /* complain_on_overflow */
193 0, /* special_function */
194 "LITERAL", /* name */
195 true, /* partial_inplace */
196 0xffff, /* src_mask */
197 0xffff, /* dst_mask */
198 false), /* pcrel_offset */
200 /* This reloc only appears immediately following a LITERAL reloc.
201 It identifies a use of the literal. It seems that the linker can
202 use this to eliminate a portion of the .lita section. The symbol
203 index is special: 1 means the literal address is in the base
204 register of a memory format instruction; 2 means the literal
205 address is in the byte offset register of a byte-manipulation
206 instruction; 3 means the literal address is in the target
207 register of a jsr instruction. This does not actually do any
209 HOWTO (ALPHA_R_LITUSE
, /* type */
211 2, /* size (0 = byte, 1 = short, 2 = long) */
213 false, /* pc_relative */
215 complain_overflow_dont
, /* complain_on_overflow */
216 0, /* special_function */
218 false, /* partial_inplace */
221 false), /* pcrel_offset */
223 /* Load the gp register. This is always used for a ldah instruction
224 which loads the upper 16 bits of the gp register. The next reloc
225 will be an IGNORE reloc which identifies the location of the lda
226 instruction which loads the lower 16 bits. The symbol index of
227 the GPDISP instruction appears to actually be the number of bytes
228 between the ldah and lda instructions. This gives two different
229 ways to determine where the lda instruction is; I don't know why
230 both are used. The value to use for the relocation is the
231 difference between the GP value and the current location; the
232 load will always be done against a register holding the current
234 HOWTO (ALPHA_R_GPDISP
, /* type */
236 2, /* size (0 = byte, 1 = short, 2 = long) */
238 true, /* pc_relative */
240 complain_overflow_dont
, /* complain_on_overflow */
241 0, /* special_function */
243 true, /* partial_inplace */
244 0xffff, /* src_mask */
245 0xffff, /* dst_mask */
246 true), /* pcrel_offset */
248 /* A 21 bit branch. The native assembler generates these for
249 branches within the text segment, and also fills in the PC
250 relative offset in the instruction. */
251 HOWTO (ALPHA_R_BRADDR
, /* type */
253 2, /* size (0 = byte, 1 = short, 2 = long) */
255 true, /* pc_relative */
257 complain_overflow_signed
, /* complain_on_overflow */
258 0, /* special_function */
260 true, /* partial_inplace */
261 0x1fffff, /* src_mask */
262 0x1fffff, /* dst_mask */
263 false), /* pcrel_offset */
265 /* A hint for a jump to a register. */
266 HOWTO (ALPHA_R_HINT
, /* type */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
270 true, /* pc_relative */
272 complain_overflow_dont
, /* complain_on_overflow */
273 0, /* special_function */
275 true, /* partial_inplace */
276 0x3fff, /* src_mask */
277 0x3fff, /* dst_mask */
278 false), /* pcrel_offset */
280 /* 16 bit PC relative offset. */
281 HOWTO (ALPHA_R_SREL16
, /* type */
283 1, /* size (0 = byte, 1 = short, 2 = long) */
285 true, /* pc_relative */
287 complain_overflow_signed
, /* complain_on_overflow */
288 0, /* special_function */
290 true, /* partial_inplace */
291 0xffff, /* src_mask */
292 0xffff, /* dst_mask */
293 false), /* pcrel_offset */
295 /* 32 bit PC relative offset. */
296 HOWTO (ALPHA_R_SREL32
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 true, /* pc_relative */
302 complain_overflow_signed
, /* complain_on_overflow */
303 0, /* special_function */
305 true, /* partial_inplace */
306 0xffffffff, /* src_mask */
307 0xffffffff, /* dst_mask */
308 false), /* pcrel_offset */
310 /* A 64 bit PC relative offset. */
311 HOWTO (ALPHA_R_SREL64
, /* type */
313 4, /* size (0 = byte, 1 = short, 2 = long) */
315 true, /* pc_relative */
317 complain_overflow_signed
, /* complain_on_overflow */
318 0, /* special_function */
320 true, /* partial_inplace */
321 MINUS_ONE
, /* src_mask */
322 MINUS_ONE
, /* dst_mask */
323 false), /* pcrel_offset */
325 /* Push a value on the reloc evaluation stack. */
326 HOWTO (ALPHA_R_OP_PUSH
, /* type */
328 0, /* size (0 = byte, 1 = short, 2 = long) */
330 false, /* pc_relative */
332 complain_overflow_dont
, /* complain_on_overflow */
333 0, /* special_function */
334 "OP_PUSH", /* name */
335 false, /* partial_inplace */
338 false), /* pcrel_offset */
340 /* Store the value from the stack at the given address. Store it in
341 a bitfield of size r_size starting at bit position r_offset. */
342 HOWTO (ALPHA_R_OP_STORE
, /* type */
344 4, /* size (0 = byte, 1 = short, 2 = long) */
346 false, /* pc_relative */
348 complain_overflow_dont
, /* complain_on_overflow */
349 0, /* special_function */
350 "OP_STORE", /* name */
351 false, /* partial_inplace */
353 MINUS_ONE
, /* dst_mask */
354 false), /* pcrel_offset */
356 /* Subtract the reloc address from the value on the top of the
358 HOWTO (ALPHA_R_OP_PSUB
, /* type */
360 0, /* size (0 = byte, 1 = short, 2 = long) */
362 false, /* pc_relative */
364 complain_overflow_dont
, /* complain_on_overflow */
365 0, /* special_function */
366 "OP_PSUB", /* name */
367 false, /* partial_inplace */
370 false), /* pcrel_offset */
372 /* Shift the value on the top of the relocation stack right by the
374 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
376 0, /* size (0 = byte, 1 = short, 2 = long) */
378 false, /* pc_relative */
380 complain_overflow_dont
, /* complain_on_overflow */
381 0, /* special_function */
382 "OP_PRSHIFT", /* name */
383 false, /* partial_inplace */
386 false), /* pcrel_offset */
388 /* Adjust the GP value for a new range in the object file. */
389 HOWTO (ALPHA_R_GPVALUE
, /* type */
391 0, /* size (0 = byte, 1 = short, 2 = long) */
393 false, /* pc_relative */
395 complain_overflow_dont
, /* complain_on_overflow */
396 0, /* special_function */
397 "GPVALUE", /* name */
398 false, /* partial_inplace */
401 false) /* pcrel_offset */
404 /* See whether the magic number matches. */
407 alpha_ecoff_bad_format_hook (abfd
, filehdr
)
411 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
413 if (ALPHA_ECOFF_BADMAG (*internal_f
))
419 /* Reloc handling. */
421 /* Swap a reloc in. */
424 alpha_ecoff_swap_reloc_in (abfd
, ext_ptr
, intern
)
427 struct internal_reloc
*intern
;
429 const RELOC
*ext
= (RELOC
*) ext_ptr
;
431 intern
->r_vaddr
= bfd_h_get_64 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
432 intern
->r_symndx
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_symndx
);
434 BFD_ASSERT (abfd
->xvec
->header_byteorder_big_p
== false);
436 intern
->r_type
= ((ext
->r_bits
[0] & RELOC_BITS0_TYPE_LITTLE
)
437 >> RELOC_BITS0_TYPE_SH_LITTLE
);
438 intern
->r_extern
= (ext
->r_bits
[1] & RELOC_BITS1_EXTERN_LITTLE
) != 0;
439 intern
->r_offset
= ((ext
->r_bits
[1] & RELOC_BITS1_OFFSET_LITTLE
)
440 >> RELOC_BITS1_OFFSET_SH_LITTLE
);
441 /* Ignored the reserved bits. */
442 intern
->r_size
= ((ext
->r_bits
[3] & RELOC_BITS3_SIZE_LITTLE
)
443 >> RELOC_BITS3_SIZE_SH_LITTLE
);
445 if (intern
->r_type
== ALPHA_R_LITUSE
446 || intern
->r_type
== ALPHA_R_GPDISP
)
448 /* Handle the LITUSE and GPDISP relocs specially. Its symndx
449 value is not actually a symbol index, but is instead a
450 special code. We put the code in the r_size field, and
451 clobber the symndx. */
452 if (intern
->r_size
!= 0)
454 intern
->r_size
= intern
->r_symndx
;
455 intern
->r_symndx
= RELOC_SECTION_NONE
;
457 else if (intern
->r_type
== ALPHA_R_IGNORE
)
459 /* The IGNORE reloc generally follows a GPDISP reloc, and is
460 against the .lita section. The section is irrelevant. */
461 if (! intern
->r_extern
&&
462 (intern
->r_symndx
== RELOC_SECTION_NONE
463 || intern
->r_symndx
== RELOC_SECTION_ABS
))
465 if (! intern
->r_extern
&& intern
->r_symndx
== RELOC_SECTION_LITA
)
466 intern
->r_symndx
= RELOC_SECTION_NONE
;
470 /* Swap a reloc out. */
473 alpha_ecoff_swap_reloc_out (abfd
, intern
, dst
)
475 const struct internal_reloc
*intern
;
478 RELOC
*ext
= (RELOC
*) dst
;
482 /* Undo the hackery done in swap_reloc_in. */
483 if (intern
->r_type
== ALPHA_R_LITUSE
484 || intern
->r_type
== ALPHA_R_GPDISP
)
486 symndx
= intern
->r_size
;
489 else if (intern
->r_type
== ALPHA_R_IGNORE
490 && ! intern
->r_extern
491 && intern
->r_symndx
== RELOC_SECTION_NONE
)
493 symndx
= RELOC_SECTION_LITA
;
494 size
= intern
->r_size
;
498 symndx
= intern
->r_symndx
;
499 size
= intern
->r_size
;
502 BFD_ASSERT (intern
->r_extern
503 || (intern
->r_symndx
>= 0 && intern
->r_symndx
<= 14));
505 bfd_h_put_64 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
506 bfd_h_put_32 (abfd
, symndx
, (bfd_byte
*) ext
->r_symndx
);
508 BFD_ASSERT (abfd
->xvec
->header_byteorder_big_p
== false);
510 ext
->r_bits
[0] = ((intern
->r_type
<< RELOC_BITS0_TYPE_SH_LITTLE
)
511 & RELOC_BITS0_TYPE_LITTLE
);
512 ext
->r_bits
[1] = ((intern
->r_extern
? RELOC_BITS1_EXTERN_LITTLE
: 0)
513 | ((intern
->r_offset
<< RELOC_BITS1_OFFSET_SH_LITTLE
)
514 & RELOC_BITS1_OFFSET_LITTLE
));
516 ext
->r_bits
[3] = ((size
<< RELOC_BITS3_SIZE_SH_LITTLE
)
517 & RELOC_BITS3_SIZE_LITTLE
);
520 /* Finish canonicalizing a reloc. Part of this is generic to all
521 ECOFF targets, and that part is in ecoff.c. The rest is done in
522 this backend routine. It must fill in the howto field. */
525 alpha_adjust_reloc_in (abfd
, intern
, rptr
)
527 const struct internal_reloc
*intern
;
530 if (intern
->r_type
> ALPHA_R_GPVALUE
)
533 switch (intern
->r_type
)
539 /* The PC relative relocs do not seem to use the section VMA as
540 a negative addend. */
544 case ALPHA_R_GPREL32
:
545 case ALPHA_R_LITERAL
:
546 /* Copy the gp value for this object file into the addend, to
547 ensure that we are not confused by the linker. */
548 if (! intern
->r_extern
)
549 rptr
->addend
+= ecoff_data (abfd
)->gp
;
554 /* The LITUSE and GPDISP relocs do not use a symbol, or an
555 addend, but they do use a special code. Put this code in the
557 rptr
->addend
= intern
->r_size
;
560 case ALPHA_R_OP_STORE
:
561 /* The STORE reloc needs the size and offset fields. We store
562 them in the addend. */
563 BFD_ASSERT (intern
->r_offset
<= 256 && intern
->r_size
<= 256);
564 rptr
->addend
= (intern
->r_offset
<< 8) + intern
->r_size
;
567 case ALPHA_R_OP_PUSH
:
568 case ALPHA_R_OP_PSUB
:
569 case ALPHA_R_OP_PRSHIFT
:
570 /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
571 address. I believe that the address supplied is really an
573 rptr
->addend
= intern
->r_vaddr
;
576 case ALPHA_R_GPVALUE
:
577 /* Set the addend field to the new GP value. */
578 rptr
->addend
= intern
->r_symndx
+ ecoff_data (abfd
)->gp
;
582 /* If the type is ALPHA_R_IGNORE, make sure this is a reference
583 to the absolute section so that the reloc is ignored. For
584 some reason the address of this reloc type is not adjusted by
585 the section vma. We record the gp value for this object file
586 here, for convenience when doing the GPDISP relocation. */
587 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
588 rptr
->address
= intern
->r_vaddr
;
589 rptr
->addend
= ecoff_data (abfd
)->gp
;
596 rptr
->howto
= &alpha_howto_table
[intern
->r_type
];
599 /* When writing out a reloc we need to pull some values back out of
600 the addend field into the reloc. This is roughly the reverse of
601 alpha_adjust_reloc_in, except that there are several changes we do
605 alpha_adjust_reloc_out (abfd
, rel
, intern
)
608 struct internal_reloc
*intern
;
610 switch (intern
->r_type
)
614 intern
->r_size
= rel
->addend
;
617 case ALPHA_R_OP_STORE
:
618 intern
->r_size
= rel
->addend
& 0xff;
619 intern
->r_offset
= (rel
->addend
>> 8) & 0xff;
622 case ALPHA_R_OP_PUSH
:
623 case ALPHA_R_OP_PSUB
:
624 case ALPHA_R_OP_PRSHIFT
:
625 intern
->r_vaddr
= rel
->addend
;
629 intern
->r_vaddr
= rel
->address
;
630 if (intern
->r_symndx
== RELOC_SECTION_ABS
)
631 intern
->r_symndx
= RELOC_SECTION_NONE
;
639 /* The size of the stack for the relocation evaluator. */
640 #define RELOC_STACKSIZE (10)
642 /* Alpha ECOFF relocs have a built in expression evaluator as well as
643 other interdependencies. Rather than use a bunch of special
644 functions and global variables, we use a single routine to do all
645 the relocation for a section. I haven't yet worked out how the
646 assembler is going to handle this. */
649 alpha_ecoff_get_relocated_section_contents (abfd
, link_info
, link_order
,
650 data
, relocateable
, symbols
)
652 struct bfd_link_info
*link_info
;
653 struct bfd_link_order
*link_order
;
655 boolean relocateable
;
658 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
659 asection
*input_section
= link_order
->u
.indirect
.section
;
660 size_t reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
661 arelent
**reloc_vector
= (arelent
**) alloca (reloc_size
);
662 bfd
*output_bfd
= relocateable
? abfd
: (bfd
*) NULL
;
664 boolean gp_undefined
;
665 bfd_vma stack
[RELOC_STACKSIZE
];
668 if (! bfd_get_section_contents (input_bfd
, input_section
, data
,
669 (file_ptr
) 0, input_section
->_raw_size
))
672 /* The section size is not going to change. */
673 input_section
->_cooked_size
= input_section
->_raw_size
;
674 input_section
->reloc_done
= true;
676 if (bfd_canonicalize_reloc (input_bfd
, input_section
, reloc_vector
,
681 /* Get the GP value for the output BFD. */
682 gp_undefined
= false;
683 if (ecoff_data (abfd
)->gp
== 0)
685 if (relocateable
!= false)
690 /* Make up a value. */
692 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
695 && (strcmp (sec
->name
, ".sbss") == 0
696 || strcmp (sec
->name
, ".sdata") == 0
697 || strcmp (sec
->name
, ".lit4") == 0
698 || strcmp (sec
->name
, ".lit8") == 0
699 || strcmp (sec
->name
, ".lita") == 0))
702 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
706 struct bfd_link_hash_entry
*h
;
708 h
= bfd_link_hash_lookup (link_info
->hash
, "_gp", false, false,
710 if (h
== (struct bfd_link_hash_entry
*) NULL
711 || h
->type
!= bfd_link_hash_defined
)
714 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
715 + h
->u
.def
.section
->output_section
->vma
716 + h
->u
.def
.section
->output_offset
);
719 gp
= ecoff_data (abfd
)->gp
;
721 for (; *reloc_vector
!= (arelent
*) NULL
; reloc_vector
++)
724 bfd_reloc_status_type r
;
729 switch (rel
->howto
->type
)
732 rel
->address
+= input_section
->output_offset
;
735 case ALPHA_R_REFLONG
:
736 case ALPHA_R_REFQUAD
:
743 && ((*rel
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) == 0)
745 rel
->address
+= input_section
->output_offset
;
748 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
752 case ALPHA_R_GPREL32
:
753 /* This relocation is used in a switch table. It is a 32
754 bit offset from the current GP value. We must adjust it
755 by the different between the original GP value and the
756 current GP value. The original GP value is stored in the
757 addend. We adjust the addend and let
758 bfd_perform_relocation finish the job. */
760 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
762 if (r
== bfd_reloc_ok
&& gp_undefined
)
764 r
= bfd_reloc_dangerous
;
765 err
= (char *) "GP relative relocation used when GP not defined";
769 case ALPHA_R_LITERAL
:
770 /* This is a reference to a literal value, generally
771 (always?) in the .lita section. This is a 16 bit GP
772 relative relocation. Sometimes the subsequent reloc is a
773 LITUSE reloc, which indicates how this reloc is used.
774 This sometimes permits rewriting the two instructions
775 referred to by the LITERAL and the LITUSE into different
776 instructions which do not refer to .lita. This can save
777 a memory reference, and permits removing a value from
778 .lita thus saving GP relative space.
780 We do not these optimizations. To do them we would need
781 to arrange to link the .lita section first, so that by
782 the time we got here we would know the final values to
783 use. This would not be particularly difficult, but it is
784 not currently implemented. */
789 /* I believe that the LITERAL reloc will only apply to a
790 ldq instruction, so check my assumption. */
791 insn
= bfd_get_32 (input_bfd
, data
+ rel
->address
);
792 BFD_ASSERT (((insn
>> 26) & 0x3f) == 0x29);
795 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
797 if (r
== bfd_reloc_ok
&& gp_undefined
)
799 r
= bfd_reloc_dangerous
;
801 (char *) "GP relative relocation used when GP not defined";
807 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
808 does not cause anything to happen, itself. */
809 rel
->address
+= input_section
->output_offset
;
813 /* This marks the ldah of an ldah/lda pair which loads the
814 gp register with the difference of the gp value and the
815 current location. The second of the pair is r_size bytes
816 ahead, and is marked with an ALPHA_R_IGNORE reloc. */
818 unsigned long insn1
, insn2
;
821 BFD_ASSERT (reloc_vector
[1] != NULL
822 && reloc_vector
[1]->howto
->type
== ALPHA_R_IGNORE
823 && (rel
->address
+ rel
->addend
824 == reloc_vector
[1]->address
));
826 /* Get the two instructions. */
827 insn1
= bfd_get_32 (input_bfd
, data
+ rel
->address
);
828 insn2
= bfd_get_32 (input_bfd
, data
+ rel
->address
+ rel
->addend
);
830 BFD_ASSERT (((insn1
>> 26) & 0x3f) == 0x09); /* ldah */
831 BFD_ASSERT (((insn2
>> 26) & 0x3f) == 0x08); /* lda */
833 /* Get the existing addend. We must account for the sign
834 extension done by lda and ldah. */
835 addend
= ((insn1
& 0xffff) << 16) + (insn2
& 0xffff);
838 addend
-= 0x80000000;
839 addend
-= 0x80000000;
844 /* The existing addend includes the different between the
845 gp of the input BFD and the address in the input BFD.
846 Subtract this out. */
847 addend
-= (reloc_vector
[1]->addend
848 - (input_section
->vma
+ rel
->address
));
850 /* Now add in the final gp value, and subtract out the
853 - (input_section
->output_section
->vma
854 + input_section
->output_offset
857 /* Change the instructions, accounting for the sign
858 extension, and write them out. */
861 insn1
= (insn1
& 0xffff0000) | ((addend
>> 16) & 0xffff);
862 insn2
= (insn2
& 0xffff0000) | (addend
& 0xffff);
864 bfd_put_32 (input_bfd
, (bfd_vma
) insn1
, data
+ rel
->address
);
865 bfd_put_32 (input_bfd
, (bfd_vma
) insn2
,
866 data
+ rel
->address
+ rel
->addend
);
868 rel
->address
+= input_section
->output_offset
;
872 case ALPHA_R_OP_PUSH
:
873 /* Push a value on the reloc evaluation stack. */
880 rel
->address
+= input_section
->output_offset
;
884 /* Figure out the relocation of this symbol. */
885 symbol
= *rel
->sym_ptr_ptr
;
887 if (symbol
->section
== &bfd_und_section
)
888 r
= bfd_reloc_undefined
;
890 if (bfd_is_com_section (symbol
->section
))
893 relocation
= symbol
->value
;
894 relocation
+= symbol
->section
->output_section
->vma
;
895 relocation
+= symbol
->section
->output_offset
;
896 relocation
+= rel
->addend
;
898 if (tos
>= RELOC_STACKSIZE
)
901 stack
[tos
++] = relocation
;
905 case ALPHA_R_OP_STORE
:
906 /* Store a value from the reloc stack into a bitfield. */
913 rel
->address
+= input_section
->output_offset
;
920 /* The offset and size for this reloc are encoded into the
921 addend field by alpha_adjust_reloc_in. */
922 offset
= (rel
->addend
>> 8) & 0xff;
923 size
= rel
->addend
& 0xff;
925 val
= bfd_get_64 (abfd
, data
+ rel
->address
);
926 val
&=~ (((1 << size
) - 1) << offset
);
927 val
|= (stack
[--tos
] & ((1 << size
) - 1)) << offset
;
928 bfd_put_64 (abfd
, val
, data
+ rel
->address
);
932 case ALPHA_R_OP_PSUB
:
933 /* Subtract a value from the top of the stack. */
940 rel
->address
+= input_section
->output_offset
;
944 /* Figure out the relocation of this symbol. */
945 symbol
= *rel
->sym_ptr_ptr
;
947 if (symbol
->section
== &bfd_und_section
)
948 r
= bfd_reloc_undefined
;
950 if (bfd_is_com_section (symbol
->section
))
953 relocation
= symbol
->value
;
954 relocation
+= symbol
->section
->output_section
->vma
;
955 relocation
+= symbol
->section
->output_offset
;
956 relocation
+= rel
->addend
;
961 stack
[tos
- 1] -= relocation
;
965 case ALPHA_R_OP_PRSHIFT
:
966 /* Shift the value on the top of the stack. */
973 rel
->address
+= input_section
->output_offset
;
977 /* Figure out the relocation of this symbol. */
978 symbol
= *rel
->sym_ptr_ptr
;
980 if (symbol
->section
== &bfd_und_section
)
981 r
= bfd_reloc_undefined
;
983 if (bfd_is_com_section (symbol
->section
))
986 relocation
= symbol
->value
;
987 relocation
+= symbol
->section
->output_section
->vma
;
988 relocation
+= symbol
->section
->output_offset
;
989 relocation
+= rel
->addend
;
994 stack
[tos
- 1] >>= relocation
;
998 case ALPHA_R_GPVALUE
:
999 /* I really don't know if this does the right thing. */
1001 gp_undefined
= false;
1010 asection
*os
= input_section
->output_section
;
1012 /* A partial link, so keep the relocs. */
1013 os
->orelocation
[os
->reloc_count
] = rel
;
1017 if (r
!= bfd_reloc_ok
)
1021 case bfd_reloc_undefined
:
1022 if (! ((*link_info
->callbacks
->undefined_symbol
)
1023 (link_info
, bfd_asymbol_name (*rel
->sym_ptr_ptr
),
1024 input_bfd
, input_section
, rel
->address
)))
1027 case bfd_reloc_dangerous
:
1028 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1029 (link_info
, err
, input_bfd
, input_section
,
1033 case bfd_reloc_overflow
:
1034 if (! ((*link_info
->callbacks
->reloc_overflow
)
1035 (link_info
, bfd_asymbol_name (*rel
->sym_ptr_ptr
),
1036 rel
->howto
->name
, rel
->addend
, input_bfd
,
1037 input_section
, rel
->address
)))
1040 case bfd_reloc_outofrange
:
1054 /* Get the howto structure for a generic reloc type. */
1056 static CONST
struct reloc_howto_struct
*
1057 alpha_bfd_reloc_type_lookup (abfd
, code
)
1059 bfd_reloc_code_real_type code
;
1066 alpha_type
= ALPHA_R_REFLONG
;
1069 alpha_type
= ALPHA_R_REFQUAD
;
1071 case BFD_RELOC_GPREL32
:
1072 alpha_type
= ALPHA_R_GPREL32
;
1074 case BFD_RELOC_ALPHA_LITERAL
:
1075 alpha_type
= ALPHA_R_LITERAL
;
1077 case BFD_RELOC_ALPHA_LITUSE
:
1078 alpha_type
= ALPHA_R_LITUSE
;
1080 case BFD_RELOC_ALPHA_GPDISP_HI16
:
1081 alpha_type
= ALPHA_R_GPDISP
;
1083 case BFD_RELOC_ALPHA_GPDISP_LO16
:
1084 alpha_type
= ALPHA_R_IGNORE
;
1086 case BFD_RELOC_23_PCREL_S2
:
1087 alpha_type
= ALPHA_R_BRADDR
;
1089 case BFD_RELOC_ALPHA_HINT
:
1090 alpha_type
= ALPHA_R_HINT
;
1092 case BFD_RELOC_16_PCREL
:
1093 alpha_type
= ALPHA_R_SREL16
;
1095 case BFD_RELOC_32_PCREL
:
1096 alpha_type
= ALPHA_R_SREL32
;
1098 case BFD_RELOC_64_PCREL
:
1099 alpha_type
= ALPHA_R_SREL64
;
1103 alpha_type
= ALPHA_R_OP_PUSH
;
1106 alpha_type
= ALPHA_R_OP_STORE
;
1109 alpha_type
= ALPHA_R_OP_PSUB
;
1112 alpha_type
= ALPHA_R_OP_PRSHIFT
;
1115 alpha_type
= ALPHA_R_GPVALUE
;
1119 return (CONST
struct reloc_howto_struct
*) NULL
;
1122 return &alpha_howto_table
[alpha_type
];
1125 /* A helper routine for alpha_relocate_section which converts an
1126 external reloc when generating relocateable output. Returns the
1127 relocation amount. */
1130 alpha_convert_external_reloc (output_bfd
, info
, input_bfd
, ext_rel
, h
)
1132 struct bfd_link_info
*info
;
1134 struct external_reloc
*ext_rel
;
1135 struct ecoff_link_hash_entry
*h
;
1137 unsigned long r_symndx
;
1140 BFD_ASSERT (info
->relocateable
);
1142 if (h
->root
.type
== bfd_link_hash_defined
)
1147 /* This symbol is defined in the output. Convert the reloc from
1148 being against the symbol to being against the section. */
1150 /* Clear the r_extern bit. */
1151 ext_rel
->r_bits
[1] &=~ RELOC_BITS1_EXTERN_LITTLE
;
1153 /* Compute a new r_symndx value. */
1154 hsec
= h
->root
.u
.def
.section
;
1155 name
= bfd_get_section_name (output_bfd
, hsec
->output_section
);
1161 if (strcmp (name
, "*ABS*") == 0)
1162 r_symndx
= RELOC_SECTION_ABS
;
1165 if (strcmp (name
, ".bss") == 0)
1166 r_symndx
= RELOC_SECTION_BSS
;
1169 if (strcmp (name
, ".data") == 0)
1170 r_symndx
= RELOC_SECTION_DATA
;
1173 if (strcmp (name
, ".fini") == 0)
1174 r_symndx
= RELOC_SECTION_FINI
;
1177 if (strcmp (name
, ".init") == 0)
1178 r_symndx
= RELOC_SECTION_INIT
;
1181 if (strcmp (name
, ".lita") == 0)
1182 r_symndx
= RELOC_SECTION_LITA
;
1183 else if (strcmp (name
, ".lit8") == 0)
1184 r_symndx
= RELOC_SECTION_LIT8
;
1185 else if (strcmp (name
, ".lit4") == 0)
1186 r_symndx
= RELOC_SECTION_LIT4
;
1189 if (strcmp (name
, ".pdata") == 0)
1190 r_symndx
= RELOC_SECTION_PDATA
;
1193 if (strcmp (name
, ".rdata") == 0)
1194 r_symndx
= RELOC_SECTION_RDATA
;
1197 if (strcmp (name
, ".sdata") == 0)
1198 r_symndx
= RELOC_SECTION_SDATA
;
1199 else if (strcmp (name
, ".sbss") == 0)
1200 r_symndx
= RELOC_SECTION_SBSS
;
1203 if (strcmp (name
, ".text") == 0)
1204 r_symndx
= RELOC_SECTION_TEXT
;
1207 if (strcmp (name
, ".xdata") == 0)
1208 r_symndx
= RELOC_SECTION_XDATA
;
1215 /* Add the section VMA and the symbol value. */
1216 relocation
= (h
->root
.u
.def
.value
1217 + hsec
->output_section
->vma
1218 + hsec
->output_offset
);
1222 /* Change the symndx value to the right one for
1227 /* Caller must give an error. */
1233 /* Write out the new r_symndx value. */
1234 bfd_h_put_32 (input_bfd
, (bfd_vma
) r_symndx
,
1235 (bfd_byte
*) ext_rel
->r_symndx
);
1240 /* Relocate a section while linking an Alpha ECOFF file. This is
1241 quite similar to get_relocated_section_contents. Perhaps they
1242 could be combined somehow. */
1245 alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1246 contents
, external_relocs
)
1248 struct bfd_link_info
*info
;
1250 asection
*input_section
;
1252 PTR external_relocs
;
1254 asection
**symndx_to_section
;
1255 struct ecoff_link_hash_entry
**sym_hashes
;
1257 boolean gp_undefined
;
1258 bfd_vma stack
[RELOC_STACKSIZE
];
1260 struct external_reloc
*ext_rel
;
1261 struct external_reloc
*ext_rel_end
;
1263 /* We keep a table mapping the symndx found in an internal reloc to
1264 the appropriate section. This is faster than looking up the
1265 section by name each time. */
1266 symndx_to_section
= ecoff_data (input_bfd
)->symndx_to_section
;
1267 if (symndx_to_section
== (asection
**) NULL
)
1269 symndx_to_section
= ((asection
**)
1270 bfd_alloc (input_bfd
,
1272 * sizeof (asection
*))));
1274 symndx_to_section
[RELOC_SECTION_NONE
] = NULL
;
1275 symndx_to_section
[RELOC_SECTION_TEXT
] =
1276 bfd_get_section_by_name (input_bfd
, ".text");
1277 symndx_to_section
[RELOC_SECTION_RDATA
] =
1278 bfd_get_section_by_name (input_bfd
, ".rdata");
1279 symndx_to_section
[RELOC_SECTION_DATA
] =
1280 bfd_get_section_by_name (input_bfd
, ".data");
1281 symndx_to_section
[RELOC_SECTION_SDATA
] =
1282 bfd_get_section_by_name (input_bfd
, ".sdata");
1283 symndx_to_section
[RELOC_SECTION_SBSS
] =
1284 bfd_get_section_by_name (input_bfd
, ".sbss");
1285 symndx_to_section
[RELOC_SECTION_BSS
] =
1286 bfd_get_section_by_name (input_bfd
, ".bss");
1287 symndx_to_section
[RELOC_SECTION_INIT
] =
1288 bfd_get_section_by_name (input_bfd
, ".init");
1289 symndx_to_section
[RELOC_SECTION_LIT8
] =
1290 bfd_get_section_by_name (input_bfd
, ".lit8");
1291 symndx_to_section
[RELOC_SECTION_LIT4
] =
1292 bfd_get_section_by_name (input_bfd
, ".lit4");
1293 symndx_to_section
[RELOC_SECTION_XDATA
] =
1294 bfd_get_section_by_name (input_bfd
, ".xdata");
1295 symndx_to_section
[RELOC_SECTION_PDATA
] =
1296 bfd_get_section_by_name (input_bfd
, ".pdata");
1297 symndx_to_section
[RELOC_SECTION_FINI
] =
1298 bfd_get_section_by_name (input_bfd
, ".fini");
1299 symndx_to_section
[RELOC_SECTION_LITA
] =
1300 bfd_get_section_by_name (input_bfd
, ".lita");
1301 symndx_to_section
[RELOC_SECTION_ABS
] = &bfd_abs_section
;
1303 ecoff_data (input_bfd
)->symndx_to_section
= symndx_to_section
;
1306 sym_hashes
= ecoff_data (input_bfd
)->sym_hashes
;
1308 gp
= ecoff_data (output_bfd
)->gp
;
1310 gp_undefined
= true;
1312 gp_undefined
= false;
1314 BFD_ASSERT (output_bfd
->xvec
->header_byteorder_big_p
== false);
1315 BFD_ASSERT (input_bfd
->xvec
->header_byteorder_big_p
== false);
1317 ext_rel
= (struct external_reloc
*) external_relocs
;
1318 ext_rel_end
= ext_rel
+ input_section
->reloc_count
;
1319 for (; ext_rel
< ext_rel_end
; ext_rel
++)
1322 unsigned long r_symndx
;
1328 boolean adjust_addrp
;
1332 r_vaddr
= bfd_h_get_64 (input_bfd
, (bfd_byte
*) ext_rel
->r_vaddr
);
1333 r_symndx
= bfd_h_get_32 (input_bfd
, (bfd_byte
*) ext_rel
->r_symndx
);
1335 r_type
= ((ext_rel
->r_bits
[0] & RELOC_BITS0_TYPE_LITTLE
)
1336 >> RELOC_BITS0_TYPE_SH_LITTLE
);
1337 r_extern
= (ext_rel
->r_bits
[1] & RELOC_BITS1_EXTERN_LITTLE
) != 0;
1338 r_offset
= ((ext_rel
->r_bits
[1] & RELOC_BITS1_OFFSET_LITTLE
)
1339 >> RELOC_BITS1_OFFSET_SH_LITTLE
);
1340 /* Ignored the reserved bits. */
1341 r_size
= ((ext_rel
->r_bits
[3] & RELOC_BITS3_SIZE_LITTLE
)
1342 >> RELOC_BITS3_SIZE_SH_LITTLE
);
1345 adjust_addrp
= true;
1354 case ALPHA_R_IGNORE
:
1355 /* This reloc appears after a GPDISP reloc. It marks the
1356 position of the second instruction to be altered by the
1357 GPDISP reloc, but is not otherwise used for anything.
1358 For some reason, the address of the relocation does not
1359 appear to include the section VMA, unlike the other
1360 relocation types. */
1361 if (info
->relocateable
)
1362 bfd_h_put_64 (input_bfd
,
1363 input_section
->output_offset
+ r_vaddr
,
1364 (bfd_byte
*) ext_rel
->r_vaddr
);
1365 adjust_addrp
= false;
1368 case ALPHA_R_REFLONG
:
1369 case ALPHA_R_REFQUAD
:
1370 case ALPHA_R_BRADDR
:
1372 case ALPHA_R_SREL16
:
1373 case ALPHA_R_SREL32
:
1374 case ALPHA_R_SREL64
:
1378 case ALPHA_R_GPREL32
:
1379 /* This relocation is used in a switch table. It is a 32
1380 bit offset from the current GP value. We must adjust it
1381 by the different between the original GP value and the
1382 current GP value. */
1384 addend
= ecoff_data (input_bfd
)->gp
- gp
;
1388 case ALPHA_R_LITERAL
:
1389 /* This is a reference to a literal value, generally
1390 (always?) in the .lita section. This is a 16 bit GP
1391 relative relocation. Sometimes the subsequent reloc is a
1392 LITUSE reloc, which indicates how this reloc is used.
1393 This sometimes permits rewriting the two instructions
1394 referred to by the LITERAL and the LITUSE into different
1395 instructions which do not refer to .lita. This can save
1396 a memory reference, and permits removing a value from
1397 .lita thus saving GP relative space.
1399 We do not these optimizations. To do them we would need
1400 to arrange to link the .lita section first, so that by
1401 the time we got here we would know the final values to
1402 use. This would not be particularly difficult, but it is
1403 not currently implemented. */
1405 /* I believe that the LITERAL reloc will only apply to a ldq
1406 instruction, so check my assumption. */
1407 BFD_ASSERT (((bfd_get_32 (input_bfd
,
1408 contents
+ r_vaddr
- input_section
->vma
)
1414 addend
= ecoff_data (input_bfd
)->gp
- gp
;
1418 case ALPHA_R_LITUSE
:
1419 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
1420 does not cause anything to happen, itself. */
1423 case ALPHA_R_GPDISP
:
1424 /* This marks the ldah of an ldah/lda pair which loads the
1425 gp register with the difference of the gp value and the
1426 current location. The second of the pair is r_symndx
1427 bytes ahead, and is also marked with an ALPHA_R_IGNORE
1430 unsigned long insn1
, insn2
;
1432 BFD_ASSERT (ext_rel
+ 1 < ext_rel_end
1433 && (((ext_rel
+ 1)->r_bits
[0]
1434 & RELOC_BITS0_TYPE_LITTLE
)
1435 >> RELOC_BITS0_TYPE_SH_LITTLE
) == ALPHA_R_IGNORE
1436 && (bfd_h_get_64 (input_bfd
,
1437 (bfd_byte
*) (ext_rel
+ 1)->r_vaddr
)
1438 == r_vaddr
- input_section
->vma
+ r_symndx
));
1440 /* Get the two instructions. */
1441 insn1
= bfd_get_32 (input_bfd
,
1442 contents
+ r_vaddr
- input_section
->vma
);
1443 insn2
= bfd_get_32 (input_bfd
,
1446 - input_section
->vma
1449 BFD_ASSERT (((insn1
>> 26) & 0x3f) == 0x09); /* ldah */
1450 BFD_ASSERT (((insn2
>> 26) & 0x3f) == 0x08); /* lda */
1452 /* Get the existing addend. We must account for the sign
1453 extension done by lda and ldah. */
1454 addend
= ((insn1
& 0xffff) << 16) + (insn2
& 0xffff);
1457 /* This is addend -= 0x100000000 without causing an
1458 integer overflow on a 32 bit host. */
1459 addend
-= 0x80000000;
1460 addend
-= 0x80000000;
1465 /* The existing addend includes the difference between the
1466 gp of the input BFD and the address in the input BFD.
1467 We want to change this to the difference between the
1468 final GP and the final address. */
1470 - ecoff_data (input_bfd
)->gp
1471 + input_section
->vma
1472 - (input_section
->output_section
->vma
1473 + input_section
->output_offset
));
1475 /* Change the instructions, accounting for the sign
1476 extension, and write them out. */
1477 if (addend
& 0x8000)
1479 insn1
= (insn1
& 0xffff0000) | ((addend
>> 16) & 0xffff);
1480 insn2
= (insn2
& 0xffff0000) | (addend
& 0xffff);
1482 bfd_put_32 (input_bfd
, (bfd_vma
) insn1
,
1483 contents
+ r_vaddr
- input_section
->vma
);
1484 bfd_put_32 (input_bfd
, (bfd_vma
) insn2
,
1485 contents
+ r_vaddr
- input_section
->vma
+ r_symndx
);
1491 case ALPHA_R_OP_PUSH
:
1492 case ALPHA_R_OP_PSUB
:
1493 case ALPHA_R_OP_PRSHIFT
:
1494 /* Manipulate values on the reloc evaluation stack. The
1495 r_vaddr field is not an address in input_section, it is
1496 the current value (including any addend) of the object
1502 s
= symndx_to_section
[r_symndx
];
1503 if (s
== (asection
*) NULL
)
1505 addend
= s
->output_section
->vma
+ s
->output_offset
- s
->vma
;
1509 struct ecoff_link_hash_entry
*h
;
1511 h
= sym_hashes
[r_symndx
];
1512 if (h
== (struct ecoff_link_hash_entry
*) NULL
)
1515 if (! info
->relocateable
)
1517 if (h
->root
.type
== bfd_link_hash_defined
)
1518 addend
= (h
->root
.u
.def
.value
1519 + h
->root
.u
.def
.section
->output_section
->vma
1520 + h
->root
.u
.def
.section
->output_offset
);
1523 /* Note that we pass the address as 0, since we
1524 do not have a meaningful number for the
1525 location within the section that is being
1527 if (! ((*info
->callbacks
->undefined_symbol
)
1528 (info
, h
->root
.root
.string
, input_bfd
,
1529 input_section
, (bfd_vma
) 0)))
1536 if (h
->root
.type
!= bfd_link_hash_defined
1539 /* This symbol is not being written out. Pass
1540 the address as 0, as with undefined_symbol,
1542 if (! ((*info
->callbacks
->unattached_reloc
)
1543 (info
, h
->root
.root
.string
, input_bfd
,
1544 input_section
, (bfd_vma
) 0)))
1548 addend
= alpha_convert_external_reloc (output_bfd
, info
,
1556 if (info
->relocateable
)
1558 /* Adjust r_vaddr by the addend. */
1559 bfd_h_put_64 (input_bfd
, addend
,
1560 (bfd_byte
*) ext_rel
->r_vaddr
);
1566 case ALPHA_R_OP_PUSH
:
1567 if (tos
>= RELOC_STACKSIZE
)
1569 stack
[tos
++] = addend
;
1572 case ALPHA_R_OP_PSUB
:
1575 stack
[tos
- 1] -= addend
;
1578 case ALPHA_R_OP_PRSHIFT
:
1581 stack
[tos
- 1] >>= addend
;
1586 adjust_addrp
= false;
1589 case ALPHA_R_OP_STORE
:
1590 /* Store a value from the reloc stack into a bitfield. If
1591 we are generating relocateable output, all we do is
1592 adjust the address of the reloc. */
1593 if (! info
->relocateable
)
1600 /* FIXME: I don't know what kind of overflow checking,
1601 if any, should be done here. */
1602 val
= bfd_get_64 (input_bfd
,
1603 contents
+ r_vaddr
- input_section
->vma
);
1604 val
&=~ (((1 << r_size
) - 1) << r_offset
);
1605 val
|= (stack
[--tos
] & ((1 << r_size
) - 1)) << r_offset
;
1606 bfd_put_64 (input_bfd
, val
,
1607 contents
+ r_vaddr
- input_section
->vma
);
1611 case ALPHA_R_GPVALUE
:
1612 /* I really don't know if this does the right thing. */
1613 gp
= ecoff_data (input_bfd
)->gp
+ r_symndx
;
1614 gp_undefined
= false;
1620 reloc_howto_type
*howto
;
1621 struct ecoff_link_hash_entry
*h
= NULL
;
1624 bfd_reloc_status_type r
;
1626 /* Perform a relocation. */
1628 howto
= &alpha_howto_table
[r_type
];
1632 h
= sym_hashes
[r_symndx
];
1633 /* If h is NULL, that means that there is a reloc
1634 against an external symbol which we thought was just
1635 a debugging symbol. This should not happen. */
1636 if (h
== (struct ecoff_link_hash_entry
*) NULL
)
1641 if (r_symndx
< 0 || r_symndx
>= NUM_RELOC_SECTIONS
)
1644 s
= symndx_to_section
[r_symndx
];
1646 if (s
== (asection
*) NULL
)
1650 if (info
->relocateable
)
1652 /* We are generating relocateable output, and must
1653 convert the existing reloc. */
1656 if (h
->root
.type
!= bfd_link_hash_defined
1659 /* This symbol is not being written out. */
1660 if (! ((*info
->callbacks
->unattached_reloc
)
1661 (info
, h
->root
.root
.string
, input_bfd
,
1662 input_section
, r_vaddr
- input_section
->vma
)))
1666 relocation
= alpha_convert_external_reloc (output_bfd
,
1674 /* This is a relocation against a section. Adjust
1675 the value by the amount the section moved. */
1676 relocation
= (s
->output_section
->vma
1681 /* If this is PC relative, the existing object file
1682 appears to already have the reloc worked out. We
1683 must subtract out the old value and add in the new
1685 if (howto
->pc_relative
)
1686 relocation
-= (input_section
->output_section
->vma
1687 + input_section
->output_offset
1688 - input_section
->vma
);
1690 /* Put in any addend. */
1691 relocation
+= addend
;
1693 /* Adjust the contents. */
1694 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
1697 - input_section
->vma
));
1701 /* We are producing a final executable. */
1704 /* This is a reloc against a symbol. */
1705 if (h
->root
.type
== bfd_link_hash_defined
)
1709 hsec
= h
->root
.u
.def
.section
;
1710 relocation
= (h
->root
.u
.def
.value
1711 + hsec
->output_section
->vma
1712 + hsec
->output_offset
);
1716 if (! ((*info
->callbacks
->undefined_symbol
)
1717 (info
, h
->root
.root
.string
, input_bfd
,
1719 r_vaddr
- input_section
->vma
)))
1726 /* This is a reloc against a section. */
1727 relocation
= (s
->output_section
->vma
1731 /* Adjust a PC relative relocation by removing the
1732 reference to the original source section. */
1733 if (howto
->pc_relative
)
1734 relocation
+= input_section
->vma
;
1737 r
= _bfd_final_link_relocate (howto
,
1741 r_vaddr
- input_section
->vma
,
1746 if (r
!= bfd_reloc_ok
)
1751 case bfd_reloc_outofrange
:
1753 case bfd_reloc_overflow
:
1758 name
= sym_hashes
[r_symndx
]->root
.root
.string
;
1760 name
= bfd_section_name (input_bfd
,
1761 symndx_to_section
[r_symndx
]);
1762 if (! ((*info
->callbacks
->reloc_overflow
)
1763 (info
, name
, alpha_howto_table
[r_type
].name
,
1764 (bfd_vma
) 0, input_bfd
, input_section
,
1765 r_vaddr
- input_section
->vma
)))
1773 if (info
->relocateable
&& adjust_addrp
)
1775 /* Change the address of the relocation. */
1776 bfd_h_put_64 (input_bfd
,
1777 (input_section
->output_section
->vma
1778 + input_section
->output_offset
1779 - input_section
->vma
1781 (bfd_byte
*) ext_rel
->r_vaddr
);
1784 if (gp_usedp
&& gp_undefined
)
1786 if (! ((*info
->callbacks
->reloc_dangerous
)
1787 (info
, "GP relative relocation when GP not defined",
1788 input_bfd
, input_section
, r_vaddr
- input_section
->vma
)))
1790 /* Only give the error once per link. */
1791 ecoff_data (output_bfd
)->gp
= gp
= 4;
1792 gp_undefined
= false;
1802 #define ecoff_core_file_p _bfd_dummy_target
1803 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
1804 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1805 #define ecoff_core_file_matches_executable_p \
1806 _bfd_dummy_core_file_matches_executable_p
1808 /* This is the ECOFF backend structure. The backend field of the
1809 target vector points to this. */
1811 static const struct ecoff_backend_data alpha_ecoff_backend_data
=
1813 /* COFF backend structure. */
1815 (void (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_in */
1816 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
1817 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
1818 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,PTR
))) bfd_void
, /* aux_out */
1819 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
1820 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
1821 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* reloc_out */
1822 alpha_ecoff_swap_filehdr_out
, alpha_ecoff_swap_aouthdr_out
,
1823 alpha_ecoff_swap_scnhdr_out
,
1824 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
1825 alpha_ecoff_swap_filehdr_in
, alpha_ecoff_swap_aouthdr_in
,
1826 alpha_ecoff_swap_scnhdr_in
, alpha_ecoff_bad_format_hook
,
1827 ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
1828 ecoff_styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
1829 ecoff_slurp_symbol_table
, NULL
, NULL
1831 /* Supported architecture. */
1833 /* Initial portion of armap string. */
1835 /* The page boundary used to align sections in a demand-paged
1836 executable file. E.g., 0x1000. */
1838 /* True if the .rdata section is part of the text segment, as on the
1839 Alpha. False if .rdata is part of the data segment, as on the
1842 /* Bitsize of constructor entries. */
1844 /* Reloc to use for constructor entries. */
1845 &alpha_howto_table
[ALPHA_R_REFQUAD
],
1847 /* Symbol table magic number. */
1849 /* Alignment of debugging information. E.g., 4. */
1851 /* Sizes of external symbolic information. */
1852 sizeof (struct hdr_ext
),
1853 sizeof (struct dnr_ext
),
1854 sizeof (struct pdr_ext
),
1855 sizeof (struct sym_ext
),
1856 sizeof (struct opt_ext
),
1857 sizeof (struct fdr_ext
),
1858 sizeof (struct rfd_ext
),
1859 sizeof (struct ext_ext
),
1860 /* Functions to swap in external symbolic data. */
1869 /* Functions to swap out external symbolic data. */
1879 /* External reloc size. */
1881 /* Reloc swapping functions. */
1882 alpha_ecoff_swap_reloc_in
,
1883 alpha_ecoff_swap_reloc_out
,
1884 /* Backend reloc tweaking. */
1885 alpha_adjust_reloc_in
,
1886 alpha_adjust_reloc_out
,
1887 /* Relocate section contents while linking. */
1888 alpha_relocate_section
1891 /* Looking up a reloc type is Alpha specific. */
1892 #define ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
1894 /* So is getting relocated section contents. */
1895 #define ecoff_bfd_get_relocated_section_contents \
1896 alpha_ecoff_get_relocated_section_contents
1898 bfd_target ecoffalpha_little_vec
=
1900 "ecoff-littlealpha", /* name */
1901 bfd_target_ecoff_flavour
,
1902 false, /* data byte order is little */
1903 false, /* header byte order is little */
1905 (HAS_RELOC
| EXEC_P
| /* object flags */
1906 HAS_LINENO
| HAS_DEBUG
|
1907 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
1909 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
1911 0, /* leading underscore */
1912 ' ', /* ar_pad_char */
1913 15, /* ar_max_namelen */
1914 4, /* minimum alignment power */
1915 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
1916 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
1917 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
1918 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
1919 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
1920 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
1922 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
1923 ecoff_archive_p
, _bfd_dummy_target
},
1924 {bfd_false
, ecoff_mkobject
, /* bfd_set_format */
1925 _bfd_generic_mkarchive
, bfd_false
},
1926 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
1927 _bfd_write_archive_contents
, bfd_false
},
1929 (PTR
) &alpha_ecoff_backend_data