1 /* ALPHA-specific support for 64-bit ELF
2 Copyright 1996 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 struct bfd_hash_entry
* elf64_alpha_link_hash_newfunc
50 PARAMS((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
51 static struct bfd_link_hash_table
* elf64_alpha_bfd_link_hash_table_create
54 static bfd_reloc_status_type elf64_alpha_reloc_nil
55 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
56 static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp
57 PARAMS((bfd
*, bfd_vma
, bfd_byte
*, bfd_byte
*));
58 static bfd_reloc_status_type elf64_alpha_reloc_gpdisp
59 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
60 static bfd_reloc_status_type elf64_alpha_reloc_op_push
61 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
62 static bfd_reloc_status_type elf64_alpha_reloc_op_store
63 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
64 static bfd_reloc_status_type elf64_alpha_reloc_op_psub
65 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
66 static bfd_reloc_status_type elf64_alpha_reloc_op_prshift
67 PARAMS((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
69 static reloc_howto_type
* elf64_alpha_bfd_reloc_type_lookup
70 PARAMS((bfd
*, bfd_reloc_code_real_type
));
71 static void elf64_alpha_info_to_howto
72 PARAMS((bfd
*, arelent
*, Elf64_Internal_Rela
*));
74 static boolean elf64_alpha_object_p
76 static boolean elf64_alpha_section_from_shdr
77 PARAMS((bfd
*, Elf64_Internal_Shdr
*, char *));
78 static boolean elf64_alpha_fake_sections
79 PARAMS((bfd
*, Elf64_Internal_Shdr
*, asection
*));
80 static int elf64_alpha_additional_program_headers
82 static boolean elf64_alpha_create_got_section
83 PARAMS((bfd
*, struct bfd_link_info
*));
84 static boolean elf64_alpha_create_dynamic_sections
85 PARAMS((bfd
*, struct bfd_link_info
*));
87 static boolean elf64_alpha_read_ecoff_info
88 PARAMS((bfd
*, asection
*, struct ecoff_debug_info
*));
89 static boolean elf64_alpha_is_local_label
90 PARAMS((bfd
*, asymbol
*));
91 static boolean elf64_alpha_find_nearest_line
92 PARAMS((bfd
*, asection
*, asymbol
**, bfd_vma
, const char **,
93 const char **, unsigned int *));
95 #if defined(__STDC__) || defined(ALMOST_STDC)
96 struct alpha_elf_link_hash_entry
;
99 static boolean elf64_alpha_output_extsym
100 PARAMS((struct alpha_elf_link_hash_entry
*, PTR
));
102 static boolean elf64_alpha_check_relocs
103 PARAMS((bfd
*, struct bfd_link_info
*, asection
*sec
,
104 const Elf_Internal_Rela
*));
105 static boolean elf64_alpha_adjust_dynamic_symbol
106 PARAMS((struct bfd_link_info
*, struct elf_link_hash_entry
*));
107 static boolean elf64_alpha_size_dynamic_sections
108 PARAMS((bfd
*, struct bfd_link_info
*));
109 static boolean elf64_alpha_adjust_dynindx
110 PARAMS((struct elf_link_hash_entry
*, PTR
));
111 static boolean elf64_alpha_relocate_section
112 PARAMS((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
113 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
114 static boolean elf64_alpha_finish_dynamic_symbol
115 PARAMS((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
116 Elf_Internal_Sym
*));
117 static boolean elf64_alpha_finish_dynamic_sections
118 PARAMS((bfd
*, struct bfd_link_info
*));
119 static boolean elf64_alpha_final_link
120 PARAMS((bfd
*, struct bfd_link_info
*));
123 #define alpha_elf_tdata(bfd) \
124 ((struct alpha_elf_obj_tdata *)elf_tdata(bfd)->tdata)
126 struct alpha_elf_link_hash_entry
128 struct elf_link_hash_entry root
;
130 /* External symbol information. */
134 /* Contexts (LITUSE) in which a literal was referenced. */
135 #define ALPHA_ELF_LINK_HASH_LU_ADDR 01
136 #define ALPHA_ELF_LINK_HASH_LU_MEM 02
137 #define ALPHA_ELF_LINK_HASH_LU_FUNC 04
140 /* Alpha ELF linker hash table. */
142 struct alpha_elf_link_hash_table
144 struct elf_link_hash_table root
;
147 /* Look up an entry in a Alpha ELF linker hash table. */
149 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
150 ((struct alpha_elf_link_hash_entry *) \
151 elf_link_hash_lookup (&(table)->root, (string), (create), \
154 /* Traverse a Alpha ELF linker hash table. */
156 #define alpha_elf_link_hash_traverse(table, func, info) \
157 (elf_link_hash_traverse \
159 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
162 /* Get the Alpha ELF linker hash table from a link_info structure. */
164 #define alpha_elf_hash_table(p) \
165 ((struct alpha_elf_link_hash_table *) ((p)->hash))
167 /* Create an entry in a Alpha ELF linker hash table. */
169 static struct bfd_hash_entry
*
170 elf64_alpha_link_hash_newfunc (entry
, table
, string
)
171 struct bfd_hash_entry
*entry
;
172 struct bfd_hash_table
*table
;
175 struct alpha_elf_link_hash_entry
*ret
=
176 (struct alpha_elf_link_hash_entry
*) entry
;
178 /* Allocate the structure if it has not already been allocated by a
180 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
181 ret
= ((struct alpha_elf_link_hash_entry
*)
182 bfd_hash_allocate (table
,
183 sizeof (struct alpha_elf_link_hash_entry
)));
184 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
185 return (struct bfd_hash_entry
*) ret
;
187 /* Call the allocation method of the superclass. */
188 ret
= ((struct alpha_elf_link_hash_entry
*)
189 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
191 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
193 /* Set local fields. */
194 memset (&ret
->esym
, 0, sizeof (EXTR
));
195 /* We use -2 as a marker to indicate that the information has
196 not been set. -1 means there is no associated ifd. */
201 return (struct bfd_hash_entry
*) ret
;
204 /* Create a Alpha ELF linker hash table. */
206 static struct bfd_link_hash_table
*
207 elf64_alpha_bfd_link_hash_table_create (abfd
)
210 struct alpha_elf_link_hash_table
*ret
;
212 ret
= ((struct alpha_elf_link_hash_table
*)
213 bfd_zalloc (abfd
, sizeof (struct alpha_elf_link_hash_table
)));
214 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
217 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
218 elf64_alpha_link_hash_newfunc
))
220 bfd_release (abfd
, ret
);
224 return &ret
->root
.root
;
228 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
229 from smaller values. Start with zero, widen, *then* decrement. */
230 #define MINUS_ONE (((bfd_vma)0) - 1)
232 static reloc_howto_type elf64_alpha_howto_table
[] =
234 HOWTO (R_ALPHA_NONE
, /* type */
236 0, /* size (0 = byte, 1 = short, 2 = long) */
238 true, /* pc_relative */
240 complain_overflow_dont
, /* complain_on_overflow */
241 elf64_alpha_reloc_nil
, /* special_function */
243 false, /* partial_inplace */
246 true), /* pcrel_offset */
248 /* A 32 bit reference to a symbol. */
249 HOWTO (R_ALPHA_REFLONG
, /* type */
251 2, /* size (0 = byte, 1 = short, 2 = long) */
253 false, /* pc_relative */
255 complain_overflow_bitfield
, /* complain_on_overflow */
256 0, /* special_function */
257 "REFLONG", /* name */
258 false, /* partial_inplace */
259 0xffffffff, /* src_mask */
260 0xffffffff, /* dst_mask */
261 false), /* pcrel_offset */
263 /* A 64 bit reference to a symbol. */
264 HOWTO (R_ALPHA_REFQUAD
, /* type */
266 4, /* size (0 = byte, 1 = short, 2 = long) */
268 false, /* pc_relative */
270 complain_overflow_bitfield
, /* complain_on_overflow */
271 0, /* special_function */
272 "REFQUAD", /* name */
273 false, /* partial_inplace */
274 MINUS_ONE
, /* src_mask */
275 MINUS_ONE
, /* dst_mask */
276 false), /* pcrel_offset */
278 /* A 32 bit GP relative offset. This is just like REFLONG except
279 that when the value is used the value of the gp register will be
281 HOWTO (R_ALPHA_GPREL32
, /* type */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
285 false, /* pc_relative */
287 complain_overflow_bitfield
, /* complain_on_overflow */
288 0, /* special_function */
289 "GPREL32", /* name */
290 false, /* partial_inplace */
291 0xffffffff, /* src_mask */
292 0xffffffff, /* dst_mask */
293 false), /* pcrel_offset */
295 /* Used for an instruction that refers to memory off the GP register. */
296 HOWTO (R_ALPHA_LITERAL
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 false, /* pc_relative */
302 complain_overflow_signed
, /* complain_on_overflow */
303 0, /* special_function */
304 "LITERAL", /* name */
305 false, /* partial_inplace */
306 0xffff, /* src_mask */
307 0xffff, /* dst_mask */
308 false), /* pcrel_offset */
310 /* This reloc only appears immediately following a LITERAL reloc.
311 It identifies a use of the literal. The symbol index is special:
312 1 means the literal address is in the base register of a memory
313 format instruction; 2 means the literal address is in the byte
314 offset register of a byte-manipulation instruction; 3 means the
315 literal address is in the target register of a jsr instruction.
316 This does not actually do any relocation. */
317 HOWTO (R_ALPHA_LITUSE
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 false, /* pc_relative */
323 complain_overflow_dont
, /* complain_on_overflow */
324 elf64_alpha_reloc_nil
, /* special_function */
326 false, /* partial_inplace */
329 false), /* pcrel_offset */
331 /* Load the gp register. This is always used for a ldah instruction
332 which loads the upper 16 bits of the gp register. The symbol
333 index of the GPDISP instruction is an offset in bytes to the lda
334 instruction that loads the lower 16 bits. The value to use for
335 the relocation is the difference between the GP value and the
336 current location; the load will always be done against a register
337 holding the current address.
339 NOTE: Unlike ECOFF, partial inplace relocation is not done. If
340 any offset is present in the instructions, it is an offset from
341 the register to the ldah instruction. This lets us avoid any
342 stupid hackery like inventing a gp value to do partial relocation
343 against. Also unlike ECOFF, we do the whole relocation off of
344 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
345 space consuming bit, that, since all the information was present
346 in the GPDISP_HI16 reloc. */
347 HOWTO (R_ALPHA_GPDISP
, /* type */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
351 false, /* pc_relative */
353 complain_overflow_dont
, /* complain_on_overflow */
354 elf64_alpha_reloc_gpdisp
, /* special_function */
356 false, /* partial_inplace */
357 0xffff, /* src_mask */
358 0xffff, /* dst_mask */
359 true), /* pcrel_offset */
361 /* A 21 bit branch. */
362 HOWTO (R_ALPHA_BRADDR
, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 true, /* pc_relative */
368 complain_overflow_signed
, /* complain_on_overflow */
369 0, /* special_function */
371 false, /* partial_inplace */
372 0x1fffff, /* src_mask */
373 0x1fffff, /* dst_mask */
374 true), /* pcrel_offset */
376 /* A hint for a jump to a register. */
377 HOWTO (R_ALPHA_HINT
, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 true, /* pc_relative */
383 complain_overflow_dont
, /* complain_on_overflow */
384 0, /* special_function */
386 false, /* partial_inplace */
387 0x3fff, /* src_mask */
388 0x3fff, /* dst_mask */
389 true), /* pcrel_offset */
391 /* 16 bit PC relative offset. */
392 HOWTO (R_ALPHA_SREL16
, /* type */
394 1, /* size (0 = byte, 1 = short, 2 = long) */
396 true, /* pc_relative */
398 complain_overflow_signed
, /* complain_on_overflow */
399 0, /* special_function */
401 false, /* partial_inplace */
402 0xffff, /* src_mask */
403 0xffff, /* dst_mask */
404 false), /* pcrel_offset */
406 /* 32 bit PC relative offset. */
407 HOWTO (R_ALPHA_SREL32
, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 true, /* pc_relative */
413 complain_overflow_signed
, /* complain_on_overflow */
414 0, /* special_function */
416 false, /* partial_inplace */
417 0xffffffff, /* src_mask */
418 0xffffffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* A 64 bit PC relative offset. */
422 HOWTO (R_ALPHA_SREL64
, /* type */
424 4, /* size (0 = byte, 1 = short, 2 = long) */
426 true, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 0, /* special_function */
431 false, /* partial_inplace */
432 MINUS_ONE
, /* src_mask */
433 MINUS_ONE
, /* dst_mask */
434 false), /* pcrel_offset */
436 /* Push a value on the reloc evaluation stack. */
437 HOWTO (ALPHA_R_OP_PUSH
, /* type */
439 0, /* size (0 = byte, 1 = short, 2 = long) */
441 false, /* pc_relative */
443 complain_overflow_dont
, /* complain_on_overflow */
444 elf64_alpha_reloc_op_push
, /* special_function */
445 "OP_PUSH", /* name */
446 false, /* partial_inplace */
449 false), /* pcrel_offset */
451 /* Store the value from the stack at the given address. Store it in
452 a bitfield of size r_size starting at bit position r_offset. */
453 HOWTO (ALPHA_R_OP_STORE
, /* type */
455 4, /* size (0 = byte, 1 = short, 2 = long) */
457 false, /* pc_relative */
459 complain_overflow_dont
, /* complain_on_overflow */
460 elf64_alpha_reloc_op_store
, /* special_function */
461 "OP_STORE", /* name */
462 false, /* partial_inplace */
464 MINUS_ONE
, /* dst_mask */
465 false), /* pcrel_offset */
467 /* Subtract the reloc address from the value on the top of the
469 HOWTO (ALPHA_R_OP_PSUB
, /* type */
471 0, /* size (0 = byte, 1 = short, 2 = long) */
473 false, /* pc_relative */
475 complain_overflow_dont
, /* complain_on_overflow */
476 elf64_alpha_reloc_op_psub
, /* special_function */
477 "OP_PSUB", /* name */
478 false, /* partial_inplace */
481 false), /* pcrel_offset */
483 /* Shift the value on the top of the relocation stack right by the
485 HOWTO (ALPHA_R_OP_PRSHIFT
, /* type */
487 0, /* size (0 = byte, 1 = short, 2 = long) */
489 false, /* pc_relative */
491 complain_overflow_dont
, /* complain_on_overflow */
492 elf64_alpha_reloc_op_prshift
, /* special_function */
493 "OP_PRSHIFT", /* name */
494 false, /* partial_inplace */
497 false), /* pcrel_offset */
499 /* Misc ELF relocations. */
506 complain_overflow_dont
,
507 bfd_elf_generic_reloc
,
514 HOWTO (R_ALPHA_GLOB_DAT
,
520 complain_overflow_dont
,
521 bfd_elf_generic_reloc
,
528 HOWTO (R_ALPHA_JMP_SLOT
,
534 complain_overflow_dont
,
535 bfd_elf_generic_reloc
,
542 HOWTO (R_ALPHA_RELATIVE
,
548 complain_overflow_dont
,
549 bfd_elf_generic_reloc
,
557 static bfd_reloc_status_type
558 elf64_alpha_reloc_nil (abfd
, reloc
, sym
, data
, sec
, output_bfd
, error_message
)
565 char **error_message
;
568 reloc
->address
+= sec
->output_offset
;
572 static bfd_reloc_status_type
573 elf64_alpha_do_reloc_gpdisp (abfd
, gpdisp
, p_ldah
, p_lda
)
576 bfd_byte
*p_ldah
, *p_lda
;
578 bfd_reloc_status_type ret
= bfd_reloc_ok
;
580 unsigned long i_ldah
, i_lda
;
582 i_ldah
= bfd_get_32(abfd
, p_ldah
);
583 i_lda
= bfd_get_32(abfd
, p_lda
);
585 /* Complain if the instructions are not correct. */
586 if (((i_ldah
>> 26) & 0x3f) != 0x09
587 || ((i_lda
>> 26) & 0x3f) != 0x08)
588 ret
= bfd_reloc_dangerous
;
590 /* Extract the user-supplied offset, mirroring the sign extensions
591 that the instructions perform. */
592 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
593 addend
= (addend
^ 0x80008000) - 0x80008000;
597 if ((bfd_signed_vma
)gpdisp
< -(bfd_signed_vma
)0x80000000
598 || gpdisp
>= 0x7fff8000)
599 ret
= bfd_reloc_overflow
;
601 /* compensate for the sign extension again. */
602 i_ldah
= ((i_ldah
& 0xffff0000)
603 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
604 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
606 bfd_put_32 (abfd
, i_ldah
, p_ldah
);
607 bfd_put_32 (abfd
, i_lda
, p_lda
);
612 static bfd_reloc_status_type
613 elf64_alpha_reloc_gpdisp (abfd
, reloc_entry
, sym
, data
, input_section
,
616 arelent
*reloc_entry
;
619 asection
*input_section
;
623 bfd_reloc_status_type ret
;
624 bfd_vma gp
, relocation
;
625 bfd_byte
*p_ldah
, *p_lda
;
627 /* Don't do anything if we're not doing a final link. */
630 reloc_entry
->address
+= input_section
->output_offset
;
634 if (reloc_entry
->address
> input_section
->_cooked_size
||
635 reloc_entry
->address
+ reloc_entry
->addend
> input_section
->_cooked_size
)
636 return bfd_reloc_outofrange
;
638 /* The gp used in the portion of the output object to which this
639 input object belongs is cached on the input bfd. */
640 gp
= _bfd_get_gp_value (abfd
);
642 relocation
= (input_section
->output_section
->vma
643 + input_section
->output_offset
644 + reloc_entry
->address
);
646 p_ldah
= (bfd_byte
*)data
+ reloc_entry
->address
;
647 p_lda
= p_ldah
+ reloc_entry
->addend
;
649 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
651 /* Complain if the instructions are not correct. */
652 if (ret
== bfd_reloc_dangerous
)
654 *err_msg
= "GPDISP relocation did not find ldah and lda instructions";
660 /* Due to the nature of the stack operations, I don't think more
661 that one entry is useful. Test this theory by setting the
662 stack size to a minimum. */
663 /* FIXME: BFD should not use static variables. */
664 #define OP_STACK_SIZE 1
665 static bfd_vma elf64_alpha_op_stack
[OP_STACK_SIZE
];
666 static int elf64_alpha_op_tos
;
668 static bfd_reloc_status_type
669 elf64_alpha_reloc_op_push (abfd
, reloc_entry
, sym
, data
, input_section
,
672 arelent
*reloc_entry
;
675 asection
*input_section
;
679 bfd_reloc_status_type r
= bfd_reloc_ok
;
682 /* Don't do anything if we're not doing a final link. */
685 reloc_entry
->address
+= input_section
->output_offset
;
689 if (elf64_alpha_op_tos
>= OP_STACK_SIZE
)
691 *err_msg
= "operation stack overflow";
692 return bfd_reloc_dangerous
;
695 /* Get the symbol value. */
696 /* FIXME: We should fail if this is a dynamic symbol. Check on that. */
697 if (bfd_is_und_section (sym
->section
))
698 r
= bfd_reloc_undefined
;
699 if (bfd_is_com_section (sym
->section
))
703 value
+= sym
->section
->output_section
->vma
;
704 value
+= sym
->section
->output_offset
;
705 value
+= reloc_entry
->addend
;
707 elf64_alpha_op_stack
[elf64_alpha_op_tos
++] = value
;
712 static bfd_reloc_status_type
713 elf64_alpha_reloc_op_store (abfd
, reloc_entry
, sym
, data
, input_section
,
716 arelent
*reloc_entry
;
719 asection
*input_section
;
726 /* Don't do anything before the final link. */
729 reloc_entry
->address
+= input_section
->output_offset
;
733 if (elf64_alpha_op_tos
<= 0)
735 *err_msg
= "operation stack underflow";
736 return bfd_reloc_dangerous
;
739 /* The offset and size for this reloc are encoded into the addend
740 field by alpha_adjust_reloc_in. */
741 offset
= (reloc_entry
->addend
>> 8) & 0xff;
742 size
= reloc_entry
->addend
& 0xff;
744 value
= bfd_get_64 (abfd
, data
+ reloc_entry
->address
);
745 value
&= ~((((bfd_vma
)1 << size
) - 1) << offset
);
746 value
|= (elf64_alpha_op_stack
[--elf64_alpha_op_tos
]
747 & (((bfd_vma
)1 << size
) - 1)) << offset
;
748 bfd_put_64 (abfd
, value
, data
+ reloc_entry
->address
);
753 static bfd_reloc_status_type
754 elf64_alpha_reloc_op_psub (abfd
, reloc_entry
, sym
, data
, input_section
,
757 arelent
*reloc_entry
;
760 asection
*input_section
;
764 bfd_reloc_status_type r
;
767 /* Don't do anything before the final link. */
770 reloc_entry
->address
+= input_section
->output_offset
;
774 if (elf64_alpha_op_tos
<= 0)
776 *err_msg
= "operation stack underflow";
777 return bfd_reloc_dangerous
;
780 if (bfd_is_und_section (sym
->section
))
781 r
= bfd_reloc_undefined
;
782 if (bfd_is_com_section (sym
->section
))
786 value
+= sym
->section
->output_section
->vma
;
787 value
+= sym
->section
->output_offset
;
788 value
+= reloc_entry
->addend
;
790 elf64_alpha_op_stack
[elf64_alpha_op_tos
-1] -= value
;
795 static bfd_reloc_status_type
796 elf64_alpha_reloc_op_prshift (abfd
, reloc_entry
, sym
, data
, input_section
,
799 arelent
*reloc_entry
;
802 asection
*input_section
;
806 /* Don't do anything before the final link. */
809 reloc_entry
->address
+= input_section
->output_offset
;
813 if (elf64_alpha_op_tos
<= 0)
815 *err_msg
= "operation stack underflow";
816 return bfd_reloc_dangerous
;
819 elf64_alpha_op_stack
[elf64_alpha_op_tos
-1] >>= reloc_entry
->addend
;
824 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
828 bfd_reloc_code_real_type bfd_reloc_val
;
832 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
834 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
835 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
836 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
837 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
838 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
839 {BFD_RELOC_ALPHA_LITERAL
, R_ALPHA_LITERAL
},
840 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
841 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
842 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
843 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
844 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
845 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
846 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
848 {BFD_RELOC_ALPHA_OP_PUSH
, R_ALPHA_OP_PUSH
},
849 {BFD_RELOC_ALPHA_OP_STORE
, R_ALPHA_OP_STORE
},
850 {BFD_RELOC_ALPHA_OP_PSUB
, R_ALPHA_OP_PSUB
},
851 {BFD_RELOC_ALPHA_OP_PRSHIFT
, R_ALPHA_OP_PRSHIFT
}
855 /* Given a BFD reloc type, return a HOWTO structure. */
857 static reloc_howto_type
*
858 elf64_alpha_bfd_reloc_type_lookup (abfd
, code
)
860 bfd_reloc_code_real_type code
;
862 const struct elf_reloc_map
*i
, *e
;
863 i
= e
= elf64_alpha_reloc_map
;
864 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
867 if (i
->bfd_reloc_val
== code
)
868 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
873 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
876 elf64_alpha_info_to_howto (abfd
, cache_ptr
, dst
)
879 Elf64_Internal_Rela
*dst
;
883 r_type
= ELF64_R_TYPE(dst
->r_info
);
884 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
885 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
889 #define PLT_HEADER_SIZE 32
890 #define PLT_HEADER_WORD1 0xc3600000 /* br $27,.+4 */
891 #define PLT_HEADER_WORD2 0xa77b000c /* ldq $27,12($27) */
892 #define PLT_HEADER_WORD3 0x47ff041f /* nop */
893 #define PLT_HEADER_WORD4 0x6b7b0000 /* jmp $27,($27) */
895 #define PLT_ENTRY_SIZE 12
896 #define PLT_ENTRY_WORD1 0x279f0000 /* ldah $28, 0($31) */
897 #define PLT_ENTRY_WORD2 0x239c0000 /* lda $28, 0($28) */
898 #define PLT_ENTRY_WORD3 0xc3e00000 /* br $31, plt0 */
900 #define RESERVED_GOT_ENTRIES 1
902 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
904 /* Set the right machine number for an Alpha ELF file. */
907 elf64_alpha_object_p (abfd
)
910 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
913 /* Handle a alpha specific section when reading an object file. This
914 is called when elfcode.h finds a section with an unknown type.
915 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
919 elf64_alpha_section_from_shdr (abfd
, hdr
, name
)
921 Elf64_Internal_Shdr
*hdr
;
926 /* There ought to be a place to keep ELF backend specific flags, but
927 at the moment there isn't one. We just keep track of the
928 sections by their name, instead. Fortunately, the ABI gives
929 suggested names for all the MIPS specific sections, so we will
930 probably get away with this. */
931 switch (hdr
->sh_type
)
933 case SHT_ALPHA_DEBUG
:
934 if (strcmp (name
, ".mdebug") != 0)
938 case SHT_ALPHA_REGINFO
:
939 if (strcmp (name
, ".reginfo") != 0
940 || hdr
->sh_size
!= sizeof (Elf64_External_RegInfo
))
948 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
950 newsect
= hdr
->bfd_section
;
952 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
954 if (! bfd_set_section_flags (abfd
, newsect
,
955 (bfd_get_section_flags (abfd
, newsect
)
961 /* For a .reginfo section, set the gp value in the tdata information
962 from the contents of this section. We need the gp value while
963 processing relocs, so we just get it now. */
964 if (hdr
->sh_type
== SHT_ALPHA_REGINFO
)
966 Elf64_External_RegInfo ext
;
969 if (! bfd_get_section_contents (abfd
, newsect
, (PTR
) &ext
,
970 (file_ptr
) 0, sizeof ext
))
972 bfd_alpha_elf64_swap_reginfo_in (abfd
, &ext
, &s
);
973 elf_gp (abfd
) = s
.ri_gp_value
;
980 /* Set the correct type for an Alpha ELF section. We do this by the
981 section name, which is a hack, but ought to work. */
984 elf64_alpha_fake_sections (abfd
, hdr
, sec
)
986 Elf64_Internal_Shdr
*hdr
;
989 register const char *name
;
991 name
= bfd_get_section_name (abfd
, sec
);
993 if (strcmp (name
, ".mdebug") == 0)
995 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
996 /* In a shared object on Irix 5.3, the .mdebug section has an
997 entsize of 0. FIXME: Does this matter? */
998 if ((abfd
->flags
& DYNAMIC
) != 0 )
1001 hdr
->sh_entsize
= 1;
1003 #ifdef ERIC_neverdef
1004 else if (strcmp (name
, ".reginfo") == 0)
1006 hdr
->sh_type
= SHT_ALPHA_REGINFO
;
1007 /* In a shared object on Irix 5.3, the .reginfo section has an
1008 entsize of 0x18. FIXME: Does this matter? */
1009 if ((abfd
->flags
& DYNAMIC
) != 0)
1010 hdr
->sh_entsize
= sizeof (Elf64_External_RegInfo
);
1012 hdr
->sh_entsize
= 1;
1014 /* Force the section size to the correct value, even if the
1015 linker thinks it is larger. The link routine below will only
1016 write out this much data for .reginfo. */
1017 hdr
->sh_size
= sec
->_raw_size
= sizeof (Elf64_External_RegInfo
);
1019 else if (strcmp (name
, ".hash") == 0
1020 || strcmp (name
, ".dynamic") == 0
1021 || strcmp (name
, ".dynstr") == 0)
1023 hdr
->sh_entsize
= 0;
1024 hdr
->sh_info
= SIZEOF_ALPHA_DYNSYM_SECNAMES
;
1026 else if (strcmp (name
, ".sdata") == 0
1027 || strcmp (name
, ".sbss") == 0
1028 || strcmp (name
, ".lit4") == 0
1029 || strcmp (name
, ".lit8") == 0)
1030 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
1037 elf64_alpha_additional_program_headers (abfd
)
1045 s
= bfd_get_section_by_name (abfd
, ".reginfo");
1046 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
1048 /* We need a PT_ALPHA_REGINFO segment. */
1052 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
1053 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
1055 /* We need a PT_ALPHA_RTPROC segment. */
1063 elf64_alpha_create_got_section(abfd
, info
)
1065 struct bfd_link_info
*info
;
1068 struct elf_link_hash_entry
*h
;
1070 if (bfd_get_section_by_name (abfd
, ".got"))
1073 s
= bfd_make_section(abfd
, ".rela.got");
1075 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1076 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1078 || !bfd_set_section_alignment (abfd
, s
, 3))
1081 s
= bfd_make_section(abfd
, ".got");
1083 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1084 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
))
1085 || !bfd_set_section_alignment (abfd
, s
, 3))
1088 s
->_raw_size
= RESERVED_GOT_ENTRIES
* 8;
1090 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
1091 (or .got.plt) section. We don't do this in the linker script
1092 because we don't want to define the symbol if we are not creating
1093 a global offset table. */
1095 if (!(_bfd_generic_link_add_one_symbol
1096 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
, (bfd_vma
) 0,
1097 (const char *) NULL
, false, get_elf_backend_data (abfd
)->collect
,
1098 (struct bfd_link_hash_entry
**) &h
)))
1100 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1101 h
->type
= STT_OBJECT
;
1104 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1107 elf_hash_table (info
)->hgot
= h
;
1113 elf64_alpha_create_dynamic_sections (abfd
, info
)
1115 struct bfd_link_info
*info
;
1117 register asection
*s
;
1118 struct elf_link_hash_entry
*h
;
1120 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1122 s
= bfd_make_section (abfd
, ".plt");
1124 || ! bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1125 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1127 || ! bfd_set_section_alignment (abfd
, s
, 3))
1130 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1133 if (! (_bfd_generic_link_add_one_symbol
1134 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
1135 (bfd_vma
) 0, (const char *) NULL
, false,
1136 get_elf_backend_data (abfd
)->collect
,
1137 (struct bfd_link_hash_entry
**) &h
)))
1139 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1140 h
->type
= STT_OBJECT
;
1143 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1146 s
= bfd_make_section (abfd
, ".rela.plt");
1148 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1149 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1151 || ! bfd_set_section_alignment (abfd
, s
, 3))
1154 if (!elf64_alpha_create_got_section (abfd
, info
))
1160 /* The structure of the runtile procedure descriptor created by the
1161 loader for use by the static exception system. */
1165 /* Read ECOFF debugging information from a .mdebug section into a
1166 ecoff_debug_info structure. */
1169 elf64_alpha_read_ecoff_info (abfd
, section
, debug
)
1172 struct ecoff_debug_info
*debug
;
1175 const struct ecoff_debug_swap
*swap
;
1176 char *ext_hdr
= NULL
;
1178 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1180 ext_hdr
= (char *) bfd_malloc ((size_t) swap
->external_hdr_size
);
1181 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1184 if (bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1185 swap
->external_hdr_size
)
1189 symhdr
= &debug
->symbolic_header
;
1190 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1192 /* The symbolic header contains absolute file offsets and sizes to
1194 #define READ(ptr, offset, count, size, type) \
1195 if (symhdr->count == 0) \
1196 debug->ptr = NULL; \
1199 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \
1200 if (debug->ptr == NULL) \
1201 goto error_return; \
1202 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1203 || (bfd_read (debug->ptr, size, symhdr->count, \
1204 abfd) != size * symhdr->count)) \
1205 goto error_return; \
1208 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1209 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1210 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1211 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1212 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1213 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1215 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1216 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1217 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
1218 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
1219 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
1223 debug
->adjust
= NULL
;
1228 if (ext_hdr
!= NULL
)
1230 if (debug
->line
!= NULL
)
1232 if (debug
->external_dnr
!= NULL
)
1233 free (debug
->external_dnr
);
1234 if (debug
->external_pdr
!= NULL
)
1235 free (debug
->external_pdr
);
1236 if (debug
->external_sym
!= NULL
)
1237 free (debug
->external_sym
);
1238 if (debug
->external_opt
!= NULL
)
1239 free (debug
->external_opt
);
1240 if (debug
->external_aux
!= NULL
)
1241 free (debug
->external_aux
);
1242 if (debug
->ss
!= NULL
)
1244 if (debug
->ssext
!= NULL
)
1245 free (debug
->ssext
);
1246 if (debug
->external_fdr
!= NULL
)
1247 free (debug
->external_fdr
);
1248 if (debug
->external_rfd
!= NULL
)
1249 free (debug
->external_rfd
);
1250 if (debug
->external_ext
!= NULL
)
1251 free (debug
->external_ext
);
1255 /* Alpha ELF local labels start with '$'. */
1258 elf64_alpha_is_local_label (abfd
, symbol
)
1262 return symbol
->name
[0] == '$';
1265 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1266 routine in order to handle the ECOFF debugging information. We
1267 still call this mips_elf_find_line because of the slot
1268 find_line_info in elf_obj_tdata is declared that way. */
1270 struct mips_elf_find_line
1272 struct ecoff_debug_info d
;
1273 struct ecoff_find_line i
;
1277 elf64_alpha_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
1278 functionname_ptr
, line_ptr
)
1283 const char **filename_ptr
;
1284 const char **functionname_ptr
;
1285 unsigned int *line_ptr
;
1289 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
1293 struct mips_elf_find_line
*fi
;
1294 const struct ecoff_debug_swap
* const swap
=
1295 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1297 /* If we are called during a link, alpha_elf_final_link may have
1298 cleared the SEC_HAS_CONTENTS field. We force it back on here
1299 if appropriate (which it normally will be). */
1300 origflags
= msec
->flags
;
1301 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
1302 msec
->flags
|= SEC_HAS_CONTENTS
;
1304 fi
= elf_tdata (abfd
)->find_line_info
;
1307 bfd_size_type external_fdr_size
;
1310 struct fdr
*fdr_ptr
;
1312 fi
= ((struct mips_elf_find_line
*)
1313 bfd_zalloc (abfd
, sizeof (struct mips_elf_find_line
)));
1316 msec
->flags
= origflags
;
1320 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
1322 msec
->flags
= origflags
;
1326 /* Swap in the FDR information. */
1327 fi
->d
.fdr
= ((struct fdr
*)
1329 (fi
->d
.symbolic_header
.ifdMax
*
1330 sizeof (struct fdr
))));
1331 if (fi
->d
.fdr
== NULL
)
1333 msec
->flags
= origflags
;
1336 external_fdr_size
= swap
->external_fdr_size
;
1337 fdr_ptr
= fi
->d
.fdr
;
1338 fraw_src
= (char *) fi
->d
.external_fdr
;
1339 fraw_end
= (fraw_src
1340 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
1341 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
1342 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
1344 elf_tdata (abfd
)->find_line_info
= fi
;
1346 /* Note that we don't bother to ever free this information.
1347 find_nearest_line is either called all the time, as in
1348 objdump -l, so the information should be saved, or it is
1349 rarely called, as in ld error messages, so the memory
1350 wasted is unimportant. Still, it would probably be a
1351 good idea for free_cached_info to throw it away. */
1354 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
1355 &fi
->i
, filename_ptr
, functionname_ptr
,
1358 msec
->flags
= origflags
;
1362 msec
->flags
= origflags
;
1365 /* Fall back on the generic ELF find_nearest_line routine. */
1367 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
1368 filename_ptr
, functionname_ptr
,
1372 /* Structure used to pass information to alpha_elf_output_extsym. */
1377 struct bfd_link_info
*info
;
1378 struct ecoff_debug_info
*debug
;
1379 const struct ecoff_debug_swap
*swap
;
1384 elf64_alpha_output_extsym (h
, data
)
1385 struct alpha_elf_link_hash_entry
*h
;
1388 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1390 asection
*sec
, *output_section
;
1392 if (h
->root
.indx
== -2)
1394 else if (((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1395 || (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
1396 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
1397 && (h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
1399 else if (einfo
->info
->strip
== strip_all
1400 || (einfo
->info
->strip
== strip_some
1401 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1402 h
->root
.root
.root
.string
,
1403 false, false) == NULL
))
1411 if (h
->esym
.ifd
== -2)
1414 h
->esym
.cobol_main
= 0;
1415 h
->esym
.weakext
= 0;
1416 h
->esym
.reserved
= 0;
1417 h
->esym
.ifd
= ifdNil
;
1418 h
->esym
.asym
.value
= 0;
1419 h
->esym
.asym
.st
= stGlobal
;
1421 if (h
->root
.root
.type
!= bfd_link_hash_defined
1422 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1423 h
->esym
.asym
.sc
= scAbs
;
1428 sec
= h
->root
.root
.u
.def
.section
;
1429 output_section
= sec
->output_section
;
1431 /* When making a shared library and symbol h is the one from
1432 the another shared library, OUTPUT_SECTION may be null. */
1433 if (output_section
== NULL
)
1434 h
->esym
.asym
.sc
= scUndefined
;
1437 name
= bfd_section_name (output_section
->owner
, output_section
);
1439 if (strcmp (name
, ".text") == 0)
1440 h
->esym
.asym
.sc
= scText
;
1441 else if (strcmp (name
, ".data") == 0)
1442 h
->esym
.asym
.sc
= scData
;
1443 else if (strcmp (name
, ".sdata") == 0)
1444 h
->esym
.asym
.sc
= scSData
;
1445 else if (strcmp (name
, ".rodata") == 0
1446 || strcmp (name
, ".rdata") == 0)
1447 h
->esym
.asym
.sc
= scRData
;
1448 else if (strcmp (name
, ".bss") == 0)
1449 h
->esym
.asym
.sc
= scBss
;
1450 else if (strcmp (name
, ".sbss") == 0)
1451 h
->esym
.asym
.sc
= scSBss
;
1452 else if (strcmp (name
, ".init") == 0)
1453 h
->esym
.asym
.sc
= scInit
;
1454 else if (strcmp (name
, ".fini") == 0)
1455 h
->esym
.asym
.sc
= scFini
;
1457 h
->esym
.asym
.sc
= scAbs
;
1461 h
->esym
.asym
.reserved
= 0;
1462 h
->esym
.asym
.index
= indexNil
;
1465 if (h
->root
.root
.type
== bfd_link_hash_common
)
1466 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1467 else if (h
->root
.root
.type
== bfd_link_hash_defined
1468 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1470 if (h
->esym
.asym
.sc
== scCommon
)
1471 h
->esym
.asym
.sc
= scBss
;
1472 else if (h
->esym
.asym
.sc
== scSCommon
)
1473 h
->esym
.asym
.sc
= scSBss
;
1475 sec
= h
->root
.root
.u
.def
.section
;
1476 output_section
= sec
->output_section
;
1477 if (output_section
!= NULL
)
1478 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1479 + sec
->output_offset
1480 + output_section
->vma
);
1482 h
->esym
.asym
.value
= 0;
1484 else if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1486 /* Set type and value for a symbol with a function stub. */
1487 h
->esym
.asym
.st
= stProc
;
1488 sec
= h
->root
.root
.u
.def
.section
;
1490 h
->esym
.asym
.value
= 0;
1493 output_section
= sec
->output_section
;
1494 if (output_section
!= NULL
)
1495 h
->esym
.asym
.value
= (h
->root
.plt_offset
1496 + sec
->output_offset
1497 + output_section
->vma
);
1499 h
->esym
.asym
.value
= 0;
1506 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1507 h
->root
.root
.root
.string
,
1510 einfo
->failed
= true;
1517 /* FIXME: Create a runtime procedure table from the .mdebug section.
1520 mips_elf_create_procedure_table (handle, abfd, info, s, debug)
1523 struct bfd_link_info *info;
1525 struct ecoff_debug_info *debug;
1530 elf64_alpha_check_relocs (abfd
, info
, sec
, relocs
)
1532 struct bfd_link_info
*info
;
1534 const Elf_Internal_Rela
*relocs
;
1540 Elf_Internal_Shdr
*symtab_hdr
;
1541 struct elf_link_hash_entry
**sym_hashes
;
1542 const Elf_Internal_Rela
*rel
, *relend
;
1544 if (info
->relocateable
)
1547 sgot
= srelgot
= sreloc
= NULL
;
1548 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
1549 sym_hashes
= elf_sym_hashes(abfd
);
1550 dynobj
= elf_hash_table(info
)->dynobj
;
1553 sgot
= bfd_get_section_by_name(dynobj
, ".got");
1554 srelgot
= bfd_get_section_by_name(dynobj
, ".rela.got");
1557 relend
= relocs
+ sec
->reloc_count
;
1558 for (rel
= relocs
; rel
< relend
; ++rel
)
1560 unsigned long r_symndx
;
1561 struct alpha_elf_link_hash_entry
*h
;
1563 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1564 if (r_symndx
< symtab_hdr
->sh_info
)
1567 h
= ((struct alpha_elf_link_hash_entry
*)
1568 sym_hashes
[r_symndx
- symtab_hdr
->sh_info
]);
1570 switch (ELF64_R_TYPE (rel
->r_info
))
1572 case R_ALPHA_LITERAL
:
1573 /* If this is a load of a function symbol and we are building a
1574 shared library or calling a shared library, then we need a
1577 We can tell if it is a function either by noticing the
1578 type of the symbol, or, if the type is undefined, by
1579 noticing that we have a LITUSE(3) reloc next.
1581 Note that it is not fatal to be wrong guessing that a symbol
1582 is an object, but it is fatal to be wrong guessing that a
1583 symbol is a function.
1585 Furthermore, the .plt trampoline does not give constant
1586 function addresses, so if we ever see a function's address
1587 taken, we cannot do lazy binding on that function. */
1592 && ELF64_R_TYPE (rel
[1].r_info
) == R_ALPHA_LITUSE
)
1594 switch (rel
[1].r_addend
)
1596 case 1: /* Memory reference */
1597 h
->flags
|= ALPHA_ELF_LINK_HASH_LU_MEM
;
1599 case 3: /* Call reference */
1600 h
->flags
|= ALPHA_ELF_LINK_HASH_LU_FUNC
;
1605 h
->flags
|= ALPHA_ELF_LINK_HASH_LU_ADDR
;
1607 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
1609 || !(h
->root
.elf_link_hash_flags
1610 & ELF_LINK_HASH_DEF_REGULAR
))
1611 && (h
->root
.type
== STT_FUNC
1612 || (h
->root
.type
== STT_NOTYPE
1613 && (h
->flags
& ALPHA_ELF_LINK_HASH_LU_FUNC
))))
1615 h
->root
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1621 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
1623 /* Create the .got section. */
1624 if (!elf64_alpha_create_got_section(dynobj
, info
))
1627 sgot
= bfd_get_section_by_name(dynobj
, ".got");
1628 srelgot
= bfd_get_section_by_name(dynobj
, ".rela.got");
1633 if (h
->root
.got_offset
!= MINUS_ONE
)
1635 /* We have already allocated space in this .got. */
1639 /* Make sure this becomes a dynamic symbol. */
1640 if (h
->root
.dynindx
== -1
1641 && ! _bfd_elf_link_record_dynamic_symbol (info
, &h
->root
))
1644 /* Reserve space for a reloc even if we won't use it. */
1645 srelgot
->_raw_size
+= sizeof(Elf64_External_Rela
);
1647 /* Create the relocation in adjust_dynamic_symbol */
1649 h
->root
.got_offset
= sgot
->_raw_size
;
1650 sgot
->_raw_size
+= 8;
1654 bfd_vma
*lgotoff
= elf_local_got_offsets(abfd
);
1655 if (lgotoff
== NULL
)
1659 size
= elf_tdata(abfd
)->symtab_hdr
.sh_info
* sizeof(bfd_vma
);
1660 lgotoff
= (bfd_vma
*)bfd_alloc(abfd
, size
);
1661 if (lgotoff
== NULL
)
1664 elf_local_got_offsets(abfd
) = lgotoff
;
1665 memset(lgotoff
, -1, size
);
1668 if (lgotoff
[ELF64_R_SYM(rel
->r_info
)] != MINUS_ONE
)
1670 /* We have already allocated space in the .got. */
1673 lgotoff
[ELF64_R_SYM(rel
->r_info
)] = sgot
->_raw_size
;
1674 sgot
->_raw_size
+= 8;
1678 /* If we are generating a shared object, we need to
1679 output a R_ALPHA_RELATIVE reloc so that the dynamic
1680 linker can adjust this GOT entry. */
1681 srelgot
->_raw_size
+= sizeof(Elf64_External_Rela
);
1686 case R_ALPHA_SREL16
:
1687 case R_ALPHA_SREL32
:
1688 case R_ALPHA_SREL64
:
1693 case R_ALPHA_REFLONG
:
1694 case R_ALPHA_REFQUAD
:
1697 && !(h
->root
.elf_link_hash_flags
1698 & ELF_LINK_HASH_DEF_REGULAR
)))
1700 /* When creating a shared object or referring to a symbol in
1701 a shared object, we must copy these relocs into the
1702 object file. We create a reloc section in dynobj and
1703 make room for the reloc. */
1707 name
= (bfd_elf_string_from_elf_section
1708 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1709 elf_section_data(sec
)->rel_hdr
.sh_name
));
1713 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1714 && strcmp (bfd_get_section_name (abfd
, sec
),
1717 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1720 sreloc
= bfd_make_section (dynobj
, name
);
1722 || !bfd_set_section_flags (dynobj
, sreloc
,
1727 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
1731 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
1740 /* Adjust a symbol defined by a dynamic object and referenced by a
1741 regular object. The current definition is in some section of the
1742 dynamic object, but we're not including those sections. We have to
1743 change the definition to something the rest of the link can
1747 elf64_alpha_adjust_dynamic_symbol (info
, h
)
1748 struct bfd_link_info
*info
;
1749 struct elf_link_hash_entry
*h
;
1754 dynobj
= elf_hash_table(info
)->dynobj
;
1756 /* If this is a function, put it in the procedure linkage table. We
1757 will fill in the contents of the procedure linkage table later,
1758 though we could actually do it here. */
1760 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1762 /* We hadn't seen all of the input symbols or all of the relocations
1763 when we guessed that we needed a .plt entry. Revise our decision. */
1765 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1766 || (((struct alpha_elf_link_hash_entry
*) h
)->flags
1767 & ALPHA_ELF_LINK_HASH_LU_ADDR
))
1769 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1773 s
= bfd_get_section_by_name(dynobj
, ".plt");
1774 BFD_ASSERT(s
!= NULL
);
1776 /* The first bit of the .plt is reserved. */
1777 if (s
->_raw_size
== 0)
1778 s
->_raw_size
= PLT_HEADER_SIZE
;
1780 h
->plt_offset
= s
->_raw_size
;
1782 /* If this symbol is not defined in a regular file, and we are not
1783 generating a shared library, then set the symbol to the location
1784 in the .plt. This is required to make function pointers compare
1785 equal between the normal executable and the shared library. */
1788 h
->root
.u
.def
.section
= s
;
1789 h
->root
.u
.def
.value
= s
->_raw_size
;
1792 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1794 /* We also need an entry in the .rela.plt section. */
1795 s
= bfd_get_section_by_name(dynobj
, ".rela.plt");
1796 BFD_ASSERT(s
!= NULL
);
1797 s
->_raw_size
+= sizeof(Elf64_External_Rela
);
1802 /* If this is a weak symbol, and there is a real definition, the
1803 processor independent code will have arranged for us to see the
1804 real definition first, and we can just use the same value. */
1805 if (h
->weakdef
!= NULL
)
1807 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1808 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1809 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1810 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1814 /* This is a reference to a symbol defined by a dynamic object which
1815 is not a function. The Alpha, since it uses .got entries for
1816 symbols even in regular objects, does not need the hackery of a
1817 .dynbss section and COPY dynamic relocations. */
1822 /* Set the sizes of the dynamic sections. */
1825 elf64_alpha_size_dynamic_sections (output_bfd
, info
)
1827 struct bfd_link_info
*info
;
1834 dynobj
= elf_hash_table(info
)->dynobj
;
1835 BFD_ASSERT(dynobj
!= NULL
);
1837 if (elf_hash_table(info
)->dynamic_sections_created
)
1839 /* Set the contents of the .interp section to the interpreter. */
1842 s
= bfd_get_section_by_name(dynobj
, ".interp");
1843 BFD_ASSERT(s
!= NULL
);
1844 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1845 s
->contents
= (unsigned char *)ELF_DYNAMIC_INTERPRETER
;
1850 /* We may have created entries in the .rela.got section.
1851 However, if we are not creating the dynamic sections, we will
1852 not actually use these entries. Reset the size of .rel.got,
1853 which will cause it to get stripped from the output file
1855 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1860 /* The check_relocs and adjust_dynamic_symbol entry points have
1861 determined the sizes of the various dynamic sections. Allocate
1865 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1870 if (!(s
->flags
& SEC_IN_MEMORY
))
1873 /* It's OK to base decisions on the section name, because none
1874 of the dynobj section names depend upon the input files. */
1875 name
= bfd_get_section_name(dynobj
, s
);
1877 /* If we don't need this section, strip it from the output file.
1878 This is to handle .rela.bss and .rela.plt. We must create it
1879 in create_dynamic_sections, because it must be created before
1880 the linker maps input sections to output sections. The
1881 linker does that before adjust_dynamic_symbol is called, and
1882 it is that function which decides whether anything needs to
1883 go into these sections. */
1887 if (strncmp(name
, ".rela", 5) == 0)
1889 strip
= (s
->_raw_size
== 0);
1895 /* If this relocation section applies to a read only
1896 section, then we probably need a DT_TEXTREL entry. */
1897 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
1899 && (target
->flags
& SEC_READONLY
) != 0)
1902 if (strcmp(name
, ".rela.plt") == 0)
1905 /* We use the reloc_count field as a counter if we need
1906 to copy relocs into the output file. */
1910 else if (strcmp(name
, ".got") == 0)
1912 /* If we are generating a shared library, we generate a
1913 section symbol for each output section. These are local
1914 symbols, which means that they must come first in the
1915 dynamic symbol table. That means we must increment the
1916 dynamic symbol index of every other dynamic symbol. */
1923 c
[1] = bfd_count_sections(output_bfd
);
1925 elf_link_hash_traverse (elf_hash_table(info
),
1926 elf64_alpha_adjust_dynindx
,
1928 elf_hash_table (info
)->dynsymcount
+= c
[1];
1930 for (i
= 1, p
= output_bfd
->sections
;
1934 elf_section_data (p
)->dynindx
= i
;
1935 /* These symbols will have no names, so we don't need to
1936 fiddle with dynstr_index. */
1940 else if (strcmp (name
, ".plt") != 0)
1942 /* It's not one of our sections, so don't allocate space. */
1950 for (spp
= &s
->output_section
->owner
->sections
;
1951 *spp
!= s
->output_section
;
1952 spp
= &(*spp
)->next
)
1954 *spp
= s
->output_section
->next
;
1955 --s
->output_section
->owner
->section_count
;
1960 /* Allocate memory for the section contents. */
1961 s
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, s
->_raw_size
);
1962 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1966 if (elf_hash_table (info
)->dynamic_sections_created
)
1968 /* Add some entries to the .dynamic section. We fill in the
1969 values later, in elf64_alpha_finish_dynamic_sections, but we
1970 must add the entries now so that we get the correct size for
1971 the .dynamic section. The DT_DEBUG entry is filled in by the
1972 dynamic linker and used by the debugger. */
1975 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
1979 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0))
1984 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1985 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1986 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
1990 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
1991 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
1992 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
1993 sizeof(Elf64_External_Rela
)))
1998 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2006 /* Increment the index of a dynamic symbol by a given amount. Called
2007 via elf_link_hash_traverse. */
2010 elf64_alpha_adjust_dynindx (h
, cparg
)
2011 struct elf_link_hash_entry
*h
;
2014 long *cp
= (long *)cparg
;
2016 if (h
->dynindx
>= cp
[0])
2017 h
->dynindx
+= cp
[1];
2022 /* Relocate an Alpha ELF section. */
2025 elf64_alpha_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2026 contents
, relocs
, local_syms
, local_sections
)
2028 struct bfd_link_info
*info
;
2030 asection
*input_section
;
2032 Elf_Internal_Rela
*relocs
;
2033 Elf_Internal_Sym
*local_syms
;
2034 asection
**local_sections
;
2036 Elf_Internal_Shdr
*symtab_hdr
;
2037 Elf_Internal_Rela
*rel
;
2038 Elf_Internal_Rela
*relend
;
2039 asection
*sec
, *sgot
, *splt
;
2043 symtab_hdr
= &elf_tdata(input_bfd
)->symtab_hdr
;
2045 /* Find the gp value for this input bfd. */
2048 dynobj
= elf_hash_table(info
)->dynobj
;
2051 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2052 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2054 gp
= _bfd_get_gp_value(dynobj
);
2057 gp
= (sgot
->output_section
->vma
2058 + sgot
->output_offset
2060 _bfd_set_gp_value(dynobj
, gp
);
2065 relend
= relocs
+ input_section
->reloc_count
;
2066 for (; rel
< relend
; rel
++)
2069 reloc_howto_type
*howto
;
2070 unsigned long r_symndx
;
2071 struct elf_link_hash_entry
*h
;
2072 Elf_Internal_Sym
*sym
;
2075 bfd_reloc_status_type r
;
2077 r_type
= ELF64_R_TYPE(rel
->r_info
);
2078 if (r_type
< 0 || r_type
>= (int) R_ALPHA_max
)
2080 bfd_set_error (bfd_error_bad_value
);
2083 howto
= elf64_alpha_howto_table
+ r_type
;
2085 r_symndx
= ELF64_R_SYM(rel
->r_info
);
2087 if (info
->relocateable
)
2089 /* This is a relocateable link. We don't have to change
2090 anything, unless the reloc is against a section symbol,
2091 in which case we have to adjust according to where the
2092 section symbol winds up in the output section. */
2093 if (r_symndx
< symtab_hdr
->sh_info
)
2095 sym
= local_syms
+ r_symndx
;
2096 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
2098 sec
= local_sections
[r_symndx
];
2099 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2106 /* This is a final link. */
2112 if (r_symndx
< symtab_hdr
->sh_info
)
2114 sym
= local_syms
+ r_symndx
;
2115 sec
= local_sections
[r_symndx
];
2116 relocation
= (sec
->output_section
->vma
2117 + sec
->output_offset
2122 h
= elf_sym_hashes(input_bfd
)[r_symndx
- symtab_hdr
->sh_info
];
2124 while (h
->root
.type
== bfd_link_hash_indirect
2125 || h
->root
.type
== bfd_link_hash_warning
)
2126 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
2128 if (h
->root
.type
== bfd_link_hash_defined
2129 || h
->root
.type
== bfd_link_hash_defweak
)
2131 sec
= h
->root
.u
.def
.section
;
2133 /* If the symbol was defined as a common symbol in a
2134 regular object file, and there was no definition in
2135 any dynamic object, then the linker will have
2136 allocated space for the symbol in a common section
2137 but the ELF_LINK_HASH_DEF_REGULAR flag will not have
2138 been set. This is done for dynamic symbols in
2139 elf_adjust_dynamic_symbol but this is not done for
2140 non-dynamic symbols, somehow. */
2141 if ((h
->elf_link_hash_flags
2142 & (ELF_LINK_HASH_DEF_REGULAR
2143 | ELF_LINK_HASH_REF_REGULAR
2144 | ELF_LINK_HASH_DEF_DYNAMIC
))
2145 == ELF_LINK_HASH_REF_REGULAR
2146 && !(sec
->owner
->flags
& DYNAMIC
))
2147 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2150 if ((r_type
== R_ALPHA_LITERAL
2151 && elf_hash_table(info
)->dynamic_sections_created
2154 || !(h
->elf_link_hash_flags
2155 & ELF_LINK_HASH_DEF_REGULAR
)))
2158 || !(h
->elf_link_hash_flags
2159 & ELF_LINK_HASH_DEF_REGULAR
))
2160 && (input_section
->flags
& SEC_ALLOC
)
2161 && (r_type
== R_ALPHA_REFLONG
2162 || r_type
== R_ALPHA_REFQUAD
2163 || r_type
== R_ALPHA_LITERAL
)))
2165 /* In these cases, we don't need the relocation value.
2166 We check specially because in some obscure cases
2167 sec->output_section will be NULL. */
2171 /* FIXME: Are not these obscure cases simply bugs? Let's
2172 get something working and come back to this. */
2173 if (sec
->output_section
== NULL
)
2175 #endif /* rth_notdef */
2178 relocation
= (h
->root
.u
.def
.value
2179 + sec
->output_section
->vma
2180 + sec
->output_offset
);
2183 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2185 else if (info
->shared
&& !info
->symbolic
)
2189 if (!((*info
->callbacks
->undefined_symbol
)
2190 (info
, h
->root
.root
.string
, input_bfd
,
2191 input_section
, rel
->r_offset
)))
2196 addend
= rel
->r_addend
;
2200 case R_ALPHA_GPDISP
:
2202 bfd_byte
*p_ldah
, *p_lda
;
2204 relocation
= (input_section
->output_section
->vma
2205 + input_section
->output_offset
2208 p_ldah
= contents
+ rel
->r_offset
- input_section
->vma
;
2209 p_lda
= p_ldah
+ rel
->r_addend
;
2211 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- relocation
,
2216 case R_ALPHA_OP_PUSH
:
2217 case R_ALPHA_OP_STORE
:
2218 case R_ALPHA_OP_PSUB
:
2219 case R_ALPHA_OP_PRSHIFT
:
2223 case R_ALPHA_LITERAL
:
2227 BFD_ASSERT(gp
!= 0);
2228 BFD_ASSERT(sgot
!= NULL
);
2231 gotoff
= h
->got_offset
;
2235 gotoff
= elf_local_got_offsets (input_bfd
)[r_symndx
];
2237 /* Use the lsb as a flag indicating that we've already
2238 output the relocation entry. */
2241 gotoff
&= ~(bfd_vma
)1;
2245 Elf_Internal_Rela outrel
;
2247 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2248 BFD_ASSERT(srel
!= NULL
);
2250 outrel
.r_offset
= (sgot
->output_section
->vma
2251 + sgot
->output_offset
+ gotoff
);
2252 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
2253 outrel
.r_addend
= 0;
2255 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2256 ((Elf64_External_Rela
*)
2258 + srel
->reloc_count
++);
2260 elf_local_got_offsets (input_bfd
)[r_symndx
] |= 1;
2264 /* Initialize the .got entry. */
2265 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ gotoff
);
2267 /* Figure the gprel relocation. */
2269 relocation
= (sgot
->output_section
->vma
2270 + sgot
->output_offset
2274 /* overflow handled by _bfd_final_link_relocate */
2277 case R_ALPHA_GPREL32
:
2278 BFD_ASSERT(gp
!= 0);
2282 case R_ALPHA_BRADDR
:
2284 /* The regular PC-relative stuff measures from the start of
2285 the instruction rather than the end. */
2289 case R_ALPHA_REFLONG
:
2290 case R_ALPHA_REFQUAD
:
2292 || (h
&& !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2296 Elf_Internal_Rela outrel
;
2298 name
= (bfd_elf_string_from_elf_section
2299 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
2300 elf_section_data(input_section
)->rel_hdr
.sh_name
));
2301 BFD_ASSERT(name
!= NULL
);
2303 srel
= bfd_get_section_by_name(dynobj
, name
);
2304 BFD_ASSERT(srel
!= NULL
);
2306 outrel
.r_offset
= (input_section
->output_section
->vma
2307 + input_section
->output_offset
2309 outrel
.r_addend
= 0;
2312 BFD_ASSERT(h
->dynindx
!= -1);
2313 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, r_type
);
2318 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
2321 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2322 ((Elf64_External_Rela
*)
2324 + srel
->reloc_count
++);
2330 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2331 contents
, rel
->r_offset
, relocation
,
2341 case bfd_reloc_overflow
:
2346 name
= h
->root
.root
.string
;
2349 name
= (bfd_elf_string_from_elf_section
2350 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2354 name
= bfd_section_name (input_bfd
, sec
);
2356 if (! ((*info
->callbacks
->reloc_overflow
)
2357 (info
, name
, howto
->name
, (bfd_vma
) 0,
2358 input_bfd
, input_section
, rel
->r_offset
)))
2364 case bfd_reloc_outofrange
:
2372 /* Finish up dynamic symbol handling. We set the contents of various
2373 dynamic sections here. */
2376 elf64_alpha_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2378 struct bfd_link_info
*info
;
2379 struct elf_link_hash_entry
*h
;
2380 Elf_Internal_Sym
*sym
;
2382 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
2384 if (h
->plt_offset
!= MINUS_ONE
)
2386 asection
*splt
, *sgot
, *srel
;
2387 Elf_Internal_Rela outrel
;
2388 bfd_vma got_addr
, plt_addr
;
2391 /* This symbol has an entry in the procedure linkage table. */
2393 BFD_ASSERT(h
->dynindx
!= -1);
2394 BFD_ASSERT(h
->got_offset
!= MINUS_ONE
);
2396 splt
= bfd_get_section_by_name(dynobj
, ".plt");
2397 BFD_ASSERT(splt
!= NULL
);
2398 srel
= bfd_get_section_by_name(dynobj
, ".rela.plt");
2399 BFD_ASSERT(srel
!= NULL
);
2400 sgot
= bfd_get_section_by_name(dynobj
, ".got");
2401 BFD_ASSERT(sgot
!= NULL
);
2403 got_addr
= (sgot
->output_section
->vma
2404 + sgot
->output_offset
2406 plt_addr
= (splt
->output_section
->vma
2407 + splt
->output_offset
2410 plt_index
= (h
->plt_offset
- PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
2412 /* Fill in the entry in the procedure linkage table. */
2414 unsigned insn1
, insn2
, insn3
;
2417 /* decompose the reloc offset for the plt for ldah+lda */
2418 hi
= plt_index
* sizeof(Elf64_External_Rela
);
2419 lo
= ((hi
& 0xffff) ^ 0x8000) - 0x8000;
2420 hi
= (hi
- lo
) >> 16;
2422 insn1
= PLT_ENTRY_WORD1
| (hi
& 0xffff);
2423 insn2
= PLT_ENTRY_WORD2
| (lo
& 0xffff);
2424 insn3
= PLT_ENTRY_WORD3
| ((-(h
->plt_offset
+ 12) >> 2) & 0x1fffff);
2426 bfd_put_32 (output_bfd
, insn1
, splt
->contents
+ h
->plt_offset
);
2427 bfd_put_32 (output_bfd
, insn2
, splt
->contents
+ h
->plt_offset
+ 4);
2428 bfd_put_32 (output_bfd
, insn3
, splt
->contents
+ h
->plt_offset
+ 8);
2431 /* Fill in the entry in the .rela.plt section. */
2432 outrel
.r_offset
= got_addr
;
2433 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
2434 outrel
.r_addend
= 0;
2436 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2437 ((Elf64_External_Rela
*)srel
->contents
2440 if (!(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2442 /* Mark the symbol as undefined, rather than as defined in the
2443 .plt section. Leave the value alone. */
2444 sym
->st_shndx
= SHN_UNDEF
;
2447 /* Fill in the entry in the global offset table. */
2448 bfd_put_64 (output_bfd
, plt_addr
, sgot
->contents
+ h
->got_offset
);
2450 else if (h
->got_offset
!= MINUS_ONE
)
2452 asection
*sgot
, *srel
;
2453 Elf_Internal_Rela outrel
;
2455 BFD_ASSERT(h
->dynindx
!= -1);
2457 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2458 BFD_ASSERT (sgot
!= NULL
);
2459 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2460 BFD_ASSERT (srel
!= NULL
);
2462 outrel
.r_offset
= (sgot
->output_section
->vma
2463 + sgot
->output_offset
2465 outrel
.r_addend
= 0;
2468 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2469 outrel
.r_info
= ELF64_R_INFO(0, R_ALPHA_RELATIVE
);
2472 bfd_put_64(output_bfd
, (bfd_vma
)0, sgot
->contents
+ h
->got_offset
);
2473 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_GLOB_DAT
);
2476 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2477 ((Elf64_External_Rela
*)srel
->contents
2478 + srel
->reloc_count
++));
2481 /* Mark some specially defined symbols as absolute. */
2482 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2483 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2484 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2485 sym
->st_shndx
= SHN_ABS
;
2490 /* Finish up the dynamic sections. */
2493 elf64_alpha_finish_dynamic_sections (output_bfd
, info
)
2495 struct bfd_link_info
*info
;
2501 dynobj
= elf_hash_table (info
)->dynobj
;
2502 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2504 if (elf_hash_table (info
)->dynamic_sections_created
)
2507 Elf64_External_Dyn
*dyncon
, *dynconend
;
2509 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2510 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2512 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2513 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2514 for (; dyncon
< dynconend
; dyncon
++)
2516 Elf_Internal_Dyn dyn
;
2520 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2535 /* My interpretation of the TIS v1.1 ELF document indicates
2536 that RELASZ should not include JMPREL. This is not what
2537 the rest of the BFD does. It is, however, what the
2538 glibc ld.so wants. Do this fixup here until we found
2539 out who is right. */
2540 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
2544 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
2549 s
= bfd_get_section_by_name (output_bfd
, name
);
2550 dyn
.d_un
.d_ptr
= (s
? s
->vma
: 0);
2554 s
= bfd_get_section_by_name (output_bfd
, name
);
2556 (s
->_cooked_size
? s
->_cooked_size
: s
->_raw_size
);
2560 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2563 /* Initialize the PLT0 entry */
2564 if (splt
->_raw_size
> 0)
2566 bfd_put_32 (output_bfd
, PLT_HEADER_WORD1
, splt
->contents
);
2567 bfd_put_32 (output_bfd
, PLT_HEADER_WORD2
, splt
->contents
+ 4);
2568 bfd_put_32 (output_bfd
, PLT_HEADER_WORD3
, splt
->contents
+ 8);
2569 bfd_put_32 (output_bfd
, PLT_HEADER_WORD4
, splt
->contents
+ 12);
2571 /* The next two words will be filled in by ld.so */
2572 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 16);
2573 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 24);
2575 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
2580 /* Set the first entry in the global offset table to the address of
2581 the dynamic section. */
2582 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2583 if (sgot
&& sgot
->_raw_size
> 0)
2586 bfd_put_64 (output_bfd
, (bfd_vma
)0, sgot
->contents
);
2588 bfd_put_64 (output_bfd
,
2589 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2592 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
=
2593 8 * RESERVED_GOT_ENTRIES
;
2600 Elf_Internal_Sym sym
;
2602 /* Set up the section symbols for the output sections. */
2604 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2605 BFD_ASSERT (sdynsym
!= NULL
);
2609 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2612 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2616 sym
.st_value
= s
->vma
;
2618 indx
= elf_section_data (s
)->this_idx
;
2619 BFD_ASSERT (indx
> 0);
2620 sym
.st_shndx
= indx
;
2622 bfd_elf64_swap_symbol_out (output_bfd
, &sym
,
2623 (PTR
) (((Elf64_External_Sym
*)
2625 + elf_section_data (s
)->dynindx
));
2628 /* Set the sh_info field of the output .dynsym section to the
2629 index of the first global symbol. */
2630 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2631 bfd_count_sections (output_bfd
) + 1;
2637 /* We need to use a special link routine to handle the .reginfo and
2638 the .mdebug sections. We need to merge all instances of these
2639 sections together, not write them all out sequentially. */
2642 elf64_alpha_final_link (abfd
, info
)
2644 struct bfd_link_info
*info
;
2647 struct bfd_link_order
*p
;
2648 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
2649 struct ecoff_debug_info debug
;
2650 const struct ecoff_debug_swap
*swap
2651 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
2652 HDRR
*symhdr
= &debug
.symbolic_header
;
2653 PTR mdebug_handle
= NULL
;
2655 /* Go through the sections and collect the .reginfo and .mdebug
2659 gptab_data_sec
= NULL
;
2660 gptab_bss_sec
= NULL
;
2661 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
2663 #ifdef ERIC_neverdef
2664 if (strcmp (o
->name
, ".reginfo") == 0)
2666 memset (®info
, 0, sizeof reginfo
);
2668 /* We have found the .reginfo section in the output file.
2669 Look through all the link_orders comprising it and merge
2670 the information together. */
2671 for (p
= o
->link_order_head
;
2672 p
!= (struct bfd_link_order
*) NULL
;
2675 asection
*input_section
;
2677 Elf64_External_RegInfo ext
;
2680 if (p
->type
!= bfd_indirect_link_order
)
2682 if (p
->type
== bfd_fill_link_order
)
2687 input_section
= p
->u
.indirect
.section
;
2688 input_bfd
= input_section
->owner
;
2690 /* The linker emulation code has probably clobbered the
2691 size to be zero bytes. */
2692 if (input_section
->_raw_size
== 0)
2693 input_section
->_raw_size
= sizeof (Elf64_External_RegInfo
);
2695 if (! bfd_get_section_contents (input_bfd
, input_section
,
2701 bfd_alpha_elf64_swap_reginfo_in (input_bfd
, &ext
, &sub
);
2703 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
2704 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
2705 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
2706 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
2707 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
2709 /* ri_gp_value is set by the function
2710 alpha_elf_section_processing when the section is
2711 finally written out. */
2713 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2714 elf_link_input_bfd ignores this section. */
2715 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
2718 /* Force the section size to the value we want. */
2719 o
->_raw_size
= sizeof (Elf64_External_RegInfo
);
2721 /* Skip this section later on (I don't think this currently
2722 matters, but someday it might). */
2723 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
2729 if (strcmp (o
->name
, ".mdebug") == 0)
2731 struct extsym_info einfo
;
2733 /* We have found the .mdebug section in the output file.
2734 Look through all the link_orders comprising it and merge
2735 the information together. */
2736 symhdr
->magic
= swap
->sym_magic
;
2737 /* FIXME: What should the version stamp be? */
2739 symhdr
->ilineMax
= 0;
2743 symhdr
->isymMax
= 0;
2744 symhdr
->ioptMax
= 0;
2745 symhdr
->iauxMax
= 0;
2747 symhdr
->issExtMax
= 0;
2750 symhdr
->iextMax
= 0;
2752 /* We accumulate the debugging information itself in the
2753 debug_info structure. */
2755 debug
.external_dnr
= NULL
;
2756 debug
.external_pdr
= NULL
;
2757 debug
.external_sym
= NULL
;
2758 debug
.external_opt
= NULL
;
2759 debug
.external_aux
= NULL
;
2761 debug
.ssext
= debug
.ssext_end
= NULL
;
2762 debug
.external_fdr
= NULL
;
2763 debug
.external_rfd
= NULL
;
2764 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2766 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
2767 if (mdebug_handle
== (PTR
) NULL
)
2776 static const char * const name
[] =
2778 ".text", ".init", ".fini", ".data",
2779 ".rodata", ".sdata", ".sbss", ".bss"
2781 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
2782 scRData
, scSData
, scSBss
, scBss
};
2785 esym
.cobol_main
= 0;
2789 esym
.asym
.iss
= issNil
;
2790 esym
.asym
.st
= stLocal
;
2791 esym
.asym
.reserved
= 0;
2792 esym
.asym
.index
= indexNil
;
2793 for (i
= 0; i
< 8; i
++)
2795 esym
.asym
.sc
= sc
[i
];
2796 s
= bfd_get_section_by_name (abfd
, name
[i
]);
2799 esym
.asym
.value
= s
->vma
;
2800 last
= s
->vma
+ s
->_raw_size
;
2803 esym
.asym
.value
= last
;
2805 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
2811 for (p
= o
->link_order_head
;
2812 p
!= (struct bfd_link_order
*) NULL
;
2815 asection
*input_section
;
2817 const struct ecoff_debug_swap
*input_swap
;
2818 struct ecoff_debug_info input_debug
;
2822 if (p
->type
!= bfd_indirect_link_order
)
2824 if (p
->type
== bfd_fill_link_order
)
2829 input_section
= p
->u
.indirect
.section
;
2830 input_bfd
= input_section
->owner
;
2832 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
2833 || (get_elf_backend_data (input_bfd
)
2834 ->elf_backend_ecoff_debug_swap
) == NULL
)
2836 /* I don't know what a non ALPHA ELF bfd would be
2837 doing with a .mdebug section, but I don't really
2838 want to deal with it. */
2842 input_swap
= (get_elf_backend_data (input_bfd
)
2843 ->elf_backend_ecoff_debug_swap
);
2845 BFD_ASSERT (p
->size
== input_section
->_raw_size
);
2847 /* The ECOFF linking code expects that we have already
2848 read in the debugging information and set up an
2849 ecoff_debug_info structure, so we do that now. */
2850 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
2854 if (! (bfd_ecoff_debug_accumulate
2855 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
2856 &input_debug
, input_swap
, info
)))
2859 /* Loop through the external symbols. For each one with
2860 interesting information, try to find the symbol in
2861 the linker global hash table and save the information
2862 for the output external symbols. */
2863 eraw_src
= input_debug
.external_ext
;
2864 eraw_end
= (eraw_src
2865 + (input_debug
.symbolic_header
.iextMax
2866 * input_swap
->external_ext_size
));
2868 eraw_src
< eraw_end
;
2869 eraw_src
+= input_swap
->external_ext_size
)
2873 struct alpha_elf_link_hash_entry
*h
;
2875 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
2876 if (ext
.asym
.sc
== scNil
2877 || ext
.asym
.sc
== scUndefined
2878 || ext
.asym
.sc
== scSUndefined
)
2881 name
= input_debug
.ssext
+ ext
.asym
.iss
;
2882 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
2883 name
, false, false, true);
2884 if (h
== NULL
|| h
->esym
.ifd
!= -2)
2890 < input_debug
.symbolic_header
.ifdMax
);
2891 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
2897 /* Free up the information we just read. */
2898 free (input_debug
.line
);
2899 free (input_debug
.external_dnr
);
2900 free (input_debug
.external_pdr
);
2901 free (input_debug
.external_sym
);
2902 free (input_debug
.external_opt
);
2903 free (input_debug
.external_aux
);
2904 free (input_debug
.ss
);
2905 free (input_debug
.ssext
);
2906 free (input_debug
.external_fdr
);
2907 free (input_debug
.external_rfd
);
2908 free (input_debug
.external_ext
);
2910 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2911 elf_link_input_bfd ignores this section. */
2912 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
2915 #ifdef ERIC_neverdef
2918 /* Create .rtproc section. */
2919 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
2920 if (rtproc_sec
== NULL
)
2922 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2925 rtproc_sec
= bfd_make_section (abfd
, ".rtproc");
2926 if (rtproc_sec
== NULL
2927 || ! bfd_set_section_flags (abfd
, rtproc_sec
, flags
)
2928 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 12))
2932 if (! alpha_elf_create_procedure_table (mdebug_handle
, abfd
,
2933 info
, rtproc_sec
, &debug
))
2939 /* Build the external symbol information. */
2942 einfo
.debug
= &debug
;
2944 einfo
.failed
= false;
2945 elf_link_hash_traverse (elf_hash_table (info
),
2946 elf64_alpha_output_extsym
,
2951 /* Set the size of the .mdebug section. */
2952 o
->_raw_size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
2954 /* Skip this section later on (I don't think this currently
2955 matters, but someday it might). */
2956 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
2961 #ifdef ERIC_neverdef
2962 if (strncmp (o
->name
, ".gptab.", sizeof ".gptab." - 1) == 0)
2964 const char *subname
;
2967 Elf64_External_gptab
*ext_tab
;
2970 /* The .gptab.sdata and .gptab.sbss sections hold
2971 information describing how the small data area would
2972 change depending upon the -G switch. These sections
2973 not used in executables files. */
2974 if (! info
->relocateable
)
2978 for (p
= o
->link_order_head
;
2979 p
!= (struct bfd_link_order
*) NULL
;
2982 asection
*input_section
;
2984 if (p
->type
!= bfd_indirect_link_order
)
2986 if (p
->type
== bfd_fill_link_order
)
2991 input_section
= p
->u
.indirect
.section
;
2993 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2994 elf_link_input_bfd ignores this section. */
2995 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
2998 /* Skip this section later on (I don't think this
2999 currently matters, but someday it might). */
3000 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3002 /* Really remove the section. */
3003 for (secpp
= &abfd
->sections
;
3005 secpp
= &(*secpp
)->next
)
3007 *secpp
= (*secpp
)->next
;
3008 --abfd
->section_count
;
3013 /* There is one gptab for initialized data, and one for
3014 uninitialized data. */
3015 if (strcmp (o
->name
, ".gptab.sdata") == 0)
3017 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
3021 (*_bfd_error_handler
)
3022 ("%s: illegal section name `%s'",
3023 bfd_get_filename (abfd
), o
->name
);
3024 bfd_set_error (bfd_error_nonrepresentable_section
);
3028 /* The linker script always combines .gptab.data and
3029 .gptab.sdata into .gptab.sdata, and likewise for
3030 .gptab.bss and .gptab.sbss. It is possible that there is
3031 no .sdata or .sbss section in the output file, in which
3032 case we must change the name of the output section. */
3033 subname
= o
->name
+ sizeof ".gptab" - 1;
3034 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
3036 if (o
== gptab_data_sec
)
3037 o
->name
= ".gptab.data";
3039 o
->name
= ".gptab.bss";
3040 subname
= o
->name
+ sizeof ".gptab" - 1;
3041 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
3044 /* Set up the first entry. */
3046 tab
= (Elf64_gptab
*) bfd_malloc (c
* sizeof (Elf64_gptab
));
3049 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
3050 tab
[0].gt_header
.gt_unused
= 0;
3052 /* Combine the input sections. */
3053 for (p
= o
->link_order_head
;
3054 p
!= (struct bfd_link_order
*) NULL
;
3057 asection
*input_section
;
3061 bfd_size_type gpentry
;
3063 if (p
->type
!= bfd_indirect_link_order
)
3065 if (p
->type
== bfd_fill_link_order
)
3070 input_section
= p
->u
.indirect
.section
;
3071 input_bfd
= input_section
->owner
;
3073 /* Combine the gptab entries for this input section one
3074 by one. We know that the input gptab entries are
3075 sorted by ascending -G value. */
3076 size
= bfd_section_size (input_bfd
, input_section
);
3078 for (gpentry
= sizeof (Elf64_External_gptab
);
3080 gpentry
+= sizeof (Elf64_External_gptab
))
3082 Elf64_External_gptab ext_gptab
;
3083 Elf64_gptab int_gptab
;
3089 if (! (bfd_get_section_contents
3090 (input_bfd
, input_section
, (PTR
) &ext_gptab
,
3091 gpentry
, sizeof (Elf64_External_gptab
))))
3097 bfd_alpha_elf64_swap_gptab_in (input_bfd
, &ext_gptab
,
3099 val
= int_gptab
.gt_entry
.gt_g_value
;
3100 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
3103 for (look
= 1; look
< c
; look
++)
3105 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
3106 tab
[look
].gt_entry
.gt_bytes
+= add
;
3108 if (tab
[look
].gt_entry
.gt_g_value
== val
)
3114 Elf64_gptab
*new_tab
;
3117 /* We need a new table entry. */
3118 new_tab
= ((Elf64_gptab
*)
3119 bfd_realloc ((PTR
) tab
,
3120 (c
+ 1) * sizeof (Elf64_gptab
)));
3121 if (new_tab
== NULL
)
3127 tab
[c
].gt_entry
.gt_g_value
= val
;
3128 tab
[c
].gt_entry
.gt_bytes
= add
;
3130 /* Merge in the size for the next smallest -G
3131 value, since that will be implied by this new
3134 for (look
= 1; look
< c
; look
++)
3136 if (tab
[look
].gt_entry
.gt_g_value
< val
3138 || (tab
[look
].gt_entry
.gt_g_value
3139 > tab
[max
].gt_entry
.gt_g_value
)))
3143 tab
[c
].gt_entry
.gt_bytes
+=
3144 tab
[max
].gt_entry
.gt_bytes
;
3149 last
= int_gptab
.gt_entry
.gt_bytes
;
3152 /* Hack: reset the SEC_HAS_CONTENTS flag so that
3153 elf_link_input_bfd ignores this section. */
3154 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
3157 /* The table must be sorted by -G value. */
3159 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
3161 /* Swap out the table. */
3162 ext_tab
= ((Elf64_External_gptab
*)
3163 bfd_alloc (abfd
, c
* sizeof (Elf64_External_gptab
)));
3164 if (ext_tab
== NULL
)
3170 for (i
= 0; i
< c
; i
++)
3171 bfd_alpha_elf64_swap_gptab_out (abfd
, tab
+ i
, ext_tab
+ i
);
3174 o
->_raw_size
= c
* sizeof (Elf64_External_gptab
);
3175 o
->contents
= (bfd_byte
*) ext_tab
;
3177 /* Skip this section later on (I don't think this currently
3178 matters, but someday it might). */
3179 o
->link_order_head
= (struct bfd_link_order
*) NULL
;
3185 /* Invoke the regular ELF backend linker to do all the work. */
3186 if (! bfd_elf64_bfd_final_link (abfd
, info
))
3189 /* Now write out the computed sections. */
3191 #ifdef ERIC_neverdef
3192 if (reginfo_sec
!= (asection
*) NULL
)
3194 Elf64_External_RegInfo ext
;
3196 bfd_alpha_elf64_swap_reginfo_out (abfd
, ®info
, &ext
);
3197 if (! bfd_set_section_contents (abfd
, reginfo_sec
, (PTR
) &ext
,
3198 (file_ptr
) 0, sizeof ext
))
3203 if (mdebug_sec
!= (asection
*) NULL
)
3205 BFD_ASSERT (abfd
->output_has_begun
);
3206 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
3208 mdebug_sec
->filepos
))
3211 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
3214 if (gptab_data_sec
!= (asection
*) NULL
)
3216 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
3217 gptab_data_sec
->contents
,
3219 gptab_data_sec
->_raw_size
))
3223 if (gptab_bss_sec
!= (asection
*) NULL
)
3225 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
3226 gptab_bss_sec
->contents
,
3228 gptab_bss_sec
->_raw_size
))
3235 /* ECOFF swapping routines. These are used when dealing with the
3236 .mdebug section, which is in the ECOFF debugging format. Copied
3237 from elf32-mips.c. */
3238 static const struct ecoff_debug_swap
3239 elf64_alpha_ecoff_debug_swap
=
3241 /* Symbol table magic number. */
3243 /* Alignment of debugging information. E.g., 4. */
3245 /* Sizes of external symbolic information. */
3246 sizeof (struct hdr_ext
),
3247 sizeof (struct dnr_ext
),
3248 sizeof (struct pdr_ext
),
3249 sizeof (struct sym_ext
),
3250 sizeof (struct opt_ext
),
3251 sizeof (struct fdr_ext
),
3252 sizeof (struct rfd_ext
),
3253 sizeof (struct ext_ext
),
3254 /* Functions to swap in external symbolic data. */
3263 _bfd_ecoff_swap_tir_in
,
3264 _bfd_ecoff_swap_rndx_in
,
3265 /* Functions to swap out external symbolic data. */
3274 _bfd_ecoff_swap_tir_out
,
3275 _bfd_ecoff_swap_rndx_out
,
3276 /* Function to read in symbolic data. */
3277 elf64_alpha_read_ecoff_info
3280 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
3281 #define TARGET_LITTLE_NAME "elf64-alpha"
3282 #define ELF_ARCH bfd_arch_alpha
3283 #define ELF_MACHINE_CODE EM_ALPHA
3284 #define ELF_MAXPAGESIZE 0x100000
3286 #define bfd_elf64_bfd_link_hash_table_create \
3287 elf64_alpha_bfd_link_hash_table_create
3289 #define bfd_elf64_bfd_reloc_type_lookup \
3290 elf64_alpha_bfd_reloc_type_lookup
3291 #define elf_info_to_howto \
3292 elf64_alpha_info_to_howto
3294 #define elf_backend_object_p \
3295 elf64_alpha_object_p
3296 #define elf_backend_section_from_shdr \
3297 elf64_alpha_section_from_shdr
3298 #define elf_backend_fake_sections \
3299 elf64_alpha_fake_sections
3300 #define elf_backend_additional_program_headers \
3301 elf64_alpha_additional_program_headers
3303 #define bfd_elf64_bfd_is_local_label \
3304 elf64_alpha_is_local_label
3305 #define bfd_elf64_find_nearest_line \
3306 elf64_alpha_find_nearest_line
3308 #define elf_backend_check_relocs \
3309 elf64_alpha_check_relocs
3310 #define elf_backend_create_dynamic_sections \
3311 elf64_alpha_create_dynamic_sections
3312 #define elf_backend_adjust_dynamic_symbol \
3313 elf64_alpha_adjust_dynamic_symbol
3314 #define elf_backend_size_dynamic_sections \
3315 elf64_alpha_size_dynamic_sections
3316 #define elf_backend_relocate_section \
3317 elf64_alpha_relocate_section
3318 #define elf_backend_finish_dynamic_symbol \
3319 elf64_alpha_finish_dynamic_symbol
3320 #define elf_backend_finish_dynamic_sections \
3321 elf64_alpha_finish_dynamic_sections
3322 #define bfd_elf64_bfd_final_link \
3323 elf64_alpha_final_link
3325 #define elf_backend_ecoff_debug_swap \
3326 &elf64_alpha_ecoff_debug_swap
3329 * A few constants that determine how the .plt section is set up.
3331 #define elf_backend_want_got_plt 0
3332 #define elf_backend_plt_readonly 0
3333 #define elf_backend_want_plt_sym 1
3335 #include "elf64-target.h"