1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* We need a published ABI spec for this. Until one comes out, don't
22 assume this'll remain unchanged forever. */
29 #include "elf/alpha.h"
33 #define NO_COFF_RELOCS
34 #define NO_COFF_SYMBOLS
35 #define NO_COFF_LINENOS
37 /* Get the ECOFF swapping routines. Needed for the debug information. */
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
42 #include "coff/alpha.h"
47 #include "ecoffswap.h"
49 static struct bfd_hash_entry * elf64_alpha_link_hash_newfunc
50 PARAMS((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
51 static struct bfd_link_hash_table * elf64_alpha_bfd_link_hash_table_create
54 static bfd_reloc_status_type elf64_alpha_reloc_nil
55 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56 static bfd_reloc_status_type elf64_alpha_reloc_bad
57 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
59 PARAMS((bfd *, bfd_vma, bfd_byte *, bfd_byte *));
60 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
61 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
63 static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup
64 PARAMS((bfd *, bfd_reloc_code_real_type));
65 static void elf64_alpha_info_to_howto
66 PARAMS((bfd *, arelent *, Elf64_Internal_Rela *));
68 static boolean elf64_alpha_object_p
70 static boolean elf64_alpha_section_from_shdr
71 PARAMS((bfd *, Elf64_Internal_Shdr *, char *));
72 static boolean elf64_alpha_fake_sections
73 PARAMS((bfd *, Elf64_Internal_Shdr *, asection *));
74 static int elf64_alpha_additional_program_headers
76 static boolean elf64_alpha_create_got_section
77 PARAMS((bfd *, struct bfd_link_info *));
78 static boolean elf64_alpha_create_dynamic_sections
79 PARAMS((bfd *, struct bfd_link_info *));
81 static boolean elf64_alpha_read_ecoff_info
82 PARAMS((bfd *, asection *, struct ecoff_debug_info *));
83 static boolean elf64_alpha_is_local_label
84 PARAMS((bfd *, asymbol *));
85 static boolean elf64_alpha_find_nearest_line
86 PARAMS((bfd *, asection *, asymbol **, bfd_vma, const char **,
87 const char **, unsigned int *));
89 #if defined(__STDC__) || defined(ALMOST_STDC)
90 struct alpha_elf_link_hash_entry;
93 static boolean elf64_alpha_output_extsym
94 PARAMS((struct alpha_elf_link_hash_entry *, PTR));
96 static boolean elf64_alpha_can_merge_gots
97 PARAMS((bfd *, bfd *));
98 static void elf64_alpha_merge_gots
99 PARAMS((bfd *, bfd *));
101 static boolean elf64_alpha_check_relocs
102 PARAMS((bfd *, struct bfd_link_info *, asection *sec,
103 const Elf_Internal_Rela *));
104 static boolean elf64_alpha_adjust_dynamic_symbol
105 PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *));
106 static boolean elf64_alpha_size_dynamic_sections
107 PARAMS((bfd *, struct bfd_link_info *));
108 static boolean elf64_alpha_adjust_dynindx
109 PARAMS((struct elf_link_hash_entry *, PTR));
110 static boolean elf64_alpha_relocate_section
111 PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
112 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
113 static boolean elf64_alpha_finish_dynamic_symbol
114 PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
115 Elf_Internal_Sym *));
116 static boolean elf64_alpha_finish_dynamic_sections
117 PARAMS((bfd *, struct bfd_link_info *));
118 static boolean elf64_alpha_final_link
119 PARAMS((bfd *, struct bfd_link_info *));
122 struct alpha_elf_link_hash_entry
124 struct elf_link_hash_entry root;
126 /* External symbol information. */
129 /* Cumulative flags for all the .got entries. */
132 /* Contexts (LITUSE) in which a literal was referenced. */
133 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
134 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
135 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
136 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x08
138 /* Used to implement multiple .got subsections. */
139 struct alpha_elf_got_entry
141 struct alpha_elf_got_entry *next;
143 /* which .got subsection? */
146 /* the addend in effect for this entry. */
149 /* the .got offset for this entry. */
154 /* An additional flag. */
155 #define ALPHA_ELF_GOT_ENTRY_RELOCS_DONE 0x10
158 /* used to count non-got, non-plt relocations for delayed sizing
159 of relocation sections. */
160 struct alpha_elf_reloc_entry
162 struct alpha_elf_reloc_entry *next;
164 /* which .reloc section? */
167 /* what kind of relocation? */
170 /* how many did we find? */
175 /* Alpha ELF linker hash table. */
177 struct alpha_elf_link_hash_table
179 struct elf_link_hash_table root;
181 /* The head of a list of .got subsections linked through
182 alpha_elf_tdata(abfd)->got_link_next. */
186 /* Look up an entry in a Alpha ELF linker hash table. */
188 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
189 ((struct alpha_elf_link_hash_entry *) \
190 elf_link_hash_lookup (&(table)->root, (string), (create), \
193 /* Traverse a Alpha ELF linker hash table. */
195 #define alpha_elf_link_hash_traverse(table, func, info) \
196 (elf_link_hash_traverse \
198 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
201 /* Get the Alpha ELF linker hash table from a link_info structure. */
203 #define alpha_elf_hash_table(p) \
204 ((struct alpha_elf_link_hash_table *) ((p)->hash))
206 /* Get the object's symbols as our own entry type. */
208 #define alpha_elf_sym_hashes(abfd) \
209 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
211 /* Should we do dynamic things to this symbol? */
213 #define alpha_elf_dynamic_symbol_p(h, info) \
214 (((info)->shared && !(info)->symbolic) \
215 || (((h)->elf_link_hash_flags \
216 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
217 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
219 /* Create an entry in a Alpha ELF linker hash table. */
221 static struct bfd_hash_entry *
222 elf64_alpha_link_hash_newfunc (entry, table, string)
223 struct bfd_hash_entry *entry;
224 struct bfd_hash_table *table;
227 struct alpha_elf_link_hash_entry *ret =
228 (struct alpha_elf_link_hash_entry *) entry;
230 /* Allocate the structure if it has not already been allocated by a
232 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
233 ret = ((struct alpha_elf_link_hash_entry *)
234 bfd_hash_allocate (table,
235 sizeof (struct alpha_elf_link_hash_entry)));
236 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
237 return (struct bfd_hash_entry *) ret;
239 /* Call the allocation method of the superclass. */
240 ret = ((struct alpha_elf_link_hash_entry *)
241 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
243 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
245 /* Set local fields. */
246 memset (&ret->esym, 0, sizeof (EXTR));
247 /* We use -2 as a marker to indicate that the information has
248 not been set. -1 means there is no associated ifd. */
251 ret->got_entries = NULL;
252 ret->reloc_entries = NULL;
255 return (struct bfd_hash_entry *) ret;
258 /* Create a Alpha ELF linker hash table. */
260 static struct bfd_link_hash_table *
261 elf64_alpha_bfd_link_hash_table_create (abfd)
264 struct alpha_elf_link_hash_table *ret;
266 ret = ((struct alpha_elf_link_hash_table *)
267 bfd_zalloc (abfd, sizeof (struct alpha_elf_link_hash_table)));
268 if (ret == (struct alpha_elf_link_hash_table *) NULL)
271 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
272 elf64_alpha_link_hash_newfunc))
274 bfd_release (abfd, ret);
278 return &ret->root.root;
281 /* We have some private fields hanging off of the elf_tdata structure. */
283 struct alpha_elf_obj_tdata
285 struct elf_obj_tdata root;
287 /* For every input file, these are the got entries for that object's
289 struct alpha_elf_got_entry ** local_got_entries;
291 /* For every input file, this is the object that owns the got that
292 this input file uses. */
295 /* For every got, this is a linked list through the objects using this got */
296 bfd *in_got_link_next;
298 /* For every got, this is a link to the next got subsegment. */
301 /* For every got, this is the section. */
304 /* For every got, this is it's total number of *entries*. */
305 int total_got_entries;
307 /* For every got, this is the sum of the number of *entries* required
308 to hold all of the member object's local got. */
309 int n_local_got_entries;
312 #define alpha_elf_tdata(abfd) \
313 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
316 elf64_alpha_mkobject (abfd)
319 abfd->tdata.any = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
320 if (abfd->tdata.any == NULL)
325 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
326 from smaller values. Start with zero, widen, *then* decrement. */
327 #define MINUS_ONE (((bfd_vma)0) - 1)
329 static reloc_howto_type elf64_alpha_howto_table[] =
331 HOWTO (R_ALPHA_NONE, /* type */
333 0, /* size (0 = byte, 1 = short, 2 = long) */
335 true, /* pc_relative */
337 complain_overflow_dont, /* complain_on_overflow */
338 elf64_alpha_reloc_nil, /* special_function */
340 false, /* partial_inplace */
343 true), /* pcrel_offset */
345 /* A 32 bit reference to a symbol. */
346 HOWTO (R_ALPHA_REFLONG, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 false, /* pc_relative */
352 complain_overflow_bitfield, /* complain_on_overflow */
353 0, /* special_function */
354 "REFLONG", /* name */
355 false, /* partial_inplace */
356 0xffffffff, /* src_mask */
357 0xffffffff, /* dst_mask */
358 false), /* pcrel_offset */
360 /* A 64 bit reference to a symbol. */
361 HOWTO (R_ALPHA_REFQUAD, /* type */
363 4, /* size (0 = byte, 1 = short, 2 = long) */
365 false, /* pc_relative */
367 complain_overflow_bitfield, /* complain_on_overflow */
368 0, /* special_function */
369 "REFQUAD", /* name */
370 false, /* partial_inplace */
371 MINUS_ONE, /* src_mask */
372 MINUS_ONE, /* dst_mask */
373 false), /* pcrel_offset */
375 /* A 32 bit GP relative offset. This is just like REFLONG except
376 that when the value is used the value of the gp register will be
378 HOWTO (R_ALPHA_GPREL32, /* type */
380 2, /* size (0 = byte, 1 = short, 2 = long) */
382 false, /* pc_relative */
384 complain_overflow_bitfield, /* complain_on_overflow */
385 0, /* special_function */
386 "GPREL32", /* name */
387 false, /* partial_inplace */
388 0xffffffff, /* src_mask */
389 0xffffffff, /* dst_mask */
390 false), /* pcrel_offset */
392 /* Used for an instruction that refers to memory off the GP register. */
393 HOWTO (R_ALPHA_LITERAL, /* type */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
397 false, /* pc_relative */
399 complain_overflow_signed, /* complain_on_overflow */
400 0, /* special_function */
401 "ELF_LITERAL", /* name */
402 false, /* partial_inplace */
403 0xffff, /* src_mask */
404 0xffff, /* dst_mask */
405 false), /* pcrel_offset */
407 /* This reloc only appears immediately following an ELF_LITERAL reloc.
408 It identifies a use of the literal. The symbol index is special:
409 1 means the literal address is in the base register of a memory
410 format instruction; 2 means the literal address is in the byte
411 offset register of a byte-manipulation instruction; 3 means the
412 literal address is in the target register of a jsr instruction.
413 This does not actually do any relocation. */
414 HOWTO (R_ALPHA_LITUSE, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_dont, /* complain_on_overflow */
421 elf64_alpha_reloc_nil, /* special_function */
423 false, /* partial_inplace */
426 false), /* pcrel_offset */
428 /* Load the gp register. This is always used for a ldah instruction
429 which loads the upper 16 bits of the gp register. The symbol
430 index of the GPDISP instruction is an offset in bytes to the lda
431 instruction that loads the lower 16 bits. The value to use for
432 the relocation is the difference between the GP value and the
433 current location; the load will always be done against a register
434 holding the current address.
436 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
437 any offset is present in the instructions, it is an offset from
438 the register to the ldah instruction. This lets us avoid any
439 stupid hackery like inventing a gp value to do partial relocation
440 against. Also unlike ECOFF, we do the whole relocation off of
441 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
442 space consuming bit, that, since all the information was present
443 in the GPDISP_HI16 reloc. */
444 HOWTO (R_ALPHA_GPDISP, /* type */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
448 false, /* pc_relative */
450 complain_overflow_dont, /* complain_on_overflow */
451 elf64_alpha_reloc_gpdisp, /* special_function */
453 false, /* partial_inplace */
454 0xffff, /* src_mask */
455 0xffff, /* dst_mask */
456 true), /* pcrel_offset */
458 /* A 21 bit branch. */
459 HOWTO (R_ALPHA_BRADDR, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 true, /* pc_relative */
465 complain_overflow_signed, /* complain_on_overflow */
466 0, /* special_function */
468 false, /* partial_inplace */
469 0x1fffff, /* src_mask */
470 0x1fffff, /* dst_mask */
471 true), /* pcrel_offset */
473 /* A hint for a jump to a register. */
474 HOWTO (R_ALPHA_HINT, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 true, /* pc_relative */
480 complain_overflow_dont, /* complain_on_overflow */
481 0, /* special_function */
483 false, /* partial_inplace */
484 0x3fff, /* src_mask */
485 0x3fff, /* dst_mask */
486 true), /* pcrel_offset */
488 /* 16 bit PC relative offset. */
489 HOWTO (R_ALPHA_SREL16, /* type */
491 1, /* size (0 = byte, 1 = short, 2 = long) */
493 true, /* pc_relative */
495 complain_overflow_signed, /* complain_on_overflow */
496 0, /* special_function */
498 false, /* partial_inplace */
499 0xffff, /* src_mask */
500 0xffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* 32 bit PC relative offset. */
504 HOWTO (R_ALPHA_SREL32, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 true, /* pc_relative */
510 complain_overflow_signed, /* complain_on_overflow */
511 0, /* special_function */
513 false, /* partial_inplace */
514 0xffffffff, /* src_mask */
515 0xffffffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* A 64 bit PC relative offset. */
519 HOWTO (R_ALPHA_SREL64, /* type */
521 4, /* size (0 = byte, 1 = short, 2 = long) */
523 true, /* pc_relative */
525 complain_overflow_signed, /* complain_on_overflow */
526 0, /* special_function */
528 false, /* partial_inplace */
529 MINUS_ONE, /* src_mask */
530 MINUS_ONE, /* dst_mask */
531 false), /* pcrel_offset */
533 /* Push a value on the reloc evaluation stack. */
534 HOWTO (ALPHA_R_OP_PUSH, /* type */
536 0, /* size (0 = byte, 1 = short, 2 = long) */
538 false, /* pc_relative */
540 complain_overflow_dont, /* complain_on_overflow */
541 elf64_alpha_reloc_bad, /* special_function */
542 "OP_PUSH", /* name */
543 false, /* partial_inplace */
546 false), /* pcrel_offset */
548 /* Store the value from the stack at the given address. Store it in
549 a bitfield of size r_size starting at bit position r_offset. */
550 HOWTO (ALPHA_R_OP_STORE, /* type */
552 4, /* size (0 = byte, 1 = short, 2 = long) */
554 false, /* pc_relative */
556 complain_overflow_dont, /* complain_on_overflow */
557 elf64_alpha_reloc_bad, /* special_function */
558 "OP_STORE", /* name */
559 false, /* partial_inplace */
561 MINUS_ONE, /* dst_mask */
562 false), /* pcrel_offset */
564 /* Subtract the reloc address from the value on the top of the
566 HOWTO (ALPHA_R_OP_PSUB, /* type */
568 0, /* size (0 = byte, 1 = short, 2 = long) */
570 false, /* pc_relative */
572 complain_overflow_dont, /* complain_on_overflow */
573 elf64_alpha_reloc_bad, /* special_function */
574 "OP_PSUB", /* name */
575 false, /* partial_inplace */
578 false), /* pcrel_offset */
580 /* Shift the value on the top of the relocation stack right by the
582 HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
584 0, /* size (0 = byte, 1 = short, 2 = long) */
586 false, /* pc_relative */
588 complain_overflow_dont, /* complain_on_overflow */
589 elf64_alpha_reloc_bad, /* special_function */
590 "OP_PRSHIFT", /* name */
591 false, /* partial_inplace */
594 false), /* pcrel_offset */
596 /* Misc ELF relocations. */
603 complain_overflow_dont,
604 bfd_elf_generic_reloc,
611 HOWTO (R_ALPHA_GLOB_DAT,
617 complain_overflow_dont,
618 bfd_elf_generic_reloc,
625 HOWTO (R_ALPHA_JMP_SLOT,
631 complain_overflow_dont,
632 bfd_elf_generic_reloc,
639 HOWTO (R_ALPHA_RELATIVE,
645 complain_overflow_dont,
646 bfd_elf_generic_reloc,
654 /* A relocation function which doesn't do anything. */
656 static bfd_reloc_status_type
657 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
664 char **error_message;
667 reloc->address += sec->output_offset;
671 /* A relocation function used for an unsupported reloc. */
673 static bfd_reloc_status_type
674 elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
681 char **error_message;
684 reloc->address += sec->output_offset;
685 return bfd_reloc_notsupported;
688 /* Do the work of the GPDISP relocation. */
690 static bfd_reloc_status_type
691 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
697 bfd_reloc_status_type ret = bfd_reloc_ok;
699 unsigned long i_ldah, i_lda;
701 i_ldah = bfd_get_32 (abfd, p_ldah);
702 i_lda = bfd_get_32 (abfd, p_lda);
704 /* Complain if the instructions are not correct. */
705 if (((i_ldah >> 26) & 0x3f) != 0x09
706 || ((i_lda >> 26) & 0x3f) != 0x08)
707 ret = bfd_reloc_dangerous;
709 /* Extract the user-supplied offset, mirroring the sign extensions
710 that the instructions perform. */
711 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
712 addend = (addend ^ 0x80008000) - 0x80008000;
716 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma)0x80000000
717 || gpdisp >= 0x7fff8000)
718 ret = bfd_reloc_overflow;
720 /* compensate for the sign extension again. */
721 i_ldah = ((i_ldah & 0xffff0000)
722 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
723 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
725 bfd_put_32 (abfd, i_ldah, p_ldah);
726 bfd_put_32 (abfd, i_lda, p_lda);
731 /* The special function for the GPDISP reloc. */
733 static bfd_reloc_status_type
734 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
737 arelent *reloc_entry;
740 asection *input_section;
744 bfd_reloc_status_type ret;
745 bfd_vma gp, relocation;
746 bfd_byte *p_ldah, *p_lda;
748 /* Don't do anything if we're not doing a final link. */
751 reloc_entry->address += input_section->output_offset;
755 if (reloc_entry->address > input_section->_cooked_size ||
756 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
757 return bfd_reloc_outofrange;
759 /* The gp used in the portion of the output object to which this
760 input object belongs is cached on the input bfd. */
761 gp = _bfd_get_gp_value (abfd);
763 relocation = (input_section->output_section->vma
764 + input_section->output_offset
765 + reloc_entry->address);
767 p_ldah = (bfd_byte *) data + reloc_entry->address;
768 p_lda = p_ldah + reloc_entry->addend;
770 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
772 /* Complain if the instructions are not correct. */
773 if (ret == bfd_reloc_dangerous)
774 *err_msg = "GPDISP relocation did not find ldah and lda instructions";
779 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
783 bfd_reloc_code_real_type bfd_reloc_val;
787 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
789 {BFD_RELOC_NONE, R_ALPHA_NONE},
790 {BFD_RELOC_32, R_ALPHA_REFLONG},
791 {BFD_RELOC_64, R_ALPHA_REFQUAD},
792 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
793 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
794 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
795 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
796 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
797 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
798 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
799 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
800 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
801 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
804 /* Given a BFD reloc type, return a HOWTO structure. */
806 static reloc_howto_type *
807 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
809 bfd_reloc_code_real_type code;
811 const struct elf_reloc_map *i, *e;
812 i = e = elf64_alpha_reloc_map;
813 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
816 if (i->bfd_reloc_val == code)
817 return &elf64_alpha_howto_table[i->elf_reloc_val];
822 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
825 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
828 Elf64_Internal_Rela *dst;
832 r_type = ELF64_R_TYPE(dst->r_info);
833 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
834 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
838 #define PLT_HEADER_SIZE 32
839 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
840 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
841 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
842 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
844 #define PLT_ENTRY_SIZE 12
845 #define PLT_ENTRY_WORD1 0x279f0000 /* ldah $28, 0($31) */
846 #define PLT_ENTRY_WORD2 0x239c0000 /* lda $28, 0($28) */
847 #define PLT_ENTRY_WORD3 0xc3e00000 /* br $31, plt0 */
849 #define MAX_GOT_ENTRIES (64*1024 / 8)
851 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
853 /* Set the right machine number for an Alpha ELF file. */
856 elf64_alpha_object_p (abfd)
859 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
862 /* Handle an Alpha specific section when reading an object file. This
863 is called when elfcode.h finds a section with an unknown type.
864 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
868 elf64_alpha_section_from_shdr (abfd, hdr, name)
870 Elf64_Internal_Shdr *hdr;
875 /* There ought to be a place to keep ELF backend specific flags, but
876 at the moment there isn't one. We just keep track of the
877 sections by their name, instead. Fortunately, the ABI gives
878 suggested names for all the MIPS specific sections, so we will
879 probably get away with this. */
880 switch (hdr->sh_type)
882 case SHT_ALPHA_DEBUG:
883 if (strcmp (name, ".mdebug") != 0)
887 case SHT_ALPHA_REGINFO:
888 if (strcmp (name, ".reginfo") != 0
889 || hdr->sh_size != sizeof (Elf64_External_RegInfo))
897 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
899 newsect = hdr->bfd_section;
901 if (hdr->sh_type == SHT_ALPHA_DEBUG)
903 if (! bfd_set_section_flags (abfd, newsect,
904 (bfd_get_section_flags (abfd, newsect)
910 /* For a .reginfo section, set the gp value in the tdata information
911 from the contents of this section. We need the gp value while
912 processing relocs, so we just get it now. */
913 if (hdr->sh_type == SHT_ALPHA_REGINFO)
915 Elf64_External_RegInfo ext;
918 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
919 (file_ptr) 0, sizeof ext))
921 bfd_alpha_elf64_swap_reginfo_in (abfd, &ext, &s);
922 elf_gp (abfd) = s.ri_gp_value;
929 /* Set the correct type for an Alpha ELF section. We do this by the
930 section name, which is a hack, but ought to work. */
933 elf64_alpha_fake_sections (abfd, hdr, sec)
935 Elf64_Internal_Shdr *hdr;
938 register const char *name;
940 name = bfd_get_section_name (abfd, sec);
942 if (strcmp (name, ".mdebug") == 0)
944 hdr->sh_type = SHT_ALPHA_DEBUG;
945 /* In a shared object on Irix 5.3, the .mdebug section has an
946 entsize of 0. FIXME: Does this matter? */
947 if ((abfd->flags & DYNAMIC) != 0 )
953 else if (strcmp (name, ".reginfo") == 0)
955 hdr->sh_type = SHT_ALPHA_REGINFO;
956 /* In a shared object on Irix 5.3, the .reginfo section has an
957 entsize of 0x18. FIXME: Does this matter? */
958 if ((abfd->flags & DYNAMIC) != 0)
959 hdr->sh_entsize = sizeof (Elf64_External_RegInfo);
963 /* Force the section size to the correct value, even if the
964 linker thinks it is larger. The link routine below will only
965 write out this much data for .reginfo. */
966 hdr->sh_size = sec->_raw_size = sizeof (Elf64_External_RegInfo);
968 else if (strcmp (name, ".hash") == 0
969 || strcmp (name, ".dynamic") == 0
970 || strcmp (name, ".dynstr") == 0)
973 hdr->sh_info = SIZEOF_ALPHA_DYNSYM_SECNAMES;
976 else if (strcmp (name, ".sdata") == 0
977 || strcmp (name, ".sbss") == 0
978 || strcmp (name, ".lit4") == 0
979 || strcmp (name, ".lit8") == 0)
980 hdr->sh_flags |= SHF_ALPHA_GPREL;
985 /* Return the number of additional phdrs we will need. */
988 elf64_alpha_additional_program_headers (abfd)
996 s = bfd_get_section_by_name (abfd, ".reginfo");
997 if (s != NULL && (s->flags & SEC_LOAD) != 0)
999 /* We need a PT_ALPHA_REGINFO segment. */
1003 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL
1004 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
1006 /* We need a PT_ALPHA_RTPROC segment. */
1013 /* Create the .got section. */
1016 elf64_alpha_create_got_section(abfd, info)
1018 struct bfd_link_info *info;
1022 if (bfd_get_section_by_name (abfd, ".got"))
1025 s = bfd_make_section (abfd, ".got");
1027 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1030 | SEC_LINKER_CREATED))
1031 || !bfd_set_section_alignment (abfd, s, 3))
1034 alpha_elf_tdata (abfd)->got = s;
1039 /* Create all the dynamic sections. */
1042 elf64_alpha_create_dynamic_sections (abfd, info)
1044 struct bfd_link_info *info;
1047 struct elf_link_hash_entry *h;
1049 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1051 s = bfd_make_section (abfd, ".plt");
1053 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1056 | SEC_LINKER_CREATED
1058 || ! bfd_set_section_alignment (abfd, s, 3))
1061 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1064 if (! (_bfd_generic_link_add_one_symbol
1065 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1066 (bfd_vma) 0, (const char *) NULL, false,
1067 get_elf_backend_data (abfd)->collect,
1068 (struct bfd_link_hash_entry **) &h)))
1070 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1071 h->type = STT_OBJECT;
1074 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1077 s = bfd_make_section (abfd, ".rela.plt");
1079 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1082 | SEC_LINKER_CREATED
1084 || ! bfd_set_section_alignment (abfd, s, 3))
1087 /* We may or may not have created a .got section for this object, but
1088 we definitely havn't done the rest of the work. */
1090 if (!elf64_alpha_create_got_section (abfd, info))
1093 s = bfd_make_section(abfd, ".rela.got");
1095 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1098 | SEC_LINKER_CREATED
1100 || !bfd_set_section_alignment (abfd, s, 3))
1103 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1104 dynobj's .got section. We don't do this in the linker script
1105 because we don't want to define the symbol if we are not creating
1106 a global offset table. */
1108 if (!(_bfd_generic_link_add_one_symbol
1109 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
1110 alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
1111 false, get_elf_backend_data (abfd)->collect,
1112 (struct bfd_link_hash_entry **) &h)))
1114 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1115 h->type = STT_OBJECT;
1118 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1121 elf_hash_table (info)->hgot = h;
1126 /* Read ECOFF debugging information from a .mdebug section into a
1127 ecoff_debug_info structure. */
1130 elf64_alpha_read_ecoff_info (abfd, section, debug)
1133 struct ecoff_debug_info *debug;
1136 const struct ecoff_debug_swap *swap;
1137 char *ext_hdr = NULL;
1139 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1141 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
1142 if (ext_hdr == NULL && swap->external_hdr_size != 0)
1145 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
1146 swap->external_hdr_size)
1150 symhdr = &debug->symbolic_header;
1151 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
1153 /* The symbolic header contains absolute file offsets and sizes to
1155 #define READ(ptr, offset, count, size, type) \
1156 if (symhdr->count == 0) \
1157 debug->ptr = NULL; \
1160 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1161 if (debug->ptr == NULL) \
1162 goto error_return; \
1163 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1164 || (bfd_read (debug->ptr, size, symhdr->count, \
1165 abfd) != size * symhdr->count)) \
1166 goto error_return; \
1169 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
1170 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
1171 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
1172 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
1173 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
1174 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
1176 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
1177 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
1178 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
1179 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
1180 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
1184 debug->adjust = NULL;
1189 if (ext_hdr != NULL)
1191 if (debug->line != NULL)
1193 if (debug->external_dnr != NULL)
1194 free (debug->external_dnr);
1195 if (debug->external_pdr != NULL)
1196 free (debug->external_pdr);
1197 if (debug->external_sym != NULL)
1198 free (debug->external_sym);
1199 if (debug->external_opt != NULL)
1200 free (debug->external_opt);
1201 if (debug->external_aux != NULL)
1202 free (debug->external_aux);
1203 if (debug->ss != NULL)
1205 if (debug->ssext != NULL)
1206 free (debug->ssext);
1207 if (debug->external_fdr != NULL)
1208 free (debug->external_fdr);
1209 if (debug->external_rfd != NULL)
1210 free (debug->external_rfd);
1211 if (debug->external_ext != NULL)
1212 free (debug->external_ext);
1216 /* Alpha ELF local labels start with '$'. */
1219 elf64_alpha_is_local_label (abfd, symbol)
1223 return symbol->name[0] == '$';
1226 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1227 routine in order to handle the ECOFF debugging information. We
1228 still call this mips_elf_find_line because of the slot
1229 find_line_info in elf_obj_tdata is declared that way. */
1231 struct mips_elf_find_line
1233 struct ecoff_debug_info d;
1234 struct ecoff_find_line i;
1238 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
1239 functionname_ptr, line_ptr)
1244 const char **filename_ptr;
1245 const char **functionname_ptr;
1246 unsigned int *line_ptr;
1250 msec = bfd_get_section_by_name (abfd, ".mdebug");
1254 struct mips_elf_find_line *fi;
1255 const struct ecoff_debug_swap * const swap =
1256 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1258 /* If we are called during a link, alpha_elf_final_link may have
1259 cleared the SEC_HAS_CONTENTS field. We force it back on here
1260 if appropriate (which it normally will be). */
1261 origflags = msec->flags;
1262 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
1263 msec->flags |= SEC_HAS_CONTENTS;
1265 fi = elf_tdata (abfd)->find_line_info;
1268 bfd_size_type external_fdr_size;
1271 struct fdr *fdr_ptr;
1273 fi = ((struct mips_elf_find_line *)
1274 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
1277 msec->flags = origflags;
1281 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
1283 msec->flags = origflags;
1287 /* Swap in the FDR information. */
1288 fi->d.fdr = ((struct fdr *)
1290 (fi->d.symbolic_header.ifdMax *
1291 sizeof (struct fdr))));
1292 if (fi->d.fdr == NULL)
1294 msec->flags = origflags;
1297 external_fdr_size = swap->external_fdr_size;
1298 fdr_ptr = fi->d.fdr;
1299 fraw_src = (char *) fi->d.external_fdr;
1300 fraw_end = (fraw_src
1301 + fi->d.symbolic_header.ifdMax * external_fdr_size);
1302 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
1303 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
1305 elf_tdata (abfd)->find_line_info = fi;
1307 /* Note that we don't bother to ever free this information.
1308 find_nearest_line is either called all the time, as in
1309 objdump -l, so the information should be saved, or it is
1310 rarely called, as in ld error messages, so the memory
1311 wasted is unimportant. Still, it would probably be a
1312 good idea for free_cached_info to throw it away. */
1315 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
1316 &fi->i, filename_ptr, functionname_ptr,
1319 msec->flags = origflags;
1323 msec->flags = origflags;
1326 /* Fall back on the generic ELF find_nearest_line routine. */
1328 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
1329 filename_ptr, functionname_ptr,
1333 /* Structure used to pass information to alpha_elf_output_extsym. */
1338 struct bfd_link_info *info;
1339 struct ecoff_debug_info *debug;
1340 const struct ecoff_debug_swap *swap;
1345 elf64_alpha_output_extsym (h, data)
1346 struct alpha_elf_link_hash_entry *h;
1349 struct extsym_info *einfo = (struct extsym_info *) data;
1351 asection *sec, *output_section;
1353 if (h->root.indx == -2)
1355 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1356 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
1357 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1358 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
1360 else if (einfo->info->strip == strip_all
1361 || (einfo->info->strip == strip_some
1362 && bfd_hash_lookup (einfo->info->keep_hash,
1363 h->root.root.root.string,
1364 false, false) == NULL))
1372 if (h->esym.ifd == -2)
1375 h->esym.cobol_main = 0;
1376 h->esym.weakext = 0;
1377 h->esym.reserved = 0;
1378 h->esym.ifd = ifdNil;
1379 h->esym.asym.value = 0;
1380 h->esym.asym.st = stGlobal;
1382 if (h->root.root.type != bfd_link_hash_defined
1383 && h->root.root.type != bfd_link_hash_defweak)
1384 h->esym.asym.sc = scAbs;
1389 sec = h->root.root.u.def.section;
1390 output_section = sec->output_section;
1392 /* When making a shared library and symbol h is the one from
1393 the another shared library, OUTPUT_SECTION may be null. */
1394 if (output_section == NULL)
1395 h->esym.asym.sc = scUndefined;
1398 name = bfd_section_name (output_section->owner, output_section);
1400 if (strcmp (name, ".text") == 0)
1401 h->esym.asym.sc = scText;
1402 else if (strcmp (name, ".data") == 0)
1403 h->esym.asym.sc = scData;
1404 else if (strcmp (name, ".sdata") == 0)
1405 h->esym.asym.sc = scSData;
1406 else if (strcmp (name, ".rodata") == 0
1407 || strcmp (name, ".rdata") == 0)
1408 h->esym.asym.sc = scRData;
1409 else if (strcmp (name, ".bss") == 0)
1410 h->esym.asym.sc = scBss;
1411 else if (strcmp (name, ".sbss") == 0)
1412 h->esym.asym.sc = scSBss;
1413 else if (strcmp (name, ".init") == 0)
1414 h->esym.asym.sc = scInit;
1415 else if (strcmp (name, ".fini") == 0)
1416 h->esym.asym.sc = scFini;
1418 h->esym.asym.sc = scAbs;
1422 h->esym.asym.reserved = 0;
1423 h->esym.asym.index = indexNil;
1426 if (h->root.root.type == bfd_link_hash_common)
1427 h->esym.asym.value = h->root.root.u.c.size;
1428 else if (h->root.root.type == bfd_link_hash_defined
1429 || h->root.root.type == bfd_link_hash_defweak)
1431 if (h->esym.asym.sc == scCommon)
1432 h->esym.asym.sc = scBss;
1433 else if (h->esym.asym.sc == scSCommon)
1434 h->esym.asym.sc = scSBss;
1436 sec = h->root.root.u.def.section;
1437 output_section = sec->output_section;
1438 if (output_section != NULL)
1439 h->esym.asym.value = (h->root.root.u.def.value
1440 + sec->output_offset
1441 + output_section->vma);
1443 h->esym.asym.value = 0;
1445 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1447 /* Set type and value for a symbol with a function stub. */
1448 h->esym.asym.st = stProc;
1449 sec = bfd_get_section_by_name (einfo->abfd, ".plt");
1451 h->esym.asym.value = 0;
1454 output_section = sec->output_section;
1455 if (output_section != NULL)
1456 h->esym.asym.value = (h->root.plt_offset
1457 + sec->output_offset
1458 + output_section->vma);
1460 h->esym.asym.value = 0;
1467 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
1468 h->root.root.root.string,
1471 einfo->failed = true;
1478 /* FIXME: Create a runtime procedure table from the .mdebug section.
1481 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
1484 struct bfd_link_info *info;
1486 struct ecoff_debug_info *debug;
1489 /* Handle dynamic relocations when doing an Alpha ELF link. */
1492 elf64_alpha_check_relocs (abfd, info, sec, relocs)
1494 struct bfd_link_info *info;
1496 const Elf_Internal_Rela *relocs;
1500 const char *rel_sec_name;
1501 Elf_Internal_Shdr *symtab_hdr;
1502 struct alpha_elf_link_hash_entry **sym_hashes;
1503 struct alpha_elf_got_entry **local_got_entries;
1504 const Elf_Internal_Rela *rel, *relend;
1507 if (info->relocateable)
1510 dynobj = elf_hash_table(info)->dynobj;
1512 elf_hash_table(info)->dynobj = dynobj = abfd;
1515 rel_sec_name = NULL;
1516 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
1517 sym_hashes = alpha_elf_sym_hashes(abfd);
1518 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
1521 relend = relocs + sec->reloc_count;
1522 for (rel = relocs; rel < relend; ++rel)
1524 unsigned long r_symndx, r_type;
1525 struct alpha_elf_link_hash_entry *h;
1527 r_symndx = ELF64_R_SYM (rel->r_info);
1528 if (r_symndx < symtab_hdr->sh_info)
1532 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1533 h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
1535 r_type = ELF64_R_TYPE (rel->r_info);
1539 case R_ALPHA_LITERAL:
1541 struct alpha_elf_got_entry *gotent;
1546 /* Search for and possibly create a got entry. */
1547 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
1548 if (gotent->gotobj == abfd &&
1549 gotent->addend == rel->r_addend)
1554 gotent = ((struct alpha_elf_got_entry *)
1556 sizeof (struct alpha_elf_got_entry)));
1560 gotent->gotobj = abfd;
1561 gotent->addend = rel->r_addend;
1562 gotent->got_offset = -1;
1565 gotent->next = h->got_entries;
1566 h->got_entries = gotent;
1568 alpha_elf_tdata (abfd)->total_got_entries++;
1573 /* This is a local .got entry -- record for merge. */
1574 if (!local_got_entries)
1577 size = (symtab_hdr->sh_info
1578 * sizeof (struct alpha_elf_got_entry *));
1580 local_got_entries = ((struct alpha_elf_got_entry **)
1581 bfd_alloc (abfd, size));
1582 if (!local_got_entries)
1585 memset (local_got_entries, 0, size);
1586 alpha_elf_tdata (abfd)->local_got_entries =
1590 for (gotent = local_got_entries[ELF64_R_SYM(rel->r_info)];
1591 gotent != NULL && gotent->addend != rel->r_addend;
1592 gotent = gotent->next)
1596 gotent = ((struct alpha_elf_got_entry *)
1598 sizeof (struct alpha_elf_got_entry)));
1602 gotent->gotobj = abfd;
1603 gotent->addend = rel->r_addend;
1604 gotent->got_offset = -1;
1607 gotent->next = local_got_entries[ELF64_R_SYM(rel->r_info)];
1608 local_got_entries[ELF64_R_SYM(rel->r_info)] = gotent;
1610 alpha_elf_tdata(abfd)->total_got_entries++;
1611 alpha_elf_tdata(abfd)->n_local_got_entries++;
1615 /* Remember how this literal is used from its LITUSEs.
1616 This will be important when it comes to decide if we can
1617 create a .plt entry for a function symbol. */
1619 && ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE)
1624 if (rel->r_addend >= 1 && rel->r_addend <= 3)
1625 flags |= 1 << rel->r_addend;
1627 while (rel+1 < relend &&
1628 ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE);
1632 /* No LITUSEs -- presumably the address is not being
1633 loaded for nothing. */
1634 flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
1637 gotent->flags |= flags;
1640 /* Make a guess as to whether a .plt entry will be needed. */
1641 if ((h->flags |= flags) == ALPHA_ELF_LINK_HASH_LU_FUNC)
1642 h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1644 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1649 case R_ALPHA_GPDISP:
1650 case R_ALPHA_GPREL32:
1651 /* We don't actually use the .got here, but the sections must
1652 be created before the linker maps input sections to output
1656 if (!elf64_alpha_create_got_section (abfd, info))
1659 /* Make sure the object's gotobj is set to itself so
1660 that we default to every object with its own .got.
1661 We'll merge .gots later once we've collected each
1663 alpha_elf_tdata(abfd)->gotobj = abfd;
1669 case R_ALPHA_SREL16:
1670 case R_ALPHA_SREL32:
1671 case R_ALPHA_SREL64:
1676 case R_ALPHA_REFLONG:
1677 case R_ALPHA_REFQUAD:
1678 if (rel_sec_name == NULL)
1680 rel_sec_name = (bfd_elf_string_from_elf_section
1681 (abfd, elf_elfheader(abfd)->e_shstrndx,
1682 elf_section_data(sec)->rel_hdr.sh_name));
1683 if (rel_sec_name == NULL)
1686 BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0
1687 && strcmp (bfd_get_section_name (abfd, sec),
1688 rel_sec_name+5) == 0);
1691 /* We need to create the section here now whether we eventually
1692 use it or not so that it gets mapped to an output section by
1693 the linker. If not used, we'll kill it in
1694 size_dynamic_sections. */
1697 sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
1700 sreloc = bfd_make_section (dynobj, rel_sec_name);
1702 || !bfd_set_section_flags (dynobj, sreloc,
1706 | SEC_LINKER_CREATED
1708 || !bfd_set_section_alignment (dynobj, sreloc, 3))
1715 /* Since we havn't seen all of the input symbols yet, we
1716 don't know whether we'll actually need a dynamic relocation
1717 entry for this reloc. So make a record of it. Once we
1718 find out if this thing needs dynamic relocation we'll
1719 expand the relocation sections by the appropriate amount. */
1721 struct alpha_elf_reloc_entry *rent;
1723 for (rent = h->reloc_entries; rent; rent = rent->next)
1724 if (rent->rtype == r_type && rent->srel == sreloc)
1729 rent = ((struct alpha_elf_reloc_entry *)
1731 sizeof (struct alpha_elf_reloc_entry)));
1735 rent->srel = sreloc;
1736 rent->rtype = r_type;
1739 rent->next = h->reloc_entries;
1740 h->reloc_entries = rent;
1745 else if (info->shared)
1747 /* If this is a shared library, we need a RELATIVE reloc. */
1748 sreloc->_raw_size += sizeof (Elf64_External_Rela);
1757 /* Adjust a symbol defined by a dynamic object and referenced by a
1758 regular object. The current definition is in some section of the
1759 dynamic object, but we're not including those sections. We have to
1760 change the definition to something the rest of the link can
1764 elf64_alpha_adjust_dynamic_symbol (info, h)
1765 struct bfd_link_info *info;
1766 struct elf_link_hash_entry *h;
1770 struct alpha_elf_link_hash_entry *ah;
1772 dynobj = elf_hash_table(info)->dynobj;
1773 ah = (struct alpha_elf_link_hash_entry *)h;
1775 /* Now that we've seen all of the input symbols, finalize our decision
1776 about whether this symbol should get a .plt entry. */
1778 if (h->root.type != bfd_link_hash_undefweak
1779 && alpha_elf_dynamic_symbol_p (h, info)
1780 && (h->type == STT_FUNC
1781 || (h->type == STT_NOTYPE
1782 && ah->flags == ALPHA_ELF_LINK_HASH_LU_FUNC))
1783 /* Don't prevent otherwise valid programs from linking by attempting
1784 to create a new .got entry somewhere. A Correct Solution would be
1785 to add a new .got section to a new object file and let it be merged
1786 somewhere later. But for now don't bother. */
1789 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1791 s = bfd_get_section_by_name(dynobj, ".plt");
1792 if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info))
1795 /* The first bit of the .plt is reserved. */
1796 if (s->_raw_size == 0)
1797 s->_raw_size = PLT_HEADER_SIZE;
1799 h->plt_offset = s->_raw_size;
1800 s->_raw_size += PLT_ENTRY_SIZE;
1802 /* If this symbol is not defined in a regular file, and we are not
1803 generating a shared library, then set the symbol to the location
1804 in the .plt. This is required to make function pointers compare
1805 equal between the normal executable and the shared library. */
1808 h->root.u.def.section = s;
1809 h->root.u.def.value = h->plt_offset;
1812 /* We also need a JMP_SLOT entry in the .rela.plt section. */
1813 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1814 BFD_ASSERT (s != NULL);
1815 s->_raw_size += sizeof (Elf64_External_Rela);
1820 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1822 /* If this is a weak symbol, and there is a real definition, the
1823 processor independent code will have arranged for us to see the
1824 real definition first, and we can just use the same value. */
1825 if (h->weakdef != NULL)
1827 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1828 || h->weakdef->root.type == bfd_link_hash_defweak);
1829 h->root.u.def.section = h->weakdef->root.u.def.section;
1830 h->root.u.def.value = h->weakdef->root.u.def.value;
1834 /* This is a reference to a symbol defined by a dynamic object which
1835 is not a function. The Alpha, since it uses .got entries for all
1836 symbols even in regular objects, does not need the hackery of a
1837 .dynbss section and COPY dynamic relocations. */
1842 /* Is it possible to merge two object file's .got tables? */
1845 elf64_alpha_can_merge_gots (a, b)
1848 int total = alpha_elf_tdata (a)->total_got_entries;
1850 /* Trivial quick fallout test. */
1851 if (total + alpha_elf_tdata (b)->total_got_entries <= MAX_GOT_ENTRIES)
1854 /* By their nature, local .got entries cannot be merged. */
1855 if ((total += alpha_elf_tdata (b)->n_local_got_entries) > MAX_GOT_ENTRIES)
1858 /* Failing the common trivial comparison, we must effectively
1859 perform the merge. Not actually performing the merge means that
1860 we don't have to store undo information in case we fail. */
1862 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes(b);
1863 Elf_Internal_Shdr *symtab_hdr = &elf_tdata(b)->symtab_hdr;
1866 n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info;
1867 for (i = 0; i < n; ++i)
1869 struct alpha_elf_got_entry *ae, *be;
1870 for (be = hashes[i]->got_entries; be ; be = be->next)
1872 if (be->gotobj != b)
1875 for (ae = hashes[i]->got_entries; ae ; ae = ae->next)
1876 if (ae->gotobj == a && ae->addend == be->addend)
1879 if (++total > MAX_GOT_ENTRIES)
1889 /* Actually merge two .got tables. */
1892 elf64_alpha_merge_gots (a, b)
1895 int total = alpha_elf_tdata(a)->total_got_entries;
1897 /* Remember local expansion. */
1899 int e = alpha_elf_tdata(b)->n_local_got_entries;
1901 alpha_elf_tdata(a)->n_local_got_entries += e;
1904 /* Let the local .got entries know they are part of a new subsegment. */
1906 struct alpha_elf_got_entry **local_got_entries;
1907 local_got_entries = alpha_elf_tdata(b)->local_got_entries;
1908 if (local_got_entries)
1912 n = elf_tdata(b)->symtab_hdr.sh_info;
1913 for (i = 0; i < n; ++i)
1915 struct alpha_elf_got_entry *gotent;
1916 for (gotent = local_got_entries[i]; gotent; gotent = gotent->next)
1922 /* Merge the global .got entries. */
1924 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes(b);
1925 Elf_Internal_Shdr *symtab_hdr = &elf_tdata(b)->symtab_hdr;
1928 n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info;
1929 for (i = 0; i < n; ++i)
1931 struct alpha_elf_got_entry *ae, *be, **pbe, **start;
1932 start = &hashes[i]->got_entries;
1933 for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
1935 if (be->gotobj != b)
1938 for (ae = *start; ae ; ae = ae->next)
1939 if (ae->gotobj == a && ae->addend == be->addend)
1952 alpha_elf_tdata(a)->total_got_entries = total;
1953 alpha_elf_tdata(b)->gotobj = a;
1956 /* Calculate the offsets for the got entries. */
1959 elf64_alpha_calc_got_offsets_for_symbol (h, arg)
1960 struct alpha_elf_link_hash_entry *h;
1963 struct alpha_elf_got_entry *gotent;
1965 for (gotent = h->got_entries; gotent; gotent = gotent->next)
1967 bfd_size_type *plge = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
1968 gotent->got_offset = *plge;
1976 elf64_alpha_calc_got_offsets (info)
1977 struct bfd_link_info *info;
1979 bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
1981 /* First, zero out the .got sizes, as we may be recalculating the
1982 .got after optimizing it. */
1983 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
1984 alpha_elf_tdata(i)->got->_raw_size = 0;
1986 /* Next, fill in the offsets for all the global entries. */
1987 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
1988 elf64_alpha_calc_got_offsets_for_symbol,
1991 /* Finally, fill in the offsets for the local entries. */
1992 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
1994 bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
1997 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
1999 struct alpha_elf_got_entry **local_got_entries, *gotent;
2002 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
2003 if (!local_got_entries)
2006 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
2007 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
2009 gotent->got_offset = got_offset;
2014 alpha_elf_tdata(i)->got->_raw_size = got_offset;
2018 /* Remove a section from the output BFD. */
2021 elf64_alpha_strip_section_from_output (s)
2026 for (spp = &s->output_section->owner->sections;
2027 *spp != s->output_section;
2028 spp = &(*spp)->next)
2030 *spp = s->output_section->next;
2031 --s->output_section->owner->section_count;
2034 /* Constructs the gots. */
2037 elf64_alpha_always_size_sections (output_bfd, info)
2039 struct bfd_link_info *info;
2041 bfd *i, *got_list, *cur_got_obj, **cur_got_tail;
2044 if (info->relocateable)
2050 cur_got_tail = NULL;
2051 for (i = info->input_bfds; i ; i = i->link_next)
2053 bfd *this_got = alpha_elf_tdata (i)->gotobj;
2055 /* Don't play if there is no .got for this input file. */
2056 if (this_got == NULL)
2059 if (alpha_elf_tdata (this_got)->total_got_entries > MAX_GOT_ENTRIES)
2061 /* Yikes! A single object file has too many entries. */
2062 (*_bfd_error_handler)
2063 ("%s: .got subsegment exceeds 64K (size %d)",
2064 bfd_get_filename(i),
2065 alpha_elf_tdata(this_got)->total_got_entries * 8);
2071 if (elf64_alpha_can_merge_gots (cur_got_obj, i))
2073 elf64_alpha_merge_gots (cur_got_obj, i);
2080 (*info->callbacks->warning)
2081 (info, "using multiple gp values", (char *) NULL,
2082 output_bfd, (asection *) NULL, (bfd_vma) 0);
2084 *cur_got_tail = NULL;
2085 alpha_elf_tdata(cur_got_obj)->got_link_next = got_list;
2086 got_list = cur_got_obj;
2095 cur_got_tail = &alpha_elf_tdata(i)->in_got_link_next;
2099 alpha_elf_tdata (cur_got_obj)->got_link_next = got_list;
2100 alpha_elf_hash_table (info)->got_list = got_list = cur_got_obj;
2102 /* Once the gots have been merged, fill in the got offsets for everything
2104 elf64_alpha_calc_got_offsets (info);
2106 /* Allocate space for all of the .got subsections. */
2107 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
2109 asection *s = alpha_elf_tdata(i)->got;
2110 if (s->_raw_size > 0)
2112 s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
2113 if (s->contents == NULL)
2121 /* Work out the sizes of the dynamic relocation entries. */
2124 elf64_alpha_calc_dynrel_sizes (h, info)
2125 struct alpha_elf_link_hash_entry *h;
2126 struct bfd_link_info *info;
2128 /* If the symbol was defined as a common symbol in a regular object
2129 file, and there was no definition in any dynamic object, then the
2130 linker will have allocated space for the symbol in a common
2131 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
2132 set. This is done for dynamic symbols in
2133 elf_adjust_dynamic_symbol but this is not done for non-dynamic
2134 symbols, somehow. */
2135 if (((h->root.elf_link_hash_flags
2136 & (ELF_LINK_HASH_DEF_REGULAR
2137 | ELF_LINK_HASH_REF_REGULAR
2138 | ELF_LINK_HASH_DEF_DYNAMIC))
2139 == ELF_LINK_HASH_REF_REGULAR)
2140 && (h->root.root.type == bfd_link_hash_defined
2141 || h->root.root.type == bfd_link_hash_defweak)
2142 && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
2144 h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2147 /* If the symbol is dynamic, we'll need all the relocations in their
2149 if (alpha_elf_dynamic_symbol_p (&h->root, info))
2151 struct alpha_elf_reloc_entry *relent;
2153 for (relent = h->reloc_entries; relent; relent = relent->next)
2155 relent->srel->_raw_size +=
2156 sizeof (Elf64_External_Rela) * relent->count;
2159 /* Only add a .rela.got entry if we're not using a .plt entry. */
2160 if (h->root.plt_offset == MINUS_ONE)
2162 bfd *dynobj = elf_hash_table(info)->dynobj;
2163 struct alpha_elf_got_entry *gotent;
2164 bfd_size_type count = 0;
2167 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
2171 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2172 BFD_ASSERT (srel != NULL);
2173 srel->_raw_size += sizeof (Elf64_External_Rela) * count;
2177 /* Otherwise, shared objects require RELATIVE relocs for all REFQUAD
2178 and REFLONG relocations. */
2179 else if (info->shared)
2181 struct alpha_elf_reloc_entry *relent;
2183 for (relent = h->reloc_entries; relent; relent = relent->next)
2184 if (relent->rtype == R_ALPHA_REFLONG
2185 || relent->rtype == R_ALPHA_REFQUAD)
2187 relent->srel->_raw_size +=
2188 sizeof(Elf64_External_Rela) * relent->count;
2195 /* Set the sizes of the dynamic sections. */
2198 elf64_alpha_size_dynamic_sections (output_bfd, info)
2200 struct bfd_link_info *info;
2207 dynobj = elf_hash_table(info)->dynobj;
2208 BFD_ASSERT(dynobj != NULL);
2210 if (elf_hash_table (info)->dynamic_sections_created)
2212 /* Set the contents of the .interp section to the interpreter. */
2215 s = bfd_get_section_by_name (dynobj, ".interp");
2216 BFD_ASSERT (s != NULL);
2217 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2218 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2221 /* Now that we've seen all of the input files, we can decide which
2222 symbols need dynamic relocation entries and which don't. We've
2223 collected information in check_relocs that we can now apply to
2224 size the dynamic relocation sections. */
2225 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
2226 elf64_alpha_calc_dynrel_sizes,
2229 /* When building shared libraries, each local .got entry needs a
2235 bfd_size_type count;
2237 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2238 BFD_ASSERT (srel != NULL);
2240 for (i = alpha_elf_hash_table(info)->got_list, count = 0;
2242 i = alpha_elf_tdata(i)->got_link_next)
2243 count += alpha_elf_tdata(i)->n_local_got_entries;
2245 srel->_raw_size += count * sizeof(Elf64_External_Rela);
2248 /* else we're not dynamic and by definition we don't need such things. */
2250 /* The check_relocs and adjust_dynamic_symbol entry points have
2251 determined the sizes of the various dynamic sections. Allocate
2255 for (s = dynobj->sections; s != NULL; s = s->next)
2260 if (!(s->flags & SEC_LINKER_CREATED))
2263 /* It's OK to base decisions on the section name, because none
2264 of the dynobj section names depend upon the input files. */
2265 name = bfd_get_section_name (dynobj, s);
2267 /* If we don't need this section, strip it from the output file.
2268 This is to handle .rela.bss and .rela.plt. We must create it
2269 in create_dynamic_sections, because it must be created before
2270 the linker maps input sections to output sections. The
2271 linker does that before adjust_dynamic_symbol is called, and
2272 it is that function which decides whether anything needs to
2273 go into these sections. */
2277 if (strncmp (name, ".rela", 5) == 0)
2279 strip = (s->_raw_size == 0);
2285 /* If this relocation section applies to a read only
2286 section, then we probably need a DT_TEXTREL entry. */
2287 target = bfd_get_section_by_name (output_bfd, name + 5);
2289 && (target->flags & SEC_READONLY) != 0)
2292 if (strcmp(name, ".rela.plt") == 0)
2295 /* We use the reloc_count field as a counter if we need
2296 to copy relocs into the output file. */
2300 else if (strcmp (name, ".plt") != 0)
2302 /* It's not one of our dynamic sections, so don't allocate space. */
2307 elf64_alpha_strip_section_from_output (s);
2310 /* Allocate memory for the section contents. */
2311 s->contents = (bfd_byte *) bfd_zalloc(dynobj, s->_raw_size);
2312 if (s->contents == NULL && s->_raw_size != 0)
2317 /* If we are generating a shared library, we generate a section
2318 symbol for each output section. These are local symbols, which
2319 means that they must come first in the dynamic symbol table.
2320 That means we must increment the dynamic symbol index of every
2321 other dynamic symbol. */
2328 c[1] = bfd_count_sections (output_bfd);
2330 elf_hash_table (info)->dynsymcount += c[1];
2331 elf_link_hash_traverse (elf_hash_table(info),
2332 elf64_alpha_adjust_dynindx,
2335 for (i = 1, p = output_bfd->sections;
2339 elf_section_data (p)->dynindx = i;
2340 /* These symbols will have no names, so we don't need to
2341 fiddle with dynstr_index. */
2345 if (elf_hash_table (info)->dynamic_sections_created)
2347 /* Add some entries to the .dynamic section. We fill in the
2348 values later, in elf64_alpha_finish_dynamic_sections, but we
2349 must add the entries now so that we get the correct size for
2350 the .dynamic section. The DT_DEBUG entry is filled in by the
2351 dynamic linker and used by the debugger. */
2354 if (!bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
2358 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0))
2363 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
2364 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
2365 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
2369 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
2370 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
2371 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
2372 sizeof(Elf64_External_Rela)))
2377 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
2385 /* Increment the index of a dynamic symbol by a given amount. Called
2386 via elf_link_hash_traverse. */
2389 elf64_alpha_adjust_dynindx (h, cparg)
2390 struct elf_link_hash_entry *h;
2393 long *cp = (long *)cparg;
2395 if (h->dynindx >= cp[0])
2396 h->dynindx += cp[1];
2401 /* Relocate an Alpha ELF section. */
2404 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
2405 contents, relocs, local_syms, local_sections)
2407 struct bfd_link_info *info;
2409 asection *input_section;
2411 Elf_Internal_Rela *relocs;
2412 Elf_Internal_Sym *local_syms;
2413 asection **local_sections;
2415 Elf_Internal_Shdr *symtab_hdr;
2416 Elf_Internal_Rela *rel;
2417 Elf_Internal_Rela *relend;
2418 asection *sec, *sgot, *srel, *srelgot;
2419 bfd *dynobj, *gotobj;
2422 srelgot = srel = NULL;
2423 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2424 dynobj = elf_hash_table (info)->dynobj;
2427 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2430 /* Find the gp value for this input bfd. */
2433 gotobj = alpha_elf_tdata (input_bfd)->gotobj;
2436 sgot = alpha_elf_tdata (gotobj)->got;
2437 gp = _bfd_get_gp_value (gotobj);
2440 gp = (sgot->output_section->vma
2441 + sgot->output_offset
2443 _bfd_set_gp_value (gotobj, gp);
2448 relend = relocs + input_section->reloc_count;
2449 for (; rel < relend; rel++)
2452 reloc_howto_type *howto;
2453 unsigned long r_symndx;
2454 struct alpha_elf_link_hash_entry *h;
2455 Elf_Internal_Sym *sym;
2458 bfd_reloc_status_type r;
2460 r_type = ELF64_R_TYPE(rel->r_info);
2461 if (r_type < 0 || r_type >= (int) R_ALPHA_max)
2463 bfd_set_error (bfd_error_bad_value);
2466 howto = elf64_alpha_howto_table + r_type;
2468 r_symndx = ELF64_R_SYM(rel->r_info);
2470 if (info->relocateable)
2472 /* This is a relocateable link. We don't have to change
2473 anything, unless the reloc is against a section symbol,
2474 in which case we have to adjust according to where the
2475 section symbol winds up in the output section. */
2476 if (r_symndx < symtab_hdr->sh_info)
2478 sym = local_syms + r_symndx;
2479 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
2481 sec = local_sections[r_symndx];
2482 rel->r_addend += sec->output_offset + sym->st_value;
2489 /* This is a final link. */
2495 if (r_symndx < symtab_hdr->sh_info)
2497 sym = local_syms + r_symndx;
2498 sec = local_sections[r_symndx];
2499 relocation = (sec->output_section->vma
2500 + sec->output_offset
2505 h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info];
2507 while (h->root.root.type == bfd_link_hash_indirect
2508 || h->root.root.type == bfd_link_hash_warning)
2509 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2511 if (h->root.root.type == bfd_link_hash_defined
2512 || h->root.root.type == bfd_link_hash_defweak)
2514 sec = h->root.root.u.def.section;
2517 if ((r_type == R_ALPHA_LITERAL
2518 && elf_hash_table(info)->dynamic_sections_created
2521 || !(h->root.elf_link_hash_flags
2522 & ELF_LINK_HASH_DEF_REGULAR)))
2525 || !(h->root.elf_link_hash_flags
2526 & ELF_LINK_HASH_DEF_REGULAR))
2527 && (input_section->flags & SEC_ALLOC)
2528 && (r_type == R_ALPHA_REFLONG
2529 || r_type == R_ALPHA_REFQUAD
2530 || r_type == R_ALPHA_LITERAL)))
2532 /* In these cases, we don't need the relocation value.
2533 We check specially because in some obscure cases
2534 sec->output_section will be NULL. */
2538 /* FIXME: Are not these obscure cases simply bugs? Let's
2539 get something working and come back to this. */
2540 if (sec->output_section == NULL)
2542 #endif /* rth_notdef */
2545 relocation = (h->root.root.u.def.value
2546 + sec->output_section->vma
2547 + sec->output_offset);
2550 else if (h->root.root.type == bfd_link_hash_undefweak)
2552 else if (info->shared && !info->symbolic)
2556 if (!((*info->callbacks->undefined_symbol)
2557 (info, h->root.root.root.string, input_bfd,
2558 input_section, rel->r_offset)))
2563 addend = rel->r_addend;
2567 case R_ALPHA_GPDISP:
2569 bfd_byte *p_ldah, *p_lda;
2571 BFD_ASSERT(gp != 0);
2573 relocation = (input_section->output_section->vma
2574 + input_section->output_offset
2577 p_ldah = contents + rel->r_offset - input_section->vma;
2578 p_lda = p_ldah + rel->r_addend;
2580 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - relocation,
2585 case R_ALPHA_OP_PUSH:
2586 case R_ALPHA_OP_STORE:
2587 case R_ALPHA_OP_PSUB:
2588 case R_ALPHA_OP_PRSHIFT:
2589 /* We hate these silly beasts. */
2592 case R_ALPHA_LITERAL:
2594 struct alpha_elf_got_entry *gotent;
2596 BFD_ASSERT(sgot != NULL);
2597 BFD_ASSERT(gp != 0);
2601 gotent = h->got_entries;
2602 while (gotent->gotobj != gotobj || gotent->addend != addend)
2603 gotent = gotent->next;
2605 /* Initialize the .got entry's value. */
2606 if (!(gotent->flags & ALPHA_ELF_GOT_ENTRY_RELOCS_DONE))
2608 bfd_put_64 (output_bfd, relocation+addend,
2609 sgot->contents + gotent->got_offset);
2611 /* The dynamic relocations for the .got entries are
2612 done in finish_dynamic_symbol. */
2614 gotent->flags |= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE;
2619 gotent = (alpha_elf_tdata(input_bfd)->
2620 local_got_entries[r_symndx]);
2621 while (gotent->addend != addend)
2622 gotent = gotent->next;
2624 if (!(gotent->flags & ALPHA_ELF_GOT_ENTRY_RELOCS_DONE))
2626 bfd_put_64 (output_bfd, relocation+addend,
2627 sgot->contents + gotent->got_offset);
2629 /* Local got entries need RELATIVE relocs in shared
2633 Elf_Internal_Rela outrel;
2635 BFD_ASSERT(srelgot != NULL);
2637 outrel.r_offset = (sgot->output_section->vma
2638 + sgot->output_offset
2639 + gotent->got_offset);
2640 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2641 outrel.r_addend = 0;
2643 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2644 ((Elf64_External_Rela *)
2646 + srelgot->reloc_count++);
2649 gotent->flags |= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE;
2653 /* Figure the gprel relocation. */
2655 relocation = (sgot->output_section->vma
2656 + sgot->output_offset
2657 + gotent->got_offset);
2660 /* overflow handled by _bfd_final_link_relocate */
2663 case R_ALPHA_GPREL32:
2664 BFD_ASSERT(gp != 0);
2668 case R_ALPHA_BRADDR:
2670 /* The regular PC-relative stuff measures from the start of
2671 the instruction rather than the end. */
2675 case R_ALPHA_REFLONG:
2676 case R_ALPHA_REFQUAD:
2678 Elf_Internal_Rela outrel;
2680 /* Careful here to remember RELATIVE relocations for global
2681 variables for symbolic shared objects. */
2683 if (h && alpha_elf_dynamic_symbol_p (&h->root, info))
2685 BFD_ASSERT(h->root.dynindx != -1);
2686 outrel.r_info = ELF64_R_INFO(h->root.dynindx, r_type);
2687 outrel.r_addend = addend;
2688 addend = 0, relocation = 0;
2690 else if (info->shared)
2692 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2693 outrel.r_addend = 0;
2702 name = (bfd_elf_string_from_elf_section
2703 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
2704 elf_section_data(input_section)->rel_hdr.sh_name));
2705 BFD_ASSERT(name != NULL);
2707 srel = bfd_get_section_by_name (dynobj, name);
2708 BFD_ASSERT(srel != NULL);
2711 outrel.r_offset = (input_section->output_section->vma
2712 + input_section->output_offset
2715 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2716 ((Elf64_External_Rela *)
2718 + srel->reloc_count++);
2724 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2725 contents, rel->r_offset, relocation,
2735 case bfd_reloc_overflow:
2740 name = h->root.root.root.string;
2743 name = (bfd_elf_string_from_elf_section
2744 (input_bfd, symtab_hdr->sh_link, sym->st_name));
2748 name = bfd_section_name (input_bfd, sec);
2750 if (! ((*info->callbacks->reloc_overflow)
2751 (info, name, howto->name, (bfd_vma) 0,
2752 input_bfd, input_section, rel->r_offset)))
2758 case bfd_reloc_outofrange:
2766 /* Finish up dynamic symbol handling. We set the contents of various
2767 dynamic sections here. */
2770 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
2772 struct bfd_link_info *info;
2773 struct elf_link_hash_entry *h;
2774 Elf_Internal_Sym *sym;
2776 bfd *dynobj = elf_hash_table(info)->dynobj;
2778 if (h->plt_offset != MINUS_ONE)
2780 /* Fill in the .plt entry for this symbol. */
2781 asection *splt, *sgot, *srel;
2782 Elf_Internal_Rela outrel;
2783 bfd_vma got_addr, plt_addr;
2785 struct alpha_elf_got_entry *gotent;
2787 BFD_ASSERT (h->dynindx != -1);
2789 /* The first .got entry will be updated by the .plt with the
2790 address of the target function. */
2791 gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
2792 BFD_ASSERT (gotent && gotent->addend == 0);
2794 splt = bfd_get_section_by_name (dynobj, ".plt");
2795 BFD_ASSERT (splt != NULL);
2796 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
2797 BFD_ASSERT (srel != NULL);
2798 sgot = alpha_elf_tdata (gotent->gotobj)->got;
2799 BFD_ASSERT (sgot != NULL);
2801 got_addr = (sgot->output_section->vma
2802 + sgot->output_offset
2803 + gotent->got_offset);
2804 plt_addr = (splt->output_section->vma
2805 + splt->output_offset
2808 plt_index = (h->plt_offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
2810 /* Fill in the entry in the procedure linkage table. */
2812 unsigned insn1, insn2, insn3;
2815 /* decompose the reloc offset for the plt for ldah+lda */
2816 hi = plt_index * sizeof(Elf64_External_Rela);
2817 lo = ((hi & 0xffff) ^ 0x8000) - 0x8000;
2818 hi = (hi - lo) >> 16;
2820 insn1 = PLT_ENTRY_WORD1 | (hi & 0xffff);
2821 insn2 = PLT_ENTRY_WORD2 | (lo & 0xffff);
2822 insn3 = PLT_ENTRY_WORD3 | ((-(h->plt_offset + 12) >> 2) & 0x1fffff);
2824 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt_offset);
2825 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt_offset + 4);
2826 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt_offset + 8);
2829 /* Fill in the entry in the .rela.plt section. */
2830 outrel.r_offset = got_addr;
2831 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
2832 outrel.r_addend = 0;
2834 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2835 ((Elf64_External_Rela *)srel->contents
2838 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2840 /* Mark the symbol as undefined, rather than as defined in the
2841 .plt section. Leave the value alone. */
2842 sym->st_shndx = SHN_UNDEF;
2845 /* Fill in the entries in the .got. */
2846 bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
2848 /* Subsequent .got entries will continue to bounce through the .plt. */
2849 while ((gotent = gotent->next) != NULL)
2851 sgot = alpha_elf_tdata(gotent->gotobj)->got;
2852 BFD_ASSERT(sgot != NULL);
2853 BFD_ASSERT(gotent->addend == 0);
2855 bfd_put_64 (output_bfd, plt_addr,
2856 sgot->contents + gotent->got_offset);
2859 else if (alpha_elf_dynamic_symbol_p (h, info))
2861 /* Fill in the dynamic relocations for this symbol's .got entries. */
2863 Elf_Internal_Rela outrel;
2864 struct alpha_elf_got_entry *gotent;
2866 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2867 BFD_ASSERT (srel != NULL);
2869 outrel.r_info = ELF64_R_INFO (h->dynindx, R_ALPHA_GLOB_DAT);
2870 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
2872 gotent = gotent->next)
2874 asection *sgot = alpha_elf_tdata (gotent->gotobj)->got;
2875 outrel.r_offset = (sgot->output_section->vma
2876 + sgot->output_offset
2877 + gotent->got_offset);
2878 outrel.r_addend = gotent->addend;
2880 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2881 ((Elf64_External_Rela *)srel->contents
2882 + srel->reloc_count++));
2886 /* Mark some specially defined symbols as absolute. */
2887 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2888 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2889 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2890 sym->st_shndx = SHN_ABS;
2895 /* Finish up the dynamic sections. */
2898 elf64_alpha_finish_dynamic_sections (output_bfd, info)
2900 struct bfd_link_info *info;
2905 dynobj = elf_hash_table (info)->dynobj;
2906 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2908 if (elf_hash_table (info)->dynamic_sections_created)
2911 Elf64_External_Dyn *dyncon, *dynconend;
2913 splt = bfd_get_section_by_name (dynobj, ".plt");
2914 BFD_ASSERT (splt != NULL && sdyn != NULL);
2916 dyncon = (Elf64_External_Dyn *) sdyn->contents;
2917 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2918 for (; dyncon < dynconend; dyncon++)
2920 Elf_Internal_Dyn dyn;
2924 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2939 /* My interpretation of the TIS v1.1 ELF document indicates
2940 that RELASZ should not include JMPREL. This is not what
2941 the rest of the BFD does. It is, however, what the
2942 glibc ld.so wants. Do this fixup here until we found
2943 out who is right. */
2944 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2948 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
2953 s = bfd_get_section_by_name (output_bfd, name);
2954 dyn.d_un.d_ptr = (s ? s->vma : 0);
2958 s = bfd_get_section_by_name (output_bfd, name);
2960 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
2964 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2967 /* Initialize the PLT0 entry */
2968 if (splt->_raw_size > 0)
2970 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
2971 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
2972 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
2973 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
2975 /* The next two words will be filled in by ld.so */
2976 bfd_put_64 (output_bfd, 0, splt->contents + 16);
2977 bfd_put_64 (output_bfd, 0, splt->contents + 24);
2979 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
2988 Elf_Internal_Sym sym;
2990 /* Set up the section symbols for the output sections. */
2992 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
2993 BFD_ASSERT (sdynsym != NULL);
2997 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
3000 for (s = output_bfd->sections; s != NULL; s = s->next)
3004 sym.st_value = s->vma;
3006 indx = elf_section_data (s)->this_idx;
3007 BFD_ASSERT (indx > 0);
3008 sym.st_shndx = indx;
3010 bfd_elf64_swap_symbol_out (output_bfd, &sym,
3011 (PTR) (((Elf64_External_Sym *)
3013 + elf_section_data (s)->dynindx));
3016 /* Set the sh_info field of the output .dynsym section to the
3017 index of the first global symbol. */
3018 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
3019 bfd_count_sections (output_bfd) + 1;
3025 /* We need to use a special link routine to handle the .reginfo and
3026 the .mdebug sections. We need to merge all instances of these
3027 sections together, not write them all out sequentially. */
3030 elf64_alpha_final_link (abfd, info)
3032 struct bfd_link_info *info;
3035 struct bfd_link_order *p;
3036 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
3037 struct ecoff_debug_info debug;
3038 const struct ecoff_debug_swap *swap
3039 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3040 HDRR *symhdr = &debug.symbolic_header;
3041 PTR mdebug_handle = NULL;
3043 /* Go through the sections and collect the .reginfo and .mdebug
3047 gptab_data_sec = NULL;
3048 gptab_bss_sec = NULL;
3049 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3051 #ifdef ERIC_neverdef
3052 if (strcmp (o->name, ".reginfo") == 0)
3054 memset (®info, 0, sizeof reginfo);
3056 /* We have found the .reginfo section in the output file.
3057 Look through all the link_orders comprising it and merge
3058 the information together. */
3059 for (p = o->link_order_head;
3060 p != (struct bfd_link_order *) NULL;
3063 asection *input_section;
3065 Elf64_External_RegInfo ext;
3068 if (p->type != bfd_indirect_link_order)
3070 if (p->type == bfd_fill_link_order)
3075 input_section = p->u.indirect.section;
3076 input_bfd = input_section->owner;
3078 /* The linker emulation code has probably clobbered the
3079 size to be zero bytes. */
3080 if (input_section->_raw_size == 0)
3081 input_section->_raw_size = sizeof (Elf64_External_RegInfo);
3083 if (! bfd_get_section_contents (input_bfd, input_section,
3089 bfd_alpha_elf64_swap_reginfo_in (input_bfd, &ext, &sub);
3091 reginfo.ri_gprmask |= sub.ri_gprmask;
3092 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
3093 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
3094 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
3095 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
3097 /* ri_gp_value is set by the function
3098 alpha_elf_section_processing when the section is
3099 finally written out. */
3101 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3102 elf_link_input_bfd ignores this section. */
3103 input_section->flags &=~ SEC_HAS_CONTENTS;
3106 /* Force the section size to the value we want. */
3107 o->_raw_size = sizeof (Elf64_External_RegInfo);
3109 /* Skip this section later on (I don't think this currently
3110 matters, but someday it might). */
3111 o->link_order_head = (struct bfd_link_order *) NULL;
3117 if (strcmp (o->name, ".mdebug") == 0)
3119 struct extsym_info einfo;
3121 /* We have found the .mdebug section in the output file.
3122 Look through all the link_orders comprising it and merge
3123 the information together. */
3124 symhdr->magic = swap->sym_magic;
3125 /* FIXME: What should the version stamp be? */
3127 symhdr->ilineMax = 0;
3131 symhdr->isymMax = 0;
3132 symhdr->ioptMax = 0;
3133 symhdr->iauxMax = 0;
3135 symhdr->issExtMax = 0;
3138 symhdr->iextMax = 0;
3140 /* We accumulate the debugging information itself in the
3141 debug_info structure. */
3143 debug.external_dnr = NULL;
3144 debug.external_pdr = NULL;
3145 debug.external_sym = NULL;
3146 debug.external_opt = NULL;
3147 debug.external_aux = NULL;
3149 debug.ssext = debug.ssext_end = NULL;
3150 debug.external_fdr = NULL;
3151 debug.external_rfd = NULL;
3152 debug.external_ext = debug.external_ext_end = NULL;
3154 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
3155 if (mdebug_handle == (PTR) NULL)
3164 static const char * const name[] =
3166 ".text", ".init", ".fini", ".data",
3167 ".rodata", ".sdata", ".sbss", ".bss"
3169 static const int sc[] = { scText, scInit, scFini, scData,
3170 scRData, scSData, scSBss, scBss };
3173 esym.cobol_main = 0;
3177 esym.asym.iss = issNil;
3178 esym.asym.st = stLocal;
3179 esym.asym.reserved = 0;
3180 esym.asym.index = indexNil;
3181 for (i = 0; i < 8; i++)
3183 esym.asym.sc = sc[i];
3184 s = bfd_get_section_by_name (abfd, name[i]);
3187 esym.asym.value = s->vma;
3188 last = s->vma + s->_raw_size;
3191 esym.asym.value = last;
3193 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
3199 for (p = o->link_order_head;
3200 p != (struct bfd_link_order *) NULL;
3203 asection *input_section;
3205 const struct ecoff_debug_swap *input_swap;
3206 struct ecoff_debug_info input_debug;
3210 if (p->type != bfd_indirect_link_order)
3212 if (p->type == bfd_fill_link_order)
3217 input_section = p->u.indirect.section;
3218 input_bfd = input_section->owner;
3220 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
3221 || (get_elf_backend_data (input_bfd)
3222 ->elf_backend_ecoff_debug_swap) == NULL)
3224 /* I don't know what a non ALPHA ELF bfd would be
3225 doing with a .mdebug section, but I don't really
3226 want to deal with it. */
3230 input_swap = (get_elf_backend_data (input_bfd)
3231 ->elf_backend_ecoff_debug_swap);
3233 BFD_ASSERT (p->size == input_section->_raw_size);
3235 /* The ECOFF linking code expects that we have already
3236 read in the debugging information and set up an
3237 ecoff_debug_info structure, so we do that now. */
3238 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
3242 if (! (bfd_ecoff_debug_accumulate
3243 (mdebug_handle, abfd, &debug, swap, input_bfd,
3244 &input_debug, input_swap, info)))
3247 /* Loop through the external symbols. For each one with
3248 interesting information, try to find the symbol in
3249 the linker global hash table and save the information
3250 for the output external symbols. */
3251 eraw_src = input_debug.external_ext;
3252 eraw_end = (eraw_src
3253 + (input_debug.symbolic_header.iextMax
3254 * input_swap->external_ext_size));
3256 eraw_src < eraw_end;
3257 eraw_src += input_swap->external_ext_size)
3261 struct alpha_elf_link_hash_entry *h;
3263 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
3264 if (ext.asym.sc == scNil
3265 || ext.asym.sc == scUndefined
3266 || ext.asym.sc == scSUndefined)
3269 name = input_debug.ssext + ext.asym.iss;
3270 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
3271 name, false, false, true);
3272 if (h == NULL || h->esym.ifd != -2)
3278 < input_debug.symbolic_header.ifdMax);
3279 ext.ifd = input_debug.ifdmap[ext.ifd];
3285 /* Free up the information we just read. */
3286 free (input_debug.line);
3287 free (input_debug.external_dnr);
3288 free (input_debug.external_pdr);
3289 free (input_debug.external_sym);
3290 free (input_debug.external_opt);
3291 free (input_debug.external_aux);
3292 free (input_debug.ss);
3293 free (input_debug.ssext);
3294 free (input_debug.external_fdr);
3295 free (input_debug.external_rfd);
3296 free (input_debug.external_ext);
3298 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3299 elf_link_input_bfd ignores this section. */
3300 input_section->flags &=~ SEC_HAS_CONTENTS;
3303 #ifdef ERIC_neverdef
3306 /* Create .rtproc section. */
3307 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
3308 if (rtproc_sec == NULL)
3310 flagword flags = (SEC_HAS_CONTENTS
3312 | SEC_LINKER_CREATED
3315 rtproc_sec = bfd_make_section (abfd, ".rtproc");
3316 if (rtproc_sec == NULL
3317 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
3318 || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
3322 if (! alpha_elf_create_procedure_table (mdebug_handle, abfd,
3323 info, rtproc_sec, &debug))
3329 /* Build the external symbol information. */
3332 einfo.debug = &debug;
3334 einfo.failed = false;
3335 elf_link_hash_traverse (elf_hash_table (info),
3336 elf64_alpha_output_extsym,
3341 /* Set the size of the .mdebug section. */
3342 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
3344 /* Skip this section later on (I don't think this currently
3345 matters, but someday it might). */
3346 o->link_order_head = (struct bfd_link_order *) NULL;
3351 #ifdef ERIC_neverdef
3352 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
3354 const char *subname;
3357 Elf64_External_gptab *ext_tab;
3360 /* The .gptab.sdata and .gptab.sbss sections hold
3361 information describing how the small data area would
3362 change depending upon the -G switch. These sections
3363 not used in executables files. */
3364 if (! info->relocateable)
3368 for (p = o->link_order_head;
3369 p != (struct bfd_link_order *) NULL;
3372 asection *input_section;
3374 if (p->type != bfd_indirect_link_order)
3376 if (p->type == bfd_fill_link_order)
3381 input_section = p->u.indirect.section;
3383 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3384 elf_link_input_bfd ignores this section. */
3385 input_section->flags &=~ SEC_HAS_CONTENTS;
3388 /* Skip this section later on (I don't think this
3389 currently matters, but someday it might). */
3390 o->link_order_head = (struct bfd_link_order *) NULL;
3392 /* Really remove the section. */
3393 for (secpp = &abfd->sections;
3395 secpp = &(*secpp)->next)
3397 *secpp = (*secpp)->next;
3398 --abfd->section_count;
3403 /* There is one gptab for initialized data, and one for
3404 uninitialized data. */
3405 if (strcmp (o->name, ".gptab.sdata") == 0)
3407 else if (strcmp (o->name, ".gptab.sbss") == 0)
3411 (*_bfd_error_handler)
3412 ("%s: illegal section name `%s'",
3413 bfd_get_filename (abfd), o->name);
3414 bfd_set_error (bfd_error_nonrepresentable_section);
3418 /* The linker script always combines .gptab.data and
3419 .gptab.sdata into .gptab.sdata, and likewise for
3420 .gptab.bss and .gptab.sbss. It is possible that there is
3421 no .sdata or .sbss section in the output file, in which
3422 case we must change the name of the output section. */
3423 subname = o->name + sizeof ".gptab" - 1;
3424 if (bfd_get_section_by_name (abfd, subname) == NULL)
3426 if (o == gptab_data_sec)
3427 o->name = ".gptab.data";
3429 o->name = ".gptab.bss";
3430 subname = o->name + sizeof ".gptab" - 1;
3431 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
3434 /* Set up the first entry. */
3436 tab = (Elf64_gptab *) bfd_malloc (c * sizeof (Elf64_gptab));
3439 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
3440 tab[0].gt_header.gt_unused = 0;
3442 /* Combine the input sections. */
3443 for (p = o->link_order_head;
3444 p != (struct bfd_link_order *) NULL;
3447 asection *input_section;
3451 bfd_size_type gpentry;
3453 if (p->type != bfd_indirect_link_order)
3455 if (p->type == bfd_fill_link_order)
3460 input_section = p->u.indirect.section;
3461 input_bfd = input_section->owner;
3463 /* Combine the gptab entries for this input section one
3464 by one. We know that the input gptab entries are
3465 sorted by ascending -G value. */
3466 size = bfd_section_size (input_bfd, input_section);
3468 for (gpentry = sizeof (Elf64_External_gptab);
3470 gpentry += sizeof (Elf64_External_gptab))
3472 Elf64_External_gptab ext_gptab;
3473 Elf64_gptab int_gptab;
3479 if (! (bfd_get_section_contents
3480 (input_bfd, input_section, (PTR) &ext_gptab,
3481 gpentry, sizeof (Elf64_External_gptab))))
3487 bfd_alpha_elf64_swap_gptab_in (input_bfd, &ext_gptab,
3489 val = int_gptab.gt_entry.gt_g_value;
3490 add = int_gptab.gt_entry.gt_bytes - last;
3493 for (look = 1; look < c; look++)
3495 if (tab[look].gt_entry.gt_g_value >= val)
3496 tab[look].gt_entry.gt_bytes += add;
3498 if (tab[look].gt_entry.gt_g_value == val)
3504 Elf64_gptab *new_tab;
3507 /* We need a new table entry. */
3508 new_tab = ((Elf64_gptab *)
3509 bfd_realloc ((PTR) tab,
3510 (c + 1) * sizeof (Elf64_gptab)));
3511 if (new_tab == NULL)
3517 tab[c].gt_entry.gt_g_value = val;
3518 tab[c].gt_entry.gt_bytes = add;
3520 /* Merge in the size for the next smallest -G
3521 value, since that will be implied by this new
3524 for (look = 1; look < c; look++)
3526 if (tab[look].gt_entry.gt_g_value < val
3528 || (tab[look].gt_entry.gt_g_value
3529 > tab[max].gt_entry.gt_g_value)))
3533 tab[c].gt_entry.gt_bytes +=
3534 tab[max].gt_entry.gt_bytes;
3539 last = int_gptab.gt_entry.gt_bytes;
3542 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3543 elf_link_input_bfd ignores this section. */
3544 input_section->flags &=~ SEC_HAS_CONTENTS;
3547 /* The table must be sorted by -G value. */
3549 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
3551 /* Swap out the table. */
3552 ext_tab = ((Elf64_External_gptab *)
3553 bfd_alloc (abfd, c * sizeof (Elf64_External_gptab)));
3554 if (ext_tab == NULL)
3560 for (i = 0; i < c; i++)
3561 bfd_alpha_elf64_swap_gptab_out (abfd, tab + i, ext_tab + i);
3564 o->_raw_size = c * sizeof (Elf64_External_gptab);
3565 o->contents = (bfd_byte *) ext_tab;
3567 /* Skip this section later on (I don't think this currently
3568 matters, but someday it might). */
3569 o->link_order_head = (struct bfd_link_order *) NULL;
3575 /* Invoke the regular ELF backend linker to do all the work. */
3576 if (! bfd_elf64_bfd_final_link (abfd, info))
3579 /* Now write out the computed sections. */
3581 /* The .got subsections... */
3583 bfd *i, *dynobj = elf_hash_table(info)->dynobj;
3584 for (i = alpha_elf_hash_table(info)->got_list;
3586 i = alpha_elf_tdata(i)->got_link_next)
3590 /* elf_bfd_final_link already did everything in dynobj. */
3594 sgot = alpha_elf_tdata(i)->got;
3595 if (! bfd_set_section_contents (abfd, sgot->output_section,
3596 sgot->contents, sgot->output_offset,
3602 #ifdef ERIC_neverdef
3603 if (reginfo_sec != (asection *) NULL)
3605 Elf64_External_RegInfo ext;
3607 bfd_alpha_elf64_swap_reginfo_out (abfd, ®info, &ext);
3608 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
3609 (file_ptr) 0, sizeof ext))
3614 if (mdebug_sec != (asection *) NULL)
3616 BFD_ASSERT (abfd->output_has_begun);
3617 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
3619 mdebug_sec->filepos))
3622 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
3625 if (gptab_data_sec != (asection *) NULL)
3627 if (! bfd_set_section_contents (abfd, gptab_data_sec,
3628 gptab_data_sec->contents,
3630 gptab_data_sec->_raw_size))
3634 if (gptab_bss_sec != (asection *) NULL)
3636 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
3637 gptab_bss_sec->contents,
3639 gptab_bss_sec->_raw_size))
3646 /* ECOFF swapping routines. These are used when dealing with the
3647 .mdebug section, which is in the ECOFF debugging format. Copied
3648 from elf32-mips.c. */
3649 static const struct ecoff_debug_swap
3650 elf64_alpha_ecoff_debug_swap =
3652 /* Symbol table magic number. */
3654 /* Alignment of debugging information. E.g., 4. */
3656 /* Sizes of external symbolic information. */
3657 sizeof (struct hdr_ext),
3658 sizeof (struct dnr_ext),
3659 sizeof (struct pdr_ext),
3660 sizeof (struct sym_ext),
3661 sizeof (struct opt_ext),
3662 sizeof (struct fdr_ext),
3663 sizeof (struct rfd_ext),
3664 sizeof (struct ext_ext),
3665 /* Functions to swap in external symbolic data. */
3674 _bfd_ecoff_swap_tir_in,
3675 _bfd_ecoff_swap_rndx_in,
3676 /* Functions to swap out external symbolic data. */
3685 _bfd_ecoff_swap_tir_out,
3686 _bfd_ecoff_swap_rndx_out,
3687 /* Function to read in symbolic data. */
3688 elf64_alpha_read_ecoff_info
3691 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
3692 #define TARGET_LITTLE_NAME "elf64-alpha"
3693 #define ELF_ARCH bfd_arch_alpha
3694 #define ELF_MACHINE_CODE EM_ALPHA
3695 #define ELF_MAXPAGESIZE 0x100000
3697 #define bfd_elf64_bfd_link_hash_table_create \
3698 elf64_alpha_bfd_link_hash_table_create
3700 #define bfd_elf64_bfd_reloc_type_lookup \
3701 elf64_alpha_bfd_reloc_type_lookup
3702 #define elf_info_to_howto \
3703 elf64_alpha_info_to_howto
3705 #define bfd_elf64_mkobject \
3706 elf64_alpha_mkobject
3708 #define elf_backend_object_p \
3709 elf64_alpha_object_p
3710 #define elf_backend_section_from_shdr \
3711 elf64_alpha_section_from_shdr
3712 #define elf_backend_fake_sections \
3713 elf64_alpha_fake_sections
3714 #define elf_backend_additional_program_headers \
3715 elf64_alpha_additional_program_headers
3717 #define bfd_elf64_bfd_is_local_label \
3718 elf64_alpha_is_local_label
3719 #define bfd_elf64_find_nearest_line \
3720 elf64_alpha_find_nearest_line
3722 #define elf_backend_check_relocs \
3723 elf64_alpha_check_relocs
3724 #define elf_backend_create_dynamic_sections \
3725 elf64_alpha_create_dynamic_sections
3726 #define elf_backend_adjust_dynamic_symbol \
3727 elf64_alpha_adjust_dynamic_symbol
3728 #define elf_backend_always_size_sections \
3729 elf64_alpha_always_size_sections
3730 #define elf_backend_size_dynamic_sections \
3731 elf64_alpha_size_dynamic_sections
3732 #define elf_backend_relocate_section \
3733 elf64_alpha_relocate_section
3734 #define elf_backend_finish_dynamic_symbol \
3735 elf64_alpha_finish_dynamic_symbol
3736 #define elf_backend_finish_dynamic_sections \
3737 elf64_alpha_finish_dynamic_sections
3738 #define bfd_elf64_bfd_final_link \
3739 elf64_alpha_final_link
3741 #define elf_backend_ecoff_debug_swap \
3742 &elf64_alpha_ecoff_debug_swap
3745 * A few constants that determine how the .plt section is set up.
3747 #define elf_backend_want_got_plt 0
3748 #define elf_backend_plt_readonly 0
3749 #define elf_backend_want_plt_sym 1
3751 #include "elf64-target.h"