1 /* Alpha specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 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. */
188 /* The most recent relax pass that we've seen. The GOTs
189 should be regenerated if this doesn't match. */
193 /* Look up an entry in a Alpha ELF linker hash table. */
195 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \
196 ((struct alpha_elf_link_hash_entry *) \
197 elf_link_hash_lookup (&(table)->root, (string), (create), \
200 /* Traverse a Alpha ELF linker hash table. */
202 #define alpha_elf_link_hash_traverse(table, func, info) \
203 (elf_link_hash_traverse \
205 (bfd_boolean (*) (struct elf_link_hash_entry *, PTR)) (func), \
208 /* Get the Alpha ELF linker hash table from a link_info structure. */
210 #define alpha_elf_hash_table(p) \
211 ((struct alpha_elf_link_hash_table *) ((p)->hash))
213 /* Get the object's symbols as our own entry type. */
215 #define alpha_elf_sym_hashes(abfd) \
216 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd))
218 /* Should we do dynamic things to this symbol? This differs from the
219 generic version in that we never need to consider function pointer
220 equality wrt PLT entries -- we don't create a PLT entry if a symbol's
221 address is ever taken. */
223 static inline bfd_boolean
224 alpha_elf_dynamic_symbol_p (struct elf_link_hash_entry
*h
,
225 struct bfd_link_info
*info
)
227 return _bfd_elf_dynamic_symbol_p (h
, info
, 0);
230 /* Create an entry in a Alpha ELF linker hash table. */
232 static struct bfd_hash_entry
*
233 elf64_alpha_link_hash_newfunc (struct bfd_hash_entry
*entry
,
234 struct bfd_hash_table
*table
,
237 struct alpha_elf_link_hash_entry
*ret
=
238 (struct alpha_elf_link_hash_entry
*) entry
;
240 /* Allocate the structure if it has not already been allocated by a
242 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
243 ret
= ((struct alpha_elf_link_hash_entry
*)
244 bfd_hash_allocate (table
,
245 sizeof (struct alpha_elf_link_hash_entry
)));
246 if (ret
== (struct alpha_elf_link_hash_entry
*) NULL
)
247 return (struct bfd_hash_entry
*) ret
;
249 /* Call the allocation method of the superclass. */
250 ret
= ((struct alpha_elf_link_hash_entry
*)
251 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
253 if (ret
!= (struct alpha_elf_link_hash_entry
*) NULL
)
255 /* Set local fields. */
256 memset (&ret
->esym
, 0, sizeof (EXTR
));
257 /* We use -2 as a marker to indicate that the information has
258 not been set. -1 means there is no associated ifd. */
261 ret
->got_entries
= NULL
;
262 ret
->reloc_entries
= NULL
;
265 return (struct bfd_hash_entry
*) ret
;
268 /* Create a Alpha ELF linker hash table. */
270 static struct bfd_link_hash_table
*
271 elf64_alpha_bfd_link_hash_table_create (bfd
*abfd
)
273 struct alpha_elf_link_hash_table
*ret
;
274 bfd_size_type amt
= sizeof (struct alpha_elf_link_hash_table
);
276 ret
= (struct alpha_elf_link_hash_table
*) bfd_zmalloc (amt
);
277 if (ret
== (struct alpha_elf_link_hash_table
*) NULL
)
280 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
281 elf64_alpha_link_hash_newfunc
,
282 sizeof (struct alpha_elf_link_hash_entry
)))
288 return &ret
->root
.root
;
291 /* We have some private fields hanging off of the elf_tdata structure. */
293 struct alpha_elf_obj_tdata
295 struct elf_obj_tdata root
;
297 /* For every input file, these are the got entries for that object's
299 struct alpha_elf_got_entry
** local_got_entries
;
301 /* For every input file, this is the object that owns the got that
302 this input file uses. */
305 /* For every got, this is a linked list through the objects using this got */
306 bfd
*in_got_link_next
;
308 /* For every got, this is a link to the next got subsegment. */
311 /* For every got, this is the section. */
314 /* For every got, this is it's total number of words. */
317 /* For every got, this is the sum of the number of words required
318 to hold all of the member object's local got. */
322 #define alpha_elf_tdata(abfd) \
323 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any)
326 elf64_alpha_mkobject (bfd
*abfd
)
328 if (abfd
->tdata
.any
== NULL
)
330 bfd_size_type amt
= sizeof (struct alpha_elf_obj_tdata
);
331 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
332 if (abfd
->tdata
.any
== NULL
)
335 return bfd_elf_mkobject (abfd
);
339 elf64_alpha_object_p (bfd
*abfd
)
341 /* Set the right machine number for an Alpha ELF file. */
342 return bfd_default_set_arch_mach (abfd
, bfd_arch_alpha
, 0);
345 /* A relocation function which doesn't do anything. */
347 static bfd_reloc_status_type
348 elf64_alpha_reloc_nil (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc
,
349 asymbol
*sym ATTRIBUTE_UNUSED
,
350 PTR data ATTRIBUTE_UNUSED
, asection
*sec
,
351 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
354 reloc
->address
+= sec
->output_offset
;
358 /* A relocation function used for an unsupported reloc. */
360 static bfd_reloc_status_type
361 elf64_alpha_reloc_bad (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc
,
362 asymbol
*sym ATTRIBUTE_UNUSED
,
363 PTR data ATTRIBUTE_UNUSED
, asection
*sec
,
364 bfd
*output_bfd
, char **error_message ATTRIBUTE_UNUSED
)
367 reloc
->address
+= sec
->output_offset
;
368 return bfd_reloc_notsupported
;
371 /* Do the work of the GPDISP relocation. */
373 static bfd_reloc_status_type
374 elf64_alpha_do_reloc_gpdisp (bfd
*abfd
, bfd_vma gpdisp
, bfd_byte
*p_ldah
,
377 bfd_reloc_status_type ret
= bfd_reloc_ok
;
379 unsigned long i_ldah
, i_lda
;
381 i_ldah
= bfd_get_32 (abfd
, p_ldah
);
382 i_lda
= bfd_get_32 (abfd
, p_lda
);
384 /* Complain if the instructions are not correct. */
385 if (((i_ldah
>> 26) & 0x3f) != 0x09
386 || ((i_lda
>> 26) & 0x3f) != 0x08)
387 ret
= bfd_reloc_dangerous
;
389 /* Extract the user-supplied offset, mirroring the sign extensions
390 that the instructions perform. */
391 addend
= ((i_ldah
& 0xffff) << 16) | (i_lda
& 0xffff);
392 addend
= (addend
^ 0x80008000) - 0x80008000;
396 if ((bfd_signed_vma
) gpdisp
< -(bfd_signed_vma
) 0x80000000
397 || (bfd_signed_vma
) gpdisp
>= (bfd_signed_vma
) 0x7fff8000)
398 ret
= bfd_reloc_overflow
;
400 /* compensate for the sign extension again. */
401 i_ldah
= ((i_ldah
& 0xffff0000)
402 | (((gpdisp
>> 16) + ((gpdisp
>> 15) & 1)) & 0xffff));
403 i_lda
= (i_lda
& 0xffff0000) | (gpdisp
& 0xffff);
405 bfd_put_32 (abfd
, (bfd_vma
) i_ldah
, p_ldah
);
406 bfd_put_32 (abfd
, (bfd_vma
) i_lda
, p_lda
);
411 /* The special function for the GPDISP reloc. */
413 static bfd_reloc_status_type
414 elf64_alpha_reloc_gpdisp (bfd
*abfd
, arelent
*reloc_entry
,
415 asymbol
*sym ATTRIBUTE_UNUSED
, PTR data
,
416 asection
*input_section
, bfd
*output_bfd
,
419 bfd_reloc_status_type ret
;
420 bfd_vma gp
, relocation
;
421 bfd_vma high_address
;
422 bfd_byte
*p_ldah
, *p_lda
;
424 /* Don't do anything if we're not doing a final link. */
427 reloc_entry
->address
+= input_section
->output_offset
;
431 high_address
= bfd_get_section_limit (abfd
, input_section
);
432 if (reloc_entry
->address
> high_address
433 || reloc_entry
->address
+ reloc_entry
->addend
> high_address
)
434 return bfd_reloc_outofrange
;
436 /* The gp used in the portion of the output object to which this
437 input object belongs is cached on the input bfd. */
438 gp
= _bfd_get_gp_value (abfd
);
440 relocation
= (input_section
->output_section
->vma
441 + input_section
->output_offset
442 + reloc_entry
->address
);
444 p_ldah
= (bfd_byte
*) data
+ reloc_entry
->address
;
445 p_lda
= p_ldah
+ reloc_entry
->addend
;
447 ret
= elf64_alpha_do_reloc_gpdisp (abfd
, gp
- relocation
, p_ldah
, p_lda
);
449 /* Complain if the instructions are not correct. */
450 if (ret
== bfd_reloc_dangerous
)
451 *err_msg
= _("GPDISP relocation did not find ldah and lda instructions");
456 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
457 from smaller values. Start with zero, widen, *then* decrement. */
458 #define MINUS_ONE (((bfd_vma)0) - 1)
460 #define SKIP_HOWTO(N) \
461 HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0)
463 static reloc_howto_type elf64_alpha_howto_table
[] =
465 HOWTO (R_ALPHA_NONE
, /* type */
467 0, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_dont
, /* complain_on_overflow */
472 elf64_alpha_reloc_nil
, /* special_function */
474 FALSE
, /* partial_inplace */
477 TRUE
), /* pcrel_offset */
479 /* A 32 bit reference to a symbol. */
480 HOWTO (R_ALPHA_REFLONG
, /* type */
482 2, /* size (0 = byte, 1 = short, 2 = long) */
484 FALSE
, /* pc_relative */
486 complain_overflow_bitfield
, /* complain_on_overflow */
487 0, /* special_function */
488 "REFLONG", /* name */
489 FALSE
, /* partial_inplace */
490 0xffffffff, /* src_mask */
491 0xffffffff, /* dst_mask */
492 FALSE
), /* pcrel_offset */
494 /* A 64 bit reference to a symbol. */
495 HOWTO (R_ALPHA_REFQUAD
, /* type */
497 4, /* size (0 = byte, 1 = short, 2 = long) */
499 FALSE
, /* pc_relative */
501 complain_overflow_bitfield
, /* complain_on_overflow */
502 0, /* special_function */
503 "REFQUAD", /* name */
504 FALSE
, /* partial_inplace */
505 MINUS_ONE
, /* src_mask */
506 MINUS_ONE
, /* dst_mask */
507 FALSE
), /* pcrel_offset */
509 /* A 32 bit GP relative offset. This is just like REFLONG except
510 that when the value is used the value of the gp register will be
512 HOWTO (R_ALPHA_GPREL32
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE
, /* pc_relative */
518 complain_overflow_bitfield
, /* complain_on_overflow */
519 0, /* special_function */
520 "GPREL32", /* name */
521 FALSE
, /* partial_inplace */
522 0xffffffff, /* src_mask */
523 0xffffffff, /* dst_mask */
524 FALSE
), /* pcrel_offset */
526 /* Used for an instruction that refers to memory off the GP register. */
527 HOWTO (R_ALPHA_LITERAL
, /* type */
529 1, /* size (0 = byte, 1 = short, 2 = long) */
531 FALSE
, /* pc_relative */
533 complain_overflow_signed
, /* complain_on_overflow */
534 0, /* special_function */
535 "ELF_LITERAL", /* name */
536 FALSE
, /* partial_inplace */
537 0xffff, /* src_mask */
538 0xffff, /* dst_mask */
539 FALSE
), /* pcrel_offset */
541 /* This reloc only appears immediately following an ELF_LITERAL reloc.
542 It identifies a use of the literal. The symbol index is special:
543 1 means the literal address is in the base register of a memory
544 format instruction; 2 means the literal address is in the byte
545 offset register of a byte-manipulation instruction; 3 means the
546 literal address is in the target register of a jsr instruction.
547 This does not actually do any relocation. */
548 HOWTO (R_ALPHA_LITUSE
, /* type */
550 1, /* size (0 = byte, 1 = short, 2 = long) */
552 FALSE
, /* pc_relative */
554 complain_overflow_dont
, /* complain_on_overflow */
555 elf64_alpha_reloc_nil
, /* special_function */
557 FALSE
, /* partial_inplace */
560 FALSE
), /* pcrel_offset */
562 /* Load the gp register. This is always used for a ldah instruction
563 which loads the upper 16 bits of the gp register. The symbol
564 index of the GPDISP instruction is an offset in bytes to the lda
565 instruction that loads the lower 16 bits. The value to use for
566 the relocation is the difference between the GP value and the
567 current location; the load will always be done against a register
568 holding the current address.
570 NOTE: Unlike ECOFF, partial in-place relocation is not done. If
571 any offset is present in the instructions, it is an offset from
572 the register to the ldah instruction. This lets us avoid any
573 stupid hackery like inventing a gp value to do partial relocation
574 against. Also unlike ECOFF, we do the whole relocation off of
575 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd,
576 space consuming bit, that, since all the information was present
577 in the GPDISP_HI16 reloc. */
578 HOWTO (R_ALPHA_GPDISP
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE
, /* pc_relative */
584 complain_overflow_dont
, /* complain_on_overflow */
585 elf64_alpha_reloc_gpdisp
, /* special_function */
587 FALSE
, /* partial_inplace */
588 0xffff, /* src_mask */
589 0xffff, /* dst_mask */
590 TRUE
), /* pcrel_offset */
592 /* A 21 bit branch. */
593 HOWTO (R_ALPHA_BRADDR
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 TRUE
, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 0, /* special_function */
602 FALSE
, /* partial_inplace */
603 0x1fffff, /* src_mask */
604 0x1fffff, /* dst_mask */
605 TRUE
), /* pcrel_offset */
607 /* A hint for a jump to a register. */
608 HOWTO (R_ALPHA_HINT
, /* type */
610 1, /* size (0 = byte, 1 = short, 2 = long) */
612 TRUE
, /* pc_relative */
614 complain_overflow_dont
, /* complain_on_overflow */
615 0, /* special_function */
617 FALSE
, /* partial_inplace */
618 0x3fff, /* src_mask */
619 0x3fff, /* dst_mask */
620 TRUE
), /* pcrel_offset */
622 /* 16 bit PC relative offset. */
623 HOWTO (R_ALPHA_SREL16
, /* type */
625 1, /* size (0 = byte, 1 = short, 2 = long) */
627 TRUE
, /* pc_relative */
629 complain_overflow_signed
, /* complain_on_overflow */
630 0, /* special_function */
632 FALSE
, /* partial_inplace */
633 0xffff, /* src_mask */
634 0xffff, /* dst_mask */
635 TRUE
), /* pcrel_offset */
637 /* 32 bit PC relative offset. */
638 HOWTO (R_ALPHA_SREL32
, /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 TRUE
, /* pc_relative */
644 complain_overflow_signed
, /* complain_on_overflow */
645 0, /* special_function */
647 FALSE
, /* partial_inplace */
648 0xffffffff, /* src_mask */
649 0xffffffff, /* dst_mask */
650 TRUE
), /* pcrel_offset */
652 /* A 64 bit PC relative offset. */
653 HOWTO (R_ALPHA_SREL64
, /* type */
655 4, /* size (0 = byte, 1 = short, 2 = long) */
657 TRUE
, /* pc_relative */
659 complain_overflow_signed
, /* complain_on_overflow */
660 0, /* special_function */
662 FALSE
, /* partial_inplace */
663 MINUS_ONE
, /* src_mask */
664 MINUS_ONE
, /* dst_mask */
665 TRUE
), /* pcrel_offset */
667 /* Skip 12 - 16; deprecated ECOFF relocs. */
674 /* The high 16 bits of the displacement from GP to the target. */
675 HOWTO (R_ALPHA_GPRELHIGH
,
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_signed
, /* complain_on_overflow */
682 0, /* special_function */
683 "GPRELHIGH", /* name */
684 FALSE
, /* partial_inplace */
685 0xffff, /* src_mask */
686 0xffff, /* dst_mask */
687 FALSE
), /* pcrel_offset */
689 /* The low 16 bits of the displacement from GP to the target. */
690 HOWTO (R_ALPHA_GPRELLOW
,
692 1, /* size (0 = byte, 1 = short, 2 = long) */
694 FALSE
, /* pc_relative */
696 complain_overflow_dont
, /* complain_on_overflow */
697 0, /* special_function */
698 "GPRELLOW", /* name */
699 FALSE
, /* partial_inplace */
700 0xffff, /* src_mask */
701 0xffff, /* dst_mask */
702 FALSE
), /* pcrel_offset */
704 /* A 16-bit displacement from the GP to the target. */
705 HOWTO (R_ALPHA_GPREL16
,
707 1, /* size (0 = byte, 1 = short, 2 = long) */
709 FALSE
, /* pc_relative */
711 complain_overflow_signed
, /* complain_on_overflow */
712 0, /* special_function */
713 "GPREL16", /* name */
714 FALSE
, /* partial_inplace */
715 0xffff, /* src_mask */
716 0xffff, /* dst_mask */
717 FALSE
), /* pcrel_offset */
719 /* Skip 20 - 23; deprecated ECOFF relocs. */
725 /* Misc ELF relocations. */
727 /* A dynamic relocation to copy the target into our .dynbss section. */
728 /* Not generated, as all Alpha objects use PIC, so it is not needed. It
729 is present because every other ELF has one, but should not be used
730 because .dynbss is an ugly thing. */
737 complain_overflow_dont
,
738 bfd_elf_generic_reloc
,
745 /* A dynamic relocation for a .got entry. */
746 HOWTO (R_ALPHA_GLOB_DAT
,
752 complain_overflow_dont
,
753 bfd_elf_generic_reloc
,
760 /* A dynamic relocation for a .plt entry. */
761 HOWTO (R_ALPHA_JMP_SLOT
,
767 complain_overflow_dont
,
768 bfd_elf_generic_reloc
,
775 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */
776 HOWTO (R_ALPHA_RELATIVE
,
782 complain_overflow_dont
,
783 bfd_elf_generic_reloc
,
790 /* A 21 bit branch that adjusts for gp loads. */
791 HOWTO (R_ALPHA_BRSGP
, /* type */
793 2, /* size (0 = byte, 1 = short, 2 = long) */
795 TRUE
, /* pc_relative */
797 complain_overflow_signed
, /* complain_on_overflow */
798 0, /* special_function */
800 FALSE
, /* partial_inplace */
801 0x1fffff, /* src_mask */
802 0x1fffff, /* dst_mask */
803 TRUE
), /* pcrel_offset */
805 /* Creates a tls_index for the symbol in the got. */
806 HOWTO (R_ALPHA_TLSGD
, /* type */
808 1, /* size (0 = byte, 1 = short, 2 = long) */
810 FALSE
, /* pc_relative */
812 complain_overflow_signed
, /* complain_on_overflow */
813 0, /* special_function */
815 FALSE
, /* partial_inplace */
816 0xffff, /* src_mask */
817 0xffff, /* dst_mask */
818 FALSE
), /* pcrel_offset */
820 /* Creates a tls_index for the (current) module in the got. */
821 HOWTO (R_ALPHA_TLSLDM
, /* type */
823 1, /* size (0 = byte, 1 = short, 2 = long) */
825 FALSE
, /* pc_relative */
827 complain_overflow_signed
, /* complain_on_overflow */
828 0, /* special_function */
830 FALSE
, /* partial_inplace */
831 0xffff, /* src_mask */
832 0xffff, /* dst_mask */
833 FALSE
), /* pcrel_offset */
835 /* A dynamic relocation for a DTP module entry. */
836 HOWTO (R_ALPHA_DTPMOD64
, /* type */
838 4, /* size (0 = byte, 1 = short, 2 = long) */
840 FALSE
, /* pc_relative */
842 complain_overflow_bitfield
, /* complain_on_overflow */
843 0, /* special_function */
844 "DTPMOD64", /* name */
845 FALSE
, /* partial_inplace */
846 MINUS_ONE
, /* src_mask */
847 MINUS_ONE
, /* dst_mask */
848 FALSE
), /* pcrel_offset */
850 /* Creates a 64-bit offset in the got for the displacement
851 from DTP to the target. */
852 HOWTO (R_ALPHA_GOTDTPREL
, /* type */
854 1, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE
, /* pc_relative */
858 complain_overflow_signed
, /* complain_on_overflow */
859 0, /* special_function */
860 "GOTDTPREL", /* name */
861 FALSE
, /* partial_inplace */
862 0xffff, /* src_mask */
863 0xffff, /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 /* A dynamic relocation for a displacement from DTP to the target. */
867 HOWTO (R_ALPHA_DTPREL64
, /* type */
869 4, /* size (0 = byte, 1 = short, 2 = long) */
871 FALSE
, /* pc_relative */
873 complain_overflow_bitfield
, /* complain_on_overflow */
874 0, /* special_function */
875 "DTPREL64", /* name */
876 FALSE
, /* partial_inplace */
877 MINUS_ONE
, /* src_mask */
878 MINUS_ONE
, /* dst_mask */
879 FALSE
), /* pcrel_offset */
881 /* The high 16 bits of the displacement from DTP to the target. */
882 HOWTO (R_ALPHA_DTPRELHI
, /* type */
884 1, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE
, /* pc_relative */
888 complain_overflow_signed
, /* complain_on_overflow */
889 0, /* special_function */
890 "DTPRELHI", /* name */
891 FALSE
, /* partial_inplace */
892 0xffff, /* src_mask */
893 0xffff, /* dst_mask */
894 FALSE
), /* pcrel_offset */
896 /* The low 16 bits of the displacement from DTP to the target. */
897 HOWTO (R_ALPHA_DTPRELLO
, /* type */
899 1, /* size (0 = byte, 1 = short, 2 = long) */
901 FALSE
, /* pc_relative */
903 complain_overflow_dont
, /* complain_on_overflow */
904 0, /* special_function */
905 "DTPRELLO", /* name */
906 FALSE
, /* partial_inplace */
907 0xffff, /* src_mask */
908 0xffff, /* dst_mask */
909 FALSE
), /* pcrel_offset */
911 /* A 16-bit displacement from DTP to the target. */
912 HOWTO (R_ALPHA_DTPREL16
, /* type */
914 1, /* size (0 = byte, 1 = short, 2 = long) */
916 FALSE
, /* pc_relative */
918 complain_overflow_signed
, /* complain_on_overflow */
919 0, /* special_function */
920 "DTPREL16", /* name */
921 FALSE
, /* partial_inplace */
922 0xffff, /* src_mask */
923 0xffff, /* dst_mask */
924 FALSE
), /* pcrel_offset */
926 /* Creates a 64-bit offset in the got for the displacement
927 from TP to the target. */
928 HOWTO (R_ALPHA_GOTTPREL
, /* type */
930 1, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE
, /* pc_relative */
934 complain_overflow_signed
, /* complain_on_overflow */
935 0, /* special_function */
936 "GOTTPREL", /* name */
937 FALSE
, /* partial_inplace */
938 0xffff, /* src_mask */
939 0xffff, /* dst_mask */
940 FALSE
), /* pcrel_offset */
942 /* A dynamic relocation for a displacement from TP to the target. */
943 HOWTO (R_ALPHA_TPREL64
, /* type */
945 4, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE
, /* pc_relative */
949 complain_overflow_bitfield
, /* complain_on_overflow */
950 0, /* special_function */
951 "TPREL64", /* name */
952 FALSE
, /* partial_inplace */
953 MINUS_ONE
, /* src_mask */
954 MINUS_ONE
, /* dst_mask */
955 FALSE
), /* pcrel_offset */
957 /* The high 16 bits of the displacement from TP to the target. */
958 HOWTO (R_ALPHA_TPRELHI
, /* type */
960 1, /* size (0 = byte, 1 = short, 2 = long) */
962 FALSE
, /* pc_relative */
964 complain_overflow_signed
, /* complain_on_overflow */
965 0, /* special_function */
966 "TPRELHI", /* name */
967 FALSE
, /* partial_inplace */
968 0xffff, /* src_mask */
969 0xffff, /* dst_mask */
970 FALSE
), /* pcrel_offset */
972 /* The low 16 bits of the displacement from TP to the target. */
973 HOWTO (R_ALPHA_TPRELLO
, /* type */
975 1, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE
, /* pc_relative */
979 complain_overflow_dont
, /* complain_on_overflow */
980 0, /* special_function */
981 "TPRELLO", /* name */
982 FALSE
, /* partial_inplace */
983 0xffff, /* src_mask */
984 0xffff, /* dst_mask */
985 FALSE
), /* pcrel_offset */
987 /* A 16-bit displacement from TP to the target. */
988 HOWTO (R_ALPHA_TPREL16
, /* type */
990 1, /* size (0 = byte, 1 = short, 2 = long) */
992 FALSE
, /* pc_relative */
994 complain_overflow_signed
, /* complain_on_overflow */
995 0, /* special_function */
996 "TPREL16", /* name */
997 FALSE
, /* partial_inplace */
998 0xffff, /* src_mask */
999 0xffff, /* dst_mask */
1000 FALSE
), /* pcrel_offset */
1003 /* A mapping from BFD reloc types to Alpha ELF reloc types. */
1005 struct elf_reloc_map
1007 bfd_reloc_code_real_type bfd_reloc_val
;
1011 static const struct elf_reloc_map elf64_alpha_reloc_map
[] =
1013 {BFD_RELOC_NONE
, R_ALPHA_NONE
},
1014 {BFD_RELOC_32
, R_ALPHA_REFLONG
},
1015 {BFD_RELOC_64
, R_ALPHA_REFQUAD
},
1016 {BFD_RELOC_CTOR
, R_ALPHA_REFQUAD
},
1017 {BFD_RELOC_GPREL32
, R_ALPHA_GPREL32
},
1018 {BFD_RELOC_ALPHA_ELF_LITERAL
, R_ALPHA_LITERAL
},
1019 {BFD_RELOC_ALPHA_LITUSE
, R_ALPHA_LITUSE
},
1020 {BFD_RELOC_ALPHA_GPDISP
, R_ALPHA_GPDISP
},
1021 {BFD_RELOC_23_PCREL_S2
, R_ALPHA_BRADDR
},
1022 {BFD_RELOC_ALPHA_HINT
, R_ALPHA_HINT
},
1023 {BFD_RELOC_16_PCREL
, R_ALPHA_SREL16
},
1024 {BFD_RELOC_32_PCREL
, R_ALPHA_SREL32
},
1025 {BFD_RELOC_64_PCREL
, R_ALPHA_SREL64
},
1026 {BFD_RELOC_ALPHA_GPREL_HI16
, R_ALPHA_GPRELHIGH
},
1027 {BFD_RELOC_ALPHA_GPREL_LO16
, R_ALPHA_GPRELLOW
},
1028 {BFD_RELOC_GPREL16
, R_ALPHA_GPREL16
},
1029 {BFD_RELOC_ALPHA_BRSGP
, R_ALPHA_BRSGP
},
1030 {BFD_RELOC_ALPHA_TLSGD
, R_ALPHA_TLSGD
},
1031 {BFD_RELOC_ALPHA_TLSLDM
, R_ALPHA_TLSLDM
},
1032 {BFD_RELOC_ALPHA_DTPMOD64
, R_ALPHA_DTPMOD64
},
1033 {BFD_RELOC_ALPHA_GOTDTPREL16
, R_ALPHA_GOTDTPREL
},
1034 {BFD_RELOC_ALPHA_DTPREL64
, R_ALPHA_DTPREL64
},
1035 {BFD_RELOC_ALPHA_DTPREL_HI16
, R_ALPHA_DTPRELHI
},
1036 {BFD_RELOC_ALPHA_DTPREL_LO16
, R_ALPHA_DTPRELLO
},
1037 {BFD_RELOC_ALPHA_DTPREL16
, R_ALPHA_DTPREL16
},
1038 {BFD_RELOC_ALPHA_GOTTPREL16
, R_ALPHA_GOTTPREL
},
1039 {BFD_RELOC_ALPHA_TPREL64
, R_ALPHA_TPREL64
},
1040 {BFD_RELOC_ALPHA_TPREL_HI16
, R_ALPHA_TPRELHI
},
1041 {BFD_RELOC_ALPHA_TPREL_LO16
, R_ALPHA_TPRELLO
},
1042 {BFD_RELOC_ALPHA_TPREL16
, R_ALPHA_TPREL16
},
1045 /* Given a BFD reloc type, return a HOWTO structure. */
1047 static reloc_howto_type
*
1048 elf64_alpha_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1049 bfd_reloc_code_real_type code
)
1051 const struct elf_reloc_map
*i
, *e
;
1052 i
= e
= elf64_alpha_reloc_map
;
1053 e
+= sizeof (elf64_alpha_reloc_map
) / sizeof (struct elf_reloc_map
);
1056 if (i
->bfd_reloc_val
== code
)
1057 return &elf64_alpha_howto_table
[i
->elf_reloc_val
];
1062 static reloc_howto_type
*
1063 elf64_alpha_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1069 i
< (sizeof (elf64_alpha_howto_table
)
1070 / sizeof (elf64_alpha_howto_table
[0]));
1072 if (elf64_alpha_howto_table
[i
].name
!= NULL
1073 && strcasecmp (elf64_alpha_howto_table
[i
].name
, r_name
) == 0)
1074 return &elf64_alpha_howto_table
[i
];
1079 /* Given an Alpha ELF reloc type, fill in an arelent structure. */
1082 elf64_alpha_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
1083 Elf_Internal_Rela
*dst
)
1085 unsigned r_type
= ELF64_R_TYPE(dst
->r_info
);
1086 BFD_ASSERT (r_type
< (unsigned int) R_ALPHA_max
);
1087 cache_ptr
->howto
= &elf64_alpha_howto_table
[r_type
];
1090 /* These two relocations create a two-word entry in the got. */
1091 #define alpha_got_entry_size(r_type) \
1092 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8)
1094 /* This is PT_TLS segment p_vaddr. */
1095 #define alpha_get_dtprel_base(info) \
1096 (elf_hash_table (info)->tls_sec->vma)
1098 /* Main program TLS (whose template starts at PT_TLS p_vaddr)
1099 is assigned offset round(16, PT_TLS p_align). */
1100 #define alpha_get_tprel_base(info) \
1101 (elf_hash_table (info)->tls_sec->vma \
1102 - align_power ((bfd_vma) 16, \
1103 elf_hash_table (info)->tls_sec->alignment_power))
1105 /* Handle an Alpha specific section when reading an object file. This
1106 is called when bfd_section_from_shdr finds a section with an unknown
1108 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure
1112 elf64_alpha_section_from_shdr (bfd
*abfd
,
1113 Elf_Internal_Shdr
*hdr
,
1119 /* There ought to be a place to keep ELF backend specific flags, but
1120 at the moment there isn't one. We just keep track of the
1121 sections by their name, instead. Fortunately, the ABI gives
1122 suggested names for all the MIPS specific sections, so we will
1123 probably get away with this. */
1124 switch (hdr
->sh_type
)
1126 case SHT_ALPHA_DEBUG
:
1127 if (strcmp (name
, ".mdebug") != 0)
1134 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1136 newsect
= hdr
->bfd_section
;
1138 if (hdr
->sh_type
== SHT_ALPHA_DEBUG
)
1140 if (! bfd_set_section_flags (abfd
, newsect
,
1141 (bfd_get_section_flags (abfd
, newsect
)
1149 /* Convert Alpha specific section flags to bfd internal section flags. */
1152 elf64_alpha_section_flags (flagword
*flags
, const Elf_Internal_Shdr
*hdr
)
1154 if (hdr
->sh_flags
& SHF_ALPHA_GPREL
)
1155 *flags
|= SEC_SMALL_DATA
;
1160 /* Set the correct type for an Alpha ELF section. We do this by the
1161 section name, which is a hack, but ought to work. */
1164 elf64_alpha_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
1166 register const char *name
;
1168 name
= bfd_get_section_name (abfd
, sec
);
1170 if (strcmp (name
, ".mdebug") == 0)
1172 hdr
->sh_type
= SHT_ALPHA_DEBUG
;
1173 /* In a shared object on Irix 5.3, the .mdebug section has an
1174 entsize of 0. FIXME: Does this matter? */
1175 if ((abfd
->flags
& DYNAMIC
) != 0 )
1176 hdr
->sh_entsize
= 0;
1178 hdr
->sh_entsize
= 1;
1180 else if ((sec
->flags
& SEC_SMALL_DATA
)
1181 || strcmp (name
, ".sdata") == 0
1182 || strcmp (name
, ".sbss") == 0
1183 || strcmp (name
, ".lit4") == 0
1184 || strcmp (name
, ".lit8") == 0)
1185 hdr
->sh_flags
|= SHF_ALPHA_GPREL
;
1190 /* Hook called by the linker routine which adds symbols from an object
1191 file. We use it to put .comm items in .sbss, and not .bss. */
1194 elf64_alpha_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
1195 Elf_Internal_Sym
*sym
,
1196 const char **namep ATTRIBUTE_UNUSED
,
1197 flagword
*flagsp ATTRIBUTE_UNUSED
,
1198 asection
**secp
, bfd_vma
*valp
)
1200 if (sym
->st_shndx
== SHN_COMMON
1201 && !info
->relocatable
1202 && sym
->st_size
<= elf_gp_size (abfd
))
1204 /* Common symbols less than or equal to -G nn bytes are
1205 automatically put into .sbss. */
1207 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
1211 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
1214 | SEC_LINKER_CREATED
));
1220 *valp
= sym
->st_size
;
1226 /* Create the .got section. */
1229 elf64_alpha_create_got_section (bfd
*abfd
,
1230 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1235 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1236 | SEC_LINKER_CREATED
);
1237 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
1239 || !bfd_set_section_alignment (abfd
, s
, 3))
1242 alpha_elf_tdata (abfd
)->got
= s
;
1244 /* Make sure the object's gotobj is set to itself so that we default
1245 to every object with its own .got. We'll merge .gots later once
1246 we've collected each object's info. */
1247 alpha_elf_tdata (abfd
)->gotobj
= abfd
;
1252 /* Create all the dynamic sections. */
1255 elf64_alpha_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
1259 struct elf_link_hash_entry
*h
;
1261 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */
1263 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1264 | SEC_LINKER_CREATED
1265 | (elf64_alpha_use_secureplt
? SEC_READONLY
: 0));
1266 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", flags
);
1267 if (s
== NULL
|| ! bfd_set_section_alignment (abfd
, s
, 4))
1270 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1272 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
1273 "_PROCEDURE_LINKAGE_TABLE_");
1274 elf_hash_table (info
)->hplt
= h
;
1278 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1279 | SEC_LINKER_CREATED
| SEC_READONLY
);
1280 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.plt", flags
);
1281 if (s
== NULL
|| ! bfd_set_section_alignment (abfd
, s
, 3))
1284 if (elf64_alpha_use_secureplt
)
1286 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
1287 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
1288 if (s
== NULL
|| ! bfd_set_section_alignment (abfd
, s
, 3))
1292 /* We may or may not have created a .got section for this object, but
1293 we definitely havn't done the rest of the work. */
1295 if (alpha_elf_tdata(abfd
)->gotobj
== NULL
)
1297 if (!elf64_alpha_create_got_section (abfd
, info
))
1301 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1302 | SEC_LINKER_CREATED
| SEC_READONLY
);
1303 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got", flags
);
1305 || !bfd_set_section_alignment (abfd
, s
, 3))
1308 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
1309 dynobj's .got section. We don't do this in the linker script
1310 because we don't want to define the symbol if we are not creating
1311 a global offset table. */
1312 h
= _bfd_elf_define_linkage_sym (abfd
, info
, alpha_elf_tdata(abfd
)->got
,
1313 "_GLOBAL_OFFSET_TABLE_");
1314 elf_hash_table (info
)->hgot
= h
;
1321 /* Read ECOFF debugging information from a .mdebug section into a
1322 ecoff_debug_info structure. */
1325 elf64_alpha_read_ecoff_info (bfd
*abfd
, asection
*section
,
1326 struct ecoff_debug_info
*debug
)
1329 const struct ecoff_debug_swap
*swap
;
1330 char *ext_hdr
= NULL
;
1332 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1333 memset (debug
, 0, sizeof (*debug
));
1335 ext_hdr
= (char *) bfd_malloc (swap
->external_hdr_size
);
1336 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1339 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, (file_ptr
) 0,
1340 swap
->external_hdr_size
))
1343 symhdr
= &debug
->symbolic_header
;
1344 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1346 /* The symbolic header contains absolute file offsets and sizes to
1348 #define READ(ptr, offset, count, size, type) \
1349 if (symhdr->count == 0) \
1350 debug->ptr = NULL; \
1353 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1354 debug->ptr = (type) bfd_malloc (amt); \
1355 if (debug->ptr == NULL) \
1356 goto error_return; \
1357 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1358 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1359 goto error_return; \
1362 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1363 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, PTR
);
1364 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, PTR
);
1365 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, PTR
);
1366 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, PTR
);
1367 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1369 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1370 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1371 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, PTR
);
1372 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, PTR
);
1373 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, PTR
);
1381 if (ext_hdr
!= NULL
)
1383 if (debug
->line
!= NULL
)
1385 if (debug
->external_dnr
!= NULL
)
1386 free (debug
->external_dnr
);
1387 if (debug
->external_pdr
!= NULL
)
1388 free (debug
->external_pdr
);
1389 if (debug
->external_sym
!= NULL
)
1390 free (debug
->external_sym
);
1391 if (debug
->external_opt
!= NULL
)
1392 free (debug
->external_opt
);
1393 if (debug
->external_aux
!= NULL
)
1394 free (debug
->external_aux
);
1395 if (debug
->ss
!= NULL
)
1397 if (debug
->ssext
!= NULL
)
1398 free (debug
->ssext
);
1399 if (debug
->external_fdr
!= NULL
)
1400 free (debug
->external_fdr
);
1401 if (debug
->external_rfd
!= NULL
)
1402 free (debug
->external_rfd
);
1403 if (debug
->external_ext
!= NULL
)
1404 free (debug
->external_ext
);
1408 /* Alpha ELF local labels start with '$'. */
1411 elf64_alpha_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
, const char *name
)
1413 return name
[0] == '$';
1416 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line
1417 routine in order to handle the ECOFF debugging information. We
1418 still call this mips_elf_find_line because of the slot
1419 find_line_info in elf_obj_tdata is declared that way. */
1421 struct mips_elf_find_line
1423 struct ecoff_debug_info d
;
1424 struct ecoff_find_line i
;
1428 elf64_alpha_find_nearest_line (bfd
*abfd
, asection
*section
, asymbol
**symbols
,
1429 bfd_vma offset
, const char **filename_ptr
,
1430 const char **functionname_ptr
,
1431 unsigned int *line_ptr
)
1435 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
1436 filename_ptr
, functionname_ptr
,
1438 &elf_tdata (abfd
)->dwarf2_find_line_info
))
1441 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
1445 struct mips_elf_find_line
*fi
;
1446 const struct ecoff_debug_swap
* const swap
=
1447 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1449 /* If we are called during a link, alpha_elf_final_link may have
1450 cleared the SEC_HAS_CONTENTS field. We force it back on here
1451 if appropriate (which it normally will be). */
1452 origflags
= msec
->flags
;
1453 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
1454 msec
->flags
|= SEC_HAS_CONTENTS
;
1456 fi
= elf_tdata (abfd
)->find_line_info
;
1459 bfd_size_type external_fdr_size
;
1462 struct fdr
*fdr_ptr
;
1463 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
1465 fi
= (struct mips_elf_find_line
*) bfd_zalloc (abfd
, amt
);
1468 msec
->flags
= origflags
;
1472 if (!elf64_alpha_read_ecoff_info (abfd
, msec
, &fi
->d
))
1474 msec
->flags
= origflags
;
1478 /* Swap in the FDR information. */
1479 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
1480 fi
->d
.fdr
= (struct fdr
*) bfd_alloc (abfd
, amt
);
1481 if (fi
->d
.fdr
== NULL
)
1483 msec
->flags
= origflags
;
1486 external_fdr_size
= swap
->external_fdr_size
;
1487 fdr_ptr
= fi
->d
.fdr
;
1488 fraw_src
= (char *) fi
->d
.external_fdr
;
1489 fraw_end
= (fraw_src
1490 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
1491 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
1492 (*swap
->swap_fdr_in
) (abfd
, (PTR
) fraw_src
, fdr_ptr
);
1494 elf_tdata (abfd
)->find_line_info
= fi
;
1496 /* Note that we don't bother to ever free this information.
1497 find_nearest_line is either called all the time, as in
1498 objdump -l, so the information should be saved, or it is
1499 rarely called, as in ld error messages, so the memory
1500 wasted is unimportant. Still, it would probably be a
1501 good idea for free_cached_info to throw it away. */
1504 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
1505 &fi
->i
, filename_ptr
, functionname_ptr
,
1508 msec
->flags
= origflags
;
1512 msec
->flags
= origflags
;
1515 /* Fall back on the generic ELF find_nearest_line routine. */
1517 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
1518 filename_ptr
, functionname_ptr
,
1522 /* Structure used to pass information to alpha_elf_output_extsym. */
1527 struct bfd_link_info
*info
;
1528 struct ecoff_debug_info
*debug
;
1529 const struct ecoff_debug_swap
*swap
;
1534 elf64_alpha_output_extsym (struct alpha_elf_link_hash_entry
*h
, PTR data
)
1536 struct extsym_info
*einfo
= (struct extsym_info
*) data
;
1538 asection
*sec
, *output_section
;
1540 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1541 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1543 if (h
->root
.indx
== -2)
1545 else if ((h
->root
.def_dynamic
1546 || h
->root
.ref_dynamic
1547 || h
->root
.root
.type
== bfd_link_hash_new
)
1548 && !h
->root
.def_regular
1549 && !h
->root
.ref_regular
)
1551 else if (einfo
->info
->strip
== strip_all
1552 || (einfo
->info
->strip
== strip_some
1553 && bfd_hash_lookup (einfo
->info
->keep_hash
,
1554 h
->root
.root
.root
.string
,
1555 FALSE
, FALSE
) == NULL
))
1563 if (h
->esym
.ifd
== -2)
1566 h
->esym
.cobol_main
= 0;
1567 h
->esym
.weakext
= 0;
1568 h
->esym
.reserved
= 0;
1569 h
->esym
.ifd
= ifdNil
;
1570 h
->esym
.asym
.value
= 0;
1571 h
->esym
.asym
.st
= stGlobal
;
1573 if (h
->root
.root
.type
!= bfd_link_hash_defined
1574 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
1575 h
->esym
.asym
.sc
= scAbs
;
1580 sec
= h
->root
.root
.u
.def
.section
;
1581 output_section
= sec
->output_section
;
1583 /* When making a shared library and symbol h is the one from
1584 the another shared library, OUTPUT_SECTION may be null. */
1585 if (output_section
== NULL
)
1586 h
->esym
.asym
.sc
= scUndefined
;
1589 name
= bfd_section_name (output_section
->owner
, output_section
);
1591 if (strcmp (name
, ".text") == 0)
1592 h
->esym
.asym
.sc
= scText
;
1593 else if (strcmp (name
, ".data") == 0)
1594 h
->esym
.asym
.sc
= scData
;
1595 else if (strcmp (name
, ".sdata") == 0)
1596 h
->esym
.asym
.sc
= scSData
;
1597 else if (strcmp (name
, ".rodata") == 0
1598 || strcmp (name
, ".rdata") == 0)
1599 h
->esym
.asym
.sc
= scRData
;
1600 else if (strcmp (name
, ".bss") == 0)
1601 h
->esym
.asym
.sc
= scBss
;
1602 else if (strcmp (name
, ".sbss") == 0)
1603 h
->esym
.asym
.sc
= scSBss
;
1604 else if (strcmp (name
, ".init") == 0)
1605 h
->esym
.asym
.sc
= scInit
;
1606 else if (strcmp (name
, ".fini") == 0)
1607 h
->esym
.asym
.sc
= scFini
;
1609 h
->esym
.asym
.sc
= scAbs
;
1613 h
->esym
.asym
.reserved
= 0;
1614 h
->esym
.asym
.index
= indexNil
;
1617 if (h
->root
.root
.type
== bfd_link_hash_common
)
1618 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
1619 else if (h
->root
.root
.type
== bfd_link_hash_defined
1620 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1622 if (h
->esym
.asym
.sc
== scCommon
)
1623 h
->esym
.asym
.sc
= scBss
;
1624 else if (h
->esym
.asym
.sc
== scSCommon
)
1625 h
->esym
.asym
.sc
= scSBss
;
1627 sec
= h
->root
.root
.u
.def
.section
;
1628 output_section
= sec
->output_section
;
1629 if (output_section
!= NULL
)
1630 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
1631 + sec
->output_offset
1632 + output_section
->vma
);
1634 h
->esym
.asym
.value
= 0;
1637 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
1638 h
->root
.root
.root
.string
,
1641 einfo
->failed
= TRUE
;
1648 /* Search for and possibly create a got entry. */
1650 static struct alpha_elf_got_entry
*
1651 get_got_entry (bfd
*abfd
, struct alpha_elf_link_hash_entry
*h
,
1652 unsigned long r_type
, unsigned long r_symndx
,
1655 struct alpha_elf_got_entry
*gotent
;
1656 struct alpha_elf_got_entry
**slot
;
1659 slot
= &h
->got_entries
;
1662 /* This is a local .got entry -- record for merge. */
1664 struct alpha_elf_got_entry
**local_got_entries
;
1666 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
1667 if (!local_got_entries
)
1670 Elf_Internal_Shdr
*symtab_hdr
;
1672 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
1673 size
= symtab_hdr
->sh_info
;
1674 size
*= sizeof (struct alpha_elf_got_entry
*);
1677 = (struct alpha_elf_got_entry
**) bfd_zalloc (abfd
, size
);
1678 if (!local_got_entries
)
1681 alpha_elf_tdata (abfd
)->local_got_entries
= local_got_entries
;
1684 slot
= &local_got_entries
[r_symndx
];
1687 for (gotent
= *slot
; gotent
; gotent
= gotent
->next
)
1688 if (gotent
->gotobj
== abfd
1689 && gotent
->reloc_type
== r_type
1690 && gotent
->addend
== r_addend
)
1698 amt
= sizeof (struct alpha_elf_got_entry
);
1699 gotent
= (struct alpha_elf_got_entry
*) bfd_alloc (abfd
, amt
);
1703 gotent
->gotobj
= abfd
;
1704 gotent
->addend
= r_addend
;
1705 gotent
->got_offset
= -1;
1706 gotent
->plt_offset
= -1;
1707 gotent
->use_count
= 1;
1708 gotent
->reloc_type
= r_type
;
1709 gotent
->reloc_done
= 0;
1710 gotent
->reloc_xlated
= 0;
1712 gotent
->next
= *slot
;
1715 entry_size
= alpha_got_entry_size (r_type
);
1716 alpha_elf_tdata (abfd
)->total_got_size
+= entry_size
;
1718 alpha_elf_tdata(abfd
)->local_got_size
+= entry_size
;
1721 gotent
->use_count
+= 1;
1727 elf64_alpha_want_plt (struct alpha_elf_link_hash_entry
*ah
)
1729 return ((ah
->root
.type
== STT_FUNC
1730 || ah
->root
.root
.type
== bfd_link_hash_undefweak
1731 || ah
->root
.root
.type
== bfd_link_hash_undefined
)
1732 && (ah
->flags
& ALPHA_ELF_LINK_HASH_LU_PLT
) != 0
1733 && (ah
->flags
& ~ALPHA_ELF_LINK_HASH_LU_PLT
) == 0);
1736 /* Handle dynamic relocations when doing an Alpha ELF link. */
1739 elf64_alpha_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1740 asection
*sec
, const Elf_Internal_Rela
*relocs
)
1744 const char *rel_sec_name
;
1745 Elf_Internal_Shdr
*symtab_hdr
;
1746 struct alpha_elf_link_hash_entry
**sym_hashes
;
1747 const Elf_Internal_Rela
*rel
, *relend
;
1750 if (info
->relocatable
)
1753 /* Don't do anything special with non-loaded, non-alloced sections.
1754 In particular, any relocs in such sections should not affect GOT
1755 and PLT reference counting (ie. we don't allow them to create GOT
1756 or PLT entries), there's no possibility or desire to optimize TLS
1757 relocs, and there's not much point in propagating relocs to shared
1758 libs that the dynamic linker won't relocate. */
1759 if ((sec
->flags
& SEC_ALLOC
) == 0)
1762 dynobj
= elf_hash_table(info
)->dynobj
;
1764 elf_hash_table(info
)->dynobj
= dynobj
= abfd
;
1767 rel_sec_name
= NULL
;
1768 symtab_hdr
= &elf_tdata(abfd
)->symtab_hdr
;
1769 sym_hashes
= alpha_elf_sym_hashes(abfd
);
1771 relend
= relocs
+ sec
->reloc_count
;
1772 for (rel
= relocs
; rel
< relend
; ++rel
)
1780 unsigned long r_symndx
, r_type
;
1781 struct alpha_elf_link_hash_entry
*h
;
1782 unsigned int gotent_flags
;
1783 bfd_boolean maybe_dynamic
;
1787 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1788 if (r_symndx
< symtab_hdr
->sh_info
)
1792 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1794 while (h
->root
.root
.type
== bfd_link_hash_indirect
1795 || h
->root
.root
.type
== bfd_link_hash_warning
)
1796 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
1798 h
->root
.ref_regular
= 1;
1801 /* We can only get preliminary data on whether a symbol is
1802 locally or externally defined, as not all of the input files
1803 have yet been processed. Do something with what we know, as
1804 this may help reduce memory usage and processing time later. */
1805 maybe_dynamic
= FALSE
;
1806 if (h
&& ((info
->shared
1808 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
1809 || !h
->root
.def_regular
1810 || h
->root
.root
.type
== bfd_link_hash_defweak
))
1811 maybe_dynamic
= TRUE
;
1815 r_type
= ELF64_R_TYPE (rel
->r_info
);
1816 addend
= rel
->r_addend
;
1820 case R_ALPHA_LITERAL
:
1821 need
= NEED_GOT
| NEED_GOT_ENTRY
;
1823 /* Remember how this literal is used from its LITUSEs.
1824 This will be important when it comes to decide if we can
1825 create a .plt entry for a function symbol. */
1826 while (++rel
< relend
&& ELF64_R_TYPE (rel
->r_info
) == R_ALPHA_LITUSE
)
1827 if (rel
->r_addend
>= 1 && rel
->r_addend
<= 6)
1828 gotent_flags
|= 1 << rel
->r_addend
;
1831 /* No LITUSEs -- presumably the address is used somehow. */
1832 if (gotent_flags
== 0)
1833 gotent_flags
= ALPHA_ELF_LINK_HASH_LU_ADDR
;
1836 case R_ALPHA_GPDISP
:
1837 case R_ALPHA_GPREL16
:
1838 case R_ALPHA_GPREL32
:
1839 case R_ALPHA_GPRELHIGH
:
1840 case R_ALPHA_GPRELLOW
:
1845 case R_ALPHA_REFLONG
:
1846 case R_ALPHA_REFQUAD
:
1847 if (info
->shared
|| maybe_dynamic
)
1851 case R_ALPHA_TLSLDM
:
1852 /* The symbol for a TLSLDM reloc is ignored. Collapse the
1853 reloc to the 0 symbol so that they all match. */
1856 maybe_dynamic
= FALSE
;
1860 case R_ALPHA_GOTDTPREL
:
1861 need
= NEED_GOT
| NEED_GOT_ENTRY
;
1864 case R_ALPHA_GOTTPREL
:
1865 need
= NEED_GOT
| NEED_GOT_ENTRY
;
1866 gotent_flags
= ALPHA_ELF_LINK_HASH_TLS_IE
;
1868 info
->flags
|= DF_STATIC_TLS
;
1871 case R_ALPHA_TPREL64
:
1872 if (info
->shared
|| maybe_dynamic
)
1875 info
->flags
|= DF_STATIC_TLS
;
1879 if (need
& NEED_GOT
)
1881 if (alpha_elf_tdata(abfd
)->gotobj
== NULL
)
1883 if (!elf64_alpha_create_got_section (abfd
, info
))
1888 if (need
& NEED_GOT_ENTRY
)
1890 struct alpha_elf_got_entry
*gotent
;
1892 gotent
= get_got_entry (abfd
, h
, r_type
, r_symndx
, addend
);
1898 gotent
->flags
|= gotent_flags
;
1901 gotent_flags
|= h
->flags
;
1902 h
->flags
= gotent_flags
;
1904 /* Make a guess as to whether a .plt entry is needed. */
1905 /* ??? It appears that we won't make it into
1906 adjust_dynamic_symbol for symbols that remain
1907 totally undefined. Copying this check here means
1908 we can create a plt entry for them too. */
1910 = (maybe_dynamic
&& elf64_alpha_want_plt (h
));
1915 if (need
& NEED_DYNREL
)
1917 if (rel_sec_name
== NULL
)
1919 rel_sec_name
= (bfd_elf_string_from_elf_section
1920 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1921 elf_section_data(sec
)->rel_hdr
.sh_name
));
1922 if (rel_sec_name
== NULL
)
1925 BFD_ASSERT (CONST_STRNEQ (rel_sec_name
, ".rela")
1926 && strcmp (bfd_get_section_name (abfd
, sec
),
1927 rel_sec_name
+5) == 0);
1930 /* We need to create the section here now whether we eventually
1931 use it or not so that it gets mapped to an output section by
1932 the linker. If not used, we'll kill it in
1933 size_dynamic_sections. */
1936 sreloc
= bfd_get_section_by_name (dynobj
, rel_sec_name
);
1941 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1942 | SEC_LINKER_CREATED
| SEC_READONLY
);
1943 if (sec
->flags
& SEC_ALLOC
)
1944 flags
|= SEC_ALLOC
| SEC_LOAD
;
1945 sreloc
= bfd_make_section_with_flags (dynobj
,
1949 || !bfd_set_section_alignment (dynobj
, sreloc
, 3))
1956 /* Since we havn't seen all of the input symbols yet, we
1957 don't know whether we'll actually need a dynamic relocation
1958 entry for this reloc. So make a record of it. Once we
1959 find out if this thing needs dynamic relocation we'll
1960 expand the relocation sections by the appropriate amount. */
1962 struct alpha_elf_reloc_entry
*rent
;
1964 for (rent
= h
->reloc_entries
; rent
; rent
= rent
->next
)
1965 if (rent
->rtype
== r_type
&& rent
->srel
== sreloc
)
1970 amt
= sizeof (struct alpha_elf_reloc_entry
);
1971 rent
= (struct alpha_elf_reloc_entry
*) bfd_alloc (abfd
, amt
);
1975 rent
->srel
= sreloc
;
1976 rent
->rtype
= r_type
;
1978 rent
->reltext
= (sec
->flags
& SEC_READONLY
) != 0;
1980 rent
->next
= h
->reloc_entries
;
1981 h
->reloc_entries
= rent
;
1986 else if (info
->shared
)
1988 /* If this is a shared library, and the section is to be
1989 loaded into memory, we need a RELATIVE reloc. */
1990 sreloc
->size
+= sizeof (Elf64_External_Rela
);
1991 if (sec
->flags
& SEC_READONLY
)
1992 info
->flags
|= DF_TEXTREL
;
2000 /* Adjust a symbol defined by a dynamic object and referenced by a
2001 regular object. The current definition is in some section of the
2002 dynamic object, but we're not including those sections. We have to
2003 change the definition to something the rest of the link can
2007 elf64_alpha_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2008 struct elf_link_hash_entry
*h
)
2012 struct alpha_elf_link_hash_entry
*ah
;
2014 dynobj
= elf_hash_table(info
)->dynobj
;
2015 ah
= (struct alpha_elf_link_hash_entry
*)h
;
2017 /* Now that we've seen all of the input symbols, finalize our decision
2018 about whether this symbol should get a .plt entry. Irritatingly, it
2019 is common for folk to leave undefined symbols in shared libraries,
2020 and they still expect lazy binding; accept undefined symbols in lieu
2022 if (alpha_elf_dynamic_symbol_p (h
, info
) && elf64_alpha_want_plt (ah
))
2024 h
->needs_plt
= TRUE
;
2026 s
= bfd_get_section_by_name(dynobj
, ".plt");
2027 if (!s
&& !elf64_alpha_create_dynamic_sections (dynobj
, info
))
2030 /* We need one plt entry per got subsection. Delay allocation of
2031 the actual plt entries until size_plt_section, called from
2032 size_dynamic_sections or during relaxation. */
2037 h
->needs_plt
= FALSE
;
2039 /* If this is a weak symbol, and there is a real definition, the
2040 processor independent code will have arranged for us to see the
2041 real definition first, and we can just use the same value. */
2042 if (h
->u
.weakdef
!= NULL
)
2044 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2045 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2046 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2047 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2051 /* This is a reference to a symbol defined by a dynamic object which
2052 is not a function. The Alpha, since it uses .got entries for all
2053 symbols even in regular objects, does not need the hackery of a
2054 .dynbss section and COPY dynamic relocations. */
2059 /* Record STO_ALPHA_NOPV and STO_ALPHA_STD_GPLOAD. */
2062 elf64_alpha_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
2063 const Elf_Internal_Sym
*isym
,
2064 bfd_boolean definition
,
2065 bfd_boolean dynamic
)
2067 if (!dynamic
&& definition
)
2068 h
->other
= ((h
->other
& ELF_ST_VISIBILITY (-1))
2069 | (isym
->st_other
& ~ELF_ST_VISIBILITY (-1)));
2072 /* Symbol versioning can create new symbols, and make our old symbols
2073 indirect to the new ones. Consolidate the got and reloc information
2074 in these situations. */
2077 elf64_alpha_merge_ind_symbols (struct alpha_elf_link_hash_entry
*hi
,
2078 PTR dummy ATTRIBUTE_UNUSED
)
2080 struct alpha_elf_link_hash_entry
*hs
;
2082 if (hi
->root
.root
.type
!= bfd_link_hash_indirect
)
2086 hs
= (struct alpha_elf_link_hash_entry
*)hs
->root
.root
.u
.i
.link
;
2087 } while (hs
->root
.root
.type
== bfd_link_hash_indirect
);
2089 /* Merge the flags. Whee. */
2091 hs
->flags
|= hi
->flags
;
2093 /* Merge the .got entries. Cannibalize the old symbol's list in
2094 doing so, since we don't need it anymore. */
2096 if (hs
->got_entries
== NULL
)
2097 hs
->got_entries
= hi
->got_entries
;
2100 struct alpha_elf_got_entry
*gi
, *gs
, *gin
, *gsh
;
2102 gsh
= hs
->got_entries
;
2103 for (gi
= hi
->got_entries
; gi
; gi
= gin
)
2106 for (gs
= gsh
; gs
; gs
= gs
->next
)
2107 if (gi
->gotobj
== gs
->gotobj
2108 && gi
->reloc_type
== gs
->reloc_type
2109 && gi
->addend
== gs
->addend
)
2111 gi
->use_count
+= gs
->use_count
;
2114 gi
->next
= hs
->got_entries
;
2115 hs
->got_entries
= gi
;
2119 hi
->got_entries
= NULL
;
2121 /* And similar for the reloc entries. */
2123 if (hs
->reloc_entries
== NULL
)
2124 hs
->reloc_entries
= hi
->reloc_entries
;
2127 struct alpha_elf_reloc_entry
*ri
, *rs
, *rin
, *rsh
;
2129 rsh
= hs
->reloc_entries
;
2130 for (ri
= hi
->reloc_entries
; ri
; ri
= rin
)
2133 for (rs
= rsh
; rs
; rs
= rs
->next
)
2134 if (ri
->rtype
== rs
->rtype
&& ri
->srel
== rs
->srel
)
2136 rs
->count
+= ri
->count
;
2139 ri
->next
= hs
->reloc_entries
;
2140 hs
->reloc_entries
= ri
;
2144 hi
->reloc_entries
= NULL
;
2149 /* Is it possible to merge two object file's .got tables? */
2152 elf64_alpha_can_merge_gots (bfd
*a
, bfd
*b
)
2154 int total
= alpha_elf_tdata (a
)->total_got_size
;
2157 /* Trivial quick fallout test. */
2158 if (total
+ alpha_elf_tdata (b
)->total_got_size
<= MAX_GOT_SIZE
)
2161 /* By their nature, local .got entries cannot be merged. */
2162 if ((total
+= alpha_elf_tdata (b
)->local_got_size
) > MAX_GOT_SIZE
)
2165 /* Failing the common trivial comparison, we must effectively
2166 perform the merge. Not actually performing the merge means that
2167 we don't have to store undo information in case we fail. */
2168 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
2170 struct alpha_elf_link_hash_entry
**hashes
= alpha_elf_sym_hashes (bsub
);
2171 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
2174 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
2175 for (i
= 0; i
< n
; ++i
)
2177 struct alpha_elf_got_entry
*ae
, *be
;
2178 struct alpha_elf_link_hash_entry
*h
;
2181 while (h
->root
.root
.type
== bfd_link_hash_indirect
2182 || h
->root
.root
.type
== bfd_link_hash_warning
)
2183 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2185 for (be
= h
->got_entries
; be
; be
= be
->next
)
2187 if (be
->use_count
== 0)
2189 if (be
->gotobj
!= b
)
2192 for (ae
= h
->got_entries
; ae
; ae
= ae
->next
)
2194 && ae
->reloc_type
== be
->reloc_type
2195 && ae
->addend
== be
->addend
)
2198 total
+= alpha_got_entry_size (be
->reloc_type
);
2199 if (total
> MAX_GOT_SIZE
)
2209 /* Actually merge two .got tables. */
2212 elf64_alpha_merge_gots (bfd
*a
, bfd
*b
)
2214 int total
= alpha_elf_tdata (a
)->total_got_size
;
2217 /* Remember local expansion. */
2219 int e
= alpha_elf_tdata (b
)->local_got_size
;
2221 alpha_elf_tdata (a
)->local_got_size
+= e
;
2224 for (bsub
= b
; bsub
; bsub
= alpha_elf_tdata (bsub
)->in_got_link_next
)
2226 struct alpha_elf_got_entry
**local_got_entries
;
2227 struct alpha_elf_link_hash_entry
**hashes
;
2228 Elf_Internal_Shdr
*symtab_hdr
;
2231 /* Let the local .got entries know they are part of a new subsegment. */
2232 local_got_entries
= alpha_elf_tdata (bsub
)->local_got_entries
;
2233 if (local_got_entries
)
2235 n
= elf_tdata (bsub
)->symtab_hdr
.sh_info
;
2236 for (i
= 0; i
< n
; ++i
)
2238 struct alpha_elf_got_entry
*ent
;
2239 for (ent
= local_got_entries
[i
]; ent
; ent
= ent
->next
)
2244 /* Merge the global .got entries. */
2245 hashes
= alpha_elf_sym_hashes (bsub
);
2246 symtab_hdr
= &elf_tdata (bsub
)->symtab_hdr
;
2248 n
= NUM_SHDR_ENTRIES (symtab_hdr
) - symtab_hdr
->sh_info
;
2249 for (i
= 0; i
< n
; ++i
)
2251 struct alpha_elf_got_entry
*ae
, *be
, **pbe
, **start
;
2252 struct alpha_elf_link_hash_entry
*h
;
2255 while (h
->root
.root
.type
== bfd_link_hash_indirect
2256 || h
->root
.root
.type
== bfd_link_hash_warning
)
2257 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2259 pbe
= start
= &h
->got_entries
;
2260 while ((be
= *pbe
) != NULL
)
2262 if (be
->use_count
== 0)
2265 memset (be
, 0xa5, sizeof (*be
));
2268 if (be
->gotobj
!= b
)
2271 for (ae
= *start
; ae
; ae
= ae
->next
)
2273 && ae
->reloc_type
== be
->reloc_type
2274 && ae
->addend
== be
->addend
)
2276 ae
->flags
|= be
->flags
;
2277 ae
->use_count
+= be
->use_count
;
2279 memset (be
, 0xa5, sizeof (*be
));
2283 total
+= alpha_got_entry_size (be
->reloc_type
);
2291 alpha_elf_tdata (bsub
)->gotobj
= a
;
2293 alpha_elf_tdata (a
)->total_got_size
= total
;
2295 /* Merge the two in_got chains. */
2300 while ((next
= alpha_elf_tdata (bsub
)->in_got_link_next
) != NULL
)
2303 alpha_elf_tdata (bsub
)->in_got_link_next
= b
;
2307 /* Calculate the offsets for the got entries. */
2310 elf64_alpha_calc_got_offsets_for_symbol (struct alpha_elf_link_hash_entry
*h
,
2311 PTR arg ATTRIBUTE_UNUSED
)
2313 struct alpha_elf_got_entry
*gotent
;
2315 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2316 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2318 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2319 if (gotent
->use_count
> 0)
2321 struct alpha_elf_obj_tdata
*td
;
2322 bfd_size_type
*plge
;
2324 td
= alpha_elf_tdata (gotent
->gotobj
);
2325 plge
= &td
->got
->size
;
2326 gotent
->got_offset
= *plge
;
2327 *plge
+= alpha_got_entry_size (gotent
->reloc_type
);
2334 elf64_alpha_calc_got_offsets (struct bfd_link_info
*info
)
2336 bfd
*i
, *got_list
= alpha_elf_hash_table(info
)->got_list
;
2338 /* First, zero out the .got sizes, as we may be recalculating the
2339 .got after optimizing it. */
2340 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2341 alpha_elf_tdata(i
)->got
->size
= 0;
2343 /* Next, fill in the offsets for all the global entries. */
2344 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2345 elf64_alpha_calc_got_offsets_for_symbol
,
2348 /* Finally, fill in the offsets for the local entries. */
2349 for (i
= got_list
; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2351 bfd_size_type got_offset
= alpha_elf_tdata(i
)->got
->size
;
2354 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2356 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2359 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2360 if (!local_got_entries
)
2363 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2364 for (gotent
= local_got_entries
[k
]; gotent
; gotent
= gotent
->next
)
2365 if (gotent
->use_count
> 0)
2367 gotent
->got_offset
= got_offset
;
2368 got_offset
+= alpha_got_entry_size (gotent
->reloc_type
);
2372 alpha_elf_tdata(i
)->got
->size
= got_offset
;
2376 /* Constructs the gots. */
2379 elf64_alpha_size_got_sections (struct bfd_link_info
*info
)
2381 bfd
*i
, *got_list
, *cur_got_obj
= NULL
;
2383 got_list
= alpha_elf_hash_table (info
)->got_list
;
2385 /* On the first time through, pretend we have an existing got list
2386 consisting of all of the input files. */
2387 if (got_list
== NULL
)
2389 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
2391 bfd
*this_got
= alpha_elf_tdata (i
)->gotobj
;
2392 if (this_got
== NULL
)
2395 /* We are assuming no merging has yet occurred. */
2396 BFD_ASSERT (this_got
== i
);
2398 if (alpha_elf_tdata (this_got
)->total_got_size
> MAX_GOT_SIZE
)
2400 /* Yikes! A single object file has too many entries. */
2401 (*_bfd_error_handler
)
2402 (_("%B: .got subsegment exceeds 64K (size %d)"),
2403 i
, alpha_elf_tdata (this_got
)->total_got_size
);
2407 if (got_list
== NULL
)
2408 got_list
= this_got
;
2410 alpha_elf_tdata(cur_got_obj
)->got_link_next
= this_got
;
2411 cur_got_obj
= this_got
;
2414 /* Strange degenerate case of no got references. */
2415 if (got_list
== NULL
)
2418 alpha_elf_hash_table (info
)->got_list
= got_list
;
2421 cur_got_obj
= got_list
;
2422 i
= alpha_elf_tdata(cur_got_obj
)->got_link_next
;
2425 if (elf64_alpha_can_merge_gots (cur_got_obj
, i
))
2427 elf64_alpha_merge_gots (cur_got_obj
, i
);
2429 alpha_elf_tdata(i
)->got
->size
= 0;
2430 i
= alpha_elf_tdata(i
)->got_link_next
;
2431 alpha_elf_tdata(cur_got_obj
)->got_link_next
= i
;
2436 i
= alpha_elf_tdata(i
)->got_link_next
;
2440 /* Once the gots have been merged, fill in the got offsets for
2441 everything therein. */
2442 elf64_alpha_calc_got_offsets (info
);
2448 elf64_alpha_size_plt_section_1 (struct alpha_elf_link_hash_entry
*h
, PTR data
)
2450 asection
*splt
= (asection
*) data
;
2451 struct alpha_elf_got_entry
*gotent
;
2452 bfd_boolean saw_one
= FALSE
;
2454 /* If we didn't need an entry before, we still don't. */
2455 if (!h
->root
.needs_plt
)
2458 /* For each LITERAL got entry still in use, allocate a plt entry. */
2459 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2460 if (gotent
->reloc_type
== R_ALPHA_LITERAL
2461 && gotent
->use_count
> 0)
2463 if (splt
->size
== 0)
2464 splt
->size
= PLT_HEADER_SIZE
;
2465 gotent
->plt_offset
= splt
->size
;
2466 splt
->size
+= PLT_ENTRY_SIZE
;
2470 /* If there weren't any, there's no longer a need for the PLT entry. */
2472 h
->root
.needs_plt
= FALSE
;
2477 /* Called from relax_section to rebuild the PLT in light of potential changes
2478 in the function's status. */
2481 elf64_alpha_size_plt_section (struct bfd_link_info
*info
)
2483 asection
*splt
, *spltrel
, *sgotplt
;
2484 unsigned long entries
;
2487 dynobj
= elf_hash_table(info
)->dynobj
;
2488 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2494 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2495 elf64_alpha_size_plt_section_1
, splt
);
2497 /* Every plt entry requires a JMP_SLOT relocation. */
2498 spltrel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2502 if (elf64_alpha_use_secureplt
)
2503 entries
= (splt
->size
- NEW_PLT_HEADER_SIZE
) / NEW_PLT_ENTRY_SIZE
;
2505 entries
= (splt
->size
- OLD_PLT_HEADER_SIZE
) / OLD_PLT_ENTRY_SIZE
;
2507 spltrel
->size
= entries
* sizeof (Elf64_External_Rela
);
2509 /* When using the secureplt, we need two words somewhere in the data
2510 segment for the dynamic linker to tell us where to go. This is the
2511 entire contents of the .got.plt section. */
2512 if (elf64_alpha_use_secureplt
)
2514 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
2515 sgotplt
->size
= entries
? 16 : 0;
2520 elf64_alpha_always_size_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2521 struct bfd_link_info
*info
)
2525 if (info
->relocatable
)
2528 /* First, take care of the indirect symbols created by versioning. */
2529 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2530 elf64_alpha_merge_ind_symbols
,
2533 if (!elf64_alpha_size_got_sections (info
))
2536 /* Allocate space for all of the .got subsections. */
2537 i
= alpha_elf_hash_table (info
)->got_list
;
2538 for ( ; i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2540 asection
*s
= alpha_elf_tdata(i
)->got
;
2543 s
->contents
= (bfd_byte
*) bfd_zalloc (i
, s
->size
);
2544 if (s
->contents
== NULL
)
2552 /* The number of dynamic relocations required by a static relocation. */
2555 alpha_dynamic_entries_for_reloc (int r_type
, int dynamic
, int shared
)
2559 /* May appear in GOT entries. */
2561 return (dynamic
? 2 : shared
? 1 : 0);
2562 case R_ALPHA_TLSLDM
:
2564 case R_ALPHA_LITERAL
:
2565 case R_ALPHA_GOTTPREL
:
2566 return dynamic
|| shared
;
2567 case R_ALPHA_GOTDTPREL
:
2570 /* May appear in data sections. */
2571 case R_ALPHA_REFLONG
:
2572 case R_ALPHA_REFQUAD
:
2573 case R_ALPHA_TPREL64
:
2574 return dynamic
|| shared
;
2576 /* Everything else is illegal. We'll issue an error during
2577 relocate_section. */
2583 /* Work out the sizes of the dynamic relocation entries. */
2586 elf64_alpha_calc_dynrel_sizes (struct alpha_elf_link_hash_entry
*h
,
2587 struct bfd_link_info
*info
)
2589 bfd_boolean dynamic
;
2590 struct alpha_elf_reloc_entry
*relent
;
2591 unsigned long entries
;
2593 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2594 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2596 /* If the symbol was defined as a common symbol in a regular object
2597 file, and there was no definition in any dynamic object, then the
2598 linker will have allocated space for the symbol in a common
2599 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been
2600 set. This is done for dynamic symbols in
2601 elf_adjust_dynamic_symbol but this is not done for non-dynamic
2602 symbols, somehow. */
2603 if (!h
->root
.def_regular
2604 && h
->root
.ref_regular
2605 && !h
->root
.def_dynamic
2606 && (h
->root
.root
.type
== bfd_link_hash_defined
2607 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2608 && !(h
->root
.root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
2609 h
->root
.def_regular
= 1;
2611 /* If the symbol is dynamic, we'll need all the relocations in their
2612 natural form. If this is a shared object, and it has been forced
2613 local, we'll need the same number of RELATIVE relocations. */
2614 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
2616 /* If the symbol is a hidden undefined weak, then we never have any
2617 relocations. Avoid the loop which may want to add RELATIVE relocs
2618 based on info->shared. */
2619 if (h
->root
.root
.type
== bfd_link_hash_undefweak
&& !dynamic
)
2622 for (relent
= h
->reloc_entries
; relent
; relent
= relent
->next
)
2624 entries
= alpha_dynamic_entries_for_reloc (relent
->rtype
, dynamic
,
2628 relent
->srel
->size
+=
2629 entries
* sizeof (Elf64_External_Rela
) * relent
->count
;
2630 if (relent
->reltext
)
2631 info
->flags
|= DT_TEXTREL
;
2638 /* Subroutine of elf64_alpha_size_rela_got_section for doing the
2642 elf64_alpha_size_rela_got_1 (struct alpha_elf_link_hash_entry
*h
,
2643 struct bfd_link_info
*info
)
2645 bfd_boolean dynamic
;
2646 struct alpha_elf_got_entry
*gotent
;
2647 unsigned long entries
;
2649 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2650 h
= (struct alpha_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2652 /* If we're using a plt for this symbol, then all of its relocations
2653 for its got entries go into .rela.plt. */
2654 if (h
->root
.needs_plt
)
2657 /* If the symbol is dynamic, we'll need all the relocations in their
2658 natural form. If this is a shared object, and it has been forced
2659 local, we'll need the same number of RELATIVE relocations. */
2660 dynamic
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
2662 /* If the symbol is a hidden undefined weak, then we never have any
2663 relocations. Avoid the loop which may want to add RELATIVE relocs
2664 based on info->shared. */
2665 if (h
->root
.root
.type
== bfd_link_hash_undefweak
&& !dynamic
)
2669 for (gotent
= h
->got_entries
; gotent
; gotent
= gotent
->next
)
2670 if (gotent
->use_count
> 0)
2671 entries
+= alpha_dynamic_entries_for_reloc (gotent
->reloc_type
,
2672 dynamic
, info
->shared
);
2676 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
2677 asection
*srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2678 BFD_ASSERT (srel
!= NULL
);
2679 srel
->size
+= sizeof (Elf64_External_Rela
) * entries
;
2685 /* Set the sizes of the dynamic relocation sections. */
2688 elf64_alpha_size_rela_got_section (struct bfd_link_info
*info
)
2690 unsigned long entries
;
2694 /* Shared libraries often require RELATIVE relocs, and some relocs
2695 require attention for the main application as well. */
2698 for (i
= alpha_elf_hash_table(info
)->got_list
;
2699 i
; i
= alpha_elf_tdata(i
)->got_link_next
)
2703 for (j
= i
; j
; j
= alpha_elf_tdata(j
)->in_got_link_next
)
2705 struct alpha_elf_got_entry
**local_got_entries
, *gotent
;
2708 local_got_entries
= alpha_elf_tdata(j
)->local_got_entries
;
2709 if (!local_got_entries
)
2712 for (k
= 0, n
= elf_tdata(j
)->symtab_hdr
.sh_info
; k
< n
; ++k
)
2713 for (gotent
= local_got_entries
[k
];
2714 gotent
; gotent
= gotent
->next
)
2715 if (gotent
->use_count
> 0)
2716 entries
+= (alpha_dynamic_entries_for_reloc
2717 (gotent
->reloc_type
, 0, info
->shared
));
2721 dynobj
= elf_hash_table(info
)->dynobj
;
2722 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
2725 BFD_ASSERT (entries
== 0);
2728 srel
->size
= sizeof (Elf64_External_Rela
) * entries
;
2730 /* Now do the non-local symbols. */
2731 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2732 elf64_alpha_size_rela_got_1
, info
);
2735 /* Set the sizes of the dynamic sections. */
2738 elf64_alpha_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2739 struct bfd_link_info
*info
)
2745 dynobj
= elf_hash_table(info
)->dynobj
;
2746 BFD_ASSERT(dynobj
!= NULL
);
2748 if (elf_hash_table (info
)->dynamic_sections_created
)
2750 /* Set the contents of the .interp section to the interpreter. */
2751 if (info
->executable
)
2753 s
= bfd_get_section_by_name (dynobj
, ".interp");
2754 BFD_ASSERT (s
!= NULL
);
2755 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2756 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2759 /* Now that we've seen all of the input files, we can decide which
2760 symbols need dynamic relocation entries and which don't. We've
2761 collected information in check_relocs that we can now apply to
2762 size the dynamic relocation sections. */
2763 alpha_elf_link_hash_traverse (alpha_elf_hash_table (info
),
2764 elf64_alpha_calc_dynrel_sizes
, info
);
2766 elf64_alpha_size_rela_got_section (info
);
2767 elf64_alpha_size_plt_section (info
);
2769 /* else we're not dynamic and by definition we don't need such things. */
2771 /* The check_relocs and adjust_dynamic_symbol entry points have
2772 determined the sizes of the various dynamic sections. Allocate
2775 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2779 if (!(s
->flags
& SEC_LINKER_CREATED
))
2782 /* It's OK to base decisions on the section name, because none
2783 of the dynobj section names depend upon the input files. */
2784 name
= bfd_get_section_name (dynobj
, s
);
2786 if (CONST_STRNEQ (name
, ".rela"))
2790 if (strcmp (name
, ".rela.plt") == 0)
2793 /* We use the reloc_count field as a counter if we need
2794 to copy relocs into the output file. */
2798 else if (! CONST_STRNEQ (name
, ".got")
2799 && strcmp (name
, ".plt") != 0
2800 && strcmp (name
, ".dynbss") != 0)
2802 /* It's not one of our dynamic sections, so don't allocate space. */
2808 /* If we don't need this section, strip it from the output file.
2809 This is to handle .rela.bss and .rela.plt. We must create it
2810 in create_dynamic_sections, because it must be created before
2811 the linker maps input sections to output sections. The
2812 linker does that before adjust_dynamic_symbol is called, and
2813 it is that function which decides whether anything needs to
2814 go into these sections. */
2815 s
->flags
|= SEC_EXCLUDE
;
2817 else if ((s
->flags
& SEC_HAS_CONTENTS
) != 0)
2819 /* Allocate memory for the section contents. */
2820 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2821 if (s
->contents
== NULL
)
2826 if (elf_hash_table (info
)->dynamic_sections_created
)
2828 /* Add some entries to the .dynamic section. We fill in the
2829 values later, in elf64_alpha_finish_dynamic_sections, but we
2830 must add the entries now so that we get the correct size for
2831 the .dynamic section. The DT_DEBUG entry is filled in by the
2832 dynamic linker and used by the debugger. */
2833 #define add_dynamic_entry(TAG, VAL) \
2834 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2836 if (info
->executable
)
2838 if (!add_dynamic_entry (DT_DEBUG
, 0))
2844 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2845 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2846 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2847 || !add_dynamic_entry (DT_JMPREL
, 0))
2850 if (elf64_alpha_use_secureplt
2851 && !add_dynamic_entry (DT_ALPHA_PLTRO
, 1))
2855 if (!add_dynamic_entry (DT_RELA
, 0)
2856 || !add_dynamic_entry (DT_RELASZ
, 0)
2857 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2860 if (info
->flags
& DF_TEXTREL
)
2862 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2866 #undef add_dynamic_entry
2871 /* These functions do relaxation for Alpha ELF.
2873 Currently I'm only handling what I can do with existing compiler
2874 and assembler support, which means no instructions are removed,
2875 though some may be nopped. At this time GCC does not emit enough
2876 information to do all of the relaxing that is possible. It will
2877 take some not small amount of work for that to happen.
2879 There are a couple of interesting papers that I once read on this
2880 subject, that I cannot find references to at the moment, that
2881 related to Alpha in particular. They are by David Wall, then of
2884 struct alpha_relax_info
2889 Elf_Internal_Shdr
*symtab_hdr
;
2890 Elf_Internal_Rela
*relocs
, *relend
;
2891 struct bfd_link_info
*link_info
;
2895 struct alpha_elf_link_hash_entry
*h
;
2896 struct alpha_elf_got_entry
**first_gotent
;
2897 struct alpha_elf_got_entry
*gotent
;
2898 bfd_boolean changed_contents
;
2899 bfd_boolean changed_relocs
;
2900 unsigned char other
;
2903 static Elf_Internal_Rela
*
2904 elf64_alpha_find_reloc_at_ofs (Elf_Internal_Rela
*rel
,
2905 Elf_Internal_Rela
*relend
,
2906 bfd_vma offset
, int type
)
2908 while (rel
< relend
)
2910 if (rel
->r_offset
== offset
2911 && ELF64_R_TYPE (rel
->r_info
) == (unsigned int) type
)
2919 elf64_alpha_relax_got_load (struct alpha_relax_info
*info
, bfd_vma symval
,
2920 Elf_Internal_Rela
*irel
, unsigned long r_type
)
2923 bfd_signed_vma disp
;
2925 /* Get the instruction. */
2926 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
2928 if (insn
>> 26 != OP_LDQ
)
2930 reloc_howto_type
*howto
= elf64_alpha_howto_table
+ r_type
;
2931 ((*_bfd_error_handler
)
2932 ("%B: %A+0x%lx: warning: %s relocation against unexpected insn",
2933 info
->abfd
, info
->sec
,
2934 (unsigned long) irel
->r_offset
, howto
->name
));
2938 /* Can't relax dynamic symbols. */
2939 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
2942 /* Can't use local-exec relocations in shared libraries. */
2943 if (r_type
== R_ALPHA_GOTTPREL
&& info
->link_info
->shared
)
2946 if (r_type
== R_ALPHA_LITERAL
)
2948 /* Look for nice constant addresses. This includes the not-uncommon
2949 special case of 0 for undefweak symbols. */
2950 if ((info
->h
&& info
->h
->root
.root
.type
== bfd_link_hash_undefweak
)
2951 || (!info
->link_info
->shared
2952 && (symval
>= (bfd_vma
)-0x8000 || symval
< 0x8000)))
2955 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
2956 insn
|= (symval
& 0xffff);
2957 r_type
= R_ALPHA_NONE
;
2961 disp
= symval
- info
->gp
;
2962 insn
= (OP_LDA
<< 26) | (insn
& 0x03ff0000);
2963 r_type
= R_ALPHA_GPREL16
;
2968 bfd_vma dtp_base
, tp_base
;
2970 BFD_ASSERT (elf_hash_table (info
->link_info
)->tls_sec
!= NULL
);
2971 dtp_base
= alpha_get_dtprel_base (info
->link_info
);
2972 tp_base
= alpha_get_tprel_base (info
->link_info
);
2973 disp
= symval
- (r_type
== R_ALPHA_GOTDTPREL
? dtp_base
: tp_base
);
2975 insn
= (OP_LDA
<< 26) | (insn
& (31 << 21)) | (31 << 16);
2979 case R_ALPHA_GOTDTPREL
:
2980 r_type
= R_ALPHA_DTPREL16
;
2982 case R_ALPHA_GOTTPREL
:
2983 r_type
= R_ALPHA_TPREL16
;
2991 if (disp
< -0x8000 || disp
>= 0x8000)
2994 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, info
->contents
+ irel
->r_offset
);
2995 info
->changed_contents
= TRUE
;
2997 /* Reduce the use count on this got entry by one, possibly
2999 if (--info
->gotent
->use_count
== 0)
3001 int sz
= alpha_got_entry_size (r_type
);
3002 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3004 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
3007 /* Smash the existing GOT relocation for its 16-bit immediate pair. */
3008 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
), r_type
);
3009 info
->changed_relocs
= TRUE
;
3011 /* ??? Search forward through this basic block looking for insns
3012 that use the target register. Stop after an insn modifying the
3013 register is seen, or after a branch or call.
3015 Any such memory load insn may be substituted by a load directly
3016 off the GP. This allows the memory load insn to be issued before
3017 the calculated GP register would otherwise be ready.
3019 Any such jsr insn can be replaced by a bsr if it is in range.
3021 This would mean that we'd have to _add_ relocations, the pain of
3022 which gives one pause. */
3028 elf64_alpha_relax_opt_call (struct alpha_relax_info
*info
, bfd_vma symval
)
3030 /* If the function has the same gp, and we can identify that the
3031 function does not use its function pointer, we can eliminate the
3034 /* If the symbol is marked NOPV, we are being told the function never
3035 needs its procedure value. */
3036 if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_NOPV
)
3039 /* If the symbol is marked STD_GP, we are being told the function does
3040 a normal ldgp in the first two words. */
3041 else if ((info
->other
& STO_ALPHA_STD_GPLOAD
) == STO_ALPHA_STD_GPLOAD
)
3044 /* Otherwise, we may be able to identify a GP load in the first two
3045 words, which we can then skip. */
3048 Elf_Internal_Rela
*tsec_relocs
, *tsec_relend
, *tsec_free
, *gpdisp
;
3051 /* Load the relocations from the section that the target symbol is in. */
3052 if (info
->sec
== info
->tsec
)
3054 tsec_relocs
= info
->relocs
;
3055 tsec_relend
= info
->relend
;
3060 tsec_relocs
= (_bfd_elf_link_read_relocs
3061 (info
->abfd
, info
->tsec
, (PTR
) NULL
,
3062 (Elf_Internal_Rela
*) NULL
,
3063 info
->link_info
->keep_memory
));
3064 if (tsec_relocs
== NULL
)
3066 tsec_relend
= tsec_relocs
+ info
->tsec
->reloc_count
;
3067 tsec_free
= (info
->link_info
->keep_memory
? NULL
: tsec_relocs
);
3070 /* Recover the symbol's offset within the section. */
3071 ofs
= (symval
- info
->tsec
->output_section
->vma
3072 - info
->tsec
->output_offset
);
3074 /* Look for a GPDISP reloc. */
3075 gpdisp
= (elf64_alpha_find_reloc_at_ofs
3076 (tsec_relocs
, tsec_relend
, ofs
, R_ALPHA_GPDISP
));
3078 if (!gpdisp
|| gpdisp
->r_addend
!= 4)
3088 /* We've now determined that we can skip an initial gp load. Verify
3089 that the call and the target use the same gp. */
3090 if (info
->link_info
->hash
->creator
!= info
->tsec
->owner
->xvec
3091 || info
->gotobj
!= alpha_elf_tdata (info
->tsec
->owner
)->gotobj
)
3098 elf64_alpha_relax_with_lituse (struct alpha_relax_info
*info
,
3099 bfd_vma symval
, Elf_Internal_Rela
*irel
)
3101 Elf_Internal_Rela
*urel
, *irelend
= info
->relend
;
3102 int flags
, count
, i
;
3103 bfd_signed_vma disp
;
3106 bfd_boolean lit_reused
= FALSE
;
3107 bfd_boolean all_optimized
= TRUE
;
3108 unsigned int lit_insn
;
3110 lit_insn
= bfd_get_32 (info
->abfd
, info
->contents
+ irel
->r_offset
);
3111 if (lit_insn
>> 26 != OP_LDQ
)
3113 ((*_bfd_error_handler
)
3114 ("%B: %A+0x%lx: warning: LITERAL relocation against unexpected insn",
3115 info
->abfd
, info
->sec
,
3116 (unsigned long) irel
->r_offset
));
3120 /* Can't relax dynamic symbols. */
3121 if (alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
))
3124 /* Summarize how this particular LITERAL is used. */
3125 for (urel
= irel
+1, flags
= count
= 0; urel
< irelend
; ++urel
, ++count
)
3127 if (ELF64_R_TYPE (urel
->r_info
) != R_ALPHA_LITUSE
)
3129 if (urel
->r_addend
<= 6)
3130 flags
|= 1 << urel
->r_addend
;
3133 /* A little preparation for the loop... */
3134 disp
= symval
- info
->gp
;
3136 for (urel
= irel
+1, i
= 0; i
< count
; ++i
, ++urel
)
3140 bfd_signed_vma xdisp
;
3142 insn
= bfd_get_32 (info
->abfd
, info
->contents
+ urel
->r_offset
);
3144 switch (urel
->r_addend
)
3146 case LITUSE_ALPHA_ADDR
:
3148 /* This type is really just a placeholder to note that all
3149 uses cannot be optimized, but to still allow some. */
3150 all_optimized
= FALSE
;
3153 case LITUSE_ALPHA_BASE
:
3154 /* We can always optimize 16-bit displacements. */
3156 /* Extract the displacement from the instruction, sign-extending
3157 it if necessary, then test whether it is within 16 or 32 bits
3158 displacement from GP. */
3159 insn_disp
= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
3161 xdisp
= disp
+ insn_disp
;
3162 fits16
= (xdisp
>= - (bfd_signed_vma
) 0x8000 && xdisp
< 0x8000);
3163 fits32
= (xdisp
>= - (bfd_signed_vma
) 0x80000000
3164 && xdisp
< 0x7fff8000);
3168 /* Take the op code and dest from this insn, take the base
3169 register from the literal insn. Leave the offset alone. */
3170 insn
= (insn
& 0xffe0ffff) | (lit_insn
& 0x001f0000);
3171 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3173 urel
->r_addend
= irel
->r_addend
;
3174 info
->changed_relocs
= TRUE
;
3176 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3177 info
->contents
+ urel
->r_offset
);
3178 info
->changed_contents
= TRUE
;
3181 /* If all mem+byte, we can optimize 32-bit mem displacements. */
3182 else if (fits32
&& !(flags
& ~6))
3184 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */
3186 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3188 lit_insn
= (OP_LDAH
<< 26) | (lit_insn
& 0x03ff0000);
3189 bfd_put_32 (info
->abfd
, (bfd_vma
) lit_insn
,
3190 info
->contents
+ irel
->r_offset
);
3192 info
->changed_contents
= TRUE
;
3194 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3196 urel
->r_addend
= irel
->r_addend
;
3197 info
->changed_relocs
= TRUE
;
3200 all_optimized
= FALSE
;
3203 case LITUSE_ALPHA_BYTOFF
:
3204 /* We can always optimize byte instructions. */
3206 /* FIXME: sanity check the insn for byte op. Check that the
3207 literal dest reg is indeed Rb in the byte insn. */
3209 insn
&= ~ (unsigned) 0x001ff000;
3210 insn
|= ((symval
& 7) << 13) | 0x1000;
3212 urel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3214 info
->changed_relocs
= TRUE
;
3216 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3217 info
->contents
+ urel
->r_offset
);
3218 info
->changed_contents
= TRUE
;
3221 case LITUSE_ALPHA_JSR
:
3222 case LITUSE_ALPHA_TLSGD
:
3223 case LITUSE_ALPHA_TLSLDM
:
3224 case LITUSE_ALPHA_JSRDIRECT
:
3226 bfd_vma optdest
, org
;
3227 bfd_signed_vma odisp
;
3229 /* For undefined weak symbols, we're mostly interested in getting
3230 rid of the got entry whenever possible, so optimize this to a
3231 use of the zero register. */
3232 if (info
->h
&& info
->h
->root
.root
.type
== bfd_link_hash_undefweak
)
3235 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3236 info
->contents
+ urel
->r_offset
);
3238 info
->changed_contents
= TRUE
;
3242 /* If not zero, place to jump without needing pv. */
3243 optdest
= elf64_alpha_relax_opt_call (info
, symval
);
3244 org
= (info
->sec
->output_section
->vma
3245 + info
->sec
->output_offset
3246 + urel
->r_offset
+ 4);
3247 odisp
= (optdest
? optdest
: symval
) - org
;
3249 if (odisp
>= -0x400000 && odisp
< 0x400000)
3251 Elf_Internal_Rela
*xrel
;
3253 /* Preserve branch prediction call stack when possible. */
3254 if ((insn
& INSN_JSR_MASK
) == INSN_JSR
)
3255 insn
= (OP_BSR
<< 26) | (insn
& 0x03e00000);
3257 insn
= (OP_BR
<< 26) | (insn
& 0x03e00000);
3259 urel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
3261 urel
->r_addend
= irel
->r_addend
;
3264 urel
->r_addend
+= optdest
- symval
;
3266 all_optimized
= FALSE
;
3268 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
,
3269 info
->contents
+ urel
->r_offset
);
3271 /* Kill any HINT reloc that might exist for this insn. */
3272 xrel
= (elf64_alpha_find_reloc_at_ofs
3273 (info
->relocs
, info
->relend
, urel
->r_offset
,
3276 xrel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3278 info
->changed_contents
= TRUE
;
3279 info
->changed_relocs
= TRUE
;
3282 all_optimized
= FALSE
;
3284 /* Even if the target is not in range for a direct branch,
3285 if we share a GP, we can eliminate the gp reload. */
3288 Elf_Internal_Rela
*gpdisp
3289 = (elf64_alpha_find_reloc_at_ofs
3290 (info
->relocs
, irelend
, urel
->r_offset
+ 4,
3294 bfd_byte
*p_ldah
= info
->contents
+ gpdisp
->r_offset
;
3295 bfd_byte
*p_lda
= p_ldah
+ gpdisp
->r_addend
;
3296 unsigned int ldah
= bfd_get_32 (info
->abfd
, p_ldah
);
3297 unsigned int lda
= bfd_get_32 (info
->abfd
, p_lda
);
3299 /* Verify that the instruction is "ldah $29,0($26)".
3300 Consider a function that ends in a noreturn call,
3301 and that the next function begins with an ldgp,
3302 and that by accident there is no padding between.
3303 In that case the insn would use $27 as the base. */
3304 if (ldah
== 0x27ba0000 && lda
== 0x23bd0000)
3306 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_ldah
);
3307 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, p_lda
);
3309 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3310 info
->changed_contents
= TRUE
;
3311 info
->changed_relocs
= TRUE
;
3320 /* If all cases were optimized, we can reduce the use count on this
3321 got entry by one, possibly eliminating it. */
3324 if (--info
->gotent
->use_count
== 0)
3326 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
3327 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3329 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
3332 /* If the literal instruction is no longer needed (it may have been
3333 reused. We can eliminate it. */
3334 /* ??? For now, I don't want to deal with compacting the section,
3335 so just nop it out. */
3338 irel
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3339 info
->changed_relocs
= TRUE
;
3341 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
,
3342 info
->contents
+ irel
->r_offset
);
3343 info
->changed_contents
= TRUE
;
3349 return elf64_alpha_relax_got_load (info
, symval
, irel
, R_ALPHA_LITERAL
);
3353 elf64_alpha_relax_tls_get_addr (struct alpha_relax_info
*info
, bfd_vma symval
,
3354 Elf_Internal_Rela
*irel
, bfd_boolean is_gd
)
3358 Elf_Internal_Rela
*gpdisp
, *hint
;
3359 bfd_boolean dynamic
, use_gottprel
, pos1_unusable
;
3360 unsigned long new_symndx
;
3362 dynamic
= alpha_elf_dynamic_symbol_p (&info
->h
->root
, info
->link_info
);
3364 /* If a TLS symbol is accessed using IE at least once, there is no point
3365 to use dynamic model for it. */
3366 if (is_gd
&& info
->h
&& (info
->h
->flags
& ALPHA_ELF_LINK_HASH_TLS_IE
))
3369 /* If the symbol is local, and we've already committed to DF_STATIC_TLS,
3370 then we might as well relax to IE. */
3371 else if (info
->link_info
->shared
&& !dynamic
3372 && (info
->link_info
->flags
& DF_STATIC_TLS
))
3375 /* Otherwise we must be building an executable to do anything. */
3376 else if (info
->link_info
->shared
)
3379 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and
3380 the matching LITUSE_TLS relocations. */
3381 if (irel
+ 2 >= info
->relend
)
3383 if (ELF64_R_TYPE (irel
[1].r_info
) != R_ALPHA_LITERAL
3384 || ELF64_R_TYPE (irel
[2].r_info
) != R_ALPHA_LITUSE
3385 || irel
[2].r_addend
!= (is_gd
? LITUSE_ALPHA_TLSGD
: LITUSE_ALPHA_TLSLDM
))
3388 /* There must be a GPDISP relocation positioned immediately after the
3389 LITUSE relocation. */
3390 gpdisp
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
3391 irel
[2].r_offset
+ 4, R_ALPHA_GPDISP
);
3395 pos
[0] = info
->contents
+ irel
[0].r_offset
;
3396 pos
[1] = info
->contents
+ irel
[1].r_offset
;
3397 pos
[2] = info
->contents
+ irel
[2].r_offset
;
3398 pos
[3] = info
->contents
+ gpdisp
->r_offset
;
3399 pos
[4] = pos
[3] + gpdisp
->r_addend
;
3400 pos1_unusable
= FALSE
;
3402 /* Generally, the positions are not allowed to be out of order, lest the
3403 modified insn sequence have different register lifetimes. We can make
3404 an exception when pos 1 is adjacent to pos 0. */
3405 if (pos
[1] + 4 == pos
[0])
3407 bfd_byte
*tmp
= pos
[0];
3411 else if (pos
[1] < pos
[0])
3412 pos1_unusable
= TRUE
;
3413 if (pos
[1] >= pos
[2] || pos
[2] >= pos
[3])
3416 /* Reduce the use count on the LITERAL relocation. Do this before we
3417 smash the symndx when we adjust the relocations below. */
3419 struct alpha_elf_got_entry
*lit_gotent
;
3420 struct alpha_elf_link_hash_entry
*lit_h
;
3423 BFD_ASSERT (ELF64_R_SYM (irel
[1].r_info
) >= info
->symtab_hdr
->sh_info
);
3424 indx
= ELF64_R_SYM (irel
[1].r_info
) - info
->symtab_hdr
->sh_info
;
3425 lit_h
= alpha_elf_sym_hashes (info
->abfd
)[indx
];
3427 while (lit_h
->root
.root
.type
== bfd_link_hash_indirect
3428 || lit_h
->root
.root
.type
== bfd_link_hash_warning
)
3429 lit_h
= (struct alpha_elf_link_hash_entry
*) lit_h
->root
.root
.u
.i
.link
;
3431 for (lit_gotent
= lit_h
->got_entries
; lit_gotent
;
3432 lit_gotent
= lit_gotent
->next
)
3433 if (lit_gotent
->gotobj
== info
->gotobj
3434 && lit_gotent
->reloc_type
== R_ALPHA_LITERAL
3435 && lit_gotent
->addend
== irel
[1].r_addend
)
3437 BFD_ASSERT (lit_gotent
);
3439 if (--lit_gotent
->use_count
== 0)
3441 int sz
= alpha_got_entry_size (R_ALPHA_LITERAL
);
3442 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3448 lda $16,x($gp) !tlsgd!1
3449 ldq $27,__tls_get_addr($gp) !literal!1
3450 jsr $26,($27),__tls_get_addr !lituse_tlsgd!1
3451 ldah $29,0($26) !gpdisp!2
3452 lda $29,0($29) !gpdisp!2
3454 ldq $16,x($gp) !gottprel
3459 or the first pair to
3460 lda $16,x($gp) !tprel
3463 ldah $16,x($gp) !tprelhi
3464 lda $16,x($16) !tprello
3468 use_gottprel
= FALSE
;
3469 new_symndx
= is_gd
? ELF64_R_SYM (irel
->r_info
) : 0;
3470 switch (!dynamic
&& !info
->link_info
->shared
)
3475 bfd_signed_vma disp
;
3477 BFD_ASSERT (elf_hash_table (info
->link_info
)->tls_sec
!= NULL
);
3478 tp_base
= alpha_get_tprel_base (info
->link_info
);
3479 disp
= symval
- tp_base
;
3481 if (disp
>= -0x8000 && disp
< 0x8000)
3483 insn
= (OP_LDA
<< 26) | (16 << 21) | (31 << 16);
3484 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
3485 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
3487 irel
[0].r_offset
= pos
[0] - info
->contents
;
3488 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPREL16
);
3489 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3492 else if (disp
>= -(bfd_signed_vma
) 0x80000000
3493 && disp
< (bfd_signed_vma
) 0x7fff8000
3496 insn
= (OP_LDAH
<< 26) | (16 << 21) | (31 << 16);
3497 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
3498 insn
= (OP_LDA
<< 26) | (16 << 21) | (16 << 16);
3499 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[1]);
3501 irel
[0].r_offset
= pos
[0] - info
->contents
;
3502 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELHI
);
3503 irel
[1].r_offset
= pos
[1] - info
->contents
;
3504 irel
[1].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_TPRELLO
);
3511 use_gottprel
= TRUE
;
3513 insn
= (OP_LDQ
<< 26) | (16 << 21) | (29 << 16);
3514 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[0]);
3515 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[1]);
3517 irel
[0].r_offset
= pos
[0] - info
->contents
;
3518 irel
[0].r_info
= ELF64_R_INFO (new_symndx
, R_ALPHA_GOTTPREL
);
3519 irel
[1].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3523 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_RDUNIQ
, pos
[2]);
3525 insn
= INSN_ADDQ
| (16 << 21) | (0 << 16) | (0 << 0);
3526 bfd_put_32 (info
->abfd
, (bfd_vma
) insn
, pos
[3]);
3528 bfd_put_32 (info
->abfd
, (bfd_vma
) INSN_UNOP
, pos
[4]);
3530 irel
[2].r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3531 gpdisp
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3533 hint
= elf64_alpha_find_reloc_at_ofs (info
->relocs
, info
->relend
,
3534 irel
[2].r_offset
, R_ALPHA_HINT
);
3536 hint
->r_info
= ELF64_R_INFO (0, R_ALPHA_NONE
);
3538 info
->changed_contents
= TRUE
;
3539 info
->changed_relocs
= TRUE
;
3541 /* Reduce the use count on the TLSGD/TLSLDM relocation. */
3542 if (--info
->gotent
->use_count
== 0)
3544 int sz
= alpha_got_entry_size (info
->gotent
->reloc_type
);
3545 alpha_elf_tdata (info
->gotobj
)->total_got_size
-= sz
;
3547 alpha_elf_tdata (info
->gotobj
)->local_got_size
-= sz
;
3550 /* If we've switched to a GOTTPREL relocation, increment the reference
3551 count on that got entry. */
3554 struct alpha_elf_got_entry
*tprel_gotent
;
3556 for (tprel_gotent
= *info
->first_gotent
; tprel_gotent
;
3557 tprel_gotent
= tprel_gotent
->next
)
3558 if (tprel_gotent
->gotobj
== info
->gotobj
3559 && tprel_gotent
->reloc_type
== R_ALPHA_GOTTPREL
3560 && tprel_gotent
->addend
== irel
->r_addend
)
3563 tprel_gotent
->use_count
++;
3566 if (info
->gotent
->use_count
== 0)
3567 tprel_gotent
= info
->gotent
;
3570 tprel_gotent
= (struct alpha_elf_got_entry
*)
3571 bfd_alloc (info
->abfd
, sizeof (struct alpha_elf_got_entry
));
3575 tprel_gotent
->next
= *info
->first_gotent
;
3576 *info
->first_gotent
= tprel_gotent
;
3578 tprel_gotent
->gotobj
= info
->gotobj
;
3579 tprel_gotent
->addend
= irel
->r_addend
;
3580 tprel_gotent
->got_offset
= -1;
3581 tprel_gotent
->reloc_done
= 0;
3582 tprel_gotent
->reloc_xlated
= 0;
3585 tprel_gotent
->use_count
= 1;
3586 tprel_gotent
->reloc_type
= R_ALPHA_GOTTPREL
;
3594 elf64_alpha_relax_section (bfd
*abfd
, asection
*sec
,
3595 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
3597 Elf_Internal_Shdr
*symtab_hdr
;
3598 Elf_Internal_Rela
*internal_relocs
;
3599 Elf_Internal_Rela
*irel
, *irelend
;
3600 Elf_Internal_Sym
*isymbuf
= NULL
;
3601 struct alpha_elf_got_entry
**local_got_entries
;
3602 struct alpha_relax_info info
;
3604 /* There's nothing to change, yet. */
3607 if (link_info
->relocatable
3608 || ((sec
->flags
& (SEC_CODE
| SEC_RELOC
| SEC_ALLOC
))
3609 != (SEC_CODE
| SEC_RELOC
| SEC_ALLOC
))
3610 || sec
->reloc_count
== 0)
3613 /* Make sure our GOT and PLT tables are up-to-date. */
3614 if (alpha_elf_hash_table(link_info
)->relax_trip
!= link_info
->relax_trip
)
3616 alpha_elf_hash_table(link_info
)->relax_trip
= link_info
->relax_trip
;
3618 /* This should never fail after the initial round, since the only
3619 error is GOT overflow, and relaxation only shrinks the table. */
3620 if (!elf64_alpha_size_got_sections (link_info
))
3622 if (elf_hash_table (link_info
)->dynamic_sections_created
)
3624 elf64_alpha_size_plt_section (link_info
);
3625 elf64_alpha_size_rela_got_section (link_info
);
3629 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3630 local_got_entries
= alpha_elf_tdata(abfd
)->local_got_entries
;
3632 /* Load the relocations for this section. */
3633 internal_relocs
= (_bfd_elf_link_read_relocs
3634 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
3635 link_info
->keep_memory
));
3636 if (internal_relocs
== NULL
)
3639 memset(&info
, 0, sizeof (info
));
3642 info
.link_info
= link_info
;
3643 info
.symtab_hdr
= symtab_hdr
;
3644 info
.relocs
= internal_relocs
;
3645 info
.relend
= irelend
= internal_relocs
+ sec
->reloc_count
;
3647 /* Find the GP for this object. Do not store the result back via
3648 _bfd_set_gp_value, since this could change again before final. */
3649 info
.gotobj
= alpha_elf_tdata (abfd
)->gotobj
;
3652 asection
*sgot
= alpha_elf_tdata (info
.gotobj
)->got
;
3653 info
.gp
= (sgot
->output_section
->vma
3654 + sgot
->output_offset
3658 /* Get the section contents. */
3659 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
3660 info
.contents
= elf_section_data (sec
)->this_hdr
.contents
;
3663 if (!bfd_malloc_and_get_section (abfd
, sec
, &info
.contents
))
3667 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3670 struct alpha_elf_got_entry
*gotent
;
3671 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
3672 unsigned long r_symndx
= ELF64_R_SYM (irel
->r_info
);
3674 /* Early exit for unhandled or unrelaxable relocations. */
3677 case R_ALPHA_LITERAL
:
3678 case R_ALPHA_GPRELHIGH
:
3679 case R_ALPHA_GPRELLOW
:
3680 case R_ALPHA_GOTDTPREL
:
3681 case R_ALPHA_GOTTPREL
:
3685 case R_ALPHA_TLSLDM
:
3686 /* The symbol for a TLSLDM reloc is ignored. Collapse the
3687 reloc to the 0 symbol so that they all match. */
3695 /* Get the value of the symbol referred to by the reloc. */
3696 if (r_symndx
< symtab_hdr
->sh_info
)
3698 /* A local symbol. */
3699 Elf_Internal_Sym
*isym
;
3701 /* Read this BFD's local symbols. */
3702 if (isymbuf
== NULL
)
3704 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3705 if (isymbuf
== NULL
)
3706 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
3707 symtab_hdr
->sh_info
, 0,
3709 if (isymbuf
== NULL
)
3713 isym
= isymbuf
+ r_symndx
;
3715 /* Given the symbol for a TLSLDM reloc is ignored, this also
3716 means forcing the symbol value to the tp base. */
3717 if (r_type
== R_ALPHA_TLSLDM
)
3719 info
.tsec
= bfd_abs_section_ptr
;
3720 symval
= alpha_get_tprel_base (info
.link_info
);
3724 symval
= isym
->st_value
;
3725 if (isym
->st_shndx
== SHN_UNDEF
)
3727 else if (isym
->st_shndx
== SHN_ABS
)
3728 info
.tsec
= bfd_abs_section_ptr
;
3729 else if (isym
->st_shndx
== SHN_COMMON
)
3730 info
.tsec
= bfd_com_section_ptr
;
3732 info
.tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3736 info
.other
= isym
->st_other
;
3737 if (local_got_entries
)
3738 info
.first_gotent
= &local_got_entries
[r_symndx
];
3741 info
.first_gotent
= &info
.gotent
;
3748 struct alpha_elf_link_hash_entry
*h
;
3750 indx
= r_symndx
- symtab_hdr
->sh_info
;
3751 h
= alpha_elf_sym_hashes (abfd
)[indx
];
3752 BFD_ASSERT (h
!= NULL
);
3754 while (h
->root
.root
.type
== bfd_link_hash_indirect
3755 || h
->root
.root
.type
== bfd_link_hash_warning
)
3756 h
= (struct alpha_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
3758 /* If the symbol is undefined, we can't do anything with it. */
3759 if (h
->root
.root
.type
== bfd_link_hash_undefined
)
3762 /* If the symbol isn't defined in the current module,
3763 again we can't do anything. */
3764 if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
3766 info
.tsec
= bfd_abs_section_ptr
;
3769 else if (!h
->root
.def_regular
)
3771 /* Except for TLSGD relocs, which can sometimes be
3772 relaxed to GOTTPREL relocs. */
3773 if (r_type
!= R_ALPHA_TLSGD
)
3775 info
.tsec
= bfd_abs_section_ptr
;
3780 info
.tsec
= h
->root
.root
.u
.def
.section
;
3781 symval
= h
->root
.root
.u
.def
.value
;
3785 info
.other
= h
->root
.other
;
3786 info
.first_gotent
= &h
->got_entries
;
3789 /* Search for the got entry to be used by this relocation. */
3790 for (gotent
= *info
.first_gotent
; gotent
; gotent
= gotent
->next
)
3791 if (gotent
->gotobj
== info
.gotobj
3792 && gotent
->reloc_type
== r_type
3793 && gotent
->addend
== irel
->r_addend
)
3795 info
.gotent
= gotent
;
3797 symval
+= info
.tsec
->output_section
->vma
+ info
.tsec
->output_offset
;
3798 symval
+= irel
->r_addend
;
3802 case R_ALPHA_LITERAL
:
3803 BFD_ASSERT(info
.gotent
!= NULL
);
3805 /* If there exist LITUSE relocations immediately following, this
3806 opens up all sorts of interesting optimizations, because we
3807 now know every location that this address load is used. */
3808 if (irel
+1 < irelend
3809 && ELF64_R_TYPE (irel
[1].r_info
) == R_ALPHA_LITUSE
)
3811 if (!elf64_alpha_relax_with_lituse (&info
, symval
, irel
))
3816 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
3821 case R_ALPHA_GOTDTPREL
:
3822 case R_ALPHA_GOTTPREL
:
3823 BFD_ASSERT(info
.gotent
!= NULL
);
3824 if (!elf64_alpha_relax_got_load (&info
, symval
, irel
, r_type
))
3829 case R_ALPHA_TLSLDM
:
3830 BFD_ASSERT(info
.gotent
!= NULL
);
3831 if (!elf64_alpha_relax_tls_get_addr (&info
, symval
, irel
,
3832 r_type
== R_ALPHA_TLSGD
))
3839 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3841 if (!link_info
->keep_memory
)
3845 /* Cache the symbols for elf_link_input_bfd. */
3846 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3850 if (info
.contents
!= NULL
3851 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
3853 if (!info
.changed_contents
&& !link_info
->keep_memory
)
3854 free (info
.contents
);
3857 /* Cache the section contents for elf_link_input_bfd. */
3858 elf_section_data (sec
)->this_hdr
.contents
= info
.contents
;
3862 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
3864 if (!info
.changed_relocs
)
3865 free (internal_relocs
);
3867 elf_section_data (sec
)->relocs
= internal_relocs
;
3870 *again
= info
.changed_contents
|| info
.changed_relocs
;
3876 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3878 if (info
.contents
!= NULL
3879 && elf_section_data (sec
)->this_hdr
.contents
!= info
.contents
)
3880 free (info
.contents
);
3881 if (internal_relocs
!= NULL
3882 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3883 free (internal_relocs
);
3887 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET)
3888 into the next available slot in SREL. */
3891 elf64_alpha_emit_dynrel (bfd
*abfd
, struct bfd_link_info
*info
,
3892 asection
*sec
, asection
*srel
, bfd_vma offset
,
3893 long dynindx
, long rtype
, bfd_vma addend
)
3895 Elf_Internal_Rela outrel
;
3898 BFD_ASSERT (srel
!= NULL
);
3900 outrel
.r_info
= ELF64_R_INFO (dynindx
, rtype
);
3901 outrel
.r_addend
= addend
;
3903 offset
= _bfd_elf_section_offset (abfd
, info
, sec
, offset
);
3904 if ((offset
| 1) != (bfd_vma
) -1)
3905 outrel
.r_offset
= sec
->output_section
->vma
+ sec
->output_offset
+ offset
;
3907 memset (&outrel
, 0, sizeof (outrel
));
3909 loc
= srel
->contents
;
3910 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
3911 bfd_elf64_swap_reloca_out (abfd
, &outrel
, loc
);
3912 BFD_ASSERT (sizeof (Elf64_External_Rela
) * srel
->reloc_count
<= srel
->size
);
3915 /* Relocate an Alpha ELF section for a relocatable link.
3917 We don't have to change anything unless the reloc is against a section
3918 symbol, in which case we have to adjust according to where the section
3919 symbol winds up in the output section. */
3922 elf64_alpha_relocate_section_r (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3923 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3924 bfd
*input_bfd
, asection
*input_section
,
3925 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3926 Elf_Internal_Rela
*relocs
,
3927 Elf_Internal_Sym
*local_syms
,
3928 asection
**local_sections
)
3930 unsigned long symtab_hdr_sh_info
;
3931 Elf_Internal_Rela
*rel
;
3932 Elf_Internal_Rela
*relend
;
3933 struct elf_link_hash_entry
**sym_hashes
;
3934 bfd_boolean ret_val
= TRUE
;
3936 symtab_hdr_sh_info
= elf_tdata (input_bfd
)->symtab_hdr
.sh_info
;
3937 sym_hashes
= elf_sym_hashes (input_bfd
);
3939 relend
= relocs
+ input_section
->reloc_count
;
3940 for (rel
= relocs
; rel
< relend
; rel
++)
3942 unsigned long r_symndx
;
3943 Elf_Internal_Sym
*sym
;
3945 unsigned long r_type
;
3947 r_type
= ELF64_R_TYPE (rel
->r_info
);
3948 if (r_type
>= R_ALPHA_max
)
3950 (*_bfd_error_handler
)
3951 (_("%B: unknown relocation type %d"),
3952 input_bfd
, (int) r_type
);
3953 bfd_set_error (bfd_error_bad_value
);
3958 /* The symbol associated with GPDISP and LITUSE is
3959 immaterial. Only the addend is significant. */
3960 if (r_type
== R_ALPHA_GPDISP
|| r_type
== R_ALPHA_LITUSE
)
3963 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3964 if (r_symndx
< symtab_hdr_sh_info
)
3966 sym
= local_syms
+ r_symndx
;
3967 sec
= local_sections
[r_symndx
];
3971 struct elf_link_hash_entry
*h
;
3973 h
= sym_hashes
[r_symndx
- symtab_hdr_sh_info
];
3975 while (h
->root
.type
== bfd_link_hash_indirect
3976 || h
->root
.type
== bfd_link_hash_warning
)
3977 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3979 if (h
->root
.type
!= bfd_link_hash_defined
3980 && h
->root
.type
!= bfd_link_hash_defweak
)
3984 sec
= h
->root
.u
.def
.section
;
3987 if (sec
!= NULL
&& elf_discarded_section (sec
))
3989 /* For relocs against symbols from removed linkonce sections,
3990 or sections discarded by a linker script, we just want the
3991 section contents zeroed. */
3992 _bfd_clear_contents (elf64_alpha_howto_table
+ r_type
,
3993 input_bfd
, contents
+ rel
->r_offset
);
3999 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4000 rel
->r_addend
+= sec
->output_offset
;
4006 /* Relocate an Alpha ELF section. */
4009 elf64_alpha_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
4010 bfd
*input_bfd
, asection
*input_section
,
4011 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
4012 Elf_Internal_Sym
*local_syms
,
4013 asection
**local_sections
)
4015 Elf_Internal_Shdr
*symtab_hdr
;
4016 Elf_Internal_Rela
*rel
;
4017 Elf_Internal_Rela
*relend
;
4018 asection
*sgot
, *srel
, *srelgot
;
4019 bfd
*dynobj
, *gotobj
;
4020 bfd_vma gp
, tp_base
, dtp_base
;
4021 struct alpha_elf_got_entry
**local_got_entries
;
4022 bfd_boolean ret_val
;
4024 /* Handle relocatable links with a smaller loop. */
4025 if (info
->relocatable
)
4026 return elf64_alpha_relocate_section_r (output_bfd
, info
, input_bfd
,
4027 input_section
, contents
, relocs
,
4028 local_syms
, local_sections
);
4030 /* This is a final link. */
4034 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4036 dynobj
= elf_hash_table (info
)->dynobj
;
4038 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
4042 if (input_section
->flags
& SEC_ALLOC
)
4044 const char *section_name
;
4045 section_name
= (bfd_elf_string_from_elf_section
4046 (input_bfd
, elf_elfheader(input_bfd
)->e_shstrndx
,
4047 elf_section_data(input_section
)->rel_hdr
.sh_name
));
4048 BFD_ASSERT(section_name
!= NULL
);
4049 srel
= bfd_get_section_by_name (dynobj
, section_name
);
4054 /* Find the gp value for this input bfd. */
4055 gotobj
= alpha_elf_tdata (input_bfd
)->gotobj
;
4058 sgot
= alpha_elf_tdata (gotobj
)->got
;
4059 gp
= _bfd_get_gp_value (gotobj
);
4062 gp
= (sgot
->output_section
->vma
4063 + sgot
->output_offset
4065 _bfd_set_gp_value (gotobj
, gp
);
4074 local_got_entries
= alpha_elf_tdata(input_bfd
)->local_got_entries
;
4076 if (elf_hash_table (info
)->tls_sec
!= NULL
)
4078 dtp_base
= alpha_get_dtprel_base (info
);
4079 tp_base
= alpha_get_tprel_base (info
);
4082 dtp_base
= tp_base
= 0;
4084 relend
= relocs
+ input_section
->reloc_count
;
4085 for (rel
= relocs
; rel
< relend
; rel
++)
4087 struct alpha_elf_link_hash_entry
*h
= NULL
;
4088 struct alpha_elf_got_entry
*gotent
;
4089 bfd_reloc_status_type r
;
4090 reloc_howto_type
*howto
;
4091 unsigned long r_symndx
;
4092 Elf_Internal_Sym
*sym
= NULL
;
4093 asection
*sec
= NULL
;
4096 bfd_boolean dynamic_symbol_p
;
4097 bfd_boolean undef_weak_ref
= FALSE
;
4098 unsigned long r_type
;
4100 r_type
= ELF64_R_TYPE(rel
->r_info
);
4101 if (r_type
>= R_ALPHA_max
)
4103 (*_bfd_error_handler
)
4104 (_("%B: unknown relocation type %d"),
4105 input_bfd
, (int) r_type
);
4106 bfd_set_error (bfd_error_bad_value
);
4111 howto
= elf64_alpha_howto_table
+ r_type
;
4112 r_symndx
= ELF64_R_SYM(rel
->r_info
);
4114 /* The symbol for a TLSLDM reloc is ignored. Collapse the
4115 reloc to the 0 symbol so that they all match. */
4116 if (r_type
== R_ALPHA_TLSLDM
)
4119 if (r_symndx
< symtab_hdr
->sh_info
)
4122 sym
= local_syms
+ r_symndx
;
4123 sec
= local_sections
[r_symndx
];
4125 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &msec
, rel
);
4127 /* If this is a tp-relative relocation against sym 0,
4128 this is hackery from relax_section. Force the value to
4129 be the tls module base. */
4131 && (r_type
== R_ALPHA_TLSLDM
4132 || r_type
== R_ALPHA_GOTTPREL
4133 || r_type
== R_ALPHA_TPREL64
4134 || r_type
== R_ALPHA_TPRELHI
4135 || r_type
== R_ALPHA_TPRELLO
4136 || r_type
== R_ALPHA_TPREL16
))
4139 if (local_got_entries
)
4140 gotent
= local_got_entries
[r_symndx
];
4144 /* Need to adjust local GOT entries' addends for SEC_MERGE
4145 unless it has been done already. */
4146 if ((sec
->flags
& SEC_MERGE
)
4147 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
4148 && sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
4150 && !gotent
->reloc_xlated
)
4152 struct alpha_elf_got_entry
*ent
;
4154 for (ent
= gotent
; ent
; ent
= ent
->next
)
4156 ent
->reloc_xlated
= 1;
4157 if (ent
->use_count
== 0)
4161 _bfd_merged_section_offset (output_bfd
, &msec
,
4162 elf_section_data (sec
)->
4164 sym
->st_value
+ ent
->addend
);
4165 ent
->addend
-= sym
->st_value
;
4166 ent
->addend
+= msec
->output_section
->vma
4167 + msec
->output_offset
4168 - sec
->output_section
->vma
4169 - sec
->output_offset
;
4173 dynamic_symbol_p
= FALSE
;
4178 bfd_boolean unresolved_reloc
;
4179 struct elf_link_hash_entry
*hh
;
4180 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
4182 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4183 r_symndx
, symtab_hdr
, sym_hashes
,
4185 unresolved_reloc
, warned
);
4191 && ! unresolved_reloc
4192 && hh
->root
.type
== bfd_link_hash_undefweak
)
4193 undef_weak_ref
= TRUE
;
4195 h
= (struct alpha_elf_link_hash_entry
*) hh
;
4196 dynamic_symbol_p
= alpha_elf_dynamic_symbol_p (&h
->root
, info
);
4197 gotent
= h
->got_entries
;
4200 if (sec
!= NULL
&& elf_discarded_section (sec
))
4202 /* For relocs against symbols from removed linkonce sections,
4203 or sections discarded by a linker script, we just want the
4204 section contents zeroed. Avoid any special processing. */
4205 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
4211 addend
= rel
->r_addend
;
4214 /* Search for the proper got entry. */
4215 for (; gotent
; gotent
= gotent
->next
)
4216 if (gotent
->gotobj
== gotobj
4217 && gotent
->reloc_type
== r_type
4218 && gotent
->addend
== addend
)
4223 case R_ALPHA_GPDISP
:
4225 bfd_byte
*p_ldah
, *p_lda
;
4227 BFD_ASSERT(gp
!= 0);
4229 value
= (input_section
->output_section
->vma
4230 + input_section
->output_offset
4233 p_ldah
= contents
+ rel
->r_offset
;
4234 p_lda
= p_ldah
+ rel
->r_addend
;
4236 r
= elf64_alpha_do_reloc_gpdisp (input_bfd
, gp
- value
,
4241 case R_ALPHA_LITERAL
:
4242 BFD_ASSERT(sgot
!= NULL
);
4243 BFD_ASSERT(gp
!= 0);
4244 BFD_ASSERT(gotent
!= NULL
);
4245 BFD_ASSERT(gotent
->use_count
>= 1);
4247 if (!gotent
->reloc_done
)
4249 gotent
->reloc_done
= 1;
4251 bfd_put_64 (output_bfd
, value
,
4252 sgot
->contents
+ gotent
->got_offset
);
4254 /* If the symbol has been forced local, output a
4255 RELATIVE reloc, otherwise it will be handled in
4256 finish_dynamic_symbol. */
4257 if (info
->shared
&& !dynamic_symbol_p
&& !undef_weak_ref
)
4258 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4259 gotent
->got_offset
, 0,
4260 R_ALPHA_RELATIVE
, value
);
4263 value
= (sgot
->output_section
->vma
4264 + sgot
->output_offset
4265 + gotent
->got_offset
);
4269 case R_ALPHA_GPREL32
:
4270 case R_ALPHA_GPREL16
:
4271 case R_ALPHA_GPRELLOW
:
4272 if (dynamic_symbol_p
)
4274 (*_bfd_error_handler
)
4275 (_("%B: gp-relative relocation against dynamic symbol %s"),
4276 input_bfd
, h
->root
.root
.root
.string
);
4279 BFD_ASSERT(gp
!= 0);
4283 case R_ALPHA_GPRELHIGH
:
4284 if (dynamic_symbol_p
)
4286 (*_bfd_error_handler
)
4287 (_("%B: gp-relative relocation against dynamic symbol %s"),
4288 input_bfd
, h
->root
.root
.root
.string
);
4291 BFD_ASSERT(gp
!= 0);
4293 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4297 /* A call to a dynamic symbol is definitely out of range of
4298 the 16-bit displacement. Don't bother writing anything. */
4299 if (dynamic_symbol_p
)
4304 /* The regular PC-relative stuff measures from the start of
4305 the instruction rather than the end. */
4309 case R_ALPHA_BRADDR
:
4310 if (dynamic_symbol_p
)
4312 (*_bfd_error_handler
)
4313 (_("%B: pc-relative relocation against dynamic symbol %s"),
4314 input_bfd
, h
->root
.root
.root
.string
);
4317 /* The regular PC-relative stuff measures from the start of
4318 the instruction rather than the end. */
4327 /* The regular PC-relative stuff measures from the start of
4328 the instruction rather than the end. */
4331 /* The source and destination gp must be the same. Note that
4332 the source will always have an assigned gp, since we forced
4333 one in check_relocs, but that the destination may not, as
4334 it might not have had any relocations at all. Also take
4335 care not to crash if H is an undefined symbol. */
4336 if (h
!= NULL
&& sec
!= NULL
4337 && alpha_elf_tdata (sec
->owner
)->gotobj
4338 && gotobj
!= alpha_elf_tdata (sec
->owner
)->gotobj
)
4340 (*_bfd_error_handler
)
4341 (_("%B: change in gp: BRSGP %s"),
4342 input_bfd
, h
->root
.root
.root
.string
);
4346 /* The symbol should be marked either NOPV or STD_GPLOAD. */
4348 other
= h
->root
.other
;
4350 other
= sym
->st_other
;
4351 switch (other
& STO_ALPHA_STD_GPLOAD
)
4353 case STO_ALPHA_NOPV
:
4355 case STO_ALPHA_STD_GPLOAD
:
4360 name
= h
->root
.root
.root
.string
;
4363 name
= (bfd_elf_string_from_elf_section
4364 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4366 name
= _("<unknown>");
4367 else if (name
[0] == 0)
4368 name
= bfd_section_name (input_bfd
, sec
);
4370 (*_bfd_error_handler
)
4371 (_("%B: !samegp reloc against symbol without .prologue: %s"),
4380 case R_ALPHA_REFLONG
:
4381 case R_ALPHA_REFQUAD
:
4382 case R_ALPHA_DTPREL64
:
4383 case R_ALPHA_TPREL64
:
4385 long dynindx
, dyntype
= r_type
;
4388 /* Careful here to remember RELATIVE relocations for global
4389 variables for symbolic shared objects. */
4391 if (dynamic_symbol_p
)
4393 BFD_ASSERT(h
->root
.dynindx
!= -1);
4394 dynindx
= h
->root
.dynindx
;
4396 addend
= 0, value
= 0;
4398 else if (r_type
== R_ALPHA_DTPREL64
)
4400 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4404 else if (r_type
== R_ALPHA_TPREL64
)
4406 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4413 dynaddend
= value
- dtp_base
;
4415 else if (info
->shared
4417 && (input_section
->flags
& SEC_ALLOC
)
4420 if (r_type
== R_ALPHA_REFLONG
)
4422 (*_bfd_error_handler
)
4423 (_("%B: unhandled dynamic relocation against %s"),
4425 h
->root
.root
.root
.string
);
4429 dyntype
= R_ALPHA_RELATIVE
;
4435 if (input_section
->flags
& SEC_ALLOC
)
4436 elf64_alpha_emit_dynrel (output_bfd
, info
, input_section
,
4437 srel
, rel
->r_offset
, dynindx
,
4438 dyntype
, dynaddend
);
4442 case R_ALPHA_SREL16
:
4443 case R_ALPHA_SREL32
:
4444 case R_ALPHA_SREL64
:
4445 if (dynamic_symbol_p
)
4447 (*_bfd_error_handler
)
4448 (_("%B: pc-relative relocation against dynamic symbol %s"),
4449 input_bfd
, h
->root
.root
.root
.string
);
4452 else if ((info
->shared
|| info
->pie
) && undef_weak_ref
)
4454 (*_bfd_error_handler
)
4455 (_("%B: pc-relative relocation against undefined weak symbol %s"),
4456 input_bfd
, h
->root
.root
.root
.string
);
4461 /* ??? .eh_frame references to discarded sections will be smashed
4462 to relocations against SHN_UNDEF. The .eh_frame format allows
4463 NULL to be encoded as 0 in any format, so this works here. */
4465 howto
= (elf64_alpha_howto_table
4466 + (r_type
- R_ALPHA_SREL32
+ R_ALPHA_REFLONG
));
4469 case R_ALPHA_TLSLDM
:
4470 /* Ignore the symbol for the relocation. The result is always
4471 the current module. */
4472 dynamic_symbol_p
= 0;
4476 if (!gotent
->reloc_done
)
4478 gotent
->reloc_done
= 1;
4480 /* Note that the module index for the main program is 1. */
4481 bfd_put_64 (output_bfd
, !info
->shared
&& !dynamic_symbol_p
,
4482 sgot
->contents
+ gotent
->got_offset
);
4484 /* If the symbol has been forced local, output a
4485 DTPMOD64 reloc, otherwise it will be handled in
4486 finish_dynamic_symbol. */
4487 if (info
->shared
&& !dynamic_symbol_p
)
4488 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4489 gotent
->got_offset
, 0,
4490 R_ALPHA_DTPMOD64
, 0);
4492 if (dynamic_symbol_p
|| r_type
== R_ALPHA_TLSLDM
)
4496 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4499 bfd_put_64 (output_bfd
, value
,
4500 sgot
->contents
+ gotent
->got_offset
+ 8);
4503 value
= (sgot
->output_section
->vma
4504 + sgot
->output_offset
4505 + gotent
->got_offset
);
4509 case R_ALPHA_DTPRELHI
:
4510 case R_ALPHA_DTPRELLO
:
4511 case R_ALPHA_DTPREL16
:
4512 if (dynamic_symbol_p
)
4514 (*_bfd_error_handler
)
4515 (_("%B: dtp-relative relocation against dynamic symbol %s"),
4516 input_bfd
, h
->root
.root
.root
.string
);
4519 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4521 if (r_type
== R_ALPHA_DTPRELHI
)
4522 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4525 case R_ALPHA_TPRELHI
:
4526 case R_ALPHA_TPRELLO
:
4527 case R_ALPHA_TPREL16
:
4530 (*_bfd_error_handler
)
4531 (_("%B: TLS local exec code cannot be linked into shared objects"),
4535 else if (dynamic_symbol_p
)
4537 (*_bfd_error_handler
)
4538 (_("%B: tp-relative relocation against dynamic symbol %s"),
4539 input_bfd
, h
->root
.root
.root
.string
);
4542 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4544 if (r_type
== R_ALPHA_TPRELHI
)
4545 value
= ((bfd_signed_vma
) value
>> 16) + ((value
>> 15) & 1);
4548 case R_ALPHA_GOTDTPREL
:
4549 case R_ALPHA_GOTTPREL
:
4550 BFD_ASSERT(sgot
!= NULL
);
4551 BFD_ASSERT(gp
!= 0);
4552 BFD_ASSERT(gotent
!= NULL
);
4553 BFD_ASSERT(gotent
->use_count
>= 1);
4555 if (!gotent
->reloc_done
)
4557 gotent
->reloc_done
= 1;
4559 if (dynamic_symbol_p
)
4563 BFD_ASSERT (elf_hash_table (info
)->tls_sec
!= NULL
);
4564 if (r_type
== R_ALPHA_GOTDTPREL
)
4566 else if (!info
->shared
)
4570 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srelgot
,
4571 gotent
->got_offset
, 0,
4577 bfd_put_64 (output_bfd
, value
,
4578 sgot
->contents
+ gotent
->got_offset
);
4581 value
= (sgot
->output_section
->vma
4582 + sgot
->output_offset
4583 + gotent
->got_offset
);
4589 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4590 contents
, rel
->r_offset
, value
, 0);
4599 case bfd_reloc_overflow
:
4603 /* Don't warn if the overflow is due to pc relative reloc
4604 against discarded section. Section optimization code should
4607 if (r_symndx
< symtab_hdr
->sh_info
4608 && sec
!= NULL
&& howto
->pc_relative
4609 && elf_discarded_section (sec
))
4616 name
= (bfd_elf_string_from_elf_section
4617 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4621 name
= bfd_section_name (input_bfd
, sec
);
4623 if (! ((*info
->callbacks
->reloc_overflow
)
4624 (info
, (h
? &h
->root
.root
: NULL
), name
, howto
->name
,
4625 (bfd_vma
) 0, input_bfd
, input_section
,
4632 case bfd_reloc_outofrange
:
4640 /* Finish up dynamic symbol handling. We set the contents of various
4641 dynamic sections here. */
4644 elf64_alpha_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
4645 struct elf_link_hash_entry
*h
,
4646 Elf_Internal_Sym
*sym
)
4648 struct alpha_elf_link_hash_entry
*ah
= (struct alpha_elf_link_hash_entry
*)h
;
4649 bfd
*dynobj
= elf_hash_table(info
)->dynobj
;
4653 /* Fill in the .plt entry for this symbol. */
4654 asection
*splt
, *sgot
, *srel
;
4655 Elf_Internal_Rela outrel
;
4657 bfd_vma got_addr
, plt_addr
;
4659 struct alpha_elf_got_entry
*gotent
;
4661 BFD_ASSERT (h
->dynindx
!= -1);
4663 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4664 BFD_ASSERT (splt
!= NULL
);
4665 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4666 BFD_ASSERT (srel
!= NULL
);
4668 for (gotent
= ah
->got_entries
; gotent
; gotent
= gotent
->next
)
4669 if (gotent
->reloc_type
== R_ALPHA_LITERAL
4670 && gotent
->use_count
> 0)
4675 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4676 BFD_ASSERT (sgot
!= NULL
);
4678 BFD_ASSERT (gotent
->got_offset
!= -1);
4679 BFD_ASSERT (gotent
->plt_offset
!= -1);
4681 got_addr
= (sgot
->output_section
->vma
4682 + sgot
->output_offset
4683 + gotent
->got_offset
);
4684 plt_addr
= (splt
->output_section
->vma
4685 + splt
->output_offset
4686 + gotent
->plt_offset
);
4688 plt_index
= (gotent
->plt_offset
-PLT_HEADER_SIZE
) / PLT_ENTRY_SIZE
;
4690 /* Fill in the entry in the procedure linkage table. */
4691 if (elf64_alpha_use_secureplt
)
4693 disp
= (PLT_HEADER_SIZE
- 4) - (gotent
->plt_offset
+ 4);
4694 insn
= INSN_AD (INSN_BR
, 31, disp
);
4695 bfd_put_32 (output_bfd
, insn
,
4696 splt
->contents
+ gotent
->plt_offset
);
4698 plt_index
= ((gotent
->plt_offset
- NEW_PLT_HEADER_SIZE
)
4699 / NEW_PLT_ENTRY_SIZE
);
4703 disp
= -(gotent
->plt_offset
+ 4);
4704 insn
= INSN_AD (INSN_BR
, 28, disp
);
4705 bfd_put_32 (output_bfd
, insn
,
4706 splt
->contents
+ gotent
->plt_offset
);
4707 bfd_put_32 (output_bfd
, INSN_UNOP
,
4708 splt
->contents
+ gotent
->plt_offset
+ 4);
4709 bfd_put_32 (output_bfd
, INSN_UNOP
,
4710 splt
->contents
+ gotent
->plt_offset
+ 8);
4712 plt_index
= ((gotent
->plt_offset
- OLD_PLT_HEADER_SIZE
)
4713 / OLD_PLT_ENTRY_SIZE
);
4716 /* Fill in the entry in the .rela.plt section. */
4717 outrel
.r_offset
= got_addr
;
4718 outrel
.r_info
= ELF64_R_INFO(h
->dynindx
, R_ALPHA_JMP_SLOT
);
4719 outrel
.r_addend
= 0;
4721 loc
= srel
->contents
+ plt_index
* sizeof (Elf64_External_Rela
);
4722 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
4724 /* Fill in the entry in the .got. */
4725 bfd_put_64 (output_bfd
, plt_addr
,
4726 sgot
->contents
+ gotent
->got_offset
);
4729 else if (alpha_elf_dynamic_symbol_p (h
, info
))
4731 /* Fill in the dynamic relocations for this symbol's .got entries. */
4733 struct alpha_elf_got_entry
*gotent
;
4735 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4736 BFD_ASSERT (srel
!= NULL
);
4738 for (gotent
= ((struct alpha_elf_link_hash_entry
*) h
)->got_entries
;
4740 gotent
= gotent
->next
)
4745 if (gotent
->use_count
== 0)
4748 sgot
= alpha_elf_tdata (gotent
->gotobj
)->got
;
4750 r_type
= gotent
->reloc_type
;
4753 case R_ALPHA_LITERAL
:
4754 r_type
= R_ALPHA_GLOB_DAT
;
4757 r_type
= R_ALPHA_DTPMOD64
;
4759 case R_ALPHA_GOTDTPREL
:
4760 r_type
= R_ALPHA_DTPREL64
;
4762 case R_ALPHA_GOTTPREL
:
4763 r_type
= R_ALPHA_TPREL64
;
4765 case R_ALPHA_TLSLDM
:
4770 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4771 gotent
->got_offset
, h
->dynindx
,
4772 r_type
, gotent
->addend
);
4774 if (gotent
->reloc_type
== R_ALPHA_TLSGD
)
4775 elf64_alpha_emit_dynrel (output_bfd
, info
, sgot
, srel
,
4776 gotent
->got_offset
+ 8, h
->dynindx
,
4777 R_ALPHA_DTPREL64
, gotent
->addend
);
4781 /* Mark some specially defined symbols as absolute. */
4782 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4783 || h
== elf_hash_table (info
)->hgot
4784 || h
== elf_hash_table (info
)->hplt
)
4785 sym
->st_shndx
= SHN_ABS
;
4790 /* Finish up the dynamic sections. */
4793 elf64_alpha_finish_dynamic_sections (bfd
*output_bfd
,
4794 struct bfd_link_info
*info
)
4799 dynobj
= elf_hash_table (info
)->dynobj
;
4800 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4802 if (elf_hash_table (info
)->dynamic_sections_created
)
4804 asection
*splt
, *sgotplt
, *srelaplt
;
4805 Elf64_External_Dyn
*dyncon
, *dynconend
;
4806 bfd_vma plt_vma
, gotplt_vma
;
4808 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4809 srelaplt
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4810 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
4812 plt_vma
= splt
->output_section
->vma
+ splt
->output_offset
;
4815 if (elf64_alpha_use_secureplt
)
4817 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
4818 BFD_ASSERT (sgotplt
!= NULL
);
4819 if (sgotplt
->size
> 0)
4820 gotplt_vma
= sgotplt
->output_section
->vma
+ sgotplt
->output_offset
;
4823 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4824 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4825 for (; dyncon
< dynconend
; dyncon
++)
4827 Elf_Internal_Dyn dyn
;
4829 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4835 = elf64_alpha_use_secureplt
? gotplt_vma
: plt_vma
;
4838 dyn
.d_un
.d_val
= srelaplt
? srelaplt
->size
: 0;
4841 dyn
.d_un
.d_ptr
= srelaplt
? srelaplt
->vma
: 0;
4845 /* My interpretation of the TIS v1.1 ELF document indicates
4846 that RELASZ should not include JMPREL. This is not what
4847 the rest of the BFD does. It is, however, what the
4848 glibc ld.so wants. Do this fixup here until we found
4849 out who is right. */
4851 dyn
.d_un
.d_val
-= srelaplt
->size
;
4855 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4858 /* Initialize the plt header. */
4864 if (elf64_alpha_use_secureplt
)
4866 ofs
= gotplt_vma
- (plt_vma
+ PLT_HEADER_SIZE
);
4868 insn
= INSN_ABC (INSN_SUBQ
, 27, 28, 25);
4869 bfd_put_32 (output_bfd
, insn
, splt
->contents
);
4871 insn
= INSN_ABO (INSN_LDAH
, 28, 28, (ofs
+ 0x8000) >> 16);
4872 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 4);
4874 insn
= INSN_ABC (INSN_S4SUBQ
, 25, 25, 25);
4875 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 8);
4877 insn
= INSN_ABO (INSN_LDA
, 28, 28, ofs
);
4878 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 12);
4880 insn
= INSN_ABO (INSN_LDQ
, 27, 28, 0);
4881 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 16);
4883 insn
= INSN_ABC (INSN_ADDQ
, 25, 25, 25);
4884 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 20);
4886 insn
= INSN_ABO (INSN_LDQ
, 28, 28, 8);
4887 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 24);
4889 insn
= INSN_AB (INSN_JMP
, 31, 27);
4890 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 28);
4892 insn
= INSN_AD (INSN_BR
, 28, -PLT_HEADER_SIZE
);
4893 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 32);
4897 insn
= INSN_AD (INSN_BR
, 27, 0); /* br $27, .+4 */
4898 bfd_put_32 (output_bfd
, insn
, splt
->contents
);
4900 insn
= INSN_ABO (INSN_LDQ
, 27, 27, 12);
4901 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 4);
4904 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 8);
4906 insn
= INSN_AB (INSN_JMP
, 27, 27);
4907 bfd_put_32 (output_bfd
, insn
, splt
->contents
+ 12);
4909 /* The next two words will be filled in by ld.so. */
4910 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 16);
4911 bfd_put_64 (output_bfd
, 0, splt
->contents
+ 24);
4914 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 0;
4921 /* We need to use a special link routine to handle the .mdebug section.
4922 We need to merge all instances of these sections together, not write
4923 them all out sequentially. */
4926 elf64_alpha_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
4929 struct bfd_link_order
*p
;
4930 asection
*mdebug_sec
;
4931 struct ecoff_debug_info debug
;
4932 const struct ecoff_debug_swap
*swap
4933 = get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
4934 HDRR
*symhdr
= &debug
.symbolic_header
;
4935 PTR mdebug_handle
= NULL
;
4937 /* Go through the sections and collect the mdebug information. */
4939 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4941 if (strcmp (o
->name
, ".mdebug") == 0)
4943 struct extsym_info einfo
;
4945 /* We have found the .mdebug section in the output file.
4946 Look through all the link_orders comprising it and merge
4947 the information together. */
4948 symhdr
->magic
= swap
->sym_magic
;
4949 /* FIXME: What should the version stamp be? */
4951 symhdr
->ilineMax
= 0;
4955 symhdr
->isymMax
= 0;
4956 symhdr
->ioptMax
= 0;
4957 symhdr
->iauxMax
= 0;
4959 symhdr
->issExtMax
= 0;
4962 symhdr
->iextMax
= 0;
4964 /* We accumulate the debugging information itself in the
4965 debug_info structure. */
4967 debug
.external_dnr
= NULL
;
4968 debug
.external_pdr
= NULL
;
4969 debug
.external_sym
= NULL
;
4970 debug
.external_opt
= NULL
;
4971 debug
.external_aux
= NULL
;
4973 debug
.ssext
= debug
.ssext_end
= NULL
;
4974 debug
.external_fdr
= NULL
;
4975 debug
.external_rfd
= NULL
;
4976 debug
.external_ext
= debug
.external_ext_end
= NULL
;
4978 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
4979 if (mdebug_handle
== (PTR
) NULL
)
4988 static const char * const name
[] =
4990 ".text", ".init", ".fini", ".data",
4991 ".rodata", ".sdata", ".sbss", ".bss"
4993 static const int sc
[] = { scText
, scInit
, scFini
, scData
,
4994 scRData
, scSData
, scSBss
, scBss
};
4997 esym
.cobol_main
= 0;
5001 esym
.asym
.iss
= issNil
;
5002 esym
.asym
.st
= stLocal
;
5003 esym
.asym
.reserved
= 0;
5004 esym
.asym
.index
= indexNil
;
5005 for (i
= 0; i
< 8; i
++)
5007 esym
.asym
.sc
= sc
[i
];
5008 s
= bfd_get_section_by_name (abfd
, name
[i
]);
5011 esym
.asym
.value
= s
->vma
;
5012 last
= s
->vma
+ s
->size
;
5015 esym
.asym
.value
= last
;
5017 if (! bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
5023 for (p
= o
->map_head
.link_order
;
5024 p
!= (struct bfd_link_order
*) NULL
;
5027 asection
*input_section
;
5029 const struct ecoff_debug_swap
*input_swap
;
5030 struct ecoff_debug_info input_debug
;
5034 if (p
->type
!= bfd_indirect_link_order
)
5036 if (p
->type
== bfd_data_link_order
)
5041 input_section
= p
->u
.indirect
.section
;
5042 input_bfd
= input_section
->owner
;
5044 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
5045 || (get_elf_backend_data (input_bfd
)
5046 ->elf_backend_ecoff_debug_swap
) == NULL
)
5048 /* I don't know what a non ALPHA ELF bfd would be
5049 doing with a .mdebug section, but I don't really
5050 want to deal with it. */
5054 input_swap
= (get_elf_backend_data (input_bfd
)
5055 ->elf_backend_ecoff_debug_swap
);
5057 BFD_ASSERT (p
->size
== input_section
->size
);
5059 /* The ECOFF linking code expects that we have already
5060 read in the debugging information and set up an
5061 ecoff_debug_info structure, so we do that now. */
5062 if (!elf64_alpha_read_ecoff_info (input_bfd
, input_section
,
5066 if (! (bfd_ecoff_debug_accumulate
5067 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
5068 &input_debug
, input_swap
, info
)))
5071 /* Loop through the external symbols. For each one with
5072 interesting information, try to find the symbol in
5073 the linker global hash table and save the information
5074 for the output external symbols. */
5075 eraw_src
= input_debug
.external_ext
;
5076 eraw_end
= (eraw_src
5077 + (input_debug
.symbolic_header
.iextMax
5078 * input_swap
->external_ext_size
));
5080 eraw_src
< eraw_end
;
5081 eraw_src
+= input_swap
->external_ext_size
)
5085 struct alpha_elf_link_hash_entry
*h
;
5087 (*input_swap
->swap_ext_in
) (input_bfd
, (PTR
) eraw_src
, &ext
);
5088 if (ext
.asym
.sc
== scNil
5089 || ext
.asym
.sc
== scUndefined
5090 || ext
.asym
.sc
== scSUndefined
)
5093 name
= input_debug
.ssext
+ ext
.asym
.iss
;
5094 h
= alpha_elf_link_hash_lookup (alpha_elf_hash_table (info
),
5095 name
, FALSE
, FALSE
, TRUE
);
5096 if (h
== NULL
|| h
->esym
.ifd
!= -2)
5102 < input_debug
.symbolic_header
.ifdMax
);
5103 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
5109 /* Free up the information we just read. */
5110 free (input_debug
.line
);
5111 free (input_debug
.external_dnr
);
5112 free (input_debug
.external_pdr
);
5113 free (input_debug
.external_sym
);
5114 free (input_debug
.external_opt
);
5115 free (input_debug
.external_aux
);
5116 free (input_debug
.ss
);
5117 free (input_debug
.ssext
);
5118 free (input_debug
.external_fdr
);
5119 free (input_debug
.external_rfd
);
5120 free (input_debug
.external_ext
);
5122 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5123 elf_link_input_bfd ignores this section. */
5124 input_section
->flags
&=~ SEC_HAS_CONTENTS
;
5127 /* Build the external symbol information. */
5130 einfo
.debug
= &debug
;
5132 einfo
.failed
= FALSE
;
5133 elf_link_hash_traverse (elf_hash_table (info
),
5134 elf64_alpha_output_extsym
,
5139 /* Set the size of the .mdebug section. */
5140 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
5142 /* Skip this section later on (I don't think this currently
5143 matters, but someday it might). */
5144 o
->map_head
.link_order
= (struct bfd_link_order
*) NULL
;
5150 /* Invoke the regular ELF backend linker to do all the work. */
5151 if (! bfd_elf_final_link (abfd
, info
))
5154 /* Now write out the computed sections. */
5156 /* The .got subsections... */
5158 bfd
*i
, *dynobj
= elf_hash_table(info
)->dynobj
;
5159 for (i
= alpha_elf_hash_table(info
)->got_list
;
5161 i
= alpha_elf_tdata(i
)->got_link_next
)
5165 /* elf_bfd_final_link already did everything in dynobj. */
5169 sgot
= alpha_elf_tdata(i
)->got
;
5170 if (! bfd_set_section_contents (abfd
, sgot
->output_section
,
5172 (file_ptr
) sgot
->output_offset
,
5178 if (mdebug_sec
!= (asection
*) NULL
)
5180 BFD_ASSERT (abfd
->output_has_begun
);
5181 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
5183 mdebug_sec
->filepos
))
5186 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
5192 static enum elf_reloc_type_class
5193 elf64_alpha_reloc_type_class (const Elf_Internal_Rela
*rela
)
5195 switch ((int) ELF64_R_TYPE (rela
->r_info
))
5197 case R_ALPHA_RELATIVE
:
5198 return reloc_class_relative
;
5199 case R_ALPHA_JMP_SLOT
:
5200 return reloc_class_plt
;
5202 return reloc_class_copy
;
5204 return reloc_class_normal
;
5208 static const struct bfd_elf_special_section elf64_alpha_special_sections
[] =
5210 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_ALPHA_GPREL
},
5211 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_ALPHA_GPREL
},
5212 { NULL
, 0, 0, 0, 0 }
5215 /* ECOFF swapping routines. These are used when dealing with the
5216 .mdebug section, which is in the ECOFF debugging format. Copied
5217 from elf32-mips.c. */
5218 static const struct ecoff_debug_swap
5219 elf64_alpha_ecoff_debug_swap
=
5221 /* Symbol table magic number. */
5223 /* Alignment of debugging information. E.g., 4. */
5225 /* Sizes of external symbolic information. */
5226 sizeof (struct hdr_ext
),
5227 sizeof (struct dnr_ext
),
5228 sizeof (struct pdr_ext
),
5229 sizeof (struct sym_ext
),
5230 sizeof (struct opt_ext
),
5231 sizeof (struct fdr_ext
),
5232 sizeof (struct rfd_ext
),
5233 sizeof (struct ext_ext
),
5234 /* Functions to swap in external symbolic data. */
5243 _bfd_ecoff_swap_tir_in
,
5244 _bfd_ecoff_swap_rndx_in
,
5245 /* Functions to swap out external symbolic data. */
5254 _bfd_ecoff_swap_tir_out
,
5255 _bfd_ecoff_swap_rndx_out
,
5256 /* Function to read in symbolic data. */
5257 elf64_alpha_read_ecoff_info
5260 /* Use a non-standard hash bucket size of 8. */
5262 static const struct elf_size_info alpha_elf_size_info
=
5264 sizeof (Elf64_External_Ehdr
),
5265 sizeof (Elf64_External_Phdr
),
5266 sizeof (Elf64_External_Shdr
),
5267 sizeof (Elf64_External_Rel
),
5268 sizeof (Elf64_External_Rela
),
5269 sizeof (Elf64_External_Sym
),
5270 sizeof (Elf64_External_Dyn
),
5271 sizeof (Elf_External_Note
),
5275 ELFCLASS64
, EV_CURRENT
,
5276 bfd_elf64_write_out_phdrs
,
5277 bfd_elf64_write_shdrs_and_ehdr
,
5278 bfd_elf64_write_relocs
,
5279 bfd_elf64_swap_symbol_in
,
5280 bfd_elf64_swap_symbol_out
,
5281 bfd_elf64_slurp_reloc_table
,
5282 bfd_elf64_slurp_symbol_table
,
5283 bfd_elf64_swap_dyn_in
,
5284 bfd_elf64_swap_dyn_out
,
5285 bfd_elf64_swap_reloc_in
,
5286 bfd_elf64_swap_reloc_out
,
5287 bfd_elf64_swap_reloca_in
,
5288 bfd_elf64_swap_reloca_out
5291 #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec
5292 #define TARGET_LITTLE_NAME "elf64-alpha"
5293 #define ELF_ARCH bfd_arch_alpha
5294 #define ELF_MACHINE_CODE EM_ALPHA
5295 #define ELF_MAXPAGESIZE 0x10000
5296 #define ELF_COMMONPAGESIZE 0x2000
5298 #define bfd_elf64_bfd_link_hash_table_create \
5299 elf64_alpha_bfd_link_hash_table_create
5301 #define bfd_elf64_bfd_reloc_type_lookup \
5302 elf64_alpha_bfd_reloc_type_lookup
5303 #define bfd_elf64_bfd_reloc_name_lookup \
5304 elf64_alpha_bfd_reloc_name_lookup
5305 #define elf_info_to_howto \
5306 elf64_alpha_info_to_howto
5308 #define bfd_elf64_mkobject \
5309 elf64_alpha_mkobject
5310 #define elf_backend_object_p \
5311 elf64_alpha_object_p
5313 #define elf_backend_section_from_shdr \
5314 elf64_alpha_section_from_shdr
5315 #define elf_backend_section_flags \
5316 elf64_alpha_section_flags
5317 #define elf_backend_fake_sections \
5318 elf64_alpha_fake_sections
5320 #define bfd_elf64_bfd_is_local_label_name \
5321 elf64_alpha_is_local_label_name
5322 #define bfd_elf64_find_nearest_line \
5323 elf64_alpha_find_nearest_line
5324 #define bfd_elf64_bfd_relax_section \
5325 elf64_alpha_relax_section
5327 #define elf_backend_add_symbol_hook \
5328 elf64_alpha_add_symbol_hook
5329 #define elf_backend_check_relocs \
5330 elf64_alpha_check_relocs
5331 #define elf_backend_create_dynamic_sections \
5332 elf64_alpha_create_dynamic_sections
5333 #define elf_backend_adjust_dynamic_symbol \
5334 elf64_alpha_adjust_dynamic_symbol
5335 #define elf_backend_merge_symbol_attribute \
5336 elf64_alpha_merge_symbol_attribute
5337 #define elf_backend_always_size_sections \
5338 elf64_alpha_always_size_sections
5339 #define elf_backend_size_dynamic_sections \
5340 elf64_alpha_size_dynamic_sections
5341 #define elf_backend_omit_section_dynsym \
5342 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
5343 #define elf_backend_relocate_section \
5344 elf64_alpha_relocate_section
5345 #define elf_backend_finish_dynamic_symbol \
5346 elf64_alpha_finish_dynamic_symbol
5347 #define elf_backend_finish_dynamic_sections \
5348 elf64_alpha_finish_dynamic_sections
5349 #define bfd_elf64_bfd_final_link \
5350 elf64_alpha_final_link
5351 #define elf_backend_reloc_type_class \
5352 elf64_alpha_reloc_type_class
5354 #define elf_backend_ecoff_debug_swap \
5355 &elf64_alpha_ecoff_debug_swap
5357 #define elf_backend_size_info \
5360 #define elf_backend_special_sections \
5361 elf64_alpha_special_sections
5363 /* A few constants that determine how the .plt section is set up. */
5364 #define elf_backend_want_got_plt 0
5365 #define elf_backend_plt_readonly 0
5366 #define elf_backend_want_plt_sym 1
5367 #define elf_backend_got_header_size 0
5369 #include "elf64-target.h"
5371 /* FreeBSD support. */
5373 #undef TARGET_LITTLE_SYM
5374 #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec
5375 #undef TARGET_LITTLE_NAME
5376 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd"
5378 #define ELF_OSABI ELFOSABI_FREEBSD
5380 /* The kernel recognizes executables as valid only if they carry a
5381 "FreeBSD" label in the ELF header. So we put this label on all
5382 executables and (for simplicity) also all other object files. */
5385 elf64_alpha_fbsd_post_process_headers (bfd
* abfd
,
5386 struct bfd_link_info
* link_info ATTRIBUTE_UNUSED
)
5388 Elf_Internal_Ehdr
* i_ehdrp
; /* ELF file header, internal form. */
5390 i_ehdrp
= elf_elfheader (abfd
);
5392 /* Put an ABI label supported by FreeBSD >= 4.1. */
5393 i_ehdrp
->e_ident
[EI_OSABI
] = get_elf_backend_data (abfd
)->elf_osabi
;
5394 #ifdef OLD_FREEBSD_ABI_LABEL
5395 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */
5396 memcpy (&i_ehdrp
->e_ident
[EI_ABIVERSION
], "FreeBSD", 8);
5400 #undef elf_backend_post_process_headers
5401 #define elf_backend_post_process_headers \
5402 elf64_alpha_fbsd_post_process_headers
5405 #define elf64_bed elf64_alpha_fbsd_bed
5407 #include "elf64-target.h"