1 /* IA-64 support for 64-bit ELF
2 Copyright (C) 1998-2018 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
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 "bfd_stdint.h"
31 #include "elfxx-ia64.h"
36 #define LOG_SECTION_ALIGN 3
40 #define LOG_SECTION_ALIGN 2
43 typedef struct bfd_hash_entry *(*new_hash_entry_func)
44 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
46 /* In dynamically (linker-) created sections, we generally need to keep track
47 of the place a symbol or expression got allocated to. This is done via hash
48 tables that store entries of the following type. */
50 struct elfNN_ia64_dyn_sym_info
52 /* The addend for which this entry is relevant. */
57 bfd_vma pltoff_offset;
61 bfd_vma dtpmod_offset;
62 bfd_vma dtprel_offset;
64 /* The symbol table entry, if any, that this was derived from. */
65 struct elf_link_hash_entry *h;
67 /* Used to count non-got, non-plt relocations for delayed sizing
68 of relocation sections. */
69 struct elfNN_ia64_dyn_reloc_entry
71 struct elfNN_ia64_dyn_reloc_entry *next;
76 /* Is this reloc against readonly section? */
80 /* TRUE when the section contents have been updated. */
81 unsigned got_done : 1;
82 unsigned fptr_done : 1;
83 unsigned pltoff_done : 1;
84 unsigned tprel_done : 1;
85 unsigned dtpmod_done : 1;
86 unsigned dtprel_done : 1;
88 /* TRUE for the different kinds of linker data we want created. */
89 unsigned want_got : 1;
90 unsigned want_gotx : 1;
91 unsigned want_fptr : 1;
92 unsigned want_ltoff_fptr : 1;
93 unsigned want_plt : 1;
94 unsigned want_plt2 : 1;
95 unsigned want_pltoff : 1;
96 unsigned want_tprel : 1;
97 unsigned want_dtpmod : 1;
98 unsigned want_dtprel : 1;
101 struct elfNN_ia64_local_hash_entry
105 /* The number of elements in elfNN_ia64_dyn_sym_info array. */
107 /* The number of sorted elements in elfNN_ia64_dyn_sym_info array. */
108 unsigned int sorted_count;
109 /* The size of elfNN_ia64_dyn_sym_info array. */
111 /* The array of elfNN_ia64_dyn_sym_info. */
112 struct elfNN_ia64_dyn_sym_info *info;
114 /* TRUE if this hash entry's addends was translated for
115 SHF_MERGE optimization. */
116 unsigned sec_merge_done : 1;
119 struct elfNN_ia64_link_hash_entry
121 struct elf_link_hash_entry root;
122 /* The number of elements in elfNN_ia64_dyn_sym_info array. */
124 /* The number of sorted elements in elfNN_ia64_dyn_sym_info array. */
125 unsigned int sorted_count;
126 /* The size of elfNN_ia64_dyn_sym_info array. */
128 /* The array of elfNN_ia64_dyn_sym_info. */
129 struct elfNN_ia64_dyn_sym_info *info;
132 struct elfNN_ia64_link_hash_table
134 /* The main hash table. */
135 struct elf_link_hash_table root;
137 asection *fptr_sec; /* Function descriptor table (or NULL). */
138 asection *rel_fptr_sec; /* Dynamic relocation section for same. */
139 asection *pltoff_sec; /* Private descriptors for plt (or NULL). */
140 asection *rel_pltoff_sec; /* Dynamic relocation section for same. */
142 bfd_size_type minplt_entries; /* Number of minplt entries. */
143 unsigned reltext : 1; /* Are there relocs against readonly sections? */
144 unsigned self_dtpmod_done : 1;/* Has self DTPMOD entry been finished? */
145 bfd_vma self_dtpmod_offset; /* .got offset to self DTPMOD entry. */
146 /* There are maybe R_IA64_GPREL22 relocations, including those
147 optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT
148 sections. We need to record those sections so that we can choose
149 a proper GP to cover all R_IA64_GPREL22 relocations. */
150 asection *max_short_sec; /* Maximum short output section. */
151 bfd_vma max_short_offset; /* Maximum short offset. */
152 asection *min_short_sec; /* Minimum short output section. */
153 bfd_vma min_short_offset; /* Minimum short offset. */
155 htab_t loc_hash_table;
156 void *loc_hash_memory;
159 struct elfNN_ia64_allocate_data
161 struct bfd_link_info *info;
163 bfd_boolean only_got;
166 #define elfNN_ia64_hash_table(p) \
167 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
168 == IA64_ELF_DATA ? ((struct elfNN_ia64_link_hash_table *) ((p)->hash)) : NULL)
170 static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info
171 (struct elfNN_ia64_link_hash_table *ia64_info,
172 struct elf_link_hash_entry *h,
173 bfd *abfd, const Elf_Internal_Rela *rel, bfd_boolean create);
174 static bfd_boolean elfNN_ia64_dynamic_symbol_p
175 (struct elf_link_hash_entry *h, struct bfd_link_info *info, int);
176 static bfd_boolean elfNN_ia64_choose_gp
177 (bfd *abfd, struct bfd_link_info *info, bfd_boolean final);
178 static void elfNN_ia64_dyn_sym_traverse
179 (struct elfNN_ia64_link_hash_table *ia64_info,
180 bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, void *),
182 static bfd_boolean allocate_global_data_got
183 (struct elfNN_ia64_dyn_sym_info *dyn_i, void * data);
184 static bfd_boolean allocate_global_fptr_got
185 (struct elfNN_ia64_dyn_sym_info *dyn_i, void * data);
186 static bfd_boolean allocate_local_got
187 (struct elfNN_ia64_dyn_sym_info *dyn_i, void * data);
188 static bfd_boolean elfNN_ia64_hpux_vec
189 (const bfd_target *vec);
190 static bfd_boolean allocate_dynrel_entries
191 (struct elfNN_ia64_dyn_sym_info *dyn_i, void * data);
192 static asection *get_pltoff
193 (bfd *abfd, struct bfd_link_info *info,
194 struct elfNN_ia64_link_hash_table *ia64_info);
196 /* ia64-specific relocation. */
198 /* Given a ELF reloc, return the matching HOWTO structure. */
201 elfNN_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
203 Elf_Internal_Rela *elf_reloc)
205 unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info);
207 bfd_reloc->howto = ia64_elf_lookup_howto (r_type);
208 if (bfd_reloc->howto == NULL)
210 /* xgettext:c-format */
211 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
213 bfd_set_error (bfd_error_bad_value);
220 #define PLT_HEADER_SIZE (3 * 16)
221 #define PLT_MIN_ENTRY_SIZE (1 * 16)
222 #define PLT_FULL_ENTRY_SIZE (2 * 16)
223 #define PLT_RESERVED_WORDS 3
225 static const bfd_byte plt_header[PLT_HEADER_SIZE] =
227 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */
228 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */
229 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
230 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */
231 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */
232 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
233 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */
234 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */
235 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
238 static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] =
240 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */
241 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */
242 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */
245 static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
247 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
248 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/
249 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
250 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
251 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
252 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
255 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
257 static const bfd_byte oor_brl[16] =
259 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */
261 0x00, 0x00, 0x00, 0xc0
264 static const bfd_byte oor_ip[48] =
266 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */
268 0x01, 0x00, 0x00, 0x60,
269 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */
270 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */
271 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */
272 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */
273 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
274 0x60, 0x00, 0x80, 0x00 /* br b6;; */
277 static size_t oor_branch_size = sizeof (oor_brl);
280 bfd_elfNN_ia64_after_parse (int itanium)
282 oor_branch_size = itanium ? sizeof (oor_ip) : sizeof (oor_brl);
286 /* Rename some of the generic section flags to better document how they
288 #define skip_relax_pass_0 sec_flg0
289 #define skip_relax_pass_1 sec_flg1
291 /* These functions do relaxation for IA-64 ELF. */
294 elfNN_ia64_update_short_info (asection *sec, bfd_vma offset,
295 struct elfNN_ia64_link_hash_table *ia64_info)
297 /* Skip ABS and SHF_IA_64_SHORT sections. */
298 if (sec == bfd_abs_section_ptr
299 || (sec->flags & SEC_SMALL_DATA) != 0)
302 if (!ia64_info->min_short_sec)
304 ia64_info->max_short_sec = sec;
305 ia64_info->max_short_offset = offset;
306 ia64_info->min_short_sec = sec;
307 ia64_info->min_short_offset = offset;
309 else if (sec == ia64_info->max_short_sec
310 && offset > ia64_info->max_short_offset)
311 ia64_info->max_short_offset = offset;
312 else if (sec == ia64_info->min_short_sec
313 && offset < ia64_info->min_short_offset)
314 ia64_info->min_short_offset = offset;
315 else if (sec->output_section->vma
316 > ia64_info->max_short_sec->vma)
318 ia64_info->max_short_sec = sec;
319 ia64_info->max_short_offset = offset;
321 else if (sec->output_section->vma
322 < ia64_info->min_short_sec->vma)
324 ia64_info->min_short_sec = sec;
325 ia64_info->min_short_offset = offset;
330 elfNN_ia64_relax_section (bfd *abfd, asection *sec,
331 struct bfd_link_info *link_info,
336 struct one_fixup *next;
342 Elf_Internal_Shdr *symtab_hdr;
343 Elf_Internal_Rela *internal_relocs;
344 Elf_Internal_Rela *irel, *irelend;
346 Elf_Internal_Sym *isymbuf = NULL;
347 struct elfNN_ia64_link_hash_table *ia64_info;
348 struct one_fixup *fixups = NULL;
349 bfd_boolean changed_contents = FALSE;
350 bfd_boolean changed_relocs = FALSE;
351 bfd_boolean changed_got = FALSE;
352 bfd_boolean skip_relax_pass_0 = TRUE;
353 bfd_boolean skip_relax_pass_1 = TRUE;
356 /* Assume we're not going to change any sizes, and we'll only need
360 if (bfd_link_relocatable (link_info))
361 (*link_info->callbacks->einfo)
362 (_("%P%F: --relax and -r may not be used together\n"));
364 /* Don't even try to relax for non-ELF outputs. */
365 if (!is_elf_hash_table (link_info->hash))
368 /* Nothing to do if there are no relocations or there is no need for
370 if ((sec->flags & SEC_RELOC) == 0
371 || sec->reloc_count == 0
372 || (link_info->relax_pass == 0 && sec->skip_relax_pass_0)
373 || (link_info->relax_pass == 1 && sec->skip_relax_pass_1))
376 ia64_info = elfNN_ia64_hash_table (link_info);
377 if (ia64_info == NULL)
380 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
382 /* Load the relocations for this section. */
383 internal_relocs = (_bfd_elf_link_read_relocs
384 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
385 link_info->keep_memory));
386 if (internal_relocs == NULL)
389 irelend = internal_relocs + sec->reloc_count;
391 /* Get the section contents. */
392 if (elf_section_data (sec)->this_hdr.contents != NULL)
393 contents = elf_section_data (sec)->this_hdr.contents;
396 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
400 for (irel = internal_relocs; irel < irelend; irel++)
402 unsigned long r_type = ELFNN_R_TYPE (irel->r_info);
403 bfd_vma symaddr, reladdr, trampoff, toff, roff;
407 bfd_boolean is_branch;
408 struct elfNN_ia64_dyn_sym_info *dyn_i;
413 case R_IA64_PCREL21B:
414 case R_IA64_PCREL21BI:
415 case R_IA64_PCREL21M:
416 case R_IA64_PCREL21F:
417 /* In pass 1, all br relaxations are done. We can skip it. */
418 if (link_info->relax_pass == 1)
420 skip_relax_pass_0 = FALSE;
424 case R_IA64_PCREL60B:
425 /* We can't optimize brl to br in pass 0 since br relaxations
426 will increase the code size. Defer it to pass 1. */
427 if (link_info->relax_pass == 0)
429 skip_relax_pass_1 = FALSE;
436 /* Update max_short_sec/min_short_sec. */
438 case R_IA64_LTOFF22X:
440 /* We can't relax ldx/mov in pass 0 since br relaxations will
441 increase the code size. Defer it to pass 1. */
442 if (link_info->relax_pass == 0)
444 skip_relax_pass_1 = FALSE;
454 /* Get the value of the symbol referred to by the reloc. */
455 if (ELFNN_R_SYM (irel->r_info) < symtab_hdr->sh_info)
457 /* A local symbol. */
458 Elf_Internal_Sym *isym;
460 /* Read this BFD's local symbols. */
463 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
465 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
466 symtab_hdr->sh_info, 0,
472 isym = isymbuf + ELFNN_R_SYM (irel->r_info);
473 if (isym->st_shndx == SHN_UNDEF)
474 continue; /* We can't do anything with undefined symbols. */
475 else if (isym->st_shndx == SHN_ABS)
476 tsec = bfd_abs_section_ptr;
477 else if (isym->st_shndx == SHN_COMMON)
478 tsec = bfd_com_section_ptr;
479 else if (isym->st_shndx == SHN_IA_64_ANSI_COMMON)
480 tsec = bfd_com_section_ptr;
482 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
484 toff = isym->st_value;
485 dyn_i = get_dyn_sym_info (ia64_info, NULL, abfd, irel, FALSE);
486 symtype = ELF_ST_TYPE (isym->st_info);
491 struct elf_link_hash_entry *h;
493 indx = ELFNN_R_SYM (irel->r_info) - symtab_hdr->sh_info;
494 h = elf_sym_hashes (abfd)[indx];
495 BFD_ASSERT (h != NULL);
497 while (h->root.type == bfd_link_hash_indirect
498 || h->root.type == bfd_link_hash_warning)
499 h = (struct elf_link_hash_entry *) h->root.u.i.link;
501 dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, FALSE);
503 /* For branches to dynamic symbols, we're interested instead
504 in a branch to the PLT entry. */
505 if (is_branch && dyn_i && dyn_i->want_plt2)
507 /* Internal branches shouldn't be sent to the PLT.
508 Leave this for now and we'll give an error later. */
509 if (r_type != R_IA64_PCREL21B)
512 tsec = ia64_info->root.splt;
513 toff = dyn_i->plt2_offset;
514 BFD_ASSERT (irel->r_addend == 0);
517 /* Can't do anything else with dynamic symbols. */
518 else if (elfNN_ia64_dynamic_symbol_p (h, link_info, r_type))
523 /* We can't do anything with undefined symbols. */
524 if (h->root.type == bfd_link_hash_undefined
525 || h->root.type == bfd_link_hash_undefweak)
528 tsec = h->root.u.def.section;
529 toff = h->root.u.def.value;
535 if (tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
537 /* At this stage in linking, no SEC_MERGE symbol has been
538 adjusted, so all references to such symbols need to be
539 passed through _bfd_merged_section_offset. (Later, in
540 relocate_section, all SEC_MERGE symbols *except* for
541 section symbols have been adjusted.)
543 gas may reduce relocations against symbols in SEC_MERGE
544 sections to a relocation against the section symbol when
545 the original addend was zero. When the reloc is against
546 a section symbol we should include the addend in the
547 offset passed to _bfd_merged_section_offset, since the
548 location of interest is the original symbol. On the
549 other hand, an access to "sym+addend" where "sym" is not
550 a section symbol should not include the addend; Such an
551 access is presumed to be an offset from "sym"; The
552 location of interest is just "sym". */
553 if (symtype == STT_SECTION)
554 toff += irel->r_addend;
556 toff = _bfd_merged_section_offset (abfd, &tsec,
557 elf_section_data (tsec)->sec_info,
560 if (symtype != STT_SECTION)
561 toff += irel->r_addend;
564 toff += irel->r_addend;
566 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
568 roff = irel->r_offset;
572 bfd_signed_vma offset;
574 reladdr = (sec->output_section->vma
576 + roff) & (bfd_vma) -4;
578 /* The .plt section is aligned at 32byte and the .text section
579 is aligned at 64byte. The .text section is right after the
580 .plt section. After the first relaxation pass, linker may
581 increase the gap between the .plt and .text sections up
582 to 32byte. We assume linker will always insert 32byte
583 between the .plt and .text sections after the first
585 if (tsec == ia64_info->root.splt)
586 offset = -0x1000000 + 32;
590 /* If the branch is in range, no need to do anything. */
591 if ((bfd_signed_vma) (symaddr - reladdr) >= offset
592 && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
594 /* If the 60-bit branch is in 21-bit range, optimize it. */
595 if (r_type == R_IA64_PCREL60B)
597 ia64_elf_relax_brl (contents, roff);
600 = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
603 /* If the original relocation offset points to slot
604 1, change it to slot 2. */
605 if ((irel->r_offset & 3) == 1)
608 changed_contents = TRUE;
609 changed_relocs = TRUE;
614 else if (r_type == R_IA64_PCREL60B)
616 else if (ia64_elf_relax_br (contents, roff))
619 = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
622 /* Make the relocation offset point to slot 1. */
623 irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1;
625 changed_contents = TRUE;
626 changed_relocs = TRUE;
630 /* We can't put a trampoline in a .init/.fini section. Issue
632 if (strcmp (sec->output_section->name, ".init") == 0
633 || strcmp (sec->output_section->name, ".fini") == 0)
636 /* xgettext:c-format */
637 (_("%pB: can't relax br at %#" PRIx64 " in section `%pA';"
638 " please use brl or indirect branch"),
639 sec->owner, (uint64_t) roff, sec);
640 bfd_set_error (bfd_error_bad_value);
644 /* If the branch and target are in the same section, you've
645 got one honking big section and we can't help you unless
646 you are branching backwards. You'll get an error message
648 if (tsec == sec && toff > roff)
651 /* Look for an existing fixup to this address. */
652 for (f = fixups; f ; f = f->next)
653 if (f->tsec == tsec && f->toff == toff)
658 /* Two alternatives: If it's a branch to a PLT entry, we can
659 make a copy of the FULL_PLT entry. Otherwise, we'll have
660 to use a `brl' insn to get where we're going. */
664 if (tsec == ia64_info->root.splt)
665 size = sizeof (plt_full_entry);
667 size = oor_branch_size;
669 /* Resize the current section to make room for the new branch. */
670 trampoff = (sec->size + 15) & (bfd_vma) -16;
672 /* If trampoline is out of range, there is nothing we
674 offset = trampoff - (roff & (bfd_vma) -4);
675 if (offset < -0x1000000 || offset > 0x0FFFFF0)
678 amt = trampoff + size;
679 contents = (bfd_byte *) bfd_realloc (contents, amt);
680 if (contents == NULL)
684 if (tsec == ia64_info->root.splt)
686 memcpy (contents + trampoff, plt_full_entry, size);
688 /* Hijack the old relocation for use as the PLTOFF reloc. */
689 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
691 irel->r_offset = trampoff;
695 if (size == sizeof (oor_ip))
697 memcpy (contents + trampoff, oor_ip, size);
698 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
700 irel->r_addend -= 16;
701 irel->r_offset = trampoff + 2;
705 memcpy (contents + trampoff, oor_brl, size);
706 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
708 irel->r_offset = trampoff + 2;
713 /* Record the fixup so we don't do it again this section. */
714 f = (struct one_fixup *)
715 bfd_malloc ((bfd_size_type) sizeof (*f));
719 f->trampoff = trampoff;
724 /* If trampoline is out of range, there is nothing we
726 offset = f->trampoff - (roff & (bfd_vma) -4);
727 if (offset < -0x1000000 || offset > 0x0FFFFF0)
730 /* Nop out the reloc, since we're finalizing things here. */
731 irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
734 /* Fix up the existing branch to hit the trampoline. */
735 if (ia64_elf_install_value (contents + roff, offset, r_type)
739 changed_contents = TRUE;
740 changed_relocs = TRUE;
747 bfd *obfd = sec->output_section->owner;
748 gp = _bfd_get_gp_value (obfd);
751 if (!elfNN_ia64_choose_gp (obfd, link_info, FALSE))
753 gp = _bfd_get_gp_value (obfd);
757 /* If the data is out of range, do nothing. */
758 if ((bfd_signed_vma) (symaddr - gp) >= 0x200000
759 ||(bfd_signed_vma) (symaddr - gp) < -0x200000)
762 if (r_type == R_IA64_GPREL22)
763 elfNN_ia64_update_short_info (tsec->output_section,
764 tsec->output_offset + toff,
766 else if (r_type == R_IA64_LTOFF22X)
768 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
770 changed_relocs = TRUE;
771 if (dyn_i->want_gotx)
773 dyn_i->want_gotx = 0;
774 changed_got |= !dyn_i->want_got;
777 elfNN_ia64_update_short_info (tsec->output_section,
778 tsec->output_offset + toff,
783 ia64_elf_relax_ldxmov (contents, roff);
784 irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
785 changed_contents = TRUE;
786 changed_relocs = TRUE;
791 /* ??? If we created fixups, this may push the code segment large
792 enough that the data segment moves, which will change the GP.
793 Reset the GP so that we re-calculate next round. We need to
794 do this at the _beginning_ of the next round; now will not do. */
796 /* Clean up and go home. */
799 struct one_fixup *f = fixups;
800 fixups = fixups->next;
805 && symtab_hdr->contents != (unsigned char *) isymbuf)
807 if (! link_info->keep_memory)
811 /* Cache the symbols for elf_link_input_bfd. */
812 symtab_hdr->contents = (unsigned char *) isymbuf;
817 && elf_section_data (sec)->this_hdr.contents != contents)
819 if (!changed_contents && !link_info->keep_memory)
823 /* Cache the section contents for elf_link_input_bfd. */
824 elf_section_data (sec)->this_hdr.contents = contents;
828 if (elf_section_data (sec)->relocs != internal_relocs)
831 free (internal_relocs);
833 elf_section_data (sec)->relocs = internal_relocs;
838 struct elfNN_ia64_allocate_data data;
839 data.info = link_info;
841 ia64_info->self_dtpmod_offset = (bfd_vma) -1;
843 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data);
844 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data);
845 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data);
846 ia64_info->root.sgot->size = data.ofs;
848 if (ia64_info->root.dynamic_sections_created
849 && ia64_info->root.srelgot != NULL)
851 /* Resize .rela.got. */
852 ia64_info->root.srelgot->size = 0;
853 if (bfd_link_pic (link_info)
854 && ia64_info->self_dtpmod_offset != (bfd_vma) -1)
855 ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela);
856 data.only_got = TRUE;
857 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries,
862 if (link_info->relax_pass == 0)
864 /* Pass 0 is only needed to relax br. */
865 sec->skip_relax_pass_0 = skip_relax_pass_0;
866 sec->skip_relax_pass_1 = skip_relax_pass_1;
869 *again = changed_contents || changed_relocs;
873 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
876 && elf_section_data (sec)->this_hdr.contents != contents)
878 if (internal_relocs != NULL
879 && elf_section_data (sec)->relocs != internal_relocs)
880 free (internal_relocs);
883 #undef skip_relax_pass_0
884 #undef skip_relax_pass_1
886 /* Return TRUE if NAME is an unwind table section name. */
888 static inline bfd_boolean
889 is_unwind_section_name (bfd *abfd, const char *name)
891 if (elfNN_ia64_hpux_vec (abfd->xvec)
892 && !strcmp (name, ELF_STRING_ia64_unwind_hdr))
895 return ((CONST_STRNEQ (name, ELF_STRING_ia64_unwind)
896 && ! CONST_STRNEQ (name, ELF_STRING_ia64_unwind_info))
897 || CONST_STRNEQ (name, ELF_STRING_ia64_unwind_once));
900 /* Handle an IA-64 specific section when reading an object file. This
901 is called when bfd_section_from_shdr finds a section with an unknown
905 elfNN_ia64_section_from_shdr (bfd *abfd,
906 Elf_Internal_Shdr *hdr,
910 /* There ought to be a place to keep ELF backend specific flags, but
911 at the moment there isn't one. We just keep track of the
912 sections by their name, instead. Fortunately, the ABI gives
913 suggested names for all the MIPS specific sections, so we will
914 probably get away with this. */
915 switch (hdr->sh_type)
917 case SHT_IA_64_UNWIND:
918 case SHT_IA_64_HP_OPT_ANOT:
922 if (strcmp (name, ELF_STRING_ia64_archext) != 0)
930 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
936 /* Convert IA-64 specific section flags to bfd internal section flags. */
938 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
942 elfNN_ia64_section_flags (flagword *flags,
943 const Elf_Internal_Shdr *hdr)
945 if (hdr->sh_flags & SHF_IA_64_SHORT)
946 *flags |= SEC_SMALL_DATA;
951 /* Set the correct type for an IA-64 ELF section. We do this by the
952 section name, which is a hack, but ought to work. */
955 elfNN_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr,
960 name = bfd_get_section_name (abfd, sec);
962 if (is_unwind_section_name (abfd, name))
964 /* We don't have the sections numbered at this point, so sh_info
965 is set later, in elfNN_ia64_final_write_processing. */
966 hdr->sh_type = SHT_IA_64_UNWIND;
967 hdr->sh_flags |= SHF_LINK_ORDER;
969 else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
970 hdr->sh_type = SHT_IA_64_EXT;
971 else if (strcmp (name, ".HP.opt_annot") == 0)
972 hdr->sh_type = SHT_IA_64_HP_OPT_ANOT;
973 else if (strcmp (name, ".reloc") == 0)
974 /* This is an ugly, but unfortunately necessary hack that is
975 needed when producing EFI binaries on IA-64. It tells
976 elf.c:elf_fake_sections() not to consider ".reloc" as a section
977 containing ELF relocation info. We need this hack in order to
978 be able to generate ELF binaries that can be translated into
979 EFI applications (which are essentially COFF objects). Those
980 files contain a COFF ".reloc" section inside an ELFNN object,
981 which would normally cause BFD to segfault because it would
982 attempt to interpret this section as containing relocation
983 entries for section "oc". With this hack enabled, ".reloc"
984 will be treated as a normal data section, which will avoid the
985 segfault. However, you won't be able to create an ELFNN binary
986 with a section named "oc" that needs relocations, but that's
987 the kind of ugly side-effects you get when detecting section
988 types based on their names... In practice, this limitation is
990 hdr->sh_type = SHT_PROGBITS;
992 if (sec->flags & SEC_SMALL_DATA)
993 hdr->sh_flags |= SHF_IA_64_SHORT;
995 /* Some HP linkers look for the SHF_IA_64_HP_TLS flag instead of SHF_TLS. */
997 if (elfNN_ia64_hpux_vec (abfd->xvec) && (sec->flags & SHF_TLS))
998 hdr->sh_flags |= SHF_IA_64_HP_TLS;
1003 /* The final processing done just before writing out an IA-64 ELF
1007 elfNN_ia64_final_write_processing (bfd *abfd,
1008 bfd_boolean linker ATTRIBUTE_UNUSED)
1010 Elf_Internal_Shdr *hdr;
1013 for (s = abfd->sections; s; s = s->next)
1015 hdr = &elf_section_data (s)->this_hdr;
1016 switch (hdr->sh_type)
1018 case SHT_IA_64_UNWIND:
1019 /* The IA-64 processor-specific ABI requires setting sh_link
1020 to the unwind section, whereas HP-UX requires sh_info to
1021 do so. For maximum compatibility, we'll set both for
1023 hdr->sh_info = hdr->sh_link;
1028 if (! elf_flags_init (abfd))
1030 unsigned long flags = 0;
1032 if (abfd->xvec->byteorder == BFD_ENDIAN_BIG)
1033 flags |= EF_IA_64_BE;
1034 if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64)
1035 flags |= EF_IA_64_ABI64;
1037 elf_elfheader(abfd)->e_flags = flags;
1038 elf_flags_init (abfd) = TRUE;
1042 /* Hook called by the linker routine which adds symbols from an object
1043 file. We use it to put .comm items in .sbss, and not .bss. */
1046 elfNN_ia64_add_symbol_hook (bfd *abfd,
1047 struct bfd_link_info *info,
1048 Elf_Internal_Sym *sym,
1049 const char **namep ATTRIBUTE_UNUSED,
1050 flagword *flagsp ATTRIBUTE_UNUSED,
1054 if (sym->st_shndx == SHN_COMMON
1055 && !bfd_link_relocatable (info)
1056 && sym->st_size <= elf_gp_size (abfd))
1058 /* Common symbols less than or equal to -G nn bytes are
1059 automatically put into .sbss. */
1061 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
1065 scomm = bfd_make_section_with_flags (abfd, ".scommon",
1068 | SEC_LINKER_CREATED));
1074 *valp = sym->st_size;
1080 /* Return the number of additional phdrs we will need. */
1083 elfNN_ia64_additional_program_headers (bfd *abfd,
1084 struct bfd_link_info *info ATTRIBUTE_UNUSED)
1089 /* See if we need a PT_IA_64_ARCHEXT segment. */
1090 s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext);
1091 if (s && (s->flags & SEC_LOAD))
1094 /* Count how many PT_IA_64_UNWIND segments we need. */
1095 for (s = abfd->sections; s; s = s->next)
1096 if (is_unwind_section_name (abfd, s->name) && (s->flags & SEC_LOAD))
1103 elfNN_ia64_modify_segment_map (bfd *abfd,
1104 struct bfd_link_info *info ATTRIBUTE_UNUSED)
1106 struct elf_segment_map *m, **pm;
1107 Elf_Internal_Shdr *hdr;
1110 /* If we need a PT_IA_64_ARCHEXT segment, it must come before
1111 all PT_LOAD segments. */
1112 s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext);
1113 if (s && (s->flags & SEC_LOAD))
1115 for (m = elf_seg_map (abfd); m != NULL; m = m->next)
1116 if (m->p_type == PT_IA_64_ARCHEXT)
1120 m = ((struct elf_segment_map *)
1121 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
1125 m->p_type = PT_IA_64_ARCHEXT;
1129 /* We want to put it after the PHDR and INTERP segments. */
1130 pm = &elf_seg_map (abfd);
1132 && ((*pm)->p_type == PT_PHDR
1133 || (*pm)->p_type == PT_INTERP))
1141 /* Install PT_IA_64_UNWIND segments, if needed. */
1142 for (s = abfd->sections; s; s = s->next)
1144 hdr = &elf_section_data (s)->this_hdr;
1145 if (hdr->sh_type != SHT_IA_64_UNWIND)
1148 if (s && (s->flags & SEC_LOAD))
1150 for (m = elf_seg_map (abfd); m != NULL; m = m->next)
1151 if (m->p_type == PT_IA_64_UNWIND)
1155 /* Look through all sections in the unwind segment
1156 for a match since there may be multiple sections
1158 for (i = m->count - 1; i >= 0; --i)
1159 if (m->sections[i] == s)
1168 m = ((struct elf_segment_map *)
1169 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
1173 m->p_type = PT_IA_64_UNWIND;
1178 /* We want to put it last. */
1179 pm = &elf_seg_map (abfd);
1190 /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of
1191 the input sections for each output section in the segment and testing
1192 for SHF_IA_64_NORECOV on each. */
1195 elfNN_ia64_modify_program_headers (bfd *abfd,
1196 struct bfd_link_info *info ATTRIBUTE_UNUSED)
1198 struct elf_obj_tdata *tdata = elf_tdata (abfd);
1199 struct elf_segment_map *m;
1200 Elf_Internal_Phdr *p;
1202 for (p = tdata->phdr, m = elf_seg_map (abfd); m != NULL; m = m->next, p++)
1203 if (m->p_type == PT_LOAD)
1206 for (i = m->count - 1; i >= 0; --i)
1208 struct bfd_link_order *order = m->sections[i]->map_head.link_order;
1210 while (order != NULL)
1212 if (order->type == bfd_indirect_link_order)
1214 asection *is = order->u.indirect.section;
1215 bfd_vma flags = elf_section_data(is)->this_hdr.sh_flags;
1216 if (flags & SHF_IA_64_NORECOV)
1218 p->p_flags |= PF_IA_64_NORECOV;
1222 order = order->next;
1231 /* According to the Tahoe assembler spec, all labels starting with a
1235 elfNN_ia64_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
1238 return name[0] == '.';
1241 /* Should we do dynamic things to this symbol? */
1244 elfNN_ia64_dynamic_symbol_p (struct elf_link_hash_entry *h,
1245 struct bfd_link_info *info, int r_type)
1247 bfd_boolean ignore_protected
1248 = ((r_type & 0xf8) == 0x40 /* FPTR relocs */
1249 || (r_type & 0xf8) == 0x50); /* LTOFF_FPTR relocs */
1251 return _bfd_elf_dynamic_symbol_p (h, info, ignore_protected);
1254 static struct bfd_hash_entry*
1255 elfNN_ia64_new_elf_hash_entry (struct bfd_hash_entry *entry,
1256 struct bfd_hash_table *table,
1259 struct elfNN_ia64_link_hash_entry *ret;
1260 ret = (struct elfNN_ia64_link_hash_entry *) entry;
1262 /* Allocate the structure if it has not already been allocated by a
1265 ret = bfd_hash_allocate (table, sizeof (*ret));
1270 /* Call the allocation method of the superclass. */
1271 ret = ((struct elfNN_ia64_link_hash_entry *)
1272 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1277 ret->sorted_count = 0;
1279 return (struct bfd_hash_entry *) ret;
1283 elfNN_ia64_hash_copy_indirect (struct bfd_link_info *info,
1284 struct elf_link_hash_entry *xdir,
1285 struct elf_link_hash_entry *xind)
1287 struct elfNN_ia64_link_hash_entry *dir, *ind;
1289 dir = (struct elfNN_ia64_link_hash_entry *) xdir;
1290 ind = (struct elfNN_ia64_link_hash_entry *) xind;
1292 /* Copy down any references that we may have already seen to the
1293 symbol which just became indirect. */
1295 if (dir->root.versioned != versioned_hidden)
1296 dir->root.ref_dynamic |= ind->root.ref_dynamic;
1297 dir->root.ref_regular |= ind->root.ref_regular;
1298 dir->root.ref_regular_nonweak |= ind->root.ref_regular_nonweak;
1299 dir->root.needs_plt |= ind->root.needs_plt;
1301 if (ind->root.root.type != bfd_link_hash_indirect)
1304 /* Copy over the got and plt data. This would have been done
1307 if (ind->info != NULL)
1309 struct elfNN_ia64_dyn_sym_info *dyn_i;
1315 dir->info = ind->info;
1316 dir->count = ind->count;
1317 dir->sorted_count = ind->sorted_count;
1318 dir->size = ind->size;
1322 ind->sorted_count = 0;
1325 /* Fix up the dyn_sym_info pointers to the global symbol. */
1326 for (count = dir->count, dyn_i = dir->info;
1329 dyn_i->h = &dir->root;
1332 /* Copy over the dynindx. */
1334 if (ind->root.dynindx != -1)
1336 if (dir->root.dynindx != -1)
1337 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1338 dir->root.dynstr_index);
1339 dir->root.dynindx = ind->root.dynindx;
1340 dir->root.dynstr_index = ind->root.dynstr_index;
1341 ind->root.dynindx = -1;
1342 ind->root.dynstr_index = 0;
1347 elfNN_ia64_hash_hide_symbol (struct bfd_link_info *info,
1348 struct elf_link_hash_entry *xh,
1349 bfd_boolean force_local)
1351 struct elfNN_ia64_link_hash_entry *h;
1352 struct elfNN_ia64_dyn_sym_info *dyn_i;
1355 h = (struct elfNN_ia64_link_hash_entry *)xh;
1357 _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
1359 for (count = h->count, dyn_i = h->info;
1363 dyn_i->want_plt2 = 0;
1364 dyn_i->want_plt = 0;
1368 /* Compute a hash of a local hash entry. */
1371 elfNN_ia64_local_htab_hash (const void *ptr)
1373 struct elfNN_ia64_local_hash_entry *entry
1374 = (struct elfNN_ia64_local_hash_entry *) ptr;
1376 return ELF_LOCAL_SYMBOL_HASH (entry->id, entry->r_sym);
1379 /* Compare local hash entries. */
1382 elfNN_ia64_local_htab_eq (const void *ptr1, const void *ptr2)
1384 struct elfNN_ia64_local_hash_entry *entry1
1385 = (struct elfNN_ia64_local_hash_entry *) ptr1;
1386 struct elfNN_ia64_local_hash_entry *entry2
1387 = (struct elfNN_ia64_local_hash_entry *) ptr2;
1389 return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym;
1392 /* Free the global elfNN_ia64_dyn_sym_info array. */
1395 elfNN_ia64_global_dyn_info_free (void **xentry,
1396 void * unused ATTRIBUTE_UNUSED)
1398 struct elfNN_ia64_link_hash_entry *entry
1399 = (struct elfNN_ia64_link_hash_entry *) xentry;
1406 entry->sorted_count = 0;
1413 /* Free the local elfNN_ia64_dyn_sym_info array. */
1416 elfNN_ia64_local_dyn_info_free (void **slot,
1417 void * unused ATTRIBUTE_UNUSED)
1419 struct elfNN_ia64_local_hash_entry *entry
1420 = (struct elfNN_ia64_local_hash_entry *) *slot;
1427 entry->sorted_count = 0;
1434 /* Destroy IA-64 linker hash table. */
1437 elfNN_ia64_link_hash_table_free (bfd *obfd)
1439 struct elfNN_ia64_link_hash_table *ia64_info
1440 = (struct elfNN_ia64_link_hash_table *) obfd->link.hash;
1441 if (ia64_info->loc_hash_table)
1443 htab_traverse (ia64_info->loc_hash_table,
1444 elfNN_ia64_local_dyn_info_free, NULL);
1445 htab_delete (ia64_info->loc_hash_table);
1447 if (ia64_info->loc_hash_memory)
1448 objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
1449 elf_link_hash_traverse (&ia64_info->root,
1450 elfNN_ia64_global_dyn_info_free, NULL);
1451 _bfd_elf_link_hash_table_free (obfd);
1454 /* Create the derived linker hash table. The IA-64 ELF port uses this
1455 derived hash table to keep information specific to the IA-64 ElF
1456 linker (without using static variables). */
1458 static struct bfd_link_hash_table *
1459 elfNN_ia64_hash_table_create (bfd *abfd)
1461 struct elfNN_ia64_link_hash_table *ret;
1463 ret = bfd_zmalloc ((bfd_size_type) sizeof (*ret));
1467 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
1468 elfNN_ia64_new_elf_hash_entry,
1469 sizeof (struct elfNN_ia64_link_hash_entry),
1476 ret->loc_hash_table = htab_try_create (1024, elfNN_ia64_local_htab_hash,
1477 elfNN_ia64_local_htab_eq, NULL);
1478 ret->loc_hash_memory = objalloc_create ();
1479 if (!ret->loc_hash_table || !ret->loc_hash_memory)
1481 elfNN_ia64_link_hash_table_free (abfd);
1484 ret->root.root.hash_table_free = elfNN_ia64_link_hash_table_free;
1486 return &ret->root.root;
1489 /* Traverse both local and global hash tables. */
1491 struct elfNN_ia64_dyn_sym_traverse_data
1493 bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, void *);
1498 elfNN_ia64_global_dyn_sym_thunk (struct bfd_hash_entry *xentry,
1501 struct elfNN_ia64_link_hash_entry *entry
1502 = (struct elfNN_ia64_link_hash_entry *) xentry;
1503 struct elfNN_ia64_dyn_sym_traverse_data *data
1504 = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
1505 struct elfNN_ia64_dyn_sym_info *dyn_i;
1508 for (count = entry->count, dyn_i = entry->info;
1511 if (! (*data->func) (dyn_i, data->data))
1517 elfNN_ia64_local_dyn_sym_thunk (void **slot, void * xdata)
1519 struct elfNN_ia64_local_hash_entry *entry
1520 = (struct elfNN_ia64_local_hash_entry *) *slot;
1521 struct elfNN_ia64_dyn_sym_traverse_data *data
1522 = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
1523 struct elfNN_ia64_dyn_sym_info *dyn_i;
1526 for (count = entry->count, dyn_i = entry->info;
1529 if (! (*data->func) (dyn_i, data->data))
1535 elfNN_ia64_dyn_sym_traverse (struct elfNN_ia64_link_hash_table *ia64_info,
1536 bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, void *),
1539 struct elfNN_ia64_dyn_sym_traverse_data xdata;
1544 elf_link_hash_traverse (&ia64_info->root,
1545 elfNN_ia64_global_dyn_sym_thunk, &xdata);
1546 htab_traverse (ia64_info->loc_hash_table,
1547 elfNN_ia64_local_dyn_sym_thunk, &xdata);
1551 elfNN_ia64_create_dynamic_sections (bfd *abfd,
1552 struct bfd_link_info *info)
1554 struct elfNN_ia64_link_hash_table *ia64_info;
1557 if (! _bfd_elf_create_dynamic_sections (abfd, info))
1560 ia64_info = elfNN_ia64_hash_table (info);
1561 if (ia64_info == NULL)
1565 flagword flags = bfd_get_section_flags (abfd, ia64_info->root.sgot);
1566 bfd_set_section_flags (abfd, ia64_info->root.sgot,
1567 SEC_SMALL_DATA | flags);
1568 /* The .got section is always aligned at 8 bytes. */
1569 if (! bfd_set_section_alignment (abfd, ia64_info->root.sgot, 3))
1573 if (!get_pltoff (abfd, info, ia64_info))
1576 s = bfd_make_section_anyway_with_flags (abfd, ".rela.IA_64.pltoff",
1577 (SEC_ALLOC | SEC_LOAD
1580 | SEC_LINKER_CREATED
1583 || !bfd_set_section_alignment (abfd, s, LOG_SECTION_ALIGN))
1585 ia64_info->rel_pltoff_sec = s;
1590 /* Find and/or create a hash entry for local symbol. */
1591 static struct elfNN_ia64_local_hash_entry *
1592 get_local_sym_hash (struct elfNN_ia64_link_hash_table *ia64_info,
1593 bfd *abfd, const Elf_Internal_Rela *rel,
1596 struct elfNN_ia64_local_hash_entry e, *ret;
1597 asection *sec = abfd->sections;
1598 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
1599 ELFNN_R_SYM (rel->r_info));
1603 e.r_sym = ELFNN_R_SYM (rel->r_info);
1604 slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h,
1605 create ? INSERT : NO_INSERT);
1611 return (struct elfNN_ia64_local_hash_entry *) *slot;
1613 ret = (struct elfNN_ia64_local_hash_entry *)
1614 objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory,
1615 sizeof (struct elfNN_ia64_local_hash_entry));
1618 memset (ret, 0, sizeof (*ret));
1620 ret->r_sym = ELFNN_R_SYM (rel->r_info);
1626 /* Used to sort elfNN_ia64_dyn_sym_info array. */
1629 addend_compare (const void *xp, const void *yp)
1631 const struct elfNN_ia64_dyn_sym_info *x
1632 = (const struct elfNN_ia64_dyn_sym_info *) xp;
1633 const struct elfNN_ia64_dyn_sym_info *y
1634 = (const struct elfNN_ia64_dyn_sym_info *) yp;
1636 return x->addend < y->addend ? -1 : x->addend > y->addend ? 1 : 0;
1639 /* Sort elfNN_ia64_dyn_sym_info array and remove duplicates. */
1642 sort_dyn_sym_info (struct elfNN_ia64_dyn_sym_info *info,
1645 bfd_vma curr, prev, got_offset;
1646 unsigned int i, kept, dupes, diff, dest, src, len;
1648 qsort (info, count, sizeof (*info), addend_compare);
1650 /* Find the first duplicate. */
1651 prev = info [0].addend;
1652 got_offset = info [0].got_offset;
1653 for (i = 1; i < count; i++)
1655 curr = info [i].addend;
1658 /* For duplicates, make sure that GOT_OFFSET is valid. */
1659 if (got_offset == (bfd_vma) -1)
1660 got_offset = info [i].got_offset;
1663 got_offset = info [i].got_offset;
1667 /* We may move a block of elements to here. */
1670 /* Remove duplicates. */
1675 /* For duplicates, make sure that the kept one has a valid
1678 if (got_offset != (bfd_vma) -1)
1679 info [kept].got_offset = got_offset;
1681 curr = info [i].addend;
1682 got_offset = info [i].got_offset;
1684 /* Move a block of elements whose first one is different from
1688 for (src = i + 1; src < count; src++)
1690 if (info [src].addend != curr)
1692 /* For duplicates, make sure that GOT_OFFSET is
1694 if (got_offset == (bfd_vma) -1)
1695 got_offset = info [src].got_offset;
1698 /* Make sure that the kept one has a valid got_offset. */
1699 if (got_offset != (bfd_vma) -1)
1700 info [kept].got_offset = got_offset;
1708 /* Find the next duplicate. SRC will be kept. */
1709 prev = info [src].addend;
1710 got_offset = info [src].got_offset;
1711 for (dupes = src + 1; dupes < count; dupes ++)
1713 curr = info [dupes].addend;
1716 /* Make sure that got_offset is valid. */
1717 if (got_offset == (bfd_vma) -1)
1718 got_offset = info [dupes].got_offset;
1720 /* For duplicates, make sure that the kept one has
1721 a valid got_offset. */
1722 if (got_offset != (bfd_vma) -1)
1723 info [dupes - 1].got_offset = got_offset;
1726 got_offset = info [dupes].got_offset;
1730 /* How much to move. */
1734 if (len == 1 && dupes < count)
1736 /* If we only move 1 element, we combine it with the next
1737 one. There must be at least a duplicate. Find the
1738 next different one. */
1739 for (diff = dupes + 1, src++; diff < count; diff++, src++)
1741 if (info [diff].addend != curr)
1743 /* Make sure that got_offset is valid. */
1744 if (got_offset == (bfd_vma) -1)
1745 got_offset = info [diff].got_offset;
1748 /* Makre sure that the last duplicated one has an valid
1750 BFD_ASSERT (curr == prev);
1751 if (got_offset != (bfd_vma) -1)
1752 info [diff - 1].got_offset = got_offset;
1756 /* Find the next duplicate. Track the current valid
1758 prev = info [diff].addend;
1759 got_offset = info [diff].got_offset;
1760 for (dupes = diff + 1; dupes < count; dupes ++)
1762 curr = info [dupes].addend;
1765 /* For duplicates, make sure that GOT_OFFSET
1767 if (got_offset == (bfd_vma) -1)
1768 got_offset = info [dupes].got_offset;
1771 got_offset = info [dupes].got_offset;
1776 len = diff - src + 1;
1781 memmove (&info [dest], &info [src], len * sizeof (*info));
1790 /* When we get here, either there is no duplicate at all or
1791 the only duplicate is the last element. */
1794 /* If the last element is a duplicate, make sure that the
1795 kept one has a valid got_offset. We also update count. */
1796 if (got_offset != (bfd_vma) -1)
1797 info [dest - 1].got_offset = got_offset;
1805 /* Find and/or create a descriptor for dynamic symbol info. This will
1806 vary based on global or local symbol, and the addend to the reloc.
1808 We don't sort when inserting. Also, we sort and eliminate
1809 duplicates if there is an unsorted section. Typically, this will
1810 only happen once, because we do all insertions before lookups. We
1811 then use bsearch to do a lookup. This also allows lookups to be
1812 fast. So we have fast insertion (O(log N) due to duplicate check),
1813 fast lookup (O(log N)) and one sort (O(N log N) expected time).
1814 Previously, all lookups were O(N) because of the use of the linked
1815 list and also all insertions were O(N) because of the check for
1816 duplicates. There are some complications here because the array
1817 size grows occasionally, which may add an O(N) factor, but this
1818 should be rare. Also, we free the excess array allocation, which
1819 requires a copy which is O(N), but this only happens once. */
1821 static struct elfNN_ia64_dyn_sym_info *
1822 get_dyn_sym_info (struct elfNN_ia64_link_hash_table *ia64_info,
1823 struct elf_link_hash_entry *h, bfd *abfd,
1824 const Elf_Internal_Rela *rel, bfd_boolean create)
1826 struct elfNN_ia64_dyn_sym_info **info_p, *info, *dyn_i, key;
1827 unsigned int *count_p, *sorted_count_p, *size_p;
1828 unsigned int count, sorted_count, size;
1829 bfd_vma addend = rel ? rel->r_addend : 0;
1834 struct elfNN_ia64_link_hash_entry *global_h;
1836 global_h = (struct elfNN_ia64_link_hash_entry *) h;
1837 info_p = &global_h->info;
1838 count_p = &global_h->count;
1839 sorted_count_p = &global_h->sorted_count;
1840 size_p = &global_h->size;
1844 struct elfNN_ia64_local_hash_entry *loc_h;
1846 loc_h = get_local_sym_hash (ia64_info, abfd, rel, create);
1849 BFD_ASSERT (!create);
1853 info_p = &loc_h->info;
1854 count_p = &loc_h->count;
1855 sorted_count_p = &loc_h->sorted_count;
1856 size_p = &loc_h->size;
1860 sorted_count = *sorted_count_p;
1865 /* When we create the array, we don't check for duplicates,
1866 except in the previously sorted section if one exists, and
1867 against the last inserted entry. This allows insertions to
1873 /* Try bsearch first on the sorted section. */
1874 key.addend = addend;
1875 dyn_i = bsearch (&key, info, sorted_count,
1876 sizeof (*info), addend_compare);
1884 /* Do a quick check for the last inserted entry. */
1885 dyn_i = info + count - 1;
1886 if (dyn_i->addend == addend)
1894 /* It is the very first element. We create the array of size
1897 amt = size * sizeof (*info);
1898 info = bfd_malloc (amt);
1900 else if (size <= count)
1902 /* We double the array size every time when we reach the
1905 amt = size * sizeof (*info);
1906 info = bfd_realloc (info, amt);
1917 /* Append the new one to the array. */
1918 dyn_i = info + count;
1919 memset (dyn_i, 0, sizeof (*dyn_i));
1920 dyn_i->got_offset = (bfd_vma) -1;
1921 dyn_i->addend = addend;
1923 /* We increment count only since the new ones are unsorted and
1924 may have duplicate. */
1929 /* It is a lookup without insertion. Sort array if part of the
1930 array isn't sorted. */
1931 if (count != sorted_count)
1933 count = sort_dyn_sym_info (info, count);
1935 *sorted_count_p = count;
1938 /* Free unused memory. */
1941 amt = count * sizeof (*info);
1942 info = bfd_malloc (amt);
1945 memcpy (info, *info_p, amt);
1952 key.addend = addend;
1953 dyn_i = bsearch (&key, info, count,
1954 sizeof (*info), addend_compare);
1961 get_got (bfd *abfd, struct bfd_link_info *info,
1962 struct elfNN_ia64_link_hash_table *ia64_info)
1967 got = ia64_info->root.sgot;
1972 dynobj = ia64_info->root.dynobj;
1974 ia64_info->root.dynobj = dynobj = abfd;
1975 if (!_bfd_elf_create_got_section (dynobj, info))
1978 got = ia64_info->root.sgot;
1980 /* The .got section is always aligned at 8 bytes. */
1981 if (!bfd_set_section_alignment (abfd, got, 3))
1984 flags = bfd_get_section_flags (abfd, got);
1985 if (! bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags))
1992 /* Create function descriptor section (.opd). This section is called .opd
1993 because it contains "official procedure descriptors". The "official"
1994 refers to the fact that these descriptors are used when taking the address
1995 of a procedure, thus ensuring a unique address for each procedure. */
1998 get_fptr (bfd *abfd, struct bfd_link_info *info,
1999 struct elfNN_ia64_link_hash_table *ia64_info)
2004 fptr = ia64_info->fptr_sec;
2007 dynobj = ia64_info->root.dynobj;
2009 ia64_info->root.dynobj = dynobj = abfd;
2011 fptr = bfd_make_section_anyway_with_flags (dynobj, ".opd",
2016 | (bfd_link_pie (info)
2018 | SEC_LINKER_CREATED));
2020 || !bfd_set_section_alignment (abfd, fptr, 4))
2026 ia64_info->fptr_sec = fptr;
2028 if (bfd_link_pie (info))
2031 fptr_rel = bfd_make_section_anyway_with_flags (dynobj, ".rela.opd",
2032 (SEC_ALLOC | SEC_LOAD
2035 | SEC_LINKER_CREATED
2037 if (fptr_rel == NULL
2038 || !bfd_set_section_alignment (abfd, fptr_rel,
2045 ia64_info->rel_fptr_sec = fptr_rel;
2053 get_pltoff (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED,
2054 struct elfNN_ia64_link_hash_table *ia64_info)
2059 pltoff = ia64_info->pltoff_sec;
2062 dynobj = ia64_info->root.dynobj;
2064 ia64_info->root.dynobj = dynobj = abfd;
2066 pltoff = bfd_make_section_anyway_with_flags (dynobj,
2067 ELF_STRING_ia64_pltoff,
2073 | SEC_LINKER_CREATED));
2075 || !bfd_set_section_alignment (abfd, pltoff, 4))
2081 ia64_info->pltoff_sec = pltoff;
2088 get_reloc_section (bfd *abfd,
2089 struct elfNN_ia64_link_hash_table *ia64_info,
2090 asection *sec, bfd_boolean create)
2092 const char *srel_name;
2096 srel_name = (bfd_elf_string_from_elf_section
2097 (abfd, elf_elfheader(abfd)->e_shstrndx,
2098 _bfd_elf_single_rel_hdr (sec)->sh_name));
2099 if (srel_name == NULL)
2102 dynobj = ia64_info->root.dynobj;
2104 ia64_info->root.dynobj = dynobj = abfd;
2106 srel = bfd_get_linker_section (dynobj, srel_name);
2107 if (srel == NULL && create)
2109 srel = bfd_make_section_anyway_with_flags (dynobj, srel_name,
2110 (SEC_ALLOC | SEC_LOAD
2113 | SEC_LINKER_CREATED
2116 || !bfd_set_section_alignment (dynobj, srel,
2125 count_dyn_reloc (bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
2126 asection *srel, int type, bfd_boolean reltext)
2128 struct elfNN_ia64_dyn_reloc_entry *rent;
2130 for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
2131 if (rent->srel == srel && rent->type == type)
2136 rent = ((struct elfNN_ia64_dyn_reloc_entry *)
2137 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)));
2141 rent->next = dyn_i->reloc_entries;
2145 dyn_i->reloc_entries = rent;
2147 rent->reltext = reltext;
2154 elfNN_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info,
2156 const Elf_Internal_Rela *relocs)
2158 struct elfNN_ia64_link_hash_table *ia64_info;
2159 const Elf_Internal_Rela *relend;
2160 Elf_Internal_Shdr *symtab_hdr;
2161 const Elf_Internal_Rela *rel;
2162 asection *got, *fptr, *srel, *pltoff;
2171 NEED_LTOFF_FPTR = 128,
2177 struct elf_link_hash_entry *h;
2178 unsigned long r_symndx;
2179 bfd_boolean maybe_dynamic;
2181 if (bfd_link_relocatable (info))
2184 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2185 ia64_info = elfNN_ia64_hash_table (info);
2186 if (ia64_info == NULL)
2189 got = fptr = srel = pltoff = NULL;
2191 relend = relocs + sec->reloc_count;
2193 /* We scan relocations first to create dynamic relocation arrays. We
2194 modified get_dyn_sym_info to allow fast insertion and support fast
2195 lookup in the next loop. */
2196 for (rel = relocs; rel < relend; ++rel)
2198 r_symndx = ELFNN_R_SYM (rel->r_info);
2199 if (r_symndx >= symtab_hdr->sh_info)
2201 long indx = r_symndx - symtab_hdr->sh_info;
2202 h = elf_sym_hashes (abfd)[indx];
2203 while (h->root.type == bfd_link_hash_indirect
2204 || h->root.type == bfd_link_hash_warning)
2205 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2210 if (h && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
2213 /* We can only get preliminary data on whether a symbol is
2214 locally or externally defined, as not all of the input files
2215 have yet been processed. Do something with what we know, as
2216 this may help reduce memory usage and processing time later. */
2217 maybe_dynamic = (h && ((!bfd_link_executable (info)
2218 && (!SYMBOLIC_BIND (info, h)
2219 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
2221 || h->root.type == bfd_link_hash_defweak));
2224 switch (ELFNN_R_TYPE (rel->r_info))
2226 case R_IA64_TPREL64MSB:
2227 case R_IA64_TPREL64LSB:
2228 if (bfd_link_pic (info) || maybe_dynamic)
2229 need_entry = NEED_DYNREL;
2232 case R_IA64_LTOFF_TPREL22:
2233 need_entry = NEED_TPREL;
2234 if (bfd_link_pic (info))
2235 info->flags |= DF_STATIC_TLS;
2238 case R_IA64_DTPREL32MSB:
2239 case R_IA64_DTPREL32LSB:
2240 case R_IA64_DTPREL64MSB:
2241 case R_IA64_DTPREL64LSB:
2242 if (bfd_link_pic (info) || maybe_dynamic)
2243 need_entry = NEED_DYNREL;
2246 case R_IA64_LTOFF_DTPREL22:
2247 need_entry = NEED_DTPREL;
2250 case R_IA64_DTPMOD64MSB:
2251 case R_IA64_DTPMOD64LSB:
2252 if (bfd_link_pic (info) || maybe_dynamic)
2253 need_entry = NEED_DYNREL;
2256 case R_IA64_LTOFF_DTPMOD22:
2257 need_entry = NEED_DTPMOD;
2260 case R_IA64_LTOFF_FPTR22:
2261 case R_IA64_LTOFF_FPTR64I:
2262 case R_IA64_LTOFF_FPTR32MSB:
2263 case R_IA64_LTOFF_FPTR32LSB:
2264 case R_IA64_LTOFF_FPTR64MSB:
2265 case R_IA64_LTOFF_FPTR64LSB:
2266 need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
2269 case R_IA64_FPTR64I:
2270 case R_IA64_FPTR32MSB:
2271 case R_IA64_FPTR32LSB:
2272 case R_IA64_FPTR64MSB:
2273 case R_IA64_FPTR64LSB:
2274 if (bfd_link_pic (info) || h)
2275 need_entry = NEED_FPTR | NEED_DYNREL;
2277 need_entry = NEED_FPTR;
2280 case R_IA64_LTOFF22:
2281 case R_IA64_LTOFF64I:
2282 need_entry = NEED_GOT;
2285 case R_IA64_LTOFF22X:
2286 need_entry = NEED_GOTX;
2289 case R_IA64_PLTOFF22:
2290 case R_IA64_PLTOFF64I:
2291 case R_IA64_PLTOFF64MSB:
2292 case R_IA64_PLTOFF64LSB:
2293 need_entry = NEED_PLTOFF;
2297 need_entry |= NEED_MIN_PLT;
2301 (*info->callbacks->warning)
2302 (info, _("@pltoff reloc against local symbol"), 0,
2303 abfd, 0, (bfd_vma) 0);
2307 case R_IA64_PCREL21B:
2308 case R_IA64_PCREL60B:
2309 /* Depending on where this symbol is defined, we may or may not
2310 need a full plt entry. Only skip if we know we'll not need
2311 the entry -- static or symbolic, and the symbol definition
2312 has already been seen. */
2313 if (maybe_dynamic && rel->r_addend == 0)
2314 need_entry = NEED_FULL_PLT;
2320 case R_IA64_DIR32MSB:
2321 case R_IA64_DIR32LSB:
2322 case R_IA64_DIR64MSB:
2323 case R_IA64_DIR64LSB:
2324 /* Shared objects will always need at least a REL relocation. */
2325 if (bfd_link_pic (info) || maybe_dynamic)
2326 need_entry = NEED_DYNREL;
2329 case R_IA64_IPLTMSB:
2330 case R_IA64_IPLTLSB:
2331 /* Shared objects will always need at least a REL relocation. */
2332 if (bfd_link_pic (info) || maybe_dynamic)
2333 need_entry = NEED_DYNREL;
2336 case R_IA64_PCREL22:
2337 case R_IA64_PCREL64I:
2338 case R_IA64_PCREL32MSB:
2339 case R_IA64_PCREL32LSB:
2340 case R_IA64_PCREL64MSB:
2341 case R_IA64_PCREL64LSB:
2343 need_entry = NEED_DYNREL;
2350 if ((need_entry & NEED_FPTR) != 0
2353 (*info->callbacks->warning)
2354 (info, _("non-zero addend in @fptr reloc"), 0,
2355 abfd, 0, (bfd_vma) 0);
2358 if (get_dyn_sym_info (ia64_info, h, abfd, rel, TRUE) == NULL)
2362 /* Now, we only do lookup without insertion, which is very fast
2363 with the modified get_dyn_sym_info. */
2364 for (rel = relocs; rel < relend; ++rel)
2366 struct elfNN_ia64_dyn_sym_info *dyn_i;
2367 int dynrel_type = R_IA64_NONE;
2369 r_symndx = ELFNN_R_SYM (rel->r_info);
2370 if (r_symndx >= symtab_hdr->sh_info)
2372 /* We're dealing with a global symbol -- find its hash entry
2373 and mark it as being referenced. */
2374 long indx = r_symndx - symtab_hdr->sh_info;
2375 h = elf_sym_hashes (abfd)[indx];
2376 while (h->root.type == bfd_link_hash_indirect
2377 || h->root.type == bfd_link_hash_warning)
2378 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2380 /* PR15323, ref flags aren't set for references in the same
2387 if (h && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
2390 /* We can only get preliminary data on whether a symbol is
2391 locally or externally defined, as not all of the input files
2392 have yet been processed. Do something with what we know, as
2393 this may help reduce memory usage and processing time later. */
2394 maybe_dynamic = (h && ((!bfd_link_executable (info)
2395 && (!SYMBOLIC_BIND (info, h)
2396 || info->unresolved_syms_in_shared_libs == RM_IGNORE))
2398 || h->root.type == bfd_link_hash_defweak));
2401 switch (ELFNN_R_TYPE (rel->r_info))
2403 case R_IA64_TPREL64MSB:
2404 case R_IA64_TPREL64LSB:
2405 if (bfd_link_pic (info) || maybe_dynamic)
2406 need_entry = NEED_DYNREL;
2407 dynrel_type = R_IA64_TPREL64LSB;
2408 if (bfd_link_pic (info))
2409 info->flags |= DF_STATIC_TLS;
2412 case R_IA64_LTOFF_TPREL22:
2413 need_entry = NEED_TPREL;
2414 if (bfd_link_pic (info))
2415 info->flags |= DF_STATIC_TLS;
2418 case R_IA64_DTPREL32MSB:
2419 case R_IA64_DTPREL32LSB:
2420 case R_IA64_DTPREL64MSB:
2421 case R_IA64_DTPREL64LSB:
2422 if (bfd_link_pic (info) || maybe_dynamic)
2423 need_entry = NEED_DYNREL;
2424 dynrel_type = R_IA64_DTPRELNNLSB;
2427 case R_IA64_LTOFF_DTPREL22:
2428 need_entry = NEED_DTPREL;
2431 case R_IA64_DTPMOD64MSB:
2432 case R_IA64_DTPMOD64LSB:
2433 if (bfd_link_pic (info) || maybe_dynamic)
2434 need_entry = NEED_DYNREL;
2435 dynrel_type = R_IA64_DTPMOD64LSB;
2438 case R_IA64_LTOFF_DTPMOD22:
2439 need_entry = NEED_DTPMOD;
2442 case R_IA64_LTOFF_FPTR22:
2443 case R_IA64_LTOFF_FPTR64I:
2444 case R_IA64_LTOFF_FPTR32MSB:
2445 case R_IA64_LTOFF_FPTR32LSB:
2446 case R_IA64_LTOFF_FPTR64MSB:
2447 case R_IA64_LTOFF_FPTR64LSB:
2448 need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
2451 case R_IA64_FPTR64I:
2452 case R_IA64_FPTR32MSB:
2453 case R_IA64_FPTR32LSB:
2454 case R_IA64_FPTR64MSB:
2455 case R_IA64_FPTR64LSB:
2456 if (bfd_link_pic (info) || h)
2457 need_entry = NEED_FPTR | NEED_DYNREL;
2459 need_entry = NEED_FPTR;
2460 dynrel_type = R_IA64_FPTRNNLSB;
2463 case R_IA64_LTOFF22:
2464 case R_IA64_LTOFF64I:
2465 need_entry = NEED_GOT;
2468 case R_IA64_LTOFF22X:
2469 need_entry = NEED_GOTX;
2472 case R_IA64_PLTOFF22:
2473 case R_IA64_PLTOFF64I:
2474 case R_IA64_PLTOFF64MSB:
2475 case R_IA64_PLTOFF64LSB:
2476 need_entry = NEED_PLTOFF;
2480 need_entry |= NEED_MIN_PLT;
2484 case R_IA64_PCREL21B:
2485 case R_IA64_PCREL60B:
2486 /* Depending on where this symbol is defined, we may or may not
2487 need a full plt entry. Only skip if we know we'll not need
2488 the entry -- static or symbolic, and the symbol definition
2489 has already been seen. */
2490 if (maybe_dynamic && rel->r_addend == 0)
2491 need_entry = NEED_FULL_PLT;
2497 case R_IA64_DIR32MSB:
2498 case R_IA64_DIR32LSB:
2499 case R_IA64_DIR64MSB:
2500 case R_IA64_DIR64LSB:
2501 /* Shared objects will always need at least a REL relocation. */
2502 if (bfd_link_pic (info) || maybe_dynamic)
2503 need_entry = NEED_DYNREL;
2504 dynrel_type = R_IA64_DIRNNLSB;
2507 case R_IA64_IPLTMSB:
2508 case R_IA64_IPLTLSB:
2509 /* Shared objects will always need at least a REL relocation. */
2510 if (bfd_link_pic (info) || maybe_dynamic)
2511 need_entry = NEED_DYNREL;
2512 dynrel_type = R_IA64_IPLTLSB;
2515 case R_IA64_PCREL22:
2516 case R_IA64_PCREL64I:
2517 case R_IA64_PCREL32MSB:
2518 case R_IA64_PCREL32LSB:
2519 case R_IA64_PCREL64MSB:
2520 case R_IA64_PCREL64LSB:
2522 need_entry = NEED_DYNREL;
2523 dynrel_type = R_IA64_PCRELNNLSB;
2530 dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, FALSE);
2532 /* Record whether or not this is a local symbol. */
2535 /* Create what's needed. */
2536 if (need_entry & (NEED_GOT | NEED_GOTX | NEED_TPREL
2537 | NEED_DTPMOD | NEED_DTPREL))
2541 got = get_got (abfd, info, ia64_info);
2545 if (need_entry & NEED_GOT)
2546 dyn_i->want_got = 1;
2547 if (need_entry & NEED_GOTX)
2548 dyn_i->want_gotx = 1;
2549 if (need_entry & NEED_TPREL)
2550 dyn_i->want_tprel = 1;
2551 if (need_entry & NEED_DTPMOD)
2552 dyn_i->want_dtpmod = 1;
2553 if (need_entry & NEED_DTPREL)
2554 dyn_i->want_dtprel = 1;
2556 if (need_entry & NEED_FPTR)
2560 fptr = get_fptr (abfd, info, ia64_info);
2565 /* FPTRs for shared libraries are allocated by the dynamic
2566 linker. Make sure this local symbol will appear in the
2567 dynamic symbol table. */
2568 if (!h && bfd_link_pic (info))
2570 if (! (bfd_elf_link_record_local_dynamic_symbol
2571 (info, abfd, (long) r_symndx)))
2575 dyn_i->want_fptr = 1;
2577 if (need_entry & NEED_LTOFF_FPTR)
2578 dyn_i->want_ltoff_fptr = 1;
2579 if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT))
2581 if (!ia64_info->root.dynobj)
2582 ia64_info->root.dynobj = abfd;
2584 dyn_i->want_plt = 1;
2586 if (need_entry & NEED_FULL_PLT)
2587 dyn_i->want_plt2 = 1;
2588 if (need_entry & NEED_PLTOFF)
2590 /* This is needed here, in case @pltoff is used in a non-shared
2594 pltoff = get_pltoff (abfd, info, ia64_info);
2599 dyn_i->want_pltoff = 1;
2601 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
2605 srel = get_reloc_section (abfd, ia64_info, sec, TRUE);
2609 if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type,
2610 (sec->flags & SEC_READONLY) != 0))
2618 /* For cleanliness, and potentially faster dynamic loading, allocate
2619 external GOT entries first. */
2622 allocate_global_data_got (struct elfNN_ia64_dyn_sym_info *dyn_i,
2625 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2627 if ((dyn_i->want_got || dyn_i->want_gotx)
2628 && ! dyn_i->want_fptr
2629 && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0))
2631 dyn_i->got_offset = x->ofs;
2634 if (dyn_i->want_tprel)
2636 dyn_i->tprel_offset = x->ofs;
2639 if (dyn_i->want_dtpmod)
2641 if (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0))
2643 dyn_i->dtpmod_offset = x->ofs;
2648 struct elfNN_ia64_link_hash_table *ia64_info;
2650 ia64_info = elfNN_ia64_hash_table (x->info);
2651 if (ia64_info == NULL)
2654 if (ia64_info->self_dtpmod_offset == (bfd_vma) -1)
2656 ia64_info->self_dtpmod_offset = x->ofs;
2659 dyn_i->dtpmod_offset = ia64_info->self_dtpmod_offset;
2662 if (dyn_i->want_dtprel)
2664 dyn_i->dtprel_offset = x->ofs;
2670 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2673 allocate_global_fptr_got (struct elfNN_ia64_dyn_sym_info *dyn_i,
2676 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2680 && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, R_IA64_FPTRNNLSB))
2682 dyn_i->got_offset = x->ofs;
2688 /* Lastly, allocate all the GOT entries for local data. */
2691 allocate_local_got (struct elfNN_ia64_dyn_sym_info *dyn_i,
2694 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2696 if ((dyn_i->want_got || dyn_i->want_gotx)
2697 && !elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0))
2699 dyn_i->got_offset = x->ofs;
2705 /* Search for the index of a global symbol in it's defining object file. */
2708 global_sym_index (struct elf_link_hash_entry *h)
2710 struct elf_link_hash_entry **p;
2713 BFD_ASSERT (h->root.type == bfd_link_hash_defined
2714 || h->root.type == bfd_link_hash_defweak);
2716 obj = h->root.u.def.section->owner;
2717 for (p = elf_sym_hashes (obj); *p != h; ++p)
2720 return p - elf_sym_hashes (obj) + elf_tdata (obj)->symtab_hdr.sh_info;
2723 /* Allocate function descriptors. We can do these for every function
2724 in a main executable that is not exported. */
2727 allocate_fptr (struct elfNN_ia64_dyn_sym_info *dyn_i, void * data)
2729 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2731 if (dyn_i->want_fptr)
2733 struct elf_link_hash_entry *h = dyn_i->h;
2736 while (h->root.type == bfd_link_hash_indirect
2737 || h->root.type == bfd_link_hash_warning)
2738 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2740 if (!bfd_link_executable (x->info)
2742 || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2743 && !UNDEFWEAK_NO_DYNAMIC_RELOC (x->info, h))
2744 || (h->root.type != bfd_link_hash_undefweak
2745 && h->root.type != bfd_link_hash_undefined)))
2747 if (h && h->dynindx == -1)
2749 BFD_ASSERT ((h->root.type == bfd_link_hash_defined)
2750 || (h->root.type == bfd_link_hash_defweak));
2752 if (!bfd_elf_link_record_local_dynamic_symbol
2753 (x->info, h->root.u.def.section->owner,
2754 global_sym_index (h)))
2758 dyn_i->want_fptr = 0;
2760 else if (h == NULL || h->dynindx == -1)
2762 dyn_i->fptr_offset = x->ofs;
2766 dyn_i->want_fptr = 0;
2771 /* Allocate all the minimal PLT entries. */
2774 allocate_plt_entries (struct elfNN_ia64_dyn_sym_info *dyn_i,
2777 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2779 if (dyn_i->want_plt)
2781 struct elf_link_hash_entry *h = dyn_i->h;
2784 while (h->root.type == bfd_link_hash_indirect
2785 || h->root.type == bfd_link_hash_warning)
2786 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2788 /* ??? Versioned symbols seem to lose NEEDS_PLT. */
2789 if (elfNN_ia64_dynamic_symbol_p (h, x->info, 0))
2791 bfd_size_type offset = x->ofs;
2793 offset = PLT_HEADER_SIZE;
2794 dyn_i->plt_offset = offset;
2795 x->ofs = offset + PLT_MIN_ENTRY_SIZE;
2797 dyn_i->want_pltoff = 1;
2801 dyn_i->want_plt = 0;
2802 dyn_i->want_plt2 = 0;
2808 /* Allocate all the full PLT entries. */
2811 allocate_plt2_entries (struct elfNN_ia64_dyn_sym_info *dyn_i,
2814 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2816 if (dyn_i->want_plt2)
2818 struct elf_link_hash_entry *h = dyn_i->h;
2819 bfd_size_type ofs = x->ofs;
2821 dyn_i->plt2_offset = ofs;
2822 x->ofs = ofs + PLT_FULL_ENTRY_SIZE;
2824 while (h->root.type == bfd_link_hash_indirect
2825 || h->root.type == bfd_link_hash_warning)
2826 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2827 dyn_i->h->plt.offset = ofs;
2832 /* Allocate all the PLTOFF entries requested by relocations and
2833 plt entries. We can't share space with allocated FPTR entries,
2834 because the latter are not necessarily addressable by the GP.
2835 ??? Relaxation might be able to determine that they are. */
2838 allocate_pltoff_entries (struct elfNN_ia64_dyn_sym_info *dyn_i,
2841 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2843 if (dyn_i->want_pltoff)
2845 dyn_i->pltoff_offset = x->ofs;
2851 /* Allocate dynamic relocations for those symbols that turned out
2855 allocate_dynrel_entries (struct elfNN_ia64_dyn_sym_info *dyn_i,
2858 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2859 struct elfNN_ia64_link_hash_table *ia64_info;
2860 struct elfNN_ia64_dyn_reloc_entry *rent;
2861 bfd_boolean dynamic_symbol, shared, resolved_zero;
2863 ia64_info = elfNN_ia64_hash_table (x->info);
2864 if (ia64_info == NULL)
2867 /* Note that this can't be used in relation to FPTR relocs below. */
2868 dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0);
2870 shared = bfd_link_pic (x->info);
2871 resolved_zero = (dyn_i->h
2872 && UNDEFWEAK_NO_DYNAMIC_RELOC (x->info,
2875 /* Take care of the GOT and PLT relocations. */
2878 && (dynamic_symbol || shared)
2879 && (dyn_i->want_got || dyn_i->want_gotx))
2880 || (dyn_i->want_ltoff_fptr
2882 && dyn_i->h->dynindx != -1))
2884 if (!dyn_i->want_ltoff_fptr
2885 || !bfd_link_pie (x->info)
2887 || dyn_i->h->root.type != bfd_link_hash_undefweak)
2888 ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela);
2890 if ((dynamic_symbol || shared) && dyn_i->want_tprel)
2891 ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela);
2892 if (dynamic_symbol && dyn_i->want_dtpmod)
2893 ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela);
2894 if (dynamic_symbol && dyn_i->want_dtprel)
2895 ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela);
2900 if (ia64_info->rel_fptr_sec && dyn_i->want_fptr)
2902 if (dyn_i->h == NULL || dyn_i->h->root.type != bfd_link_hash_undefweak)
2903 ia64_info->rel_fptr_sec->size += sizeof (ElfNN_External_Rela);
2906 if (!resolved_zero && dyn_i->want_pltoff)
2908 bfd_size_type t = 0;
2910 /* Dynamic symbols get one IPLT relocation. Local symbols in
2911 shared libraries get two REL relocations. Local symbols in
2912 main applications get nothing. */
2914 t = sizeof (ElfNN_External_Rela);
2916 t = 2 * sizeof (ElfNN_External_Rela);
2918 ia64_info->rel_pltoff_sec->size += t;
2921 /* Take care of the normal data relocations. */
2923 for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
2925 int count = rent->count;
2929 case R_IA64_FPTR32LSB:
2930 case R_IA64_FPTR64LSB:
2931 /* Allocate one iff !want_fptr and not PIE, which by this point
2932 will be true only if we're actually allocating one statically
2933 in the main executable. Position independent executables
2934 need a relative reloc. */
2935 if (dyn_i->want_fptr && !bfd_link_pie (x->info))
2938 case R_IA64_PCREL32LSB:
2939 case R_IA64_PCREL64LSB:
2940 if (!dynamic_symbol)
2943 case R_IA64_DIR32LSB:
2944 case R_IA64_DIR64LSB:
2945 if (!dynamic_symbol && !shared)
2948 case R_IA64_IPLTLSB:
2949 if (!dynamic_symbol && !shared)
2951 /* Use two REL relocations for IPLT relocations
2952 against local symbols. */
2953 if (!dynamic_symbol)
2956 case R_IA64_DTPREL32LSB:
2957 case R_IA64_TPREL64LSB:
2958 case R_IA64_DTPREL64LSB:
2959 case R_IA64_DTPMOD64LSB:
2965 ia64_info->reltext = 1;
2966 rent->srel->size += sizeof (ElfNN_External_Rela) * count;
2973 elfNN_ia64_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2974 struct elf_link_hash_entry *h)
2976 /* ??? Undefined symbols with PLT entries should be re-defined
2977 to be the PLT entry. */
2979 /* If this is a weak symbol, and there is a real definition, the
2980 processor independent code will have arranged for us to see the
2981 real definition first, and we can just use the same value. */
2982 if (h->is_weakalias)
2984 struct elf_link_hash_entry *def = weakdef (h);
2985 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2986 h->root.u.def.section = def->root.u.def.section;
2987 h->root.u.def.value = def->root.u.def.value;
2991 /* If this is a reference to a symbol defined by a dynamic object which
2992 is not a function, we might allocate the symbol in our .dynbss section
2993 and allocate a COPY dynamic relocation.
2995 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
3002 elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3003 struct bfd_link_info *info)
3005 struct elfNN_ia64_allocate_data data;
3006 struct elfNN_ia64_link_hash_table *ia64_info;
3009 bfd_boolean relplt = FALSE;
3011 ia64_info = elfNN_ia64_hash_table (info);
3012 if (ia64_info == NULL)
3014 dynobj = ia64_info->root.dynobj;
3015 ia64_info->self_dtpmod_offset = (bfd_vma) -1;
3016 BFD_ASSERT(dynobj != NULL);
3019 /* Set the contents of the .interp section to the interpreter. */
3020 if (ia64_info->root.dynamic_sections_created
3021 && bfd_link_executable (info) && !info->nointerp)
3023 sec = bfd_get_linker_section (dynobj, ".interp");
3024 BFD_ASSERT (sec != NULL);
3025 sec->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3026 sec->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
3029 /* Allocate the GOT entries. */
3031 if (ia64_info->root.sgot)
3034 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data);
3035 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data);
3036 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data);
3037 ia64_info->root.sgot->size = data.ofs;
3040 /* Allocate the FPTR entries. */
3042 if (ia64_info->fptr_sec)
3045 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data);
3046 ia64_info->fptr_sec->size = data.ofs;
3049 /* Now that we've seen all of the input files, we can decide which
3050 symbols need plt entries. Allocate the minimal PLT entries first.
3051 We do this even though dynamic_sections_created may be FALSE, because
3052 this has the side-effect of clearing want_plt and want_plt2. */
3055 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data);
3057 ia64_info->minplt_entries = 0;
3060 ia64_info->minplt_entries
3061 = (data.ofs - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE;
3064 /* Align the pointer for the plt2 entries. */
3065 data.ofs = (data.ofs + 31) & (bfd_vma) -32;
3067 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
3068 if (data.ofs != 0 || ia64_info->root.dynamic_sections_created)
3070 /* FIXME: we always reserve the memory for dynamic linker even if
3071 there are no PLT entries since dynamic linker may assume the
3072 reserved memory always exists. */
3074 BFD_ASSERT (ia64_info->root.dynamic_sections_created);
3076 ia64_info->root.splt->size = data.ofs;
3078 /* If we've got a .plt, we need some extra memory for the dynamic
3079 linker. We stuff these in .got.plt. */
3080 ia64_info->root.sgotplt->size = 8 * PLT_RESERVED_WORDS;
3083 /* Allocate the PLTOFF entries. */
3085 if (ia64_info->pltoff_sec)
3088 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data);
3089 ia64_info->pltoff_sec->size = data.ofs;
3092 if (ia64_info->root.dynamic_sections_created)
3094 /* Allocate space for the dynamic relocations that turned out to be
3097 if (bfd_link_pic (info) && ia64_info->self_dtpmod_offset != (bfd_vma) -1)
3098 ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela);
3099 data.only_got = FALSE;
3100 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data);
3103 /* We have now determined the sizes of the various dynamic sections.
3104 Allocate memory for them. */
3105 for (sec = dynobj->sections; sec != NULL; sec = sec->next)
3109 if (!(sec->flags & SEC_LINKER_CREATED))
3112 /* If we don't need this section, strip it from the output file.
3113 There were several sections primarily related to dynamic
3114 linking that must be create before the linker maps input
3115 sections to output sections. The linker does that before
3116 bfd_elf_size_dynamic_sections is called, and it is that
3117 function which decides whether anything needs to go into
3120 strip = (sec->size == 0);
3122 if (sec == ia64_info->root.sgot)
3124 else if (sec == ia64_info->root.srelgot)
3127 ia64_info->root.srelgot = NULL;
3129 /* We use the reloc_count field as a counter if we need to
3130 copy relocs into the output file. */
3131 sec->reloc_count = 0;
3133 else if (sec == ia64_info->fptr_sec)
3136 ia64_info->fptr_sec = NULL;
3138 else if (sec == ia64_info->rel_fptr_sec)
3141 ia64_info->rel_fptr_sec = NULL;
3143 /* We use the reloc_count field as a counter if we need to
3144 copy relocs into the output file. */
3145 sec->reloc_count = 0;
3147 else if (sec == ia64_info->root.splt)
3150 ia64_info->root.splt = NULL;
3152 else if (sec == ia64_info->pltoff_sec)
3155 ia64_info->pltoff_sec = NULL;
3157 else if (sec == ia64_info->rel_pltoff_sec)
3160 ia64_info->rel_pltoff_sec = NULL;
3164 /* We use the reloc_count field as a counter if we need to
3165 copy relocs into the output file. */
3166 sec->reloc_count = 0;
3173 /* It's OK to base decisions on the section name, because none
3174 of the dynobj section names depend upon the input files. */
3175 name = bfd_get_section_name (dynobj, sec);
3177 if (strcmp (name, ".got.plt") == 0)
3179 else if (CONST_STRNEQ (name, ".rel"))
3183 /* We use the reloc_count field as a counter if we need to
3184 copy relocs into the output file. */
3185 sec->reloc_count = 0;
3193 sec->flags |= SEC_EXCLUDE;
3196 /* Allocate memory for the section contents. */
3197 sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
3198 if (sec->contents == NULL && sec->size != 0)
3203 if (ia64_info->root.dynamic_sections_created)
3205 /* Add some entries to the .dynamic section. We fill in the values
3206 later (in finish_dynamic_sections) but we must add the entries now
3207 so that we get the correct size for the .dynamic section. */
3209 if (bfd_link_executable (info))
3211 /* The DT_DEBUG entry is filled in by the dynamic linker and used
3213 #define add_dynamic_entry(TAG, VAL) \
3214 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3216 if (!add_dynamic_entry (DT_DEBUG, 0))
3220 if (!add_dynamic_entry (DT_IA_64_PLT_RESERVE, 0))
3222 if (!add_dynamic_entry (DT_PLTGOT, 0))
3227 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
3228 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3229 || !add_dynamic_entry (DT_JMPREL, 0))
3233 if (!add_dynamic_entry (DT_RELA, 0)
3234 || !add_dynamic_entry (DT_RELASZ, 0)
3235 || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela)))
3238 if (ia64_info->reltext)
3240 if (!add_dynamic_entry (DT_TEXTREL, 0))
3242 info->flags |= DF_TEXTREL;
3246 /* ??? Perhaps force __gp local. */
3252 elfNN_ia64_install_dyn_reloc (bfd *abfd, struct bfd_link_info *info,
3253 asection *sec, asection *srel,
3254 bfd_vma offset, unsigned int type,
3255 long dynindx, bfd_vma addend)
3257 Elf_Internal_Rela outrel;
3260 BFD_ASSERT (dynindx != -1);
3261 outrel.r_info = ELFNN_R_INFO (dynindx, type);
3262 outrel.r_addend = addend;
3263 outrel.r_offset = _bfd_elf_section_offset (abfd, info, sec, offset);
3264 if (outrel.r_offset >= (bfd_vma) -2)
3266 /* Run for the hills. We shouldn't be outputting a relocation
3267 for this. So do what everyone else does and output a no-op. */
3268 outrel.r_info = ELFNN_R_INFO (0, R_IA64_NONE);
3269 outrel.r_addend = 0;
3270 outrel.r_offset = 0;
3273 outrel.r_offset += sec->output_section->vma + sec->output_offset;
3275 loc = srel->contents;
3276 loc += srel->reloc_count++ * sizeof (ElfNN_External_Rela);
3277 bfd_elfNN_swap_reloca_out (abfd, &outrel, loc);
3278 BFD_ASSERT (sizeof (ElfNN_External_Rela) * srel->reloc_count <= srel->size);
3281 /* Store an entry for target address TARGET_ADDR in the linkage table
3282 and return the gp-relative address of the linkage table entry. */
3285 set_got_entry (bfd *abfd, struct bfd_link_info *info,
3286 struct elfNN_ia64_dyn_sym_info *dyn_i,
3287 long dynindx, bfd_vma addend, bfd_vma value,
3288 unsigned int dyn_r_type)
3290 struct elfNN_ia64_link_hash_table *ia64_info;
3295 ia64_info = elfNN_ia64_hash_table (info);
3296 if (ia64_info == NULL)
3299 got_sec = ia64_info->root.sgot;
3303 case R_IA64_TPREL64LSB:
3304 done = dyn_i->tprel_done;
3305 dyn_i->tprel_done = TRUE;
3306 got_offset = dyn_i->tprel_offset;
3308 case R_IA64_DTPMOD64LSB:
3309 if (dyn_i->dtpmod_offset != ia64_info->self_dtpmod_offset)
3311 done = dyn_i->dtpmod_done;
3312 dyn_i->dtpmod_done = TRUE;
3316 done = ia64_info->self_dtpmod_done;
3317 ia64_info->self_dtpmod_done = TRUE;
3320 got_offset = dyn_i->dtpmod_offset;
3322 case R_IA64_DTPREL32LSB:
3323 case R_IA64_DTPREL64LSB:
3324 done = dyn_i->dtprel_done;
3325 dyn_i->dtprel_done = TRUE;
3326 got_offset = dyn_i->dtprel_offset;
3329 done = dyn_i->got_done;
3330 dyn_i->got_done = TRUE;
3331 got_offset = dyn_i->got_offset;
3335 BFD_ASSERT ((got_offset & 7) == 0);
3339 /* Store the target address in the linkage table entry. */
3340 bfd_put_64 (abfd, value, got_sec->contents + got_offset);
3342 /* Install a dynamic relocation if needed. */
3343 if (((bfd_link_pic (info)
3345 || (ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
3346 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, dyn_i->h))
3347 || dyn_i->h->root.type != bfd_link_hash_undefweak)
3348 && dyn_r_type != R_IA64_DTPREL32LSB
3349 && dyn_r_type != R_IA64_DTPREL64LSB)
3350 || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info, dyn_r_type)
3352 && (dyn_r_type == R_IA64_FPTR32LSB
3353 || dyn_r_type == R_IA64_FPTR64LSB)))
3354 && (!dyn_i->want_ltoff_fptr
3355 || !bfd_link_pie (info)
3357 || dyn_i->h->root.type != bfd_link_hash_undefweak))
3360 && dyn_r_type != R_IA64_TPREL64LSB
3361 && dyn_r_type != R_IA64_DTPMOD64LSB
3362 && dyn_r_type != R_IA64_DTPREL32LSB
3363 && dyn_r_type != R_IA64_DTPREL64LSB)
3365 dyn_r_type = R_IA64_RELNNLSB;
3370 if (bfd_big_endian (abfd))
3374 case R_IA64_REL32LSB:
3375 dyn_r_type = R_IA64_REL32MSB;
3377 case R_IA64_DIR32LSB:
3378 dyn_r_type = R_IA64_DIR32MSB;
3380 case R_IA64_FPTR32LSB:
3381 dyn_r_type = R_IA64_FPTR32MSB;
3383 case R_IA64_DTPREL32LSB:
3384 dyn_r_type = R_IA64_DTPREL32MSB;
3386 case R_IA64_REL64LSB:
3387 dyn_r_type = R_IA64_REL64MSB;
3389 case R_IA64_DIR64LSB:
3390 dyn_r_type = R_IA64_DIR64MSB;
3392 case R_IA64_FPTR64LSB:
3393 dyn_r_type = R_IA64_FPTR64MSB;
3395 case R_IA64_TPREL64LSB:
3396 dyn_r_type = R_IA64_TPREL64MSB;
3398 case R_IA64_DTPMOD64LSB:
3399 dyn_r_type = R_IA64_DTPMOD64MSB;
3401 case R_IA64_DTPREL64LSB:
3402 dyn_r_type = R_IA64_DTPREL64MSB;
3410 elfNN_ia64_install_dyn_reloc (abfd, NULL, got_sec,
3411 ia64_info->root.srelgot,
3412 got_offset, dyn_r_type,
3417 /* Return the address of the linkage table entry. */
3418 value = (got_sec->output_section->vma
3419 + got_sec->output_offset
3425 /* Fill in a function descriptor consisting of the function's code
3426 address and its global pointer. Return the descriptor's address. */
3429 set_fptr_entry (bfd *abfd, struct bfd_link_info *info,
3430 struct elfNN_ia64_dyn_sym_info *dyn_i,
3433 struct elfNN_ia64_link_hash_table *ia64_info;
3436 ia64_info = elfNN_ia64_hash_table (info);
3437 if (ia64_info == NULL)
3440 fptr_sec = ia64_info->fptr_sec;
3442 if (!dyn_i->fptr_done)
3444 dyn_i->fptr_done = 1;
3446 /* Fill in the function descriptor. */
3447 bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset);
3448 bfd_put_64 (abfd, _bfd_get_gp_value (abfd),
3449 fptr_sec->contents + dyn_i->fptr_offset + 8);
3450 if (ia64_info->rel_fptr_sec)
3452 Elf_Internal_Rela outrel;
3455 if (bfd_little_endian (abfd))
3456 outrel.r_info = ELFNN_R_INFO (0, R_IA64_IPLTLSB);
3458 outrel.r_info = ELFNN_R_INFO (0, R_IA64_IPLTMSB);
3459 outrel.r_addend = value;
3460 outrel.r_offset = (fptr_sec->output_section->vma
3461 + fptr_sec->output_offset
3462 + dyn_i->fptr_offset);
3463 loc = ia64_info->rel_fptr_sec->contents;
3464 loc += ia64_info->rel_fptr_sec->reloc_count++
3465 * sizeof (ElfNN_External_Rela);
3466 bfd_elfNN_swap_reloca_out (abfd, &outrel, loc);
3470 /* Return the descriptor's address. */
3471 value = (fptr_sec->output_section->vma
3472 + fptr_sec->output_offset
3473 + dyn_i->fptr_offset);
3478 /* Fill in a PLTOFF entry consisting of the function's code address
3479 and its global pointer. Return the descriptor's address. */
3482 set_pltoff_entry (bfd *abfd, struct bfd_link_info *info,
3483 struct elfNN_ia64_dyn_sym_info *dyn_i,
3484 bfd_vma value, bfd_boolean is_plt)
3486 struct elfNN_ia64_link_hash_table *ia64_info;
3487 asection *pltoff_sec;
3489 ia64_info = elfNN_ia64_hash_table (info);
3490 if (ia64_info == NULL)
3493 pltoff_sec = ia64_info->pltoff_sec;
3495 /* Don't do anything if this symbol uses a real PLT entry. In
3496 that case, we'll fill this in during finish_dynamic_symbol. */
3497 if ((! dyn_i->want_plt || is_plt)
3498 && !dyn_i->pltoff_done)
3500 bfd_vma gp = _bfd_get_gp_value (abfd);
3502 /* Fill in the function descriptor. */
3503 bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset);
3504 bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
3506 /* Install dynamic relocations if needed. */
3508 && bfd_link_pic (info)
3510 || (ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
3511 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, dyn_i->h))
3512 || dyn_i->h->root.type != bfd_link_hash_undefweak))
3514 unsigned int dyn_r_type;
3516 if (bfd_big_endian (abfd))
3517 dyn_r_type = R_IA64_RELNNMSB;
3519 dyn_r_type = R_IA64_RELNNLSB;
3521 elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec,
3522 ia64_info->rel_pltoff_sec,
3523 dyn_i->pltoff_offset,
3524 dyn_r_type, 0, value);
3525 elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec,
3526 ia64_info->rel_pltoff_sec,
3527 dyn_i->pltoff_offset + ARCH_SIZE / 8,
3531 dyn_i->pltoff_done = 1;
3534 /* Return the descriptor's address. */
3535 value = (pltoff_sec->output_section->vma
3536 + pltoff_sec->output_offset
3537 + dyn_i->pltoff_offset);
3542 /* Return the base VMA address which should be subtracted from real addresses
3543 when resolving @tprel() relocation.
3544 Main program TLS (whose template starts at PT_TLS p_vaddr)
3545 is assigned offset round(2 * size of pointer, PT_TLS p_align). */
3548 elfNN_ia64_tprel_base (struct bfd_link_info *info)
3550 asection *tls_sec = elf_hash_table (info)->tls_sec;
3551 return tls_sec->vma - align_power ((bfd_vma) ARCH_SIZE / 4,
3552 tls_sec->alignment_power);
3555 /* Return the base VMA address which should be subtracted from real addresses
3556 when resolving @dtprel() relocation.
3557 This is PT_TLS segment p_vaddr. */
3560 elfNN_ia64_dtprel_base (struct bfd_link_info *info)
3562 return elf_hash_table (info)->tls_sec->vma;
3565 /* Called through qsort to sort the .IA_64.unwind section during a
3566 non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd
3567 to the output bfd so we can do proper endianness frobbing. */
3569 static bfd *elfNN_ia64_unwind_entry_compare_bfd;
3572 elfNN_ia64_unwind_entry_compare (const void * a, const void * b)
3576 av = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, a);
3577 bv = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, b);
3579 return (av < bv ? -1 : av > bv ? 1 : 0);
3582 /* Make sure we've got ourselves a nice fat __gp value. */
3584 elfNN_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info, bfd_boolean final)
3586 bfd_vma min_vma = (bfd_vma) -1, max_vma = 0;
3587 bfd_vma min_short_vma = min_vma, max_short_vma = 0;
3588 struct elf_link_hash_entry *gp;
3591 struct elfNN_ia64_link_hash_table *ia64_info;
3593 ia64_info = elfNN_ia64_hash_table (info);
3594 if (ia64_info == NULL)
3597 /* Find the min and max vma of all sections marked short. Also collect
3598 min and max vma of any type, for use in selecting a nice gp. */
3599 for (os = abfd->sections; os ; os = os->next)
3603 if ((os->flags & SEC_ALLOC) == 0)
3607 /* When this function is called from elfNN_ia64_final_link
3608 the correct value to use is os->size. When called from
3609 elfNN_ia64_relax_section we are in the middle of section
3610 sizing; some sections will already have os->size set, others
3611 will have os->size zero and os->rawsize the previous size. */
3612 hi = os->vma + (!final && os->rawsize ? os->rawsize : os->size);
3620 if (os->flags & SEC_SMALL_DATA)
3622 if (min_short_vma > lo)
3624 if (max_short_vma < hi)
3629 if (ia64_info->min_short_sec)
3632 > (ia64_info->min_short_sec->vma
3633 + ia64_info->min_short_offset))
3634 min_short_vma = (ia64_info->min_short_sec->vma
3635 + ia64_info->min_short_offset);
3637 < (ia64_info->max_short_sec->vma
3638 + ia64_info->max_short_offset))
3639 max_short_vma = (ia64_info->max_short_sec->vma
3640 + ia64_info->max_short_offset);
3643 /* See if the user wants to force a value. */
3644 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
3648 && (gp->root.type == bfd_link_hash_defined
3649 || gp->root.type == bfd_link_hash_defweak))
3651 asection *gp_sec = gp->root.u.def.section;
3652 gp_val = (gp->root.u.def.value
3653 + gp_sec->output_section->vma
3654 + gp_sec->output_offset);
3658 /* Pick a sensible value. */
3660 if (ia64_info->min_short_sec)
3662 bfd_vma short_range = max_short_vma - min_short_vma;
3664 /* If min_short_sec is set, pick one in the middle bewteen
3665 min_short_vma and max_short_vma. */
3666 if (short_range >= 0x400000)
3668 gp_val = min_short_vma + short_range / 2;
3672 asection *got_sec = ia64_info->root.sgot;
3674 /* Start with just the address of the .got. */
3676 gp_val = got_sec->output_section->vma;
3677 else if (max_short_vma != 0)
3678 gp_val = min_short_vma;
3679 else if (max_vma - min_vma < 0x200000)
3682 gp_val = max_vma - 0x200000 + 8;
3685 /* If it is possible to address the entire image, but we
3686 don't with the choice above, adjust. */
3687 if (max_vma - min_vma < 0x400000
3688 && (max_vma - gp_val >= 0x200000
3689 || gp_val - min_vma > 0x200000))
3690 gp_val = min_vma + 0x200000;
3691 else if (max_short_vma != 0)
3693 /* If we don't cover all the short data, adjust. */
3694 if (max_short_vma - gp_val >= 0x200000)
3695 gp_val = min_short_vma + 0x200000;
3697 /* If we're addressing stuff past the end, adjust back. */
3698 if (gp_val > max_vma)
3699 gp_val = max_vma - 0x200000 + 8;
3703 /* Validate whether all SHF_IA_64_SHORT sections are within
3704 range of the chosen GP. */
3706 if (max_short_vma != 0)
3708 if (max_short_vma - min_short_vma >= 0x400000)
3712 /* xgettext:c-format */
3713 (_("%pB: short data segment overflowed (%#" PRIx64 " >= 0x400000)"),
3714 abfd, (uint64_t) (max_short_vma - min_short_vma));
3717 else if ((gp_val > min_short_vma
3718 && gp_val - min_short_vma > 0x200000)
3719 || (gp_val < max_short_vma
3720 && max_short_vma - gp_val >= 0x200000))
3723 (_("%pB: __gp does not cover short data segment"), abfd);
3728 _bfd_set_gp_value (abfd, gp_val);
3734 elfNN_ia64_final_link (bfd *abfd, struct bfd_link_info *info)
3736 struct elfNN_ia64_link_hash_table *ia64_info;
3737 asection *unwind_output_sec;
3739 ia64_info = elfNN_ia64_hash_table (info);
3740 if (ia64_info == NULL)
3743 /* Make sure we've got ourselves a nice fat __gp value. */
3744 if (!bfd_link_relocatable (info))
3747 struct elf_link_hash_entry *gp;
3749 /* We assume after gp is set, section size will only decrease. We
3750 need to adjust gp for it. */
3751 _bfd_set_gp_value (abfd, 0);
3752 if (! elfNN_ia64_choose_gp (abfd, info, TRUE))
3754 gp_val = _bfd_get_gp_value (abfd);
3756 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
3760 gp->root.type = bfd_link_hash_defined;
3761 gp->root.u.def.value = gp_val;
3762 gp->root.u.def.section = bfd_abs_section_ptr;
3766 /* If we're producing a final executable, we need to sort the contents
3767 of the .IA_64.unwind section. Force this section to be relocated
3768 into memory rather than written immediately to the output file. */
3769 unwind_output_sec = NULL;
3770 if (!bfd_link_relocatable (info))
3772 asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
3775 unwind_output_sec = s->output_section;
3776 unwind_output_sec->contents
3777 = bfd_malloc (unwind_output_sec->size);
3778 if (unwind_output_sec->contents == NULL)
3783 /* Invoke the regular ELF backend linker to do all the work. */
3784 if (!bfd_elf_final_link (abfd, info))
3787 if (unwind_output_sec)
3789 elfNN_ia64_unwind_entry_compare_bfd = abfd;
3790 qsort (unwind_output_sec->contents,
3791 (size_t) (unwind_output_sec->size / 24),
3793 elfNN_ia64_unwind_entry_compare);
3795 if (! bfd_set_section_contents (abfd, unwind_output_sec,
3796 unwind_output_sec->contents, (bfd_vma) 0,
3797 unwind_output_sec->size))
3805 elfNN_ia64_relocate_section (bfd *output_bfd,
3806 struct bfd_link_info *info,
3808 asection *input_section,
3810 Elf_Internal_Rela *relocs,
3811 Elf_Internal_Sym *local_syms,
3812 asection **local_sections)
3814 struct elfNN_ia64_link_hash_table *ia64_info;
3815 Elf_Internal_Shdr *symtab_hdr;
3816 Elf_Internal_Rela *rel;
3817 Elf_Internal_Rela *relend;
3819 bfd_boolean ret_val = TRUE; /* for non-fatal errors */
3822 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3823 ia64_info = elfNN_ia64_hash_table (info);
3824 if (ia64_info == NULL)
3827 /* Infect various flags from the input section to the output section. */
3828 if (bfd_link_relocatable (info))
3832 flags = elf_section_data(input_section)->this_hdr.sh_flags;
3833 flags &= SHF_IA_64_NORECOV;
3835 elf_section_data(input_section->output_section)
3836 ->this_hdr.sh_flags |= flags;
3839 gp_val = _bfd_get_gp_value (output_bfd);
3840 srel = get_reloc_section (input_bfd, ia64_info, input_section, FALSE);
3843 relend = relocs + input_section->reloc_count;
3844 for (; rel < relend; ++rel)
3846 struct elf_link_hash_entry *h;
3847 struct elfNN_ia64_dyn_sym_info *dyn_i;
3848 bfd_reloc_status_type r;
3849 reloc_howto_type *howto;
3850 unsigned long r_symndx;
3851 Elf_Internal_Sym *sym;
3852 unsigned int r_type;
3856 bfd_boolean dynamic_symbol_p;
3857 bfd_boolean undef_weak_ref;
3859 r_type = ELFNN_R_TYPE (rel->r_info);
3860 if (r_type > R_IA64_MAX_RELOC_CODE)
3862 /* xgettext:c-format */
3863 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3864 input_bfd, (int) r_type);
3865 bfd_set_error (bfd_error_bad_value);
3870 howto = ia64_elf_lookup_howto (r_type);
3877 r_symndx = ELFNN_R_SYM (rel->r_info);
3881 undef_weak_ref = FALSE;
3883 if (r_symndx < symtab_hdr->sh_info)
3885 /* Reloc against local symbol. */
3887 sym = local_syms + r_symndx;
3888 sym_sec = local_sections[r_symndx];
3890 value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel);
3891 if (!bfd_link_relocatable (info)
3892 && (sym_sec->flags & SEC_MERGE) != 0
3893 && ELF_ST_TYPE (sym->st_info) == STT_SECTION
3894 && sym_sec->sec_info_type == SEC_INFO_TYPE_MERGE)
3896 struct elfNN_ia64_local_hash_entry *loc_h;
3898 loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, FALSE);
3899 if (loc_h && ! loc_h->sec_merge_done)
3901 struct elfNN_ia64_dyn_sym_info *dynent;
3904 for (count = loc_h->count, dynent = loc_h->info;
3910 _bfd_merged_section_offset (output_bfd, &msec,
3911 elf_section_data (msec)->
3915 dynent->addend -= sym->st_value;
3916 dynent->addend += msec->output_section->vma
3917 + msec->output_offset
3918 - sym_sec->output_section->vma
3919 - sym_sec->output_offset;
3922 /* We may have introduced duplicated entries. We need
3923 to remove them properly. */
3924 count = sort_dyn_sym_info (loc_h->info, loc_h->count);
3925 if (count != loc_h->count)
3927 loc_h->count = count;
3928 loc_h->sorted_count = count;
3931 loc_h->sec_merge_done = 1;
3937 bfd_boolean unresolved_reloc;
3938 bfd_boolean warned, ignored;
3939 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
3941 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3942 r_symndx, symtab_hdr, sym_hashes,
3944 unresolved_reloc, warned, ignored);
3946 if (h->root.type == bfd_link_hash_undefweak)
3947 undef_weak_ref = TRUE;
3948 else if (warned || (ignored && bfd_link_executable (info)))
3952 if (sym_sec != NULL && discarded_section (sym_sec))
3953 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3954 rel, 1, relend, howto, 0, contents);
3956 if (bfd_link_relocatable (info))
3959 hit_addr = contents + rel->r_offset;
3960 value += rel->r_addend;
3961 dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info, r_type);
3972 case R_IA64_DIR32MSB:
3973 case R_IA64_DIR32LSB:
3974 case R_IA64_DIR64MSB:
3975 case R_IA64_DIR64LSB:
3976 /* Install a dynamic relocation for this reloc. */
3977 if ((dynamic_symbol_p || bfd_link_pic (info))
3978 && !(h && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
3979 && r_symndx != STN_UNDEF
3980 && (input_section->flags & SEC_ALLOC) != 0)
3982 unsigned int dyn_r_type;
3986 BFD_ASSERT (srel != NULL);
3993 /* ??? People shouldn't be doing non-pic code in
3994 shared libraries nor dynamic executables. */
3996 /* xgettext:c-format */
3997 (_("%pB: non-pic code with imm relocation against dynamic symbol `%s'"),
3999 h ? h->root.root.string
4000 : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4009 /* If we don't need dynamic symbol lookup, find a
4010 matching RELATIVE relocation. */
4011 dyn_r_type = r_type;
4012 if (dynamic_symbol_p)
4014 dynindx = h->dynindx;
4015 addend = rel->r_addend;
4022 case R_IA64_DIR32MSB:
4023 dyn_r_type = R_IA64_REL32MSB;
4025 case R_IA64_DIR32LSB:
4026 dyn_r_type = R_IA64_REL32LSB;
4028 case R_IA64_DIR64MSB:
4029 dyn_r_type = R_IA64_REL64MSB;
4031 case R_IA64_DIR64LSB:
4032 dyn_r_type = R_IA64_REL64LSB;
4042 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
4043 srel, rel->r_offset, dyn_r_type,
4048 case R_IA64_LTV32MSB:
4049 case R_IA64_LTV32LSB:
4050 case R_IA64_LTV64MSB:
4051 case R_IA64_LTV64LSB:
4052 r = ia64_elf_install_value (hit_addr, value, r_type);
4055 case R_IA64_GPREL22:
4056 case R_IA64_GPREL64I:
4057 case R_IA64_GPREL32MSB:
4058 case R_IA64_GPREL32LSB:
4059 case R_IA64_GPREL64MSB:
4060 case R_IA64_GPREL64LSB:
4061 if (dynamic_symbol_p)
4064 /* xgettext:c-format */
4065 (_("%pB: @gprel relocation against dynamic symbol %s"),
4067 h ? h->root.root.string
4068 : bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4074 r = ia64_elf_install_value (hit_addr, value, r_type);
4077 case R_IA64_LTOFF22:
4078 case R_IA64_LTOFF22X:
4079 case R_IA64_LTOFF64I:
4080 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
4081 value = set_got_entry (input_bfd, info, dyn_i, (h ? h->dynindx : -1),
4082 rel->r_addend, value, R_IA64_DIRNNLSB);
4084 r = ia64_elf_install_value (hit_addr, value, r_type);
4087 case R_IA64_PLTOFF22:
4088 case R_IA64_PLTOFF64I:
4089 case R_IA64_PLTOFF64MSB:
4090 case R_IA64_PLTOFF64LSB:
4091 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
4092 value = set_pltoff_entry (output_bfd, info, dyn_i, value, FALSE);
4094 r = ia64_elf_install_value (hit_addr, value, r_type);
4097 case R_IA64_FPTR64I:
4098 case R_IA64_FPTR32MSB:
4099 case R_IA64_FPTR32LSB:
4100 case R_IA64_FPTR64MSB:
4101 case R_IA64_FPTR64LSB:
4102 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
4103 if (dyn_i->want_fptr)
4105 if (!undef_weak_ref)
4106 value = set_fptr_entry (output_bfd, info, dyn_i, value);
4108 if (!dyn_i->want_fptr || bfd_link_pie (info))
4111 unsigned int dyn_r_type = r_type;
4112 bfd_vma addend = rel->r_addend;
4114 /* Otherwise, we expect the dynamic linker to create
4117 if (dyn_i->want_fptr)
4119 if (r_type == R_IA64_FPTR64I)
4121 /* We can't represent this without a dynamic symbol.
4122 Adjust the relocation to be against an output
4123 section symbol, which are always present in the
4124 dynamic symbol table. */
4125 /* ??? People shouldn't be doing non-pic code in
4126 shared libraries. Hork. */
4128 (_("%pB: linking non-pic code in a position independent executable"),
4135 dyn_r_type = r_type + R_IA64_RELNNLSB - R_IA64_FPTRNNLSB;
4139 if (h->dynindx != -1)
4140 dynindx = h->dynindx;
4142 dynindx = (_bfd_elf_link_lookup_local_dynindx
4143 (info, h->root.u.def.section->owner,
4144 global_sym_index (h)));
4149 dynindx = (_bfd_elf_link_lookup_local_dynindx
4150 (info, input_bfd, (long) r_symndx));
4154 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
4155 srel, rel->r_offset, dyn_r_type,
4159 r = ia64_elf_install_value (hit_addr, value, r_type);
4162 case R_IA64_LTOFF_FPTR22:
4163 case R_IA64_LTOFF_FPTR64I:
4164 case R_IA64_LTOFF_FPTR32MSB:
4165 case R_IA64_LTOFF_FPTR32LSB:
4166 case R_IA64_LTOFF_FPTR64MSB:
4167 case R_IA64_LTOFF_FPTR64LSB:
4171 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
4172 if (dyn_i->want_fptr)
4174 BFD_ASSERT (h == NULL || h->dynindx == -1);
4175 if (!undef_weak_ref)
4176 value = set_fptr_entry (output_bfd, info, dyn_i, value);
4181 /* Otherwise, we expect the dynamic linker to create
4185 if (h->dynindx != -1)
4186 dynindx = h->dynindx;
4188 dynindx = (_bfd_elf_link_lookup_local_dynindx
4189 (info, h->root.u.def.section->owner,
4190 global_sym_index (h)));
4193 dynindx = (_bfd_elf_link_lookup_local_dynindx
4194 (info, input_bfd, (long) r_symndx));
4198 value = set_got_entry (output_bfd, info, dyn_i, dynindx,
4199 rel->r_addend, value, R_IA64_FPTRNNLSB);
4201 r = ia64_elf_install_value (hit_addr, value, r_type);
4205 case R_IA64_PCREL32MSB:
4206 case R_IA64_PCREL32LSB:
4207 case R_IA64_PCREL64MSB:
4208 case R_IA64_PCREL64LSB:
4209 /* Install a dynamic relocation for this reloc. */
4210 if (dynamic_symbol_p && r_symndx != STN_UNDEF)
4212 BFD_ASSERT (srel != NULL);
4214 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
4215 srel, rel->r_offset, r_type,
4216 h->dynindx, rel->r_addend);
4220 case R_IA64_PCREL21B:
4221 case R_IA64_PCREL60B:
4222 /* We should have created a PLT entry for any dynamic symbol. */
4225 dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE);
4227 if (dyn_i && dyn_i->want_plt2)
4229 /* Should have caught this earlier. */
4230 BFD_ASSERT (rel->r_addend == 0);
4232 value = (ia64_info->root.splt->output_section->vma
4233 + ia64_info->root.splt->output_offset
4234 + dyn_i->plt2_offset);
4238 /* Since there's no PLT entry, Validate that this is
4240 BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL);
4242 /* If the symbol is undef_weak, we shouldn't be trying
4243 to call it. There's every chance that we'd wind up
4244 with an out-of-range fixup here. Don't bother setting
4245 any value at all. */
4251 case R_IA64_PCREL21BI:
4252 case R_IA64_PCREL21F:
4253 case R_IA64_PCREL21M:
4254 case R_IA64_PCREL22:
4255 case R_IA64_PCREL64I:
4256 /* The PCREL21BI reloc is specifically not intended for use with
4257 dynamic relocs. PCREL21F and PCREL21M are used for speculation
4258 fixup code, and thus probably ought not be dynamic. The
4259 PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */
4260 if (dynamic_symbol_p)
4264 if (r_type == R_IA64_PCREL21BI)
4265 /* xgettext:c-format */
4266 msg = _("%pB: @internal branch to dynamic symbol %s");
4267 else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M)
4268 /* xgettext:c-format */
4269 msg = _("%pB: speculation fixup to dynamic symbol %s");
4271 /* xgettext:c-format */
4272 msg = _("%pB: @pcrel relocation against dynamic symbol %s");
4273 _bfd_error_handler (msg, input_bfd,
4274 h ? h->root.root.string
4275 : bfd_elf_sym_name (input_bfd,
4285 /* Make pc-relative. */
4286 value -= (input_section->output_section->vma
4287 + input_section->output_offset
4288 + rel->r_offset) & ~ (bfd_vma) 0x3;
4289 r = ia64_elf_install_value (hit_addr, value, r_type);
4292 case R_IA64_SEGREL32MSB:
4293 case R_IA64_SEGREL32LSB:
4294 case R_IA64_SEGREL64MSB:
4295 case R_IA64_SEGREL64LSB:
4297 /* Find the segment that contains the output_section. */
4298 Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section
4299 (output_bfd, input_section->output_section);
4303 r = bfd_reloc_notsupported;
4307 /* The VMA of the segment is the vaddr of the associated
4309 if (value > p->p_vaddr)
4310 value -= p->p_vaddr;
4313 r = ia64_elf_install_value (hit_addr, value, r_type);
4318 case R_IA64_SECREL32MSB:
4319 case R_IA64_SECREL32LSB:
4320 case R_IA64_SECREL64MSB:
4321 case R_IA64_SECREL64LSB:
4322 /* Make output-section relative to section where the symbol
4323 is defined. PR 475 */
4325 value -= sym_sec->output_section->vma;
4326 r = ia64_elf_install_value (hit_addr, value, r_type);
4329 case R_IA64_IPLTMSB:
4330 case R_IA64_IPLTLSB:
4331 /* Install a dynamic relocation for this reloc. */
4332 if ((dynamic_symbol_p || bfd_link_pic (info))
4333 && (input_section->flags & SEC_ALLOC) != 0)
4335 BFD_ASSERT (srel != NULL);
4337 /* If we don't need dynamic symbol lookup, install two
4338 RELATIVE relocations. */
4339 if (!dynamic_symbol_p)
4341 unsigned int dyn_r_type;
4343 if (r_type == R_IA64_IPLTMSB)
4344 dyn_r_type = R_IA64_REL64MSB;
4346 dyn_r_type = R_IA64_REL64LSB;
4348 elfNN_ia64_install_dyn_reloc (output_bfd, info,
4350 srel, rel->r_offset,
4351 dyn_r_type, 0, value);
4352 elfNN_ia64_install_dyn_reloc (output_bfd, info,
4354 srel, rel->r_offset + 8,
4355 dyn_r_type, 0, gp_val);
4358 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
4359 srel, rel->r_offset, r_type,
4360 h->dynindx, rel->r_addend);
4363 if (r_type == R_IA64_IPLTMSB)
4364 r_type = R_IA64_DIR64MSB;
4366 r_type = R_IA64_DIR64LSB;
4367 ia64_elf_install_value (hit_addr, value, r_type);
4368 r = ia64_elf_install_value (hit_addr + 8, gp_val, r_type);
4371 case R_IA64_TPREL14:
4372 case R_IA64_TPREL22:
4373 case R_IA64_TPREL64I:
4374 if (elf_hash_table (info)->tls_sec == NULL)
4375 goto missing_tls_sec;
4376 value -= elfNN_ia64_tprel_base (info);
4377 r = ia64_elf_install_value (hit_addr, value, r_type);
4380 case R_IA64_DTPREL14:
4381 case R_IA64_DTPREL22:
4382 case R_IA64_DTPREL64I:
4383 case R_IA64_DTPREL32LSB:
4384 case R_IA64_DTPREL32MSB:
4385 case R_IA64_DTPREL64LSB:
4386 case R_IA64_DTPREL64MSB:
4387 if (elf_hash_table (info)->tls_sec == NULL)
4388 goto missing_tls_sec;
4389 value -= elfNN_ia64_dtprel_base (info);
4390 r = ia64_elf_install_value (hit_addr, value, r_type);
4393 case R_IA64_LTOFF_TPREL22:
4394 case R_IA64_LTOFF_DTPMOD22:
4395 case R_IA64_LTOFF_DTPREL22:
4398 long dynindx = h ? h->dynindx : -1;
4399 bfd_vma r_addend = rel->r_addend;
4404 case R_IA64_LTOFF_TPREL22:
4405 if (!dynamic_symbol_p)
4407 if (elf_hash_table (info)->tls_sec == NULL)
4408 goto missing_tls_sec;
4409 if (!bfd_link_pic (info))
4410 value -= elfNN_ia64_tprel_base (info);
4413 r_addend += value - elfNN_ia64_dtprel_base (info);
4417 got_r_type = R_IA64_TPREL64LSB;
4419 case R_IA64_LTOFF_DTPMOD22:
4420 if (!dynamic_symbol_p && !bfd_link_pic (info))
4422 got_r_type = R_IA64_DTPMOD64LSB;
4424 case R_IA64_LTOFF_DTPREL22:
4425 if (!dynamic_symbol_p)
4427 if (elf_hash_table (info)->tls_sec == NULL)
4428 goto missing_tls_sec;
4429 value -= elfNN_ia64_dtprel_base (info);
4431 got_r_type = R_IA64_DTPRELNNLSB;
4434 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE);
4435 value = set_got_entry (input_bfd, info, dyn_i, dynindx, r_addend,
4438 r = ia64_elf_install_value (hit_addr, value, r_type);
4443 r = bfd_reloc_notsupported;
4452 case bfd_reloc_undefined:
4453 /* This can happen for global table relative relocs if
4454 __gp is undefined. This is a panic situation so we
4455 don't try to continue. */
4456 (*info->callbacks->undefined_symbol)
4457 (info, "__gp", input_bfd, input_section, rel->r_offset, 1);
4460 case bfd_reloc_notsupported:
4465 name = h->root.root.string;
4467 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4469 (*info->callbacks->warning) (info, _("unsupported reloc"),
4471 input_section, rel->r_offset);
4476 case bfd_reloc_dangerous:
4477 case bfd_reloc_outofrange:
4478 case bfd_reloc_overflow:
4485 name = h->root.root.string;
4487 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
4492 case R_IA64_TPREL14:
4493 case R_IA64_TPREL22:
4494 case R_IA64_TPREL64I:
4495 case R_IA64_DTPREL14:
4496 case R_IA64_DTPREL22:
4497 case R_IA64_DTPREL64I:
4498 case R_IA64_DTPREL32LSB:
4499 case R_IA64_DTPREL32MSB:
4500 case R_IA64_DTPREL64LSB:
4501 case R_IA64_DTPREL64MSB:
4502 case R_IA64_LTOFF_TPREL22:
4503 case R_IA64_LTOFF_DTPMOD22:
4504 case R_IA64_LTOFF_DTPREL22:
4506 /* xgettext:c-format */
4507 (_("%pB: missing TLS section for relocation %s against `%s'"
4508 " at %#" PRIx64 " in section `%pA'."),
4509 input_bfd, howto->name, name,
4510 (uint64_t) rel->r_offset, input_section);
4513 case R_IA64_PCREL21B:
4514 case R_IA64_PCREL21BI:
4515 case R_IA64_PCREL21M:
4516 case R_IA64_PCREL21F:
4517 if (is_elf_hash_table (info->hash))
4519 /* Relaxtion is always performed for ELF output.
4520 Overflow failures for those relocations mean
4521 that the section is too big to relax. */
4523 /* xgettext:c-format */
4524 (_("%pB: Can't relax br (%s) to `%s' at %#" PRIx64
4525 " in section `%pA' with size %#" PRIx64
4527 input_bfd, howto->name, name, (uint64_t) rel->r_offset,
4528 input_section, (uint64_t) input_section->size);
4533 (*info->callbacks->reloc_overflow) (info,
4554 elfNN_ia64_finish_dynamic_symbol (bfd *output_bfd,
4555 struct bfd_link_info *info,
4556 struct elf_link_hash_entry *h,
4557 Elf_Internal_Sym *sym)
4559 struct elfNN_ia64_link_hash_table *ia64_info;
4560 struct elfNN_ia64_dyn_sym_info *dyn_i;
4562 ia64_info = elfNN_ia64_hash_table (info);
4563 if (ia64_info == NULL)
4566 dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE);
4568 /* Fill in the PLT data, if required. */
4569 if (dyn_i && dyn_i->want_plt)
4571 Elf_Internal_Rela outrel;
4574 bfd_vma plt_addr, pltoff_addr, gp_val, plt_index;
4576 gp_val = _bfd_get_gp_value (output_bfd);
4578 /* Initialize the minimal PLT entry. */
4580 plt_index = (dyn_i->plt_offset - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE;
4581 plt_sec = ia64_info->root.splt;
4582 loc = plt_sec->contents + dyn_i->plt_offset;
4584 memcpy (loc, plt_min_entry, PLT_MIN_ENTRY_SIZE);
4585 ia64_elf_install_value (loc, plt_index, R_IA64_IMM22);
4586 ia64_elf_install_value (loc+2, -dyn_i->plt_offset, R_IA64_PCREL21B);
4588 plt_addr = (plt_sec->output_section->vma
4589 + plt_sec->output_offset
4590 + dyn_i->plt_offset);
4591 pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, TRUE);
4593 /* Initialize the FULL PLT entry, if needed. */
4594 if (dyn_i->want_plt2)
4596 loc = plt_sec->contents + dyn_i->plt2_offset;
4598 memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE);
4599 ia64_elf_install_value (loc, pltoff_addr - gp_val, R_IA64_IMM22);
4601 /* Mark the symbol as undefined, rather than as defined in the
4602 plt section. Leave the value alone. */
4603 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4604 first place. But perhaps elflink.c did some for us. */
4605 if (!h->def_regular)
4606 sym->st_shndx = SHN_UNDEF;
4609 /* Create the dynamic relocation. */
4610 outrel.r_offset = pltoff_addr;
4611 if (bfd_little_endian (output_bfd))
4612 outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTLSB);
4614 outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTMSB);
4615 outrel.r_addend = 0;
4617 /* This is fun. In the .IA_64.pltoff section, we've got entries
4618 that correspond both to real PLT entries, and those that
4619 happened to resolve to local symbols but need to be created
4620 to satisfy @pltoff relocations. The .rela.IA_64.pltoff
4621 relocations for the real PLT should come at the end of the
4622 section, so that they can be indexed by plt entry at runtime.
4624 We emitted all of the relocations for the non-PLT @pltoff
4625 entries during relocate_section. So we can consider the
4626 existing sec->reloc_count to be the base of the array of
4629 loc = ia64_info->rel_pltoff_sec->contents;
4630 loc += ((ia64_info->rel_pltoff_sec->reloc_count + plt_index)
4631 * sizeof (ElfNN_External_Rela));
4632 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
4635 /* Mark some specially defined symbols as absolute. */
4636 if (h == ia64_info->root.hdynamic
4637 || h == ia64_info->root.hgot
4638 || h == ia64_info->root.hplt)
4639 sym->st_shndx = SHN_ABS;
4645 elfNN_ia64_finish_dynamic_sections (bfd *abfd,
4646 struct bfd_link_info *info)
4648 struct elfNN_ia64_link_hash_table *ia64_info;
4651 ia64_info = elfNN_ia64_hash_table (info);
4652 if (ia64_info == NULL)
4655 dynobj = ia64_info->root.dynobj;
4657 if (ia64_info->root.dynamic_sections_created)
4659 ElfNN_External_Dyn *dyncon, *dynconend;
4660 asection *sdyn, *sgotplt;
4663 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4664 sgotplt = ia64_info->root.sgotplt;
4665 BFD_ASSERT (sdyn != NULL);
4666 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
4667 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
4669 gp_val = _bfd_get_gp_value (abfd);
4671 for (; dyncon < dynconend; dyncon++)
4673 Elf_Internal_Dyn dyn;
4675 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
4680 dyn.d_un.d_ptr = gp_val;
4684 dyn.d_un.d_val = (ia64_info->minplt_entries
4685 * sizeof (ElfNN_External_Rela));
4689 /* See the comment above in finish_dynamic_symbol. */
4690 dyn.d_un.d_ptr = (ia64_info->rel_pltoff_sec->output_section->vma
4691 + ia64_info->rel_pltoff_sec->output_offset
4692 + (ia64_info->rel_pltoff_sec->reloc_count
4693 * sizeof (ElfNN_External_Rela)));
4696 case DT_IA_64_PLT_RESERVE:
4697 dyn.d_un.d_ptr = (sgotplt->output_section->vma
4698 + sgotplt->output_offset);
4702 bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon);
4705 /* Initialize the PLT0 entry. */
4706 if (ia64_info->root.splt)
4708 bfd_byte *loc = ia64_info->root.splt->contents;
4711 memcpy (loc, plt_header, PLT_HEADER_SIZE);
4713 pltres = (sgotplt->output_section->vma
4714 + sgotplt->output_offset
4717 ia64_elf_install_value (loc+1, pltres, R_IA64_GPREL22);
4724 /* ELF file flag handling: */
4726 /* Function to keep IA-64 specific file flags. */
4728 elfNN_ia64_set_private_flags (bfd *abfd, flagword flags)
4730 BFD_ASSERT (!elf_flags_init (abfd)
4731 || elf_elfheader (abfd)->e_flags == flags);
4733 elf_elfheader (abfd)->e_flags = flags;
4734 elf_flags_init (abfd) = TRUE;
4738 /* Merge backend specific data from an object file to the output
4739 object file when linking. */
4741 elfNN_ia64_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4743 bfd *obfd = info->output_bfd;
4746 bfd_boolean ok = TRUE;
4748 /* Don't even pretend to support mixed-format linking. */
4749 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4750 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4753 in_flags = elf_elfheader (ibfd)->e_flags;
4754 out_flags = elf_elfheader (obfd)->e_flags;
4756 if (! elf_flags_init (obfd))
4758 elf_flags_init (obfd) = TRUE;
4759 elf_elfheader (obfd)->e_flags = in_flags;
4761 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4762 && bfd_get_arch_info (obfd)->the_default)
4764 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
4765 bfd_get_mach (ibfd));
4771 /* Check flag compatibility. */
4772 if (in_flags == out_flags)
4775 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4776 if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP))
4777 elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP;
4779 if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL))
4782 (_("%pB: linking trap-on-NULL-dereference with non-trapping files"),
4785 bfd_set_error (bfd_error_bad_value);
4788 if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE))
4791 (_("%pB: linking big-endian files with little-endian files"),
4794 bfd_set_error (bfd_error_bad_value);
4797 if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64))
4800 (_("%pB: linking 64-bit files with 32-bit files"),
4803 bfd_set_error (bfd_error_bad_value);
4806 if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP))
4809 (_("%pB: linking constant-gp files with non-constant-gp files"),
4812 bfd_set_error (bfd_error_bad_value);
4815 if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP)
4816 != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
4819 (_("%pB: linking auto-pic files with non-auto-pic files"),
4822 bfd_set_error (bfd_error_bad_value);
4830 elfNN_ia64_print_private_bfd_data (bfd *abfd, void * ptr)
4832 FILE *file = (FILE *) ptr;
4833 flagword flags = elf_elfheader (abfd)->e_flags;
4835 BFD_ASSERT (abfd != NULL && ptr != NULL);
4837 fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n",
4838 (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "",
4839 (flags & EF_IA_64_EXT) ? "EXT, " : "",
4840 (flags & EF_IA_64_BE) ? "BE, " : "LE, ",
4841 (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "",
4842 (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "",
4843 (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "",
4844 (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "",
4845 (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32");
4847 _bfd_elf_print_private_bfd_data (abfd, ptr);
4851 static enum elf_reloc_type_class
4852 elfNN_ia64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
4853 const asection *rel_sec ATTRIBUTE_UNUSED,
4854 const Elf_Internal_Rela *rela)
4856 switch ((int) ELFNN_R_TYPE (rela->r_info))
4858 case R_IA64_REL32MSB:
4859 case R_IA64_REL32LSB:
4860 case R_IA64_REL64MSB:
4861 case R_IA64_REL64LSB:
4862 return reloc_class_relative;
4863 case R_IA64_IPLTMSB:
4864 case R_IA64_IPLTLSB:
4865 return reloc_class_plt;
4867 return reloc_class_copy;
4869 return reloc_class_normal;
4873 static const struct bfd_elf_special_section elfNN_ia64_special_sections[] =
4875 { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
4876 { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
4877 { NULL, 0, 0, 0, 0 }
4881 elfNN_ia64_object_p (bfd *abfd)
4884 asection *group, *unwi, *unw;
4887 char *unwi_name, *unw_name;
4890 if (abfd->flags & DYNAMIC)
4893 /* Flags for fake group section. */
4894 flags = (SEC_LINKER_CREATED | SEC_GROUP | SEC_LINK_ONCE
4897 /* We add a fake section group for each .gnu.linkonce.t.* section,
4898 which isn't in a section group, and its unwind sections. */
4899 for (sec = abfd->sections; sec != NULL; sec = sec->next)
4901 if (elf_sec_group (sec) == NULL
4902 && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP))
4903 == (SEC_LINK_ONCE | SEC_CODE))
4904 && CONST_STRNEQ (sec->name, ".gnu.linkonce.t."))
4906 name = sec->name + 16;
4908 amt = strlen (name) + sizeof (".gnu.linkonce.ia64unwi.");
4909 unwi_name = bfd_alloc (abfd, amt);
4913 strcpy (stpcpy (unwi_name, ".gnu.linkonce.ia64unwi."), name);
4914 unwi = bfd_get_section_by_name (abfd, unwi_name);
4916 amt = strlen (name) + sizeof (".gnu.linkonce.ia64unw.");
4917 unw_name = bfd_alloc (abfd, amt);
4921 strcpy (stpcpy (unw_name, ".gnu.linkonce.ia64unw."), name);
4922 unw = bfd_get_section_by_name (abfd, unw_name);
4924 /* We need to create a fake group section for it and its
4926 group = bfd_make_section_anyway_with_flags (abfd, name,
4931 /* Move the fake group section to the beginning. */
4932 bfd_section_list_remove (abfd, group);
4933 bfd_section_list_prepend (abfd, group);
4935 elf_next_in_group (group) = sec;
4937 elf_group_name (sec) = name;
4938 elf_next_in_group (sec) = sec;
4939 elf_sec_group (sec) = group;
4943 elf_group_name (unwi) = name;
4944 elf_next_in_group (unwi) = sec;
4945 elf_next_in_group (sec) = unwi;
4946 elf_sec_group (unwi) = group;
4951 elf_group_name (unw) = name;
4954 elf_next_in_group (unw) = elf_next_in_group (unwi);
4955 elf_next_in_group (unwi) = unw;
4959 elf_next_in_group (unw) = sec;
4960 elf_next_in_group (sec) = unw;
4962 elf_sec_group (unw) = group;
4965 /* Fake SHT_GROUP section header. */
4966 elf_section_data (group)->this_hdr.bfd_section = group;
4967 elf_section_data (group)->this_hdr.sh_type = SHT_GROUP;
4974 elfNN_ia64_hpux_vec (const bfd_target *vec)
4976 extern const bfd_target ia64_elfNN_hpux_be_vec;
4977 return (vec == &ia64_elfNN_hpux_be_vec);
4981 elfNN_hpux_post_process_headers (bfd *abfd,
4982 struct bfd_link_info *info ATTRIBUTE_UNUSED)
4984 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
4986 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
4987 i_ehdrp->e_ident[EI_ABIVERSION] = 1;
4991 elfNN_hpux_backend_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4992 asection *sec, int *retval)
4994 if (bfd_is_com_section (sec))
4996 *retval = SHN_IA_64_ANSI_COMMON;
5003 elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
5006 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
5008 switch (elfsym->internal_elf_sym.st_shndx)
5010 case SHN_IA_64_ANSI_COMMON:
5011 asym->section = bfd_com_section_ptr;
5012 asym->value = elfsym->internal_elf_sym.st_size;
5013 asym->flags &= ~BSF_GLOBAL;
5018 #define TARGET_LITTLE_SYM ia64_elfNN_le_vec
5019 #define TARGET_LITTLE_NAME "elfNN-ia64-little"
5020 #define TARGET_BIG_SYM ia64_elfNN_be_vec
5021 #define TARGET_BIG_NAME "elfNN-ia64-big"
5022 #define ELF_ARCH bfd_arch_ia64
5023 #define ELF_TARGET_ID IA64_ELF_DATA
5024 #define ELF_MACHINE_CODE EM_IA_64
5025 #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */
5026 #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */
5027 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
5028 #define ELF_COMMONPAGESIZE 0x4000 /* 16KB */
5030 #define elf_backend_section_from_shdr \
5031 elfNN_ia64_section_from_shdr
5032 #define elf_backend_section_flags \
5033 elfNN_ia64_section_flags
5034 #define elf_backend_fake_sections \
5035 elfNN_ia64_fake_sections
5036 #define elf_backend_final_write_processing \
5037 elfNN_ia64_final_write_processing
5038 #define elf_backend_add_symbol_hook \
5039 elfNN_ia64_add_symbol_hook
5040 #define elf_backend_additional_program_headers \
5041 elfNN_ia64_additional_program_headers
5042 #define elf_backend_modify_segment_map \
5043 elfNN_ia64_modify_segment_map
5044 #define elf_backend_modify_program_headers \
5045 elfNN_ia64_modify_program_headers
5046 #define elf_info_to_howto \
5047 elfNN_ia64_info_to_howto
5049 #define bfd_elfNN_bfd_reloc_type_lookup \
5050 ia64_elf_reloc_type_lookup
5051 #define bfd_elfNN_bfd_reloc_name_lookup \
5052 ia64_elf_reloc_name_lookup
5053 #define bfd_elfNN_bfd_is_local_label_name \
5054 elfNN_ia64_is_local_label_name
5055 #define bfd_elfNN_bfd_relax_section \
5056 elfNN_ia64_relax_section
5058 #define elf_backend_object_p \
5061 /* Stuff for the BFD linker: */
5062 #define bfd_elfNN_bfd_link_hash_table_create \
5063 elfNN_ia64_hash_table_create
5064 #define elf_backend_create_dynamic_sections \
5065 elfNN_ia64_create_dynamic_sections
5066 #define elf_backend_check_relocs \
5067 elfNN_ia64_check_relocs
5068 #define elf_backend_adjust_dynamic_symbol \
5069 elfNN_ia64_adjust_dynamic_symbol
5070 #define elf_backend_size_dynamic_sections \
5071 elfNN_ia64_size_dynamic_sections
5072 #define elf_backend_omit_section_dynsym \
5073 _bfd_elf_omit_section_dynsym_all
5074 #define elf_backend_relocate_section \
5075 elfNN_ia64_relocate_section
5076 #define elf_backend_finish_dynamic_symbol \
5077 elfNN_ia64_finish_dynamic_symbol
5078 #define elf_backend_finish_dynamic_sections \
5079 elfNN_ia64_finish_dynamic_sections
5080 #define bfd_elfNN_bfd_final_link \
5081 elfNN_ia64_final_link
5083 #define bfd_elfNN_bfd_merge_private_bfd_data \
5084 elfNN_ia64_merge_private_bfd_data
5085 #define bfd_elfNN_bfd_set_private_flags \
5086 elfNN_ia64_set_private_flags
5087 #define bfd_elfNN_bfd_print_private_bfd_data \
5088 elfNN_ia64_print_private_bfd_data
5090 #define elf_backend_plt_readonly 1
5091 #define elf_backend_can_gc_sections 1
5092 #define elf_backend_want_plt_sym 0
5093 #define elf_backend_plt_alignment 5
5094 #define elf_backend_got_header_size 0
5095 #define elf_backend_want_got_plt 1
5096 #define elf_backend_may_use_rel_p 1
5097 #define elf_backend_may_use_rela_p 1
5098 #define elf_backend_default_use_rela_p 1
5099 #define elf_backend_want_dynbss 0
5100 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
5101 #define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol
5102 #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol
5103 #define elf_backend_reloc_type_class elfNN_ia64_reloc_type_class
5104 #define elf_backend_rela_normal 1
5105 #define elf_backend_dtrel_excludes_plt 1
5106 #define elf_backend_special_sections elfNN_ia64_special_sections
5107 #define elf_backend_default_execstack 0
5109 /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
5110 SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
5111 We don't want to flood users with so many error messages. We turn
5112 off the warning for now. It will be turned on later when the Intel
5113 compiler is fixed. */
5114 #define elf_backend_link_order_error_handler NULL
5116 #include "elfNN-target.h"
5118 /* HPUX-specific vectors. */
5120 #undef TARGET_LITTLE_SYM
5121 #undef TARGET_LITTLE_NAME
5122 #undef TARGET_BIG_SYM
5123 #define TARGET_BIG_SYM ia64_elfNN_hpux_be_vec
5124 #undef TARGET_BIG_NAME
5125 #define TARGET_BIG_NAME "elfNN-ia64-hpux-big"
5127 /* These are HP-UX specific functions. */
5129 #undef elf_backend_post_process_headers
5130 #define elf_backend_post_process_headers elfNN_hpux_post_process_headers
5132 #undef elf_backend_section_from_bfd_section
5133 #define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section
5135 #undef elf_backend_symbol_processing
5136 #define elf_backend_symbol_processing elfNN_hpux_backend_symbol_processing
5138 #undef elf_backend_want_p_paddr_set_to_zero
5139 #define elf_backend_want_p_paddr_set_to_zero 1
5141 #undef ELF_COMMONPAGESIZE
5143 #define ELF_OSABI ELFOSABI_HPUX
5146 #define elfNN_bed elfNN_ia64_hpux_bed
5148 #include "elfNN-target.h"