1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997 Free Software Foundation, Inc.
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_always_size_sections
106 PARAMS ((bfd *, struct bfd_link_info *));
107 static boolean elf64_alpha_calc_dynrel_sizes
108 PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *));
109 static boolean elf64_alpha_check_relocs
110 PARAMS((bfd *, struct bfd_link_info *, asection *sec,
111 const Elf_Internal_Rela *));
112 static boolean elf64_alpha_adjust_dynamic_symbol
113 PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *));
114 static boolean elf64_alpha_size_dynamic_sections
115 PARAMS((bfd *, struct bfd_link_info *));
116 static boolean elf64_alpha_adjust_dynindx
117 PARAMS((struct elf_link_hash_entry *, PTR));
118 static boolean elf64_alpha_relocate_section
119 PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
120 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
121 static boolean elf64_alpha_finish_dynamic_symbol
122 PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
123 Elf_Internal_Sym *));
124 static boolean elf64_alpha_finish_dynamic_sections
125 PARAMS((bfd *, struct bfd_link_info *));
126 static boolean elf64_alpha_final_link
127 PARAMS((bfd *, struct bfd_link_info *));
130 struct alpha_elf_link_hash_entry
132 struct elf_link_hash_entry root;
134 /* External symbol information. */
137 /* Cumulative flags for all the .got entries. */
140 /* Contexts (LITUSE) in which a literal was referenced. */
141 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
142 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
143 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
144 #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x08
146 /* Used to implement multiple .got subsections. */
147 struct alpha_elf_got_entry
149 struct alpha_elf_got_entry *next;
151 /* which .got subsection? */
154 /* the addend in effect for this entry. */
157 /* the .got offset for this entry. */
162 /* An additional flag. */
163 #define ALPHA_ELF_GOT_ENTRY_RELOCS_DONE 0x10
166 /* used to count non-got, non-plt relocations for delayed sizing
167 of relocation sections. */
168 struct alpha_elf_reloc_entry
170 struct alpha_elf_reloc_entry *next;
172 /* which .reloc section? */
175 /* what kind of relocation? */
178 /* how many did we find? */
183 /* Alpha ELF linker hash table. */
185 struct alpha_elf_link_hash_table
187 struct elf_link_hash_table root;
189 /* The head of a list of .got subsections linked through
190 alpha_elf_tdata(abfd)->got_link_next. */
194 /* Look up an entry in a Alpha ELF linker hash table. */
196 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
197 ((struct alpha_elf_link_hash_entry *) \
198 elf_link_hash_lookup (&(table)->root, (string), (create), \
201 /* Traverse a Alpha ELF linker hash table. */
203 #define alpha_elf_link_hash_traverse(table, func, info) \
204 (elf_link_hash_traverse \
206 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
209 /* Get the Alpha ELF linker hash table from a link_info structure. */
211 #define alpha_elf_hash_table(p) \
212 ((struct alpha_elf_link_hash_table *) ((p)->hash))
214 /* Get the object's symbols as our own entry type. */
216 #define alpha_elf_sym_hashes(abfd) \
217 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
219 /* Should we do dynamic things to this symbol? */
221 #define alpha_elf_dynamic_symbol_p(h, info) \
222 (((info)->shared && !(info)->symbolic && (h)->dynindx != -1) \
223 || (((h)->elf_link_hash_flags \
224 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) \
225 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
227 /* Create an entry in a Alpha ELF linker hash table. */
229 static struct bfd_hash_entry *
230 elf64_alpha_link_hash_newfunc (entry, table, string)
231 struct bfd_hash_entry *entry;
232 struct bfd_hash_table *table;
235 struct alpha_elf_link_hash_entry *ret =
236 (struct alpha_elf_link_hash_entry *) entry;
238 /* Allocate the structure if it has not already been allocated by a
240 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
241 ret = ((struct alpha_elf_link_hash_entry *)
242 bfd_hash_allocate (table,
243 sizeof (struct alpha_elf_link_hash_entry)));
244 if (ret == (struct alpha_elf_link_hash_entry *) NULL)
245 return (struct bfd_hash_entry *) ret;
247 /* Call the allocation method of the superclass. */
248 ret = ((struct alpha_elf_link_hash_entry *)
249 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
251 if (ret != (struct alpha_elf_link_hash_entry *) NULL)
253 /* Set local fields. */
254 memset (&ret->esym, 0, sizeof (EXTR));
255 /* We use -2 as a marker to indicate that the information has
256 not been set. -1 means there is no associated ifd. */
259 ret->got_entries = NULL;
260 ret->reloc_entries = NULL;
263 return (struct bfd_hash_entry *) ret;
266 /* Create a Alpha ELF linker hash table. */
268 static struct bfd_link_hash_table *
269 elf64_alpha_bfd_link_hash_table_create (abfd)
272 struct alpha_elf_link_hash_table *ret;
274 ret = ((struct alpha_elf_link_hash_table *)
275 bfd_zalloc (abfd, sizeof (struct alpha_elf_link_hash_table)));
276 if (ret == (struct alpha_elf_link_hash_table *) NULL)
279 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
280 elf64_alpha_link_hash_newfunc))
282 bfd_release (abfd, ret);
286 return &ret->root.root;
289 /* We have some private fields hanging off of the elf_tdata structure. */
291 struct alpha_elf_obj_tdata
293 struct elf_obj_tdata root;
295 /* For every input file, these are the got entries for that object's
297 struct alpha_elf_got_entry ** local_got_entries;
299 /* For every input file, this is the object that owns the got that
300 this input file uses. */
303 /* For every got, this is a linked list through the objects using this got */
304 bfd *in_got_link_next;
306 /* For every got, this is a link to the next got subsegment. */
309 /* For every got, this is the section. */
312 /* For every got, this is it's total number of *entries*. */
313 int total_got_entries;
315 /* For every got, this is the sum of the number of *entries* required
316 to hold all of the member object's local got. */
317 int n_local_got_entries;
320 #define alpha_elf_tdata(abfd) \
321 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
324 elf64_alpha_mkobject (abfd)
327 abfd->tdata.any = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
328 if (abfd->tdata.any == NULL)
334 elf64_alpha_object_p (abfd)
337 /* Allocate our special target data. */
338 struct alpha_elf_obj_tdata *new_tdata;
339 new_tdata = bfd_zalloc (abfd, sizeof (struct alpha_elf_obj_tdata));
340 if (new_tdata == NULL)
342 new_tdata->root = *abfd->tdata.elf_obj_data;
343 abfd->tdata.any = new_tdata;
345 /* Set the right machine number for an Alpha ELF file. */
346 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0);
349 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
350 from smaller values. Start with zero, widen, *then* decrement. */
351 #define MINUS_ONE (((bfd_vma)0) - 1)
353 static reloc_howto_type elf64_alpha_howto_table[] =
355 HOWTO (R_ALPHA_NONE, /* type */
357 0, /* size (0 = byte, 1 = short, 2 = long) */
359 true, /* pc_relative */
361 complain_overflow_dont, /* complain_on_overflow */
362 elf64_alpha_reloc_nil, /* special_function */
364 false, /* partial_inplace */
367 true), /* pcrel_offset */
369 /* A 32 bit reference to a symbol. */
370 HOWTO (R_ALPHA_REFLONG, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 false, /* pc_relative */
376 complain_overflow_bitfield, /* complain_on_overflow */
377 0, /* special_function */
378 "REFLONG", /* name */
379 false, /* partial_inplace */
380 0xffffffff, /* src_mask */
381 0xffffffff, /* dst_mask */
382 false), /* pcrel_offset */
384 /* A 64 bit reference to a symbol. */
385 HOWTO (R_ALPHA_REFQUAD, /* type */
387 4, /* size (0 = byte, 1 = short, 2 = long) */
389 false, /* pc_relative */
391 complain_overflow_bitfield, /* complain_on_overflow */
392 0, /* special_function */
393 "REFQUAD", /* name */
394 false, /* partial_inplace */
395 MINUS_ONE, /* src_mask */
396 MINUS_ONE, /* dst_mask */
397 false), /* pcrel_offset */
399 /* A 32 bit GP relative offset. This is just like REFLONG except
400 that when the value is used the value of the gp register will be
402 HOWTO (R_ALPHA_GPREL32, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 false, /* pc_relative */
408 complain_overflow_bitfield, /* complain_on_overflow */
409 0, /* special_function */
410 "GPREL32", /* name */
411 false, /* partial_inplace */
412 0xffffffff, /* src_mask */
413 0xffffffff, /* dst_mask */
414 false), /* pcrel_offset */
416 /* Used for an instruction that refers to memory off the GP register. */
417 HOWTO (R_ALPHA_LITERAL, /* type */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
421 false, /* pc_relative */
423 complain_overflow_signed, /* complain_on_overflow */
424 0, /* special_function */
425 "ELF_LITERAL", /* name */
426 false, /* partial_inplace */
427 0xffff, /* src_mask */
428 0xffff, /* dst_mask */
429 false), /* pcrel_offset */
431 /* This reloc only appears immediately following an ELF_LITERAL reloc.
432 It identifies a use of the literal. The symbol index is special:
433 1 means the literal address is in the base register of a memory
434 format instruction; 2 means the literal address is in the byte
435 offset register of a byte-manipulation instruction; 3 means the
436 literal address is in the target register of a jsr instruction.
437 This does not actually do any relocation. */
438 HOWTO (R_ALPHA_LITUSE, /* type */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
442 false, /* pc_relative */
444 complain_overflow_dont, /* complain_on_overflow */
445 elf64_alpha_reloc_nil, /* special_function */
447 false, /* partial_inplace */
450 false), /* pcrel_offset */
452 /* Load the gp register. This is always used for a ldah instruction
453 which loads the upper 16 bits of the gp register. The symbol
454 index of the GPDISP instruction is an offset in bytes to the lda
455 instruction that loads the lower 16 bits. The value to use for
456 the relocation is the difference between the GP value and the
457 current location; the load will always be done against a register
458 holding the current address.
460 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
461 any offset is present in the instructions, it is an offset from
462 the register to the ldah instruction. This lets us avoid any
463 stupid hackery like inventing a gp value to do partial relocation
464 against. Also unlike ECOFF, we do the whole relocation off of
465 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
466 space consuming bit, that, since all the information was present
467 in the GPDISP_HI16 reloc. */
468 HOWTO (R_ALPHA_GPDISP, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 false, /* pc_relative */
474 complain_overflow_dont, /* complain_on_overflow */
475 elf64_alpha_reloc_gpdisp, /* special_function */
477 false, /* partial_inplace */
478 0xffff, /* src_mask */
479 0xffff, /* dst_mask */
480 true), /* pcrel_offset */
482 /* A 21 bit branch. */
483 HOWTO (R_ALPHA_BRADDR, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 true, /* pc_relative */
489 complain_overflow_signed, /* complain_on_overflow */
490 0, /* special_function */
492 false, /* partial_inplace */
493 0x1fffff, /* src_mask */
494 0x1fffff, /* dst_mask */
495 true), /* pcrel_offset */
497 /* A hint for a jump to a register. */
498 HOWTO (R_ALPHA_HINT, /* type */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
502 true, /* pc_relative */
504 complain_overflow_dont, /* complain_on_overflow */
505 0, /* special_function */
507 false, /* partial_inplace */
508 0x3fff, /* src_mask */
509 0x3fff, /* dst_mask */
510 true), /* pcrel_offset */
512 /* 16 bit PC relative offset. */
513 HOWTO (R_ALPHA_SREL16, /* type */
515 1, /* size (0 = byte, 1 = short, 2 = long) */
517 true, /* pc_relative */
519 complain_overflow_signed, /* complain_on_overflow */
520 0, /* special_function */
522 false, /* partial_inplace */
523 0xffff, /* src_mask */
524 0xffff, /* dst_mask */
525 false), /* pcrel_offset */
527 /* 32 bit PC relative offset. */
528 HOWTO (R_ALPHA_SREL32, /* type */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
532 true, /* pc_relative */
534 complain_overflow_signed, /* complain_on_overflow */
535 0, /* special_function */
537 false, /* partial_inplace */
538 0xffffffff, /* src_mask */
539 0xffffffff, /* dst_mask */
540 false), /* pcrel_offset */
542 /* A 64 bit PC relative offset. */
543 HOWTO (R_ALPHA_SREL64, /* type */
545 4, /* size (0 = byte, 1 = short, 2 = long) */
547 true, /* pc_relative */
549 complain_overflow_signed, /* complain_on_overflow */
550 0, /* special_function */
552 false, /* partial_inplace */
553 MINUS_ONE, /* src_mask */
554 MINUS_ONE, /* dst_mask */
555 false), /* pcrel_offset */
557 /* Push a value on the reloc evaluation stack. */
558 /* Not implemented -- it's dumb. */
559 HOWTO (R_ALPHA_OP_PUSH, /* type */
561 0, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_dont, /* complain_on_overflow */
566 elf64_alpha_reloc_bad, /* special_function */
567 "OP_PUSH", /* name */
568 false, /* partial_inplace */
571 false), /* pcrel_offset */
573 /* Store the value from the stack at the given address. Store it in
574 a bitfield of size r_size starting at bit position r_offset. */
575 /* Not implemented -- it's dumb. */
576 HOWTO (R_ALPHA_OP_STORE, /* type */
578 4, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_dont, /* complain_on_overflow */
583 elf64_alpha_reloc_bad, /* special_function */
584 "OP_STORE", /* name */
585 false, /* partial_inplace */
587 MINUS_ONE, /* dst_mask */
588 false), /* pcrel_offset */
590 /* Subtract the reloc address from the value on the top of the
592 /* Not implemented -- it's dumb. */
593 HOWTO (R_ALPHA_OP_PSUB, /* type */
595 0, /* size (0 = byte, 1 = short, 2 = long) */
597 false, /* pc_relative */
599 complain_overflow_dont, /* complain_on_overflow */
600 elf64_alpha_reloc_bad, /* special_function */
601 "OP_PSUB", /* name */
602 false, /* partial_inplace */
605 false), /* pcrel_offset */
607 /* Shift the value on the top of the relocation stack right by the
609 /* Not implemented -- it's dumb. */
610 HOWTO (R_ALPHA_OP_PRSHIFT, /* type */
612 0, /* size (0 = byte, 1 = short, 2 = long) */
614 false, /* pc_relative */
616 complain_overflow_dont, /* complain_on_overflow */
617 elf64_alpha_reloc_bad, /* special_function */
618 "OP_PRSHIFT", /* name */
619 false, /* partial_inplace */
622 false), /* pcrel_offset */
624 /* Change the value of GP used by +r_addend until the next GPVALUE or the
625 end of the input bfd. */
626 /* Not implemented -- it's dumb. */
627 HOWTO (R_ALPHA_GPVALUE,
629 0, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_dont, /* complain_on_overflow */
634 elf64_alpha_reloc_bad, /* special_function */
635 "GPVALUE", /* name */
636 false, /* partial_inplace */
639 false), /* pcrel_offset */
641 /* The high 16 bits of the displacement from GP to the target. */
642 /* XXX: Not implemented. */
643 HOWTO (R_ALPHA_GPRELHIGH,
645 0, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_dont, /* complain_on_overflow */
650 elf64_alpha_reloc_bad, /* special_function */
651 "GPRELHIGH", /* name */
652 false, /* partial_inplace */
655 false), /* pcrel_offset */
657 /* The low 16 bits of the displacement from GP to the target. */
658 /* XXX: Not implemented. */
659 HOWTO (R_ALPHA_GPRELLOW,
661 0, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_dont, /* complain_on_overflow */
666 elf64_alpha_reloc_bad, /* special_function */
667 "GPRELLOW", /* name */
668 false, /* partial_inplace */
671 false), /* pcrel_offset */
673 /* A 16-bit displacement from the GP to the target. */
674 /* XXX: Not implemented. */
675 HOWTO (R_ALPHA_IMMED_GP_16,
677 0, /* size (0 = byte, 1 = short, 2 = long) */
679 false, /* pc_relative */
681 complain_overflow_dont, /* complain_on_overflow */
682 elf64_alpha_reloc_bad, /* special_function */
683 "IMMED_GP_16", /* name */
684 false, /* partial_inplace */
687 false), /* pcrel_offset */
689 /* The high bits of a 32-bit displacement from the GP to the target; the
690 low bits are supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
691 /* XXX: Not implemented. */
692 HOWTO (R_ALPHA_IMMED_GP_HI32,
694 0, /* size (0 = byte, 1 = short, 2 = long) */
696 false, /* pc_relative */
698 complain_overflow_dont, /* complain_on_overflow */
699 elf64_alpha_reloc_bad, /* special_function */
700 "IMMED_GP_HI32", /* name */
701 false, /* partial_inplace */
704 false), /* pcrel_offset */
706 /* The high bits of a 32-bit displacement to the starting address of the
707 current section (the relocation target is ignored); the low bits are
708 supplied in the subsequent R_ALPHA_IMMED_LO32 relocs. */
709 /* XXX: Not implemented. */
710 HOWTO (R_ALPHA_IMMED_SCN_HI32,
712 0, /* size (0 = byte, 1 = short, 2 = long) */
714 false, /* pc_relative */
716 complain_overflow_dont, /* complain_on_overflow */
717 elf64_alpha_reloc_bad, /* special_function */
718 "IMMED_SCN_HI32", /* name */
719 false, /* partial_inplace */
722 false), /* pcrel_offset */
724 /* The high bits of a 32-bit displacement from the previous br, bsr, jsr
725 or jmp insn (as tagged by a BRADDR or HINT reloc) to the target; the
726 low bits are supplied by subsequent R_ALPHA_IMMED_LO32 relocs. */
727 /* XXX: Not implemented. */
728 HOWTO (R_ALPHA_IMMED_BR_HI32,
730 0, /* size (0 = byte, 1 = short, 2 = long) */
732 false, /* pc_relative */
734 complain_overflow_dont, /* complain_on_overflow */
735 elf64_alpha_reloc_bad, /* special_function */
736 "IMMED_BR_HI32", /* name */
737 false, /* partial_inplace */
740 false), /* pcrel_offset */
742 /* The low 16 bits of a displacement calculated in a previous HI32 reloc. */
743 /* XXX: Not implemented. */
744 HOWTO (R_ALPHA_IMMED_LO32,
746 0, /* size (0 = byte, 1 = short, 2 = long) */
748 false, /* pc_relative */
750 complain_overflow_dont, /* complain_on_overflow */
751 elf64_alpha_reloc_bad, /* special_function */
752 "IMMED_LO32", /* name */
753 false, /* partial_inplace */
756 false), /* pcrel_offset */
758 /* Misc ELF relocations. */
760 /* A dynamic relocation to copy the target into our .dynbss section. */
761 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
762 is present because every other ELF has one, but should not be used
763 because .dynbss is an ugly thing. */
770 complain_overflow_dont,
771 bfd_elf_generic_reloc,
778 /* A dynamic relocation for a .got entry. */
779 HOWTO (R_ALPHA_GLOB_DAT,
785 complain_overflow_dont,
786 bfd_elf_generic_reloc,
793 /* A dynamic relocation for a .plt entry. */
794 HOWTO (R_ALPHA_JMP_SLOT,
800 complain_overflow_dont,
801 bfd_elf_generic_reloc,
808 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
809 HOWTO (R_ALPHA_RELATIVE,
815 complain_overflow_dont,
816 bfd_elf_generic_reloc,
824 /* A relocation function which doesn't do anything. */
826 static bfd_reloc_status_type
827 elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
834 char **error_message;
837 reloc->address += sec->output_offset;
841 /* A relocation function used for an unsupported reloc. */
843 static bfd_reloc_status_type
844 elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message)
851 char **error_message;
854 reloc->address += sec->output_offset;
855 return bfd_reloc_notsupported;
858 /* Do the work of the GPDISP relocation. */
860 static bfd_reloc_status_type
861 elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda)
867 bfd_reloc_status_type ret = bfd_reloc_ok;
869 unsigned long i_ldah, i_lda;
871 i_ldah = bfd_get_32 (abfd, p_ldah);
872 i_lda = bfd_get_32 (abfd, p_lda);
874 /* Complain if the instructions are not correct. */
875 if (((i_ldah >> 26) & 0x3f) != 0x09
876 || ((i_lda >> 26) & 0x3f) != 0x08)
877 ret = bfd_reloc_dangerous;
879 /* Extract the user-supplied offset, mirroring the sign extensions
880 that the instructions perform. */
881 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff);
882 addend = (addend ^ 0x80008000) - 0x80008000;
886 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma)0x80000000
887 || gpdisp >= 0x7fff8000)
888 ret = bfd_reloc_overflow;
890 /* compensate for the sign extension again. */
891 i_ldah = ((i_ldah & 0xffff0000)
892 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff));
893 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff);
895 bfd_put_32 (abfd, i_ldah, p_ldah);
896 bfd_put_32 (abfd, i_lda, p_lda);
901 /* The special function for the GPDISP reloc. */
903 static bfd_reloc_status_type
904 elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section,
907 arelent *reloc_entry;
910 asection *input_section;
914 bfd_reloc_status_type ret;
915 bfd_vma gp, relocation;
916 bfd_byte *p_ldah, *p_lda;
918 /* Don't do anything if we're not doing a final link. */
921 reloc_entry->address += input_section->output_offset;
925 if (reloc_entry->address > input_section->_cooked_size ||
926 reloc_entry->address + reloc_entry->addend > input_section->_cooked_size)
927 return bfd_reloc_outofrange;
929 /* The gp used in the portion of the output object to which this
930 input object belongs is cached on the input bfd. */
931 gp = _bfd_get_gp_value (abfd);
933 relocation = (input_section->output_section->vma
934 + input_section->output_offset
935 + reloc_entry->address);
937 p_ldah = (bfd_byte *) data + reloc_entry->address;
938 p_lda = p_ldah + reloc_entry->addend;
940 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda);
942 /* Complain if the instructions are not correct. */
943 if (ret == bfd_reloc_dangerous)
944 *err_msg = "GPDISP relocation did not find ldah and lda instructions";
949 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
953 bfd_reloc_code_real_type bfd_reloc_val;
957 static const struct elf_reloc_map elf64_alpha_reloc_map[] =
959 {BFD_RELOC_NONE, R_ALPHA_NONE},
960 {BFD_RELOC_32, R_ALPHA_REFLONG},
961 {BFD_RELOC_64, R_ALPHA_REFQUAD},
962 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD},
963 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32},
964 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL},
965 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE},
966 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP},
967 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR},
968 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT},
969 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16},
970 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32},
971 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64},
974 /* Given a BFD reloc type, return a HOWTO structure. */
976 static reloc_howto_type *
977 elf64_alpha_bfd_reloc_type_lookup (abfd, code)
979 bfd_reloc_code_real_type code;
981 const struct elf_reloc_map *i, *e;
982 i = e = elf64_alpha_reloc_map;
983 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map);
986 if (i->bfd_reloc_val == code)
987 return &elf64_alpha_howto_table[i->elf_reloc_val];
992 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
995 elf64_alpha_info_to_howto (abfd, cache_ptr, dst)
998 Elf64_Internal_Rela *dst;
1002 r_type = ELF64_R_TYPE(dst->r_info);
1003 BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
1004 cache_ptr->howto = &elf64_alpha_howto_table[r_type];
1008 #define PLT_HEADER_SIZE 32
1009 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
1010 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
1011 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
1012 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
1014 #define PLT_ENTRY_SIZE 12
1015 #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */
1016 #define PLT_ENTRY_WORD2 0
1017 #define PLT_ENTRY_WORD3 0
1019 #define MAX_GOT_ENTRIES (64*1024 / 8)
1021 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
1023 /* Handle an Alpha specific section when reading an object file. This
1024 is called when elfcode.h finds a section with an unknown type.
1025 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
1029 elf64_alpha_section_from_shdr (abfd, hdr, name)
1031 Elf64_Internal_Shdr *hdr;
1036 /* There ought to be a place to keep ELF backend specific flags, but
1037 at the moment there isn't one. We just keep track of the
1038 sections by their name, instead. Fortunately, the ABI gives
1039 suggested names for all the MIPS specific sections, so we will
1040 probably get away with this. */
1041 switch (hdr->sh_type)
1043 case SHT_ALPHA_DEBUG:
1044 if (strcmp (name, ".mdebug") != 0)
1047 #ifdef ERIC_neverdef
1048 case SHT_ALPHA_REGINFO:
1049 if (strcmp (name, ".reginfo") != 0
1050 || hdr->sh_size != sizeof (Elf64_External_RegInfo))
1058 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1060 newsect = hdr->bfd_section;
1062 if (hdr->sh_type == SHT_ALPHA_DEBUG)
1064 if (! bfd_set_section_flags (abfd, newsect,
1065 (bfd_get_section_flags (abfd, newsect)
1070 #ifdef ERIC_neverdef
1071 /* For a .reginfo section, set the gp value in the tdata information
1072 from the contents of this section. We need the gp value while
1073 processing relocs, so we just get it now. */
1074 if (hdr->sh_type == SHT_ALPHA_REGINFO)
1076 Elf64_External_RegInfo ext;
1079 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
1080 (file_ptr) 0, sizeof ext))
1082 bfd_alpha_elf64_swap_reginfo_in (abfd, &ext, &s);
1083 elf_gp (abfd) = s.ri_gp_value;
1090 /* Set the correct type for an Alpha ELF section. We do this by the
1091 section name, which is a hack, but ought to work. */
1094 elf64_alpha_fake_sections (abfd, hdr, sec)
1096 Elf64_Internal_Shdr *hdr;
1099 register const char *name;
1101 name = bfd_get_section_name (abfd, sec);
1103 if (strcmp (name, ".mdebug") == 0)
1105 hdr->sh_type = SHT_ALPHA_DEBUG;
1106 /* In a shared object on Irix 5.3, the .mdebug section has an
1107 entsize of 0. FIXME: Does this matter? */
1108 if ((abfd->flags & DYNAMIC) != 0 )
1109 hdr->sh_entsize = 0;
1111 hdr->sh_entsize = 1;
1113 #ifdef ERIC_neverdef
1114 else if (strcmp (name, ".reginfo") == 0)
1116 hdr->sh_type = SHT_ALPHA_REGINFO;
1117 /* In a shared object on Irix 5.3, the .reginfo section has an
1118 entsize of 0x18. FIXME: Does this matter? */
1119 if ((abfd->flags & DYNAMIC) != 0)
1120 hdr->sh_entsize = sizeof (Elf64_External_RegInfo);
1122 hdr->sh_entsize = 1;
1124 /* Force the section size to the correct value, even if the
1125 linker thinks it is larger. The link routine below will only
1126 write out this much data for .reginfo. */
1127 hdr->sh_size = sec->_raw_size = sizeof (Elf64_External_RegInfo);
1129 else if (strcmp (name, ".hash") == 0
1130 || strcmp (name, ".dynamic") == 0
1131 || strcmp (name, ".dynstr") == 0)
1133 hdr->sh_entsize = 0;
1134 hdr->sh_info = SIZEOF_ALPHA_DYNSYM_SECNAMES;
1137 else if (strcmp (name, ".sdata") == 0
1138 || strcmp (name, ".sbss") == 0
1139 || strcmp (name, ".lit4") == 0
1140 || strcmp (name, ".lit8") == 0)
1141 hdr->sh_flags |= SHF_ALPHA_GPREL;
1146 /* Return the number of additional phdrs we will need. */
1149 elf64_alpha_additional_program_headers (abfd)
1157 s = bfd_get_section_by_name (abfd, ".reginfo");
1158 if (s != NULL && (s->flags & SEC_LOAD) != 0)
1160 /* We need a PT_ALPHA_REGINFO segment. */
1164 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL
1165 && bfd_get_section_by_name (abfd, ".mdebug") != NULL)
1167 /* We need a PT_ALPHA_RTPROC segment. */
1174 /* Create the .got section. */
1177 elf64_alpha_create_got_section(abfd, info)
1179 struct bfd_link_info *info;
1183 if (bfd_get_section_by_name (abfd, ".got"))
1186 s = bfd_make_section (abfd, ".got");
1188 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1191 | SEC_LINKER_CREATED))
1192 || !bfd_set_section_alignment (abfd, s, 3))
1195 alpha_elf_tdata (abfd)->got = s;
1200 /* Create all the dynamic sections. */
1203 elf64_alpha_create_dynamic_sections (abfd, info)
1205 struct bfd_link_info *info;
1208 struct elf_link_hash_entry *h;
1210 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1212 s = bfd_make_section (abfd, ".plt");
1214 || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1217 | SEC_LINKER_CREATED
1219 || ! bfd_set_section_alignment (abfd, s, 3))
1222 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1225 if (! (_bfd_generic_link_add_one_symbol
1226 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
1227 (bfd_vma) 0, (const char *) NULL, false,
1228 get_elf_backend_data (abfd)->collect,
1229 (struct bfd_link_hash_entry **) &h)))
1231 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1232 h->type = STT_OBJECT;
1235 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1238 s = bfd_make_section (abfd, ".rela.plt");
1240 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1243 | SEC_LINKER_CREATED
1245 || ! bfd_set_section_alignment (abfd, s, 3))
1248 /* We may or may not have created a .got section for this object, but
1249 we definitely havn't done the rest of the work. */
1251 if (!elf64_alpha_create_got_section (abfd, info))
1254 s = bfd_make_section(abfd, ".rela.got");
1256 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1259 | SEC_LINKER_CREATED
1261 || !bfd_set_section_alignment (abfd, s, 3))
1264 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1265 dynobj's .got section. We don't do this in the linker script
1266 because we don't want to define the symbol if we are not creating
1267 a global offset table. */
1269 if (!(_bfd_generic_link_add_one_symbol
1270 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
1271 alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
1272 false, get_elf_backend_data (abfd)->collect,
1273 (struct bfd_link_hash_entry **) &h)))
1275 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1276 h->type = STT_OBJECT;
1279 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
1282 elf_hash_table (info)->hgot = h;
1287 /* Read ECOFF debugging information from a .mdebug section into a
1288 ecoff_debug_info structure. */
1291 elf64_alpha_read_ecoff_info (abfd, section, debug)
1294 struct ecoff_debug_info *debug;
1297 const struct ecoff_debug_swap *swap;
1298 char *ext_hdr = NULL;
1300 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1302 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size);
1303 if (ext_hdr == NULL && swap->external_hdr_size != 0)
1306 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
1307 swap->external_hdr_size)
1311 symhdr = &debug->symbolic_header;
1312 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
1314 /* The symbolic header contains absolute file offsets and sizes to
1316 #define READ(ptr, offset, count, size, type) \
1317 if (symhdr->count == 0) \
1318 debug->ptr = NULL; \
1321 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1322 if (debug->ptr == NULL) \
1323 goto error_return; \
1324 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1325 || (bfd_read (debug->ptr, size, symhdr->count, \
1326 abfd) != size * symhdr->count)) \
1327 goto error_return; \
1330 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
1331 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
1332 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
1333 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
1334 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
1335 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
1337 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
1338 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
1339 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
1340 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
1341 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
1345 debug->adjust = NULL;
1350 if (ext_hdr != NULL)
1352 if (debug->line != NULL)
1354 if (debug->external_dnr != NULL)
1355 free (debug->external_dnr);
1356 if (debug->external_pdr != NULL)
1357 free (debug->external_pdr);
1358 if (debug->external_sym != NULL)
1359 free (debug->external_sym);
1360 if (debug->external_opt != NULL)
1361 free (debug->external_opt);
1362 if (debug->external_aux != NULL)
1363 free (debug->external_aux);
1364 if (debug->ss != NULL)
1366 if (debug->ssext != NULL)
1367 free (debug->ssext);
1368 if (debug->external_fdr != NULL)
1369 free (debug->external_fdr);
1370 if (debug->external_rfd != NULL)
1371 free (debug->external_rfd);
1372 if (debug->external_ext != NULL)
1373 free (debug->external_ext);
1377 /* Alpha ELF local labels start with '$'. */
1380 elf64_alpha_is_local_label_name (abfd, name)
1384 return name[0] == '$';
1387 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1388 routine in order to handle the ECOFF debugging information. We
1389 still call this mips_elf_find_line because of the slot
1390 find_line_info in elf_obj_tdata is declared that way. */
1392 struct mips_elf_find_line
1394 struct ecoff_debug_info d;
1395 struct ecoff_find_line i;
1399 elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
1400 functionname_ptr, line_ptr)
1405 const char **filename_ptr;
1406 const char **functionname_ptr;
1407 unsigned int *line_ptr;
1411 msec = bfd_get_section_by_name (abfd, ".mdebug");
1415 struct mips_elf_find_line *fi;
1416 const struct ecoff_debug_swap * const swap =
1417 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1419 /* If we are called during a link, alpha_elf_final_link may have
1420 cleared the SEC_HAS_CONTENTS field. We force it back on here
1421 if appropriate (which it normally will be). */
1422 origflags = msec->flags;
1423 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS)
1424 msec->flags |= SEC_HAS_CONTENTS;
1426 fi = elf_tdata (abfd)->find_line_info;
1429 bfd_size_type external_fdr_size;
1432 struct fdr *fdr_ptr;
1434 fi = ((struct mips_elf_find_line *)
1435 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line)));
1438 msec->flags = origflags;
1442 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d))
1444 msec->flags = origflags;
1448 /* Swap in the FDR information. */
1449 fi->d.fdr = ((struct fdr *)
1451 (fi->d.symbolic_header.ifdMax *
1452 sizeof (struct fdr))));
1453 if (fi->d.fdr == NULL)
1455 msec->flags = origflags;
1458 external_fdr_size = swap->external_fdr_size;
1459 fdr_ptr = fi->d.fdr;
1460 fraw_src = (char *) fi->d.external_fdr;
1461 fraw_end = (fraw_src
1462 + fi->d.symbolic_header.ifdMax * external_fdr_size);
1463 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
1464 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr);
1466 elf_tdata (abfd)->find_line_info = fi;
1468 /* Note that we don't bother to ever free this information.
1469 find_nearest_line is either called all the time, as in
1470 objdump -l, so the information should be saved, or it is
1471 rarely called, as in ld error messages, so the memory
1472 wasted is unimportant. Still, it would probably be a
1473 good idea for free_cached_info to throw it away. */
1476 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap,
1477 &fi->i, filename_ptr, functionname_ptr,
1480 msec->flags = origflags;
1484 msec->flags = origflags;
1487 /* Fall back on the generic ELF find_nearest_line routine. */
1489 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset,
1490 filename_ptr, functionname_ptr,
1494 /* Structure used to pass information to alpha_elf_output_extsym. */
1499 struct bfd_link_info *info;
1500 struct ecoff_debug_info *debug;
1501 const struct ecoff_debug_swap *swap;
1506 elf64_alpha_output_extsym (h, data)
1507 struct alpha_elf_link_hash_entry *h;
1510 struct extsym_info *einfo = (struct extsym_info *) data;
1512 asection *sec, *output_section;
1514 if (h->root.indx == -2)
1516 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1517 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
1518 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1519 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
1521 else if (einfo->info->strip == strip_all
1522 || (einfo->info->strip == strip_some
1523 && bfd_hash_lookup (einfo->info->keep_hash,
1524 h->root.root.root.string,
1525 false, false) == NULL))
1533 if (h->esym.ifd == -2)
1536 h->esym.cobol_main = 0;
1537 h->esym.weakext = 0;
1538 h->esym.reserved = 0;
1539 h->esym.ifd = ifdNil;
1540 h->esym.asym.value = 0;
1541 h->esym.asym.st = stGlobal;
1543 if (h->root.root.type != bfd_link_hash_defined
1544 && h->root.root.type != bfd_link_hash_defweak)
1545 h->esym.asym.sc = scAbs;
1550 sec = h->root.root.u.def.section;
1551 output_section = sec->output_section;
1553 /* When making a shared library and symbol h is the one from
1554 the another shared library, OUTPUT_SECTION may be null. */
1555 if (output_section == NULL)
1556 h->esym.asym.sc = scUndefined;
1559 name = bfd_section_name (output_section->owner, output_section);
1561 if (strcmp (name, ".text") == 0)
1562 h->esym.asym.sc = scText;
1563 else if (strcmp (name, ".data") == 0)
1564 h->esym.asym.sc = scData;
1565 else if (strcmp (name, ".sdata") == 0)
1566 h->esym.asym.sc = scSData;
1567 else if (strcmp (name, ".rodata") == 0
1568 || strcmp (name, ".rdata") == 0)
1569 h->esym.asym.sc = scRData;
1570 else if (strcmp (name, ".bss") == 0)
1571 h->esym.asym.sc = scBss;
1572 else if (strcmp (name, ".sbss") == 0)
1573 h->esym.asym.sc = scSBss;
1574 else if (strcmp (name, ".init") == 0)
1575 h->esym.asym.sc = scInit;
1576 else if (strcmp (name, ".fini") == 0)
1577 h->esym.asym.sc = scFini;
1579 h->esym.asym.sc = scAbs;
1583 h->esym.asym.reserved = 0;
1584 h->esym.asym.index = indexNil;
1587 if (h->root.root.type == bfd_link_hash_common)
1588 h->esym.asym.value = h->root.root.u.c.size;
1589 else if (h->root.root.type == bfd_link_hash_defined
1590 || h->root.root.type == bfd_link_hash_defweak)
1592 if (h->esym.asym.sc == scCommon)
1593 h->esym.asym.sc = scBss;
1594 else if (h->esym.asym.sc == scSCommon)
1595 h->esym.asym.sc = scSBss;
1597 sec = h->root.root.u.def.section;
1598 output_section = sec->output_section;
1599 if (output_section != NULL)
1600 h->esym.asym.value = (h->root.root.u.def.value
1601 + sec->output_offset
1602 + output_section->vma);
1604 h->esym.asym.value = 0;
1606 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1608 /* Set type and value for a symbol with a function stub. */
1609 h->esym.asym.st = stProc;
1610 sec = bfd_get_section_by_name (einfo->abfd, ".plt");
1612 h->esym.asym.value = 0;
1615 output_section = sec->output_section;
1616 if (output_section != NULL)
1617 h->esym.asym.value = (h->root.plt_offset
1618 + sec->output_offset
1619 + output_section->vma);
1621 h->esym.asym.value = 0;
1628 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
1629 h->root.root.root.string,
1632 einfo->failed = true;
1639 /* FIXME: Create a runtime procedure table from the .mdebug section.
1642 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
1645 struct bfd_link_info *info;
1647 struct ecoff_debug_info *debug;
1650 /* Handle dynamic relocations when doing an Alpha ELF link. */
1653 elf64_alpha_check_relocs (abfd, info, sec, relocs)
1655 struct bfd_link_info *info;
1657 const Elf_Internal_Rela *relocs;
1661 const char *rel_sec_name;
1662 Elf_Internal_Shdr *symtab_hdr;
1663 struct alpha_elf_link_hash_entry **sym_hashes;
1664 struct alpha_elf_got_entry **local_got_entries;
1665 const Elf_Internal_Rela *rel, *relend;
1668 if (info->relocateable)
1671 dynobj = elf_hash_table(info)->dynobj;
1673 elf_hash_table(info)->dynobj = dynobj = abfd;
1676 rel_sec_name = NULL;
1677 symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
1678 sym_hashes = alpha_elf_sym_hashes(abfd);
1679 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries;
1682 relend = relocs + sec->reloc_count;
1683 for (rel = relocs; rel < relend; ++rel)
1685 unsigned long r_symndx, r_type;
1686 struct alpha_elf_link_hash_entry *h;
1688 r_symndx = ELF64_R_SYM (rel->r_info);
1689 if (r_symndx < symtab_hdr->sh_info)
1693 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1694 h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
1696 r_type = ELF64_R_TYPE (rel->r_info);
1700 case R_ALPHA_LITERAL:
1702 struct alpha_elf_got_entry *gotent;
1707 /* Search for and possibly create a got entry. */
1708 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
1709 if (gotent->gotobj == abfd &&
1710 gotent->addend == rel->r_addend)
1715 gotent = ((struct alpha_elf_got_entry *)
1717 sizeof (struct alpha_elf_got_entry)));
1721 gotent->gotobj = abfd;
1722 gotent->addend = rel->r_addend;
1723 gotent->got_offset = -1;
1726 gotent->next = h->got_entries;
1727 h->got_entries = gotent;
1729 alpha_elf_tdata (abfd)->total_got_entries++;
1734 /* This is a local .got entry -- record for merge. */
1735 if (!local_got_entries)
1738 size = (symtab_hdr->sh_info
1739 * sizeof (struct alpha_elf_got_entry *));
1741 local_got_entries = ((struct alpha_elf_got_entry **)
1742 bfd_alloc (abfd, size));
1743 if (!local_got_entries)
1746 memset (local_got_entries, 0, size);
1747 alpha_elf_tdata (abfd)->local_got_entries =
1751 for (gotent = local_got_entries[ELF64_R_SYM(rel->r_info)];
1752 gotent != NULL && gotent->addend != rel->r_addend;
1753 gotent = gotent->next)
1757 gotent = ((struct alpha_elf_got_entry *)
1759 sizeof (struct alpha_elf_got_entry)));
1763 gotent->gotobj = abfd;
1764 gotent->addend = rel->r_addend;
1765 gotent->got_offset = -1;
1768 gotent->next = local_got_entries[ELF64_R_SYM(rel->r_info)];
1769 local_got_entries[ELF64_R_SYM(rel->r_info)] = gotent;
1771 alpha_elf_tdata(abfd)->total_got_entries++;
1772 alpha_elf_tdata(abfd)->n_local_got_entries++;
1776 /* Remember how this literal is used from its LITUSEs.
1777 This will be important when it comes to decide if we can
1778 create a .plt entry for a function symbol. */
1780 && ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE)
1785 if (rel->r_addend >= 1 && rel->r_addend <= 3)
1786 flags |= 1 << rel->r_addend;
1788 while (rel+1 < relend &&
1789 ELF64_R_TYPE (rel[1].r_info) == R_ALPHA_LITUSE);
1793 /* No LITUSEs -- presumably the address is not being
1794 loaded for nothing. */
1795 flags = ALPHA_ELF_LINK_HASH_LU_ADDR;
1798 gotent->flags |= flags;
1801 /* Make a guess as to whether a .plt entry will be needed. */
1802 if ((h->flags |= flags) == ALPHA_ELF_LINK_HASH_LU_FUNC)
1803 h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1805 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1810 case R_ALPHA_GPDISP:
1811 case R_ALPHA_GPREL32:
1812 /* We don't actually use the .got here, but the sections must
1813 be created before the linker maps input sections to output
1817 if (!elf64_alpha_create_got_section (abfd, info))
1820 /* Make sure the object's gotobj is set to itself so
1821 that we default to every object with its own .got.
1822 We'll merge .gots later once we've collected each
1824 alpha_elf_tdata(abfd)->gotobj = abfd;
1830 case R_ALPHA_SREL16:
1831 case R_ALPHA_SREL32:
1832 case R_ALPHA_SREL64:
1837 case R_ALPHA_REFLONG:
1838 case R_ALPHA_REFQUAD:
1839 if (rel_sec_name == NULL)
1841 rel_sec_name = (bfd_elf_string_from_elf_section
1842 (abfd, elf_elfheader(abfd)->e_shstrndx,
1843 elf_section_data(sec)->rel_hdr.sh_name));
1844 if (rel_sec_name == NULL)
1847 BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0
1848 && strcmp (bfd_get_section_name (abfd, sec),
1849 rel_sec_name+5) == 0);
1852 /* We need to create the section here now whether we eventually
1853 use it or not so that it gets mapped to an output section by
1854 the linker. If not used, we'll kill it in
1855 size_dynamic_sections. */
1858 sreloc = bfd_get_section_by_name (dynobj, rel_sec_name);
1861 sreloc = bfd_make_section (dynobj, rel_sec_name);
1863 || !bfd_set_section_flags (dynobj, sreloc,
1867 | SEC_LINKER_CREATED
1869 || !bfd_set_section_alignment (dynobj, sreloc, 3))
1876 /* Since we havn't seen all of the input symbols yet, we
1877 don't know whether we'll actually need a dynamic relocation
1878 entry for this reloc. So make a record of it. Once we
1879 find out if this thing needs dynamic relocation we'll
1880 expand the relocation sections by the appropriate amount. */
1882 struct alpha_elf_reloc_entry *rent;
1884 for (rent = h->reloc_entries; rent; rent = rent->next)
1885 if (rent->rtype == r_type && rent->srel == sreloc)
1890 rent = ((struct alpha_elf_reloc_entry *)
1892 sizeof (struct alpha_elf_reloc_entry)));
1896 rent->srel = sreloc;
1897 rent->rtype = r_type;
1900 rent->next = h->reloc_entries;
1901 h->reloc_entries = rent;
1906 else if (info->shared)
1908 /* If this is a shared library, we need a RELATIVE reloc. */
1909 sreloc->_raw_size += sizeof (Elf64_External_Rela);
1918 /* Adjust a symbol defined by a dynamic object and referenced by a
1919 regular object. The current definition is in some section of the
1920 dynamic object, but we're not including those sections. We have to
1921 change the definition to something the rest of the link can
1925 elf64_alpha_adjust_dynamic_symbol (info, h)
1926 struct bfd_link_info *info;
1927 struct elf_link_hash_entry *h;
1931 struct alpha_elf_link_hash_entry *ah;
1933 dynobj = elf_hash_table(info)->dynobj;
1934 ah = (struct alpha_elf_link_hash_entry *)h;
1936 /* Now that we've seen all of the input symbols, finalize our decision
1937 about whether this symbol should get a .plt entry. */
1939 if (h->root.type != bfd_link_hash_undefweak
1940 && alpha_elf_dynamic_symbol_p (h, info)
1941 && ((h->type == STT_FUNC
1942 && !(ah->flags & ALPHA_ELF_LINK_HASH_LU_ADDR))
1943 || (h->type == STT_NOTYPE
1944 && ah->flags == ALPHA_ELF_LINK_HASH_LU_FUNC))
1945 /* Don't prevent otherwise valid programs from linking by attempting
1946 to create a new .got entry somewhere. A Correct Solution would be
1947 to add a new .got section to a new object file and let it be merged
1948 somewhere later. But for now don't bother. */
1951 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1953 s = bfd_get_section_by_name(dynobj, ".plt");
1954 if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info))
1957 /* The first bit of the .plt is reserved. */
1958 if (s->_raw_size == 0)
1959 s->_raw_size = PLT_HEADER_SIZE;
1961 h->plt_offset = s->_raw_size;
1962 s->_raw_size += PLT_ENTRY_SIZE;
1964 /* If this symbol is not defined in a regular file, and we are not
1965 generating a shared library, then set the symbol to the location
1966 in the .plt. This is required to make function pointers compare
1967 equal between the normal executable and the shared library. */
1970 h->root.u.def.section = s;
1971 h->root.u.def.value = h->plt_offset;
1974 /* We also need a JMP_SLOT entry in the .rela.plt section. */
1975 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1976 BFD_ASSERT (s != NULL);
1977 s->_raw_size += sizeof (Elf64_External_Rela);
1982 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1984 /* If this is a weak symbol, and there is a real definition, the
1985 processor independent code will have arranged for us to see the
1986 real definition first, and we can just use the same value. */
1987 if (h->weakdef != NULL)
1989 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1990 || h->weakdef->root.type == bfd_link_hash_defweak);
1991 h->root.u.def.section = h->weakdef->root.u.def.section;
1992 h->root.u.def.value = h->weakdef->root.u.def.value;
1996 /* This is a reference to a symbol defined by a dynamic object which
1997 is not a function. The Alpha, since it uses .got entries for all
1998 symbols even in regular objects, does not need the hackery of a
1999 .dynbss section and COPY dynamic relocations. */
2004 /* Is it possible to merge two object file's .got tables? */
2007 elf64_alpha_can_merge_gots (a, b)
2010 int total = alpha_elf_tdata (a)->total_got_entries;
2012 /* Trivial quick fallout test. */
2013 if (total + alpha_elf_tdata (b)->total_got_entries <= MAX_GOT_ENTRIES)
2016 /* By their nature, local .got entries cannot be merged. */
2017 if ((total += alpha_elf_tdata (b)->n_local_got_entries) > MAX_GOT_ENTRIES)
2020 /* Failing the common trivial comparison, we must effectively
2021 perform the merge. Not actually performing the merge means that
2022 we don't have to store undo information in case we fail. */
2024 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes(b);
2025 Elf_Internal_Shdr *symtab_hdr = &elf_tdata(b)->symtab_hdr;
2028 n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info;
2029 for (i = 0; i < n; ++i)
2031 struct alpha_elf_got_entry *ae, *be;
2032 for (be = hashes[i]->got_entries; be ; be = be->next)
2034 if (be->gotobj != b)
2037 for (ae = hashes[i]->got_entries; ae ; ae = ae->next)
2038 if (ae->gotobj == a && ae->addend == be->addend)
2041 if (++total > MAX_GOT_ENTRIES)
2051 /* Actually merge two .got tables. */
2054 elf64_alpha_merge_gots (a, b)
2057 int total = alpha_elf_tdata(a)->total_got_entries;
2059 /* Remember local expansion. */
2061 int e = alpha_elf_tdata(b)->n_local_got_entries;
2063 alpha_elf_tdata(a)->n_local_got_entries += e;
2066 /* Let the local .got entries know they are part of a new subsegment. */
2068 struct alpha_elf_got_entry **local_got_entries;
2069 local_got_entries = alpha_elf_tdata(b)->local_got_entries;
2070 if (local_got_entries)
2074 n = elf_tdata(b)->symtab_hdr.sh_info;
2075 for (i = 0; i < n; ++i)
2077 struct alpha_elf_got_entry *gotent;
2078 for (gotent = local_got_entries[i]; gotent; gotent = gotent->next)
2084 /* Merge the global .got entries. */
2086 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes(b);
2087 Elf_Internal_Shdr *symtab_hdr = &elf_tdata(b)->symtab_hdr;
2090 n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info;
2091 for (i = 0; i < n; ++i)
2093 struct alpha_elf_got_entry *ae, *be, **pbe, **start;
2094 start = &hashes[i]->got_entries;
2095 for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next)
2097 if (be->gotobj != b)
2100 for (ae = *start; ae ; ae = ae->next)
2101 if (ae->gotobj == a && ae->addend == be->addend)
2103 ae->flags |= be->flags;
2115 alpha_elf_tdata(a)->total_got_entries = total;
2116 alpha_elf_tdata(b)->gotobj = a;
2119 /* Calculate the offsets for the got entries. */
2122 elf64_alpha_calc_got_offsets_for_symbol (h, arg)
2123 struct alpha_elf_link_hash_entry *h;
2126 struct alpha_elf_got_entry *gotent;
2128 for (gotent = h->got_entries; gotent; gotent = gotent->next)
2130 bfd_size_type *plge = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size;
2131 gotent->got_offset = *plge;
2139 elf64_alpha_calc_got_offsets (info)
2140 struct bfd_link_info *info;
2142 bfd *i, *got_list = alpha_elf_hash_table(info)->got_list;
2144 /* First, zero out the .got sizes, as we may be recalculating the
2145 .got after optimizing it. */
2146 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
2147 alpha_elf_tdata(i)->got->_raw_size = 0;
2149 /* Next, fill in the offsets for all the global entries. */
2150 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
2151 elf64_alpha_calc_got_offsets_for_symbol,
2154 /* Finally, fill in the offsets for the local entries. */
2155 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
2157 bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size;
2160 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next)
2162 struct alpha_elf_got_entry **local_got_entries, *gotent;
2165 local_got_entries = alpha_elf_tdata(j)->local_got_entries;
2166 if (!local_got_entries)
2169 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k)
2170 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next)
2172 gotent->got_offset = got_offset;
2177 alpha_elf_tdata(i)->got->_raw_size = got_offset;
2181 /* Remove a section from the output BFD. */
2184 elf64_alpha_strip_section_from_output (s)
2189 for (spp = &s->output_section->owner->sections;
2190 *spp != s->output_section;
2191 spp = &(*spp)->next)
2193 *spp = s->output_section->next;
2194 --s->output_section->owner->section_count;
2197 /* Constructs the gots. */
2200 elf64_alpha_always_size_sections (output_bfd, info)
2202 struct bfd_link_info *info;
2204 bfd *i, *got_list, *cur_got_obj, **cur_got_tail;
2207 if (info->relocateable)
2213 cur_got_tail = NULL;
2214 for (i = info->input_bfds; i ; i = i->link_next)
2216 bfd *this_got = alpha_elf_tdata (i)->gotobj;
2218 /* Don't play if there is no .got for this input file. */
2219 if (this_got == NULL)
2222 if (alpha_elf_tdata (this_got)->total_got_entries > MAX_GOT_ENTRIES)
2224 /* Yikes! A single object file has too many entries. */
2225 (*_bfd_error_handler)
2226 ("%s: .got subsegment exceeds 64K (size %d)",
2227 bfd_get_filename(i),
2228 alpha_elf_tdata(this_got)->total_got_entries * 8);
2234 if (elf64_alpha_can_merge_gots (cur_got_obj, i))
2236 elf64_alpha_merge_gots (cur_got_obj, i);
2243 (*info->callbacks->warning)
2244 (info, "using multiple gp values", (char *) NULL,
2245 output_bfd, (asection *) NULL, (bfd_vma) 0);
2247 *cur_got_tail = NULL;
2248 alpha_elf_tdata(cur_got_obj)->got_link_next = got_list;
2249 got_list = cur_got_obj;
2258 cur_got_tail = &alpha_elf_tdata(i)->in_got_link_next;
2262 alpha_elf_tdata (cur_got_obj)->got_link_next = got_list;
2263 alpha_elf_hash_table (info)->got_list = got_list = cur_got_obj;
2265 /* Once the gots have been merged, fill in the got offsets for everything
2267 elf64_alpha_calc_got_offsets (info);
2269 /* Allocate space for all of the .got subsections. */
2270 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next)
2272 asection *s = alpha_elf_tdata(i)->got;
2273 if (s->_raw_size > 0)
2275 s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size);
2276 if (s->contents == NULL)
2284 /* Work out the sizes of the dynamic relocation entries. */
2287 elf64_alpha_calc_dynrel_sizes (h, info)
2288 struct alpha_elf_link_hash_entry *h;
2289 struct bfd_link_info *info;
2291 /* If the symbol was defined as a common symbol in a regular object
2292 file, and there was no definition in any dynamic object, then the
2293 linker will have allocated space for the symbol in a common
2294 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
2295 set. This is done for dynamic symbols in
2296 elf_adjust_dynamic_symbol but this is not done for non-dynamic
2297 symbols, somehow. */
2298 if (((h->root.elf_link_hash_flags
2299 & (ELF_LINK_HASH_DEF_REGULAR
2300 | ELF_LINK_HASH_REF_REGULAR
2301 | ELF_LINK_HASH_DEF_DYNAMIC))
2302 == ELF_LINK_HASH_REF_REGULAR)
2303 && (h->root.root.type == bfd_link_hash_defined
2304 || h->root.root.type == bfd_link_hash_defweak)
2305 && !(h->root.root.u.def.section->owner->flags & DYNAMIC))
2307 h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2310 /* If the symbol is dynamic, we'll need all the relocations in their
2311 natural form. If it has been forced local, we'll need the same
2312 number of RELATIVE relocations. */
2313 if (alpha_elf_dynamic_symbol_p (&h->root, info)
2314 || (info->shared && h->root.dynindx == -1))
2316 struct alpha_elf_reloc_entry *relent;
2318 for (relent = h->reloc_entries; relent; relent = relent->next)
2320 relent->srel->_raw_size +=
2321 sizeof (Elf64_External_Rela) * relent->count;
2324 /* Only add a .rela.got entry if we're not using a .plt entry. */
2325 if (h->root.plt_offset == MINUS_ONE)
2327 bfd *dynobj = elf_hash_table(info)->dynobj;
2328 struct alpha_elf_got_entry *gotent;
2329 bfd_size_type count = 0;
2332 for (gotent = h->got_entries; gotent ; gotent = gotent->next)
2336 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2337 BFD_ASSERT (srel != NULL);
2338 srel->_raw_size += sizeof (Elf64_External_Rela) * count;
2342 /* Otherwise, shared objects require RELATIVE relocs for all REFQUAD
2343 and REFLONG relocations. */
2344 else if (info->shared)
2346 struct alpha_elf_reloc_entry *relent;
2348 for (relent = h->reloc_entries; relent; relent = relent->next)
2349 if (relent->rtype == R_ALPHA_REFLONG
2350 || relent->rtype == R_ALPHA_REFQUAD)
2352 relent->srel->_raw_size +=
2353 sizeof(Elf64_External_Rela) * relent->count;
2360 /* Set the sizes of the dynamic sections. */
2363 elf64_alpha_size_dynamic_sections (output_bfd, info)
2365 struct bfd_link_info *info;
2372 dynobj = elf_hash_table(info)->dynobj;
2373 BFD_ASSERT(dynobj != NULL);
2375 if (elf_hash_table (info)->dynamic_sections_created)
2377 /* Set the contents of the .interp section to the interpreter. */
2380 s = bfd_get_section_by_name (dynobj, ".interp");
2381 BFD_ASSERT (s != NULL);
2382 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2383 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2386 /* Now that we've seen all of the input files, we can decide which
2387 symbols need dynamic relocation entries and which don't. We've
2388 collected information in check_relocs that we can now apply to
2389 size the dynamic relocation sections. */
2390 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info),
2391 elf64_alpha_calc_dynrel_sizes,
2394 /* When building shared libraries, each local .got entry needs a
2400 bfd_size_type count;
2402 srel = bfd_get_section_by_name (dynobj, ".rela.got");
2403 BFD_ASSERT (srel != NULL);
2405 for (i = alpha_elf_hash_table(info)->got_list, count = 0;
2407 i = alpha_elf_tdata(i)->got_link_next)
2408 count += alpha_elf_tdata(i)->n_local_got_entries;
2410 srel->_raw_size += count * sizeof(Elf64_External_Rela);
2413 /* else we're not dynamic and by definition we don't need such things. */
2415 /* The check_relocs and adjust_dynamic_symbol entry points have
2416 determined the sizes of the various dynamic sections. Allocate
2420 for (s = dynobj->sections; s != NULL; s = s->next)
2425 if (!(s->flags & SEC_LINKER_CREATED))
2428 /* It's OK to base decisions on the section name, because none
2429 of the dynobj section names depend upon the input files. */
2430 name = bfd_get_section_name (dynobj, s);
2432 /* If we don't need this section, strip it from the output file.
2433 This is to handle .rela.bss and .rela.plt. We must create it
2434 in create_dynamic_sections, because it must be created before
2435 the linker maps input sections to output sections. The
2436 linker does that before adjust_dynamic_symbol is called, and
2437 it is that function which decides whether anything needs to
2438 go into these sections. */
2442 if (strncmp (name, ".rela", 5) == 0)
2444 strip = (s->_raw_size == 0);
2448 const char *outname;
2451 /* If this relocation section applies to a read only
2452 section, then we probably need a DT_TEXTREL entry. */
2453 outname = bfd_get_section_name (output_bfd,
2455 target = bfd_get_section_by_name (output_bfd, outname + 5);
2457 && (target->flags & SEC_READONLY) != 0
2458 && (target->flags & SEC_ALLOC) != 0)
2461 if (strcmp(name, ".rela.plt") == 0)
2464 /* We use the reloc_count field as a counter if we need
2465 to copy relocs into the output file. */
2469 else if (strcmp (name, ".plt") != 0)
2471 /* It's not one of our dynamic sections, so don't allocate space. */
2476 elf64_alpha_strip_section_from_output (s);
2479 /* Allocate memory for the section contents. */
2480 s->contents = (bfd_byte *) bfd_zalloc(dynobj, s->_raw_size);
2481 if (s->contents == NULL && s->_raw_size != 0)
2486 /* If we are generating a shared library, we generate a section
2487 symbol for each output section. These are local symbols, which
2488 means that they must come first in the dynamic symbol table.
2489 That means we must increment the dynamic symbol index of every
2490 other dynamic symbol. */
2497 c[1] = bfd_count_sections (output_bfd);
2499 elf_hash_table (info)->dynsymcount += c[1];
2500 elf_link_hash_traverse (elf_hash_table(info),
2501 elf64_alpha_adjust_dynindx,
2504 for (i = 1, p = output_bfd->sections;
2508 elf_section_data (p)->dynindx = i;
2509 /* These symbols will have no names, so we don't need to
2510 fiddle with dynstr_index. */
2514 if (elf_hash_table (info)->dynamic_sections_created)
2516 /* Add some entries to the .dynamic section. We fill in the
2517 values later, in elf64_alpha_finish_dynamic_sections, but we
2518 must add the entries now so that we get the correct size for
2519 the .dynamic section. The DT_DEBUG entry is filled in by the
2520 dynamic linker and used by the debugger. */
2523 if (!bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
2527 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0))
2532 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
2533 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
2534 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
2538 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
2539 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
2540 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
2541 sizeof(Elf64_External_Rela)))
2546 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
2554 /* Increment the index of a dynamic symbol by a given amount. Called
2555 via elf_link_hash_traverse. */
2558 elf64_alpha_adjust_dynindx (h, cparg)
2559 struct elf_link_hash_entry *h;
2562 long *cp = (long *)cparg;
2564 if (h->dynindx >= cp[0])
2565 h->dynindx += cp[1];
2570 /* Relocate an Alpha ELF section. */
2573 elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section,
2574 contents, relocs, local_syms, local_sections)
2576 struct bfd_link_info *info;
2578 asection *input_section;
2580 Elf_Internal_Rela *relocs;
2581 Elf_Internal_Sym *local_syms;
2582 asection **local_sections;
2584 Elf_Internal_Shdr *symtab_hdr;
2585 Elf_Internal_Rela *rel;
2586 Elf_Internal_Rela *relend;
2587 asection *sec, *sgot, *srel, *srelgot;
2588 bfd *dynobj, *gotobj;
2591 srelgot = srel = NULL;
2592 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2593 dynobj = elf_hash_table (info)->dynobj;
2596 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2599 /* Find the gp value for this input bfd. */
2602 gotobj = alpha_elf_tdata (input_bfd)->gotobj;
2605 sgot = alpha_elf_tdata (gotobj)->got;
2606 gp = _bfd_get_gp_value (gotobj);
2609 gp = (sgot->output_section->vma
2610 + sgot->output_offset
2612 _bfd_set_gp_value (gotobj, gp);
2617 relend = relocs + input_section->reloc_count;
2618 for (; rel < relend; rel++)
2621 reloc_howto_type *howto;
2622 unsigned long r_symndx;
2623 struct alpha_elf_link_hash_entry *h;
2624 Elf_Internal_Sym *sym;
2627 bfd_reloc_status_type r;
2629 r_type = ELF64_R_TYPE(rel->r_info);
2630 if (r_type < 0 || r_type >= (int) R_ALPHA_max)
2632 bfd_set_error (bfd_error_bad_value);
2635 howto = elf64_alpha_howto_table + r_type;
2637 r_symndx = ELF64_R_SYM(rel->r_info);
2639 if (info->relocateable)
2641 /* This is a relocateable link. We don't have to change
2642 anything, unless the reloc is against a section symbol,
2643 in which case we have to adjust according to where the
2644 section symbol winds up in the output section. */
2645 if (r_symndx < symtab_hdr->sh_info)
2647 sym = local_syms + r_symndx;
2648 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
2650 sec = local_sections[r_symndx];
2651 rel->r_addend += sec->output_offset + sym->st_value;
2658 /* This is a final link. */
2664 if (r_symndx < symtab_hdr->sh_info)
2666 sym = local_syms + r_symndx;
2667 sec = local_sections[r_symndx];
2668 relocation = (sec->output_section->vma
2669 + sec->output_offset
2674 h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info];
2676 while (h->root.root.type == bfd_link_hash_indirect
2677 || h->root.root.type == bfd_link_hash_warning)
2678 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link;
2680 if (h->root.root.type == bfd_link_hash_defined
2681 || h->root.root.type == bfd_link_hash_defweak)
2683 sec = h->root.root.u.def.section;
2686 if ((r_type == R_ALPHA_LITERAL
2687 && elf_hash_table(info)->dynamic_sections_created
2690 || !(h->root.elf_link_hash_flags
2691 & ELF_LINK_HASH_DEF_REGULAR)))
2694 || !(h->root.elf_link_hash_flags
2695 & ELF_LINK_HASH_DEF_REGULAR))
2696 && (input_section->flags & SEC_ALLOC)
2697 && (r_type == R_ALPHA_REFLONG
2698 || r_type == R_ALPHA_REFQUAD
2699 || r_type == R_ALPHA_LITERAL)))
2701 /* In these cases, we don't need the relocation value.
2702 We check specially because in some obscure cases
2703 sec->output_section will be NULL. */
2707 /* FIXME: Are not these obscure cases simply bugs? Let's
2708 get something working and come back to this. */
2709 if (sec->output_section == NULL)
2711 #endif /* rth_notdef */
2714 relocation = (h->root.root.u.def.value
2715 + sec->output_section->vma
2716 + sec->output_offset);
2719 else if (h->root.root.type == bfd_link_hash_undefweak)
2721 else if (info->shared && !info->symbolic)
2725 if (!((*info->callbacks->undefined_symbol)
2726 (info, h->root.root.root.string, input_bfd,
2727 input_section, rel->r_offset)))
2732 addend = rel->r_addend;
2736 case R_ALPHA_GPDISP:
2738 bfd_byte *p_ldah, *p_lda;
2740 BFD_ASSERT(gp != 0);
2742 relocation = (input_section->output_section->vma
2743 + input_section->output_offset
2746 p_ldah = contents + rel->r_offset - input_section->vma;
2747 p_lda = p_ldah + rel->r_addend;
2749 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - relocation,
2754 case R_ALPHA_OP_PUSH:
2755 case R_ALPHA_OP_STORE:
2756 case R_ALPHA_OP_PSUB:
2757 case R_ALPHA_OP_PRSHIFT:
2758 /* We hate these silly beasts. */
2761 case R_ALPHA_LITERAL:
2763 struct alpha_elf_got_entry *gotent;
2765 BFD_ASSERT(sgot != NULL);
2766 BFD_ASSERT(gp != 0);
2770 gotent = h->got_entries;
2772 /* We may be looking at a default versioned symbol, which
2773 won't have the got entries we set up earlier. Go find
2777 struct alpha_elf_link_hash_entry *v;
2781 p = strchr (h->root.root.root.string, ELF_VER_CHR);
2782 BFD_ASSERT (p != NULL && p[1] == ELF_VER_CHR);
2784 len = p - h->root.root.root.string;
2785 name = bfd_malloc (len + 1);
2788 memcpy (name, h->root.root.root.string, len);
2791 v = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
2792 name, false, false, false);
2793 BFD_ASSERT (v != NULL);
2794 while (v->got_entries == NULL)
2796 BFD_ASSERT (v->root.root.type==bfd_link_hash_indirect);
2797 v = (struct alpha_elf_link_hash_entry *)
2798 v->root.root.u.i.link;
2800 gotent = v->got_entries;
2804 while (gotent->gotobj != gotobj || gotent->addend != addend)
2805 gotent = gotent->next;
2807 /* Initialize the .got entry's value. */
2808 if (!(gotent->flags & ALPHA_ELF_GOT_ENTRY_RELOCS_DONE))
2810 bfd_put_64 (output_bfd, relocation+addend,
2811 sgot->contents + gotent->got_offset);
2813 /* If the symbol has been forced local, output a
2814 RELATIVE reloc, otherwise it will be handled in
2815 finish_dynamic_symbol. */
2816 if (info->shared && h->root.dynindx == -1)
2818 Elf_Internal_Rela outrel;
2820 BFD_ASSERT(srelgot != NULL);
2822 outrel.r_offset = (sgot->output_section->vma
2823 + sgot->output_offset
2824 + gotent->got_offset);
2825 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2826 outrel.r_addend = 0;
2828 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2829 ((Elf64_External_Rela *)
2831 + srelgot->reloc_count++);
2834 gotent->flags |= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE;
2839 gotent = (alpha_elf_tdata(input_bfd)->
2840 local_got_entries[r_symndx]);
2841 while (gotent->addend != addend)
2842 gotent = gotent->next;
2844 if (!(gotent->flags & ALPHA_ELF_GOT_ENTRY_RELOCS_DONE))
2846 bfd_put_64 (output_bfd, relocation+addend,
2847 sgot->contents + gotent->got_offset);
2849 /* Local got entries need RELATIVE relocs in shared
2853 Elf_Internal_Rela outrel;
2855 BFD_ASSERT(srelgot != NULL);
2857 outrel.r_offset = (sgot->output_section->vma
2858 + sgot->output_offset
2859 + gotent->got_offset);
2860 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2861 outrel.r_addend = 0;
2863 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2864 ((Elf64_External_Rela *)
2866 + srelgot->reloc_count++);
2869 gotent->flags |= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE;
2873 /* Figure the gprel relocation. */
2875 relocation = (sgot->output_section->vma
2876 + sgot->output_offset
2877 + gotent->got_offset);
2880 /* overflow handled by _bfd_final_link_relocate */
2883 case R_ALPHA_GPREL32:
2884 BFD_ASSERT(gp != 0);
2888 case R_ALPHA_BRADDR:
2890 /* The regular PC-relative stuff measures from the start of
2891 the instruction rather than the end. */
2895 case R_ALPHA_REFLONG:
2896 case R_ALPHA_REFQUAD:
2898 Elf_Internal_Rela outrel;
2901 /* Careful here to remember RELATIVE relocations for global
2902 variables for symbolic shared objects. */
2904 if (h && alpha_elf_dynamic_symbol_p (&h->root, info))
2906 BFD_ASSERT(h->root.dynindx != -1);
2907 outrel.r_info = ELF64_R_INFO(h->root.dynindx, r_type);
2908 outrel.r_addend = addend;
2909 addend = 0, relocation = 0;
2911 else if (info->shared)
2913 outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE);
2914 outrel.r_addend = 0;
2923 name = (bfd_elf_string_from_elf_section
2924 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx,
2925 elf_section_data(input_section)->rel_hdr.sh_name));
2926 BFD_ASSERT(name != NULL);
2928 srel = bfd_get_section_by_name (dynobj, name);
2929 BFD_ASSERT(srel != NULL);
2934 if (elf_section_data (input_section)->stab_info == NULL)
2935 outrel.r_offset = rel->r_offset;
2940 off = (_bfd_stab_section_offset
2941 (output_bfd, &elf_hash_table (info)->stab_info,
2943 &elf_section_data (input_section)->stab_info,
2945 if (off == (bfd_vma) -1)
2947 outrel.r_offset = off;
2951 outrel.r_offset += (input_section->output_section->vma
2952 + input_section->output_offset);
2954 memset (&outrel, 0, sizeof outrel);
2956 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
2957 ((Elf64_External_Rela *)
2959 + srel->reloc_count++);
2965 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2966 contents, rel->r_offset, relocation,
2976 case bfd_reloc_overflow:
2981 name = h->root.root.root.string;
2984 name = (bfd_elf_string_from_elf_section
2985 (input_bfd, symtab_hdr->sh_link, sym->st_name));
2989 name = bfd_section_name (input_bfd, sec);
2991 if (! ((*info->callbacks->reloc_overflow)
2992 (info, name, howto->name, (bfd_vma) 0,
2993 input_bfd, input_section, rel->r_offset)))
2999 case bfd_reloc_outofrange:
3007 /* Finish up dynamic symbol handling. We set the contents of various
3008 dynamic sections here. */
3011 elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym)
3013 struct bfd_link_info *info;
3014 struct elf_link_hash_entry *h;
3015 Elf_Internal_Sym *sym;
3017 bfd *dynobj = elf_hash_table(info)->dynobj;
3019 if (h->plt_offset != MINUS_ONE)
3021 /* Fill in the .plt entry for this symbol. */
3022 asection *splt, *sgot, *srel;
3023 Elf_Internal_Rela outrel;
3024 bfd_vma got_addr, plt_addr;
3026 struct alpha_elf_got_entry *gotent;
3028 BFD_ASSERT (h->dynindx != -1);
3030 /* The first .got entry will be updated by the .plt with the
3031 address of the target function. */
3032 gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
3033 BFD_ASSERT (gotent && gotent->addend == 0);
3035 splt = bfd_get_section_by_name (dynobj, ".plt");
3036 BFD_ASSERT (splt != NULL);
3037 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
3038 BFD_ASSERT (srel != NULL);
3039 sgot = alpha_elf_tdata (gotent->gotobj)->got;
3040 BFD_ASSERT (sgot != NULL);
3042 got_addr = (sgot->output_section->vma
3043 + sgot->output_offset
3044 + gotent->got_offset);
3045 plt_addr = (splt->output_section->vma
3046 + splt->output_offset
3049 plt_index = (h->plt_offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
3051 /* Fill in the entry in the procedure linkage table. */
3053 unsigned insn1, insn2, insn3;
3055 insn1 = PLT_ENTRY_WORD1 | ((-(h->plt_offset + 4) >> 2) & 0x1fffff);
3056 insn2 = PLT_ENTRY_WORD2;
3057 insn3 = PLT_ENTRY_WORD3;
3059 bfd_put_32 (output_bfd, insn1, splt->contents + h->plt_offset);
3060 bfd_put_32 (output_bfd, insn2, splt->contents + h->plt_offset + 4);
3061 bfd_put_32 (output_bfd, insn3, splt->contents + h->plt_offset + 8);
3064 /* Fill in the entry in the .rela.plt section. */
3065 outrel.r_offset = got_addr;
3066 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT);
3067 outrel.r_addend = 0;
3069 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3070 ((Elf64_External_Rela *)srel->contents
3073 if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
3075 /* Mark the symbol as undefined, rather than as defined in the
3076 .plt section. Leave the value alone. */
3077 sym->st_shndx = SHN_UNDEF;
3080 /* Fill in the entries in the .got. */
3081 bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset);
3083 /* Subsequent .got entries will continue to bounce through the .plt. */
3084 while ((gotent = gotent->next) != NULL)
3086 sgot = alpha_elf_tdata(gotent->gotobj)->got;
3087 BFD_ASSERT(sgot != NULL);
3088 BFD_ASSERT(gotent->addend == 0);
3090 bfd_put_64 (output_bfd, plt_addr,
3091 sgot->contents + gotent->got_offset);
3094 else if (alpha_elf_dynamic_symbol_p (h, info))
3096 /* Fill in the dynamic relocations for this symbol's .got entries. */
3098 Elf_Internal_Rela outrel;
3099 struct alpha_elf_got_entry *gotent;
3101 srel = bfd_get_section_by_name (dynobj, ".rela.got");
3102 BFD_ASSERT (srel != NULL);
3104 outrel.r_info = ELF64_R_INFO (h->dynindx, R_ALPHA_GLOB_DAT);
3105 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries;
3107 gotent = gotent->next)
3109 asection *sgot = alpha_elf_tdata (gotent->gotobj)->got;
3110 outrel.r_offset = (sgot->output_section->vma
3111 + sgot->output_offset
3112 + gotent->got_offset);
3113 outrel.r_addend = gotent->addend;
3115 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3116 ((Elf64_External_Rela *)srel->contents
3117 + srel->reloc_count++));
3121 /* Mark some specially defined symbols as absolute. */
3122 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3123 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3124 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3125 sym->st_shndx = SHN_ABS;
3130 /* Finish up the dynamic sections. */
3133 elf64_alpha_finish_dynamic_sections (output_bfd, info)
3135 struct bfd_link_info *info;
3140 dynobj = elf_hash_table (info)->dynobj;
3141 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3143 if (elf_hash_table (info)->dynamic_sections_created)
3146 Elf64_External_Dyn *dyncon, *dynconend;
3148 splt = bfd_get_section_by_name (dynobj, ".plt");
3149 BFD_ASSERT (splt != NULL && sdyn != NULL);
3151 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3152 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3153 for (; dyncon < dynconend; dyncon++)
3155 Elf_Internal_Dyn dyn;
3159 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3174 /* My interpretation of the TIS v1.1 ELF document indicates
3175 that RELASZ should not include JMPREL. This is not what
3176 the rest of the BFD does. It is, however, what the
3177 glibc ld.so wants. Do this fixup here until we found
3178 out who is right. */
3179 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3183 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
3188 s = bfd_get_section_by_name (output_bfd, name);
3189 dyn.d_un.d_ptr = (s ? s->vma : 0);
3193 s = bfd_get_section_by_name (output_bfd, name);
3195 (s->_cooked_size ? s->_cooked_size : s->_raw_size);
3199 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3202 /* Initialize the PLT0 entry */
3203 if (splt->_raw_size > 0)
3205 bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents);
3206 bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4);
3207 bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8);
3208 bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12);
3210 /* The next two words will be filled in by ld.so */
3211 bfd_put_64 (output_bfd, 0, splt->contents + 16);
3212 bfd_put_64 (output_bfd, 0, splt->contents + 24);
3214 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
3223 Elf_Internal_Sym sym;
3225 /* Set up the section symbols for the output sections. */
3227 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
3228 BFD_ASSERT (sdynsym != NULL);
3232 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
3235 for (s = output_bfd->sections; s != NULL; s = s->next)
3239 sym.st_value = s->vma;
3241 indx = elf_section_data (s)->this_idx;
3242 BFD_ASSERT (indx > 0);
3243 sym.st_shndx = indx;
3245 bfd_elf64_swap_symbol_out (output_bfd, &sym,
3246 (PTR) (((Elf64_External_Sym *)
3248 + elf_section_data (s)->dynindx));
3251 /* Set the sh_info field of the output .dynsym section to the
3252 index of the first global symbol. */
3253 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
3254 bfd_count_sections (output_bfd) + 1;
3260 /* We need to use a special link routine to handle the .reginfo and
3261 the .mdebug sections. We need to merge all instances of these
3262 sections together, not write them all out sequentially. */
3265 elf64_alpha_final_link (abfd, info)
3267 struct bfd_link_info *info;
3270 struct bfd_link_order *p;
3271 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
3272 struct ecoff_debug_info debug;
3273 const struct ecoff_debug_swap *swap
3274 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
3275 HDRR *symhdr = &debug.symbolic_header;
3276 PTR mdebug_handle = NULL;
3278 /* Go through the sections and collect the .reginfo and .mdebug
3282 gptab_data_sec = NULL;
3283 gptab_bss_sec = NULL;
3284 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3286 #ifdef ERIC_neverdef
3287 if (strcmp (o->name, ".reginfo") == 0)
3289 memset (®info, 0, sizeof reginfo);
3291 /* We have found the .reginfo section in the output file.
3292 Look through all the link_orders comprising it and merge
3293 the information together. */
3294 for (p = o->link_order_head;
3295 p != (struct bfd_link_order *) NULL;
3298 asection *input_section;
3300 Elf64_External_RegInfo ext;
3303 if (p->type != bfd_indirect_link_order)
3305 if (p->type == bfd_fill_link_order)
3310 input_section = p->u.indirect.section;
3311 input_bfd = input_section->owner;
3313 /* The linker emulation code has probably clobbered the
3314 size to be zero bytes. */
3315 if (input_section->_raw_size == 0)
3316 input_section->_raw_size = sizeof (Elf64_External_RegInfo);
3318 if (! bfd_get_section_contents (input_bfd, input_section,
3324 bfd_alpha_elf64_swap_reginfo_in (input_bfd, &ext, &sub);
3326 reginfo.ri_gprmask |= sub.ri_gprmask;
3327 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
3328 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
3329 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
3330 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
3332 /* ri_gp_value is set by the function
3333 alpha_elf_section_processing when the section is
3334 finally written out. */
3336 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3337 elf_link_input_bfd ignores this section. */
3338 input_section->flags &=~ SEC_HAS_CONTENTS;
3341 /* Force the section size to the value we want. */
3342 o->_raw_size = sizeof (Elf64_External_RegInfo);
3344 /* Skip this section later on (I don't think this currently
3345 matters, but someday it might). */
3346 o->link_order_head = (struct bfd_link_order *) NULL;
3352 if (strcmp (o->name, ".mdebug") == 0)
3354 struct extsym_info einfo;
3356 /* We have found the .mdebug section in the output file.
3357 Look through all the link_orders comprising it and merge
3358 the information together. */
3359 symhdr->magic = swap->sym_magic;
3360 /* FIXME: What should the version stamp be? */
3362 symhdr->ilineMax = 0;
3366 symhdr->isymMax = 0;
3367 symhdr->ioptMax = 0;
3368 symhdr->iauxMax = 0;
3370 symhdr->issExtMax = 0;
3373 symhdr->iextMax = 0;
3375 /* We accumulate the debugging information itself in the
3376 debug_info structure. */
3378 debug.external_dnr = NULL;
3379 debug.external_pdr = NULL;
3380 debug.external_sym = NULL;
3381 debug.external_opt = NULL;
3382 debug.external_aux = NULL;
3384 debug.ssext = debug.ssext_end = NULL;
3385 debug.external_fdr = NULL;
3386 debug.external_rfd = NULL;
3387 debug.external_ext = debug.external_ext_end = NULL;
3389 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
3390 if (mdebug_handle == (PTR) NULL)
3399 static const char * const name[] =
3401 ".text", ".init", ".fini", ".data",
3402 ".rodata", ".sdata", ".sbss", ".bss"
3404 static const int sc[] = { scText, scInit, scFini, scData,
3405 scRData, scSData, scSBss, scBss };
3408 esym.cobol_main = 0;
3412 esym.asym.iss = issNil;
3413 esym.asym.st = stLocal;
3414 esym.asym.reserved = 0;
3415 esym.asym.index = indexNil;
3416 for (i = 0; i < 8; i++)
3418 esym.asym.sc = sc[i];
3419 s = bfd_get_section_by_name (abfd, name[i]);
3422 esym.asym.value = s->vma;
3423 last = s->vma + s->_raw_size;
3426 esym.asym.value = last;
3428 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap,
3434 for (p = o->link_order_head;
3435 p != (struct bfd_link_order *) NULL;
3438 asection *input_section;
3440 const struct ecoff_debug_swap *input_swap;
3441 struct ecoff_debug_info input_debug;
3445 if (p->type != bfd_indirect_link_order)
3447 if (p->type == bfd_fill_link_order)
3452 input_section = p->u.indirect.section;
3453 input_bfd = input_section->owner;
3455 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
3456 || (get_elf_backend_data (input_bfd)
3457 ->elf_backend_ecoff_debug_swap) == NULL)
3459 /* I don't know what a non ALPHA ELF bfd would be
3460 doing with a .mdebug section, but I don't really
3461 want to deal with it. */
3465 input_swap = (get_elf_backend_data (input_bfd)
3466 ->elf_backend_ecoff_debug_swap);
3468 BFD_ASSERT (p->size == input_section->_raw_size);
3470 /* The ECOFF linking code expects that we have already
3471 read in the debugging information and set up an
3472 ecoff_debug_info structure, so we do that now. */
3473 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section,
3477 if (! (bfd_ecoff_debug_accumulate
3478 (mdebug_handle, abfd, &debug, swap, input_bfd,
3479 &input_debug, input_swap, info)))
3482 /* Loop through the external symbols. For each one with
3483 interesting information, try to find the symbol in
3484 the linker global hash table and save the information
3485 for the output external symbols. */
3486 eraw_src = input_debug.external_ext;
3487 eraw_end = (eraw_src
3488 + (input_debug.symbolic_header.iextMax
3489 * input_swap->external_ext_size));
3491 eraw_src < eraw_end;
3492 eraw_src += input_swap->external_ext_size)
3496 struct alpha_elf_link_hash_entry *h;
3498 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
3499 if (ext.asym.sc == scNil
3500 || ext.asym.sc == scUndefined
3501 || ext.asym.sc == scSUndefined)
3504 name = input_debug.ssext + ext.asym.iss;
3505 h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info),
3506 name, false, false, true);
3507 if (h == NULL || h->esym.ifd != -2)
3513 < input_debug.symbolic_header.ifdMax);
3514 ext.ifd = input_debug.ifdmap[ext.ifd];
3520 /* Free up the information we just read. */
3521 free (input_debug.line);
3522 free (input_debug.external_dnr);
3523 free (input_debug.external_pdr);
3524 free (input_debug.external_sym);
3525 free (input_debug.external_opt);
3526 free (input_debug.external_aux);
3527 free (input_debug.ss);
3528 free (input_debug.ssext);
3529 free (input_debug.external_fdr);
3530 free (input_debug.external_rfd);
3531 free (input_debug.external_ext);
3533 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3534 elf_link_input_bfd ignores this section. */
3535 input_section->flags &=~ SEC_HAS_CONTENTS;
3538 #ifdef ERIC_neverdef
3541 /* Create .rtproc section. */
3542 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc");
3543 if (rtproc_sec == NULL)
3545 flagword flags = (SEC_HAS_CONTENTS
3547 | SEC_LINKER_CREATED
3550 rtproc_sec = bfd_make_section (abfd, ".rtproc");
3551 if (rtproc_sec == NULL
3552 || ! bfd_set_section_flags (abfd, rtproc_sec, flags)
3553 || ! bfd_set_section_alignment (abfd, rtproc_sec, 12))
3557 if (! alpha_elf_create_procedure_table (mdebug_handle, abfd,
3558 info, rtproc_sec, &debug))
3564 /* Build the external symbol information. */
3567 einfo.debug = &debug;
3569 einfo.failed = false;
3570 elf_link_hash_traverse (elf_hash_table (info),
3571 elf64_alpha_output_extsym,
3576 /* Set the size of the .mdebug section. */
3577 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
3579 /* Skip this section later on (I don't think this currently
3580 matters, but someday it might). */
3581 o->link_order_head = (struct bfd_link_order *) NULL;
3586 #ifdef ERIC_neverdef
3587 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
3589 const char *subname;
3592 Elf64_External_gptab *ext_tab;
3595 /* The .gptab.sdata and .gptab.sbss sections hold
3596 information describing how the small data area would
3597 change depending upon the -G switch. These sections
3598 not used in executables files. */
3599 if (! info->relocateable)
3603 for (p = o->link_order_head;
3604 p != (struct bfd_link_order *) NULL;
3607 asection *input_section;
3609 if (p->type != bfd_indirect_link_order)
3611 if (p->type == bfd_fill_link_order)
3616 input_section = p->u.indirect.section;
3618 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3619 elf_link_input_bfd ignores this section. */
3620 input_section->flags &=~ SEC_HAS_CONTENTS;
3623 /* Skip this section later on (I don't think this
3624 currently matters, but someday it might). */
3625 o->link_order_head = (struct bfd_link_order *) NULL;
3627 /* Really remove the section. */
3628 for (secpp = &abfd->sections;
3630 secpp = &(*secpp)->next)
3632 *secpp = (*secpp)->next;
3633 --abfd->section_count;
3638 /* There is one gptab for initialized data, and one for
3639 uninitialized data. */
3640 if (strcmp (o->name, ".gptab.sdata") == 0)
3642 else if (strcmp (o->name, ".gptab.sbss") == 0)
3646 (*_bfd_error_handler)
3647 ("%s: illegal section name `%s'",
3648 bfd_get_filename (abfd), o->name);
3649 bfd_set_error (bfd_error_nonrepresentable_section);
3653 /* The linker script always combines .gptab.data and
3654 .gptab.sdata into .gptab.sdata, and likewise for
3655 .gptab.bss and .gptab.sbss. It is possible that there is
3656 no .sdata or .sbss section in the output file, in which
3657 case we must change the name of the output section. */
3658 subname = o->name + sizeof ".gptab" - 1;
3659 if (bfd_get_section_by_name (abfd, subname) == NULL)
3661 if (o == gptab_data_sec)
3662 o->name = ".gptab.data";
3664 o->name = ".gptab.bss";
3665 subname = o->name + sizeof ".gptab" - 1;
3666 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
3669 /* Set up the first entry. */
3671 tab = (Elf64_gptab *) bfd_malloc (c * sizeof (Elf64_gptab));
3674 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
3675 tab[0].gt_header.gt_unused = 0;
3677 /* Combine the input sections. */
3678 for (p = o->link_order_head;
3679 p != (struct bfd_link_order *) NULL;
3682 asection *input_section;
3686 bfd_size_type gpentry;
3688 if (p->type != bfd_indirect_link_order)
3690 if (p->type == bfd_fill_link_order)
3695 input_section = p->u.indirect.section;
3696 input_bfd = input_section->owner;
3698 /* Combine the gptab entries for this input section one
3699 by one. We know that the input gptab entries are
3700 sorted by ascending -G value. */
3701 size = bfd_section_size (input_bfd, input_section);
3703 for (gpentry = sizeof (Elf64_External_gptab);
3705 gpentry += sizeof (Elf64_External_gptab))
3707 Elf64_External_gptab ext_gptab;
3708 Elf64_gptab int_gptab;
3714 if (! (bfd_get_section_contents
3715 (input_bfd, input_section, (PTR) &ext_gptab,
3716 gpentry, sizeof (Elf64_External_gptab))))
3722 bfd_alpha_elf64_swap_gptab_in (input_bfd, &ext_gptab,
3724 val = int_gptab.gt_entry.gt_g_value;
3725 add = int_gptab.gt_entry.gt_bytes - last;
3728 for (look = 1; look < c; look++)
3730 if (tab[look].gt_entry.gt_g_value >= val)
3731 tab[look].gt_entry.gt_bytes += add;
3733 if (tab[look].gt_entry.gt_g_value == val)
3739 Elf64_gptab *new_tab;
3742 /* We need a new table entry. */
3743 new_tab = ((Elf64_gptab *)
3744 bfd_realloc ((PTR) tab,
3745 (c + 1) * sizeof (Elf64_gptab)));
3746 if (new_tab == NULL)
3752 tab[c].gt_entry.gt_g_value = val;
3753 tab[c].gt_entry.gt_bytes = add;
3755 /* Merge in the size for the next smallest -G
3756 value, since that will be implied by this new
3759 for (look = 1; look < c; look++)
3761 if (tab[look].gt_entry.gt_g_value < val
3763 || (tab[look].gt_entry.gt_g_value
3764 > tab[max].gt_entry.gt_g_value)))
3768 tab[c].gt_entry.gt_bytes +=
3769 tab[max].gt_entry.gt_bytes;
3774 last = int_gptab.gt_entry.gt_bytes;
3777 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3778 elf_link_input_bfd ignores this section. */
3779 input_section->flags &=~ SEC_HAS_CONTENTS;
3782 /* The table must be sorted by -G value. */
3784 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
3786 /* Swap out the table. */
3787 ext_tab = ((Elf64_External_gptab *)
3788 bfd_alloc (abfd, c * sizeof (Elf64_External_gptab)));
3789 if (ext_tab == NULL)
3795 for (i = 0; i < c; i++)
3796 bfd_alpha_elf64_swap_gptab_out (abfd, tab + i, ext_tab + i);
3799 o->_raw_size = c * sizeof (Elf64_External_gptab);
3800 o->contents = (bfd_byte *) ext_tab;
3802 /* Skip this section later on (I don't think this currently
3803 matters, but someday it might). */
3804 o->link_order_head = (struct bfd_link_order *) NULL;
3810 /* Invoke the regular ELF backend linker to do all the work. */
3811 if (! bfd_elf64_bfd_final_link (abfd, info))
3814 /* Now write out the computed sections. */
3816 /* The .got subsections... */
3818 bfd *i, *dynobj = elf_hash_table(info)->dynobj;
3819 for (i = alpha_elf_hash_table(info)->got_list;
3821 i = alpha_elf_tdata(i)->got_link_next)
3825 /* elf_bfd_final_link already did everything in dynobj. */
3829 sgot = alpha_elf_tdata(i)->got;
3830 if (! bfd_set_section_contents (abfd, sgot->output_section,
3831 sgot->contents, sgot->output_offset,
3837 #ifdef ERIC_neverdef
3838 if (reginfo_sec != (asection *) NULL)
3840 Elf64_External_RegInfo ext;
3842 bfd_alpha_elf64_swap_reginfo_out (abfd, ®info, &ext);
3843 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
3844 (file_ptr) 0, sizeof ext))
3849 if (mdebug_sec != (asection *) NULL)
3851 BFD_ASSERT (abfd->output_has_begun);
3852 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
3854 mdebug_sec->filepos))
3857 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
3860 if (gptab_data_sec != (asection *) NULL)
3862 if (! bfd_set_section_contents (abfd, gptab_data_sec,
3863 gptab_data_sec->contents,
3865 gptab_data_sec->_raw_size))
3869 if (gptab_bss_sec != (asection *) NULL)
3871 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
3872 gptab_bss_sec->contents,
3874 gptab_bss_sec->_raw_size))
3881 /* ECOFF swapping routines. These are used when dealing with the
3882 .mdebug section, which is in the ECOFF debugging format. Copied
3883 from elf32-mips.c. */
3884 static const struct ecoff_debug_swap
3885 elf64_alpha_ecoff_debug_swap =
3887 /* Symbol table magic number. */
3889 /* Alignment of debugging information. E.g., 4. */
3891 /* Sizes of external symbolic information. */
3892 sizeof (struct hdr_ext),
3893 sizeof (struct dnr_ext),
3894 sizeof (struct pdr_ext),
3895 sizeof (struct sym_ext),
3896 sizeof (struct opt_ext),
3897 sizeof (struct fdr_ext),
3898 sizeof (struct rfd_ext),
3899 sizeof (struct ext_ext),
3900 /* Functions to swap in external symbolic data. */
3909 _bfd_ecoff_swap_tir_in,
3910 _bfd_ecoff_swap_rndx_in,
3911 /* Functions to swap out external symbolic data. */
3920 _bfd_ecoff_swap_tir_out,
3921 _bfd_ecoff_swap_rndx_out,
3922 /* Function to read in symbolic data. */
3923 elf64_alpha_read_ecoff_info
3926 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
3927 #define TARGET_LITTLE_NAME "elf64-alpha"
3928 #define ELF_ARCH bfd_arch_alpha
3929 #define ELF_MACHINE_CODE EM_ALPHA
3930 #define ELF_MAXPAGESIZE 0x100000
3932 #define bfd_elf64_bfd_link_hash_table_create \
3933 elf64_alpha_bfd_link_hash_table_create
3935 #define bfd_elf64_bfd_reloc_type_lookup \
3936 elf64_alpha_bfd_reloc_type_lookup
3937 #define elf_info_to_howto \
3938 elf64_alpha_info_to_howto
3940 #define bfd_elf64_mkobject \
3941 elf64_alpha_mkobject
3942 #define elf_backend_object_p \
3943 elf64_alpha_object_p
3945 #define elf_backend_section_from_shdr \
3946 elf64_alpha_section_from_shdr
3947 #define elf_backend_fake_sections \
3948 elf64_alpha_fake_sections
3949 #define elf_backend_additional_program_headers \
3950 elf64_alpha_additional_program_headers
3952 #define bfd_elf64_bfd_is_local_label_name \
3953 elf64_alpha_is_local_label_name
3954 #define bfd_elf64_find_nearest_line \
3955 elf64_alpha_find_nearest_line
3957 #define elf_backend_check_relocs \
3958 elf64_alpha_check_relocs
3959 #define elf_backend_create_dynamic_sections \
3960 elf64_alpha_create_dynamic_sections
3961 #define elf_backend_adjust_dynamic_symbol \
3962 elf64_alpha_adjust_dynamic_symbol
3963 #define elf_backend_always_size_sections \
3964 elf64_alpha_always_size_sections
3965 #define elf_backend_size_dynamic_sections \
3966 elf64_alpha_size_dynamic_sections
3967 #define elf_backend_relocate_section \
3968 elf64_alpha_relocate_section
3969 #define elf_backend_finish_dynamic_symbol \
3970 elf64_alpha_finish_dynamic_symbol
3971 #define elf_backend_finish_dynamic_sections \
3972 elf64_alpha_finish_dynamic_sections
3973 #define bfd_elf64_bfd_final_link \
3974 elf64_alpha_final_link
3976 #define elf_backend_ecoff_debug_swap \
3977 &elf64_alpha_ecoff_debug_swap
3980 * A few constants that determine how the .plt section is set up.
3982 #define elf_backend_want_got_plt 0
3983 #define elf_backend_plt_readonly 0
3984 #define elf_backend_want_plt_sym 1
3986 #include "elf64-target.h"