1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998 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 int elf64_alpha_additional_program_headers
77 static boolean elf64_alpha_create_got_section
78 PARAMS((bfd
*, struct bfd_link_info
*));
79 static boolean elf64_alpha_create_dynamic_sections
80 PARAMS((bfd
*, struct bfd_link_info
*));
82 static boolean elf64_alpha_read_ecoff_info
83 PARAMS((bfd
*, asection
*, struct ecoff_debug_info
*));
84 static boolean elf64_alpha_is_local_label_name
85 PARAMS((bfd
*, const char *));
86 static boolean elf64_alpha_find_nearest_line
87 PARAMS((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
88 const char **, unsigned int *));
90 #if defined(__STDC__) || defined(ALMOST_STDC)
91 struct alpha_elf_link_hash_entry
;
94 static boolean elf64_alpha_output_extsym
95 PARAMS((struct alpha_elf_link_hash_entry
*, PTR
));
97 static boolean elf64_alpha_can_merge_gots
98 PARAMS((bfd
*, bfd
*));
99 static void elf64_alpha_merge_gots
100 PARAMS((bfd
*, bfd
*));
101 static boolean elf64_alpha_calc_got_offsets_for_symbol
102 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
103 static void elf64_alpha_calc_got_offsets
PARAMS ((struct bfd_link_info
*));
104 static void elf64_alpha_strip_section_from_output
PARAMS ((asection
*));
105 static boolean elf64_alpha_size_got_sections
106 PARAMS ((bfd
*, struct bfd_link_info
*));
107 static boolean elf64_alpha_always_size_sections
108 PARAMS ((bfd
*, struct bfd_link_info
*));
109 static boolean elf64_alpha_calc_dynrel_sizes
110 PARAMS ((struct alpha_elf_link_hash_entry
*, struct bfd_link_info
*));
111 static boolean elf64_alpha_add_symbol_hook
112 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
113 const char **, flagword
*, asection
**, bfd_vma
*));
114 static boolean elf64_alpha_check_relocs
115 PARAMS((bfd
*, struct bfd_link_info
*, asection
*sec
,
116 const Elf_Internal_Rela
*));
117 static boolean elf64_alpha_adjust_dynamic_symbol
118 PARAMS((struct bfd_link_info
*, struct elf_link_hash_entry
*));
119 static boolean elf64_alpha_size_dynamic_sections
120 PARAMS((bfd
*, struct bfd_link_info
*));
121 static boolean elf64_alpha_adjust_dynindx
122 PARAMS((struct elf_link_hash_entry
*, PTR
));
123 static boolean elf64_alpha_relocate_section
124 PARAMS((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
125 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
126 static boolean elf64_alpha_finish_dynamic_symbol
127 PARAMS((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
128 Elf_Internal_Sym
*));
129 static boolean elf64_alpha_finish_dynamic_sections
130 PARAMS((bfd
*, struct bfd_link_info
*));
131 static boolean elf64_alpha_final_link
132 PARAMS((bfd
*, struct bfd_link_info
*));
135 struct alpha_elf_link_hash_entry
137 struct elf_link_hash_entry root
;
139 /* External symbol information. */
142 /* Cumulative flags for all the .got entries. */
145 /* Contexts (LITUSE) in which a literal was referenced. */
146 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
147 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
148 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
149 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x08
151 /* Used to implement multiple .got subsections. */
152 struct alpha_elf_got_entry
154 struct alpha_elf_got_entry
*next
;
156 /* which .got subsection? */
159 /* the addend in effect for this entry. */
162 /* the .got offset for this entry. */
167 /* An additional flag. */
168 #define ALPHA_ELF_GOT_ENTRY_RELOCS_DONE 0x10
173 /* used to count non-got, non-plt relocations for delayed sizing
174 of relocation sections. */
175 struct alpha_elf_reloc_entry
177 struct alpha_elf_reloc_entry
*next
;
179 /* which .reloc section? */
182 /* what kind of relocation? */
185 /* how many did we find? */
190 /* Alpha ELF linker hash table. */
192 struct alpha_elf_link_hash_table
194 struct elf_link_hash_table root
;
196 /* The head of a list of .got subsections linked through
197 alpha_elf_tdata(abfd)->got_link_next. */
201 /* Look up an entry in a Alpha ELF linker hash table. */
203 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
204 ((struct alpha_elf_link_hash_entry *) \
205 elf_link_hash_lookup (&(table)->root, (string), (create), \
208 /* Traverse a Alpha ELF linker hash table. */
210 #define alpha_elf_link_hash_traverse(table, func, info) \
211 (elf_link_hash_traverse \
213 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
216 /* Get the Alpha ELF linker hash table from a link_info structure. */
218 #define alpha_elf_hash_table(p) \
219 ((struct alpha_elf_link_hash_table *) ((p)->hash))
221 /* Get the object's symbols as our own entry type. */
223 #define alpha_elf_sym_hashes(abfd) \
224 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
226 /* Should we do dynamic things to this symbol? */
228 #define alpha_elf_dynamic_symbol_p(h, info) \
229 (((info)->shared && !(info)->symbolic && (h)->dynindx != -1) \
230 || (((h)->elf_link_hash_flags \
231 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
232 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
234 /* Create an entry in a Alpha ELF linker hash table. */
236 static struct bfd_hash_entry
*
237 elf64_alpha_link_hash_newfunc (entry
, table
, string
)
238 struct bfd_hash_entry
*entry
;
239 struct bfd_hash_table
*table
;
242 struct alpha_elf_link_hash_entry
*ret
=
243 (struct alpha_elf_link_hash_entry
*) entry
;
245 /* Allocate the structure if it has not already been allocated by a
247 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
248 ret
= ((struct alpha_elf_link_hash_entry
*)
249 bfd_hash_allocate (table
,
250 sizeof (struct alpha_elf_link_hash_entry
)));
251 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
252 return (struct bfd_hash_entry
*) ret
;
254 /* Call the allocation method of the superclass. */
255 ret
= ((struct alpha_elf_link_hash_entry
*)
256 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
258 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
260 /* Set local fields. */
261 memset (&ret
->esym
, 0, sizeof (EXTR
));
262 /* We use -2 as a marker to indicate that the information has
263 not been set. -1 means there is no associated ifd. */
266 ret
->got_entries
= NULL
;
267 ret
->reloc_entries
= NULL
;
270 return (struct bfd_hash_entry
*) ret
;
273 /* Create a Alpha ELF linker hash table. */
275 static struct bfd_link_hash_table
*
276 elf64_alpha_bfd_link_hash_table_create (abfd
)
279 struct alpha_elf_link_hash_table
*ret
;
281 ret
= ((struct alpha_elf_link_hash_table
*)
282 bfd_zalloc (abfd
, sizeof (struct alpha_elf_link_hash_table
)));
283 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
286 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
287 elf64_alpha_link_hash_newfunc
))
289 bfd_release (abfd
, ret
);
293 return &ret
->root
.root
;
296 /* We have some private fields hanging off of the elf_tdata structure. */
298 struct alpha_elf_obj_tdata
300 struct elf_obj_tdata root
;
302 /* For every input file, these are the got entries for that object's
304 struct alpha_elf_got_entry
** local_got_entries
;
306 /* For every input file, this is the object that owns the got that
307 this input file uses. */
310 /* For every got, this is a linked list through the objects using this got */
311 bfd
*in_got_link_next
;
313 /* For every got, this is a link to the next got subsegment. */
316 /* For every got, this is the section. */
319 /* For every got, this is it's total number of *entries*. */
320 int total_got_entries
;
322 /* For every got, this is the sum of the number of *entries* required
323 to hold all of the member object's local got. */
324 int n_local_got_entries
;
327 #define alpha_elf_tdata(abfd) \
328 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
331 elf64_alpha_mkobject (abfd
)
334 abfd
->tdata
.any
= bfd_zalloc (abfd
, sizeof (struct alpha_elf_obj_tdata
));
335 if (abfd
->tdata
.any
== NULL
)
341 elf64_alpha_object_p (abfd
)
344 /* Allocate our special target data. */
345 struct alpha_elf_obj_tdata
*new_tdata
;
346 new_tdata
= bfd_zalloc (abfd
, sizeof (struct alpha_elf_obj_tdata
));
347 if (new_tdata
== NULL
)
349 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
350 abfd
->tdata
.any
= new_tdata
;
352 /* Set the right machine number for an Alpha ELF file. */
353 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
356 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
357 from smaller values. Start with zero, widen, *then* decrement. */
358 #define MINUS_ONE (((bfd_vma)0) - 1)
360 static reloc_howto_type elf64_alpha_howto_table
[] =
362 HOWTO (R_ALPHA_NONE
, /* type */
364 0, /* size (0 = byte, 1 = short, 2 = long) */
366 true, /* pc_relative */
368 complain_overflow_dont
, /* complain_on_overflow */
369 elf64_alpha_reloc_nil
, /* special_function */
371 false, /* partial_inplace */
374 true), /* pcrel_offset */
376 /* A 32 bit reference to a symbol. */
377 HOWTO (R_ALPHA_REFLONG
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 false, /* pc_relative */
383 complain_overflow_bitfield
, /* complain_on_overflow */
384 0, /* special_function */
385 "REFLONG", /* name */
386 false, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 false), /* pcrel_offset */
391 /* A 64 bit reference to a symbol. */
392 HOWTO (R_ALPHA_REFQUAD
, /* type */
394 4, /* size (0 = byte, 1 = short, 2 = long) */
396 false, /* pc_relative */
398 complain_overflow_bitfield
, /* complain_on_overflow */
399 0, /* special_function */
400 "REFQUAD", /* name */
401 false, /* partial_inplace */
402 MINUS_ONE
, /* src_mask */
403 MINUS_ONE
, /* dst_mask */
404 false), /* pcrel_offset */
406 /* A 32 bit GP relative offset. This is just like REFLONG except
407 that when the value is used the value of the gp register will be
409 HOWTO (R_ALPHA_GPREL32
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_bitfield
, /* complain_on_overflow */
416 0, /* special_function */
417 "GPREL32", /* name */
418 false, /* partial_inplace */
419 0xffffffff, /* src_mask */
420 0xffffffff, /* dst_mask */
421 false), /* pcrel_offset */
423 /* Used for an instruction that refers to memory off the GP register. */
424 HOWTO (R_ALPHA_LITERAL
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_signed
, /* complain_on_overflow */
431 0, /* special_function */
432 "ELF_LITERAL", /* name */
433 false, /* partial_inplace */
434 0xffff, /* src_mask */
435 0xffff, /* dst_mask */
436 false), /* pcrel_offset */
438 /* This reloc only appears immediately following an ELF_LITERAL reloc.
439 It identifies a use of the literal. The symbol index is special:
440 1 means the literal address is in the base register of a memory
441 format instruction; 2 means the literal address is in the byte
442 offset register of a byte-manipulation instruction; 3 means the
443 literal address is in the target register of a jsr instruction.
444 This does not actually do any relocation. */
445 HOWTO (R_ALPHA_LITUSE
, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 false, /* pc_relative */
451 complain_overflow_dont
, /* complain_on_overflow */
452 elf64_alpha_reloc_nil
, /* special_function */
454 false, /* partial_inplace */
457 false), /* pcrel_offset */
459 /* Load the gp register. This is always used for a ldah instruction
460 which loads the upper 16 bits of the gp register. The symbol
461 index of the GPDISP instruction is an offset in bytes to the lda
462 instruction that loads the lower 16 bits. The value to use for
463 the relocation is the difference between the GP value and the
464 current location; the load will always be done against a register
465 holding the current address.
467 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
468 any offset is present in the instructions, it is an offset from
469 the register to the ldah instruction. This lets us avoid any
470 stupid hackery like inventing a gp value to do partial relocation
471 against. Also unlike ECOFF, we do the whole relocation off of
472 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
473 space consuming bit, that, since all the information was present
474 in the GPDISP_HI16 reloc. */
475 HOWTO (R_ALPHA_GPDISP
, /* type */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
479 false, /* pc_relative */
481 complain_overflow_dont
, /* complain_on_overflow */
482 elf64_alpha_reloc_gpdisp
, /* special_function */
484 false, /* partial_inplace */
485 0xffff, /* src_mask */
486 0xffff, /* dst_mask */
487 true), /* pcrel_offset */
489 /* A 21 bit branch. */
490 HOWTO (R_ALPHA_BRADDR
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 true, /* pc_relative */
496 complain_overflow_signed
, /* complain_on_overflow */
497 0, /* special_function */
499 false, /* partial_inplace */
500 0x1fffff, /* src_mask */
501 0x1fffff, /* dst_mask */
502 true), /* pcrel_offset */
504 /* A hint for a jump to a register. */
505 HOWTO (R_ALPHA_HINT
, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 true, /* pc_relative */
511 complain_overflow_dont
, /* complain_on_overflow */
512 0, /* special_function */
514 false, /* partial_inplace */
515 0x3fff, /* src_mask */
516 0x3fff, /* dst_mask */
517 true), /* pcrel_offset */
519 /* 16 bit PC relative offset. */
520 HOWTO (R_ALPHA_SREL16
, /* type */
522 1, /* size (0 = byte, 1 = short, 2 = long) */
524 true, /* pc_relative */
526 complain_overflow_signed
, /* complain_on_overflow */
527 0, /* special_function */
529 false, /* partial_inplace */
530 0xffff, /* src_mask */
531 0xffff, /* dst_mask */
532 false), /* pcrel_offset */
534 /* 32 bit PC relative offset. */
535 HOWTO (R_ALPHA_SREL32
, /* type */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
539 true, /* pc_relative */
541 complain_overflow_signed
, /* complain_on_overflow */
542 0, /* special_function */
544 false, /* partial_inplace */
545 0xffffffff, /* src_mask */
546 0xffffffff, /* dst_mask */
547 false), /* pcrel_offset */
549 /* A 64 bit PC relative offset. */
550 HOWTO (R_ALPHA_SREL64
, /* type */
552 4, /* size (0 = byte, 1 = short, 2 = long) */
554 true, /* pc_relative */
556 complain_overflow_signed
, /* complain_on_overflow */
557 0, /* special_function */
559 false, /* partial_inplace */
560 MINUS_ONE
, /* src_mask */
561 MINUS_ONE
, /* dst_mask */
562 false), /* pcrel_offset */
564 /* Push a value on the reloc evaluation stack. */
565 /* Not implemented -- it's dumb. */
566 HOWTO (R_ALPHA_OP_PUSH
, /* type */
568 0, /* size (0 = byte, 1 = short, 2 = long) */
570 false, /* pc_relative */
572 complain_overflow_dont
, /* complain_on_overflow */
573 elf64_alpha_reloc_bad
, /* special_function */
574 "OP_PUSH", /* name */
575 false, /* partial_inplace */
578 false), /* pcrel_offset */
580 /* Store the value from the stack at the given address. Store it in
581 a bitfield of size r_size starting at bit position r_offset. */
582 /* Not implemented -- it's dumb. */
583 HOWTO (R_ALPHA_OP_STORE
, /* type */
585 4, /* size (0 = byte, 1 = short, 2 = long) */
587 false, /* pc_relative */
589 complain_overflow_dont
, /* complain_on_overflow */
590 elf64_alpha_reloc_bad
, /* special_function */
591 "OP_STORE", /* name */
592 false, /* partial_inplace */
594 MINUS_ONE
, /* dst_mask */
595 false), /* pcrel_offset */
597 /* Subtract the reloc address from the value on the top of the
599 /* Not implemented -- it's dumb. */
600 HOWTO (R_ALPHA_OP_PSUB
, /* type */
602 0, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_dont
, /* complain_on_overflow */
607 elf64_alpha_reloc_bad
, /* special_function */
608 "OP_PSUB", /* name */
609 false, /* partial_inplace */
612 false), /* pcrel_offset */
614 /* Shift the value on the top of the relocation stack right by the
616 /* Not implemented -- it's dumb. */
617 HOWTO (R_ALPHA_OP_PRSHIFT
, /* type */
619 0, /* size (0 = byte, 1 = short, 2 = long) */
621 false, /* pc_relative */
623 complain_overflow_dont
, /* complain_on_overflow */
624 elf64_alpha_reloc_bad
, /* special_function */
625 "OP_PRSHIFT", /* name */
626 false, /* partial_inplace */
629 false), /* pcrel_offset */
631 /* Change the value of GP used by +r_addend until the next GPVALUE or the
632 end of the input bfd. */
633 /* Not implemented -- it's dumb. */
634 HOWTO (R_ALPHA_GPVALUE
,
636 0, /* size (0 = byte, 1 = short, 2 = long) */
638 false, /* pc_relative */
640 complain_overflow_dont
, /* complain_on_overflow */
641 elf64_alpha_reloc_bad
, /* special_function */
642 "GPVALUE", /* name */
643 false, /* partial_inplace */
646 false), /* pcrel_offset */
648 /* The high 16 bits of the displacement from GP to the target. */
649 HOWTO (R_ALPHA_GPRELHIGH
,
651 2, /* size (0 = byte, 1 = short, 2 = long) */
653 false, /* pc_relative */
655 complain_overflow_signed
, /* complain_on_overflow */
656 elf64_alpha_reloc_bad
, /* special_function */
657 "GPRELHIGH", /* name */
658 false, /* partial_inplace */
659 0xffff, /* src_mask */
660 0xffff, /* dst_mask */
661 false), /* pcrel_offset */
663 /* The low 16 bits of the displacement from GP to the target. */
664 HOWTO (R_ALPHA_GPRELLOW
,
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_dont
, /* complain_on_overflow */
671 elf64_alpha_reloc_bad
, /* special_function */
672 "GPRELLOW", /* name */
673 false, /* partial_inplace */
674 0xffff, /* src_mask */
675 0xffff, /* dst_mask */
676 false), /* pcrel_offset */
678 /* A 16-bit displacement from the GP to the target. */
679 /* XXX: Not implemented. */
680 HOWTO (R_ALPHA_IMMED_GP_16
,
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 false, /* pc_relative */
686 complain_overflow_signed
, /* complain_on_overflow */
687 0, /* special_function */
688 "IMMED_GP_16", /* name */
689 false, /* partial_inplace */
690 0xffff, /* src_mask */
691 0xffff, /* dst_mask */
692 false), /* pcrel_offset */
694 /* The high bits of a 32-bit displacement from the GP to the target; the
695 low bits are supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
696 /* XXX: Not implemented. */
697 HOWTO (R_ALPHA_IMMED_GP_HI32
,
699 0, /* size (0 = byte, 1 = short, 2 = long) */
701 false, /* pc_relative */
703 complain_overflow_dont
, /* complain_on_overflow */
704 elf64_alpha_reloc_bad
, /* special_function */
705 "IMMED_GP_HI32", /* name */
706 false, /* partial_inplace */
709 false), /* pcrel_offset */
711 /* The high bits of a 32-bit displacement to the starting address of the
712 current section (the relocation target is ignored); the low bits are
713 supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
714 /* XXX: Not implemented. */
715 HOWTO (R_ALPHA_IMMED_SCN_HI32
,
717 0, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_dont
, /* complain_on_overflow */
722 elf64_alpha_reloc_bad
, /* special_function */
723 "IMMED_SCN_HI32", /* name */
724 false, /* partial_inplace */
727 false), /* pcrel_offset */
729 /* The high bits of a 32-bit displacement from the previous br, bsr, jsr
730 or jmp insn (as tagged by a BRADDR or HINT reloc) to the target; the
731 low bits are supplied by subsequent R_ALPHA_IMMED_LO32 relocs. */
732 /* XXX: Not implemented. */
733 HOWTO (R_ALPHA_IMMED_BR_HI32
,
735 0, /* size (0 = byte, 1 = short, 2 = long) */
737 false, /* pc_relative */
739 complain_overflow_dont
, /* complain_on_overflow */
740 elf64_alpha_reloc_bad
, /* special_function */
741 "IMMED_BR_HI32", /* name */
742 false, /* partial_inplace */
745 false), /* pcrel_offset */
747 /* The low 16 bits of a displacement calculated in a previous HI32 reloc. */
748 /* XXX: Not implemented. */
749 HOWTO (R_ALPHA_IMMED_LO32
,
751 0, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_dont
, /* complain_on_overflow */
756 elf64_alpha_reloc_bad
, /* special_function */
757 "IMMED_LO32", /* name */
758 false, /* partial_inplace */
761 false), /* pcrel_offset */
763 /* Misc ELF relocations. */
765 /* A dynamic relocation to copy the target into our .dynbss section. */
766 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
767 is present because every other ELF has one, but should not be used
768 because .dynbss is an ugly thing. */
775 complain_overflow_dont
,
776 bfd_elf_generic_reloc
,
783 /* A dynamic relocation for a .got entry. */
784 HOWTO (R_ALPHA_GLOB_DAT
,
790 complain_overflow_dont
,
791 bfd_elf_generic_reloc
,
798 /* A dynamic relocation for a .plt entry. */
799 HOWTO (R_ALPHA_JMP_SLOT
,
805 complain_overflow_dont
,
806 bfd_elf_generic_reloc
,
813 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
814 HOWTO (R_ALPHA_RELATIVE
,
820 complain_overflow_dont
,
821 bfd_elf_generic_reloc
,
829 /* A relocation function which doesn't do anything. */
831 static bfd_reloc_status_type
832 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
839 char **error_message
;
842 reloc
->address
+= sec
->output_offset
;
846 /* A relocation function used for an unsupported reloc. */
848 static bfd_reloc_status_type
849 elf64_alpha_reloc_bad (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
856 char **error_message
;
859 reloc
->address
+= sec
->output_offset
;
860 return bfd_reloc_notsupported
;
863 /* Do the work of the GPDISP relocation. */
865 static bfd_reloc_status_type
866 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
872 bfd_reloc_status_type ret
= bfd_reloc_ok
;
874 unsigned long i_ldah
, i_lda
;
876 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
877 i_lda
= bfd_get_32 (abfd
, p_lda
);
879 /* Complain if the instructions are not correct. */
880 if (((i_ldah
>> 26) & 0x3f) != 0x09
881 || ((i_lda
>> 26) & 0x3f) != 0x08)
882 ret
= bfd_reloc_dangerous
;
884 /* Extract the user-supplied offset, mirroring the sign extensions
885 that the instructions perform. */
886 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
887 addend
= (addend
^ 0x80008000) - 0x80008000;
891 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
)0x80000000
892 || gpdisp
>= 0x7fff8000)
893 ret
= bfd_reloc_overflow
;
895 /* compensate for the sign extension again. */
896 i_ldah
= ((i_ldah
& 0xffff0000)
897 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
898 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
900 bfd_put_32 (abfd
, i_ldah
, p_ldah
);
901 bfd_put_32 (abfd
, i_lda
, p_lda
);
906 /* The special function for the GPDISP reloc. */
908 static bfd_reloc_status_type
909 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
912 arelent
*reloc_entry
;
915 asection
*input_section
;
919 bfd_reloc_status_type ret
;
920 bfd_vma gp
, relocation
;
921 bfd_byte
*p_ldah
, *p_lda
;
923 /* Don't do anything if we're not doing a final link. */
926 reloc_entry
->address
+= input_section
->output_offset
;
930 if (reloc_entry
->address
> input_section
->_cooked_size
||
931 reloc_entry
->address
+ reloc_entry
->addend
> input_section
->_cooked_size
)
932 return bfd_reloc_outofrange
;
934 /* The gp used in the portion of the output object to which this
935 input object belongs is cached on the input bfd. */
936 gp
= _bfd_get_gp_value (abfd
);
938 relocation
= (input_section
->output_section
->vma
939 + input_section
->output_offset
940 + reloc_entry
->address
);
942 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
943 p_lda
= p_ldah
+ reloc_entry
->addend
;
945 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
947 /* Complain if the instructions are not correct. */
948 if (ret
== bfd_reloc_dangerous
)
949 *err_msg
= "GPDISP relocation did not find ldah and lda instructions";
954 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
958 bfd_reloc_code_real_type bfd_reloc_val
;
962 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
964 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
965 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
966 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
967 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
968 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
969 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
970 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
971 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
972 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
973 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
974 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
975 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
976 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
979 /* Given a BFD reloc type, return a HOWTO structure. */
981 static reloc_howto_type
*
982 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
984 bfd_reloc_code_real_type code
;
986 const struct elf_reloc_map
*i
, *e
;
987 i
= e
= elf64_alpha_reloc_map
;
988 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
991 if (i
->bfd_reloc_val
== code
)
992 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
997 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1000 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
1003 Elf64_Internal_Rela
*dst
;
1007 r_type
= ELF64_R_TYPE(dst
->r_info
);
1008 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1009 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1012 /* These functions do relaxation for Alpha ELF.
1014 Currently I'm only handling what I can do with existing compiler
1015 and assembler support, which means no instructions are removed,
1016 though some may be nopped. At this time GCC does not emit enough
1017 information to do all of the relaxing that is possible. It will
1018 take some not small amount of work for that to happen.
1020 There are a couple of interesting papers that I once read on this
1021 subject, that I cannot find references to at the moment, that
1022 related to Alpha in particular. They are by David Wall, then of
1026 #define OP_LDAH 0x09
1027 #define INSN_JSR 0x68004000
1028 #define INSN_JSR_MASK 0xfc00c000
1032 #define INSN_UNOP 0x2fe00000
1034 struct alpha_relax_info
1039 Elf_Internal_Rela
*relocs
, *relend
;
1040 struct bfd_link_info
*link_info
;
1041 boolean changed_contents
;
1042 boolean changed_relocs
;
1045 struct alpha_elf_link_hash_entry
*h
;
1046 struct alpha_elf_got_entry
*gotent
;
1049 static Elf_Internal_Rela
* elf64_alpha_relax_with_lituse
1050 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1051 Elf_Internal_Rela
*irel
, Elf_Internal_Rela
*irelend
));
1053 static boolean elf64_alpha_relax_without_lituse
1054 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
,
1055 Elf_Internal_Rela
*irel
));
1057 static bfd_vma elf64_alpha_relax_opt_call
1058 PARAMS((struct alpha_relax_info
*info
, bfd_vma symval
));
1060 static boolean elf64_alpha_relax_section
1061 PARAMS((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
1064 static Elf_Internal_Rela
*
1065 elf64_alpha_relax_find_reloc_ofs (rel
, relend
, offset
, type
)
1066 Elf_Internal_Rela
*rel
, *relend
;
1070 while (rel
< relend
)
1072 if (rel
->r_offset
== offset
&& ELF64_R_TYPE (rel
->r_info
) == type
)
1079 static Elf_Internal_Rela
*
1080 elf64_alpha_relax_with_lituse (info
, symval
, irel
, irelend
)
1081 struct alpha_relax_info
*info
;
1083 Elf_Internal_Rela
*irel
, *irelend
;
1085 Elf_Internal_Rela
*urel
;
1086 int flags
, count
, i
;
1087 bfd_signed_vma disp
;
1090 boolean lit_reused
= false;
1091 boolean all_optimized
= true;
1092 unsigned int lit_insn
;
1094 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1095 if (lit_insn
>> 26 != OP_LDQ
)
1097 ((*_bfd_error_handler
)
1098 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1099 bfd_get_filename (info
->abfd
), info
->sec
->name
,
1100 (unsigned long)irel
->r_offset
));
1104 /* Summarize how this particular LITERAL is used. */
1105 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
1107 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
1109 if (urel
->r_addend
>= 0 && urel
->r_addend
<= 3)
1110 flags
|= 1 << urel
->r_addend
;
1113 /* A little preparation for the loop... */
1114 disp
= symval
- info
->gp
;
1115 fits16
= (disp
>= -(bfd_signed_vma
)0x8000 && disp
< 0x8000);
1116 fits32
= (disp
>= -(bfd_signed_vma
)0x80000000 && disp
< 0x7fff8000);
1118 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
1121 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
1123 switch (urel
->r_addend
)
1125 default: /* 0 = ADDRESS FORMAT */
1126 /* This type is really just a placeholder to note that all
1127 uses cannot be optimized, but to still allow some. */
1128 all_optimized
= false;
1131 case 1: /* MEM FORMAT */
1132 /* We can always optimize 16-bit displacements. */
1135 /* FIXME: sanity check the insn for mem format with
1138 /* Take the op code and dest from this insn, take the base
1139 register from the literal insn. Leave the offset alone. */
1140 insn
= (insn
& 0xffe00000) | (lit_insn
& 0x001f0000);
1141 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1143 urel
->r_addend
= irel
->r_addend
;
1144 info
->changed_relocs
= true;
1146 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ urel
->r_offset
);
1147 info
->changed_contents
= true;
1150 /* If all mem+byte, we can optimize 32-bit mem displacements. */
1151 else if (fits32
&& !(flags
& ~6))
1153 /* FIXME: sanity check that lit insn Ra is mem insn Rb, and
1154 that mem_insn disp is zero. */
1156 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1158 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
1159 bfd_put_32 (info
->abfd
, lit_insn
,
1160 info
->contents
+ irel
->r_offset
);
1162 info
->changed_contents
= true;
1164 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1166 urel
->r_addend
= irel
->r_addend
;
1167 info
->changed_relocs
= true;
1170 all_optimized
= false;
1173 case 2: /* BYTE OFFSET FORMAT */
1174 /* We can always optimize byte instructions. */
1176 /* FIXME: sanity check the insn for byte op. Check that the
1177 literal dest reg is indeed Rb in the byte insn. */
1179 insn
= (insn
& ~0x001ff000) | ((symval
& 7) << 13) | 0x1000;
1181 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1183 info
->changed_relocs
= true;
1185 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ urel
->r_offset
);
1186 info
->changed_contents
= true;
1189 case 3: /* CALL FORMAT */
1191 /* If not zero, place to jump without needing pv. */
1192 bfd_vma optdest
= elf64_alpha_relax_opt_call (info
, symval
);
1193 bfd_vma org
= (info
->sec
->output_section
->vma
1194 + info
->sec
->output_offset
1195 + urel
->r_offset
+ 4);
1196 bfd_signed_vma odisp
;
1198 odisp
= (optdest
? optdest
: symval
) - org
;
1199 if (odisp
>= -0x400000 && odisp
< 0x400000)
1201 Elf_Internal_Rela
*xrel
;
1203 /* Preserve branch prediction call stack when possible. */
1204 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
1205 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
1207 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
1209 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
1211 urel
->r_addend
= irel
->r_addend
;
1212 info
->changed_relocs
= true;
1214 /* Kill any HINT reloc that might exist for this insn. */
1215 xrel
= (elf64_alpha_relax_find_reloc_ofs
1216 (info
->relocs
, info
->relend
, urel
->r_offset
,
1219 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1222 urel
->r_addend
+= optdest
- symval
;
1224 all_optimized
= false;
1226 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ urel
->r_offset
);
1227 info
->changed_contents
= true;
1230 all_optimized
= false;
1232 /* ??? If target gp == current gp we can eliminate the gp reload.
1233 This does depend on every place a gp could be reloaded will
1234 be, which currently happens for all code produced by gcc, but
1235 not necessarily by hand-coded assembly, or if sibling calls
1238 Perhaps conditionalize this on a flag being set in the target
1239 object file's header, and have gcc set it? */
1245 /* If all cases were optimized, we can reduce the use count on this
1246 got entry by one, possibly eliminating it. */
1249 info
->gotent
->use_count
-= 1;
1250 alpha_elf_tdata (info
->gotent
->gotobj
)->total_got_entries
-= 1;
1252 alpha_elf_tdata (info
->gotent
->gotobj
)->n_local_got_entries
-= 1;
1254 /* If the literal instruction is no longer needed (it may have been
1255 reused. We can eliminate it.
1256 ??? For now, I don't want to deal with compacting the section,
1257 so just nop it out. */
1260 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
1261 info
->changed_relocs
= true;
1263 bfd_put_32 (info
->abfd
, INSN_UNOP
, info
->contents
+ irel
->r_offset
);
1264 info
->changed_contents
= true;
1268 return irel
+ count
;
1272 elf64_alpha_relax_opt_call (info
, symval
)
1273 struct alpha_relax_info
*info
;
1276 /* If the function has the same gp, and we can identify that the
1277 function does not use its function pointer, we can eliminate the
1280 ??? The .prologue [0,1] information is what we need. How do we
1281 get it out of the mdebug uglyness? What shall we do when we drop
1282 that crap for dwarf2?
1284 For now, only consider the case in which there is an identifyable
1285 GP load in the first two words. We can then skip over that load. */
1291 elf64_alpha_relax_without_lituse (info
, symval
, irel
)
1292 struct alpha_relax_info
*info
;
1294 Elf_Internal_Rela
*irel
;
1297 bfd_signed_vma disp
;
1299 /* Get the instruction. */
1300 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
1302 if (insn
>> 26 != OP_LDQ
)
1304 ((*_bfd_error_handler
)
1305 ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn",
1306 bfd_get_filename (info
->abfd
), info
->sec
->name
,
1307 (unsigned long) irel
->r_offset
));
1311 /* So we aren't told much. Do what we can with the address load and
1312 fake the rest. All of the optimizations here require that the
1313 offset from the GP fit in 16 bits. */
1315 disp
= symval
- info
->gp
;
1316 if (disp
< -0x8000 || disp
>= 0x8000)
1319 /* On the LITERAL instruction itself, consider exchanging
1320 `ldq R,X(gp)' for `lda R,Y(gp)'. */
1322 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
1323 bfd_put_32 (info
->abfd
, insn
, info
->contents
+ irel
->r_offset
);
1324 info
->changed_contents
= true;
1326 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), R_ALPHA_GPRELLOW
);
1327 info
->changed_relocs
= true;
1329 /* Reduce the use count on this got entry by one, possibly
1331 info
->gotent
->use_count
-= 1;
1332 alpha_elf_tdata (info
->gotent
->gotobj
)->total_got_entries
-= 1;
1334 alpha_elf_tdata (info
->gotent
->gotobj
)->n_local_got_entries
-= 1;
1336 /* ??? Search forward through this basic block looking for insns
1337 that use the target register. Stop after an insn modifying the
1338 register is seen, or after a branch or call.
1340 Any such memory load insn may be substituted by a load directly
1341 off the GP. This allows the memory load insn to be issued before
1342 the calculated GP register would otherwise be ready.
1344 Any such jsr insn can be replaced by a bsr if it is in range.
1346 This would mean that we'd have to _add_ relocations, the pain of
1347 which gives one pause. */
1353 elf64_alpha_relax_section (abfd
, sec
, link_info
, again
)
1356 struct bfd_link_info
*link_info
;
1359 Elf_Internal_Shdr
*symtab_hdr
;
1360 Elf_Internal_Rela
*internal_relocs
;
1361 Elf_Internal_Rela
*free_relocs
= NULL
;
1362 Elf_Internal_Rela
*irel
, *irelend
;
1363 bfd_byte
*free_contents
= NULL
;
1364 Elf64_External_Sym
*extsyms
= NULL
;
1365 Elf64_External_Sym
*free_extsyms
= NULL
;
1366 struct alpha_elf_got_entry
**local_got_entries
;
1367 struct alpha_relax_info info
;
1369 /* We are not currently changing any sizes, so only one pass. */
1372 if (link_info
->relocateable
1373 || (sec
->flags
& SEC_RELOC
) == 0
1374 || sec
->reloc_count
== 0)
1377 /* If this is the first time we have been called for this section,
1378 initialize the cooked size. */
1379 if (sec
->_cooked_size
== 0)
1380 sec
->_cooked_size
= sec
->_raw_size
;
1382 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1383 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
1385 /* Load the relocations for this section. */
1386 internal_relocs
= (_bfd_elf64_link_read_relocs
1387 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1388 link_info
->keep_memory
));
1389 if (internal_relocs
== NULL
)
1391 if (! link_info
->keep_memory
)
1392 free_relocs
= internal_relocs
;
1394 memset(&info
, 0, sizeof(info
));
1397 info
.link_info
= link_info
;
1398 info
.relocs
= internal_relocs
;
1399 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
1401 /* Find the GP for this object. */
1402 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
1405 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
1406 info
.gp
= _bfd_get_gp_value (info
.gotobj
);
1409 info
.gp
= (sgot
->output_section
->vma
1410 + sgot
->output_offset
1412 _bfd_set_gp_value (info
.gotobj
, info
.gp
);
1416 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1421 if (ELF64_R_TYPE (irel
->r_info
) != (int) R_ALPHA_LITERAL
)
1424 /* Get the section contents. */
1425 if (info
.contents
== NULL
)
1427 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1428 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
1431 info
.contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
1432 if (info
.contents
== NULL
)
1434 free_contents
= info
.contents
;
1436 if (! bfd_get_section_contents (abfd
, sec
, info
.contents
,
1437 (file_ptr
) 0, sec
->_raw_size
))
1442 /* Read this BFD's symbols if we haven't done so already. */
1443 if (extsyms
== NULL
)
1445 if (symtab_hdr
->contents
!= NULL
)
1446 extsyms
= (Elf64_External_Sym
*) symtab_hdr
->contents
;
1449 extsyms
= ((Elf64_External_Sym
*)
1450 bfd_malloc (symtab_hdr
->sh_size
));
1451 if (extsyms
== NULL
)
1453 free_extsyms
= extsyms
;
1454 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
1455 || (bfd_read (extsyms
, 1, symtab_hdr
->sh_size
, abfd
)
1456 != symtab_hdr
->sh_size
))
1461 /* Get the value of the symbol referred to by the reloc. */
1462 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1464 Elf_Internal_Sym isym
;
1466 /* A local symbol. */
1467 bfd_elf64_swap_symbol_in (abfd
,
1468 extsyms
+ ELF64_R_SYM (irel
->r_info
),
1472 info
.gotent
= local_got_entries
[ELF64_R_SYM(irel
->r_info
)];
1473 symval
= (isym
.st_value
1474 + sec
->output_section
->vma
1475 + sec
->output_offset
);
1480 struct alpha_elf_link_hash_entry
*h
;
1481 struct alpha_elf_got_entry
*gotent
;
1483 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1484 h
= alpha_elf_sym_hashes (abfd
)[indx
];
1485 BFD_ASSERT (h
!= NULL
);
1487 /* We can't do anthing with undefined or dynamic symbols. */
1488 if (h
->root
.root
.type
== bfd_link_hash_undefined
1489 || h
->root
.root
.type
== bfd_link_hash_undefweak
1490 || alpha_elf_dynamic_symbol_p (&h
->root
, link_info
))
1493 /* Search for the got entry to be used by this relocation. */
1494 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
1495 if (gotent
->gotobj
== info
.gotobj
1496 && gotent
->addend
== irel
->r_addend
)
1500 info
.gotent
= gotent
;
1501 symval
= (h
->root
.root
.u
.def
.value
1502 + h
->root
.root
.u
.def
.section
->output_section
->vma
1503 + h
->root
.root
.u
.def
.section
->output_offset
);
1505 symval
+= irel
->r_addend
;
1507 BFD_ASSERT(info
.gotent
!= NULL
);
1509 /* If there exist LITUSE relocations immediately following, this
1510 opens up all sorts of interesting optimizations, because we
1511 now know every location that this address load is used. */
1513 if (irel
+1 < irelend
&& ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
1515 irel
= elf64_alpha_relax_with_lituse (&info
, symval
, irel
, irelend
);
1521 if (!elf64_alpha_relax_without_lituse (&info
, symval
, irel
))
1526 if (!elf64_alpha_size_got_sections (abfd
, link_info
))
1529 if (info
.changed_relocs
)
1531 elf_section_data (sec
)->relocs
= internal_relocs
;
1533 else if (free_relocs
!= NULL
)
1538 if (info
.changed_contents
)
1540 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
1542 else if (free_contents
!= NULL
)
1544 if (! link_info
->keep_memory
)
1545 free (free_contents
);
1548 /* Cache the section contents for elf_link_input_bfd. */
1549 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
1553 if (free_extsyms
!= NULL
)
1555 if (! link_info
->keep_memory
)
1556 free (free_extsyms
);
1559 /* Cache the symbols for elf_link_input_bfd. */
1560 symtab_hdr
->contents
= extsyms
;
1567 if (free_relocs
!= NULL
)
1569 if (free_contents
!= NULL
)
1570 free (free_contents
);
1571 if (free_extsyms
!= NULL
)
1572 free (free_extsyms
);
1577 #define PLT_HEADER_SIZE 32
1578 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
1579 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
1580 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
1581 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
1583 #define PLT_ENTRY_SIZE 12
1584 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
1585 #define PLT_ENTRY_WORD2 0
1586 #define PLT_ENTRY_WORD3 0
1588 #define MAX_GOT_ENTRIES (64*1024 / 8)
1590 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
1592 /* Handle an Alpha specific section when reading an object file. This
1593 is called when elfcode.h finds a section with an unknown type.
1594 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
1598 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
1600 Elf64_Internal_Shdr
*hdr
;
1605 /* There ought to be a place to keep ELF backend specific flags, but
1606 at the moment there isn't one. We just keep track of the
1607 sections by their name, instead. Fortunately, the ABI gives
1608 suggested names for all the MIPS specific sections, so we will
1609 probably get away with this. */
1610 switch (hdr
->sh_type
)
1612 case SHT_ALPHA_DEBUG
:
1613 if (strcmp (name
, ".mdebug") != 0)
1616 #ifdef ERIC_neverdef
1617 case SHT_ALPHA_REGINFO
:
1618 if (strcmp (name
, ".reginfo") != 0
1619 || hdr
->sh_size
!= sizeof (Elf64_External_RegInfo
))
1627 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1629 newsect
= hdr
->bfd_section
;
1631 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
1633 if (! bfd_set_section_flags (abfd
, newsect
,
1634 (bfd_get_section_flags (abfd
, newsect
)
1639 #ifdef ERIC_neverdef
1640 /* For a .reginfo section, set the gp value in the tdata information
1641 from the contents of this section. We need the gp value while
1642 processing relocs, so we just get it now. */
1643 if (hdr
->sh_type
== SHT_ALPHA_REGINFO
)
1645 Elf64_External_RegInfo ext
;
1648 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
1649 (file_ptr
) 0, sizeof ext
))
1651 bfd_alpha_elf64_swap_reginfo_in (abfd
, &ext
, &s
);
1652 elf_gp (abfd
) = s
.ri_gp_value
;
1659 /* Set the correct type for an Alpha ELF section. We do this by the
1660 section name, which is a hack, but ought to work. */
1663 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
1665 Elf64_Internal_Shdr
*hdr
;
1668 register const char *name
;
1670 name
= bfd_get_section_name (abfd
, sec
);
1672 if (strcmp (name
, ".mdebug") == 0)
1674 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
1675 /* In a shared object on Irix 5.3, the .mdebug section has an
1676 entsize of 0. FIXME: Does this matter? */
1677 if ((abfd
->flags
& DYNAMIC
) != 0 )
1678 hdr
->sh_entsize
= 0;
1680 hdr
->sh_entsize
= 1;
1682 #ifdef ERIC_neverdef
1683 else if (strcmp (name
, ".reginfo") == 0)
1685 hdr
->sh_type
= SHT_ALPHA_REGINFO
;
1686 /* In a shared object on Irix 5.3, the .reginfo section has an
1687 entsize of 0x18. FIXME: Does this matter? */
1688 if ((abfd
->flags
& DYNAMIC
) != 0)
1689 hdr
->sh_entsize
= sizeof (Elf64_External_RegInfo
);
1691 hdr
->sh_entsize
= 1;
1693 /* Force the section size to the correct value, even if the
1694 linker thinks it is larger. The link routine below will only
1695 write out this much data for .reginfo. */
1696 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf64_External_RegInfo
);
1698 else if (strcmp (name
, ".hash") == 0
1699 || strcmp (name
, ".dynamic") == 0
1700 || strcmp (name
, ".dynstr") == 0)
1702 hdr
->sh_entsize
= 0;
1703 hdr
->sh_info
= SIZEOF_ALPHA_DYNSYM_SECNAMES
;
1706 else if (strcmp (name
, ".sdata") == 0
1707 || strcmp (name
, ".sbss") == 0
1708 || strcmp (name
, ".lit4") == 0
1709 || strcmp (name
, ".lit8") == 0)
1710 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
1715 /* Hook called by the linker routine which adds symbols from an object
1716 file. We use it to put .comm items in .sbss, and not .bss. */
1719 elf64_alpha_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1721 struct bfd_link_info
*info
;
1722 const Elf_Internal_Sym
*sym
;
1728 if (sym
->st_shndx
== SHN_COMMON
1729 && !info
->relocateable
1730 && sym
->st_size
<= bfd_get_gp_size (abfd
))
1732 /* Common symbols less than or equal to -G nn bytes are
1733 automatically put into .sbss. */
1735 asection
*sbss
= bfd_get_section_by_name (abfd
, ".sbss");
1739 sbss
= bfd_make_section (abfd
, ".sbss");
1741 || !bfd_set_section_flags (abfd
, sbss
, (SEC_ALLOC
| SEC_LOAD
1743 | SEC_LINKER_CREATED
)))
1747 if (bfd_get_section_alignment (abfd
, sbss
) < sym
->st_value
)
1749 if (!bfd_set_section_alignment (abfd
, sbss
, sym
->st_value
))
1754 *valp
= sym
->st_size
;
1760 /* Return the number of additional phdrs we will need. */
1763 elf64_alpha_additional_program_headers (abfd
)
1771 s
= bfd_get_section_by_name (abfd
, ".reginfo");
1772 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
1774 /* We need a PT_ALPHA_REGINFO segment. */
1778 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
1779 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
1781 /* We need a PT_ALPHA_RTPROC segment. */
1788 /* Create the .got section. */
1791 elf64_alpha_create_got_section(abfd
, info
)
1793 struct bfd_link_info
*info
;
1797 if (bfd_get_section_by_name (abfd
, ".got"))
1800 s
= bfd_make_section (abfd
, ".got");
1802 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1805 | SEC_LINKER_CREATED
))
1806 || !bfd_set_section_alignment (abfd
, s
, 3))
1809 alpha_elf_tdata (abfd
)->got
= s
;
1814 /* Create all the dynamic sections. */
1817 elf64_alpha_create_dynamic_sections (abfd
, info
)
1819 struct bfd_link_info
*info
;
1822 struct elf_link_hash_entry
*h
;
1824 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1826 s
= bfd_make_section (abfd
, ".plt");
1828 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1831 | SEC_LINKER_CREATED
1833 || ! bfd_set_section_alignment (abfd
, s
, 3))
1836 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1839 if (! (_bfd_generic_link_add_one_symbol
1840 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
1841 (bfd_vma
) 0, (const char *) NULL
, false,
1842 get_elf_backend_data (abfd
)->collect
,
1843 (struct bfd_link_hash_entry
**) &h
)))
1845 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1846 h
->type
= STT_OBJECT
;
1849 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1852 s
= bfd_make_section (abfd
, ".rela.plt");
1854 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1857 | SEC_LINKER_CREATED
1859 || ! bfd_set_section_alignment (abfd
, s
, 3))
1862 /* We may or may not have created a .got section for this object, but
1863 we definitely havn't done the rest of the work. */
1865 if (!elf64_alpha_create_got_section (abfd
, info
))
1868 s
= bfd_make_section(abfd
, ".rela.got");
1870 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1873 | SEC_LINKER_CREATED
1875 || !bfd_set_section_alignment (abfd
, s
, 3))
1878 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1879 dynobj's .got section. We don't do this in the linker script
1880 because we don't want to define the symbol if we are not creating
1881 a global offset table. */
1883 if (!(_bfd_generic_link_add_one_symbol
1884 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
,
1885 alpha_elf_tdata(abfd
)->got
, (bfd_vma
) 0, (const char *) NULL
,
1886 false, get_elf_backend_data (abfd
)->collect
,
1887 (struct bfd_link_hash_entry
**) &h
)))
1889 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1890 h
->type
= STT_OBJECT
;
1893 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1896 elf_hash_table (info
)->hgot
= h
;
1901 /* Read ECOFF debugging information from a .mdebug section into a
1902 ecoff_debug_info structure. */
1905 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
1908 struct ecoff_debug_info
*debug
;
1911 const struct ecoff_debug_swap
*swap
;
1912 char *ext_hdr
= NULL
;
1914 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1916 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
1917 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1920 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1921 swap
->external_hdr_size
)
1925 symhdr
= &debug
->symbolic_header
;
1926 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1928 /* The symbolic header contains absolute file offsets and sizes to
1930 #define READ(ptr, offset, count, size, type) \
1931 if (symhdr->count == 0) \
1932 debug->ptr = NULL; \
1935 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1936 if (debug->ptr == NULL) \
1937 goto error_return; \
1938 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1939 || (bfd_read (debug->ptr, size, symhdr->count, \
1940 abfd) != size * symhdr->count)) \
1941 goto error_return; \
1944 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1945 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1946 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1947 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1948 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1949 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1951 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1952 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1953 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
1954 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
1955 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
1959 debug
->adjust
= NULL
;
1964 if (ext_hdr
!= NULL
)
1966 if (debug
->line
!= NULL
)
1968 if (debug
->external_dnr
!= NULL
)
1969 free (debug
->external_dnr
);
1970 if (debug
->external_pdr
!= NULL
)
1971 free (debug
->external_pdr
);
1972 if (debug
->external_sym
!= NULL
)
1973 free (debug
->external_sym
);
1974 if (debug
->external_opt
!= NULL
)
1975 free (debug
->external_opt
);
1976 if (debug
->external_aux
!= NULL
)
1977 free (debug
->external_aux
);
1978 if (debug
->ss
!= NULL
)
1980 if (debug
->ssext
!= NULL
)
1981 free (debug
->ssext
);
1982 if (debug
->external_fdr
!= NULL
)
1983 free (debug
->external_fdr
);
1984 if (debug
->external_rfd
!= NULL
)
1985 free (debug
->external_rfd
);
1986 if (debug
->external_ext
!= NULL
)
1987 free (debug
->external_ext
);
1991 /* Alpha ELF local labels start with '$'. */
1994 elf64_alpha_is_local_label_name (abfd
, name
)
1998 return name
[0] == '$';
2001 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
2002 routine in order to handle the ECOFF debugging information. We
2003 still call this mips_elf_find_line because of the slot
2004 find_line_info in elf_obj_tdata is declared that way. */
2006 struct mips_elf_find_line
2008 struct ecoff_debug_info d
;
2009 struct ecoff_find_line i
;
2013 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2014 functionname_ptr
, line_ptr
)
2019 const char **filename_ptr
;
2020 const char **functionname_ptr
;
2021 unsigned int *line_ptr
;
2025 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
2029 struct mips_elf_find_line
*fi
;
2030 const struct ecoff_debug_swap
* const swap
=
2031 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2033 /* If we are called during a link, alpha_elf_final_link may have
2034 cleared the SEC_HAS_CONTENTS field. We force it back on here
2035 if appropriate (which it normally will be). */
2036 origflags
= msec
->flags
;
2037 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
2038 msec
->flags
|= SEC_HAS_CONTENTS
;
2040 fi
= elf_tdata (abfd
)->find_line_info
;
2043 bfd_size_type external_fdr_size
;
2046 struct fdr
*fdr_ptr
;
2048 fi
= ((struct mips_elf_find_line
*)
2049 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
2052 msec
->flags
= origflags
;
2056 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
2058 msec
->flags
= origflags
;
2062 /* Swap in the FDR information. */
2063 fi
->d
.fdr
= ((struct fdr
*)
2065 (fi
->d
.symbolic_header
.ifdMax
*
2066 sizeof (struct fdr
))));
2067 if (fi
->d
.fdr
== NULL
)
2069 msec
->flags
= origflags
;
2072 external_fdr_size
= swap
->external_fdr_size
;
2073 fdr_ptr
= fi
->d
.fdr
;
2074 fraw_src
= (char *) fi
->d
.external_fdr
;
2075 fraw_end
= (fraw_src
2076 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
2077 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
2078 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
2080 elf_tdata (abfd
)->find_line_info
= fi
;
2082 /* Note that we don't bother to ever free this information.
2083 find_nearest_line is either called all the time, as in
2084 objdump -l, so the information should be saved, or it is
2085 rarely called, as in ld error messages, so the memory
2086 wasted is unimportant. Still, it would probably be a
2087 good idea for free_cached_info to throw it away. */
2090 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
2091 &fi
->i
, filename_ptr
, functionname_ptr
,
2094 msec
->flags
= origflags
;
2098 msec
->flags
= origflags
;
2101 /* Fall back on the generic ELF find_nearest_line routine. */
2103 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
2104 filename_ptr
, functionname_ptr
,
2108 /* Structure used to pass information to alpha_elf_output_extsym. */
2113 struct bfd_link_info
*info
;
2114 struct ecoff_debug_info
*debug
;
2115 const struct ecoff_debug_swap
*swap
;
2120 elf64_alpha_output_extsym (h
, data
)
2121 struct alpha_elf_link_hash_entry
*h
;
2124 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
2126 asection
*sec
, *output_section
;
2128 if (h
->root
.indx
== -2)
2130 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2131 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
2132 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2133 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
2135 else if (einfo
->info
->strip
== strip_all
2136 || (einfo
->info
->strip
== strip_some
2137 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2138 h
->root
.root
.root
.string
,
2139 false, false) == NULL
))
2147 if (h
->esym
.ifd
== -2)
2150 h
->esym
.cobol_main
= 0;
2151 h
->esym
.weakext
= 0;
2152 h
->esym
.reserved
= 0;
2153 h
->esym
.ifd
= ifdNil
;
2154 h
->esym
.asym
.value
= 0;
2155 h
->esym
.asym
.st
= stGlobal
;
2157 if (h
->root
.root
.type
!= bfd_link_hash_defined
2158 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2159 h
->esym
.asym
.sc
= scAbs
;
2164 sec
= h
->root
.root
.u
.def
.section
;
2165 output_section
= sec
->output_section
;
2167 /* When making a shared library and symbol h is the one from
2168 the another shared library, OUTPUT_SECTION may be null. */
2169 if (output_section
== NULL
)
2170 h
->esym
.asym
.sc
= scUndefined
;
2173 name
= bfd_section_name (output_section
->owner
, output_section
);
2175 if (strcmp (name
, ".text") == 0)
2176 h
->esym
.asym
.sc
= scText
;
2177 else if (strcmp (name
, ".data") == 0)
2178 h
->esym
.asym
.sc
= scData
;
2179 else if (strcmp (name
, ".sdata") == 0)
2180 h
->esym
.asym
.sc
= scSData
;
2181 else if (strcmp (name
, ".rodata") == 0
2182 || strcmp (name
, ".rdata") == 0)
2183 h
->esym
.asym
.sc
= scRData
;
2184 else if (strcmp (name
, ".bss") == 0)
2185 h
->esym
.asym
.sc
= scBss
;
2186 else if (strcmp (name
, ".sbss") == 0)
2187 h
->esym
.asym
.sc
= scSBss
;
2188 else if (strcmp (name
, ".init") == 0)
2189 h
->esym
.asym
.sc
= scInit
;
2190 else if (strcmp (name
, ".fini") == 0)
2191 h
->esym
.asym
.sc
= scFini
;
2193 h
->esym
.asym
.sc
= scAbs
;
2197 h
->esym
.asym
.reserved
= 0;
2198 h
->esym
.asym
.index
= indexNil
;
2201 if (h
->root
.root
.type
== bfd_link_hash_common
)
2202 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2203 else if (h
->root
.root
.type
== bfd_link_hash_defined
2204 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2206 if (h
->esym
.asym
.sc
== scCommon
)
2207 h
->esym
.asym
.sc
= scBss
;
2208 else if (h
->esym
.asym
.sc
== scSCommon
)
2209 h
->esym
.asym
.sc
= scSBss
;
2211 sec
= h
->root
.root
.u
.def
.section
;
2212 output_section
= sec
->output_section
;
2213 if (output_section
!= NULL
)
2214 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2215 + sec
->output_offset
2216 + output_section
->vma
);
2218 h
->esym
.asym
.value
= 0;
2220 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2222 /* Set type and value for a symbol with a function stub. */
2223 h
->esym
.asym
.st
= stProc
;
2224 sec
= bfd_get_section_by_name (einfo
->abfd
, ".plt");
2226 h
->esym
.asym
.value
= 0;
2229 output_section
= sec
->output_section
;
2230 if (output_section
!= NULL
)
2231 h
->esym
.asym
.value
= (h
->root
.plt_offset
2232 + sec
->output_offset
2233 + output_section
->vma
);
2235 h
->esym
.asym
.value
= 0;
2242 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2243 h
->root
.root
.root
.string
,
2246 einfo
->failed
= true;
2253 /* FIXME: Create a runtime procedure table from the .mdebug section.
2256 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
2259 struct bfd_link_info *info;
2261 struct ecoff_debug_info *debug;
2264 /* Handle dynamic relocations when doing an Alpha ELF link. */
2267 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
2269 struct bfd_link_info
*info
;
2271 const Elf_Internal_Rela
*relocs
;
2275 const char *rel_sec_name
;
2276 Elf_Internal_Shdr
*symtab_hdr
;
2277 struct alpha_elf_link_hash_entry
**sym_hashes
;
2278 struct alpha_elf_got_entry
**local_got_entries
;
2279 const Elf_Internal_Rela
*rel
, *relend
;
2282 if (info
->relocateable
)
2285 dynobj
= elf_hash_table(info
)->dynobj
;
2287 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
2290 rel_sec_name
= NULL
;
2291 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
2292 sym_hashes
= alpha_elf_sym_hashes(abfd
);
2293 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
2296 relend
= relocs
+ sec
->reloc_count
;
2297 for (rel
= relocs
; rel
< relend
; ++rel
)
2299 unsigned long r_symndx
, r_type
;
2300 struct alpha_elf_link_hash_entry
*h
;
2302 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2303 if (r_symndx
< symtab_hdr
->sh_info
)
2307 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2309 while (h
->root
.root
.type
== bfd_link_hash_indirect
2310 || h
->root
.root
.type
== bfd_link_hash_warning
)
2311 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2313 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
2315 r_type
= ELF64_R_TYPE (rel
->r_info
);
2319 case R_ALPHA_LITERAL
:
2321 struct alpha_elf_got_entry
*gotent
;
2326 /* Search for and possibly create a got entry. */
2327 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2328 if (gotent
->gotobj
== abfd
&&
2329 gotent
->addend
== rel
->r_addend
)
2334 gotent
= ((struct alpha_elf_got_entry
*)
2336 sizeof (struct alpha_elf_got_entry
)));
2340 gotent
->gotobj
= abfd
;
2341 gotent
->addend
= rel
->r_addend
;
2342 gotent
->got_offset
= -1;
2344 gotent
->use_count
= 1;
2346 gotent
->next
= h
->got_entries
;
2347 h
->got_entries
= gotent
;
2349 alpha_elf_tdata (abfd
)->total_got_entries
++;
2352 gotent
->use_count
+= 1;
2356 /* This is a local .got entry -- record for merge. */
2357 if (!local_got_entries
)
2360 size
= (symtab_hdr
->sh_info
2361 * sizeof (struct alpha_elf_got_entry
*));
2363 local_got_entries
= ((struct alpha_elf_got_entry
**)
2364 bfd_alloc (abfd
, size
));
2365 if (!local_got_entries
)
2368 memset (local_got_entries
, 0, size
);
2369 alpha_elf_tdata (abfd
)->local_got_entries
=
2373 for (gotent
= local_got_entries
[ELF64_R_SYM(rel
->r_info
)];
2374 gotent
!= NULL
&& gotent
->addend
!= rel
->r_addend
;
2375 gotent
= gotent
->next
)
2379 gotent
= ((struct alpha_elf_got_entry
*)
2381 sizeof (struct alpha_elf_got_entry
)));
2385 gotent
->gotobj
= abfd
;
2386 gotent
->addend
= rel
->r_addend
;
2387 gotent
->got_offset
= -1;
2389 gotent
->use_count
= 1;
2391 gotent
->next
= local_got_entries
[ELF64_R_SYM(rel
->r_info
)];
2392 local_got_entries
[ELF64_R_SYM(rel
->r_info
)] = gotent
;
2394 alpha_elf_tdata(abfd
)->total_got_entries
++;
2395 alpha_elf_tdata(abfd
)->n_local_got_entries
++;
2398 gotent
->use_count
+= 1;
2401 /* Remember how this literal is used from its LITUSEs.
2402 This will be important when it comes to decide if we can
2403 create a .plt entry for a function symbol. */
2405 && ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
)
2410 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 3)
2411 flags
|= 1 << rel
->r_addend
;
2413 while (rel
+1 < relend
&&
2414 ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
);
2418 /* No LITUSEs -- presumably the address is not being
2419 loaded for nothing. */
2420 flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
2423 gotent
->flags
|= flags
;
2426 /* Make a guess as to whether a .plt entry will be needed. */
2427 if ((h
->flags
|= flags
) == ALPHA_ELF_LINK_HASH_LU_FUNC
)
2428 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2430 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2435 case R_ALPHA_GPDISP
:
2436 case R_ALPHA_GPREL32
:
2437 case R_ALPHA_GPRELHIGH
:
2438 case R_ALPHA_GPRELLOW
:
2439 /* We don't actually use the .got here, but the sections must
2440 be created before the linker maps input sections to output
2444 if (!elf64_alpha_create_got_section (abfd
, info
))
2447 /* Make sure the object's gotobj is set to itself so
2448 that we default to every object with its own .got.
2449 We'll merge .gots later once we've collected each
2451 alpha_elf_tdata(abfd
)->gotobj
= abfd
;
2457 case R_ALPHA_SREL16
:
2458 case R_ALPHA_SREL32
:
2459 case R_ALPHA_SREL64
:
2464 case R_ALPHA_REFLONG
:
2465 case R_ALPHA_REFQUAD
:
2466 if (rel_sec_name
== NULL
)
2468 rel_sec_name
= (bfd_elf_string_from_elf_section
2469 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
2470 elf_section_data(sec
)->rel_hdr
.sh_name
));
2471 if (rel_sec_name
== NULL
)
2474 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
2475 && strcmp (bfd_get_section_name (abfd
, sec
),
2476 rel_sec_name
+5) == 0);
2479 /* We need to create the section here now whether we eventually
2480 use it or not so that it gets mapped to an output section by
2481 the linker. If not used, we'll kill it in
2482 size_dynamic_sections. */
2485 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
2488 sreloc
= bfd_make_section (dynobj
, rel_sec_name
);
2490 || !bfd_set_section_flags (dynobj
, sreloc
,
2494 | SEC_LINKER_CREATED
2496 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
2503 /* Since we havn't seen all of the input symbols yet, we
2504 don't know whether we'll actually need a dynamic relocation
2505 entry for this reloc. So make a record of it. Once we
2506 find out if this thing needs dynamic relocation we'll
2507 expand the relocation sections by the appropriate amount. */
2509 struct alpha_elf_reloc_entry
*rent
;
2511 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
2512 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
2517 rent
= ((struct alpha_elf_reloc_entry
*)
2519 sizeof (struct alpha_elf_reloc_entry
)));
2523 rent
->srel
= sreloc
;
2524 rent
->rtype
= r_type
;
2527 rent
->next
= h
->reloc_entries
;
2528 h
->reloc_entries
= rent
;
2533 else if (info
->shared
)
2535 /* If this is a shared library, we need a RELATIVE reloc. */
2536 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
2545 /* Adjust a symbol defined by a dynamic object and referenced by a
2546 regular object. The current definition is in some section of the
2547 dynamic object, but we're not including those sections. We have to
2548 change the definition to something the rest of the link can
2552 elf64_alpha_adjust_dynamic_symbol (info
, h
)
2553 struct bfd_link_info
*info
;
2554 struct elf_link_hash_entry
*h
;
2558 struct alpha_elf_link_hash_entry
*ah
;
2560 dynobj
= elf_hash_table(info
)->dynobj
;
2561 ah
= (struct alpha_elf_link_hash_entry
*)h
;
2563 /* Now that we've seen all of the input symbols, finalize our decision
2564 about whether this symbol should get a .plt entry. */
2566 if (h
->root
.type
!= bfd_link_hash_undefweak
2567 && alpha_elf_dynamic_symbol_p (h
, info
)
2568 && ((h
->type
== STT_FUNC
2569 && !(ah
->flags
& ALPHA_ELF_LINK_HASH_LU_ADDR
))
2570 || (h
->type
== STT_NOTYPE
2571 && ah
->flags
== ALPHA_ELF_LINK_HASH_LU_FUNC
))
2572 /* Don't prevent otherwise valid programs from linking by attempting
2573 to create a new .got entry somewhere. A Correct Solution would be
2574 to add a new .got section to a new object file and let it be merged
2575 somewhere later. But for now don't bother. */
2578 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2580 s
= bfd_get_section_by_name(dynobj
, ".plt");
2581 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
2584 /* The first bit of the .plt is reserved. */
2585 if (s
->_raw_size
== 0)
2586 s
->_raw_size
= PLT_HEADER_SIZE
;
2588 h
->plt_offset
= s
->_raw_size
;
2589 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2591 /* If this symbol is not defined in a regular file, and we are not
2592 generating a shared library, then set the symbol to the location
2593 in the .plt. This is required to make function pointers compare
2594 equal between the normal executable and the shared library. */
2597 h
->root
.u
.def
.section
= s
;
2598 h
->root
.u
.def
.value
= h
->plt_offset
;
2601 /* We also need a JMP_SLOT entry in the .rela.plt section. */
2602 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2603 BFD_ASSERT (s
!= NULL
);
2604 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
2609 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2611 /* If this is a weak symbol, and there is a real definition, the
2612 processor independent code will have arranged for us to see the
2613 real definition first, and we can just use the same value. */
2614 if (h
->weakdef
!= NULL
)
2616 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2617 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2618 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2619 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2623 /* This is a reference to a symbol defined by a dynamic object which
2624 is not a function. The Alpha, since it uses .got entries for all
2625 symbols even in regular objects, does not need the hackery of a
2626 .dynbss section and COPY dynamic relocations. */
2631 /* Symbol versioning can create new symbols, and make our old symbols
2632 indirect to the new ones. Consolidate the got and reloc information
2633 in these situations. */
2636 elf64_alpha_merge_ind_symbols (hi
, dummy
)
2637 struct alpha_elf_link_hash_entry
*hi
;
2640 struct alpha_elf_link_hash_entry
*hs
;
2642 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
2646 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
2647 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
2649 /* Merge the flags. Whee. */
2651 hs
->flags
|= hi
->flags
;
2653 /* Merge the .got entries. Cannibalize the old symbol's list in
2654 doing so, since we don't need it anymore. */
2656 if (hs
->got_entries
== NULL
)
2657 hs
->got_entries
= hi
->got_entries
;
2660 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
2662 gsh
= hs
->got_entries
;
2663 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
2666 for (gs
= gsh
; gs
; gs
= gs
->next
)
2667 if (gi
->gotobj
== gs
->gotobj
&& gi
->addend
== gs
->addend
)
2669 gi
->next
= hs
->got_entries
;
2670 hs
->got_entries
= gi
;
2674 hi
->got_entries
= NULL
;
2676 /* And similar for the reloc entries. */
2678 if (hs
->reloc_entries
== NULL
)
2679 hs
->reloc_entries
= hi
->reloc_entries
;
2682 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
2684 rsh
= hs
->reloc_entries
;
2685 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
2688 for (rs
= rsh
; rs
; rs
= rs
->next
)
2689 if (ri
->rtype
== rs
->rtype
)
2691 rs
->count
+= ri
->count
;
2694 ri
->next
= hs
->reloc_entries
;
2695 hs
->reloc_entries
= ri
;
2699 hi
->reloc_entries
= NULL
;
2704 /* Is it possible to merge two object file's .got tables? */
2707 elf64_alpha_can_merge_gots (a
, b
)
2710 int total
= alpha_elf_tdata (a
)->total_got_entries
;
2712 /* Trivial quick fallout test. */
2713 if (total
+ alpha_elf_tdata (b
)->total_got_entries
<= MAX_GOT_ENTRIES
)
2716 /* By their nature, local .got entries cannot be merged. */
2717 if ((total
+= alpha_elf_tdata (b
)->n_local_got_entries
) > MAX_GOT_ENTRIES
)
2720 /* Failing the common trivial comparison, we must effectively
2721 perform the merge. Not actually performing the merge means that
2722 we don't have to store undo information in case we fail. */
2724 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes(b
);
2725 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata(b
)->symtab_hdr
;
2728 n
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
- symtab_hdr
->sh_info
;
2729 for (i
= 0; i
< n
; ++i
)
2731 struct alpha_elf_got_entry
*ae
, *be
;
2732 struct alpha_elf_link_hash_entry
*h
;
2735 while (h
->root
.root
.type
== bfd_link_hash_indirect
2736 || h
->root
.root
.type
== bfd_link_hash_warning
)
2737 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2739 for (be
= h
->got_entries
; be
; be
= be
->next
)
2741 if (be
->use_count
== 0)
2743 if (be
->gotobj
!= b
)
2746 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
2747 if (ae
->gotobj
== a
&& ae
->addend
== be
->addend
)
2750 if (++total
> MAX_GOT_ENTRIES
)
2760 /* Actually merge two .got tables. */
2763 elf64_alpha_merge_gots (a
, b
)
2766 int total
= alpha_elf_tdata(a
)->total_got_entries
;
2768 /* Remember local expansion. */
2770 int e
= alpha_elf_tdata(b
)->n_local_got_entries
;
2772 alpha_elf_tdata(a
)->n_local_got_entries
+= e
;
2775 /* Let the local .got entries know they are part of a new subsegment. */
2777 struct alpha_elf_got_entry
**local_got_entries
;
2778 local_got_entries
= alpha_elf_tdata(b
)->local_got_entries
;
2779 if (local_got_entries
)
2783 n
= elf_tdata(b
)->symtab_hdr
.sh_info
;
2784 for (i
= 0; i
< n
; ++i
)
2786 struct alpha_elf_got_entry
*gotent
;
2787 for (gotent
= local_got_entries
[i
]; gotent
; gotent
= gotent
->next
)
2793 /* Merge the global .got entries. */
2795 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes(b
);
2796 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata(b
)->symtab_hdr
;
2799 n
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
- symtab_hdr
->sh_info
;
2800 for (i
= 0; i
< n
; ++i
)
2802 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
2803 struct alpha_elf_link_hash_entry
*h
;
2806 while (h
->root
.root
.type
== bfd_link_hash_indirect
2807 || h
->root
.root
.type
== bfd_link_hash_warning
)
2808 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2810 start
= &h
->got_entries
;
2811 for (pbe
= start
, be
= *start
; be
; pbe
= &be
->next
, be
= be
->next
)
2813 if (be
->use_count
== 0)
2818 if (be
->gotobj
!= b
)
2821 for (ae
= *start
; ae
; ae
= ae
->next
)
2822 if (ae
->gotobj
== a
&& ae
->addend
== be
->addend
)
2824 ae
->flags
|= be
->flags
;
2836 alpha_elf_tdata(a
)->total_got_entries
= total
;
2837 alpha_elf_tdata(b
)->gotobj
= a
;
2840 /* Calculate the offsets for the got entries. */
2843 elf64_alpha_calc_got_offsets_for_symbol (h
, arg
)
2844 struct alpha_elf_link_hash_entry
*h
;
2847 struct alpha_elf_got_entry
*gotent
;
2849 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2850 if (gotent
->use_count
> 0)
2853 = &alpha_elf_tdata (gotent
->gotobj
)->got
->_raw_size
;
2855 gotent
->got_offset
= *plge
;
2863 elf64_alpha_calc_got_offsets (info
)
2864 struct bfd_link_info
*info
;
2866 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
2868 /* First, zero out the .got sizes, as we may be recalculating the
2869 .got after optimizing it. */
2870 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2871 alpha_elf_tdata(i
)->got
->_raw_size
= 0;
2873 /* Next, fill in the offsets for all the global entries. */
2874 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2875 elf64_alpha_calc_got_offsets_for_symbol
,
2878 /* Finally, fill in the offsets for the local entries. */
2879 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2881 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->_raw_size
;
2884 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2886 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2889 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2890 if (!local_got_entries
)
2893 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2894 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
2896 gotent
->got_offset
= got_offset
;
2901 alpha_elf_tdata(i
)->got
->_raw_size
= got_offset
;
2905 /* Remove a section from the output BFD. */
2908 elf64_alpha_strip_section_from_output (s
)
2913 for (spp
= &s
->output_section
->owner
->sections
;
2914 *spp
!= s
->output_section
;
2915 spp
= &(*spp
)->next
)
2917 *spp
= s
->output_section
->next
;
2918 --s
->output_section
->owner
->section_count
;
2921 /* Constructs the gots. */
2924 elf64_alpha_size_got_sections (output_bfd
, info
)
2926 struct bfd_link_info
*info
;
2928 bfd
*i
, *got_list
, *cur_got_obj
, **cur_got_tail
;
2934 cur_got_tail
= NULL
;
2935 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2937 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
2939 /* Don't play if there is no .got for this input file. */
2940 if (this_got
== NULL
)
2943 if (alpha_elf_tdata (this_got
)->total_got_entries
> MAX_GOT_ENTRIES
)
2945 /* Yikes! A single object file has too many entries. */
2946 (*_bfd_error_handler
)
2947 ("%s: .got subsegment exceeds 64K (size %d)",
2948 bfd_get_filename(i
),
2949 alpha_elf_tdata(this_got
)->total_got_entries
* 8);
2955 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
2957 elf64_alpha_merge_gots (cur_got_obj
, i
);
2964 (*info
->callbacks
->warning
)
2965 (info
, "using multiple gp values", (char *) NULL
,
2966 output_bfd
, (asection
*) NULL
, (bfd_vma
) 0);
2968 *cur_got_tail
= NULL
;
2969 alpha_elf_tdata(cur_got_obj
)->got_link_next
= got_list
;
2970 got_list
= cur_got_obj
;
2979 cur_got_tail
= &alpha_elf_tdata(i
)->in_got_link_next
;
2983 alpha_elf_tdata (cur_got_obj
)->got_link_next
= got_list
;
2984 alpha_elf_hash_table (info
)->got_list
= cur_got_obj
;
2986 /* Once the gots have been merged, fill in the got offsets for everything
2988 elf64_alpha_calc_got_offsets (info
);
2994 elf64_alpha_always_size_sections (output_bfd
, info
)
2996 struct bfd_link_info
*info
;
3000 if (info
->relocateable
)
3003 /* First, take care of the indirect symbols created by versioning. */
3004 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3005 elf64_alpha_merge_ind_symbols
,
3008 if (!elf64_alpha_size_got_sections (output_bfd
, info
))
3011 /* Allocate space for all of the .got subsections. */
3012 i
= alpha_elf_hash_table (info
)->got_list
;
3013 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
3015 asection
*s
= alpha_elf_tdata(i
)->got
;
3016 if (s
->_raw_size
> 0)
3018 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->_raw_size
);
3019 if (s
->contents
== NULL
)
3027 /* Work out the sizes of the dynamic relocation entries. */
3030 elf64_alpha_calc_dynrel_sizes (h
, info
)
3031 struct alpha_elf_link_hash_entry
*h
;
3032 struct bfd_link_info
*info
;
3034 /* If the symbol was defined as a common symbol in a regular object
3035 file, and there was no definition in any dynamic object, then the
3036 linker will have allocated space for the symbol in a common
3037 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
3038 set. This is done for dynamic symbols in
3039 elf_adjust_dynamic_symbol but this is not done for non-dynamic
3040 symbols, somehow. */
3041 if (((h
->root
.elf_link_hash_flags
3042 & (ELF_LINK_HASH_DEF_REGULAR
3043 | ELF_LINK_HASH_REF_REGULAR
3044 | ELF_LINK_HASH_DEF_DYNAMIC
))
3045 == ELF_LINK_HASH_REF_REGULAR
)
3046 && (h
->root
.root
.type
== bfd_link_hash_defined
3047 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3048 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
3050 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3053 /* If the symbol is dynamic, we'll need all the relocations in their
3054 natural form. If it has been forced local, we'll need the same
3055 number of RELATIVE relocations. */
3056 if (alpha_elf_dynamic_symbol_p (&h
->root
, info
)
3057 || (info
->shared
&& h
->root
.dynindx
== -1))
3059 struct alpha_elf_reloc_entry
*relent
;
3061 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
3063 relent
->srel
->_raw_size
+=
3064 sizeof (Elf64_External_Rela
) * relent
->count
;
3067 /* Only add a .rela.got entry if we're not using a .plt entry. */
3068 if (h
->root
.plt_offset
== MINUS_ONE
)
3070 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
3071 struct alpha_elf_got_entry
*gotent
;
3072 bfd_size_type count
= 0;
3075 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
3079 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3080 BFD_ASSERT (srel
!= NULL
);
3081 srel
->_raw_size
+= sizeof (Elf64_External_Rela
) * count
;
3085 /* Otherwise, shared objects require RELATIVE relocs for all REFQUAD
3086 and REFLONG relocations. */
3087 else if (info
->shared
)
3089 struct alpha_elf_reloc_entry
*relent
;
3091 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
3092 if (relent
->rtype
== R_ALPHA_REFLONG
3093 || relent
->rtype
== R_ALPHA_REFQUAD
)
3095 relent
->srel
->_raw_size
+=
3096 sizeof(Elf64_External_Rela
) * relent
->count
;
3103 /* Set the sizes of the dynamic sections. */
3106 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
3108 struct bfd_link_info
*info
;
3115 dynobj
= elf_hash_table(info
)->dynobj
;
3116 BFD_ASSERT(dynobj
!= NULL
);
3118 if (elf_hash_table (info
)->dynamic_sections_created
)
3120 /* Set the contents of the .interp section to the interpreter. */
3123 s
= bfd_get_section_by_name (dynobj
, ".interp");
3124 BFD_ASSERT (s
!= NULL
);
3125 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3126 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3129 /* Now that we've seen all of the input files, we can decide which
3130 symbols need dynamic relocation entries and which don't. We've
3131 collected information in check_relocs that we can now apply to
3132 size the dynamic relocation sections. */
3133 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
3134 elf64_alpha_calc_dynrel_sizes
,
3137 /* When building shared libraries, each local .got entry needs a
3143 bfd_size_type count
;
3145 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3146 BFD_ASSERT (srel
!= NULL
);
3148 for (i
= alpha_elf_hash_table(info
)->got_list
, count
= 0;
3150 i
= alpha_elf_tdata(i
)->got_link_next
)
3151 count
+= alpha_elf_tdata(i
)->n_local_got_entries
;
3153 srel
->_raw_size
+= count
* sizeof(Elf64_External_Rela
);
3156 /* else we're not dynamic and by definition we don't need such things. */
3158 /* The check_relocs and adjust_dynamic_symbol entry points have
3159 determined the sizes of the various dynamic sections. Allocate
3163 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3168 if (!(s
->flags
& SEC_LINKER_CREATED
))
3171 /* It's OK to base decisions on the section name, because none
3172 of the dynobj section names depend upon the input files. */
3173 name
= bfd_get_section_name (dynobj
, s
);
3175 /* If we don't need this section, strip it from the output file.
3176 This is to handle .rela.bss and .rela.plt. We must create it
3177 in create_dynamic_sections, because it must be created before
3178 the linker maps input sections to output sections. The
3179 linker does that before adjust_dynamic_symbol is called, and
3180 it is that function which decides whether anything needs to
3181 go into these sections. */
3185 if (strncmp (name
, ".rela", 5) == 0)
3187 strip
= (s
->_raw_size
== 0);
3191 const char *outname
;
3194 /* If this relocation section applies to a read only
3195 section, then we probably need a DT_TEXTREL entry. */
3196 outname
= bfd_get_section_name (output_bfd
,
3198 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
3200 && (target
->flags
& SEC_READONLY
) != 0
3201 && (target
->flags
& SEC_ALLOC
) != 0)
3204 if (strcmp(name
, ".rela.plt") == 0)
3207 /* We use the reloc_count field as a counter if we need
3208 to copy relocs into the output file. */
3212 else if (strcmp (name
, ".plt") != 0)
3214 /* It's not one of our dynamic sections, so don't allocate space. */
3219 elf64_alpha_strip_section_from_output (s
);
3222 /* Allocate memory for the section contents. */
3223 s
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, s
->_raw_size
);
3224 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3229 /* If we are generating a shared library, we generate a section
3230 symbol for each output section. These are local symbols, which
3231 means that they must come first in the dynamic symbol table.
3232 That means we must increment the dynamic symbol index of every
3233 other dynamic symbol. */
3240 c
[1] = bfd_count_sections (output_bfd
);
3242 elf_hash_table (info
)->dynsymcount
+= c
[1];
3243 elf_link_hash_traverse (elf_hash_table(info
),
3244 elf64_alpha_adjust_dynindx
,
3247 for (i
= 1, p
= output_bfd
->sections
;
3251 elf_section_data (p
)->dynindx
= i
;
3252 /* These symbols will have no names, so we don't need to
3253 fiddle with dynstr_index. */
3257 if (elf_hash_table (info
)->dynamic_sections_created
)
3259 /* Add some entries to the .dynamic section. We fill in the
3260 values later, in elf64_alpha_finish_dynamic_sections, but we
3261 must add the entries now so that we get the correct size for
3262 the .dynamic section. The DT_DEBUG entry is filled in by the
3263 dynamic linker and used by the debugger. */
3266 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
3270 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0))
3275 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
3276 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
3277 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
3281 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
3282 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
3283 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
3284 sizeof(Elf64_External_Rela
)))
3289 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
3297 /* Increment the index of a dynamic symbol by a given amount. Called
3298 via elf_link_hash_traverse. */
3301 elf64_alpha_adjust_dynindx (h
, cparg
)
3302 struct elf_link_hash_entry
*h
;
3305 long *cp
= (long *)cparg
;
3307 if (h
->dynindx
>= cp
[0])
3308 h
->dynindx
+= cp
[1];
3313 /* Relocate an Alpha ELF section. */
3316 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3317 contents
, relocs
, local_syms
, local_sections
)
3319 struct bfd_link_info
*info
;
3321 asection
*input_section
;
3323 Elf_Internal_Rela
*relocs
;
3324 Elf_Internal_Sym
*local_syms
;
3325 asection
**local_sections
;
3327 Elf_Internal_Shdr
*symtab_hdr
;
3328 Elf_Internal_Rela
*rel
;
3329 Elf_Internal_Rela
*relend
;
3330 asection
*sec
, *sgot
, *srel
, *srelgot
;
3331 bfd
*dynobj
, *gotobj
;
3334 srelgot
= srel
= NULL
;
3335 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3336 dynobj
= elf_hash_table (info
)->dynobj
;
3339 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3342 /* Find the gp value for this input bfd. */
3345 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
3348 sgot
= alpha_elf_tdata (gotobj
)->got
;
3349 gp
= _bfd_get_gp_value (gotobj
);
3352 gp
= (sgot
->output_section
->vma
3353 + sgot
->output_offset
3355 _bfd_set_gp_value (gotobj
, gp
);
3360 relend
= relocs
+ input_section
->reloc_count
;
3361 for (; rel
< relend
; rel
++)
3364 reloc_howto_type
*howto
;
3365 unsigned long r_symndx
;
3366 struct alpha_elf_link_hash_entry
*h
;
3367 Elf_Internal_Sym
*sym
;
3370 bfd_reloc_status_type r
;
3372 r_type
= ELF64_R_TYPE(rel
->r_info
);
3373 if (r_type
< 0 || r_type
>= (int) R_ALPHA_max
)
3375 bfd_set_error (bfd_error_bad_value
);
3378 howto
= elf64_alpha_howto_table
+ r_type
;
3380 r_symndx
= ELF64_R_SYM(rel
->r_info
);
3382 if (info
->relocateable
)
3384 /* This is a relocateable link. We don't have to change
3385 anything, unless the reloc is against a section symbol,
3386 in which case we have to adjust according to where the
3387 section symbol winds up in the output section. */
3388 if (r_symndx
< symtab_hdr
->sh_info
)
3390 sym
= local_syms
+ r_symndx
;
3391 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
3393 sec
= local_sections
[r_symndx
];
3394 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
3401 /* This is a final link. */
3407 if (r_symndx
< symtab_hdr
->sh_info
)
3409 sym
= local_syms
+ r_symndx
;
3410 sec
= local_sections
[r_symndx
];
3411 relocation
= (sec
->output_section
->vma
3412 + sec
->output_offset
3417 h
= alpha_elf_sym_hashes (input_bfd
)[r_symndx
- symtab_hdr
->sh_info
];
3419 while (h
->root
.root
.type
== bfd_link_hash_indirect
3420 || h
->root
.root
.type
== bfd_link_hash_warning
)
3421 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3423 if (h
->root
.root
.type
== bfd_link_hash_defined
3424 || h
->root
.root
.type
== bfd_link_hash_defweak
)
3426 sec
= h
->root
.root
.u
.def
.section
;
3429 if ((r_type
== R_ALPHA_LITERAL
3430 && elf_hash_table(info
)->dynamic_sections_created
3433 || !(h
->root
.elf_link_hash_flags
3434 & ELF_LINK_HASH_DEF_REGULAR
)))
3437 || !(h
->root
.elf_link_hash_flags
3438 & ELF_LINK_HASH_DEF_REGULAR
))
3439 && (input_section
->flags
& SEC_ALLOC
)
3440 && (r_type
== R_ALPHA_REFLONG
3441 || r_type
== R_ALPHA_REFQUAD
3442 || r_type
== R_ALPHA_LITERAL
)))
3444 /* In these cases, we don't need the relocation value.
3445 We check specially because in some obscure cases
3446 sec->output_section will be NULL. */
3450 /* FIXME: Are not these obscure cases simply bugs? Let's
3451 get something working and come back to this. */
3452 if (sec
->output_section
== NULL
)
3454 #endif /* rth_notdef */
3457 relocation
= (h
->root
.root
.u
.def
.value
3458 + sec
->output_section
->vma
3459 + sec
->output_offset
);
3462 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3464 else if (info
->shared
&& !info
->symbolic
)
3468 if (!((*info
->callbacks
->undefined_symbol
)
3469 (info
, h
->root
.root
.root
.string
, input_bfd
,
3470 input_section
, rel
->r_offset
)))
3475 addend
= rel
->r_addend
;
3479 case R_ALPHA_GPDISP
:
3481 bfd_byte
*p_ldah
, *p_lda
;
3483 BFD_ASSERT(gp
!= 0);
3485 relocation
= (input_section
->output_section
->vma
3486 + input_section
->output_offset
3489 p_ldah
= contents
+ rel
->r_offset
- input_section
->vma
;
3490 p_lda
= p_ldah
+ rel
->r_addend
;
3492 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- relocation
,
3497 case R_ALPHA_OP_PUSH
:
3498 case R_ALPHA_OP_STORE
:
3499 case R_ALPHA_OP_PSUB
:
3500 case R_ALPHA_OP_PRSHIFT
:
3501 /* We hate these silly beasts. */
3504 case R_ALPHA_LITERAL
:
3506 struct alpha_elf_got_entry
*gotent
;
3508 BFD_ASSERT(sgot
!= NULL
);
3509 BFD_ASSERT(gp
!= 0);
3513 gotent
= h
->got_entries
;
3514 BFD_ASSERT(gotent
!= NULL
);
3516 while (gotent
->gotobj
!= gotobj
|| gotent
->addend
!= addend
)
3517 gotent
= gotent
->next
;
3519 /* Initialize the .got entry's value. */
3520 if (!(gotent
->flags
& ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
))
3522 bfd_put_64 (output_bfd
, relocation
+addend
,
3523 sgot
->contents
+ gotent
->got_offset
);
3525 /* If the symbol has been forced local, output a
3526 RELATIVE reloc, otherwise it will be handled in
3527 finish_dynamic_symbol. */
3528 if (info
->shared
&& h
->root
.dynindx
== -1)
3530 Elf_Internal_Rela outrel
;
3532 BFD_ASSERT(srelgot
!= NULL
);
3534 outrel
.r_offset
= (sgot
->output_section
->vma
3535 + sgot
->output_offset
3536 + gotent
->got_offset
);
3537 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
3538 outrel
.r_addend
= 0;
3540 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3541 ((Elf64_External_Rela
*)
3543 + srelgot
->reloc_count
++);
3546 gotent
->flags
|= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
;
3551 gotent
= (alpha_elf_tdata(input_bfd
)->
3552 local_got_entries
[r_symndx
]);
3553 while (gotent
->addend
!= addend
)
3554 gotent
= gotent
->next
;
3556 if (!(gotent
->flags
& ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
))
3558 bfd_put_64 (output_bfd
, relocation
+addend
,
3559 sgot
->contents
+ gotent
->got_offset
);
3561 /* Local got entries need RELATIVE relocs in shared
3565 Elf_Internal_Rela outrel
;
3567 BFD_ASSERT(srelgot
!= NULL
);
3569 outrel
.r_offset
= (sgot
->output_section
->vma
3570 + sgot
->output_offset
3571 + gotent
->got_offset
);
3572 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
3573 outrel
.r_addend
= 0;
3575 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3576 ((Elf64_External_Rela
*)
3578 + srelgot
->reloc_count
++);
3581 gotent
->flags
|= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
;
3585 /* Figure the gprel relocation. */
3587 relocation
= (sgot
->output_section
->vma
3588 + sgot
->output_offset
3589 + gotent
->got_offset
);
3592 /* overflow handled by _bfd_final_link_relocate */
3595 case R_ALPHA_GPREL32
:
3596 case R_ALPHA_GPRELLOW
:
3597 BFD_ASSERT(gp
!= 0);
3601 case R_ALPHA_GPRELHIGH
:
3602 BFD_ASSERT(gp
!= 0);
3604 relocation
+= addend
;
3606 relocation
= (((bfd_signed_vma
) relocation
>> 16)
3607 + ((relocation
>> 15) & 1));
3610 case R_ALPHA_BRADDR
:
3612 /* The regular PC-relative stuff measures from the start of
3613 the instruction rather than the end. */
3617 case R_ALPHA_REFLONG
:
3618 case R_ALPHA_REFQUAD
:
3620 Elf_Internal_Rela outrel
;
3623 /* Careful here to remember RELATIVE relocations for global
3624 variables for symbolic shared objects. */
3626 if (h
&& alpha_elf_dynamic_symbol_p (&h
->root
, info
))
3628 BFD_ASSERT(h
->root
.dynindx
!= -1);
3629 outrel
.r_info
= ELF64_R_INFO(h
->root
.dynindx
, r_type
);
3630 outrel
.r_addend
= addend
;
3631 addend
= 0, relocation
= 0;
3633 else if (info
->shared
)
3635 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
3636 outrel
.r_addend
= 0;
3645 name
= (bfd_elf_string_from_elf_section
3646 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
3647 elf_section_data(input_section
)->rel_hdr
.sh_name
));
3648 BFD_ASSERT(name
!= NULL
);
3650 srel
= bfd_get_section_by_name (dynobj
, name
);
3651 BFD_ASSERT(srel
!= NULL
);
3656 if (elf_section_data (input_section
)->stab_info
== NULL
)
3657 outrel
.r_offset
= rel
->r_offset
;
3662 off
= (_bfd_stab_section_offset
3663 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3665 &elf_section_data (input_section
)->stab_info
,
3667 if (off
== (bfd_vma
) -1)
3669 outrel
.r_offset
= off
;
3673 outrel
.r_offset
+= (input_section
->output_section
->vma
3674 + input_section
->output_offset
);
3676 memset (&outrel
, 0, sizeof outrel
);
3678 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3679 ((Elf64_External_Rela
*)
3681 + srel
->reloc_count
++);
3687 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3688 contents
, rel
->r_offset
, relocation
,
3698 case bfd_reloc_overflow
:
3703 name
= h
->root
.root
.root
.string
;
3706 name
= (bfd_elf_string_from_elf_section
3707 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
3711 name
= bfd_section_name (input_bfd
, sec
);
3713 if (! ((*info
->callbacks
->reloc_overflow
)
3714 (info
, name
, howto
->name
, (bfd_vma
) 0,
3715 input_bfd
, input_section
, rel
->r_offset
)))
3721 case bfd_reloc_outofrange
:
3729 /* Finish up dynamic symbol handling. We set the contents of various
3730 dynamic sections here. */
3733 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3735 struct bfd_link_info
*info
;
3736 struct elf_link_hash_entry
*h
;
3737 Elf_Internal_Sym
*sym
;
3739 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
3741 if (h
->plt_offset
!= MINUS_ONE
)
3743 /* Fill in the .plt entry for this symbol. */
3744 asection
*splt
, *sgot
, *srel
;
3745 Elf_Internal_Rela outrel
;
3746 bfd_vma got_addr
, plt_addr
;
3748 struct alpha_elf_got_entry
*gotent
;
3750 BFD_ASSERT (h
->dynindx
!= -1);
3752 /* The first .got entry will be updated by the .plt with the
3753 address of the target function. */
3754 gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
3755 BFD_ASSERT (gotent
&& gotent
->addend
== 0);
3757 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3758 BFD_ASSERT (splt
!= NULL
);
3759 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3760 BFD_ASSERT (srel
!= NULL
);
3761 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
3762 BFD_ASSERT (sgot
!= NULL
);
3764 got_addr
= (sgot
->output_section
->vma
3765 + sgot
->output_offset
3766 + gotent
->got_offset
);
3767 plt_addr
= (splt
->output_section
->vma
3768 + splt
->output_offset
3771 plt_index
= (h
->plt_offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
3773 /* Fill in the entry in the procedure linkage table. */
3775 unsigned insn1
, insn2
, insn3
;
3777 insn1
= PLT_ENTRY_WORD1
| ((-(h
->plt_offset
+ 4) >> 2) & 0x1fffff);
3778 insn2
= PLT_ENTRY_WORD2
;
3779 insn3
= PLT_ENTRY_WORD3
;
3781 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt_offset
);
3782 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt_offset
+ 4);
3783 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt_offset
+ 8);
3786 /* Fill in the entry in the .rela.plt section. */
3787 outrel
.r_offset
= got_addr
;
3788 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
3789 outrel
.r_addend
= 0;
3791 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3792 ((Elf64_External_Rela
*)srel
->contents
3795 if (!(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3797 /* Mark the symbol as undefined, rather than as defined in the
3798 .plt section. Leave the value alone. */
3799 sym
->st_shndx
= SHN_UNDEF
;
3802 /* Fill in the entries in the .got. */
3803 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ gotent
->got_offset
);
3805 /* Subsequent .got entries will continue to bounce through the .plt. */
3806 while ((gotent
= gotent
->next
) != NULL
)
3808 sgot
= alpha_elf_tdata(gotent
->gotobj
)->got
;
3809 BFD_ASSERT(sgot
!= NULL
);
3810 BFD_ASSERT(gotent
->addend
== 0);
3812 bfd_put_64 (output_bfd
, plt_addr
,
3813 sgot
->contents
+ gotent
->got_offset
);
3816 else if (alpha_elf_dynamic_symbol_p (h
, info
))
3818 /* Fill in the dynamic relocations for this symbol's .got entries. */
3820 Elf_Internal_Rela outrel
;
3821 struct alpha_elf_got_entry
*gotent
;
3823 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
3824 BFD_ASSERT (srel
!= NULL
);
3826 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_ALPHA_GLOB_DAT
);
3827 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
3829 gotent
= gotent
->next
)
3831 asection
*sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
3832 outrel
.r_offset
= (sgot
->output_section
->vma
3833 + sgot
->output_offset
3834 + gotent
->got_offset
);
3835 outrel
.r_addend
= gotent
->addend
;
3837 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3838 ((Elf64_External_Rela
*)srel
->contents
3839 + srel
->reloc_count
++));
3843 /* Mark some specially defined symbols as absolute. */
3844 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3845 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3846 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3847 sym
->st_shndx
= SHN_ABS
;
3852 /* Finish up the dynamic sections. */
3855 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
3857 struct bfd_link_info
*info
;
3862 dynobj
= elf_hash_table (info
)->dynobj
;
3863 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3865 if (elf_hash_table (info
)->dynamic_sections_created
)
3868 Elf64_External_Dyn
*dyncon
, *dynconend
;
3870 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3871 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3873 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3874 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3875 for (; dyncon
< dynconend
; dyncon
++)
3877 Elf_Internal_Dyn dyn
;
3881 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3896 /* My interpretation of the TIS v1.1 ELF document indicates
3897 that RELASZ should not include JMPREL. This is not what
3898 the rest of the BFD does. It is, however, what the
3899 glibc ld.so wants. Do this fixup here until we found
3900 out who is right. */
3901 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
3905 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
3910 s
= bfd_get_section_by_name (output_bfd
, name
);
3911 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
3915 s
= bfd_get_section_by_name (output_bfd
, name
);
3917 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
3921 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3924 /* Initialize the PLT0 entry */
3925 if (splt
->_raw_size
> 0)
3927 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
3928 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
3929 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
3930 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
3932 /* The next two words will be filled in by ld.so */
3933 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 16);
3934 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 24);
3936 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
3945 Elf_Internal_Sym sym
;
3947 /* Set up the section symbols for the output sections. */
3949 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
3950 BFD_ASSERT (sdynsym
!= NULL
);
3954 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
3957 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
3961 sym
.st_value
= s
->vma
;
3963 indx
= elf_section_data (s
)->this_idx
;
3964 BFD_ASSERT (indx
> 0);
3965 sym
.st_shndx
= indx
;
3967 bfd_elf64_swap_symbol_out (output_bfd
, &sym
,
3968 (PTR
) (((Elf64_External_Sym
*)
3970 + elf_section_data (s
)->dynindx
));
3973 /* Set the sh_info field of the output .dynsym section to the
3974 index of the first global symbol. */
3975 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
3976 bfd_count_sections (output_bfd
) + 1;
3982 /* We need to use a special link routine to handle the .reginfo and
3983 the .mdebug sections. We need to merge all instances of these
3984 sections together, not write them all out sequentially. */
3987 elf64_alpha_final_link (abfd
, info
)
3989 struct bfd_link_info
*info
;
3992 struct bfd_link_order
*p
;
3993 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3994 struct ecoff_debug_info debug
;
3995 const struct ecoff_debug_swap
*swap
3996 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3997 HDRR
*symhdr
= &debug
.symbolic_header
;
3998 PTR mdebug_handle
= NULL
;
4000 /* Go through the sections and collect the .reginfo and .mdebug
4004 gptab_data_sec
= NULL
;
4005 gptab_bss_sec
= NULL
;
4006 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4008 #ifdef ERIC_neverdef
4009 if (strcmp (o
->name
, ".reginfo") == 0)
4011 memset (®info
, 0, sizeof reginfo
);
4013 /* We have found the .reginfo section in the output file.
4014 Look through all the link_orders comprising it and merge
4015 the information together. */
4016 for (p
= o
->link_order_head
;
4017 p
!= (struct bfd_link_order
*) NULL
;
4020 asection
*input_section
;
4022 Elf64_External_RegInfo ext
;
4025 if (p
->type
!= bfd_indirect_link_order
)
4027 if (p
->type
== bfd_fill_link_order
)
4032 input_section
= p
->u
.indirect
.section
;
4033 input_bfd
= input_section
->owner
;
4035 /* The linker emulation code has probably clobbered the
4036 size to be zero bytes. */
4037 if (input_section
->_raw_size
== 0)
4038 input_section
->_raw_size
= sizeof (Elf64_External_RegInfo
);
4040 if (! bfd_get_section_contents (input_bfd
, input_section
,
4046 bfd_alpha_elf64_swap_reginfo_in (input_bfd
, &ext
, &sub
);
4048 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
4049 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
4050 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
4051 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
4052 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
4054 /* ri_gp_value is set by the function
4055 alpha_elf_section_processing when the section is
4056 finally written out. */
4058 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4059 elf_link_input_bfd ignores this section. */
4060 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4063 /* Force the section size to the value we want. */
4064 o
->_raw_size
= sizeof (Elf64_External_RegInfo
);
4066 /* Skip this section later on (I don't think this currently
4067 matters, but someday it might). */
4068 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4074 if (strcmp (o
->name
, ".mdebug") == 0)
4076 struct extsym_info einfo
;
4078 /* We have found the .mdebug section in the output file.
4079 Look through all the link_orders comprising it and merge
4080 the information together. */
4081 symhdr
->magic
= swap
->sym_magic
;
4082 /* FIXME: What should the version stamp be? */
4084 symhdr
->ilineMax
= 0;
4088 symhdr
->isymMax
= 0;
4089 symhdr
->ioptMax
= 0;
4090 symhdr
->iauxMax
= 0;
4092 symhdr
->issExtMax
= 0;
4095 symhdr
->iextMax
= 0;
4097 /* We accumulate the debugging information itself in the
4098 debug_info structure. */
4100 debug
.external_dnr
= NULL
;
4101 debug
.external_pdr
= NULL
;
4102 debug
.external_sym
= NULL
;
4103 debug
.external_opt
= NULL
;
4104 debug
.external_aux
= NULL
;
4106 debug
.ssext
= debug
.ssext_end
= NULL
;
4107 debug
.external_fdr
= NULL
;
4108 debug
.external_rfd
= NULL
;
4109 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4111 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4112 if (mdebug_handle
== (PTR
) NULL
)
4121 static const char * const name
[] =
4123 ".text", ".init", ".fini", ".data",
4124 ".rodata", ".sdata", ".sbss", ".bss"
4126 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4127 scRData
, scSData
, scSBss
, scBss
};
4130 esym
.cobol_main
= 0;
4134 esym
.asym
.iss
= issNil
;
4135 esym
.asym
.st
= stLocal
;
4136 esym
.asym
.reserved
= 0;
4137 esym
.asym
.index
= indexNil
;
4138 for (i
= 0; i
< 8; i
++)
4140 esym
.asym
.sc
= sc
[i
];
4141 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4144 esym
.asym
.value
= s
->vma
;
4145 last
= s
->vma
+ s
->_raw_size
;
4148 esym
.asym
.value
= last
;
4150 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4156 for (p
= o
->link_order_head
;
4157 p
!= (struct bfd_link_order
*) NULL
;
4160 asection
*input_section
;
4162 const struct ecoff_debug_swap
*input_swap
;
4163 struct ecoff_debug_info input_debug
;
4167 if (p
->type
!= bfd_indirect_link_order
)
4169 if (p
->type
== bfd_fill_link_order
)
4174 input_section
= p
->u
.indirect
.section
;
4175 input_bfd
= input_section
->owner
;
4177 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4178 || (get_elf_backend_data (input_bfd
)
4179 ->elf_backend_ecoff_debug_swap
) == NULL
)
4181 /* I don't know what a non ALPHA ELF bfd would be
4182 doing with a .mdebug section, but I don't really
4183 want to deal with it. */
4187 input_swap
= (get_elf_backend_data (input_bfd
)
4188 ->elf_backend_ecoff_debug_swap
);
4190 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
4192 /* The ECOFF linking code expects that we have already
4193 read in the debugging information and set up an
4194 ecoff_debug_info structure, so we do that now. */
4195 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
4199 if (! (bfd_ecoff_debug_accumulate
4200 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
4201 &input_debug
, input_swap
, info
)))
4204 /* Loop through the external symbols. For each one with
4205 interesting information, try to find the symbol in
4206 the linker global hash table and save the information
4207 for the output external symbols. */
4208 eraw_src
= input_debug
.external_ext
;
4209 eraw_end
= (eraw_src
4210 + (input_debug
.symbolic_header
.iextMax
4211 * input_swap
->external_ext_size
));
4213 eraw_src
< eraw_end
;
4214 eraw_src
+= input_swap
->external_ext_size
)
4218 struct alpha_elf_link_hash_entry
*h
;
4220 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
4221 if (ext
.asym
.sc
== scNil
4222 || ext
.asym
.sc
== scUndefined
4223 || ext
.asym
.sc
== scSUndefined
)
4226 name
= input_debug
.ssext
+ ext
.asym
.iss
;
4227 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
4228 name
, false, false, true);
4229 if (h
== NULL
|| h
->esym
.ifd
!= -2)
4235 < input_debug
.symbolic_header
.ifdMax
);
4236 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
4242 /* Free up the information we just read. */
4243 free (input_debug
.line
);
4244 free (input_debug
.external_dnr
);
4245 free (input_debug
.external_pdr
);
4246 free (input_debug
.external_sym
);
4247 free (input_debug
.external_opt
);
4248 free (input_debug
.external_aux
);
4249 free (input_debug
.ss
);
4250 free (input_debug
.ssext
);
4251 free (input_debug
.external_fdr
);
4252 free (input_debug
.external_rfd
);
4253 free (input_debug
.external_ext
);
4255 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4256 elf_link_input_bfd ignores this section. */
4257 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4260 #ifdef ERIC_neverdef
4263 /* Create .rtproc section. */
4264 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
4265 if (rtproc_sec
== NULL
)
4267 flagword flags
= (SEC_HAS_CONTENTS
4269 | SEC_LINKER_CREATED
4272 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
4273 if (rtproc_sec
== NULL
4274 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
4275 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
4279 if (! alpha_elf_create_procedure_table (mdebug_handle
, abfd
,
4280 info
, rtproc_sec
, &debug
))
4286 /* Build the external symbol information. */
4289 einfo
.debug
= &debug
;
4291 einfo
.failed
= false;
4292 elf_link_hash_traverse (elf_hash_table (info
),
4293 elf64_alpha_output_extsym
,
4298 /* Set the size of the .mdebug section. */
4299 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
4301 /* Skip this section later on (I don't think this currently
4302 matters, but someday it might). */
4303 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4308 #ifdef ERIC_neverdef
4309 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
4311 const char *subname
;
4314 Elf64_External_gptab
*ext_tab
;
4317 /* The .gptab.sdata and .gptab.sbss sections hold
4318 information describing how the small data area would
4319 change depending upon the -G switch. These sections
4320 not used in executables files. */
4321 if (! info
->relocateable
)
4325 for (p
= o
->link_order_head
;
4326 p
!= (struct bfd_link_order
*) NULL
;
4329 asection
*input_section
;
4331 if (p
->type
!= bfd_indirect_link_order
)
4333 if (p
->type
== bfd_fill_link_order
)
4338 input_section
= p
->u
.indirect
.section
;
4340 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4341 elf_link_input_bfd ignores this section. */
4342 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4345 /* Skip this section later on (I don't think this
4346 currently matters, but someday it might). */
4347 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4349 /* Really remove the section. */
4350 for (secpp
= &abfd
->sections
;
4352 secpp
= &(*secpp
)->next
)
4354 *secpp
= (*secpp
)->next
;
4355 --abfd
->section_count
;
4360 /* There is one gptab for initialized data, and one for
4361 uninitialized data. */
4362 if (strcmp (o
->name
, ".gptab.sdata") == 0)
4364 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
4368 (*_bfd_error_handler
)
4369 ("%s: illegal section name `%s'",
4370 bfd_get_filename (abfd
), o
->name
);
4371 bfd_set_error (bfd_error_nonrepresentable_section
);
4375 /* The linker script always combines .gptab.data and
4376 .gptab.sdata into .gptab.sdata, and likewise for
4377 .gptab.bss and .gptab.sbss. It is possible that there is
4378 no .sdata or .sbss section in the output file, in which
4379 case we must change the name of the output section. */
4380 subname
= o
->name
+ sizeof ".gptab" - 1;
4381 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
4383 if (o
== gptab_data_sec
)
4384 o
->name
= ".gptab.data";
4386 o
->name
= ".gptab.bss";
4387 subname
= o
->name
+ sizeof ".gptab" - 1;
4388 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
4391 /* Set up the first entry. */
4393 tab
= (Elf64_gptab
*) bfd_malloc (c
* sizeof (Elf64_gptab
));
4396 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
4397 tab
[0].gt_header
.gt_unused
= 0;
4399 /* Combine the input sections. */
4400 for (p
= o
->link_order_head
;
4401 p
!= (struct bfd_link_order
*) NULL
;
4404 asection
*input_section
;
4408 bfd_size_type gpentry
;
4410 if (p
->type
!= bfd_indirect_link_order
)
4412 if (p
->type
== bfd_fill_link_order
)
4417 input_section
= p
->u
.indirect
.section
;
4418 input_bfd
= input_section
->owner
;
4420 /* Combine the gptab entries for this input section one
4421 by one. We know that the input gptab entries are
4422 sorted by ascending -G value. */
4423 size
= bfd_section_size (input_bfd
, input_section
);
4425 for (gpentry
= sizeof (Elf64_External_gptab
);
4427 gpentry
+= sizeof (Elf64_External_gptab
))
4429 Elf64_External_gptab ext_gptab
;
4430 Elf64_gptab int_gptab
;
4436 if (! (bfd_get_section_contents
4437 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
4438 gpentry
, sizeof (Elf64_External_gptab
))))
4444 bfd_alpha_elf64_swap_gptab_in (input_bfd
, &ext_gptab
,
4446 val
= int_gptab
.gt_entry
.gt_g_value
;
4447 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
4450 for (look
= 1; look
< c
; look
++)
4452 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
4453 tab
[look
].gt_entry
.gt_bytes
+= add
;
4455 if (tab
[look
].gt_entry
.gt_g_value
== val
)
4461 Elf64_gptab
*new_tab
;
4464 /* We need a new table entry. */
4465 new_tab
= ((Elf64_gptab
*)
4466 bfd_realloc ((PTR
) tab
,
4467 (c
+ 1) * sizeof (Elf64_gptab
)));
4468 if (new_tab
== NULL
)
4474 tab
[c
].gt_entry
.gt_g_value
= val
;
4475 tab
[c
].gt_entry
.gt_bytes
= add
;
4477 /* Merge in the size for the next smallest -G
4478 value, since that will be implied by this new
4481 for (look
= 1; look
< c
; look
++)
4483 if (tab
[look
].gt_entry
.gt_g_value
< val
4485 || (tab
[look
].gt_entry
.gt_g_value
4486 > tab
[max
].gt_entry
.gt_g_value
)))
4490 tab
[c
].gt_entry
.gt_bytes
+=
4491 tab
[max
].gt_entry
.gt_bytes
;
4496 last
= int_gptab
.gt_entry
.gt_bytes
;
4499 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4500 elf_link_input_bfd ignores this section. */
4501 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
4504 /* The table must be sorted by -G value. */
4506 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
4508 /* Swap out the table. */
4509 ext_tab
= ((Elf64_External_gptab
*)
4510 bfd_alloc (abfd
, c
* sizeof (Elf64_External_gptab
)));
4511 if (ext_tab
== NULL
)
4517 for (i
= 0; i
< c
; i
++)
4518 bfd_alpha_elf64_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
4521 o
->_raw_size
= c
* sizeof (Elf64_External_gptab
);
4522 o
->contents
= (bfd_byte
*) ext_tab
;
4524 /* Skip this section later on (I don't think this currently
4525 matters, but someday it might). */
4526 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
4532 /* Invoke the regular ELF backend linker to do all the work. */
4533 if (! bfd_elf64_bfd_final_link (abfd
, info
))
4536 /* Now write out the computed sections. */
4538 /* The .got subsections... */
4540 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
4541 for (i
= alpha_elf_hash_table(info
)->got_list
;
4543 i
= alpha_elf_tdata(i
)->got_link_next
)
4547 /* elf_bfd_final_link already did everything in dynobj. */
4551 sgot
= alpha_elf_tdata(i
)->got
;
4552 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
4553 sgot
->contents
, sgot
->output_offset
,
4559 #ifdef ERIC_neverdef
4560 if (reginfo_sec
!= (asection
*) NULL
)
4562 Elf64_External_RegInfo ext
;
4564 bfd_alpha_elf64_swap_reginfo_out (abfd
, ®info
, &ext
);
4565 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
4566 (file_ptr
) 0, sizeof ext
))
4571 if (mdebug_sec
!= (asection
*) NULL
)
4573 BFD_ASSERT (abfd
->output_has_begun
);
4574 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
4576 mdebug_sec
->filepos
))
4579 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
4582 if (gptab_data_sec
!= (asection
*) NULL
)
4584 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
4585 gptab_data_sec
->contents
,
4587 gptab_data_sec
->_raw_size
))
4591 if (gptab_bss_sec
!= (asection
*) NULL
)
4593 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
4594 gptab_bss_sec
->contents
,
4596 gptab_bss_sec
->_raw_size
))
4603 /* ECOFF swapping routines. These are used when dealing with the
4604 .mdebug section, which is in the ECOFF debugging format. Copied
4605 from elf32-mips.c. */
4606 static const struct ecoff_debug_swap
4607 elf64_alpha_ecoff_debug_swap
=
4609 /* Symbol table magic number. */
4611 /* Alignment of debugging information. E.g., 4. */
4613 /* Sizes of external symbolic information. */
4614 sizeof (struct hdr_ext
),
4615 sizeof (struct dnr_ext
),
4616 sizeof (struct pdr_ext
),
4617 sizeof (struct sym_ext
),
4618 sizeof (struct opt_ext
),
4619 sizeof (struct fdr_ext
),
4620 sizeof (struct rfd_ext
),
4621 sizeof (struct ext_ext
),
4622 /* Functions to swap in external symbolic data. */
4631 _bfd_ecoff_swap_tir_in
,
4632 _bfd_ecoff_swap_rndx_in
,
4633 /* Functions to swap out external symbolic data. */
4642 _bfd_ecoff_swap_tir_out
,
4643 _bfd_ecoff_swap_rndx_out
,
4644 /* Function to read in symbolic data. */
4645 elf64_alpha_read_ecoff_info
4648 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
4649 #define TARGET_LITTLE_NAME "elf64-alpha"
4650 #define ELF_ARCH bfd_arch_alpha
4651 #define ELF_MACHINE_CODE EM_ALPHA
4652 #define ELF_MAXPAGESIZE 0x10000
4654 #define bfd_elf64_bfd_link_hash_table_create \
4655 elf64_alpha_bfd_link_hash_table_create
4657 #define bfd_elf64_bfd_reloc_type_lookup \
4658 elf64_alpha_bfd_reloc_type_lookup
4659 #define elf_info_to_howto \
4660 elf64_alpha_info_to_howto
4662 #define bfd_elf64_mkobject \
4663 elf64_alpha_mkobject
4664 #define elf_backend_object_p \
4665 elf64_alpha_object_p
4667 #define elf_backend_section_from_shdr \
4668 elf64_alpha_section_from_shdr
4669 #define elf_backend_fake_sections \
4670 elf64_alpha_fake_sections
4671 #define elf_backend_additional_program_headers \
4672 elf64_alpha_additional_program_headers
4674 #define bfd_elf64_bfd_is_local_label_name \
4675 elf64_alpha_is_local_label_name
4676 #define bfd_elf64_find_nearest_line \
4677 elf64_alpha_find_nearest_line
4678 #define bfd_elf64_bfd_relax_section \
4679 elf64_alpha_relax_section
4681 #define elf_backend_add_symbol_hook \
4682 elf64_alpha_add_symbol_hook
4683 #define elf_backend_check_relocs \
4684 elf64_alpha_check_relocs
4685 #define elf_backend_create_dynamic_sections \
4686 elf64_alpha_create_dynamic_sections
4687 #define elf_backend_adjust_dynamic_symbol \
4688 elf64_alpha_adjust_dynamic_symbol
4689 #define elf_backend_always_size_sections \
4690 elf64_alpha_always_size_sections
4691 #define elf_backend_size_dynamic_sections \
4692 elf64_alpha_size_dynamic_sections
4693 #define elf_backend_relocate_section \
4694 elf64_alpha_relocate_section
4695 #define elf_backend_finish_dynamic_symbol \
4696 elf64_alpha_finish_dynamic_symbol
4697 #define elf_backend_finish_dynamic_sections \
4698 elf64_alpha_finish_dynamic_sections
4699 #define bfd_elf64_bfd_final_link \
4700 elf64_alpha_final_link
4702 #define elf_backend_ecoff_debug_swap \
4703 &elf64_alpha_ecoff_debug_swap
4706 * A few constants that determine how the .plt section is set up.
4708 #define elf_backend_want_got_plt 0
4709 #define elf_backend_plt_readonly 0
4710 #define elf_backend_want_plt_sym 1
4712 #include "elf64-target.h"