1 /* IA-64 support for OpenVMS
2 Copyright (C) 1998-2017 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
)
249 = ia64_elf_lookup_howto ((unsigned int) ELF64_R_TYPE (elf_reloc
->r_info
));
253 #define PLT_FULL_ENTRY_SIZE (2 * 16)
255 static const bfd_byte plt_full_entry
[PLT_FULL_ENTRY_SIZE
] =
257 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
258 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/
259 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
260 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
261 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
262 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
265 static const bfd_byte oor_brl
[16] =
267 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;;*/
269 0x00, 0x00, 0x00, 0xc0
273 /* These functions do relaxation for IA-64 ELF. */
275 /* Rename some of the generic section flags to better document how they
277 #define skip_relax_pass_0 sec_flg0
278 #define skip_relax_pass_1 sec_flg1
281 elf64_ia64_update_short_info (asection
*sec
, bfd_vma offset
,
282 struct elf64_ia64_link_hash_table
*ia64_info
)
284 /* Skip ABS and SHF_IA_64_SHORT sections. */
285 if (sec
== bfd_abs_section_ptr
286 || (sec
->flags
& SEC_SMALL_DATA
) != 0)
289 if (!ia64_info
->min_short_sec
)
291 ia64_info
->max_short_sec
= sec
;
292 ia64_info
->max_short_offset
= offset
;
293 ia64_info
->min_short_sec
= sec
;
294 ia64_info
->min_short_offset
= offset
;
296 else if (sec
== ia64_info
->max_short_sec
297 && offset
> ia64_info
->max_short_offset
)
298 ia64_info
->max_short_offset
= offset
;
299 else if (sec
== ia64_info
->min_short_sec
300 && offset
< ia64_info
->min_short_offset
)
301 ia64_info
->min_short_offset
= offset
;
302 else if (sec
->output_section
->vma
303 > ia64_info
->max_short_sec
->vma
)
305 ia64_info
->max_short_sec
= sec
;
306 ia64_info
->max_short_offset
= offset
;
308 else if (sec
->output_section
->vma
309 < ia64_info
->min_short_sec
->vma
)
311 ia64_info
->min_short_sec
= sec
;
312 ia64_info
->min_short_offset
= offset
;
316 /* Use a two passes algorithm. In the first pass, branches are relaxed
317 (which may increase the size of the section). In the second pass,
318 the other relaxations are done.
322 elf64_ia64_relax_section (bfd
*abfd
, asection
*sec
,
323 struct bfd_link_info
*link_info
,
328 struct one_fixup
*next
;
334 Elf_Internal_Shdr
*symtab_hdr
;
335 Elf_Internal_Rela
*internal_relocs
;
336 Elf_Internal_Rela
*irel
, *irelend
;
338 Elf_Internal_Sym
*isymbuf
= NULL
;
339 struct elf64_ia64_link_hash_table
*ia64_info
;
340 struct one_fixup
*fixups
= NULL
;
341 bfd_boolean changed_contents
= FALSE
;
342 bfd_boolean changed_relocs
= FALSE
;
343 bfd_boolean skip_relax_pass_0
= TRUE
;
344 bfd_boolean skip_relax_pass_1
= TRUE
;
347 /* Assume we're not going to change any sizes, and we'll only need
351 if (bfd_link_relocatable (link_info
))
352 (*link_info
->callbacks
->einfo
)
353 (_("%P%F: --relax and -r may not be used together\n"));
355 /* Don't even try to relax for non-ELF outputs. */
356 if (!is_elf_hash_table (link_info
->hash
))
359 /* Nothing to do if there are no relocations or there is no need for
361 if ((sec
->flags
& SEC_RELOC
) == 0
362 || sec
->reloc_count
== 0
363 || (link_info
->relax_pass
== 0 && sec
->skip_relax_pass_0
)
364 || (link_info
->relax_pass
== 1 && sec
->skip_relax_pass_1
))
367 ia64_info
= elf64_ia64_hash_table (link_info
);
368 if (ia64_info
== NULL
)
371 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
373 /* Load the relocations for this section. */
374 internal_relocs
= (_bfd_elf_link_read_relocs
375 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
376 link_info
->keep_memory
));
377 if (internal_relocs
== NULL
)
380 irelend
= internal_relocs
+ sec
->reloc_count
;
382 /* Get the section contents. */
383 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
384 contents
= elf_section_data (sec
)->this_hdr
.contents
;
387 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
391 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
393 unsigned long r_type
= ELF64_R_TYPE (irel
->r_info
);
394 bfd_vma symaddr
, reladdr
, trampoff
, toff
, roff
;
398 bfd_boolean is_branch
;
399 struct elf64_ia64_dyn_sym_info
*dyn_i
;
403 case R_IA64_PCREL21B
:
404 case R_IA64_PCREL21BI
:
405 case R_IA64_PCREL21M
:
406 case R_IA64_PCREL21F
:
407 /* In pass 1, all br relaxations are done. We can skip it. */
408 if (link_info
->relax_pass
== 1)
410 skip_relax_pass_0
= FALSE
;
414 case R_IA64_PCREL60B
:
415 /* We can't optimize brl to br in pass 0 since br relaxations
416 will increase the code size. Defer it to pass 1. */
417 if (link_info
->relax_pass
== 0)
419 skip_relax_pass_1
= FALSE
;
426 /* Update max_short_sec/min_short_sec. */
428 case R_IA64_LTOFF22X
:
430 /* We can't relax ldx/mov in pass 0 since br relaxations will
431 increase the code size. Defer it to pass 1. */
432 if (link_info
->relax_pass
== 0)
434 skip_relax_pass_1
= FALSE
;
444 /* Get the value of the symbol referred to by the reloc. */
445 if (ELF64_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
447 /* A local symbol. */
448 Elf_Internal_Sym
*isym
;
450 /* Read this BFD's local symbols. */
453 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
455 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
456 symtab_hdr
->sh_info
, 0,
462 isym
= isymbuf
+ ELF64_R_SYM (irel
->r_info
);
463 if (isym
->st_shndx
== SHN_UNDEF
)
464 continue; /* We can't do anything with undefined symbols. */
465 else if (isym
->st_shndx
== SHN_ABS
)
466 tsec
= bfd_abs_section_ptr
;
467 else if (isym
->st_shndx
== SHN_COMMON
)
468 tsec
= bfd_com_section_ptr
;
469 else if (isym
->st_shndx
== SHN_IA_64_ANSI_COMMON
)
470 tsec
= bfd_com_section_ptr
;
472 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
474 toff
= isym
->st_value
;
475 dyn_i
= get_dyn_sym_info (ia64_info
, NULL
, abfd
, irel
, FALSE
);
480 struct elf_link_hash_entry
*h
;
482 indx
= ELF64_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
483 h
= elf_sym_hashes (abfd
)[indx
];
484 BFD_ASSERT (h
!= NULL
);
486 while (h
->root
.type
== bfd_link_hash_indirect
487 || h
->root
.type
== bfd_link_hash_warning
)
488 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
490 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, irel
, FALSE
);
492 /* For branches to dynamic symbols, we're interested instead
493 in a branch to the PLT entry. */
494 if (is_branch
&& dyn_i
&& dyn_i
->want_plt2
)
496 /* Internal branches shouldn't be sent to the PLT.
497 Leave this for now and we'll give an error later. */
498 if (r_type
!= R_IA64_PCREL21B
)
501 tsec
= ia64_info
->root
.splt
;
502 toff
= dyn_i
->plt2_offset
;
503 BFD_ASSERT (irel
->r_addend
== 0);
506 /* Can't do anything else with dynamic symbols. */
507 else if (elf64_ia64_dynamic_symbol_p (h
))
512 /* We can't do anything with undefined symbols. */
513 if (h
->root
.type
== bfd_link_hash_undefined
514 || h
->root
.type
== bfd_link_hash_undefweak
)
517 tsec
= h
->root
.u
.def
.section
;
518 toff
= h
->root
.u
.def
.value
;
522 toff
+= irel
->r_addend
;
524 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
526 roff
= irel
->r_offset
;
530 bfd_signed_vma offset
;
532 reladdr
= (sec
->output_section
->vma
534 + roff
) & (bfd_vma
) -4;
536 /* The .plt section is aligned at 32byte and the .text section
537 is aligned at 64byte. The .text section is right after the
538 .plt section. After the first relaxation pass, linker may
539 increase the gap between the .plt and .text sections up
540 to 32byte. We assume linker will always insert 32byte
541 between the .plt and .text sections after the first
543 if (tsec
== ia64_info
->root
.splt
)
544 offset
= -0x1000000 + 32;
548 /* If the branch is in range, no need to do anything. */
549 if ((bfd_signed_vma
) (symaddr
- reladdr
) >= offset
550 && (bfd_signed_vma
) (symaddr
- reladdr
) <= 0x0FFFFF0)
552 /* If the 60-bit branch is in 21-bit range, optimize it. */
553 if (r_type
== R_IA64_PCREL60B
)
555 ia64_elf_relax_brl (contents
, roff
);
557 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
560 /* If the original relocation offset points to slot
561 1, change it to slot 2. */
562 if ((irel
->r_offset
& 3) == 1)
568 else if (r_type
== R_IA64_PCREL60B
)
570 else if (ia64_elf_relax_br (contents
, roff
))
572 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
575 /* Make the relocation offset point to slot 1. */
576 irel
->r_offset
= (irel
->r_offset
& ~((bfd_vma
) 0x3)) + 1;
580 /* We can't put a trampoline in a .init/.fini section. Issue
582 if (strcmp (sec
->output_section
->name
, ".init") == 0
583 || strcmp (sec
->output_section
->name
, ".fini") == 0)
586 /* xgettext:c-format */
587 (_("%B: Can't relax br at 0x%lx in section `%A'."
588 " Please use brl or indirect branch."),
589 sec
->owner
, (unsigned long) roff
, sec
);
590 bfd_set_error (bfd_error_bad_value
);
594 /* If the branch and target are in the same section, you've
595 got one honking big section and we can't help you unless
596 you are branching backwards. You'll get an error message
598 if (tsec
== sec
&& toff
> roff
)
601 /* Look for an existing fixup to this address. */
602 for (f
= fixups
; f
; f
= f
->next
)
603 if (f
->tsec
== tsec
&& f
->toff
== toff
)
608 /* Two alternatives: If it's a branch to a PLT entry, we can
609 make a copy of the FULL_PLT entry. Otherwise, we'll have
610 to use a `brl' insn to get where we're going. */
614 if (tsec
== ia64_info
->root
.splt
)
615 size
= sizeof (plt_full_entry
);
617 size
= sizeof (oor_brl
);
619 /* Resize the current section to make room for the new branch. */
620 trampoff
= (sec
->size
+ 15) & (bfd_vma
) -16;
622 /* If trampoline is out of range, there is nothing we
624 offset
= trampoff
- (roff
& (bfd_vma
) -4);
625 if (offset
< -0x1000000 || offset
> 0x0FFFFF0)
628 amt
= trampoff
+ size
;
629 contents
= (bfd_byte
*) bfd_realloc (contents
, amt
);
630 if (contents
== NULL
)
634 if (tsec
== ia64_info
->root
.splt
)
636 memcpy (contents
+ trampoff
, plt_full_entry
, size
);
638 /* Hijack the old relocation for use as the PLTOFF reloc. */
639 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
641 irel
->r_offset
= trampoff
;
645 memcpy (contents
+ trampoff
, oor_brl
, size
);
646 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
648 irel
->r_offset
= trampoff
+ 2;
651 /* Record the fixup so we don't do it again this section. */
652 f
= (struct one_fixup
*)
653 bfd_malloc ((bfd_size_type
) sizeof (*f
));
657 f
->trampoff
= trampoff
;
662 /* If trampoline is out of range, there is nothing we
664 offset
= f
->trampoff
- (roff
& (bfd_vma
) -4);
665 if (offset
< -0x1000000 || offset
> 0x0FFFFF0)
668 /* Nop out the reloc, since we're finalizing things here. */
669 irel
->r_info
= ELF64_R_INFO (0, R_IA64_NONE
);
672 /* Fix up the existing branch to hit the trampoline. */
673 if (ia64_elf_install_value (contents
+ roff
, offset
, r_type
)
677 changed_contents
= TRUE
;
678 changed_relocs
= TRUE
;
685 bfd
*obfd
= sec
->output_section
->owner
;
686 gp
= _bfd_get_gp_value (obfd
);
689 if (!elf64_ia64_choose_gp (obfd
, link_info
, FALSE
))
691 gp
= _bfd_get_gp_value (obfd
);
695 /* If the data is out of range, do nothing. */
696 if ((bfd_signed_vma
) (symaddr
- gp
) >= 0x200000
697 ||(bfd_signed_vma
) (symaddr
- gp
) < -0x200000)
700 if (r_type
== R_IA64_GPREL22
)
701 elf64_ia64_update_short_info (tsec
->output_section
,
702 tsec
->output_offset
+ toff
,
704 else if (r_type
== R_IA64_LTOFF22X
)
706 /* Can't deal yet correctly with ABS symbols. */
707 if (bfd_is_abs_section (tsec
))
710 irel
->r_info
= ELF64_R_INFO (ELF64_R_SYM (irel
->r_info
),
712 changed_relocs
= TRUE
;
714 elf64_ia64_update_short_info (tsec
->output_section
,
715 tsec
->output_offset
+ toff
,
720 ia64_elf_relax_ldxmov (contents
, roff
);
721 irel
->r_info
= ELF64_R_INFO (0, R_IA64_NONE
);
722 changed_contents
= TRUE
;
723 changed_relocs
= TRUE
;
728 /* ??? If we created fixups, this may push the code segment large
729 enough that the data segment moves, which will change the GP.
730 Reset the GP so that we re-calculate next round. We need to
731 do this at the _beginning_ of the next round; now will not do. */
733 /* Clean up and go home. */
736 struct one_fixup
*f
= fixups
;
737 fixups
= fixups
->next
;
742 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
744 if (! link_info
->keep_memory
)
748 /* Cache the symbols for elf_link_input_bfd. */
749 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
754 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
756 if (!changed_contents
&& !link_info
->keep_memory
)
760 /* Cache the section contents for elf_link_input_bfd. */
761 elf_section_data (sec
)->this_hdr
.contents
= contents
;
765 if (elf_section_data (sec
)->relocs
!= internal_relocs
)
768 free (internal_relocs
);
770 elf_section_data (sec
)->relocs
= internal_relocs
;
773 if (link_info
->relax_pass
== 0)
775 /* Pass 0 is only needed to relax br. */
776 sec
->skip_relax_pass_0
= skip_relax_pass_0
;
777 sec
->skip_relax_pass_1
= skip_relax_pass_1
;
780 *again
= changed_contents
|| changed_relocs
;
784 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
787 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
789 if (internal_relocs
!= NULL
790 && elf_section_data (sec
)->relocs
!= internal_relocs
)
791 free (internal_relocs
);
794 #undef skip_relax_pass_0
795 #undef skip_relax_pass_1
797 /* Return TRUE if NAME is an unwind table section name. */
799 static inline bfd_boolean
800 is_unwind_section_name (bfd
*abfd ATTRIBUTE_UNUSED
, const char *name
)
802 return ((CONST_STRNEQ (name
, ELF_STRING_ia64_unwind
)
803 && ! CONST_STRNEQ (name
, ELF_STRING_ia64_unwind_info
))
804 || CONST_STRNEQ (name
, ELF_STRING_ia64_unwind_once
));
808 /* Convert IA-64 specific section flags to bfd internal section flags. */
810 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
814 elf64_ia64_section_flags (flagword
*flags
,
815 const Elf_Internal_Shdr
*hdr
)
817 if (hdr
->sh_flags
& SHF_IA_64_SHORT
)
818 *flags
|= SEC_SMALL_DATA
;
823 /* Set the correct type for an IA-64 ELF section. We do this by the
824 section name, which is a hack, but ought to work. */
827 elf64_ia64_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
,
832 name
= bfd_get_section_name (abfd
, sec
);
834 if (is_unwind_section_name (abfd
, name
))
836 /* We don't have the sections numbered at this point, so sh_info
837 is set later, in elf64_ia64_final_write_processing. */
838 hdr
->sh_type
= SHT_IA_64_UNWIND
;
839 hdr
->sh_flags
|= SHF_LINK_ORDER
;
841 else if (strcmp (name
, ELF_STRING_ia64_archext
) == 0)
842 hdr
->sh_type
= SHT_IA_64_EXT
;
844 if (sec
->flags
& SEC_SMALL_DATA
)
845 hdr
->sh_flags
|= SHF_IA_64_SHORT
;
850 /* Hook called by the linker routine which adds symbols from an object
851 file. We use it to put .comm items in .sbss, and not .bss. */
854 elf64_ia64_add_symbol_hook (bfd
*abfd
,
855 struct bfd_link_info
*info
,
856 Elf_Internal_Sym
*sym
,
857 const char **namep ATTRIBUTE_UNUSED
,
858 flagword
*flagsp ATTRIBUTE_UNUSED
,
862 if (sym
->st_shndx
== SHN_COMMON
863 && !bfd_link_relocatable (info
)
864 && sym
->st_size
<= elf_gp_size (abfd
))
866 /* Common symbols less than or equal to -G nn bytes are
867 automatically put into .sbss. */
869 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
873 scomm
= bfd_make_section_with_flags (abfd
, ".scommon",
876 | SEC_LINKER_CREATED
));
882 *valp
= sym
->st_size
;
888 /* According to the Tahoe assembler spec, all labels starting with a
892 elf64_ia64_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
895 return name
[0] == '.';
898 /* Should we do dynamic things to this symbol? */
901 elf64_ia64_dynamic_symbol_p (struct elf_link_hash_entry
*h
)
903 return h
!= NULL
&& h
->def_dynamic
;
906 static struct bfd_hash_entry
*
907 elf64_ia64_new_elf_hash_entry (struct bfd_hash_entry
*entry
,
908 struct bfd_hash_table
*table
,
911 struct elf64_ia64_link_hash_entry
*ret
;
912 ret
= (struct elf64_ia64_link_hash_entry
*) entry
;
914 /* Allocate the structure if it has not already been allocated by a
917 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
922 /* Call the allocation method of the superclass. */
923 ret
= ((struct elf64_ia64_link_hash_entry
*)
924 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
929 ret
->sorted_count
= 0;
931 return (struct bfd_hash_entry
*) ret
;
935 elf64_ia64_hash_hide_symbol (struct bfd_link_info
*info
,
936 struct elf_link_hash_entry
*xh
,
937 bfd_boolean force_local
)
939 struct elf64_ia64_link_hash_entry
*h
;
940 struct elf64_ia64_dyn_sym_info
*dyn_i
;
943 h
= (struct elf64_ia64_link_hash_entry
*)xh
;
945 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
947 for (count
= h
->count
, dyn_i
= h
->info
;
951 dyn_i
->want_plt2
= 0;
956 /* Compute a hash of a local hash entry. */
959 elf64_ia64_local_htab_hash (const void *ptr
)
961 struct elf64_ia64_local_hash_entry
*entry
962 = (struct elf64_ia64_local_hash_entry
*) ptr
;
964 return ELF_LOCAL_SYMBOL_HASH (entry
->id
, entry
->r_sym
);
967 /* Compare local hash entries. */
970 elf64_ia64_local_htab_eq (const void *ptr1
, const void *ptr2
)
972 struct elf64_ia64_local_hash_entry
*entry1
973 = (struct elf64_ia64_local_hash_entry
*) ptr1
;
974 struct elf64_ia64_local_hash_entry
*entry2
975 = (struct elf64_ia64_local_hash_entry
*) ptr2
;
977 return entry1
->id
== entry2
->id
&& entry1
->r_sym
== entry2
->r_sym
;
980 /* Free the global elf64_ia64_dyn_sym_info array. */
983 elf64_ia64_global_dyn_info_free (void **xentry
,
984 void * unused ATTRIBUTE_UNUSED
)
986 struct elf64_ia64_link_hash_entry
*entry
987 = (struct elf64_ia64_link_hash_entry
*) xentry
;
989 if (entry
->root
.root
.type
== bfd_link_hash_warning
)
990 entry
= (struct elf64_ia64_link_hash_entry
*) entry
->root
.root
.u
.i
.link
;
997 entry
->sorted_count
= 0;
1004 /* Free the local elf64_ia64_dyn_sym_info array. */
1007 elf64_ia64_local_dyn_info_free (void **slot
,
1008 void * unused ATTRIBUTE_UNUSED
)
1010 struct elf64_ia64_local_hash_entry
*entry
1011 = (struct elf64_ia64_local_hash_entry
*) *slot
;
1018 entry
->sorted_count
= 0;
1025 /* Destroy IA-64 linker hash table. */
1028 elf64_ia64_link_hash_table_free (bfd
*obfd
)
1030 struct elf64_ia64_link_hash_table
*ia64_info
1031 = (struct elf64_ia64_link_hash_table
*) obfd
->link
.hash
;
1032 if (ia64_info
->loc_hash_table
)
1034 htab_traverse (ia64_info
->loc_hash_table
,
1035 elf64_ia64_local_dyn_info_free
, NULL
);
1036 htab_delete (ia64_info
->loc_hash_table
);
1038 if (ia64_info
->loc_hash_memory
)
1039 objalloc_free ((struct objalloc
*) ia64_info
->loc_hash_memory
);
1040 elf_link_hash_traverse (&ia64_info
->root
,
1041 elf64_ia64_global_dyn_info_free
, NULL
);
1042 _bfd_elf_link_hash_table_free (obfd
);
1045 /* Create the derived linker hash table. The IA-64 ELF port uses this
1046 derived hash table to keep information specific to the IA-64 ElF
1047 linker (without using static variables). */
1049 static struct bfd_link_hash_table
*
1050 elf64_ia64_hash_table_create (bfd
*abfd
)
1052 struct elf64_ia64_link_hash_table
*ret
;
1054 ret
= bfd_zmalloc ((bfd_size_type
) sizeof (*ret
));
1058 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1059 elf64_ia64_new_elf_hash_entry
,
1060 sizeof (struct elf64_ia64_link_hash_entry
),
1067 ret
->loc_hash_table
= htab_try_create (1024, elf64_ia64_local_htab_hash
,
1068 elf64_ia64_local_htab_eq
, NULL
);
1069 ret
->loc_hash_memory
= objalloc_create ();
1070 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
1072 elf64_ia64_link_hash_table_free (abfd
);
1075 ret
->root
.root
.hash_table_free
= elf64_ia64_link_hash_table_free
;
1077 return &ret
->root
.root
;
1080 /* Traverse both local and global hash tables. */
1082 struct elf64_ia64_dyn_sym_traverse_data
1084 bfd_boolean (*func
) (struct elf64_ia64_dyn_sym_info
*, void *);
1089 elf64_ia64_global_dyn_sym_thunk (struct bfd_hash_entry
*xentry
,
1092 struct elf64_ia64_link_hash_entry
*entry
1093 = (struct elf64_ia64_link_hash_entry
*) xentry
;
1094 struct elf64_ia64_dyn_sym_traverse_data
*data
1095 = (struct elf64_ia64_dyn_sym_traverse_data
*) xdata
;
1096 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1099 if (entry
->root
.root
.type
== bfd_link_hash_warning
)
1100 entry
= (struct elf64_ia64_link_hash_entry
*) entry
->root
.root
.u
.i
.link
;
1102 for (count
= entry
->count
, dyn_i
= entry
->info
;
1105 if (! (*data
->func
) (dyn_i
, data
->data
))
1111 elf64_ia64_local_dyn_sym_thunk (void **slot
, void * xdata
)
1113 struct elf64_ia64_local_hash_entry
*entry
1114 = (struct elf64_ia64_local_hash_entry
*) *slot
;
1115 struct elf64_ia64_dyn_sym_traverse_data
*data
1116 = (struct elf64_ia64_dyn_sym_traverse_data
*) xdata
;
1117 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1120 for (count
= entry
->count
, dyn_i
= entry
->info
;
1123 if (! (*data
->func
) (dyn_i
, data
->data
))
1129 elf64_ia64_dyn_sym_traverse (struct elf64_ia64_link_hash_table
*ia64_info
,
1130 bfd_boolean (*func
) (struct elf64_ia64_dyn_sym_info
*, void *),
1133 struct elf64_ia64_dyn_sym_traverse_data xdata
;
1138 elf_link_hash_traverse (&ia64_info
->root
,
1139 elf64_ia64_global_dyn_sym_thunk
, &xdata
);
1140 htab_traverse (ia64_info
->loc_hash_table
,
1141 elf64_ia64_local_dyn_sym_thunk
, &xdata
);
1144 #define NOTE_NAME "IPF/VMS"
1147 create_ia64_vms_notes (bfd
*abfd
, struct bfd_link_info
*info
,
1148 unsigned int time_hi
, unsigned int time_lo
)
1151 Elf_Internal_Note notes
[NBR_NOTES
];
1153 int module_name_len
;
1154 unsigned char cur_time
[8];
1155 Elf64_External_VMS_ORIG_DYN_Note
*orig_dyn
;
1156 unsigned int orig_dyn_size
;
1157 unsigned int note_size
;
1159 unsigned char *noteptr
;
1160 unsigned char *note_contents
;
1161 struct elf64_ia64_link_hash_table
*ia64_info
;
1163 ia64_info
= elf64_ia64_hash_table (info
);
1165 module_name
= vms_get_module_name (bfd_get_filename (abfd
), TRUE
);
1166 module_name_len
= strlen (module_name
) + 1;
1168 bfd_putl32 (time_lo
, cur_time
+ 0);
1169 bfd_putl32 (time_hi
, cur_time
+ 4);
1171 /* Note 0: IMGNAM. */
1172 notes
[0].type
= NT_VMS_IMGNAM
;
1173 notes
[0].descdata
= module_name
;
1174 notes
[0].descsz
= module_name_len
;
1176 /* Note 1: GSTNAM. */
1177 notes
[1].type
= NT_VMS_GSTNAM
;
1178 notes
[1].descdata
= module_name
;
1179 notes
[1].descsz
= module_name_len
;
1181 /* Note 2: IMGID. */
1182 #define IMG_ID "V1.0"
1183 notes
[2].type
= NT_VMS_IMGID
;
1184 notes
[2].descdata
= IMG_ID
;
1185 notes
[2].descsz
= sizeof (IMG_ID
);
1187 /* Note 3: Linktime. */
1188 notes
[3].type
= NT_VMS_LINKTIME
;
1189 notes
[3].descdata
= (char *)cur_time
;
1190 notes
[3].descsz
= sizeof (cur_time
);
1192 /* Note 4: Linker id. */
1193 notes
[4].type
= NT_VMS_LINKID
;
1194 notes
[4].descdata
= "GNU ld " BFD_VERSION_STRING
;
1195 notes
[4].descsz
= strlen (notes
[4].descdata
) + 1;
1197 /* Note 5: Original dyn. */
1198 orig_dyn_size
= (sizeof (*orig_dyn
) + sizeof (IMG_ID
) - 1 + 7) & ~7;
1199 orig_dyn
= bfd_zalloc (abfd
, orig_dyn_size
);
1200 if (orig_dyn
== NULL
)
1202 bfd_putl32 (1, orig_dyn
->major_id
);
1203 bfd_putl32 (3, orig_dyn
->minor_id
);
1204 memcpy (orig_dyn
->manipulation_date
, cur_time
, sizeof (cur_time
));
1205 bfd_putl64 (VMS_LF_IMGSTA
| VMS_LF_MAIN
, orig_dyn
->link_flags
);
1206 bfd_putl32 (EF_IA_64_ABI64
, orig_dyn
->elf_flags
);
1207 memcpy (orig_dyn
->imgid
, IMG_ID
, sizeof (IMG_ID
));
1208 notes
[5].type
= NT_VMS_ORIG_DYN
;
1209 notes
[5].descdata
= (char *)orig_dyn
;
1210 notes
[5].descsz
= orig_dyn_size
;
1212 /* Note 3: Patchtime. */
1213 notes
[6].type
= NT_VMS_PATCHTIME
;
1214 notes
[6].descdata
= (char *)cur_time
;
1215 notes
[6].descsz
= sizeof (cur_time
);
1217 /* Compute notes size. */
1219 for (i
= 0; i
< NBR_NOTES
; i
++)
1220 note_size
+= sizeof (Elf64_External_VMS_Note
) - 1
1221 + ((sizeof (NOTE_NAME
) - 1 + 7) & ~7)
1222 + ((notes
[i
].descsz
+ 7) & ~7);
1224 /* Malloc a temporary buffer large enough for most notes */
1225 note_contents
= (unsigned char *) bfd_zalloc (abfd
, note_size
);
1226 if (note_contents
== NULL
)
1228 noteptr
= note_contents
;
1231 for (i
= 0; i
< NBR_NOTES
; i
++)
1233 Elf64_External_VMS_Note
*enote
= (Elf64_External_VMS_Note
*) noteptr
;
1235 bfd_putl64 (sizeof (NOTE_NAME
) - 1, enote
->namesz
);
1236 bfd_putl64 (notes
[i
].descsz
, enote
->descsz
);
1237 bfd_putl64 (notes
[i
].type
, enote
->type
);
1239 noteptr
= (unsigned char *)enote
->name
;
1240 memcpy (noteptr
, NOTE_NAME
, sizeof (NOTE_NAME
) - 1);
1241 noteptr
+= (sizeof (NOTE_NAME
) - 1 + 7) & ~7;
1242 memcpy (noteptr
, notes
[i
].descdata
, notes
[i
].descsz
);
1243 noteptr
+= (notes
[i
].descsz
+ 7) & ~7;
1246 ia64_info
->note_sec
->contents
= note_contents
;
1247 ia64_info
->note_sec
->size
= note_size
;
1255 elf64_ia64_create_dynamic_sections (bfd
*abfd
,
1256 struct bfd_link_info
*info
)
1258 struct elf64_ia64_link_hash_table
*ia64_info
;
1261 const struct elf_backend_data
*bed
;
1263 ia64_info
= elf64_ia64_hash_table (info
);
1264 if (ia64_info
== NULL
)
1267 if (elf_hash_table (info
)->dynamic_sections_created
)
1270 abfd
= elf_hash_table (info
)->dynobj
;
1271 bed
= get_elf_backend_data (abfd
);
1273 flags
= bed
->dynamic_sec_flags
;
1275 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynamic",
1276 flags
| SEC_READONLY
);
1278 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
1281 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", flags
| SEC_READONLY
);
1283 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
1285 ia64_info
->root
.splt
= s
;
1287 if (!get_got (abfd
, ia64_info
))
1290 if (!get_pltoff (abfd
, ia64_info
))
1293 s
= bfd_make_section_anyway_with_flags (abfd
, ".vmsdynstr",
1297 | SEC_LINKER_CREATED
));
1299 || !bfd_set_section_alignment (abfd
, s
, 0))
1302 /* Create a fixup section. */
1303 s
= bfd_make_section_anyway_with_flags (abfd
, ".fixups",
1307 | SEC_LINKER_CREATED
));
1309 || !bfd_set_section_alignment (abfd
, s
, 3))
1311 ia64_info
->fixups_sec
= s
;
1313 /* Create the transfer fixup section. */
1314 s
= bfd_make_section_anyway_with_flags (abfd
, ".transfer",
1318 | SEC_LINKER_CREATED
));
1320 || !bfd_set_section_alignment (abfd
, s
, 3))
1322 s
->size
= sizeof (struct elf64_vms_transfer
);
1323 ia64_info
->transfer_sec
= s
;
1325 /* Create note section. */
1326 s
= bfd_make_section_anyway_with_flags (abfd
, ".vms.note",
1332 || !bfd_set_section_alignment (abfd
, s
, 3))
1334 ia64_info
->note_sec
= s
;
1336 elf_hash_table (info
)->dynamic_sections_created
= TRUE
;
1340 /* Find and/or create a hash entry for local symbol. */
1341 static struct elf64_ia64_local_hash_entry
*
1342 get_local_sym_hash (struct elf64_ia64_link_hash_table
*ia64_info
,
1343 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
1346 struct elf64_ia64_local_hash_entry e
, *ret
;
1347 asection
*sec
= abfd
->sections
;
1348 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
1349 ELF64_R_SYM (rel
->r_info
));
1353 e
.r_sym
= ELF64_R_SYM (rel
->r_info
);
1354 slot
= htab_find_slot_with_hash (ia64_info
->loc_hash_table
, &e
, h
,
1355 create
? INSERT
: NO_INSERT
);
1361 return (struct elf64_ia64_local_hash_entry
*) *slot
;
1363 ret
= (struct elf64_ia64_local_hash_entry
*)
1364 objalloc_alloc ((struct objalloc
*) ia64_info
->loc_hash_memory
,
1365 sizeof (struct elf64_ia64_local_hash_entry
));
1368 memset (ret
, 0, sizeof (*ret
));
1370 ret
->r_sym
= ELF64_R_SYM (rel
->r_info
);
1376 /* Used to sort elf64_ia64_dyn_sym_info array. */
1379 addend_compare (const void *xp
, const void *yp
)
1381 const struct elf64_ia64_dyn_sym_info
*x
1382 = (const struct elf64_ia64_dyn_sym_info
*) xp
;
1383 const struct elf64_ia64_dyn_sym_info
*y
1384 = (const struct elf64_ia64_dyn_sym_info
*) yp
;
1386 return x
->addend
< y
->addend
? -1 : x
->addend
> y
->addend
? 1 : 0;
1389 /* Sort elf64_ia64_dyn_sym_info array and remove duplicates. */
1392 sort_dyn_sym_info (struct elf64_ia64_dyn_sym_info
*info
,
1395 bfd_vma curr
, prev
, got_offset
;
1396 unsigned int i
, kept
, dupes
, diff
, dest
, src
, len
;
1398 qsort (info
, count
, sizeof (*info
), addend_compare
);
1400 /* Find the first duplicate. */
1401 prev
= info
[0].addend
;
1402 got_offset
= info
[0].got_offset
;
1403 for (i
= 1; i
< count
; i
++)
1405 curr
= info
[i
].addend
;
1408 /* For duplicates, make sure that GOT_OFFSET is valid. */
1409 if (got_offset
== (bfd_vma
) -1)
1410 got_offset
= info
[i
].got_offset
;
1413 got_offset
= info
[i
].got_offset
;
1417 /* We may move a block of elements to here. */
1420 /* Remove duplicates. */
1425 /* For duplicates, make sure that the kept one has a valid
1428 if (got_offset
!= (bfd_vma
) -1)
1429 info
[kept
].got_offset
= got_offset
;
1431 curr
= info
[i
].addend
;
1432 got_offset
= info
[i
].got_offset
;
1434 /* Move a block of elements whose first one is different from
1438 for (src
= i
+ 1; src
< count
; src
++)
1440 if (info
[src
].addend
!= curr
)
1442 /* For duplicates, make sure that GOT_OFFSET is
1444 if (got_offset
== (bfd_vma
) -1)
1445 got_offset
= info
[src
].got_offset
;
1448 /* Make sure that the kept one has a valid got_offset. */
1449 if (got_offset
!= (bfd_vma
) -1)
1450 info
[kept
].got_offset
= got_offset
;
1458 /* Find the next duplicate. SRC will be kept. */
1459 prev
= info
[src
].addend
;
1460 got_offset
= info
[src
].got_offset
;
1461 for (dupes
= src
+ 1; dupes
< count
; dupes
++)
1463 curr
= info
[dupes
].addend
;
1466 /* Make sure that got_offset is valid. */
1467 if (got_offset
== (bfd_vma
) -1)
1468 got_offset
= info
[dupes
].got_offset
;
1470 /* For duplicates, make sure that the kept one has
1471 a valid got_offset. */
1472 if (got_offset
!= (bfd_vma
) -1)
1473 info
[dupes
- 1].got_offset
= got_offset
;
1476 got_offset
= info
[dupes
].got_offset
;
1480 /* How much to move. */
1484 if (len
== 1 && dupes
< count
)
1486 /* If we only move 1 element, we combine it with the next
1487 one. There must be at least a duplicate. Find the
1488 next different one. */
1489 for (diff
= dupes
+ 1, src
++; diff
< count
; diff
++, src
++)
1491 if (info
[diff
].addend
!= curr
)
1493 /* Make sure that got_offset is valid. */
1494 if (got_offset
== (bfd_vma
) -1)
1495 got_offset
= info
[diff
].got_offset
;
1498 /* Makre sure that the last duplicated one has an valid
1500 BFD_ASSERT (curr
== prev
);
1501 if (got_offset
!= (bfd_vma
) -1)
1502 info
[diff
- 1].got_offset
= got_offset
;
1506 /* Find the next duplicate. Track the current valid
1508 prev
= info
[diff
].addend
;
1509 got_offset
= info
[diff
].got_offset
;
1510 for (dupes
= diff
+ 1; dupes
< count
; dupes
++)
1512 curr
= info
[dupes
].addend
;
1515 /* For duplicates, make sure that GOT_OFFSET
1517 if (got_offset
== (bfd_vma
) -1)
1518 got_offset
= info
[dupes
].got_offset
;
1521 got_offset
= info
[dupes
].got_offset
;
1526 len
= diff
- src
+ 1;
1531 memmove (&info
[dest
], &info
[src
], len
* sizeof (*info
));
1540 /* When we get here, either there is no duplicate at all or
1541 the only duplicate is the last element. */
1544 /* If the last element is a duplicate, make sure that the
1545 kept one has a valid got_offset. We also update count. */
1546 if (got_offset
!= (bfd_vma
) -1)
1547 info
[dest
- 1].got_offset
= got_offset
;
1555 /* Find and/or create a descriptor for dynamic symbol info. This will
1556 vary based on global or local symbol, and the addend to the reloc.
1558 We don't sort when inserting. Also, we sort and eliminate
1559 duplicates if there is an unsorted section. Typically, this will
1560 only happen once, because we do all insertions before lookups. We
1561 then use bsearch to do a lookup. This also allows lookups to be
1562 fast. So we have fast insertion (O(log N) due to duplicate check),
1563 fast lookup (O(log N)) and one sort (O(N log N) expected time).
1564 Previously, all lookups were O(N) because of the use of the linked
1565 list and also all insertions were O(N) because of the check for
1566 duplicates. There are some complications here because the array
1567 size grows occasionally, which may add an O(N) factor, but this
1568 should be rare. Also, we free the excess array allocation, which
1569 requires a copy which is O(N), but this only happens once. */
1571 static struct elf64_ia64_dyn_sym_info
*
1572 get_dyn_sym_info (struct elf64_ia64_link_hash_table
*ia64_info
,
1573 struct elf_link_hash_entry
*h
, bfd
*abfd
,
1574 const Elf_Internal_Rela
*rel
, bfd_boolean create
)
1576 struct elf64_ia64_dyn_sym_info
**info_p
, *info
, *dyn_i
, key
;
1577 unsigned int *count_p
, *sorted_count_p
, *size_p
;
1578 unsigned int count
, sorted_count
, size
;
1579 bfd_vma addend
= rel
? rel
->r_addend
: 0;
1584 struct elf64_ia64_link_hash_entry
*global_h
;
1586 global_h
= (struct elf64_ia64_link_hash_entry
*) h
;
1587 info_p
= &global_h
->info
;
1588 count_p
= &global_h
->count
;
1589 sorted_count_p
= &global_h
->sorted_count
;
1590 size_p
= &global_h
->size
;
1594 struct elf64_ia64_local_hash_entry
*loc_h
;
1596 loc_h
= get_local_sym_hash (ia64_info
, abfd
, rel
, create
);
1599 BFD_ASSERT (!create
);
1603 info_p
= &loc_h
->info
;
1604 count_p
= &loc_h
->count
;
1605 sorted_count_p
= &loc_h
->sorted_count
;
1606 size_p
= &loc_h
->size
;
1610 sorted_count
= *sorted_count_p
;
1615 /* When we create the array, we don't check for duplicates,
1616 except in the previously sorted section if one exists, and
1617 against the last inserted entry. This allows insertions to
1623 /* Try bsearch first on the sorted section. */
1624 key
.addend
= addend
;
1625 dyn_i
= bsearch (&key
, info
, sorted_count
,
1626 sizeof (*info
), addend_compare
);
1634 /* Do a quick check for the last inserted entry. */
1635 dyn_i
= info
+ count
- 1;
1636 if (dyn_i
->addend
== addend
)
1644 /* It is the very first element. We create the array of size
1647 amt
= size
* sizeof (*info
);
1648 info
= bfd_malloc (amt
);
1650 else if (size
<= count
)
1652 /* We double the array size every time when we reach the
1655 amt
= size
* sizeof (*info
);
1656 info
= bfd_realloc (info
, amt
);
1667 /* Append the new one to the array. */
1668 dyn_i
= info
+ count
;
1669 memset (dyn_i
, 0, sizeof (*dyn_i
));
1670 dyn_i
->got_offset
= (bfd_vma
) -1;
1671 dyn_i
->addend
= addend
;
1673 /* We increment count only since the new ones are unsorted and
1674 may have duplicate. */
1679 /* It is a lookup without insertion. Sort array if part of the
1680 array isn't sorted. */
1681 if (count
!= sorted_count
)
1683 count
= sort_dyn_sym_info (info
, count
);
1685 *sorted_count_p
= count
;
1688 /* Free unused memory. */
1691 amt
= count
* sizeof (*info
);
1692 info
= bfd_malloc (amt
);
1695 memcpy (info
, *info_p
, amt
);
1702 key
.addend
= addend
;
1703 dyn_i
= bsearch (&key
, info
, count
,
1704 sizeof (*info
), addend_compare
);
1711 get_got (bfd
*abfd
, struct elf64_ia64_link_hash_table
*ia64_info
)
1716 got
= ia64_info
->root
.sgot
;
1721 dynobj
= ia64_info
->root
.dynobj
;
1723 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1725 /* The .got section is always aligned at 8 bytes. */
1726 flags
= get_elf_backend_data (dynobj
)->dynamic_sec_flags
;
1727 got
= bfd_make_section_anyway_with_flags (dynobj
, ".got",
1728 flags
| SEC_SMALL_DATA
);
1730 || !bfd_set_section_alignment (dynobj
, got
, 3))
1732 ia64_info
->root
.sgot
= got
;
1738 /* Create function descriptor section (.opd). This section is called .opd
1739 because it contains "official procedure descriptors". The "official"
1740 refers to the fact that these descriptors are used when taking the address
1741 of a procedure, thus ensuring a unique address for each procedure. */
1744 get_fptr (bfd
*abfd
, struct bfd_link_info
*info
,
1745 struct elf64_ia64_link_hash_table
*ia64_info
)
1750 fptr
= ia64_info
->fptr_sec
;
1753 dynobj
= ia64_info
->root
.dynobj
;
1755 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1757 fptr
= bfd_make_section_anyway_with_flags (dynobj
, ".opd",
1762 | (bfd_link_pie (info
) ? 0
1764 | SEC_LINKER_CREATED
));
1766 || !bfd_set_section_alignment (dynobj
, fptr
, 4))
1772 ia64_info
->fptr_sec
= fptr
;
1774 if (bfd_link_pie (info
))
1777 fptr_rel
= bfd_make_section_anyway_with_flags (dynobj
, ".rela.opd",
1778 (SEC_ALLOC
| SEC_LOAD
1781 | SEC_LINKER_CREATED
1783 if (fptr_rel
== NULL
1784 || !bfd_set_section_alignment (dynobj
, fptr_rel
, 3))
1790 ia64_info
->rel_fptr_sec
= fptr_rel
;
1798 get_pltoff (bfd
*abfd
, struct elf64_ia64_link_hash_table
*ia64_info
)
1803 pltoff
= ia64_info
->pltoff_sec
;
1806 dynobj
= ia64_info
->root
.dynobj
;
1808 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1810 pltoff
= bfd_make_section_anyway_with_flags (dynobj
,
1811 ELF_STRING_ia64_pltoff
,
1817 | SEC_LINKER_CREATED
));
1819 || !bfd_set_section_alignment (dynobj
, pltoff
, 4))
1825 ia64_info
->pltoff_sec
= pltoff
;
1832 get_reloc_section (bfd
*abfd
,
1833 struct elf64_ia64_link_hash_table
*ia64_info
,
1834 asection
*sec
, bfd_boolean create
)
1836 const char *srel_name
;
1840 srel_name
= (bfd_elf_string_from_elf_section
1841 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1842 _bfd_elf_single_rel_hdr (sec
)->sh_name
));
1843 if (srel_name
== NULL
)
1846 BFD_ASSERT ((CONST_STRNEQ (srel_name
, ".rela")
1847 && strcmp (bfd_get_section_name (abfd
, sec
),
1849 || (CONST_STRNEQ (srel_name
, ".rel")
1850 && strcmp (bfd_get_section_name (abfd
, sec
),
1851 srel_name
+4) == 0));
1853 dynobj
= ia64_info
->root
.dynobj
;
1855 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1857 srel
= bfd_get_linker_section (dynobj
, srel_name
);
1858 if (srel
== NULL
&& create
)
1860 srel
= bfd_make_section_anyway_with_flags (dynobj
, srel_name
,
1861 (SEC_ALLOC
| SEC_LOAD
1864 | SEC_LINKER_CREATED
1867 || !bfd_set_section_alignment (dynobj
, srel
, 3))
1875 count_dyn_reloc (bfd
*abfd
, struct elf64_ia64_dyn_sym_info
*dyn_i
,
1876 asection
*srel
, int type
)
1878 struct elf64_ia64_dyn_reloc_entry
*rent
;
1880 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
1881 if (rent
->srel
== srel
&& rent
->type
== type
)
1886 rent
= ((struct elf64_ia64_dyn_reloc_entry
*)
1887 bfd_alloc (abfd
, (bfd_size_type
) sizeof (*rent
)));
1891 rent
->next
= dyn_i
->reloc_entries
;
1895 dyn_i
->reloc_entries
= rent
;
1903 elf64_ia64_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
1905 const Elf_Internal_Rela
*relocs
)
1907 struct elf64_ia64_link_hash_table
*ia64_info
;
1908 const Elf_Internal_Rela
*relend
;
1909 Elf_Internal_Shdr
*symtab_hdr
;
1910 const Elf_Internal_Rela
*rel
;
1911 asection
*got
, *fptr
, *srel
, *pltoff
;
1920 NEED_LTOFF_FPTR
= 128
1923 struct elf_link_hash_entry
*h
;
1924 unsigned long r_symndx
;
1925 bfd_boolean maybe_dynamic
;
1927 if (bfd_link_relocatable (info
))
1930 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1931 ia64_info
= elf64_ia64_hash_table (info
);
1932 if (ia64_info
== NULL
)
1935 got
= fptr
= srel
= pltoff
= NULL
;
1937 relend
= relocs
+ sec
->reloc_count
;
1939 /* We scan relocations first to create dynamic relocation arrays. We
1940 modified get_dyn_sym_info to allow fast insertion and support fast
1941 lookup in the next loop. */
1942 for (rel
= relocs
; rel
< relend
; ++rel
)
1944 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1945 if (r_symndx
>= symtab_hdr
->sh_info
)
1947 long indx
= r_symndx
- symtab_hdr
->sh_info
;
1948 h
= elf_sym_hashes (abfd
)[indx
];
1949 while (h
->root
.type
== bfd_link_hash_indirect
1950 || h
->root
.type
== bfd_link_hash_warning
)
1951 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1956 /* We can only get preliminary data on whether a symbol is
1957 locally or externally defined, as not all of the input files
1958 have yet been processed. Do something with what we know, as
1959 this may help reduce memory usage and processing time later. */
1960 maybe_dynamic
= (h
&& ((!bfd_link_executable (info
)
1961 && (!SYMBOLIC_BIND (info
, h
)
1962 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
1964 || h
->root
.type
== bfd_link_hash_defweak
));
1967 switch (ELF64_R_TYPE (rel
->r_info
))
1969 case R_IA64_TPREL64MSB
:
1970 case R_IA64_TPREL64LSB
:
1971 case R_IA64_LTOFF_TPREL22
:
1972 case R_IA64_DTPREL32MSB
:
1973 case R_IA64_DTPREL32LSB
:
1974 case R_IA64_DTPREL64MSB
:
1975 case R_IA64_DTPREL64LSB
:
1976 case R_IA64_LTOFF_DTPREL22
:
1977 case R_IA64_DTPMOD64MSB
:
1978 case R_IA64_DTPMOD64LSB
:
1979 case R_IA64_LTOFF_DTPMOD22
:
1983 case R_IA64_IPLTMSB
:
1984 case R_IA64_IPLTLSB
:
1987 case R_IA64_LTOFF_FPTR22
:
1988 case R_IA64_LTOFF_FPTR64I
:
1989 case R_IA64_LTOFF_FPTR32MSB
:
1990 case R_IA64_LTOFF_FPTR32LSB
:
1991 case R_IA64_LTOFF_FPTR64MSB
:
1992 case R_IA64_LTOFF_FPTR64LSB
:
1993 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
1996 case R_IA64_FPTR64I
:
1997 case R_IA64_FPTR32MSB
:
1998 case R_IA64_FPTR32LSB
:
1999 case R_IA64_FPTR64MSB
:
2000 case R_IA64_FPTR64LSB
:
2001 if (bfd_link_pic (info
) || h
)
2002 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2004 need_entry
= NEED_FPTR
;
2007 case R_IA64_LTOFF22
:
2008 case R_IA64_LTOFF64I
:
2009 need_entry
= NEED_GOT
;
2012 case R_IA64_LTOFF22X
:
2013 need_entry
= NEED_GOTX
;
2016 case R_IA64_PLTOFF22
:
2017 case R_IA64_PLTOFF64I
:
2018 case R_IA64_PLTOFF64MSB
:
2019 case R_IA64_PLTOFF64LSB
:
2020 need_entry
= NEED_PLTOFF
;
2024 need_entry
|= NEED_MIN_PLT
;
2028 (*info
->callbacks
->warning
)
2029 (info
, _("@pltoff reloc against local symbol"), 0,
2030 abfd
, 0, (bfd_vma
) 0);
2034 case R_IA64_PCREL21B
:
2035 case R_IA64_PCREL60B
:
2036 /* Depending on where this symbol is defined, we may or may not
2037 need a full plt entry. Only skip if we know we'll not need
2038 the entry -- static or symbolic, and the symbol definition
2039 has already been seen. */
2040 if (maybe_dynamic
&& rel
->r_addend
== 0)
2041 need_entry
= NEED_FULL_PLT
;
2047 case R_IA64_DIR32MSB
:
2048 case R_IA64_DIR32LSB
:
2049 case R_IA64_DIR64MSB
:
2050 case R_IA64_DIR64LSB
:
2051 /* Shared objects will always need at least a REL relocation. */
2052 if (bfd_link_pic (info
) || maybe_dynamic
)
2053 need_entry
= NEED_DYNREL
;
2056 case R_IA64_PCREL22
:
2057 case R_IA64_PCREL64I
:
2058 case R_IA64_PCREL32MSB
:
2059 case R_IA64_PCREL32LSB
:
2060 case R_IA64_PCREL64MSB
:
2061 case R_IA64_PCREL64LSB
:
2063 need_entry
= NEED_DYNREL
;
2070 if ((need_entry
& NEED_FPTR
) != 0
2073 (*info
->callbacks
->warning
)
2074 (info
, _("non-zero addend in @fptr reloc"), 0,
2075 abfd
, 0, (bfd_vma
) 0);
2078 if (get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, TRUE
) == NULL
)
2082 /* Now, we only do lookup without insertion, which is very fast
2083 with the modified get_dyn_sym_info. */
2084 for (rel
= relocs
; rel
< relend
; ++rel
)
2086 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2087 int dynrel_type
= R_IA64_NONE
;
2089 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2090 if (r_symndx
>= symtab_hdr
->sh_info
)
2092 /* We're dealing with a global symbol -- find its hash entry
2093 and mark it as being referenced. */
2094 long indx
= r_symndx
- symtab_hdr
->sh_info
;
2095 h
= elf_sym_hashes (abfd
)[indx
];
2096 while (h
->root
.type
== bfd_link_hash_indirect
2097 || h
->root
.type
== bfd_link_hash_warning
)
2098 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2100 /* PR15323, ref flags aren't set for references in the same
2102 h
->root
.non_ir_ref
= 1;
2108 /* We can only get preliminary data on whether a symbol is
2109 locally or externally defined, as not all of the input files
2110 have yet been processed. Do something with what we know, as
2111 this may help reduce memory usage and processing time later. */
2112 maybe_dynamic
= (h
&& ((!bfd_link_executable (info
)
2113 && (!SYMBOLIC_BIND (info
, h
)
2114 || info
->unresolved_syms_in_shared_libs
== RM_IGNORE
))
2116 || h
->root
.type
== bfd_link_hash_defweak
));
2119 switch (ELF64_R_TYPE (rel
->r_info
))
2121 case R_IA64_TPREL64MSB
:
2122 case R_IA64_TPREL64LSB
:
2123 case R_IA64_LTOFF_TPREL22
:
2124 case R_IA64_DTPREL32MSB
:
2125 case R_IA64_DTPREL32LSB
:
2126 case R_IA64_DTPREL64MSB
:
2127 case R_IA64_DTPREL64LSB
:
2128 case R_IA64_LTOFF_DTPREL22
:
2129 case R_IA64_DTPMOD64MSB
:
2130 case R_IA64_DTPMOD64LSB
:
2131 case R_IA64_LTOFF_DTPMOD22
:
2135 case R_IA64_LTOFF_FPTR22
:
2136 case R_IA64_LTOFF_FPTR64I
:
2137 case R_IA64_LTOFF_FPTR32MSB
:
2138 case R_IA64_LTOFF_FPTR32LSB
:
2139 case R_IA64_LTOFF_FPTR64MSB
:
2140 case R_IA64_LTOFF_FPTR64LSB
:
2141 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
2144 case R_IA64_FPTR64I
:
2145 case R_IA64_FPTR32MSB
:
2146 case R_IA64_FPTR32LSB
:
2147 case R_IA64_FPTR64MSB
:
2148 case R_IA64_FPTR64LSB
:
2149 if (bfd_link_pic (info
) || h
)
2150 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2152 need_entry
= NEED_FPTR
;
2153 dynrel_type
= R_IA64_FPTR64LSB
;
2156 case R_IA64_LTOFF22
:
2157 case R_IA64_LTOFF64I
:
2158 need_entry
= NEED_GOT
;
2161 case R_IA64_LTOFF22X
:
2162 need_entry
= NEED_GOTX
;
2165 case R_IA64_PLTOFF22
:
2166 case R_IA64_PLTOFF64I
:
2167 case R_IA64_PLTOFF64MSB
:
2168 case R_IA64_PLTOFF64LSB
:
2169 need_entry
= NEED_PLTOFF
;
2173 need_entry
|= NEED_MIN_PLT
;
2177 case R_IA64_PCREL21B
:
2178 case R_IA64_PCREL60B
:
2179 /* Depending on where this symbol is defined, we may or may not
2180 need a full plt entry. Only skip if we know we'll not need
2181 the entry -- static or symbolic, and the symbol definition
2182 has already been seen. */
2183 if (maybe_dynamic
&& rel
->r_addend
== 0)
2184 need_entry
= NEED_FULL_PLT
;
2190 case R_IA64_DIR32MSB
:
2191 case R_IA64_DIR32LSB
:
2192 case R_IA64_DIR64MSB
:
2193 case R_IA64_DIR64LSB
:
2194 /* Shared objects will always need at least a REL relocation. */
2195 if (bfd_link_pic (info
) || maybe_dynamic
)
2196 need_entry
= NEED_DYNREL
;
2197 dynrel_type
= R_IA64_DIR64LSB
;
2200 case R_IA64_IPLTMSB
:
2201 case R_IA64_IPLTLSB
:
2204 case R_IA64_PCREL22
:
2205 case R_IA64_PCREL64I
:
2206 case R_IA64_PCREL32MSB
:
2207 case R_IA64_PCREL32LSB
:
2208 case R_IA64_PCREL64MSB
:
2209 case R_IA64_PCREL64LSB
:
2211 need_entry
= NEED_DYNREL
;
2212 dynrel_type
= R_IA64_PCREL64LSB
;
2219 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, FALSE
);
2221 /* Record whether or not this is a local symbol. */
2224 /* Create what's needed. */
2225 if (need_entry
& (NEED_GOT
| NEED_GOTX
))
2229 got
= get_got (abfd
, ia64_info
);
2233 if (need_entry
& NEED_GOT
)
2234 dyn_i
->want_got
= 1;
2235 if (need_entry
& NEED_GOTX
)
2236 dyn_i
->want_gotx
= 1;
2238 if (need_entry
& NEED_FPTR
)
2240 /* Create the .opd section. */
2243 fptr
= get_fptr (abfd
, info
, ia64_info
);
2247 dyn_i
->want_fptr
= 1;
2249 if (need_entry
& NEED_LTOFF_FPTR
)
2250 dyn_i
->want_ltoff_fptr
= 1;
2251 if (need_entry
& (NEED_MIN_PLT
| NEED_FULL_PLT
))
2253 if (!ia64_info
->root
.dynobj
)
2254 ia64_info
->root
.dynobj
= abfd
;
2256 dyn_i
->want_plt
= 1;
2258 if (need_entry
& NEED_FULL_PLT
)
2259 dyn_i
->want_plt2
= 1;
2260 if (need_entry
& NEED_PLTOFF
)
2262 /* This is needed here, in case @pltoff is used in a non-shared
2266 pltoff
= get_pltoff (abfd
, ia64_info
);
2271 dyn_i
->want_pltoff
= 1;
2273 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
2277 srel
= get_reloc_section (abfd
, ia64_info
, sec
, TRUE
);
2281 if (!count_dyn_reloc (abfd
, dyn_i
, srel
, dynrel_type
))
2289 /* For cleanliness, and potentially faster dynamic loading, allocate
2290 external GOT entries first. */
2293 allocate_global_data_got (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2296 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2298 if ((dyn_i
->want_got
|| dyn_i
->want_gotx
)
2299 && ! dyn_i
->want_fptr
2300 && elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
2302 /* GOT entry with FPTR is done by allocate_global_fptr_got. */
2303 dyn_i
->got_offset
= x
->ofs
;
2309 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2312 allocate_global_fptr_got (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2315 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2319 && elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
2321 dyn_i
->got_offset
= x
->ofs
;
2327 /* Lastly, allocate all the GOT entries for local data. */
2330 allocate_local_got (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2333 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*) data
;
2335 if ((dyn_i
->want_got
|| dyn_i
->want_gotx
)
2336 && !elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
2338 dyn_i
->got_offset
= x
->ofs
;
2344 /* Allocate function descriptors. We can do these for every function
2345 in a main executable that is not exported. */
2348 allocate_fptr (struct elf64_ia64_dyn_sym_info
*dyn_i
, void * data
)
2350 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*) data
;
2352 if (dyn_i
->want_fptr
)
2354 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2357 while (h
->root
.type
== bfd_link_hash_indirect
2358 || h
->root
.type
== bfd_link_hash_warning
)
2359 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2361 if (h
== NULL
|| !h
->def_dynamic
)
2363 /* A non dynamic symbol. */
2364 dyn_i
->fptr_offset
= x
->ofs
;
2368 dyn_i
->want_fptr
= 0;
2373 /* Allocate all the minimal PLT entries. */
2376 allocate_plt_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2377 void * data ATTRIBUTE_UNUSED
)
2379 if (dyn_i
->want_plt
)
2381 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2384 while (h
->root
.type
== bfd_link_hash_indirect
2385 || h
->root
.type
== bfd_link_hash_warning
)
2386 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2388 /* ??? Versioned symbols seem to lose NEEDS_PLT. */
2389 if (elf64_ia64_dynamic_symbol_p (h
))
2391 dyn_i
->want_pltoff
= 1;
2395 dyn_i
->want_plt
= 0;
2396 dyn_i
->want_plt2
= 0;
2402 /* Allocate all the full PLT entries. */
2405 allocate_plt2_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2408 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2410 if (dyn_i
->want_plt2
)
2412 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2413 bfd_size_type ofs
= x
->ofs
;
2415 dyn_i
->plt2_offset
= ofs
;
2416 x
->ofs
= ofs
+ PLT_FULL_ENTRY_SIZE
;
2418 while (h
->root
.type
== bfd_link_hash_indirect
2419 || h
->root
.type
== bfd_link_hash_warning
)
2420 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2421 dyn_i
->h
->plt
.offset
= ofs
;
2426 /* Allocate all the PLTOFF entries requested by relocations and
2427 plt entries. We can't share space with allocated FPTR entries,
2428 because the latter are not necessarily addressable by the GP.
2429 ??? Relaxation might be able to determine that they are. */
2432 allocate_pltoff_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2435 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2437 if (dyn_i
->want_pltoff
)
2439 dyn_i
->pltoff_offset
= x
->ofs
;
2445 /* Allocate dynamic relocations for those symbols that turned out
2449 allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info
*dyn_i
,
2452 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
2453 struct elf64_ia64_link_hash_table
*ia64_info
;
2454 struct elf64_ia64_dyn_reloc_entry
*rent
;
2455 bfd_boolean dynamic_symbol
, shared
, resolved_zero
;
2456 struct elf64_ia64_link_hash_entry
*h_ia64
;
2458 ia64_info
= elf64_ia64_hash_table (x
->info
);
2459 if (ia64_info
== NULL
)
2462 /* Note that this can't be used in relation to FPTR relocs below. */
2463 dynamic_symbol
= elf64_ia64_dynamic_symbol_p (dyn_i
->h
);
2465 shared
= bfd_link_pic (x
->info
);
2466 resolved_zero
= (dyn_i
->h
2467 && ELF_ST_VISIBILITY (dyn_i
->h
->other
)
2468 && dyn_i
->h
->root
.type
== bfd_link_hash_undefweak
);
2470 /* Take care of the GOT and PLT relocations. */
2473 && (dynamic_symbol
|| shared
)
2474 && (dyn_i
->want_got
|| dyn_i
->want_gotx
))
2475 || (dyn_i
->want_ltoff_fptr
2477 && dyn_i
->h
->def_dynamic
))
2480 if (dyn_i
->h
!= NULL
&& dyn_i
->h
->def_dynamic
)
2482 h_ia64
= (struct elf64_ia64_link_hash_entry
*) dyn_i
->h
;
2483 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2484 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2485 ia64_info
->fixups_sec
->size
+=
2486 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2490 if (ia64_info
->rel_fptr_sec
&& dyn_i
->want_fptr
)
2492 /* VMS: only image reloc. */
2493 if (dyn_i
->h
== NULL
|| dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
)
2494 ia64_info
->rel_fptr_sec
->size
+= sizeof (Elf64_External_Rela
);
2497 if (!resolved_zero
&& dyn_i
->want_pltoff
)
2500 if (dyn_i
->h
!= NULL
&& dyn_i
->h
->def_dynamic
)
2502 h_ia64
= (struct elf64_ia64_link_hash_entry
*) dyn_i
->h
;
2503 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2504 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2505 ia64_info
->fixups_sec
->size
+=
2506 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2510 /* Take care of the normal data relocations. */
2512 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
2514 int count
= rent
->count
;
2518 case R_IA64_FPTR32LSB
:
2519 case R_IA64_FPTR64LSB
:
2520 /* Allocate one iff !want_fptr and not PIE, which by this point
2521 will be true only if we're actually allocating one statically
2522 in the main executable. Position independent executables
2523 need a relative reloc. */
2524 if (dyn_i
->want_fptr
&& !bfd_link_pie (x
->info
))
2527 case R_IA64_PCREL32LSB
:
2528 case R_IA64_PCREL64LSB
:
2529 if (!dynamic_symbol
)
2532 case R_IA64_DIR32LSB
:
2533 case R_IA64_DIR64LSB
:
2534 if (!dynamic_symbol
&& !shared
)
2537 case R_IA64_IPLTLSB
:
2538 if (!dynamic_symbol
&& !shared
)
2540 /* Use two REL relocations for IPLT relocations
2541 against local symbols. */
2542 if (!dynamic_symbol
)
2545 case R_IA64_DTPREL32LSB
:
2546 case R_IA64_TPREL64LSB
:
2547 case R_IA64_DTPREL64LSB
:
2548 case R_IA64_DTPMOD64LSB
:
2555 if (!dynamic_symbol
)
2558 h_ia64
= (struct elf64_ia64_link_hash_entry
*) dyn_i
->h
;
2559 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2560 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2561 ia64_info
->fixups_sec
->size
+=
2562 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2569 elf64_ia64_adjust_dynamic_symbol (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2570 struct elf_link_hash_entry
*h
)
2572 /* ??? Undefined symbols with PLT entries should be re-defined
2573 to be the PLT entry. */
2575 /* If this is a weak symbol, and there is a real definition, the
2576 processor independent code will have arranged for us to see the
2577 real definition first, and we can just use the same value. */
2578 if (h
->u
.weakdef
!= NULL
)
2580 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2581 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2582 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2583 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2587 /* If this is a reference to a symbol defined by a dynamic object which
2588 is not a function, we might allocate the symbol in our .dynbss section
2589 and allocate a COPY dynamic relocation.
2591 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
2598 elf64_ia64_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2599 struct bfd_link_info
*info
)
2601 struct elf64_ia64_allocate_data data
;
2602 struct elf64_ia64_link_hash_table
*ia64_info
;
2605 struct elf_link_hash_table
*hash_table
;
2607 hash_table
= elf_hash_table (info
);
2608 dynobj
= hash_table
->dynobj
;
2609 ia64_info
= elf64_ia64_hash_table (info
);
2610 if (ia64_info
== NULL
)
2612 BFD_ASSERT(dynobj
!= NULL
);
2615 /* Allocate the GOT entries. */
2617 if (ia64_info
->root
.sgot
)
2620 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_global_data_got
, &data
);
2621 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_global_fptr_got
, &data
);
2622 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_local_got
, &data
);
2623 ia64_info
->root
.sgot
->size
= data
.ofs
;
2626 /* Allocate the FPTR entries. */
2628 if (ia64_info
->fptr_sec
)
2631 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_fptr
, &data
);
2632 ia64_info
->fptr_sec
->size
= data
.ofs
;
2635 /* Now that we've seen all of the input files, we can decide which
2636 symbols need plt entries. Allocate the minimal PLT entries first.
2637 We do this even though dynamic_sections_created may be FALSE, because
2638 this has the side-effect of clearing want_plt and want_plt2. */
2641 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_plt_entries
, &data
);
2643 /* Align the pointer for the plt2 entries. */
2644 data
.ofs
= (data
.ofs
+ 31) & (bfd_vma
) -32;
2646 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_plt2_entries
, &data
);
2647 if (data
.ofs
!= 0 || ia64_info
->root
.dynamic_sections_created
)
2649 /* FIXME: we always reserve the memory for dynamic linker even if
2650 there are no PLT entries since dynamic linker may assume the
2651 reserved memory always exists. */
2653 BFD_ASSERT (ia64_info
->root
.dynamic_sections_created
);
2655 ia64_info
->root
.splt
->size
= data
.ofs
;
2658 /* Allocate the PLTOFF entries. */
2660 if (ia64_info
->pltoff_sec
)
2663 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_pltoff_entries
, &data
);
2664 ia64_info
->pltoff_sec
->size
= data
.ofs
;
2667 if (ia64_info
->root
.dynamic_sections_created
)
2669 /* Allocate space for the dynamic relocations that turned out to be
2671 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_dynrel_entries
, &data
);
2674 /* We have now determined the sizes of the various dynamic sections.
2675 Allocate memory for them. */
2676 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2680 if (!(sec
->flags
& SEC_LINKER_CREATED
))
2683 /* If we don't need this section, strip it from the output file.
2684 There were several sections primarily related to dynamic
2685 linking that must be create before the linker maps input
2686 sections to output sections. The linker does that before
2687 bfd_elf_size_dynamic_sections is called, and it is that
2688 function which decides whether anything needs to go into
2691 strip
= (sec
->size
== 0);
2693 if (sec
== ia64_info
->root
.sgot
)
2695 else if (sec
== ia64_info
->root
.srelgot
)
2698 ia64_info
->root
.srelgot
= NULL
;
2700 /* We use the reloc_count field as a counter if we need to
2701 copy relocs into the output file. */
2702 sec
->reloc_count
= 0;
2704 else if (sec
== ia64_info
->fptr_sec
)
2707 ia64_info
->fptr_sec
= NULL
;
2709 else if (sec
== ia64_info
->rel_fptr_sec
)
2712 ia64_info
->rel_fptr_sec
= NULL
;
2714 /* We use the reloc_count field as a counter if we need to
2715 copy relocs into the output file. */
2716 sec
->reloc_count
= 0;
2718 else if (sec
== ia64_info
->root
.splt
)
2721 ia64_info
->root
.splt
= NULL
;
2723 else if (sec
== ia64_info
->pltoff_sec
)
2726 ia64_info
->pltoff_sec
= NULL
;
2728 else if (sec
== ia64_info
->fixups_sec
)
2731 ia64_info
->fixups_sec
= NULL
;
2733 else if (sec
== ia64_info
->transfer_sec
)
2741 /* It's OK to base decisions on the section name, because none
2742 of the dynobj section names depend upon the input files. */
2743 name
= bfd_get_section_name (dynobj
, sec
);
2745 if (strcmp (name
, ".got.plt") == 0)
2747 else if (CONST_STRNEQ (name
, ".rel"))
2751 /* We use the reloc_count field as a counter if we need to
2752 copy relocs into the output file. */
2753 sec
->reloc_count
= 0;
2761 sec
->flags
|= SEC_EXCLUDE
;
2764 /* Allocate memory for the section contents. */
2765 sec
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, sec
->size
);
2766 if (sec
->contents
== NULL
&& sec
->size
!= 0)
2771 if (elf_hash_table (info
)->dynamic_sections_created
)
2775 asection
*dynstrsec
;
2776 Elf_Internal_Dyn dyn
;
2777 const struct elf_backend_data
*bed
;
2778 unsigned int shl_num
= 0;
2779 bfd_vma fixups_off
= 0;
2781 unsigned int time_hi
, time_lo
;
2783 /* The .dynamic section must exist and be empty. */
2784 dynsec
= bfd_get_linker_section (hash_table
->dynobj
, ".dynamic");
2785 BFD_ASSERT (dynsec
!= NULL
);
2786 BFD_ASSERT (dynsec
->size
== 0);
2788 dynstrsec
= bfd_get_linker_section (hash_table
->dynobj
, ".vmsdynstr");
2789 BFD_ASSERT (dynstrsec
!= NULL
);
2790 BFD_ASSERT (dynstrsec
->size
== 0);
2791 dynstrsec
->size
= 1; /* Initial blank. */
2793 /* Ident + link time. */
2794 vms_get_time (&time_hi
, &time_lo
);
2796 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_IDENT
, 0))
2798 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_LINKTIME
,
2799 (((bfd_uint64_t
)time_hi
) << 32)
2804 strdyn_off
= dynsec
->size
;
2805 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_STRTAB_OFFSET
, 0))
2807 if (!_bfd_elf_add_dynamic_entry (info
, DT_STRSZ
, 0))
2811 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_PLTGOT_SEG
, 0))
2813 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_PLTGOT_OFFSET
, 0))
2817 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_FPMODE
, 0x9800000))
2819 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_LNKFLAGS
,
2820 VMS_LF_IMGSTA
| VMS_LF_MAIN
))
2823 /* Add entries for shared libraries. */
2824 for (abfd
= info
->input_bfds
; abfd
; abfd
= abfd
->link
.next
)
2828 bfd_size_type strindex
;
2829 bfd_byte
*newcontents
;
2830 bfd_vma fixups_shl_off
;
2832 if (!(abfd
->flags
& DYNAMIC
))
2834 BFD_ASSERT (abfd
->xvec
== output_bfd
->xvec
);
2836 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_NEEDED_IDENT
,
2837 elf_ia64_vms_ident (abfd
)))
2840 soname
= vms_get_module_name (abfd
->filename
, TRUE
);
2843 strindex
= dynstrsec
->size
;
2844 soname_len
= strlen (soname
) + 1;
2845 newcontents
= (bfd_byte
*) bfd_realloc (dynstrsec
->contents
,
2846 strindex
+ soname_len
);
2847 if (newcontents
== NULL
)
2849 memcpy (newcontents
+ strindex
, soname
, soname_len
);
2850 dynstrsec
->size
+= soname_len
;
2851 dynstrsec
->contents
= newcontents
;
2853 if (!_bfd_elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
2856 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_FIXUP_NEEDED
,
2861 /* The fixups_off was in fact containing the size of the fixup
2862 section. Remap into the offset. */
2863 fixups_shl_off
= elf_ia64_vms_tdata (abfd
)->fixups_off
;
2864 elf_ia64_vms_tdata (abfd
)->fixups_off
= fixups_off
;
2866 if (!_bfd_elf_add_dynamic_entry
2867 (info
, DT_IA_64_VMS_FIXUP_RELA_CNT
,
2868 fixups_shl_off
/ sizeof (Elf64_External_VMS_IMAGE_FIXUP
)))
2870 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_FIXUP_RELA_OFF
,
2873 fixups_off
+= fixups_shl_off
;
2877 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWINDSZ
, 0))
2879 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_CODSEG
, 0))
2881 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_INFOSEG
, 0))
2883 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_OFFSET
, 0))
2885 if (!_bfd_elf_add_dynamic_entry (info
, DT_IA_64_VMS_UNWIND_SEG
, 0))
2888 if (!_bfd_elf_add_dynamic_entry (info
, DT_NULL
, 0xdead))
2891 /* Fix the strtab entries. */
2892 bed
= get_elf_backend_data (hash_table
->dynobj
);
2894 if (dynstrsec
->size
> 1)
2895 dynstrsec
->contents
[0] = 0;
2897 dynstrsec
->size
= 0;
2899 /* Note: one 'spare' (ie DT_NULL) entry is added by
2900 bfd_elf_size_dynsym_hash_dynstr. */
2901 dyn
.d_tag
= DT_IA_64_VMS_STRTAB_OFFSET
;
2902 dyn
.d_un
.d_val
= dynsec
->size
/* + sizeof (Elf64_External_Dyn) */;
2903 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
,
2904 dynsec
->contents
+ strdyn_off
);
2906 dyn
.d_tag
= DT_STRSZ
;
2907 dyn
.d_un
.d_val
= dynstrsec
->size
;
2908 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
,
2909 dynsec
->contents
+ strdyn_off
+ bed
->s
->sizeof_dyn
);
2911 elf_ia64_vms_tdata (output_bfd
)->needed_count
= shl_num
;
2914 if (!create_ia64_vms_notes (output_bfd
, info
, time_hi
, time_lo
))
2918 /* ??? Perhaps force __gp local. */
2924 elf64_ia64_install_fixup (bfd
*output_bfd
,
2925 struct elf64_ia64_link_hash_table
*ia64_info
,
2926 struct elf_link_hash_entry
*h
,
2927 unsigned int type
, asection
*sec
, bfd_vma offset
,
2931 Elf64_External_VMS_IMAGE_FIXUP
*fixup
;
2932 struct elf64_ia64_link_hash_entry
*h_ia64
;
2934 Elf_Internal_Phdr
*phdr
;
2936 if (h
== NULL
|| !h
->def_dynamic
)
2939 h_ia64
= (struct elf64_ia64_link_hash_entry
*) h
;
2940 fixoff
= elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
;
2941 elf_ia64_vms_tdata (h_ia64
->shl
)->fixups_off
+=
2942 sizeof (Elf64_External_VMS_IMAGE_FIXUP
);
2943 relsec
= ia64_info
->fixups_sec
;
2945 fixup
= (Elf64_External_VMS_IMAGE_FIXUP
*)(relsec
->contents
+ fixoff
);
2946 offset
+= sec
->output_section
->vma
+ sec
->output_offset
;
2948 /* FIXME: this is slow. We should cache the last one used, or create a
2950 phdr
= _bfd_elf_find_segment_containing_section
2951 (output_bfd
, sec
->output_section
);
2952 BFD_ASSERT (phdr
!= NULL
);
2954 bfd_putl64 (offset
- phdr
->p_vaddr
, fixup
->fixup_offset
);
2955 bfd_putl32 (type
, fixup
->type
);
2956 bfd_putl32 (phdr
- elf_tdata (output_bfd
)->phdr
, fixup
->fixup_seg
);
2957 bfd_putl64 (addend
, fixup
->addend
);
2958 bfd_putl32 (h
->root
.u
.def
.value
, fixup
->symvec_index
);
2959 bfd_putl32 (2, fixup
->data_type
);
2962 /* Store an entry for target address TARGET_ADDR in the linkage table
2963 and return the gp-relative address of the linkage table entry. */
2966 set_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
2967 struct elf64_ia64_dyn_sym_info
*dyn_i
,
2968 bfd_vma addend
, bfd_vma value
, unsigned int dyn_r_type
)
2970 struct elf64_ia64_link_hash_table
*ia64_info
;
2975 ia64_info
= elf64_ia64_hash_table (info
);
2976 if (ia64_info
== NULL
)
2979 got_sec
= ia64_info
->root
.sgot
;
2983 case R_IA64_TPREL64LSB
:
2984 case R_IA64_DTPMOD64LSB
:
2985 case R_IA64_DTPREL32LSB
:
2986 case R_IA64_DTPREL64LSB
:
2990 done
= dyn_i
->got_done
;
2991 dyn_i
->got_done
= TRUE
;
2992 got_offset
= dyn_i
->got_offset
;
2996 BFD_ASSERT ((got_offset
& 7) == 0);
3000 /* Store the target address in the linkage table entry. */
3001 bfd_put_64 (abfd
, value
, got_sec
->contents
+ got_offset
);
3003 /* Install a dynamic relocation if needed. */
3004 if (((bfd_link_pic (info
)
3006 || ELF_ST_VISIBILITY (dyn_i
->h
->other
) == STV_DEFAULT
3007 || dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
))
3008 || elf64_ia64_dynamic_symbol_p (dyn_i
->h
))
3009 && (!dyn_i
->want_ltoff_fptr
3010 || !bfd_link_pie (info
)
3012 || dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
))
3014 if (!dyn_i
->h
|| !dyn_i
->h
->def_dynamic
)
3016 dyn_r_type
= R_IA64_REL64LSB
;
3020 /* VMS: install a FIX32 or FIX64. */
3023 case R_IA64_DIR32LSB
:
3024 case R_IA64_FPTR32LSB
:
3025 dyn_r_type
= R_IA64_VMS_FIX32
;
3027 case R_IA64_DIR64LSB
:
3028 case R_IA64_FPTR64LSB
:
3029 dyn_r_type
= R_IA64_VMS_FIX64
;
3035 elf64_ia64_install_fixup
3036 (info
->output_bfd
, ia64_info
, dyn_i
->h
,
3037 dyn_r_type
, got_sec
, got_offset
, addend
);
3041 /* Return the address of the linkage table entry. */
3042 value
= (got_sec
->output_section
->vma
3043 + got_sec
->output_offset
3049 /* Fill in a function descriptor consisting of the function's code
3050 address and its global pointer. Return the descriptor's address. */
3053 set_fptr_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3054 struct elf64_ia64_dyn_sym_info
*dyn_i
,
3057 struct elf64_ia64_link_hash_table
*ia64_info
;
3060 ia64_info
= elf64_ia64_hash_table (info
);
3061 if (ia64_info
== NULL
)
3064 fptr_sec
= ia64_info
->fptr_sec
;
3066 if (!dyn_i
->fptr_done
)
3068 dyn_i
->fptr_done
= 1;
3070 /* Fill in the function descriptor. */
3071 bfd_put_64 (abfd
, value
, fptr_sec
->contents
+ dyn_i
->fptr_offset
);
3072 bfd_put_64 (abfd
, _bfd_get_gp_value (abfd
),
3073 fptr_sec
->contents
+ dyn_i
->fptr_offset
+ 8);
3076 /* Return the descriptor's address. */
3077 value
= (fptr_sec
->output_section
->vma
3078 + fptr_sec
->output_offset
3079 + dyn_i
->fptr_offset
);
3084 /* Fill in a PLTOFF entry consisting of the function's code address
3085 and its global pointer. Return the descriptor's address. */
3088 set_pltoff_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3089 struct elf64_ia64_dyn_sym_info
*dyn_i
,
3090 bfd_vma value
, bfd_boolean is_plt
)
3092 struct elf64_ia64_link_hash_table
*ia64_info
;
3093 asection
*pltoff_sec
;
3095 ia64_info
= elf64_ia64_hash_table (info
);
3096 if (ia64_info
== NULL
)
3099 pltoff_sec
= ia64_info
->pltoff_sec
;
3101 /* Don't do anything if this symbol uses a real PLT entry. In
3102 that case, we'll fill this in during finish_dynamic_symbol. */
3103 if ((! dyn_i
->want_plt
|| is_plt
)
3104 && !dyn_i
->pltoff_done
)
3106 bfd_vma gp
= _bfd_get_gp_value (abfd
);
3108 /* Fill in the function descriptor. */
3109 bfd_put_64 (abfd
, value
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
);
3110 bfd_put_64 (abfd
, gp
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
+ 8);
3112 /* Install dynamic relocations if needed. */
3114 && bfd_link_pic (info
)
3116 || ELF_ST_VISIBILITY (dyn_i
->h
->other
) == STV_DEFAULT
3117 || dyn_i
->h
->root
.type
!= bfd_link_hash_undefweak
))
3123 dyn_i
->pltoff_done
= 1;
3126 /* Return the descriptor's address. */
3127 value
= (pltoff_sec
->output_section
->vma
3128 + pltoff_sec
->output_offset
3129 + dyn_i
->pltoff_offset
);
3134 /* Called through qsort to sort the .IA_64.unwind section during a
3135 non-relocatable link. Set elf64_ia64_unwind_entry_compare_bfd
3136 to the output bfd so we can do proper endianness frobbing. */
3138 static bfd
*elf64_ia64_unwind_entry_compare_bfd
;
3141 elf64_ia64_unwind_entry_compare (const void * a
, const void * b
)
3145 av
= bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd
, a
);
3146 bv
= bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd
, b
);
3148 return (av
< bv
? -1 : av
> bv
? 1 : 0);
3151 /* Make sure we've got ourselves a nice fat __gp value. */
3153 elf64_ia64_choose_gp (bfd
*abfd
, struct bfd_link_info
*info
, bfd_boolean final
)
3155 bfd_vma min_vma
= (bfd_vma
) -1, max_vma
= 0;
3156 bfd_vma min_short_vma
= min_vma
, max_short_vma
= 0;
3157 struct elf_link_hash_entry
*gp
;
3160 struct elf64_ia64_link_hash_table
*ia64_info
;
3162 ia64_info
= elf64_ia64_hash_table (info
);
3163 if (ia64_info
== NULL
)
3166 /* Find the min and max vma of all sections marked short. Also collect
3167 min and max vma of any type, for use in selecting a nice gp. */
3168 for (os
= abfd
->sections
; os
; os
= os
->next
)
3172 if ((os
->flags
& SEC_ALLOC
) == 0)
3176 /* When this function is called from elfNN_ia64_final_link
3177 the correct value to use is os->size. When called from
3178 elfNN_ia64_relax_section we are in the middle of section
3179 sizing; some sections will already have os->size set, others
3180 will have os->size zero and os->rawsize the previous size. */
3181 hi
= os
->vma
+ (!final
&& os
->rawsize
? os
->rawsize
: os
->size
);
3189 if (os
->flags
& SEC_SMALL_DATA
)
3191 if (min_short_vma
> lo
)
3193 if (max_short_vma
< hi
)
3198 if (ia64_info
->min_short_sec
)
3201 > (ia64_info
->min_short_sec
->vma
3202 + ia64_info
->min_short_offset
))
3203 min_short_vma
= (ia64_info
->min_short_sec
->vma
3204 + ia64_info
->min_short_offset
);
3206 < (ia64_info
->max_short_sec
->vma
3207 + ia64_info
->max_short_offset
))
3208 max_short_vma
= (ia64_info
->max_short_sec
->vma
3209 + ia64_info
->max_short_offset
);
3212 /* See if the user wants to force a value. */
3213 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
3217 && (gp
->root
.type
== bfd_link_hash_defined
3218 || gp
->root
.type
== bfd_link_hash_defweak
))
3220 asection
*gp_sec
= gp
->root
.u
.def
.section
;
3221 gp_val
= (gp
->root
.u
.def
.value
3222 + gp_sec
->output_section
->vma
3223 + gp_sec
->output_offset
);
3227 /* Pick a sensible value. */
3229 if (ia64_info
->min_short_sec
)
3231 bfd_vma short_range
= max_short_vma
- min_short_vma
;
3233 /* If min_short_sec is set, pick one in the middle bewteen
3234 min_short_vma and max_short_vma. */
3235 if (short_range
>= 0x400000)
3237 gp_val
= min_short_vma
+ short_range
/ 2;
3241 asection
*got_sec
= ia64_info
->root
.sgot
;
3243 /* Start with just the address of the .got. */
3245 gp_val
= got_sec
->output_section
->vma
;
3246 else if (max_short_vma
!= 0)
3247 gp_val
= min_short_vma
;
3248 else if (max_vma
- min_vma
< 0x200000)
3251 gp_val
= max_vma
- 0x200000 + 8;
3254 /* If it is possible to address the entire image, but we
3255 don't with the choice above, adjust. */
3256 if (max_vma
- min_vma
< 0x400000
3257 && (max_vma
- gp_val
>= 0x200000
3258 || gp_val
- min_vma
> 0x200000))
3259 gp_val
= min_vma
+ 0x200000;
3260 else if (max_short_vma
!= 0)
3262 /* If we don't cover all the short data, adjust. */
3263 if (max_short_vma
- gp_val
>= 0x200000)
3264 gp_val
= min_short_vma
+ 0x200000;
3266 /* If we're addressing stuff past the end, adjust back. */
3267 if (gp_val
> max_vma
)
3268 gp_val
= max_vma
- 0x200000 + 8;
3272 /* Validate whether all SHF_IA_64_SHORT sections are within
3273 range of the chosen GP. */
3275 if (max_short_vma
!= 0)
3277 if (max_short_vma
- min_short_vma
>= 0x400000)
3281 /* xgettext:c-format */
3282 (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
3283 bfd_get_filename (abfd
),
3284 (unsigned long) (max_short_vma
- min_short_vma
));
3287 else if ((gp_val
> min_short_vma
3288 && gp_val
- min_short_vma
> 0x200000)
3289 || (gp_val
< max_short_vma
3290 && max_short_vma
- gp_val
>= 0x200000))
3293 (_("%s: __gp does not cover short data segment"),
3294 bfd_get_filename (abfd
));
3299 _bfd_set_gp_value (abfd
, gp_val
);
3305 elf64_ia64_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
3307 struct elf64_ia64_link_hash_table
*ia64_info
;
3308 asection
*unwind_output_sec
;
3310 ia64_info
= elf64_ia64_hash_table (info
);
3311 if (ia64_info
== NULL
)
3314 /* Make sure we've got ourselves a nice fat __gp value. */
3315 if (!bfd_link_relocatable (info
))
3318 struct elf_link_hash_entry
*gp
;
3320 /* We assume after gp is set, section size will only decrease. We
3321 need to adjust gp for it. */
3322 _bfd_set_gp_value (abfd
, 0);
3323 if (! elf64_ia64_choose_gp (abfd
, info
, TRUE
))
3325 gp_val
= _bfd_get_gp_value (abfd
);
3327 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", FALSE
,
3331 gp
->root
.type
= bfd_link_hash_defined
;
3332 gp
->root
.u
.def
.value
= gp_val
;
3333 gp
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3337 /* If we're producing a final executable, we need to sort the contents
3338 of the .IA_64.unwind section. Force this section to be relocated
3339 into memory rather than written immediately to the output file. */
3340 unwind_output_sec
= NULL
;
3341 if (!bfd_link_relocatable (info
))
3343 asection
*s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
3346 unwind_output_sec
= s
->output_section
;
3347 unwind_output_sec
->contents
3348 = bfd_malloc (unwind_output_sec
->size
);
3349 if (unwind_output_sec
->contents
== NULL
)
3354 /* Invoke the regular ELF backend linker to do all the work. */
3355 if (!bfd_elf_final_link (abfd
, info
))
3358 if (unwind_output_sec
)
3360 elf64_ia64_unwind_entry_compare_bfd
= abfd
;
3361 qsort (unwind_output_sec
->contents
,
3362 (size_t) (unwind_output_sec
->size
/ 24),
3364 elf64_ia64_unwind_entry_compare
);
3366 if (! bfd_set_section_contents (abfd
, unwind_output_sec
,
3367 unwind_output_sec
->contents
, (bfd_vma
) 0,
3368 unwind_output_sec
->size
))
3376 elf64_ia64_relocate_section (bfd
*output_bfd
,
3377 struct bfd_link_info
*info
,
3379 asection
*input_section
,
3381 Elf_Internal_Rela
*relocs
,
3382 Elf_Internal_Sym
*local_syms
,
3383 asection
**local_sections
)
3385 struct elf64_ia64_link_hash_table
*ia64_info
;
3386 Elf_Internal_Shdr
*symtab_hdr
;
3387 Elf_Internal_Rela
*rel
;
3388 Elf_Internal_Rela
*relend
;
3389 bfd_boolean ret_val
= TRUE
; /* for non-fatal errors */
3392 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3393 ia64_info
= elf64_ia64_hash_table (info
);
3394 if (ia64_info
== NULL
)
3397 /* Infect various flags from the input section to the output section. */
3398 if (bfd_link_relocatable (info
))
3402 flags
= elf_section_data(input_section
)->this_hdr
.sh_flags
;
3403 flags
&= SHF_IA_64_NORECOV
;
3405 elf_section_data(input_section
->output_section
)
3406 ->this_hdr
.sh_flags
|= flags
;
3409 gp_val
= _bfd_get_gp_value (output_bfd
);
3412 relend
= relocs
+ input_section
->reloc_count
;
3413 for (; rel
< relend
; ++rel
)
3415 struct elf_link_hash_entry
*h
;
3416 struct elf64_ia64_dyn_sym_info
*dyn_i
;
3417 bfd_reloc_status_type r
;
3418 reloc_howto_type
*howto
;
3419 unsigned long r_symndx
;
3420 Elf_Internal_Sym
*sym
;
3421 unsigned int r_type
;
3425 bfd_boolean dynamic_symbol_p
;
3426 bfd_boolean undef_weak_ref
;
3428 r_type
= ELF64_R_TYPE (rel
->r_info
);
3429 if (r_type
> R_IA64_MAX_RELOC_CODE
)
3432 /* xgettext:c-format */
3433 (_("%B: unknown relocation type %d"),
3434 input_bfd
, (int) r_type
);
3435 bfd_set_error (bfd_error_bad_value
);
3440 howto
= ia64_elf_lookup_howto (r_type
);
3441 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3445 undef_weak_ref
= FALSE
;
3447 if (r_symndx
< symtab_hdr
->sh_info
)
3449 /* Reloc against local symbol. */
3451 sym
= local_syms
+ r_symndx
;
3452 sym_sec
= local_sections
[r_symndx
];
3454 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &msec
, rel
);
3455 if (!bfd_link_relocatable (info
)
3456 && (sym_sec
->flags
& SEC_MERGE
) != 0
3457 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
3458 && sym_sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
3460 struct elf64_ia64_local_hash_entry
*loc_h
;
3462 loc_h
= get_local_sym_hash (ia64_info
, input_bfd
, rel
, FALSE
);
3463 if (loc_h
&& ! loc_h
->sec_merge_done
)
3465 struct elf64_ia64_dyn_sym_info
*dynent
;
3468 for (count
= loc_h
->count
, dynent
= loc_h
->info
;
3474 _bfd_merged_section_offset (output_bfd
, &msec
,
3475 elf_section_data (msec
)->
3479 dynent
->addend
-= sym
->st_value
;
3480 dynent
->addend
+= msec
->output_section
->vma
3481 + msec
->output_offset
3482 - sym_sec
->output_section
->vma
3483 - sym_sec
->output_offset
;
3486 /* We may have introduced duplicated entries. We need
3487 to remove them properly. */
3488 count
= sort_dyn_sym_info (loc_h
->info
, loc_h
->count
);
3489 if (count
!= loc_h
->count
)
3491 loc_h
->count
= count
;
3492 loc_h
->sorted_count
= count
;
3495 loc_h
->sec_merge_done
= 1;
3501 bfd_boolean unresolved_reloc
;
3502 bfd_boolean warned
, ignored
;
3503 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
3505 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
3506 r_symndx
, symtab_hdr
, sym_hashes
,
3508 unresolved_reloc
, warned
, ignored
);
3510 if (h
->root
.type
== bfd_link_hash_undefweak
)
3511 undef_weak_ref
= TRUE
;
3516 /* For relocs against symbols from removed linkonce sections,
3517 or sections discarded by a linker script, we just want the
3518 section contents zeroed. Avoid any special processing. */
3519 if (sym_sec
!= NULL
&& discarded_section (sym_sec
))
3520 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
3521 rel
, 1, relend
, howto
, 0, contents
);
3523 if (bfd_link_relocatable (info
))
3526 hit_addr
= contents
+ rel
->r_offset
;
3527 value
+= rel
->r_addend
;
3528 dynamic_symbol_p
= elf64_ia64_dynamic_symbol_p (h
);
3539 case R_IA64_DIR32MSB
:
3540 case R_IA64_DIR32LSB
:
3541 case R_IA64_DIR64MSB
:
3542 case R_IA64_DIR64LSB
:
3543 /* Install a dynamic relocation for this reloc. */
3544 if ((dynamic_symbol_p
|| bfd_link_pic (info
))
3546 && (input_section
->flags
& SEC_ALLOC
) != 0)
3548 unsigned int dyn_r_type
;
3556 /* ??? People shouldn't be doing non-pic code in
3557 shared libraries nor dynamic executables. */
3559 /* xgettext:c-format */
3560 (_("%B: non-pic code with imm relocation against dynamic symbol `%s'"),
3562 h
? h
->root
.root
.string
3563 : bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3572 /* If we don't need dynamic symbol lookup, find a
3573 matching RELATIVE relocation. */
3574 dyn_r_type
= r_type
;
3575 if (dynamic_symbol_p
)
3577 addend
= rel
->r_addend
;
3585 /* VMS: install a FIX64. */
3588 case R_IA64_DIR32LSB
:
3589 dyn_r_type
= R_IA64_VMS_FIX32
;
3591 case R_IA64_DIR64LSB
:
3592 dyn_r_type
= R_IA64_VMS_FIX64
;
3598 elf64_ia64_install_fixup
3599 (output_bfd
, ia64_info
, h
,
3600 dyn_r_type
, input_section
, rel
->r_offset
, addend
);
3606 case R_IA64_LTV32MSB
:
3607 case R_IA64_LTV32LSB
:
3608 case R_IA64_LTV64MSB
:
3609 case R_IA64_LTV64LSB
:
3610 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3613 case R_IA64_GPREL22
:
3614 case R_IA64_GPREL64I
:
3615 case R_IA64_GPREL32MSB
:
3616 case R_IA64_GPREL32LSB
:
3617 case R_IA64_GPREL64MSB
:
3618 case R_IA64_GPREL64LSB
:
3619 if (dynamic_symbol_p
)
3622 /* xgettext:c-format */
3623 (_("%B: @gprel relocation against dynamic symbol %s"),
3625 h
? h
->root
.root
.string
3626 : bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3632 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3635 case R_IA64_LTOFF22
:
3636 case R_IA64_LTOFF22X
:
3637 case R_IA64_LTOFF64I
:
3638 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3639 value
= set_got_entry (input_bfd
, info
, dyn_i
,
3640 rel
->r_addend
, value
, R_IA64_DIR64LSB
);
3642 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3645 case R_IA64_PLTOFF22
:
3646 case R_IA64_PLTOFF64I
:
3647 case R_IA64_PLTOFF64MSB
:
3648 case R_IA64_PLTOFF64LSB
:
3649 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3650 value
= set_pltoff_entry (output_bfd
, info
, dyn_i
, value
, FALSE
);
3652 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3655 case R_IA64_FPTR64I
:
3656 case R_IA64_FPTR32MSB
:
3657 case R_IA64_FPTR32LSB
:
3658 case R_IA64_FPTR64MSB
:
3659 case R_IA64_FPTR64LSB
:
3660 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3661 if (dyn_i
->want_fptr
)
3663 if (!undef_weak_ref
)
3664 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3666 if (!dyn_i
->want_fptr
|| bfd_link_pie (info
))
3668 /* Otherwise, we expect the dynamic linker to create
3671 if (dyn_i
->want_fptr
)
3673 if (r_type
== R_IA64_FPTR64I
)
3675 /* We can't represent this without a dynamic symbol.
3676 Adjust the relocation to be against an output
3677 section symbol, which are always present in the
3678 dynamic symbol table. */
3679 /* ??? People shouldn't be doing non-pic code in
3680 shared libraries. Hork. */
3682 (_("%B: linking non-pic code in a position independent executable"),
3694 elf64_ia64_install_fixup
3695 (output_bfd
, ia64_info
, h
, R_IA64_VMS_FIXFD
,
3696 input_section
, rel
->r_offset
, 0);
3701 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3704 case R_IA64_LTOFF_FPTR22
:
3705 case R_IA64_LTOFF_FPTR64I
:
3706 case R_IA64_LTOFF_FPTR32MSB
:
3707 case R_IA64_LTOFF_FPTR32LSB
:
3708 case R_IA64_LTOFF_FPTR64MSB
:
3709 case R_IA64_LTOFF_FPTR64LSB
:
3710 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, FALSE
);
3711 if (dyn_i
->want_fptr
)
3713 BFD_ASSERT (h
== NULL
|| !h
->def_dynamic
);
3714 if (!undef_weak_ref
)
3715 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3720 value
= set_got_entry (output_bfd
, info
, dyn_i
,
3721 rel
->r_addend
, value
, R_IA64_FPTR64LSB
);
3723 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3726 case R_IA64_PCREL32MSB
:
3727 case R_IA64_PCREL32LSB
:
3728 case R_IA64_PCREL64MSB
:
3729 case R_IA64_PCREL64LSB
:
3730 /* Install a dynamic relocation for this reloc. */
3731 if (dynamic_symbol_p
&& r_symndx
!= 0)
3733 /* VMS: doesn't exist ??? */
3738 case R_IA64_PCREL21B
:
3739 case R_IA64_PCREL60B
:
3740 /* We should have created a PLT entry for any dynamic symbol. */
3743 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, FALSE
);
3745 if (dyn_i
&& dyn_i
->want_plt2
)
3747 /* Should have caught this earlier. */
3748 BFD_ASSERT (rel
->r_addend
== 0);
3750 value
= (ia64_info
->root
.splt
->output_section
->vma
3751 + ia64_info
->root
.splt
->output_offset
3752 + dyn_i
->plt2_offset
);
3756 /* Since there's no PLT entry, Validate that this is
3758 BFD_ASSERT (undef_weak_ref
|| sym_sec
->output_section
!= NULL
);
3760 /* If the symbol is undef_weak, we shouldn't be trying
3761 to call it. There's every chance that we'd wind up
3762 with an out-of-range fixup here. Don't bother setting
3763 any value at all. */
3769 case R_IA64_PCREL21BI
:
3770 case R_IA64_PCREL21F
:
3771 case R_IA64_PCREL21M
:
3772 case R_IA64_PCREL22
:
3773 case R_IA64_PCREL64I
:
3774 /* The PCREL21BI reloc is specifically not intended for use with
3775 dynamic relocs. PCREL21F and PCREL21M are used for speculation
3776 fixup code, and thus probably ought not be dynamic. The
3777 PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */
3778 if (dynamic_symbol_p
)
3782 if (r_type
== R_IA64_PCREL21BI
)
3783 /* xgettext:c-format */
3784 msg
= _("%B: @internal branch to dynamic symbol %s");
3785 else if (r_type
== R_IA64_PCREL21F
|| r_type
== R_IA64_PCREL21M
)
3786 /* xgettext:c-format */
3787 msg
= _("%B: speculation fixup to dynamic symbol %s");
3789 /* xgettext:c-format */
3790 msg
= _("%B: @pcrel relocation against dynamic symbol %s");
3791 _bfd_error_handler (msg
, input_bfd
,
3792 h
? h
->root
.root
.string
3793 : bfd_elf_sym_name (input_bfd
,
3803 /* Make pc-relative. */
3804 value
-= (input_section
->output_section
->vma
3805 + input_section
->output_offset
3806 + rel
->r_offset
) & ~ (bfd_vma
) 0x3;
3807 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3810 case R_IA64_SEGREL32MSB
:
3811 case R_IA64_SEGREL32LSB
:
3812 case R_IA64_SEGREL64MSB
:
3813 case R_IA64_SEGREL64LSB
:
3815 /* Find the segment that contains the output_section. */
3816 Elf_Internal_Phdr
*p
= _bfd_elf_find_segment_containing_section
3817 (output_bfd
, sym_sec
->output_section
);
3821 r
= bfd_reloc_notsupported
;
3825 /* The VMA of the segment is the vaddr of the associated
3827 if (value
> p
->p_vaddr
)
3828 value
-= p
->p_vaddr
;
3831 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3836 case R_IA64_SECREL32MSB
:
3837 case R_IA64_SECREL32LSB
:
3838 case R_IA64_SECREL64MSB
:
3839 case R_IA64_SECREL64LSB
:
3840 /* Make output-section relative to section where the symbol
3841 is defined. PR 475 */
3843 value
-= sym_sec
->output_section
->vma
;
3844 r
= ia64_elf_install_value (hit_addr
, value
, r_type
);
3847 case R_IA64_IPLTMSB
:
3848 case R_IA64_IPLTLSB
:
3849 /* Install a dynamic relocation for this reloc. */
3850 if ((dynamic_symbol_p
|| bfd_link_pic (info
))
3851 && (input_section
->flags
& SEC_ALLOC
) != 0)
3857 if (r_type
== R_IA64_IPLTMSB
)
3858 r_type
= R_IA64_DIR64MSB
;
3860 r_type
= R_IA64_DIR64LSB
;
3861 ia64_elf_install_value (hit_addr
, value
, r_type
);
3862 r
= ia64_elf_install_value (hit_addr
+ 8, gp_val
, r_type
);
3865 case R_IA64_TPREL14
:
3866 case R_IA64_TPREL22
:
3867 case R_IA64_TPREL64I
:
3868 r
= bfd_reloc_notsupported
;
3871 case R_IA64_DTPREL14
:
3872 case R_IA64_DTPREL22
:
3873 case R_IA64_DTPREL64I
:
3874 case R_IA64_DTPREL32LSB
:
3875 case R_IA64_DTPREL32MSB
:
3876 case R_IA64_DTPREL64LSB
:
3877 case R_IA64_DTPREL64MSB
:
3878 r
= bfd_reloc_notsupported
;
3881 case R_IA64_LTOFF_TPREL22
:
3882 case R_IA64_LTOFF_DTPMOD22
:
3883 case R_IA64_LTOFF_DTPREL22
:
3884 r
= bfd_reloc_notsupported
;
3888 r
= bfd_reloc_notsupported
;
3897 case bfd_reloc_undefined
:
3898 /* This can happen for global table relative relocs if
3899 __gp is undefined. This is a panic situation so we
3900 don't try to continue. */
3901 (*info
->callbacks
->undefined_symbol
)
3902 (info
, "__gp", input_bfd
, input_section
, rel
->r_offset
, 1);
3905 case bfd_reloc_notsupported
:
3910 name
= h
->root
.root
.string
;
3912 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3914 (*info
->callbacks
->warning
) (info
, _("unsupported reloc"),
3916 input_section
, rel
->r_offset
);
3921 case bfd_reloc_dangerous
:
3922 case bfd_reloc_outofrange
:
3923 case bfd_reloc_overflow
:
3929 name
= h
->root
.root
.string
;
3931 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
,
3936 case R_IA64_TPREL14
:
3937 case R_IA64_TPREL22
:
3938 case R_IA64_TPREL64I
:
3939 case R_IA64_DTPREL14
:
3940 case R_IA64_DTPREL22
:
3941 case R_IA64_DTPREL64I
:
3942 case R_IA64_DTPREL32LSB
:
3943 case R_IA64_DTPREL32MSB
:
3944 case R_IA64_DTPREL64LSB
:
3945 case R_IA64_DTPREL64MSB
:
3946 case R_IA64_LTOFF_TPREL22
:
3947 case R_IA64_LTOFF_DTPMOD22
:
3948 case R_IA64_LTOFF_DTPREL22
:
3950 /* xgettext:c-format */
3951 (_("%B: missing TLS section for relocation %s against `%s'"
3952 " at 0x%lx in section `%A'."),
3953 input_bfd
, howto
->name
, name
,
3954 rel
->r_offset
, input_section
);
3957 case R_IA64_PCREL21B
:
3958 case R_IA64_PCREL21BI
:
3959 case R_IA64_PCREL21M
:
3960 case R_IA64_PCREL21F
:
3961 if (is_elf_hash_table (info
->hash
))
3963 /* Relaxtion is always performed for ELF output.
3964 Overflow failures for those relocations mean
3965 that the section is too big to relax. */
3967 /* xgettext:c-format */
3968 (_("%B: Can't relax br (%s) to `%s' at 0x%lx in section"
3969 " `%A' with size 0x%lx (> 0x1000000)."),
3970 input_bfd
, howto
->name
, name
, rel
->r_offset
,
3971 input_section
, input_section
->size
);
3976 (*info
->callbacks
->reloc_overflow
) (info
,
3997 elf64_ia64_finish_dynamic_symbol (bfd
*output_bfd
,
3998 struct bfd_link_info
*info
,
3999 struct elf_link_hash_entry
*h
,
4000 Elf_Internal_Sym
*sym
)
4002 struct elf64_ia64_link_hash_table
*ia64_info
;
4003 struct elf64_ia64_dyn_sym_info
*dyn_i
;
4005 ia64_info
= elf64_ia64_hash_table (info
);
4006 if (ia64_info
== NULL
)
4009 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, FALSE
);
4011 /* Fill in the PLT data, if required. */
4012 if (dyn_i
&& dyn_i
->want_plt
)
4016 bfd_vma plt_addr
, pltoff_addr
, gp_val
;
4018 gp_val
= _bfd_get_gp_value (output_bfd
);
4020 plt_sec
= ia64_info
->root
.splt
;
4021 plt_addr
= 0; /* Not used as overriden by FIXUPs. */
4022 pltoff_addr
= set_pltoff_entry (output_bfd
, info
, dyn_i
, plt_addr
, TRUE
);
4024 /* Initialize the FULL PLT entry, if needed. */
4025 if (dyn_i
->want_plt2
)
4027 loc
= plt_sec
->contents
+ dyn_i
->plt2_offset
;
4029 memcpy (loc
, plt_full_entry
, PLT_FULL_ENTRY_SIZE
);
4030 ia64_elf_install_value (loc
, pltoff_addr
- gp_val
, R_IA64_IMM22
);
4032 /* Mark the symbol as undefined, rather than as defined in the
4033 plt section. Leave the value alone. */
4034 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4035 first place. But perhaps elflink.c did some for us. */
4036 if (!h
->def_regular
)
4037 sym
->st_shndx
= SHN_UNDEF
;
4041 elf64_ia64_install_fixup
4042 (output_bfd
, ia64_info
, h
, R_IA64_VMS_FIXFD
, ia64_info
->pltoff_sec
,
4043 pltoff_addr
- (ia64_info
->pltoff_sec
->output_section
->vma
4044 + ia64_info
->pltoff_sec
->output_offset
), 0);
4047 /* Mark some specially defined symbols as absolute. */
4048 if (h
== ia64_info
->root
.hdynamic
4049 || h
== ia64_info
->root
.hgot
4050 || h
== ia64_info
->root
.hplt
)
4051 sym
->st_shndx
= SHN_ABS
;
4057 elf64_ia64_finish_dynamic_sections (bfd
*abfd
,
4058 struct bfd_link_info
*info
)
4060 struct elf64_ia64_link_hash_table
*ia64_info
;
4063 ia64_info
= elf64_ia64_hash_table (info
);
4064 if (ia64_info
== NULL
)
4067 dynobj
= ia64_info
->root
.dynobj
;
4069 if (elf_hash_table (info
)->dynamic_sections_created
)
4071 Elf64_External_Dyn
*dyncon
, *dynconend
;
4073 asection
*unwind_sec
;
4075 unsigned int gp_seg
;
4077 Elf_Internal_Phdr
*phdr
;
4078 Elf_Internal_Phdr
*base_phdr
;
4079 unsigned int unwind_seg
= 0;
4080 unsigned int code_seg
= 0;
4082 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
4083 BFD_ASSERT (sdyn
!= NULL
);
4084 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
4085 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4087 gp_val
= _bfd_get_gp_value (abfd
);
4088 phdr
= _bfd_elf_find_segment_containing_section
4089 (info
->output_bfd
, ia64_info
->pltoff_sec
->output_section
);
4090 BFD_ASSERT (phdr
!= NULL
);
4091 base_phdr
= elf_tdata (info
->output_bfd
)->phdr
;
4092 gp_seg
= phdr
- base_phdr
;
4093 gp_off
= gp_val
- phdr
->p_vaddr
;
4095 unwind_sec
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
4096 if (unwind_sec
!= NULL
)
4100 phdr
= _bfd_elf_find_segment_containing_section (abfd
, unwind_sec
);
4101 BFD_ASSERT (phdr
!= NULL
);
4102 unwind_seg
= phdr
- base_phdr
;
4104 code_sec
= bfd_get_section_by_name (abfd
, "$CODE$");
4105 phdr
= _bfd_elf_find_segment_containing_section (abfd
, code_sec
);
4106 BFD_ASSERT (phdr
!= NULL
);
4107 code_seg
= phdr
- base_phdr
;
4110 for (; dyncon
< dynconend
; dyncon
++)
4112 Elf_Internal_Dyn dyn
;
4114 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4118 case DT_IA_64_VMS_FIXUP_RELA_OFF
:
4120 (ia64_info
->fixups_sec
->output_section
->vma
4121 + ia64_info
->fixups_sec
->output_offset
)
4122 - (sdyn
->output_section
->vma
+ sdyn
->output_offset
);
4125 case DT_IA_64_VMS_PLTGOT_OFFSET
:
4126 dyn
.d_un
.d_val
= gp_off
;
4129 case DT_IA_64_VMS_PLTGOT_SEG
:
4130 dyn
.d_un
.d_val
= gp_seg
;
4133 case DT_IA_64_VMS_UNWINDSZ
:
4134 if (unwind_sec
== NULL
)
4136 dyn
.d_tag
= DT_NULL
;
4137 dyn
.d_un
.d_val
= 0xdead;
4140 dyn
.d_un
.d_val
= unwind_sec
->size
;
4143 case DT_IA_64_VMS_UNWIND_CODSEG
:
4144 dyn
.d_un
.d_val
= code_seg
;
4147 case DT_IA_64_VMS_UNWIND_INFOSEG
:
4148 case DT_IA_64_VMS_UNWIND_SEG
:
4149 dyn
.d_un
.d_val
= unwind_seg
;
4152 case DT_IA_64_VMS_UNWIND_OFFSET
:
4156 /* No need to rewrite the entry. */
4160 bfd_elf64_swap_dyn_out (abfd
, &dyn
, dyncon
);
4164 /* Handle transfer addresses. */
4166 asection
*tfr_sec
= ia64_info
->transfer_sec
;
4167 struct elf64_vms_transfer
*tfr
;
4168 struct elf_link_hash_entry
*tfr3
;
4170 tfr
= (struct elf64_vms_transfer
*)tfr_sec
->contents
;
4171 bfd_putl32 (6 * 8, tfr
->size
);
4172 bfd_putl64 (tfr_sec
->output_section
->vma
4173 + tfr_sec
->output_offset
4174 + 6 * 8, tfr
->tfradr3
);
4176 tfr3
= elf_link_hash_lookup (elf_hash_table (info
), "ELF$TFRADR", FALSE
,
4180 && (tfr3
->root
.type
== bfd_link_hash_defined
4181 || tfr3
->root
.type
== bfd_link_hash_defweak
))
4183 asection
*tfr3_sec
= tfr3
->root
.u
.def
.section
;
4186 tfr3_val
= (tfr3
->root
.u
.def
.value
4187 + tfr3_sec
->output_section
->vma
4188 + tfr3_sec
->output_offset
);
4190 bfd_putl64 (tfr3_val
, tfr
->tfr3_func
);
4191 bfd_putl64 (_bfd_get_gp_value (info
->output_bfd
), tfr
->tfr3_gp
);
4194 /* FIXME: set linker flags,
4195 handle lib$initialize. */
4201 /* ELF file flag handling: */
4203 /* Function to keep IA-64 specific file flags. */
4205 elf64_ia64_set_private_flags (bfd
*abfd
, flagword flags
)
4207 BFD_ASSERT (!elf_flags_init (abfd
)
4208 || elf_elfheader (abfd
)->e_flags
== flags
);
4210 elf_elfheader (abfd
)->e_flags
= flags
;
4211 elf_flags_init (abfd
) = TRUE
;
4215 /* Merge backend specific data from an object file to the output
4216 object file when linking. */
4218 elf64_ia64_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
4220 bfd
*obfd
= info
->output_bfd
;
4223 bfd_boolean ok
= TRUE
;
4225 /* Don't even pretend to support mixed-format linking. */
4226 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4227 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4230 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4231 out_flags
= elf_elfheader (obfd
)->e_flags
;
4233 if (! elf_flags_init (obfd
))
4235 elf_flags_init (obfd
) = TRUE
;
4236 elf_elfheader (obfd
)->e_flags
= in_flags
;
4238 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
4239 && bfd_get_arch_info (obfd
)->the_default
)
4241 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
4242 bfd_get_mach (ibfd
));
4248 /* Check flag compatibility. */
4249 if (in_flags
== out_flags
)
4252 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4253 if (!(in_flags
& EF_IA_64_REDUCEDFP
) && (out_flags
& EF_IA_64_REDUCEDFP
))
4254 elf_elfheader (obfd
)->e_flags
&= ~EF_IA_64_REDUCEDFP
;
4256 if ((in_flags
& EF_IA_64_TRAPNIL
) != (out_flags
& EF_IA_64_TRAPNIL
))
4259 (_("%B: linking trap-on-NULL-dereference with non-trapping files"),
4262 bfd_set_error (bfd_error_bad_value
);
4265 if ((in_flags
& EF_IA_64_BE
) != (out_flags
& EF_IA_64_BE
))
4268 (_("%B: linking big-endian files with little-endian files"),
4271 bfd_set_error (bfd_error_bad_value
);
4274 if ((in_flags
& EF_IA_64_ABI64
) != (out_flags
& EF_IA_64_ABI64
))
4277 (_("%B: linking 64-bit files with 32-bit files"),
4280 bfd_set_error (bfd_error_bad_value
);
4283 if ((in_flags
& EF_IA_64_CONS_GP
) != (out_flags
& EF_IA_64_CONS_GP
))
4286 (_("%B: linking constant-gp files with non-constant-gp files"),
4289 bfd_set_error (bfd_error_bad_value
);
4292 if ((in_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
)
4293 != (out_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4296 (_("%B: linking auto-pic files with non-auto-pic files"),
4299 bfd_set_error (bfd_error_bad_value
);
4307 elf64_ia64_print_private_bfd_data (bfd
*abfd
, void * ptr
)
4309 FILE *file
= (FILE *) ptr
;
4310 flagword flags
= elf_elfheader (abfd
)->e_flags
;
4312 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4314 fprintf (file
, "private flags = %s%s%s%s%s%s%s%s\n",
4315 (flags
& EF_IA_64_TRAPNIL
) ? "TRAPNIL, " : "",
4316 (flags
& EF_IA_64_EXT
) ? "EXT, " : "",
4317 (flags
& EF_IA_64_BE
) ? "BE, " : "LE, ",
4318 (flags
& EF_IA_64_REDUCEDFP
) ? "REDUCEDFP, " : "",
4319 (flags
& EF_IA_64_CONS_GP
) ? "CONS_GP, " : "",
4320 (flags
& EF_IA_64_NOFUNCDESC_CONS_GP
) ? "NOFUNCDESC_CONS_GP, " : "",
4321 (flags
& EF_IA_64_ABSOLUTE
) ? "ABSOLUTE, " : "",
4322 (flags
& EF_IA_64_ABI64
) ? "ABI64" : "ABI32");
4324 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4328 static enum elf_reloc_type_class
4329 elf64_ia64_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4330 const asection
*rel_sec ATTRIBUTE_UNUSED
,
4331 const Elf_Internal_Rela
*rela
)
4333 switch ((int) ELF64_R_TYPE (rela
->r_info
))
4335 case R_IA64_REL32MSB
:
4336 case R_IA64_REL32LSB
:
4337 case R_IA64_REL64MSB
:
4338 case R_IA64_REL64LSB
:
4339 return reloc_class_relative
;
4340 case R_IA64_IPLTMSB
:
4341 case R_IA64_IPLTLSB
:
4342 return reloc_class_plt
;
4344 return reloc_class_copy
;
4346 return reloc_class_normal
;
4350 static const struct bfd_elf_special_section elf64_ia64_special_sections
[] =
4352 { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_IA_64_SHORT
},
4353 { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_IA_64_SHORT
},
4354 { NULL
, 0, 0, 0, 0 }
4358 elf64_ia64_object_p (bfd
*abfd
)
4361 asection
*group
, *unwi
, *unw
;
4364 char *unwi_name
, *unw_name
;
4367 if (abfd
->flags
& DYNAMIC
)
4370 /* Flags for fake group section. */
4371 flags
= (SEC_LINKER_CREATED
| SEC_GROUP
| SEC_LINK_ONCE
4374 /* We add a fake section group for each .gnu.linkonce.t.* section,
4375 which isn't in a section group, and its unwind sections. */
4376 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4378 if (elf_sec_group (sec
) == NULL
4379 && ((sec
->flags
& (SEC_LINK_ONCE
| SEC_CODE
| SEC_GROUP
))
4380 == (SEC_LINK_ONCE
| SEC_CODE
))
4381 && CONST_STRNEQ (sec
->name
, ".gnu.linkonce.t."))
4383 name
= sec
->name
+ 16;
4385 amt
= strlen (name
) + sizeof (".gnu.linkonce.ia64unwi.");
4386 unwi_name
= bfd_alloc (abfd
, amt
);
4390 strcpy (stpcpy (unwi_name
, ".gnu.linkonce.ia64unwi."), name
);
4391 unwi
= bfd_get_section_by_name (abfd
, unwi_name
);
4393 amt
= strlen (name
) + sizeof (".gnu.linkonce.ia64unw.");
4394 unw_name
= bfd_alloc (abfd
, amt
);
4398 strcpy (stpcpy (unw_name
, ".gnu.linkonce.ia64unw."), name
);
4399 unw
= bfd_get_section_by_name (abfd
, unw_name
);
4401 /* We need to create a fake group section for it and its
4403 group
= bfd_make_section_anyway_with_flags (abfd
, name
,
4408 /* Move the fake group section to the beginning. */
4409 bfd_section_list_remove (abfd
, group
);
4410 bfd_section_list_prepend (abfd
, group
);
4412 elf_next_in_group (group
) = sec
;
4414 elf_group_name (sec
) = name
;
4415 elf_next_in_group (sec
) = sec
;
4416 elf_sec_group (sec
) = group
;
4420 elf_group_name (unwi
) = name
;
4421 elf_next_in_group (unwi
) = sec
;
4422 elf_next_in_group (sec
) = unwi
;
4423 elf_sec_group (unwi
) = group
;
4428 elf_group_name (unw
) = name
;
4431 elf_next_in_group (unw
) = elf_next_in_group (unwi
);
4432 elf_next_in_group (unwi
) = unw
;
4436 elf_next_in_group (unw
) = sec
;
4437 elf_next_in_group (sec
) = unw
;
4439 elf_sec_group (unw
) = group
;
4442 /* Fake SHT_GROUP section header. */
4443 elf_section_data (group
)->this_hdr
.bfd_section
= group
;
4444 elf_section_data (group
)->this_hdr
.sh_type
= SHT_GROUP
;
4450 /* Handle an IA-64 specific section when reading an object file. This
4451 is called when bfd_section_from_shdr finds a section with an unknown
4455 elf64_vms_section_from_shdr (bfd
*abfd
,
4456 Elf_Internal_Shdr
*hdr
,
4460 flagword secflags
= 0;
4462 switch (hdr
->sh_type
)
4464 case SHT_IA_64_VMS_TRACE
:
4465 case SHT_IA_64_VMS_DEBUG
:
4466 case SHT_IA_64_VMS_DEBUG_STR
:
4467 secflags
= SEC_DEBUGGING
;
4470 case SHT_IA_64_UNWIND
:
4471 case SHT_IA_64_HP_OPT_ANOT
:
4475 if (strcmp (name
, ELF_STRING_ia64_archext
) != 0)
4483 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
4488 asection
*newsect
= hdr
->bfd_section
;
4490 if (! bfd_set_section_flags
4491 (abfd
, newsect
, bfd_get_section_flags (abfd
, newsect
) | secflags
))
4499 elf64_vms_object_p (bfd
*abfd
)
4501 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4502 Elf_Internal_Phdr
*i_phdr
= elf_tdata (abfd
)->phdr
;
4504 unsigned int num_text
= 0;
4505 unsigned int num_data
= 0;
4506 unsigned int num_rodata
= 0;
4509 if (!elf64_ia64_object_p (abfd
))
4512 /* Many VMS compilers do not generate sections for the corresponding
4513 segment. This is boring as binutils tools won't be able to disassemble
4514 the code. So we simply create all the missing sections. */
4515 for (i
= 0; i
< i_ehdrp
->e_phnum
; i
++, i_phdr
++)
4517 /* Is there a section for this segment? */
4518 bfd_vma base_vma
= i_phdr
->p_vaddr
;
4519 bfd_vma limit_vma
= base_vma
+ i_phdr
->p_filesz
;
4521 if (i_phdr
->p_type
!= PT_LOAD
)
4524 /* We need to cover from base_vms to limit_vma. */
4526 while (base_vma
< limit_vma
)
4528 bfd_vma next_vma
= limit_vma
;
4534 /* Find a section covering [base_vma;limit_vma) */
4535 for (sec
= abfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4537 /* Skip uninteresting sections (either not in memory or
4539 if ((sec
->flags
& (SEC_ALLOC
| SEC_LOAD
)) == 0
4540 || sec
->vma
+ sec
->size
<= base_vma
)
4542 if (sec
->vma
<= base_vma
)
4544 /* This section covers (maybe partially) the beginning
4546 base_vma
= sec
->vma
+ sec
->size
;
4549 if (sec
->vma
< next_vma
)
4551 /* This section partially covers the end of the range.
4552 Used to compute the size of the hole. */
4553 next_vma
= sec
->vma
;
4557 /* No section covering [base_vma; next_vma). Create a fake one. */
4558 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
4559 if (i_phdr
->p_flags
& PF_X
)
4562 if (num_text
++ == 0)
4565 sprintf (name
, ".text$%u", num_text
);
4567 else if ((i_phdr
->p_flags
& (PF_R
| PF_W
)) == PF_R
)
4569 flags
|= SEC_READONLY
;
4570 sprintf (name
, ".rodata$%u", num_rodata
++);
4575 sprintf (name
, ".data$%u", num_data
++);
4578 /* Allocate name. */
4581 size_t name_len
= strlen (name
) + 1;
4582 nname
= bfd_alloc (abfd
, name_len
);
4585 memcpy (nname
, name
, name_len
);
4588 /* Create and fill new section. */
4589 nsec
= bfd_make_section_anyway_with_flags (abfd
, nname
, flags
);
4592 nsec
->vma
= base_vma
;
4593 nsec
->size
= next_vma
- base_vma
;
4594 nsec
->filepos
= i_phdr
->p_offset
+ (base_vma
- i_phdr
->p_vaddr
);
4596 base_vma
= next_vma
;
4603 elf64_vms_post_process_headers (bfd
*abfd
,
4604 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4606 Elf_Internal_Ehdr
*i_ehdrp
= elf_elfheader (abfd
);
4608 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_OPENVMS
;
4609 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 2;
4613 elf64_vms_section_processing (bfd
*abfd ATTRIBUTE_UNUSED
,
4614 Elf_Internal_Shdr
*hdr
)
4616 if (hdr
->bfd_section
!= NULL
)
4618 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
4620 if (strcmp (name
, ".text") == 0)
4621 hdr
->sh_flags
|= SHF_IA_64_VMS_SHARED
;
4622 else if ((strcmp (name
, ".debug") == 0)
4623 || (strcmp (name
, ".debug_abbrev") == 0)
4624 || (strcmp (name
, ".debug_aranges") == 0)
4625 || (strcmp (name
, ".debug_frame") == 0)
4626 || (strcmp (name
, ".debug_info") == 0)
4627 || (strcmp (name
, ".debug_loc") == 0)
4628 || (strcmp (name
, ".debug_macinfo") == 0)
4629 || (strcmp (name
, ".debug_pubnames") == 0)
4630 || (strcmp (name
, ".debug_pubtypes") == 0))
4631 hdr
->sh_type
= SHT_IA_64_VMS_DEBUG
;
4632 else if ((strcmp (name
, ".debug_line") == 0)
4633 || (strcmp (name
, ".debug_ranges") == 0)
4634 || (strcmp (name
, ".trace_info") == 0)
4635 || (strcmp (name
, ".trace_abbrev") == 0)
4636 || (strcmp (name
, ".trace_aranges") == 0))
4637 hdr
->sh_type
= SHT_IA_64_VMS_TRACE
;
4638 else if (strcmp (name
, ".debug_str") == 0)
4639 hdr
->sh_type
= SHT_IA_64_VMS_DEBUG_STR
;
4645 /* The final processing done just before writing out a VMS IA-64 ELF
4649 elf64_vms_final_write_processing (bfd
*abfd
,
4650 bfd_boolean linker ATTRIBUTE_UNUSED
)
4652 Elf_Internal_Shdr
*hdr
;
4654 int unwind_info_sect_idx
= 0;
4656 for (s
= abfd
->sections
; s
; s
= s
->next
)
4658 hdr
= &elf_section_data (s
)->this_hdr
;
4660 if (strcmp (bfd_get_section_name (abfd
, hdr
->bfd_section
),
4661 ".IA_64.unwind_info") == 0)
4662 unwind_info_sect_idx
= elf_section_data (s
)->this_idx
;
4664 switch (hdr
->sh_type
)
4666 case SHT_IA_64_UNWIND
:
4667 /* VMS requires sh_info to point to the unwind info section. */
4668 hdr
->sh_info
= unwind_info_sect_idx
;
4673 if (! elf_flags_init (abfd
))
4675 unsigned long flags
= 0;
4677 if (abfd
->xvec
->byteorder
== BFD_ENDIAN_BIG
)
4678 flags
|= EF_IA_64_BE
;
4679 if (bfd_get_mach (abfd
) == bfd_mach_ia64_elf64
)
4680 flags
|= EF_IA_64_ABI64
;
4682 elf_elfheader (abfd
)->e_flags
= flags
;
4683 elf_flags_init (abfd
) = TRUE
;
4688 elf64_vms_write_shdrs_and_ehdr (bfd
*abfd
)
4690 unsigned char needed_count
[8];
4692 if (!bfd_elf64_write_shdrs_and_ehdr (abfd
))
4695 bfd_putl64 (elf_ia64_vms_tdata (abfd
)->needed_count
, needed_count
);
4697 if (bfd_seek (abfd
, sizeof (Elf64_External_Ehdr
), SEEK_SET
) != 0
4698 || bfd_bwrite (needed_count
, 8, abfd
) != 8)
4705 elf64_vms_close_and_cleanup (bfd
*abfd
)
4707 if (bfd_get_format (abfd
) == bfd_object
)
4711 /* Pad to 8 byte boundary for IPF/VMS. */
4712 isize
= bfd_get_size (abfd
);
4713 if ((isize
& 7) != 0)
4715 int ishort
= 8 - (isize
& 7);
4716 bfd_uint64_t pad
= 0;
4718 bfd_seek (abfd
, isize
, SEEK_SET
);
4719 bfd_bwrite (&pad
, ishort
, abfd
);
4723 return _bfd_elf_close_and_cleanup (abfd
);
4726 /* Add symbols from an ELF object file to the linker hash table. */
4729 elf64_vms_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4731 Elf_Internal_Shdr
*hdr
;
4732 bfd_size_type symcount
;
4733 bfd_size_type extsymcount
;
4734 bfd_size_type extsymoff
;
4735 struct elf_link_hash_entry
**sym_hash
;
4736 bfd_boolean dynamic
;
4737 Elf_Internal_Sym
*isymbuf
= NULL
;
4738 Elf_Internal_Sym
*isym
;
4739 Elf_Internal_Sym
*isymend
;
4740 const struct elf_backend_data
*bed
;
4741 struct elf_link_hash_table
*htab
;
4744 htab
= elf_hash_table (info
);
4745 bed
= get_elf_backend_data (abfd
);
4747 if ((abfd
->flags
& DYNAMIC
) == 0)
4753 /* You can't use -r against a dynamic object. Also, there's no
4754 hope of using a dynamic object which does not exactly match
4755 the format of the output file. */
4756 if (bfd_link_relocatable (info
)
4757 || !is_elf_hash_table (htab
)
4758 || info
->output_bfd
->xvec
!= abfd
->xvec
)
4760 if (bfd_link_relocatable (info
))
4761 bfd_set_error (bfd_error_invalid_operation
);
4763 bfd_set_error (bfd_error_wrong_format
);
4770 /* If we are creating a shared library, create all the dynamic
4771 sections immediately. We need to attach them to something,
4772 so we attach them to this BFD, provided it is the right
4773 format. FIXME: If there are no input BFD's of the same
4774 format as the output, we can't make a shared library. */
4775 if (bfd_link_pic (info
)
4776 && is_elf_hash_table (htab
)
4777 && info
->output_bfd
->xvec
== abfd
->xvec
4778 && !htab
->dynamic_sections_created
)
4780 if (! elf64_ia64_create_dynamic_sections (abfd
, info
))
4784 else if (!is_elf_hash_table (htab
))
4792 /* ld --just-symbols and dynamic objects don't mix very well.
4793 ld shouldn't allow it. */
4794 if ((s
= abfd
->sections
) != NULL
4795 && s
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
4798 /* Be sure there are dynamic sections. */
4799 if (! elf64_ia64_create_dynamic_sections (htab
->dynobj
, info
))
4802 s
= bfd_get_section_by_name (abfd
, ".dynamic");
4805 /* VMS libraries do not have dynamic sections. Create one from
4807 Elf_Internal_Phdr
*phdr
;
4808 unsigned int i
, phnum
;
4810 phdr
= elf_tdata (abfd
)->phdr
;
4813 phnum
= elf_elfheader (abfd
)->e_phnum
;
4814 for (i
= 0; i
< phnum
; phdr
++)
4815 if (phdr
->p_type
== PT_DYNAMIC
)
4817 s
= bfd_make_section (abfd
, ".dynamic");
4820 s
->vma
= phdr
->p_vaddr
;
4821 s
->lma
= phdr
->p_paddr
;
4822 s
->size
= phdr
->p_filesz
;
4823 s
->filepos
= phdr
->p_offset
;
4824 s
->flags
|= SEC_HAS_CONTENTS
;
4825 s
->alignment_power
= bfd_log2 (phdr
->p_align
);
4832 /* Extract IDENT. */
4833 if (!bfd_malloc_and_get_section (abfd
, s
, &dynbuf
))
4840 for (extdyn
= dynbuf
;
4841 extdyn
< dynbuf
+ s
->size
;
4842 extdyn
+= bed
->s
->sizeof_dyn
)
4844 Elf_Internal_Dyn dyn
;
4846 bed
->s
->swap_dyn_in (abfd
, extdyn
, &dyn
);
4847 if (dyn
.d_tag
== DT_IA_64_VMS_IDENT
)
4849 bfd_uint64_t tagv
= dyn
.d_un
.d_val
;
4850 elf_ia64_vms_ident (abfd
) = tagv
;
4854 if (extdyn
>= dynbuf
+ s
->size
)
4856 /* Ident not found. */
4857 goto error_free_dyn
;
4861 /* We do not want to include any of the sections in a dynamic
4862 object in the output file. We hack by simply clobbering the
4863 list of sections in the BFD. This could be handled more
4864 cleanly by, say, a new section flag; the existing
4865 SEC_NEVER_LOAD flag is not the one we want, because that one
4866 still implies that the section takes up space in the output
4868 bfd_section_list_clear (abfd
);
4870 /* FIXME: should we detect if this library is already included ?
4871 This should be harmless and shouldn't happen in practice. */
4874 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4875 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
4877 /* The sh_info field of the symtab header tells us where the
4878 external symbols start. We don't care about the local symbols at
4880 extsymcount
= symcount
- hdr
->sh_info
;
4881 extsymoff
= hdr
->sh_info
;
4884 if (extsymcount
!= 0)
4886 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
4888 if (isymbuf
== NULL
)
4891 /* We store a pointer to the hash table entry for each external
4893 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
4894 sym_hash
= (struct elf_link_hash_entry
**) bfd_alloc (abfd
, amt
);
4895 if (sym_hash
== NULL
)
4896 goto error_free_sym
;
4897 elf_sym_hashes (abfd
) = sym_hash
;
4900 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
;
4906 asection
*sec
, *new_sec
;
4909 struct elf_link_hash_entry
*h
;
4910 bfd_boolean definition
;
4911 bfd_boolean size_change_ok
;
4912 bfd_boolean type_change_ok
;
4914 unsigned int old_alignment
;
4917 flags
= BSF_NO_FLAGS
;
4919 value
= isym
->st_value
;
4921 common
= bed
->common_definition (isym
);
4923 bind
= ELF_ST_BIND (isym
->st_info
);
4927 /* This should be impossible, since ELF requires that all
4928 global symbols follow all local symbols, and that sh_info
4929 point to the first global symbol. Unfortunately, Irix 5
4934 if (isym
->st_shndx
!= SHN_UNDEF
&& !common
)
4942 case STB_GNU_UNIQUE
:
4943 flags
= BSF_GNU_UNIQUE
;
4947 /* Leave it up to the processor backend. */
4951 if (isym
->st_shndx
== SHN_UNDEF
)
4952 sec
= bfd_und_section_ptr
;
4953 else if (isym
->st_shndx
== SHN_ABS
)
4954 sec
= bfd_abs_section_ptr
;
4955 else if (isym
->st_shndx
== SHN_COMMON
)
4957 sec
= bfd_com_section_ptr
;
4958 /* What ELF calls the size we call the value. What ELF
4959 calls the value we call the alignment. */
4960 value
= isym
->st_size
;
4964 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4966 sec
= bfd_abs_section_ptr
;
4967 else if (sec
->kept_section
)
4969 /* Symbols from discarded section are undefined. We keep
4971 sec
= bfd_und_section_ptr
;
4972 isym
->st_shndx
= SHN_UNDEF
;
4974 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
4978 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
4981 goto error_free_vers
;
4983 if (bed
->elf_add_symbol_hook
)
4985 if (! (*bed
->elf_add_symbol_hook
) (abfd
, info
, isym
, &name
, &flags
,
4987 goto error_free_vers
;
4989 /* The hook function sets the name to NULL if this symbol
4990 should be skipped for some reason. */
4995 /* Sanity check that all possibilities were handled. */
4998 bfd_set_error (bfd_error_bad_value
);
4999 goto error_free_vers
;
5002 if (bfd_is_und_section (sec
)
5003 || bfd_is_com_section (sec
))
5008 size_change_ok
= FALSE
;
5009 type_change_ok
= bed
->type_change_ok
;
5014 if (! bfd_is_und_section (sec
))
5015 h
= elf_link_hash_lookup (htab
, name
, TRUE
, FALSE
, FALSE
);
5017 h
= ((struct elf_link_hash_entry
*) bfd_wrapped_link_hash_lookup
5018 (abfd
, info
, name
, TRUE
, FALSE
, FALSE
));
5020 goto error_free_sym
;
5024 if (is_elf_hash_table (htab
))
5026 while (h
->root
.type
== bfd_link_hash_indirect
5027 || h
->root
.type
== bfd_link_hash_warning
)
5028 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5030 /* Remember the old alignment if this is a common symbol, so
5031 that we don't reduce the alignment later on. We can't
5032 check later, because _bfd_generic_link_add_one_symbol
5033 will set a default for the alignment which we want to
5034 override. We also remember the old bfd where the existing
5035 definition comes from. */
5036 switch (h
->root
.type
)
5041 case bfd_link_hash_defined
:
5042 if (abfd
->selective_search
)
5045 case bfd_link_hash_defweak
:
5046 old_bfd
= h
->root
.u
.def
.section
->owner
;
5049 case bfd_link_hash_common
:
5050 old_bfd
= h
->root
.u
.c
.p
->section
->owner
;
5051 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
5056 if (! (_bfd_generic_link_add_one_symbol
5057 (info
, abfd
, name
, flags
, sec
, value
, NULL
, FALSE
, bed
->collect
,
5058 (struct bfd_link_hash_entry
**) sym_hash
)))
5059 goto error_free_vers
;
5062 while (h
->root
.type
== bfd_link_hash_indirect
5063 || h
->root
.type
== bfd_link_hash_warning
)
5064 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5068 h
->unique_global
= (flags
& BSF_GNU_UNIQUE
) != 0;
5070 /* Set the alignment of a common symbol. */
5071 if ((common
|| bfd_is_com_section (sec
))
5072 && h
->root
.type
== bfd_link_hash_common
)
5077 align
= bfd_log2 (isym
->st_value
);
5080 /* The new symbol is a common symbol in a shared object.
5081 We need to get the alignment from the section. */
5082 align
= new_sec
->alignment_power
;
5084 if (align
> old_alignment
5085 /* Permit an alignment power of zero if an alignment of one
5086 is specified and no other alignments have been specified. */
5087 || (isym
->st_value
== 1 && old_alignment
== 0))
5088 h
->root
.u
.c
.p
->alignment_power
= align
;
5090 h
->root
.u
.c
.p
->alignment_power
= old_alignment
;
5093 if (is_elf_hash_table (htab
))
5095 /* Check the alignment when a common symbol is involved. This
5096 can change when a common symbol is overridden by a normal
5097 definition or a common symbol is ignored due to the old
5098 normal definition. We need to make sure the maximum
5099 alignment is maintained. */
5100 if ((old_alignment
|| common
)
5101 && h
->root
.type
!= bfd_link_hash_common
)
5103 unsigned int common_align
;
5104 unsigned int normal_align
;
5105 unsigned int symbol_align
;
5109 symbol_align
= ffs (h
->root
.u
.def
.value
) - 1;
5110 if (h
->root
.u
.def
.section
->owner
!= NULL
5111 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
5113 normal_align
= h
->root
.u
.def
.section
->alignment_power
;
5114 if (normal_align
> symbol_align
)
5115 normal_align
= symbol_align
;
5118 normal_align
= symbol_align
;
5122 common_align
= old_alignment
;
5123 common_bfd
= old_bfd
;
5128 common_align
= bfd_log2 (isym
->st_value
);
5130 normal_bfd
= old_bfd
;
5133 if (normal_align
< common_align
)
5135 /* PR binutils/2735 */
5136 if (normal_bfd
== NULL
)
5138 /* xgettext:c-format */
5139 (_("Warning: alignment %u of common symbol `%s' in %B"
5140 " is greater than the alignment (%u) of its section %A"),
5141 1 << common_align
, name
, common_bfd
,
5142 1 << normal_align
, h
->root
.u
.def
.section
);
5145 /* xgettext:c-format */
5146 (_("Warning: alignment %u of symbol `%s' in %B"
5147 " is smaller than %u in %B"),
5148 1 << normal_align
, name
, normal_bfd
,
5149 1 << common_align
, common_bfd
);
5153 /* Remember the symbol size if it isn't undefined. */
5154 if ((isym
->st_size
!= 0 && isym
->st_shndx
!= SHN_UNDEF
)
5155 && (definition
|| h
->size
== 0))
5158 && h
->size
!= isym
->st_size
5159 && ! size_change_ok
)
5161 /* xgettext:c-format */
5162 (_("Warning: size of symbol `%s' changed"
5163 " from %lu in %B to %lu in %B"),
5164 name
, (unsigned long) h
->size
, old_bfd
,
5165 (unsigned long) isym
->st_size
, abfd
);
5167 h
->size
= isym
->st_size
;
5170 /* If this is a common symbol, then we always want H->SIZE
5171 to be the size of the common symbol. The code just above
5172 won't fix the size if a common symbol becomes larger. We
5173 don't warn about a size change here, because that is
5174 covered by --warn-common. Allow changed between different
5176 if (h
->root
.type
== bfd_link_hash_common
)
5177 h
->size
= h
->root
.u
.c
.size
;
5179 if (ELF_ST_TYPE (isym
->st_info
) != STT_NOTYPE
5180 && (definition
|| h
->type
== STT_NOTYPE
))
5182 unsigned int type
= ELF_ST_TYPE (isym
->st_info
);
5184 if (h
->type
!= type
)
5186 if (h
->type
!= STT_NOTYPE
&& ! type_change_ok
)
5188 /* xgettext:c-format */
5189 (_("Warning: type of symbol `%s' changed"
5190 " from %d to %d in %B"),
5191 name
, h
->type
, type
, abfd
);
5197 /* Set a flag in the hash table entry indicating the type of
5198 reference or definition we just found. Keep a count of
5199 the number of dynamic symbols we find. A dynamic symbol
5200 is one which is referenced or defined by both a regular
5201 object and a shared object. */
5207 if (bind
!= STB_WEAK
)
5208 h
->ref_regular_nonweak
= 1;
5212 BFD_ASSERT (!h
->def_dynamic
);
5218 BFD_ASSERT (definition
);
5221 ((struct elf64_ia64_link_hash_entry
*)h
)->shl
= abfd
;
5226 if (isymbuf
!= NULL
)
5232 /* If this object is the same format as the output object, and it is
5233 not a shared library, then let the backend look through the
5236 This is required to build global offset table entries and to
5237 arrange for dynamic relocs. It is not required for the
5238 particular common case of linking non PIC code, even when linking
5239 against shared libraries, but unfortunately there is no way of
5240 knowing whether an object file has been compiled PIC or not.
5241 Looking through the relocs is not particularly time consuming.
5242 The problem is that we must either (1) keep the relocs in memory,
5243 which causes the linker to require additional runtime memory or
5244 (2) read the relocs twice from the input file, which wastes time.
5245 This would be a good case for using mmap.
5247 I have no idea how to handle linking PIC code into a file of a
5248 different format. It probably can't be done. */
5250 && is_elf_hash_table (htab
)
5251 && bed
->check_relocs
!= NULL
5252 && (*bed
->relocs_compatible
) (abfd
->xvec
, info
->output_bfd
->xvec
))
5256 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5258 Elf_Internal_Rela
*internal_relocs
;
5261 if ((o
->flags
& SEC_RELOC
) == 0
5262 || o
->reloc_count
== 0
5263 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
5264 && (o
->flags
& SEC_DEBUGGING
) != 0)
5265 || bfd_is_abs_section (o
->output_section
))
5268 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
5270 if (internal_relocs
== NULL
)
5273 ok
= (*bed
->check_relocs
) (abfd
, info
, o
, internal_relocs
);
5275 if (elf_section_data (o
)->relocs
!= internal_relocs
)
5276 free (internal_relocs
);
5287 if (isymbuf
!= NULL
)
5294 elf64_vms_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
5297 struct bfd_link_hash_entry
**pundef
;
5298 struct bfd_link_hash_entry
**next_pundef
;
5300 /* We only accept VMS libraries. */
5301 if (info
->output_bfd
->xvec
!= abfd
->xvec
)
5303 bfd_set_error (bfd_error_wrong_format
);
5307 /* The archive_pass field in the archive itself is used to
5308 initialize PASS, since we may search the same archive multiple
5310 pass
= ++abfd
->archive_pass
;
5312 /* Look through the list of undefined symbols. */
5313 for (pundef
= &info
->hash
->undefs
; *pundef
!= NULL
; pundef
= next_pundef
)
5315 struct bfd_link_hash_entry
*h
;
5321 next_pundef
= &(*pundef
)->u
.undef
.next
;
5323 /* When a symbol is defined, it is not necessarily removed from
5325 if (h
->type
!= bfd_link_hash_undefined
5326 && h
->type
!= bfd_link_hash_common
)
5328 /* Remove this entry from the list, for general cleanliness
5329 and because we are going to look through the list again
5330 if we search any more libraries. We can't remove the
5331 entry if it is the tail, because that would lose any
5332 entries we add to the list later on. */
5333 if (*pundef
!= info
->hash
->undefs_tail
)
5335 *pundef
= *next_pundef
;
5336 next_pundef
= pundef
;
5341 /* Look for this symbol in the archive hash table. */
5342 symidx
= _bfd_vms_lib_find_symbol (abfd
, h
->root
.string
);
5343 if (symidx
== BFD_NO_MORE_SYMBOLS
)
5345 /* Nothing in this slot. */
5349 element
= bfd_get_elt_at_index (abfd
, symidx
);
5350 if (element
== NULL
)
5353 if (element
->archive_pass
== -1 || element
->archive_pass
== pass
)
5355 /* Next symbol if this archive is wrong or already handled. */
5359 orig_element
= element
;
5360 if (bfd_is_thin_archive (abfd
))
5362 element
= _bfd_vms_lib_get_imagelib_file (element
);
5363 if (element
== NULL
|| !bfd_check_format (element
, bfd_object
))
5365 orig_element
->archive_pass
= -1;
5369 else if (! bfd_check_format (element
, bfd_object
))
5371 element
->archive_pass
= -1;
5375 /* Unlike the generic linker, we know that this element provides
5376 a definition for an undefined symbol and we know that we want
5377 to include it. We don't need to check anything. */
5378 if (! (*info
->callbacks
->add_archive_element
) (info
, element
,
5379 h
->root
.string
, &element
))
5381 if (! elf64_vms_link_add_object_symbols (element
, info
))
5384 orig_element
->archive_pass
= pass
;
5391 elf64_vms_bfd_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
5393 switch (bfd_get_format (abfd
))
5396 return elf64_vms_link_add_object_symbols (abfd
, info
);
5399 return elf64_vms_link_add_archive_symbols (abfd
, info
);
5402 bfd_set_error (bfd_error_wrong_format
);
5408 elf64_ia64_vms_mkobject (bfd
*abfd
)
5410 return bfd_elf_allocate_object
5411 (abfd
, sizeof (struct elf64_ia64_vms_obj_tdata
), IA64_ELF_DATA
);
5415 /* Size-dependent data and functions. */
5416 static const struct elf_size_info elf64_ia64_vms_size_info
= {
5417 sizeof (Elf64_External_VMS_Ehdr
),
5418 sizeof (Elf64_External_Phdr
),
5419 sizeof (Elf64_External_Shdr
),
5420 sizeof (Elf64_External_Rel
),
5421 sizeof (Elf64_External_Rela
),
5422 sizeof (Elf64_External_Sym
),
5423 sizeof (Elf64_External_Dyn
),
5424 sizeof (Elf_External_Note
),
5427 64, 3, /* ARCH_SIZE, LOG_FILE_ALIGN */
5428 ELFCLASS64
, EV_CURRENT
,
5429 bfd_elf64_write_out_phdrs
,
5430 elf64_vms_write_shdrs_and_ehdr
,
5431 bfd_elf64_checksum_contents
,
5432 bfd_elf64_write_relocs
,
5433 bfd_elf64_swap_symbol_in
,
5434 bfd_elf64_swap_symbol_out
,
5435 bfd_elf64_slurp_reloc_table
,
5436 bfd_elf64_slurp_symbol_table
,
5437 bfd_elf64_swap_dyn_in
,
5438 bfd_elf64_swap_dyn_out
,
5439 bfd_elf64_swap_reloc_in
,
5440 bfd_elf64_swap_reloc_out
,
5441 bfd_elf64_swap_reloca_in
,
5442 bfd_elf64_swap_reloca_out
5445 #define ELF_ARCH bfd_arch_ia64
5446 #define ELF_MACHINE_CODE EM_IA_64
5447 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5448 #define ELF_COMMONPAGESIZE 0x200 /* 16KB */
5450 #define elf_backend_section_from_shdr \
5451 elf64_ia64_section_from_shdr
5452 #define elf_backend_section_flags \
5453 elf64_ia64_section_flags
5454 #define elf_backend_fake_sections \
5455 elf64_ia64_fake_sections
5456 #define elf_backend_final_write_processing \
5457 elf64_ia64_final_write_processing
5458 #define elf_backend_add_symbol_hook \
5459 elf64_ia64_add_symbol_hook
5460 #define elf_info_to_howto \
5461 elf64_ia64_info_to_howto
5463 #define bfd_elf64_bfd_reloc_type_lookup \
5464 ia64_elf_reloc_type_lookup
5465 #define bfd_elf64_bfd_reloc_name_lookup \
5466 ia64_elf_reloc_name_lookup
5467 #define bfd_elf64_bfd_is_local_label_name \
5468 elf64_ia64_is_local_label_name
5469 #define bfd_elf64_bfd_relax_section \
5470 elf64_ia64_relax_section
5472 #define elf_backend_object_p \
5475 /* Stuff for the BFD linker: */
5476 #define bfd_elf64_bfd_link_hash_table_create \
5477 elf64_ia64_hash_table_create
5478 #define elf_backend_create_dynamic_sections \
5479 elf64_ia64_create_dynamic_sections
5480 #define elf_backend_check_relocs \
5481 elf64_ia64_check_relocs
5482 #define elf_backend_adjust_dynamic_symbol \
5483 elf64_ia64_adjust_dynamic_symbol
5484 #define elf_backend_size_dynamic_sections \
5485 elf64_ia64_size_dynamic_sections
5486 #define elf_backend_omit_section_dynsym \
5487 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
5488 #define elf_backend_relocate_section \
5489 elf64_ia64_relocate_section
5490 #define elf_backend_finish_dynamic_symbol \
5491 elf64_ia64_finish_dynamic_symbol
5492 #define elf_backend_finish_dynamic_sections \
5493 elf64_ia64_finish_dynamic_sections
5494 #define bfd_elf64_bfd_final_link \
5495 elf64_ia64_final_link
5497 #define bfd_elf64_bfd_merge_private_bfd_data \
5498 elf64_ia64_merge_private_bfd_data
5499 #define bfd_elf64_bfd_set_private_flags \
5500 elf64_ia64_set_private_flags
5501 #define bfd_elf64_bfd_print_private_bfd_data \
5502 elf64_ia64_print_private_bfd_data
5504 #define elf_backend_plt_readonly 1
5505 #define elf_backend_want_plt_sym 0
5506 #define elf_backend_plt_alignment 5
5507 #define elf_backend_got_header_size 0
5508 #define elf_backend_want_got_plt 1
5509 #define elf_backend_may_use_rel_p 1
5510 #define elf_backend_may_use_rela_p 1
5511 #define elf_backend_default_use_rela_p 1
5512 #define elf_backend_want_dynbss 0
5513 #define elf_backend_hide_symbol elf64_ia64_hash_hide_symbol
5514 #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol
5515 #define elf_backend_reloc_type_class elf64_ia64_reloc_type_class
5516 #define elf_backend_rela_normal 1
5517 #define elf_backend_special_sections elf64_ia64_special_sections
5518 #define elf_backend_default_execstack 0
5520 /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
5521 SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
5522 We don't want to flood users with so many error messages. We turn
5523 off the warning for now. It will be turned on later when the Intel
5524 compiler is fixed. */
5525 #define elf_backend_link_order_error_handler NULL
5527 /* VMS-specific vectors. */
5529 #undef TARGET_LITTLE_SYM
5530 #define TARGET_LITTLE_SYM ia64_elf64_vms_vec
5531 #undef TARGET_LITTLE_NAME
5532 #define TARGET_LITTLE_NAME "elf64-ia64-vms"
5533 #undef TARGET_BIG_SYM
5534 #undef TARGET_BIG_NAME
5536 /* These are VMS specific functions. */
5538 #undef elf_backend_object_p
5539 #define elf_backend_object_p elf64_vms_object_p
5541 #undef elf_backend_section_from_shdr
5542 #define elf_backend_section_from_shdr elf64_vms_section_from_shdr
5544 #undef elf_backend_post_process_headers
5545 #define elf_backend_post_process_headers elf64_vms_post_process_headers
5547 #undef elf_backend_section_processing
5548 #define elf_backend_section_processing elf64_vms_section_processing
5550 #undef elf_backend_final_write_processing
5551 #define elf_backend_final_write_processing elf64_vms_final_write_processing
5553 #undef bfd_elf64_close_and_cleanup
5554 #define bfd_elf64_close_and_cleanup elf64_vms_close_and_cleanup
5556 #undef elf_backend_section_from_bfd_section
5558 #undef elf_backend_symbol_processing
5560 #undef elf_backend_want_p_paddr_set_to_zero
5563 #define ELF_OSABI ELFOSABI_OPENVMS
5565 #undef ELF_MAXPAGESIZE
5566 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5569 #define elf64_bed elf64_ia64_vms_bed
5571 #define elf_backend_size_info elf64_ia64_vms_size_info
5573 /* Use VMS-style archives (in particular, don't use the standard coff
5575 #define bfd_elf64_archive_functions
5577 #undef bfd_elf64_archive_p
5578 #define bfd_elf64_archive_p _bfd_vms_lib_ia64_archive_p
5579 #undef bfd_elf64_write_archive_contents
5580 #define bfd_elf64_write_archive_contents _bfd_vms_lib_write_archive_contents
5581 #undef bfd_elf64_mkarchive
5582 #define bfd_elf64_mkarchive _bfd_vms_lib_ia64_mkarchive
5584 #define bfd_elf64_archive_slurp_armap \
5585 _bfd_vms_lib_slurp_armap
5586 #define bfd_elf64_archive_slurp_extended_name_table \
5587 _bfd_vms_lib_slurp_extended_name_table
5588 #define bfd_elf64_archive_construct_extended_name_table \
5589 _bfd_vms_lib_construct_extended_name_table
5590 #define bfd_elf64_archive_truncate_arname \
5591 _bfd_vms_lib_truncate_arname
5592 #define bfd_elf64_archive_write_armap \
5593 _bfd_vms_lib_write_armap
5594 #define bfd_elf64_archive_read_ar_hdr \
5595 _bfd_vms_lib_read_ar_hdr
5596 #define bfd_elf64_archive_write_ar_hdr \
5597 _bfd_vms_lib_write_ar_hdr
5598 #define bfd_elf64_archive_openr_next_archived_file \
5599 _bfd_vms_lib_openr_next_archived_file
5600 #define bfd_elf64_archive_get_elt_at_index \
5601 _bfd_vms_lib_get_elt_at_index
5602 #define bfd_elf64_archive_generic_stat_arch_elt \
5603 _bfd_vms_lib_generic_stat_arch_elt
5604 #define bfd_elf64_archive_update_armap_timestamp \
5605 _bfd_vms_lib_update_armap_timestamp
5607 /* VMS link methods. */
5608 #undef bfd_elf64_bfd_link_add_symbols
5609 #define bfd_elf64_bfd_link_add_symbols elf64_vms_bfd_link_add_symbols
5611 #undef elf_backend_want_got_sym
5612 #define elf_backend_want_got_sym 0
5614 #undef bfd_elf64_mkobject
5615 #define bfd_elf64_mkobject elf64_ia64_vms_mkobject
5617 /* Redefine to align segments on block size. */
5618 #undef ELF_MAXPAGESIZE
5619 #define ELF_MAXPAGESIZE 0x200 /* 512B */
5621 #undef elf_backend_want_got_plt
5622 #define elf_backend_want_got_plt 0
5624 #include "elf64-target.h"