1 /* IA-64 support for OpenVMS
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
26 #include "opcode/ia64.h"
30 #include "elfxx-ia64.h"
34 /* THE RULES for all the stuff the linker creates --
36 GOT Entries created in response to LTOFF or LTOFF_FPTR
37 relocations. Dynamic relocs created for dynamic
38 symbols in an application; REL relocs for locals
41 FPTR The canonical function descriptor. Created for local
42 symbols in applications. Descriptors for dynamic symbols
43 and local symbols in shared libraries are created by
44 ld.so. Thus there are no dynamic relocs against these
45 objects. The FPTR relocs for such _are_ passed through
46 to the dynamic relocation tables.
48 FULL_PLT Created for a PCREL21B relocation against a dynamic symbol.
49 Requires the creation of a PLTOFF entry. This does not
50 require any dynamic relocations.
52 PLTOFF Created by PLTOFF relocations. For local symbols, this
53 is an alternate function descriptor, and in shared libraries
54 requires two REL relocations. Note that this cannot be
55 transformed into an FPTR relocation, since it must be in
56 range of the GP. For dynamic symbols, this is a function
59 typedef struct bfd_hash_entry *(*new_hash_entry_func)
60 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
62 /* In dynamically (linker-) created sections, we generally need to keep track
63 of the place a symbol or expression got allocated to. This is done via hash
64 tables that store entries of the following type. */
66 struct elf64_ia64_dyn_sym_info
68 /* The addend for which this entry is relevant. */
73 bfd_vma pltoff_offset;
77 /* The symbol table entry, if any, that this was derived from. */
78 struct elf_link_hash_entry *h;
80 /* Used to count non-got, non-plt relocations for delayed sizing
81 of relocation sections. */
82 struct elf64_ia64_dyn_reloc_entry
84 struct elf64_ia64_dyn_reloc_entry *next;
90 /* TRUE when the section contents have been updated. */
91 unsigned got_done : 1;
92 unsigned fptr_done : 1;
93 unsigned pltoff_done : 1;
95 /* TRUE for the different kinds of linker data we want created. */
96 unsigned want_got : 1;
97 unsigned want_gotx : 1;
98 unsigned want_fptr : 1;
99 unsigned want_ltoff_fptr : 1;
100 unsigned want_plt : 1; /* A MIN_PLT entry. */
101 unsigned want_plt2 : 1; /* A FULL_PLT. */
102 unsigned want_pltoff : 1;
105 struct elf64_ia64_local_hash_entry
109 /* The number of elements in elf64_ia64_dyn_sym_info array. */
111 /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */
112 unsigned int sorted_count;
113 /* The size of elf64_ia64_dyn_sym_info array. */
115 /* The array of elf64_ia64_dyn_sym_info. */
116 struct elf64_ia64_dyn_sym_info *info;
118 /* TRUE if this hash entry's addends was translated for
119 SHF_MERGE optimization. */
120 unsigned sec_merge_done : 1;
123 struct elf64_ia64_link_hash_entry
125 struct elf_link_hash_entry root;
127 /* Set if this symbol is defined in a shared library.
128 We can't use root.u.def.section->owner as the symbol is an absolute
132 /* The number of elements in elf64_ia64_dyn_sym_info array. */
134 /* The number of sorted elements in elf64_ia64_dyn_sym_info array. */
135 unsigned int sorted_count;
136 /* The size of elf64_ia64_dyn_sym_info array. */
138 /* The array of elf64_ia64_dyn_sym_info. */
139 struct elf64_ia64_dyn_sym_info *info;
142 struct elf64_ia64_link_hash_table
144 /* The main hash table. */
145 struct elf_link_hash_table root;
147 asection *fptr_sec; /* Function descriptor table (or NULL). */
148 asection *rel_fptr_sec; /* Dynamic relocation section for same. */
149 asection *pltoff_sec; /* Private descriptors for plt (or NULL). */
150 asection *fixups_sec; /* Fixups section. */
151 asection *transfer_sec; /* Transfer vector section. */
152 asection *note_sec; /* .note section. */
154 /* There are maybe R_IA64_GPREL22 relocations, including those
155 optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT
156 sections. We need to record those sections so that we can choose
157 a proper GP to cover all R_IA64_GPREL22 relocations. */
158 asection *max_short_sec; /* Maximum short output section. */
159 bfd_vma max_short_offset; /* Maximum short offset. */
160 asection *min_short_sec; /* Minimum short output section. */
161 bfd_vma min_short_offset; /* Minimum short offset. */
163 htab_t loc_hash_table;
164 void *loc_hash_memory;
167 struct elf64_ia64_allocate_data
169 struct bfd_link_info *info;
173 #define elf64_ia64_hash_table(p) \
174 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
175 == IA64_ELF_DATA ? ((struct elf64_ia64_link_hash_table *) ((p)->hash)) : NULL)
177 struct elf64_ia64_vms_obj_tdata
179 struct elf_obj_tdata root;
181 /* Ident for shared library. */
184 /* Used only during link: offset in the .fixups section for this bfd. */
187 /* Max number of shared libraries. */
188 unsigned int needed_count;
191 #define elf_ia64_vms_tdata(abfd) \
192 ((struct elf64_ia64_vms_obj_tdata *)((abfd)->tdata.any))
193 #define elf_ia64_vms_ident(abfd) (elf_ia64_vms_tdata(abfd)->ident)
195 struct elf64_vms_transfer
197 unsigned char size[4];
198 unsigned char spare[4];
199 unsigned char tfradr1[8];
200 unsigned char tfradr2[8];
201 unsigned char tfradr3[8];
202 unsigned char tfradr4[8];
203 unsigned char tfradr5[8];
205 /* Local function descriptor for tfr3. */
206 unsigned char tfr3_func[8];
207 unsigned char tfr3_gp[8];
212 Elf64_External_Ehdr ehdr;
213 unsigned char vms_needed_count[8];
214 } Elf64_External_VMS_Ehdr;
216 static struct elf64_ia64_dyn_sym_info * get_dyn_sym_info
217 (struct elf64_ia64_link_hash_table *,
218 struct elf_link_hash_entry *,
219 bfd *, const Elf_Internal_Rela *, bfd_boolean);
220 static bfd_boolean elf64_ia64_dynamic_symbol_p
221 (struct elf_link_hash_entry *);
222 static bfd_boolean elf64_ia64_choose_gp
223 (bfd *, struct bfd_link_info *, bfd_boolean);
224 static void elf64_ia64_dyn_sym_traverse
225 (struct elf64_ia64_link_hash_table *,
226 bfd_boolean (*) (struct elf64_ia64_dyn_sym_info *, void *),
228 static bfd_boolean allocate_global_data_got
229 (struct elf64_ia64_dyn_sym_info *, void *);
230 static bfd_boolean allocate_global_fptr_got
231 (struct elf64_ia64_dyn_sym_info *, void *);
232 static bfd_boolean allocate_local_got
233 (struct elf64_ia64_dyn_sym_info *, void *);
234 static bfd_boolean allocate_dynrel_entries
235 (struct elf64_ia64_dyn_sym_info *, void *);
236 static asection *get_pltoff
237 (bfd *, struct elf64_ia64_link_hash_table *);
238 static asection *get_got
239 (bfd *, struct elf64_ia64_link_hash_table *);
242 /* Given a ELF reloc, return the matching HOWTO structure. */
245 elf64_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
247 Elf_Internal_Rela *elf_reloc)
250 = ia64_elf_lookup_howto ((unsigned int) ELF64_R_TYPE (elf_reloc->r_info));
254 #define PLT_FULL_ENTRY_SIZE (2 * 16)
256 static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
258 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
259 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/
260 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
261 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
262 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
263 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
266 static const bfd_byte oor_brl[16] =
268 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;;*/
270 0x00, 0x00, 0x00, 0xc0
274 /* These functions do relaxation for IA-64 ELF. */
276 /* Rename some of the generic section flags to better document how they
278 #define skip_relax_pass_0 sec_flg0
279 #define skip_relax_pass_1 sec_flg1
282 elf64_ia64_update_short_info (asection *sec, bfd_vma offset,
283 struct elf64_ia64_link_hash_table *ia64_info)
285 /* Skip ABS and SHF_IA_64_SHORT sections. */
286 if (sec == bfd_abs_section_ptr
287 || (sec->flags & SEC_SMALL_DATA) != 0)
290 if (!ia64_info->min_short_sec)
292 ia64_info->max_short_sec = sec;
293 ia64_info->max_short_offset = offset;
294 ia64_info->min_short_sec = sec;
295 ia64_info->min_short_offset = offset;
297 else if (sec == ia64_info->max_short_sec
298 && offset > ia64_info->max_short_offset)
299 ia64_info->max_short_offset = offset;
300 else if (sec == ia64_info->min_short_sec
301 && offset < ia64_info->min_short_offset)
302 ia64_info->min_short_offset = offset;
303 else if (sec->output_section->vma
304 > ia64_info->max_short_sec->vma)
306 ia64_info->max_short_sec = sec;
307 ia64_info->max_short_offset = offset;
309 else if (sec->output_section->vma
310 < ia64_info->min_short_sec->vma)
312 ia64_info->min_short_sec = sec;
313 ia64_info->min_short_offset = offset;
317 /* Use a two passes algorithm. In the first pass, branches are relaxed
318 (which may increase the size of the section). In the second pass,
319 the other relaxations are done.
323 elf64_ia64_relax_section (bfd *abfd, asection *sec,
324 struct bfd_link_info *link_info,
329 struct one_fixup *next;
335 Elf_Internal_Shdr *symtab_hdr;
336 Elf_Internal_Rela *internal_relocs;
337 Elf_Internal_Rela *irel, *irelend;
339 Elf_Internal_Sym *isymbuf = NULL;
340 struct elf64_ia64_link_hash_table *ia64_info;
341 struct one_fixup *fixups = NULL;
342 bfd_boolean changed_contents = FALSE;
343 bfd_boolean changed_relocs = FALSE;
344 bfd_boolean skip_relax_pass_0 = TRUE;
345 bfd_boolean skip_relax_pass_1 = TRUE;
348 /* Assume we're not going to change any sizes, and we'll only need
352 if (link_info->relocatable)
353 (*link_info->callbacks->einfo)
354 (_("%P%F: --relax and -r may not be used together\n"));
356 /* Don't even try to relax for non-ELF outputs. */
357 if (!is_elf_hash_table (link_info->hash))
360 /* Nothing to do if there are no relocations or there is no need for
362 if ((sec->flags & SEC_RELOC) == 0
363 || sec->reloc_count == 0
364 || (link_info->relax_pass == 0 && sec->skip_relax_pass_0)
365 || (link_info->relax_pass == 1 && sec->skip_relax_pass_1))
368 ia64_info = elf64_ia64_hash_table (link_info);
369 if (ia64_info == NULL)
372 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
374 /* Load the relocations for this section. */
375 internal_relocs = (_bfd_elf_link_read_relocs
376 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
377 link_info->keep_memory));
378 if (internal_relocs == NULL)
381 irelend = internal_relocs + sec->reloc_count;
383 /* Get the section contents. */
384 if (elf_section_data (sec)->this_hdr.contents != NULL)
385 contents = elf_section_data (sec)->this_hdr.contents;
388 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
392 for (irel = internal_relocs; irel < irelend; irel++)
394 unsigned long r_type = ELF64_R_TYPE (irel->r_info);
395 bfd_vma symaddr, reladdr, trampoff, toff, roff;
399 bfd_boolean is_branch;
400 struct elf64_ia64_dyn_sym_info *dyn_i;
404 case R_IA64_PCREL21B:
405 case R_IA64_PCREL21BI:
406 case R_IA64_PCREL21M:
407 case R_IA64_PCREL21F:
408 /* In pass 1, all br relaxations are done. We can skip it. */
409 if (link_info->relax_pass == 1)
411 skip_relax_pass_0 = FALSE;
415 case R_IA64_PCREL60B:
416 /* We can't optimize brl to br in pass 0 since br relaxations
417 will increase the code size. Defer it to pass 1. */
418 if (link_info->relax_pass == 0)
420 skip_relax_pass_1 = FALSE;
427 /* Update max_short_sec/min_short_sec. */
429 case R_IA64_LTOFF22X:
431 /* We can't relax ldx/mov in pass 0 since br relaxations will
432 increase the code size. Defer it to pass 1. */
433 if (link_info->relax_pass == 0)
435 skip_relax_pass_1 = FALSE;
445 /* Get the value of the symbol referred to by the reloc. */
446 if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
448 /* A local symbol. */
449 Elf_Internal_Sym *isym;
451 /* Read this BFD's local symbols. */
454 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
456 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
457 symtab_hdr->sh_info, 0,
463 isym = isymbuf + ELF64_R_SYM (irel->r_info);
464 if (isym->st_shndx == SHN_UNDEF)
465 continue; /* We can't do anything with undefined symbols. */
466 else if (isym->st_shndx == SHN_ABS)
467 tsec = bfd_abs_section_ptr;
468 else if (isym->st_shndx == SHN_COMMON)
469 tsec = bfd_com_section_ptr;
470 else if (isym->st_shndx == SHN_IA_64_ANSI_COMMON)
471 tsec = bfd_com_section_ptr;
473 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
475 toff = isym->st_value;
476 dyn_i = get_dyn_sym_info (ia64_info, NULL, abfd, irel, FALSE);
481 struct elf_link_hash_entry *h;
483 indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
484 h = elf_sym_hashes (abfd)[indx];
485 BFD_ASSERT (h != NULL);
487 while (h->root.type == bfd_link_hash_indirect
488 || h->root.type == bfd_link_hash_warning)
489 h = (struct elf_link_hash_entry *) h->root.u.i.link;
491 dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, FALSE);
493 /* For branches to dynamic symbols, we're interested instead
494 in a branch to the PLT entry. */
495 if (is_branch && dyn_i && dyn_i->want_plt2)
497 /* Internal branches shouldn't be sent to the PLT.
498 Leave this for now and we'll give an error later. */
499 if (r_type != R_IA64_PCREL21B)
502 tsec = ia64_info->root.splt;
503 toff = dyn_i->plt2_offset;
504 BFD_ASSERT (irel->r_addend == 0);
507 /* Can't do anything else with dynamic symbols. */
508 else if (elf64_ia64_dynamic_symbol_p (h))
513 /* We can't do anything with undefined symbols. */
514 if (h->root.type == bfd_link_hash_undefined
515 || h->root.type == bfd_link_hash_undefweak)
518 tsec = h->root.u.def.section;
519 toff = h->root.u.def.value;
523 toff += irel->r_addend;
525 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
527 roff = irel->r_offset;
531 bfd_signed_vma offset;
533 reladdr = (sec->output_section->vma
535 + roff) & (bfd_vma) -4;
537 /* The .plt section is aligned at 32byte and the .text section
538 is aligned at 64byte. The .text section is right after the
539 .plt section. After the first relaxation pass, linker may
540 increase the gap between the .plt and .text sections up
541 to 32byte. We assume linker will always insert 32byte
542 between the .plt and .text sections after the first
544 if (tsec == ia64_info->root.splt)
545 offset = -0x1000000 + 32;
549 /* If the branch is in range, no need to do anything. */
550 if ((bfd_signed_vma) (symaddr - reladdr) >= offset
551 && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
553 /* If the 60-bit branch is in 21-bit range, optimize it. */
554 if (r_type == R_IA64_PCREL60B)
556 ia64_elf_relax_brl (contents, roff);
558 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
561 /* If the original relocation offset points to slot
562 1, change it to slot 2. */
563 if ((irel->r_offset & 3) == 1)
569 else if (r_type == R_IA64_PCREL60B)
571 else if (ia64_elf_relax_br (contents, roff))
573 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
576 /* Make the relocation offset point to slot 1. */
577 irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1;
581 /* We can't put a trampoline in a .init/.fini section. Issue
583 if (strcmp (sec->output_section->name, ".init") == 0
584 || strcmp (sec->output_section->name, ".fini") == 0)
586 (*_bfd_error_handler)
587 (_("%B: Can't relax br at 0x%lx in section `%A'. Please use brl or indirect branch."),
588 sec->owner, sec, (unsigned long) roff);
589 bfd_set_error (bfd_error_bad_value);
593 /* If the branch and target are in the same section, you've
594 got one honking big section and we can't help you unless
595 you are branching backwards. You'll get an error message
597 if (tsec == sec && toff > roff)
600 /* Look for an existing fixup to this address. */
601 for (f = fixups; f ; f = f->next)
602 if (f->tsec == tsec && f->toff == toff)
607 /* Two alternatives: If it's a branch to a PLT entry, we can
608 make a copy of the FULL_PLT entry. Otherwise, we'll have
609 to use a `brl' insn to get where we're going. */
613 if (tsec == ia64_info->root.splt)
614 size = sizeof (plt_full_entry);
616 size = sizeof (oor_brl);
618 /* Resize the current section to make room for the new branch. */
619 trampoff = (sec->size + 15) & (bfd_vma) -16;
621 /* If trampoline is out of range, there is nothing we
623 offset = trampoff - (roff & (bfd_vma) -4);
624 if (offset < -0x1000000 || offset > 0x0FFFFF0)
627 amt = trampoff + size;
628 contents = (bfd_byte *) bfd_realloc (contents, amt);
629 if (contents == NULL)
633 if (tsec == ia64_info->root.splt)
635 memcpy (contents + trampoff, plt_full_entry, size);
637 /* Hijack the old relocation for use as the PLTOFF reloc. */
638 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
640 irel->r_offset = trampoff;
644 memcpy (contents + trampoff, oor_brl, size);
645 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
647 irel->r_offset = trampoff + 2;
650 /* Record the fixup so we don't do it again this section. */
651 f = (struct one_fixup *)
652 bfd_malloc ((bfd_size_type) sizeof (*f));
656 f->trampoff = trampoff;
661 /* If trampoline is out of range, there is nothing we
663 offset = f->trampoff - (roff & (bfd_vma) -4);
664 if (offset < -0x1000000 || offset > 0x0FFFFF0)
667 /* Nop out the reloc, since we're finalizing things here. */
668 irel->r_info = ELF64_R_INFO (0, R_IA64_NONE);
671 /* Fix up the existing branch to hit the trampoline. */
672 if (ia64_elf_install_value (contents + roff, offset, r_type)
676 changed_contents = TRUE;
677 changed_relocs = TRUE;
684 bfd *obfd = sec->output_section->owner;
685 gp = _bfd_get_gp_value (obfd);
688 if (!elf64_ia64_choose_gp (obfd, link_info, FALSE))
690 gp = _bfd_get_gp_value (obfd);
694 /* If the data is out of range, do nothing. */
695 if ((bfd_signed_vma) (symaddr - gp) >= 0x200000
696 ||(bfd_signed_vma) (symaddr - gp) < -0x200000)
699 if (r_type == R_IA64_GPREL22)
700 elf64_ia64_update_short_info (tsec->output_section,
701 tsec->output_offset + toff,
703 else if (r_type == R_IA64_LTOFF22X)
705 /* Can't deal yet correctly with ABS symbols. */
706 if (bfd_is_abs_section (tsec))
709 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
711 changed_relocs = TRUE;
713 elf64_ia64_update_short_info (tsec->output_section,
714 tsec->output_offset + toff,
719 ia64_elf_relax_ldxmov (contents, roff);
720 irel->r_info = ELF64_R_INFO (0, R_IA64_NONE);
721 changed_contents = TRUE;
722 changed_relocs = TRUE;
727 /* ??? If we created fixups, this may push the code segment large
728 enough that the data segment moves, which will change the GP.
729 Reset the GP so that we re-calculate next round. We need to
730 do this at the _beginning_ of the next round; now will not do. */
732 /* Clean up and go home. */
735 struct one_fixup *f = fixups;
736 fixups = fixups->next;
741 && symtab_hdr->contents != (unsigned char *) isymbuf)
743 if (! link_info->keep_memory)
747 /* Cache the symbols for elf_link_input_bfd. */
748 symtab_hdr->contents = (unsigned char *) isymbuf;
753 && elf_section_data (sec)->this_hdr.contents != contents)
755 if (!changed_contents && !link_info->keep_memory)
759 /* Cache the section contents for elf_link_input_bfd. */
760 elf_section_data (sec)->this_hdr.contents = contents;
764 if (elf_section_data (sec)->relocs != internal_relocs)
767 free (internal_relocs);
769 elf_section_data (sec)->relocs = internal_relocs;
772 if (link_info->relax_pass == 0)
774 /* Pass 0 is only needed to relax br. */
775 sec->skip_relax_pass_0 = skip_relax_pass_0;
776 sec->skip_relax_pass_1 = skip_relax_pass_1;
779 *again = changed_contents || changed_relocs;
783 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
786 && elf_section_data (sec)->this_hdr.contents != contents)
788 if (internal_relocs != NULL
789 && elf_section_data (sec)->relocs != internal_relocs)
790 free (internal_relocs);
793 #undef skip_relax_pass_0
794 #undef skip_relax_pass_1
796 /* Return TRUE if NAME is an unwind table section name. */
798 static inline bfd_boolean
799 is_unwind_section_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
801 return ((CONST_STRNEQ (name, ELF_STRING_ia64_unwind)
802 && ! CONST_STRNEQ (name, ELF_STRING_ia64_unwind_info))
803 || CONST_STRNEQ (name, ELF_STRING_ia64_unwind_once));
807 /* Convert IA-64 specific section flags to bfd internal section flags. */
809 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
813 elf64_ia64_section_flags (flagword *flags,
814 const Elf_Internal_Shdr *hdr)
816 if (hdr->sh_flags & SHF_IA_64_SHORT)
817 *flags |= SEC_SMALL_DATA;
822 /* Set the correct type for an IA-64 ELF section. We do this by the
823 section name, which is a hack, but ought to work. */
826 elf64_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr,
831 name = bfd_get_section_name (abfd, sec);
833 if (is_unwind_section_name (abfd, name))
835 /* We don't have the sections numbered at this point, so sh_info
836 is set later, in elf64_ia64_final_write_processing. */
837 hdr->sh_type = SHT_IA_64_UNWIND;
838 hdr->sh_flags |= SHF_LINK_ORDER;
840 else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
841 hdr->sh_type = SHT_IA_64_EXT;
843 if (sec->flags & SEC_SMALL_DATA)
844 hdr->sh_flags |= SHF_IA_64_SHORT;
849 /* Hook called by the linker routine which adds symbols from an object
850 file. We use it to put .comm items in .sbss, and not .bss. */
853 elf64_ia64_add_symbol_hook (bfd *abfd,
854 struct bfd_link_info *info,
855 Elf_Internal_Sym *sym,
856 const char **namep ATTRIBUTE_UNUSED,
857 flagword *flagsp ATTRIBUTE_UNUSED,
861 if (sym->st_shndx == SHN_COMMON
862 && !info->relocatable
863 && sym->st_size <= elf_gp_size (abfd))
865 /* Common symbols less than or equal to -G nn bytes are
866 automatically put into .sbss. */
868 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
872 scomm = bfd_make_section_with_flags (abfd, ".scommon",
875 | SEC_LINKER_CREATED));
881 *valp = sym->st_size;
887 /* According to the Tahoe assembler spec, all labels starting with a
891 elf64_ia64_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
894 return name[0] == '.';
897 /* Should we do dynamic things to this symbol? */
900 elf64_ia64_dynamic_symbol_p (struct elf_link_hash_entry *h)
902 return h != NULL && h->def_dynamic;
905 static struct bfd_hash_entry*
906 elf64_ia64_new_elf_hash_entry (struct bfd_hash_entry *entry,
907 struct bfd_hash_table *table,
910 struct elf64_ia64_link_hash_entry *ret;
911 ret = (struct elf64_ia64_link_hash_entry *) entry;
913 /* Allocate the structure if it has not already been allocated by a
916 ret = bfd_hash_allocate (table, sizeof (*ret));
921 /* Call the allocation method of the superclass. */
922 ret = ((struct elf64_ia64_link_hash_entry *)
923 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
928 ret->sorted_count = 0;
930 return (struct bfd_hash_entry *) ret;
934 elf64_ia64_hash_hide_symbol (struct bfd_link_info *info,
935 struct elf_link_hash_entry *xh,
936 bfd_boolean force_local)
938 struct elf64_ia64_link_hash_entry *h;
939 struct elf64_ia64_dyn_sym_info *dyn_i;
942 h = (struct elf64_ia64_link_hash_entry *)xh;
944 _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
946 for (count = h->count, dyn_i = h->info;
950 dyn_i->want_plt2 = 0;
955 /* Compute a hash of a local hash entry. */
958 elf64_ia64_local_htab_hash (const void *ptr)
960 struct elf64_ia64_local_hash_entry *entry
961 = (struct elf64_ia64_local_hash_entry *) ptr;
963 return ELF_LOCAL_SYMBOL_HASH (entry->id, entry->r_sym);
966 /* Compare local hash entries. */
969 elf64_ia64_local_htab_eq (const void *ptr1, const void *ptr2)
971 struct elf64_ia64_local_hash_entry *entry1
972 = (struct elf64_ia64_local_hash_entry *) ptr1;
973 struct elf64_ia64_local_hash_entry *entry2
974 = (struct elf64_ia64_local_hash_entry *) ptr2;
976 return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym;
979 /* Create the derived linker hash table. The IA-64 ELF port uses this
980 derived hash table to keep information specific to the IA-64 ElF
981 linker (without using static variables). */
983 static struct bfd_link_hash_table *
984 elf64_ia64_hash_table_create (bfd *abfd)
986 struct elf64_ia64_link_hash_table *ret;
988 ret = bfd_zmalloc ((bfd_size_type) sizeof (*ret));
992 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
993 elf64_ia64_new_elf_hash_entry,
994 sizeof (struct elf64_ia64_link_hash_entry),
1001 ret->loc_hash_table = htab_try_create (1024, elf64_ia64_local_htab_hash,
1002 elf64_ia64_local_htab_eq, NULL);
1003 ret->loc_hash_memory = objalloc_create ();
1004 if (!ret->loc_hash_table || !ret->loc_hash_memory)
1010 return &ret->root.root;
1013 /* Free the global elf64_ia64_dyn_sym_info array. */
1016 elf64_ia64_global_dyn_info_free (void **xentry,
1017 void * unused ATTRIBUTE_UNUSED)
1019 struct elf64_ia64_link_hash_entry *entry
1020 = (struct elf64_ia64_link_hash_entry *) xentry;
1022 if (entry->root.root.type == bfd_link_hash_warning)
1023 entry = (struct elf64_ia64_link_hash_entry *) entry->root.root.u.i.link;
1030 entry->sorted_count = 0;
1037 /* Free the local elf64_ia64_dyn_sym_info array. */
1040 elf64_ia64_local_dyn_info_free (void **slot,
1041 void * unused ATTRIBUTE_UNUSED)
1043 struct elf64_ia64_local_hash_entry *entry
1044 = (struct elf64_ia64_local_hash_entry *) *slot;
1051 entry->sorted_count = 0;
1058 /* Destroy IA-64 linker hash table. */
1061 elf64_ia64_hash_table_free (struct bfd_link_hash_table *hash)
1063 struct elf64_ia64_link_hash_table *ia64_info
1064 = (struct elf64_ia64_link_hash_table *) hash;
1065 if (ia64_info->loc_hash_table)
1067 htab_traverse (ia64_info->loc_hash_table,
1068 elf64_ia64_local_dyn_info_free, NULL);
1069 htab_delete (ia64_info->loc_hash_table);
1071 if (ia64_info->loc_hash_memory)
1072 objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
1073 elf_link_hash_traverse (&ia64_info->root,
1074 elf64_ia64_global_dyn_info_free, NULL);
1075 _bfd_elf_link_hash_table_free (hash);
1078 /* Traverse both local and global hash tables. */
1080 struct elf64_ia64_dyn_sym_traverse_data
1082 bfd_boolean (*func) (struct elf64_ia64_dyn_sym_info *, void *);
1087 elf64_ia64_global_dyn_sym_thunk (struct bfd_hash_entry *xentry,
1090 struct elf64_ia64_link_hash_entry *entry
1091 = (struct elf64_ia64_link_hash_entry *) xentry;
1092 struct elf64_ia64_dyn_sym_traverse_data *data
1093 = (struct elf64_ia64_dyn_sym_traverse_data *) xdata;
1094 struct elf64_ia64_dyn_sym_info *dyn_i;
1097 if (entry->root.root.type == bfd_link_hash_warning)
1098 entry = (struct elf64_ia64_link_hash_entry *) entry->root.root.u.i.link;
1100 for (count = entry->count, dyn_i = entry->info;
1103 if (! (*data->func) (dyn_i, data->data))
1109 elf64_ia64_local_dyn_sym_thunk (void **slot, void * xdata)
1111 struct elf64_ia64_local_hash_entry *entry
1112 = (struct elf64_ia64_local_hash_entry *) *slot;
1113 struct elf64_ia64_dyn_sym_traverse_data *data
1114 = (struct elf64_ia64_dyn_sym_traverse_data *) xdata;
1115 struct elf64_ia64_dyn_sym_info *dyn_i;
1118 for (count = entry->count, dyn_i = entry->info;
1121 if (! (*data->func) (dyn_i, data->data))
1127 elf64_ia64_dyn_sym_traverse (struct elf64_ia64_link_hash_table *ia64_info,
1128 bfd_boolean (*func) (struct elf64_ia64_dyn_sym_info *, void *),
1131 struct elf64_ia64_dyn_sym_traverse_data xdata;
1136 elf_link_hash_traverse (&ia64_info->root,
1137 elf64_ia64_global_dyn_sym_thunk, &xdata);
1138 htab_traverse (ia64_info->loc_hash_table,
1139 elf64_ia64_local_dyn_sym_thunk, &xdata);
1142 #define NOTE_NAME "IPF/VMS"
1145 create_ia64_vms_notes (bfd *abfd, struct bfd_link_info *info,
1146 unsigned int time_hi, unsigned int time_lo)
1149 Elf_Internal_Note notes[NBR_NOTES];
1151 int module_name_len;
1152 unsigned char cur_time[8];
1153 Elf64_External_VMS_ORIG_DYN_Note *orig_dyn;
1154 unsigned int orig_dyn_size;
1155 unsigned int note_size;
1157 unsigned char *noteptr;
1158 unsigned char *note_contents;
1159 struct elf64_ia64_link_hash_table *ia64_info;
1161 ia64_info = elf64_ia64_hash_table (info);
1163 module_name = vms_get_module_name (bfd_get_filename (abfd), TRUE);
1164 module_name_len = strlen (module_name) + 1;
1166 bfd_putl32 (time_lo, cur_time + 0);
1167 bfd_putl32 (time_hi, cur_time + 4);
1169 /* Note 0: IMGNAM. */
1170 notes[0].type = NT_VMS_IMGNAM;
1171 notes[0].descdata = module_name;
1172 notes[0].descsz = module_name_len;
1174 /* Note 1: GSTNAM. */
1175 notes[1].type = NT_VMS_GSTNAM;
1176 notes[1].descdata = module_name;
1177 notes[1].descsz = module_name_len;
1179 /* Note 2: IMGID. */
1180 #define IMG_ID "V1.0"
1181 notes[2].type = NT_VMS_IMGID;
1182 notes[2].descdata = IMG_ID;
1183 notes[2].descsz = sizeof (IMG_ID);
1185 /* Note 3: Linktime. */
1186 notes[3].type = NT_VMS_LINKTIME;
1187 notes[3].descdata = (char *)cur_time;
1188 notes[3].descsz = sizeof (cur_time);
1190 /* Note 4: Linker id. */
1191 notes[4].type = NT_VMS_LINKID;
1192 notes[4].descdata = "GNU ld " BFD_VERSION_STRING;
1193 notes[4].descsz = strlen (notes[4].descdata) + 1;
1195 /* Note 5: Original dyn. */
1196 orig_dyn_size = (sizeof (*orig_dyn) + sizeof (IMG_ID) - 1 + 7) & ~7;
1197 orig_dyn = bfd_zalloc (abfd, orig_dyn_size);
1198 if (orig_dyn == NULL)
1200 bfd_putl32 (1, orig_dyn->major_id);
1201 bfd_putl32 (3, orig_dyn->minor_id);
1202 memcpy (orig_dyn->manipulation_date, cur_time, sizeof (cur_time));
1203 bfd_putl64 (VMS_LF_IMGSTA | VMS_LF_MAIN, orig_dyn->link_flags);
1204 bfd_putl32 (EF_IA_64_ABI64, orig_dyn->elf_flags);
1205 memcpy (orig_dyn->imgid, IMG_ID, sizeof (IMG_ID));
1206 notes[5].type = NT_VMS_ORIG_DYN;
1207 notes[5].descdata = (char *)orig_dyn;
1208 notes[5].descsz = orig_dyn_size;
1210 /* Note 3: Patchtime. */
1211 notes[6].type = NT_VMS_PATCHTIME;
1212 notes[6].descdata = (char *)cur_time;
1213 notes[6].descsz = sizeof (cur_time);
1215 /* Compute notes size. */
1217 for (i = 0; i < NBR_NOTES; i++)
1218 note_size += sizeof (Elf64_External_VMS_Note) - 1
1219 + ((sizeof (NOTE_NAME) - 1 + 7) & ~7)
1220 + ((notes[i].descsz + 7) & ~7);
1222 /* Malloc a temporary buffer large enough for most notes */
1223 note_contents = (unsigned char *) bfd_zalloc (abfd, note_size);
1224 if (note_contents == NULL)
1226 noteptr = note_contents;
1229 for (i = 0; i < NBR_NOTES; i++)
1231 Elf64_External_VMS_Note *enote = (Elf64_External_VMS_Note *) noteptr;
1233 bfd_putl64 (sizeof (NOTE_NAME) - 1, enote->namesz);
1234 bfd_putl64 (notes[i].descsz, enote->descsz);
1235 bfd_putl64 (notes[i].type, enote->type);
1237 noteptr = (unsigned char *)enote->name;
1238 memcpy (noteptr, NOTE_NAME, sizeof (NOTE_NAME) - 1);
1239 noteptr += (sizeof (NOTE_NAME) - 1 + 7) & ~7;
1240 memcpy (noteptr, notes[i].descdata, notes[i].descsz);
1241 noteptr += (notes[i].descsz + 7) & ~7;
1244 ia64_info->note_sec->contents = note_contents;
1245 ia64_info->note_sec->size = note_size;
1253 elf64_ia64_create_dynamic_sections (bfd *abfd,
1254 struct bfd_link_info *info)
1256 struct elf64_ia64_link_hash_table *ia64_info;
1259 const struct elf_backend_data *bed;
1261 ia64_info = elf64_ia64_hash_table (info);
1262 if (ia64_info == NULL)
1265 if (elf_hash_table (info)->dynamic_sections_created)
1268 abfd = elf_hash_table (info)->dynobj;
1269 bed = get_elf_backend_data (abfd);
1271 flags = bed->dynamic_sec_flags;
1273 s = bfd_make_section_anyway_with_flags (abfd, ".dynamic",
1274 flags | SEC_READONLY);
1276 || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
1279 s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags | SEC_READONLY);
1281 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
1283 ia64_info->root.splt = s;
1285 if (!get_got (abfd, ia64_info))
1288 if (!get_pltoff (abfd, ia64_info))
1291 s = bfd_make_section_anyway_with_flags (abfd, ".vmsdynstr",
1295 | SEC_LINKER_CREATED));
1297 || !bfd_set_section_alignment (abfd, s, 0))
1300 /* Create a fixup section. */
1301 s = bfd_make_section_anyway_with_flags (abfd, ".fixups",
1305 | SEC_LINKER_CREATED));
1307 || !bfd_set_section_alignment (abfd, s, 3))
1309 ia64_info->fixups_sec = s;
1311 /* Create the transfer fixup section. */
1312 s = bfd_make_section_anyway_with_flags (abfd, ".transfer",
1316 | SEC_LINKER_CREATED));
1318 || !bfd_set_section_alignment (abfd, s, 3))
1320 s->size = sizeof (struct elf64_vms_transfer);
1321 ia64_info->transfer_sec = s;
1323 /* Create note section. */
1324 s = bfd_make_section_anyway_with_flags (abfd, ".vms.note",
1330 || !bfd_set_section_alignment (abfd, s, 3))
1332 ia64_info->note_sec = s;
1334 elf_hash_table (info)->dynamic_sections_created = TRUE;
1338 /* Find and/or create a hash entry for local symbol. */
1339 static struct elf64_ia64_local_hash_entry *
1340 get_local_sym_hash (struct elf64_ia64_link_hash_table *ia64_info,
1341 bfd *abfd, const Elf_Internal_Rela *rel,
1344 struct elf64_ia64_local_hash_entry e, *ret;
1345 asection *sec = abfd->sections;
1346 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
1347 ELF64_R_SYM (rel->r_info));
1351 e.r_sym = ELF64_R_SYM (rel->r_info);
1352 slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h,
1353 create ? INSERT : NO_INSERT);
1359 return (struct elf64_ia64_local_hash_entry *) *slot;
1361 ret = (struct elf64_ia64_local_hash_entry *)
1362 objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory,
1363 sizeof (struct elf64_ia64_local_hash_entry));
1366 memset (ret, 0, sizeof (*ret));
1368 ret->r_sym = ELF64_R_SYM (rel->r_info);
1374 /* Used to sort elf64_ia64_dyn_sym_info array. */
1377 addend_compare (const void *xp, const void *yp)
1379 const struct elf64_ia64_dyn_sym_info *x
1380 = (const struct elf64_ia64_dyn_sym_info *) xp;
1381 const struct elf64_ia64_dyn_sym_info *y
1382 = (const struct elf64_ia64_dyn_sym_info *) yp;
1384 return x->addend < y->addend ? -1 : x->addend > y->addend ? 1 : 0;
1387 /* Sort elf64_ia64_dyn_sym_info array and remove duplicates. */
1390 sort_dyn_sym_info (struct elf64_ia64_dyn_sym_info *info,
1393 bfd_vma curr, prev, got_offset;
1394 unsigned int i, kept, dupes, diff, dest, src, len;
1396 qsort (info, count, sizeof (*info), addend_compare);
1398 /* Find the first duplicate. */
1399 prev = info [0].addend;
1400 got_offset = info [0].got_offset;
1401 for (i = 1; i < count; i++)
1403 curr = info [i].addend;
1406 /* For duplicates, make sure that GOT_OFFSET is valid. */
1407 if (got_offset == (bfd_vma) -1)
1408 got_offset = info [i].got_offset;
1411 got_offset = info [i].got_offset;
1415 /* We may move a block of elements to here. */
1418 /* Remove duplicates. */
1423 /* For duplicates, make sure that the kept one has a valid
1426 if (got_offset != (bfd_vma) -1)
1427 info [kept].got_offset = got_offset;
1429 curr = info [i].addend;
1430 got_offset = info [i].got_offset;
1432 /* Move a block of elements whose first one is different from
1436 for (src = i + 1; src < count; src++)
1438 if (info [src].addend != curr)
1440 /* For duplicates, make sure that GOT_OFFSET is
1442 if (got_offset == (bfd_vma) -1)
1443 got_offset = info [src].got_offset;
1446 /* Make sure that the kept one has a valid got_offset. */
1447 if (got_offset != (bfd_vma) -1)
1448 info [kept].got_offset = got_offset;
1456 /* Find the next duplicate. SRC will be kept. */
1457 prev = info [src].addend;
1458 got_offset = info [src].got_offset;
1459 for (dupes = src + 1; dupes < count; dupes ++)
1461 curr = info [dupes].addend;
1464 /* Make sure that got_offset is valid. */
1465 if (got_offset == (bfd_vma) -1)
1466 got_offset = info [dupes].got_offset;
1468 /* For duplicates, make sure that the kept one has
1469 a valid got_offset. */
1470 if (got_offset != (bfd_vma) -1)
1471 info [dupes - 1].got_offset = got_offset;
1474 got_offset = info [dupes].got_offset;
1478 /* How much to move. */
1482 if (len == 1 && dupes < count)
1484 /* If we only move 1 element, we combine it with the next
1485 one. There must be at least a duplicate. Find the
1486 next different one. */
1487 for (diff = dupes + 1, src++; diff < count; diff++, src++)
1489 if (info [diff].addend != curr)
1491 /* Make sure that got_offset is valid. */
1492 if (got_offset == (bfd_vma) -1)
1493 got_offset = info [diff].got_offset;
1496 /* Makre sure that the last duplicated one has an valid
1498 BFD_ASSERT (curr == prev);
1499 if (got_offset != (bfd_vma) -1)
1500 info [diff - 1].got_offset = got_offset;
1504 /* Find the next duplicate. Track the current valid
1506 prev = info [diff].addend;
1507 got_offset = info [diff].got_offset;
1508 for (dupes = diff + 1; dupes < count; dupes ++)
1510 curr = info [dupes].addend;
1513 /* For duplicates, make sure that GOT_OFFSET
1515 if (got_offset == (bfd_vma) -1)
1516 got_offset = info [dupes].got_offset;
1519 got_offset = info [dupes].got_offset;
1524 len = diff - src + 1;
1529 memmove (&info [dest], &info [src], len * sizeof (*info));
1538 /* When we get here, either there is no duplicate at all or
1539 the only duplicate is the last element. */
1542 /* If the last element is a duplicate, make sure that the
1543 kept one has a valid got_offset. We also update count. */
1544 if (got_offset != (bfd_vma) -1)
1545 info [dest - 1].got_offset = got_offset;
1553 /* Find and/or create a descriptor for dynamic symbol info. This will
1554 vary based on global or local symbol, and the addend to the reloc.
1556 We don't sort when inserting. Also, we sort and eliminate
1557 duplicates if there is an unsorted section. Typically, this will
1558 only happen once, because we do all insertions before lookups. We
1559 then use bsearch to do a lookup. This also allows lookups to be
1560 fast. So we have fast insertion (O(log N) due to duplicate check),
1561 fast lookup (O(log N)) and one sort (O(N log N) expected time).
1562 Previously, all lookups were O(N) because of the use of the linked
1563 list and also all insertions were O(N) because of the check for
1564 duplicates. There are some complications here because the array
1565 size grows occasionally, which may add an O(N) factor, but this
1566 should be rare. Also, we free the excess array allocation, which
1567 requires a copy which is O(N), but this only happens once. */
1569 static struct elf64_ia64_dyn_sym_info *
1570 get_dyn_sym_info (struct elf64_ia64_link_hash_table *ia64_info,
1571 struct elf_link_hash_entry *h, bfd *abfd,
1572 const Elf_Internal_Rela *rel, bfd_boolean create)
1574 struct elf64_ia64_dyn_sym_info **info_p, *info, *dyn_i, key;
1575 unsigned int *count_p, *sorted_count_p, *size_p;
1576 unsigned int count, sorted_count, size;
1577 bfd_vma addend = rel ? rel->r_addend : 0;
1582 struct elf64_ia64_link_hash_entry *global_h;
1584 global_h = (struct elf64_ia64_link_hash_entry *) h;
1585 info_p = &global_h->info;
1586 count_p = &global_h->count;
1587 sorted_count_p = &global_h->sorted_count;
1588 size_p = &global_h->size;
1592 struct elf64_ia64_local_hash_entry *loc_h;
1594 loc_h = get_local_sym_hash (ia64_info, abfd, rel, create);
1597 BFD_ASSERT (!create);
1601 info_p = &loc_h->info;
1602 count_p = &loc_h->count;
1603 sorted_count_p = &loc_h->sorted_count;
1604 size_p = &loc_h->size;
1608 sorted_count = *sorted_count_p;
1613 /* When we create the array, we don't check for duplicates,
1614 except in the previously sorted section if one exists, and
1615 against the last inserted entry. This allows insertions to
1621 /* Try bsearch first on the sorted section. */
1622 key.addend = addend;
1623 dyn_i = bsearch (&key, info, sorted_count,
1624 sizeof (*info), addend_compare);
1632 /* Do a quick check for the last inserted entry. */
1633 dyn_i = info + count - 1;
1634 if (dyn_i->addend == addend)
1642 /* It is the very first element. We create the array of size
1645 amt = size * sizeof (*info);
1646 info = bfd_malloc (amt);
1648 else if (size <= count)
1650 /* We double the array size every time when we reach the
1653 amt = size * sizeof (*info);
1654 info = bfd_realloc (info, amt);
1665 /* Append the new one to the array. */
1666 dyn_i = info + count;
1667 memset (dyn_i, 0, sizeof (*dyn_i));
1668 dyn_i->got_offset = (bfd_vma) -1;
1669 dyn_i->addend = addend;
1671 /* We increment count only since the new ones are unsorted and
1672 may have duplicate. */
1677 /* It is a lookup without insertion. Sort array if part of the
1678 array isn't sorted. */
1679 if (count != sorted_count)
1681 count = sort_dyn_sym_info (info, count);
1683 *sorted_count_p = count;
1686 /* Free unused memory. */
1689 amt = count * sizeof (*info);
1690 info = bfd_malloc (amt);
1693 memcpy (info, *info_p, amt);
1700 key.addend = addend;
1701 dyn_i = bsearch (&key, info, count,
1702 sizeof (*info), addend_compare);
1709 get_got (bfd *abfd, struct elf64_ia64_link_hash_table *ia64_info)
1714 got = ia64_info->root.sgot;
1719 dynobj = ia64_info->root.dynobj;
1721 ia64_info->root.dynobj = dynobj = abfd;
1723 /* The .got section is always aligned at 8 bytes. */
1724 flags = get_elf_backend_data (dynobj)->dynamic_sec_flags;
1725 got = bfd_make_section_anyway_with_flags (dynobj, ".got",
1726 flags | SEC_SMALL_DATA);
1728 || !bfd_set_section_alignment (dynobj, got, 3))
1730 ia64_info->root.sgot = got;
1736 /* Create function descriptor section (.opd). This section is called .opd
1737 because it contains "official procedure descriptors". The "official"
1738 refers to the fact that these descriptors are used when taking the address
1739 of a procedure, thus ensuring a unique address for each procedure. */
1742 get_fptr (bfd *abfd, struct bfd_link_info *info,
1743 struct elf64_ia64_link_hash_table *ia64_info)
1748 fptr = ia64_info->fptr_sec;
1751 dynobj = ia64_info->root.dynobj;
1753 ia64_info->root.dynobj = dynobj = abfd;
1755 fptr = bfd_make_section_anyway_with_flags (dynobj, ".opd",
1762 | SEC_LINKER_CREATED));
1764 || !bfd_set_section_alignment (dynobj, fptr, 4))
1770 ia64_info->fptr_sec = fptr;
1775 fptr_rel = bfd_make_section_anyway_with_flags (dynobj, ".rela.opd",
1776 (SEC_ALLOC | SEC_LOAD
1779 | SEC_LINKER_CREATED
1781 if (fptr_rel == NULL
1782 || !bfd_set_section_alignment (dynobj, fptr_rel, 3))
1788 ia64_info->rel_fptr_sec = fptr_rel;
1796 get_pltoff (bfd *abfd, struct elf64_ia64_link_hash_table *ia64_info)
1801 pltoff = ia64_info->pltoff_sec;
1804 dynobj = ia64_info->root.dynobj;
1806 ia64_info->root.dynobj = dynobj = abfd;
1808 pltoff = bfd_make_section_anyway_with_flags (dynobj,
1809 ELF_STRING_ia64_pltoff,
1815 | SEC_LINKER_CREATED));
1817 || !bfd_set_section_alignment (dynobj, pltoff, 4))
1823 ia64_info->pltoff_sec = pltoff;
1830 get_reloc_section (bfd *abfd,
1831 struct elf64_ia64_link_hash_table *ia64_info,
1832 asection *sec, bfd_boolean create)
1834 const char *srel_name;
1838 srel_name = (bfd_elf_string_from_elf_section
1839 (abfd, elf_elfheader(abfd)->e_shstrndx,
1840 _bfd_elf_single_rel_hdr (sec)->sh_name));
1841 if (srel_name == NULL)
1844 BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
1845 && strcmp (bfd_get_section_name (abfd, sec),
1847 || (CONST_STRNEQ (srel_name, ".rel")
1848 && strcmp (bfd_get_section_name (abfd, sec),
1849 srel_name+4) == 0));
1851 dynobj = ia64_info->root.dynobj;
1853 ia64_info->root.dynobj = dynobj = abfd;
1855 srel = bfd_get_linker_section (dynobj, srel_name);
1856 if (srel == NULL && create)
1858 srel = bfd_make_section_anyway_with_flags (dynobj, srel_name,
1859 (SEC_ALLOC | SEC_LOAD
1862 | SEC_LINKER_CREATED
1865 || !bfd_set_section_alignment (dynobj, srel, 3))
1873 count_dyn_reloc (bfd *abfd, struct elf64_ia64_dyn_sym_info *dyn_i,
1874 asection *srel, int type)
1876 struct elf64_ia64_dyn_reloc_entry *rent;
1878 for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
1879 if (rent->srel == srel && rent->type == type)
1884 rent = ((struct elf64_ia64_dyn_reloc_entry *)
1885 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)));
1889 rent->next = dyn_i->reloc_entries;
1893 dyn_i->reloc_entries = rent;
1901 elf64_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info,
1903 const Elf_Internal_Rela *relocs)
1905 struct elf64_ia64_link_hash_table *ia64_info;
1906 const Elf_Internal_Rela *relend;
1907 Elf_Internal_Shdr *symtab_hdr;
1908 const Elf_Internal_Rela *rel;
1909 asection *got, *fptr, *srel, *pltoff;
1918 NEED_LTOFF_FPTR = 128
1921 struct elf_link_hash_entry *h;
1922 unsigned long r_symndx;
1923 bfd_boolean maybe_dynamic;
1925 if (info->relocatable)
1928 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1929 ia64_info = elf64_ia64_hash_table (info);
1930 if (ia64_info == NULL)
1933 got = fptr = srel = pltoff = NULL;
1935 relend = relocs + sec->reloc_count;
1937 /* We scan relocations first to create dynamic relocation arrays. We
1938 modified get_dyn_sym_info to allow fast insertion and support fast
1939 lookup in the next loop. */
1940 for (rel = relocs; rel < relend; ++rel)
1942 r_symndx = ELF64_R_SYM (rel->r_info);
1943 if (r_symndx >= symtab_hdr->sh_info)
1945 long indx = r_symndx - symtab_hdr->sh_info;
1946 h = elf_sym_hashes (abfd)[indx];
1947 while (h->root.type == bfd_link_hash_indirect
1948 || h->root.type == bfd_link_hash_warning)
1949 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1954 /* We can only get preliminary data on whether a symbol is
1955 locally or externally defined, as not all of the input files
1956 have yet been processed. Do something with what we know, as
1957 this may help reduce memory usage and processing time later. */
1958 maybe_dynamic = (h && ((!info->executable
1959 && (!SYMBOLIC_BIND (info, h)
1960 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
1962 || h->root.type == bfd_link_hash_defweak));
1965 switch (ELF64_R_TYPE (rel->r_info))
1967 case R_IA64_TPREL64MSB:
1968 case R_IA64_TPREL64LSB:
1969 case R_IA64_LTOFF_TPREL22:
1970 case R_IA64_DTPREL32MSB:
1971 case R_IA64_DTPREL32LSB:
1972 case R_IA64_DTPREL64MSB:
1973 case R_IA64_DTPREL64LSB:
1974 case R_IA64_LTOFF_DTPREL22:
1975 case R_IA64_DTPMOD64MSB:
1976 case R_IA64_DTPMOD64LSB:
1977 case R_IA64_LTOFF_DTPMOD22:
1981 case R_IA64_IPLTMSB:
1982 case R_IA64_IPLTLSB:
1985 case R_IA64_LTOFF_FPTR22:
1986 case R_IA64_LTOFF_FPTR64I:
1987 case R_IA64_LTOFF_FPTR32MSB:
1988 case R_IA64_LTOFF_FPTR32LSB:
1989 case R_IA64_LTOFF_FPTR64MSB:
1990 case R_IA64_LTOFF_FPTR64LSB:
1991 need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
1994 case R_IA64_FPTR64I:
1995 case R_IA64_FPTR32MSB:
1996 case R_IA64_FPTR32LSB:
1997 case R_IA64_FPTR64MSB:
1998 case R_IA64_FPTR64LSB:
1999 if (info->shared || h)
2000 need_entry = NEED_FPTR | NEED_DYNREL;
2002 need_entry = NEED_FPTR;
2005 case R_IA64_LTOFF22:
2006 case R_IA64_LTOFF64I:
2007 need_entry = NEED_GOT;
2010 case R_IA64_LTOFF22X:
2011 need_entry = NEED_GOTX;
2014 case R_IA64_PLTOFF22:
2015 case R_IA64_PLTOFF64I:
2016 case R_IA64_PLTOFF64MSB:
2017 case R_IA64_PLTOFF64LSB:
2018 need_entry = NEED_PLTOFF;
2022 need_entry |= NEED_MIN_PLT;
2026 (*info->callbacks->warning)
2027 (info, _("@pltoff reloc against local symbol"), 0,
2028 abfd, 0, (bfd_vma) 0);
2032 case R_IA64_PCREL21B:
2033 case R_IA64_PCREL60B:
2034 /* Depending on where this symbol is defined, we may or may not
2035 need a full plt entry. Only skip if we know we'll not need
2036 the entry -- static or symbolic, and the symbol definition
2037 has already been seen. */
2038 if (maybe_dynamic && rel->r_addend == 0)
2039 need_entry = NEED_FULL_PLT;
2045 case R_IA64_DIR32MSB:
2046 case R_IA64_DIR32LSB:
2047 case R_IA64_DIR64MSB:
2048 case R_IA64_DIR64LSB:
2049 /* Shared objects will always need at least a REL relocation. */
2050 if (info->shared || maybe_dynamic)
2051 need_entry = NEED_DYNREL;
2054 case R_IA64_PCREL22:
2055 case R_IA64_PCREL64I:
2056 case R_IA64_PCREL32MSB:
2057 case R_IA64_PCREL32LSB:
2058 case R_IA64_PCREL64MSB:
2059 case R_IA64_PCREL64LSB:
2061 need_entry = NEED_DYNREL;
2068 if ((need_entry & NEED_FPTR) != 0
2071 (*info->callbacks->warning)
2072 (info, _("non-zero addend in @fptr reloc"), 0,
2073 abfd, 0, (bfd_vma) 0);
2076 if (get_dyn_sym_info (ia64_info, h, abfd, rel, TRUE) == NULL)
2080 /* Now, we only do lookup without insertion, which is very fast
2081 with the modified get_dyn_sym_info. */
2082 for (rel = relocs; rel < relend; ++rel)
2084 struct elf64_ia64_dyn_sym_info *dyn_i;
2085 int dynrel_type = R_IA64_NONE;
2087 r_symndx = ELF64_R_SYM (rel->r_info);
2088 if (r_symndx >= symtab_hdr->sh_info)
2090 /* We're dealing with a global symbol -- find its hash entry
2091 and mark it as being referenced. */
2092 long indx = r_symndx - symtab_hdr->sh_info;
2093 h = elf_sym_hashes (abfd)[indx];
2094 while (h->root.type == bfd_link_hash_indirect
2095 || h->root.type == bfd_link_hash_warning)
2096 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2103 /* We can only get preliminary data on whether a symbol is
2104 locally or externally defined, as not all of the input files
2105 have yet been processed. Do something with what we know, as
2106 this may help reduce memory usage and processing time later. */
2107 maybe_dynamic = (h && ((!info->executable
2108 && (!SYMBOLIC_BIND (info, h)
2109 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
2111 || h->root.type == bfd_link_hash_defweak));
2114 switch (ELF64_R_TYPE (rel->r_info))
2116 case R_IA64_TPREL64MSB:
2117 case R_IA64_TPREL64LSB:
2118 case R_IA64_LTOFF_TPREL22:
2119 case R_IA64_DTPREL32MSB:
2120 case R_IA64_DTPREL32LSB:
2121 case R_IA64_DTPREL64MSB:
2122 case R_IA64_DTPREL64LSB:
2123 case R_IA64_LTOFF_DTPREL22:
2124 case R_IA64_DTPMOD64MSB:
2125 case R_IA64_DTPMOD64LSB:
2126 case R_IA64_LTOFF_DTPMOD22:
2130 case R_IA64_LTOFF_FPTR22:
2131 case R_IA64_LTOFF_FPTR64I:
2132 case R_IA64_LTOFF_FPTR32MSB:
2133 case R_IA64_LTOFF_FPTR32LSB:
2134 case R_IA64_LTOFF_FPTR64MSB:
2135 case R_IA64_LTOFF_FPTR64LSB:
2136 need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
2139 case R_IA64_FPTR64I:
2140 case R_IA64_FPTR32MSB:
2141 case R_IA64_FPTR32LSB:
2142 case R_IA64_FPTR64MSB:
2143 case R_IA64_FPTR64LSB:
2144 if (info->shared || h)
2145 need_entry = NEED_FPTR | NEED_DYNREL;
2147 need_entry = NEED_FPTR;
2148 dynrel_type = R_IA64_FPTR64LSB;
2151 case R_IA64_LTOFF22:
2152 case R_IA64_LTOFF64I:
2153 need_entry = NEED_GOT;
2156 case R_IA64_LTOFF22X:
2157 need_entry = NEED_GOTX;
2160 case R_IA64_PLTOFF22:
2161 case R_IA64_PLTOFF64I:
2162 case R_IA64_PLTOFF64MSB:
2163 case R_IA64_PLTOFF64LSB:
2164 need_entry = NEED_PLTOFF;
2168 need_entry |= NEED_MIN_PLT;
2172 case R_IA64_PCREL21B:
2173 case R_IA64_PCREL60B:
2174 /* Depending on where this symbol is defined, we may or may not
2175 need a full plt entry. Only skip if we know we'll not need
2176 the entry -- static or symbolic, and the symbol definition
2177 has already been seen. */
2178 if (maybe_dynamic && rel->r_addend == 0)
2179 need_entry = NEED_FULL_PLT;
2185 case R_IA64_DIR32MSB:
2186 case R_IA64_DIR32LSB:
2187 case R_IA64_DIR64MSB:
2188 case R_IA64_DIR64LSB:
2189 /* Shared objects will always need at least a REL relocation. */
2190 if (info->shared || maybe_dynamic)
2191 need_entry = NEED_DYNREL;
2192 dynrel_type = R_IA64_DIR64LSB;
2195 case R_IA64_IPLTMSB:
2196 case R_IA64_IPLTLSB:
2199 case R_IA64_PCREL22:
2200 case R_IA64_PCREL64I:
2201 case R_IA64_PCREL32MSB:
2202 case R_IA64_PCREL32LSB:
2203 case R_IA64_PCREL64MSB:
2204 case R_IA64_PCREL64LSB:
2206 need_entry = NEED_DYNREL;
2207 dynrel_type = R_IA64_PCREL64LSB;
2214 dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, FALSE);
2216 /* Record whether or not this is a local symbol. */
2219 /* Create what's needed. */
2220 if (need_entry & (NEED_GOT | NEED_GOTX))
2224 got = get_got (abfd, ia64_info);
2228 if (need_entry & NEED_GOT)
2229 dyn_i->want_got = 1;
2230 if (need_entry & NEED_GOTX)
2231 dyn_i->want_gotx = 1;
2233 if (need_entry & NEED_FPTR)
2235 /* Create the .opd section. */
2238 fptr = get_fptr (abfd, info, ia64_info);
2242 dyn_i->want_fptr = 1;
2244 if (need_entry & NEED_LTOFF_FPTR)
2245 dyn_i->want_ltoff_fptr = 1;
2246 if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT))
2248 if (!ia64_info->root.dynobj)
2249 ia64_info->root.dynobj = abfd;
2251 dyn_i->want_plt = 1;
2253 if (need_entry & NEED_FULL_PLT)
2254 dyn_i->want_plt2 = 1;
2255 if (need_entry & NEED_PLTOFF)
2257 /* This is needed here, in case @pltoff is used in a non-shared
2261 pltoff = get_pltoff (abfd, ia64_info);
2266 dyn_i->want_pltoff = 1;
2268 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
2272 srel = get_reloc_section (abfd, ia64_info, sec, TRUE);
2276 if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type))
2284 /* For cleanliness, and potentially faster dynamic loading, allocate
2285 external GOT entries first. */
2288 allocate_global_data_got (struct elf64_ia64_dyn_sym_info *dyn_i,
2291 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
2293 if ((dyn_i->want_got || dyn_i->want_gotx)
2294 && ! dyn_i->want_fptr
2295 && elf64_ia64_dynamic_symbol_p (dyn_i->h))
2297 /* GOT entry with FPTR is done by allocate_global_fptr_got. */
2298 dyn_i->got_offset = x->ofs;
2304 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2307 allocate_global_fptr_got (struct elf64_ia64_dyn_sym_info *dyn_i,
2310 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
2314 && elf64_ia64_dynamic_symbol_p (dyn_i->h))
2316 dyn_i->got_offset = x->ofs;
2322 /* Lastly, allocate all the GOT entries for local data. */
2325 allocate_local_got (struct elf64_ia64_dyn_sym_info *dyn_i,
2328 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *) data;
2330 if ((dyn_i->want_got || dyn_i->want_gotx)
2331 && !elf64_ia64_dynamic_symbol_p (dyn_i->h))
2333 dyn_i->got_offset = x->ofs;
2339 /* Allocate function descriptors. We can do these for every function
2340 in a main executable that is not exported. */
2343 allocate_fptr (struct elf64_ia64_dyn_sym_info *dyn_i, void * data)
2345 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *) data;
2347 if (dyn_i->want_fptr)
2349 struct elf_link_hash_entry *h = dyn_i->h;
2352 while (h->root.type == bfd_link_hash_indirect
2353 || h->root.type == bfd_link_hash_warning)
2354 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2356 if (h == NULL || !h->def_dynamic)
2358 /* A non dynamic symbol. */
2359 dyn_i->fptr_offset = x->ofs;
2363 dyn_i->want_fptr = 0;
2368 /* Allocate all the minimal PLT entries. */
2371 allocate_plt_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
2372 void * data ATTRIBUTE_UNUSED)
2374 if (dyn_i->want_plt)
2376 struct elf_link_hash_entry *h = dyn_i->h;
2379 while (h->root.type == bfd_link_hash_indirect
2380 || h->root.type == bfd_link_hash_warning)
2381 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2383 /* ??? Versioned symbols seem to lose NEEDS_PLT. */
2384 if (elf64_ia64_dynamic_symbol_p (h))
2386 dyn_i->want_pltoff = 1;
2390 dyn_i->want_plt = 0;
2391 dyn_i->want_plt2 = 0;
2397 /* Allocate all the full PLT entries. */
2400 allocate_plt2_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
2403 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
2405 if (dyn_i->want_plt2)
2407 struct elf_link_hash_entry *h = dyn_i->h;
2408 bfd_size_type ofs = x->ofs;
2410 dyn_i->plt2_offset = ofs;
2411 x->ofs = ofs + PLT_FULL_ENTRY_SIZE;
2413 while (h->root.type == bfd_link_hash_indirect
2414 || h->root.type == bfd_link_hash_warning)
2415 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2416 dyn_i->h->plt.offset = ofs;
2421 /* Allocate all the PLTOFF entries requested by relocations and
2422 plt entries. We can't share space with allocated FPTR entries,
2423 because the latter are not necessarily addressable by the GP.
2424 ??? Relaxation might be able to determine that they are. */
2427 allocate_pltoff_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
2430 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
2432 if (dyn_i->want_pltoff)
2434 dyn_i->pltoff_offset = x->ofs;
2440 /* Allocate dynamic relocations for those symbols that turned out
2444 allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info *dyn_i,
2447 struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data;
2448 struct elf64_ia64_link_hash_table *ia64_info;
2449 struct elf64_ia64_dyn_reloc_entry *rent;
2450 bfd_boolean dynamic_symbol, shared, resolved_zero;
2451 struct elf64_ia64_link_hash_entry *h_ia64;
2453 ia64_info = elf64_ia64_hash_table (x->info);
2454 if (ia64_info == NULL)
2457 /* Note that this can't be used in relation to FPTR relocs below. */
2458 dynamic_symbol = elf64_ia64_dynamic_symbol_p (dyn_i->h);
2460 shared = x->info->shared;
2461 resolved_zero = (dyn_i->h
2462 && ELF_ST_VISIBILITY (dyn_i->h->other)
2463 && dyn_i->h->root.type == bfd_link_hash_undefweak);
2465 /* Take care of the GOT and PLT relocations. */
2468 && (dynamic_symbol || shared)
2469 && (dyn_i->want_got || dyn_i->want_gotx))
2470 || (dyn_i->want_ltoff_fptr
2472 && dyn_i->h->def_dynamic))
2475 if (dyn_i->h != NULL && dyn_i->h->def_dynamic)
2477 h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h;
2478 elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
2479 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2480 ia64_info->fixups_sec->size +=
2481 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2485 if (ia64_info->rel_fptr_sec && dyn_i->want_fptr)
2487 /* VMS: only image reloc. */
2488 if (dyn_i->h == NULL || dyn_i->h->root.type != bfd_link_hash_undefweak)
2489 ia64_info->rel_fptr_sec->size += sizeof (Elf64_External_Rela);
2492 if (!resolved_zero && dyn_i->want_pltoff)
2495 if (dyn_i->h != NULL && dyn_i->h->def_dynamic)
2497 h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h;
2498 elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
2499 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2500 ia64_info->fixups_sec->size +=
2501 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2505 /* Take care of the normal data relocations. */
2507 for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
2509 int count = rent->count;
2513 case R_IA64_FPTR32LSB:
2514 case R_IA64_FPTR64LSB:
2515 /* Allocate one iff !want_fptr and not PIE, which by this point
2516 will be true only if we're actually allocating one statically
2517 in the main executable. Position independent executables
2518 need a relative reloc. */
2519 if (dyn_i->want_fptr && !x->info->pie)
2522 case R_IA64_PCREL32LSB:
2523 case R_IA64_PCREL64LSB:
2524 if (!dynamic_symbol)
2527 case R_IA64_DIR32LSB:
2528 case R_IA64_DIR64LSB:
2529 if (!dynamic_symbol && !shared)
2532 case R_IA64_IPLTLSB:
2533 if (!dynamic_symbol && !shared)
2535 /* Use two REL relocations for IPLT relocations
2536 against local symbols. */
2537 if (!dynamic_symbol)
2540 case R_IA64_DTPREL32LSB:
2541 case R_IA64_TPREL64LSB:
2542 case R_IA64_DTPREL64LSB:
2543 case R_IA64_DTPMOD64LSB:
2550 if (!dynamic_symbol)
2553 h_ia64 = (struct elf64_ia64_link_hash_entry *) dyn_i->h;
2554 elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
2555 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2556 ia64_info->fixups_sec->size +=
2557 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2564 elf64_ia64_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2565 struct elf_link_hash_entry *h)
2567 /* ??? Undefined symbols with PLT entries should be re-defined
2568 to be the PLT entry. */
2570 /* If this is a weak symbol, and there is a real definition, the
2571 processor independent code will have arranged for us to see the
2572 real definition first, and we can just use the same value. */
2573 if (h->u.weakdef != NULL)
2575 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2576 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2577 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2578 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2582 /* If this is a reference to a symbol defined by a dynamic object which
2583 is not a function, we might allocate the symbol in our .dynbss section
2584 and allocate a COPY dynamic relocation.
2586 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
2593 elf64_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2594 struct bfd_link_info *info)
2596 struct elf64_ia64_allocate_data data;
2597 struct elf64_ia64_link_hash_table *ia64_info;
2600 struct elf_link_hash_table *hash_table;
2602 hash_table = elf_hash_table (info);
2603 dynobj = hash_table->dynobj;
2604 ia64_info = elf64_ia64_hash_table (info);
2605 if (ia64_info == NULL)
2607 BFD_ASSERT(dynobj != NULL);
2610 /* Allocate the GOT entries. */
2612 if (ia64_info->root.sgot)
2615 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data);
2616 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data);
2617 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data);
2618 ia64_info->root.sgot->size = data.ofs;
2621 /* Allocate the FPTR entries. */
2623 if (ia64_info->fptr_sec)
2626 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data);
2627 ia64_info->fptr_sec->size = data.ofs;
2630 /* Now that we've seen all of the input files, we can decide which
2631 symbols need plt entries. Allocate the minimal PLT entries first.
2632 We do this even though dynamic_sections_created may be FALSE, because
2633 this has the side-effect of clearing want_plt and want_plt2. */
2636 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data);
2638 /* Align the pointer for the plt2 entries. */
2639 data.ofs = (data.ofs + 31) & (bfd_vma) -32;
2641 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
2642 if (data.ofs != 0 || ia64_info->root.dynamic_sections_created)
2644 /* FIXME: we always reserve the memory for dynamic linker even if
2645 there are no PLT entries since dynamic linker may assume the
2646 reserved memory always exists. */
2648 BFD_ASSERT (ia64_info->root.dynamic_sections_created);
2650 ia64_info->root.splt->size = data.ofs;
2653 /* Allocate the PLTOFF entries. */
2655 if (ia64_info->pltoff_sec)
2658 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data);
2659 ia64_info->pltoff_sec->size = data.ofs;
2662 if (ia64_info->root.dynamic_sections_created)
2664 /* Allocate space for the dynamic relocations that turned out to be
2666 elf64_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data);
2669 /* We have now determined the sizes of the various dynamic sections.
2670 Allocate memory for them. */
2671 for (sec = dynobj->sections; sec != NULL; sec = sec->next)
2675 if (!(sec->flags & SEC_LINKER_CREATED))
2678 /* If we don't need this section, strip it from the output file.
2679 There were several sections primarily related to dynamic
2680 linking that must be create before the linker maps input
2681 sections to output sections. The linker does that before
2682 bfd_elf_size_dynamic_sections is called, and it is that
2683 function which decides whether anything needs to go into
2686 strip = (sec->size == 0);
2688 if (sec == ia64_info->root.sgot)
2690 else if (sec == ia64_info->root.srelgot)
2693 ia64_info->root.srelgot = NULL;
2695 /* We use the reloc_count field as a counter if we need to
2696 copy relocs into the output file. */
2697 sec->reloc_count = 0;
2699 else if (sec == ia64_info->fptr_sec)
2702 ia64_info->fptr_sec = NULL;
2704 else if (sec == ia64_info->rel_fptr_sec)
2707 ia64_info->rel_fptr_sec = NULL;
2709 /* We use the reloc_count field as a counter if we need to
2710 copy relocs into the output file. */
2711 sec->reloc_count = 0;
2713 else if (sec == ia64_info->root.splt)
2716 ia64_info->root.splt = NULL;
2718 else if (sec == ia64_info->pltoff_sec)
2721 ia64_info->pltoff_sec = NULL;
2723 else if (sec == ia64_info->fixups_sec)
2726 ia64_info->fixups_sec = NULL;
2728 else if (sec == ia64_info->transfer_sec)
2736 /* It's OK to base decisions on the section name, because none
2737 of the dynobj section names depend upon the input files. */
2738 name = bfd_get_section_name (dynobj, sec);
2740 if (strcmp (name, ".got.plt") == 0)
2742 else if (CONST_STRNEQ (name, ".rel"))
2746 /* We use the reloc_count field as a counter if we need to
2747 copy relocs into the output file. */
2748 sec->reloc_count = 0;
2756 sec->flags |= SEC_EXCLUDE;
2759 /* Allocate memory for the section contents. */
2760 sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
2761 if (sec->contents == NULL && sec->size != 0)
2766 if (elf_hash_table (info)->dynamic_sections_created)
2770 asection *dynstrsec;
2771 Elf_Internal_Dyn dyn;
2772 const struct elf_backend_data *bed;
2773 unsigned int shl_num = 0;
2774 bfd_vma fixups_off = 0;
2776 unsigned int time_hi, time_lo;
2778 /* The .dynamic section must exist and be empty. */
2779 dynsec = bfd_get_linker_section (hash_table->dynobj, ".dynamic");
2780 BFD_ASSERT (dynsec != NULL);
2781 BFD_ASSERT (dynsec->size == 0);
2783 dynstrsec = bfd_get_linker_section (hash_table->dynobj, ".vmsdynstr");
2784 BFD_ASSERT (dynstrsec != NULL);
2785 BFD_ASSERT (dynstrsec->size == 0);
2786 dynstrsec->size = 1; /* Initial blank. */
2788 /* Ident + link time. */
2789 vms_get_time (&time_hi, &time_lo);
2791 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_IDENT, 0))
2793 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LINKTIME,
2794 (((bfd_uint64_t)time_hi) << 32)
2799 strdyn_off = dynsec->size;
2800 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_STRTAB_OFFSET, 0))
2802 if (!_bfd_elf_add_dynamic_entry (info, DT_STRSZ, 0))
2806 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_PLTGOT_SEG, 0))
2808 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_PLTGOT_OFFSET, 0))
2812 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FPMODE, 0x9800000))
2814 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LNKFLAGS,
2815 VMS_LF_IMGSTA | VMS_LF_MAIN))
2818 /* Add entries for shared libraries. */
2819 for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
2823 bfd_size_type strindex;
2824 bfd_byte *newcontents;
2825 bfd_vma fixups_shl_off;
2827 if (!(abfd->flags & DYNAMIC))
2829 BFD_ASSERT (abfd->xvec == output_bfd->xvec);
2831 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_NEEDED_IDENT,
2832 elf_ia64_vms_ident (abfd)))
2835 soname = vms_get_module_name (abfd->filename, TRUE);
2838 strindex = dynstrsec->size;
2839 soname_len = strlen (soname) + 1;
2840 newcontents = (bfd_byte *) bfd_realloc (dynstrsec->contents,
2841 strindex + soname_len);
2842 if (newcontents == NULL)
2844 memcpy (newcontents + strindex, soname, soname_len);
2845 dynstrsec->size += soname_len;
2846 dynstrsec->contents = newcontents;
2848 if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex))
2851 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FIXUP_NEEDED,
2856 /* The fixups_off was in fact containing the size of the fixup
2857 section. Remap into the offset. */
2858 fixups_shl_off = elf_ia64_vms_tdata (abfd)->fixups_off;
2859 elf_ia64_vms_tdata (abfd)->fixups_off = fixups_off;
2861 if (!_bfd_elf_add_dynamic_entry
2862 (info, DT_IA_64_VMS_FIXUP_RELA_CNT,
2863 fixups_shl_off / sizeof (Elf64_External_VMS_IMAGE_FIXUP)))
2865 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_FIXUP_RELA_OFF,
2868 fixups_off += fixups_shl_off;
2872 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWINDSZ, 0))
2874 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_CODSEG, 0))
2876 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_INFOSEG, 0))
2878 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_OFFSET, 0))
2880 if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_UNWIND_SEG, 0))
2883 if (!_bfd_elf_add_dynamic_entry (info, DT_NULL, 0xdead))
2886 /* Fix the strtab entries. */
2887 bed = get_elf_backend_data (hash_table->dynobj);
2889 if (dynstrsec->size > 1)
2890 dynstrsec->contents[0] = 0;
2892 dynstrsec->size = 0;
2894 /* Note: one 'spare' (ie DT_NULL) entry is added by
2895 bfd_elf_size_dynsym_hash_dynstr. */
2896 dyn.d_tag = DT_IA_64_VMS_STRTAB_OFFSET;
2897 dyn.d_un.d_val = dynsec->size /* + sizeof (Elf64_External_Dyn) */;
2898 bed->s->swap_dyn_out (hash_table->dynobj, &dyn,
2899 dynsec->contents + strdyn_off);
2901 dyn.d_tag = DT_STRSZ;
2902 dyn.d_un.d_val = dynstrsec->size;
2903 bed->s->swap_dyn_out (hash_table->dynobj, &dyn,
2904 dynsec->contents + strdyn_off + bed->s->sizeof_dyn);
2906 elf_ia64_vms_tdata (output_bfd)->needed_count = shl_num;
2909 if (!create_ia64_vms_notes (output_bfd, info, time_hi, time_lo))
2913 /* ??? Perhaps force __gp local. */
2919 elf64_ia64_install_fixup (bfd *output_bfd,
2920 struct elf64_ia64_link_hash_table *ia64_info,
2921 struct elf_link_hash_entry *h,
2922 unsigned int type, asection *sec, bfd_vma offset,
2926 Elf64_External_VMS_IMAGE_FIXUP *fixup;
2927 struct elf64_ia64_link_hash_entry *h_ia64;
2929 Elf_Internal_Phdr *phdr;
2931 if (h == NULL || !h->def_dynamic)
2934 h_ia64 = (struct elf64_ia64_link_hash_entry *) h;
2935 fixoff = elf_ia64_vms_tdata (h_ia64->shl)->fixups_off;
2936 elf_ia64_vms_tdata (h_ia64->shl)->fixups_off +=
2937 sizeof (Elf64_External_VMS_IMAGE_FIXUP);
2938 relsec = ia64_info->fixups_sec;
2940 fixup = (Elf64_External_VMS_IMAGE_FIXUP *)(relsec->contents + fixoff);
2941 offset += sec->output_section->vma + sec->output_offset;
2943 /* FIXME: this is slow. We should cache the last one used, or create a
2945 phdr = _bfd_elf_find_segment_containing_section
2946 (output_bfd, sec->output_section);
2947 BFD_ASSERT (phdr != NULL);
2949 bfd_putl64 (offset - phdr->p_vaddr, fixup->fixup_offset);
2950 bfd_putl32 (type, fixup->type);
2951 bfd_putl32 (phdr - elf_tdata (output_bfd)->phdr, fixup->fixup_seg);
2952 bfd_putl64 (addend, fixup->addend);
2953 bfd_putl32 (h->root.u.def.value, fixup->symvec_index);
2954 bfd_putl32 (2, fixup->data_type);
2957 /* Store an entry for target address TARGET_ADDR in the linkage table
2958 and return the gp-relative address of the linkage table entry. */
2961 set_got_entry (bfd *abfd, struct bfd_link_info *info,
2962 struct elf64_ia64_dyn_sym_info *dyn_i,
2963 bfd_vma addend, bfd_vma value, unsigned int dyn_r_type)
2965 struct elf64_ia64_link_hash_table *ia64_info;
2970 ia64_info = elf64_ia64_hash_table (info);
2971 if (ia64_info == NULL)
2974 got_sec = ia64_info->root.sgot;
2978 case R_IA64_TPREL64LSB:
2979 case R_IA64_DTPMOD64LSB:
2980 case R_IA64_DTPREL32LSB:
2981 case R_IA64_DTPREL64LSB:
2985 done = dyn_i->got_done;
2986 dyn_i->got_done = TRUE;
2987 got_offset = dyn_i->got_offset;
2991 BFD_ASSERT ((got_offset & 7) == 0);
2995 /* Store the target address in the linkage table entry. */
2996 bfd_put_64 (abfd, value, got_sec->contents + got_offset);
2998 /* Install a dynamic relocation if needed. */
3001 || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
3002 || dyn_i->h->root.type != bfd_link_hash_undefweak))
3003 || elf64_ia64_dynamic_symbol_p (dyn_i->h))
3004 && (!dyn_i->want_ltoff_fptr
3007 || dyn_i->h->root.type != bfd_link_hash_undefweak))
3009 if (!dyn_i->h || !dyn_i->h->def_dynamic)
3011 dyn_r_type = R_IA64_REL64LSB;
3015 /* VMS: install a FIX32 or FIX64. */
3018 case R_IA64_DIR32LSB:
3019 case R_IA64_FPTR32LSB:
3020 dyn_r_type = R_IA64_VMS_FIX32;
3022 case R_IA64_DIR64LSB:
3023 case R_IA64_FPTR64LSB:
3024 dyn_r_type = R_IA64_VMS_FIX64;
3030 elf64_ia64_install_fixup
3031 (info->output_bfd, ia64_info, dyn_i->h,
3032 dyn_r_type, got_sec, got_offset, addend);
3036 /* Return the address of the linkage table entry. */
3037 value = (got_sec->output_section->vma
3038 + got_sec->output_offset
3044 /* Fill in a function descriptor consisting of the function's code
3045 address and its global pointer. Return the descriptor's address. */
3048 set_fptr_entry (bfd *abfd, struct bfd_link_info *info,
3049 struct elf64_ia64_dyn_sym_info *dyn_i,
3052 struct elf64_ia64_link_hash_table *ia64_info;
3055 ia64_info = elf64_ia64_hash_table (info);
3056 if (ia64_info == NULL)
3059 fptr_sec = ia64_info->fptr_sec;
3061 if (!dyn_i->fptr_done)
3063 dyn_i->fptr_done = 1;
3065 /* Fill in the function descriptor. */
3066 bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset);
3067 bfd_put_64 (abfd, _bfd_get_gp_value (abfd),
3068 fptr_sec->contents + dyn_i->fptr_offset + 8);
3071 /* Return the descriptor's address. */
3072 value = (fptr_sec->output_section->vma
3073 + fptr_sec->output_offset
3074 + dyn_i->fptr_offset);
3079 /* Fill in a PLTOFF entry consisting of the function's code address
3080 and its global pointer. Return the descriptor's address. */
3083 set_pltoff_entry (bfd *abfd, struct bfd_link_info *info,
3084 struct elf64_ia64_dyn_sym_info *dyn_i,
3085 bfd_vma value, bfd_boolean is_plt)
3087 struct elf64_ia64_link_hash_table *ia64_info;
3088 asection *pltoff_sec;
3090 ia64_info = elf64_ia64_hash_table (info);
3091 if (ia64_info == NULL)
3094 pltoff_sec = ia64_info->pltoff_sec;
3096 /* Don't do anything if this symbol uses a real PLT entry. In
3097 that case, we'll fill this in during finish_dynamic_symbol. */
3098 if ((! dyn_i->want_plt || is_plt)
3099 && !dyn_i->pltoff_done)
3101 bfd_vma gp = _bfd_get_gp_value (abfd);
3103 /* Fill in the function descriptor. */
3104 bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset);
3105 bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
3107 /* Install dynamic relocations if needed. */
3111 || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
3112 || dyn_i->h->root.type != bfd_link_hash_undefweak))
3118 dyn_i->pltoff_done = 1;
3121 /* Return the descriptor's address. */
3122 value = (pltoff_sec->output_section->vma
3123 + pltoff_sec->output_offset
3124 + dyn_i->pltoff_offset);
3129 /* Called through qsort to sort the .IA_64.unwind section during a
3130 non-relocatable link. Set elf64_ia64_unwind_entry_compare_bfd
3131 to the output bfd so we can do proper endianness frobbing. */
3133 static bfd *elf64_ia64_unwind_entry_compare_bfd;
3136 elf64_ia64_unwind_entry_compare (const void * a, const void * b)
3140 av = bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd, a);
3141 bv = bfd_get_64 (elf64_ia64_unwind_entry_compare_bfd, b);
3143 return (av < bv ? -1 : av > bv ? 1 : 0);
3146 /* Make sure we've got ourselves a nice fat __gp value. */
3148 elf64_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info, bfd_boolean final)
3150 bfd_vma min_vma = (bfd_vma) -1, max_vma = 0;
3151 bfd_vma min_short_vma = min_vma, max_short_vma = 0;
3152 struct elf_link_hash_entry *gp;
3155 struct elf64_ia64_link_hash_table *ia64_info;
3157 ia64_info = elf64_ia64_hash_table (info);
3158 if (ia64_info == NULL)
3161 /* Find the min and max vma of all sections marked short. Also collect
3162 min and max vma of any type, for use in selecting a nice gp. */
3163 for (os = abfd->sections; os ; os = os->next)
3167 if ((os->flags & SEC_ALLOC) == 0)
3171 /* When this function is called from elfNN_ia64_final_link
3172 the correct value to use is os->size. When called from
3173 elfNN_ia64_relax_section we are in the middle of section
3174 sizing; some sections will already have os->size set, others
3175 will have os->size zero and os->rawsize the previous size. */
3176 hi = os->vma + (!final && os->rawsize ? os->rawsize : os->size);
3184 if (os->flags & SEC_SMALL_DATA)
3186 if (min_short_vma > lo)
3188 if (max_short_vma < hi)
3193 if (ia64_info->min_short_sec)
3196 > (ia64_info->min_short_sec->vma
3197 + ia64_info->min_short_offset))
3198 min_short_vma = (ia64_info->min_short_sec->vma
3199 + ia64_info->min_short_offset);
3201 < (ia64_info->max_short_sec->vma
3202 + ia64_info->max_short_offset))
3203 max_short_vma = (ia64_info->max_short_sec->vma
3204 + ia64_info->max_short_offset);
3207 /* See if the user wants to force a value. */
3208 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
3212 && (gp->root.type == bfd_link_hash_defined
3213 || gp->root.type == bfd_link_hash_defweak))
3215 asection *gp_sec = gp->root.u.def.section;
3216 gp_val = (gp->root.u.def.value
3217 + gp_sec->output_section->vma
3218 + gp_sec->output_offset);
3222 /* Pick a sensible value. */
3224 if (ia64_info->min_short_sec)
3226 bfd_vma short_range = max_short_vma - min_short_vma;
3228 /* If min_short_sec is set, pick one in the middle bewteen
3229 min_short_vma and max_short_vma. */
3230 if (short_range >= 0x400000)
3232 gp_val = min_short_vma + short_range / 2;
3236 asection *got_sec = ia64_info->root.sgot;
3238 /* Start with just the address of the .got. */
3240 gp_val = got_sec->output_section->vma;
3241 else if (max_short_vma != 0)
3242 gp_val = min_short_vma;
3243 else if (max_vma - min_vma < 0x200000)
3246 gp_val = max_vma - 0x200000 + 8;
3249 /* If it is possible to address the entire image, but we
3250 don't with the choice above, adjust. */
3251 if (max_vma - min_vma < 0x400000
3252 && (max_vma - gp_val >= 0x200000
3253 || gp_val - min_vma > 0x200000))
3254 gp_val = min_vma + 0x200000;
3255 else if (max_short_vma != 0)
3257 /* If we don't cover all the short data, adjust. */
3258 if (max_short_vma - gp_val >= 0x200000)
3259 gp_val = min_short_vma + 0x200000;
3261 /* If we're addressing stuff past the end, adjust back. */
3262 if (gp_val > max_vma)
3263 gp_val = max_vma - 0x200000 + 8;
3267 /* Validate whether all SHF_IA_64_SHORT sections are within
3268 range of the chosen GP. */
3270 if (max_short_vma != 0)
3272 if (max_short_vma - min_short_vma >= 0x400000)
3275 (*_bfd_error_handler)
3276 (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
3277 bfd_get_filename (abfd),
3278 (unsigned long) (max_short_vma - min_short_vma));
3281 else if ((gp_val > min_short_vma
3282 && gp_val - min_short_vma > 0x200000)
3283 || (gp_val < max_short_vma
3284 && max_short_vma - gp_val >= 0x200000))
3286 (*_bfd_error_handler)
3287 (_("%s: __gp does not cover short data segment"),
3288 bfd_get_filename (abfd));
3293 _bfd_set_gp_value (abfd, gp_val);
3299 elf64_ia64_final_link (bfd *abfd, struct bfd_link_info *info)
3301 struct elf64_ia64_link_hash_table *ia64_info;
3302 asection *unwind_output_sec;
3304 ia64_info = elf64_ia64_hash_table (info);
3305 if (ia64_info == NULL)
3308 /* Make sure we've got ourselves a nice fat __gp value. */
3309 if (!info->relocatable)
3312 struct elf_link_hash_entry *gp;
3314 /* We assume after gp is set, section size will only decrease. We
3315 need to adjust gp for it. */
3316 _bfd_set_gp_value (abfd, 0);
3317 if (! elf64_ia64_choose_gp (abfd, info, TRUE))
3319 gp_val = _bfd_get_gp_value (abfd);
3321 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
3325 gp->root.type = bfd_link_hash_defined;
3326 gp->root.u.def.value = gp_val;
3327 gp->root.u.def.section = bfd_abs_section_ptr;
3331 /* If we're producing a final executable, we need to sort the contents
3332 of the .IA_64.unwind section. Force this section to be relocated
3333 into memory rather than written immediately to the output file. */
3334 unwind_output_sec = NULL;
3335 if (!info->relocatable)
3337 asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
3340 unwind_output_sec = s->output_section;
3341 unwind_output_sec->contents
3342 = bfd_malloc (unwind_output_sec->size);
3343 if (unwind_output_sec->contents == NULL)
3348 /* Invoke the regular ELF backend linker to do all the work. */
3349 if (!bfd_elf_final_link (abfd, info))
3352 if (unwind_output_sec)
3354 elf64_ia64_unwind_entry_compare_bfd = abfd;
3355 qsort (unwind_output_sec->contents,
3356 (size_t) (unwind_output_sec->size / 24),
3358 elf64_ia64_unwind_entry_compare);
3360 if (! bfd_set_section_contents (abfd, unwind_output_sec,
3361 unwind_output_sec->contents, (bfd_vma) 0,
3362 unwind_output_sec->size))
3370 elf64_ia64_relocate_section (bfd *output_bfd,
3371 struct bfd_link_info *info,
3373 asection *input_section,
3375 Elf_Internal_Rela *relocs,
3376 Elf_Internal_Sym *local_syms,
3377 asection **local_sections)
3379 struct elf64_ia64_link_hash_table *ia64_info;
3380 Elf_Internal_Shdr *symtab_hdr;
3381 Elf_Internal_Rela *rel;
3382 Elf_Internal_Rela *relend;
3383 bfd_boolean ret_val = TRUE; /* for non-fatal errors */
3386 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3387 ia64_info = elf64_ia64_hash_table (info);
3388 if (ia64_info == NULL)
3391 /* Infect various flags from the input section to the output section. */
3392 if (info->relocatable)
3396 flags = elf_section_data(input_section)->this_hdr.sh_flags;
3397 flags &= SHF_IA_64_NORECOV;
3399 elf_section_data(input_section->output_section)
3400 ->this_hdr.sh_flags |= flags;
3403 gp_val = _bfd_get_gp_value (output_bfd);
3406 relend = relocs + input_section->reloc_count;
3407 for (; rel < relend; ++rel)
3409 struct elf_link_hash_entry *h;
3410 struct elf64_ia64_dyn_sym_info *dyn_i;
3411 bfd_reloc_status_type r;
3412 reloc_howto_type *howto;
3413 unsigned long r_symndx;
3414 Elf_Internal_Sym *sym;
3415 unsigned int r_type;
3419 bfd_boolean dynamic_symbol_p;
3420 bfd_boolean undef_weak_ref;
3422 r_type = ELF64_R_TYPE (rel->r_info);
3423 if (r_type > R_IA64_MAX_RELOC_CODE)
3425 (*_bfd_error_handler)
3426 (_("%B: unknown relocation type %d"),
3427 input_bfd, (int) r_type);
3428 bfd_set_error (bfd_error_bad_value);
3433 howto = ia64_elf_lookup_howto (r_type);
3434 r_symndx = ELF64_R_SYM (rel->r_info);
3438 undef_weak_ref = FALSE;
3440 if (r_symndx < symtab_hdr->sh_info)
3442 /* Reloc against local symbol. */
3444 sym = local_syms + r_symndx;
3445 sym_sec = local_sections[r_symndx];
3447 value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel);
3448 if (!info->relocatable
3449 && (sym_sec->flags & SEC_MERGE) != 0
3450 && ELF_ST_TYPE (sym->st_info) == STT_SECTION
3451 && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
3453 struct elf64_ia64_local_hash_entry *loc_h;
3455 loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, FALSE);
3456 if (loc_h && ! loc_h->sec_merge_done)
3458 struct elf64_ia64_dyn_sym_info *dynent;
3461 for (count = loc_h->count, dynent = loc_h->info;
3467 _bfd_merged_section_offset (output_bfd, &msec,
3468 elf_section_data (msec)->
3472 dynent->addend -= sym->st_value;
3473 dynent->addend += msec->output_section->vma
3474 + msec->output_offset
3475 - sym_sec->output_section->vma
3476 - sym_sec->output_offset;
3479 /* We may have introduced duplicated entries. We need
3480 to remove them properly. */
3481 count = sort_dyn_sym_info (loc_h->info, loc_h->count);
3482 if (count != loc_h->count)
3484 loc_h->count = count;
3485 loc_h->sorted_count = count;
3488 loc_h->sec_merge_done = 1;
3494 bfd_boolean unresolved_reloc;
3496 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
3498 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3499 r_symndx, symtab_hdr, sym_hashes,
3501 unresolved_reloc, warned);
3503 if (h->root.type == bfd_link_hash_undefweak)
3504 undef_weak_ref = TRUE;
3509 /* For relocs against symbols from removed linkonce sections,
3510 or sections discarded by a linker script, we just want the
3511 section contents zeroed. Avoid any special processing. */
3512 if (sym_sec != NULL && discarded_section (sym_sec))
3513 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3514 rel, 1, relend, howto, 0, contents);
3516 if (info->relocatable)
3519 hit_addr = contents + rel->r_offset;
3520 value += rel->r_addend;
3521 dynamic_symbol_p = elf64_ia64_dynamic_symbol_p (h);
3532 case R_IA64_DIR32MSB:
3533 case R_IA64_DIR32LSB:
3534 case R_IA64_DIR64MSB:
3535 case R_IA64_DIR64LSB:
3536 /* Install a dynamic relocation for this reloc. */
3537 if ((dynamic_symbol_p || info->shared)
3539 && (input_section->flags & SEC_ALLOC) != 0)
3541 unsigned int dyn_r_type;
3549 /* ??? People shouldn't be doing non-pic code in
3550 shared libraries nor dynamic executables. */
3551 (*_bfd_error_handler)
3552 (_("%B: non-pic code with imm relocation against dynamic symbol `%s'"),
3554 h ? h->root.root.string
3555 : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3564 /* If we don't need dynamic symbol lookup, find a
3565 matching RELATIVE relocation. */
3566 dyn_r_type = r_type;
3567 if (dynamic_symbol_p)
3569 addend = rel->r_addend;
3577 /* VMS: install a FIX64. */
3580 case R_IA64_DIR32LSB:
3581 dyn_r_type = R_IA64_VMS_FIX32;
3583 case R_IA64_DIR64LSB:
3584 dyn_r_type = R_IA64_VMS_FIX64;
3590 elf64_ia64_install_fixup
3591 (output_bfd, ia64_info, h,
3592 dyn_r_type, input_section, rel->r_offset, addend);
3598 case R_IA64_LTV32MSB:
3599 case R_IA64_LTV32LSB:
3600 case R_IA64_LTV64MSB:
3601 case R_IA64_LTV64LSB:
3602 r = ia64_elf_install_value (hit_addr, value, r_type);
3605 case R_IA64_GPREL22:
3606 case R_IA64_GPREL64I:
3607 case R_IA64_GPREL32MSB:
3608 case R_IA64_GPREL32LSB:
3609 case R_IA64_GPREL64MSB:
3610 case R_IA64_GPREL64LSB:
3611 if (dynamic_symbol_p)
3613 (*_bfd_error_handler)
3614 (_("%B: @gprel relocation against dynamic symbol %s"),
3616 h ? h->root.root.string
3617 : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3623 r = ia64_elf_install_value (hit_addr, value, r_type);
3626 case R_IA64_LTOFF22:
3627 case R_IA64_LTOFF22X:
3628 case R_IA64_LTOFF64I:
3629 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
3630 value = set_got_entry (input_bfd, info, dyn_i,
3631 rel->r_addend, value, R_IA64_DIR64LSB);
3633 r = ia64_elf_install_value (hit_addr, value, r_type);
3636 case R_IA64_PLTOFF22:
3637 case R_IA64_PLTOFF64I:
3638 case R_IA64_PLTOFF64MSB:
3639 case R_IA64_PLTOFF64LSB:
3640 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
3641 value = set_pltoff_entry (output_bfd, info, dyn_i, value, FALSE);
3643 r = ia64_elf_install_value (hit_addr, value, r_type);
3646 case R_IA64_FPTR64I:
3647 case R_IA64_FPTR32MSB:
3648 case R_IA64_FPTR32LSB:
3649 case R_IA64_FPTR64MSB:
3650 case R_IA64_FPTR64LSB:
3651 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
3652 if (dyn_i->want_fptr)
3654 if (!undef_weak_ref)
3655 value = set_fptr_entry (output_bfd, info, dyn_i, value);
3657 if (!dyn_i->want_fptr || info->pie)
3659 /* Otherwise, we expect the dynamic linker to create
3662 if (dyn_i->want_fptr)
3664 if (r_type == R_IA64_FPTR64I)
3666 /* We can't represent this without a dynamic symbol.
3667 Adjust the relocation to be against an output
3668 section symbol, which are always present in the
3669 dynamic symbol table. */
3670 /* ??? People shouldn't be doing non-pic code in
3671 shared libraries. Hork. */
3672 (*_bfd_error_handler)
3673 (_("%B: linking non-pic code in a position independent executable"),
3685 elf64_ia64_install_fixup
3686 (output_bfd, ia64_info, h, R_IA64_VMS_FIXFD,
3687 input_section, rel->r_offset, 0);
3692 r = ia64_elf_install_value (hit_addr, value, r_type);
3695 case R_IA64_LTOFF_FPTR22:
3696 case R_IA64_LTOFF_FPTR64I:
3697 case R_IA64_LTOFF_FPTR32MSB:
3698 case R_IA64_LTOFF_FPTR32LSB:
3699 case R_IA64_LTOFF_FPTR64MSB:
3700 case R_IA64_LTOFF_FPTR64LSB:
3701 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
3702 if (dyn_i->want_fptr)
3704 BFD_ASSERT (h == NULL || !h->def_dynamic);
3705 if (!undef_weak_ref)
3706 value = set_fptr_entry (output_bfd, info, dyn_i, value);
3711 value = set_got_entry (output_bfd, info, dyn_i,
3712 rel->r_addend, value, R_IA64_FPTR64LSB);
3714 r = ia64_elf_install_value (hit_addr, value, r_type);
3717 case R_IA64_PCREL32MSB:
3718 case R_IA64_PCREL32LSB:
3719 case R_IA64_PCREL64MSB:
3720 case R_IA64_PCREL64LSB:
3721 /* Install a dynamic relocation for this reloc. */
3722 if (dynamic_symbol_p && r_symndx != 0)
3724 /* VMS: doesn't exist ??? */
3729 case R_IA64_PCREL21B:
3730 case R_IA64_PCREL60B:
3731 /* We should have created a PLT entry for any dynamic symbol. */
3734 dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE);
3736 if (dyn_i && dyn_i->want_plt2)
3738 /* Should have caught this earlier. */
3739 BFD_ASSERT (rel->r_addend == 0);
3741 value = (ia64_info->root.splt->output_section->vma
3742 + ia64_info->root.splt->output_offset
3743 + dyn_i->plt2_offset);
3747 /* Since there's no PLT entry, Validate that this is
3749 BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL);
3751 /* If the symbol is undef_weak, we shouldn't be trying
3752 to call it. There's every chance that we'd wind up
3753 with an out-of-range fixup here. Don't bother setting
3754 any value at all. */
3760 case R_IA64_PCREL21BI:
3761 case R_IA64_PCREL21F:
3762 case R_IA64_PCREL21M:
3763 case R_IA64_PCREL22:
3764 case R_IA64_PCREL64I:
3765 /* The PCREL21BI reloc is specifically not intended for use with
3766 dynamic relocs. PCREL21F and PCREL21M are used for speculation
3767 fixup code, and thus probably ought not be dynamic. The
3768 PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */
3769 if (dynamic_symbol_p)
3773 if (r_type == R_IA64_PCREL21BI)
3774 msg = _("%B: @internal branch to dynamic symbol %s");
3775 else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M)
3776 msg = _("%B: speculation fixup to dynamic symbol %s");
3778 msg = _("%B: @pcrel relocation against dynamic symbol %s");
3779 (*_bfd_error_handler) (msg, input_bfd,
3780 h ? h->root.root.string
3781 : bfd_elf_sym_name (input_bfd,
3791 /* Make pc-relative. */
3792 value -= (input_section->output_section->vma
3793 + input_section->output_offset
3794 + rel->r_offset) & ~ (bfd_vma) 0x3;
3795 r = ia64_elf_install_value (hit_addr, value, r_type);
3798 case R_IA64_SEGREL32MSB:
3799 case R_IA64_SEGREL32LSB:
3800 case R_IA64_SEGREL64MSB:
3801 case R_IA64_SEGREL64LSB:
3803 /* Find the segment that contains the output_section. */
3804 Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section
3805 (output_bfd, sym_sec->output_section);
3809 r = bfd_reloc_notsupported;
3813 /* The VMA of the segment is the vaddr of the associated
3815 if (value > p->p_vaddr)
3816 value -= p->p_vaddr;
3819 r = ia64_elf_install_value (hit_addr, value, r_type);
3824 case R_IA64_SECREL32MSB:
3825 case R_IA64_SECREL32LSB:
3826 case R_IA64_SECREL64MSB:
3827 case R_IA64_SECREL64LSB:
3828 /* Make output-section relative to section where the symbol
3829 is defined. PR 475 */
3831 value -= sym_sec->output_section->vma;
3832 r = ia64_elf_install_value (hit_addr, value, r_type);
3835 case R_IA64_IPLTMSB:
3836 case R_IA64_IPLTLSB:
3837 /* Install a dynamic relocation for this reloc. */
3838 if ((dynamic_symbol_p || info->shared)
3839 && (input_section->flags & SEC_ALLOC) != 0)
3845 if (r_type == R_IA64_IPLTMSB)
3846 r_type = R_IA64_DIR64MSB;
3848 r_type = R_IA64_DIR64LSB;
3849 ia64_elf_install_value (hit_addr, value, r_type);
3850 r = ia64_elf_install_value (hit_addr + 8, gp_val, r_type);
3853 case R_IA64_TPREL14:
3854 case R_IA64_TPREL22:
3855 case R_IA64_TPREL64I:
3856 r = bfd_reloc_notsupported;
3859 case R_IA64_DTPREL14:
3860 case R_IA64_DTPREL22:
3861 case R_IA64_DTPREL64I:
3862 case R_IA64_DTPREL32LSB:
3863 case R_IA64_DTPREL32MSB:
3864 case R_IA64_DTPREL64LSB:
3865 case R_IA64_DTPREL64MSB:
3866 r = bfd_reloc_notsupported;
3869 case R_IA64_LTOFF_TPREL22:
3870 case R_IA64_LTOFF_DTPMOD22:
3871 case R_IA64_LTOFF_DTPREL22:
3872 r = bfd_reloc_notsupported;
3876 r = bfd_reloc_notsupported;
3885 case bfd_reloc_undefined:
3886 /* This can happen for global table relative relocs if
3887 __gp is undefined. This is a panic situation so we
3888 don't try to continue. */
3889 (*info->callbacks->undefined_symbol)
3890 (info, "__gp", input_bfd, input_section, rel->r_offset, 1);
3893 case bfd_reloc_notsupported:
3898 name = h->root.root.string;
3900 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3902 if (!(*info->callbacks->warning) (info, _("unsupported reloc"),
3904 input_section, rel->r_offset))
3910 case bfd_reloc_dangerous:
3911 case bfd_reloc_outofrange:
3912 case bfd_reloc_overflow:
3918 name = h->root.root.string;
3920 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3925 case R_IA64_TPREL14:
3926 case R_IA64_TPREL22:
3927 case R_IA64_TPREL64I:
3928 case R_IA64_DTPREL14:
3929 case R_IA64_DTPREL22:
3930 case R_IA64_DTPREL64I:
3931 case R_IA64_DTPREL32LSB:
3932 case R_IA64_DTPREL32MSB:
3933 case R_IA64_DTPREL64LSB:
3934 case R_IA64_DTPREL64MSB:
3935 case R_IA64_LTOFF_TPREL22:
3936 case R_IA64_LTOFF_DTPMOD22:
3937 case R_IA64_LTOFF_DTPREL22:
3938 (*_bfd_error_handler)
3939 (_("%B: missing TLS section for relocation %s against `%s' at 0x%lx in section `%A'."),
3940 input_bfd, input_section, howto->name, name,
3944 case R_IA64_PCREL21B:
3945 case R_IA64_PCREL21BI:
3946 case R_IA64_PCREL21M:
3947 case R_IA64_PCREL21F:
3948 if (is_elf_hash_table (info->hash))
3950 /* Relaxtion is always performed for ELF output.
3951 Overflow failures for those relocations mean
3952 that the section is too big to relax. */
3953 (*_bfd_error_handler)
3954 (_("%B: Can't relax br (%s) to `%s' at 0x%lx in section `%A' with size 0x%lx (> 0x1000000)."),
3955 input_bfd, input_section, howto->name, name,
3956 rel->r_offset, input_section->size);
3960 if (!(*info->callbacks->reloc_overflow) (info,
3982 elf64_ia64_finish_dynamic_symbol (bfd *output_bfd,
3983 struct bfd_link_info *info,
3984 struct elf_link_hash_entry *h,
3985 Elf_Internal_Sym *sym)
3987 struct elf64_ia64_link_hash_table *ia64_info;
3988 struct elf64_ia64_dyn_sym_info *dyn_i;
3990 ia64_info = elf64_ia64_hash_table (info);
3991 if (ia64_info == NULL)
3994 dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE);
3996 /* Fill in the PLT data, if required. */
3997 if (dyn_i && dyn_i->want_plt)
4001 bfd_vma plt_addr, pltoff_addr, gp_val;
4003 gp_val = _bfd_get_gp_value (output_bfd);
4005 plt_sec = ia64_info->root.splt;
4006 plt_addr = 0; /* Not used as overriden by FIXUPs. */
4007 pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, TRUE);
4009 /* Initialize the FULL PLT entry, if needed. */
4010 if (dyn_i->want_plt2)
4012 loc = plt_sec->contents + dyn_i->plt2_offset;
4014 memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE);
4015 ia64_elf_install_value (loc, pltoff_addr - gp_val, R_IA64_IMM22);
4017 /* Mark the symbol as undefined, rather than as defined in the
4018 plt section. Leave the value alone. */
4019 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4020 first place. But perhaps elflink.c did some for us. */
4021 if (!h->def_regular)
4022 sym->st_shndx = SHN_UNDEF;
4026 elf64_ia64_install_fixup
4027 (output_bfd, ia64_info, h, R_IA64_VMS_FIXFD, ia64_info->pltoff_sec,
4028 pltoff_addr - (ia64_info->pltoff_sec->output_section->vma
4029 + ia64_info->pltoff_sec->output_offset), 0);
4032 /* Mark some specially defined symbols as absolute. */
4033 if (h == ia64_info->root.hdynamic
4034 || h == ia64_info->root.hgot
4035 || h == ia64_info->root.hplt)
4036 sym->st_shndx = SHN_ABS;
4042 elf64_ia64_finish_dynamic_sections (bfd *abfd,
4043 struct bfd_link_info *info)
4045 struct elf64_ia64_link_hash_table *ia64_info;
4048 ia64_info = elf64_ia64_hash_table (info);
4049 if (ia64_info == NULL)
4052 dynobj = ia64_info->root.dynobj;
4054 if (elf_hash_table (info)->dynamic_sections_created)
4056 Elf64_External_Dyn *dyncon, *dynconend;
4058 asection *unwind_sec;
4060 unsigned int gp_seg;
4062 Elf_Internal_Phdr *phdr;
4063 Elf_Internal_Phdr *base_phdr;
4064 unsigned int unwind_seg = 0;
4065 unsigned int code_seg = 0;
4067 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4068 BFD_ASSERT (sdyn != NULL);
4069 dyncon = (Elf64_External_Dyn *) sdyn->contents;
4070 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
4072 gp_val = _bfd_get_gp_value (abfd);
4073 phdr = _bfd_elf_find_segment_containing_section
4074 (info->output_bfd, ia64_info->pltoff_sec->output_section);
4075 BFD_ASSERT (phdr != NULL);
4076 base_phdr = elf_tdata (info->output_bfd)->phdr;
4077 gp_seg = phdr - base_phdr;
4078 gp_off = gp_val - phdr->p_vaddr;
4080 unwind_sec = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
4081 if (unwind_sec != NULL)
4085 phdr = _bfd_elf_find_segment_containing_section (abfd, unwind_sec);
4086 BFD_ASSERT (phdr != NULL);
4087 unwind_seg = phdr - base_phdr;
4089 code_sec = bfd_get_section_by_name (abfd, "$CODE$");
4090 phdr = _bfd_elf_find_segment_containing_section (abfd, code_sec);
4091 BFD_ASSERT (phdr != NULL);
4092 code_seg = phdr - base_phdr;
4095 for (; dyncon < dynconend; dyncon++)
4097 Elf_Internal_Dyn dyn;
4099 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
4103 case DT_IA_64_VMS_FIXUP_RELA_OFF:
4105 (ia64_info->fixups_sec->output_section->vma
4106 + ia64_info->fixups_sec->output_offset)
4107 - (sdyn->output_section->vma + sdyn->output_offset);
4110 case DT_IA_64_VMS_PLTGOT_OFFSET:
4111 dyn.d_un.d_val = gp_off;
4114 case DT_IA_64_VMS_PLTGOT_SEG:
4115 dyn.d_un.d_val = gp_seg;
4118 case DT_IA_64_VMS_UNWINDSZ:
4119 if (unwind_sec == NULL)
4121 dyn.d_tag = DT_NULL;
4122 dyn.d_un.d_val = 0xdead;
4125 dyn.d_un.d_val = unwind_sec->size;
4128 case DT_IA_64_VMS_UNWIND_CODSEG:
4129 dyn.d_un.d_val = code_seg;
4132 case DT_IA_64_VMS_UNWIND_INFOSEG:
4133 case DT_IA_64_VMS_UNWIND_SEG:
4134 dyn.d_un.d_val = unwind_seg;
4137 case DT_IA_64_VMS_UNWIND_OFFSET:
4141 /* No need to rewrite the entry. */
4145 bfd_elf64_swap_dyn_out (abfd, &dyn, dyncon);
4149 /* Handle transfer addresses. */
4151 asection *tfr_sec = ia64_info->transfer_sec;
4152 struct elf64_vms_transfer *tfr;
4153 struct elf_link_hash_entry *tfr3;
4155 tfr = (struct elf64_vms_transfer *)tfr_sec->contents;
4156 bfd_putl32 (6 * 8, tfr->size);
4157 bfd_putl64 (tfr_sec->output_section->vma
4158 + tfr_sec->output_offset
4159 + 6 * 8, tfr->tfradr3);
4161 tfr3 = elf_link_hash_lookup (elf_hash_table (info), "ELF$TFRADR", FALSE,
4165 && (tfr3->root.type == bfd_link_hash_defined
4166 || tfr3->root.type == bfd_link_hash_defweak))
4168 asection *tfr3_sec = tfr3->root.u.def.section;
4171 tfr3_val = (tfr3->root.u.def.value
4172 + tfr3_sec->output_section->vma
4173 + tfr3_sec->output_offset);
4175 bfd_putl64 (tfr3_val, tfr->tfr3_func);
4176 bfd_putl64 (_bfd_get_gp_value (info->output_bfd), tfr->tfr3_gp);
4179 /* FIXME: set linker flags,
4180 handle lib$initialize. */
4186 /* ELF file flag handling: */
4188 /* Function to keep IA-64 specific file flags. */
4190 elf64_ia64_set_private_flags (bfd *abfd, flagword flags)
4192 BFD_ASSERT (!elf_flags_init (abfd)
4193 || elf_elfheader (abfd)->e_flags == flags);
4195 elf_elfheader (abfd)->e_flags = flags;
4196 elf_flags_init (abfd) = TRUE;
4200 /* Merge backend specific data from an object file to the output
4201 object file when linking. */
4203 elf64_ia64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4207 bfd_boolean ok = TRUE;
4209 /* Don't even pretend to support mixed-format linking. */
4210 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4211 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4214 in_flags = elf_elfheader (ibfd)->e_flags;
4215 out_flags = elf_elfheader (obfd)->e_flags;
4217 if (! elf_flags_init (obfd))
4219 elf_flags_init (obfd) = TRUE;
4220 elf_elfheader (obfd)->e_flags = in_flags;
4222 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4223 && bfd_get_arch_info (obfd)->the_default)
4225 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
4226 bfd_get_mach (ibfd));
4232 /* Check flag compatibility. */
4233 if (in_flags == out_flags)
4236 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4237 if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP))
4238 elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP;
4240 if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL))
4242 (*_bfd_error_handler)
4243 (_("%B: linking trap-on-NULL-dereference with non-trapping files"),
4246 bfd_set_error (bfd_error_bad_value);
4249 if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE))
4251 (*_bfd_error_handler)
4252 (_("%B: linking big-endian files with little-endian files"),
4255 bfd_set_error (bfd_error_bad_value);
4258 if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64))
4260 (*_bfd_error_handler)
4261 (_("%B: linking 64-bit files with 32-bit files"),
4264 bfd_set_error (bfd_error_bad_value);
4267 if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP))
4269 (*_bfd_error_handler)
4270 (_("%B: linking constant-gp files with non-constant-gp files"),
4273 bfd_set_error (bfd_error_bad_value);
4276 if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP)
4277 != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
4279 (*_bfd_error_handler)
4280 (_("%B: linking auto-pic files with non-auto-pic files"),
4283 bfd_set_error (bfd_error_bad_value);
4291 elf64_ia64_print_private_bfd_data (bfd *abfd, void * ptr)
4293 FILE *file = (FILE *) ptr;
4294 flagword flags = elf_elfheader (abfd)->e_flags;
4296 BFD_ASSERT (abfd != NULL && ptr != NULL);
4298 fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n",
4299 (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "",
4300 (flags & EF_IA_64_EXT) ? "EXT, " : "",
4301 (flags & EF_IA_64_BE) ? "BE, " : "LE, ",
4302 (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "",
4303 (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "",
4304 (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "",
4305 (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "",
4306 (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32");
4308 _bfd_elf_print_private_bfd_data (abfd, ptr);
4312 static enum elf_reloc_type_class
4313 elf64_ia64_reloc_type_class (const Elf_Internal_Rela *rela)
4315 switch ((int) ELF64_R_TYPE (rela->r_info))
4317 case R_IA64_REL32MSB:
4318 case R_IA64_REL32LSB:
4319 case R_IA64_REL64MSB:
4320 case R_IA64_REL64LSB:
4321 return reloc_class_relative;
4322 case R_IA64_IPLTMSB:
4323 case R_IA64_IPLTLSB:
4324 return reloc_class_plt;
4326 return reloc_class_copy;
4328 return reloc_class_normal;
4332 static const struct bfd_elf_special_section elf64_ia64_special_sections[] =
4334 { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
4335 { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
4336 { NULL, 0, 0, 0, 0 }
4340 elf64_ia64_object_p (bfd *abfd)
4343 asection *group, *unwi, *unw;
4346 char *unwi_name, *unw_name;
4349 if (abfd->flags & DYNAMIC)
4352 /* Flags for fake group section. */
4353 flags = (SEC_LINKER_CREATED | SEC_GROUP | SEC_LINK_ONCE
4356 /* We add a fake section group for each .gnu.linkonce.t.* section,
4357 which isn't in a section group, and its unwind sections. */
4358 for (sec = abfd->sections; sec != NULL; sec = sec->next)
4360 if (elf_sec_group (sec) == NULL
4361 && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP))
4362 == (SEC_LINK_ONCE | SEC_CODE))
4363 && CONST_STRNEQ (sec->name, ".gnu.linkonce.t."))
4365 name = sec->name + 16;
4367 amt = strlen (name) + sizeof (".gnu.linkonce.ia64unwi.");
4368 unwi_name = bfd_alloc (abfd, amt);
4372 strcpy (stpcpy (unwi_name, ".gnu.linkonce.ia64unwi."), name);
4373 unwi = bfd_get_section_by_name (abfd, unwi_name);
4375 amt = strlen (name) + sizeof (".gnu.linkonce.ia64unw.");
4376 unw_name = bfd_alloc (abfd, amt);
4380 strcpy (stpcpy (unw_name, ".gnu.linkonce.ia64unw."), name);
4381 unw = bfd_get_section_by_name (abfd, unw_name);
4383 /* We need to create a fake group section for it and its
4385 group = bfd_make_section_anyway_with_flags (abfd, name,
4390 /* Move the fake group section to the beginning. */
4391 bfd_section_list_remove (abfd, group);
4392 bfd_section_list_prepend (abfd, group);
4394 elf_next_in_group (group) = sec;
4396 elf_group_name (sec) = name;
4397 elf_next_in_group (sec) = sec;
4398 elf_sec_group (sec) = group;
4402 elf_group_name (unwi) = name;
4403 elf_next_in_group (unwi) = sec;
4404 elf_next_in_group (sec) = unwi;
4405 elf_sec_group (unwi) = group;
4410 elf_group_name (unw) = name;
4413 elf_next_in_group (unw) = elf_next_in_group (unwi);
4414 elf_next_in_group (unwi) = unw;
4418 elf_next_in_group (unw) = sec;
4419 elf_next_in_group (sec) = unw;
4421 elf_sec_group (unw) = group;
4424 /* Fake SHT_GROUP section header. */
4425 elf_section_data (group)->this_hdr.bfd_section = group;
4426 elf_section_data (group)->this_hdr.sh_type = SHT_GROUP;
4432 /* Handle an IA-64 specific section when reading an object file. This
4433 is called when bfd_section_from_shdr finds a section with an unknown
4437 elf64_vms_section_from_shdr (bfd *abfd,
4438 Elf_Internal_Shdr *hdr,
4442 flagword secflags = 0;
4444 switch (hdr->sh_type)
4446 case SHT_IA_64_VMS_TRACE:
4447 case SHT_IA_64_VMS_DEBUG:
4448 case SHT_IA_64_VMS_DEBUG_STR:
4449 secflags = SEC_DEBUGGING;
4452 case SHT_IA_64_UNWIND:
4453 case SHT_IA_64_HP_OPT_ANOT:
4457 if (strcmp (name, ELF_STRING_ia64_archext) != 0)
4465 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
4470 asection *newsect = hdr->bfd_section;
4472 if (! bfd_set_section_flags
4473 (abfd, newsect, bfd_get_section_flags (abfd, newsect) | secflags))
4481 elf64_vms_object_p (bfd *abfd)
4483 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
4484 Elf_Internal_Phdr *i_phdr = elf_tdata (abfd)->phdr;
4486 unsigned int num_text = 0;
4487 unsigned int num_data = 0;
4488 unsigned int num_rodata = 0;
4491 if (!elf64_ia64_object_p (abfd))
4494 /* Many VMS compilers do not generate sections for the corresponding
4495 segment. This is boring as binutils tools won't be able to disassemble
4496 the code. So we simply create all the missing sections. */
4497 for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++)
4499 /* Is there a section for this segment? */
4500 bfd_vma base_vma = i_phdr->p_vaddr;
4501 bfd_vma limit_vma = base_vma + i_phdr->p_filesz;
4503 if (i_phdr->p_type != PT_LOAD)
4506 /* We need to cover from base_vms to limit_vma. */
4508 while (base_vma < limit_vma)
4510 bfd_vma next_vma = limit_vma;
4516 /* Find a section covering [base_vma;limit_vma) */
4517 for (sec = abfd->sections; sec != NULL; sec = sec->next)
4519 /* Skip uninteresting sections (either not in memory or
4521 if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == 0
4522 || sec->vma + sec->size <= base_vma)
4524 if (sec->vma <= base_vma)
4526 /* This section covers (maybe partially) the beginning
4528 base_vma = sec->vma + sec->size;
4531 if (sec->vma < next_vma)
4533 /* This section partially covers the end of the range.
4534 Used to compute the size of the hole. */
4535 next_vma = sec->vma;
4539 /* No section covering [base_vma; next_vma). Create a fake one. */
4540 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
4541 if (i_phdr->p_flags & PF_X)
4544 if (num_text++ == 0)
4547 sprintf (name, ".text$%u", num_text);
4549 else if ((i_phdr->p_flags & (PF_R | PF_W)) == PF_R)
4551 flags |= SEC_READONLY;
4552 sprintf (name, ".rodata$%u", num_rodata++);
4557 sprintf (name, ".data$%u", num_data++);
4560 /* Allocate name. */
4563 size_t name_len = strlen (name) + 1;
4564 nname = bfd_alloc (abfd, name_len);
4567 memcpy (nname, name, name_len);
4570 /* Create and fill new section. */
4571 nsec = bfd_make_section_anyway_with_flags (abfd, nname, flags);
4574 nsec->vma = base_vma;
4575 nsec->size = next_vma - base_vma;
4576 nsec->filepos = i_phdr->p_offset + (base_vma - i_phdr->p_vaddr);
4578 base_vma = next_vma;
4585 elf64_vms_post_process_headers (bfd *abfd,
4586 struct bfd_link_info *info ATTRIBUTE_UNUSED)
4588 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
4590 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_OPENVMS;
4591 i_ehdrp->e_ident[EI_ABIVERSION] = 2;
4595 elf64_vms_section_processing (bfd *abfd ATTRIBUTE_UNUSED,
4596 Elf_Internal_Shdr *hdr)
4598 if (hdr->bfd_section != NULL)
4600 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
4602 if (strcmp (name, ".text") == 0)
4603 hdr->sh_flags |= SHF_IA_64_VMS_SHARED;
4604 else if ((strcmp (name, ".debug") == 0)
4605 || (strcmp (name, ".debug_abbrev") == 0)
4606 || (strcmp (name, ".debug_aranges") == 0)
4607 || (strcmp (name, ".debug_frame") == 0)
4608 || (strcmp (name, ".debug_info") == 0)
4609 || (strcmp (name, ".debug_loc") == 0)
4610 || (strcmp (name, ".debug_macinfo") == 0)
4611 || (strcmp (name, ".debug_pubnames") == 0)
4612 || (strcmp (name, ".debug_pubtypes") == 0))
4613 hdr->sh_type = SHT_IA_64_VMS_DEBUG;
4614 else if ((strcmp (name, ".debug_line") == 0)
4615 || (strcmp (name, ".debug_ranges") == 0)
4616 || (strcmp (name, ".trace_info") == 0)
4617 || (strcmp (name, ".trace_abbrev") == 0)
4618 || (strcmp (name, ".trace_aranges") == 0))
4619 hdr->sh_type = SHT_IA_64_VMS_TRACE;
4620 else if (strcmp (name, ".debug_str") == 0)
4621 hdr->sh_type = SHT_IA_64_VMS_DEBUG_STR;
4627 /* The final processing done just before writing out a VMS IA-64 ELF
4631 elf64_vms_final_write_processing (bfd *abfd,
4632 bfd_boolean linker ATTRIBUTE_UNUSED)
4634 Elf_Internal_Shdr *hdr;
4636 int unwind_info_sect_idx = 0;
4638 for (s = abfd->sections; s; s = s->next)
4640 hdr = &elf_section_data (s)->this_hdr;
4642 if (strcmp (bfd_get_section_name (abfd, hdr->bfd_section),
4643 ".IA_64.unwind_info") == 0)
4644 unwind_info_sect_idx = elf_section_data (s)->this_idx;
4646 switch (hdr->sh_type)
4648 case SHT_IA_64_UNWIND:
4649 /* VMS requires sh_info to point to the unwind info section. */
4650 hdr->sh_info = unwind_info_sect_idx;
4655 if (! elf_flags_init (abfd))
4657 unsigned long flags = 0;
4659 if (abfd->xvec->byteorder == BFD_ENDIAN_BIG)
4660 flags |= EF_IA_64_BE;
4661 if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64)
4662 flags |= EF_IA_64_ABI64;
4664 elf_elfheader (abfd)->e_flags = flags;
4665 elf_flags_init (abfd) = TRUE;
4670 elf64_vms_write_shdrs_and_ehdr (bfd *abfd)
4672 unsigned char needed_count[8];
4674 if (!bfd_elf64_write_shdrs_and_ehdr (abfd))
4677 bfd_putl64 (elf_ia64_vms_tdata (abfd)->needed_count, needed_count);
4679 if (bfd_seek (abfd, sizeof (Elf64_External_Ehdr), SEEK_SET) != 0
4680 || bfd_bwrite (needed_count, 8, abfd) != 8)
4687 elf64_vms_close_and_cleanup (bfd *abfd)
4689 if (bfd_get_format (abfd) == bfd_object)
4693 /* Pad to 8 byte boundary for IPF/VMS. */
4694 isize = bfd_get_size (abfd);
4695 if ((isize & 7) != 0)
4697 int ishort = 8 - (isize & 7);
4698 bfd_uint64_t pad = 0;
4700 bfd_seek (abfd, isize, SEEK_SET);
4701 bfd_bwrite (&pad, ishort, abfd);
4705 return _bfd_elf_close_and_cleanup (abfd);
4708 /* Add symbols from an ELF object file to the linker hash table. */
4711 elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
4713 Elf_Internal_Shdr *hdr;
4714 bfd_size_type symcount;
4715 bfd_size_type extsymcount;
4716 bfd_size_type extsymoff;
4717 struct elf_link_hash_entry **sym_hash;
4718 bfd_boolean dynamic;
4719 Elf_Internal_Sym *isymbuf = NULL;
4720 Elf_Internal_Sym *isym;
4721 Elf_Internal_Sym *isymend;
4722 const struct elf_backend_data *bed;
4723 struct elf_link_hash_table *htab;
4726 htab = elf_hash_table (info);
4727 bed = get_elf_backend_data (abfd);
4729 if ((abfd->flags & DYNAMIC) == 0)
4735 /* You can't use -r against a dynamic object. Also, there's no
4736 hope of using a dynamic object which does not exactly match
4737 the format of the output file. */
4738 if (info->relocatable
4739 || !is_elf_hash_table (htab)
4740 || info->output_bfd->xvec != abfd->xvec)
4742 if (info->relocatable)
4743 bfd_set_error (bfd_error_invalid_operation);
4745 bfd_set_error (bfd_error_wrong_format);
4752 /* If we are creating a shared library, create all the dynamic
4753 sections immediately. We need to attach them to something,
4754 so we attach them to this BFD, provided it is the right
4755 format. FIXME: If there are no input BFD's of the same
4756 format as the output, we can't make a shared library. */
4758 && is_elf_hash_table (htab)
4759 && info->output_bfd->xvec == abfd->xvec
4760 && !htab->dynamic_sections_created)
4762 if (! elf64_ia64_create_dynamic_sections (abfd, info))
4766 else if (!is_elf_hash_table (htab))
4774 /* ld --just-symbols and dynamic objects don't mix very well.
4775 ld shouldn't allow it. */
4776 if ((s = abfd->sections) != NULL
4777 && s->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
4780 /* Be sure there are dynamic sections. */
4781 if (! elf64_ia64_create_dynamic_sections (htab->dynobj, info))
4784 s = bfd_get_section_by_name (abfd, ".dynamic");
4787 /* VMS libraries do not have dynamic sections. Create one from
4789 Elf_Internal_Phdr *phdr;
4790 unsigned int i, phnum;
4792 phdr = elf_tdata (abfd)->phdr;
4795 phnum = elf_elfheader (abfd)->e_phnum;
4796 for (i = 0; i < phnum; phdr++)
4797 if (phdr->p_type == PT_DYNAMIC)
4799 s = bfd_make_section (abfd, ".dynamic");
4802 s->vma = phdr->p_vaddr;
4803 s->lma = phdr->p_paddr;
4804 s->size = phdr->p_filesz;
4805 s->filepos = phdr->p_offset;
4806 s->flags |= SEC_HAS_CONTENTS;
4807 s->alignment_power = bfd_log2 (phdr->p_align);
4814 /* Extract IDENT. */
4815 if (!bfd_malloc_and_get_section (abfd, s, &dynbuf))
4822 for (extdyn = dynbuf;
4823 extdyn < dynbuf + s->size;
4824 extdyn += bed->s->sizeof_dyn)
4826 Elf_Internal_Dyn dyn;
4828 bed->s->swap_dyn_in (abfd, extdyn, &dyn);
4829 if (dyn.d_tag == DT_IA_64_VMS_IDENT)
4831 bfd_uint64_t tagv = dyn.d_un.d_val;
4832 elf_ia64_vms_ident (abfd) = tagv;
4836 if (extdyn >= dynbuf + s->size)
4838 /* Ident not found. */
4839 goto error_free_dyn;
4843 /* We do not want to include any of the sections in a dynamic
4844 object in the output file. We hack by simply clobbering the
4845 list of sections in the BFD. This could be handled more
4846 cleanly by, say, a new section flag; the existing
4847 SEC_NEVER_LOAD flag is not the one we want, because that one
4848 still implies that the section takes up space in the output
4850 bfd_section_list_clear (abfd);
4852 /* FIXME: should we detect if this library is already included ?
4853 This should be harmless and shouldn't happen in practice. */
4856 hdr = &elf_tdata (abfd)->symtab_hdr;
4857 symcount = hdr->sh_size / bed->s->sizeof_sym;
4859 /* The sh_info field of the symtab header tells us where the
4860 external symbols start. We don't care about the local symbols at
4862 extsymcount = symcount - hdr->sh_info;
4863 extsymoff = hdr->sh_info;
4866 if (extsymcount != 0)
4868 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
4870 if (isymbuf == NULL)
4873 /* We store a pointer to the hash table entry for each external
4875 amt = extsymcount * sizeof (struct elf_link_hash_entry *);
4876 sym_hash = (struct elf_link_hash_entry **) bfd_alloc (abfd, amt);
4877 if (sym_hash == NULL)
4878 goto error_free_sym;
4879 elf_sym_hashes (abfd) = sym_hash;
4882 for (isym = isymbuf, isymend = isymbuf + extsymcount;
4888 asection *sec, *new_sec;
4891 struct elf_link_hash_entry *h;
4892 bfd_boolean definition;
4893 bfd_boolean size_change_ok;
4894 bfd_boolean type_change_ok;
4896 unsigned int old_alignment;
4899 flags = BSF_NO_FLAGS;
4901 value = isym->st_value;
4903 common = bed->common_definition (isym);
4905 bind = ELF_ST_BIND (isym->st_info);
4909 /* This should be impossible, since ELF requires that all
4910 global symbols follow all local symbols, and that sh_info
4911 point to the first global symbol. Unfortunately, Irix 5
4916 if (isym->st_shndx != SHN_UNDEF && !common)
4924 case STB_GNU_UNIQUE:
4925 flags = BSF_GNU_UNIQUE;
4929 /* Leave it up to the processor backend. */
4933 if (isym->st_shndx == SHN_UNDEF)
4934 sec = bfd_und_section_ptr;
4935 else if (isym->st_shndx == SHN_ABS)
4936 sec = bfd_abs_section_ptr;
4937 else if (isym->st_shndx == SHN_COMMON)
4939 sec = bfd_com_section_ptr;
4940 /* What ELF calls the size we call the value. What ELF
4941 calls the value we call the alignment. */
4942 value = isym->st_size;
4946 sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4948 sec = bfd_abs_section_ptr;
4949 else if (sec->kept_section)
4951 /* Symbols from discarded section are undefined. We keep
4953 sec = bfd_und_section_ptr;
4954 isym->st_shndx = SHN_UNDEF;
4956 else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
4960 name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
4963 goto error_free_vers;
4965 if (bed->elf_add_symbol_hook)
4967 if (! (*bed->elf_add_symbol_hook) (abfd, info, isym, &name, &flags,
4969 goto error_free_vers;
4971 /* The hook function sets the name to NULL if this symbol
4972 should be skipped for some reason. */
4977 /* Sanity check that all possibilities were handled. */
4980 bfd_set_error (bfd_error_bad_value);
4981 goto error_free_vers;
4984 if (bfd_is_und_section (sec)
4985 || bfd_is_com_section (sec))
4990 size_change_ok = FALSE;
4991 type_change_ok = bed->type_change_ok;
4996 if (! bfd_is_und_section (sec))
4997 h = elf_link_hash_lookup (htab, name, TRUE, FALSE, FALSE);
4999 h = ((struct elf_link_hash_entry *) bfd_wrapped_link_hash_lookup
5000 (abfd, info, name, TRUE, FALSE, FALSE));
5002 goto error_free_sym;
5006 if (is_elf_hash_table (htab))
5008 while (h->root.type == bfd_link_hash_indirect
5009 || h->root.type == bfd_link_hash_warning)
5010 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5012 /* Remember the old alignment if this is a common symbol, so
5013 that we don't reduce the alignment later on. We can't
5014 check later, because _bfd_generic_link_add_one_symbol
5015 will set a default for the alignment which we want to
5016 override. We also remember the old bfd where the existing
5017 definition comes from. */
5018 switch (h->root.type)
5023 case bfd_link_hash_defined:
5024 if (abfd->selective_search)
5027 case bfd_link_hash_defweak:
5028 old_bfd = h->root.u.def.section->owner;
5031 case bfd_link_hash_common:
5032 old_bfd = h->root.u.c.p->section->owner;
5033 old_alignment = h->root.u.c.p->alignment_power;
5038 if (! (_bfd_generic_link_add_one_symbol
5039 (info, abfd, name, flags, sec, value, NULL, FALSE, bed->collect,
5040 (struct bfd_link_hash_entry **) sym_hash)))
5041 goto error_free_vers;
5044 while (h->root.type == bfd_link_hash_indirect
5045 || h->root.type == bfd_link_hash_warning)
5046 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5049 h->unique_global = (flags & BSF_GNU_UNIQUE) != 0;
5051 /* Set the alignment of a common symbol. */
5052 if ((common || bfd_is_com_section (sec))
5053 && h->root.type == bfd_link_hash_common)
5058 align = bfd_log2 (isym->st_value);
5061 /* The new symbol is a common symbol in a shared object.
5062 We need to get the alignment from the section. */
5063 align = new_sec->alignment_power;
5065 if (align > old_alignment
5066 /* Permit an alignment power of zero if an alignment of one
5067 is specified and no other alignments have been specified. */
5068 || (isym->st_value == 1 && old_alignment == 0))
5069 h->root.u.c.p->alignment_power = align;
5071 h->root.u.c.p->alignment_power = old_alignment;
5074 if (is_elf_hash_table (htab))
5076 /* Check the alignment when a common symbol is involved. This
5077 can change when a common symbol is overridden by a normal
5078 definition or a common symbol is ignored due to the old
5079 normal definition. We need to make sure the maximum
5080 alignment is maintained. */
5081 if ((old_alignment || common)
5082 && h->root.type != bfd_link_hash_common)
5084 unsigned int common_align;
5085 unsigned int normal_align;
5086 unsigned int symbol_align;
5090 symbol_align = ffs (h->root.u.def.value) - 1;
5091 if (h->root.u.def.section->owner != NULL
5092 && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
5094 normal_align = h->root.u.def.section->alignment_power;
5095 if (normal_align > symbol_align)
5096 normal_align = symbol_align;
5099 normal_align = symbol_align;
5103 common_align = old_alignment;
5104 common_bfd = old_bfd;
5109 common_align = bfd_log2 (isym->st_value);
5111 normal_bfd = old_bfd;
5114 if (normal_align < common_align)
5116 /* PR binutils/2735 */
5117 if (normal_bfd == NULL)
5118 (*_bfd_error_handler)
5119 (_("Warning: alignment %u of common symbol `%s' in %B"
5120 " is greater than the alignment (%u) of its section %A"),
5121 common_bfd, h->root.u.def.section,
5122 1 << common_align, name, 1 << normal_align);
5124 (*_bfd_error_handler)
5125 (_("Warning: alignment %u of symbol `%s' in %B"
5126 " is smaller than %u in %B"),
5127 normal_bfd, common_bfd,
5128 1 << normal_align, name, 1 << common_align);
5132 /* Remember the symbol size if it isn't undefined. */
5133 if ((isym->st_size != 0 && isym->st_shndx != SHN_UNDEF)
5134 && (definition || h->size == 0))
5137 && h->size != isym->st_size
5138 && ! size_change_ok)
5139 (*_bfd_error_handler)
5140 (_("Warning: size of symbol `%s' changed"
5141 " from %lu in %B to %lu in %B"),
5143 name, (unsigned long) h->size,
5144 (unsigned long) isym->st_size);
5146 h->size = isym->st_size;
5149 /* If this is a common symbol, then we always want H->SIZE
5150 to be the size of the common symbol. The code just above
5151 won't fix the size if a common symbol becomes larger. We
5152 don't warn about a size change here, because that is
5153 covered by --warn-common. Allow changed between different
5155 if (h->root.type == bfd_link_hash_common)
5156 h->size = h->root.u.c.size;
5158 if (ELF_ST_TYPE (isym->st_info) != STT_NOTYPE
5159 && (definition || h->type == STT_NOTYPE))
5161 unsigned int type = ELF_ST_TYPE (isym->st_info);
5163 if (h->type != type)
5165 if (h->type != STT_NOTYPE && ! type_change_ok)
5166 (*_bfd_error_handler)
5167 (_("Warning: type of symbol `%s' changed"
5168 " from %d to %d in %B"),
5169 abfd, name, h->type, type);
5175 /* Set a flag in the hash table entry indicating the type of
5176 reference or definition we just found. Keep a count of
5177 the number of dynamic symbols we find. A dynamic symbol
5178 is one which is referenced or defined by both a regular
5179 object and a shared object. */
5185 if (bind != STB_WEAK)
5186 h->ref_regular_nonweak = 1;
5190 BFD_ASSERT (!h->def_dynamic);
5196 BFD_ASSERT (definition);
5199 ((struct elf64_ia64_link_hash_entry *)h)->shl = abfd;
5204 if (isymbuf != NULL)
5210 /* If this object is the same format as the output object, and it is
5211 not a shared library, then let the backend look through the
5214 This is required to build global offset table entries and to
5215 arrange for dynamic relocs. It is not required for the
5216 particular common case of linking non PIC code, even when linking
5217 against shared libraries, but unfortunately there is no way of
5218 knowing whether an object file has been compiled PIC or not.
5219 Looking through the relocs is not particularly time consuming.
5220 The problem is that we must either (1) keep the relocs in memory,
5221 which causes the linker to require additional runtime memory or
5222 (2) read the relocs twice from the input file, which wastes time.
5223 This would be a good case for using mmap.
5225 I have no idea how to handle linking PIC code into a file of a
5226 different format. It probably can't be done. */
5228 && is_elf_hash_table (htab)
5229 && bed->check_relocs != NULL
5230 && (*bed->relocs_compatible) (abfd->xvec, info->output_bfd->xvec))
5234 for (o = abfd->sections; o != NULL; o = o->next)
5236 Elf_Internal_Rela *internal_relocs;
5239 if ((o->flags & SEC_RELOC) == 0
5240 || o->reloc_count == 0
5241 || ((info->strip == strip_all || info->strip == strip_debugger)
5242 && (o->flags & SEC_DEBUGGING) != 0)
5243 || bfd_is_abs_section (o->output_section))
5246 internal_relocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL,
5248 if (internal_relocs == NULL)
5251 ok = (*bed->check_relocs) (abfd, info, o, internal_relocs);
5253 if (elf_section_data (o)->relocs != internal_relocs)
5254 free (internal_relocs);
5265 if (isymbuf != NULL)
5272 elf64_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
5275 struct bfd_link_hash_entry **pundef;
5276 struct bfd_link_hash_entry **next_pundef;
5278 /* We only accept VMS libraries. */
5279 if (info->output_bfd->xvec != abfd->xvec)
5281 bfd_set_error (bfd_error_wrong_format);
5285 /* The archive_pass field in the archive itself is used to
5286 initialize PASS, since we may search the same archive multiple
5288 pass = ++abfd->archive_pass;
5290 /* Look through the list of undefined symbols. */
5291 for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef)
5293 struct bfd_link_hash_entry *h;
5299 next_pundef = &(*pundef)->u.undef.next;
5301 /* When a symbol is defined, it is not necessarily removed from
5303 if (h->type != bfd_link_hash_undefined
5304 && h->type != bfd_link_hash_common)
5306 /* Remove this entry from the list, for general cleanliness
5307 and because we are going to look through the list again
5308 if we search any more libraries. We can't remove the
5309 entry if it is the tail, because that would lose any
5310 entries we add to the list later on. */
5311 if (*pundef != info->hash->undefs_tail)
5313 *pundef = *next_pundef;
5314 next_pundef = pundef;
5319 /* Look for this symbol in the archive hash table. */
5320 symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string);
5321 if (symidx == BFD_NO_MORE_SYMBOLS)
5323 /* Nothing in this slot. */
5327 element = bfd_get_elt_at_index (abfd, symidx);
5328 if (element == NULL)
5331 if (element->archive_pass == -1 || element->archive_pass == pass)
5333 /* Next symbol if this archive is wrong or already handled. */
5337 orig_element = element;
5338 if (bfd_is_thin_archive (abfd))
5340 element = _bfd_vms_lib_get_imagelib_file (element);
5341 if (element == NULL || !bfd_check_format (element, bfd_object))
5343 orig_element->archive_pass = -1;
5347 else if (! bfd_check_format (element, bfd_object))
5349 element->archive_pass = -1;
5353 /* Unlike the generic linker, we know that this element provides
5354 a definition for an undefined symbol and we know that we want
5355 to include it. We don't need to check anything. */
5356 if (! (*info->callbacks->add_archive_element) (info, element,
5357 h->root.string, &element))
5359 if (! elf64_vms_link_add_object_symbols (element, info))
5362 orig_element->archive_pass = pass;
5369 elf64_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
5371 switch (bfd_get_format (abfd))
5374 return elf64_vms_link_add_object_symbols (abfd, info);
5377 return elf64_vms_link_add_archive_symbols (abfd, info);
5380 bfd_set_error (bfd_error_wrong_format);
5386 elf64_ia64_vms_mkobject (bfd *abfd)
5388 return bfd_elf_allocate_object
5389 (abfd, sizeof (struct elf64_ia64_vms_obj_tdata), IA64_ELF_DATA);
5393 /* Size-dependent data and functions. */
5394 static const struct elf_size_info elf64_ia64_vms_size_info = {
5395 sizeof (Elf64_External_VMS_Ehdr),
5396 sizeof (Elf64_External_Phdr),
5397 sizeof (Elf64_External_Shdr),
5398 sizeof (Elf64_External_Rel),
5399 sizeof (Elf64_External_Rela),
5400 sizeof (Elf64_External_Sym),
5401 sizeof (Elf64_External_Dyn),
5402 sizeof (Elf_External_Note),
5405 64, 3, /* ARCH_SIZE, LOG_FILE_ALIGN */
5406 ELFCLASS64, EV_CURRENT,
5407 bfd_elf64_write_out_phdrs,
5408 elf64_vms_write_shdrs_and_ehdr,
5409 bfd_elf64_checksum_contents,
5410 bfd_elf64_write_relocs,
5411 bfd_elf64_swap_symbol_in,
5412 bfd_elf64_swap_symbol_out,
5413 bfd_elf64_slurp_reloc_table,
5414 bfd_elf64_slurp_symbol_table,
5415 bfd_elf64_swap_dyn_in,
5416 bfd_elf64_swap_dyn_out,
5417 bfd_elf64_swap_reloc_in,
5418 bfd_elf64_swap_reloc_out,
5419 bfd_elf64_swap_reloca_in,
5420 bfd_elf64_swap_reloca_out
5423 #define ELF_ARCH bfd_arch_ia64
5424 #define ELF_MACHINE_CODE EM_IA_64
5425 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5426 #define ELF_COMMONPAGESIZE 0x200 /* 16KB */
5428 #define elf_backend_section_from_shdr \
5429 elf64_ia64_section_from_shdr
5430 #define elf_backend_section_flags \
5431 elf64_ia64_section_flags
5432 #define elf_backend_fake_sections \
5433 elf64_ia64_fake_sections
5434 #define elf_backend_final_write_processing \
5435 elf64_ia64_final_write_processing
5436 #define elf_backend_add_symbol_hook \
5437 elf64_ia64_add_symbol_hook
5438 #define elf_info_to_howto \
5439 elf64_ia64_info_to_howto
5441 #define bfd_elf64_bfd_reloc_type_lookup \
5442 ia64_elf_reloc_type_lookup
5443 #define bfd_elf64_bfd_reloc_name_lookup \
5444 ia64_elf_reloc_name_lookup
5445 #define bfd_elf64_bfd_is_local_label_name \
5446 elf64_ia64_is_local_label_name
5447 #define bfd_elf64_bfd_relax_section \
5448 elf64_ia64_relax_section
5450 #define elf_backend_object_p \
5453 /* Stuff for the BFD linker: */
5454 #define bfd_elf64_bfd_link_hash_table_create \
5455 elf64_ia64_hash_table_create
5456 #define bfd_elf64_bfd_link_hash_table_free \
5457 elf64_ia64_hash_table_free
5458 #define elf_backend_create_dynamic_sections \
5459 elf64_ia64_create_dynamic_sections
5460 #define elf_backend_check_relocs \
5461 elf64_ia64_check_relocs
5462 #define elf_backend_adjust_dynamic_symbol \
5463 elf64_ia64_adjust_dynamic_symbol
5464 #define elf_backend_size_dynamic_sections \
5465 elf64_ia64_size_dynamic_sections
5466 #define elf_backend_omit_section_dynsym \
5467 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
5468 #define elf_backend_relocate_section \
5469 elf64_ia64_relocate_section
5470 #define elf_backend_finish_dynamic_symbol \
5471 elf64_ia64_finish_dynamic_symbol
5472 #define elf_backend_finish_dynamic_sections \
5473 elf64_ia64_finish_dynamic_sections
5474 #define bfd_elf64_bfd_final_link \
5475 elf64_ia64_final_link
5477 #define bfd_elf64_bfd_merge_private_bfd_data \
5478 elf64_ia64_merge_private_bfd_data
5479 #define bfd_elf64_bfd_set_private_flags \
5480 elf64_ia64_set_private_flags
5481 #define bfd_elf64_bfd_print_private_bfd_data \
5482 elf64_ia64_print_private_bfd_data
5484 #define elf_backend_plt_readonly 1
5485 #define elf_backend_want_plt_sym 0
5486 #define elf_backend_plt_alignment 5
5487 #define elf_backend_got_header_size 0
5488 #define elf_backend_want_got_plt 1
5489 #define elf_backend_may_use_rel_p 1
5490 #define elf_backend_may_use_rela_p 1
5491 #define elf_backend_default_use_rela_p 1
5492 #define elf_backend_want_dynbss 0
5493 #define elf_backend_hide_symbol elf64_ia64_hash_hide_symbol
5494 #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol
5495 #define elf_backend_reloc_type_class elf64_ia64_reloc_type_class
5496 #define elf_backend_rela_normal 1
5497 #define elf_backend_special_sections elf64_ia64_special_sections
5498 #define elf_backend_default_execstack 0
5500 /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
5501 SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
5502 We don't want to flood users with so many error messages. We turn
5503 off the warning for now. It will be turned on later when the Intel
5504 compiler is fixed. */
5505 #define elf_backend_link_order_error_handler NULL
5507 /* VMS-specific vectors. */
5509 #undef TARGET_LITTLE_SYM
5510 #define TARGET_LITTLE_SYM bfd_elf64_ia64_vms_vec
5511 #undef TARGET_LITTLE_NAME
5512 #define TARGET_LITTLE_NAME "elf64-ia64-vms"
5513 #undef TARGET_BIG_SYM
5514 #undef TARGET_BIG_NAME
5516 /* These are VMS specific functions. */
5518 #undef elf_backend_object_p
5519 #define elf_backend_object_p elf64_vms_object_p
5521 #undef elf_backend_section_from_shdr
5522 #define elf_backend_section_from_shdr elf64_vms_section_from_shdr
5524 #undef elf_backend_post_process_headers
5525 #define elf_backend_post_process_headers elf64_vms_post_process_headers
5527 #undef elf_backend_section_processing
5528 #define elf_backend_section_processing elf64_vms_section_processing
5530 #undef elf_backend_final_write_processing
5531 #define elf_backend_final_write_processing elf64_vms_final_write_processing
5533 #undef bfd_elf64_close_and_cleanup
5534 #define bfd_elf64_close_and_cleanup elf64_vms_close_and_cleanup
5536 #undef elf_backend_section_from_bfd_section
5538 #undef elf_backend_symbol_processing
5540 #undef elf_backend_want_p_paddr_set_to_zero
5543 #define ELF_OSABI ELFOSABI_OPENVMS
5545 #undef ELF_MAXPAGESIZE
5546 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5549 #define elf64_bed elf64_ia64_vms_bed
5551 #define elf_backend_size_info elf64_ia64_vms_size_info
5553 /* Use VMS-style archives (in particular, don't use the standard coff
5555 #define bfd_elf64_archive_functions
5557 #undef bfd_elf64_archive_p
5558 #define bfd_elf64_archive_p _bfd_vms_lib_ia64_archive_p
5559 #undef bfd_elf64_write_archive_contents
5560 #define bfd_elf64_write_archive_contents _bfd_vms_lib_write_archive_contents
5561 #undef bfd_elf64_mkarchive
5562 #define bfd_elf64_mkarchive _bfd_vms_lib_ia64_mkarchive
5564 #define bfd_elf64_archive_slurp_armap \
5565 _bfd_vms_lib_slurp_armap
5566 #define bfd_elf64_archive_slurp_extended_name_table \
5567 _bfd_vms_lib_slurp_extended_name_table
5568 #define bfd_elf64_archive_construct_extended_name_table \
5569 _bfd_vms_lib_construct_extended_name_table
5570 #define bfd_elf64_archive_truncate_arname \
5571 _bfd_vms_lib_truncate_arname
5572 #define bfd_elf64_archive_write_armap \
5573 _bfd_vms_lib_write_armap
5574 #define bfd_elf64_archive_read_ar_hdr \
5575 _bfd_vms_lib_read_ar_hdr
5576 #define bfd_elf64_archive_write_ar_hdr \
5577 _bfd_vms_lib_write_ar_hdr
5578 #define bfd_elf64_archive_openr_next_archived_file \
5579 _bfd_vms_lib_openr_next_archived_file
5580 #define bfd_elf64_archive_get_elt_at_index \
5581 _bfd_vms_lib_get_elt_at_index
5582 #define bfd_elf64_archive_generic_stat_arch_elt \
5583 _bfd_vms_lib_generic_stat_arch_elt
5584 #define bfd_elf64_archive_update_armap_timestamp \
5585 _bfd_vms_lib_update_armap_timestamp
5587 /* VMS link methods. */
5588 #undef bfd_elf64_bfd_link_add_symbols
5589 #define bfd_elf64_bfd_link_add_symbols elf64_vms_bfd_link_add_symbols
5591 #undef elf_backend_want_got_sym
5592 #define elf_backend_want_got_sym 0
5594 #undef bfd_elf64_mkobject
5595 #define bfd_elf64_mkobject elf64_ia64_vms_mkobject
5597 /* Redefine to align segments on block size. */
5598 #undef ELF_MAXPAGESIZE
5599 #define ELF_MAXPAGESIZE 0x200 /* 512B */
5601 #undef elf_backend_want_got_plt
5602 #define elf_backend_want_got_plt 0
5604 #include "elf64-target.h"