1 /* BFD back-end for ALPHA Extended-Coff files.
2 Copyright 1993, 1994 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 bfd_target
*alpha_ecoff_object_p
PARAMS ((bfd
*));
37 static boolean alpha_ecoff_bad_format_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
38 static void alpha_ecoff_swap_reloc_in
PARAMS ((bfd
*, PTR
,
39 struct internal_reloc
*));
40 static void alpha_ecoff_swap_reloc_out
PARAMS ((bfd
*,
41 const struct internal_reloc
*,
43 static void alpha_adjust_reloc_in
PARAMS ((bfd
*,
44 const struct internal_reloc
*,
46 static void alpha_adjust_reloc_out
PARAMS ((bfd
*, const arelent
*,
47 struct internal_reloc
*));
48 static bfd_byte
*alpha_ecoff_get_relocated_section_contents
49 PARAMS ((bfd
*abfd
, struct bfd_link_info
*, struct bfd_link_order
*,
50 bfd_byte
*data
, boolean relocateable
, asymbol
**symbols
));
51 static bfd_vma alpha_convert_external_reloc
52 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, struct external_reloc
*,
53 struct ecoff_link_hash_entry
*));
54 static boolean alpha_relocate_section
PARAMS ((bfd
*, struct bfd_link_info
*,
58 /* ECOFF has COFF sections, but the debugging information is stored in
59 a completely different format. ECOFF targets use some of the
60 swapping routines from coffswap.h, and some of the generic COFF
61 routines in coffgen.c, but, unlike the real COFF targets, do not
62 use coffcode.h itself.
64 Get the generic COFF swapping routines, except for the reloc,
65 symbol, and lineno ones. Give them ecoff names. Define some
66 accessor macros for the large sizes used for Alpha ECOFF. */
68 #define GET_FILEHDR_SYMPTR bfd_h_get_64
69 #define PUT_FILEHDR_SYMPTR bfd_h_put_64
70 #define GET_AOUTHDR_TSIZE bfd_h_get_64
71 #define PUT_AOUTHDR_TSIZE bfd_h_put_64
72 #define GET_AOUTHDR_DSIZE bfd_h_get_64
73 #define PUT_AOUTHDR_DSIZE bfd_h_put_64
74 #define GET_AOUTHDR_BSIZE bfd_h_get_64
75 #define PUT_AOUTHDR_BSIZE bfd_h_put_64
76 #define GET_AOUTHDR_ENTRY bfd_h_get_64
77 #define PUT_AOUTHDR_ENTRY bfd_h_put_64
78 #define GET_AOUTHDR_TEXT_START bfd_h_get_64
79 #define PUT_AOUTHDR_TEXT_START bfd_h_put_64
80 #define GET_AOUTHDR_DATA_START bfd_h_get_64
81 #define PUT_AOUTHDR_DATA_START bfd_h_put_64
82 #define GET_SCNHDR_PADDR bfd_h_get_64
83 #define PUT_SCNHDR_PADDR bfd_h_put_64
84 #define GET_SCNHDR_VADDR bfd_h_get_64
85 #define PUT_SCNHDR_VADDR bfd_h_put_64
86 #define GET_SCNHDR_SIZE bfd_h_get_64
87 #define PUT_SCNHDR_SIZE bfd_h_put_64
88 #define GET_SCNHDR_SCNPTR bfd_h_get_64
89 #define PUT_SCNHDR_SCNPTR bfd_h_put_64
90 #define GET_SCNHDR_RELPTR bfd_h_get_64
91 #define PUT_SCNHDR_RELPTR bfd_h_put_64
92 #define GET_SCNHDR_LNNOPTR bfd_h_get_64
93 #define PUT_SCNHDR_LNNOPTR bfd_h_put_64
97 #define NO_COFF_RELOCS
98 #define NO_COFF_SYMBOLS
99 #define NO_COFF_LINENOS
100 #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
101 #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
102 #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
103 #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
104 #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
105 #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
106 #include "coffswap.h"
108 /* Get the ECOFF swapping routines. */
110 #include "ecoffswap.h"
112 /* How to process the various reloc types. */
114 static bfd_reloc_status_type
115 reloc_nil
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
116 asection
*, bfd
*, char **));
118 static bfd_reloc_status_type
119 reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
126 char **error_message
;
131 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
132 from smaller values. Start with zero, widen, *then* decrement. */
133 #define MINUS_ONE (((bfd_vma)0) - 1)
135 static reloc_howto_type alpha_howto_table
[] =
137 /* Reloc type 0 is ignored by itself. However, it appears after a
138 GPDISP reloc to identify the location where the low order 16 bits
139 of the gp register are loaded. */
140 HOWTO (ALPHA_R_IGNORE
, /* type */
142 0, /* size (0 = byte, 1 = short, 2 = long) */
144 true, /* pc_relative */
146 complain_overflow_dont
, /* complain_on_overflow */
147 reloc_nil
, /* special_function */
149 true, /* partial_inplace */
152 true), /* pcrel_offset */
154 /* A 32 bit reference to a symbol. */
155 HOWTO (ALPHA_R_REFLONG
, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 false, /* pc_relative */
161 complain_overflow_bitfield
, /* complain_on_overflow */
162 0, /* special_function */
163 "REFLONG", /* name */
164 true, /* partial_inplace */
165 0xffffffff, /* src_mask */
166 0xffffffff, /* dst_mask */
167 false), /* pcrel_offset */
169 /* A 64 bit reference to a symbol. */
170 HOWTO (ALPHA_R_REFQUAD
, /* type */
172 4, /* size (0 = byte, 1 = short, 2 = long) */
174 false, /* pc_relative */
176 complain_overflow_bitfield
, /* complain_on_overflow */
177 0, /* special_function */
178 "REFQUAD", /* name */
179 true, /* partial_inplace */
180 MINUS_ONE
, /* src_mask */
181 MINUS_ONE
, /* dst_mask */
182 false), /* pcrel_offset */
184 /* A 32 bit GP relative offset. This is just like REFLONG except
185 that when the value is used the value of the gp register will be
187 HOWTO (ALPHA_R_GPREL32
, /* type */
189 2, /* size (0 = byte, 1 = short, 2 = long) */
191 false, /* pc_relative */
193 complain_overflow_bitfield
, /* complain_on_overflow */
194 0, /* special_function */
195 "GPREL32", /* name */
196 true, /* partial_inplace */
197 0xffffffff, /* src_mask */
198 0xffffffff, /* dst_mask */
199 false), /* pcrel_offset */
201 /* Used for an instruction that refers to memory off the GP
202 register. The offset is 16 bits of the 32 bit instruction. This
203 reloc always seems to be against the .lita section. */
204 HOWTO (ALPHA_R_LITERAL
, /* type */
206 2, /* size (0 = byte, 1 = short, 2 = long) */
208 false, /* pc_relative */
210 complain_overflow_signed
, /* complain_on_overflow */
211 0, /* special_function */
212 "LITERAL", /* name */
213 true, /* partial_inplace */
214 0xffff, /* src_mask */
215 0xffff, /* dst_mask */
216 false), /* pcrel_offset */
218 /* This reloc only appears immediately following a LITERAL reloc.
219 It identifies a use of the literal. It seems that the linker can
220 use this to eliminate a portion of the .lita section. The symbol
221 index is special: 1 means the literal address is in the base
222 register of a memory format instruction; 2 means the literal
223 address is in the byte offset register of a byte-manipulation
224 instruction; 3 means the literal address is in the target
225 register of a jsr instruction. This does not actually do any
227 HOWTO (ALPHA_R_LITUSE
, /* type */
229 2, /* size (0 = byte, 1 = short, 2 = long) */
231 false, /* pc_relative */
233 complain_overflow_dont
, /* complain_on_overflow */
234 reloc_nil
, /* special_function */
236 false, /* partial_inplace */
239 false), /* pcrel_offset */
241 /* Load the gp register. This is always used for a ldah instruction
242 which loads the upper 16 bits of the gp register. The next reloc
243 will be an IGNORE reloc which identifies the location of the lda
244 instruction which loads the lower 16 bits. The symbol index of
245 the GPDISP instruction appears to actually be the number of bytes
246 between the ldah and lda instructions. This gives two different
247 ways to determine where the lda instruction is; I don't know why
248 both are used. The value to use for the relocation is the
249 difference between the GP value and the current location; the
250 load will always be done against a register holding the current
252 HOWTO (ALPHA_R_GPDISP
, /* type */
254 2, /* size (0 = byte, 1 = short, 2 = long) */
256 true, /* pc_relative */
258 complain_overflow_dont
, /* complain_on_overflow */
259 reloc_nil
, /* special_function */
261 true, /* partial_inplace */
262 0xffff, /* src_mask */
263 0xffff, /* dst_mask */
264 true), /* pcrel_offset */
266 /* A 21 bit branch. The native assembler generates these for
267 branches within the text segment, and also fills in the PC
268 relative offset in the instruction. */
269 HOWTO (ALPHA_R_BRADDR
, /* type */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
273 true, /* pc_relative */
275 complain_overflow_signed
, /* complain_on_overflow */
276 0, /* special_function */
278 true, /* partial_inplace */
279 0x1fffff, /* src_mask */
280 0x1fffff, /* dst_mask */
281 false), /* pcrel_offset */
283 /* A hint for a jump to a register. */
284 HOWTO (ALPHA_R_HINT
, /* type */
286 2, /* size (0 = byte, 1 = short, 2 = long) */
288 true, /* pc_relative */
290 complain_overflow_dont
, /* complain_on_overflow */
291 0, /* special_function */
293 true, /* partial_inplace */
294 0x3fff, /* src_mask */
295 0x3fff, /* dst_mask */
296 false), /* pcrel_offset */
298 /* 16 bit PC relative offset. */
299 HOWTO (ALPHA_R_SREL16
, /* type */
301 1, /* size (0 = byte, 1 = short, 2 = long) */
303 true, /* pc_relative */
305 complain_overflow_signed
, /* complain_on_overflow */
306 0, /* special_function */
308 true, /* partial_inplace */
309 0xffff, /* src_mask */
310 0xffff, /* dst_mask */
311 false), /* pcrel_offset */
313 /* 32 bit PC relative offset. */
314 HOWTO (ALPHA_R_SREL32
, /* type */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
318 true, /* pc_relative */
320 complain_overflow_signed
, /* complain_on_overflow */
321 0, /* special_function */
323 true, /* partial_inplace */
324 0xffffffff, /* src_mask */
325 0xffffffff, /* dst_mask */
326 false), /* pcrel_offset */
328 /* A 64 bit PC relative offset. */
329 HOWTO (ALPHA_R_SREL64
, /* type */
331 4, /* size (0 = byte, 1 = short, 2 = long) */
333 true, /* pc_relative */
335 complain_overflow_signed
, /* complain_on_overflow */
336 0, /* special_function */
338 true, /* partial_inplace */
339 MINUS_ONE
, /* src_mask */
340 MINUS_ONE
, /* dst_mask */
341 false), /* pcrel_offset */
343 /* Push a value on the reloc evaluation stack. */
344 HOWTO (ALPHA_R_OP_PUSH
, /* type */
346 0, /* size (0 = byte, 1 = short, 2 = long) */
348 false, /* pc_relative */
350 complain_overflow_dont
, /* complain_on_overflow */
351 0, /* special_function */
352 "OP_PUSH", /* name */
353 false, /* partial_inplace */
356 false), /* pcrel_offset */
358 /* Store the value from the stack at the given address. Store it in
359 a bitfield of size r_size starting at bit position r_offset. */
360 HOWTO (ALPHA_R_OP_STORE
, /* type */
362 4, /* size (0 = byte, 1 = short, 2 = long) */
364 false, /* pc_relative */
366 complain_overflow_dont
, /* complain_on_overflow */
367 0, /* special_function */
368 "OP_STORE", /* name */
369 false, /* partial_inplace */
371 MINUS_ONE
, /* dst_mask */
372 false), /* pcrel_offset */
374 /* Subtract the reloc address from the value on the top of the
376 HOWTO (ALPHA_R_OP_PSUB
, /* type */
378 0, /* size (0 = byte, 1 = short, 2 = long) */
380 false, /* pc_relative */
382 complain_overflow_dont
, /* complain_on_overflow */
383 0, /* special_function */
384 "OP_PSUB", /* name */
385 false, /* partial_inplace */
388 false), /* pcrel_offset */
390 /* Shift the value on the top of the relocation stack right by the
392 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
394 0, /* size (0 = byte, 1 = short, 2 = long) */
396 false, /* pc_relative */
398 complain_overflow_dont
, /* complain_on_overflow */
399 0, /* special_function */
400 "OP_PRSHIFT", /* name */
401 false, /* partial_inplace */
404 false), /* pcrel_offset */
406 /* Adjust the GP value for a new range in the object file. */
407 HOWTO (ALPHA_R_GPVALUE
, /* type */
409 0, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_dont
, /* complain_on_overflow */
414 0, /* special_function */
415 "GPVALUE", /* name */
416 false, /* partial_inplace */
419 false) /* pcrel_offset */
422 /* Recognize an Alpha ECOFF file. */
425 alpha_ecoff_object_p (abfd
)
428 static bfd_target
*ret
;
430 ret
= coff_object_p (abfd
);
432 if (ret
!= (bfd_target
*) NULL
)
436 /* Alpha ECOFF has a .pdata section. The lnnoptr field of the
437 .pdata section is the number of entries it contains. Each
438 entry takes up 8 bytes. The number of entries is required
439 since the section is aligned to a 16 byte boundary. When we
440 link .pdata sections together, we do not want to include the
441 alignment bytes. We handle this on input by faking the size
442 of the .pdata section to remove the unwanted alignment bytes.
443 On output we will set the lnnoptr field and force the
445 sec
= bfd_get_section_by_name (abfd
, _PDATA
);
446 if (sec
!= (asection
*) NULL
)
450 size
= sec
->line_filepos
* 8;
451 BFD_ASSERT (size
== bfd_section_size (abfd
, sec
)
452 || size
+ 8 == bfd_section_size (abfd
, sec
));
453 if (! bfd_set_section_size (abfd
, sec
, size
))
461 /* See whether the magic number matches. */
464 alpha_ecoff_bad_format_hook (abfd
, filehdr
)
468 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
470 if (ALPHA_ECOFF_BADMAG (*internal_f
))
476 /* Reloc handling. */
478 /* Swap a reloc in. */
481 alpha_ecoff_swap_reloc_in (abfd
, ext_ptr
, intern
)
484 struct internal_reloc
*intern
;
486 const RELOC
*ext
= (RELOC
*) ext_ptr
;
488 intern
->r_vaddr
= bfd_h_get_64 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
489 intern
->r_symndx
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_symndx
);
491 BFD_ASSERT (abfd
->xvec
->header_byteorder_big_p
== false);
493 intern
->r_type
= ((ext
->r_bits
[0] & RELOC_BITS0_TYPE_LITTLE
)
494 >> RELOC_BITS0_TYPE_SH_LITTLE
);
495 intern
->r_extern
= (ext
->r_bits
[1] & RELOC_BITS1_EXTERN_LITTLE
) != 0;
496 intern
->r_offset
= ((ext
->r_bits
[1] & RELOC_BITS1_OFFSET_LITTLE
)
497 >> RELOC_BITS1_OFFSET_SH_LITTLE
);
498 /* Ignored the reserved bits. */
499 intern
->r_size
= ((ext
->r_bits
[3] & RELOC_BITS3_SIZE_LITTLE
)
500 >> RELOC_BITS3_SIZE_SH_LITTLE
);
502 if (intern
->r_type
== ALPHA_R_LITUSE
503 || intern
->r_type
== ALPHA_R_GPDISP
)
505 /* Handle the LITUSE and GPDISP relocs specially. Its symndx
506 value is not actually a symbol index, but is instead a
507 special code. We put the code in the r_size field, and
508 clobber the symndx. */
509 if (intern
->r_size
!= 0)
511 intern
->r_size
= intern
->r_symndx
;
512 intern
->r_symndx
= RELOC_SECTION_NONE
;
514 else if (intern
->r_type
== ALPHA_R_IGNORE
)
516 /* The IGNORE reloc generally follows a GPDISP reloc, and is
517 against the .lita section. The section is irrelevant. */
518 if (! intern
->r_extern
&&
519 (intern
->r_symndx
== RELOC_SECTION_NONE
520 || intern
->r_symndx
== RELOC_SECTION_ABS
))
522 if (! intern
->r_extern
&& intern
->r_symndx
== RELOC_SECTION_LITA
)
523 intern
->r_symndx
= RELOC_SECTION_NONE
;
527 /* Swap a reloc out. */
530 alpha_ecoff_swap_reloc_out (abfd
, intern
, dst
)
532 const struct internal_reloc
*intern
;
535 RELOC
*ext
= (RELOC
*) dst
;
539 /* Undo the hackery done in swap_reloc_in. */
540 if (intern
->r_type
== ALPHA_R_LITUSE
541 || intern
->r_type
== ALPHA_R_GPDISP
)
543 symndx
= intern
->r_size
;
546 else if (intern
->r_type
== ALPHA_R_IGNORE
547 && ! intern
->r_extern
548 && intern
->r_symndx
== RELOC_SECTION_NONE
)
550 symndx
= RELOC_SECTION_LITA
;
551 size
= intern
->r_size
;
555 symndx
= intern
->r_symndx
;
556 size
= intern
->r_size
;
559 BFD_ASSERT (intern
->r_extern
560 || (intern
->r_symndx
>= 0 && intern
->r_symndx
<= 14));
562 bfd_h_put_64 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
563 bfd_h_put_32 (abfd
, symndx
, (bfd_byte
*) ext
->r_symndx
);
565 BFD_ASSERT (abfd
->xvec
->header_byteorder_big_p
== false);
567 ext
->r_bits
[0] = ((intern
->r_type
<< RELOC_BITS0_TYPE_SH_LITTLE
)
568 & RELOC_BITS0_TYPE_LITTLE
);
569 ext
->r_bits
[1] = ((intern
->r_extern
? RELOC_BITS1_EXTERN_LITTLE
: 0)
570 | ((intern
->r_offset
<< RELOC_BITS1_OFFSET_SH_LITTLE
)
571 & RELOC_BITS1_OFFSET_LITTLE
));
573 ext
->r_bits
[3] = ((size
<< RELOC_BITS3_SIZE_SH_LITTLE
)
574 & RELOC_BITS3_SIZE_LITTLE
);
577 /* Finish canonicalizing a reloc. Part of this is generic to all
578 ECOFF targets, and that part is in ecoff.c. The rest is done in
579 this backend routine. It must fill in the howto field. */
582 alpha_adjust_reloc_in (abfd
, intern
, rptr
)
584 const struct internal_reloc
*intern
;
587 if (intern
->r_type
> ALPHA_R_GPVALUE
)
590 switch (intern
->r_type
)
596 /* The PC relative relocs do not seem to use the section VMA as
597 a negative addend. */
601 case ALPHA_R_GPREL32
:
602 case ALPHA_R_LITERAL
:
603 /* Copy the gp value for this object file into the addend, to
604 ensure that we are not confused by the linker. */
605 if (! intern
->r_extern
)
606 rptr
->addend
+= ecoff_data (abfd
)->gp
;
611 /* The LITUSE and GPDISP relocs do not use a symbol, or an
612 addend, but they do use a special code. Put this code in the
614 rptr
->addend
= intern
->r_size
;
617 case ALPHA_R_OP_STORE
:
618 /* The STORE reloc needs the size and offset fields. We store
619 them in the addend. */
620 BFD_ASSERT (intern
->r_offset
<= 256 && intern
->r_size
<= 256);
621 rptr
->addend
= (intern
->r_offset
<< 8) + intern
->r_size
;
624 case ALPHA_R_OP_PUSH
:
625 case ALPHA_R_OP_PSUB
:
626 case ALPHA_R_OP_PRSHIFT
:
627 /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
628 address. I believe that the address supplied is really an
630 rptr
->addend
= intern
->r_vaddr
;
633 case ALPHA_R_GPVALUE
:
634 /* Set the addend field to the new GP value. */
635 rptr
->addend
= intern
->r_symndx
+ ecoff_data (abfd
)->gp
;
639 /* If the type is ALPHA_R_IGNORE, make sure this is a reference
640 to the absolute section so that the reloc is ignored. For
641 some reason the address of this reloc type is not adjusted by
642 the section vma. We record the gp value for this object file
643 here, for convenience when doing the GPDISP relocation. */
644 rptr
->sym_ptr_ptr
= bfd_abs_section
.symbol_ptr_ptr
;
645 rptr
->address
= intern
->r_vaddr
;
646 rptr
->addend
= ecoff_data (abfd
)->gp
;
653 rptr
->howto
= &alpha_howto_table
[intern
->r_type
];
656 /* When writing out a reloc we need to pull some values back out of
657 the addend field into the reloc. This is roughly the reverse of
658 alpha_adjust_reloc_in, except that there are several changes we do
662 alpha_adjust_reloc_out (abfd
, rel
, intern
)
665 struct internal_reloc
*intern
;
667 switch (intern
->r_type
)
671 intern
->r_size
= rel
->addend
;
674 case ALPHA_R_OP_STORE
:
675 intern
->r_size
= rel
->addend
& 0xff;
676 intern
->r_offset
= (rel
->addend
>> 8) & 0xff;
679 case ALPHA_R_OP_PUSH
:
680 case ALPHA_R_OP_PSUB
:
681 case ALPHA_R_OP_PRSHIFT
:
682 intern
->r_vaddr
= rel
->addend
;
686 intern
->r_vaddr
= rel
->address
;
687 if (intern
->r_symndx
== RELOC_SECTION_ABS
)
688 intern
->r_symndx
= RELOC_SECTION_NONE
;
696 /* The size of the stack for the relocation evaluator. */
697 #define RELOC_STACKSIZE (10)
699 /* Alpha ECOFF relocs have a built in expression evaluator as well as
700 other interdependencies. Rather than use a bunch of special
701 functions and global variables, we use a single routine to do all
702 the relocation for a section. I haven't yet worked out how the
703 assembler is going to handle this. */
706 alpha_ecoff_get_relocated_section_contents (abfd
, link_info
, link_order
,
707 data
, relocateable
, symbols
)
709 struct bfd_link_info
*link_info
;
710 struct bfd_link_order
*link_order
;
712 boolean relocateable
;
715 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
716 asection
*input_section
= link_order
->u
.indirect
.section
;
717 size_t reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
718 arelent
**reloc_vector
= NULL
;
719 bfd
*output_bfd
= relocateable
? abfd
: (bfd
*) NULL
;
721 boolean gp_undefined
;
722 bfd_vma stack
[RELOC_STACKSIZE
];
725 reloc_vector
= (arelent
**) malloc (reloc_size
);
726 if (reloc_vector
== NULL
&& reloc_size
!= 0)
728 bfd_set_error (bfd_error_no_memory
);
732 if (! bfd_get_section_contents (input_bfd
, input_section
, data
,
733 (file_ptr
) 0, input_section
->_raw_size
))
736 /* The section size is not going to change. */
737 input_section
->_cooked_size
= input_section
->_raw_size
;
738 input_section
->reloc_done
= true;
740 if (bfd_canonicalize_reloc (input_bfd
, input_section
, reloc_vector
,
743 goto successful_return
;
745 /* Get the GP value for the output BFD. */
746 gp_undefined
= false;
747 if (ecoff_data (abfd
)->gp
== 0)
749 if (relocateable
!= false)
754 /* Make up a value. */
756 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
759 && (strcmp (sec
->name
, ".sbss") == 0
760 || strcmp (sec
->name
, ".sdata") == 0
761 || strcmp (sec
->name
, ".lit4") == 0
762 || strcmp (sec
->name
, ".lit8") == 0
763 || strcmp (sec
->name
, ".lita") == 0))
766 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
770 struct bfd_link_hash_entry
*h
;
772 h
= bfd_link_hash_lookup (link_info
->hash
, "_gp", false, false,
774 if (h
== (struct bfd_link_hash_entry
*) NULL
775 || h
->type
!= bfd_link_hash_defined
)
778 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
779 + h
->u
.def
.section
->output_section
->vma
780 + h
->u
.def
.section
->output_offset
);
783 gp
= ecoff_data (abfd
)->gp
;
785 for (; *reloc_vector
!= (arelent
*) NULL
; reloc_vector
++)
788 bfd_reloc_status_type r
;
793 switch (rel
->howto
->type
)
796 rel
->address
+= input_section
->output_offset
;
799 case ALPHA_R_REFLONG
:
800 case ALPHA_R_REFQUAD
:
807 && ((*rel
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) == 0)
809 rel
->address
+= input_section
->output_offset
;
812 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
816 case ALPHA_R_GPREL32
:
817 /* This relocation is used in a switch table. It is a 32
818 bit offset from the current GP value. We must adjust it
819 by the different between the original GP value and the
820 current GP value. The original GP value is stored in the
821 addend. We adjust the addend and let
822 bfd_perform_relocation finish the job. */
824 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
826 if (r
== bfd_reloc_ok
&& gp_undefined
)
828 r
= bfd_reloc_dangerous
;
829 err
= (char *) "GP relative relocation used when GP not defined";
833 case ALPHA_R_LITERAL
:
834 /* This is a reference to a literal value, generally
835 (always?) in the .lita section. This is a 16 bit GP
836 relative relocation. Sometimes the subsequent reloc is a
837 LITUSE reloc, which indicates how this reloc is used.
838 This sometimes permits rewriting the two instructions
839 referred to by the LITERAL and the LITUSE into different
840 instructions which do not refer to .lita. This can save
841 a memory reference, and permits removing a value from
842 .lita thus saving GP relative space.
844 We do not these optimizations. To do them we would need
845 to arrange to link the .lita section first, so that by
846 the time we got here we would know the final values to
847 use. This would not be particularly difficult, but it is
848 not currently implemented. */
853 /* I believe that the LITERAL reloc will only apply to a
854 ldq or ldl instruction, so check my assumption. */
855 insn
= bfd_get_32 (input_bfd
, data
+ rel
->address
);
856 BFD_ASSERT (((insn
>> 26) & 0x3f) == 0x29
857 || ((insn
>> 26) & 0x3f) == 0x28);
860 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
862 if (r
== bfd_reloc_ok
&& gp_undefined
)
864 r
= bfd_reloc_dangerous
;
866 (char *) "GP relative relocation used when GP not defined";
872 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
873 does not cause anything to happen, itself. */
874 rel
->address
+= input_section
->output_offset
;
878 /* This marks the ldah of an ldah/lda pair which loads the
879 gp register with the difference of the gp value and the
880 current location. The second of the pair is r_size bytes
881 ahead, and is marked with an ALPHA_R_IGNORE reloc. */
883 unsigned long insn1
, insn2
;
886 BFD_ASSERT (reloc_vector
[1] != NULL
887 && reloc_vector
[1]->howto
->type
== ALPHA_R_IGNORE
888 && (rel
->address
+ rel
->addend
889 == reloc_vector
[1]->address
));
891 /* Get the two instructions. */
892 insn1
= bfd_get_32 (input_bfd
, data
+ rel
->address
);
893 insn2
= bfd_get_32 (input_bfd
, data
+ rel
->address
+ rel
->addend
);
895 BFD_ASSERT (((insn1
>> 26) & 0x3f) == 0x09); /* ldah */
896 BFD_ASSERT (((insn2
>> 26) & 0x3f) == 0x08); /* lda */
898 /* Get the existing addend. We must account for the sign
899 extension done by lda and ldah. */
900 addend
= ((insn1
& 0xffff) << 16) + (insn2
& 0xffff);
903 addend
-= 0x80000000;
904 addend
-= 0x80000000;
909 /* The existing addend includes the different between the
910 gp of the input BFD and the address in the input BFD.
911 Subtract this out. */
912 addend
-= (reloc_vector
[1]->addend
913 - (input_section
->vma
+ rel
->address
));
915 /* Now add in the final gp value, and subtract out the
918 - (input_section
->output_section
->vma
919 + input_section
->output_offset
922 /* Change the instructions, accounting for the sign
923 extension, and write them out. */
926 insn1
= (insn1
& 0xffff0000) | ((addend
>> 16) & 0xffff);
927 insn2
= (insn2
& 0xffff0000) | (addend
& 0xffff);
929 bfd_put_32 (input_bfd
, (bfd_vma
) insn1
, data
+ rel
->address
);
930 bfd_put_32 (input_bfd
, (bfd_vma
) insn2
,
931 data
+ rel
->address
+ rel
->addend
);
933 rel
->address
+= input_section
->output_offset
;
937 case ALPHA_R_OP_PUSH
:
938 /* Push a value on the reloc evaluation stack. */
945 rel
->address
+= input_section
->output_offset
;
949 /* Figure out the relocation of this symbol. */
950 symbol
= *rel
->sym_ptr_ptr
;
952 if (symbol
->section
== &bfd_und_section
)
953 r
= bfd_reloc_undefined
;
955 if (bfd_is_com_section (symbol
->section
))
958 relocation
= symbol
->value
;
959 relocation
+= symbol
->section
->output_section
->vma
;
960 relocation
+= symbol
->section
->output_offset
;
961 relocation
+= rel
->addend
;
963 if (tos
>= RELOC_STACKSIZE
)
966 stack
[tos
++] = relocation
;
970 case ALPHA_R_OP_STORE
:
971 /* Store a value from the reloc stack into a bitfield. */
978 rel
->address
+= input_section
->output_offset
;
985 /* The offset and size for this reloc are encoded into the
986 addend field by alpha_adjust_reloc_in. */
987 offset
= (rel
->addend
>> 8) & 0xff;
988 size
= rel
->addend
& 0xff;
990 val
= bfd_get_64 (abfd
, data
+ rel
->address
);
991 val
&=~ (((1 << size
) - 1) << offset
);
992 val
|= (stack
[--tos
] & ((1 << size
) - 1)) << offset
;
993 bfd_put_64 (abfd
, val
, data
+ rel
->address
);
997 case ALPHA_R_OP_PSUB
:
998 /* Subtract a value from the top of the stack. */
1005 rel
->address
+= input_section
->output_offset
;
1009 /* Figure out the relocation of this symbol. */
1010 symbol
= *rel
->sym_ptr_ptr
;
1012 if (symbol
->section
== &bfd_und_section
)
1013 r
= bfd_reloc_undefined
;
1015 if (bfd_is_com_section (symbol
->section
))
1018 relocation
= symbol
->value
;
1019 relocation
+= symbol
->section
->output_section
->vma
;
1020 relocation
+= symbol
->section
->output_offset
;
1021 relocation
+= rel
->addend
;
1026 stack
[tos
- 1] -= relocation
;
1030 case ALPHA_R_OP_PRSHIFT
:
1031 /* Shift the value on the top of the stack. */
1038 rel
->address
+= input_section
->output_offset
;
1042 /* Figure out the relocation of this symbol. */
1043 symbol
= *rel
->sym_ptr_ptr
;
1045 if (symbol
->section
== &bfd_und_section
)
1046 r
= bfd_reloc_undefined
;
1048 if (bfd_is_com_section (symbol
->section
))
1051 relocation
= symbol
->value
;
1052 relocation
+= symbol
->section
->output_section
->vma
;
1053 relocation
+= symbol
->section
->output_offset
;
1054 relocation
+= rel
->addend
;
1059 stack
[tos
- 1] >>= relocation
;
1063 case ALPHA_R_GPVALUE
:
1064 /* I really don't know if this does the right thing. */
1066 gp_undefined
= false;
1075 asection
*os
= input_section
->output_section
;
1077 /* A partial link, so keep the relocs. */
1078 os
->orelocation
[os
->reloc_count
] = rel
;
1082 if (r
!= bfd_reloc_ok
)
1086 case bfd_reloc_undefined
:
1087 if (! ((*link_info
->callbacks
->undefined_symbol
)
1088 (link_info
, bfd_asymbol_name (*rel
->sym_ptr_ptr
),
1089 input_bfd
, input_section
, rel
->address
)))
1092 case bfd_reloc_dangerous
:
1093 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1094 (link_info
, err
, input_bfd
, input_section
,
1098 case bfd_reloc_overflow
:
1099 if (! ((*link_info
->callbacks
->reloc_overflow
)
1100 (link_info
, bfd_asymbol_name (*rel
->sym_ptr_ptr
),
1101 rel
->howto
->name
, rel
->addend
, input_bfd
,
1102 input_section
, rel
->address
)))
1105 case bfd_reloc_outofrange
:
1117 if (reloc_vector
!= NULL
)
1118 free (reloc_vector
);
1122 if (reloc_vector
!= NULL
)
1123 free (reloc_vector
);
1127 /* Get the howto structure for a generic reloc type. */
1129 static CONST
struct reloc_howto_struct
*
1130 alpha_bfd_reloc_type_lookup (abfd
, code
)
1132 bfd_reloc_code_real_type code
;
1139 alpha_type
= ALPHA_R_REFLONG
;
1142 case BFD_RELOC_CTOR
:
1143 alpha_type
= ALPHA_R_REFQUAD
;
1145 case BFD_RELOC_GPREL32
:
1146 alpha_type
= ALPHA_R_GPREL32
;
1148 case BFD_RELOC_ALPHA_LITERAL
:
1149 alpha_type
= ALPHA_R_LITERAL
;
1151 case BFD_RELOC_ALPHA_LITUSE
:
1152 alpha_type
= ALPHA_R_LITUSE
;
1154 case BFD_RELOC_ALPHA_GPDISP_HI16
:
1155 alpha_type
= ALPHA_R_GPDISP
;
1157 case BFD_RELOC_ALPHA_GPDISP_LO16
:
1158 alpha_type
= ALPHA_R_IGNORE
;
1160 case BFD_RELOC_23_PCREL_S2
:
1161 alpha_type
= ALPHA_R_BRADDR
;
1163 case BFD_RELOC_ALPHA_HINT
:
1164 alpha_type
= ALPHA_R_HINT
;
1166 case BFD_RELOC_16_PCREL
:
1167 alpha_type
= ALPHA_R_SREL16
;
1169 case BFD_RELOC_32_PCREL
:
1170 alpha_type
= ALPHA_R_SREL32
;
1172 case BFD_RELOC_64_PCREL
:
1173 alpha_type
= ALPHA_R_SREL64
;
1177 alpha_type
= ALPHA_R_OP_PUSH
;
1180 alpha_type
= ALPHA_R_OP_STORE
;
1183 alpha_type
= ALPHA_R_OP_PSUB
;
1186 alpha_type
= ALPHA_R_OP_PRSHIFT
;
1189 alpha_type
= ALPHA_R_GPVALUE
;
1193 return (CONST
struct reloc_howto_struct
*) NULL
;
1196 return &alpha_howto_table
[alpha_type
];
1199 /* A helper routine for alpha_relocate_section which converts an
1200 external reloc when generating relocateable output. Returns the
1201 relocation amount. */
1204 alpha_convert_external_reloc (output_bfd
, info
, input_bfd
, ext_rel
, h
)
1206 struct bfd_link_info
*info
;
1208 struct external_reloc
*ext_rel
;
1209 struct ecoff_link_hash_entry
*h
;
1211 unsigned long r_symndx
;
1214 BFD_ASSERT (info
->relocateable
);
1216 if (h
->root
.type
== bfd_link_hash_defined
)
1221 /* This symbol is defined in the output. Convert the reloc from
1222 being against the symbol to being against the section. */
1224 /* Clear the r_extern bit. */
1225 ext_rel
->r_bits
[1] &=~ RELOC_BITS1_EXTERN_LITTLE
;
1227 /* Compute a new r_symndx value. */
1228 hsec
= h
->root
.u
.def
.section
;
1229 name
= bfd_get_section_name (output_bfd
, hsec
->output_section
);
1235 if (strcmp (name
, "*ABS*") == 0)
1236 r_symndx
= RELOC_SECTION_ABS
;
1239 if (strcmp (name
, ".bss") == 0)
1240 r_symndx
= RELOC_SECTION_BSS
;
1243 if (strcmp (name
, ".data") == 0)
1244 r_symndx
= RELOC_SECTION_DATA
;
1247 if (strcmp (name
, ".fini") == 0)
1248 r_symndx
= RELOC_SECTION_FINI
;
1251 if (strcmp (name
, ".init") == 0)
1252 r_symndx
= RELOC_SECTION_INIT
;
1255 if (strcmp (name
, ".lita") == 0)
1256 r_symndx
= RELOC_SECTION_LITA
;
1257 else if (strcmp (name
, ".lit8") == 0)
1258 r_symndx
= RELOC_SECTION_LIT8
;
1259 else if (strcmp (name
, ".lit4") == 0)
1260 r_symndx
= RELOC_SECTION_LIT4
;
1263 if (strcmp (name
, ".pdata") == 0)
1264 r_symndx
= RELOC_SECTION_PDATA
;
1267 if (strcmp (name
, ".rdata") == 0)
1268 r_symndx
= RELOC_SECTION_RDATA
;
1271 if (strcmp (name
, ".sdata") == 0)
1272 r_symndx
= RELOC_SECTION_SDATA
;
1273 else if (strcmp (name
, ".sbss") == 0)
1274 r_symndx
= RELOC_SECTION_SBSS
;
1277 if (strcmp (name
, ".text") == 0)
1278 r_symndx
= RELOC_SECTION_TEXT
;
1281 if (strcmp (name
, ".xdata") == 0)
1282 r_symndx
= RELOC_SECTION_XDATA
;
1289 /* Add the section VMA and the symbol value. */
1290 relocation
= (h
->root
.u
.def
.value
1291 + hsec
->output_section
->vma
1292 + hsec
->output_offset
);
1296 /* Change the symndx value to the right one for
1301 /* Caller must give an error. */
1307 /* Write out the new r_symndx value. */
1308 bfd_h_put_32 (input_bfd
, (bfd_vma
) r_symndx
,
1309 (bfd_byte
*) ext_rel
->r_symndx
);
1314 /* Relocate a section while linking an Alpha ECOFF file. This is
1315 quite similar to get_relocated_section_contents. Perhaps they
1316 could be combined somehow. */
1319 alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1320 contents
, external_relocs
)
1322 struct bfd_link_info
*info
;
1324 asection
*input_section
;
1326 PTR external_relocs
;
1328 asection
**symndx_to_section
;
1329 struct ecoff_link_hash_entry
**sym_hashes
;
1331 boolean gp_undefined
;
1332 bfd_vma stack
[RELOC_STACKSIZE
];
1334 struct external_reloc
*ext_rel
;
1335 struct external_reloc
*ext_rel_end
;
1337 /* We keep a table mapping the symndx found in an internal reloc to
1338 the appropriate section. This is faster than looking up the
1339 section by name each time. */
1340 symndx_to_section
= ecoff_data (input_bfd
)->symndx_to_section
;
1341 if (symndx_to_section
== (asection
**) NULL
)
1343 symndx_to_section
= ((asection
**)
1344 bfd_alloc (input_bfd
,
1346 * sizeof (asection
*))));
1347 if (!symndx_to_section
)
1349 bfd_set_error (bfd_error_no_memory
);
1353 symndx_to_section
[RELOC_SECTION_NONE
] = NULL
;
1354 symndx_to_section
[RELOC_SECTION_TEXT
] =
1355 bfd_get_section_by_name (input_bfd
, ".text");
1356 symndx_to_section
[RELOC_SECTION_RDATA
] =
1357 bfd_get_section_by_name (input_bfd
, ".rdata");
1358 symndx_to_section
[RELOC_SECTION_DATA
] =
1359 bfd_get_section_by_name (input_bfd
, ".data");
1360 symndx_to_section
[RELOC_SECTION_SDATA
] =
1361 bfd_get_section_by_name (input_bfd
, ".sdata");
1362 symndx_to_section
[RELOC_SECTION_SBSS
] =
1363 bfd_get_section_by_name (input_bfd
, ".sbss");
1364 symndx_to_section
[RELOC_SECTION_BSS
] =
1365 bfd_get_section_by_name (input_bfd
, ".bss");
1366 symndx_to_section
[RELOC_SECTION_INIT
] =
1367 bfd_get_section_by_name (input_bfd
, ".init");
1368 symndx_to_section
[RELOC_SECTION_LIT8
] =
1369 bfd_get_section_by_name (input_bfd
, ".lit8");
1370 symndx_to_section
[RELOC_SECTION_LIT4
] =
1371 bfd_get_section_by_name (input_bfd
, ".lit4");
1372 symndx_to_section
[RELOC_SECTION_XDATA
] =
1373 bfd_get_section_by_name (input_bfd
, ".xdata");
1374 symndx_to_section
[RELOC_SECTION_PDATA
] =
1375 bfd_get_section_by_name (input_bfd
, ".pdata");
1376 symndx_to_section
[RELOC_SECTION_FINI
] =
1377 bfd_get_section_by_name (input_bfd
, ".fini");
1378 symndx_to_section
[RELOC_SECTION_LITA
] =
1379 bfd_get_section_by_name (input_bfd
, ".lita");
1380 symndx_to_section
[RELOC_SECTION_ABS
] = &bfd_abs_section
;
1382 ecoff_data (input_bfd
)->symndx_to_section
= symndx_to_section
;
1385 sym_hashes
= ecoff_data (input_bfd
)->sym_hashes
;
1387 gp
= ecoff_data (output_bfd
)->gp
;
1389 gp_undefined
= true;
1391 gp_undefined
= false;
1393 BFD_ASSERT (output_bfd
->xvec
->header_byteorder_big_p
== false);
1394 BFD_ASSERT (input_bfd
->xvec
->header_byteorder_big_p
== false);
1396 ext_rel
= (struct external_reloc
*) external_relocs
;
1397 ext_rel_end
= ext_rel
+ input_section
->reloc_count
;
1398 for (; ext_rel
< ext_rel_end
; ext_rel
++)
1401 unsigned long r_symndx
;
1407 boolean adjust_addrp
;
1411 r_vaddr
= bfd_h_get_64 (input_bfd
, (bfd_byte
*) ext_rel
->r_vaddr
);
1412 r_symndx
= bfd_h_get_32 (input_bfd
, (bfd_byte
*) ext_rel
->r_symndx
);
1414 r_type
= ((ext_rel
->r_bits
[0] & RELOC_BITS0_TYPE_LITTLE
)
1415 >> RELOC_BITS0_TYPE_SH_LITTLE
);
1416 r_extern
= (ext_rel
->r_bits
[1] & RELOC_BITS1_EXTERN_LITTLE
) != 0;
1417 r_offset
= ((ext_rel
->r_bits
[1] & RELOC_BITS1_OFFSET_LITTLE
)
1418 >> RELOC_BITS1_OFFSET_SH_LITTLE
);
1419 /* Ignored the reserved bits. */
1420 r_size
= ((ext_rel
->r_bits
[3] & RELOC_BITS3_SIZE_LITTLE
)
1421 >> RELOC_BITS3_SIZE_SH_LITTLE
);
1424 adjust_addrp
= true;
1433 case ALPHA_R_IGNORE
:
1434 /* This reloc appears after a GPDISP reloc. It marks the
1435 position of the second instruction to be altered by the
1436 GPDISP reloc, but is not otherwise used for anything.
1437 For some reason, the address of the relocation does not
1438 appear to include the section VMA, unlike the other
1439 relocation types. */
1440 if (info
->relocateable
)
1441 bfd_h_put_64 (input_bfd
,
1442 input_section
->output_offset
+ r_vaddr
,
1443 (bfd_byte
*) ext_rel
->r_vaddr
);
1444 adjust_addrp
= false;
1447 case ALPHA_R_REFLONG
:
1448 case ALPHA_R_REFQUAD
:
1449 case ALPHA_R_BRADDR
:
1451 case ALPHA_R_SREL16
:
1452 case ALPHA_R_SREL32
:
1453 case ALPHA_R_SREL64
:
1457 case ALPHA_R_GPREL32
:
1458 /* This relocation is used in a switch table. It is a 32
1459 bit offset from the current GP value. We must adjust it
1460 by the different between the original GP value and the
1461 current GP value. */
1463 addend
= ecoff_data (input_bfd
)->gp
- gp
;
1467 case ALPHA_R_LITERAL
:
1468 /* This is a reference to a literal value, generally
1469 (always?) in the .lita section. This is a 16 bit GP
1470 relative relocation. Sometimes the subsequent reloc is a
1471 LITUSE reloc, which indicates how this reloc is used.
1472 This sometimes permits rewriting the two instructions
1473 referred to by the LITERAL and the LITUSE into different
1474 instructions which do not refer to .lita. This can save
1475 a memory reference, and permits removing a value from
1476 .lita thus saving GP relative space.
1478 We do not these optimizations. To do them we would need
1479 to arrange to link the .lita section first, so that by
1480 the time we got here we would know the final values to
1481 use. This would not be particularly difficult, but it is
1482 not currently implemented. */
1484 /* I believe that the LITERAL reloc will only apply to a ldq
1485 or ldl instruction, so check my assumption. */
1489 insn
= bfd_get_32 (input_bfd
,
1490 contents
+ r_vaddr
- input_section
->vma
);
1491 BFD_ASSERT (((insn
>> 26) & 0x3f) == 0x29
1492 || ((insn
>> 26) & 0x3f) == 0x28);
1496 addend
= ecoff_data (input_bfd
)->gp
- gp
;
1500 case ALPHA_R_LITUSE
:
1501 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
1502 does not cause anything to happen, itself. */
1505 case ALPHA_R_GPDISP
:
1506 /* This marks the ldah of an ldah/lda pair which loads the
1507 gp register with the difference of the gp value and the
1508 current location. The second of the pair is r_symndx
1509 bytes ahead, and is also marked with an ALPHA_R_IGNORE
1512 unsigned long insn1
, insn2
;
1514 BFD_ASSERT (ext_rel
+ 1 < ext_rel_end
1515 && (((ext_rel
+ 1)->r_bits
[0]
1516 & RELOC_BITS0_TYPE_LITTLE
)
1517 >> RELOC_BITS0_TYPE_SH_LITTLE
) == ALPHA_R_IGNORE
1518 && (bfd_h_get_64 (input_bfd
,
1519 (bfd_byte
*) (ext_rel
+ 1)->r_vaddr
)
1520 == r_vaddr
- input_section
->vma
+ r_symndx
));
1522 /* Get the two instructions. */
1523 insn1
= bfd_get_32 (input_bfd
,
1524 contents
+ r_vaddr
- input_section
->vma
);
1525 insn2
= bfd_get_32 (input_bfd
,
1528 - input_section
->vma
1531 BFD_ASSERT (((insn1
>> 26) & 0x3f) == 0x09); /* ldah */
1532 BFD_ASSERT (((insn2
>> 26) & 0x3f) == 0x08); /* lda */
1534 /* Get the existing addend. We must account for the sign
1535 extension done by lda and ldah. */
1536 addend
= ((insn1
& 0xffff) << 16) + (insn2
& 0xffff);
1539 /* This is addend -= 0x100000000 without causing an
1540 integer overflow on a 32 bit host. */
1541 addend
-= 0x80000000;
1542 addend
-= 0x80000000;
1547 /* The existing addend includes the difference between the
1548 gp of the input BFD and the address in the input BFD.
1549 We want to change this to the difference between the
1550 final GP and the final address. */
1552 - ecoff_data (input_bfd
)->gp
1553 + input_section
->vma
1554 - (input_section
->output_section
->vma
1555 + input_section
->output_offset
));
1557 /* Change the instructions, accounting for the sign
1558 extension, and write them out. */
1559 if (addend
& 0x8000)
1561 insn1
= (insn1
& 0xffff0000) | ((addend
>> 16) & 0xffff);
1562 insn2
= (insn2
& 0xffff0000) | (addend
& 0xffff);
1564 bfd_put_32 (input_bfd
, (bfd_vma
) insn1
,
1565 contents
+ r_vaddr
- input_section
->vma
);
1566 bfd_put_32 (input_bfd
, (bfd_vma
) insn2
,
1567 contents
+ r_vaddr
- input_section
->vma
+ r_symndx
);
1573 case ALPHA_R_OP_PUSH
:
1574 case ALPHA_R_OP_PSUB
:
1575 case ALPHA_R_OP_PRSHIFT
:
1576 /* Manipulate values on the reloc evaluation stack. The
1577 r_vaddr field is not an address in input_section, it is
1578 the current value (including any addend) of the object
1584 s
= symndx_to_section
[r_symndx
];
1585 if (s
== (asection
*) NULL
)
1587 addend
= s
->output_section
->vma
+ s
->output_offset
- s
->vma
;
1591 struct ecoff_link_hash_entry
*h
;
1593 h
= sym_hashes
[r_symndx
];
1594 if (h
== (struct ecoff_link_hash_entry
*) NULL
)
1597 if (! info
->relocateable
)
1599 if (h
->root
.type
== bfd_link_hash_defined
)
1600 addend
= (h
->root
.u
.def
.value
1601 + h
->root
.u
.def
.section
->output_section
->vma
1602 + h
->root
.u
.def
.section
->output_offset
);
1605 /* Note that we pass the address as 0, since we
1606 do not have a meaningful number for the
1607 location within the section that is being
1609 if (! ((*info
->callbacks
->undefined_symbol
)
1610 (info
, h
->root
.root
.string
, input_bfd
,
1611 input_section
, (bfd_vma
) 0)))
1618 if (h
->root
.type
!= bfd_link_hash_defined
1621 /* This symbol is not being written out. Pass
1622 the address as 0, as with undefined_symbol,
1624 if (! ((*info
->callbacks
->unattached_reloc
)
1625 (info
, h
->root
.root
.string
, input_bfd
,
1626 input_section
, (bfd_vma
) 0)))
1630 addend
= alpha_convert_external_reloc (output_bfd
, info
,
1638 if (info
->relocateable
)
1640 /* Adjust r_vaddr by the addend. */
1641 bfd_h_put_64 (input_bfd
, addend
,
1642 (bfd_byte
*) ext_rel
->r_vaddr
);
1648 case ALPHA_R_OP_PUSH
:
1649 if (tos
>= RELOC_STACKSIZE
)
1651 stack
[tos
++] = addend
;
1654 case ALPHA_R_OP_PSUB
:
1657 stack
[tos
- 1] -= addend
;
1660 case ALPHA_R_OP_PRSHIFT
:
1663 stack
[tos
- 1] >>= addend
;
1668 adjust_addrp
= false;
1671 case ALPHA_R_OP_STORE
:
1672 /* Store a value from the reloc stack into a bitfield. If
1673 we are generating relocateable output, all we do is
1674 adjust the address of the reloc. */
1675 if (! info
->relocateable
)
1683 /* Get the relocation mask. The separate steps and the
1684 casts to bfd_vma are attempts to avoid a bug in the
1685 Alpha OSF 1.3 C compiler. See reloc.c for more
1688 mask
<<= (bfd_vma
) r_size
;
1691 /* FIXME: I don't know what kind of overflow checking,
1692 if any, should be done here. */
1693 val
= bfd_get_64 (input_bfd
,
1694 contents
+ r_vaddr
- input_section
->vma
);
1695 val
&=~ mask
<< (bfd_vma
) r_offset
;
1696 val
|= (stack
[--tos
] & mask
) << (bfd_vma
) r_offset
;
1697 bfd_put_64 (input_bfd
, val
,
1698 contents
+ r_vaddr
- input_section
->vma
);
1702 case ALPHA_R_GPVALUE
:
1703 /* I really don't know if this does the right thing. */
1704 gp
= ecoff_data (input_bfd
)->gp
+ r_symndx
;
1705 gp_undefined
= false;
1711 reloc_howto_type
*howto
;
1712 struct ecoff_link_hash_entry
*h
= NULL
;
1715 bfd_reloc_status_type r
;
1717 /* Perform a relocation. */
1719 howto
= &alpha_howto_table
[r_type
];
1723 h
= sym_hashes
[r_symndx
];
1724 /* If h is NULL, that means that there is a reloc
1725 against an external symbol which we thought was just
1726 a debugging symbol. This should not happen. */
1727 if (h
== (struct ecoff_link_hash_entry
*) NULL
)
1732 if (r_symndx
>= NUM_RELOC_SECTIONS
)
1735 s
= symndx_to_section
[r_symndx
];
1737 if (s
== (asection
*) NULL
)
1741 if (info
->relocateable
)
1743 /* We are generating relocateable output, and must
1744 convert the existing reloc. */
1747 if (h
->root
.type
!= bfd_link_hash_defined
1750 /* This symbol is not being written out. */
1751 if (! ((*info
->callbacks
->unattached_reloc
)
1752 (info
, h
->root
.root
.string
, input_bfd
,
1753 input_section
, r_vaddr
- input_section
->vma
)))
1757 relocation
= alpha_convert_external_reloc (output_bfd
,
1765 /* This is a relocation against a section. Adjust
1766 the value by the amount the section moved. */
1767 relocation
= (s
->output_section
->vma
1772 /* If this is PC relative, the existing object file
1773 appears to already have the reloc worked out. We
1774 must subtract out the old value and add in the new
1776 if (howto
->pc_relative
)
1777 relocation
-= (input_section
->output_section
->vma
1778 + input_section
->output_offset
1779 - input_section
->vma
);
1781 /* Put in any addend. */
1782 relocation
+= addend
;
1784 /* Adjust the contents. */
1785 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
1788 - input_section
->vma
));
1792 /* We are producing a final executable. */
1795 /* This is a reloc against a symbol. */
1796 if (h
->root
.type
== bfd_link_hash_defined
)
1800 hsec
= h
->root
.u
.def
.section
;
1801 relocation
= (h
->root
.u
.def
.value
1802 + hsec
->output_section
->vma
1803 + hsec
->output_offset
);
1807 if (! ((*info
->callbacks
->undefined_symbol
)
1808 (info
, h
->root
.root
.string
, input_bfd
,
1810 r_vaddr
- input_section
->vma
)))
1817 /* This is a reloc against a section. */
1818 relocation
= (s
->output_section
->vma
1822 /* Adjust a PC relative relocation by removing the
1823 reference to the original source section. */
1824 if (howto
->pc_relative
)
1825 relocation
+= input_section
->vma
;
1828 r
= _bfd_final_link_relocate (howto
,
1832 r_vaddr
- input_section
->vma
,
1837 if (r
!= bfd_reloc_ok
)
1842 case bfd_reloc_outofrange
:
1844 case bfd_reloc_overflow
:
1849 name
= sym_hashes
[r_symndx
]->root
.root
.string
;
1851 name
= bfd_section_name (input_bfd
,
1852 symndx_to_section
[r_symndx
]);
1853 if (! ((*info
->callbacks
->reloc_overflow
)
1854 (info
, name
, alpha_howto_table
[r_type
].name
,
1855 (bfd_vma
) 0, input_bfd
, input_section
,
1856 r_vaddr
- input_section
->vma
)))
1864 if (info
->relocateable
&& adjust_addrp
)
1866 /* Change the address of the relocation. */
1867 bfd_h_put_64 (input_bfd
,
1868 (input_section
->output_section
->vma
1869 + input_section
->output_offset
1870 - input_section
->vma
1872 (bfd_byte
*) ext_rel
->r_vaddr
);
1875 if (gp_usedp
&& gp_undefined
)
1877 if (! ((*info
->callbacks
->reloc_dangerous
)
1878 (info
, "GP relative relocation when GP not defined",
1879 input_bfd
, input_section
, r_vaddr
- input_section
->vma
)))
1881 /* Only give the error once per link. */
1882 ecoff_data (output_bfd
)->gp
= gp
= 4;
1883 gp_undefined
= false;
1893 #define ecoff_core_file_p _bfd_dummy_target
1894 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
1895 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1896 #define ecoff_core_file_matches_executable_p \
1897 _bfd_dummy_core_file_matches_executable_p
1899 /* This is the ECOFF backend structure. The backend field of the
1900 target vector points to this. */
1902 static const struct ecoff_backend_data alpha_ecoff_backend_data
=
1904 /* COFF backend structure. */
1906 (void (*) PARAMS ((bfd
*,PTR
,int,int,int,int,PTR
))) bfd_void
, /* aux_in */
1907 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
1908 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
1909 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,int,int,PTR
)))bfd_void
,/*aux_out*/
1910 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
1911 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
1912 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* reloc_out */
1913 alpha_ecoff_swap_filehdr_out
, alpha_ecoff_swap_aouthdr_out
,
1914 alpha_ecoff_swap_scnhdr_out
,
1915 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, true,
1916 alpha_ecoff_swap_filehdr_in
, alpha_ecoff_swap_aouthdr_in
,
1917 alpha_ecoff_swap_scnhdr_in
, alpha_ecoff_bad_format_hook
,
1918 ecoff_set_arch_mach_hook
, ecoff_mkobject_hook
,
1919 ecoff_styp_to_sec_flags
, ecoff_make_section_hook
, ecoff_set_alignment_hook
,
1920 ecoff_slurp_symbol_table
, NULL
, NULL
1922 /* Supported architecture. */
1924 /* Initial portion of armap string. */
1926 /* The page boundary used to align sections in a demand-paged
1927 executable file. E.g., 0x1000. */
1929 /* True if the .rdata section is part of the text segment, as on the
1930 Alpha. False if .rdata is part of the data segment, as on the
1933 /* Bitsize of constructor entries. */
1935 /* Reloc to use for constructor entries. */
1936 &alpha_howto_table
[ALPHA_R_REFQUAD
],
1938 /* Symbol table magic number. */
1940 /* Alignment of debugging information. E.g., 4. */
1942 /* Sizes of external symbolic information. */
1943 sizeof (struct hdr_ext
),
1944 sizeof (struct dnr_ext
),
1945 sizeof (struct pdr_ext
),
1946 sizeof (struct sym_ext
),
1947 sizeof (struct opt_ext
),
1948 sizeof (struct fdr_ext
),
1949 sizeof (struct rfd_ext
),
1950 sizeof (struct ext_ext
),
1951 /* Functions to swap in external symbolic data. */
1960 /* Functions to swap out external symbolic data. */
1970 /* External reloc size. */
1972 /* Reloc swapping functions. */
1973 alpha_ecoff_swap_reloc_in
,
1974 alpha_ecoff_swap_reloc_out
,
1975 /* Backend reloc tweaking. */
1976 alpha_adjust_reloc_in
,
1977 alpha_adjust_reloc_out
,
1978 /* Relocate section contents while linking. */
1979 alpha_relocate_section
1982 /* Looking up a reloc type is Alpha specific. */
1983 #define ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
1985 /* So is getting relocated section contents. */
1986 #define ecoff_bfd_get_relocated_section_contents \
1987 alpha_ecoff_get_relocated_section_contents
1989 /* Relaxing sections is generic. */
1990 #define ecoff_bfd_relax_section bfd_generic_relax_section
1992 bfd_target ecoffalpha_little_vec
=
1994 "ecoff-littlealpha", /* name */
1995 bfd_target_ecoff_flavour
,
1996 false, /* data byte order is little */
1997 false, /* header byte order is little */
1999 (HAS_RELOC
| EXEC_P
| /* object flags */
2000 HAS_LINENO
| HAS_DEBUG
|
2001 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
2003 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* sect
2005 0, /* leading underscore */
2006 ' ', /* ar_pad_char */
2007 15, /* ar_max_namelen */
2008 4, /* minimum alignment power */
2009 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2010 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2011 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2012 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2013 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2014 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2016 {_bfd_dummy_target
, alpha_ecoff_object_p
, /* bfd_check_format */
2017 ecoff_archive_p
, _bfd_dummy_target
},
2018 {bfd_false
, ecoff_mkobject
, /* bfd_set_format */
2019 _bfd_generic_mkarchive
, bfd_false
},
2020 {bfd_false
, ecoff_write_object_contents
, /* bfd_write_contents */
2021 _bfd_write_archive_contents
, bfd_false
},
2023 (PTR
) &alpha_ecoff_backend_data