1 /* IA-64 support for OpenVMS
2 Copyright (C) 1998-2019 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
25 #include "opcode/ia64.h"
29 #include "elfxx-ia64.h"
33 /* THE RULES for all the stuff the linker creates --
35 GOT Entries created in response to LTOFF or LTOFF_FPTR
36 relocations. Dynamic relocs created for dynamic
37 symbols in an application; REL relocs for locals
40 FPTR The canonical function descriptor. Created for local
41 symbols in applications. Descriptors for dynamic symbols
42 and local symbols in shared libraries are created by
43 ld.so. Thus there are no dynamic relocs against these
44 objects. The FPTR relocs for such _are_ passed through
45 to the dynamic relocation tables.
47 FULL_PLT Created for a PCREL21B relocation against a dynamic symbol.
48 Requires the creation of a PLTOFF entry. This does not
49 require any dynamic relocations.
51 PLTOFF Created by PLTOFF relocations. For local symbols, this
52 is an alternate function descriptor, and in shared libraries
53 requires two REL relocations. Note that this cannot be
54 transformed into an FPTR relocation, since it must be in
55 range of the GP. For dynamic symbols, this is a function
58 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
59 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
61 /* In dynamically (linker-) created sections, we generally need to keep track
62 of the place a symbol or expression got allocated to. This is done via hash
63 tables that store entries of the following type. */
65 struct elf64_ia64_dyn_sym_info
67 /* The addend for which this entry is relevant. */
72 bfd_vma pltoff_offset
;
76 /* The symbol table entry, if any, that this was derived from. */
77 struct elf_link_hash_entry
*h
;
79 /* Used to count non-got, non-plt relocations for delayed sizing
80 of relocation sections. */
81 struct elf64_ia64_dyn_reloc_entry
83 struct elf64_ia64_dyn_reloc_entry
*next
;
89 /* TRUE when the section contents have been updated. */
90 unsigned got_done
: 1;
91 unsigned fptr_done
: 1;
92 unsigned pltoff_done
: 1;
94 /* TRUE for the different kinds of linker data we want created. */
95 unsigned want_got
: 1;
96 unsigned want_gotx
: 1;
97 unsigned want_fptr
: 1;
98 unsigned want_ltoff_fptr
: 1;
99 unsigned want_plt
: 1; /* A MIN_PLT entry. */
100 unsigned want_plt2
: 1; /* A FULL_PLT. */
101 unsigned want_pltoff
: 1;
104 struct elf64_ia64_local_hash_entry
108 /* The number of elements in elf64_ia64_dyn_sym_info array. */
110 /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */
111 unsigned int sorted_count
;
112 /* The size of elf64_ia64_dyn_sym_info array. */
114 /* The array of elf64_ia64_dyn_sym_info. */
115 struct elf64_ia64_dyn_sym_info
*info
;
117 /* TRUE if this hash entry's addends was translated for
118 SHF_MERGE optimization. */
119 unsigned sec_merge_done
: 1;
122 struct elf64_ia64_link_hash_entry
124 struct elf_link_hash_entry root
;
126 /* Set if this symbol is defined in a shared library.
127 We can't use root.u.def.section->owner as the symbol is an absolute
131 /* The number of elements in elf64_ia64_dyn_sym_info array. */
133 /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */
134 unsigned int sorted_count
;
135 /* The size of elf64_ia64_dyn_sym_info array. */
137 /* The array of elf64_ia64_dyn_sym_info. */
138 struct elf64_ia64_dyn_sym_info
*info
;
141 struct elf64_ia64_link_hash_table
143 /* The main hash table. */
144 struct elf_link_hash_table root
;
146 asection
*fptr_sec
; /* Function descriptor table (or NULL). */
147 asection
*rel_fptr_sec
; /* Dynamic relocation section for same. */
148 asection
*pltoff_sec
; /* Private descriptors for plt (or NULL). */
149 asection
*fixups_sec
; /* Fixups section. */
150 asection
*transfer_sec
; /* Transfer vector section. */
151 asection
*note_sec
; /* .note section. */
153 /* There are maybe R_IA64_GPREL22 relocations, including those
154 optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT
155 sections. We need to record those sections so that we can choose
156 a proper GP to cover all R_IA64_GPREL22 relocations. */
157 asection
*max_short_sec
; /* Maximum short output section. */
158 bfd_vma max_short_offset
; /* Maximum short offset. */
159 asection
*min_short_sec
; /* Minimum short output section. */
160 bfd_vma min_short_offset
; /* Minimum short offset. */
162 htab_t loc_hash_table
;
163 void *loc_hash_memory
;
166 struct elf64_ia64_allocate_data
168 struct bfd_link_info
*info
;
172 #define elf64_ia64_hash_table(p) \
173 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
174 == IA64_ELF_DATA ? ((struct elf64_ia64_link_hash_table *) ((p)->hash)) : NULL)
176 struct elf64_ia64_vms_obj_tdata
178 struct elf_obj_tdata root
;
180 /* Ident for shared library. */
183 /* Used only during link: offset in the .fixups section for this bfd. */
186 /* Max number of shared libraries. */
187 unsigned int needed_count
;
190 #define elf_ia64_vms_tdata(abfd) \
191 ((struct elf64_ia64_vms_obj_tdata *)((abfd)->tdata.any))
192 #define elf_ia64_vms_ident(abfd) (elf_ia64_vms_tdata(abfd)->ident)
194 struct elf64_vms_transfer
196 unsigned char size
[4];
197 unsigned char spare
[4];
198 unsigned char tfradr1
[8];
199 unsigned char tfradr2
[8];
200 unsigned char tfradr3
[8];
201 unsigned char tfradr4
[8];
202 unsigned char tfradr5
[8];
204 /* Local function descriptor for tfr3. */
205 unsigned char tfr3_func
[8];
206 unsigned char tfr3_gp
[8];
211 Elf64_External_Ehdr ehdr
;
212 unsigned char vms_needed_count
[8];
213 } Elf64_External_VMS_Ehdr
;
215 static struct elf64_ia64_dyn_sym_info
* get_dyn_sym_info
216 (struct elf64_ia64_link_hash_table
*,
217 struct elf_link_hash_entry
*,
218 bfd
*, const Elf_Internal_Rela
*, bfd_boolean
);
219 static bfd_boolean elf64_ia64_dynamic_symbol_p
220 (struct elf_link_hash_entry
*);
221 static bfd_boolean elf64_ia64_choose_gp
222 (bfd
*, struct bfd_link_info
*, bfd_boolean
);
223 static void elf64_ia64_dyn_sym_traverse
224 (struct elf64_ia64_link_hash_table
*,
225 bfd_boolean (*) (struct elf64_ia64_dyn_sym_info
*, void *),
227 static bfd_boolean allocate_global_data_got
228 (struct elf64_ia64_dyn_sym_info
*, void *);
229 static bfd_boolean allocate_global_fptr_got
230 (struct elf64_ia64_dyn_sym_info
*, void *);
231 static bfd_boolean allocate_local_got
232 (struct elf64_ia64_dyn_sym_info
*, void *);
233 static bfd_boolean allocate_dynrel_entries
234 (struct elf64_ia64_dyn_sym_info
*, void *);
235 static asection
*get_pltoff
236 (bfd
*, struct elf64_ia64_link_hash_table
*);
237 static asection
*get_got
238 (bfd
*, struct elf64_ia64_link_hash_table
*);
241 /* Given a ELF reloc, return the matching HOWTO structure. */
244 elf64_ia64_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
246 Elf_Internal_Rela
*elf_reloc
)
248 unsigned int r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
250 bfd_reloc
->howto
= ia64_elf_lookup_howto (r_type
);
251 if (bfd_reloc
->howto
== NULL
)
253 /* xgettext:c-format */
254 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
256 bfd_set_error (bfd_error_bad_value
);
264 #define PLT_FULL_ENTRY_SIZE (2 * 16)
266 static const bfd_byte plt_full_entry
[PLT_FULL_ENTRY_SIZE
] =
268 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
269 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/
270 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
271 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
272 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
273 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
276 static const bfd_byte oor_brl
[16] =
278 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;;*/
280 0x00, 0x00, 0x00, 0xc0
284 /* These functions do relaxation for IA-64 ELF. */
286 /* Rename some of the generic section flags to better document how they
288 #define skip_relax_pass_0 sec_flg0
289 #define skip_relax_pass_1 sec_flg1
292 elf64_ia64_update_short_info (asection
*sec
, bfd_vma offset
,
293 struct elf64_ia64_link_hash_table
*ia64_info
)
295 /* Skip ABS and SHF_IA_64_SHORT sections. */
296 if (sec
== bfd_abs_section_ptr
297 || (sec
->flags
& SEC_SMALL_DATA
) != 0)
300 if (!ia64_info
->min_short_sec
)
302 ia64_info
->max_short_sec
= sec
;
303 ia64_info
->max_short_offset
= offset
;
304 ia64_info
->min_short_sec
= sec
;
305 ia64_info
->min_short_offset
= offset
;
307 else if (sec
== ia64_info
->max_short_sec
308 && offset
> ia64_info
->max_short_offset
)
309 ia64_info
->max_short_offset
= offset
;
310 else if (sec
== ia64_info
->min_short_sec
311 && offset
< ia64_info
->min_short_offset
)
312 ia64_info
->min_short_offset
= offset
;
313 else if (sec
->output_section
->vma
314 > ia64_info
->max_short_sec
->vma
)
316 ia64_info
->max_short_sec
= sec
;
317 ia64_info
->max_short_offset
= offset
;
319 else if (sec
->output_section
->vma
320 < ia64_info
->min_short_sec
->vma
)
322 ia64_info
->min_short_sec
= sec
;
323 ia64_info
->min_short_offset
= offset
;
327 /* Use a two passes algorithm. In the first pass, branches are relaxed
328 (which may increase the size of the section). In the second pass,
329 the other relaxations are done.
333 elf64_ia64_relax_section (bfd
*abfd
, asection
*sec
,
334 struct bfd_link_info
*link_info
,
339 struct one_fixup
*next
;
345 Elf_Internal_Shdr
*symtab_hdr
;
346 Elf_Internal_Rela
*internal_relocs
;
347 Elf_Internal_Rela
*irel
, *irelend
;
349 Elf_Internal_Sym
*isymbuf
= NULL
;
350 struct elf64_ia64_link_hash_table
*ia64_info
;
351 struct one_fixup
*fixups
= NULL
;
352 bfd_boolean changed_contents
= FALSE
;
353 bfd_boolean changed_relocs
= FALSE
;
354 bfd_boolean skip_relax_pass_0
= TRUE
;
355 bfd_boolean skip_relax_pass_1
= TRUE
;
358 /* Assume we're not going to change any sizes, and we'll only need
362 if (bfd_link_relocatable (link_info
))
363 (*link_info
->callbacks
->einfo
)
364 (_("%P%F: --relax and -r may not be used together\n"));
366 /* Don't even try to relax for non-ELF outputs. */
367 if (!is_elf_hash_table (link_info
->hash
))
370 /* Nothing to do if there are no relocations or there is no need for
372 if ((sec
->flags
& SEC_RELOC
) == 0
373 || sec
->reloc_count
== 0
374 || (link_info
->relax_pass
== 0 && sec
->skip_relax_pass_0
)
375 || (link_info
->relax_pass
== 1 && sec
->skip_relax_pass_1
))
378 ia64_info
= elf64_ia64_hash_table (link_info
);
379 if (ia64_info
== NULL
)
382 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
384 /* Load the relocations for this section. */
385 internal_relocs
= (_bfd_elf_link_read_relocs
386 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
387 link_info
->keep_memory
));
388 if (internal_relocs
== NULL
)
391 irelend
= internal_relocs
+ sec
->reloc_count
;
393 /* Get the section contents. */
394 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
395 contents
= elf_section_data (sec
)->this_hdr
.contents
;
398 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
402 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
404 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
405 bfd_vma symaddr
, reladdr
, trampoff
, toff
, roff
;
409 bfd_boolean is_branch
;
410 struct elf64_ia64_dyn_sym_info
*dyn_i
;
414 case R_IA64_PCREL21B
:
415 case R_IA64_PCREL21BI
:
416 case R_IA64_PCREL21M
:
417 case R_IA64_PCREL21F
:
418 /* In pass 1, all br relaxations are done. We can skip it. */
419 if (link_info
->relax_pass
== 1)
421 skip_relax_pass_0
= FALSE
;
425 case R_IA64_PCREL60B
:
426 /* We can't optimize brl to br in pass 0 since br relaxations
427 will increase the code size. Defer it to pass 1. */
428 if (link_info
->relax_pass
== 0)
430 skip_relax_pass_1
= FALSE
;
437 /* Update max_short_sec/min_short_sec. */
439 case R_IA64_LTOFF22X
:
441 /* We can't relax ldx/mov in pass 0 since br relaxations will
442 increase the code size. Defer it to pass 1. */
443 if (link_info
->relax_pass
== 0)
445 skip_relax_pass_1
= FALSE
;
455 /* Get the value of the symbol referred to by the reloc. */
456 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
458 /* A local symbol. */
459 Elf_Internal_Sym
*isym
;
461 /* Read this BFD's local symbols. */
464 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
466 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
467 symtab_hdr
->sh_info
, 0,
473 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
474 if (isym
->st_shndx
== SHN_UNDEF
)
475 continue; /* We can't do anything with undefined symbols. */
476 else if (isym
->st_shndx
== SHN_ABS
)
477 tsec
= bfd_abs_section_ptr
;
478 else if (isym
->st_shndx
== SHN_COMMON
)
479 tsec
= bfd_com_section_ptr
;
480 else if (isym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
481 tsec
= bfd_com_section_ptr
;
483 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
485 toff
= isym
->st_value
;
486 dyn_i
= get_dyn_sym_info (ia64_info
, NULL
, abfd
, irel
, FALSE
);
491 struct elf_link_hash_entry
*h
;
493 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
494 h
= elf_sym_hashes (abfd
)[indx
];
495 BFD_ASSERT (h
!= NULL
);
497 while (h
->root
.type
== bfd_link_hash_indirect
498 || h
->root
.type
== bfd_link_hash_warning
)
499 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
501 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, irel
, FALSE
);
503 /* For branches to dynamic symbols, we're interested instead
504 in a branch to the PLT entry. */
505 if (is_branch
&& dyn_i
&& dyn_i
->want_plt2
)
507 /* Internal branches shouldn't be sent to the PLT.
508 Leave this for now and we'll give an error later. */
509 if (r_type
!= R_IA64_PCREL21B
)
512 tsec
= ia64_info
->root
.splt
;
513 toff
= dyn_i
->plt2_offset
;
514 BFD_ASSERT (irel
->r_addend
== 0);
517 /* Can't do anything else with dynamic symbols. */
518 else if (elf64_ia64_dynamic_symbol_p (h
))
523 /* We can't do anything with undefined symbols. */
524 if (h
->root
.type
== bfd_link_hash_undefined
525 || h
->root
.type
== bfd_link_hash_undefweak
)
528 tsec
= h
->root
.u
.def
.section
;
529 toff
= h
->root
.u
.def
.value
;
533 toff
+= irel
->r_addend
;
535 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
537 roff
= irel
->r_offset
;
541 bfd_signed_vma offset
;
543 reladdr
= (sec
->output_section
->vma
545 + roff
) & (bfd_vma
) -4;
547 /* The .plt section is aligned at 32byte and the .text section
548 is aligned at 64byte. The .text section is right after the
549 .plt section. After the first relaxation pass, linker may
550 increase the gap between the .plt and .text sections up
551 to 32byte. We assume linker will always insert 32byte
552 between the .plt and .text sections after the first
554 if (tsec
== ia64_info
->root
.splt
)
555 offset
= -0x1000000 + 32;
559 /* If the branch is in range, no need to do anything. */
560 if ((bfd_signed_vma
) (symaddr
- reladdr
) >= offset
561 && (bfd_signed_vma
) (symaddr
- reladdr
) <= 0x0FFFFF0)
563 /* If the 60-bit branch is in 21-bit range, optimize it. */
564 if (r_type
== R_IA64_PCREL60B
)
566 ia64_elf_relax_brl (contents
, roff
);
568 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
571 /* If the original relocation offset points to slot
572 1, change it to slot 2. */
573 if ((irel
->r_offset
& 3) == 1)
579 else if (r_type
== R_IA64_PCREL60B
)
581 else if (ia64_elf_relax_br (contents
, roff
))
583 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
586 /* Make the relocation offset point to slot 1. */
587 irel
->r_offset
= (irel
->r_offset
& ~((bfd_vma
) 0x3)) + 1;
591 /* We can't put a trampoline in a .init/.fini section. Issue
593 if (strcmp (sec
->output_section
->name
, ".init") == 0
594 || strcmp (sec
->output_section
->name
, ".fini") == 0)
597 /* xgettext:c-format */
598 (_("%pB: can't relax br at %#" PRIx64
" in section `%pA';"
599 " please use brl or indirect branch"),
600 sec
->owner
, (uint64_t) roff
, sec
);
601 bfd_set_error (bfd_error_bad_value
);
605 /* If the branch and target are in the same section, you've
606 got one honking big section and we can't help you unless
607 you are branching backwards. You'll get an error message
609 if (tsec
== sec
&& toff
> roff
)
612 /* Look for an existing fixup to this address. */
613 for (f
= fixups
; f
; f
= f
->next
)
614 if (f
->tsec
== tsec
&& f
->toff
== toff
)
619 /* Two alternatives: If it's a branch to a PLT entry, we can
620 make a copy of the FULL_PLT entry. Otherwise, we'll have
621 to use a `brl' insn to get where we're going. */
625 if (tsec
== ia64_info
->root
.splt
)
626 size
= sizeof (plt_full_entry
);
628 size
= sizeof (oor_brl
);
630 /* Resize the current section to make room for the new branch. */
631 trampoff
= (sec
->size
+ 15) & (bfd_vma
) -16;
633 /* If trampoline is out of range, there is nothing we
635 offset
= trampoff
- (roff
& (bfd_vma
) -4);
636 if (offset
< -0x1000000 || offset
> 0x0FFFFF0)
639 amt
= trampoff
+ size
;
640 contents
= (bfd_byte
*) bfd_realloc (contents
, amt
);
641 if (contents
== NULL
)
645 if (tsec
== ia64_info
->root
.splt
)
647 memcpy (contents
+ trampoff
, plt_full_entry
, size
);
649 /* Hijack the old relocation for use as the PLTOFF reloc. */
650 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
652 irel
->r_offset
= trampoff
;
656 memcpy (contents
+ trampoff
, oor_brl
, size
);
657 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
659 irel
->r_offset
= trampoff
+ 2;
662 /* Record the fixup so we don't do it again this section. */
663 f
= (struct one_fixup
*)
664 bfd_malloc ((bfd_size_type
) sizeof (*f
));
668 f
->trampoff
= trampoff
;
673 /* If trampoline is out of range, there is nothing we
675 offset
= f
->trampoff
- (roff
& (bfd_vma
) -4);
676 if (offset
< -0x1000000 || offset
> 0x0FFFFF0)
679 /* Nop out the reloc, since we're finalizing things here. */
680 irel
->r_info
= ELF64_R_INFO (0, R_IA64_NONE
);
683 /* Fix up the existing branch to hit the trampoline. */
684 if (ia64_elf_install_value (contents
+ roff
, offset
, r_type
)
688 changed_contents
= TRUE
;
689 changed_relocs
= TRUE
;
696 bfd
*obfd
= sec
->output_section
->owner
;
697 gp
= _bfd_get_gp_value (obfd
);
700 if (!elf64_ia64_choose_gp (obfd
, link_info
, FALSE
))
702 gp
= _bfd_get_gp_value (obfd
);
706 /* If the data is out of range, do nothing. */
707 if ((bfd_signed_vma
) (symaddr
- gp
) >= 0x200000
708 ||(bfd_signed_vma
) (symaddr
- gp
) < -0x200000)
711 if (r_type
== R_IA64_GPREL22
)
712 elf64_ia64_update_short_info (tsec
->output_section
,
713 tsec
->output_offset
+ toff
,
715 else if (r_type
== R_IA64_LTOFF22X
)
717 /* Can't deal yet correctly with ABS symbols. */
718 if (bfd_is_abs_section (tsec
))
721 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
723 changed_relocs
= TRUE
;
725 elf64_ia64_update_short_info (tsec
->output_section
,
726 tsec
->output_offset
+ toff
,
731 ia64_elf_relax_ldxmov (contents
, roff
);
732 irel
->r_info
= ELF64_R_INFO (0, R_IA64_NONE
);
733 changed_contents
= TRUE
;
734 changed_relocs
= TRUE
;
739 /* ??? If we created fixups, this may push the code segment large
740 enough that the data segment moves, which will change the GP.
741 Reset the GP so that we re-calculate next round. We need to
742 do this at the _beginning_ of the next round; now will not do. */
744 /* Clean up and go home. */
747 struct one_fixup
*f
= fixups
;
748 fixups
= fixups
->next
;
753 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
755 if (! link_info
->keep_memory
)
759 /* Cache the symbols for elf_link_input_bfd. */
760 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
765 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
767 if (!changed_contents
&& !link_info
->keep_memory
)
771 /* Cache the section contents for elf_link_input_bfd. */
772 elf_section_data (sec
)->this_hdr
.contents
= contents
;
776 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
779 free (internal_relocs
);
781 elf_section_data (sec
)->relocs
= internal_relocs
;
784 if (link_info
->relax_pass
== 0)
786 /* Pass 0 is only needed to relax br. */
787 sec
->skip_relax_pass_0
= skip_relax_pass_0
;
788 sec
->skip_relax_pass_1
= skip_relax_pass_1
;
791 *again
= changed_contents
|| changed_relocs
;
795 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
798 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
800 if (internal_relocs
!= NULL
801 && elf_section_data (sec
)->relocs
!= internal_relocs
)
802 free (internal_relocs
);
805 #undef skip_relax_pass_0
806 #undef skip_relax_pass_1
808 /* Return TRUE if NAME is an unwind table section name. */
810 static inline bfd_boolean
811 is_unwind_section_name (bfd
*abfd ATTRIBUTE_UNUSED
, const char *name
)
813 return ((CONST_STRNEQ (name
, ELF_STRING_ia64_unwind
)
814 && ! CONST_STRNEQ (name
, ELF_STRING_ia64_unwind_info
))
815 || CONST_STRNEQ (name
, ELF_STRING_ia64_unwind_once
));
819 /* Convert IA-64 specific section flags to bfd internal section flags. */
821 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
825 elf64_ia64_section_flags (flagword
*flags
,
826 const Elf_Internal_Shdr
*hdr
)
828 if (hdr
->sh_flags
& SHF_IA_64_SHORT
)
829 *flags
|= SEC_SMALL_DATA
;
834 /* Set the correct type for an IA-64 ELF section. We do this by the
835 section name, which is a hack, but ought to work. */
838 elf64_ia64_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
843 name
= bfd_section_name (sec
);
845 if (is_unwind_section_name (abfd
, name
))
847 /* We don't have the sections numbered at this point, so sh_info
848 is set later, in elf64_ia64_final_write_processing. */
849 hdr
->sh_type
= SHT_IA_64_UNWIND
;
850 hdr
->sh_flags
|= SHF_LINK_ORDER
;
852 else if (strcmp (name
, ELF_STRING_ia64_archext
) == 0)
853 hdr
->sh_type
= SHT_IA_64_EXT
;
855 if (sec
->flags
& SEC_SMALL_DATA
)
856 hdr
->sh_flags
|= SHF_IA_64_SHORT
;
861 /* Hook called by the linker routine which adds symbols from an object
862 file. We use it to put .comm items in .sbss, and not .bss. */
865 elf64_ia64_add_symbol_hook (bfd
*abfd
,
866 struct bfd_link_info
*info
,
867 Elf_Internal_Sym
*sym
,
868 const char **namep ATTRIBUTE_UNUSED
,
869 flagword
*flagsp ATTRIBUTE_UNUSED
,
873 if (sym
->st_shndx
== SHN_COMMON
874 && !bfd_link_relocatable (info
)
875 && sym
->st_size
<= elf_gp_size (abfd
))
877 /* Common symbols less than or equal to -G nn bytes are
878 automatically put into .sbss. */
880 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
884 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
887 | SEC_LINKER_CREATED
));
893 *valp
= sym
->st_size
;
899 /* According to the Tahoe assembler spec, all labels starting with a
903 elf64_ia64_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
906 return name
[0] == '.';
909 /* Should we do dynamic things to this symbol? */
912 elf64_ia64_dynamic_symbol_p (struct elf_link_hash_entry
*h
)
914 return h
!= NULL
&& h
->def_dynamic
;
917 static struct bfd_hash_entry
*
918 elf64_ia64_new_elf_hash_entry (struct bfd_hash_entry
*entry
,
919 struct bfd_hash_table
*table
,
922 struct elf64_ia64_link_hash_entry
*ret
;
923 ret
= (struct elf64_ia64_link_hash_entry
*) entry
;
925 /* Allocate the structure if it has not already been allocated by a
928 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
933 /* Call the allocation method of the superclass. */
934 ret
= ((struct elf64_ia64_link_hash_entry
*)
935 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
940 ret
->sorted_count
= 0;
942 return (struct bfd_hash_entry
*) ret
;
946 elf64_ia64_hash_hide_symbol (struct bfd_link_info
*info
,
947 struct elf_link_hash_entry
*xh
,
948 bfd_boolean force_local
)
950 struct elf64_ia64_link_hash_entry
*h
;
951 struct elf64_ia64_dyn_sym_info
*dyn_i
;
954 h
= (struct elf64_ia64_link_hash_entry
*)xh
;
956 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
958 for (count
= h
->count
, dyn_i
= h
->info
;
962 dyn_i
->want_plt2
= 0;
967 /* Compute a hash of a local hash entry. */
970 elf64_ia64_local_htab_hash (const void *ptr
)
972 struct elf64_ia64_local_hash_entry
*entry
973 = (struct elf64_ia64_local_hash_entry
*) ptr
;
975 return ELF_LOCAL_SYMBOL_HASH (entry
->id
, entry
->r_sym
);
978 /* Compare local hash entries. */
981 elf64_ia64_local_htab_eq (const void *ptr1
, const void *ptr2
)
983 struct elf64_ia64_local_hash_entry
*entry1
984 = (struct elf64_ia64_local_hash_entry
*) ptr1
;
985 struct elf64_ia64_local_hash_entry
*entry2
986 = (struct elf64_ia64_local_hash_entry
*) ptr2
;
988 return entry1
->id
== entry2
->id
&& entry1
->r_sym
== entry2
->r_sym
;
991 /* Free the global elf64_ia64_dyn_sym_info array. */
994 elf64_ia64_global_dyn_info_free (void **xentry
,
995 void * unused ATTRIBUTE_UNUSED
)
997 struct elf64_ia64_link_hash_entry
*entry
998 = (struct elf64_ia64_link_hash_entry
*) xentry
;
1000 if (entry
->root
.root
.type
== bfd_link_hash_warning
)
1001 entry
= (struct elf64_ia64_link_hash_entry
*) entry
->root
.root
.u
.i
.link
;
1008 entry
->sorted_count
= 0;
1015 /* Free the local elf64_ia64_dyn_sym_info array. */
1018 elf64_ia64_local_dyn_info_free (void **slot
,
1019 void * unused ATTRIBUTE_UNUSED
)
1021 struct elf64_ia64_local_hash_entry
*entry
1022 = (struct elf64_ia64_local_hash_entry
*) *slot
;
1029 entry
->sorted_count
= 0;
1036 /* Destroy IA-64 linker hash table. */
1039 elf64_ia64_link_hash_table_free (bfd
*obfd
)
1041 struct elf64_ia64_link_hash_table
*ia64_info
1042 = (struct elf64_ia64_link_hash_table
*) obfd
->link
.hash
;
1043 if (ia64_info
->loc_hash_table
)
1045 htab_traverse (ia64_info
->loc_hash_table
,
1046 elf64_ia64_local_dyn_info_free
, NULL
);
1047 htab_delete (ia64_info
->loc_hash_table
);
1049 if (ia64_info
->loc_hash_memory
)
1050 objalloc_free ((struct objalloc
*) ia64_info
->loc_hash_memory
);
1051 elf_link_hash_traverse (&ia64_info
->root
,
1052 elf64_ia64_global_dyn_info_free
, NULL
);
1053 _bfd_elf_link_hash_table_free (obfd
);
1056 /* Create the derived linker hash table. The IA-64 ELF port uses this
1057 derived hash table to keep information specific to the IA-64 ElF
1058 linker (without using static variables). */
1060 static struct bfd_link_hash_table
*
1061 elf64_ia64_hash_table_create (bfd
*abfd
)
1063 struct elf64_ia64_link_hash_table
*ret
;
1065 ret
= bfd_zmalloc ((bfd_size_type
) sizeof (*ret
));
1069 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1070 elf64_ia64_new_elf_hash_entry
,
1071 sizeof (struct elf64_ia64_link_hash_entry
),
1078 ret
->loc_hash_table
= htab_try_create (1024, elf64_ia64_local_htab_hash
,
1079 elf64_ia64_local_htab_eq
, NULL
);
1080 ret
->loc_hash_memory
= objalloc_create ();
1081 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1083 elf64_ia64_link_hash_table_free (abfd
);
1086 ret
->root
.root
.hash_table_free
= elf64_ia64_link_hash_table_free
;
1088 return &ret
->root
.root
;
1091 /* Traverse both local and global hash tables. */
1093 struct elf64_ia64_dyn_sym_traverse_data
1095 bfd_boolean (*func
) (struct elf64_ia64_dyn_sym_info
*, void *);
1100 elf64_ia64_global_dyn_sym_thunk (struct bfd_hash_entry
*xentry
,
1103 struct elf64_ia64_link_hash_entry
*entry
1104 = (struct elf64_ia64_link_hash_entry
*) xentry
;
1105 struct elf64_ia64_dyn_sym_traverse_data
*data
1106 = (struct elf64_ia64_dyn_sym_traverse_data
*) xdata
;
1107 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1110 if (entry
->root
.root
.type
== bfd_link_hash_warning
)
1111 entry
= (struct elf64_ia64_link_hash_entry
*) entry
->root
.root
.u
.i
.link
;
1113 for (count
= entry
->count
, dyn_i
= entry
->info
;
1116 if (! (*data
->func
) (dyn_i
, data
->data
))
1122 elf64_ia64_local_dyn_sym_thunk (void **slot
, void * xdata
)
1124 struct elf64_ia64_local_hash_entry
*entry
1125 = (struct elf64_ia64_local_hash_entry
*) *slot
;
1126 struct elf64_ia64_dyn_sym_traverse_data
*data
1127 = (struct elf64_ia64_dyn_sym_traverse_data
*) xdata
;
1128 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1131 for (count
= entry
->count
, dyn_i
= entry
->info
;
1134 if (! (*data
->func
) (dyn_i
, data
->data
))
1140 elf64_ia64_dyn_sym_traverse (struct elf64_ia64_link_hash_table
*ia64_info
,
1141 bfd_boolean (*func
) (struct elf64_ia64_dyn_sym_info
*, void *),
1144 struct elf64_ia64_dyn_sym_traverse_data xdata
;
1149 elf_link_hash_traverse (&ia64_info
->root
,
1150 elf64_ia64_global_dyn_sym_thunk
, &xdata
);
1151 htab_traverse (ia64_info
->loc_hash_table
,
1152 elf64_ia64_local_dyn_sym_thunk
, &xdata
);
1155 #define NOTE_NAME "IPF/VMS"
1158 create_ia64_vms_notes (bfd
*abfd
, struct bfd_link_info
*info
,
1159 unsigned int time_hi
, unsigned int time_lo
)
1162 Elf_Internal_Note notes
[NBR_NOTES
];
1164 int module_name_len
;
1165 unsigned char cur_time
[8];
1166 Elf64_External_VMS_ORIG_DYN_Note
*orig_dyn
;
1167 unsigned int orig_dyn_size
;
1168 unsigned int note_size
;
1170 unsigned char *noteptr
;
1171 unsigned char *note_contents
;
1172 struct elf64_ia64_link_hash_table
*ia64_info
;
1174 ia64_info
= elf64_ia64_hash_table (info
);
1176 module_name
= vms_get_module_name (bfd_get_filename (abfd
), TRUE
);
1177 module_name_len
= strlen (module_name
) + 1;
1179 bfd_putl32 (time_lo
, cur_time
+ 0);
1180 bfd_putl32 (time_hi
, cur_time
+ 4);
1182 /* Note 0: IMGNAM. */
1183 notes
[0].type
= NT_VMS_IMGNAM
;
1184 notes
[0].descdata
= module_name
;
1185 notes
[0].descsz
= module_name_len
;
1187 /* Note 1: GSTNAM. */
1188 notes
[1].type
= NT_VMS_GSTNAM
;
1189 notes
[1].descdata
= module_name
;
1190 notes
[1].descsz
= module_name_len
;
1192 /* Note 2: IMGID. */
1193 #define IMG_ID "V1.0"
1194 notes
[2].type
= NT_VMS_IMGID
;
1195 notes
[2].descdata
= IMG_ID
;
1196 notes
[2].descsz
= sizeof (IMG_ID
);
1198 /* Note 3: Linktime. */
1199 notes
[3].type
= NT_VMS_LINKTIME
;
1200 notes
[3].descdata
= (char *)cur_time
;
1201 notes
[3].descsz
= sizeof (cur_time
);
1203 /* Note 4: Linker id. */
1204 notes
[4].type
= NT_VMS_LINKID
;
1205 notes
[4].descdata
= "GNU ld " BFD_VERSION_STRING
;
1206 notes
[4].descsz
= strlen (notes
[4].descdata
) + 1;
1208 /* Note 5: Original dyn. */
1209 orig_dyn_size
= (sizeof (*orig_dyn
) + sizeof (IMG_ID
) - 1 + 7) & ~7;
1210 orig_dyn
= bfd_zalloc (abfd
, orig_dyn_size
);
1211 if (orig_dyn
== NULL
)
1213 bfd_putl32 (1, orig_dyn
->major_id
);
1214 bfd_putl32 (3, orig_dyn
->minor_id
);
1215 memcpy (orig_dyn
->manipulation_date
, cur_time
, sizeof (cur_time
));
1216 bfd_putl64 (VMS_LF_IMGSTA
| VMS_LF_MAIN
, orig_dyn
->link_flags
);
1217 bfd_putl32 (EF_IA_64_ABI64
, orig_dyn
->elf_flags
);
1218 memcpy (orig_dyn
->imgid
, IMG_ID
, sizeof (IMG_ID
));
1219 notes
[5].type
= NT_VMS_ORIG_DYN
;
1220 notes
[5].descdata
= (char *)orig_dyn
;
1221 notes
[5].descsz
= orig_dyn_size
;
1223 /* Note 3: Patchtime. */
1224 notes
[6].type
= NT_VMS_PATCHTIME
;
1225 notes
[6].descdata
= (char *)cur_time
;
1226 notes
[6].descsz
= sizeof (cur_time
);
1228 /* Compute notes size. */
1230 for (i
= 0; i
< NBR_NOTES
; i
++)
1231 note_size
+= sizeof (Elf64_External_VMS_Note
) - 1
1232 + ((sizeof (NOTE_NAME
) - 1 + 7) & ~7)
1233 + ((notes
[i
].descsz
+ 7) & ~7);
1235 /* Malloc a temporary buffer large enough for most notes */
1236 note_contents
= (unsigned char *) bfd_zalloc (abfd
, note_size
);
1237 if (note_contents
== NULL
)
1239 noteptr
= note_contents
;
1242 for (i
= 0; i
< NBR_NOTES
; i
++)
1244 Elf64_External_VMS_Note
*enote
= (Elf64_External_VMS_Note
*) noteptr
;
1246 bfd_putl64 (sizeof (NOTE_NAME
) - 1, enote
->namesz
);
1247 bfd_putl64 (notes
[i
].descsz
, enote
->descsz
);
1248 bfd_putl64 (notes
[i
].type
, enote
->type
);
1250 noteptr
= (unsigned char *)enote
->name
;
1251 memcpy (noteptr
, NOTE_NAME
, sizeof (NOTE_NAME
) - 1);
1252 noteptr
+= (sizeof (NOTE_NAME
) - 1 + 7) & ~7;
1253 memcpy (noteptr
, notes
[i
].descdata
, notes
[i
].descsz
);
1254 noteptr
+= (notes
[i
].descsz
+ 7) & ~7;
1257 ia64_info
->note_sec
->contents
= note_contents
;
1258 ia64_info
->note_sec
->size
= note_size
;
1266 elf64_ia64_create_dynamic_sections (bfd
*abfd
,
1267 struct bfd_link_info
*info
)
1269 struct elf64_ia64_link_hash_table
*ia64_info
;
1272 const struct elf_backend_data
*bed
;
1274 ia64_info
= elf64_ia64_hash_table (info
);
1275 if (ia64_info
== NULL
)
1278 if (elf_hash_table (info
)->dynamic_sections_created
)
1281 abfd
= elf_hash_table (info
)->dynobj
;
1282 bed
= get_elf_backend_data (abfd
);
1284 flags
= bed
->dynamic_sec_flags
;
1286 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynamic",
1287 flags
| SEC_READONLY
);
1289 || !bfd_set_section_alignment (s
, bed
->s
->log_file_align
))
1292 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", flags
| SEC_READONLY
);
1294 || !bfd_set_section_alignment (s
, bed
->plt_alignment
))
1296 ia64_info
->root
.splt
= s
;
1298 if (!get_got (abfd
, ia64_info
))
1301 if (!get_pltoff (abfd
, ia64_info
))
1304 s
= bfd_make_section_anyway_with_flags (abfd
, ".vmsdynstr",
1308 | SEC_LINKER_CREATED
));
1310 || !bfd_set_section_alignment (s
, 0))
1313 /* Create a fixup section. */
1314 s
= bfd_make_section_anyway_with_flags (abfd
, ".fixups",
1318 | SEC_LINKER_CREATED
));
1320 || !bfd_set_section_alignment (s
, 3))
1322 ia64_info
->fixups_sec
= s
;
1324 /* Create the transfer fixup section. */
1325 s
= bfd_make_section_anyway_with_flags (abfd
, ".transfer",
1329 | SEC_LINKER_CREATED
));
1331 || !bfd_set_section_alignment (s
, 3))
1333 s
->size
= sizeof (struct elf64_vms_transfer
);
1334 ia64_info
->transfer_sec
= s
;
1336 /* Create note section. */
1337 s
= bfd_make_section_anyway_with_flags (abfd
, ".vms.note",
1343 || !bfd_set_section_alignment (s
, 3))
1345 ia64_info
->note_sec
= s
;
1347 elf_hash_table (info
)->dynamic_sections_created
= TRUE
;
1351 /* Find and/or create a hash entry for local symbol. */
1352 static struct elf64_ia64_local_hash_entry
*
1353 get_local_sym_hash (struct elf64_ia64_link_hash_table
*ia64_info
,
1354 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1357 struct elf64_ia64_local_hash_entry e
, *ret
;
1358 asection
*sec
= abfd
->sections
;
1359 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1360 ELF64_R_SYM (rel
->r_info
));
1364 e
.r_sym
= ELF64_R_SYM (rel
->r_info
);
1365 slot
= htab_find_slot_with_hash (ia64_info
->loc_hash_table
, &e
, h
,
1366 create
? INSERT
: NO_INSERT
);
1372 return (struct elf64_ia64_local_hash_entry
*) *slot
;
1374 ret
= (struct elf64_ia64_local_hash_entry
*)
1375 objalloc_alloc ((struct objalloc
*) ia64_info
->loc_hash_memory
,
1376 sizeof (struct elf64_ia64_local_hash_entry
));
1379 memset (ret
, 0, sizeof (*ret
));
1381 ret
->r_sym
= ELF64_R_SYM (rel
->r_info
);
1387 /* Used to sort elf64_ia64_dyn_sym_info array. */
1390 addend_compare (const void *xp
, const void *yp
)
1392 const struct elf64_ia64_dyn_sym_info
*x
1393 = (const struct elf64_ia64_dyn_sym_info
*) xp
;
1394 const struct elf64_ia64_dyn_sym_info
*y
1395 = (const struct elf64_ia64_dyn_sym_info
*) yp
;
1397 return x
->addend
< y
->addend
? -1 : x
->addend
> y
->addend
? 1 : 0;
1400 /* Sort elf64_ia64_dyn_sym_info array and remove duplicates. */
1403 sort_dyn_sym_info (struct elf64_ia64_dyn_sym_info
*info
,
1406 bfd_vma curr
, prev
, got_offset
;
1407 unsigned int i
, kept
, dupes
, diff
, dest
, src
, len
;
1409 qsort (info
, count
, sizeof (*info
), addend_compare
);
1411 /* Find the first duplicate. */
1412 prev
= info
[0].addend
;
1413 got_offset
= info
[0].got_offset
;
1414 for (i
= 1; i
< count
; i
++)
1416 curr
= info
[i
].addend
;
1419 /* For duplicates, make sure that GOT_OFFSET is valid. */
1420 if (got_offset
== (bfd_vma
) -1)
1421 got_offset
= info
[i
].got_offset
;
1424 got_offset
= info
[i
].got_offset
;
1428 /* We may move a block of elements to here. */
1431 /* Remove duplicates. */
1436 /* For duplicates, make sure that the kept one has a valid
1439 if (got_offset
!= (bfd_vma
) -1)
1440 info
[kept
].got_offset
= got_offset
;
1442 curr
= info
[i
].addend
;
1443 got_offset
= info
[i
].got_offset
;
1445 /* Move a block of elements whose first one is different from
1449 for (src
= i
+ 1; src
< count
; src
++)
1451 if (info
[src
].addend
!= curr
)
1453 /* For duplicates, make sure that GOT_OFFSET is
1455 if (got_offset
== (bfd_vma
) -1)
1456 got_offset
= info
[src
].got_offset
;
1459 /* Make sure that the kept one has a valid got_offset. */
1460 if (got_offset
!= (bfd_vma
) -1)
1461 info
[kept
].got_offset
= got_offset
;
1469 /* Find the next duplicate. SRC will be kept. */
1470 prev
= info
[src
].addend
;
1471 got_offset
= info
[src
].got_offset
;
1472 for (dupes
= src
+ 1; dupes
< count
; dupes
++)
1474 curr
= info
[dupes
].addend
;
1477 /* Make sure that got_offset is valid. */
1478 if (got_offset
== (bfd_vma
) -1)
1479 got_offset
= info
[dupes
].got_offset
;
1481 /* For duplicates, make sure that the kept one has
1482 a valid got_offset. */
1483 if (got_offset
!= (bfd_vma
) -1)
1484 info
[dupes
- 1].got_offset
= got_offset
;
1487 got_offset
= info
[dupes
].got_offset
;
1491 /* How much to move. */
1495 if (len
== 1 && dupes
< count
)
1497 /* If we only move 1 element, we combine it with the next
1498 one. There must be at least a duplicate. Find the
1499 next different one. */
1500 for (diff
= dupes
+ 1, src
++; diff
< count
; diff
++, src
++)
1502 if (info
[diff
].addend
!= curr
)
1504 /* Make sure that got_offset is valid. */
1505 if (got_offset
== (bfd_vma
) -1)
1506 got_offset
= info
[diff
].got_offset
;
1509 /* Makre sure that the last duplicated one has an valid
1511 BFD_ASSERT (curr
== prev
);
1512 if (got_offset
!= (bfd_vma
) -1)
1513 info
[diff
- 1].got_offset
= got_offset
;
1517 /* Find the next duplicate. Track the current valid
1519 prev
= info
[diff
].addend
;
1520 got_offset
= info
[diff
].got_offset
;
1521 for (dupes
= diff
+ 1; dupes
< count
; dupes
++)
1523 curr
= info
[dupes
].addend
;
1526 /* For duplicates, make sure that GOT_OFFSET
1528 if (got_offset
== (bfd_vma
) -1)
1529 got_offset
= info
[dupes
].got_offset
;
1532 got_offset
= info
[dupes
].got_offset
;
1537 len
= diff
- src
+ 1;
1542 memmove (&info
[dest
], &info
[src
], len
* sizeof (*info
));
1551 /* When we get here, either there is no duplicate at all or
1552 the only duplicate is the last element. */
1555 /* If the last element is a duplicate, make sure that the
1556 kept one has a valid got_offset. We also update count. */
1557 if (got_offset
!= (bfd_vma
) -1)
1558 info
[dest
- 1].got_offset
= got_offset
;
1566 /* Find and/or create a descriptor for dynamic symbol info. This will
1567 vary based on global or local symbol, and the addend to the reloc.
1569 We don't sort when inserting. Also, we sort and eliminate
1570 duplicates if there is an unsorted section. Typically, this will
1571 only happen once, because we do all insertions before lookups. We
1572 then use bsearch to do a lookup. This also allows lookups to be
1573 fast. So we have fast insertion (O(log N) due to duplicate check),
1574 fast lookup (O(log N)) and one sort (O(N log N) expected time).
1575 Previously, all lookups were O(N) because of the use of the linked
1576 list and also all insertions were O(N) because of the check for
1577 duplicates. There are some complications here because the array
1578 size grows occasionally, which may add an O(N) factor, but this
1579 should be rare. Also, we free the excess array allocation, which
1580 requires a copy which is O(N), but this only happens once. */
1582 static struct elf64_ia64_dyn_sym_info
*
1583 get_dyn_sym_info (struct elf64_ia64_link_hash_table
*ia64_info
,
1584 struct elf_link_hash_entry
*h
, bfd
*abfd
,
1585 const Elf_Internal_Rela
*rel
, bfd_boolean create
)
1587 struct elf64_ia64_dyn_sym_info
**info_p
, *info
, *dyn_i
, key
;
1588 unsigned int *count_p
, *sorted_count_p
, *size_p
;
1589 unsigned int count
, sorted_count
, size
;
1590 bfd_vma addend
= rel
? rel
->r_addend
: 0;
1595 struct elf64_ia64_link_hash_entry
*global_h
;
1597 global_h
= (struct elf64_ia64_link_hash_entry
*) h
;
1598 info_p
= &global_h
->info
;
1599 count_p
= &global_h
->count
;
1600 sorted_count_p
= &global_h
->sorted_count
;
1601 size_p
= &global_h
->size
;
1605 struct elf64_ia64_local_hash_entry
*loc_h
;
1607 loc_h
= get_local_sym_hash (ia64_info
, abfd
, rel
, create
);
1610 BFD_ASSERT (!create
);
1614 info_p
= &loc_h
->info
;
1615 count_p
= &loc_h
->count
;
1616 sorted_count_p
= &loc_h
->sorted_count
;
1617 size_p
= &loc_h
->size
;
1621 sorted_count
= *sorted_count_p
;
1626 /* When we create the array, we don't check for duplicates,
1627 except in the previously sorted section if one exists, and
1628 against the last inserted entry. This allows insertions to
1634 /* Try bsearch first on the sorted section. */
1635 key
.addend
= addend
;
1636 dyn_i
= bsearch (&key
, info
, sorted_count
,
1637 sizeof (*info
), addend_compare
);
1645 /* Do a quick check for the last inserted entry. */
1646 dyn_i
= info
+ count
- 1;
1647 if (dyn_i
->addend
== addend
)
1655 /* It is the very first element. We create the array of size
1658 amt
= size
* sizeof (*info
);
1659 info
= bfd_malloc (amt
);
1661 else if (size
<= count
)
1663 /* We double the array size every time when we reach the
1666 amt
= size
* sizeof (*info
);
1667 info
= bfd_realloc (info
, amt
);
1678 /* Append the new one to the array. */
1679 dyn_i
= info
+ count
;
1680 memset (dyn_i
, 0, sizeof (*dyn_i
));
1681 dyn_i
->got_offset
= (bfd_vma
) -1;
1682 dyn_i
->addend
= addend
;
1684 /* We increment count only since the new ones are unsorted and
1685 may have duplicate. */
1690 /* It is a lookup without insertion. Sort array if part of the
1691 array isn't sorted. */
1692 if (count
!= sorted_count
)
1694 count
= sort_dyn_sym_info (info
, count
);
1696 *sorted_count_p
= count
;
1699 /* Free unused memory. */
1702 amt
= count
* sizeof (*info
);
1703 info
= bfd_malloc (amt
);
1706 memcpy (info
, *info_p
, amt
);
1713 key
.addend
= addend
;
1714 dyn_i
= bsearch (&key
, info
, count
,
1715 sizeof (*info
), addend_compare
);
1722 get_got (bfd
*abfd
, struct elf64_ia64_link_hash_table
*ia64_info
)
1727 got
= ia64_info
->root
.sgot
;
1732 dynobj
= ia64_info
->root
.dynobj
;
1734 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1736 /* The .got section is always aligned at 8 bytes. */
1737 flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
1738 got
= bfd_make_section_anyway_with_flags (dynobj
, ".got",
1739 flags
| SEC_SMALL_DATA
);
1741 || !bfd_set_section_alignment (got
, 3))
1743 ia64_info
->root
.sgot
= got
;
1749 /* Create function descriptor section (.opd). This section is called .opd
1750 because it contains "official procedure descriptors". The "official"
1751 refers to the fact that these descriptors are used when taking the address
1752 of a procedure, thus ensuring a unique address for each procedure. */
1755 get_fptr (bfd
*abfd
, struct bfd_link_info
*info
,
1756 struct elf64_ia64_link_hash_table
*ia64_info
)
1761 fptr
= ia64_info
->fptr_sec
;
1764 dynobj
= ia64_info
->root
.dynobj
;
1766 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1768 fptr
= bfd_make_section_anyway_with_flags (dynobj
, ".opd",
1773 | (bfd_link_pie (info
) ? 0
1775 | SEC_LINKER_CREATED
));
1777 || !bfd_set_section_alignment (fptr
, 4))
1783 ia64_info
->fptr_sec
= fptr
;
1785 if (bfd_link_pie (info
))
1788 fptr_rel
= bfd_make_section_anyway_with_flags (dynobj
, ".rela.opd",
1789 (SEC_ALLOC
| SEC_LOAD
1792 | SEC_LINKER_CREATED
1794 if (fptr_rel
== NULL
1795 || !bfd_set_section_alignment (fptr_rel
, 3))
1801 ia64_info
->rel_fptr_sec
= fptr_rel
;
1809 get_pltoff (bfd
*abfd
, struct elf64_ia64_link_hash_table
*ia64_info
)
1814 pltoff
= ia64_info
->pltoff_sec
;
1817 dynobj
= ia64_info
->root
.dynobj
;
1819 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1821 pltoff
= bfd_make_section_anyway_with_flags (dynobj
,
1822 ELF_STRING_ia64_pltoff
,
1828 | SEC_LINKER_CREATED
));
1830 || !bfd_set_section_alignment (pltoff
, 4))
1836 ia64_info
->pltoff_sec
= pltoff
;
1843 get_reloc_section (bfd
*abfd
,
1844 struct elf64_ia64_link_hash_table
*ia64_info
,
1845 asection
*sec
, bfd_boolean create
)
1847 const char *srel_name
;
1851 srel_name
= (bfd_elf_string_from_elf_section
1852 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1853 _bfd_elf_single_rel_hdr (sec
)->sh_name
));
1854 if (srel_name
== NULL
)
1857 BFD_ASSERT ((CONST_STRNEQ (srel_name
, ".rela")
1858 && strcmp (bfd_section_name (sec
), srel_name
+5) == 0)
1859 || (CONST_STRNEQ (srel_name
, ".rel")
1860 && strcmp (bfd_section_name (sec
), srel_name
+4) == 0));
1862 dynobj
= ia64_info
->root
.dynobj
;
1864 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1866 srel
= bfd_get_linker_section (dynobj
, srel_name
);
1867 if (srel
== NULL
&& create
)
1869 srel
= bfd_make_section_anyway_with_flags (dynobj
, srel_name
,
1870 (SEC_ALLOC
| SEC_LOAD
1873 | SEC_LINKER_CREATED
1876 || !bfd_set_section_alignment (srel
, 3))
1884 count_dyn_reloc (bfd
*abfd
, struct elf64_ia64_dyn_sym_info
*dyn_i
,
1885 asection
*srel
, int type
)
1887 struct elf64_ia64_dyn_reloc_entry
*rent
;
1889 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
1890 if (rent
->srel
== srel
&& rent
->type
== type
)
1895 rent
= ((struct elf64_ia64_dyn_reloc_entry
*)
1896 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
)));
1900 rent
->next
= dyn_i
->reloc_entries
;
1904 dyn_i
->reloc_entries
= rent
;
1912 elf64_ia64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1914 const Elf_Internal_Rela
*relocs
)
1916 struct elf64_ia64_link_hash_table
*ia64_info
;
1917 const Elf_Internal_Rela
*relend
;
1918 Elf_Internal_Shdr
*symtab_hdr
;
1919 const Elf_Internal_Rela
*rel
;
1920 asection
*got
, *fptr
, *srel
, *pltoff
;
1929 NEED_LTOFF_FPTR
= 128
1932 struct elf_link_hash_entry
*h
;
1933 unsigned long r_symndx
;
1934 bfd_boolean maybe_dynamic
;
1936 if (bfd_link_relocatable (info
))
1939 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1940 ia64_info
= elf64_ia64_hash_table (info
);
1941 if (ia64_info
== NULL
)
1944 got
= fptr
= srel
= pltoff
= NULL
;
1946 relend
= relocs
+ sec
->reloc_count
;
1948 /* We scan relocations first to create dynamic relocation arrays. We
1949 modified get_dyn_sym_info to allow fast insertion and support fast
1950 lookup in the next loop. */
1951 for (rel
= relocs
; rel
< relend
; ++rel
)
1953 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1954 if (r_symndx
>= symtab_hdr
->sh_info
)
1956 long indx
= r_symndx
- symtab_hdr
->sh_info
;
1957 h
= elf_sym_hashes (abfd
)[indx
];
1958 while (h
->root
.type
== bfd_link_hash_indirect
1959 || h
->root
.type
== bfd_link_hash_warning
)
1960 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1965 /* We can only get preliminary data on whether a symbol is
1966 locally or externally defined, as not all of the input files
1967 have yet been processed. Do something with what we know, as
1968 this may help reduce memory usage and processing time later. */
1969 maybe_dynamic
= (h
&& ((!bfd_link_executable (info
)
1970 && (!SYMBOLIC_BIND (info
, h
)
1971 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
1973 || h
->root
.type
== bfd_link_hash_defweak
));
1976 switch (ELF64_R_TYPE (rel
->r_info
))
1978 case R_IA64_TPREL64MSB
:
1979 case R_IA64_TPREL64LSB
:
1980 case R_IA64_LTOFF_TPREL22
:
1981 case R_IA64_DTPREL32MSB
:
1982 case R_IA64_DTPREL32LSB
:
1983 case R_IA64_DTPREL64MSB
:
1984 case R_IA64_DTPREL64LSB
:
1985 case R_IA64_LTOFF_DTPREL22
:
1986 case R_IA64_DTPMOD64MSB
:
1987 case R_IA64_DTPMOD64LSB
:
1988 case R_IA64_LTOFF_DTPMOD22
:
1992 case R_IA64_IPLTMSB
:
1993 case R_IA64_IPLTLSB
:
1996 case R_IA64_LTOFF_FPTR22
:
1997 case R_IA64_LTOFF_FPTR64I
:
1998 case R_IA64_LTOFF_FPTR32MSB
:
1999 case R_IA64_LTOFF_FPTR32LSB
:
2000 case R_IA64_LTOFF_FPTR64MSB
:
2001 case R_IA64_LTOFF_FPTR64LSB
:
2002 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
2005 case R_IA64_FPTR64I
:
2006 case R_IA64_FPTR32MSB
:
2007 case R_IA64_FPTR32LSB
:
2008 case R_IA64_FPTR64MSB
:
2009 case R_IA64_FPTR64LSB
:
2010 if (bfd_link_pic (info
) || h
)
2011 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2013 need_entry
= NEED_FPTR
;
2016 case R_IA64_LTOFF22
:
2017 case R_IA64_LTOFF64I
:
2018 need_entry
= NEED_GOT
;
2021 case R_IA64_LTOFF22X
:
2022 need_entry
= NEED_GOTX
;
2025 case R_IA64_PLTOFF22
:
2026 case R_IA64_PLTOFF64I
:
2027 case R_IA64_PLTOFF64MSB
:
2028 case R_IA64_PLTOFF64LSB
:
2029 need_entry
= NEED_PLTOFF
;
2033 need_entry
|= NEED_MIN_PLT
;
2037 (*info
->callbacks
->warning
)
2038 (info
, _("@pltoff reloc against local symbol"), 0,
2039 abfd
, 0, (bfd_vma
) 0);
2043 case R_IA64_PCREL21B
:
2044 case R_IA64_PCREL60B
:
2045 /* Depending on where this symbol is defined, we may or may not
2046 need a full plt entry. Only skip if we know we'll not need
2047 the entry -- static or symbolic, and the symbol definition
2048 has already been seen. */
2049 if (maybe_dynamic
&& rel
->r_addend
== 0)
2050 need_entry
= NEED_FULL_PLT
;
2056 case R_IA64_DIR32MSB
:
2057 case R_IA64_DIR32LSB
:
2058 case R_IA64_DIR64MSB
:
2059 case R_IA64_DIR64LSB
:
2060 /* Shared objects will always need at least a REL relocation. */
2061 if (bfd_link_pic (info
) || maybe_dynamic
)
2062 need_entry
= NEED_DYNREL
;
2065 case R_IA64_PCREL22
:
2066 case R_IA64_PCREL64I
:
2067 case R_IA64_PCREL32MSB
:
2068 case R_IA64_PCREL32LSB
:
2069 case R_IA64_PCREL64MSB
:
2070 case R_IA64_PCREL64LSB
:
2072 need_entry
= NEED_DYNREL
;
2079 if ((need_entry
& NEED_FPTR
) != 0
2082 (*info
->callbacks
->warning
)
2083 (info
, _("non-zero addend in @fptr reloc"), 0,
2084 abfd
, 0, (bfd_vma
) 0);
2087 if (get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, TRUE
) == NULL
)
2091 /* Now, we only do lookup without insertion, which is very fast
2092 with the modified get_dyn_sym_info. */
2093 for (rel
= relocs
; rel
< relend
; ++rel
)
2095 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2096 int dynrel_type
= R_IA64_NONE
;
2098 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2099 if (r_symndx
>= symtab_hdr
->sh_info
)
2101 /* We're dealing with a global symbol -- find its hash entry
2102 and mark it as being referenced. */
2103 long indx
= r_symndx
- symtab_hdr
->sh_info
;
2104 h
= elf_sym_hashes (abfd
)[indx
];
2105 while (h
->root
.type
== bfd_link_hash_indirect
2106 || h
->root
.type
== bfd_link_hash_warning
)
2107 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2109 /* PR15323, ref flags aren't set for references in the same
2116 /* We can only get preliminary data on whether a symbol is
2117 locally or externally defined, as not all of the input files
2118 have yet been processed. Do something with what we know, as
2119 this may help reduce memory usage and processing time later. */
2120 maybe_dynamic
= (h
&& ((!bfd_link_executable (info
)
2121 && (!SYMBOLIC_BIND (info
, h
)
2122 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
2124 || h
->root
.type
== bfd_link_hash_defweak
));
2127 switch (ELF64_R_TYPE (rel
->r_info
))
2129 case R_IA64_TPREL64MSB
:
2130 case R_IA64_TPREL64LSB
:
2131 case R_IA64_LTOFF_TPREL22
:
2132 case R_IA64_DTPREL32MSB
:
2133 case R_IA64_DTPREL32LSB
:
2134 case R_IA64_DTPREL64MSB
:
2135 case R_IA64_DTPREL64LSB
:
2136 case R_IA64_LTOFF_DTPREL22
:
2137 case R_IA64_DTPMOD64MSB
:
2138 case R_IA64_DTPMOD64LSB
:
2139 case R_IA64_LTOFF_DTPMOD22
:
2143 case R_IA64_LTOFF_FPTR22
:
2144 case R_IA64_LTOFF_FPTR64I
:
2145 case R_IA64_LTOFF_FPTR32MSB
:
2146 case R_IA64_LTOFF_FPTR32LSB
:
2147 case R_IA64_LTOFF_FPTR64MSB
:
2148 case R_IA64_LTOFF_FPTR64LSB
:
2149 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
2152 case R_IA64_FPTR64I
:
2153 case R_IA64_FPTR32MSB
:
2154 case R_IA64_FPTR32LSB
:
2155 case R_IA64_FPTR64MSB
:
2156 case R_IA64_FPTR64LSB
:
2157 if (bfd_link_pic (info
) || h
)
2158 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2160 need_entry
= NEED_FPTR
;
2161 dynrel_type
= R_IA64_FPTR64LSB
;
2164 case R_IA64_LTOFF22
:
2165 case R_IA64_LTOFF64I
:
2166 need_entry
= NEED_GOT
;
2169 case R_IA64_LTOFF22X
:
2170 need_entry
= NEED_GOTX
;
2173 case R_IA64_PLTOFF22
:
2174 case R_IA64_PLTOFF64I
:
2175 case R_IA64_PLTOFF64MSB
:
2176 case R_IA64_PLTOFF64LSB
:
2177 need_entry
= NEED_PLTOFF
;
2181 need_entry
|= NEED_MIN_PLT
;
2185 case R_IA64_PCREL21B
:
2186 case R_IA64_PCREL60B
:
2187 /* Depending on where this symbol is defined, we may or may not
2188 need a full plt entry. Only skip if we know we'll not need
2189 the entry -- static or symbolic, and the symbol definition
2190 has already been seen. */
2191 if (maybe_dynamic
&& rel
->r_addend
== 0)
2192 need_entry
= NEED_FULL_PLT
;
2198 case R_IA64_DIR32MSB
:
2199 case R_IA64_DIR32LSB
:
2200 case R_IA64_DIR64MSB
:
2201 case R_IA64_DIR64LSB
:
2202 /* Shared objects will always need at least a REL relocation. */
2203 if (bfd_link_pic (info
) || maybe_dynamic
)
2204 need_entry
= NEED_DYNREL
;
2205 dynrel_type
= R_IA64_DIR64LSB
;
2208 case R_IA64_IPLTMSB
:
2209 case R_IA64_IPLTLSB
:
2212 case R_IA64_PCREL22
:
2213 case R_IA64_PCREL64I
:
2214 case R_IA64_PCREL32MSB
:
2215 case R_IA64_PCREL32LSB
:
2216 case R_IA64_PCREL64MSB
:
2217 case R_IA64_PCREL64LSB
:
2219 need_entry
= NEED_DYNREL
;
2220 dynrel_type
= R_IA64_PCREL64LSB
;
2227 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, FALSE
);
2229 /* Record whether or not this is a local symbol. */
2232 /* Create what's needed. */
2233 if (need_entry
& (NEED_GOT
| NEED_GOTX
))
2237 got
= get_got (abfd
, ia64_info
);
2241 if (need_entry
& NEED_GOT
)
2242 dyn_i
->want_got
= 1;
2243 if (need_entry
& NEED_GOTX
)
2244 dyn_i
->want_gotx
= 1;
2246 if (need_entry
& NEED_FPTR
)
2248 /* Create the .opd section. */
2251 fptr
= get_fptr (abfd
, info
, ia64_info
);
2255 dyn_i
->want_fptr
= 1;
2257 if (need_entry
& NEED_LTOFF_FPTR
)
2258 dyn_i
->want_ltoff_fptr
= 1;
2259 if (need_entry
& (NEED_MIN_PLT
| NEED_FULL_PLT
))
2261 if (!ia64_info
->root
.dynobj
)
2262 ia64_info
->root
.dynobj
= abfd
;
2264 dyn_i
->want_plt
= 1;
2266 if (need_entry
& NEED_FULL_PLT
)
2267 dyn_i
->want_plt2
= 1;
2268 if (need_entry
& NEED_PLTOFF
)
2270 /* This is needed here, in case @pltoff is used in a non-shared
2274 pltoff
= get_pltoff (abfd
, ia64_info
);
2279 dyn_i
->want_pltoff
= 1;
2281 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
2285 srel
= get_reloc_section (abfd
, ia64_info
, sec
, TRUE
);
2289 if (!count_dyn_reloc (abfd
, dyn_i
, srel
, dynrel_type
))
2297 /* For cleanliness, and potentially faster dynamic loading, allocate
2298 external GOT entries first. */
2301 allocate_global_data_got (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2304 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2306 if ((dyn_i
->want_got
|| dyn_i
->want_gotx
)
2307 && ! dyn_i
->want_fptr
2308 && elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
2310 /* GOT entry with FPTR is done by allocate_global_fptr_got. */
2311 dyn_i
->got_offset
= x
->ofs
;
2317 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2320 allocate_global_fptr_got (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2323 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2327 && elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
2329 dyn_i
->got_offset
= x
->ofs
;
2335 /* Lastly, allocate all the GOT entries for local data. */
2338 allocate_local_got (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2341 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*) data
;
2343 if ((dyn_i
->want_got
|| dyn_i
->want_gotx
)
2344 && !elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
2346 dyn_i
->got_offset
= x
->ofs
;
2352 /* Allocate function descriptors. We can do these for every function
2353 in a main executable that is not exported. */
2356 allocate_fptr (struct elf64_ia64_dyn_sym_info
*dyn_i
, void * data
)
2358 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*) data
;
2360 if (dyn_i
->want_fptr
)
2362 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2365 while (h
->root
.type
== bfd_link_hash_indirect
2366 || h
->root
.type
== bfd_link_hash_warning
)
2367 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2369 if (h
== NULL
|| !h
->def_dynamic
)
2371 /* A non dynamic symbol. */
2372 dyn_i
->fptr_offset
= x
->ofs
;
2376 dyn_i
->want_fptr
= 0;
2381 /* Allocate all the minimal PLT entries. */
2384 allocate_plt_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2385 void * data ATTRIBUTE_UNUSED
)
2387 if (dyn_i
->want_plt
)
2389 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2392 while (h
->root
.type
== bfd_link_hash_indirect
2393 || h
->root
.type
== bfd_link_hash_warning
)
2394 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2396 /* ??? Versioned symbols seem to lose NEEDS_PLT. */
2397 if (elf64_ia64_dynamic_symbol_p (h
))
2399 dyn_i
->want_pltoff
= 1;
2403 dyn_i
->want_plt
= 0;
2404 dyn_i
->want_plt2
= 0;
2410 /* Allocate all the full PLT entries. */
2413 allocate_plt2_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2416 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2418 if (dyn_i
->want_plt2
)
2420 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2421 bfd_size_type ofs
= x
->ofs
;
2423 dyn_i
->plt2_offset
= ofs
;
2424 x
->ofs
= ofs
+ PLT_FULL_ENTRY_SIZE
;
2426 while (h
->root
.type
== bfd_link_hash_indirect
2427 || h
->root
.type
== bfd_link_hash_warning
)
2428 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2429 dyn_i
->h
->plt
.offset
= ofs
;
2434 /* Allocate all the PLTOFF entries requested by relocations and
2435 plt entries. We can't share space with allocated FPTR entries,
2436 because the latter are not necessarily addressable by the GP.
2437 ??? Relaxation might be able to determine that they are. */
2440 allocate_pltoff_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2443 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2445 if (dyn_i
->want_pltoff
)
2447 dyn_i
->pltoff_offset
= x
->ofs
;
2453 /* Allocate dynamic relocations for those symbols that turned out
2457 allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2460 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2461 struct elf64_ia64_link_hash_table
*ia64_info
;
2462 struct elf64_ia64_dyn_reloc_entry
*rent
;
2463 bfd_boolean dynamic_symbol
, shared
, resolved_zero
;
2464 struct elf64_ia64_link_hash_entry
*h_ia64
;
2466 ia64_info
= elf64_ia64_hash_table (x
->info
);
2467 if (ia64_info
== NULL
)
2470 /* Note that this can't be used in relation to FPTR relocs below. */
2471 dynamic_symbol
= elf64_ia64_dynamic_symbol_p (dyn_i
->h
);
2473 shared
= bfd_link_pic (x
->info
);
2474 resolved_zero
= (dyn_i
->h
2475 && ELF_ST_VISIBILITY (dyn_i
->h
->other
)
2476 && dyn_i
->h
->root
.type
== bfd_link_hash_undefweak
);
2478 /* Take care of the GOT and PLT relocations. */
2481 && (dynamic_symbol
|| shared
)
2482 && (dyn_i
->want_got
|| dyn_i
->want_gotx
))
2483 || (dyn_i
->want_ltoff_fptr
2485 && dyn_i
->h
->def_dynamic
))
2488 if (dyn_i
->h
!= NULL
&& dyn_i
->h
->def_dynamic
)
2490 h_ia64
= (struct elf64_ia64_link_hash_entry
*) dyn_i
->h
;
2491 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2492 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2493 ia64_info
->fixups_sec
->size
+=
2494 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2498 if (ia64_info
->rel_fptr_sec
&& dyn_i
->want_fptr
)
2500 /* VMS: only image reloc. */
2501 if (dyn_i
->h
== NULL
|| dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
)
2502 ia64_info
->rel_fptr_sec
->size
+= sizeof (Elf64_External_Rela
);
2505 if (!resolved_zero
&& dyn_i
->want_pltoff
)
2508 if (dyn_i
->h
!= NULL
&& dyn_i
->h
->def_dynamic
)
2510 h_ia64
= (struct elf64_ia64_link_hash_entry
*) dyn_i
->h
;
2511 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2512 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2513 ia64_info
->fixups_sec
->size
+=
2514 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2518 /* Take care of the normal data relocations. */
2520 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
2522 int count
= rent
->count
;
2526 case R_IA64_FPTR32LSB
:
2527 case R_IA64_FPTR64LSB
:
2528 /* Allocate one iff !want_fptr and not PIE, which by this point
2529 will be true only if we're actually allocating one statically
2530 in the main executable. Position independent executables
2531 need a relative reloc. */
2532 if (dyn_i
->want_fptr
&& !bfd_link_pie (x
->info
))
2535 case R_IA64_PCREL32LSB
:
2536 case R_IA64_PCREL64LSB
:
2537 if (!dynamic_symbol
)
2540 case R_IA64_DIR32LSB
:
2541 case R_IA64_DIR64LSB
:
2542 if (!dynamic_symbol
&& !shared
)
2545 case R_IA64_IPLTLSB
:
2546 if (!dynamic_symbol
&& !shared
)
2548 /* Use two REL relocations for IPLT relocations
2549 against local symbols. */
2550 if (!dynamic_symbol
)
2553 case R_IA64_DTPREL32LSB
:
2554 case R_IA64_TPREL64LSB
:
2555 case R_IA64_DTPREL64LSB
:
2556 case R_IA64_DTPMOD64LSB
:
2563 if (!dynamic_symbol
)
2566 h_ia64
= (struct elf64_ia64_link_hash_entry
*) dyn_i
->h
;
2567 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2568 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2569 ia64_info
->fixups_sec
->size
+=
2570 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2577 elf64_ia64_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2578 struct elf_link_hash_entry
*h
)
2580 /* ??? Undefined symbols with PLT entries should be re-defined
2581 to be the PLT entry. */
2583 /* If this is a weak symbol, and there is a real definition, the
2584 processor independent code will have arranged for us to see the
2585 real definition first, and we can just use the same value. */
2586 if (h
->is_weakalias
)
2588 struct elf_link_hash_entry
*def
= weakdef (h
);
2589 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
2590 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
2591 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
2595 /* If this is a reference to a symbol defined by a dynamic object which
2596 is not a function, we might allocate the symbol in our .dynbss section
2597 and allocate a COPY dynamic relocation.
2599 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
2606 elf64_ia64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2607 struct bfd_link_info
*info
)
2609 struct elf64_ia64_allocate_data data
;
2610 struct elf64_ia64_link_hash_table
*ia64_info
;
2613 struct elf_link_hash_table
*hash_table
;
2615 hash_table
= elf_hash_table (info
);
2616 dynobj
= hash_table
->dynobj
;
2617 ia64_info
= elf64_ia64_hash_table (info
);
2618 if (ia64_info
== NULL
)
2620 BFD_ASSERT(dynobj
!= NULL
);
2623 /* Allocate the GOT entries. */
2625 if (ia64_info
->root
.sgot
)
2628 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_global_data_got
, &data
);
2629 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_global_fptr_got
, &data
);
2630 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_local_got
, &data
);
2631 ia64_info
->root
.sgot
->size
= data
.ofs
;
2634 /* Allocate the FPTR entries. */
2636 if (ia64_info
->fptr_sec
)
2639 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_fptr
, &data
);
2640 ia64_info
->fptr_sec
->size
= data
.ofs
;
2643 /* Now that we've seen all of the input files, we can decide which
2644 symbols need plt entries. Allocate the minimal PLT entries first.
2645 We do this even though dynamic_sections_created may be FALSE, because
2646 this has the side-effect of clearing want_plt and want_plt2. */
2649 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_plt_entries
, &data
);
2651 /* Align the pointer for the plt2 entries. */
2652 data
.ofs
= (data
.ofs
+ 31) & (bfd_vma
) -32;
2654 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_plt2_entries
, &data
);
2655 if (data
.ofs
!= 0 || ia64_info
->root
.dynamic_sections_created
)
2657 /* FIXME: we always reserve the memory for dynamic linker even if
2658 there are no PLT entries since dynamic linker may assume the
2659 reserved memory always exists. */
2661 BFD_ASSERT (ia64_info
->root
.dynamic_sections_created
);
2663 ia64_info
->root
.splt
->size
= data
.ofs
;
2666 /* Allocate the PLTOFF entries. */
2668 if (ia64_info
->pltoff_sec
)
2671 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_pltoff_entries
, &data
);
2672 ia64_info
->pltoff_sec
->size
= data
.ofs
;
2675 if (ia64_info
->root
.dynamic_sections_created
)
2677 /* Allocate space for the dynamic relocations that turned out to be
2679 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_dynrel_entries
, &data
);
2682 /* We have now determined the sizes of the various dynamic sections.
2683 Allocate memory for them. */
2684 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2688 if (!(sec
->flags
& SEC_LINKER_CREATED
))
2691 /* If we don't need this section, strip it from the output file.
2692 There were several sections primarily related to dynamic
2693 linking that must be create before the linker maps input
2694 sections to output sections. The linker does that before
2695 bfd_elf_size_dynamic_sections is called, and it is that
2696 function which decides whether anything needs to go into
2699 strip
= (sec
->size
== 0);
2701 if (sec
== ia64_info
->root
.sgot
)
2703 else if (sec
== ia64_info
->root
.srelgot
)
2706 ia64_info
->root
.srelgot
= NULL
;
2708 /* We use the reloc_count field as a counter if we need to
2709 copy relocs into the output file. */
2710 sec
->reloc_count
= 0;
2712 else if (sec
== ia64_info
->fptr_sec
)
2715 ia64_info
->fptr_sec
= NULL
;
2717 else if (sec
== ia64_info
->rel_fptr_sec
)
2720 ia64_info
->rel_fptr_sec
= NULL
;
2722 /* We use the reloc_count field as a counter if we need to
2723 copy relocs into the output file. */
2724 sec
->reloc_count
= 0;
2726 else if (sec
== ia64_info
->root
.splt
)
2729 ia64_info
->root
.splt
= NULL
;
2731 else if (sec
== ia64_info
->pltoff_sec
)
2734 ia64_info
->pltoff_sec
= NULL
;
2736 else if (sec
== ia64_info
->fixups_sec
)
2739 ia64_info
->fixups_sec
= NULL
;
2741 else if (sec
== ia64_info
->transfer_sec
)
2749 /* It's OK to base decisions on the section name, because none
2750 of the dynobj section names depend upon the input files. */
2751 name
= bfd_section_name (sec
);
2753 if (strcmp (name
, ".got.plt") == 0)
2755 else if (CONST_STRNEQ (name
, ".rel"))
2759 /* We use the reloc_count field as a counter if we need to
2760 copy relocs into the output file. */
2761 sec
->reloc_count
= 0;
2769 sec
->flags
|= SEC_EXCLUDE
;
2772 /* Allocate memory for the section contents. */
2773 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
2774 if (sec
->contents
== NULL
&& sec
->size
!= 0)
2779 if (elf_hash_table (info
)->dynamic_sections_created
)
2783 asection
*dynstrsec
;
2784 Elf_Internal_Dyn dyn
;
2785 const struct elf_backend_data
*bed
;
2786 unsigned int shl_num
= 0;
2787 bfd_vma fixups_off
= 0;
2789 unsigned int time_hi
, time_lo
;
2791 /* The .dynamic section must exist and be empty. */
2792 dynsec
= bfd_get_linker_section (hash_table
->dynobj
, ".dynamic");
2793 BFD_ASSERT (dynsec
!= NULL
);
2794 BFD_ASSERT (dynsec
->size
== 0);
2796 dynstrsec
= bfd_get_linker_section (hash_table
->dynobj
, ".vmsdynstr");
2797 BFD_ASSERT (dynstrsec
!= NULL
);
2798 BFD_ASSERT (dynstrsec
->size
== 0);
2799 dynstrsec
->size
= 1; /* Initial blank. */
2801 /* Ident + link time. */
2802 vms_get_time (&time_hi
, &time_lo
);
2804 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_IDENT
, 0))
2806 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_LINKTIME
,
2807 (((bfd_uint64_t
)time_hi
) << 32)
2812 strdyn_off
= dynsec
->size
;
2813 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_STRTAB_OFFSET
, 0))
2815 if (!_bfd_elf_add_dynamic_entry (info
, DT_STRSZ
, 0))
2819 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_PLTGOT_SEG
, 0))
2821 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_PLTGOT_OFFSET
, 0))
2825 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_FPMODE
, 0x9800000))
2827 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_LNKFLAGS
,
2828 VMS_LF_IMGSTA
| VMS_LF_MAIN
))
2831 /* Add entries for shared libraries. */
2832 for (abfd
= info
->input_bfds
; abfd
; abfd
= abfd
->link
.next
)
2836 bfd_size_type strindex
;
2837 bfd_byte
*newcontents
;
2838 bfd_vma fixups_shl_off
;
2840 if (!(abfd
->flags
& DYNAMIC
))
2842 BFD_ASSERT (abfd
->xvec
== output_bfd
->xvec
);
2844 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_NEEDED_IDENT
,
2845 elf_ia64_vms_ident (abfd
)))
2848 soname
= vms_get_module_name (abfd
->filename
, TRUE
);
2851 strindex
= dynstrsec
->size
;
2852 soname_len
= strlen (soname
) + 1;
2853 newcontents
= (bfd_byte
*) bfd_realloc (dynstrsec
->contents
,
2854 strindex
+ soname_len
);
2855 if (newcontents
== NULL
)
2857 memcpy (newcontents
+ strindex
, soname
, soname_len
);
2858 dynstrsec
->size
+= soname_len
;
2859 dynstrsec
->contents
= newcontents
;
2861 if (!_bfd_elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
2864 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_FIXUP_NEEDED
,
2869 /* The fixups_off was in fact containing the size of the fixup
2870 section. Remap into the offset. */
2871 fixups_shl_off
= elf_ia64_vms_tdata (abfd
)->fixups_off
;
2872 elf_ia64_vms_tdata (abfd
)->fixups_off
= fixups_off
;
2874 if (!_bfd_elf_add_dynamic_entry
2875 (info
, DT_IA_64_VMS_FIXUP_RELA_CNT
,
2876 fixups_shl_off
/ sizeof (Elf64_External_VMS_IMAGE_FIXUP
)))
2878 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_FIXUP_RELA_OFF
,
2881 fixups_off
+= fixups_shl_off
;
2885 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWINDSZ
, 0))
2887 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_CODSEG
, 0))
2889 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_INFOSEG
, 0))
2891 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_OFFSET
, 0))
2893 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_SEG
, 0))
2896 if (!_bfd_elf_add_dynamic_entry (info
, DT_NULL
, 0xdead))
2899 /* Fix the strtab entries. */
2900 bed
= get_elf_backend_data (hash_table
->dynobj
);
2902 if (dynstrsec
->size
> 1)
2903 dynstrsec
->contents
[0] = 0;
2905 dynstrsec
->size
= 0;
2907 /* Note: one 'spare' (ie DT_NULL) entry is added by
2908 bfd_elf_size_dynsym_hash_dynstr. */
2909 dyn
.d_tag
= DT_IA_64_VMS_STRTAB_OFFSET
;
2910 dyn
.d_un
.d_val
= dynsec
->size
/* + sizeof (Elf64_External_Dyn) */;
2911 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
,
2912 dynsec
->contents
+ strdyn_off
);
2914 dyn
.d_tag
= DT_STRSZ
;
2915 dyn
.d_un
.d_val
= dynstrsec
->size
;
2916 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
,
2917 dynsec
->contents
+ strdyn_off
+ bed
->s
->sizeof_dyn
);
2919 elf_ia64_vms_tdata (output_bfd
)->needed_count
= shl_num
;
2922 if (!create_ia64_vms_notes (output_bfd
, info
, time_hi
, time_lo
))
2926 /* ??? Perhaps force __gp local. */
2932 elf64_ia64_install_fixup (bfd
*output_bfd
,
2933 struct elf64_ia64_link_hash_table
*ia64_info
,
2934 struct elf_link_hash_entry
*h
,
2935 unsigned int type
, asection
*sec
, bfd_vma offset
,
2939 Elf64_External_VMS_IMAGE_FIXUP
*fixup
;
2940 struct elf64_ia64_link_hash_entry
*h_ia64
;
2942 Elf_Internal_Phdr
*phdr
;
2944 if (h
== NULL
|| !h
->def_dynamic
)
2947 h_ia64
= (struct elf64_ia64_link_hash_entry
*) h
;
2948 fixoff
= elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
;
2949 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2950 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2951 relsec
= ia64_info
->fixups_sec
;
2953 fixup
= (Elf64_External_VMS_IMAGE_FIXUP
*)(relsec
->contents
+ fixoff
);
2954 offset
+= sec
->output_section
->vma
+ sec
->output_offset
;
2956 /* FIXME: this is slow. We should cache the last one used, or create a
2958 phdr
= _bfd_elf_find_segment_containing_section
2959 (output_bfd
, sec
->output_section
);
2960 BFD_ASSERT (phdr
!= NULL
);
2962 bfd_putl64 (offset
- phdr
->p_vaddr
, fixup
->fixup_offset
);
2963 bfd_putl32 (type
, fixup
->type
);
2964 bfd_putl32 (phdr
- elf_tdata (output_bfd
)->phdr
, fixup
->fixup_seg
);
2965 bfd_putl64 (addend
, fixup
->addend
);
2966 bfd_putl32 (h
->root
.u
.def
.value
, fixup
->symvec_index
);
2967 bfd_putl32 (2, fixup
->data_type
);
2970 /* Store an entry for target address TARGET_ADDR in the linkage table
2971 and return the gp-relative address of the linkage table entry. */
2974 set_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2975 struct elf64_ia64_dyn_sym_info
*dyn_i
,
2976 bfd_vma addend
, bfd_vma value
, unsigned int dyn_r_type
)
2978 struct elf64_ia64_link_hash_table
*ia64_info
;
2983 ia64_info
= elf64_ia64_hash_table (info
);
2984 if (ia64_info
== NULL
)
2987 got_sec
= ia64_info
->root
.sgot
;
2991 case R_IA64_TPREL64LSB
:
2992 case R_IA64_DTPMOD64LSB
:
2993 case R_IA64_DTPREL32LSB
:
2994 case R_IA64_DTPREL64LSB
:
2998 done
= dyn_i
->got_done
;
2999 dyn_i
->got_done
= TRUE
;
3000 got_offset
= dyn_i
->got_offset
;
3004 BFD_ASSERT ((got_offset
& 7) == 0);
3008 /* Store the target address in the linkage table entry. */
3009 bfd_put_64 (abfd
, value
, got_sec
->contents
+ got_offset
);
3011 /* Install a dynamic relocation if needed. */
3012 if (((bfd_link_pic (info
)
3014 || ELF_ST_VISIBILITY (dyn_i
->h
->other
) == STV_DEFAULT
3015 || dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
))
3016 || elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
3017 && (!dyn_i
->want_ltoff_fptr
3018 || !bfd_link_pie (info
)
3020 || dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
))
3022 if (!dyn_i
->h
|| !dyn_i
->h
->def_dynamic
)
3024 dyn_r_type
= R_IA64_REL64LSB
;
3028 /* VMS: install a FIX32 or FIX64. */
3031 case R_IA64_DIR32LSB
:
3032 case R_IA64_FPTR32LSB
:
3033 dyn_r_type
= R_IA64_VMS_FIX32
;
3035 case R_IA64_DIR64LSB
:
3036 case R_IA64_FPTR64LSB
:
3037 dyn_r_type
= R_IA64_VMS_FIX64
;
3043 elf64_ia64_install_fixup
3044 (info
->output_bfd
, ia64_info
, dyn_i
->h
,
3045 dyn_r_type
, got_sec
, got_offset
, addend
);
3049 /* Return the address of the linkage table entry. */
3050 value
= (got_sec
->output_section
->vma
3051 + got_sec
->output_offset
3057 /* Fill in a function descriptor consisting of the function's code
3058 address and its global pointer. Return the descriptor's address. */
3061 set_fptr_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3062 struct elf64_ia64_dyn_sym_info
*dyn_i
,
3065 struct elf64_ia64_link_hash_table
*ia64_info
;
3068 ia64_info
= elf64_ia64_hash_table (info
);
3069 if (ia64_info
== NULL
)
3072 fptr_sec
= ia64_info
->fptr_sec
;
3074 if (!dyn_i
->fptr_done
)
3076 dyn_i
->fptr_done
= 1;
3078 /* Fill in the function descriptor. */
3079 bfd_put_64 (abfd
, value
, fptr_sec
->contents
+ dyn_i
->fptr_offset
);
3080 bfd_put_64 (abfd
, _bfd_get_gp_value (abfd
),
3081 fptr_sec
->contents
+ dyn_i
->fptr_offset
+ 8);
3084 /* Return the descriptor's address. */
3085 value
= (fptr_sec
->output_section
->vma
3086 + fptr_sec
->output_offset
3087 + dyn_i
->fptr_offset
);
3092 /* Fill in a PLTOFF entry consisting of the function's code address
3093 and its global pointer. Return the descriptor's address. */
3096 set_pltoff_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3097 struct elf64_ia64_dyn_sym_info
*dyn_i
,
3098 bfd_vma value
, bfd_boolean is_plt
)
3100 struct elf64_ia64_link_hash_table
*ia64_info
;
3101 asection
*pltoff_sec
;
3103 ia64_info
= elf64_ia64_hash_table (info
);
3104 if (ia64_info
== NULL
)
3107 pltoff_sec
= ia64_info
->pltoff_sec
;
3109 /* Don't do anything if this symbol uses a real PLT entry. In
3110 that case, we'll fill this in during finish_dynamic_symbol. */
3111 if ((! dyn_i
->want_plt
|| is_plt
)
3112 && !dyn_i
->pltoff_done
)
3114 bfd_vma gp
= _bfd_get_gp_value (abfd
);
3116 /* Fill in the function descriptor. */
3117 bfd_put_64 (abfd
, value
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
);
3118 bfd_put_64 (abfd
, gp
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
+ 8);
3120 /* Install dynamic relocations if needed. */
3122 && bfd_link_pic (info
)
3124 || ELF_ST_VISIBILITY (dyn_i
->h
->other
) == STV_DEFAULT
3125 || dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
))
3131 dyn_i
->pltoff_done
= 1;
3134 /* Return the descriptor's address. */
3135 value
= (pltoff_sec
->output_section
->vma
3136 + pltoff_sec
->output_offset
3137 + dyn_i
->pltoff_offset
);
3142 /* Called through qsort to sort the .IA_64.unwind section during a
3143 non-relocatable link. Set elf64_ia64_unwind_entry_compare_bfd
3144 to the output bfd so we can do proper endianness frobbing. */
3146 static bfd
*elf64_ia64_unwind_entry_compare_bfd
;
3149 elf64_ia64_unwind_entry_compare (const void * a
, const void * b
)
3153 av
= bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd
, a
);
3154 bv
= bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd
, b
);
3156 return (av
< bv
? -1 : av
> bv
? 1 : 0);
3159 /* Make sure we've got ourselves a nice fat __gp value. */
3161 elf64_ia64_choose_gp (bfd
*abfd
, struct bfd_link_info
*info
, bfd_boolean final
)
3163 bfd_vma min_vma
= (bfd_vma
) -1, max_vma
= 0;
3164 bfd_vma min_short_vma
= min_vma
, max_short_vma
= 0;
3165 struct elf_link_hash_entry
*gp
;
3168 struct elf64_ia64_link_hash_table
*ia64_info
;
3170 ia64_info
= elf64_ia64_hash_table (info
);
3171 if (ia64_info
== NULL
)
3174 /* Find the min and max vma of all sections marked short. Also collect
3175 min and max vma of any type, for use in selecting a nice gp. */
3176 for (os
= abfd
->sections
; os
; os
= os
->next
)
3180 if ((os
->flags
& SEC_ALLOC
) == 0)
3184 /* When this function is called from elfNN_ia64_final_link
3185 the correct value to use is os->size. When called from
3186 elfNN_ia64_relax_section we are in the middle of section
3187 sizing; some sections will already have os->size set, others
3188 will have os->size zero and os->rawsize the previous size. */
3189 hi
= os
->vma
+ (!final
&& os
->rawsize
? os
->rawsize
: os
->size
);
3197 if (os
->flags
& SEC_SMALL_DATA
)
3199 if (min_short_vma
> lo
)
3201 if (max_short_vma
< hi
)
3206 if (ia64_info
->min_short_sec
)
3209 > (ia64_info
->min_short_sec
->vma
3210 + ia64_info
->min_short_offset
))
3211 min_short_vma
= (ia64_info
->min_short_sec
->vma
3212 + ia64_info
->min_short_offset
);
3214 < (ia64_info
->max_short_sec
->vma
3215 + ia64_info
->max_short_offset
))
3216 max_short_vma
= (ia64_info
->max_short_sec
->vma
3217 + ia64_info
->max_short_offset
);
3220 /* See if the user wants to force a value. */
3221 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
3225 && (gp
->root
.type
== bfd_link_hash_defined
3226 || gp
->root
.type
== bfd_link_hash_defweak
))
3228 asection
*gp_sec
= gp
->root
.u
.def
.section
;
3229 gp_val
= (gp
->root
.u
.def
.value
3230 + gp_sec
->output_section
->vma
3231 + gp_sec
->output_offset
);
3235 /* Pick a sensible value. */
3237 if (ia64_info
->min_short_sec
)
3239 bfd_vma short_range
= max_short_vma
- min_short_vma
;
3241 /* If min_short_sec is set, pick one in the middle bewteen
3242 min_short_vma and max_short_vma. */
3243 if (short_range
>= 0x400000)
3245 gp_val
= min_short_vma
+ short_range
/ 2;
3249 asection
*got_sec
= ia64_info
->root
.sgot
;
3251 /* Start with just the address of the .got. */
3253 gp_val
= got_sec
->output_section
->vma
;
3254 else if (max_short_vma
!= 0)
3255 gp_val
= min_short_vma
;
3256 else if (max_vma
- min_vma
< 0x200000)
3259 gp_val
= max_vma
- 0x200000 + 8;
3262 /* If it is possible to address the entire image, but we
3263 don't with the choice above, adjust. */
3264 if (max_vma
- min_vma
< 0x400000
3265 && (max_vma
- gp_val
>= 0x200000
3266 || gp_val
- min_vma
> 0x200000))
3267 gp_val
= min_vma
+ 0x200000;
3268 else if (max_short_vma
!= 0)
3270 /* If we don't cover all the short data, adjust. */
3271 if (max_short_vma
- gp_val
>= 0x200000)
3272 gp_val
= min_short_vma
+ 0x200000;
3274 /* If we're addressing stuff past the end, adjust back. */
3275 if (gp_val
> max_vma
)
3276 gp_val
= max_vma
- 0x200000 + 8;
3280 /* Validate whether all SHF_IA_64_SHORT sections are within
3281 range of the chosen GP. */
3283 if (max_short_vma
!= 0)
3285 if (max_short_vma
- min_short_vma
>= 0x400000)
3289 /* xgettext:c-format */
3290 (_("%pB: short data segment overflowed (%#" PRIx64
" >= 0x400000)"),
3291 abfd
, (uint64_t) (max_short_vma
- min_short_vma
));
3294 else if ((gp_val
> min_short_vma
3295 && gp_val
- min_short_vma
> 0x200000)
3296 || (gp_val
< max_short_vma
3297 && max_short_vma
- gp_val
>= 0x200000))
3300 (_("%pB: __gp does not cover short data segment"), abfd
);
3305 _bfd_set_gp_value (abfd
, gp_val
);
3311 elf64_ia64_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
3313 struct elf64_ia64_link_hash_table
*ia64_info
;
3314 asection
*unwind_output_sec
;
3316 ia64_info
= elf64_ia64_hash_table (info
);
3317 if (ia64_info
== NULL
)
3320 /* Make sure we've got ourselves a nice fat __gp value. */
3321 if (!bfd_link_relocatable (info
))
3324 struct elf_link_hash_entry
*gp
;
3326 /* We assume after gp is set, section size will only decrease. We
3327 need to adjust gp for it. */
3328 _bfd_set_gp_value (abfd
, 0);
3329 if (! elf64_ia64_choose_gp (abfd
, info
, TRUE
))
3331 gp_val
= _bfd_get_gp_value (abfd
);
3333 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
3337 gp
->root
.type
= bfd_link_hash_defined
;
3338 gp
->root
.u
.def
.value
= gp_val
;
3339 gp
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3343 /* If we're producing a final executable, we need to sort the contents
3344 of the .IA_64.unwind section. Force this section to be relocated
3345 into memory rather than written immediately to the output file. */
3346 unwind_output_sec
= NULL
;
3347 if (!bfd_link_relocatable (info
))
3349 asection
*s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
3352 unwind_output_sec
= s
->output_section
;
3353 unwind_output_sec
->contents
3354 = bfd_malloc (unwind_output_sec
->size
);
3355 if (unwind_output_sec
->contents
== NULL
)
3360 /* Invoke the regular ELF backend linker to do all the work. */
3361 if (!bfd_elf_final_link (abfd
, info
))
3364 if (unwind_output_sec
)
3366 elf64_ia64_unwind_entry_compare_bfd
= abfd
;
3367 qsort (unwind_output_sec
->contents
,
3368 (size_t) (unwind_output_sec
->size
/ 24),
3370 elf64_ia64_unwind_entry_compare
);
3372 if (! bfd_set_section_contents (abfd
, unwind_output_sec
,
3373 unwind_output_sec
->contents
, (bfd_vma
) 0,
3374 unwind_output_sec
->size
))
3382 elf64_ia64_relocate_section (bfd
*output_bfd
,
3383 struct bfd_link_info
*info
,
3385 asection
*input_section
,
3387 Elf_Internal_Rela
*relocs
,
3388 Elf_Internal_Sym
*local_syms
,
3389 asection
**local_sections
)
3391 struct elf64_ia64_link_hash_table
*ia64_info
;
3392 Elf_Internal_Shdr
*symtab_hdr
;
3393 Elf_Internal_Rela
*rel
;
3394 Elf_Internal_Rela
*relend
;
3395 bfd_boolean ret_val
= TRUE
; /* for non-fatal errors */
3398 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3399 ia64_info
= elf64_ia64_hash_table (info
);
3400 if (ia64_info
== NULL
)
3403 /* Infect various flags from the input section to the output section. */
3404 if (bfd_link_relocatable (info
))
3408 flags
= elf_section_data(input_section
)->this_hdr
.sh_flags
;
3409 flags
&= SHF_IA_64_NORECOV
;
3411 elf_section_data(input_section
->output_section
)
3412 ->this_hdr
.sh_flags
|= flags
;
3415 gp_val
= _bfd_get_gp_value (output_bfd
);
3418 relend
= relocs
+ input_section
->reloc_count
;
3419 for (; rel
< relend
; ++rel
)
3421 struct elf_link_hash_entry
*h
;
3422 struct elf64_ia64_dyn_sym_info
*dyn_i
;
3423 bfd_reloc_status_type r
;
3424 reloc_howto_type
*howto
;
3425 unsigned long r_symndx
;
3426 Elf_Internal_Sym
*sym
;
3427 unsigned int r_type
;
3431 bfd_boolean dynamic_symbol_p
;
3432 bfd_boolean undef_weak_ref
;
3434 r_type
= ELF64_R_TYPE (rel
->r_info
);
3435 if (r_type
> R_IA64_MAX_RELOC_CODE
)
3437 /* xgettext:c-format */
3438 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3439 input_bfd
, (int) r_type
);
3440 bfd_set_error (bfd_error_bad_value
);
3445 howto
= ia64_elf_lookup_howto (r_type
);
3451 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3455 undef_weak_ref
= FALSE
;
3457 if (r_symndx
< symtab_hdr
->sh_info
)
3459 /* Reloc against local symbol. */
3461 sym
= local_syms
+ r_symndx
;
3462 sym_sec
= local_sections
[r_symndx
];
3464 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &msec
, rel
);
3465 if (!bfd_link_relocatable (info
)
3466 && (sym_sec
->flags
& SEC_MERGE
) != 0
3467 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3468 && sym_sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
3470 struct elf64_ia64_local_hash_entry
*loc_h
;
3472 loc_h
= get_local_sym_hash (ia64_info
, input_bfd
, rel
, FALSE
);
3473 if (loc_h
&& ! loc_h
->sec_merge_done
)
3475 struct elf64_ia64_dyn_sym_info
*dynent
;
3478 for (count
= loc_h
->count
, dynent
= loc_h
->info
;
3484 _bfd_merged_section_offset (output_bfd
, &msec
,
3485 elf_section_data (msec
)->
3489 dynent
->addend
-= sym
->st_value
;
3490 dynent
->addend
+= msec
->output_section
->vma
3491 + msec
->output_offset
3492 - sym_sec
->output_section
->vma
3493 - sym_sec
->output_offset
;
3496 /* We may have introduced duplicated entries. We need
3497 to remove them properly. */
3498 count
= sort_dyn_sym_info (loc_h
->info
, loc_h
->count
);
3499 if (count
!= loc_h
->count
)
3501 loc_h
->count
= count
;
3502 loc_h
->sorted_count
= count
;
3505 loc_h
->sec_merge_done
= 1;
3511 bfd_boolean unresolved_reloc
;
3512 bfd_boolean warned
, ignored
;
3513 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3515 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3516 r_symndx
, symtab_hdr
, sym_hashes
,
3518 unresolved_reloc
, warned
, ignored
);
3520 if (h
->root
.type
== bfd_link_hash_undefweak
)
3521 undef_weak_ref
= TRUE
;
3526 /* For relocs against symbols from removed linkonce sections,
3527 or sections discarded by a linker script, we just want the
3528 section contents zeroed. Avoid any special processing. */
3529 if (sym_sec
!= NULL
&& discarded_section (sym_sec
))
3530 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3531 rel
, 1, relend
, howto
, 0, contents
);
3533 if (bfd_link_relocatable (info
))
3536 hit_addr
= contents
+ rel
->r_offset
;
3537 value
+= rel
->r_addend
;
3538 dynamic_symbol_p
= elf64_ia64_dynamic_symbol_p (h
);
3549 case R_IA64_DIR32MSB
:
3550 case R_IA64_DIR32LSB
:
3551 case R_IA64_DIR64MSB
:
3552 case R_IA64_DIR64LSB
:
3553 /* Install a dynamic relocation for this reloc. */
3554 if ((dynamic_symbol_p
|| bfd_link_pic (info
))
3556 && (input_section
->flags
& SEC_ALLOC
) != 0)
3558 unsigned int dyn_r_type
;
3566 /* ??? People shouldn't be doing non-pic code in
3567 shared libraries nor dynamic executables. */
3569 /* xgettext:c-format */
3570 (_("%pB: non-pic code with imm relocation against"
3571 " dynamic symbol `%s'"),
3573 h
? h
->root
.root
.string
3574 : bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3583 /* If we don't need dynamic symbol lookup, find a
3584 matching RELATIVE relocation. */
3585 dyn_r_type
= r_type
;
3586 if (dynamic_symbol_p
)
3588 addend
= rel
->r_addend
;
3596 /* VMS: install a FIX64. */
3599 case R_IA64_DIR32LSB
:
3600 dyn_r_type
= R_IA64_VMS_FIX32
;
3602 case R_IA64_DIR64LSB
:
3603 dyn_r_type
= R_IA64_VMS_FIX64
;
3609 elf64_ia64_install_fixup
3610 (output_bfd
, ia64_info
, h
,
3611 dyn_r_type
, input_section
, rel
->r_offset
, addend
);
3617 case R_IA64_LTV32MSB
:
3618 case R_IA64_LTV32LSB
:
3619 case R_IA64_LTV64MSB
:
3620 case R_IA64_LTV64LSB
:
3621 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3624 case R_IA64_GPREL22
:
3625 case R_IA64_GPREL64I
:
3626 case R_IA64_GPREL32MSB
:
3627 case R_IA64_GPREL32LSB
:
3628 case R_IA64_GPREL64MSB
:
3629 case R_IA64_GPREL64LSB
:
3630 if (dynamic_symbol_p
)
3633 /* xgettext:c-format */
3634 (_("%pB: @gprel relocation against dynamic symbol %s"),
3636 h
? h
->root
.root
.string
3637 : bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3643 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3646 case R_IA64_LTOFF22
:
3647 case R_IA64_LTOFF22X
:
3648 case R_IA64_LTOFF64I
:
3649 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3650 value
= set_got_entry (input_bfd
, info
, dyn_i
,
3651 rel
->r_addend
, value
, R_IA64_DIR64LSB
);
3653 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3656 case R_IA64_PLTOFF22
:
3657 case R_IA64_PLTOFF64I
:
3658 case R_IA64_PLTOFF64MSB
:
3659 case R_IA64_PLTOFF64LSB
:
3660 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3661 value
= set_pltoff_entry (output_bfd
, info
, dyn_i
, value
, FALSE
);
3663 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3666 case R_IA64_FPTR64I
:
3667 case R_IA64_FPTR32MSB
:
3668 case R_IA64_FPTR32LSB
:
3669 case R_IA64_FPTR64MSB
:
3670 case R_IA64_FPTR64LSB
:
3671 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3672 if (dyn_i
->want_fptr
)
3674 if (!undef_weak_ref
)
3675 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3677 if (!dyn_i
->want_fptr
|| bfd_link_pie (info
))
3679 /* Otherwise, we expect the dynamic linker to create
3682 if (dyn_i
->want_fptr
)
3684 if (r_type
== R_IA64_FPTR64I
)
3686 /* We can't represent this without a dynamic symbol.
3687 Adjust the relocation to be against an output
3688 section symbol, which are always present in the
3689 dynamic symbol table. */
3690 /* ??? People shouldn't be doing non-pic code in
3691 shared libraries. Hork. */
3693 (_("%pB: linking non-pic code in a position independent executable"),
3705 elf64_ia64_install_fixup
3706 (output_bfd
, ia64_info
, h
, R_IA64_VMS_FIXFD
,
3707 input_section
, rel
->r_offset
, 0);
3712 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3715 case R_IA64_LTOFF_FPTR22
:
3716 case R_IA64_LTOFF_FPTR64I
:
3717 case R_IA64_LTOFF_FPTR32MSB
:
3718 case R_IA64_LTOFF_FPTR32LSB
:
3719 case R_IA64_LTOFF_FPTR64MSB
:
3720 case R_IA64_LTOFF_FPTR64LSB
:
3721 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3722 if (dyn_i
->want_fptr
)
3724 BFD_ASSERT (h
== NULL
|| !h
->def_dynamic
);
3725 if (!undef_weak_ref
)
3726 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3731 value
= set_got_entry (output_bfd
, info
, dyn_i
,
3732 rel
->r_addend
, value
, R_IA64_FPTR64LSB
);
3734 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3737 case R_IA64_PCREL32MSB
:
3738 case R_IA64_PCREL32LSB
:
3739 case R_IA64_PCREL64MSB
:
3740 case R_IA64_PCREL64LSB
:
3741 /* Install a dynamic relocation for this reloc. */
3742 if (dynamic_symbol_p
&& r_symndx
!= 0)
3744 /* VMS: doesn't exist ??? */
3749 case R_IA64_PCREL21B
:
3750 case R_IA64_PCREL60B
:
3751 /* We should have created a PLT entry for any dynamic symbol. */
3754 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, FALSE
);
3756 if (dyn_i
&& dyn_i
->want_plt2
)
3758 /* Should have caught this earlier. */
3759 BFD_ASSERT (rel
->r_addend
== 0);
3761 value
= (ia64_info
->root
.splt
->output_section
->vma
3762 + ia64_info
->root
.splt
->output_offset
3763 + dyn_i
->plt2_offset
);
3767 /* Since there's no PLT entry, Validate that this is
3769 BFD_ASSERT (undef_weak_ref
|| sym_sec
->output_section
!= NULL
);
3771 /* If the symbol is undef_weak, we shouldn't be trying
3772 to call it. There's every chance that we'd wind up
3773 with an out-of-range fixup here. Don't bother setting
3774 any value at all. */
3780 case R_IA64_PCREL21BI
:
3781 case R_IA64_PCREL21F
:
3782 case R_IA64_PCREL21M
:
3783 case R_IA64_PCREL22
:
3784 case R_IA64_PCREL64I
:
3785 /* The PCREL21BI reloc is specifically not intended for use with
3786 dynamic relocs. PCREL21F and PCREL21M are used for speculation
3787 fixup code, and thus probably ought not be dynamic. The
3788 PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */
3789 if (dynamic_symbol_p
)
3793 if (r_type
== R_IA64_PCREL21BI
)
3794 /* xgettext:c-format */
3795 msg
= _("%pB: @internal branch to dynamic symbol %s");
3796 else if (r_type
== R_IA64_PCREL21F
|| r_type
== R_IA64_PCREL21M
)
3797 /* xgettext:c-format */
3798 msg
= _("%pB: speculation fixup to dynamic symbol %s");
3800 /* xgettext:c-format */
3801 msg
= _("%pB: @pcrel relocation against dynamic symbol %s");
3802 _bfd_error_handler (msg
, input_bfd
,
3803 h
? h
->root
.root
.string
3804 : bfd_elf_sym_name (input_bfd
,
3814 /* Make pc-relative. */
3815 value
-= (input_section
->output_section
->vma
3816 + input_section
->output_offset
3817 + rel
->r_offset
) & ~ (bfd_vma
) 0x3;
3818 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3821 case R_IA64_SEGREL32MSB
:
3822 case R_IA64_SEGREL32LSB
:
3823 case R_IA64_SEGREL64MSB
:
3824 case R_IA64_SEGREL64LSB
:
3826 /* Find the segment that contains the output_section. */
3827 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section
3828 (output_bfd
, sym_sec
->output_section
);
3832 r
= bfd_reloc_notsupported
;
3836 /* The VMA of the segment is the vaddr of the associated
3838 if (value
> p
->p_vaddr
)
3839 value
-= p
->p_vaddr
;
3842 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3847 case R_IA64_SECREL32MSB
:
3848 case R_IA64_SECREL32LSB
:
3849 case R_IA64_SECREL64MSB
:
3850 case R_IA64_SECREL64LSB
:
3851 /* Make output-section relative to section where the symbol
3852 is defined. PR 475 */
3854 value
-= sym_sec
->output_section
->vma
;
3855 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3858 case R_IA64_IPLTMSB
:
3859 case R_IA64_IPLTLSB
:
3860 /* Install a dynamic relocation for this reloc. */
3861 if ((dynamic_symbol_p
|| bfd_link_pic (info
))
3862 && (input_section
->flags
& SEC_ALLOC
) != 0)
3868 if (r_type
== R_IA64_IPLTMSB
)
3869 r_type
= R_IA64_DIR64MSB
;
3871 r_type
= R_IA64_DIR64LSB
;
3872 ia64_elf_install_value (hit_addr
, value
, r_type
);
3873 r
= ia64_elf_install_value (hit_addr
+ 8, gp_val
, r_type
);
3876 case R_IA64_TPREL14
:
3877 case R_IA64_TPREL22
:
3878 case R_IA64_TPREL64I
:
3879 r
= bfd_reloc_notsupported
;
3882 case R_IA64_DTPREL14
:
3883 case R_IA64_DTPREL22
:
3884 case R_IA64_DTPREL64I
:
3885 case R_IA64_DTPREL32LSB
:
3886 case R_IA64_DTPREL32MSB
:
3887 case R_IA64_DTPREL64LSB
:
3888 case R_IA64_DTPREL64MSB
:
3889 r
= bfd_reloc_notsupported
;
3892 case R_IA64_LTOFF_TPREL22
:
3893 case R_IA64_LTOFF_DTPMOD22
:
3894 case R_IA64_LTOFF_DTPREL22
:
3895 r
= bfd_reloc_notsupported
;
3899 r
= bfd_reloc_notsupported
;
3908 case bfd_reloc_undefined
:
3909 /* This can happen for global table relative relocs if
3910 __gp is undefined. This is a panic situation so we
3911 don't try to continue. */
3912 (*info
->callbacks
->undefined_symbol
)
3913 (info
, "__gp", input_bfd
, input_section
, rel
->r_offset
, 1);
3916 case bfd_reloc_notsupported
:
3921 name
= h
->root
.root
.string
;
3923 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3925 (*info
->callbacks
->warning
) (info
, _("unsupported reloc"),
3927 input_section
, rel
->r_offset
);
3932 case bfd_reloc_dangerous
:
3933 case bfd_reloc_outofrange
:
3934 case bfd_reloc_overflow
:
3940 name
= h
->root
.root
.string
;
3942 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3947 case R_IA64_TPREL14
:
3948 case R_IA64_TPREL22
:
3949 case R_IA64_TPREL64I
:
3950 case R_IA64_DTPREL14
:
3951 case R_IA64_DTPREL22
:
3952 case R_IA64_DTPREL64I
:
3953 case R_IA64_DTPREL32LSB
:
3954 case R_IA64_DTPREL32MSB
:
3955 case R_IA64_DTPREL64LSB
:
3956 case R_IA64_DTPREL64MSB
:
3957 case R_IA64_LTOFF_TPREL22
:
3958 case R_IA64_LTOFF_DTPMOD22
:
3959 case R_IA64_LTOFF_DTPREL22
:
3961 /* xgettext:c-format */
3962 (_("%pB: missing TLS section for relocation %s against `%s'"
3963 " at %#" PRIx64
" in section `%pA'."),
3964 input_bfd
, howto
->name
, name
,
3965 (uint64_t) rel
->r_offset
, input_section
);
3968 case R_IA64_PCREL21B
:
3969 case R_IA64_PCREL21BI
:
3970 case R_IA64_PCREL21M
:
3971 case R_IA64_PCREL21F
:
3972 if (is_elf_hash_table (info
->hash
))
3974 /* Relaxtion is always performed for ELF output.
3975 Overflow failures for those relocations mean
3976 that the section is too big to relax. */
3978 /* xgettext:c-format */
3979 (_("%pB: Can't relax br (%s) to `%s' "
3980 "at %#" PRIx64
" in section `%pA' "
3981 "with size %#" PRIx64
" (> 0x1000000)."),
3982 input_bfd
, howto
->name
, name
, (uint64_t) rel
->r_offset
,
3983 input_section
, (uint64_t) input_section
->size
);
3988 (*info
->callbacks
->reloc_overflow
) (info
,
4009 elf64_ia64_finish_dynamic_symbol (bfd
*output_bfd
,
4010 struct bfd_link_info
*info
,
4011 struct elf_link_hash_entry
*h
,
4012 Elf_Internal_Sym
*sym
)
4014 struct elf64_ia64_link_hash_table
*ia64_info
;
4015 struct elf64_ia64_dyn_sym_info
*dyn_i
;
4017 ia64_info
= elf64_ia64_hash_table (info
);
4018 if (ia64_info
== NULL
)
4021 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, FALSE
);
4023 /* Fill in the PLT data, if required. */
4024 if (dyn_i
&& dyn_i
->want_plt
)
4028 bfd_vma plt_addr
, pltoff_addr
, gp_val
;
4030 gp_val
= _bfd_get_gp_value (output_bfd
);
4032 plt_sec
= ia64_info
->root
.splt
;
4033 plt_addr
= 0; /* Not used as overriden by FIXUPs. */
4034 pltoff_addr
= set_pltoff_entry (output_bfd
, info
, dyn_i
, plt_addr
, TRUE
);
4036 /* Initialize the FULL PLT entry, if needed. */
4037 if (dyn_i
->want_plt2
)
4039 loc
= plt_sec
->contents
+ dyn_i
->plt2_offset
;
4041 memcpy (loc
, plt_full_entry
, PLT_FULL_ENTRY_SIZE
);
4042 ia64_elf_install_value (loc
, pltoff_addr
- gp_val
, R_IA64_IMM22
);
4044 /* Mark the symbol as undefined, rather than as defined in the
4045 plt section. Leave the value alone. */
4046 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4047 first place. But perhaps elflink.c did some for us. */
4048 if (!h
->def_regular
)
4049 sym
->st_shndx
= SHN_UNDEF
;
4053 elf64_ia64_install_fixup
4054 (output_bfd
, ia64_info
, h
, R_IA64_VMS_FIXFD
, ia64_info
->pltoff_sec
,
4055 pltoff_addr
- (ia64_info
->pltoff_sec
->output_section
->vma
4056 + ia64_info
->pltoff_sec
->output_offset
), 0);
4059 /* Mark some specially defined symbols as absolute. */
4060 if (h
== ia64_info
->root
.hdynamic
4061 || h
== ia64_info
->root
.hgot
4062 || h
== ia64_info
->root
.hplt
)
4063 sym
->st_shndx
= SHN_ABS
;
4069 elf64_ia64_finish_dynamic_sections (bfd
*abfd
,
4070 struct bfd_link_info
*info
)
4072 struct elf64_ia64_link_hash_table
*ia64_info
;
4075 ia64_info
= elf64_ia64_hash_table (info
);
4076 if (ia64_info
== NULL
)
4079 dynobj
= ia64_info
->root
.dynobj
;
4081 if (elf_hash_table (info
)->dynamic_sections_created
)
4083 Elf64_External_Dyn
*dyncon
, *dynconend
;
4085 asection
*unwind_sec
;
4087 unsigned int gp_seg
;
4089 Elf_Internal_Phdr
*phdr
;
4090 Elf_Internal_Phdr
*base_phdr
;
4091 unsigned int unwind_seg
= 0;
4092 unsigned int code_seg
= 0;
4094 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4095 BFD_ASSERT (sdyn
!= NULL
);
4096 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4097 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4099 gp_val
= _bfd_get_gp_value (abfd
);
4100 phdr
= _bfd_elf_find_segment_containing_section
4101 (info
->output_bfd
, ia64_info
->pltoff_sec
->output_section
);
4102 BFD_ASSERT (phdr
!= NULL
);
4103 base_phdr
= elf_tdata (info
->output_bfd
)->phdr
;
4104 gp_seg
= phdr
- base_phdr
;
4105 gp_off
= gp_val
- phdr
->p_vaddr
;
4107 unwind_sec
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
4108 if (unwind_sec
!= NULL
)
4112 phdr
= _bfd_elf_find_segment_containing_section (abfd
, unwind_sec
);
4113 BFD_ASSERT (phdr
!= NULL
);
4114 unwind_seg
= phdr
- base_phdr
;
4116 code_sec
= bfd_get_section_by_name (abfd
, "$CODE$");
4117 phdr
= _bfd_elf_find_segment_containing_section (abfd
, code_sec
);
4118 BFD_ASSERT (phdr
!= NULL
);
4119 code_seg
= phdr
- base_phdr
;
4122 for (; dyncon
< dynconend
; dyncon
++)
4124 Elf_Internal_Dyn dyn
;
4126 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4130 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
4132 (ia64_info
->fixups_sec
->output_section
->vma
4133 + ia64_info
->fixups_sec
->output_offset
)
4134 - (sdyn
->output_section
->vma
+ sdyn
->output_offset
);
4137 case DT_IA_64_VMS_PLTGOT_OFFSET
:
4138 dyn
.d_un
.d_val
= gp_off
;
4141 case DT_IA_64_VMS_PLTGOT_SEG
:
4142 dyn
.d_un
.d_val
= gp_seg
;
4145 case DT_IA_64_VMS_UNWINDSZ
:
4146 if (unwind_sec
== NULL
)
4148 dyn
.d_tag
= DT_NULL
;
4149 dyn
.d_un
.d_val
= 0xdead;
4152 dyn
.d_un
.d_val
= unwind_sec
->size
;
4155 case DT_IA_64_VMS_UNWIND_CODSEG
:
4156 dyn
.d_un
.d_val
= code_seg
;
4159 case DT_IA_64_VMS_UNWIND_INFOSEG
:
4160 case DT_IA_64_VMS_UNWIND_SEG
:
4161 dyn
.d_un
.d_val
= unwind_seg
;
4164 case DT_IA_64_VMS_UNWIND_OFFSET
:
4168 /* No need to rewrite the entry. */
4172 bfd_elf64_swap_dyn_out (abfd
, &dyn
, dyncon
);
4176 /* Handle transfer addresses. */
4178 asection
*tfr_sec
= ia64_info
->transfer_sec
;
4179 struct elf64_vms_transfer
*tfr
;
4180 struct elf_link_hash_entry
*tfr3
;
4182 tfr
= (struct elf64_vms_transfer
*)tfr_sec
->contents
;
4183 bfd_putl32 (6 * 8, tfr
->size
);
4184 bfd_putl64 (tfr_sec
->output_section
->vma
4185 + tfr_sec
->output_offset
4186 + 6 * 8, tfr
->tfradr3
);
4188 tfr3
= elf_link_hash_lookup (elf_hash_table (info
), "ELF$TFRADR", FALSE
,
4192 && (tfr3
->root
.type
== bfd_link_hash_defined
4193 || tfr3
->root
.type
== bfd_link_hash_defweak
))
4195 asection
*tfr3_sec
= tfr3
->root
.u
.def
.section
;
4198 tfr3_val
= (tfr3
->root
.u
.def
.value
4199 + tfr3_sec
->output_section
->vma
4200 + tfr3_sec
->output_offset
);
4202 bfd_putl64 (tfr3_val
, tfr
->tfr3_func
);
4203 bfd_putl64 (_bfd_get_gp_value (info
->output_bfd
), tfr
->tfr3_gp
);
4206 /* FIXME: set linker flags,
4207 handle lib$initialize. */
4213 /* ELF file flag handling: */
4215 /* Function to keep IA-64 specific file flags. */
4217 elf64_ia64_set_private_flags (bfd
*abfd
, flagword flags
)
4219 BFD_ASSERT (!elf_flags_init (abfd
)
4220 || elf_elfheader (abfd
)->e_flags
== flags
);
4222 elf_elfheader (abfd
)->e_flags
= flags
;
4223 elf_flags_init (abfd
) = TRUE
;
4227 /* Merge backend specific data from an object file to the output
4228 object file when linking. */
4230 elf64_ia64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
4232 bfd
*obfd
= info
->output_bfd
;
4235 bfd_boolean ok
= TRUE
;
4237 /* Don't even pretend to support mixed-format linking. */
4238 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4239 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4242 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4243 out_flags
= elf_elfheader (obfd
)->e_flags
;
4245 if (! elf_flags_init (obfd
))
4247 elf_flags_init (obfd
) = TRUE
;
4248 elf_elfheader (obfd
)->e_flags
= in_flags
;
4250 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
4251 && bfd_get_arch_info (obfd
)->the_default
)
4253 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
4254 bfd_get_mach (ibfd
));
4260 /* Check flag compatibility. */
4261 if (in_flags
== out_flags
)
4264 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4265 if (!(in_flags
& EF_IA_64_REDUCEDFP
) && (out_flags
& EF_IA_64_REDUCEDFP
))
4266 elf_elfheader (obfd
)->e_flags
&= ~EF_IA_64_REDUCEDFP
;
4268 if ((in_flags
& EF_IA_64_TRAPNIL
) != (out_flags
& EF_IA_64_TRAPNIL
))
4271 (_("%pB: linking trap-on-NULL-dereference with non-trapping files"),
4274 bfd_set_error (bfd_error_bad_value
);
4277 if ((in_flags
& EF_IA_64_BE
) != (out_flags
& EF_IA_64_BE
))
4280 (_("%pB: linking big-endian files with little-endian files"),
4283 bfd_set_error (bfd_error_bad_value
);
4286 if ((in_flags
& EF_IA_64_ABI64
) != (out_flags
& EF_IA_64_ABI64
))
4289 (_("%pB: linking 64-bit files with 32-bit files"),
4292 bfd_set_error (bfd_error_bad_value
);
4295 if ((in_flags
& EF_IA_64_CONS_GP
) != (out_flags
& EF_IA_64_CONS_GP
))
4298 (_("%pB: linking constant-gp files with non-constant-gp files"),
4301 bfd_set_error (bfd_error_bad_value
);
4304 if ((in_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
)
4305 != (out_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4308 (_("%pB: linking auto-pic files with non-auto-pic files"),
4311 bfd_set_error (bfd_error_bad_value
);
4319 elf64_ia64_print_private_bfd_data (bfd
*abfd
, void * ptr
)
4321 FILE *file
= (FILE *) ptr
;
4322 flagword flags
= elf_elfheader (abfd
)->e_flags
;
4324 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4326 fprintf (file
, "private flags = %s%s%s%s%s%s%s%s\n",
4327 (flags
& EF_IA_64_TRAPNIL
) ? "TRAPNIL, " : "",
4328 (flags
& EF_IA_64_EXT
) ? "EXT, " : "",
4329 (flags
& EF_IA_64_BE
) ? "BE, " : "LE, ",
4330 (flags
& EF_IA_64_REDUCEDFP
) ? "REDUCEDFP, " : "",
4331 (flags
& EF_IA_64_CONS_GP
) ? "CONS_GP, " : "",
4332 (flags
& EF_IA_64_NOFUNCDESC_CONS_GP
) ? "NOFUNCDESC_CONS_GP, " : "",
4333 (flags
& EF_IA_64_ABSOLUTE
) ? "ABSOLUTE, " : "",
4334 (flags
& EF_IA_64_ABI64
) ? "ABI64" : "ABI32");
4336 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4340 static enum elf_reloc_type_class
4341 elf64_ia64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4342 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4343 const Elf_Internal_Rela
*rela
)
4345 switch ((int) ELF64_R_TYPE (rela
->r_info
))
4347 case R_IA64_REL32MSB
:
4348 case R_IA64_REL32LSB
:
4349 case R_IA64_REL64MSB
:
4350 case R_IA64_REL64LSB
:
4351 return reloc_class_relative
;
4352 case R_IA64_IPLTMSB
:
4353 case R_IA64_IPLTLSB
:
4354 return reloc_class_plt
;
4356 return reloc_class_copy
;
4358 return reloc_class_normal
;
4362 static const struct bfd_elf_special_section elf64_ia64_special_sections
[] =
4364 { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_IA_64_SHORT
},
4365 { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_IA_64_SHORT
},
4366 { NULL
, 0, 0, 0, 0 }
4370 elf64_ia64_object_p (bfd
*abfd
)
4373 asection
*group
, *unwi
, *unw
;
4376 char *unwi_name
, *unw_name
;
4379 if (abfd
->flags
& DYNAMIC
)
4382 /* Flags for fake group section. */
4383 flags
= (SEC_LINKER_CREATED
| SEC_GROUP
| SEC_LINK_ONCE
4386 /* We add a fake section group for each .gnu.linkonce.t.* section,
4387 which isn't in a section group, and its unwind sections. */
4388 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4390 if (elf_sec_group (sec
) == NULL
4391 && ((sec
->flags
& (SEC_LINK_ONCE
| SEC_CODE
| SEC_GROUP
))
4392 == (SEC_LINK_ONCE
| SEC_CODE
))
4393 && CONST_STRNEQ (sec
->name
, ".gnu.linkonce.t."))
4395 name
= sec
->name
+ 16;
4397 amt
= strlen (name
) + sizeof (".gnu.linkonce.ia64unwi.");
4398 unwi_name
= bfd_alloc (abfd
, amt
);
4402 strcpy (stpcpy (unwi_name
, ".gnu.linkonce.ia64unwi."), name
);
4403 unwi
= bfd_get_section_by_name (abfd
, unwi_name
);
4405 amt
= strlen (name
) + sizeof (".gnu.linkonce.ia64unw.");
4406 unw_name
= bfd_alloc (abfd
, amt
);
4410 strcpy (stpcpy (unw_name
, ".gnu.linkonce.ia64unw."), name
);
4411 unw
= bfd_get_section_by_name (abfd
, unw_name
);
4413 /* We need to create a fake group section for it and its
4415 group
= bfd_make_section_anyway_with_flags (abfd
, name
,
4420 /* Move the fake group section to the beginning. */
4421 bfd_section_list_remove (abfd
, group
);
4422 bfd_section_list_prepend (abfd
, group
);
4424 elf_next_in_group (group
) = sec
;
4426 elf_group_name (sec
) = name
;
4427 elf_next_in_group (sec
) = sec
;
4428 elf_sec_group (sec
) = group
;
4432 elf_group_name (unwi
) = name
;
4433 elf_next_in_group (unwi
) = sec
;
4434 elf_next_in_group (sec
) = unwi
;
4435 elf_sec_group (unwi
) = group
;
4440 elf_group_name (unw
) = name
;
4443 elf_next_in_group (unw
) = elf_next_in_group (unwi
);
4444 elf_next_in_group (unwi
) = unw
;
4448 elf_next_in_group (unw
) = sec
;
4449 elf_next_in_group (sec
) = unw
;
4451 elf_sec_group (unw
) = group
;
4454 /* Fake SHT_GROUP section header. */
4455 elf_section_data (group
)->this_hdr
.bfd_section
= group
;
4456 elf_section_data (group
)->this_hdr
.sh_type
= SHT_GROUP
;
4462 /* Handle an IA-64 specific section when reading an object file. This
4463 is called when bfd_section_from_shdr finds a section with an unknown
4467 elf64_vms_section_from_shdr (bfd
*abfd
,
4468 Elf_Internal_Shdr
*hdr
,
4472 flagword secflags
= 0;
4474 switch (hdr
->sh_type
)
4476 case SHT_IA_64_VMS_TRACE
:
4477 case SHT_IA_64_VMS_DEBUG
:
4478 case SHT_IA_64_VMS_DEBUG_STR
:
4479 secflags
= SEC_DEBUGGING
;
4482 case SHT_IA_64_UNWIND
:
4483 case SHT_IA_64_HP_OPT_ANOT
:
4487 if (strcmp (name
, ELF_STRING_ia64_archext
) != 0)
4495 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4500 asection
*newsect
= hdr
->bfd_section
;
4502 if (!bfd_set_section_flags (newsect
,
4503 bfd_section_flags (newsect
) | secflags
))
4511 elf64_vms_object_p (bfd
*abfd
)
4513 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4514 Elf_Internal_Phdr
*i_phdr
= elf_tdata (abfd
)->phdr
;
4516 unsigned int num_text
= 0;
4517 unsigned int num_data
= 0;
4518 unsigned int num_rodata
= 0;
4521 if (!elf64_ia64_object_p (abfd
))
4524 /* Many VMS compilers do not generate sections for the corresponding
4525 segment. This is boring as binutils tools won't be able to disassemble
4526 the code. So we simply create all the missing sections. */
4527 for (i
= 0; i
< i_ehdrp
->e_phnum
; i
++, i_phdr
++)
4529 /* Is there a section for this segment? */
4530 bfd_vma base_vma
= i_phdr
->p_vaddr
;
4531 bfd_vma limit_vma
= base_vma
+ i_phdr
->p_filesz
;
4533 if (i_phdr
->p_type
!= PT_LOAD
)
4536 /* We need to cover from base_vms to limit_vma. */
4538 while (base_vma
< limit_vma
)
4540 bfd_vma next_vma
= limit_vma
;
4546 /* Find a section covering [base_vma;limit_vma) */
4547 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4549 /* Skip uninteresting sections (either not in memory or
4551 if ((sec
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == 0
4552 || sec
->vma
+ sec
->size
<= base_vma
)
4554 if (sec
->vma
<= base_vma
)
4556 /* This section covers (maybe partially) the beginning
4558 base_vma
= sec
->vma
+ sec
->size
;
4561 if (sec
->vma
< next_vma
)
4563 /* This section partially covers the end of the range.
4564 Used to compute the size of the hole. */
4565 next_vma
= sec
->vma
;
4569 /* No section covering [base_vma; next_vma). Create a fake one. */
4570 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
4571 if (i_phdr
->p_flags
& PF_X
)
4574 if (num_text
++ == 0)
4577 sprintf (name
, ".text$%u", num_text
);
4579 else if ((i_phdr
->p_flags
& (PF_R
| PF_W
)) == PF_R
)
4581 flags
|= SEC_READONLY
;
4582 sprintf (name
, ".rodata$%u", num_rodata
++);
4587 sprintf (name
, ".data$%u", num_data
++);
4590 /* Allocate name. */
4593 size_t name_len
= strlen (name
) + 1;
4594 nname
= bfd_alloc (abfd
, name_len
);
4597 memcpy (nname
, name
, name_len
);
4600 /* Create and fill new section. */
4601 nsec
= bfd_make_section_anyway_with_flags (abfd
, nname
, flags
);
4604 nsec
->vma
= base_vma
;
4605 nsec
->size
= next_vma
- base_vma
;
4606 nsec
->filepos
= i_phdr
->p_offset
+ (base_vma
- i_phdr
->p_vaddr
);
4608 base_vma
= next_vma
;
4615 elf64_vms_init_file_header (bfd
*abfd
, struct bfd_link_info
*info
)
4617 Elf_Internal_Ehdr
*i_ehdrp
;
4619 if (!_bfd_elf_init_file_header (abfd
, info
))
4622 i_ehdrp
= elf_elfheader (abfd
);
4623 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_OPENVMS
;
4624 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 2;
4629 elf64_vms_section_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4630 Elf_Internal_Shdr
*hdr
)
4632 if (hdr
->bfd_section
!= NULL
)
4634 const char *name
= bfd_section_name (hdr
->bfd_section
);
4636 if (strcmp (name
, ".text") == 0)
4637 hdr
->sh_flags
|= SHF_IA_64_VMS_SHARED
;
4638 else if ((strcmp (name
, ".debug") == 0)
4639 || (strcmp (name
, ".debug_abbrev") == 0)
4640 || (strcmp (name
, ".debug_aranges") == 0)
4641 || (strcmp (name
, ".debug_frame") == 0)
4642 || (strcmp (name
, ".debug_info") == 0)
4643 || (strcmp (name
, ".debug_loc") == 0)
4644 || (strcmp (name
, ".debug_macinfo") == 0)
4645 || (strcmp (name
, ".debug_pubnames") == 0)
4646 || (strcmp (name
, ".debug_pubtypes") == 0))
4647 hdr
->sh_type
= SHT_IA_64_VMS_DEBUG
;
4648 else if ((strcmp (name
, ".debug_line") == 0)
4649 || (strcmp (name
, ".debug_ranges") == 0)
4650 || (strcmp (name
, ".trace_info") == 0)
4651 || (strcmp (name
, ".trace_abbrev") == 0)
4652 || (strcmp (name
, ".trace_aranges") == 0))
4653 hdr
->sh_type
= SHT_IA_64_VMS_TRACE
;
4654 else if (strcmp (name
, ".debug_str") == 0)
4655 hdr
->sh_type
= SHT_IA_64_VMS_DEBUG_STR
;
4661 /* The final processing done just before writing out a VMS IA-64 ELF
4665 elf64_vms_final_write_processing (bfd
*abfd
)
4667 Elf_Internal_Shdr
*hdr
;
4669 int unwind_info_sect_idx
= 0;
4671 for (s
= abfd
->sections
; s
; s
= s
->next
)
4673 hdr
= &elf_section_data (s
)->this_hdr
;
4675 if (strcmp (bfd_section_name (hdr
->bfd_section
),
4676 ".IA_64.unwind_info") == 0)
4677 unwind_info_sect_idx
= elf_section_data (s
)->this_idx
;
4679 switch (hdr
->sh_type
)
4681 case SHT_IA_64_UNWIND
:
4682 /* VMS requires sh_info to point to the unwind info section. */
4683 hdr
->sh_info
= unwind_info_sect_idx
;
4688 if (! elf_flags_init (abfd
))
4690 unsigned long flags
= 0;
4692 if (abfd
->xvec
->byteorder
== BFD_ENDIAN_BIG
)
4693 flags
|= EF_IA_64_BE
;
4694 if (bfd_get_mach (abfd
) == bfd_mach_ia64_elf64
)
4695 flags
|= EF_IA_64_ABI64
;
4697 elf_elfheader (abfd
)->e_flags
= flags
;
4698 elf_flags_init (abfd
) = TRUE
;
4700 return _bfd_elf_final_write_processing (abfd
);
4704 elf64_vms_write_shdrs_and_ehdr (bfd
*abfd
)
4706 unsigned char needed_count
[8];
4708 if (!bfd_elf64_write_shdrs_and_ehdr (abfd
))
4711 bfd_putl64 (elf_ia64_vms_tdata (abfd
)->needed_count
, needed_count
);
4713 if (bfd_seek (abfd
, sizeof (Elf64_External_Ehdr
), SEEK_SET
) != 0
4714 || bfd_bwrite (needed_count
, 8, abfd
) != 8)
4721 elf64_vms_close_and_cleanup (bfd
*abfd
)
4723 if (bfd_get_format (abfd
) == bfd_object
)
4727 /* Pad to 8 byte boundary for IPF/VMS. */
4728 isize
= bfd_get_size (abfd
);
4729 if ((isize
& 7) != 0)
4731 int ishort
= 8 - (isize
& 7);
4732 bfd_uint64_t pad
= 0;
4734 bfd_seek (abfd
, isize
, SEEK_SET
);
4735 bfd_bwrite (&pad
, ishort
, abfd
);
4739 return _bfd_elf_close_and_cleanup (abfd
);
4742 /* Add symbols from an ELF object file to the linker hash table. */
4745 elf64_vms_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4747 Elf_Internal_Shdr
*hdr
;
4748 bfd_size_type symcount
;
4749 bfd_size_type extsymcount
;
4750 bfd_size_type extsymoff
;
4751 struct elf_link_hash_entry
**sym_hash
;
4752 bfd_boolean dynamic
;
4753 Elf_Internal_Sym
*isymbuf
= NULL
;
4754 Elf_Internal_Sym
*isym
;
4755 Elf_Internal_Sym
*isymend
;
4756 const struct elf_backend_data
*bed
;
4757 struct elf_link_hash_table
*htab
;
4760 htab
= elf_hash_table (info
);
4761 bed
= get_elf_backend_data (abfd
);
4763 if ((abfd
->flags
& DYNAMIC
) == 0)
4769 /* You can't use -r against a dynamic object. Also, there's no
4770 hope of using a dynamic object which does not exactly match
4771 the format of the output file. */
4772 if (bfd_link_relocatable (info
)
4773 || !is_elf_hash_table (htab
)
4774 || info
->output_bfd
->xvec
!= abfd
->xvec
)
4776 if (bfd_link_relocatable (info
))
4777 bfd_set_error (bfd_error_invalid_operation
);
4779 bfd_set_error (bfd_error_wrong_format
);
4786 /* If we are creating a shared library, create all the dynamic
4787 sections immediately. We need to attach them to something,
4788 so we attach them to this BFD, provided it is the right
4789 format. FIXME: If there are no input BFD's of the same
4790 format as the output, we can't make a shared library. */
4791 if (bfd_link_pic (info
)
4792 && is_elf_hash_table (htab
)
4793 && info
->output_bfd
->xvec
== abfd
->xvec
4794 && !htab
->dynamic_sections_created
)
4796 if (! elf64_ia64_create_dynamic_sections (abfd
, info
))
4800 else if (!is_elf_hash_table (htab
))
4808 /* ld --just-symbols and dynamic objects don't mix very well.
4809 ld shouldn't allow it. */
4810 if ((s
= abfd
->sections
) != NULL
4811 && s
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4814 /* Be sure there are dynamic sections. */
4815 if (! elf64_ia64_create_dynamic_sections (htab
->dynobj
, info
))
4818 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4821 /* VMS libraries do not have dynamic sections. Create one from
4823 Elf_Internal_Phdr
*phdr
;
4824 unsigned int i
, phnum
;
4826 phdr
= elf_tdata (abfd
)->phdr
;
4829 phnum
= elf_elfheader (abfd
)->e_phnum
;
4830 for (i
= 0; i
< phnum
; phdr
++)
4831 if (phdr
->p_type
== PT_DYNAMIC
)
4833 s
= bfd_make_section (abfd
, ".dynamic");
4836 s
->vma
= phdr
->p_vaddr
;
4837 s
->lma
= phdr
->p_paddr
;
4838 s
->size
= phdr
->p_filesz
;
4839 s
->filepos
= phdr
->p_offset
;
4840 s
->flags
|= SEC_HAS_CONTENTS
;
4841 s
->alignment_power
= bfd_log2 (phdr
->p_align
);
4848 /* Extract IDENT. */
4849 if (!bfd_malloc_and_get_section (abfd
, s
, &dynbuf
))
4856 for (extdyn
= dynbuf
;
4857 extdyn
< dynbuf
+ s
->size
;
4858 extdyn
+= bed
->s
->sizeof_dyn
)
4860 Elf_Internal_Dyn dyn
;
4862 bed
->s
->swap_dyn_in (abfd
, extdyn
, &dyn
);
4863 if (dyn
.d_tag
== DT_IA_64_VMS_IDENT
)
4865 bfd_uint64_t tagv
= dyn
.d_un
.d_val
;
4866 elf_ia64_vms_ident (abfd
) = tagv
;
4870 if (extdyn
>= dynbuf
+ s
->size
)
4872 /* Ident not found. */
4873 goto error_free_dyn
;
4877 /* We do not want to include any of the sections in a dynamic
4878 object in the output file. We hack by simply clobbering the
4879 list of sections in the BFD. This could be handled more
4880 cleanly by, say, a new section flag; the existing
4881 SEC_NEVER_LOAD flag is not the one we want, because that one
4882 still implies that the section takes up space in the output
4884 bfd_section_list_clear (abfd
);
4886 /* FIXME: should we detect if this library is already included ?
4887 This should be harmless and shouldn't happen in practice. */
4890 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4891 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
4893 /* The sh_info field of the symtab header tells us where the
4894 external symbols start. We don't care about the local symbols at
4896 extsymcount
= symcount
- hdr
->sh_info
;
4897 extsymoff
= hdr
->sh_info
;
4900 if (extsymcount
!= 0)
4902 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
4904 if (isymbuf
== NULL
)
4907 /* We store a pointer to the hash table entry for each external
4909 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
4910 sym_hash
= (struct elf_link_hash_entry
**) bfd_alloc (abfd
, amt
);
4911 if (sym_hash
== NULL
)
4912 goto error_free_sym
;
4913 elf_sym_hashes (abfd
) = sym_hash
;
4916 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
;
4922 asection
*sec
, *new_sec
;
4925 struct elf_link_hash_entry
*h
;
4926 bfd_boolean definition
;
4927 bfd_boolean size_change_ok
;
4928 bfd_boolean type_change_ok
;
4930 unsigned int old_alignment
;
4933 flags
= BSF_NO_FLAGS
;
4935 value
= isym
->st_value
;
4937 common
= bed
->common_definition (isym
);
4939 bind
= ELF_ST_BIND (isym
->st_info
);
4943 /* This should be impossible, since ELF requires that all
4944 global symbols follow all local symbols, and that sh_info
4945 point to the first global symbol. Unfortunately, Irix 5
4950 if (isym
->st_shndx
!= SHN_UNDEF
&& !common
)
4958 case STB_GNU_UNIQUE
:
4959 flags
= BSF_GNU_UNIQUE
;
4963 /* Leave it up to the processor backend. */
4967 if (isym
->st_shndx
== SHN_UNDEF
)
4968 sec
= bfd_und_section_ptr
;
4969 else if (isym
->st_shndx
== SHN_ABS
)
4970 sec
= bfd_abs_section_ptr
;
4971 else if (isym
->st_shndx
== SHN_COMMON
)
4973 sec
= bfd_com_section_ptr
;
4974 /* What ELF calls the size we call the value. What ELF
4975 calls the value we call the alignment. */
4976 value
= isym
->st_size
;
4980 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4982 sec
= bfd_abs_section_ptr
;
4983 else if (sec
->kept_section
)
4985 /* Symbols from discarded section are undefined. We keep
4987 sec
= bfd_und_section_ptr
;
4988 isym
->st_shndx
= SHN_UNDEF
;
4990 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
4994 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
4997 goto error_free_vers
;
4999 if (bed
->elf_add_symbol_hook
)
5001 if (! (*bed
->elf_add_symbol_hook
) (abfd
, info
, isym
, &name
, &flags
,
5003 goto error_free_vers
;
5005 /* The hook function sets the name to NULL if this symbol
5006 should be skipped for some reason. */
5011 /* Sanity check that all possibilities were handled. */
5014 bfd_set_error (bfd_error_bad_value
);
5015 goto error_free_vers
;
5018 if (bfd_is_und_section (sec
)
5019 || bfd_is_com_section (sec
))
5024 size_change_ok
= FALSE
;
5025 type_change_ok
= bed
->type_change_ok
;
5030 if (! bfd_is_und_section (sec
))
5031 h
= elf_link_hash_lookup (htab
, name
, TRUE
, FALSE
, FALSE
);
5033 h
= ((struct elf_link_hash_entry
*) bfd_wrapped_link_hash_lookup
5034 (abfd
, info
, name
, TRUE
, FALSE
, FALSE
));
5036 goto error_free_sym
;
5040 if (is_elf_hash_table (htab
))
5042 while (h
->root
.type
== bfd_link_hash_indirect
5043 || h
->root
.type
== bfd_link_hash_warning
)
5044 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5046 /* Remember the old alignment if this is a common symbol, so
5047 that we don't reduce the alignment later on. We can't
5048 check later, because _bfd_generic_link_add_one_symbol
5049 will set a default for the alignment which we want to
5050 override. We also remember the old bfd where the existing
5051 definition comes from. */
5052 switch (h
->root
.type
)
5057 case bfd_link_hash_defined
:
5058 if (abfd
->selective_search
)
5061 case bfd_link_hash_defweak
:
5062 old_bfd
= h
->root
.u
.def
.section
->owner
;
5065 case bfd_link_hash_common
:
5066 old_bfd
= h
->root
.u
.c
.p
->section
->owner
;
5067 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
5072 if (! (_bfd_generic_link_add_one_symbol
5073 (info
, abfd
, name
, flags
, sec
, value
, NULL
, FALSE
, bed
->collect
,
5074 (struct bfd_link_hash_entry
**) sym_hash
)))
5075 goto error_free_vers
;
5078 while (h
->root
.type
== bfd_link_hash_indirect
5079 || h
->root
.type
== bfd_link_hash_warning
)
5080 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5084 h
->unique_global
= (flags
& BSF_GNU_UNIQUE
) != 0;
5086 /* Set the alignment of a common symbol. */
5087 if ((common
|| bfd_is_com_section (sec
))
5088 && h
->root
.type
== bfd_link_hash_common
)
5093 align
= bfd_log2 (isym
->st_value
);
5096 /* The new symbol is a common symbol in a shared object.
5097 We need to get the alignment from the section. */
5098 align
= new_sec
->alignment_power
;
5100 if (align
> old_alignment
5101 /* Permit an alignment power of zero if an alignment of one
5102 is specified and no other alignments have been specified. */
5103 || (isym
->st_value
== 1 && old_alignment
== 0))
5104 h
->root
.u
.c
.p
->alignment_power
= align
;
5106 h
->root
.u
.c
.p
->alignment_power
= old_alignment
;
5109 if (is_elf_hash_table (htab
))
5111 /* Check the alignment when a common symbol is involved. This
5112 can change when a common symbol is overridden by a normal
5113 definition or a common symbol is ignored due to the old
5114 normal definition. We need to make sure the maximum
5115 alignment is maintained. */
5116 if ((old_alignment
|| common
)
5117 && h
->root
.type
!= bfd_link_hash_common
)
5119 unsigned int common_align
;
5120 unsigned int normal_align
;
5121 unsigned int symbol_align
;
5125 symbol_align
= ffs (h
->root
.u
.def
.value
) - 1;
5126 if (h
->root
.u
.def
.section
->owner
!= NULL
5127 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
5129 normal_align
= h
->root
.u
.def
.section
->alignment_power
;
5130 if (normal_align
> symbol_align
)
5131 normal_align
= symbol_align
;
5134 normal_align
= symbol_align
;
5138 common_align
= old_alignment
;
5139 common_bfd
= old_bfd
;
5144 common_align
= bfd_log2 (isym
->st_value
);
5146 normal_bfd
= old_bfd
;
5149 if (normal_align
< common_align
)
5151 /* PR binutils/2735 */
5152 if (normal_bfd
== NULL
)
5154 /* xgettext:c-format */
5155 (_("warning: alignment %u of common symbol `%s' in %pB"
5156 " is greater than the alignment (%u) of its section %pA"),
5157 1 << common_align
, name
, common_bfd
,
5158 1 << normal_align
, h
->root
.u
.def
.section
);
5161 /* xgettext:c-format */
5162 (_("warning: alignment %u of symbol `%s' in %pB"
5163 " is smaller than %u in %pB"),
5164 1 << normal_align
, name
, normal_bfd
,
5165 1 << common_align
, common_bfd
);
5169 /* Remember the symbol size if it isn't undefined. */
5170 if ((isym
->st_size
!= 0 && isym
->st_shndx
!= SHN_UNDEF
)
5171 && (definition
|| h
->size
== 0))
5174 && h
->size
!= isym
->st_size
5175 && ! size_change_ok
)
5177 /* xgettext:c-format */
5178 (_("warning: size of symbol `%s' changed"
5179 " from %" PRIu64
" in %pB to %" PRIu64
" in %pB"),
5180 name
, (uint64_t) h
->size
, old_bfd
,
5181 (uint64_t) isym
->st_size
, abfd
);
5183 h
->size
= isym
->st_size
;
5186 /* If this is a common symbol, then we always want H->SIZE
5187 to be the size of the common symbol. The code just above
5188 won't fix the size if a common symbol becomes larger. We
5189 don't warn about a size change here, because that is
5190 covered by --warn-common. Allow changed between different
5192 if (h
->root
.type
== bfd_link_hash_common
)
5193 h
->size
= h
->root
.u
.c
.size
;
5195 if (ELF_ST_TYPE (isym
->st_info
) != STT_NOTYPE
5196 && (definition
|| h
->type
== STT_NOTYPE
))
5198 unsigned int type
= ELF_ST_TYPE (isym
->st_info
);
5200 if (h
->type
!= type
)
5202 if (h
->type
!= STT_NOTYPE
&& ! type_change_ok
)
5204 /* xgettext:c-format */
5205 (_("warning: type of symbol `%s' changed"
5206 " from %d to %d in %pB"),
5207 name
, h
->type
, type
, abfd
);
5213 /* Set a flag in the hash table entry indicating the type of
5214 reference or definition we just found. Keep a count of
5215 the number of dynamic symbols we find. A dynamic symbol
5216 is one which is referenced or defined by both a regular
5217 object and a shared object. */
5223 if (bind
!= STB_WEAK
)
5224 h
->ref_regular_nonweak
= 1;
5228 BFD_ASSERT (!h
->def_dynamic
);
5234 BFD_ASSERT (definition
);
5237 ((struct elf64_ia64_link_hash_entry
*)h
)->shl
= abfd
;
5242 if (isymbuf
!= NULL
)
5248 /* If this object is the same format as the output object, and it is
5249 not a shared library, then let the backend look through the
5252 This is required to build global offset table entries and to
5253 arrange for dynamic relocs. It is not required for the
5254 particular common case of linking non PIC code, even when linking
5255 against shared libraries, but unfortunately there is no way of
5256 knowing whether an object file has been compiled PIC or not.
5257 Looking through the relocs is not particularly time consuming.
5258 The problem is that we must either (1) keep the relocs in memory,
5259 which causes the linker to require additional runtime memory or
5260 (2) read the relocs twice from the input file, which wastes time.
5261 This would be a good case for using mmap.
5263 I have no idea how to handle linking PIC code into a file of a
5264 different format. It probably can't be done. */
5266 && is_elf_hash_table (htab
)
5267 && bed
->check_relocs
!= NULL
5268 && (*bed
->relocs_compatible
) (abfd
->xvec
, info
->output_bfd
->xvec
))
5272 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5274 Elf_Internal_Rela
*internal_relocs
;
5277 if ((o
->flags
& SEC_RELOC
) == 0
5278 || o
->reloc_count
== 0
5279 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
5280 && (o
->flags
& SEC_DEBUGGING
) != 0)
5281 || bfd_is_abs_section (o
->output_section
))
5284 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
5286 if (internal_relocs
== NULL
)
5289 ok
= (*bed
->check_relocs
) (abfd
, info
, o
, internal_relocs
);
5291 if (elf_section_data (o
)->relocs
!= internal_relocs
)
5292 free (internal_relocs
);
5303 if (isymbuf
!= NULL
)
5310 elf64_vms_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
5313 struct bfd_link_hash_entry
**pundef
;
5314 struct bfd_link_hash_entry
**next_pundef
;
5316 /* We only accept VMS libraries. */
5317 if (info
->output_bfd
->xvec
!= abfd
->xvec
)
5319 bfd_set_error (bfd_error_wrong_format
);
5323 /* The archive_pass field in the archive itself is used to
5324 initialize PASS, since we may search the same archive multiple
5326 pass
= ++abfd
->archive_pass
;
5328 /* Look through the list of undefined symbols. */
5329 for (pundef
= &info
->hash
->undefs
; *pundef
!= NULL
; pundef
= next_pundef
)
5331 struct bfd_link_hash_entry
*h
;
5337 next_pundef
= &(*pundef
)->u
.undef
.next
;
5339 /* When a symbol is defined, it is not necessarily removed from
5341 if (h
->type
!= bfd_link_hash_undefined
5342 && h
->type
!= bfd_link_hash_common
)
5344 /* Remove this entry from the list, for general cleanliness
5345 and because we are going to look through the list again
5346 if we search any more libraries. We can't remove the
5347 entry if it is the tail, because that would lose any
5348 entries we add to the list later on. */
5349 if (*pundef
!= info
->hash
->undefs_tail
)
5351 *pundef
= *next_pundef
;
5352 next_pundef
= pundef
;
5357 /* Look for this symbol in the archive hash table. */
5358 symidx
= _bfd_vms_lib_find_symbol (abfd
, h
->root
.string
);
5359 if (symidx
== BFD_NO_MORE_SYMBOLS
)
5361 /* Nothing in this slot. */
5365 element
= bfd_get_elt_at_index (abfd
, symidx
);
5366 if (element
== NULL
)
5369 if (element
->archive_pass
== -1 || element
->archive_pass
== pass
)
5371 /* Next symbol if this archive is wrong or already handled. */
5375 orig_element
= element
;
5376 if (bfd_is_thin_archive (abfd
))
5378 element
= _bfd_vms_lib_get_imagelib_file (element
);
5379 if (element
== NULL
|| !bfd_check_format (element
, bfd_object
))
5381 orig_element
->archive_pass
= -1;
5385 else if (! bfd_check_format (element
, bfd_object
))
5387 element
->archive_pass
= -1;
5391 /* Unlike the generic linker, we know that this element provides
5392 a definition for an undefined symbol and we know that we want
5393 to include it. We don't need to check anything. */
5394 if (! (*info
->callbacks
->add_archive_element
) (info
, element
,
5395 h
->root
.string
, &element
))
5397 if (! elf64_vms_link_add_object_symbols (element
, info
))
5400 orig_element
->archive_pass
= pass
;
5407 elf64_vms_bfd_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
5409 switch (bfd_get_format (abfd
))
5412 return elf64_vms_link_add_object_symbols (abfd
, info
);
5415 return elf64_vms_link_add_archive_symbols (abfd
, info
);
5418 bfd_set_error (bfd_error_wrong_format
);
5424 elf64_ia64_vms_mkobject (bfd
*abfd
)
5426 return bfd_elf_allocate_object
5427 (abfd
, sizeof (struct elf64_ia64_vms_obj_tdata
), IA64_ELF_DATA
);
5431 /* Size-dependent data and functions. */
5432 static const struct elf_size_info elf64_ia64_vms_size_info
= {
5433 sizeof (Elf64_External_VMS_Ehdr
),
5434 sizeof (Elf64_External_Phdr
),
5435 sizeof (Elf64_External_Shdr
),
5436 sizeof (Elf64_External_Rel
),
5437 sizeof (Elf64_External_Rela
),
5438 sizeof (Elf64_External_Sym
),
5439 sizeof (Elf64_External_Dyn
),
5440 sizeof (Elf_External_Note
),
5443 64, 3, /* ARCH_SIZE, LOG_FILE_ALIGN */
5444 ELFCLASS64
, EV_CURRENT
,
5445 bfd_elf64_write_out_phdrs
,
5446 elf64_vms_write_shdrs_and_ehdr
,
5447 bfd_elf64_checksum_contents
,
5448 bfd_elf64_write_relocs
,
5449 bfd_elf64_swap_symbol_in
,
5450 bfd_elf64_swap_symbol_out
,
5451 bfd_elf64_slurp_reloc_table
,
5452 bfd_elf64_slurp_symbol_table
,
5453 bfd_elf64_swap_dyn_in
,
5454 bfd_elf64_swap_dyn_out
,
5455 bfd_elf64_swap_reloc_in
,
5456 bfd_elf64_swap_reloc_out
,
5457 bfd_elf64_swap_reloca_in
,
5458 bfd_elf64_swap_reloca_out
5461 #define ELF_ARCH bfd_arch_ia64
5462 #define ELF_MACHINE_CODE EM_IA_64
5463 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5464 #define ELF_COMMONPAGESIZE 0x200 /* 16KB */
5466 #define elf_backend_section_from_shdr \
5467 elf64_ia64_section_from_shdr
5468 #define elf_backend_section_flags \
5469 elf64_ia64_section_flags
5470 #define elf_backend_fake_sections \
5471 elf64_ia64_fake_sections
5472 #define elf_backend_final_write_processing \
5473 elf64_ia64_final_write_processing
5474 #define elf_backend_add_symbol_hook \
5475 elf64_ia64_add_symbol_hook
5476 #define elf_info_to_howto \
5477 elf64_ia64_info_to_howto
5479 #define bfd_elf64_bfd_reloc_type_lookup \
5480 ia64_elf_reloc_type_lookup
5481 #define bfd_elf64_bfd_reloc_name_lookup \
5482 ia64_elf_reloc_name_lookup
5483 #define bfd_elf64_bfd_is_local_label_name \
5484 elf64_ia64_is_local_label_name
5485 #define bfd_elf64_bfd_relax_section \
5486 elf64_ia64_relax_section
5488 #define elf_backend_object_p \
5491 /* Stuff for the BFD linker: */
5492 #define bfd_elf64_bfd_link_hash_table_create \
5493 elf64_ia64_hash_table_create
5494 #define elf_backend_create_dynamic_sections \
5495 elf64_ia64_create_dynamic_sections
5496 #define elf_backend_check_relocs \
5497 elf64_ia64_check_relocs
5498 #define elf_backend_adjust_dynamic_symbol \
5499 elf64_ia64_adjust_dynamic_symbol
5500 #define elf_backend_size_dynamic_sections \
5501 elf64_ia64_size_dynamic_sections
5502 #define elf_backend_omit_section_dynsym \
5503 _bfd_elf_omit_section_dynsym_all
5504 #define elf_backend_relocate_section \
5505 elf64_ia64_relocate_section
5506 #define elf_backend_finish_dynamic_symbol \
5507 elf64_ia64_finish_dynamic_symbol
5508 #define elf_backend_finish_dynamic_sections \
5509 elf64_ia64_finish_dynamic_sections
5510 #define bfd_elf64_bfd_final_link \
5511 elf64_ia64_final_link
5513 #define bfd_elf64_bfd_merge_private_bfd_data \
5514 elf64_ia64_merge_private_bfd_data
5515 #define bfd_elf64_bfd_set_private_flags \
5516 elf64_ia64_set_private_flags
5517 #define bfd_elf64_bfd_print_private_bfd_data \
5518 elf64_ia64_print_private_bfd_data
5520 #define elf_backend_plt_readonly 1
5521 #define elf_backend_want_plt_sym 0
5522 #define elf_backend_plt_alignment 5
5523 #define elf_backend_got_header_size 0
5524 #define elf_backend_want_got_plt 1
5525 #define elf_backend_may_use_rel_p 1
5526 #define elf_backend_may_use_rela_p 1
5527 #define elf_backend_default_use_rela_p 1
5528 #define elf_backend_want_dynbss 0
5529 #define elf_backend_hide_symbol elf64_ia64_hash_hide_symbol
5530 #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol
5531 #define elf_backend_reloc_type_class elf64_ia64_reloc_type_class
5532 #define elf_backend_rela_normal 1
5533 #define elf_backend_special_sections elf64_ia64_special_sections
5534 #define elf_backend_default_execstack 0
5536 /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
5537 SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
5538 We don't want to flood users with so many error messages. We turn
5539 off the warning for now. It will be turned on later when the Intel
5540 compiler is fixed. */
5541 #define elf_backend_link_order_error_handler NULL
5543 /* VMS-specific vectors. */
5545 #undef TARGET_LITTLE_SYM
5546 #define TARGET_LITTLE_SYM ia64_elf64_vms_vec
5547 #undef TARGET_LITTLE_NAME
5548 #define TARGET_LITTLE_NAME "elf64-ia64-vms"
5549 #undef TARGET_BIG_SYM
5550 #undef TARGET_BIG_NAME
5552 /* These are VMS specific functions. */
5554 #undef elf_backend_object_p
5555 #define elf_backend_object_p elf64_vms_object_p
5557 #undef elf_backend_section_from_shdr
5558 #define elf_backend_section_from_shdr elf64_vms_section_from_shdr
5560 #undef elf_backend_init_file_header
5561 #define elf_backend_init_file_header elf64_vms_init_file_header
5563 #undef elf_backend_section_processing
5564 #define elf_backend_section_processing elf64_vms_section_processing
5566 #undef elf_backend_final_write_processing
5567 #define elf_backend_final_write_processing elf64_vms_final_write_processing
5569 #undef bfd_elf64_close_and_cleanup
5570 #define bfd_elf64_close_and_cleanup elf64_vms_close_and_cleanup
5572 #undef elf_backend_section_from_bfd_section
5574 #undef elf_backend_symbol_processing
5576 #undef elf_backend_want_p_paddr_set_to_zero
5579 #define ELF_OSABI ELFOSABI_OPENVMS
5581 #undef ELF_MAXPAGESIZE
5582 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5585 #define elf64_bed elf64_ia64_vms_bed
5587 #define elf_backend_size_info elf64_ia64_vms_size_info
5589 /* Use VMS-style archives (in particular, don't use the standard coff
5591 #define bfd_elf64_archive_functions
5593 #undef bfd_elf64_archive_p
5594 #define bfd_elf64_archive_p _bfd_vms_lib_ia64_archive_p
5595 #undef bfd_elf64_write_archive_contents
5596 #define bfd_elf64_write_archive_contents _bfd_vms_lib_write_archive_contents
5597 #undef bfd_elf64_mkarchive
5598 #define bfd_elf64_mkarchive _bfd_vms_lib_ia64_mkarchive
5600 #define bfd_elf64_archive_slurp_armap \
5601 _bfd_vms_lib_slurp_armap
5602 #define bfd_elf64_archive_slurp_extended_name_table \
5603 _bfd_vms_lib_slurp_extended_name_table
5604 #define bfd_elf64_archive_construct_extended_name_table \
5605 _bfd_vms_lib_construct_extended_name_table
5606 #define bfd_elf64_archive_truncate_arname \
5607 _bfd_vms_lib_truncate_arname
5608 #define bfd_elf64_archive_write_armap \
5609 _bfd_vms_lib_write_armap
5610 #define bfd_elf64_archive_read_ar_hdr \
5611 _bfd_vms_lib_read_ar_hdr
5612 #define bfd_elf64_archive_write_ar_hdr \
5613 _bfd_vms_lib_write_ar_hdr
5614 #define bfd_elf64_archive_openr_next_archived_file \
5615 _bfd_vms_lib_openr_next_archived_file
5616 #define bfd_elf64_archive_get_elt_at_index \
5617 _bfd_vms_lib_get_elt_at_index
5618 #define bfd_elf64_archive_generic_stat_arch_elt \
5619 _bfd_vms_lib_generic_stat_arch_elt
5620 #define bfd_elf64_archive_update_armap_timestamp \
5621 _bfd_vms_lib_update_armap_timestamp
5623 /* VMS link methods. */
5624 #undef bfd_elf64_bfd_link_add_symbols
5625 #define bfd_elf64_bfd_link_add_symbols elf64_vms_bfd_link_add_symbols
5627 #undef elf_backend_want_got_sym
5628 #define elf_backend_want_got_sym 0
5630 #undef bfd_elf64_mkobject
5631 #define bfd_elf64_mkobject elf64_ia64_vms_mkobject
5633 /* Redefine to align segments on block size. */
5634 #undef ELF_MAXPAGESIZE
5635 #define ELF_MAXPAGESIZE 0x200 /* 512B */
5637 #undef elf_backend_want_got_plt
5638 #define elf_backend_want_got_plt 0
5640 #include "elf64-target.h"