1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 97, 98, 1999 Free Software Foundation, Inc.
3 Contributed by Richard Henderson <rth@tamu.edu>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* We need a published ABI spec for this. Until one comes out, don't
22 assume this'll remain unchanged forever. */
29 #include "elf/alpha.h"
33 #define NO_COFF_RELOCS
34 #define NO_COFF_SYMBOLS
35 #define NO_COFF_LINENOS
37 /* Get the ECOFF swapping routines. Needed for the debug information. */
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
42 #include "coff/alpha.h"
47 #include "ecoffswap.h"
49 static boolean elf64_alpha_mkobject
PARAMS ((bfd
*));
50 static struct bfd_hash_entry
* elf64_alpha_link_hash_newfunc
51 PARAMS((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
52 static struct bfd_link_hash_table
* elf64_alpha_bfd_link_hash_table_create
55 static bfd_reloc_status_type elf64_alpha_reloc_nil
56 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
57 static bfd_reloc_status_type elf64_alpha_reloc_bad
58 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
59 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
60 PARAMS((bfd
*, bfd_vma
, bfd_byte
*, bfd_byte
*));
61 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
62 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
64 static reloc_howto_type
* elf64_alpha_bfd_reloc_type_lookup
65 PARAMS((bfd
*, bfd_reloc_code_real_type
));
66 static void elf64_alpha_info_to_howto
67 PARAMS((bfd
*, arelent
*, Elf64_Internal_Rela
*));
69 static boolean elf64_alpha_object_p
71 static boolean elf64_alpha_section_from_shdr
72 PARAMS((bfd
*, Elf64_Internal_Shdr
*, char *));
73 static boolean elf64_alpha_fake_sections
74 PARAMS((bfd
*, Elf64_Internal_Shdr
*, asection
*));
75 static boolean elf64_alpha_create_got_section
76 PARAMS((bfd
*, struct bfd_link_info
*));
77 static boolean elf64_alpha_create_dynamic_sections
78 PARAMS((bfd
*, struct bfd_link_info
*));
80 static boolean elf64_alpha_read_ecoff_info
81 PARAMS((bfd
*, asection
*, struct ecoff_debug_info
*));
82 static boolean elf64_alpha_is_local_label_name
83 PARAMS((bfd
*, const char *));
84 static boolean elf64_alpha_find_nearest_line
85 PARAMS((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
86 const char **, unsigned int *));
88 #if defined(__STDC__) || defined(ALMOST_STDC)
89 struct alpha_elf_link_hash_entry
;
92 static boolean elf64_alpha_output_extsym
93 PARAMS((struct alpha_elf_link_hash_entry
*, PTR
));
95 static boolean elf64_alpha_can_merge_gots
96 PARAMS((bfd
*, bfd
*));
97 static void elf64_alpha_merge_gots
98 PARAMS((bfd
*, bfd
*));
99 static boolean elf64_alpha_calc_got_offsets_for_symbol
100 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
101 static void elf64_alpha_calc_got_offsets
PARAMS ((struct bfd_link_info
*));
102 static boolean elf64_alpha_size_got_sections
103 PARAMS ((bfd
*, struct bfd_link_info
*));
104 static boolean elf64_alpha_always_size_sections
105 PARAMS ((bfd
*, struct bfd_link_info
*));
106 static boolean elf64_alpha_calc_dynrel_sizes
107 PARAMS ((struct alpha_elf_link_hash_entry
*, struct bfd_link_info
*));
108 static boolean elf64_alpha_add_symbol_hook
109 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
110 const char **, flagword
*, asection
**, bfd_vma
*));
111 static boolean elf64_alpha_check_relocs
112 PARAMS((bfd
*, struct bfd_link_info
*, asection
*sec
,
113 const Elf_Internal_Rela
*));
114 static boolean elf64_alpha_adjust_dynamic_symbol
115 PARAMS((struct bfd_link_info
*, struct elf_link_hash_entry
*));
116 static boolean elf64_alpha_size_dynamic_sections
117 PARAMS((bfd
*, struct bfd_link_info
*));
118 static boolean elf64_alpha_relocate_section
119 PARAMS((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
120 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
121 static boolean elf64_alpha_finish_dynamic_symbol
122 PARAMS((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
123 Elf_Internal_Sym
*));
124 static boolean elf64_alpha_finish_dynamic_sections
125 PARAMS((bfd
*, struct bfd_link_info
*));
126 static boolean elf64_alpha_final_link
127 PARAMS((bfd
*, struct bfd_link_info
*));
130 struct alpha_elf_link_hash_entry
132 struct elf_link_hash_entry root
;
134 /* External symbol information. */
137 /* Cumulative flags for all the .got entries. */
140 /* Contexts (LITUSE) in which a literal was referenced. */
141 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
142 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
143 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
144 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x08
146 /* Used to implement multiple .got subsections. */
147 struct alpha_elf_got_entry
149 struct alpha_elf_got_entry
*next
;
151 /* which .got subsection? */
154 /* the addend in effect for this entry. */
157 /* the .got offset for this entry. */
162 /* An additional flag. */
163 #define ALPHA_ELF_GOT_ENTRY_RELOCS_DONE 0x10
168 /* used to count non-got, non-plt relocations for delayed sizing
169 of relocation sections. */
170 struct alpha_elf_reloc_entry
172 struct alpha_elf_reloc_entry
*next
;
174 /* which .reloc section? */
177 /* what kind of relocation? */
180 /* how many did we find? */
185 /* Alpha ELF linker hash table. */
187 struct alpha_elf_link_hash_table
189 struct elf_link_hash_table root
;
191 /* The head of a list of .got subsections linked through
192 alpha_elf_tdata(abfd)->got_link_next. */
196 /* Look up an entry in a Alpha ELF linker hash table. */
198 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
199 ((struct alpha_elf_link_hash_entry *) \
200 elf_link_hash_lookup (&(table)->root, (string), (create), \
203 /* Traverse a Alpha ELF linker hash table. */
205 #define alpha_elf_link_hash_traverse(table, func, info) \
206 (elf_link_hash_traverse \
208 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
211 /* Get the Alpha ELF linker hash table from a link_info structure. */
213 #define alpha_elf_hash_table(p) \
214 ((struct alpha_elf_link_hash_table *) ((p)->hash))
216 /* Get the object's symbols as our own entry type. */
218 #define alpha_elf_sym_hashes(abfd) \
219 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
221 /* Should we do dynamic things to this symbol? */
223 #define alpha_elf_dynamic_symbol_p(h, info) \
224 ((((info)->shared && !(info)->symbolic) \
225 || (((h)->elf_link_hash_flags \
226 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
227 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
228 || (h)->root.type == bfd_link_hash_undefweak \
229 || (h)->root.type == bfd_link_hash_defweak) \
230 && (h)->dynindx != -1)
232 /* Create an entry in a Alpha ELF linker hash table. */
234 static struct bfd_hash_entry
*
235 elf64_alpha_link_hash_newfunc (entry
, table
, string
)
236 struct bfd_hash_entry
*entry
;
237 struct bfd_hash_table
*table
;
240 struct alpha_elf_link_hash_entry
*ret
=
241 (struct alpha_elf_link_hash_entry
*) entry
;
243 /* Allocate the structure if it has not already been allocated by a
245 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
246 ret
= ((struct alpha_elf_link_hash_entry
*)
247 bfd_hash_allocate (table
,
248 sizeof (struct alpha_elf_link_hash_entry
)));
249 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
250 return (struct bfd_hash_entry
*) ret
;
252 /* Call the allocation method of the superclass. */
253 ret
= ((struct alpha_elf_link_hash_entry
*)
254 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
256 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
258 /* Set local fields. */
259 memset (&ret
->esym
, 0, sizeof (EXTR
));
260 /* We use -2 as a marker to indicate that the information has
261 not been set. -1 means there is no associated ifd. */
264 ret
->got_entries
= NULL
;
265 ret
->reloc_entries
= NULL
;
268 return (struct bfd_hash_entry
*) ret
;
271 /* Create a Alpha ELF linker hash table. */
273 static struct bfd_link_hash_table
*
274 elf64_alpha_bfd_link_hash_table_create (abfd
)
277 struct alpha_elf_link_hash_table
*ret
;
279 ret
= ((struct alpha_elf_link_hash_table
*)
280 bfd_zalloc (abfd
, sizeof (struct alpha_elf_link_hash_table
)));
281 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
284 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
285 elf64_alpha_link_hash_newfunc
))
287 bfd_release (abfd
, ret
);
291 return &ret
->root
.root
;
294 /* We have some private fields hanging off of the elf_tdata structure. */
296 struct alpha_elf_obj_tdata
298 struct elf_obj_tdata root
;
300 /* For every input file, these are the got entries for that object's
302 struct alpha_elf_got_entry
** local_got_entries
;
304 /* For every input file, this is the object that owns the got that
305 this input file uses. */
308 /* For every got, this is a linked list through the objects using this got */
309 bfd
*in_got_link_next
;
311 /* For every got, this is a link to the next got subsegment. */
314 /* For every got, this is the section. */
317 /* For every got, this is it's total number of *entries*. */
318 int total_got_entries
;
320 /* For every got, this is the sum of the number of *entries* required
321 to hold all of the member object's local got. */
322 int n_local_got_entries
;
325 #define alpha_elf_tdata(abfd) \
326 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
329 elf64_alpha_mkobject (abfd
)
332 abfd
->tdata
.any
= bfd_zalloc (abfd
, sizeof (struct alpha_elf_obj_tdata
));
333 if (abfd
->tdata
.any
== NULL
)
339 elf64_alpha_object_p (abfd
)
342 /* Allocate our special target data. */
343 struct alpha_elf_obj_tdata
*new_tdata
;
344 new_tdata
= bfd_zalloc (abfd
, sizeof (struct alpha_elf_obj_tdata
));
345 if (new_tdata
== NULL
)
347 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
348 abfd
->tdata
.any
= new_tdata
;
350 /* Set the right machine number for an Alpha ELF file. */
351 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
354 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
355 from smaller values. Start with zero, widen, *then* decrement. */
356 #define MINUS_ONE (((bfd_vma)0) - 1)
358 static reloc_howto_type elf64_alpha_howto_table
[] =
360 HOWTO (R_ALPHA_NONE
, /* type */
362 0, /* size (0 = byte, 1 = short, 2 = long) */
364 true, /* pc_relative */
366 complain_overflow_dont
, /* complain_on_overflow */
367 elf64_alpha_reloc_nil
, /* special_function */
369 false, /* partial_inplace */
372 true), /* pcrel_offset */
374 /* A 32 bit reference to a symbol. */
375 HOWTO (R_ALPHA_REFLONG
, /* type */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_bitfield
, /* complain_on_overflow */
382 0, /* special_function */
383 "REFLONG", /* name */
384 false, /* partial_inplace */
385 0xffffffff, /* src_mask */
386 0xffffffff, /* dst_mask */
387 false), /* pcrel_offset */
389 /* A 64 bit reference to a symbol. */
390 HOWTO (R_ALPHA_REFQUAD
, /* type */
392 4, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_bitfield
, /* complain_on_overflow */
397 0, /* special_function */
398 "REFQUAD", /* name */
399 false, /* partial_inplace */
400 MINUS_ONE
, /* src_mask */
401 MINUS_ONE
, /* dst_mask */
402 false), /* pcrel_offset */
404 /* A 32 bit GP relative offset. This is just like REFLONG except
405 that when the value is used the value of the gp register will be
407 HOWTO (R_ALPHA_GPREL32
, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_bitfield
, /* complain_on_overflow */
414 0, /* special_function */
415 "GPREL32", /* name */
416 false, /* partial_inplace */
417 0xffffffff, /* src_mask */
418 0xffffffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* Used for an instruction that refers to memory off the GP register. */
422 HOWTO (R_ALPHA_LITERAL
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 0, /* special_function */
430 "ELF_LITERAL", /* name */
431 false, /* partial_inplace */
432 0xffff, /* src_mask */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* This reloc only appears immediately following an ELF_LITERAL reloc.
437 It identifies a use of the literal. The symbol index is special:
438 1 means the literal address is in the base register of a memory
439 format instruction; 2 means the literal address is in the byte
440 offset register of a byte-manipulation instruction; 3 means the
441 literal address is in the target register of a jsr instruction.
442 This does not actually do any relocation. */
443 HOWTO (R_ALPHA_LITUSE
, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 false, /* pc_relative */
449 complain_overflow_dont
, /* complain_on_overflow */
450 elf64_alpha_reloc_nil
, /* special_function */
452 false, /* partial_inplace */
455 false), /* pcrel_offset */
457 /* Load the gp register. This is always used for a ldah instruction
458 which loads the upper 16 bits of the gp register. The symbol
459 index of the GPDISP instruction is an offset in bytes to the lda
460 instruction that loads the lower 16 bits. The value to use for
461 the relocation is the difference between the GP value and the
462 current location; the load will always be done against a register
463 holding the current address.
465 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
466 any offset is present in the instructions, it is an offset from
467 the register to the ldah instruction. This lets us avoid any
468 stupid hackery like inventing a gp value to do partial relocation
469 against. Also unlike ECOFF, we do the whole relocation off of
470 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
471 space consuming bit, that, since all the information was present
472 in the GPDISP_HI16 reloc. */
473 HOWTO (R_ALPHA_GPDISP
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_dont
, /* complain_on_overflow */
480 elf64_alpha_reloc_gpdisp
, /* special_function */
482 false, /* partial_inplace */
483 0xffff, /* src_mask */
484 0xffff, /* dst_mask */
485 true), /* pcrel_offset */
487 /* A 21 bit branch. */
488 HOWTO (R_ALPHA_BRADDR
, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 true, /* pc_relative */
494 complain_overflow_signed
, /* complain_on_overflow */
495 0, /* special_function */
497 false, /* partial_inplace */
498 0x1fffff, /* src_mask */
499 0x1fffff, /* dst_mask */
500 true), /* pcrel_offset */
502 /* A hint for a jump to a register. */
503 HOWTO (R_ALPHA_HINT
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 true, /* pc_relative */
509 complain_overflow_dont
, /* complain_on_overflow */
510 0, /* special_function */
512 false, /* partial_inplace */
513 0x3fff, /* src_mask */
514 0x3fff, /* dst_mask */
515 true), /* pcrel_offset */
517 /* 16 bit PC relative offset. */
518 HOWTO (R_ALPHA_SREL16
, /* type */
520 1, /* size (0 = byte, 1 = short, 2 = long) */
522 true, /* pc_relative */
524 complain_overflow_signed
, /* complain_on_overflow */
525 0, /* special_function */
527 false, /* partial_inplace */
528 0xffff, /* src_mask */
529 0xffff, /* dst_mask */
530 false), /* pcrel_offset */
532 /* 32 bit PC relative offset. */
533 HOWTO (R_ALPHA_SREL32
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 true, /* pc_relative */
539 complain_overflow_signed
, /* complain_on_overflow */
540 0, /* special_function */
542 false, /* partial_inplace */
543 0xffffffff, /* src_mask */
544 0xffffffff, /* dst_mask */
545 false), /* pcrel_offset */
547 /* A 64 bit PC relative offset. */
548 HOWTO (R_ALPHA_SREL64
, /* type */
550 4, /* size (0 = byte, 1 = short, 2 = long) */
552 true, /* pc_relative */
554 complain_overflow_signed
, /* complain_on_overflow */
555 0, /* special_function */
557 false, /* partial_inplace */
558 MINUS_ONE
, /* src_mask */
559 MINUS_ONE
, /* dst_mask */
560 false), /* pcrel_offset */
562 /* Push a value on the reloc evaluation stack. */
563 /* Not implemented -- it's dumb. */
564 HOWTO (R_ALPHA_OP_PUSH
, /* type */
566 0, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 elf64_alpha_reloc_bad
, /* special_function */
572 "OP_PUSH", /* name */
573 false, /* partial_inplace */
576 false), /* pcrel_offset */
578 /* Store the value from the stack at the given address. Store it in
579 a bitfield of size r_size starting at bit position r_offset. */
580 /* Not implemented -- it's dumb. */
581 HOWTO (R_ALPHA_OP_STORE
, /* type */
583 4, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_dont
, /* complain_on_overflow */
588 elf64_alpha_reloc_bad
, /* special_function */
589 "OP_STORE", /* name */
590 false, /* partial_inplace */
592 MINUS_ONE
, /* dst_mask */
593 false), /* pcrel_offset */
595 /* Subtract the reloc address from the value on the top of the
597 /* Not implemented -- it's dumb. */
598 HOWTO (R_ALPHA_OP_PSUB
, /* type */
600 0, /* size (0 = byte, 1 = short, 2 = long) */
602 false, /* pc_relative */
604 complain_overflow_dont
, /* complain_on_overflow */
605 elf64_alpha_reloc_bad
, /* special_function */
606 "OP_PSUB", /* name */
607 false, /* partial_inplace */
610 false), /* pcrel_offset */
612 /* Shift the value on the top of the relocation stack right by the
614 /* Not implemented -- it's dumb. */
615 HOWTO (R_ALPHA_OP_PRSHIFT
, /* type */
617 0, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_dont
, /* complain_on_overflow */
622 elf64_alpha_reloc_bad
, /* special_function */
623 "OP_PRSHIFT", /* name */
624 false, /* partial_inplace */
627 false), /* pcrel_offset */
629 /* Change the value of GP used by +r_addend until the next GPVALUE or the
630 end of the input bfd. */
631 /* Not implemented -- it's dumb. */
632 HOWTO (R_ALPHA_GPVALUE
,
634 0, /* size (0 = byte, 1 = short, 2 = long) */
636 false, /* pc_relative */
638 complain_overflow_dont
, /* complain_on_overflow */
639 elf64_alpha_reloc_bad
, /* special_function */
640 "GPVALUE", /* name */
641 false, /* partial_inplace */
644 false), /* pcrel_offset */
646 /* The high 16 bits of the displacement from GP to the target. */
647 HOWTO (R_ALPHA_GPRELHIGH
,
649 2, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_signed
, /* complain_on_overflow */
654 elf64_alpha_reloc_bad
, /* special_function */
655 "GPRELHIGH", /* name */
656 false, /* partial_inplace */
657 0xffff, /* src_mask */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
661 /* The low 16 bits of the displacement from GP to the target. */
662 HOWTO (R_ALPHA_GPRELLOW
,
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 false, /* pc_relative */
668 complain_overflow_dont
, /* complain_on_overflow */
669 elf64_alpha_reloc_bad
, /* special_function */
670 "GPRELLOW", /* name */
671 false, /* partial_inplace */
672 0xffff, /* src_mask */
673 0xffff, /* dst_mask */
674 false), /* pcrel_offset */
676 /* A 16-bit displacement from the GP to the target. */
677 /* XXX: Not implemented. */
678 HOWTO (R_ALPHA_IMMED_GP_16
,
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 false, /* pc_relative */
684 complain_overflow_signed
, /* complain_on_overflow */
685 0, /* special_function */
686 "IMMED_GP_16", /* name */
687 false, /* partial_inplace */
688 0xffff, /* src_mask */
689 0xffff, /* dst_mask */
690 false), /* pcrel_offset */
692 /* The high bits of a 32-bit displacement from the GP to the target; the
693 low bits are supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
694 /* XXX: Not implemented. */
695 HOWTO (R_ALPHA_IMMED_GP_HI32
,
697 0, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_dont
, /* complain_on_overflow */
702 elf64_alpha_reloc_bad
, /* special_function */
703 "IMMED_GP_HI32", /* name */
704 false, /* partial_inplace */
707 false), /* pcrel_offset */
709 /* The high bits of a 32-bit displacement to the starting address of the
710 current section (the relocation target is ignored); the low bits are
711 supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
712 /* XXX: Not implemented. */
713 HOWTO (R_ALPHA_IMMED_SCN_HI32
,
715 0, /* size (0 = byte, 1 = short, 2 = long) */
717 false, /* pc_relative */
719 complain_overflow_dont
, /* complain_on_overflow */
720 elf64_alpha_reloc_bad
, /* special_function */
721 "IMMED_SCN_HI32", /* name */
722 false, /* partial_inplace */
725 false), /* pcrel_offset */
727 /* The high bits of a 32-bit displacement from the previous br, bsr, jsr
728 or jmp insn (as tagged by a BRADDR or HINT reloc) to the target; the
729 low bits are supplied by subsequent R_ALPHA_IMMED_LO32 relocs. */
730 /* XXX: Not implemented. */
731 HOWTO (R_ALPHA_IMMED_BR_HI32
,
733 0, /* size (0 = byte, 1 = short, 2 = long) */
735 false, /* pc_relative */
737 complain_overflow_dont
, /* complain_on_overflow */
738 elf64_alpha_reloc_bad
, /* special_function */
739 "IMMED_BR_HI32", /* name */
740 false, /* partial_inplace */
743 false), /* pcrel_offset */
745 /* The low 16 bits of a displacement calculated in a previous HI32 reloc. */
746 /* XXX: Not implemented. */
747 HOWTO (R_ALPHA_IMMED_LO32
,
749 0, /* size (0 = byte, 1 = short, 2 = long) */
751 false, /* pc_relative */
753 complain_overflow_dont
, /* complain_on_overflow */
754 elf64_alpha_reloc_bad
, /* special_function */
755 "IMMED_LO32", /* name */
756 false, /* partial_inplace */
759 false), /* pcrel_offset */
761 /* Misc ELF relocations. */
763 /* A dynamic relocation to copy the target into our .dynbss section. */
764 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
765 is present because every other ELF has one, but should not be used
766 because .dynbss is an ugly thing. */
773 complain_overflow_dont
,
774 bfd_elf_generic_reloc
,
781 /* A dynamic relocation for a .got entry. */
782 HOWTO (R_ALPHA_GLOB_DAT
,
788 complain_overflow_dont
,
789 bfd_elf_generic_reloc
,
796 /* A dynamic relocation for a .plt entry. */
797 HOWTO (R_ALPHA_JMP_SLOT
,
803 complain_overflow_dont
,
804 bfd_elf_generic_reloc
,
811 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
812 HOWTO (R_ALPHA_RELATIVE
,
818 complain_overflow_dont
,
819 bfd_elf_generic_reloc
,
827 /* A relocation function which doesn't do anything. */
829 static bfd_reloc_status_type
830 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
837 char **error_message
;
840 reloc
->address
+= sec
->output_offset
;
844 /* A relocation function used for an unsupported reloc. */
846 static bfd_reloc_status_type
847 elf64_alpha_reloc_bad (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
854 char **error_message
;
857 reloc
->address
+= sec
->output_offset
;
858 return bfd_reloc_notsupported
;
861 /* Do the work of the GPDISP relocation. */
863 static bfd_reloc_status_type
864 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
870 bfd_reloc_status_type ret
= bfd_reloc_ok
;
872 unsigned long i_ldah
, i_lda
;
874 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
875 i_lda
= bfd_get_32 (abfd
, p_lda
);
877 /* Complain if the instructions are not correct. */
878 if (((i_ldah
>> 26) & 0x3f) != 0x09
879 || ((i_lda
>> 26) & 0x3f) != 0x08)
880 ret
= bfd_reloc_dangerous
;
882 /* Extract the user-supplied offset, mirroring the sign extensions
883 that the instructions perform. */
884 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
885 addend
= (addend
^ 0x80008000) - 0x80008000;
889 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
) 0x80000000
890 || (bfd_signed_vma
) gpdisp
>= (bfd_signed_vma
) 0x7fff8000)
891 ret
= bfd_reloc_overflow
;
893 /* compensate for the sign extension again. */
894 i_ldah
= ((i_ldah
& 0xffff0000)
895 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
896 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
898 bfd_put_32 (abfd
, i_ldah
, p_ldah
);
899 bfd_put_32 (abfd
, i_lda
, p_lda
);
904 /* The special function for the GPDISP reloc. */
906 static bfd_reloc_status_type
907 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
910 arelent
*reloc_entry
;
913 asection
*input_section
;
917 bfd_reloc_status_type ret
;
918 bfd_vma gp
, relocation
;
919 bfd_byte
*p_ldah
, *p_lda
;
921 /* Don't do anything if we're not doing a final link. */
924 reloc_entry
->address
+= input_section
->output_offset
;
928 if (reloc_entry
->address
> input_section
->_cooked_size
||
929 reloc_entry
->address
+ reloc_entry
->addend
> input_section
->_cooked_size
)
930 return bfd_reloc_outofrange
;
932 /* The gp used in the portion of the output object to which this
933 input object belongs is cached on the input bfd. */
934 gp
= _bfd_get_gp_value (abfd
);
936 relocation
= (input_section
->output_section
->vma
937 + input_section
->output_offset
938 + reloc_entry
->address
);
940 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
941 p_lda
= p_ldah
+ reloc_entry
->addend
;
943 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
945 /* Complain if the instructions are not correct. */
946 if (ret
== bfd_reloc_dangerous
)
947 *err_msg
= _("GPDISP relocation did not find ldah and lda instructions");
952 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
956 bfd_reloc_code_real_type bfd_reloc_val
;
960 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
962 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
963 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
964 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
965 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
966 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
967 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
968 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
969 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
970 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
971 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
972 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
973 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
974 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
976 /* The BFD_RELOC_ALPHA_USER_* relocations are used by the assembler to process
977 the explicit !<reloc>!sequence relocations, and are mapped into the normal
978 relocations at the end of processing. */
979 {BFD_RELOC_ALPHA_USER_LITERAL
, R_ALPHA_LITERAL
},
980 {BFD_RELOC_ALPHA_USER_LITUSE_BASE
, R_ALPHA_LITUSE
},
981 {BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF
, R_ALPHA_LITUSE
},
982 {BFD_RELOC_ALPHA_USER_LITUSE_JSR
, R_ALPHA_LITUSE
},
983 {BFD_RELOC_ALPHA_USER_GPDISP
, R_ALPHA_GPDISP
},
984 {BFD_RELOC_ALPHA_USER_GPRELHIGH
, R_ALPHA_GPRELHIGH
},
985 {BFD_RELOC_ALPHA_USER_GPRELLOW
, R_ALPHA_GPRELLOW
},
988 /* Given a BFD reloc type, return a HOWTO structure. */
990 static reloc_howto_type
*
991 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
993 bfd_reloc_code_real_type code
;
995 const struct elf_reloc_map
*i
, *e
;
996 i
= e
= elf64_alpha_reloc_map
;
997 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
1000 if (i
->bfd_reloc_val
== code
)
1001 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
1006 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1009 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
1012 Elf64_Internal_Rela
*dst
;
1016 r_type
= ELF64_R_TYPE(dst
->r_info
);
1017 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1018 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1021 /* These functions do relaxation for Alpha ELF.
1023 Currently I'm only handling what I can do with existing compiler
1024 and assembler support, which means no instructions are removed,
1025 though some may be nopped. At this time GCC does not emit enough
1026 information to do all of the relaxing that is possible. It will
1027 take some not small amount of work for that to happen.
1029 There are a couple of interesting papers that I once read on this
1030 subject, that I cannot find references to at the moment, that
1031 related to Alpha in particular. They are by David Wall, then of
1035 #define OP_LDAH 0x09
1036 #define INSN_JSR 0x68004000
1037 #define INSN_JSR_MASK 0xfc00c000
1041 #define INSN_UNOP 0x2fe00000
1043 struct alpha_relax_info
1048 Elf_Internal_Rela
*relocs
, *relend
;
1049 struct bfd_link_info
*link_info
;
1050 boolean changed_contents
;
1051 boolean changed_relocs
;
1055 struct alpha_elf_link_hash_entry
*h
;
1056 struct alpha_elf_got_entry
*gotent
;
1057 unsigned char other
;
1060 static Elf_Internal_Rela
* elf64_alpha_relax_with_lituse
1061 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1062 Elf_Internal_Rela
*irel
, Elf_Internal_Rela
*irelend
));
1064 static boolean elf64_alpha_relax_without_lituse
1065 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1066 Elf_Internal_Rela
*irel
));
1068 static bfd_vma elf64_alpha_relax_opt_call
1069 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
));
1071 static boolean elf64_alpha_relax_section
1072 PARAMS((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
1075 static Elf_Internal_Rela
*
1076 elf64_alpha_find_reloc_at_ofs (rel
, relend
, offset
, type
)
1077 Elf_Internal_Rela
*rel
, *relend
;
1081 while (rel
< relend
)
1083 if (rel
->r_offset
== offset
&& ELF64_R_TYPE (rel
->r_info
) == type
)
1090 static Elf_Internal_Rela
*
1091 elf64_alpha_relax_with_lituse (info
, symval
, irel
, irelend
)
1092 struct alpha_relax_info
*info
;
1094 Elf_Internal_Rela
*irel
, *irelend
;
1096 Elf_Internal_Rela
*urel
;
1097 int flags
, count
, i
;
1098 bfd_signed_vma disp
;
1101 boolean lit_reused
= false;
1102 boolean all_optimized
= true;
1103 unsigned int lit_insn
;
1105 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1106 if (lit_insn
>> 26 != OP_LDQ
)
1108 ((*_bfd_error_handler
)
1109 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1110 bfd_get_filename (info
->abfd
), info
->sec
->name
,
1111 (unsigned long)irel
->r_offset
));
1115 /* Summarize how this particular LITERAL is used. */
1116 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
1118 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
1120 if (urel
->r_addend
>= 0 && urel
->r_addend
<= 3)
1121 flags
|= 1 << urel
->r_addend
;
1124 /* A little preparation for the loop... */
1125 disp
= symval
- info
->gp
;
1126 fits16
= (disp
>= -(bfd_signed_vma
)0x8000 && disp
< 0x8000);
1127 fits32
= (disp
>= -(bfd_signed_vma
)0x80000000 && disp
< 0x7fff8000);
1129 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
1132 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
1134 switch (urel
->r_addend
)
1136 default: /* 0 = ADDRESS FORMAT */
1137 /* This type is really just a placeholder to note that all
1138 uses cannot be optimized, but to still allow some. */
1139 all_optimized
= false;
1142 case 1: /* MEM FORMAT */
1143 /* We can always optimize 16-bit displacements. */
1146 /* FIXME: sanity check the insn for mem format with
1149 /* Take the op code and dest from this insn, take the base
1150 register from the literal insn. Leave the offset alone. */
1151 insn
= (insn
& 0xffe00000) | (lit_insn
& 0x001f0000);
1152 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1154 urel
->r_addend
= irel
->r_addend
;
1155 info
->changed_relocs
= true;
1157 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ urel
->r_offset
);
1158 info
->changed_contents
= true;
1161 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1162 else if (fits32
&& !(flags
& ~6))
1164 /* FIXME: sanity check that lit insn Ra is mem insn Rb, and
1165 that mem_insn disp is zero. */
1167 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1169 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
1170 bfd_put_32 (info
->abfd
, lit_insn
,
1171 info
->contents
+ irel
->r_offset
);
1173 info
->changed_contents
= true;
1175 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1177 urel
->r_addend
= irel
->r_addend
;
1178 info
->changed_relocs
= true;
1181 all_optimized
= false;
1184 case 2: /* BYTE OFFSET FORMAT */
1185 /* We can always optimize byte instructions. */
1187 /* FIXME: sanity check the insn for byte op. Check that the
1188 literal dest reg is indeed Rb in the byte insn. */
1190 insn
= (insn
& ~0x001ff000) | ((symval
& 7) << 13) | 0x1000;
1192 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1194 info
->changed_relocs
= true;
1196 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ urel
->r_offset
);
1197 info
->changed_contents
= true;
1200 case 3: /* CALL FORMAT */
1202 /* If not zero, place to jump without needing pv. */
1203 bfd_vma optdest
= elf64_alpha_relax_opt_call (info
, symval
);
1204 bfd_vma org
= (info
->sec
->output_section
->vma
1205 + info
->sec
->output_offset
1206 + urel
->r_offset
+ 4);
1207 bfd_signed_vma odisp
;
1209 odisp
= (optdest
? optdest
: symval
) - org
;
1210 if (odisp
>= -0x400000 && odisp
< 0x400000)
1212 Elf_Internal_Rela
*xrel
;
1214 /* Preserve branch prediction call stack when possible. */
1215 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
1216 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
1218 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
1220 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1222 urel
->r_addend
= irel
->r_addend
;
1225 urel
->r_addend
+= optdest
- symval
;
1227 all_optimized
= false;
1229 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ urel
->r_offset
);
1231 /* Kill any HINT reloc that might exist for this insn. */
1232 xrel
= (elf64_alpha_find_reloc_at_ofs
1233 (info
->relocs
, info
->relend
, urel
->r_offset
,
1236 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1238 info
->changed_contents
= true;
1239 info
->changed_relocs
= true;
1242 all_optimized
= false;
1244 /* ??? If target gp == current gp we can eliminate the gp reload.
1245 This does depend on every place a gp could be reloaded will
1246 be, which currently happens for all code produced by gcc, but
1247 not necessarily by hand-coded assembly, or if sibling calls
1250 Perhaps conditionalize this on a flag being set in the target
1251 object file's header, and have gcc set it? */
1257 /* If all cases were optimized, we can reduce the use count on this
1258 got entry by one, possibly eliminating it. */
1261 info
->gotent
->use_count
-= 1;
1262 alpha_elf_tdata (info
->gotent
->gotobj
)->total_got_entries
-= 1;
1264 alpha_elf_tdata (info
->gotent
->gotobj
)->n_local_got_entries
-= 1;
1266 /* If the literal instruction is no longer needed (it may have been
1267 reused. We can eliminate it.
1268 ??? For now, I don't want to deal with compacting the section,
1269 so just nop it out. */
1272 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1273 info
->changed_relocs
= true;
1275 bfd_put_32 (info
->abfd
, INSN_UNOP
, info
->contents
+ irel
->r_offset
);
1276 info
->changed_contents
= true;
1280 return irel
+ count
;
1284 elf64_alpha_relax_opt_call (info
, symval
)
1285 struct alpha_relax_info
*info
;
1288 /* If the function has the same gp, and we can identify that the
1289 function does not use its function pointer, we can eliminate the
1292 /* If the symbol is marked NOPV, we are being told the function never
1293 needs its procedure value. */
1294 if (info
->other
== STO_ALPHA_NOPV
)
1297 /* If the symbol is marked STD_GP, we are being told the function does
1298 a normal ldgp in the first two words. */
1299 else if (info
->other
== STO_ALPHA_STD_GPLOAD
)
1302 /* Otherwise, we may be able to identify a GP load in the first two
1303 words, which we can then skip. */
1306 Elf_Internal_Rela
*tsec_relocs
, *tsec_relend
, *tsec_free
, *gpdisp
;
1309 /* Load the relocations from the section that the target symbol is in. */
1310 if (info
->sec
== info
->tsec
)
1312 tsec_relocs
= info
->relocs
;
1313 tsec_relend
= info
->relend
;
1318 tsec_relocs
= (_bfd_elf64_link_read_relocs
1319 (info
->abfd
, info
->tsec
, (PTR
) NULL
,
1320 (Elf_Internal_Rela
*) NULL
,
1321 info
->link_info
->keep_memory
));
1322 if (tsec_relocs
== NULL
)
1324 tsec_relend
= tsec_relocs
+ info
->tsec
->reloc_count
;
1325 tsec_free
= (info
->link_info
->keep_memory
? NULL
: tsec_relocs
);
1328 /* Recover the symbol's offset within the section. */
1329 ofs
= (symval
- info
->tsec
->output_section
->vma
1330 - info
->tsec
->output_offset
);
1332 /* Look for a GPDISP reloc. */
1333 gpdisp
= (elf64_alpha_find_reloc_at_ofs
1334 (tsec_relocs
, tsec_relend
, ofs
, R_ALPHA_GPDISP
));
1336 if (!gpdisp
|| gpdisp
->r_addend
!= 4)
1346 /* We've now determined that we can skip an initial gp load. Verify
1347 that the call and the target use the same gp. */
1348 if (info
->link_info
->hash
->creator
!= info
->tsec
->owner
->xvec
1349 || info
->gotobj
!= alpha_elf_tdata (info
->tsec
->owner
)->gotobj
)
1356 elf64_alpha_relax_without_lituse (info
, symval
, irel
)
1357 struct alpha_relax_info
*info
;
1359 Elf_Internal_Rela
*irel
;
1362 bfd_signed_vma disp
;
1364 /* Get the instruction. */
1365 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1367 if (insn
>> 26 != OP_LDQ
)
1369 ((*_bfd_error_handler
)
1370 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1371 bfd_get_filename (info
->abfd
), info
->sec
->name
,
1372 (unsigned long) irel
->r_offset
));
1376 /* So we aren't told much. Do what we can with the address load and
1377 fake the rest. All of the optimizations here require that the
1378 offset from the GP fit in 16 bits. */
1380 disp
= symval
- info
->gp
;
1381 if (disp
< -0x8000 || disp
>= 0x8000)
1384 /* On the LITERAL instruction itself, consider exchanging
1385 `ldq R,X(gp)' for `lda R,Y(gp)'. */
1387 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
1388 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ irel
->r_offset
);
1389 info
->changed_contents
= true;
1391 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), R_ALPHA_GPRELLOW
);
1392 info
->changed_relocs
= true;
1394 /* Reduce the use count on this got entry by one, possibly
1396 info
->gotent
->use_count
-= 1;
1397 alpha_elf_tdata (info
->gotent
->gotobj
)->total_got_entries
-= 1;
1399 alpha_elf_tdata (info
->gotent
->gotobj
)->n_local_got_entries
-= 1;
1401 /* ??? Search forward through this basic block looking for insns
1402 that use the target register. Stop after an insn modifying the
1403 register is seen, or after a branch or call.
1405 Any such memory load insn may be substituted by a load directly
1406 off the GP. This allows the memory load insn to be issued before
1407 the calculated GP register would otherwise be ready.
1409 Any such jsr insn can be replaced by a bsr if it is in range.
1411 This would mean that we'd have to _add_ relocations, the pain of
1412 which gives one pause. */
1418 elf64_alpha_relax_section (abfd
, sec
, link_info
, again
)
1421 struct bfd_link_info
*link_info
;
1424 Elf_Internal_Shdr
*symtab_hdr
;
1425 Elf_Internal_Rela
*internal_relocs
;
1426 Elf_Internal_Rela
*free_relocs
= NULL
;
1427 Elf_Internal_Rela
*irel
, *irelend
;
1428 bfd_byte
*free_contents
= NULL
;
1429 Elf64_External_Sym
*extsyms
= NULL
;
1430 Elf64_External_Sym
*free_extsyms
= NULL
;
1431 struct alpha_elf_got_entry
**local_got_entries
;
1432 struct alpha_relax_info info
;
1434 /* We are not currently changing any sizes, so only one pass. */
1437 if (link_info
->relocateable
1438 || (sec
->flags
& SEC_RELOC
) == 0
1439 || sec
->reloc_count
== 0)
1442 /* If this is the first time we have been called for this section,
1443 initialize the cooked size. */
1444 if (sec
->_cooked_size
== 0)
1445 sec
->_cooked_size
= sec
->_raw_size
;
1447 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1448 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
1450 /* Load the relocations for this section. */
1451 internal_relocs
= (_bfd_elf64_link_read_relocs
1452 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1453 link_info
->keep_memory
));
1454 if (internal_relocs
== NULL
)
1456 if (! link_info
->keep_memory
)
1457 free_relocs
= internal_relocs
;
1459 memset(&info
, 0, sizeof(info
));
1462 info
.link_info
= link_info
;
1463 info
.relocs
= internal_relocs
;
1464 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
1466 /* Find the GP for this object. */
1467 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
1470 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
1471 info
.gp
= _bfd_get_gp_value (info
.gotobj
);
1474 info
.gp
= (sgot
->output_section
->vma
1475 + sgot
->output_offset
1477 _bfd_set_gp_value (info
.gotobj
, info
.gp
);
1481 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1484 Elf_Internal_Sym isym
;
1485 struct alpha_elf_got_entry
*gotent
;
1487 if (ELF64_R_TYPE (irel
->r_info
) != (int) R_ALPHA_LITERAL
)
1490 /* Get the section contents. */
1491 if (info
.contents
== NULL
)
1493 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1494 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
1497 info
.contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
1498 if (info
.contents
== NULL
)
1500 free_contents
= info
.contents
;
1502 if (! bfd_get_section_contents (abfd
, sec
, info
.contents
,
1503 (file_ptr
) 0, sec
->_raw_size
))
1508 /* Read this BFD's symbols if we haven't done so already. */
1509 if (extsyms
== NULL
)
1511 if (symtab_hdr
->contents
!= NULL
)
1512 extsyms
= (Elf64_External_Sym
*) symtab_hdr
->contents
;
1515 extsyms
= ((Elf64_External_Sym
*)
1516 bfd_malloc (symtab_hdr
->sh_size
));
1517 if (extsyms
== NULL
)
1519 free_extsyms
= extsyms
;
1520 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
1521 || (bfd_read (extsyms
, 1, symtab_hdr
->sh_size
, abfd
)
1522 != symtab_hdr
->sh_size
))
1527 /* Get the value of the symbol referred to by the reloc. */
1528 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1530 /* A local symbol. */
1531 bfd_elf64_swap_symbol_in (abfd
,
1532 extsyms
+ ELF64_R_SYM (irel
->r_info
),
1534 if (isym
.st_shndx
== SHN_UNDEF
)
1535 info
.tsec
= bfd_und_section_ptr
;
1536 else if (isym
.st_shndx
> 0 && isym
.st_shndx
< SHN_LORESERVE
)
1537 info
.tsec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
1538 else if (isym
.st_shndx
== SHN_ABS
)
1539 info
.tsec
= bfd_abs_section_ptr
;
1540 else if (isym
.st_shndx
== SHN_COMMON
)
1541 info
.tsec
= bfd_com_section_ptr
;
1543 continue; /* who knows. */
1546 info
.other
= isym
.st_other
;
1547 gotent
= local_got_entries
[ELF64_R_SYM(irel
->r_info
)];
1548 symval
= isym
.st_value
;
1553 struct alpha_elf_link_hash_entry
*h
;
1555 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1556 h
= alpha_elf_sym_hashes (abfd
)[indx
];
1557 BFD_ASSERT (h
!= NULL
);
1559 while (h
->root
.root
.type
== bfd_link_hash_indirect
1560 || h
->root
.root
.type
== bfd_link_hash_warning
)
1561 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1563 /* We can't do anthing with undefined or dynamic symbols. */
1564 if (h
->root
.root
.type
== bfd_link_hash_undefined
1565 || h
->root
.root
.type
== bfd_link_hash_undefweak
1566 || alpha_elf_dynamic_symbol_p (&h
->root
, link_info
))
1570 info
.gotent
= gotent
;
1571 info
.tsec
= h
->root
.root
.u
.def
.section
;
1572 info
.other
= h
->root
.other
;
1573 gotent
= h
->got_entries
;
1574 symval
= h
->root
.root
.u
.def
.value
;
1577 /* Search for the got entry to be used by this relocation. */
1578 while (gotent
->gotobj
!= info
.gotobj
|| gotent
->addend
!= irel
->r_addend
)
1579 gotent
= gotent
->next
;
1580 info
.gotent
= gotent
;
1582 symval
+= info
.tsec
->output_section
->vma
+ info
.tsec
->output_offset
;
1583 symval
+= irel
->r_addend
;
1585 BFD_ASSERT(info
.gotent
!= NULL
);
1587 /* If there exist LITUSE relocations immediately following, this
1588 opens up all sorts of interesting optimizations, because we
1589 now know every location that this address load is used. */
1591 if (irel
+1 < irelend
&& ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
1593 irel
= elf64_alpha_relax_with_lituse (&info
, symval
, irel
, irelend
);
1599 if (!elf64_alpha_relax_without_lituse (&info
, symval
, irel
))
1604 if (!elf64_alpha_size_got_sections (abfd
, link_info
))
1607 if (info
.changed_relocs
)
1609 elf_section_data (sec
)->relocs
= internal_relocs
;
1611 else if (free_relocs
!= NULL
)
1616 if (info
.changed_contents
)
1618 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
1620 else if (free_contents
!= NULL
)
1622 if (! link_info
->keep_memory
)
1623 free (free_contents
);
1626 /* Cache the section contents for elf_link_input_bfd. */
1627 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
1631 if (free_extsyms
!= NULL
)
1633 if (! link_info
->keep_memory
)
1634 free (free_extsyms
);
1637 /* Cache the symbols for elf_link_input_bfd. */
1638 symtab_hdr
->contents
= extsyms
;
1642 *again
= info
.changed_contents
|| info
.changed_relocs
;
1647 if (free_relocs
!= NULL
)
1649 if (free_contents
!= NULL
)
1650 free (free_contents
);
1651 if (free_extsyms
!= NULL
)
1652 free (free_extsyms
);
1657 #define PLT_HEADER_SIZE 32
1658 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
1659 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
1660 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
1661 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
1663 #define PLT_ENTRY_SIZE 12
1664 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
1665 #define PLT_ENTRY_WORD2 0
1666 #define PLT_ENTRY_WORD3 0
1668 #define MAX_GOT_ENTRIES (64*1024 / 8)
1670 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
1672 /* Handle an Alpha specific section when reading an object file. This
1673 is called when elfcode.h finds a section with an unknown type.
1674 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
1678 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
1680 Elf64_Internal_Shdr
*hdr
;
1685 /* There ought to be a place to keep ELF backend specific flags, but
1686 at the moment there isn't one. We just keep track of the
1687 sections by their name, instead. Fortunately, the ABI gives
1688 suggested names for all the MIPS specific sections, so we will
1689 probably get away with this. */
1690 switch (hdr
->sh_type
)
1692 case SHT_ALPHA_DEBUG
:
1693 if (strcmp (name
, ".mdebug") != 0)
1696 #ifdef ERIC_neverdef
1697 case SHT_ALPHA_REGINFO
:
1698 if (strcmp (name
, ".reginfo") != 0
1699 || hdr
->sh_size
!= sizeof (Elf64_External_RegInfo
))
1707 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1709 newsect
= hdr
->bfd_section
;
1711 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
1713 if (! bfd_set_section_flags (abfd
, newsect
,
1714 (bfd_get_section_flags (abfd
, newsect
)
1719 #ifdef ERIC_neverdef
1720 /* For a .reginfo section, set the gp value in the tdata information
1721 from the contents of this section. We need the gp value while
1722 processing relocs, so we just get it now. */
1723 if (hdr
->sh_type
== SHT_ALPHA_REGINFO
)
1725 Elf64_External_RegInfo ext
;
1728 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
1729 (file_ptr
) 0, sizeof ext
))
1731 bfd_alpha_elf64_swap_reginfo_in (abfd
, &ext
, &s
);
1732 elf_gp (abfd
) = s
.ri_gp_value
;
1739 /* Set the correct type for an Alpha ELF section. We do this by the
1740 section name, which is a hack, but ought to work. */
1743 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
1745 Elf64_Internal_Shdr
*hdr
;
1748 register const char *name
;
1750 name
= bfd_get_section_name (abfd
, sec
);
1752 if (strcmp (name
, ".mdebug") == 0)
1754 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
1755 /* In a shared object on Irix 5.3, the .mdebug section has an
1756 entsize of 0. FIXME: Does this matter? */
1757 if ((abfd
->flags
& DYNAMIC
) != 0 )
1758 hdr
->sh_entsize
= 0;
1760 hdr
->sh_entsize
= 1;
1762 #ifdef ERIC_neverdef
1763 else if (strcmp (name
, ".reginfo") == 0)
1765 hdr
->sh_type
= SHT_ALPHA_REGINFO
;
1766 /* In a shared object on Irix 5.3, the .reginfo section has an
1767 entsize of 0x18. FIXME: Does this matter? */
1768 if ((abfd
->flags
& DYNAMIC
) != 0)
1769 hdr
->sh_entsize
= sizeof (Elf64_External_RegInfo
);
1771 hdr
->sh_entsize
= 1;
1773 /* Force the section size to the correct value, even if the
1774 linker thinks it is larger. The link routine below will only
1775 write out this much data for .reginfo. */
1776 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf64_External_RegInfo
);
1778 else if (strcmp (name
, ".hash") == 0
1779 || strcmp (name
, ".dynamic") == 0
1780 || strcmp (name
, ".dynstr") == 0)
1782 hdr
->sh_entsize
= 0;
1783 hdr
->sh_info
= SIZEOF_ALPHA_DYNSYM_SECNAMES
;
1786 else if (strcmp (name
, ".sdata") == 0
1787 || strcmp (name
, ".sbss") == 0
1788 || strcmp (name
, ".lit4") == 0
1789 || strcmp (name
, ".lit8") == 0)
1790 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
1795 /* Hook called by the linker routine which adds symbols from an object
1796 file. We use it to put .comm items in .sbss, and not .bss. */
1799 elf64_alpha_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1801 struct bfd_link_info
*info
;
1802 const Elf_Internal_Sym
*sym
;
1808 if (sym
->st_shndx
== SHN_COMMON
1809 && !info
->relocateable
1810 && sym
->st_size
<= bfd_get_gp_size (abfd
))
1812 /* Common symbols less than or equal to -G nn bytes are
1813 automatically put into .sbss. */
1815 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
1819 scomm
= bfd_make_section (abfd
, ".scommon");
1821 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
1823 | SEC_LINKER_CREATED
)))
1828 *valp
= sym
->st_size
;
1834 /* Create the .got section. */
1837 elf64_alpha_create_got_section(abfd
, info
)
1839 struct bfd_link_info
*info
;
1843 if (bfd_get_section_by_name (abfd
, ".got"))
1846 s
= bfd_make_section (abfd
, ".got");
1848 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1851 | SEC_LINKER_CREATED
))
1852 || !bfd_set_section_alignment (abfd
, s
, 3))
1855 alpha_elf_tdata (abfd
)->got
= s
;
1860 /* Create all the dynamic sections. */
1863 elf64_alpha_create_dynamic_sections (abfd
, info
)
1865 struct bfd_link_info
*info
;
1868 struct elf_link_hash_entry
*h
;
1870 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1872 s
= bfd_make_section (abfd
, ".plt");
1874 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1877 | SEC_LINKER_CREATED
1879 || ! bfd_set_section_alignment (abfd
, s
, 3))
1882 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1885 if (! (_bfd_generic_link_add_one_symbol
1886 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
1887 (bfd_vma
) 0, (const char *) NULL
, false,
1888 get_elf_backend_data (abfd
)->collect
,
1889 (struct bfd_link_hash_entry
**) &h
)))
1891 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1892 h
->type
= STT_OBJECT
;
1895 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1898 s
= bfd_make_section (abfd
, ".rela.plt");
1900 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1903 | SEC_LINKER_CREATED
1905 || ! bfd_set_section_alignment (abfd
, s
, 3))
1908 /* We may or may not have created a .got section for this object, but
1909 we definitely havn't done the rest of the work. */
1911 if (!elf64_alpha_create_got_section (abfd
, info
))
1914 s
= bfd_make_section(abfd
, ".rela.got");
1916 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1919 | SEC_LINKER_CREATED
1921 || !bfd_set_section_alignment (abfd
, s
, 3))
1924 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1925 dynobj's .got section. We don't do this in the linker script
1926 because we don't want to define the symbol if we are not creating
1927 a global offset table. */
1929 if (!(_bfd_generic_link_add_one_symbol
1930 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
,
1931 alpha_elf_tdata(abfd
)->got
, (bfd_vma
) 0, (const char *) NULL
,
1932 false, get_elf_backend_data (abfd
)->collect
,
1933 (struct bfd_link_hash_entry
**) &h
)))
1935 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1936 h
->type
= STT_OBJECT
;
1939 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1942 elf_hash_table (info
)->hgot
= h
;
1947 /* Read ECOFF debugging information from a .mdebug section into a
1948 ecoff_debug_info structure. */
1951 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
1954 struct ecoff_debug_info
*debug
;
1957 const struct ecoff_debug_swap
*swap
;
1958 char *ext_hdr
= NULL
;
1960 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1961 memset (debug
, 0, sizeof(*debug
));
1963 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
1964 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1967 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1968 swap
->external_hdr_size
)
1972 symhdr
= &debug
->symbolic_header
;
1973 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1975 /* The symbolic header contains absolute file offsets and sizes to
1977 #define READ(ptr, offset, count, size, type) \
1978 if (symhdr->count == 0) \
1979 debug->ptr = NULL; \
1982 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1983 if (debug->ptr == NULL) \
1984 goto error_return; \
1985 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1986 || (bfd_read (debug->ptr, size, symhdr->count, \
1987 abfd) != size * symhdr->count)) \
1988 goto error_return; \
1991 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1992 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1993 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1994 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1995 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1996 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1998 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1999 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
2000 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
2001 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
2002 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
2006 debug
->adjust
= NULL
;
2011 if (ext_hdr
!= NULL
)
2013 if (debug
->line
!= NULL
)
2015 if (debug
->external_dnr
!= NULL
)
2016 free (debug
->external_dnr
);
2017 if (debug
->external_pdr
!= NULL
)
2018 free (debug
->external_pdr
);
2019 if (debug
->external_sym
!= NULL
)
2020 free (debug
->external_sym
);
2021 if (debug
->external_opt
!= NULL
)
2022 free (debug
->external_opt
);
2023 if (debug
->external_aux
!= NULL
)
2024 free (debug
->external_aux
);
2025 if (debug
->ss
!= NULL
)
2027 if (debug
->ssext
!= NULL
)
2028 free (debug
->ssext
);
2029 if (debug
->external_fdr
!= NULL
)
2030 free (debug
->external_fdr
);
2031 if (debug
->external_rfd
!= NULL
)
2032 free (debug
->external_rfd
);
2033 if (debug
->external_ext
!= NULL
)
2034 free (debug
->external_ext
);
2038 /* Alpha ELF local labels start with '$'. */
2041 elf64_alpha_is_local_label_name (abfd
, name
)
2045 return name
[0] == '$';
2048 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2049 routine in order to handle the ECOFF debugging information. We
2050 still call this mips_elf_find_line because of the slot
2051 find_line_info in elf_obj_tdata is declared that way. */
2053 struct mips_elf_find_line
2055 struct ecoff_debug_info d
;
2056 struct ecoff_find_line i
;
2060 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2061 functionname_ptr
, line_ptr
)
2066 const char **filename_ptr
;
2067 const char **functionname_ptr
;
2068 unsigned int *line_ptr
;
2072 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2076 struct mips_elf_find_line
*fi
;
2077 const struct ecoff_debug_swap
* const swap
=
2078 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2080 /* If we are called during a link, alpha_elf_final_link may have
2081 cleared the SEC_HAS_CONTENTS field. We force it back on here
2082 if appropriate (which it normally will be). */
2083 origflags
= msec
->flags
;
2084 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2085 msec
->flags
|= SEC_HAS_CONTENTS
;
2087 fi
= elf_tdata (abfd
)->find_line_info
;
2090 bfd_size_type external_fdr_size
;
2093 struct fdr
*fdr_ptr
;
2095 fi
= ((struct mips_elf_find_line
*)
2096 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2099 msec
->flags
= origflags
;
2103 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
2105 msec
->flags
= origflags
;
2109 /* Swap in the FDR information. */
2110 fi
->d
.fdr
= ((struct fdr
*)
2112 (fi
->d
.symbolic_header
.ifdMax
*
2113 sizeof (struct fdr
))));
2114 if (fi
->d
.fdr
== NULL
)
2116 msec
->flags
= origflags
;
2119 external_fdr_size
= swap
->external_fdr_size
;
2120 fdr_ptr
= fi
->d
.fdr
;
2121 fraw_src
= (char *) fi
->d
.external_fdr
;
2122 fraw_end
= (fraw_src
2123 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2124 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2125 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2127 elf_tdata (abfd
)->find_line_info
= fi
;
2129 /* Note that we don't bother to ever free this information.
2130 find_nearest_line is either called all the time, as in
2131 objdump -l, so the information should be saved, or it is
2132 rarely called, as in ld error messages, so the memory
2133 wasted is unimportant. Still, it would probably be a
2134 good idea for free_cached_info to throw it away. */
2137 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2138 &fi
->i
, filename_ptr
, functionname_ptr
,
2141 msec
->flags
= origflags
;
2145 msec
->flags
= origflags
;
2148 /* Fall back on the generic ELF find_nearest_line routine. */
2150 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2151 filename_ptr
, functionname_ptr
,
2155 /* Structure used to pass information to alpha_elf_output_extsym. */
2160 struct bfd_link_info
*info
;
2161 struct ecoff_debug_info
*debug
;
2162 const struct ecoff_debug_swap
*swap
;
2167 elf64_alpha_output_extsym (h
, data
)
2168 struct alpha_elf_link_hash_entry
*h
;
2171 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2173 asection
*sec
, *output_section
;
2175 if (h
->root
.indx
== -2)
2177 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2178 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2179 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2180 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2182 else if (einfo
->info
->strip
== strip_all
2183 || (einfo
->info
->strip
== strip_some
2184 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2185 h
->root
.root
.root
.string
,
2186 false, false) == NULL
))
2194 if (h
->esym
.ifd
== -2)
2197 h
->esym
.cobol_main
= 0;
2198 h
->esym
.weakext
= 0;
2199 h
->esym
.reserved
= 0;
2200 h
->esym
.ifd
= ifdNil
;
2201 h
->esym
.asym
.value
= 0;
2202 h
->esym
.asym
.st
= stGlobal
;
2204 if (h
->root
.root
.type
!= bfd_link_hash_defined
2205 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2206 h
->esym
.asym
.sc
= scAbs
;
2211 sec
= h
->root
.root
.u
.def
.section
;
2212 output_section
= sec
->output_section
;
2214 /* When making a shared library and symbol h is the one from
2215 the another shared library, OUTPUT_SECTION may be null. */
2216 if (output_section
== NULL
)
2217 h
->esym
.asym
.sc
= scUndefined
;
2220 name
= bfd_section_name (output_section
->owner
, output_section
);
2222 if (strcmp (name
, ".text") == 0)
2223 h
->esym
.asym
.sc
= scText
;
2224 else if (strcmp (name
, ".data") == 0)
2225 h
->esym
.asym
.sc
= scData
;
2226 else if (strcmp (name
, ".sdata") == 0)
2227 h
->esym
.asym
.sc
= scSData
;
2228 else if (strcmp (name
, ".rodata") == 0
2229 || strcmp (name
, ".rdata") == 0)
2230 h
->esym
.asym
.sc
= scRData
;
2231 else if (strcmp (name
, ".bss") == 0)
2232 h
->esym
.asym
.sc
= scBss
;
2233 else if (strcmp (name
, ".sbss") == 0)
2234 h
->esym
.asym
.sc
= scSBss
;
2235 else if (strcmp (name
, ".init") == 0)
2236 h
->esym
.asym
.sc
= scInit
;
2237 else if (strcmp (name
, ".fini") == 0)
2238 h
->esym
.asym
.sc
= scFini
;
2240 h
->esym
.asym
.sc
= scAbs
;
2244 h
->esym
.asym
.reserved
= 0;
2245 h
->esym
.asym
.index
= indexNil
;
2248 if (h
->root
.root
.type
== bfd_link_hash_common
)
2249 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2250 else if (h
->root
.root
.type
== bfd_link_hash_defined
2251 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2253 if (h
->esym
.asym
.sc
== scCommon
)
2254 h
->esym
.asym
.sc
= scBss
;
2255 else if (h
->esym
.asym
.sc
== scSCommon
)
2256 h
->esym
.asym
.sc
= scSBss
;
2258 sec
= h
->root
.root
.u
.def
.section
;
2259 output_section
= sec
->output_section
;
2260 if (output_section
!= NULL
)
2261 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2262 + sec
->output_offset
2263 + output_section
->vma
);
2265 h
->esym
.asym
.value
= 0;
2267 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2269 /* Set type and value for a symbol with a function stub. */
2270 h
->esym
.asym
.st
= stProc
;
2271 sec
= bfd_get_section_by_name (einfo
->abfd
, ".plt");
2273 h
->esym
.asym
.value
= 0;
2276 output_section
= sec
->output_section
;
2277 if (output_section
!= NULL
)
2278 h
->esym
.asym
.value
= (h
->root
.plt
.offset
2279 + sec
->output_offset
2280 + output_section
->vma
);
2282 h
->esym
.asym
.value
= 0;
2289 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2290 h
->root
.root
.root
.string
,
2293 einfo
->failed
= true;
2300 /* FIXME: Create a runtime procedure table from the .mdebug section.
2303 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
2306 struct bfd_link_info *info;
2308 struct ecoff_debug_info *debug;
2311 /* Handle dynamic relocations when doing an Alpha ELF link. */
2314 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
2316 struct bfd_link_info
*info
;
2318 const Elf_Internal_Rela
*relocs
;
2322 const char *rel_sec_name
;
2323 Elf_Internal_Shdr
*symtab_hdr
;
2324 struct alpha_elf_link_hash_entry
**sym_hashes
;
2325 struct alpha_elf_got_entry
**local_got_entries
;
2326 const Elf_Internal_Rela
*rel
, *relend
;
2329 if (info
->relocateable
)
2332 dynobj
= elf_hash_table(info
)->dynobj
;
2334 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
2337 rel_sec_name
= NULL
;
2338 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
2339 sym_hashes
= alpha_elf_sym_hashes(abfd
);
2340 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2343 relend
= relocs
+ sec
->reloc_count
;
2344 for (rel
= relocs
; rel
< relend
; ++rel
)
2346 unsigned long r_symndx
, r_type
;
2347 struct alpha_elf_link_hash_entry
*h
;
2349 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2350 if (r_symndx
< symtab_hdr
->sh_info
)
2354 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2356 while (h
->root
.root
.type
== bfd_link_hash_indirect
2357 || h
->root
.root
.type
== bfd_link_hash_warning
)
2358 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2360 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
2362 r_type
= ELF64_R_TYPE (rel
->r_info
);
2366 case R_ALPHA_LITERAL
:
2368 struct alpha_elf_got_entry
*gotent
;
2373 /* Search for and possibly create a got entry. */
2374 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2375 if (gotent
->gotobj
== abfd
&&
2376 gotent
->addend
== rel
->r_addend
)
2381 gotent
= ((struct alpha_elf_got_entry
*)
2383 sizeof (struct alpha_elf_got_entry
)));
2387 gotent
->gotobj
= abfd
;
2388 gotent
->addend
= rel
->r_addend
;
2389 gotent
->got_offset
= -1;
2391 gotent
->use_count
= 1;
2393 gotent
->next
= h
->got_entries
;
2394 h
->got_entries
= gotent
;
2396 alpha_elf_tdata (abfd
)->total_got_entries
++;
2399 gotent
->use_count
+= 1;
2403 /* This is a local .got entry -- record for merge. */
2404 if (!local_got_entries
)
2407 size
= (symtab_hdr
->sh_info
2408 * sizeof (struct alpha_elf_got_entry
*));
2410 local_got_entries
= ((struct alpha_elf_got_entry
**)
2411 bfd_alloc (abfd
, size
));
2412 if (!local_got_entries
)
2415 memset (local_got_entries
, 0, size
);
2416 alpha_elf_tdata (abfd
)->local_got_entries
=
2420 for (gotent
= local_got_entries
[ELF64_R_SYM(rel
->r_info
)];
2421 gotent
!= NULL
&& gotent
->addend
!= rel
->r_addend
;
2422 gotent
= gotent
->next
)
2426 gotent
= ((struct alpha_elf_got_entry
*)
2428 sizeof (struct alpha_elf_got_entry
)));
2432 gotent
->gotobj
= abfd
;
2433 gotent
->addend
= rel
->r_addend
;
2434 gotent
->got_offset
= -1;
2436 gotent
->use_count
= 1;
2438 gotent
->next
= local_got_entries
[ELF64_R_SYM(rel
->r_info
)];
2439 local_got_entries
[ELF64_R_SYM(rel
->r_info
)] = gotent
;
2441 alpha_elf_tdata(abfd
)->total_got_entries
++;
2442 alpha_elf_tdata(abfd
)->n_local_got_entries
++;
2445 gotent
->use_count
+= 1;
2448 /* Remember how this literal is used from its LITUSEs.
2449 This will be important when it comes to decide if we can
2450 create a .plt entry for a function symbol. */
2452 && ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
)
2457 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 3)
2458 flags
|= 1 << rel
->r_addend
;
2460 while (rel
+1 < relend
&&
2461 ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
);
2465 /* No LITUSEs -- presumably the address is not being
2466 loaded for nothing. */
2467 flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
2470 gotent
->flags
|= flags
;
2473 /* Make a guess as to whether a .plt entry will be needed. */
2474 if ((h
->flags
|= flags
) == ALPHA_ELF_LINK_HASH_LU_FUNC
)
2475 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2477 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2482 case R_ALPHA_GPDISP
:
2483 case R_ALPHA_GPREL32
:
2484 case R_ALPHA_GPRELHIGH
:
2485 case R_ALPHA_GPRELLOW
:
2486 /* We don't actually use the .got here, but the sections must
2487 be created before the linker maps input sections to output
2491 if (!elf64_alpha_create_got_section (abfd
, info
))
2494 /* Make sure the object's gotobj is set to itself so
2495 that we default to every object with its own .got.
2496 We'll merge .gots later once we've collected each
2498 alpha_elf_tdata(abfd
)->gotobj
= abfd
;
2504 case R_ALPHA_SREL16
:
2505 case R_ALPHA_SREL32
:
2506 case R_ALPHA_SREL64
:
2511 case R_ALPHA_REFLONG
:
2512 case R_ALPHA_REFQUAD
:
2513 if (rel_sec_name
== NULL
)
2515 rel_sec_name
= (bfd_elf_string_from_elf_section
2516 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
2517 elf_section_data(sec
)->rel_hdr
.sh_name
));
2518 if (rel_sec_name
== NULL
)
2521 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
2522 && strcmp (bfd_get_section_name (abfd
, sec
),
2523 rel_sec_name
+5) == 0);
2526 /* We need to create the section here now whether we eventually
2527 use it or not so that it gets mapped to an output section by
2528 the linker. If not used, we'll kill it in
2529 size_dynamic_sections. */
2532 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
2535 sreloc
= bfd_make_section (dynobj
, rel_sec_name
);
2537 || !bfd_set_section_flags (dynobj
, sreloc
,
2541 | SEC_LINKER_CREATED
2543 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
2550 /* Since we havn't seen all of the input symbols yet, we
2551 don't know whether we'll actually need a dynamic relocation
2552 entry for this reloc. So make a record of it. Once we
2553 find out if this thing needs dynamic relocation we'll
2554 expand the relocation sections by the appropriate amount. */
2556 struct alpha_elf_reloc_entry
*rent
;
2558 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
2559 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
2564 rent
= ((struct alpha_elf_reloc_entry
*)
2566 sizeof (struct alpha_elf_reloc_entry
)));
2570 rent
->srel
= sreloc
;
2571 rent
->rtype
= r_type
;
2574 rent
->next
= h
->reloc_entries
;
2575 h
->reloc_entries
= rent
;
2580 else if (info
->shared
)
2582 /* If this is a shared library, we need a RELATIVE reloc. */
2583 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
2592 /* Adjust a symbol defined by a dynamic object and referenced by a
2593 regular object. The current definition is in some section of the
2594 dynamic object, but we're not including those sections. We have to
2595 change the definition to something the rest of the link can
2599 elf64_alpha_adjust_dynamic_symbol (info
, h
)
2600 struct bfd_link_info
*info
;
2601 struct elf_link_hash_entry
*h
;
2605 struct alpha_elf_link_hash_entry
*ah
;
2607 dynobj
= elf_hash_table(info
)->dynobj
;
2608 ah
= (struct alpha_elf_link_hash_entry
*)h
;
2610 /* Now that we've seen all of the input symbols, finalize our decision
2611 about whether this symbol should get a .plt entry. */
2613 if (h
->root
.type
!= bfd_link_hash_undefweak
2614 && alpha_elf_dynamic_symbol_p (h
, info
)
2615 && ((h
->type
== STT_FUNC
2616 && !(ah
->flags
& ALPHA_ELF_LINK_HASH_LU_ADDR
))
2617 || (h
->type
== STT_NOTYPE
2618 && ah
->flags
== ALPHA_ELF_LINK_HASH_LU_FUNC
))
2619 /* Don't prevent otherwise valid programs from linking by attempting
2620 to create a new .got entry somewhere. A Correct Solution would be
2621 to add a new .got section to a new object file and let it be merged
2622 somewhere later. But for now don't bother. */
2625 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2627 s
= bfd_get_section_by_name(dynobj
, ".plt");
2628 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
2631 /* The first bit of the .plt is reserved. */
2632 if (s
->_raw_size
== 0)
2633 s
->_raw_size
= PLT_HEADER_SIZE
;
2635 h
->plt
.offset
= s
->_raw_size
;
2636 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2638 /* If this symbol is not defined in a regular file, and we are not
2639 generating a shared library, then set the symbol to the location
2640 in the .plt. This is required to make function pointers compare
2641 equal between the normal executable and the shared library. */
2643 && h
->root
.type
!= bfd_link_hash_defweak
)
2645 h
->root
.u
.def
.section
= s
;
2646 h
->root
.u
.def
.value
= h
->plt
.offset
;
2649 /* We also need a JMP_SLOT entry in the .rela.plt section. */
2650 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2651 BFD_ASSERT (s
!= NULL
);
2652 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
2657 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2659 /* If this is a weak symbol, and there is a real definition, the
2660 processor independent code will have arranged for us to see the
2661 real definition first, and we can just use the same value. */
2662 if (h
->weakdef
!= NULL
)
2664 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2665 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2666 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2667 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2671 /* This is a reference to a symbol defined by a dynamic object which
2672 is not a function. The Alpha, since it uses .got entries for all
2673 symbols even in regular objects, does not need the hackery of a
2674 .dynbss section and COPY dynamic relocations. */
2679 /* Symbol versioning can create new symbols, and make our old symbols
2680 indirect to the new ones. Consolidate the got and reloc information
2681 in these situations. */
2684 elf64_alpha_merge_ind_symbols (hi
, dummy
)
2685 struct alpha_elf_link_hash_entry
*hi
;
2688 struct alpha_elf_link_hash_entry
*hs
;
2690 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
2694 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
2695 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
2697 /* Merge the flags. Whee. */
2699 hs
->flags
|= hi
->flags
;
2701 /* Merge the .got entries. Cannibalize the old symbol's list in
2702 doing so, since we don't need it anymore. */
2704 if (hs
->got_entries
== NULL
)
2705 hs
->got_entries
= hi
->got_entries
;
2708 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
2710 gsh
= hs
->got_entries
;
2711 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
2714 for (gs
= gsh
; gs
; gs
= gs
->next
)
2715 if (gi
->gotobj
== gs
->gotobj
&& gi
->addend
== gs
->addend
)
2717 gi
->next
= hs
->got_entries
;
2718 hs
->got_entries
= gi
;
2722 hi
->got_entries
= NULL
;
2724 /* And similar for the reloc entries. */
2726 if (hs
->reloc_entries
== NULL
)
2727 hs
->reloc_entries
= hi
->reloc_entries
;
2730 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
2732 rsh
= hs
->reloc_entries
;
2733 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
2736 for (rs
= rsh
; rs
; rs
= rs
->next
)
2737 if (ri
->rtype
== rs
->rtype
)
2739 rs
->count
+= ri
->count
;
2742 ri
->next
= hs
->reloc_entries
;
2743 hs
->reloc_entries
= ri
;
2747 hi
->reloc_entries
= NULL
;
2752 /* Is it possible to merge two object file's .got tables? */
2755 elf64_alpha_can_merge_gots (a
, b
)
2758 int total
= alpha_elf_tdata (a
)->total_got_entries
;
2761 /* Trivial quick fallout test. */
2762 if (total
+ alpha_elf_tdata (b
)->total_got_entries
<= MAX_GOT_ENTRIES
)
2765 /* By their nature, local .got entries cannot be merged. */
2766 if ((total
+= alpha_elf_tdata (b
)->n_local_got_entries
) > MAX_GOT_ENTRIES
)
2769 /* Failing the common trivial comparison, we must effectively
2770 perform the merge. Not actually performing the merge means that
2771 we don't have to store undo information in case we fail. */
2772 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
2774 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes (bsub
);
2775 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
2778 n
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
- symtab_hdr
->sh_info
;
2779 for (i
= 0; i
< n
; ++i
)
2781 struct alpha_elf_got_entry
*ae
, *be
;
2782 struct alpha_elf_link_hash_entry
*h
;
2785 while (h
->root
.root
.type
== bfd_link_hash_indirect
2786 || h
->root
.root
.type
== bfd_link_hash_warning
)
2787 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2789 for (be
= h
->got_entries
; be
; be
= be
->next
)
2791 if (be
->use_count
== 0)
2793 if (be
->gotobj
!= b
)
2796 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
2797 if (ae
->gotobj
== a
&& ae
->addend
== be
->addend
)
2800 if (++total
> MAX_GOT_ENTRIES
)
2810 /* Actually merge two .got tables. */
2813 elf64_alpha_merge_gots (a
, b
)
2816 int total
= alpha_elf_tdata (a
)->total_got_entries
;
2819 /* Remember local expansion. */
2821 int e
= alpha_elf_tdata (b
)->n_local_got_entries
;
2823 alpha_elf_tdata (a
)->n_local_got_entries
+= e
;
2826 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
2828 struct alpha_elf_got_entry
**local_got_entries
;
2829 struct alpha_elf_link_hash_entry
**hashes
;
2830 Elf_Internal_Shdr
*symtab_hdr
;
2833 /* Let the local .got entries know they are part of a new subsegment. */
2834 local_got_entries
= alpha_elf_tdata (bsub
)->local_got_entries
;
2835 if (local_got_entries
)
2837 n
= elf_tdata (bsub
)->symtab_hdr
.sh_info
;
2838 for (i
= 0; i
< n
; ++i
)
2840 struct alpha_elf_got_entry
*ent
;
2841 for (ent
= local_got_entries
[i
]; ent
; ent
= ent
->next
)
2846 /* Merge the global .got entries. */
2847 hashes
= alpha_elf_sym_hashes (bsub
);
2848 symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
2850 n
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
- symtab_hdr
->sh_info
;
2851 for (i
= 0; i
< n
; ++i
)
2853 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
2854 struct alpha_elf_link_hash_entry
*h
;
2857 while (h
->root
.root
.type
== bfd_link_hash_indirect
2858 || h
->root
.root
.type
== bfd_link_hash_warning
)
2859 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2861 start
= &h
->got_entries
;
2862 for (pbe
= start
, be
= *start
; be
; pbe
= &be
->next
, be
= be
->next
)
2864 if (be
->use_count
== 0)
2869 if (be
->gotobj
!= b
)
2872 for (ae
= *start
; ae
; ae
= ae
->next
)
2873 if (ae
->gotobj
== a
&& ae
->addend
== be
->addend
)
2875 ae
->flags
|= be
->flags
;
2876 ae
->use_count
+= be
->use_count
;
2887 alpha_elf_tdata (bsub
)->gotobj
= a
;
2889 alpha_elf_tdata (a
)->total_got_entries
= total
;
2891 /* Merge the two in_got chains. */
2896 while ((next
= alpha_elf_tdata (bsub
)->in_got_link_next
) != NULL
)
2899 alpha_elf_tdata (bsub
)->in_got_link_next
= b
;
2903 /* Calculate the offsets for the got entries. */
2906 elf64_alpha_calc_got_offsets_for_symbol (h
, arg
)
2907 struct alpha_elf_link_hash_entry
*h
;
2910 struct alpha_elf_got_entry
*gotent
;
2912 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2913 if (gotent
->use_count
> 0)
2916 = &alpha_elf_tdata (gotent
->gotobj
)->got
->_raw_size
;
2918 gotent
->got_offset
= *plge
;
2926 elf64_alpha_calc_got_offsets (info
)
2927 struct bfd_link_info
*info
;
2929 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
2931 /* First, zero out the .got sizes, as we may be recalculating the
2932 .got after optimizing it. */
2933 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2934 alpha_elf_tdata(i
)->got
->_raw_size
= 0;
2936 /* Next, fill in the offsets for all the global entries. */
2937 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2938 elf64_alpha_calc_got_offsets_for_symbol
,
2941 /* Finally, fill in the offsets for the local entries. */
2942 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2944 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->_raw_size
;
2947 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2949 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2952 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2953 if (!local_got_entries
)
2956 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2957 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
2958 if (gotent
->use_count
> 0)
2960 gotent
->got_offset
= got_offset
;
2965 alpha_elf_tdata(i
)->got
->_raw_size
= got_offset
;
2966 alpha_elf_tdata(i
)->got
->_cooked_size
= got_offset
;
2970 /* Constructs the gots. */
2973 elf64_alpha_size_got_sections (output_bfd
, info
)
2975 struct bfd_link_info
*info
;
2977 bfd
*i
, *got_list
, *cur_got_obj
;
2978 int something_changed
= 0;
2980 got_list
= alpha_elf_hash_table (info
)->got_list
;
2982 /* On the first time through, pretend we have an existing got list
2983 consisting of all of the input files. */
2984 if (got_list
== NULL
)
2986 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2988 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
2989 if (this_got
== NULL
)
2992 /* We are assuming no merging has yet ocurred. */
2993 BFD_ASSERT (this_got
== i
);
2995 if (alpha_elf_tdata (this_got
)->total_got_entries
> MAX_GOT_ENTRIES
)
2997 /* Yikes! A single object file has too many entries. */
2998 (*_bfd_error_handler
)
2999 (_("%s: .got subsegment exceeds 64K (size %d)"),
3000 bfd_get_filename (i
),
3001 alpha_elf_tdata (this_got
)->total_got_entries
* 8);
3005 if (got_list
== NULL
)
3006 got_list
= this_got
;
3008 alpha_elf_tdata(cur_got_obj
)->got_link_next
= this_got
;
3009 cur_got_obj
= this_got
;
3012 /* Strange degenerate case of no got references. */
3013 if (got_list
== NULL
)
3016 alpha_elf_hash_table (info
)->got_list
= got_list
;
3018 /* Force got offsets to be recalculated. */
3019 something_changed
= 1;
3022 cur_got_obj
= got_list
;
3023 i
= alpha_elf_tdata(cur_got_obj
)->got_link_next
;
3026 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
3028 elf64_alpha_merge_gots (cur_got_obj
, i
);
3029 i
= alpha_elf_tdata(i
)->got_link_next
;
3030 alpha_elf_tdata(cur_got_obj
)->got_link_next
= i
;
3031 something_changed
= 1;
3036 i
= alpha_elf_tdata(i
)->got_link_next
;
3040 /* Once the gots have been merged, fill in the got offsets for
3041 everything therein. */
3042 if (1 || something_changed
)
3043 elf64_alpha_calc_got_offsets (info
);
3049 elf64_alpha_always_size_sections (output_bfd
, info
)
3051 struct bfd_link_info
*info
;
3055 if (info
->relocateable
)
3058 /* First, take care of the indirect symbols created by versioning. */
3059 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3060 elf64_alpha_merge_ind_symbols
,
3063 if (!elf64_alpha_size_got_sections (output_bfd
, info
))
3066 /* Allocate space for all of the .got subsections. */
3067 i
= alpha_elf_hash_table (info
)->got_list
;
3068 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3070 asection
*s
= alpha_elf_tdata(i
)->got
;
3071 if (s
->_raw_size
> 0)
3073 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->_raw_size
);
3074 if (s
->contents
== NULL
)
3082 /* Work out the sizes of the dynamic relocation entries. */
3085 elf64_alpha_calc_dynrel_sizes (h
, info
)
3086 struct alpha_elf_link_hash_entry
*h
;
3087 struct bfd_link_info
*info
;
3089 /* If the symbol was defined as a common symbol in a regular object
3090 file, and there was no definition in any dynamic object, then the
3091 linker will have allocated space for the symbol in a common
3092 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3093 set. This is done for dynamic symbols in
3094 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3095 symbols, somehow. */
3096 if (((h
->root
.elf_link_hash_flags
3097 & (ELF_LINK_HASH_DEF_REGULAR
3098 | ELF_LINK_HASH_REF_REGULAR
3099 | ELF_LINK_HASH_DEF_DYNAMIC
))
3100 == ELF_LINK_HASH_REF_REGULAR
)
3101 && (h
->root
.root
.type
== bfd_link_hash_defined
3102 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3103 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
3105 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3108 /* If the symbol is dynamic, we'll need all the relocations in their
3109 natural form. If this is a shared object, and it has been forced
3110 local, we'll need the same number of RELATIVE relocations. */
3112 if (alpha_elf_dynamic_symbol_p (&h
->root
, info
) || info
->shared
)
3114 struct alpha_elf_reloc_entry
*relent
;
3116 struct alpha_elf_got_entry
*gotent
;
3117 bfd_size_type count
;
3120 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
3121 if (relent
->rtype
== R_ALPHA_REFLONG
3122 || relent
->rtype
== R_ALPHA_REFQUAD
)
3124 relent
->srel
->_raw_size
+=
3125 sizeof(Elf64_External_Rela
) * relent
->count
;
3128 dynobj
= elf_hash_table(info
)->dynobj
;
3131 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3134 /* If we are using a .plt entry, subtract one, as the first
3135 reference uses a .rela.plt entry instead. */
3136 if (h
->root
.plt
.offset
!= MINUS_ONE
)
3141 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3142 BFD_ASSERT (srel
!= NULL
);
3143 srel
->_raw_size
+= sizeof (Elf64_External_Rela
) * count
;
3150 /* Set the sizes of the dynamic sections. */
3153 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
3155 struct bfd_link_info
*info
;
3162 dynobj
= elf_hash_table(info
)->dynobj
;
3163 BFD_ASSERT(dynobj
!= NULL
);
3165 if (elf_hash_table (info
)->dynamic_sections_created
)
3167 /* Set the contents of the .interp section to the interpreter. */
3170 s
= bfd_get_section_by_name (dynobj
, ".interp");
3171 BFD_ASSERT (s
!= NULL
);
3172 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3173 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3176 /* Now that we've seen all of the input files, we can decide which
3177 symbols need dynamic relocation entries and which don't. We've
3178 collected information in check_relocs that we can now apply to
3179 size the dynamic relocation sections. */
3180 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3181 elf64_alpha_calc_dynrel_sizes
,
3184 /* When building shared libraries, each local .got entry needs a
3190 bfd_size_type count
;
3192 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3193 BFD_ASSERT (srel
!= NULL
);
3195 for (i
= alpha_elf_hash_table(info
)->got_list
, count
= 0;
3197 i
= alpha_elf_tdata(i
)->got_link_next
)
3198 count
+= alpha_elf_tdata(i
)->n_local_got_entries
;
3200 srel
->_raw_size
+= count
* sizeof(Elf64_External_Rela
);
3203 /* else we're not dynamic and by definition we don't need such things. */
3205 /* The check_relocs and adjust_dynamic_symbol entry points have
3206 determined the sizes of the various dynamic sections. Allocate
3210 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3215 if (!(s
->flags
& SEC_LINKER_CREATED
))
3218 /* It's OK to base decisions on the section name, because none
3219 of the dynobj section names depend upon the input files. */
3220 name
= bfd_get_section_name (dynobj
, s
);
3222 /* If we don't need this section, strip it from the output file.
3223 This is to handle .rela.bss and .rela.plt. We must create it
3224 in create_dynamic_sections, because it must be created before
3225 the linker maps input sections to output sections. The
3226 linker does that before adjust_dynamic_symbol is called, and
3227 it is that function which decides whether anything needs to
3228 go into these sections. */
3232 if (strncmp (name
, ".rela", 5) == 0)
3234 strip
= (s
->_raw_size
== 0);
3238 const char *outname
;
3241 /* If this relocation section applies to a read only
3242 section, then we probably need a DT_TEXTREL entry. */
3243 outname
= bfd_get_section_name (output_bfd
,
3245 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
3247 && (target
->flags
& SEC_READONLY
) != 0
3248 && (target
->flags
& SEC_ALLOC
) != 0)
3251 if (strcmp(name
, ".rela.plt") == 0)
3254 /* We use the reloc_count field as a counter if we need
3255 to copy relocs into the output file. */
3259 else if (strcmp (name
, ".plt") != 0)
3261 /* It's not one of our dynamic sections, so don't allocate space. */
3266 _bfd_strip_section_from_output (info
, s
);
3269 /* Allocate memory for the section contents. */
3270 s
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, s
->_raw_size
);
3271 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3276 if (elf_hash_table (info
)->dynamic_sections_created
)
3278 /* Add some entries to the .dynamic section. We fill in the
3279 values later, in elf64_alpha_finish_dynamic_sections, but we
3280 must add the entries now so that we get the correct size for
3281 the .dynamic section. The DT_DEBUG entry is filled in by the
3282 dynamic linker and used by the debugger. */
3285 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
3289 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0))
3294 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3295 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
3296 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
3300 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
3301 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
3302 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
3303 sizeof(Elf64_External_Rela
)))
3308 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
3316 /* Relocate an Alpha ELF section. */
3319 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3320 contents
, relocs
, local_syms
, local_sections
)
3322 struct bfd_link_info
*info
;
3324 asection
*input_section
;
3326 Elf_Internal_Rela
*relocs
;
3327 Elf_Internal_Sym
*local_syms
;
3328 asection
**local_sections
;
3330 Elf_Internal_Shdr
*symtab_hdr
;
3331 Elf_Internal_Rela
*rel
;
3332 Elf_Internal_Rela
*relend
;
3333 asection
*sec
, *sgot
, *srel
, *srelgot
;
3334 bfd
*dynobj
, *gotobj
;
3337 srelgot
= srel
= NULL
;
3338 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3339 dynobj
= elf_hash_table (info
)->dynobj
;
3342 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3345 /* Find the gp value for this input bfd. */
3348 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
3351 sgot
= alpha_elf_tdata (gotobj
)->got
;
3352 gp
= _bfd_get_gp_value (gotobj
);
3355 gp
= (sgot
->output_section
->vma
3356 + sgot
->output_offset
3358 _bfd_set_gp_value (gotobj
, gp
);
3363 relend
= relocs
+ input_section
->reloc_count
;
3364 for (; rel
< relend
; rel
++)
3367 reloc_howto_type
*howto
;
3368 unsigned long r_symndx
;
3369 struct alpha_elf_link_hash_entry
*h
;
3370 Elf_Internal_Sym
*sym
;
3373 bfd_reloc_status_type r
;
3375 r_type
= ELF64_R_TYPE(rel
->r_info
);
3376 if (r_type
< 0 || r_type
>= (int) R_ALPHA_max
)
3378 bfd_set_error (bfd_error_bad_value
);
3381 howto
= elf64_alpha_howto_table
+ r_type
;
3383 r_symndx
= ELF64_R_SYM(rel
->r_info
);
3385 if (info
->relocateable
)
3387 /* This is a relocateable link. We don't have to change
3388 anything, unless the reloc is against a section symbol,
3389 in which case we have to adjust according to where the
3390 section symbol winds up in the output section. */
3392 /* The symbol associated with GPDISP and LITUSE is
3393 immaterial. Only the addend is significant. */
3394 if (r_type
== R_ALPHA_GPDISP
|| r_type
== R_ALPHA_LITUSE
)
3397 if (r_symndx
< symtab_hdr
->sh_info
)
3399 sym
= local_syms
+ r_symndx
;
3400 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
3402 sec
= local_sections
[r_symndx
];
3403 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
3410 /* This is a final link. */
3416 if (r_symndx
< symtab_hdr
->sh_info
)
3418 sym
= local_syms
+ r_symndx
;
3419 sec
= local_sections
[r_symndx
];
3420 relocation
= (sec
->output_section
->vma
3421 + sec
->output_offset
3426 h
= alpha_elf_sym_hashes (input_bfd
)[r_symndx
- symtab_hdr
->sh_info
];
3428 while (h
->root
.root
.type
== bfd_link_hash_indirect
3429 || h
->root
.root
.type
== bfd_link_hash_warning
)
3430 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3432 if (h
->root
.root
.type
== bfd_link_hash_defined
3433 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3435 sec
= h
->root
.root
.u
.def
.section
;
3438 if ((r_type
== R_ALPHA_LITERAL
3439 && elf_hash_table(info
)->dynamic_sections_created
3442 || !(h
->root
.elf_link_hash_flags
3443 & ELF_LINK_HASH_DEF_REGULAR
)))
3446 || !(h
->root
.elf_link_hash_flags
3447 & ELF_LINK_HASH_DEF_REGULAR
))
3448 && (input_section
->flags
& SEC_ALLOC
)
3449 && (r_type
== R_ALPHA_REFLONG
3450 || r_type
== R_ALPHA_REFQUAD
3451 || r_type
== R_ALPHA_LITERAL
)))
3453 /* In these cases, we don't need the relocation value.
3454 We check specially because in some obscure cases
3455 sec->output_section will be NULL. */
3459 /* FIXME: Are not these obscure cases simply bugs? Let's
3460 get something working and come back to this. */
3461 if (sec
->output_section
== NULL
)
3463 #endif /* rth_notdef */
3466 relocation
= (h
->root
.root
.u
.def
.value
3467 + sec
->output_section
->vma
3468 + sec
->output_offset
);
3471 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3473 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
3477 if (!((*info
->callbacks
->undefined_symbol
)
3478 (info
, h
->root
.root
.root
.string
, input_bfd
,
3479 input_section
, rel
->r_offset
)))
3484 addend
= rel
->r_addend
;
3488 case R_ALPHA_GPDISP
:
3490 bfd_byte
*p_ldah
, *p_lda
;
3492 BFD_ASSERT(gp
!= 0);
3494 relocation
= (input_section
->output_section
->vma
3495 + input_section
->output_offset
3498 p_ldah
= contents
+ rel
->r_offset
- input_section
->vma
;
3499 p_lda
= p_ldah
+ rel
->r_addend
;
3501 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- relocation
,
3506 case R_ALPHA_OP_PUSH
:
3507 case R_ALPHA_OP_STORE
:
3508 case R_ALPHA_OP_PSUB
:
3509 case R_ALPHA_OP_PRSHIFT
:
3510 /* We hate these silly beasts. */
3513 case R_ALPHA_LITERAL
:
3515 struct alpha_elf_got_entry
*gotent
;
3516 boolean dynamic_symbol
;
3518 BFD_ASSERT(sgot
!= NULL
);
3519 BFD_ASSERT(gp
!= 0);
3523 gotent
= h
->got_entries
;
3524 dynamic_symbol
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
3528 gotent
= (alpha_elf_tdata(input_bfd
)->
3529 local_got_entries
[r_symndx
]);
3530 dynamic_symbol
= false;
3533 BFD_ASSERT(gotent
!= NULL
);
3535 while (gotent
->gotobj
!= gotobj
|| gotent
->addend
!= addend
)
3536 gotent
= gotent
->next
;
3538 BFD_ASSERT(gotent
->use_count
>= 1);
3540 /* Initialize the .got entry's value. */
3541 if (!(gotent
->flags
& ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
))
3543 bfd_put_64 (output_bfd
, relocation
+addend
,
3544 sgot
->contents
+ gotent
->got_offset
);
3546 /* If the symbol has been forced local, output a
3547 RELATIVE reloc, otherwise it will be handled in
3548 finish_dynamic_symbol. */
3549 if (info
->shared
&& !dynamic_symbol
)
3551 Elf_Internal_Rela outrel
;
3553 BFD_ASSERT(srelgot
!= NULL
);
3555 outrel
.r_offset
= (sgot
->output_section
->vma
3556 + sgot
->output_offset
3557 + gotent
->got_offset
);
3558 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
3559 outrel
.r_addend
= 0;
3561 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3562 ((Elf64_External_Rela
*)
3564 + srelgot
->reloc_count
++);
3565 BFD_ASSERT (sizeof(Elf64_External_Rela
)
3566 * srelgot
->reloc_count
3567 <= srelgot
->_cooked_size
);
3570 gotent
->flags
|= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
;
3573 /* Figure the gprel relocation. */
3575 relocation
= (sgot
->output_section
->vma
3576 + sgot
->output_offset
3577 + gotent
->got_offset
);
3580 /* overflow handled by _bfd_final_link_relocate */
3583 case R_ALPHA_GPREL32
:
3584 case R_ALPHA_GPRELLOW
:
3585 BFD_ASSERT(gp
!= 0);
3589 case R_ALPHA_GPRELHIGH
:
3590 BFD_ASSERT(gp
!= 0);
3592 relocation
+= addend
;
3594 relocation
= (((bfd_signed_vma
) relocation
>> 16)
3595 + ((relocation
>> 15) & 1));
3598 case R_ALPHA_BRADDR
:
3600 /* The regular PC-relative stuff measures from the start of
3601 the instruction rather than the end. */
3605 case R_ALPHA_REFLONG
:
3606 case R_ALPHA_REFQUAD
:
3608 Elf_Internal_Rela outrel
;
3611 /* Careful here to remember RELATIVE relocations for global
3612 variables for symbolic shared objects. */
3614 if (h
&& alpha_elf_dynamic_symbol_p (&h
->root
, info
))
3616 BFD_ASSERT(h
->root
.dynindx
!= -1);
3617 outrel
.r_info
= ELF64_R_INFO(h
->root
.dynindx
, r_type
);
3618 outrel
.r_addend
= addend
;
3619 addend
= 0, relocation
= 0;
3621 else if (info
->shared
)
3623 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
3624 outrel
.r_addend
= 0;
3633 name
= (bfd_elf_string_from_elf_section
3634 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
3635 elf_section_data(input_section
)->rel_hdr
.sh_name
));
3636 BFD_ASSERT(name
!= NULL
);
3638 srel
= bfd_get_section_by_name (dynobj
, name
);
3639 BFD_ASSERT(srel
!= NULL
);
3644 if (elf_section_data (input_section
)->stab_info
== NULL
)
3645 outrel
.r_offset
= rel
->r_offset
;
3650 off
= (_bfd_stab_section_offset
3651 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3653 &elf_section_data (input_section
)->stab_info
,
3655 if (off
== (bfd_vma
) -1)
3657 outrel
.r_offset
= off
;
3661 outrel
.r_offset
+= (input_section
->output_section
->vma
3662 + input_section
->output_offset
);
3664 memset (&outrel
, 0, sizeof outrel
);
3666 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3667 ((Elf64_External_Rela
*)
3669 + srel
->reloc_count
++);
3670 BFD_ASSERT (sizeof(Elf64_External_Rela
) * srel
->reloc_count
3671 <= srel
->_cooked_size
);
3677 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3678 contents
, rel
->r_offset
, relocation
,
3688 case bfd_reloc_overflow
:
3693 name
= h
->root
.root
.root
.string
;
3696 name
= (bfd_elf_string_from_elf_section
3697 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
3701 name
= bfd_section_name (input_bfd
, sec
);
3703 if (! ((*info
->callbacks
->reloc_overflow
)
3704 (info
, name
, howto
->name
, (bfd_vma
) 0,
3705 input_bfd
, input_section
, rel
->r_offset
)))
3711 case bfd_reloc_outofrange
:
3719 /* Finish up dynamic symbol handling. We set the contents of various
3720 dynamic sections here. */
3723 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3725 struct bfd_link_info
*info
;
3726 struct elf_link_hash_entry
*h
;
3727 Elf_Internal_Sym
*sym
;
3729 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
3731 if (h
->plt
.offset
!= MINUS_ONE
)
3733 /* Fill in the .plt entry for this symbol. */
3734 asection
*splt
, *sgot
, *srel
;
3735 Elf_Internal_Rela outrel
;
3736 bfd_vma got_addr
, plt_addr
;
3738 struct alpha_elf_got_entry
*gotent
;
3740 BFD_ASSERT (h
->dynindx
!= -1);
3742 /* The first .got entry will be updated by the .plt with the
3743 address of the target function. */
3744 gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
3745 BFD_ASSERT (gotent
&& gotent
->addend
== 0);
3747 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3748 BFD_ASSERT (splt
!= NULL
);
3749 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3750 BFD_ASSERT (srel
!= NULL
);
3751 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
3752 BFD_ASSERT (sgot
!= NULL
);
3754 got_addr
= (sgot
->output_section
->vma
3755 + sgot
->output_offset
3756 + gotent
->got_offset
);
3757 plt_addr
= (splt
->output_section
->vma
3758 + splt
->output_offset
3761 plt_index
= (h
->plt
.offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3763 /* Fill in the entry in the procedure linkage table. */
3765 unsigned insn1
, insn2
, insn3
;
3767 insn1
= PLT_ENTRY_WORD1
| ((-(h
->plt
.offset
+ 4) >> 2) & 0x1fffff);
3768 insn2
= PLT_ENTRY_WORD2
;
3769 insn3
= PLT_ENTRY_WORD3
;
3771 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt
.offset
);
3772 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt
.offset
+ 4);
3773 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt
.offset
+ 8);
3776 /* Fill in the entry in the .rela.plt section. */
3777 outrel
.r_offset
= got_addr
;
3778 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
3779 outrel
.r_addend
= 0;
3781 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3782 ((Elf64_External_Rela
*)srel
->contents
3785 if (!(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3787 /* Mark the symbol as undefined, rather than as defined in the
3788 .plt section. Leave the value alone. */
3789 sym
->st_shndx
= SHN_UNDEF
;
3792 /* Fill in the entries in the .got. */
3793 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ gotent
->got_offset
);
3795 /* Subsequent .got entries will continue to bounce through the .plt. */
3798 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3799 BFD_ASSERT (! info
->shared
|| srel
!= NULL
);
3801 gotent
= gotent
->next
;
3804 sgot
= alpha_elf_tdata(gotent
->gotobj
)->got
;
3805 BFD_ASSERT(sgot
!= NULL
);
3806 BFD_ASSERT(gotent
->addend
== 0);
3808 bfd_put_64 (output_bfd
, plt_addr
,
3809 sgot
->contents
+ gotent
->got_offset
);
3813 outrel
.r_offset
= (sgot
->output_section
->vma
3814 + sgot
->output_offset
3815 + gotent
->got_offset
);
3816 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
3817 outrel
.r_addend
= 0;
3819 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3820 ((Elf64_External_Rela
*)
3822 + srel
->reloc_count
++);
3823 BFD_ASSERT (sizeof(Elf64_External_Rela
) * srel
->reloc_count
3824 <= srel
->_cooked_size
);
3827 gotent
= gotent
->next
;
3829 while (gotent
!= NULL
);
3832 else if (alpha_elf_dynamic_symbol_p (h
, info
))
3834 /* Fill in the dynamic relocations for this symbol's .got entries. */
3836 Elf_Internal_Rela outrel
;
3837 struct alpha_elf_got_entry
*gotent
;
3839 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3840 BFD_ASSERT (srel
!= NULL
);
3842 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_ALPHA_GLOB_DAT
);
3843 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
3845 gotent
= gotent
->next
)
3847 asection
*sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
3848 outrel
.r_offset
= (sgot
->output_section
->vma
3849 + sgot
->output_offset
3850 + gotent
->got_offset
);
3851 outrel
.r_addend
= gotent
->addend
;
3853 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3854 ((Elf64_External_Rela
*)srel
->contents
3855 + srel
->reloc_count
++));
3856 BFD_ASSERT (sizeof(Elf64_External_Rela
) * srel
->reloc_count
3857 <= srel
->_cooked_size
);
3861 /* Mark some specially defined symbols as absolute. */
3862 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3863 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3864 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3865 sym
->st_shndx
= SHN_ABS
;
3870 /* Finish up the dynamic sections. */
3873 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
3875 struct bfd_link_info
*info
;
3880 dynobj
= elf_hash_table (info
)->dynobj
;
3881 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3883 if (elf_hash_table (info
)->dynamic_sections_created
)
3886 Elf64_External_Dyn
*dyncon
, *dynconend
;
3888 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3889 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3891 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3892 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3893 for (; dyncon
< dynconend
; dyncon
++)
3895 Elf_Internal_Dyn dyn
;
3899 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3914 /* My interpretation of the TIS v1.1 ELF document indicates
3915 that RELASZ should not include JMPREL. This is not what
3916 the rest of the BFD does. It is, however, what the
3917 glibc ld.so wants. Do this fixup here until we found
3918 out who is right. */
3919 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
3923 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
3928 s
= bfd_get_section_by_name (output_bfd
, name
);
3929 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
3933 s
= bfd_get_section_by_name (output_bfd
, name
);
3935 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
3939 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3942 /* Initialize the PLT0 entry */
3943 if (splt
->_raw_size
> 0)
3945 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
3946 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
3947 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
3948 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
3950 /* The next two words will be filled in by ld.so */
3951 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 16);
3952 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 24);
3954 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
3962 /* We need to use a special link routine to handle the .reginfo and
3963 the .mdebug sections. We need to merge all instances of these
3964 sections together, not write them all out sequentially. */
3967 elf64_alpha_final_link (abfd
, info
)
3969 struct bfd_link_info
*info
;
3972 struct bfd_link_order
*p
;
3973 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3974 struct ecoff_debug_info debug
;
3975 const struct ecoff_debug_swap
*swap
3976 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3977 HDRR
*symhdr
= &debug
.symbolic_header
;
3978 PTR mdebug_handle
= NULL
;
3983 (*info
->callbacks
->warning
)
3984 (info
, _("using multiple gp values"), (char *) NULL
,
3985 output_bfd
, (asection
*) NULL
, (bfd_vma
) 0);
3989 /* Go through the sections and collect the .reginfo and .mdebug
3993 gptab_data_sec
= NULL
;
3994 gptab_bss_sec
= NULL
;
3995 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3997 #ifdef ERIC_neverdef
3998 if (strcmp (o
->name
, ".reginfo") == 0)
4000 memset (®info
, 0, sizeof reginfo
);
4002 /* We have found the .reginfo section in the output file.
4003 Look through all the link_orders comprising it and merge
4004 the information together. */
4005 for (p
= o
->link_order_head
;
4006 p
!= (struct bfd_link_order
*) NULL
;
4009 asection
*input_section
;
4011 Elf64_External_RegInfo ext
;
4014 if (p
->type
!= bfd_indirect_link_order
)
4016 if (p
->type
== bfd_fill_link_order
)
4021 input_section
= p
->u
.indirect
.section
;
4022 input_bfd
= input_section
->owner
;
4024 /* The linker emulation code has probably clobbered the
4025 size to be zero bytes. */
4026 if (input_section
->_raw_size
== 0)
4027 input_section
->_raw_size
= sizeof (Elf64_External_RegInfo
);
4029 if (! bfd_get_section_contents (input_bfd
, input_section
,
4035 bfd_alpha_elf64_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4037 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4038 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4039 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4040 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4041 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4043 /* ri_gp_value is set by the function
4044 alpha_elf_section_processing when the section is
4045 finally written out. */
4047 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4048 elf_link_input_bfd ignores this section. */
4049 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4052 /* Force the section size to the value we want. */
4053 o
->_raw_size
= sizeof (Elf64_External_RegInfo
);
4055 /* Skip this section later on (I don't think this currently
4056 matters, but someday it might). */
4057 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4063 if (strcmp (o
->name
, ".mdebug") == 0)
4065 struct extsym_info einfo
;
4067 /* We have found the .mdebug section in the output file.
4068 Look through all the link_orders comprising it and merge
4069 the information together. */
4070 symhdr
->magic
= swap
->sym_magic
;
4071 /* FIXME: What should the version stamp be? */
4073 symhdr
->ilineMax
= 0;
4077 symhdr
->isymMax
= 0;
4078 symhdr
->ioptMax
= 0;
4079 symhdr
->iauxMax
= 0;
4081 symhdr
->issExtMax
= 0;
4084 symhdr
->iextMax
= 0;
4086 /* We accumulate the debugging information itself in the
4087 debug_info structure. */
4089 debug
.external_dnr
= NULL
;
4090 debug
.external_pdr
= NULL
;
4091 debug
.external_sym
= NULL
;
4092 debug
.external_opt
= NULL
;
4093 debug
.external_aux
= NULL
;
4095 debug
.ssext
= debug
.ssext_end
= NULL
;
4096 debug
.external_fdr
= NULL
;
4097 debug
.external_rfd
= NULL
;
4098 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4100 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4101 if (mdebug_handle
== (PTR
) NULL
)
4110 static const char * const name
[] =
4112 ".text", ".init", ".fini", ".data",
4113 ".rodata", ".sdata", ".sbss", ".bss"
4115 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4116 scRData
, scSData
, scSBss
, scBss
};
4119 esym
.cobol_main
= 0;
4123 esym
.asym
.iss
= issNil
;
4124 esym
.asym
.st
= stLocal
;
4125 esym
.asym
.reserved
= 0;
4126 esym
.asym
.index
= indexNil
;
4127 for (i
= 0; i
< 8; i
++)
4129 esym
.asym
.sc
= sc
[i
];
4130 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4133 esym
.asym
.value
= s
->vma
;
4134 last
= s
->vma
+ s
->_raw_size
;
4137 esym
.asym
.value
= last
;
4139 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4145 for (p
= o
->link_order_head
;
4146 p
!= (struct bfd_link_order
*) NULL
;
4149 asection
*input_section
;
4151 const struct ecoff_debug_swap
*input_swap
;
4152 struct ecoff_debug_info input_debug
;
4156 if (p
->type
!= bfd_indirect_link_order
)
4158 if (p
->type
== bfd_fill_link_order
)
4163 input_section
= p
->u
.indirect
.section
;
4164 input_bfd
= input_section
->owner
;
4166 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4167 || (get_elf_backend_data (input_bfd
)
4168 ->elf_backend_ecoff_debug_swap
) == NULL
)
4170 /* I don't know what a non ALPHA ELF bfd would be
4171 doing with a .mdebug section, but I don't really
4172 want to deal with it. */
4176 input_swap
= (get_elf_backend_data (input_bfd
)
4177 ->elf_backend_ecoff_debug_swap
);
4179 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4181 /* The ECOFF linking code expects that we have already
4182 read in the debugging information and set up an
4183 ecoff_debug_info structure, so we do that now. */
4184 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
4188 if (! (bfd_ecoff_debug_accumulate
4189 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4190 &input_debug
, input_swap
, info
)))
4193 /* Loop through the external symbols. For each one with
4194 interesting information, try to find the symbol in
4195 the linker global hash table and save the information
4196 for the output external symbols. */
4197 eraw_src
= input_debug
.external_ext
;
4198 eraw_end
= (eraw_src
4199 + (input_debug
.symbolic_header
.iextMax
4200 * input_swap
->external_ext_size
));
4202 eraw_src
< eraw_end
;
4203 eraw_src
+= input_swap
->external_ext_size
)
4207 struct alpha_elf_link_hash_entry
*h
;
4209 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4210 if (ext
.asym
.sc
== scNil
4211 || ext
.asym
.sc
== scUndefined
4212 || ext
.asym
.sc
== scSUndefined
)
4215 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4216 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
4217 name
, false, false, true);
4218 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4224 < input_debug
.symbolic_header
.ifdMax
);
4225 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4231 /* Free up the information we just read. */
4232 free (input_debug
.line
);
4233 free (input_debug
.external_dnr
);
4234 free (input_debug
.external_pdr
);
4235 free (input_debug
.external_sym
);
4236 free (input_debug
.external_opt
);
4237 free (input_debug
.external_aux
);
4238 free (input_debug
.ss
);
4239 free (input_debug
.ssext
);
4240 free (input_debug
.external_fdr
);
4241 free (input_debug
.external_rfd
);
4242 free (input_debug
.external_ext
);
4244 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4245 elf_link_input_bfd ignores this section. */
4246 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4249 #ifdef ERIC_neverdef
4252 /* Create .rtproc section. */
4253 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4254 if (rtproc_sec
== NULL
)
4256 flagword flags
= (SEC_HAS_CONTENTS
4258 | SEC_LINKER_CREATED
4261 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4262 if (rtproc_sec
== NULL
4263 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4264 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
4268 if (! alpha_elf_create_procedure_table (mdebug_handle
, abfd
,
4269 info
, rtproc_sec
, &debug
))
4275 /* Build the external symbol information. */
4278 einfo
.debug
= &debug
;
4280 einfo
.failed
= false;
4281 elf_link_hash_traverse (elf_hash_table (info
),
4282 elf64_alpha_output_extsym
,
4287 /* Set the size of the .mdebug section. */
4288 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4290 /* Skip this section later on (I don't think this currently
4291 matters, but someday it might). */
4292 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4297 #ifdef ERIC_neverdef
4298 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4300 const char *subname
;
4303 Elf64_External_gptab
*ext_tab
;
4306 /* The .gptab.sdata and .gptab.sbss sections hold
4307 information describing how the small data area would
4308 change depending upon the -G switch. These sections
4309 not used in executables files. */
4310 if (! info
->relocateable
)
4314 for (p
= o
->link_order_head
;
4315 p
!= (struct bfd_link_order
*) NULL
;
4318 asection
*input_section
;
4320 if (p
->type
!= bfd_indirect_link_order
)
4322 if (p
->type
== bfd_fill_link_order
)
4327 input_section
= p
->u
.indirect
.section
;
4329 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4330 elf_link_input_bfd ignores this section. */
4331 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4334 /* Skip this section later on (I don't think this
4335 currently matters, but someday it might). */
4336 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4338 /* Really remove the section. */
4339 for (secpp
= &abfd
->sections
;
4341 secpp
= &(*secpp
)->next
)
4343 *secpp
= (*secpp
)->next
;
4344 --abfd
->section_count
;
4349 /* There is one gptab for initialized data, and one for
4350 uninitialized data. */
4351 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4353 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4357 (*_bfd_error_handler
)
4358 (_("%s: illegal section name `%s'"),
4359 bfd_get_filename (abfd
), o
->name
);
4360 bfd_set_error (bfd_error_nonrepresentable_section
);
4364 /* The linker script always combines .gptab.data and
4365 .gptab.sdata into .gptab.sdata, and likewise for
4366 .gptab.bss and .gptab.sbss. It is possible that there is
4367 no .sdata or .sbss section in the output file, in which
4368 case we must change the name of the output section. */
4369 subname
= o
->name
+ sizeof ".gptab" - 1;
4370 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4372 if (o
== gptab_data_sec
)
4373 o
->name
= ".gptab.data";
4375 o
->name
= ".gptab.bss";
4376 subname
= o
->name
+ sizeof ".gptab" - 1;
4377 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4380 /* Set up the first entry. */
4382 tab
= (Elf64_gptab
*) bfd_malloc (c
* sizeof (Elf64_gptab
));
4385 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4386 tab
[0].gt_header
.gt_unused
= 0;
4388 /* Combine the input sections. */
4389 for (p
= o
->link_order_head
;
4390 p
!= (struct bfd_link_order
*) NULL
;
4393 asection
*input_section
;
4397 bfd_size_type gpentry
;
4399 if (p
->type
!= bfd_indirect_link_order
)
4401 if (p
->type
== bfd_fill_link_order
)
4406 input_section
= p
->u
.indirect
.section
;
4407 input_bfd
= input_section
->owner
;
4409 /* Combine the gptab entries for this input section one
4410 by one. We know that the input gptab entries are
4411 sorted by ascending -G value. */
4412 size
= bfd_section_size (input_bfd
, input_section
);
4414 for (gpentry
= sizeof (Elf64_External_gptab
);
4416 gpentry
+= sizeof (Elf64_External_gptab
))
4418 Elf64_External_gptab ext_gptab
;
4419 Elf64_gptab int_gptab
;
4425 if (! (bfd_get_section_contents
4426 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4427 gpentry
, sizeof (Elf64_External_gptab
))))
4433 bfd_alpha_elf64_swap_gptab_in (input_bfd
, &ext_gptab
,
4435 val
= int_gptab
.gt_entry
.gt_g_value
;
4436 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4439 for (look
= 1; look
< c
; look
++)
4441 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4442 tab
[look
].gt_entry
.gt_bytes
+= add
;
4444 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4450 Elf64_gptab
*new_tab
;
4453 /* We need a new table entry. */
4454 new_tab
= ((Elf64_gptab
*)
4455 bfd_realloc ((PTR
) tab
,
4456 (c
+ 1) * sizeof (Elf64_gptab
)));
4457 if (new_tab
== NULL
)
4463 tab
[c
].gt_entry
.gt_g_value
= val
;
4464 tab
[c
].gt_entry
.gt_bytes
= add
;
4466 /* Merge in the size for the next smallest -G
4467 value, since that will be implied by this new
4470 for (look
= 1; look
< c
; look
++)
4472 if (tab
[look
].gt_entry
.gt_g_value
< val
4474 || (tab
[look
].gt_entry
.gt_g_value
4475 > tab
[max
].gt_entry
.gt_g_value
)))
4479 tab
[c
].gt_entry
.gt_bytes
+=
4480 tab
[max
].gt_entry
.gt_bytes
;
4485 last
= int_gptab
.gt_entry
.gt_bytes
;
4488 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4489 elf_link_input_bfd ignores this section. */
4490 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4493 /* The table must be sorted by -G value. */
4495 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4497 /* Swap out the table. */
4498 ext_tab
= ((Elf64_External_gptab
*)
4499 bfd_alloc (abfd
, c
* sizeof (Elf64_External_gptab
)));
4500 if (ext_tab
== NULL
)
4506 for (i
= 0; i
< c
; i
++)
4507 bfd_alpha_elf64_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4510 o
->_raw_size
= c
* sizeof (Elf64_External_gptab
);
4511 o
->contents
= (bfd_byte
*) ext_tab
;
4513 /* Skip this section later on (I don't think this currently
4514 matters, but someday it might). */
4515 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4521 /* Invoke the regular ELF backend linker to do all the work. */
4522 if (! bfd_elf64_bfd_final_link (abfd
, info
))
4525 /* Now write out the computed sections. */
4527 /* The .got subsections... */
4529 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
4530 for (i
= alpha_elf_hash_table(info
)->got_list
;
4532 i
= alpha_elf_tdata(i
)->got_link_next
)
4536 /* elf_bfd_final_link already did everything in dynobj. */
4540 sgot
= alpha_elf_tdata(i
)->got
;
4541 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
4542 sgot
->contents
, sgot
->output_offset
,
4548 #ifdef ERIC_neverdef
4549 if (reginfo_sec
!= (asection
*) NULL
)
4551 Elf64_External_RegInfo ext
;
4553 bfd_alpha_elf64_swap_reginfo_out (abfd
, ®info
, &ext
);
4554 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4555 (file_ptr
) 0, sizeof ext
))
4560 if (mdebug_sec
!= (asection
*) NULL
)
4562 BFD_ASSERT (abfd
->output_has_begun
);
4563 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4565 mdebug_sec
->filepos
))
4568 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4571 if (gptab_data_sec
!= (asection
*) NULL
)
4573 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4574 gptab_data_sec
->contents
,
4576 gptab_data_sec
->_raw_size
))
4580 if (gptab_bss_sec
!= (asection
*) NULL
)
4582 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4583 gptab_bss_sec
->contents
,
4585 gptab_bss_sec
->_raw_size
))
4592 /* ECOFF swapping routines. These are used when dealing with the
4593 .mdebug section, which is in the ECOFF debugging format. Copied
4594 from elf32-mips.c. */
4595 static const struct ecoff_debug_swap
4596 elf64_alpha_ecoff_debug_swap
=
4598 /* Symbol table magic number. */
4600 /* Alignment of debugging information. E.g., 4. */
4602 /* Sizes of external symbolic information. */
4603 sizeof (struct hdr_ext
),
4604 sizeof (struct dnr_ext
),
4605 sizeof (struct pdr_ext
),
4606 sizeof (struct sym_ext
),
4607 sizeof (struct opt_ext
),
4608 sizeof (struct fdr_ext
),
4609 sizeof (struct rfd_ext
),
4610 sizeof (struct ext_ext
),
4611 /* Functions to swap in external symbolic data. */
4620 _bfd_ecoff_swap_tir_in
,
4621 _bfd_ecoff_swap_rndx_in
,
4622 /* Functions to swap out external symbolic data. */
4631 _bfd_ecoff_swap_tir_out
,
4632 _bfd_ecoff_swap_rndx_out
,
4633 /* Function to read in symbolic data. */
4634 elf64_alpha_read_ecoff_info
4637 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
4638 #define TARGET_LITTLE_NAME "elf64-alpha"
4639 #define ELF_ARCH bfd_arch_alpha
4640 #define ELF_MACHINE_CODE EM_ALPHA
4641 #define ELF_MAXPAGESIZE 0x10000
4643 #define bfd_elf64_bfd_link_hash_table_create \
4644 elf64_alpha_bfd_link_hash_table_create
4646 #define bfd_elf64_bfd_reloc_type_lookup \
4647 elf64_alpha_bfd_reloc_type_lookup
4648 #define elf_info_to_howto \
4649 elf64_alpha_info_to_howto
4651 #define bfd_elf64_mkobject \
4652 elf64_alpha_mkobject
4653 #define elf_backend_object_p \
4654 elf64_alpha_object_p
4656 #define elf_backend_section_from_shdr \
4657 elf64_alpha_section_from_shdr
4658 #define elf_backend_fake_sections \
4659 elf64_alpha_fake_sections
4661 #define bfd_elf64_bfd_is_local_label_name \
4662 elf64_alpha_is_local_label_name
4663 #define bfd_elf64_find_nearest_line \
4664 elf64_alpha_find_nearest_line
4665 #define bfd_elf64_bfd_relax_section \
4666 elf64_alpha_relax_section
4668 #define elf_backend_add_symbol_hook \
4669 elf64_alpha_add_symbol_hook
4670 #define elf_backend_check_relocs \
4671 elf64_alpha_check_relocs
4672 #define elf_backend_create_dynamic_sections \
4673 elf64_alpha_create_dynamic_sections
4674 #define elf_backend_adjust_dynamic_symbol \
4675 elf64_alpha_adjust_dynamic_symbol
4676 #define elf_backend_always_size_sections \
4677 elf64_alpha_always_size_sections
4678 #define elf_backend_size_dynamic_sections \
4679 elf64_alpha_size_dynamic_sections
4680 #define elf_backend_relocate_section \
4681 elf64_alpha_relocate_section
4682 #define elf_backend_finish_dynamic_symbol \
4683 elf64_alpha_finish_dynamic_symbol
4684 #define elf_backend_finish_dynamic_sections \
4685 elf64_alpha_finish_dynamic_sections
4686 #define bfd_elf64_bfd_final_link \
4687 elf64_alpha_final_link
4689 #define elf_backend_ecoff_debug_swap \
4690 &elf64_alpha_ecoff_debug_swap
4693 * A few constants that determine how the .plt section is set up.
4695 #define elf_backend_want_got_plt 0
4696 #define elf_backend_plt_readonly 0
4697 #define elf_backend_want_plt_sym 1
4698 #define elf_backend_got_header_size 0
4699 #define elf_backend_plt_header_size PLT_HEADER_SIZE
4701 #include "elf64-target.h"