1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Richard Henderson <rth@tamu.edu>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* We need a published ABI spec for this. Until one comes out, don't
23 assume this'll remain unchanged forever. */
30 #include "elf/alpha.h"
34 #define NO_COFF_RELOCS
35 #define NO_COFF_SYMBOLS
36 #define NO_COFF_LINENOS
38 /* Get the ECOFF swapping routines. Needed for the debug information. */
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
43 #include "coff/alpha.h"
48 #include "ecoffswap.h"
50 static bfd_boolean alpha_elf_dynamic_symbol_p
51 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
52 static struct bfd_hash_entry
* elf64_alpha_link_hash_newfunc
53 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
54 static struct bfd_link_hash_table
* elf64_alpha_bfd_link_hash_table_create
57 static bfd_reloc_status_type elf64_alpha_reloc_nil
58 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
59 static bfd_reloc_status_type elf64_alpha_reloc_bad
60 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
61 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
62 PARAMS ((bfd
*, bfd_vma
, bfd_byte
*, bfd_byte
*));
63 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
64 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
66 static reloc_howto_type
* elf64_alpha_bfd_reloc_type_lookup
67 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
68 static void elf64_alpha_info_to_howto
69 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
71 static bfd_boolean elf64_alpha_mkobject
73 static bfd_boolean elf64_alpha_object_p
75 static bfd_boolean elf64_alpha_section_from_shdr
76 PARAMS ((bfd
*, Elf_Internal_Shdr
*, const char *));
77 static bfd_boolean elf64_alpha_section_flags
78 PARAMS ((flagword
*, const 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
*, Elf_Internal_Sym
*,
127 const char **, flagword
*, asection
**, bfd_vma
*));
128 static struct alpha_elf_got_entry
*get_got_entry
129 PARAMS ((bfd
*, struct alpha_elf_link_hash_entry
*, unsigned long,
130 unsigned long, bfd_vma
));
131 static bfd_boolean elf64_alpha_check_relocs
132 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*sec
,
133 const Elf_Internal_Rela
*));
134 static bfd_boolean elf64_alpha_adjust_dynamic_symbol
135 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
136 static bfd_boolean elf64_alpha_size_dynamic_sections
137 PARAMS ((bfd
*, struct bfd_link_info
*));
138 static void elf64_alpha_emit_dynrel
139 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, asection
*,
140 bfd_vma
, long, long, bfd_vma
));
141 static bfd_boolean elf64_alpha_relocate_section_r
142 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
143 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
144 static bfd_boolean elf64_alpha_relocate_section
145 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
146 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
147 static bfd_boolean elf64_alpha_finish_dynamic_symbol
148 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
149 Elf_Internal_Sym
*));
150 static bfd_boolean elf64_alpha_finish_dynamic_sections
151 PARAMS ((bfd
*, struct bfd_link_info
*));
152 static bfd_boolean elf64_alpha_final_link
153 PARAMS ((bfd
*, struct bfd_link_info
*));
154 static bfd_boolean elf64_alpha_merge_ind_symbols
155 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
156 static Elf_Internal_Rela
* elf64_alpha_find_reloc_at_ofs
157 PARAMS ((Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_vma
, int));
158 static enum elf_reloc_type_class elf64_alpha_reloc_type_class
159 PARAMS ((const Elf_Internal_Rela
*));
161 struct alpha_elf_link_hash_entry
163 struct elf_link_hash_entry root
;
165 /* External symbol information. */
168 /* Cumulative flags for all the .got entries. */
171 /* Contexts in which a literal was referenced. */
172 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
173 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
174 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
175 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08
176 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10
177 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20
178 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x38
179 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x40
180 #define ALPHA_ELF_LINK_HASH_PLT_LOC 0x80
182 /* Used to undo the localization of a plt symbol. */
183 asection
*plt_old_section
;
184 bfd_vma plt_old_value
;
186 /* Used to implement multiple .got subsections. */
187 struct alpha_elf_got_entry
189 struct alpha_elf_got_entry
*next
;
191 /* Which .got subsection? */
194 /* The addend in effect for this entry. */
197 /* The .got offset for this entry. */
200 /* How many references to this entry? */
203 /* The relocation type of this entry. */
204 unsigned char reloc_type
;
206 /* How a LITERAL is used. */
209 /* Have we initialized the dynamic relocation for this entry? */
210 unsigned char reloc_done
;
212 /* Have we adjusted this entry for SEC_MERGE? */
213 unsigned char reloc_xlated
;
216 /* Used to count non-got, non-plt relocations for delayed sizing
217 of relocation sections. */
218 struct alpha_elf_reloc_entry
220 struct alpha_elf_reloc_entry
*next
;
222 /* Which .reloc section? */
225 /* What kind of relocation? */
228 /* Is this against read-only section? */
229 unsigned int reltext
: 1;
231 /* How many did we find? */
236 /* Alpha ELF linker hash table. */
238 struct alpha_elf_link_hash_table
240 struct elf_link_hash_table root
;
242 /* The head of a list of .got subsections linked through
243 alpha_elf_tdata(abfd)->got_link_next. */
247 /* Look up an entry in a Alpha ELF linker hash table. */
249 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
250 ((struct alpha_elf_link_hash_entry *) \
251 elf_link_hash_lookup (&(table)->root, (string), (create), \
254 /* Traverse a Alpha ELF linker hash table. */
256 #define alpha_elf_link_hash_traverse(table, func, info) \
257 (elf_link_hash_traverse \
259 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
262 /* Get the Alpha ELF linker hash table from a link_info structure. */
264 #define alpha_elf_hash_table(p) \
265 ((struct alpha_elf_link_hash_table *) ((p)->hash))
267 /* Get the object's symbols as our own entry type. */
269 #define alpha_elf_sym_hashes(abfd) \
270 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
272 /* Should we do dynamic things to this symbol? This differs from the
273 generic version in that we never need to consider function pointer
274 equality wrt PLT entries -- we don't create a PLT entry if a symbol's
275 address is ever taken. */
277 static inline bfd_boolean
278 alpha_elf_dynamic_symbol_p (h
, info
)
279 struct elf_link_hash_entry
*h
;
280 struct bfd_link_info
*info
;
282 return _bfd_elf_dynamic_symbol_p (h
, info
, 0);
285 /* Create an entry in a Alpha ELF linker hash table. */
287 static struct bfd_hash_entry
*
288 elf64_alpha_link_hash_newfunc (entry
, table
, string
)
289 struct bfd_hash_entry
*entry
;
290 struct bfd_hash_table
*table
;
293 struct alpha_elf_link_hash_entry
*ret
=
294 (struct alpha_elf_link_hash_entry
*) entry
;
296 /* Allocate the structure if it has not already been allocated by a
298 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
299 ret
= ((struct alpha_elf_link_hash_entry
*)
300 bfd_hash_allocate (table
,
301 sizeof (struct alpha_elf_link_hash_entry
)));
302 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
303 return (struct bfd_hash_entry
*) ret
;
305 /* Call the allocation method of the superclass. */
306 ret
= ((struct alpha_elf_link_hash_entry
*)
307 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
309 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
311 /* Set local fields. */
312 memset (&ret
->esym
, 0, sizeof (EXTR
));
313 /* We use -2 as a marker to indicate that the information has
314 not been set. -1 means there is no associated ifd. */
317 ret
->got_entries
= NULL
;
318 ret
->reloc_entries
= NULL
;
321 return (struct bfd_hash_entry
*) ret
;
324 /* Create a Alpha ELF linker hash table. */
326 static struct bfd_link_hash_table
*
327 elf64_alpha_bfd_link_hash_table_create (abfd
)
330 struct alpha_elf_link_hash_table
*ret
;
331 bfd_size_type amt
= sizeof (struct alpha_elf_link_hash_table
);
333 ret
= (struct alpha_elf_link_hash_table
*) bfd_zmalloc (amt
);
334 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
337 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
338 elf64_alpha_link_hash_newfunc
))
344 return &ret
->root
.root
;
347 /* We have some private fields hanging off of the elf_tdata structure. */
349 struct alpha_elf_obj_tdata
351 struct elf_obj_tdata root
;
353 /* For every input file, these are the got entries for that object's
355 struct alpha_elf_got_entry
** local_got_entries
;
357 /* For every input file, this is the object that owns the got that
358 this input file uses. */
361 /* For every got, this is a linked list through the objects using this got */
362 bfd
*in_got_link_next
;
364 /* For every got, this is a link to the next got subsegment. */
367 /* For every got, this is the section. */
370 /* For every got, this is it's total number of words. */
373 /* For every got, this is the sum of the number of words required
374 to hold all of the member object's local got. */
378 #define alpha_elf_tdata(abfd) \
379 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
382 elf64_alpha_mkobject (abfd
)
385 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
386 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
387 if (abfd
->tdata
.any
== NULL
)
393 elf64_alpha_object_p (abfd
)
396 /* Set the right machine number for an Alpha ELF file. */
397 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
400 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
401 from smaller values. Start with zero, widen, *then* decrement. */
402 #define MINUS_ONE (((bfd_vma)0) - 1)
404 #define SKIP_HOWTO(N) \
405 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
407 static reloc_howto_type elf64_alpha_howto_table
[] =
409 HOWTO (R_ALPHA_NONE
, /* type */
411 0, /* size (0 = byte, 1 = short, 2 = long) */
413 TRUE
, /* pc_relative */
415 complain_overflow_dont
, /* complain_on_overflow */
416 elf64_alpha_reloc_nil
, /* special_function */
418 FALSE
, /* partial_inplace */
421 TRUE
), /* pcrel_offset */
423 /* A 32 bit reference to a symbol. */
424 HOWTO (R_ALPHA_REFLONG
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 FALSE
, /* pc_relative */
430 complain_overflow_bitfield
, /* complain_on_overflow */
431 0, /* special_function */
432 "REFLONG", /* name */
433 FALSE
, /* partial_inplace */
434 0xffffffff, /* src_mask */
435 0xffffffff, /* dst_mask */
436 FALSE
), /* pcrel_offset */
438 /* A 64 bit reference to a symbol. */
439 HOWTO (R_ALPHA_REFQUAD
, /* type */
441 4, /* size (0 = byte, 1 = short, 2 = long) */
443 FALSE
, /* pc_relative */
445 complain_overflow_bitfield
, /* complain_on_overflow */
446 0, /* special_function */
447 "REFQUAD", /* name */
448 FALSE
, /* partial_inplace */
449 MINUS_ONE
, /* src_mask */
450 MINUS_ONE
, /* dst_mask */
451 FALSE
), /* pcrel_offset */
453 /* A 32 bit GP relative offset. This is just like REFLONG except
454 that when the value is used the value of the gp register will be
456 HOWTO (R_ALPHA_GPREL32
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 FALSE
, /* pc_relative */
462 complain_overflow_bitfield
, /* complain_on_overflow */
463 0, /* special_function */
464 "GPREL32", /* name */
465 FALSE
, /* partial_inplace */
466 0xffffffff, /* src_mask */
467 0xffffffff, /* dst_mask */
468 FALSE
), /* pcrel_offset */
470 /* Used for an instruction that refers to memory off the GP register. */
471 HOWTO (R_ALPHA_LITERAL
, /* type */
473 1, /* size (0 = byte, 1 = short, 2 = long) */
475 FALSE
, /* pc_relative */
477 complain_overflow_signed
, /* complain_on_overflow */
478 0, /* special_function */
479 "ELF_LITERAL", /* name */
480 FALSE
, /* partial_inplace */
481 0xffff, /* src_mask */
482 0xffff, /* dst_mask */
483 FALSE
), /* pcrel_offset */
485 /* This reloc only appears immediately following an ELF_LITERAL reloc.
486 It identifies a use of the literal. The symbol index is special:
487 1 means the literal address is in the base register of a memory
488 format instruction; 2 means the literal address is in the byte
489 offset register of a byte-manipulation instruction; 3 means the
490 literal address is in the target register of a jsr instruction.
491 This does not actually do any relocation. */
492 HOWTO (R_ALPHA_LITUSE
, /* type */
494 1, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE
, /* pc_relative */
498 complain_overflow_dont
, /* complain_on_overflow */
499 elf64_alpha_reloc_nil
, /* special_function */
501 FALSE
, /* partial_inplace */
504 FALSE
), /* pcrel_offset */
506 /* Load the gp register. This is always used for a ldah instruction
507 which loads the upper 16 bits of the gp register. The symbol
508 index of the GPDISP instruction is an offset in bytes to the lda
509 instruction that loads the lower 16 bits. The value to use for
510 the relocation is the difference between the GP value and the
511 current location; the load will always be done against a register
512 holding the current address.
514 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
515 any offset is present in the instructions, it is an offset from
516 the register to the ldah instruction. This lets us avoid any
517 stupid hackery like inventing a gp value to do partial relocation
518 against. Also unlike ECOFF, we do the whole relocation off of
519 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
520 space consuming bit, that, since all the information was present
521 in the GPDISP_HI16 reloc. */
522 HOWTO (R_ALPHA_GPDISP
, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 FALSE
, /* pc_relative */
528 complain_overflow_dont
, /* complain_on_overflow */
529 elf64_alpha_reloc_gpdisp
, /* special_function */
531 FALSE
, /* partial_inplace */
532 0xffff, /* src_mask */
533 0xffff, /* dst_mask */
534 TRUE
), /* pcrel_offset */
536 /* A 21 bit branch. */
537 HOWTO (R_ALPHA_BRADDR
, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 TRUE
, /* pc_relative */
543 complain_overflow_signed
, /* complain_on_overflow */
544 0, /* special_function */
546 FALSE
, /* partial_inplace */
547 0x1fffff, /* src_mask */
548 0x1fffff, /* dst_mask */
549 TRUE
), /* pcrel_offset */
551 /* A hint for a jump to a register. */
552 HOWTO (R_ALPHA_HINT
, /* type */
554 1, /* size (0 = byte, 1 = short, 2 = long) */
556 TRUE
, /* pc_relative */
558 complain_overflow_dont
, /* complain_on_overflow */
559 0, /* special_function */
561 FALSE
, /* partial_inplace */
562 0x3fff, /* src_mask */
563 0x3fff, /* dst_mask */
564 TRUE
), /* pcrel_offset */
566 /* 16 bit PC relative offset. */
567 HOWTO (R_ALPHA_SREL16
, /* type */
569 1, /* size (0 = byte, 1 = short, 2 = long) */
571 TRUE
, /* pc_relative */
573 complain_overflow_signed
, /* complain_on_overflow */
574 0, /* special_function */
576 FALSE
, /* partial_inplace */
577 0xffff, /* src_mask */
578 0xffff, /* dst_mask */
579 TRUE
), /* pcrel_offset */
581 /* 32 bit PC relative offset. */
582 HOWTO (R_ALPHA_SREL32
, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 TRUE
, /* pc_relative */
588 complain_overflow_signed
, /* complain_on_overflow */
589 0, /* special_function */
591 FALSE
, /* partial_inplace */
592 0xffffffff, /* src_mask */
593 0xffffffff, /* dst_mask */
594 TRUE
), /* pcrel_offset */
596 /* A 64 bit PC relative offset. */
597 HOWTO (R_ALPHA_SREL64
, /* type */
599 4, /* size (0 = byte, 1 = short, 2 = long) */
601 TRUE
, /* pc_relative */
603 complain_overflow_signed
, /* complain_on_overflow */
604 0, /* special_function */
606 FALSE
, /* partial_inplace */
607 MINUS_ONE
, /* src_mask */
608 MINUS_ONE
, /* dst_mask */
609 TRUE
), /* pcrel_offset */
611 /* Skip 12 - 16; deprecated ECOFF relocs. */
618 /* The high 16 bits of the displacement from GP to the target. */
619 HOWTO (R_ALPHA_GPRELHIGH
,
621 1, /* size (0 = byte, 1 = short, 2 = long) */
623 FALSE
, /* pc_relative */
625 complain_overflow_signed
, /* complain_on_overflow */
626 0, /* special_function */
627 "GPRELHIGH", /* name */
628 FALSE
, /* partial_inplace */
629 0xffff, /* src_mask */
630 0xffff, /* dst_mask */
631 FALSE
), /* pcrel_offset */
633 /* The low 16 bits of the displacement from GP to the target. */
634 HOWTO (R_ALPHA_GPRELLOW
,
636 1, /* size (0 = byte, 1 = short, 2 = long) */
638 FALSE
, /* pc_relative */
640 complain_overflow_dont
, /* complain_on_overflow */
641 0, /* special_function */
642 "GPRELLOW", /* name */
643 FALSE
, /* partial_inplace */
644 0xffff, /* src_mask */
645 0xffff, /* dst_mask */
646 FALSE
), /* pcrel_offset */
648 /* A 16-bit displacement from the GP to the target. */
649 HOWTO (R_ALPHA_GPREL16
,
651 1, /* size (0 = byte, 1 = short, 2 = long) */
653 FALSE
, /* pc_relative */
655 complain_overflow_signed
, /* complain_on_overflow */
656 0, /* special_function */
657 "GPREL16", /* name */
658 FALSE
, /* partial_inplace */
659 0xffff, /* src_mask */
660 0xffff, /* dst_mask */
661 FALSE
), /* pcrel_offset */
663 /* Skip 20 - 23; deprecated ECOFF relocs. */
669 /* Misc ELF relocations. */
671 /* A dynamic relocation to copy the target into our .dynbss section. */
672 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
673 is present because every other ELF has one, but should not be used
674 because .dynbss is an ugly thing. */
681 complain_overflow_dont
,
682 bfd_elf_generic_reloc
,
689 /* A dynamic relocation for a .got entry. */
690 HOWTO (R_ALPHA_GLOB_DAT
,
696 complain_overflow_dont
,
697 bfd_elf_generic_reloc
,
704 /* A dynamic relocation for a .plt entry. */
705 HOWTO (R_ALPHA_JMP_SLOT
,
711 complain_overflow_dont
,
712 bfd_elf_generic_reloc
,
719 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
720 HOWTO (R_ALPHA_RELATIVE
,
726 complain_overflow_dont
,
727 bfd_elf_generic_reloc
,
734 /* A 21 bit branch that adjusts for gp loads. */
735 HOWTO (R_ALPHA_BRSGP
, /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 TRUE
, /* pc_relative */
741 complain_overflow_signed
, /* complain_on_overflow */
742 0, /* special_function */
744 FALSE
, /* partial_inplace */
745 0x1fffff, /* src_mask */
746 0x1fffff, /* dst_mask */
747 TRUE
), /* pcrel_offset */
749 /* Creates a tls_index for the symbol in the got. */
750 HOWTO (R_ALPHA_TLSGD
, /* type */
752 1, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE
, /* pc_relative */
756 complain_overflow_signed
, /* complain_on_overflow */
757 0, /* special_function */
759 FALSE
, /* partial_inplace */
760 0xffff, /* src_mask */
761 0xffff, /* dst_mask */
762 FALSE
), /* pcrel_offset */
764 /* Creates a tls_index for the (current) module in the got. */
765 HOWTO (R_ALPHA_TLSLDM
, /* type */
767 1, /* size (0 = byte, 1 = short, 2 = long) */
769 FALSE
, /* pc_relative */
771 complain_overflow_signed
, /* complain_on_overflow */
772 0, /* special_function */
774 FALSE
, /* partial_inplace */
775 0xffff, /* src_mask */
776 0xffff, /* dst_mask */
777 FALSE
), /* pcrel_offset */
779 /* A dynamic relocation for a DTP module entry. */
780 HOWTO (R_ALPHA_DTPMOD64
, /* type */
782 4, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE
, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 0, /* special_function */
788 "DTPMOD64", /* name */
789 FALSE
, /* partial_inplace */
790 MINUS_ONE
, /* src_mask */
791 MINUS_ONE
, /* dst_mask */
792 FALSE
), /* pcrel_offset */
794 /* Creates a 64-bit offset in the got for the displacement
795 from DTP to the target. */
796 HOWTO (R_ALPHA_GOTDTPREL
, /* type */
798 1, /* size (0 = byte, 1 = short, 2 = long) */
800 FALSE
, /* pc_relative */
802 complain_overflow_signed
, /* complain_on_overflow */
803 0, /* special_function */
804 "GOTDTPREL", /* name */
805 FALSE
, /* partial_inplace */
806 0xffff, /* src_mask */
807 0xffff, /* dst_mask */
808 FALSE
), /* pcrel_offset */
810 /* A dynamic relocation for a displacement from DTP to the target. */
811 HOWTO (R_ALPHA_DTPREL64
, /* type */
813 4, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE
, /* pc_relative */
817 complain_overflow_bitfield
, /* complain_on_overflow */
818 0, /* special_function */
819 "DTPREL64", /* name */
820 FALSE
, /* partial_inplace */
821 MINUS_ONE
, /* src_mask */
822 MINUS_ONE
, /* dst_mask */
823 FALSE
), /* pcrel_offset */
825 /* The high 16 bits of the displacement from DTP to the target. */
826 HOWTO (R_ALPHA_DTPRELHI
, /* type */
828 1, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE
, /* pc_relative */
832 complain_overflow_signed
, /* complain_on_overflow */
833 0, /* special_function */
834 "DTPRELHI", /* name */
835 FALSE
, /* partial_inplace */
836 0xffff, /* src_mask */
837 0xffff, /* dst_mask */
838 FALSE
), /* pcrel_offset */
840 /* The low 16 bits of the displacement from DTP to the target. */
841 HOWTO (R_ALPHA_DTPRELLO
, /* type */
843 1, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 0, /* special_function */
849 "DTPRELLO", /* name */
850 FALSE
, /* partial_inplace */
851 0xffff, /* src_mask */
852 0xffff, /* dst_mask */
853 FALSE
), /* pcrel_offset */
855 /* A 16-bit displacement from DTP to the target. */
856 HOWTO (R_ALPHA_DTPREL16
, /* type */
858 1, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_signed
, /* complain_on_overflow */
863 0, /* special_function */
864 "DTPREL16", /* name */
865 FALSE
, /* partial_inplace */
866 0xffff, /* src_mask */
867 0xffff, /* dst_mask */
868 FALSE
), /* pcrel_offset */
870 /* Creates a 64-bit offset in the got for the displacement
871 from TP to the target. */
872 HOWTO (R_ALPHA_GOTTPREL
, /* type */
874 1, /* size (0 = byte, 1 = short, 2 = long) */
876 FALSE
, /* pc_relative */
878 complain_overflow_signed
, /* complain_on_overflow */
879 0, /* special_function */
880 "GOTTPREL", /* name */
881 FALSE
, /* partial_inplace */
882 0xffff, /* src_mask */
883 0xffff, /* dst_mask */
884 FALSE
), /* pcrel_offset */
886 /* A dynamic relocation for a displacement from TP to the target. */
887 HOWTO (R_ALPHA_TPREL64
, /* type */
889 4, /* size (0 = byte, 1 = short, 2 = long) */
891 FALSE
, /* pc_relative */
893 complain_overflow_bitfield
, /* complain_on_overflow */
894 0, /* special_function */
895 "TPREL64", /* name */
896 FALSE
, /* partial_inplace */
897 MINUS_ONE
, /* src_mask */
898 MINUS_ONE
, /* dst_mask */
899 FALSE
), /* pcrel_offset */
901 /* The high 16 bits of the displacement from TP to the target. */
902 HOWTO (R_ALPHA_TPRELHI
, /* type */
904 1, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE
, /* pc_relative */
908 complain_overflow_signed
, /* complain_on_overflow */
909 0, /* special_function */
910 "TPRELHI", /* name */
911 FALSE
, /* partial_inplace */
912 0xffff, /* src_mask */
913 0xffff, /* dst_mask */
914 FALSE
), /* pcrel_offset */
916 /* The low 16 bits of the displacement from TP to the target. */
917 HOWTO (R_ALPHA_TPRELLO
, /* type */
919 1, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE
, /* pc_relative */
923 complain_overflow_dont
, /* complain_on_overflow */
924 0, /* special_function */
925 "TPRELLO", /* name */
926 FALSE
, /* partial_inplace */
927 0xffff, /* src_mask */
928 0xffff, /* dst_mask */
929 FALSE
), /* pcrel_offset */
931 /* A 16-bit displacement from TP to the target. */
932 HOWTO (R_ALPHA_TPREL16
, /* type */
934 1, /* size (0 = byte, 1 = short, 2 = long) */
936 FALSE
, /* pc_relative */
938 complain_overflow_signed
, /* complain_on_overflow */
939 0, /* special_function */
940 "TPREL16", /* name */
941 FALSE
, /* partial_inplace */
942 0xffff, /* src_mask */
943 0xffff, /* dst_mask */
944 FALSE
), /* pcrel_offset */
947 /* A relocation function which doesn't do anything. */
949 static bfd_reloc_status_type
950 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
951 bfd
*abfd ATTRIBUTE_UNUSED
;
953 asymbol
*sym ATTRIBUTE_UNUSED
;
954 PTR data ATTRIBUTE_UNUSED
;
957 char **error_message ATTRIBUTE_UNUSED
;
960 reloc
->address
+= sec
->output_offset
;
964 /* A relocation function used for an unsupported reloc. */
966 static bfd_reloc_status_type
967 elf64_alpha_reloc_bad (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
968 bfd
*abfd ATTRIBUTE_UNUSED
;
970 asymbol
*sym ATTRIBUTE_UNUSED
;
971 PTR data ATTRIBUTE_UNUSED
;
974 char **error_message ATTRIBUTE_UNUSED
;
977 reloc
->address
+= sec
->output_offset
;
978 return bfd_reloc_notsupported
;
981 /* Do the work of the GPDISP relocation. */
983 static bfd_reloc_status_type
984 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
990 bfd_reloc_status_type ret
= bfd_reloc_ok
;
992 unsigned long i_ldah
, i_lda
;
994 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
995 i_lda
= bfd_get_32 (abfd
, p_lda
);
997 /* Complain if the instructions are not correct. */
998 if (((i_ldah
>> 26) & 0x3f) != 0x09
999 || ((i_lda
>> 26) & 0x3f) != 0x08)
1000 ret
= bfd_reloc_dangerous
;
1002 /* Extract the user-supplied offset, mirroring the sign extensions
1003 that the instructions perform. */
1004 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
1005 addend
= (addend
^ 0x80008000) - 0x80008000;
1009 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
) 0x80000000
1010 || (bfd_signed_vma
) gpdisp
>= (bfd_signed_vma
) 0x7fff8000)
1011 ret
= bfd_reloc_overflow
;
1013 /* compensate for the sign extension again. */
1014 i_ldah
= ((i_ldah
& 0xffff0000)
1015 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
1016 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
1018 bfd_put_32 (abfd
, (bfd_vma
) i_ldah
, p_ldah
);
1019 bfd_put_32 (abfd
, (bfd_vma
) i_lda
, p_lda
);
1024 /* The special function for the GPDISP reloc. */
1026 static bfd_reloc_status_type
1027 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
1028 output_bfd
, err_msg
)
1030 arelent
*reloc_entry
;
1031 asymbol
*sym ATTRIBUTE_UNUSED
;
1033 asection
*input_section
;
1037 bfd_reloc_status_type ret
;
1038 bfd_vma gp
, relocation
;
1039 bfd_vma high_address
;
1040 bfd_byte
*p_ldah
, *p_lda
;
1042 /* Don't do anything if we're not doing a final link. */
1045 reloc_entry
->address
+= input_section
->output_offset
;
1046 return bfd_reloc_ok
;
1049 high_address
= bfd_get_section_limit (abfd
, input_section
);
1050 if (reloc_entry
->address
> high_address
1051 || reloc_entry
->address
+ reloc_entry
->addend
> high_address
)
1052 return bfd_reloc_outofrange
;
1054 /* The gp used in the portion of the output object to which this
1055 input object belongs is cached on the input bfd. */
1056 gp
= _bfd_get_gp_value (abfd
);
1058 relocation
= (input_section
->output_section
->vma
1059 + input_section
->output_offset
1060 + reloc_entry
->address
);
1062 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
1063 p_lda
= p_ldah
+ reloc_entry
->addend
;
1065 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
1067 /* Complain if the instructions are not correct. */
1068 if (ret
== bfd_reloc_dangerous
)
1069 *err_msg
= _("GPDISP relocation did not find ldah and lda instructions");
1074 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1076 struct elf_reloc_map
1078 bfd_reloc_code_real_type bfd_reloc_val
;
1082 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
1084 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
1085 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
1086 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
1087 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
1088 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
1089 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
1090 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
1091 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
1092 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
1093 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
1094 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
1095 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
1096 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
1097 {BFD_RELOC_ALPHA_GPREL_HI16
, R_ALPHA_GPRELHIGH
},
1098 {BFD_RELOC_ALPHA_GPREL_LO16
, R_ALPHA_GPRELLOW
},
1099 {BFD_RELOC_GPREL16
, R_ALPHA_GPREL16
},
1100 {BFD_RELOC_ALPHA_BRSGP
, R_ALPHA_BRSGP
},
1101 {BFD_RELOC_ALPHA_TLSGD
, R_ALPHA_TLSGD
},
1102 {BFD_RELOC_ALPHA_TLSLDM
, R_ALPHA_TLSLDM
},
1103 {BFD_RELOC_ALPHA_DTPMOD64
, R_ALPHA_DTPMOD64
},
1104 {BFD_RELOC_ALPHA_GOTDTPREL16
, R_ALPHA_GOTDTPREL
},
1105 {BFD_RELOC_ALPHA_DTPREL64
, R_ALPHA_DTPREL64
},
1106 {BFD_RELOC_ALPHA_DTPREL_HI16
, R_ALPHA_DTPRELHI
},
1107 {BFD_RELOC_ALPHA_DTPREL_LO16
, R_ALPHA_DTPRELLO
},
1108 {BFD_RELOC_ALPHA_DTPREL16
, R_ALPHA_DTPREL16
},
1109 {BFD_RELOC_ALPHA_GOTTPREL16
, R_ALPHA_GOTTPREL
},
1110 {BFD_RELOC_ALPHA_TPREL64
, R_ALPHA_TPREL64
},
1111 {BFD_RELOC_ALPHA_TPREL_HI16
, R_ALPHA_TPRELHI
},
1112 {BFD_RELOC_ALPHA_TPREL_LO16
, R_ALPHA_TPRELLO
},
1113 {BFD_RELOC_ALPHA_TPREL16
, R_ALPHA_TPREL16
},
1116 /* Given a BFD reloc type, return a HOWTO structure. */
1118 static reloc_howto_type
*
1119 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
1120 bfd
*abfd ATTRIBUTE_UNUSED
;
1121 bfd_reloc_code_real_type code
;
1123 const struct elf_reloc_map
*i
, *e
;
1124 i
= e
= elf64_alpha_reloc_map
;
1125 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
1128 if (i
->bfd_reloc_val
== code
)
1129 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
1134 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1137 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
1138 bfd
*abfd ATTRIBUTE_UNUSED
;
1140 Elf_Internal_Rela
*dst
;
1144 r_type
= ELF64_R_TYPE(dst
->r_info
);
1145 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1146 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1149 /* These two relocations create a two-word entry in the got. */
1150 #define alpha_got_entry_size(r_type) \
1151 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1153 /* This is PT_TLS segment p_vaddr. */
1154 #define alpha_get_dtprel_base(info) \
1155 (elf_hash_table (info)->tls_sec->vma)
1157 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1158 is assigned offset round(16, PT_TLS p_align). */
1159 #define alpha_get_tprel_base(info) \
1160 (elf_hash_table (info)->tls_sec->vma \
1161 - align_power ((bfd_vma) 16, \
1162 elf_hash_table (info)->tls_sec->alignment_power))
1164 /* These functions do relaxation for Alpha ELF.
1166 Currently I'm only handling what I can do with existing compiler
1167 and assembler support, which means no instructions are removed,
1168 though some may be nopped. At this time GCC does not emit enough
1169 information to do all of the relaxing that is possible. It will
1170 take some not small amount of work for that to happen.
1172 There are a couple of interesting papers that I once read on this
1173 subject, that I cannot find references to at the moment, that
1174 related to Alpha in particular. They are by David Wall, then of
1178 #define OP_LDAH 0x09
1179 #define INSN_JSR 0x68004000
1180 #define INSN_JSR_MASK 0xfc00c000
1184 #define INSN_UNOP 0x2ffe0000
1185 #define INSN_ADDQ 0x40000400
1186 #define INSN_RDUNIQ 0x0000009e
1188 struct alpha_relax_info
1193 Elf_Internal_Shdr
*symtab_hdr
;
1194 Elf_Internal_Rela
*relocs
, *relend
;
1195 struct bfd_link_info
*link_info
;
1199 struct alpha_elf_link_hash_entry
*h
;
1200 struct alpha_elf_got_entry
**first_gotent
;
1201 struct alpha_elf_got_entry
*gotent
;
1202 bfd_boolean changed_contents
;
1203 bfd_boolean changed_relocs
;
1204 unsigned char other
;
1207 static bfd_boolean elf64_alpha_relax_with_lituse
1208 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1209 Elf_Internal_Rela
*irel
));
1210 static bfd_vma elf64_alpha_relax_opt_call
1211 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
));
1212 static bfd_boolean elf64_alpha_relax_got_load
1213 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1214 Elf_Internal_Rela
*irel
, unsigned long));
1215 static bfd_boolean elf64_alpha_relax_gprelhilo
1216 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1217 Elf_Internal_Rela
*irel
, bfd_boolean
));
1218 static bfd_boolean elf64_alpha_relax_tls_get_addr
1219 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1220 Elf_Internal_Rela
*irel
, bfd_boolean
));
1221 static bfd_boolean elf64_alpha_relax_section
1222 PARAMS((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
1223 bfd_boolean
*again
));
1225 static Elf_Internal_Rela
*
1226 elf64_alpha_find_reloc_at_ofs (rel
, relend
, offset
, type
)
1227 Elf_Internal_Rela
*rel
, *relend
;
1231 while (rel
< relend
)
1233 if (rel
->r_offset
== offset
1234 && ELF64_R_TYPE (rel
->r_info
) == (unsigned int) type
)
1242 elf64_alpha_relax_with_lituse (info
, symval
, irel
)
1243 struct alpha_relax_info
*info
;
1245 Elf_Internal_Rela
*irel
;
1247 Elf_Internal_Rela
*urel
, *irelend
= info
->relend
;
1248 int flags
, count
, i
;
1249 bfd_signed_vma disp
;
1252 bfd_boolean lit_reused
= FALSE
;
1253 bfd_boolean all_optimized
= TRUE
;
1254 unsigned int lit_insn
;
1256 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1257 if (lit_insn
>> 26 != OP_LDQ
)
1259 ((*_bfd_error_handler
)
1260 ("%B: %A+0x%lx: warning: LITERAL relocation against unexpected insn",
1261 info
->abfd
, info
->sec
,
1262 (unsigned long) irel
->r_offset
));
1266 /* Can't relax dynamic symbols. */
1267 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
1270 /* Summarize how this particular LITERAL is used. */
1271 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
1273 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
1275 if (urel
->r_addend
<= 3)
1276 flags
|= 1 << urel
->r_addend
;
1279 /* A little preparation for the loop... */
1280 disp
= symval
- info
->gp
;
1282 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
1286 bfd_signed_vma xdisp
;
1288 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
1290 switch (urel
->r_addend
)
1292 case LITUSE_ALPHA_ADDR
:
1294 /* This type is really just a placeholder to note that all
1295 uses cannot be optimized, but to still allow some. */
1296 all_optimized
= FALSE
;
1299 case LITUSE_ALPHA_BASE
:
1300 /* We can always optimize 16-bit displacements. */
1302 /* Extract the displacement from the instruction, sign-extending
1303 it if necessary, then test whether it is within 16 or 32 bits
1304 displacement from GP. */
1305 insn_disp
= insn
& 0x0000ffff;
1306 if (insn_disp
& 0x8000)
1307 insn_disp
|= ~0xffff; /* Negative: sign-extend. */
1309 xdisp
= disp
+ insn_disp
;
1310 fits16
= (xdisp
>= - (bfd_signed_vma
) 0x8000 && xdisp
< 0x8000);
1311 fits32
= (xdisp
>= - (bfd_signed_vma
) 0x80000000
1312 && xdisp
< 0x7fff8000);
1316 /* Take the op code and dest from this insn, take the base
1317 register from the literal insn. Leave the offset alone. */
1318 insn
= (insn
& 0xffe0ffff) | (lit_insn
& 0x001f0000);
1319 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1321 urel
->r_addend
= irel
->r_addend
;
1322 info
->changed_relocs
= TRUE
;
1324 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1325 info
->contents
+ urel
->r_offset
);
1326 info
->changed_contents
= TRUE
;
1329 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1330 else if (fits32
&& !(flags
& ~6))
1332 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
1334 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1336 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
1337 bfd_put_32 (info
->abfd
, (bfd_vma
) lit_insn
,
1338 info
->contents
+ irel
->r_offset
);
1340 info
->changed_contents
= TRUE
;
1342 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1344 urel
->r_addend
= irel
->r_addend
;
1345 info
->changed_relocs
= TRUE
;
1348 all_optimized
= FALSE
;
1351 case LITUSE_ALPHA_BYTOFF
:
1352 /* We can always optimize byte instructions. */
1354 /* FIXME: sanity check the insn for byte op. Check that the
1355 literal dest reg is indeed Rb in the byte insn. */
1357 insn
&= ~ (unsigned) 0x001ff000;
1358 insn
|= ((symval
& 7) << 13) | 0x1000;
1360 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1362 info
->changed_relocs
= TRUE
;
1364 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1365 info
->contents
+ urel
->r_offset
);
1366 info
->changed_contents
= TRUE
;
1369 case LITUSE_ALPHA_JSR
:
1370 case LITUSE_ALPHA_TLSGD
:
1371 case LITUSE_ALPHA_TLSLDM
:
1373 bfd_vma optdest
, org
;
1374 bfd_signed_vma odisp
;
1376 /* If not zero, place to jump without needing pv. */
1377 optdest
= elf64_alpha_relax_opt_call (info
, symval
);
1378 org
= (info
->sec
->output_section
->vma
1379 + info
->sec
->output_offset
1380 + urel
->r_offset
+ 4);
1381 odisp
= (optdest
? optdest
: symval
) - org
;
1383 if (odisp
>= -0x400000 && odisp
< 0x400000)
1385 Elf_Internal_Rela
*xrel
;
1387 /* Preserve branch prediction call stack when possible. */
1388 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
1389 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
1391 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
1393 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1395 urel
->r_addend
= irel
->r_addend
;
1398 urel
->r_addend
+= optdest
- symval
;
1400 all_optimized
= FALSE
;
1402 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1403 info
->contents
+ urel
->r_offset
);
1405 /* Kill any HINT reloc that might exist for this insn. */
1406 xrel
= (elf64_alpha_find_reloc_at_ofs
1407 (info
->relocs
, info
->relend
, urel
->r_offset
,
1410 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1412 info
->changed_contents
= TRUE
;
1413 info
->changed_relocs
= TRUE
;
1416 all_optimized
= FALSE
;
1418 /* Even if the target is not in range for a direct branch,
1419 if we share a GP, we can eliminate the gp reload. */
1422 Elf_Internal_Rela
*gpdisp
1423 = (elf64_alpha_find_reloc_at_ofs
1424 (info
->relocs
, irelend
, urel
->r_offset
+ 4,
1428 bfd_byte
*p_ldah
= info
->contents
+ gpdisp
->r_offset
;
1429 bfd_byte
*p_lda
= p_ldah
+ gpdisp
->r_addend
;
1430 unsigned int ldah
= bfd_get_32 (info
->abfd
, p_ldah
);
1431 unsigned int lda
= bfd_get_32 (info
->abfd
, p_lda
);
1433 /* Verify that the instruction is "ldah $29,0($26)".
1434 Consider a function that ends in a noreturn call,
1435 and that the next function begins with an ldgp,
1436 and that by accident there is no padding between.
1437 In that case the insn would use $27 as the base. */
1438 if (ldah
== 0x27ba0000 && lda
== 0x23bd0000)
1440 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_ldah
);
1441 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_lda
);
1443 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1444 info
->changed_contents
= TRUE
;
1445 info
->changed_relocs
= TRUE
;
1454 /* If all cases were optimized, we can reduce the use count on this
1455 got entry by one, possibly eliminating it. */
1458 if (--info
->gotent
->use_count
== 0)
1460 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
1461 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1463 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1466 /* If the literal instruction is no longer needed (it may have been
1467 reused. We can eliminate it. */
1468 /* ??? For now, I don't want to deal with compacting the section,
1469 so just nop it out. */
1472 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1473 info
->changed_relocs
= TRUE
;
1475 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
,
1476 info
->contents
+ irel
->r_offset
);
1477 info
->changed_contents
= TRUE
;
1485 elf64_alpha_relax_opt_call (info
, symval
)
1486 struct alpha_relax_info
*info
;
1489 /* If the function has the same gp, and we can identify that the
1490 function does not use its function pointer, we can eliminate the
1493 /* If the symbol is marked NOPV, we are being told the function never
1494 needs its procedure value. */
1495 if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_NOPV
)
1498 /* If the symbol is marked STD_GP, we are being told the function does
1499 a normal ldgp in the first two words. */
1500 else if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_STD_GPLOAD
)
1503 /* Otherwise, we may be able to identify a GP load in the first two
1504 words, which we can then skip. */
1507 Elf_Internal_Rela
*tsec_relocs
, *tsec_relend
, *tsec_free
, *gpdisp
;
1510 /* Load the relocations from the section that the target symbol is in. */
1511 if (info
->sec
== info
->tsec
)
1513 tsec_relocs
= info
->relocs
;
1514 tsec_relend
= info
->relend
;
1519 tsec_relocs
= (_bfd_elf_link_read_relocs
1520 (info
->abfd
, info
->tsec
, (PTR
) NULL
,
1521 (Elf_Internal_Rela
*) NULL
,
1522 info
->link_info
->keep_memory
));
1523 if (tsec_relocs
== NULL
)
1525 tsec_relend
= tsec_relocs
+ info
->tsec
->reloc_count
;
1526 tsec_free
= (info
->link_info
->keep_memory
? NULL
: tsec_relocs
);
1529 /* Recover the symbol's offset within the section. */
1530 ofs
= (symval
- info
->tsec
->output_section
->vma
1531 - info
->tsec
->output_offset
);
1533 /* Look for a GPDISP reloc. */
1534 gpdisp
= (elf64_alpha_find_reloc_at_ofs
1535 (tsec_relocs
, tsec_relend
, ofs
, R_ALPHA_GPDISP
));
1537 if (!gpdisp
|| gpdisp
->r_addend
!= 4)
1547 /* We've now determined that we can skip an initial gp load. Verify
1548 that the call and the target use the same gp. */
1549 if (info
->link_info
->hash
->creator
!= info
->tsec
->owner
->xvec
1550 || info
->gotobj
!= alpha_elf_tdata (info
->tsec
->owner
)->gotobj
)
1557 elf64_alpha_relax_got_load (info
, symval
, irel
, r_type
)
1558 struct alpha_relax_info
*info
;
1560 Elf_Internal_Rela
*irel
;
1561 unsigned long r_type
;
1564 bfd_signed_vma disp
;
1566 /* Get the instruction. */
1567 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1569 if (insn
>> 26 != OP_LDQ
)
1571 reloc_howto_type
*howto
= elf64_alpha_howto_table
+ r_type
;
1572 ((*_bfd_error_handler
)
1573 ("%B: %A+0x%lx: warning: %s relocation against unexpected insn",
1574 info
->abfd
, info
->sec
,
1575 (unsigned long) irel
->r_offset
, howto
->name
));
1579 /* Can't relax dynamic symbols. */
1580 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
1583 /* Can't use local-exec relocations in shared libraries. */
1584 if (r_type
== R_ALPHA_GOTTPREL
&& info
->link_info
->shared
)
1587 if (r_type
== R_ALPHA_LITERAL
)
1588 disp
= symval
- info
->gp
;
1591 bfd_vma dtp_base
, tp_base
;
1593 BFD_ASSERT (elf_hash_table (info
->link_info
)->tls_sec
!= NULL
);
1594 dtp_base
= alpha_get_dtprel_base (info
->link_info
);
1595 tp_base
= alpha_get_tprel_base (info
->link_info
);
1596 disp
= symval
- (r_type
== R_ALPHA_GOTDTPREL
? dtp_base
: tp_base
);
1599 if (disp
< -0x8000 || disp
>= 0x8000)
1602 /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading
1603 a constant, so force the base register to be $31. */
1604 if (r_type
== R_ALPHA_LITERAL
)
1605 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
1607 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
1608 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, info
->contents
+ irel
->r_offset
);
1609 info
->changed_contents
= TRUE
;
1611 /* Reduce the use count on this got entry by one, possibly
1613 if (--info
->gotent
->use_count
== 0)
1615 int sz
= alpha_got_entry_size (r_type
);
1616 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1618 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1621 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
1624 case R_ALPHA_LITERAL
:
1625 r_type
= R_ALPHA_GPREL16
;
1627 case R_ALPHA_GOTDTPREL
:
1628 r_type
= R_ALPHA_DTPREL16
;
1630 case R_ALPHA_GOTTPREL
:
1631 r_type
= R_ALPHA_TPREL16
;
1638 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), r_type
);
1639 info
->changed_relocs
= TRUE
;
1641 /* ??? Search forward through this basic block looking for insns
1642 that use the target register. Stop after an insn modifying the
1643 register is seen, or after a branch or call.
1645 Any such memory load insn may be substituted by a load directly
1646 off the GP. This allows the memory load insn to be issued before
1647 the calculated GP register would otherwise be ready.
1649 Any such jsr insn can be replaced by a bsr if it is in range.
1651 This would mean that we'd have to _add_ relocations, the pain of
1652 which gives one pause. */
1658 elf64_alpha_relax_gprelhilo (info
, symval
, irel
, hi
)
1659 struct alpha_relax_info
*info
;
1661 Elf_Internal_Rela
*irel
;
1665 bfd_signed_vma disp
;
1666 bfd_byte
*pos
= info
->contents
+ irel
->r_offset
;
1668 /* ??? This assumes that the compiler doesn't render
1672 ldah t, array(gp) !gprelhigh
1674 ldq r, array(t) !gprellow
1676 which would indeed be the most efficient way to implement this. */
1680 disp
= symval
- info
->gp
;
1681 if (disp
< -0x8000 || disp
>= 0x8000)
1686 /* Nop out the high instruction. */
1688 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
);
1689 info
->changed_contents
= TRUE
;
1691 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1693 info
->changed_relocs
= TRUE
;
1697 /* Adjust the low instruction to reference GP directly. */
1699 insn
= bfd_get_32 (info
->abfd
, pos
);
1700 insn
= (insn
& 0xffe00000) | (29 << 16);
1701 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
);
1702 info
->changed_contents
= TRUE
;
1704 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1706 info
->changed_relocs
= TRUE
;
1713 elf64_alpha_relax_tls_get_addr (info
, symval
, irel
, is_gd
)
1714 struct alpha_relax_info
*info
;
1716 Elf_Internal_Rela
*irel
;
1721 Elf_Internal_Rela
*gpdisp
, *hint
;
1722 bfd_boolean dynamic
, use_gottprel
, pos1_unusable
;
1723 unsigned long new_symndx
;
1725 dynamic
= alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
);
1727 /* If a TLS symbol is accessed using IE at least once, there is no point
1728 to use dynamic model for it. */
1729 if (is_gd
&& info
->h
&& (info
->h
->flags
& ALPHA_ELF_LINK_HASH_TLS_IE
))
1732 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
1733 then we might as well relax to IE. */
1734 else if (info
->link_info
->shared
&& !dynamic
1735 && (info
->link_info
->flags
& DF_STATIC_TLS
))
1738 /* Otherwise we must be building an executable to do anything. */
1739 else if (info
->link_info
->shared
)
1742 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
1743 the matching LITUSE_TLS relocations. */
1744 if (irel
+ 2 >= info
->relend
)
1746 if (ELF64_R_TYPE (irel
[1].r_info
) != R_ALPHA_LITERAL
1747 || ELF64_R_TYPE (irel
[2].r_info
) != R_ALPHA_LITUSE
1748 || irel
[2].r_addend
!= (is_gd
? LITUSE_ALPHA_TLSGD
: LITUSE_ALPHA_TLSLDM
))
1751 /* There must be a GPDISP relocation positioned immediately after the
1752 LITUSE relocation. */
1753 gpdisp
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
1754 irel
[2].r_offset
+ 4, R_ALPHA_GPDISP
);
1758 pos
[0] = info
->contents
+ irel
[0].r_offset
;
1759 pos
[1] = info
->contents
+ irel
[1].r_offset
;
1760 pos
[2] = info
->contents
+ irel
[2].r_offset
;
1761 pos
[3] = info
->contents
+ gpdisp
->r_offset
;
1762 pos
[4] = pos
[3] + gpdisp
->r_addend
;
1763 pos1_unusable
= FALSE
;
1765 /* Generally, the positions are not allowed to be out of order, lest the
1766 modified insn sequence have different register lifetimes. We can make
1767 an exception when pos 1 is adjacent to pos 0. */
1768 if (pos
[1] + 4 == pos
[0])
1770 bfd_byte
*tmp
= pos
[0];
1774 else if (pos
[1] < pos
[0])
1775 pos1_unusable
= TRUE
;
1776 if (pos
[1] >= pos
[2] || pos
[2] >= pos
[3])
1779 /* Reduce the use count on the LITERAL relocation. Do this before we
1780 smash the symndx when we adjust the relocations below. */
1782 struct alpha_elf_got_entry
*lit_gotent
;
1783 struct alpha_elf_link_hash_entry
*lit_h
;
1786 BFD_ASSERT (ELF64_R_SYM (irel
[1].r_info
) >= info
->symtab_hdr
->sh_info
);
1787 indx
= ELF64_R_SYM (irel
[1].r_info
) - info
->symtab_hdr
->sh_info
;
1788 lit_h
= alpha_elf_sym_hashes (info
->abfd
)[indx
];
1790 while (lit_h
->root
.root
.type
== bfd_link_hash_indirect
1791 || lit_h
->root
.root
.type
== bfd_link_hash_warning
)
1792 lit_h
= (struct alpha_elf_link_hash_entry
*) lit_h
->root
.root
.u
.i
.link
;
1794 for (lit_gotent
= lit_h
->got_entries
; lit_gotent
;
1795 lit_gotent
= lit_gotent
->next
)
1796 if (lit_gotent
->gotobj
== info
->gotobj
1797 && lit_gotent
->reloc_type
== R_ALPHA_LITERAL
1798 && lit_gotent
->addend
== irel
[1].r_addend
)
1800 BFD_ASSERT (lit_gotent
);
1802 if (--lit_gotent
->use_count
== 0)
1804 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
1805 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1811 lda $16,x($gp) !tlsgd!1
1812 ldq $27,__tls_get_addr($gp) !literal!1
1813 jsr $26,($27)__tls_get_addr !lituse_tlsgd!1
1814 ldah $29,0($26) !gpdisp!2
1815 lda $29,0($29) !gpdisp!2
1817 ldq $16,x($gp) !gottprel
1822 or the first pair to
1823 lda $16,x($gp) !tprel
1826 ldah $16,x($gp) !tprelhi
1827 lda $16,x($16) !tprello
1831 use_gottprel
= FALSE
;
1832 new_symndx
= is_gd
? ELF64_R_SYM (irel
->r_info
) : 0;
1833 switch (!dynamic
&& !info
->link_info
->shared
)
1838 bfd_signed_vma disp
;
1840 BFD_ASSERT (elf_hash_table (info
->link_info
)->tls_sec
!= NULL
);
1841 tp_base
= alpha_get_tprel_base (info
->link_info
);
1842 disp
= symval
- tp_base
;
1844 if (disp
>= -0x8000 && disp
< 0x8000)
1846 insn
= (OP_LDA
<< 26) | (16 << 21) | (31 << 16);
1847 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1848 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
1850 irel
[0].r_offset
= pos
[0] - info
->contents
;
1851 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPREL16
);
1852 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1855 else if (disp
>= -(bfd_signed_vma
) 0x80000000
1856 && disp
< (bfd_signed_vma
) 0x7fff8000
1859 insn
= (OP_LDAH
<< 26) | (16 << 21) | (31 << 16);
1860 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1861 insn
= (OP_LDA
<< 26) | (16 << 21) | (16 << 16);
1862 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[1]);
1864 irel
[0].r_offset
= pos
[0] - info
->contents
;
1865 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELHI
);
1866 irel
[1].r_offset
= pos
[1] - info
->contents
;
1867 irel
[1].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELLO
);
1874 use_gottprel
= TRUE
;
1876 insn
= (OP_LDQ
<< 26) | (16 << 21) | (29 << 16);
1877 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1878 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
1880 irel
[0].r_offset
= pos
[0] - info
->contents
;
1881 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_GOTTPREL
);
1882 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1886 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_RDUNIQ
, pos
[2]);
1888 insn
= INSN_ADDQ
| (16 << 21) | (0 << 16) | (0 << 0);
1889 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[3]);
1891 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[4]);
1893 irel
[2].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1894 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1896 hint
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
1897 irel
[2].r_offset
, R_ALPHA_HINT
);
1899 hint
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1901 info
->changed_contents
= TRUE
;
1902 info
->changed_relocs
= TRUE
;
1904 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
1905 if (--info
->gotent
->use_count
== 0)
1907 int sz
= alpha_got_entry_size (info
->gotent
->reloc_type
);
1908 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1910 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1913 /* If we've switched to a GOTTPREL relocation, increment the reference
1914 count on that got entry. */
1917 struct alpha_elf_got_entry
*tprel_gotent
;
1919 for (tprel_gotent
= *info
->first_gotent
; tprel_gotent
;
1920 tprel_gotent
= tprel_gotent
->next
)
1921 if (tprel_gotent
->gotobj
== info
->gotobj
1922 && tprel_gotent
->reloc_type
== R_ALPHA_GOTTPREL
1923 && tprel_gotent
->addend
== irel
->r_addend
)
1926 tprel_gotent
->use_count
++;
1929 if (info
->gotent
->use_count
== 0)
1930 tprel_gotent
= info
->gotent
;
1933 tprel_gotent
= (struct alpha_elf_got_entry
*)
1934 bfd_alloc (info
->abfd
, sizeof (struct alpha_elf_got_entry
));
1938 tprel_gotent
->next
= *info
->first_gotent
;
1939 *info
->first_gotent
= tprel_gotent
;
1941 tprel_gotent
->gotobj
= info
->gotobj
;
1942 tprel_gotent
->addend
= irel
->r_addend
;
1943 tprel_gotent
->got_offset
= -1;
1944 tprel_gotent
->reloc_done
= 0;
1945 tprel_gotent
->reloc_xlated
= 0;
1948 tprel_gotent
->use_count
= 1;
1949 tprel_gotent
->reloc_type
= R_ALPHA_GOTTPREL
;
1957 elf64_alpha_relax_section (abfd
, sec
, link_info
, again
)
1960 struct bfd_link_info
*link_info
;
1963 Elf_Internal_Shdr
*symtab_hdr
;
1964 Elf_Internal_Rela
*internal_relocs
;
1965 Elf_Internal_Rela
*irel
, *irelend
;
1966 Elf_Internal_Sym
*isymbuf
= NULL
;
1967 struct alpha_elf_got_entry
**local_got_entries
;
1968 struct alpha_relax_info info
;
1970 /* We are not currently changing any sizes, so only one pass. */
1973 if (link_info
->relocatable
1974 || (sec
->flags
& SEC_RELOC
) == 0
1975 || sec
->reloc_count
== 0)
1978 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1979 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
1981 /* Load the relocations for this section. */
1982 internal_relocs
= (_bfd_elf_link_read_relocs
1983 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1984 link_info
->keep_memory
));
1985 if (internal_relocs
== NULL
)
1988 memset(&info
, 0, sizeof (info
));
1991 info
.link_info
= link_info
;
1992 info
.symtab_hdr
= symtab_hdr
;
1993 info
.relocs
= internal_relocs
;
1994 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
1996 /* Find the GP for this object. Do not store the result back via
1997 _bfd_set_gp_value, since this could change again before final. */
1998 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
2001 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
2002 info
.gp
= (sgot
->output_section
->vma
2003 + sgot
->output_offset
2007 /* Get the section contents. */
2008 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2009 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
2012 if (!bfd_malloc_and_get_section (abfd
, sec
, &info
.contents
))
2016 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2019 struct alpha_elf_got_entry
*gotent
;
2020 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
2021 unsigned long r_symndx
= ELF64_R_SYM (irel
->r_info
);
2023 /* Early exit for unhandled or unrelaxable relocations. */
2026 case R_ALPHA_LITERAL
:
2027 case R_ALPHA_GPRELHIGH
:
2028 case R_ALPHA_GPRELLOW
:
2029 case R_ALPHA_GOTDTPREL
:
2030 case R_ALPHA_GOTTPREL
:
2034 case R_ALPHA_TLSLDM
:
2035 /* The symbol for a TLSLDM reloc is ignored. Collapse the
2036 reloc to the 0 symbol so that they all match. */
2044 /* Get the value of the symbol referred to by the reloc. */
2045 if (r_symndx
< symtab_hdr
->sh_info
)
2047 /* A local symbol. */
2048 Elf_Internal_Sym
*isym
;
2050 /* Read this BFD's local symbols. */
2051 if (isymbuf
== NULL
)
2053 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2054 if (isymbuf
== NULL
)
2055 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2056 symtab_hdr
->sh_info
, 0,
2058 if (isymbuf
== NULL
)
2062 isym
= isymbuf
+ r_symndx
;
2064 /* Given the symbol for a TLSLDM reloc is ignored, this also
2065 means forcing the symbol value to the tp base. */
2066 if (r_type
== R_ALPHA_TLSLDM
)
2068 info
.tsec
= bfd_abs_section_ptr
;
2069 symval
= alpha_get_tprel_base (info
.link_info
);
2073 symval
= isym
->st_value
;
2074 if (isym
->st_shndx
== SHN_UNDEF
)
2076 else if (isym
->st_shndx
== SHN_ABS
)
2077 info
.tsec
= bfd_abs_section_ptr
;
2078 else if (isym
->st_shndx
== SHN_COMMON
)
2079 info
.tsec
= bfd_com_section_ptr
;
2081 info
.tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2085 info
.other
= isym
->st_other
;
2086 if (local_got_entries
)
2087 info
.first_gotent
= &local_got_entries
[r_symndx
];
2090 info
.first_gotent
= &info
.gotent
;
2097 struct alpha_elf_link_hash_entry
*h
;
2099 indx
= r_symndx
- symtab_hdr
->sh_info
;
2100 h
= alpha_elf_sym_hashes (abfd
)[indx
];
2101 BFD_ASSERT (h
!= NULL
);
2103 while (h
->root
.root
.type
== bfd_link_hash_indirect
2104 || h
->root
.root
.type
== bfd_link_hash_warning
)
2105 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2107 /* If the symbol is undefined, we can't do anything with it. */
2108 if (h
->root
.root
.type
== bfd_link_hash_undefweak
2109 || h
->root
.root
.type
== bfd_link_hash_undefined
)
2112 /* If the symbol isn't defined in the current module, again
2113 we can't do anything. */
2114 if (!h
->root
.def_regular
)
2116 /* Except for TLSGD relocs, which can sometimes be
2117 relaxed to GOTTPREL relocs. */
2118 if (r_type
!= R_ALPHA_TLSGD
)
2120 info
.tsec
= bfd_abs_section_ptr
;
2125 info
.tsec
= h
->root
.root
.u
.def
.section
;
2126 symval
= h
->root
.root
.u
.def
.value
;
2130 info
.other
= h
->root
.other
;
2131 info
.first_gotent
= &h
->got_entries
;
2134 /* Search for the got entry to be used by this relocation. */
2135 for (gotent
= *info
.first_gotent
; gotent
; gotent
= gotent
->next
)
2136 if (gotent
->gotobj
== info
.gotobj
2137 && gotent
->reloc_type
== r_type
2138 && gotent
->addend
== irel
->r_addend
)
2140 info
.gotent
= gotent
;
2142 symval
+= info
.tsec
->output_section
->vma
+ info
.tsec
->output_offset
;
2143 symval
+= irel
->r_addend
;
2147 case R_ALPHA_LITERAL
:
2148 BFD_ASSERT(info
.gotent
!= NULL
);
2150 /* If there exist LITUSE relocations immediately following, this
2151 opens up all sorts of interesting optimizations, because we
2152 now know every location that this address load is used. */
2153 if (irel
+1 < irelend
2154 && ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
2156 if (!elf64_alpha_relax_with_lituse (&info
, symval
, irel
))
2161 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
2166 case R_ALPHA_GPRELHIGH
:
2167 case R_ALPHA_GPRELLOW
:
2168 if (!elf64_alpha_relax_gprelhilo (&info
, symval
, irel
,
2169 r_type
== R_ALPHA_GPRELHIGH
))
2173 case R_ALPHA_GOTDTPREL
:
2174 case R_ALPHA_GOTTPREL
:
2175 BFD_ASSERT(info
.gotent
!= NULL
);
2176 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
2181 case R_ALPHA_TLSLDM
:
2182 BFD_ASSERT(info
.gotent
!= NULL
);
2183 if (!elf64_alpha_relax_tls_get_addr (&info
, symval
, irel
,
2184 r_type
== R_ALPHA_TLSGD
))
2190 if (!elf64_alpha_size_plt_section (link_info
))
2192 if (!elf64_alpha_size_got_sections (link_info
))
2194 if (!elf64_alpha_size_rela_got_section (link_info
))
2198 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2200 if (!link_info
->keep_memory
)
2204 /* Cache the symbols for elf_link_input_bfd. */
2205 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2209 if (info
.contents
!= NULL
2210 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
2212 if (!info
.changed_contents
&& !link_info
->keep_memory
)
2213 free (info
.contents
);
2216 /* Cache the section contents for elf_link_input_bfd. */
2217 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
2221 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2223 if (!info
.changed_relocs
)
2224 free (internal_relocs
);
2226 elf_section_data (sec
)->relocs
= internal_relocs
;
2229 *again
= info
.changed_contents
|| info
.changed_relocs
;
2235 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2237 if (info
.contents
!= NULL
2238 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
2239 free (info
.contents
);
2240 if (internal_relocs
!= NULL
2241 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2242 free (internal_relocs
);
2247 #define PLT_HEADER_SIZE 32
2248 #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */
2249 #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */
2250 #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */
2251 #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */
2253 #define PLT_ENTRY_SIZE 12
2254 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
2255 #define PLT_ENTRY_WORD2 0
2256 #define PLT_ENTRY_WORD3 0
2258 #define MAX_GOT_SIZE (64*1024)
2260 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
2262 /* Handle an Alpha specific section when reading an object file. This
2263 is called when elfcode.h finds a section with an unknown type.
2264 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
2268 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
2270 Elf_Internal_Shdr
*hdr
;
2275 /* There ought to be a place to keep ELF backend specific flags, but
2276 at the moment there isn't one. We just keep track of the
2277 sections by their name, instead. Fortunately, the ABI gives
2278 suggested names for all the MIPS specific sections, so we will
2279 probably get away with this. */
2280 switch (hdr
->sh_type
)
2282 case SHT_ALPHA_DEBUG
:
2283 if (strcmp (name
, ".mdebug") != 0)
2290 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2292 newsect
= hdr
->bfd_section
;
2294 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
2296 if (! bfd_set_section_flags (abfd
, newsect
,
2297 (bfd_get_section_flags (abfd
, newsect
)
2305 /* Convert Alpha specific section flags to bfd internal section flags. */
2308 elf64_alpha_section_flags (flags
, hdr
)
2310 const Elf_Internal_Shdr
*hdr
;
2312 if (hdr
->sh_flags
& SHF_ALPHA_GPREL
)
2313 *flags
|= SEC_SMALL_DATA
;
2318 /* Set the correct type for an Alpha ELF section. We do this by the
2319 section name, which is a hack, but ought to work. */
2322 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
2324 Elf_Internal_Shdr
*hdr
;
2327 register const char *name
;
2329 name
= bfd_get_section_name (abfd
, sec
);
2331 if (strcmp (name
, ".mdebug") == 0)
2333 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
2334 /* In a shared object on Irix 5.3, the .mdebug section has an
2335 entsize of 0. FIXME: Does this matter? */
2336 if ((abfd
->flags
& DYNAMIC
) != 0 )
2337 hdr
->sh_entsize
= 0;
2339 hdr
->sh_entsize
= 1;
2341 else if ((sec
->flags
& SEC_SMALL_DATA
)
2342 || strcmp (name
, ".sdata") == 0
2343 || strcmp (name
, ".sbss") == 0
2344 || strcmp (name
, ".lit4") == 0
2345 || strcmp (name
, ".lit8") == 0)
2346 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
2351 /* Hook called by the linker routine which adds symbols from an object
2352 file. We use it to put .comm items in .sbss, and not .bss. */
2355 elf64_alpha_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2357 struct bfd_link_info
*info
;
2358 Elf_Internal_Sym
*sym
;
2359 const char **namep ATTRIBUTE_UNUSED
;
2360 flagword
*flagsp ATTRIBUTE_UNUSED
;
2364 if (sym
->st_shndx
== SHN_COMMON
2365 && !info
->relocatable
2366 && sym
->st_size
<= elf_gp_size (abfd
))
2368 /* Common symbols less than or equal to -G nn bytes are
2369 automatically put into .sbss. */
2371 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
2375 scomm
= bfd_make_section (abfd
, ".scommon");
2377 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
2379 | SEC_LINKER_CREATED
)))
2384 *valp
= sym
->st_size
;
2390 /* Create the .got section. */
2393 elf64_alpha_create_got_section(abfd
, info
)
2395 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2399 if ((s
= bfd_get_section_by_name (abfd
, ".got")))
2401 /* Check for a non-linker created .got? */
2402 if (alpha_elf_tdata (abfd
)->got
== NULL
)
2403 alpha_elf_tdata (abfd
)->got
= s
;
2407 s
= bfd_make_section (abfd
, ".got");
2409 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2412 | SEC_LINKER_CREATED
))
2413 || !bfd_set_section_alignment (abfd
, s
, 3))
2416 alpha_elf_tdata (abfd
)->got
= s
;
2421 /* Create all the dynamic sections. */
2424 elf64_alpha_create_dynamic_sections (abfd
, info
)
2426 struct bfd_link_info
*info
;
2429 struct elf_link_hash_entry
*h
;
2430 struct bfd_link_hash_entry
*bh
;
2432 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
2434 s
= bfd_make_section (abfd
, ".plt");
2436 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2439 | SEC_LINKER_CREATED
2441 || ! bfd_set_section_alignment (abfd
, s
, 3))
2444 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2447 if (! (_bfd_generic_link_add_one_symbol
2448 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
2449 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
2450 get_elf_backend_data (abfd
)->collect
, &bh
)))
2452 h
= (struct elf_link_hash_entry
*) bh
;
2454 h
->type
= STT_OBJECT
;
2457 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2460 s
= bfd_make_section (abfd
, ".rela.plt");
2462 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2465 | SEC_LINKER_CREATED
2467 || ! bfd_set_section_alignment (abfd
, s
, 3))
2470 /* We may or may not have created a .got section for this object, but
2471 we definitely havn't done the rest of the work. */
2473 if (!elf64_alpha_create_got_section (abfd
, info
))
2476 s
= bfd_make_section(abfd
, ".rela.got");
2478 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2481 | SEC_LINKER_CREATED
2483 || !bfd_set_section_alignment (abfd
, s
, 3))
2486 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
2487 dynobj's .got section. We don't do this in the linker script
2488 because we don't want to define the symbol if we are not creating
2489 a global offset table. */
2491 if (!(_bfd_generic_link_add_one_symbol
2492 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
,
2493 alpha_elf_tdata(abfd
)->got
, (bfd_vma
) 0, (const char *) NULL
,
2494 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2496 h
= (struct elf_link_hash_entry
*) bh
;
2498 h
->type
= STT_OBJECT
;
2501 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2504 elf_hash_table (info
)->hgot
= h
;
2509 /* Read ECOFF debugging information from a .mdebug section into a
2510 ecoff_debug_info structure. */
2513 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
2516 struct ecoff_debug_info
*debug
;
2519 const struct ecoff_debug_swap
*swap
;
2520 char *ext_hdr
= NULL
;
2522 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2523 memset (debug
, 0, sizeof (*debug
));
2525 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
2526 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2529 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2530 swap
->external_hdr_size
))
2533 symhdr
= &debug
->symbolic_header
;
2534 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2536 /* The symbolic header contains absolute file offsets and sizes to
2538 #define READ(ptr, offset, count, size, type) \
2539 if (symhdr->count == 0) \
2540 debug->ptr = NULL; \
2543 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
2544 debug->ptr = (type) bfd_malloc (amt); \
2545 if (debug->ptr == NULL) \
2546 goto error_return; \
2547 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2548 || bfd_bread (debug->ptr, amt, abfd) != amt) \
2549 goto error_return; \
2552 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2553 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2554 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2555 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2556 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2557 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2559 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2560 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2561 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2562 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2563 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2571 if (ext_hdr
!= NULL
)
2573 if (debug
->line
!= NULL
)
2575 if (debug
->external_dnr
!= NULL
)
2576 free (debug
->external_dnr
);
2577 if (debug
->external_pdr
!= NULL
)
2578 free (debug
->external_pdr
);
2579 if (debug
->external_sym
!= NULL
)
2580 free (debug
->external_sym
);
2581 if (debug
->external_opt
!= NULL
)
2582 free (debug
->external_opt
);
2583 if (debug
->external_aux
!= NULL
)
2584 free (debug
->external_aux
);
2585 if (debug
->ss
!= NULL
)
2587 if (debug
->ssext
!= NULL
)
2588 free (debug
->ssext
);
2589 if (debug
->external_fdr
!= NULL
)
2590 free (debug
->external_fdr
);
2591 if (debug
->external_rfd
!= NULL
)
2592 free (debug
->external_rfd
);
2593 if (debug
->external_ext
!= NULL
)
2594 free (debug
->external_ext
);
2598 /* Alpha ELF local labels start with '$'. */
2601 elf64_alpha_is_local_label_name (abfd
, name
)
2602 bfd
*abfd ATTRIBUTE_UNUSED
;
2605 return name
[0] == '$';
2608 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2609 routine in order to handle the ECOFF debugging information. We
2610 still call this mips_elf_find_line because of the slot
2611 find_line_info in elf_obj_tdata is declared that way. */
2613 struct mips_elf_find_line
2615 struct ecoff_debug_info d
;
2616 struct ecoff_find_line i
;
2620 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2621 functionname_ptr
, line_ptr
)
2626 const char **filename_ptr
;
2627 const char **functionname_ptr
;
2628 unsigned int *line_ptr
;
2632 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
2633 filename_ptr
, functionname_ptr
,
2635 &elf_tdata (abfd
)->dwarf2_find_line_info
))
2638 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2642 struct mips_elf_find_line
*fi
;
2643 const struct ecoff_debug_swap
* const swap
=
2644 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2646 /* If we are called during a link, alpha_elf_final_link may have
2647 cleared the SEC_HAS_CONTENTS field. We force it back on here
2648 if appropriate (which it normally will be). */
2649 origflags
= msec
->flags
;
2650 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2651 msec
->flags
|= SEC_HAS_CONTENTS
;
2653 fi
= elf_tdata (abfd
)->find_line_info
;
2656 bfd_size_type external_fdr_size
;
2659 struct fdr
*fdr_ptr
;
2660 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
2662 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
2665 msec
->flags
= origflags
;
2669 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
2671 msec
->flags
= origflags
;
2675 /* Swap in the FDR information. */
2676 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
2677 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
2678 if (fi
->d
.fdr
== NULL
)
2680 msec
->flags
= origflags
;
2683 external_fdr_size
= swap
->external_fdr_size
;
2684 fdr_ptr
= fi
->d
.fdr
;
2685 fraw_src
= (char *) fi
->d
.external_fdr
;
2686 fraw_end
= (fraw_src
2687 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2688 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2689 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2691 elf_tdata (abfd
)->find_line_info
= fi
;
2693 /* Note that we don't bother to ever free this information.
2694 find_nearest_line is either called all the time, as in
2695 objdump -l, so the information should be saved, or it is
2696 rarely called, as in ld error messages, so the memory
2697 wasted is unimportant. Still, it would probably be a
2698 good idea for free_cached_info to throw it away. */
2701 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2702 &fi
->i
, filename_ptr
, functionname_ptr
,
2705 msec
->flags
= origflags
;
2709 msec
->flags
= origflags
;
2712 /* Fall back on the generic ELF find_nearest_line routine. */
2714 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2715 filename_ptr
, functionname_ptr
,
2719 /* Structure used to pass information to alpha_elf_output_extsym. */
2724 struct bfd_link_info
*info
;
2725 struct ecoff_debug_info
*debug
;
2726 const struct ecoff_debug_swap
*swap
;
2731 elf64_alpha_output_extsym (h
, data
)
2732 struct alpha_elf_link_hash_entry
*h
;
2735 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2737 asection
*sec
, *output_section
;
2739 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2740 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2742 if (h
->root
.indx
== -2)
2744 else if ((h
->root
.def_dynamic
2745 || h
->root
.ref_dynamic
2746 || h
->root
.root
.type
== bfd_link_hash_new
)
2747 && !h
->root
.def_regular
2748 && !h
->root
.ref_regular
)
2750 else if (einfo
->info
->strip
== strip_all
2751 || (einfo
->info
->strip
== strip_some
2752 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2753 h
->root
.root
.root
.string
,
2754 FALSE
, FALSE
) == NULL
))
2762 if (h
->esym
.ifd
== -2)
2765 h
->esym
.cobol_main
= 0;
2766 h
->esym
.weakext
= 0;
2767 h
->esym
.reserved
= 0;
2768 h
->esym
.ifd
= ifdNil
;
2769 h
->esym
.asym
.value
= 0;
2770 h
->esym
.asym
.st
= stGlobal
;
2772 if (h
->root
.root
.type
!= bfd_link_hash_defined
2773 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2774 h
->esym
.asym
.sc
= scAbs
;
2779 sec
= h
->root
.root
.u
.def
.section
;
2780 output_section
= sec
->output_section
;
2782 /* When making a shared library and symbol h is the one from
2783 the another shared library, OUTPUT_SECTION may be null. */
2784 if (output_section
== NULL
)
2785 h
->esym
.asym
.sc
= scUndefined
;
2788 name
= bfd_section_name (output_section
->owner
, output_section
);
2790 if (strcmp (name
, ".text") == 0)
2791 h
->esym
.asym
.sc
= scText
;
2792 else if (strcmp (name
, ".data") == 0)
2793 h
->esym
.asym
.sc
= scData
;
2794 else if (strcmp (name
, ".sdata") == 0)
2795 h
->esym
.asym
.sc
= scSData
;
2796 else if (strcmp (name
, ".rodata") == 0
2797 || strcmp (name
, ".rdata") == 0)
2798 h
->esym
.asym
.sc
= scRData
;
2799 else if (strcmp (name
, ".bss") == 0)
2800 h
->esym
.asym
.sc
= scBss
;
2801 else if (strcmp (name
, ".sbss") == 0)
2802 h
->esym
.asym
.sc
= scSBss
;
2803 else if (strcmp (name
, ".init") == 0)
2804 h
->esym
.asym
.sc
= scInit
;
2805 else if (strcmp (name
, ".fini") == 0)
2806 h
->esym
.asym
.sc
= scFini
;
2808 h
->esym
.asym
.sc
= scAbs
;
2812 h
->esym
.asym
.reserved
= 0;
2813 h
->esym
.asym
.index
= indexNil
;
2816 if (h
->root
.root
.type
== bfd_link_hash_common
)
2817 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2818 else if (h
->root
.root
.type
== bfd_link_hash_defined
2819 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2821 if (h
->esym
.asym
.sc
== scCommon
)
2822 h
->esym
.asym
.sc
= scBss
;
2823 else if (h
->esym
.asym
.sc
== scSCommon
)
2824 h
->esym
.asym
.sc
= scSBss
;
2826 sec
= h
->root
.root
.u
.def
.section
;
2827 output_section
= sec
->output_section
;
2828 if (output_section
!= NULL
)
2829 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2830 + sec
->output_offset
2831 + output_section
->vma
);
2833 h
->esym
.asym
.value
= 0;
2835 else if (h
->root
.needs_plt
)
2837 /* Set type and value for a symbol with a function stub. */
2838 h
->esym
.asym
.st
= stProc
;
2839 sec
= bfd_get_section_by_name (einfo
->abfd
, ".plt");
2841 h
->esym
.asym
.value
= 0;
2844 output_section
= sec
->output_section
;
2845 if (output_section
!= NULL
)
2846 h
->esym
.asym
.value
= (h
->root
.plt
.offset
2847 + sec
->output_offset
2848 + output_section
->vma
);
2850 h
->esym
.asym
.value
= 0;
2854 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2855 h
->root
.root
.root
.string
,
2858 einfo
->failed
= TRUE
;
2865 /* Search for and possibly create a got entry. */
2867 static struct alpha_elf_got_entry
*
2868 get_got_entry (abfd
, h
, r_type
, r_symndx
, r_addend
)
2870 struct alpha_elf_link_hash_entry
*h
;
2871 unsigned long r_type
, r_symndx
;
2874 struct alpha_elf_got_entry
*gotent
;
2875 struct alpha_elf_got_entry
**slot
;
2878 slot
= &h
->got_entries
;
2881 /* This is a local .got entry -- record for merge. */
2883 struct alpha_elf_got_entry
**local_got_entries
;
2885 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2886 if (!local_got_entries
)
2889 Elf_Internal_Shdr
*symtab_hdr
;
2891 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
2892 size
= symtab_hdr
->sh_info
;
2893 size
*= sizeof (struct alpha_elf_got_entry
*);
2896 = (struct alpha_elf_got_entry
**) bfd_zalloc (abfd
, size
);
2897 if (!local_got_entries
)
2900 alpha_elf_tdata (abfd
)->local_got_entries
= local_got_entries
;
2903 slot
= &local_got_entries
[r_symndx
];
2906 for (gotent
= *slot
; gotent
; gotent
= gotent
->next
)
2907 if (gotent
->gotobj
== abfd
2908 && gotent
->reloc_type
== r_type
2909 && gotent
->addend
== r_addend
)
2917 amt
= sizeof (struct alpha_elf_got_entry
);
2918 gotent
= (struct alpha_elf_got_entry
*) bfd_alloc (abfd
, amt
);
2922 gotent
->gotobj
= abfd
;
2923 gotent
->addend
= r_addend
;
2924 gotent
->got_offset
= -1;
2925 gotent
->use_count
= 1;
2926 gotent
->reloc_type
= r_type
;
2927 gotent
->reloc_done
= 0;
2928 gotent
->reloc_xlated
= 0;
2930 gotent
->next
= *slot
;
2933 entry_size
= alpha_got_entry_size (r_type
);
2934 alpha_elf_tdata (abfd
)->total_got_size
+= entry_size
;
2936 alpha_elf_tdata(abfd
)->local_got_size
+= entry_size
;
2939 gotent
->use_count
+= 1;
2944 /* Handle dynamic relocations when doing an Alpha ELF link. */
2947 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
2949 struct bfd_link_info
*info
;
2951 const Elf_Internal_Rela
*relocs
;
2955 const char *rel_sec_name
;
2956 Elf_Internal_Shdr
*symtab_hdr
;
2957 struct alpha_elf_link_hash_entry
**sym_hashes
;
2958 const Elf_Internal_Rela
*rel
, *relend
;
2959 bfd_boolean got_created
;
2962 if (info
->relocatable
)
2965 dynobj
= elf_hash_table(info
)->dynobj
;
2967 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
2970 rel_sec_name
= NULL
;
2971 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
2972 sym_hashes
= alpha_elf_sym_hashes(abfd
);
2973 got_created
= FALSE
;
2975 relend
= relocs
+ sec
->reloc_count
;
2976 for (rel
= relocs
; rel
< relend
; ++rel
)
2984 unsigned long r_symndx
, r_type
;
2985 struct alpha_elf_link_hash_entry
*h
;
2986 unsigned int gotent_flags
;
2987 bfd_boolean maybe_dynamic
;
2991 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2992 if (r_symndx
< symtab_hdr
->sh_info
)
2996 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2998 while (h
->root
.root
.type
== bfd_link_hash_indirect
2999 || h
->root
.root
.type
== bfd_link_hash_warning
)
3000 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3002 h
->root
.ref_regular
= 1;
3005 /* We can only get preliminary data on whether a symbol is
3006 locally or externally defined, as not all of the input files
3007 have yet been processed. Do something with what we know, as
3008 this may help reduce memory usage and processing time later. */
3009 maybe_dynamic
= FALSE
;
3010 if (h
&& ((info
->shared
3011 && (!info
->symbolic
|| info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
3012 || !h
->root
.def_regular
3013 || h
->root
.root
.type
== bfd_link_hash_defweak
))
3014 maybe_dynamic
= TRUE
;
3018 r_type
= ELF64_R_TYPE (rel
->r_info
);
3019 addend
= rel
->r_addend
;
3023 case R_ALPHA_LITERAL
:
3024 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3026 /* Remember how this literal is used from its LITUSEs.
3027 This will be important when it comes to decide if we can
3028 create a .plt entry for a function symbol. */
3029 while (++rel
< relend
&& ELF64_R_TYPE (rel
->r_info
) == R_ALPHA_LITUSE
)
3030 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 5)
3031 gotent_flags
|= 1 << rel
->r_addend
;
3034 /* No LITUSEs -- presumably the address is used somehow. */
3035 if (gotent_flags
== 0)
3036 gotent_flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
3039 case R_ALPHA_GPDISP
:
3040 case R_ALPHA_GPREL16
:
3041 case R_ALPHA_GPREL32
:
3042 case R_ALPHA_GPRELHIGH
:
3043 case R_ALPHA_GPRELLOW
:
3048 case R_ALPHA_REFLONG
:
3049 case R_ALPHA_REFQUAD
:
3050 if ((info
->shared
&& (sec
->flags
& SEC_ALLOC
)) || maybe_dynamic
)
3054 case R_ALPHA_TLSLDM
:
3055 /* The symbol for a TLSLDM reloc is ignored. Collapse the
3056 reloc to the 0 symbol so that they all match. */
3059 maybe_dynamic
= FALSE
;
3063 case R_ALPHA_GOTDTPREL
:
3064 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3067 case R_ALPHA_GOTTPREL
:
3068 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3069 gotent_flags
= ALPHA_ELF_LINK_HASH_TLS_IE
;
3071 info
->flags
|= DF_STATIC_TLS
;
3074 case R_ALPHA_TPREL64
:
3075 if (info
->shared
|| maybe_dynamic
)
3078 info
->flags
|= DF_STATIC_TLS
;
3082 if (need
& NEED_GOT
)
3086 if (!elf64_alpha_create_got_section (abfd
, info
))
3089 /* Make sure the object's gotobj is set to itself so
3090 that we default to every object with its own .got.
3091 We'll merge .gots later once we've collected each
3093 alpha_elf_tdata(abfd
)->gotobj
= abfd
;
3099 if (need
& NEED_GOT_ENTRY
)
3101 struct alpha_elf_got_entry
*gotent
;
3103 gotent
= get_got_entry (abfd
, h
, r_type
, r_symndx
, addend
);
3109 gotent
->flags
|= gotent_flags
;
3112 gotent_flags
|= h
->flags
;
3113 h
->flags
= gotent_flags
;
3115 /* Make a guess as to whether a .plt entry is needed. */
3116 if ((gotent_flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
)
3117 && !(gotent_flags
& ~ALPHA_ELF_LINK_HASH_LU_FUNC
))
3118 h
->root
.needs_plt
= 1;
3120 h
->root
.needs_plt
= 0;
3125 if (need
& NEED_DYNREL
)
3127 if (rel_sec_name
== NULL
)
3129 rel_sec_name
= (bfd_elf_string_from_elf_section
3130 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
3131 elf_section_data(sec
)->rel_hdr
.sh_name
));
3132 if (rel_sec_name
== NULL
)
3135 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
3136 && strcmp (bfd_get_section_name (abfd
, sec
),
3137 rel_sec_name
+5) == 0);
3140 /* We need to create the section here now whether we eventually
3141 use it or not so that it gets mapped to an output section by
3142 the linker. If not used, we'll kill it in
3143 size_dynamic_sections. */
3146 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
3151 sreloc
= bfd_make_section (dynobj
, rel_sec_name
);
3152 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3153 | SEC_LINKER_CREATED
| SEC_READONLY
);
3154 if (sec
->flags
& SEC_ALLOC
)
3155 flags
|= SEC_ALLOC
| SEC_LOAD
;
3157 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
3158 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
3165 /* Since we havn't seen all of the input symbols yet, we
3166 don't know whether we'll actually need a dynamic relocation
3167 entry for this reloc. So make a record of it. Once we
3168 find out if this thing needs dynamic relocation we'll
3169 expand the relocation sections by the appropriate amount. */
3171 struct alpha_elf_reloc_entry
*rent
;
3173 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
3174 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
3179 amt
= sizeof (struct alpha_elf_reloc_entry
);
3180 rent
= (struct alpha_elf_reloc_entry
*) bfd_alloc (abfd
, amt
);
3184 rent
->srel
= sreloc
;
3185 rent
->rtype
= r_type
;
3187 rent
->reltext
= ((sec
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3188 == (SEC_READONLY
| SEC_ALLOC
));
3190 rent
->next
= h
->reloc_entries
;
3191 h
->reloc_entries
= rent
;
3196 else if (info
->shared
)
3198 /* If this is a shared library, and the section is to be
3199 loaded into memory, we need a RELATIVE reloc. */
3200 sreloc
->size
+= sizeof (Elf64_External_Rela
);
3201 if ((sec
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3202 == (SEC_READONLY
| SEC_ALLOC
))
3203 info
->flags
|= DF_TEXTREL
;
3211 /* Adjust a symbol defined by a dynamic object and referenced by a
3212 regular object. The current definition is in some section of the
3213 dynamic object, but we're not including those sections. We have to
3214 change the definition to something the rest of the link can
3218 elf64_alpha_adjust_dynamic_symbol (info
, h
)
3219 struct bfd_link_info
*info
;
3220 struct elf_link_hash_entry
*h
;
3224 struct alpha_elf_link_hash_entry
*ah
;
3226 dynobj
= elf_hash_table(info
)->dynobj
;
3227 ah
= (struct alpha_elf_link_hash_entry
*)h
;
3229 /* Now that we've seen all of the input symbols, finalize our decision
3230 about whether this symbol should get a .plt entry. */
3232 if (alpha_elf_dynamic_symbol_p (h
, info
)
3233 && ((h
->type
== STT_FUNC
3234 && !(ah
->flags
& ALPHA_ELF_LINK_HASH_LU_ADDR
))
3235 || (h
->type
== STT_NOTYPE
3236 && (ah
->flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
)
3237 && !(ah
->flags
& ~ALPHA_ELF_LINK_HASH_LU_FUNC
)))
3238 /* Don't prevent otherwise valid programs from linking by attempting
3239 to create a new .got entry somewhere. A Correct Solution would be
3240 to add a new .got section to a new object file and let it be merged
3241 somewhere later. But for now don't bother. */
3246 s
= bfd_get_section_by_name(dynobj
, ".plt");
3247 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
3250 /* The first bit of the .plt is reserved. */
3252 s
->size
= PLT_HEADER_SIZE
;
3254 h
->plt
.offset
= s
->size
;
3255 s
->size
+= PLT_ENTRY_SIZE
;
3257 /* If this symbol is not defined in a regular file, and we are not
3258 generating a shared library, then set the symbol to the location
3259 in the .plt. This is required to make function pointers compare
3260 equal between the normal executable and the shared library. */
3262 && h
->root
.type
!= bfd_link_hash_defweak
)
3264 ah
->plt_old_section
= h
->root
.u
.def
.section
;
3265 ah
->plt_old_value
= h
->root
.u
.def
.value
;
3266 ah
->flags
|= ALPHA_ELF_LINK_HASH_PLT_LOC
;
3267 h
->root
.u
.def
.section
= s
;
3268 h
->root
.u
.def
.value
= h
->plt
.offset
;
3271 /* We also need a JMP_SLOT entry in the .rela.plt section. */
3272 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3273 BFD_ASSERT (s
!= NULL
);
3274 s
->size
+= sizeof (Elf64_External_Rela
);
3281 /* If this is a weak symbol, and there is a real definition, the
3282 processor independent code will have arranged for us to see the
3283 real definition first, and we can just use the same value. */
3284 if (h
->u
.weakdef
!= NULL
)
3286 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
3287 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
3288 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
3289 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
3293 /* This is a reference to a symbol defined by a dynamic object which
3294 is not a function. The Alpha, since it uses .got entries for all
3295 symbols even in regular objects, does not need the hackery of a
3296 .dynbss section and COPY dynamic relocations. */
3301 /* Symbol versioning can create new symbols, and make our old symbols
3302 indirect to the new ones. Consolidate the got and reloc information
3303 in these situations. */
3306 elf64_alpha_merge_ind_symbols (hi
, dummy
)
3307 struct alpha_elf_link_hash_entry
*hi
;
3308 PTR dummy ATTRIBUTE_UNUSED
;
3310 struct alpha_elf_link_hash_entry
*hs
;
3312 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
3316 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
3317 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
3319 /* Merge the flags. Whee. */
3321 hs
->flags
|= hi
->flags
;
3323 /* Merge the .got entries. Cannibalize the old symbol's list in
3324 doing so, since we don't need it anymore. */
3326 if (hs
->got_entries
== NULL
)
3327 hs
->got_entries
= hi
->got_entries
;
3330 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
3332 gsh
= hs
->got_entries
;
3333 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
3336 for (gs
= gsh
; gs
; gs
= gs
->next
)
3337 if (gi
->gotobj
== gs
->gotobj
3338 && gi
->reloc_type
== gs
->reloc_type
3339 && gi
->addend
== gs
->addend
)
3341 gi
->use_count
+= gs
->use_count
;
3344 gi
->next
= hs
->got_entries
;
3345 hs
->got_entries
= gi
;
3349 hi
->got_entries
= NULL
;
3351 /* And similar for the reloc entries. */
3353 if (hs
->reloc_entries
== NULL
)
3354 hs
->reloc_entries
= hi
->reloc_entries
;
3357 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
3359 rsh
= hs
->reloc_entries
;
3360 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
3363 for (rs
= rsh
; rs
; rs
= rs
->next
)
3364 if (ri
->rtype
== rs
->rtype
&& ri
->srel
== rs
->srel
)
3366 rs
->count
+= ri
->count
;
3369 ri
->next
= hs
->reloc_entries
;
3370 hs
->reloc_entries
= ri
;
3374 hi
->reloc_entries
= NULL
;
3379 /* Is it possible to merge two object file's .got tables? */
3382 elf64_alpha_can_merge_gots (a
, b
)
3385 int total
= alpha_elf_tdata (a
)->total_got_size
;
3388 /* Trivial quick fallout test. */
3389 if (total
+ alpha_elf_tdata (b
)->total_got_size
<= MAX_GOT_SIZE
)
3392 /* By their nature, local .got entries cannot be merged. */
3393 if ((total
+= alpha_elf_tdata (b
)->local_got_size
) > MAX_GOT_SIZE
)
3396 /* Failing the common trivial comparison, we must effectively
3397 perform the merge. Not actually performing the merge means that
3398 we don't have to store undo information in case we fail. */
3399 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
3401 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes (bsub
);
3402 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
3405 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
3406 for (i
= 0; i
< n
; ++i
)
3408 struct alpha_elf_got_entry
*ae
, *be
;
3409 struct alpha_elf_link_hash_entry
*h
;
3412 while (h
->root
.root
.type
== bfd_link_hash_indirect
3413 || h
->root
.root
.type
== bfd_link_hash_warning
)
3414 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3416 for (be
= h
->got_entries
; be
; be
= be
->next
)
3418 if (be
->use_count
== 0)
3420 if (be
->gotobj
!= b
)
3423 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
3425 && ae
->reloc_type
== be
->reloc_type
3426 && ae
->addend
== be
->addend
)
3429 total
+= alpha_got_entry_size (be
->reloc_type
);
3430 if (total
> MAX_GOT_SIZE
)
3440 /* Actually merge two .got tables. */
3443 elf64_alpha_merge_gots (a
, b
)
3446 int total
= alpha_elf_tdata (a
)->total_got_size
;
3449 /* Remember local expansion. */
3451 int e
= alpha_elf_tdata (b
)->local_got_size
;
3453 alpha_elf_tdata (a
)->local_got_size
+= e
;
3456 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
3458 struct alpha_elf_got_entry
**local_got_entries
;
3459 struct alpha_elf_link_hash_entry
**hashes
;
3460 Elf_Internal_Shdr
*symtab_hdr
;
3463 /* Let the local .got entries know they are part of a new subsegment. */
3464 local_got_entries
= alpha_elf_tdata (bsub
)->local_got_entries
;
3465 if (local_got_entries
)
3467 n
= elf_tdata (bsub
)->symtab_hdr
.sh_info
;
3468 for (i
= 0; i
< n
; ++i
)
3470 struct alpha_elf_got_entry
*ent
;
3471 for (ent
= local_got_entries
[i
]; ent
; ent
= ent
->next
)
3476 /* Merge the global .got entries. */
3477 hashes
= alpha_elf_sym_hashes (bsub
);
3478 symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
3480 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
3481 for (i
= 0; i
< n
; ++i
)
3483 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
3484 struct alpha_elf_link_hash_entry
*h
;
3487 while (h
->root
.root
.type
== bfd_link_hash_indirect
3488 || h
->root
.root
.type
== bfd_link_hash_warning
)
3489 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3491 start
= &h
->got_entries
;
3492 for (pbe
= start
, be
= *start
; be
; pbe
= &be
->next
, be
= be
->next
)
3494 if (be
->use_count
== 0)
3499 if (be
->gotobj
!= b
)
3502 for (ae
= *start
; ae
; ae
= ae
->next
)
3504 && ae
->reloc_type
== be
->reloc_type
3505 && ae
->addend
== be
->addend
)
3507 ae
->flags
|= be
->flags
;
3508 ae
->use_count
+= be
->use_count
;
3513 total
+= alpha_got_entry_size (be
->reloc_type
);
3519 alpha_elf_tdata (bsub
)->gotobj
= a
;
3521 alpha_elf_tdata (a
)->total_got_size
= total
;
3523 /* Merge the two in_got chains. */
3528 while ((next
= alpha_elf_tdata (bsub
)->in_got_link_next
) != NULL
)
3531 alpha_elf_tdata (bsub
)->in_got_link_next
= b
;
3535 /* Calculate the offsets for the got entries. */
3538 elf64_alpha_calc_got_offsets_for_symbol (h
, arg
)
3539 struct alpha_elf_link_hash_entry
*h
;
3540 PTR arg ATTRIBUTE_UNUSED
;
3542 bfd_boolean result
= TRUE
;
3543 struct alpha_elf_got_entry
*gotent
;
3545 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3546 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3548 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3549 if (gotent
->use_count
> 0)
3551 struct alpha_elf_obj_tdata
*td
;
3552 bfd_size_type
*plge
;
3554 td
= alpha_elf_tdata (gotent
->gotobj
);
3557 _bfd_error_handler (_("Symbol %s has no GOT subsection for offset 0x%x"),
3558 h
->root
.root
.root
.string
, gotent
->got_offset
);
3562 plge
= &td
->got
->size
;
3563 gotent
->got_offset
= *plge
;
3564 *plge
+= alpha_got_entry_size (gotent
->reloc_type
);
3571 elf64_alpha_calc_got_offsets (info
)
3572 struct bfd_link_info
*info
;
3574 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
3576 /* First, zero out the .got sizes, as we may be recalculating the
3577 .got after optimizing it. */
3578 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3579 alpha_elf_tdata(i
)->got
->size
= 0;
3581 /* Next, fill in the offsets for all the global entries. */
3582 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3583 elf64_alpha_calc_got_offsets_for_symbol
,
3586 /* Finally, fill in the offsets for the local entries. */
3587 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3589 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->size
;
3592 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
3594 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
3597 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
3598 if (!local_got_entries
)
3601 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
3602 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
3603 if (gotent
->use_count
> 0)
3605 gotent
->got_offset
= got_offset
;
3606 got_offset
+= alpha_got_entry_size (gotent
->reloc_type
);
3610 alpha_elf_tdata(i
)->got
->size
= got_offset
;
3614 /* Constructs the gots. */
3617 elf64_alpha_size_got_sections (info
)
3618 struct bfd_link_info
*info
;
3620 bfd
*i
, *got_list
, *cur_got_obj
= NULL
;
3621 int something_changed
= 0;
3623 got_list
= alpha_elf_hash_table (info
)->got_list
;
3625 /* On the first time through, pretend we have an existing got list
3626 consisting of all of the input files. */
3627 if (got_list
== NULL
)
3629 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
3631 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
3632 if (this_got
== NULL
)
3635 /* We are assuming no merging has yet occurred. */
3636 BFD_ASSERT (this_got
== i
);
3638 if (alpha_elf_tdata (this_got
)->total_got_size
> MAX_GOT_SIZE
)
3640 /* Yikes! A single object file has too many entries. */
3641 (*_bfd_error_handler
)
3642 (_("%B: .got subsegment exceeds 64K (size %d)"),
3643 i
, alpha_elf_tdata (this_got
)->total_got_size
);
3647 if (got_list
== NULL
)
3648 got_list
= this_got
;
3650 alpha_elf_tdata(cur_got_obj
)->got_link_next
= this_got
;
3651 cur_got_obj
= this_got
;
3654 /* Strange degenerate case of no got references. */
3655 if (got_list
== NULL
)
3658 alpha_elf_hash_table (info
)->got_list
= got_list
;
3660 /* Force got offsets to be recalculated. */
3661 something_changed
= 1;
3664 cur_got_obj
= got_list
;
3665 i
= alpha_elf_tdata(cur_got_obj
)->got_link_next
;
3668 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
3670 elf64_alpha_merge_gots (cur_got_obj
, i
);
3671 i
= alpha_elf_tdata(i
)->got_link_next
;
3672 alpha_elf_tdata(cur_got_obj
)->got_link_next
= i
;
3673 something_changed
= 1;
3678 i
= alpha_elf_tdata(i
)->got_link_next
;
3682 /* Once the gots have been merged, fill in the got offsets for
3683 everything therein. */
3684 if (1 || something_changed
)
3685 elf64_alpha_calc_got_offsets (info
);
3690 /* Called from relax_section to rebuild the PLT in light of
3691 potential changes in the function's status. */
3694 elf64_alpha_size_plt_section (info
)
3695 struct bfd_link_info
*info
;
3697 asection
*splt
, *spltrel
;
3698 unsigned long entries
;
3701 dynobj
= elf_hash_table(info
)->dynobj
;
3702 splt
= bfd_get_section_by_name(dynobj
, ".plt");
3708 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3709 elf64_alpha_size_plt_section_1
, splt
);
3711 /* Every plt entry requires a JMP_SLOT relocation. */
3712 spltrel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3714 entries
= (splt
->size
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3717 spltrel
->size
= entries
* sizeof (Elf64_External_Rela
);
3723 elf64_alpha_size_plt_section_1 (h
, data
)
3724 struct alpha_elf_link_hash_entry
*h
;
3727 asection
*splt
= (asection
*) data
;
3728 struct alpha_elf_got_entry
*gotent
;
3730 /* If we didn't need an entry before, we still don't. */
3731 if (!h
->root
.needs_plt
)
3734 /* There must still be a LITERAL got entry for the function. */
3735 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3736 if (gotent
->reloc_type
== R_ALPHA_LITERAL
3737 && gotent
->use_count
> 0)
3740 /* If there is, reset the PLT offset. If not, there's no longer
3741 a need for the PLT entry. */
3744 if (splt
->size
== 0)
3745 splt
->size
= PLT_HEADER_SIZE
;
3746 h
->root
.plt
.offset
= splt
->size
;
3747 splt
->size
+= PLT_ENTRY_SIZE
;
3751 h
->root
.needs_plt
= 0;
3752 h
->root
.plt
.offset
= -1;
3754 /* Undo the definition frobbing begun in adjust_dynamic_symbol. */
3755 if (h
->flags
& ALPHA_ELF_LINK_HASH_PLT_LOC
)
3757 h
->root
.root
.u
.def
.section
= h
->plt_old_section
;
3758 h
->root
.root
.u
.def
.value
= h
->plt_old_value
;
3759 h
->flags
&= ~ALPHA_ELF_LINK_HASH_PLT_LOC
;
3767 elf64_alpha_always_size_sections (output_bfd
, info
)
3768 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3769 struct bfd_link_info
*info
;
3773 if (info
->relocatable
)
3776 /* First, take care of the indirect symbols created by versioning. */
3777 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3778 elf64_alpha_merge_ind_symbols
,
3781 if (!elf64_alpha_size_got_sections (info
))
3784 /* Allocate space for all of the .got subsections. */
3785 i
= alpha_elf_hash_table (info
)->got_list
;
3786 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3788 asection
*s
= alpha_elf_tdata(i
)->got
;
3791 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->size
);
3792 if (s
->contents
== NULL
)
3800 /* The number of dynamic relocations required by a static relocation. */
3803 alpha_dynamic_entries_for_reloc (r_type
, dynamic
, shared
)
3804 int r_type
, dynamic
, shared
;
3808 /* May appear in GOT entries. */
3810 return (dynamic
? 2 : shared
? 1 : 0);
3811 case R_ALPHA_TLSLDM
:
3813 case R_ALPHA_LITERAL
:
3814 case R_ALPHA_GOTTPREL
:
3815 return dynamic
|| shared
;
3816 case R_ALPHA_GOTDTPREL
:
3819 /* May appear in data sections. */
3820 case R_ALPHA_REFLONG
:
3821 case R_ALPHA_REFQUAD
:
3822 case R_ALPHA_TPREL64
:
3823 return dynamic
|| shared
;
3825 /* Everything else is illegal. We'll issue an error during
3826 relocate_section. */
3832 /* Work out the sizes of the dynamic relocation entries. */
3835 elf64_alpha_calc_dynrel_sizes (h
, info
)
3836 struct alpha_elf_link_hash_entry
*h
;
3837 struct bfd_link_info
*info
;
3839 bfd_boolean dynamic
;
3840 struct alpha_elf_reloc_entry
*relent
;
3841 unsigned long entries
;
3843 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3844 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3846 /* If the symbol was defined as a common symbol in a regular object
3847 file, and there was no definition in any dynamic object, then the
3848 linker will have allocated space for the symbol in a common
3849 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3850 set. This is done for dynamic symbols in
3851 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3852 symbols, somehow. */
3853 if (!h
->root
.def_regular
3854 && h
->root
.ref_regular
3855 && !h
->root
.def_dynamic
3856 && (h
->root
.root
.type
== bfd_link_hash_defined
3857 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3858 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
3859 h
->root
.def_regular
= 1;
3861 /* If the symbol is dynamic, we'll need all the relocations in their
3862 natural form. If this is a shared object, and it has been forced
3863 local, we'll need the same number of RELATIVE relocations. */
3865 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
3867 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
3869 entries
= alpha_dynamic_entries_for_reloc (relent
->rtype
, dynamic
,
3873 relent
->srel
->size
+=
3874 entries
* sizeof (Elf64_External_Rela
) * relent
->count
;
3875 if (relent
->reltext
)
3876 info
->flags
|= DT_TEXTREL
;
3883 /* Set the sizes of the dynamic relocation sections. */
3886 elf64_alpha_size_rela_got_section (info
)
3887 struct bfd_link_info
*info
;
3889 unsigned long entries
;
3893 /* Shared libraries often require RELATIVE relocs, and some relocs
3894 require attention for the main application as well. */
3897 for (i
= alpha_elf_hash_table(info
)->got_list
;
3898 i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3902 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
3904 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
3907 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
3908 if (!local_got_entries
)
3911 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
3912 for (gotent
= local_got_entries
[k
];
3913 gotent
; gotent
= gotent
->next
)
3914 if (gotent
->use_count
> 0)
3915 entries
+= (alpha_dynamic_entries_for_reloc
3916 (gotent
->reloc_type
, 0, info
->shared
));
3920 dynobj
= elf_hash_table(info
)->dynobj
;
3921 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3924 BFD_ASSERT (entries
== 0);
3927 srel
->size
= sizeof (Elf64_External_Rela
) * entries
;
3929 /* Now do the non-local symbols. */
3930 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3931 elf64_alpha_size_rela_got_1
, info
);
3936 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
3940 elf64_alpha_size_rela_got_1 (h
, info
)
3941 struct alpha_elf_link_hash_entry
*h
;
3942 struct bfd_link_info
*info
;
3944 bfd_boolean dynamic
;
3945 struct alpha_elf_got_entry
*gotent
;
3946 unsigned long entries
;
3948 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3949 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3951 /* If the symbol is dynamic, we'll need all the relocations in their
3952 natural form. If this is a shared object, and it has been forced
3953 local, we'll need the same number of RELATIVE relocations. */
3955 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
3958 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3959 if (gotent
->use_count
> 0)
3960 entries
+= alpha_dynamic_entries_for_reloc (gotent
->reloc_type
,
3961 dynamic
, info
->shared
);
3963 /* If we are using a .plt entry, subtract one, as the first
3964 reference uses a .rela.plt entry instead. */
3965 if (h
->root
.plt
.offset
!= MINUS_ONE
)
3970 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
3971 asection
*srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3972 BFD_ASSERT (srel
!= NULL
);
3973 srel
->size
+= sizeof (Elf64_External_Rela
) * entries
;
3979 /* Set the sizes of the dynamic sections. */
3982 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
3983 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3984 struct bfd_link_info
*info
;
3990 dynobj
= elf_hash_table(info
)->dynobj
;
3991 BFD_ASSERT(dynobj
!= NULL
);
3993 if (elf_hash_table (info
)->dynamic_sections_created
)
3995 /* Set the contents of the .interp section to the interpreter. */
3996 if (info
->executable
)
3998 s
= bfd_get_section_by_name (dynobj
, ".interp");
3999 BFD_ASSERT (s
!= NULL
);
4000 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4001 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4004 /* Now that we've seen all of the input files, we can decide which
4005 symbols need dynamic relocation entries and which don't. We've
4006 collected information in check_relocs that we can now apply to
4007 size the dynamic relocation sections. */
4008 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
4009 elf64_alpha_calc_dynrel_sizes
, info
);
4011 elf64_alpha_size_rela_got_section (info
);
4013 /* else we're not dynamic and by definition we don't need such things. */
4015 /* The check_relocs and adjust_dynamic_symbol entry points have
4016 determined the sizes of the various dynamic sections. Allocate
4019 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4024 if (!(s
->flags
& SEC_LINKER_CREATED
))
4027 /* It's OK to base decisions on the section name, because none
4028 of the dynobj section names depend upon the input files. */
4029 name
= bfd_get_section_name (dynobj
, s
);
4031 /* If we don't need this section, strip it from the output file.
4032 This is to handle .rela.bss and .rela.plt. We must create it
4033 in create_dynamic_sections, because it must be created before
4034 the linker maps input sections to output sections. The
4035 linker does that before adjust_dynamic_symbol is called, and
4036 it is that function which decides whether anything needs to
4037 go into these sections. */
4041 if (strncmp (name
, ".rela", 5) == 0)
4043 strip
= (s
->size
== 0);
4047 if (strcmp(name
, ".rela.plt") == 0)
4050 /* We use the reloc_count field as a counter if we need
4051 to copy relocs into the output file. */
4055 else if (strcmp (name
, ".plt") != 0)
4057 /* It's not one of our dynamic sections, so don't allocate space. */
4062 _bfd_strip_section_from_output (info
, s
);
4065 /* Allocate memory for the section contents. */
4066 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
4067 if (s
->contents
== NULL
&& s
->size
!= 0)
4072 if (elf_hash_table (info
)->dynamic_sections_created
)
4074 /* Add some entries to the .dynamic section. We fill in the
4075 values later, in elf64_alpha_finish_dynamic_sections, but we
4076 must add the entries now so that we get the correct size for
4077 the .dynamic section. The DT_DEBUG entry is filled in by the
4078 dynamic linker and used by the debugger. */
4079 #define add_dynamic_entry(TAG, VAL) \
4080 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4082 if (info
->executable
)
4084 if (!add_dynamic_entry (DT_DEBUG
, 0))
4090 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4091 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4092 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4093 || !add_dynamic_entry (DT_JMPREL
, 0))
4097 if (!add_dynamic_entry (DT_RELA
, 0)
4098 || !add_dynamic_entry (DT_RELASZ
, 0)
4099 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4102 if (info
->flags
& DF_TEXTREL
)
4104 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4108 #undef add_dynamic_entry
4113 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
4114 into the next available slot in SREL. */
4117 elf64_alpha_emit_dynrel (abfd
, info
, sec
, srel
, offset
, dynindx
, rtype
, addend
)
4119 struct bfd_link_info
*info
;
4120 asection
*sec
, *srel
;
4121 bfd_vma offset
, addend
;
4122 long dynindx
, rtype
;
4124 Elf_Internal_Rela outrel
;
4127 BFD_ASSERT (srel
!= NULL
);
4129 outrel
.r_info
= ELF64_R_INFO (dynindx
, rtype
);
4130 outrel
.r_addend
= addend
;
4132 offset
= _bfd_elf_section_offset (abfd
, info
, sec
, offset
);
4133 if ((offset
| 1) != (bfd_vma
) -1)
4134 outrel
.r_offset
= sec
->output_section
->vma
+ sec
->output_offset
+ offset
;
4136 memset (&outrel
, 0, sizeof (outrel
));
4138 loc
= srel
->contents
;
4139 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4140 bfd_elf64_swap_reloca_out (abfd
, &outrel
, loc
);
4141 BFD_ASSERT (sizeof (Elf64_External_Rela
) * srel
->reloc_count
<= srel
->size
);
4144 /* Relocate an Alpha ELF section for a relocatable link.
4146 We don't have to change anything unless the reloc is against a section
4147 symbol, in which case we have to adjust according to where the section
4148 symbol winds up in the output section. */
4151 elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
, input_section
,
4152 contents
, relocs
, local_syms
, local_sections
)
4153 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4154 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4156 asection
*input_section
;
4157 bfd_byte
*contents ATTRIBUTE_UNUSED
;
4158 Elf_Internal_Rela
*relocs
;
4159 Elf_Internal_Sym
*local_syms
;
4160 asection
**local_sections
;
4162 unsigned long symtab_hdr_sh_info
;
4163 Elf_Internal_Rela
*rel
;
4164 Elf_Internal_Rela
*relend
;
4165 bfd_boolean ret_val
= TRUE
;
4167 symtab_hdr_sh_info
= elf_tdata (input_bfd
)->symtab_hdr
.sh_info
;
4169 relend
= relocs
+ input_section
->reloc_count
;
4170 for (rel
= relocs
; rel
< relend
; rel
++)
4172 unsigned long r_symndx
;
4173 Elf_Internal_Sym
*sym
;
4175 unsigned long r_type
;
4177 r_type
= ELF64_R_TYPE(rel
->r_info
);
4178 if (r_type
>= R_ALPHA_max
)
4180 (*_bfd_error_handler
)
4181 (_("%B: unknown relocation type %d"),
4182 input_bfd
, (int) r_type
);
4183 bfd_set_error (bfd_error_bad_value
);
4188 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4190 /* The symbol associated with GPDISP and LITUSE is
4191 immaterial. Only the addend is significant. */
4192 if (r_type
== R_ALPHA_GPDISP
|| r_type
== R_ALPHA_LITUSE
)
4195 if (r_symndx
< symtab_hdr_sh_info
)
4197 sym
= local_syms
+ r_symndx
;
4198 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
4200 sec
= local_sections
[r_symndx
];
4201 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4209 /* Relocate an Alpha ELF section. */
4212 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4213 contents
, relocs
, local_syms
, local_sections
)
4215 struct bfd_link_info
*info
;
4217 asection
*input_section
;
4219 Elf_Internal_Rela
*relocs
;
4220 Elf_Internal_Sym
*local_syms
;
4221 asection
**local_sections
;
4223 Elf_Internal_Shdr
*symtab_hdr
;
4224 Elf_Internal_Rela
*rel
;
4225 Elf_Internal_Rela
*relend
;
4226 asection
*sgot
, *srel
, *srelgot
;
4227 bfd
*dynobj
, *gotobj
;
4228 bfd_vma gp
, tp_base
, dtp_base
;
4229 struct alpha_elf_got_entry
**local_got_entries
;
4230 bfd_boolean ret_val
;
4231 const char *section_name
;
4233 /* Handle relocatable links with a smaller loop. */
4234 if (info
->relocatable
)
4235 return elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
,
4236 input_section
, contents
, relocs
,
4237 local_syms
, local_sections
);
4239 /* This is a final link. */
4243 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4245 dynobj
= elf_hash_table (info
)->dynobj
;
4247 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
4251 section_name
= (bfd_elf_string_from_elf_section
4252 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
4253 elf_section_data(input_section
)->rel_hdr
.sh_name
));
4254 BFD_ASSERT(section_name
!= NULL
);
4255 srel
= bfd_get_section_by_name (dynobj
, section_name
);
4257 /* Find the gp value for this input bfd. */
4258 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
4261 sgot
= alpha_elf_tdata (gotobj
)->got
;
4262 gp
= _bfd_get_gp_value (gotobj
);
4265 gp
= (sgot
->output_section
->vma
4266 + sgot
->output_offset
4268 _bfd_set_gp_value (gotobj
, gp
);
4277 local_got_entries
= alpha_elf_tdata(input_bfd
)->local_got_entries
;
4279 if (elf_hash_table (info
)->tls_sec
!= NULL
)
4281 dtp_base
= alpha_get_dtprel_base (info
);
4282 tp_base
= alpha_get_tprel_base (info
);
4285 dtp_base
= tp_base
= 0;
4287 relend
= relocs
+ input_section
->reloc_count
;
4288 for (rel
= relocs
; rel
< relend
; rel
++)
4290 struct alpha_elf_link_hash_entry
*h
= NULL
;
4291 struct alpha_elf_got_entry
*gotent
;
4292 bfd_reloc_status_type r
;
4293 reloc_howto_type
*howto
;
4294 unsigned long r_symndx
;
4295 Elf_Internal_Sym
*sym
= NULL
;
4296 asection
*sec
= NULL
;
4299 bfd_boolean dynamic_symbol_p
;
4300 bfd_boolean undef_weak_ref
= FALSE
;
4301 unsigned long r_type
;
4303 r_type
= ELF64_R_TYPE(rel
->r_info
);
4304 if (r_type
>= R_ALPHA_max
)
4306 (*_bfd_error_handler
)
4307 (_("%B: unknown relocation type %d"),
4308 input_bfd
, (int) r_type
);
4309 bfd_set_error (bfd_error_bad_value
);
4314 howto
= elf64_alpha_howto_table
+ r_type
;
4315 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4317 /* The symbol for a TLSLDM reloc is ignored. Collapse the
4318 reloc to the 0 symbol so that they all match. */
4319 if (r_type
== R_ALPHA_TLSLDM
)
4322 if (r_symndx
< symtab_hdr
->sh_info
)
4325 sym
= local_syms
+ r_symndx
;
4326 sec
= local_sections
[r_symndx
];
4328 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &msec
, rel
);
4330 /* If this is a tp-relative relocation against sym 0,
4331 this is hackery from relax_section. Force the value to
4334 && (r_type
== R_ALPHA_TLSLDM
4335 || r_type
== R_ALPHA_GOTTPREL
4336 || r_type
== R_ALPHA_TPREL64
4337 || r_type
== R_ALPHA_TPRELHI
4338 || r_type
== R_ALPHA_TPRELLO
4339 || r_type
== R_ALPHA_TPREL16
))
4342 if (local_got_entries
)
4343 gotent
= local_got_entries
[r_symndx
];
4347 /* Need to adjust local GOT entries' addends for SEC_MERGE
4348 unless it has been done already. */
4349 if ((sec
->flags
& SEC_MERGE
)
4350 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
4351 && sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
4353 && !gotent
->reloc_xlated
)
4355 struct alpha_elf_got_entry
*ent
;
4357 for (ent
= gotent
; ent
; ent
= ent
->next
)
4359 ent
->reloc_xlated
= 1;
4360 if (ent
->use_count
== 0)
4364 _bfd_merged_section_offset (output_bfd
, &msec
,
4365 elf_section_data (sec
)->
4367 sym
->st_value
+ ent
->addend
);
4368 ent
->addend
-= sym
->st_value
;
4369 ent
->addend
+= msec
->output_section
->vma
4370 + msec
->output_offset
4371 - sec
->output_section
->vma
4372 - sec
->output_offset
;
4376 dynamic_symbol_p
= FALSE
;
4381 bfd_boolean unresolved_reloc
;
4382 struct elf_link_hash_entry
*hh
;
4383 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
4385 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4386 r_symndx
, symtab_hdr
, sym_hashes
,
4388 unresolved_reloc
, warned
);
4394 && ! unresolved_reloc
4395 && hh
->root
.type
== bfd_link_hash_undefweak
)
4396 undef_weak_ref
= TRUE
;
4398 h
= (struct alpha_elf_link_hash_entry
*) hh
;
4399 dynamic_symbol_p
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4400 gotent
= h
->got_entries
;
4403 addend
= rel
->r_addend
;
4406 /* Search for the proper got entry. */
4407 for (; gotent
; gotent
= gotent
->next
)
4408 if (gotent
->gotobj
== gotobj
4409 && gotent
->reloc_type
== r_type
4410 && gotent
->addend
== addend
)
4415 case R_ALPHA_GPDISP
:
4417 bfd_byte
*p_ldah
, *p_lda
;
4419 BFD_ASSERT(gp
!= 0);
4421 value
= (input_section
->output_section
->vma
4422 + input_section
->output_offset
4425 p_ldah
= contents
+ rel
->r_offset
;
4426 p_lda
= p_ldah
+ rel
->r_addend
;
4428 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- value
,
4433 case R_ALPHA_LITERAL
:
4434 BFD_ASSERT(sgot
!= NULL
);
4435 BFD_ASSERT(gp
!= 0);
4436 BFD_ASSERT(gotent
!= NULL
);
4437 BFD_ASSERT(gotent
->use_count
>= 1);
4439 if (!gotent
->reloc_done
)
4441 gotent
->reloc_done
= 1;
4443 bfd_put_64 (output_bfd
, value
,
4444 sgot
->contents
+ gotent
->got_offset
);
4446 /* If the symbol has been forced local, output a
4447 RELATIVE reloc, otherwise it will be handled in
4448 finish_dynamic_symbol. */
4449 if (info
->shared
&& !dynamic_symbol_p
)
4450 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4451 gotent
->got_offset
, 0,
4452 R_ALPHA_RELATIVE
, value
);
4455 value
= (sgot
->output_section
->vma
4456 + sgot
->output_offset
4457 + gotent
->got_offset
);
4461 case R_ALPHA_GPREL32
:
4462 /* If the target section was a removed linkonce section,
4463 r_symndx will be zero. In this case, assume that the
4464 switch will not be used, so don't fill it in. If we
4465 do nothing here, we'll get relocation truncated messages,
4466 due to the placement of the application above 4GB. */
4474 case R_ALPHA_GPREL16
:
4475 case R_ALPHA_GPRELLOW
:
4476 if (dynamic_symbol_p
)
4478 (*_bfd_error_handler
)
4479 (_("%B: gp-relative relocation against dynamic symbol %s"),
4480 input_bfd
, h
->root
.root
.root
.string
);
4483 BFD_ASSERT(gp
!= 0);
4487 case R_ALPHA_GPRELHIGH
:
4488 if (dynamic_symbol_p
)
4490 (*_bfd_error_handler
)
4491 (_("%B: gp-relative relocation against dynamic symbol %s"),
4492 input_bfd
, h
->root
.root
.root
.string
);
4495 BFD_ASSERT(gp
!= 0);
4497 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4501 /* A call to a dynamic symbol is definitely out of range of
4502 the 16-bit displacement. Don't bother writing anything. */
4503 if (dynamic_symbol_p
)
4508 /* The regular PC-relative stuff measures from the start of
4509 the instruction rather than the end. */
4513 case R_ALPHA_BRADDR
:
4514 if (dynamic_symbol_p
)
4516 (*_bfd_error_handler
)
4517 (_("%B: pc-relative relocation against dynamic symbol %s"),
4518 input_bfd
, h
->root
.root
.root
.string
);
4521 /* The regular PC-relative stuff measures from the start of
4522 the instruction rather than the end. */
4531 /* The regular PC-relative stuff measures from the start of
4532 the instruction rather than the end. */
4535 /* The source and destination gp must be the same. Note that
4536 the source will always have an assigned gp, since we forced
4537 one in check_relocs, but that the destination may not, as
4538 it might not have had any relocations at all. Also take
4539 care not to crash if H is an undefined symbol. */
4540 if (h
!= NULL
&& sec
!= NULL
4541 && alpha_elf_tdata (sec
->owner
)->gotobj
4542 && gotobj
!= alpha_elf_tdata (sec
->owner
)->gotobj
)
4544 (*_bfd_error_handler
)
4545 (_("%B: change in gp: BRSGP %s"),
4546 input_bfd
, h
->root
.root
.root
.string
);
4550 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4552 other
= h
->root
.other
;
4554 other
= sym
->st_other
;
4555 switch (other
& STO_ALPHA_STD_GPLOAD
)
4557 case STO_ALPHA_NOPV
:
4559 case STO_ALPHA_STD_GPLOAD
:
4564 name
= h
->root
.root
.root
.string
;
4567 name
= (bfd_elf_string_from_elf_section
4568 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4570 name
= _("<unknown>");
4571 else if (name
[0] == 0)
4572 name
= bfd_section_name (input_bfd
, sec
);
4574 (*_bfd_error_handler
)
4575 (_("%B: !samegp reloc against symbol without .prologue: %s"),
4584 case R_ALPHA_REFLONG
:
4585 case R_ALPHA_REFQUAD
:
4586 case R_ALPHA_DTPREL64
:
4587 case R_ALPHA_TPREL64
:
4589 long dynindx
, dyntype
= r_type
;
4592 /* Careful here to remember RELATIVE relocations for global
4593 variables for symbolic shared objects. */
4595 if (dynamic_symbol_p
)
4597 BFD_ASSERT(h
->root
.dynindx
!= -1);
4598 dynindx
= h
->root
.dynindx
;
4600 addend
= 0, value
= 0;
4602 else if (r_type
== R_ALPHA_DTPREL64
)
4604 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4608 else if (r_type
== R_ALPHA_TPREL64
)
4610 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4617 dynaddend
= value
- dtp_base
;
4619 else if (info
->shared
4621 && (input_section
->flags
& SEC_ALLOC
))
4623 if (r_type
== R_ALPHA_REFLONG
)
4625 (*_bfd_error_handler
)
4626 (_("%B: unhandled dynamic relocation against %s"),
4628 h
->root
.root
.root
.string
);
4632 dyntype
= R_ALPHA_RELATIVE
;
4638 elf64_alpha_emit_dynrel (output_bfd
, info
, input_section
,
4639 srel
, rel
->r_offset
, dynindx
,
4640 dyntype
, dynaddend
);
4644 case R_ALPHA_SREL16
:
4645 case R_ALPHA_SREL32
:
4646 case R_ALPHA_SREL64
:
4647 if (dynamic_symbol_p
)
4649 (*_bfd_error_handler
)
4650 (_("%B: pc-relative relocation against dynamic symbol %s"),
4651 input_bfd
, h
->root
.root
.root
.string
);
4655 /* ??? .eh_frame references to discarded sections will be smashed
4656 to relocations against SHN_UNDEF. The .eh_frame format allows
4657 NULL to be encoded as 0 in any format, so this works here. */
4659 howto
= (elf64_alpha_howto_table
4660 + (r_type
- R_ALPHA_SREL32
+ R_ALPHA_REFLONG
));
4663 case R_ALPHA_TLSLDM
:
4664 /* Ignore the symbol for the relocation. The result is always
4665 the current module. */
4666 dynamic_symbol_p
= 0;
4670 if (!gotent
->reloc_done
)
4672 gotent
->reloc_done
= 1;
4674 /* Note that the module index for the main program is 1. */
4675 bfd_put_64 (output_bfd
, !info
->shared
&& !dynamic_symbol_p
,
4676 sgot
->contents
+ gotent
->got_offset
);
4678 /* If the symbol has been forced local, output a
4679 DTPMOD64 reloc, otherwise it will be handled in
4680 finish_dynamic_symbol. */
4681 if (info
->shared
&& !dynamic_symbol_p
)
4682 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4683 gotent
->got_offset
, 0,
4684 R_ALPHA_DTPMOD64
, 0);
4686 if (dynamic_symbol_p
|| r_type
== R_ALPHA_TLSLDM
)
4690 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4693 bfd_put_64 (output_bfd
, value
,
4694 sgot
->contents
+ gotent
->got_offset
+ 8);
4697 value
= (sgot
->output_section
->vma
4698 + sgot
->output_offset
4699 + gotent
->got_offset
);
4703 case R_ALPHA_DTPRELHI
:
4704 case R_ALPHA_DTPRELLO
:
4705 case R_ALPHA_DTPREL16
:
4706 if (dynamic_symbol_p
)
4708 (*_bfd_error_handler
)
4709 (_("%B: dtp-relative relocation against dynamic symbol %s"),
4710 input_bfd
, h
->root
.root
.root
.string
);
4713 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4715 if (r_type
== R_ALPHA_DTPRELHI
)
4716 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4719 case R_ALPHA_TPRELHI
:
4720 case R_ALPHA_TPRELLO
:
4721 case R_ALPHA_TPREL16
:
4724 (*_bfd_error_handler
)
4725 (_("%B: TLS local exec code cannot be linked into shared objects"),
4729 else if (dynamic_symbol_p
)
4731 (*_bfd_error_handler
)
4732 (_("%B: tp-relative relocation against dynamic symbol %s"),
4733 input_bfd
, h
->root
.root
.root
.string
);
4736 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4738 if (r_type
== R_ALPHA_TPRELHI
)
4739 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4742 case R_ALPHA_GOTDTPREL
:
4743 case R_ALPHA_GOTTPREL
:
4744 BFD_ASSERT(sgot
!= NULL
);
4745 BFD_ASSERT(gp
!= 0);
4746 BFD_ASSERT(gotent
!= NULL
);
4747 BFD_ASSERT(gotent
->use_count
>= 1);
4749 if (!gotent
->reloc_done
)
4751 gotent
->reloc_done
= 1;
4753 if (dynamic_symbol_p
)
4757 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4758 if (r_type
== R_ALPHA_GOTDTPREL
)
4760 else if (!info
->shared
)
4764 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4765 gotent
->got_offset
, 0,
4771 bfd_put_64 (output_bfd
, value
,
4772 sgot
->contents
+ gotent
->got_offset
);
4775 value
= (sgot
->output_section
->vma
4776 + sgot
->output_offset
4777 + gotent
->got_offset
);
4783 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4784 contents
, rel
->r_offset
, value
, 0);
4793 case bfd_reloc_overflow
:
4797 /* Don't warn if the overflow is due to pc relative reloc
4798 against discarded section. Section optimization code should
4801 if (r_symndx
< symtab_hdr
->sh_info
4802 && sec
!= NULL
&& howto
->pc_relative
4803 && elf_discarded_section (sec
))
4810 name
= (bfd_elf_string_from_elf_section
4811 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4815 name
= bfd_section_name (input_bfd
, sec
);
4817 if (! ((*info
->callbacks
->reloc_overflow
)
4818 (info
, (h
? &h
->root
.root
: NULL
), name
, howto
->name
,
4819 (bfd_vma
) 0, input_bfd
, input_section
,
4826 case bfd_reloc_outofrange
:
4834 /* Finish up dynamic symbol handling. We set the contents of various
4835 dynamic sections here. */
4838 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4840 struct bfd_link_info
*info
;
4841 struct elf_link_hash_entry
*h
;
4842 Elf_Internal_Sym
*sym
;
4844 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4846 if (h
->plt
.offset
!= MINUS_ONE
)
4848 /* Fill in the .plt entry for this symbol. */
4849 asection
*splt
, *sgot
, *srel
;
4850 Elf_Internal_Rela outrel
;
4852 bfd_vma got_addr
, plt_addr
;
4854 struct alpha_elf_got_entry
*gotent
;
4856 BFD_ASSERT (h
->dynindx
!= -1);
4858 /* The first .got entry will be updated by the .plt with the
4859 address of the target function. */
4860 gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4861 BFD_ASSERT (gotent
&& gotent
->addend
== 0);
4863 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4864 BFD_ASSERT (splt
!= NULL
);
4865 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4866 BFD_ASSERT (srel
!= NULL
);
4867 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4868 BFD_ASSERT (sgot
!= NULL
);
4870 got_addr
= (sgot
->output_section
->vma
4871 + sgot
->output_offset
4872 + gotent
->got_offset
);
4873 plt_addr
= (splt
->output_section
->vma
4874 + splt
->output_offset
4877 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
4879 /* Fill in the entry in the procedure linkage table. */
4881 bfd_vma insn1
, insn2
, insn3
;
4883 insn1
= PLT_ENTRY_WORD1
| ((-(h
->plt
.offset
+ 4) >> 2) & 0x1fffff);
4884 insn2
= PLT_ENTRY_WORD2
;
4885 insn3
= PLT_ENTRY_WORD3
;
4887 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt
.offset
);
4888 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt
.offset
+ 4);
4889 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt
.offset
+ 8);
4892 /* Fill in the entry in the .rela.plt section. */
4893 outrel
.r_offset
= got_addr
;
4894 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
4895 outrel
.r_addend
= 0;
4897 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
4898 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
4900 if (!h
->def_regular
)
4902 /* Mark the symbol as undefined, rather than as defined in the
4903 .plt section. Leave the value alone. */
4904 sym
->st_shndx
= SHN_UNDEF
;
4907 /* Fill in the entries in the .got. */
4908 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ gotent
->got_offset
);
4910 /* Subsequent .got entries will continue to bounce through the .plt. */
4913 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4914 BFD_ASSERT (! info
->shared
|| srel
!= NULL
);
4916 gotent
= gotent
->next
;
4919 sgot
= alpha_elf_tdata(gotent
->gotobj
)->got
;
4920 BFD_ASSERT(sgot
!= NULL
);
4921 BFD_ASSERT(gotent
->addend
== 0);
4923 bfd_put_64 (output_bfd
, plt_addr
,
4924 sgot
->contents
+ gotent
->got_offset
);
4927 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4928 gotent
->got_offset
, 0,
4929 R_ALPHA_RELATIVE
, plt_addr
);
4931 gotent
= gotent
->next
;
4933 while (gotent
!= NULL
);
4936 else if (alpha_elf_dynamic_symbol_p (h
, info
))
4938 /* Fill in the dynamic relocations for this symbol's .got entries. */
4940 struct alpha_elf_got_entry
*gotent
;
4942 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4943 BFD_ASSERT (srel
!= NULL
);
4945 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4947 gotent
= gotent
->next
)
4952 if (gotent
->use_count
== 0)
4955 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4957 r_type
= gotent
->reloc_type
;
4960 case R_ALPHA_LITERAL
:
4961 r_type
= R_ALPHA_GLOB_DAT
;
4964 r_type
= R_ALPHA_DTPMOD64
;
4966 case R_ALPHA_GOTDTPREL
:
4967 r_type
= R_ALPHA_DTPREL64
;
4969 case R_ALPHA_GOTTPREL
:
4970 r_type
= R_ALPHA_TPREL64
;
4972 case R_ALPHA_TLSLDM
:
4977 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4978 gotent
->got_offset
, h
->dynindx
,
4979 r_type
, gotent
->addend
);
4981 if (gotent
->reloc_type
== R_ALPHA_TLSGD
)
4982 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4983 gotent
->got_offset
+ 8, h
->dynindx
,
4984 R_ALPHA_DTPREL64
, gotent
->addend
);
4988 /* Mark some specially defined symbols as absolute. */
4989 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4990 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4991 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4992 sym
->st_shndx
= SHN_ABS
;
4997 /* Finish up the dynamic sections. */
5000 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
5002 struct bfd_link_info
*info
;
5007 dynobj
= elf_hash_table (info
)->dynobj
;
5008 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5010 if (elf_hash_table (info
)->dynamic_sections_created
)
5013 Elf64_External_Dyn
*dyncon
, *dynconend
;
5015 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5016 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
5018 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
5019 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
5020 for (; dyncon
< dynconend
; dyncon
++)
5022 Elf_Internal_Dyn dyn
;
5026 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5041 /* My interpretation of the TIS v1.1 ELF document indicates
5042 that RELASZ should not include JMPREL. This is not what
5043 the rest of the BFD does. It is, however, what the
5044 glibc ld.so wants. Do this fixup here until we found
5045 out who is right. */
5046 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
5048 dyn
.d_un
.d_val
-= s
->size
;
5052 s
= bfd_get_section_by_name (output_bfd
, name
);
5053 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
5057 s
= bfd_get_section_by_name (output_bfd
, name
);
5058 dyn
.d_un
.d_val
= s
->size
;
5062 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5065 /* Initialize the PLT0 entry. */
5068 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
5069 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
5070 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
5071 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
5073 /* The next two words will be filled in by ld.so */
5074 bfd_put_64 (output_bfd
, (bfd_vma
) 0, splt
->contents
+ 16);
5075 bfd_put_64 (output_bfd
, (bfd_vma
) 0, splt
->contents
+ 24);
5077 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 0;
5084 /* We need to use a special link routine to handle the .mdebug section.
5085 We need to merge all instances of these sections together, not write
5086 them all out sequentially. */
5089 elf64_alpha_final_link (abfd
, info
)
5091 struct bfd_link_info
*info
;
5094 struct bfd_link_order
*p
;
5095 asection
*mdebug_sec
;
5096 struct ecoff_debug_info debug
;
5097 const struct ecoff_debug_swap
*swap
5098 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
5099 HDRR
*symhdr
= &debug
.symbolic_header
;
5100 PTR mdebug_handle
= NULL
;
5102 /* Go through the sections and collect the mdebug information. */
5104 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5106 if (strcmp (o
->name
, ".mdebug") == 0)
5108 struct extsym_info einfo
;
5110 /* We have found the .mdebug section in the output file.
5111 Look through all the link_orders comprising it and merge
5112 the information together. */
5113 symhdr
->magic
= swap
->sym_magic
;
5114 /* FIXME: What should the version stamp be? */
5116 symhdr
->ilineMax
= 0;
5120 symhdr
->isymMax
= 0;
5121 symhdr
->ioptMax
= 0;
5122 symhdr
->iauxMax
= 0;
5124 symhdr
->issExtMax
= 0;
5127 symhdr
->iextMax
= 0;
5129 /* We accumulate the debugging information itself in the
5130 debug_info structure. */
5132 debug
.external_dnr
= NULL
;
5133 debug
.external_pdr
= NULL
;
5134 debug
.external_sym
= NULL
;
5135 debug
.external_opt
= NULL
;
5136 debug
.external_aux
= NULL
;
5138 debug
.ssext
= debug
.ssext_end
= NULL
;
5139 debug
.external_fdr
= NULL
;
5140 debug
.external_rfd
= NULL
;
5141 debug
.external_ext
= debug
.external_ext_end
= NULL
;
5143 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
5144 if (mdebug_handle
== (PTR
) NULL
)
5153 static const char * const name
[] =
5155 ".text", ".init", ".fini", ".data",
5156 ".rodata", ".sdata", ".sbss", ".bss"
5158 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
5159 scRData
, scSData
, scSBss
, scBss
};
5162 esym
.cobol_main
= 0;
5166 esym
.asym
.iss
= issNil
;
5167 esym
.asym
.st
= stLocal
;
5168 esym
.asym
.reserved
= 0;
5169 esym
.asym
.index
= indexNil
;
5170 for (i
= 0; i
< 8; i
++)
5172 esym
.asym
.sc
= sc
[i
];
5173 s
= bfd_get_section_by_name (abfd
, name
[i
]);
5176 esym
.asym
.value
= s
->vma
;
5177 last
= s
->vma
+ s
->size
;
5180 esym
.asym
.value
= last
;
5182 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
5188 for (p
= o
->link_order_head
;
5189 p
!= (struct bfd_link_order
*) NULL
;
5192 asection
*input_section
;
5194 const struct ecoff_debug_swap
*input_swap
;
5195 struct ecoff_debug_info input_debug
;
5199 if (p
->type
!= bfd_indirect_link_order
)
5201 if (p
->type
== bfd_data_link_order
)
5206 input_section
= p
->u
.indirect
.section
;
5207 input_bfd
= input_section
->owner
;
5209 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
5210 || (get_elf_backend_data (input_bfd
)
5211 ->elf_backend_ecoff_debug_swap
) == NULL
)
5213 /* I don't know what a non ALPHA ELF bfd would be
5214 doing with a .mdebug section, but I don't really
5215 want to deal with it. */
5219 input_swap
= (get_elf_backend_data (input_bfd
)
5220 ->elf_backend_ecoff_debug_swap
);
5222 BFD_ASSERT (p
->size
== input_section
->size
);
5224 /* The ECOFF linking code expects that we have already
5225 read in the debugging information and set up an
5226 ecoff_debug_info structure, so we do that now. */
5227 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
5231 if (! (bfd_ecoff_debug_accumulate
5232 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5233 &input_debug
, input_swap
, info
)))
5236 /* Loop through the external symbols. For each one with
5237 interesting information, try to find the symbol in
5238 the linker global hash table and save the information
5239 for the output external symbols. */
5240 eraw_src
= input_debug
.external_ext
;
5241 eraw_end
= (eraw_src
5242 + (input_debug
.symbolic_header
.iextMax
5243 * input_swap
->external_ext_size
));
5245 eraw_src
< eraw_end
;
5246 eraw_src
+= input_swap
->external_ext_size
)
5250 struct alpha_elf_link_hash_entry
*h
;
5252 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5253 if (ext
.asym
.sc
== scNil
5254 || ext
.asym
.sc
== scUndefined
5255 || ext
.asym
.sc
== scSUndefined
)
5258 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5259 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
5260 name
, FALSE
, FALSE
, TRUE
);
5261 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5267 < input_debug
.symbolic_header
.ifdMax
);
5268 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5274 /* Free up the information we just read. */
5275 free (input_debug
.line
);
5276 free (input_debug
.external_dnr
);
5277 free (input_debug
.external_pdr
);
5278 free (input_debug
.external_sym
);
5279 free (input_debug
.external_opt
);
5280 free (input_debug
.external_aux
);
5281 free (input_debug
.ss
);
5282 free (input_debug
.ssext
);
5283 free (input_debug
.external_fdr
);
5284 free (input_debug
.external_rfd
);
5285 free (input_debug
.external_ext
);
5287 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5288 elf_link_input_bfd ignores this section. */
5289 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5292 /* Build the external symbol information. */
5295 einfo
.debug
= &debug
;
5297 einfo
.failed
= FALSE
;
5298 elf_link_hash_traverse (elf_hash_table (info
),
5299 elf64_alpha_output_extsym
,
5304 /* Set the size of the .mdebug section. */
5305 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5307 /* Skip this section later on (I don't think this currently
5308 matters, but someday it might). */
5309 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5315 /* Invoke the regular ELF backend linker to do all the work. */
5316 if (! bfd_elf_final_link (abfd
, info
))
5319 /* Now write out the computed sections. */
5321 /* The .got subsections... */
5323 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
5324 for (i
= alpha_elf_hash_table(info
)->got_list
;
5326 i
= alpha_elf_tdata(i
)->got_link_next
)
5330 /* elf_bfd_final_link already did everything in dynobj. */
5334 sgot
= alpha_elf_tdata(i
)->got
;
5335 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
5337 (file_ptr
) sgot
->output_offset
,
5343 if (mdebug_sec
!= (asection
*) NULL
)
5345 BFD_ASSERT (abfd
->output_has_begun
);
5346 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5348 mdebug_sec
->filepos
))
5351 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5357 static enum elf_reloc_type_class
5358 elf64_alpha_reloc_type_class (rela
)
5359 const Elf_Internal_Rela
*rela
;
5361 switch ((int) ELF64_R_TYPE (rela
->r_info
))
5363 case R_ALPHA_RELATIVE
:
5364 return reloc_class_relative
;
5365 case R_ALPHA_JMP_SLOT
:
5366 return reloc_class_plt
;
5368 return reloc_class_copy
;
5370 return reloc_class_normal
;
5374 static struct bfd_elf_special_section
const elf64_alpha_special_sections
[]=
5376 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_ALPHA_GPREL
},
5377 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_ALPHA_GPREL
},
5378 { NULL
, 0, 0, 0, 0 }
5381 /* ECOFF swapping routines. These are used when dealing with the
5382 .mdebug section, which is in the ECOFF debugging format. Copied
5383 from elf32-mips.c. */
5384 static const struct ecoff_debug_swap
5385 elf64_alpha_ecoff_debug_swap
=
5387 /* Symbol table magic number. */
5389 /* Alignment of debugging information. E.g., 4. */
5391 /* Sizes of external symbolic information. */
5392 sizeof (struct hdr_ext
),
5393 sizeof (struct dnr_ext
),
5394 sizeof (struct pdr_ext
),
5395 sizeof (struct sym_ext
),
5396 sizeof (struct opt_ext
),
5397 sizeof (struct fdr_ext
),
5398 sizeof (struct rfd_ext
),
5399 sizeof (struct ext_ext
),
5400 /* Functions to swap in external symbolic data. */
5409 _bfd_ecoff_swap_tir_in
,
5410 _bfd_ecoff_swap_rndx_in
,
5411 /* Functions to swap out external symbolic data. */
5420 _bfd_ecoff_swap_tir_out
,
5421 _bfd_ecoff_swap_rndx_out
,
5422 /* Function to read in symbolic data. */
5423 elf64_alpha_read_ecoff_info
5426 /* Use a non-standard hash bucket size of 8. */
5428 static const struct elf_size_info alpha_elf_size_info
=
5430 sizeof (Elf64_External_Ehdr
),
5431 sizeof (Elf64_External_Phdr
),
5432 sizeof (Elf64_External_Shdr
),
5433 sizeof (Elf64_External_Rel
),
5434 sizeof (Elf64_External_Rela
),
5435 sizeof (Elf64_External_Sym
),
5436 sizeof (Elf64_External_Dyn
),
5437 sizeof (Elf_External_Note
),
5441 ELFCLASS64
, EV_CURRENT
,
5442 bfd_elf64_write_out_phdrs
,
5443 bfd_elf64_write_shdrs_and_ehdr
,
5444 bfd_elf64_write_relocs
,
5445 bfd_elf64_swap_symbol_in
,
5446 bfd_elf64_swap_symbol_out
,
5447 bfd_elf64_slurp_reloc_table
,
5448 bfd_elf64_slurp_symbol_table
,
5449 bfd_elf64_swap_dyn_in
,
5450 bfd_elf64_swap_dyn_out
,
5451 bfd_elf64_swap_reloc_in
,
5452 bfd_elf64_swap_reloc_out
,
5453 bfd_elf64_swap_reloca_in
,
5454 bfd_elf64_swap_reloca_out
5457 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5458 #define TARGET_LITTLE_NAME "elf64-alpha"
5459 #define ELF_ARCH bfd_arch_alpha
5460 #define ELF_MACHINE_CODE EM_ALPHA
5461 #define ELF_MAXPAGESIZE 0x10000
5463 #define bfd_elf64_bfd_link_hash_table_create \
5464 elf64_alpha_bfd_link_hash_table_create
5466 #define bfd_elf64_bfd_reloc_type_lookup \
5467 elf64_alpha_bfd_reloc_type_lookup
5468 #define elf_info_to_howto \
5469 elf64_alpha_info_to_howto
5471 #define bfd_elf64_mkobject \
5472 elf64_alpha_mkobject
5473 #define elf_backend_object_p \
5474 elf64_alpha_object_p
5476 #define elf_backend_section_from_shdr \
5477 elf64_alpha_section_from_shdr
5478 #define elf_backend_section_flags \
5479 elf64_alpha_section_flags
5480 #define elf_backend_fake_sections \
5481 elf64_alpha_fake_sections
5483 #define bfd_elf64_bfd_is_local_label_name \
5484 elf64_alpha_is_local_label_name
5485 #define bfd_elf64_find_nearest_line \
5486 elf64_alpha_find_nearest_line
5487 #define bfd_elf64_bfd_relax_section \
5488 elf64_alpha_relax_section
5490 #define elf_backend_add_symbol_hook \
5491 elf64_alpha_add_symbol_hook
5492 #define elf_backend_check_relocs \
5493 elf64_alpha_check_relocs
5494 #define elf_backend_create_dynamic_sections \
5495 elf64_alpha_create_dynamic_sections
5496 #define elf_backend_adjust_dynamic_symbol \
5497 elf64_alpha_adjust_dynamic_symbol
5498 #define elf_backend_always_size_sections \
5499 elf64_alpha_always_size_sections
5500 #define elf_backend_size_dynamic_sections \
5501 elf64_alpha_size_dynamic_sections
5502 #define elf_backend_relocate_section \
5503 elf64_alpha_relocate_section
5504 #define elf_backend_finish_dynamic_symbol \
5505 elf64_alpha_finish_dynamic_symbol
5506 #define elf_backend_finish_dynamic_sections \
5507 elf64_alpha_finish_dynamic_sections
5508 #define bfd_elf64_bfd_final_link \
5509 elf64_alpha_final_link
5510 #define elf_backend_reloc_type_class \
5511 elf64_alpha_reloc_type_class
5513 #define elf_backend_ecoff_debug_swap \
5514 &elf64_alpha_ecoff_debug_swap
5516 #define elf_backend_size_info \
5519 #define elf_backend_special_sections \
5520 elf64_alpha_special_sections
5522 /* A few constants that determine how the .plt section is set up. */
5523 #define elf_backend_want_got_plt 0
5524 #define elf_backend_plt_readonly 0
5525 #define elf_backend_want_plt_sym 1
5526 #define elf_backend_got_header_size 0
5528 #include "elf64-target.h"
5530 /* FreeBSD support. */
5532 #undef TARGET_LITTLE_SYM
5533 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5534 #undef TARGET_LITTLE_NAME
5535 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5537 /* The kernel recognizes executables as valid only if they carry a
5538 "FreeBSD" label in the ELF header. So we put this label on all
5539 executables and (for simplicity) also all other object files. */
5541 static void elf64_alpha_fbsd_post_process_headers
5542 PARAMS ((bfd
*, struct bfd_link_info
*));
5545 elf64_alpha_fbsd_post_process_headers (abfd
, link_info
)
5547 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
5549 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
5551 i_ehdrp
= elf_elfheader (abfd
);
5553 /* Put an ABI label supported by FreeBSD >= 4.1. */
5554 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
5555 #ifdef OLD_FREEBSD_ABI_LABEL
5556 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5557 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5561 #undef elf_backend_post_process_headers
5562 #define elf_backend_post_process_headers \
5563 elf64_alpha_fbsd_post_process_headers
5566 #define elf64_bed elf64_alpha_fbsd_bed
5568 #include "elf64-target.h"