1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 bfd_boolean 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 *, Elf_Internal_Rela *));
71 static bfd_boolean elf64_alpha_mkobject
73 static bfd_boolean elf64_alpha_object_p
75 static bfd_boolean elf64_alpha_section_from_shdr
76 PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
77 static bfd_boolean elf64_alpha_section_flags
78 PARAMS ((flagword *, Elf_Internal_Shdr *));
79 static bfd_boolean elf64_alpha_fake_sections
80 PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
81 static bfd_boolean elf64_alpha_create_got_section
82 PARAMS ((bfd *, struct bfd_link_info *));
83 static bfd_boolean elf64_alpha_create_dynamic_sections
84 PARAMS ((bfd *, struct bfd_link_info *));
86 static bfd_boolean elf64_alpha_read_ecoff_info
87 PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
88 static bfd_boolean elf64_alpha_is_local_label_name
89 PARAMS ((bfd *, const char *));
90 static bfd_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 bfd_boolean elf64_alpha_output_extsym
99 PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
101 static bfd_boolean elf64_alpha_can_merge_gots
102 PARAMS ((bfd *, bfd *));
103 static void elf64_alpha_merge_gots
104 PARAMS ((bfd *, bfd *));
105 static bfd_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
108 PARAMS ((struct bfd_link_info *));
109 static bfd_boolean elf64_alpha_size_got_sections
110 PARAMS ((struct bfd_link_info *));
111 static bfd_boolean elf64_alpha_size_plt_section
112 PARAMS ((struct bfd_link_info *));
113 static bfd_boolean elf64_alpha_size_plt_section_1
114 PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
115 static bfd_boolean elf64_alpha_always_size_sections
116 PARAMS ((bfd *, struct bfd_link_info *));
117 static int alpha_dynamic_entries_for_reloc
118 PARAMS ((int, int, int));
119 static bfd_boolean elf64_alpha_calc_dynrel_sizes
120 PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
121 static bfd_boolean elf64_alpha_size_rela_got_section
122 PARAMS ((struct bfd_link_info *));
123 static bfd_boolean elf64_alpha_size_rela_got_1
124 PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
125 static bfd_boolean elf64_alpha_add_symbol_hook
126 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
127 const char **, flagword *, asection **, bfd_vma *));
128 static struct alpha_elf_got_entry *get_got_entry
129 PARAMS ((bfd *, struct alpha_elf_link_hash_entry *, unsigned long,
130 unsigned long, bfd_vma));
131 static bfd_boolean elf64_alpha_check_relocs
132 PARAMS ((bfd *, struct bfd_link_info *, asection *sec,
133 const Elf_Internal_Rela *));
134 static bfd_boolean elf64_alpha_adjust_dynamic_symbol
135 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
136 static bfd_boolean elf64_alpha_size_dynamic_sections
137 PARAMS ((bfd *, struct bfd_link_info *));
138 static void elf64_alpha_emit_dynrel
139 PARAMS ((bfd *, struct bfd_link_info *, asection *, asection *,
140 bfd_vma, long, long, bfd_vma));
141 static bfd_boolean elf64_alpha_relocate_section_r
142 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
143 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
144 static bfd_boolean elf64_alpha_relocate_section
145 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
146 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
147 static bfd_boolean elf64_alpha_finish_dynamic_symbol
148 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
149 Elf_Internal_Sym *));
150 static bfd_boolean elf64_alpha_finish_dynamic_sections
151 PARAMS ((bfd *, struct bfd_link_info *));
152 static bfd_boolean elf64_alpha_final_link
153 PARAMS ((bfd *, struct bfd_link_info *));
154 static bfd_boolean elf64_alpha_merge_ind_symbols
155 PARAMS ((struct alpha_elf_link_hash_entry *, PTR));
156 static Elf_Internal_Rela * elf64_alpha_find_reloc_at_ofs
157 PARAMS ((Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_vma, int));
158 static enum elf_reloc_type_class elf64_alpha_reloc_type_class
159 PARAMS ((const Elf_Internal_Rela *));
161 struct alpha_elf_link_hash_entry
163 struct elf_link_hash_entry root;
165 /* External symbol information. */
168 /* Cumulative flags for all the .got entries. */
171 /* Contexts in which a literal was referenced. */
172 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
173 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
174 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
175 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08
176 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10
177 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20
178 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x38
179 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x40
180 #define ALPHA_ELF_LINK_HASH_PLT_LOC 0x80
182 /* Used to undo the localization of a plt symbol. */
183 asection *plt_old_section;
184 bfd_vma plt_old_value;
186 /* Used to implement multiple .got subsections. */
187 struct alpha_elf_got_entry
189 struct alpha_elf_got_entry *next;
191 /* Which .got subsection? */
194 /* The addend in effect for this entry. */
197 /* The .got offset for this entry. */
200 /* How many references to this entry? */
203 /* The relocation type of this entry. */
204 unsigned char reloc_type;
206 /* How a LITERAL is used. */
209 /* Have we initialized the dynamic relocation for this entry? */
210 unsigned char reloc_done;
212 /* Have we adjusted this entry for SEC_MERGE? */
213 unsigned char reloc_xlated;
216 /* Used to count non-got, non-plt relocations for delayed sizing
217 of relocation sections. */
218 struct alpha_elf_reloc_entry
220 struct alpha_elf_reloc_entry *next;
222 /* Which .reloc section? */
225 /* What kind of relocation? */
228 /* Is this against read-only section? */
229 unsigned int reltext : 1;
231 /* How many did we find? */
236 /* Alpha ELF linker hash table. */
238 struct alpha_elf_link_hash_table
240 struct elf_link_hash_table root;
242 /* The head of a list of .got subsections linked through
243 alpha_elf_tdata(abfd)->got_link_next. */
247 /* Look up an entry in a Alpha ELF linker hash table. */
249 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
250 ((struct alpha_elf_link_hash_entry *) \
251 elf_link_hash_lookup (&(table)->root, (string), (create), \
254 /* Traverse a Alpha ELF linker hash table. */
256 #define alpha_elf_link_hash_traverse(table, func, info) \
257 (elf_link_hash_traverse \
259 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
262 /* Get the Alpha ELF linker hash table from a link_info structure. */
264 #define alpha_elf_hash_table(p) \
265 ((struct alpha_elf_link_hash_table *) ((p)->hash))
267 /* Get the object's symbols as our own entry type. */
269 #define alpha_elf_sym_hashes(abfd) \
270 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
272 /* Should we do dynamic things to this symbol? This differs from the
273 generic version in that we never need to consider function pointer
274 equality wrt PLT entries -- we don't create a PLT entry if a symbol's
275 address is ever taken. */
277 static inline bfd_boolean
278 alpha_elf_dynamic_symbol_p (h, info)
279 struct elf_link_hash_entry *h;
280 struct bfd_link_info *info;
282 return _bfd_elf_dynamic_symbol_p (h, info, 0);
285 /* Create an entry in a Alpha ELF linker hash table. */
287 static struct bfd_hash_entry *
288 elf64_alpha_link_hash_newfunc (entry, table, string)
289 struct bfd_hash_entry *entry;
290 struct bfd_hash_table *table;
293 struct alpha_elf_link_hash_entry *ret =
294 (struct alpha_elf_link_hash_entry *) entry;
296 /* Allocate the structure if it has not already been allocated by a
298 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
299 ret = ((struct alpha_elf_link_hash_entry *)
300 bfd_hash_allocate (table,
301 sizeof (struct alpha_elf_link_hash_entry)));
302 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
303 return (struct bfd_hash_entry *) ret;
305 /* Call the allocation method of the superclass. */
306 ret = ((struct alpha_elf_link_hash_entry *)
307 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
309 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
311 /* Set local fields. */
312 memset (&ret->esym, 0, sizeof (EXTR));
313 /* We use -2 as a marker to indicate that the information has
314 not been set. -1 means there is no associated ifd. */
317 ret->got_entries = NULL;
318 ret->reloc_entries = NULL;
321 return (struct bfd_hash_entry *) ret;
324 /* Create a Alpha ELF linker hash table. */
326 static struct bfd_link_hash_table *
327 elf64_alpha_bfd_link_hash_table_create (abfd)
330 struct alpha_elf_link_hash_table *ret;
331 bfd_size_type amt = sizeof (struct alpha_elf_link_hash_table);
333 ret = (struct alpha_elf_link_hash_table *) bfd_zmalloc (amt);
334 if (ret == (struct alpha_elf_link_hash_table *) NULL)
337 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
338 elf64_alpha_link_hash_newfunc))
344 return &ret->root.root;
347 /* We have some private fields hanging off of the elf_tdata structure. */
349 struct alpha_elf_obj_tdata
351 struct elf_obj_tdata root;
353 /* For every input file, these are the got entries for that object's
355 struct alpha_elf_got_entry ** local_got_entries;
357 /* For every input file, this is the object that owns the got that
358 this input file uses. */
361 /* For every got, this is a linked list through the objects using this got */
362 bfd *in_got_link_next;
364 /* For every got, this is a link to the next got subsegment. */
367 /* For every got, this is the section. */
370 /* For every got, this is it's total number of words. */
373 /* For every got, this is the sum of the number of words required
374 to hold all of the member object's local got. */
378 #define alpha_elf_tdata(abfd) \
379 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
382 elf64_alpha_mkobject (abfd)
385 bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata);
386 abfd->tdata.any = bfd_zalloc (abfd, amt);
387 if (abfd->tdata.any == NULL)
393 elf64_alpha_object_p (abfd)
396 /* Allocate our special target data. */
397 struct alpha_elf_obj_tdata *new_tdata;
398 bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata);
399 new_tdata = bfd_zalloc (abfd, amt);
400 if (new_tdata == NULL)
402 new_tdata->root = *abfd->tdata.elf_obj_data;
403 abfd->tdata.any = new_tdata;
405 /* Set the right machine number for an Alpha ELF file. */
406 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
409 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
410 from smaller values. Start with zero, widen, *then* decrement. */
411 #define MINUS_ONE (((bfd_vma)0) - 1)
413 #define SKIP_HOWTO(N) \
414 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
416 static reloc_howto_type elf64_alpha_howto_table[] =
418 HOWTO (R_ALPHA_NONE, /* type */
420 0, /* size (0 = byte, 1 = short, 2 = long) */
422 TRUE, /* pc_relative */
424 complain_overflow_dont, /* complain_on_overflow */
425 elf64_alpha_reloc_nil, /* special_function */
427 FALSE, /* partial_inplace */
430 TRUE), /* pcrel_offset */
432 /* A 32 bit reference to a symbol. */
433 HOWTO (R_ALPHA_REFLONG, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 FALSE, /* pc_relative */
439 complain_overflow_bitfield, /* complain_on_overflow */
440 0, /* special_function */
441 "REFLONG", /* name */
442 FALSE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 FALSE), /* pcrel_offset */
447 /* A 64 bit reference to a symbol. */
448 HOWTO (R_ALPHA_REFQUAD, /* type */
450 4, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE, /* pc_relative */
454 complain_overflow_bitfield, /* complain_on_overflow */
455 0, /* special_function */
456 "REFQUAD", /* name */
457 FALSE, /* partial_inplace */
458 MINUS_ONE, /* src_mask */
459 MINUS_ONE, /* dst_mask */
460 FALSE), /* pcrel_offset */
462 /* A 32 bit GP relative offset. This is just like REFLONG except
463 that when the value is used the value of the gp register will be
465 HOWTO (R_ALPHA_GPREL32, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 FALSE, /* pc_relative */
471 complain_overflow_bitfield, /* complain_on_overflow */
472 0, /* special_function */
473 "GPREL32", /* name */
474 FALSE, /* partial_inplace */
475 0xffffffff, /* src_mask */
476 0xffffffff, /* dst_mask */
477 FALSE), /* pcrel_offset */
479 /* Used for an instruction that refers to memory off the GP register. */
480 HOWTO (R_ALPHA_LITERAL, /* type */
482 1, /* size (0 = byte, 1 = short, 2 = long) */
484 FALSE, /* pc_relative */
486 complain_overflow_signed, /* complain_on_overflow */
487 0, /* special_function */
488 "ELF_LITERAL", /* name */
489 FALSE, /* partial_inplace */
490 0xffff, /* src_mask */
491 0xffff, /* dst_mask */
492 FALSE), /* pcrel_offset */
494 /* This reloc only appears immediately following an ELF_LITERAL reloc.
495 It identifies a use of the literal. The symbol index is special:
496 1 means the literal address is in the base register of a memory
497 format instruction; 2 means the literal address is in the byte
498 offset register of a byte-manipulation instruction; 3 means the
499 literal address is in the target register of a jsr instruction.
500 This does not actually do any relocation. */
501 HOWTO (R_ALPHA_LITUSE, /* type */
503 1, /* size (0 = byte, 1 = short, 2 = long) */
505 FALSE, /* pc_relative */
507 complain_overflow_dont, /* complain_on_overflow */
508 elf64_alpha_reloc_nil, /* special_function */
510 FALSE, /* partial_inplace */
513 FALSE), /* pcrel_offset */
515 /* Load the gp register. This is always used for a ldah instruction
516 which loads the upper 16 bits of the gp register. The symbol
517 index of the GPDISP instruction is an offset in bytes to the lda
518 instruction that loads the lower 16 bits. The value to use for
519 the relocation is the difference between the GP value and the
520 current location; the load will always be done against a register
521 holding the current address.
523 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
524 any offset is present in the instructions, it is an offset from
525 the register to the ldah instruction. This lets us avoid any
526 stupid hackery like inventing a gp value to do partial relocation
527 against. Also unlike ECOFF, we do the whole relocation off of
528 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
529 space consuming bit, that, since all the information was present
530 in the GPDISP_HI16 reloc. */
531 HOWTO (R_ALPHA_GPDISP, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE, /* pc_relative */
537 complain_overflow_dont, /* complain_on_overflow */
538 elf64_alpha_reloc_gpdisp, /* special_function */
540 FALSE, /* partial_inplace */
541 0xffff, /* src_mask */
542 0xffff, /* dst_mask */
543 TRUE), /* pcrel_offset */
545 /* A 21 bit branch. */
546 HOWTO (R_ALPHA_BRADDR, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 TRUE, /* pc_relative */
552 complain_overflow_signed, /* complain_on_overflow */
553 0, /* special_function */
555 FALSE, /* partial_inplace */
556 0x1fffff, /* src_mask */
557 0x1fffff, /* dst_mask */
558 TRUE), /* pcrel_offset */
560 /* A hint for a jump to a register. */
561 HOWTO (R_ALPHA_HINT, /* type */
563 1, /* size (0 = byte, 1 = short, 2 = long) */
565 TRUE, /* pc_relative */
567 complain_overflow_dont, /* complain_on_overflow */
568 0, /* special_function */
570 FALSE, /* partial_inplace */
571 0x3fff, /* src_mask */
572 0x3fff, /* dst_mask */
573 TRUE), /* pcrel_offset */
575 /* 16 bit PC relative offset. */
576 HOWTO (R_ALPHA_SREL16, /* type */
578 1, /* size (0 = byte, 1 = short, 2 = long) */
580 TRUE, /* pc_relative */
582 complain_overflow_signed, /* complain_on_overflow */
583 0, /* special_function */
585 FALSE, /* partial_inplace */
586 0xffff, /* src_mask */
587 0xffff, /* dst_mask */
588 TRUE), /* pcrel_offset */
590 /* 32 bit PC relative offset. */
591 HOWTO (R_ALPHA_SREL32, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 TRUE, /* pc_relative */
597 complain_overflow_signed, /* complain_on_overflow */
598 0, /* special_function */
600 FALSE, /* partial_inplace */
601 0xffffffff, /* src_mask */
602 0xffffffff, /* dst_mask */
603 TRUE), /* pcrel_offset */
605 /* A 64 bit PC relative offset. */
606 HOWTO (R_ALPHA_SREL64, /* type */
608 4, /* size (0 = byte, 1 = short, 2 = long) */
610 TRUE, /* pc_relative */
612 complain_overflow_signed, /* complain_on_overflow */
613 0, /* special_function */
615 FALSE, /* partial_inplace */
616 MINUS_ONE, /* src_mask */
617 MINUS_ONE, /* dst_mask */
618 TRUE), /* pcrel_offset */
620 /* Skip 12 - 16; deprecated ECOFF relocs. */
627 /* The high 16 bits of the displacement from GP to the target. */
628 HOWTO (R_ALPHA_GPRELHIGH,
630 1, /* size (0 = byte, 1 = short, 2 = long) */
632 FALSE, /* pc_relative */
634 complain_overflow_signed, /* complain_on_overflow */
635 0, /* special_function */
636 "GPRELHIGH", /* name */
637 FALSE, /* partial_inplace */
638 0xffff, /* src_mask */
639 0xffff, /* dst_mask */
640 FALSE), /* pcrel_offset */
642 /* The low 16 bits of the displacement from GP to the target. */
643 HOWTO (R_ALPHA_GPRELLOW,
645 1, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE, /* pc_relative */
649 complain_overflow_dont, /* complain_on_overflow */
650 0, /* special_function */
651 "GPRELLOW", /* name */
652 FALSE, /* partial_inplace */
653 0xffff, /* src_mask */
654 0xffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
657 /* A 16-bit displacement from the GP to the target. */
658 HOWTO (R_ALPHA_GPREL16,
660 1, /* size (0 = byte, 1 = short, 2 = long) */
662 FALSE, /* pc_relative */
664 complain_overflow_signed, /* complain_on_overflow */
665 0, /* special_function */
666 "GPREL16", /* name */
667 FALSE, /* partial_inplace */
668 0xffff, /* src_mask */
669 0xffff, /* dst_mask */
670 FALSE), /* pcrel_offset */
672 /* Skip 20 - 23; deprecated ECOFF relocs. */
678 /* Misc ELF relocations. */
680 /* A dynamic relocation to copy the target into our .dynbss section. */
681 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
682 is present because every other ELF has one, but should not be used
683 because .dynbss is an ugly thing. */
690 complain_overflow_dont,
691 bfd_elf_generic_reloc,
698 /* A dynamic relocation for a .got entry. */
699 HOWTO (R_ALPHA_GLOB_DAT,
705 complain_overflow_dont,
706 bfd_elf_generic_reloc,
713 /* A dynamic relocation for a .plt entry. */
714 HOWTO (R_ALPHA_JMP_SLOT,
720 complain_overflow_dont,
721 bfd_elf_generic_reloc,
728 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
729 HOWTO (R_ALPHA_RELATIVE,
735 complain_overflow_dont,
736 bfd_elf_generic_reloc,
743 /* A 21 bit branch that adjusts for gp loads. */
744 HOWTO (R_ALPHA_BRSGP, /* type */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
748 TRUE, /* pc_relative */
750 complain_overflow_signed, /* complain_on_overflow */
751 0, /* special_function */
753 FALSE, /* partial_inplace */
754 0x1fffff, /* src_mask */
755 0x1fffff, /* dst_mask */
756 TRUE), /* pcrel_offset */
758 /* Creates a tls_index for the symbol in the got. */
759 HOWTO (R_ALPHA_TLSGD, /* type */
761 1, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE, /* pc_relative */
765 complain_overflow_signed, /* complain_on_overflow */
766 0, /* special_function */
768 FALSE, /* partial_inplace */
769 0xffff, /* src_mask */
770 0xffff, /* dst_mask */
771 FALSE), /* pcrel_offset */
773 /* Creates a tls_index for the (current) module in the got. */
774 HOWTO (R_ALPHA_TLSLDM, /* type */
776 1, /* size (0 = byte, 1 = short, 2 = long) */
778 FALSE, /* pc_relative */
780 complain_overflow_signed, /* complain_on_overflow */
781 0, /* special_function */
783 FALSE, /* partial_inplace */
784 0xffff, /* src_mask */
785 0xffff, /* dst_mask */
786 FALSE), /* pcrel_offset */
788 /* A dynamic relocation for a DTP module entry. */
789 HOWTO (R_ALPHA_DTPMOD64, /* type */
791 4, /* size (0 = byte, 1 = short, 2 = long) */
793 FALSE, /* pc_relative */
795 complain_overflow_bitfield, /* complain_on_overflow */
796 0, /* special_function */
797 "DTPMOD64", /* name */
798 FALSE, /* partial_inplace */
799 MINUS_ONE, /* src_mask */
800 MINUS_ONE, /* dst_mask */
801 FALSE), /* pcrel_offset */
803 /* Creates a 64-bit offset in the got for the displacement
804 from DTP to the target. */
805 HOWTO (R_ALPHA_GOTDTPREL, /* type */
807 1, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE, /* pc_relative */
811 complain_overflow_signed, /* complain_on_overflow */
812 0, /* special_function */
813 "GOTDTPREL", /* name */
814 FALSE, /* partial_inplace */
815 0xffff, /* src_mask */
816 0xffff, /* dst_mask */
817 FALSE), /* pcrel_offset */
819 /* A dynamic relocation for a displacement from DTP to the target. */
820 HOWTO (R_ALPHA_DTPREL64, /* type */
822 4, /* size (0 = byte, 1 = short, 2 = long) */
824 FALSE, /* pc_relative */
826 complain_overflow_bitfield, /* complain_on_overflow */
827 0, /* special_function */
828 "DTPREL64", /* name */
829 FALSE, /* partial_inplace */
830 MINUS_ONE, /* src_mask */
831 MINUS_ONE, /* dst_mask */
832 FALSE), /* pcrel_offset */
834 /* The high 16 bits of the displacement from DTP to the target. */
835 HOWTO (R_ALPHA_DTPRELHI, /* type */
837 1, /* size (0 = byte, 1 = short, 2 = long) */
839 FALSE, /* pc_relative */
841 complain_overflow_signed, /* complain_on_overflow */
842 0, /* special_function */
843 "DTPRELHI", /* name */
844 FALSE, /* partial_inplace */
845 0xffff, /* src_mask */
846 0xffff, /* dst_mask */
847 FALSE), /* pcrel_offset */
849 /* The low 16 bits of the displacement from DTP to the target. */
850 HOWTO (R_ALPHA_DTPRELLO, /* type */
852 1, /* size (0 = byte, 1 = short, 2 = long) */
854 FALSE, /* pc_relative */
856 complain_overflow_dont, /* complain_on_overflow */
857 0, /* special_function */
858 "DTPRELLO", /* name */
859 FALSE, /* partial_inplace */
860 0xffff, /* src_mask */
861 0xffff, /* dst_mask */
862 FALSE), /* pcrel_offset */
864 /* A 16-bit displacement from DTP to the target. */
865 HOWTO (R_ALPHA_DTPREL16, /* type */
867 1, /* size (0 = byte, 1 = short, 2 = long) */
869 FALSE, /* pc_relative */
871 complain_overflow_signed, /* complain_on_overflow */
872 0, /* special_function */
873 "DTPREL16", /* name */
874 FALSE, /* partial_inplace */
875 0xffff, /* src_mask */
876 0xffff, /* dst_mask */
877 FALSE), /* pcrel_offset */
879 /* Creates a 64-bit offset in the got for the displacement
880 from TP to the target. */
881 HOWTO (R_ALPHA_GOTTPREL, /* type */
883 1, /* size (0 = byte, 1 = short, 2 = long) */
885 FALSE, /* pc_relative */
887 complain_overflow_signed, /* complain_on_overflow */
888 0, /* special_function */
889 "GOTTPREL", /* name */
890 FALSE, /* partial_inplace */
891 0xffff, /* src_mask */
892 0xffff, /* dst_mask */
893 FALSE), /* pcrel_offset */
895 /* A dynamic relocation for a displacement from TP to the target. */
896 HOWTO (R_ALPHA_TPREL64, /* type */
898 4, /* size (0 = byte, 1 = short, 2 = long) */
900 FALSE, /* pc_relative */
902 complain_overflow_bitfield, /* complain_on_overflow */
903 0, /* special_function */
904 "TPREL64", /* name */
905 FALSE, /* partial_inplace */
906 MINUS_ONE, /* src_mask */
907 MINUS_ONE, /* dst_mask */
908 FALSE), /* pcrel_offset */
910 /* The high 16 bits of the displacement from TP to the target. */
911 HOWTO (R_ALPHA_TPRELHI, /* type */
913 1, /* size (0 = byte, 1 = short, 2 = long) */
915 FALSE, /* pc_relative */
917 complain_overflow_signed, /* complain_on_overflow */
918 0, /* special_function */
919 "TPRELHI", /* name */
920 FALSE, /* partial_inplace */
921 0xffff, /* src_mask */
922 0xffff, /* dst_mask */
923 FALSE), /* pcrel_offset */
925 /* The low 16 bits of the displacement from TP to the target. */
926 HOWTO (R_ALPHA_TPRELLO, /* type */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
930 FALSE, /* pc_relative */
932 complain_overflow_dont, /* complain_on_overflow */
933 0, /* special_function */
934 "TPRELLO", /* name */
935 FALSE, /* partial_inplace */
936 0xffff, /* src_mask */
937 0xffff, /* dst_mask */
938 FALSE), /* pcrel_offset */
940 /* A 16-bit displacement from TP to the target. */
941 HOWTO (R_ALPHA_TPREL16, /* type */
943 1, /* size (0 = byte, 1 = short, 2 = long) */
945 FALSE, /* pc_relative */
947 complain_overflow_signed, /* complain_on_overflow */
948 0, /* special_function */
949 "TPREL16", /* name */
950 FALSE, /* partial_inplace */
951 0xffff, /* src_mask */
952 0xffff, /* dst_mask */
953 FALSE), /* pcrel_offset */
956 /* A relocation function which doesn't do anything. */
958 static bfd_reloc_status_type
959 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
960 bfd *abfd ATTRIBUTE_UNUSED;
962 asymbol *sym ATTRIBUTE_UNUSED;
963 PTR data ATTRIBUTE_UNUSED;
966 char **error_message ATTRIBUTE_UNUSED;
969 reloc->address += sec->output_offset;
973 /* A relocation function used for an unsupported reloc. */
975 static bfd_reloc_status_type
976 elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
977 bfd *abfd ATTRIBUTE_UNUSED;
979 asymbol *sym ATTRIBUTE_UNUSED;
980 PTR data ATTRIBUTE_UNUSED;
983 char **error_message ATTRIBUTE_UNUSED;
986 reloc->address += sec->output_offset;
987 return bfd_reloc_notsupported;
990 /* Do the work of the GPDISP relocation. */
992 static bfd_reloc_status_type
993 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
999 bfd_reloc_status_type ret = bfd_reloc_ok;
1001 unsigned long i_ldah, i_lda;
1003 i_ldah = bfd_get_32 (abfd, p_ldah);
1004 i_lda = bfd_get_32 (abfd, p_lda);
1006 /* Complain if the instructions are not correct. */
1007 if (((i_ldah >> 26) & 0x3f) != 0x09
1008 || ((i_lda >> 26) & 0x3f) != 0x08)
1009 ret = bfd_reloc_dangerous;
1011 /* Extract the user-supplied offset, mirroring the sign extensions
1012 that the instructions perform. */
1013 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
1014 addend = (addend ^ 0x80008000) - 0x80008000;
1018 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000
1019 || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000)
1020 ret = bfd_reloc_overflow;
1022 /* compensate for the sign extension again. */
1023 i_ldah = ((i_ldah & 0xffff0000)
1024 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
1025 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
1027 bfd_put_32 (abfd, (bfd_vma) i_ldah, p_ldah);
1028 bfd_put_32 (abfd, (bfd_vma) i_lda, p_lda);
1033 /* The special function for the GPDISP reloc. */
1035 static bfd_reloc_status_type
1036 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
1037 output_bfd, err_msg)
1039 arelent *reloc_entry;
1040 asymbol *sym ATTRIBUTE_UNUSED;
1042 asection *input_section;
1046 bfd_reloc_status_type ret;
1047 bfd_vma gp, relocation;
1048 bfd_byte *p_ldah, *p_lda;
1050 /* Don't do anything if we're not doing a final link. */
1053 reloc_entry->address += input_section->output_offset;
1054 return bfd_reloc_ok;
1057 if (reloc_entry->address > input_section->_cooked_size ||
1058 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
1059 return bfd_reloc_outofrange;
1061 /* The gp used in the portion of the output object to which this
1062 input object belongs is cached on the input bfd. */
1063 gp = _bfd_get_gp_value (abfd);
1065 relocation = (input_section->output_section->vma
1066 + input_section->output_offset
1067 + reloc_entry->address);
1069 p_ldah = (bfd_byte *) data + reloc_entry->address;
1070 p_lda = p_ldah + reloc_entry->addend;
1072 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
1074 /* Complain if the instructions are not correct. */
1075 if (ret == bfd_reloc_dangerous)
1076 *err_msg = _("GPDISP relocation did not find ldah and lda instructions");
1081 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1083 struct elf_reloc_map
1085 bfd_reloc_code_real_type bfd_reloc_val;
1089 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
1091 {BFD_RELOC_NONE, R_ALPHA_NONE},
1092 {BFD_RELOC_32, R_ALPHA_REFLONG},
1093 {BFD_RELOC_64, R_ALPHA_REFQUAD},
1094 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
1095 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
1096 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
1097 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
1098 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
1099 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
1100 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
1101 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
1102 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
1103 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
1104 {BFD_RELOC_ALPHA_GPREL_HI16, R_ALPHA_GPRELHIGH},
1105 {BFD_RELOC_ALPHA_GPREL_LO16, R_ALPHA_GPRELLOW},
1106 {BFD_RELOC_GPREL16, R_ALPHA_GPREL16},
1107 {BFD_RELOC_ALPHA_BRSGP, R_ALPHA_BRSGP},
1108 {BFD_RELOC_ALPHA_TLSGD, R_ALPHA_TLSGD},
1109 {BFD_RELOC_ALPHA_TLSLDM, R_ALPHA_TLSLDM},
1110 {BFD_RELOC_ALPHA_DTPMOD64, R_ALPHA_DTPMOD64},
1111 {BFD_RELOC_ALPHA_GOTDTPREL16, R_ALPHA_GOTDTPREL},
1112 {BFD_RELOC_ALPHA_DTPREL64, R_ALPHA_DTPREL64},
1113 {BFD_RELOC_ALPHA_DTPREL_HI16, R_ALPHA_DTPRELHI},
1114 {BFD_RELOC_ALPHA_DTPREL_LO16, R_ALPHA_DTPRELLO},
1115 {BFD_RELOC_ALPHA_DTPREL16, R_ALPHA_DTPREL16},
1116 {BFD_RELOC_ALPHA_GOTTPREL16, R_ALPHA_GOTTPREL},
1117 {BFD_RELOC_ALPHA_TPREL64, R_ALPHA_TPREL64},
1118 {BFD_RELOC_ALPHA_TPREL_HI16, R_ALPHA_TPRELHI},
1119 {BFD_RELOC_ALPHA_TPREL_LO16, R_ALPHA_TPRELLO},
1120 {BFD_RELOC_ALPHA_TPREL16, R_ALPHA_TPREL16},
1123 /* Given a BFD reloc type, return a HOWTO structure. */
1125 static reloc_howto_type *
1126 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
1127 bfd *abfd ATTRIBUTE_UNUSED;
1128 bfd_reloc_code_real_type code;
1130 const struct elf_reloc_map *i, *e;
1131 i = e = elf64_alpha_reloc_map;
1132 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
1135 if (i->bfd_reloc_val == code)
1136 return &elf64_alpha_howto_table[i->elf_reloc_val];
1141 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1144 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
1145 bfd *abfd ATTRIBUTE_UNUSED;
1147 Elf_Internal_Rela *dst;
1151 r_type = ELF64_R_TYPE(dst->r_info);
1152 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
1153 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
1156 /* These two relocations create a two-word entry in the got. */
1157 #define alpha_got_entry_size(r_type) \
1158 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1160 /* This is PT_TLS segment p_vaddr. */
1161 #define alpha_get_dtprel_base(tlss) \
1164 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1165 is assigned offset round(16, PT_TLS p_align). */
1166 #define alpha_get_tprel_base(tlss) \
1167 ((tlss)->start - align_power ((bfd_vma) 16, (tlss)->align))
1169 /* These functions do relaxation for Alpha ELF.
1171 Currently I'm only handling what I can do with existing compiler
1172 and assembler support, which means no instructions are removed,
1173 though some may be nopped. At this time GCC does not emit enough
1174 information to do all of the relaxing that is possible. It will
1175 take some not small amount of work for that to happen.
1177 There are a couple of interesting papers that I once read on this
1178 subject, that I cannot find references to at the moment, that
1179 related to Alpha in particular. They are by David Wall, then of
1183 #define OP_LDAH 0x09
1184 #define INSN_JSR 0x68004000
1185 #define INSN_JSR_MASK 0xfc00c000
1189 #define INSN_UNOP 0x2ffe0000
1190 #define INSN_ADDQ 0x40000400
1191 #define INSN_RDUNIQ 0x0000009e
1193 struct alpha_relax_info
1198 Elf_Internal_Shdr *symtab_hdr;
1199 Elf_Internal_Rela *relocs, *relend;
1200 struct bfd_link_info *link_info;
1201 struct elf_link_tls_segment *tls_segment;
1205 struct alpha_elf_link_hash_entry *h;
1206 struct alpha_elf_got_entry **first_gotent;
1207 struct alpha_elf_got_entry *gotent;
1208 bfd_boolean changed_contents;
1209 bfd_boolean changed_relocs;
1210 unsigned char other;
1213 static bfd_boolean elf64_alpha_relax_with_lituse
1214 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1215 Elf_Internal_Rela *irel));
1216 static bfd_vma elf64_alpha_relax_opt_call
1217 PARAMS((struct alpha_relax_info *info, bfd_vma symval));
1218 static bfd_boolean elf64_alpha_relax_got_load
1219 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1220 Elf_Internal_Rela *irel, unsigned long));
1221 static bfd_boolean elf64_alpha_relax_gprelhilo
1222 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1223 Elf_Internal_Rela *irel, bfd_boolean));
1224 static bfd_boolean elf64_alpha_relax_tls_get_addr
1225 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1226 Elf_Internal_Rela *irel, bfd_boolean));
1227 static struct elf_link_tls_segment *elf64_alpha_relax_find_tls_segment
1228 PARAMS((struct alpha_relax_info *, struct elf_link_tls_segment *));
1229 static bfd_boolean elf64_alpha_relax_section
1230 PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
1231 bfd_boolean *again));
1233 static Elf_Internal_Rela *
1234 elf64_alpha_find_reloc_at_ofs (rel, relend, offset, type)
1235 Elf_Internal_Rela *rel, *relend;
1239 while (rel < relend)
1241 if (rel->r_offset == offset
1242 && ELF64_R_TYPE (rel->r_info) == (unsigned int) type)
1250 elf64_alpha_relax_with_lituse (info, symval, irel)
1251 struct alpha_relax_info *info;
1253 Elf_Internal_Rela *irel;
1255 Elf_Internal_Rela *urel, *irelend = info->relend;
1256 int flags, count, i;
1257 bfd_signed_vma disp;
1260 bfd_boolean lit_reused = FALSE;
1261 bfd_boolean all_optimized = TRUE;
1262 unsigned int lit_insn;
1264 lit_insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1265 if (lit_insn >> 26 != OP_LDQ)
1267 ((*_bfd_error_handler)
1268 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1269 bfd_archive_filename (info->abfd), info->sec->name,
1270 (unsigned long) irel->r_offset));
1274 /* Can't relax dynamic symbols. */
1275 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info))
1278 /* Summarize how this particular LITERAL is used. */
1279 for (urel = irel+1, flags = count = 0; urel < irelend; ++urel, ++count)
1281 if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE)
1283 if (urel->r_addend <= 3)
1284 flags |= 1 << urel->r_addend;
1287 /* A little preparation for the loop... */
1288 disp = symval - info->gp;
1290 for (urel = irel+1, i = 0; i < count; ++i, ++urel)
1294 bfd_signed_vma xdisp;
1296 insn = bfd_get_32 (info->abfd, info->contents + urel->r_offset);
1298 switch (urel->r_addend)
1300 case LITUSE_ALPHA_ADDR:
1302 /* This type is really just a placeholder to note that all
1303 uses cannot be optimized, but to still allow some. */
1304 all_optimized = FALSE;
1307 case LITUSE_ALPHA_BASE:
1308 /* We can always optimize 16-bit displacements. */
1310 /* Extract the displacement from the instruction, sign-extending
1311 it if necessary, then test whether it is within 16 or 32 bits
1312 displacement from GP. */
1313 insn_disp = insn & 0x0000ffff;
1314 if (insn_disp & 0x8000)
1315 insn_disp |= ~0xffff; /* Negative: sign-extend. */
1317 xdisp = disp + insn_disp;
1318 fits16 = (xdisp >= - (bfd_signed_vma) 0x8000 && xdisp < 0x8000);
1319 fits32 = (xdisp >= - (bfd_signed_vma) 0x80000000
1320 && xdisp < 0x7fff8000);
1324 /* Take the op code and dest from this insn, take the base
1325 register from the literal insn. Leave the offset alone. */
1326 insn = (insn & 0xffe0ffff) | (lit_insn & 0x001f0000);
1327 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1329 urel->r_addend = irel->r_addend;
1330 info->changed_relocs = TRUE;
1332 bfd_put_32 (info->abfd, (bfd_vma) insn,
1333 info->contents + urel->r_offset);
1334 info->changed_contents = TRUE;
1337 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1338 else if (fits32 && !(flags & ~6))
1340 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
1342 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1344 lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000);
1345 bfd_put_32 (info->abfd, (bfd_vma) lit_insn,
1346 info->contents + irel->r_offset);
1348 info->changed_contents = TRUE;
1350 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1352 urel->r_addend = irel->r_addend;
1353 info->changed_relocs = TRUE;
1356 all_optimized = FALSE;
1359 case LITUSE_ALPHA_BYTOFF:
1360 /* We can always optimize byte instructions. */
1362 /* FIXME: sanity check the insn for byte op. Check that the
1363 literal dest reg is indeed Rb in the byte insn. */
1365 insn &= ~ (unsigned) 0x001ff000;
1366 insn |= ((symval & 7) << 13) | 0x1000;
1368 urel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1370 info->changed_relocs = TRUE;
1372 bfd_put_32 (info->abfd, (bfd_vma) insn,
1373 info->contents + urel->r_offset);
1374 info->changed_contents = TRUE;
1377 case LITUSE_ALPHA_JSR:
1378 case LITUSE_ALPHA_TLSGD:
1379 case LITUSE_ALPHA_TLSLDM:
1381 bfd_vma optdest, org;
1382 bfd_signed_vma odisp;
1384 /* If not zero, place to jump without needing pv. */
1385 optdest = elf64_alpha_relax_opt_call (info, symval);
1386 org = (info->sec->output_section->vma
1387 + info->sec->output_offset
1388 + urel->r_offset + 4);
1389 odisp = (optdest ? optdest : symval) - org;
1391 if (odisp >= -0x400000 && odisp < 0x400000)
1393 Elf_Internal_Rela *xrel;
1395 /* Preserve branch prediction call stack when possible. */
1396 if ((insn & INSN_JSR_MASK) == INSN_JSR)
1397 insn = (OP_BSR << 26) | (insn & 0x03e00000);
1399 insn = (OP_BR << 26) | (insn & 0x03e00000);
1401 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1403 urel->r_addend = irel->r_addend;
1406 urel->r_addend += optdest - symval;
1408 all_optimized = FALSE;
1410 bfd_put_32 (info->abfd, (bfd_vma) insn,
1411 info->contents + urel->r_offset);
1413 /* Kill any HINT reloc that might exist for this insn. */
1414 xrel = (elf64_alpha_find_reloc_at_ofs
1415 (info->relocs, info->relend, urel->r_offset,
1418 xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1420 info->changed_contents = TRUE;
1421 info->changed_relocs = TRUE;
1424 all_optimized = FALSE;
1426 /* Even if the target is not in range for a direct branch,
1427 if we share a GP, we can eliminate the gp reload. */
1430 Elf_Internal_Rela *gpdisp
1431 = (elf64_alpha_find_reloc_at_ofs
1432 (info->relocs, irelend, urel->r_offset + 4,
1436 bfd_byte *p_ldah = info->contents + gpdisp->r_offset;
1437 bfd_byte *p_lda = p_ldah + gpdisp->r_addend;
1438 unsigned int ldah = bfd_get_32 (info->abfd, p_ldah);
1439 unsigned int lda = bfd_get_32 (info->abfd, p_lda);
1441 /* Verify that the instruction is "ldah $29,0($26)".
1442 Consider a function that ends in a noreturn call,
1443 and that the next function begins with an ldgp,
1444 and that by accident there is no padding between.
1445 In that case the insn would use $27 as the base. */
1446 if (ldah == 0x27ba0000 && lda == 0x23bd0000)
1448 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_ldah);
1449 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_lda);
1451 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1452 info->changed_contents = TRUE;
1453 info->changed_relocs = TRUE;
1462 /* If all cases were optimized, we can reduce the use count on this
1463 got entry by one, possibly eliminating it. */
1466 if (--info->gotent->use_count == 0)
1468 int sz = alpha_got_entry_size (R_ALPHA_LITERAL);
1469 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1471 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1474 /* If the literal instruction is no longer needed (it may have been
1475 reused. We can eliminate it. */
1476 /* ??? For now, I don't want to deal with compacting the section,
1477 so just nop it out. */
1480 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1481 info->changed_relocs = TRUE;
1483 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP,
1484 info->contents + irel->r_offset);
1485 info->changed_contents = TRUE;
1493 elf64_alpha_relax_opt_call (info, symval)
1494 struct alpha_relax_info *info;
1497 /* If the function has the same gp, and we can identify that the
1498 function does not use its function pointer, we can eliminate the
1501 /* If the symbol is marked NOPV, we are being told the function never
1502 needs its procedure value. */
1503 if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV)
1506 /* If the symbol is marked STD_GP, we are being told the function does
1507 a normal ldgp in the first two words. */
1508 else if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD)
1511 /* Otherwise, we may be able to identify a GP load in the first two
1512 words, which we can then skip. */
1515 Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp;
1518 /* Load the relocations from the section that the target symbol is in. */
1519 if (info->sec == info->tsec)
1521 tsec_relocs = info->relocs;
1522 tsec_relend = info->relend;
1527 tsec_relocs = (_bfd_elf_link_read_relocs
1528 (info->abfd, info->tsec, (PTR) NULL,
1529 (Elf_Internal_Rela *) NULL,
1530 info->link_info->keep_memory));
1531 if (tsec_relocs == NULL)
1533 tsec_relend = tsec_relocs + info->tsec->reloc_count;
1534 tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs);
1537 /* Recover the symbol's offset within the section. */
1538 ofs = (symval - info->tsec->output_section->vma
1539 - info->tsec->output_offset);
1541 /* Look for a GPDISP reloc. */
1542 gpdisp = (elf64_alpha_find_reloc_at_ofs
1543 (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP));
1545 if (!gpdisp || gpdisp->r_addend != 4)
1555 /* We've now determined that we can skip an initial gp load. Verify
1556 that the call and the target use the same gp. */
1557 if (info->link_info->hash->creator != info->tsec->owner->xvec
1558 || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj)
1565 elf64_alpha_relax_got_load (info, symval, irel, r_type)
1566 struct alpha_relax_info *info;
1568 Elf_Internal_Rela *irel;
1569 unsigned long r_type;
1572 bfd_signed_vma disp;
1574 /* Get the instruction. */
1575 insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1577 if (insn >> 26 != OP_LDQ)
1579 reloc_howto_type *howto = elf64_alpha_howto_table + r_type;
1580 ((*_bfd_error_handler)
1581 ("%s: %s+0x%lx: warning: %s relocation against unexpected insn",
1582 bfd_archive_filename (info->abfd), info->sec->name,
1583 (unsigned long) irel->r_offset, howto->name));
1587 /* Can't relax dynamic symbols. */
1588 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info))
1591 /* Can't use local-exec relocations in shared libraries. */
1592 if (r_type == R_ALPHA_GOTTPREL && info->link_info->shared)
1595 if (r_type == R_ALPHA_LITERAL)
1596 disp = symval - info->gp;
1599 bfd_vma dtp_base, tp_base;
1601 BFD_ASSERT (info->tls_segment != NULL);
1602 dtp_base = alpha_get_dtprel_base (info->tls_segment);
1603 tp_base = alpha_get_tprel_base (info->tls_segment);
1604 disp = symval - (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base);
1607 if (disp < -0x8000 || disp >= 0x8000)
1610 /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading
1611 a constant, so force the base register to be $31. */
1612 if (r_type == R_ALPHA_LITERAL)
1613 insn = (OP_LDA << 26) | (insn & 0x03ff0000);
1615 insn = (OP_LDA << 26) | (insn & (31 << 21)) | (31 << 16);
1616 bfd_put_32 (info->abfd, (bfd_vma) insn, info->contents + irel->r_offset);
1617 info->changed_contents = TRUE;
1619 /* Reduce the use count on this got entry by one, possibly
1621 if (--info->gotent->use_count == 0)
1623 int sz = alpha_got_entry_size (r_type);
1624 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1626 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1629 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
1632 case R_ALPHA_LITERAL:
1633 r_type = R_ALPHA_GPREL16;
1635 case R_ALPHA_GOTDTPREL:
1636 r_type = R_ALPHA_DTPREL16;
1638 case R_ALPHA_GOTTPREL:
1639 r_type = R_ALPHA_TPREL16;
1646 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), r_type);
1647 info->changed_relocs = TRUE;
1649 /* ??? Search forward through this basic block looking for insns
1650 that use the target register. Stop after an insn modifying the
1651 register is seen, or after a branch or call.
1653 Any such memory load insn may be substituted by a load directly
1654 off the GP. This allows the memory load insn to be issued before
1655 the calculated GP register would otherwise be ready.
1657 Any such jsr insn can be replaced by a bsr if it is in range.
1659 This would mean that we'd have to _add_ relocations, the pain of
1660 which gives one pause. */
1666 elf64_alpha_relax_gprelhilo (info, symval, irel, hi)
1667 struct alpha_relax_info *info;
1669 Elf_Internal_Rela *irel;
1673 bfd_signed_vma disp;
1674 bfd_byte *pos = info->contents + irel->r_offset;
1676 /* ??? This assumes that the compiler doesn't render
1680 ldah t, array(gp) !gprelhigh
1682 ldq r, array(t) !gprellow
1684 which would indeed be the most efficient way to implement this. */
1688 disp = symval - info->gp;
1689 if (disp < -0x8000 || disp >= 0x8000)
1694 /* Nop out the high instruction. */
1696 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos);
1697 info->changed_contents = TRUE;
1699 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1701 info->changed_relocs = TRUE;
1705 /* Adjust the low instruction to reference GP directly. */
1707 insn = bfd_get_32 (info->abfd, pos);
1708 insn = (insn & 0xffe00000) | (29 << 16);
1709 bfd_put_32 (info->abfd, (bfd_vma) insn, pos);
1710 info->changed_contents = TRUE;
1712 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1714 info->changed_relocs = TRUE;
1721 elf64_alpha_relax_tls_get_addr (info, symval, irel, is_gd)
1722 struct alpha_relax_info *info;
1724 Elf_Internal_Rela *irel;
1729 Elf_Internal_Rela *gpdisp, *hint;
1730 bfd_boolean dynamic, use_gottprel, pos1_unusable;
1731 unsigned long new_symndx;
1733 dynamic = alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info);
1735 /* If a TLS symbol is accessed using IE at least once, there is no point
1736 to use dynamic model for it. */
1737 if (is_gd && info->h && (info->h->flags & ALPHA_ELF_LINK_HASH_TLS_IE))
1740 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
1741 then we might as well relax to IE. */
1742 else if (info->link_info->shared && !dynamic
1743 && (info->link_info->flags & DF_STATIC_TLS))
1746 /* Otherwise we must be building an executable to do anything. */
1747 else if (info->link_info->shared)
1750 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
1751 the matching LITUSE_TLS relocations. */
1752 if (irel + 2 >= info->relend)
1754 if (ELF64_R_TYPE (irel[1].r_info) != R_ALPHA_LITERAL
1755 || ELF64_R_TYPE (irel[2].r_info) != R_ALPHA_LITUSE
1756 || irel[2].r_addend != (is_gd ? LITUSE_ALPHA_TLSGD : LITUSE_ALPHA_TLSLDM))
1759 /* There must be a GPDISP relocation positioned immediately after the
1760 LITUSE relocation. */
1761 gpdisp = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend,
1762 irel[2].r_offset + 4, R_ALPHA_GPDISP);
1766 pos[0] = info->contents + irel[0].r_offset;
1767 pos[1] = info->contents + irel[1].r_offset;
1768 pos[2] = info->contents + irel[2].r_offset;
1769 pos[3] = info->contents + gpdisp->r_offset;
1770 pos[4] = pos[3] + gpdisp->r_addend;
1771 pos1_unusable = FALSE;
1773 /* Generally, the positions are not allowed to be out of order, lest the
1774 modified insn sequence have different register lifetimes. We can make
1775 an exception when pos 1 is adjacent to pos 0. */
1776 if (pos[1] + 4 == pos[0])
1778 bfd_byte *tmp = pos[0];
1782 else if (pos[1] < pos[0])
1783 pos1_unusable = TRUE;
1784 if (pos[1] >= pos[2] || pos[2] >= pos[3])
1787 /* Reduce the use count on the LITERAL relocation. Do this before we
1788 smash the symndx when we adjust the relocations below. */
1790 struct alpha_elf_got_entry *lit_gotent;
1791 struct alpha_elf_link_hash_entry *lit_h;
1794 BFD_ASSERT (ELF64_R_SYM (irel[1].r_info) >= info->symtab_hdr->sh_info);
1795 indx = ELF64_R_SYM (irel[1].r_info) - info->symtab_hdr->sh_info;
1796 lit_h = alpha_elf_sym_hashes (info->abfd)[indx];
1798 while (lit_h->root.root.type == bfd_link_hash_indirect
1799 || lit_h->root.root.type == bfd_link_hash_warning)
1800 lit_h = (struct alpha_elf_link_hash_entry *) lit_h->root.root.u.i.link;
1802 for (lit_gotent = lit_h->got_entries; lit_gotent ;
1803 lit_gotent = lit_gotent->next)
1804 if (lit_gotent->gotobj == info->gotobj
1805 && lit_gotent->reloc_type == R_ALPHA_LITERAL
1806 && lit_gotent->addend == irel[1].r_addend)
1808 BFD_ASSERT (lit_gotent);
1810 if (--lit_gotent->use_count == 0)
1812 int sz = alpha_got_entry_size (R_ALPHA_LITERAL);
1813 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1819 lda $16,x($gp) !tlsgd!1
1820 ldq $27,__tls_get_addr($gp) !literal!1
1821 jsr $26,($27)__tls_get_addr !lituse_tlsgd!1
1822 ldah $29,0($26) !gpdisp!2
1823 lda $29,0($29) !gpdisp!2
1825 ldq $16,x($gp) !gottprel
1830 or the first pair to
1831 lda $16,x($gp) !tprel
1834 ldah $16,x($gp) !tprelhi
1835 lda $16,x($16) !tprello
1839 use_gottprel = FALSE;
1840 new_symndx = is_gd ? ELF64_R_SYM (irel->r_info) : 0;
1841 switch (!dynamic && !info->link_info->shared)
1846 bfd_signed_vma disp;
1848 BFD_ASSERT (info->tls_segment != NULL);
1849 tp_base = alpha_get_tprel_base (info->tls_segment);
1850 disp = symval - tp_base;
1852 if (disp >= -0x8000 && disp < 0x8000)
1854 insn = (OP_LDA << 26) | (16 << 21) | (31 << 16);
1855 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1856 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]);
1858 irel[0].r_offset = pos[0] - info->contents;
1859 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPREL16);
1860 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1863 else if (disp >= -(bfd_signed_vma) 0x80000000
1864 && disp < (bfd_signed_vma) 0x7fff8000
1867 insn = (OP_LDAH << 26) | (16 << 21) | (31 << 16);
1868 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1869 insn = (OP_LDA << 26) | (16 << 21) | (16 << 16);
1870 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[1]);
1872 irel[0].r_offset = pos[0] - info->contents;
1873 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPRELHI);
1874 irel[1].r_offset = pos[1] - info->contents;
1875 irel[1].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPRELLO);
1882 use_gottprel = TRUE;
1884 insn = (OP_LDQ << 26) | (16 << 21) | (29 << 16);
1885 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1886 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]);
1888 irel[0].r_offset = pos[0] - info->contents;
1889 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_GOTTPREL);
1890 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1894 bfd_put_32 (info->abfd, (bfd_vma) INSN_RDUNIQ, pos[2]);
1896 insn = INSN_ADDQ | (16 << 21) | (0 << 16) | (0 << 0);
1897 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[3]);
1899 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[4]);
1901 irel[2].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1902 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1904 hint = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend,
1905 irel[2].r_offset, R_ALPHA_HINT);
1907 hint->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1909 info->changed_contents = TRUE;
1910 info->changed_relocs = TRUE;
1912 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
1913 if (--info->gotent->use_count == 0)
1915 int sz = alpha_got_entry_size (info->gotent->reloc_type);
1916 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1918 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1921 /* If we've switched to a GOTTPREL relocation, increment the reference
1922 count on that got entry. */
1925 struct alpha_elf_got_entry *tprel_gotent;
1927 for (tprel_gotent = *info->first_gotent; tprel_gotent ;
1928 tprel_gotent = tprel_gotent->next)
1929 if (tprel_gotent->gotobj == info->gotobj
1930 && tprel_gotent->reloc_type == R_ALPHA_GOTTPREL
1931 && tprel_gotent->addend == irel->r_addend)
1934 tprel_gotent->use_count++;
1937 if (info->gotent->use_count == 0)
1938 tprel_gotent = info->gotent;
1941 tprel_gotent = (struct alpha_elf_got_entry *)
1942 bfd_alloc (info->abfd, sizeof (struct alpha_elf_got_entry));
1946 tprel_gotent->next = *info->first_gotent;
1947 *info->first_gotent = tprel_gotent;
1949 tprel_gotent->gotobj = info->gotobj;
1950 tprel_gotent->addend = irel->r_addend;
1951 tprel_gotent->got_offset = -1;
1952 tprel_gotent->reloc_done = 0;
1953 tprel_gotent->reloc_xlated = 0;
1956 tprel_gotent->use_count = 1;
1957 tprel_gotent->reloc_type = R_ALPHA_GOTTPREL;
1964 static struct elf_link_tls_segment *
1965 elf64_alpha_relax_find_tls_segment (info, seg)
1966 struct alpha_relax_info *info;
1967 struct elf_link_tls_segment *seg;
1969 bfd *output_bfd = info->sec->output_section->owner;
1974 for (o = output_bfd->sections; o ; o = o->next)
1975 if ((o->flags & SEC_THREAD_LOCAL) != 0
1976 && (o->flags & SEC_LOAD) != 0)
1988 if (bfd_get_section_alignment (output_bfd, o) > align)
1989 align = bfd_get_section_alignment (output_bfd, o);
1991 size = o->_raw_size;
1992 if (size == 0 && (o->flags & SEC_HAS_CONTENTS) == 0)
1994 struct bfd_link_order *lo;
1995 for (lo = o->link_order_head; lo ; lo = lo->next)
1996 if (size < lo->offset + lo->size)
1997 size = lo->offset + lo->size;
1999 end = o->vma + size;
2002 while (o && (o->flags & SEC_THREAD_LOCAL));
2005 seg->size = end - base;
2012 elf64_alpha_relax_section (abfd, sec, link_info, again)
2015 struct bfd_link_info *link_info;
2018 Elf_Internal_Shdr *symtab_hdr;
2019 Elf_Internal_Rela *internal_relocs;
2020 Elf_Internal_Rela *irel, *irelend;
2021 Elf_Internal_Sym *isymbuf = NULL;
2022 struct alpha_elf_got_entry **local_got_entries;
2023 struct alpha_relax_info info;
2024 struct elf_link_tls_segment tls_segment;
2026 /* We are not currently changing any sizes, so only one pass. */
2029 if (link_info->relocatable
2030 || (sec->flags & SEC_RELOC) == 0
2031 || sec->reloc_count == 0)
2034 /* If this is the first time we have been called for this section,
2035 initialize the cooked size. */
2036 if (sec->_cooked_size == 0)
2037 sec->_cooked_size = sec->_raw_size;
2039 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2040 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2042 /* Load the relocations for this section. */
2043 internal_relocs = (_bfd_elf_link_read_relocs
2044 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2045 link_info->keep_memory));
2046 if (internal_relocs == NULL)
2049 memset(&info, 0, sizeof (info));
2052 info.link_info = link_info;
2053 info.symtab_hdr = symtab_hdr;
2054 info.relocs = internal_relocs;
2055 info.relend = irelend = internal_relocs + sec->reloc_count;
2057 /* Find the GP for this object. Do not store the result back via
2058 _bfd_set_gp_value, since this could change again before final. */
2059 info.gotobj = alpha_elf_tdata (abfd)->gotobj;
2062 asection *sgot = alpha_elf_tdata (info.gotobj)->got;
2063 info.gp = (sgot->output_section->vma
2064 + sgot->output_offset
2068 /* Get the section contents. */
2069 if (elf_section_data (sec)->this_hdr.contents != NULL)
2070 info.contents = elf_section_data (sec)->this_hdr.contents;
2073 info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2074 if (info.contents == NULL)
2077 if (! bfd_get_section_contents (abfd, sec, info.contents,
2078 (file_ptr) 0, sec->_raw_size))
2082 /* Compute the TLS segment information. The version normally found in
2083 elf_hash_table (link_info)->tls_segment isn't built until final_link.
2084 ??? Probably should look into extracting this into a common function. */
2085 info.tls_segment = elf64_alpha_relax_find_tls_segment (&info, &tls_segment);
2087 for (irel = internal_relocs; irel < irelend; irel++)
2090 struct alpha_elf_got_entry *gotent;
2091 unsigned long r_type = ELF64_R_TYPE (irel->r_info);
2092 unsigned long r_symndx = ELF64_R_SYM (irel->r_info);
2094 /* Early exit for unhandled or unrelaxable relocations. */
2097 case R_ALPHA_LITERAL:
2098 case R_ALPHA_GPRELHIGH:
2099 case R_ALPHA_GPRELLOW:
2100 case R_ALPHA_GOTDTPREL:
2101 case R_ALPHA_GOTTPREL:
2105 case R_ALPHA_TLSLDM:
2106 /* The symbol for a TLSLDM reloc is ignored. Collapse the
2107 reloc to the 0 symbol so that they all match. */
2115 /* Get the value of the symbol referred to by the reloc. */
2116 if (r_symndx < symtab_hdr->sh_info)
2118 /* A local symbol. */
2119 Elf_Internal_Sym *isym;
2121 /* Read this BFD's local symbols. */
2122 if (isymbuf == NULL)
2124 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2125 if (isymbuf == NULL)
2126 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2127 symtab_hdr->sh_info, 0,
2129 if (isymbuf == NULL)
2133 isym = isymbuf + r_symndx;
2135 /* Given the symbol for a TLSLDM reloc is ignored, this also
2136 means forcing the symbol value to the tp base. */
2137 if (r_type == R_ALPHA_TLSLDM)
2139 info.tsec = bfd_abs_section_ptr;
2140 symval = alpha_get_tprel_base (info.tls_segment);
2144 symval = isym->st_value;
2145 if (isym->st_shndx == SHN_UNDEF)
2147 else if (isym->st_shndx == SHN_ABS)
2148 info.tsec = bfd_abs_section_ptr;
2149 else if (isym->st_shndx == SHN_COMMON)
2150 info.tsec = bfd_com_section_ptr;
2152 info.tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2156 info.other = isym->st_other;
2157 if (local_got_entries)
2158 info.first_gotent = &local_got_entries[r_symndx];
2161 info.first_gotent = &info.gotent;
2168 struct alpha_elf_link_hash_entry *h;
2170 indx = r_symndx - symtab_hdr->sh_info;
2171 h = alpha_elf_sym_hashes (abfd)[indx];
2172 BFD_ASSERT (h != NULL);
2174 while (h->root.root.type == bfd_link_hash_indirect
2175 || h->root.root.type == bfd_link_hash_warning)
2176 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2178 /* If the symbol is undefined, we can't do anything with it. */
2179 if (h->root.root.type == bfd_link_hash_undefweak
2180 || h->root.root.type == bfd_link_hash_undefined)
2183 /* If the symbol isn't defined in the current module, again
2184 we can't do anything. */
2185 if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2187 /* Except for TLSGD relocs, which can sometimes be
2188 relaxed to GOTTPREL relocs. */
2189 if (r_type != R_ALPHA_TLSGD)
2191 info.tsec = bfd_abs_section_ptr;
2196 info.tsec = h->root.root.u.def.section;
2197 symval = h->root.root.u.def.value;
2201 info.other = h->root.other;
2202 info.first_gotent = &h->got_entries;
2205 /* Search for the got entry to be used by this relocation. */
2206 for (gotent = *info.first_gotent; gotent ; gotent = gotent->next)
2207 if (gotent->gotobj == info.gotobj
2208 && gotent->reloc_type == r_type
2209 && gotent->addend == irel->r_addend)
2211 info.gotent = gotent;
2213 symval += info.tsec->output_section->vma + info.tsec->output_offset;
2214 symval += irel->r_addend;
2218 case R_ALPHA_LITERAL:
2219 BFD_ASSERT(info.gotent != NULL);
2221 /* If there exist LITUSE relocations immediately following, this
2222 opens up all sorts of interesting optimizations, because we
2223 now know every location that this address load is used. */
2224 if (irel+1 < irelend
2225 && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE)
2227 if (!elf64_alpha_relax_with_lituse (&info, symval, irel))
2232 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type))
2237 case R_ALPHA_GPRELHIGH:
2238 case R_ALPHA_GPRELLOW:
2239 if (!elf64_alpha_relax_gprelhilo (&info, symval, irel,
2240 r_type == R_ALPHA_GPRELHIGH))
2244 case R_ALPHA_GOTDTPREL:
2245 case R_ALPHA_GOTTPREL:
2246 BFD_ASSERT(info.gotent != NULL);
2247 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type))
2252 case R_ALPHA_TLSLDM:
2253 BFD_ASSERT(info.gotent != NULL);
2254 if (!elf64_alpha_relax_tls_get_addr (&info, symval, irel,
2255 r_type == R_ALPHA_TLSGD))
2261 if (!elf64_alpha_size_plt_section (link_info))
2263 if (!elf64_alpha_size_got_sections (link_info))
2265 if (!elf64_alpha_size_rela_got_section (link_info))
2269 && symtab_hdr->contents != (unsigned char *) isymbuf)
2271 if (!link_info->keep_memory)
2275 /* Cache the symbols for elf_link_input_bfd. */
2276 symtab_hdr->contents = (unsigned char *) isymbuf;
2280 if (info.contents != NULL
2281 && elf_section_data (sec)->this_hdr.contents != info.contents)
2283 if (!info.changed_contents && !link_info->keep_memory)
2284 free (info.contents);
2287 /* Cache the section contents for elf_link_input_bfd. */
2288 elf_section_data (sec)->this_hdr.contents = info.contents;
2292 if (elf_section_data (sec)->relocs != internal_relocs)
2294 if (!info.changed_relocs)
2295 free (internal_relocs);
2297 elf_section_data (sec)->relocs = internal_relocs;
2300 *again = info.changed_contents || info.changed_relocs;
2306 && symtab_hdr->contents != (unsigned char *) isymbuf)
2308 if (info.contents != NULL
2309 && elf_section_data (sec)->this_hdr.contents != info.contents)
2310 free (info.contents);
2311 if (internal_relocs != NULL
2312 && elf_section_data (sec)->relocs != internal_relocs)
2313 free (internal_relocs);
2318 #define PLT_HEADER_SIZE 32
2319 #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */
2320 #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */
2321 #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */
2322 #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */
2324 #define PLT_ENTRY_SIZE 12
2325 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
2326 #define PLT_ENTRY_WORD2 0
2327 #define PLT_ENTRY_WORD3 0
2329 #define MAX_GOT_SIZE (64*1024)
2331 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
2333 /* Handle an Alpha specific section when reading an object file. This
2334 is called when elfcode.h finds a section with an unknown type.
2335 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
2339 elf64_alpha_section_from_shdr (abfd, hdr, name)
2341 Elf_Internal_Shdr *hdr;
2346 /* There ought to be a place to keep ELF backend specific flags, but
2347 at the moment there isn't one. We just keep track of the
2348 sections by their name, instead. Fortunately, the ABI gives
2349 suggested names for all the MIPS specific sections, so we will
2350 probably get away with this. */
2351 switch (hdr->sh_type)
2353 case SHT_ALPHA_DEBUG:
2354 if (strcmp (name, ".mdebug") != 0)
2361 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2363 newsect = hdr->bfd_section;
2365 if (hdr->sh_type == SHT_ALPHA_DEBUG)
2367 if (! bfd_set_section_flags (abfd, newsect,
2368 (bfd_get_section_flags (abfd, newsect)
2376 /* Convert Alpha specific section flags to bfd internal section flags. */
2379 elf64_alpha_section_flags (flags, hdr)
2381 Elf_Internal_Shdr *hdr;
2383 if (hdr->sh_flags & SHF_ALPHA_GPREL)
2384 *flags |= SEC_SMALL_DATA;
2389 /* Set the correct type for an Alpha ELF section. We do this by the
2390 section name, which is a hack, but ought to work. */
2393 elf64_alpha_fake_sections (abfd, hdr, sec)
2395 Elf_Internal_Shdr *hdr;
2398 register const char *name;
2400 name = bfd_get_section_name (abfd, sec);
2402 if (strcmp (name, ".mdebug") == 0)
2404 hdr->sh_type = SHT_ALPHA_DEBUG;
2405 /* In a shared object on Irix 5.3, the .mdebug section has an
2406 entsize of 0. FIXME: Does this matter? */
2407 if ((abfd->flags & DYNAMIC) != 0 )
2408 hdr->sh_entsize = 0;
2410 hdr->sh_entsize = 1;
2412 else if ((sec->flags & SEC_SMALL_DATA)
2413 || strcmp (name, ".sdata") == 0
2414 || strcmp (name, ".sbss") == 0
2415 || strcmp (name, ".lit4") == 0
2416 || strcmp (name, ".lit8") == 0)
2417 hdr->sh_flags |= SHF_ALPHA_GPREL;
2422 /* Hook called by the linker routine which adds symbols from an object
2423 file. We use it to put .comm items in .sbss, and not .bss. */
2426 elf64_alpha_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2428 struct bfd_link_info *info;
2429 const Elf_Internal_Sym *sym;
2430 const char **namep ATTRIBUTE_UNUSED;
2431 flagword *flagsp ATTRIBUTE_UNUSED;
2435 if (sym->st_shndx == SHN_COMMON
2436 && !info->relocatable
2437 && sym->st_size <= elf_gp_size (abfd))
2439 /* Common symbols less than or equal to -G nn bytes are
2440 automatically put into .sbss. */
2442 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2446 scomm = bfd_make_section (abfd, ".scommon");
2448 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2450 | SEC_LINKER_CREATED)))
2455 *valp = sym->st_size;
2461 /* Create the .got section. */
2464 elf64_alpha_create_got_section(abfd, info)
2466 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2470 if ((s = bfd_get_section_by_name (abfd, ".got")))
2472 /* Check for a non-linker created .got? */
2473 if (alpha_elf_tdata (abfd)->got == NULL)
2474 alpha_elf_tdata (abfd)->got = s;
2478 s = bfd_make_section (abfd, ".got");
2480 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2483 | SEC_LINKER_CREATED))
2484 || !bfd_set_section_alignment (abfd, s, 3))
2487 alpha_elf_tdata (abfd)->got = s;
2492 /* Create all the dynamic sections. */
2495 elf64_alpha_create_dynamic_sections (abfd, info)
2497 struct bfd_link_info *info;
2500 struct elf_link_hash_entry *h;
2501 struct bfd_link_hash_entry *bh;
2503 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
2505 s = bfd_make_section (abfd, ".plt");
2507 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2510 | SEC_LINKER_CREATED
2512 || ! bfd_set_section_alignment (abfd, s, 3))
2515 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2518 if (! (_bfd_generic_link_add_one_symbol
2519 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2520 (bfd_vma) 0, (const char *) NULL, FALSE,
2521 get_elf_backend_data (abfd)->collect, &bh)))
2523 h = (struct elf_link_hash_entry *) bh;
2524 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2525 h->type = STT_OBJECT;
2528 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2531 s = bfd_make_section (abfd, ".rela.plt");
2533 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2536 | SEC_LINKER_CREATED
2538 || ! bfd_set_section_alignment (abfd, s, 3))
2541 /* We may or may not have created a .got section for this object, but
2542 we definitely havn't done the rest of the work. */
2544 if (!elf64_alpha_create_got_section (abfd, info))
2547 s = bfd_make_section(abfd, ".rela.got");
2549 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2552 | SEC_LINKER_CREATED
2554 || !bfd_set_section_alignment (abfd, s, 3))
2557 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
2558 dynobj's .got section. We don't do this in the linker script
2559 because we don't want to define the symbol if we are not creating
2560 a global offset table. */
2562 if (!(_bfd_generic_link_add_one_symbol
2563 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
2564 alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
2565 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2567 h = (struct elf_link_hash_entry *) bh;
2568 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2569 h->type = STT_OBJECT;
2572 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2575 elf_hash_table (info)->hgot = h;
2580 /* Read ECOFF debugging information from a .mdebug section into a
2581 ecoff_debug_info structure. */
2584 elf64_alpha_read_ecoff_info (abfd, section, debug)
2587 struct ecoff_debug_info *debug;
2590 const struct ecoff_debug_swap *swap;
2591 char *ext_hdr = NULL;
2593 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2594 memset (debug, 0, sizeof (*debug));
2596 ext_hdr = (char *) bfd_malloc (swap->external_hdr_size);
2597 if (ext_hdr == NULL && swap->external_hdr_size != 0)
2600 if (! bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
2601 swap->external_hdr_size))
2604 symhdr = &debug->symbolic_header;
2605 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
2607 /* The symbolic header contains absolute file offsets and sizes to
2609 #define READ(ptr, offset, count, size, type) \
2610 if (symhdr->count == 0) \
2611 debug->ptr = NULL; \
2614 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
2615 debug->ptr = (type) bfd_malloc (amt); \
2616 if (debug->ptr == NULL) \
2617 goto error_return; \
2618 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2619 || bfd_bread (debug->ptr, amt, abfd) != amt) \
2620 goto error_return; \
2623 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
2624 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
2625 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
2626 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
2627 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
2628 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
2630 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
2631 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
2632 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
2633 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
2634 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
2638 debug->adjust = NULL;
2643 if (ext_hdr != NULL)
2645 if (debug->line != NULL)
2647 if (debug->external_dnr != NULL)
2648 free (debug->external_dnr);
2649 if (debug->external_pdr != NULL)
2650 free (debug->external_pdr);
2651 if (debug->external_sym != NULL)
2652 free (debug->external_sym);
2653 if (debug->external_opt != NULL)
2654 free (debug->external_opt);
2655 if (debug->external_aux != NULL)
2656 free (debug->external_aux);
2657 if (debug->ss != NULL)
2659 if (debug->ssext != NULL)
2660 free (debug->ssext);
2661 if (debug->external_fdr != NULL)
2662 free (debug->external_fdr);
2663 if (debug->external_rfd != NULL)
2664 free (debug->external_rfd);
2665 if (debug->external_ext != NULL)
2666 free (debug->external_ext);
2670 /* Alpha ELF local labels start with '$'. */
2673 elf64_alpha_is_local_label_name (abfd, name)
2674 bfd *abfd ATTRIBUTE_UNUSED;
2677 return name[0] == '$';
2680 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2681 routine in order to handle the ECOFF debugging information. We
2682 still call this mips_elf_find_line because of the slot
2683 find_line_info in elf_obj_tdata is declared that way. */
2685 struct mips_elf_find_line
2687 struct ecoff_debug_info d;
2688 struct ecoff_find_line i;
2692 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2693 functionname_ptr, line_ptr)
2698 const char **filename_ptr;
2699 const char **functionname_ptr;
2700 unsigned int *line_ptr;
2704 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
2705 filename_ptr, functionname_ptr,
2707 &elf_tdata (abfd)->dwarf2_find_line_info))
2710 msec = bfd_get_section_by_name (abfd, ".mdebug");
2714 struct mips_elf_find_line *fi;
2715 const struct ecoff_debug_swap * const swap =
2716 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2718 /* If we are called during a link, alpha_elf_final_link may have
2719 cleared the SEC_HAS_CONTENTS field. We force it back on here
2720 if appropriate (which it normally will be). */
2721 origflags = msec->flags;
2722 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
2723 msec->flags |= SEC_HAS_CONTENTS;
2725 fi = elf_tdata (abfd)->find_line_info;
2728 bfd_size_type external_fdr_size;
2731 struct fdr *fdr_ptr;
2732 bfd_size_type amt = sizeof (struct mips_elf_find_line);
2734 fi = (struct mips_elf_find_line *) bfd_zalloc (abfd, amt);
2737 msec->flags = origflags;
2741 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
2743 msec->flags = origflags;
2747 /* Swap in the FDR information. */
2748 amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr);
2749 fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt);
2750 if (fi->d.fdr == NULL)
2752 msec->flags = origflags;
2755 external_fdr_size = swap->external_fdr_size;
2756 fdr_ptr = fi->d.fdr;
2757 fraw_src = (char *) fi->d.external_fdr;
2758 fraw_end = (fraw_src
2759 + fi->d.symbolic_header.ifdMax * external_fdr_size);
2760 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
2761 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
2763 elf_tdata (abfd)->find_line_info = fi;
2765 /* Note that we don't bother to ever free this information.
2766 find_nearest_line is either called all the time, as in
2767 objdump -l, so the information should be saved, or it is
2768 rarely called, as in ld error messages, so the memory
2769 wasted is unimportant. Still, it would probably be a
2770 good idea for free_cached_info to throw it away. */
2773 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
2774 &fi->i, filename_ptr, functionname_ptr,
2777 msec->flags = origflags;
2781 msec->flags = origflags;
2784 /* Fall back on the generic ELF find_nearest_line routine. */
2786 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
2787 filename_ptr, functionname_ptr,
2791 /* Structure used to pass information to alpha_elf_output_extsym. */
2796 struct bfd_link_info *info;
2797 struct ecoff_debug_info *debug;
2798 const struct ecoff_debug_swap *swap;
2803 elf64_alpha_output_extsym (h, data)
2804 struct alpha_elf_link_hash_entry *h;
2807 struct extsym_info *einfo = (struct extsym_info *) data;
2809 asection *sec, *output_section;
2811 if (h->root.root.type == bfd_link_hash_warning)
2812 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
2814 if (h->root.indx == -2)
2816 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2817 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
2818 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2819 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
2821 else if (einfo->info->strip == strip_all
2822 || (einfo->info->strip == strip_some
2823 && bfd_hash_lookup (einfo->info->keep_hash,
2824 h->root.root.root.string,
2825 FALSE, FALSE) == NULL))
2833 if (h->esym.ifd == -2)
2836 h->esym.cobol_main = 0;
2837 h->esym.weakext = 0;
2838 h->esym.reserved = 0;
2839 h->esym.ifd = ifdNil;
2840 h->esym.asym.value = 0;
2841 h->esym.asym.st = stGlobal;
2843 if (h->root.root.type != bfd_link_hash_defined
2844 && h->root.root.type != bfd_link_hash_defweak)
2845 h->esym.asym.sc = scAbs;
2850 sec = h->root.root.u.def.section;
2851 output_section = sec->output_section;
2853 /* When making a shared library and symbol h is the one from
2854 the another shared library, OUTPUT_SECTION may be null. */
2855 if (output_section == NULL)
2856 h->esym.asym.sc = scUndefined;
2859 name = bfd_section_name (output_section->owner, output_section);
2861 if (strcmp (name, ".text") == 0)
2862 h->esym.asym.sc = scText;
2863 else if (strcmp (name, ".data") == 0)
2864 h->esym.asym.sc = scData;
2865 else if (strcmp (name, ".sdata") == 0)
2866 h->esym.asym.sc = scSData;
2867 else if (strcmp (name, ".rodata") == 0
2868 || strcmp (name, ".rdata") == 0)
2869 h->esym.asym.sc = scRData;
2870 else if (strcmp (name, ".bss") == 0)
2871 h->esym.asym.sc = scBss;
2872 else if (strcmp (name, ".sbss") == 0)
2873 h->esym.asym.sc = scSBss;
2874 else if (strcmp (name, ".init") == 0)
2875 h->esym.asym.sc = scInit;
2876 else if (strcmp (name, ".fini") == 0)
2877 h->esym.asym.sc = scFini;
2879 h->esym.asym.sc = scAbs;
2883 h->esym.asym.reserved = 0;
2884 h->esym.asym.index = indexNil;
2887 if (h->root.root.type == bfd_link_hash_common)
2888 h->esym.asym.value = h->root.root.u.c.size;
2889 else if (h->root.root.type == bfd_link_hash_defined
2890 || h->root.root.type == bfd_link_hash_defweak)
2892 if (h->esym.asym.sc == scCommon)
2893 h->esym.asym.sc = scBss;
2894 else if (h->esym.asym.sc == scSCommon)
2895 h->esym.asym.sc = scSBss;
2897 sec = h->root.root.u.def.section;
2898 output_section = sec->output_section;
2899 if (output_section != NULL)
2900 h->esym.asym.value = (h->root.root.u.def.value
2901 + sec->output_offset
2902 + output_section->vma);
2904 h->esym.asym.value = 0;
2906 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2908 /* Set type and value for a symbol with a function stub. */
2909 h->esym.asym.st = stProc;
2910 sec = bfd_get_section_by_name (einfo->abfd, ".plt");
2912 h->esym.asym.value = 0;
2915 output_section = sec->output_section;
2916 if (output_section != NULL)
2917 h->esym.asym.value = (h->root.plt.offset
2918 + sec->output_offset
2919 + output_section->vma);
2921 h->esym.asym.value = 0;
2925 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
2926 h->root.root.root.string,
2929 einfo->failed = TRUE;
2936 /* Search for and possibly create a got entry. */
2938 static struct alpha_elf_got_entry *
2939 get_got_entry (abfd, h, r_type, r_symndx, r_addend)
2941 struct alpha_elf_link_hash_entry *h;
2942 unsigned long r_type, r_symndx;
2945 struct alpha_elf_got_entry *gotent;
2946 struct alpha_elf_got_entry **slot;
2949 slot = &h->got_entries;
2952 /* This is a local .got entry -- record for merge. */
2954 struct alpha_elf_got_entry **local_got_entries;
2956 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2957 if (!local_got_entries)
2960 Elf_Internal_Shdr *symtab_hdr;
2962 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2963 size = symtab_hdr->sh_info;
2964 size *= sizeof (struct alpha_elf_got_entry *);
2967 = (struct alpha_elf_got_entry **) bfd_zalloc (abfd, size);
2968 if (!local_got_entries)
2971 alpha_elf_tdata (abfd)->local_got_entries = local_got_entries;
2974 slot = &local_got_entries[r_symndx];
2977 for (gotent = *slot; gotent ; gotent = gotent->next)
2978 if (gotent->gotobj == abfd
2979 && gotent->reloc_type == r_type
2980 && gotent->addend == r_addend)
2988 amt = sizeof (struct alpha_elf_got_entry);
2989 gotent = (struct alpha_elf_got_entry *) bfd_alloc (abfd, amt);
2993 gotent->gotobj = abfd;
2994 gotent->addend = r_addend;
2995 gotent->got_offset = -1;
2996 gotent->use_count = 1;
2997 gotent->reloc_type = r_type;
2998 gotent->reloc_done = 0;
2999 gotent->reloc_xlated = 0;
3001 gotent->next = *slot;
3004 entry_size = alpha_got_entry_size (r_type);
3005 alpha_elf_tdata (abfd)->total_got_size += entry_size;
3007 alpha_elf_tdata(abfd)->local_got_size += entry_size;
3010 gotent->use_count += 1;
3015 /* Handle dynamic relocations when doing an Alpha ELF link. */
3018 elf64_alpha_check_relocs (abfd, info, sec, relocs)
3020 struct bfd_link_info *info;
3022 const Elf_Internal_Rela *relocs;
3026 const char *rel_sec_name;
3027 Elf_Internal_Shdr *symtab_hdr;
3028 struct alpha_elf_link_hash_entry **sym_hashes;
3029 const Elf_Internal_Rela *rel, *relend;
3030 bfd_boolean got_created;
3033 if (info->relocatable)
3036 dynobj = elf_hash_table(info)->dynobj;
3038 elf_hash_table(info)->dynobj = dynobj = abfd;
3041 rel_sec_name = NULL;
3042 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
3043 sym_hashes = alpha_elf_sym_hashes(abfd);
3044 got_created = FALSE;
3046 relend = relocs + sec->reloc_count;
3047 for (rel = relocs; rel < relend; ++rel)
3055 unsigned long r_symndx, r_type;
3056 struct alpha_elf_link_hash_entry *h;
3057 unsigned int gotent_flags;
3058 bfd_boolean maybe_dynamic;
3062 r_symndx = ELF64_R_SYM (rel->r_info);
3063 if (r_symndx < symtab_hdr->sh_info)
3067 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3069 while (h->root.root.type == bfd_link_hash_indirect
3070 || h->root.root.type == bfd_link_hash_warning)
3071 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3073 h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
3076 /* We can only get preliminary data on whether a symbol is
3077 locally or externally defined, as not all of the input files
3078 have yet been processed. Do something with what we know, as
3079 this may help reduce memory usage and processing time later. */
3080 maybe_dynamic = FALSE;
3081 if (h && ((info->shared
3082 && (!info->symbolic || info->unresolved_syms_in_shared_libs == RM_IGNORE))
3083 || ! (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
3084 || h->root.root.type == bfd_link_hash_defweak))
3085 maybe_dynamic = TRUE;
3089 r_type = ELF64_R_TYPE (rel->r_info);
3090 addend = rel->r_addend;
3094 case R_ALPHA_LITERAL:
3095 need = NEED_GOT | NEED_GOT_ENTRY;
3097 /* Remember how this literal is used from its LITUSEs.
3098 This will be important when it comes to decide if we can
3099 create a .plt entry for a function symbol. */
3100 while (++rel < relend && ELF64_R_TYPE (rel->r_info) == R_ALPHA_LITUSE)
3101 if (rel->r_addend >= 1 && rel->r_addend <= 5)
3102 gotent_flags |= 1 << rel->r_addend;
3105 /* No LITUSEs -- presumably the address is used somehow. */
3106 if (gotent_flags == 0)
3107 gotent_flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
3110 case R_ALPHA_GPDISP:
3111 case R_ALPHA_GPREL16:
3112 case R_ALPHA_GPREL32:
3113 case R_ALPHA_GPRELHIGH:
3114 case R_ALPHA_GPRELLOW:
3119 case R_ALPHA_REFLONG:
3120 case R_ALPHA_REFQUAD:
3121 if ((info->shared && (sec->flags & SEC_ALLOC)) || maybe_dynamic)
3125 case R_ALPHA_TLSLDM:
3126 /* The symbol for a TLSLDM reloc is ignored. Collapse the
3127 reloc to the 0 symbol so that they all match. */
3130 maybe_dynamic = FALSE;
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 ah->plt_old_section = h->root.u.def.section;
3336 ah->plt_old_value = h->root.u.def.value;
3337 ah->flags |= ALPHA_ELF_LINK_HASH_PLT_LOC;
3338 h->root.u.def.section = s;
3339 h->root.u.def.value = h->plt.offset;
3342 /* We also need a JMP_SLOT entry in the .rela.plt section. */
3343 s = bfd_get_section_by_name (dynobj, ".rela.plt");
3344 BFD_ASSERT (s != NULL);
3345 s->_raw_size += sizeof (Elf64_External_Rela);
3350 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3352 /* If this is a weak symbol, and there is a real definition, the
3353 processor independent code will have arranged for us to see the
3354 real definition first, and we can just use the same value. */
3355 if (h->weakdef != NULL)
3357 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3358 || h->weakdef->root.type == bfd_link_hash_defweak);
3359 h->root.u.def.section = h->weakdef->root.u.def.section;
3360 h->root.u.def.value = h->weakdef->root.u.def.value;
3364 /* This is a reference to a symbol defined by a dynamic object which
3365 is not a function. The Alpha, since it uses .got entries for all
3366 symbols even in regular objects, does not need the hackery of a
3367 .dynbss section and COPY dynamic relocations. */
3372 /* Symbol versioning can create new symbols, and make our old symbols
3373 indirect to the new ones. Consolidate the got and reloc information
3374 in these situations. */
3377 elf64_alpha_merge_ind_symbols (hi, dummy)
3378 struct alpha_elf_link_hash_entry *hi;
3379 PTR dummy ATTRIBUTE_UNUSED;
3381 struct alpha_elf_link_hash_entry *hs;
3383 if (hi->root.root.type != bfd_link_hash_indirect)
3387 hs = (struct alpha_elf_link_hash_entry *)hs->root.root.u.i.link;
3388 } while (hs->root.root.type == bfd_link_hash_indirect);
3390 /* Merge the flags. Whee. */
3392 hs->flags |= hi->flags;
3394 /* Merge the .got entries. Cannibalize the old symbol's list in
3395 doing so, since we don't need it anymore. */
3397 if (hs->got_entries == NULL)
3398 hs->got_entries = hi->got_entries;
3401 struct alpha_elf_got_entry *gi, *gs, *gin, *gsh;
3403 gsh = hs->got_entries;
3404 for (gi = hi->got_entries; gi ; gi = gin)
3407 for (gs = gsh; gs ; gs = gs->next)
3408 if (gi->gotobj == gs->gotobj
3409 && gi->reloc_type == gs->reloc_type
3410 && gi->addend == gs->addend)
3412 gi->use_count += gs->use_count;
3415 gi->next = hs->got_entries;
3416 hs->got_entries = gi;
3420 hi->got_entries = NULL;
3422 /* And similar for the reloc entries. */
3424 if (hs->reloc_entries == NULL)
3425 hs->reloc_entries = hi->reloc_entries;
3428 struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh;
3430 rsh = hs->reloc_entries;
3431 for (ri = hi->reloc_entries; ri ; ri = rin)
3434 for (rs = rsh; rs ; rs = rs->next)
3435 if (ri->rtype == rs->rtype && ri->srel == rs->srel)
3437 rs->count += ri->count;
3440 ri->next = hs->reloc_entries;
3441 hs->reloc_entries = ri;
3445 hi->reloc_entries = NULL;
3450 /* Is it possible to merge two object file's .got tables? */
3453 elf64_alpha_can_merge_gots (a, b)
3456 int total = alpha_elf_tdata (a)->total_got_size;
3459 /* Trivial quick fallout test. */
3460 if (total + alpha_elf_tdata (b)->total_got_size <= MAX_GOT_SIZE)
3463 /* By their nature, local .got entries cannot be merged. */
3464 if ((total += alpha_elf_tdata (b)->local_got_size) > MAX_GOT_SIZE)
3467 /* Failing the common trivial comparison, we must effectively
3468 perform the merge. Not actually performing the merge means that
3469 we don't have to store undo information in case we fail. */
3470 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
3472 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub);
3473 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
3476 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
3477 for (i = 0; i < n; ++i)
3479 struct alpha_elf_got_entry *ae, *be;
3480 struct alpha_elf_link_hash_entry *h;
3483 while (h->root.root.type == bfd_link_hash_indirect
3484 || h->root.root.type == bfd_link_hash_warning)
3485 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3487 for (be = h->got_entries; be ; be = be->next)
3489 if (be->use_count == 0)
3491 if (be->gotobj != b)
3494 for (ae = h->got_entries; ae ; ae = ae->next)
3496 && ae->reloc_type == be->reloc_type
3497 && ae->addend == be->addend)
3500 total += alpha_got_entry_size (be->reloc_type);
3501 if (total > MAX_GOT_SIZE)
3511 /* Actually merge two .got tables. */
3514 elf64_alpha_merge_gots (a, b)
3517 int total = alpha_elf_tdata (a)->total_got_size;
3520 /* Remember local expansion. */
3522 int e = alpha_elf_tdata (b)->local_got_size;
3524 alpha_elf_tdata (a)->local_got_size += e;
3527 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
3529 struct alpha_elf_got_entry **local_got_entries;
3530 struct alpha_elf_link_hash_entry **hashes;
3531 Elf_Internal_Shdr *symtab_hdr;
3534 /* Let the local .got entries know they are part of a new subsegment. */
3535 local_got_entries = alpha_elf_tdata (bsub)->local_got_entries;
3536 if (local_got_entries)
3538 n = elf_tdata (bsub)->symtab_hdr.sh_info;
3539 for (i = 0; i < n; ++i)
3541 struct alpha_elf_got_entry *ent;
3542 for (ent = local_got_entries[i]; ent; ent = ent->next)
3547 /* Merge the global .got entries. */
3548 hashes = alpha_elf_sym_hashes (bsub);
3549 symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
3551 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
3552 for (i = 0; i < n; ++i)
3554 struct alpha_elf_got_entry *ae, *be, **pbe, **start;
3555 struct alpha_elf_link_hash_entry *h;
3558 while (h->root.root.type == bfd_link_hash_indirect
3559 || h->root.root.type == bfd_link_hash_warning)
3560 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3562 start = &h->got_entries;
3563 for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
3565 if (be->use_count == 0)
3570 if (be->gotobj != b)
3573 for (ae = *start; ae ; ae = ae->next)
3575 && ae->reloc_type == be->reloc_type
3576 && ae->addend == be->addend)
3578 ae->flags |= be->flags;
3579 ae->use_count += be->use_count;
3584 total += alpha_got_entry_size (be->reloc_type);
3590 alpha_elf_tdata (bsub)->gotobj = a;
3592 alpha_elf_tdata (a)->total_got_size = total;
3594 /* Merge the two in_got chains. */
3599 while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL)
3602 alpha_elf_tdata (bsub)->in_got_link_next = b;
3606 /* Calculate the offsets for the got entries. */
3609 elf64_alpha_calc_got_offsets_for_symbol (h, arg)
3610 struct alpha_elf_link_hash_entry *h;
3611 PTR arg ATTRIBUTE_UNUSED;
3613 struct alpha_elf_got_entry *gotent;
3615 if (h->root.root.type == bfd_link_hash_warning)
3616 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
3618 for (gotent = h->got_entries; gotent; gotent = gotent->next)
3619 if (gotent->use_count > 0)
3622 = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
3624 gotent->got_offset = *plge;
3625 *plge += alpha_got_entry_size (gotent->reloc_type);
3632 elf64_alpha_calc_got_offsets (info)
3633 struct bfd_link_info *info;
3635 bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
3637 /* First, zero out the .got sizes, as we may be recalculating the
3638 .got after optimizing it. */
3639 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
3640 alpha_elf_tdata(i)->got->_raw_size = 0;
3642 /* Next, fill in the offsets for all the global entries. */
3643 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3644 elf64_alpha_calc_got_offsets_for_symbol,
3647 /* Finally, fill in the offsets for the local entries. */
3648 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
3650 bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
3653 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
3655 struct alpha_elf_got_entry **local_got_entries, *gotent;
3658 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
3659 if (!local_got_entries)
3662 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
3663 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
3664 if (gotent->use_count > 0)
3666 gotent->got_offset = got_offset;
3667 got_offset += alpha_got_entry_size (gotent->reloc_type);
3671 alpha_elf_tdata(i)->got->_raw_size = got_offset;
3672 alpha_elf_tdata(i)->got->_cooked_size = got_offset;
3676 /* Constructs the gots. */
3679 elf64_alpha_size_got_sections (info)
3680 struct bfd_link_info *info;
3682 bfd *i, *got_list, *cur_got_obj = NULL;
3683 int something_changed = 0;
3685 got_list = alpha_elf_hash_table (info)->got_list;
3687 /* On the first time through, pretend we have an existing got list
3688 consisting of all of the input files. */
3689 if (got_list == NULL)
3691 for (i = info->input_bfds; i ; i = i->link_next)
3693 bfd *this_got = alpha_elf_tdata (i)->gotobj;
3694 if (this_got == NULL)
3697 /* We are assuming no merging has yet ocurred. */
3698 BFD_ASSERT (this_got == i);
3700 if (alpha_elf_tdata (this_got)->total_got_size > MAX_GOT_SIZE)
3702 /* Yikes! A single object file has too many entries. */
3703 (*_bfd_error_handler)
3704 (_("%s: .got subsegment exceeds 64K (size %d)"),
3705 bfd_archive_filename (i),
3706 alpha_elf_tdata (this_got)->total_got_size);
3710 if (got_list == NULL)
3711 got_list = this_got;
3713 alpha_elf_tdata(cur_got_obj)->got_link_next = this_got;
3714 cur_got_obj = this_got;
3717 /* Strange degenerate case of no got references. */
3718 if (got_list == NULL)
3721 alpha_elf_hash_table (info)->got_list = got_list;
3723 /* Force got offsets to be recalculated. */
3724 something_changed = 1;
3727 cur_got_obj = got_list;
3728 i = alpha_elf_tdata(cur_got_obj)->got_link_next;
3731 if (elf64_alpha_can_merge_gots (cur_got_obj, i))
3733 elf64_alpha_merge_gots (cur_got_obj, i);
3734 i = alpha_elf_tdata(i)->got_link_next;
3735 alpha_elf_tdata(cur_got_obj)->got_link_next = i;
3736 something_changed = 1;
3741 i = alpha_elf_tdata(i)->got_link_next;
3745 /* Once the gots have been merged, fill in the got offsets for
3746 everything therein. */
3747 if (1 || something_changed)
3748 elf64_alpha_calc_got_offsets (info);
3753 /* Called from relax_section to rebuild the PLT in light of
3754 potential changes in the function's status. */
3757 elf64_alpha_size_plt_section (info)
3758 struct bfd_link_info *info;
3760 asection *splt, *spltrel;
3761 unsigned long entries;
3764 dynobj = elf_hash_table(info)->dynobj;
3765 splt = bfd_get_section_by_name(dynobj, ".plt");
3769 splt->_raw_size = 0;
3771 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3772 elf64_alpha_size_plt_section_1, splt);
3774 splt->_cooked_size = splt->_raw_size;
3776 /* Every plt entry requires a JMP_SLOT relocation. */
3777 spltrel = bfd_get_section_by_name (dynobj, ".rela.plt");
3778 if (splt->_raw_size)
3779 entries = (splt->_raw_size - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
3782 spltrel->_raw_size = entries * sizeof (Elf64_External_Rela);
3783 spltrel->_cooked_size = spltrel->_raw_size;
3789 elf64_alpha_size_plt_section_1 (h, data)
3790 struct alpha_elf_link_hash_entry *h;
3793 asection *splt = (asection *) data;
3794 struct alpha_elf_got_entry *gotent;
3796 /* If we didn't need an entry before, we still don't. */
3797 if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT))
3800 /* There must still be a LITERAL got entry for the function. */
3801 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
3802 if (gotent->reloc_type == R_ALPHA_LITERAL
3803 && gotent->use_count > 0)
3806 /* If there is, reset the PLT offset. If not, there's no longer
3807 a need for the PLT entry. */
3810 if (splt->_raw_size == 0)
3811 splt->_raw_size = PLT_HEADER_SIZE;
3812 h->root.plt.offset = splt->_raw_size;
3813 splt->_raw_size += PLT_ENTRY_SIZE;
3817 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3818 h->root.plt.offset = -1;
3820 /* Undo the definition frobbing begun in adjust_dynamic_symbol. */
3821 if (h->flags & ALPHA_ELF_LINK_HASH_PLT_LOC)
3823 h->root.root.u.def.section = h->plt_old_section;
3824 h->root.root.u.def.value = h->plt_old_value;
3825 h->flags &= ~ALPHA_ELF_LINK_HASH_PLT_LOC;
3833 elf64_alpha_always_size_sections (output_bfd, info)
3834 bfd *output_bfd ATTRIBUTE_UNUSED;
3835 struct bfd_link_info *info;
3839 if (info->relocatable)
3842 /* First, take care of the indirect symbols created by versioning. */
3843 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3844 elf64_alpha_merge_ind_symbols,
3847 if (!elf64_alpha_size_got_sections (info))
3850 /* Allocate space for all of the .got subsections. */
3851 i = alpha_elf_hash_table (info)->got_list;
3852 for ( ; i ; i = alpha_elf_tdata(i)->got_link_next)
3854 asection *s = alpha_elf_tdata(i)->got;
3855 if (s->_raw_size > 0)
3857 s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
3858 if (s->contents == NULL)
3866 /* The number of dynamic relocations required by a static relocation. */
3869 alpha_dynamic_entries_for_reloc (r_type, dynamic, shared)
3870 int r_type, dynamic, shared;
3874 /* May appear in GOT entries. */
3876 return (dynamic ? 2 : shared ? 1 : 0);
3877 case R_ALPHA_TLSLDM:
3879 case R_ALPHA_LITERAL:
3880 case R_ALPHA_GOTTPREL:
3881 return dynamic || shared;
3882 case R_ALPHA_GOTDTPREL:
3885 /* May appear in data sections. */
3886 case R_ALPHA_REFLONG:
3887 case R_ALPHA_REFQUAD:
3888 case R_ALPHA_TPREL64:
3889 return dynamic || shared;
3891 /* Everything else is illegal. We'll issue an error during
3892 relocate_section. */
3898 /* Work out the sizes of the dynamic relocation entries. */
3901 elf64_alpha_calc_dynrel_sizes (h, info)
3902 struct alpha_elf_link_hash_entry *h;
3903 struct bfd_link_info *info;
3905 bfd_boolean dynamic;
3906 struct alpha_elf_reloc_entry *relent;
3907 unsigned long entries;
3909 if (h->root.root.type == bfd_link_hash_warning)
3910 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
3912 /* If the symbol was defined as a common symbol in a regular object
3913 file, and there was no definition in any dynamic object, then the
3914 linker will have allocated space for the symbol in a common
3915 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3916 set. This is done for dynamic symbols in
3917 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3918 symbols, somehow. */
3919 if (((h->root.elf_link_hash_flags
3920 & (ELF_LINK_HASH_DEF_REGULAR
3921 | ELF_LINK_HASH_REF_REGULAR
3922 | ELF_LINK_HASH_DEF_DYNAMIC))
3923 == ELF_LINK_HASH_REF_REGULAR)
3924 && (h->root.root.type == bfd_link_hash_defined
3925 || h->root.root.type == bfd_link_hash_defweak)
3926 && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
3927 h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3929 /* If the symbol is dynamic, we'll need all the relocations in their
3930 natural form. If this is a shared object, and it has been forced
3931 local, we'll need the same number of RELATIVE relocations. */
3933 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info);
3935 for (relent = h->reloc_entries; relent; relent = relent->next)
3937 entries = alpha_dynamic_entries_for_reloc (relent->rtype, dynamic,
3941 relent->srel->_raw_size +=
3942 entries * sizeof (Elf64_External_Rela) * relent->count;
3943 if (relent->reltext)
3944 info->flags |= DT_TEXTREL;
3951 /* Set the sizes of the dynamic relocation sections. */
3954 elf64_alpha_size_rela_got_section (info)
3955 struct bfd_link_info *info;
3957 unsigned long entries;
3961 /* Shared libraries often require RELATIVE relocs, and some relocs
3962 require attention for the main application as well. */
3965 for (i = alpha_elf_hash_table(info)->got_list;
3966 i ; i = alpha_elf_tdata(i)->got_link_next)
3970 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
3972 struct alpha_elf_got_entry **local_got_entries, *gotent;
3975 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
3976 if (!local_got_entries)
3979 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
3980 for (gotent = local_got_entries[k];
3981 gotent ; gotent = gotent->next)
3982 if (gotent->use_count > 0)
3983 entries += (alpha_dynamic_entries_for_reloc
3984 (gotent->reloc_type, 0, info->shared));
3988 dynobj = elf_hash_table(info)->dynobj;
3989 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3992 BFD_ASSERT (entries == 0);
3995 srel->_raw_size = sizeof (Elf64_External_Rela) * entries;
3997 /* Now do the non-local symbols. */
3998 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3999 elf64_alpha_size_rela_got_1, info);
4001 srel->_cooked_size = srel->_raw_size;
4006 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
4010 elf64_alpha_size_rela_got_1 (h, info)
4011 struct alpha_elf_link_hash_entry *h;
4012 struct bfd_link_info *info;
4014 bfd_boolean dynamic;
4015 struct alpha_elf_got_entry *gotent;
4016 unsigned long entries;
4018 if (h->root.root.type == bfd_link_hash_warning)
4019 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
4021 /* If the symbol is dynamic, we'll need all the relocations in their
4022 natural form. If this is a shared object, and it has been forced
4023 local, we'll need the same number of RELATIVE relocations. */
4025 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info);
4028 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
4029 if (gotent->use_count > 0)
4030 entries += alpha_dynamic_entries_for_reloc (gotent->reloc_type,
4031 dynamic, info->shared);
4033 /* If we are using a .plt entry, subtract one, as the first
4034 reference uses a .rela.plt entry instead. */
4035 if (h->root.plt.offset != MINUS_ONE)
4040 bfd *dynobj = elf_hash_table(info)->dynobj;
4041 asection *srel = bfd_get_section_by_name (dynobj, ".rela.got");
4042 BFD_ASSERT (srel != NULL);
4043 srel->_raw_size += sizeof (Elf64_External_Rela) * entries;
4049 /* Set the sizes of the dynamic sections. */
4052 elf64_alpha_size_dynamic_sections (output_bfd, info)
4053 bfd *output_bfd ATTRIBUTE_UNUSED;
4054 struct bfd_link_info *info;
4060 dynobj = elf_hash_table(info)->dynobj;
4061 BFD_ASSERT(dynobj != NULL);
4063 if (elf_hash_table (info)->dynamic_sections_created)
4065 /* Set the contents of the .interp section to the interpreter. */
4066 if (info->executable)
4068 s = bfd_get_section_by_name (dynobj, ".interp");
4069 BFD_ASSERT (s != NULL);
4070 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4071 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4074 /* Now that we've seen all of the input files, we can decide which
4075 symbols need dynamic relocation entries and which don't. We've
4076 collected information in check_relocs that we can now apply to
4077 size the dynamic relocation sections. */
4078 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
4079 elf64_alpha_calc_dynrel_sizes, info);
4081 elf64_alpha_size_rela_got_section (info);
4083 /* else we're not dynamic and by definition we don't need such things. */
4085 /* The check_relocs and adjust_dynamic_symbol entry points have
4086 determined the sizes of the various dynamic sections. Allocate
4089 for (s = dynobj->sections; s != NULL; s = s->next)
4094 if (!(s->flags & SEC_LINKER_CREATED))
4097 /* It's OK to base decisions on the section name, because none
4098 of the dynobj section names depend upon the input files. */
4099 name = bfd_get_section_name (dynobj, s);
4101 /* If we don't need this section, strip it from the output file.
4102 This is to handle .rela.bss and .rela.plt. We must create it
4103 in create_dynamic_sections, because it must be created before
4104 the linker maps input sections to output sections. The
4105 linker does that before adjust_dynamic_symbol is called, and
4106 it is that function which decides whether anything needs to
4107 go into these sections. */
4111 if (strncmp (name, ".rela", 5) == 0)
4113 strip = (s->_raw_size == 0);
4117 if (strcmp(name, ".rela.plt") == 0)
4120 /* We use the reloc_count field as a counter if we need
4121 to copy relocs into the output file. */
4125 else if (strcmp (name, ".plt") != 0)
4127 /* It's not one of our dynamic sections, so don't allocate space. */
4132 _bfd_strip_section_from_output (info, s);
4135 /* Allocate memory for the section contents. */
4136 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4137 if (s->contents == NULL && s->_raw_size != 0)
4142 if (elf_hash_table (info)->dynamic_sections_created)
4144 /* Add some entries to the .dynamic section. We fill in the
4145 values later, in elf64_alpha_finish_dynamic_sections, but we
4146 must add the entries now so that we get the correct size for
4147 the .dynamic section. The DT_DEBUG entry is filled in by the
4148 dynamic linker and used by the debugger. */
4149 #define add_dynamic_entry(TAG, VAL) \
4150 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4152 if (info->executable)
4154 if (!add_dynamic_entry (DT_DEBUG, 0))
4160 if (!add_dynamic_entry (DT_PLTGOT, 0)
4161 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4162 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4163 || !add_dynamic_entry (DT_JMPREL, 0))
4167 if (!add_dynamic_entry (DT_RELA, 0)
4168 || !add_dynamic_entry (DT_RELASZ, 0)
4169 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
4172 if (info->flags & DF_TEXTREL)
4174 if (!add_dynamic_entry (DT_TEXTREL, 0))
4178 #undef add_dynamic_entry
4183 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
4184 into the next available slot in SREL. */
4187 elf64_alpha_emit_dynrel (abfd, info, sec, srel, offset, dynindx, rtype, addend)
4189 struct bfd_link_info *info;
4190 asection *sec, *srel;
4191 bfd_vma offset, addend;
4192 long dynindx, rtype;
4194 Elf_Internal_Rela outrel;
4197 BFD_ASSERT (srel != NULL);
4199 outrel.r_info = ELF64_R_INFO (dynindx, rtype);
4200 outrel.r_addend = addend;
4202 offset = _bfd_elf_section_offset (abfd, info, sec, offset);
4203 if ((offset | 1) != (bfd_vma) -1)
4204 outrel.r_offset = sec->output_section->vma + sec->output_offset + offset;
4206 memset (&outrel, 0, sizeof (outrel));
4208 loc = srel->contents;
4209 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
4210 bfd_elf64_swap_reloca_out (abfd, &outrel, loc);
4211 BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
4212 <= srel->_cooked_size);
4215 /* Relocate an Alpha ELF section for a relocatable link.
4217 We don't have to change anything unless the reloc is against a section
4218 symbol, in which case we have to adjust according to where the section
4219 symbol winds up in the output section. */
4222 elf64_alpha_relocate_section_r (output_bfd, info, input_bfd, input_section,
4223 contents, relocs, local_syms, local_sections)
4224 bfd *output_bfd ATTRIBUTE_UNUSED;
4225 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4227 asection *input_section;
4228 bfd_byte *contents ATTRIBUTE_UNUSED;
4229 Elf_Internal_Rela *relocs;
4230 Elf_Internal_Sym *local_syms;
4231 asection **local_sections;
4233 unsigned long symtab_hdr_sh_info;
4234 Elf_Internal_Rela *rel;
4235 Elf_Internal_Rela *relend;
4236 bfd_boolean ret_val = TRUE;
4238 symtab_hdr_sh_info = elf_tdata (input_bfd)->symtab_hdr.sh_info;
4240 relend = relocs + input_section->reloc_count;
4241 for (rel = relocs; rel < relend; rel++)
4243 unsigned long r_symndx;
4244 Elf_Internal_Sym *sym;
4246 unsigned long r_type;
4248 r_type = ELF64_R_TYPE(rel->r_info);
4249 if (r_type >= R_ALPHA_max)
4251 (*_bfd_error_handler)
4252 (_("%s: unknown relocation type %d"),
4253 bfd_archive_filename (input_bfd), (int)r_type);
4254 bfd_set_error (bfd_error_bad_value);
4259 r_symndx = ELF64_R_SYM(rel->r_info);
4261 /* The symbol associated with GPDISP and LITUSE is
4262 immaterial. Only the addend is significant. */
4263 if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE)
4266 if (r_symndx < symtab_hdr_sh_info)
4268 sym = local_syms + r_symndx;
4269 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
4271 sec = local_sections[r_symndx];
4272 rel->r_addend += sec->output_offset + sym->st_value;
4280 /* Relocate an Alpha ELF section. */
4283 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
4284 contents, relocs, local_syms, local_sections)
4286 struct bfd_link_info *info;
4288 asection *input_section;
4290 Elf_Internal_Rela *relocs;
4291 Elf_Internal_Sym *local_syms;
4292 asection **local_sections;
4294 Elf_Internal_Shdr *symtab_hdr;
4295 Elf_Internal_Rela *rel;
4296 Elf_Internal_Rela *relend;
4297 struct elf_link_tls_segment *tls_segment;
4298 asection *sgot, *srel, *srelgot;
4299 bfd *dynobj, *gotobj;
4300 bfd_vma gp, tp_base, dtp_base;
4301 struct alpha_elf_got_entry **local_got_entries;
4302 bfd_boolean ret_val;
4303 const char *section_name;
4305 /* Handle relocatable links with a smaller loop. */
4306 if (info->relocatable)
4307 return elf64_alpha_relocate_section_r (output_bfd, info, input_bfd,
4308 input_section, contents, relocs,
4309 local_syms, local_sections);
4311 /* This is a final link. */
4315 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4317 dynobj = elf_hash_table (info)->dynobj;
4319 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
4323 section_name = (bfd_elf_string_from_elf_section
4324 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
4325 elf_section_data(input_section)->rel_hdr.sh_name));
4326 BFD_ASSERT(section_name != NULL);
4327 srel = bfd_get_section_by_name (dynobj, section_name);
4329 /* Find the gp value for this input bfd. */
4330 gotobj = alpha_elf_tdata (input_bfd)->gotobj;
4333 sgot = alpha_elf_tdata (gotobj)->got;
4334 gp = _bfd_get_gp_value (gotobj);
4337 gp = (sgot->output_section->vma
4338 + sgot->output_offset
4340 _bfd_set_gp_value (gotobj, gp);
4349 local_got_entries = alpha_elf_tdata(input_bfd)->local_got_entries;
4351 tls_segment = elf_hash_table (info)->tls_segment;
4354 dtp_base = alpha_get_dtprel_base (tls_segment);
4355 tp_base = alpha_get_tprel_base (tls_segment);
4358 dtp_base = tp_base = 0;
4360 relend = relocs + input_section->reloc_count;
4361 for (rel = relocs; rel < relend; rel++)
4363 struct alpha_elf_link_hash_entry *h = NULL;
4364 struct alpha_elf_got_entry *gotent;
4365 bfd_reloc_status_type r;
4366 reloc_howto_type *howto;
4367 unsigned long r_symndx;
4368 Elf_Internal_Sym *sym = NULL;
4369 asection *sec = NULL;
4372 bfd_boolean dynamic_symbol_p;
4373 bfd_boolean undef_weak_ref = FALSE;
4374 unsigned long r_type;
4376 r_type = ELF64_R_TYPE(rel->r_info);
4377 if (r_type >= R_ALPHA_max)
4379 (*_bfd_error_handler)
4380 (_("%s: unknown relocation type %d"),
4381 bfd_archive_filename (input_bfd), (int)r_type);
4382 bfd_set_error (bfd_error_bad_value);
4387 howto = elf64_alpha_howto_table + r_type;
4388 r_symndx = ELF64_R_SYM(rel->r_info);
4390 /* The symbol for a TLSLDM reloc is ignored. Collapse the
4391 reloc to the 0 symbol so that they all match. */
4392 if (r_type == R_ALPHA_TLSLDM)
4395 if (r_symndx < symtab_hdr->sh_info)
4397 sym = local_syms + r_symndx;
4398 sec = local_sections[r_symndx];
4399 value = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4401 /* If this is a tp-relative relocation against sym 0,
4402 this is hackery from relax_section. Force the value to
4405 && (r_type == R_ALPHA_TLSLDM
4406 || r_type == R_ALPHA_GOTTPREL
4407 || r_type == R_ALPHA_TPREL64
4408 || r_type == R_ALPHA_TPRELHI
4409 || r_type == R_ALPHA_TPRELLO
4410 || r_type == R_ALPHA_TPREL16))
4413 if (local_got_entries)
4414 gotent = local_got_entries[r_symndx];
4418 /* Need to adjust local GOT entries' addends for SEC_MERGE
4419 unless it has been done already. */
4420 if ((sec->flags & SEC_MERGE)
4421 && ELF_ST_TYPE (sym->st_info) == STT_SECTION
4422 && sec->sec_info_type == ELF_INFO_TYPE_MERGE
4424 && !gotent->reloc_xlated)
4426 struct alpha_elf_got_entry *ent;
4429 for (ent = gotent; ent; ent = ent->next)
4431 ent->reloc_xlated = 1;
4432 if (ent->use_count == 0)
4436 _bfd_merged_section_offset (output_bfd, &msec,
4437 elf_section_data (sec)->
4439 sym->st_value + ent->addend,
4441 ent->addend -= sym->st_value;
4442 ent->addend += msec->output_section->vma
4443 + msec->output_offset
4444 - sec->output_section->vma
4445 - sec->output_offset;
4449 dynamic_symbol_p = FALSE;
4454 bfd_boolean unresolved_reloc;
4455 struct elf_link_hash_entry *hh;
4457 RELOC_FOR_GLOBAL_SYMBOL (hh,
4458 (struct elf_link_hash_entry *) alpha_elf_sym_hashes (input_bfd),
4459 r_symndx, symtab_hdr, value,
4460 sec, unresolved_reloc, info,
4467 && ! unresolved_reloc
4468 && hh->root.type == bfd_link_hash_undefweak)
4469 undef_weak_ref = TRUE;
4471 h = (struct alpha_elf_link_hash_entry *) hh;
4472 dynamic_symbol_p = alpha_elf_dynamic_symbol_p (&h->root, info);
4473 gotent = h->got_entries;
4476 addend = rel->r_addend;
4479 /* Search for the proper got entry. */
4480 for (; gotent ; gotent = gotent->next)
4481 if (gotent->gotobj == gotobj
4482 && gotent->reloc_type == r_type
4483 && gotent->addend == addend)
4488 case R_ALPHA_GPDISP:
4490 bfd_byte *p_ldah, *p_lda;
4492 BFD_ASSERT(gp != 0);
4494 value = (input_section->output_section->vma
4495 + input_section->output_offset
4498 p_ldah = contents + rel->r_offset;
4499 p_lda = p_ldah + rel->r_addend;
4501 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - value,
4506 case R_ALPHA_LITERAL:
4507 BFD_ASSERT(sgot != NULL);
4508 BFD_ASSERT(gp != 0);
4509 BFD_ASSERT(gotent != NULL);
4510 BFD_ASSERT(gotent->use_count >= 1);
4512 if (!gotent->reloc_done)
4514 gotent->reloc_done = 1;
4516 bfd_put_64 (output_bfd, value,
4517 sgot->contents + gotent->got_offset);
4519 /* If the symbol has been forced local, output a
4520 RELATIVE reloc, otherwise it will be handled in
4521 finish_dynamic_symbol. */
4522 if (info->shared && !dynamic_symbol_p)
4523 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot,
4524 gotent->got_offset, 0,
4525 R_ALPHA_RELATIVE, value);
4528 value = (sgot->output_section->vma
4529 + sgot->output_offset
4530 + gotent->got_offset);
4534 case R_ALPHA_GPREL32:
4535 /* If the target section was a removed linkonce section,
4536 r_symndx will be zero. In this case, assume that the
4537 switch will not be used, so don't fill it in. If we
4538 do nothing here, we'll get relocation truncated messages,
4539 due to the placement of the application above 4GB. */
4547 case R_ALPHA_GPREL16:
4548 case R_ALPHA_GPRELLOW:
4549 if (dynamic_symbol_p)
4551 (*_bfd_error_handler)
4552 (_("%s: gp-relative relocation against dynamic symbol %s"),
4553 bfd_archive_filename (input_bfd), h->root.root.root.string);
4556 BFD_ASSERT(gp != 0);
4560 case R_ALPHA_GPRELHIGH:
4561 if (dynamic_symbol_p)
4563 (*_bfd_error_handler)
4564 (_("%s: gp-relative relocation against dynamic symbol %s"),
4565 bfd_archive_filename (input_bfd), h->root.root.root.string);
4568 BFD_ASSERT(gp != 0);
4570 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4574 /* A call to a dynamic symbol is definitely out of range of
4575 the 16-bit displacement. Don't bother writing anything. */
4576 if (dynamic_symbol_p)
4581 /* The regular PC-relative stuff measures from the start of
4582 the instruction rather than the end. */
4586 case R_ALPHA_BRADDR:
4587 if (dynamic_symbol_p)
4589 (*_bfd_error_handler)
4590 (_("%s: pc-relative relocation against dynamic symbol %s"),
4591 bfd_archive_filename (input_bfd), h->root.root.root.string);
4594 /* The regular PC-relative stuff measures from the start of
4595 the instruction rather than the end. */
4604 /* The regular PC-relative stuff measures from the start of
4605 the instruction rather than the end. */
4608 /* The source and destination gp must be the same. Note that
4609 the source will always have an assigned gp, since we forced
4610 one in check_relocs, but that the destination may not, as
4611 it might not have had any relocations at all. Also take
4612 care not to crash if H is an undefined symbol. */
4613 if (h != NULL && sec != NULL
4614 && alpha_elf_tdata (sec->owner)->gotobj
4615 && gotobj != alpha_elf_tdata (sec->owner)->gotobj)
4617 (*_bfd_error_handler)
4618 (_("%s: change in gp: BRSGP %s"),
4619 bfd_archive_filename (input_bfd), h->root.root.root.string);
4623 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4625 other = h->root.other;
4627 other = sym->st_other;
4628 switch (other & STO_ALPHA_STD_GPLOAD)
4630 case STO_ALPHA_NOPV:
4632 case STO_ALPHA_STD_GPLOAD:
4637 name = h->root.root.root.string;
4640 name = (bfd_elf_string_from_elf_section
4641 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4643 name = _("<unknown>");
4644 else if (name[0] == 0)
4645 name = bfd_section_name (input_bfd, sec);
4647 (*_bfd_error_handler)
4648 (_("%s: !samegp reloc against symbol without .prologue: %s"),
4649 bfd_archive_filename (input_bfd), name);
4657 case R_ALPHA_REFLONG:
4658 case R_ALPHA_REFQUAD:
4659 case R_ALPHA_DTPREL64:
4660 case R_ALPHA_TPREL64:
4662 long dynindx, dyntype = r_type;
4665 /* Careful here to remember RELATIVE relocations for global
4666 variables for symbolic shared objects. */
4668 if (dynamic_symbol_p)
4670 BFD_ASSERT(h->root.dynindx != -1);
4671 dynindx = h->root.dynindx;
4673 addend = 0, value = 0;
4675 else if (r_type == R_ALPHA_DTPREL64)
4677 BFD_ASSERT(tls_segment != NULL);
4681 else if (r_type == R_ALPHA_TPREL64)
4683 BFD_ASSERT(tls_segment != NULL);
4690 dynaddend = value - dtp_base;
4692 else if (info->shared
4694 && (input_section->flags & SEC_ALLOC))
4696 if (r_type == R_ALPHA_REFLONG)
4698 (*_bfd_error_handler)
4699 (_("%s: unhandled dynamic relocation against %s"),
4700 bfd_archive_filename (input_bfd),
4701 h->root.root.root.string);
4705 dyntype = R_ALPHA_RELATIVE;
4711 elf64_alpha_emit_dynrel (output_bfd, info, input_section,
4712 srel, rel->r_offset, dynindx,
4713 dyntype, dynaddend);
4717 case R_ALPHA_SREL16:
4718 case R_ALPHA_SREL32:
4719 case R_ALPHA_SREL64:
4720 if (dynamic_symbol_p)
4722 (*_bfd_error_handler)
4723 (_("%s: pc-relative relocation against dynamic symbol %s"),
4724 bfd_archive_filename (input_bfd), h->root.root.root.string);
4728 /* ??? .eh_frame references to discarded sections will be smashed
4729 to relocations against SHN_UNDEF. The .eh_frame format allows
4730 NULL to be encoded as 0 in any format, so this works here. */
4732 howto = (elf64_alpha_howto_table
4733 + (r_type - R_ALPHA_SREL32 + R_ALPHA_REFLONG));
4736 case R_ALPHA_TLSLDM:
4737 /* Ignore the symbol for the relocation. The result is always
4738 the current module. */
4739 dynamic_symbol_p = 0;
4743 if (!gotent->reloc_done)
4745 gotent->reloc_done = 1;
4747 /* Note that the module index for the main program is 1. */
4748 bfd_put_64 (output_bfd, !info->shared && !dynamic_symbol_p,
4749 sgot->contents + gotent->got_offset);
4751 /* If the symbol has been forced local, output a
4752 DTPMOD64 reloc, otherwise it will be handled in
4753 finish_dynamic_symbol. */
4754 if (info->shared && !dynamic_symbol_p)
4755 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot,
4756 gotent->got_offset, 0,
4757 R_ALPHA_DTPMOD64, 0);
4759 if (dynamic_symbol_p || r_type == R_ALPHA_TLSLDM)
4763 BFD_ASSERT(tls_segment != NULL);
4766 bfd_put_64 (output_bfd, value,
4767 sgot->contents + gotent->got_offset + 8);
4770 value = (sgot->output_section->vma
4771 + sgot->output_offset
4772 + gotent->got_offset);
4776 case R_ALPHA_DTPRELHI:
4777 case R_ALPHA_DTPRELLO:
4778 case R_ALPHA_DTPREL16:
4779 if (dynamic_symbol_p)
4781 (*_bfd_error_handler)
4782 (_("%s: dtp-relative relocation against dynamic symbol %s"),
4783 bfd_archive_filename (input_bfd), h->root.root.root.string);
4786 BFD_ASSERT(tls_segment != NULL);
4788 if (r_type == R_ALPHA_DTPRELHI)
4789 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4792 case R_ALPHA_TPRELHI:
4793 case R_ALPHA_TPRELLO:
4794 case R_ALPHA_TPREL16:
4797 (*_bfd_error_handler)
4798 (_("%s: TLS local exec code cannot be linked into shared objects"),
4799 bfd_archive_filename (input_bfd));
4802 else if (dynamic_symbol_p)
4804 (*_bfd_error_handler)
4805 (_("%s: tp-relative relocation against dynamic symbol %s"),
4806 bfd_archive_filename (input_bfd), h->root.root.root.string);
4809 BFD_ASSERT(tls_segment != NULL);
4811 if (r_type == R_ALPHA_TPRELHI)
4812 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4815 case R_ALPHA_GOTDTPREL:
4816 case R_ALPHA_GOTTPREL:
4817 BFD_ASSERT(sgot != NULL);
4818 BFD_ASSERT(gp != 0);
4819 BFD_ASSERT(gotent != NULL);
4820 BFD_ASSERT(gotent->use_count >= 1);
4822 if (!gotent->reloc_done)
4824 gotent->reloc_done = 1;
4826 if (dynamic_symbol_p)
4830 BFD_ASSERT(tls_segment != NULL);
4831 if (r_type == R_ALPHA_GOTDTPREL)
4833 else if (!info->shared)
4837 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot,
4838 gotent->got_offset, 0,
4844 bfd_put_64 (output_bfd, value,
4845 sgot->contents + gotent->got_offset);
4848 value = (sgot->output_section->vma
4849 + sgot->output_offset
4850 + gotent->got_offset);
4856 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4857 contents, rel->r_offset, value, 0);
4866 case bfd_reloc_overflow:
4870 /* Don't warn if the overflow is due to pc relative reloc
4871 against discarded section. Section optimization code should
4874 if (r_symndx < symtab_hdr->sh_info
4875 && sec != NULL && howto->pc_relative
4876 && elf_discarded_section (sec))
4880 name = h->root.root.root.string;
4883 name = (bfd_elf_string_from_elf_section
4884 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4888 name = bfd_section_name (input_bfd, sec);
4890 if (! ((*info->callbacks->reloc_overflow)
4891 (info, name, howto->name, (bfd_vma) 0,
4892 input_bfd, input_section, rel->r_offset)))
4898 case bfd_reloc_outofrange:
4906 /* Finish up dynamic symbol handling. We set the contents of various
4907 dynamic sections here. */
4910 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
4912 struct bfd_link_info *info;
4913 struct elf_link_hash_entry *h;
4914 Elf_Internal_Sym *sym;
4916 bfd *dynobj = elf_hash_table(info)->dynobj;
4918 if (h->plt.offset != MINUS_ONE)
4920 /* Fill in the .plt entry for this symbol. */
4921 asection *splt, *sgot, *srel;
4922 Elf_Internal_Rela outrel;
4924 bfd_vma got_addr, plt_addr;
4926 struct alpha_elf_got_entry *gotent;
4928 BFD_ASSERT (h->dynindx != -1);
4930 /* The first .got entry will be updated by the .plt with the
4931 address of the target function. */
4932 gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
4933 BFD_ASSERT (gotent && gotent->addend == 0);
4935 splt = bfd_get_section_by_name (dynobj, ".plt");
4936 BFD_ASSERT (splt != NULL);
4937 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4938 BFD_ASSERT (srel != NULL);
4939 sgot = alpha_elf_tdata (gotent->gotobj)->got;
4940 BFD_ASSERT (sgot != NULL);
4942 got_addr = (sgot->output_section->vma
4943 + sgot->output_offset
4944 + gotent->got_offset);
4945 plt_addr = (splt->output_section->vma
4946 + splt->output_offset
4949 plt_index = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
4951 /* Fill in the entry in the procedure linkage table. */
4953 bfd_vma insn1, insn2, insn3;
4955 insn1 = PLT_ENTRY_WORD1 | ((-(h->plt.offset + 4) >> 2) & 0x1fffff);
4956 insn2 = PLT_ENTRY_WORD2;
4957 insn3 = PLT_ENTRY_WORD3;
4959 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt.offset);
4960 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt.offset + 4);
4961 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt.offset + 8);
4964 /* Fill in the entry in the .rela.plt section. */
4965 outrel.r_offset = got_addr;
4966 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
4967 outrel.r_addend = 0;
4969 loc = srel->contents + plt_index * sizeof (Elf64_External_Rela);
4970 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
4972 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
4974 /* Mark the symbol as undefined, rather than as defined in the
4975 .plt section. Leave the value alone. */
4976 sym->st_shndx = SHN_UNDEF;
4979 /* Fill in the entries in the .got. */
4980 bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
4982 /* Subsequent .got entries will continue to bounce through the .plt. */
4985 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4986 BFD_ASSERT (! info->shared || srel != NULL);
4988 gotent = gotent->next;
4991 sgot = alpha_elf_tdata(gotent->gotobj)->got;
4992 BFD_ASSERT(sgot != NULL);
4993 BFD_ASSERT(gotent->addend == 0);
4995 bfd_put_64 (output_bfd, plt_addr,
4996 sgot->contents + gotent->got_offset);
4999 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel,
5000 gotent->got_offset, 0,
5001 R_ALPHA_RELATIVE, plt_addr);
5003 gotent = gotent->next;
5005 while (gotent != NULL);
5008 else if (alpha_elf_dynamic_symbol_p (h, info))
5010 /* Fill in the dynamic relocations for this symbol's .got entries. */
5012 struct alpha_elf_got_entry *gotent;
5014 srel = bfd_get_section_by_name (dynobj, ".rela.got");
5015 BFD_ASSERT (srel != NULL);
5017 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
5019 gotent = gotent->next)
5024 if (gotent->use_count == 0)
5027 sgot = alpha_elf_tdata (gotent->gotobj)->got;
5029 r_type = gotent->reloc_type;
5032 case R_ALPHA_LITERAL:
5033 r_type = R_ALPHA_GLOB_DAT;
5036 r_type = R_ALPHA_DTPMOD64;
5038 case R_ALPHA_GOTDTPREL:
5039 r_type = R_ALPHA_DTPREL64;
5041 case R_ALPHA_GOTTPREL:
5042 r_type = R_ALPHA_TPREL64;
5044 case R_ALPHA_TLSLDM:
5049 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel,
5050 gotent->got_offset, h->dynindx,
5051 r_type, gotent->addend);
5053 if (gotent->reloc_type == R_ALPHA_TLSGD)
5054 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel,
5055 gotent->got_offset + 8, h->dynindx,
5056 R_ALPHA_DTPREL64, gotent->addend);
5060 /* Mark some specially defined symbols as absolute. */
5061 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5062 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
5063 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
5064 sym->st_shndx = SHN_ABS;
5069 /* Finish up the dynamic sections. */
5072 elf64_alpha_finish_dynamic_sections (output_bfd, info)
5074 struct bfd_link_info *info;
5079 dynobj = elf_hash_table (info)->dynobj;
5080 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5082 if (elf_hash_table (info)->dynamic_sections_created)
5085 Elf64_External_Dyn *dyncon, *dynconend;
5087 splt = bfd_get_section_by_name (dynobj, ".plt");
5088 BFD_ASSERT (splt != NULL && sdyn != NULL);
5090 dyncon = (Elf64_External_Dyn *) sdyn->contents;
5091 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5092 for (; dyncon < dynconend; dyncon++)
5094 Elf_Internal_Dyn dyn;
5098 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
5113 /* My interpretation of the TIS v1.1 ELF document indicates
5114 that RELASZ should not include JMPREL. This is not what
5115 the rest of the BFD does. It is, however, what the
5116 glibc ld.so wants. Do this fixup here until we found
5117 out who is right. */
5118 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
5122 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
5127 s = bfd_get_section_by_name (output_bfd, name);
5128 dyn.d_un.d_ptr = (s ? s->vma : 0);
5132 s = bfd_get_section_by_name (output_bfd, name);
5134 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
5138 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
5141 /* Initialize the PLT0 entry. */
5142 if (splt->_raw_size > 0)
5144 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
5145 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
5146 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
5147 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
5149 /* The next two words will be filled in by ld.so */
5150 bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 16);
5151 bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 24);
5153 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 0;
5160 /* We need to use a special link routine to handle the .mdebug section.
5161 We need to merge all instances of these sections together, not write
5162 them all out sequentially. */
5165 elf64_alpha_final_link (abfd, info)
5167 struct bfd_link_info *info;
5170 struct bfd_link_order *p;
5171 asection *mdebug_sec;
5172 struct ecoff_debug_info debug;
5173 const struct ecoff_debug_swap *swap
5174 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
5175 HDRR *symhdr = &debug.symbolic_header;
5176 PTR mdebug_handle = NULL;
5178 /* Go through the sections and collect the mdebug information. */
5180 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
5182 if (strcmp (o->name, ".mdebug") == 0)
5184 struct extsym_info einfo;
5186 /* We have found the .mdebug section in the output file.
5187 Look through all the link_orders comprising it and merge
5188 the information together. */
5189 symhdr->magic = swap->sym_magic;
5190 /* FIXME: What should the version stamp be? */
5192 symhdr->ilineMax = 0;
5196 symhdr->isymMax = 0;
5197 symhdr->ioptMax = 0;
5198 symhdr->iauxMax = 0;
5200 symhdr->issExtMax = 0;
5203 symhdr->iextMax = 0;
5205 /* We accumulate the debugging information itself in the
5206 debug_info structure. */
5208 debug.external_dnr = NULL;
5209 debug.external_pdr = NULL;
5210 debug.external_sym = NULL;
5211 debug.external_opt = NULL;
5212 debug.external_aux = NULL;
5214 debug.ssext = debug.ssext_end = NULL;
5215 debug.external_fdr = NULL;
5216 debug.external_rfd = NULL;
5217 debug.external_ext = debug.external_ext_end = NULL;
5219 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
5220 if (mdebug_handle == (PTR) NULL)
5229 static const char * const name[] =
5231 ".text", ".init", ".fini", ".data",
5232 ".rodata", ".sdata", ".sbss", ".bss"
5234 static const int sc[] = { scText, scInit, scFini, scData,
5235 scRData, scSData, scSBss, scBss };
5238 esym.cobol_main = 0;
5242 esym.asym.iss = issNil;
5243 esym.asym.st = stLocal;
5244 esym.asym.reserved = 0;
5245 esym.asym.index = indexNil;
5246 for (i = 0; i < 8; i++)
5248 esym.asym.sc = sc[i];
5249 s = bfd_get_section_by_name (abfd, name[i]);
5252 esym.asym.value = s->vma;
5253 last = s->vma + s->_raw_size;
5256 esym.asym.value = last;
5258 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
5264 for (p = o->link_order_head;
5265 p != (struct bfd_link_order *) NULL;
5268 asection *input_section;
5270 const struct ecoff_debug_swap *input_swap;
5271 struct ecoff_debug_info input_debug;
5275 if (p->type != bfd_indirect_link_order)
5277 if (p->type == bfd_data_link_order)
5282 input_section = p->u.indirect.section;
5283 input_bfd = input_section->owner;
5285 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
5286 || (get_elf_backend_data (input_bfd)
5287 ->elf_backend_ecoff_debug_swap) == NULL)
5289 /* I don't know what a non ALPHA ELF bfd would be
5290 doing with a .mdebug section, but I don't really
5291 want to deal with it. */
5295 input_swap = (get_elf_backend_data (input_bfd)
5296 ->elf_backend_ecoff_debug_swap);
5298 BFD_ASSERT (p->size == input_section->_raw_size);
5300 /* The ECOFF linking code expects that we have already
5301 read in the debugging information and set up an
5302 ecoff_debug_info structure, so we do that now. */
5303 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
5307 if (! (bfd_ecoff_debug_accumulate
5308 (mdebug_handle, abfd, &debug, swap, input_bfd,
5309 &input_debug, input_swap, info)))
5312 /* Loop through the external symbols. For each one with
5313 interesting information, try to find the symbol in
5314 the linker global hash table and save the information
5315 for the output external symbols. */
5316 eraw_src = input_debug.external_ext;
5317 eraw_end = (eraw_src
5318 + (input_debug.symbolic_header.iextMax
5319 * input_swap->external_ext_size));
5321 eraw_src < eraw_end;
5322 eraw_src += input_swap->external_ext_size)
5326 struct alpha_elf_link_hash_entry *h;
5328 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
5329 if (ext.asym.sc == scNil
5330 || ext.asym.sc == scUndefined
5331 || ext.asym.sc == scSUndefined)
5334 name = input_debug.ssext + ext.asym.iss;
5335 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
5336 name, FALSE, FALSE, TRUE);
5337 if (h == NULL || h->esym.ifd != -2)
5343 < input_debug.symbolic_header.ifdMax);
5344 ext.ifd = input_debug.ifdmap[ext.ifd];
5350 /* Free up the information we just read. */
5351 free (input_debug.line);
5352 free (input_debug.external_dnr);
5353 free (input_debug.external_pdr);
5354 free (input_debug.external_sym);
5355 free (input_debug.external_opt);
5356 free (input_debug.external_aux);
5357 free (input_debug.ss);
5358 free (input_debug.ssext);
5359 free (input_debug.external_fdr);
5360 free (input_debug.external_rfd);
5361 free (input_debug.external_ext);
5363 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5364 elf_link_input_bfd ignores this section. */
5365 input_section->flags &=~ SEC_HAS_CONTENTS;
5368 /* Build the external symbol information. */
5371 einfo.debug = &debug;
5373 einfo.failed = FALSE;
5374 elf_link_hash_traverse (elf_hash_table (info),
5375 elf64_alpha_output_extsym,
5380 /* Set the size of the .mdebug section. */
5381 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
5383 /* Skip this section later on (I don't think this currently
5384 matters, but someday it might). */
5385 o->link_order_head = (struct bfd_link_order *) NULL;
5391 /* Invoke the regular ELF backend linker to do all the work. */
5392 if (! bfd_elf64_bfd_final_link (abfd, info))
5395 /* Now write out the computed sections. */
5397 /* The .got subsections... */
5399 bfd *i, *dynobj = elf_hash_table(info)->dynobj;
5400 for (i = alpha_elf_hash_table(info)->got_list;
5402 i = alpha_elf_tdata(i)->got_link_next)
5406 /* elf_bfd_final_link already did everything in dynobj. */
5410 sgot = alpha_elf_tdata(i)->got;
5411 if (! bfd_set_section_contents (abfd, sgot->output_section,
5413 (file_ptr) sgot->output_offset,
5419 if (mdebug_sec != (asection *) NULL)
5421 BFD_ASSERT (abfd->output_has_begun);
5422 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
5424 mdebug_sec->filepos))
5427 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
5433 static enum elf_reloc_type_class
5434 elf64_alpha_reloc_type_class (rela)
5435 const Elf_Internal_Rela *rela;
5437 switch ((int) ELF64_R_TYPE (rela->r_info))
5439 case R_ALPHA_RELATIVE:
5440 return reloc_class_relative;
5441 case R_ALPHA_JMP_SLOT:
5442 return reloc_class_plt;
5444 return reloc_class_copy;
5446 return reloc_class_normal;
5450 static struct bfd_elf_special_section const elf64_alpha_special_sections[]=
5452 { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
5453 { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
5454 { NULL, 0, 0, 0, 0 }
5457 /* ECOFF swapping routines. These are used when dealing with the
5458 .mdebug section, which is in the ECOFF debugging format. Copied
5459 from elf32-mips.c. */
5460 static const struct ecoff_debug_swap
5461 elf64_alpha_ecoff_debug_swap =
5463 /* Symbol table magic number. */
5465 /* Alignment of debugging information. E.g., 4. */
5467 /* Sizes of external symbolic information. */
5468 sizeof (struct hdr_ext),
5469 sizeof (struct dnr_ext),
5470 sizeof (struct pdr_ext),
5471 sizeof (struct sym_ext),
5472 sizeof (struct opt_ext),
5473 sizeof (struct fdr_ext),
5474 sizeof (struct rfd_ext),
5475 sizeof (struct ext_ext),
5476 /* Functions to swap in external symbolic data. */
5485 _bfd_ecoff_swap_tir_in,
5486 _bfd_ecoff_swap_rndx_in,
5487 /* Functions to swap out external symbolic data. */
5496 _bfd_ecoff_swap_tir_out,
5497 _bfd_ecoff_swap_rndx_out,
5498 /* Function to read in symbolic data. */
5499 elf64_alpha_read_ecoff_info
5502 /* Use a non-standard hash bucket size of 8. */
5504 static const struct elf_size_info alpha_elf_size_info =
5506 sizeof (Elf64_External_Ehdr),
5507 sizeof (Elf64_External_Phdr),
5508 sizeof (Elf64_External_Shdr),
5509 sizeof (Elf64_External_Rel),
5510 sizeof (Elf64_External_Rela),
5511 sizeof (Elf64_External_Sym),
5512 sizeof (Elf64_External_Dyn),
5513 sizeof (Elf_External_Note),
5517 ELFCLASS64, EV_CURRENT,
5518 bfd_elf64_write_out_phdrs,
5519 bfd_elf64_write_shdrs_and_ehdr,
5520 bfd_elf64_write_relocs,
5521 bfd_elf64_swap_symbol_in,
5522 bfd_elf64_swap_symbol_out,
5523 bfd_elf64_slurp_reloc_table,
5524 bfd_elf64_slurp_symbol_table,
5525 bfd_elf64_swap_dyn_in,
5526 bfd_elf64_swap_dyn_out,
5527 bfd_elf64_swap_reloc_in,
5528 bfd_elf64_swap_reloc_out,
5529 bfd_elf64_swap_reloca_in,
5530 bfd_elf64_swap_reloca_out
5533 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5534 #define TARGET_LITTLE_NAME "elf64-alpha"
5535 #define ELF_ARCH bfd_arch_alpha
5536 #define ELF_MACHINE_CODE EM_ALPHA
5537 #define ELF_MAXPAGESIZE 0x10000
5539 #define bfd_elf64_bfd_link_hash_table_create \
5540 elf64_alpha_bfd_link_hash_table_create
5542 #define bfd_elf64_bfd_reloc_type_lookup \
5543 elf64_alpha_bfd_reloc_type_lookup
5544 #define elf_info_to_howto \
5545 elf64_alpha_info_to_howto
5547 #define bfd_elf64_mkobject \
5548 elf64_alpha_mkobject
5549 #define elf_backend_object_p \
5550 elf64_alpha_object_p
5552 #define elf_backend_section_from_shdr \
5553 elf64_alpha_section_from_shdr
5554 #define elf_backend_section_flags \
5555 elf64_alpha_section_flags
5556 #define elf_backend_fake_sections \
5557 elf64_alpha_fake_sections
5559 #define bfd_elf64_bfd_is_local_label_name \
5560 elf64_alpha_is_local_label_name
5561 #define bfd_elf64_find_nearest_line \
5562 elf64_alpha_find_nearest_line
5563 #define bfd_elf64_bfd_relax_section \
5564 elf64_alpha_relax_section
5566 #define elf_backend_add_symbol_hook \
5567 elf64_alpha_add_symbol_hook
5568 #define elf_backend_check_relocs \
5569 elf64_alpha_check_relocs
5570 #define elf_backend_create_dynamic_sections \
5571 elf64_alpha_create_dynamic_sections
5572 #define elf_backend_adjust_dynamic_symbol \
5573 elf64_alpha_adjust_dynamic_symbol
5574 #define elf_backend_always_size_sections \
5575 elf64_alpha_always_size_sections
5576 #define elf_backend_size_dynamic_sections \
5577 elf64_alpha_size_dynamic_sections
5578 #define elf_backend_relocate_section \
5579 elf64_alpha_relocate_section
5580 #define elf_backend_finish_dynamic_symbol \
5581 elf64_alpha_finish_dynamic_symbol
5582 #define elf_backend_finish_dynamic_sections \
5583 elf64_alpha_finish_dynamic_sections
5584 #define bfd_elf64_bfd_final_link \
5585 elf64_alpha_final_link
5586 #define elf_backend_reloc_type_class \
5587 elf64_alpha_reloc_type_class
5589 #define elf_backend_ecoff_debug_swap \
5590 &elf64_alpha_ecoff_debug_swap
5592 #define elf_backend_size_info \
5595 #define elf_backend_special_sections \
5596 elf64_alpha_special_sections
5598 /* A few constants that determine how the .plt section is set up. */
5599 #define elf_backend_want_got_plt 0
5600 #define elf_backend_plt_readonly 0
5601 #define elf_backend_want_plt_sym 1
5602 #define elf_backend_got_header_size 0
5603 #define elf_backend_plt_header_size PLT_HEADER_SIZE
5605 #include "elf64-target.h"
5607 /* FreeBSD support. */
5609 #undef TARGET_LITTLE_SYM
5610 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5611 #undef TARGET_LITTLE_NAME
5612 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5614 /* The kernel recognizes executables as valid only if they carry a
5615 "FreeBSD" label in the ELF header. So we put this label on all
5616 executables and (for simplicity) also all other object files. */
5618 static void elf64_alpha_fbsd_post_process_headers
5619 PARAMS ((bfd *, struct bfd_link_info *));
5622 elf64_alpha_fbsd_post_process_headers (abfd, link_info)
5624 struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
5626 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
5628 i_ehdrp = elf_elfheader (abfd);
5630 /* Put an ABI label supported by FreeBSD >= 4.1. */
5631 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
5632 #ifdef OLD_FREEBSD_ABI_LABEL
5633 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5634 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
5638 #undef elf_backend_post_process_headers
5639 #define elf_backend_post_process_headers \
5640 elf64_alpha_fbsd_post_process_headers
5643 #define elf64_bed elf64_alpha_fbsd_bed
5645 #include "elf64-target.h"