1 /* ALPHA-specific support for 64-bit ELF
2 Copyright 1996 Free Software Foundation, Inc.
3 Contributed by Richard Henderson <rth@tamu.edu>.
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_do_reloc_gpdisp
57 PARAMS((bfd *, bfd_vma, bfd_byte *, bfd_byte *));
58 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
59 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
60 static bfd_reloc_status_type elf64_alpha_reloc_op_push
61 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
62 static bfd_reloc_status_type elf64_alpha_reloc_op_store
63 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
64 static bfd_reloc_status_type elf64_alpha_reloc_op_psub
65 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
66 static bfd_reloc_status_type elf64_alpha_reloc_op_prshift
67 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
69 static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup
70 PARAMS((bfd *, bfd_reloc_code_real_type));
71 static void elf64_alpha_info_to_howto
72 PARAMS((bfd *, arelent *, Elf64_Internal_Rela *));
74 static boolean elf64_alpha_object_p
76 static boolean elf64_alpha_section_from_shdr
77 PARAMS((bfd *, Elf64_Internal_Shdr *, char *));
78 static boolean elf64_alpha_fake_sections
79 PARAMS((bfd *, Elf64_Internal_Shdr *, asection *));
80 static int elf64_alpha_additional_program_headers
82 static boolean elf64_alpha_create_got_section
83 PARAMS((bfd *, struct bfd_link_info *));
84 static boolean elf64_alpha_create_dynamic_sections
85 PARAMS((bfd *, struct bfd_link_info *));
87 static boolean elf64_alpha_read_ecoff_info
88 PARAMS((bfd *, asection *, struct ecoff_debug_info *));
89 static boolean elf64_alpha_is_local_label
90 PARAMS((bfd *, asymbol *));
91 static boolean elf64_alpha_find_nearest_line
92 PARAMS((bfd *, asection *, asymbol **, bfd_vma, const char **,
93 const char **, unsigned int *));
95 struct alpha_elf_link_hash_entry;
96 static boolean elf64_alpha_output_extsym
97 PARAMS((struct alpha_elf_link_hash_entry *, PTR));
99 static boolean elf64_alpha_check_relocs
100 PARAMS((bfd *, struct bfd_link_info *, asection *sec,
101 const Elf_Internal_Rela *));
102 static boolean elf64_alpha_adjust_dynamic_symbol
103 PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *));
104 static boolean elf64_alpha_size_dynamic_sections
105 PARAMS((bfd *, struct bfd_link_info *));
106 static boolean elf64_alpha_adjust_dynindx
107 PARAMS((struct elf_link_hash_entry *, PTR));
108 static boolean elf64_alpha_relocate_section
109 PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
110 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
111 static boolean elf64_alpha_finish_dynamic_symbol
112 PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
113 Elf_Internal_Sym *));
114 static boolean elf64_alpha_finish_dynamic_sections
115 PARAMS((bfd *, struct bfd_link_info *));
116 static boolean elf64_alpha_final_link
117 PARAMS((bfd *, struct bfd_link_info *));
120 #define alpha_elf_tdata(bfd) \
121 ((struct alpha_elf_obj_tdata *)elf_tdata(bfd)->tdata)
123 struct alpha_elf_link_hash_entry
125 struct elf_link_hash_entry root;
127 /* External symbol information. */
131 /* Alpha ELF linker hash table. */
133 struct alpha_elf_link_hash_table
135 struct elf_link_hash_table root;
138 /* Look up an entry in a Alpha ELF linker hash table. */
140 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
141 ((struct alpha_elf_link_hash_entry *) \
142 elf_link_hash_lookup (&(table)->root, (string), (create), \
145 /* Traverse a Alpha ELF linker hash table. */
147 #define alpha_elf_link_hash_traverse(table, func, info) \
148 (elf_link_hash_traverse \
150 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
153 /* Get the Alpha ELF linker hash table from a link_info structure. */
155 #define alpha_elf_hash_table(p) \
156 ((struct alpha_elf_link_hash_table *) ((p)->hash))
158 /* Create an entry in a Alpha ELF linker hash table. */
160 static struct bfd_hash_entry *
161 elf64_alpha_link_hash_newfunc (entry, table, string)
162 struct bfd_hash_entry *entry;
163 struct bfd_hash_table *table;
166 struct alpha_elf_link_hash_entry *ret =
167 (struct alpha_elf_link_hash_entry *) entry;
169 /* Allocate the structure if it has not already been allocated by a
171 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
172 ret = ((struct alpha_elf_link_hash_entry *)
173 bfd_hash_allocate (table,
174 sizeof (struct alpha_elf_link_hash_entry)));
175 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
176 return (struct bfd_hash_entry *) ret;
178 /* Call the allocation method of the superclass. */
179 ret = ((struct alpha_elf_link_hash_entry *)
180 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
182 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
184 /* Set local fields. */
185 memset (&ret->esym, 0, sizeof (EXTR));
186 /* We use -2 as a marker to indicate that the information has
187 not been set. -1 means there is no associated ifd. */
191 return (struct bfd_hash_entry *) ret;
194 /* Create a Alpha ELF linker hash table. */
196 static struct bfd_link_hash_table *
197 elf64_alpha_bfd_link_hash_table_create (abfd)
200 struct alpha_elf_link_hash_table *ret;
202 ret = ((struct alpha_elf_link_hash_table *)
203 bfd_zalloc (abfd, sizeof (struct alpha_elf_link_hash_table)));
204 if (ret == (struct alpha_elf_link_hash_table *) NULL)
207 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
208 elf64_alpha_link_hash_newfunc))
210 bfd_release (abfd, ret);
214 return &ret->root.root;
218 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
219 from smaller values. Start with zero, widen, *then* decrement. */
220 #define MINUS_ONE (((bfd_vma)0) - 1)
222 static reloc_howto_type elf64_alpha_howto_table[] =
224 HOWTO (R_ALPHA_NONE, /* type */
226 0, /* size (0 = byte, 1 = short, 2 = long) */
228 true, /* pc_relative */
230 complain_overflow_dont, /* complain_on_overflow */
231 elf64_alpha_reloc_nil, /* special_function */
233 false, /* partial_inplace */
236 true), /* pcrel_offset */
238 /* A 32 bit reference to a symbol. */
239 HOWTO (R_ALPHA_REFLONG, /* type */
241 2, /* size (0 = byte, 1 = short, 2 = long) */
243 false, /* pc_relative */
245 complain_overflow_bitfield, /* complain_on_overflow */
246 0, /* special_function */
247 "REFLONG", /* name */
248 false, /* partial_inplace */
249 0xffffffff, /* src_mask */
250 0xffffffff, /* dst_mask */
251 false), /* pcrel_offset */
253 /* A 64 bit reference to a symbol. */
254 HOWTO (R_ALPHA_REFQUAD, /* type */
256 4, /* size (0 = byte, 1 = short, 2 = long) */
258 false, /* pc_relative */
260 complain_overflow_bitfield, /* complain_on_overflow */
261 0, /* special_function */
262 "REFQUAD", /* name */
263 false, /* partial_inplace */
264 MINUS_ONE, /* src_mask */
265 MINUS_ONE, /* dst_mask */
266 false), /* pcrel_offset */
268 /* A 32 bit GP relative offset. This is just like REFLONG except
269 that when the value is used the value of the gp register will be
271 HOWTO (R_ALPHA_GPREL32, /* type */
273 2, /* size (0 = byte, 1 = short, 2 = long) */
275 false, /* pc_relative */
277 complain_overflow_bitfield, /* complain_on_overflow */
278 0, /* special_function */
279 "GPREL32", /* name */
280 false, /* partial_inplace */
281 0xffffffff, /* src_mask */
282 0xffffffff, /* dst_mask */
283 false), /* pcrel_offset */
285 /* Used for an instruction that refers to memory off the GP register. */
286 HOWTO (R_ALPHA_LITERAL, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 false, /* pc_relative */
292 complain_overflow_signed, /* complain_on_overflow */
293 0, /* special_function */
294 "LITERAL", /* name */
295 false, /* partial_inplace */
296 0xffff, /* src_mask */
297 0xffff, /* dst_mask */
298 false), /* pcrel_offset */
300 /* This reloc only appears immediately following a LITERAL reloc.
301 It identifies a use of the literal. The symbol index is special:
302 1 means the literal address is in the base register of a memory
303 format instruction; 2 means the literal address is in the byte
304 offset register of a byte-manipulation instruction; 3 means the
305 literal address is in the target register of a jsr instruction.
306 This does not actually do any relocation. */
307 HOWTO (R_ALPHA_LITUSE, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 false, /* pc_relative */
313 complain_overflow_dont, /* complain_on_overflow */
314 elf64_alpha_reloc_nil, /* special_function */
316 false, /* partial_inplace */
319 false), /* pcrel_offset */
321 /* Load the gp register. This is always used for a ldah instruction
322 which loads the upper 16 bits of the gp register. The symbol
323 index of the GPDISP instruction is an offset in bytes to the lda
324 instruction that loads the lower 16 bits. The value to use for
325 the relocation is the difference between the GP value and the
326 current location; the load will always be done against a register
327 holding the current address.
329 NOTE: Unlike ECOFF, partial inplace relocation is not done. If
330 any offset is present in the instructions, it is an offset from
331 the register to the ldah instruction. This lets us avoid any
332 stupid hackery like inventing a gp value to do partial relocation
333 against. Also unlike ECOFF, we do the whole relocation off of
334 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
335 space consuming bit, that, since all the information was present
336 in the GPDISP_HI16 reloc. */
337 HOWTO (R_ALPHA_GPDISP, /* type */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
341 false, /* pc_relative */
343 complain_overflow_dont, /* complain_on_overflow */
344 elf64_alpha_reloc_gpdisp, /* special_function */
346 false, /* partial_inplace */
347 0xffff, /* src_mask */
348 0xffff, /* dst_mask */
349 true), /* pcrel_offset */
351 /* A 21 bit branch. */
352 HOWTO (R_ALPHA_BRADDR, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 true, /* pc_relative */
358 complain_overflow_signed, /* complain_on_overflow */
359 0, /* special_function */
361 false, /* partial_inplace */
362 0x1fffff, /* src_mask */
363 0x1fffff, /* dst_mask */
364 true), /* pcrel_offset */
366 /* A hint for a jump to a register. */
367 HOWTO (R_ALPHA_HINT, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 true, /* pc_relative */
373 complain_overflow_dont, /* complain_on_overflow */
374 0, /* special_function */
376 false, /* partial_inplace */
377 0x3fff, /* src_mask */
378 0x3fff, /* dst_mask */
379 true), /* pcrel_offset */
381 /* 16 bit PC relative offset. */
382 HOWTO (R_ALPHA_SREL16, /* type */
384 1, /* size (0 = byte, 1 = short, 2 = long) */
386 true, /* pc_relative */
388 complain_overflow_signed, /* complain_on_overflow */
389 0, /* special_function */
391 false, /* partial_inplace */
392 0xffff, /* src_mask */
393 0xffff, /* dst_mask */
394 false), /* pcrel_offset */
396 /* 32 bit PC relative offset. */
397 HOWTO (R_ALPHA_SREL32, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 true, /* pc_relative */
403 complain_overflow_signed, /* complain_on_overflow */
404 0, /* special_function */
406 false, /* partial_inplace */
407 0xffffffff, /* src_mask */
408 0xffffffff, /* dst_mask */
409 false), /* pcrel_offset */
411 /* A 64 bit PC relative offset. */
412 HOWTO (R_ALPHA_SREL64, /* type */
414 4, /* size (0 = byte, 1 = short, 2 = long) */
416 true, /* pc_relative */
418 complain_overflow_signed, /* complain_on_overflow */
419 0, /* special_function */
421 false, /* partial_inplace */
422 MINUS_ONE, /* src_mask */
423 MINUS_ONE, /* dst_mask */
424 false), /* pcrel_offset */
426 /* Push a value on the reloc evaluation stack. */
427 HOWTO (ALPHA_R_OP_PUSH, /* type */
429 0, /* size (0 = byte, 1 = short, 2 = long) */
431 false, /* pc_relative */
433 complain_overflow_dont, /* complain_on_overflow */
434 elf64_alpha_reloc_op_push, /* special_function */
435 "OP_PUSH", /* name */
436 false, /* partial_inplace */
439 false), /* pcrel_offset */
441 /* Store the value from the stack at the given address. Store it in
442 a bitfield of size r_size starting at bit position r_offset. */
443 HOWTO (ALPHA_R_OP_STORE, /* type */
445 4, /* size (0 = byte, 1 = short, 2 = long) */
447 false, /* pc_relative */
449 complain_overflow_dont, /* complain_on_overflow */
450 elf64_alpha_reloc_op_store, /* special_function */
451 "OP_STORE", /* name */
452 false, /* partial_inplace */
454 MINUS_ONE, /* dst_mask */
455 false), /* pcrel_offset */
457 /* Subtract the reloc address from the value on the top of the
459 HOWTO (ALPHA_R_OP_PSUB, /* type */
461 0, /* size (0 = byte, 1 = short, 2 = long) */
463 false, /* pc_relative */
465 complain_overflow_dont, /* complain_on_overflow */
466 elf64_alpha_reloc_op_psub, /* special_function */
467 "OP_PSUB", /* name */
468 false, /* partial_inplace */
471 false), /* pcrel_offset */
473 /* Shift the value on the top of the relocation stack right by the
475 HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
477 0, /* size (0 = byte, 1 = short, 2 = long) */
479 false, /* pc_relative */
481 complain_overflow_dont, /* complain_on_overflow */
482 elf64_alpha_reloc_op_prshift, /* special_function */
483 "OP_PRSHIFT", /* name */
484 false, /* partial_inplace */
487 false), /* pcrel_offset */
489 /* Misc ELF relocations. */
496 complain_overflow_dont,
497 bfd_elf_generic_reloc,
504 HOWTO (R_ALPHA_GLOB_DAT,
510 complain_overflow_dont,
511 bfd_elf_generic_reloc,
518 HOWTO (R_ALPHA_JMP_SLOT,
524 complain_overflow_dont,
525 bfd_elf_generic_reloc,
532 HOWTO (R_ALPHA_RELATIVE,
538 complain_overflow_dont,
539 bfd_elf_generic_reloc,
547 static bfd_reloc_status_type
548 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
555 char **error_message;
558 reloc->address += sec->output_offset;
562 static bfd_reloc_status_type
563 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
566 bfd_byte *p_ldah, *p_lda;
568 bfd_reloc_status_type ret = bfd_reloc_ok;
570 unsigned long i_ldah, i_lda;
572 i_ldah = bfd_get_32(abfd, p_ldah);
573 i_lda = bfd_get_32(abfd, p_lda);
575 /* Complain if the instructions are not correct. */
576 if (((i_ldah >> 26) & 0x3f) != 0x09
577 || ((i_lda >> 26) & 0x3f) != 0x08)
578 ret = bfd_reloc_dangerous;
580 /* Extract the user-supplied offset, mirroring the sign extensions
581 that the instructions perform. */
582 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
583 addend = (addend ^ 0x80008000) - 0x80008000;
587 if ((bfd_signed_vma)gpdisp < -(bfd_signed_vma)0x80000000
588 || gpdisp >= 0x7fff8000)
589 ret = bfd_reloc_overflow;
591 /* compensate for the sign extension again. */
592 i_ldah = ((i_ldah & 0xffff0000)
593 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
594 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
596 bfd_put_32 (abfd, i_ldah, p_ldah);
597 bfd_put_32 (abfd, i_lda, p_lda);
602 static bfd_reloc_status_type
603 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
606 arelent *reloc_entry;
609 asection *input_section;
613 bfd_reloc_status_type ret;
614 bfd_vma gp, relocation;
615 bfd_byte *p_ldah, *p_lda;
617 /* Don't do anything if we're not doing a final link. */
620 reloc_entry->address += input_section->output_offset;
624 if (reloc_entry->address > input_section->_cooked_size ||
625 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
626 return bfd_reloc_outofrange;
628 /* The gp used in the portion of the output object to which this
629 input object belongs is cached on the input bfd. */
630 gp = _bfd_get_gp_value (abfd);
632 relocation = (input_section->output_section->vma
633 + input_section->output_offset
634 + reloc_entry->address);
636 p_ldah = (bfd_byte *)data + reloc_entry->address;
637 p_lda = p_ldah + reloc_entry->addend;
639 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
641 /* Complain if the instructions are not correct. */
642 if (ret == bfd_reloc_dangerous)
644 *err_msg = "GPDISP relocation did not find ldah and lda instructions";
650 /* Due to the nature of the stack operations, I don't think more
651 that one entry is useful. Test this theory by setting the
652 stack size to a minimum. */
653 /* FIXME: BFD should not use static variables. */
654 #define OP_STACK_SIZE 1
655 static bfd_vma elf64_alpha_op_stack[OP_STACK_SIZE];
656 static int elf64_alpha_op_tos;
658 static bfd_reloc_status_type
659 elf64_alpha_reloc_op_push (abfd, reloc_entry, sym, data, input_section,
662 arelent *reloc_entry;
665 asection *input_section;
669 bfd_reloc_status_type r = bfd_reloc_ok;
672 /* Don't do anything if we're not doing a final link. */
675 reloc_entry->address += input_section->output_offset;
679 if (elf64_alpha_op_tos >= OP_STACK_SIZE)
681 *err_msg = "operation stack overflow";
682 return bfd_reloc_dangerous;
685 /* Get the symbol value. */
686 /* FIXME: We should fail if this is a dynamic symbol. Check on that. */
687 if (bfd_is_und_section (sym->section))
688 r = bfd_reloc_undefined;
689 if (bfd_is_com_section (sym->section))
693 value += sym->section->output_section->vma;
694 value += sym->section->output_offset;
695 value += reloc_entry->addend;
697 elf64_alpha_op_stack[elf64_alpha_op_tos++] = value;
702 static bfd_reloc_status_type
703 elf64_alpha_reloc_op_store (abfd, reloc_entry, sym, data, input_section,
706 arelent *reloc_entry;
709 asection *input_section;
716 /* Don't do anything before the final link. */
719 reloc_entry->address += input_section->output_offset;
723 if (elf64_alpha_op_tos <= 0)
725 *err_msg = "operation stack underflow";
726 return bfd_reloc_dangerous;
729 /* The offset and size for this reloc are encoded into the addend
730 field by alpha_adjust_reloc_in. */
731 offset = (reloc_entry->addend >> 8) & 0xff;
732 size = reloc_entry->addend & 0xff;
734 value = bfd_get_64 (abfd, data + reloc_entry->address);
735 value &= ~((((bfd_vma)1 << size) - 1) << offset);
736 value |= (elf64_alpha_op_stack[--elf64_alpha_op_tos]
737 & (((bfd_vma)1 << size) - 1)) << offset;
738 bfd_put_64 (abfd, value, data + reloc_entry->address);
743 static bfd_reloc_status_type
744 elf64_alpha_reloc_op_psub (abfd, reloc_entry, sym, data, input_section,
747 arelent *reloc_entry;
750 asection *input_section;
754 bfd_reloc_status_type r;
757 /* Don't do anything before the final link. */
760 reloc_entry->address += input_section->output_offset;
764 if (elf64_alpha_op_tos <= 0)
766 *err_msg = "operation stack underflow";
767 return bfd_reloc_dangerous;
770 if (bfd_is_und_section (sym->section))
771 r = bfd_reloc_undefined;
772 if (bfd_is_com_section (sym->section))
776 value += sym->section->output_section->vma;
777 value += sym->section->output_offset;
778 value += reloc_entry->addend;
780 elf64_alpha_op_stack[elf64_alpha_op_tos-1] -= value;
785 static bfd_reloc_status_type
786 elf64_alpha_reloc_op_prshift (abfd, reloc_entry, sym, data, input_section,
789 arelent *reloc_entry;
792 asection *input_section;
796 /* Don't do anything before the final link. */
799 reloc_entry->address += input_section->output_offset;
803 if (elf64_alpha_op_tos <= 0)
805 *err_msg = "operation stack underflow";
806 return bfd_reloc_dangerous;
809 elf64_alpha_op_stack[elf64_alpha_op_tos-1] >>= reloc_entry->addend;
814 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
818 bfd_reloc_code_real_type bfd_reloc_val;
822 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
824 {BFD_RELOC_NONE, R_ALPHA_NONE},
825 {BFD_RELOC_32, R_ALPHA_REFLONG},
826 {BFD_RELOC_64, R_ALPHA_REFQUAD},
827 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
828 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
829 {BFD_RELOC_ALPHA_LITERAL, R_ALPHA_LITERAL},
830 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
831 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
832 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
833 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
834 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
835 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
836 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
838 {BFD_RELOC_ALPHA_OP_PUSH, R_ALPHA_OP_PUSH},
839 {BFD_RELOC_ALPHA_OP_STORE, R_ALPHA_OP_STORE},
840 {BFD_RELOC_ALPHA_OP_PSUB, R_ALPHA_OP_PSUB},
841 {BFD_RELOC_ALPHA_OP_PRSHIFT, R_ALPHA_OP_PRSHIFT}
845 /* Given a BFD reloc type, return a HOWTO structure. */
847 static reloc_howto_type *
848 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
850 bfd_reloc_code_real_type code;
852 const struct elf_reloc_map *i, *e;
853 i = e = elf64_alpha_reloc_map;
854 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
857 if (i->bfd_reloc_val == code)
858 return &elf64_alpha_howto_table[i->elf_reloc_val];
863 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
866 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
869 Elf64_Internal_Rela *dst;
873 r_type = ELF64_R_TYPE(dst->r_info);
874 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
875 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
879 #define PLT_HEADER_SIZE 32
880 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
881 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
882 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
883 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
885 #define PLT_ENTRY_SIZE 12
886 #define PLT_ENTRY_WORD1 0x279f0000 /* ldah $28, 0($31) */
887 #define PLT_ENTRY_WORD2 0x239c0000 /* lda $28, 0($28) */
888 #define PLT_ENTRY_WORD3 0xc3e00000 /* br $31, plt0 */
890 #define RESERVED_GOT_ENTRIES 1
892 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
894 /* Set the right machine number for an Alpha ELF file. */
897 elf64_alpha_object_p (abfd)
900 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
903 /* Handle a alpha specific section when reading an object file. This
904 is called when elfcode.h finds a section with an unknown type.
905 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
909 elf64_alpha_section_from_shdr (abfd, hdr, name)
911 Elf64_Internal_Shdr *hdr;
916 /* There ought to be a place to keep ELF backend specific flags, but
917 at the moment there isn't one. We just keep track of the
918 sections by their name, instead. Fortunately, the ABI gives
919 suggested names for all the MIPS specific sections, so we will
920 probably get away with this. */
921 switch (hdr->sh_type)
923 case SHT_ALPHA_DEBUG:
924 if (strcmp (name, ".mdebug") != 0)
928 case SHT_ALPHA_REGINFO:
929 if (strcmp (name, ".reginfo") != 0
930 || hdr->sh_size != sizeof (Elf64_External_RegInfo))
938 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
940 newsect = hdr->bfd_section;
942 if (hdr->sh_type == SHT_ALPHA_DEBUG)
944 if (! bfd_set_section_flags (abfd, newsect,
945 (bfd_get_section_flags (abfd, newsect)
951 /* For a .reginfo section, set the gp value in the tdata information
952 from the contents of this section. We need the gp value while
953 processing relocs, so we just get it now. */
954 if (hdr->sh_type == SHT_ALPHA_REGINFO)
956 Elf64_External_RegInfo ext;
959 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
960 (file_ptr) 0, sizeof ext))
962 bfd_alpha_elf64_swap_reginfo_in (abfd, &ext, &s);
963 elf_gp (abfd) = s.ri_gp_value;
970 /* Set the correct type for an Alpha ELF section. We do this by the
971 section name, which is a hack, but ought to work. */
974 elf64_alpha_fake_sections (abfd, hdr, sec)
976 Elf64_Internal_Shdr *hdr;
979 register const char *name;
981 name = bfd_get_section_name (abfd, sec);
983 if (strcmp (name, ".mdebug") == 0)
985 hdr->sh_type = SHT_ALPHA_DEBUG;
986 /* In a shared object on Irix 5.3, the .mdebug section has an
987 entsize of 0. FIXME: Does this matter? */
988 if ((abfd->flags & DYNAMIC) != 0 )
994 else if (strcmp (name, ".reginfo") == 0)
996 hdr->sh_type = SHT_ALPHA_REGINFO;
997 /* In a shared object on Irix 5.3, the .reginfo section has an
998 entsize of 0x18. FIXME: Does this matter? */
999 if ((abfd->flags & DYNAMIC) != 0)
1000 hdr->sh_entsize = sizeof (Elf64_External_RegInfo);
1002 hdr->sh_entsize = 1;
1004 /* Force the section size to the correct value, even if the
1005 linker thinks it is larger. The link routine below will only
1006 write out this much data for .reginfo. */
1007 hdr->sh_size = sec->_raw_size = sizeof (Elf64_External_RegInfo);
1009 else if (strcmp (name, ".hash") == 0
1010 || strcmp (name, ".dynamic") == 0
1011 || strcmp (name, ".dynstr") == 0)
1013 hdr->sh_entsize = 0;
1014 hdr->sh_info = SIZEOF_ALPHA_DYNSYM_SECNAMES;
1016 else if (strcmp (name, ".sdata") == 0
1017 || strcmp (name, ".sbss") == 0
1018 || strcmp (name, ".lit4") == 0
1019 || strcmp (name, ".lit8") == 0)
1020 hdr->sh_flags |= SHF_ALPHA_GPREL;
1027 elf64_alpha_additional_program_headers (abfd)
1035 s = bfd_get_section_by_name (abfd, ".reginfo");
1036 if (s != NULL && (s->flags & SEC_LOAD) != 0)
1038 /* We need a PT_ALPHA_REGINFO segment. */
1042 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL
1043 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
1045 /* We need a PT_ALPHA_RTPROC segment. */
1053 elf64_alpha_create_got_section(abfd, info)
1055 struct bfd_link_info *info;
1058 struct elf_link_hash_entry *h;
1060 if (bfd_get_section_by_name (abfd, ".got"))
1063 s = bfd_make_section(abfd, ".rela.got");
1065 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1066 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1068 || !bfd_set_section_alignment (abfd, s, 3))
1071 s = bfd_make_section(abfd, ".got");
1073 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1074 | SEC_HAS_CONTENTS | SEC_IN_MEMORY))
1075 || !bfd_set_section_alignment (abfd, s, 3))
1078 s->_raw_size = RESERVED_GOT_ENTRIES * 8;
1080 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
1081 (or .got.plt) section. We don't do this in the linker script
1082 because we don't want to define the symbol if we are not creating
1083 a global offset table. */
1085 if (!(_bfd_generic_link_add_one_symbol
1086 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, (bfd_vma) 0,
1087 (const char *) NULL, false, get_elf_backend_data (abfd)->collect,
1088 (struct bfd_link_hash_entry **) &h)))
1090 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1091 h->type = STT_OBJECT;
1094 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1097 elf_hash_table (info)->hgot = h;
1103 elf64_alpha_create_dynamic_sections (abfd, info)
1105 struct bfd_link_info *info;
1107 register asection *s;
1108 struct elf_link_hash_entry *h;
1110 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1112 s = bfd_make_section (abfd, ".plt");
1114 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1115 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1117 || ! bfd_set_section_alignment (abfd, s, 3))
1120 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1123 if (! (_bfd_generic_link_add_one_symbol
1124 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1125 (bfd_vma) 0, (const char *) NULL, false,
1126 get_elf_backend_data (abfd)->collect,
1127 (struct bfd_link_hash_entry **) &h)))
1129 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1130 h->type = STT_OBJECT;
1133 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1136 s = bfd_make_section (abfd, ".rela.plt");
1138 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1139 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1141 || ! bfd_set_section_alignment (abfd, s, 3))
1144 if (!elf64_alpha_create_got_section (abfd, info))
1150 /* The structure of the runtile procedure descriptor created by the
1151 loader for use by the static exception system. */
1155 /* Read ECOFF debugging information from a .mdebug section into a
1156 ecoff_debug_info structure. */
1159 elf64_alpha_read_ecoff_info (abfd, section, debug)
1162 struct ecoff_debug_info *debug;
1165 const struct ecoff_debug_swap *swap;
1166 char *ext_hdr = NULL;
1168 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1170 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
1171 if (ext_hdr == NULL && swap->external_hdr_size != 0)
1174 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
1175 swap->external_hdr_size)
1179 symhdr = &debug->symbolic_header;
1180 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
1182 /* The symbolic header contains absolute file offsets and sizes to
1184 #define READ(ptr, offset, count, size, type) \
1185 if (symhdr->count == 0) \
1186 debug->ptr = NULL; \
1189 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1190 if (debug->ptr == NULL) \
1191 goto error_return; \
1192 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1193 || (bfd_read (debug->ptr, size, symhdr->count, \
1194 abfd) != size * symhdr->count)) \
1195 goto error_return; \
1198 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
1199 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
1200 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
1201 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
1202 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
1203 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
1205 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
1206 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
1207 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
1208 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
1209 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
1213 debug->adjust = NULL;
1218 if (ext_hdr != NULL)
1220 if (debug->line != NULL)
1222 if (debug->external_dnr != NULL)
1223 free (debug->external_dnr);
1224 if (debug->external_pdr != NULL)
1225 free (debug->external_pdr);
1226 if (debug->external_sym != NULL)
1227 free (debug->external_sym);
1228 if (debug->external_opt != NULL)
1229 free (debug->external_opt);
1230 if (debug->external_aux != NULL)
1231 free (debug->external_aux);
1232 if (debug->ss != NULL)
1234 if (debug->ssext != NULL)
1235 free (debug->ssext);
1236 if (debug->external_fdr != NULL)
1237 free (debug->external_fdr);
1238 if (debug->external_rfd != NULL)
1239 free (debug->external_rfd);
1240 if (debug->external_ext != NULL)
1241 free (debug->external_ext);
1245 /* Alpha ELF local labels start with '$'. */
1248 elf64_alpha_is_local_label (abfd, symbol)
1252 return symbol->name[0] == '$';
1255 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1256 routine in order to handle the ECOFF debugging information. We
1257 still call this mips_elf_find_line because of the slot
1258 find_line_info in elf_obj_tdata is declared that way. */
1260 struct mips_elf_find_line
1262 struct ecoff_debug_info d;
1263 struct ecoff_find_line i;
1267 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
1268 functionname_ptr, line_ptr)
1273 const char **filename_ptr;
1274 const char **functionname_ptr;
1275 unsigned int *line_ptr;
1279 msec = bfd_get_section_by_name (abfd, ".mdebug");
1283 struct mips_elf_find_line *fi;
1284 const struct ecoff_debug_swap * const swap =
1285 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1287 /* If we are called during a link, alpha_elf_final_link may have
1288 cleared the SEC_HAS_CONTENTS field. We force it back on here
1289 if appropriate (which it normally will be). */
1290 origflags = msec->flags;
1291 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
1292 msec->flags |= SEC_HAS_CONTENTS;
1294 fi = elf_tdata (abfd)->find_line_info;
1297 bfd_size_type external_fdr_size;
1300 struct fdr *fdr_ptr;
1302 fi = ((struct mips_elf_find_line *)
1303 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
1306 msec->flags = origflags;
1310 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
1312 msec->flags = origflags;
1316 /* Swap in the FDR information. */
1317 fi->d.fdr = ((struct fdr *)
1319 (fi->d.symbolic_header.ifdMax *
1320 sizeof (struct fdr))));
1321 if (fi->d.fdr == NULL)
1323 msec->flags = origflags;
1326 external_fdr_size = swap->external_fdr_size;
1327 fdr_ptr = fi->d.fdr;
1328 fraw_src = (char *) fi->d.external_fdr;
1329 fraw_end = (fraw_src
1330 + fi->d.symbolic_header.ifdMax * external_fdr_size);
1331 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
1332 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
1334 elf_tdata (abfd)->find_line_info = fi;
1336 /* Note that we don't bother to ever free this information.
1337 find_nearest_line is either called all the time, as in
1338 objdump -l, so the information should be saved, or it is
1339 rarely called, as in ld error messages, so the memory
1340 wasted is unimportant. Still, it would probably be a
1341 good idea for free_cached_info to throw it away. */
1344 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
1345 &fi->i, filename_ptr, functionname_ptr,
1348 msec->flags = origflags;
1352 msec->flags = origflags;
1355 /* Fall back on the generic ELF find_nearest_line routine. */
1357 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
1358 filename_ptr, functionname_ptr,
1362 /* Structure used to pass information to alpha_elf_output_extsym. */
1367 struct bfd_link_info *info;
1368 struct ecoff_debug_info *debug;
1369 const struct ecoff_debug_swap *swap;
1374 elf64_alpha_output_extsym (h, data)
1375 struct alpha_elf_link_hash_entry *h;
1378 struct extsym_info *einfo = (struct extsym_info *) data;
1380 asection *sec, *output_section;
1382 if (h->root.indx == -2)
1384 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1385 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
1386 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1387 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
1389 else if (einfo->info->strip == strip_all
1390 || (einfo->info->strip == strip_some
1391 && bfd_hash_lookup (einfo->info->keep_hash,
1392 h->root.root.root.string,
1393 false, false) == NULL))
1401 if (h->esym.ifd == -2)
1404 h->esym.cobol_main = 0;
1405 h->esym.weakext = 0;
1406 h->esym.reserved = 0;
1407 h->esym.ifd = ifdNil;
1408 h->esym.asym.value = 0;
1409 h->esym.asym.st = stGlobal;
1411 if (h->root.root.type != bfd_link_hash_defined
1412 && h->root.root.type != bfd_link_hash_defweak)
1413 h->esym.asym.sc = scAbs;
1418 sec = h->root.root.u.def.section;
1419 output_section = sec->output_section;
1421 /* When making a shared library and symbol h is the one from
1422 the another shared library, OUTPUT_SECTION may be null. */
1423 if (output_section == NULL)
1424 h->esym.asym.sc = scUndefined;
1427 name = bfd_section_name (output_section->owner, output_section);
1429 if (strcmp (name, ".text") == 0)
1430 h->esym.asym.sc = scText;
1431 else if (strcmp (name, ".data") == 0)
1432 h->esym.asym.sc = scData;
1433 else if (strcmp (name, ".sdata") == 0)
1434 h->esym.asym.sc = scSData;
1435 else if (strcmp (name, ".rodata") == 0
1436 || strcmp (name, ".rdata") == 0)
1437 h->esym.asym.sc = scRData;
1438 else if (strcmp (name, ".bss") == 0)
1439 h->esym.asym.sc = scBss;
1440 else if (strcmp (name, ".sbss") == 0)
1441 h->esym.asym.sc = scSBss;
1442 else if (strcmp (name, ".init") == 0)
1443 h->esym.asym.sc = scInit;
1444 else if (strcmp (name, ".fini") == 0)
1445 h->esym.asym.sc = scFini;
1447 h->esym.asym.sc = scAbs;
1451 h->esym.asym.reserved = 0;
1452 h->esym.asym.index = indexNil;
1455 if (h->root.root.type == bfd_link_hash_common)
1456 h->esym.asym.value = h->root.root.u.c.size;
1457 else if (h->root.root.type == bfd_link_hash_defined
1458 || h->root.root.type == bfd_link_hash_defweak)
1460 if (h->esym.asym.sc == scCommon)
1461 h->esym.asym.sc = scBss;
1462 else if (h->esym.asym.sc == scSCommon)
1463 h->esym.asym.sc = scSBss;
1465 sec = h->root.root.u.def.section;
1466 output_section = sec->output_section;
1467 if (output_section != NULL)
1468 h->esym.asym.value = (h->root.root.u.def.value
1469 + sec->output_offset
1470 + output_section->vma);
1472 h->esym.asym.value = 0;
1474 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1476 /* Set type and value for a symbol with a function stub. */
1477 h->esym.asym.st = stProc;
1478 sec = h->root.root.u.def.section;
1480 h->esym.asym.value = 0;
1483 output_section = sec->output_section;
1484 if (output_section != NULL)
1485 h->esym.asym.value = (h->root.plt_offset
1486 + sec->output_offset
1487 + output_section->vma);
1489 h->esym.asym.value = 0;
1496 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
1497 h->root.root.root.string,
1500 einfo->failed = true;
1507 /* FIXME: Create a runtime procedure table from the .mdebug section.
1510 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
1513 struct bfd_link_info *info;
1515 struct ecoff_debug_info *debug;
1520 elf64_alpha_check_relocs (abfd, info, sec, relocs)
1522 struct bfd_link_info *info;
1524 const Elf_Internal_Rela *relocs;
1530 Elf_Internal_Shdr *symtab_hdr;
1531 struct elf_link_hash_entry **sym_hashes;
1532 const Elf_Internal_Rela *rel, *relend;
1534 if (info->relocateable)
1537 sgot = srelgot = sreloc = NULL;
1538 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
1539 sym_hashes = elf_sym_hashes(abfd);
1540 dynobj = elf_hash_table(info)->dynobj;
1543 sgot = bfd_get_section_by_name(dynobj, ".got");
1544 srelgot = bfd_get_section_by_name(dynobj, ".rela.got");
1547 relend = relocs + sec->reloc_count;
1548 for (rel = relocs; rel < relend; ++rel)
1550 unsigned long r_symndx;
1551 struct elf_link_hash_entry *h;
1553 r_symndx = ELF64_R_SYM(rel->r_info);
1554 if (r_symndx < symtab_hdr->sh_info)
1557 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1559 switch (ELF64_R_TYPE(rel->r_info))
1561 case R_ALPHA_LITERAL:
1562 /* If this is a load of a function symbol and we are building a
1563 shared library or calling a shared library, then we need a
1566 We can tell if it is a function either by noticing the
1567 type of the symbol, or, if the type is undefined, by
1568 noticing that we have a LITUSE(3) reloc next.
1570 Note that it is not fatal to be wrong guessing that a symbol
1571 is an object, but it is fatal to be wrong guessing that a
1572 symbol is a function.
1574 Furthermore, the .plt trampoline cannot abide by weak
1575 symbols that turn out to be undefined. */
1578 && h->root.type != bfd_link_hash_undefweak
1580 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1581 && (h->type == STT_FUNC
1582 || (h->type == STT_NOTYPE
1584 && ELF64_R_TYPE(rel[1].r_info) == R_ALPHA_LITUSE
1585 && rel[1].r_addend == 3)))
1587 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1592 elf_hash_table(info)->dynobj = dynobj = abfd;
1594 /* Create the .got section. */
1595 if (!elf64_alpha_create_got_section(dynobj, info))
1598 sgot = bfd_get_section_by_name(dynobj, ".got");
1599 srelgot = bfd_get_section_by_name(dynobj, ".rela.got");
1604 if (h->got_offset != MINUS_ONE)
1606 /* We have already allocated space in this .got. */
1610 /* Make sure this becomes a dynamic symbol. */
1611 if (h->dynindx == -1
1612 && !_bfd_elf_link_record_dynamic_symbol(info, h))
1615 /* Reserve space for a reloc even if we won't use it. */
1616 srelgot->_raw_size += sizeof(Elf64_External_Rela);
1618 /* Create the relocation in adjust_dynamic_symbol */
1620 h->got_offset = sgot->_raw_size;
1621 sgot->_raw_size += 8;
1625 bfd_vma *lgotoff = elf_local_got_offsets(abfd);
1626 if (lgotoff == NULL)
1630 size = elf_tdata(abfd)->symtab_hdr.sh_info * sizeof(bfd_vma);
1631 lgotoff = (bfd_vma *)bfd_alloc(abfd, size);
1632 if (lgotoff == NULL)
1635 elf_local_got_offsets(abfd) = lgotoff;
1636 memset(lgotoff, -1, size);
1639 if (lgotoff[ELF64_R_SYM(rel->r_info)] != MINUS_ONE)
1641 /* We have already allocated space in the .got. */
1644 lgotoff[ELF64_R_SYM(rel->r_info)] = sgot->_raw_size;
1645 sgot->_raw_size += 8;
1649 /* If we are generating a shared object, we need to
1650 output a R_ALPHA_RELATIVE reloc so that the dynamic
1651 linker can adjust this GOT entry. */
1652 srelgot->_raw_size += sizeof(Elf64_External_Rela);
1657 case R_ALPHA_SREL16:
1658 case R_ALPHA_SREL32:
1659 case R_ALPHA_SREL64:
1664 case R_ALPHA_REFLONG:
1665 case R_ALPHA_REFQUAD:
1667 || (h && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1669 /* When creating a shared object or referring to a symbol in
1670 a shared object, we must copy these relocs into the
1671 object file. We create a reloc section in dynobj and
1672 make room for the reloc. */
1676 name = (bfd_elf_string_from_elf_section
1677 (abfd, elf_elfheader(abfd)->e_shstrndx,
1678 elf_section_data(sec)->rel_hdr.sh_name));
1682 BFD_ASSERT(strncmp(name, ".rela", 5) == 0
1683 && strcmp(bfd_get_section_name(abfd, sec),
1686 sreloc = bfd_get_section_by_name(dynobj, name);
1689 sreloc = bfd_make_section(dynobj, name);
1691 || !bfd_set_section_flags(dynobj, sreloc,
1696 || !bfd_set_section_alignment(dynobj, sreloc, 3))
1700 sreloc->_raw_size += sizeof(Elf64_External_Rela);
1709 /* Adjust a symbol defined by a dynamic object and referenced by a
1710 regular object. The current definition is in some section of the
1711 dynamic object, but we're not including those sections. We have to
1712 change the definition to something the rest of the link can
1716 elf64_alpha_adjust_dynamic_symbol (info, h)
1717 struct bfd_link_info *info;
1718 struct elf_link_hash_entry *h;
1723 dynobj = elf_hash_table(info)->dynobj;
1725 /* If this is a function, put it in the procedure linkage table. We
1726 will fill in the contents of the procedure linkage table later,
1727 though we could actually do it here. */
1729 if (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
1731 /* We hadn't seen all of the input symbols when we guessed that we
1732 needed a .plt entry. Revise our decision. */
1734 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1736 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1740 s = bfd_get_section_by_name(dynobj, ".plt");
1741 BFD_ASSERT(s != NULL);
1743 /* The first bit of the .plt is reserved. */
1744 if (s->_raw_size == 0)
1745 s->_raw_size = PLT_HEADER_SIZE;
1747 h->plt_offset = s->_raw_size;
1749 /* If this symbol is not defined in a regular file, and we are not
1750 generating a shared library, then set the symbol to the location
1751 in the .plt. This is required to make function pointers compare
1752 equal between the normal executable and the shared library. */
1755 h->root.u.def.section = s;
1756 h->root.u.def.value = s->_raw_size;
1759 s->_raw_size += PLT_ENTRY_SIZE;
1761 /* We also need an entry in the .rela.plt section. */
1762 s = bfd_get_section_by_name(dynobj, ".rela.plt");
1763 BFD_ASSERT(s != NULL);
1764 s->_raw_size += sizeof(Elf64_External_Rela);
1769 /* If this is a weak symbol, and there is a real definition, the
1770 processor independent code will have arranged for us to see the
1771 real definition first, and we can just use the same value. */
1772 if (h->weakdef != NULL)
1774 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1775 || h->weakdef->root.type == bfd_link_hash_defweak);
1776 h->root.u.def.section = h->weakdef->root.u.def.section;
1777 h->root.u.def.value = h->weakdef->root.u.def.value;
1781 /* This is a reference to a symbol defined by a dynamic object which
1782 is not a function. The Alpha, since it uses .got entries for
1783 symbols even in regular objects, does not need the hackery of a
1784 .dynbss section and COPY dynamic relocations. */
1789 /* Set the sizes of the dynamic sections. */
1792 elf64_alpha_size_dynamic_sections (output_bfd, info)
1794 struct bfd_link_info *info;
1801 dynobj = elf_hash_table(info)->dynobj;
1802 BFD_ASSERT(dynobj != NULL);
1804 if (elf_hash_table(info)->dynamic_sections_created)
1806 /* Set the contents of the .interp section to the interpreter. */
1809 s = bfd_get_section_by_name(dynobj, ".interp");
1810 BFD_ASSERT(s != NULL);
1811 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1812 s->contents = (unsigned char *)ELF_DYNAMIC_INTERPRETER;
1817 /* We may have created entries in the .rela.got section.
1818 However, if we are not creating the dynamic sections, we will
1819 not actually use these entries. Reset the size of .rel.got,
1820 which will cause it to get stripped from the output file
1822 s = bfd_get_section_by_name (dynobj, ".rela.got");
1827 /* The check_relocs and adjust_dynamic_symbol entry points have
1828 determined the sizes of the various dynamic sections. Allocate
1832 for (s = dynobj->sections; s != NULL; s = s->next)
1837 if (!(s->flags & SEC_IN_MEMORY))
1840 /* It's OK to base decisions on the section name, because none
1841 of the dynobj section names depend upon the input files. */
1842 name = bfd_get_section_name(dynobj, s);
1844 /* If we don't need this section, strip it from the output file.
1845 This is to handle .rela.bss and .rela.plt. We must create it
1846 in create_dynamic_sections, because it must be created before
1847 the linker maps input sections to output sections. The
1848 linker does that before adjust_dynamic_symbol is called, and
1849 it is that function which decides whether anything needs to
1850 go into these sections. */
1854 if (strncmp(name, ".rela", 5) == 0)
1856 strip = (s->_raw_size == 0);
1862 /* If this relocation section applies to a read only
1863 section, then we probably need a DT_TEXTREL entry. */
1864 target = bfd_get_section_by_name (output_bfd, name + 5);
1866 && (target->flags & SEC_READONLY) != 0)
1869 if (strcmp(name, ".rela.plt") == 0)
1872 /* We use the reloc_count field as a counter if we need
1873 to copy relocs into the output file. */
1877 else if (strcmp(name, ".got") == 0)
1879 /* If we are generating a shared library, we generate a
1880 section symbol for each output section. These are local
1881 symbols, which means that they must come first in the
1882 dynamic symbol table. That means we must increment the
1883 dynamic symbol index of every other dynamic symbol. */
1890 c[1] = bfd_count_sections(output_bfd);
1892 elf_link_hash_traverse (elf_hash_table(info),
1893 elf64_alpha_adjust_dynindx,
1895 elf_hash_table (info)->dynsymcount += c[1];
1897 for (i = 3, p = output_bfd->sections;
1901 elf_section_data (p)->dynindx = i;
1902 /* These symbols will have no names, so we don't need to
1903 fiddle with dynstr_index. */
1907 else if (strcmp (name, ".plt") != 0)
1909 /* It's not one of our sections, so don't allocate space. */
1917 for (spp = &s->output_section->owner->sections;
1918 *spp != s->output_section;
1919 spp = &(*spp)->next)
1921 *spp = s->output_section->next;
1922 --s->output_section->owner->section_count;
1927 /* Allocate memory for the section contents. */
1928 s->contents = (bfd_byte *) bfd_zalloc(dynobj, s->_raw_size);
1929 if (s->contents == NULL && s->_raw_size != 0)
1933 if (elf_hash_table (info)->dynamic_sections_created)
1935 /* Add some entries to the .dynamic section. We fill in the
1936 values later, in elf64_alpha_finish_dynamic_sections, but we
1937 must add the entries now so that we get the correct size for
1938 the .dynamic section. The DT_DEBUG entry is filled in by the
1939 dynamic linker and used by the debugger. */
1942 if (!bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
1946 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0))
1951 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1952 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1953 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
1957 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
1958 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
1959 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
1960 sizeof(Elf64_External_Rela)))
1965 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
1973 /* Increment the index of a dynamic symbol by a given amount. Called
1974 via elf_link_hash_traverse. */
1977 elf64_alpha_adjust_dynindx (h, cparg)
1978 struct elf_link_hash_entry *h;
1981 long *cp = (long *)cparg;
1983 if (h->dynindx >= cp[0])
1984 h->dynindx += cp[1];
1989 /* Relocate an Alpha ELF section. */
1992 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
1993 contents, relocs, local_syms, local_sections)
1995 struct bfd_link_info *info;
1997 asection *input_section;
1999 Elf_Internal_Rela *relocs;
2000 Elf_Internal_Sym *local_syms;
2001 asection **local_sections;
2003 Elf_Internal_Shdr *symtab_hdr;
2004 Elf_Internal_Rela *rel;
2005 Elf_Internal_Rela *relend;
2006 asection *sec, *sgot, *splt;
2010 symtab_hdr = &elf_tdata(input_bfd)->symtab_hdr;
2012 /* Find the gp value for this input bfd. */
2015 dynobj = elf_hash_table(info)->dynobj;
2018 sgot = bfd_get_section_by_name (dynobj, ".got");
2019 splt = bfd_get_section_by_name (dynobj, ".plt");
2021 gp = _bfd_get_gp_value(dynobj);
2024 gp = (sgot->output_section->vma
2025 + sgot->output_offset
2027 _bfd_set_gp_value(dynobj, gp);
2032 relend = relocs + input_section->reloc_count;
2033 for (; rel < relend; rel++)
2036 reloc_howto_type *howto;
2037 unsigned long r_symndx;
2038 struct elf_link_hash_entry *h;
2039 Elf_Internal_Sym *sym;
2042 bfd_reloc_status_type r;
2044 r_type = ELF64_R_TYPE(rel->r_info);
2045 if (r_type < 0 || r_type >= (int) R_ALPHA_max)
2047 bfd_set_error (bfd_error_bad_value);
2050 howto = elf64_alpha_howto_table + r_type;
2052 r_symndx = ELF64_R_SYM(rel->r_info);
2054 if (info->relocateable)
2056 /* This is a relocateable link. We don't have to change
2057 anything, unless the reloc is against a section symbol,
2058 in which case we have to adjust according to where the
2059 section symbol winds up in the output section. */
2060 if (r_symndx < symtab_hdr->sh_info)
2062 sym = local_syms + r_symndx;
2063 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
2065 sec = local_sections[r_symndx];
2066 rel->r_addend += sec->output_offset + sym->st_value;
2073 /* This is a final link. */
2079 if (r_symndx < symtab_hdr->sh_info)
2081 sym = local_syms + r_symndx;
2082 sec = local_sections[r_symndx];
2083 relocation = (sec->output_section->vma
2084 + sec->output_offset
2089 h = elf_sym_hashes(input_bfd)[r_symndx - symtab_hdr->sh_info];
2091 while (h->root.type == bfd_link_hash_indirect
2092 || h->root.type == bfd_link_hash_warning)
2093 h = (struct elf_link_hash_entry *)h->root.u.i.link;
2095 if (h->root.type == bfd_link_hash_defined
2096 || h->root.type == bfd_link_hash_defweak)
2098 sec = h->root.u.def.section;
2100 /* If the symbol was defined as a common symbol in a
2101 regular object file, and there was no definition in
2102 any dynamic object, then the linker will have
2103 allocated space for the symbol in a common section
2104 but the ELF_LINK_HASH_DEF_REGULAR flag will not have
2105 been set. This is done for dynamic symbols in
2106 elf_adjust_dynamic_symbol but this is not done for
2107 non-dynamic symbols, somehow. */
2108 if ((h->elf_link_hash_flags
2109 & (ELF_LINK_HASH_DEF_REGULAR
2110 | ELF_LINK_HASH_REF_REGULAR
2111 | ELF_LINK_HASH_DEF_DYNAMIC))
2112 == ELF_LINK_HASH_REF_REGULAR
2113 && !(sec->owner->flags & DYNAMIC))
2114 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2117 if ((r_type == R_ALPHA_LITERAL
2118 && elf_hash_table(info)->dynamic_sections_created
2121 || !(h->elf_link_hash_flags
2122 & ELF_LINK_HASH_DEF_REGULAR)))
2125 || !(h->elf_link_hash_flags
2126 & ELF_LINK_HASH_DEF_REGULAR))
2127 && (input_section->flags & SEC_ALLOC)
2128 && (r_type == R_ALPHA_REFLONG
2129 || r_type == R_ALPHA_REFQUAD
2130 || r_type == R_ALPHA_LITERAL)))
2132 /* In these cases, we don't need the relocation value.
2133 We check specially because in some obscure cases
2134 sec->output_section will be NULL. */
2138 /* FIXME: Are not these obscure cases simply bugs? Let's
2139 get something working and come back to this. */
2140 if (sec->output_section == NULL)
2142 #endif /* rth_notdef */
2145 relocation = (h->root.u.def.value
2146 + sec->output_section->vma
2147 + sec->output_offset);
2150 else if (h->root.type == bfd_link_hash_undefweak)
2152 else if (info->shared && !info->symbolic)
2156 if (!((*info->callbacks->undefined_symbol)
2157 (info, h->root.root.string, input_bfd,
2158 input_section, rel->r_offset)))
2163 addend = rel->r_addend;
2167 case R_ALPHA_GPDISP:
2169 bfd_byte *p_ldah, *p_lda;
2171 relocation = (input_section->output_section->vma
2172 + input_section->output_offset
2175 p_ldah = contents + rel->r_offset - input_section->vma;
2176 p_lda = p_ldah + rel->r_addend;
2178 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - relocation,
2183 case R_ALPHA_OP_PUSH:
2184 case R_ALPHA_OP_STORE:
2185 case R_ALPHA_OP_PSUB:
2186 case R_ALPHA_OP_PRSHIFT:
2190 case R_ALPHA_LITERAL:
2194 BFD_ASSERT(gp != 0);
2195 BFD_ASSERT(sgot != NULL);
2198 gotoff = h->got_offset;
2202 gotoff = elf_local_got_offsets (input_bfd)[r_symndx];
2204 /* Use the lsb as a flag indicating that we've already
2205 output the relocation entry. */
2208 gotoff &= ~(bfd_vma)1;
2212 Elf_Internal_Rela outrel;
2214 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2215 BFD_ASSERT(srel != NULL);
2217 outrel.r_offset = (sgot->output_section->vma
2218 + sgot->output_offset + gotoff);
2219 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2220 outrel.r_addend = 0;
2222 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2223 ((Elf64_External_Rela *)
2225 + srel->reloc_count++);
2227 elf_local_got_offsets (input_bfd)[r_symndx] |= 1;
2231 /* Initialize the .got entry. */
2232 bfd_put_64 (output_bfd, relocation, sgot->contents + gotoff);
2234 /* Figure the gprel relocation. */
2236 relocation = (sgot->output_section->vma
2237 + sgot->output_offset
2241 /* overflow handled by _bfd_final_link_relocate */
2244 case R_ALPHA_GPREL32:
2245 BFD_ASSERT(gp != 0);
2249 case R_ALPHA_BRADDR:
2251 /* The regular PC-relative stuff measures from the start of
2252 the instruction rather than the end. */
2256 case R_ALPHA_REFLONG:
2257 case R_ALPHA_REFQUAD:
2259 || (h && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
2263 Elf_Internal_Rela outrel;
2265 name = (bfd_elf_string_from_elf_section
2266 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
2267 elf_section_data(input_section)->rel_hdr.sh_name));
2268 BFD_ASSERT(name != NULL);
2270 srel = bfd_get_section_by_name(dynobj, name);
2271 BFD_ASSERT(srel != NULL);
2273 outrel.r_offset = (input_section->output_section->vma
2274 + input_section->output_offset
2276 outrel.r_addend = 0;
2279 BFD_ASSERT(h->dynindx != -1);
2280 outrel.r_info = ELF64_R_INFO(h->dynindx, r_type);
2285 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2288 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2289 ((Elf64_External_Rela *)
2291 + srel->reloc_count++);
2297 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2298 contents, rel->r_offset, relocation,
2308 case bfd_reloc_overflow:
2313 name = h->root.root.string;
2316 name = (bfd_elf_string_from_elf_section
2317 (input_bfd, symtab_hdr->sh_link, sym->st_name));
2321 name = bfd_section_name (input_bfd, sec);
2323 if (! ((*info->callbacks->reloc_overflow)
2324 (info, name, howto->name, (bfd_vma) 0,
2325 input_bfd, input_section, rel->r_offset)))
2331 case bfd_reloc_outofrange:
2339 /* Finish up dynamic symbol handling. We set the contents of various
2340 dynamic sections here. */
2343 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
2345 struct bfd_link_info *info;
2346 struct elf_link_hash_entry *h;
2347 Elf_Internal_Sym *sym;
2349 bfd *dynobj = elf_hash_table(info)->dynobj;
2351 if (h->plt_offset != MINUS_ONE)
2353 asection *splt, *sgot, *srel;
2354 Elf_Internal_Rela outrel;
2355 bfd_vma got_addr, plt_addr;
2358 /* This symbol has an entry in the procedure linkage table. */
2360 BFD_ASSERT(h->dynindx != -1);
2361 BFD_ASSERT(h->got_offset != MINUS_ONE);
2363 splt = bfd_get_section_by_name(dynobj, ".plt");
2364 BFD_ASSERT(splt != NULL);
2365 srel = bfd_get_section_by_name(dynobj, ".rela.plt");
2366 BFD_ASSERT(srel != NULL);
2367 sgot = bfd_get_section_by_name(dynobj, ".got");
2368 BFD_ASSERT(sgot != NULL);
2370 got_addr = (sgot->output_section->vma
2371 + sgot->output_offset
2373 plt_addr = (splt->output_section->vma
2374 + splt->output_offset
2377 plt_index = (h->plt_offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
2379 /* Fill in the entry in the procedure linkage table. */
2381 unsigned insn1, insn2, insn3;
2384 /* decompose the reloc offset for the plt for ldah+lda */
2385 hi = plt_index * sizeof(Elf64_External_Rela);
2386 lo = ((hi & 0xffff) ^ 0x8000) - 0x8000;
2387 hi = (hi - lo) >> 16;
2389 insn1 = PLT_ENTRY_WORD1 | (hi & 0xffff);
2390 insn2 = PLT_ENTRY_WORD2 | (lo & 0xffff);
2391 insn3 = PLT_ENTRY_WORD3 | ((-(h->plt_offset + 12) >> 2) & 0x1fffff);
2393 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt_offset);
2394 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt_offset + 4);
2395 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt_offset + 8);
2398 /* Fill in the entry in the .rela.plt section. */
2399 outrel.r_offset = got_addr;
2400 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
2401 outrel.r_addend = 0;
2403 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2404 ((Elf64_External_Rela *)srel->contents
2407 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2409 /* Mark the symbol as undefined, rather than as defined in the
2410 .plt section. Leave the value alone. */
2411 sym->st_shndx = SHN_UNDEF;
2414 /* Fill in the entry in the global offset table. */
2415 bfd_put_64 (output_bfd, plt_addr, sgot->contents + h->got_offset);
2417 else if (h->got_offset != MINUS_ONE)
2419 asection *sgot, *srel;
2420 Elf_Internal_Rela outrel;
2422 BFD_ASSERT(h->dynindx != -1);
2424 sgot = bfd_get_section_by_name (dynobj, ".got");
2425 BFD_ASSERT (sgot != NULL);
2426 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2427 BFD_ASSERT (srel != NULL);
2429 outrel.r_offset = (sgot->output_section->vma
2430 + sgot->output_offset
2432 outrel.r_addend = 0;
2435 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2436 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2439 bfd_put_64(output_bfd, (bfd_vma)0, sgot->contents + h->got_offset);
2440 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_GLOB_DAT);
2443 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2444 ((Elf64_External_Rela *)srel->contents
2445 + srel->reloc_count++));
2448 /* Mark some specially defined symbols as absolute. */
2449 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2450 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2451 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2452 sym->st_shndx = SHN_ABS;
2457 /* Finish up the dynamic sections. */
2460 elf64_alpha_finish_dynamic_sections (output_bfd, info)
2462 struct bfd_link_info *info;
2468 dynobj = elf_hash_table (info)->dynobj;
2469 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2471 if (elf_hash_table (info)->dynamic_sections_created)
2474 Elf64_External_Dyn *dyncon, *dynconend;
2476 splt = bfd_get_section_by_name (dynobj, ".plt");
2477 BFD_ASSERT (splt != NULL && sdyn != NULL);
2479 dyncon = (Elf64_External_Dyn *) sdyn->contents;
2480 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2481 for (; dyncon < dynconend; dyncon++)
2483 Elf_Internal_Dyn dyn;
2487 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2502 /* My interpretation of the TIS v1.1 ELF document indicates
2503 that RELASZ should not include JMPREL. This is not what
2504 the rest of the BFD does. It is, however, what the
2505 glibc ld.so wants. Do this fixup here until we found
2506 out who is right. */
2507 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2511 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
2516 s = bfd_get_section_by_name (output_bfd, name);
2517 dyn.d_un.d_ptr = (s ? s->vma : 0);
2521 s = bfd_get_section_by_name (output_bfd, name);
2523 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
2527 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2530 /* Initialize the PLT0 entry */
2531 if (splt->_raw_size > 0)
2533 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
2534 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
2535 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
2536 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
2538 /* The next two words will be filled in by ld.so */
2539 bfd_put_64 (output_bfd, 0, splt->contents + 16);
2540 bfd_put_64 (output_bfd, 0, splt->contents + 24);
2542 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
2547 /* Set the first entry in the global offset table to the address of
2548 the dynamic section. */
2549 sgot = bfd_get_section_by_name (dynobj, ".got");
2550 if (sgot && sgot->_raw_size > 0)
2553 bfd_put_64 (output_bfd, (bfd_vma)0, sgot->contents);
2555 bfd_put_64 (output_bfd,
2556 sdyn->output_section->vma + sdyn->output_offset,
2559 elf_section_data (sgot->output_section)->this_hdr.sh_entsize =
2560 8 * RESERVED_GOT_ENTRIES;
2567 Elf_Internal_Sym sym;
2569 /* Set up the section symbols for the output sections. */
2571 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
2572 BFD_ASSERT (sdynsym != NULL);
2576 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
2579 for (s = output_bfd->sections; s != NULL; s = s->next)
2583 sym.st_value = s->vma;
2585 indx = elf_section_data (s)->this_idx;
2586 BFD_ASSERT (indx > 0);
2587 sym.st_shndx = indx;
2589 bfd_elf64_swap_symbol_out (output_bfd, &sym,
2590 (PTR) (((Elf64_External_Sym *)
2592 + elf_section_data (s)->dynindx));
2595 /* Set the sh_info field of the output .dynsym section to the
2596 index of the first global symbol. */
2597 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
2598 bfd_count_sections (output_bfd) + 1;
2604 /* We need to use a special link routine to handle the .reginfo and
2605 the .mdebug sections. We need to merge all instances of these
2606 sections together, not write them all out sequentially. */
2609 elf64_alpha_final_link (abfd, info)
2611 struct bfd_link_info *info;
2614 struct bfd_link_order *p;
2615 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
2616 struct ecoff_debug_info debug;
2617 const struct ecoff_debug_swap *swap
2618 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2619 HDRR *symhdr = &debug.symbolic_header;
2620 PTR mdebug_handle = NULL;
2622 /* Go through the sections and collect the .reginfo and .mdebug
2626 gptab_data_sec = NULL;
2627 gptab_bss_sec = NULL;
2628 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2630 #ifdef ERIC_neverdef
2631 if (strcmp (o->name, ".reginfo") == 0)
2633 memset (®info, 0, sizeof reginfo);
2635 /* We have found the .reginfo section in the output file.
2636 Look through all the link_orders comprising it and merge
2637 the information together. */
2638 for (p = o->link_order_head;
2639 p != (struct bfd_link_order *) NULL;
2642 asection *input_section;
2644 Elf64_External_RegInfo ext;
2647 if (p->type != bfd_indirect_link_order)
2649 if (p->type == bfd_fill_link_order)
2654 input_section = p->u.indirect.section;
2655 input_bfd = input_section->owner;
2657 /* The linker emulation code has probably clobbered the
2658 size to be zero bytes. */
2659 if (input_section->_raw_size == 0)
2660 input_section->_raw_size = sizeof (Elf64_External_RegInfo);
2662 if (! bfd_get_section_contents (input_bfd, input_section,
2668 bfd_alpha_elf64_swap_reginfo_in (input_bfd, &ext, &sub);
2670 reginfo.ri_gprmask |= sub.ri_gprmask;
2671 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
2672 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
2673 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
2674 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
2676 /* ri_gp_value is set by the function
2677 alpha_elf_section_processing when the section is
2678 finally written out. */
2680 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2681 elf_link_input_bfd ignores this section. */
2682 input_section->flags &=~ SEC_HAS_CONTENTS;
2685 /* Force the section size to the value we want. */
2686 o->_raw_size = sizeof (Elf64_External_RegInfo);
2688 /* Skip this section later on (I don't think this currently
2689 matters, but someday it might). */
2690 o->link_order_head = (struct bfd_link_order *) NULL;
2696 if (strcmp (o->name, ".mdebug") == 0)
2698 struct extsym_info einfo;
2700 /* We have found the .mdebug section in the output file.
2701 Look through all the link_orders comprising it and merge
2702 the information together. */
2703 symhdr->magic = swap->sym_magic;
2704 /* FIXME: What should the version stamp be? */
2706 symhdr->ilineMax = 0;
2710 symhdr->isymMax = 0;
2711 symhdr->ioptMax = 0;
2712 symhdr->iauxMax = 0;
2714 symhdr->issExtMax = 0;
2717 symhdr->iextMax = 0;
2719 /* We accumulate the debugging information itself in the
2720 debug_info structure. */
2722 debug.external_dnr = NULL;
2723 debug.external_pdr = NULL;
2724 debug.external_sym = NULL;
2725 debug.external_opt = NULL;
2726 debug.external_aux = NULL;
2728 debug.ssext = debug.ssext_end = NULL;
2729 debug.external_fdr = NULL;
2730 debug.external_rfd = NULL;
2731 debug.external_ext = debug.external_ext_end = NULL;
2733 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
2734 if (mdebug_handle == (PTR) NULL)
2743 static const char * const name[] =
2745 ".text", ".init", ".fini", ".data",
2746 ".rodata", ".sdata", ".sbss", ".bss"
2748 static const int sc[] = { scText, scInit, scFini, scData,
2749 scRData, scSData, scSBss, scBss };
2752 esym.cobol_main = 0;
2756 esym.asym.iss = issNil;
2757 esym.asym.st = stLocal;
2758 esym.asym.reserved = 0;
2759 esym.asym.index = indexNil;
2760 for (i = 0; i < 8; i++)
2762 esym.asym.sc = sc[i];
2763 s = bfd_get_section_by_name (abfd, name[i]);
2766 esym.asym.value = s->vma;
2767 last = s->vma + s->_raw_size;
2770 esym.asym.value = last;
2772 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
2778 for (p = o->link_order_head;
2779 p != (struct bfd_link_order *) NULL;
2782 asection *input_section;
2784 const struct ecoff_debug_swap *input_swap;
2785 struct ecoff_debug_info input_debug;
2789 if (p->type != bfd_indirect_link_order)
2791 if (p->type == bfd_fill_link_order)
2796 input_section = p->u.indirect.section;
2797 input_bfd = input_section->owner;
2799 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
2800 || (get_elf_backend_data (input_bfd)
2801 ->elf_backend_ecoff_debug_swap) == NULL)
2803 /* I don't know what a non ALPHA ELF bfd would be
2804 doing with a .mdebug section, but I don't really
2805 want to deal with it. */
2809 input_swap = (get_elf_backend_data (input_bfd)
2810 ->elf_backend_ecoff_debug_swap);
2812 BFD_ASSERT (p->size == input_section->_raw_size);
2814 /* The ECOFF linking code expects that we have already
2815 read in the debugging information and set up an
2816 ecoff_debug_info structure, so we do that now. */
2817 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
2821 if (! (bfd_ecoff_debug_accumulate
2822 (mdebug_handle, abfd, &debug, swap, input_bfd,
2823 &input_debug, input_swap, info)))
2826 /* Loop through the external symbols. For each one with
2827 interesting information, try to find the symbol in
2828 the linker global hash table and save the information
2829 for the output external symbols. */
2830 eraw_src = input_debug.external_ext;
2831 eraw_end = (eraw_src
2832 + (input_debug.symbolic_header.iextMax
2833 * input_swap->external_ext_size));
2835 eraw_src < eraw_end;
2836 eraw_src += input_swap->external_ext_size)
2840 struct alpha_elf_link_hash_entry *h;
2842 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
2843 if (ext.asym.sc == scNil
2844 || ext.asym.sc == scUndefined
2845 || ext.asym.sc == scSUndefined)
2848 name = input_debug.ssext + ext.asym.iss;
2849 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
2850 name, false, false, true);
2851 if (h == NULL || h->esym.ifd != -2)
2857 < input_debug.symbolic_header.ifdMax);
2858 ext.ifd = input_debug.ifdmap[ext.ifd];
2864 /* Free up the information we just read. */
2865 free (input_debug.line);
2866 free (input_debug.external_dnr);
2867 free (input_debug.external_pdr);
2868 free (input_debug.external_sym);
2869 free (input_debug.external_opt);
2870 free (input_debug.external_aux);
2871 free (input_debug.ss);
2872 free (input_debug.ssext);
2873 free (input_debug.external_fdr);
2874 free (input_debug.external_rfd);
2875 free (input_debug.external_ext);
2877 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2878 elf_link_input_bfd ignores this section. */
2879 input_section->flags &=~ SEC_HAS_CONTENTS;
2882 #ifdef ERIC_neverdef
2885 /* Create .rtproc section. */
2886 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
2887 if (rtproc_sec == NULL)
2889 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
2892 rtproc_sec = bfd_make_section (abfd, ".rtproc");
2893 if (rtproc_sec == NULL
2894 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
2895 || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
2899 if (! alpha_elf_create_procedure_table (mdebug_handle, abfd,
2900 info, rtproc_sec, &debug))
2906 /* Build the external symbol information. */
2909 einfo.debug = &debug;
2911 einfo.failed = false;
2912 elf_link_hash_traverse (elf_hash_table (info),
2913 elf64_alpha_output_extsym,
2918 /* Set the size of the .mdebug section. */
2919 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
2921 /* Skip this section later on (I don't think this currently
2922 matters, but someday it might). */
2923 o->link_order_head = (struct bfd_link_order *) NULL;
2928 #ifdef ERIC_neverdef
2929 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
2931 const char *subname;
2934 Elf64_External_gptab *ext_tab;
2937 /* The .gptab.sdata and .gptab.sbss sections hold
2938 information describing how the small data area would
2939 change depending upon the -G switch. These sections
2940 not used in executables files. */
2941 if (! info->relocateable)
2945 for (p = o->link_order_head;
2946 p != (struct bfd_link_order *) NULL;
2949 asection *input_section;
2951 if (p->type != bfd_indirect_link_order)
2953 if (p->type == bfd_fill_link_order)
2958 input_section = p->u.indirect.section;
2960 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2961 elf_link_input_bfd ignores this section. */
2962 input_section->flags &=~ SEC_HAS_CONTENTS;
2965 /* Skip this section later on (I don't think this
2966 currently matters, but someday it might). */
2967 o->link_order_head = (struct bfd_link_order *) NULL;
2969 /* Really remove the section. */
2970 for (secpp = &abfd->sections;
2972 secpp = &(*secpp)->next)
2974 *secpp = (*secpp)->next;
2975 --abfd->section_count;
2980 /* There is one gptab for initialized data, and one for
2981 uninitialized data. */
2982 if (strcmp (o->name, ".gptab.sdata") == 0)
2984 else if (strcmp (o->name, ".gptab.sbss") == 0)
2988 (*_bfd_error_handler)
2989 ("%s: illegal section name `%s'",
2990 bfd_get_filename (abfd), o->name);
2991 bfd_set_error (bfd_error_nonrepresentable_section);
2995 /* The linker script always combines .gptab.data and
2996 .gptab.sdata into .gptab.sdata, and likewise for
2997 .gptab.bss and .gptab.sbss. It is possible that there is
2998 no .sdata or .sbss section in the output file, in which
2999 case we must change the name of the output section. */
3000 subname = o->name + sizeof ".gptab" - 1;
3001 if (bfd_get_section_by_name (abfd, subname) == NULL)
3003 if (o == gptab_data_sec)
3004 o->name = ".gptab.data";
3006 o->name = ".gptab.bss";
3007 subname = o->name + sizeof ".gptab" - 1;
3008 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
3011 /* Set up the first entry. */
3013 tab = (Elf64_gptab *) bfd_malloc (c * sizeof (Elf64_gptab));
3016 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
3017 tab[0].gt_header.gt_unused = 0;
3019 /* Combine the input sections. */
3020 for (p = o->link_order_head;
3021 p != (struct bfd_link_order *) NULL;
3024 asection *input_section;
3028 bfd_size_type gpentry;
3030 if (p->type != bfd_indirect_link_order)
3032 if (p->type == bfd_fill_link_order)
3037 input_section = p->u.indirect.section;
3038 input_bfd = input_section->owner;
3040 /* Combine the gptab entries for this input section one
3041 by one. We know that the input gptab entries are
3042 sorted by ascending -G value. */
3043 size = bfd_section_size (input_bfd, input_section);
3045 for (gpentry = sizeof (Elf64_External_gptab);
3047 gpentry += sizeof (Elf64_External_gptab))
3049 Elf64_External_gptab ext_gptab;
3050 Elf64_gptab int_gptab;
3056 if (! (bfd_get_section_contents
3057 (input_bfd, input_section, (PTR) &ext_gptab,
3058 gpentry, sizeof (Elf64_External_gptab))))
3064 bfd_alpha_elf64_swap_gptab_in (input_bfd, &ext_gptab,
3066 val = int_gptab.gt_entry.gt_g_value;
3067 add = int_gptab.gt_entry.gt_bytes - last;
3070 for (look = 1; look < c; look++)
3072 if (tab[look].gt_entry.gt_g_value >= val)
3073 tab[look].gt_entry.gt_bytes += add;
3075 if (tab[look].gt_entry.gt_g_value == val)
3081 Elf64_gptab *new_tab;
3084 /* We need a new table entry. */
3085 new_tab = ((Elf64_gptab *)
3086 bfd_realloc ((PTR) tab,
3087 (c + 1) * sizeof (Elf64_gptab)));
3088 if (new_tab == NULL)
3094 tab[c].gt_entry.gt_g_value = val;
3095 tab[c].gt_entry.gt_bytes = add;
3097 /* Merge in the size for the next smallest -G
3098 value, since that will be implied by this new
3101 for (look = 1; look < c; look++)
3103 if (tab[look].gt_entry.gt_g_value < val
3105 || (tab[look].gt_entry.gt_g_value
3106 > tab[max].gt_entry.gt_g_value)))
3110 tab[c].gt_entry.gt_bytes +=
3111 tab[max].gt_entry.gt_bytes;
3116 last = int_gptab.gt_entry.gt_bytes;
3119 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3120 elf_link_input_bfd ignores this section. */
3121 input_section->flags &=~ SEC_HAS_CONTENTS;
3124 /* The table must be sorted by -G value. */
3126 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
3128 /* Swap out the table. */
3129 ext_tab = ((Elf64_External_gptab *)
3130 bfd_alloc (abfd, c * sizeof (Elf64_External_gptab)));
3131 if (ext_tab == NULL)
3137 for (i = 0; i < c; i++)
3138 bfd_alpha_elf64_swap_gptab_out (abfd, tab + i, ext_tab + i);
3141 o->_raw_size = c * sizeof (Elf64_External_gptab);
3142 o->contents = (bfd_byte *) ext_tab;
3144 /* Skip this section later on (I don't think this currently
3145 matters, but someday it might). */
3146 o->link_order_head = (struct bfd_link_order *) NULL;
3152 /* Invoke the regular ELF backend linker to do all the work. */
3153 if (! bfd_elf64_bfd_final_link (abfd, info))
3156 /* Now write out the computed sections. */
3158 #ifdef ERIC_neverdef
3159 if (reginfo_sec != (asection *) NULL)
3161 Elf64_External_RegInfo ext;
3163 bfd_alpha_elf64_swap_reginfo_out (abfd, ®info, &ext);
3164 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
3165 (file_ptr) 0, sizeof ext))
3170 if (mdebug_sec != (asection *) NULL)
3172 BFD_ASSERT (abfd->output_has_begun);
3173 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
3175 mdebug_sec->filepos))
3178 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
3181 if (gptab_data_sec != (asection *) NULL)
3183 if (! bfd_set_section_contents (abfd, gptab_data_sec,
3184 gptab_data_sec->contents,
3186 gptab_data_sec->_raw_size))
3190 if (gptab_bss_sec != (asection *) NULL)
3192 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
3193 gptab_bss_sec->contents,
3195 gptab_bss_sec->_raw_size))
3202 /* ECOFF swapping routines. These are used when dealing with the
3203 .mdebug section, which is in the ECOFF debugging format. Copied
3204 from elf32-mips.c. */
3205 static const struct ecoff_debug_swap
3206 elf64_alpha_ecoff_debug_swap =
3208 /* Symbol table magic number. */
3210 /* Alignment of debugging information. E.g., 4. */
3212 /* Sizes of external symbolic information. */
3213 sizeof (struct hdr_ext),
3214 sizeof (struct dnr_ext),
3215 sizeof (struct pdr_ext),
3216 sizeof (struct sym_ext),
3217 sizeof (struct opt_ext),
3218 sizeof (struct fdr_ext),
3219 sizeof (struct rfd_ext),
3220 sizeof (struct ext_ext),
3221 /* Functions to swap in external symbolic data. */
3230 _bfd_ecoff_swap_tir_in,
3231 _bfd_ecoff_swap_rndx_in,
3232 /* Functions to swap out external symbolic data. */
3241 _bfd_ecoff_swap_tir_out,
3242 _bfd_ecoff_swap_rndx_out,
3243 /* Function to read in symbolic data. */
3244 elf64_alpha_read_ecoff_info
3247 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
3248 #define TARGET_LITTLE_NAME "elf64-alpha"
3249 #define ELF_ARCH bfd_arch_alpha
3250 #define ELF_MACHINE_CODE EM_ALPHA
3251 #define ELF_MAXPAGESIZE 0x100000
3253 #define bfd_elf64_bfd_link_hash_table_create \
3254 elf64_alpha_bfd_link_hash_table_create
3256 #define bfd_elf64_bfd_reloc_type_lookup \
3257 elf64_alpha_bfd_reloc_type_lookup
3258 #define elf_info_to_howto \
3259 elf64_alpha_info_to_howto
3261 #define elf_backend_object_p \
3262 elf64_alpha_object_p
3263 #define elf_backend_section_from_shdr \
3264 elf64_alpha_section_from_shdr
3265 #define elf_backend_fake_sections \
3266 elf64_alpha_fake_sections
3267 #define elf_backend_additional_program_headers \
3268 elf64_alpha_additional_program_headers
3270 #define bfd_elf64_bfd_is_local_label \
3271 elf64_alpha_is_local_label
3272 #define bfd_elf64_find_nearest_line \
3273 elf64_alpha_find_nearest_line
3275 #define elf_backend_check_relocs \
3276 elf64_alpha_check_relocs
3277 #define elf_backend_create_dynamic_sections \
3278 elf64_alpha_create_dynamic_sections
3279 #define elf_backend_adjust_dynamic_symbol \
3280 elf64_alpha_adjust_dynamic_symbol
3281 #define elf_backend_size_dynamic_sections \
3282 elf64_alpha_size_dynamic_sections
3283 #define elf_backend_relocate_section \
3284 elf64_alpha_relocate_section
3285 #define elf_backend_finish_dynamic_symbol \
3286 elf64_alpha_finish_dynamic_symbol
3287 #define elf_backend_finish_dynamic_sections \
3288 elf64_alpha_finish_dynamic_sections
3289 #define bfd_elf64_bfd_final_link \
3290 elf64_alpha_final_link
3292 #define elf_backend_ecoff_debug_swap \
3293 &elf64_alpha_ecoff_debug_swap
3296 * A few constants that determine how the .plt section is set up.
3298 #define elf_backend_want_got_plt 0
3299 #define elf_backend_plt_readonly 0
3300 #define elf_backend_want_plt_sym 1
3302 #include "elf64-target.h"