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 int alpha_elf_dynamic_symbol_p
51 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
52 static struct bfd_hash_entry * elf64_alpha_link_hash_newfunc
53 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
54 static struct bfd_link_hash_table * elf64_alpha_bfd_link_hash_table_create
57 static bfd_reloc_status_type elf64_alpha_reloc_nil
58 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
59 static bfd_reloc_status_type elf64_alpha_reloc_bad
60 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
61 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
62 PARAMS ((bfd *, bfd_vma, bfd_byte *, bfd_byte *));
63 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
64 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
66 static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup
67 PARAMS ((bfd *, bfd_reloc_code_real_type));
68 static void elf64_alpha_info_to_howto
69 PARAMS ((bfd *, arelent *, 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? */
275 alpha_elf_dynamic_symbol_p (h, info)
276 struct elf_link_hash_entry *h;
277 struct bfd_link_info *info;
282 while (h->root.type == bfd_link_hash_indirect
283 || h->root.type == bfd_link_hash_warning)
284 h = (struct elf_link_hash_entry *) h->root.u.i.link;
286 if (h->dynindx == -1)
289 if (h->root.type == bfd_link_hash_undefweak
290 || h->root.type == bfd_link_hash_defweak)
293 switch (ELF_ST_VISIBILITY (h->other))
301 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
306 if ((info->shared && !info->symbolic)
307 || ((h->elf_link_hash_flags
308 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))
309 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
315 /* Create an entry in a Alpha ELF linker hash table. */
317 static struct bfd_hash_entry *
318 elf64_alpha_link_hash_newfunc (entry, table, string)
319 struct bfd_hash_entry *entry;
320 struct bfd_hash_table *table;
323 struct alpha_elf_link_hash_entry *ret =
324 (struct alpha_elf_link_hash_entry *) entry;
326 /* Allocate the structure if it has not already been allocated by a
328 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
329 ret = ((struct alpha_elf_link_hash_entry *)
330 bfd_hash_allocate (table,
331 sizeof (struct alpha_elf_link_hash_entry)));
332 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
333 return (struct bfd_hash_entry *) ret;
335 /* Call the allocation method of the superclass. */
336 ret = ((struct alpha_elf_link_hash_entry *)
337 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
339 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
341 /* Set local fields. */
342 memset (&ret->esym, 0, sizeof (EXTR));
343 /* We use -2 as a marker to indicate that the information has
344 not been set. -1 means there is no associated ifd. */
347 ret->got_entries = NULL;
348 ret->reloc_entries = NULL;
351 return (struct bfd_hash_entry *) ret;
354 /* Create a Alpha ELF linker hash table. */
356 static struct bfd_link_hash_table *
357 elf64_alpha_bfd_link_hash_table_create (abfd)
360 struct alpha_elf_link_hash_table *ret;
361 bfd_size_type amt = sizeof (struct alpha_elf_link_hash_table);
363 ret = (struct alpha_elf_link_hash_table *) bfd_zmalloc (amt);
364 if (ret == (struct alpha_elf_link_hash_table *) NULL)
367 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
368 elf64_alpha_link_hash_newfunc))
374 return &ret->root.root;
377 /* We have some private fields hanging off of the elf_tdata structure. */
379 struct alpha_elf_obj_tdata
381 struct elf_obj_tdata root;
383 /* For every input file, these are the got entries for that object's
385 struct alpha_elf_got_entry ** local_got_entries;
387 /* For every input file, this is the object that owns the got that
388 this input file uses. */
391 /* For every got, this is a linked list through the objects using this got */
392 bfd *in_got_link_next;
394 /* For every got, this is a link to the next got subsegment. */
397 /* For every got, this is the section. */
400 /* For every got, this is it's total number of words. */
403 /* For every got, this is the sum of the number of words required
404 to hold all of the member object's local got. */
408 #define alpha_elf_tdata(abfd) \
409 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
412 elf64_alpha_mkobject (abfd)
415 bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata);
416 abfd->tdata.any = bfd_zalloc (abfd, amt);
417 if (abfd->tdata.any == NULL)
423 elf64_alpha_object_p (abfd)
426 /* Allocate our special target data. */
427 struct alpha_elf_obj_tdata *new_tdata;
428 bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata);
429 new_tdata = bfd_zalloc (abfd, amt);
430 if (new_tdata == NULL)
432 new_tdata->root = *abfd->tdata.elf_obj_data;
433 abfd->tdata.any = new_tdata;
435 /* Set the right machine number for an Alpha ELF file. */
436 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
439 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
440 from smaller values. Start with zero, widen, *then* decrement. */
441 #define MINUS_ONE (((bfd_vma)0) - 1)
443 #define SKIP_HOWTO(N) \
444 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
446 static reloc_howto_type elf64_alpha_howto_table[] =
448 HOWTO (R_ALPHA_NONE, /* type */
450 0, /* size (0 = byte, 1 = short, 2 = long) */
452 TRUE, /* pc_relative */
454 complain_overflow_dont, /* complain_on_overflow */
455 elf64_alpha_reloc_nil, /* special_function */
457 FALSE, /* partial_inplace */
460 TRUE), /* pcrel_offset */
462 /* A 32 bit reference to a symbol. */
463 HOWTO (R_ALPHA_REFLONG, /* type */
465 2, /* size (0 = byte, 1 = short, 2 = long) */
467 FALSE, /* pc_relative */
469 complain_overflow_bitfield, /* complain_on_overflow */
470 0, /* special_function */
471 "REFLONG", /* name */
472 FALSE, /* partial_inplace */
473 0xffffffff, /* src_mask */
474 0xffffffff, /* dst_mask */
475 FALSE), /* pcrel_offset */
477 /* A 64 bit reference to a symbol. */
478 HOWTO (R_ALPHA_REFQUAD, /* type */
480 4, /* size (0 = byte, 1 = short, 2 = long) */
482 FALSE, /* pc_relative */
484 complain_overflow_bitfield, /* complain_on_overflow */
485 0, /* special_function */
486 "REFQUAD", /* name */
487 FALSE, /* partial_inplace */
488 MINUS_ONE, /* src_mask */
489 MINUS_ONE, /* dst_mask */
490 FALSE), /* pcrel_offset */
492 /* A 32 bit GP relative offset. This is just like REFLONG except
493 that when the value is used the value of the gp register will be
495 HOWTO (R_ALPHA_GPREL32, /* type */
497 2, /* size (0 = byte, 1 = short, 2 = long) */
499 FALSE, /* pc_relative */
501 complain_overflow_bitfield, /* complain_on_overflow */
502 0, /* special_function */
503 "GPREL32", /* name */
504 FALSE, /* partial_inplace */
505 0xffffffff, /* src_mask */
506 0xffffffff, /* dst_mask */
507 FALSE), /* pcrel_offset */
509 /* Used for an instruction that refers to memory off the GP register. */
510 HOWTO (R_ALPHA_LITERAL, /* type */
512 1, /* size (0 = byte, 1 = short, 2 = long) */
514 FALSE, /* pc_relative */
516 complain_overflow_signed, /* complain_on_overflow */
517 0, /* special_function */
518 "ELF_LITERAL", /* name */
519 FALSE, /* partial_inplace */
520 0xffff, /* src_mask */
521 0xffff, /* dst_mask */
522 FALSE), /* pcrel_offset */
524 /* This reloc only appears immediately following an ELF_LITERAL reloc.
525 It identifies a use of the literal. The symbol index is special:
526 1 means the literal address is in the base register of a memory
527 format instruction; 2 means the literal address is in the byte
528 offset register of a byte-manipulation instruction; 3 means the
529 literal address is in the target register of a jsr instruction.
530 This does not actually do any relocation. */
531 HOWTO (R_ALPHA_LITUSE, /* type */
533 1, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE, /* pc_relative */
537 complain_overflow_dont, /* complain_on_overflow */
538 elf64_alpha_reloc_nil, /* special_function */
540 FALSE, /* partial_inplace */
543 FALSE), /* pcrel_offset */
545 /* Load the gp register. This is always used for a ldah instruction
546 which loads the upper 16 bits of the gp register. The symbol
547 index of the GPDISP instruction is an offset in bytes to the lda
548 instruction that loads the lower 16 bits. The value to use for
549 the relocation is the difference between the GP value and the
550 current location; the load will always be done against a register
551 holding the current address.
553 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
554 any offset is present in the instructions, it is an offset from
555 the register to the ldah instruction. This lets us avoid any
556 stupid hackery like inventing a gp value to do partial relocation
557 against. Also unlike ECOFF, we do the whole relocation off of
558 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
559 space consuming bit, that, since all the information was present
560 in the GPDISP_HI16 reloc. */
561 HOWTO (R_ALPHA_GPDISP, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 FALSE, /* pc_relative */
567 complain_overflow_dont, /* complain_on_overflow */
568 elf64_alpha_reloc_gpdisp, /* special_function */
570 FALSE, /* partial_inplace */
571 0xffff, /* src_mask */
572 0xffff, /* dst_mask */
573 TRUE), /* pcrel_offset */
575 /* A 21 bit branch. */
576 HOWTO (R_ALPHA_BRADDR, /* type */
578 2, /* 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 0x1fffff, /* src_mask */
587 0x1fffff, /* dst_mask */
588 TRUE), /* pcrel_offset */
590 /* A hint for a jump to a register. */
591 HOWTO (R_ALPHA_HINT, /* type */
593 1, /* size (0 = byte, 1 = short, 2 = long) */
595 TRUE, /* pc_relative */
597 complain_overflow_dont, /* complain_on_overflow */
598 0, /* special_function */
600 FALSE, /* partial_inplace */
601 0x3fff, /* src_mask */
602 0x3fff, /* dst_mask */
603 TRUE), /* pcrel_offset */
605 /* 16 bit PC relative offset. */
606 HOWTO (R_ALPHA_SREL16, /* type */
608 1, /* 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 0xffff, /* src_mask */
617 0xffff, /* dst_mask */
618 TRUE), /* pcrel_offset */
620 /* 32 bit PC relative offset. */
621 HOWTO (R_ALPHA_SREL32, /* type */
623 2, /* size (0 = byte, 1 = short, 2 = long) */
625 TRUE, /* pc_relative */
627 complain_overflow_signed, /* complain_on_overflow */
628 0, /* special_function */
630 FALSE, /* partial_inplace */
631 0xffffffff, /* src_mask */
632 0xffffffff, /* dst_mask */
633 TRUE), /* pcrel_offset */
635 /* A 64 bit PC relative offset. */
636 HOWTO (R_ALPHA_SREL64, /* type */
638 4, /* size (0 = byte, 1 = short, 2 = long) */
640 TRUE, /* pc_relative */
642 complain_overflow_signed, /* complain_on_overflow */
643 0, /* special_function */
645 FALSE, /* partial_inplace */
646 MINUS_ONE, /* src_mask */
647 MINUS_ONE, /* dst_mask */
648 TRUE), /* pcrel_offset */
650 /* Skip 12 - 16; deprecated ECOFF relocs. */
657 /* The high 16 bits of the displacement from GP to the target. */
658 HOWTO (R_ALPHA_GPRELHIGH,
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 "GPRELHIGH", /* name */
667 FALSE, /* partial_inplace */
668 0xffff, /* src_mask */
669 0xffff, /* dst_mask */
670 FALSE), /* pcrel_offset */
672 /* The low 16 bits of the displacement from GP to the target. */
673 HOWTO (R_ALPHA_GPRELLOW,
675 1, /* size (0 = byte, 1 = short, 2 = long) */
677 FALSE, /* pc_relative */
679 complain_overflow_dont, /* complain_on_overflow */
680 0, /* special_function */
681 "GPRELLOW", /* name */
682 FALSE, /* partial_inplace */
683 0xffff, /* src_mask */
684 0xffff, /* dst_mask */
685 FALSE), /* pcrel_offset */
687 /* A 16-bit displacement from the GP to the target. */
688 HOWTO (R_ALPHA_GPREL16,
690 1, /* size (0 = byte, 1 = short, 2 = long) */
692 FALSE, /* pc_relative */
694 complain_overflow_signed, /* complain_on_overflow */
695 0, /* special_function */
696 "GPREL16", /* name */
697 FALSE, /* partial_inplace */
698 0xffff, /* src_mask */
699 0xffff, /* dst_mask */
700 FALSE), /* pcrel_offset */
702 /* Skip 20 - 23; deprecated ECOFF relocs. */
708 /* Misc ELF relocations. */
710 /* A dynamic relocation to copy the target into our .dynbss section. */
711 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
712 is present because every other ELF has one, but should not be used
713 because .dynbss is an ugly thing. */
720 complain_overflow_dont,
721 bfd_elf_generic_reloc,
728 /* A dynamic relocation for a .got entry. */
729 HOWTO (R_ALPHA_GLOB_DAT,
735 complain_overflow_dont,
736 bfd_elf_generic_reloc,
743 /* A dynamic relocation for a .plt entry. */
744 HOWTO (R_ALPHA_JMP_SLOT,
750 complain_overflow_dont,
751 bfd_elf_generic_reloc,
758 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
759 HOWTO (R_ALPHA_RELATIVE,
765 complain_overflow_dont,
766 bfd_elf_generic_reloc,
773 /* A 21 bit branch that adjusts for gp loads. */
774 HOWTO (R_ALPHA_BRSGP, /* type */
776 2, /* size (0 = byte, 1 = short, 2 = long) */
778 TRUE, /* pc_relative */
780 complain_overflow_signed, /* complain_on_overflow */
781 0, /* special_function */
783 FALSE, /* partial_inplace */
784 0x1fffff, /* src_mask */
785 0x1fffff, /* dst_mask */
786 TRUE), /* pcrel_offset */
788 /* Creates a tls_index for the symbol in the got. */
789 HOWTO (R_ALPHA_TLSGD, /* type */
791 1, /* size (0 = byte, 1 = short, 2 = long) */
793 FALSE, /* pc_relative */
795 complain_overflow_signed, /* complain_on_overflow */
796 0, /* special_function */
798 FALSE, /* partial_inplace */
799 0xffff, /* src_mask */
800 0xffff, /* dst_mask */
801 FALSE), /* pcrel_offset */
803 /* Creates a tls_index for the (current) module in the got. */
804 HOWTO (R_ALPHA_TLSLDM, /* type */
806 1, /* size (0 = byte, 1 = short, 2 = long) */
808 FALSE, /* pc_relative */
810 complain_overflow_signed, /* complain_on_overflow */
811 0, /* special_function */
813 FALSE, /* partial_inplace */
814 0xffff, /* src_mask */
815 0xffff, /* dst_mask */
816 FALSE), /* pcrel_offset */
818 /* A dynamic relocation for a DTP module entry. */
819 HOWTO (R_ALPHA_DTPMOD64, /* type */
821 4, /* size (0 = byte, 1 = short, 2 = long) */
823 FALSE, /* pc_relative */
825 complain_overflow_bitfield, /* complain_on_overflow */
826 0, /* special_function */
827 "DTPMOD64", /* name */
828 FALSE, /* partial_inplace */
829 MINUS_ONE, /* src_mask */
830 MINUS_ONE, /* dst_mask */
831 FALSE), /* pcrel_offset */
833 /* Creates a 64-bit offset in the got for the displacement
834 from DTP to the target. */
835 HOWTO (R_ALPHA_GOTDTPREL, /* 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 "GOTDTPREL", /* name */
844 FALSE, /* partial_inplace */
845 0xffff, /* src_mask */
846 0xffff, /* dst_mask */
847 FALSE), /* pcrel_offset */
849 /* A dynamic relocation for a displacement from DTP to the target. */
850 HOWTO (R_ALPHA_DTPREL64, /* type */
852 4, /* size (0 = byte, 1 = short, 2 = long) */
854 FALSE, /* pc_relative */
856 complain_overflow_bitfield, /* complain_on_overflow */
857 0, /* special_function */
858 "DTPREL64", /* name */
859 FALSE, /* partial_inplace */
860 MINUS_ONE, /* src_mask */
861 MINUS_ONE, /* dst_mask */
862 FALSE), /* pcrel_offset */
864 /* The high 16 bits of the displacement from DTP to the target. */
865 HOWTO (R_ALPHA_DTPRELHI, /* 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 "DTPRELHI", /* name */
874 FALSE, /* partial_inplace */
875 0xffff, /* src_mask */
876 0xffff, /* dst_mask */
877 FALSE), /* pcrel_offset */
879 /* The low 16 bits of the displacement from DTP to the target. */
880 HOWTO (R_ALPHA_DTPRELLO, /* type */
882 1, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE, /* pc_relative */
886 complain_overflow_dont, /* complain_on_overflow */
887 0, /* special_function */
888 "DTPRELLO", /* name */
889 FALSE, /* partial_inplace */
890 0xffff, /* src_mask */
891 0xffff, /* dst_mask */
892 FALSE), /* pcrel_offset */
894 /* A 16-bit displacement from DTP to the target. */
895 HOWTO (R_ALPHA_DTPREL16, /* type */
897 1, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE, /* pc_relative */
901 complain_overflow_signed, /* complain_on_overflow */
902 0, /* special_function */
903 "DTPREL16", /* name */
904 FALSE, /* partial_inplace */
905 0xffff, /* src_mask */
906 0xffff, /* dst_mask */
907 FALSE), /* pcrel_offset */
909 /* Creates a 64-bit offset in the got for the displacement
910 from TP to the target. */
911 HOWTO (R_ALPHA_GOTTPREL, /* 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 "GOTTPREL", /* name */
920 FALSE, /* partial_inplace */
921 0xffff, /* src_mask */
922 0xffff, /* dst_mask */
923 FALSE), /* pcrel_offset */
925 /* A dynamic relocation for a displacement from TP to the target. */
926 HOWTO (R_ALPHA_TPREL64, /* type */
928 4, /* size (0 = byte, 1 = short, 2 = long) */
930 FALSE, /* pc_relative */
932 complain_overflow_bitfield, /* complain_on_overflow */
933 0, /* special_function */
934 "TPREL64", /* name */
935 FALSE, /* partial_inplace */
936 MINUS_ONE, /* src_mask */
937 MINUS_ONE, /* dst_mask */
938 FALSE), /* pcrel_offset */
940 /* The high 16 bits of the displacement from TP to the target. */
941 HOWTO (R_ALPHA_TPRELHI, /* 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 "TPRELHI", /* name */
950 FALSE, /* partial_inplace */
951 0xffff, /* src_mask */
952 0xffff, /* dst_mask */
953 FALSE), /* pcrel_offset */
955 /* The low 16 bits of the displacement from TP to the target. */
956 HOWTO (R_ALPHA_TPRELLO, /* type */
958 1, /* size (0 = byte, 1 = short, 2 = long) */
960 FALSE, /* pc_relative */
962 complain_overflow_dont, /* complain_on_overflow */
963 0, /* special_function */
964 "TPRELLO", /* name */
965 FALSE, /* partial_inplace */
966 0xffff, /* src_mask */
967 0xffff, /* dst_mask */
968 FALSE), /* pcrel_offset */
970 /* A 16-bit displacement from TP to the target. */
971 HOWTO (R_ALPHA_TPREL16, /* type */
973 1, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE, /* pc_relative */
977 complain_overflow_signed, /* complain_on_overflow */
978 0, /* special_function */
979 "TPREL16", /* name */
980 FALSE, /* partial_inplace */
981 0xffff, /* src_mask */
982 0xffff, /* dst_mask */
983 FALSE), /* pcrel_offset */
986 /* A relocation function which doesn't do anything. */
988 static bfd_reloc_status_type
989 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
990 bfd *abfd ATTRIBUTE_UNUSED;
992 asymbol *sym ATTRIBUTE_UNUSED;
993 PTR data ATTRIBUTE_UNUSED;
996 char **error_message ATTRIBUTE_UNUSED;
999 reloc->address += sec->output_offset;
1000 return bfd_reloc_ok;
1003 /* A relocation function used for an unsupported reloc. */
1005 static bfd_reloc_status_type
1006 elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
1007 bfd *abfd ATTRIBUTE_UNUSED;
1009 asymbol *sym ATTRIBUTE_UNUSED;
1010 PTR data ATTRIBUTE_UNUSED;
1013 char **error_message ATTRIBUTE_UNUSED;
1016 reloc->address += sec->output_offset;
1017 return bfd_reloc_notsupported;
1020 /* Do the work of the GPDISP relocation. */
1022 static bfd_reloc_status_type
1023 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
1029 bfd_reloc_status_type ret = bfd_reloc_ok;
1031 unsigned long i_ldah, i_lda;
1033 i_ldah = bfd_get_32 (abfd, p_ldah);
1034 i_lda = bfd_get_32 (abfd, p_lda);
1036 /* Complain if the instructions are not correct. */
1037 if (((i_ldah >> 26) & 0x3f) != 0x09
1038 || ((i_lda >> 26) & 0x3f) != 0x08)
1039 ret = bfd_reloc_dangerous;
1041 /* Extract the user-supplied offset, mirroring the sign extensions
1042 that the instructions perform. */
1043 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
1044 addend = (addend ^ 0x80008000) - 0x80008000;
1048 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000
1049 || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000)
1050 ret = bfd_reloc_overflow;
1052 /* compensate for the sign extension again. */
1053 i_ldah = ((i_ldah & 0xffff0000)
1054 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
1055 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
1057 bfd_put_32 (abfd, (bfd_vma) i_ldah, p_ldah);
1058 bfd_put_32 (abfd, (bfd_vma) i_lda, p_lda);
1063 /* The special function for the GPDISP reloc. */
1065 static bfd_reloc_status_type
1066 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
1067 output_bfd, err_msg)
1069 arelent *reloc_entry;
1070 asymbol *sym ATTRIBUTE_UNUSED;
1072 asection *input_section;
1076 bfd_reloc_status_type ret;
1077 bfd_vma gp, relocation;
1078 bfd_byte *p_ldah, *p_lda;
1080 /* Don't do anything if we're not doing a final link. */
1083 reloc_entry->address += input_section->output_offset;
1084 return bfd_reloc_ok;
1087 if (reloc_entry->address > input_section->_cooked_size ||
1088 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
1089 return bfd_reloc_outofrange;
1091 /* The gp used in the portion of the output object to which this
1092 input object belongs is cached on the input bfd. */
1093 gp = _bfd_get_gp_value (abfd);
1095 relocation = (input_section->output_section->vma
1096 + input_section->output_offset
1097 + reloc_entry->address);
1099 p_ldah = (bfd_byte *) data + reloc_entry->address;
1100 p_lda = p_ldah + reloc_entry->addend;
1102 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
1104 /* Complain if the instructions are not correct. */
1105 if (ret == bfd_reloc_dangerous)
1106 *err_msg = _("GPDISP relocation did not find ldah and lda instructions");
1111 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1113 struct elf_reloc_map
1115 bfd_reloc_code_real_type bfd_reloc_val;
1119 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
1121 {BFD_RELOC_NONE, R_ALPHA_NONE},
1122 {BFD_RELOC_32, R_ALPHA_REFLONG},
1123 {BFD_RELOC_64, R_ALPHA_REFQUAD},
1124 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
1125 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
1126 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
1127 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
1128 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
1129 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
1130 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
1131 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
1132 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
1133 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
1134 {BFD_RELOC_ALPHA_GPREL_HI16, R_ALPHA_GPRELHIGH},
1135 {BFD_RELOC_ALPHA_GPREL_LO16, R_ALPHA_GPRELLOW},
1136 {BFD_RELOC_GPREL16, R_ALPHA_GPREL16},
1137 {BFD_RELOC_ALPHA_BRSGP, R_ALPHA_BRSGP},
1138 {BFD_RELOC_ALPHA_TLSGD, R_ALPHA_TLSGD},
1139 {BFD_RELOC_ALPHA_TLSLDM, R_ALPHA_TLSLDM},
1140 {BFD_RELOC_ALPHA_DTPMOD64, R_ALPHA_DTPMOD64},
1141 {BFD_RELOC_ALPHA_GOTDTPREL16, R_ALPHA_GOTDTPREL},
1142 {BFD_RELOC_ALPHA_DTPREL64, R_ALPHA_DTPREL64},
1143 {BFD_RELOC_ALPHA_DTPREL_HI16, R_ALPHA_DTPRELHI},
1144 {BFD_RELOC_ALPHA_DTPREL_LO16, R_ALPHA_DTPRELLO},
1145 {BFD_RELOC_ALPHA_DTPREL16, R_ALPHA_DTPREL16},
1146 {BFD_RELOC_ALPHA_GOTTPREL16, R_ALPHA_GOTTPREL},
1147 {BFD_RELOC_ALPHA_TPREL64, R_ALPHA_TPREL64},
1148 {BFD_RELOC_ALPHA_TPREL_HI16, R_ALPHA_TPRELHI},
1149 {BFD_RELOC_ALPHA_TPREL_LO16, R_ALPHA_TPRELLO},
1150 {BFD_RELOC_ALPHA_TPREL16, R_ALPHA_TPREL16},
1153 /* Given a BFD reloc type, return a HOWTO structure. */
1155 static reloc_howto_type *
1156 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
1157 bfd *abfd ATTRIBUTE_UNUSED;
1158 bfd_reloc_code_real_type code;
1160 const struct elf_reloc_map *i, *e;
1161 i = e = elf64_alpha_reloc_map;
1162 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
1165 if (i->bfd_reloc_val == code)
1166 return &elf64_alpha_howto_table[i->elf_reloc_val];
1171 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1174 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
1175 bfd *abfd ATTRIBUTE_UNUSED;
1177 Elf_Internal_Rela *dst;
1181 r_type = ELF64_R_TYPE(dst->r_info);
1182 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
1183 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
1186 /* These two relocations create a two-word entry in the got. */
1187 #define alpha_got_entry_size(r_type) \
1188 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1190 /* This is PT_TLS segment p_vaddr. */
1191 #define alpha_get_dtprel_base(tlss) \
1194 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1195 is assigned offset round(16, PT_TLS p_align). */
1196 #define alpha_get_tprel_base(tlss) \
1197 ((tlss)->start - align_power ((bfd_vma) 16, (tlss)->align))
1199 /* These functions do relaxation for Alpha ELF.
1201 Currently I'm only handling what I can do with existing compiler
1202 and assembler support, which means no instructions are removed,
1203 though some may be nopped. At this time GCC does not emit enough
1204 information to do all of the relaxing that is possible. It will
1205 take some not small amount of work for that to happen.
1207 There are a couple of interesting papers that I once read on this
1208 subject, that I cannot find references to at the moment, that
1209 related to Alpha in particular. They are by David Wall, then of
1213 #define OP_LDAH 0x09
1214 #define INSN_JSR 0x68004000
1215 #define INSN_JSR_MASK 0xfc00c000
1219 #define INSN_UNOP 0x2ffe0000
1220 #define INSN_ADDQ 0x40000400
1221 #define INSN_RDUNIQ 0x0000009e
1223 struct alpha_relax_info
1228 Elf_Internal_Shdr *symtab_hdr;
1229 Elf_Internal_Rela *relocs, *relend;
1230 struct bfd_link_info *link_info;
1231 struct elf_link_tls_segment *tls_segment;
1235 struct alpha_elf_link_hash_entry *h;
1236 struct alpha_elf_got_entry **first_gotent;
1237 struct alpha_elf_got_entry *gotent;
1238 bfd_boolean changed_contents;
1239 bfd_boolean changed_relocs;
1240 unsigned char other;
1243 static bfd_boolean elf64_alpha_relax_with_lituse
1244 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1245 Elf_Internal_Rela *irel));
1246 static bfd_vma elf64_alpha_relax_opt_call
1247 PARAMS((struct alpha_relax_info *info, bfd_vma symval));
1248 static bfd_boolean elf64_alpha_relax_got_load
1249 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1250 Elf_Internal_Rela *irel, unsigned long));
1251 static bfd_boolean elf64_alpha_relax_gprelhilo
1252 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1253 Elf_Internal_Rela *irel, bfd_boolean));
1254 static bfd_boolean elf64_alpha_relax_tls_get_addr
1255 PARAMS((struct alpha_relax_info *info, bfd_vma symval,
1256 Elf_Internal_Rela *irel, bfd_boolean));
1257 static struct elf_link_tls_segment *elf64_alpha_relax_find_tls_segment
1258 PARAMS((struct alpha_relax_info *, struct elf_link_tls_segment *));
1259 static bfd_boolean elf64_alpha_relax_section
1260 PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
1261 bfd_boolean *again));
1263 static Elf_Internal_Rela *
1264 elf64_alpha_find_reloc_at_ofs (rel, relend, offset, type)
1265 Elf_Internal_Rela *rel, *relend;
1269 while (rel < relend)
1271 if (rel->r_offset == offset
1272 && ELF64_R_TYPE (rel->r_info) == (unsigned int) type)
1280 elf64_alpha_relax_with_lituse (info, symval, irel)
1281 struct alpha_relax_info *info;
1283 Elf_Internal_Rela *irel;
1285 Elf_Internal_Rela *urel, *irelend = info->relend;
1286 int flags, count, i;
1287 bfd_signed_vma disp;
1290 bfd_boolean lit_reused = FALSE;
1291 bfd_boolean all_optimized = TRUE;
1292 unsigned int lit_insn;
1294 lit_insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1295 if (lit_insn >> 26 != OP_LDQ)
1297 ((*_bfd_error_handler)
1298 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1299 bfd_archive_filename (info->abfd), info->sec->name,
1300 (unsigned long) irel->r_offset));
1304 /* Can't relax dynamic symbols. */
1305 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info))
1308 /* Summarize how this particular LITERAL is used. */
1309 for (urel = irel+1, flags = count = 0; urel < irelend; ++urel, ++count)
1311 if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE)
1313 if (urel->r_addend <= 3)
1314 flags |= 1 << urel->r_addend;
1317 /* A little preparation for the loop... */
1318 disp = symval - info->gp;
1320 for (urel = irel+1, i = 0; i < count; ++i, ++urel)
1324 bfd_signed_vma xdisp;
1326 insn = bfd_get_32 (info->abfd, info->contents + urel->r_offset);
1328 switch (urel->r_addend)
1330 case LITUSE_ALPHA_ADDR:
1332 /* This type is really just a placeholder to note that all
1333 uses cannot be optimized, but to still allow some. */
1334 all_optimized = FALSE;
1337 case LITUSE_ALPHA_BASE:
1338 /* We can always optimize 16-bit displacements. */
1340 /* Extract the displacement from the instruction, sign-extending
1341 it if necessary, then test whether it is within 16 or 32 bits
1342 displacement from GP. */
1343 insn_disp = insn & 0x0000ffff;
1344 if (insn_disp & 0x8000)
1345 insn_disp |= ~0xffff; /* Negative: sign-extend. */
1347 xdisp = disp + insn_disp;
1348 fits16 = (xdisp >= - (bfd_signed_vma) 0x8000 && xdisp < 0x8000);
1349 fits32 = (xdisp >= - (bfd_signed_vma) 0x80000000
1350 && xdisp < 0x7fff8000);
1354 /* Take the op code and dest from this insn, take the base
1355 register from the literal insn. Leave the offset alone. */
1356 insn = (insn & 0xffe0ffff) | (lit_insn & 0x001f0000);
1357 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1359 urel->r_addend = irel->r_addend;
1360 info->changed_relocs = TRUE;
1362 bfd_put_32 (info->abfd, (bfd_vma) insn,
1363 info->contents + urel->r_offset);
1364 info->changed_contents = TRUE;
1367 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1368 else if (fits32 && !(flags & ~6))
1370 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
1372 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1374 lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000);
1375 bfd_put_32 (info->abfd, (bfd_vma) lit_insn,
1376 info->contents + irel->r_offset);
1378 info->changed_contents = TRUE;
1380 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1382 urel->r_addend = irel->r_addend;
1383 info->changed_relocs = TRUE;
1386 all_optimized = FALSE;
1389 case LITUSE_ALPHA_BYTOFF:
1390 /* We can always optimize byte instructions. */
1392 /* FIXME: sanity check the insn for byte op. Check that the
1393 literal dest reg is indeed Rb in the byte insn. */
1395 insn &= ~ (unsigned) 0x001ff000;
1396 insn |= ((symval & 7) << 13) | 0x1000;
1398 urel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1400 info->changed_relocs = TRUE;
1402 bfd_put_32 (info->abfd, (bfd_vma) insn,
1403 info->contents + urel->r_offset);
1404 info->changed_contents = TRUE;
1407 case LITUSE_ALPHA_JSR:
1408 case LITUSE_ALPHA_TLSGD:
1409 case LITUSE_ALPHA_TLSLDM:
1411 bfd_vma optdest, org;
1412 bfd_signed_vma odisp;
1414 /* If not zero, place to jump without needing pv. */
1415 optdest = elf64_alpha_relax_opt_call (info, symval);
1416 org = (info->sec->output_section->vma
1417 + info->sec->output_offset
1418 + urel->r_offset + 4);
1419 odisp = (optdest ? optdest : symval) - org;
1421 if (odisp >= -0x400000 && odisp < 0x400000)
1423 Elf_Internal_Rela *xrel;
1425 /* Preserve branch prediction call stack when possible. */
1426 if ((insn & INSN_JSR_MASK) == INSN_JSR)
1427 insn = (OP_BSR << 26) | (insn & 0x03e00000);
1429 insn = (OP_BR << 26) | (insn & 0x03e00000);
1431 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1433 urel->r_addend = irel->r_addend;
1436 urel->r_addend += optdest - symval;
1438 all_optimized = FALSE;
1440 bfd_put_32 (info->abfd, (bfd_vma) insn,
1441 info->contents + urel->r_offset);
1443 /* Kill any HINT reloc that might exist for this insn. */
1444 xrel = (elf64_alpha_find_reloc_at_ofs
1445 (info->relocs, info->relend, urel->r_offset,
1448 xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1450 info->changed_contents = TRUE;
1451 info->changed_relocs = TRUE;
1454 all_optimized = FALSE;
1456 /* Even if the target is not in range for a direct branch,
1457 if we share a GP, we can eliminate the gp reload. */
1460 Elf_Internal_Rela *gpdisp
1461 = (elf64_alpha_find_reloc_at_ofs
1462 (info->relocs, irelend, urel->r_offset + 4,
1466 bfd_byte *p_ldah = info->contents + gpdisp->r_offset;
1467 bfd_byte *p_lda = p_ldah + gpdisp->r_addend;
1468 unsigned int ldah = bfd_get_32 (info->abfd, p_ldah);
1469 unsigned int lda = bfd_get_32 (info->abfd, p_lda);
1471 /* Verify that the instruction is "ldah $29,0($26)".
1472 Consider a function that ends in a noreturn call,
1473 and that the next function begins with an ldgp,
1474 and that by accident there is no padding between.
1475 In that case the insn would use $27 as the base. */
1476 if (ldah == 0x27ba0000 && lda == 0x23bd0000)
1478 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_ldah);
1479 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_lda);
1481 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1482 info->changed_contents = TRUE;
1483 info->changed_relocs = TRUE;
1492 /* If all cases were optimized, we can reduce the use count on this
1493 got entry by one, possibly eliminating it. */
1496 if (--info->gotent->use_count == 0)
1498 int sz = alpha_got_entry_size (R_ALPHA_LITERAL);
1499 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1501 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1504 /* If the literal instruction is no longer needed (it may have been
1505 reused. We can eliminate it. */
1506 /* ??? For now, I don't want to deal with compacting the section,
1507 so just nop it out. */
1510 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1511 info->changed_relocs = TRUE;
1513 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP,
1514 info->contents + irel->r_offset);
1515 info->changed_contents = TRUE;
1523 elf64_alpha_relax_opt_call (info, symval)
1524 struct alpha_relax_info *info;
1527 /* If the function has the same gp, and we can identify that the
1528 function does not use its function pointer, we can eliminate the
1531 /* If the symbol is marked NOPV, we are being told the function never
1532 needs its procedure value. */
1533 if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV)
1536 /* If the symbol is marked STD_GP, we are being told the function does
1537 a normal ldgp in the first two words. */
1538 else if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD)
1541 /* Otherwise, we may be able to identify a GP load in the first two
1542 words, which we can then skip. */
1545 Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp;
1548 /* Load the relocations from the section that the target symbol is in. */
1549 if (info->sec == info->tsec)
1551 tsec_relocs = info->relocs;
1552 tsec_relend = info->relend;
1557 tsec_relocs = (_bfd_elf64_link_read_relocs
1558 (info->abfd, info->tsec, (PTR) NULL,
1559 (Elf_Internal_Rela *) NULL,
1560 info->link_info->keep_memory));
1561 if (tsec_relocs == NULL)
1563 tsec_relend = tsec_relocs + info->tsec->reloc_count;
1564 tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs);
1567 /* Recover the symbol's offset within the section. */
1568 ofs = (symval - info->tsec->output_section->vma
1569 - info->tsec->output_offset);
1571 /* Look for a GPDISP reloc. */
1572 gpdisp = (elf64_alpha_find_reloc_at_ofs
1573 (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP));
1575 if (!gpdisp || gpdisp->r_addend != 4)
1585 /* We've now determined that we can skip an initial gp load. Verify
1586 that the call and the target use the same gp. */
1587 if (info->link_info->hash->creator != info->tsec->owner->xvec
1588 || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj)
1595 elf64_alpha_relax_got_load (info, symval, irel, r_type)
1596 struct alpha_relax_info *info;
1598 Elf_Internal_Rela *irel;
1599 unsigned long r_type;
1602 bfd_signed_vma disp;
1604 /* Get the instruction. */
1605 insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset);
1607 if (insn >> 26 != OP_LDQ)
1609 reloc_howto_type *howto = elf64_alpha_howto_table + r_type;
1610 ((*_bfd_error_handler)
1611 ("%s: %s+0x%lx: warning: %s relocation against unexpected insn",
1612 bfd_archive_filename (info->abfd), info->sec->name,
1613 (unsigned long) irel->r_offset, howto->name));
1617 /* Can't relax dynamic symbols. */
1618 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info))
1621 /* Can't use local-exec relocations in shared libraries. */
1622 if (r_type == R_ALPHA_GOTTPREL && info->link_info->shared)
1625 if (r_type == R_ALPHA_LITERAL)
1626 disp = symval - info->gp;
1629 bfd_vma dtp_base, tp_base;
1631 BFD_ASSERT (info->tls_segment != NULL);
1632 dtp_base = alpha_get_dtprel_base (info->tls_segment);
1633 tp_base = alpha_get_tprel_base (info->tls_segment);
1634 disp = symval - (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base);
1637 if (disp < -0x8000 || disp >= 0x8000)
1640 /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading
1641 a constant, so force the base register to be $31. */
1642 if (r_type == R_ALPHA_LITERAL)
1643 insn = (OP_LDA << 26) | (insn & 0x03ff0000);
1645 insn = (OP_LDA << 26) | (insn & (31 << 21)) | (31 << 16);
1646 bfd_put_32 (info->abfd, (bfd_vma) insn, info->contents + irel->r_offset);
1647 info->changed_contents = TRUE;
1649 /* Reduce the use count on this got entry by one, possibly
1651 if (--info->gotent->use_count == 0)
1653 int sz = alpha_got_entry_size (r_type);
1654 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1656 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1659 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
1662 case R_ALPHA_LITERAL:
1663 r_type = R_ALPHA_GPREL16;
1665 case R_ALPHA_GOTDTPREL:
1666 r_type = R_ALPHA_DTPREL16;
1668 case R_ALPHA_GOTTPREL:
1669 r_type = R_ALPHA_TPREL16;
1676 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), r_type);
1677 info->changed_relocs = TRUE;
1679 /* ??? Search forward through this basic block looking for insns
1680 that use the target register. Stop after an insn modifying the
1681 register is seen, or after a branch or call.
1683 Any such memory load insn may be substituted by a load directly
1684 off the GP. This allows the memory load insn to be issued before
1685 the calculated GP register would otherwise be ready.
1687 Any such jsr insn can be replaced by a bsr if it is in range.
1689 This would mean that we'd have to _add_ relocations, the pain of
1690 which gives one pause. */
1696 elf64_alpha_relax_gprelhilo (info, symval, irel, hi)
1697 struct alpha_relax_info *info;
1699 Elf_Internal_Rela *irel;
1703 bfd_signed_vma disp;
1704 bfd_byte *pos = info->contents + irel->r_offset;
1706 /* ??? This assumes that the compiler doesn't render
1710 ldah t, array(gp) !gprelhigh
1712 ldq r, array(t) !gprellow
1714 which would indeed be the most efficient way to implement this. */
1718 disp = symval - info->gp;
1719 if (disp < -0x8000 || disp >= 0x8000)
1724 /* Nop out the high instruction. */
1726 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos);
1727 info->changed_contents = TRUE;
1729 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1731 info->changed_relocs = TRUE;
1735 /* Adjust the low instruction to reference GP directly. */
1737 insn = bfd_get_32 (info->abfd, pos);
1738 insn = (insn & 0xffe00000) | (29 << 16);
1739 bfd_put_32 (info->abfd, (bfd_vma) insn, pos);
1740 info->changed_contents = TRUE;
1742 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
1744 info->changed_relocs = TRUE;
1751 elf64_alpha_relax_tls_get_addr (info, symval, irel, is_gd)
1752 struct alpha_relax_info *info;
1754 Elf_Internal_Rela *irel;
1759 Elf_Internal_Rela *gpdisp, *hint;
1760 bfd_boolean dynamic, use_gottprel, pos1_unusable;
1761 unsigned long new_symndx;
1763 dynamic = alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info);
1765 /* If a TLS symbol is accessed using IE at least once, there is no point
1766 to use dynamic model for it. */
1767 if (is_gd && info->h && (info->h->flags & ALPHA_ELF_LINK_HASH_TLS_IE))
1770 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
1771 then we might as well relax to IE. */
1772 else if (info->link_info->shared && !dynamic
1773 && (info->link_info->flags & DF_STATIC_TLS))
1776 /* Otherwise we must be building an executable to do anything. */
1777 else if (info->link_info->shared)
1780 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
1781 the matching LITUSE_TLS relocations. */
1782 if (irel + 2 >= info->relend)
1784 if (ELF64_R_TYPE (irel[1].r_info) != R_ALPHA_LITERAL
1785 || ELF64_R_TYPE (irel[2].r_info) != R_ALPHA_LITUSE
1786 || irel[2].r_addend != (is_gd ? LITUSE_ALPHA_TLSGD : LITUSE_ALPHA_TLSLDM))
1789 /* There must be a GPDISP relocation positioned immediately after the
1790 LITUSE relocation. */
1791 gpdisp = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend,
1792 irel[2].r_offset + 4, R_ALPHA_GPDISP);
1796 pos[0] = info->contents + irel[0].r_offset;
1797 pos[1] = info->contents + irel[1].r_offset;
1798 pos[2] = info->contents + irel[2].r_offset;
1799 pos[3] = info->contents + gpdisp->r_offset;
1800 pos[4] = pos[3] + gpdisp->r_addend;
1801 pos1_unusable = FALSE;
1803 /* Generally, the positions are not allowed to be out of order, lest the
1804 modified insn sequence have different register lifetimes. We can make
1805 an exception when pos 1 is adjacent to pos 0. */
1806 if (pos[1] + 4 == pos[0])
1808 bfd_byte *tmp = pos[0];
1812 else if (pos[1] < pos[0])
1813 pos1_unusable = TRUE;
1814 if (pos[1] >= pos[2] || pos[2] >= pos[3])
1817 /* Reduce the use count on the LITERAL relocation. Do this before we
1818 smash the symndx when we adjust the relocations below. */
1820 struct alpha_elf_got_entry *lit_gotent;
1821 struct alpha_elf_link_hash_entry *lit_h;
1824 BFD_ASSERT (ELF64_R_SYM (irel[1].r_info) >= info->symtab_hdr->sh_info);
1825 indx = ELF64_R_SYM (irel[1].r_info) - info->symtab_hdr->sh_info;
1826 lit_h = alpha_elf_sym_hashes (info->abfd)[indx];
1828 while (lit_h->root.root.type == bfd_link_hash_indirect
1829 || lit_h->root.root.type == bfd_link_hash_warning)
1830 lit_h = (struct alpha_elf_link_hash_entry *) lit_h->root.root.u.i.link;
1832 for (lit_gotent = lit_h->got_entries; lit_gotent ;
1833 lit_gotent = lit_gotent->next)
1834 if (lit_gotent->gotobj == info->gotobj
1835 && lit_gotent->reloc_type == R_ALPHA_LITERAL
1836 && lit_gotent->addend == irel[1].r_addend)
1838 BFD_ASSERT (lit_gotent);
1840 if (--lit_gotent->use_count == 0)
1842 int sz = alpha_got_entry_size (R_ALPHA_LITERAL);
1843 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1849 lda $16,x($gp) !tlsgd!1
1850 ldq $27,__tls_get_addr($gp) !literal!1
1851 jsr $26,($27)__tls_get_addr !lituse_tlsgd!1
1852 ldah $29,0($26) !gpdisp!2
1853 lda $29,0($29) !gpdisp!2
1855 ldq $16,x($gp) !gottprel
1860 or the first pair to
1861 lda $16,x($gp) !tprel
1864 ldah $16,x($gp) !tprelhi
1865 lda $16,x($16) !tprello
1869 use_gottprel = FALSE;
1870 new_symndx = is_gd ? ELF64_R_SYM (irel->r_info) : 0;
1871 switch (!dynamic && !info->link_info->shared)
1876 bfd_signed_vma disp;
1878 BFD_ASSERT (info->tls_segment != NULL);
1879 tp_base = alpha_get_tprel_base (info->tls_segment);
1880 disp = symval - tp_base;
1882 if (disp >= -0x8000 && disp < 0x8000)
1884 insn = (OP_LDA << 26) | (16 << 21) | (31 << 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_TPREL16);
1890 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1893 else if (disp >= -(bfd_signed_vma) 0x80000000
1894 && disp < (bfd_signed_vma) 0x7fff8000
1897 insn = (OP_LDAH << 26) | (16 << 21) | (31 << 16);
1898 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1899 insn = (OP_LDA << 26) | (16 << 21) | (16 << 16);
1900 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[1]);
1902 irel[0].r_offset = pos[0] - info->contents;
1903 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPRELHI);
1904 irel[1].r_offset = pos[1] - info->contents;
1905 irel[1].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPRELLO);
1912 use_gottprel = TRUE;
1914 insn = (OP_LDQ << 26) | (16 << 21) | (29 << 16);
1915 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]);
1916 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]);
1918 irel[0].r_offset = pos[0] - info->contents;
1919 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_GOTTPREL);
1920 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1924 bfd_put_32 (info->abfd, (bfd_vma) INSN_RDUNIQ, pos[2]);
1926 insn = INSN_ADDQ | (16 << 21) | (0 << 16) | (0 << 0);
1927 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[3]);
1929 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[4]);
1931 irel[2].r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1932 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1934 hint = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend,
1935 irel[2].r_offset, R_ALPHA_HINT);
1937 hint->r_info = ELF64_R_INFO (0, R_ALPHA_NONE);
1939 info->changed_contents = TRUE;
1940 info->changed_relocs = TRUE;
1942 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
1943 if (--info->gotent->use_count == 0)
1945 int sz = alpha_got_entry_size (info->gotent->reloc_type);
1946 alpha_elf_tdata (info->gotobj)->total_got_size -= sz;
1948 alpha_elf_tdata (info->gotobj)->local_got_size -= sz;
1951 /* If we've switched to a GOTTPREL relocation, increment the reference
1952 count on that got entry. */
1955 struct alpha_elf_got_entry *tprel_gotent;
1957 for (tprel_gotent = *info->first_gotent; tprel_gotent ;
1958 tprel_gotent = tprel_gotent->next)
1959 if (tprel_gotent->gotobj == info->gotobj
1960 && tprel_gotent->reloc_type == R_ALPHA_GOTTPREL
1961 && tprel_gotent->addend == irel->r_addend)
1964 tprel_gotent->use_count++;
1967 if (info->gotent->use_count == 0)
1968 tprel_gotent = info->gotent;
1971 tprel_gotent = (struct alpha_elf_got_entry *)
1972 bfd_alloc (info->abfd, sizeof (struct alpha_elf_got_entry));
1976 tprel_gotent->next = *info->first_gotent;
1977 *info->first_gotent = tprel_gotent;
1979 tprel_gotent->gotobj = info->gotobj;
1980 tprel_gotent->addend = irel->r_addend;
1981 tprel_gotent->got_offset = -1;
1982 tprel_gotent->reloc_done = 0;
1983 tprel_gotent->reloc_xlated = 0;
1986 tprel_gotent->use_count = 1;
1987 tprel_gotent->reloc_type = R_ALPHA_GOTTPREL;
1994 static struct elf_link_tls_segment *
1995 elf64_alpha_relax_find_tls_segment (info, seg)
1996 struct alpha_relax_info *info;
1997 struct elf_link_tls_segment *seg;
1999 bfd *output_bfd = info->sec->output_section->owner;
2004 for (o = output_bfd->sections; o ; o = o->next)
2005 if ((o->flags & SEC_THREAD_LOCAL) != 0
2006 && (o->flags & SEC_LOAD) != 0)
2018 if (bfd_get_section_alignment (output_bfd, o) > align)
2019 align = bfd_get_section_alignment (output_bfd, o);
2021 size = o->_raw_size;
2022 if (size == 0 && (o->flags & SEC_HAS_CONTENTS) == 0)
2024 struct bfd_link_order *lo;
2025 for (lo = o->link_order_head; lo ; lo = lo->next)
2026 if (size < lo->offset + lo->size)
2027 size = lo->offset + lo->size;
2029 end = o->vma + size;
2032 while (o && (o->flags & SEC_THREAD_LOCAL));
2035 seg->size = end - base;
2042 elf64_alpha_relax_section (abfd, sec, link_info, again)
2045 struct bfd_link_info *link_info;
2048 Elf_Internal_Shdr *symtab_hdr;
2049 Elf_Internal_Rela *internal_relocs;
2050 Elf_Internal_Rela *irel, *irelend;
2051 Elf_Internal_Sym *isymbuf = NULL;
2052 struct alpha_elf_got_entry **local_got_entries;
2053 struct alpha_relax_info info;
2054 struct elf_link_tls_segment tls_segment;
2056 /* We are not currently changing any sizes, so only one pass. */
2059 if (link_info->relocateable
2060 || (sec->flags & SEC_RELOC) == 0
2061 || sec->reloc_count == 0)
2064 /* If this is the first time we have been called for this section,
2065 initialize the cooked size. */
2066 if (sec->_cooked_size == 0)
2067 sec->_cooked_size = sec->_raw_size;
2069 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2070 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2072 /* Load the relocations for this section. */
2073 internal_relocs = (_bfd_elf64_link_read_relocs
2074 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2075 link_info->keep_memory));
2076 if (internal_relocs == NULL)
2079 memset(&info, 0, sizeof (info));
2082 info.link_info = link_info;
2083 info.symtab_hdr = symtab_hdr;
2084 info.relocs = internal_relocs;
2085 info.relend = irelend = internal_relocs + sec->reloc_count;
2087 /* Find the GP for this object. Do not store the result back via
2088 _bfd_set_gp_value, since this could change again before final. */
2089 info.gotobj = alpha_elf_tdata (abfd)->gotobj;
2092 asection *sgot = alpha_elf_tdata (info.gotobj)->got;
2093 info.gp = (sgot->output_section->vma
2094 + sgot->output_offset
2098 /* Get the section contents. */
2099 if (elf_section_data (sec)->this_hdr.contents != NULL)
2100 info.contents = elf_section_data (sec)->this_hdr.contents;
2103 info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
2104 if (info.contents == NULL)
2107 if (! bfd_get_section_contents (abfd, sec, info.contents,
2108 (file_ptr) 0, sec->_raw_size))
2112 /* Compute the TLS segment information. The version normally found in
2113 elf_hash_table (link_info)->tls_segment isn't built until final_link.
2114 ??? Probably should look into extracting this into a common function. */
2115 info.tls_segment = elf64_alpha_relax_find_tls_segment (&info, &tls_segment);
2117 for (irel = internal_relocs; irel < irelend; irel++)
2120 struct alpha_elf_got_entry *gotent;
2121 unsigned long r_type = ELF64_R_TYPE (irel->r_info);
2122 unsigned long r_symndx = ELF64_R_SYM (irel->r_info);
2124 /* Early exit for unhandled or unrelaxable relocations. */
2127 case R_ALPHA_LITERAL:
2128 case R_ALPHA_GPRELHIGH:
2129 case R_ALPHA_GPRELLOW:
2130 case R_ALPHA_GOTDTPREL:
2131 case R_ALPHA_GOTTPREL:
2135 case R_ALPHA_TLSLDM:
2136 /* The symbol for a TLSLDM reloc is ignored. Collapse the
2137 reloc to the 0 symbol so that they all match. */
2145 /* Get the value of the symbol referred to by the reloc. */
2146 if (r_symndx < symtab_hdr->sh_info)
2148 /* A local symbol. */
2149 Elf_Internal_Sym *isym;
2151 /* Read this BFD's local symbols. */
2152 if (isymbuf == NULL)
2154 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2155 if (isymbuf == NULL)
2156 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2157 symtab_hdr->sh_info, 0,
2159 if (isymbuf == NULL)
2163 isym = isymbuf + r_symndx;
2165 /* Given the symbol for a TLSLDM reloc is ignored, this also
2166 means forcing the symbol value to the tp base. */
2167 if (r_type == R_ALPHA_TLSLDM)
2169 info.tsec = bfd_abs_section_ptr;
2170 symval = alpha_get_tprel_base (info.tls_segment);
2174 symval = isym->st_value;
2175 if (isym->st_shndx == SHN_UNDEF)
2177 else if (isym->st_shndx == SHN_ABS)
2178 info.tsec = bfd_abs_section_ptr;
2179 else if (isym->st_shndx == SHN_COMMON)
2180 info.tsec = bfd_com_section_ptr;
2182 info.tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2186 info.other = isym->st_other;
2187 if (local_got_entries)
2188 info.first_gotent = &local_got_entries[r_symndx];
2191 info.first_gotent = &info.gotent;
2198 struct alpha_elf_link_hash_entry *h;
2200 indx = r_symndx - symtab_hdr->sh_info;
2201 h = alpha_elf_sym_hashes (abfd)[indx];
2202 BFD_ASSERT (h != NULL);
2204 while (h->root.root.type == bfd_link_hash_indirect
2205 || h->root.root.type == bfd_link_hash_warning)
2206 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2208 /* If the symbol is undefined, we can't do anything with it. */
2209 if (h->root.root.type == bfd_link_hash_undefweak
2210 || h->root.root.type == bfd_link_hash_undefined)
2213 /* If the symbol isn't defined in the current module, again
2214 we can't do anything. */
2215 if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2217 /* Except for TLSGD relocs, which can sometimes be
2218 relaxed to GOTTPREL relocs. */
2219 if (r_type != R_ALPHA_TLSGD)
2221 info.tsec = bfd_abs_section_ptr;
2226 info.tsec = h->root.root.u.def.section;
2227 symval = h->root.root.u.def.value;
2231 info.other = h->root.other;
2232 info.first_gotent = &h->got_entries;
2235 /* Search for the got entry to be used by this relocation. */
2236 for (gotent = *info.first_gotent; gotent ; gotent = gotent->next)
2237 if (gotent->gotobj == info.gotobj
2238 && gotent->reloc_type == r_type
2239 && gotent->addend == irel->r_addend)
2241 info.gotent = gotent;
2243 symval += info.tsec->output_section->vma + info.tsec->output_offset;
2244 symval += irel->r_addend;
2248 case R_ALPHA_LITERAL:
2249 BFD_ASSERT(info.gotent != NULL);
2251 /* If there exist LITUSE relocations immediately following, this
2252 opens up all sorts of interesting optimizations, because we
2253 now know every location that this address load is used. */
2254 if (irel+1 < irelend
2255 && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE)
2257 if (!elf64_alpha_relax_with_lituse (&info, symval, irel))
2262 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type))
2267 case R_ALPHA_GPRELHIGH:
2268 case R_ALPHA_GPRELLOW:
2269 if (!elf64_alpha_relax_gprelhilo (&info, symval, irel,
2270 r_type == R_ALPHA_GPRELHIGH))
2274 case R_ALPHA_GOTDTPREL:
2275 case R_ALPHA_GOTTPREL:
2276 BFD_ASSERT(info.gotent != NULL);
2277 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type))
2282 case R_ALPHA_TLSLDM:
2283 BFD_ASSERT(info.gotent != NULL);
2284 if (!elf64_alpha_relax_tls_get_addr (&info, symval, irel,
2285 r_type == R_ALPHA_TLSGD))
2291 if (!elf64_alpha_size_plt_section (link_info))
2293 if (!elf64_alpha_size_got_sections (link_info))
2295 if (!elf64_alpha_size_rela_got_section (link_info))
2299 && symtab_hdr->contents != (unsigned char *) isymbuf)
2301 if (!link_info->keep_memory)
2305 /* Cache the symbols for elf_link_input_bfd. */
2306 symtab_hdr->contents = (unsigned char *) isymbuf;
2310 if (info.contents != NULL
2311 && elf_section_data (sec)->this_hdr.contents != info.contents)
2313 if (!info.changed_contents && !link_info->keep_memory)
2314 free (info.contents);
2317 /* Cache the section contents for elf_link_input_bfd. */
2318 elf_section_data (sec)->this_hdr.contents = info.contents;
2322 if (elf_section_data (sec)->relocs != internal_relocs)
2324 if (!info.changed_relocs)
2325 free (internal_relocs);
2327 elf_section_data (sec)->relocs = internal_relocs;
2330 *again = info.changed_contents || info.changed_relocs;
2336 && symtab_hdr->contents != (unsigned char *) isymbuf)
2338 if (info.contents != NULL
2339 && elf_section_data (sec)->this_hdr.contents != info.contents)
2340 free (info.contents);
2341 if (internal_relocs != NULL
2342 && elf_section_data (sec)->relocs != internal_relocs)
2343 free (internal_relocs);
2348 #define PLT_HEADER_SIZE 32
2349 #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */
2350 #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */
2351 #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */
2352 #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */
2354 #define PLT_ENTRY_SIZE 12
2355 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
2356 #define PLT_ENTRY_WORD2 0
2357 #define PLT_ENTRY_WORD3 0
2359 #define MAX_GOT_SIZE (64*1024)
2361 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
2363 /* Handle an Alpha specific section when reading an object file. This
2364 is called when elfcode.h finds a section with an unknown type.
2365 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
2369 elf64_alpha_section_from_shdr (abfd, hdr, name)
2371 Elf_Internal_Shdr *hdr;
2376 /* There ought to be a place to keep ELF backend specific flags, but
2377 at the moment there isn't one. We just keep track of the
2378 sections by their name, instead. Fortunately, the ABI gives
2379 suggested names for all the MIPS specific sections, so we will
2380 probably get away with this. */
2381 switch (hdr->sh_type)
2383 case SHT_ALPHA_DEBUG:
2384 if (strcmp (name, ".mdebug") != 0)
2391 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2393 newsect = hdr->bfd_section;
2395 if (hdr->sh_type == SHT_ALPHA_DEBUG)
2397 if (! bfd_set_section_flags (abfd, newsect,
2398 (bfd_get_section_flags (abfd, newsect)
2406 /* Convert Alpha specific section flags to bfd internal section flags. */
2409 elf64_alpha_section_flags (flags, hdr)
2411 Elf_Internal_Shdr *hdr;
2413 if (hdr->sh_flags & SHF_ALPHA_GPREL)
2414 *flags |= SEC_SMALL_DATA;
2419 /* Set the correct type for an Alpha ELF section. We do this by the
2420 section name, which is a hack, but ought to work. */
2423 elf64_alpha_fake_sections (abfd, hdr, sec)
2425 Elf_Internal_Shdr *hdr;
2428 register const char *name;
2430 name = bfd_get_section_name (abfd, sec);
2432 if (strcmp (name, ".mdebug") == 0)
2434 hdr->sh_type = SHT_ALPHA_DEBUG;
2435 /* In a shared object on Irix 5.3, the .mdebug section has an
2436 entsize of 0. FIXME: Does this matter? */
2437 if ((abfd->flags & DYNAMIC) != 0 )
2438 hdr->sh_entsize = 0;
2440 hdr->sh_entsize = 1;
2442 else if ((sec->flags & SEC_SMALL_DATA)
2443 || strcmp (name, ".sdata") == 0
2444 || strcmp (name, ".sbss") == 0
2445 || strcmp (name, ".lit4") == 0
2446 || strcmp (name, ".lit8") == 0)
2447 hdr->sh_flags |= SHF_ALPHA_GPREL;
2452 /* Hook called by the linker routine which adds symbols from an object
2453 file. We use it to put .comm items in .sbss, and not .bss. */
2456 elf64_alpha_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2458 struct bfd_link_info *info;
2459 const Elf_Internal_Sym *sym;
2460 const char **namep ATTRIBUTE_UNUSED;
2461 flagword *flagsp ATTRIBUTE_UNUSED;
2465 if (sym->st_shndx == SHN_COMMON
2466 && !info->relocateable
2467 && sym->st_size <= elf_gp_size (abfd))
2469 /* Common symbols less than or equal to -G nn bytes are
2470 automatically put into .sbss. */
2472 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
2476 scomm = bfd_make_section (abfd, ".scommon");
2478 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
2480 | SEC_LINKER_CREATED)))
2485 *valp = sym->st_size;
2491 /* Create the .got section. */
2494 elf64_alpha_create_got_section(abfd, info)
2496 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2500 if (bfd_get_section_by_name (abfd, ".got"))
2503 s = bfd_make_section (abfd, ".got");
2505 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2508 | SEC_LINKER_CREATED))
2509 || !bfd_set_section_alignment (abfd, s, 3))
2512 alpha_elf_tdata (abfd)->got = s;
2517 /* Create all the dynamic sections. */
2520 elf64_alpha_create_dynamic_sections (abfd, info)
2522 struct bfd_link_info *info;
2525 struct elf_link_hash_entry *h;
2526 struct bfd_link_hash_entry *bh;
2528 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
2530 s = bfd_make_section (abfd, ".plt");
2532 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2535 | SEC_LINKER_CREATED
2537 || ! bfd_set_section_alignment (abfd, s, 3))
2540 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2543 if (! (_bfd_generic_link_add_one_symbol
2544 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
2545 (bfd_vma) 0, (const char *) NULL, FALSE,
2546 get_elf_backend_data (abfd)->collect, &bh)))
2548 h = (struct elf_link_hash_entry *) bh;
2549 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2550 h->type = STT_OBJECT;
2553 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2556 s = bfd_make_section (abfd, ".rela.plt");
2558 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2561 | SEC_LINKER_CREATED
2563 || ! bfd_set_section_alignment (abfd, s, 3))
2566 /* We may or may not have created a .got section for this object, but
2567 we definitely havn't done the rest of the work. */
2569 if (!elf64_alpha_create_got_section (abfd, info))
2572 s = bfd_make_section(abfd, ".rela.got");
2574 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
2577 | SEC_LINKER_CREATED
2579 || !bfd_set_section_alignment (abfd, s, 3))
2582 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
2583 dynobj's .got section. We don't do this in the linker script
2584 because we don't want to define the symbol if we are not creating
2585 a global offset table. */
2587 if (!(_bfd_generic_link_add_one_symbol
2588 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
2589 alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
2590 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
2592 h = (struct elf_link_hash_entry *) bh;
2593 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2594 h->type = STT_OBJECT;
2597 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
2600 elf_hash_table (info)->hgot = h;
2605 /* Read ECOFF debugging information from a .mdebug section into a
2606 ecoff_debug_info structure. */
2609 elf64_alpha_read_ecoff_info (abfd, section, debug)
2612 struct ecoff_debug_info *debug;
2615 const struct ecoff_debug_swap *swap;
2616 char *ext_hdr = NULL;
2618 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2619 memset (debug, 0, sizeof (*debug));
2621 ext_hdr = (char *) bfd_malloc (swap->external_hdr_size);
2622 if (ext_hdr == NULL && swap->external_hdr_size != 0)
2625 if (! bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
2626 swap->external_hdr_size))
2629 symhdr = &debug->symbolic_header;
2630 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
2632 /* The symbolic header contains absolute file offsets and sizes to
2634 #define READ(ptr, offset, count, size, type) \
2635 if (symhdr->count == 0) \
2636 debug->ptr = NULL; \
2639 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
2640 debug->ptr = (type) bfd_malloc (amt); \
2641 if (debug->ptr == NULL) \
2642 goto error_return; \
2643 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2644 || bfd_bread (debug->ptr, amt, abfd) != amt) \
2645 goto error_return; \
2648 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
2649 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
2650 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
2651 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
2652 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
2653 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
2655 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
2656 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
2657 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
2658 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
2659 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
2663 debug->adjust = NULL;
2668 if (ext_hdr != NULL)
2670 if (debug->line != NULL)
2672 if (debug->external_dnr != NULL)
2673 free (debug->external_dnr);
2674 if (debug->external_pdr != NULL)
2675 free (debug->external_pdr);
2676 if (debug->external_sym != NULL)
2677 free (debug->external_sym);
2678 if (debug->external_opt != NULL)
2679 free (debug->external_opt);
2680 if (debug->external_aux != NULL)
2681 free (debug->external_aux);
2682 if (debug->ss != NULL)
2684 if (debug->ssext != NULL)
2685 free (debug->ssext);
2686 if (debug->external_fdr != NULL)
2687 free (debug->external_fdr);
2688 if (debug->external_rfd != NULL)
2689 free (debug->external_rfd);
2690 if (debug->external_ext != NULL)
2691 free (debug->external_ext);
2695 /* Alpha ELF local labels start with '$'. */
2698 elf64_alpha_is_local_label_name (abfd, name)
2699 bfd *abfd ATTRIBUTE_UNUSED;
2702 return name[0] == '$';
2705 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2706 routine in order to handle the ECOFF debugging information. We
2707 still call this mips_elf_find_line because of the slot
2708 find_line_info in elf_obj_tdata is declared that way. */
2710 struct mips_elf_find_line
2712 struct ecoff_debug_info d;
2713 struct ecoff_find_line i;
2717 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
2718 functionname_ptr, line_ptr)
2723 const char **filename_ptr;
2724 const char **functionname_ptr;
2725 unsigned int *line_ptr;
2729 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
2730 filename_ptr, functionname_ptr,
2732 &elf_tdata (abfd)->dwarf2_find_line_info))
2735 msec = bfd_get_section_by_name (abfd, ".mdebug");
2739 struct mips_elf_find_line *fi;
2740 const struct ecoff_debug_swap * const swap =
2741 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
2743 /* If we are called during a link, alpha_elf_final_link may have
2744 cleared the SEC_HAS_CONTENTS field. We force it back on here
2745 if appropriate (which it normally will be). */
2746 origflags = msec->flags;
2747 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
2748 msec->flags |= SEC_HAS_CONTENTS;
2750 fi = elf_tdata (abfd)->find_line_info;
2753 bfd_size_type external_fdr_size;
2756 struct fdr *fdr_ptr;
2757 bfd_size_type amt = sizeof (struct mips_elf_find_line);
2759 fi = (struct mips_elf_find_line *) bfd_zalloc (abfd, amt);
2762 msec->flags = origflags;
2766 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
2768 msec->flags = origflags;
2772 /* Swap in the FDR information. */
2773 amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr);
2774 fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt);
2775 if (fi->d.fdr == NULL)
2777 msec->flags = origflags;
2780 external_fdr_size = swap->external_fdr_size;
2781 fdr_ptr = fi->d.fdr;
2782 fraw_src = (char *) fi->d.external_fdr;
2783 fraw_end = (fraw_src
2784 + fi->d.symbolic_header.ifdMax * external_fdr_size);
2785 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
2786 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
2788 elf_tdata (abfd)->find_line_info = fi;
2790 /* Note that we don't bother to ever free this information.
2791 find_nearest_line is either called all the time, as in
2792 objdump -l, so the information should be saved, or it is
2793 rarely called, as in ld error messages, so the memory
2794 wasted is unimportant. Still, it would probably be a
2795 good idea for free_cached_info to throw it away. */
2798 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
2799 &fi->i, filename_ptr, functionname_ptr,
2802 msec->flags = origflags;
2806 msec->flags = origflags;
2809 /* Fall back on the generic ELF find_nearest_line routine. */
2811 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
2812 filename_ptr, functionname_ptr,
2816 /* Structure used to pass information to alpha_elf_output_extsym. */
2821 struct bfd_link_info *info;
2822 struct ecoff_debug_info *debug;
2823 const struct ecoff_debug_swap *swap;
2828 elf64_alpha_output_extsym (h, data)
2829 struct alpha_elf_link_hash_entry *h;
2832 struct extsym_info *einfo = (struct extsym_info *) data;
2834 asection *sec, *output_section;
2836 if (h->root.root.type == bfd_link_hash_warning)
2837 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
2839 if (h->root.indx == -2)
2841 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2842 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
2843 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2844 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
2846 else if (einfo->info->strip == strip_all
2847 || (einfo->info->strip == strip_some
2848 && bfd_hash_lookup (einfo->info->keep_hash,
2849 h->root.root.root.string,
2850 FALSE, FALSE) == NULL))
2858 if (h->esym.ifd == -2)
2861 h->esym.cobol_main = 0;
2862 h->esym.weakext = 0;
2863 h->esym.reserved = 0;
2864 h->esym.ifd = ifdNil;
2865 h->esym.asym.value = 0;
2866 h->esym.asym.st = stGlobal;
2868 if (h->root.root.type != bfd_link_hash_defined
2869 && h->root.root.type != bfd_link_hash_defweak)
2870 h->esym.asym.sc = scAbs;
2875 sec = h->root.root.u.def.section;
2876 output_section = sec->output_section;
2878 /* When making a shared library and symbol h is the one from
2879 the another shared library, OUTPUT_SECTION may be null. */
2880 if (output_section == NULL)
2881 h->esym.asym.sc = scUndefined;
2884 name = bfd_section_name (output_section->owner, output_section);
2886 if (strcmp (name, ".text") == 0)
2887 h->esym.asym.sc = scText;
2888 else if (strcmp (name, ".data") == 0)
2889 h->esym.asym.sc = scData;
2890 else if (strcmp (name, ".sdata") == 0)
2891 h->esym.asym.sc = scSData;
2892 else if (strcmp (name, ".rodata") == 0
2893 || strcmp (name, ".rdata") == 0)
2894 h->esym.asym.sc = scRData;
2895 else if (strcmp (name, ".bss") == 0)
2896 h->esym.asym.sc = scBss;
2897 else if (strcmp (name, ".sbss") == 0)
2898 h->esym.asym.sc = scSBss;
2899 else if (strcmp (name, ".init") == 0)
2900 h->esym.asym.sc = scInit;
2901 else if (strcmp (name, ".fini") == 0)
2902 h->esym.asym.sc = scFini;
2904 h->esym.asym.sc = scAbs;
2908 h->esym.asym.reserved = 0;
2909 h->esym.asym.index = indexNil;
2912 if (h->root.root.type == bfd_link_hash_common)
2913 h->esym.asym.value = h->root.root.u.c.size;
2914 else if (h->root.root.type == bfd_link_hash_defined
2915 || h->root.root.type == bfd_link_hash_defweak)
2917 if (h->esym.asym.sc == scCommon)
2918 h->esym.asym.sc = scBss;
2919 else if (h->esym.asym.sc == scSCommon)
2920 h->esym.asym.sc = scSBss;
2922 sec = h->root.root.u.def.section;
2923 output_section = sec->output_section;
2924 if (output_section != NULL)
2925 h->esym.asym.value = (h->root.root.u.def.value
2926 + sec->output_offset
2927 + output_section->vma);
2929 h->esym.asym.value = 0;
2931 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2933 /* Set type and value for a symbol with a function stub. */
2934 h->esym.asym.st = stProc;
2935 sec = bfd_get_section_by_name (einfo->abfd, ".plt");
2937 h->esym.asym.value = 0;
2940 output_section = sec->output_section;
2941 if (output_section != NULL)
2942 h->esym.asym.value = (h->root.plt.offset
2943 + sec->output_offset
2944 + output_section->vma);
2946 h->esym.asym.value = 0;
2950 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
2951 h->root.root.root.string,
2954 einfo->failed = TRUE;
2961 /* Search for and possibly create a got entry. */
2963 static struct alpha_elf_got_entry *
2964 get_got_entry (abfd, h, r_type, r_symndx, r_addend)
2966 struct alpha_elf_link_hash_entry *h;
2967 unsigned long r_type, r_symndx;
2970 struct alpha_elf_got_entry *gotent;
2971 struct alpha_elf_got_entry **slot;
2974 slot = &h->got_entries;
2977 /* This is a local .got entry -- record for merge. */
2979 struct alpha_elf_got_entry **local_got_entries;
2981 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
2982 if (!local_got_entries)
2985 Elf_Internal_Shdr *symtab_hdr;
2987 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
2988 size = symtab_hdr->sh_info;
2989 size *= sizeof (struct alpha_elf_got_entry *);
2992 = (struct alpha_elf_got_entry **) bfd_zalloc (abfd, size);
2993 if (!local_got_entries)
2996 alpha_elf_tdata (abfd)->local_got_entries = local_got_entries;
2999 slot = &local_got_entries[r_symndx];
3002 for (gotent = *slot; gotent ; gotent = gotent->next)
3003 if (gotent->gotobj == abfd
3004 && gotent->reloc_type == r_type
3005 && gotent->addend == r_addend)
3013 amt = sizeof (struct alpha_elf_got_entry);
3014 gotent = (struct alpha_elf_got_entry *) bfd_alloc (abfd, amt);
3018 gotent->gotobj = abfd;
3019 gotent->addend = r_addend;
3020 gotent->got_offset = -1;
3021 gotent->use_count = 1;
3022 gotent->reloc_type = r_type;
3023 gotent->reloc_done = 0;
3024 gotent->reloc_xlated = 0;
3026 gotent->next = *slot;
3029 entry_size = alpha_got_entry_size (r_type);
3030 alpha_elf_tdata (abfd)->total_got_size += entry_size;
3032 alpha_elf_tdata(abfd)->local_got_size += entry_size;
3035 gotent->use_count += 1;
3040 /* Handle dynamic relocations when doing an Alpha ELF link. */
3043 elf64_alpha_check_relocs (abfd, info, sec, relocs)
3045 struct bfd_link_info *info;
3047 const Elf_Internal_Rela *relocs;
3051 const char *rel_sec_name;
3052 Elf_Internal_Shdr *symtab_hdr;
3053 struct alpha_elf_link_hash_entry **sym_hashes;
3054 const Elf_Internal_Rela *rel, *relend;
3055 bfd_boolean got_created;
3058 if (info->relocateable)
3061 dynobj = elf_hash_table(info)->dynobj;
3063 elf_hash_table(info)->dynobj = dynobj = abfd;
3066 rel_sec_name = NULL;
3067 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
3068 sym_hashes = alpha_elf_sym_hashes(abfd);
3069 got_created = FALSE;
3071 relend = relocs + sec->reloc_count;
3072 for (rel = relocs; rel < relend; ++rel)
3080 unsigned long r_symndx, r_type;
3081 struct alpha_elf_link_hash_entry *h;
3082 unsigned int gotent_flags;
3083 bfd_boolean maybe_dynamic;
3087 r_symndx = ELF64_R_SYM (rel->r_info);
3088 if (r_symndx < symtab_hdr->sh_info)
3092 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3094 while (h->root.root.type == bfd_link_hash_indirect
3095 || h->root.root.type == bfd_link_hash_warning)
3096 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3098 h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
3101 /* We can only get preliminary data on whether a symbol is
3102 locally or externally defined, as not all of the input files
3103 have yet been processed. Do something with what we know, as
3104 this may help reduce memory usage and processing time later. */
3105 maybe_dynamic = FALSE;
3106 if (h && ((info->shared
3107 && (!info->symbolic || info->allow_shlib_undefined))
3108 || ! (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
3109 || h->root.root.type == bfd_link_hash_defweak))
3110 maybe_dynamic = TRUE;
3114 r_type = ELF64_R_TYPE (rel->r_info);
3115 addend = rel->r_addend;
3119 case R_ALPHA_LITERAL:
3120 need = NEED_GOT | NEED_GOT_ENTRY;
3122 /* Remember how this literal is used from its LITUSEs.
3123 This will be important when it comes to decide if we can
3124 create a .plt entry for a function symbol. */
3125 while (++rel < relend && ELF64_R_TYPE (rel->r_info) == R_ALPHA_LITUSE)
3126 if (rel->r_addend >= 1 && rel->r_addend <= 5)
3127 gotent_flags |= 1 << rel->r_addend;
3130 /* No LITUSEs -- presumably the address is used somehow. */
3131 if (gotent_flags == 0)
3132 gotent_flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
3135 case R_ALPHA_GPDISP:
3136 case R_ALPHA_GPREL16:
3137 case R_ALPHA_GPREL32:
3138 case R_ALPHA_GPRELHIGH:
3139 case R_ALPHA_GPRELLOW:
3144 case R_ALPHA_REFLONG:
3145 case R_ALPHA_REFQUAD:
3146 if ((info->shared && (sec->flags & SEC_ALLOC)) || maybe_dynamic)
3150 case R_ALPHA_TLSLDM:
3151 /* The symbol for a TLSLDM reloc is ignored. Collapse the
3152 reloc to the 0 symbol so that they all match. */
3155 maybe_dynamic = FALSE;
3159 case R_ALPHA_GOTDTPREL:
3160 need = NEED_GOT | NEED_GOT_ENTRY;
3163 case R_ALPHA_GOTTPREL:
3164 need = NEED_GOT | NEED_GOT_ENTRY;
3165 gotent_flags = ALPHA_ELF_LINK_HASH_TLS_IE;
3167 info->flags |= DF_STATIC_TLS;
3170 case R_ALPHA_TPREL64:
3171 if (info->shared || maybe_dynamic)
3174 info->flags |= DF_STATIC_TLS;
3178 if (need & NEED_GOT)
3182 if (!elf64_alpha_create_got_section (abfd, info))
3185 /* Make sure the object's gotobj is set to itself so
3186 that we default to every object with its own .got.
3187 We'll merge .gots later once we've collected each
3189 alpha_elf_tdata(abfd)->gotobj = abfd;
3195 if (need & NEED_GOT_ENTRY)
3197 struct alpha_elf_got_entry *gotent;
3199 gotent = get_got_entry (abfd, h, r_type, r_symndx, addend);
3205 gotent->flags |= gotent_flags;
3208 gotent_flags |= h->flags;
3209 h->flags = gotent_flags;
3211 /* Make a guess as to whether a .plt entry is needed. */
3212 if ((gotent_flags & ALPHA_ELF_LINK_HASH_LU_FUNC)
3213 && !(gotent_flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC))
3214 h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3216 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3221 if (need & NEED_DYNREL)
3223 if (rel_sec_name == NULL)
3225 rel_sec_name = (bfd_elf_string_from_elf_section
3226 (abfd, elf_elfheader(abfd)->e_shstrndx,
3227 elf_section_data(sec)->rel_hdr.sh_name));
3228 if (rel_sec_name == NULL)
3231 BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0
3232 && strcmp (bfd_get_section_name (abfd, sec),
3233 rel_sec_name+5) == 0);
3236 /* We need to create the section here now whether we eventually
3237 use it or not so that it gets mapped to an output section by
3238 the linker. If not used, we'll kill it in
3239 size_dynamic_sections. */
3242 sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
3247 sreloc = bfd_make_section (dynobj, rel_sec_name);
3248 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY
3249 | SEC_LINKER_CREATED | SEC_READONLY);
3250 if (sec->flags & SEC_ALLOC)
3251 flags |= SEC_ALLOC | SEC_LOAD;
3253 || !bfd_set_section_flags (dynobj, sreloc, flags)
3254 || !bfd_set_section_alignment (dynobj, sreloc, 3))
3261 /* Since we havn't seen all of the input symbols yet, we
3262 don't know whether we'll actually need a dynamic relocation
3263 entry for this reloc. So make a record of it. Once we
3264 find out if this thing needs dynamic relocation we'll
3265 expand the relocation sections by the appropriate amount. */
3267 struct alpha_elf_reloc_entry *rent;
3269 for (rent = h->reloc_entries; rent; rent = rent->next)
3270 if (rent->rtype == r_type && rent->srel == sreloc)
3275 amt = sizeof (struct alpha_elf_reloc_entry);
3276 rent = (struct alpha_elf_reloc_entry *) bfd_alloc (abfd, amt);
3280 rent->srel = sreloc;
3281 rent->rtype = r_type;
3283 rent->reltext = ((sec->flags & (SEC_READONLY | SEC_ALLOC))
3284 == (SEC_READONLY | SEC_ALLOC));
3286 rent->next = h->reloc_entries;
3287 h->reloc_entries = rent;
3292 else if (info->shared)
3294 /* If this is a shared library, and the section is to be
3295 loaded into memory, we need a RELATIVE reloc. */
3296 sreloc->_raw_size += sizeof (Elf64_External_Rela);
3297 if ((sec->flags & (SEC_READONLY | SEC_ALLOC))
3298 == (SEC_READONLY | SEC_ALLOC))
3299 info->flags |= DF_TEXTREL;
3307 /* Adjust a symbol defined by a dynamic object and referenced by a
3308 regular object. The current definition is in some section of the
3309 dynamic object, but we're not including those sections. We have to
3310 change the definition to something the rest of the link can
3314 elf64_alpha_adjust_dynamic_symbol (info, h)
3315 struct bfd_link_info *info;
3316 struct elf_link_hash_entry *h;
3320 struct alpha_elf_link_hash_entry *ah;
3322 dynobj = elf_hash_table(info)->dynobj;
3323 ah = (struct alpha_elf_link_hash_entry *)h;
3325 /* Now that we've seen all of the input symbols, finalize our decision
3326 about whether this symbol should get a .plt entry. */
3328 if (alpha_elf_dynamic_symbol_p (h, info)
3329 && ((h->type == STT_FUNC
3330 && !(ah->flags & ALPHA_ELF_LINK_HASH_LU_ADDR))
3331 || (h->type == STT_NOTYPE
3332 && (ah->flags & ALPHA_ELF_LINK_HASH_LU_FUNC)
3333 && !(ah->flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC)))
3334 /* Don't prevent otherwise valid programs from linking by attempting
3335 to create a new .got entry somewhere. A Correct Solution would be
3336 to add a new .got section to a new object file and let it be merged
3337 somewhere later. But for now don't bother. */
3340 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3342 s = bfd_get_section_by_name(dynobj, ".plt");
3343 if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info))
3346 /* The first bit of the .plt is reserved. */
3347 if (s->_raw_size == 0)
3348 s->_raw_size = PLT_HEADER_SIZE;
3350 h->plt.offset = s->_raw_size;
3351 s->_raw_size += PLT_ENTRY_SIZE;
3353 /* If this symbol is not defined in a regular file, and we are not
3354 generating a shared library, then set the symbol to the location
3355 in the .plt. This is required to make function pointers compare
3356 equal between the normal executable and the shared library. */
3358 && h->root.type != bfd_link_hash_defweak)
3360 ah->plt_old_section = h->root.u.def.section;
3361 ah->plt_old_value = h->root.u.def.value;
3362 ah->flags |= ALPHA_ELF_LINK_HASH_PLT_LOC;
3363 h->root.u.def.section = s;
3364 h->root.u.def.value = h->plt.offset;
3367 /* We also need a JMP_SLOT entry in the .rela.plt section. */
3368 s = bfd_get_section_by_name (dynobj, ".rela.plt");
3369 BFD_ASSERT (s != NULL);
3370 s->_raw_size += sizeof (Elf64_External_Rela);
3375 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3377 /* If this is a weak symbol, and there is a real definition, the
3378 processor independent code will have arranged for us to see the
3379 real definition first, and we can just use the same value. */
3380 if (h->weakdef != NULL)
3382 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3383 || h->weakdef->root.type == bfd_link_hash_defweak);
3384 h->root.u.def.section = h->weakdef->root.u.def.section;
3385 h->root.u.def.value = h->weakdef->root.u.def.value;
3389 /* This is a reference to a symbol defined by a dynamic object which
3390 is not a function. The Alpha, since it uses .got entries for all
3391 symbols even in regular objects, does not need the hackery of a
3392 .dynbss section and COPY dynamic relocations. */
3397 /* Symbol versioning can create new symbols, and make our old symbols
3398 indirect to the new ones. Consolidate the got and reloc information
3399 in these situations. */
3402 elf64_alpha_merge_ind_symbols (hi, dummy)
3403 struct alpha_elf_link_hash_entry *hi;
3404 PTR dummy ATTRIBUTE_UNUSED;
3406 struct alpha_elf_link_hash_entry *hs;
3408 if (hi->root.root.type != bfd_link_hash_indirect)
3412 hs = (struct alpha_elf_link_hash_entry *)hs->root.root.u.i.link;
3413 } while (hs->root.root.type == bfd_link_hash_indirect);
3415 /* Merge the flags. Whee. */
3417 hs->flags |= hi->flags;
3419 /* Merge the .got entries. Cannibalize the old symbol's list in
3420 doing so, since we don't need it anymore. */
3422 if (hs->got_entries == NULL)
3423 hs->got_entries = hi->got_entries;
3426 struct alpha_elf_got_entry *gi, *gs, *gin, *gsh;
3428 gsh = hs->got_entries;
3429 for (gi = hi->got_entries; gi ; gi = gin)
3432 for (gs = gsh; gs ; gs = gs->next)
3433 if (gi->gotobj == gs->gotobj
3434 && gi->reloc_type == gs->reloc_type
3435 && gi->addend == gs->addend)
3437 gi->use_count += gs->use_count;
3440 gi->next = hs->got_entries;
3441 hs->got_entries = gi;
3445 hi->got_entries = NULL;
3447 /* And similar for the reloc entries. */
3449 if (hs->reloc_entries == NULL)
3450 hs->reloc_entries = hi->reloc_entries;
3453 struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh;
3455 rsh = hs->reloc_entries;
3456 for (ri = hi->reloc_entries; ri ; ri = rin)
3459 for (rs = rsh; rs ; rs = rs->next)
3460 if (ri->rtype == rs->rtype && ri->srel == rs->srel)
3462 rs->count += ri->count;
3465 ri->next = hs->reloc_entries;
3466 hs->reloc_entries = ri;
3470 hi->reloc_entries = NULL;
3475 /* Is it possible to merge two object file's .got tables? */
3478 elf64_alpha_can_merge_gots (a, b)
3481 int total = alpha_elf_tdata (a)->total_got_size;
3484 /* Trivial quick fallout test. */
3485 if (total + alpha_elf_tdata (b)->total_got_size <= MAX_GOT_SIZE)
3488 /* By their nature, local .got entries cannot be merged. */
3489 if ((total += alpha_elf_tdata (b)->local_got_size) > MAX_GOT_SIZE)
3492 /* Failing the common trivial comparison, we must effectively
3493 perform the merge. Not actually performing the merge means that
3494 we don't have to store undo information in case we fail. */
3495 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
3497 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub);
3498 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
3501 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
3502 for (i = 0; i < n; ++i)
3504 struct alpha_elf_got_entry *ae, *be;
3505 struct alpha_elf_link_hash_entry *h;
3508 while (h->root.root.type == bfd_link_hash_indirect
3509 || h->root.root.type == bfd_link_hash_warning)
3510 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3512 for (be = h->got_entries; be ; be = be->next)
3514 if (be->use_count == 0)
3516 if (be->gotobj != b)
3519 for (ae = h->got_entries; ae ; ae = ae->next)
3521 && ae->reloc_type == be->reloc_type
3522 && ae->addend == be->addend)
3525 total += alpha_got_entry_size (be->reloc_type);
3526 if (total > MAX_GOT_SIZE)
3536 /* Actually merge two .got tables. */
3539 elf64_alpha_merge_gots (a, b)
3542 int total = alpha_elf_tdata (a)->total_got_size;
3545 /* Remember local expansion. */
3547 int e = alpha_elf_tdata (b)->local_got_size;
3549 alpha_elf_tdata (a)->local_got_size += e;
3552 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next)
3554 struct alpha_elf_got_entry **local_got_entries;
3555 struct alpha_elf_link_hash_entry **hashes;
3556 Elf_Internal_Shdr *symtab_hdr;
3559 /* Let the local .got entries know they are part of a new subsegment. */
3560 local_got_entries = alpha_elf_tdata (bsub)->local_got_entries;
3561 if (local_got_entries)
3563 n = elf_tdata (bsub)->symtab_hdr.sh_info;
3564 for (i = 0; i < n; ++i)
3566 struct alpha_elf_got_entry *ent;
3567 for (ent = local_got_entries[i]; ent; ent = ent->next)
3572 /* Merge the global .got entries. */
3573 hashes = alpha_elf_sym_hashes (bsub);
3574 symtab_hdr = &elf_tdata (bsub)->symtab_hdr;
3576 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info;
3577 for (i = 0; i < n; ++i)
3579 struct alpha_elf_got_entry *ae, *be, **pbe, **start;
3580 struct alpha_elf_link_hash_entry *h;
3583 while (h->root.root.type == bfd_link_hash_indirect
3584 || h->root.root.type == bfd_link_hash_warning)
3585 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
3587 start = &h->got_entries;
3588 for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
3590 if (be->use_count == 0)
3595 if (be->gotobj != b)
3598 for (ae = *start; ae ; ae = ae->next)
3600 && ae->reloc_type == be->reloc_type
3601 && ae->addend == be->addend)
3603 ae->flags |= be->flags;
3604 ae->use_count += be->use_count;
3609 total += alpha_got_entry_size (be->reloc_type);
3615 alpha_elf_tdata (bsub)->gotobj = a;
3617 alpha_elf_tdata (a)->total_got_size = total;
3619 /* Merge the two in_got chains. */
3624 while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL)
3627 alpha_elf_tdata (bsub)->in_got_link_next = b;
3631 /* Calculate the offsets for the got entries. */
3634 elf64_alpha_calc_got_offsets_for_symbol (h, arg)
3635 struct alpha_elf_link_hash_entry *h;
3636 PTR arg ATTRIBUTE_UNUSED;
3638 struct alpha_elf_got_entry *gotent;
3640 if (h->root.root.type == bfd_link_hash_warning)
3641 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
3643 for (gotent = h->got_entries; gotent; gotent = gotent->next)
3644 if (gotent->use_count > 0)
3647 = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
3649 gotent->got_offset = *plge;
3650 *plge += alpha_got_entry_size (gotent->reloc_type);
3657 elf64_alpha_calc_got_offsets (info)
3658 struct bfd_link_info *info;
3660 bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
3662 /* First, zero out the .got sizes, as we may be recalculating the
3663 .got after optimizing it. */
3664 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
3665 alpha_elf_tdata(i)->got->_raw_size = 0;
3667 /* Next, fill in the offsets for all the global entries. */
3668 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3669 elf64_alpha_calc_got_offsets_for_symbol,
3672 /* Finally, fill in the offsets for the local entries. */
3673 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
3675 bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
3678 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
3680 struct alpha_elf_got_entry **local_got_entries, *gotent;
3683 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
3684 if (!local_got_entries)
3687 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
3688 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
3689 if (gotent->use_count > 0)
3691 gotent->got_offset = got_offset;
3692 got_offset += alpha_got_entry_size (gotent->reloc_type);
3696 alpha_elf_tdata(i)->got->_raw_size = got_offset;
3697 alpha_elf_tdata(i)->got->_cooked_size = got_offset;
3701 /* Constructs the gots. */
3704 elf64_alpha_size_got_sections (info)
3705 struct bfd_link_info *info;
3707 bfd *i, *got_list, *cur_got_obj = NULL;
3708 int something_changed = 0;
3710 got_list = alpha_elf_hash_table (info)->got_list;
3712 /* On the first time through, pretend we have an existing got list
3713 consisting of all of the input files. */
3714 if (got_list == NULL)
3716 for (i = info->input_bfds; i ; i = i->link_next)
3718 bfd *this_got = alpha_elf_tdata (i)->gotobj;
3719 if (this_got == NULL)
3722 /* We are assuming no merging has yet ocurred. */
3723 BFD_ASSERT (this_got == i);
3725 if (alpha_elf_tdata (this_got)->total_got_size > MAX_GOT_SIZE)
3727 /* Yikes! A single object file has too many entries. */
3728 (*_bfd_error_handler)
3729 (_("%s: .got subsegment exceeds 64K (size %d)"),
3730 bfd_archive_filename (i),
3731 alpha_elf_tdata (this_got)->total_got_size);
3735 if (got_list == NULL)
3736 got_list = this_got;
3738 alpha_elf_tdata(cur_got_obj)->got_link_next = this_got;
3739 cur_got_obj = this_got;
3742 /* Strange degenerate case of no got references. */
3743 if (got_list == NULL)
3746 alpha_elf_hash_table (info)->got_list = got_list;
3748 /* Force got offsets to be recalculated. */
3749 something_changed = 1;
3752 cur_got_obj = got_list;
3753 i = alpha_elf_tdata(cur_got_obj)->got_link_next;
3756 if (elf64_alpha_can_merge_gots (cur_got_obj, i))
3758 elf64_alpha_merge_gots (cur_got_obj, i);
3759 i = alpha_elf_tdata(i)->got_link_next;
3760 alpha_elf_tdata(cur_got_obj)->got_link_next = i;
3761 something_changed = 1;
3766 i = alpha_elf_tdata(i)->got_link_next;
3770 /* Once the gots have been merged, fill in the got offsets for
3771 everything therein. */
3772 if (1 || something_changed)
3773 elf64_alpha_calc_got_offsets (info);
3778 /* Called from relax_section to rebuild the PLT in light of
3779 potential changes in the function's status. */
3782 elf64_alpha_size_plt_section (info)
3783 struct bfd_link_info *info;
3785 asection *splt, *spltrel;
3786 unsigned long entries;
3789 dynobj = elf_hash_table(info)->dynobj;
3790 splt = bfd_get_section_by_name(dynobj, ".plt");
3794 splt->_raw_size = 0;
3796 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3797 elf64_alpha_size_plt_section_1, splt);
3799 splt->_cooked_size = splt->_raw_size;
3801 /* Every plt entry requires a JMP_SLOT relocation. */
3802 spltrel = bfd_get_section_by_name (dynobj, ".rela.plt");
3803 if (splt->_raw_size)
3804 entries = (splt->_raw_size - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
3807 spltrel->_raw_size = entries * sizeof (Elf64_External_Rela);
3808 spltrel->_cooked_size = spltrel->_raw_size;
3814 elf64_alpha_size_plt_section_1 (h, data)
3815 struct alpha_elf_link_hash_entry *h;
3818 asection *splt = (asection *) data;
3819 struct alpha_elf_got_entry *gotent;
3821 /* If we didn't need an entry before, we still don't. */
3822 if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT))
3825 /* There must still be a LITERAL got entry for the function. */
3826 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
3827 if (gotent->reloc_type == R_ALPHA_LITERAL
3828 && gotent->use_count > 0)
3831 /* If there is, reset the PLT offset. If not, there's no longer
3832 a need for the PLT entry. */
3835 if (splt->_raw_size == 0)
3836 splt->_raw_size = PLT_HEADER_SIZE;
3837 h->root.plt.offset = splt->_raw_size;
3838 splt->_raw_size += PLT_ENTRY_SIZE;
3842 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3843 h->root.plt.offset = -1;
3845 /* Undo the definition frobbing begun in adjust_dynamic_symbol. */
3846 if (h->flags & ALPHA_ELF_LINK_HASH_PLT_LOC)
3848 h->root.root.u.def.section = h->plt_old_section;
3849 h->root.root.u.def.value = h->plt_old_value;
3850 h->flags &= ~ALPHA_ELF_LINK_HASH_PLT_LOC;
3858 elf64_alpha_always_size_sections (output_bfd, info)
3859 bfd *output_bfd ATTRIBUTE_UNUSED;
3860 struct bfd_link_info *info;
3864 if (info->relocateable)
3867 /* First, take care of the indirect symbols created by versioning. */
3868 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
3869 elf64_alpha_merge_ind_symbols,
3872 if (!elf64_alpha_size_got_sections (info))
3875 /* Allocate space for all of the .got subsections. */
3876 i = alpha_elf_hash_table (info)->got_list;
3877 for ( ; i ; i = alpha_elf_tdata(i)->got_link_next)
3879 asection *s = alpha_elf_tdata(i)->got;
3880 if (s->_raw_size > 0)
3882 s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
3883 if (s->contents == NULL)
3891 /* The number of dynamic relocations required by a static relocation. */
3894 alpha_dynamic_entries_for_reloc (r_type, dynamic, shared)
3895 int r_type, dynamic, shared;
3899 /* May appear in GOT entries. */
3901 return (dynamic ? 2 : shared ? 1 : 0);
3902 case R_ALPHA_TLSLDM:
3904 case R_ALPHA_LITERAL:
3905 case R_ALPHA_GOTTPREL:
3906 return dynamic || shared;
3907 case R_ALPHA_GOTDTPREL:
3910 /* May appear in data sections. */
3911 case R_ALPHA_REFLONG:
3912 case R_ALPHA_REFQUAD:
3913 case R_ALPHA_TPREL64:
3914 return dynamic || shared;
3916 /* Everything else is illegal. We'll issue an error during
3917 relocate_section. */
3923 /* Work out the sizes of the dynamic relocation entries. */
3926 elf64_alpha_calc_dynrel_sizes (h, info)
3927 struct alpha_elf_link_hash_entry *h;
3928 struct bfd_link_info *info;
3930 bfd_boolean dynamic;
3931 struct alpha_elf_reloc_entry *relent;
3932 unsigned long entries;
3934 if (h->root.root.type == bfd_link_hash_warning)
3935 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
3937 /* If the symbol was defined as a common symbol in a regular object
3938 file, and there was no definition in any dynamic object, then the
3939 linker will have allocated space for the symbol in a common
3940 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3941 set. This is done for dynamic symbols in
3942 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3943 symbols, somehow. */
3944 if (((h->root.elf_link_hash_flags
3945 & (ELF_LINK_HASH_DEF_REGULAR
3946 | ELF_LINK_HASH_REF_REGULAR
3947 | ELF_LINK_HASH_DEF_DYNAMIC))
3948 == ELF_LINK_HASH_REF_REGULAR)
3949 && (h->root.root.type == bfd_link_hash_defined
3950 || h->root.root.type == bfd_link_hash_defweak)
3951 && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
3952 h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3954 /* If the symbol is dynamic, we'll need all the relocations in their
3955 natural form. If this is a shared object, and it has been forced
3956 local, we'll need the same number of RELATIVE relocations. */
3958 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info);
3960 for (relent = h->reloc_entries; relent; relent = relent->next)
3962 entries = alpha_dynamic_entries_for_reloc (relent->rtype, dynamic,
3966 relent->srel->_raw_size +=
3967 entries * sizeof (Elf64_External_Rela) * relent->count;
3968 if (relent->reltext)
3969 info->flags |= DT_TEXTREL;
3976 /* Set the sizes of the dynamic relocation sections. */
3979 elf64_alpha_size_rela_got_section (info)
3980 struct bfd_link_info *info;
3982 unsigned long entries;
3986 /* Shared libraries often require RELATIVE relocs, and some relocs
3987 require attention for the main application as well. */
3990 for (i = alpha_elf_hash_table(info)->got_list;
3991 i ; i = alpha_elf_tdata(i)->got_link_next)
3995 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
3997 struct alpha_elf_got_entry **local_got_entries, *gotent;
4000 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
4001 if (!local_got_entries)
4004 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
4005 for (gotent = local_got_entries[k];
4006 gotent ; gotent = gotent->next)
4007 if (gotent->use_count > 0)
4008 entries += (alpha_dynamic_entries_for_reloc
4009 (gotent->reloc_type, 0, info->shared));
4013 dynobj = elf_hash_table(info)->dynobj;
4014 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4017 BFD_ASSERT (entries == 0);
4020 srel->_raw_size = sizeof (Elf64_External_Rela) * entries;
4022 /* Now do the non-local symbols. */
4023 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
4024 elf64_alpha_size_rela_got_1, info);
4026 srel->_cooked_size = srel->_raw_size;
4031 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
4035 elf64_alpha_size_rela_got_1 (h, info)
4036 struct alpha_elf_link_hash_entry *h;
4037 struct bfd_link_info *info;
4039 bfd_boolean dynamic;
4040 struct alpha_elf_got_entry *gotent;
4041 unsigned long entries;
4043 if (h->root.root.type == bfd_link_hash_warning)
4044 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link;
4046 /* If the symbol is dynamic, we'll need all the relocations in their
4047 natural form. If this is a shared object, and it has been forced
4048 local, we'll need the same number of RELATIVE relocations. */
4050 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info);
4053 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
4054 if (gotent->use_count > 0)
4055 entries += alpha_dynamic_entries_for_reloc (gotent->reloc_type,
4056 dynamic, info->shared);
4058 /* If we are using a .plt entry, subtract one, as the first
4059 reference uses a .rela.plt entry instead. */
4060 if (h->root.plt.offset != MINUS_ONE)
4065 bfd *dynobj = elf_hash_table(info)->dynobj;
4066 asection *srel = bfd_get_section_by_name (dynobj, ".rela.got");
4067 BFD_ASSERT (srel != NULL);
4068 srel->_raw_size += sizeof (Elf64_External_Rela) * entries;
4074 /* Set the sizes of the dynamic sections. */
4077 elf64_alpha_size_dynamic_sections (output_bfd, info)
4078 bfd *output_bfd ATTRIBUTE_UNUSED;
4079 struct bfd_link_info *info;
4085 dynobj = elf_hash_table(info)->dynobj;
4086 BFD_ASSERT(dynobj != NULL);
4088 if (elf_hash_table (info)->dynamic_sections_created)
4090 /* Set the contents of the .interp section to the interpreter. */
4093 s = bfd_get_section_by_name (dynobj, ".interp");
4094 BFD_ASSERT (s != NULL);
4095 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4096 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4099 /* Now that we've seen all of the input files, we can decide which
4100 symbols need dynamic relocation entries and which don't. We've
4101 collected information in check_relocs that we can now apply to
4102 size the dynamic relocation sections. */
4103 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
4104 elf64_alpha_calc_dynrel_sizes, info);
4106 elf64_alpha_size_rela_got_section (info);
4108 /* else we're not dynamic and by definition we don't need such things. */
4110 /* The check_relocs and adjust_dynamic_symbol entry points have
4111 determined the sizes of the various dynamic sections. Allocate
4114 for (s = dynobj->sections; s != NULL; s = s->next)
4119 if (!(s->flags & SEC_LINKER_CREATED))
4122 /* It's OK to base decisions on the section name, because none
4123 of the dynobj section names depend upon the input files. */
4124 name = bfd_get_section_name (dynobj, s);
4126 /* If we don't need this section, strip it from the output file.
4127 This is to handle .rela.bss and .rela.plt. We must create it
4128 in create_dynamic_sections, because it must be created before
4129 the linker maps input sections to output sections. The
4130 linker does that before adjust_dynamic_symbol is called, and
4131 it is that function which decides whether anything needs to
4132 go into these sections. */
4136 if (strncmp (name, ".rela", 5) == 0)
4138 strip = (s->_raw_size == 0);
4142 if (strcmp(name, ".rela.plt") == 0)
4145 /* We use the reloc_count field as a counter if we need
4146 to copy relocs into the output file. */
4150 else if (strcmp (name, ".plt") != 0)
4152 /* It's not one of our dynamic sections, so don't allocate space. */
4157 _bfd_strip_section_from_output (info, s);
4160 /* Allocate memory for the section contents. */
4161 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4162 if (s->contents == NULL && s->_raw_size != 0)
4167 if (elf_hash_table (info)->dynamic_sections_created)
4169 /* Add some entries to the .dynamic section. We fill in the
4170 values later, in elf64_alpha_finish_dynamic_sections, but we
4171 must add the entries now so that we get the correct size for
4172 the .dynamic section. The DT_DEBUG entry is filled in by the
4173 dynamic linker and used by the debugger. */
4174 #define add_dynamic_entry(TAG, VAL) \
4175 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4179 if (!add_dynamic_entry (DT_DEBUG, 0))
4185 if (!add_dynamic_entry (DT_PLTGOT, 0)
4186 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4187 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4188 || !add_dynamic_entry (DT_JMPREL, 0))
4192 if (!add_dynamic_entry (DT_RELA, 0)
4193 || !add_dynamic_entry (DT_RELASZ, 0)
4194 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
4197 if (info->flags & DF_TEXTREL)
4199 if (!add_dynamic_entry (DT_TEXTREL, 0))
4203 #undef add_dynamic_entry
4208 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
4209 into the next available slot in SREL. */
4212 elf64_alpha_emit_dynrel (abfd, info, sec, srel, offset, dynindx, rtype, addend)
4214 struct bfd_link_info *info;
4215 asection *sec, *srel;
4216 bfd_vma offset, addend;
4217 long dynindx, rtype;
4219 Elf_Internal_Rela outrel;
4222 BFD_ASSERT (srel != NULL);
4224 outrel.r_info = ELF64_R_INFO (dynindx, rtype);
4225 outrel.r_addend = addend;
4227 offset = _bfd_elf_section_offset (abfd, info, sec, offset);
4228 if ((offset | 1) != (bfd_vma) -1)
4229 outrel.r_offset = sec->output_section->vma + sec->output_offset + offset;
4231 memset (&outrel, 0, sizeof (outrel));
4233 loc = srel->contents;
4234 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
4235 bfd_elf64_swap_reloca_out (abfd, &outrel, loc);
4236 BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count
4237 <= srel->_cooked_size);
4240 /* Relocate an Alpha ELF section for a relocatable link.
4242 We don't have to change anything unless the reloc is against a section
4243 symbol, in which case we have to adjust according to where the section
4244 symbol winds up in the output section. */
4247 elf64_alpha_relocate_section_r (output_bfd, info, input_bfd, input_section,
4248 contents, relocs, local_syms, local_sections)
4249 bfd *output_bfd ATTRIBUTE_UNUSED;
4250 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4252 asection *input_section;
4253 bfd_byte *contents ATTRIBUTE_UNUSED;
4254 Elf_Internal_Rela *relocs;
4255 Elf_Internal_Sym *local_syms;
4256 asection **local_sections;
4258 unsigned long symtab_hdr_sh_info;
4259 Elf_Internal_Rela *rel;
4260 Elf_Internal_Rela *relend;
4261 bfd_boolean ret_val = TRUE;
4263 symtab_hdr_sh_info = elf_tdata (input_bfd)->symtab_hdr.sh_info;
4265 relend = relocs + input_section->reloc_count;
4266 for (rel = relocs; rel < relend; rel++)
4268 unsigned long r_symndx;
4269 Elf_Internal_Sym *sym;
4271 unsigned long r_type;
4273 r_type = ELF64_R_TYPE(rel->r_info);
4274 if (r_type >= R_ALPHA_max)
4276 (*_bfd_error_handler)
4277 (_("%s: unknown relocation type %d"),
4278 bfd_archive_filename (input_bfd), (int)r_type);
4279 bfd_set_error (bfd_error_bad_value);
4284 r_symndx = ELF64_R_SYM(rel->r_info);
4286 /* The symbol associated with GPDISP and LITUSE is
4287 immaterial. Only the addend is significant. */
4288 if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE)
4291 if (r_symndx < symtab_hdr_sh_info)
4293 sym = local_syms + r_symndx;
4294 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
4296 sec = local_sections[r_symndx];
4297 rel->r_addend += sec->output_offset + sym->st_value;
4305 /* Relocate an Alpha ELF section. */
4308 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
4309 contents, relocs, local_syms, local_sections)
4311 struct bfd_link_info *info;
4313 asection *input_section;
4315 Elf_Internal_Rela *relocs;
4316 Elf_Internal_Sym *local_syms;
4317 asection **local_sections;
4319 Elf_Internal_Shdr *symtab_hdr;
4320 Elf_Internal_Rela *rel;
4321 Elf_Internal_Rela *relend;
4322 struct elf_link_tls_segment *tls_segment;
4323 asection *sgot, *srel, *srelgot;
4324 bfd *dynobj, *gotobj;
4325 bfd_vma gp, tp_base, dtp_base;
4326 struct alpha_elf_got_entry **local_got_entries;
4327 bfd_boolean ret_val;
4328 const char *section_name;
4330 /* Handle relocatable links with a smaller loop. */
4331 if (info->relocateable)
4332 return elf64_alpha_relocate_section_r (output_bfd, info, input_bfd,
4333 input_section, contents, relocs,
4334 local_syms, local_sections);
4336 /* This is a final link. */
4340 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4342 dynobj = elf_hash_table (info)->dynobj;
4344 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
4348 section_name = (bfd_elf_string_from_elf_section
4349 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
4350 elf_section_data(input_section)->rel_hdr.sh_name));
4351 BFD_ASSERT(section_name != NULL);
4352 srel = bfd_get_section_by_name (dynobj, section_name);
4354 /* Find the gp value for this input bfd. */
4355 gotobj = alpha_elf_tdata (input_bfd)->gotobj;
4358 sgot = alpha_elf_tdata (gotobj)->got;
4359 gp = _bfd_get_gp_value (gotobj);
4362 gp = (sgot->output_section->vma
4363 + sgot->output_offset
4365 _bfd_set_gp_value (gotobj, gp);
4374 local_got_entries = alpha_elf_tdata(input_bfd)->local_got_entries;
4376 tls_segment = elf_hash_table (info)->tls_segment;
4379 dtp_base = alpha_get_dtprel_base (tls_segment);
4380 tp_base = alpha_get_tprel_base (tls_segment);
4383 dtp_base = tp_base = 0;
4385 relend = relocs + input_section->reloc_count;
4386 for (rel = relocs; rel < relend; rel++)
4388 struct alpha_elf_link_hash_entry *h = NULL;
4389 struct alpha_elf_got_entry *gotent;
4390 bfd_reloc_status_type r;
4391 reloc_howto_type *howto;
4392 unsigned long r_symndx;
4393 Elf_Internal_Sym *sym = NULL;
4394 asection *sec = NULL;
4397 bfd_boolean dynamic_symbol_p;
4398 bfd_boolean undef_weak_ref = FALSE;
4399 unsigned long r_type;
4401 r_type = ELF64_R_TYPE(rel->r_info);
4402 if (r_type >= R_ALPHA_max)
4404 (*_bfd_error_handler)
4405 (_("%s: unknown relocation type %d"),
4406 bfd_archive_filename (input_bfd), (int)r_type);
4407 bfd_set_error (bfd_error_bad_value);
4412 howto = elf64_alpha_howto_table + r_type;
4413 r_symndx = ELF64_R_SYM(rel->r_info);
4415 /* The symbol for a TLSLDM reloc is ignored. Collapse the
4416 reloc to the 0 symbol so that they all match. */
4417 if (r_type == R_ALPHA_TLSLDM)
4420 if (r_symndx < symtab_hdr->sh_info)
4422 sym = local_syms + r_symndx;
4423 sec = local_sections[r_symndx];
4424 value = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4426 /* If this is a tp-relative relocation against sym 0,
4427 this is hackery from relax_section. Force the value to
4430 && (r_type == R_ALPHA_TLSLDM
4431 || r_type == R_ALPHA_GOTTPREL
4432 || r_type == R_ALPHA_TPREL64
4433 || r_type == R_ALPHA_TPRELHI
4434 || r_type == R_ALPHA_TPRELLO
4435 || r_type == R_ALPHA_TPREL16))
4438 if (local_got_entries)
4439 gotent = local_got_entries[r_symndx];
4443 /* Need to adjust local GOT entries' addends for SEC_MERGE
4444 unless it has been done already. */
4445 if ((sec->flags & SEC_MERGE)
4446 && ELF_ST_TYPE (sym->st_info) == STT_SECTION
4447 && sec->sec_info_type == ELF_INFO_TYPE_MERGE
4449 && !gotent->reloc_xlated)
4451 struct alpha_elf_got_entry *ent;
4454 for (ent = gotent; ent; ent = ent->next)
4456 ent->reloc_xlated = 1;
4457 if (ent->use_count == 0)
4461 _bfd_merged_section_offset (output_bfd, &msec,
4462 elf_section_data (sec)->
4464 sym->st_value + ent->addend,
4466 ent->addend -= sym->st_value;
4467 ent->addend += msec->output_section->vma
4468 + msec->output_offset
4469 - sec->output_section->vma
4470 - sec->output_offset;
4474 dynamic_symbol_p = FALSE;
4478 h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info];
4480 while (h->root.root.type == bfd_link_hash_indirect
4481 || h->root.root.type == bfd_link_hash_warning)
4482 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
4485 if (h->root.root.type == bfd_link_hash_defined
4486 || h->root.root.type == bfd_link_hash_defweak)
4488 sec = h->root.root.u.def.section;
4490 /* Detect the cases that sym_sec->output_section is
4491 expected to be NULL -- all cases in which the symbol
4492 is defined in another shared module. This includes
4493 PLT relocs for which we've created a PLT entry and
4494 other relocs for which we're prepared to create
4495 dynamic relocations. */
4496 /* ??? Just accept it NULL and continue. */
4498 if (sec->output_section != NULL)
4499 value = (h->root.root.u.def.value
4500 + sec->output_section->vma
4501 + sec->output_offset);
4503 else if (h->root.root.type == bfd_link_hash_undefweak)
4504 undef_weak_ref = TRUE;
4505 else if (info->shared
4506 && !info->no_undefined
4507 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
4511 if (!((*info->callbacks->undefined_symbol)
4512 (info, h->root.root.root.string, input_bfd,
4513 input_section, rel->r_offset,
4514 (!info->shared || info->no_undefined
4515 || ELF_ST_VISIBILITY (h->root.other)))))
4520 dynamic_symbol_p = alpha_elf_dynamic_symbol_p (&h->root, info);
4521 gotent = h->got_entries;
4524 addend = rel->r_addend;
4527 /* Search for the proper got entry. */
4528 for (; gotent ; gotent = gotent->next)
4529 if (gotent->gotobj == gotobj
4530 && gotent->reloc_type == r_type
4531 && gotent->addend == addend)
4536 case R_ALPHA_GPDISP:
4538 bfd_byte *p_ldah, *p_lda;
4540 BFD_ASSERT(gp != 0);
4542 value = (input_section->output_section->vma
4543 + input_section->output_offset
4546 p_ldah = contents + rel->r_offset;
4547 p_lda = p_ldah + rel->r_addend;
4549 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - value,
4554 case R_ALPHA_LITERAL:
4555 BFD_ASSERT(sgot != NULL);
4556 BFD_ASSERT(gp != 0);
4557 BFD_ASSERT(gotent != NULL);
4558 BFD_ASSERT(gotent->use_count >= 1);
4560 if (!gotent->reloc_done)
4562 gotent->reloc_done = 1;
4564 bfd_put_64 (output_bfd, value,
4565 sgot->contents + gotent->got_offset);
4567 /* If the symbol has been forced local, output a
4568 RELATIVE reloc, otherwise it will be handled in
4569 finish_dynamic_symbol. */
4570 if (info->shared && !dynamic_symbol_p)
4571 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot,
4572 gotent->got_offset, 0,
4573 R_ALPHA_RELATIVE, value);
4576 value = (sgot->output_section->vma
4577 + sgot->output_offset
4578 + gotent->got_offset);
4582 case R_ALPHA_GPREL16:
4583 case R_ALPHA_GPREL32:
4584 case R_ALPHA_GPRELLOW:
4585 if (dynamic_symbol_p)
4587 (*_bfd_error_handler)
4588 (_("%s: gp-relative relocation against dynamic symbol %s"),
4589 bfd_archive_filename (input_bfd), h->root.root.root.string);
4592 BFD_ASSERT(gp != 0);
4596 case R_ALPHA_GPRELHIGH:
4597 if (dynamic_symbol_p)
4599 (*_bfd_error_handler)
4600 (_("%s: gp-relative relocation against dynamic symbol %s"),
4601 bfd_archive_filename (input_bfd), h->root.root.root.string);
4604 BFD_ASSERT(gp != 0);
4606 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4610 /* A call to a dynamic symbol is definitely out of range of
4611 the 16-bit displacement. Don't bother writing anything. */
4612 if (dynamic_symbol_p)
4617 /* The regular PC-relative stuff measures from the start of
4618 the instruction rather than the end. */
4622 case R_ALPHA_BRADDR:
4623 if (dynamic_symbol_p)
4625 (*_bfd_error_handler)
4626 (_("%s: pc-relative relocation against dynamic symbol %s"),
4627 bfd_archive_filename (input_bfd), h->root.root.root.string);
4630 /* The regular PC-relative stuff measures from the start of
4631 the instruction rather than the end. */
4640 /* The regular PC-relative stuff measures from the start of
4641 the instruction rather than the end. */
4644 /* The source and destination gp must be the same. Note that
4645 the source will always have an assigned gp, since we forced
4646 one in check_relocs, but that the destination may not, as
4647 it might not have had any relocations at all. Also take
4648 care not to crash if H is an undefined symbol. */
4649 if (h != NULL && sec != NULL
4650 && alpha_elf_tdata (sec->owner)->gotobj
4651 && gotobj != alpha_elf_tdata (sec->owner)->gotobj)
4653 (*_bfd_error_handler)
4654 (_("%s: change in gp: BRSGP %s"),
4655 bfd_archive_filename (input_bfd), h->root.root.root.string);
4659 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4661 other = h->root.other;
4663 other = sym->st_other;
4664 switch (other & STO_ALPHA_STD_GPLOAD)
4666 case STO_ALPHA_NOPV:
4668 case STO_ALPHA_STD_GPLOAD:
4673 name = h->root.root.root.string;
4676 name = (bfd_elf_string_from_elf_section
4677 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4679 name = _("<unknown>");
4680 else if (name[0] == 0)
4681 name = bfd_section_name (input_bfd, sec);
4683 (*_bfd_error_handler)
4684 (_("%s: !samegp reloc against symbol without .prologue: %s"),
4685 bfd_archive_filename (input_bfd), name);
4693 case R_ALPHA_REFLONG:
4694 case R_ALPHA_REFQUAD:
4695 case R_ALPHA_DTPREL64:
4696 case R_ALPHA_TPREL64:
4698 long dynindx, dyntype = r_type;
4701 /* Careful here to remember RELATIVE relocations for global
4702 variables for symbolic shared objects. */
4704 if (dynamic_symbol_p)
4706 BFD_ASSERT(h->root.dynindx != -1);
4707 dynindx = h->root.dynindx;
4709 addend = 0, value = 0;
4711 else if (r_type == R_ALPHA_DTPREL64)
4713 BFD_ASSERT(tls_segment != NULL);
4717 else if (r_type == R_ALPHA_TPREL64)
4719 BFD_ASSERT(tls_segment != NULL);
4726 dynaddend = value - dtp_base;
4728 else if (info->shared
4730 && (input_section->flags & SEC_ALLOC))
4732 if (r_type == R_ALPHA_REFLONG)
4734 (*_bfd_error_handler)
4735 (_("%s: unhandled dynamic relocation against %s"),
4736 bfd_archive_filename (input_bfd),
4737 h->root.root.root.string);
4741 dyntype = R_ALPHA_RELATIVE;
4747 elf64_alpha_emit_dynrel (output_bfd, info, input_section,
4748 srel, rel->r_offset, dynindx,
4749 dyntype, dynaddend);
4753 case R_ALPHA_SREL16:
4754 case R_ALPHA_SREL32:
4755 case R_ALPHA_SREL64:
4756 if (dynamic_symbol_p)
4758 (*_bfd_error_handler)
4759 (_("%s: pc-relative relocation against dynamic symbol %s"),
4760 bfd_archive_filename (input_bfd), h->root.root.root.string);
4764 /* ??? .eh_frame references to discarded sections will be smashed
4765 to relocations against SHN_UNDEF. The .eh_frame format allows
4766 NULL to be encoded as 0 in any format, so this works here. */
4768 howto = (elf64_alpha_howto_table
4769 + (r_type - R_ALPHA_SREL32 + R_ALPHA_REFLONG));
4772 case R_ALPHA_TLSLDM:
4773 /* Ignore the symbol for the relocation. The result is always
4774 the current module. */
4775 dynamic_symbol_p = 0;
4779 if (!gotent->reloc_done)
4781 gotent->reloc_done = 1;
4783 /* Note that the module index for the main program is 1. */
4784 bfd_put_64 (output_bfd, !info->shared && !dynamic_symbol_p,
4785 sgot->contents + gotent->got_offset);
4787 /* If the symbol has been forced local, output a
4788 DTPMOD64 reloc, otherwise it will be handled in
4789 finish_dynamic_symbol. */
4790 if (info->shared && !dynamic_symbol_p)
4791 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot,
4792 gotent->got_offset, 0,
4793 R_ALPHA_DTPMOD64, 0);
4795 if (dynamic_symbol_p || r_type == R_ALPHA_TLSLDM)
4799 BFD_ASSERT(tls_segment != NULL);
4802 bfd_put_64 (output_bfd, value,
4803 sgot->contents + gotent->got_offset + 8);
4806 value = (sgot->output_section->vma
4807 + sgot->output_offset
4808 + gotent->got_offset);
4812 case R_ALPHA_DTPRELHI:
4813 case R_ALPHA_DTPRELLO:
4814 case R_ALPHA_DTPREL16:
4815 if (dynamic_symbol_p)
4817 (*_bfd_error_handler)
4818 (_("%s: dtp-relative relocation against dynamic symbol %s"),
4819 bfd_archive_filename (input_bfd), h->root.root.root.string);
4822 BFD_ASSERT(tls_segment != NULL);
4824 if (r_type == R_ALPHA_DTPRELHI)
4825 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4828 case R_ALPHA_TPRELHI:
4829 case R_ALPHA_TPRELLO:
4830 case R_ALPHA_TPREL16:
4833 (*_bfd_error_handler)
4834 (_("%s: TLS local exec code cannot be linked into shared objects"),
4835 bfd_archive_filename (input_bfd));
4838 else if (dynamic_symbol_p)
4840 (*_bfd_error_handler)
4841 (_("%s: tp-relative relocation against dynamic symbol %s"),
4842 bfd_archive_filename (input_bfd), h->root.root.root.string);
4845 BFD_ASSERT(tls_segment != NULL);
4847 if (r_type == R_ALPHA_TPRELHI)
4848 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1);
4851 case R_ALPHA_GOTDTPREL:
4852 case R_ALPHA_GOTTPREL:
4853 BFD_ASSERT(sgot != NULL);
4854 BFD_ASSERT(gp != 0);
4855 BFD_ASSERT(gotent != NULL);
4856 BFD_ASSERT(gotent->use_count >= 1);
4858 if (!gotent->reloc_done)
4860 gotent->reloc_done = 1;
4862 if (dynamic_symbol_p)
4866 BFD_ASSERT(tls_segment != NULL);
4867 if (r_type == R_ALPHA_GOTDTPREL)
4869 else if (!info->shared)
4873 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot,
4874 gotent->got_offset, 0,
4880 bfd_put_64 (output_bfd, value,
4881 sgot->contents + gotent->got_offset);
4884 value = (sgot->output_section->vma
4885 + sgot->output_offset
4886 + gotent->got_offset);
4892 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4893 contents, rel->r_offset, value, 0);
4902 case bfd_reloc_overflow:
4906 /* Don't warn if the overflow is due to pc relative reloc
4907 against discarded section. Section optimization code should
4910 if (r_symndx < symtab_hdr->sh_info
4911 && sec != NULL && howto->pc_relative
4912 && elf_discarded_section (sec))
4916 name = h->root.root.root.string;
4919 name = (bfd_elf_string_from_elf_section
4920 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4924 name = bfd_section_name (input_bfd, sec);
4926 if (! ((*info->callbacks->reloc_overflow)
4927 (info, name, howto->name, (bfd_vma) 0,
4928 input_bfd, input_section, rel->r_offset)))
4934 case bfd_reloc_outofrange:
4942 /* Finish up dynamic symbol handling. We set the contents of various
4943 dynamic sections here. */
4946 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
4948 struct bfd_link_info *info;
4949 struct elf_link_hash_entry *h;
4950 Elf_Internal_Sym *sym;
4952 bfd *dynobj = elf_hash_table(info)->dynobj;
4954 if (h->plt.offset != MINUS_ONE)
4956 /* Fill in the .plt entry for this symbol. */
4957 asection *splt, *sgot, *srel;
4958 Elf_Internal_Rela outrel;
4960 bfd_vma got_addr, plt_addr;
4962 struct alpha_elf_got_entry *gotent;
4964 BFD_ASSERT (h->dynindx != -1);
4966 /* The first .got entry will be updated by the .plt with the
4967 address of the target function. */
4968 gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
4969 BFD_ASSERT (gotent && gotent->addend == 0);
4971 splt = bfd_get_section_by_name (dynobj, ".plt");
4972 BFD_ASSERT (splt != NULL);
4973 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4974 BFD_ASSERT (srel != NULL);
4975 sgot = alpha_elf_tdata (gotent->gotobj)->got;
4976 BFD_ASSERT (sgot != NULL);
4978 got_addr = (sgot->output_section->vma
4979 + sgot->output_offset
4980 + gotent->got_offset);
4981 plt_addr = (splt->output_section->vma
4982 + splt->output_offset
4985 plt_index = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
4987 /* Fill in the entry in the procedure linkage table. */
4989 bfd_vma insn1, insn2, insn3;
4991 insn1 = PLT_ENTRY_WORD1 | ((-(h->plt.offset + 4) >> 2) & 0x1fffff);
4992 insn2 = PLT_ENTRY_WORD2;
4993 insn3 = PLT_ENTRY_WORD3;
4995 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt.offset);
4996 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt.offset + 4);
4997 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt.offset + 8);
5000 /* Fill in the entry in the .rela.plt section. */
5001 outrel.r_offset = got_addr;
5002 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
5003 outrel.r_addend = 0;
5005 loc = srel->contents + plt_index * sizeof (Elf64_External_Rela);
5006 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5008 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
5010 /* Mark the symbol as undefined, rather than as defined in the
5011 .plt section. Leave the value alone. */
5012 sym->st_shndx = SHN_UNDEF;
5015 /* Fill in the entries in the .got. */
5016 bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
5018 /* Subsequent .got entries will continue to bounce through the .plt. */
5021 srel = bfd_get_section_by_name (dynobj, ".rela.got");
5022 BFD_ASSERT (! info->shared || srel != NULL);
5024 gotent = gotent->next;
5027 sgot = alpha_elf_tdata(gotent->gotobj)->got;
5028 BFD_ASSERT(sgot != NULL);
5029 BFD_ASSERT(gotent->addend == 0);
5031 bfd_put_64 (output_bfd, plt_addr,
5032 sgot->contents + gotent->got_offset);
5035 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel,
5036 gotent->got_offset, 0,
5037 R_ALPHA_RELATIVE, plt_addr);
5039 gotent = gotent->next;
5041 while (gotent != NULL);
5044 else if (alpha_elf_dynamic_symbol_p (h, info))
5046 /* Fill in the dynamic relocations for this symbol's .got entries. */
5048 struct alpha_elf_got_entry *gotent;
5050 srel = bfd_get_section_by_name (dynobj, ".rela.got");
5051 BFD_ASSERT (srel != NULL);
5053 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
5055 gotent = gotent->next)
5060 if (gotent->use_count == 0)
5063 sgot = alpha_elf_tdata (gotent->gotobj)->got;
5065 r_type = gotent->reloc_type;
5068 case R_ALPHA_LITERAL:
5069 r_type = R_ALPHA_GLOB_DAT;
5072 r_type = R_ALPHA_DTPMOD64;
5074 case R_ALPHA_GOTDTPREL:
5075 r_type = R_ALPHA_DTPREL64;
5077 case R_ALPHA_GOTTPREL:
5078 r_type = R_ALPHA_TPREL64;
5080 case R_ALPHA_TLSLDM:
5085 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel,
5086 gotent->got_offset, h->dynindx,
5087 r_type, gotent->addend);
5089 if (gotent->reloc_type == R_ALPHA_TLSGD)
5090 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel,
5091 gotent->got_offset + 8, h->dynindx,
5092 R_ALPHA_DTPREL64, gotent->addend);
5096 /* Mark some specially defined symbols as absolute. */
5097 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5098 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
5099 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
5100 sym->st_shndx = SHN_ABS;
5105 /* Finish up the dynamic sections. */
5108 elf64_alpha_finish_dynamic_sections (output_bfd, info)
5110 struct bfd_link_info *info;
5115 dynobj = elf_hash_table (info)->dynobj;
5116 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5118 if (elf_hash_table (info)->dynamic_sections_created)
5121 Elf64_External_Dyn *dyncon, *dynconend;
5123 splt = bfd_get_section_by_name (dynobj, ".plt");
5124 BFD_ASSERT (splt != NULL && sdyn != NULL);
5126 dyncon = (Elf64_External_Dyn *) sdyn->contents;
5127 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5128 for (; dyncon < dynconend; dyncon++)
5130 Elf_Internal_Dyn dyn;
5134 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
5149 /* My interpretation of the TIS v1.1 ELF document indicates
5150 that RELASZ should not include JMPREL. This is not what
5151 the rest of the BFD does. It is, however, what the
5152 glibc ld.so wants. Do this fixup here until we found
5153 out who is right. */
5154 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
5158 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
5163 s = bfd_get_section_by_name (output_bfd, name);
5164 dyn.d_un.d_ptr = (s ? s->vma : 0);
5168 s = bfd_get_section_by_name (output_bfd, name);
5170 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
5174 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
5177 /* Initialize the PLT0 entry. */
5178 if (splt->_raw_size > 0)
5180 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
5181 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
5182 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
5183 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
5185 /* The next two words will be filled in by ld.so */
5186 bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 16);
5187 bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 24);
5189 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 0;
5196 /* We need to use a special link routine to handle the .mdebug section.
5197 We need to merge all instances of these sections together, not write
5198 them all out sequentially. */
5201 elf64_alpha_final_link (abfd, info)
5203 struct bfd_link_info *info;
5206 struct bfd_link_order *p;
5207 asection *mdebug_sec;
5208 struct ecoff_debug_info debug;
5209 const struct ecoff_debug_swap *swap
5210 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
5211 HDRR *symhdr = &debug.symbolic_header;
5212 PTR mdebug_handle = NULL;
5214 /* Go through the sections and collect the mdebug information. */
5216 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
5218 if (strcmp (o->name, ".mdebug") == 0)
5220 struct extsym_info einfo;
5222 /* We have found the .mdebug section in the output file.
5223 Look through all the link_orders comprising it and merge
5224 the information together. */
5225 symhdr->magic = swap->sym_magic;
5226 /* FIXME: What should the version stamp be? */
5228 symhdr->ilineMax = 0;
5232 symhdr->isymMax = 0;
5233 symhdr->ioptMax = 0;
5234 symhdr->iauxMax = 0;
5236 symhdr->issExtMax = 0;
5239 symhdr->iextMax = 0;
5241 /* We accumulate the debugging information itself in the
5242 debug_info structure. */
5244 debug.external_dnr = NULL;
5245 debug.external_pdr = NULL;
5246 debug.external_sym = NULL;
5247 debug.external_opt = NULL;
5248 debug.external_aux = NULL;
5250 debug.ssext = debug.ssext_end = NULL;
5251 debug.external_fdr = NULL;
5252 debug.external_rfd = NULL;
5253 debug.external_ext = debug.external_ext_end = NULL;
5255 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
5256 if (mdebug_handle == (PTR) NULL)
5265 static const char * const name[] =
5267 ".text", ".init", ".fini", ".data",
5268 ".rodata", ".sdata", ".sbss", ".bss"
5270 static const int sc[] = { scText, scInit, scFini, scData,
5271 scRData, scSData, scSBss, scBss };
5274 esym.cobol_main = 0;
5278 esym.asym.iss = issNil;
5279 esym.asym.st = stLocal;
5280 esym.asym.reserved = 0;
5281 esym.asym.index = indexNil;
5282 for (i = 0; i < 8; i++)
5284 esym.asym.sc = sc[i];
5285 s = bfd_get_section_by_name (abfd, name[i]);
5288 esym.asym.value = s->vma;
5289 last = s->vma + s->_raw_size;
5292 esym.asym.value = last;
5294 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
5300 for (p = o->link_order_head;
5301 p != (struct bfd_link_order *) NULL;
5304 asection *input_section;
5306 const struct ecoff_debug_swap *input_swap;
5307 struct ecoff_debug_info input_debug;
5311 if (p->type != bfd_indirect_link_order)
5313 if (p->type == bfd_data_link_order)
5318 input_section = p->u.indirect.section;
5319 input_bfd = input_section->owner;
5321 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
5322 || (get_elf_backend_data (input_bfd)
5323 ->elf_backend_ecoff_debug_swap) == NULL)
5325 /* I don't know what a non ALPHA ELF bfd would be
5326 doing with a .mdebug section, but I don't really
5327 want to deal with it. */
5331 input_swap = (get_elf_backend_data (input_bfd)
5332 ->elf_backend_ecoff_debug_swap);
5334 BFD_ASSERT (p->size == input_section->_raw_size);
5336 /* The ECOFF linking code expects that we have already
5337 read in the debugging information and set up an
5338 ecoff_debug_info structure, so we do that now. */
5339 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
5343 if (! (bfd_ecoff_debug_accumulate
5344 (mdebug_handle, abfd, &debug, swap, input_bfd,
5345 &input_debug, input_swap, info)))
5348 /* Loop through the external symbols. For each one with
5349 interesting information, try to find the symbol in
5350 the linker global hash table and save the information
5351 for the output external symbols. */
5352 eraw_src = input_debug.external_ext;
5353 eraw_end = (eraw_src
5354 + (input_debug.symbolic_header.iextMax
5355 * input_swap->external_ext_size));
5357 eraw_src < eraw_end;
5358 eraw_src += input_swap->external_ext_size)
5362 struct alpha_elf_link_hash_entry *h;
5364 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
5365 if (ext.asym.sc == scNil
5366 || ext.asym.sc == scUndefined
5367 || ext.asym.sc == scSUndefined)
5370 name = input_debug.ssext + ext.asym.iss;
5371 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
5372 name, FALSE, FALSE, TRUE);
5373 if (h == NULL || h->esym.ifd != -2)
5379 < input_debug.symbolic_header.ifdMax);
5380 ext.ifd = input_debug.ifdmap[ext.ifd];
5386 /* Free up the information we just read. */
5387 free (input_debug.line);
5388 free (input_debug.external_dnr);
5389 free (input_debug.external_pdr);
5390 free (input_debug.external_sym);
5391 free (input_debug.external_opt);
5392 free (input_debug.external_aux);
5393 free (input_debug.ss);
5394 free (input_debug.ssext);
5395 free (input_debug.external_fdr);
5396 free (input_debug.external_rfd);
5397 free (input_debug.external_ext);
5399 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5400 elf_link_input_bfd ignores this section. */
5401 input_section->flags &=~ SEC_HAS_CONTENTS;
5404 /* Build the external symbol information. */
5407 einfo.debug = &debug;
5409 einfo.failed = FALSE;
5410 elf_link_hash_traverse (elf_hash_table (info),
5411 elf64_alpha_output_extsym,
5416 /* Set the size of the .mdebug section. */
5417 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
5419 /* Skip this section later on (I don't think this currently
5420 matters, but someday it might). */
5421 o->link_order_head = (struct bfd_link_order *) NULL;
5427 /* Invoke the regular ELF backend linker to do all the work. */
5428 if (! bfd_elf64_bfd_final_link (abfd, info))
5431 /* Now write out the computed sections. */
5433 /* The .got subsections... */
5435 bfd *i, *dynobj = elf_hash_table(info)->dynobj;
5436 for (i = alpha_elf_hash_table(info)->got_list;
5438 i = alpha_elf_tdata(i)->got_link_next)
5442 /* elf_bfd_final_link already did everything in dynobj. */
5446 sgot = alpha_elf_tdata(i)->got;
5447 if (! bfd_set_section_contents (abfd, sgot->output_section,
5449 (file_ptr) sgot->output_offset,
5455 if (mdebug_sec != (asection *) NULL)
5457 BFD_ASSERT (abfd->output_has_begun);
5458 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
5460 mdebug_sec->filepos))
5463 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
5469 static enum elf_reloc_type_class
5470 elf64_alpha_reloc_type_class (rela)
5471 const Elf_Internal_Rela *rela;
5473 switch ((int) ELF64_R_TYPE (rela->r_info))
5475 case R_ALPHA_RELATIVE:
5476 return reloc_class_relative;
5477 case R_ALPHA_JMP_SLOT:
5478 return reloc_class_plt;
5480 return reloc_class_copy;
5482 return reloc_class_normal;
5486 /* ECOFF swapping routines. These are used when dealing with the
5487 .mdebug section, which is in the ECOFF debugging format. Copied
5488 from elf32-mips.c. */
5489 static const struct ecoff_debug_swap
5490 elf64_alpha_ecoff_debug_swap =
5492 /* Symbol table magic number. */
5494 /* Alignment of debugging information. E.g., 4. */
5496 /* Sizes of external symbolic information. */
5497 sizeof (struct hdr_ext),
5498 sizeof (struct dnr_ext),
5499 sizeof (struct pdr_ext),
5500 sizeof (struct sym_ext),
5501 sizeof (struct opt_ext),
5502 sizeof (struct fdr_ext),
5503 sizeof (struct rfd_ext),
5504 sizeof (struct ext_ext),
5505 /* Functions to swap in external symbolic data. */
5514 _bfd_ecoff_swap_tir_in,
5515 _bfd_ecoff_swap_rndx_in,
5516 /* Functions to swap out external symbolic data. */
5525 _bfd_ecoff_swap_tir_out,
5526 _bfd_ecoff_swap_rndx_out,
5527 /* Function to read in symbolic data. */
5528 elf64_alpha_read_ecoff_info
5531 /* Use a non-standard hash bucket size of 8. */
5533 static const struct elf_size_info alpha_elf_size_info =
5535 sizeof (Elf64_External_Ehdr),
5536 sizeof (Elf64_External_Phdr),
5537 sizeof (Elf64_External_Shdr),
5538 sizeof (Elf64_External_Rel),
5539 sizeof (Elf64_External_Rela),
5540 sizeof (Elf64_External_Sym),
5541 sizeof (Elf64_External_Dyn),
5542 sizeof (Elf_External_Note),
5546 ELFCLASS64, EV_CURRENT,
5547 bfd_elf64_write_out_phdrs,
5548 bfd_elf64_write_shdrs_and_ehdr,
5549 bfd_elf64_write_relocs,
5550 bfd_elf64_swap_symbol_in,
5551 bfd_elf64_swap_symbol_out,
5552 bfd_elf64_slurp_reloc_table,
5553 bfd_elf64_slurp_symbol_table,
5554 bfd_elf64_swap_dyn_in,
5555 bfd_elf64_swap_dyn_out,
5556 bfd_elf64_swap_reloc_in,
5557 bfd_elf64_swap_reloc_out,
5558 bfd_elf64_swap_reloca_in,
5559 bfd_elf64_swap_reloca_out
5562 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5563 #define TARGET_LITTLE_NAME "elf64-alpha"
5564 #define ELF_ARCH bfd_arch_alpha
5565 #define ELF_MACHINE_CODE EM_ALPHA
5566 #define ELF_MAXPAGESIZE 0x10000
5568 #define bfd_elf64_bfd_link_hash_table_create \
5569 elf64_alpha_bfd_link_hash_table_create
5571 #define bfd_elf64_bfd_reloc_type_lookup \
5572 elf64_alpha_bfd_reloc_type_lookup
5573 #define elf_info_to_howto \
5574 elf64_alpha_info_to_howto
5576 #define bfd_elf64_mkobject \
5577 elf64_alpha_mkobject
5578 #define elf_backend_object_p \
5579 elf64_alpha_object_p
5581 #define elf_backend_section_from_shdr \
5582 elf64_alpha_section_from_shdr
5583 #define elf_backend_section_flags \
5584 elf64_alpha_section_flags
5585 #define elf_backend_fake_sections \
5586 elf64_alpha_fake_sections
5588 #define bfd_elf64_bfd_is_local_label_name \
5589 elf64_alpha_is_local_label_name
5590 #define bfd_elf64_find_nearest_line \
5591 elf64_alpha_find_nearest_line
5592 #define bfd_elf64_bfd_relax_section \
5593 elf64_alpha_relax_section
5595 #define elf_backend_add_symbol_hook \
5596 elf64_alpha_add_symbol_hook
5597 #define elf_backend_check_relocs \
5598 elf64_alpha_check_relocs
5599 #define elf_backend_create_dynamic_sections \
5600 elf64_alpha_create_dynamic_sections
5601 #define elf_backend_adjust_dynamic_symbol \
5602 elf64_alpha_adjust_dynamic_symbol
5603 #define elf_backend_always_size_sections \
5604 elf64_alpha_always_size_sections
5605 #define elf_backend_size_dynamic_sections \
5606 elf64_alpha_size_dynamic_sections
5607 #define elf_backend_relocate_section \
5608 elf64_alpha_relocate_section
5609 #define elf_backend_finish_dynamic_symbol \
5610 elf64_alpha_finish_dynamic_symbol
5611 #define elf_backend_finish_dynamic_sections \
5612 elf64_alpha_finish_dynamic_sections
5613 #define bfd_elf64_bfd_final_link \
5614 elf64_alpha_final_link
5615 #define elf_backend_reloc_type_class \
5616 elf64_alpha_reloc_type_class
5618 #define elf_backend_ecoff_debug_swap \
5619 &elf64_alpha_ecoff_debug_swap
5621 #define elf_backend_size_info \
5624 /* A few constants that determine how the .plt section is set up. */
5625 #define elf_backend_want_got_plt 0
5626 #define elf_backend_plt_readonly 0
5627 #define elf_backend_want_plt_sym 1
5628 #define elf_backend_got_header_size 0
5629 #define elf_backend_plt_header_size PLT_HEADER_SIZE
5631 #include "elf64-target.h"
5633 /* FreeBSD support. */
5635 #undef TARGET_LITTLE_SYM
5636 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5637 #undef TARGET_LITTLE_NAME
5638 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5640 /* The kernel recognizes executables as valid only if they carry a
5641 "FreeBSD" label in the ELF header. So we put this label on all
5642 executables and (for simplicity) also all other object files. */
5644 static void elf64_alpha_fbsd_post_process_headers
5645 PARAMS ((bfd *, struct bfd_link_info *));
5648 elf64_alpha_fbsd_post_process_headers (abfd, link_info)
5650 struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
5652 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
5654 i_ehdrp = elf_elfheader (abfd);
5656 /* Put an ABI label supported by FreeBSD >= 4.1. */
5657 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
5658 #ifdef OLD_FREEBSD_ABI_LABEL
5659 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5660 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8);
5664 #undef elf_backend_post_process_headers
5665 #define elf_backend_post_process_headers \
5666 elf64_alpha_fbsd_post_process_headers
5669 #define elf64_bed elf64_alpha_fbsd_bed
5671 #include "elf64-target.h"