1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Richard Henderson <rth@tamu.edu>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* We need a published ABI spec for this. Until one comes out, don't
23 assume this'll remain unchanged forever. */
30 #include "elf/alpha.h"
34 #define NO_COFF_RELOCS
35 #define NO_COFF_SYMBOLS
36 #define NO_COFF_LINENOS
38 /* Get the ECOFF swapping routines. Needed for the debug information. */
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
43 #include "coff/alpha.h"
48 #include "ecoffswap.h"
50 static int alpha_elf_dynamic_symbol_p
51 PARAMS ((struct elf_link_hash_entry
*, struct bfd_link_info
*));
52 static struct bfd_hash_entry
* elf64_alpha_link_hash_newfunc
53 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
54 static struct bfd_link_hash_table
* elf64_alpha_bfd_link_hash_table_create
57 static bfd_reloc_status_type elf64_alpha_reloc_nil
58 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
59 static bfd_reloc_status_type elf64_alpha_reloc_bad
60 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
61 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
62 PARAMS ((bfd
*, bfd_vma
, bfd_byte
*, bfd_byte
*));
63 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
64 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
66 static reloc_howto_type
* elf64_alpha_bfd_reloc_type_lookup
67 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
68 static void elf64_alpha_info_to_howto
69 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
71 static bfd_boolean elf64_alpha_mkobject
73 static bfd_boolean elf64_alpha_object_p
75 static bfd_boolean elf64_alpha_section_from_shdr
76 PARAMS ((bfd
*, Elf_Internal_Shdr
*, const char *));
77 static bfd_boolean elf64_alpha_section_flags
78 PARAMS ((flagword
*, Elf_Internal_Shdr
*));
79 static bfd_boolean elf64_alpha_fake_sections
80 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
81 static bfd_boolean elf64_alpha_create_got_section
82 PARAMS ((bfd
*, struct bfd_link_info
*));
83 static bfd_boolean elf64_alpha_create_dynamic_sections
84 PARAMS ((bfd
*, struct bfd_link_info
*));
86 static bfd_boolean elf64_alpha_read_ecoff_info
87 PARAMS ((bfd
*, asection
*, struct ecoff_debug_info
*));
88 static bfd_boolean elf64_alpha_is_local_label_name
89 PARAMS ((bfd
*, const char *));
90 static bfd_boolean elf64_alpha_find_nearest_line
91 PARAMS ((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
92 const char **, unsigned int *));
94 #if defined(__STDC__) || defined(ALMOST_STDC)
95 struct alpha_elf_link_hash_entry
;
98 static bfd_boolean elf64_alpha_output_extsym
99 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
101 static bfd_boolean elf64_alpha_can_merge_gots
102 PARAMS ((bfd
*, bfd
*));
103 static void elf64_alpha_merge_gots
104 PARAMS ((bfd
*, bfd
*));
105 static bfd_boolean elf64_alpha_calc_got_offsets_for_symbol
106 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
107 static void elf64_alpha_calc_got_offsets
108 PARAMS ((struct bfd_link_info
*));
109 static bfd_boolean elf64_alpha_size_got_sections
110 PARAMS ((struct bfd_link_info
*));
111 static bfd_boolean elf64_alpha_size_plt_section
112 PARAMS ((struct bfd_link_info
*));
113 static bfd_boolean elf64_alpha_size_plt_section_1
114 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
115 static bfd_boolean elf64_alpha_always_size_sections
116 PARAMS ((bfd
*, struct bfd_link_info
*));
117 static int alpha_dynamic_entries_for_reloc
118 PARAMS ((int, int, int));
119 static bfd_boolean elf64_alpha_calc_dynrel_sizes
120 PARAMS ((struct alpha_elf_link_hash_entry
*, struct bfd_link_info
*));
121 static bfd_boolean elf64_alpha_size_rela_got_section
122 PARAMS ((struct bfd_link_info
*));
123 static bfd_boolean elf64_alpha_size_rela_got_1
124 PARAMS ((struct alpha_elf_link_hash_entry
*, struct bfd_link_info
*));
125 static bfd_boolean elf64_alpha_add_symbol_hook
126 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
127 const char **, flagword
*, asection
**, bfd_vma
*));
128 static struct alpha_elf_got_entry
*get_got_entry
129 PARAMS ((bfd
*, struct alpha_elf_link_hash_entry
*, unsigned long,
130 unsigned long, bfd_vma
));
131 static bfd_boolean elf64_alpha_check_relocs
132 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*sec
,
133 const Elf_Internal_Rela
*));
134 static bfd_boolean elf64_alpha_adjust_dynamic_symbol
135 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
136 static bfd_boolean elf64_alpha_size_dynamic_sections
137 PARAMS ((bfd
*, struct bfd_link_info
*));
138 static void elf64_alpha_emit_dynrel
139 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*, asection
*,
140 bfd_vma
, long, long, bfd_vma
));
141 static bfd_boolean elf64_alpha_relocate_section_r
142 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
143 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
144 static bfd_boolean elf64_alpha_relocate_section
145 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
146 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
147 static bfd_boolean elf64_alpha_finish_dynamic_symbol
148 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
149 Elf_Internal_Sym
*));
150 static bfd_boolean elf64_alpha_finish_dynamic_sections
151 PARAMS ((bfd
*, struct bfd_link_info
*));
152 static bfd_boolean elf64_alpha_final_link
153 PARAMS ((bfd
*, struct bfd_link_info
*));
154 static bfd_boolean elf64_alpha_merge_ind_symbols
155 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
156 static Elf_Internal_Rela
* elf64_alpha_find_reloc_at_ofs
157 PARAMS ((Elf_Internal_Rela
*, Elf_Internal_Rela
*, bfd_vma
, int));
158 static enum elf_reloc_type_class elf64_alpha_reloc_type_class
159 PARAMS ((const Elf_Internal_Rela
*));
161 struct alpha_elf_link_hash_entry
163 struct elf_link_hash_entry root
;
165 /* External symbol information. */
168 /* Cumulative flags for all the .got entries. */
171 /* Contexts in which a literal was referenced. */
172 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
173 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
174 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
175 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08
176 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10
177 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20
178 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x38
179 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x40
180 #define ALPHA_ELF_LINK_HASH_PLT_LOC 0x80
182 /* Used to undo the localization of a plt symbol. */
183 asection
*plt_old_section
;
184 bfd_vma plt_old_value
;
186 /* Used to implement multiple .got subsections. */
187 struct alpha_elf_got_entry
189 struct alpha_elf_got_entry
*next
;
191 /* Which .got subsection? */
194 /* The addend in effect for this entry. */
197 /* The .got offset for this entry. */
200 /* How many references to this entry? */
203 /* The relocation type of this entry. */
204 unsigned char reloc_type
;
206 /* How a LITERAL is used. */
209 /* Have we initialized the dynamic relocation for this entry? */
210 unsigned char reloc_done
;
212 /* Have we adjusted this entry for SEC_MERGE? */
213 unsigned char reloc_xlated
;
216 /* Used to count non-got, non-plt relocations for delayed sizing
217 of relocation sections. */
218 struct alpha_elf_reloc_entry
220 struct alpha_elf_reloc_entry
*next
;
222 /* Which .reloc section? */
225 /* What kind of relocation? */
228 /* Is this against read-only section? */
229 unsigned int reltext
: 1;
231 /* How many did we find? */
236 /* Alpha ELF linker hash table. */
238 struct alpha_elf_link_hash_table
240 struct elf_link_hash_table root
;
242 /* The head of a list of .got subsections linked through
243 alpha_elf_tdata(abfd)->got_link_next. */
247 /* Look up an entry in a Alpha ELF linker hash table. */
249 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
250 ((struct alpha_elf_link_hash_entry *) \
251 elf_link_hash_lookup (&(table)->root, (string), (create), \
254 /* Traverse a Alpha ELF linker hash table. */
256 #define alpha_elf_link_hash_traverse(table, func, info) \
257 (elf_link_hash_traverse \
259 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
262 /* Get the Alpha ELF linker hash table from a link_info structure. */
264 #define alpha_elf_hash_table(p) \
265 ((struct alpha_elf_link_hash_table *) ((p)->hash))
267 /* Get the object's symbols as our own entry type. */
269 #define alpha_elf_sym_hashes(abfd) \
270 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
272 /* Should we do dynamic things to this symbol? */
275 alpha_elf_dynamic_symbol_p (h
, info
)
276 struct elf_link_hash_entry
*h
;
277 struct bfd_link_info
*info
;
282 while (h
->root
.type
== bfd_link_hash_indirect
283 || h
->root
.type
== bfd_link_hash_warning
)
284 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
286 if (h
->dynindx
== -1)
289 if (h
->root
.type
== bfd_link_hash_undefweak
290 || h
->root
.type
== bfd_link_hash_defweak
)
293 switch (ELF_ST_VISIBILITY (h
->other
))
301 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
306 if ((info
->shared
&& !info
->symbolic
)
307 || ((h
->elf_link_hash_flags
308 & (ELF_LINK_HASH_DEF_DYNAMIC
309 | ELF_LINK_HASH_DEF_REGULAR
310 | ELF_LINK_HASH_REF_REGULAR
))
311 == (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
)))
317 /* Create an entry in a Alpha ELF linker hash table. */
319 static struct bfd_hash_entry
*
320 elf64_alpha_link_hash_newfunc (entry
, table
, string
)
321 struct bfd_hash_entry
*entry
;
322 struct bfd_hash_table
*table
;
325 struct alpha_elf_link_hash_entry
*ret
=
326 (struct alpha_elf_link_hash_entry
*) entry
;
328 /* Allocate the structure if it has not already been allocated by a
330 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
331 ret
= ((struct alpha_elf_link_hash_entry
*)
332 bfd_hash_allocate (table
,
333 sizeof (struct alpha_elf_link_hash_entry
)));
334 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
335 return (struct bfd_hash_entry
*) ret
;
337 /* Call the allocation method of the superclass. */
338 ret
= ((struct alpha_elf_link_hash_entry
*)
339 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
341 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
343 /* Set local fields. */
344 memset (&ret
->esym
, 0, sizeof (EXTR
));
345 /* We use -2 as a marker to indicate that the information has
346 not been set. -1 means there is no associated ifd. */
349 ret
->got_entries
= NULL
;
350 ret
->reloc_entries
= NULL
;
353 return (struct bfd_hash_entry
*) ret
;
356 /* Create a Alpha ELF linker hash table. */
358 static struct bfd_link_hash_table
*
359 elf64_alpha_bfd_link_hash_table_create (abfd
)
362 struct alpha_elf_link_hash_table
*ret
;
363 bfd_size_type amt
= sizeof (struct alpha_elf_link_hash_table
);
365 ret
= (struct alpha_elf_link_hash_table
*) bfd_zmalloc (amt
);
366 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
369 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
370 elf64_alpha_link_hash_newfunc
))
376 return &ret
->root
.root
;
379 /* We have some private fields hanging off of the elf_tdata structure. */
381 struct alpha_elf_obj_tdata
383 struct elf_obj_tdata root
;
385 /* For every input file, these are the got entries for that object's
387 struct alpha_elf_got_entry
** local_got_entries
;
389 /* For every input file, this is the object that owns the got that
390 this input file uses. */
393 /* For every got, this is a linked list through the objects using this got */
394 bfd
*in_got_link_next
;
396 /* For every got, this is a link to the next got subsegment. */
399 /* For every got, this is the section. */
402 /* For every got, this is it's total number of words. */
405 /* For every got, this is the sum of the number of words required
406 to hold all of the member object's local got. */
410 #define alpha_elf_tdata(abfd) \
411 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
414 elf64_alpha_mkobject (abfd
)
417 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
418 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
419 if (abfd
->tdata
.any
== NULL
)
425 elf64_alpha_object_p (abfd
)
428 /* Allocate our special target data. */
429 struct alpha_elf_obj_tdata
*new_tdata
;
430 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
431 new_tdata
= bfd_zalloc (abfd
, amt
);
432 if (new_tdata
== NULL
)
434 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
435 abfd
->tdata
.any
= new_tdata
;
437 /* Set the right machine number for an Alpha ELF file. */
438 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
441 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
442 from smaller values. Start with zero, widen, *then* decrement. */
443 #define MINUS_ONE (((bfd_vma)0) - 1)
445 #define SKIP_HOWTO(N) \
446 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
448 static reloc_howto_type elf64_alpha_howto_table
[] =
450 HOWTO (R_ALPHA_NONE
, /* type */
452 0, /* size (0 = byte, 1 = short, 2 = long) */
454 TRUE
, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 elf64_alpha_reloc_nil
, /* special_function */
459 FALSE
, /* partial_inplace */
462 TRUE
), /* pcrel_offset */
464 /* A 32 bit reference to a symbol. */
465 HOWTO (R_ALPHA_REFLONG
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 FALSE
, /* pc_relative */
471 complain_overflow_bitfield
, /* complain_on_overflow */
472 0, /* special_function */
473 "REFLONG", /* name */
474 FALSE
, /* partial_inplace */
475 0xffffffff, /* src_mask */
476 0xffffffff, /* dst_mask */
477 FALSE
), /* pcrel_offset */
479 /* A 64 bit reference to a symbol. */
480 HOWTO (R_ALPHA_REFQUAD
, /* type */
482 4, /* size (0 = byte, 1 = short, 2 = long) */
484 FALSE
, /* pc_relative */
486 complain_overflow_bitfield
, /* complain_on_overflow */
487 0, /* special_function */
488 "REFQUAD", /* name */
489 FALSE
, /* partial_inplace */
490 MINUS_ONE
, /* src_mask */
491 MINUS_ONE
, /* dst_mask */
492 FALSE
), /* pcrel_offset */
494 /* A 32 bit GP relative offset. This is just like REFLONG except
495 that when the value is used the value of the gp register will be
497 HOWTO (R_ALPHA_GPREL32
, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE
, /* pc_relative */
503 complain_overflow_bitfield
, /* complain_on_overflow */
504 0, /* special_function */
505 "GPREL32", /* name */
506 FALSE
, /* partial_inplace */
507 0xffffffff, /* src_mask */
508 0xffffffff, /* dst_mask */
509 FALSE
), /* pcrel_offset */
511 /* Used for an instruction that refers to memory off the GP register. */
512 HOWTO (R_ALPHA_LITERAL
, /* type */
514 1, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE
, /* pc_relative */
518 complain_overflow_signed
, /* complain_on_overflow */
519 0, /* special_function */
520 "ELF_LITERAL", /* name */
521 FALSE
, /* partial_inplace */
522 0xffff, /* src_mask */
523 0xffff, /* dst_mask */
524 FALSE
), /* pcrel_offset */
526 /* This reloc only appears immediately following an ELF_LITERAL reloc.
527 It identifies a use of the literal. The symbol index is special:
528 1 means the literal address is in the base register of a memory
529 format instruction; 2 means the literal address is in the byte
530 offset register of a byte-manipulation instruction; 3 means the
531 literal address is in the target register of a jsr instruction.
532 This does not actually do any relocation. */
533 HOWTO (R_ALPHA_LITUSE
, /* type */
535 1, /* size (0 = byte, 1 = short, 2 = long) */
537 FALSE
, /* pc_relative */
539 complain_overflow_dont
, /* complain_on_overflow */
540 elf64_alpha_reloc_nil
, /* special_function */
542 FALSE
, /* partial_inplace */
545 FALSE
), /* pcrel_offset */
547 /* Load the gp register. This is always used for a ldah instruction
548 which loads the upper 16 bits of the gp register. The symbol
549 index of the GPDISP instruction is an offset in bytes to the lda
550 instruction that loads the lower 16 bits. The value to use for
551 the relocation is the difference between the GP value and the
552 current location; the load will always be done against a register
553 holding the current address.
555 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
556 any offset is present in the instructions, it is an offset from
557 the register to the ldah instruction. This lets us avoid any
558 stupid hackery like inventing a gp value to do partial relocation
559 against. Also unlike ECOFF, we do the whole relocation off of
560 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
561 space consuming bit, that, since all the information was present
562 in the GPDISP_HI16 reloc. */
563 HOWTO (R_ALPHA_GPDISP
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_dont
, /* complain_on_overflow */
570 elf64_alpha_reloc_gpdisp
, /* special_function */
572 FALSE
, /* partial_inplace */
573 0xffff, /* src_mask */
574 0xffff, /* dst_mask */
575 TRUE
), /* pcrel_offset */
577 /* A 21 bit branch. */
578 HOWTO (R_ALPHA_BRADDR
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 TRUE
, /* pc_relative */
584 complain_overflow_signed
, /* complain_on_overflow */
585 0, /* special_function */
587 FALSE
, /* partial_inplace */
588 0x1fffff, /* src_mask */
589 0x1fffff, /* dst_mask */
590 TRUE
), /* pcrel_offset */
592 /* A hint for a jump to a register. */
593 HOWTO (R_ALPHA_HINT
, /* type */
595 1, /* size (0 = byte, 1 = short, 2 = long) */
597 TRUE
, /* pc_relative */
599 complain_overflow_dont
, /* complain_on_overflow */
600 0, /* special_function */
602 FALSE
, /* partial_inplace */
603 0x3fff, /* src_mask */
604 0x3fff, /* dst_mask */
605 TRUE
), /* pcrel_offset */
607 /* 16 bit PC relative offset. */
608 HOWTO (R_ALPHA_SREL16
, /* type */
610 1, /* size (0 = byte, 1 = short, 2 = long) */
612 TRUE
, /* pc_relative */
614 complain_overflow_signed
, /* complain_on_overflow */
615 0, /* special_function */
617 FALSE
, /* partial_inplace */
618 0xffff, /* src_mask */
619 0xffff, /* dst_mask */
620 TRUE
), /* pcrel_offset */
622 /* 32 bit PC relative offset. */
623 HOWTO (R_ALPHA_SREL32
, /* type */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
627 TRUE
, /* pc_relative */
629 complain_overflow_signed
, /* complain_on_overflow */
630 0, /* special_function */
632 FALSE
, /* partial_inplace */
633 0xffffffff, /* src_mask */
634 0xffffffff, /* dst_mask */
635 TRUE
), /* pcrel_offset */
637 /* A 64 bit PC relative offset. */
638 HOWTO (R_ALPHA_SREL64
, /* type */
640 4, /* size (0 = byte, 1 = short, 2 = long) */
642 TRUE
, /* pc_relative */
644 complain_overflow_signed
, /* complain_on_overflow */
645 0, /* special_function */
647 FALSE
, /* partial_inplace */
648 MINUS_ONE
, /* src_mask */
649 MINUS_ONE
, /* dst_mask */
650 TRUE
), /* pcrel_offset */
652 /* Skip 12 - 16; deprecated ECOFF relocs. */
659 /* The high 16 bits of the displacement from GP to the target. */
660 HOWTO (R_ALPHA_GPRELHIGH
,
662 1, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_signed
, /* complain_on_overflow */
667 0, /* special_function */
668 "GPRELHIGH", /* name */
669 FALSE
, /* partial_inplace */
670 0xffff, /* src_mask */
671 0xffff, /* dst_mask */
672 FALSE
), /* pcrel_offset */
674 /* The low 16 bits of the displacement from GP to the target. */
675 HOWTO (R_ALPHA_GPRELLOW
,
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_dont
, /* complain_on_overflow */
682 0, /* special_function */
683 "GPRELLOW", /* name */
684 FALSE
, /* partial_inplace */
685 0xffff, /* src_mask */
686 0xffff, /* dst_mask */
687 FALSE
), /* pcrel_offset */
689 /* A 16-bit displacement from the GP to the target. */
690 HOWTO (R_ALPHA_GPREL16
,
692 1, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_signed
, /* complain_on_overflow */
697 0, /* special_function */
698 "GPREL16", /* name */
699 FALSE
, /* partial_inplace */
700 0xffff, /* src_mask */
701 0xffff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 /* Skip 20 - 23; deprecated ECOFF relocs. */
710 /* Misc ELF relocations. */
712 /* A dynamic relocation to copy the target into our .dynbss section. */
713 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
714 is present because every other ELF has one, but should not be used
715 because .dynbss is an ugly thing. */
722 complain_overflow_dont
,
723 bfd_elf_generic_reloc
,
730 /* A dynamic relocation for a .got entry. */
731 HOWTO (R_ALPHA_GLOB_DAT
,
737 complain_overflow_dont
,
738 bfd_elf_generic_reloc
,
745 /* A dynamic relocation for a .plt entry. */
746 HOWTO (R_ALPHA_JMP_SLOT
,
752 complain_overflow_dont
,
753 bfd_elf_generic_reloc
,
760 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
761 HOWTO (R_ALPHA_RELATIVE
,
767 complain_overflow_dont
,
768 bfd_elf_generic_reloc
,
775 /* A 21 bit branch that adjusts for gp loads. */
776 HOWTO (R_ALPHA_BRSGP
, /* type */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 TRUE
, /* pc_relative */
782 complain_overflow_signed
, /* complain_on_overflow */
783 0, /* special_function */
785 FALSE
, /* partial_inplace */
786 0x1fffff, /* src_mask */
787 0x1fffff, /* dst_mask */
788 TRUE
), /* pcrel_offset */
790 /* Creates a tls_index for the symbol in the got. */
791 HOWTO (R_ALPHA_TLSGD
, /* type */
793 1, /* size (0 = byte, 1 = short, 2 = long) */
795 FALSE
, /* pc_relative */
797 complain_overflow_signed
, /* complain_on_overflow */
798 0, /* special_function */
800 FALSE
, /* partial_inplace */
801 0xffff, /* src_mask */
802 0xffff, /* dst_mask */
803 FALSE
), /* pcrel_offset */
805 /* Creates a tls_index for the (current) module in the got. */
806 HOWTO (R_ALPHA_TLSLDM
, /* type */
808 1, /* size (0 = byte, 1 = short, 2 = long) */
810 FALSE
, /* pc_relative */
812 complain_overflow_signed
, /* complain_on_overflow */
813 0, /* special_function */
815 FALSE
, /* partial_inplace */
816 0xffff, /* src_mask */
817 0xffff, /* dst_mask */
818 FALSE
), /* pcrel_offset */
820 /* A dynamic relocation for a DTP module entry. */
821 HOWTO (R_ALPHA_DTPMOD64
, /* type */
823 4, /* size (0 = byte, 1 = short, 2 = long) */
825 FALSE
, /* pc_relative */
827 complain_overflow_bitfield
, /* complain_on_overflow */
828 0, /* special_function */
829 "DTPMOD64", /* name */
830 FALSE
, /* partial_inplace */
831 MINUS_ONE
, /* src_mask */
832 MINUS_ONE
, /* dst_mask */
833 FALSE
), /* pcrel_offset */
835 /* Creates a 64-bit offset in the got for the displacement
836 from DTP to the target. */
837 HOWTO (R_ALPHA_GOTDTPREL
, /* type */
839 1, /* size (0 = byte, 1 = short, 2 = long) */
841 FALSE
, /* pc_relative */
843 complain_overflow_signed
, /* complain_on_overflow */
844 0, /* special_function */
845 "GOTDTPREL", /* name */
846 FALSE
, /* partial_inplace */
847 0xffff, /* src_mask */
848 0xffff, /* dst_mask */
849 FALSE
), /* pcrel_offset */
851 /* A dynamic relocation for a displacement from DTP to the target. */
852 HOWTO (R_ALPHA_DTPREL64
, /* type */
854 4, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE
, /* pc_relative */
858 complain_overflow_bitfield
, /* complain_on_overflow */
859 0, /* special_function */
860 "DTPREL64", /* name */
861 FALSE
, /* partial_inplace */
862 MINUS_ONE
, /* src_mask */
863 MINUS_ONE
, /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 /* The high 16 bits of the displacement from DTP to the target. */
867 HOWTO (R_ALPHA_DTPRELHI
, /* type */
869 1, /* size (0 = byte, 1 = short, 2 = long) */
871 FALSE
, /* pc_relative */
873 complain_overflow_signed
, /* complain_on_overflow */
874 0, /* special_function */
875 "DTPRELHI", /* name */
876 FALSE
, /* partial_inplace */
877 0xffff, /* src_mask */
878 0xffff, /* dst_mask */
879 FALSE
), /* pcrel_offset */
881 /* The low 16 bits of the displacement from DTP to the target. */
882 HOWTO (R_ALPHA_DTPRELLO
, /* type */
884 1, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE
, /* pc_relative */
888 complain_overflow_dont
, /* complain_on_overflow */
889 0, /* special_function */
890 "DTPRELLO", /* name */
891 FALSE
, /* partial_inplace */
892 0xffff, /* src_mask */
893 0xffff, /* dst_mask */
894 FALSE
), /* pcrel_offset */
896 /* A 16-bit displacement from DTP to the target. */
897 HOWTO (R_ALPHA_DTPREL16
, /* type */
899 1, /* size (0 = byte, 1 = short, 2 = long) */
901 FALSE
, /* pc_relative */
903 complain_overflow_signed
, /* complain_on_overflow */
904 0, /* special_function */
905 "DTPREL16", /* name */
906 FALSE
, /* partial_inplace */
907 0xffff, /* src_mask */
908 0xffff, /* dst_mask */
909 FALSE
), /* pcrel_offset */
911 /* Creates a 64-bit offset in the got for the displacement
912 from TP to the target. */
913 HOWTO (R_ALPHA_GOTTPREL
, /* type */
915 1, /* size (0 = byte, 1 = short, 2 = long) */
917 FALSE
, /* pc_relative */
919 complain_overflow_signed
, /* complain_on_overflow */
920 0, /* special_function */
921 "GOTTPREL", /* name */
922 FALSE
, /* partial_inplace */
923 0xffff, /* src_mask */
924 0xffff, /* dst_mask */
925 FALSE
), /* pcrel_offset */
927 /* A dynamic relocation for a displacement from TP to the target. */
928 HOWTO (R_ALPHA_TPREL64
, /* type */
930 4, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE
, /* pc_relative */
934 complain_overflow_bitfield
, /* complain_on_overflow */
935 0, /* special_function */
936 "TPREL64", /* name */
937 FALSE
, /* partial_inplace */
938 MINUS_ONE
, /* src_mask */
939 MINUS_ONE
, /* dst_mask */
940 FALSE
), /* pcrel_offset */
942 /* The high 16 bits of the displacement from TP to the target. */
943 HOWTO (R_ALPHA_TPRELHI
, /* type */
945 1, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE
, /* pc_relative */
949 complain_overflow_signed
, /* complain_on_overflow */
950 0, /* special_function */
951 "TPRELHI", /* name */
952 FALSE
, /* partial_inplace */
953 0xffff, /* src_mask */
954 0xffff, /* dst_mask */
955 FALSE
), /* pcrel_offset */
957 /* The low 16 bits of the displacement from TP to the target. */
958 HOWTO (R_ALPHA_TPRELLO
, /* type */
960 1, /* size (0 = byte, 1 = short, 2 = long) */
962 FALSE
, /* pc_relative */
964 complain_overflow_dont
, /* complain_on_overflow */
965 0, /* special_function */
966 "TPRELLO", /* name */
967 FALSE
, /* partial_inplace */
968 0xffff, /* src_mask */
969 0xffff, /* dst_mask */
970 FALSE
), /* pcrel_offset */
972 /* A 16-bit displacement from TP to the target. */
973 HOWTO (R_ALPHA_TPREL16
, /* type */
975 1, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE
, /* pc_relative */
979 complain_overflow_signed
, /* complain_on_overflow */
980 0, /* special_function */
981 "TPREL16", /* name */
982 FALSE
, /* partial_inplace */
983 0xffff, /* src_mask */
984 0xffff, /* dst_mask */
985 FALSE
), /* pcrel_offset */
988 /* A relocation function which doesn't do anything. */
990 static bfd_reloc_status_type
991 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
992 bfd
*abfd ATTRIBUTE_UNUSED
;
994 asymbol
*sym ATTRIBUTE_UNUSED
;
995 PTR data ATTRIBUTE_UNUSED
;
998 char **error_message ATTRIBUTE_UNUSED
;
1001 reloc
->address
+= sec
->output_offset
;
1002 return bfd_reloc_ok
;
1005 /* A relocation function used for an unsupported reloc. */
1007 static bfd_reloc_status_type
1008 elf64_alpha_reloc_bad (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
1009 bfd
*abfd ATTRIBUTE_UNUSED
;
1011 asymbol
*sym ATTRIBUTE_UNUSED
;
1012 PTR data ATTRIBUTE_UNUSED
;
1015 char **error_message ATTRIBUTE_UNUSED
;
1018 reloc
->address
+= sec
->output_offset
;
1019 return bfd_reloc_notsupported
;
1022 /* Do the work of the GPDISP relocation. */
1024 static bfd_reloc_status_type
1025 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
1031 bfd_reloc_status_type ret
= bfd_reloc_ok
;
1033 unsigned long i_ldah
, i_lda
;
1035 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
1036 i_lda
= bfd_get_32 (abfd
, p_lda
);
1038 /* Complain if the instructions are not correct. */
1039 if (((i_ldah
>> 26) & 0x3f) != 0x09
1040 || ((i_lda
>> 26) & 0x3f) != 0x08)
1041 ret
= bfd_reloc_dangerous
;
1043 /* Extract the user-supplied offset, mirroring the sign extensions
1044 that the instructions perform. */
1045 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
1046 addend
= (addend
^ 0x80008000) - 0x80008000;
1050 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
) 0x80000000
1051 || (bfd_signed_vma
) gpdisp
>= (bfd_signed_vma
) 0x7fff8000)
1052 ret
= bfd_reloc_overflow
;
1054 /* compensate for the sign extension again. */
1055 i_ldah
= ((i_ldah
& 0xffff0000)
1056 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
1057 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
1059 bfd_put_32 (abfd
, (bfd_vma
) i_ldah
, p_ldah
);
1060 bfd_put_32 (abfd
, (bfd_vma
) i_lda
, p_lda
);
1065 /* The special function for the GPDISP reloc. */
1067 static bfd_reloc_status_type
1068 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
1069 output_bfd
, err_msg
)
1071 arelent
*reloc_entry
;
1072 asymbol
*sym ATTRIBUTE_UNUSED
;
1074 asection
*input_section
;
1078 bfd_reloc_status_type ret
;
1079 bfd_vma gp
, relocation
;
1080 bfd_byte
*p_ldah
, *p_lda
;
1082 /* Don't do anything if we're not doing a final link. */
1085 reloc_entry
->address
+= input_section
->output_offset
;
1086 return bfd_reloc_ok
;
1089 if (reloc_entry
->address
> input_section
->_cooked_size
||
1090 reloc_entry
->address
+ reloc_entry
->addend
> input_section
->_cooked_size
)
1091 return bfd_reloc_outofrange
;
1093 /* The gp used in the portion of the output object to which this
1094 input object belongs is cached on the input bfd. */
1095 gp
= _bfd_get_gp_value (abfd
);
1097 relocation
= (input_section
->output_section
->vma
1098 + input_section
->output_offset
1099 + reloc_entry
->address
);
1101 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
1102 p_lda
= p_ldah
+ reloc_entry
->addend
;
1104 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
1106 /* Complain if the instructions are not correct. */
1107 if (ret
== bfd_reloc_dangerous
)
1108 *err_msg
= _("GPDISP relocation did not find ldah and lda instructions");
1113 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1115 struct elf_reloc_map
1117 bfd_reloc_code_real_type bfd_reloc_val
;
1121 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
1123 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
1124 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
1125 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
1126 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
1127 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
1128 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
1129 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
1130 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
1131 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
1132 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
1133 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
1134 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
1135 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
1136 {BFD_RELOC_ALPHA_GPREL_HI16
, R_ALPHA_GPRELHIGH
},
1137 {BFD_RELOC_ALPHA_GPREL_LO16
, R_ALPHA_GPRELLOW
},
1138 {BFD_RELOC_GPREL16
, R_ALPHA_GPREL16
},
1139 {BFD_RELOC_ALPHA_BRSGP
, R_ALPHA_BRSGP
},
1140 {BFD_RELOC_ALPHA_TLSGD
, R_ALPHA_TLSGD
},
1141 {BFD_RELOC_ALPHA_TLSLDM
, R_ALPHA_TLSLDM
},
1142 {BFD_RELOC_ALPHA_DTPMOD64
, R_ALPHA_DTPMOD64
},
1143 {BFD_RELOC_ALPHA_GOTDTPREL16
, R_ALPHA_GOTDTPREL
},
1144 {BFD_RELOC_ALPHA_DTPREL64
, R_ALPHA_DTPREL64
},
1145 {BFD_RELOC_ALPHA_DTPREL_HI16
, R_ALPHA_DTPRELHI
},
1146 {BFD_RELOC_ALPHA_DTPREL_LO16
, R_ALPHA_DTPRELLO
},
1147 {BFD_RELOC_ALPHA_DTPREL16
, R_ALPHA_DTPREL16
},
1148 {BFD_RELOC_ALPHA_GOTTPREL16
, R_ALPHA_GOTTPREL
},
1149 {BFD_RELOC_ALPHA_TPREL64
, R_ALPHA_TPREL64
},
1150 {BFD_RELOC_ALPHA_TPREL_HI16
, R_ALPHA_TPRELHI
},
1151 {BFD_RELOC_ALPHA_TPREL_LO16
, R_ALPHA_TPRELLO
},
1152 {BFD_RELOC_ALPHA_TPREL16
, R_ALPHA_TPREL16
},
1155 /* Given a BFD reloc type, return a HOWTO structure. */
1157 static reloc_howto_type
*
1158 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
1159 bfd
*abfd ATTRIBUTE_UNUSED
;
1160 bfd_reloc_code_real_type code
;
1162 const struct elf_reloc_map
*i
, *e
;
1163 i
= e
= elf64_alpha_reloc_map
;
1164 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
1167 if (i
->bfd_reloc_val
== code
)
1168 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
1173 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1176 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
1177 bfd
*abfd ATTRIBUTE_UNUSED
;
1179 Elf_Internal_Rela
*dst
;
1183 r_type
= ELF64_R_TYPE(dst
->r_info
);
1184 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1185 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1188 /* These two relocations create a two-word entry in the got. */
1189 #define alpha_got_entry_size(r_type) \
1190 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1192 /* This is PT_TLS segment p_vaddr. */
1193 #define alpha_get_dtprel_base(tlss) \
1196 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1197 is assigned offset round(16, PT_TLS p_align). */
1198 #define alpha_get_tprel_base(tlss) \
1199 ((tlss)->start - align_power ((bfd_vma) 16, (tlss)->align))
1201 /* These functions do relaxation for Alpha ELF.
1203 Currently I'm only handling what I can do with existing compiler
1204 and assembler support, which means no instructions are removed,
1205 though some may be nopped. At this time GCC does not emit enough
1206 information to do all of the relaxing that is possible. It will
1207 take some not small amount of work for that to happen.
1209 There are a couple of interesting papers that I once read on this
1210 subject, that I cannot find references to at the moment, that
1211 related to Alpha in particular. They are by David Wall, then of
1215 #define OP_LDAH 0x09
1216 #define INSN_JSR 0x68004000
1217 #define INSN_JSR_MASK 0xfc00c000
1221 #define INSN_UNOP 0x2ffe0000
1222 #define INSN_ADDQ 0x40000400
1223 #define INSN_RDUNIQ 0x0000009e
1225 struct alpha_relax_info
1230 Elf_Internal_Shdr
*symtab_hdr
;
1231 Elf_Internal_Rela
*relocs
, *relend
;
1232 struct bfd_link_info
*link_info
;
1233 struct elf_link_tls_segment
*tls_segment
;
1237 struct alpha_elf_link_hash_entry
*h
;
1238 struct alpha_elf_got_entry
**first_gotent
;
1239 struct alpha_elf_got_entry
*gotent
;
1240 bfd_boolean changed_contents
;
1241 bfd_boolean changed_relocs
;
1242 unsigned char other
;
1245 static bfd_boolean elf64_alpha_relax_with_lituse
1246 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1247 Elf_Internal_Rela
*irel
));
1248 static bfd_vma elf64_alpha_relax_opt_call
1249 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
));
1250 static bfd_boolean elf64_alpha_relax_got_load
1251 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1252 Elf_Internal_Rela
*irel
, unsigned long));
1253 static bfd_boolean elf64_alpha_relax_gprelhilo
1254 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1255 Elf_Internal_Rela
*irel
, bfd_boolean
));
1256 static bfd_boolean elf64_alpha_relax_tls_get_addr
1257 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1258 Elf_Internal_Rela
*irel
, bfd_boolean
));
1259 static struct elf_link_tls_segment
*elf64_alpha_relax_find_tls_segment
1260 PARAMS((struct alpha_relax_info
*, struct elf_link_tls_segment
*));
1261 static bfd_boolean elf64_alpha_relax_section
1262 PARAMS((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
1263 bfd_boolean
*again
));
1265 static Elf_Internal_Rela
*
1266 elf64_alpha_find_reloc_at_ofs (rel
, relend
, offset
, type
)
1267 Elf_Internal_Rela
*rel
, *relend
;
1271 while (rel
< relend
)
1273 if (rel
->r_offset
== offset
1274 && ELF64_R_TYPE (rel
->r_info
) == (unsigned int) type
)
1282 elf64_alpha_relax_with_lituse (info
, symval
, irel
)
1283 struct alpha_relax_info
*info
;
1285 Elf_Internal_Rela
*irel
;
1287 Elf_Internal_Rela
*urel
, *irelend
= info
->relend
;
1288 int flags
, count
, i
;
1289 bfd_signed_vma disp
;
1292 bfd_boolean lit_reused
= FALSE
;
1293 bfd_boolean all_optimized
= TRUE
;
1294 unsigned int lit_insn
;
1296 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1297 if (lit_insn
>> 26 != OP_LDQ
)
1299 ((*_bfd_error_handler
)
1300 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1301 bfd_archive_filename (info
->abfd
), info
->sec
->name
,
1302 (unsigned long) irel
->r_offset
));
1306 /* Can't relax dynamic symbols. */
1307 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
1310 /* Summarize how this particular LITERAL is used. */
1311 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
1313 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
1315 if (urel
->r_addend
<= 3)
1316 flags
|= 1 << urel
->r_addend
;
1319 /* A little preparation for the loop... */
1320 disp
= symval
- info
->gp
;
1322 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
1326 bfd_signed_vma xdisp
;
1328 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
1330 switch (urel
->r_addend
)
1332 case LITUSE_ALPHA_ADDR
:
1334 /* This type is really just a placeholder to note that all
1335 uses cannot be optimized, but to still allow some. */
1336 all_optimized
= FALSE
;
1339 case LITUSE_ALPHA_BASE
:
1340 /* We can always optimize 16-bit displacements. */
1342 /* Extract the displacement from the instruction, sign-extending
1343 it if necessary, then test whether it is within 16 or 32 bits
1344 displacement from GP. */
1345 insn_disp
= insn
& 0x0000ffff;
1346 if (insn_disp
& 0x8000)
1347 insn_disp
|= ~0xffff; /* Negative: sign-extend. */
1349 xdisp
= disp
+ insn_disp
;
1350 fits16
= (xdisp
>= - (bfd_signed_vma
) 0x8000 && xdisp
< 0x8000);
1351 fits32
= (xdisp
>= - (bfd_signed_vma
) 0x80000000
1352 && xdisp
< 0x7fff8000);
1356 /* Take the op code and dest from this insn, take the base
1357 register from the literal insn. Leave the offset alone. */
1358 insn
= (insn
& 0xffe0ffff) | (lit_insn
& 0x001f0000);
1359 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1361 urel
->r_addend
= irel
->r_addend
;
1362 info
->changed_relocs
= TRUE
;
1364 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1365 info
->contents
+ urel
->r_offset
);
1366 info
->changed_contents
= TRUE
;
1369 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1370 else if (fits32
&& !(flags
& ~6))
1372 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
1374 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1376 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
1377 bfd_put_32 (info
->abfd
, (bfd_vma
) lit_insn
,
1378 info
->contents
+ irel
->r_offset
);
1380 info
->changed_contents
= TRUE
;
1382 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1384 urel
->r_addend
= irel
->r_addend
;
1385 info
->changed_relocs
= TRUE
;
1388 all_optimized
= FALSE
;
1391 case LITUSE_ALPHA_BYTOFF
:
1392 /* We can always optimize byte instructions. */
1394 /* FIXME: sanity check the insn for byte op. Check that the
1395 literal dest reg is indeed Rb in the byte insn. */
1397 insn
&= ~ (unsigned) 0x001ff000;
1398 insn
|= ((symval
& 7) << 13) | 0x1000;
1400 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1402 info
->changed_relocs
= TRUE
;
1404 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1405 info
->contents
+ urel
->r_offset
);
1406 info
->changed_contents
= TRUE
;
1409 case LITUSE_ALPHA_JSR
:
1410 case LITUSE_ALPHA_TLSGD
:
1411 case LITUSE_ALPHA_TLSLDM
:
1413 bfd_vma optdest
, org
;
1414 bfd_signed_vma odisp
;
1416 /* If not zero, place to jump without needing pv. */
1417 optdest
= elf64_alpha_relax_opt_call (info
, symval
);
1418 org
= (info
->sec
->output_section
->vma
1419 + info
->sec
->output_offset
1420 + urel
->r_offset
+ 4);
1421 odisp
= (optdest
? optdest
: symval
) - org
;
1423 if (odisp
>= -0x400000 && odisp
< 0x400000)
1425 Elf_Internal_Rela
*xrel
;
1427 /* Preserve branch prediction call stack when possible. */
1428 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
1429 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
1431 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
1433 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1435 urel
->r_addend
= irel
->r_addend
;
1438 urel
->r_addend
+= optdest
- symval
;
1440 all_optimized
= FALSE
;
1442 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
1443 info
->contents
+ urel
->r_offset
);
1445 /* Kill any HINT reloc that might exist for this insn. */
1446 xrel
= (elf64_alpha_find_reloc_at_ofs
1447 (info
->relocs
, info
->relend
, urel
->r_offset
,
1450 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1452 info
->changed_contents
= TRUE
;
1453 info
->changed_relocs
= TRUE
;
1456 all_optimized
= FALSE
;
1458 /* Even if the target is not in range for a direct branch,
1459 if we share a GP, we can eliminate the gp reload. */
1462 Elf_Internal_Rela
*gpdisp
1463 = (elf64_alpha_find_reloc_at_ofs
1464 (info
->relocs
, irelend
, urel
->r_offset
+ 4,
1468 bfd_byte
*p_ldah
= info
->contents
+ gpdisp
->r_offset
;
1469 bfd_byte
*p_lda
= p_ldah
+ gpdisp
->r_addend
;
1470 unsigned int ldah
= bfd_get_32 (info
->abfd
, p_ldah
);
1471 unsigned int lda
= bfd_get_32 (info
->abfd
, p_lda
);
1473 /* Verify that the instruction is "ldah $29,0($26)".
1474 Consider a function that ends in a noreturn call,
1475 and that the next function begins with an ldgp,
1476 and that by accident there is no padding between.
1477 In that case the insn would use $27 as the base. */
1478 if (ldah
== 0x27ba0000 && lda
== 0x23bd0000)
1480 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_ldah
);
1481 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_lda
);
1483 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1484 info
->changed_contents
= TRUE
;
1485 info
->changed_relocs
= TRUE
;
1494 /* If all cases were optimized, we can reduce the use count on this
1495 got entry by one, possibly eliminating it. */
1498 if (--info
->gotent
->use_count
== 0)
1500 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
1501 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1503 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1506 /* If the literal instruction is no longer needed (it may have been
1507 reused. We can eliminate it. */
1508 /* ??? For now, I don't want to deal with compacting the section,
1509 so just nop it out. */
1512 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1513 info
->changed_relocs
= TRUE
;
1515 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
,
1516 info
->contents
+ irel
->r_offset
);
1517 info
->changed_contents
= TRUE
;
1525 elf64_alpha_relax_opt_call (info
, symval
)
1526 struct alpha_relax_info
*info
;
1529 /* If the function has the same gp, and we can identify that the
1530 function does not use its function pointer, we can eliminate the
1533 /* If the symbol is marked NOPV, we are being told the function never
1534 needs its procedure value. */
1535 if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_NOPV
)
1538 /* If the symbol is marked STD_GP, we are being told the function does
1539 a normal ldgp in the first two words. */
1540 else if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_STD_GPLOAD
)
1543 /* Otherwise, we may be able to identify a GP load in the first two
1544 words, which we can then skip. */
1547 Elf_Internal_Rela
*tsec_relocs
, *tsec_relend
, *tsec_free
, *gpdisp
;
1550 /* Load the relocations from the section that the target symbol is in. */
1551 if (info
->sec
== info
->tsec
)
1553 tsec_relocs
= info
->relocs
;
1554 tsec_relend
= info
->relend
;
1559 tsec_relocs
= (_bfd_elf_link_read_relocs
1560 (info
->abfd
, info
->tsec
, (PTR
) NULL
,
1561 (Elf_Internal_Rela
*) NULL
,
1562 info
->link_info
->keep_memory
));
1563 if (tsec_relocs
== NULL
)
1565 tsec_relend
= tsec_relocs
+ info
->tsec
->reloc_count
;
1566 tsec_free
= (info
->link_info
->keep_memory
? NULL
: tsec_relocs
);
1569 /* Recover the symbol's offset within the section. */
1570 ofs
= (symval
- info
->tsec
->output_section
->vma
1571 - info
->tsec
->output_offset
);
1573 /* Look for a GPDISP reloc. */
1574 gpdisp
= (elf64_alpha_find_reloc_at_ofs
1575 (tsec_relocs
, tsec_relend
, ofs
, R_ALPHA_GPDISP
));
1577 if (!gpdisp
|| gpdisp
->r_addend
!= 4)
1587 /* We've now determined that we can skip an initial gp load. Verify
1588 that the call and the target use the same gp. */
1589 if (info
->link_info
->hash
->creator
!= info
->tsec
->owner
->xvec
1590 || info
->gotobj
!= alpha_elf_tdata (info
->tsec
->owner
)->gotobj
)
1597 elf64_alpha_relax_got_load (info
, symval
, irel
, r_type
)
1598 struct alpha_relax_info
*info
;
1600 Elf_Internal_Rela
*irel
;
1601 unsigned long r_type
;
1604 bfd_signed_vma disp
;
1606 /* Get the instruction. */
1607 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1609 if (insn
>> 26 != OP_LDQ
)
1611 reloc_howto_type
*howto
= elf64_alpha_howto_table
+ r_type
;
1612 ((*_bfd_error_handler
)
1613 ("%s: %s+0x%lx: warning: %s relocation against unexpected insn",
1614 bfd_archive_filename (info
->abfd
), info
->sec
->name
,
1615 (unsigned long) irel
->r_offset
, howto
->name
));
1619 /* Can't relax dynamic symbols. */
1620 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
1623 /* Can't use local-exec relocations in shared libraries. */
1624 if (r_type
== R_ALPHA_GOTTPREL
&& info
->link_info
->shared
)
1627 if (r_type
== R_ALPHA_LITERAL
)
1628 disp
= symval
- info
->gp
;
1631 bfd_vma dtp_base
, tp_base
;
1633 BFD_ASSERT (info
->tls_segment
!= NULL
);
1634 dtp_base
= alpha_get_dtprel_base (info
->tls_segment
);
1635 tp_base
= alpha_get_tprel_base (info
->tls_segment
);
1636 disp
= symval
- (r_type
== R_ALPHA_GOTDTPREL
? dtp_base
: tp_base
);
1639 if (disp
< -0x8000 || disp
>= 0x8000)
1642 /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading
1643 a constant, so force the base register to be $31. */
1644 if (r_type
== R_ALPHA_LITERAL
)
1645 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
1647 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
1648 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, info
->contents
+ irel
->r_offset
);
1649 info
->changed_contents
= TRUE
;
1651 /* Reduce the use count on this got entry by one, possibly
1653 if (--info
->gotent
->use_count
== 0)
1655 int sz
= alpha_got_entry_size (r_type
);
1656 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1658 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1661 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
1664 case R_ALPHA_LITERAL
:
1665 r_type
= R_ALPHA_GPREL16
;
1667 case R_ALPHA_GOTDTPREL
:
1668 r_type
= R_ALPHA_DTPREL16
;
1670 case R_ALPHA_GOTTPREL
:
1671 r_type
= R_ALPHA_TPREL16
;
1678 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), r_type
);
1679 info
->changed_relocs
= TRUE
;
1681 /* ??? Search forward through this basic block looking for insns
1682 that use the target register. Stop after an insn modifying the
1683 register is seen, or after a branch or call.
1685 Any such memory load insn may be substituted by a load directly
1686 off the GP. This allows the memory load insn to be issued before
1687 the calculated GP register would otherwise be ready.
1689 Any such jsr insn can be replaced by a bsr if it is in range.
1691 This would mean that we'd have to _add_ relocations, the pain of
1692 which gives one pause. */
1698 elf64_alpha_relax_gprelhilo (info
, symval
, irel
, hi
)
1699 struct alpha_relax_info
*info
;
1701 Elf_Internal_Rela
*irel
;
1705 bfd_signed_vma disp
;
1706 bfd_byte
*pos
= info
->contents
+ irel
->r_offset
;
1708 /* ??? This assumes that the compiler doesn't render
1712 ldah t, array(gp) !gprelhigh
1714 ldq r, array(t) !gprellow
1716 which would indeed be the most efficient way to implement this. */
1720 disp
= symval
- info
->gp
;
1721 if (disp
< -0x8000 || disp
>= 0x8000)
1726 /* Nop out the high instruction. */
1728 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
);
1729 info
->changed_contents
= TRUE
;
1731 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1733 info
->changed_relocs
= TRUE
;
1737 /* Adjust the low instruction to reference GP directly. */
1739 insn
= bfd_get_32 (info
->abfd
, pos
);
1740 insn
= (insn
& 0xffe00000) | (29 << 16);
1741 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
);
1742 info
->changed_contents
= TRUE
;
1744 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1746 info
->changed_relocs
= TRUE
;
1753 elf64_alpha_relax_tls_get_addr (info
, symval
, irel
, is_gd
)
1754 struct alpha_relax_info
*info
;
1756 Elf_Internal_Rela
*irel
;
1761 Elf_Internal_Rela
*gpdisp
, *hint
;
1762 bfd_boolean dynamic
, use_gottprel
, pos1_unusable
;
1763 unsigned long new_symndx
;
1765 dynamic
= alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
);
1767 /* If a TLS symbol is accessed using IE at least once, there is no point
1768 to use dynamic model for it. */
1769 if (is_gd
&& info
->h
&& (info
->h
->flags
& ALPHA_ELF_LINK_HASH_TLS_IE
))
1772 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
1773 then we might as well relax to IE. */
1774 else if (info
->link_info
->shared
&& !dynamic
1775 && (info
->link_info
->flags
& DF_STATIC_TLS
))
1778 /* Otherwise we must be building an executable to do anything. */
1779 else if (info
->link_info
->shared
)
1782 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
1783 the matching LITUSE_TLS relocations. */
1784 if (irel
+ 2 >= info
->relend
)
1786 if (ELF64_R_TYPE (irel
[1].r_info
) != R_ALPHA_LITERAL
1787 || ELF64_R_TYPE (irel
[2].r_info
) != R_ALPHA_LITUSE
1788 || irel
[2].r_addend
!= (is_gd
? LITUSE_ALPHA_TLSGD
: LITUSE_ALPHA_TLSLDM
))
1791 /* There must be a GPDISP relocation positioned immediately after the
1792 LITUSE relocation. */
1793 gpdisp
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
1794 irel
[2].r_offset
+ 4, R_ALPHA_GPDISP
);
1798 pos
[0] = info
->contents
+ irel
[0].r_offset
;
1799 pos
[1] = info
->contents
+ irel
[1].r_offset
;
1800 pos
[2] = info
->contents
+ irel
[2].r_offset
;
1801 pos
[3] = info
->contents
+ gpdisp
->r_offset
;
1802 pos
[4] = pos
[3] + gpdisp
->r_addend
;
1803 pos1_unusable
= FALSE
;
1805 /* Generally, the positions are not allowed to be out of order, lest the
1806 modified insn sequence have different register lifetimes. We can make
1807 an exception when pos 1 is adjacent to pos 0. */
1808 if (pos
[1] + 4 == pos
[0])
1810 bfd_byte
*tmp
= pos
[0];
1814 else if (pos
[1] < pos
[0])
1815 pos1_unusable
= TRUE
;
1816 if (pos
[1] >= pos
[2] || pos
[2] >= pos
[3])
1819 /* Reduce the use count on the LITERAL relocation. Do this before we
1820 smash the symndx when we adjust the relocations below. */
1822 struct alpha_elf_got_entry
*lit_gotent
;
1823 struct alpha_elf_link_hash_entry
*lit_h
;
1826 BFD_ASSERT (ELF64_R_SYM (irel
[1].r_info
) >= info
->symtab_hdr
->sh_info
);
1827 indx
= ELF64_R_SYM (irel
[1].r_info
) - info
->symtab_hdr
->sh_info
;
1828 lit_h
= alpha_elf_sym_hashes (info
->abfd
)[indx
];
1830 while (lit_h
->root
.root
.type
== bfd_link_hash_indirect
1831 || lit_h
->root
.root
.type
== bfd_link_hash_warning
)
1832 lit_h
= (struct alpha_elf_link_hash_entry
*) lit_h
->root
.root
.u
.i
.link
;
1834 for (lit_gotent
= lit_h
->got_entries
; lit_gotent
;
1835 lit_gotent
= lit_gotent
->next
)
1836 if (lit_gotent
->gotobj
== info
->gotobj
1837 && lit_gotent
->reloc_type
== R_ALPHA_LITERAL
1838 && lit_gotent
->addend
== irel
[1].r_addend
)
1840 BFD_ASSERT (lit_gotent
);
1842 if (--lit_gotent
->use_count
== 0)
1844 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
1845 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1851 lda $16,x($gp) !tlsgd!1
1852 ldq $27,__tls_get_addr($gp) !literal!1
1853 jsr $26,($27)__tls_get_addr !lituse_tlsgd!1
1854 ldah $29,0($26) !gpdisp!2
1855 lda $29,0($29) !gpdisp!2
1857 ldq $16,x($gp) !gottprel
1862 or the first pair to
1863 lda $16,x($gp) !tprel
1866 ldah $16,x($gp) !tprelhi
1867 lda $16,x($16) !tprello
1871 use_gottprel
= FALSE
;
1872 new_symndx
= is_gd
? ELF64_R_SYM (irel
->r_info
) : 0;
1873 switch (!dynamic
&& !info
->link_info
->shared
)
1878 bfd_signed_vma disp
;
1880 BFD_ASSERT (info
->tls_segment
!= NULL
);
1881 tp_base
= alpha_get_tprel_base (info
->tls_segment
);
1882 disp
= symval
- tp_base
;
1884 if (disp
>= -0x8000 && disp
< 0x8000)
1886 insn
= (OP_LDA
<< 26) | (16 << 21) | (31 << 16);
1887 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1888 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
1890 irel
[0].r_offset
= pos
[0] - info
->contents
;
1891 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPREL16
);
1892 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1895 else if (disp
>= -(bfd_signed_vma
) 0x80000000
1896 && disp
< (bfd_signed_vma
) 0x7fff8000
1899 insn
= (OP_LDAH
<< 26) | (16 << 21) | (31 << 16);
1900 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1901 insn
= (OP_LDA
<< 26) | (16 << 21) | (16 << 16);
1902 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[1]);
1904 irel
[0].r_offset
= pos
[0] - info
->contents
;
1905 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELHI
);
1906 irel
[1].r_offset
= pos
[1] - info
->contents
;
1907 irel
[1].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELLO
);
1914 use_gottprel
= TRUE
;
1916 insn
= (OP_LDQ
<< 26) | (16 << 21) | (29 << 16);
1917 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
1918 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
1920 irel
[0].r_offset
= pos
[0] - info
->contents
;
1921 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_GOTTPREL
);
1922 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1926 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_RDUNIQ
, pos
[2]);
1928 insn
= INSN_ADDQ
| (16 << 21) | (0 << 16) | (0 << 0);
1929 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[3]);
1931 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[4]);
1933 irel
[2].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1934 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1936 hint
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
1937 irel
[2].r_offset
, R_ALPHA_HINT
);
1939 hint
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1941 info
->changed_contents
= TRUE
;
1942 info
->changed_relocs
= TRUE
;
1944 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
1945 if (--info
->gotent
->use_count
== 0)
1947 int sz
= alpha_got_entry_size (info
->gotent
->reloc_type
);
1948 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
1950 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
1953 /* If we've switched to a GOTTPREL relocation, increment the reference
1954 count on that got entry. */
1957 struct alpha_elf_got_entry
*tprel_gotent
;
1959 for (tprel_gotent
= *info
->first_gotent
; tprel_gotent
;
1960 tprel_gotent
= tprel_gotent
->next
)
1961 if (tprel_gotent
->gotobj
== info
->gotobj
1962 && tprel_gotent
->reloc_type
== R_ALPHA_GOTTPREL
1963 && tprel_gotent
->addend
== irel
->r_addend
)
1966 tprel_gotent
->use_count
++;
1969 if (info
->gotent
->use_count
== 0)
1970 tprel_gotent
= info
->gotent
;
1973 tprel_gotent
= (struct alpha_elf_got_entry
*)
1974 bfd_alloc (info
->abfd
, sizeof (struct alpha_elf_got_entry
));
1978 tprel_gotent
->next
= *info
->first_gotent
;
1979 *info
->first_gotent
= tprel_gotent
;
1981 tprel_gotent
->gotobj
= info
->gotobj
;
1982 tprel_gotent
->addend
= irel
->r_addend
;
1983 tprel_gotent
->got_offset
= -1;
1984 tprel_gotent
->reloc_done
= 0;
1985 tprel_gotent
->reloc_xlated
= 0;
1988 tprel_gotent
->use_count
= 1;
1989 tprel_gotent
->reloc_type
= R_ALPHA_GOTTPREL
;
1996 static struct elf_link_tls_segment
*
1997 elf64_alpha_relax_find_tls_segment (info
, seg
)
1998 struct alpha_relax_info
*info
;
1999 struct elf_link_tls_segment
*seg
;
2001 bfd
*output_bfd
= info
->sec
->output_section
->owner
;
2006 for (o
= output_bfd
->sections
; o
; o
= o
->next
)
2007 if ((o
->flags
& SEC_THREAD_LOCAL
) != 0
2008 && (o
->flags
& SEC_LOAD
) != 0)
2020 if (bfd_get_section_alignment (output_bfd
, o
) > align
)
2021 align
= bfd_get_section_alignment (output_bfd
, o
);
2023 size
= o
->_raw_size
;
2024 if (size
== 0 && (o
->flags
& SEC_HAS_CONTENTS
) == 0)
2026 struct bfd_link_order
*lo
;
2027 for (lo
= o
->link_order_head
; lo
; lo
= lo
->next
)
2028 if (size
< lo
->offset
+ lo
->size
)
2029 size
= lo
->offset
+ lo
->size
;
2031 end
= o
->vma
+ size
;
2034 while (o
&& (o
->flags
& SEC_THREAD_LOCAL
));
2037 seg
->size
= end
- base
;
2044 elf64_alpha_relax_section (abfd
, sec
, link_info
, again
)
2047 struct bfd_link_info
*link_info
;
2050 Elf_Internal_Shdr
*symtab_hdr
;
2051 Elf_Internal_Rela
*internal_relocs
;
2052 Elf_Internal_Rela
*irel
, *irelend
;
2053 Elf_Internal_Sym
*isymbuf
= NULL
;
2054 struct alpha_elf_got_entry
**local_got_entries
;
2055 struct alpha_relax_info info
;
2056 struct elf_link_tls_segment tls_segment
;
2058 /* We are not currently changing any sizes, so only one pass. */
2061 if (link_info
->relocateable
2062 || (sec
->flags
& SEC_RELOC
) == 0
2063 || sec
->reloc_count
== 0)
2066 /* If this is the first time we have been called for this section,
2067 initialize the cooked size. */
2068 if (sec
->_cooked_size
== 0)
2069 sec
->_cooked_size
= sec
->_raw_size
;
2071 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2072 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2074 /* Load the relocations for this section. */
2075 internal_relocs
= (_bfd_elf_link_read_relocs
2076 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2077 link_info
->keep_memory
));
2078 if (internal_relocs
== NULL
)
2081 memset(&info
, 0, sizeof (info
));
2084 info
.link_info
= link_info
;
2085 info
.symtab_hdr
= symtab_hdr
;
2086 info
.relocs
= internal_relocs
;
2087 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
2089 /* Find the GP for this object. Do not store the result back via
2090 _bfd_set_gp_value, since this could change again before final. */
2091 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
2094 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
2095 info
.gp
= (sgot
->output_section
->vma
2096 + sgot
->output_offset
2100 /* Get the section contents. */
2101 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2102 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
2105 info
.contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2106 if (info
.contents
== NULL
)
2109 if (! bfd_get_section_contents (abfd
, sec
, info
.contents
,
2110 (file_ptr
) 0, sec
->_raw_size
))
2114 /* Compute the TLS segment information. The version normally found in
2115 elf_hash_table (link_info)->tls_segment isn't built until final_link.
2116 ??? Probably should look into extracting this into a common function. */
2117 info
.tls_segment
= elf64_alpha_relax_find_tls_segment (&info
, &tls_segment
);
2119 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2122 struct alpha_elf_got_entry
*gotent
;
2123 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
2124 unsigned long r_symndx
= ELF64_R_SYM (irel
->r_info
);
2126 /* Early exit for unhandled or unrelaxable relocations. */
2129 case R_ALPHA_LITERAL
:
2130 case R_ALPHA_GPRELHIGH
:
2131 case R_ALPHA_GPRELLOW
:
2132 case R_ALPHA_GOTDTPREL
:
2133 case R_ALPHA_GOTTPREL
:
2137 case R_ALPHA_TLSLDM
:
2138 /* The symbol for a TLSLDM reloc is ignored. Collapse the
2139 reloc to the 0 symbol so that they all match. */
2147 /* Get the value of the symbol referred to by the reloc. */
2148 if (r_symndx
< symtab_hdr
->sh_info
)
2150 /* A local symbol. */
2151 Elf_Internal_Sym
*isym
;
2153 /* Read this BFD's local symbols. */
2154 if (isymbuf
== NULL
)
2156 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2157 if (isymbuf
== NULL
)
2158 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2159 symtab_hdr
->sh_info
, 0,
2161 if (isymbuf
== NULL
)
2165 isym
= isymbuf
+ r_symndx
;
2167 /* Given the symbol for a TLSLDM reloc is ignored, this also
2168 means forcing the symbol value to the tp base. */
2169 if (r_type
== R_ALPHA_TLSLDM
)
2171 info
.tsec
= bfd_abs_section_ptr
;
2172 symval
= alpha_get_tprel_base (info
.tls_segment
);
2176 symval
= isym
->st_value
;
2177 if (isym
->st_shndx
== SHN_UNDEF
)
2179 else if (isym
->st_shndx
== SHN_ABS
)
2180 info
.tsec
= bfd_abs_section_ptr
;
2181 else if (isym
->st_shndx
== SHN_COMMON
)
2182 info
.tsec
= bfd_com_section_ptr
;
2184 info
.tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2188 info
.other
= isym
->st_other
;
2189 if (local_got_entries
)
2190 info
.first_gotent
= &local_got_entries
[r_symndx
];
2193 info
.first_gotent
= &info
.gotent
;
2200 struct alpha_elf_link_hash_entry
*h
;
2202 indx
= r_symndx
- symtab_hdr
->sh_info
;
2203 h
= alpha_elf_sym_hashes (abfd
)[indx
];
2204 BFD_ASSERT (h
!= NULL
);
2206 while (h
->root
.root
.type
== bfd_link_hash_indirect
2207 || h
->root
.root
.type
== bfd_link_hash_warning
)
2208 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2210 /* If the symbol is undefined, we can't do anything with it. */
2211 if (h
->root
.root
.type
== bfd_link_hash_undefweak
2212 || h
->root
.root
.type
== bfd_link_hash_undefined
)
2215 /* If the symbol isn't defined in the current module, again
2216 we can't do anything. */
2217 if (!(h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2219 /* Except for TLSGD relocs, which can sometimes be
2220 relaxed to GOTTPREL relocs. */
2221 if (r_type
!= R_ALPHA_TLSGD
)
2223 info
.tsec
= bfd_abs_section_ptr
;
2228 info
.tsec
= h
->root
.root
.u
.def
.section
;
2229 symval
= h
->root
.root
.u
.def
.value
;
2233 info
.other
= h
->root
.other
;
2234 info
.first_gotent
= &h
->got_entries
;
2237 /* Search for the got entry to be used by this relocation. */
2238 for (gotent
= *info
.first_gotent
; gotent
; gotent
= gotent
->next
)
2239 if (gotent
->gotobj
== info
.gotobj
2240 && gotent
->reloc_type
== r_type
2241 && gotent
->addend
== irel
->r_addend
)
2243 info
.gotent
= gotent
;
2245 symval
+= info
.tsec
->output_section
->vma
+ info
.tsec
->output_offset
;
2246 symval
+= irel
->r_addend
;
2250 case R_ALPHA_LITERAL
:
2251 BFD_ASSERT(info
.gotent
!= NULL
);
2253 /* If there exist LITUSE relocations immediately following, this
2254 opens up all sorts of interesting optimizations, because we
2255 now know every location that this address load is used. */
2256 if (irel
+1 < irelend
2257 && ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
2259 if (!elf64_alpha_relax_with_lituse (&info
, symval
, irel
))
2264 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
2269 case R_ALPHA_GPRELHIGH
:
2270 case R_ALPHA_GPRELLOW
:
2271 if (!elf64_alpha_relax_gprelhilo (&info
, symval
, irel
,
2272 r_type
== R_ALPHA_GPRELHIGH
))
2276 case R_ALPHA_GOTDTPREL
:
2277 case R_ALPHA_GOTTPREL
:
2278 BFD_ASSERT(info
.gotent
!= NULL
);
2279 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
2284 case R_ALPHA_TLSLDM
:
2285 BFD_ASSERT(info
.gotent
!= NULL
);
2286 if (!elf64_alpha_relax_tls_get_addr (&info
, symval
, irel
,
2287 r_type
== R_ALPHA_TLSGD
))
2293 if (!elf64_alpha_size_plt_section (link_info
))
2295 if (!elf64_alpha_size_got_sections (link_info
))
2297 if (!elf64_alpha_size_rela_got_section (link_info
))
2301 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2303 if (!link_info
->keep_memory
)
2307 /* Cache the symbols for elf_link_input_bfd. */
2308 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2312 if (info
.contents
!= NULL
2313 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
2315 if (!info
.changed_contents
&& !link_info
->keep_memory
)
2316 free (info
.contents
);
2319 /* Cache the section contents for elf_link_input_bfd. */
2320 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
2324 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
2326 if (!info
.changed_relocs
)
2327 free (internal_relocs
);
2329 elf_section_data (sec
)->relocs
= internal_relocs
;
2332 *again
= info
.changed_contents
|| info
.changed_relocs
;
2338 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2340 if (info
.contents
!= NULL
2341 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
2342 free (info
.contents
);
2343 if (internal_relocs
!= NULL
2344 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2345 free (internal_relocs
);
2350 #define PLT_HEADER_SIZE 32
2351 #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */
2352 #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */
2353 #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */
2354 #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */
2356 #define PLT_ENTRY_SIZE 12
2357 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
2358 #define PLT_ENTRY_WORD2 0
2359 #define PLT_ENTRY_WORD3 0
2361 #define MAX_GOT_SIZE (64*1024)
2363 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
2365 /* Handle an Alpha specific section when reading an object file. This
2366 is called when elfcode.h finds a section with an unknown type.
2367 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
2371 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
2373 Elf_Internal_Shdr
*hdr
;
2378 /* There ought to be a place to keep ELF backend specific flags, but
2379 at the moment there isn't one. We just keep track of the
2380 sections by their name, instead. Fortunately, the ABI gives
2381 suggested names for all the MIPS specific sections, so we will
2382 probably get away with this. */
2383 switch (hdr
->sh_type
)
2385 case SHT_ALPHA_DEBUG
:
2386 if (strcmp (name
, ".mdebug") != 0)
2393 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2395 newsect
= hdr
->bfd_section
;
2397 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
2399 if (! bfd_set_section_flags (abfd
, newsect
,
2400 (bfd_get_section_flags (abfd
, newsect
)
2408 /* Convert Alpha specific section flags to bfd internal section flags. */
2411 elf64_alpha_section_flags (flags
, hdr
)
2413 Elf_Internal_Shdr
*hdr
;
2415 if (hdr
->sh_flags
& SHF_ALPHA_GPREL
)
2416 *flags
|= SEC_SMALL_DATA
;
2421 /* Set the correct type for an Alpha ELF section. We do this by the
2422 section name, which is a hack, but ought to work. */
2425 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
2427 Elf_Internal_Shdr
*hdr
;
2430 register const char *name
;
2432 name
= bfd_get_section_name (abfd
, sec
);
2434 if (strcmp (name
, ".mdebug") == 0)
2436 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
2437 /* In a shared object on Irix 5.3, the .mdebug section has an
2438 entsize of 0. FIXME: Does this matter? */
2439 if ((abfd
->flags
& DYNAMIC
) != 0 )
2440 hdr
->sh_entsize
= 0;
2442 hdr
->sh_entsize
= 1;
2444 else if ((sec
->flags
& SEC_SMALL_DATA
)
2445 || strcmp (name
, ".sdata") == 0
2446 || strcmp (name
, ".sbss") == 0
2447 || strcmp (name
, ".lit4") == 0
2448 || strcmp (name
, ".lit8") == 0)
2449 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
2454 /* Hook called by the linker routine which adds symbols from an object
2455 file. We use it to put .comm items in .sbss, and not .bss. */
2458 elf64_alpha_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2460 struct bfd_link_info
*info
;
2461 const Elf_Internal_Sym
*sym
;
2462 const char **namep ATTRIBUTE_UNUSED
;
2463 flagword
*flagsp ATTRIBUTE_UNUSED
;
2467 if (sym
->st_shndx
== SHN_COMMON
2468 && !info
->relocateable
2469 && sym
->st_size
<= elf_gp_size (abfd
))
2471 /* Common symbols less than or equal to -G nn bytes are
2472 automatically put into .sbss. */
2474 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
2478 scomm
= bfd_make_section (abfd
, ".scommon");
2480 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
2482 | SEC_LINKER_CREATED
)))
2487 *valp
= sym
->st_size
;
2493 /* Create the .got section. */
2496 elf64_alpha_create_got_section(abfd
, info
)
2498 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2502 if (bfd_get_section_by_name (abfd
, ".got"))
2505 s
= bfd_make_section (abfd
, ".got");
2507 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2510 | SEC_LINKER_CREATED
))
2511 || !bfd_set_section_alignment (abfd
, s
, 3))
2514 alpha_elf_tdata (abfd
)->got
= s
;
2519 /* Create all the dynamic sections. */
2522 elf64_alpha_create_dynamic_sections (abfd
, info
)
2524 struct bfd_link_info
*info
;
2527 struct elf_link_hash_entry
*h
;
2528 struct bfd_link_hash_entry
*bh
;
2530 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
2532 s
= bfd_make_section (abfd
, ".plt");
2534 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2537 | SEC_LINKER_CREATED
2539 || ! bfd_set_section_alignment (abfd
, s
, 3))
2542 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
2545 if (! (_bfd_generic_link_add_one_symbol
2546 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
2547 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
2548 get_elf_backend_data (abfd
)->collect
, &bh
)))
2550 h
= (struct elf_link_hash_entry
*) bh
;
2551 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2552 h
->type
= STT_OBJECT
;
2555 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2558 s
= bfd_make_section (abfd
, ".rela.plt");
2560 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2563 | SEC_LINKER_CREATED
2565 || ! bfd_set_section_alignment (abfd
, s
, 3))
2568 /* We may or may not have created a .got section for this object, but
2569 we definitely havn't done the rest of the work. */
2571 if (!elf64_alpha_create_got_section (abfd
, info
))
2574 s
= bfd_make_section(abfd
, ".rela.got");
2576 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
2579 | SEC_LINKER_CREATED
2581 || !bfd_set_section_alignment (abfd
, s
, 3))
2584 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
2585 dynobj's .got section. We don't do this in the linker script
2586 because we don't want to define the symbol if we are not creating
2587 a global offset table. */
2589 if (!(_bfd_generic_link_add_one_symbol
2590 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
,
2591 alpha_elf_tdata(abfd
)->got
, (bfd_vma
) 0, (const char *) NULL
,
2592 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2594 h
= (struct elf_link_hash_entry
*) bh
;
2595 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2596 h
->type
= STT_OBJECT
;
2599 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2602 elf_hash_table (info
)->hgot
= h
;
2607 /* Read ECOFF debugging information from a .mdebug section into a
2608 ecoff_debug_info structure. */
2611 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
2614 struct ecoff_debug_info
*debug
;
2617 const struct ecoff_debug_swap
*swap
;
2618 char *ext_hdr
= NULL
;
2620 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2621 memset (debug
, 0, sizeof (*debug
));
2623 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
2624 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
2627 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
2628 swap
->external_hdr_size
))
2631 symhdr
= &debug
->symbolic_header
;
2632 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
2634 /* The symbolic header contains absolute file offsets and sizes to
2636 #define READ(ptr, offset, count, size, type) \
2637 if (symhdr->count == 0) \
2638 debug->ptr = NULL; \
2641 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
2642 debug->ptr = (type) bfd_malloc (amt); \
2643 if (debug->ptr == NULL) \
2644 goto error_return; \
2645 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
2646 || bfd_bread (debug->ptr, amt, abfd) != amt) \
2647 goto error_return; \
2650 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
2651 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
2652 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
2653 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
2654 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
2655 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
2657 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
2658 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2659 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2660 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2661 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2665 debug
->adjust
= NULL
;
2670 if (ext_hdr
!= NULL
)
2672 if (debug
->line
!= NULL
)
2674 if (debug
->external_dnr
!= NULL
)
2675 free (debug
->external_dnr
);
2676 if (debug
->external_pdr
!= NULL
)
2677 free (debug
->external_pdr
);
2678 if (debug
->external_sym
!= NULL
)
2679 free (debug
->external_sym
);
2680 if (debug
->external_opt
!= NULL
)
2681 free (debug
->external_opt
);
2682 if (debug
->external_aux
!= NULL
)
2683 free (debug
->external_aux
);
2684 if (debug
->ss
!= NULL
)
2686 if (debug
->ssext
!= NULL
)
2687 free (debug
->ssext
);
2688 if (debug
->external_fdr
!= NULL
)
2689 free (debug
->external_fdr
);
2690 if (debug
->external_rfd
!= NULL
)
2691 free (debug
->external_rfd
);
2692 if (debug
->external_ext
!= NULL
)
2693 free (debug
->external_ext
);
2697 /* Alpha ELF local labels start with '$'. */
2700 elf64_alpha_is_local_label_name (abfd
, name
)
2701 bfd
*abfd ATTRIBUTE_UNUSED
;
2704 return name
[0] == '$';
2707 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2708 routine in order to handle the ECOFF debugging information. We
2709 still call this mips_elf_find_line because of the slot
2710 find_line_info in elf_obj_tdata is declared that way. */
2712 struct mips_elf_find_line
2714 struct ecoff_debug_info d
;
2715 struct ecoff_find_line i
;
2719 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2720 functionname_ptr
, line_ptr
)
2725 const char **filename_ptr
;
2726 const char **functionname_ptr
;
2727 unsigned int *line_ptr
;
2731 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
2732 filename_ptr
, functionname_ptr
,
2734 &elf_tdata (abfd
)->dwarf2_find_line_info
))
2737 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2741 struct mips_elf_find_line
*fi
;
2742 const struct ecoff_debug_swap
* const swap
=
2743 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2745 /* If we are called during a link, alpha_elf_final_link may have
2746 cleared the SEC_HAS_CONTENTS field. We force it back on here
2747 if appropriate (which it normally will be). */
2748 origflags
= msec
->flags
;
2749 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2750 msec
->flags
|= SEC_HAS_CONTENTS
;
2752 fi
= elf_tdata (abfd
)->find_line_info
;
2755 bfd_size_type external_fdr_size
;
2758 struct fdr
*fdr_ptr
;
2759 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
2761 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
2764 msec
->flags
= origflags
;
2768 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
2770 msec
->flags
= origflags
;
2774 /* Swap in the FDR information. */
2775 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
2776 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
2777 if (fi
->d
.fdr
== NULL
)
2779 msec
->flags
= origflags
;
2782 external_fdr_size
= swap
->external_fdr_size
;
2783 fdr_ptr
= fi
->d
.fdr
;
2784 fraw_src
= (char *) fi
->d
.external_fdr
;
2785 fraw_end
= (fraw_src
2786 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2787 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2788 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2790 elf_tdata (abfd
)->find_line_info
= fi
;
2792 /* Note that we don't bother to ever free this information.
2793 find_nearest_line is either called all the time, as in
2794 objdump -l, so the information should be saved, or it is
2795 rarely called, as in ld error messages, so the memory
2796 wasted is unimportant. Still, it would probably be a
2797 good idea for free_cached_info to throw it away. */
2800 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2801 &fi
->i
, filename_ptr
, functionname_ptr
,
2804 msec
->flags
= origflags
;
2808 msec
->flags
= origflags
;
2811 /* Fall back on the generic ELF find_nearest_line routine. */
2813 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2814 filename_ptr
, functionname_ptr
,
2818 /* Structure used to pass information to alpha_elf_output_extsym. */
2823 struct bfd_link_info
*info
;
2824 struct ecoff_debug_info
*debug
;
2825 const struct ecoff_debug_swap
*swap
;
2830 elf64_alpha_output_extsym (h
, data
)
2831 struct alpha_elf_link_hash_entry
*h
;
2834 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2836 asection
*sec
, *output_section
;
2838 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2839 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2841 if (h
->root
.indx
== -2)
2843 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2844 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2845 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2846 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2848 else if (einfo
->info
->strip
== strip_all
2849 || (einfo
->info
->strip
== strip_some
2850 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2851 h
->root
.root
.root
.string
,
2852 FALSE
, FALSE
) == NULL
))
2860 if (h
->esym
.ifd
== -2)
2863 h
->esym
.cobol_main
= 0;
2864 h
->esym
.weakext
= 0;
2865 h
->esym
.reserved
= 0;
2866 h
->esym
.ifd
= ifdNil
;
2867 h
->esym
.asym
.value
= 0;
2868 h
->esym
.asym
.st
= stGlobal
;
2870 if (h
->root
.root
.type
!= bfd_link_hash_defined
2871 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2872 h
->esym
.asym
.sc
= scAbs
;
2877 sec
= h
->root
.root
.u
.def
.section
;
2878 output_section
= sec
->output_section
;
2880 /* When making a shared library and symbol h is the one from
2881 the another shared library, OUTPUT_SECTION may be null. */
2882 if (output_section
== NULL
)
2883 h
->esym
.asym
.sc
= scUndefined
;
2886 name
= bfd_section_name (output_section
->owner
, output_section
);
2888 if (strcmp (name
, ".text") == 0)
2889 h
->esym
.asym
.sc
= scText
;
2890 else if (strcmp (name
, ".data") == 0)
2891 h
->esym
.asym
.sc
= scData
;
2892 else if (strcmp (name
, ".sdata") == 0)
2893 h
->esym
.asym
.sc
= scSData
;
2894 else if (strcmp (name
, ".rodata") == 0
2895 || strcmp (name
, ".rdata") == 0)
2896 h
->esym
.asym
.sc
= scRData
;
2897 else if (strcmp (name
, ".bss") == 0)
2898 h
->esym
.asym
.sc
= scBss
;
2899 else if (strcmp (name
, ".sbss") == 0)
2900 h
->esym
.asym
.sc
= scSBss
;
2901 else if (strcmp (name
, ".init") == 0)
2902 h
->esym
.asym
.sc
= scInit
;
2903 else if (strcmp (name
, ".fini") == 0)
2904 h
->esym
.asym
.sc
= scFini
;
2906 h
->esym
.asym
.sc
= scAbs
;
2910 h
->esym
.asym
.reserved
= 0;
2911 h
->esym
.asym
.index
= indexNil
;
2914 if (h
->root
.root
.type
== bfd_link_hash_common
)
2915 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2916 else if (h
->root
.root
.type
== bfd_link_hash_defined
2917 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2919 if (h
->esym
.asym
.sc
== scCommon
)
2920 h
->esym
.asym
.sc
= scBss
;
2921 else if (h
->esym
.asym
.sc
== scSCommon
)
2922 h
->esym
.asym
.sc
= scSBss
;
2924 sec
= h
->root
.root
.u
.def
.section
;
2925 output_section
= sec
->output_section
;
2926 if (output_section
!= NULL
)
2927 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2928 + sec
->output_offset
2929 + output_section
->vma
);
2931 h
->esym
.asym
.value
= 0;
2933 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2935 /* Set type and value for a symbol with a function stub. */
2936 h
->esym
.asym
.st
= stProc
;
2937 sec
= bfd_get_section_by_name (einfo
->abfd
, ".plt");
2939 h
->esym
.asym
.value
= 0;
2942 output_section
= sec
->output_section
;
2943 if (output_section
!= NULL
)
2944 h
->esym
.asym
.value
= (h
->root
.plt
.offset
2945 + sec
->output_offset
2946 + output_section
->vma
);
2948 h
->esym
.asym
.value
= 0;
2952 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2953 h
->root
.root
.root
.string
,
2956 einfo
->failed
= TRUE
;
2963 /* Search for and possibly create a got entry. */
2965 static struct alpha_elf_got_entry
*
2966 get_got_entry (abfd
, h
, r_type
, r_symndx
, r_addend
)
2968 struct alpha_elf_link_hash_entry
*h
;
2969 unsigned long r_type
, r_symndx
;
2972 struct alpha_elf_got_entry
*gotent
;
2973 struct alpha_elf_got_entry
**slot
;
2976 slot
= &h
->got_entries
;
2979 /* This is a local .got entry -- record for merge. */
2981 struct alpha_elf_got_entry
**local_got_entries
;
2983 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2984 if (!local_got_entries
)
2987 Elf_Internal_Shdr
*symtab_hdr
;
2989 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
2990 size
= symtab_hdr
->sh_info
;
2991 size
*= sizeof (struct alpha_elf_got_entry
*);
2994 = (struct alpha_elf_got_entry
**) bfd_zalloc (abfd
, size
);
2995 if (!local_got_entries
)
2998 alpha_elf_tdata (abfd
)->local_got_entries
= local_got_entries
;
3001 slot
= &local_got_entries
[r_symndx
];
3004 for (gotent
= *slot
; gotent
; gotent
= gotent
->next
)
3005 if (gotent
->gotobj
== abfd
3006 && gotent
->reloc_type
== r_type
3007 && gotent
->addend
== r_addend
)
3015 amt
= sizeof (struct alpha_elf_got_entry
);
3016 gotent
= (struct alpha_elf_got_entry
*) bfd_alloc (abfd
, amt
);
3020 gotent
->gotobj
= abfd
;
3021 gotent
->addend
= r_addend
;
3022 gotent
->got_offset
= -1;
3023 gotent
->use_count
= 1;
3024 gotent
->reloc_type
= r_type
;
3025 gotent
->reloc_done
= 0;
3026 gotent
->reloc_xlated
= 0;
3028 gotent
->next
= *slot
;
3031 entry_size
= alpha_got_entry_size (r_type
);
3032 alpha_elf_tdata (abfd
)->total_got_size
+= entry_size
;
3034 alpha_elf_tdata(abfd
)->local_got_size
+= entry_size
;
3037 gotent
->use_count
+= 1;
3042 /* Handle dynamic relocations when doing an Alpha ELF link. */
3045 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
3047 struct bfd_link_info
*info
;
3049 const Elf_Internal_Rela
*relocs
;
3053 const char *rel_sec_name
;
3054 Elf_Internal_Shdr
*symtab_hdr
;
3055 struct alpha_elf_link_hash_entry
**sym_hashes
;
3056 const Elf_Internal_Rela
*rel
, *relend
;
3057 bfd_boolean got_created
;
3060 if (info
->relocateable
)
3063 dynobj
= elf_hash_table(info
)->dynobj
;
3065 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
3068 rel_sec_name
= NULL
;
3069 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
3070 sym_hashes
= alpha_elf_sym_hashes(abfd
);
3071 got_created
= FALSE
;
3073 relend
= relocs
+ sec
->reloc_count
;
3074 for (rel
= relocs
; rel
< relend
; ++rel
)
3082 unsigned long r_symndx
, r_type
;
3083 struct alpha_elf_link_hash_entry
*h
;
3084 unsigned int gotent_flags
;
3085 bfd_boolean maybe_dynamic
;
3089 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3090 if (r_symndx
< symtab_hdr
->sh_info
)
3094 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3096 while (h
->root
.root
.type
== bfd_link_hash_indirect
3097 || h
->root
.root
.type
== bfd_link_hash_warning
)
3098 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3100 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
3103 /* We can only get preliminary data on whether a symbol is
3104 locally or externally defined, as not all of the input files
3105 have yet been processed. Do something with what we know, as
3106 this may help reduce memory usage and processing time later. */
3107 maybe_dynamic
= FALSE
;
3108 if (h
&& ((info
->shared
3109 && (!info
->symbolic
|| info
->allow_shlib_undefined
))
3110 || ! (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
3111 || h
->root
.root
.type
== bfd_link_hash_defweak
))
3112 maybe_dynamic
= TRUE
;
3116 r_type
= ELF64_R_TYPE (rel
->r_info
);
3117 addend
= rel
->r_addend
;
3121 case R_ALPHA_LITERAL
:
3122 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3124 /* Remember how this literal is used from its LITUSEs.
3125 This will be important when it comes to decide if we can
3126 create a .plt entry for a function symbol. */
3127 while (++rel
< relend
&& ELF64_R_TYPE (rel
->r_info
) == R_ALPHA_LITUSE
)
3128 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 5)
3129 gotent_flags
|= 1 << rel
->r_addend
;
3132 /* No LITUSEs -- presumably the address is used somehow. */
3133 if (gotent_flags
== 0)
3134 gotent_flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
3137 case R_ALPHA_GPDISP
:
3138 case R_ALPHA_GPREL16
:
3139 case R_ALPHA_GPREL32
:
3140 case R_ALPHA_GPRELHIGH
:
3141 case R_ALPHA_GPRELLOW
:
3146 case R_ALPHA_REFLONG
:
3147 case R_ALPHA_REFQUAD
:
3148 if ((info
->shared
&& (sec
->flags
& SEC_ALLOC
)) || maybe_dynamic
)
3152 case R_ALPHA_TLSLDM
:
3153 /* The symbol for a TLSLDM reloc is ignored. Collapse the
3154 reloc to the 0 symbol so that they all match. */
3157 maybe_dynamic
= FALSE
;
3161 case R_ALPHA_GOTDTPREL
:
3162 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3165 case R_ALPHA_GOTTPREL
:
3166 need
= NEED_GOT
| NEED_GOT_ENTRY
;
3167 gotent_flags
= ALPHA_ELF_LINK_HASH_TLS_IE
;
3169 info
->flags
|= DF_STATIC_TLS
;
3172 case R_ALPHA_TPREL64
:
3173 if (info
->shared
|| maybe_dynamic
)
3176 info
->flags
|= DF_STATIC_TLS
;
3180 if (need
& NEED_GOT
)
3184 if (!elf64_alpha_create_got_section (abfd
, info
))
3187 /* Make sure the object's gotobj is set to itself so
3188 that we default to every object with its own .got.
3189 We'll merge .gots later once we've collected each
3191 alpha_elf_tdata(abfd
)->gotobj
= abfd
;
3197 if (need
& NEED_GOT_ENTRY
)
3199 struct alpha_elf_got_entry
*gotent
;
3201 gotent
= get_got_entry (abfd
, h
, r_type
, r_symndx
, addend
);
3207 gotent
->flags
|= gotent_flags
;
3210 gotent_flags
|= h
->flags
;
3211 h
->flags
= gotent_flags
;
3213 /* Make a guess as to whether a .plt entry is needed. */
3214 if ((gotent_flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
)
3215 && !(gotent_flags
& ~ALPHA_ELF_LINK_HASH_LU_FUNC
))
3216 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3218 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3223 if (need
& NEED_DYNREL
)
3225 if (rel_sec_name
== NULL
)
3227 rel_sec_name
= (bfd_elf_string_from_elf_section
3228 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
3229 elf_section_data(sec
)->rel_hdr
.sh_name
));
3230 if (rel_sec_name
== NULL
)
3233 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
3234 && strcmp (bfd_get_section_name (abfd
, sec
),
3235 rel_sec_name
+5) == 0);
3238 /* We need to create the section here now whether we eventually
3239 use it or not so that it gets mapped to an output section by
3240 the linker. If not used, we'll kill it in
3241 size_dynamic_sections. */
3244 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
3249 sreloc
= bfd_make_section (dynobj
, rel_sec_name
);
3250 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3251 | SEC_LINKER_CREATED
| SEC_READONLY
);
3252 if (sec
->flags
& SEC_ALLOC
)
3253 flags
|= SEC_ALLOC
| SEC_LOAD
;
3255 || !bfd_set_section_flags (dynobj
, sreloc
, flags
)
3256 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
3263 /* Since we havn't seen all of the input symbols yet, we
3264 don't know whether we'll actually need a dynamic relocation
3265 entry for this reloc. So make a record of it. Once we
3266 find out if this thing needs dynamic relocation we'll
3267 expand the relocation sections by the appropriate amount. */
3269 struct alpha_elf_reloc_entry
*rent
;
3271 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
3272 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
3277 amt
= sizeof (struct alpha_elf_reloc_entry
);
3278 rent
= (struct alpha_elf_reloc_entry
*) bfd_alloc (abfd
, amt
);
3282 rent
->srel
= sreloc
;
3283 rent
->rtype
= r_type
;
3285 rent
->reltext
= ((sec
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3286 == (SEC_READONLY
| SEC_ALLOC
));
3288 rent
->next
= h
->reloc_entries
;
3289 h
->reloc_entries
= rent
;
3294 else if (info
->shared
)
3296 /* If this is a shared library, and the section is to be
3297 loaded into memory, we need a RELATIVE reloc. */
3298 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
3299 if ((sec
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3300 == (SEC_READONLY
| SEC_ALLOC
))
3301 info
->flags
|= DF_TEXTREL
;
3309 /* Adjust a symbol defined by a dynamic object and referenced by a
3310 regular object. The current definition is in some section of the
3311 dynamic object, but we're not including those sections. We have to
3312 change the definition to something the rest of the link can
3316 elf64_alpha_adjust_dynamic_symbol (info
, h
)
3317 struct bfd_link_info
*info
;
3318 struct elf_link_hash_entry
*h
;
3322 struct alpha_elf_link_hash_entry
*ah
;
3324 dynobj
= elf_hash_table(info
)->dynobj
;
3325 ah
= (struct alpha_elf_link_hash_entry
*)h
;
3327 /* Now that we've seen all of the input symbols, finalize our decision
3328 about whether this symbol should get a .plt entry. */
3330 if (alpha_elf_dynamic_symbol_p (h
, info
)
3331 && ((h
->type
== STT_FUNC
3332 && !(ah
->flags
& ALPHA_ELF_LINK_HASH_LU_ADDR
))
3333 || (h
->type
== STT_NOTYPE
3334 && (ah
->flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
)
3335 && !(ah
->flags
& ~ALPHA_ELF_LINK_HASH_LU_FUNC
)))
3336 /* Don't prevent otherwise valid programs from linking by attempting
3337 to create a new .got entry somewhere. A Correct Solution would be
3338 to add a new .got section to a new object file and let it be merged
3339 somewhere later. But for now don't bother. */
3342 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3344 s
= bfd_get_section_by_name(dynobj
, ".plt");
3345 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
3348 /* The first bit of the .plt is reserved. */
3349 if (s
->_raw_size
== 0)
3350 s
->_raw_size
= PLT_HEADER_SIZE
;
3352 h
->plt
.offset
= s
->_raw_size
;
3353 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3355 /* If this symbol is not defined in a regular file, and we are not
3356 generating a shared library, then set the symbol to the location
3357 in the .plt. This is required to make function pointers compare
3358 equal between the normal executable and the shared library. */
3360 && h
->root
.type
!= bfd_link_hash_defweak
)
3362 ah
->plt_old_section
= h
->root
.u
.def
.section
;
3363 ah
->plt_old_value
= h
->root
.u
.def
.value
;
3364 ah
->flags
|= ALPHA_ELF_LINK_HASH_PLT_LOC
;
3365 h
->root
.u
.def
.section
= s
;
3366 h
->root
.u
.def
.value
= h
->plt
.offset
;
3369 /* We also need a JMP_SLOT entry in the .rela.plt section. */
3370 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3371 BFD_ASSERT (s
!= NULL
);
3372 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3377 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3379 /* If this is a weak symbol, and there is a real definition, the
3380 processor independent code will have arranged for us to see the
3381 real definition first, and we can just use the same value. */
3382 if (h
->weakdef
!= NULL
)
3384 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3385 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3386 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3387 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3391 /* This is a reference to a symbol defined by a dynamic object which
3392 is not a function. The Alpha, since it uses .got entries for all
3393 symbols even in regular objects, does not need the hackery of a
3394 .dynbss section and COPY dynamic relocations. */
3399 /* Symbol versioning can create new symbols, and make our old symbols
3400 indirect to the new ones. Consolidate the got and reloc information
3401 in these situations. */
3404 elf64_alpha_merge_ind_symbols (hi
, dummy
)
3405 struct alpha_elf_link_hash_entry
*hi
;
3406 PTR dummy ATTRIBUTE_UNUSED
;
3408 struct alpha_elf_link_hash_entry
*hs
;
3410 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
3414 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
3415 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
3417 /* Merge the flags. Whee. */
3419 hs
->flags
|= hi
->flags
;
3421 /* Merge the .got entries. Cannibalize the old symbol's list in
3422 doing so, since we don't need it anymore. */
3424 if (hs
->got_entries
== NULL
)
3425 hs
->got_entries
= hi
->got_entries
;
3428 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
3430 gsh
= hs
->got_entries
;
3431 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
3434 for (gs
= gsh
; gs
; gs
= gs
->next
)
3435 if (gi
->gotobj
== gs
->gotobj
3436 && gi
->reloc_type
== gs
->reloc_type
3437 && gi
->addend
== gs
->addend
)
3439 gi
->use_count
+= gs
->use_count
;
3442 gi
->next
= hs
->got_entries
;
3443 hs
->got_entries
= gi
;
3447 hi
->got_entries
= NULL
;
3449 /* And similar for the reloc entries. */
3451 if (hs
->reloc_entries
== NULL
)
3452 hs
->reloc_entries
= hi
->reloc_entries
;
3455 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
3457 rsh
= hs
->reloc_entries
;
3458 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
3461 for (rs
= rsh
; rs
; rs
= rs
->next
)
3462 if (ri
->rtype
== rs
->rtype
&& ri
->srel
== rs
->srel
)
3464 rs
->count
+= ri
->count
;
3467 ri
->next
= hs
->reloc_entries
;
3468 hs
->reloc_entries
= ri
;
3472 hi
->reloc_entries
= NULL
;
3477 /* Is it possible to merge two object file's .got tables? */
3480 elf64_alpha_can_merge_gots (a
, b
)
3483 int total
= alpha_elf_tdata (a
)->total_got_size
;
3486 /* Trivial quick fallout test. */
3487 if (total
+ alpha_elf_tdata (b
)->total_got_size
<= MAX_GOT_SIZE
)
3490 /* By their nature, local .got entries cannot be merged. */
3491 if ((total
+= alpha_elf_tdata (b
)->local_got_size
) > MAX_GOT_SIZE
)
3494 /* Failing the common trivial comparison, we must effectively
3495 perform the merge. Not actually performing the merge means that
3496 we don't have to store undo information in case we fail. */
3497 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
3499 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes (bsub
);
3500 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
3503 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
3504 for (i
= 0; i
< n
; ++i
)
3506 struct alpha_elf_got_entry
*ae
, *be
;
3507 struct alpha_elf_link_hash_entry
*h
;
3510 while (h
->root
.root
.type
== bfd_link_hash_indirect
3511 || h
->root
.root
.type
== bfd_link_hash_warning
)
3512 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3514 for (be
= h
->got_entries
; be
; be
= be
->next
)
3516 if (be
->use_count
== 0)
3518 if (be
->gotobj
!= b
)
3521 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
3523 && ae
->reloc_type
== be
->reloc_type
3524 && ae
->addend
== be
->addend
)
3527 total
+= alpha_got_entry_size (be
->reloc_type
);
3528 if (total
> MAX_GOT_SIZE
)
3538 /* Actually merge two .got tables. */
3541 elf64_alpha_merge_gots (a
, b
)
3544 int total
= alpha_elf_tdata (a
)->total_got_size
;
3547 /* Remember local expansion. */
3549 int e
= alpha_elf_tdata (b
)->local_got_size
;
3551 alpha_elf_tdata (a
)->local_got_size
+= e
;
3554 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
3556 struct alpha_elf_got_entry
**local_got_entries
;
3557 struct alpha_elf_link_hash_entry
**hashes
;
3558 Elf_Internal_Shdr
*symtab_hdr
;
3561 /* Let the local .got entries know they are part of a new subsegment. */
3562 local_got_entries
= alpha_elf_tdata (bsub
)->local_got_entries
;
3563 if (local_got_entries
)
3565 n
= elf_tdata (bsub
)->symtab_hdr
.sh_info
;
3566 for (i
= 0; i
< n
; ++i
)
3568 struct alpha_elf_got_entry
*ent
;
3569 for (ent
= local_got_entries
[i
]; ent
; ent
= ent
->next
)
3574 /* Merge the global .got entries. */
3575 hashes
= alpha_elf_sym_hashes (bsub
);
3576 symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
3578 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
3579 for (i
= 0; i
< n
; ++i
)
3581 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
3582 struct alpha_elf_link_hash_entry
*h
;
3585 while (h
->root
.root
.type
== bfd_link_hash_indirect
3586 || h
->root
.root
.type
== bfd_link_hash_warning
)
3587 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3589 start
= &h
->got_entries
;
3590 for (pbe
= start
, be
= *start
; be
; pbe
= &be
->next
, be
= be
->next
)
3592 if (be
->use_count
== 0)
3597 if (be
->gotobj
!= b
)
3600 for (ae
= *start
; ae
; ae
= ae
->next
)
3602 && ae
->reloc_type
== be
->reloc_type
3603 && ae
->addend
== be
->addend
)
3605 ae
->flags
|= be
->flags
;
3606 ae
->use_count
+= be
->use_count
;
3611 total
+= alpha_got_entry_size (be
->reloc_type
);
3617 alpha_elf_tdata (bsub
)->gotobj
= a
;
3619 alpha_elf_tdata (a
)->total_got_size
= total
;
3621 /* Merge the two in_got chains. */
3626 while ((next
= alpha_elf_tdata (bsub
)->in_got_link_next
) != NULL
)
3629 alpha_elf_tdata (bsub
)->in_got_link_next
= b
;
3633 /* Calculate the offsets for the got entries. */
3636 elf64_alpha_calc_got_offsets_for_symbol (h
, arg
)
3637 struct alpha_elf_link_hash_entry
*h
;
3638 PTR arg ATTRIBUTE_UNUSED
;
3640 struct alpha_elf_got_entry
*gotent
;
3642 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3643 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3645 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3646 if (gotent
->use_count
> 0)
3649 = &alpha_elf_tdata (gotent
->gotobj
)->got
->_raw_size
;
3651 gotent
->got_offset
= *plge
;
3652 *plge
+= alpha_got_entry_size (gotent
->reloc_type
);
3659 elf64_alpha_calc_got_offsets (info
)
3660 struct bfd_link_info
*info
;
3662 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
3664 /* First, zero out the .got sizes, as we may be recalculating the
3665 .got after optimizing it. */
3666 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3667 alpha_elf_tdata(i
)->got
->_raw_size
= 0;
3669 /* Next, fill in the offsets for all the global entries. */
3670 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3671 elf64_alpha_calc_got_offsets_for_symbol
,
3674 /* Finally, fill in the offsets for the local entries. */
3675 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3677 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->_raw_size
;
3680 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
3682 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
3685 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
3686 if (!local_got_entries
)
3689 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
3690 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
3691 if (gotent
->use_count
> 0)
3693 gotent
->got_offset
= got_offset
;
3694 got_offset
+= alpha_got_entry_size (gotent
->reloc_type
);
3698 alpha_elf_tdata(i
)->got
->_raw_size
= got_offset
;
3699 alpha_elf_tdata(i
)->got
->_cooked_size
= got_offset
;
3703 /* Constructs the gots. */
3706 elf64_alpha_size_got_sections (info
)
3707 struct bfd_link_info
*info
;
3709 bfd
*i
, *got_list
, *cur_got_obj
= NULL
;
3710 int something_changed
= 0;
3712 got_list
= alpha_elf_hash_table (info
)->got_list
;
3714 /* On the first time through, pretend we have an existing got list
3715 consisting of all of the input files. */
3716 if (got_list
== NULL
)
3718 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
3720 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
3721 if (this_got
== NULL
)
3724 /* We are assuming no merging has yet ocurred. */
3725 BFD_ASSERT (this_got
== i
);
3727 if (alpha_elf_tdata (this_got
)->total_got_size
> MAX_GOT_SIZE
)
3729 /* Yikes! A single object file has too many entries. */
3730 (*_bfd_error_handler
)
3731 (_("%s: .got subsegment exceeds 64K (size %d)"),
3732 bfd_archive_filename (i
),
3733 alpha_elf_tdata (this_got
)->total_got_size
);
3737 if (got_list
== NULL
)
3738 got_list
= this_got
;
3740 alpha_elf_tdata(cur_got_obj
)->got_link_next
= this_got
;
3741 cur_got_obj
= this_got
;
3744 /* Strange degenerate case of no got references. */
3745 if (got_list
== NULL
)
3748 alpha_elf_hash_table (info
)->got_list
= got_list
;
3750 /* Force got offsets to be recalculated. */
3751 something_changed
= 1;
3754 cur_got_obj
= got_list
;
3755 i
= alpha_elf_tdata(cur_got_obj
)->got_link_next
;
3758 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
3760 elf64_alpha_merge_gots (cur_got_obj
, i
);
3761 i
= alpha_elf_tdata(i
)->got_link_next
;
3762 alpha_elf_tdata(cur_got_obj
)->got_link_next
= i
;
3763 something_changed
= 1;
3768 i
= alpha_elf_tdata(i
)->got_link_next
;
3772 /* Once the gots have been merged, fill in the got offsets for
3773 everything therein. */
3774 if (1 || something_changed
)
3775 elf64_alpha_calc_got_offsets (info
);
3780 /* Called from relax_section to rebuild the PLT in light of
3781 potential changes in the function's status. */
3784 elf64_alpha_size_plt_section (info
)
3785 struct bfd_link_info
*info
;
3787 asection
*splt
, *spltrel
;
3788 unsigned long entries
;
3791 dynobj
= elf_hash_table(info
)->dynobj
;
3792 splt
= bfd_get_section_by_name(dynobj
, ".plt");
3796 splt
->_raw_size
= 0;
3798 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3799 elf64_alpha_size_plt_section_1
, splt
);
3801 splt
->_cooked_size
= splt
->_raw_size
;
3803 /* Every plt entry requires a JMP_SLOT relocation. */
3804 spltrel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3805 if (splt
->_raw_size
)
3806 entries
= (splt
->_raw_size
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3809 spltrel
->_raw_size
= entries
* sizeof (Elf64_External_Rela
);
3810 spltrel
->_cooked_size
= spltrel
->_raw_size
;
3816 elf64_alpha_size_plt_section_1 (h
, data
)
3817 struct alpha_elf_link_hash_entry
*h
;
3820 asection
*splt
= (asection
*) data
;
3821 struct alpha_elf_got_entry
*gotent
;
3823 /* If we didn't need an entry before, we still don't. */
3824 if (!(h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
))
3827 /* There must still be a LITERAL got entry for the function. */
3828 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3829 if (gotent
->reloc_type
== R_ALPHA_LITERAL
3830 && gotent
->use_count
> 0)
3833 /* If there is, reset the PLT offset. If not, there's no longer
3834 a need for the PLT entry. */
3837 if (splt
->_raw_size
== 0)
3838 splt
->_raw_size
= PLT_HEADER_SIZE
;
3839 h
->root
.plt
.offset
= splt
->_raw_size
;
3840 splt
->_raw_size
+= PLT_ENTRY_SIZE
;
3844 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3845 h
->root
.plt
.offset
= -1;
3847 /* Undo the definition frobbing begun in adjust_dynamic_symbol. */
3848 if (h
->flags
& ALPHA_ELF_LINK_HASH_PLT_LOC
)
3850 h
->root
.root
.u
.def
.section
= h
->plt_old_section
;
3851 h
->root
.root
.u
.def
.value
= h
->plt_old_value
;
3852 h
->flags
&= ~ALPHA_ELF_LINK_HASH_PLT_LOC
;
3860 elf64_alpha_always_size_sections (output_bfd
, info
)
3861 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3862 struct bfd_link_info
*info
;
3866 if (info
->relocateable
)
3869 /* First, take care of the indirect symbols created by versioning. */
3870 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3871 elf64_alpha_merge_ind_symbols
,
3874 if (!elf64_alpha_size_got_sections (info
))
3877 /* Allocate space for all of the .got subsections. */
3878 i
= alpha_elf_hash_table (info
)->got_list
;
3879 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3881 asection
*s
= alpha_elf_tdata(i
)->got
;
3882 if (s
->_raw_size
> 0)
3884 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->_raw_size
);
3885 if (s
->contents
== NULL
)
3893 /* The number of dynamic relocations required by a static relocation. */
3896 alpha_dynamic_entries_for_reloc (r_type
, dynamic
, shared
)
3897 int r_type
, dynamic
, shared
;
3901 /* May appear in GOT entries. */
3903 return (dynamic
? 2 : shared
? 1 : 0);
3904 case R_ALPHA_TLSLDM
:
3906 case R_ALPHA_LITERAL
:
3907 case R_ALPHA_GOTTPREL
:
3908 return dynamic
|| shared
;
3909 case R_ALPHA_GOTDTPREL
:
3912 /* May appear in data sections. */
3913 case R_ALPHA_REFLONG
:
3914 case R_ALPHA_REFQUAD
:
3915 case R_ALPHA_TPREL64
:
3916 return dynamic
|| shared
;
3918 /* Everything else is illegal. We'll issue an error during
3919 relocate_section. */
3925 /* Work out the sizes of the dynamic relocation entries. */
3928 elf64_alpha_calc_dynrel_sizes (h
, info
)
3929 struct alpha_elf_link_hash_entry
*h
;
3930 struct bfd_link_info
*info
;
3932 bfd_boolean dynamic
;
3933 struct alpha_elf_reloc_entry
*relent
;
3934 unsigned long entries
;
3936 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3937 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3939 /* If the symbol was defined as a common symbol in a regular object
3940 file, and there was no definition in any dynamic object, then the
3941 linker will have allocated space for the symbol in a common
3942 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3943 set. This is done for dynamic symbols in
3944 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3945 symbols, somehow. */
3946 if (((h
->root
.elf_link_hash_flags
3947 & (ELF_LINK_HASH_DEF_REGULAR
3948 | ELF_LINK_HASH_REF_REGULAR
3949 | ELF_LINK_HASH_DEF_DYNAMIC
))
3950 == ELF_LINK_HASH_REF_REGULAR
)
3951 && (h
->root
.root
.type
== bfd_link_hash_defined
3952 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3953 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
3954 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3956 /* If the symbol is dynamic, we'll need all the relocations in their
3957 natural form. If this is a shared object, and it has been forced
3958 local, we'll need the same number of RELATIVE relocations. */
3960 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
3962 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
3964 entries
= alpha_dynamic_entries_for_reloc (relent
->rtype
, dynamic
,
3968 relent
->srel
->_raw_size
+=
3969 entries
* sizeof (Elf64_External_Rela
) * relent
->count
;
3970 if (relent
->reltext
)
3971 info
->flags
|= DT_TEXTREL
;
3978 /* Set the sizes of the dynamic relocation sections. */
3981 elf64_alpha_size_rela_got_section (info
)
3982 struct bfd_link_info
*info
;
3984 unsigned long entries
;
3988 /* Shared libraries often require RELATIVE relocs, and some relocs
3989 require attention for the main application as well. */
3992 for (i
= alpha_elf_hash_table(info
)->got_list
;
3993 i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3997 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
3999 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
4002 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
4003 if (!local_got_entries
)
4006 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
4007 for (gotent
= local_got_entries
[k
];
4008 gotent
; gotent
= gotent
->next
)
4009 if (gotent
->use_count
> 0)
4010 entries
+= (alpha_dynamic_entries_for_reloc
4011 (gotent
->reloc_type
, 0, info
->shared
));
4015 dynobj
= elf_hash_table(info
)->dynobj
;
4016 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4019 BFD_ASSERT (entries
== 0);
4022 srel
->_raw_size
= sizeof (Elf64_External_Rela
) * entries
;
4024 /* Now do the non-local symbols. */
4025 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
4026 elf64_alpha_size_rela_got_1
, info
);
4028 srel
->_cooked_size
= srel
->_raw_size
;
4033 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
4037 elf64_alpha_size_rela_got_1 (h
, info
)
4038 struct alpha_elf_link_hash_entry
*h
;
4039 struct bfd_link_info
*info
;
4041 bfd_boolean dynamic
;
4042 struct alpha_elf_got_entry
*gotent
;
4043 unsigned long entries
;
4045 if (h
->root
.root
.type
== bfd_link_hash_warning
)
4046 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4048 /* If the symbol is dynamic, we'll need all the relocations in their
4049 natural form. If this is a shared object, and it has been forced
4050 local, we'll need the same number of RELATIVE relocations. */
4052 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4055 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
4056 if (gotent
->use_count
> 0)
4057 entries
+= alpha_dynamic_entries_for_reloc (gotent
->reloc_type
,
4058 dynamic
, info
->shared
);
4060 /* If we are using a .plt entry, subtract one, as the first
4061 reference uses a .rela.plt entry instead. */
4062 if (h
->root
.plt
.offset
!= MINUS_ONE
)
4067 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4068 asection
*srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4069 BFD_ASSERT (srel
!= NULL
);
4070 srel
->_raw_size
+= sizeof (Elf64_External_Rela
) * entries
;
4076 /* Set the sizes of the dynamic sections. */
4079 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
4080 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4081 struct bfd_link_info
*info
;
4087 dynobj
= elf_hash_table(info
)->dynobj
;
4088 BFD_ASSERT(dynobj
!= NULL
);
4090 if (elf_hash_table (info
)->dynamic_sections_created
)
4092 /* Set the contents of the .interp section to the interpreter. */
4095 s
= bfd_get_section_by_name (dynobj
, ".interp");
4096 BFD_ASSERT (s
!= NULL
);
4097 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4098 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4101 /* Now that we've seen all of the input files, we can decide which
4102 symbols need dynamic relocation entries and which don't. We've
4103 collected information in check_relocs that we can now apply to
4104 size the dynamic relocation sections. */
4105 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
4106 elf64_alpha_calc_dynrel_sizes
, info
);
4108 elf64_alpha_size_rela_got_section (info
);
4110 /* else we're not dynamic and by definition we don't need such things. */
4112 /* The check_relocs and adjust_dynamic_symbol entry points have
4113 determined the sizes of the various dynamic sections. Allocate
4116 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4121 if (!(s
->flags
& SEC_LINKER_CREATED
))
4124 /* It's OK to base decisions on the section name, because none
4125 of the dynobj section names depend upon the input files. */
4126 name
= bfd_get_section_name (dynobj
, s
);
4128 /* If we don't need this section, strip it from the output file.
4129 This is to handle .rela.bss and .rela.plt. We must create it
4130 in create_dynamic_sections, because it must be created before
4131 the linker maps input sections to output sections. The
4132 linker does that before adjust_dynamic_symbol is called, and
4133 it is that function which decides whether anything needs to
4134 go into these sections. */
4138 if (strncmp (name
, ".rela", 5) == 0)
4140 strip
= (s
->_raw_size
== 0);
4144 if (strcmp(name
, ".rela.plt") == 0)
4147 /* We use the reloc_count field as a counter if we need
4148 to copy relocs into the output file. */
4152 else if (strcmp (name
, ".plt") != 0)
4154 /* It's not one of our dynamic sections, so don't allocate space. */
4159 _bfd_strip_section_from_output (info
, s
);
4162 /* Allocate memory for the section contents. */
4163 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4164 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
4169 if (elf_hash_table (info
)->dynamic_sections_created
)
4171 /* Add some entries to the .dynamic section. We fill in the
4172 values later, in elf64_alpha_finish_dynamic_sections, but we
4173 must add the entries now so that we get the correct size for
4174 the .dynamic section. The DT_DEBUG entry is filled in by the
4175 dynamic linker and used by the debugger. */
4176 #define add_dynamic_entry(TAG, VAL) \
4177 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4181 if (!add_dynamic_entry (DT_DEBUG
, 0))
4187 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4188 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4189 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4190 || !add_dynamic_entry (DT_JMPREL
, 0))
4194 if (!add_dynamic_entry (DT_RELA
, 0)
4195 || !add_dynamic_entry (DT_RELASZ
, 0)
4196 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4199 if (info
->flags
& DF_TEXTREL
)
4201 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4205 #undef add_dynamic_entry
4210 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
4211 into the next available slot in SREL. */
4214 elf64_alpha_emit_dynrel (abfd
, info
, sec
, srel
, offset
, dynindx
, rtype
, addend
)
4216 struct bfd_link_info
*info
;
4217 asection
*sec
, *srel
;
4218 bfd_vma offset
, addend
;
4219 long dynindx
, rtype
;
4221 Elf_Internal_Rela outrel
;
4224 BFD_ASSERT (srel
!= NULL
);
4226 outrel
.r_info
= ELF64_R_INFO (dynindx
, rtype
);
4227 outrel
.r_addend
= addend
;
4229 offset
= _bfd_elf_section_offset (abfd
, info
, sec
, offset
);
4230 if ((offset
| 1) != (bfd_vma
) -1)
4231 outrel
.r_offset
= sec
->output_section
->vma
+ sec
->output_offset
+ offset
;
4233 memset (&outrel
, 0, sizeof (outrel
));
4235 loc
= srel
->contents
;
4236 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4237 bfd_elf64_swap_reloca_out (abfd
, &outrel
, loc
);
4238 BFD_ASSERT (sizeof (Elf64_External_Rela
) * srel
->reloc_count
4239 <= srel
->_cooked_size
);
4242 /* Relocate an Alpha ELF section for a relocatable link.
4244 We don't have to change anything unless the reloc is against a section
4245 symbol, in which case we have to adjust according to where the section
4246 symbol winds up in the output section. */
4249 elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
, input_section
,
4250 contents
, relocs
, local_syms
, local_sections
)
4251 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4252 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4254 asection
*input_section
;
4255 bfd_byte
*contents ATTRIBUTE_UNUSED
;
4256 Elf_Internal_Rela
*relocs
;
4257 Elf_Internal_Sym
*local_syms
;
4258 asection
**local_sections
;
4260 unsigned long symtab_hdr_sh_info
;
4261 Elf_Internal_Rela
*rel
;
4262 Elf_Internal_Rela
*relend
;
4263 bfd_boolean ret_val
= TRUE
;
4265 symtab_hdr_sh_info
= elf_tdata (input_bfd
)->symtab_hdr
.sh_info
;
4267 relend
= relocs
+ input_section
->reloc_count
;
4268 for (rel
= relocs
; rel
< relend
; rel
++)
4270 unsigned long r_symndx
;
4271 Elf_Internal_Sym
*sym
;
4273 unsigned long r_type
;
4275 r_type
= ELF64_R_TYPE(rel
->r_info
);
4276 if (r_type
>= R_ALPHA_max
)
4278 (*_bfd_error_handler
)
4279 (_("%s: unknown relocation type %d"),
4280 bfd_archive_filename (input_bfd
), (int)r_type
);
4281 bfd_set_error (bfd_error_bad_value
);
4286 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4288 /* The symbol associated with GPDISP and LITUSE is
4289 immaterial. Only the addend is significant. */
4290 if (r_type
== R_ALPHA_GPDISP
|| r_type
== R_ALPHA_LITUSE
)
4293 if (r_symndx
< symtab_hdr_sh_info
)
4295 sym
= local_syms
+ r_symndx
;
4296 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
4298 sec
= local_sections
[r_symndx
];
4299 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4307 /* Relocate an Alpha ELF section. */
4310 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4311 contents
, relocs
, local_syms
, local_sections
)
4313 struct bfd_link_info
*info
;
4315 asection
*input_section
;
4317 Elf_Internal_Rela
*relocs
;
4318 Elf_Internal_Sym
*local_syms
;
4319 asection
**local_sections
;
4321 Elf_Internal_Shdr
*symtab_hdr
;
4322 Elf_Internal_Rela
*rel
;
4323 Elf_Internal_Rela
*relend
;
4324 struct elf_link_tls_segment
*tls_segment
;
4325 asection
*sgot
, *srel
, *srelgot
;
4326 bfd
*dynobj
, *gotobj
;
4327 bfd_vma gp
, tp_base
, dtp_base
;
4328 struct alpha_elf_got_entry
**local_got_entries
;
4329 bfd_boolean ret_val
;
4330 const char *section_name
;
4332 /* Handle relocatable links with a smaller loop. */
4333 if (info
->relocateable
)
4334 return elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
,
4335 input_section
, contents
, relocs
,
4336 local_syms
, local_sections
);
4338 /* This is a final link. */
4342 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4344 dynobj
= elf_hash_table (info
)->dynobj
;
4346 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
4350 section_name
= (bfd_elf_string_from_elf_section
4351 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
4352 elf_section_data(input_section
)->rel_hdr
.sh_name
));
4353 BFD_ASSERT(section_name
!= NULL
);
4354 srel
= bfd_get_section_by_name (dynobj
, section_name
);
4356 /* Find the gp value for this input bfd. */
4357 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
4360 sgot
= alpha_elf_tdata (gotobj
)->got
;
4361 gp
= _bfd_get_gp_value (gotobj
);
4364 gp
= (sgot
->output_section
->vma
4365 + sgot
->output_offset
4367 _bfd_set_gp_value (gotobj
, gp
);
4376 local_got_entries
= alpha_elf_tdata(input_bfd
)->local_got_entries
;
4378 tls_segment
= elf_hash_table (info
)->tls_segment
;
4381 dtp_base
= alpha_get_dtprel_base (tls_segment
);
4382 tp_base
= alpha_get_tprel_base (tls_segment
);
4385 dtp_base
= tp_base
= 0;
4387 relend
= relocs
+ input_section
->reloc_count
;
4388 for (rel
= relocs
; rel
< relend
; rel
++)
4390 struct alpha_elf_link_hash_entry
*h
= NULL
;
4391 struct alpha_elf_got_entry
*gotent
;
4392 bfd_reloc_status_type r
;
4393 reloc_howto_type
*howto
;
4394 unsigned long r_symndx
;
4395 Elf_Internal_Sym
*sym
= NULL
;
4396 asection
*sec
= NULL
;
4399 bfd_boolean dynamic_symbol_p
;
4400 bfd_boolean undef_weak_ref
= FALSE
;
4401 unsigned long r_type
;
4403 r_type
= ELF64_R_TYPE(rel
->r_info
);
4404 if (r_type
>= R_ALPHA_max
)
4406 (*_bfd_error_handler
)
4407 (_("%s: unknown relocation type %d"),
4408 bfd_archive_filename (input_bfd
), (int)r_type
);
4409 bfd_set_error (bfd_error_bad_value
);
4414 howto
= elf64_alpha_howto_table
+ r_type
;
4415 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4417 /* The symbol for a TLSLDM reloc is ignored. Collapse the
4418 reloc to the 0 symbol so that they all match. */
4419 if (r_type
== R_ALPHA_TLSLDM
)
4422 if (r_symndx
< symtab_hdr
->sh_info
)
4424 sym
= local_syms
+ r_symndx
;
4425 sec
= local_sections
[r_symndx
];
4426 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4428 /* If this is a tp-relative relocation against sym 0,
4429 this is hackery from relax_section. Force the value to
4432 && (r_type
== R_ALPHA_TLSLDM
4433 || r_type
== R_ALPHA_GOTTPREL
4434 || r_type
== R_ALPHA_TPREL64
4435 || r_type
== R_ALPHA_TPRELHI
4436 || r_type
== R_ALPHA_TPRELLO
4437 || r_type
== R_ALPHA_TPREL16
))
4440 if (local_got_entries
)
4441 gotent
= local_got_entries
[r_symndx
];
4445 /* Need to adjust local GOT entries' addends for SEC_MERGE
4446 unless it has been done already. */
4447 if ((sec
->flags
& SEC_MERGE
)
4448 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
4449 && sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
4451 && !gotent
->reloc_xlated
)
4453 struct alpha_elf_got_entry
*ent
;
4456 for (ent
= gotent
; ent
; ent
= ent
->next
)
4458 ent
->reloc_xlated
= 1;
4459 if (ent
->use_count
== 0)
4463 _bfd_merged_section_offset (output_bfd
, &msec
,
4464 elf_section_data (sec
)->
4466 sym
->st_value
+ ent
->addend
,
4468 ent
->addend
-= sym
->st_value
;
4469 ent
->addend
+= msec
->output_section
->vma
4470 + msec
->output_offset
4471 - sec
->output_section
->vma
4472 - sec
->output_offset
;
4476 dynamic_symbol_p
= FALSE
;
4480 h
= alpha_elf_sym_hashes (input_bfd
)[r_symndx
- symtab_hdr
->sh_info
];
4482 while (h
->root
.root
.type
== bfd_link_hash_indirect
4483 || h
->root
.root
.type
== bfd_link_hash_warning
)
4484 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
4487 if (h
->root
.root
.type
== bfd_link_hash_defined
4488 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4490 sec
= h
->root
.root
.u
.def
.section
;
4492 /* Detect the cases that sym_sec->output_section is
4493 expected to be NULL -- all cases in which the symbol
4494 is defined in another shared module. This includes
4495 PLT relocs for which we've created a PLT entry and
4496 other relocs for which we're prepared to create
4497 dynamic relocations. */
4498 /* ??? Just accept it NULL and continue. */
4500 if (sec
->output_section
!= NULL
)
4501 value
= (h
->root
.root
.u
.def
.value
4502 + sec
->output_section
->vma
4503 + sec
->output_offset
);
4505 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4506 undef_weak_ref
= TRUE
;
4507 else if (info
->shared
4508 && !info
->no_undefined
4509 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4513 if (!((*info
->callbacks
->undefined_symbol
)
4514 (info
, h
->root
.root
.root
.string
, input_bfd
,
4515 input_section
, rel
->r_offset
,
4516 (!info
->shared
|| info
->no_undefined
4517 || ELF_ST_VISIBILITY (h
->root
.other
)))))
4522 dynamic_symbol_p
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4523 gotent
= h
->got_entries
;
4526 addend
= rel
->r_addend
;
4529 /* Search for the proper got entry. */
4530 for (; gotent
; gotent
= gotent
->next
)
4531 if (gotent
->gotobj
== gotobj
4532 && gotent
->reloc_type
== r_type
4533 && gotent
->addend
== addend
)
4538 case R_ALPHA_GPDISP
:
4540 bfd_byte
*p_ldah
, *p_lda
;
4542 BFD_ASSERT(gp
!= 0);
4544 value
= (input_section
->output_section
->vma
4545 + input_section
->output_offset
4548 p_ldah
= contents
+ rel
->r_offset
;
4549 p_lda
= p_ldah
+ rel
->r_addend
;
4551 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- value
,
4556 case R_ALPHA_LITERAL
:
4557 BFD_ASSERT(sgot
!= NULL
);
4558 BFD_ASSERT(gp
!= 0);
4559 BFD_ASSERT(gotent
!= NULL
);
4560 BFD_ASSERT(gotent
->use_count
>= 1);
4562 if (!gotent
->reloc_done
)
4564 gotent
->reloc_done
= 1;
4566 bfd_put_64 (output_bfd
, value
,
4567 sgot
->contents
+ gotent
->got_offset
);
4569 /* If the symbol has been forced local, output a
4570 RELATIVE reloc, otherwise it will be handled in
4571 finish_dynamic_symbol. */
4572 if (info
->shared
&& !dynamic_symbol_p
)
4573 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4574 gotent
->got_offset
, 0,
4575 R_ALPHA_RELATIVE
, value
);
4578 value
= (sgot
->output_section
->vma
4579 + sgot
->output_offset
4580 + gotent
->got_offset
);
4584 case R_ALPHA_GPREL32
:
4585 /* If the target section was a removed linkonce section,
4586 r_symndx will be zero. In this case, assume that the
4587 switch will not be used, so don't fill it in. If we
4588 do nothing here, we'll get relocation truncated messages,
4589 due to the placement of the application above 4GB. */
4597 case R_ALPHA_GPREL16
:
4598 case R_ALPHA_GPRELLOW
:
4599 if (dynamic_symbol_p
)
4601 (*_bfd_error_handler
)
4602 (_("%s: gp-relative relocation against dynamic symbol %s"),
4603 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4606 BFD_ASSERT(gp
!= 0);
4610 case R_ALPHA_GPRELHIGH
:
4611 if (dynamic_symbol_p
)
4613 (*_bfd_error_handler
)
4614 (_("%s: gp-relative relocation against dynamic symbol %s"),
4615 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4618 BFD_ASSERT(gp
!= 0);
4620 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4624 /* A call to a dynamic symbol is definitely out of range of
4625 the 16-bit displacement. Don't bother writing anything. */
4626 if (dynamic_symbol_p
)
4631 /* The regular PC-relative stuff measures from the start of
4632 the instruction rather than the end. */
4636 case R_ALPHA_BRADDR
:
4637 if (dynamic_symbol_p
)
4639 (*_bfd_error_handler
)
4640 (_("%s: pc-relative relocation against dynamic symbol %s"),
4641 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4644 /* The regular PC-relative stuff measures from the start of
4645 the instruction rather than the end. */
4654 /* The regular PC-relative stuff measures from the start of
4655 the instruction rather than the end. */
4658 /* The source and destination gp must be the same. Note that
4659 the source will always have an assigned gp, since we forced
4660 one in check_relocs, but that the destination may not, as
4661 it might not have had any relocations at all. Also take
4662 care not to crash if H is an undefined symbol. */
4663 if (h
!= NULL
&& sec
!= NULL
4664 && alpha_elf_tdata (sec
->owner
)->gotobj
4665 && gotobj
!= alpha_elf_tdata (sec
->owner
)->gotobj
)
4667 (*_bfd_error_handler
)
4668 (_("%s: change in gp: BRSGP %s"),
4669 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4673 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4675 other
= h
->root
.other
;
4677 other
= sym
->st_other
;
4678 switch (other
& STO_ALPHA_STD_GPLOAD
)
4680 case STO_ALPHA_NOPV
:
4682 case STO_ALPHA_STD_GPLOAD
:
4687 name
= h
->root
.root
.root
.string
;
4690 name
= (bfd_elf_string_from_elf_section
4691 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4693 name
= _("<unknown>");
4694 else if (name
[0] == 0)
4695 name
= bfd_section_name (input_bfd
, sec
);
4697 (*_bfd_error_handler
)
4698 (_("%s: !samegp reloc against symbol without .prologue: %s"),
4699 bfd_archive_filename (input_bfd
), name
);
4707 case R_ALPHA_REFLONG
:
4708 case R_ALPHA_REFQUAD
:
4709 case R_ALPHA_DTPREL64
:
4710 case R_ALPHA_TPREL64
:
4712 long dynindx
, dyntype
= r_type
;
4715 /* Careful here to remember RELATIVE relocations for global
4716 variables for symbolic shared objects. */
4718 if (dynamic_symbol_p
)
4720 BFD_ASSERT(h
->root
.dynindx
!= -1);
4721 dynindx
= h
->root
.dynindx
;
4723 addend
= 0, value
= 0;
4725 else if (r_type
== R_ALPHA_DTPREL64
)
4727 BFD_ASSERT(tls_segment
!= NULL
);
4731 else if (r_type
== R_ALPHA_TPREL64
)
4733 BFD_ASSERT(tls_segment
!= NULL
);
4740 dynaddend
= value
- dtp_base
;
4742 else if (info
->shared
4744 && (input_section
->flags
& SEC_ALLOC
))
4746 if (r_type
== R_ALPHA_REFLONG
)
4748 (*_bfd_error_handler
)
4749 (_("%s: unhandled dynamic relocation against %s"),
4750 bfd_archive_filename (input_bfd
),
4751 h
->root
.root
.root
.string
);
4755 dyntype
= R_ALPHA_RELATIVE
;
4761 elf64_alpha_emit_dynrel (output_bfd
, info
, input_section
,
4762 srel
, rel
->r_offset
, dynindx
,
4763 dyntype
, dynaddend
);
4767 case R_ALPHA_SREL16
:
4768 case R_ALPHA_SREL32
:
4769 case R_ALPHA_SREL64
:
4770 if (dynamic_symbol_p
)
4772 (*_bfd_error_handler
)
4773 (_("%s: pc-relative relocation against dynamic symbol %s"),
4774 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4778 /* ??? .eh_frame references to discarded sections will be smashed
4779 to relocations against SHN_UNDEF. The .eh_frame format allows
4780 NULL to be encoded as 0 in any format, so this works here. */
4782 howto
= (elf64_alpha_howto_table
4783 + (r_type
- R_ALPHA_SREL32
+ R_ALPHA_REFLONG
));
4786 case R_ALPHA_TLSLDM
:
4787 /* Ignore the symbol for the relocation. The result is always
4788 the current module. */
4789 dynamic_symbol_p
= 0;
4793 if (!gotent
->reloc_done
)
4795 gotent
->reloc_done
= 1;
4797 /* Note that the module index for the main program is 1. */
4798 bfd_put_64 (output_bfd
, !info
->shared
&& !dynamic_symbol_p
,
4799 sgot
->contents
+ gotent
->got_offset
);
4801 /* If the symbol has been forced local, output a
4802 DTPMOD64 reloc, otherwise it will be handled in
4803 finish_dynamic_symbol. */
4804 if (info
->shared
&& !dynamic_symbol_p
)
4805 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4806 gotent
->got_offset
, 0,
4807 R_ALPHA_DTPMOD64
, 0);
4809 if (dynamic_symbol_p
|| r_type
== R_ALPHA_TLSLDM
)
4813 BFD_ASSERT(tls_segment
!= NULL
);
4816 bfd_put_64 (output_bfd
, value
,
4817 sgot
->contents
+ gotent
->got_offset
+ 8);
4820 value
= (sgot
->output_section
->vma
4821 + sgot
->output_offset
4822 + gotent
->got_offset
);
4826 case R_ALPHA_DTPRELHI
:
4827 case R_ALPHA_DTPRELLO
:
4828 case R_ALPHA_DTPREL16
:
4829 if (dynamic_symbol_p
)
4831 (*_bfd_error_handler
)
4832 (_("%s: dtp-relative relocation against dynamic symbol %s"),
4833 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4836 BFD_ASSERT(tls_segment
!= NULL
);
4838 if (r_type
== R_ALPHA_DTPRELHI
)
4839 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4842 case R_ALPHA_TPRELHI
:
4843 case R_ALPHA_TPRELLO
:
4844 case R_ALPHA_TPREL16
:
4847 (*_bfd_error_handler
)
4848 (_("%s: TLS local exec code cannot be linked into shared objects"),
4849 bfd_archive_filename (input_bfd
));
4852 else if (dynamic_symbol_p
)
4854 (*_bfd_error_handler
)
4855 (_("%s: tp-relative relocation against dynamic symbol %s"),
4856 bfd_archive_filename (input_bfd
), h
->root
.root
.root
.string
);
4859 BFD_ASSERT(tls_segment
!= NULL
);
4861 if (r_type
== R_ALPHA_TPRELHI
)
4862 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4865 case R_ALPHA_GOTDTPREL
:
4866 case R_ALPHA_GOTTPREL
:
4867 BFD_ASSERT(sgot
!= NULL
);
4868 BFD_ASSERT(gp
!= 0);
4869 BFD_ASSERT(gotent
!= NULL
);
4870 BFD_ASSERT(gotent
->use_count
>= 1);
4872 if (!gotent
->reloc_done
)
4874 gotent
->reloc_done
= 1;
4876 if (dynamic_symbol_p
)
4880 BFD_ASSERT(tls_segment
!= NULL
);
4881 if (r_type
== R_ALPHA_GOTDTPREL
)
4883 else if (!info
->shared
)
4887 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4888 gotent
->got_offset
, 0,
4894 bfd_put_64 (output_bfd
, value
,
4895 sgot
->contents
+ gotent
->got_offset
);
4898 value
= (sgot
->output_section
->vma
4899 + sgot
->output_offset
4900 + gotent
->got_offset
);
4906 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4907 contents
, rel
->r_offset
, value
, 0);
4916 case bfd_reloc_overflow
:
4920 /* Don't warn if the overflow is due to pc relative reloc
4921 against discarded section. Section optimization code should
4924 if (r_symndx
< symtab_hdr
->sh_info
4925 && sec
!= NULL
&& howto
->pc_relative
4926 && elf_discarded_section (sec
))
4930 name
= h
->root
.root
.root
.string
;
4933 name
= (bfd_elf_string_from_elf_section
4934 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4938 name
= bfd_section_name (input_bfd
, sec
);
4940 if (! ((*info
->callbacks
->reloc_overflow
)
4941 (info
, name
, howto
->name
, (bfd_vma
) 0,
4942 input_bfd
, input_section
, rel
->r_offset
)))
4948 case bfd_reloc_outofrange
:
4956 /* Finish up dynamic symbol handling. We set the contents of various
4957 dynamic sections here. */
4960 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4962 struct bfd_link_info
*info
;
4963 struct elf_link_hash_entry
*h
;
4964 Elf_Internal_Sym
*sym
;
4966 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4968 if (h
->plt
.offset
!= MINUS_ONE
)
4970 /* Fill in the .plt entry for this symbol. */
4971 asection
*splt
, *sgot
, *srel
;
4972 Elf_Internal_Rela outrel
;
4974 bfd_vma got_addr
, plt_addr
;
4976 struct alpha_elf_got_entry
*gotent
;
4978 BFD_ASSERT (h
->dynindx
!= -1);
4980 /* The first .got entry will be updated by the .plt with the
4981 address of the target function. */
4982 gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4983 BFD_ASSERT (gotent
&& gotent
->addend
== 0);
4985 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4986 BFD_ASSERT (splt
!= NULL
);
4987 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4988 BFD_ASSERT (srel
!= NULL
);
4989 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4990 BFD_ASSERT (sgot
!= NULL
);
4992 got_addr
= (sgot
->output_section
->vma
4993 + sgot
->output_offset
4994 + gotent
->got_offset
);
4995 plt_addr
= (splt
->output_section
->vma
4996 + splt
->output_offset
4999 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
5001 /* Fill in the entry in the procedure linkage table. */
5003 bfd_vma insn1
, insn2
, insn3
;
5005 insn1
= PLT_ENTRY_WORD1
| ((-(h
->plt
.offset
+ 4) >> 2) & 0x1fffff);
5006 insn2
= PLT_ENTRY_WORD2
;
5007 insn3
= PLT_ENTRY_WORD3
;
5009 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt
.offset
);
5010 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt
.offset
+ 4);
5011 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt
.offset
+ 8);
5014 /* Fill in the entry in the .rela.plt section. */
5015 outrel
.r_offset
= got_addr
;
5016 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
5017 outrel
.r_addend
= 0;
5019 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
5020 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5022 if (!(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
5024 /* Mark the symbol as undefined, rather than as defined in the
5025 .plt section. Leave the value alone. */
5026 sym
->st_shndx
= SHN_UNDEF
;
5029 /* Fill in the entries in the .got. */
5030 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ gotent
->got_offset
);
5032 /* Subsequent .got entries will continue to bounce through the .plt. */
5035 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
5036 BFD_ASSERT (! info
->shared
|| srel
!= NULL
);
5038 gotent
= gotent
->next
;
5041 sgot
= alpha_elf_tdata(gotent
->gotobj
)->got
;
5042 BFD_ASSERT(sgot
!= NULL
);
5043 BFD_ASSERT(gotent
->addend
== 0);
5045 bfd_put_64 (output_bfd
, plt_addr
,
5046 sgot
->contents
+ gotent
->got_offset
);
5049 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
5050 gotent
->got_offset
, 0,
5051 R_ALPHA_RELATIVE
, plt_addr
);
5053 gotent
= gotent
->next
;
5055 while (gotent
!= NULL
);
5058 else if (alpha_elf_dynamic_symbol_p (h
, info
))
5060 /* Fill in the dynamic relocations for this symbol's .got entries. */
5062 struct alpha_elf_got_entry
*gotent
;
5064 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
5065 BFD_ASSERT (srel
!= NULL
);
5067 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
5069 gotent
= gotent
->next
)
5074 if (gotent
->use_count
== 0)
5077 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
5079 r_type
= gotent
->reloc_type
;
5082 case R_ALPHA_LITERAL
:
5083 r_type
= R_ALPHA_GLOB_DAT
;
5086 r_type
= R_ALPHA_DTPMOD64
;
5088 case R_ALPHA_GOTDTPREL
:
5089 r_type
= R_ALPHA_DTPREL64
;
5091 case R_ALPHA_GOTTPREL
:
5092 r_type
= R_ALPHA_TPREL64
;
5094 case R_ALPHA_TLSLDM
:
5099 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
5100 gotent
->got_offset
, h
->dynindx
,
5101 r_type
, gotent
->addend
);
5103 if (gotent
->reloc_type
== R_ALPHA_TLSGD
)
5104 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
5105 gotent
->got_offset
+ 8, h
->dynindx
,
5106 R_ALPHA_DTPREL64
, gotent
->addend
);
5110 /* Mark some specially defined symbols as absolute. */
5111 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
5112 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
5113 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
5114 sym
->st_shndx
= SHN_ABS
;
5119 /* Finish up the dynamic sections. */
5122 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
5124 struct bfd_link_info
*info
;
5129 dynobj
= elf_hash_table (info
)->dynobj
;
5130 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5132 if (elf_hash_table (info
)->dynamic_sections_created
)
5135 Elf64_External_Dyn
*dyncon
, *dynconend
;
5137 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5138 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
5140 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
5141 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5142 for (; dyncon
< dynconend
; dyncon
++)
5144 Elf_Internal_Dyn dyn
;
5148 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5163 /* My interpretation of the TIS v1.1 ELF document indicates
5164 that RELASZ should not include JMPREL. This is not what
5165 the rest of the BFD does. It is, however, what the
5166 glibc ld.so wants. Do this fixup here until we found
5167 out who is right. */
5168 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
5172 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
5177 s
= bfd_get_section_by_name (output_bfd
, name
);
5178 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
5182 s
= bfd_get_section_by_name (output_bfd
, name
);
5184 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
5188 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5191 /* Initialize the PLT0 entry. */
5192 if (splt
->_raw_size
> 0)
5194 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
5195 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
5196 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
5197 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
5199 /* The next two words will be filled in by ld.so */
5200 bfd_put_64 (output_bfd
, (bfd_vma
) 0, splt
->contents
+ 16);
5201 bfd_put_64 (output_bfd
, (bfd_vma
) 0, splt
->contents
+ 24);
5203 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 0;
5210 /* We need to use a special link routine to handle the .mdebug section.
5211 We need to merge all instances of these sections together, not write
5212 them all out sequentially. */
5215 elf64_alpha_final_link (abfd
, info
)
5217 struct bfd_link_info
*info
;
5220 struct bfd_link_order
*p
;
5221 asection
*mdebug_sec
;
5222 struct ecoff_debug_info debug
;
5223 const struct ecoff_debug_swap
*swap
5224 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
5225 HDRR
*symhdr
= &debug
.symbolic_header
;
5226 PTR mdebug_handle
= NULL
;
5228 /* Go through the sections and collect the mdebug information. */
5230 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
5232 if (strcmp (o
->name
, ".mdebug") == 0)
5234 struct extsym_info einfo
;
5236 /* We have found the .mdebug section in the output file.
5237 Look through all the link_orders comprising it and merge
5238 the information together. */
5239 symhdr
->magic
= swap
->sym_magic
;
5240 /* FIXME: What should the version stamp be? */
5242 symhdr
->ilineMax
= 0;
5246 symhdr
->isymMax
= 0;
5247 symhdr
->ioptMax
= 0;
5248 symhdr
->iauxMax
= 0;
5250 symhdr
->issExtMax
= 0;
5253 symhdr
->iextMax
= 0;
5255 /* We accumulate the debugging information itself in the
5256 debug_info structure. */
5258 debug
.external_dnr
= NULL
;
5259 debug
.external_pdr
= NULL
;
5260 debug
.external_sym
= NULL
;
5261 debug
.external_opt
= NULL
;
5262 debug
.external_aux
= NULL
;
5264 debug
.ssext
= debug
.ssext_end
= NULL
;
5265 debug
.external_fdr
= NULL
;
5266 debug
.external_rfd
= NULL
;
5267 debug
.external_ext
= debug
.external_ext_end
= NULL
;
5269 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
5270 if (mdebug_handle
== (PTR
) NULL
)
5279 static const char * const name
[] =
5281 ".text", ".init", ".fini", ".data",
5282 ".rodata", ".sdata", ".sbss", ".bss"
5284 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
5285 scRData
, scSData
, scSBss
, scBss
};
5288 esym
.cobol_main
= 0;
5292 esym
.asym
.iss
= issNil
;
5293 esym
.asym
.st
= stLocal
;
5294 esym
.asym
.reserved
= 0;
5295 esym
.asym
.index
= indexNil
;
5296 for (i
= 0; i
< 8; i
++)
5298 esym
.asym
.sc
= sc
[i
];
5299 s
= bfd_get_section_by_name (abfd
, name
[i
]);
5302 esym
.asym
.value
= s
->vma
;
5303 last
= s
->vma
+ s
->_raw_size
;
5306 esym
.asym
.value
= last
;
5308 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
5314 for (p
= o
->link_order_head
;
5315 p
!= (struct bfd_link_order
*) NULL
;
5318 asection
*input_section
;
5320 const struct ecoff_debug_swap
*input_swap
;
5321 struct ecoff_debug_info input_debug
;
5325 if (p
->type
!= bfd_indirect_link_order
)
5327 if (p
->type
== bfd_data_link_order
)
5332 input_section
= p
->u
.indirect
.section
;
5333 input_bfd
= input_section
->owner
;
5335 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
5336 || (get_elf_backend_data (input_bfd
)
5337 ->elf_backend_ecoff_debug_swap
) == NULL
)
5339 /* I don't know what a non ALPHA ELF bfd would be
5340 doing with a .mdebug section, but I don't really
5341 want to deal with it. */
5345 input_swap
= (get_elf_backend_data (input_bfd
)
5346 ->elf_backend_ecoff_debug_swap
);
5348 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
5350 /* The ECOFF linking code expects that we have already
5351 read in the debugging information and set up an
5352 ecoff_debug_info structure, so we do that now. */
5353 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
5357 if (! (bfd_ecoff_debug_accumulate
5358 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5359 &input_debug
, input_swap
, info
)))
5362 /* Loop through the external symbols. For each one with
5363 interesting information, try to find the symbol in
5364 the linker global hash table and save the information
5365 for the output external symbols. */
5366 eraw_src
= input_debug
.external_ext
;
5367 eraw_end
= (eraw_src
5368 + (input_debug
.symbolic_header
.iextMax
5369 * input_swap
->external_ext_size
));
5371 eraw_src
< eraw_end
;
5372 eraw_src
+= input_swap
->external_ext_size
)
5376 struct alpha_elf_link_hash_entry
*h
;
5378 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5379 if (ext
.asym
.sc
== scNil
5380 || ext
.asym
.sc
== scUndefined
5381 || ext
.asym
.sc
== scSUndefined
)
5384 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5385 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
5386 name
, FALSE
, FALSE
, TRUE
);
5387 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5393 < input_debug
.symbolic_header
.ifdMax
);
5394 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5400 /* Free up the information we just read. */
5401 free (input_debug
.line
);
5402 free (input_debug
.external_dnr
);
5403 free (input_debug
.external_pdr
);
5404 free (input_debug
.external_sym
);
5405 free (input_debug
.external_opt
);
5406 free (input_debug
.external_aux
);
5407 free (input_debug
.ss
);
5408 free (input_debug
.ssext
);
5409 free (input_debug
.external_fdr
);
5410 free (input_debug
.external_rfd
);
5411 free (input_debug
.external_ext
);
5413 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5414 elf_link_input_bfd ignores this section. */
5415 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5418 /* Build the external symbol information. */
5421 einfo
.debug
= &debug
;
5423 einfo
.failed
= FALSE
;
5424 elf_link_hash_traverse (elf_hash_table (info
),
5425 elf64_alpha_output_extsym
,
5430 /* Set the size of the .mdebug section. */
5431 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5433 /* Skip this section later on (I don't think this currently
5434 matters, but someday it might). */
5435 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
5441 /* Invoke the regular ELF backend linker to do all the work. */
5442 if (! bfd_elf64_bfd_final_link (abfd
, info
))
5445 /* Now write out the computed sections. */
5447 /* The .got subsections... */
5449 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
5450 for (i
= alpha_elf_hash_table(info
)->got_list
;
5452 i
= alpha_elf_tdata(i
)->got_link_next
)
5456 /* elf_bfd_final_link already did everything in dynobj. */
5460 sgot
= alpha_elf_tdata(i
)->got
;
5461 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
5463 (file_ptr
) sgot
->output_offset
,
5469 if (mdebug_sec
!= (asection
*) NULL
)
5471 BFD_ASSERT (abfd
->output_has_begun
);
5472 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5474 mdebug_sec
->filepos
))
5477 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5483 static enum elf_reloc_type_class
5484 elf64_alpha_reloc_type_class (rela
)
5485 const Elf_Internal_Rela
*rela
;
5487 switch ((int) ELF64_R_TYPE (rela
->r_info
))
5489 case R_ALPHA_RELATIVE
:
5490 return reloc_class_relative
;
5491 case R_ALPHA_JMP_SLOT
:
5492 return reloc_class_plt
;
5494 return reloc_class_copy
;
5496 return reloc_class_normal
;
5500 /* ECOFF swapping routines. These are used when dealing with the
5501 .mdebug section, which is in the ECOFF debugging format. Copied
5502 from elf32-mips.c. */
5503 static const struct ecoff_debug_swap
5504 elf64_alpha_ecoff_debug_swap
=
5506 /* Symbol table magic number. */
5508 /* Alignment of debugging information. E.g., 4. */
5510 /* Sizes of external symbolic information. */
5511 sizeof (struct hdr_ext
),
5512 sizeof (struct dnr_ext
),
5513 sizeof (struct pdr_ext
),
5514 sizeof (struct sym_ext
),
5515 sizeof (struct opt_ext
),
5516 sizeof (struct fdr_ext
),
5517 sizeof (struct rfd_ext
),
5518 sizeof (struct ext_ext
),
5519 /* Functions to swap in external symbolic data. */
5528 _bfd_ecoff_swap_tir_in
,
5529 _bfd_ecoff_swap_rndx_in
,
5530 /* Functions to swap out external symbolic data. */
5539 _bfd_ecoff_swap_tir_out
,
5540 _bfd_ecoff_swap_rndx_out
,
5541 /* Function to read in symbolic data. */
5542 elf64_alpha_read_ecoff_info
5545 /* Use a non-standard hash bucket size of 8. */
5547 static const struct elf_size_info alpha_elf_size_info
=
5549 sizeof (Elf64_External_Ehdr
),
5550 sizeof (Elf64_External_Phdr
),
5551 sizeof (Elf64_External_Shdr
),
5552 sizeof (Elf64_External_Rel
),
5553 sizeof (Elf64_External_Rela
),
5554 sizeof (Elf64_External_Sym
),
5555 sizeof (Elf64_External_Dyn
),
5556 sizeof (Elf_External_Note
),
5560 ELFCLASS64
, EV_CURRENT
,
5561 bfd_elf64_write_out_phdrs
,
5562 bfd_elf64_write_shdrs_and_ehdr
,
5563 bfd_elf64_write_relocs
,
5564 bfd_elf64_swap_symbol_in
,
5565 bfd_elf64_swap_symbol_out
,
5566 bfd_elf64_slurp_reloc_table
,
5567 bfd_elf64_slurp_symbol_table
,
5568 bfd_elf64_swap_dyn_in
,
5569 bfd_elf64_swap_dyn_out
,
5570 bfd_elf64_swap_reloc_in
,
5571 bfd_elf64_swap_reloc_out
,
5572 bfd_elf64_swap_reloca_in
,
5573 bfd_elf64_swap_reloca_out
5576 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5577 #define TARGET_LITTLE_NAME "elf64-alpha"
5578 #define ELF_ARCH bfd_arch_alpha
5579 #define ELF_MACHINE_CODE EM_ALPHA
5580 #define ELF_MAXPAGESIZE 0x10000
5582 #define bfd_elf64_bfd_link_hash_table_create \
5583 elf64_alpha_bfd_link_hash_table_create
5585 #define bfd_elf64_bfd_reloc_type_lookup \
5586 elf64_alpha_bfd_reloc_type_lookup
5587 #define elf_info_to_howto \
5588 elf64_alpha_info_to_howto
5590 #define bfd_elf64_mkobject \
5591 elf64_alpha_mkobject
5592 #define elf_backend_object_p \
5593 elf64_alpha_object_p
5595 #define elf_backend_section_from_shdr \
5596 elf64_alpha_section_from_shdr
5597 #define elf_backend_section_flags \
5598 elf64_alpha_section_flags
5599 #define elf_backend_fake_sections \
5600 elf64_alpha_fake_sections
5602 #define bfd_elf64_bfd_is_local_label_name \
5603 elf64_alpha_is_local_label_name
5604 #define bfd_elf64_find_nearest_line \
5605 elf64_alpha_find_nearest_line
5606 #define bfd_elf64_bfd_relax_section \
5607 elf64_alpha_relax_section
5609 #define elf_backend_add_symbol_hook \
5610 elf64_alpha_add_symbol_hook
5611 #define elf_backend_check_relocs \
5612 elf64_alpha_check_relocs
5613 #define elf_backend_create_dynamic_sections \
5614 elf64_alpha_create_dynamic_sections
5615 #define elf_backend_adjust_dynamic_symbol \
5616 elf64_alpha_adjust_dynamic_symbol
5617 #define elf_backend_always_size_sections \
5618 elf64_alpha_always_size_sections
5619 #define elf_backend_size_dynamic_sections \
5620 elf64_alpha_size_dynamic_sections
5621 #define elf_backend_relocate_section \
5622 elf64_alpha_relocate_section
5623 #define elf_backend_finish_dynamic_symbol \
5624 elf64_alpha_finish_dynamic_symbol
5625 #define elf_backend_finish_dynamic_sections \
5626 elf64_alpha_finish_dynamic_sections
5627 #define bfd_elf64_bfd_final_link \
5628 elf64_alpha_final_link
5629 #define elf_backend_reloc_type_class \
5630 elf64_alpha_reloc_type_class
5632 #define elf_backend_ecoff_debug_swap \
5633 &elf64_alpha_ecoff_debug_swap
5635 #define elf_backend_size_info \
5638 /* A few constants that determine how the .plt section is set up. */
5639 #define elf_backend_want_got_plt 0
5640 #define elf_backend_plt_readonly 0
5641 #define elf_backend_want_plt_sym 1
5642 #define elf_backend_got_header_size 0
5643 #define elf_backend_plt_header_size PLT_HEADER_SIZE
5645 #include "elf64-target.h"
5647 /* FreeBSD support. */
5649 #undef TARGET_LITTLE_SYM
5650 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5651 #undef TARGET_LITTLE_NAME
5652 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5654 /* The kernel recognizes executables as valid only if they carry a
5655 "FreeBSD" label in the ELF header. So we put this label on all
5656 executables and (for simplicity) also all other object files. */
5658 static void elf64_alpha_fbsd_post_process_headers
5659 PARAMS ((bfd
*, struct bfd_link_info
*));
5662 elf64_alpha_fbsd_post_process_headers (abfd
, link_info
)
5664 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
;
5666 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
5668 i_ehdrp
= elf_elfheader (abfd
);
5670 /* Put an ABI label supported by FreeBSD >= 4.1. */
5671 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
5672 #ifdef OLD_FREEBSD_ABI_LABEL
5673 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5674 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5678 #undef elf_backend_post_process_headers
5679 #define elf_backend_post_process_headers \
5680 elf64_alpha_fbsd_post_process_headers
5683 #define elf64_bed elf64_alpha_fbsd_bed
5685 #include "elf64-target.h"