1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Richard Henderson <rth@tamu.edu>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* We need a published ABI spec for this. Until one comes out, don't
23 assume this'll remain unchanged forever. */
30 #include "elf/alpha.h"
34 #define NO_COFF_RELOCS
35 #define NO_COFF_SYMBOLS
36 #define NO_COFF_LINENOS
38 /* Get the ECOFF swapping routines. Needed for the debug information. */
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
43 #include "coff/alpha.h"
48 #include "ecoffswap.h"
50 static int alpha_elf_dynamic_symbol_p
51 PARAMS((struct elf_link_hash_entry *, struct bfd_link_info *));
52 static struct bfd_hash_entry * elf64_alpha_link_hash_newfunc
53 PARAMS((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
54 static struct bfd_link_hash_table * elf64_alpha_bfd_link_hash_table_create
57 static bfd_reloc_status_type elf64_alpha_reloc_nil
58 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
59 static bfd_reloc_status_type elf64_alpha_reloc_bad
60 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
61 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
62 PARAMS((bfd *, bfd_vma, bfd_byte *, bfd_byte *));
63 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
64 PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
66 static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup
67 PARAMS((bfd *, bfd_reloc_code_real_type));
68 static void elf64_alpha_info_to_howto
69 PARAMS((bfd *, arelent *, Elf64_Internal_Rela *));
71 static boolean elf64_alpha_mkobject
73 static boolean elf64_alpha_object_p
75 static boolean elf64_alpha_section_from_shdr
76 PARAMS((bfd *, Elf64_Internal_Shdr *, char *));
77 static boolean elf64_alpha_section_flags
78 PARAMS((flagword *, Elf64_Internal_Shdr *));
79 static boolean elf64_alpha_fake_sections
80 PARAMS((bfd *, Elf64_Internal_Shdr *, asection *));
81 static boolean elf64_alpha_create_got_section
82 PARAMS((bfd *, struct bfd_link_info *));
83 static boolean elf64_alpha_create_dynamic_sections
84 PARAMS((bfd *, struct bfd_link_info *));
86 static boolean elf64_alpha_read_ecoff_info
87 PARAMS((bfd *, asection *, struct ecoff_debug_info *));
88 static boolean elf64_alpha_is_local_label_name
89 PARAMS((bfd *, const char *));
90 static boolean elf64_alpha_find_nearest_line
91 PARAMS((bfd *, asection *, asymbol **, bfd_vma, const char **,
92 const char **, unsigned int *));
94 #if defined(__STDC__) || defined(ALMOST_STDC)
95 struct alpha_elf_link_hash_entry;
98 static boolean elf64_alpha_output_extsym
99 PARAMS((struct alpha_elf_link_hash_entry *, PTR));
101 static boolean elf64_alpha_can_merge_gots
102 PARAMS((bfd *, bfd *));
103 static void elf64_alpha_merge_gots
104 PARAMS((bfd *, bfd *));
105 static boolean elf64_alpha_calc_got_offsets_for_symbol
106 PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
107 static void elf64_alpha_calc_got_offsets PARAMS ((struct bfd_link_info *));
108 static boolean elf64_alpha_size_got_sections
109 PARAMS ((struct bfd_link_info *));
110 static boolean elf64_alpha_size_plt_section
111 PARAMS ((struct bfd_link_info *));
112 static boolean elf64_alpha_size_plt_section_1
113 PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
114 static boolean elf64_alpha_always_size_sections
115 PARAMS ((bfd *, struct bfd_link_info *));
116 static int alpha_dynamic_entries_for_reloc
117 PARAMS ((int, int, int));
118 static boolean elf64_alpha_calc_dynrel_sizes
119 PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
120 static boolean elf64_alpha_size_rela_got_section
121 PARAMS ((struct bfd_link_info *));
122 static boolean elf64_alpha_size_rela_got_1
123 PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
124 static boolean elf64_alpha_add_symbol_hook
125 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
126 const char **, flagword *, asection **, bfd_vma *));
127 static struct alpha_elf_got_entry *get_got_entry
128 PARAMS ((bfd *, struct alpha_elf_link_hash_entry *, unsigned long,
129 unsigned long, bfd_vma));
130 static boolean elf64_alpha_check_relocs
131 PARAMS((bfd *, struct bfd_link_info *, asection *sec,
132 const Elf_Internal_Rela *));
133 static boolean elf64_alpha_adjust_dynamic_symbol
134 PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *));
135 static boolean elf64_alpha_size_dynamic_sections
136 PARAMS((bfd *, struct bfd_link_info *));
137 static boolean elf64_alpha_relocate_section
138 PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
139 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
140 static boolean elf64_alpha_finish_dynamic_symbol
141 PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
142 Elf_Internal_Sym *));
143 static boolean elf64_alpha_finish_dynamic_sections
144 PARAMS((bfd *, struct bfd_link_info *));
145 static boolean elf64_alpha_final_link
146 PARAMS((bfd *, struct bfd_link_info *));
147 static boolean elf64_alpha_merge_ind_symbols
148 PARAMS((struct alpha_elf_link_hash_entry *, PTR));
149 static Elf_Internal_Rela * elf64_alpha_find_reloc_at_ofs
150 PARAMS ((Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_vma, int));
151 static enum elf_reloc_type_class elf64_alpha_reloc_type_class
152 PARAMS ((const Elf_Internal_Rela *));
154 struct alpha_elf_link_hash_entry
156 struct elf_link_hash_entry root;
158 /* External symbol information. */
161 /* Cumulative flags for all the .got entries. */
164 /* Contexts in which a literal was referenced. */
165 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
166 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
167 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
168 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08
169 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10
170 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20
171 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x38
172 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x40
174 /* Used to implement multiple .got subsections. */
175 struct alpha_elf_got_entry
177 struct alpha_elf_got_entry *next;
179 /* which .got subsection? */
182 /* the addend in effect for this entry. */
185 /* the .got offset for this entry. */
188 /* How many references to this entry? */
191 /* The relocation type of this entry. */
192 unsigned char reloc_type;
194 /* How a LITERAL is used. */
197 /* Have we initialized the dynamic relocation for this entry? */
198 unsigned char reloc_done;
200 /* Have we adjusted this entry for SEC_MERGE? */
201 unsigned char reloc_xlated;
204 /* used to count non-got, non-plt relocations for delayed sizing
205 of relocation sections. */
206 struct alpha_elf_reloc_entry
208 struct alpha_elf_reloc_entry *next;
210 /* which .reloc section? */
213 /* what kind of relocation? */
216 /* is this against read-only section? */
217 unsigned int reltext : 1;
219 /* how many did we find? */
224 /* Alpha ELF linker hash table. */
226 struct alpha_elf_link_hash_table
228 struct elf_link_hash_table root;
230 /* The head of a list of .got subsections linked through
231 alpha_elf_tdata(abfd)->got_link_next. */
235 /* Look up an entry in a Alpha ELF linker hash table. */
237 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
238 ((struct alpha_elf_link_hash_entry *) \
239 elf_link_hash_lookup (&(table)->root, (string), (create), \
242 /* Traverse a Alpha ELF linker hash table. */
244 #define alpha_elf_link_hash_traverse(table, func, info) \
245 (elf_link_hash_traverse \
247 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
250 /* Get the Alpha ELF linker hash table from a link_info structure. */
252 #define alpha_elf_hash_table(p) \
253 ((struct alpha_elf_link_hash_table *) ((p)->hash))
255 /* Get the object's symbols as our own entry type. */
257 #define alpha_elf_sym_hashes(abfd) \
258 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
260 /* Should we do dynamic things to this symbol? */
263 alpha_elf_dynamic_symbol_p (h, info)
264 struct elf_link_hash_entry *h;
265 struct bfd_link_info *info;
270 while (h->root.type == bfd_link_hash_indirect
271 || h->root.type == bfd_link_hash_warning)
272 h = (struct elf_link_hash_entry *) h->root.u.i.link;
274 if (h->dynindx == -1)
277 if (h->root.type == bfd_link_hash_undefweak
278 || h->root.type == bfd_link_hash_defweak)
281 switch (ELF_ST_VISIBILITY (h->other))
289 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
294 if ((info->shared && !info->symbolic)
295 || ((h->elf_link_hash_flags
296 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))
297 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
303 /* Create an entry in a Alpha ELF linker hash table. */
305 static struct bfd_hash_entry *
306 elf64_alpha_link_hash_newfunc (entry, table, string)
307 struct bfd_hash_entry *entry;
308 struct bfd_hash_table *table;
311 struct alpha_elf_link_hash_entry *ret =
312 (struct alpha_elf_link_hash_entry *) entry;
314 /* Allocate the structure if it has not already been allocated by a
316 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
317 ret = ((struct alpha_elf_link_hash_entry *)
318 bfd_hash_allocate (table,
319 sizeof (struct alpha_elf_link_hash_entry)));
320 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
321 return (struct bfd_hash_entry *) ret;
323 /* Call the allocation method of the superclass. */
324 ret = ((struct alpha_elf_link_hash_entry *)
325 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
327 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
329 /* Set local fields. */
330 memset (&ret->esym, 0, sizeof (EXTR));
331 /* We use -2 as a marker to indicate that the information has
332 not been set. -1 means there is no associated ifd. */
335 ret->got_entries = NULL;
336 ret->reloc_entries = NULL;
339 return (struct bfd_hash_entry *) ret;
342 /* Create a Alpha ELF linker hash table. */
344 static struct bfd_link_hash_table *
345 elf64_alpha_bfd_link_hash_table_create (abfd)
348 struct alpha_elf_link_hash_table *ret;
349 bfd_size_type amt = sizeof (struct alpha_elf_link_hash_table);
351 ret = (struct alpha_elf_link_hash_table *) bfd_zmalloc (amt);
352 if (ret == (struct alpha_elf_link_hash_table *) NULL)
355 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
356 elf64_alpha_link_hash_newfunc))
362 return &ret->root.root;
365 /* We have some private fields hanging off of the elf_tdata structure. */
367 struct alpha_elf_obj_tdata
369 struct elf_obj_tdata root;
371 /* For every input file, these are the got entries for that object's
373 struct alpha_elf_got_entry ** local_got_entries;
375 /* For every input file, this is the object that owns the got that
376 this input file uses. */
379 /* For every got, this is a linked list through the objects using this got */
380 bfd *in_got_link_next;
382 /* For every got, this is a link to the next got subsegment. */
385 /* For every got, this is the section. */
388 /* For every got, this is it's total number of words. */
391 /* For every got, this is the sum of the number of words required
392 to hold all of the member object's local got. */
396 #define alpha_elf_tdata(abfd) \
397 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
400 elf64_alpha_mkobject (abfd)
403 bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata);
404 abfd->tdata.any = bfd_zalloc (abfd, amt);
405 if (abfd->tdata.any == NULL)
411 elf64_alpha_object_p (abfd)
414 /* Allocate our special target data. */
415 struct alpha_elf_obj_tdata *new_tdata;
416 bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata);
417 new_tdata = bfd_zalloc (abfd, amt);
418 if (new_tdata == NULL)
420 new_tdata->root = *abfd->tdata.elf_obj_data;
421 abfd->tdata.any = new_tdata;
423 /* Set the right machine number for an Alpha ELF file. */
424 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
427 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
428 from smaller values. Start with zero, widen, *then* decrement. */
429 #define MINUS_ONE (((bfd_vma)0) - 1)
431 #define SKIP_HOWTO(N) \
432 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
434 static reloc_howto_type elf64_alpha_howto_table[] =
436 HOWTO (R_ALPHA_NONE, /* type */
438 0, /* size (0 = byte, 1 = short, 2 = long) */
440 true, /* pc_relative */
442 complain_overflow_dont, /* complain_on_overflow */
443 elf64_alpha_reloc_nil, /* special_function */
445 false, /* partial_inplace */
448 true), /* pcrel_offset */
450 /* A 32 bit reference to a symbol. */
451 HOWTO (R_ALPHA_REFLONG, /* type */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
455 false, /* pc_relative */
457 complain_overflow_bitfield, /* complain_on_overflow */
458 0, /* special_function */
459 "REFLONG", /* name */
460 false, /* partial_inplace */
461 0xffffffff, /* src_mask */
462 0xffffffff, /* dst_mask */
463 false), /* pcrel_offset */
465 /* A 64 bit reference to a symbol. */
466 HOWTO (R_ALPHA_REFQUAD, /* type */
468 4, /* size (0 = byte, 1 = short, 2 = long) */
470 false, /* pc_relative */
472 complain_overflow_bitfield, /* complain_on_overflow */
473 0, /* special_function */
474 "REFQUAD", /* name */
475 false, /* partial_inplace */
476 MINUS_ONE, /* src_mask */
477 MINUS_ONE, /* dst_mask */
478 false), /* pcrel_offset */
480 /* A 32 bit GP relative offset. This is just like REFLONG except
481 that when the value is used the value of the gp register will be
483 HOWTO (R_ALPHA_GPREL32, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 false, /* pc_relative */
489 complain_overflow_bitfield, /* complain_on_overflow */
490 0, /* special_function */
491 "GPREL32", /* name */
492 false, /* partial_inplace */
493 0xffffffff, /* src_mask */
494 0xffffffff, /* dst_mask */
495 false), /* pcrel_offset */
497 /* Used for an instruction that refers to memory off the GP register. */
498 HOWTO (R_ALPHA_LITERAL, /* type */
500 1, /* size (0 = byte, 1 = short, 2 = long) */
502 false, /* pc_relative */
504 complain_overflow_signed, /* complain_on_overflow */
505 0, /* special_function */
506 "ELF_LITERAL", /* name */
507 false, /* partial_inplace */
508 0xffff, /* src_mask */
509 0xffff, /* dst_mask */
510 false), /* pcrel_offset */
512 /* This reloc only appears immediately following an ELF_LITERAL reloc.
513 It identifies a use of the literal. The symbol index is special:
514 1 means the literal address is in the base register of a memory
515 format instruction; 2 means the literal address is in the byte
516 offset register of a byte-manipulation instruction; 3 means the
517 literal address is in the target register of a jsr instruction.
518 This does not actually do any relocation. */
519 HOWTO (R_ALPHA_LITUSE, /* type */
521 1, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_dont, /* complain_on_overflow */
526 elf64_alpha_reloc_nil, /* special_function */
528 false, /* partial_inplace */
531 false), /* pcrel_offset */
533 /* Load the gp register. This is always used for a ldah instruction
534 which loads the upper 16 bits of the gp register. The symbol
535 index of the GPDISP instruction is an offset in bytes to the lda
536 instruction that loads the lower 16 bits. The value to use for
537 the relocation is the difference between the GP value and the
538 current location; the load will always be done against a register
539 holding the current address.
541 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
542 any offset is present in the instructions, it is an offset from
543 the register to the ldah instruction. This lets us avoid any
544 stupid hackery like inventing a gp value to do partial relocation
545 against. Also unlike ECOFF, we do the whole relocation off of
546 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
547 space consuming bit, that, since all the information was present
548 in the GPDISP_HI16 reloc. */
549 HOWTO (R_ALPHA_GPDISP, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 false, /* pc_relative */
555 complain_overflow_dont, /* complain_on_overflow */
556 elf64_alpha_reloc_gpdisp, /* special_function */
558 false, /* partial_inplace */
559 0xffff, /* src_mask */
560 0xffff, /* dst_mask */
561 true), /* pcrel_offset */
563 /* A 21 bit branch. */
564 HOWTO (R_ALPHA_BRADDR, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 true, /* pc_relative */
570 complain_overflow_signed, /* complain_on_overflow */
571 0, /* special_function */
573 false, /* partial_inplace */
574 0x1fffff, /* src_mask */
575 0x1fffff, /* dst_mask */
576 true), /* pcrel_offset */
578 /* A hint for a jump to a register. */
579 HOWTO (R_ALPHA_HINT, /* type */
581 1, /* size (0 = byte, 1 = short, 2 = long) */
583 true, /* pc_relative */
585 complain_overflow_dont, /* complain_on_overflow */
586 0, /* special_function */
588 false, /* partial_inplace */
589 0x3fff, /* src_mask */
590 0x3fff, /* dst_mask */
591 true), /* pcrel_offset */
593 /* 16 bit PC relative offset. */
594 HOWTO (R_ALPHA_SREL16, /* type */
596 1, /* size (0 = byte, 1 = short, 2 = long) */
598 true, /* pc_relative */
600 complain_overflow_signed, /* complain_on_overflow */
601 0, /* special_function */
603 false, /* partial_inplace */
604 0xffff, /* src_mask */
605 0xffff, /* dst_mask */
606 true), /* pcrel_offset */
608 /* 32 bit PC relative offset. */
609 HOWTO (R_ALPHA_SREL32, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 true, /* pc_relative */
615 complain_overflow_signed, /* complain_on_overflow */
616 0, /* special_function */
618 false, /* partial_inplace */
619 0xffffffff, /* src_mask */
620 0xffffffff, /* dst_mask */
621 true), /* pcrel_offset */
623 /* A 64 bit PC relative offset. */
624 HOWTO (R_ALPHA_SREL64, /* type */
626 4, /* size (0 = byte, 1 = short, 2 = long) */
628 true, /* pc_relative */
630 complain_overflow_signed, /* complain_on_overflow */
631 0, /* special_function */
633 false, /* partial_inplace */
634 MINUS_ONE, /* src_mask */
635 MINUS_ONE, /* dst_mask */
636 true), /* pcrel_offset */
638 /* Skip 12 - 16; deprecated ECOFF relocs. */
645 /* The high 16 bits of the displacement from GP to the target. */
646 HOWTO (R_ALPHA_GPRELHIGH,
648 1, /* size (0 = byte, 1 = short, 2 = long) */
650 false, /* pc_relative */
652 complain_overflow_signed, /* complain_on_overflow */
653 0, /* special_function */
654 "GPRELHIGH", /* name */
655 false, /* partial_inplace */
656 0xffff, /* src_mask */
657 0xffff, /* dst_mask */
658 false), /* pcrel_offset */
660 /* The low 16 bits of the displacement from GP to the target. */
661 HOWTO (R_ALPHA_GPRELLOW,
663 1, /* size (0 = byte, 1 = short, 2 = long) */
665 false, /* pc_relative */
667 complain_overflow_dont, /* complain_on_overflow */
668 0, /* special_function */
669 "GPRELLOW", /* name */
670 false, /* partial_inplace */
671 0xffff, /* src_mask */
672 0xffff, /* dst_mask */
673 false), /* pcrel_offset */
675 /* A 16-bit displacement from the GP to the target. */
676 HOWTO (R_ALPHA_GPREL16,
678 1, /* size (0 = byte, 1 = short, 2 = long) */
680 false, /* pc_relative */
682 complain_overflow_signed, /* complain_on_overflow */
683 0, /* special_function */
684 "GPREL16", /* name */
685 false, /* partial_inplace */
686 0xffff, /* src_mask */
687 0xffff, /* dst_mask */
688 false), /* pcrel_offset */
690 /* Skip 20 - 23; deprecated ECOFF relocs. */
696 /* Misc ELF relocations. */
698 /* A dynamic relocation to copy the target into our .dynbss section. */
699 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
700 is present because every other ELF has one, but should not be used
701 because .dynbss is an ugly thing. */
708 complain_overflow_dont,
709 bfd_elf_generic_reloc,
716 /* A dynamic relocation for a .got entry. */
717 HOWTO (R_ALPHA_GLOB_DAT,
723 complain_overflow_dont,
724 bfd_elf_generic_reloc,
731 /* A dynamic relocation for a .plt entry. */
732 HOWTO (R_ALPHA_JMP_SLOT,
738 complain_overflow_dont,
739 bfd_elf_generic_reloc,
746 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
747 HOWTO (R_ALPHA_RELATIVE,
753 complain_overflow_dont,
754 bfd_elf_generic_reloc,
761 /* A 21 bit branch that adjusts for gp loads. */
762 HOWTO (R_ALPHA_BRSGP, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 true, /* pc_relative */
768 complain_overflow_signed, /* complain_on_overflow */
769 0, /* special_function */
771 false, /* partial_inplace */
772 0x1fffff, /* src_mask */
773 0x1fffff, /* dst_mask */
774 true), /* pcrel_offset */
776 /* Creates a tls_index for the symbol in the got. */
777 HOWTO (R_ALPHA_TLSGD, /* type */
779 1, /* size (0 = byte, 1 = short, 2 = long) */
781 false, /* pc_relative */
783 complain_overflow_signed, /* complain_on_overflow */
784 0, /* special_function */
786 false, /* partial_inplace */
787 0xffff, /* src_mask */
788 0xffff, /* dst_mask */
789 false), /* pcrel_offset */
791 /* Creates a tls_index for the (current) module in the got. */
792 HOWTO (R_ALPHA_TLSLDM, /* type */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
796 false, /* pc_relative */
798 complain_overflow_signed, /* complain_on_overflow */
799 0, /* special_function */
801 false, /* partial_inplace */
802 0xffff, /* src_mask */
803 0xffff, /* dst_mask */
804 false), /* pcrel_offset */
806 /* A dynamic relocation for a DTP module entry. */
807 HOWTO (R_ALPHA_DTPMOD64, /* type */
809 4, /* size (0 = byte, 1 = short, 2 = long) */
811 false, /* pc_relative */
813 complain_overflow_bitfield, /* complain_on_overflow */
814 0, /* special_function */
815 "DTPMOD64", /* name */
816 false, /* partial_inplace */
817 MINUS_ONE, /* src_mask */
818 MINUS_ONE, /* dst_mask */
819 false), /* pcrel_offset */
821 /* Creates a 64-bit offset in the got for the displacement
822 from DTP to the target. */
823 HOWTO (R_ALPHA_GOTDTPREL, /* type */
825 1, /* size (0 = byte, 1 = short, 2 = long) */
827 false, /* pc_relative */
829 complain_overflow_signed, /* complain_on_overflow */
830 0, /* special_function */
831 "GOTDTPREL", /* name */
832 false, /* partial_inplace */
833 0xffff, /* src_mask */
834 0xffff, /* dst_mask */
835 false), /* pcrel_offset */
837 /* A dynamic relocation for a displacement from DTP to the target. */
838 HOWTO (R_ALPHA_DTPREL64, /* type */
840 4, /* size (0 = byte, 1 = short, 2 = long) */
842 false, /* pc_relative */
844 complain_overflow_bitfield, /* complain_on_overflow */
845 0, /* special_function */
846 "DTPREL64", /* name */
847 false, /* partial_inplace */
848 MINUS_ONE, /* src_mask */
849 MINUS_ONE, /* dst_mask */
850 false), /* pcrel_offset */
852 /* The high 16 bits of the displacement from DTP to the target. */
853 HOWTO (R_ALPHA_DTPRELHI, /* type */
855 1, /* size (0 = byte, 1 = short, 2 = long) */
857 false, /* pc_relative */
859 complain_overflow_signed, /* complain_on_overflow */
860 0, /* special_function */
861 "DTPRELHI", /* name */
862 false, /* partial_inplace */
863 0xffff, /* src_mask */
864 0xffff, /* dst_mask */
865 false), /* pcrel_offset */
867 /* The low 16 bits of the displacement from DTP to the target. */
868 HOWTO (R_ALPHA_DTPRELLO, /* type */
870 1, /* size (0 = byte, 1 = short, 2 = long) */
872 false, /* pc_relative */
874 complain_overflow_dont, /* complain_on_overflow */
875 0, /* special_function */
876 "DTPRELLO", /* name */
877 false, /* partial_inplace */
878 0xffff, /* src_mask */
879 0xffff, /* dst_mask */
880 false), /* pcrel_offset */
882 /* A 16-bit displacement from DTP to the target. */
883 HOWTO (R_ALPHA_DTPREL16, /* type */
885 1, /* size (0 = byte, 1 = short, 2 = long) */
887 false, /* pc_relative */
889 complain_overflow_signed, /* complain_on_overflow */
890 0, /* special_function */
891 "DTPREL16", /* name */
892 false, /* partial_inplace */
893 0xffff, /* src_mask */
894 0xffff, /* dst_mask */
895 false), /* pcrel_offset */
897 /* Creates a 64-bit offset in the got for the displacement
898 from TP to the target. */
899 HOWTO (R_ALPHA_GOTTPREL, /* type */
901 1, /* size (0 = byte, 1 = short, 2 = long) */
903 false, /* pc_relative */
905 complain_overflow_signed, /* complain_on_overflow */
906 0, /* special_function */
907 "GOTTPREL", /* name */
908 false, /* partial_inplace */
909 0xffff, /* src_mask */
910 0xffff, /* dst_mask */
911 false), /* pcrel_offset */
913 /* A dynamic relocation for a displacement from TP to the target. */
914 HOWTO (R_ALPHA_TPREL64, /* type */
916 4, /* size (0 = byte, 1 = short, 2 = long) */
918 false, /* pc_relative */
920 complain_overflow_bitfield, /* complain_on_overflow */
921 0, /* special_function */
922 "TPREL64", /* name */
923 false, /* partial_inplace */
924 MINUS_ONE, /* src_mask */
925 MINUS_ONE, /* dst_mask */
926 false), /* pcrel_offset */
928 /* The high 16 bits of the displacement from TP to the target. */
929 HOWTO (R_ALPHA_TPRELHI, /* type */
931 1, /* size (0 = byte, 1 = short, 2 = long) */
933 false, /* pc_relative */
935 complain_overflow_signed, /* complain_on_overflow */
936 0, /* special_function */
937 "TPRELHI", /* name */
938 false, /* partial_inplace */
939 0xffff, /* src_mask */
940 0xffff, /* dst_mask */
941 false), /* pcrel_offset */
943 /* The low 16 bits of the displacement from TP to the target. */
944 HOWTO (R_ALPHA_TPRELLO, /* type */
946 1, /* size (0 = byte, 1 = short, 2 = long) */
948 false, /* pc_relative */
950 complain_overflow_dont, /* complain_on_overflow */
951 0, /* special_function */
952 "TPRELLO", /* name */
953 false, /* partial_inplace */
954 0xffff, /* src_mask */
955 0xffff, /* dst_mask */
956 false), /* pcrel_offset */
958 /* A 16-bit displacement from TP to the target. */
959 HOWTO (R_ALPHA_TPREL16, /* type */
961 1, /* size (0 = byte, 1 = short, 2 = long) */
963 false, /* pc_relative */
965 complain_overflow_signed, /* complain_on_overflow */
966 0, /* special_function */
967 "TPREL16", /* name */
968 false, /* partial_inplace */
969 0xffff, /* src_mask */
970 0xffff, /* dst_mask */
971 false), /* pcrel_offset */
974 /* A relocation function which doesn't do anything. */
976 static bfd_reloc_status_type
977 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
978 bfd *abfd ATTRIBUTE_UNUSED;
980 asymbol *sym ATTRIBUTE_UNUSED;
981 PTR data ATTRIBUTE_UNUSED;
984 char **error_message ATTRIBUTE_UNUSED;
987 reloc->address += sec->output_offset;
991 /* A relocation function used for an unsupported reloc. */
993 static bfd_reloc_status_type
994 elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
995 bfd *abfd ATTRIBUTE_UNUSED;
997 asymbol *sym ATTRIBUTE_UNUSED;
998 PTR data ATTRIBUTE_UNUSED;
1001 char **error_message ATTRIBUTE_UNUSED;
1004 reloc->address += sec->output_offset;
1005 return bfd_reloc_notsupported;
1008 /* Do the work of the GPDISP relocation. */
1010 static bfd_reloc_status_type
1011 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
1017 bfd_reloc_status_type ret = bfd_reloc_ok;
1019 unsigned long i_ldah, i_lda;
1021 i_ldah = bfd_get_32 (abfd, p_ldah);
1022 i_lda = bfd_get_32 (abfd, p_lda);
1024 /* Complain if the instructions are not correct. */
1025 if (((i_ldah >> 26) & 0x3f) != 0x09
1026 || ((i_lda >> 26) & 0x3f) != 0x08)
1027 ret = bfd_reloc_dangerous;
1029 /* Extract the user-supplied offset, mirroring the sign extensions
1030 that the instructions perform. */
1031 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
1032 addend = (addend ^ 0x80008000) - 0x80008000;
1036 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000
1037 || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000)
1038 ret = bfd_reloc_overflow;
1040 /* compensate for the sign extension again. */
1041 i_ldah = ((i_ldah & 0xffff0000)
1042 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
1043 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
1045 bfd_put_32 (abfd, (bfd_vma) i_ldah, p_ldah);
1046 bfd_put_32 (abfd, (bfd_vma) i_lda, p_lda);
1051 /* The special function for the GPDISP reloc. */
1053 static bfd_reloc_status_type
1054 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
1055 output_bfd, err_msg)
1057 arelent *reloc_entry;
1058 asymbol *sym ATTRIBUTE_UNUSED;
1060 asection *input_section;
1064 bfd_reloc_status_type ret;
1065 bfd_vma gp, relocation;
1066 bfd_byte *p_ldah, *p_lda;
1068 /* Don't do anything if we're not doing a final link. */
1071 reloc_entry->address += input_section->output_offset;
1072 return bfd_reloc_ok;
1075 if (reloc_entry->address > input_section->_cooked_size ||
1076 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
1077 return bfd_reloc_outofrange;
1079 /* The gp used in the portion of the output object to which this
1080 input object belongs is cached on the input bfd. */
1081 gp = _bfd_get_gp_value (abfd);
1083 relocation = (input_section->output_section->vma
1084 + input_section->output_offset
1085 + reloc_entry->address);
1087 p_ldah = (bfd_byte *) data + reloc_entry->address;
1088 p_lda = p_ldah + reloc_entry->addend;
1090 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
1092 /* Complain if the instructions are not correct. */
1093 if (ret == bfd_reloc_dangerous)
1094 *err_msg = _("GPDISP relocation did not find ldah and lda instructions");
1099 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1101 struct elf_reloc_map
1103 bfd_reloc_code_real_type bfd_reloc_val;
1107 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
1109 {BFD_RELOC_NONE, R_ALPHA_NONE},
1110 {BFD_RELOC_32, R_ALPHA_REFLONG},
1111 {BFD_RELOC_64, R_ALPHA_REFQUAD},
1112 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
1113 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
1114 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
1115 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
1116 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
1117 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
1118 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
1119 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
1120 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
1121 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
1122 {BFD_RELOC_ALPHA_GPREL_HI16, R_ALPHA_GPRELHIGH},
1123 {BFD_RELOC_ALPHA_GPREL_LO16, R_ALPHA_GPRELLOW},
1124 {BFD_RELOC_GPREL16, R_ALPHA_GPREL16},
1125 {BFD_RELOC_ALPHA_BRSGP, R_ALPHA_BRSGP},
1126 {BFD_RELOC_ALPHA_TLSGD, R_ALPHA_TLSGD},
1127 {BFD_RELOC_ALPHA_TLSLDM, R_ALPHA_TLSLDM},
1128 {BFD_RELOC_ALPHA_DTPMOD64, R_ALPHA_DTPMOD64},
1129 {BFD_RELOC_ALPHA_GOTDTPREL16, R_ALPHA_GOTDTPREL},
1130 {BFD_RELOC_ALPHA_DTPREL64, R_ALPHA_DTPREL64},
1131 {BFD_RELOC_ALPHA_DTPREL_HI16, R_ALPHA_DTPRELHI},
1132 {BFD_RELOC_ALPHA_DTPREL_LO16, R_ALPHA_DTPRELLO},
1133 {BFD_RELOC_ALPHA_DTPREL16, R_ALPHA_DTPREL16},
1134 {BFD_RELOC_ALPHA_GOTTPREL16, R_ALPHA_GOTTPREL},
1135 {BFD_RELOC_ALPHA_TPREL64, R_ALPHA_TPREL64},
1136 {BFD_RELOC_ALPHA_TPREL_HI16, R_ALPHA_TPRELHI},
1137 {BFD_RELOC_ALPHA_TPREL_LO16, R_ALPHA_TPRELLO},
1138 {BFD_RELOC_ALPHA_TPREL16, R_ALPHA_TPREL16},
1141 /* Given a BFD reloc type, return a HOWTO structure. */
1143 static reloc_howto_type *
1144 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
1145 bfd *abfd ATTRIBUTE_UNUSED;
1146 bfd_reloc_code_real_type code;
1148 const struct elf_reloc_map *i, *e;
1149 i = e = elf64_alpha_reloc_map;
1150 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
1153 if (i->bfd_reloc_val == code)
1154 return &elf64_alpha_howto_table[i->elf_reloc_val];
1159 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1162 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
1163 bfd *abfd ATTRIBUTE_UNUSED;
1165 Elf64_Internal_Rela *dst;
1169 r_type = ELF64_R_TYPE(dst->r_info);
1170 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
1171 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
1174 /* These two relocations create a two-word entry in the got. */
1175 #define alpha_got_entry_size(r_type) \
1176 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1178 /* This is PT_TLS segment p_vaddr. */
1179 #define alpha_get_dtprel_base(tlss) \
1182 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1183 is assigned offset round(16, PT_TLS p_align). */
1184 #define alpha_get_tprel_base(tlss) \
1185 ((tlss)->start - align_power ((bfd_vma) 16, (tlss)->align))
1187 /* These functions do relaxation for Alpha ELF.
1189 Currently I'm only handling what I can do with existing compiler
1190 and assembler support, which means no instructions are removed,
1191 though some may be nopped. At this time GCC does not emit enough
1192 information to do all of the relaxing that is possible. It will
1193 take some not small amount of work for that to happen.
1195 There are a couple of interesting papers that I once read on this
1196 subject, that I cannot find references to at the moment, that
1197 related to Alpha in particular. They are by David Wall, then of
1201 #define OP_LDAH 0x09
1202 #define INSN_JSR 0x68004000
1203 #define INSN_JSR_MASK 0xfc00c000
1207 #define INSN_UNOP 0x2ffe0000
1208 #define INSN_ADDQ 0x40000400
1209 #define INSN_RDUNIQ 0x0000009e
1211 struct alpha_relax_info
1216 Elf_Internal_Shdr *symtab_hdr;
1217 Elf_Internal_Rela *relocs, *relend;
1218 struct bfd_link_info *link_info;
1219 struct elf_link_tls_segment *tls_segment;
1223 struct alpha_elf_link_hash_entry *h;
1224 struct alpha_elf_got_entry **first_gotent;
1225 struct alpha_elf_got_entry *gotent;
1226 boolean changed_contents;
1227 boolean changed_relocs;
1228 unsigned char other;
1231 static boolean elf64_alpha_relax_with_lituse
1232 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1233 Elf_Internal_Rela *irel));
1234 static bfd_vma elf64_alpha_relax_opt_call
1235 PARAMS((struct alpha_relax_info *info, bfd_vma symval));
1236 static boolean elf64_alpha_relax_got_load
1237 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1238 Elf_Internal_Rela *irel, unsigned long));
1239 static boolean elf64_alpha_relax_gprelhilo
1240 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1241 Elf_Internal_Rela *irel, boolean));
1242 static boolean elf64_alpha_relax_tls_get_addr
1243 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1244 Elf_Internal_Rela *irel, boolean));
1245 static struct elf_link_tls_segment *elf64_alpha_relax_find_tls_segment
1246 PARAMS((struct alpha_relax_info *, struct elf_link_tls_segment *));
1247 static boolean elf64_alpha_relax_section
1248 PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
1251 static Elf_Internal_Rela *
1252 elf64_alpha_find_reloc_at_ofs (rel, relend, offset, type)
1253 Elf_Internal_Rela *rel, *relend;
1257 while (rel < relend)
1259 if (rel->r_offset == offset
1260 && ELF64_R_TYPE (rel->r_info) == (unsigned int) type)
1268 elf64_alpha_relax_with_lituse (info, symval, irel)
1269 struct alpha_relax_info *info;
1271 Elf_Internal_Rela *irel;
1273 Elf_Internal_Rela *urel, *irelend = info->relend;
1274 int flags, count, i;
1275 bfd_signed_vma disp;
1278 boolean lit_reused = false;
1279 boolean all_optimized = true;
1280 unsigned int lit_insn;
1282 lit_insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1283 if (lit_insn >> 26 != OP_LDQ)
1285 ((*_bfd_error_handler)
1286 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1287 bfd_archive_filename (info->abfd), info->sec->name,
1288 (unsigned long) irel->r_offset));
1292 /* Can't relax dynamic symbols. */
1293 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info))
1296 /* Summarize how this particular LITERAL is used. */
1297 for (urel = irel+1, flags = count = 0; urel < irelend; ++urel, ++count)
1299 if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE)
1301 if (urel->r_addend <= 3)
1302 flags |= 1 << urel->r_addend;
1305 /* A little preparation for the loop... */
1306 disp = symval - info->gp;
1308 for (urel = irel+1, i = 0; i < count; ++i, ++urel)
1312 bfd_signed_vma xdisp;
1314 insn = bfd_get_32 (info->abfd, info->contents + urel->r_offset);
1316 switch (urel->r_addend)
1318 case LITUSE_ALPHA_ADDR:
1320 /* This type is really just a placeholder to note that all
1321 uses cannot be optimized, but to still allow some. */
1322 all_optimized = false;
1325 case LITUSE_ALPHA_BASE:
1326 /* We can always optimize 16-bit displacements. */
1328 /* Extract the displacement from the instruction, sign-extending
1329 it if necessary, then test whether it is within 16 or 32 bits
1330 displacement from GP. */
1331 insn_disp = insn & 0x0000ffff;
1332 if (insn_disp & 0x8000)
1333 insn_disp |= ~0xffff; /* Negative: sign-extend. */
1335 xdisp = disp + insn_disp;
1336 fits16 = (xdisp >= - (bfd_signed_vma) 0x8000 && xdisp < 0x8000);
1337 fits32 = (xdisp >= - (bfd_signed_vma) 0x80000000
1338 && xdisp < 0x7fff8000);
1342 /* Take the op code and dest from this insn, take the base
1343 register from the literal insn. Leave the offset alone. */
1344 insn = (insn & 0xffe0ffff) | (lit_insn & 0x001f0000);
1345 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1347 urel->r_addend = irel->r_addend;
1348 info->changed_relocs = true;
1350 bfd_put_32 (info->abfd, (bfd_vma) insn,
1351 info->contents + urel->r_offset);
1352 info->changed_contents = true;
1355 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1356 else if (fits32 && !(flags & ~6))
1358 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
1360 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1362 lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000);
1363 bfd_put_32 (info->abfd, (bfd_vma) lit_insn,
1364 info->contents + irel->r_offset);
1366 info->changed_contents = true;
1368 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1370 urel->r_addend = irel->r_addend;
1371 info->changed_relocs = true;
1374 all_optimized = false;
1377 case LITUSE_ALPHA_BYTOFF:
1378 /* We can always optimize byte instructions. */
1380 /* FIXME: sanity check the insn for byte op. Check that the
1381 literal dest reg is indeed Rb in the byte insn. */
1383 insn &= ~ (unsigned) 0x001ff000;
1384 insn |= ((symval & 7) << 13) | 0x1000;
1386 urel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1388 info->changed_relocs = true;
1390 bfd_put_32 (info->abfd, (bfd_vma) insn,
1391 info->contents + urel->r_offset);
1392 info->changed_contents = true;
1395 case LITUSE_ALPHA_JSR:
1396 case LITUSE_ALPHA_TLSGD:
1397 case LITUSE_ALPHA_TLSLDM:
1399 bfd_vma optdest, org;
1400 bfd_signed_vma odisp;
1402 /* If this symbol is undefined, we can't relax it to a branch. */
1404 && (info->h->root.root.type == bfd_link_hash_undefweak
1405 || info->h->root.root.type == bfd_link_hash_undefined))
1407 all_optimized = false;
1411 /* If not zero, place to jump without needing pv. */
1412 optdest = elf64_alpha_relax_opt_call (info, symval);
1413 org = (info->sec->output_section->vma
1414 + info->sec->output_offset
1415 + urel->r_offset + 4);
1416 odisp = (optdest ? optdest : symval) - org;
1418 if (odisp >= -0x400000 && odisp < 0x400000)
1420 Elf_Internal_Rela *xrel;
1422 /* Preserve branch prediction call stack when possible. */
1423 if ((insn & INSN_JSR_MASK) == INSN_JSR)
1424 insn = (OP_BSR << 26) | (insn & 0x03e00000);
1426 insn = (OP_BR << 26) | (insn & 0x03e00000);
1428 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1430 urel->r_addend = irel->r_addend;
1433 urel->r_addend += optdest - symval;
1435 all_optimized = false;
1437 bfd_put_32 (info->abfd, (bfd_vma) insn,
1438 info->contents + urel->r_offset);
1440 /* Kill any HINT reloc that might exist for this insn. */
1441 xrel = (elf64_alpha_find_reloc_at_ofs
1442 (info->relocs, info->relend, urel->r_offset,
1445 xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1447 info->changed_contents = true;
1448 info->changed_relocs = true;
1451 all_optimized = false;
1453 /* Even if the target is not in range for a direct branch,
1454 if we share a GP, we can eliminate the gp reload. */
1457 Elf_Internal_Rela *gpdisp
1458 = (elf64_alpha_find_reloc_at_ofs
1459 (info->relocs, irelend, urel->r_offset + 4,
1463 bfd_byte *p_ldah = info->contents + gpdisp->r_offset;
1464 bfd_byte *p_lda = p_ldah + gpdisp->r_addend;
1465 unsigned int ldah = bfd_get_32 (info->abfd, p_ldah);
1466 unsigned int lda = bfd_get_32 (info->abfd, p_lda);
1468 /* Verify that the instruction is "ldah $29,0($26)".
1469 Consider a function that ends in a noreturn call,
1470 and that the next function begins with an ldgp,
1471 and that by accident there is no padding between.
1472 In that case the insn would use $27 as the base. */
1473 if (ldah == 0x27ba0000 && lda == 0x23bd0000)
1475 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_ldah);
1476 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_lda);
1478 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1479 info->changed_contents = true;
1480 info->changed_relocs = true;
1489 /* If all cases were optimized, we can reduce the use count on this
1490 got entry by one, possibly eliminating it. */
1493 if (--info->gotent->use_count == 0)
1495 int sz = alpha_got_entry_size (R_ALPHA_LITERAL);
1496 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1498 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1501 /* If the literal instruction is no longer needed (it may have been
1502 reused. We can eliminate it. */
1503 /* ??? For now, I don't want to deal with compacting the section,
1504 so just nop it out. */
1507 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1508 info->changed_relocs = true;
1510 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP,
1511 info->contents + irel->r_offset);
1512 info->changed_contents = true;
1520 elf64_alpha_relax_opt_call (info, symval)
1521 struct alpha_relax_info *info;
1524 /* If the function has the same gp, and we can identify that the
1525 function does not use its function pointer, we can eliminate the
1528 /* If the symbol is marked NOPV, we are being told the function never
1529 needs its procedure value. */
1530 if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV)
1533 /* If the symbol is marked STD_GP, we are being told the function does
1534 a normal ldgp in the first two words. */
1535 else if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD)
1538 /* Otherwise, we may be able to identify a GP load in the first two
1539 words, which we can then skip. */
1542 Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp;
1545 /* Load the relocations from the section that the target symbol is in. */
1546 if (info->sec == info->tsec)
1548 tsec_relocs = info->relocs;
1549 tsec_relend = info->relend;
1554 tsec_relocs = (_bfd_elf64_link_read_relocs
1555 (info->abfd, info->tsec, (PTR) NULL,
1556 (Elf_Internal_Rela *) NULL,
1557 info->link_info->keep_memory));
1558 if (tsec_relocs == NULL)
1560 tsec_relend = tsec_relocs + info->tsec->reloc_count;
1561 tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs);
1564 /* Recover the symbol's offset within the section. */
1565 ofs = (symval - info->tsec->output_section->vma
1566 - info->tsec->output_offset);
1568 /* Look for a GPDISP reloc. */
1569 gpdisp = (elf64_alpha_find_reloc_at_ofs
1570 (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP));
1572 if (!gpdisp || gpdisp->r_addend != 4)
1582 /* We've now determined that we can skip an initial gp load. Verify
1583 that the call and the target use the same gp. */
1584 if (info->link_info->hash->creator != info->tsec->owner->xvec
1585 || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj)
1592 elf64_alpha_relax_got_load (info, symval, irel, r_type)
1593 struct alpha_relax_info *info;
1595 Elf_Internal_Rela *irel;
1596 unsigned long r_type;
1599 bfd_signed_vma disp;
1601 /* Get the instruction. */
1602 insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1604 if (insn >> 26 != OP_LDQ)
1606 reloc_howto_type *howto = elf64_alpha_howto_table + r_type;
1607 ((*_bfd_error_handler)
1608 ("%s: %s+0x%lx: warning: %s relocation against unexpected insn",
1609 bfd_archive_filename (info->abfd), info->sec->name,
1610 (unsigned long) irel->r_offset, howto->name));
1614 /* Can't relax dynamic symbols. */
1615 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info))
1618 /* Can't use local-exec relocations in shared libraries. */
1619 if (r_type == R_ALPHA_GOTTPREL && info->link_info->shared)
1622 if (r_type == R_ALPHA_LITERAL)
1623 disp = symval - info->gp;
1626 bfd_vma dtp_base, tp_base;
1628 BFD_ASSERT (info->tls_segment != NULL);
1629 dtp_base = alpha_get_dtprel_base (info->tls_segment);
1630 tp_base = alpha_get_tprel_base (info->tls_segment);
1631 disp = symval - (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base);
1634 if (disp < -0x8000 || disp >= 0x8000)
1637 /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading
1638 a constant, so force the base register to be $31. */
1639 if (r_type == R_ALPHA_LITERAL)
1640 insn = (OP_LDA << 26) | (insn & 0x03ff0000);
1642 insn = (OP_LDA << 26) | (insn & (31 << 21)) | (31 << 16);
1643 bfd_put_32 (info->abfd, (bfd_vma) insn, info->contents + irel->r_offset);
1644 info->changed_contents = true;
1648 case R_ALPHA_LITERAL:
1649 r_type = R_ALPHA_GPREL16;
1651 case R_ALPHA_GOTDTPREL:
1652 r_type = R_ALPHA_DTPREL16;
1654 case R_ALPHA_GOTTPREL:
1655 r_type = R_ALPHA_TPREL16;
1662 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), r_type);
1663 info->changed_relocs = true;
1665 /* Reduce the use count on this got entry by one, possibly
1667 if (--info->gotent->use_count == 0)
1669 int sz = alpha_got_entry_size (r_type);
1670 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1672 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1675 /* ??? Search forward through this basic block looking for insns
1676 that use the target register. Stop after an insn modifying the
1677 register is seen, or after a branch or call.
1679 Any such memory load insn may be substituted by a load directly
1680 off the GP. This allows the memory load insn to be issued before
1681 the calculated GP register would otherwise be ready.
1683 Any such jsr insn can be replaced by a bsr if it is in range.
1685 This would mean that we'd have to _add_ relocations, the pain of
1686 which gives one pause. */
1692 elf64_alpha_relax_gprelhilo (info, symval, irel, hi)
1693 struct alpha_relax_info *info;
1695 Elf_Internal_Rela *irel;
1699 bfd_signed_vma disp;
1700 bfd_byte *pos = info->contents + irel->r_offset;
1702 /* ??? This assumes that the compiler doesn't render
1706 ldah t, array(gp) !gprelhigh
1708 ldq r, array(t) !gprellow
1710 which would indeed be the most efficient way to implement this. */
1714 disp = symval - info->gp;
1715 if (disp < -0x8000 || disp >= 0x8000)
1720 /* Nop out the high instruction. */
1722 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos);
1723 info->changed_contents = true;
1725 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1727 info->changed_relocs = true;
1731 /* Adjust the low instruction to reference GP directly. */
1733 insn = bfd_get_32 (info->abfd, pos);
1734 insn = (insn & 0xffe00000) | (29 << 16);
1735 bfd_put_32 (info->abfd, (bfd_vma) insn, pos);
1736 info->changed_contents = true;
1738 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1740 info->changed_relocs = true;
1747 elf64_alpha_relax_tls_get_addr (info, symval, irel, is_gd)
1748 struct alpha_relax_info *info;
1750 Elf_Internal_Rela *irel;
1755 Elf_Internal_Rela *gpdisp, *hint;
1756 boolean dynamic, use_gottprel;
1758 dynamic = alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info);
1760 /* ??? For LD relaxation, we need a symbol referencing the beginning
1761 of the TLS segment. */
1765 /* If a TLS symbol is accessed using IE at least once, there is no point
1766 to use dynamic model for it. */
1767 if (is_gd && info->h && (info->h->flags & ALPHA_ELF_LINK_HASH_TLS_IE))
1770 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
1771 then we might as well relax to IE. */
1772 else if (info->link_info->shared && !dynamic
1773 && (info->link_info->flags & DF_STATIC_TLS))
1776 /* Otherwise we must be building an executable to do anything. */
1777 else if (info->link_info->shared)
1780 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
1781 the matching LITUSE_TLS relocations. */
1782 if (irel + 2 >= info->relend)
1784 if (ELF64_R_TYPE (irel[1].r_info) != R_ALPHA_LITERAL
1785 || ELF64_R_TYPE (irel[2].r_info) != R_ALPHA_LITUSE
1786 || irel[2].r_addend != (is_gd ? LITUSE_ALPHA_TLSGD : LITUSE_ALPHA_TLSLDM))
1789 /* There must be a GPDISP relocation positioned immediately after the
1790 LITUSE relocation. */
1791 gpdisp = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend,
1792 irel[2].r_offset + 4, R_ALPHA_GPDISP);
1796 pos[0] = info->contents + irel[0].r_offset;
1797 pos[1] = info->contents + irel[1].r_offset;
1798 pos[2] = info->contents + irel[2].r_offset;
1799 pos[3] = info->contents + gpdisp->r_offset;
1800 pos[4] = pos[3] + gpdisp->r_addend;
1802 /* Only positions 0 and 1 are allowed to be out of order. */
1803 if (pos[1] < pos[0])
1805 bfd_byte *tmp = pos[0];
1809 if (pos[1] >= pos[2] || pos[2] >= pos[3] || pos[3] >= pos[4])
1812 /* Reduce the use count on the LITERAL relocation. Do this before we
1813 smash the symndx when we adjust the relocations below. */
1815 struct alpha_elf_got_entry *lit_gotent;
1816 struct alpha_elf_link_hash_entry *lit_h;
1819 BFD_ASSERT (ELF64_R_SYM (irel[1].r_info) >= info->symtab_hdr->sh_info);
1820 indx = ELF64_R_SYM (irel[1].r_info) - info->symtab_hdr->sh_info;
1821 lit_h = alpha_elf_sym_hashes (info->abfd)[indx];
1823 while (lit_h->root.root.type == bfd_link_hash_indirect
1824 || lit_h->root.root.type == bfd_link_hash_warning)
1825 lit_h = (struct alpha_elf_link_hash_entry *) lit_h->root.root.u.i.link;
1827 for (lit_gotent = lit_h->got_entries; lit_gotent ;
1828 lit_gotent = lit_gotent->next)
1829 if (lit_gotent->gotobj == info->gotobj
1830 && lit_gotent->reloc_type == R_ALPHA_LITERAL
1831 && lit_gotent->addend == irel[1].r_addend)
1833 BFD_ASSERT (lit_gotent);
1835 if (--lit_gotent->use_count == 0)
1837 int sz = alpha_got_entry_size (R_ALPHA_LITERAL);
1838 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1844 lda $16,x($gp) !tlsgd!1
1845 ldq $27,__tls_get_addr($gp) !literal!1
1846 jsr $26,($27)__tls_get_addr !lituse_tlsgd!1
1847 ldah $29,0($26) !gpdisp!2
1848 lda $29,0($29) !gpdisp!2
1850 ldq $16,x($gp) !gottprel
1855 or the first pair to
1856 lda $16,x($gp) !tprel
1859 ldah $16,x($gp) !tprelhi
1860 lda $16,x($16) !tprello
1864 use_gottprel = false;
1865 switch (!dynamic && !info->link_info->shared)
1870 bfd_signed_vma disp;
1872 BFD_ASSERT (info->tls_segment != NULL);
1873 tp_base = alpha_get_tprel_base (info->tls_segment);
1874 disp = symval - tp_base;
1876 if (disp >= -0x8000 && disp < 0x8000)
1878 insn = (OP_LDA << 26) | (16 << 21) | (31 << 16);
1879 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1880 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]);
1882 irel[0].r_offset = pos[0] - info->contents;
1883 irel[0].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1885 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1888 else if (disp >= -(bfd_signed_vma) 0x80000000
1889 && disp < (bfd_signed_vma) 0x7fff8000)
1891 insn = (OP_LDAH << 26) | (16 << 21) | (31 << 16);
1892 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1893 insn = (OP_LDA << 26) | (16 << 21) | (16 << 16);
1894 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[1]);
1896 irel[0].r_offset = pos[0] - info->contents;
1897 irel[0].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1899 irel[1].r_offset = pos[1] - info->contents;
1900 irel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1908 use_gottprel = true;
1910 insn = (OP_LDQ << 26) | (16 << 21) | (29 << 16);
1911 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1912 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]);
1914 irel[0].r_offset = pos[0] - info->contents;
1915 irel[0].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1917 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1921 bfd_put_32 (info->abfd, (bfd_vma) INSN_RDUNIQ, pos[2]);
1923 insn = INSN_ADDQ | (16 << 21) | (0 << 16) | (0 << 0);
1924 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[3]);
1926 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[4]);
1928 irel[2].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1929 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1931 hint = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend,
1932 irel[2].r_offset, R_ALPHA_HINT);
1934 hint->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1936 info->changed_contents = true;
1937 info->changed_relocs = true;
1939 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
1940 if (--info->gotent->use_count == 0)
1942 int sz = alpha_got_entry_size (info->gotent->reloc_type);
1943 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1945 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1948 /* If we've switched to a GOTTPREL relocation, increment the reference
1949 count on that got entry. */
1952 struct alpha_elf_got_entry *tprel_gotent;
1954 for (tprel_gotent = *info->first_gotent; tprel_gotent ;
1955 tprel_gotent = tprel_gotent->next)
1956 if (tprel_gotent->gotobj == info->gotobj
1957 && tprel_gotent->reloc_type == R_ALPHA_GOTTPREL
1958 && tprel_gotent->addend == irel->r_addend)
1961 tprel_gotent->use_count++;
1964 if (info->gotent->use_count == 0)
1965 tprel_gotent = info->gotent;
1968 tprel_gotent = (struct alpha_elf_got_entry *)
1969 bfd_alloc (info->abfd, sizeof (struct alpha_elf_got_entry));
1973 tprel_gotent->next = *info->first_gotent;
1974 *info->first_gotent = tprel_gotent;
1976 tprel_gotent->gotobj = info->gotobj;
1977 tprel_gotent->addend = irel->r_addend;
1978 tprel_gotent->got_offset = -1;
1979 tprel_gotent->reloc_done = 0;
1980 tprel_gotent->reloc_xlated = 0;
1983 tprel_gotent->use_count = 1;
1984 tprel_gotent->reloc_type = R_ALPHA_GOTTPREL;
1991 static struct elf_link_tls_segment *
1992 elf64_alpha_relax_find_tls_segment (info, seg)
1993 struct alpha_relax_info *info;
1994 struct elf_link_tls_segment *seg;
1996 bfd *output_bfd = info->sec->output_section->owner;
1997 asection *first_tls_sec = NULL, *o;
2001 for (o = output_bfd->sections; o ; o = o->next)
2002 if ((o->flags & SEC_THREAD_LOCAL) != 0
2003 && (o->flags & SEC_LOAD) != 0)
2011 base = first_tls_sec->vma;
2014 for (o = first_tls_sec; o && (o->flags & SEC_THREAD_LOCAL); o = o->next)
2018 if (bfd_get_section_alignment (output_bfd, o) > align)
2019 align = bfd_get_section_alignment (output_bfd, o);
2021 size = o->_raw_size;
2022 if (size == 0 && (o->flags & SEC_HAS_CONTENTS) == 0)
2024 struct bfd_link_order *lo;
2025 for (lo = o->link_order_head; lo ; lo = lo->next)
2026 if (size < lo->offset + lo->size)
2027 size = lo->offset + lo->size;
2029 end = o->vma + size;
2033 seg->size = end - base;
2040 elf64_alpha_relax_section (abfd, sec, link_info, again)
2043 struct bfd_link_info *link_info;
2046 Elf_Internal_Shdr *symtab_hdr;
2047 Elf_Internal_Shdr *shndx_hdr;
2048 Elf_Internal_Rela *internal_relocs;
2049 Elf_Internal_Rela *free_relocs = NULL;
2050 Elf_Internal_Rela *irel, *irelend;
2051 bfd_byte *free_contents = NULL;
2052 Elf64_External_Sym *extsyms;
2053 Elf64_External_Sym *free_extsyms = NULL;
2054 Elf_External_Sym_Shndx *shndx_buf = NULL;
2055 struct alpha_elf_got_entry **local_got_entries;
2056 struct alpha_relax_info info;
2057 struct elf_link_tls_segment tls_segment;
2059 /* We are not currently changing any sizes, so only one pass. */
2062 if (link_info->relocateable
2063 || (sec->flags & SEC_RELOC) == 0
2064 || sec->reloc_count == 0)
2067 /* If this is the first time we have been called for this section,
2068 initialize the cooked size. */
2069 if (sec->_cooked_size == 0)
2070 sec->_cooked_size = sec->_raw_size;
2072 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2073 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2075 /* Load the relocations for this section. */
2076 internal_relocs = (_bfd_elf64_link_read_relocs
2077 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2078 link_info->keep_memory));
2079 if (internal_relocs == NULL)
2081 if (! link_info->keep_memory)
2082 free_relocs = internal_relocs;
2084 memset(&info, 0, sizeof (info));
2087 info.link_info = link_info;
2088 info.symtab_hdr = symtab_hdr;
2089 info.relocs = internal_relocs;
2090 info.relend = irelend = internal_relocs + sec->reloc_count;
2092 /* Find the GP for this object. Do not store the result back via
2093 _bfd_set_gp_value, since this could change again before final. */
2094 info.gotobj = alpha_elf_tdata (abfd)->gotobj;
2097 asection *sgot = alpha_elf_tdata (info.gotobj)->got;
2098 info.gp = (sgot->output_section->vma
2099 + sgot->output_offset
2103 /* Get the section contents. */
2104 if (elf_section_data (sec)->this_hdr.contents != NULL)
2105 info.contents = elf_section_data (sec)->this_hdr.contents;
2108 info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2109 if (info.contents == NULL)
2111 free_contents = info.contents;
2113 if (! bfd_get_section_contents (abfd, sec, info.contents,
2114 (file_ptr) 0, sec->_raw_size))
2118 /* Read this BFD's symbols. */
2119 if (symtab_hdr->contents != NULL)
2120 extsyms = (Elf64_External_Sym *) symtab_hdr->contents;
2123 bfd_size_type amt = symtab_hdr->sh_info * sizeof (Elf64_External_Sym);
2124 extsyms = (Elf64_External_Sym *) bfd_malloc (amt);
2125 if (extsyms == NULL)
2127 free_extsyms = extsyms;
2128 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
2129 || bfd_bread ((PTR) extsyms, amt, abfd) != amt)
2133 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
2134 if (shndx_hdr->sh_size != 0)
2137 amt = symtab_hdr->sh_info * sizeof (Elf_External_Sym_Shndx);
2138 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
2139 if (shndx_buf == NULL)
2141 if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
2142 || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt)
2146 /* Compute the TLS segment information. The version normally found in
2147 elf_hash_table (link_info)->tls_segment isn't built until final_link.
2148 ??? Probably should look into extracting this into a common function. */
2149 info.tls_segment = elf64_alpha_relax_find_tls_segment (&info, &tls_segment);
2151 for (irel = internal_relocs; irel < irelend; irel++)
2154 Elf_Internal_Sym isym;
2155 struct alpha_elf_got_entry *gotent;
2156 unsigned long r_type = ELF64_R_TYPE (irel->r_info);
2158 /* Early exit for unhandled or unrelaxable relocations. */
2161 case R_ALPHA_LITERAL:
2162 case R_ALPHA_GPRELHIGH:
2163 case R_ALPHA_GPRELLOW:
2164 case R_ALPHA_GOTDTPREL:
2165 case R_ALPHA_GOTTPREL:
2167 case R_ALPHA_TLSLDM:
2173 /* Get the value of the symbol referred to by the reloc. */
2174 if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2176 /* A local symbol. */
2177 Elf64_External_Sym *esym;
2178 Elf_External_Sym_Shndx *shndx;
2180 esym = extsyms + ELF64_R_SYM (irel->r_info);
2181 shndx = shndx_buf + (shndx_buf ? ELF64_R_SYM (irel->r_info) : 0);
2182 bfd_elf64_swap_symbol_in (abfd, esym, shndx, &isym);
2183 if (isym.st_shndx == SHN_UNDEF)
2184 info.tsec = bfd_und_section_ptr;
2185 else if (isym.st_shndx == SHN_ABS)
2186 info.tsec = bfd_abs_section_ptr;
2187 else if (isym.st_shndx == SHN_COMMON)
2188 info.tsec = bfd_com_section_ptr;
2190 info.tsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
2193 info.other = isym.st_other;
2194 info.first_gotent = &local_got_entries[ELF64_R_SYM(irel->r_info)];
2195 symval = isym.st_value;
2200 struct alpha_elf_link_hash_entry *h;
2202 indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2203 h = alpha_elf_sym_hashes (abfd)[indx];
2204 BFD_ASSERT (h != NULL);
2206 while (h->root.root.type == bfd_link_hash_indirect
2207 || h->root.root.type == bfd_link_hash_warning)
2208 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2211 info.tsec = h->root.root.u.def.section;
2212 info.other = h->root.other;
2213 info.first_gotent = &h->got_entries;
2214 symval = h->root.root.u.def.value;
2217 /* Search for the got entry to be used by this relocation. */
2218 for (gotent = *info.first_gotent; gotent ; gotent = gotent->next)
2219 if (gotent->gotobj == info.gotobj
2220 && gotent->reloc_type == r_type
2221 && gotent->addend == irel->r_addend)
2223 info.gotent = gotent;
2225 symval += info.tsec->output_section->vma + info.tsec->output_offset;
2226 symval += irel->r_addend;
2230 case R_ALPHA_LITERAL:
2231 BFD_ASSERT(info.gotent != NULL);
2233 /* If there exist LITUSE relocations immediately following, this
2234 opens up all sorts of interesting optimizations, because we
2235 now know every location that this address load is used. */
2236 if (irel+1 < irelend
2237 && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE)
2239 if (!elf64_alpha_relax_with_lituse (&info, symval, irel))
2244 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type))
2249 case R_ALPHA_GPRELHIGH:
2250 case R_ALPHA_GPRELLOW:
2251 if (!elf64_alpha_relax_gprelhilo (&info, symval, irel,
2252 r_type == R_ALPHA_GPRELHIGH))
2256 case R_ALPHA_GOTDTPREL:
2257 case R_ALPHA_GOTTPREL:
2258 BFD_ASSERT(info.gotent != NULL);
2259 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type))
2264 case R_ALPHA_TLSLDM:
2265 BFD_ASSERT(info.gotent != NULL);
2266 if (!elf64_alpha_relax_tls_get_addr (&info, symval, irel,
2267 r_type == R_ALPHA_TLSGD))
2273 if (!elf64_alpha_size_plt_section (link_info))
2275 if (!elf64_alpha_size_got_sections (link_info))
2277 if (!elf64_alpha_size_rela_got_section (link_info))
2280 if (info.changed_relocs)
2281 elf_section_data (sec)->relocs = internal_relocs;
2282 else if (free_relocs != NULL)
2285 if (info.changed_contents)
2286 elf_section_data (sec)->this_hdr.contents = info.contents;
2287 else if (free_contents != NULL)
2289 if (! link_info->keep_memory)
2290 free (free_contents);
2293 /* Cache the section contents for elf_link_input_bfd. */
2294 elf_section_data (sec)->this_hdr.contents = info.contents;
2298 if (shndx_buf != NULL)
2301 if (free_extsyms != NULL)
2303 if (! link_info->keep_memory)
2304 free (free_extsyms);
2307 /* Cache the symbols for elf_link_input_bfd. */
2308 symtab_hdr->contents = (unsigned char *) extsyms;
2312 *again = info.changed_contents || info.changed_relocs;
2317 if (free_relocs != NULL)
2319 if (free_contents != NULL)
2320 free (free_contents);
2321 if (shndx_buf != NULL)
2323 if (free_extsyms != NULL)
2324 free (free_extsyms);
2329 #define PLT_HEADER_SIZE 32
2330 #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */
2331 #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */
2332 #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */
2333 #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */
2335 #define PLT_ENTRY_SIZE 12
2336 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
2337 #define PLT_ENTRY_WORD2 0
2338 #define PLT_ENTRY_WORD3 0
2340 #define MAX_GOT_SIZE (64*1024)
2342 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
2344 /* Handle an Alpha specific section when reading an object file. This
2345 is called when elfcode.h finds a section with an unknown type.
2346 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
2350 elf64_alpha_section_from_shdr (abfd, hdr, name)
2352 Elf64_Internal_Shdr *hdr;
2357 /* There ought to be a place to keep ELF backend specific flags, but
2358 at the moment there isn't one. We just keep track of the
2359 sections by their name, instead. Fortunately, the ABI gives
2360 suggested names for all the MIPS specific sections, so we will
2361 probably get away with this. */
2362 switch (hdr->sh_type)
2364 case SHT_ALPHA_DEBUG:
2365 if (strcmp (name, ".mdebug") != 0)
2372 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2374 newsect = hdr->bfd_section;
2376 if (hdr->sh_type == SHT_ALPHA_DEBUG)
2378 if (! bfd_set_section_flags (abfd, newsect,
2379 (bfd_get_section_flags (abfd, newsect)
2387 /* Convert Alpha specific section flags to bfd internal section flags. */
2390 elf64_alpha_section_flags (flags, hdr)
2392 Elf64_Internal_Shdr *hdr;
2394 if (hdr->sh_flags & SHF_ALPHA_GPREL)
2395 *flags |= SEC_SMALL_DATA;
2400 /* Set the correct type for an Alpha ELF section. We do this by the
2401 section name, which is a hack, but ought to work. */
2404 elf64_alpha_fake_sections (abfd, hdr, sec)
2406 Elf64_Internal_Shdr *hdr;
2409 register const char *name;
2411 name = bfd_get_section_name (abfd, sec);
2413 if (strcmp (name, ".mdebug") == 0)
2415 hdr->sh_type = SHT_ALPHA_DEBUG;
2416 /* In a shared object on Irix 5.3, the .mdebug section has an
2417 entsize of 0. FIXME: Does this matter? */
2418 if ((abfd->flags & DYNAMIC) != 0 )
2419 hdr->sh_entsize = 0;
2421 hdr->sh_entsize = 1;
2423 else if ((sec->flags & SEC_SMALL_DATA)
2424 || strcmp (name, ".sdata") == 0
2425 || strcmp (name, ".sbss") == 0
2426 || strcmp (name, ".lit4") == 0
2427 || strcmp (name, ".lit8") == 0)
2428 hdr->sh_flags |= SHF_ALPHA_GPREL;
2433 /* Hook called by the linker routine which adds symbols from an object
2434 file. We use it to put .comm items in .sbss, and not .bss. */
2437 elf64_alpha_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2439 struct bfd_link_info *info;
2440 const Elf_Internal_Sym *sym;
2441 const char **namep ATTRIBUTE_UNUSED;
2442 flagword *flagsp ATTRIBUTE_UNUSED;
2446 if (sym->st_shndx == SHN_COMMON
2447 && !info->relocateable
2448 && sym->st_size <= elf_gp_size (abfd))
2450 /* Common symbols less than or equal to -G nn bytes are
2451 automatically put into .sbss. */
2453 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2457 scomm = bfd_make_section (abfd, ".scommon");
2459 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2461 | SEC_LINKER_CREATED)))
2466 *valp = sym->st_size;
2472 /* Create the .got section. */
2475 elf64_alpha_create_got_section(abfd, info)
2477 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2481 if (bfd_get_section_by_name (abfd, ".got"))
2484 s = bfd_make_section (abfd, ".got");
2486 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2489 | SEC_LINKER_CREATED))
2490 || !bfd_set_section_alignment (abfd, s, 3))
2493 alpha_elf_tdata (abfd)->got = s;
2498 /* Create all the dynamic sections. */
2501 elf64_alpha_create_dynamic_sections (abfd, info)
2503 struct bfd_link_info *info;
2506 struct elf_link_hash_entry *h;
2508 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
2510 s = bfd_make_section (abfd, ".plt");
2512 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2515 | SEC_LINKER_CREATED
2517 || ! bfd_set_section_alignment (abfd, s, 3))
2520 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2523 if (! (_bfd_generic_link_add_one_symbol
2524 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2525 (bfd_vma) 0, (const char *) NULL, false,
2526 get_elf_backend_data (abfd)->collect,
2527 (struct bfd_link_hash_entry **) &h)))
2529 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2530 h->type = STT_OBJECT;
2533 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2536 s = bfd_make_section (abfd, ".rela.plt");
2538 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2541 | SEC_LINKER_CREATED
2543 || ! bfd_set_section_alignment (abfd, s, 3))
2546 /* We may or may not have created a .got section for this object, but
2547 we definitely havn't done the rest of the work. */
2549 if (!elf64_alpha_create_got_section (abfd, info))
2552 s = bfd_make_section(abfd, ".rela.got");
2554 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2557 | SEC_LINKER_CREATED
2559 || !bfd_set_section_alignment (abfd, s, 3))
2562 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
2563 dynobj's .got section. We don't do this in the linker script
2564 because we don't want to define the symbol if we are not creating
2565 a global offset table. */
2567 if (!(_bfd_generic_link_add_one_symbol
2568 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
2569 alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
2570 false, get_elf_backend_data (abfd)->collect,
2571 (struct bfd_link_hash_entry **) &h)))
2573 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2574 h->type = STT_OBJECT;
2577 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2580 elf_hash_table (info)->hgot = h;
2585 /* Read ECOFF debugging information from a .mdebug section into a
2586 ecoff_debug_info structure. */
2589 elf64_alpha_read_ecoff_info (abfd, section, debug)
2592 struct ecoff_debug_info *debug;
2595 const struct ecoff_debug_swap *swap;
2596 char *ext_hdr = NULL;
2598 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2599 memset (debug, 0, sizeof (*debug));
2601 ext_hdr = (char *) bfd_malloc (swap->external_hdr_size);
2602 if (ext_hdr == NULL && swap->external_hdr_size != 0)
2605 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
2606 swap->external_hdr_size)
2610 symhdr = &debug->symbolic_header;
2611 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
2613 /* The symbolic header contains absolute file offsets and sizes to
2615 #define READ(ptr, offset, count, size, type) \
2616 if (symhdr->count == 0) \
2617 debug->ptr = NULL; \
2620 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
2621 debug->ptr = (type) bfd_malloc (amt); \
2622 if (debug->ptr == NULL) \
2623 goto error_return; \
2624 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2625 || bfd_bread (debug->ptr, amt, abfd) != amt) \
2626 goto error_return; \
2629 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
2630 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
2631 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
2632 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
2633 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
2634 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
2636 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
2637 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
2638 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
2639 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
2640 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
2644 debug->adjust = NULL;
2649 if (ext_hdr != NULL)
2651 if (debug->line != NULL)
2653 if (debug->external_dnr != NULL)
2654 free (debug->external_dnr);
2655 if (debug->external_pdr != NULL)
2656 free (debug->external_pdr);
2657 if (debug->external_sym != NULL)
2658 free (debug->external_sym);
2659 if (debug->external_opt != NULL)
2660 free (debug->external_opt);
2661 if (debug->external_aux != NULL)
2662 free (debug->external_aux);
2663 if (debug->ss != NULL)
2665 if (debug->ssext != NULL)
2666 free (debug->ssext);
2667 if (debug->external_fdr != NULL)
2668 free (debug->external_fdr);
2669 if (debug->external_rfd != NULL)
2670 free (debug->external_rfd);
2671 if (debug->external_ext != NULL)
2672 free (debug->external_ext);
2676 /* Alpha ELF local labels start with '$'. */
2679 elf64_alpha_is_local_label_name (abfd, name)
2680 bfd *abfd ATTRIBUTE_UNUSED;
2683 return name[0] == '$';
2686 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2687 routine in order to handle the ECOFF debugging information. We
2688 still call this mips_elf_find_line because of the slot
2689 find_line_info in elf_obj_tdata is declared that way. */
2691 struct mips_elf_find_line
2693 struct ecoff_debug_info d;
2694 struct ecoff_find_line i;
2698 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2699 functionname_ptr, line_ptr)
2704 const char **filename_ptr;
2705 const char **functionname_ptr;
2706 unsigned int *line_ptr;
2710 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
2711 filename_ptr, functionname_ptr,
2713 &elf_tdata (abfd)->dwarf2_find_line_info))
2716 msec = bfd_get_section_by_name (abfd, ".mdebug");
2720 struct mips_elf_find_line *fi;
2721 const struct ecoff_debug_swap * const swap =
2722 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2724 /* If we are called during a link, alpha_elf_final_link may have
2725 cleared the SEC_HAS_CONTENTS field. We force it back on here
2726 if appropriate (which it normally will be). */
2727 origflags = msec->flags;
2728 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
2729 msec->flags |= SEC_HAS_CONTENTS;
2731 fi = elf_tdata (abfd)->find_line_info;
2734 bfd_size_type external_fdr_size;
2737 struct fdr *fdr_ptr;
2738 bfd_size_type amt = sizeof (struct mips_elf_find_line);
2740 fi = (struct mips_elf_find_line *) bfd_zalloc (abfd, amt);
2743 msec->flags = origflags;
2747 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
2749 msec->flags = origflags;
2753 /* Swap in the FDR information. */
2754 amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr);
2755 fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt);
2756 if (fi->d.fdr == NULL)
2758 msec->flags = origflags;
2761 external_fdr_size = swap->external_fdr_size;
2762 fdr_ptr = fi->d.fdr;
2763 fraw_src = (char *) fi->d.external_fdr;
2764 fraw_end = (fraw_src
2765 + fi->d.symbolic_header.ifdMax * external_fdr_size);
2766 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
2767 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
2769 elf_tdata (abfd)->find_line_info = fi;
2771 /* Note that we don't bother to ever free this information.
2772 find_nearest_line is either called all the time, as in
2773 objdump -l, so the information should be saved, or it is
2774 rarely called, as in ld error messages, so the memory
2775 wasted is unimportant. Still, it would probably be a
2776 good idea for free_cached_info to throw it away. */
2779 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
2780 &fi->i, filename_ptr, functionname_ptr,
2783 msec->flags = origflags;
2787 msec->flags = origflags;
2790 /* Fall back on the generic ELF find_nearest_line routine. */
2792 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
2793 filename_ptr, functionname_ptr,
2797 /* Structure used to pass information to alpha_elf_output_extsym. */
2802 struct bfd_link_info *info;
2803 struct ecoff_debug_info *debug;
2804 const struct ecoff_debug_swap *swap;
2809 elf64_alpha_output_extsym (h, data)
2810 struct alpha_elf_link_hash_entry *h;
2813 struct extsym_info *einfo = (struct extsym_info *) data;
2815 asection *sec, *output_section;
2817 if (h->root.root.type == bfd_link_hash_warning)
2818 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
2820 if (h->root.indx == -2)
2822 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2823 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
2824 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2825 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
2827 else if (einfo->info->strip == strip_all
2828 || (einfo->info->strip == strip_some
2829 && bfd_hash_lookup (einfo->info->keep_hash,
2830 h->root.root.root.string,
2831 false, false) == NULL))
2839 if (h->esym.ifd == -2)
2842 h->esym.cobol_main = 0;
2843 h->esym.weakext = 0;
2844 h->esym.reserved = 0;
2845 h->esym.ifd = ifdNil;
2846 h->esym.asym.value = 0;
2847 h->esym.asym.st = stGlobal;
2849 if (h->root.root.type != bfd_link_hash_defined
2850 && h->root.root.type != bfd_link_hash_defweak)
2851 h->esym.asym.sc = scAbs;
2856 sec = h->root.root.u.def.section;
2857 output_section = sec->output_section;
2859 /* When making a shared library and symbol h is the one from
2860 the another shared library, OUTPUT_SECTION may be null. */
2861 if (output_section == NULL)
2862 h->esym.asym.sc = scUndefined;
2865 name = bfd_section_name (output_section->owner, output_section);
2867 if (strcmp (name, ".text") == 0)
2868 h->esym.asym.sc = scText;
2869 else if (strcmp (name, ".data") == 0)
2870 h->esym.asym.sc = scData;
2871 else if (strcmp (name, ".sdata") == 0)
2872 h->esym.asym.sc = scSData;
2873 else if (strcmp (name, ".rodata") == 0
2874 || strcmp (name, ".rdata") == 0)
2875 h->esym.asym.sc = scRData;
2876 else if (strcmp (name, ".bss") == 0)
2877 h->esym.asym.sc = scBss;
2878 else if (strcmp (name, ".sbss") == 0)
2879 h->esym.asym.sc = scSBss;
2880 else if (strcmp (name, ".init") == 0)
2881 h->esym.asym.sc = scInit;
2882 else if (strcmp (name, ".fini") == 0)
2883 h->esym.asym.sc = scFini;
2885 h->esym.asym.sc = scAbs;
2889 h->esym.asym.reserved = 0;
2890 h->esym.asym.index = indexNil;
2893 if (h->root.root.type == bfd_link_hash_common)
2894 h->esym.asym.value = h->root.root.u.c.size;
2895 else if (h->root.root.type == bfd_link_hash_defined
2896 || h->root.root.type == bfd_link_hash_defweak)
2898 if (h->esym.asym.sc == scCommon)
2899 h->esym.asym.sc = scBss;
2900 else if (h->esym.asym.sc == scSCommon)
2901 h->esym.asym.sc = scSBss;
2903 sec = h->root.root.u.def.section;
2904 output_section = sec->output_section;
2905 if (output_section != NULL)
2906 h->esym.asym.value = (h->root.root.u.def.value
2907 + sec->output_offset
2908 + output_section->vma);
2910 h->esym.asym.value = 0;
2912 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2914 /* Set type and value for a symbol with a function stub. */
2915 h->esym.asym.st = stProc;
2916 sec = bfd_get_section_by_name (einfo->abfd, ".plt");
2918 h->esym.asym.value = 0;
2921 output_section = sec->output_section;
2922 if (output_section != NULL)
2923 h->esym.asym.value = (h->root.plt.offset
2924 + sec->output_offset
2925 + output_section->vma);
2927 h->esym.asym.value = 0;
2931 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
2932 h->root.root.root.string,
2935 einfo->failed = true;
2942 /* Search for and possibly create a got entry. */
2944 static struct alpha_elf_got_entry *
2945 get_got_entry (abfd, h, r_type, r_symndx, r_addend)
2947 struct alpha_elf_link_hash_entry *h;
2948 unsigned long r_type, r_symndx;
2951 struct alpha_elf_got_entry *gotent;
2952 struct alpha_elf_got_entry **slot;
2955 slot = &h->got_entries;
2958 /* This is a local .got entry -- record for merge. */
2960 struct alpha_elf_got_entry **local_got_entries;
2962 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2963 if (!local_got_entries)
2966 Elf_Internal_Shdr *symtab_hdr;
2968 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2969 size = symtab_hdr->sh_info;
2970 size *= sizeof (struct alpha_elf_got_entry *);
2973 = (struct alpha_elf_got_entry **) bfd_alloc (abfd, size);
2974 if (!local_got_entries)
2977 memset (local_got_entries, 0, (size_t) size);
2978 alpha_elf_tdata (abfd)->local_got_entries = local_got_entries;
2981 slot = &local_got_entries[r_symndx];
2984 for (gotent = *slot; gotent ; gotent = gotent->next)
2985 if (gotent->gotobj == abfd
2986 && gotent->reloc_type == r_type
2987 && gotent->addend == r_addend)
2995 amt = sizeof (struct alpha_elf_got_entry);
2996 gotent = (struct alpha_elf_got_entry *) bfd_alloc (abfd, amt);
3000 gotent->gotobj = abfd;
3001 gotent->addend = r_addend;
3002 gotent->got_offset = -1;
3003 gotent->use_count = 1;
3004 gotent->reloc_type = r_type;
3005 gotent->reloc_done = 0;
3006 gotent->reloc_xlated = 0;
3008 gotent->next = *slot;
3011 entry_size = alpha_got_entry_size (r_type);
3012 alpha_elf_tdata (abfd)->total_got_size += entry_size;
3014 alpha_elf_tdata(abfd)->local_got_size += entry_size;
3017 gotent->use_count += 1;
3022 /* Handle dynamic relocations when doing an Alpha ELF link. */
3025 elf64_alpha_check_relocs (abfd, info, sec, relocs)
3027 struct bfd_link_info *info;
3029 const Elf_Internal_Rela *relocs;
3033 const char *rel_sec_name;
3034 Elf_Internal_Shdr *symtab_hdr;
3035 struct alpha_elf_link_hash_entry **sym_hashes;
3036 const Elf_Internal_Rela *rel, *relend;
3037 boolean got_created;
3040 if (info->relocateable)
3043 dynobj = elf_hash_table(info)->dynobj;
3045 elf_hash_table(info)->dynobj = dynobj = abfd;
3048 rel_sec_name = NULL;
3049 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
3050 sym_hashes = alpha_elf_sym_hashes(abfd);
3051 got_created = false;
3053 relend = relocs + sec->reloc_count;
3054 for (rel = relocs; rel < relend; ++rel)
3062 unsigned long r_symndx, r_type;
3063 struct alpha_elf_link_hash_entry *h;
3064 unsigned int gotent_flags;
3065 boolean maybe_dynamic;
3069 r_symndx = ELF64_R_SYM (rel->r_info);
3070 if (r_symndx < symtab_hdr->sh_info)
3074 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3076 while (h->root.root.type == bfd_link_hash_indirect
3077 || h->root.root.type == bfd_link_hash_warning)
3078 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3080 h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
3083 /* We can only get preliminary data on whether a symbol is
3084 locally or externally defined, as not all of the input files
3085 have yet been processed. Do something with what we know, as
3086 this may help reduce memory usage and processing time later. */
3087 maybe_dynamic = false;
3088 if (h && ((info->shared
3089 && (!info->symbolic || info->allow_shlib_undefined))
3090 || ! (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
3091 || h->root.root.type == bfd_link_hash_defweak))
3092 maybe_dynamic = true;
3096 r_type = ELF64_R_TYPE (rel->r_info);
3097 addend = rel->r_addend;
3101 case R_ALPHA_LITERAL:
3102 need = NEED_GOT | NEED_GOT_ENTRY;
3104 /* Remember how this literal is used from its LITUSEs.
3105 This will be important when it comes to decide if we can
3106 create a .plt entry for a function symbol. */
3107 while (++rel < relend && ELF64_R_TYPE (rel->r_info) == R_ALPHA_LITUSE)
3108 if (rel->r_addend >= 1 && rel->r_addend <= 5)
3109 gotent_flags |= 1 << rel->r_addend;
3112 /* No LITUSEs -- presumably the address is used somehow. */
3113 if (gotent_flags == 0)
3114 gotent_flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
3117 case R_ALPHA_GPDISP:
3118 case R_ALPHA_GPREL16:
3119 case R_ALPHA_GPREL32:
3120 case R_ALPHA_GPRELHIGH:
3121 case R_ALPHA_GPRELLOW:
3126 case R_ALPHA_REFLONG:
3127 case R_ALPHA_REFQUAD:
3128 if (info->shared || maybe_dynamic)
3133 case R_ALPHA_TLSLDM:
3134 case R_ALPHA_GOTDTPREL:
3135 need = NEED_GOT | NEED_GOT_ENTRY;
3138 case R_ALPHA_GOTTPREL:
3139 need = NEED_GOT | NEED_GOT_ENTRY;
3140 gotent_flags = ALPHA_ELF_LINK_HASH_TLS_IE;
3142 info->flags |= DF_STATIC_TLS;
3145 case R_ALPHA_TPREL64:
3146 if (info->shared || maybe_dynamic)
3149 info->flags |= DF_STATIC_TLS;
3153 if (need & NEED_GOT)
3157 if (!elf64_alpha_create_got_section (abfd, info))
3160 /* Make sure the object's gotobj is set to itself so
3161 that we default to every object with its own .got.
3162 We'll merge .gots later once we've collected each
3164 alpha_elf_tdata(abfd)->gotobj = abfd;
3170 if (need & NEED_GOT_ENTRY)
3172 struct alpha_elf_got_entry *gotent;
3174 gotent = get_got_entry (abfd, h, r_type, r_symndx, addend);
3180 gotent->flags |= gotent_flags;
3183 gotent_flags |= h->flags;
3184 h->flags = gotent_flags;
3186 /* Make a guess as to whether a .plt entry is needed. */
3187 if ((gotent_flags & ALPHA_ELF_LINK_HASH_LU_FUNC)
3188 && !(gotent_flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC))
3189 h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3191 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3196 if (need & NEED_DYNREL)
3198 if (rel_sec_name == NULL)
3200 rel_sec_name = (bfd_elf_string_from_elf_section
3201 (abfd, elf_elfheader(abfd)->e_shstrndx,
3202 elf_section_data(sec)->rel_hdr.sh_name));
3203 if (rel_sec_name == NULL)
3206 BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0
3207 && strcmp (bfd_get_section_name (abfd, sec),
3208 rel_sec_name+5) == 0);
3211 /* We need to create the section here now whether we eventually
3212 use it or not so that it gets mapped to an output section by
3213 the linker. If not used, we'll kill it in
3214 size_dynamic_sections. */
3217 sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
3222 sreloc = bfd_make_section (dynobj, rel_sec_name);
3223 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
3224 | SEC_LINKER_CREATED | SEC_READONLY);
3225 if (sec->flags & SEC_ALLOC)
3226 flags |= SEC_ALLOC | SEC_LOAD;
3228 || !bfd_set_section_flags (dynobj, sreloc, flags)
3229 || !bfd_set_section_alignment (dynobj, sreloc, 3))
3236 /* Since we havn't seen all of the input symbols yet, we
3237 don't know whether we'll actually need a dynamic relocation
3238 entry for this reloc. So make a record of it. Once we
3239 find out if this thing needs dynamic relocation we'll
3240 expand the relocation sections by the appropriate amount. */
3242 struct alpha_elf_reloc_entry *rent;
3244 for (rent = h->reloc_entries; rent; rent = rent->next)
3245 if (rent->rtype == r_type && rent->srel == sreloc)
3250 amt = sizeof (struct alpha_elf_reloc_entry);
3251 rent = (struct alpha_elf_reloc_entry *) bfd_alloc (abfd, amt);
3255 rent->srel = sreloc;
3256 rent->rtype = r_type;
3258 rent->reltext = ((sec->flags & (SEC_READONLY | SEC_ALLOC))
3259 == (SEC_READONLY | SEC_ALLOC));
3261 rent->next = h->reloc_entries;
3262 h->reloc_entries = rent;
3267 else if (info->shared)
3269 /* If this is a shared library, and the section is to be
3270 loaded into memory, we need a RELATIVE reloc. */
3271 sreloc->_raw_size += sizeof (Elf64_External_Rela);
3272 if ((sec->flags & (SEC_READONLY | SEC_ALLOC))
3273 == (SEC_READONLY | SEC_ALLOC))
3274 info->flags |= DF_TEXTREL;
3282 /* Adjust a symbol defined by a dynamic object and referenced by a
3283 regular object. The current definition is in some section of the
3284 dynamic object, but we're not including those sections. We have to
3285 change the definition to something the rest of the link can
3289 elf64_alpha_adjust_dynamic_symbol (info, h)
3290 struct bfd_link_info *info;
3291 struct elf_link_hash_entry *h;
3295 struct alpha_elf_link_hash_entry *ah;
3297 dynobj = elf_hash_table(info)->dynobj;
3298 ah = (struct alpha_elf_link_hash_entry *)h;
3300 /* Now that we've seen all of the input symbols, finalize our decision
3301 about whether this symbol should get a .plt entry. */
3303 if (alpha_elf_dynamic_symbol_p (h, info)
3304 && ((h->type == STT_FUNC
3305 && !(ah->flags & ALPHA_ELF_LINK_HASH_LU_ADDR))
3306 || (h->type == STT_NOTYPE
3307 && (ah->flags & ALPHA_ELF_LINK_HASH_LU_FUNC)
3308 && !(ah->flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC)))
3309 /* Don't prevent otherwise valid programs from linking by attempting
3310 to create a new .got entry somewhere. A Correct Solution would be
3311 to add a new .got section to a new object file and let it be merged
3312 somewhere later. But for now don't bother. */
3315 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3317 s = bfd_get_section_by_name(dynobj, ".plt");
3318 if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info))
3321 /* The first bit of the .plt is reserved. */
3322 if (s->_raw_size == 0)
3323 s->_raw_size = PLT_HEADER_SIZE;
3325 h->plt.offset = s->_raw_size;
3326 s->_raw_size += PLT_ENTRY_SIZE;
3328 /* If this symbol is not defined in a regular file, and we are not
3329 generating a shared library, then set the symbol to the location
3330 in the .plt. This is required to make function pointers compare
3331 equal between the normal executable and the shared library. */
3333 && h->root.type != bfd_link_hash_defweak)
3335 h->root.u.def.section = s;
3336 h->root.u.def.value = h->plt.offset;
3339 /* We also need a JMP_SLOT entry in the .rela.plt section. */
3340 s = bfd_get_section_by_name (dynobj, ".rela.plt");
3341 BFD_ASSERT (s != NULL);
3342 s->_raw_size += sizeof (Elf64_External_Rela);
3347 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3349 /* If this is a weak symbol, and there is a real definition, the
3350 processor independent code will have arranged for us to see the
3351 real definition first, and we can just use the same value. */
3352 if (h->weakdef != NULL)
3354 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3355 || h->weakdef->root.type == bfd_link_hash_defweak);
3356 h->root.u.def.section = h->weakdef->root.u.def.section;
3357 h->root.u.def.value = h->weakdef->root.u.def.value;
3361 /* This is a reference to a symbol defined by a dynamic object which
3362 is not a function. The Alpha, since it uses .got entries for all
3363 symbols even in regular objects, does not need the hackery of a
3364 .dynbss section and COPY dynamic relocations. */
3369 /* Symbol versioning can create new symbols, and make our old symbols
3370 indirect to the new ones. Consolidate the got and reloc information
3371 in these situations. */
3374 elf64_alpha_merge_ind_symbols (hi, dummy)
3375 struct alpha_elf_link_hash_entry *hi;
3376 PTR dummy ATTRIBUTE_UNUSED;
3378 struct alpha_elf_link_hash_entry *hs;
3380 if (hi->root.root.type != bfd_link_hash_indirect)
3384 hs = (struct alpha_elf_link_hash_entry *)hs->root.root.u.i.link;
3385 } while (hs->root.root.type == bfd_link_hash_indirect);
3387 /* Merge the flags. Whee. */
3389 hs->flags |= hi->flags;
3391 /* Merge the .got entries. Cannibalize the old symbol's list in
3392 doing so, since we don't need it anymore. */
3394 if (hs->got_entries == NULL)
3395 hs->got_entries = hi->got_entries;
3398 struct alpha_elf_got_entry *gi, *gs, *gin, *gsh;
3400 gsh = hs->got_entries;
3401 for (gi = hi->got_entries; gi ; gi = gin)
3404 for (gs = gsh; gs ; gs = gs->next)
3405 if (gi->gotobj == gs->gotobj
3406 && gi->reloc_type == gs->reloc_type
3407 && gi->addend == gs->addend)
3409 gi->use_count += gs->use_count;
3412 gi->next = hs->got_entries;
3413 hs->got_entries = gi;
3417 hi->got_entries = NULL;
3419 /* And similar for the reloc entries. */
3421 if (hs->reloc_entries == NULL)
3422 hs->reloc_entries = hi->reloc_entries;
3425 struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh;
3427 rsh = hs->reloc_entries;
3428 for (ri = hi->reloc_entries; ri ; ri = rin)
3431 for (rs = rsh; rs ; rs = rs->next)
3432 if (ri->rtype == rs->rtype)
3434 rs->count += ri->count;
3437 ri->next = hs->reloc_entries;
3438 hs->reloc_entries = ri;
3442 hi->reloc_entries = NULL;
3447 /* Is it possible to merge two object file's .got tables? */
3450 elf64_alpha_can_merge_gots (a, b)
3453 int total = alpha_elf_tdata (a)->total_got_size;
3456 /* Trivial quick fallout test. */
3457 if (total + alpha_elf_tdata (b)->total_got_size <= MAX_GOT_SIZE)
3460 /* By their nature, local .got entries cannot be merged. */
3461 if ((total += alpha_elf_tdata (b)->local_got_size) > MAX_GOT_SIZE)
3464 /* Failing the common trivial comparison, we must effectively
3465 perform the merge. Not actually performing the merge means that
3466 we don't have to store undo information in case we fail. */
3467 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
3469 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub);
3470 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
3473 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
3474 for (i = 0; i < n; ++i)
3476 struct alpha_elf_got_entry *ae, *be;
3477 struct alpha_elf_link_hash_entry *h;
3480 while (h->root.root.type == bfd_link_hash_indirect
3481 || h->root.root.type == bfd_link_hash_warning)
3482 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3484 for (be = h->got_entries; be ; be = be->next)
3486 if (be->use_count == 0)
3488 if (be->gotobj != b)
3491 for (ae = h->got_entries; ae ; ae = ae->next)
3493 && ae->reloc_type == be->reloc_type
3494 && ae->addend == be->addend)
3497 total += alpha_got_entry_size (be->reloc_type);
3498 if (total > MAX_GOT_SIZE)
3508 /* Actually merge two .got tables. */
3511 elf64_alpha_merge_gots (a, b)
3514 int total = alpha_elf_tdata (a)->total_got_size;
3517 /* Remember local expansion. */
3519 int e = alpha_elf_tdata (b)->local_got_size;
3521 alpha_elf_tdata (a)->local_got_size += e;
3524 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
3526 struct alpha_elf_got_entry **local_got_entries;
3527 struct alpha_elf_link_hash_entry **hashes;
3528 Elf_Internal_Shdr *symtab_hdr;
3531 /* Let the local .got entries know they are part of a new subsegment. */
3532 local_got_entries = alpha_elf_tdata (bsub)->local_got_entries;
3533 if (local_got_entries)
3535 n = elf_tdata (bsub)->symtab_hdr.sh_info;
3536 for (i = 0; i < n; ++i)
3538 struct alpha_elf_got_entry *ent;
3539 for (ent = local_got_entries[i]; ent; ent = ent->next)
3544 /* Merge the global .got entries. */
3545 hashes = alpha_elf_sym_hashes (bsub);
3546 symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
3548 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
3549 for (i = 0; i < n; ++i)
3551 struct alpha_elf_got_entry *ae, *be, **pbe, **start;
3552 struct alpha_elf_link_hash_entry *h;
3555 while (h->root.root.type == bfd_link_hash_indirect
3556 || h->root.root.type == bfd_link_hash_warning)
3557 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3559 start = &h->got_entries;
3560 for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
3562 if (be->use_count == 0)
3567 if (be->gotobj != b)
3570 for (ae = *start; ae ; ae = ae->next)
3572 && ae->reloc_type == be->reloc_type
3573 && ae->addend == be->addend)
3575 ae->flags |= be->flags;
3576 ae->use_count += be->use_count;
3581 total += alpha_got_entry_size (be->reloc_type);
3587 alpha_elf_tdata (bsub)->gotobj = a;
3589 alpha_elf_tdata (a)->total_got_size = total;
3591 /* Merge the two in_got chains. */
3596 while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL)
3599 alpha_elf_tdata (bsub)->in_got_link_next = b;
3603 /* Calculate the offsets for the got entries. */
3606 elf64_alpha_calc_got_offsets_for_symbol (h, arg)
3607 struct alpha_elf_link_hash_entry *h;
3608 PTR arg ATTRIBUTE_UNUSED;
3610 struct alpha_elf_got_entry *gotent;
3612 if (h->root.root.type == bfd_link_hash_warning)
3613 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
3615 for (gotent = h->got_entries; gotent; gotent = gotent->next)
3616 if (gotent->use_count > 0)
3619 = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
3621 gotent->got_offset = *plge;
3622 *plge += alpha_got_entry_size (gotent->reloc_type);
3629 elf64_alpha_calc_got_offsets (info)
3630 struct bfd_link_info *info;
3632 bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
3634 /* First, zero out the .got sizes, as we may be recalculating the
3635 .got after optimizing it. */
3636 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
3637 alpha_elf_tdata(i)->got->_raw_size = 0;
3639 /* Next, fill in the offsets for all the global entries. */
3640 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3641 elf64_alpha_calc_got_offsets_for_symbol,
3644 /* Finally, fill in the offsets for the local entries. */
3645 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
3647 bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
3650 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
3652 struct alpha_elf_got_entry **local_got_entries, *gotent;
3655 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
3656 if (!local_got_entries)
3659 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
3660 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
3661 if (gotent->use_count > 0)
3663 gotent->got_offset = got_offset;
3664 got_offset += alpha_got_entry_size (gotent->reloc_type);
3668 alpha_elf_tdata(i)->got->_raw_size = got_offset;
3669 alpha_elf_tdata(i)->got->_cooked_size = got_offset;
3673 /* Constructs the gots. */
3676 elf64_alpha_size_got_sections (info)
3677 struct bfd_link_info *info;
3679 bfd *i, *got_list, *cur_got_obj = NULL;
3680 int something_changed = 0;
3682 got_list = alpha_elf_hash_table (info)->got_list;
3684 /* On the first time through, pretend we have an existing got list
3685 consisting of all of the input files. */
3686 if (got_list == NULL)
3688 for (i = info->input_bfds; i ; i = i->link_next)
3690 bfd *this_got = alpha_elf_tdata (i)->gotobj;
3691 if (this_got == NULL)
3694 /* We are assuming no merging has yet ocurred. */
3695 BFD_ASSERT (this_got == i);
3697 if (alpha_elf_tdata (this_got)->total_got_size > MAX_GOT_SIZE)
3699 /* Yikes! A single object file has too many entries. */
3700 (*_bfd_error_handler)
3701 (_("%s: .got subsegment exceeds 64K (size %d)"),
3702 bfd_archive_filename (i),
3703 alpha_elf_tdata (this_got)->total_got_size);
3707 if (got_list == NULL)
3708 got_list = this_got;
3710 alpha_elf_tdata(cur_got_obj)->got_link_next = this_got;
3711 cur_got_obj = this_got;
3714 /* Strange degenerate case of no got references. */
3715 if (got_list == NULL)
3718 alpha_elf_hash_table (info)->got_list = got_list;
3720 /* Force got offsets to be recalculated. */
3721 something_changed = 1;
3724 cur_got_obj = got_list;
3725 i = alpha_elf_tdata(cur_got_obj)->got_link_next;
3728 if (elf64_alpha_can_merge_gots (cur_got_obj, i))
3730 elf64_alpha_merge_gots (cur_got_obj, i);
3731 i = alpha_elf_tdata(i)->got_link_next;
3732 alpha_elf_tdata(cur_got_obj)->got_link_next = i;
3733 something_changed = 1;
3738 i = alpha_elf_tdata(i)->got_link_next;
3742 /* Once the gots have been merged, fill in the got offsets for
3743 everything therein. */
3744 if (1 || something_changed)
3745 elf64_alpha_calc_got_offsets (info);
3750 /* Called from relax_section to rebuild the PLT in light of
3751 potential changes in the function's status. */
3754 elf64_alpha_size_plt_section (info)
3755 struct bfd_link_info *info;
3757 asection *splt, *spltrel;
3758 unsigned long entries;
3761 dynobj = elf_hash_table(info)->dynobj;
3762 splt = bfd_get_section_by_name(dynobj, ".plt");
3766 splt->_raw_size = 0;
3768 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3769 elf64_alpha_size_plt_section_1, splt);
3771 splt->_cooked_size = splt->_raw_size;
3773 /* Every plt entry requires a JMP_SLOT relocation. */
3774 spltrel = bfd_get_section_by_name (dynobj, ".rela.plt");
3775 if (splt->_raw_size)
3776 entries = (splt->_raw_size - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
3779 spltrel->_raw_size = entries * sizeof (Elf64_External_Rela);
3780 spltrel->_cooked_size = spltrel->_raw_size;
3786 elf64_alpha_size_plt_section_1 (h, data)
3787 struct alpha_elf_link_hash_entry *h;
3790 asection *splt = (asection *) data;
3791 struct alpha_elf_got_entry *gotent;
3793 /* If we didn't need an entry before, we still don't. */
3794 if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT))
3797 /* There must still be a LITERAL got entry for the function. */
3798 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
3799 if (gotent->reloc_type == R_ALPHA_LITERAL
3800 && gotent->use_count > 0)
3803 /* If there is, reset the PLT offset. If not, there's no longer
3804 a need for the PLT entry. */
3807 if (splt->_raw_size == 0)
3808 splt->_raw_size = PLT_HEADER_SIZE;
3809 h->root.plt.offset = splt->_raw_size;
3810 splt->_raw_size += PLT_ENTRY_SIZE;
3814 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3815 h->root.plt.offset = -1;
3822 elf64_alpha_always_size_sections (output_bfd, info)
3823 bfd *output_bfd ATTRIBUTE_UNUSED;
3824 struct bfd_link_info *info;
3828 if (info->relocateable)
3831 /* First, take care of the indirect symbols created by versioning. */
3832 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3833 elf64_alpha_merge_ind_symbols,
3836 if (!elf64_alpha_size_got_sections (info))
3839 /* Allocate space for all of the .got subsections. */
3840 i = alpha_elf_hash_table (info)->got_list;
3841 for ( ; i ; i = alpha_elf_tdata(i)->got_link_next)
3843 asection *s = alpha_elf_tdata(i)->got;
3844 if (s->_raw_size > 0)
3846 s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
3847 if (s->contents == NULL)
3855 /* The number of dynamic relocations required by a static relocation. */
3858 alpha_dynamic_entries_for_reloc (r_type, dynamic, shared)
3859 int r_type, dynamic, shared;
3863 /* May appear in GOT entries. */
3865 return (dynamic ? 2 : shared ? 1 : 0);
3866 case R_ALPHA_TLSLDM:
3868 case R_ALPHA_LITERAL:
3869 return dynamic || shared;
3870 case R_ALPHA_GOTDTPREL:
3871 case R_ALPHA_GOTTPREL:
3874 /* May appear in data sections. */
3875 case R_ALPHA_REFLONG:
3876 case R_ALPHA_REFQUAD:
3877 return dynamic || shared;
3878 case R_ALPHA_SREL64:
3879 case R_ALPHA_TPREL64:
3882 /* Everything else is illegal. We'll issue an error during
3883 relocate_section. */
3889 /* Work out the sizes of the dynamic relocation entries. */
3892 elf64_alpha_calc_dynrel_sizes (h, info)
3893 struct alpha_elf_link_hash_entry *h;
3894 struct bfd_link_info *info;
3897 struct alpha_elf_reloc_entry *relent;
3898 unsigned long entries;
3900 if (h->root.root.type == bfd_link_hash_warning)
3901 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
3903 /* If the symbol was defined as a common symbol in a regular object
3904 file, and there was no definition in any dynamic object, then the
3905 linker will have allocated space for the symbol in a common
3906 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3907 set. This is done for dynamic symbols in
3908 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3909 symbols, somehow. */
3910 if (((h->root.elf_link_hash_flags
3911 & (ELF_LINK_HASH_DEF_REGULAR
3912 | ELF_LINK_HASH_REF_REGULAR
3913 | ELF_LINK_HASH_DEF_DYNAMIC))
3914 == ELF_LINK_HASH_REF_REGULAR)
3915 && (h->root.root.type == bfd_link_hash_defined
3916 || h->root.root.type == bfd_link_hash_defweak)
3917 && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
3918 h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3920 /* If the symbol is dynamic, we'll need all the relocations in their
3921 natural form. If this is a shared object, and it has been forced
3922 local, we'll need the same number of RELATIVE relocations. */
3924 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info);
3926 for (relent = h->reloc_entries; relent; relent = relent->next)
3928 entries = alpha_dynamic_entries_for_reloc (relent->rtype, dynamic,
3932 relent->srel->_raw_size +=
3933 entries * sizeof (Elf64_External_Rela) * relent->count;
3934 if (relent->reltext)
3935 info->flags |= DT_TEXTREL;
3942 /* Set the sizes of the dynamic relocation sections. */
3945 elf64_alpha_size_rela_got_section (info)
3946 struct bfd_link_info *info;
3948 unsigned long entries;
3952 /* Shared libraries often require RELATIVE relocs, and some relocs
3953 require attention for the main application as well. */
3956 for (i = alpha_elf_hash_table(info)->got_list;
3957 i ; i = alpha_elf_tdata(i)->got_link_next)
3961 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
3963 struct alpha_elf_got_entry **local_got_entries, *gotent;
3966 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
3967 if (!local_got_entries)
3970 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
3971 for (gotent = local_got_entries[k];
3972 gotent ; gotent = gotent->next)
3973 if (gotent->use_count > 0)
3974 entries += (alpha_dynamic_entries_for_reloc
3975 (gotent->reloc_type, 0, info->shared));
3979 dynobj = elf_hash_table(info)->dynobj;
3980 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3983 BFD_ASSERT (entries == 0);
3986 srel->_raw_size = sizeof (Elf64_External_Rela) * entries;
3988 /* Now do the non-local symbols. */
3989 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3990 elf64_alpha_size_rela_got_1, info);
3992 srel->_cooked_size = srel->_raw_size;
3997 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
4001 elf64_alpha_size_rela_got_1 (h, info)
4002 struct alpha_elf_link_hash_entry *h;
4003 struct bfd_link_info *info;
4006 struct alpha_elf_got_entry *gotent;
4007 unsigned long entries;
4009 if (h->root.root.type == bfd_link_hash_warning)
4010 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
4012 /* If the symbol is dynamic, we'll need all the relocations in their
4013 natural form. If this is a shared object, and it has been forced
4014 local, we'll need the same number of RELATIVE relocations. */
4016 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info);
4019 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
4020 if (gotent->use_count > 0)
4021 entries += alpha_dynamic_entries_for_reloc (gotent->reloc_type,
4022 dynamic, info->shared);
4024 /* If we are using a .plt entry, subtract one, as the first
4025 reference uses a .rela.plt entry instead. */
4026 if (h->root.plt.offset != MINUS_ONE)
4031 bfd *dynobj = elf_hash_table(info)->dynobj;
4032 asection *srel = bfd_get_section_by_name (dynobj, ".rela.got");
4033 BFD_ASSERT (srel != NULL);
4034 srel->_raw_size += sizeof (Elf64_External_Rela) * entries;
4040 /* Set the sizes of the dynamic sections. */
4043 elf64_alpha_size_dynamic_sections (output_bfd, info)
4044 bfd *output_bfd ATTRIBUTE_UNUSED;
4045 struct bfd_link_info *info;
4051 dynobj = elf_hash_table(info)->dynobj;
4052 BFD_ASSERT(dynobj != NULL);
4054 if (elf_hash_table (info)->dynamic_sections_created)
4056 /* Set the contents of the .interp section to the interpreter. */
4059 s = bfd_get_section_by_name (dynobj, ".interp");
4060 BFD_ASSERT (s != NULL);
4061 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4062 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4065 /* Now that we've seen all of the input files, we can decide which
4066 symbols need dynamic relocation entries and which don't. We've
4067 collected information in check_relocs that we can now apply to
4068 size the dynamic relocation sections. */
4069 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
4070 elf64_alpha_calc_dynrel_sizes, info);
4072 elf64_alpha_size_rela_got_section (info);
4074 /* else we're not dynamic and by definition we don't need such things. */
4076 /* The check_relocs and adjust_dynamic_symbol entry points have
4077 determined the sizes of the various dynamic sections. Allocate
4080 for (s = dynobj->sections; s != NULL; s = s->next)
4085 if (!(s->flags & SEC_LINKER_CREATED))
4088 /* It's OK to base decisions on the section name, because none
4089 of the dynobj section names depend upon the input files. */
4090 name = bfd_get_section_name (dynobj, s);
4092 /* If we don't need this section, strip it from the output file.
4093 This is to handle .rela.bss and .rela.plt. We must create it
4094 in create_dynamic_sections, because it must be created before
4095 the linker maps input sections to output sections. The
4096 linker does that before adjust_dynamic_symbol is called, and
4097 it is that function which decides whether anything needs to
4098 go into these sections. */
4102 if (strncmp (name, ".rela", 5) == 0)
4104 strip = (s->_raw_size == 0);
4108 if (strcmp(name, ".rela.plt") == 0)
4111 /* We use the reloc_count field as a counter if we need
4112 to copy relocs into the output file. */
4116 else if (strcmp (name, ".plt") != 0)
4118 /* It's not one of our dynamic sections, so don't allocate space. */
4123 _bfd_strip_section_from_output (info, s);
4126 /* Allocate memory for the section contents. */
4127 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4128 if (s->contents == NULL && s->_raw_size != 0)
4133 if (elf_hash_table (info)->dynamic_sections_created)
4135 /* Add some entries to the .dynamic section. We fill in the
4136 values later, in elf64_alpha_finish_dynamic_sections, but we
4137 must add the entries now so that we get the correct size for
4138 the .dynamic section. The DT_DEBUG entry is filled in by the
4139 dynamic linker and used by the debugger. */
4140 #define add_dynamic_entry(TAG, VAL) \
4141 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4145 if (!add_dynamic_entry (DT_DEBUG, 0))
4149 if (!add_dynamic_entry (DT_PLTGOT, 0))
4154 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
4155 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4156 || !add_dynamic_entry (DT_JMPREL, 0))
4160 if (!add_dynamic_entry (DT_RELA, 0)
4161 || !add_dynamic_entry (DT_RELASZ, 0)
4162 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
4165 if (info->flags & DF_TEXTREL)
4167 if (!add_dynamic_entry (DT_TEXTREL, 0))
4171 #undef add_dynamic_entry
4176 /* Relocate an Alpha ELF section. */
4179 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
4180 contents, relocs, local_syms, local_sections)
4182 struct bfd_link_info *info;
4184 asection *input_section;
4186 Elf_Internal_Rela *relocs;
4187 Elf_Internal_Sym *local_syms;
4188 asection **local_sections;
4190 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4191 Elf_Internal_Rela *rel;
4192 Elf_Internal_Rela *relend;
4193 struct elf_link_tls_segment *tls_segment = NULL;
4194 asection *sgot = NULL, *srel = NULL, *srelgot = NULL;
4195 bfd *dynobj = NULL, *gotobj = NULL;
4196 bfd_vma gp = 0, tp_base = 0, dtp_base = 0;
4197 boolean ret_val = true;
4199 if (!info->relocateable)
4203 dynobj = elf_hash_table (info)->dynobj;
4205 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
4207 name = (bfd_elf_string_from_elf_section
4208 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
4209 elf_section_data(input_section)->rel_hdr.sh_name));
4210 BFD_ASSERT(name != NULL);
4211 srel = bfd_get_section_by_name (dynobj, name);
4213 /* Find the gp value for this input bfd. */
4214 gotobj = alpha_elf_tdata (input_bfd)->gotobj;
4217 sgot = alpha_elf_tdata (gotobj)->got;
4218 gp = _bfd_get_gp_value (gotobj);
4221 gp = (sgot->output_section->vma
4222 + sgot->output_offset
4224 _bfd_set_gp_value (gotobj, gp);
4228 tls_segment = elf_hash_table (info)->tls_segment;
4231 dtp_base = alpha_get_dtprel_base (tls_segment);
4232 tp_base = alpha_get_tprel_base (tls_segment);
4237 relend = relocs + input_section->reloc_count;
4238 for (; rel < relend; rel++)
4240 struct alpha_elf_link_hash_entry *h;
4241 struct alpha_elf_got_entry *gotent;
4242 bfd_reloc_status_type r;
4243 reloc_howto_type *howto;
4244 unsigned long r_symndx;
4245 Elf_Internal_Sym *sym;
4249 boolean dynamic_symbol_p;
4250 boolean undef_weak_ref;
4251 unsigned long r_type;
4253 r_type = ELF64_R_TYPE(rel->r_info);
4254 if (r_type >= R_ALPHA_max)
4256 (*_bfd_error_handler)
4257 (_("%s: unknown relocation type %d"),
4258 bfd_archive_filename (input_bfd), (int)r_type);
4259 bfd_set_error (bfd_error_bad_value);
4264 howto = elf64_alpha_howto_table + r_type;
4265 r_symndx = ELF64_R_SYM(rel->r_info);
4267 if (info->relocateable)
4269 /* This is a relocateable link. We don't have to change
4270 anything, unless the reloc is against a section symbol,
4271 in which case we have to adjust according to where the
4272 section symbol winds up in the output section. */
4274 /* The symbol associated with GPDISP and LITUSE is
4275 immaterial. Only the addend is significant. */
4276 if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE)
4279 if (r_symndx < symtab_hdr->sh_info)
4281 sym = local_syms + r_symndx;
4282 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
4284 sec = local_sections[r_symndx];
4285 rel->r_addend += sec->output_offset + sym->st_value;
4292 /* This is a final link. */
4297 undef_weak_ref = false;
4299 if (r_symndx < symtab_hdr->sh_info)
4301 sym = local_syms + r_symndx;
4302 sec = local_sections[r_symndx];
4303 value = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4305 gotent = alpha_elf_tdata(input_bfd)->local_got_entries[r_symndx];
4307 /* Need to adjust local GOT entries' addends for SEC_MERGE
4308 unless it has been done already. */
4309 if ((sec->flags & SEC_MERGE)
4310 && ELF_ST_TYPE (sym->st_info) == STT_SECTION
4311 && (elf_section_data (sec)->sec_info_type
4312 == ELF_INFO_TYPE_MERGE)
4313 && !gotent->reloc_xlated)
4315 struct alpha_elf_got_entry *ent;
4318 for (ent = gotent; ent; ent = ent->next)
4320 ent->reloc_xlated = 1;
4321 if (ent->use_count == 0)
4325 _bfd_merged_section_offset (output_bfd, &msec,
4326 elf_section_data (sec)->
4328 sym->st_value + ent->addend,
4330 ent->addend -= sym->st_value;
4331 ent->addend += msec->output_section->vma
4332 + msec->output_offset
4333 - sec->output_section->vma
4334 - sec->output_offset;
4338 dynamic_symbol_p = false;
4342 h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info];
4344 while (h->root.root.type == bfd_link_hash_indirect
4345 || h->root.root.type == bfd_link_hash_warning)
4346 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
4349 if (h->root.root.type == bfd_link_hash_defined
4350 || h->root.root.type == bfd_link_hash_defweak)
4352 sec = h->root.root.u.def.section;
4354 /* Detect the cases that sym_sec->output_section is
4355 expected to be NULL -- all cases in which the symbol
4356 is defined in another shared module. This includes
4357 PLT relocs for which we've created a PLT entry and
4358 other relocs for which we're prepared to create
4359 dynamic relocations. */
4360 /* ??? Just accept it NULL and continue. */
4362 if (sec->output_section != NULL)
4363 value = (h->root.root.u.def.value
4364 + sec->output_section->vma
4365 + sec->output_offset);
4367 else if (h->root.root.type == bfd_link_hash_undefweak)
4368 undef_weak_ref = true;
4369 else if (info->shared
4370 && (!info->symbolic || info->allow_shlib_undefined)
4371 && !info->no_undefined
4372 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
4376 if (!((*info->callbacks->undefined_symbol)
4377 (info, h->root.root.root.string, input_bfd,
4378 input_section, rel->r_offset,
4379 (!info->shared || info->no_undefined
4380 || ELF_ST_VISIBILITY (h->root.other)))))
4386 dynamic_symbol_p = alpha_elf_dynamic_symbol_p (&h->root, info);
4387 gotent = h->got_entries;
4390 addend = rel->r_addend;
4393 /* Search for the proper got entry. */
4394 for (; gotent ; gotent = gotent->next)
4395 if (gotent->gotobj == gotobj
4396 && gotent->reloc_type == r_type
4397 && gotent->addend == addend)
4402 case R_ALPHA_GPDISP:
4404 bfd_byte *p_ldah, *p_lda;
4406 BFD_ASSERT(gp != 0);
4408 value = (input_section->output_section->vma
4409 + input_section->output_offset
4412 p_ldah = contents + rel->r_offset;
4413 p_lda = p_ldah + rel->r_addend;
4415 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - value,
4420 case R_ALPHA_LITERAL:
4421 BFD_ASSERT(sgot != NULL);
4422 BFD_ASSERT(gp != 0);
4423 BFD_ASSERT(gotent != NULL);
4424 BFD_ASSERT(gotent->use_count >= 1);
4426 if (!gotent->reloc_done)
4428 gotent->reloc_done = 1;
4430 bfd_put_64 (output_bfd, value,
4431 sgot->contents + gotent->got_offset);
4433 /* If the symbol has been forced local, output a
4434 RELATIVE reloc, otherwise it will be handled in
4435 finish_dynamic_symbol. */
4436 if (info->shared && !dynamic_symbol_p)
4438 Elf_Internal_Rela outrel;
4440 BFD_ASSERT(srelgot != NULL);
4442 outrel.r_offset = (sgot->output_section->vma
4443 + sgot->output_offset
4444 + gotent->got_offset);
4445 outrel.r_info = ELF64_R_INFO (0, R_ALPHA_RELATIVE);
4446 outrel.r_addend = value;
4448 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
4449 ((Elf64_External_Rela *)
4451 + srelgot->reloc_count++);
4452 BFD_ASSERT (sizeof (Elf64_External_Rela)
4453 * srelgot->reloc_count
4454 <= srelgot->_cooked_size);
4458 value = (sgot->output_section->vma
4459 + sgot->output_offset
4460 + gotent->got_offset);
4464 case R_ALPHA_GPREL16:
4465 case R_ALPHA_GPREL32:
4466 case R_ALPHA_GPRELLOW:
4467 if (dynamic_symbol_p)
4469 (*_bfd_error_handler)
4470 (_("%s: gp-relative relocation against dynamic symbol %s"),
4471 bfd_archive_filename (input_bfd), h->root.root.root.string);
4474 BFD_ASSERT(gp != 0);
4478 case R_ALPHA_GPRELHIGH:
4479 if (dynamic_symbol_p)
4481 (*_bfd_error_handler)
4482 (_("%s: gp-relative relocation against dynamic symbol %s"),
4483 bfd_archive_filename (input_bfd), h->root.root.root.string);
4486 BFD_ASSERT(gp != 0);
4488 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4492 /* A call to a dynamic symbol is definitely out of range of
4493 the 16-bit displacement. Don't bother writing anything. */
4494 if (dynamic_symbol_p)
4499 /* The regular PC-relative stuff measures from the start of
4500 the instruction rather than the end. */
4504 case R_ALPHA_BRADDR:
4505 if (dynamic_symbol_p)
4507 (*_bfd_error_handler)
4508 (_("%s: pc-relative relocation against dynamic symbol %s"),
4509 bfd_archive_filename (input_bfd), h->root.root.root.string);
4512 /* The regular PC-relative stuff measures from the start of
4513 the instruction rather than the end. */
4522 /* The regular PC-relative stuff measures from the start of
4523 the instruction rather than the end. */
4526 /* The source and destination gp must be the same. Note that
4527 the source will always have an assigned gp, since we forced
4528 one in check_relocs, but that the destination may not, as
4529 it might not have had any relocations at all. Also take
4530 care not to crash if H is an undefined symbol. */
4531 if (h != NULL && sec != NULL
4532 && alpha_elf_tdata (sec->owner)->gotobj
4533 && gotobj != alpha_elf_tdata (sec->owner)->gotobj)
4535 (*_bfd_error_handler)
4536 (_("%s: change in gp: BRSGP %s"),
4537 bfd_archive_filename (input_bfd), h->root.root.root.string);
4541 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4543 other = h->root.other;
4545 other = sym->st_other;
4546 switch (other & STO_ALPHA_STD_GPLOAD)
4548 case STO_ALPHA_NOPV:
4550 case STO_ALPHA_STD_GPLOAD:
4555 name = h->root.root.root.string;
4558 name = (bfd_elf_string_from_elf_section
4559 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4561 name = _("<unknown>");
4562 else if (name[0] == 0)
4563 name = bfd_section_name (input_bfd, sec);
4565 (*_bfd_error_handler)
4566 (_("%s: !samegp reloc against symbol without .prologue: %s"),
4567 bfd_archive_filename (input_bfd), name);
4575 case R_ALPHA_REFLONG:
4576 case R_ALPHA_REFQUAD:
4577 case R_ALPHA_DTPREL64:
4578 case R_ALPHA_TPREL64:
4580 Elf_Internal_Rela outrel;
4582 /* Careful here to remember RELATIVE relocations for global
4583 variables for symbolic shared objects. */
4585 if (dynamic_symbol_p)
4587 BFD_ASSERT(h->root.dynindx != -1);
4588 outrel.r_info = ELF64_R_INFO (h->root.dynindx, r_type);
4589 outrel.r_addend = addend;
4590 addend = 0, value = 0;
4592 else if (r_type == R_ALPHA_DTPREL64)
4594 BFD_ASSERT(tls_segment != NULL);
4598 else if (r_type == R_ALPHA_TPREL64)
4600 BFD_ASSERT(tls_segment != NULL);
4604 else if (info->shared
4606 && (input_section->flags & SEC_ALLOC))
4608 if (r_type == R_ALPHA_REFLONG)
4610 (*_bfd_error_handler)
4611 (_("%s: unhandled dynamic relocation against %s"),
4612 bfd_archive_filename (input_bfd),
4613 h->root.root.root.string);
4616 outrel.r_info = ELF64_R_INFO (0, R_ALPHA_RELATIVE);
4617 outrel.r_addend = value;
4622 BFD_ASSERT(srel != NULL);
4625 _bfd_elf_section_offset (output_bfd, info, input_section,
4627 if ((outrel.r_offset | 1) != (bfd_vma) -1)
4628 outrel.r_offset += (input_section->output_section->vma
4629 + input_section->output_offset);
4631 memset (&outrel, 0, sizeof outrel);
4633 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
4634 ((Elf64_External_Rela *)
4636 + srel->reloc_count++);
4637 BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
4638 <= srel->_cooked_size);
4642 case R_ALPHA_SREL16:
4643 case R_ALPHA_SREL32:
4644 case R_ALPHA_SREL64:
4645 if (dynamic_symbol_p)
4647 (*_bfd_error_handler)
4648 (_("%s: pc-relative relocation against dynamic symbol %s"),
4649 bfd_archive_filename (input_bfd), h->root.root.root.string);
4653 /* ??? .eh_frame references to discarded sections will be smashed
4654 to relocations against SHN_UNDEF. The .eh_frame format allows
4655 NULL to be encoded as 0 in any format, so this works here. */
4657 howto = (elf64_alpha_howto_table
4658 + (r_type - R_ALPHA_SREL32 + R_ALPHA_REFLONG));
4661 case R_ALPHA_TLSLDM:
4662 /* Ignore the symbol for the relocation. The result is always
4663 the current module. */
4664 dynamic_symbol_p = 0;
4668 if (!gotent->reloc_done)
4670 gotent->reloc_done = 1;
4672 /* Note that the module index for the main program is 1. */
4673 bfd_put_64 (output_bfd, !info->shared && !dynamic_symbol_p,
4674 sgot->contents + gotent->got_offset);
4676 /* If the symbol has been forced local, output a
4677 DTPMOD64 reloc, otherwise it will be handled in
4678 finish_dynamic_symbol. */
4679 if (info->shared && !dynamic_symbol_p)
4681 Elf_Internal_Rela outrel;
4683 BFD_ASSERT(srelgot != NULL);
4685 outrel.r_offset = (sgot->output_section->vma
4686 + sgot->output_offset
4687 + gotent->got_offset);
4688 /* ??? Proper dynindx here. */
4689 outrel.r_info = ELF64_R_INFO (0, R_ALPHA_DTPMOD64);
4690 outrel.r_addend = 0;
4692 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
4693 ((Elf64_External_Rela *)
4695 + srelgot->reloc_count++);
4696 BFD_ASSERT (sizeof (Elf64_External_Rela)
4697 * srelgot->reloc_count
4698 <= srelgot->_cooked_size);
4701 if (dynamic_symbol_p || r_type == R_ALPHA_TLSLDM)
4705 BFD_ASSERT(tls_segment != NULL);
4708 bfd_put_64 (output_bfd, value,
4709 sgot->contents + gotent->got_offset + 8);
4712 value = (sgot->output_section->vma
4713 + sgot->output_offset
4714 + gotent->got_offset);
4718 case R_ALPHA_DTPRELHI:
4719 case R_ALPHA_DTPRELLO:
4720 case R_ALPHA_DTPREL16:
4721 if (dynamic_symbol_p)
4723 (*_bfd_error_handler)
4724 (_("%s: dtp-relative relocation against dynamic symbol %s"),
4725 bfd_archive_filename (input_bfd), h->root.root.root.string);
4728 BFD_ASSERT(tls_segment != NULL);
4730 if (r_type == R_ALPHA_DTPRELHI)
4731 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4734 case R_ALPHA_TPRELHI:
4735 case R_ALPHA_TPRELLO:
4736 case R_ALPHA_TPREL16:
4739 (*_bfd_error_handler)
4740 (_("%s: TLS local exec code cannot be linked into shared objects"),
4741 bfd_archive_filename (input_bfd));
4744 else if (dynamic_symbol_p)
4746 (*_bfd_error_handler)
4747 (_("%s: tp-relative relocation against dynamic symbol %s"),
4748 bfd_archive_filename (input_bfd), h->root.root.root.string);
4751 BFD_ASSERT(tls_segment != NULL);
4753 if (r_type == R_ALPHA_TPRELHI)
4754 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4757 case R_ALPHA_GOTDTPREL:
4758 case R_ALPHA_GOTTPREL:
4759 BFD_ASSERT(sgot != NULL);
4760 BFD_ASSERT(gp != 0);
4761 BFD_ASSERT(gotent != NULL);
4762 BFD_ASSERT(gotent->use_count >= 1);
4764 if (!gotent->reloc_done)
4766 gotent->reloc_done = 1;
4768 if (dynamic_symbol_p)
4772 BFD_ASSERT(tls_segment != NULL);
4773 value -= (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base);
4775 bfd_put_64 (output_bfd, value,
4776 sgot->contents + gotent->got_offset);
4779 value = (sgot->output_section->vma
4780 + sgot->output_offset
4781 + gotent->got_offset);
4787 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4788 contents, rel->r_offset, value, 0);
4797 case bfd_reloc_overflow:
4801 /* Don't warn if the overflow is due to pc relative reloc
4802 against discarded section. Section optimization code should
4805 if (r_symndx < symtab_hdr->sh_info
4806 && sec != NULL && howto->pc_relative
4807 && elf_discarded_section (sec))
4811 name = h->root.root.root.string;
4814 name = (bfd_elf_string_from_elf_section
4815 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4819 name = bfd_section_name (input_bfd, sec);
4821 if (! ((*info->callbacks->reloc_overflow)
4822 (info, name, howto->name, (bfd_vma) 0,
4823 input_bfd, input_section, rel->r_offset)))
4829 case bfd_reloc_outofrange:
4837 /* Finish up dynamic symbol handling. We set the contents of various
4838 dynamic sections here. */
4841 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
4843 struct bfd_link_info *info;
4844 struct elf_link_hash_entry *h;
4845 Elf_Internal_Sym *sym;
4847 bfd *dynobj = elf_hash_table(info)->dynobj;
4849 if (h->plt.offset != MINUS_ONE)
4851 /* Fill in the .plt entry for this symbol. */
4852 asection *splt, *sgot, *srel;
4853 Elf_Internal_Rela outrel;
4854 bfd_vma got_addr, plt_addr;
4856 struct alpha_elf_got_entry *gotent;
4858 BFD_ASSERT (h->dynindx != -1);
4860 /* The first .got entry will be updated by the .plt with the
4861 address of the target function. */
4862 gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
4863 BFD_ASSERT (gotent && gotent->addend == 0);
4865 splt = bfd_get_section_by_name (dynobj, ".plt");
4866 BFD_ASSERT (splt != NULL);
4867 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4868 BFD_ASSERT (srel != NULL);
4869 sgot = alpha_elf_tdata (gotent->gotobj)->got;
4870 BFD_ASSERT (sgot != NULL);
4872 got_addr = (sgot->output_section->vma
4873 + sgot->output_offset
4874 + gotent->got_offset);
4875 plt_addr = (splt->output_section->vma
4876 + splt->output_offset
4879 plt_index = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
4881 /* Fill in the entry in the procedure linkage table. */
4883 bfd_vma insn1, insn2, insn3;
4885 insn1 = PLT_ENTRY_WORD1 | ((-(h->plt.offset + 4) >> 2) & 0x1fffff);
4886 insn2 = PLT_ENTRY_WORD2;
4887 insn3 = PLT_ENTRY_WORD3;
4889 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt.offset);
4890 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt.offset + 4);
4891 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt.offset + 8);
4894 /* Fill in the entry in the .rela.plt section. */
4895 outrel.r_offset = got_addr;
4896 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
4897 outrel.r_addend = 0;
4899 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
4900 ((Elf64_External_Rela *)srel->contents
4903 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
4905 /* Mark the symbol as undefined, rather than as defined in the
4906 .plt section. Leave the value alone. */
4907 sym->st_shndx = SHN_UNDEF;
4910 /* Fill in the entries in the .got. */
4911 bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
4913 /* Subsequent .got entries will continue to bounce through the .plt. */
4916 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4917 BFD_ASSERT (! info->shared || srel != NULL);
4919 gotent = gotent->next;
4922 sgot = alpha_elf_tdata(gotent->gotobj)->got;
4923 BFD_ASSERT(sgot != NULL);
4924 BFD_ASSERT(gotent->addend == 0);
4926 bfd_put_64 (output_bfd, plt_addr,
4927 sgot->contents + gotent->got_offset);
4931 outrel.r_offset = (sgot->output_section->vma
4932 + sgot->output_offset
4933 + gotent->got_offset);
4934 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
4935 outrel.r_addend = plt_addr;
4937 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
4938 ((Elf64_External_Rela *)
4940 + srel->reloc_count++);
4941 BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
4942 <= srel->_cooked_size);
4945 gotent = gotent->next;
4947 while (gotent != NULL);
4950 else if (alpha_elf_dynamic_symbol_p (h, info))
4952 /* Fill in the dynamic relocations for this symbol's .got entries. */
4954 Elf_Internal_Rela outrel;
4955 struct alpha_elf_got_entry *gotent;
4957 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4958 BFD_ASSERT (srel != NULL);
4960 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
4962 gotent = gotent->next)
4967 if (gotent->use_count == 0)
4970 sgot = alpha_elf_tdata (gotent->gotobj)->got;
4971 outrel.r_offset = (sgot->output_section->vma
4972 + sgot->output_offset
4973 + gotent->got_offset);
4975 r_type = gotent->reloc_type;
4978 case R_ALPHA_LITERAL:
4979 r_type = R_ALPHA_GLOB_DAT;
4982 r_type = R_ALPHA_DTPMOD64;
4984 case R_ALPHA_GOTDTPREL:
4985 r_type = R_ALPHA_DTPREL64;
4987 case R_ALPHA_GOTTPREL:
4988 r_type = R_ALPHA_TPREL64;
4990 case R_ALPHA_TLSLDM:
4995 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
4996 outrel.r_addend = gotent->addend;
4998 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
4999 ((Elf64_External_Rela *)srel->contents
5000 + srel->reloc_count++));
5002 if (gotent->reloc_type == R_ALPHA_TLSGD)
5004 outrel.r_offset += 8;
5005 outrel.r_info = ELF64_R_INFO (h->dynindx, R_ALPHA_DTPREL64);
5007 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
5008 ((Elf64_External_Rela *)srel->contents
5009 + srel->reloc_count++));
5012 BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
5013 <= srel->_cooked_size);
5017 /* Mark some specially defined symbols as absolute. */
5018 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5019 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
5020 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
5021 sym->st_shndx = SHN_ABS;
5026 /* Finish up the dynamic sections. */
5029 elf64_alpha_finish_dynamic_sections (output_bfd, info)
5031 struct bfd_link_info *info;
5036 dynobj = elf_hash_table (info)->dynobj;
5037 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5039 if (elf_hash_table (info)->dynamic_sections_created)
5042 Elf64_External_Dyn *dyncon, *dynconend;
5044 splt = bfd_get_section_by_name (dynobj, ".plt");
5045 BFD_ASSERT (splt != NULL && sdyn != NULL);
5047 dyncon = (Elf64_External_Dyn *) sdyn->contents;
5048 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5049 for (; dyncon < dynconend; dyncon++)
5051 Elf_Internal_Dyn dyn;
5055 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
5070 /* My interpretation of the TIS v1.1 ELF document indicates
5071 that RELASZ should not include JMPREL. This is not what
5072 the rest of the BFD does. It is, however, what the
5073 glibc ld.so wants. Do this fixup here until we found
5074 out who is right. */
5075 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
5079 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
5084 s = bfd_get_section_by_name (output_bfd, name);
5085 dyn.d_un.d_ptr = (s ? s->vma : 0);
5089 s = bfd_get_section_by_name (output_bfd, name);
5091 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
5095 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
5098 /* Initialize the PLT0 entry */
5099 if (splt->_raw_size > 0)
5101 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
5102 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
5103 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
5104 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
5106 /* The next two words will be filled in by ld.so */
5107 bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 16);
5108 bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 24);
5110 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
5118 /* We need to use a special link routine to handle the .mdebug section.
5119 We need to merge all instances of these sections together, not write
5120 them all out sequentially. */
5123 elf64_alpha_final_link (abfd, info)
5125 struct bfd_link_info *info;
5128 struct bfd_link_order *p;
5129 asection *mdebug_sec;
5130 struct ecoff_debug_info debug;
5131 const struct ecoff_debug_swap *swap
5132 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
5133 HDRR *symhdr = &debug.symbolic_header;
5134 PTR mdebug_handle = NULL;
5136 /* Go through the sections and collect the mdebug information. */
5138 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
5140 if (strcmp (o->name, ".mdebug") == 0)
5142 struct extsym_info einfo;
5144 /* We have found the .mdebug section in the output file.
5145 Look through all the link_orders comprising it and merge
5146 the information together. */
5147 symhdr->magic = swap->sym_magic;
5148 /* FIXME: What should the version stamp be? */
5150 symhdr->ilineMax = 0;
5154 symhdr->isymMax = 0;
5155 symhdr->ioptMax = 0;
5156 symhdr->iauxMax = 0;
5158 symhdr->issExtMax = 0;
5161 symhdr->iextMax = 0;
5163 /* We accumulate the debugging information itself in the
5164 debug_info structure. */
5166 debug.external_dnr = NULL;
5167 debug.external_pdr = NULL;
5168 debug.external_sym = NULL;
5169 debug.external_opt = NULL;
5170 debug.external_aux = NULL;
5172 debug.ssext = debug.ssext_end = NULL;
5173 debug.external_fdr = NULL;
5174 debug.external_rfd = NULL;
5175 debug.external_ext = debug.external_ext_end = NULL;
5177 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
5178 if (mdebug_handle == (PTR) NULL)
5187 static const char * const name[] =
5189 ".text", ".init", ".fini", ".data",
5190 ".rodata", ".sdata", ".sbss", ".bss"
5192 static const int sc[] = { scText, scInit, scFini, scData,
5193 scRData, scSData, scSBss, scBss };
5196 esym.cobol_main = 0;
5200 esym.asym.iss = issNil;
5201 esym.asym.st = stLocal;
5202 esym.asym.reserved = 0;
5203 esym.asym.index = indexNil;
5204 for (i = 0; i < 8; i++)
5206 esym.asym.sc = sc[i];
5207 s = bfd_get_section_by_name (abfd, name[i]);
5210 esym.asym.value = s->vma;
5211 last = s->vma + s->_raw_size;
5214 esym.asym.value = last;
5216 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
5222 for (p = o->link_order_head;
5223 p != (struct bfd_link_order *) NULL;
5226 asection *input_section;
5228 const struct ecoff_debug_swap *input_swap;
5229 struct ecoff_debug_info input_debug;
5233 if (p->type != bfd_indirect_link_order)
5235 if (p->type == bfd_data_link_order)
5240 input_section = p->u.indirect.section;
5241 input_bfd = input_section->owner;
5243 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
5244 || (get_elf_backend_data (input_bfd)
5245 ->elf_backend_ecoff_debug_swap) == NULL)
5247 /* I don't know what a non ALPHA ELF bfd would be
5248 doing with a .mdebug section, but I don't really
5249 want to deal with it. */
5253 input_swap = (get_elf_backend_data (input_bfd)
5254 ->elf_backend_ecoff_debug_swap);
5256 BFD_ASSERT (p->size == input_section->_raw_size);
5258 /* The ECOFF linking code expects that we have already
5259 read in the debugging information and set up an
5260 ecoff_debug_info structure, so we do that now. */
5261 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
5265 if (! (bfd_ecoff_debug_accumulate
5266 (mdebug_handle, abfd, &debug, swap, input_bfd,
5267 &input_debug, input_swap, info)))
5270 /* Loop through the external symbols. For each one with
5271 interesting information, try to find the symbol in
5272 the linker global hash table and save the information
5273 for the output external symbols. */
5274 eraw_src = input_debug.external_ext;
5275 eraw_end = (eraw_src
5276 + (input_debug.symbolic_header.iextMax
5277 * input_swap->external_ext_size));
5279 eraw_src < eraw_end;
5280 eraw_src += input_swap->external_ext_size)
5284 struct alpha_elf_link_hash_entry *h;
5286 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
5287 if (ext.asym.sc == scNil
5288 || ext.asym.sc == scUndefined
5289 || ext.asym.sc == scSUndefined)
5292 name = input_debug.ssext + ext.asym.iss;
5293 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
5294 name, false, false, true);
5295 if (h == NULL || h->esym.ifd != -2)
5301 < input_debug.symbolic_header.ifdMax);
5302 ext.ifd = input_debug.ifdmap[ext.ifd];
5308 /* Free up the information we just read. */
5309 free (input_debug.line);
5310 free (input_debug.external_dnr);
5311 free (input_debug.external_pdr);
5312 free (input_debug.external_sym);
5313 free (input_debug.external_opt);
5314 free (input_debug.external_aux);
5315 free (input_debug.ss);
5316 free (input_debug.ssext);
5317 free (input_debug.external_fdr);
5318 free (input_debug.external_rfd);
5319 free (input_debug.external_ext);
5321 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5322 elf_link_input_bfd ignores this section. */
5323 input_section->flags &=~ SEC_HAS_CONTENTS;
5326 /* Build the external symbol information. */
5329 einfo.debug = &debug;
5331 einfo.failed = false;
5332 elf_link_hash_traverse (elf_hash_table (info),
5333 elf64_alpha_output_extsym,
5338 /* Set the size of the .mdebug section. */
5339 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
5341 /* Skip this section later on (I don't think this currently
5342 matters, but someday it might). */
5343 o->link_order_head = (struct bfd_link_order *) NULL;
5349 /* Invoke the regular ELF backend linker to do all the work. */
5350 if (! bfd_elf64_bfd_final_link (abfd, info))
5353 /* Now write out the computed sections. */
5355 /* The .got subsections... */
5357 bfd *i, *dynobj = elf_hash_table(info)->dynobj;
5358 for (i = alpha_elf_hash_table(info)->got_list;
5360 i = alpha_elf_tdata(i)->got_link_next)
5364 /* elf_bfd_final_link already did everything in dynobj. */
5368 sgot = alpha_elf_tdata(i)->got;
5369 if (! bfd_set_section_contents (abfd, sgot->output_section,
5371 (file_ptr) sgot->output_offset,
5377 if (mdebug_sec != (asection *) NULL)
5379 BFD_ASSERT (abfd->output_has_begun);
5380 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
5382 mdebug_sec->filepos))
5385 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
5391 static enum elf_reloc_type_class
5392 elf64_alpha_reloc_type_class (rela)
5393 const Elf_Internal_Rela *rela;
5395 switch ((int) ELF64_R_TYPE (rela->r_info))
5397 case R_ALPHA_RELATIVE:
5398 return reloc_class_relative;
5399 case R_ALPHA_JMP_SLOT:
5400 return reloc_class_plt;
5402 return reloc_class_copy;
5404 return reloc_class_normal;
5408 /* ECOFF swapping routines. These are used when dealing with the
5409 .mdebug section, which is in the ECOFF debugging format. Copied
5410 from elf32-mips.c. */
5411 static const struct ecoff_debug_swap
5412 elf64_alpha_ecoff_debug_swap =
5414 /* Symbol table magic number. */
5416 /* Alignment of debugging information. E.g., 4. */
5418 /* Sizes of external symbolic information. */
5419 sizeof (struct hdr_ext),
5420 sizeof (struct dnr_ext),
5421 sizeof (struct pdr_ext),
5422 sizeof (struct sym_ext),
5423 sizeof (struct opt_ext),
5424 sizeof (struct fdr_ext),
5425 sizeof (struct rfd_ext),
5426 sizeof (struct ext_ext),
5427 /* Functions to swap in external symbolic data. */
5436 _bfd_ecoff_swap_tir_in,
5437 _bfd_ecoff_swap_rndx_in,
5438 /* Functions to swap out external symbolic data. */
5447 _bfd_ecoff_swap_tir_out,
5448 _bfd_ecoff_swap_rndx_out,
5449 /* Function to read in symbolic data. */
5450 elf64_alpha_read_ecoff_info
5453 /* Use a non-standard hash bucket size of 8. */
5455 const struct elf_size_info alpha_elf_size_info =
5457 sizeof (Elf64_External_Ehdr),
5458 sizeof (Elf64_External_Phdr),
5459 sizeof (Elf64_External_Shdr),
5460 sizeof (Elf64_External_Rel),
5461 sizeof (Elf64_External_Rela),
5462 sizeof (Elf64_External_Sym),
5463 sizeof (Elf64_External_Dyn),
5464 sizeof (Elf_External_Note),
5468 ELFCLASS64, EV_CURRENT,
5469 bfd_elf64_write_out_phdrs,
5470 bfd_elf64_write_shdrs_and_ehdr,
5471 bfd_elf64_write_relocs,
5472 bfd_elf64_swap_symbol_out,
5473 bfd_elf64_slurp_reloc_table,
5474 bfd_elf64_slurp_symbol_table,
5475 bfd_elf64_swap_dyn_in,
5476 bfd_elf64_swap_dyn_out,
5483 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5484 #define TARGET_LITTLE_NAME "elf64-alpha"
5485 #define ELF_ARCH bfd_arch_alpha
5486 #define ELF_MACHINE_CODE EM_ALPHA
5487 #define ELF_MAXPAGESIZE 0x10000
5489 #define bfd_elf64_bfd_link_hash_table_create \
5490 elf64_alpha_bfd_link_hash_table_create
5492 #define bfd_elf64_bfd_reloc_type_lookup \
5493 elf64_alpha_bfd_reloc_type_lookup
5494 #define elf_info_to_howto \
5495 elf64_alpha_info_to_howto
5497 #define bfd_elf64_mkobject \
5498 elf64_alpha_mkobject
5499 #define elf_backend_object_p \
5500 elf64_alpha_object_p
5502 #define elf_backend_section_from_shdr \
5503 elf64_alpha_section_from_shdr
5504 #define elf_backend_section_flags \
5505 elf64_alpha_section_flags
5506 #define elf_backend_fake_sections \
5507 elf64_alpha_fake_sections
5509 #define bfd_elf64_bfd_is_local_label_name \
5510 elf64_alpha_is_local_label_name
5511 #define bfd_elf64_find_nearest_line \
5512 elf64_alpha_find_nearest_line
5513 #define bfd_elf64_bfd_relax_section \
5514 elf64_alpha_relax_section
5516 #define elf_backend_add_symbol_hook \
5517 elf64_alpha_add_symbol_hook
5518 #define elf_backend_check_relocs \
5519 elf64_alpha_check_relocs
5520 #define elf_backend_create_dynamic_sections \
5521 elf64_alpha_create_dynamic_sections
5522 #define elf_backend_adjust_dynamic_symbol \
5523 elf64_alpha_adjust_dynamic_symbol
5524 #define elf_backend_always_size_sections \
5525 elf64_alpha_always_size_sections
5526 #define elf_backend_size_dynamic_sections \
5527 elf64_alpha_size_dynamic_sections
5528 #define elf_backend_relocate_section \
5529 elf64_alpha_relocate_section
5530 #define elf_backend_finish_dynamic_symbol \
5531 elf64_alpha_finish_dynamic_symbol
5532 #define elf_backend_finish_dynamic_sections \
5533 elf64_alpha_finish_dynamic_sections
5534 #define bfd_elf64_bfd_final_link \
5535 elf64_alpha_final_link
5536 #define elf_backend_reloc_type_class \
5537 elf64_alpha_reloc_type_class
5539 #define elf_backend_ecoff_debug_swap \
5540 &elf64_alpha_ecoff_debug_swap
5542 #define elf_backend_size_info \
5545 /* A few constants that determine how the .plt section is set up. */
5546 #define elf_backend_want_got_plt 0
5547 #define elf_backend_plt_readonly 0
5548 #define elf_backend_want_plt_sym 1
5549 #define elf_backend_got_header_size 0
5550 #define elf_backend_plt_header_size PLT_HEADER_SIZE
5552 #include "elf64-target.h"