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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 const bfd_target
*alpha_ecoff_object_p
PARAMS ((bfd
*));
37 static boolean alpha_ecoff_bad_format_hook
PARAMS ((bfd
*abfd
, PTR filehdr
));
38 static PTR alpha_ecoff_mkobject_hook
PARAMS ((bfd
*, PTR filehdr
, PTR aouthdr
));
39 static void alpha_ecoff_swap_reloc_in
PARAMS ((bfd
*, PTR
,
40 struct internal_reloc
*));
41 static void alpha_ecoff_swap_reloc_out
PARAMS ((bfd
*,
42 const struct internal_reloc
*,
44 static void alpha_adjust_reloc_in
PARAMS ((bfd
*,
45 const struct internal_reloc
*,
47 static void alpha_adjust_reloc_out
PARAMS ((bfd
*, const arelent
*,
48 struct internal_reloc
*));
49 static bfd_byte
*alpha_ecoff_get_relocated_section_contents
50 PARAMS ((bfd
*abfd
, struct bfd_link_info
*, struct bfd_link_order
*,
51 bfd_byte
*data
, boolean relocateable
, asymbol
**symbols
));
52 static bfd_vma alpha_convert_external_reloc
53 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, struct external_reloc
*,
54 struct ecoff_link_hash_entry
*));
55 static boolean alpha_relocate_section
PARAMS ((bfd
*, struct bfd_link_info
*,
58 static boolean alpha_adjust_headers
59 PARAMS ((bfd
*, struct internal_filehdr
*, struct internal_aouthdr
*));
61 /* ECOFF has COFF sections, but the debugging information is stored in
62 a completely different format. ECOFF targets use some of the
63 swapping routines from coffswap.h, and some of the generic COFF
64 routines in coffgen.c, but, unlike the real COFF targets, do not
65 use coffcode.h itself.
67 Get the generic COFF swapping routines, except for the reloc,
68 symbol, and lineno ones. Give them ecoff names. Define some
69 accessor macros for the large sizes used for Alpha ECOFF. */
71 #define GET_FILEHDR_SYMPTR bfd_h_get_64
72 #define PUT_FILEHDR_SYMPTR bfd_h_put_64
73 #define GET_AOUTHDR_TSIZE bfd_h_get_64
74 #define PUT_AOUTHDR_TSIZE bfd_h_put_64
75 #define GET_AOUTHDR_DSIZE bfd_h_get_64
76 #define PUT_AOUTHDR_DSIZE bfd_h_put_64
77 #define GET_AOUTHDR_BSIZE bfd_h_get_64
78 #define PUT_AOUTHDR_BSIZE bfd_h_put_64
79 #define GET_AOUTHDR_ENTRY bfd_h_get_64
80 #define PUT_AOUTHDR_ENTRY bfd_h_put_64
81 #define GET_AOUTHDR_TEXT_START bfd_h_get_64
82 #define PUT_AOUTHDR_TEXT_START bfd_h_put_64
83 #define GET_AOUTHDR_DATA_START bfd_h_get_64
84 #define PUT_AOUTHDR_DATA_START bfd_h_put_64
85 #define GET_SCNHDR_PADDR bfd_h_get_64
86 #define PUT_SCNHDR_PADDR bfd_h_put_64
87 #define GET_SCNHDR_VADDR bfd_h_get_64
88 #define PUT_SCNHDR_VADDR bfd_h_put_64
89 #define GET_SCNHDR_SIZE bfd_h_get_64
90 #define PUT_SCNHDR_SIZE bfd_h_put_64
91 #define GET_SCNHDR_SCNPTR bfd_h_get_64
92 #define PUT_SCNHDR_SCNPTR bfd_h_put_64
93 #define GET_SCNHDR_RELPTR bfd_h_get_64
94 #define PUT_SCNHDR_RELPTR bfd_h_put_64
95 #define GET_SCNHDR_LNNOPTR bfd_h_get_64
96 #define PUT_SCNHDR_LNNOPTR bfd_h_put_64
100 #define NO_COFF_RELOCS
101 #define NO_COFF_SYMBOLS
102 #define NO_COFF_LINENOS
103 #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in
104 #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out
105 #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in
106 #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out
107 #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in
108 #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out
109 #include "coffswap.h"
111 /* Get the ECOFF swapping routines. */
113 #include "ecoffswap.h"
115 /* How to process the various reloc types. */
117 static bfd_reloc_status_type
118 reloc_nil
PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
,
119 asection
*, bfd
*, char **));
121 static bfd_reloc_status_type
122 reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
129 char **error_message
;
134 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
135 from smaller values. Start with zero, widen, *then* decrement. */
136 #define MINUS_ONE (((bfd_vma)0) - 1)
138 static reloc_howto_type alpha_howto_table
[] =
140 /* Reloc type 0 is ignored by itself. However, it appears after a
141 GPDISP reloc to identify the location where the low order 16 bits
142 of the gp register are loaded. */
143 HOWTO (ALPHA_R_IGNORE
, /* type */
145 0, /* size (0 = byte, 1 = short, 2 = long) */
147 true, /* pc_relative */
149 complain_overflow_dont
, /* complain_on_overflow */
150 reloc_nil
, /* special_function */
152 true, /* partial_inplace */
155 true), /* pcrel_offset */
157 /* A 32 bit reference to a symbol. */
158 HOWTO (ALPHA_R_REFLONG
, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 false, /* pc_relative */
164 complain_overflow_bitfield
, /* complain_on_overflow */
165 0, /* special_function */
166 "REFLONG", /* name */
167 true, /* partial_inplace */
168 0xffffffff, /* src_mask */
169 0xffffffff, /* dst_mask */
170 false), /* pcrel_offset */
172 /* A 64 bit reference to a symbol. */
173 HOWTO (ALPHA_R_REFQUAD
, /* type */
175 4, /* size (0 = byte, 1 = short, 2 = long) */
177 false, /* pc_relative */
179 complain_overflow_bitfield
, /* complain_on_overflow */
180 0, /* special_function */
181 "REFQUAD", /* name */
182 true, /* partial_inplace */
183 MINUS_ONE
, /* src_mask */
184 MINUS_ONE
, /* dst_mask */
185 false), /* pcrel_offset */
187 /* A 32 bit GP relative offset. This is just like REFLONG except
188 that when the value is used the value of the gp register will be
190 HOWTO (ALPHA_R_GPREL32
, /* type */
192 2, /* size (0 = byte, 1 = short, 2 = long) */
194 false, /* pc_relative */
196 complain_overflow_bitfield
, /* complain_on_overflow */
197 0, /* special_function */
198 "GPREL32", /* name */
199 true, /* partial_inplace */
200 0xffffffff, /* src_mask */
201 0xffffffff, /* dst_mask */
202 false), /* pcrel_offset */
204 /* Used for an instruction that refers to memory off the GP
205 register. The offset is 16 bits of the 32 bit instruction. This
206 reloc always seems to be against the .lita section. */
207 HOWTO (ALPHA_R_LITERAL
, /* type */
209 2, /* size (0 = byte, 1 = short, 2 = long) */
211 false, /* pc_relative */
213 complain_overflow_signed
, /* complain_on_overflow */
214 0, /* special_function */
215 "LITERAL", /* name */
216 true, /* partial_inplace */
217 0xffff, /* src_mask */
218 0xffff, /* dst_mask */
219 false), /* pcrel_offset */
221 /* This reloc only appears immediately following a LITERAL reloc.
222 It identifies a use of the literal. It seems that the linker can
223 use this to eliminate a portion of the .lita section. The symbol
224 index is special: 1 means the literal address is in the base
225 register of a memory format instruction; 2 means the literal
226 address is in the byte offset register of a byte-manipulation
227 instruction; 3 means the literal address is in the target
228 register of a jsr instruction. This does not actually do any
230 HOWTO (ALPHA_R_LITUSE
, /* type */
232 2, /* size (0 = byte, 1 = short, 2 = long) */
234 false, /* pc_relative */
236 complain_overflow_dont
, /* complain_on_overflow */
237 reloc_nil
, /* special_function */
239 false, /* partial_inplace */
242 false), /* pcrel_offset */
244 /* Load the gp register. This is always used for a ldah instruction
245 which loads the upper 16 bits of the gp register. The next reloc
246 will be an IGNORE reloc which identifies the location of the lda
247 instruction which loads the lower 16 bits. The symbol index of
248 the GPDISP instruction appears to actually be the number of bytes
249 between the ldah and lda instructions. This gives two different
250 ways to determine where the lda instruction is; I don't know why
251 both are used. The value to use for the relocation is the
252 difference between the GP value and the current location; the
253 load will always be done against a register holding the current
255 HOWTO (ALPHA_R_GPDISP
, /* type */
257 2, /* size (0 = byte, 1 = short, 2 = long) */
259 true, /* pc_relative */
261 complain_overflow_dont
, /* complain_on_overflow */
262 reloc_nil
, /* special_function */
264 true, /* partial_inplace */
265 0xffff, /* src_mask */
266 0xffff, /* dst_mask */
267 true), /* pcrel_offset */
269 /* A 21 bit branch. The native assembler generates these for
270 branches within the text segment, and also fills in the PC
271 relative offset in the instruction. */
272 HOWTO (ALPHA_R_BRADDR
, /* type */
274 2, /* size (0 = byte, 1 = short, 2 = long) */
276 true, /* pc_relative */
278 complain_overflow_signed
, /* complain_on_overflow */
279 0, /* special_function */
281 true, /* partial_inplace */
282 0x1fffff, /* src_mask */
283 0x1fffff, /* dst_mask */
284 false), /* pcrel_offset */
286 /* A hint for a jump to a register. */
287 HOWTO (ALPHA_R_HINT
, /* type */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
291 true, /* pc_relative */
293 complain_overflow_dont
, /* complain_on_overflow */
294 0, /* special_function */
296 true, /* partial_inplace */
297 0x3fff, /* src_mask */
298 0x3fff, /* dst_mask */
299 false), /* pcrel_offset */
301 /* 16 bit PC relative offset. */
302 HOWTO (ALPHA_R_SREL16
, /* type */
304 1, /* size (0 = byte, 1 = short, 2 = long) */
306 true, /* pc_relative */
308 complain_overflow_signed
, /* complain_on_overflow */
309 0, /* special_function */
311 true, /* partial_inplace */
312 0xffff, /* src_mask */
313 0xffff, /* dst_mask */
314 false), /* pcrel_offset */
316 /* 32 bit PC relative offset. */
317 HOWTO (ALPHA_R_SREL32
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 true, /* pc_relative */
323 complain_overflow_signed
, /* complain_on_overflow */
324 0, /* special_function */
326 true, /* partial_inplace */
327 0xffffffff, /* src_mask */
328 0xffffffff, /* dst_mask */
329 false), /* pcrel_offset */
331 /* A 64 bit PC relative offset. */
332 HOWTO (ALPHA_R_SREL64
, /* type */
334 4, /* size (0 = byte, 1 = short, 2 = long) */
336 true, /* pc_relative */
338 complain_overflow_signed
, /* complain_on_overflow */
339 0, /* special_function */
341 true, /* partial_inplace */
342 MINUS_ONE
, /* src_mask */
343 MINUS_ONE
, /* dst_mask */
344 false), /* pcrel_offset */
346 /* Push a value on the reloc evaluation stack. */
347 HOWTO (ALPHA_R_OP_PUSH
, /* type */
349 0, /* size (0 = byte, 1 = short, 2 = long) */
351 false, /* pc_relative */
353 complain_overflow_dont
, /* complain_on_overflow */
354 0, /* special_function */
355 "OP_PUSH", /* name */
356 false, /* partial_inplace */
359 false), /* pcrel_offset */
361 /* Store the value from the stack at the given address. Store it in
362 a bitfield of size r_size starting at bit position r_offset. */
363 HOWTO (ALPHA_R_OP_STORE
, /* type */
365 4, /* size (0 = byte, 1 = short, 2 = long) */
367 false, /* pc_relative */
369 complain_overflow_dont
, /* complain_on_overflow */
370 0, /* special_function */
371 "OP_STORE", /* name */
372 false, /* partial_inplace */
374 MINUS_ONE
, /* dst_mask */
375 false), /* pcrel_offset */
377 /* Subtract the reloc address from the value on the top of the
379 HOWTO (ALPHA_R_OP_PSUB
, /* type */
381 0, /* size (0 = byte, 1 = short, 2 = long) */
383 false, /* pc_relative */
385 complain_overflow_dont
, /* complain_on_overflow */
386 0, /* special_function */
387 "OP_PSUB", /* name */
388 false, /* partial_inplace */
391 false), /* pcrel_offset */
393 /* Shift the value on the top of the relocation stack right by the
395 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
397 0, /* size (0 = byte, 1 = short, 2 = long) */
399 false, /* pc_relative */
401 complain_overflow_dont
, /* complain_on_overflow */
402 0, /* special_function */
403 "OP_PRSHIFT", /* name */
404 false, /* partial_inplace */
407 false), /* pcrel_offset */
409 /* Adjust the GP value for a new range in the object file. */
410 HOWTO (ALPHA_R_GPVALUE
, /* type */
412 0, /* size (0 = byte, 1 = short, 2 = long) */
414 false, /* pc_relative */
416 complain_overflow_dont
, /* complain_on_overflow */
417 0, /* special_function */
418 "GPVALUE", /* name */
419 false, /* partial_inplace */
422 false) /* pcrel_offset */
425 /* Recognize an Alpha ECOFF file. */
427 static const bfd_target
*
428 alpha_ecoff_object_p (abfd
)
431 static const bfd_target
*ret
;
433 ret
= coff_object_p (abfd
);
439 /* Alpha ECOFF has a .pdata section. The lnnoptr field of the
440 .pdata section is the number of entries it contains. Each
441 entry takes up 8 bytes. The number of entries is required
442 since the section is aligned to a 16 byte boundary. When we
443 link .pdata sections together, we do not want to include the
444 alignment bytes. We handle this on input by faking the size
445 of the .pdata section to remove the unwanted alignment bytes.
446 On output we will set the lnnoptr field and force the
448 sec
= bfd_get_section_by_name (abfd
, _PDATA
);
449 if (sec
!= (asection
*) NULL
)
453 size
= sec
->line_filepos
* 8;
454 BFD_ASSERT (size
== bfd_section_size (abfd
, sec
)
455 || size
+ 8 == bfd_section_size (abfd
, sec
));
456 if (! bfd_set_section_size (abfd
, sec
, size
))
464 /* See whether the magic number matches. */
467 alpha_ecoff_bad_format_hook (abfd
, filehdr
)
471 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
473 if (ALPHA_ECOFF_BADMAG (*internal_f
))
479 /* This is a hook called by coff_real_object_p to create any backend
480 specific information. */
483 alpha_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
)
490 ecoff
= _bfd_ecoff_mkobject_hook (abfd
, filehdr
, aouthdr
);
494 struct internal_filehdr
*internal_f
= (struct internal_filehdr
*) filehdr
;
496 /* Set additional BFD flags according to the object type from the
497 machine specific file header flags. */
498 switch (internal_f
->f_flags
& F_ALPHA_OBJECT_TYPE_MASK
)
500 case F_ALPHA_SHARABLE
:
501 abfd
->flags
|= DYNAMIC
;
503 case F_ALPHA_CALL_SHARED
:
504 /* Always executable if using shared libraries as the run time
505 loader might resolve undefined references. */
506 abfd
->flags
|= (DYNAMIC
| EXEC_P
);
513 /* Reloc handling. */
515 /* Swap a reloc in. */
518 alpha_ecoff_swap_reloc_in (abfd
, ext_ptr
, intern
)
521 struct internal_reloc
*intern
;
523 const RELOC
*ext
= (RELOC
*) ext_ptr
;
525 intern
->r_vaddr
= bfd_h_get_64 (abfd
, (bfd_byte
*) ext
->r_vaddr
);
526 intern
->r_symndx
= bfd_h_get_32 (abfd
, (bfd_byte
*) ext
->r_symndx
);
528 BFD_ASSERT (abfd
->xvec
->header_byteorder_big_p
== false);
530 intern
->r_type
= ((ext
->r_bits
[0] & RELOC_BITS0_TYPE_LITTLE
)
531 >> RELOC_BITS0_TYPE_SH_LITTLE
);
532 intern
->r_extern
= (ext
->r_bits
[1] & RELOC_BITS1_EXTERN_LITTLE
) != 0;
533 intern
->r_offset
= ((ext
->r_bits
[1] & RELOC_BITS1_OFFSET_LITTLE
)
534 >> RELOC_BITS1_OFFSET_SH_LITTLE
);
535 /* Ignored the reserved bits. */
536 intern
->r_size
= ((ext
->r_bits
[3] & RELOC_BITS3_SIZE_LITTLE
)
537 >> RELOC_BITS3_SIZE_SH_LITTLE
);
539 if (intern
->r_type
== ALPHA_R_LITUSE
540 || intern
->r_type
== ALPHA_R_GPDISP
)
542 /* Handle the LITUSE and GPDISP relocs specially. Its symndx
543 value is not actually a symbol index, but is instead a
544 special code. We put the code in the r_size field, and
545 clobber the symndx. */
546 if (intern
->r_size
!= 0)
548 intern
->r_size
= intern
->r_symndx
;
549 intern
->r_symndx
= RELOC_SECTION_NONE
;
551 else if (intern
->r_type
== ALPHA_R_IGNORE
)
553 /* The IGNORE reloc generally follows a GPDISP reloc, and is
554 against the .lita section. The section is irrelevant. */
555 if (! intern
->r_extern
&&
556 intern
->r_symndx
== RELOC_SECTION_ABS
)
558 if (! intern
->r_extern
&& intern
->r_symndx
== RELOC_SECTION_LITA
)
559 intern
->r_symndx
= RELOC_SECTION_ABS
;
563 /* Swap a reloc out. */
566 alpha_ecoff_swap_reloc_out (abfd
, intern
, dst
)
568 const struct internal_reloc
*intern
;
571 RELOC
*ext
= (RELOC
*) dst
;
575 /* Undo the hackery done in swap_reloc_in. */
576 if (intern
->r_type
== ALPHA_R_LITUSE
577 || intern
->r_type
== ALPHA_R_GPDISP
)
579 symndx
= intern
->r_size
;
582 else if (intern
->r_type
== ALPHA_R_IGNORE
583 && ! intern
->r_extern
584 && intern
->r_symndx
== RELOC_SECTION_ABS
)
586 symndx
= RELOC_SECTION_LITA
;
587 size
= intern
->r_size
;
591 symndx
= intern
->r_symndx
;
592 size
= intern
->r_size
;
595 BFD_ASSERT (intern
->r_extern
596 || (intern
->r_symndx
>= 0 && intern
->r_symndx
<= 14));
598 bfd_h_put_64 (abfd
, intern
->r_vaddr
, (bfd_byte
*) ext
->r_vaddr
);
599 bfd_h_put_32 (abfd
, symndx
, (bfd_byte
*) ext
->r_symndx
);
601 BFD_ASSERT (abfd
->xvec
->header_byteorder_big_p
== false);
603 ext
->r_bits
[0] = ((intern
->r_type
<< RELOC_BITS0_TYPE_SH_LITTLE
)
604 & RELOC_BITS0_TYPE_LITTLE
);
605 ext
->r_bits
[1] = ((intern
->r_extern
? RELOC_BITS1_EXTERN_LITTLE
: 0)
606 | ((intern
->r_offset
<< RELOC_BITS1_OFFSET_SH_LITTLE
)
607 & RELOC_BITS1_OFFSET_LITTLE
));
609 ext
->r_bits
[3] = ((size
<< RELOC_BITS3_SIZE_SH_LITTLE
)
610 & RELOC_BITS3_SIZE_LITTLE
);
613 /* Finish canonicalizing a reloc. Part of this is generic to all
614 ECOFF targets, and that part is in ecoff.c. The rest is done in
615 this backend routine. It must fill in the howto field. */
618 alpha_adjust_reloc_in (abfd
, intern
, rptr
)
620 const struct internal_reloc
*intern
;
623 if (intern
->r_type
> ALPHA_R_GPVALUE
)
626 switch (intern
->r_type
)
632 /* The PC relative relocs do not seem to use the section VMA as
633 a negative addend. */
637 case ALPHA_R_GPREL32
:
638 case ALPHA_R_LITERAL
:
639 /* Copy the gp value for this object file into the addend, to
640 ensure that we are not confused by the linker. */
641 if (! intern
->r_extern
)
642 rptr
->addend
+= ecoff_data (abfd
)->gp
;
647 /* The LITUSE and GPDISP relocs do not use a symbol, or an
648 addend, but they do use a special code. Put this code in the
650 rptr
->addend
= intern
->r_size
;
653 case ALPHA_R_OP_STORE
:
654 /* The STORE reloc needs the size and offset fields. We store
655 them in the addend. */
656 BFD_ASSERT (intern
->r_offset
<= 256 && intern
->r_size
<= 256);
657 rptr
->addend
= (intern
->r_offset
<< 8) + intern
->r_size
;
660 case ALPHA_R_OP_PUSH
:
661 case ALPHA_R_OP_PSUB
:
662 case ALPHA_R_OP_PRSHIFT
:
663 /* The PUSH, PSUB and PRSHIFT relocs do not actually use an
664 address. I believe that the address supplied is really an
666 rptr
->addend
= intern
->r_vaddr
;
669 case ALPHA_R_GPVALUE
:
670 /* Set the addend field to the new GP value. */
671 rptr
->addend
= intern
->r_symndx
+ ecoff_data (abfd
)->gp
;
675 /* If the type is ALPHA_R_IGNORE, make sure this is a reference
676 to the absolute section so that the reloc is ignored. For
677 some reason the address of this reloc type is not adjusted by
678 the section vma. We record the gp value for this object file
679 here, for convenience when doing the GPDISP relocation. */
680 rptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
681 rptr
->address
= intern
->r_vaddr
;
682 rptr
->addend
= ecoff_data (abfd
)->gp
;
689 rptr
->howto
= &alpha_howto_table
[intern
->r_type
];
692 /* When writing out a reloc we need to pull some values back out of
693 the addend field into the reloc. This is roughly the reverse of
694 alpha_adjust_reloc_in, except that there are several changes we do
698 alpha_adjust_reloc_out (abfd
, rel
, intern
)
701 struct internal_reloc
*intern
;
703 switch (intern
->r_type
)
707 intern
->r_size
= rel
->addend
;
710 case ALPHA_R_OP_STORE
:
711 intern
->r_size
= rel
->addend
& 0xff;
712 intern
->r_offset
= (rel
->addend
>> 8) & 0xff;
715 case ALPHA_R_OP_PUSH
:
716 case ALPHA_R_OP_PSUB
:
717 case ALPHA_R_OP_PRSHIFT
:
718 intern
->r_vaddr
= rel
->addend
;
722 intern
->r_vaddr
= rel
->address
;
730 /* The size of the stack for the relocation evaluator. */
731 #define RELOC_STACKSIZE (10)
733 /* Alpha ECOFF relocs have a built in expression evaluator as well as
734 other interdependencies. Rather than use a bunch of special
735 functions and global variables, we use a single routine to do all
736 the relocation for a section. I haven't yet worked out how the
737 assembler is going to handle this. */
740 alpha_ecoff_get_relocated_section_contents (abfd
, link_info
, link_order
,
741 data
, relocateable
, symbols
)
743 struct bfd_link_info
*link_info
;
744 struct bfd_link_order
*link_order
;
746 boolean relocateable
;
749 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
750 asection
*input_section
= link_order
->u
.indirect
.section
;
751 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
752 arelent
**reloc_vector
= NULL
;
754 bfd
*output_bfd
= relocateable
? abfd
: (bfd
*) NULL
;
756 boolean gp_undefined
;
757 bfd_vma stack
[RELOC_STACKSIZE
];
762 reloc_vector
= (arelent
**) bfd_malloc (reloc_size
);
763 if (reloc_vector
== NULL
&& reloc_size
!= 0)
766 if (! bfd_get_section_contents (input_bfd
, input_section
, data
,
767 (file_ptr
) 0, input_section
->_raw_size
))
770 /* The section size is not going to change. */
771 input_section
->_cooked_size
= input_section
->_raw_size
;
772 input_section
->reloc_done
= true;
774 reloc_count
= bfd_canonicalize_reloc (input_bfd
, input_section
,
775 reloc_vector
, symbols
);
778 if (reloc_count
== 0)
779 goto successful_return
;
781 /* Get the GP value for the output BFD. */
782 gp_undefined
= false;
783 if (ecoff_data (abfd
)->gp
== 0)
785 if (relocateable
!= false)
790 /* Make up a value. */
792 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
795 && (strcmp (sec
->name
, ".sbss") == 0
796 || strcmp (sec
->name
, ".sdata") == 0
797 || strcmp (sec
->name
, ".lit4") == 0
798 || strcmp (sec
->name
, ".lit8") == 0
799 || strcmp (sec
->name
, ".lita") == 0))
802 ecoff_data (abfd
)->gp
= lo
+ 0x8000;
806 struct bfd_link_hash_entry
*h
;
808 h
= bfd_link_hash_lookup (link_info
->hash
, "_gp", false, false,
810 if (h
== (struct bfd_link_hash_entry
*) NULL
811 || h
->type
!= bfd_link_hash_defined
)
814 ecoff_data (abfd
)->gp
= (h
->u
.def
.value
815 + h
->u
.def
.section
->output_section
->vma
816 + h
->u
.def
.section
->output_offset
);
819 gp
= ecoff_data (abfd
)->gp
;
821 for (; *reloc_vector
!= (arelent
*) NULL
; reloc_vector
++)
824 bfd_reloc_status_type r
;
829 switch (rel
->howto
->type
)
832 rel
->address
+= input_section
->output_offset
;
835 case ALPHA_R_REFLONG
:
836 case ALPHA_R_REFQUAD
:
843 && ((*rel
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) == 0)
845 rel
->address
+= input_section
->output_offset
;
848 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
852 case ALPHA_R_GPREL32
:
853 /* This relocation is used in a switch table. It is a 32
854 bit offset from the current GP value. We must adjust it
855 by the different between the original GP value and the
856 current GP value. The original GP value is stored in the
857 addend. We adjust the addend and let
858 bfd_perform_relocation finish the job. */
860 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
862 if (r
== bfd_reloc_ok
&& gp_undefined
)
864 r
= bfd_reloc_dangerous
;
865 err
= (char *) "GP relative relocation used when GP not defined";
869 case ALPHA_R_LITERAL
:
870 /* This is a reference to a literal value, generally
871 (always?) in the .lita section. This is a 16 bit GP
872 relative relocation. Sometimes the subsequent reloc is a
873 LITUSE reloc, which indicates how this reloc is used.
874 This sometimes permits rewriting the two instructions
875 referred to by the LITERAL and the LITUSE into different
876 instructions which do not refer to .lita. This can save
877 a memory reference, and permits removing a value from
878 .lita thus saving GP relative space.
880 We do not these optimizations. To do them we would need
881 to arrange to link the .lita section first, so that by
882 the time we got here we would know the final values to
883 use. This would not be particularly difficult, but it is
884 not currently implemented. */
889 /* I believe that the LITERAL reloc will only apply to a
890 ldq or ldl instruction, so check my assumption. */
891 insn
= bfd_get_32 (input_bfd
, data
+ rel
->address
);
892 BFD_ASSERT (((insn
>> 26) & 0x3f) == 0x29
893 || ((insn
>> 26) & 0x3f) == 0x28);
896 r
= bfd_perform_relocation (input_bfd
, rel
, data
, input_section
,
898 if (r
== bfd_reloc_ok
&& gp_undefined
)
900 r
= bfd_reloc_dangerous
;
902 (char *) "GP relative relocation used when GP not defined";
908 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
909 does not cause anything to happen, itself. */
910 rel
->address
+= input_section
->output_offset
;
914 /* This marks the ldah of an ldah/lda pair which loads the
915 gp register with the difference of the gp value and the
916 current location. The second of the pair is r_size bytes
917 ahead, and is marked with an ALPHA_R_IGNORE reloc. */
919 unsigned long insn1
, insn2
;
922 BFD_ASSERT (reloc_vector
[1] != NULL
923 && reloc_vector
[1]->howto
->type
== ALPHA_R_IGNORE
924 && (rel
->address
+ rel
->addend
925 == reloc_vector
[1]->address
));
927 /* Get the two instructions. */
928 insn1
= bfd_get_32 (input_bfd
, data
+ rel
->address
);
929 insn2
= bfd_get_32 (input_bfd
, data
+ rel
->address
+ rel
->addend
);
931 BFD_ASSERT (((insn1
>> 26) & 0x3f) == 0x09); /* ldah */
932 BFD_ASSERT (((insn2
>> 26) & 0x3f) == 0x08); /* lda */
934 /* Get the existing addend. We must account for the sign
935 extension done by lda and ldah. */
936 addend
= ((insn1
& 0xffff) << 16) + (insn2
& 0xffff);
939 addend
-= 0x80000000;
940 addend
-= 0x80000000;
945 /* The existing addend includes the different between the
946 gp of the input BFD and the address in the input BFD.
947 Subtract this out. */
948 addend
-= (reloc_vector
[1]->addend
949 - (input_section
->vma
+ rel
->address
));
951 /* Now add in the final gp value, and subtract out the
954 - (input_section
->output_section
->vma
955 + input_section
->output_offset
958 /* Change the instructions, accounting for the sign
959 extension, and write them out. */
962 insn1
= (insn1
& 0xffff0000) | ((addend
>> 16) & 0xffff);
963 insn2
= (insn2
& 0xffff0000) | (addend
& 0xffff);
965 bfd_put_32 (input_bfd
, (bfd_vma
) insn1
, data
+ rel
->address
);
966 bfd_put_32 (input_bfd
, (bfd_vma
) insn2
,
967 data
+ rel
->address
+ rel
->addend
);
969 rel
->address
+= input_section
->output_offset
;
973 case ALPHA_R_OP_PUSH
:
974 /* Push a value on the reloc evaluation stack. */
981 rel
->address
+= input_section
->output_offset
;
985 /* Figure out the relocation of this symbol. */
986 symbol
= *rel
->sym_ptr_ptr
;
988 if (bfd_is_und_section (symbol
->section
))
989 r
= bfd_reloc_undefined
;
991 if (bfd_is_com_section (symbol
->section
))
994 relocation
= symbol
->value
;
995 relocation
+= symbol
->section
->output_section
->vma
;
996 relocation
+= symbol
->section
->output_offset
;
997 relocation
+= rel
->addend
;
999 if (tos
>= RELOC_STACKSIZE
)
1002 stack
[tos
++] = relocation
;
1006 case ALPHA_R_OP_STORE
:
1007 /* Store a value from the reloc stack into a bitfield. */
1014 rel
->address
+= input_section
->output_offset
;
1021 /* The offset and size for this reloc are encoded into the
1022 addend field by alpha_adjust_reloc_in. */
1023 offset
= (rel
->addend
>> 8) & 0xff;
1024 size
= rel
->addend
& 0xff;
1026 val
= bfd_get_64 (abfd
, data
+ rel
->address
);
1027 val
&=~ (((1 << size
) - 1) << offset
);
1028 val
|= (stack
[--tos
] & ((1 << size
) - 1)) << offset
;
1029 bfd_put_64 (abfd
, val
, data
+ rel
->address
);
1033 case ALPHA_R_OP_PSUB
:
1034 /* Subtract a value from the top of the stack. */
1041 rel
->address
+= input_section
->output_offset
;
1045 /* Figure out the relocation of this symbol. */
1046 symbol
= *rel
->sym_ptr_ptr
;
1048 if (bfd_is_und_section (symbol
->section
))
1049 r
= bfd_reloc_undefined
;
1051 if (bfd_is_com_section (symbol
->section
))
1054 relocation
= symbol
->value
;
1055 relocation
+= symbol
->section
->output_section
->vma
;
1056 relocation
+= symbol
->section
->output_offset
;
1057 relocation
+= rel
->addend
;
1062 stack
[tos
- 1] -= relocation
;
1066 case ALPHA_R_OP_PRSHIFT
:
1067 /* Shift the value on the top of the stack. */
1074 rel
->address
+= input_section
->output_offset
;
1078 /* Figure out the relocation of this symbol. */
1079 symbol
= *rel
->sym_ptr_ptr
;
1081 if (bfd_is_und_section (symbol
->section
))
1082 r
= bfd_reloc_undefined
;
1084 if (bfd_is_com_section (symbol
->section
))
1087 relocation
= symbol
->value
;
1088 relocation
+= symbol
->section
->output_section
->vma
;
1089 relocation
+= symbol
->section
->output_offset
;
1090 relocation
+= rel
->addend
;
1095 stack
[tos
- 1] >>= relocation
;
1099 case ALPHA_R_GPVALUE
:
1100 /* I really don't know if this does the right thing. */
1102 gp_undefined
= false;
1111 asection
*os
= input_section
->output_section
;
1113 /* A partial link, so keep the relocs. */
1114 os
->orelocation
[os
->reloc_count
] = rel
;
1118 if (r
!= bfd_reloc_ok
)
1122 case bfd_reloc_undefined
:
1123 if (! ((*link_info
->callbacks
->undefined_symbol
)
1124 (link_info
, bfd_asymbol_name (*rel
->sym_ptr_ptr
),
1125 input_bfd
, input_section
, rel
->address
)))
1128 case bfd_reloc_dangerous
:
1129 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1130 (link_info
, err
, input_bfd
, input_section
,
1134 case bfd_reloc_overflow
:
1135 if (! ((*link_info
->callbacks
->reloc_overflow
)
1136 (link_info
, bfd_asymbol_name (*rel
->sym_ptr_ptr
),
1137 rel
->howto
->name
, rel
->addend
, input_bfd
,
1138 input_section
, rel
->address
)))
1141 case bfd_reloc_outofrange
:
1153 if (reloc_vector
!= NULL
)
1154 free (reloc_vector
);
1158 if (reloc_vector
!= NULL
)
1159 free (reloc_vector
);
1163 /* Get the howto structure for a generic reloc type. */
1165 static reloc_howto_type
*
1166 alpha_bfd_reloc_type_lookup (abfd
, code
)
1168 bfd_reloc_code_real_type code
;
1175 alpha_type
= ALPHA_R_REFLONG
;
1178 case BFD_RELOC_CTOR
:
1179 alpha_type
= ALPHA_R_REFQUAD
;
1181 case BFD_RELOC_GPREL32
:
1182 alpha_type
= ALPHA_R_GPREL32
;
1184 case BFD_RELOC_ALPHA_LITERAL
:
1185 alpha_type
= ALPHA_R_LITERAL
;
1187 case BFD_RELOC_ALPHA_LITUSE
:
1188 alpha_type
= ALPHA_R_LITUSE
;
1190 case BFD_RELOC_ALPHA_GPDISP_HI16
:
1191 alpha_type
= ALPHA_R_GPDISP
;
1193 case BFD_RELOC_ALPHA_GPDISP_LO16
:
1194 alpha_type
= ALPHA_R_IGNORE
;
1196 case BFD_RELOC_23_PCREL_S2
:
1197 alpha_type
= ALPHA_R_BRADDR
;
1199 case BFD_RELOC_ALPHA_HINT
:
1200 alpha_type
= ALPHA_R_HINT
;
1202 case BFD_RELOC_16_PCREL
:
1203 alpha_type
= ALPHA_R_SREL16
;
1205 case BFD_RELOC_32_PCREL
:
1206 alpha_type
= ALPHA_R_SREL32
;
1208 case BFD_RELOC_64_PCREL
:
1209 alpha_type
= ALPHA_R_SREL64
;
1213 alpha_type
= ALPHA_R_OP_PUSH
;
1216 alpha_type
= ALPHA_R_OP_STORE
;
1219 alpha_type
= ALPHA_R_OP_PSUB
;
1222 alpha_type
= ALPHA_R_OP_PRSHIFT
;
1225 alpha_type
= ALPHA_R_GPVALUE
;
1229 return (reloc_howto_type
*) NULL
;
1232 return &alpha_howto_table
[alpha_type
];
1235 /* A helper routine for alpha_relocate_section which converts an
1236 external reloc when generating relocateable output. Returns the
1237 relocation amount. */
1240 alpha_convert_external_reloc (output_bfd
, info
, input_bfd
, ext_rel
, h
)
1242 struct bfd_link_info
*info
;
1244 struct external_reloc
*ext_rel
;
1245 struct ecoff_link_hash_entry
*h
;
1247 unsigned long r_symndx
;
1250 BFD_ASSERT (info
->relocateable
);
1252 if (h
->root
.type
== bfd_link_hash_defined
1253 || h
->root
.type
== bfd_link_hash_defweak
)
1258 /* This symbol is defined in the output. Convert the reloc from
1259 being against the symbol to being against the section. */
1261 /* Clear the r_extern bit. */
1262 ext_rel
->r_bits
[1] &=~ RELOC_BITS1_EXTERN_LITTLE
;
1264 /* Compute a new r_symndx value. */
1265 hsec
= h
->root
.u
.def
.section
;
1266 name
= bfd_get_section_name (output_bfd
, hsec
->output_section
);
1272 if (strcmp (name
, "*ABS*") == 0)
1273 r_symndx
= RELOC_SECTION_ABS
;
1276 if (strcmp (name
, ".bss") == 0)
1277 r_symndx
= RELOC_SECTION_BSS
;
1280 if (strcmp (name
, ".data") == 0)
1281 r_symndx
= RELOC_SECTION_DATA
;
1284 if (strcmp (name
, ".fini") == 0)
1285 r_symndx
= RELOC_SECTION_FINI
;
1288 if (strcmp (name
, ".init") == 0)
1289 r_symndx
= RELOC_SECTION_INIT
;
1292 if (strcmp (name
, ".lita") == 0)
1293 r_symndx
= RELOC_SECTION_LITA
;
1294 else if (strcmp (name
, ".lit8") == 0)
1295 r_symndx
= RELOC_SECTION_LIT8
;
1296 else if (strcmp (name
, ".lit4") == 0)
1297 r_symndx
= RELOC_SECTION_LIT4
;
1300 if (strcmp (name
, ".pdata") == 0)
1301 r_symndx
= RELOC_SECTION_PDATA
;
1304 if (strcmp (name
, ".rdata") == 0)
1305 r_symndx
= RELOC_SECTION_RDATA
;
1306 else if (strcmp (name
, ".rconst") == 0)
1307 r_symndx
= RELOC_SECTION_RCONST
;
1310 if (strcmp (name
, ".sdata") == 0)
1311 r_symndx
= RELOC_SECTION_SDATA
;
1312 else if (strcmp (name
, ".sbss") == 0)
1313 r_symndx
= RELOC_SECTION_SBSS
;
1316 if (strcmp (name
, ".text") == 0)
1317 r_symndx
= RELOC_SECTION_TEXT
;
1320 if (strcmp (name
, ".xdata") == 0)
1321 r_symndx
= RELOC_SECTION_XDATA
;
1328 /* Add the section VMA and the symbol value. */
1329 relocation
= (h
->root
.u
.def
.value
1330 + hsec
->output_section
->vma
1331 + hsec
->output_offset
);
1335 /* Change the symndx value to the right one for
1340 /* Caller must give an error. */
1346 /* Write out the new r_symndx value. */
1347 bfd_h_put_32 (input_bfd
, (bfd_vma
) r_symndx
,
1348 (bfd_byte
*) ext_rel
->r_symndx
);
1353 /* Relocate a section while linking an Alpha ECOFF file. This is
1354 quite similar to get_relocated_section_contents. Perhaps they
1355 could be combined somehow. */
1358 alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1359 contents
, external_relocs
)
1361 struct bfd_link_info
*info
;
1363 asection
*input_section
;
1365 PTR external_relocs
;
1367 asection
**symndx_to_section
;
1368 struct ecoff_link_hash_entry
**sym_hashes
;
1370 boolean gp_undefined
;
1371 bfd_vma stack
[RELOC_STACKSIZE
];
1373 struct external_reloc
*ext_rel
;
1374 struct external_reloc
*ext_rel_end
;
1376 /* We keep a table mapping the symndx found in an internal reloc to
1377 the appropriate section. This is faster than looking up the
1378 section by name each time. */
1379 symndx_to_section
= ecoff_data (input_bfd
)->symndx_to_section
;
1380 if (symndx_to_section
== (asection
**) NULL
)
1382 symndx_to_section
= ((asection
**)
1383 bfd_alloc (input_bfd
,
1385 * sizeof (asection
*))));
1386 if (!symndx_to_section
)
1389 symndx_to_section
[RELOC_SECTION_NONE
] = NULL
;
1390 symndx_to_section
[RELOC_SECTION_TEXT
] =
1391 bfd_get_section_by_name (input_bfd
, ".text");
1392 symndx_to_section
[RELOC_SECTION_RDATA
] =
1393 bfd_get_section_by_name (input_bfd
, ".rdata");
1394 symndx_to_section
[RELOC_SECTION_DATA
] =
1395 bfd_get_section_by_name (input_bfd
, ".data");
1396 symndx_to_section
[RELOC_SECTION_SDATA
] =
1397 bfd_get_section_by_name (input_bfd
, ".sdata");
1398 symndx_to_section
[RELOC_SECTION_SBSS
] =
1399 bfd_get_section_by_name (input_bfd
, ".sbss");
1400 symndx_to_section
[RELOC_SECTION_BSS
] =
1401 bfd_get_section_by_name (input_bfd
, ".bss");
1402 symndx_to_section
[RELOC_SECTION_INIT
] =
1403 bfd_get_section_by_name (input_bfd
, ".init");
1404 symndx_to_section
[RELOC_SECTION_LIT8
] =
1405 bfd_get_section_by_name (input_bfd
, ".lit8");
1406 symndx_to_section
[RELOC_SECTION_LIT4
] =
1407 bfd_get_section_by_name (input_bfd
, ".lit4");
1408 symndx_to_section
[RELOC_SECTION_XDATA
] =
1409 bfd_get_section_by_name (input_bfd
, ".xdata");
1410 symndx_to_section
[RELOC_SECTION_PDATA
] =
1411 bfd_get_section_by_name (input_bfd
, ".pdata");
1412 symndx_to_section
[RELOC_SECTION_FINI
] =
1413 bfd_get_section_by_name (input_bfd
, ".fini");
1414 symndx_to_section
[RELOC_SECTION_LITA
] =
1415 bfd_get_section_by_name (input_bfd
, ".lita");
1416 symndx_to_section
[RELOC_SECTION_ABS
] = bfd_abs_section_ptr
;
1417 symndx_to_section
[RELOC_SECTION_RCONST
] =
1418 bfd_get_section_by_name (input_bfd
, ".rconst");
1420 ecoff_data (input_bfd
)->symndx_to_section
= symndx_to_section
;
1423 sym_hashes
= ecoff_data (input_bfd
)->sym_hashes
;
1425 gp
= ecoff_data (output_bfd
)->gp
;
1427 gp_undefined
= true;
1429 gp_undefined
= false;
1431 BFD_ASSERT (output_bfd
->xvec
->header_byteorder_big_p
== false);
1432 BFD_ASSERT (input_bfd
->xvec
->header_byteorder_big_p
== false);
1434 ext_rel
= (struct external_reloc
*) external_relocs
;
1435 ext_rel_end
= ext_rel
+ input_section
->reloc_count
;
1436 for (; ext_rel
< ext_rel_end
; ext_rel
++)
1439 unsigned long r_symndx
;
1445 boolean adjust_addrp
;
1449 r_vaddr
= bfd_h_get_64 (input_bfd
, (bfd_byte
*) ext_rel
->r_vaddr
);
1450 r_symndx
= bfd_h_get_32 (input_bfd
, (bfd_byte
*) ext_rel
->r_symndx
);
1452 r_type
= ((ext_rel
->r_bits
[0] & RELOC_BITS0_TYPE_LITTLE
)
1453 >> RELOC_BITS0_TYPE_SH_LITTLE
);
1454 r_extern
= (ext_rel
->r_bits
[1] & RELOC_BITS1_EXTERN_LITTLE
) != 0;
1455 r_offset
= ((ext_rel
->r_bits
[1] & RELOC_BITS1_OFFSET_LITTLE
)
1456 >> RELOC_BITS1_OFFSET_SH_LITTLE
);
1457 /* Ignored the reserved bits. */
1458 r_size
= ((ext_rel
->r_bits
[3] & RELOC_BITS3_SIZE_LITTLE
)
1459 >> RELOC_BITS3_SIZE_SH_LITTLE
);
1462 adjust_addrp
= true;
1471 case ALPHA_R_IGNORE
:
1472 /* This reloc appears after a GPDISP reloc. It marks the
1473 position of the second instruction to be altered by the
1474 GPDISP reloc, but is not otherwise used for anything.
1475 For some reason, the address of the relocation does not
1476 appear to include the section VMA, unlike the other
1477 relocation types. */
1478 if (info
->relocateable
)
1479 bfd_h_put_64 (input_bfd
,
1480 input_section
->output_offset
+ r_vaddr
,
1481 (bfd_byte
*) ext_rel
->r_vaddr
);
1482 adjust_addrp
= false;
1485 case ALPHA_R_REFLONG
:
1486 case ALPHA_R_REFQUAD
:
1487 case ALPHA_R_BRADDR
:
1489 case ALPHA_R_SREL16
:
1490 case ALPHA_R_SREL32
:
1491 case ALPHA_R_SREL64
:
1495 case ALPHA_R_GPREL32
:
1496 /* This relocation is used in a switch table. It is a 32
1497 bit offset from the current GP value. We must adjust it
1498 by the different between the original GP value and the
1499 current GP value. */
1501 addend
= ecoff_data (input_bfd
)->gp
- gp
;
1505 case ALPHA_R_LITERAL
:
1506 /* This is a reference to a literal value, generally
1507 (always?) in the .lita section. This is a 16 bit GP
1508 relative relocation. Sometimes the subsequent reloc is a
1509 LITUSE reloc, which indicates how this reloc is used.
1510 This sometimes permits rewriting the two instructions
1511 referred to by the LITERAL and the LITUSE into different
1512 instructions which do not refer to .lita. This can save
1513 a memory reference, and permits removing a value from
1514 .lita thus saving GP relative space.
1516 We do not these optimizations. To do them we would need
1517 to arrange to link the .lita section first, so that by
1518 the time we got here we would know the final values to
1519 use. This would not be particularly difficult, but it is
1520 not currently implemented. */
1522 /* I believe that the LITERAL reloc will only apply to a ldq
1523 or ldl instruction, so check my assumption. */
1527 insn
= bfd_get_32 (input_bfd
,
1528 contents
+ r_vaddr
- input_section
->vma
);
1529 BFD_ASSERT (((insn
>> 26) & 0x3f) == 0x29
1530 || ((insn
>> 26) & 0x3f) == 0x28);
1534 addend
= ecoff_data (input_bfd
)->gp
- gp
;
1538 case ALPHA_R_LITUSE
:
1539 /* See ALPHA_R_LITERAL above for the uses of this reloc. It
1540 does not cause anything to happen, itself. */
1543 case ALPHA_R_GPDISP
:
1544 /* This marks the ldah of an ldah/lda pair which loads the
1545 gp register with the difference of the gp value and the
1546 current location. The second of the pair is r_symndx
1547 bytes ahead, and is also marked with an ALPHA_R_IGNORE
1550 unsigned long insn1
, insn2
;
1552 BFD_ASSERT (ext_rel
+ 1 < ext_rel_end
1553 && (((ext_rel
+ 1)->r_bits
[0]
1554 & RELOC_BITS0_TYPE_LITTLE
)
1555 >> RELOC_BITS0_TYPE_SH_LITTLE
) == ALPHA_R_IGNORE
1556 && (bfd_h_get_64 (input_bfd
,
1557 (bfd_byte
*) (ext_rel
+ 1)->r_vaddr
)
1558 == r_vaddr
- input_section
->vma
+ r_symndx
));
1560 /* Get the two instructions. */
1561 insn1
= bfd_get_32 (input_bfd
,
1562 contents
+ r_vaddr
- input_section
->vma
);
1563 insn2
= bfd_get_32 (input_bfd
,
1566 - input_section
->vma
1569 BFD_ASSERT (((insn1
>> 26) & 0x3f) == 0x09); /* ldah */
1570 BFD_ASSERT (((insn2
>> 26) & 0x3f) == 0x08); /* lda */
1572 /* Get the existing addend. We must account for the sign
1573 extension done by lda and ldah. */
1574 addend
= ((insn1
& 0xffff) << 16) + (insn2
& 0xffff);
1577 /* This is addend -= 0x100000000 without causing an
1578 integer overflow on a 32 bit host. */
1579 addend
-= 0x80000000;
1580 addend
-= 0x80000000;
1585 /* The existing addend includes the difference between the
1586 gp of the input BFD and the address in the input BFD.
1587 We want to change this to the difference between the
1588 final GP and the final address. */
1590 - ecoff_data (input_bfd
)->gp
1591 + input_section
->vma
1592 - (input_section
->output_section
->vma
1593 + input_section
->output_offset
));
1595 /* Change the instructions, accounting for the sign
1596 extension, and write them out. */
1597 if (addend
& 0x8000)
1599 insn1
= (insn1
& 0xffff0000) | ((addend
>> 16) & 0xffff);
1600 insn2
= (insn2
& 0xffff0000) | (addend
& 0xffff);
1602 bfd_put_32 (input_bfd
, (bfd_vma
) insn1
,
1603 contents
+ r_vaddr
- input_section
->vma
);
1604 bfd_put_32 (input_bfd
, (bfd_vma
) insn2
,
1605 contents
+ r_vaddr
- input_section
->vma
+ r_symndx
);
1611 case ALPHA_R_OP_PUSH
:
1612 case ALPHA_R_OP_PSUB
:
1613 case ALPHA_R_OP_PRSHIFT
:
1614 /* Manipulate values on the reloc evaluation stack. The
1615 r_vaddr field is not an address in input_section, it is
1616 the current value (including any addend) of the object
1622 s
= symndx_to_section
[r_symndx
];
1623 if (s
== (asection
*) NULL
)
1625 addend
= s
->output_section
->vma
+ s
->output_offset
- s
->vma
;
1629 struct ecoff_link_hash_entry
*h
;
1631 h
= sym_hashes
[r_symndx
];
1632 if (h
== (struct ecoff_link_hash_entry
*) NULL
)
1635 if (! info
->relocateable
)
1637 if (h
->root
.type
== bfd_link_hash_defined
1638 || h
->root
.type
== bfd_link_hash_defweak
)
1639 addend
= (h
->root
.u
.def
.value
1640 + h
->root
.u
.def
.section
->output_section
->vma
1641 + h
->root
.u
.def
.section
->output_offset
);
1644 /* Note that we pass the address as 0, since we
1645 do not have a meaningful number for the
1646 location within the section that is being
1648 if (! ((*info
->callbacks
->undefined_symbol
)
1649 (info
, h
->root
.root
.string
, input_bfd
,
1650 input_section
, (bfd_vma
) 0)))
1657 if (h
->root
.type
!= bfd_link_hash_defined
1658 && h
->root
.type
!= bfd_link_hash_defweak
1661 /* This symbol is not being written out. Pass
1662 the address as 0, as with undefined_symbol,
1664 if (! ((*info
->callbacks
->unattached_reloc
)
1665 (info
, h
->root
.root
.string
, input_bfd
,
1666 input_section
, (bfd_vma
) 0)))
1670 addend
= alpha_convert_external_reloc (output_bfd
, info
,
1678 if (info
->relocateable
)
1680 /* Adjust r_vaddr by the addend. */
1681 bfd_h_put_64 (input_bfd
, addend
,
1682 (bfd_byte
*) ext_rel
->r_vaddr
);
1688 case ALPHA_R_OP_PUSH
:
1689 if (tos
>= RELOC_STACKSIZE
)
1691 stack
[tos
++] = addend
;
1694 case ALPHA_R_OP_PSUB
:
1697 stack
[tos
- 1] -= addend
;
1700 case ALPHA_R_OP_PRSHIFT
:
1703 stack
[tos
- 1] >>= addend
;
1708 adjust_addrp
= false;
1711 case ALPHA_R_OP_STORE
:
1712 /* Store a value from the reloc stack into a bitfield. If
1713 we are generating relocateable output, all we do is
1714 adjust the address of the reloc. */
1715 if (! info
->relocateable
)
1723 /* Get the relocation mask. The separate steps and the
1724 casts to bfd_vma are attempts to avoid a bug in the
1725 Alpha OSF 1.3 C compiler. See reloc.c for more
1728 mask
<<= (bfd_vma
) r_size
;
1731 /* FIXME: I don't know what kind of overflow checking,
1732 if any, should be done here. */
1733 val
= bfd_get_64 (input_bfd
,
1734 contents
+ r_vaddr
- input_section
->vma
);
1735 val
&=~ mask
<< (bfd_vma
) r_offset
;
1736 val
|= (stack
[--tos
] & mask
) << (bfd_vma
) r_offset
;
1737 bfd_put_64 (input_bfd
, val
,
1738 contents
+ r_vaddr
- input_section
->vma
);
1742 case ALPHA_R_GPVALUE
:
1743 /* I really don't know if this does the right thing. */
1744 gp
= ecoff_data (input_bfd
)->gp
+ r_symndx
;
1745 gp_undefined
= false;
1751 reloc_howto_type
*howto
;
1752 struct ecoff_link_hash_entry
*h
= NULL
;
1755 bfd_reloc_status_type r
;
1757 /* Perform a relocation. */
1759 howto
= &alpha_howto_table
[r_type
];
1763 h
= sym_hashes
[r_symndx
];
1764 /* If h is NULL, that means that there is a reloc
1765 against an external symbol which we thought was just
1766 a debugging symbol. This should not happen. */
1767 if (h
== (struct ecoff_link_hash_entry
*) NULL
)
1772 if (r_symndx
>= NUM_RELOC_SECTIONS
)
1775 s
= symndx_to_section
[r_symndx
];
1777 if (s
== (asection
*) NULL
)
1781 if (info
->relocateable
)
1783 /* We are generating relocateable output, and must
1784 convert the existing reloc. */
1787 if (h
->root
.type
!= bfd_link_hash_defined
1788 && h
->root
.type
!= bfd_link_hash_defweak
1791 /* This symbol is not being written out. */
1792 if (! ((*info
->callbacks
->unattached_reloc
)
1793 (info
, h
->root
.root
.string
, input_bfd
,
1794 input_section
, r_vaddr
- input_section
->vma
)))
1798 relocation
= alpha_convert_external_reloc (output_bfd
,
1806 /* This is a relocation against a section. Adjust
1807 the value by the amount the section moved. */
1808 relocation
= (s
->output_section
->vma
1813 /* If this is PC relative, the existing object file
1814 appears to already have the reloc worked out. We
1815 must subtract out the old value and add in the new
1817 if (howto
->pc_relative
)
1818 relocation
-= (input_section
->output_section
->vma
1819 + input_section
->output_offset
1820 - input_section
->vma
);
1822 /* Put in any addend. */
1823 relocation
+= addend
;
1825 /* Adjust the contents. */
1826 r
= _bfd_relocate_contents (howto
, input_bfd
, relocation
,
1829 - input_section
->vma
));
1833 /* We are producing a final executable. */
1836 /* This is a reloc against a symbol. */
1837 if (h
->root
.type
== bfd_link_hash_defined
1838 || h
->root
.type
== bfd_link_hash_defweak
)
1842 hsec
= h
->root
.u
.def
.section
;
1843 relocation
= (h
->root
.u
.def
.value
1844 + hsec
->output_section
->vma
1845 + hsec
->output_offset
);
1849 if (! ((*info
->callbacks
->undefined_symbol
)
1850 (info
, h
->root
.root
.string
, input_bfd
,
1852 r_vaddr
- input_section
->vma
)))
1859 /* This is a reloc against a section. */
1860 relocation
= (s
->output_section
->vma
1864 /* Adjust a PC relative relocation by removing the
1865 reference to the original source section. */
1866 if (howto
->pc_relative
)
1867 relocation
+= input_section
->vma
;
1870 r
= _bfd_final_link_relocate (howto
,
1874 r_vaddr
- input_section
->vma
,
1879 if (r
!= bfd_reloc_ok
)
1884 case bfd_reloc_outofrange
:
1886 case bfd_reloc_overflow
:
1891 name
= sym_hashes
[r_symndx
]->root
.root
.string
;
1893 name
= bfd_section_name (input_bfd
,
1894 symndx_to_section
[r_symndx
]);
1895 if (! ((*info
->callbacks
->reloc_overflow
)
1896 (info
, name
, alpha_howto_table
[r_type
].name
,
1897 (bfd_vma
) 0, input_bfd
, input_section
,
1898 r_vaddr
- input_section
->vma
)))
1906 if (info
->relocateable
&& adjust_addrp
)
1908 /* Change the address of the relocation. */
1909 bfd_h_put_64 (input_bfd
,
1910 (input_section
->output_section
->vma
1911 + input_section
->output_offset
1912 - input_section
->vma
1914 (bfd_byte
*) ext_rel
->r_vaddr
);
1917 if (gp_usedp
&& gp_undefined
)
1919 if (! ((*info
->callbacks
->reloc_dangerous
)
1920 (info
, "GP relative relocation when GP not defined",
1921 input_bfd
, input_section
, r_vaddr
- input_section
->vma
)))
1923 /* Only give the error once per link. */
1924 ecoff_data (output_bfd
)->gp
= gp
= 4;
1925 gp_undefined
= false;
1935 /* Do final adjustments to the filehdr and the aouthdr. This routine
1936 sets the dynamic bits in the file header. */
1940 alpha_adjust_headers (abfd
, fhdr
, ahdr
)
1942 struct internal_filehdr
*fhdr
;
1943 struct internal_aouthdr
*ahdr
;
1945 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == (DYNAMIC
| EXEC_P
))
1946 fhdr
->f_flags
|= F_ALPHA_CALL_SHARED
;
1947 else if ((abfd
->flags
& DYNAMIC
) != 0)
1948 fhdr
->f_flags
|= F_ALPHA_SHARABLE
;
1952 /* This is the ECOFF backend structure. The backend field of the
1953 target vector points to this. */
1955 static const struct ecoff_backend_data alpha_ecoff_backend_data
=
1957 /* COFF backend structure. */
1959 (void (*) PARAMS ((bfd
*,PTR
,int,int,int,int,PTR
))) bfd_void
, /* aux_in */
1960 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_in */
1961 (void (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_in */
1962 (unsigned (*) PARAMS ((bfd
*,PTR
,int,int,int,int,PTR
)))bfd_void
,/*aux_out*/
1963 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* sym_out */
1964 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* lineno_out */
1965 (unsigned (*) PARAMS ((bfd
*,PTR
,PTR
))) bfd_void
, /* reloc_out */
1966 alpha_ecoff_swap_filehdr_out
, alpha_ecoff_swap_aouthdr_out
,
1967 alpha_ecoff_swap_scnhdr_out
,
1968 FILHSZ
, AOUTSZ
, SCNHSZ
, 0, 0, 0, 0, true,
1969 alpha_ecoff_swap_filehdr_in
, alpha_ecoff_swap_aouthdr_in
,
1970 alpha_ecoff_swap_scnhdr_in
, NULL
,
1971 alpha_ecoff_bad_format_hook
, _bfd_ecoff_set_arch_mach_hook
,
1972 alpha_ecoff_mkobject_hook
, _bfd_ecoff_styp_to_sec_flags
,
1973 _bfd_ecoff_set_alignment_hook
, _bfd_ecoff_slurp_symbol_table
,
1974 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
1976 /* Supported architecture. */
1978 /* Initial portion of armap string. */
1980 /* The page boundary used to align sections in a demand-paged
1981 executable file. E.g., 0x1000. */
1983 /* True if the .rdata section is part of the text segment, as on the
1984 Alpha. False if .rdata is part of the data segment, as on the
1987 /* Bitsize of constructor entries. */
1989 /* Reloc to use for constructor entries. */
1990 &alpha_howto_table
[ALPHA_R_REFQUAD
],
1992 /* Symbol table magic number. */
1994 /* Alignment of debugging information. E.g., 4. */
1996 /* Sizes of external symbolic information. */
1997 sizeof (struct hdr_ext
),
1998 sizeof (struct dnr_ext
),
1999 sizeof (struct pdr_ext
),
2000 sizeof (struct sym_ext
),
2001 sizeof (struct opt_ext
),
2002 sizeof (struct fdr_ext
),
2003 sizeof (struct rfd_ext
),
2004 sizeof (struct ext_ext
),
2005 /* Functions to swap in external symbolic data. */
2014 _bfd_ecoff_swap_tir_in
,
2015 _bfd_ecoff_swap_rndx_in
,
2016 /* Functions to swap out external symbolic data. */
2025 _bfd_ecoff_swap_tir_out
,
2026 _bfd_ecoff_swap_rndx_out
,
2027 /* Function to read in symbolic data. */
2028 _bfd_ecoff_slurp_symbolic_info
2030 /* External reloc size. */
2032 /* Reloc swapping functions. */
2033 alpha_ecoff_swap_reloc_in
,
2034 alpha_ecoff_swap_reloc_out
,
2035 /* Backend reloc tweaking. */
2036 alpha_adjust_reloc_in
,
2037 alpha_adjust_reloc_out
,
2038 /* Relocate section contents while linking. */
2039 alpha_relocate_section
,
2040 /* Do final adjustments to filehdr and aouthdr. */
2041 alpha_adjust_headers
2044 /* Looking up a reloc type is Alpha specific. */
2045 #define _bfd_ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup
2047 /* So is getting relocated section contents. */
2048 #define _bfd_ecoff_bfd_get_relocated_section_contents \
2049 alpha_ecoff_get_relocated_section_contents
2051 /* Handling file windows is generic. */
2052 #define _bfd_ecoff_get_section_contents_in_window \
2053 _bfd_generic_get_section_contents_in_window
2055 /* Relaxing sections is generic. */
2056 #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section
2058 const bfd_target ecoffalpha_little_vec
=
2060 "ecoff-littlealpha", /* name */
2061 bfd_target_ecoff_flavour
,
2062 false, /* data byte order is little */
2063 false, /* header byte order is little */
2065 (HAS_RELOC
| EXEC_P
| /* object flags */
2066 HAS_LINENO
| HAS_DEBUG
|
2067 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
2069 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
),
2070 0, /* leading underscore */
2071 ' ', /* ar_pad_char */
2072 15, /* ar_max_namelen */
2073 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2074 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2075 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2076 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2077 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2078 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2080 {_bfd_dummy_target
, alpha_ecoff_object_p
, /* bfd_check_format */
2081 _bfd_ecoff_archive_p
, _bfd_dummy_target
},
2082 {bfd_false
, _bfd_ecoff_mkobject
, /* bfd_set_format */
2083 _bfd_generic_mkarchive
, bfd_false
},
2084 {bfd_false
, _bfd_ecoff_write_object_contents
, /* bfd_write_contents */
2085 _bfd_write_archive_contents
, bfd_false
},
2087 BFD_JUMP_TABLE_GENERIC (_bfd_ecoff
),
2088 BFD_JUMP_TABLE_COPY (_bfd_ecoff
),
2089 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2090 BFD_JUMP_TABLE_ARCHIVE (_bfd_ecoff
),
2091 BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff
),
2092 BFD_JUMP_TABLE_RELOCS (_bfd_ecoff
),
2093 BFD_JUMP_TABLE_WRITE (_bfd_ecoff
),
2094 BFD_JUMP_TABLE_LINK (_bfd_ecoff
),
2095 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2097 (PTR
) &alpha_ecoff_backend_data