1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
4 Contributed by Richard Henderson <rth@tamu.edu>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22 /* We need a published ABI spec for this. Until one comes out, don't
23 assume this'll remain unchanged forever. */
30 #include "elf/alpha.h"
34 #define NO_COFF_RELOCS
35 #define NO_COFF_SYMBOLS
36 #define NO_COFF_LINENOS
38 /* Get the ECOFF swapping routines. Needed for the debug information. */
39 #include "coff/internal.h"
41 #include "coff/symconst.h"
42 #include "coff/ecoff.h"
43 #include "coff/alpha.h"
48 #include "ecoffswap.h"
51 /* Instruction data for plt generation and relaxation. */
59 #define INSN_LDA (OP_LDA << 26)
60 #define INSN_LDAH (OP_LDAH << 26)
61 #define INSN_LDQ (OP_LDQ << 26)
62 #define INSN_BR (OP_BR << 26)
64 #define INSN_ADDQ 0x40000400
65 #define INSN_RDUNIQ 0x0000009e
66 #define INSN_SUBQ 0x40000520
67 #define INSN_S4SUBQ 0x40000560
68 #define INSN_UNOP 0x2ffe0000
70 #define INSN_JSR 0x68004000
71 #define INSN_JMP 0x68000000
72 #define INSN_JSR_MASK 0xfc00c000
74 #define INSN_A(I,A) (I | (A << 21))
75 #define INSN_AB(I,A,B) (I | (A << 21) | (B << 16))
76 #define INSN_ABC(I,A,B,C) (I | (A << 21) | (B << 16) | C)
77 #define INSN_ABO(I,A,B,O) (I | (A << 21) | (B << 16) | ((O) & 0xffff))
78 #define INSN_AD(I,A,D) (I | (A << 21) | (((D) >> 2) & 0x1fffff))
82 /* Set by ld emulation. Putting this into the link_info or hash structure
83 is simply working too hard. */
85 bfd_boolean elf64_alpha_use_secureplt
= TRUE
;
87 bfd_boolean elf64_alpha_use_secureplt
= FALSE
;
90 #define OLD_PLT_HEADER_SIZE 32
91 #define OLD_PLT_ENTRY_SIZE 12
92 #define NEW_PLT_HEADER_SIZE 36
93 #define NEW_PLT_ENTRY_SIZE 4
95 #define PLT_HEADER_SIZE \
96 (elf64_alpha_use_secureplt ? NEW_PLT_HEADER_SIZE : OLD_PLT_HEADER_SIZE)
97 #define PLT_ENTRY_SIZE \
98 (elf64_alpha_use_secureplt ? NEW_PLT_ENTRY_SIZE : OLD_PLT_ENTRY_SIZE)
100 #define MAX_GOT_SIZE (64*1024)
102 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so"
104 struct alpha_elf_link_hash_entry
106 struct elf_link_hash_entry root
;
108 /* External symbol information. */
111 /* Cumulative flags for all the .got entries. */
114 /* Contexts in which a literal was referenced. */
115 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01
116 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02
117 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04
118 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08
119 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10
120 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20
121 #define ALPHA_ELF_LINK_HASH_LU_JSRDIRECT 0x40
122 #define ALPHA_ELF_LINK_HASH_LU_PLT 0x38
123 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x80
125 /* Used to implement multiple .got subsections. */
126 struct alpha_elf_got_entry
128 struct alpha_elf_got_entry
*next
;
130 /* Which .got subsection? */
133 /* The addend in effect for this entry. */
136 /* The .got offset for this entry. */
139 /* The .plt offset for this entry. */
142 /* How many references to this entry? */
145 /* The relocation type of this entry. */
146 unsigned char reloc_type
;
148 /* How a LITERAL is used. */
151 /* Have we initialized the dynamic relocation for this entry? */
152 unsigned char reloc_done
;
154 /* Have we adjusted this entry for SEC_MERGE? */
155 unsigned char reloc_xlated
;
158 /* Used to count non-got, non-plt relocations for delayed sizing
159 of relocation sections. */
160 struct alpha_elf_reloc_entry
162 struct alpha_elf_reloc_entry
*next
;
164 /* Which .reloc section? */
167 /* What kind of relocation? */
170 /* Is this against read-only section? */
171 unsigned int reltext
: 1;
173 /* How many did we find? */
178 /* Alpha ELF linker hash table. */
180 struct alpha_elf_link_hash_table
182 struct elf_link_hash_table root
;
184 /* The head of a list of .got subsections linked through
185 alpha_elf_tdata(abfd)->got_link_next. */
189 /* Look up an entry in a Alpha ELF linker hash table. */
191 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
192 ((struct alpha_elf_link_hash_entry *) \
193 elf_link_hash_lookup (&(table)->root, (string), (create), \
196 /* Traverse a Alpha ELF linker hash table. */
198 #define alpha_elf_link_hash_traverse(table, func, info) \
199 (elf_link_hash_traverse \
201 (bfd_boolean (*) (struct elf_link_hash_entry *, PTR)) (func), \
204 /* Get the Alpha ELF linker hash table from a link_info structure. */
206 #define alpha_elf_hash_table(p) \
207 ((struct alpha_elf_link_hash_table *) ((p)->hash))
209 /* Get the object's symbols as our own entry type. */
211 #define alpha_elf_sym_hashes(abfd) \
212 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
214 /* Should we do dynamic things to this symbol? This differs from the
215 generic version in that we never need to consider function pointer
216 equality wrt PLT entries -- we don't create a PLT entry if a symbol's
217 address is ever taken. */
219 static inline bfd_boolean
220 alpha_elf_dynamic_symbol_p (struct elf_link_hash_entry
*h
,
221 struct bfd_link_info
*info
)
223 return _bfd_elf_dynamic_symbol_p (h
, info
, 0);
226 /* Create an entry in a Alpha ELF linker hash table. */
228 static struct bfd_hash_entry
*
229 elf64_alpha_link_hash_newfunc (struct bfd_hash_entry
*entry
,
230 struct bfd_hash_table
*table
,
233 struct alpha_elf_link_hash_entry
*ret
=
234 (struct alpha_elf_link_hash_entry
*) entry
;
236 /* Allocate the structure if it has not already been allocated by a
238 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
239 ret
= ((struct alpha_elf_link_hash_entry
*)
240 bfd_hash_allocate (table
,
241 sizeof (struct alpha_elf_link_hash_entry
)));
242 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
243 return (struct bfd_hash_entry
*) ret
;
245 /* Call the allocation method of the superclass. */
246 ret
= ((struct alpha_elf_link_hash_entry
*)
247 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
249 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
251 /* Set local fields. */
252 memset (&ret
->esym
, 0, sizeof (EXTR
));
253 /* We use -2 as a marker to indicate that the information has
254 not been set. -1 means there is no associated ifd. */
257 ret
->got_entries
= NULL
;
258 ret
->reloc_entries
= NULL
;
261 return (struct bfd_hash_entry
*) ret
;
264 /* Create a Alpha ELF linker hash table. */
266 static struct bfd_link_hash_table
*
267 elf64_alpha_bfd_link_hash_table_create (bfd
*abfd
)
269 struct alpha_elf_link_hash_table
*ret
;
270 bfd_size_type amt
= sizeof (struct alpha_elf_link_hash_table
);
272 ret
= (struct alpha_elf_link_hash_table
*) bfd_zmalloc (amt
);
273 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
276 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
277 elf64_alpha_link_hash_newfunc
,
278 sizeof (struct alpha_elf_link_hash_entry
)))
284 return &ret
->root
.root
;
287 /* We have some private fields hanging off of the elf_tdata structure. */
289 struct alpha_elf_obj_tdata
291 struct elf_obj_tdata root
;
293 /* For every input file, these are the got entries for that object's
295 struct alpha_elf_got_entry
** local_got_entries
;
297 /* For every input file, this is the object that owns the got that
298 this input file uses. */
301 /* For every got, this is a linked list through the objects using this got */
302 bfd
*in_got_link_next
;
304 /* For every got, this is a link to the next got subsegment. */
307 /* For every got, this is the section. */
310 /* For every got, this is it's total number of words. */
313 /* For every got, this is the sum of the number of words required
314 to hold all of the member object's local got. */
318 #define alpha_elf_tdata(abfd) \
319 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
322 elf64_alpha_mkobject (bfd
*abfd
)
324 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
325 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
326 if (abfd
->tdata
.any
== NULL
)
332 elf64_alpha_object_p (bfd
*abfd
)
334 /* Set the right machine number for an Alpha ELF file. */
335 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
338 /* A relocation function which doesn't do anything. */
340 static bfd_reloc_status_type
341 elf64_alpha_reloc_nil (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc
,
342 asymbol
*sym ATTRIBUTE_UNUSED
,
343 PTR data ATTRIBUTE_UNUSED
, asection
*sec
,
344 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
347 reloc
->address
+= sec
->output_offset
;
351 /* A relocation function used for an unsupported reloc. */
353 static bfd_reloc_status_type
354 elf64_alpha_reloc_bad (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc
,
355 asymbol
*sym ATTRIBUTE_UNUSED
,
356 PTR data ATTRIBUTE_UNUSED
, asection
*sec
,
357 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
360 reloc
->address
+= sec
->output_offset
;
361 return bfd_reloc_notsupported
;
364 /* Do the work of the GPDISP relocation. */
366 static bfd_reloc_status_type
367 elf64_alpha_do_reloc_gpdisp (bfd
*abfd
, bfd_vma gpdisp
, bfd_byte
*p_ldah
,
370 bfd_reloc_status_type ret
= bfd_reloc_ok
;
372 unsigned long i_ldah
, i_lda
;
374 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
375 i_lda
= bfd_get_32 (abfd
, p_lda
);
377 /* Complain if the instructions are not correct. */
378 if (((i_ldah
>> 26) & 0x3f) != 0x09
379 || ((i_lda
>> 26) & 0x3f) != 0x08)
380 ret
= bfd_reloc_dangerous
;
382 /* Extract the user-supplied offset, mirroring the sign extensions
383 that the instructions perform. */
384 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
385 addend
= (addend
^ 0x80008000) - 0x80008000;
389 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
) 0x80000000
390 || (bfd_signed_vma
) gpdisp
>= (bfd_signed_vma
) 0x7fff8000)
391 ret
= bfd_reloc_overflow
;
393 /* compensate for the sign extension again. */
394 i_ldah
= ((i_ldah
& 0xffff0000)
395 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
396 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
398 bfd_put_32 (abfd
, (bfd_vma
) i_ldah
, p_ldah
);
399 bfd_put_32 (abfd
, (bfd_vma
) i_lda
, p_lda
);
404 /* The special function for the GPDISP reloc. */
406 static bfd_reloc_status_type
407 elf64_alpha_reloc_gpdisp (bfd
*abfd
, arelent
*reloc_entry
,
408 asymbol
*sym ATTRIBUTE_UNUSED
, PTR data
,
409 asection
*input_section
, bfd
*output_bfd
,
412 bfd_reloc_status_type ret
;
413 bfd_vma gp
, relocation
;
414 bfd_vma high_address
;
415 bfd_byte
*p_ldah
, *p_lda
;
417 /* Don't do anything if we're not doing a final link. */
420 reloc_entry
->address
+= input_section
->output_offset
;
424 high_address
= bfd_get_section_limit (abfd
, input_section
);
425 if (reloc_entry
->address
> high_address
426 || reloc_entry
->address
+ reloc_entry
->addend
> high_address
)
427 return bfd_reloc_outofrange
;
429 /* The gp used in the portion of the output object to which this
430 input object belongs is cached on the input bfd. */
431 gp
= _bfd_get_gp_value (abfd
);
433 relocation
= (input_section
->output_section
->vma
434 + input_section
->output_offset
435 + reloc_entry
->address
);
437 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
438 p_lda
= p_ldah
+ reloc_entry
->addend
;
440 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
442 /* Complain if the instructions are not correct. */
443 if (ret
== bfd_reloc_dangerous
)
444 *err_msg
= _("GPDISP relocation did not find ldah and lda instructions");
449 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
450 from smaller values. Start with zero, widen, *then* decrement. */
451 #define MINUS_ONE (((bfd_vma)0) - 1)
453 #define SKIP_HOWTO(N) \
454 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
456 static reloc_howto_type elf64_alpha_howto_table
[] =
458 HOWTO (R_ALPHA_NONE
, /* type */
460 0, /* size (0 = byte, 1 = short, 2 = long) */
462 TRUE
, /* pc_relative */
464 complain_overflow_dont
, /* complain_on_overflow */
465 elf64_alpha_reloc_nil
, /* special_function */
467 FALSE
, /* partial_inplace */
470 TRUE
), /* pcrel_offset */
472 /* A 32 bit reference to a symbol. */
473 HOWTO (R_ALPHA_REFLONG
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 FALSE
, /* pc_relative */
479 complain_overflow_bitfield
, /* complain_on_overflow */
480 0, /* special_function */
481 "REFLONG", /* name */
482 FALSE
, /* partial_inplace */
483 0xffffffff, /* src_mask */
484 0xffffffff, /* dst_mask */
485 FALSE
), /* pcrel_offset */
487 /* A 64 bit reference to a symbol. */
488 HOWTO (R_ALPHA_REFQUAD
, /* type */
490 4, /* size (0 = byte, 1 = short, 2 = long) */
492 FALSE
, /* pc_relative */
494 complain_overflow_bitfield
, /* complain_on_overflow */
495 0, /* special_function */
496 "REFQUAD", /* name */
497 FALSE
, /* partial_inplace */
498 MINUS_ONE
, /* src_mask */
499 MINUS_ONE
, /* dst_mask */
500 FALSE
), /* pcrel_offset */
502 /* A 32 bit GP relative offset. This is just like REFLONG except
503 that when the value is used the value of the gp register will be
505 HOWTO (R_ALPHA_GPREL32
, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 FALSE
, /* pc_relative */
511 complain_overflow_bitfield
, /* complain_on_overflow */
512 0, /* special_function */
513 "GPREL32", /* name */
514 FALSE
, /* partial_inplace */
515 0xffffffff, /* src_mask */
516 0xffffffff, /* dst_mask */
517 FALSE
), /* pcrel_offset */
519 /* Used for an instruction that refers to memory off the GP register. */
520 HOWTO (R_ALPHA_LITERAL
, /* type */
522 1, /* size (0 = byte, 1 = short, 2 = long) */
524 FALSE
, /* pc_relative */
526 complain_overflow_signed
, /* complain_on_overflow */
527 0, /* special_function */
528 "ELF_LITERAL", /* name */
529 FALSE
, /* partial_inplace */
530 0xffff, /* src_mask */
531 0xffff, /* dst_mask */
532 FALSE
), /* pcrel_offset */
534 /* This reloc only appears immediately following an ELF_LITERAL reloc.
535 It identifies a use of the literal. The symbol index is special:
536 1 means the literal address is in the base register of a memory
537 format instruction; 2 means the literal address is in the byte
538 offset register of a byte-manipulation instruction; 3 means the
539 literal address is in the target register of a jsr instruction.
540 This does not actually do any relocation. */
541 HOWTO (R_ALPHA_LITUSE
, /* type */
543 1, /* size (0 = byte, 1 = short, 2 = long) */
545 FALSE
, /* pc_relative */
547 complain_overflow_dont
, /* complain_on_overflow */
548 elf64_alpha_reloc_nil
, /* special_function */
550 FALSE
, /* partial_inplace */
553 FALSE
), /* pcrel_offset */
555 /* Load the gp register. This is always used for a ldah instruction
556 which loads the upper 16 bits of the gp register. The symbol
557 index of the GPDISP instruction is an offset in bytes to the lda
558 instruction that loads the lower 16 bits. The value to use for
559 the relocation is the difference between the GP value and the
560 current location; the load will always be done against a register
561 holding the current address.
563 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
564 any offset is present in the instructions, it is an offset from
565 the register to the ldah instruction. This lets us avoid any
566 stupid hackery like inventing a gp value to do partial relocation
567 against. Also unlike ECOFF, we do the whole relocation off of
568 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
569 space consuming bit, that, since all the information was present
570 in the GPDISP_HI16 reloc. */
571 HOWTO (R_ALPHA_GPDISP
, /* type */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
575 FALSE
, /* pc_relative */
577 complain_overflow_dont
, /* complain_on_overflow */
578 elf64_alpha_reloc_gpdisp
, /* special_function */
580 FALSE
, /* partial_inplace */
581 0xffff, /* src_mask */
582 0xffff, /* dst_mask */
583 TRUE
), /* pcrel_offset */
585 /* A 21 bit branch. */
586 HOWTO (R_ALPHA_BRADDR
, /* type */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 TRUE
, /* pc_relative */
592 complain_overflow_signed
, /* complain_on_overflow */
593 0, /* special_function */
595 FALSE
, /* partial_inplace */
596 0x1fffff, /* src_mask */
597 0x1fffff, /* dst_mask */
598 TRUE
), /* pcrel_offset */
600 /* A hint for a jump to a register. */
601 HOWTO (R_ALPHA_HINT
, /* type */
603 1, /* size (0 = byte, 1 = short, 2 = long) */
605 TRUE
, /* pc_relative */
607 complain_overflow_dont
, /* complain_on_overflow */
608 0, /* special_function */
610 FALSE
, /* partial_inplace */
611 0x3fff, /* src_mask */
612 0x3fff, /* dst_mask */
613 TRUE
), /* pcrel_offset */
615 /* 16 bit PC relative offset. */
616 HOWTO (R_ALPHA_SREL16
, /* type */
618 1, /* size (0 = byte, 1 = short, 2 = long) */
620 TRUE
, /* pc_relative */
622 complain_overflow_signed
, /* complain_on_overflow */
623 0, /* special_function */
625 FALSE
, /* partial_inplace */
626 0xffff, /* src_mask */
627 0xffff, /* dst_mask */
628 TRUE
), /* pcrel_offset */
630 /* 32 bit PC relative offset. */
631 HOWTO (R_ALPHA_SREL32
, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 TRUE
, /* pc_relative */
637 complain_overflow_signed
, /* complain_on_overflow */
638 0, /* special_function */
640 FALSE
, /* partial_inplace */
641 0xffffffff, /* src_mask */
642 0xffffffff, /* dst_mask */
643 TRUE
), /* pcrel_offset */
645 /* A 64 bit PC relative offset. */
646 HOWTO (R_ALPHA_SREL64
, /* type */
648 4, /* size (0 = byte, 1 = short, 2 = long) */
650 TRUE
, /* pc_relative */
652 complain_overflow_signed
, /* complain_on_overflow */
653 0, /* special_function */
655 FALSE
, /* partial_inplace */
656 MINUS_ONE
, /* src_mask */
657 MINUS_ONE
, /* dst_mask */
658 TRUE
), /* pcrel_offset */
660 /* Skip 12 - 16; deprecated ECOFF relocs. */
667 /* The high 16 bits of the displacement from GP to the target. */
668 HOWTO (R_ALPHA_GPRELHIGH
,
670 1, /* size (0 = byte, 1 = short, 2 = long) */
672 FALSE
, /* pc_relative */
674 complain_overflow_signed
, /* complain_on_overflow */
675 0, /* special_function */
676 "GPRELHIGH", /* name */
677 FALSE
, /* partial_inplace */
678 0xffff, /* src_mask */
679 0xffff, /* dst_mask */
680 FALSE
), /* pcrel_offset */
682 /* The low 16 bits of the displacement from GP to the target. */
683 HOWTO (R_ALPHA_GPRELLOW
,
685 1, /* size (0 = byte, 1 = short, 2 = long) */
687 FALSE
, /* pc_relative */
689 complain_overflow_dont
, /* complain_on_overflow */
690 0, /* special_function */
691 "GPRELLOW", /* name */
692 FALSE
, /* partial_inplace */
693 0xffff, /* src_mask */
694 0xffff, /* dst_mask */
695 FALSE
), /* pcrel_offset */
697 /* A 16-bit displacement from the GP to the target. */
698 HOWTO (R_ALPHA_GPREL16
,
700 1, /* size (0 = byte, 1 = short, 2 = long) */
702 FALSE
, /* pc_relative */
704 complain_overflow_signed
, /* complain_on_overflow */
705 0, /* special_function */
706 "GPREL16", /* name */
707 FALSE
, /* partial_inplace */
708 0xffff, /* src_mask */
709 0xffff, /* dst_mask */
710 FALSE
), /* pcrel_offset */
712 /* Skip 20 - 23; deprecated ECOFF relocs. */
718 /* Misc ELF relocations. */
720 /* A dynamic relocation to copy the target into our .dynbss section. */
721 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
722 is present because every other ELF has one, but should not be used
723 because .dynbss is an ugly thing. */
730 complain_overflow_dont
,
731 bfd_elf_generic_reloc
,
738 /* A dynamic relocation for a .got entry. */
739 HOWTO (R_ALPHA_GLOB_DAT
,
745 complain_overflow_dont
,
746 bfd_elf_generic_reloc
,
753 /* A dynamic relocation for a .plt entry. */
754 HOWTO (R_ALPHA_JMP_SLOT
,
760 complain_overflow_dont
,
761 bfd_elf_generic_reloc
,
768 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
769 HOWTO (R_ALPHA_RELATIVE
,
775 complain_overflow_dont
,
776 bfd_elf_generic_reloc
,
783 /* A 21 bit branch that adjusts for gp loads. */
784 HOWTO (R_ALPHA_BRSGP
, /* type */
786 2, /* size (0 = byte, 1 = short, 2 = long) */
788 TRUE
, /* pc_relative */
790 complain_overflow_signed
, /* complain_on_overflow */
791 0, /* special_function */
793 FALSE
, /* partial_inplace */
794 0x1fffff, /* src_mask */
795 0x1fffff, /* dst_mask */
796 TRUE
), /* pcrel_offset */
798 /* Creates a tls_index for the symbol in the got. */
799 HOWTO (R_ALPHA_TLSGD
, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE
, /* pc_relative */
805 complain_overflow_signed
, /* complain_on_overflow */
806 0, /* special_function */
808 FALSE
, /* partial_inplace */
809 0xffff, /* src_mask */
810 0xffff, /* dst_mask */
811 FALSE
), /* pcrel_offset */
813 /* Creates a tls_index for the (current) module in the got. */
814 HOWTO (R_ALPHA_TLSLDM
, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_signed
, /* complain_on_overflow */
821 0, /* special_function */
823 FALSE
, /* partial_inplace */
824 0xffff, /* src_mask */
825 0xffff, /* dst_mask */
826 FALSE
), /* pcrel_offset */
828 /* A dynamic relocation for a DTP module entry. */
829 HOWTO (R_ALPHA_DTPMOD64
, /* type */
831 4, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_bitfield
, /* complain_on_overflow */
836 0, /* special_function */
837 "DTPMOD64", /* name */
838 FALSE
, /* partial_inplace */
839 MINUS_ONE
, /* src_mask */
840 MINUS_ONE
, /* dst_mask */
841 FALSE
), /* pcrel_offset */
843 /* Creates a 64-bit offset in the got for the displacement
844 from DTP to the target. */
845 HOWTO (R_ALPHA_GOTDTPREL
, /* type */
847 1, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_signed
, /* complain_on_overflow */
852 0, /* special_function */
853 "GOTDTPREL", /* name */
854 FALSE
, /* partial_inplace */
855 0xffff, /* src_mask */
856 0xffff, /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* A dynamic relocation for a displacement from DTP to the target. */
860 HOWTO (R_ALPHA_DTPREL64
, /* type */
862 4, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_bitfield
, /* complain_on_overflow */
867 0, /* special_function */
868 "DTPREL64", /* name */
869 FALSE
, /* partial_inplace */
870 MINUS_ONE
, /* src_mask */
871 MINUS_ONE
, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 /* The high 16 bits of the displacement from DTP to the target. */
875 HOWTO (R_ALPHA_DTPRELHI
, /* type */
877 1, /* size (0 = byte, 1 = short, 2 = long) */
879 FALSE
, /* pc_relative */
881 complain_overflow_signed
, /* complain_on_overflow */
882 0, /* special_function */
883 "DTPRELHI", /* name */
884 FALSE
, /* partial_inplace */
885 0xffff, /* src_mask */
886 0xffff, /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* The low 16 bits of the displacement from DTP to the target. */
890 HOWTO (R_ALPHA_DTPRELLO
, /* type */
892 1, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE
, /* pc_relative */
896 complain_overflow_dont
, /* complain_on_overflow */
897 0, /* special_function */
898 "DTPRELLO", /* name */
899 FALSE
, /* partial_inplace */
900 0xffff, /* src_mask */
901 0xffff, /* dst_mask */
902 FALSE
), /* pcrel_offset */
904 /* A 16-bit displacement from DTP to the target. */
905 HOWTO (R_ALPHA_DTPREL16
, /* type */
907 1, /* size (0 = byte, 1 = short, 2 = long) */
909 FALSE
, /* pc_relative */
911 complain_overflow_signed
, /* complain_on_overflow */
912 0, /* special_function */
913 "DTPREL16", /* name */
914 FALSE
, /* partial_inplace */
915 0xffff, /* src_mask */
916 0xffff, /* dst_mask */
917 FALSE
), /* pcrel_offset */
919 /* Creates a 64-bit offset in the got for the displacement
920 from TP to the target. */
921 HOWTO (R_ALPHA_GOTTPREL
, /* type */
923 1, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_signed
, /* complain_on_overflow */
928 0, /* special_function */
929 "GOTTPREL", /* name */
930 FALSE
, /* partial_inplace */
931 0xffff, /* src_mask */
932 0xffff, /* dst_mask */
933 FALSE
), /* pcrel_offset */
935 /* A dynamic relocation for a displacement from TP to the target. */
936 HOWTO (R_ALPHA_TPREL64
, /* type */
938 4, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_bitfield
, /* complain_on_overflow */
943 0, /* special_function */
944 "TPREL64", /* name */
945 FALSE
, /* partial_inplace */
946 MINUS_ONE
, /* src_mask */
947 MINUS_ONE
, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 /* The high 16 bits of the displacement from TP to the target. */
951 HOWTO (R_ALPHA_TPRELHI
, /* type */
953 1, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_signed
, /* complain_on_overflow */
958 0, /* special_function */
959 "TPRELHI", /* name */
960 FALSE
, /* partial_inplace */
961 0xffff, /* src_mask */
962 0xffff, /* dst_mask */
963 FALSE
), /* pcrel_offset */
965 /* The low 16 bits of the displacement from TP to the target. */
966 HOWTO (R_ALPHA_TPRELLO
, /* type */
968 1, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE
, /* pc_relative */
972 complain_overflow_dont
, /* complain_on_overflow */
973 0, /* special_function */
974 "TPRELLO", /* name */
975 FALSE
, /* partial_inplace */
976 0xffff, /* src_mask */
977 0xffff, /* dst_mask */
978 FALSE
), /* pcrel_offset */
980 /* A 16-bit displacement from TP to the target. */
981 HOWTO (R_ALPHA_TPREL16
, /* type */
983 1, /* size (0 = byte, 1 = short, 2 = long) */
985 FALSE
, /* pc_relative */
987 complain_overflow_signed
, /* complain_on_overflow */
988 0, /* special_function */
989 "TPREL16", /* name */
990 FALSE
, /* partial_inplace */
991 0xffff, /* src_mask */
992 0xffff, /* dst_mask */
993 FALSE
), /* pcrel_offset */
996 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1000 bfd_reloc_code_real_type bfd_reloc_val
;
1004 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
1006 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
1007 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
1008 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
1009 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
1010 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
1011 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
1012 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
1013 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
1014 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
1015 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
1016 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
1017 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
1018 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
1019 {BFD_RELOC_ALPHA_GPREL_HI16
, R_ALPHA_GPRELHIGH
},
1020 {BFD_RELOC_ALPHA_GPREL_LO16
, R_ALPHA_GPRELLOW
},
1021 {BFD_RELOC_GPREL16
, R_ALPHA_GPREL16
},
1022 {BFD_RELOC_ALPHA_BRSGP
, R_ALPHA_BRSGP
},
1023 {BFD_RELOC_ALPHA_TLSGD
, R_ALPHA_TLSGD
},
1024 {BFD_RELOC_ALPHA_TLSLDM
, R_ALPHA_TLSLDM
},
1025 {BFD_RELOC_ALPHA_DTPMOD64
, R_ALPHA_DTPMOD64
},
1026 {BFD_RELOC_ALPHA_GOTDTPREL16
, R_ALPHA_GOTDTPREL
},
1027 {BFD_RELOC_ALPHA_DTPREL64
, R_ALPHA_DTPREL64
},
1028 {BFD_RELOC_ALPHA_DTPREL_HI16
, R_ALPHA_DTPRELHI
},
1029 {BFD_RELOC_ALPHA_DTPREL_LO16
, R_ALPHA_DTPRELLO
},
1030 {BFD_RELOC_ALPHA_DTPREL16
, R_ALPHA_DTPREL16
},
1031 {BFD_RELOC_ALPHA_GOTTPREL16
, R_ALPHA_GOTTPREL
},
1032 {BFD_RELOC_ALPHA_TPREL64
, R_ALPHA_TPREL64
},
1033 {BFD_RELOC_ALPHA_TPREL_HI16
, R_ALPHA_TPRELHI
},
1034 {BFD_RELOC_ALPHA_TPREL_LO16
, R_ALPHA_TPRELLO
},
1035 {BFD_RELOC_ALPHA_TPREL16
, R_ALPHA_TPREL16
},
1038 /* Given a BFD reloc type, return a HOWTO structure. */
1040 static reloc_howto_type
*
1041 elf64_alpha_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1042 bfd_reloc_code_real_type code
)
1044 const struct elf_reloc_map
*i
, *e
;
1045 i
= e
= elf64_alpha_reloc_map
;
1046 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
1049 if (i
->bfd_reloc_val
== code
)
1050 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
1055 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1058 elf64_alpha_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
1059 Elf_Internal_Rela
*dst
)
1061 unsigned r_type
= ELF64_R_TYPE(dst
->r_info
);
1062 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1063 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1066 /* These two relocations create a two-word entry in the got. */
1067 #define alpha_got_entry_size(r_type) \
1068 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1070 /* This is PT_TLS segment p_vaddr. */
1071 #define alpha_get_dtprel_base(info) \
1072 (elf_hash_table (info)->tls_sec->vma)
1074 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1075 is assigned offset round(16, PT_TLS p_align). */
1076 #define alpha_get_tprel_base(info) \
1077 (elf_hash_table (info)->tls_sec->vma \
1078 - align_power ((bfd_vma) 16, \
1079 elf_hash_table (info)->tls_sec->alignment_power))
1081 /* Handle an Alpha specific section when reading an object file. This
1082 is called when bfd_section_from_shdr finds a section with an unknown
1084 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
1088 elf64_alpha_section_from_shdr (bfd
*abfd
,
1089 Elf_Internal_Shdr
*hdr
,
1095 /* There ought to be a place to keep ELF backend specific flags, but
1096 at the moment there isn't one. We just keep track of the
1097 sections by their name, instead. Fortunately, the ABI gives
1098 suggested names for all the MIPS specific sections, so we will
1099 probably get away with this. */
1100 switch (hdr
->sh_type
)
1102 case SHT_ALPHA_DEBUG
:
1103 if (strcmp (name
, ".mdebug") != 0)
1110 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1112 newsect
= hdr
->bfd_section
;
1114 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
1116 if (! bfd_set_section_flags (abfd
, newsect
,
1117 (bfd_get_section_flags (abfd
, newsect
)
1125 /* Convert Alpha specific section flags to bfd internal section flags. */
1128 elf64_alpha_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
1130 if (hdr
->sh_flags
& SHF_ALPHA_GPREL
)
1131 *flags
|= SEC_SMALL_DATA
;
1136 /* Set the correct type for an Alpha ELF section. We do this by the
1137 section name, which is a hack, but ought to work. */
1140 elf64_alpha_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
1142 register const char *name
;
1144 name
= bfd_get_section_name (abfd
, sec
);
1146 if (strcmp (name
, ".mdebug") == 0)
1148 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
1149 /* In a shared object on Irix 5.3, the .mdebug section has an
1150 entsize of 0. FIXME: Does this matter? */
1151 if ((abfd
->flags
& DYNAMIC
) != 0 )
1152 hdr
->sh_entsize
= 0;
1154 hdr
->sh_entsize
= 1;
1156 else if ((sec
->flags
& SEC_SMALL_DATA
)
1157 || strcmp (name
, ".sdata") == 0
1158 || strcmp (name
, ".sbss") == 0
1159 || strcmp (name
, ".lit4") == 0
1160 || strcmp (name
, ".lit8") == 0)
1161 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
1166 /* Hook called by the linker routine which adds symbols from an object
1167 file. We use it to put .comm items in .sbss, and not .bss. */
1170 elf64_alpha_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1171 Elf_Internal_Sym
*sym
,
1172 const char **namep ATTRIBUTE_UNUSED
,
1173 flagword
*flagsp ATTRIBUTE_UNUSED
,
1174 asection
**secp
, bfd_vma
*valp
)
1176 if (sym
->st_shndx
== SHN_COMMON
1177 && !info
->relocatable
1178 && sym
->st_size
<= elf_gp_size (abfd
))
1180 /* Common symbols less than or equal to -G nn bytes are
1181 automatically put into .sbss. */
1183 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
1187 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
1190 | SEC_LINKER_CREATED
));
1196 *valp
= sym
->st_size
;
1202 /* Create the .got section. */
1205 elf64_alpha_create_got_section (bfd
*abfd
,
1206 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1211 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1212 | SEC_LINKER_CREATED
);
1213 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
1215 || !bfd_set_section_alignment (abfd
, s
, 3))
1218 alpha_elf_tdata (abfd
)->got
= s
;
1220 /* Make sure the object's gotobj is set to itself so that we default
1221 to every object with its own .got. We'll merge .gots later once
1222 we've collected each object's info. */
1223 alpha_elf_tdata (abfd
)->gotobj
= abfd
;
1228 /* Create all the dynamic sections. */
1231 elf64_alpha_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
1235 struct elf_link_hash_entry
*h
;
1237 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1239 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1240 | SEC_LINKER_CREATED
1241 | (elf64_alpha_use_secureplt
? SEC_READONLY
: 0));
1242 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", flags
);
1243 if (s
== NULL
|| ! bfd_set_section_alignment (abfd
, s
, 4))
1246 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1248 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
1249 "_PROCEDURE_LINKAGE_TABLE_");
1250 elf_hash_table (info
)->hplt
= h
;
1254 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1255 | SEC_LINKER_CREATED
| SEC_READONLY
);
1256 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.plt", flags
);
1257 if (s
== NULL
|| ! bfd_set_section_alignment (abfd
, s
, 3))
1260 if (elf64_alpha_use_secureplt
)
1262 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
1263 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
1264 if (s
== NULL
|| ! bfd_set_section_alignment (abfd
, s
, 3))
1268 /* We may or may not have created a .got section for this object, but
1269 we definitely havn't done the rest of the work. */
1271 if (alpha_elf_tdata(abfd
)->gotobj
== NULL
)
1273 if (!elf64_alpha_create_got_section (abfd
, info
))
1277 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1278 | SEC_LINKER_CREATED
| SEC_READONLY
);
1279 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got", flags
);
1281 || !bfd_set_section_alignment (abfd
, s
, 3))
1284 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1285 dynobj's .got section. We don't do this in the linker script
1286 because we don't want to define the symbol if we are not creating
1287 a global offset table. */
1288 h
= _bfd_elf_define_linkage_sym (abfd
, info
, alpha_elf_tdata(abfd
)->got
,
1289 "_GLOBAL_OFFSET_TABLE_");
1290 elf_hash_table (info
)->hgot
= h
;
1297 /* Read ECOFF debugging information from a .mdebug section into a
1298 ecoff_debug_info structure. */
1301 elf64_alpha_read_ecoff_info (bfd
*abfd
, asection
*section
,
1302 struct ecoff_debug_info
*debug
)
1305 const struct ecoff_debug_swap
*swap
;
1306 char *ext_hdr
= NULL
;
1308 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1309 memset (debug
, 0, sizeof (*debug
));
1311 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
1312 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1315 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1316 swap
->external_hdr_size
))
1319 symhdr
= &debug
->symbolic_header
;
1320 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1322 /* The symbolic header contains absolute file offsets and sizes to
1324 #define READ(ptr, offset, count, size, type) \
1325 if (symhdr->count == 0) \
1326 debug->ptr = NULL; \
1329 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1330 debug->ptr = (type) bfd_malloc (amt); \
1331 if (debug->ptr == NULL) \
1332 goto error_return; \
1333 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1334 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1335 goto error_return; \
1338 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1339 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1340 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1341 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1342 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1343 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1345 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1346 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1347 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
1348 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
1349 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
1357 if (ext_hdr
!= NULL
)
1359 if (debug
->line
!= NULL
)
1361 if (debug
->external_dnr
!= NULL
)
1362 free (debug
->external_dnr
);
1363 if (debug
->external_pdr
!= NULL
)
1364 free (debug
->external_pdr
);
1365 if (debug
->external_sym
!= NULL
)
1366 free (debug
->external_sym
);
1367 if (debug
->external_opt
!= NULL
)
1368 free (debug
->external_opt
);
1369 if (debug
->external_aux
!= NULL
)
1370 free (debug
->external_aux
);
1371 if (debug
->ss
!= NULL
)
1373 if (debug
->ssext
!= NULL
)
1374 free (debug
->ssext
);
1375 if (debug
->external_fdr
!= NULL
)
1376 free (debug
->external_fdr
);
1377 if (debug
->external_rfd
!= NULL
)
1378 free (debug
->external_rfd
);
1379 if (debug
->external_ext
!= NULL
)
1380 free (debug
->external_ext
);
1384 /* Alpha ELF local labels start with '$'. */
1387 elf64_alpha_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
, const char *name
)
1389 return name
[0] == '$';
1392 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1393 routine in order to handle the ECOFF debugging information. We
1394 still call this mips_elf_find_line because of the slot
1395 find_line_info in elf_obj_tdata is declared that way. */
1397 struct mips_elf_find_line
1399 struct ecoff_debug_info d
;
1400 struct ecoff_find_line i
;
1404 elf64_alpha_find_nearest_line (bfd
*abfd
, asection
*section
, asymbol
**symbols
,
1405 bfd_vma offset
, const char **filename_ptr
,
1406 const char **functionname_ptr
,
1407 unsigned int *line_ptr
)
1411 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
1412 filename_ptr
, functionname_ptr
,
1414 &elf_tdata (abfd
)->dwarf2_find_line_info
))
1417 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
1421 struct mips_elf_find_line
*fi
;
1422 const struct ecoff_debug_swap
* const swap
=
1423 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1425 /* If we are called during a link, alpha_elf_final_link may have
1426 cleared the SEC_HAS_CONTENTS field. We force it back on here
1427 if appropriate (which it normally will be). */
1428 origflags
= msec
->flags
;
1429 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
1430 msec
->flags
|= SEC_HAS_CONTENTS
;
1432 fi
= elf_tdata (abfd
)->find_line_info
;
1435 bfd_size_type external_fdr_size
;
1438 struct fdr
*fdr_ptr
;
1439 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
1441 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
1444 msec
->flags
= origflags
;
1448 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
1450 msec
->flags
= origflags
;
1454 /* Swap in the FDR information. */
1455 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
1456 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
1457 if (fi
->d
.fdr
== NULL
)
1459 msec
->flags
= origflags
;
1462 external_fdr_size
= swap
->external_fdr_size
;
1463 fdr_ptr
= fi
->d
.fdr
;
1464 fraw_src
= (char *) fi
->d
.external_fdr
;
1465 fraw_end
= (fraw_src
1466 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
1467 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
1468 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
1470 elf_tdata (abfd
)->find_line_info
= fi
;
1472 /* Note that we don't bother to ever free this information.
1473 find_nearest_line is either called all the time, as in
1474 objdump -l, so the information should be saved, or it is
1475 rarely called, as in ld error messages, so the memory
1476 wasted is unimportant. Still, it would probably be a
1477 good idea for free_cached_info to throw it away. */
1480 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
1481 &fi
->i
, filename_ptr
, functionname_ptr
,
1484 msec
->flags
= origflags
;
1488 msec
->flags
= origflags
;
1491 /* Fall back on the generic ELF find_nearest_line routine. */
1493 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
1494 filename_ptr
, functionname_ptr
,
1498 /* Structure used to pass information to alpha_elf_output_extsym. */
1503 struct bfd_link_info
*info
;
1504 struct ecoff_debug_info
*debug
;
1505 const struct ecoff_debug_swap
*swap
;
1510 elf64_alpha_output_extsym (struct alpha_elf_link_hash_entry
*h
, PTR data
)
1512 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1514 asection
*sec
, *output_section
;
1516 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1517 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1519 if (h
->root
.indx
== -2)
1521 else if ((h
->root
.def_dynamic
1522 || h
->root
.ref_dynamic
1523 || h
->root
.root
.type
== bfd_link_hash_new
)
1524 && !h
->root
.def_regular
1525 && !h
->root
.ref_regular
)
1527 else if (einfo
->info
->strip
== strip_all
1528 || (einfo
->info
->strip
== strip_some
1529 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1530 h
->root
.root
.root
.string
,
1531 FALSE
, FALSE
) == NULL
))
1539 if (h
->esym
.ifd
== -2)
1542 h
->esym
.cobol_main
= 0;
1543 h
->esym
.weakext
= 0;
1544 h
->esym
.reserved
= 0;
1545 h
->esym
.ifd
= ifdNil
;
1546 h
->esym
.asym
.value
= 0;
1547 h
->esym
.asym
.st
= stGlobal
;
1549 if (h
->root
.root
.type
!= bfd_link_hash_defined
1550 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1551 h
->esym
.asym
.sc
= scAbs
;
1556 sec
= h
->root
.root
.u
.def
.section
;
1557 output_section
= sec
->output_section
;
1559 /* When making a shared library and symbol h is the one from
1560 the another shared library, OUTPUT_SECTION may be null. */
1561 if (output_section
== NULL
)
1562 h
->esym
.asym
.sc
= scUndefined
;
1565 name
= bfd_section_name (output_section
->owner
, output_section
);
1567 if (strcmp (name
, ".text") == 0)
1568 h
->esym
.asym
.sc
= scText
;
1569 else if (strcmp (name
, ".data") == 0)
1570 h
->esym
.asym
.sc
= scData
;
1571 else if (strcmp (name
, ".sdata") == 0)
1572 h
->esym
.asym
.sc
= scSData
;
1573 else if (strcmp (name
, ".rodata") == 0
1574 || strcmp (name
, ".rdata") == 0)
1575 h
->esym
.asym
.sc
= scRData
;
1576 else if (strcmp (name
, ".bss") == 0)
1577 h
->esym
.asym
.sc
= scBss
;
1578 else if (strcmp (name
, ".sbss") == 0)
1579 h
->esym
.asym
.sc
= scSBss
;
1580 else if (strcmp (name
, ".init") == 0)
1581 h
->esym
.asym
.sc
= scInit
;
1582 else if (strcmp (name
, ".fini") == 0)
1583 h
->esym
.asym
.sc
= scFini
;
1585 h
->esym
.asym
.sc
= scAbs
;
1589 h
->esym
.asym
.reserved
= 0;
1590 h
->esym
.asym
.index
= indexNil
;
1593 if (h
->root
.root
.type
== bfd_link_hash_common
)
1594 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1595 else if (h
->root
.root
.type
== bfd_link_hash_defined
1596 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1598 if (h
->esym
.asym
.sc
== scCommon
)
1599 h
->esym
.asym
.sc
= scBss
;
1600 else if (h
->esym
.asym
.sc
== scSCommon
)
1601 h
->esym
.asym
.sc
= scSBss
;
1603 sec
= h
->root
.root
.u
.def
.section
;
1604 output_section
= sec
->output_section
;
1605 if (output_section
!= NULL
)
1606 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1607 + sec
->output_offset
1608 + output_section
->vma
);
1610 h
->esym
.asym
.value
= 0;
1613 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1614 h
->root
.root
.root
.string
,
1617 einfo
->failed
= TRUE
;
1624 /* Search for and possibly create a got entry. */
1626 static struct alpha_elf_got_entry
*
1627 get_got_entry (bfd
*abfd
, struct alpha_elf_link_hash_entry
*h
,
1628 unsigned long r_type
, unsigned long r_symndx
,
1631 struct alpha_elf_got_entry
*gotent
;
1632 struct alpha_elf_got_entry
**slot
;
1635 slot
= &h
->got_entries
;
1638 /* This is a local .got entry -- record for merge. */
1640 struct alpha_elf_got_entry
**local_got_entries
;
1642 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
1643 if (!local_got_entries
)
1646 Elf_Internal_Shdr
*symtab_hdr
;
1648 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
1649 size
= symtab_hdr
->sh_info
;
1650 size
*= sizeof (struct alpha_elf_got_entry
*);
1653 = (struct alpha_elf_got_entry
**) bfd_zalloc (abfd
, size
);
1654 if (!local_got_entries
)
1657 alpha_elf_tdata (abfd
)->local_got_entries
= local_got_entries
;
1660 slot
= &local_got_entries
[r_symndx
];
1663 for (gotent
= *slot
; gotent
; gotent
= gotent
->next
)
1664 if (gotent
->gotobj
== abfd
1665 && gotent
->reloc_type
== r_type
1666 && gotent
->addend
== r_addend
)
1674 amt
= sizeof (struct alpha_elf_got_entry
);
1675 gotent
= (struct alpha_elf_got_entry
*) bfd_alloc (abfd
, amt
);
1679 gotent
->gotobj
= abfd
;
1680 gotent
->addend
= r_addend
;
1681 gotent
->got_offset
= -1;
1682 gotent
->plt_offset
= -1;
1683 gotent
->use_count
= 1;
1684 gotent
->reloc_type
= r_type
;
1685 gotent
->reloc_done
= 0;
1686 gotent
->reloc_xlated
= 0;
1688 gotent
->next
= *slot
;
1691 entry_size
= alpha_got_entry_size (r_type
);
1692 alpha_elf_tdata (abfd
)->total_got_size
+= entry_size
;
1694 alpha_elf_tdata(abfd
)->local_got_size
+= entry_size
;
1697 gotent
->use_count
+= 1;
1703 elf64_alpha_want_plt (struct alpha_elf_link_hash_entry
*ah
)
1705 return ((ah
->root
.type
== STT_FUNC
1706 || ah
->root
.root
.type
== bfd_link_hash_undefweak
1707 || ah
->root
.root
.type
== bfd_link_hash_undefined
)
1708 && (ah
->flags
& ALPHA_ELF_LINK_HASH_LU_PLT
) != 0
1709 && (ah
->flags
& ~ALPHA_ELF_LINK_HASH_LU_PLT
) == 0);
1712 /* Handle dynamic relocations when doing an Alpha ELF link. */
1715 elf64_alpha_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1716 asection
*sec
, const Elf_Internal_Rela
*relocs
)
1720 const char *rel_sec_name
;
1721 Elf_Internal_Shdr
*symtab_hdr
;
1722 struct alpha_elf_link_hash_entry
**sym_hashes
;
1723 const Elf_Internal_Rela
*rel
, *relend
;
1726 if (info
->relocatable
)
1729 /* Don't do anything special with non-loaded, non-alloced sections.
1730 In particular, any relocs in such sections should not affect GOT
1731 and PLT reference counting (ie. we don't allow them to create GOT
1732 or PLT entries), there's no possibility or desire to optimize TLS
1733 relocs, and there's not much point in propagating relocs to shared
1734 libs that the dynamic linker won't relocate. */
1735 if ((sec
->flags
& SEC_ALLOC
) == 0)
1738 dynobj
= elf_hash_table(info
)->dynobj
;
1740 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
1743 rel_sec_name
= NULL
;
1744 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
1745 sym_hashes
= alpha_elf_sym_hashes(abfd
);
1747 relend
= relocs
+ sec
->reloc_count
;
1748 for (rel
= relocs
; rel
< relend
; ++rel
)
1756 unsigned long r_symndx
, r_type
;
1757 struct alpha_elf_link_hash_entry
*h
;
1758 unsigned int gotent_flags
;
1759 bfd_boolean maybe_dynamic
;
1763 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1764 if (r_symndx
< symtab_hdr
->sh_info
)
1768 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1770 while (h
->root
.root
.type
== bfd_link_hash_indirect
1771 || h
->root
.root
.type
== bfd_link_hash_warning
)
1772 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1774 h
->root
.ref_regular
= 1;
1777 /* We can only get preliminary data on whether a symbol is
1778 locally or externally defined, as not all of the input files
1779 have yet been processed. Do something with what we know, as
1780 this may help reduce memory usage and processing time later. */
1781 maybe_dynamic
= FALSE
;
1782 if (h
&& ((info
->shared
1784 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
1785 || !h
->root
.def_regular
1786 || h
->root
.root
.type
== bfd_link_hash_defweak
))
1787 maybe_dynamic
= TRUE
;
1791 r_type
= ELF64_R_TYPE (rel
->r_info
);
1792 addend
= rel
->r_addend
;
1796 case R_ALPHA_LITERAL
:
1797 need
= NEED_GOT
| NEED_GOT_ENTRY
;
1799 /* Remember how this literal is used from its LITUSEs.
1800 This will be important when it comes to decide if we can
1801 create a .plt entry for a function symbol. */
1802 while (++rel
< relend
&& ELF64_R_TYPE (rel
->r_info
) == R_ALPHA_LITUSE
)
1803 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 6)
1804 gotent_flags
|= 1 << rel
->r_addend
;
1807 /* No LITUSEs -- presumably the address is used somehow. */
1808 if (gotent_flags
== 0)
1809 gotent_flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
1812 case R_ALPHA_GPDISP
:
1813 case R_ALPHA_GPREL16
:
1814 case R_ALPHA_GPREL32
:
1815 case R_ALPHA_GPRELHIGH
:
1816 case R_ALPHA_GPRELLOW
:
1821 case R_ALPHA_REFLONG
:
1822 case R_ALPHA_REFQUAD
:
1823 if (info
->shared
|| maybe_dynamic
)
1827 case R_ALPHA_TLSLDM
:
1828 /* The symbol for a TLSLDM reloc is ignored. Collapse the
1829 reloc to the 0 symbol so that they all match. */
1832 maybe_dynamic
= FALSE
;
1836 case R_ALPHA_GOTDTPREL
:
1837 need
= NEED_GOT
| NEED_GOT_ENTRY
;
1840 case R_ALPHA_GOTTPREL
:
1841 need
= NEED_GOT
| NEED_GOT_ENTRY
;
1842 gotent_flags
= ALPHA_ELF_LINK_HASH_TLS_IE
;
1844 info
->flags
|= DF_STATIC_TLS
;
1847 case R_ALPHA_TPREL64
:
1848 if (info
->shared
|| maybe_dynamic
)
1851 info
->flags
|= DF_STATIC_TLS
;
1855 if (need
& NEED_GOT
)
1857 if (alpha_elf_tdata(abfd
)->gotobj
== NULL
)
1859 if (!elf64_alpha_create_got_section (abfd
, info
))
1864 if (need
& NEED_GOT_ENTRY
)
1866 struct alpha_elf_got_entry
*gotent
;
1868 gotent
= get_got_entry (abfd
, h
, r_type
, r_symndx
, addend
);
1874 gotent
->flags
|= gotent_flags
;
1877 gotent_flags
|= h
->flags
;
1878 h
->flags
= gotent_flags
;
1880 /* Make a guess as to whether a .plt entry is needed. */
1881 /* ??? It appears that we won't make it into
1882 adjust_dynamic_symbol for symbols that remain
1883 totally undefined. Copying this check here means
1884 we can create a plt entry for them too. */
1886 = (maybe_dynamic
&& elf64_alpha_want_plt (h
));
1891 if (need
& NEED_DYNREL
)
1893 if (rel_sec_name
== NULL
)
1895 rel_sec_name
= (bfd_elf_string_from_elf_section
1896 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1897 elf_section_data(sec
)->rel_hdr
.sh_name
));
1898 if (rel_sec_name
== NULL
)
1901 BFD_ASSERT (strncmp (rel_sec_name
, ".rela", 5) == 0
1902 && strcmp (bfd_get_section_name (abfd
, sec
),
1903 rel_sec_name
+5) == 0);
1906 /* We need to create the section here now whether we eventually
1907 use it or not so that it gets mapped to an output section by
1908 the linker. If not used, we'll kill it in
1909 size_dynamic_sections. */
1912 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
1917 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1918 | SEC_LINKER_CREATED
| SEC_READONLY
);
1919 if (sec
->flags
& SEC_ALLOC
)
1920 flags
|= SEC_ALLOC
| SEC_LOAD
;
1921 sreloc
= bfd_make_section_with_flags (dynobj
,
1925 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
1932 /* Since we havn't seen all of the input symbols yet, we
1933 don't know whether we'll actually need a dynamic relocation
1934 entry for this reloc. So make a record of it. Once we
1935 find out if this thing needs dynamic relocation we'll
1936 expand the relocation sections by the appropriate amount. */
1938 struct alpha_elf_reloc_entry
*rent
;
1940 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
1941 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
1946 amt
= sizeof (struct alpha_elf_reloc_entry
);
1947 rent
= (struct alpha_elf_reloc_entry
*) bfd_alloc (abfd
, amt
);
1951 rent
->srel
= sreloc
;
1952 rent
->rtype
= r_type
;
1954 rent
->reltext
= (sec
->flags
& SEC_READONLY
) != 0;
1956 rent
->next
= h
->reloc_entries
;
1957 h
->reloc_entries
= rent
;
1962 else if (info
->shared
)
1964 /* If this is a shared library, and the section is to be
1965 loaded into memory, we need a RELATIVE reloc. */
1966 sreloc
->size
+= sizeof (Elf64_External_Rela
);
1967 if (sec
->flags
& SEC_READONLY
)
1968 info
->flags
|= DF_TEXTREL
;
1976 /* Adjust a symbol defined by a dynamic object and referenced by a
1977 regular object. The current definition is in some section of the
1978 dynamic object, but we're not including those sections. We have to
1979 change the definition to something the rest of the link can
1983 elf64_alpha_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1984 struct elf_link_hash_entry
*h
)
1988 struct alpha_elf_link_hash_entry
*ah
;
1990 dynobj
= elf_hash_table(info
)->dynobj
;
1991 ah
= (struct alpha_elf_link_hash_entry
*)h
;
1993 /* Now that we've seen all of the input symbols, finalize our decision
1994 about whether this symbol should get a .plt entry. Irritatingly, it
1995 is common for folk to leave undefined symbols in shared libraries,
1996 and they still expect lazy binding; accept undefined symbols in lieu
1998 if (alpha_elf_dynamic_symbol_p (h
, info
) && elf64_alpha_want_plt (ah
))
2000 h
->needs_plt
= TRUE
;
2002 s
= bfd_get_section_by_name(dynobj
, ".plt");
2003 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
2006 /* We need one plt entry per got subsection. Delay allocation of
2007 the actual plt entries until size_plt_section, called from
2008 size_dynamic_sections or during relaxation. */
2013 h
->needs_plt
= FALSE
;
2015 /* If this is a weak symbol, and there is a real definition, the
2016 processor independent code will have arranged for us to see the
2017 real definition first, and we can just use the same value. */
2018 if (h
->u
.weakdef
!= NULL
)
2020 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2021 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2022 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2023 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2027 /* This is a reference to a symbol defined by a dynamic object which
2028 is not a function. The Alpha, since it uses .got entries for all
2029 symbols even in regular objects, does not need the hackery of a
2030 .dynbss section and COPY dynamic relocations. */
2035 /* Symbol versioning can create new symbols, and make our old symbols
2036 indirect to the new ones. Consolidate the got and reloc information
2037 in these situations. */
2040 elf64_alpha_merge_ind_symbols (struct alpha_elf_link_hash_entry
*hi
,
2041 PTR dummy ATTRIBUTE_UNUSED
)
2043 struct alpha_elf_link_hash_entry
*hs
;
2045 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
2049 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
2050 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
2052 /* Merge the flags. Whee. */
2054 hs
->flags
|= hi
->flags
;
2056 /* Merge the .got entries. Cannibalize the old symbol's list in
2057 doing so, since we don't need it anymore. */
2059 if (hs
->got_entries
== NULL
)
2060 hs
->got_entries
= hi
->got_entries
;
2063 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
2065 gsh
= hs
->got_entries
;
2066 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
2069 for (gs
= gsh
; gs
; gs
= gs
->next
)
2070 if (gi
->gotobj
== gs
->gotobj
2071 && gi
->reloc_type
== gs
->reloc_type
2072 && gi
->addend
== gs
->addend
)
2074 gi
->use_count
+= gs
->use_count
;
2077 gi
->next
= hs
->got_entries
;
2078 hs
->got_entries
= gi
;
2082 hi
->got_entries
= NULL
;
2084 /* And similar for the reloc entries. */
2086 if (hs
->reloc_entries
== NULL
)
2087 hs
->reloc_entries
= hi
->reloc_entries
;
2090 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
2092 rsh
= hs
->reloc_entries
;
2093 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
2096 for (rs
= rsh
; rs
; rs
= rs
->next
)
2097 if (ri
->rtype
== rs
->rtype
&& ri
->srel
== rs
->srel
)
2099 rs
->count
+= ri
->count
;
2102 ri
->next
= hs
->reloc_entries
;
2103 hs
->reloc_entries
= ri
;
2107 hi
->reloc_entries
= NULL
;
2112 /* Is it possible to merge two object file's .got tables? */
2115 elf64_alpha_can_merge_gots (bfd
*a
, bfd
*b
)
2117 int total
= alpha_elf_tdata (a
)->total_got_size
;
2120 /* Trivial quick fallout test. */
2121 if (total
+ alpha_elf_tdata (b
)->total_got_size
<= MAX_GOT_SIZE
)
2124 /* By their nature, local .got entries cannot be merged. */
2125 if ((total
+= alpha_elf_tdata (b
)->local_got_size
) > MAX_GOT_SIZE
)
2128 /* Failing the common trivial comparison, we must effectively
2129 perform the merge. Not actually performing the merge means that
2130 we don't have to store undo information in case we fail. */
2131 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
2133 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes (bsub
);
2134 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
2137 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
2138 for (i
= 0; i
< n
; ++i
)
2140 struct alpha_elf_got_entry
*ae
, *be
;
2141 struct alpha_elf_link_hash_entry
*h
;
2144 while (h
->root
.root
.type
== bfd_link_hash_indirect
2145 || h
->root
.root
.type
== bfd_link_hash_warning
)
2146 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2148 for (be
= h
->got_entries
; be
; be
= be
->next
)
2150 if (be
->use_count
== 0)
2152 if (be
->gotobj
!= b
)
2155 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
2157 && ae
->reloc_type
== be
->reloc_type
2158 && ae
->addend
== be
->addend
)
2161 total
+= alpha_got_entry_size (be
->reloc_type
);
2162 if (total
> MAX_GOT_SIZE
)
2172 /* Actually merge two .got tables. */
2175 elf64_alpha_merge_gots (bfd
*a
, bfd
*b
)
2177 int total
= alpha_elf_tdata (a
)->total_got_size
;
2180 /* Remember local expansion. */
2182 int e
= alpha_elf_tdata (b
)->local_got_size
;
2184 alpha_elf_tdata (a
)->local_got_size
+= e
;
2187 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
2189 struct alpha_elf_got_entry
**local_got_entries
;
2190 struct alpha_elf_link_hash_entry
**hashes
;
2191 Elf_Internal_Shdr
*symtab_hdr
;
2194 /* Let the local .got entries know they are part of a new subsegment. */
2195 local_got_entries
= alpha_elf_tdata (bsub
)->local_got_entries
;
2196 if (local_got_entries
)
2198 n
= elf_tdata (bsub
)->symtab_hdr
.sh_info
;
2199 for (i
= 0; i
< n
; ++i
)
2201 struct alpha_elf_got_entry
*ent
;
2202 for (ent
= local_got_entries
[i
]; ent
; ent
= ent
->next
)
2207 /* Merge the global .got entries. */
2208 hashes
= alpha_elf_sym_hashes (bsub
);
2209 symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
2211 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
2212 for (i
= 0; i
< n
; ++i
)
2214 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
2215 struct alpha_elf_link_hash_entry
*h
;
2218 while (h
->root
.root
.type
== bfd_link_hash_indirect
2219 || h
->root
.root
.type
== bfd_link_hash_warning
)
2220 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2222 pbe
= start
= &h
->got_entries
;
2223 while ((be
= *pbe
) != NULL
)
2225 if (be
->use_count
== 0)
2228 memset (be
, 0xa5, sizeof (*be
));
2231 if (be
->gotobj
!= b
)
2234 for (ae
= *start
; ae
; ae
= ae
->next
)
2236 && ae
->reloc_type
== be
->reloc_type
2237 && ae
->addend
== be
->addend
)
2239 ae
->flags
|= be
->flags
;
2240 ae
->use_count
+= be
->use_count
;
2242 memset (be
, 0xa5, sizeof (*be
));
2246 total
+= alpha_got_entry_size (be
->reloc_type
);
2254 alpha_elf_tdata (bsub
)->gotobj
= a
;
2256 alpha_elf_tdata (a
)->total_got_size
= total
;
2258 /* Merge the two in_got chains. */
2263 while ((next
= alpha_elf_tdata (bsub
)->in_got_link_next
) != NULL
)
2266 alpha_elf_tdata (bsub
)->in_got_link_next
= b
;
2270 /* Calculate the offsets for the got entries. */
2273 elf64_alpha_calc_got_offsets_for_symbol (struct alpha_elf_link_hash_entry
*h
,
2274 PTR arg ATTRIBUTE_UNUSED
)
2276 struct alpha_elf_got_entry
*gotent
;
2278 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2279 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2281 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2282 if (gotent
->use_count
> 0)
2284 struct alpha_elf_obj_tdata
*td
;
2285 bfd_size_type
*plge
;
2287 td
= alpha_elf_tdata (gotent
->gotobj
);
2288 plge
= &td
->got
->size
;
2289 gotent
->got_offset
= *plge
;
2290 *plge
+= alpha_got_entry_size (gotent
->reloc_type
);
2297 elf64_alpha_calc_got_offsets (struct bfd_link_info
*info
)
2299 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
2301 /* First, zero out the .got sizes, as we may be recalculating the
2302 .got after optimizing it. */
2303 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2304 alpha_elf_tdata(i
)->got
->size
= 0;
2306 /* Next, fill in the offsets for all the global entries. */
2307 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2308 elf64_alpha_calc_got_offsets_for_symbol
,
2311 /* Finally, fill in the offsets for the local entries. */
2312 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2314 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->size
;
2317 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2319 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2322 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2323 if (!local_got_entries
)
2326 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2327 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
2328 if (gotent
->use_count
> 0)
2330 gotent
->got_offset
= got_offset
;
2331 got_offset
+= alpha_got_entry_size (gotent
->reloc_type
);
2335 alpha_elf_tdata(i
)->got
->size
= got_offset
;
2339 /* Constructs the gots. */
2342 elf64_alpha_size_got_sections (struct bfd_link_info
*info
)
2344 bfd
*i
, *got_list
, *cur_got_obj
= NULL
;
2345 int something_changed
= 0;
2347 got_list
= alpha_elf_hash_table (info
)->got_list
;
2349 /* On the first time through, pretend we have an existing got list
2350 consisting of all of the input files. */
2351 if (got_list
== NULL
)
2353 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2355 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
2356 if (this_got
== NULL
)
2359 /* We are assuming no merging has yet occurred. */
2360 BFD_ASSERT (this_got
== i
);
2362 if (alpha_elf_tdata (this_got
)->total_got_size
> MAX_GOT_SIZE
)
2364 /* Yikes! A single object file has too many entries. */
2365 (*_bfd_error_handler
)
2366 (_("%B: .got subsegment exceeds 64K (size %d)"),
2367 i
, alpha_elf_tdata (this_got
)->total_got_size
);
2371 if (got_list
== NULL
)
2372 got_list
= this_got
;
2374 alpha_elf_tdata(cur_got_obj
)->got_link_next
= this_got
;
2375 cur_got_obj
= this_got
;
2378 /* Strange degenerate case of no got references. */
2379 if (got_list
== NULL
)
2382 alpha_elf_hash_table (info
)->got_list
= got_list
;
2384 /* Force got offsets to be recalculated. */
2385 something_changed
= 1;
2388 cur_got_obj
= got_list
;
2389 i
= alpha_elf_tdata(cur_got_obj
)->got_link_next
;
2392 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
2394 elf64_alpha_merge_gots (cur_got_obj
, i
);
2396 alpha_elf_tdata(i
)->got
->size
= 0;
2397 i
= alpha_elf_tdata(i
)->got_link_next
;
2398 alpha_elf_tdata(cur_got_obj
)->got_link_next
= i
;
2400 something_changed
= 1;
2405 i
= alpha_elf_tdata(i
)->got_link_next
;
2409 /* Once the gots have been merged, fill in the got offsets for
2410 everything therein. */
2411 if (1 || something_changed
)
2412 elf64_alpha_calc_got_offsets (info
);
2418 elf64_alpha_size_plt_section_1 (struct alpha_elf_link_hash_entry
*h
, PTR data
)
2420 asection
*splt
= (asection
*) data
;
2421 struct alpha_elf_got_entry
*gotent
;
2422 bfd_boolean saw_one
= FALSE
;
2424 /* If we didn't need an entry before, we still don't. */
2425 if (!h
->root
.needs_plt
)
2428 /* For each LITERAL got entry still in use, allocate a plt entry. */
2429 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2430 if (gotent
->reloc_type
== R_ALPHA_LITERAL
2431 && gotent
->use_count
> 0)
2433 if (splt
->size
== 0)
2434 splt
->size
= PLT_HEADER_SIZE
;
2435 gotent
->plt_offset
= splt
->size
;
2436 splt
->size
+= PLT_ENTRY_SIZE
;
2440 /* If there weren't any, there's no longer a need for the PLT entry. */
2442 h
->root
.needs_plt
= FALSE
;
2447 /* Called from relax_section to rebuild the PLT in light of
2448 potential changes in the function's status. */
2451 elf64_alpha_size_plt_section (struct bfd_link_info
*info
)
2453 asection
*splt
, *spltrel
, *sgotplt
;
2454 unsigned long entries
;
2457 dynobj
= elf_hash_table(info
)->dynobj
;
2458 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2464 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2465 elf64_alpha_size_plt_section_1
, splt
);
2467 /* Every plt entry requires a JMP_SLOT relocation. */
2468 spltrel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2471 if (elf64_alpha_use_secureplt
)
2472 entries
= (splt
->size
- NEW_PLT_HEADER_SIZE
) / NEW_PLT_ENTRY_SIZE
;
2474 entries
= (splt
->size
- OLD_PLT_HEADER_SIZE
) / OLD_PLT_ENTRY_SIZE
;
2478 spltrel
->size
= entries
* sizeof (Elf64_External_Rela
);
2480 /* When using the secureplt, we need two words somewhere in the data
2481 segment for the dynamic linker to tell us where to go. This is the
2482 entire contents of the .got.plt section. */
2483 if (elf64_alpha_use_secureplt
)
2485 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2486 sgotplt
->size
= entries
? 16 : 0;
2493 elf64_alpha_always_size_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2494 struct bfd_link_info
*info
)
2498 if (info
->relocatable
)
2501 /* First, take care of the indirect symbols created by versioning. */
2502 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2503 elf64_alpha_merge_ind_symbols
,
2506 if (!elf64_alpha_size_got_sections (info
))
2509 /* Allocate space for all of the .got subsections. */
2510 i
= alpha_elf_hash_table (info
)->got_list
;
2511 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2513 asection
*s
= alpha_elf_tdata(i
)->got
;
2516 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->size
);
2517 if (s
->contents
== NULL
)
2525 /* The number of dynamic relocations required by a static relocation. */
2528 alpha_dynamic_entries_for_reloc (int r_type
, int dynamic
, int shared
)
2532 /* May appear in GOT entries. */
2534 return (dynamic
? 2 : shared
? 1 : 0);
2535 case R_ALPHA_TLSLDM
:
2537 case R_ALPHA_LITERAL
:
2538 case R_ALPHA_GOTTPREL
:
2539 return dynamic
|| shared
;
2540 case R_ALPHA_GOTDTPREL
:
2543 /* May appear in data sections. */
2544 case R_ALPHA_REFLONG
:
2545 case R_ALPHA_REFQUAD
:
2546 case R_ALPHA_TPREL64
:
2547 return dynamic
|| shared
;
2549 /* Everything else is illegal. We'll issue an error during
2550 relocate_section. */
2556 /* Work out the sizes of the dynamic relocation entries. */
2559 elf64_alpha_calc_dynrel_sizes (struct alpha_elf_link_hash_entry
*h
,
2560 struct bfd_link_info
*info
)
2562 bfd_boolean dynamic
;
2563 struct alpha_elf_reloc_entry
*relent
;
2564 unsigned long entries
;
2566 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2567 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2569 /* If the symbol was defined as a common symbol in a regular object
2570 file, and there was no definition in any dynamic object, then the
2571 linker will have allocated space for the symbol in a common
2572 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
2573 set. This is done for dynamic symbols in
2574 elf_adjust_dynamic_symbol but this is not done for non-dynamic
2575 symbols, somehow. */
2576 if (!h
->root
.def_regular
2577 && h
->root
.ref_regular
2578 && !h
->root
.def_dynamic
2579 && (h
->root
.root
.type
== bfd_link_hash_defined
2580 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2581 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
2582 h
->root
.def_regular
= 1;
2584 /* If the symbol is dynamic, we'll need all the relocations in their
2585 natural form. If this is a shared object, and it has been forced
2586 local, we'll need the same number of RELATIVE relocations. */
2587 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
2589 /* If the symbol is a hidden undefined weak, then we never have any
2590 relocations. Avoid the loop which may want to add RELATIVE relocs
2591 based on info->shared. */
2592 if (h
->root
.root
.type
== bfd_link_hash_undefweak
&& !dynamic
)
2595 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
2597 entries
= alpha_dynamic_entries_for_reloc (relent
->rtype
, dynamic
,
2601 relent
->srel
->size
+=
2602 entries
* sizeof (Elf64_External_Rela
) * relent
->count
;
2603 if (relent
->reltext
)
2604 info
->flags
|= DT_TEXTREL
;
2611 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
2615 elf64_alpha_size_rela_got_1 (struct alpha_elf_link_hash_entry
*h
,
2616 struct bfd_link_info
*info
)
2618 bfd_boolean dynamic
;
2619 struct alpha_elf_got_entry
*gotent
;
2620 unsigned long entries
;
2622 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2623 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2625 /* If we're using a plt for this symbol, then all of its relocations
2626 for its got entries go into .rela.plt. */
2627 if (h
->root
.needs_plt
)
2630 /* If the symbol is dynamic, we'll need all the relocations in their
2631 natural form. If this is a shared object, and it has been forced
2632 local, we'll need the same number of RELATIVE relocations. */
2633 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
2635 /* If the symbol is a hidden undefined weak, then we never have any
2636 relocations. Avoid the loop which may want to add RELATIVE relocs
2637 based on info->shared. */
2638 if (h
->root
.root
.type
== bfd_link_hash_undefweak
&& !dynamic
)
2642 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2643 if (gotent
->use_count
> 0)
2644 entries
+= alpha_dynamic_entries_for_reloc (gotent
->reloc_type
,
2645 dynamic
, info
->shared
);
2649 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
2650 asection
*srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2651 BFD_ASSERT (srel
!= NULL
);
2652 srel
->size
+= sizeof (Elf64_External_Rela
) * entries
;
2658 /* Set the sizes of the dynamic relocation sections. */
2661 elf64_alpha_size_rela_got_section (struct bfd_link_info
*info
)
2663 unsigned long entries
;
2667 /* Shared libraries often require RELATIVE relocs, and some relocs
2668 require attention for the main application as well. */
2671 for (i
= alpha_elf_hash_table(info
)->got_list
;
2672 i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2676 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2678 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2681 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2682 if (!local_got_entries
)
2685 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2686 for (gotent
= local_got_entries
[k
];
2687 gotent
; gotent
= gotent
->next
)
2688 if (gotent
->use_count
> 0)
2689 entries
+= (alpha_dynamic_entries_for_reloc
2690 (gotent
->reloc_type
, 0, info
->shared
));
2694 dynobj
= elf_hash_table(info
)->dynobj
;
2695 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2698 BFD_ASSERT (entries
== 0);
2701 srel
->size
= sizeof (Elf64_External_Rela
) * entries
;
2703 /* Now do the non-local symbols. */
2704 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2705 elf64_alpha_size_rela_got_1
, info
);
2710 /* Set the sizes of the dynamic sections. */
2713 elf64_alpha_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2714 struct bfd_link_info
*info
)
2720 dynobj
= elf_hash_table(info
)->dynobj
;
2721 BFD_ASSERT(dynobj
!= NULL
);
2723 if (elf_hash_table (info
)->dynamic_sections_created
)
2725 /* Set the contents of the .interp section to the interpreter. */
2726 if (info
->executable
)
2728 s
= bfd_get_section_by_name (dynobj
, ".interp");
2729 BFD_ASSERT (s
!= NULL
);
2730 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2731 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2734 /* Now that we've seen all of the input files, we can decide which
2735 symbols need dynamic relocation entries and which don't. We've
2736 collected information in check_relocs that we can now apply to
2737 size the dynamic relocation sections. */
2738 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2739 elf64_alpha_calc_dynrel_sizes
, info
);
2741 elf64_alpha_size_rela_got_section (info
);
2742 elf64_alpha_size_plt_section (info
);
2744 /* else we're not dynamic and by definition we don't need such things. */
2746 /* The check_relocs and adjust_dynamic_symbol entry points have
2747 determined the sizes of the various dynamic sections. Allocate
2750 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2754 if (!(s
->flags
& SEC_LINKER_CREATED
))
2757 /* It's OK to base decisions on the section name, because none
2758 of the dynobj section names depend upon the input files. */
2759 name
= bfd_get_section_name (dynobj
, s
);
2761 if (strncmp (name
, ".rela", 5) == 0)
2765 if (strcmp (name
, ".rela.plt") == 0)
2768 /* We use the reloc_count field as a counter if we need
2769 to copy relocs into the output file. */
2773 else if (strncmp (name
, ".got", 4) != 0
2774 && strcmp (name
, ".plt") != 0
2775 && strcmp (name
, ".dynbss") != 0)
2777 /* It's not one of our dynamic sections, so don't allocate space. */
2783 /* If we don't need this section, strip it from the output file.
2784 This is to handle .rela.bss and .rela.plt. We must create it
2785 in create_dynamic_sections, because it must be created before
2786 the linker maps input sections to output sections. The
2787 linker does that before adjust_dynamic_symbol is called, and
2788 it is that function which decides whether anything needs to
2789 go into these sections. */
2790 s
->flags
|= SEC_EXCLUDE
;
2792 else if ((s
->flags
& SEC_HAS_CONTENTS
) != 0)
2794 /* Allocate memory for the section contents. */
2795 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2796 if (s
->contents
== NULL
)
2801 if (elf_hash_table (info
)->dynamic_sections_created
)
2803 /* Add some entries to the .dynamic section. We fill in the
2804 values later, in elf64_alpha_finish_dynamic_sections, but we
2805 must add the entries now so that we get the correct size for
2806 the .dynamic section. The DT_DEBUG entry is filled in by the
2807 dynamic linker and used by the debugger. */
2808 #define add_dynamic_entry(TAG, VAL) \
2809 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2811 if (info
->executable
)
2813 if (!add_dynamic_entry (DT_DEBUG
, 0))
2819 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2820 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2821 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2822 || !add_dynamic_entry (DT_JMPREL
, 0))
2825 if (elf64_alpha_use_secureplt
2826 && !add_dynamic_entry (DT_ALPHA_PLTRO
, 1))
2830 if (!add_dynamic_entry (DT_RELA
, 0)
2831 || !add_dynamic_entry (DT_RELASZ
, 0)
2832 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2835 if (info
->flags
& DF_TEXTREL
)
2837 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2841 #undef add_dynamic_entry
2846 /* These functions do relaxation for Alpha ELF.
2848 Currently I'm only handling what I can do with existing compiler
2849 and assembler support, which means no instructions are removed,
2850 though some may be nopped. At this time GCC does not emit enough
2851 information to do all of the relaxing that is possible. It will
2852 take some not small amount of work for that to happen.
2854 There are a couple of interesting papers that I once read on this
2855 subject, that I cannot find references to at the moment, that
2856 related to Alpha in particular. They are by David Wall, then of
2859 struct alpha_relax_info
2864 Elf_Internal_Shdr
*symtab_hdr
;
2865 Elf_Internal_Rela
*relocs
, *relend
;
2866 struct bfd_link_info
*link_info
;
2870 struct alpha_elf_link_hash_entry
*h
;
2871 struct alpha_elf_got_entry
**first_gotent
;
2872 struct alpha_elf_got_entry
*gotent
;
2873 bfd_boolean changed_contents
;
2874 bfd_boolean changed_relocs
;
2875 unsigned char other
;
2878 static Elf_Internal_Rela
*
2879 elf64_alpha_find_reloc_at_ofs (Elf_Internal_Rela
*rel
,
2880 Elf_Internal_Rela
*relend
,
2881 bfd_vma offset
, int type
)
2883 while (rel
< relend
)
2885 if (rel
->r_offset
== offset
2886 && ELF64_R_TYPE (rel
->r_info
) == (unsigned int) type
)
2894 elf64_alpha_relax_got_load (struct alpha_relax_info
*info
, bfd_vma symval
,
2895 Elf_Internal_Rela
*irel
, unsigned long r_type
)
2898 bfd_signed_vma disp
;
2900 /* Get the instruction. */
2901 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
2903 if (insn
>> 26 != OP_LDQ
)
2905 reloc_howto_type
*howto
= elf64_alpha_howto_table
+ r_type
;
2906 ((*_bfd_error_handler
)
2907 ("%B: %A+0x%lx: warning: %s relocation against unexpected insn",
2908 info
->abfd
, info
->sec
,
2909 (unsigned long) irel
->r_offset
, howto
->name
));
2913 /* Can't relax dynamic symbols. */
2914 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
2917 /* Can't use local-exec relocations in shared libraries. */
2918 if (r_type
== R_ALPHA_GOTTPREL
&& info
->link_info
->shared
)
2921 if (r_type
== R_ALPHA_LITERAL
)
2923 /* Look for nice constant addresses. This includes the not-uncommon
2924 special case of 0 for undefweak symbols. */
2925 if ((info
->h
&& info
->h
->root
.root
.type
== bfd_link_hash_undefweak
)
2926 || (!info
->link_info
->shared
2927 && (symval
>= (bfd_vma
)-0x8000 || symval
< 0x8000)))
2930 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
2931 insn
|= (symval
& 0xffff);
2932 r_type
= R_ALPHA_NONE
;
2936 disp
= symval
- info
->gp
;
2937 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
2938 r_type
= R_ALPHA_GPREL16
;
2943 bfd_vma dtp_base
, tp_base
;
2945 BFD_ASSERT (elf_hash_table (info
->link_info
)->tls_sec
!= NULL
);
2946 dtp_base
= alpha_get_dtprel_base (info
->link_info
);
2947 tp_base
= alpha_get_tprel_base (info
->link_info
);
2948 disp
= symval
- (r_type
== R_ALPHA_GOTDTPREL
? dtp_base
: tp_base
);
2950 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
2954 case R_ALPHA_GOTDTPREL
:
2955 r_type
= R_ALPHA_DTPREL16
;
2957 case R_ALPHA_GOTTPREL
:
2958 r_type
= R_ALPHA_TPREL16
;
2966 if (disp
< -0x8000 || disp
>= 0x8000)
2969 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, info
->contents
+ irel
->r_offset
);
2970 info
->changed_contents
= TRUE
;
2972 /* Reduce the use count on this got entry by one, possibly
2974 if (--info
->gotent
->use_count
== 0)
2976 int sz
= alpha_got_entry_size (r_type
);
2977 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
2979 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
2982 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
2983 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), r_type
);
2984 info
->changed_relocs
= TRUE
;
2986 /* ??? Search forward through this basic block looking for insns
2987 that use the target register. Stop after an insn modifying the
2988 register is seen, or after a branch or call.
2990 Any such memory load insn may be substituted by a load directly
2991 off the GP. This allows the memory load insn to be issued before
2992 the calculated GP register would otherwise be ready.
2994 Any such jsr insn can be replaced by a bsr if it is in range.
2996 This would mean that we'd have to _add_ relocations, the pain of
2997 which gives one pause. */
3003 elf64_alpha_relax_opt_call (struct alpha_relax_info
*info
, bfd_vma symval
)
3005 /* If the function has the same gp, and we can identify that the
3006 function does not use its function pointer, we can eliminate the
3009 /* If the symbol is marked NOPV, we are being told the function never
3010 needs its procedure value. */
3011 if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_NOPV
)
3014 /* If the symbol is marked STD_GP, we are being told the function does
3015 a normal ldgp in the first two words. */
3016 else if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_STD_GPLOAD
)
3019 /* Otherwise, we may be able to identify a GP load in the first two
3020 words, which we can then skip. */
3023 Elf_Internal_Rela
*tsec_relocs
, *tsec_relend
, *tsec_free
, *gpdisp
;
3026 /* Load the relocations from the section that the target symbol is in. */
3027 if (info
->sec
== info
->tsec
)
3029 tsec_relocs
= info
->relocs
;
3030 tsec_relend
= info
->relend
;
3035 tsec_relocs
= (_bfd_elf_link_read_relocs
3036 (info
->abfd
, info
->tsec
, (PTR
) NULL
,
3037 (Elf_Internal_Rela
*) NULL
,
3038 info
->link_info
->keep_memory
));
3039 if (tsec_relocs
== NULL
)
3041 tsec_relend
= tsec_relocs
+ info
->tsec
->reloc_count
;
3042 tsec_free
= (info
->link_info
->keep_memory
? NULL
: tsec_relocs
);
3045 /* Recover the symbol's offset within the section. */
3046 ofs
= (symval
- info
->tsec
->output_section
->vma
3047 - info
->tsec
->output_offset
);
3049 /* Look for a GPDISP reloc. */
3050 gpdisp
= (elf64_alpha_find_reloc_at_ofs
3051 (tsec_relocs
, tsec_relend
, ofs
, R_ALPHA_GPDISP
));
3053 if (!gpdisp
|| gpdisp
->r_addend
!= 4)
3063 /* We've now determined that we can skip an initial gp load. Verify
3064 that the call and the target use the same gp. */
3065 if (info
->link_info
->hash
->creator
!= info
->tsec
->owner
->xvec
3066 || info
->gotobj
!= alpha_elf_tdata (info
->tsec
->owner
)->gotobj
)
3073 elf64_alpha_relax_with_lituse (struct alpha_relax_info
*info
,
3074 bfd_vma symval
, Elf_Internal_Rela
*irel
)
3076 Elf_Internal_Rela
*urel
, *irelend
= info
->relend
;
3077 int flags
, count
, i
;
3078 bfd_signed_vma disp
;
3081 bfd_boolean lit_reused
= FALSE
;
3082 bfd_boolean all_optimized
= TRUE
;
3083 unsigned int lit_insn
;
3085 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
3086 if (lit_insn
>> 26 != OP_LDQ
)
3088 ((*_bfd_error_handler
)
3089 ("%B: %A+0x%lx: warning: LITERAL relocation against unexpected insn",
3090 info
->abfd
, info
->sec
,
3091 (unsigned long) irel
->r_offset
));
3095 /* Can't relax dynamic symbols. */
3096 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
3099 /* Summarize how this particular LITERAL is used. */
3100 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
3102 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
3104 if (urel
->r_addend
<= 6)
3105 flags
|= 1 << urel
->r_addend
;
3108 /* A little preparation for the loop... */
3109 disp
= symval
- info
->gp
;
3111 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
3115 bfd_signed_vma xdisp
;
3117 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
3119 switch (urel
->r_addend
)
3121 case LITUSE_ALPHA_ADDR
:
3123 /* This type is really just a placeholder to note that all
3124 uses cannot be optimized, but to still allow some. */
3125 all_optimized
= FALSE
;
3128 case LITUSE_ALPHA_BASE
:
3129 /* We can always optimize 16-bit displacements. */
3131 /* Extract the displacement from the instruction, sign-extending
3132 it if necessary, then test whether it is within 16 or 32 bits
3133 displacement from GP. */
3134 insn_disp
= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
3136 xdisp
= disp
+ insn_disp
;
3137 fits16
= (xdisp
>= - (bfd_signed_vma
) 0x8000 && xdisp
< 0x8000);
3138 fits32
= (xdisp
>= - (bfd_signed_vma
) 0x80000000
3139 && xdisp
< 0x7fff8000);
3143 /* Take the op code and dest from this insn, take the base
3144 register from the literal insn. Leave the offset alone. */
3145 insn
= (insn
& 0xffe0ffff) | (lit_insn
& 0x001f0000);
3146 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3148 urel
->r_addend
= irel
->r_addend
;
3149 info
->changed_relocs
= TRUE
;
3151 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3152 info
->contents
+ urel
->r_offset
);
3153 info
->changed_contents
= TRUE
;
3156 /* If all mem+byte, we can optimize 32-bit mem displacements. */
3157 else if (fits32
&& !(flags
& ~6))
3159 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
3161 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3163 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
3164 bfd_put_32 (info
->abfd
, (bfd_vma
) lit_insn
,
3165 info
->contents
+ irel
->r_offset
);
3167 info
->changed_contents
= TRUE
;
3169 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3171 urel
->r_addend
= irel
->r_addend
;
3172 info
->changed_relocs
= TRUE
;
3175 all_optimized
= FALSE
;
3178 case LITUSE_ALPHA_BYTOFF
:
3179 /* We can always optimize byte instructions. */
3181 /* FIXME: sanity check the insn for byte op. Check that the
3182 literal dest reg is indeed Rb in the byte insn. */
3184 insn
&= ~ (unsigned) 0x001ff000;
3185 insn
|= ((symval
& 7) << 13) | 0x1000;
3187 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3189 info
->changed_relocs
= TRUE
;
3191 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3192 info
->contents
+ urel
->r_offset
);
3193 info
->changed_contents
= TRUE
;
3196 case LITUSE_ALPHA_JSR
:
3197 case LITUSE_ALPHA_TLSGD
:
3198 case LITUSE_ALPHA_TLSLDM
:
3199 case LITUSE_ALPHA_JSRDIRECT
:
3201 bfd_vma optdest
, org
;
3202 bfd_signed_vma odisp
;
3204 /* For undefined weak symbols, we're mostly interested in getting
3205 rid of the got entry whenever possible, so optimize this to a
3206 use of the zero register. */
3207 if (info
->h
&& info
->h
->root
.root
.type
== bfd_link_hash_undefweak
)
3210 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3211 info
->contents
+ urel
->r_offset
);
3213 info
->changed_contents
= TRUE
;
3217 /* If not zero, place to jump without needing pv. */
3218 optdest
= elf64_alpha_relax_opt_call (info
, symval
);
3219 org
= (info
->sec
->output_section
->vma
3220 + info
->sec
->output_offset
3221 + urel
->r_offset
+ 4);
3222 odisp
= (optdest
? optdest
: symval
) - org
;
3224 if (odisp
>= -0x400000 && odisp
< 0x400000)
3226 Elf_Internal_Rela
*xrel
;
3228 /* Preserve branch prediction call stack when possible. */
3229 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
3230 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
3232 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
3234 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3236 urel
->r_addend
= irel
->r_addend
;
3239 urel
->r_addend
+= optdest
- symval
;
3241 all_optimized
= FALSE
;
3243 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3244 info
->contents
+ urel
->r_offset
);
3246 /* Kill any HINT reloc that might exist for this insn. */
3247 xrel
= (elf64_alpha_find_reloc_at_ofs
3248 (info
->relocs
, info
->relend
, urel
->r_offset
,
3251 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3253 info
->changed_contents
= TRUE
;
3254 info
->changed_relocs
= TRUE
;
3257 all_optimized
= FALSE
;
3259 /* Even if the target is not in range for a direct branch,
3260 if we share a GP, we can eliminate the gp reload. */
3263 Elf_Internal_Rela
*gpdisp
3264 = (elf64_alpha_find_reloc_at_ofs
3265 (info
->relocs
, irelend
, urel
->r_offset
+ 4,
3269 bfd_byte
*p_ldah
= info
->contents
+ gpdisp
->r_offset
;
3270 bfd_byte
*p_lda
= p_ldah
+ gpdisp
->r_addend
;
3271 unsigned int ldah
= bfd_get_32 (info
->abfd
, p_ldah
);
3272 unsigned int lda
= bfd_get_32 (info
->abfd
, p_lda
);
3274 /* Verify that the instruction is "ldah $29,0($26)".
3275 Consider a function that ends in a noreturn call,
3276 and that the next function begins with an ldgp,
3277 and that by accident there is no padding between.
3278 In that case the insn would use $27 as the base. */
3279 if (ldah
== 0x27ba0000 && lda
== 0x23bd0000)
3281 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_ldah
);
3282 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_lda
);
3284 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3285 info
->changed_contents
= TRUE
;
3286 info
->changed_relocs
= TRUE
;
3295 /* If all cases were optimized, we can reduce the use count on this
3296 got entry by one, possibly eliminating it. */
3299 if (--info
->gotent
->use_count
== 0)
3301 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
3302 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3304 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
3307 /* If the literal instruction is no longer needed (it may have been
3308 reused. We can eliminate it. */
3309 /* ??? For now, I don't want to deal with compacting the section,
3310 so just nop it out. */
3313 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3314 info
->changed_relocs
= TRUE
;
3316 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
,
3317 info
->contents
+ irel
->r_offset
);
3318 info
->changed_contents
= TRUE
;
3324 return elf64_alpha_relax_got_load (info
, symval
, irel
, R_ALPHA_LITERAL
);
3328 elf64_alpha_relax_tls_get_addr (struct alpha_relax_info
*info
, bfd_vma symval
,
3329 Elf_Internal_Rela
*irel
, bfd_boolean is_gd
)
3333 Elf_Internal_Rela
*gpdisp
, *hint
;
3334 bfd_boolean dynamic
, use_gottprel
, pos1_unusable
;
3335 unsigned long new_symndx
;
3337 dynamic
= alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
);
3339 /* If a TLS symbol is accessed using IE at least once, there is no point
3340 to use dynamic model for it. */
3341 if (is_gd
&& info
->h
&& (info
->h
->flags
& ALPHA_ELF_LINK_HASH_TLS_IE
))
3344 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
3345 then we might as well relax to IE. */
3346 else if (info
->link_info
->shared
&& !dynamic
3347 && (info
->link_info
->flags
& DF_STATIC_TLS
))
3350 /* Otherwise we must be building an executable to do anything. */
3351 else if (info
->link_info
->shared
)
3354 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
3355 the matching LITUSE_TLS relocations. */
3356 if (irel
+ 2 >= info
->relend
)
3358 if (ELF64_R_TYPE (irel
[1].r_info
) != R_ALPHA_LITERAL
3359 || ELF64_R_TYPE (irel
[2].r_info
) != R_ALPHA_LITUSE
3360 || irel
[2].r_addend
!= (is_gd
? LITUSE_ALPHA_TLSGD
: LITUSE_ALPHA_TLSLDM
))
3363 /* There must be a GPDISP relocation positioned immediately after the
3364 LITUSE relocation. */
3365 gpdisp
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
3366 irel
[2].r_offset
+ 4, R_ALPHA_GPDISP
);
3370 pos
[0] = info
->contents
+ irel
[0].r_offset
;
3371 pos
[1] = info
->contents
+ irel
[1].r_offset
;
3372 pos
[2] = info
->contents
+ irel
[2].r_offset
;
3373 pos
[3] = info
->contents
+ gpdisp
->r_offset
;
3374 pos
[4] = pos
[3] + gpdisp
->r_addend
;
3375 pos1_unusable
= FALSE
;
3377 /* Generally, the positions are not allowed to be out of order, lest the
3378 modified insn sequence have different register lifetimes. We can make
3379 an exception when pos 1 is adjacent to pos 0. */
3380 if (pos
[1] + 4 == pos
[0])
3382 bfd_byte
*tmp
= pos
[0];
3386 else if (pos
[1] < pos
[0])
3387 pos1_unusable
= TRUE
;
3388 if (pos
[1] >= pos
[2] || pos
[2] >= pos
[3])
3391 /* Reduce the use count on the LITERAL relocation. Do this before we
3392 smash the symndx when we adjust the relocations below. */
3394 struct alpha_elf_got_entry
*lit_gotent
;
3395 struct alpha_elf_link_hash_entry
*lit_h
;
3398 BFD_ASSERT (ELF64_R_SYM (irel
[1].r_info
) >= info
->symtab_hdr
->sh_info
);
3399 indx
= ELF64_R_SYM (irel
[1].r_info
) - info
->symtab_hdr
->sh_info
;
3400 lit_h
= alpha_elf_sym_hashes (info
->abfd
)[indx
];
3402 while (lit_h
->root
.root
.type
== bfd_link_hash_indirect
3403 || lit_h
->root
.root
.type
== bfd_link_hash_warning
)
3404 lit_h
= (struct alpha_elf_link_hash_entry
*) lit_h
->root
.root
.u
.i
.link
;
3406 for (lit_gotent
= lit_h
->got_entries
; lit_gotent
;
3407 lit_gotent
= lit_gotent
->next
)
3408 if (lit_gotent
->gotobj
== info
->gotobj
3409 && lit_gotent
->reloc_type
== R_ALPHA_LITERAL
3410 && lit_gotent
->addend
== irel
[1].r_addend
)
3412 BFD_ASSERT (lit_gotent
);
3414 if (--lit_gotent
->use_count
== 0)
3416 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
3417 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3423 lda $16,x($gp) !tlsgd!1
3424 ldq $27,__tls_get_addr($gp) !literal!1
3425 jsr $26,($27),__tls_get_addr !lituse_tlsgd!1
3426 ldah $29,0($26) !gpdisp!2
3427 lda $29,0($29) !gpdisp!2
3429 ldq $16,x($gp) !gottprel
3434 or the first pair to
3435 lda $16,x($gp) !tprel
3438 ldah $16,x($gp) !tprelhi
3439 lda $16,x($16) !tprello
3443 use_gottprel
= FALSE
;
3444 new_symndx
= is_gd
? ELF64_R_SYM (irel
->r_info
) : 0;
3445 switch (!dynamic
&& !info
->link_info
->shared
)
3450 bfd_signed_vma disp
;
3452 BFD_ASSERT (elf_hash_table (info
->link_info
)->tls_sec
!= NULL
);
3453 tp_base
= alpha_get_tprel_base (info
->link_info
);
3454 disp
= symval
- tp_base
;
3456 if (disp
>= -0x8000 && disp
< 0x8000)
3458 insn
= (OP_LDA
<< 26) | (16 << 21) | (31 << 16);
3459 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
3460 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
3462 irel
[0].r_offset
= pos
[0] - info
->contents
;
3463 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPREL16
);
3464 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3467 else if (disp
>= -(bfd_signed_vma
) 0x80000000
3468 && disp
< (bfd_signed_vma
) 0x7fff8000
3471 insn
= (OP_LDAH
<< 26) | (16 << 21) | (31 << 16);
3472 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
3473 insn
= (OP_LDA
<< 26) | (16 << 21) | (16 << 16);
3474 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[1]);
3476 irel
[0].r_offset
= pos
[0] - info
->contents
;
3477 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELHI
);
3478 irel
[1].r_offset
= pos
[1] - info
->contents
;
3479 irel
[1].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELLO
);
3486 use_gottprel
= TRUE
;
3488 insn
= (OP_LDQ
<< 26) | (16 << 21) | (29 << 16);
3489 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
3490 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
3492 irel
[0].r_offset
= pos
[0] - info
->contents
;
3493 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_GOTTPREL
);
3494 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3498 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_RDUNIQ
, pos
[2]);
3500 insn
= INSN_ADDQ
| (16 << 21) | (0 << 16) | (0 << 0);
3501 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[3]);
3503 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[4]);
3505 irel
[2].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3506 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3508 hint
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
3509 irel
[2].r_offset
, R_ALPHA_HINT
);
3511 hint
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3513 info
->changed_contents
= TRUE
;
3514 info
->changed_relocs
= TRUE
;
3516 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
3517 if (--info
->gotent
->use_count
== 0)
3519 int sz
= alpha_got_entry_size (info
->gotent
->reloc_type
);
3520 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3522 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
3525 /* If we've switched to a GOTTPREL relocation, increment the reference
3526 count on that got entry. */
3529 struct alpha_elf_got_entry
*tprel_gotent
;
3531 for (tprel_gotent
= *info
->first_gotent
; tprel_gotent
;
3532 tprel_gotent
= tprel_gotent
->next
)
3533 if (tprel_gotent
->gotobj
== info
->gotobj
3534 && tprel_gotent
->reloc_type
== R_ALPHA_GOTTPREL
3535 && tprel_gotent
->addend
== irel
->r_addend
)
3538 tprel_gotent
->use_count
++;
3541 if (info
->gotent
->use_count
== 0)
3542 tprel_gotent
= info
->gotent
;
3545 tprel_gotent
= (struct alpha_elf_got_entry
*)
3546 bfd_alloc (info
->abfd
, sizeof (struct alpha_elf_got_entry
));
3550 tprel_gotent
->next
= *info
->first_gotent
;
3551 *info
->first_gotent
= tprel_gotent
;
3553 tprel_gotent
->gotobj
= info
->gotobj
;
3554 tprel_gotent
->addend
= irel
->r_addend
;
3555 tprel_gotent
->got_offset
= -1;
3556 tprel_gotent
->reloc_done
= 0;
3557 tprel_gotent
->reloc_xlated
= 0;
3560 tprel_gotent
->use_count
= 1;
3561 tprel_gotent
->reloc_type
= R_ALPHA_GOTTPREL
;
3569 elf64_alpha_relax_section (bfd
*abfd
, asection
*sec
,
3570 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
3572 Elf_Internal_Shdr
*symtab_hdr
;
3573 Elf_Internal_Rela
*internal_relocs
;
3574 Elf_Internal_Rela
*irel
, *irelend
;
3575 Elf_Internal_Sym
*isymbuf
= NULL
;
3576 struct alpha_elf_got_entry
**local_got_entries
;
3577 struct alpha_relax_info info
;
3579 /* We are not currently changing any sizes, so only one pass. */
3582 if (link_info
->relocatable
3583 || ((sec
->flags
& (SEC_CODE
| SEC_RELOC
| SEC_ALLOC
))
3584 != (SEC_CODE
| SEC_RELOC
| SEC_ALLOC
))
3585 || sec
->reloc_count
== 0)
3588 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3589 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
3591 /* Load the relocations for this section. */
3592 internal_relocs
= (_bfd_elf_link_read_relocs
3593 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
3594 link_info
->keep_memory
));
3595 if (internal_relocs
== NULL
)
3598 memset(&info
, 0, sizeof (info
));
3601 info
.link_info
= link_info
;
3602 info
.symtab_hdr
= symtab_hdr
;
3603 info
.relocs
= internal_relocs
;
3604 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
3606 /* Find the GP for this object. Do not store the result back via
3607 _bfd_set_gp_value, since this could change again before final. */
3608 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
3611 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
3612 info
.gp
= (sgot
->output_section
->vma
3613 + sgot
->output_offset
3617 /* Get the section contents. */
3618 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3619 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
3622 if (!bfd_malloc_and_get_section (abfd
, sec
, &info
.contents
))
3626 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3629 struct alpha_elf_got_entry
*gotent
;
3630 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
3631 unsigned long r_symndx
= ELF64_R_SYM (irel
->r_info
);
3633 /* Early exit for unhandled or unrelaxable relocations. */
3636 case R_ALPHA_LITERAL
:
3637 case R_ALPHA_GPRELHIGH
:
3638 case R_ALPHA_GPRELLOW
:
3639 case R_ALPHA_GOTDTPREL
:
3640 case R_ALPHA_GOTTPREL
:
3644 case R_ALPHA_TLSLDM
:
3645 /* The symbol for a TLSLDM reloc is ignored. Collapse the
3646 reloc to the 0 symbol so that they all match. */
3654 /* Get the value of the symbol referred to by the reloc. */
3655 if (r_symndx
< symtab_hdr
->sh_info
)
3657 /* A local symbol. */
3658 Elf_Internal_Sym
*isym
;
3660 /* Read this BFD's local symbols. */
3661 if (isymbuf
== NULL
)
3663 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3664 if (isymbuf
== NULL
)
3665 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
3666 symtab_hdr
->sh_info
, 0,
3668 if (isymbuf
== NULL
)
3672 isym
= isymbuf
+ r_symndx
;
3674 /* Given the symbol for a TLSLDM reloc is ignored, this also
3675 means forcing the symbol value to the tp base. */
3676 if (r_type
== R_ALPHA_TLSLDM
)
3678 info
.tsec
= bfd_abs_section_ptr
;
3679 symval
= alpha_get_tprel_base (info
.link_info
);
3683 symval
= isym
->st_value
;
3684 if (isym
->st_shndx
== SHN_UNDEF
)
3686 else if (isym
->st_shndx
== SHN_ABS
)
3687 info
.tsec
= bfd_abs_section_ptr
;
3688 else if (isym
->st_shndx
== SHN_COMMON
)
3689 info
.tsec
= bfd_com_section_ptr
;
3691 info
.tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3695 info
.other
= isym
->st_other
;
3696 if (local_got_entries
)
3697 info
.first_gotent
= &local_got_entries
[r_symndx
];
3700 info
.first_gotent
= &info
.gotent
;
3707 struct alpha_elf_link_hash_entry
*h
;
3709 indx
= r_symndx
- symtab_hdr
->sh_info
;
3710 h
= alpha_elf_sym_hashes (abfd
)[indx
];
3711 BFD_ASSERT (h
!= NULL
);
3713 while (h
->root
.root
.type
== bfd_link_hash_indirect
3714 || h
->root
.root
.type
== bfd_link_hash_warning
)
3715 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3717 /* If the symbol is undefined, we can't do anything with it. */
3718 if (h
->root
.root
.type
== bfd_link_hash_undefined
)
3721 /* If the symbol isn't defined in the current module,
3722 again we can't do anything. */
3723 if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3725 info
.tsec
= bfd_abs_section_ptr
;
3728 else if (!h
->root
.def_regular
)
3730 /* Except for TLSGD relocs, which can sometimes be
3731 relaxed to GOTTPREL relocs. */
3732 if (r_type
!= R_ALPHA_TLSGD
)
3734 info
.tsec
= bfd_abs_section_ptr
;
3739 info
.tsec
= h
->root
.root
.u
.def
.section
;
3740 symval
= h
->root
.root
.u
.def
.value
;
3744 info
.other
= h
->root
.other
;
3745 info
.first_gotent
= &h
->got_entries
;
3748 /* Search for the got entry to be used by this relocation. */
3749 for (gotent
= *info
.first_gotent
; gotent
; gotent
= gotent
->next
)
3750 if (gotent
->gotobj
== info
.gotobj
3751 && gotent
->reloc_type
== r_type
3752 && gotent
->addend
== irel
->r_addend
)
3754 info
.gotent
= gotent
;
3756 symval
+= info
.tsec
->output_section
->vma
+ info
.tsec
->output_offset
;
3757 symval
+= irel
->r_addend
;
3761 case R_ALPHA_LITERAL
:
3762 BFD_ASSERT(info
.gotent
!= NULL
);
3764 /* If there exist LITUSE relocations immediately following, this
3765 opens up all sorts of interesting optimizations, because we
3766 now know every location that this address load is used. */
3767 if (irel
+1 < irelend
3768 && ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
3770 if (!elf64_alpha_relax_with_lituse (&info
, symval
, irel
))
3775 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
3780 case R_ALPHA_GOTDTPREL
:
3781 case R_ALPHA_GOTTPREL
:
3782 BFD_ASSERT(info
.gotent
!= NULL
);
3783 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
3788 case R_ALPHA_TLSLDM
:
3789 BFD_ASSERT(info
.gotent
!= NULL
);
3790 if (!elf64_alpha_relax_tls_get_addr (&info
, symval
, irel
,
3791 r_type
== R_ALPHA_TLSGD
))
3797 if (!elf64_alpha_size_plt_section (link_info
))
3799 if (!elf64_alpha_size_got_sections (link_info
))
3801 if (!elf64_alpha_size_rela_got_section (link_info
))
3805 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3807 if (!link_info
->keep_memory
)
3811 /* Cache the symbols for elf_link_input_bfd. */
3812 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3816 if (info
.contents
!= NULL
3817 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
3819 if (!info
.changed_contents
&& !link_info
->keep_memory
)
3820 free (info
.contents
);
3823 /* Cache the section contents for elf_link_input_bfd. */
3824 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
3828 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3830 if (!info
.changed_relocs
)
3831 free (internal_relocs
);
3833 elf_section_data (sec
)->relocs
= internal_relocs
;
3836 *again
= info
.changed_contents
|| info
.changed_relocs
;
3842 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3844 if (info
.contents
!= NULL
3845 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
3846 free (info
.contents
);
3847 if (internal_relocs
!= NULL
3848 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3849 free (internal_relocs
);
3853 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
3854 into the next available slot in SREL. */
3857 elf64_alpha_emit_dynrel (bfd
*abfd
, struct bfd_link_info
*info
,
3858 asection
*sec
, asection
*srel
, bfd_vma offset
,
3859 long dynindx
, long rtype
, bfd_vma addend
)
3861 Elf_Internal_Rela outrel
;
3864 BFD_ASSERT (srel
!= NULL
);
3866 outrel
.r_info
= ELF64_R_INFO (dynindx
, rtype
);
3867 outrel
.r_addend
= addend
;
3869 offset
= _bfd_elf_section_offset (abfd
, info
, sec
, offset
);
3870 if ((offset
| 1) != (bfd_vma
) -1)
3871 outrel
.r_offset
= sec
->output_section
->vma
+ sec
->output_offset
+ offset
;
3873 memset (&outrel
, 0, sizeof (outrel
));
3875 loc
= srel
->contents
;
3876 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3877 bfd_elf64_swap_reloca_out (abfd
, &outrel
, loc
);
3878 BFD_ASSERT (sizeof (Elf64_External_Rela
) * srel
->reloc_count
<= srel
->size
);
3881 /* Relocate an Alpha ELF section for a relocatable link.
3883 We don't have to change anything unless the reloc is against a section
3884 symbol, in which case we have to adjust according to where the section
3885 symbol winds up in the output section. */
3888 elf64_alpha_relocate_section_r (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3889 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3890 bfd
*input_bfd
, asection
*input_section
,
3891 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3892 Elf_Internal_Rela
*relocs
,
3893 Elf_Internal_Sym
*local_syms
,
3894 asection
**local_sections
)
3896 unsigned long symtab_hdr_sh_info
;
3897 Elf_Internal_Rela
*rel
;
3898 Elf_Internal_Rela
*relend
;
3899 bfd_boolean ret_val
= TRUE
;
3901 symtab_hdr_sh_info
= elf_tdata (input_bfd
)->symtab_hdr
.sh_info
;
3903 relend
= relocs
+ input_section
->reloc_count
;
3904 for (rel
= relocs
; rel
< relend
; rel
++)
3906 unsigned long r_symndx
;
3907 Elf_Internal_Sym
*sym
;
3909 unsigned long r_type
;
3911 r_type
= ELF64_R_TYPE(rel
->r_info
);
3912 if (r_type
>= R_ALPHA_max
)
3914 (*_bfd_error_handler
)
3915 (_("%B: unknown relocation type %d"),
3916 input_bfd
, (int) r_type
);
3917 bfd_set_error (bfd_error_bad_value
);
3922 r_symndx
= ELF64_R_SYM(rel
->r_info
);
3924 /* The symbol associated with GPDISP and LITUSE is
3925 immaterial. Only the addend is significant. */
3926 if (r_type
== R_ALPHA_GPDISP
|| r_type
== R_ALPHA_LITUSE
)
3929 if (r_symndx
< symtab_hdr_sh_info
)
3931 sym
= local_syms
+ r_symndx
;
3932 if (ELF_ST_TYPE(sym
->st_info
) == STT_SECTION
)
3934 sec
= local_sections
[r_symndx
];
3935 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
3943 /* Relocate an Alpha ELF section. */
3946 elf64_alpha_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
3947 bfd
*input_bfd
, asection
*input_section
,
3948 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
3949 Elf_Internal_Sym
*local_syms
,
3950 asection
**local_sections
)
3952 Elf_Internal_Shdr
*symtab_hdr
;
3953 Elf_Internal_Rela
*rel
;
3954 Elf_Internal_Rela
*relend
;
3955 asection
*sgot
, *srel
, *srelgot
;
3956 bfd
*dynobj
, *gotobj
;
3957 bfd_vma gp
, tp_base
, dtp_base
;
3958 struct alpha_elf_got_entry
**local_got_entries
;
3959 bfd_boolean ret_val
;
3961 /* Handle relocatable links with a smaller loop. */
3962 if (info
->relocatable
)
3963 return elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
,
3964 input_section
, contents
, relocs
,
3965 local_syms
, local_sections
);
3967 /* This is a final link. */
3971 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3973 dynobj
= elf_hash_table (info
)->dynobj
;
3975 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3979 if (input_section
->flags
& SEC_ALLOC
)
3981 const char *section_name
;
3982 section_name
= (bfd_elf_string_from_elf_section
3983 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
3984 elf_section_data(input_section
)->rel_hdr
.sh_name
));
3985 BFD_ASSERT(section_name
!= NULL
);
3986 srel
= bfd_get_section_by_name (dynobj
, section_name
);
3991 /* Find the gp value for this input bfd. */
3992 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
3995 sgot
= alpha_elf_tdata (gotobj
)->got
;
3996 gp
= _bfd_get_gp_value (gotobj
);
3999 gp
= (sgot
->output_section
->vma
4000 + sgot
->output_offset
4002 _bfd_set_gp_value (gotobj
, gp
);
4011 local_got_entries
= alpha_elf_tdata(input_bfd
)->local_got_entries
;
4013 if (elf_hash_table (info
)->tls_sec
!= NULL
)
4015 dtp_base
= alpha_get_dtprel_base (info
);
4016 tp_base
= alpha_get_tprel_base (info
);
4019 dtp_base
= tp_base
= 0;
4021 relend
= relocs
+ input_section
->reloc_count
;
4022 for (rel
= relocs
; rel
< relend
; rel
++)
4024 struct alpha_elf_link_hash_entry
*h
= NULL
;
4025 struct alpha_elf_got_entry
*gotent
;
4026 bfd_reloc_status_type r
;
4027 reloc_howto_type
*howto
;
4028 unsigned long r_symndx
;
4029 Elf_Internal_Sym
*sym
= NULL
;
4030 asection
*sec
= NULL
;
4033 bfd_boolean dynamic_symbol_p
;
4034 bfd_boolean undef_weak_ref
= FALSE
;
4035 unsigned long r_type
;
4037 r_type
= ELF64_R_TYPE(rel
->r_info
);
4038 if (r_type
>= R_ALPHA_max
)
4040 (*_bfd_error_handler
)
4041 (_("%B: unknown relocation type %d"),
4042 input_bfd
, (int) r_type
);
4043 bfd_set_error (bfd_error_bad_value
);
4048 howto
= elf64_alpha_howto_table
+ r_type
;
4049 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4051 /* The symbol for a TLSLDM reloc is ignored. Collapse the
4052 reloc to the 0 symbol so that they all match. */
4053 if (r_type
== R_ALPHA_TLSLDM
)
4056 if (r_symndx
< symtab_hdr
->sh_info
)
4059 sym
= local_syms
+ r_symndx
;
4060 sec
= local_sections
[r_symndx
];
4062 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &msec
, rel
);
4064 /* If this is a tp-relative relocation against sym 0,
4065 this is hackery from relax_section. Force the value to
4066 be the tls module base. */
4068 && (r_type
== R_ALPHA_TLSLDM
4069 || r_type
== R_ALPHA_GOTTPREL
4070 || r_type
== R_ALPHA_TPREL64
4071 || r_type
== R_ALPHA_TPRELHI
4072 || r_type
== R_ALPHA_TPRELLO
4073 || r_type
== R_ALPHA_TPREL16
))
4076 if (local_got_entries
)
4077 gotent
= local_got_entries
[r_symndx
];
4081 /* Need to adjust local GOT entries' addends for SEC_MERGE
4082 unless it has been done already. */
4083 if ((sec
->flags
& SEC_MERGE
)
4084 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
4085 && sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
4087 && !gotent
->reloc_xlated
)
4089 struct alpha_elf_got_entry
*ent
;
4091 for (ent
= gotent
; ent
; ent
= ent
->next
)
4093 ent
->reloc_xlated
= 1;
4094 if (ent
->use_count
== 0)
4098 _bfd_merged_section_offset (output_bfd
, &msec
,
4099 elf_section_data (sec
)->
4101 sym
->st_value
+ ent
->addend
);
4102 ent
->addend
-= sym
->st_value
;
4103 ent
->addend
+= msec
->output_section
->vma
4104 + msec
->output_offset
4105 - sec
->output_section
->vma
4106 - sec
->output_offset
;
4110 dynamic_symbol_p
= FALSE
;
4115 bfd_boolean unresolved_reloc
;
4116 struct elf_link_hash_entry
*hh
;
4117 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
4119 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4120 r_symndx
, symtab_hdr
, sym_hashes
,
4122 unresolved_reloc
, warned
);
4128 && ! unresolved_reloc
4129 && hh
->root
.type
== bfd_link_hash_undefweak
)
4130 undef_weak_ref
= TRUE
;
4132 h
= (struct alpha_elf_link_hash_entry
*) hh
;
4133 dynamic_symbol_p
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4134 gotent
= h
->got_entries
;
4137 addend
= rel
->r_addend
;
4140 /* Search for the proper got entry. */
4141 for (; gotent
; gotent
= gotent
->next
)
4142 if (gotent
->gotobj
== gotobj
4143 && gotent
->reloc_type
== r_type
4144 && gotent
->addend
== addend
)
4149 case R_ALPHA_GPDISP
:
4151 bfd_byte
*p_ldah
, *p_lda
;
4153 BFD_ASSERT(gp
!= 0);
4155 value
= (input_section
->output_section
->vma
4156 + input_section
->output_offset
4159 p_ldah
= contents
+ rel
->r_offset
;
4160 p_lda
= p_ldah
+ rel
->r_addend
;
4162 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- value
,
4167 case R_ALPHA_LITERAL
:
4168 BFD_ASSERT(sgot
!= NULL
);
4169 BFD_ASSERT(gp
!= 0);
4170 BFD_ASSERT(gotent
!= NULL
);
4171 BFD_ASSERT(gotent
->use_count
>= 1);
4173 if (!gotent
->reloc_done
)
4175 gotent
->reloc_done
= 1;
4177 bfd_put_64 (output_bfd
, value
,
4178 sgot
->contents
+ gotent
->got_offset
);
4180 /* If the symbol has been forced local, output a
4181 RELATIVE reloc, otherwise it will be handled in
4182 finish_dynamic_symbol. */
4183 if (info
->shared
&& !dynamic_symbol_p
&& !undef_weak_ref
)
4184 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4185 gotent
->got_offset
, 0,
4186 R_ALPHA_RELATIVE
, value
);
4189 value
= (sgot
->output_section
->vma
4190 + sgot
->output_offset
4191 + gotent
->got_offset
);
4195 case R_ALPHA_GPREL32
:
4196 /* If the target section was a removed linkonce section,
4197 r_symndx will be zero. In this case, assume that the
4198 switch will not be used, so don't fill it in. If we
4199 do nothing here, we'll get relocation truncated messages,
4200 due to the placement of the application above 4GB. */
4208 case R_ALPHA_GPREL16
:
4209 case R_ALPHA_GPRELLOW
:
4210 if (dynamic_symbol_p
)
4212 (*_bfd_error_handler
)
4213 (_("%B: gp-relative relocation against dynamic symbol %s"),
4214 input_bfd
, h
->root
.root
.root
.string
);
4217 BFD_ASSERT(gp
!= 0);
4221 case R_ALPHA_GPRELHIGH
:
4222 if (dynamic_symbol_p
)
4224 (*_bfd_error_handler
)
4225 (_("%B: gp-relative relocation against dynamic symbol %s"),
4226 input_bfd
, h
->root
.root
.root
.string
);
4229 BFD_ASSERT(gp
!= 0);
4231 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4235 /* A call to a dynamic symbol is definitely out of range of
4236 the 16-bit displacement. Don't bother writing anything. */
4237 if (dynamic_symbol_p
)
4242 /* The regular PC-relative stuff measures from the start of
4243 the instruction rather than the end. */
4247 case R_ALPHA_BRADDR
:
4248 if (dynamic_symbol_p
)
4250 (*_bfd_error_handler
)
4251 (_("%B: pc-relative relocation against dynamic symbol %s"),
4252 input_bfd
, h
->root
.root
.root
.string
);
4255 /* The regular PC-relative stuff measures from the start of
4256 the instruction rather than the end. */
4265 /* The regular PC-relative stuff measures from the start of
4266 the instruction rather than the end. */
4269 /* The source and destination gp must be the same. Note that
4270 the source will always have an assigned gp, since we forced
4271 one in check_relocs, but that the destination may not, as
4272 it might not have had any relocations at all. Also take
4273 care not to crash if H is an undefined symbol. */
4274 if (h
!= NULL
&& sec
!= NULL
4275 && alpha_elf_tdata (sec
->owner
)->gotobj
4276 && gotobj
!= alpha_elf_tdata (sec
->owner
)->gotobj
)
4278 (*_bfd_error_handler
)
4279 (_("%B: change in gp: BRSGP %s"),
4280 input_bfd
, h
->root
.root
.root
.string
);
4284 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4286 other
= h
->root
.other
;
4288 other
= sym
->st_other
;
4289 switch (other
& STO_ALPHA_STD_GPLOAD
)
4291 case STO_ALPHA_NOPV
:
4293 case STO_ALPHA_STD_GPLOAD
:
4298 name
= h
->root
.root
.root
.string
;
4301 name
= (bfd_elf_string_from_elf_section
4302 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4304 name
= _("<unknown>");
4305 else if (name
[0] == 0)
4306 name
= bfd_section_name (input_bfd
, sec
);
4308 (*_bfd_error_handler
)
4309 (_("%B: !samegp reloc against symbol without .prologue: %s"),
4318 case R_ALPHA_REFLONG
:
4319 case R_ALPHA_REFQUAD
:
4320 case R_ALPHA_DTPREL64
:
4321 case R_ALPHA_TPREL64
:
4323 long dynindx
, dyntype
= r_type
;
4326 /* Careful here to remember RELATIVE relocations for global
4327 variables for symbolic shared objects. */
4329 if (dynamic_symbol_p
)
4331 BFD_ASSERT(h
->root
.dynindx
!= -1);
4332 dynindx
= h
->root
.dynindx
;
4334 addend
= 0, value
= 0;
4336 else if (r_type
== R_ALPHA_DTPREL64
)
4338 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4342 else if (r_type
== R_ALPHA_TPREL64
)
4344 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4351 dynaddend
= value
- dtp_base
;
4353 else if (info
->shared
4355 && (input_section
->flags
& SEC_ALLOC
)
4358 if (r_type
== R_ALPHA_REFLONG
)
4360 (*_bfd_error_handler
)
4361 (_("%B: unhandled dynamic relocation against %s"),
4363 h
->root
.root
.root
.string
);
4367 dyntype
= R_ALPHA_RELATIVE
;
4373 if (input_section
->flags
& SEC_ALLOC
)
4374 elf64_alpha_emit_dynrel (output_bfd
, info
, input_section
,
4375 srel
, rel
->r_offset
, dynindx
,
4376 dyntype
, dynaddend
);
4380 case R_ALPHA_SREL16
:
4381 case R_ALPHA_SREL32
:
4382 case R_ALPHA_SREL64
:
4383 if (dynamic_symbol_p
)
4385 (*_bfd_error_handler
)
4386 (_("%B: pc-relative relocation against dynamic symbol %s"),
4387 input_bfd
, h
->root
.root
.root
.string
);
4390 else if ((info
->shared
|| info
->pie
) && undef_weak_ref
)
4392 (*_bfd_error_handler
)
4393 (_("%B: pc-relative relocation against undefined weak symbol %s"),
4394 input_bfd
, h
->root
.root
.root
.string
);
4399 /* ??? .eh_frame references to discarded sections will be smashed
4400 to relocations against SHN_UNDEF. The .eh_frame format allows
4401 NULL to be encoded as 0 in any format, so this works here. */
4403 howto
= (elf64_alpha_howto_table
4404 + (r_type
- R_ALPHA_SREL32
+ R_ALPHA_REFLONG
));
4407 case R_ALPHA_TLSLDM
:
4408 /* Ignore the symbol for the relocation. The result is always
4409 the current module. */
4410 dynamic_symbol_p
= 0;
4414 if (!gotent
->reloc_done
)
4416 gotent
->reloc_done
= 1;
4418 /* Note that the module index for the main program is 1. */
4419 bfd_put_64 (output_bfd
, !info
->shared
&& !dynamic_symbol_p
,
4420 sgot
->contents
+ gotent
->got_offset
);
4422 /* If the symbol has been forced local, output a
4423 DTPMOD64 reloc, otherwise it will be handled in
4424 finish_dynamic_symbol. */
4425 if (info
->shared
&& !dynamic_symbol_p
)
4426 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4427 gotent
->got_offset
, 0,
4428 R_ALPHA_DTPMOD64
, 0);
4430 if (dynamic_symbol_p
|| r_type
== R_ALPHA_TLSLDM
)
4434 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4437 bfd_put_64 (output_bfd
, value
,
4438 sgot
->contents
+ gotent
->got_offset
+ 8);
4441 value
= (sgot
->output_section
->vma
4442 + sgot
->output_offset
4443 + gotent
->got_offset
);
4447 case R_ALPHA_DTPRELHI
:
4448 case R_ALPHA_DTPRELLO
:
4449 case R_ALPHA_DTPREL16
:
4450 if (dynamic_symbol_p
)
4452 (*_bfd_error_handler
)
4453 (_("%B: dtp-relative relocation against dynamic symbol %s"),
4454 input_bfd
, h
->root
.root
.root
.string
);
4457 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4459 if (r_type
== R_ALPHA_DTPRELHI
)
4460 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4463 case R_ALPHA_TPRELHI
:
4464 case R_ALPHA_TPRELLO
:
4465 case R_ALPHA_TPREL16
:
4468 (*_bfd_error_handler
)
4469 (_("%B: TLS local exec code cannot be linked into shared objects"),
4473 else if (dynamic_symbol_p
)
4475 (*_bfd_error_handler
)
4476 (_("%B: tp-relative relocation against dynamic symbol %s"),
4477 input_bfd
, h
->root
.root
.root
.string
);
4480 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4482 if (r_type
== R_ALPHA_TPRELHI
)
4483 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4486 case R_ALPHA_GOTDTPREL
:
4487 case R_ALPHA_GOTTPREL
:
4488 BFD_ASSERT(sgot
!= NULL
);
4489 BFD_ASSERT(gp
!= 0);
4490 BFD_ASSERT(gotent
!= NULL
);
4491 BFD_ASSERT(gotent
->use_count
>= 1);
4493 if (!gotent
->reloc_done
)
4495 gotent
->reloc_done
= 1;
4497 if (dynamic_symbol_p
)
4501 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4502 if (r_type
== R_ALPHA_GOTDTPREL
)
4504 else if (!info
->shared
)
4508 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4509 gotent
->got_offset
, 0,
4515 bfd_put_64 (output_bfd
, value
,
4516 sgot
->contents
+ gotent
->got_offset
);
4519 value
= (sgot
->output_section
->vma
4520 + sgot
->output_offset
4521 + gotent
->got_offset
);
4527 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4528 contents
, rel
->r_offset
, value
, 0);
4537 case bfd_reloc_overflow
:
4541 /* Don't warn if the overflow is due to pc relative reloc
4542 against discarded section. Section optimization code should
4545 if (r_symndx
< symtab_hdr
->sh_info
4546 && sec
!= NULL
&& howto
->pc_relative
4547 && elf_discarded_section (sec
))
4554 name
= (bfd_elf_string_from_elf_section
4555 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4559 name
= bfd_section_name (input_bfd
, sec
);
4561 if (! ((*info
->callbacks
->reloc_overflow
)
4562 (info
, (h
? &h
->root
.root
: NULL
), name
, howto
->name
,
4563 (bfd_vma
) 0, input_bfd
, input_section
,
4570 case bfd_reloc_outofrange
:
4578 /* Finish up dynamic symbol handling. We set the contents of various
4579 dynamic sections here. */
4582 elf64_alpha_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
4583 struct elf_link_hash_entry
*h
,
4584 Elf_Internal_Sym
*sym
)
4586 struct alpha_elf_link_hash_entry
*ah
= (struct alpha_elf_link_hash_entry
*)h
;
4587 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4591 /* Fill in the .plt entry for this symbol. */
4592 asection
*splt
, *sgot
, *srel
;
4593 Elf_Internal_Rela outrel
;
4595 bfd_vma got_addr
, plt_addr
;
4597 struct alpha_elf_got_entry
*gotent
;
4599 BFD_ASSERT (h
->dynindx
!= -1);
4601 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4602 BFD_ASSERT (splt
!= NULL
);
4603 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4604 BFD_ASSERT (srel
!= NULL
);
4606 for (gotent
= ah
->got_entries
; gotent
; gotent
= gotent
->next
)
4607 if (gotent
->reloc_type
== R_ALPHA_LITERAL
4608 && gotent
->use_count
> 0)
4613 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4614 BFD_ASSERT (sgot
!= NULL
);
4616 BFD_ASSERT (gotent
->got_offset
!= -1);
4617 BFD_ASSERT (gotent
->plt_offset
!= -1);
4619 got_addr
= (sgot
->output_section
->vma
4620 + sgot
->output_offset
4621 + gotent
->got_offset
);
4622 plt_addr
= (splt
->output_section
->vma
4623 + splt
->output_offset
4624 + gotent
->plt_offset
);
4626 plt_index
= (gotent
->plt_offset
-PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
4628 /* Fill in the entry in the procedure linkage table. */
4629 if (elf64_alpha_use_secureplt
)
4631 disp
= (PLT_HEADER_SIZE
- 4) - (gotent
->plt_offset
+ 4);
4632 insn
= INSN_AD (INSN_BR
, 31, disp
);
4633 bfd_put_32 (output_bfd
, insn
,
4634 splt
->contents
+ gotent
->plt_offset
);
4636 plt_index
= ((gotent
->plt_offset
- NEW_PLT_HEADER_SIZE
)
4637 / NEW_PLT_ENTRY_SIZE
);
4641 disp
= -(gotent
->plt_offset
+ 4);
4642 insn
= INSN_AD (INSN_BR
, 28, disp
);
4643 bfd_put_32 (output_bfd
, insn
,
4644 splt
->contents
+ gotent
->plt_offset
);
4645 bfd_put_32 (output_bfd
, INSN_UNOP
,
4646 splt
->contents
+ gotent
->plt_offset
+ 4);
4647 bfd_put_32 (output_bfd
, INSN_UNOP
,
4648 splt
->contents
+ gotent
->plt_offset
+ 8);
4650 plt_index
= ((gotent
->plt_offset
- OLD_PLT_HEADER_SIZE
)
4651 / OLD_PLT_ENTRY_SIZE
);
4654 /* Fill in the entry in the .rela.plt section. */
4655 outrel
.r_offset
= got_addr
;
4656 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
4657 outrel
.r_addend
= 0;
4659 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
4660 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
4662 /* Fill in the entry in the .got. */
4663 bfd_put_64 (output_bfd
, plt_addr
,
4664 sgot
->contents
+ gotent
->got_offset
);
4667 else if (alpha_elf_dynamic_symbol_p (h
, info
))
4669 /* Fill in the dynamic relocations for this symbol's .got entries. */
4671 struct alpha_elf_got_entry
*gotent
;
4673 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4674 BFD_ASSERT (srel
!= NULL
);
4676 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4678 gotent
= gotent
->next
)
4683 if (gotent
->use_count
== 0)
4686 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4688 r_type
= gotent
->reloc_type
;
4691 case R_ALPHA_LITERAL
:
4692 r_type
= R_ALPHA_GLOB_DAT
;
4695 r_type
= R_ALPHA_DTPMOD64
;
4697 case R_ALPHA_GOTDTPREL
:
4698 r_type
= R_ALPHA_DTPREL64
;
4700 case R_ALPHA_GOTTPREL
:
4701 r_type
= R_ALPHA_TPREL64
;
4703 case R_ALPHA_TLSLDM
:
4708 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4709 gotent
->got_offset
, h
->dynindx
,
4710 r_type
, gotent
->addend
);
4712 if (gotent
->reloc_type
== R_ALPHA_TLSGD
)
4713 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4714 gotent
->got_offset
+ 8, h
->dynindx
,
4715 R_ALPHA_DTPREL64
, gotent
->addend
);
4719 /* Mark some specially defined symbols as absolute. */
4720 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4721 || h
== elf_hash_table (info
)->hgot
4722 || h
== elf_hash_table (info
)->hplt
)
4723 sym
->st_shndx
= SHN_ABS
;
4728 /* Finish up the dynamic sections. */
4731 elf64_alpha_finish_dynamic_sections (bfd
*output_bfd
,
4732 struct bfd_link_info
*info
)
4737 dynobj
= elf_hash_table (info
)->dynobj
;
4738 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4740 if (elf_hash_table (info
)->dynamic_sections_created
)
4742 asection
*splt
, *sgotplt
, *srelaplt
;
4743 Elf64_External_Dyn
*dyncon
, *dynconend
;
4744 bfd_vma plt_vma
, gotplt_vma
;
4746 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4747 srelaplt
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4748 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
4750 plt_vma
= splt
->output_section
->vma
+ splt
->output_offset
;
4753 if (elf64_alpha_use_secureplt
)
4755 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
4756 BFD_ASSERT (sgotplt
!= NULL
);
4757 if (sgotplt
->size
> 0)
4758 gotplt_vma
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
;
4761 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4762 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4763 for (; dyncon
< dynconend
; dyncon
++)
4765 Elf_Internal_Dyn dyn
;
4767 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4773 = elf64_alpha_use_secureplt
? gotplt_vma
: plt_vma
;
4776 dyn
.d_un
.d_val
= srelaplt
? srelaplt
->size
: 0;
4779 dyn
.d_un
.d_ptr
= srelaplt
? srelaplt
->vma
: 0;
4783 /* My interpretation of the TIS v1.1 ELF document indicates
4784 that RELASZ should not include JMPREL. This is not what
4785 the rest of the BFD does. It is, however, what the
4786 glibc ld.so wants. Do this fixup here until we found
4787 out who is right. */
4789 dyn
.d_un
.d_val
-= srelaplt
->size
;
4793 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4796 /* Initialize the plt header. */
4802 if (elf64_alpha_use_secureplt
)
4804 ofs
= gotplt_vma
- (plt_vma
+ PLT_HEADER_SIZE
);
4806 insn
= INSN_ABC (INSN_SUBQ
, 27, 28, 25);
4807 bfd_put_32 (output_bfd
, insn
, splt
->contents
);
4809 insn
= INSN_ABO (INSN_LDAH
, 28, 28, (ofs
+ 0x8000) >> 16);
4810 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 4);
4812 insn
= INSN_ABC (INSN_S4SUBQ
, 25, 25, 25);
4813 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 8);
4815 insn
= INSN_ABO (INSN_LDA
, 28, 28, ofs
);
4816 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 12);
4818 insn
= INSN_ABO (INSN_LDQ
, 27, 28, 0);
4819 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 16);
4821 insn
= INSN_ABC (INSN_ADDQ
, 25, 25, 25);
4822 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 20);
4824 insn
= INSN_ABO (INSN_LDQ
, 28, 28, 8);
4825 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 24);
4827 insn
= INSN_AB (INSN_JMP
, 31, 27);
4828 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 28);
4830 insn
= INSN_AD (INSN_BR
, 28, -PLT_HEADER_SIZE
);
4831 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 32);
4835 insn
= INSN_AD (INSN_BR
, 27, 0); /* br $27, .+4 */
4836 bfd_put_32 (output_bfd
, insn
, splt
->contents
);
4838 insn
= INSN_ABO (INSN_LDQ
, 27, 27, 12);
4839 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 4);
4842 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 8);
4844 insn
= INSN_AB (INSN_JMP
, 27, 27);
4845 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 12);
4847 /* The next two words will be filled in by ld.so. */
4848 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 16);
4849 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 24);
4852 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 0;
4859 /* We need to use a special link routine to handle the .mdebug section.
4860 We need to merge all instances of these sections together, not write
4861 them all out sequentially. */
4864 elf64_alpha_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
4867 struct bfd_link_order
*p
;
4868 asection
*mdebug_sec
;
4869 struct ecoff_debug_info debug
;
4870 const struct ecoff_debug_swap
*swap
4871 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4872 HDRR
*symhdr
= &debug
.symbolic_header
;
4873 PTR mdebug_handle
= NULL
;
4875 /* Go through the sections and collect the mdebug information. */
4877 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4879 if (strcmp (o
->name
, ".mdebug") == 0)
4881 struct extsym_info einfo
;
4883 /* We have found the .mdebug section in the output file.
4884 Look through all the link_orders comprising it and merge
4885 the information together. */
4886 symhdr
->magic
= swap
->sym_magic
;
4887 /* FIXME: What should the version stamp be? */
4889 symhdr
->ilineMax
= 0;
4893 symhdr
->isymMax
= 0;
4894 symhdr
->ioptMax
= 0;
4895 symhdr
->iauxMax
= 0;
4897 symhdr
->issExtMax
= 0;
4900 symhdr
->iextMax
= 0;
4902 /* We accumulate the debugging information itself in the
4903 debug_info structure. */
4905 debug
.external_dnr
= NULL
;
4906 debug
.external_pdr
= NULL
;
4907 debug
.external_sym
= NULL
;
4908 debug
.external_opt
= NULL
;
4909 debug
.external_aux
= NULL
;
4911 debug
.ssext
= debug
.ssext_end
= NULL
;
4912 debug
.external_fdr
= NULL
;
4913 debug
.external_rfd
= NULL
;
4914 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4916 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4917 if (mdebug_handle
== (PTR
) NULL
)
4926 static const char * const name
[] =
4928 ".text", ".init", ".fini", ".data",
4929 ".rodata", ".sdata", ".sbss", ".bss"
4931 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4932 scRData
, scSData
, scSBss
, scBss
};
4935 esym
.cobol_main
= 0;
4939 esym
.asym
.iss
= issNil
;
4940 esym
.asym
.st
= stLocal
;
4941 esym
.asym
.reserved
= 0;
4942 esym
.asym
.index
= indexNil
;
4943 for (i
= 0; i
< 8; i
++)
4945 esym
.asym
.sc
= sc
[i
];
4946 s
= bfd_get_section_by_name (abfd
, name
[i
]);
4949 esym
.asym
.value
= s
->vma
;
4950 last
= s
->vma
+ s
->size
;
4953 esym
.asym
.value
= last
;
4955 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
4961 for (p
= o
->map_head
.link_order
;
4962 p
!= (struct bfd_link_order
*) NULL
;
4965 asection
*input_section
;
4967 const struct ecoff_debug_swap
*input_swap
;
4968 struct ecoff_debug_info input_debug
;
4972 if (p
->type
!= bfd_indirect_link_order
)
4974 if (p
->type
== bfd_data_link_order
)
4979 input_section
= p
->u
.indirect
.section
;
4980 input_bfd
= input_section
->owner
;
4982 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
4983 || (get_elf_backend_data (input_bfd
)
4984 ->elf_backend_ecoff_debug_swap
) == NULL
)
4986 /* I don't know what a non ALPHA ELF bfd would be
4987 doing with a .mdebug section, but I don't really
4988 want to deal with it. */
4992 input_swap
= (get_elf_backend_data (input_bfd
)
4993 ->elf_backend_ecoff_debug_swap
);
4995 BFD_ASSERT (p
->size
== input_section
->size
);
4997 /* The ECOFF linking code expects that we have already
4998 read in the debugging information and set up an
4999 ecoff_debug_info structure, so we do that now. */
5000 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
5004 if (! (bfd_ecoff_debug_accumulate
5005 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5006 &input_debug
, input_swap
, info
)))
5009 /* Loop through the external symbols. For each one with
5010 interesting information, try to find the symbol in
5011 the linker global hash table and save the information
5012 for the output external symbols. */
5013 eraw_src
= input_debug
.external_ext
;
5014 eraw_end
= (eraw_src
5015 + (input_debug
.symbolic_header
.iextMax
5016 * input_swap
->external_ext_size
));
5018 eraw_src
< eraw_end
;
5019 eraw_src
+= input_swap
->external_ext_size
)
5023 struct alpha_elf_link_hash_entry
*h
;
5025 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5026 if (ext
.asym
.sc
== scNil
5027 || ext
.asym
.sc
== scUndefined
5028 || ext
.asym
.sc
== scSUndefined
)
5031 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5032 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
5033 name
, FALSE
, FALSE
, TRUE
);
5034 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5040 < input_debug
.symbolic_header
.ifdMax
);
5041 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5047 /* Free up the information we just read. */
5048 free (input_debug
.line
);
5049 free (input_debug
.external_dnr
);
5050 free (input_debug
.external_pdr
);
5051 free (input_debug
.external_sym
);
5052 free (input_debug
.external_opt
);
5053 free (input_debug
.external_aux
);
5054 free (input_debug
.ss
);
5055 free (input_debug
.ssext
);
5056 free (input_debug
.external_fdr
);
5057 free (input_debug
.external_rfd
);
5058 free (input_debug
.external_ext
);
5060 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5061 elf_link_input_bfd ignores this section. */
5062 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5065 /* Build the external symbol information. */
5068 einfo
.debug
= &debug
;
5070 einfo
.failed
= FALSE
;
5071 elf_link_hash_traverse (elf_hash_table (info
),
5072 elf64_alpha_output_extsym
,
5077 /* Set the size of the .mdebug section. */
5078 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5080 /* Skip this section later on (I don't think this currently
5081 matters, but someday it might). */
5082 o
->map_head
.link_order
= (struct bfd_link_order
*) NULL
;
5088 /* Invoke the regular ELF backend linker to do all the work. */
5089 if (! bfd_elf_final_link (abfd
, info
))
5092 /* Now write out the computed sections. */
5094 /* The .got subsections... */
5096 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
5097 for (i
= alpha_elf_hash_table(info
)->got_list
;
5099 i
= alpha_elf_tdata(i
)->got_link_next
)
5103 /* elf_bfd_final_link already did everything in dynobj. */
5107 sgot
= alpha_elf_tdata(i
)->got
;
5108 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
5110 (file_ptr
) sgot
->output_offset
,
5116 if (mdebug_sec
!= (asection
*) NULL
)
5118 BFD_ASSERT (abfd
->output_has_begun
);
5119 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5121 mdebug_sec
->filepos
))
5124 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5130 static enum elf_reloc_type_class
5131 elf64_alpha_reloc_type_class (const Elf_Internal_Rela
*rela
)
5133 switch ((int) ELF64_R_TYPE (rela
->r_info
))
5135 case R_ALPHA_RELATIVE
:
5136 return reloc_class_relative
;
5137 case R_ALPHA_JMP_SLOT
:
5138 return reloc_class_plt
;
5140 return reloc_class_copy
;
5142 return reloc_class_normal
;
5146 static const struct bfd_elf_special_section elf64_alpha_special_sections
[] =
5148 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_ALPHA_GPREL
},
5149 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_ALPHA_GPREL
},
5150 { NULL
, 0, 0, 0, 0 }
5153 /* ECOFF swapping routines. These are used when dealing with the
5154 .mdebug section, which is in the ECOFF debugging format. Copied
5155 from elf32-mips.c. */
5156 static const struct ecoff_debug_swap
5157 elf64_alpha_ecoff_debug_swap
=
5159 /* Symbol table magic number. */
5161 /* Alignment of debugging information. E.g., 4. */
5163 /* Sizes of external symbolic information. */
5164 sizeof (struct hdr_ext
),
5165 sizeof (struct dnr_ext
),
5166 sizeof (struct pdr_ext
),
5167 sizeof (struct sym_ext
),
5168 sizeof (struct opt_ext
),
5169 sizeof (struct fdr_ext
),
5170 sizeof (struct rfd_ext
),
5171 sizeof (struct ext_ext
),
5172 /* Functions to swap in external symbolic data. */
5181 _bfd_ecoff_swap_tir_in
,
5182 _bfd_ecoff_swap_rndx_in
,
5183 /* Functions to swap out external symbolic data. */
5192 _bfd_ecoff_swap_tir_out
,
5193 _bfd_ecoff_swap_rndx_out
,
5194 /* Function to read in symbolic data. */
5195 elf64_alpha_read_ecoff_info
5198 /* Use a non-standard hash bucket size of 8. */
5200 static const struct elf_size_info alpha_elf_size_info
=
5202 sizeof (Elf64_External_Ehdr
),
5203 sizeof (Elf64_External_Phdr
),
5204 sizeof (Elf64_External_Shdr
),
5205 sizeof (Elf64_External_Rel
),
5206 sizeof (Elf64_External_Rela
),
5207 sizeof (Elf64_External_Sym
),
5208 sizeof (Elf64_External_Dyn
),
5209 sizeof (Elf_External_Note
),
5213 ELFCLASS64
, EV_CURRENT
,
5214 bfd_elf64_write_out_phdrs
,
5215 bfd_elf64_write_shdrs_and_ehdr
,
5216 bfd_elf64_write_relocs
,
5217 bfd_elf64_swap_symbol_in
,
5218 bfd_elf64_swap_symbol_out
,
5219 bfd_elf64_slurp_reloc_table
,
5220 bfd_elf64_slurp_symbol_table
,
5221 bfd_elf64_swap_dyn_in
,
5222 bfd_elf64_swap_dyn_out
,
5223 bfd_elf64_swap_reloc_in
,
5224 bfd_elf64_swap_reloc_out
,
5225 bfd_elf64_swap_reloca_in
,
5226 bfd_elf64_swap_reloca_out
5229 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5230 #define TARGET_LITTLE_NAME "elf64-alpha"
5231 #define ELF_ARCH bfd_arch_alpha
5232 #define ELF_MACHINE_CODE EM_ALPHA
5233 #define ELF_MAXPAGESIZE 0x10000
5234 #define ELF_COMMONPAGESIZE 0x2000
5236 #define bfd_elf64_bfd_link_hash_table_create \
5237 elf64_alpha_bfd_link_hash_table_create
5239 #define bfd_elf64_bfd_reloc_type_lookup \
5240 elf64_alpha_bfd_reloc_type_lookup
5241 #define elf_info_to_howto \
5242 elf64_alpha_info_to_howto
5244 #define bfd_elf64_mkobject \
5245 elf64_alpha_mkobject
5246 #define elf_backend_object_p \
5247 elf64_alpha_object_p
5249 #define elf_backend_section_from_shdr \
5250 elf64_alpha_section_from_shdr
5251 #define elf_backend_section_flags \
5252 elf64_alpha_section_flags
5253 #define elf_backend_fake_sections \
5254 elf64_alpha_fake_sections
5256 #define bfd_elf64_bfd_is_local_label_name \
5257 elf64_alpha_is_local_label_name
5258 #define bfd_elf64_find_nearest_line \
5259 elf64_alpha_find_nearest_line
5260 #define bfd_elf64_bfd_relax_section \
5261 elf64_alpha_relax_section
5263 #define elf_backend_add_symbol_hook \
5264 elf64_alpha_add_symbol_hook
5265 #define elf_backend_check_relocs \
5266 elf64_alpha_check_relocs
5267 #define elf_backend_create_dynamic_sections \
5268 elf64_alpha_create_dynamic_sections
5269 #define elf_backend_adjust_dynamic_symbol \
5270 elf64_alpha_adjust_dynamic_symbol
5271 #define elf_backend_always_size_sections \
5272 elf64_alpha_always_size_sections
5273 #define elf_backend_size_dynamic_sections \
5274 elf64_alpha_size_dynamic_sections
5275 #define elf_backend_relocate_section \
5276 elf64_alpha_relocate_section
5277 #define elf_backend_finish_dynamic_symbol \
5278 elf64_alpha_finish_dynamic_symbol
5279 #define elf_backend_finish_dynamic_sections \
5280 elf64_alpha_finish_dynamic_sections
5281 #define bfd_elf64_bfd_final_link \
5282 elf64_alpha_final_link
5283 #define elf_backend_reloc_type_class \
5284 elf64_alpha_reloc_type_class
5286 #define elf_backend_ecoff_debug_swap \
5287 &elf64_alpha_ecoff_debug_swap
5289 #define elf_backend_size_info \
5292 #define elf_backend_special_sections \
5293 elf64_alpha_special_sections
5295 /* A few constants that determine how the .plt section is set up. */
5296 #define elf_backend_want_got_plt 0
5297 #define elf_backend_plt_readonly 0
5298 #define elf_backend_want_plt_sym 1
5299 #define elf_backend_got_header_size 0
5301 #include "elf64-target.h"
5303 /* FreeBSD support. */
5305 #undef TARGET_LITTLE_SYM
5306 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5307 #undef TARGET_LITTLE_NAME
5308 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5310 /* The kernel recognizes executables as valid only if they carry a
5311 "FreeBSD" label in the ELF header. So we put this label on all
5312 executables and (for simplicity) also all other object files. */
5315 elf64_alpha_fbsd_post_process_headers (bfd
* abfd
,
5316 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
5318 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
5320 i_ehdrp
= elf_elfheader (abfd
);
5322 /* Put an ABI label supported by FreeBSD >= 4.1. */
5323 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
5324 #ifdef OLD_FREEBSD_ABI_LABEL
5325 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5326 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5330 #undef elf_backend_post_process_headers
5331 #define elf_backend_post_process_headers \
5332 elf64_alpha_fbsd_post_process_headers
5335 #define elf64_bed elf64_alpha_fbsd_bed
5337 #include "elf64-target.h"