1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Richard Henderson <rth@tamu.edu>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* We need a published ABI spec for this. Until one comes out, don't
23 assume this'll remain unchanged forever. */
30 #include "elf/alpha.h"
34 #define NO_COFF_RELOCS
35 #define NO_COFF_SYMBOLS
36 #define NO_COFF_LINENOS
38 /* Get the ECOFF swapping routines. Needed for the debug information. */
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
43 #include "coff/alpha.h"
48 #include "ecoffswap.h"
50 static int alpha_elf_dynamic_symbol_p
51 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
52 static struct bfd_hash_entry
* elf64_alpha_link_hash_newfunc
53 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
54 static struct bfd_link_hash_table
* elf64_alpha_bfd_link_hash_table_create
57 static bfd_reloc_status_type elf64_alpha_reloc_nil
58 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
59 static bfd_reloc_status_type elf64_alpha_reloc_bad
60 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
61 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
62 PARAMS ((bfd
*, bfd_vma
, bfd_byte
*, bfd_byte
*));
63 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
64 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
66 static reloc_howto_type
* elf64_alpha_bfd_reloc_type_lookup
67 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
68 static void elf64_alpha_info_to_howto
69 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
71 static bfd_boolean elf64_alpha_mkobject
73 static bfd_boolean elf64_alpha_object_p
75 static bfd_boolean elf64_alpha_section_from_shdr
76 PARAMS ((bfd
*, Elf_Internal_Shdr
*, const char *));
77 static bfd_boolean elf64_alpha_section_flags
78 PARAMS ((flagword
*, Elf_Internal_Shdr
*));
79 static bfd_boolean elf64_alpha_fake_sections
80 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
81 static bfd_boolean elf64_alpha_create_got_section
82 PARAMS ((bfd
*, struct bfd_link_info
*));
83 static bfd_boolean elf64_alpha_create_dynamic_sections
84 PARAMS ((bfd
*, struct bfd_link_info
*));
86 static bfd_boolean elf64_alpha_read_ecoff_info
87 PARAMS ((bfd
*, asection
*, struct ecoff_debug_info
*));
88 static bfd_boolean elf64_alpha_is_local_label_name
89 PARAMS ((bfd
*, const char *));
90 static bfd_boolean elf64_alpha_find_nearest_line
91 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
92 const char **, unsigned int *));
94 #if defined(__STDC__) || defined(ALMOST_STDC)
95 struct alpha_elf_link_hash_entry
;
98 static bfd_boolean elf64_alpha_output_extsym
99 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
101 static bfd_boolean elf64_alpha_can_merge_gots
102 PARAMS ((bfd
*, bfd
*));
103 static void elf64_alpha_merge_gots
104 PARAMS ((bfd
*, bfd
*));
105 static bfd_boolean elf64_alpha_calc_got_offsets_for_symbol
106 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
107 static void elf64_alpha_calc_got_offsets
108 PARAMS ((struct bfd_link_info
*));
109 static bfd_boolean elf64_alpha_size_got_sections
110 PARAMS ((struct bfd_link_info
*));
111 static bfd_boolean elf64_alpha_size_plt_section
112 PARAMS ((struct bfd_link_info
*));
113 static bfd_boolean elf64_alpha_size_plt_section_1
114 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
115 static bfd_boolean elf64_alpha_always_size_sections
116 PARAMS ((bfd
*, struct bfd_link_info
*));
117 static int alpha_dynamic_entries_for_reloc
118 PARAMS ((int, int, int));
119 static bfd_boolean elf64_alpha_calc_dynrel_sizes
120 PARAMS ((struct alpha_elf_link_hash_entry
*, struct bfd_link_info
*));
121 static bfd_boolean elf64_alpha_size_rela_got_section
122 PARAMS ((struct bfd_link_info
*));
123 static bfd_boolean elf64_alpha_size_rela_got_1
124 PARAMS ((struct alpha_elf_link_hash_entry
*, struct bfd_link_info
*));
125 static bfd_boolean elf64_alpha_add_symbol_hook
126 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
127 const char **, flagword
*, asection
**, bfd_vma
*));
128 static struct alpha_elf_got_entry
*get_got_entry
129 PARAMS ((bfd
*, struct alpha_elf_link_hash_entry
*, unsigned long,
130 unsigned long, bfd_vma
));
131 static bfd_boolean elf64_alpha_check_relocs
132 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*sec
,
133 const Elf_Internal_Rela
*));
134 static bfd_boolean elf64_alpha_adjust_dynamic_symbol
135 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
136 static bfd_boolean elf64_alpha_size_dynamic_sections
137 PARAMS ((bfd
*, struct bfd_link_info
*));
138 static void elf64_alpha_emit_dynrel
139 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, asection
*,
140 bfd_vma
, long, long, bfd_vma
));
141 static bfd_boolean elf64_alpha_relocate_section_r
142 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
143 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
144 static bfd_boolean elf64_alpha_relocate_section
145 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
146 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
147 static bfd_boolean elf64_alpha_finish_dynamic_symbol
148 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
149 Elf_Internal_Sym
*));
150 static bfd_boolean elf64_alpha_finish_dynamic_sections
151 PARAMS ((bfd
*, struct bfd_link_info
*));
152 static bfd_boolean elf64_alpha_final_link
153 PARAMS ((bfd
*, struct bfd_link_info
*));
154 static bfd_boolean elf64_alpha_merge_ind_symbols
155 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
156 static Elf_Internal_Rela
* elf64_alpha_find_reloc_at_ofs
157 PARAMS ((Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_vma
, int));
158 static enum elf_reloc_type_class elf64_alpha_reloc_type_class
159 PARAMS ((const Elf_Internal_Rela
*));
161 struct alpha_elf_link_hash_entry
163 struct elf_link_hash_entry root
;
165 /* External symbol information. */
168 /* Cumulative flags for all the .got entries. */
171 /* Contexts in which a literal was referenced. */
172 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
173 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
174 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
175 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08
176 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10
177 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20
178 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x38
179 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x40
181 /* Used to implement multiple .got subsections. */
182 struct alpha_elf_got_entry
184 struct alpha_elf_got_entry
*next
;
186 /* Which .got subsection? */
189 /* The addend in effect for this entry. */
192 /* The .got offset for this entry. */
195 /* How many references to this entry? */
198 /* The relocation type of this entry. */
199 unsigned char reloc_type
;
201 /* How a LITERAL is used. */
204 /* Have we initialized the dynamic relocation for this entry? */
205 unsigned char reloc_done
;
207 /* Have we adjusted this entry for SEC_MERGE? */
208 unsigned char reloc_xlated
;
211 /* Used to count non-got, non-plt relocations for delayed sizing
212 of relocation sections. */
213 struct alpha_elf_reloc_entry
215 struct alpha_elf_reloc_entry
*next
;
217 /* Which .reloc section? */
220 /* What kind of relocation? */
223 /* Is this against read-only section? */
224 unsigned int reltext
: 1;
226 /* How many did we find? */
231 /* Alpha ELF linker hash table. */
233 struct alpha_elf_link_hash_table
235 struct elf_link_hash_table root
;
237 /* The head of a list of .got subsections linked through
238 alpha_elf_tdata(abfd)->got_link_next. */
242 /* Look up an entry in a Alpha ELF linker hash table. */
244 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
245 ((struct alpha_elf_link_hash_entry *) \
246 elf_link_hash_lookup (&(table)->root, (string), (create), \
249 /* Traverse a Alpha ELF linker hash table. */
251 #define alpha_elf_link_hash_traverse(table, func, info) \
252 (elf_link_hash_traverse \
254 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
257 /* Get the Alpha ELF linker hash table from a link_info structure. */
259 #define alpha_elf_hash_table(p) \
260 ((struct alpha_elf_link_hash_table *) ((p)->hash))
262 /* Get the object's symbols as our own entry type. */
264 #define alpha_elf_sym_hashes(abfd) \
265 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
267 /* Should we do dynamic things to this symbol? */
270 alpha_elf_dynamic_symbol_p (h
, info
)
271 struct elf_link_hash_entry
*h
;
272 struct bfd_link_info
*info
;
277 while (h
->root
.type
== bfd_link_hash_indirect
278 || h
->root
.type
== bfd_link_hash_warning
)
279 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
281 if (h
->dynindx
== -1)
284 if (h
->root
.type
== bfd_link_hash_undefweak
285 || h
->root
.type
== bfd_link_hash_defweak
)
288 switch (ELF_ST_VISIBILITY (h
->other
))
296 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
301 if ((info
->shared
&& !info
->symbolic
)
302 || ((h
->elf_link_hash_flags
303 & (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
))
304 == (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
)))
310 /* Create an entry in a Alpha ELF linker hash table. */
312 static struct bfd_hash_entry
*
313 elf64_alpha_link_hash_newfunc (entry
, table
, string
)
314 struct bfd_hash_entry
*entry
;
315 struct bfd_hash_table
*table
;
318 struct alpha_elf_link_hash_entry
*ret
=
319 (struct alpha_elf_link_hash_entry
*) entry
;
321 /* Allocate the structure if it has not already been allocated by a
323 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
324 ret
= ((struct alpha_elf_link_hash_entry
*)
325 bfd_hash_allocate (table
,
326 sizeof (struct alpha_elf_link_hash_entry
)));
327 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
328 return (struct bfd_hash_entry
*) ret
;
330 /* Call the allocation method of the superclass. */
331 ret
= ((struct alpha_elf_link_hash_entry
*)
332 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
334 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
336 /* Set local fields. */
337 memset (&ret
->esym
, 0, sizeof (EXTR
));
338 /* We use -2 as a marker to indicate that the information has
339 not been set. -1 means there is no associated ifd. */
342 ret
->got_entries
= NULL
;
343 ret
->reloc_entries
= NULL
;
346 return (struct bfd_hash_entry
*) ret
;
349 /* Create a Alpha ELF linker hash table. */
351 static struct bfd_link_hash_table
*
352 elf64_alpha_bfd_link_hash_table_create (abfd
)
355 struct alpha_elf_link_hash_table
*ret
;
356 bfd_size_type amt
= sizeof (struct alpha_elf_link_hash_table
);
358 ret
= (struct alpha_elf_link_hash_table
*) bfd_zmalloc (amt
);
359 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
362 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
363 elf64_alpha_link_hash_newfunc
))
369 return &ret
->root
.root
;
372 /* We have some private fields hanging off of the elf_tdata structure. */
374 struct alpha_elf_obj_tdata
376 struct elf_obj_tdata root
;
378 /* For every input file, these are the got entries for that object's
380 struct alpha_elf_got_entry
** local_got_entries
;
382 /* For every input file, this is the object that owns the got that
383 this input file uses. */
386 /* For every got, this is a linked list through the objects using this got */
387 bfd
*in_got_link_next
;
389 /* For every got, this is a link to the next got subsegment. */
392 /* For every got, this is the section. */
395 /* For every got, this is it's total number of words. */
398 /* For every got, this is the sum of the number of words required
399 to hold all of the member object's local got. */
403 #define alpha_elf_tdata(abfd) \
404 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
407 elf64_alpha_mkobject (abfd
)
410 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
411 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
412 if (abfd
->tdata
.any
== NULL
)
418 elf64_alpha_object_p (abfd
)
421 /* Allocate our special target data. */
422 struct alpha_elf_obj_tdata
*new_tdata
;
423 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
424 new_tdata
= bfd_zalloc (abfd
, amt
);
425 if (new_tdata
== NULL
)
427 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
428 abfd
->tdata
.any
= new_tdata
;
430 /* Set the right machine number for an Alpha ELF file. */
431 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
434 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
435 from smaller values. Start with zero, widen, *then* decrement. */
436 #define MINUS_ONE (((bfd_vma)0) - 1)
438 #define SKIP_HOWTO(N) \
439 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
441 static reloc_howto_type elf64_alpha_howto_table
[] =
443 HOWTO (R_ALPHA_NONE
, /* type */
445 0, /* size (0 = byte, 1 = short, 2 = long) */
447 TRUE
, /* pc_relative */
449 complain_overflow_dont
, /* complain_on_overflow */
450 elf64_alpha_reloc_nil
, /* special_function */
452 FALSE
, /* partial_inplace */
455 TRUE
), /* pcrel_offset */
457 /* A 32 bit reference to a symbol. */
458 HOWTO (R_ALPHA_REFLONG
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 FALSE
, /* pc_relative */
464 complain_overflow_bitfield
, /* complain_on_overflow */
465 0, /* special_function */
466 "REFLONG", /* name */
467 FALSE
, /* partial_inplace */
468 0xffffffff, /* src_mask */
469 0xffffffff, /* dst_mask */
470 FALSE
), /* pcrel_offset */
472 /* A 64 bit reference to a symbol. */
473 HOWTO (R_ALPHA_REFQUAD
, /* type */
475 4, /* size (0 = byte, 1 = short, 2 = long) */
477 FALSE
, /* pc_relative */
479 complain_overflow_bitfield
, /* complain_on_overflow */
480 0, /* special_function */
481 "REFQUAD", /* name */
482 FALSE
, /* partial_inplace */
483 MINUS_ONE
, /* src_mask */
484 MINUS_ONE
, /* dst_mask */
485 FALSE
), /* pcrel_offset */
487 /* A 32 bit GP relative offset. This is just like REFLONG except
488 that when the value is used the value of the gp register will be
490 HOWTO (R_ALPHA_GPREL32
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 FALSE
, /* pc_relative */
496 complain_overflow_bitfield
, /* complain_on_overflow */
497 0, /* special_function */
498 "GPREL32", /* name */
499 FALSE
, /* partial_inplace */
500 0xffffffff, /* src_mask */
501 0xffffffff, /* dst_mask */
502 FALSE
), /* pcrel_offset */
504 /* Used for an instruction that refers to memory off the GP register. */
505 HOWTO (R_ALPHA_LITERAL
, /* type */
507 1, /* size (0 = byte, 1 = short, 2 = long) */
509 FALSE
, /* pc_relative */
511 complain_overflow_signed
, /* complain_on_overflow */
512 0, /* special_function */
513 "ELF_LITERAL", /* name */
514 FALSE
, /* partial_inplace */
515 0xffff, /* src_mask */
516 0xffff, /* dst_mask */
517 FALSE
), /* pcrel_offset */
519 /* This reloc only appears immediately following an ELF_LITERAL reloc.
520 It identifies a use of the literal. The symbol index is special:
521 1 means the literal address is in the base register of a memory
522 format instruction; 2 means the literal address is in the byte
523 offset register of a byte-manipulation instruction; 3 means the
524 literal address is in the target register of a jsr instruction.
525 This does not actually do any relocation. */
526 HOWTO (R_ALPHA_LITUSE
, /* type */
528 1, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE
, /* pc_relative */
532 complain_overflow_dont
, /* complain_on_overflow */
533 elf64_alpha_reloc_nil
, /* special_function */
535 FALSE
, /* partial_inplace */
538 FALSE
), /* pcrel_offset */
540 /* Load the gp register. This is always used for a ldah instruction
541 which loads the upper 16 bits of the gp register. The symbol
542 index of the GPDISP instruction is an offset in bytes to the lda
543 instruction that loads the lower 16 bits. The value to use for
544 the relocation is the difference between the GP value and the
545 current location; the load will always be done against a register
546 holding the current address.
548 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
549 any offset is present in the instructions, it is an offset from
550 the register to the ldah instruction. This lets us avoid any
551 stupid hackery like inventing a gp value to do partial relocation
552 against. Also unlike ECOFF, we do the whole relocation off of
553 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
554 space consuming bit, that, since all the information was present
555 in the GPDISP_HI16 reloc. */
556 HOWTO (R_ALPHA_GPDISP
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 FALSE
, /* pc_relative */
562 complain_overflow_dont
, /* complain_on_overflow */
563 elf64_alpha_reloc_gpdisp
, /* special_function */
565 FALSE
, /* partial_inplace */
566 0xffff, /* src_mask */
567 0xffff, /* dst_mask */
568 TRUE
), /* pcrel_offset */
570 /* A 21 bit branch. */
571 HOWTO (R_ALPHA_BRADDR
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 TRUE
, /* pc_relative */
577 complain_overflow_signed
, /* complain_on_overflow */
578 0, /* special_function */
580 FALSE
, /* partial_inplace */
581 0x1fffff, /* src_mask */
582 0x1fffff, /* dst_mask */
583 TRUE
), /* pcrel_offset */
585 /* A hint for a jump to a register. */
586 HOWTO (R_ALPHA_HINT
, /* type */
588 1, /* size (0 = byte, 1 = short, 2 = long) */
590 TRUE
, /* pc_relative */
592 complain_overflow_dont
, /* complain_on_overflow */
593 0, /* special_function */
595 FALSE
, /* partial_inplace */
596 0x3fff, /* src_mask */
597 0x3fff, /* dst_mask */
598 TRUE
), /* pcrel_offset */
600 /* 16 bit PC relative offset. */
601 HOWTO (R_ALPHA_SREL16
, /* type */
603 1, /* size (0 = byte, 1 = short, 2 = long) */
605 TRUE
, /* pc_relative */
607 complain_overflow_signed
, /* complain_on_overflow */
608 0, /* special_function */
610 FALSE
, /* partial_inplace */
611 0xffff, /* src_mask */
612 0xffff, /* dst_mask */
613 TRUE
), /* pcrel_offset */
615 /* 32 bit PC relative offset. */
616 HOWTO (R_ALPHA_SREL32
, /* type */
618 2, /* size (0 = byte, 1 = short, 2 = long) */
620 TRUE
, /* pc_relative */
622 complain_overflow_signed
, /* complain_on_overflow */
623 0, /* special_function */
625 FALSE
, /* partial_inplace */
626 0xffffffff, /* src_mask */
627 0xffffffff, /* dst_mask */
628 TRUE
), /* pcrel_offset */
630 /* A 64 bit PC relative offset. */
631 HOWTO (R_ALPHA_SREL64
, /* type */
633 4, /* size (0 = byte, 1 = short, 2 = long) */
635 TRUE
, /* pc_relative */
637 complain_overflow_signed
, /* complain_on_overflow */
638 0, /* special_function */
640 FALSE
, /* partial_inplace */
641 MINUS_ONE
, /* src_mask */
642 MINUS_ONE
, /* dst_mask */
643 TRUE
), /* pcrel_offset */
645 /* Skip 12 - 16; deprecated ECOFF relocs. */
652 /* The high 16 bits of the displacement from GP to the target. */
653 HOWTO (R_ALPHA_GPRELHIGH
,
655 1, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE
, /* pc_relative */
659 complain_overflow_signed
, /* complain_on_overflow */
660 0, /* special_function */
661 "GPRELHIGH", /* name */
662 FALSE
, /* partial_inplace */
663 0xffff, /* src_mask */
664 0xffff, /* dst_mask */
665 FALSE
), /* pcrel_offset */
667 /* The low 16 bits of the displacement from GP to the target. */
668 HOWTO (R_ALPHA_GPRELLOW
,
670 1, /* size (0 = byte, 1 = short, 2 = long) */
672 FALSE
, /* pc_relative */
674 complain_overflow_dont
, /* complain_on_overflow */
675 0, /* special_function */
676 "GPRELLOW", /* name */
677 FALSE
, /* partial_inplace */
678 0xffff, /* src_mask */
679 0xffff, /* dst_mask */
680 FALSE
), /* pcrel_offset */
682 /* A 16-bit displacement from the GP to the target. */
683 HOWTO (R_ALPHA_GPREL16
,
685 1, /* size (0 = byte, 1 = short, 2 = long) */
687 FALSE
, /* pc_relative */
689 complain_overflow_signed
, /* complain_on_overflow */
690 0, /* special_function */
691 "GPREL16", /* name */
692 FALSE
, /* partial_inplace */
693 0xffff, /* src_mask */
694 0xffff, /* dst_mask */
695 FALSE
), /* pcrel_offset */
697 /* Skip 20 - 23; deprecated ECOFF relocs. */
703 /* Misc ELF relocations. */
705 /* A dynamic relocation to copy the target into our .dynbss section. */
706 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
707 is present because every other ELF has one, but should not be used
708 because .dynbss is an ugly thing. */
715 complain_overflow_dont
,
716 bfd_elf_generic_reloc
,
723 /* A dynamic relocation for a .got entry. */
724 HOWTO (R_ALPHA_GLOB_DAT
,
730 complain_overflow_dont
,
731 bfd_elf_generic_reloc
,
738 /* A dynamic relocation for a .plt entry. */
739 HOWTO (R_ALPHA_JMP_SLOT
,
745 complain_overflow_dont
,
746 bfd_elf_generic_reloc
,
753 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
754 HOWTO (R_ALPHA_RELATIVE
,
760 complain_overflow_dont
,
761 bfd_elf_generic_reloc
,
768 /* A 21 bit branch that adjusts for gp loads. */
769 HOWTO (R_ALPHA_BRSGP
, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 TRUE
, /* pc_relative */
775 complain_overflow_signed
, /* complain_on_overflow */
776 0, /* special_function */
778 FALSE
, /* partial_inplace */
779 0x1fffff, /* src_mask */
780 0x1fffff, /* dst_mask */
781 TRUE
), /* pcrel_offset */
783 /* Creates a tls_index for the symbol in the got. */
784 HOWTO (R_ALPHA_TLSGD
, /* type */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
788 FALSE
, /* pc_relative */
790 complain_overflow_signed
, /* complain_on_overflow */
791 0, /* special_function */
793 FALSE
, /* partial_inplace */
794 0xffff, /* src_mask */
795 0xffff, /* dst_mask */
796 FALSE
), /* pcrel_offset */
798 /* Creates a tls_index for the (current) module in the got. */
799 HOWTO (R_ALPHA_TLSLDM
, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE
, /* pc_relative */
805 complain_overflow_signed
, /* complain_on_overflow */
806 0, /* special_function */
808 FALSE
, /* partial_inplace */
809 0xffff, /* src_mask */
810 0xffff, /* dst_mask */
811 FALSE
), /* pcrel_offset */
813 /* A dynamic relocation for a DTP module entry. */
814 HOWTO (R_ALPHA_DTPMOD64
, /* type */
816 4, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_bitfield
, /* complain_on_overflow */
821 0, /* special_function */
822 "DTPMOD64", /* name */
823 FALSE
, /* partial_inplace */
824 MINUS_ONE
, /* src_mask */
825 MINUS_ONE
, /* dst_mask */
826 FALSE
), /* pcrel_offset */
828 /* Creates a 64-bit offset in the got for the displacement
829 from DTP to the target. */
830 HOWTO (R_ALPHA_GOTDTPREL
, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE
, /* pc_relative */
836 complain_overflow_signed
, /* complain_on_overflow */
837 0, /* special_function */
838 "GOTDTPREL", /* name */
839 FALSE
, /* partial_inplace */
840 0xffff, /* src_mask */
841 0xffff, /* dst_mask */
842 FALSE
), /* pcrel_offset */
844 /* A dynamic relocation for a displacement from DTP to the target. */
845 HOWTO (R_ALPHA_DTPREL64
, /* type */
847 4, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_bitfield
, /* complain_on_overflow */
852 0, /* special_function */
853 "DTPREL64", /* name */
854 FALSE
, /* partial_inplace */
855 MINUS_ONE
, /* src_mask */
856 MINUS_ONE
, /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* The high 16 bits of the displacement from DTP to the target. */
860 HOWTO (R_ALPHA_DTPRELHI
, /* type */
862 1, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_signed
, /* complain_on_overflow */
867 0, /* special_function */
868 "DTPRELHI", /* name */
869 FALSE
, /* partial_inplace */
870 0xffff, /* src_mask */
871 0xffff, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 /* The low 16 bits of the displacement from DTP to the target. */
875 HOWTO (R_ALPHA_DTPRELLO
, /* type */
877 1, /* size (0 = byte, 1 = short, 2 = long) */
879 FALSE
, /* pc_relative */
881 complain_overflow_dont
, /* complain_on_overflow */
882 0, /* special_function */
883 "DTPRELLO", /* name */
884 FALSE
, /* partial_inplace */
885 0xffff, /* src_mask */
886 0xffff, /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* A 16-bit displacement from DTP to the target. */
890 HOWTO (R_ALPHA_DTPREL16
, /* type */
892 1, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE
, /* pc_relative */
896 complain_overflow_signed
, /* complain_on_overflow */
897 0, /* special_function */
898 "DTPREL16", /* name */
899 FALSE
, /* partial_inplace */
900 0xffff, /* src_mask */
901 0xffff, /* dst_mask */
902 FALSE
), /* pcrel_offset */
904 /* Creates a 64-bit offset in the got for the displacement
905 from TP to the target. */
906 HOWTO (R_ALPHA_GOTTPREL
, /* type */
908 1, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE
, /* pc_relative */
912 complain_overflow_signed
, /* complain_on_overflow */
913 0, /* special_function */
914 "GOTTPREL", /* name */
915 FALSE
, /* partial_inplace */
916 0xffff, /* src_mask */
917 0xffff, /* dst_mask */
918 FALSE
), /* pcrel_offset */
920 /* A dynamic relocation for a displacement from TP to the target. */
921 HOWTO (R_ALPHA_TPREL64
, /* type */
923 4, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_bitfield
, /* complain_on_overflow */
928 0, /* special_function */
929 "TPREL64", /* name */
930 FALSE
, /* partial_inplace */
931 MINUS_ONE
, /* src_mask */
932 MINUS_ONE
, /* dst_mask */
933 FALSE
), /* pcrel_offset */
935 /* The high 16 bits of the displacement from TP to the target. */
936 HOWTO (R_ALPHA_TPRELHI
, /* type */
938 1, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_signed
, /* complain_on_overflow */
943 0, /* special_function */
944 "TPRELHI", /* name */
945 FALSE
, /* partial_inplace */
946 0xffff, /* src_mask */
947 0xffff, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 /* The low 16 bits of the displacement from TP to the target. */
951 HOWTO (R_ALPHA_TPRELLO
, /* type */
953 1, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 0, /* special_function */
959 "TPRELLO", /* name */
960 FALSE
, /* partial_inplace */
961 0xffff, /* src_mask */
962 0xffff, /* dst_mask */
963 FALSE
), /* pcrel_offset */
965 /* A 16-bit displacement from TP to the target. */
966 HOWTO (R_ALPHA_TPREL16
, /* type */
968 1, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE
, /* pc_relative */
972 complain_overflow_signed
, /* complain_on_overflow */
973 0, /* special_function */
974 "TPREL16", /* name */
975 FALSE
, /* partial_inplace */
976 0xffff, /* src_mask */
977 0xffff, /* dst_mask */
978 FALSE
), /* pcrel_offset */
981 /* A relocation function which doesn't do anything. */
983 static bfd_reloc_status_type
984 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
985 bfd
*abfd ATTRIBUTE_UNUSED
;
987 asymbol
*sym ATTRIBUTE_UNUSED
;
988 PTR data ATTRIBUTE_UNUSED
;
991 char **error_message ATTRIBUTE_UNUSED
;
994 reloc
->address
+= sec
->output_offset
;
998 /* A relocation function used for an unsupported reloc. */
1000 static bfd_reloc_status_type
1001 elf64_alpha_reloc_bad (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
1002 bfd
*abfd ATTRIBUTE_UNUSED
;
1004 asymbol
*sym ATTRIBUTE_UNUSED
;
1005 PTR data ATTRIBUTE_UNUSED
;
1008 char **error_message ATTRIBUTE_UNUSED
;
1011 reloc
->address
+= sec
->output_offset
;
1012 return bfd_reloc_notsupported
;
1015 /* Do the work of the GPDISP relocation. */
1017 static bfd_reloc_status_type
1018 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
1024 bfd_reloc_status_type ret
= bfd_reloc_ok
;
1026 unsigned long i_ldah
, i_lda
;
1028 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
1029 i_lda
= bfd_get_32 (abfd
, p_lda
);
1031 /* Complain if the instructions are not correct. */
1032 if (((i_ldah
>> 26) & 0x3f) != 0x09
1033 || ((i_lda
>> 26) & 0x3f) != 0x08)
1034 ret
= bfd_reloc_dangerous
;
1036 /* Extract the user-supplied offset, mirroring the sign extensions
1037 that the instructions perform. */
1038 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
1039 addend
= (addend
^ 0x80008000) - 0x80008000;
1043 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
) 0x80000000
1044 || (bfd_signed_vma
) gpdisp
>= (bfd_signed_vma
) 0x7fff8000)
1045 ret
= bfd_reloc_overflow
;
1047 /* compensate for the sign extension again. */
1048 i_ldah
= ((i_ldah
& 0xffff0000)
1049 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
1050 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
1052 bfd_put_32 (abfd
, (bfd_vma
) i_ldah
, p_ldah
);
1053 bfd_put_32 (abfd
, (bfd_vma
) i_lda
, p_lda
);
1058 /* The special function for the GPDISP reloc. */
1060 static bfd_reloc_status_type
1061 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
1062 output_bfd
, err_msg
)
1064 arelent
*reloc_entry
;
1065 asymbol
*sym ATTRIBUTE_UNUSED
;
1067 asection
*input_section
;
1071 bfd_reloc_status_type ret
;
1072 bfd_vma gp
, relocation
;
1073 bfd_byte
*p_ldah
, *p_lda
;
1075 /* Don't do anything if we're not doing a final link. */
1078 reloc_entry
->address
+= input_section
->output_offset
;
1079 return bfd_reloc_ok
;
1082 if (reloc_entry
->address
> input_section
->_cooked_size
||
1083 reloc_entry
->address
+ reloc_entry
->addend
> input_section
->_cooked_size
)
1084 return bfd_reloc_outofrange
;
1086 /* The gp used in the portion of the output object to which this
1087 input object belongs is cached on the input bfd. */
1088 gp
= _bfd_get_gp_value (abfd
);
1090 relocation
= (input_section
->output_section
->vma
1091 + input_section
->output_offset
1092 + reloc_entry
->address
);
1094 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
1095 p_lda
= p_ldah
+ reloc_entry
->addend
;
1097 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
1099 /* Complain if the instructions are not correct. */
1100 if (ret
== bfd_reloc_dangerous
)
1101 *err_msg
= _("GPDISP relocation did not find ldah and lda instructions");
1106 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1108 struct elf_reloc_map
1110 bfd_reloc_code_real_type bfd_reloc_val
;
1114 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
1116 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
1117 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
1118 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
1119 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
1120 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
1121 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
1122 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
1123 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
1124 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
1125 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
1126 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
1127 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
1128 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
1129 {BFD_RELOC_ALPHA_GPREL_HI16
, R_ALPHA_GPRELHIGH
},
1130 {BFD_RELOC_ALPHA_GPREL_LO16
, R_ALPHA_GPRELLOW
},
1131 {BFD_RELOC_GPREL16
, R_ALPHA_GPREL16
},
1132 {BFD_RELOC_ALPHA_BRSGP
, R_ALPHA_BRSGP
},
1133 {BFD_RELOC_ALPHA_TLSGD
, R_ALPHA_TLSGD
},
1134 {BFD_RELOC_ALPHA_TLSLDM
, R_ALPHA_TLSLDM
},
1135 {BFD_RELOC_ALPHA_DTPMOD64
, R_ALPHA_DTPMOD64
},
1136 {BFD_RELOC_ALPHA_GOTDTPREL16
, R_ALPHA_GOTDTPREL
},
1137 {BFD_RELOC_ALPHA_DTPREL64
, R_ALPHA_DTPREL64
},
1138 {BFD_RELOC_ALPHA_DTPREL_HI16
, R_ALPHA_DTPRELHI
},
1139 {BFD_RELOC_ALPHA_DTPREL_LO16
, R_ALPHA_DTPRELLO
},
1140 {BFD_RELOC_ALPHA_DTPREL16
, R_ALPHA_DTPREL16
},
1141 {BFD_RELOC_ALPHA_GOTTPREL16
, R_ALPHA_GOTTPREL
},
1142 {BFD_RELOC_ALPHA_TPREL64
, R_ALPHA_TPREL64
},
1143 {BFD_RELOC_ALPHA_TPREL_HI16
, R_ALPHA_TPRELHI
},
1144 {BFD_RELOC_ALPHA_TPREL_LO16
, R_ALPHA_TPRELLO
},
1145 {BFD_RELOC_ALPHA_TPREL16
, R_ALPHA_TPREL16
},
1148 /* Given a BFD reloc type, return a HOWTO structure. */
1150 static reloc_howto_type
*
1151 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
1152 bfd
*abfd ATTRIBUTE_UNUSED
;
1153 bfd_reloc_code_real_type code
;
1155 const struct elf_reloc_map
*i
, *e
;
1156 i
= e
= elf64_alpha_reloc_map
;
1157 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
1160 if (i
->bfd_reloc_val
== code
)
1161 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
1166 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1169 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
1170 bfd
*abfd ATTRIBUTE_UNUSED
;
1172 Elf_Internal_Rela
*dst
;
1176 r_type
= ELF64_R_TYPE(dst
->r_info
);
1177 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1178 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1181 /* These two relocations create a two-word entry in the got. */
1182 #define alpha_got_entry_size(r_type) \
1183 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1185 /* This is PT_TLS segment p_vaddr. */
1186 #define alpha_get_dtprel_base(tlss) \
1189 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1190 is assigned offset round(16, PT_TLS p_align). */
1191 #define alpha_get_tprel_base(tlss) \
1192 ((tlss)->start - align_power ((bfd_vma) 16, (tlss)->align))
1194 /* These functions do relaxation for Alpha ELF.
1196 Currently I'm only handling what I can do with existing compiler
1197 and assembler support, which means no instructions are removed,
1198 though some may be nopped. At this time GCC does not emit enough
1199 information to do all of the relaxing that is possible. It will
1200 take some not small amount of work for that to happen.
1202 There are a couple of interesting papers that I once read on this
1203 subject, that I cannot find references to at the moment, that
1204 related to Alpha in particular. They are by David Wall, then of
1208 #define OP_LDAH 0x09
1209 #define INSN_JSR 0x68004000
1210 #define INSN_JSR_MASK 0xfc00c000
1214 #define INSN_UNOP 0x2ffe0000
1215 #define INSN_ADDQ 0x40000400
1216 #define INSN_RDUNIQ 0x0000009e
1218 struct alpha_relax_info
1223 Elf_Internal_Shdr
*symtab_hdr
;
1224 Elf_Internal_Rela
*relocs
, *relend
;
1225 struct bfd_link_info
*link_info
;
1226 struct elf_link_tls_segment
*tls_segment
;
1230 struct alpha_elf_link_hash_entry
*h
;
1231 struct alpha_elf_got_entry
**first_gotent
;
1232 struct alpha_elf_got_entry
*gotent
;
1233 bfd_boolean changed_contents
;
1234 bfd_boolean changed_relocs
;
1235 unsigned char other
;
1238 static bfd_boolean elf64_alpha_relax_with_lituse
1239 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1240 Elf_Internal_Rela
*irel
));
1241 static bfd_vma elf64_alpha_relax_opt_call
1242 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
));
1243 static bfd_boolean elf64_alpha_relax_got_load
1244 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1245 Elf_Internal_Rela
*irel
, unsigned long));
1246 static bfd_boolean elf64_alpha_relax_gprelhilo
1247 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1248 Elf_Internal_Rela
*irel
, bfd_boolean
));
1249 static bfd_boolean elf64_alpha_relax_tls_get_addr
1250 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1251 Elf_Internal_Rela
*irel
, bfd_boolean
));
1252 static struct elf_link_tls_segment
*elf64_alpha_relax_find_tls_segment
1253 PARAMS((struct alpha_relax_info
*, struct elf_link_tls_segment
*));
1254 static bfd_boolean elf64_alpha_relax_section
1255 PARAMS((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
1256 bfd_boolean
*again
));
1258 static Elf_Internal_Rela
*
1259 elf64_alpha_find_reloc_at_ofs (rel
, relend
, offset
, type
)
1260 Elf_Internal_Rela
*rel
, *relend
;
1264 while (rel
< relend
)
1266 if (rel
->r_offset
== offset
1267 && ELF64_R_TYPE (rel
->r_info
) == (unsigned int) type
)
1275 elf64_alpha_relax_with_lituse (info
, symval
, irel
)
1276 struct alpha_relax_info
*info
;
1278 Elf_Internal_Rela
*irel
;
1280 Elf_Internal_Rela
*urel
, *irelend
= info
->relend
;
1281 int flags
, count
, i
;
1282 bfd_signed_vma disp
;
1285 bfd_boolean lit_reused
= FALSE
;
1286 bfd_boolean all_optimized
= TRUE
;
1287 unsigned int lit_insn
;
1289 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1290 if (lit_insn
>> 26 != OP_LDQ
)
1292 ((*_bfd_error_handler
)
1293 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1294 bfd_archive_filename (info
->abfd
), info
->sec
->name
,
1295 (unsigned long) irel
->r_offset
));
1299 /* Can't relax dynamic symbols. */
1300 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
1303 /* Summarize how this particular LITERAL is used. */
1304 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
1306 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
1308 if (urel
->r_addend
<= 3)
1309 flags
|= 1 << urel
->r_addend
;
1312 /* A little preparation for the loop... */
1313 disp
= symval
- info
->gp
;
1315 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
1319 bfd_signed_vma xdisp
;
1321 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
1323 switch (urel
->r_addend
)
1325 case LITUSE_ALPHA_ADDR
:
1327 /* This type is really just a placeholder to note that all
1328 uses cannot be optimized, but to still allow some. */
1329 all_optimized
= FALSE
;
1332 case LITUSE_ALPHA_BASE
:
1333 /* We can always optimize 16-bit displacements. */
1335 /* Extract the displacement from the instruction, sign-extending
1336 it if necessary, then test whether it is within 16 or 32 bits
1337 displacement from GP. */
1338 insn_disp
= insn
& 0x0000ffff;
1339 if (insn_disp
& 0x8000)
1340 insn_disp
|= ~0xffff; /* Negative: sign-extend. */
1342 xdisp
= disp
+ insn_disp
;
1343 fits16
= (xdisp
>= - (bfd_signed_vma
) 0x8000 && xdisp
< 0x8000);
1344 fits32
= (xdisp
>= - (bfd_signed_vma
) 0x80000000
1345 && xdisp
< 0x7fff8000);
1349 /* Take the op code and dest from this insn, take the base
1350 register from the literal insn. Leave the offset alone. */
1351 insn
= (insn
& 0xffe0ffff) | (lit_insn
& 0x001f0000);
1352 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1354 urel
->r_addend
= irel
->r_addend
;
1355 info
->changed_relocs
= TRUE
;
1357 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1358 info
->contents
+ urel
->r_offset
);
1359 info
->changed_contents
= TRUE
;
1362 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1363 else if (fits32
&& !(flags
& ~6))
1365 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
1367 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1369 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
1370 bfd_put_32 (info
->abfd
, (bfd_vma
) lit_insn
,
1371 info
->contents
+ irel
->r_offset
);
1373 info
->changed_contents
= TRUE
;
1375 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1377 urel
->r_addend
= irel
->r_addend
;
1378 info
->changed_relocs
= TRUE
;
1381 all_optimized
= FALSE
;
1384 case LITUSE_ALPHA_BYTOFF
:
1385 /* We can always optimize byte instructions. */
1387 /* FIXME: sanity check the insn for byte op. Check that the
1388 literal dest reg is indeed Rb in the byte insn. */
1390 insn
&= ~ (unsigned) 0x001ff000;
1391 insn
|= ((symval
& 7) << 13) | 0x1000;
1393 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1395 info
->changed_relocs
= TRUE
;
1397 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1398 info
->contents
+ urel
->r_offset
);
1399 info
->changed_contents
= TRUE
;
1402 case LITUSE_ALPHA_JSR
:
1403 case LITUSE_ALPHA_TLSGD
:
1404 case LITUSE_ALPHA_TLSLDM
:
1406 bfd_vma optdest
, org
;
1407 bfd_signed_vma odisp
;
1409 /* If not zero, place to jump without needing pv. */
1410 optdest
= elf64_alpha_relax_opt_call (info
, symval
);
1411 org
= (info
->sec
->output_section
->vma
1412 + info
->sec
->output_offset
1413 + urel
->r_offset
+ 4);
1414 odisp
= (optdest
? optdest
: symval
) - org
;
1416 if (odisp
>= -0x400000 && odisp
< 0x400000)
1418 Elf_Internal_Rela
*xrel
;
1420 /* Preserve branch prediction call stack when possible. */
1421 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
1422 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
1424 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
1426 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1428 urel
->r_addend
= irel
->r_addend
;
1431 urel
->r_addend
+= optdest
- symval
;
1433 all_optimized
= FALSE
;
1435 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1436 info
->contents
+ urel
->r_offset
);
1438 /* Kill any HINT reloc that might exist for this insn. */
1439 xrel
= (elf64_alpha_find_reloc_at_ofs
1440 (info
->relocs
, info
->relend
, urel
->r_offset
,
1443 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1445 info
->changed_contents
= TRUE
;
1446 info
->changed_relocs
= TRUE
;
1449 all_optimized
= FALSE
;
1451 /* Even if the target is not in range for a direct branch,
1452 if we share a GP, we can eliminate the gp reload. */
1455 Elf_Internal_Rela
*gpdisp
1456 = (elf64_alpha_find_reloc_at_ofs
1457 (info
->relocs
, irelend
, urel
->r_offset
+ 4,
1461 bfd_byte
*p_ldah
= info
->contents
+ gpdisp
->r_offset
;
1462 bfd_byte
*p_lda
= p_ldah
+ gpdisp
->r_addend
;
1463 unsigned int ldah
= bfd_get_32 (info
->abfd
, p_ldah
);
1464 unsigned int lda
= bfd_get_32 (info
->abfd
, p_lda
);
1466 /* Verify that the instruction is "ldah $29,0($26)".
1467 Consider a function that ends in a noreturn call,
1468 and that the next function begins with an ldgp,
1469 and that by accident there is no padding between.
1470 In that case the insn would use $27 as the base. */
1471 if (ldah
== 0x27ba0000 && lda
== 0x23bd0000)
1473 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_ldah
);
1474 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_lda
);
1476 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1477 info
->changed_contents
= TRUE
;
1478 info
->changed_relocs
= TRUE
;
1487 /* If all cases were optimized, we can reduce the use count on this
1488 got entry by one, possibly eliminating it. */
1491 if (--info
->gotent
->use_count
== 0)
1493 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
1494 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1496 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1499 /* If the literal instruction is no longer needed (it may have been
1500 reused. We can eliminate it. */
1501 /* ??? For now, I don't want to deal with compacting the section,
1502 so just nop it out. */
1505 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1506 info
->changed_relocs
= TRUE
;
1508 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
,
1509 info
->contents
+ irel
->r_offset
);
1510 info
->changed_contents
= TRUE
;
1518 elf64_alpha_relax_opt_call (info
, symval
)
1519 struct alpha_relax_info
*info
;
1522 /* If the function has the same gp, and we can identify that the
1523 function does not use its function pointer, we can eliminate the
1526 /* If the symbol is marked NOPV, we are being told the function never
1527 needs its procedure value. */
1528 if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_NOPV
)
1531 /* If the symbol is marked STD_GP, we are being told the function does
1532 a normal ldgp in the first two words. */
1533 else if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_STD_GPLOAD
)
1536 /* Otherwise, we may be able to identify a GP load in the first two
1537 words, which we can then skip. */
1540 Elf_Internal_Rela
*tsec_relocs
, *tsec_relend
, *tsec_free
, *gpdisp
;
1543 /* Load the relocations from the section that the target symbol is in. */
1544 if (info
->sec
== info
->tsec
)
1546 tsec_relocs
= info
->relocs
;
1547 tsec_relend
= info
->relend
;
1552 tsec_relocs
= (_bfd_elf64_link_read_relocs
1553 (info
->abfd
, info
->tsec
, (PTR
) NULL
,
1554 (Elf_Internal_Rela
*) NULL
,
1555 info
->link_info
->keep_memory
));
1556 if (tsec_relocs
== NULL
)
1558 tsec_relend
= tsec_relocs
+ info
->tsec
->reloc_count
;
1559 tsec_free
= (info
->link_info
->keep_memory
? NULL
: tsec_relocs
);
1562 /* Recover the symbol's offset within the section. */
1563 ofs
= (symval
- info
->tsec
->output_section
->vma
1564 - info
->tsec
->output_offset
);
1566 /* Look for a GPDISP reloc. */
1567 gpdisp
= (elf64_alpha_find_reloc_at_ofs
1568 (tsec_relocs
, tsec_relend
, ofs
, R_ALPHA_GPDISP
));
1570 if (!gpdisp
|| gpdisp
->r_addend
!= 4)
1580 /* We've now determined that we can skip an initial gp load. Verify
1581 that the call and the target use the same gp. */
1582 if (info
->link_info
->hash
->creator
!= info
->tsec
->owner
->xvec
1583 || info
->gotobj
!= alpha_elf_tdata (info
->tsec
->owner
)->gotobj
)
1590 elf64_alpha_relax_got_load (info
, symval
, irel
, r_type
)
1591 struct alpha_relax_info
*info
;
1593 Elf_Internal_Rela
*irel
;
1594 unsigned long r_type
;
1597 bfd_signed_vma disp
;
1599 /* Get the instruction. */
1600 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1602 if (insn
>> 26 != OP_LDQ
)
1604 reloc_howto_type
*howto
= elf64_alpha_howto_table
+ r_type
;
1605 ((*_bfd_error_handler
)
1606 ("%s: %s+0x%lx: warning: %s relocation against unexpected insn",
1607 bfd_archive_filename (info
->abfd
), info
->sec
->name
,
1608 (unsigned long) irel
->r_offset
, howto
->name
));
1612 /* Can't relax dynamic symbols. */
1613 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
1616 /* Can't use local-exec relocations in shared libraries. */
1617 if (r_type
== R_ALPHA_GOTTPREL
&& info
->link_info
->shared
)
1620 if (r_type
== R_ALPHA_LITERAL
)
1621 disp
= symval
- info
->gp
;
1624 bfd_vma dtp_base
, tp_base
;
1626 BFD_ASSERT (info
->tls_segment
!= NULL
);
1627 dtp_base
= alpha_get_dtprel_base (info
->tls_segment
);
1628 tp_base
= alpha_get_tprel_base (info
->tls_segment
);
1629 disp
= symval
- (r_type
== R_ALPHA_GOTDTPREL
? dtp_base
: tp_base
);
1632 if (disp
< -0x8000 || disp
>= 0x8000)
1635 /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading
1636 a constant, so force the base register to be $31. */
1637 if (r_type
== R_ALPHA_LITERAL
)
1638 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
1640 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
1641 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, info
->contents
+ irel
->r_offset
);
1642 info
->changed_contents
= TRUE
;
1644 /* Reduce the use count on this got entry by one, possibly
1646 if (--info
->gotent
->use_count
== 0)
1648 int sz
= alpha_got_entry_size (r_type
);
1649 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1651 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1654 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
1657 case R_ALPHA_LITERAL
:
1658 r_type
= R_ALPHA_GPREL16
;
1660 case R_ALPHA_GOTDTPREL
:
1661 r_type
= R_ALPHA_DTPREL16
;
1663 case R_ALPHA_GOTTPREL
:
1664 r_type
= R_ALPHA_TPREL16
;
1671 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), r_type
);
1672 info
->changed_relocs
= TRUE
;
1674 /* ??? Search forward through this basic block looking for insns
1675 that use the target register. Stop after an insn modifying the
1676 register is seen, or after a branch or call.
1678 Any such memory load insn may be substituted by a load directly
1679 off the GP. This allows the memory load insn to be issued before
1680 the calculated GP register would otherwise be ready.
1682 Any such jsr insn can be replaced by a bsr if it is in range.
1684 This would mean that we'd have to _add_ relocations, the pain of
1685 which gives one pause. */
1691 elf64_alpha_relax_gprelhilo (info
, symval
, irel
, hi
)
1692 struct alpha_relax_info
*info
;
1694 Elf_Internal_Rela
*irel
;
1698 bfd_signed_vma disp
;
1699 bfd_byte
*pos
= info
->contents
+ irel
->r_offset
;
1701 /* ??? This assumes that the compiler doesn't render
1705 ldah t, array(gp) !gprelhigh
1707 ldq r, array(t) !gprellow
1709 which would indeed be the most efficient way to implement this. */
1713 disp
= symval
- info
->gp
;
1714 if (disp
< -0x8000 || disp
>= 0x8000)
1719 /* Nop out the high instruction. */
1721 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
);
1722 info
->changed_contents
= TRUE
;
1724 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1726 info
->changed_relocs
= TRUE
;
1730 /* Adjust the low instruction to reference GP directly. */
1732 insn
= bfd_get_32 (info
->abfd
, pos
);
1733 insn
= (insn
& 0xffe00000) | (29 << 16);
1734 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
);
1735 info
->changed_contents
= TRUE
;
1737 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1739 info
->changed_relocs
= TRUE
;
1746 elf64_alpha_relax_tls_get_addr (info
, symval
, irel
, is_gd
)
1747 struct alpha_relax_info
*info
;
1749 Elf_Internal_Rela
*irel
;
1754 Elf_Internal_Rela
*gpdisp
, *hint
;
1755 bfd_boolean dynamic
, use_gottprel
, pos1_unusable
;
1757 dynamic
= alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
);
1759 /* ??? For LD relaxation, we need a symbol referencing the beginning
1760 of the TLS segment. */
1761 /* ??? The STN_UNDEF symbol (dynindex 0) works fine for this. Adjust
1762 the code below to expect that. */
1766 /* If a TLS symbol is accessed using IE at least once, there is no point
1767 to use dynamic model for it. */
1768 if (is_gd
&& info
->h
&& (info
->h
->flags
& ALPHA_ELF_LINK_HASH_TLS_IE
))
1771 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
1772 then we might as well relax to IE. */
1773 else if (info
->link_info
->shared
&& !dynamic
1774 && (info
->link_info
->flags
& DF_STATIC_TLS
))
1777 /* Otherwise we must be building an executable to do anything. */
1778 else if (info
->link_info
->shared
)
1781 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
1782 the matching LITUSE_TLS relocations. */
1783 if (irel
+ 2 >= info
->relend
)
1785 if (ELF64_R_TYPE (irel
[1].r_info
) != R_ALPHA_LITERAL
1786 || ELF64_R_TYPE (irel
[2].r_info
) != R_ALPHA_LITUSE
1787 || irel
[2].r_addend
!= (is_gd
? LITUSE_ALPHA_TLSGD
: LITUSE_ALPHA_TLSLDM
))
1790 /* There must be a GPDISP relocation positioned immediately after the
1791 LITUSE relocation. */
1792 gpdisp
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
1793 irel
[2].r_offset
+ 4, R_ALPHA_GPDISP
);
1797 pos
[0] = info
->contents
+ irel
[0].r_offset
;
1798 pos
[1] = info
->contents
+ irel
[1].r_offset
;
1799 pos
[2] = info
->contents
+ irel
[2].r_offset
;
1800 pos
[3] = info
->contents
+ gpdisp
->r_offset
;
1801 pos
[4] = pos
[3] + gpdisp
->r_addend
;
1802 pos1_unusable
= FALSE
;
1804 /* Generally, the positions are not allowed to be out of order, lest the
1805 modified insn sequence have different register lifetimes. We can make
1806 an exception when pos 1 is adjacent to pos 0. */
1807 if (pos
[1] + 4 == pos
[0])
1809 bfd_byte
*tmp
= pos
[0];
1813 else if (pos
[1] < pos
[0])
1814 pos1_unusable
= TRUE
;
1815 if (pos
[1] >= pos
[2] || pos
[2] >= pos
[3])
1818 /* Reduce the use count on the LITERAL relocation. Do this before we
1819 smash the symndx when we adjust the relocations below. */
1821 struct alpha_elf_got_entry
*lit_gotent
;
1822 struct alpha_elf_link_hash_entry
*lit_h
;
1825 BFD_ASSERT (ELF64_R_SYM (irel
[1].r_info
) >= info
->symtab_hdr
->sh_info
);
1826 indx
= ELF64_R_SYM (irel
[1].r_info
) - info
->symtab_hdr
->sh_info
;
1827 lit_h
= alpha_elf_sym_hashes (info
->abfd
)[indx
];
1829 while (lit_h
->root
.root
.type
== bfd_link_hash_indirect
1830 || lit_h
->root
.root
.type
== bfd_link_hash_warning
)
1831 lit_h
= (struct alpha_elf_link_hash_entry
*) lit_h
->root
.root
.u
.i
.link
;
1833 for (lit_gotent
= lit_h
->got_entries
; lit_gotent
;
1834 lit_gotent
= lit_gotent
->next
)
1835 if (lit_gotent
->gotobj
== info
->gotobj
1836 && lit_gotent
->reloc_type
== R_ALPHA_LITERAL
1837 && lit_gotent
->addend
== irel
[1].r_addend
)
1839 BFD_ASSERT (lit_gotent
);
1841 if (--lit_gotent
->use_count
== 0)
1843 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
1844 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1850 lda $16,x($gp) !tlsgd!1
1851 ldq $27,__tls_get_addr($gp) !literal!1
1852 jsr $26,($27)__tls_get_addr !lituse_tlsgd!1
1853 ldah $29,0($26) !gpdisp!2
1854 lda $29,0($29) !gpdisp!2
1856 ldq $16,x($gp) !gottprel
1861 or the first pair to
1862 lda $16,x($gp) !tprel
1865 ldah $16,x($gp) !tprelhi
1866 lda $16,x($16) !tprello
1870 use_gottprel
= FALSE
;
1871 switch (!dynamic
&& !info
->link_info
->shared
)
1876 bfd_signed_vma disp
;
1878 BFD_ASSERT (info
->tls_segment
!= NULL
);
1879 tp_base
= alpha_get_tprel_base (info
->tls_segment
);
1880 disp
= symval
- tp_base
;
1882 if (disp
>= -0x8000 && disp
< 0x8000)
1884 insn
= (OP_LDA
<< 26) | (16 << 21) | (31 << 16);
1885 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1886 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
1888 irel
[0].r_offset
= pos
[0] - info
->contents
;
1889 irel
[0].r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1891 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1894 else if (disp
>= -(bfd_signed_vma
) 0x80000000
1895 && disp
< (bfd_signed_vma
) 0x7fff8000
1898 insn
= (OP_LDAH
<< 26) | (16 << 21) | (31 << 16);
1899 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1900 insn
= (OP_LDA
<< 26) | (16 << 21) | (16 << 16);
1901 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[1]);
1903 irel
[0].r_offset
= pos
[0] - info
->contents
;
1904 irel
[0].r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1906 irel
[1].r_offset
= pos
[1] - info
->contents
;
1907 irel
[1].r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1915 use_gottprel
= TRUE
;
1917 insn
= (OP_LDQ
<< 26) | (16 << 21) | (29 << 16);
1918 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1919 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
1921 irel
[0].r_offset
= pos
[0] - info
->contents
;
1922 irel
[0].r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1924 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1928 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_RDUNIQ
, pos
[2]);
1930 insn
= INSN_ADDQ
| (16 << 21) | (0 << 16) | (0 << 0);
1931 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[3]);
1933 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[4]);
1935 irel
[2].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1936 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1938 hint
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
1939 irel
[2].r_offset
, R_ALPHA_HINT
);
1941 hint
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1943 info
->changed_contents
= TRUE
;
1944 info
->changed_relocs
= TRUE
;
1946 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
1947 if (--info
->gotent
->use_count
== 0)
1949 int sz
= alpha_got_entry_size (info
->gotent
->reloc_type
);
1950 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1952 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1955 /* If we've switched to a GOTTPREL relocation, increment the reference
1956 count on that got entry. */
1959 struct alpha_elf_got_entry
*tprel_gotent
;
1961 for (tprel_gotent
= *info
->first_gotent
; tprel_gotent
;
1962 tprel_gotent
= tprel_gotent
->next
)
1963 if (tprel_gotent
->gotobj
== info
->gotobj
1964 && tprel_gotent
->reloc_type
== R_ALPHA_GOTTPREL
1965 && tprel_gotent
->addend
== irel
->r_addend
)
1968 tprel_gotent
->use_count
++;
1971 if (info
->gotent
->use_count
== 0)
1972 tprel_gotent
= info
->gotent
;
1975 tprel_gotent
= (struct alpha_elf_got_entry
*)
1976 bfd_alloc (info
->abfd
, sizeof (struct alpha_elf_got_entry
));
1980 tprel_gotent
->next
= *info
->first_gotent
;
1981 *info
->first_gotent
= tprel_gotent
;
1983 tprel_gotent
->gotobj
= info
->gotobj
;
1984 tprel_gotent
->addend
= irel
->r_addend
;
1985 tprel_gotent
->got_offset
= -1;
1986 tprel_gotent
->reloc_done
= 0;
1987 tprel_gotent
->reloc_xlated
= 0;
1990 tprel_gotent
->use_count
= 1;
1991 tprel_gotent
->reloc_type
= R_ALPHA_GOTTPREL
;
1998 static struct elf_link_tls_segment
*
1999 elf64_alpha_relax_find_tls_segment (info
, seg
)
2000 struct alpha_relax_info
*info
;
2001 struct elf_link_tls_segment
*seg
;
2003 bfd
*output_bfd
= info
->sec
->output_section
->owner
;
2008 for (o
= output_bfd
->sections
; o
; o
= o
->next
)
2009 if ((o
->flags
& SEC_THREAD_LOCAL
) != 0
2010 && (o
->flags
& SEC_LOAD
) != 0)
2022 if (bfd_get_section_alignment (output_bfd
, o
) > align
)
2023 align
= bfd_get_section_alignment (output_bfd
, o
);
2025 size
= o
->_raw_size
;
2026 if (size
== 0 && (o
->flags
& SEC_HAS_CONTENTS
) == 0)
2028 struct bfd_link_order
*lo
;
2029 for (lo
= o
->link_order_head
; lo
; lo
= lo
->next
)
2030 if (size
< lo
->offset
+ lo
->size
)
2031 size
= lo
->offset
+ lo
->size
;
2033 end
= o
->vma
+ size
;
2036 while (o
&& (o
->flags
& SEC_THREAD_LOCAL
));
2039 seg
->size
= end
- base
;
2046 elf64_alpha_relax_section (abfd
, sec
, link_info
, again
)
2049 struct bfd_link_info
*link_info
;
2052 Elf_Internal_Shdr
*symtab_hdr
;
2053 Elf_Internal_Rela
*internal_relocs
;
2054 Elf_Internal_Rela
*irel
, *irelend
;
2055 Elf_Internal_Sym
*isymbuf
= NULL
;
2056 struct alpha_elf_got_entry
**local_got_entries
;
2057 struct alpha_relax_info info
;
2058 struct elf_link_tls_segment tls_segment
;
2060 /* We are not currently changing any sizes, so only one pass. */
2063 if (link_info
->relocateable
2064 || (sec
->flags
& SEC_RELOC
) == 0
2065 || sec
->reloc_count
== 0)
2068 /* If this is the first time we have been called for this section,
2069 initialize the cooked size. */
2070 if (sec
->_cooked_size
== 0)
2071 sec
->_cooked_size
= sec
->_raw_size
;
2073 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2074 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2076 /* Load the relocations for this section. */
2077 internal_relocs
= (_bfd_elf64_link_read_relocs
2078 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2079 link_info
->keep_memory
));
2080 if (internal_relocs
== NULL
)
2083 memset(&info
, 0, sizeof (info
));
2086 info
.link_info
= link_info
;
2087 info
.symtab_hdr
= symtab_hdr
;
2088 info
.relocs
= internal_relocs
;
2089 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
2091 /* Find the GP for this object. Do not store the result back via
2092 _bfd_set_gp_value, since this could change again before final. */
2093 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
2096 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
2097 info
.gp
= (sgot
->output_section
->vma
2098 + sgot
->output_offset
2102 /* Get the section contents. */
2103 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2104 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
2107 info
.contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2108 if (info
.contents
== NULL
)
2111 if (! bfd_get_section_contents (abfd
, sec
, info
.contents
,
2112 (file_ptr
) 0, sec
->_raw_size
))
2116 /* Compute the TLS segment information. The version normally found in
2117 elf_hash_table (link_info)->tls_segment isn't built until final_link.
2118 ??? Probably should look into extracting this into a common function. */
2119 info
.tls_segment
= elf64_alpha_relax_find_tls_segment (&info
, &tls_segment
);
2121 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2124 struct alpha_elf_got_entry
*gotent
;
2125 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
2127 /* Early exit for unhandled or unrelaxable relocations. */
2130 case R_ALPHA_LITERAL
:
2131 case R_ALPHA_GPRELHIGH
:
2132 case R_ALPHA_GPRELLOW
:
2133 case R_ALPHA_GOTDTPREL
:
2134 case R_ALPHA_GOTTPREL
:
2136 case R_ALPHA_TLSLDM
:
2142 /* Get the value of the symbol referred to by the reloc. */
2143 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2145 /* A local symbol. */
2146 Elf_Internal_Sym
*isym
;
2148 /* Read this BFD's local symbols. */
2149 if (isymbuf
== NULL
)
2151 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2152 if (isymbuf
== NULL
)
2153 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2154 symtab_hdr
->sh_info
, 0,
2156 if (isymbuf
== NULL
)
2160 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
2161 if (isym
->st_shndx
== SHN_UNDEF
)
2163 else if (isym
->st_shndx
== SHN_ABS
)
2164 info
.tsec
= bfd_abs_section_ptr
;
2165 else if (isym
->st_shndx
== SHN_COMMON
)
2166 info
.tsec
= bfd_com_section_ptr
;
2168 info
.tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2171 info
.other
= isym
->st_other
;
2172 info
.first_gotent
= &local_got_entries
[ELF64_R_SYM(irel
->r_info
)];
2173 symval
= isym
->st_value
;
2178 struct alpha_elf_link_hash_entry
*h
;
2180 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2181 h
= alpha_elf_sym_hashes (abfd
)[indx
];
2182 BFD_ASSERT (h
!= NULL
);
2184 while (h
->root
.root
.type
== bfd_link_hash_indirect
2185 || h
->root
.root
.type
== bfd_link_hash_warning
)
2186 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2188 /* If the symbol is undefined, we can't do anything with it. */
2189 if (h
->root
.root
.type
== bfd_link_hash_undefweak
2190 || h
->root
.root
.type
== bfd_link_hash_undefined
)
2193 /* If the symbol isn't defined in the current module, again
2194 we can't do anything. */
2195 if (!(h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2199 info
.tsec
= h
->root
.root
.u
.def
.section
;
2200 info
.other
= h
->root
.other
;
2201 info
.first_gotent
= &h
->got_entries
;
2202 symval
= h
->root
.root
.u
.def
.value
;
2205 /* Search for the got entry to be used by this relocation. */
2206 for (gotent
= *info
.first_gotent
; gotent
; gotent
= gotent
->next
)
2207 if (gotent
->gotobj
== info
.gotobj
2208 && gotent
->reloc_type
== r_type
2209 && gotent
->addend
== irel
->r_addend
)
2211 info
.gotent
= gotent
;
2213 symval
+= info
.tsec
->output_section
->vma
+ info
.tsec
->output_offset
;
2214 symval
+= irel
->r_addend
;
2218 case R_ALPHA_LITERAL
:
2219 BFD_ASSERT(info
.gotent
!= NULL
);
2221 /* If there exist LITUSE relocations immediately following, this
2222 opens up all sorts of interesting optimizations, because we
2223 now know every location that this address load is used. */
2224 if (irel
+1 < irelend
2225 && ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
2227 if (!elf64_alpha_relax_with_lituse (&info
, symval
, irel
))
2232 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
2237 case R_ALPHA_GPRELHIGH
:
2238 case R_ALPHA_GPRELLOW
:
2239 if (!elf64_alpha_relax_gprelhilo (&info
, symval
, irel
,
2240 r_type
== R_ALPHA_GPRELHIGH
))
2244 case R_ALPHA_GOTDTPREL
:
2245 case R_ALPHA_GOTTPREL
:
2246 BFD_ASSERT(info
.gotent
!= NULL
);
2247 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
2252 case R_ALPHA_TLSLDM
:
2253 BFD_ASSERT(info
.gotent
!= NULL
);
2254 if (!elf64_alpha_relax_tls_get_addr (&info
, symval
, irel
,
2255 r_type
== R_ALPHA_TLSGD
))
2261 if (!elf64_alpha_size_plt_section (link_info
))
2263 if (!elf64_alpha_size_got_sections (link_info
))
2265 if (!elf64_alpha_size_rela_got_section (link_info
))
2269 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2271 if (!link_info
->keep_memory
)
2275 /* Cache the symbols for elf_link_input_bfd. */
2276 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2280 if (info
.contents
!= NULL
2281 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
2283 if (!info
.changed_contents
&& !link_info
->keep_memory
)
2284 free (info
.contents
);
2287 /* Cache the section contents for elf_link_input_bfd. */
2288 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
2292 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2294 if (!info
.changed_relocs
)
2295 free (internal_relocs
);
2297 elf_section_data (sec
)->relocs
= internal_relocs
;
2300 *again
= info
.changed_contents
|| info
.changed_relocs
;
2306 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2308 if (info
.contents
!= NULL
2309 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
2310 free (info
.contents
);
2311 if (internal_relocs
!= NULL
2312 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2313 free (internal_relocs
);
2318 #define PLT_HEADER_SIZE 32
2319 #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */
2320 #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */
2321 #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */
2322 #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */
2324 #define PLT_ENTRY_SIZE 12
2325 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
2326 #define PLT_ENTRY_WORD2 0
2327 #define PLT_ENTRY_WORD3 0
2329 #define MAX_GOT_SIZE (64*1024)
2331 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
2333 /* Handle an Alpha specific section when reading an object file. This
2334 is called when elfcode.h finds a section with an unknown type.
2335 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
2339 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
2341 Elf_Internal_Shdr
*hdr
;
2346 /* There ought to be a place to keep ELF backend specific flags, but
2347 at the moment there isn't one. We just keep track of the
2348 sections by their name, instead. Fortunately, the ABI gives
2349 suggested names for all the MIPS specific sections, so we will
2350 probably get away with this. */
2351 switch (hdr
->sh_type
)
2353 case SHT_ALPHA_DEBUG
:
2354 if (strcmp (name
, ".mdebug") != 0)
2361 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2363 newsect
= hdr
->bfd_section
;
2365 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
2367 if (! bfd_set_section_flags (abfd
, newsect
,
2368 (bfd_get_section_flags (abfd
, newsect
)
2376 /* Convert Alpha specific section flags to bfd internal section flags. */
2379 elf64_alpha_section_flags (flags
, hdr
)
2381 Elf_Internal_Shdr
*hdr
;
2383 if (hdr
->sh_flags
& SHF_ALPHA_GPREL
)
2384 *flags
|= SEC_SMALL_DATA
;
2389 /* Set the correct type for an Alpha ELF section. We do this by the
2390 section name, which is a hack, but ought to work. */
2393 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
2395 Elf_Internal_Shdr
*hdr
;
2398 register const char *name
;
2400 name
= bfd_get_section_name (abfd
, sec
);
2402 if (strcmp (name
, ".mdebug") == 0)
2404 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
2405 /* In a shared object on Irix 5.3, the .mdebug section has an
2406 entsize of 0. FIXME: Does this matter? */
2407 if ((abfd
->flags
& DYNAMIC
) != 0 )
2408 hdr
->sh_entsize
= 0;
2410 hdr
->sh_entsize
= 1;
2412 else if ((sec
->flags
& SEC_SMALL_DATA
)
2413 || strcmp (name
, ".sdata") == 0
2414 || strcmp (name
, ".sbss") == 0
2415 || strcmp (name
, ".lit4") == 0
2416 || strcmp (name
, ".lit8") == 0)
2417 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
2422 /* Hook called by the linker routine which adds symbols from an object
2423 file. We use it to put .comm items in .sbss, and not .bss. */
2426 elf64_alpha_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2428 struct bfd_link_info
*info
;
2429 const Elf_Internal_Sym
*sym
;
2430 const char **namep ATTRIBUTE_UNUSED
;
2431 flagword
*flagsp ATTRIBUTE_UNUSED
;
2435 if (sym
->st_shndx
== SHN_COMMON
2436 && !info
->relocateable
2437 && sym
->st_size
<= elf_gp_size (abfd
))
2439 /* Common symbols less than or equal to -G nn bytes are
2440 automatically put into .sbss. */
2442 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
2446 scomm
= bfd_make_section (abfd
, ".scommon");
2448 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
2450 | SEC_LINKER_CREATED
)))
2455 *valp
= sym
->st_size
;
2461 /* Create the .got section. */
2464 elf64_alpha_create_got_section(abfd
, info
)
2466 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2470 if (bfd_get_section_by_name (abfd
, ".got"))
2473 s
= bfd_make_section (abfd
, ".got");
2475 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2478 | SEC_LINKER_CREATED
))
2479 || !bfd_set_section_alignment (abfd
, s
, 3))
2482 alpha_elf_tdata (abfd
)->got
= s
;
2487 /* Create all the dynamic sections. */
2490 elf64_alpha_create_dynamic_sections (abfd
, info
)
2492 struct bfd_link_info
*info
;
2495 struct elf_link_hash_entry
*h
;
2496 struct bfd_link_hash_entry
*bh
;
2498 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
2500 s
= bfd_make_section (abfd
, ".plt");
2502 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2505 | SEC_LINKER_CREATED
2507 || ! bfd_set_section_alignment (abfd
, s
, 3))
2510 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2513 if (! (_bfd_generic_link_add_one_symbol
2514 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
2515 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
2516 get_elf_backend_data (abfd
)->collect
, &bh
)))
2518 h
= (struct elf_link_hash_entry
*) bh
;
2519 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2520 h
->type
= STT_OBJECT
;
2523 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2526 s
= bfd_make_section (abfd
, ".rela.plt");
2528 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2531 | SEC_LINKER_CREATED
2533 || ! bfd_set_section_alignment (abfd
, s
, 3))
2536 /* We may or may not have created a .got section for this object, but
2537 we definitely havn't done the rest of the work. */
2539 if (!elf64_alpha_create_got_section (abfd
, info
))
2542 s
= bfd_make_section(abfd
, ".rela.got");
2544 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2547 | SEC_LINKER_CREATED
2549 || !bfd_set_section_alignment (abfd
, s
, 3))
2552 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
2553 dynobj's .got section. We don't do this in the linker script
2554 because we don't want to define the symbol if we are not creating
2555 a global offset table. */
2557 if (!(_bfd_generic_link_add_one_symbol
2558 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
,
2559 alpha_elf_tdata(abfd
)->got
, (bfd_vma
) 0, (const char *) NULL
,
2560 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2562 h
= (struct elf_link_hash_entry
*) bh
;
2563 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2564 h
->type
= STT_OBJECT
;
2567 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2570 elf_hash_table (info
)->hgot
= h
;
2575 /* Read ECOFF debugging information from a .mdebug section into a
2576 ecoff_debug_info structure. */
2579 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
2582 struct ecoff_debug_info
*debug
;
2585 const struct ecoff_debug_swap
*swap
;
2586 char *ext_hdr
= NULL
;
2588 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2589 memset (debug
, 0, sizeof (*debug
));
2591 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
2592 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2595 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2596 swap
->external_hdr_size
))
2599 symhdr
= &debug
->symbolic_header
;
2600 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2602 /* The symbolic header contains absolute file offsets and sizes to
2604 #define READ(ptr, offset, count, size, type) \
2605 if (symhdr->count == 0) \
2606 debug->ptr = NULL; \
2609 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
2610 debug->ptr = (type) bfd_malloc (amt); \
2611 if (debug->ptr == NULL) \
2612 goto error_return; \
2613 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2614 || bfd_bread (debug->ptr, amt, abfd) != amt) \
2615 goto error_return; \
2618 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2619 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2620 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2621 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2622 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2623 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2625 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2626 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2627 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2628 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2629 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2633 debug
->adjust
= NULL
;
2638 if (ext_hdr
!= NULL
)
2640 if (debug
->line
!= NULL
)
2642 if (debug
->external_dnr
!= NULL
)
2643 free (debug
->external_dnr
);
2644 if (debug
->external_pdr
!= NULL
)
2645 free (debug
->external_pdr
);
2646 if (debug
->external_sym
!= NULL
)
2647 free (debug
->external_sym
);
2648 if (debug
->external_opt
!= NULL
)
2649 free (debug
->external_opt
);
2650 if (debug
->external_aux
!= NULL
)
2651 free (debug
->external_aux
);
2652 if (debug
->ss
!= NULL
)
2654 if (debug
->ssext
!= NULL
)
2655 free (debug
->ssext
);
2656 if (debug
->external_fdr
!= NULL
)
2657 free (debug
->external_fdr
);
2658 if (debug
->external_rfd
!= NULL
)
2659 free (debug
->external_rfd
);
2660 if (debug
->external_ext
!= NULL
)
2661 free (debug
->external_ext
);
2665 /* Alpha ELF local labels start with '$'. */
2668 elf64_alpha_is_local_label_name (abfd
, name
)
2669 bfd
*abfd ATTRIBUTE_UNUSED
;
2672 return name
[0] == '$';
2675 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2676 routine in order to handle the ECOFF debugging information. We
2677 still call this mips_elf_find_line because of the slot
2678 find_line_info in elf_obj_tdata is declared that way. */
2680 struct mips_elf_find_line
2682 struct ecoff_debug_info d
;
2683 struct ecoff_find_line i
;
2687 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2688 functionname_ptr
, line_ptr
)
2693 const char **filename_ptr
;
2694 const char **functionname_ptr
;
2695 unsigned int *line_ptr
;
2699 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
2700 filename_ptr
, functionname_ptr
,
2702 &elf_tdata (abfd
)->dwarf2_find_line_info
))
2705 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2709 struct mips_elf_find_line
*fi
;
2710 const struct ecoff_debug_swap
* const swap
=
2711 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2713 /* If we are called during a link, alpha_elf_final_link may have
2714 cleared the SEC_HAS_CONTENTS field. We force it back on here
2715 if appropriate (which it normally will be). */
2716 origflags
= msec
->flags
;
2717 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2718 msec
->flags
|= SEC_HAS_CONTENTS
;
2720 fi
= elf_tdata (abfd
)->find_line_info
;
2723 bfd_size_type external_fdr_size
;
2726 struct fdr
*fdr_ptr
;
2727 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
2729 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
2732 msec
->flags
= origflags
;
2736 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
2738 msec
->flags
= origflags
;
2742 /* Swap in the FDR information. */
2743 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
2744 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
2745 if (fi
->d
.fdr
== NULL
)
2747 msec
->flags
= origflags
;
2750 external_fdr_size
= swap
->external_fdr_size
;
2751 fdr_ptr
= fi
->d
.fdr
;
2752 fraw_src
= (char *) fi
->d
.external_fdr
;
2753 fraw_end
= (fraw_src
2754 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2755 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2756 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2758 elf_tdata (abfd
)->find_line_info
= fi
;
2760 /* Note that we don't bother to ever free this information.
2761 find_nearest_line is either called all the time, as in
2762 objdump -l, so the information should be saved, or it is
2763 rarely called, as in ld error messages, so the memory
2764 wasted is unimportant. Still, it would probably be a
2765 good idea for free_cached_info to throw it away. */
2768 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2769 &fi
->i
, filename_ptr
, functionname_ptr
,
2772 msec
->flags
= origflags
;
2776 msec
->flags
= origflags
;
2779 /* Fall back on the generic ELF find_nearest_line routine. */
2781 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2782 filename_ptr
, functionname_ptr
,
2786 /* Structure used to pass information to alpha_elf_output_extsym. */
2791 struct bfd_link_info
*info
;
2792 struct ecoff_debug_info
*debug
;
2793 const struct ecoff_debug_swap
*swap
;
2798 elf64_alpha_output_extsym (h
, data
)
2799 struct alpha_elf_link_hash_entry
*h
;
2802 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2804 asection
*sec
, *output_section
;
2806 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2807 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2809 if (h
->root
.indx
== -2)
2811 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2812 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2813 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2814 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2816 else if (einfo
->info
->strip
== strip_all
2817 || (einfo
->info
->strip
== strip_some
2818 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2819 h
->root
.root
.root
.string
,
2820 FALSE
, FALSE
) == NULL
))
2828 if (h
->esym
.ifd
== -2)
2831 h
->esym
.cobol_main
= 0;
2832 h
->esym
.weakext
= 0;
2833 h
->esym
.reserved
= 0;
2834 h
->esym
.ifd
= ifdNil
;
2835 h
->esym
.asym
.value
= 0;
2836 h
->esym
.asym
.st
= stGlobal
;
2838 if (h
->root
.root
.type
!= bfd_link_hash_defined
2839 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2840 h
->esym
.asym
.sc
= scAbs
;
2845 sec
= h
->root
.root
.u
.def
.section
;
2846 output_section
= sec
->output_section
;
2848 /* When making a shared library and symbol h is the one from
2849 the another shared library, OUTPUT_SECTION may be null. */
2850 if (output_section
== NULL
)
2851 h
->esym
.asym
.sc
= scUndefined
;
2854 name
= bfd_section_name (output_section
->owner
, output_section
);
2856 if (strcmp (name
, ".text") == 0)
2857 h
->esym
.asym
.sc
= scText
;
2858 else if (strcmp (name
, ".data") == 0)
2859 h
->esym
.asym
.sc
= scData
;
2860 else if (strcmp (name
, ".sdata") == 0)
2861 h
->esym
.asym
.sc
= scSData
;
2862 else if (strcmp (name
, ".rodata") == 0
2863 || strcmp (name
, ".rdata") == 0)
2864 h
->esym
.asym
.sc
= scRData
;
2865 else if (strcmp (name
, ".bss") == 0)
2866 h
->esym
.asym
.sc
= scBss
;
2867 else if (strcmp (name
, ".sbss") == 0)
2868 h
->esym
.asym
.sc
= scSBss
;
2869 else if (strcmp (name
, ".init") == 0)
2870 h
->esym
.asym
.sc
= scInit
;
2871 else if (strcmp (name
, ".fini") == 0)
2872 h
->esym
.asym
.sc
= scFini
;
2874 h
->esym
.asym
.sc
= scAbs
;
2878 h
->esym
.asym
.reserved
= 0;
2879 h
->esym
.asym
.index
= indexNil
;
2882 if (h
->root
.root
.type
== bfd_link_hash_common
)
2883 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2884 else if (h
->root
.root
.type
== bfd_link_hash_defined
2885 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2887 if (h
->esym
.asym
.sc
== scCommon
)
2888 h
->esym
.asym
.sc
= scBss
;
2889 else if (h
->esym
.asym
.sc
== scSCommon
)
2890 h
->esym
.asym
.sc
= scSBss
;
2892 sec
= h
->root
.root
.u
.def
.section
;
2893 output_section
= sec
->output_section
;
2894 if (output_section
!= NULL
)
2895 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2896 + sec
->output_offset
2897 + output_section
->vma
);
2899 h
->esym
.asym
.value
= 0;
2901 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2903 /* Set type and value for a symbol with a function stub. */
2904 h
->esym
.asym
.st
= stProc
;
2905 sec
= bfd_get_section_by_name (einfo
->abfd
, ".plt");
2907 h
->esym
.asym
.value
= 0;
2910 output_section
= sec
->output_section
;
2911 if (output_section
!= NULL
)
2912 h
->esym
.asym
.value
= (h
->root
.plt
.offset
2913 + sec
->output_offset
2914 + output_section
->vma
);
2916 h
->esym
.asym
.value
= 0;
2920 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2921 h
->root
.root
.root
.string
,
2924 einfo
->failed
= TRUE
;
2931 /* Search for and possibly create a got entry. */
2933 static struct alpha_elf_got_entry
*
2934 get_got_entry (abfd
, h
, r_type
, r_symndx
, r_addend
)
2936 struct alpha_elf_link_hash_entry
*h
;
2937 unsigned long r_type
, r_symndx
;
2940 struct alpha_elf_got_entry
*gotent
;
2941 struct alpha_elf_got_entry
**slot
;
2944 slot
= &h
->got_entries
;
2947 /* This is a local .got entry -- record for merge. */
2949 struct alpha_elf_got_entry
**local_got_entries
;
2951 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2952 if (!local_got_entries
)
2955 Elf_Internal_Shdr
*symtab_hdr
;
2957 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
2958 size
= symtab_hdr
->sh_info
;
2959 size
*= sizeof (struct alpha_elf_got_entry
*);
2962 = (struct alpha_elf_got_entry
**) bfd_zalloc (abfd
, size
);
2963 if (!local_got_entries
)
2966 alpha_elf_tdata (abfd
)->local_got_entries
= local_got_entries
;
2969 slot
= &local_got_entries
[r_symndx
];
2972 for (gotent
= *slot
; gotent
; gotent
= gotent
->next
)
2973 if (gotent
->gotobj
== abfd
2974 && gotent
->reloc_type
== r_type
2975 && gotent
->addend
== r_addend
)
2983 amt
= sizeof (struct alpha_elf_got_entry
);
2984 gotent
= (struct alpha_elf_got_entry
*) bfd_alloc (abfd
, amt
);
2988 gotent
->gotobj
= abfd
;
2989 gotent
->addend
= r_addend
;
2990 gotent
->got_offset
= -1;
2991 gotent
->use_count
= 1;
2992 gotent
->reloc_type
= r_type
;
2993 gotent
->reloc_done
= 0;
2994 gotent
->reloc_xlated
= 0;
2996 gotent
->next
= *slot
;
2999 entry_size
= alpha_got_entry_size (r_type
);
3000 alpha_elf_tdata (abfd
)->total_got_size
+= entry_size
;
3002 alpha_elf_tdata(abfd
)->local_got_size
+= entry_size
;
3005 gotent
->use_count
+= 1;
3010 /* Handle dynamic relocations when doing an Alpha ELF link. */
3013 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
3015 struct bfd_link_info
*info
;
3017 const Elf_Internal_Rela
*relocs
;
3021 const char *rel_sec_name
;
3022 Elf_Internal_Shdr
*symtab_hdr
;
3023 struct alpha_elf_link_hash_entry
**sym_hashes
;
3024 const Elf_Internal_Rela
*rel
, *relend
;
3025 bfd_boolean got_created
;
3028 if (info
->relocateable
)
3031 dynobj
= elf_hash_table(info
)->dynobj
;
3033 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
3036 rel_sec_name
= NULL
;
3037 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
3038 sym_hashes
= alpha_elf_sym_hashes(abfd
);
3039 got_created
= FALSE
;
3041 relend
= relocs
+ sec
->reloc_count
;
3042 for (rel
= relocs
; rel
< relend
; ++rel
)
3050 unsigned long r_symndx
, r_type
;
3051 struct alpha_elf_link_hash_entry
*h
;
3052 unsigned int gotent_flags
;
3053 bfd_boolean maybe_dynamic
;
3057 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3058 if (r_symndx
< symtab_hdr
->sh_info
)
3062 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3064 while (h
->root
.root
.type
== bfd_link_hash_indirect
3065 || h
->root
.root
.type
== bfd_link_hash_warning
)
3066 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3068 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
3071 /* We can only get preliminary data on whether a symbol is
3072 locally or externally defined, as not all of the input files
3073 have yet been processed. Do something with what we know, as
3074 this may help reduce memory usage and processing time later. */
3075 maybe_dynamic
= FALSE
;
3076 if (h
&& ((info
->shared
3077 && (!info
->symbolic
|| info
->allow_shlib_undefined
))
3078 || ! (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
3079 || h
->root
.root
.type
== bfd_link_hash_defweak
))
3080 maybe_dynamic
= TRUE
;
3084 r_type
= ELF64_R_TYPE (rel
->r_info
);
3085 addend
= rel
->r_addend
;
3089 case R_ALPHA_LITERAL
:
3090 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3092 /* Remember how this literal is used from its LITUSEs.
3093 This will be important when it comes to decide if we can
3094 create a .plt entry for a function symbol. */
3095 while (++rel
< relend
&& ELF64_R_TYPE (rel
->r_info
) == R_ALPHA_LITUSE
)
3096 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 5)
3097 gotent_flags
|= 1 << rel
->r_addend
;
3100 /* No LITUSEs -- presumably the address is used somehow. */
3101 if (gotent_flags
== 0)
3102 gotent_flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
3105 case R_ALPHA_GPDISP
:
3106 case R_ALPHA_GPREL16
:
3107 case R_ALPHA_GPREL32
:
3108 case R_ALPHA_GPRELHIGH
:
3109 case R_ALPHA_GPRELLOW
:
3114 case R_ALPHA_REFLONG
:
3115 case R_ALPHA_REFQUAD
:
3116 if ((info
->shared
&& (sec
->flags
& SEC_ALLOC
)) || maybe_dynamic
)
3121 case R_ALPHA_TLSLDM
:
3122 case R_ALPHA_GOTDTPREL
:
3123 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3126 case R_ALPHA_GOTTPREL
:
3127 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3128 gotent_flags
= ALPHA_ELF_LINK_HASH_TLS_IE
;
3130 info
->flags
|= DF_STATIC_TLS
;
3133 case R_ALPHA_TPREL64
:
3134 if (info
->shared
|| maybe_dynamic
)
3137 info
->flags
|= DF_STATIC_TLS
;
3141 if (need
& NEED_GOT
)
3145 if (!elf64_alpha_create_got_section (abfd
, info
))
3148 /* Make sure the object's gotobj is set to itself so
3149 that we default to every object with its own .got.
3150 We'll merge .gots later once we've collected each
3152 alpha_elf_tdata(abfd
)->gotobj
= abfd
;
3158 if (need
& NEED_GOT_ENTRY
)
3160 struct alpha_elf_got_entry
*gotent
;
3162 gotent
= get_got_entry (abfd
, h
, r_type
, r_symndx
, addend
);
3168 gotent
->flags
|= gotent_flags
;
3171 gotent_flags
|= h
->flags
;
3172 h
->flags
= gotent_flags
;
3174 /* Make a guess as to whether a .plt entry is needed. */
3175 if ((gotent_flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
)
3176 && !(gotent_flags
& ~ALPHA_ELF_LINK_HASH_LU_FUNC
))
3177 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3179 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3184 if (need
& NEED_DYNREL
)
3186 if (rel_sec_name
== NULL
)
3188 rel_sec_name
= (bfd_elf_string_from_elf_section
3189 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
3190 elf_section_data(sec
)->rel_hdr
.sh_name
));
3191 if (rel_sec_name
== NULL
)
3194 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
3195 && strcmp (bfd_get_section_name (abfd
, sec
),
3196 rel_sec_name
+5) == 0);
3199 /* We need to create the section here now whether we eventually
3200 use it or not so that it gets mapped to an output section by
3201 the linker. If not used, we'll kill it in
3202 size_dynamic_sections. */
3205 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
3210 sreloc
= bfd_make_section (dynobj
, rel_sec_name
);
3211 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3212 | SEC_LINKER_CREATED
| SEC_READONLY
);
3213 if (sec
->flags
& SEC_ALLOC
)
3214 flags
|= SEC_ALLOC
| SEC_LOAD
;
3216 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
3217 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
3224 /* Since we havn't seen all of the input symbols yet, we
3225 don't know whether we'll actually need a dynamic relocation
3226 entry for this reloc. So make a record of it. Once we
3227 find out if this thing needs dynamic relocation we'll
3228 expand the relocation sections by the appropriate amount. */
3230 struct alpha_elf_reloc_entry
*rent
;
3232 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
3233 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
3238 amt
= sizeof (struct alpha_elf_reloc_entry
);
3239 rent
= (struct alpha_elf_reloc_entry
*) bfd_alloc (abfd
, amt
);
3243 rent
->srel
= sreloc
;
3244 rent
->rtype
= r_type
;
3246 rent
->reltext
= ((sec
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3247 == (SEC_READONLY
| SEC_ALLOC
));
3249 rent
->next
= h
->reloc_entries
;
3250 h
->reloc_entries
= rent
;
3255 else if (info
->shared
)
3257 /* If this is a shared library, and the section is to be
3258 loaded into memory, we need a RELATIVE reloc. */
3259 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
3260 if ((sec
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3261 == (SEC_READONLY
| SEC_ALLOC
))
3262 info
->flags
|= DF_TEXTREL
;
3270 /* Adjust a symbol defined by a dynamic object and referenced by a
3271 regular object. The current definition is in some section of the
3272 dynamic object, but we're not including those sections. We have to
3273 change the definition to something the rest of the link can
3277 elf64_alpha_adjust_dynamic_symbol (info
, h
)
3278 struct bfd_link_info
*info
;
3279 struct elf_link_hash_entry
*h
;
3283 struct alpha_elf_link_hash_entry
*ah
;
3285 dynobj
= elf_hash_table(info
)->dynobj
;
3286 ah
= (struct alpha_elf_link_hash_entry
*)h
;
3288 /* Now that we've seen all of the input symbols, finalize our decision
3289 about whether this symbol should get a .plt entry. */
3291 if (alpha_elf_dynamic_symbol_p (h
, info
)
3292 && ((h
->type
== STT_FUNC
3293 && !(ah
->flags
& ALPHA_ELF_LINK_HASH_LU_ADDR
))
3294 || (h
->type
== STT_NOTYPE
3295 && (ah
->flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
)
3296 && !(ah
->flags
& ~ALPHA_ELF_LINK_HASH_LU_FUNC
)))
3297 /* Don't prevent otherwise valid programs from linking by attempting
3298 to create a new .got entry somewhere. A Correct Solution would be
3299 to add a new .got section to a new object file and let it be merged
3300 somewhere later. But for now don't bother. */
3303 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3305 s
= bfd_get_section_by_name(dynobj
, ".plt");
3306 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
3309 /* The first bit of the .plt is reserved. */
3310 if (s
->_raw_size
== 0)
3311 s
->_raw_size
= PLT_HEADER_SIZE
;
3313 h
->plt
.offset
= s
->_raw_size
;
3314 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3316 /* If this symbol is not defined in a regular file, and we are not
3317 generating a shared library, then set the symbol to the location
3318 in the .plt. This is required to make function pointers compare
3319 equal between the normal executable and the shared library. */
3321 && h
->root
.type
!= bfd_link_hash_defweak
)
3323 h
->root
.u
.def
.section
= s
;
3324 h
->root
.u
.def
.value
= h
->plt
.offset
;
3327 /* We also need a JMP_SLOT entry in the .rela.plt section. */
3328 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3329 BFD_ASSERT (s
!= NULL
);
3330 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3335 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3337 /* If this is a weak symbol, and there is a real definition, the
3338 processor independent code will have arranged for us to see the
3339 real definition first, and we can just use the same value. */
3340 if (h
->weakdef
!= NULL
)
3342 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3343 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3344 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3345 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3349 /* This is a reference to a symbol defined by a dynamic object which
3350 is not a function. The Alpha, since it uses .got entries for all
3351 symbols even in regular objects, does not need the hackery of a
3352 .dynbss section and COPY dynamic relocations. */
3357 /* Symbol versioning can create new symbols, and make our old symbols
3358 indirect to the new ones. Consolidate the got and reloc information
3359 in these situations. */
3362 elf64_alpha_merge_ind_symbols (hi
, dummy
)
3363 struct alpha_elf_link_hash_entry
*hi
;
3364 PTR dummy ATTRIBUTE_UNUSED
;
3366 struct alpha_elf_link_hash_entry
*hs
;
3368 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
3372 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
3373 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
3375 /* Merge the flags. Whee. */
3377 hs
->flags
|= hi
->flags
;
3379 /* Merge the .got entries. Cannibalize the old symbol's list in
3380 doing so, since we don't need it anymore. */
3382 if (hs
->got_entries
== NULL
)
3383 hs
->got_entries
= hi
->got_entries
;
3386 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
3388 gsh
= hs
->got_entries
;
3389 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
3392 for (gs
= gsh
; gs
; gs
= gs
->next
)
3393 if (gi
->gotobj
== gs
->gotobj
3394 && gi
->reloc_type
== gs
->reloc_type
3395 && gi
->addend
== gs
->addend
)
3397 gi
->use_count
+= gs
->use_count
;
3400 gi
->next
= hs
->got_entries
;
3401 hs
->got_entries
= gi
;
3405 hi
->got_entries
= NULL
;
3407 /* And similar for the reloc entries. */
3409 if (hs
->reloc_entries
== NULL
)
3410 hs
->reloc_entries
= hi
->reloc_entries
;
3413 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
3415 rsh
= hs
->reloc_entries
;
3416 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
3419 for (rs
= rsh
; rs
; rs
= rs
->next
)
3420 if (ri
->rtype
== rs
->rtype
&& ri
->srel
== rs
->srel
)
3422 rs
->count
+= ri
->count
;
3425 ri
->next
= hs
->reloc_entries
;
3426 hs
->reloc_entries
= ri
;
3430 hi
->reloc_entries
= NULL
;
3435 /* Is it possible to merge two object file's .got tables? */
3438 elf64_alpha_can_merge_gots (a
, b
)
3441 int total
= alpha_elf_tdata (a
)->total_got_size
;
3444 /* Trivial quick fallout test. */
3445 if (total
+ alpha_elf_tdata (b
)->total_got_size
<= MAX_GOT_SIZE
)
3448 /* By their nature, local .got entries cannot be merged. */
3449 if ((total
+= alpha_elf_tdata (b
)->local_got_size
) > MAX_GOT_SIZE
)
3452 /* Failing the common trivial comparison, we must effectively
3453 perform the merge. Not actually performing the merge means that
3454 we don't have to store undo information in case we fail. */
3455 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
3457 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes (bsub
);
3458 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
3461 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
3462 for (i
= 0; i
< n
; ++i
)
3464 struct alpha_elf_got_entry
*ae
, *be
;
3465 struct alpha_elf_link_hash_entry
*h
;
3468 while (h
->root
.root
.type
== bfd_link_hash_indirect
3469 || h
->root
.root
.type
== bfd_link_hash_warning
)
3470 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3472 for (be
= h
->got_entries
; be
; be
= be
->next
)
3474 if (be
->use_count
== 0)
3476 if (be
->gotobj
!= b
)
3479 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
3481 && ae
->reloc_type
== be
->reloc_type
3482 && ae
->addend
== be
->addend
)
3485 total
+= alpha_got_entry_size (be
->reloc_type
);
3486 if (total
> MAX_GOT_SIZE
)
3496 /* Actually merge two .got tables. */
3499 elf64_alpha_merge_gots (a
, b
)
3502 int total
= alpha_elf_tdata (a
)->total_got_size
;
3505 /* Remember local expansion. */
3507 int e
= alpha_elf_tdata (b
)->local_got_size
;
3509 alpha_elf_tdata (a
)->local_got_size
+= e
;
3512 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
3514 struct alpha_elf_got_entry
**local_got_entries
;
3515 struct alpha_elf_link_hash_entry
**hashes
;
3516 Elf_Internal_Shdr
*symtab_hdr
;
3519 /* Let the local .got entries know they are part of a new subsegment. */
3520 local_got_entries
= alpha_elf_tdata (bsub
)->local_got_entries
;
3521 if (local_got_entries
)
3523 n
= elf_tdata (bsub
)->symtab_hdr
.sh_info
;
3524 for (i
= 0; i
< n
; ++i
)
3526 struct alpha_elf_got_entry
*ent
;
3527 for (ent
= local_got_entries
[i
]; ent
; ent
= ent
->next
)
3532 /* Merge the global .got entries. */
3533 hashes
= alpha_elf_sym_hashes (bsub
);
3534 symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
3536 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
3537 for (i
= 0; i
< n
; ++i
)
3539 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
3540 struct alpha_elf_link_hash_entry
*h
;
3543 while (h
->root
.root
.type
== bfd_link_hash_indirect
3544 || h
->root
.root
.type
== bfd_link_hash_warning
)
3545 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3547 start
= &h
->got_entries
;
3548 for (pbe
= start
, be
= *start
; be
; pbe
= &be
->next
, be
= be
->next
)
3550 if (be
->use_count
== 0)
3555 if (be
->gotobj
!= b
)
3558 for (ae
= *start
; ae
; ae
= ae
->next
)
3560 && ae
->reloc_type
== be
->reloc_type
3561 && ae
->addend
== be
->addend
)
3563 ae
->flags
|= be
->flags
;
3564 ae
->use_count
+= be
->use_count
;
3569 total
+= alpha_got_entry_size (be
->reloc_type
);
3575 alpha_elf_tdata (bsub
)->gotobj
= a
;
3577 alpha_elf_tdata (a
)->total_got_size
= total
;
3579 /* Merge the two in_got chains. */
3584 while ((next
= alpha_elf_tdata (bsub
)->in_got_link_next
) != NULL
)
3587 alpha_elf_tdata (bsub
)->in_got_link_next
= b
;
3591 /* Calculate the offsets for the got entries. */
3594 elf64_alpha_calc_got_offsets_for_symbol (h
, arg
)
3595 struct alpha_elf_link_hash_entry
*h
;
3596 PTR arg ATTRIBUTE_UNUSED
;
3598 struct alpha_elf_got_entry
*gotent
;
3600 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3601 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3603 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3604 if (gotent
->use_count
> 0)
3607 = &alpha_elf_tdata (gotent
->gotobj
)->got
->_raw_size
;
3609 gotent
->got_offset
= *plge
;
3610 *plge
+= alpha_got_entry_size (gotent
->reloc_type
);
3617 elf64_alpha_calc_got_offsets (info
)
3618 struct bfd_link_info
*info
;
3620 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
3622 /* First, zero out the .got sizes, as we may be recalculating the
3623 .got after optimizing it. */
3624 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3625 alpha_elf_tdata(i
)->got
->_raw_size
= 0;
3627 /* Next, fill in the offsets for all the global entries. */
3628 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3629 elf64_alpha_calc_got_offsets_for_symbol
,
3632 /* Finally, fill in the offsets for the local entries. */
3633 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3635 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->_raw_size
;
3638 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
3640 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
3643 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
3644 if (!local_got_entries
)
3647 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
3648 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
3649 if (gotent
->use_count
> 0)
3651 gotent
->got_offset
= got_offset
;
3652 got_offset
+= alpha_got_entry_size (gotent
->reloc_type
);
3656 alpha_elf_tdata(i
)->got
->_raw_size
= got_offset
;
3657 alpha_elf_tdata(i
)->got
->_cooked_size
= got_offset
;
3661 /* Constructs the gots. */
3664 elf64_alpha_size_got_sections (info
)
3665 struct bfd_link_info
*info
;
3667 bfd
*i
, *got_list
, *cur_got_obj
= NULL
;
3668 int something_changed
= 0;
3670 got_list
= alpha_elf_hash_table (info
)->got_list
;
3672 /* On the first time through, pretend we have an existing got list
3673 consisting of all of the input files. */
3674 if (got_list
== NULL
)
3676 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
3678 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
3679 if (this_got
== NULL
)
3682 /* We are assuming no merging has yet ocurred. */
3683 BFD_ASSERT (this_got
== i
);
3685 if (alpha_elf_tdata (this_got
)->total_got_size
> MAX_GOT_SIZE
)
3687 /* Yikes! A single object file has too many entries. */
3688 (*_bfd_error_handler
)
3689 (_("%s: .got subsegment exceeds 64K (size %d)"),
3690 bfd_archive_filename (i
),
3691 alpha_elf_tdata (this_got
)->total_got_size
);
3695 if (got_list
== NULL
)
3696 got_list
= this_got
;
3698 alpha_elf_tdata(cur_got_obj
)->got_link_next
= this_got
;
3699 cur_got_obj
= this_got
;
3702 /* Strange degenerate case of no got references. */
3703 if (got_list
== NULL
)
3706 alpha_elf_hash_table (info
)->got_list
= got_list
;
3708 /* Force got offsets to be recalculated. */
3709 something_changed
= 1;
3712 cur_got_obj
= got_list
;
3713 i
= alpha_elf_tdata(cur_got_obj
)->got_link_next
;
3716 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
3718 elf64_alpha_merge_gots (cur_got_obj
, i
);
3719 i
= alpha_elf_tdata(i
)->got_link_next
;
3720 alpha_elf_tdata(cur_got_obj
)->got_link_next
= i
;
3721 something_changed
= 1;
3726 i
= alpha_elf_tdata(i
)->got_link_next
;
3730 /* Once the gots have been merged, fill in the got offsets for
3731 everything therein. */
3732 if (1 || something_changed
)
3733 elf64_alpha_calc_got_offsets (info
);
3738 /* Called from relax_section to rebuild the PLT in light of
3739 potential changes in the function's status. */
3742 elf64_alpha_size_plt_section (info
)
3743 struct bfd_link_info
*info
;
3745 asection
*splt
, *spltrel
;
3746 unsigned long entries
;
3749 dynobj
= elf_hash_table(info
)->dynobj
;
3750 splt
= bfd_get_section_by_name(dynobj
, ".plt");
3754 splt
->_raw_size
= 0;
3756 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3757 elf64_alpha_size_plt_section_1
, splt
);
3759 splt
->_cooked_size
= splt
->_raw_size
;
3761 /* Every plt entry requires a JMP_SLOT relocation. */
3762 spltrel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3763 if (splt
->_raw_size
)
3764 entries
= (splt
->_raw_size
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3767 spltrel
->_raw_size
= entries
* sizeof (Elf64_External_Rela
);
3768 spltrel
->_cooked_size
= spltrel
->_raw_size
;
3774 elf64_alpha_size_plt_section_1 (h
, data
)
3775 struct alpha_elf_link_hash_entry
*h
;
3778 asection
*splt
= (asection
*) data
;
3779 struct alpha_elf_got_entry
*gotent
;
3781 /* If we didn't need an entry before, we still don't. */
3782 if (!(h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
))
3785 /* There must still be a LITERAL got entry for the function. */
3786 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3787 if (gotent
->reloc_type
== R_ALPHA_LITERAL
3788 && gotent
->use_count
> 0)
3791 /* If there is, reset the PLT offset. If not, there's no longer
3792 a need for the PLT entry. */
3795 if (splt
->_raw_size
== 0)
3796 splt
->_raw_size
= PLT_HEADER_SIZE
;
3797 h
->root
.plt
.offset
= splt
->_raw_size
;
3798 splt
->_raw_size
+= PLT_ENTRY_SIZE
;
3802 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3803 h
->root
.plt
.offset
= -1;
3810 elf64_alpha_always_size_sections (output_bfd
, info
)
3811 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3812 struct bfd_link_info
*info
;
3816 if (info
->relocateable
)
3819 /* First, take care of the indirect symbols created by versioning. */
3820 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3821 elf64_alpha_merge_ind_symbols
,
3824 if (!elf64_alpha_size_got_sections (info
))
3827 /* Allocate space for all of the .got subsections. */
3828 i
= alpha_elf_hash_table (info
)->got_list
;
3829 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3831 asection
*s
= alpha_elf_tdata(i
)->got
;
3832 if (s
->_raw_size
> 0)
3834 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->_raw_size
);
3835 if (s
->contents
== NULL
)
3843 /* The number of dynamic relocations required by a static relocation. */
3846 alpha_dynamic_entries_for_reloc (r_type
, dynamic
, shared
)
3847 int r_type
, dynamic
, shared
;
3851 /* May appear in GOT entries. */
3853 return (dynamic
? 2 : shared
? 1 : 0);
3854 case R_ALPHA_TLSLDM
:
3856 case R_ALPHA_LITERAL
:
3857 case R_ALPHA_GOTTPREL
:
3858 return dynamic
|| shared
;
3859 case R_ALPHA_GOTDTPREL
:
3862 /* May appear in data sections. */
3863 case R_ALPHA_REFLONG
:
3864 case R_ALPHA_REFQUAD
:
3865 case R_ALPHA_TPREL64
:
3866 return dynamic
|| shared
;
3868 /* Everything else is illegal. We'll issue an error during
3869 relocate_section. */
3875 /* Work out the sizes of the dynamic relocation entries. */
3878 elf64_alpha_calc_dynrel_sizes (h
, info
)
3879 struct alpha_elf_link_hash_entry
*h
;
3880 struct bfd_link_info
*info
;
3882 bfd_boolean dynamic
;
3883 struct alpha_elf_reloc_entry
*relent
;
3884 unsigned long entries
;
3886 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3887 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3889 /* If the symbol was defined as a common symbol in a regular object
3890 file, and there was no definition in any dynamic object, then the
3891 linker will have allocated space for the symbol in a common
3892 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3893 set. This is done for dynamic symbols in
3894 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3895 symbols, somehow. */
3896 if (((h
->root
.elf_link_hash_flags
3897 & (ELF_LINK_HASH_DEF_REGULAR
3898 | ELF_LINK_HASH_REF_REGULAR
3899 | ELF_LINK_HASH_DEF_DYNAMIC
))
3900 == ELF_LINK_HASH_REF_REGULAR
)
3901 && (h
->root
.root
.type
== bfd_link_hash_defined
3902 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3903 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
3904 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3906 /* If the symbol is dynamic, we'll need all the relocations in their
3907 natural form. If this is a shared object, and it has been forced
3908 local, we'll need the same number of RELATIVE relocations. */
3910 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
3912 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
3914 entries
= alpha_dynamic_entries_for_reloc (relent
->rtype
, dynamic
,
3918 relent
->srel
->_raw_size
+=
3919 entries
* sizeof (Elf64_External_Rela
) * relent
->count
;
3920 if (relent
->reltext
)
3921 info
->flags
|= DT_TEXTREL
;
3928 /* Set the sizes of the dynamic relocation sections. */
3931 elf64_alpha_size_rela_got_section (info
)
3932 struct bfd_link_info
*info
;
3934 unsigned long entries
;
3938 /* Shared libraries often require RELATIVE relocs, and some relocs
3939 require attention for the main application as well. */
3942 for (i
= alpha_elf_hash_table(info
)->got_list
;
3943 i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3947 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
3949 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
3952 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
3953 if (!local_got_entries
)
3956 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
3957 for (gotent
= local_got_entries
[k
];
3958 gotent
; gotent
= gotent
->next
)
3959 if (gotent
->use_count
> 0)
3960 entries
+= (alpha_dynamic_entries_for_reloc
3961 (gotent
->reloc_type
, 0, info
->shared
));
3965 dynobj
= elf_hash_table(info
)->dynobj
;
3966 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3969 BFD_ASSERT (entries
== 0);
3972 srel
->_raw_size
= sizeof (Elf64_External_Rela
) * entries
;
3974 /* Now do the non-local symbols. */
3975 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3976 elf64_alpha_size_rela_got_1
, info
);
3978 srel
->_cooked_size
= srel
->_raw_size
;
3983 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
3987 elf64_alpha_size_rela_got_1 (h
, info
)
3988 struct alpha_elf_link_hash_entry
*h
;
3989 struct bfd_link_info
*info
;
3991 bfd_boolean dynamic
;
3992 struct alpha_elf_got_entry
*gotent
;
3993 unsigned long entries
;
3995 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3996 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3998 /* If the symbol is dynamic, we'll need all the relocations in their
3999 natural form. If this is a shared object, and it has been forced
4000 local, we'll need the same number of RELATIVE relocations. */
4002 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4005 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
4006 if (gotent
->use_count
> 0)
4007 entries
+= alpha_dynamic_entries_for_reloc (gotent
->reloc_type
,
4008 dynamic
, info
->shared
);
4010 /* If we are using a .plt entry, subtract one, as the first
4011 reference uses a .rela.plt entry instead. */
4012 if (h
->root
.plt
.offset
!= MINUS_ONE
)
4017 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4018 asection
*srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4019 BFD_ASSERT (srel
!= NULL
);
4020 srel
->_raw_size
+= sizeof (Elf64_External_Rela
) * entries
;
4026 /* Set the sizes of the dynamic sections. */
4029 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
4030 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4031 struct bfd_link_info
*info
;
4037 dynobj
= elf_hash_table(info
)->dynobj
;
4038 BFD_ASSERT(dynobj
!= NULL
);
4040 if (elf_hash_table (info
)->dynamic_sections_created
)
4042 /* Set the contents of the .interp section to the interpreter. */
4045 s
= bfd_get_section_by_name (dynobj
, ".interp");
4046 BFD_ASSERT (s
!= NULL
);
4047 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4048 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4051 /* Now that we've seen all of the input files, we can decide which
4052 symbols need dynamic relocation entries and which don't. We've
4053 collected information in check_relocs that we can now apply to
4054 size the dynamic relocation sections. */
4055 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
4056 elf64_alpha_calc_dynrel_sizes
, info
);
4058 elf64_alpha_size_rela_got_section (info
);
4060 /* else we're not dynamic and by definition we don't need such things. */
4062 /* The check_relocs and adjust_dynamic_symbol entry points have
4063 determined the sizes of the various dynamic sections. Allocate
4066 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4071 if (!(s
->flags
& SEC_LINKER_CREATED
))
4074 /* It's OK to base decisions on the section name, because none
4075 of the dynobj section names depend upon the input files. */
4076 name
= bfd_get_section_name (dynobj
, s
);
4078 /* If we don't need this section, strip it from the output file.
4079 This is to handle .rela.bss and .rela.plt. We must create it
4080 in create_dynamic_sections, because it must be created before
4081 the linker maps input sections to output sections. The
4082 linker does that before adjust_dynamic_symbol is called, and
4083 it is that function which decides whether anything needs to
4084 go into these sections. */
4088 if (strncmp (name
, ".rela", 5) == 0)
4090 strip
= (s
->_raw_size
== 0);
4094 if (strcmp(name
, ".rela.plt") == 0)
4097 /* We use the reloc_count field as a counter if we need
4098 to copy relocs into the output file. */
4102 else if (strcmp (name
, ".plt") != 0)
4104 /* It's not one of our dynamic sections, so don't allocate space. */
4109 _bfd_strip_section_from_output (info
, s
);
4112 /* Allocate memory for the section contents. */
4113 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4114 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4119 if (elf_hash_table (info
)->dynamic_sections_created
)
4121 /* Add some entries to the .dynamic section. We fill in the
4122 values later, in elf64_alpha_finish_dynamic_sections, but we
4123 must add the entries now so that we get the correct size for
4124 the .dynamic section. The DT_DEBUG entry is filled in by the
4125 dynamic linker and used by the debugger. */
4126 #define add_dynamic_entry(TAG, VAL) \
4127 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4131 if (!add_dynamic_entry (DT_DEBUG
, 0))
4137 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4138 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4139 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4140 || !add_dynamic_entry (DT_JMPREL
, 0))
4144 if (!add_dynamic_entry (DT_RELA
, 0)
4145 || !add_dynamic_entry (DT_RELASZ
, 0)
4146 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4149 if (info
->flags
& DF_TEXTREL
)
4151 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4155 #undef add_dynamic_entry
4160 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
4161 into the next available slot in SREL. */
4164 elf64_alpha_emit_dynrel (abfd
, info
, sec
, srel
, offset
, dynindx
, rtype
, addend
)
4166 struct bfd_link_info
*info
;
4167 asection
*sec
, *srel
;
4168 bfd_vma offset
, addend
;
4169 long dynindx
, rtype
;
4171 Elf_Internal_Rela outrel
;
4174 BFD_ASSERT (srel
!= NULL
);
4176 outrel
.r_info
= ELF64_R_INFO (dynindx
, rtype
);
4177 outrel
.r_addend
= addend
;
4179 offset
= _bfd_elf_section_offset (abfd
, info
, sec
, offset
);
4180 if ((offset
| 1) != (bfd_vma
) -1)
4181 outrel
.r_offset
= sec
->output_section
->vma
+ sec
->output_offset
+ offset
;
4183 memset (&outrel
, 0, sizeof (outrel
));
4185 loc
= srel
->contents
;
4186 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4187 bfd_elf64_swap_reloca_out (abfd
, &outrel
, loc
);
4188 BFD_ASSERT (sizeof (Elf64_External_Rela
) * srel
->reloc_count
4189 <= srel
->_cooked_size
);
4192 /* Relocate an Alpha ELF section for a relocatable link.
4194 We don't have to change anything unless the reloc is against a section
4195 symbol, in which case we have to adjust according to where the section
4196 symbol winds up in the output section. */
4199 elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
, input_section
,
4200 contents
, relocs
, local_syms
, local_sections
)
4201 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4202 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4204 asection
*input_section
;
4205 bfd_byte
*contents ATTRIBUTE_UNUSED
;
4206 Elf_Internal_Rela
*relocs
;
4207 Elf_Internal_Sym
*local_syms
;
4208 asection
**local_sections
;
4210 unsigned long symtab_hdr_sh_info
;
4211 Elf_Internal_Rela
*rel
;
4212 Elf_Internal_Rela
*relend
;
4213 bfd_boolean ret_val
= TRUE
;
4215 symtab_hdr_sh_info
= elf_tdata (input_bfd
)->symtab_hdr
.sh_info
;
4217 relend
= relocs
+ input_section
->reloc_count
;
4218 for (rel
= relocs
; rel
< relend
; rel
++)
4220 unsigned long r_symndx
;
4221 Elf_Internal_Sym
*sym
;
4223 unsigned long r_type
;
4225 r_type
= ELF64_R_TYPE(rel
->r_info
);
4226 if (r_type
>= R_ALPHA_max
)
4228 (*_bfd_error_handler
)
4229 (_("%s: unknown relocation type %d"),
4230 bfd_archive_filename (input_bfd
), (int)r_type
);
4231 bfd_set_error (bfd_error_bad_value
);
4236 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4238 /* The symbol associated with GPDISP and LITUSE is
4239 immaterial. Only the addend is significant. */
4240 if (r_type
== R_ALPHA_GPDISP
|| r_type
== R_ALPHA_LITUSE
)
4243 if (r_symndx
< symtab_hdr_sh_info
)
4245 sym
= local_syms
+ r_symndx
;
4246 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
4248 sec
= local_sections
[r_symndx
];
4249 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4257 /* Relocate an Alpha ELF section. */
4260 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4261 contents
, relocs
, local_syms
, local_sections
)
4263 struct bfd_link_info
*info
;
4265 asection
*input_section
;
4267 Elf_Internal_Rela
*relocs
;
4268 Elf_Internal_Sym
*local_syms
;
4269 asection
**local_sections
;
4271 Elf_Internal_Shdr
*symtab_hdr
;
4272 Elf_Internal_Rela
*rel
;
4273 Elf_Internal_Rela
*relend
;
4274 struct elf_link_tls_segment
*tls_segment
;
4275 asection
*sgot
, *srel
, *srelgot
;
4276 bfd
*dynobj
, *gotobj
;
4277 bfd_vma gp
, tp_base
, dtp_base
;
4278 struct alpha_elf_got_entry
**local_got_entries
;
4279 bfd_boolean ret_val
;
4280 const char *section_name
;
4282 /* Handle relocatable links with a smaller loop. */
4283 if (info
->relocateable
)
4284 return elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
,
4285 input_section
, contents
, relocs
,
4286 local_syms
, local_sections
);
4288 /* This is a final link. */
4292 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4294 dynobj
= elf_hash_table (info
)->dynobj
;
4296 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
4300 section_name
= (bfd_elf_string_from_elf_section
4301 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
4302 elf_section_data(input_section
)->rel_hdr
.sh_name
));
4303 BFD_ASSERT(section_name
!= NULL
);
4304 srel
= bfd_get_section_by_name (dynobj
, section_name
);
4306 /* Find the gp value for this input bfd. */
4307 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
4310 sgot
= alpha_elf_tdata (gotobj
)->got
;
4311 gp
= _bfd_get_gp_value (gotobj
);
4314 gp
= (sgot
->output_section
->vma
4315 + sgot
->output_offset
4317 _bfd_set_gp_value (gotobj
, gp
);
4326 local_got_entries
= alpha_elf_tdata(input_bfd
)->local_got_entries
;
4328 tls_segment
= elf_hash_table (info
)->tls_segment
;
4331 dtp_base
= alpha_get_dtprel_base (tls_segment
);
4332 tp_base
= alpha_get_tprel_base (tls_segment
);
4335 dtp_base
= tp_base
= 0;
4337 relend
= relocs
+ input_section
->reloc_count
;
4338 for (rel
= relocs
; rel
< relend
; rel
++)
4340 struct alpha_elf_link_hash_entry
*h
= NULL
;
4341 struct alpha_elf_got_entry
*gotent
;
4342 bfd_reloc_status_type r
;
4343 reloc_howto_type
*howto
;
4344 unsigned long r_symndx
;
4345 Elf_Internal_Sym
*sym
= NULL
;
4346 asection
*sec
= NULL
;
4349 bfd_boolean dynamic_symbol_p
;
4350 bfd_boolean undef_weak_ref
= FALSE
;
4351 unsigned long r_type
;
4353 r_type
= ELF64_R_TYPE(rel
->r_info
);
4354 if (r_type
>= R_ALPHA_max
)
4356 (*_bfd_error_handler
)
4357 (_("%s: unknown relocation type %d"),
4358 bfd_archive_filename (input_bfd
), (int)r_type
);
4359 bfd_set_error (bfd_error_bad_value
);
4364 howto
= elf64_alpha_howto_table
+ r_type
;
4365 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4367 if (r_symndx
< symtab_hdr
->sh_info
)
4369 sym
= local_syms
+ r_symndx
;
4370 sec
= local_sections
[r_symndx
];
4371 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4373 if (local_got_entries
)
4374 gotent
= local_got_entries
[r_symndx
];
4378 /* Need to adjust local GOT entries' addends for SEC_MERGE
4379 unless it has been done already. */
4380 if ((sec
->flags
& SEC_MERGE
)
4381 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
4382 && (elf_section_data (sec
)->sec_info_type
4383 == ELF_INFO_TYPE_MERGE
)
4385 && !gotent
->reloc_xlated
)
4387 struct alpha_elf_got_entry
*ent
;
4390 for (ent
= gotent
; ent
; ent
= ent
->next
)
4392 ent
->reloc_xlated
= 1;
4393 if (ent
->use_count
== 0)
4397 _bfd_merged_section_offset (output_bfd
, &msec
,
4398 elf_section_data (sec
)->
4400 sym
->st_value
+ ent
->addend
,
4402 ent
->addend
-= sym
->st_value
;
4403 ent
->addend
+= msec
->output_section
->vma
4404 + msec
->output_offset
4405 - sec
->output_section
->vma
4406 - sec
->output_offset
;
4410 dynamic_symbol_p
= FALSE
;
4414 h
= alpha_elf_sym_hashes (input_bfd
)[r_symndx
- symtab_hdr
->sh_info
];
4416 while (h
->root
.root
.type
== bfd_link_hash_indirect
4417 || h
->root
.root
.type
== bfd_link_hash_warning
)
4418 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
4421 if (h
->root
.root
.type
== bfd_link_hash_defined
4422 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4424 sec
= h
->root
.root
.u
.def
.section
;
4426 /* Detect the cases that sym_sec->output_section is
4427 expected to be NULL -- all cases in which the symbol
4428 is defined in another shared module. This includes
4429 PLT relocs for which we've created a PLT entry and
4430 other relocs for which we're prepared to create
4431 dynamic relocations. */
4432 /* ??? Just accept it NULL and continue. */
4434 if (sec
->output_section
!= NULL
)
4435 value
= (h
->root
.root
.u
.def
.value
4436 + sec
->output_section
->vma
4437 + sec
->output_offset
);
4439 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4440 undef_weak_ref
= TRUE
;
4441 else if (info
->shared
4442 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
4443 && !info
->no_undefined
4444 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4448 if (!((*info
->callbacks
->undefined_symbol
)
4449 (info
, h
->root
.root
.root
.string
, input_bfd
,
4450 input_section
, rel
->r_offset
,
4451 (!info
->shared
|| info
->no_undefined
4452 || ELF_ST_VISIBILITY (h
->root
.other
)))))
4458 dynamic_symbol_p
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4459 gotent
= h
->got_entries
;
4462 addend
= rel
->r_addend
;
4465 /* Search for the proper got entry. */
4466 for (; gotent
; gotent
= gotent
->next
)
4467 if (gotent
->gotobj
== gotobj
4468 && gotent
->reloc_type
== r_type
4469 && gotent
->addend
== addend
)
4474 case R_ALPHA_GPDISP
:
4476 bfd_byte
*p_ldah
, *p_lda
;
4478 BFD_ASSERT(gp
!= 0);
4480 value
= (input_section
->output_section
->vma
4481 + input_section
->output_offset
4484 p_ldah
= contents
+ rel
->r_offset
;
4485 p_lda
= p_ldah
+ rel
->r_addend
;
4487 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- value
,
4492 case R_ALPHA_LITERAL
:
4493 BFD_ASSERT(sgot
!= NULL
);
4494 BFD_ASSERT(gp
!= 0);
4495 BFD_ASSERT(gotent
!= NULL
);
4496 BFD_ASSERT(gotent
->use_count
>= 1);
4498 if (!gotent
->reloc_done
)
4500 gotent
->reloc_done
= 1;
4502 bfd_put_64 (output_bfd
, value
,
4503 sgot
->contents
+ gotent
->got_offset
);
4505 /* If the symbol has been forced local, output a
4506 RELATIVE reloc, otherwise it will be handled in
4507 finish_dynamic_symbol. */
4508 if (info
->shared
&& !dynamic_symbol_p
)
4509 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4510 gotent
->got_offset
, 0,
4511 R_ALPHA_RELATIVE
, value
);
4514 value
= (sgot
->output_section
->vma
4515 + sgot
->output_offset
4516 + gotent
->got_offset
);
4520 case R_ALPHA_GPREL16
:
4521 case R_ALPHA_GPREL32
:
4522 case R_ALPHA_GPRELLOW
:
4523 if (dynamic_symbol_p
)
4525 (*_bfd_error_handler
)
4526 (_("%s: gp-relative relocation against dynamic symbol %s"),
4527 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4530 BFD_ASSERT(gp
!= 0);
4534 case R_ALPHA_GPRELHIGH
:
4535 if (dynamic_symbol_p
)
4537 (*_bfd_error_handler
)
4538 (_("%s: gp-relative relocation against dynamic symbol %s"),
4539 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4542 BFD_ASSERT(gp
!= 0);
4544 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4548 /* A call to a dynamic symbol is definitely out of range of
4549 the 16-bit displacement. Don't bother writing anything. */
4550 if (dynamic_symbol_p
)
4555 /* The regular PC-relative stuff measures from the start of
4556 the instruction rather than the end. */
4560 case R_ALPHA_BRADDR
:
4561 if (dynamic_symbol_p
)
4563 (*_bfd_error_handler
)
4564 (_("%s: pc-relative relocation against dynamic symbol %s"),
4565 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4568 /* The regular PC-relative stuff measures from the start of
4569 the instruction rather than the end. */
4578 /* The regular PC-relative stuff measures from the start of
4579 the instruction rather than the end. */
4582 /* The source and destination gp must be the same. Note that
4583 the source will always have an assigned gp, since we forced
4584 one in check_relocs, but that the destination may not, as
4585 it might not have had any relocations at all. Also take
4586 care not to crash if H is an undefined symbol. */
4587 if (h
!= NULL
&& sec
!= NULL
4588 && alpha_elf_tdata (sec
->owner
)->gotobj
4589 && gotobj
!= alpha_elf_tdata (sec
->owner
)->gotobj
)
4591 (*_bfd_error_handler
)
4592 (_("%s: change in gp: BRSGP %s"),
4593 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4597 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4599 other
= h
->root
.other
;
4601 other
= sym
->st_other
;
4602 switch (other
& STO_ALPHA_STD_GPLOAD
)
4604 case STO_ALPHA_NOPV
:
4606 case STO_ALPHA_STD_GPLOAD
:
4611 name
= h
->root
.root
.root
.string
;
4614 name
= (bfd_elf_string_from_elf_section
4615 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4617 name
= _("<unknown>");
4618 else if (name
[0] == 0)
4619 name
= bfd_section_name (input_bfd
, sec
);
4621 (*_bfd_error_handler
)
4622 (_("%s: !samegp reloc against symbol without .prologue: %s"),
4623 bfd_archive_filename (input_bfd
), name
);
4631 case R_ALPHA_REFLONG
:
4632 case R_ALPHA_REFQUAD
:
4633 case R_ALPHA_DTPREL64
:
4634 case R_ALPHA_TPREL64
:
4636 long dynindx
, dyntype
= r_type
;
4639 /* Careful here to remember RELATIVE relocations for global
4640 variables for symbolic shared objects. */
4642 if (dynamic_symbol_p
)
4644 BFD_ASSERT(h
->root
.dynindx
!= -1);
4645 dynindx
= h
->root
.dynindx
;
4647 addend
= 0, value
= 0;
4649 else if (r_type
== R_ALPHA_DTPREL64
)
4651 BFD_ASSERT(tls_segment
!= NULL
);
4655 else if (r_type
== R_ALPHA_TPREL64
)
4657 BFD_ASSERT(tls_segment
!= NULL
);
4664 dynaddend
= value
- dtp_base
;
4666 else if (info
->shared
4668 && (input_section
->flags
& SEC_ALLOC
))
4670 if (r_type
== R_ALPHA_REFLONG
)
4672 (*_bfd_error_handler
)
4673 (_("%s: unhandled dynamic relocation against %s"),
4674 bfd_archive_filename (input_bfd
),
4675 h
->root
.root
.root
.string
);
4679 dyntype
= R_ALPHA_RELATIVE
;
4685 elf64_alpha_emit_dynrel (output_bfd
, info
, input_section
,
4686 srel
, rel
->r_offset
, dynindx
,
4687 dyntype
, dynaddend
);
4691 case R_ALPHA_SREL16
:
4692 case R_ALPHA_SREL32
:
4693 case R_ALPHA_SREL64
:
4694 if (dynamic_symbol_p
)
4696 (*_bfd_error_handler
)
4697 (_("%s: pc-relative relocation against dynamic symbol %s"),
4698 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4702 /* ??? .eh_frame references to discarded sections will be smashed
4703 to relocations against SHN_UNDEF. The .eh_frame format allows
4704 NULL to be encoded as 0 in any format, so this works here. */
4706 howto
= (elf64_alpha_howto_table
4707 + (r_type
- R_ALPHA_SREL32
+ R_ALPHA_REFLONG
));
4710 case R_ALPHA_TLSLDM
:
4711 /* Ignore the symbol for the relocation. The result is always
4712 the current module. */
4713 dynamic_symbol_p
= 0;
4717 if (!gotent
->reloc_done
)
4719 gotent
->reloc_done
= 1;
4721 /* Note that the module index for the main program is 1. */
4722 bfd_put_64 (output_bfd
, !info
->shared
&& !dynamic_symbol_p
,
4723 sgot
->contents
+ gotent
->got_offset
);
4725 /* If the symbol has been forced local, output a
4726 DTPMOD64 reloc, otherwise it will be handled in
4727 finish_dynamic_symbol. */
4728 if (info
->shared
&& !dynamic_symbol_p
)
4729 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4730 gotent
->got_offset
, 0,
4731 R_ALPHA_DTPMOD64
, 0);
4733 if (dynamic_symbol_p
|| r_type
== R_ALPHA_TLSLDM
)
4737 BFD_ASSERT(tls_segment
!= NULL
);
4740 bfd_put_64 (output_bfd
, value
,
4741 sgot
->contents
+ gotent
->got_offset
+ 8);
4744 value
= (sgot
->output_section
->vma
4745 + sgot
->output_offset
4746 + gotent
->got_offset
);
4750 case R_ALPHA_DTPRELHI
:
4751 case R_ALPHA_DTPRELLO
:
4752 case R_ALPHA_DTPREL16
:
4753 if (dynamic_symbol_p
)
4755 (*_bfd_error_handler
)
4756 (_("%s: dtp-relative relocation against dynamic symbol %s"),
4757 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4760 BFD_ASSERT(tls_segment
!= NULL
);
4762 if (r_type
== R_ALPHA_DTPRELHI
)
4763 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4766 case R_ALPHA_TPRELHI
:
4767 case R_ALPHA_TPRELLO
:
4768 case R_ALPHA_TPREL16
:
4771 (*_bfd_error_handler
)
4772 (_("%s: TLS local exec code cannot be linked into shared objects"),
4773 bfd_archive_filename (input_bfd
));
4776 else if (dynamic_symbol_p
)
4778 (*_bfd_error_handler
)
4779 (_("%s: tp-relative relocation against dynamic symbol %s"),
4780 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4783 BFD_ASSERT(tls_segment
!= NULL
);
4785 if (r_type
== R_ALPHA_TPRELHI
)
4786 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4789 case R_ALPHA_GOTDTPREL
:
4790 case R_ALPHA_GOTTPREL
:
4791 BFD_ASSERT(sgot
!= NULL
);
4792 BFD_ASSERT(gp
!= 0);
4793 BFD_ASSERT(gotent
!= NULL
);
4794 BFD_ASSERT(gotent
->use_count
>= 1);
4796 if (!gotent
->reloc_done
)
4798 gotent
->reloc_done
= 1;
4800 if (dynamic_symbol_p
)
4804 BFD_ASSERT(tls_segment
!= NULL
);
4805 if (r_type
== R_ALPHA_GOTDTPREL
)
4807 else if (!info
->shared
)
4811 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4812 gotent
->got_offset
, 0,
4818 bfd_put_64 (output_bfd
, value
,
4819 sgot
->contents
+ gotent
->got_offset
);
4822 value
= (sgot
->output_section
->vma
4823 + sgot
->output_offset
4824 + gotent
->got_offset
);
4830 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4831 contents
, rel
->r_offset
, value
, 0);
4840 case bfd_reloc_overflow
:
4844 /* Don't warn if the overflow is due to pc relative reloc
4845 against discarded section. Section optimization code should
4848 if (r_symndx
< symtab_hdr
->sh_info
4849 && sec
!= NULL
&& howto
->pc_relative
4850 && elf_discarded_section (sec
))
4854 name
= h
->root
.root
.root
.string
;
4857 name
= (bfd_elf_string_from_elf_section
4858 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4862 name
= bfd_section_name (input_bfd
, sec
);
4864 if (! ((*info
->callbacks
->reloc_overflow
)
4865 (info
, name
, howto
->name
, (bfd_vma
) 0,
4866 input_bfd
, input_section
, rel
->r_offset
)))
4872 case bfd_reloc_outofrange
:
4880 /* Finish up dynamic symbol handling. We set the contents of various
4881 dynamic sections here. */
4884 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4886 struct bfd_link_info
*info
;
4887 struct elf_link_hash_entry
*h
;
4888 Elf_Internal_Sym
*sym
;
4890 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4892 if (h
->plt
.offset
!= MINUS_ONE
)
4894 /* Fill in the .plt entry for this symbol. */
4895 asection
*splt
, *sgot
, *srel
;
4896 Elf_Internal_Rela outrel
;
4898 bfd_vma got_addr
, plt_addr
;
4900 struct alpha_elf_got_entry
*gotent
;
4902 BFD_ASSERT (h
->dynindx
!= -1);
4904 /* The first .got entry will be updated by the .plt with the
4905 address of the target function. */
4906 gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4907 BFD_ASSERT (gotent
&& gotent
->addend
== 0);
4909 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4910 BFD_ASSERT (splt
!= NULL
);
4911 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4912 BFD_ASSERT (srel
!= NULL
);
4913 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4914 BFD_ASSERT (sgot
!= NULL
);
4916 got_addr
= (sgot
->output_section
->vma
4917 + sgot
->output_offset
4918 + gotent
->got_offset
);
4919 plt_addr
= (splt
->output_section
->vma
4920 + splt
->output_offset
4923 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
4925 /* Fill in the entry in the procedure linkage table. */
4927 bfd_vma insn1
, insn2
, insn3
;
4929 insn1
= PLT_ENTRY_WORD1
| ((-(h
->plt
.offset
+ 4) >> 2) & 0x1fffff);
4930 insn2
= PLT_ENTRY_WORD2
;
4931 insn3
= PLT_ENTRY_WORD3
;
4933 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt
.offset
);
4934 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt
.offset
+ 4);
4935 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt
.offset
+ 8);
4938 /* Fill in the entry in the .rela.plt section. */
4939 outrel
.r_offset
= got_addr
;
4940 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
4941 outrel
.r_addend
= 0;
4943 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
4944 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
4946 if (!(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
4948 /* Mark the symbol as undefined, rather than as defined in the
4949 .plt section. Leave the value alone. */
4950 sym
->st_shndx
= SHN_UNDEF
;
4953 /* Fill in the entries in the .got. */
4954 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ gotent
->got_offset
);
4956 /* Subsequent .got entries will continue to bounce through the .plt. */
4959 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4960 BFD_ASSERT (! info
->shared
|| srel
!= NULL
);
4962 gotent
= gotent
->next
;
4965 sgot
= alpha_elf_tdata(gotent
->gotobj
)->got
;
4966 BFD_ASSERT(sgot
!= NULL
);
4967 BFD_ASSERT(gotent
->addend
== 0);
4969 bfd_put_64 (output_bfd
, plt_addr
,
4970 sgot
->contents
+ gotent
->got_offset
);
4973 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4974 gotent
->got_offset
, 0,
4975 R_ALPHA_RELATIVE
, plt_addr
);
4977 gotent
= gotent
->next
;
4979 while (gotent
!= NULL
);
4982 else if (alpha_elf_dynamic_symbol_p (h
, info
))
4984 /* Fill in the dynamic relocations for this symbol's .got entries. */
4986 struct alpha_elf_got_entry
*gotent
;
4988 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4989 BFD_ASSERT (srel
!= NULL
);
4991 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4993 gotent
= gotent
->next
)
4998 if (gotent
->use_count
== 0)
5001 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
5003 r_type
= gotent
->reloc_type
;
5006 case R_ALPHA_LITERAL
:
5007 r_type
= R_ALPHA_GLOB_DAT
;
5010 r_type
= R_ALPHA_DTPMOD64
;
5012 case R_ALPHA_GOTDTPREL
:
5013 r_type
= R_ALPHA_DTPREL64
;
5015 case R_ALPHA_GOTTPREL
:
5016 r_type
= R_ALPHA_TPREL64
;
5018 case R_ALPHA_TLSLDM
:
5023 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
5024 gotent
->got_offset
, h
->dynindx
,
5025 r_type
, gotent
->addend
);
5027 if (gotent
->reloc_type
== R_ALPHA_TLSGD
)
5028 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
5029 gotent
->got_offset
+ 8, h
->dynindx
,
5030 R_ALPHA_DTPREL64
, gotent
->addend
);
5034 /* Mark some specially defined symbols as absolute. */
5035 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
5036 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
5037 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
5038 sym
->st_shndx
= SHN_ABS
;
5043 /* Finish up the dynamic sections. */
5046 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
5048 struct bfd_link_info
*info
;
5053 dynobj
= elf_hash_table (info
)->dynobj
;
5054 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5056 if (elf_hash_table (info
)->dynamic_sections_created
)
5059 Elf64_External_Dyn
*dyncon
, *dynconend
;
5061 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5062 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
5064 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
5065 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5066 for (; dyncon
< dynconend
; dyncon
++)
5068 Elf_Internal_Dyn dyn
;
5072 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5087 /* My interpretation of the TIS v1.1 ELF document indicates
5088 that RELASZ should not include JMPREL. This is not what
5089 the rest of the BFD does. It is, however, what the
5090 glibc ld.so wants. Do this fixup here until we found
5091 out who is right. */
5092 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
5096 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
5101 s
= bfd_get_section_by_name (output_bfd
, name
);
5102 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
5106 s
= bfd_get_section_by_name (output_bfd
, name
);
5108 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
5112 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5115 /* Initialize the PLT0 entry */
5116 if (splt
->_raw_size
> 0)
5118 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
5119 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
5120 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
5121 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
5123 /* The next two words will be filled in by ld.so */
5124 bfd_put_64 (output_bfd
, (bfd_vma
) 0, splt
->contents
+ 16);
5125 bfd_put_64 (output_bfd
, (bfd_vma
) 0, splt
->contents
+ 24);
5127 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 0;
5134 /* We need to use a special link routine to handle the .mdebug section.
5135 We need to merge all instances of these sections together, not write
5136 them all out sequentially. */
5139 elf64_alpha_final_link (abfd
, info
)
5141 struct bfd_link_info
*info
;
5144 struct bfd_link_order
*p
;
5145 asection
*mdebug_sec
;
5146 struct ecoff_debug_info debug
;
5147 const struct ecoff_debug_swap
*swap
5148 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
5149 HDRR
*symhdr
= &debug
.symbolic_header
;
5150 PTR mdebug_handle
= NULL
;
5152 /* Go through the sections and collect the mdebug information. */
5154 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5156 if (strcmp (o
->name
, ".mdebug") == 0)
5158 struct extsym_info einfo
;
5160 /* We have found the .mdebug section in the output file.
5161 Look through all the link_orders comprising it and merge
5162 the information together. */
5163 symhdr
->magic
= swap
->sym_magic
;
5164 /* FIXME: What should the version stamp be? */
5166 symhdr
->ilineMax
= 0;
5170 symhdr
->isymMax
= 0;
5171 symhdr
->ioptMax
= 0;
5172 symhdr
->iauxMax
= 0;
5174 symhdr
->issExtMax
= 0;
5177 symhdr
->iextMax
= 0;
5179 /* We accumulate the debugging information itself in the
5180 debug_info structure. */
5182 debug
.external_dnr
= NULL
;
5183 debug
.external_pdr
= NULL
;
5184 debug
.external_sym
= NULL
;
5185 debug
.external_opt
= NULL
;
5186 debug
.external_aux
= NULL
;
5188 debug
.ssext
= debug
.ssext_end
= NULL
;
5189 debug
.external_fdr
= NULL
;
5190 debug
.external_rfd
= NULL
;
5191 debug
.external_ext
= debug
.external_ext_end
= NULL
;
5193 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
5194 if (mdebug_handle
== (PTR
) NULL
)
5203 static const char * const name
[] =
5205 ".text", ".init", ".fini", ".data",
5206 ".rodata", ".sdata", ".sbss", ".bss"
5208 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
5209 scRData
, scSData
, scSBss
, scBss
};
5212 esym
.cobol_main
= 0;
5216 esym
.asym
.iss
= issNil
;
5217 esym
.asym
.st
= stLocal
;
5218 esym
.asym
.reserved
= 0;
5219 esym
.asym
.index
= indexNil
;
5220 for (i
= 0; i
< 8; i
++)
5222 esym
.asym
.sc
= sc
[i
];
5223 s
= bfd_get_section_by_name (abfd
, name
[i
]);
5226 esym
.asym
.value
= s
->vma
;
5227 last
= s
->vma
+ s
->_raw_size
;
5230 esym
.asym
.value
= last
;
5232 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
5238 for (p
= o
->link_order_head
;
5239 p
!= (struct bfd_link_order
*) NULL
;
5242 asection
*input_section
;
5244 const struct ecoff_debug_swap
*input_swap
;
5245 struct ecoff_debug_info input_debug
;
5249 if (p
->type
!= bfd_indirect_link_order
)
5251 if (p
->type
== bfd_data_link_order
)
5256 input_section
= p
->u
.indirect
.section
;
5257 input_bfd
= input_section
->owner
;
5259 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
5260 || (get_elf_backend_data (input_bfd
)
5261 ->elf_backend_ecoff_debug_swap
) == NULL
)
5263 /* I don't know what a non ALPHA ELF bfd would be
5264 doing with a .mdebug section, but I don't really
5265 want to deal with it. */
5269 input_swap
= (get_elf_backend_data (input_bfd
)
5270 ->elf_backend_ecoff_debug_swap
);
5272 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
5274 /* The ECOFF linking code expects that we have already
5275 read in the debugging information and set up an
5276 ecoff_debug_info structure, so we do that now. */
5277 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
5281 if (! (bfd_ecoff_debug_accumulate
5282 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5283 &input_debug
, input_swap
, info
)))
5286 /* Loop through the external symbols. For each one with
5287 interesting information, try to find the symbol in
5288 the linker global hash table and save the information
5289 for the output external symbols. */
5290 eraw_src
= input_debug
.external_ext
;
5291 eraw_end
= (eraw_src
5292 + (input_debug
.symbolic_header
.iextMax
5293 * input_swap
->external_ext_size
));
5295 eraw_src
< eraw_end
;
5296 eraw_src
+= input_swap
->external_ext_size
)
5300 struct alpha_elf_link_hash_entry
*h
;
5302 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5303 if (ext
.asym
.sc
== scNil
5304 || ext
.asym
.sc
== scUndefined
5305 || ext
.asym
.sc
== scSUndefined
)
5308 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5309 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
5310 name
, FALSE
, FALSE
, TRUE
);
5311 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5317 < input_debug
.symbolic_header
.ifdMax
);
5318 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5324 /* Free up the information we just read. */
5325 free (input_debug
.line
);
5326 free (input_debug
.external_dnr
);
5327 free (input_debug
.external_pdr
);
5328 free (input_debug
.external_sym
);
5329 free (input_debug
.external_opt
);
5330 free (input_debug
.external_aux
);
5331 free (input_debug
.ss
);
5332 free (input_debug
.ssext
);
5333 free (input_debug
.external_fdr
);
5334 free (input_debug
.external_rfd
);
5335 free (input_debug
.external_ext
);
5337 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5338 elf_link_input_bfd ignores this section. */
5339 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5342 /* Build the external symbol information. */
5345 einfo
.debug
= &debug
;
5347 einfo
.failed
= FALSE
;
5348 elf_link_hash_traverse (elf_hash_table (info
),
5349 elf64_alpha_output_extsym
,
5354 /* Set the size of the .mdebug section. */
5355 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5357 /* Skip this section later on (I don't think this currently
5358 matters, but someday it might). */
5359 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5365 /* Invoke the regular ELF backend linker to do all the work. */
5366 if (! bfd_elf64_bfd_final_link (abfd
, info
))
5369 /* Now write out the computed sections. */
5371 /* The .got subsections... */
5373 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
5374 for (i
= alpha_elf_hash_table(info
)->got_list
;
5376 i
= alpha_elf_tdata(i
)->got_link_next
)
5380 /* elf_bfd_final_link already did everything in dynobj. */
5384 sgot
= alpha_elf_tdata(i
)->got
;
5385 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
5387 (file_ptr
) sgot
->output_offset
,
5393 if (mdebug_sec
!= (asection
*) NULL
)
5395 BFD_ASSERT (abfd
->output_has_begun
);
5396 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5398 mdebug_sec
->filepos
))
5401 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5407 static enum elf_reloc_type_class
5408 elf64_alpha_reloc_type_class (rela
)
5409 const Elf_Internal_Rela
*rela
;
5411 switch ((int) ELF64_R_TYPE (rela
->r_info
))
5413 case R_ALPHA_RELATIVE
:
5414 return reloc_class_relative
;
5415 case R_ALPHA_JMP_SLOT
:
5416 return reloc_class_plt
;
5418 return reloc_class_copy
;
5420 return reloc_class_normal
;
5424 /* ECOFF swapping routines. These are used when dealing with the
5425 .mdebug section, which is in the ECOFF debugging format. Copied
5426 from elf32-mips.c. */
5427 static const struct ecoff_debug_swap
5428 elf64_alpha_ecoff_debug_swap
=
5430 /* Symbol table magic number. */
5432 /* Alignment of debugging information. E.g., 4. */
5434 /* Sizes of external symbolic information. */
5435 sizeof (struct hdr_ext
),
5436 sizeof (struct dnr_ext
),
5437 sizeof (struct pdr_ext
),
5438 sizeof (struct sym_ext
),
5439 sizeof (struct opt_ext
),
5440 sizeof (struct fdr_ext
),
5441 sizeof (struct rfd_ext
),
5442 sizeof (struct ext_ext
),
5443 /* Functions to swap in external symbolic data. */
5452 _bfd_ecoff_swap_tir_in
,
5453 _bfd_ecoff_swap_rndx_in
,
5454 /* Functions to swap out external symbolic data. */
5463 _bfd_ecoff_swap_tir_out
,
5464 _bfd_ecoff_swap_rndx_out
,
5465 /* Function to read in symbolic data. */
5466 elf64_alpha_read_ecoff_info
5469 /* Use a non-standard hash bucket size of 8. */
5471 static const struct elf_size_info alpha_elf_size_info
=
5473 sizeof (Elf64_External_Ehdr
),
5474 sizeof (Elf64_External_Phdr
),
5475 sizeof (Elf64_External_Shdr
),
5476 sizeof (Elf64_External_Rel
),
5477 sizeof (Elf64_External_Rela
),
5478 sizeof (Elf64_External_Sym
),
5479 sizeof (Elf64_External_Dyn
),
5480 sizeof (Elf_External_Note
),
5484 ELFCLASS64
, EV_CURRENT
,
5485 bfd_elf64_write_out_phdrs
,
5486 bfd_elf64_write_shdrs_and_ehdr
,
5487 bfd_elf64_write_relocs
,
5488 bfd_elf64_swap_symbol_in
,
5489 bfd_elf64_swap_symbol_out
,
5490 bfd_elf64_slurp_reloc_table
,
5491 bfd_elf64_slurp_symbol_table
,
5492 bfd_elf64_swap_dyn_in
,
5493 bfd_elf64_swap_dyn_out
,
5494 bfd_elf64_swap_reloc_in
,
5495 bfd_elf64_swap_reloc_out
,
5496 bfd_elf64_swap_reloca_in
,
5497 bfd_elf64_swap_reloca_out
5500 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5501 #define TARGET_LITTLE_NAME "elf64-alpha"
5502 #define ELF_ARCH bfd_arch_alpha
5503 #define ELF_MACHINE_CODE EM_ALPHA
5504 #define ELF_MAXPAGESIZE 0x10000
5506 #define bfd_elf64_bfd_link_hash_table_create \
5507 elf64_alpha_bfd_link_hash_table_create
5509 #define bfd_elf64_bfd_reloc_type_lookup \
5510 elf64_alpha_bfd_reloc_type_lookup
5511 #define elf_info_to_howto \
5512 elf64_alpha_info_to_howto
5514 #define bfd_elf64_mkobject \
5515 elf64_alpha_mkobject
5516 #define elf_backend_object_p \
5517 elf64_alpha_object_p
5519 #define elf_backend_section_from_shdr \
5520 elf64_alpha_section_from_shdr
5521 #define elf_backend_section_flags \
5522 elf64_alpha_section_flags
5523 #define elf_backend_fake_sections \
5524 elf64_alpha_fake_sections
5526 #define bfd_elf64_bfd_is_local_label_name \
5527 elf64_alpha_is_local_label_name
5528 #define bfd_elf64_find_nearest_line \
5529 elf64_alpha_find_nearest_line
5530 #define bfd_elf64_bfd_relax_section \
5531 elf64_alpha_relax_section
5533 #define elf_backend_add_symbol_hook \
5534 elf64_alpha_add_symbol_hook
5535 #define elf_backend_check_relocs \
5536 elf64_alpha_check_relocs
5537 #define elf_backend_create_dynamic_sections \
5538 elf64_alpha_create_dynamic_sections
5539 #define elf_backend_adjust_dynamic_symbol \
5540 elf64_alpha_adjust_dynamic_symbol
5541 #define elf_backend_always_size_sections \
5542 elf64_alpha_always_size_sections
5543 #define elf_backend_size_dynamic_sections \
5544 elf64_alpha_size_dynamic_sections
5545 #define elf_backend_relocate_section \
5546 elf64_alpha_relocate_section
5547 #define elf_backend_finish_dynamic_symbol \
5548 elf64_alpha_finish_dynamic_symbol
5549 #define elf_backend_finish_dynamic_sections \
5550 elf64_alpha_finish_dynamic_sections
5551 #define bfd_elf64_bfd_final_link \
5552 elf64_alpha_final_link
5553 #define elf_backend_reloc_type_class \
5554 elf64_alpha_reloc_type_class
5556 #define elf_backend_ecoff_debug_swap \
5557 &elf64_alpha_ecoff_debug_swap
5559 #define elf_backend_size_info \
5562 /* A few constants that determine how the .plt section is set up. */
5563 #define elf_backend_want_got_plt 0
5564 #define elf_backend_plt_readonly 0
5565 #define elf_backend_want_plt_sym 1
5566 #define elf_backend_got_header_size 0
5567 #define elf_backend_plt_header_size PLT_HEADER_SIZE
5569 #include "elf64-target.h"
5571 /* FreeBSD support. */
5573 #undef TARGET_LITTLE_SYM
5574 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5575 #undef TARGET_LITTLE_NAME
5576 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5578 /* The kernel recognizes executables as valid only if they carry a
5579 "FreeBSD" label in the ELF header. So we put this label on all
5580 executables and (for simplicity) also all other object files. */
5582 static void elf64_alpha_fbsd_post_process_headers
5583 PARAMS ((bfd
*, struct bfd_link_info
*));
5586 elf64_alpha_fbsd_post_process_headers (abfd
, link_info
)
5588 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
5590 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
5592 i_ehdrp
= elf_elfheader (abfd
);
5594 /* Put an ABI label supported by FreeBSD >= 4.1. */
5595 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
5596 #ifdef OLD_FREEBSD_ABI_LABEL
5597 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5598 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5602 #undef elf_backend_post_process_headers
5603 #define elf_backend_post_process_headers \
5604 elf64_alpha_fbsd_post_process_headers
5607 #define elf64_bed elf64_alpha_fbsd_bed
5609 #include "elf64-target.h"