1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 97, 98, 1999 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 boolean elf64_alpha_mkobject PARAMS ((bfd *));
50 static struct bfd_hash_entry * elf64_alpha_link_hash_newfunc
51 PARAMS((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
52 static struct bfd_link_hash_table * elf64_alpha_bfd_link_hash_table_create
55 static bfd_reloc_status_type elf64_alpha_reloc_nil
56 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
57 static bfd_reloc_status_type elf64_alpha_reloc_bad
58 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
59 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
60 PARAMS((bfd *, bfd_vma, bfd_byte *, bfd_byte *));
61 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
62 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
64 static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup
65 PARAMS((bfd *, bfd_reloc_code_real_type));
66 static void elf64_alpha_info_to_howto
67 PARAMS((bfd *, arelent *, Elf64_Internal_Rela *));
69 static boolean elf64_alpha_object_p
71 static boolean elf64_alpha_section_from_shdr
72 PARAMS((bfd *, Elf64_Internal_Shdr *, char *));
73 static boolean elf64_alpha_fake_sections
74 PARAMS((bfd *, Elf64_Internal_Shdr *, asection *));
75 static boolean elf64_alpha_create_got_section
76 PARAMS((bfd *, struct bfd_link_info *));
77 static boolean elf64_alpha_create_dynamic_sections
78 PARAMS((bfd *, struct bfd_link_info *));
80 static boolean elf64_alpha_read_ecoff_info
81 PARAMS((bfd *, asection *, struct ecoff_debug_info *));
82 static boolean elf64_alpha_is_local_label_name
83 PARAMS((bfd *, const char *));
84 static boolean elf64_alpha_find_nearest_line
85 PARAMS((bfd *, asection *, asymbol **, bfd_vma, const char **,
86 const char **, unsigned int *));
88 #if defined(__STDC__) || defined(ALMOST_STDC)
89 struct alpha_elf_link_hash_entry;
92 static boolean elf64_alpha_output_extsym
93 PARAMS((struct alpha_elf_link_hash_entry *, PTR));
95 static boolean elf64_alpha_can_merge_gots
96 PARAMS((bfd *, bfd *));
97 static void elf64_alpha_merge_gots
98 PARAMS((bfd *, bfd *));
99 static boolean elf64_alpha_calc_got_offsets_for_symbol
100 PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
101 static void elf64_alpha_calc_got_offsets PARAMS ((struct bfd_link_info *));
102 static boolean elf64_alpha_size_got_sections
103 PARAMS ((bfd *, struct bfd_link_info *));
104 static boolean elf64_alpha_always_size_sections
105 PARAMS ((bfd *, struct bfd_link_info *));
106 static boolean elf64_alpha_calc_dynrel_sizes
107 PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
108 static boolean elf64_alpha_add_symbol_hook
109 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
110 const char **, flagword *, asection **, bfd_vma *));
111 static boolean elf64_alpha_check_relocs
112 PARAMS((bfd *, struct bfd_link_info *, asection *sec,
113 const Elf_Internal_Rela *));
114 static boolean elf64_alpha_adjust_dynamic_symbol
115 PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *));
116 static boolean elf64_alpha_size_dynamic_sections
117 PARAMS((bfd *, struct bfd_link_info *));
118 static boolean elf64_alpha_relocate_section
119 PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
120 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
121 static boolean elf64_alpha_finish_dynamic_symbol
122 PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
123 Elf_Internal_Sym *));
124 static boolean elf64_alpha_finish_dynamic_sections
125 PARAMS((bfd *, struct bfd_link_info *));
126 static boolean elf64_alpha_final_link
127 PARAMS((bfd *, struct bfd_link_info *));
130 struct alpha_elf_link_hash_entry
132 struct elf_link_hash_entry root;
134 /* External symbol information. */
137 /* Cumulative flags for all the .got entries. */
140 /* Contexts (LITUSE) in which a literal was referenced. */
141 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
142 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
143 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
144 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x08
146 /* Used to implement multiple .got subsections. */
147 struct alpha_elf_got_entry
149 struct alpha_elf_got_entry *next;
151 /* which .got subsection? */
154 /* the addend in effect for this entry. */
157 /* the .got offset for this entry. */
162 /* An additional flag. */
163 #define ALPHA_ELF_GOT_ENTRY_RELOCS_DONE 0x10
168 /* used to count non-got, non-plt relocations for delayed sizing
169 of relocation sections. */
170 struct alpha_elf_reloc_entry
172 struct alpha_elf_reloc_entry *next;
174 /* which .reloc section? */
177 /* what kind of relocation? */
180 /* how many did we find? */
185 /* Alpha ELF linker hash table. */
187 struct alpha_elf_link_hash_table
189 struct elf_link_hash_table root;
191 /* The head of a list of .got subsections linked through
192 alpha_elf_tdata(abfd)->got_link_next. */
196 /* Look up an entry in a Alpha ELF linker hash table. */
198 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
199 ((struct alpha_elf_link_hash_entry *) \
200 elf_link_hash_lookup (&(table)->root, (string), (create), \
203 /* Traverse a Alpha ELF linker hash table. */
205 #define alpha_elf_link_hash_traverse(table, func, info) \
206 (elf_link_hash_traverse \
208 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
211 /* Get the Alpha ELF linker hash table from a link_info structure. */
213 #define alpha_elf_hash_table(p) \
214 ((struct alpha_elf_link_hash_table *) ((p)->hash))
216 /* Get the object's symbols as our own entry type. */
218 #define alpha_elf_sym_hashes(abfd) \
219 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
221 /* Should we do dynamic things to this symbol? */
223 #define alpha_elf_dynamic_symbol_p(h, info) \
224 ((((info)->shared && !(info)->symbolic) \
225 || (((h)->elf_link_hash_flags \
226 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
227 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
228 || (h)->root.type == bfd_link_hash_undefweak \
229 || (h)->root.type == bfd_link_hash_defweak) \
230 && (h)->dynindx != -1)
232 /* Create an entry in a Alpha ELF linker hash table. */
234 static struct bfd_hash_entry *
235 elf64_alpha_link_hash_newfunc (entry, table, string)
236 struct bfd_hash_entry *entry;
237 struct bfd_hash_table *table;
240 struct alpha_elf_link_hash_entry *ret =
241 (struct alpha_elf_link_hash_entry *) entry;
243 /* Allocate the structure if it has not already been allocated by a
245 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
246 ret = ((struct alpha_elf_link_hash_entry *)
247 bfd_hash_allocate (table,
248 sizeof (struct alpha_elf_link_hash_entry)));
249 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
250 return (struct bfd_hash_entry *) ret;
252 /* Call the allocation method of the superclass. */
253 ret = ((struct alpha_elf_link_hash_entry *)
254 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
256 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
258 /* Set local fields. */
259 memset (&ret->esym, 0, sizeof (EXTR));
260 /* We use -2 as a marker to indicate that the information has
261 not been set. -1 means there is no associated ifd. */
264 ret->got_entries = NULL;
265 ret->reloc_entries = NULL;
268 return (struct bfd_hash_entry *) ret;
271 /* Create a Alpha ELF linker hash table. */
273 static struct bfd_link_hash_table *
274 elf64_alpha_bfd_link_hash_table_create (abfd)
277 struct alpha_elf_link_hash_table *ret;
279 ret = ((struct alpha_elf_link_hash_table *)
280 bfd_zalloc (abfd, sizeof (struct alpha_elf_link_hash_table)));
281 if (ret == (struct alpha_elf_link_hash_table *) NULL)
284 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
285 elf64_alpha_link_hash_newfunc))
287 bfd_release (abfd, ret);
291 return &ret->root.root;
294 /* We have some private fields hanging off of the elf_tdata structure. */
296 struct alpha_elf_obj_tdata
298 struct elf_obj_tdata root;
300 /* For every input file, these are the got entries for that object's
302 struct alpha_elf_got_entry ** local_got_entries;
304 /* For every input file, this is the object that owns the got that
305 this input file uses. */
308 /* For every got, this is a linked list through the objects using this got */
309 bfd *in_got_link_next;
311 /* For every got, this is a link to the next got subsegment. */
314 /* For every got, this is the section. */
317 /* For every got, this is it's total number of *entries*. */
318 int total_got_entries;
320 /* For every got, this is the sum of the number of *entries* required
321 to hold all of the member object's local got. */
322 int n_local_got_entries;
325 #define alpha_elf_tdata(abfd) \
326 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
329 elf64_alpha_mkobject (abfd)
332 abfd->tdata.any = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
333 if (abfd->tdata.any == NULL)
339 elf64_alpha_object_p (abfd)
342 /* Allocate our special target data. */
343 struct alpha_elf_obj_tdata *new_tdata;
344 new_tdata = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
345 if (new_tdata == NULL)
347 new_tdata->root = *abfd->tdata.elf_obj_data;
348 abfd->tdata.any = new_tdata;
350 /* Set the right machine number for an Alpha ELF file. */
351 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
354 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
355 from smaller values. Start with zero, widen, *then* decrement. */
356 #define MINUS_ONE (((bfd_vma)0) - 1)
358 static reloc_howto_type elf64_alpha_howto_table[] =
360 HOWTO (R_ALPHA_NONE, /* type */
362 0, /* size (0 = byte, 1 = short, 2 = long) */
364 true, /* pc_relative */
366 complain_overflow_dont, /* complain_on_overflow */
367 elf64_alpha_reloc_nil, /* special_function */
369 false, /* partial_inplace */
372 true), /* pcrel_offset */
374 /* A 32 bit reference to a symbol. */
375 HOWTO (R_ALPHA_REFLONG, /* type */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_bitfield, /* complain_on_overflow */
382 0, /* special_function */
383 "REFLONG", /* name */
384 false, /* partial_inplace */
385 0xffffffff, /* src_mask */
386 0xffffffff, /* dst_mask */
387 false), /* pcrel_offset */
389 /* A 64 bit reference to a symbol. */
390 HOWTO (R_ALPHA_REFQUAD, /* type */
392 4, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_bitfield, /* complain_on_overflow */
397 0, /* special_function */
398 "REFQUAD", /* name */
399 false, /* partial_inplace */
400 MINUS_ONE, /* src_mask */
401 MINUS_ONE, /* dst_mask */
402 false), /* pcrel_offset */
404 /* A 32 bit GP relative offset. This is just like REFLONG except
405 that when the value is used the value of the gp register will be
407 HOWTO (R_ALPHA_GPREL32, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_bitfield, /* complain_on_overflow */
414 0, /* special_function */
415 "GPREL32", /* name */
416 false, /* partial_inplace */
417 0xffffffff, /* src_mask */
418 0xffffffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* Used for an instruction that refers to memory off the GP register. */
422 HOWTO (R_ALPHA_LITERAL, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_signed, /* complain_on_overflow */
429 0, /* special_function */
430 "ELF_LITERAL", /* name */
431 false, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* This reloc only appears immediately following an ELF_LITERAL reloc.
437 It identifies a use of the literal. The symbol index is special:
438 1 means the literal address is in the base register of a memory
439 format instruction; 2 means the literal address is in the byte
440 offset register of a byte-manipulation instruction; 3 means the
441 literal address is in the target register of a jsr instruction.
442 This does not actually do any relocation. */
443 HOWTO (R_ALPHA_LITUSE, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 false, /* pc_relative */
449 complain_overflow_dont, /* complain_on_overflow */
450 elf64_alpha_reloc_nil, /* special_function */
452 false, /* partial_inplace */
455 false), /* pcrel_offset */
457 /* Load the gp register. This is always used for a ldah instruction
458 which loads the upper 16 bits of the gp register. The symbol
459 index of the GPDISP instruction is an offset in bytes to the lda
460 instruction that loads the lower 16 bits. The value to use for
461 the relocation is the difference between the GP value and the
462 current location; the load will always be done against a register
463 holding the current address.
465 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
466 any offset is present in the instructions, it is an offset from
467 the register to the ldah instruction. This lets us avoid any
468 stupid hackery like inventing a gp value to do partial relocation
469 against. Also unlike ECOFF, we do the whole relocation off of
470 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
471 space consuming bit, that, since all the information was present
472 in the GPDISP_HI16 reloc. */
473 HOWTO (R_ALPHA_GPDISP, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_dont, /* complain_on_overflow */
480 elf64_alpha_reloc_gpdisp, /* special_function */
482 false, /* partial_inplace */
483 0xffff, /* src_mask */
484 0xffff, /* dst_mask */
485 true), /* pcrel_offset */
487 /* A 21 bit branch. */
488 HOWTO (R_ALPHA_BRADDR, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 true, /* pc_relative */
494 complain_overflow_signed, /* complain_on_overflow */
495 0, /* special_function */
497 false, /* partial_inplace */
498 0x1fffff, /* src_mask */
499 0x1fffff, /* dst_mask */
500 true), /* pcrel_offset */
502 /* A hint for a jump to a register. */
503 HOWTO (R_ALPHA_HINT, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 true, /* pc_relative */
509 complain_overflow_dont, /* complain_on_overflow */
510 0, /* special_function */
512 false, /* partial_inplace */
513 0x3fff, /* src_mask */
514 0x3fff, /* dst_mask */
515 true), /* pcrel_offset */
517 /* 16 bit PC relative offset. */
518 HOWTO (R_ALPHA_SREL16, /* type */
520 1, /* size (0 = byte, 1 = short, 2 = long) */
522 true, /* pc_relative */
524 complain_overflow_signed, /* complain_on_overflow */
525 0, /* special_function */
527 false, /* partial_inplace */
528 0xffff, /* src_mask */
529 0xffff, /* dst_mask */
530 false), /* pcrel_offset */
532 /* 32 bit PC relative offset. */
533 HOWTO (R_ALPHA_SREL32, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 true, /* pc_relative */
539 complain_overflow_signed, /* complain_on_overflow */
540 0, /* special_function */
542 false, /* partial_inplace */
543 0xffffffff, /* src_mask */
544 0xffffffff, /* dst_mask */
545 false), /* pcrel_offset */
547 /* A 64 bit PC relative offset. */
548 HOWTO (R_ALPHA_SREL64, /* type */
550 4, /* size (0 = byte, 1 = short, 2 = long) */
552 true, /* pc_relative */
554 complain_overflow_signed, /* complain_on_overflow */
555 0, /* special_function */
557 false, /* partial_inplace */
558 MINUS_ONE, /* src_mask */
559 MINUS_ONE, /* dst_mask */
560 false), /* pcrel_offset */
562 /* Push a value on the reloc evaluation stack. */
563 /* Not implemented -- it's dumb. */
564 HOWTO (R_ALPHA_OP_PUSH, /* type */
566 0, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_dont, /* complain_on_overflow */
571 elf64_alpha_reloc_bad, /* special_function */
572 "OP_PUSH", /* name */
573 false, /* partial_inplace */
576 false), /* pcrel_offset */
578 /* Store the value from the stack at the given address. Store it in
579 a bitfield of size r_size starting at bit position r_offset. */
580 /* Not implemented -- it's dumb. */
581 HOWTO (R_ALPHA_OP_STORE, /* type */
583 4, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_dont, /* complain_on_overflow */
588 elf64_alpha_reloc_bad, /* special_function */
589 "OP_STORE", /* name */
590 false, /* partial_inplace */
592 MINUS_ONE, /* dst_mask */
593 false), /* pcrel_offset */
595 /* Subtract the reloc address from the value on the top of the
597 /* Not implemented -- it's dumb. */
598 HOWTO (R_ALPHA_OP_PSUB, /* type */
600 0, /* size (0 = byte, 1 = short, 2 = long) */
602 false, /* pc_relative */
604 complain_overflow_dont, /* complain_on_overflow */
605 elf64_alpha_reloc_bad, /* special_function */
606 "OP_PSUB", /* name */
607 false, /* partial_inplace */
610 false), /* pcrel_offset */
612 /* Shift the value on the top of the relocation stack right by the
614 /* Not implemented -- it's dumb. */
615 HOWTO (R_ALPHA_OP_PRSHIFT, /* type */
617 0, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_dont, /* complain_on_overflow */
622 elf64_alpha_reloc_bad, /* special_function */
623 "OP_PRSHIFT", /* name */
624 false, /* partial_inplace */
627 false), /* pcrel_offset */
629 /* Change the value of GP used by +r_addend until the next GPVALUE or the
630 end of the input bfd. */
631 /* Not implemented -- it's dumb. */
632 HOWTO (R_ALPHA_GPVALUE,
634 0, /* size (0 = byte, 1 = short, 2 = long) */
636 false, /* pc_relative */
638 complain_overflow_dont, /* complain_on_overflow */
639 elf64_alpha_reloc_bad, /* special_function */
640 "GPVALUE", /* name */
641 false, /* partial_inplace */
644 false), /* pcrel_offset */
646 /* The high 16 bits of the displacement from GP to the target. */
647 HOWTO (R_ALPHA_GPRELHIGH,
649 2, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_signed, /* complain_on_overflow */
654 elf64_alpha_reloc_bad, /* special_function */
655 "GPRELHIGH", /* name */
656 false, /* partial_inplace */
657 0xffff, /* src_mask */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
661 /* The low 16 bits of the displacement from GP to the target. */
662 HOWTO (R_ALPHA_GPRELLOW,
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 false, /* pc_relative */
668 complain_overflow_dont, /* complain_on_overflow */
669 elf64_alpha_reloc_bad, /* special_function */
670 "GPRELLOW", /* name */
671 false, /* partial_inplace */
672 0xffff, /* src_mask */
673 0xffff, /* dst_mask */
674 false), /* pcrel_offset */
676 /* A 16-bit displacement from the GP to the target. */
677 /* XXX: Not implemented. */
678 HOWTO (R_ALPHA_IMMED_GP_16,
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 false, /* pc_relative */
684 complain_overflow_signed, /* complain_on_overflow */
685 0, /* special_function */
686 "IMMED_GP_16", /* name */
687 false, /* partial_inplace */
688 0xffff, /* src_mask */
689 0xffff, /* dst_mask */
690 false), /* pcrel_offset */
692 /* The high bits of a 32-bit displacement from the GP to the target; the
693 low bits are supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
694 /* XXX: Not implemented. */
695 HOWTO (R_ALPHA_IMMED_GP_HI32,
697 0, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_dont, /* complain_on_overflow */
702 elf64_alpha_reloc_bad, /* special_function */
703 "IMMED_GP_HI32", /* name */
704 false, /* partial_inplace */
707 false), /* pcrel_offset */
709 /* The high bits of a 32-bit displacement to the starting address of the
710 current section (the relocation target is ignored); the low bits are
711 supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
712 /* XXX: Not implemented. */
713 HOWTO (R_ALPHA_IMMED_SCN_HI32,
715 0, /* size (0 = byte, 1 = short, 2 = long) */
717 false, /* pc_relative */
719 complain_overflow_dont, /* complain_on_overflow */
720 elf64_alpha_reloc_bad, /* special_function */
721 "IMMED_SCN_HI32", /* name */
722 false, /* partial_inplace */
725 false), /* pcrel_offset */
727 /* The high bits of a 32-bit displacement from the previous br, bsr, jsr
728 or jmp insn (as tagged by a BRADDR or HINT reloc) to the target; the
729 low bits are supplied by subsequent R_ALPHA_IMMED_LO32 relocs. */
730 /* XXX: Not implemented. */
731 HOWTO (R_ALPHA_IMMED_BR_HI32,
733 0, /* size (0 = byte, 1 = short, 2 = long) */
735 false, /* pc_relative */
737 complain_overflow_dont, /* complain_on_overflow */
738 elf64_alpha_reloc_bad, /* special_function */
739 "IMMED_BR_HI32", /* name */
740 false, /* partial_inplace */
743 false), /* pcrel_offset */
745 /* The low 16 bits of a displacement calculated in a previous HI32 reloc. */
746 /* XXX: Not implemented. */
747 HOWTO (R_ALPHA_IMMED_LO32,
749 0, /* size (0 = byte, 1 = short, 2 = long) */
751 false, /* pc_relative */
753 complain_overflow_dont, /* complain_on_overflow */
754 elf64_alpha_reloc_bad, /* special_function */
755 "IMMED_LO32", /* name */
756 false, /* partial_inplace */
759 false), /* pcrel_offset */
761 /* Misc ELF relocations. */
763 /* A dynamic relocation to copy the target into our .dynbss section. */
764 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
765 is present because every other ELF has one, but should not be used
766 because .dynbss is an ugly thing. */
773 complain_overflow_dont,
774 bfd_elf_generic_reloc,
781 /* A dynamic relocation for a .got entry. */
782 HOWTO (R_ALPHA_GLOB_DAT,
788 complain_overflow_dont,
789 bfd_elf_generic_reloc,
796 /* A dynamic relocation for a .plt entry. */
797 HOWTO (R_ALPHA_JMP_SLOT,
803 complain_overflow_dont,
804 bfd_elf_generic_reloc,
811 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
812 HOWTO (R_ALPHA_RELATIVE,
818 complain_overflow_dont,
819 bfd_elf_generic_reloc,
827 /* A relocation function which doesn't do anything. */
829 static bfd_reloc_status_type
830 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
837 char **error_message;
840 reloc->address += sec->output_offset;
844 /* A relocation function used for an unsupported reloc. */
846 static bfd_reloc_status_type
847 elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
854 char **error_message;
857 reloc->address += sec->output_offset;
858 return bfd_reloc_notsupported;
861 /* Do the work of the GPDISP relocation. */
863 static bfd_reloc_status_type
864 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
870 bfd_reloc_status_type ret = bfd_reloc_ok;
872 unsigned long i_ldah, i_lda;
874 i_ldah = bfd_get_32 (abfd, p_ldah);
875 i_lda = bfd_get_32 (abfd, p_lda);
877 /* Complain if the instructions are not correct. */
878 if (((i_ldah >> 26) & 0x3f) != 0x09
879 || ((i_lda >> 26) & 0x3f) != 0x08)
880 ret = bfd_reloc_dangerous;
882 /* Extract the user-supplied offset, mirroring the sign extensions
883 that the instructions perform. */
884 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
885 addend = (addend ^ 0x80008000) - 0x80008000;
889 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000
890 || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000)
891 ret = bfd_reloc_overflow;
893 /* compensate for the sign extension again. */
894 i_ldah = ((i_ldah & 0xffff0000)
895 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
896 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
898 bfd_put_32 (abfd, i_ldah, p_ldah);
899 bfd_put_32 (abfd, i_lda, p_lda);
904 /* The special function for the GPDISP reloc. */
906 static bfd_reloc_status_type
907 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
910 arelent *reloc_entry;
913 asection *input_section;
917 bfd_reloc_status_type ret;
918 bfd_vma gp, relocation;
919 bfd_byte *p_ldah, *p_lda;
921 /* Don't do anything if we're not doing a final link. */
924 reloc_entry->address += input_section->output_offset;
928 if (reloc_entry->address > input_section->_cooked_size ||
929 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
930 return bfd_reloc_outofrange;
932 /* The gp used in the portion of the output object to which this
933 input object belongs is cached on the input bfd. */
934 gp = _bfd_get_gp_value (abfd);
936 relocation = (input_section->output_section->vma
937 + input_section->output_offset
938 + reloc_entry->address);
940 p_ldah = (bfd_byte *) data + reloc_entry->address;
941 p_lda = p_ldah + reloc_entry->addend;
943 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
945 /* Complain if the instructions are not correct. */
946 if (ret == bfd_reloc_dangerous)
947 *err_msg = _("GPDISP relocation did not find ldah and lda instructions");
952 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
956 bfd_reloc_code_real_type bfd_reloc_val;
960 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
962 {BFD_RELOC_NONE, R_ALPHA_NONE},
963 {BFD_RELOC_32, R_ALPHA_REFLONG},
964 {BFD_RELOC_64, R_ALPHA_REFQUAD},
965 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
966 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
967 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
968 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
969 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
970 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
971 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
972 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
973 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
974 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
977 /* Given a BFD reloc type, return a HOWTO structure. */
979 static reloc_howto_type *
980 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
982 bfd_reloc_code_real_type code;
984 const struct elf_reloc_map *i, *e;
985 i = e = elf64_alpha_reloc_map;
986 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
989 if (i->bfd_reloc_val == code)
990 return &elf64_alpha_howto_table[i->elf_reloc_val];
995 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
998 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
1001 Elf64_Internal_Rela *dst;
1005 r_type = ELF64_R_TYPE(dst->r_info);
1006 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
1007 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
1010 /* These functions do relaxation for Alpha ELF.
1012 Currently I'm only handling what I can do with existing compiler
1013 and assembler support, which means no instructions are removed,
1014 though some may be nopped. At this time GCC does not emit enough
1015 information to do all of the relaxing that is possible. It will
1016 take some not small amount of work for that to happen.
1018 There are a couple of interesting papers that I once read on this
1019 subject, that I cannot find references to at the moment, that
1020 related to Alpha in particular. They are by David Wall, then of
1024 #define OP_LDAH 0x09
1025 #define INSN_JSR 0x68004000
1026 #define INSN_JSR_MASK 0xfc00c000
1030 #define INSN_UNOP 0x2fe00000
1032 struct alpha_relax_info
1037 Elf_Internal_Rela *relocs, *relend;
1038 struct bfd_link_info *link_info;
1039 boolean changed_contents;
1040 boolean changed_relocs;
1044 struct alpha_elf_link_hash_entry *h;
1045 struct alpha_elf_got_entry *gotent;
1046 unsigned char other;
1049 static Elf_Internal_Rela * elf64_alpha_relax_with_lituse
1050 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1051 Elf_Internal_Rela *irel, Elf_Internal_Rela *irelend));
1053 static boolean elf64_alpha_relax_without_lituse
1054 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1055 Elf_Internal_Rela *irel));
1057 static bfd_vma elf64_alpha_relax_opt_call
1058 PARAMS((struct alpha_relax_info *info, bfd_vma symval));
1060 static boolean elf64_alpha_relax_section
1061 PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
1064 static Elf_Internal_Rela *
1065 elf64_alpha_find_reloc_at_ofs (rel, relend, offset, type)
1066 Elf_Internal_Rela *rel, *relend;
1070 while (rel < relend)
1072 if (rel->r_offset == offset && ELF64_R_TYPE (rel->r_info) == type)
1079 static Elf_Internal_Rela *
1080 elf64_alpha_relax_with_lituse (info, symval, irel, irelend)
1081 struct alpha_relax_info *info;
1083 Elf_Internal_Rela *irel, *irelend;
1085 Elf_Internal_Rela *urel;
1086 int flags, count, i;
1087 bfd_signed_vma disp;
1090 boolean lit_reused = false;
1091 boolean all_optimized = true;
1092 unsigned int lit_insn;
1094 lit_insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1095 if (lit_insn >> 26 != OP_LDQ)
1097 ((*_bfd_error_handler)
1098 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1099 bfd_get_filename (info->abfd), info->sec->name,
1100 (unsigned long)irel->r_offset));
1104 /* Summarize how this particular LITERAL is used. */
1105 for (urel = irel+1, flags = count = 0; urel < irelend; ++urel, ++count)
1107 if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE)
1109 if (urel->r_addend >= 0 && urel->r_addend <= 3)
1110 flags |= 1 << urel->r_addend;
1113 /* A little preparation for the loop... */
1114 disp = symval - info->gp;
1115 fits16 = (disp >= -(bfd_signed_vma)0x8000 && disp < 0x8000);
1116 fits32 = (disp >= -(bfd_signed_vma)0x80000000 && disp < 0x7fff8000);
1118 for (urel = irel+1, i = 0; i < count; ++i, ++urel)
1121 insn = bfd_get_32 (info->abfd, info->contents + urel->r_offset);
1123 switch (urel->r_addend)
1125 default: /* 0 = ADDRESS FORMAT */
1126 /* This type is really just a placeholder to note that all
1127 uses cannot be optimized, but to still allow some. */
1128 all_optimized = false;
1131 case 1: /* MEM FORMAT */
1132 /* We can always optimize 16-bit displacements. */
1135 /* FIXME: sanity check the insn for mem format with
1138 /* Take the op code and dest from this insn, take the base
1139 register from the literal insn. Leave the offset alone. */
1140 insn = (insn & 0xffe00000) | (lit_insn & 0x001f0000);
1141 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1143 urel->r_addend = irel->r_addend;
1144 info->changed_relocs = true;
1146 bfd_put_32 (info->abfd, insn, info->contents + urel->r_offset);
1147 info->changed_contents = true;
1150 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1151 else if (fits32 && !(flags & ~6))
1153 /* FIXME: sanity check that lit insn Ra is mem insn Rb, and
1154 that mem_insn disp is zero. */
1156 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1158 lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000);
1159 bfd_put_32 (info->abfd, lit_insn,
1160 info->contents + irel->r_offset);
1162 info->changed_contents = true;
1164 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1166 urel->r_addend = irel->r_addend;
1167 info->changed_relocs = true;
1170 all_optimized = false;
1173 case 2: /* BYTE OFFSET FORMAT */
1174 /* We can always optimize byte instructions. */
1176 /* FIXME: sanity check the insn for byte op. Check that the
1177 literal dest reg is indeed Rb in the byte insn. */
1179 insn = (insn & ~0x001ff000) | ((symval & 7) << 13) | 0x1000;
1181 urel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1183 info->changed_relocs = true;
1185 bfd_put_32 (info->abfd, insn, info->contents + urel->r_offset);
1186 info->changed_contents = true;
1189 case 3: /* CALL FORMAT */
1191 /* If not zero, place to jump without needing pv. */
1192 bfd_vma optdest = elf64_alpha_relax_opt_call (info, symval);
1193 bfd_vma org = (info->sec->output_section->vma
1194 + info->sec->output_offset
1195 + urel->r_offset + 4);
1196 bfd_signed_vma odisp;
1198 odisp = (optdest ? optdest : symval) - org;
1199 if (odisp >= -0x400000 && odisp < 0x400000)
1201 Elf_Internal_Rela *xrel;
1203 /* Preserve branch prediction call stack when possible. */
1204 if ((insn & INSN_JSR_MASK) == INSN_JSR)
1205 insn = (OP_BSR << 26) | (insn & 0x03e00000);
1207 insn = (OP_BR << 26) | (insn & 0x03e00000);
1209 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1211 urel->r_addend = irel->r_addend;
1214 urel->r_addend += optdest - symval;
1216 all_optimized = false;
1218 bfd_put_32 (info->abfd, insn, info->contents + urel->r_offset);
1220 /* Kill any HINT reloc that might exist for this insn. */
1221 xrel = (elf64_alpha_find_reloc_at_ofs
1222 (info->relocs, info->relend, urel->r_offset,
1225 xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1227 info->changed_contents = true;
1228 info->changed_relocs = true;
1231 all_optimized = false;
1233 /* ??? If target gp == current gp we can eliminate the gp reload.
1234 This does depend on every place a gp could be reloaded will
1235 be, which currently happens for all code produced by gcc, but
1236 not necessarily by hand-coded assembly, or if sibling calls
1239 Perhaps conditionalize this on a flag being set in the target
1240 object file's header, and have gcc set it? */
1246 /* If all cases were optimized, we can reduce the use count on this
1247 got entry by one, possibly eliminating it. */
1250 info->gotent->use_count -= 1;
1251 alpha_elf_tdata (info->gotent->gotobj)->total_got_entries -= 1;
1253 alpha_elf_tdata (info->gotent->gotobj)->n_local_got_entries -= 1;
1255 /* If the literal instruction is no longer needed (it may have been
1256 reused. We can eliminate it.
1257 ??? For now, I don't want to deal with compacting the section,
1258 so just nop it out. */
1261 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1262 info->changed_relocs = true;
1264 bfd_put_32 (info->abfd, INSN_UNOP, info->contents + irel->r_offset);
1265 info->changed_contents = true;
1269 return irel + count;
1273 elf64_alpha_relax_opt_call (info, symval)
1274 struct alpha_relax_info *info;
1277 /* If the function has the same gp, and we can identify that the
1278 function does not use its function pointer, we can eliminate the
1281 /* If the symbol is marked NOPV, we are being told the function never
1282 needs its procedure value. */
1283 if (info->other == STO_ALPHA_NOPV)
1286 /* If the symbol is marked STD_GP, we are being told the function does
1287 a normal ldgp in the first two words. */
1288 else if (info->other == STO_ALPHA_STD_GPLOAD)
1291 /* Otherwise, we may be able to identify a GP load in the first two
1292 words, which we can then skip. */
1295 Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp;
1298 /* Load the relocations from the section that the target symbol is in. */
1299 if (info->sec == info->tsec)
1301 tsec_relocs = info->relocs;
1302 tsec_relend = info->relend;
1307 tsec_relocs = (_bfd_elf64_link_read_relocs
1308 (info->abfd, info->tsec, (PTR) NULL,
1309 (Elf_Internal_Rela *) NULL,
1310 info->link_info->keep_memory));
1311 if (tsec_relocs == NULL)
1313 tsec_relend = tsec_relocs + info->tsec->reloc_count;
1314 tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs);
1317 /* Recover the symbol's offset within the section. */
1318 ofs = (symval - info->tsec->output_section->vma
1319 - info->tsec->output_offset);
1321 /* Look for a GPDISP reloc. */
1322 gpdisp = (elf64_alpha_find_reloc_at_ofs
1323 (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP));
1325 if (!gpdisp || gpdisp->r_addend != 4)
1335 /* We've now determined that we can skip an initial gp load. Verify
1336 that the call and the target use the same gp. */
1337 if (info->link_info->hash->creator != info->tsec->owner->xvec
1338 || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj)
1345 elf64_alpha_relax_without_lituse (info, symval, irel)
1346 struct alpha_relax_info *info;
1348 Elf_Internal_Rela *irel;
1351 bfd_signed_vma disp;
1353 /* Get the instruction. */
1354 insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1356 if (insn >> 26 != OP_LDQ)
1358 ((*_bfd_error_handler)
1359 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1360 bfd_get_filename (info->abfd), info->sec->name,
1361 (unsigned long) irel->r_offset));
1365 /* So we aren't told much. Do what we can with the address load and
1366 fake the rest. All of the optimizations here require that the
1367 offset from the GP fit in 16 bits. */
1369 disp = symval - info->gp;
1370 if (disp < -0x8000 || disp >= 0x8000)
1373 /* On the LITERAL instruction itself, consider exchanging
1374 `ldq R,X(gp)' for `lda R,Y(gp)'. */
1376 insn = (OP_LDA << 26) | (insn & 0x03ff0000);
1377 bfd_put_32 (info->abfd, insn, info->contents + irel->r_offset);
1378 info->changed_contents = true;
1380 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), R_ALPHA_GPRELLOW);
1381 info->changed_relocs = true;
1383 /* Reduce the use count on this got entry by one, possibly
1385 info->gotent->use_count -= 1;
1386 alpha_elf_tdata (info->gotent->gotobj)->total_got_entries -= 1;
1388 alpha_elf_tdata (info->gotent->gotobj)->n_local_got_entries -= 1;
1390 /* ??? Search forward through this basic block looking for insns
1391 that use the target register. Stop after an insn modifying the
1392 register is seen, or after a branch or call.
1394 Any such memory load insn may be substituted by a load directly
1395 off the GP. This allows the memory load insn to be issued before
1396 the calculated GP register would otherwise be ready.
1398 Any such jsr insn can be replaced by a bsr if it is in range.
1400 This would mean that we'd have to _add_ relocations, the pain of
1401 which gives one pause. */
1407 elf64_alpha_relax_section (abfd, sec, link_info, again)
1410 struct bfd_link_info *link_info;
1413 Elf_Internal_Shdr *symtab_hdr;
1414 Elf_Internal_Rela *internal_relocs;
1415 Elf_Internal_Rela *free_relocs = NULL;
1416 Elf_Internal_Rela *irel, *irelend;
1417 bfd_byte *free_contents = NULL;
1418 Elf64_External_Sym *extsyms = NULL;
1419 Elf64_External_Sym *free_extsyms = NULL;
1420 struct alpha_elf_got_entry **local_got_entries;
1421 struct alpha_relax_info info;
1423 /* We are not currently changing any sizes, so only one pass. */
1426 if (link_info->relocateable
1427 || (sec->flags & SEC_RELOC) == 0
1428 || sec->reloc_count == 0)
1431 /* If this is the first time we have been called for this section,
1432 initialize the cooked size. */
1433 if (sec->_cooked_size == 0)
1434 sec->_cooked_size = sec->_raw_size;
1436 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1437 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
1439 /* Load the relocations for this section. */
1440 internal_relocs = (_bfd_elf64_link_read_relocs
1441 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
1442 link_info->keep_memory));
1443 if (internal_relocs == NULL)
1445 if (! link_info->keep_memory)
1446 free_relocs = internal_relocs;
1448 memset(&info, 0, sizeof(info));
1451 info.link_info = link_info;
1452 info.relocs = internal_relocs;
1453 info.relend = irelend = internal_relocs + sec->reloc_count;
1455 /* Find the GP for this object. */
1456 info.gotobj = alpha_elf_tdata (abfd)->gotobj;
1459 asection *sgot = alpha_elf_tdata (info.gotobj)->got;
1460 info.gp = _bfd_get_gp_value (info.gotobj);
1463 info.gp = (sgot->output_section->vma
1464 + sgot->output_offset
1466 _bfd_set_gp_value (info.gotobj, info.gp);
1470 for (irel = internal_relocs; irel < irelend; irel++)
1473 Elf_Internal_Sym isym;
1474 struct alpha_elf_got_entry *gotent;
1476 if (ELF64_R_TYPE (irel->r_info) != (int) R_ALPHA_LITERAL)
1479 /* Get the section contents. */
1480 if (info.contents == NULL)
1482 if (elf_section_data (sec)->this_hdr.contents != NULL)
1483 info.contents = elf_section_data (sec)->this_hdr.contents;
1486 info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
1487 if (info.contents == NULL)
1489 free_contents = info.contents;
1491 if (! bfd_get_section_contents (abfd, sec, info.contents,
1492 (file_ptr) 0, sec->_raw_size))
1497 /* Read this BFD's symbols if we haven't done so already. */
1498 if (extsyms == NULL)
1500 if (symtab_hdr->contents != NULL)
1501 extsyms = (Elf64_External_Sym *) symtab_hdr->contents;
1504 extsyms = ((Elf64_External_Sym *)
1505 bfd_malloc (symtab_hdr->sh_size));
1506 if (extsyms == NULL)
1508 free_extsyms = extsyms;
1509 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
1510 || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
1511 != symtab_hdr->sh_size))
1516 /* Get the value of the symbol referred to by the reloc. */
1517 if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1519 /* A local symbol. */
1520 bfd_elf64_swap_symbol_in (abfd,
1521 extsyms + ELF64_R_SYM (irel->r_info),
1523 if (isym.st_shndx == SHN_UNDEF)
1524 info.tsec = bfd_und_section_ptr;
1525 else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE)
1526 info.tsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
1527 else if (isym.st_shndx == SHN_ABS)
1528 info.tsec = bfd_abs_section_ptr;
1529 else if (isym.st_shndx == SHN_COMMON)
1530 info.tsec = bfd_com_section_ptr;
1532 continue; /* who knows. */
1535 info.other = isym.st_other;
1536 gotent = local_got_entries[ELF64_R_SYM(irel->r_info)];
1537 symval = isym.st_value;
1542 struct alpha_elf_link_hash_entry *h;
1544 indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
1545 h = alpha_elf_sym_hashes (abfd)[indx];
1546 BFD_ASSERT (h != NULL);
1548 while (h->root.root.type == bfd_link_hash_indirect
1549 || h->root.root.type == bfd_link_hash_warning)
1550 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
1552 /* We can't do anthing with undefined or dynamic symbols. */
1553 if (h->root.root.type == bfd_link_hash_undefined
1554 || h->root.root.type == bfd_link_hash_undefweak
1555 || alpha_elf_dynamic_symbol_p (&h->root, link_info))
1559 info.gotent = gotent;
1560 info.tsec = h->root.root.u.def.section;
1561 info.other = h->root.other;
1562 gotent = h->got_entries;
1563 symval = h->root.root.u.def.value;
1566 /* Search for the got entry to be used by this relocation. */
1567 while (gotent->gotobj != info.gotobj || gotent->addend != irel->r_addend)
1568 gotent = gotent->next;
1569 info.gotent = gotent;
1571 symval += info.tsec->output_section->vma + info.tsec->output_offset;
1572 symval += irel->r_addend;
1574 BFD_ASSERT(info.gotent != NULL);
1576 /* If there exist LITUSE relocations immediately following, this
1577 opens up all sorts of interesting optimizations, because we
1578 now know every location that this address load is used. */
1580 if (irel+1 < irelend && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE)
1582 irel = elf64_alpha_relax_with_lituse (&info, symval, irel, irelend);
1588 if (!elf64_alpha_relax_without_lituse (&info, symval, irel))
1593 if (!elf64_alpha_size_got_sections (abfd, link_info))
1596 if (info.changed_relocs)
1598 elf_section_data (sec)->relocs = internal_relocs;
1600 else if (free_relocs != NULL)
1605 if (info.changed_contents)
1607 elf_section_data (sec)->this_hdr.contents = info.contents;
1609 else if (free_contents != NULL)
1611 if (! link_info->keep_memory)
1612 free (free_contents);
1615 /* Cache the section contents for elf_link_input_bfd. */
1616 elf_section_data (sec)->this_hdr.contents = info.contents;
1620 if (free_extsyms != NULL)
1622 if (! link_info->keep_memory)
1623 free (free_extsyms);
1626 /* Cache the symbols for elf_link_input_bfd. */
1627 symtab_hdr->contents = extsyms;
1631 *again = info.changed_contents || info.changed_relocs;
1636 if (free_relocs != NULL)
1638 if (free_contents != NULL)
1639 free (free_contents);
1640 if (free_extsyms != NULL)
1641 free (free_extsyms);
1646 #define PLT_HEADER_SIZE 32
1647 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
1648 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
1649 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
1650 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
1652 #define PLT_ENTRY_SIZE 12
1653 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
1654 #define PLT_ENTRY_WORD2 0
1655 #define PLT_ENTRY_WORD3 0
1657 #define MAX_GOT_ENTRIES (64*1024 / 8)
1659 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
1661 /* Handle an Alpha specific section when reading an object file. This
1662 is called when elfcode.h finds a section with an unknown type.
1663 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
1667 elf64_alpha_section_from_shdr (abfd, hdr, name)
1669 Elf64_Internal_Shdr *hdr;
1674 /* There ought to be a place to keep ELF backend specific flags, but
1675 at the moment there isn't one. We just keep track of the
1676 sections by their name, instead. Fortunately, the ABI gives
1677 suggested names for all the MIPS specific sections, so we will
1678 probably get away with this. */
1679 switch (hdr->sh_type)
1681 case SHT_ALPHA_DEBUG:
1682 if (strcmp (name, ".mdebug") != 0)
1685 #ifdef ERIC_neverdef
1686 case SHT_ALPHA_REGINFO:
1687 if (strcmp (name, ".reginfo") != 0
1688 || hdr->sh_size != sizeof (Elf64_External_RegInfo))
1696 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1698 newsect = hdr->bfd_section;
1700 if (hdr->sh_type == SHT_ALPHA_DEBUG)
1702 if (! bfd_set_section_flags (abfd, newsect,
1703 (bfd_get_section_flags (abfd, newsect)
1708 #ifdef ERIC_neverdef
1709 /* For a .reginfo section, set the gp value in the tdata information
1710 from the contents of this section. We need the gp value while
1711 processing relocs, so we just get it now. */
1712 if (hdr->sh_type == SHT_ALPHA_REGINFO)
1714 Elf64_External_RegInfo ext;
1717 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
1718 (file_ptr) 0, sizeof ext))
1720 bfd_alpha_elf64_swap_reginfo_in (abfd, &ext, &s);
1721 elf_gp (abfd) = s.ri_gp_value;
1728 /* Set the correct type for an Alpha ELF section. We do this by the
1729 section name, which is a hack, but ought to work. */
1732 elf64_alpha_fake_sections (abfd, hdr, sec)
1734 Elf64_Internal_Shdr *hdr;
1737 register const char *name;
1739 name = bfd_get_section_name (abfd, sec);
1741 if (strcmp (name, ".mdebug") == 0)
1743 hdr->sh_type = SHT_ALPHA_DEBUG;
1744 /* In a shared object on Irix 5.3, the .mdebug section has an
1745 entsize of 0. FIXME: Does this matter? */
1746 if ((abfd->flags & DYNAMIC) != 0 )
1747 hdr->sh_entsize = 0;
1749 hdr->sh_entsize = 1;
1751 #ifdef ERIC_neverdef
1752 else if (strcmp (name, ".reginfo") == 0)
1754 hdr->sh_type = SHT_ALPHA_REGINFO;
1755 /* In a shared object on Irix 5.3, the .reginfo section has an
1756 entsize of 0x18. FIXME: Does this matter? */
1757 if ((abfd->flags & DYNAMIC) != 0)
1758 hdr->sh_entsize = sizeof (Elf64_External_RegInfo);
1760 hdr->sh_entsize = 1;
1762 /* Force the section size to the correct value, even if the
1763 linker thinks it is larger. The link routine below will only
1764 write out this much data for .reginfo. */
1765 hdr->sh_size = sec->_raw_size = sizeof (Elf64_External_RegInfo);
1767 else if (strcmp (name, ".hash") == 0
1768 || strcmp (name, ".dynamic") == 0
1769 || strcmp (name, ".dynstr") == 0)
1771 hdr->sh_entsize = 0;
1772 hdr->sh_info = SIZEOF_ALPHA_DYNSYM_SECNAMES;
1775 else if (strcmp (name, ".sdata") == 0
1776 || strcmp (name, ".sbss") == 0
1777 || strcmp (name, ".lit4") == 0
1778 || strcmp (name, ".lit8") == 0)
1779 hdr->sh_flags |= SHF_ALPHA_GPREL;
1784 /* Hook called by the linker routine which adds symbols from an object
1785 file. We use it to put .comm items in .sbss, and not .bss. */
1788 elf64_alpha_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1790 struct bfd_link_info *info;
1791 const Elf_Internal_Sym *sym;
1797 if (sym->st_shndx == SHN_COMMON
1798 && !info->relocateable
1799 && sym->st_size <= bfd_get_gp_size (abfd))
1801 /* Common symbols less than or equal to -G nn bytes are
1802 automatically put into .sbss. */
1804 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
1808 scomm = bfd_make_section (abfd, ".scommon");
1810 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
1812 | SEC_LINKER_CREATED)))
1817 *valp = sym->st_size;
1823 /* Create the .got section. */
1826 elf64_alpha_create_got_section(abfd, info)
1828 struct bfd_link_info *info;
1832 if (bfd_get_section_by_name (abfd, ".got"))
1835 s = bfd_make_section (abfd, ".got");
1837 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1840 | SEC_LINKER_CREATED))
1841 || !bfd_set_section_alignment (abfd, s, 3))
1844 alpha_elf_tdata (abfd)->got = s;
1849 /* Create all the dynamic sections. */
1852 elf64_alpha_create_dynamic_sections (abfd, info)
1854 struct bfd_link_info *info;
1857 struct elf_link_hash_entry *h;
1859 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1861 s = bfd_make_section (abfd, ".plt");
1863 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1866 | SEC_LINKER_CREATED
1868 || ! bfd_set_section_alignment (abfd, s, 3))
1871 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1874 if (! (_bfd_generic_link_add_one_symbol
1875 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1876 (bfd_vma) 0, (const char *) NULL, false,
1877 get_elf_backend_data (abfd)->collect,
1878 (struct bfd_link_hash_entry **) &h)))
1880 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1881 h->type = STT_OBJECT;
1884 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1887 s = bfd_make_section (abfd, ".rela.plt");
1889 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1892 | SEC_LINKER_CREATED
1894 || ! bfd_set_section_alignment (abfd, s, 3))
1897 /* We may or may not have created a .got section for this object, but
1898 we definitely havn't done the rest of the work. */
1900 if (!elf64_alpha_create_got_section (abfd, info))
1903 s = bfd_make_section(abfd, ".rela.got");
1905 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1908 | SEC_LINKER_CREATED
1910 || !bfd_set_section_alignment (abfd, s, 3))
1913 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1914 dynobj's .got section. We don't do this in the linker script
1915 because we don't want to define the symbol if we are not creating
1916 a global offset table. */
1918 if (!(_bfd_generic_link_add_one_symbol
1919 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
1920 alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
1921 false, get_elf_backend_data (abfd)->collect,
1922 (struct bfd_link_hash_entry **) &h)))
1924 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1925 h->type = STT_OBJECT;
1928 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1931 elf_hash_table (info)->hgot = h;
1936 /* Read ECOFF debugging information from a .mdebug section into a
1937 ecoff_debug_info structure. */
1940 elf64_alpha_read_ecoff_info (abfd, section, debug)
1943 struct ecoff_debug_info *debug;
1946 const struct ecoff_debug_swap *swap;
1947 char *ext_hdr = NULL;
1949 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1950 memset (debug, 0, sizeof(*debug));
1952 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
1953 if (ext_hdr == NULL && swap->external_hdr_size != 0)
1956 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
1957 swap->external_hdr_size)
1961 symhdr = &debug->symbolic_header;
1962 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
1964 /* The symbolic header contains absolute file offsets and sizes to
1966 #define READ(ptr, offset, count, size, type) \
1967 if (symhdr->count == 0) \
1968 debug->ptr = NULL; \
1971 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1972 if (debug->ptr == NULL) \
1973 goto error_return; \
1974 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1975 || (bfd_read (debug->ptr, size, symhdr->count, \
1976 abfd) != size * symhdr->count)) \
1977 goto error_return; \
1980 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
1981 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
1982 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
1983 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
1984 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
1985 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
1987 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
1988 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
1989 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
1990 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
1991 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
1995 debug->adjust = NULL;
2000 if (ext_hdr != NULL)
2002 if (debug->line != NULL)
2004 if (debug->external_dnr != NULL)
2005 free (debug->external_dnr);
2006 if (debug->external_pdr != NULL)
2007 free (debug->external_pdr);
2008 if (debug->external_sym != NULL)
2009 free (debug->external_sym);
2010 if (debug->external_opt != NULL)
2011 free (debug->external_opt);
2012 if (debug->external_aux != NULL)
2013 free (debug->external_aux);
2014 if (debug->ss != NULL)
2016 if (debug->ssext != NULL)
2017 free (debug->ssext);
2018 if (debug->external_fdr != NULL)
2019 free (debug->external_fdr);
2020 if (debug->external_rfd != NULL)
2021 free (debug->external_rfd);
2022 if (debug->external_ext != NULL)
2023 free (debug->external_ext);
2027 /* Alpha ELF local labels start with '$'. */
2030 elf64_alpha_is_local_label_name (abfd, name)
2034 return name[0] == '$';
2037 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2038 routine in order to handle the ECOFF debugging information. We
2039 still call this mips_elf_find_line because of the slot
2040 find_line_info in elf_obj_tdata is declared that way. */
2042 struct mips_elf_find_line
2044 struct ecoff_debug_info d;
2045 struct ecoff_find_line i;
2049 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2050 functionname_ptr, line_ptr)
2055 const char **filename_ptr;
2056 const char **functionname_ptr;
2057 unsigned int *line_ptr;
2061 msec = bfd_get_section_by_name (abfd, ".mdebug");
2065 struct mips_elf_find_line *fi;
2066 const struct ecoff_debug_swap * const swap =
2067 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2069 /* If we are called during a link, alpha_elf_final_link may have
2070 cleared the SEC_HAS_CONTENTS field. We force it back on here
2071 if appropriate (which it normally will be). */
2072 origflags = msec->flags;
2073 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
2074 msec->flags |= SEC_HAS_CONTENTS;
2076 fi = elf_tdata (abfd)->find_line_info;
2079 bfd_size_type external_fdr_size;
2082 struct fdr *fdr_ptr;
2084 fi = ((struct mips_elf_find_line *)
2085 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
2088 msec->flags = origflags;
2092 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
2094 msec->flags = origflags;
2098 /* Swap in the FDR information. */
2099 fi->d.fdr = ((struct fdr *)
2101 (fi->d.symbolic_header.ifdMax *
2102 sizeof (struct fdr))));
2103 if (fi->d.fdr == NULL)
2105 msec->flags = origflags;
2108 external_fdr_size = swap->external_fdr_size;
2109 fdr_ptr = fi->d.fdr;
2110 fraw_src = (char *) fi->d.external_fdr;
2111 fraw_end = (fraw_src
2112 + fi->d.symbolic_header.ifdMax * external_fdr_size);
2113 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
2114 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
2116 elf_tdata (abfd)->find_line_info = fi;
2118 /* Note that we don't bother to ever free this information.
2119 find_nearest_line is either called all the time, as in
2120 objdump -l, so the information should be saved, or it is
2121 rarely called, as in ld error messages, so the memory
2122 wasted is unimportant. Still, it would probably be a
2123 good idea for free_cached_info to throw it away. */
2126 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
2127 &fi->i, filename_ptr, functionname_ptr,
2130 msec->flags = origflags;
2134 msec->flags = origflags;
2137 /* Fall back on the generic ELF find_nearest_line routine. */
2139 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
2140 filename_ptr, functionname_ptr,
2144 /* Structure used to pass information to alpha_elf_output_extsym. */
2149 struct bfd_link_info *info;
2150 struct ecoff_debug_info *debug;
2151 const struct ecoff_debug_swap *swap;
2156 elf64_alpha_output_extsym (h, data)
2157 struct alpha_elf_link_hash_entry *h;
2160 struct extsym_info *einfo = (struct extsym_info *) data;
2162 asection *sec, *output_section;
2164 if (h->root.indx == -2)
2166 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2167 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
2168 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2169 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
2171 else if (einfo->info->strip == strip_all
2172 || (einfo->info->strip == strip_some
2173 && bfd_hash_lookup (einfo->info->keep_hash,
2174 h->root.root.root.string,
2175 false, false) == NULL))
2183 if (h->esym.ifd == -2)
2186 h->esym.cobol_main = 0;
2187 h->esym.weakext = 0;
2188 h->esym.reserved = 0;
2189 h->esym.ifd = ifdNil;
2190 h->esym.asym.value = 0;
2191 h->esym.asym.st = stGlobal;
2193 if (h->root.root.type != bfd_link_hash_defined
2194 && h->root.root.type != bfd_link_hash_defweak)
2195 h->esym.asym.sc = scAbs;
2200 sec = h->root.root.u.def.section;
2201 output_section = sec->output_section;
2203 /* When making a shared library and symbol h is the one from
2204 the another shared library, OUTPUT_SECTION may be null. */
2205 if (output_section == NULL)
2206 h->esym.asym.sc = scUndefined;
2209 name = bfd_section_name (output_section->owner, output_section);
2211 if (strcmp (name, ".text") == 0)
2212 h->esym.asym.sc = scText;
2213 else if (strcmp (name, ".data") == 0)
2214 h->esym.asym.sc = scData;
2215 else if (strcmp (name, ".sdata") == 0)
2216 h->esym.asym.sc = scSData;
2217 else if (strcmp (name, ".rodata") == 0
2218 || strcmp (name, ".rdata") == 0)
2219 h->esym.asym.sc = scRData;
2220 else if (strcmp (name, ".bss") == 0)
2221 h->esym.asym.sc = scBss;
2222 else if (strcmp (name, ".sbss") == 0)
2223 h->esym.asym.sc = scSBss;
2224 else if (strcmp (name, ".init") == 0)
2225 h->esym.asym.sc = scInit;
2226 else if (strcmp (name, ".fini") == 0)
2227 h->esym.asym.sc = scFini;
2229 h->esym.asym.sc = scAbs;
2233 h->esym.asym.reserved = 0;
2234 h->esym.asym.index = indexNil;
2237 if (h->root.root.type == bfd_link_hash_common)
2238 h->esym.asym.value = h->root.root.u.c.size;
2239 else if (h->root.root.type == bfd_link_hash_defined
2240 || h->root.root.type == bfd_link_hash_defweak)
2242 if (h->esym.asym.sc == scCommon)
2243 h->esym.asym.sc = scBss;
2244 else if (h->esym.asym.sc == scSCommon)
2245 h->esym.asym.sc = scSBss;
2247 sec = h->root.root.u.def.section;
2248 output_section = sec->output_section;
2249 if (output_section != NULL)
2250 h->esym.asym.value = (h->root.root.u.def.value
2251 + sec->output_offset
2252 + output_section->vma);
2254 h->esym.asym.value = 0;
2256 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2258 /* Set type and value for a symbol with a function stub. */
2259 h->esym.asym.st = stProc;
2260 sec = bfd_get_section_by_name (einfo->abfd, ".plt");
2262 h->esym.asym.value = 0;
2265 output_section = sec->output_section;
2266 if (output_section != NULL)
2267 h->esym.asym.value = (h->root.plt.offset
2268 + sec->output_offset
2269 + output_section->vma);
2271 h->esym.asym.value = 0;
2278 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
2279 h->root.root.root.string,
2282 einfo->failed = true;
2289 /* FIXME: Create a runtime procedure table from the .mdebug section.
2292 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
2295 struct bfd_link_info *info;
2297 struct ecoff_debug_info *debug;
2300 /* Handle dynamic relocations when doing an Alpha ELF link. */
2303 elf64_alpha_check_relocs (abfd, info, sec, relocs)
2305 struct bfd_link_info *info;
2307 const Elf_Internal_Rela *relocs;
2311 const char *rel_sec_name;
2312 Elf_Internal_Shdr *symtab_hdr;
2313 struct alpha_elf_link_hash_entry **sym_hashes;
2314 struct alpha_elf_got_entry **local_got_entries;
2315 const Elf_Internal_Rela *rel, *relend;
2318 if (info->relocateable)
2321 dynobj = elf_hash_table(info)->dynobj;
2323 elf_hash_table(info)->dynobj = dynobj = abfd;
2326 rel_sec_name = NULL;
2327 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2328 sym_hashes = alpha_elf_sym_hashes(abfd);
2329 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2332 relend = relocs + sec->reloc_count;
2333 for (rel = relocs; rel < relend; ++rel)
2335 unsigned long r_symndx, r_type;
2336 struct alpha_elf_link_hash_entry *h;
2338 r_symndx = ELF64_R_SYM (rel->r_info);
2339 if (r_symndx < symtab_hdr->sh_info)
2343 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2345 while (h->root.root.type == bfd_link_hash_indirect
2346 || h->root.root.type == bfd_link_hash_warning)
2347 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2349 h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
2351 r_type = ELF64_R_TYPE (rel->r_info);
2355 case R_ALPHA_LITERAL:
2357 struct alpha_elf_got_entry *gotent;
2362 /* Search for and possibly create a got entry. */
2363 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
2364 if (gotent->gotobj == abfd &&
2365 gotent->addend == rel->r_addend)
2370 gotent = ((struct alpha_elf_got_entry *)
2372 sizeof (struct alpha_elf_got_entry)));
2376 gotent->gotobj = abfd;
2377 gotent->addend = rel->r_addend;
2378 gotent->got_offset = -1;
2380 gotent->use_count = 1;
2382 gotent->next = h->got_entries;
2383 h->got_entries = gotent;
2385 alpha_elf_tdata (abfd)->total_got_entries++;
2388 gotent->use_count += 1;
2392 /* This is a local .got entry -- record for merge. */
2393 if (!local_got_entries)
2396 size = (symtab_hdr->sh_info
2397 * sizeof (struct alpha_elf_got_entry *));
2399 local_got_entries = ((struct alpha_elf_got_entry **)
2400 bfd_alloc (abfd, size));
2401 if (!local_got_entries)
2404 memset (local_got_entries, 0, size);
2405 alpha_elf_tdata (abfd)->local_got_entries =
2409 for (gotent = local_got_entries[ELF64_R_SYM(rel->r_info)];
2410 gotent != NULL && gotent->addend != rel->r_addend;
2411 gotent = gotent->next)
2415 gotent = ((struct alpha_elf_got_entry *)
2417 sizeof (struct alpha_elf_got_entry)));
2421 gotent->gotobj = abfd;
2422 gotent->addend = rel->r_addend;
2423 gotent->got_offset = -1;
2425 gotent->use_count = 1;
2427 gotent->next = local_got_entries[ELF64_R_SYM(rel->r_info)];
2428 local_got_entries[ELF64_R_SYM(rel->r_info)] = gotent;
2430 alpha_elf_tdata(abfd)->total_got_entries++;
2431 alpha_elf_tdata(abfd)->n_local_got_entries++;
2434 gotent->use_count += 1;
2437 /* Remember how this literal is used from its LITUSEs.
2438 This will be important when it comes to decide if we can
2439 create a .plt entry for a function symbol. */
2441 && ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE)
2446 if (rel->r_addend >= 1 && rel->r_addend <= 3)
2447 flags |= 1 << rel->r_addend;
2449 while (rel+1 < relend &&
2450 ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE);
2454 /* No LITUSEs -- presumably the address is not being
2455 loaded for nothing. */
2456 flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
2459 gotent->flags |= flags;
2462 /* Make a guess as to whether a .plt entry will be needed. */
2463 if ((h->flags |= flags) == ALPHA_ELF_LINK_HASH_LU_FUNC)
2464 h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2466 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2471 case R_ALPHA_GPDISP:
2472 case R_ALPHA_GPREL32:
2473 case R_ALPHA_GPRELHIGH:
2474 case R_ALPHA_GPRELLOW:
2475 /* We don't actually use the .got here, but the sections must
2476 be created before the linker maps input sections to output
2480 if (!elf64_alpha_create_got_section (abfd, info))
2483 /* Make sure the object's gotobj is set to itself so
2484 that we default to every object with its own .got.
2485 We'll merge .gots later once we've collected each
2487 alpha_elf_tdata(abfd)->gotobj = abfd;
2493 case R_ALPHA_SREL16:
2494 case R_ALPHA_SREL32:
2495 case R_ALPHA_SREL64:
2500 case R_ALPHA_REFLONG:
2501 case R_ALPHA_REFQUAD:
2502 if (rel_sec_name == NULL)
2504 rel_sec_name = (bfd_elf_string_from_elf_section
2505 (abfd, elf_elfheader(abfd)->e_shstrndx,
2506 elf_section_data(sec)->rel_hdr.sh_name));
2507 if (rel_sec_name == NULL)
2510 BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0
2511 && strcmp (bfd_get_section_name (abfd, sec),
2512 rel_sec_name+5) == 0);
2515 /* We need to create the section here now whether we eventually
2516 use it or not so that it gets mapped to an output section by
2517 the linker. If not used, we'll kill it in
2518 size_dynamic_sections. */
2521 sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
2524 sreloc = bfd_make_section (dynobj, rel_sec_name);
2526 || !bfd_set_section_flags (dynobj, sreloc,
2530 | SEC_LINKER_CREATED
2532 || !bfd_set_section_alignment (dynobj, sreloc, 3))
2539 /* Since we havn't seen all of the input symbols yet, we
2540 don't know whether we'll actually need a dynamic relocation
2541 entry for this reloc. So make a record of it. Once we
2542 find out if this thing needs dynamic relocation we'll
2543 expand the relocation sections by the appropriate amount. */
2545 struct alpha_elf_reloc_entry *rent;
2547 for (rent = h->reloc_entries; rent; rent = rent->next)
2548 if (rent->rtype == r_type && rent->srel == sreloc)
2553 rent = ((struct alpha_elf_reloc_entry *)
2555 sizeof (struct alpha_elf_reloc_entry)));
2559 rent->srel = sreloc;
2560 rent->rtype = r_type;
2563 rent->next = h->reloc_entries;
2564 h->reloc_entries = rent;
2569 else if (info->shared)
2571 /* If this is a shared library, we need a RELATIVE reloc. */
2572 sreloc->_raw_size += sizeof (Elf64_External_Rela);
2581 /* Adjust a symbol defined by a dynamic object and referenced by a
2582 regular object. The current definition is in some section of the
2583 dynamic object, but we're not including those sections. We have to
2584 change the definition to something the rest of the link can
2588 elf64_alpha_adjust_dynamic_symbol (info, h)
2589 struct bfd_link_info *info;
2590 struct elf_link_hash_entry *h;
2594 struct alpha_elf_link_hash_entry *ah;
2596 dynobj = elf_hash_table(info)->dynobj;
2597 ah = (struct alpha_elf_link_hash_entry *)h;
2599 /* Now that we've seen all of the input symbols, finalize our decision
2600 about whether this symbol should get a .plt entry. */
2602 if (h->root.type != bfd_link_hash_undefweak
2603 && alpha_elf_dynamic_symbol_p (h, info)
2604 && ((h->type == STT_FUNC
2605 && !(ah->flags & ALPHA_ELF_LINK_HASH_LU_ADDR))
2606 || (h->type == STT_NOTYPE
2607 && ah->flags == ALPHA_ELF_LINK_HASH_LU_FUNC))
2608 /* Don't prevent otherwise valid programs from linking by attempting
2609 to create a new .got entry somewhere. A Correct Solution would be
2610 to add a new .got section to a new object file and let it be merged
2611 somewhere later. But for now don't bother. */
2614 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2616 s = bfd_get_section_by_name(dynobj, ".plt");
2617 if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info))
2620 /* The first bit of the .plt is reserved. */
2621 if (s->_raw_size == 0)
2622 s->_raw_size = PLT_HEADER_SIZE;
2624 h->plt.offset = s->_raw_size;
2625 s->_raw_size += PLT_ENTRY_SIZE;
2627 /* If this symbol is not defined in a regular file, and we are not
2628 generating a shared library, then set the symbol to the location
2629 in the .plt. This is required to make function pointers compare
2630 equal between the normal executable and the shared library. */
2632 && h->root.type != bfd_link_hash_defweak)
2634 h->root.u.def.section = s;
2635 h->root.u.def.value = h->plt.offset;
2638 /* We also need a JMP_SLOT entry in the .rela.plt section. */
2639 s = bfd_get_section_by_name (dynobj, ".rela.plt");
2640 BFD_ASSERT (s != NULL);
2641 s->_raw_size += sizeof (Elf64_External_Rela);
2646 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2648 /* If this is a weak symbol, and there is a real definition, the
2649 processor independent code will have arranged for us to see the
2650 real definition first, and we can just use the same value. */
2651 if (h->weakdef != NULL)
2653 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2654 || h->weakdef->root.type == bfd_link_hash_defweak);
2655 h->root.u.def.section = h->weakdef->root.u.def.section;
2656 h->root.u.def.value = h->weakdef->root.u.def.value;
2660 /* This is a reference to a symbol defined by a dynamic object which
2661 is not a function. The Alpha, since it uses .got entries for all
2662 symbols even in regular objects, does not need the hackery of a
2663 .dynbss section and COPY dynamic relocations. */
2668 /* Symbol versioning can create new symbols, and make our old symbols
2669 indirect to the new ones. Consolidate the got and reloc information
2670 in these situations. */
2673 elf64_alpha_merge_ind_symbols (hi, dummy)
2674 struct alpha_elf_link_hash_entry *hi;
2677 struct alpha_elf_link_hash_entry *hs;
2679 if (hi->root.root.type != bfd_link_hash_indirect)
2683 hs = (struct alpha_elf_link_hash_entry *)hs->root.root.u.i.link;
2684 } while (hs->root.root.type == bfd_link_hash_indirect);
2686 /* Merge the flags. Whee. */
2688 hs->flags |= hi->flags;
2690 /* Merge the .got entries. Cannibalize the old symbol's list in
2691 doing so, since we don't need it anymore. */
2693 if (hs->got_entries == NULL)
2694 hs->got_entries = hi->got_entries;
2697 struct alpha_elf_got_entry *gi, *gs, *gin, *gsh;
2699 gsh = hs->got_entries;
2700 for (gi = hi->got_entries; gi ; gi = gin)
2703 for (gs = gsh; gs ; gs = gs->next)
2704 if (gi->gotobj == gs->gotobj && gi->addend == gs->addend)
2706 gi->next = hs->got_entries;
2707 hs->got_entries = gi;
2711 hi->got_entries = NULL;
2713 /* And similar for the reloc entries. */
2715 if (hs->reloc_entries == NULL)
2716 hs->reloc_entries = hi->reloc_entries;
2719 struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh;
2721 rsh = hs->reloc_entries;
2722 for (ri = hi->reloc_entries; ri ; ri = rin)
2725 for (rs = rsh; rs ; rs = rs->next)
2726 if (ri->rtype == rs->rtype)
2728 rs->count += ri->count;
2731 ri->next = hs->reloc_entries;
2732 hs->reloc_entries = ri;
2736 hi->reloc_entries = NULL;
2741 /* Is it possible to merge two object file's .got tables? */
2744 elf64_alpha_can_merge_gots (a, b)
2747 int total = alpha_elf_tdata (a)->total_got_entries;
2750 /* Trivial quick fallout test. */
2751 if (total + alpha_elf_tdata (b)->total_got_entries <= MAX_GOT_ENTRIES)
2754 /* By their nature, local .got entries cannot be merged. */
2755 if ((total += alpha_elf_tdata (b)->n_local_got_entries) > MAX_GOT_ENTRIES)
2758 /* Failing the common trivial comparison, we must effectively
2759 perform the merge. Not actually performing the merge means that
2760 we don't have to store undo information in case we fail. */
2761 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
2763 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub);
2764 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
2767 n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info;
2768 for (i = 0; i < n; ++i)
2770 struct alpha_elf_got_entry *ae, *be;
2771 struct alpha_elf_link_hash_entry *h;
2774 while (h->root.root.type == bfd_link_hash_indirect
2775 || h->root.root.type == bfd_link_hash_warning)
2776 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2778 for (be = h->got_entries; be ; be = be->next)
2780 if (be->use_count == 0)
2782 if (be->gotobj != b)
2785 for (ae = h->got_entries; ae ; ae = ae->next)
2786 if (ae->gotobj == a && ae->addend == be->addend)
2789 if (++total > MAX_GOT_ENTRIES)
2799 /* Actually merge two .got tables. */
2802 elf64_alpha_merge_gots (a, b)
2805 int total = alpha_elf_tdata (a)->total_got_entries;
2808 /* Remember local expansion. */
2810 int e = alpha_elf_tdata (b)->n_local_got_entries;
2812 alpha_elf_tdata (a)->n_local_got_entries += e;
2815 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
2817 struct alpha_elf_got_entry **local_got_entries;
2818 struct alpha_elf_link_hash_entry **hashes;
2819 Elf_Internal_Shdr *symtab_hdr;
2822 /* Let the local .got entries know they are part of a new subsegment. */
2823 local_got_entries = alpha_elf_tdata (bsub)->local_got_entries;
2824 if (local_got_entries)
2826 n = elf_tdata (bsub)->symtab_hdr.sh_info;
2827 for (i = 0; i < n; ++i)
2829 struct alpha_elf_got_entry *ent;
2830 for (ent = local_got_entries[i]; ent; ent = ent->next)
2835 /* Merge the global .got entries. */
2836 hashes = alpha_elf_sym_hashes (bsub);
2837 symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
2839 n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info;
2840 for (i = 0; i < n; ++i)
2842 struct alpha_elf_got_entry *ae, *be, **pbe, **start;
2843 struct alpha_elf_link_hash_entry *h;
2846 while (h->root.root.type == bfd_link_hash_indirect
2847 || h->root.root.type == bfd_link_hash_warning)
2848 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2850 start = &h->got_entries;
2851 for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
2853 if (be->use_count == 0)
2858 if (be->gotobj != b)
2861 for (ae = *start; ae ; ae = ae->next)
2862 if (ae->gotobj == a && ae->addend == be->addend)
2864 ae->flags |= be->flags;
2865 ae->use_count += be->use_count;
2876 alpha_elf_tdata (bsub)->gotobj = a;
2878 alpha_elf_tdata (a)->total_got_entries = total;
2880 /* Merge the two in_got chains. */
2885 while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL)
2888 alpha_elf_tdata (bsub)->in_got_link_next = b;
2892 /* Calculate the offsets for the got entries. */
2895 elf64_alpha_calc_got_offsets_for_symbol (h, arg)
2896 struct alpha_elf_link_hash_entry *h;
2899 struct alpha_elf_got_entry *gotent;
2901 for (gotent = h->got_entries; gotent; gotent = gotent->next)
2902 if (gotent->use_count > 0)
2905 = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
2907 gotent->got_offset = *plge;
2915 elf64_alpha_calc_got_offsets (info)
2916 struct bfd_link_info *info;
2918 bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
2920 /* First, zero out the .got sizes, as we may be recalculating the
2921 .got after optimizing it. */
2922 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
2923 alpha_elf_tdata(i)->got->_raw_size = 0;
2925 /* Next, fill in the offsets for all the global entries. */
2926 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
2927 elf64_alpha_calc_got_offsets_for_symbol,
2930 /* Finally, fill in the offsets for the local entries. */
2931 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
2933 bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
2936 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
2938 struct alpha_elf_got_entry **local_got_entries, *gotent;
2941 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
2942 if (!local_got_entries)
2945 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
2946 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
2947 if (gotent->use_count > 0)
2949 gotent->got_offset = got_offset;
2954 alpha_elf_tdata(i)->got->_raw_size = got_offset;
2955 alpha_elf_tdata(i)->got->_cooked_size = got_offset;
2959 /* Constructs the gots. */
2962 elf64_alpha_size_got_sections (output_bfd, info)
2964 struct bfd_link_info *info;
2966 bfd *i, *got_list, *cur_got_obj;
2967 int something_changed = 0;
2969 got_list = alpha_elf_hash_table (info)->got_list;
2971 /* On the first time through, pretend we have an existing got list
2972 consisting of all of the input files. */
2973 if (got_list == NULL)
2975 for (i = info->input_bfds; i ; i = i->link_next)
2977 bfd *this_got = alpha_elf_tdata (i)->gotobj;
2978 if (this_got == NULL)
2981 /* We are assuming no merging has yet ocurred. */
2982 BFD_ASSERT (this_got == i);
2984 if (alpha_elf_tdata (this_got)->total_got_entries > MAX_GOT_ENTRIES)
2986 /* Yikes! A single object file has too many entries. */
2987 (*_bfd_error_handler)
2988 (_("%s: .got subsegment exceeds 64K (size %d)"),
2989 bfd_get_filename (i),
2990 alpha_elf_tdata (this_got)->total_got_entries * 8);
2994 if (got_list == NULL)
2995 got_list = this_got;
2997 alpha_elf_tdata(cur_got_obj)->got_link_next = this_got;
2998 cur_got_obj = this_got;
3001 /* Strange degenerate case of no got references. */
3002 if (got_list == NULL)
3005 alpha_elf_hash_table (info)->got_list = got_list;
3007 /* Force got offsets to be recalculated. */
3008 something_changed = 1;
3011 cur_got_obj = got_list;
3012 i = alpha_elf_tdata(cur_got_obj)->got_link_next;
3015 if (elf64_alpha_can_merge_gots (cur_got_obj, i))
3017 elf64_alpha_merge_gots (cur_got_obj, i);
3018 i = alpha_elf_tdata(i)->got_link_next;
3019 alpha_elf_tdata(cur_got_obj)->got_link_next = i;
3020 something_changed = 1;
3025 i = alpha_elf_tdata(i)->got_link_next;
3029 /* Once the gots have been merged, fill in the got offsets for
3030 everything therein. */
3031 if (1 || something_changed)
3032 elf64_alpha_calc_got_offsets (info);
3038 elf64_alpha_always_size_sections (output_bfd, info)
3040 struct bfd_link_info *info;
3044 if (info->relocateable)
3047 /* First, take care of the indirect symbols created by versioning. */
3048 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3049 elf64_alpha_merge_ind_symbols,
3052 if (!elf64_alpha_size_got_sections (output_bfd, info))
3055 /* Allocate space for all of the .got subsections. */
3056 i = alpha_elf_hash_table (info)->got_list;
3057 for ( ; i ; i = alpha_elf_tdata(i)->got_link_next)
3059 asection *s = alpha_elf_tdata(i)->got;
3060 if (s->_raw_size > 0)
3062 s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
3063 if (s->contents == NULL)
3071 /* Work out the sizes of the dynamic relocation entries. */
3074 elf64_alpha_calc_dynrel_sizes (h, info)
3075 struct alpha_elf_link_hash_entry *h;
3076 struct bfd_link_info *info;
3078 /* If the symbol was defined as a common symbol in a regular object
3079 file, and there was no definition in any dynamic object, then the
3080 linker will have allocated space for the symbol in a common
3081 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3082 set. This is done for dynamic symbols in
3083 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3084 symbols, somehow. */
3085 if (((h->root.elf_link_hash_flags
3086 & (ELF_LINK_HASH_DEF_REGULAR
3087 | ELF_LINK_HASH_REF_REGULAR
3088 | ELF_LINK_HASH_DEF_DYNAMIC))
3089 == ELF_LINK_HASH_REF_REGULAR)
3090 && (h->root.root.type == bfd_link_hash_defined
3091 || h->root.root.type == bfd_link_hash_defweak)
3092 && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
3094 h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3097 /* If the symbol is dynamic, we'll need all the relocations in their
3098 natural form. If this is a shared object, and it has been forced
3099 local, we'll need the same number of RELATIVE relocations. */
3101 if (alpha_elf_dynamic_symbol_p (&h->root, info) || info->shared)
3103 struct alpha_elf_reloc_entry *relent;
3105 struct alpha_elf_got_entry *gotent;
3106 bfd_size_type count;
3109 for (relent = h->reloc_entries; relent; relent = relent->next)
3110 if (relent->rtype == R_ALPHA_REFLONG
3111 || relent->rtype == R_ALPHA_REFQUAD)
3113 relent->srel->_raw_size +=
3114 sizeof(Elf64_External_Rela) * relent->count;
3117 dynobj = elf_hash_table(info)->dynobj;
3120 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
3123 /* If we are using a .plt entry, subtract one, as the first
3124 reference uses a .rela.plt entry instead. */
3125 if (h->root.plt.offset != MINUS_ONE)
3130 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3131 BFD_ASSERT (srel != NULL);
3132 srel->_raw_size += sizeof (Elf64_External_Rela) * count;
3139 /* Set the sizes of the dynamic sections. */
3142 elf64_alpha_size_dynamic_sections (output_bfd, info)
3144 struct bfd_link_info *info;
3151 dynobj = elf_hash_table(info)->dynobj;
3152 BFD_ASSERT(dynobj != NULL);
3154 if (elf_hash_table (info)->dynamic_sections_created)
3156 /* Set the contents of the .interp section to the interpreter. */
3159 s = bfd_get_section_by_name (dynobj, ".interp");
3160 BFD_ASSERT (s != NULL);
3161 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3162 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3165 /* Now that we've seen all of the input files, we can decide which
3166 symbols need dynamic relocation entries and which don't. We've
3167 collected information in check_relocs that we can now apply to
3168 size the dynamic relocation sections. */
3169 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3170 elf64_alpha_calc_dynrel_sizes,
3173 /* When building shared libraries, each local .got entry needs a
3179 bfd_size_type count;
3181 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3182 BFD_ASSERT (srel != NULL);
3184 for (i = alpha_elf_hash_table(info)->got_list, count = 0;
3186 i = alpha_elf_tdata(i)->got_link_next)
3187 count += alpha_elf_tdata(i)->n_local_got_entries;
3189 srel->_raw_size += count * sizeof(Elf64_External_Rela);
3192 /* else we're not dynamic and by definition we don't need such things. */
3194 /* The check_relocs and adjust_dynamic_symbol entry points have
3195 determined the sizes of the various dynamic sections. Allocate
3199 for (s = dynobj->sections; s != NULL; s = s->next)
3204 if (!(s->flags & SEC_LINKER_CREATED))
3207 /* It's OK to base decisions on the section name, because none
3208 of the dynobj section names depend upon the input files. */
3209 name = bfd_get_section_name (dynobj, s);
3211 /* If we don't need this section, strip it from the output file.
3212 This is to handle .rela.bss and .rela.plt. We must create it
3213 in create_dynamic_sections, because it must be created before
3214 the linker maps input sections to output sections. The
3215 linker does that before adjust_dynamic_symbol is called, and
3216 it is that function which decides whether anything needs to
3217 go into these sections. */
3221 if (strncmp (name, ".rela", 5) == 0)
3223 strip = (s->_raw_size == 0);
3227 const char *outname;
3230 /* If this relocation section applies to a read only
3231 section, then we probably need a DT_TEXTREL entry. */
3232 outname = bfd_get_section_name (output_bfd,
3234 target = bfd_get_section_by_name (output_bfd, outname + 5);
3236 && (target->flags & SEC_READONLY) != 0
3237 && (target->flags & SEC_ALLOC) != 0)
3240 if (strcmp(name, ".rela.plt") == 0)
3243 /* We use the reloc_count field as a counter if we need
3244 to copy relocs into the output file. */
3248 else if (strcmp (name, ".plt") != 0)
3250 /* It's not one of our dynamic sections, so don't allocate space. */
3255 _bfd_strip_section_from_output (s);
3258 /* Allocate memory for the section contents. */
3259 s->contents = (bfd_byte *) bfd_zalloc(dynobj, s->_raw_size);
3260 if (s->contents == NULL && s->_raw_size != 0)
3265 if (elf_hash_table (info)->dynamic_sections_created)
3267 /* Add some entries to the .dynamic section. We fill in the
3268 values later, in elf64_alpha_finish_dynamic_sections, but we
3269 must add the entries now so that we get the correct size for
3270 the .dynamic section. The DT_DEBUG entry is filled in by the
3271 dynamic linker and used by the debugger. */
3274 if (!bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
3278 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0))
3283 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
3284 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
3285 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
3289 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
3290 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
3291 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
3292 sizeof(Elf64_External_Rela)))
3297 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
3305 /* Relocate an Alpha ELF section. */
3308 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
3309 contents, relocs, local_syms, local_sections)
3311 struct bfd_link_info *info;
3313 asection *input_section;
3315 Elf_Internal_Rela *relocs;
3316 Elf_Internal_Sym *local_syms;
3317 asection **local_sections;
3319 Elf_Internal_Shdr *symtab_hdr;
3320 Elf_Internal_Rela *rel;
3321 Elf_Internal_Rela *relend;
3322 asection *sec, *sgot, *srel, *srelgot;
3323 bfd *dynobj, *gotobj;
3326 srelgot = srel = NULL;
3327 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3328 dynobj = elf_hash_table (info)->dynobj;
3331 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
3334 /* Find the gp value for this input bfd. */
3337 gotobj = alpha_elf_tdata (input_bfd)->gotobj;
3340 sgot = alpha_elf_tdata (gotobj)->got;
3341 gp = _bfd_get_gp_value (gotobj);
3344 gp = (sgot->output_section->vma
3345 + sgot->output_offset
3347 _bfd_set_gp_value (gotobj, gp);
3352 relend = relocs + input_section->reloc_count;
3353 for (; rel < relend; rel++)
3356 reloc_howto_type *howto;
3357 unsigned long r_symndx;
3358 struct alpha_elf_link_hash_entry *h;
3359 Elf_Internal_Sym *sym;
3362 bfd_reloc_status_type r;
3364 r_type = ELF64_R_TYPE(rel->r_info);
3365 if (r_type < 0 || r_type >= (int) R_ALPHA_max)
3367 bfd_set_error (bfd_error_bad_value);
3370 howto = elf64_alpha_howto_table + r_type;
3372 r_symndx = ELF64_R_SYM(rel->r_info);
3374 if (info->relocateable)
3376 /* This is a relocateable link. We don't have to change
3377 anything, unless the reloc is against a section symbol,
3378 in which case we have to adjust according to where the
3379 section symbol winds up in the output section. */
3381 /* The symbol associated with GPDISP and LITUSE is
3382 immaterial. Only the addend is significant. */
3383 if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE)
3386 if (r_symndx < symtab_hdr->sh_info)
3388 sym = local_syms + r_symndx;
3389 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
3391 sec = local_sections[r_symndx];
3392 rel->r_addend += sec->output_offset + sym->st_value;
3399 /* This is a final link. */
3405 if (r_symndx < symtab_hdr->sh_info)
3407 sym = local_syms + r_symndx;
3408 sec = local_sections[r_symndx];
3409 relocation = (sec->output_section->vma
3410 + sec->output_offset
3415 h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info];
3417 while (h->root.root.type == bfd_link_hash_indirect
3418 || h->root.root.type == bfd_link_hash_warning)
3419 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3421 if (h->root.root.type == bfd_link_hash_defined
3422 || h->root.root.type == bfd_link_hash_defweak)
3424 sec = h->root.root.u.def.section;
3427 if ((r_type == R_ALPHA_LITERAL
3428 && elf_hash_table(info)->dynamic_sections_created
3431 || !(h->root.elf_link_hash_flags
3432 & ELF_LINK_HASH_DEF_REGULAR)))
3435 || !(h->root.elf_link_hash_flags
3436 & ELF_LINK_HASH_DEF_REGULAR))
3437 && (input_section->flags & SEC_ALLOC)
3438 && (r_type == R_ALPHA_REFLONG
3439 || r_type == R_ALPHA_REFQUAD
3440 || r_type == R_ALPHA_LITERAL)))
3442 /* In these cases, we don't need the relocation value.
3443 We check specially because in some obscure cases
3444 sec->output_section will be NULL. */
3448 /* FIXME: Are not these obscure cases simply bugs? Let's
3449 get something working and come back to this. */
3450 if (sec->output_section == NULL)
3452 #endif /* rth_notdef */
3455 relocation = (h->root.root.u.def.value
3456 + sec->output_section->vma
3457 + sec->output_offset);
3460 else if (h->root.root.type == bfd_link_hash_undefweak)
3462 else if (info->shared && !info->symbolic && !info->no_undefined)
3466 if (!((*info->callbacks->undefined_symbol)
3467 (info, h->root.root.root.string, input_bfd,
3468 input_section, rel->r_offset)))
3473 addend = rel->r_addend;
3477 case R_ALPHA_GPDISP:
3479 bfd_byte *p_ldah, *p_lda;
3481 BFD_ASSERT(gp != 0);
3483 relocation = (input_section->output_section->vma
3484 + input_section->output_offset
3487 p_ldah = contents + rel->r_offset - input_section->vma;
3488 p_lda = p_ldah + rel->r_addend;
3490 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - relocation,
3495 case R_ALPHA_OP_PUSH:
3496 case R_ALPHA_OP_STORE:
3497 case R_ALPHA_OP_PSUB:
3498 case R_ALPHA_OP_PRSHIFT:
3499 /* We hate these silly beasts. */
3502 case R_ALPHA_LITERAL:
3504 struct alpha_elf_got_entry *gotent;
3505 boolean dynamic_symbol;
3507 BFD_ASSERT(sgot != NULL);
3508 BFD_ASSERT(gp != 0);
3512 gotent = h->got_entries;
3513 dynamic_symbol = alpha_elf_dynamic_symbol_p (&h->root, info);
3517 gotent = (alpha_elf_tdata(input_bfd)->
3518 local_got_entries[r_symndx]);
3519 dynamic_symbol = false;
3522 BFD_ASSERT(gotent != NULL);
3524 while (gotent->gotobj != gotobj || gotent->addend != addend)
3525 gotent = gotent->next;
3527 BFD_ASSERT(gotent->use_count >= 1);
3529 /* Initialize the .got entry's value. */
3530 if (!(gotent->flags & ALPHA_ELF_GOT_ENTRY_RELOCS_DONE))
3532 bfd_put_64 (output_bfd, relocation+addend,
3533 sgot->contents + gotent->got_offset);
3535 /* If the symbol has been forced local, output a
3536 RELATIVE reloc, otherwise it will be handled in
3537 finish_dynamic_symbol. */
3538 if (info->shared && !dynamic_symbol)
3540 Elf_Internal_Rela outrel;
3542 BFD_ASSERT(srelgot != NULL);
3544 outrel.r_offset = (sgot->output_section->vma
3545 + sgot->output_offset
3546 + gotent->got_offset);
3547 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
3548 outrel.r_addend = 0;
3550 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3551 ((Elf64_External_Rela *)
3553 + srelgot->reloc_count++);
3554 BFD_ASSERT (sizeof(Elf64_External_Rela)
3555 * srelgot->reloc_count
3556 <= srelgot->_cooked_size);
3559 gotent->flags |= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE;
3562 /* Figure the gprel relocation. */
3564 relocation = (sgot->output_section->vma
3565 + sgot->output_offset
3566 + gotent->got_offset);
3569 /* overflow handled by _bfd_final_link_relocate */
3572 case R_ALPHA_GPREL32:
3573 case R_ALPHA_GPRELLOW:
3574 BFD_ASSERT(gp != 0);
3578 case R_ALPHA_GPRELHIGH:
3579 BFD_ASSERT(gp != 0);
3581 relocation += addend;
3583 relocation = (((bfd_signed_vma) relocation >> 16)
3584 + ((relocation >> 15) & 1));
3587 case R_ALPHA_BRADDR:
3589 /* The regular PC-relative stuff measures from the start of
3590 the instruction rather than the end. */
3594 case R_ALPHA_REFLONG:
3595 case R_ALPHA_REFQUAD:
3597 Elf_Internal_Rela outrel;
3600 /* Careful here to remember RELATIVE relocations for global
3601 variables for symbolic shared objects. */
3603 if (h && alpha_elf_dynamic_symbol_p (&h->root, info))
3605 BFD_ASSERT(h->root.dynindx != -1);
3606 outrel.r_info = ELF64_R_INFO(h->root.dynindx, r_type);
3607 outrel.r_addend = addend;
3608 addend = 0, relocation = 0;
3610 else if (info->shared)
3612 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
3613 outrel.r_addend = 0;
3622 name = (bfd_elf_string_from_elf_section
3623 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
3624 elf_section_data(input_section)->rel_hdr.sh_name));
3625 BFD_ASSERT(name != NULL);
3627 srel = bfd_get_section_by_name (dynobj, name);
3628 BFD_ASSERT(srel != NULL);
3633 if (elf_section_data (input_section)->stab_info == NULL)
3634 outrel.r_offset = rel->r_offset;
3639 off = (_bfd_stab_section_offset
3640 (output_bfd, &elf_hash_table (info)->stab_info,
3642 &elf_section_data (input_section)->stab_info,
3644 if (off == (bfd_vma) -1)
3646 outrel.r_offset = off;
3650 outrel.r_offset += (input_section->output_section->vma
3651 + input_section->output_offset);
3653 memset (&outrel, 0, sizeof outrel);
3655 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3656 ((Elf64_External_Rela *)
3658 + srel->reloc_count++);
3659 BFD_ASSERT (sizeof(Elf64_External_Rela) * srel->reloc_count
3660 <= srel->_cooked_size);
3666 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3667 contents, rel->r_offset, relocation,
3677 case bfd_reloc_overflow:
3682 name = h->root.root.root.string;
3685 name = (bfd_elf_string_from_elf_section
3686 (input_bfd, symtab_hdr->sh_link, sym->st_name));
3690 name = bfd_section_name (input_bfd, sec);
3692 if (! ((*info->callbacks->reloc_overflow)
3693 (info, name, howto->name, (bfd_vma) 0,
3694 input_bfd, input_section, rel->r_offset)))
3700 case bfd_reloc_outofrange:
3708 /* Finish up dynamic symbol handling. We set the contents of various
3709 dynamic sections here. */
3712 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
3714 struct bfd_link_info *info;
3715 struct elf_link_hash_entry *h;
3716 Elf_Internal_Sym *sym;
3718 bfd *dynobj = elf_hash_table(info)->dynobj;
3720 if (h->plt.offset != MINUS_ONE)
3722 /* Fill in the .plt entry for this symbol. */
3723 asection *splt, *sgot, *srel;
3724 Elf_Internal_Rela outrel;
3725 bfd_vma got_addr, plt_addr;
3727 struct alpha_elf_got_entry *gotent;
3729 BFD_ASSERT (h->dynindx != -1);
3731 /* The first .got entry will be updated by the .plt with the
3732 address of the target function. */
3733 gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
3734 BFD_ASSERT (gotent && gotent->addend == 0);
3736 splt = bfd_get_section_by_name (dynobj, ".plt");
3737 BFD_ASSERT (splt != NULL);
3738 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
3739 BFD_ASSERT (srel != NULL);
3740 sgot = alpha_elf_tdata (gotent->gotobj)->got;
3741 BFD_ASSERT (sgot != NULL);
3743 got_addr = (sgot->output_section->vma
3744 + sgot->output_offset
3745 + gotent->got_offset);
3746 plt_addr = (splt->output_section->vma
3747 + splt->output_offset
3750 plt_index = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
3752 /* Fill in the entry in the procedure linkage table. */
3754 unsigned insn1, insn2, insn3;
3756 insn1 = PLT_ENTRY_WORD1 | ((-(h->plt.offset + 4) >> 2) & 0x1fffff);
3757 insn2 = PLT_ENTRY_WORD2;
3758 insn3 = PLT_ENTRY_WORD3;
3760 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt.offset);
3761 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt.offset + 4);
3762 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt.offset + 8);
3765 /* Fill in the entry in the .rela.plt section. */
3766 outrel.r_offset = got_addr;
3767 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
3768 outrel.r_addend = 0;
3770 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3771 ((Elf64_External_Rela *)srel->contents
3774 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
3776 /* Mark the symbol as undefined, rather than as defined in the
3777 .plt section. Leave the value alone. */
3778 sym->st_shndx = SHN_UNDEF;
3781 /* Fill in the entries in the .got. */
3782 bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
3784 /* Subsequent .got entries will continue to bounce through the .plt. */
3787 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3788 BFD_ASSERT (! info->shared || srel != NULL);
3790 gotent = gotent->next;
3793 sgot = alpha_elf_tdata(gotent->gotobj)->got;
3794 BFD_ASSERT(sgot != NULL);
3795 BFD_ASSERT(gotent->addend == 0);
3797 bfd_put_64 (output_bfd, plt_addr,
3798 sgot->contents + gotent->got_offset);
3802 outrel.r_offset = (sgot->output_section->vma
3803 + sgot->output_offset
3804 + gotent->got_offset);
3805 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
3806 outrel.r_addend = 0;
3808 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3809 ((Elf64_External_Rela *)
3811 + srel->reloc_count++);
3812 BFD_ASSERT (sizeof(Elf64_External_Rela) * srel->reloc_count
3813 <= srel->_cooked_size);
3816 gotent = gotent->next;
3818 while (gotent != NULL);
3821 else if (alpha_elf_dynamic_symbol_p (h, info))
3823 /* Fill in the dynamic relocations for this symbol's .got entries. */
3825 Elf_Internal_Rela outrel;
3826 struct alpha_elf_got_entry *gotent;
3828 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3829 BFD_ASSERT (srel != NULL);
3831 outrel.r_info = ELF64_R_INFO (h->dynindx, R_ALPHA_GLOB_DAT);
3832 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
3834 gotent = gotent->next)
3836 asection *sgot = alpha_elf_tdata (gotent->gotobj)->got;
3837 outrel.r_offset = (sgot->output_section->vma
3838 + sgot->output_offset
3839 + gotent->got_offset);
3840 outrel.r_addend = gotent->addend;
3842 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3843 ((Elf64_External_Rela *)srel->contents
3844 + srel->reloc_count++));
3845 BFD_ASSERT (sizeof(Elf64_External_Rela) * srel->reloc_count
3846 <= srel->_cooked_size);
3850 /* Mark some specially defined symbols as absolute. */
3851 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3852 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3853 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3854 sym->st_shndx = SHN_ABS;
3859 /* Finish up the dynamic sections. */
3862 elf64_alpha_finish_dynamic_sections (output_bfd, info)
3864 struct bfd_link_info *info;
3869 dynobj = elf_hash_table (info)->dynobj;
3870 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3872 if (elf_hash_table (info)->dynamic_sections_created)
3875 Elf64_External_Dyn *dyncon, *dynconend;
3877 splt = bfd_get_section_by_name (dynobj, ".plt");
3878 BFD_ASSERT (splt != NULL && sdyn != NULL);
3880 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3881 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3882 for (; dyncon < dynconend; dyncon++)
3884 Elf_Internal_Dyn dyn;
3888 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3903 /* My interpretation of the TIS v1.1 ELF document indicates
3904 that RELASZ should not include JMPREL. This is not what
3905 the rest of the BFD does. It is, however, what the
3906 glibc ld.so wants. Do this fixup here until we found
3907 out who is right. */
3908 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3912 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
3917 s = bfd_get_section_by_name (output_bfd, name);
3918 dyn.d_un.d_ptr = (s ? s->vma : 0);
3922 s = bfd_get_section_by_name (output_bfd, name);
3924 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
3928 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3931 /* Initialize the PLT0 entry */
3932 if (splt->_raw_size > 0)
3934 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
3935 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
3936 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
3937 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
3939 /* The next two words will be filled in by ld.so */
3940 bfd_put_64 (output_bfd, 0, splt->contents + 16);
3941 bfd_put_64 (output_bfd, 0, splt->contents + 24);
3943 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
3951 /* We need to use a special link routine to handle the .reginfo and
3952 the .mdebug sections. We need to merge all instances of these
3953 sections together, not write them all out sequentially. */
3956 elf64_alpha_final_link (abfd, info)
3958 struct bfd_link_info *info;
3961 struct bfd_link_order *p;
3962 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
3963 struct ecoff_debug_info debug;
3964 const struct ecoff_debug_swap *swap
3965 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3966 HDRR *symhdr = &debug.symbolic_header;
3967 PTR mdebug_handle = NULL;
3972 (*info->callbacks->warning)
3973 (info, _("using multiple gp values"), (char *) NULL,
3974 output_bfd, (asection *) NULL, (bfd_vma) 0);
3978 /* Go through the sections and collect the .reginfo and .mdebug
3982 gptab_data_sec = NULL;
3983 gptab_bss_sec = NULL;
3984 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3986 #ifdef ERIC_neverdef
3987 if (strcmp (o->name, ".reginfo") == 0)
3989 memset (®info, 0, sizeof reginfo);
3991 /* We have found the .reginfo section in the output file.
3992 Look through all the link_orders comprising it and merge
3993 the information together. */
3994 for (p = o->link_order_head;
3995 p != (struct bfd_link_order *) NULL;
3998 asection *input_section;
4000 Elf64_External_RegInfo ext;
4003 if (p->type != bfd_indirect_link_order)
4005 if (p->type == bfd_fill_link_order)
4010 input_section = p->u.indirect.section;
4011 input_bfd = input_section->owner;
4013 /* The linker emulation code has probably clobbered the
4014 size to be zero bytes. */
4015 if (input_section->_raw_size == 0)
4016 input_section->_raw_size = sizeof (Elf64_External_RegInfo);
4018 if (! bfd_get_section_contents (input_bfd, input_section,
4024 bfd_alpha_elf64_swap_reginfo_in (input_bfd, &ext, &sub);
4026 reginfo.ri_gprmask |= sub.ri_gprmask;
4027 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
4028 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
4029 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
4030 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
4032 /* ri_gp_value is set by the function
4033 alpha_elf_section_processing when the section is
4034 finally written out. */
4036 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4037 elf_link_input_bfd ignores this section. */
4038 input_section->flags &=~ SEC_HAS_CONTENTS;
4041 /* Force the section size to the value we want. */
4042 o->_raw_size = sizeof (Elf64_External_RegInfo);
4044 /* Skip this section later on (I don't think this currently
4045 matters, but someday it might). */
4046 o->link_order_head = (struct bfd_link_order *) NULL;
4052 if (strcmp (o->name, ".mdebug") == 0)
4054 struct extsym_info einfo;
4056 /* We have found the .mdebug section in the output file.
4057 Look through all the link_orders comprising it and merge
4058 the information together. */
4059 symhdr->magic = swap->sym_magic;
4060 /* FIXME: What should the version stamp be? */
4062 symhdr->ilineMax = 0;
4066 symhdr->isymMax = 0;
4067 symhdr->ioptMax = 0;
4068 symhdr->iauxMax = 0;
4070 symhdr->issExtMax = 0;
4073 symhdr->iextMax = 0;
4075 /* We accumulate the debugging information itself in the
4076 debug_info structure. */
4078 debug.external_dnr = NULL;
4079 debug.external_pdr = NULL;
4080 debug.external_sym = NULL;
4081 debug.external_opt = NULL;
4082 debug.external_aux = NULL;
4084 debug.ssext = debug.ssext_end = NULL;
4085 debug.external_fdr = NULL;
4086 debug.external_rfd = NULL;
4087 debug.external_ext = debug.external_ext_end = NULL;
4089 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
4090 if (mdebug_handle == (PTR) NULL)
4099 static const char * const name[] =
4101 ".text", ".init", ".fini", ".data",
4102 ".rodata", ".sdata", ".sbss", ".bss"
4104 static const int sc[] = { scText, scInit, scFini, scData,
4105 scRData, scSData, scSBss, scBss };
4108 esym.cobol_main = 0;
4112 esym.asym.iss = issNil;
4113 esym.asym.st = stLocal;
4114 esym.asym.reserved = 0;
4115 esym.asym.index = indexNil;
4116 for (i = 0; i < 8; i++)
4118 esym.asym.sc = sc[i];
4119 s = bfd_get_section_by_name (abfd, name[i]);
4122 esym.asym.value = s->vma;
4123 last = s->vma + s->_raw_size;
4126 esym.asym.value = last;
4128 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
4134 for (p = o->link_order_head;
4135 p != (struct bfd_link_order *) NULL;
4138 asection *input_section;
4140 const struct ecoff_debug_swap *input_swap;
4141 struct ecoff_debug_info input_debug;
4145 if (p->type != bfd_indirect_link_order)
4147 if (p->type == bfd_fill_link_order)
4152 input_section = p->u.indirect.section;
4153 input_bfd = input_section->owner;
4155 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
4156 || (get_elf_backend_data (input_bfd)
4157 ->elf_backend_ecoff_debug_swap) == NULL)
4159 /* I don't know what a non ALPHA ELF bfd would be
4160 doing with a .mdebug section, but I don't really
4161 want to deal with it. */
4165 input_swap = (get_elf_backend_data (input_bfd)
4166 ->elf_backend_ecoff_debug_swap);
4168 BFD_ASSERT (p->size == input_section->_raw_size);
4170 /* The ECOFF linking code expects that we have already
4171 read in the debugging information and set up an
4172 ecoff_debug_info structure, so we do that now. */
4173 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
4177 if (! (bfd_ecoff_debug_accumulate
4178 (mdebug_handle, abfd, &debug, swap, input_bfd,
4179 &input_debug, input_swap, info)))
4182 /* Loop through the external symbols. For each one with
4183 interesting information, try to find the symbol in
4184 the linker global hash table and save the information
4185 for the output external symbols. */
4186 eraw_src = input_debug.external_ext;
4187 eraw_end = (eraw_src
4188 + (input_debug.symbolic_header.iextMax
4189 * input_swap->external_ext_size));
4191 eraw_src < eraw_end;
4192 eraw_src += input_swap->external_ext_size)
4196 struct alpha_elf_link_hash_entry *h;
4198 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
4199 if (ext.asym.sc == scNil
4200 || ext.asym.sc == scUndefined
4201 || ext.asym.sc == scSUndefined)
4204 name = input_debug.ssext + ext.asym.iss;
4205 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
4206 name, false, false, true);
4207 if (h == NULL || h->esym.ifd != -2)
4213 < input_debug.symbolic_header.ifdMax);
4214 ext.ifd = input_debug.ifdmap[ext.ifd];
4220 /* Free up the information we just read. */
4221 free (input_debug.line);
4222 free (input_debug.external_dnr);
4223 free (input_debug.external_pdr);
4224 free (input_debug.external_sym);
4225 free (input_debug.external_opt);
4226 free (input_debug.external_aux);
4227 free (input_debug.ss);
4228 free (input_debug.ssext);
4229 free (input_debug.external_fdr);
4230 free (input_debug.external_rfd);
4231 free (input_debug.external_ext);
4233 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4234 elf_link_input_bfd ignores this section. */
4235 input_section->flags &=~ SEC_HAS_CONTENTS;
4238 #ifdef ERIC_neverdef
4241 /* Create .rtproc section. */
4242 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
4243 if (rtproc_sec == NULL)
4245 flagword flags = (SEC_HAS_CONTENTS
4247 | SEC_LINKER_CREATED
4250 rtproc_sec = bfd_make_section (abfd, ".rtproc");
4251 if (rtproc_sec == NULL
4252 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
4253 || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
4257 if (! alpha_elf_create_procedure_table (mdebug_handle, abfd,
4258 info, rtproc_sec, &debug))
4264 /* Build the external symbol information. */
4267 einfo.debug = &debug;
4269 einfo.failed = false;
4270 elf_link_hash_traverse (elf_hash_table (info),
4271 elf64_alpha_output_extsym,
4276 /* Set the size of the .mdebug section. */
4277 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
4279 /* Skip this section later on (I don't think this currently
4280 matters, but someday it might). */
4281 o->link_order_head = (struct bfd_link_order *) NULL;
4286 #ifdef ERIC_neverdef
4287 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
4289 const char *subname;
4292 Elf64_External_gptab *ext_tab;
4295 /* The .gptab.sdata and .gptab.sbss sections hold
4296 information describing how the small data area would
4297 change depending upon the -G switch. These sections
4298 not used in executables files. */
4299 if (! info->relocateable)
4303 for (p = o->link_order_head;
4304 p != (struct bfd_link_order *) NULL;
4307 asection *input_section;
4309 if (p->type != bfd_indirect_link_order)
4311 if (p->type == bfd_fill_link_order)
4316 input_section = p->u.indirect.section;
4318 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4319 elf_link_input_bfd ignores this section. */
4320 input_section->flags &=~ SEC_HAS_CONTENTS;
4323 /* Skip this section later on (I don't think this
4324 currently matters, but someday it might). */
4325 o->link_order_head = (struct bfd_link_order *) NULL;
4327 /* Really remove the section. */
4328 for (secpp = &abfd->sections;
4330 secpp = &(*secpp)->next)
4332 *secpp = (*secpp)->next;
4333 --abfd->section_count;
4338 /* There is one gptab for initialized data, and one for
4339 uninitialized data. */
4340 if (strcmp (o->name, ".gptab.sdata") == 0)
4342 else if (strcmp (o->name, ".gptab.sbss") == 0)
4346 (*_bfd_error_handler)
4347 (_("%s: illegal section name `%s'"),
4348 bfd_get_filename (abfd), o->name);
4349 bfd_set_error (bfd_error_nonrepresentable_section);
4353 /* The linker script always combines .gptab.data and
4354 .gptab.sdata into .gptab.sdata, and likewise for
4355 .gptab.bss and .gptab.sbss. It is possible that there is
4356 no .sdata or .sbss section in the output file, in which
4357 case we must change the name of the output section. */
4358 subname = o->name + sizeof ".gptab" - 1;
4359 if (bfd_get_section_by_name (abfd, subname) == NULL)
4361 if (o == gptab_data_sec)
4362 o->name = ".gptab.data";
4364 o->name = ".gptab.bss";
4365 subname = o->name + sizeof ".gptab" - 1;
4366 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
4369 /* Set up the first entry. */
4371 tab = (Elf64_gptab *) bfd_malloc (c * sizeof (Elf64_gptab));
4374 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
4375 tab[0].gt_header.gt_unused = 0;
4377 /* Combine the input sections. */
4378 for (p = o->link_order_head;
4379 p != (struct bfd_link_order *) NULL;
4382 asection *input_section;
4386 bfd_size_type gpentry;
4388 if (p->type != bfd_indirect_link_order)
4390 if (p->type == bfd_fill_link_order)
4395 input_section = p->u.indirect.section;
4396 input_bfd = input_section->owner;
4398 /* Combine the gptab entries for this input section one
4399 by one. We know that the input gptab entries are
4400 sorted by ascending -G value. */
4401 size = bfd_section_size (input_bfd, input_section);
4403 for (gpentry = sizeof (Elf64_External_gptab);
4405 gpentry += sizeof (Elf64_External_gptab))
4407 Elf64_External_gptab ext_gptab;
4408 Elf64_gptab int_gptab;
4414 if (! (bfd_get_section_contents
4415 (input_bfd, input_section, (PTR) &ext_gptab,
4416 gpentry, sizeof (Elf64_External_gptab))))
4422 bfd_alpha_elf64_swap_gptab_in (input_bfd, &ext_gptab,
4424 val = int_gptab.gt_entry.gt_g_value;
4425 add = int_gptab.gt_entry.gt_bytes - last;
4428 for (look = 1; look < c; look++)
4430 if (tab[look].gt_entry.gt_g_value >= val)
4431 tab[look].gt_entry.gt_bytes += add;
4433 if (tab[look].gt_entry.gt_g_value == val)
4439 Elf64_gptab *new_tab;
4442 /* We need a new table entry. */
4443 new_tab = ((Elf64_gptab *)
4444 bfd_realloc ((PTR) tab,
4445 (c + 1) * sizeof (Elf64_gptab)));
4446 if (new_tab == NULL)
4452 tab[c].gt_entry.gt_g_value = val;
4453 tab[c].gt_entry.gt_bytes = add;
4455 /* Merge in the size for the next smallest -G
4456 value, since that will be implied by this new
4459 for (look = 1; look < c; look++)
4461 if (tab[look].gt_entry.gt_g_value < val
4463 || (tab[look].gt_entry.gt_g_value
4464 > tab[max].gt_entry.gt_g_value)))
4468 tab[c].gt_entry.gt_bytes +=
4469 tab[max].gt_entry.gt_bytes;
4474 last = int_gptab.gt_entry.gt_bytes;
4477 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4478 elf_link_input_bfd ignores this section. */
4479 input_section->flags &=~ SEC_HAS_CONTENTS;
4482 /* The table must be sorted by -G value. */
4484 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
4486 /* Swap out the table. */
4487 ext_tab = ((Elf64_External_gptab *)
4488 bfd_alloc (abfd, c * sizeof (Elf64_External_gptab)));
4489 if (ext_tab == NULL)
4495 for (i = 0; i < c; i++)
4496 bfd_alpha_elf64_swap_gptab_out (abfd, tab + i, ext_tab + i);
4499 o->_raw_size = c * sizeof (Elf64_External_gptab);
4500 o->contents = (bfd_byte *) ext_tab;
4502 /* Skip this section later on (I don't think this currently
4503 matters, but someday it might). */
4504 o->link_order_head = (struct bfd_link_order *) NULL;
4510 /* Invoke the regular ELF backend linker to do all the work. */
4511 if (! bfd_elf64_bfd_final_link (abfd, info))
4514 /* Now write out the computed sections. */
4516 /* The .got subsections... */
4518 bfd *i, *dynobj = elf_hash_table(info)->dynobj;
4519 for (i = alpha_elf_hash_table(info)->got_list;
4521 i = alpha_elf_tdata(i)->got_link_next)
4525 /* elf_bfd_final_link already did everything in dynobj. */
4529 sgot = alpha_elf_tdata(i)->got;
4530 if (! bfd_set_section_contents (abfd, sgot->output_section,
4531 sgot->contents, sgot->output_offset,
4537 #ifdef ERIC_neverdef
4538 if (reginfo_sec != (asection *) NULL)
4540 Elf64_External_RegInfo ext;
4542 bfd_alpha_elf64_swap_reginfo_out (abfd, ®info, &ext);
4543 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
4544 (file_ptr) 0, sizeof ext))
4549 if (mdebug_sec != (asection *) NULL)
4551 BFD_ASSERT (abfd->output_has_begun);
4552 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
4554 mdebug_sec->filepos))
4557 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
4560 if (gptab_data_sec != (asection *) NULL)
4562 if (! bfd_set_section_contents (abfd, gptab_data_sec,
4563 gptab_data_sec->contents,
4565 gptab_data_sec->_raw_size))
4569 if (gptab_bss_sec != (asection *) NULL)
4571 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
4572 gptab_bss_sec->contents,
4574 gptab_bss_sec->_raw_size))
4581 /* ECOFF swapping routines. These are used when dealing with the
4582 .mdebug section, which is in the ECOFF debugging format. Copied
4583 from elf32-mips.c. */
4584 static const struct ecoff_debug_swap
4585 elf64_alpha_ecoff_debug_swap =
4587 /* Symbol table magic number. */
4589 /* Alignment of debugging information. E.g., 4. */
4591 /* Sizes of external symbolic information. */
4592 sizeof (struct hdr_ext),
4593 sizeof (struct dnr_ext),
4594 sizeof (struct pdr_ext),
4595 sizeof (struct sym_ext),
4596 sizeof (struct opt_ext),
4597 sizeof (struct fdr_ext),
4598 sizeof (struct rfd_ext),
4599 sizeof (struct ext_ext),
4600 /* Functions to swap in external symbolic data. */
4609 _bfd_ecoff_swap_tir_in,
4610 _bfd_ecoff_swap_rndx_in,
4611 /* Functions to swap out external symbolic data. */
4620 _bfd_ecoff_swap_tir_out,
4621 _bfd_ecoff_swap_rndx_out,
4622 /* Function to read in symbolic data. */
4623 elf64_alpha_read_ecoff_info
4626 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
4627 #define TARGET_LITTLE_NAME "elf64-alpha"
4628 #define ELF_ARCH bfd_arch_alpha
4629 #define ELF_MACHINE_CODE EM_ALPHA
4630 #define ELF_MAXPAGESIZE 0x10000
4632 #define bfd_elf64_bfd_link_hash_table_create \
4633 elf64_alpha_bfd_link_hash_table_create
4635 #define bfd_elf64_bfd_reloc_type_lookup \
4636 elf64_alpha_bfd_reloc_type_lookup
4637 #define elf_info_to_howto \
4638 elf64_alpha_info_to_howto
4640 #define bfd_elf64_mkobject \
4641 elf64_alpha_mkobject
4642 #define elf_backend_object_p \
4643 elf64_alpha_object_p
4645 #define elf_backend_section_from_shdr \
4646 elf64_alpha_section_from_shdr
4647 #define elf_backend_fake_sections \
4648 elf64_alpha_fake_sections
4650 #define bfd_elf64_bfd_is_local_label_name \
4651 elf64_alpha_is_local_label_name
4652 #define bfd_elf64_find_nearest_line \
4653 elf64_alpha_find_nearest_line
4654 #define bfd_elf64_bfd_relax_section \
4655 elf64_alpha_relax_section
4657 #define elf_backend_add_symbol_hook \
4658 elf64_alpha_add_symbol_hook
4659 #define elf_backend_check_relocs \
4660 elf64_alpha_check_relocs
4661 #define elf_backend_create_dynamic_sections \
4662 elf64_alpha_create_dynamic_sections
4663 #define elf_backend_adjust_dynamic_symbol \
4664 elf64_alpha_adjust_dynamic_symbol
4665 #define elf_backend_always_size_sections \
4666 elf64_alpha_always_size_sections
4667 #define elf_backend_size_dynamic_sections \
4668 elf64_alpha_size_dynamic_sections
4669 #define elf_backend_relocate_section \
4670 elf64_alpha_relocate_section
4671 #define elf_backend_finish_dynamic_symbol \
4672 elf64_alpha_finish_dynamic_symbol
4673 #define elf_backend_finish_dynamic_sections \
4674 elf64_alpha_finish_dynamic_sections
4675 #define bfd_elf64_bfd_final_link \
4676 elf64_alpha_final_link
4678 #define elf_backend_ecoff_debug_swap \
4679 &elf64_alpha_ecoff_debug_swap
4682 * A few constants that determine how the .plt section is set up.
4684 #define elf_backend_want_got_plt 0
4685 #define elf_backend_plt_readonly 0
4686 #define elf_backend_want_plt_sym 1
4687 #define elf_backend_got_header_size 0
4688 #define elf_backend_plt_header_size PLT_HEADER_SIZE
4690 #include "elf64-target.h"