1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Richard Henderson <rth@tamu.edu>.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* We need a published ABI spec for this. Until one comes out, don't
22 assume this'll remain unchanged forever. */
29 #include "elf/alpha.h"
33 #define NO_COFF_RELOCS
34 #define NO_COFF_SYMBOLS
35 #define NO_COFF_LINENOS
37 /* Get the ECOFF swapping routines. Needed for the debug information. */
38 #include "coff/internal.h"
40 #include "coff/symconst.h"
41 #include "coff/ecoff.h"
42 #include "coff/alpha.h"
47 #include "ecoffswap.h"
49 static boolean elf64_alpha_mkobject
PARAMS ((bfd
*));
50 static struct bfd_hash_entry
* elf64_alpha_link_hash_newfunc
51 PARAMS((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
52 static struct bfd_link_hash_table
* elf64_alpha_bfd_link_hash_table_create
55 static bfd_reloc_status_type elf64_alpha_reloc_nil
56 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
57 static bfd_reloc_status_type elf64_alpha_reloc_bad
58 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
59 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
60 PARAMS((bfd
*, bfd_vma
, bfd_byte
*, bfd_byte
*));
61 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
62 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
64 static reloc_howto_type
* elf64_alpha_bfd_reloc_type_lookup
65 PARAMS((bfd
*, bfd_reloc_code_real_type
));
66 static void elf64_alpha_info_to_howto
67 PARAMS((bfd
*, arelent
*, Elf64_Internal_Rela
*));
69 static boolean elf64_alpha_object_p
71 static boolean elf64_alpha_section_from_shdr
72 PARAMS((bfd
*, Elf64_Internal_Shdr
*, char *));
73 static boolean elf64_alpha_fake_sections
74 PARAMS((bfd
*, Elf64_Internal_Shdr
*, asection
*));
75 static int elf64_alpha_additional_program_headers
77 static boolean elf64_alpha_create_got_section
78 PARAMS((bfd
*, struct bfd_link_info
*));
79 static boolean elf64_alpha_create_dynamic_sections
80 PARAMS((bfd
*, struct bfd_link_info
*));
82 static boolean elf64_alpha_read_ecoff_info
83 PARAMS((bfd
*, asection
*, struct ecoff_debug_info
*));
84 static boolean elf64_alpha_is_local_label_name
85 PARAMS((bfd
*, const char *));
86 static boolean elf64_alpha_find_nearest_line
87 PARAMS((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
88 const char **, unsigned int *));
90 #if defined(__STDC__) || defined(ALMOST_STDC)
91 struct alpha_elf_link_hash_entry
;
94 static boolean elf64_alpha_output_extsym
95 PARAMS((struct alpha_elf_link_hash_entry
*, PTR
));
97 static boolean elf64_alpha_can_merge_gots
98 PARAMS((bfd
*, bfd
*));
99 static void elf64_alpha_merge_gots
100 PARAMS((bfd
*, bfd
*));
101 static boolean elf64_alpha_calc_got_offsets_for_symbol
102 PARAMS ((struct alpha_elf_link_hash_entry
*, PTR
));
103 static void elf64_alpha_calc_got_offsets
PARAMS ((struct bfd_link_info
*));
104 static void elf64_alpha_strip_section_from_output
PARAMS ((asection
*));
105 static boolean elf64_alpha_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
)
333 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
334 from smaller values. Start with zero, widen, *then* decrement. */
335 #define MINUS_ONE (((bfd_vma)0) - 1)
337 static reloc_howto_type elf64_alpha_howto_table
[] =
339 HOWTO (R_ALPHA_NONE
, /* type */
341 0, /* size (0 = byte, 1 = short, 2 = long) */
343 true, /* pc_relative */
345 complain_overflow_dont
, /* complain_on_overflow */
346 elf64_alpha_reloc_nil
, /* special_function */
348 false, /* partial_inplace */
351 true), /* pcrel_offset */
353 /* A 32 bit reference to a symbol. */
354 HOWTO (R_ALPHA_REFLONG
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 false, /* pc_relative */
360 complain_overflow_bitfield
, /* complain_on_overflow */
361 0, /* special_function */
362 "REFLONG", /* name */
363 false, /* partial_inplace */
364 0xffffffff, /* src_mask */
365 0xffffffff, /* dst_mask */
366 false), /* pcrel_offset */
368 /* A 64 bit reference to a symbol. */
369 HOWTO (R_ALPHA_REFQUAD
, /* type */
371 4, /* size (0 = byte, 1 = short, 2 = long) */
373 false, /* pc_relative */
375 complain_overflow_bitfield
, /* complain_on_overflow */
376 0, /* special_function */
377 "REFQUAD", /* name */
378 false, /* partial_inplace */
379 MINUS_ONE
, /* src_mask */
380 MINUS_ONE
, /* dst_mask */
381 false), /* pcrel_offset */
383 /* A 32 bit GP relative offset. This is just like REFLONG except
384 that when the value is used the value of the gp register will be
386 HOWTO (R_ALPHA_GPREL32
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 false, /* pc_relative */
392 complain_overflow_bitfield
, /* complain_on_overflow */
393 0, /* special_function */
394 "GPREL32", /* name */
395 false, /* partial_inplace */
396 0xffffffff, /* src_mask */
397 0xffffffff, /* dst_mask */
398 false), /* pcrel_offset */
400 /* Used for an instruction that refers to memory off the GP register. */
401 HOWTO (R_ALPHA_LITERAL
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 false, /* pc_relative */
407 complain_overflow_signed
, /* complain_on_overflow */
408 0, /* special_function */
409 "ELF_LITERAL", /* name */
410 false, /* partial_inplace */
411 0xffff, /* src_mask */
412 0xffff, /* dst_mask */
413 false), /* pcrel_offset */
415 /* This reloc only appears immediately following an ELF_LITERAL reloc.
416 It identifies a use of the literal. The symbol index is special:
417 1 means the literal address is in the base register of a memory
418 format instruction; 2 means the literal address is in the byte
419 offset register of a byte-manipulation instruction; 3 means the
420 literal address is in the target register of a jsr instruction.
421 This does not actually do any relocation. */
422 HOWTO (R_ALPHA_LITUSE
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_dont
, /* complain_on_overflow */
429 elf64_alpha_reloc_nil
, /* special_function */
431 false, /* partial_inplace */
434 false), /* pcrel_offset */
436 /* Load the gp register. This is always used for a ldah instruction
437 which loads the upper 16 bits of the gp register. The symbol
438 index of the GPDISP instruction is an offset in bytes to the lda
439 instruction that loads the lower 16 bits. The value to use for
440 the relocation is the difference between the GP value and the
441 current location; the load will always be done against a register
442 holding the current address.
444 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
445 any offset is present in the instructions, it is an offset from
446 the register to the ldah instruction. This lets us avoid any
447 stupid hackery like inventing a gp value to do partial relocation
448 against. Also unlike ECOFF, we do the whole relocation off of
449 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
450 space consuming bit, that, since all the information was present
451 in the GPDISP_HI16 reloc. */
452 HOWTO (R_ALPHA_GPDISP
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 false, /* pc_relative */
458 complain_overflow_dont
, /* complain_on_overflow */
459 elf64_alpha_reloc_gpdisp
, /* special_function */
461 false, /* partial_inplace */
462 0xffff, /* src_mask */
463 0xffff, /* dst_mask */
464 true), /* pcrel_offset */
466 /* A 21 bit branch. */
467 HOWTO (R_ALPHA_BRADDR
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 true, /* pc_relative */
473 complain_overflow_signed
, /* complain_on_overflow */
474 0, /* special_function */
476 false, /* partial_inplace */
477 0x1fffff, /* src_mask */
478 0x1fffff, /* dst_mask */
479 true), /* pcrel_offset */
481 /* A hint for a jump to a register. */
482 HOWTO (R_ALPHA_HINT
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 true, /* pc_relative */
488 complain_overflow_dont
, /* complain_on_overflow */
489 0, /* special_function */
491 false, /* partial_inplace */
492 0x3fff, /* src_mask */
493 0x3fff, /* dst_mask */
494 true), /* pcrel_offset */
496 /* 16 bit PC relative offset. */
497 HOWTO (R_ALPHA_SREL16
, /* type */
499 1, /* size (0 = byte, 1 = short, 2 = long) */
501 true, /* pc_relative */
503 complain_overflow_signed
, /* complain_on_overflow */
504 0, /* special_function */
506 false, /* partial_inplace */
507 0xffff, /* src_mask */
508 0xffff, /* dst_mask */
509 false), /* pcrel_offset */
511 /* 32 bit PC relative offset. */
512 HOWTO (R_ALPHA_SREL32
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 true, /* pc_relative */
518 complain_overflow_signed
, /* complain_on_overflow */
519 0, /* special_function */
521 false, /* partial_inplace */
522 0xffffffff, /* src_mask */
523 0xffffffff, /* dst_mask */
524 false), /* pcrel_offset */
526 /* A 64 bit PC relative offset. */
527 HOWTO (R_ALPHA_SREL64
, /* type */
529 4, /* size (0 = byte, 1 = short, 2 = long) */
531 true, /* pc_relative */
533 complain_overflow_signed
, /* complain_on_overflow */
534 0, /* special_function */
536 false, /* partial_inplace */
537 MINUS_ONE
, /* src_mask */
538 MINUS_ONE
, /* dst_mask */
539 false), /* pcrel_offset */
541 /* Push a value on the reloc evaluation stack. */
542 HOWTO (ALPHA_R_OP_PUSH
, /* type */
544 0, /* size (0 = byte, 1 = short, 2 = long) */
546 false, /* pc_relative */
548 complain_overflow_dont
, /* complain_on_overflow */
549 elf64_alpha_reloc_bad
, /* special_function */
550 "OP_PUSH", /* name */
551 false, /* partial_inplace */
554 false), /* pcrel_offset */
556 /* Store the value from the stack at the given address. Store it in
557 a bitfield of size r_size starting at bit position r_offset. */
558 HOWTO (ALPHA_R_OP_STORE
, /* type */
560 4, /* size (0 = byte, 1 = short, 2 = long) */
562 false, /* pc_relative */
564 complain_overflow_dont
, /* complain_on_overflow */
565 elf64_alpha_reloc_bad
, /* special_function */
566 "OP_STORE", /* name */
567 false, /* partial_inplace */
569 MINUS_ONE
, /* dst_mask */
570 false), /* pcrel_offset */
572 /* Subtract the reloc address from the value on the top of the
574 HOWTO (ALPHA_R_OP_PSUB
, /* type */
576 0, /* size (0 = byte, 1 = short, 2 = long) */
578 false, /* pc_relative */
580 complain_overflow_dont
, /* complain_on_overflow */
581 elf64_alpha_reloc_bad
, /* special_function */
582 "OP_PSUB", /* name */
583 false, /* partial_inplace */
586 false), /* pcrel_offset */
588 /* Shift the value on the top of the relocation stack right by the
590 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
592 0, /* size (0 = byte, 1 = short, 2 = long) */
594 false, /* pc_relative */
596 complain_overflow_dont
, /* complain_on_overflow */
597 elf64_alpha_reloc_bad
, /* special_function */
598 "OP_PRSHIFT", /* name */
599 false, /* partial_inplace */
602 false), /* pcrel_offset */
604 /* Misc ELF relocations. */
611 complain_overflow_dont
,
612 bfd_elf_generic_reloc
,
619 HOWTO (R_ALPHA_GLOB_DAT
,
625 complain_overflow_dont
,
626 bfd_elf_generic_reloc
,
633 HOWTO (R_ALPHA_JMP_SLOT
,
639 complain_overflow_dont
,
640 bfd_elf_generic_reloc
,
647 HOWTO (R_ALPHA_RELATIVE
,
653 complain_overflow_dont
,
654 bfd_elf_generic_reloc
,
662 /* A relocation function which doesn't do anything. */
664 static bfd_reloc_status_type
665 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
672 char **error_message
;
675 reloc
->address
+= sec
->output_offset
;
679 /* A relocation function used for an unsupported reloc. */
681 static bfd_reloc_status_type
682 elf64_alpha_reloc_bad (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
689 char **error_message
;
692 reloc
->address
+= sec
->output_offset
;
693 return bfd_reloc_notsupported
;
696 /* Do the work of the GPDISP relocation. */
698 static bfd_reloc_status_type
699 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
705 bfd_reloc_status_type ret
= bfd_reloc_ok
;
707 unsigned long i_ldah
, i_lda
;
709 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
710 i_lda
= bfd_get_32 (abfd
, p_lda
);
712 /* Complain if the instructions are not correct. */
713 if (((i_ldah
>> 26) & 0x3f) != 0x09
714 || ((i_lda
>> 26) & 0x3f) != 0x08)
715 ret
= bfd_reloc_dangerous
;
717 /* Extract the user-supplied offset, mirroring the sign extensions
718 that the instructions perform. */
719 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
720 addend
= (addend
^ 0x80008000) - 0x80008000;
724 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
)0x80000000
725 || gpdisp
>= 0x7fff8000)
726 ret
= bfd_reloc_overflow
;
728 /* compensate for the sign extension again. */
729 i_ldah
= ((i_ldah
& 0xffff0000)
730 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
731 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
733 bfd_put_32 (abfd
, i_ldah
, p_ldah
);
734 bfd_put_32 (abfd
, i_lda
, p_lda
);
739 /* The special function for the GPDISP reloc. */
741 static bfd_reloc_status_type
742 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
745 arelent
*reloc_entry
;
748 asection
*input_section
;
752 bfd_reloc_status_type ret
;
753 bfd_vma gp
, relocation
;
754 bfd_byte
*p_ldah
, *p_lda
;
756 /* Don't do anything if we're not doing a final link. */
759 reloc_entry
->address
+= input_section
->output_offset
;
763 if (reloc_entry
->address
> input_section
->_cooked_size
||
764 reloc_entry
->address
+ reloc_entry
->addend
> input_section
->_cooked_size
)
765 return bfd_reloc_outofrange
;
767 /* The gp used in the portion of the output object to which this
768 input object belongs is cached on the input bfd. */
769 gp
= _bfd_get_gp_value (abfd
);
771 relocation
= (input_section
->output_section
->vma
772 + input_section
->output_offset
773 + reloc_entry
->address
);
775 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
776 p_lda
= p_ldah
+ reloc_entry
->addend
;
778 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
780 /* Complain if the instructions are not correct. */
781 if (ret
== bfd_reloc_dangerous
)
782 *err_msg
= "GPDISP relocation did not find ldah and lda instructions";
787 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
791 bfd_reloc_code_real_type bfd_reloc_val
;
795 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
797 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
798 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
799 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
800 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
801 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
802 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
803 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
804 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
805 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
806 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
807 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
808 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
809 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
812 /* Given a BFD reloc type, return a HOWTO structure. */
814 static reloc_howto_type
*
815 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
817 bfd_reloc_code_real_type code
;
819 const struct elf_reloc_map
*i
, *e
;
820 i
= e
= elf64_alpha_reloc_map
;
821 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
824 if (i
->bfd_reloc_val
== code
)
825 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
830 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
833 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
836 Elf64_Internal_Rela
*dst
;
840 r_type
= ELF64_R_TYPE(dst
->r_info
);
841 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
842 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
846 #define PLT_HEADER_SIZE 32
847 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
848 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
849 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
850 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
852 #define PLT_ENTRY_SIZE 12
853 #define PLT_ENTRY_WORD1 0x279f0000 /* ldah $28, 0($31) */
854 #define PLT_ENTRY_WORD2 0x239c0000 /* lda $28, 0($28) */
855 #define PLT_ENTRY_WORD3 0xc3e00000 /* br $31, plt0 */
857 #define MAX_GOT_ENTRIES (64*1024 / 8)
859 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
861 /* Set the right machine number for an Alpha ELF file. */
864 elf64_alpha_object_p (abfd
)
867 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
870 /* Handle an Alpha specific section when reading an object file. This
871 is called when elfcode.h finds a section with an unknown type.
872 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
876 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
878 Elf64_Internal_Shdr
*hdr
;
883 /* There ought to be a place to keep ELF backend specific flags, but
884 at the moment there isn't one. We just keep track of the
885 sections by their name, instead. Fortunately, the ABI gives
886 suggested names for all the MIPS specific sections, so we will
887 probably get away with this. */
888 switch (hdr
->sh_type
)
890 case SHT_ALPHA_DEBUG
:
891 if (strcmp (name
, ".mdebug") != 0)
895 case SHT_ALPHA_REGINFO
:
896 if (strcmp (name
, ".reginfo") != 0
897 || hdr
->sh_size
!= sizeof (Elf64_External_RegInfo
))
905 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
907 newsect
= hdr
->bfd_section
;
909 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
911 if (! bfd_set_section_flags (abfd
, newsect
,
912 (bfd_get_section_flags (abfd
, newsect
)
918 /* For a .reginfo section, set the gp value in the tdata information
919 from the contents of this section. We need the gp value while
920 processing relocs, so we just get it now. */
921 if (hdr
->sh_type
== SHT_ALPHA_REGINFO
)
923 Elf64_External_RegInfo ext
;
926 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
927 (file_ptr
) 0, sizeof ext
))
929 bfd_alpha_elf64_swap_reginfo_in (abfd
, &ext
, &s
);
930 elf_gp (abfd
) = s
.ri_gp_value
;
937 /* Set the correct type for an Alpha ELF section. We do this by the
938 section name, which is a hack, but ought to work. */
941 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
943 Elf64_Internal_Shdr
*hdr
;
946 register const char *name
;
948 name
= bfd_get_section_name (abfd
, sec
);
950 if (strcmp (name
, ".mdebug") == 0)
952 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
953 /* In a shared object on Irix 5.3, the .mdebug section has an
954 entsize of 0. FIXME: Does this matter? */
955 if ((abfd
->flags
& DYNAMIC
) != 0 )
961 else if (strcmp (name
, ".reginfo") == 0)
963 hdr
->sh_type
= SHT_ALPHA_REGINFO
;
964 /* In a shared object on Irix 5.3, the .reginfo section has an
965 entsize of 0x18. FIXME: Does this matter? */
966 if ((abfd
->flags
& DYNAMIC
) != 0)
967 hdr
->sh_entsize
= sizeof (Elf64_External_RegInfo
);
971 /* Force the section size to the correct value, even if the
972 linker thinks it is larger. The link routine below will only
973 write out this much data for .reginfo. */
974 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf64_External_RegInfo
);
976 else if (strcmp (name
, ".hash") == 0
977 || strcmp (name
, ".dynamic") == 0
978 || strcmp (name
, ".dynstr") == 0)
981 hdr
->sh_info
= SIZEOF_ALPHA_DYNSYM_SECNAMES
;
984 else if (strcmp (name
, ".sdata") == 0
985 || strcmp (name
, ".sbss") == 0
986 || strcmp (name
, ".lit4") == 0
987 || strcmp (name
, ".lit8") == 0)
988 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
993 /* Return the number of additional phdrs we will need. */
996 elf64_alpha_additional_program_headers (abfd
)
1004 s
= bfd_get_section_by_name (abfd
, ".reginfo");
1005 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
1007 /* We need a PT_ALPHA_REGINFO segment. */
1011 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
1012 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
1014 /* We need a PT_ALPHA_RTPROC segment. */
1021 /* Create the .got section. */
1024 elf64_alpha_create_got_section(abfd
, info
)
1026 struct bfd_link_info
*info
;
1030 if (bfd_get_section_by_name (abfd
, ".got"))
1033 s
= bfd_make_section (abfd
, ".got");
1035 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1038 | SEC_LINKER_CREATED
))
1039 || !bfd_set_section_alignment (abfd
, s
, 3))
1042 alpha_elf_tdata (abfd
)->got
= s
;
1047 /* Create all the dynamic sections. */
1050 elf64_alpha_create_dynamic_sections (abfd
, info
)
1052 struct bfd_link_info
*info
;
1055 struct elf_link_hash_entry
*h
;
1057 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1059 s
= bfd_make_section (abfd
, ".plt");
1061 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1064 | SEC_LINKER_CREATED
1066 || ! bfd_set_section_alignment (abfd
, s
, 3))
1069 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1072 if (! (_bfd_generic_link_add_one_symbol
1073 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
1074 (bfd_vma
) 0, (const char *) NULL
, false,
1075 get_elf_backend_data (abfd
)->collect
,
1076 (struct bfd_link_hash_entry
**) &h
)))
1078 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1079 h
->type
= STT_OBJECT
;
1082 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1085 s
= bfd_make_section (abfd
, ".rela.plt");
1087 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1090 | SEC_LINKER_CREATED
1092 || ! bfd_set_section_alignment (abfd
, s
, 3))
1095 /* We may or may not have created a .got section for this object, but
1096 we definitely havn't done the rest of the work. */
1098 if (!elf64_alpha_create_got_section (abfd
, info
))
1101 s
= bfd_make_section(abfd
, ".rela.got");
1103 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1106 | SEC_LINKER_CREATED
1108 || !bfd_set_section_alignment (abfd
, s
, 3))
1111 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1112 dynobj's .got section. We don't do this in the linker script
1113 because we don't want to define the symbol if we are not creating
1114 a global offset table. */
1116 if (!(_bfd_generic_link_add_one_symbol
1117 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
,
1118 alpha_elf_tdata(abfd
)->got
, (bfd_vma
) 0, (const char *) NULL
,
1119 false, get_elf_backend_data (abfd
)->collect
,
1120 (struct bfd_link_hash_entry
**) &h
)))
1122 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1123 h
->type
= STT_OBJECT
;
1126 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1129 elf_hash_table (info
)->hgot
= h
;
1134 /* Read ECOFF debugging information from a .mdebug section into a
1135 ecoff_debug_info structure. */
1138 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
1141 struct ecoff_debug_info
*debug
;
1144 const struct ecoff_debug_swap
*swap
;
1145 char *ext_hdr
= NULL
;
1147 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1149 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
1150 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1153 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1154 swap
->external_hdr_size
)
1158 symhdr
= &debug
->symbolic_header
;
1159 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1161 /* The symbolic header contains absolute file offsets and sizes to
1163 #define READ(ptr, offset, count, size, type) \
1164 if (symhdr->count == 0) \
1165 debug->ptr = NULL; \
1168 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1169 if (debug->ptr == NULL) \
1170 goto error_return; \
1171 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1172 || (bfd_read (debug->ptr, size, symhdr->count, \
1173 abfd) != size * symhdr->count)) \
1174 goto error_return; \
1177 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1178 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1179 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1180 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1181 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1182 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1184 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1185 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1186 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
1187 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
1188 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
1192 debug
->adjust
= NULL
;
1197 if (ext_hdr
!= NULL
)
1199 if (debug
->line
!= NULL
)
1201 if (debug
->external_dnr
!= NULL
)
1202 free (debug
->external_dnr
);
1203 if (debug
->external_pdr
!= NULL
)
1204 free (debug
->external_pdr
);
1205 if (debug
->external_sym
!= NULL
)
1206 free (debug
->external_sym
);
1207 if (debug
->external_opt
!= NULL
)
1208 free (debug
->external_opt
);
1209 if (debug
->external_aux
!= NULL
)
1210 free (debug
->external_aux
);
1211 if (debug
->ss
!= NULL
)
1213 if (debug
->ssext
!= NULL
)
1214 free (debug
->ssext
);
1215 if (debug
->external_fdr
!= NULL
)
1216 free (debug
->external_fdr
);
1217 if (debug
->external_rfd
!= NULL
)
1218 free (debug
->external_rfd
);
1219 if (debug
->external_ext
!= NULL
)
1220 free (debug
->external_ext
);
1224 /* Alpha ELF local labels start with '$'. */
1227 elf64_alpha_is_local_label_name (abfd
, name
)
1231 return name
[0] == '$';
1234 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1235 routine in order to handle the ECOFF debugging information. We
1236 still call this mips_elf_find_line because of the slot
1237 find_line_info in elf_obj_tdata is declared that way. */
1239 struct mips_elf_find_line
1241 struct ecoff_debug_info d
;
1242 struct ecoff_find_line i
;
1246 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
1247 functionname_ptr
, line_ptr
)
1252 const char **filename_ptr
;
1253 const char **functionname_ptr
;
1254 unsigned int *line_ptr
;
1258 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
1262 struct mips_elf_find_line
*fi
;
1263 const struct ecoff_debug_swap
* const swap
=
1264 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1266 /* If we are called during a link, alpha_elf_final_link may have
1267 cleared the SEC_HAS_CONTENTS field. We force it back on here
1268 if appropriate (which it normally will be). */
1269 origflags
= msec
->flags
;
1270 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
1271 msec
->flags
|= SEC_HAS_CONTENTS
;
1273 fi
= elf_tdata (abfd
)->find_line_info
;
1276 bfd_size_type external_fdr_size
;
1279 struct fdr
*fdr_ptr
;
1281 fi
= ((struct mips_elf_find_line
*)
1282 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
1285 msec
->flags
= origflags
;
1289 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
1291 msec
->flags
= origflags
;
1295 /* Swap in the FDR information. */
1296 fi
->d
.fdr
= ((struct fdr
*)
1298 (fi
->d
.symbolic_header
.ifdMax
*
1299 sizeof (struct fdr
))));
1300 if (fi
->d
.fdr
== NULL
)
1302 msec
->flags
= origflags
;
1305 external_fdr_size
= swap
->external_fdr_size
;
1306 fdr_ptr
= fi
->d
.fdr
;
1307 fraw_src
= (char *) fi
->d
.external_fdr
;
1308 fraw_end
= (fraw_src
1309 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
1310 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
1311 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
1313 elf_tdata (abfd
)->find_line_info
= fi
;
1315 /* Note that we don't bother to ever free this information.
1316 find_nearest_line is either called all the time, as in
1317 objdump -l, so the information should be saved, or it is
1318 rarely called, as in ld error messages, so the memory
1319 wasted is unimportant. Still, it would probably be a
1320 good idea for free_cached_info to throw it away. */
1323 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
1324 &fi
->i
, filename_ptr
, functionname_ptr
,
1327 msec
->flags
= origflags
;
1331 msec
->flags
= origflags
;
1334 /* Fall back on the generic ELF find_nearest_line routine. */
1336 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
1337 filename_ptr
, functionname_ptr
,
1341 /* Structure used to pass information to alpha_elf_output_extsym. */
1346 struct bfd_link_info
*info
;
1347 struct ecoff_debug_info
*debug
;
1348 const struct ecoff_debug_swap
*swap
;
1353 elf64_alpha_output_extsym (h
, data
)
1354 struct alpha_elf_link_hash_entry
*h
;
1357 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1359 asection
*sec
, *output_section
;
1361 if (h
->root
.indx
== -2)
1363 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1364 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1365 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1366 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1368 else if (einfo
->info
->strip
== strip_all
1369 || (einfo
->info
->strip
== strip_some
1370 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1371 h
->root
.root
.root
.string
,
1372 false, false) == NULL
))
1380 if (h
->esym
.ifd
== -2)
1383 h
->esym
.cobol_main
= 0;
1384 h
->esym
.weakext
= 0;
1385 h
->esym
.reserved
= 0;
1386 h
->esym
.ifd
= ifdNil
;
1387 h
->esym
.asym
.value
= 0;
1388 h
->esym
.asym
.st
= stGlobal
;
1390 if (h
->root
.root
.type
!= bfd_link_hash_defined
1391 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1392 h
->esym
.asym
.sc
= scAbs
;
1397 sec
= h
->root
.root
.u
.def
.section
;
1398 output_section
= sec
->output_section
;
1400 /* When making a shared library and symbol h is the one from
1401 the another shared library, OUTPUT_SECTION may be null. */
1402 if (output_section
== NULL
)
1403 h
->esym
.asym
.sc
= scUndefined
;
1406 name
= bfd_section_name (output_section
->owner
, output_section
);
1408 if (strcmp (name
, ".text") == 0)
1409 h
->esym
.asym
.sc
= scText
;
1410 else if (strcmp (name
, ".data") == 0)
1411 h
->esym
.asym
.sc
= scData
;
1412 else if (strcmp (name
, ".sdata") == 0)
1413 h
->esym
.asym
.sc
= scSData
;
1414 else if (strcmp (name
, ".rodata") == 0
1415 || strcmp (name
, ".rdata") == 0)
1416 h
->esym
.asym
.sc
= scRData
;
1417 else if (strcmp (name
, ".bss") == 0)
1418 h
->esym
.asym
.sc
= scBss
;
1419 else if (strcmp (name
, ".sbss") == 0)
1420 h
->esym
.asym
.sc
= scSBss
;
1421 else if (strcmp (name
, ".init") == 0)
1422 h
->esym
.asym
.sc
= scInit
;
1423 else if (strcmp (name
, ".fini") == 0)
1424 h
->esym
.asym
.sc
= scFini
;
1426 h
->esym
.asym
.sc
= scAbs
;
1430 h
->esym
.asym
.reserved
= 0;
1431 h
->esym
.asym
.index
= indexNil
;
1434 if (h
->root
.root
.type
== bfd_link_hash_common
)
1435 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1436 else if (h
->root
.root
.type
== bfd_link_hash_defined
1437 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1439 if (h
->esym
.asym
.sc
== scCommon
)
1440 h
->esym
.asym
.sc
= scBss
;
1441 else if (h
->esym
.asym
.sc
== scSCommon
)
1442 h
->esym
.asym
.sc
= scSBss
;
1444 sec
= h
->root
.root
.u
.def
.section
;
1445 output_section
= sec
->output_section
;
1446 if (output_section
!= NULL
)
1447 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1448 + sec
->output_offset
1449 + output_section
->vma
);
1451 h
->esym
.asym
.value
= 0;
1453 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1455 /* Set type and value for a symbol with a function stub. */
1456 h
->esym
.asym
.st
= stProc
;
1457 sec
= bfd_get_section_by_name (einfo
->abfd
, ".plt");
1459 h
->esym
.asym
.value
= 0;
1462 output_section
= sec
->output_section
;
1463 if (output_section
!= NULL
)
1464 h
->esym
.asym
.value
= (h
->root
.plt_offset
1465 + sec
->output_offset
1466 + output_section
->vma
);
1468 h
->esym
.asym
.value
= 0;
1475 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1476 h
->root
.root
.root
.string
,
1479 einfo
->failed
= true;
1486 /* FIXME: Create a runtime procedure table from the .mdebug section.
1489 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
1492 struct bfd_link_info *info;
1494 struct ecoff_debug_info *debug;
1497 /* Handle dynamic relocations when doing an Alpha ELF link. */
1500 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
1502 struct bfd_link_info
*info
;
1504 const Elf_Internal_Rela
*relocs
;
1508 const char *rel_sec_name
;
1509 Elf_Internal_Shdr
*symtab_hdr
;
1510 struct alpha_elf_link_hash_entry
**sym_hashes
;
1511 struct alpha_elf_got_entry
**local_got_entries
;
1512 const Elf_Internal_Rela
*rel
, *relend
;
1515 if (info
->relocateable
)
1518 dynobj
= elf_hash_table(info
)->dynobj
;
1520 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
1523 rel_sec_name
= NULL
;
1524 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
1525 sym_hashes
= alpha_elf_sym_hashes(abfd
);
1526 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
1529 relend
= relocs
+ sec
->reloc_count
;
1530 for (rel
= relocs
; rel
< relend
; ++rel
)
1532 unsigned long r_symndx
, r_type
;
1533 struct alpha_elf_link_hash_entry
*h
;
1535 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1536 if (r_symndx
< symtab_hdr
->sh_info
)
1540 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1541 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
1543 r_type
= ELF64_R_TYPE (rel
->r_info
);
1547 case R_ALPHA_LITERAL
:
1549 struct alpha_elf_got_entry
*gotent
;
1554 /* Search for and possibly create a got entry. */
1555 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
1556 if (gotent
->gotobj
== abfd
&&
1557 gotent
->addend
== rel
->r_addend
)
1562 gotent
= ((struct alpha_elf_got_entry
*)
1564 sizeof (struct alpha_elf_got_entry
)));
1568 gotent
->gotobj
= abfd
;
1569 gotent
->addend
= rel
->r_addend
;
1570 gotent
->got_offset
= -1;
1573 gotent
->next
= h
->got_entries
;
1574 h
->got_entries
= gotent
;
1576 alpha_elf_tdata (abfd
)->total_got_entries
++;
1581 /* This is a local .got entry -- record for merge. */
1582 if (!local_got_entries
)
1585 size
= (symtab_hdr
->sh_info
1586 * sizeof (struct alpha_elf_got_entry
*));
1588 local_got_entries
= ((struct alpha_elf_got_entry
**)
1589 bfd_alloc (abfd
, size
));
1590 if (!local_got_entries
)
1593 memset (local_got_entries
, 0, size
);
1594 alpha_elf_tdata (abfd
)->local_got_entries
=
1598 for (gotent
= local_got_entries
[ELF64_R_SYM(rel
->r_info
)];
1599 gotent
!= NULL
&& gotent
->addend
!= rel
->r_addend
;
1600 gotent
= gotent
->next
)
1604 gotent
= ((struct alpha_elf_got_entry
*)
1606 sizeof (struct alpha_elf_got_entry
)));
1610 gotent
->gotobj
= abfd
;
1611 gotent
->addend
= rel
->r_addend
;
1612 gotent
->got_offset
= -1;
1615 gotent
->next
= local_got_entries
[ELF64_R_SYM(rel
->r_info
)];
1616 local_got_entries
[ELF64_R_SYM(rel
->r_info
)] = gotent
;
1618 alpha_elf_tdata(abfd
)->total_got_entries
++;
1619 alpha_elf_tdata(abfd
)->n_local_got_entries
++;
1623 /* Remember how this literal is used from its LITUSEs.
1624 This will be important when it comes to decide if we can
1625 create a .plt entry for a function symbol. */
1627 && ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
)
1632 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 3)
1633 flags
|= 1 << rel
->r_addend
;
1635 while (rel
+1 < relend
&&
1636 ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
);
1640 /* No LITUSEs -- presumably the address is not being
1641 loaded for nothing. */
1642 flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
1645 gotent
->flags
|= flags
;
1648 /* Make a guess as to whether a .plt entry will be needed. */
1649 if ((h
->flags
|= flags
) == ALPHA_ELF_LINK_HASH_LU_FUNC
)
1650 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1652 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1657 case R_ALPHA_GPDISP
:
1658 case R_ALPHA_GPREL32
:
1659 /* We don't actually use the .got here, but the sections must
1660 be created before the linker maps input sections to output
1664 if (!elf64_alpha_create_got_section (abfd
, info
))
1667 /* Make sure the object's gotobj is set to itself so
1668 that we default to every object with its own .got.
1669 We'll merge .gots later once we've collected each
1671 alpha_elf_tdata(abfd
)->gotobj
= abfd
;
1677 case R_ALPHA_SREL16
:
1678 case R_ALPHA_SREL32
:
1679 case R_ALPHA_SREL64
:
1684 case R_ALPHA_REFLONG
:
1685 case R_ALPHA_REFQUAD
:
1686 if (rel_sec_name
== NULL
)
1688 rel_sec_name
= (bfd_elf_string_from_elf_section
1689 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1690 elf_section_data(sec
)->rel_hdr
.sh_name
));
1691 if (rel_sec_name
== NULL
)
1694 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
1695 && strcmp (bfd_get_section_name (abfd
, sec
),
1696 rel_sec_name
+5) == 0);
1699 /* We need to create the section here now whether we eventually
1700 use it or not so that it gets mapped to an output section by
1701 the linker. If not used, we'll kill it in
1702 size_dynamic_sections. */
1705 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
1708 sreloc
= bfd_make_section (dynobj
, rel_sec_name
);
1710 || !bfd_set_section_flags (dynobj
, sreloc
,
1714 | SEC_LINKER_CREATED
1716 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
1723 /* Since we havn't seen all of the input symbols yet, we
1724 don't know whether we'll actually need a dynamic relocation
1725 entry for this reloc. So make a record of it. Once we
1726 find out if this thing needs dynamic relocation we'll
1727 expand the relocation sections by the appropriate amount. */
1729 struct alpha_elf_reloc_entry
*rent
;
1731 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
1732 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
1737 rent
= ((struct alpha_elf_reloc_entry
*)
1739 sizeof (struct alpha_elf_reloc_entry
)));
1743 rent
->srel
= sreloc
;
1744 rent
->rtype
= r_type
;
1747 rent
->next
= h
->reloc_entries
;
1748 h
->reloc_entries
= rent
;
1753 else if (info
->shared
)
1755 /* If this is a shared library, we need a RELATIVE reloc. */
1756 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
1765 /* Adjust a symbol defined by a dynamic object and referenced by a
1766 regular object. The current definition is in some section of the
1767 dynamic object, but we're not including those sections. We have to
1768 change the definition to something the rest of the link can
1772 elf64_alpha_adjust_dynamic_symbol (info
, h
)
1773 struct bfd_link_info
*info
;
1774 struct elf_link_hash_entry
*h
;
1778 struct alpha_elf_link_hash_entry
*ah
;
1780 dynobj
= elf_hash_table(info
)->dynobj
;
1781 ah
= (struct alpha_elf_link_hash_entry
*)h
;
1783 /* Now that we've seen all of the input symbols, finalize our decision
1784 about whether this symbol should get a .plt entry. */
1786 if (h
->root
.type
!= bfd_link_hash_undefweak
1787 && alpha_elf_dynamic_symbol_p (h
, info
)
1788 && (h
->type
== STT_FUNC
1789 || (h
->type
== STT_NOTYPE
1790 && ah
->flags
== ALPHA_ELF_LINK_HASH_LU_FUNC
))
1791 /* Don't prevent otherwise valid programs from linking by attempting
1792 to create a new .got entry somewhere. A Correct Solution would be
1793 to add a new .got section to a new object file and let it be merged
1794 somewhere later. But for now don't bother. */
1797 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1799 s
= bfd_get_section_by_name(dynobj
, ".plt");
1800 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
1803 /* The first bit of the .plt is reserved. */
1804 if (s
->_raw_size
== 0)
1805 s
->_raw_size
= PLT_HEADER_SIZE
;
1807 h
->plt_offset
= s
->_raw_size
;
1808 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1810 /* If this symbol is not defined in a regular file, and we are not
1811 generating a shared library, then set the symbol to the location
1812 in the .plt. This is required to make function pointers compare
1813 equal between the normal executable and the shared library. */
1816 h
->root
.u
.def
.section
= s
;
1817 h
->root
.u
.def
.value
= h
->plt_offset
;
1820 /* We also need a JMP_SLOT entry in the .rela.plt section. */
1821 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1822 BFD_ASSERT (s
!= NULL
);
1823 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
1828 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1830 /* If this is a weak symbol, and there is a real definition, the
1831 processor independent code will have arranged for us to see the
1832 real definition first, and we can just use the same value. */
1833 if (h
->weakdef
!= NULL
)
1835 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1836 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1837 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1838 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1842 /* This is a reference to a symbol defined by a dynamic object which
1843 is not a function. The Alpha, since it uses .got entries for all
1844 symbols even in regular objects, does not need the hackery of a
1845 .dynbss section and COPY dynamic relocations. */
1850 /* Is it possible to merge two object file's .got tables? */
1853 elf64_alpha_can_merge_gots (a
, b
)
1856 int total
= alpha_elf_tdata (a
)->total_got_entries
;
1858 /* Trivial quick fallout test. */
1859 if (total
+ alpha_elf_tdata (b
)->total_got_entries
<= MAX_GOT_ENTRIES
)
1862 /* By their nature, local .got entries cannot be merged. */
1863 if ((total
+= alpha_elf_tdata (b
)->n_local_got_entries
) > MAX_GOT_ENTRIES
)
1866 /* Failing the common trivial comparison, we must effectively
1867 perform the merge. Not actually performing the merge means that
1868 we don't have to store undo information in case we fail. */
1870 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes(b
);
1871 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata(b
)->symtab_hdr
;
1874 n
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
- symtab_hdr
->sh_info
;
1875 for (i
= 0; i
< n
; ++i
)
1877 struct alpha_elf_got_entry
*ae
, *be
;
1878 for (be
= hashes
[i
]->got_entries
; be
; be
= be
->next
)
1880 if (be
->gotobj
!= b
)
1883 for (ae
= hashes
[i
]->got_entries
; ae
; ae
= ae
->next
)
1884 if (ae
->gotobj
== a
&& ae
->addend
== be
->addend
)
1887 if (++total
> MAX_GOT_ENTRIES
)
1897 /* Actually merge two .got tables. */
1900 elf64_alpha_merge_gots (a
, b
)
1903 int total
= alpha_elf_tdata(a
)->total_got_entries
;
1905 /* Remember local expansion. */
1907 int e
= alpha_elf_tdata(b
)->n_local_got_entries
;
1909 alpha_elf_tdata(a
)->n_local_got_entries
+= e
;
1912 /* Let the local .got entries know they are part of a new subsegment. */
1914 struct alpha_elf_got_entry
**local_got_entries
;
1915 local_got_entries
= alpha_elf_tdata(b
)->local_got_entries
;
1916 if (local_got_entries
)
1920 n
= elf_tdata(b
)->symtab_hdr
.sh_info
;
1921 for (i
= 0; i
< n
; ++i
)
1923 struct alpha_elf_got_entry
*gotent
;
1924 for (gotent
= local_got_entries
[i
]; gotent
; gotent
= gotent
->next
)
1930 /* Merge the global .got entries. */
1932 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes(b
);
1933 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata(b
)->symtab_hdr
;
1936 n
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
- symtab_hdr
->sh_info
;
1937 for (i
= 0; i
< n
; ++i
)
1939 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
1940 start
= &hashes
[i
]->got_entries
;
1941 for (pbe
= start
, be
= *start
; be
; pbe
= &be
->next
, be
= be
->next
)
1943 if (be
->gotobj
!= b
)
1946 for (ae
= *start
; ae
; ae
= ae
->next
)
1947 if (ae
->gotobj
== a
&& ae
->addend
== be
->addend
)
1960 alpha_elf_tdata(a
)->total_got_entries
= total
;
1961 alpha_elf_tdata(b
)->gotobj
= a
;
1964 /* Calculate the offsets for the got entries. */
1967 elf64_alpha_calc_got_offsets_for_symbol (h
, arg
)
1968 struct alpha_elf_link_hash_entry
*h
;
1971 struct alpha_elf_got_entry
*gotent
;
1973 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
1975 bfd_size_type
*plge
= &alpha_elf_tdata (gotent
->gotobj
)->got
->_raw_size
;
1976 gotent
->got_offset
= *plge
;
1984 elf64_alpha_calc_got_offsets (info
)
1985 struct bfd_link_info
*info
;
1987 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
1989 /* First, zero out the .got sizes, as we may be recalculating the
1990 .got after optimizing it. */
1991 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
1992 alpha_elf_tdata(i
)->got
->_raw_size
= 0;
1994 /* Next, fill in the offsets for all the global entries. */
1995 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
1996 elf64_alpha_calc_got_offsets_for_symbol
,
1999 /* Finally, fill in the offsets for the local entries. */
2000 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2002 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->_raw_size
;
2005 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2007 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2010 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2011 if (!local_got_entries
)
2014 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2015 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
2017 gotent
->got_offset
= got_offset
;
2022 alpha_elf_tdata(i
)->got
->_raw_size
= got_offset
;
2026 /* Remove a section from the output BFD. */
2029 elf64_alpha_strip_section_from_output (s
)
2034 for (spp
= &s
->output_section
->owner
->sections
;
2035 *spp
!= s
->output_section
;
2036 spp
= &(*spp
)->next
)
2038 *spp
= s
->output_section
->next
;
2039 --s
->output_section
->owner
->section_count
;
2042 /* Constructs the gots. */
2045 elf64_alpha_always_size_sections (output_bfd
, info
)
2047 struct bfd_link_info
*info
;
2049 bfd
*i
, *got_list
, *cur_got_obj
, **cur_got_tail
;
2052 if (info
->relocateable
)
2058 cur_got_tail
= NULL
;
2059 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2061 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
2063 /* Don't play if there is no .got for this input file. */
2064 if (this_got
== NULL
)
2067 if (alpha_elf_tdata (this_got
)->total_got_entries
> MAX_GOT_ENTRIES
)
2069 /* Yikes! A single object file has too many entries. */
2070 (*_bfd_error_handler
)
2071 ("%s: .got subsegment exceeds 64K (size %d)",
2072 bfd_get_filename(i
),
2073 alpha_elf_tdata(this_got
)->total_got_entries
* 8);
2079 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
2081 elf64_alpha_merge_gots (cur_got_obj
, i
);
2088 (*info
->callbacks
->warning
)
2089 (info
, "using multiple gp values", (char *) NULL
,
2090 output_bfd
, (asection
*) NULL
, (bfd_vma
) 0);
2092 *cur_got_tail
= NULL
;
2093 alpha_elf_tdata(cur_got_obj
)->got_link_next
= got_list
;
2094 got_list
= cur_got_obj
;
2103 cur_got_tail
= &alpha_elf_tdata(i
)->in_got_link_next
;
2107 alpha_elf_tdata (cur_got_obj
)->got_link_next
= got_list
;
2108 alpha_elf_hash_table (info
)->got_list
= got_list
= cur_got_obj
;
2110 /* Once the gots have been merged, fill in the got offsets for everything
2112 elf64_alpha_calc_got_offsets (info
);
2114 /* Allocate space for all of the .got subsections. */
2115 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2117 asection
*s
= alpha_elf_tdata(i
)->got
;
2118 if (s
->_raw_size
> 0)
2120 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->_raw_size
);
2121 if (s
->contents
== NULL
)
2129 /* Work out the sizes of the dynamic relocation entries. */
2132 elf64_alpha_calc_dynrel_sizes (h
, info
)
2133 struct alpha_elf_link_hash_entry
*h
;
2134 struct bfd_link_info
*info
;
2136 /* If the symbol was defined as a common symbol in a regular object
2137 file, and there was no definition in any dynamic object, then the
2138 linker will have allocated space for the symbol in a common
2139 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
2140 set. This is done for dynamic symbols in
2141 elf_adjust_dynamic_symbol but this is not done for non-dynamic
2142 symbols, somehow. */
2143 if (((h
->root
.elf_link_hash_flags
2144 & (ELF_LINK_HASH_DEF_REGULAR
2145 | ELF_LINK_HASH_REF_REGULAR
2146 | ELF_LINK_HASH_DEF_DYNAMIC
))
2147 == ELF_LINK_HASH_REF_REGULAR
)
2148 && (h
->root
.root
.type
== bfd_link_hash_defined
2149 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2150 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
2152 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2155 /* If the symbol is dynamic, we'll need all the relocations in their
2157 if (alpha_elf_dynamic_symbol_p (&h
->root
, info
))
2159 struct alpha_elf_reloc_entry
*relent
;
2161 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
2163 relent
->srel
->_raw_size
+=
2164 sizeof (Elf64_External_Rela
) * relent
->count
;
2167 /* Only add a .rela.got entry if we're not using a .plt entry. */
2168 if (h
->root
.plt_offset
== MINUS_ONE
)
2170 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
2171 struct alpha_elf_got_entry
*gotent
;
2172 bfd_size_type count
= 0;
2175 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2179 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2180 BFD_ASSERT (srel
!= NULL
);
2181 srel
->_raw_size
+= sizeof (Elf64_External_Rela
) * count
;
2185 /* Otherwise, shared objects require RELATIVE relocs for all REFQUAD
2186 and REFLONG relocations. */
2187 else if (info
->shared
)
2189 struct alpha_elf_reloc_entry
*relent
;
2191 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
2192 if (relent
->rtype
== R_ALPHA_REFLONG
2193 || relent
->rtype
== R_ALPHA_REFQUAD
)
2195 relent
->srel
->_raw_size
+=
2196 sizeof(Elf64_External_Rela
) * relent
->count
;
2203 /* Set the sizes of the dynamic sections. */
2206 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
2208 struct bfd_link_info
*info
;
2215 dynobj
= elf_hash_table(info
)->dynobj
;
2216 BFD_ASSERT(dynobj
!= NULL
);
2218 if (elf_hash_table (info
)->dynamic_sections_created
)
2220 /* Set the contents of the .interp section to the interpreter. */
2223 s
= bfd_get_section_by_name (dynobj
, ".interp");
2224 BFD_ASSERT (s
!= NULL
);
2225 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2226 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2229 /* Now that we've seen all of the input files, we can decide which
2230 symbols need dynamic relocation entries and which don't. We've
2231 collected information in check_relocs that we can now apply to
2232 size the dynamic relocation sections. */
2233 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2234 elf64_alpha_calc_dynrel_sizes
,
2237 /* When building shared libraries, each local .got entry needs a
2243 bfd_size_type count
;
2245 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2246 BFD_ASSERT (srel
!= NULL
);
2248 for (i
= alpha_elf_hash_table(info
)->got_list
, count
= 0;
2250 i
= alpha_elf_tdata(i
)->got_link_next
)
2251 count
+= alpha_elf_tdata(i
)->n_local_got_entries
;
2253 srel
->_raw_size
+= count
* sizeof(Elf64_External_Rela
);
2256 /* else we're not dynamic and by definition we don't need such things. */
2258 /* The check_relocs and adjust_dynamic_symbol entry points have
2259 determined the sizes of the various dynamic sections. Allocate
2263 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2268 if (!(s
->flags
& SEC_LINKER_CREATED
))
2271 /* It's OK to base decisions on the section name, because none
2272 of the dynobj section names depend upon the input files. */
2273 name
= bfd_get_section_name (dynobj
, s
);
2275 /* If we don't need this section, strip it from the output file.
2276 This is to handle .rela.bss and .rela.plt. We must create it
2277 in create_dynamic_sections, because it must be created before
2278 the linker maps input sections to output sections. The
2279 linker does that before adjust_dynamic_symbol is called, and
2280 it is that function which decides whether anything needs to
2281 go into these sections. */
2285 if (strncmp (name
, ".rela", 5) == 0)
2287 strip
= (s
->_raw_size
== 0);
2291 const char *outname
;
2294 /* If this relocation section applies to a read only
2295 section, then we probably need a DT_TEXTREL entry. */
2296 outname
= bfd_get_section_name (output_bfd
,
2298 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2300 && (target
->flags
& SEC_READONLY
) != 0)
2303 if (strcmp(name
, ".rela.plt") == 0)
2306 /* We use the reloc_count field as a counter if we need
2307 to copy relocs into the output file. */
2311 else if (strcmp (name
, ".plt") != 0)
2313 /* It's not one of our dynamic sections, so don't allocate space. */
2318 elf64_alpha_strip_section_from_output (s
);
2321 /* Allocate memory for the section contents. */
2322 s
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, s
->_raw_size
);
2323 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2328 /* If we are generating a shared library, we generate a section
2329 symbol for each output section. These are local symbols, which
2330 means that they must come first in the dynamic symbol table.
2331 That means we must increment the dynamic symbol index of every
2332 other dynamic symbol. */
2339 c
[1] = bfd_count_sections (output_bfd
);
2341 elf_hash_table (info
)->dynsymcount
+= c
[1];
2342 elf_link_hash_traverse (elf_hash_table(info
),
2343 elf64_alpha_adjust_dynindx
,
2346 for (i
= 1, p
= output_bfd
->sections
;
2350 elf_section_data (p
)->dynindx
= i
;
2351 /* These symbols will have no names, so we don't need to
2352 fiddle with dynstr_index. */
2356 if (elf_hash_table (info
)->dynamic_sections_created
)
2358 /* Add some entries to the .dynamic section. We fill in the
2359 values later, in elf64_alpha_finish_dynamic_sections, but we
2360 must add the entries now so that we get the correct size for
2361 the .dynamic section. The DT_DEBUG entry is filled in by the
2362 dynamic linker and used by the debugger. */
2365 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
2369 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2374 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2375 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2376 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
2380 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
2381 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
2382 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
2383 sizeof(Elf64_External_Rela
)))
2388 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2396 /* Increment the index of a dynamic symbol by a given amount. Called
2397 via elf_link_hash_traverse. */
2400 elf64_alpha_adjust_dynindx (h
, cparg
)
2401 struct elf_link_hash_entry
*h
;
2404 long *cp
= (long *)cparg
;
2406 if (h
->dynindx
>= cp
[0])
2407 h
->dynindx
+= cp
[1];
2412 /* Relocate an Alpha ELF section. */
2415 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2416 contents
, relocs
, local_syms
, local_sections
)
2418 struct bfd_link_info
*info
;
2420 asection
*input_section
;
2422 Elf_Internal_Rela
*relocs
;
2423 Elf_Internal_Sym
*local_syms
;
2424 asection
**local_sections
;
2426 Elf_Internal_Shdr
*symtab_hdr
;
2427 Elf_Internal_Rela
*rel
;
2428 Elf_Internal_Rela
*relend
;
2429 asection
*sec
, *sgot
, *srel
, *srelgot
;
2430 bfd
*dynobj
, *gotobj
;
2433 srelgot
= srel
= NULL
;
2434 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2435 dynobj
= elf_hash_table (info
)->dynobj
;
2438 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2441 /* Find the gp value for this input bfd. */
2444 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
2447 sgot
= alpha_elf_tdata (gotobj
)->got
;
2448 gp
= _bfd_get_gp_value (gotobj
);
2451 gp
= (sgot
->output_section
->vma
2452 + sgot
->output_offset
2454 _bfd_set_gp_value (gotobj
, gp
);
2459 relend
= relocs
+ input_section
->reloc_count
;
2460 for (; rel
< relend
; rel
++)
2463 reloc_howto_type
*howto
;
2464 unsigned long r_symndx
;
2465 struct alpha_elf_link_hash_entry
*h
;
2466 Elf_Internal_Sym
*sym
;
2469 bfd_reloc_status_type r
;
2471 r_type
= ELF64_R_TYPE(rel
->r_info
);
2472 if (r_type
< 0 || r_type
>= (int) R_ALPHA_max
)
2474 bfd_set_error (bfd_error_bad_value
);
2477 howto
= elf64_alpha_howto_table
+ r_type
;
2479 r_symndx
= ELF64_R_SYM(rel
->r_info
);
2481 if (info
->relocateable
)
2483 /* This is a relocateable link. We don't have to change
2484 anything, unless the reloc is against a section symbol,
2485 in which case we have to adjust according to where the
2486 section symbol winds up in the output section. */
2487 if (r_symndx
< symtab_hdr
->sh_info
)
2489 sym
= local_syms
+ r_symndx
;
2490 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
2492 sec
= local_sections
[r_symndx
];
2493 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2500 /* This is a final link. */
2506 if (r_symndx
< symtab_hdr
->sh_info
)
2508 sym
= local_syms
+ r_symndx
;
2509 sec
= local_sections
[r_symndx
];
2510 relocation
= (sec
->output_section
->vma
2511 + sec
->output_offset
2516 h
= alpha_elf_sym_hashes (input_bfd
)[r_symndx
- symtab_hdr
->sh_info
];
2518 while (h
->root
.root
.type
== bfd_link_hash_indirect
2519 || h
->root
.root
.type
== bfd_link_hash_warning
)
2520 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2522 if (h
->root
.root
.type
== bfd_link_hash_defined
2523 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2525 sec
= h
->root
.root
.u
.def
.section
;
2528 if ((r_type
== R_ALPHA_LITERAL
2529 && elf_hash_table(info
)->dynamic_sections_created
2532 || !(h
->root
.elf_link_hash_flags
2533 & ELF_LINK_HASH_DEF_REGULAR
)))
2536 || !(h
->root
.elf_link_hash_flags
2537 & ELF_LINK_HASH_DEF_REGULAR
))
2538 && (input_section
->flags
& SEC_ALLOC
)
2539 && (r_type
== R_ALPHA_REFLONG
2540 || r_type
== R_ALPHA_REFQUAD
2541 || r_type
== R_ALPHA_LITERAL
)))
2543 /* In these cases, we don't need the relocation value.
2544 We check specially because in some obscure cases
2545 sec->output_section will be NULL. */
2549 /* FIXME: Are not these obscure cases simply bugs? Let's
2550 get something working and come back to this. */
2551 if (sec
->output_section
== NULL
)
2553 #endif /* rth_notdef */
2556 relocation
= (h
->root
.root
.u
.def
.value
2557 + sec
->output_section
->vma
2558 + sec
->output_offset
);
2561 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2563 else if (info
->shared
&& !info
->symbolic
)
2567 if (!((*info
->callbacks
->undefined_symbol
)
2568 (info
, h
->root
.root
.root
.string
, input_bfd
,
2569 input_section
, rel
->r_offset
)))
2574 addend
= rel
->r_addend
;
2578 case R_ALPHA_GPDISP
:
2580 bfd_byte
*p_ldah
, *p_lda
;
2582 BFD_ASSERT(gp
!= 0);
2584 relocation
= (input_section
->output_section
->vma
2585 + input_section
->output_offset
2588 p_ldah
= contents
+ rel
->r_offset
- input_section
->vma
;
2589 p_lda
= p_ldah
+ rel
->r_addend
;
2591 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- relocation
,
2596 case R_ALPHA_OP_PUSH
:
2597 case R_ALPHA_OP_STORE
:
2598 case R_ALPHA_OP_PSUB
:
2599 case R_ALPHA_OP_PRSHIFT
:
2600 /* We hate these silly beasts. */
2603 case R_ALPHA_LITERAL
:
2605 struct alpha_elf_got_entry
*gotent
;
2607 BFD_ASSERT(sgot
!= NULL
);
2608 BFD_ASSERT(gp
!= 0);
2612 gotent
= h
->got_entries
;
2613 while (gotent
->gotobj
!= gotobj
|| gotent
->addend
!= addend
)
2614 gotent
= gotent
->next
;
2616 /* Initialize the .got entry's value. */
2617 if (!(gotent
->flags
& ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
))
2619 bfd_put_64 (output_bfd
, relocation
+addend
,
2620 sgot
->contents
+ gotent
->got_offset
);
2622 /* The dynamic relocations for the .got entries are
2623 done in finish_dynamic_symbol. */
2625 gotent
->flags
|= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
;
2630 gotent
= (alpha_elf_tdata(input_bfd
)->
2631 local_got_entries
[r_symndx
]);
2632 while (gotent
->addend
!= addend
)
2633 gotent
= gotent
->next
;
2635 if (!(gotent
->flags
& ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
))
2637 bfd_put_64 (output_bfd
, relocation
+addend
,
2638 sgot
->contents
+ gotent
->got_offset
);
2640 /* Local got entries need RELATIVE relocs in shared
2644 Elf_Internal_Rela outrel
;
2646 BFD_ASSERT(srelgot
!= NULL
);
2648 outrel
.r_offset
= (sgot
->output_section
->vma
2649 + sgot
->output_offset
2650 + gotent
->got_offset
);
2651 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
2652 outrel
.r_addend
= 0;
2654 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2655 ((Elf64_External_Rela
*)
2657 + srelgot
->reloc_count
++);
2660 gotent
->flags
|= ALPHA_ELF_GOT_ENTRY_RELOCS_DONE
;
2664 /* Figure the gprel relocation. */
2666 relocation
= (sgot
->output_section
->vma
2667 + sgot
->output_offset
2668 + gotent
->got_offset
);
2671 /* overflow handled by _bfd_final_link_relocate */
2674 case R_ALPHA_GPREL32
:
2675 BFD_ASSERT(gp
!= 0);
2679 case R_ALPHA_BRADDR
:
2681 /* The regular PC-relative stuff measures from the start of
2682 the instruction rather than the end. */
2686 case R_ALPHA_REFLONG
:
2687 case R_ALPHA_REFQUAD
:
2689 Elf_Internal_Rela outrel
;
2691 /* Careful here to remember RELATIVE relocations for global
2692 variables for symbolic shared objects. */
2694 if (h
&& alpha_elf_dynamic_symbol_p (&h
->root
, info
))
2696 BFD_ASSERT(h
->root
.dynindx
!= -1);
2697 outrel
.r_info
= ELF64_R_INFO(h
->root
.dynindx
, r_type
);
2698 outrel
.r_addend
= addend
;
2699 addend
= 0, relocation
= 0;
2701 else if (info
->shared
)
2703 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
2704 outrel
.r_addend
= 0;
2713 name
= (bfd_elf_string_from_elf_section
2714 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
2715 elf_section_data(input_section
)->rel_hdr
.sh_name
));
2716 BFD_ASSERT(name
!= NULL
);
2718 srel
= bfd_get_section_by_name (dynobj
, name
);
2719 BFD_ASSERT(srel
!= NULL
);
2722 outrel
.r_offset
= (input_section
->output_section
->vma
2723 + input_section
->output_offset
2726 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2727 ((Elf64_External_Rela
*)
2729 + srel
->reloc_count
++);
2735 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2736 contents
, rel
->r_offset
, relocation
,
2746 case bfd_reloc_overflow
:
2751 name
= h
->root
.root
.root
.string
;
2754 name
= (bfd_elf_string_from_elf_section
2755 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2759 name
= bfd_section_name (input_bfd
, sec
);
2761 if (! ((*info
->callbacks
->reloc_overflow
)
2762 (info
, name
, howto
->name
, (bfd_vma
) 0,
2763 input_bfd
, input_section
, rel
->r_offset
)))
2769 case bfd_reloc_outofrange
:
2777 /* Finish up dynamic symbol handling. We set the contents of various
2778 dynamic sections here. */
2781 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2783 struct bfd_link_info
*info
;
2784 struct elf_link_hash_entry
*h
;
2785 Elf_Internal_Sym
*sym
;
2787 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
2789 if (h
->plt_offset
!= MINUS_ONE
)
2791 /* Fill in the .plt entry for this symbol. */
2792 asection
*splt
, *sgot
, *srel
;
2793 Elf_Internal_Rela outrel
;
2794 bfd_vma got_addr
, plt_addr
;
2796 struct alpha_elf_got_entry
*gotent
;
2798 BFD_ASSERT (h
->dynindx
!= -1);
2800 /* The first .got entry will be updated by the .plt with the
2801 address of the target function. */
2802 gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
2803 BFD_ASSERT (gotent
&& gotent
->addend
== 0);
2805 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2806 BFD_ASSERT (splt
!= NULL
);
2807 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2808 BFD_ASSERT (srel
!= NULL
);
2809 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
2810 BFD_ASSERT (sgot
!= NULL
);
2812 got_addr
= (sgot
->output_section
->vma
2813 + sgot
->output_offset
2814 + gotent
->got_offset
);
2815 plt_addr
= (splt
->output_section
->vma
2816 + splt
->output_offset
2819 plt_index
= (h
->plt_offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
2821 /* Fill in the entry in the procedure linkage table. */
2823 unsigned insn1
, insn2
, insn3
;
2826 /* decompose the reloc offset for the plt for ldah+lda */
2827 hi
= plt_index
* sizeof(Elf64_External_Rela
);
2828 lo
= ((hi
& 0xffff) ^ 0x8000) - 0x8000;
2829 hi
= (hi
- lo
) >> 16;
2831 insn1
= PLT_ENTRY_WORD1
| (hi
& 0xffff);
2832 insn2
= PLT_ENTRY_WORD2
| (lo
& 0xffff);
2833 insn3
= PLT_ENTRY_WORD3
| ((-(h
->plt_offset
+ 12) >> 2) & 0x1fffff);
2835 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt_offset
);
2836 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt_offset
+ 4);
2837 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt_offset
+ 8);
2840 /* Fill in the entry in the .rela.plt section. */
2841 outrel
.r_offset
= got_addr
;
2842 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
2843 outrel
.r_addend
= 0;
2845 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2846 ((Elf64_External_Rela
*)srel
->contents
2849 if (!(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2851 /* Mark the symbol as undefined, rather than as defined in the
2852 .plt section. Leave the value alone. */
2853 sym
->st_shndx
= SHN_UNDEF
;
2856 /* Fill in the entries in the .got. */
2857 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ gotent
->got_offset
);
2859 /* Subsequent .got entries will continue to bounce through the .plt. */
2860 while ((gotent
= gotent
->next
) != NULL
)
2862 sgot
= alpha_elf_tdata(gotent
->gotobj
)->got
;
2863 BFD_ASSERT(sgot
!= NULL
);
2864 BFD_ASSERT(gotent
->addend
== 0);
2866 bfd_put_64 (output_bfd
, plt_addr
,
2867 sgot
->contents
+ gotent
->got_offset
);
2870 else if (alpha_elf_dynamic_symbol_p (h
, info
))
2872 /* Fill in the dynamic relocations for this symbol's .got entries. */
2874 Elf_Internal_Rela outrel
;
2875 struct alpha_elf_got_entry
*gotent
;
2877 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2878 BFD_ASSERT (srel
!= NULL
);
2880 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_ALPHA_GLOB_DAT
);
2881 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
2883 gotent
= gotent
->next
)
2885 asection
*sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
2886 outrel
.r_offset
= (sgot
->output_section
->vma
2887 + sgot
->output_offset
2888 + gotent
->got_offset
);
2889 outrel
.r_addend
= gotent
->addend
;
2891 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2892 ((Elf64_External_Rela
*)srel
->contents
2893 + srel
->reloc_count
++));
2897 /* Mark some specially defined symbols as absolute. */
2898 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2899 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2900 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2901 sym
->st_shndx
= SHN_ABS
;
2906 /* Finish up the dynamic sections. */
2909 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
2911 struct bfd_link_info
*info
;
2916 dynobj
= elf_hash_table (info
)->dynobj
;
2917 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2919 if (elf_hash_table (info
)->dynamic_sections_created
)
2922 Elf64_External_Dyn
*dyncon
, *dynconend
;
2924 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2925 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2927 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2928 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2929 for (; dyncon
< dynconend
; dyncon
++)
2931 Elf_Internal_Dyn dyn
;
2935 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2950 /* My interpretation of the TIS v1.1 ELF document indicates
2951 that RELASZ should not include JMPREL. This is not what
2952 the rest of the BFD does. It is, however, what the
2953 glibc ld.so wants. Do this fixup here until we found
2954 out who is right. */
2955 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
2959 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
2964 s
= bfd_get_section_by_name (output_bfd
, name
);
2965 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
2969 s
= bfd_get_section_by_name (output_bfd
, name
);
2971 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
2975 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2978 /* Initialize the PLT0 entry */
2979 if (splt
->_raw_size
> 0)
2981 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
2982 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
2983 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
2984 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
2986 /* The next two words will be filled in by ld.so */
2987 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 16);
2988 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 24);
2990 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
2999 Elf_Internal_Sym sym
;
3001 /* Set up the section symbols for the output sections. */
3003 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
3004 BFD_ASSERT (sdynsym
!= NULL
);
3008 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
3011 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
3015 sym
.st_value
= s
->vma
;
3017 indx
= elf_section_data (s
)->this_idx
;
3018 BFD_ASSERT (indx
> 0);
3019 sym
.st_shndx
= indx
;
3021 bfd_elf64_swap_symbol_out (output_bfd
, &sym
,
3022 (PTR
) (((Elf64_External_Sym
*)
3024 + elf_section_data (s
)->dynindx
));
3027 /* Set the sh_info field of the output .dynsym section to the
3028 index of the first global symbol. */
3029 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
3030 bfd_count_sections (output_bfd
) + 1;
3036 /* We need to use a special link routine to handle the .reginfo and
3037 the .mdebug sections. We need to merge all instances of these
3038 sections together, not write them all out sequentially. */
3041 elf64_alpha_final_link (abfd
, info
)
3043 struct bfd_link_info
*info
;
3046 struct bfd_link_order
*p
;
3047 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
3048 struct ecoff_debug_info debug
;
3049 const struct ecoff_debug_swap
*swap
3050 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
3051 HDRR
*symhdr
= &debug
.symbolic_header
;
3052 PTR mdebug_handle
= NULL
;
3054 /* Go through the sections and collect the .reginfo and .mdebug
3058 gptab_data_sec
= NULL
;
3059 gptab_bss_sec
= NULL
;
3060 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
3062 #ifdef ERIC_neverdef
3063 if (strcmp (o
->name
, ".reginfo") == 0)
3065 memset (®info
, 0, sizeof reginfo
);
3067 /* We have found the .reginfo section in the output file.
3068 Look through all the link_orders comprising it and merge
3069 the information together. */
3070 for (p
= o
->link_order_head
;
3071 p
!= (struct bfd_link_order
*) NULL
;
3074 asection
*input_section
;
3076 Elf64_External_RegInfo ext
;
3079 if (p
->type
!= bfd_indirect_link_order
)
3081 if (p
->type
== bfd_fill_link_order
)
3086 input_section
= p
->u
.indirect
.section
;
3087 input_bfd
= input_section
->owner
;
3089 /* The linker emulation code has probably clobbered the
3090 size to be zero bytes. */
3091 if (input_section
->_raw_size
== 0)
3092 input_section
->_raw_size
= sizeof (Elf64_External_RegInfo
);
3094 if (! bfd_get_section_contents (input_bfd
, input_section
,
3100 bfd_alpha_elf64_swap_reginfo_in (input_bfd
, &ext
, &sub
);
3102 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
3103 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
3104 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
3105 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
3106 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
3108 /* ri_gp_value is set by the function
3109 alpha_elf_section_processing when the section is
3110 finally written out. */
3112 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3113 elf_link_input_bfd ignores this section. */
3114 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3117 /* Force the section size to the value we want. */
3118 o
->_raw_size
= sizeof (Elf64_External_RegInfo
);
3120 /* Skip this section later on (I don't think this currently
3121 matters, but someday it might). */
3122 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3128 if (strcmp (o
->name
, ".mdebug") == 0)
3130 struct extsym_info einfo
;
3132 /* We have found the .mdebug section in the output file.
3133 Look through all the link_orders comprising it and merge
3134 the information together. */
3135 symhdr
->magic
= swap
->sym_magic
;
3136 /* FIXME: What should the version stamp be? */
3138 symhdr
->ilineMax
= 0;
3142 symhdr
->isymMax
= 0;
3143 symhdr
->ioptMax
= 0;
3144 symhdr
->iauxMax
= 0;
3146 symhdr
->issExtMax
= 0;
3149 symhdr
->iextMax
= 0;
3151 /* We accumulate the debugging information itself in the
3152 debug_info structure. */
3154 debug
.external_dnr
= NULL
;
3155 debug
.external_pdr
= NULL
;
3156 debug
.external_sym
= NULL
;
3157 debug
.external_opt
= NULL
;
3158 debug
.external_aux
= NULL
;
3160 debug
.ssext
= debug
.ssext_end
= NULL
;
3161 debug
.external_fdr
= NULL
;
3162 debug
.external_rfd
= NULL
;
3163 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3165 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
3166 if (mdebug_handle
== (PTR
) NULL
)
3175 static const char * const name
[] =
3177 ".text", ".init", ".fini", ".data",
3178 ".rodata", ".sdata", ".sbss", ".bss"
3180 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
3181 scRData
, scSData
, scSBss
, scBss
};
3184 esym
.cobol_main
= 0;
3188 esym
.asym
.iss
= issNil
;
3189 esym
.asym
.st
= stLocal
;
3190 esym
.asym
.reserved
= 0;
3191 esym
.asym
.index
= indexNil
;
3192 for (i
= 0; i
< 8; i
++)
3194 esym
.asym
.sc
= sc
[i
];
3195 s
= bfd_get_section_by_name (abfd
, name
[i
]);
3198 esym
.asym
.value
= s
->vma
;
3199 last
= s
->vma
+ s
->_raw_size
;
3202 esym
.asym
.value
= last
;
3204 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
3210 for (p
= o
->link_order_head
;
3211 p
!= (struct bfd_link_order
*) NULL
;
3214 asection
*input_section
;
3216 const struct ecoff_debug_swap
*input_swap
;
3217 struct ecoff_debug_info input_debug
;
3221 if (p
->type
!= bfd_indirect_link_order
)
3223 if (p
->type
== bfd_fill_link_order
)
3228 input_section
= p
->u
.indirect
.section
;
3229 input_bfd
= input_section
->owner
;
3231 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
3232 || (get_elf_backend_data (input_bfd
)
3233 ->elf_backend_ecoff_debug_swap
) == NULL
)
3235 /* I don't know what a non ALPHA ELF bfd would be
3236 doing with a .mdebug section, but I don't really
3237 want to deal with it. */
3241 input_swap
= (get_elf_backend_data (input_bfd
)
3242 ->elf_backend_ecoff_debug_swap
);
3244 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
3246 /* The ECOFF linking code expects that we have already
3247 read in the debugging information and set up an
3248 ecoff_debug_info structure, so we do that now. */
3249 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
3253 if (! (bfd_ecoff_debug_accumulate
3254 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
3255 &input_debug
, input_swap
, info
)))
3258 /* Loop through the external symbols. For each one with
3259 interesting information, try to find the symbol in
3260 the linker global hash table and save the information
3261 for the output external symbols. */
3262 eraw_src
= input_debug
.external_ext
;
3263 eraw_end
= (eraw_src
3264 + (input_debug
.symbolic_header
.iextMax
3265 * input_swap
->external_ext_size
));
3267 eraw_src
< eraw_end
;
3268 eraw_src
+= input_swap
->external_ext_size
)
3272 struct alpha_elf_link_hash_entry
*h
;
3274 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
3275 if (ext
.asym
.sc
== scNil
3276 || ext
.asym
.sc
== scUndefined
3277 || ext
.asym
.sc
== scSUndefined
)
3280 name
= input_debug
.ssext
+ ext
.asym
.iss
;
3281 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
3282 name
, false, false, true);
3283 if (h
== NULL
|| h
->esym
.ifd
!= -2)
3289 < input_debug
.symbolic_header
.ifdMax
);
3290 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
3296 /* Free up the information we just read. */
3297 free (input_debug
.line
);
3298 free (input_debug
.external_dnr
);
3299 free (input_debug
.external_pdr
);
3300 free (input_debug
.external_sym
);
3301 free (input_debug
.external_opt
);
3302 free (input_debug
.external_aux
);
3303 free (input_debug
.ss
);
3304 free (input_debug
.ssext
);
3305 free (input_debug
.external_fdr
);
3306 free (input_debug
.external_rfd
);
3307 free (input_debug
.external_ext
);
3309 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3310 elf_link_input_bfd ignores this section. */
3311 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3314 #ifdef ERIC_neverdef
3317 /* Create .rtproc section. */
3318 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
3319 if (rtproc_sec
== NULL
)
3321 flagword flags
= (SEC_HAS_CONTENTS
3323 | SEC_LINKER_CREATED
3326 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
3327 if (rtproc_sec
== NULL
3328 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
3329 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
3333 if (! alpha_elf_create_procedure_table (mdebug_handle
, abfd
,
3334 info
, rtproc_sec
, &debug
))
3340 /* Build the external symbol information. */
3343 einfo
.debug
= &debug
;
3345 einfo
.failed
= false;
3346 elf_link_hash_traverse (elf_hash_table (info
),
3347 elf64_alpha_output_extsym
,
3352 /* Set the size of the .mdebug section. */
3353 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
3355 /* Skip this section later on (I don't think this currently
3356 matters, but someday it might). */
3357 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3362 #ifdef ERIC_neverdef
3363 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
3365 const char *subname
;
3368 Elf64_External_gptab
*ext_tab
;
3371 /* The .gptab.sdata and .gptab.sbss sections hold
3372 information describing how the small data area would
3373 change depending upon the -G switch. These sections
3374 not used in executables files. */
3375 if (! info
->relocateable
)
3379 for (p
= o
->link_order_head
;
3380 p
!= (struct bfd_link_order
*) NULL
;
3383 asection
*input_section
;
3385 if (p
->type
!= bfd_indirect_link_order
)
3387 if (p
->type
== bfd_fill_link_order
)
3392 input_section
= p
->u
.indirect
.section
;
3394 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3395 elf_link_input_bfd ignores this section. */
3396 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3399 /* Skip this section later on (I don't think this
3400 currently matters, but someday it might). */
3401 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3403 /* Really remove the section. */
3404 for (secpp
= &abfd
->sections
;
3406 secpp
= &(*secpp
)->next
)
3408 *secpp
= (*secpp
)->next
;
3409 --abfd
->section_count
;
3414 /* There is one gptab for initialized data, and one for
3415 uninitialized data. */
3416 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3418 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3422 (*_bfd_error_handler
)
3423 ("%s: illegal section name `%s'",
3424 bfd_get_filename (abfd
), o
->name
);
3425 bfd_set_error (bfd_error_nonrepresentable_section
);
3429 /* The linker script always combines .gptab.data and
3430 .gptab.sdata into .gptab.sdata, and likewise for
3431 .gptab.bss and .gptab.sbss. It is possible that there is
3432 no .sdata or .sbss section in the output file, in which
3433 case we must change the name of the output section. */
3434 subname
= o
->name
+ sizeof ".gptab" - 1;
3435 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3437 if (o
== gptab_data_sec
)
3438 o
->name
= ".gptab.data";
3440 o
->name
= ".gptab.bss";
3441 subname
= o
->name
+ sizeof ".gptab" - 1;
3442 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3445 /* Set up the first entry. */
3447 tab
= (Elf64_gptab
*) bfd_malloc (c
* sizeof (Elf64_gptab
));
3450 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3451 tab
[0].gt_header
.gt_unused
= 0;
3453 /* Combine the input sections. */
3454 for (p
= o
->link_order_head
;
3455 p
!= (struct bfd_link_order
*) NULL
;
3458 asection
*input_section
;
3462 bfd_size_type gpentry
;
3464 if (p
->type
!= bfd_indirect_link_order
)
3466 if (p
->type
== bfd_fill_link_order
)
3471 input_section
= p
->u
.indirect
.section
;
3472 input_bfd
= input_section
->owner
;
3474 /* Combine the gptab entries for this input section one
3475 by one. We know that the input gptab entries are
3476 sorted by ascending -G value. */
3477 size
= bfd_section_size (input_bfd
, input_section
);
3479 for (gpentry
= sizeof (Elf64_External_gptab
);
3481 gpentry
+= sizeof (Elf64_External_gptab
))
3483 Elf64_External_gptab ext_gptab
;
3484 Elf64_gptab int_gptab
;
3490 if (! (bfd_get_section_contents
3491 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3492 gpentry
, sizeof (Elf64_External_gptab
))))
3498 bfd_alpha_elf64_swap_gptab_in (input_bfd
, &ext_gptab
,
3500 val
= int_gptab
.gt_entry
.gt_g_value
;
3501 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3504 for (look
= 1; look
< c
; look
++)
3506 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3507 tab
[look
].gt_entry
.gt_bytes
+= add
;
3509 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3515 Elf64_gptab
*new_tab
;
3518 /* We need a new table entry. */
3519 new_tab
= ((Elf64_gptab
*)
3520 bfd_realloc ((PTR
) tab
,
3521 (c
+ 1) * sizeof (Elf64_gptab
)));
3522 if (new_tab
== NULL
)
3528 tab
[c
].gt_entry
.gt_g_value
= val
;
3529 tab
[c
].gt_entry
.gt_bytes
= add
;
3531 /* Merge in the size for the next smallest -G
3532 value, since that will be implied by this new
3535 for (look
= 1; look
< c
; look
++)
3537 if (tab
[look
].gt_entry
.gt_g_value
< val
3539 || (tab
[look
].gt_entry
.gt_g_value
3540 > tab
[max
].gt_entry
.gt_g_value
)))
3544 tab
[c
].gt_entry
.gt_bytes
+=
3545 tab
[max
].gt_entry
.gt_bytes
;
3550 last
= int_gptab
.gt_entry
.gt_bytes
;
3553 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3554 elf_link_input_bfd ignores this section. */
3555 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3558 /* The table must be sorted by -G value. */
3560 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3562 /* Swap out the table. */
3563 ext_tab
= ((Elf64_External_gptab
*)
3564 bfd_alloc (abfd
, c
* sizeof (Elf64_External_gptab
)));
3565 if (ext_tab
== NULL
)
3571 for (i
= 0; i
< c
; i
++)
3572 bfd_alpha_elf64_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3575 o
->_raw_size
= c
* sizeof (Elf64_External_gptab
);
3576 o
->contents
= (bfd_byte
*) ext_tab
;
3578 /* Skip this section later on (I don't think this currently
3579 matters, but someday it might). */
3580 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3586 /* Invoke the regular ELF backend linker to do all the work. */
3587 if (! bfd_elf64_bfd_final_link (abfd
, info
))
3590 /* Now write out the computed sections. */
3592 /* The .got subsections... */
3594 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
3595 for (i
= alpha_elf_hash_table(info
)->got_list
;
3597 i
= alpha_elf_tdata(i
)->got_link_next
)
3601 /* elf_bfd_final_link already did everything in dynobj. */
3605 sgot
= alpha_elf_tdata(i
)->got
;
3606 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
3607 sgot
->contents
, sgot
->output_offset
,
3613 #ifdef ERIC_neverdef
3614 if (reginfo_sec
!= (asection
*) NULL
)
3616 Elf64_External_RegInfo ext
;
3618 bfd_alpha_elf64_swap_reginfo_out (abfd
, ®info
, &ext
);
3619 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3620 (file_ptr
) 0, sizeof ext
))
3625 if (mdebug_sec
!= (asection
*) NULL
)
3627 BFD_ASSERT (abfd
->output_has_begun
);
3628 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3630 mdebug_sec
->filepos
))
3633 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3636 if (gptab_data_sec
!= (asection
*) NULL
)
3638 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3639 gptab_data_sec
->contents
,
3641 gptab_data_sec
->_raw_size
))
3645 if (gptab_bss_sec
!= (asection
*) NULL
)
3647 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3648 gptab_bss_sec
->contents
,
3650 gptab_bss_sec
->_raw_size
))
3657 /* ECOFF swapping routines. These are used when dealing with the
3658 .mdebug section, which is in the ECOFF debugging format. Copied
3659 from elf32-mips.c. */
3660 static const struct ecoff_debug_swap
3661 elf64_alpha_ecoff_debug_swap
=
3663 /* Symbol table magic number. */
3665 /* Alignment of debugging information. E.g., 4. */
3667 /* Sizes of external symbolic information. */
3668 sizeof (struct hdr_ext
),
3669 sizeof (struct dnr_ext
),
3670 sizeof (struct pdr_ext
),
3671 sizeof (struct sym_ext
),
3672 sizeof (struct opt_ext
),
3673 sizeof (struct fdr_ext
),
3674 sizeof (struct rfd_ext
),
3675 sizeof (struct ext_ext
),
3676 /* Functions to swap in external symbolic data. */
3685 _bfd_ecoff_swap_tir_in
,
3686 _bfd_ecoff_swap_rndx_in
,
3687 /* Functions to swap out external symbolic data. */
3696 _bfd_ecoff_swap_tir_out
,
3697 _bfd_ecoff_swap_rndx_out
,
3698 /* Function to read in symbolic data. */
3699 elf64_alpha_read_ecoff_info
3702 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
3703 #define TARGET_LITTLE_NAME "elf64-alpha"
3704 #define ELF_ARCH bfd_arch_alpha
3705 #define ELF_MACHINE_CODE EM_ALPHA
3706 #define ELF_MAXPAGESIZE 0x100000
3708 #define bfd_elf64_bfd_link_hash_table_create \
3709 elf64_alpha_bfd_link_hash_table_create
3711 #define bfd_elf64_bfd_reloc_type_lookup \
3712 elf64_alpha_bfd_reloc_type_lookup
3713 #define elf_info_to_howto \
3714 elf64_alpha_info_to_howto
3716 #define bfd_elf64_mkobject \
3717 elf64_alpha_mkobject
3719 #define elf_backend_object_p \
3720 elf64_alpha_object_p
3721 #define elf_backend_section_from_shdr \
3722 elf64_alpha_section_from_shdr
3723 #define elf_backend_fake_sections \
3724 elf64_alpha_fake_sections
3725 #define elf_backend_additional_program_headers \
3726 elf64_alpha_additional_program_headers
3728 #define bfd_elf64_bfd_is_local_label_name \
3729 elf64_alpha_is_local_label_name
3730 #define bfd_elf64_find_nearest_line \
3731 elf64_alpha_find_nearest_line
3733 #define elf_backend_check_relocs \
3734 elf64_alpha_check_relocs
3735 #define elf_backend_create_dynamic_sections \
3736 elf64_alpha_create_dynamic_sections
3737 #define elf_backend_adjust_dynamic_symbol \
3738 elf64_alpha_adjust_dynamic_symbol
3739 #define elf_backend_always_size_sections \
3740 elf64_alpha_always_size_sections
3741 #define elf_backend_size_dynamic_sections \
3742 elf64_alpha_size_dynamic_sections
3743 #define elf_backend_relocate_section \
3744 elf64_alpha_relocate_section
3745 #define elf_backend_finish_dynamic_symbol \
3746 elf64_alpha_finish_dynamic_symbol
3747 #define elf_backend_finish_dynamic_sections \
3748 elf64_alpha_finish_dynamic_sections
3749 #define bfd_elf64_bfd_final_link \
3750 elf64_alpha_final_link
3752 #define elf_backend_ecoff_debug_swap \
3753 &elf64_alpha_ecoff_debug_swap
3756 * A few constants that determine how the .plt section is set up.
3758 #define elf_backend_want_got_plt 0
3759 #define elf_backend_plt_readonly 0
3760 #define elf_backend_want_plt_sym 1
3762 #include "elf64-target.h"