Add new bitfield 'want_p_paddr_set_to_zero'.
[binutils-gdb.git] / bfd / elfxx-ia64.c
1 /* IA-64 support for 64-bit ELF
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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 2 of the License, or
10 (at your option) any later version.
11
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.
16
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include "elf-bfd.h"
25 #include "opcode/ia64.h"
26 #include "elf/ia64.h"
27
28 /* THE RULES for all the stuff the linker creates --
29
30 GOT Entries created in response to LTOFF or LTOFF_FPTR
31 relocations. Dynamic relocs created for dynamic
32 symbols in an application; REL relocs for locals
33 in a shared library.
34
35 FPTR The canonical function descriptor. Created for local
36 symbols in applications. Descriptors for dynamic symbols
37 and local symbols in shared libraries are created by
38 ld.so. Thus there are no dynamic relocs against these
39 objects. The FPTR relocs for such _are_ passed through
40 to the dynamic relocation tables.
41
42 FULL_PLT Created for a PCREL21B relocation against a dynamic symbol.
43 Requires the creation of a PLTOFF entry. This does not
44 require any dynamic relocations.
45
46 PLTOFF Created by PLTOFF relocations. For local symbols, this
47 is an alternate function descriptor, and in shared libraries
48 requires two REL relocations. Note that this cannot be
49 transformed into an FPTR relocation, since it must be in
50 range of the GP. For dynamic symbols, this is a function
51 descriptor for a MIN_PLT entry, and requires one IPLT reloc.
52
53 MIN_PLT Created by PLTOFF entries against dynamic symbols. This
54 does not reqire dynamic relocations. */
55
56 #define USE_RELA /* we want RELA relocs, not REL */
57
58 #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0])))
59
60 typedef struct bfd_hash_entry *(*new_hash_entry_func)
61 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
62
63 /* In dynamically (linker-) created sections, we generally need to keep track
64 of the place a symbol or expression got allocated to. This is done via hash
65 tables that store entries of the following type. */
66
67 struct elfNN_ia64_dyn_sym_info
68 {
69 /* The addend for which this entry is relevant. */
70 bfd_vma addend;
71
72 /* Next addend in the list. */
73 struct elfNN_ia64_dyn_sym_info *next;
74
75 bfd_vma got_offset;
76 bfd_vma fptr_offset;
77 bfd_vma pltoff_offset;
78 bfd_vma plt_offset;
79 bfd_vma plt2_offset;
80 bfd_vma tprel_offset;
81 bfd_vma dtpmod_offset;
82 bfd_vma dtprel_offset;
83
84 /* The symbol table entry, if any, that this was derrived from. */
85 struct elf_link_hash_entry *h;
86
87 /* Used to count non-got, non-plt relocations for delayed sizing
88 of relocation sections. */
89 struct elfNN_ia64_dyn_reloc_entry
90 {
91 struct elfNN_ia64_dyn_reloc_entry *next;
92 asection *srel;
93 int type;
94 int count;
95 } *reloc_entries;
96
97 /* True when the section contents have been updated. */
98 unsigned got_done : 1;
99 unsigned fptr_done : 1;
100 unsigned pltoff_done : 1;
101 unsigned tprel_done : 1;
102 unsigned dtpmod_done : 1;
103 unsigned dtprel_done : 1;
104
105 /* True for the different kinds of linker data we want created. */
106 unsigned want_got : 1;
107 unsigned want_fptr : 1;
108 unsigned want_ltoff_fptr : 1;
109 unsigned want_plt : 1;
110 unsigned want_plt2 : 1;
111 unsigned want_pltoff : 1;
112 unsigned want_tprel : 1;
113 unsigned want_dtpmod : 1;
114 unsigned want_dtprel : 1;
115 };
116
117 struct elfNN_ia64_local_hash_entry
118 {
119 struct bfd_hash_entry root;
120 struct elfNN_ia64_dyn_sym_info *info;
121
122 /* True if this hash entry's addends was translated for
123 SHF_MERGE optimization. */
124 unsigned sec_merge_done : 1;
125 };
126
127 struct elfNN_ia64_local_hash_table
128 {
129 struct bfd_hash_table root;
130 /* No additional fields for now. */
131 };
132
133 struct elfNN_ia64_link_hash_entry
134 {
135 struct elf_link_hash_entry root;
136 struct elfNN_ia64_dyn_sym_info *info;
137 };
138
139 struct elfNN_ia64_link_hash_table
140 {
141 /* The main hash table. */
142 struct elf_link_hash_table root;
143
144 asection *got_sec; /* the linkage table section (or NULL) */
145 asection *rel_got_sec; /* dynamic relocation section for same */
146 asection *fptr_sec; /* function descriptor table (or NULL) */
147 asection *plt_sec; /* the primary plt section (or NULL) */
148 asection *pltoff_sec; /* private descriptors for plt (or NULL) */
149 asection *rel_pltoff_sec; /* dynamic relocation section for same */
150
151 bfd_size_type minplt_entries; /* number of minplt entries */
152 unsigned reltext : 1; /* are there relocs against readonly sections? */
153
154 struct elfNN_ia64_local_hash_table loc_hash_table;
155 };
156
157 #define elfNN_ia64_hash_table(p) \
158 ((struct elfNN_ia64_link_hash_table *) ((p)->hash))
159
160 static bfd_reloc_status_type elfNN_ia64_reloc
161 PARAMS ((bfd *abfd, arelent *reloc, asymbol *sym, PTR data,
162 asection *input_section, bfd *output_bfd, char **error_message));
163 static reloc_howto_type * lookup_howto
164 PARAMS ((unsigned int rtype));
165 static reloc_howto_type *elfNN_ia64_reloc_type_lookup
166 PARAMS ((bfd *abfd, bfd_reloc_code_real_type bfd_code));
167 static void elfNN_ia64_info_to_howto
168 PARAMS ((bfd *abfd, arelent *bfd_reloc, ElfNN_Internal_Rela *elf_reloc));
169 static boolean elfNN_ia64_relax_section
170 PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info,
171 boolean *again));
172 static boolean is_unwind_section_name
173 PARAMS ((bfd *abfd, const char *));
174 static boolean elfNN_ia64_section_from_shdr
175 PARAMS ((bfd *, ElfNN_Internal_Shdr *, const char *));
176 static boolean elfNN_ia64_section_flags
177 PARAMS ((flagword *, ElfNN_Internal_Shdr *));
178 static boolean elfNN_ia64_fake_sections
179 PARAMS ((bfd *abfd, ElfNN_Internal_Shdr *hdr, asection *sec));
180 static void elfNN_ia64_final_write_processing
181 PARAMS ((bfd *abfd, boolean linker));
182 static boolean elfNN_ia64_add_symbol_hook
183 PARAMS ((bfd *abfd, struct bfd_link_info *info, const Elf_Internal_Sym *sym,
184 const char **namep, flagword *flagsp, asection **secp,
185 bfd_vma *valp));
186 static boolean elfNN_ia64_aix_vec
187 PARAMS ((const bfd_target *vec));
188 static boolean elfNN_ia64_aix_add_symbol_hook
189 PARAMS ((bfd *abfd, struct bfd_link_info *info, const Elf_Internal_Sym *sym,
190 const char **namep, flagword *flagsp, asection **secp,
191 bfd_vma *valp));
192 static boolean elfNN_ia64_aix_link_add_symbols
193 PARAMS ((bfd *abfd, struct bfd_link_info *info));
194 static int elfNN_ia64_additional_program_headers
195 PARAMS ((bfd *abfd));
196 static boolean elfNN_ia64_modify_segment_map
197 PARAMS ((bfd *));
198 static boolean elfNN_ia64_is_local_label_name
199 PARAMS ((bfd *abfd, const char *name));
200 static boolean elfNN_ia64_dynamic_symbol_p
201 PARAMS ((struct elf_link_hash_entry *h, struct bfd_link_info *info));
202 static boolean elfNN_ia64_local_hash_table_init
203 PARAMS ((struct elfNN_ia64_local_hash_table *ht, bfd *abfd,
204 new_hash_entry_func new));
205 static struct bfd_hash_entry *elfNN_ia64_new_loc_hash_entry
206 PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
207 const char *string));
208 static struct bfd_hash_entry *elfNN_ia64_new_elf_hash_entry
209 PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
210 const char *string));
211 static void elfNN_ia64_hash_copy_indirect
212 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
213 static void elfNN_ia64_hash_hide_symbol
214 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
215 static struct bfd_link_hash_table *elfNN_ia64_hash_table_create
216 PARAMS ((bfd *abfd));
217 static struct elfNN_ia64_local_hash_entry *elfNN_ia64_local_hash_lookup
218 PARAMS ((struct elfNN_ia64_local_hash_table *table, const char *string,
219 boolean create, boolean copy));
220 static boolean elfNN_ia64_global_dyn_sym_thunk
221 PARAMS ((struct bfd_hash_entry *, PTR));
222 static boolean elfNN_ia64_local_dyn_sym_thunk
223 PARAMS ((struct bfd_hash_entry *, PTR));
224 static void elfNN_ia64_dyn_sym_traverse
225 PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
226 boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR),
227 PTR info));
228 static boolean elfNN_ia64_create_dynamic_sections
229 PARAMS ((bfd *abfd, struct bfd_link_info *info));
230 static struct elfNN_ia64_local_hash_entry * get_local_sym_hash
231 PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
232 bfd *abfd, const Elf_Internal_Rela *rel, boolean create));
233 static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info
234 PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
235 struct elf_link_hash_entry *h,
236 bfd *abfd, const Elf_Internal_Rela *rel, boolean create));
237 static asection *get_got
238 PARAMS ((bfd *abfd, struct bfd_link_info *info,
239 struct elfNN_ia64_link_hash_table *ia64_info));
240 static asection *get_fptr
241 PARAMS ((bfd *abfd, struct bfd_link_info *info,
242 struct elfNN_ia64_link_hash_table *ia64_info));
243 static asection *get_pltoff
244 PARAMS ((bfd *abfd, struct bfd_link_info *info,
245 struct elfNN_ia64_link_hash_table *ia64_info));
246 static asection *get_reloc_section
247 PARAMS ((bfd *abfd, struct elfNN_ia64_link_hash_table *ia64_info,
248 asection *sec, boolean create));
249 static boolean count_dyn_reloc
250 PARAMS ((bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
251 asection *srel, int type));
252 static boolean elfNN_ia64_check_relocs
253 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
254 const Elf_Internal_Rela *relocs));
255 static boolean elfNN_ia64_adjust_dynamic_symbol
256 PARAMS ((struct bfd_link_info *info, struct elf_link_hash_entry *h));
257 static long global_sym_index
258 PARAMS ((struct elf_link_hash_entry *h));
259 static boolean allocate_fptr
260 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
261 static boolean allocate_global_data_got
262 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
263 static boolean allocate_global_fptr_got
264 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
265 static boolean allocate_local_got
266 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
267 static boolean allocate_pltoff_entries
268 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
269 static boolean allocate_plt_entries
270 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
271 static boolean allocate_plt2_entries
272 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
273 static boolean allocate_dynrel_entries
274 PARAMS ((struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data));
275 static boolean elfNN_ia64_size_dynamic_sections
276 PARAMS ((bfd *output_bfd, struct bfd_link_info *info));
277 static bfd_reloc_status_type elfNN_ia64_install_value
278 PARAMS ((bfd *abfd, bfd_byte *hit_addr, bfd_vma val, unsigned int r_type));
279 static void elfNN_ia64_install_dyn_reloc
280 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
281 asection *srel, bfd_vma offset, unsigned int type,
282 long dynindx, bfd_vma addend));
283 static bfd_vma set_got_entry
284 PARAMS ((bfd *abfd, struct bfd_link_info *info,
285 struct elfNN_ia64_dyn_sym_info *dyn_i, long dynindx,
286 bfd_vma addend, bfd_vma value, unsigned int dyn_r_type));
287 static bfd_vma set_fptr_entry
288 PARAMS ((bfd *abfd, struct bfd_link_info *info,
289 struct elfNN_ia64_dyn_sym_info *dyn_i,
290 bfd_vma value));
291 static bfd_vma set_pltoff_entry
292 PARAMS ((bfd *abfd, struct bfd_link_info *info,
293 struct elfNN_ia64_dyn_sym_info *dyn_i,
294 bfd_vma value, boolean));
295 static bfd_vma elfNN_ia64_tprel_base
296 PARAMS ((struct bfd_link_info *info));
297 static bfd_vma elfNN_ia64_dtprel_base
298 PARAMS ((struct bfd_link_info *info));
299 static int elfNN_ia64_unwind_entry_compare
300 PARAMS ((const PTR, const PTR));
301 static boolean elfNN_ia64_final_link
302 PARAMS ((bfd *abfd, struct bfd_link_info *info));
303 static boolean elfNN_ia64_relocate_section
304 PARAMS ((bfd *output_bfd, struct bfd_link_info *info, bfd *input_bfd,
305 asection *input_section, bfd_byte *contents,
306 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
307 asection **local_sections));
308 static boolean elfNN_ia64_finish_dynamic_symbol
309 PARAMS ((bfd *output_bfd, struct bfd_link_info *info,
310 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
311 static boolean elfNN_ia64_finish_dynamic_sections
312 PARAMS ((bfd *abfd, struct bfd_link_info *info));
313 static boolean elfNN_ia64_set_private_flags
314 PARAMS ((bfd *abfd, flagword flags));
315 static boolean elfNN_ia64_merge_private_bfd_data
316 PARAMS ((bfd *ibfd, bfd *obfd));
317 static boolean elfNN_ia64_print_private_bfd_data
318 PARAMS ((bfd *abfd, PTR ptr));
319 static enum elf_reloc_type_class elfNN_ia64_reloc_type_class
320 PARAMS ((const Elf_Internal_Rela *));
321 static boolean elfNN_ia64_hpux_vec
322 PARAMS ((const bfd_target *vec));
323 static void elfNN_hpux_post_process_headers
324 PARAMS ((bfd *abfd, struct bfd_link_info *info));
325 boolean elfNN_hpux_backend_section_from_bfd_section
326 PARAMS ((bfd *abfd, asection *sec, int *retval));
327 \f
328 /* ia64-specific relocation. */
329
330 /* Perform a relocation. Not much to do here as all the hard work is
331 done in elfNN_ia64_final_link_relocate. */
332 static bfd_reloc_status_type
333 elfNN_ia64_reloc (abfd, reloc, sym, data, input_section,
334 output_bfd, error_message)
335 bfd *abfd ATTRIBUTE_UNUSED;
336 arelent *reloc;
337 asymbol *sym ATTRIBUTE_UNUSED;
338 PTR data ATTRIBUTE_UNUSED;
339 asection *input_section;
340 bfd *output_bfd;
341 char **error_message;
342 {
343 if (output_bfd)
344 {
345 reloc->address += input_section->output_offset;
346 return bfd_reloc_ok;
347 }
348 *error_message = "Unsupported call to elfNN_ia64_reloc";
349 return bfd_reloc_notsupported;
350 }
351
352 #define IA64_HOWTO(TYPE, NAME, SIZE, PCREL, IN) \
353 HOWTO (TYPE, 0, SIZE, 0, PCREL, 0, complain_overflow_signed, \
354 elfNN_ia64_reloc, NAME, false, 0, 0, IN)
355
356 /* This table has to be sorted according to increasing number of the
357 TYPE field. */
358 static reloc_howto_type ia64_howto_table[] =
359 {
360 IA64_HOWTO (R_IA64_NONE, "NONE", 0, false, true),
361
362 IA64_HOWTO (R_IA64_IMM14, "IMM14", 0, false, true),
363 IA64_HOWTO (R_IA64_IMM22, "IMM22", 0, false, true),
364 IA64_HOWTO (R_IA64_IMM64, "IMM64", 0, false, true),
365 IA64_HOWTO (R_IA64_DIR32MSB, "DIR32MSB", 2, false, true),
366 IA64_HOWTO (R_IA64_DIR32LSB, "DIR32LSB", 2, false, true),
367 IA64_HOWTO (R_IA64_DIR64MSB, "DIR64MSB", 4, false, true),
368 IA64_HOWTO (R_IA64_DIR64LSB, "DIR64LSB", 4, false, true),
369
370 IA64_HOWTO (R_IA64_GPREL22, "GPREL22", 0, false, true),
371 IA64_HOWTO (R_IA64_GPREL64I, "GPREL64I", 0, false, true),
372 IA64_HOWTO (R_IA64_GPREL32MSB, "GPREL32MSB", 2, false, true),
373 IA64_HOWTO (R_IA64_GPREL32LSB, "GPREL32LSB", 2, false, true),
374 IA64_HOWTO (R_IA64_GPREL64MSB, "GPREL64MSB", 4, false, true),
375 IA64_HOWTO (R_IA64_GPREL64LSB, "GPREL64LSB", 4, false, true),
376
377 IA64_HOWTO (R_IA64_LTOFF22, "LTOFF22", 0, false, true),
378 IA64_HOWTO (R_IA64_LTOFF64I, "LTOFF64I", 0, false, true),
379
380 IA64_HOWTO (R_IA64_PLTOFF22, "PLTOFF22", 0, false, true),
381 IA64_HOWTO (R_IA64_PLTOFF64I, "PLTOFF64I", 0, false, true),
382 IA64_HOWTO (R_IA64_PLTOFF64MSB, "PLTOFF64MSB", 4, false, true),
383 IA64_HOWTO (R_IA64_PLTOFF64LSB, "PLTOFF64LSB", 4, false, true),
384
385 IA64_HOWTO (R_IA64_FPTR64I, "FPTR64I", 0, false, true),
386 IA64_HOWTO (R_IA64_FPTR32MSB, "FPTR32MSB", 2, false, true),
387 IA64_HOWTO (R_IA64_FPTR32LSB, "FPTR32LSB", 2, false, true),
388 IA64_HOWTO (R_IA64_FPTR64MSB, "FPTR64MSB", 4, false, true),
389 IA64_HOWTO (R_IA64_FPTR64LSB, "FPTR64LSB", 4, false, true),
390
391 IA64_HOWTO (R_IA64_PCREL60B, "PCREL60B", 0, true, true),
392 IA64_HOWTO (R_IA64_PCREL21B, "PCREL21B", 0, true, true),
393 IA64_HOWTO (R_IA64_PCREL21M, "PCREL21M", 0, true, true),
394 IA64_HOWTO (R_IA64_PCREL21F, "PCREL21F", 0, true, true),
395 IA64_HOWTO (R_IA64_PCREL32MSB, "PCREL32MSB", 2, true, true),
396 IA64_HOWTO (R_IA64_PCREL32LSB, "PCREL32LSB", 2, true, true),
397 IA64_HOWTO (R_IA64_PCREL64MSB, "PCREL64MSB", 4, true, true),
398 IA64_HOWTO (R_IA64_PCREL64LSB, "PCREL64LSB", 4, true, true),
399
400 IA64_HOWTO (R_IA64_LTOFF_FPTR22, "LTOFF_FPTR22", 0, false, true),
401 IA64_HOWTO (R_IA64_LTOFF_FPTR64I, "LTOFF_FPTR64I", 0, false, true),
402 IA64_HOWTO (R_IA64_LTOFF_FPTR32MSB, "LTOFF_FPTR32MSB", 2, false, true),
403 IA64_HOWTO (R_IA64_LTOFF_FPTR32LSB, "LTOFF_FPTR32LSB", 2, false, true),
404 IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB, "LTOFF_FPTR64MSB", 4, false, true),
405 IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB, "LTOFF_FPTR64LSB", 4, false, true),
406
407 IA64_HOWTO (R_IA64_SEGREL32MSB, "SEGREL32MSB", 2, false, true),
408 IA64_HOWTO (R_IA64_SEGREL32LSB, "SEGREL32LSB", 2, false, true),
409 IA64_HOWTO (R_IA64_SEGREL64MSB, "SEGREL64MSB", 4, false, true),
410 IA64_HOWTO (R_IA64_SEGREL64LSB, "SEGREL64LSB", 4, false, true),
411
412 IA64_HOWTO (R_IA64_SECREL32MSB, "SECREL32MSB", 2, false, true),
413 IA64_HOWTO (R_IA64_SECREL32LSB, "SECREL32LSB", 2, false, true),
414 IA64_HOWTO (R_IA64_SECREL64MSB, "SECREL64MSB", 4, false, true),
415 IA64_HOWTO (R_IA64_SECREL64LSB, "SECREL64LSB", 4, false, true),
416
417 IA64_HOWTO (R_IA64_REL32MSB, "REL32MSB", 2, false, true),
418 IA64_HOWTO (R_IA64_REL32LSB, "REL32LSB", 2, false, true),
419 IA64_HOWTO (R_IA64_REL64MSB, "REL64MSB", 4, false, true),
420 IA64_HOWTO (R_IA64_REL64LSB, "REL64LSB", 4, false, true),
421
422 IA64_HOWTO (R_IA64_LTV32MSB, "LTV32MSB", 2, false, true),
423 IA64_HOWTO (R_IA64_LTV32LSB, "LTV32LSB", 2, false, true),
424 IA64_HOWTO (R_IA64_LTV64MSB, "LTV64MSB", 4, false, true),
425 IA64_HOWTO (R_IA64_LTV64LSB, "LTV64LSB", 4, false, true),
426
427 IA64_HOWTO (R_IA64_PCREL21BI, "PCREL21BI", 0, true, true),
428 IA64_HOWTO (R_IA64_PCREL22, "PCREL22", 0, true, true),
429 IA64_HOWTO (R_IA64_PCREL64I, "PCREL64I", 0, true, true),
430
431 IA64_HOWTO (R_IA64_IPLTMSB, "IPLTMSB", 4, false, true),
432 IA64_HOWTO (R_IA64_IPLTLSB, "IPLTLSB", 4, false, true),
433 IA64_HOWTO (R_IA64_COPY, "COPY", 4, false, true),
434 IA64_HOWTO (R_IA64_LTOFF22X, "LTOFF22X", 0, false, true),
435 IA64_HOWTO (R_IA64_LDXMOV, "LDXMOV", 0, false, true),
436
437 IA64_HOWTO (R_IA64_TPREL14, "TPREL14", 0, false, false),
438 IA64_HOWTO (R_IA64_TPREL22, "TPREL22", 0, false, false),
439 IA64_HOWTO (R_IA64_TPREL64I, "TPREL64I", 0, false, false),
440 IA64_HOWTO (R_IA64_TPREL64MSB, "TPREL64MSB", 8, false, false),
441 IA64_HOWTO (R_IA64_TPREL64LSB, "TPREL64LSB", 8, false, false),
442 IA64_HOWTO (R_IA64_LTOFF_TPREL22, "LTOFF_TPREL22", 0, false, false),
443
444 IA64_HOWTO (R_IA64_DTPMOD64MSB, "TPREL64MSB", 8, false, false),
445 IA64_HOWTO (R_IA64_DTPMOD64LSB, "TPREL64LSB", 8, false, false),
446 IA64_HOWTO (R_IA64_LTOFF_DTPMOD22, "LTOFF_DTPMOD22", 0, false, false),
447
448 IA64_HOWTO (R_IA64_DTPREL14, "DTPREL14", 0, false, false),
449 IA64_HOWTO (R_IA64_DTPREL22, "DTPREL22", 0, false, false),
450 IA64_HOWTO (R_IA64_DTPREL64I, "DTPREL64I", 0, false, false),
451 IA64_HOWTO (R_IA64_DTPREL32MSB, "DTPREL32MSB", 4, false, false),
452 IA64_HOWTO (R_IA64_DTPREL32LSB, "DTPREL32LSB", 4, false, false),
453 IA64_HOWTO (R_IA64_DTPREL64MSB, "DTPREL64MSB", 8, false, false),
454 IA64_HOWTO (R_IA64_DTPREL64LSB, "DTPREL64LSB", 8, false, false),
455 IA64_HOWTO (R_IA64_LTOFF_DTPREL22, "LTOFF_DTPREL22", 0, false, false),
456 };
457
458 static unsigned char elf_code_to_howto_index[R_IA64_MAX_RELOC_CODE + 1];
459
460 /* Given a BFD reloc type, return the matching HOWTO structure. */
461
462 static reloc_howto_type *
463 lookup_howto (rtype)
464 unsigned int rtype;
465 {
466 static int inited = 0;
467 int i;
468
469 if (!inited)
470 {
471 inited = 1;
472
473 memset (elf_code_to_howto_index, 0xff, sizeof (elf_code_to_howto_index));
474 for (i = 0; i < NELEMS (ia64_howto_table); ++i)
475 elf_code_to_howto_index[ia64_howto_table[i].type] = i;
476 }
477
478 BFD_ASSERT (rtype <= R_IA64_MAX_RELOC_CODE);
479 i = elf_code_to_howto_index[rtype];
480 if (i >= NELEMS (ia64_howto_table))
481 return 0;
482 return ia64_howto_table + i;
483 }
484
485 static reloc_howto_type*
486 elfNN_ia64_reloc_type_lookup (abfd, bfd_code)
487 bfd *abfd ATTRIBUTE_UNUSED;
488 bfd_reloc_code_real_type bfd_code;
489 {
490 unsigned int rtype;
491
492 switch (bfd_code)
493 {
494 case BFD_RELOC_NONE: rtype = R_IA64_NONE; break;
495
496 case BFD_RELOC_IA64_IMM14: rtype = R_IA64_IMM14; break;
497 case BFD_RELOC_IA64_IMM22: rtype = R_IA64_IMM22; break;
498 case BFD_RELOC_IA64_IMM64: rtype = R_IA64_IMM64; break;
499
500 case BFD_RELOC_IA64_DIR32MSB: rtype = R_IA64_DIR32MSB; break;
501 case BFD_RELOC_IA64_DIR32LSB: rtype = R_IA64_DIR32LSB; break;
502 case BFD_RELOC_IA64_DIR64MSB: rtype = R_IA64_DIR64MSB; break;
503 case BFD_RELOC_IA64_DIR64LSB: rtype = R_IA64_DIR64LSB; break;
504
505 case BFD_RELOC_IA64_GPREL22: rtype = R_IA64_GPREL22; break;
506 case BFD_RELOC_IA64_GPREL64I: rtype = R_IA64_GPREL64I; break;
507 case BFD_RELOC_IA64_GPREL32MSB: rtype = R_IA64_GPREL32MSB; break;
508 case BFD_RELOC_IA64_GPREL32LSB: rtype = R_IA64_GPREL32LSB; break;
509 case BFD_RELOC_IA64_GPREL64MSB: rtype = R_IA64_GPREL64MSB; break;
510 case BFD_RELOC_IA64_GPREL64LSB: rtype = R_IA64_GPREL64LSB; break;
511
512 case BFD_RELOC_IA64_LTOFF22: rtype = R_IA64_LTOFF22; break;
513 case BFD_RELOC_IA64_LTOFF64I: rtype = R_IA64_LTOFF64I; break;
514
515 case BFD_RELOC_IA64_PLTOFF22: rtype = R_IA64_PLTOFF22; break;
516 case BFD_RELOC_IA64_PLTOFF64I: rtype = R_IA64_PLTOFF64I; break;
517 case BFD_RELOC_IA64_PLTOFF64MSB: rtype = R_IA64_PLTOFF64MSB; break;
518 case BFD_RELOC_IA64_PLTOFF64LSB: rtype = R_IA64_PLTOFF64LSB; break;
519 case BFD_RELOC_IA64_FPTR64I: rtype = R_IA64_FPTR64I; break;
520 case BFD_RELOC_IA64_FPTR32MSB: rtype = R_IA64_FPTR32MSB; break;
521 case BFD_RELOC_IA64_FPTR32LSB: rtype = R_IA64_FPTR32LSB; break;
522 case BFD_RELOC_IA64_FPTR64MSB: rtype = R_IA64_FPTR64MSB; break;
523 case BFD_RELOC_IA64_FPTR64LSB: rtype = R_IA64_FPTR64LSB; break;
524
525 case BFD_RELOC_IA64_PCREL21B: rtype = R_IA64_PCREL21B; break;
526 case BFD_RELOC_IA64_PCREL21BI: rtype = R_IA64_PCREL21BI; break;
527 case BFD_RELOC_IA64_PCREL21M: rtype = R_IA64_PCREL21M; break;
528 case BFD_RELOC_IA64_PCREL21F: rtype = R_IA64_PCREL21F; break;
529 case BFD_RELOC_IA64_PCREL22: rtype = R_IA64_PCREL22; break;
530 case BFD_RELOC_IA64_PCREL60B: rtype = R_IA64_PCREL60B; break;
531 case BFD_RELOC_IA64_PCREL64I: rtype = R_IA64_PCREL64I; break;
532 case BFD_RELOC_IA64_PCREL32MSB: rtype = R_IA64_PCREL32MSB; break;
533 case BFD_RELOC_IA64_PCREL32LSB: rtype = R_IA64_PCREL32LSB; break;
534 case BFD_RELOC_IA64_PCREL64MSB: rtype = R_IA64_PCREL64MSB; break;
535 case BFD_RELOC_IA64_PCREL64LSB: rtype = R_IA64_PCREL64LSB; break;
536
537 case BFD_RELOC_IA64_LTOFF_FPTR22: rtype = R_IA64_LTOFF_FPTR22; break;
538 case BFD_RELOC_IA64_LTOFF_FPTR64I: rtype = R_IA64_LTOFF_FPTR64I; break;
539 case BFD_RELOC_IA64_LTOFF_FPTR32MSB: rtype = R_IA64_LTOFF_FPTR32MSB; break;
540 case BFD_RELOC_IA64_LTOFF_FPTR32LSB: rtype = R_IA64_LTOFF_FPTR32LSB; break;
541 case BFD_RELOC_IA64_LTOFF_FPTR64MSB: rtype = R_IA64_LTOFF_FPTR64MSB; break;
542 case BFD_RELOC_IA64_LTOFF_FPTR64LSB: rtype = R_IA64_LTOFF_FPTR64LSB; break;
543
544 case BFD_RELOC_IA64_SEGREL32MSB: rtype = R_IA64_SEGREL32MSB; break;
545 case BFD_RELOC_IA64_SEGREL32LSB: rtype = R_IA64_SEGREL32LSB; break;
546 case BFD_RELOC_IA64_SEGREL64MSB: rtype = R_IA64_SEGREL64MSB; break;
547 case BFD_RELOC_IA64_SEGREL64LSB: rtype = R_IA64_SEGREL64LSB; break;
548
549 case BFD_RELOC_IA64_SECREL32MSB: rtype = R_IA64_SECREL32MSB; break;
550 case BFD_RELOC_IA64_SECREL32LSB: rtype = R_IA64_SECREL32LSB; break;
551 case BFD_RELOC_IA64_SECREL64MSB: rtype = R_IA64_SECREL64MSB; break;
552 case BFD_RELOC_IA64_SECREL64LSB: rtype = R_IA64_SECREL64LSB; break;
553
554 case BFD_RELOC_IA64_REL32MSB: rtype = R_IA64_REL32MSB; break;
555 case BFD_RELOC_IA64_REL32LSB: rtype = R_IA64_REL32LSB; break;
556 case BFD_RELOC_IA64_REL64MSB: rtype = R_IA64_REL64MSB; break;
557 case BFD_RELOC_IA64_REL64LSB: rtype = R_IA64_REL64LSB; break;
558
559 case BFD_RELOC_IA64_LTV32MSB: rtype = R_IA64_LTV32MSB; break;
560 case BFD_RELOC_IA64_LTV32LSB: rtype = R_IA64_LTV32LSB; break;
561 case BFD_RELOC_IA64_LTV64MSB: rtype = R_IA64_LTV64MSB; break;
562 case BFD_RELOC_IA64_LTV64LSB: rtype = R_IA64_LTV64LSB; break;
563
564 case BFD_RELOC_IA64_IPLTMSB: rtype = R_IA64_IPLTMSB; break;
565 case BFD_RELOC_IA64_IPLTLSB: rtype = R_IA64_IPLTLSB; break;
566 case BFD_RELOC_IA64_COPY: rtype = R_IA64_COPY; break;
567 case BFD_RELOC_IA64_LTOFF22X: rtype = R_IA64_LTOFF22X; break;
568 case BFD_RELOC_IA64_LDXMOV: rtype = R_IA64_LDXMOV; break;
569
570 case BFD_RELOC_IA64_TPREL14: rtype = R_IA64_TPREL14; break;
571 case BFD_RELOC_IA64_TPREL22: rtype = R_IA64_TPREL22; break;
572 case BFD_RELOC_IA64_TPREL64I: rtype = R_IA64_TPREL64I; break;
573 case BFD_RELOC_IA64_TPREL64MSB: rtype = R_IA64_TPREL64MSB; break;
574 case BFD_RELOC_IA64_TPREL64LSB: rtype = R_IA64_TPREL64LSB; break;
575 case BFD_RELOC_IA64_LTOFF_TPREL22: rtype = R_IA64_LTOFF_TPREL22; break;
576
577 case BFD_RELOC_IA64_DTPMOD64MSB: rtype = R_IA64_DTPMOD64MSB; break;
578 case BFD_RELOC_IA64_DTPMOD64LSB: rtype = R_IA64_DTPMOD64LSB; break;
579 case BFD_RELOC_IA64_LTOFF_DTPMOD22: rtype = R_IA64_LTOFF_DTPMOD22; break;
580
581 case BFD_RELOC_IA64_DTPREL14: rtype = R_IA64_DTPREL14; break;
582 case BFD_RELOC_IA64_DTPREL22: rtype = R_IA64_DTPREL22; break;
583 case BFD_RELOC_IA64_DTPREL64I: rtype = R_IA64_DTPREL64I; break;
584 case BFD_RELOC_IA64_DTPREL32MSB: rtype = R_IA64_DTPREL32MSB; break;
585 case BFD_RELOC_IA64_DTPREL32LSB: rtype = R_IA64_DTPREL32LSB; break;
586 case BFD_RELOC_IA64_DTPREL64MSB: rtype = R_IA64_DTPREL64MSB; break;
587 case BFD_RELOC_IA64_DTPREL64LSB: rtype = R_IA64_DTPREL64LSB; break;
588 case BFD_RELOC_IA64_LTOFF_DTPREL22: rtype = R_IA64_LTOFF_DTPREL22; break;
589
590 default: return 0;
591 }
592 return lookup_howto (rtype);
593 }
594
595 /* Given a ELF reloc, return the matching HOWTO structure. */
596
597 static void
598 elfNN_ia64_info_to_howto (abfd, bfd_reloc, elf_reloc)
599 bfd *abfd ATTRIBUTE_UNUSED;
600 arelent *bfd_reloc;
601 ElfNN_Internal_Rela *elf_reloc;
602 {
603 bfd_reloc->howto
604 = lookup_howto ((unsigned int) ELFNN_R_TYPE (elf_reloc->r_info));
605 }
606 \f
607 #define PLT_HEADER_SIZE (3 * 16)
608 #define PLT_MIN_ENTRY_SIZE (1 * 16)
609 #define PLT_FULL_ENTRY_SIZE (2 * 16)
610 #define PLT_RESERVED_WORDS 3
611
612 static const bfd_byte plt_header[PLT_HEADER_SIZE] =
613 {
614 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */
615 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */
616 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
617 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */
618 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */
619 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
620 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */
621 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */
622 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
623 };
624
625 static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] =
626 {
627 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */
628 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */
629 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */
630 };
631
632 static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
633 {
634 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
635 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */
636 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
637 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
638 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
639 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
640 };
641
642 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
643 #define AIX_DYNAMIC_INTERPRETER "/usr/lib/ia64l64/libc.so.1"
644 #define DYNAMIC_INTERPRETER(abfd) \
645 (elfNN_ia64_aix_vec (abfd->xvec) ? AIX_DYNAMIC_INTERPRETER : ELF_DYNAMIC_INTERPRETER)
646
647 /* Select out of range branch fixup type. Note that Itanium does
648 not support brl, and so it gets emulated by the kernel. */
649 #undef USE_BRL
650
651 static const bfd_byte oor_brl[16] =
652 {
653 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
654 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */
655 0x00, 0x00, 0x00, 0xc0
656 };
657
658 static const bfd_byte oor_ip[48] =
659 {
660 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
661 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */
662 0x01, 0x00, 0x00, 0x60,
663 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */
664 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */
665 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */
666 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */
667 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
668 0x60, 0x00, 0x80, 0x00 /* br b6;; */
669 };
670 \f
671 /* These functions do relaxation for IA-64 ELF.
672
673 This is primarily to support branches to targets out of range;
674 relaxation of R_IA64_LTOFF22X and R_IA64_LDXMOV not yet supported. */
675
676 static boolean
677 elfNN_ia64_relax_section (abfd, sec, link_info, again)
678 bfd *abfd;
679 asection *sec;
680 struct bfd_link_info *link_info;
681 boolean *again;
682 {
683 struct one_fixup
684 {
685 struct one_fixup *next;
686 asection *tsec;
687 bfd_vma toff;
688 bfd_vma trampoff;
689 };
690
691 Elf_Internal_Shdr *symtab_hdr;
692 Elf_Internal_Rela *internal_relocs;
693 Elf_Internal_Rela *irel, *irelend;
694 bfd_byte *contents;
695 Elf_Internal_Sym *isymbuf = NULL;
696 struct elfNN_ia64_link_hash_table *ia64_info;
697 struct one_fixup *fixups = NULL;
698 boolean changed_contents = false;
699 boolean changed_relocs = false;
700
701 /* Assume we're not going to change any sizes, and we'll only need
702 one pass. */
703 *again = false;
704
705 /* Nothing to do if there are no relocations. */
706 if ((sec->flags & SEC_RELOC) == 0
707 || sec->reloc_count == 0)
708 return true;
709
710 /* If this is the first time we have been called for this section,
711 initialize the cooked size. */
712 if (sec->_cooked_size == 0)
713 sec->_cooked_size = sec->_raw_size;
714
715 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
716
717 /* Load the relocations for this section. */
718 internal_relocs = (_bfd_elfNN_link_read_relocs
719 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
720 link_info->keep_memory));
721 if (internal_relocs == NULL)
722 return false;
723
724 ia64_info = elfNN_ia64_hash_table (link_info);
725 irelend = internal_relocs + sec->reloc_count;
726
727 for (irel = internal_relocs; irel < irelend; irel++)
728 if (ELFNN_R_TYPE (irel->r_info) == (int) R_IA64_PCREL21B)
729 break;
730
731 /* No branch-type relocations. */
732 if (irel == irelend)
733 {
734 if (elf_section_data (sec)->relocs != internal_relocs)
735 free (internal_relocs);
736 return true;
737 }
738
739 /* Get the section contents. */
740 if (elf_section_data (sec)->this_hdr.contents != NULL)
741 contents = elf_section_data (sec)->this_hdr.contents;
742 else
743 {
744 contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
745 if (contents == NULL)
746 goto error_return;
747
748 if (! bfd_get_section_contents (abfd, sec, contents,
749 (file_ptr) 0, sec->_raw_size))
750 goto error_return;
751 }
752
753 for (; irel < irelend; irel++)
754 {
755 bfd_vma symaddr, reladdr, trampoff, toff, roff;
756 asection *tsec;
757 struct one_fixup *f;
758 bfd_size_type amt;
759
760 if (ELFNN_R_TYPE (irel->r_info) != (int) R_IA64_PCREL21B)
761 continue;
762
763 /* Get the value of the symbol referred to by the reloc. */
764 if (ELFNN_R_SYM (irel->r_info) < symtab_hdr->sh_info)
765 {
766 /* A local symbol. */
767 Elf_Internal_Sym *isym;
768
769 /* Read this BFD's local symbols. */
770 if (isymbuf == NULL)
771 {
772 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
773 if (isymbuf == NULL)
774 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
775 symtab_hdr->sh_info, 0,
776 NULL, NULL, NULL);
777 if (isymbuf == 0)
778 goto error_return;
779 }
780
781 isym = isymbuf + ELF64_R_SYM (irel->r_info);
782 if (isym->st_shndx == SHN_UNDEF)
783 continue; /* We can't do anthing with undefined symbols. */
784 else if (isym->st_shndx == SHN_ABS)
785 tsec = bfd_abs_section_ptr;
786 else if (isym->st_shndx == SHN_COMMON)
787 tsec = bfd_com_section_ptr;
788 else if (isym->st_shndx == SHN_IA_64_ANSI_COMMON)
789 tsec = bfd_com_section_ptr;
790 else
791 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
792
793 toff = isym->st_value;
794 }
795 else
796 {
797 unsigned long indx;
798 struct elf_link_hash_entry *h;
799 struct elfNN_ia64_dyn_sym_info *dyn_i;
800
801 indx = ELFNN_R_SYM (irel->r_info) - symtab_hdr->sh_info;
802 h = elf_sym_hashes (abfd)[indx];
803 BFD_ASSERT (h != NULL);
804
805 while (h->root.type == bfd_link_hash_indirect
806 || h->root.type == bfd_link_hash_warning)
807 h = (struct elf_link_hash_entry *) h->root.u.i.link;
808
809 dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, false);
810
811 /* For branches to dynamic symbols, we're interested instead
812 in a branch to the PLT entry. */
813 if (dyn_i && dyn_i->want_plt2)
814 {
815 tsec = ia64_info->plt_sec;
816 toff = dyn_i->plt2_offset;
817 }
818 else
819 {
820 /* We can't do anthing with undefined symbols. */
821 if (h->root.type == bfd_link_hash_undefined
822 || h->root.type == bfd_link_hash_undefweak)
823 continue;
824
825 tsec = h->root.u.def.section;
826 toff = h->root.u.def.value;
827 }
828 }
829
830 symaddr = (tsec->output_section->vma
831 + tsec->output_offset
832 + toff
833 + irel->r_addend);
834
835 roff = irel->r_offset;
836 reladdr = (sec->output_section->vma
837 + sec->output_offset
838 + roff) & (bfd_vma) -4;
839
840 /* If the branch is in range, no need to do anything. */
841 if ((bfd_signed_vma) (symaddr - reladdr) >= -0x1000000
842 && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
843 continue;
844
845 /* If the branch and target are in the same section, you've
846 got one honking big section and we can't help you. You'll
847 get an error message later. */
848 if (tsec == sec)
849 continue;
850
851 /* Look for an existing fixup to this address. */
852 for (f = fixups; f ; f = f->next)
853 if (f->tsec == tsec && f->toff == toff)
854 break;
855
856 if (f == NULL)
857 {
858 /* Two alternatives: If it's a branch to a PLT entry, we can
859 make a copy of the FULL_PLT entry. Otherwise, we'll have
860 to use a `brl' insn to get where we're going. */
861
862 size_t size;
863
864 if (tsec == ia64_info->plt_sec)
865 size = sizeof (plt_full_entry);
866 else
867 {
868 #ifdef USE_BRL
869 size = sizeof (oor_brl);
870 #else
871 size = sizeof (oor_ip);
872 #endif
873 }
874
875 /* Resize the current section to make room for the new branch. */
876 trampoff = (sec->_cooked_size + 15) & (bfd_vma) -16;
877 amt = trampoff + size;
878 contents = (bfd_byte *) bfd_realloc (contents, amt);
879 if (contents == NULL)
880 goto error_return;
881 sec->_cooked_size = amt;
882
883 if (tsec == ia64_info->plt_sec)
884 {
885 memcpy (contents + trampoff, plt_full_entry, size);
886
887 /* Hijack the old relocation for use as the PLTOFF reloc. */
888 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
889 R_IA64_PLTOFF22);
890 irel->r_offset = trampoff;
891 }
892 else
893 {
894 #ifdef USE_BRL
895 memcpy (contents + trampoff, oor_brl, size);
896 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
897 R_IA64_PCREL60B);
898 irel->r_offset = trampoff + 2;
899 #else
900 memcpy (contents + trampoff, oor_ip, size);
901 irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
902 R_IA64_PCREL64I);
903 irel->r_addend -= 16;
904 irel->r_offset = trampoff + 2;
905 #endif
906 }
907
908 /* Record the fixup so we don't do it again this section. */
909 f = (struct one_fixup *) bfd_malloc ((bfd_size_type) sizeof (*f));
910 f->next = fixups;
911 f->tsec = tsec;
912 f->toff = toff;
913 f->trampoff = trampoff;
914 fixups = f;
915 }
916 else
917 {
918 /* Nop out the reloc, since we're finalizing things here. */
919 irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
920 }
921
922 /* Fix up the existing branch to hit the trampoline. Hope like
923 hell this doesn't overflow too. */
924 if (elfNN_ia64_install_value (abfd, contents + roff,
925 f->trampoff - (roff & (bfd_vma) -4),
926 R_IA64_PCREL21B) != bfd_reloc_ok)
927 goto error_return;
928
929 changed_contents = true;
930 changed_relocs = true;
931 }
932
933 /* Clean up and go home. */
934 while (fixups)
935 {
936 struct one_fixup *f = fixups;
937 fixups = fixups->next;
938 free (f);
939 }
940
941 if (isymbuf != NULL
942 && symtab_hdr->contents != (unsigned char *) isymbuf)
943 {
944 if (! link_info->keep_memory)
945 free (isymbuf);
946 else
947 {
948 /* Cache the symbols for elf_link_input_bfd. */
949 symtab_hdr->contents = (unsigned char *) isymbuf;
950 }
951 }
952
953 if (contents != NULL
954 && elf_section_data (sec)->this_hdr.contents != contents)
955 {
956 if (!changed_contents && !link_info->keep_memory)
957 free (contents);
958 else
959 {
960 /* Cache the section contents for elf_link_input_bfd. */
961 elf_section_data (sec)->this_hdr.contents = contents;
962 }
963 }
964
965 if (elf_section_data (sec)->relocs != internal_relocs)
966 {
967 if (!changed_relocs)
968 free (internal_relocs);
969 else
970 elf_section_data (sec)->relocs = internal_relocs;
971 }
972
973 *again = changed_contents || changed_relocs;
974 return true;
975
976 error_return:
977 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
978 free (isymbuf);
979 if (contents != NULL
980 && elf_section_data (sec)->this_hdr.contents != contents)
981 free (contents);
982 if (internal_relocs != NULL
983 && elf_section_data (sec)->relocs != internal_relocs)
984 free (internal_relocs);
985 return false;
986 }
987 \f
988 /* Return true if NAME is an unwind table section name. */
989
990 static inline boolean
991 is_unwind_section_name (abfd, name)
992 bfd *abfd;
993 const char *name;
994 {
995 size_t len1, len2, len3;
996
997 if (elfNN_ia64_hpux_vec (abfd->xvec)
998 && !strcmp (name, ELF_STRING_ia64_unwind_hdr))
999 return false;
1000
1001 len1 = sizeof (ELF_STRING_ia64_unwind) - 1;
1002 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
1003 len3 = sizeof (ELF_STRING_ia64_unwind_once) - 1;
1004 return ((strncmp (name, ELF_STRING_ia64_unwind, len1) == 0
1005 && strncmp (name, ELF_STRING_ia64_unwind_info, len2) != 0)
1006 || strncmp (name, ELF_STRING_ia64_unwind_once, len3) == 0);
1007 }
1008
1009 /* Handle an IA-64 specific section when reading an object file. This
1010 is called when elfcode.h finds a section with an unknown type. */
1011
1012 static boolean
1013 elfNN_ia64_section_from_shdr (abfd, hdr, name)
1014 bfd *abfd;
1015 ElfNN_Internal_Shdr *hdr;
1016 const char *name;
1017 {
1018 asection *newsect;
1019
1020 /* There ought to be a place to keep ELF backend specific flags, but
1021 at the moment there isn't one. We just keep track of the
1022 sections by their name, instead. Fortunately, the ABI gives
1023 suggested names for all the MIPS specific sections, so we will
1024 probably get away with this. */
1025 switch (hdr->sh_type)
1026 {
1027 case SHT_IA_64_UNWIND:
1028 case SHT_IA_64_HP_OPT_ANOT:
1029 break;
1030
1031 case SHT_IA_64_EXT:
1032 if (strcmp (name, ELF_STRING_ia64_archext) != 0)
1033 return false;
1034 break;
1035
1036 default:
1037 return false;
1038 }
1039
1040 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1041 return false;
1042 newsect = hdr->bfd_section;
1043
1044 return true;
1045 }
1046
1047 /* Convert IA-64 specific section flags to bfd internal section flags. */
1048
1049 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
1050 flag. */
1051
1052 static boolean
1053 elfNN_ia64_section_flags (flags, hdr)
1054 flagword *flags;
1055 ElfNN_Internal_Shdr *hdr;
1056 {
1057 if (hdr->sh_flags & SHF_IA_64_SHORT)
1058 *flags |= SEC_SMALL_DATA;
1059
1060 return true;
1061 }
1062
1063 /* Set the correct type for an IA-64 ELF section. We do this by the
1064 section name, which is a hack, but ought to work. */
1065
1066 static boolean
1067 elfNN_ia64_fake_sections (abfd, hdr, sec)
1068 bfd *abfd ATTRIBUTE_UNUSED;
1069 ElfNN_Internal_Shdr *hdr;
1070 asection *sec;
1071 {
1072 register const char *name;
1073
1074 name = bfd_get_section_name (abfd, sec);
1075
1076 if (is_unwind_section_name (abfd, name))
1077 {
1078 /* We don't have the sections numbered at this point, so sh_info
1079 is set later, in elfNN_ia64_final_write_processing. */
1080 hdr->sh_type = SHT_IA_64_UNWIND;
1081 hdr->sh_flags |= SHF_LINK_ORDER;
1082 }
1083 else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
1084 hdr->sh_type = SHT_IA_64_EXT;
1085 else if (strcmp (name, ".HP.opt_annot") == 0)
1086 hdr->sh_type = SHT_IA_64_HP_OPT_ANOT;
1087 else if (strcmp (name, ".reloc") == 0)
1088 /* This is an ugly, but unfortunately necessary hack that is
1089 needed when producing EFI binaries on IA-64. It tells
1090 elf.c:elf_fake_sections() not to consider ".reloc" as a section
1091 containing ELF relocation info. We need this hack in order to
1092 be able to generate ELF binaries that can be translated into
1093 EFI applications (which are essentially COFF objects). Those
1094 files contain a COFF ".reloc" section inside an ELFNN object,
1095 which would normally cause BFD to segfault because it would
1096 attempt to interpret this section as containing relocation
1097 entries for section "oc". With this hack enabled, ".reloc"
1098 will be treated as a normal data section, which will avoid the
1099 segfault. However, you won't be able to create an ELFNN binary
1100 with a section named "oc" that needs relocations, but that's
1101 the kind of ugly side-effects you get when detecting section
1102 types based on their names... In practice, this limitation is
1103 unlikely to bite. */
1104 hdr->sh_type = SHT_PROGBITS;
1105
1106 if (sec->flags & SEC_SMALL_DATA)
1107 hdr->sh_flags |= SHF_IA_64_SHORT;
1108
1109 return true;
1110 }
1111
1112 /* The final processing done just before writing out an IA-64 ELF
1113 object file. */
1114
1115 static void
1116 elfNN_ia64_final_write_processing (abfd, linker)
1117 bfd *abfd;
1118 boolean linker ATTRIBUTE_UNUSED;
1119 {
1120 Elf_Internal_Shdr *hdr;
1121 const char *sname;
1122 asection *text_sect, *s;
1123 size_t len;
1124
1125 for (s = abfd->sections; s; s = s->next)
1126 {
1127 hdr = &elf_section_data (s)->this_hdr;
1128 switch (hdr->sh_type)
1129 {
1130 case SHT_IA_64_UNWIND:
1131 /* See comments in gas/config/tc-ia64.c:dot_endp on why we
1132 have to do this. */
1133 sname = bfd_get_section_name (abfd, s);
1134 len = sizeof (ELF_STRING_ia64_unwind) - 1;
1135 if (sname && strncmp (sname, ELF_STRING_ia64_unwind, len) == 0)
1136 {
1137 sname += len;
1138
1139 if (sname[0] == '\0')
1140 /* .IA_64.unwind -> .text */
1141 text_sect = bfd_get_section_by_name (abfd, ".text");
1142 else
1143 /* .IA_64.unwindFOO -> FOO */
1144 text_sect = bfd_get_section_by_name (abfd, sname);
1145 }
1146 else if (sname
1147 && (len = sizeof (ELF_STRING_ia64_unwind_once) - 1,
1148 strncmp (sname, ELF_STRING_ia64_unwind_once, len)) == 0)
1149 {
1150 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.t.FOO */
1151 size_t len2 = sizeof (".gnu.linkonce.t.") - 1;
1152 char *once_name = bfd_malloc (len2 + strlen (sname + len) + 1);
1153
1154 if (once_name != NULL)
1155 {
1156 memcpy (once_name, ".gnu.linkonce.t.", len2);
1157 strcpy (once_name + len2, sname + len);
1158 text_sect = bfd_get_section_by_name (abfd, once_name);
1159 free (once_name);
1160 }
1161 else
1162 /* Should only happen if we run out of memory, in
1163 which case we're probably toast anyway. Try to
1164 cope by finding the section the slow way. */
1165 for (text_sect = abfd->sections;
1166 text_sect != NULL;
1167 text_sect = text_sect->next)
1168 {
1169 if (strncmp (bfd_section_name (abfd, text_sect),
1170 ".gnu.linkonce.t.", len2) == 0
1171 && strcmp (bfd_section_name (abfd, text_sect) + len2,
1172 sname + len) == 0)
1173 break;
1174 }
1175 }
1176 else
1177 /* last resort: fall back on .text */
1178 text_sect = bfd_get_section_by_name (abfd, ".text");
1179
1180 if (text_sect)
1181 {
1182 /* The IA-64 processor-specific ABI requires setting
1183 sh_link to the unwind section, whereas HP-UX requires
1184 sh_info to do so. For maximum compatibility, we'll
1185 set both for now... */
1186 hdr->sh_link = elf_section_data (text_sect)->this_idx;
1187 hdr->sh_info = elf_section_data (text_sect)->this_idx;
1188 }
1189 break;
1190 }
1191 }
1192 }
1193
1194 /* Hook called by the linker routine which adds symbols from an object
1195 file. We use it to put .comm items in .sbss, and not .bss. */
1196
1197 static boolean
1198 elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1199 bfd *abfd;
1200 struct bfd_link_info *info;
1201 const Elf_Internal_Sym *sym;
1202 const char **namep ATTRIBUTE_UNUSED;
1203 flagword *flagsp ATTRIBUTE_UNUSED;
1204 asection **secp;
1205 bfd_vma *valp;
1206 {
1207 if (sym->st_shndx == SHN_COMMON
1208 && !info->relocateable
1209 && sym->st_size <= elf_gp_size (abfd))
1210 {
1211 /* Common symbols less than or equal to -G nn bytes are
1212 automatically put into .sbss. */
1213
1214 asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
1215
1216 if (scomm == NULL)
1217 {
1218 scomm = bfd_make_section (abfd, ".scommon");
1219 if (scomm == NULL
1220 || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC
1221 | SEC_IS_COMMON
1222 | SEC_LINKER_CREATED)))
1223 return false;
1224 }
1225
1226 *secp = scomm;
1227 *valp = sym->st_size;
1228 }
1229
1230 return true;
1231 }
1232
1233 static boolean
1234 elfNN_ia64_aix_vec (const bfd_target *vec)
1235 {
1236 extern const bfd_target bfd_elfNN_ia64_aix_little_vec;
1237 extern const bfd_target bfd_elfNN_ia64_aix_big_vec;
1238
1239 return (/**/vec == & bfd_elfNN_ia64_aix_little_vec
1240 || vec == & bfd_elfNN_ia64_aix_big_vec);
1241 }
1242
1243 /* Hook called by the linker routine which adds symbols from an object
1244 file. We use it to handle OS-specific symbols. */
1245
1246 static boolean
1247 elfNN_ia64_aix_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1248 bfd *abfd;
1249 struct bfd_link_info *info;
1250 const Elf_Internal_Sym *sym;
1251 const char **namep;
1252 flagword *flagsp;
1253 asection **secp;
1254 bfd_vma *valp;
1255 {
1256 if (strcmp (*namep, "__GLOB_DATA_PTR") == 0)
1257 {
1258 /* Define __GLOB_DATA_PTR when it is encountered. This is expected to
1259 be a linker-defined symbol by the Aix C runtime startup code. IBM sez
1260 no one else should use it b/c it is undocumented. */
1261 struct elf_link_hash_entry *h;
1262
1263 h = elf_link_hash_lookup (elf_hash_table (info), *namep,
1264 false, false, false);
1265 if (h == NULL)
1266 {
1267 struct elf_backend_data *bed;
1268 struct elfNN_ia64_link_hash_table *ia64_info;
1269
1270 bed = get_elf_backend_data (abfd);
1271 ia64_info = elfNN_ia64_hash_table (info);
1272
1273 if (!(_bfd_generic_link_add_one_symbol
1274 (info, abfd, *namep, BSF_GLOBAL,
1275 bfd_get_section_by_name (abfd, ".bss"),
1276 bed->got_symbol_offset, (const char *) NULL, false,
1277 bed->collect, (struct bfd_link_hash_entry **) &h)))
1278 return false;
1279
1280 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
1281 h->type = STT_OBJECT;
1282
1283 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
1284 return false;
1285 }
1286
1287 return true;
1288 }
1289 else if (sym->st_shndx == SHN_LOOS)
1290 {
1291 unsigned int i;
1292
1293 /* SHN_AIX_SYSCALL: Treat this as any other symbol. The special symbol
1294 is only relevant when compiling code for extended system calls.
1295 Replace the "special" section with .text, if possible.
1296 Note that these symbols are always assumed to be in .text. */
1297 for (i = 1; i < elf_numsections (abfd); i++)
1298 {
1299 asection * sec = bfd_section_from_elf_index (abfd, i);
1300
1301 if (sec && strcmp (sec->name, ".text") == 0)
1302 {
1303 *secp = sec;
1304 break;
1305 }
1306 }
1307
1308 if (*secp == NULL)
1309 *secp = bfd_abs_section_ptr;
1310
1311 *valp = sym->st_size;
1312
1313 return true;
1314 }
1315 else
1316 {
1317 return elfNN_ia64_add_symbol_hook (abfd, info, sym,
1318 namep, flagsp, secp, valp);
1319 }
1320 }
1321
1322 boolean
1323 elfNN_ia64_aix_link_add_symbols (abfd, info)
1324 bfd *abfd;
1325 struct bfd_link_info *info;
1326 {
1327 /* Make sure dynamic sections are always created. */
1328 if (! elf_hash_table (info)->dynamic_sections_created
1329 && abfd->xvec == info->hash->creator)
1330 {
1331 if (! bfd_elfNN_link_create_dynamic_sections (abfd, info))
1332 return false;
1333 }
1334
1335 /* Now do the standard call. */
1336 return bfd_elfNN_bfd_link_add_symbols (abfd, info);
1337 }
1338
1339 /* Return the number of additional phdrs we will need. */
1340
1341 static int
1342 elfNN_ia64_additional_program_headers (abfd)
1343 bfd *abfd;
1344 {
1345 asection *s;
1346 int ret = 0;
1347
1348 /* See if we need a PT_IA_64_ARCHEXT segment. */
1349 s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext);
1350 if (s && (s->flags & SEC_LOAD))
1351 ++ret;
1352
1353 /* Count how many PT_IA_64_UNWIND segments we need. */
1354 for (s = abfd->sections; s; s = s->next)
1355 if (is_unwind_section_name (abfd, s->name) && (s->flags & SEC_LOAD))
1356 ++ret;
1357
1358 return ret;
1359 }
1360
1361 static boolean
1362 elfNN_ia64_modify_segment_map (abfd)
1363 bfd *abfd;
1364 {
1365 struct elf_segment_map *m, **pm;
1366 Elf_Internal_Shdr *hdr;
1367 asection *s;
1368
1369 /* If we need a PT_IA_64_ARCHEXT segment, it must come before
1370 all PT_LOAD segments. */
1371 s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext);
1372 if (s && (s->flags & SEC_LOAD))
1373 {
1374 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
1375 if (m->p_type == PT_IA_64_ARCHEXT)
1376 break;
1377 if (m == NULL)
1378 {
1379 m = ((struct elf_segment_map *)
1380 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
1381 if (m == NULL)
1382 return false;
1383
1384 m->p_type = PT_IA_64_ARCHEXT;
1385 m->count = 1;
1386 m->sections[0] = s;
1387
1388 /* We want to put it after the PHDR and INTERP segments. */
1389 pm = &elf_tdata (abfd)->segment_map;
1390 while (*pm != NULL
1391 && ((*pm)->p_type == PT_PHDR
1392 || (*pm)->p_type == PT_INTERP))
1393 pm = &(*pm)->next;
1394
1395 m->next = *pm;
1396 *pm = m;
1397 }
1398 }
1399
1400 /* Install PT_IA_64_UNWIND segments, if needed. */
1401 for (s = abfd->sections; s; s = s->next)
1402 {
1403 hdr = &elf_section_data (s)->this_hdr;
1404 if (hdr->sh_type != SHT_IA_64_UNWIND)
1405 continue;
1406
1407 if (s && (s->flags & SEC_LOAD))
1408 {
1409 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
1410 if (m->p_type == PT_IA_64_UNWIND)
1411 {
1412 int i;
1413
1414 /* Look through all sections in the unwind segment
1415 for a match since there may be multiple sections
1416 to a segment. */
1417 for (i = m->count - 1; i >= 0; --i)
1418 if (m->sections[i] == s)
1419 break;
1420
1421 if (i >= 0)
1422 break;
1423 }
1424
1425 if (m == NULL)
1426 {
1427 m = ((struct elf_segment_map *)
1428 bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
1429 if (m == NULL)
1430 return false;
1431
1432 m->p_type = PT_IA_64_UNWIND;
1433 m->count = 1;
1434 m->sections[0] = s;
1435 m->next = NULL;
1436
1437 /* We want to put it last. */
1438 pm = &elf_tdata (abfd)->segment_map;
1439 while (*pm != NULL)
1440 pm = &(*pm)->next;
1441 *pm = m;
1442 }
1443 }
1444 }
1445
1446 /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of
1447 the input sections for each output section in the segment and testing
1448 for SHF_IA_64_NORECOV on each. */
1449 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
1450 if (m->p_type == PT_LOAD)
1451 {
1452 int i;
1453 for (i = m->count - 1; i >= 0; --i)
1454 {
1455 struct bfd_link_order *order = m->sections[i]->link_order_head;
1456 while (order)
1457 {
1458 if (order->type == bfd_indirect_link_order)
1459 {
1460 asection *is = order->u.indirect.section;
1461 bfd_vma flags = elf_section_data(is)->this_hdr.sh_flags;
1462 if (flags & SHF_IA_64_NORECOV)
1463 {
1464 m->p_flags |= PF_IA_64_NORECOV;
1465 goto found;
1466 }
1467 }
1468 order = order->next;
1469 }
1470 }
1471 found:;
1472 }
1473
1474 return true;
1475 }
1476
1477 /* According to the Tahoe assembler spec, all labels starting with a
1478 '.' are local. */
1479
1480 static boolean
1481 elfNN_ia64_is_local_label_name (abfd, name)
1482 bfd *abfd ATTRIBUTE_UNUSED;
1483 const char *name;
1484 {
1485 return name[0] == '.';
1486 }
1487
1488 /* Should we do dynamic things to this symbol? */
1489
1490 static boolean
1491 elfNN_ia64_dynamic_symbol_p (h, info)
1492 struct elf_link_hash_entry *h;
1493 struct bfd_link_info *info;
1494 {
1495 if (h == NULL)
1496 return false;
1497
1498 while (h->root.type == bfd_link_hash_indirect
1499 || h->root.type == bfd_link_hash_warning)
1500 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1501
1502 if (h->dynindx == -1)
1503 return false;
1504 switch (ELF_ST_VISIBILITY (h->other))
1505 {
1506 case STV_INTERNAL:
1507 case STV_HIDDEN:
1508 return false;
1509 default:
1510 break;
1511 }
1512
1513 if (h->root.type == bfd_link_hash_undefweak
1514 || h->root.type == bfd_link_hash_defweak)
1515 return true;
1516
1517 if ((info->shared && (!info->symbolic || info->allow_shlib_undefined))
1518 || ((h->elf_link_hash_flags
1519 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))
1520 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
1521 return true;
1522
1523 return false;
1524 }
1525 \f
1526 static boolean
1527 elfNN_ia64_local_hash_table_init (ht, abfd, new)
1528 struct elfNN_ia64_local_hash_table *ht;
1529 bfd *abfd ATTRIBUTE_UNUSED;
1530 new_hash_entry_func new;
1531 {
1532 memset (ht, 0, sizeof (*ht));
1533 return bfd_hash_table_init (&ht->root, new);
1534 }
1535
1536 static struct bfd_hash_entry*
1537 elfNN_ia64_new_loc_hash_entry (entry, table, string)
1538 struct bfd_hash_entry *entry;
1539 struct bfd_hash_table *table;
1540 const char *string;
1541 {
1542 struct elfNN_ia64_local_hash_entry *ret;
1543 ret = (struct elfNN_ia64_local_hash_entry *) entry;
1544
1545 /* Allocate the structure if it has not already been allocated by a
1546 subclass. */
1547 if (!ret)
1548 ret = bfd_hash_allocate (table, sizeof (*ret));
1549
1550 if (!ret)
1551 return 0;
1552
1553 /* Initialize our local data. All zeros, and definitely easier
1554 than setting a handful of bit fields. */
1555 memset (ret, 0, sizeof (*ret));
1556
1557 /* Call the allocation method of the superclass. */
1558 ret = ((struct elfNN_ia64_local_hash_entry *)
1559 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
1560
1561 return (struct bfd_hash_entry *) ret;
1562 }
1563
1564 static struct bfd_hash_entry*
1565 elfNN_ia64_new_elf_hash_entry (entry, table, string)
1566 struct bfd_hash_entry *entry;
1567 struct bfd_hash_table *table;
1568 const char *string;
1569 {
1570 struct elfNN_ia64_link_hash_entry *ret;
1571 ret = (struct elfNN_ia64_link_hash_entry *) entry;
1572
1573 /* Allocate the structure if it has not already been allocated by a
1574 subclass. */
1575 if (!ret)
1576 ret = bfd_hash_allocate (table, sizeof (*ret));
1577
1578 if (!ret)
1579 return 0;
1580
1581 /* Initialize our local data. All zeros, and definitely easier
1582 than setting a handful of bit fields. */
1583 memset (ret, 0, sizeof (*ret));
1584
1585 /* Call the allocation method of the superclass. */
1586 ret = ((struct elfNN_ia64_link_hash_entry *)
1587 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1588 table, string));
1589
1590 return (struct bfd_hash_entry *) ret;
1591 }
1592
1593 static void
1594 elfNN_ia64_hash_copy_indirect (xdir, xind)
1595 struct elf_link_hash_entry *xdir, *xind;
1596 {
1597 struct elfNN_ia64_link_hash_entry *dir, *ind;
1598
1599 dir = (struct elfNN_ia64_link_hash_entry *) xdir;
1600 ind = (struct elfNN_ia64_link_hash_entry *) xind;
1601
1602 /* Copy down any references that we may have already seen to the
1603 symbol which just became indirect. */
1604
1605 dir->root.elf_link_hash_flags |=
1606 (ind->root.elf_link_hash_flags
1607 & (ELF_LINK_HASH_REF_DYNAMIC
1608 | ELF_LINK_HASH_REF_REGULAR
1609 | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
1610
1611 if (ind->root.root.type != bfd_link_hash_indirect)
1612 return;
1613
1614 /* Copy over the got and plt data. This would have been done
1615 by check_relocs. */
1616
1617 if (dir->info == NULL)
1618 {
1619 struct elfNN_ia64_dyn_sym_info *dyn_i;
1620
1621 dir->info = dyn_i = ind->info;
1622 ind->info = NULL;
1623
1624 /* Fix up the dyn_sym_info pointers to the global symbol. */
1625 for (; dyn_i; dyn_i = dyn_i->next)
1626 dyn_i->h = &dir->root;
1627 }
1628 BFD_ASSERT (ind->info == NULL);
1629
1630 /* Copy over the dynindx. */
1631
1632 if (dir->root.dynindx == -1)
1633 {
1634 dir->root.dynindx = ind->root.dynindx;
1635 dir->root.dynstr_index = ind->root.dynstr_index;
1636 ind->root.dynindx = -1;
1637 ind->root.dynstr_index = 0;
1638 }
1639 BFD_ASSERT (ind->root.dynindx == -1);
1640 }
1641
1642 static void
1643 elfNN_ia64_hash_hide_symbol (info, xh, force_local)
1644 struct bfd_link_info *info;
1645 struct elf_link_hash_entry *xh;
1646 boolean force_local;
1647 {
1648 struct elfNN_ia64_link_hash_entry *h;
1649 struct elfNN_ia64_dyn_sym_info *dyn_i;
1650
1651 h = (struct elfNN_ia64_link_hash_entry *)xh;
1652
1653 _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
1654
1655 for (dyn_i = h->info; dyn_i; dyn_i = dyn_i->next)
1656 dyn_i->want_plt2 = 0;
1657 }
1658
1659 /* Create the derived linker hash table. The IA-64 ELF port uses this
1660 derived hash table to keep information specific to the IA-64 ElF
1661 linker (without using static variables). */
1662
1663 static struct bfd_link_hash_table*
1664 elfNN_ia64_hash_table_create (abfd)
1665 bfd *abfd;
1666 {
1667 struct elfNN_ia64_link_hash_table *ret;
1668
1669 ret = bfd_zalloc (abfd, (bfd_size_type) sizeof (*ret));
1670 if (!ret)
1671 return 0;
1672 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
1673 elfNN_ia64_new_elf_hash_entry))
1674 {
1675 bfd_release (abfd, ret);
1676 return 0;
1677 }
1678
1679 if (!elfNN_ia64_local_hash_table_init (&ret->loc_hash_table, abfd,
1680 elfNN_ia64_new_loc_hash_entry))
1681 return 0;
1682 return &ret->root.root;
1683 }
1684
1685 /* Look up an entry in a Alpha ELF linker hash table. */
1686
1687 static INLINE struct elfNN_ia64_local_hash_entry *
1688 elfNN_ia64_local_hash_lookup(table, string, create, copy)
1689 struct elfNN_ia64_local_hash_table *table;
1690 const char *string;
1691 boolean create, copy;
1692 {
1693 return ((struct elfNN_ia64_local_hash_entry *)
1694 bfd_hash_lookup (&table->root, string, create, copy));
1695 }
1696
1697 /* Traverse both local and global hash tables. */
1698
1699 struct elfNN_ia64_dyn_sym_traverse_data
1700 {
1701 boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
1702 PTR data;
1703 };
1704
1705 static boolean
1706 elfNN_ia64_global_dyn_sym_thunk (xentry, xdata)
1707 struct bfd_hash_entry *xentry;
1708 PTR xdata;
1709 {
1710 struct elfNN_ia64_link_hash_entry *entry
1711 = (struct elfNN_ia64_link_hash_entry *) xentry;
1712 struct elfNN_ia64_dyn_sym_traverse_data *data
1713 = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
1714 struct elfNN_ia64_dyn_sym_info *dyn_i;
1715
1716 if (entry->root.root.type == bfd_link_hash_warning)
1717 entry = (struct elfNN_ia64_link_hash_entry *) entry->root.root.u.i.link;
1718
1719 for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next)
1720 if (! (*data->func) (dyn_i, data->data))
1721 return false;
1722 return true;
1723 }
1724
1725 static boolean
1726 elfNN_ia64_local_dyn_sym_thunk (xentry, xdata)
1727 struct bfd_hash_entry *xentry;
1728 PTR xdata;
1729 {
1730 struct elfNN_ia64_local_hash_entry *entry
1731 = (struct elfNN_ia64_local_hash_entry *) xentry;
1732 struct elfNN_ia64_dyn_sym_traverse_data *data
1733 = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
1734 struct elfNN_ia64_dyn_sym_info *dyn_i;
1735
1736 for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next)
1737 if (! (*data->func) (dyn_i, data->data))
1738 return false;
1739 return true;
1740 }
1741
1742 static void
1743 elfNN_ia64_dyn_sym_traverse (ia64_info, func, data)
1744 struct elfNN_ia64_link_hash_table *ia64_info;
1745 boolean (*func) PARAMS ((struct elfNN_ia64_dyn_sym_info *, PTR));
1746 PTR data;
1747 {
1748 struct elfNN_ia64_dyn_sym_traverse_data xdata;
1749
1750 xdata.func = func;
1751 xdata.data = data;
1752
1753 elf_link_hash_traverse (&ia64_info->root,
1754 elfNN_ia64_global_dyn_sym_thunk, &xdata);
1755 bfd_hash_traverse (&ia64_info->loc_hash_table.root,
1756 elfNN_ia64_local_dyn_sym_thunk, &xdata);
1757 }
1758 \f
1759 static boolean
1760 elfNN_ia64_create_dynamic_sections (abfd, info)
1761 bfd *abfd;
1762 struct bfd_link_info *info;
1763 {
1764 struct elfNN_ia64_link_hash_table *ia64_info;
1765 asection *s;
1766
1767 if (! _bfd_elf_create_dynamic_sections (abfd, info))
1768 return false;
1769
1770 ia64_info = elfNN_ia64_hash_table (info);
1771
1772 ia64_info->plt_sec = bfd_get_section_by_name (abfd, ".plt");
1773 ia64_info->got_sec = bfd_get_section_by_name (abfd, ".got");
1774
1775 {
1776 flagword flags = bfd_get_section_flags (abfd, ia64_info->got_sec);
1777 bfd_set_section_flags (abfd, ia64_info->got_sec, SEC_SMALL_DATA | flags);
1778 }
1779
1780 if (!get_pltoff (abfd, info, ia64_info))
1781 return false;
1782
1783 s = bfd_make_section(abfd, ".rela.IA_64.pltoff");
1784 if (s == NULL
1785 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1786 | SEC_HAS_CONTENTS
1787 | SEC_IN_MEMORY
1788 | SEC_LINKER_CREATED
1789 | SEC_READONLY))
1790 || !bfd_set_section_alignment (abfd, s, 3))
1791 return false;
1792 ia64_info->rel_pltoff_sec = s;
1793
1794 s = bfd_make_section(abfd, ".rela.got");
1795 if (s == NULL
1796 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1797 | SEC_HAS_CONTENTS
1798 | SEC_IN_MEMORY
1799 | SEC_LINKER_CREATED
1800 | SEC_READONLY))
1801 || !bfd_set_section_alignment (abfd, s, 3))
1802 return false;
1803 ia64_info->rel_got_sec = s;
1804
1805 return true;
1806 }
1807
1808 /* Find and/or create a hash entry for local symbol. */
1809 static struct elfNN_ia64_local_hash_entry *
1810 get_local_sym_hash (ia64_info, abfd, rel, create)
1811 struct elfNN_ia64_link_hash_table *ia64_info;
1812 bfd *abfd;
1813 const Elf_Internal_Rela *rel;
1814 boolean create;
1815 {
1816 char *addr_name;
1817 size_t len;
1818 struct elfNN_ia64_local_hash_entry *ret;
1819
1820 /* Construct a string for use in the elfNN_ia64_local_hash_table.
1821 name describes what was once anonymous memory. */
1822
1823 len = sizeof (void*)*2 + 1 + sizeof (bfd_vma)*4 + 1 + 1;
1824 len += 10; /* %p slop */
1825
1826 addr_name = bfd_malloc (len);
1827 if (addr_name == NULL)
1828 return 0;
1829 sprintf (addr_name, "%p:%lx",
1830 (void *) abfd, (unsigned long) ELFNN_R_SYM (rel->r_info));
1831
1832 /* Collect the canonical entry data for this address. */
1833 ret = elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table,
1834 addr_name, create, create);
1835 free (addr_name);
1836 return ret;
1837 }
1838
1839 /* Find and/or create a descriptor for dynamic symbol info. This will
1840 vary based on global or local symbol, and the addend to the reloc. */
1841
1842 static struct elfNN_ia64_dyn_sym_info *
1843 get_dyn_sym_info (ia64_info, h, abfd, rel, create)
1844 struct elfNN_ia64_link_hash_table *ia64_info;
1845 struct elf_link_hash_entry *h;
1846 bfd *abfd;
1847 const Elf_Internal_Rela *rel;
1848 boolean create;
1849 {
1850 struct elfNN_ia64_dyn_sym_info **pp;
1851 struct elfNN_ia64_dyn_sym_info *dyn_i;
1852 bfd_vma addend = rel ? rel->r_addend : 0;
1853
1854 if (h)
1855 pp = &((struct elfNN_ia64_link_hash_entry *)h)->info;
1856 else
1857 {
1858 struct elfNN_ia64_local_hash_entry *loc_h;
1859
1860 loc_h = get_local_sym_hash (ia64_info, abfd, rel, create);
1861 BFD_ASSERT (loc_h);
1862
1863 pp = &loc_h->info;
1864 }
1865
1866 for (dyn_i = *pp; dyn_i && dyn_i->addend != addend; dyn_i = *pp)
1867 pp = &dyn_i->next;
1868
1869 if (dyn_i == NULL && create)
1870 {
1871 dyn_i = ((struct elfNN_ia64_dyn_sym_info *)
1872 bfd_zalloc (abfd, (bfd_size_type) sizeof *dyn_i));
1873 *pp = dyn_i;
1874 dyn_i->addend = addend;
1875 }
1876
1877 return dyn_i;
1878 }
1879
1880 static asection *
1881 get_got (abfd, info, ia64_info)
1882 bfd *abfd;
1883 struct bfd_link_info *info;
1884 struct elfNN_ia64_link_hash_table *ia64_info;
1885 {
1886 asection *got;
1887 bfd *dynobj;
1888
1889 got = ia64_info->got_sec;
1890 if (!got)
1891 {
1892 flagword flags;
1893
1894 dynobj = ia64_info->root.dynobj;
1895 if (!dynobj)
1896 ia64_info->root.dynobj = dynobj = abfd;
1897 if (!_bfd_elf_create_got_section (dynobj, info))
1898 return 0;
1899
1900 got = bfd_get_section_by_name (dynobj, ".got");
1901 BFD_ASSERT (got);
1902 ia64_info->got_sec = got;
1903
1904 flags = bfd_get_section_flags (abfd, got);
1905 bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags);
1906 }
1907
1908 return got;
1909 }
1910
1911 /* Create function descriptor section (.opd). This section is called .opd
1912 because it contains "official prodecure descriptors". The "official"
1913 refers to the fact that these descriptors are used when taking the address
1914 of a procedure, thus ensuring a unique address for each procedure. */
1915
1916 static asection *
1917 get_fptr (abfd, info, ia64_info)
1918 bfd *abfd;
1919 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1920 struct elfNN_ia64_link_hash_table *ia64_info;
1921 {
1922 asection *fptr;
1923 bfd *dynobj;
1924
1925 fptr = ia64_info->fptr_sec;
1926 if (!fptr)
1927 {
1928 dynobj = ia64_info->root.dynobj;
1929 if (!dynobj)
1930 ia64_info->root.dynobj = dynobj = abfd;
1931
1932 fptr = bfd_make_section (dynobj, ".opd");
1933 if (!fptr
1934 || !bfd_set_section_flags (dynobj, fptr,
1935 (SEC_ALLOC
1936 | SEC_LOAD
1937 | SEC_HAS_CONTENTS
1938 | SEC_IN_MEMORY
1939 | SEC_READONLY
1940 | SEC_LINKER_CREATED))
1941 || !bfd_set_section_alignment (abfd, fptr, 4))
1942 {
1943 BFD_ASSERT (0);
1944 return NULL;
1945 }
1946
1947 ia64_info->fptr_sec = fptr;
1948 }
1949
1950 return fptr;
1951 }
1952
1953 static asection *
1954 get_pltoff (abfd, info, ia64_info)
1955 bfd *abfd;
1956 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1957 struct elfNN_ia64_link_hash_table *ia64_info;
1958 {
1959 asection *pltoff;
1960 bfd *dynobj;
1961
1962 pltoff = ia64_info->pltoff_sec;
1963 if (!pltoff)
1964 {
1965 dynobj = ia64_info->root.dynobj;
1966 if (!dynobj)
1967 ia64_info->root.dynobj = dynobj = abfd;
1968
1969 pltoff = bfd_make_section (dynobj, ELF_STRING_ia64_pltoff);
1970 if (!pltoff
1971 || !bfd_set_section_flags (dynobj, pltoff,
1972 (SEC_ALLOC
1973 | SEC_LOAD
1974 | SEC_HAS_CONTENTS
1975 | SEC_IN_MEMORY
1976 | SEC_SMALL_DATA
1977 | SEC_LINKER_CREATED))
1978 || !bfd_set_section_alignment (abfd, pltoff, 4))
1979 {
1980 BFD_ASSERT (0);
1981 return NULL;
1982 }
1983
1984 ia64_info->pltoff_sec = pltoff;
1985 }
1986
1987 return pltoff;
1988 }
1989
1990 static asection *
1991 get_reloc_section (abfd, ia64_info, sec, create)
1992 bfd *abfd;
1993 struct elfNN_ia64_link_hash_table *ia64_info;
1994 asection *sec;
1995 boolean create;
1996 {
1997 const char *srel_name;
1998 asection *srel;
1999 bfd *dynobj;
2000
2001 srel_name = (bfd_elf_string_from_elf_section
2002 (abfd, elf_elfheader(abfd)->e_shstrndx,
2003 elf_section_data(sec)->rel_hdr.sh_name));
2004 if (srel_name == NULL)
2005 return NULL;
2006
2007 BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0
2008 && strcmp (bfd_get_section_name (abfd, sec),
2009 srel_name+5) == 0)
2010 || (strncmp (srel_name, ".rel", 4) == 0
2011 && strcmp (bfd_get_section_name (abfd, sec),
2012 srel_name+4) == 0));
2013
2014 dynobj = ia64_info->root.dynobj;
2015 if (!dynobj)
2016 ia64_info->root.dynobj = dynobj = abfd;
2017
2018 srel = bfd_get_section_by_name (dynobj, srel_name);
2019 if (srel == NULL && create)
2020 {
2021 srel = bfd_make_section (dynobj, srel_name);
2022 if (srel == NULL
2023 || !bfd_set_section_flags (dynobj, srel,
2024 (SEC_ALLOC
2025 | SEC_LOAD
2026 | SEC_HAS_CONTENTS
2027 | SEC_IN_MEMORY
2028 | SEC_LINKER_CREATED
2029 | SEC_READONLY))
2030 || !bfd_set_section_alignment (dynobj, srel, 3))
2031 return NULL;
2032 }
2033
2034 if (sec->flags & SEC_READONLY)
2035 ia64_info->reltext = 1;
2036
2037 return srel;
2038 }
2039
2040 static boolean
2041 count_dyn_reloc (abfd, dyn_i, srel, type)
2042 bfd *abfd;
2043 struct elfNN_ia64_dyn_sym_info *dyn_i;
2044 asection *srel;
2045 int type;
2046 {
2047 struct elfNN_ia64_dyn_reloc_entry *rent;
2048
2049 for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
2050 if (rent->srel == srel && rent->type == type)
2051 break;
2052
2053 if (!rent)
2054 {
2055 rent = ((struct elfNN_ia64_dyn_reloc_entry *)
2056 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)));
2057 if (!rent)
2058 return false;
2059
2060 rent->next = dyn_i->reloc_entries;
2061 rent->srel = srel;
2062 rent->type = type;
2063 rent->count = 0;
2064 dyn_i->reloc_entries = rent;
2065 }
2066 rent->count++;
2067
2068 return true;
2069 }
2070
2071 static boolean
2072 elfNN_ia64_check_relocs (abfd, info, sec, relocs)
2073 bfd *abfd;
2074 struct bfd_link_info *info;
2075 asection *sec;
2076 const Elf_Internal_Rela *relocs;
2077 {
2078 struct elfNN_ia64_link_hash_table *ia64_info;
2079 const Elf_Internal_Rela *relend;
2080 Elf_Internal_Shdr *symtab_hdr;
2081 const Elf_Internal_Rela *rel;
2082 asection *got, *fptr, *srel;
2083
2084 if (info->relocateable)
2085 return true;
2086
2087 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2088 ia64_info = elfNN_ia64_hash_table (info);
2089
2090 got = fptr = srel = NULL;
2091
2092 relend = relocs + sec->reloc_count;
2093 for (rel = relocs; rel < relend; ++rel)
2094 {
2095 enum {
2096 NEED_GOT = 1,
2097 NEED_FPTR = 2,
2098 NEED_PLTOFF = 4,
2099 NEED_MIN_PLT = 8,
2100 NEED_FULL_PLT = 16,
2101 NEED_DYNREL = 32,
2102 NEED_LTOFF_FPTR = 64,
2103 NEED_TPREL = 128,
2104 NEED_DTPMOD = 256,
2105 NEED_DTPREL = 512
2106 };
2107
2108 struct elf_link_hash_entry *h = NULL;
2109 unsigned long r_symndx = ELFNN_R_SYM (rel->r_info);
2110 struct elfNN_ia64_dyn_sym_info *dyn_i;
2111 int need_entry;
2112 boolean maybe_dynamic;
2113 int dynrel_type = R_IA64_NONE;
2114
2115 if (r_symndx >= symtab_hdr->sh_info)
2116 {
2117 /* We're dealing with a global symbol -- find its hash entry
2118 and mark it as being referenced. */
2119 long indx = r_symndx - symtab_hdr->sh_info;
2120 h = elf_sym_hashes (abfd)[indx];
2121 while (h->root.type == bfd_link_hash_indirect
2122 || h->root.type == bfd_link_hash_warning)
2123 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2124
2125 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
2126 }
2127
2128 /* We can only get preliminary data on whether a symbol is
2129 locally or externally defined, as not all of the input files
2130 have yet been processed. Do something with what we know, as
2131 this may help reduce memory usage and processing time later. */
2132 maybe_dynamic = false;
2133 if (h && ((info->shared
2134 && (!info->symbolic || info->allow_shlib_undefined))
2135 || ! (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
2136 || h->root.type == bfd_link_hash_defweak
2137 || elfNN_ia64_aix_vec (abfd->xvec)))
2138 maybe_dynamic = true;
2139
2140 need_entry = 0;
2141 switch (ELFNN_R_TYPE (rel->r_info))
2142 {
2143 case R_IA64_TPREL64MSB:
2144 case R_IA64_TPREL64LSB:
2145 if (info->shared || maybe_dynamic)
2146 need_entry = NEED_DYNREL;
2147 dynrel_type = R_IA64_TPREL64LSB;
2148 if (info->shared)
2149 info->flags |= DF_STATIC_TLS;
2150 break;
2151
2152 case R_IA64_LTOFF_TPREL22:
2153 need_entry = NEED_TPREL;
2154 if (info->shared)
2155 info->flags |= DF_STATIC_TLS;
2156 break;
2157
2158 case R_IA64_DTPREL64MSB:
2159 case R_IA64_DTPREL64LSB:
2160 if (info->shared || maybe_dynamic)
2161 need_entry = NEED_DYNREL;
2162 dynrel_type = R_IA64_DTPREL64LSB;
2163 break;
2164
2165 case R_IA64_LTOFF_DTPREL22:
2166 need_entry = NEED_DTPREL;
2167 break;
2168
2169 case R_IA64_DTPMOD64MSB:
2170 case R_IA64_DTPMOD64LSB:
2171 if (info->shared || maybe_dynamic)
2172 need_entry = NEED_DYNREL;
2173 dynrel_type = R_IA64_DTPMOD64LSB;
2174 break;
2175
2176 case R_IA64_LTOFF_DTPMOD22:
2177 need_entry = NEED_DTPMOD;
2178 break;
2179
2180 case R_IA64_LTOFF_FPTR22:
2181 case R_IA64_LTOFF_FPTR64I:
2182 case R_IA64_LTOFF_FPTR32MSB:
2183 case R_IA64_LTOFF_FPTR32LSB:
2184 case R_IA64_LTOFF_FPTR64MSB:
2185 case R_IA64_LTOFF_FPTR64LSB:
2186 need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
2187 break;
2188
2189 case R_IA64_FPTR64I:
2190 case R_IA64_FPTR32MSB:
2191 case R_IA64_FPTR32LSB:
2192 case R_IA64_FPTR64MSB:
2193 case R_IA64_FPTR64LSB:
2194 if (info->shared || h || elfNN_ia64_aix_vec (abfd->xvec))
2195 need_entry = NEED_FPTR | NEED_DYNREL;
2196 else
2197 need_entry = NEED_FPTR;
2198 dynrel_type = R_IA64_FPTR64LSB;
2199 break;
2200
2201 case R_IA64_LTOFF22:
2202 case R_IA64_LTOFF22X:
2203 case R_IA64_LTOFF64I:
2204 need_entry = NEED_GOT;
2205 break;
2206
2207 case R_IA64_PLTOFF22:
2208 case R_IA64_PLTOFF64I:
2209 case R_IA64_PLTOFF64MSB:
2210 case R_IA64_PLTOFF64LSB:
2211 need_entry = NEED_PLTOFF;
2212 if (h)
2213 {
2214 if (maybe_dynamic)
2215 need_entry |= NEED_MIN_PLT;
2216 }
2217 else
2218 {
2219 (*info->callbacks->warning)
2220 (info, _("@pltoff reloc against local symbol"), 0,
2221 abfd, 0, (bfd_vma) 0);
2222 }
2223 break;
2224
2225 case R_IA64_PCREL21B:
2226 case R_IA64_PCREL60B:
2227 /* Depending on where this symbol is defined, we may or may not
2228 need a full plt entry. Only skip if we know we'll not need
2229 the entry -- static or symbolic, and the symbol definition
2230 has already been seen. */
2231 if (maybe_dynamic && rel->r_addend == 0)
2232 need_entry = NEED_FULL_PLT;
2233 break;
2234
2235 case R_IA64_IMM14:
2236 case R_IA64_IMM22:
2237 case R_IA64_IMM64:
2238 case R_IA64_DIR32MSB:
2239 case R_IA64_DIR32LSB:
2240 case R_IA64_DIR64MSB:
2241 case R_IA64_DIR64LSB:
2242 /* Shared objects will always need at least a REL relocation. */
2243 if (info->shared || maybe_dynamic
2244 || (elfNN_ia64_aix_vec (abfd->xvec)
2245 && (!h || strcmp (h->root.root.string,
2246 "__GLOB_DATA_PTR") != 0)))
2247 need_entry = NEED_DYNREL;
2248 dynrel_type = R_IA64_DIR64LSB;
2249 break;
2250
2251 case R_IA64_IPLTMSB:
2252 case R_IA64_IPLTLSB:
2253 /* Shared objects will always need at least a REL relocation. */
2254 if (info->shared || maybe_dynamic)
2255 need_entry = NEED_DYNREL;
2256 dynrel_type = R_IA64_IPLTLSB;
2257 break;
2258
2259 case R_IA64_PCREL22:
2260 case R_IA64_PCREL64I:
2261 case R_IA64_PCREL32MSB:
2262 case R_IA64_PCREL32LSB:
2263 case R_IA64_PCREL64MSB:
2264 case R_IA64_PCREL64LSB:
2265 if (maybe_dynamic)
2266 need_entry = NEED_DYNREL;
2267 dynrel_type = R_IA64_PCREL64LSB;
2268 break;
2269 }
2270
2271 if (!need_entry)
2272 continue;
2273
2274 if ((need_entry & NEED_FPTR) != 0
2275 && rel->r_addend)
2276 {
2277 (*info->callbacks->warning)
2278 (info, _("non-zero addend in @fptr reloc"), 0,
2279 abfd, 0, (bfd_vma) 0);
2280 }
2281
2282 dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, true);
2283
2284 /* Record whether or not this is a local symbol. */
2285 dyn_i->h = h;
2286
2287 /* Create what's needed. */
2288 if (need_entry & (NEED_GOT | NEED_TPREL | NEED_DTPMOD | NEED_DTPREL))
2289 {
2290 if (!got)
2291 {
2292 got = get_got (abfd, info, ia64_info);
2293 if (!got)
2294 return false;
2295 }
2296 if (need_entry & NEED_GOT)
2297 dyn_i->want_got = 1;
2298 if (need_entry & NEED_TPREL)
2299 dyn_i->want_tprel = 1;
2300 if (need_entry & NEED_DTPMOD)
2301 dyn_i->want_dtpmod = 1;
2302 if (need_entry & NEED_DTPREL)
2303 dyn_i->want_dtprel = 1;
2304 }
2305 if (need_entry & NEED_FPTR)
2306 {
2307 if (!fptr)
2308 {
2309 fptr = get_fptr (abfd, info, ia64_info);
2310 if (!fptr)
2311 return false;
2312 }
2313
2314 /* FPTRs for shared libraries are allocated by the dynamic
2315 linker. Make sure this local symbol will appear in the
2316 dynamic symbol table. */
2317 if (!h && (info->shared
2318 /* AIX also needs one */
2319 || elfNN_ia64_aix_vec (abfd->xvec)))
2320 {
2321 if (! (_bfd_elfNN_link_record_local_dynamic_symbol
2322 (info, abfd, (long) r_symndx)))
2323 return false;
2324 }
2325
2326 dyn_i->want_fptr = 1;
2327 }
2328 if (need_entry & NEED_LTOFF_FPTR)
2329 dyn_i->want_ltoff_fptr = 1;
2330 if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT))
2331 {
2332 if (!ia64_info->root.dynobj)
2333 ia64_info->root.dynobj = abfd;
2334 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2335 dyn_i->want_plt = 1;
2336 }
2337 if (need_entry & NEED_FULL_PLT)
2338 dyn_i->want_plt2 = 1;
2339 if (need_entry & NEED_PLTOFF)
2340 dyn_i->want_pltoff = 1;
2341 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
2342 {
2343 if (!srel)
2344 {
2345 srel = get_reloc_section (abfd, ia64_info, sec, true);
2346 if (!srel)
2347 return false;
2348 }
2349 if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type))
2350 return false;
2351 }
2352 }
2353
2354 return true;
2355 }
2356
2357 struct elfNN_ia64_allocate_data
2358 {
2359 struct bfd_link_info *info;
2360 bfd_size_type ofs;
2361 };
2362
2363 /* For cleanliness, and potentially faster dynamic loading, allocate
2364 external GOT entries first. */
2365
2366 static boolean
2367 allocate_global_data_got (dyn_i, data)
2368 struct elfNN_ia64_dyn_sym_info *dyn_i;
2369 PTR data;
2370 {
2371 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2372
2373 if (dyn_i->want_got
2374 && ! dyn_i->want_fptr
2375 && (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
2376 || (elfNN_ia64_aix_vec (x->info->hash->creator)
2377 && (!dyn_i->h || strcmp (dyn_i->h->root.root.string,
2378 "__GLOB_DATA_PTR") != 0))))
2379 {
2380 dyn_i->got_offset = x->ofs;
2381 x->ofs += 8;
2382 }
2383 if (dyn_i->want_tprel)
2384 {
2385 dyn_i->tprel_offset = x->ofs;
2386 x->ofs += 8;
2387 }
2388 if (dyn_i->want_dtpmod)
2389 {
2390 dyn_i->dtpmod_offset = x->ofs;
2391 x->ofs += 8;
2392 }
2393 if (dyn_i->want_dtprel)
2394 {
2395 dyn_i->dtprel_offset = x->ofs;
2396 x->ofs += 8;
2397 }
2398 return true;
2399 }
2400
2401 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2402
2403 static boolean
2404 allocate_global_fptr_got (dyn_i, data)
2405 struct elfNN_ia64_dyn_sym_info *dyn_i;
2406 PTR data;
2407 {
2408 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2409
2410 if (dyn_i->want_got
2411 && dyn_i->want_fptr
2412 && (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
2413 || elfNN_ia64_aix_vec (x->info->hash->creator)))
2414 {
2415 dyn_i->got_offset = x->ofs;
2416 x->ofs += 8;
2417 }
2418 return true;
2419 }
2420
2421 /* Lastly, allocate all the GOT entries for local data. */
2422
2423 static boolean
2424 allocate_local_got (dyn_i, data)
2425 struct elfNN_ia64_dyn_sym_info *dyn_i;
2426 PTR data;
2427 {
2428 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2429
2430 if (dyn_i->want_got
2431 && ! (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
2432 || elfNN_ia64_aix_vec (x->info->hash->creator)))
2433 {
2434 dyn_i->got_offset = x->ofs;
2435 x->ofs += 8;
2436 }
2437 return true;
2438 }
2439
2440 /* Search for the index of a global symbol in it's defining object file. */
2441
2442 static long
2443 global_sym_index (h)
2444 struct elf_link_hash_entry *h;
2445 {
2446 struct elf_link_hash_entry **p;
2447 bfd *obj;
2448
2449 BFD_ASSERT (h->root.type == bfd_link_hash_defined
2450 || h->root.type == bfd_link_hash_defweak);
2451
2452 obj = h->root.u.def.section->owner;
2453 for (p = elf_sym_hashes (obj); *p != h; ++p)
2454 continue;
2455
2456 return p - elf_sym_hashes (obj) + elf_tdata (obj)->symtab_hdr.sh_info;
2457 }
2458
2459 /* Allocate function descriptors. We can do these for every function
2460 in a main executable that is not exported. */
2461
2462 static boolean
2463 allocate_fptr (dyn_i, data)
2464 struct elfNN_ia64_dyn_sym_info *dyn_i;
2465 PTR data;
2466 {
2467 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2468
2469 if (dyn_i->want_fptr)
2470 {
2471 struct elf_link_hash_entry *h = dyn_i->h;
2472
2473 if (h)
2474 while (h->root.type == bfd_link_hash_indirect
2475 || h->root.type == bfd_link_hash_warning)
2476 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2477
2478 if (x->info->shared
2479 /* AIX needs an FPTR in this case. */
2480 || (elfNN_ia64_aix_vec (x->info->hash->creator)
2481 && (!h
2482 || h->root.type == bfd_link_hash_defined
2483 || h->root.type == bfd_link_hash_defweak)))
2484 {
2485 if (h && h->dynindx == -1)
2486 {
2487 BFD_ASSERT ((h->root.type == bfd_link_hash_defined)
2488 || (h->root.type == bfd_link_hash_defweak));
2489
2490 if (!_bfd_elfNN_link_record_local_dynamic_symbol
2491 (x->info, h->root.u.def.section->owner,
2492 global_sym_index (h)))
2493 return false;
2494 }
2495
2496 dyn_i->want_fptr = 0;
2497 }
2498 else if (h == NULL || h->dynindx == -1)
2499 {
2500 dyn_i->fptr_offset = x->ofs;
2501 x->ofs += 16;
2502 }
2503 else
2504 dyn_i->want_fptr = 0;
2505 }
2506 return true;
2507 }
2508
2509 /* Allocate all the minimal PLT entries. */
2510
2511 static boolean
2512 allocate_plt_entries (dyn_i, data)
2513 struct elfNN_ia64_dyn_sym_info *dyn_i;
2514 PTR data;
2515 {
2516 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2517
2518 if (dyn_i->want_plt)
2519 {
2520 struct elf_link_hash_entry *h = dyn_i->h;
2521
2522 if (h)
2523 while (h->root.type == bfd_link_hash_indirect
2524 || h->root.type == bfd_link_hash_warning)
2525 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2526
2527 /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */
2528 if (elfNN_ia64_dynamic_symbol_p (h, x->info))
2529 {
2530 bfd_size_type offset = x->ofs;
2531 if (offset == 0)
2532 offset = PLT_HEADER_SIZE;
2533 dyn_i->plt_offset = offset;
2534 x->ofs = offset + PLT_MIN_ENTRY_SIZE;
2535
2536 dyn_i->want_pltoff = 1;
2537 }
2538 else
2539 {
2540 dyn_i->want_plt = 0;
2541 dyn_i->want_plt2 = 0;
2542 }
2543 }
2544 return true;
2545 }
2546
2547 /* Allocate all the full PLT entries. */
2548
2549 static boolean
2550 allocate_plt2_entries (dyn_i, data)
2551 struct elfNN_ia64_dyn_sym_info *dyn_i;
2552 PTR data;
2553 {
2554 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2555
2556 if (dyn_i->want_plt2)
2557 {
2558 struct elf_link_hash_entry *h = dyn_i->h;
2559 bfd_size_type ofs = x->ofs;
2560
2561 dyn_i->plt2_offset = ofs;
2562 x->ofs = ofs + PLT_FULL_ENTRY_SIZE;
2563
2564 while (h->root.type == bfd_link_hash_indirect
2565 || h->root.type == bfd_link_hash_warning)
2566 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2567 dyn_i->h->plt.offset = ofs;
2568 }
2569 return true;
2570 }
2571
2572 /* Allocate all the PLTOFF entries requested by relocations and
2573 plt entries. We can't share space with allocated FPTR entries,
2574 because the latter are not necessarily addressable by the GP.
2575 ??? Relaxation might be able to determine that they are. */
2576
2577 static boolean
2578 allocate_pltoff_entries (dyn_i, data)
2579 struct elfNN_ia64_dyn_sym_info *dyn_i;
2580 PTR data;
2581 {
2582 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2583
2584 if (dyn_i->want_pltoff)
2585 {
2586 dyn_i->pltoff_offset = x->ofs;
2587 x->ofs += 16;
2588 }
2589 return true;
2590 }
2591
2592 /* Allocate dynamic relocations for those symbols that turned out
2593 to be dynamic. */
2594
2595 static boolean
2596 allocate_dynrel_entries (dyn_i, data)
2597 struct elfNN_ia64_dyn_sym_info *dyn_i;
2598 PTR data;
2599 {
2600 struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
2601 struct elfNN_ia64_link_hash_table *ia64_info;
2602 struct elfNN_ia64_dyn_reloc_entry *rent;
2603 boolean dynamic_symbol, shared;
2604
2605 ia64_info = elfNN_ia64_hash_table (x->info);
2606 dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
2607 || (elfNN_ia64_aix_vec (x->info->hash->creator)
2608 /* Don't allocate an entry for __GLOB_DATA_PTR */
2609 && (!dyn_i->h || strcmp (dyn_i->h->root.root.string,
2610 "__GLOB_DATA_PTR") != 0));
2611 shared = x->info->shared;
2612
2613 /* Take care of the normal data relocations. */
2614
2615 for (rent = dyn_i->reloc_entries; rent; rent = rent->next)
2616 {
2617 int count = rent->count;
2618
2619 switch (rent->type)
2620 {
2621 case R_IA64_FPTR64LSB:
2622 /* Allocate one iff !want_fptr, which by this point will
2623 be true only if we're actually allocating one statically
2624 in the main executable. */
2625 if (dyn_i->want_fptr)
2626 continue;
2627 break;
2628 case R_IA64_PCREL64LSB:
2629 if (!dynamic_symbol)
2630 continue;
2631 break;
2632 case R_IA64_DIR64LSB:
2633 if (!dynamic_symbol && !shared)
2634 continue;
2635 break;
2636 case R_IA64_IPLTLSB:
2637 if (!dynamic_symbol && !shared)
2638 continue;
2639 /* Use two REL relocations for IPLT relocations
2640 against local symbols. */
2641 if (!dynamic_symbol)
2642 count *= 2;
2643 break;
2644 case R_IA64_TPREL64LSB:
2645 case R_IA64_DTPREL64LSB:
2646 case R_IA64_DTPMOD64LSB:
2647 break;
2648 default:
2649 abort ();
2650 }
2651 rent->srel->_raw_size += sizeof (ElfNN_External_Rela) * count;
2652 }
2653
2654 /* Take care of the GOT and PLT relocations. */
2655
2656 if (((dynamic_symbol || shared) && dyn_i->want_got)
2657 || (dyn_i->want_ltoff_fptr && dyn_i->h && dyn_i->h->dynindx != -1))
2658 ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
2659 if ((dynamic_symbol || shared) && dyn_i->want_tprel)
2660 ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
2661 if ((dynamic_symbol || shared) && dyn_i->want_dtpmod)
2662 ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
2663 if (dynamic_symbol && dyn_i->want_dtprel)
2664 ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
2665
2666 if (dyn_i->want_pltoff)
2667 {
2668 bfd_size_type t = 0;
2669
2670 /* Dynamic symbols get one IPLT relocation. Local symbols in
2671 shared libraries get two REL relocations. Local symbols in
2672 main applications get nothing. */
2673 if (dynamic_symbol)
2674 t = sizeof (ElfNN_External_Rela);
2675 else if (shared)
2676 t = 2 * sizeof (ElfNN_External_Rela);
2677
2678 ia64_info->rel_pltoff_sec->_raw_size += t;
2679 }
2680
2681 return true;
2682 }
2683
2684 static boolean
2685 elfNN_ia64_adjust_dynamic_symbol (info, h)
2686 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2687 struct elf_link_hash_entry *h;
2688 {
2689 /* ??? Undefined symbols with PLT entries should be re-defined
2690 to be the PLT entry. */
2691
2692 /* If this is a weak symbol, and there is a real definition, the
2693 processor independent code will have arranged for us to see the
2694 real definition first, and we can just use the same value. */
2695 if (h->weakdef != NULL)
2696 {
2697 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2698 || h->weakdef->root.type == bfd_link_hash_defweak);
2699 h->root.u.def.section = h->weakdef->root.u.def.section;
2700 h->root.u.def.value = h->weakdef->root.u.def.value;
2701 return true;
2702 }
2703
2704 /* If this is a reference to a symbol defined by a dynamic object which
2705 is not a function, we might allocate the symbol in our .dynbss section
2706 and allocate a COPY dynamic relocation.
2707
2708 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
2709 of hackery. */
2710
2711 return true;
2712 }
2713
2714 static boolean
2715 elfNN_ia64_size_dynamic_sections (output_bfd, info)
2716 bfd *output_bfd;
2717 struct bfd_link_info *info;
2718 {
2719 struct elfNN_ia64_allocate_data data;
2720 struct elfNN_ia64_link_hash_table *ia64_info;
2721 asection *sec;
2722 bfd *dynobj;
2723 boolean relplt = false;
2724
2725 dynobj = elf_hash_table(info)->dynobj;
2726 ia64_info = elfNN_ia64_hash_table (info);
2727 BFD_ASSERT(dynobj != NULL);
2728 data.info = info;
2729
2730 /* Set the contents of the .interp section to the interpreter. */
2731 if (ia64_info->root.dynamic_sections_created
2732 && !info->shared)
2733 {
2734 sec = bfd_get_section_by_name (dynobj, ".interp");
2735 BFD_ASSERT (sec != NULL);
2736 sec->contents = (bfd_byte *) DYNAMIC_INTERPRETER (output_bfd);
2737 sec->_raw_size = strlen (DYNAMIC_INTERPRETER (output_bfd)) + 1;
2738 }
2739
2740 /* Allocate the GOT entries. */
2741
2742 if (ia64_info->got_sec)
2743 {
2744 data.ofs = 0;
2745 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data);
2746 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data);
2747 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data);
2748 ia64_info->got_sec->_raw_size = data.ofs;
2749 }
2750
2751 /* Allocate the FPTR entries. */
2752
2753 if (ia64_info->fptr_sec)
2754 {
2755 data.ofs = 0;
2756 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data);
2757 ia64_info->fptr_sec->_raw_size = data.ofs;
2758 }
2759
2760 /* Now that we've seen all of the input files, we can decide which
2761 symbols need plt entries. Allocate the minimal PLT entries first.
2762 We do this even though dynamic_sections_created may be false, because
2763 this has the side-effect of clearing want_plt and want_plt2. */
2764
2765 data.ofs = 0;
2766 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data);
2767
2768 ia64_info->minplt_entries = 0;
2769 if (data.ofs)
2770 {
2771 ia64_info->minplt_entries
2772 = (data.ofs - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE;
2773 }
2774
2775 /* Align the pointer for the plt2 entries. */
2776 data.ofs = (data.ofs + 31) & (bfd_vma) -32;
2777
2778 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
2779 if (data.ofs != 0)
2780 {
2781 BFD_ASSERT (ia64_info->root.dynamic_sections_created);
2782
2783 ia64_info->plt_sec->_raw_size = data.ofs;
2784
2785 /* If we've got a .plt, we need some extra memory for the dynamic
2786 linker. We stuff these in .got.plt. */
2787 sec = bfd_get_section_by_name (dynobj, ".got.plt");
2788 sec->_raw_size = 8 * PLT_RESERVED_WORDS;
2789 }
2790
2791 /* Allocate the PLTOFF entries. */
2792
2793 if (ia64_info->pltoff_sec)
2794 {
2795 data.ofs = 0;
2796 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data);
2797 ia64_info->pltoff_sec->_raw_size = data.ofs;
2798 }
2799
2800 if (ia64_info->root.dynamic_sections_created)
2801 {
2802 /* Allocate space for the dynamic relocations that turned out to be
2803 required. */
2804
2805 elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data);
2806 }
2807
2808 /* We have now determined the sizes of the various dynamic sections.
2809 Allocate memory for them. */
2810 for (sec = dynobj->sections; sec != NULL; sec = sec->next)
2811 {
2812 boolean strip;
2813
2814 if (!(sec->flags & SEC_LINKER_CREATED))
2815 continue;
2816
2817 /* If we don't need this section, strip it from the output file.
2818 There were several sections primarily related to dynamic
2819 linking that must be create before the linker maps input
2820 sections to output sections. The linker does that before
2821 bfd_elf_size_dynamic_sections is called, and it is that
2822 function which decides whether anything needs to go into
2823 these sections. */
2824
2825 strip = (sec->_raw_size == 0);
2826
2827 if (sec == ia64_info->got_sec)
2828 strip = false;
2829 else if (sec == ia64_info->rel_got_sec)
2830 {
2831 if (strip)
2832 ia64_info->rel_got_sec = NULL;
2833 else
2834 /* We use the reloc_count field as a counter if we need to
2835 copy relocs into the output file. */
2836 sec->reloc_count = 0;
2837 }
2838 else if (sec == ia64_info->fptr_sec)
2839 {
2840 if (strip)
2841 ia64_info->fptr_sec = NULL;
2842 }
2843 else if (sec == ia64_info->plt_sec)
2844 {
2845 if (strip)
2846 ia64_info->plt_sec = NULL;
2847 }
2848 else if (sec == ia64_info->pltoff_sec)
2849 {
2850 if (strip)
2851 ia64_info->pltoff_sec = NULL;
2852 }
2853 else if (sec == ia64_info->rel_pltoff_sec)
2854 {
2855 if (strip)
2856 ia64_info->rel_pltoff_sec = NULL;
2857 else
2858 {
2859 relplt = true;
2860 /* We use the reloc_count field as a counter if we need to
2861 copy relocs into the output file. */
2862 sec->reloc_count = 0;
2863 }
2864 }
2865 else
2866 {
2867 const char *name;
2868
2869 /* It's OK to base decisions on the section name, because none
2870 of the dynobj section names depend upon the input files. */
2871 name = bfd_get_section_name (dynobj, sec);
2872
2873 if (strcmp (name, ".got.plt") == 0)
2874 strip = false;
2875 else if (strncmp (name, ".rel", 4) == 0)
2876 {
2877 if (!strip)
2878 {
2879 /* We use the reloc_count field as a counter if we need to
2880 copy relocs into the output file. */
2881 sec->reloc_count = 0;
2882 }
2883 }
2884 else
2885 continue;
2886 }
2887
2888 if (strip)
2889 _bfd_strip_section_from_output (info, sec);
2890 else
2891 {
2892 /* Allocate memory for the section contents. */
2893 sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->_raw_size);
2894 if (sec->contents == NULL && sec->_raw_size != 0)
2895 return false;
2896 }
2897 }
2898
2899 if (elf_hash_table (info)->dynamic_sections_created)
2900 {
2901 /* Add some entries to the .dynamic section. We fill in the values
2902 later (in finish_dynamic_sections) but we must add the entries now
2903 so that we get the correct size for the .dynamic section. */
2904
2905 if (!info->shared)
2906 {
2907 /* The DT_DEBUG entry is filled in by the dynamic linker and used
2908 by the debugger. */
2909 #define add_dynamic_entry(TAG, VAL) \
2910 bfd_elfNN_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2911
2912 if (!add_dynamic_entry (DT_DEBUG, 0))
2913 return false;
2914 }
2915
2916 if (!add_dynamic_entry (DT_IA_64_PLT_RESERVE, 0))
2917 return false;
2918 if (!add_dynamic_entry (DT_PLTGOT, 0))
2919 return false;
2920
2921 if (relplt)
2922 {
2923 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
2924 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2925 || !add_dynamic_entry (DT_JMPREL, 0))
2926 return false;
2927 }
2928
2929 if (!add_dynamic_entry (DT_RELA, 0)
2930 || !add_dynamic_entry (DT_RELASZ, 0)
2931 || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela)))
2932 return false;
2933
2934 if (ia64_info->reltext)
2935 {
2936 if (!add_dynamic_entry (DT_TEXTREL, 0))
2937 return false;
2938 info->flags |= DF_TEXTREL;
2939 }
2940 }
2941
2942 /* ??? Perhaps force __gp local. */
2943
2944 return true;
2945 }
2946
2947 static bfd_reloc_status_type
2948 elfNN_ia64_install_value (abfd, hit_addr, v, r_type)
2949 bfd *abfd;
2950 bfd_byte *hit_addr;
2951 bfd_vma v;
2952 unsigned int r_type;
2953 {
2954 const struct ia64_operand *op;
2955 int bigendian = 0, shift = 0;
2956 bfd_vma t0, t1, insn, dword;
2957 enum ia64_opnd opnd;
2958 const char *err;
2959 size_t size = 8;
2960 #ifdef BFD_HOST_U_64_BIT
2961 BFD_HOST_U_64_BIT val = (BFD_HOST_U_64_BIT) v;
2962 #else
2963 bfd_vma val = v;
2964 #endif
2965
2966 opnd = IA64_OPND_NIL;
2967 switch (r_type)
2968 {
2969 case R_IA64_NONE:
2970 case R_IA64_LDXMOV:
2971 return bfd_reloc_ok;
2972
2973 /* Instruction relocations. */
2974
2975 case R_IA64_IMM14:
2976 case R_IA64_TPREL14:
2977 case R_IA64_DTPREL14:
2978 opnd = IA64_OPND_IMM14;
2979 break;
2980
2981 case R_IA64_PCREL21F: opnd = IA64_OPND_TGT25; break;
2982 case R_IA64_PCREL21M: opnd = IA64_OPND_TGT25b; break;
2983 case R_IA64_PCREL60B: opnd = IA64_OPND_TGT64; break;
2984 case R_IA64_PCREL21B:
2985 case R_IA64_PCREL21BI:
2986 opnd = IA64_OPND_TGT25c;
2987 break;
2988
2989 case R_IA64_IMM22:
2990 case R_IA64_GPREL22:
2991 case R_IA64_LTOFF22:
2992 case R_IA64_LTOFF22X:
2993 case R_IA64_PLTOFF22:
2994 case R_IA64_PCREL22:
2995 case R_IA64_LTOFF_FPTR22:
2996 case R_IA64_TPREL22:
2997 case R_IA64_DTPREL22:
2998 case R_IA64_LTOFF_TPREL22:
2999 case R_IA64_LTOFF_DTPMOD22:
3000 case R_IA64_LTOFF_DTPREL22:
3001 opnd = IA64_OPND_IMM22;
3002 break;
3003
3004 case R_IA64_IMM64:
3005 case R_IA64_GPREL64I:
3006 case R_IA64_LTOFF64I:
3007 case R_IA64_PLTOFF64I:
3008 case R_IA64_PCREL64I:
3009 case R_IA64_FPTR64I:
3010 case R_IA64_LTOFF_FPTR64I:
3011 case R_IA64_TPREL64I:
3012 case R_IA64_DTPREL64I:
3013 opnd = IA64_OPND_IMMU64;
3014 break;
3015
3016 /* Data relocations. */
3017
3018 case R_IA64_DIR32MSB:
3019 case R_IA64_GPREL32MSB:
3020 case R_IA64_FPTR32MSB:
3021 case R_IA64_PCREL32MSB:
3022 case R_IA64_LTOFF_FPTR32MSB:
3023 case R_IA64_SEGREL32MSB:
3024 case R_IA64_SECREL32MSB:
3025 case R_IA64_LTV32MSB:
3026 case R_IA64_DTPREL32MSB:
3027 size = 4; bigendian = 1;
3028 break;
3029
3030 case R_IA64_DIR32LSB:
3031 case R_IA64_GPREL32LSB:
3032 case R_IA64_FPTR32LSB:
3033 case R_IA64_PCREL32LSB:
3034 case R_IA64_LTOFF_FPTR32LSB:
3035 case R_IA64_SEGREL32LSB:
3036 case R_IA64_SECREL32LSB:
3037 case R_IA64_LTV32LSB:
3038 case R_IA64_DTPREL32LSB:
3039 size = 4; bigendian = 0;
3040 break;
3041
3042 case R_IA64_DIR64MSB:
3043 case R_IA64_GPREL64MSB:
3044 case R_IA64_PLTOFF64MSB:
3045 case R_IA64_FPTR64MSB:
3046 case R_IA64_PCREL64MSB:
3047 case R_IA64_LTOFF_FPTR64MSB:
3048 case R_IA64_SEGREL64MSB:
3049 case R_IA64_SECREL64MSB:
3050 case R_IA64_LTV64MSB:
3051 case R_IA64_TPREL64MSB:
3052 case R_IA64_DTPMOD64MSB:
3053 case R_IA64_DTPREL64MSB:
3054 size = 8; bigendian = 1;
3055 break;
3056
3057 case R_IA64_DIR64LSB:
3058 case R_IA64_GPREL64LSB:
3059 case R_IA64_PLTOFF64LSB:
3060 case R_IA64_FPTR64LSB:
3061 case R_IA64_PCREL64LSB:
3062 case R_IA64_LTOFF_FPTR64LSB:
3063 case R_IA64_SEGREL64LSB:
3064 case R_IA64_SECREL64LSB:
3065 case R_IA64_LTV64LSB:
3066 case R_IA64_TPREL64LSB:
3067 case R_IA64_DTPMOD64LSB:
3068 case R_IA64_DTPREL64LSB:
3069 size = 8; bigendian = 0;
3070 break;
3071
3072 /* Unsupported / Dynamic relocations. */
3073 default:
3074 return bfd_reloc_notsupported;
3075 }
3076
3077 switch (opnd)
3078 {
3079 case IA64_OPND_IMMU64:
3080 hit_addr -= (long) hit_addr & 0x3;
3081 t0 = bfd_get_64 (abfd, hit_addr);
3082 t1 = bfd_get_64 (abfd, hit_addr + 8);
3083
3084 /* tmpl/s: bits 0.. 5 in t0
3085 slot 0: bits 5..45 in t0
3086 slot 1: bits 46..63 in t0, bits 0..22 in t1
3087 slot 2: bits 23..63 in t1 */
3088
3089 /* First, clear the bits that form the 64 bit constant. */
3090 t0 &= ~(0x3ffffLL << 46);
3091 t1 &= ~(0x7fffffLL
3092 | (( (0x07fLL << 13) | (0x1ffLL << 27)
3093 | (0x01fLL << 22) | (0x001LL << 21)
3094 | (0x001LL << 36)) << 23));
3095
3096 t0 |= ((val >> 22) & 0x03ffffLL) << 46; /* 18 lsbs of imm41 */
3097 t1 |= ((val >> 40) & 0x7fffffLL) << 0; /* 23 msbs of imm41 */
3098 t1 |= ( (((val >> 0) & 0x07f) << 13) /* imm7b */
3099 | (((val >> 7) & 0x1ff) << 27) /* imm9d */
3100 | (((val >> 16) & 0x01f) << 22) /* imm5c */
3101 | (((val >> 21) & 0x001) << 21) /* ic */
3102 | (((val >> 63) & 0x001) << 36)) << 23; /* i */
3103
3104 bfd_put_64 (abfd, t0, hit_addr);
3105 bfd_put_64 (abfd, t1, hit_addr + 8);
3106 break;
3107
3108 case IA64_OPND_TGT64:
3109 hit_addr -= (long) hit_addr & 0x3;
3110 t0 = bfd_get_64 (abfd, hit_addr);
3111 t1 = bfd_get_64 (abfd, hit_addr + 8);
3112
3113 /* tmpl/s: bits 0.. 5 in t0
3114 slot 0: bits 5..45 in t0
3115 slot 1: bits 46..63 in t0, bits 0..22 in t1
3116 slot 2: bits 23..63 in t1 */
3117
3118 /* First, clear the bits that form the 64 bit constant. */
3119 t0 &= ~(0x3ffffLL << 46);
3120 t1 &= ~(0x7fffffLL
3121 | ((1LL << 36 | 0xfffffLL << 13) << 23));
3122
3123 val >>= 4;
3124 t0 |= ((val >> 20) & 0xffffLL) << 2 << 46; /* 16 lsbs of imm39 */
3125 t1 |= ((val >> 36) & 0x7fffffLL) << 0; /* 23 msbs of imm39 */
3126 t1 |= ((((val >> 0) & 0xfffffLL) << 13) /* imm20b */
3127 | (((val >> 59) & 0x1LL) << 36)) << 23; /* i */
3128
3129 bfd_put_64 (abfd, t0, hit_addr);
3130 bfd_put_64 (abfd, t1, hit_addr + 8);
3131 break;
3132
3133 default:
3134 switch ((long) hit_addr & 0x3)
3135 {
3136 case 0: shift = 5; break;
3137 case 1: shift = 14; hit_addr += 3; break;
3138 case 2: shift = 23; hit_addr += 6; break;
3139 case 3: return bfd_reloc_notsupported; /* shouldn't happen... */
3140 }
3141 dword = bfd_get_64 (abfd, hit_addr);
3142 insn = (dword >> shift) & 0x1ffffffffffLL;
3143
3144 op = elf64_ia64_operands + opnd;
3145 err = (*op->insert) (op, val, (ia64_insn *)& insn);
3146 if (err)
3147 return bfd_reloc_overflow;
3148
3149 dword &= ~(0x1ffffffffffLL << shift);
3150 dword |= (insn << shift);
3151 bfd_put_64 (abfd, dword, hit_addr);
3152 break;
3153
3154 case IA64_OPND_NIL:
3155 /* A data relocation. */
3156 if (bigendian)
3157 if (size == 4)
3158 bfd_putb32 (val, hit_addr);
3159 else
3160 bfd_putb64 (val, hit_addr);
3161 else
3162 if (size == 4)
3163 bfd_putl32 (val, hit_addr);
3164 else
3165 bfd_putl64 (val, hit_addr);
3166 break;
3167 }
3168
3169 return bfd_reloc_ok;
3170 }
3171
3172 static void
3173 elfNN_ia64_install_dyn_reloc (abfd, info, sec, srel, offset, type,
3174 dynindx, addend)
3175 bfd *abfd;
3176 struct bfd_link_info *info;
3177 asection *sec;
3178 asection *srel;
3179 bfd_vma offset;
3180 unsigned int type;
3181 long dynindx;
3182 bfd_vma addend;
3183 {
3184 Elf_Internal_Rela outrel;
3185
3186 offset += sec->output_section->vma + sec->output_offset;
3187
3188 BFD_ASSERT (dynindx != -1);
3189 outrel.r_info = ELFNN_R_INFO (dynindx, type);
3190 outrel.r_addend = addend;
3191 outrel.r_offset = _bfd_elf_section_offset (abfd, info, sec, offset);
3192 if ((outrel.r_offset | 1) == (bfd_vma) -1)
3193 {
3194 /* Run for the hills. We shouldn't be outputting a relocation
3195 for this. So do what everyone else does and output a no-op. */
3196 outrel.r_info = ELFNN_R_INFO (0, R_IA64_NONE);
3197 outrel.r_addend = 0;
3198 outrel.r_offset = 0;
3199 }
3200
3201 bfd_elfNN_swap_reloca_out (abfd, &outrel,
3202 ((ElfNN_External_Rela *) srel->contents
3203 + srel->reloc_count++));
3204 BFD_ASSERT (sizeof (ElfNN_External_Rela) * srel->reloc_count
3205 <= srel->_cooked_size);
3206 }
3207
3208 /* Store an entry for target address TARGET_ADDR in the linkage table
3209 and return the gp-relative address of the linkage table entry. */
3210
3211 static bfd_vma
3212 set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type)
3213 bfd *abfd;
3214 struct bfd_link_info *info;
3215 struct elfNN_ia64_dyn_sym_info *dyn_i;
3216 long dynindx;
3217 bfd_vma addend;
3218 bfd_vma value;
3219 unsigned int dyn_r_type;
3220 {
3221 struct elfNN_ia64_link_hash_table *ia64_info;
3222 asection *got_sec;
3223 boolean done;
3224 bfd_vma got_offset;
3225
3226 ia64_info = elfNN_ia64_hash_table (info);
3227 got_sec = ia64_info->got_sec;
3228
3229 switch (dyn_r_type)
3230 {
3231 case R_IA64_TPREL64LSB:
3232 done = dyn_i->tprel_done;
3233 dyn_i->tprel_done = true;
3234 got_offset = dyn_i->tprel_offset;
3235 break;
3236 case R_IA64_DTPMOD64LSB:
3237 done = dyn_i->dtpmod_done;
3238 dyn_i->dtpmod_done = true;
3239 got_offset = dyn_i->dtpmod_offset;
3240 break;
3241 case R_IA64_DTPREL64LSB:
3242 done = dyn_i->dtprel_done;
3243 dyn_i->dtprel_done = true;
3244 got_offset = dyn_i->dtprel_offset;
3245 break;
3246 default:
3247 done = dyn_i->got_done;
3248 dyn_i->got_done = true;
3249 got_offset = dyn_i->got_offset;
3250 break;
3251 }
3252
3253 BFD_ASSERT ((got_offset & 7) == 0);
3254
3255 if (! done)
3256 {
3257 /* Store the target address in the linkage table entry. */
3258 bfd_put_64 (abfd, value, got_sec->contents + got_offset);
3259
3260 /* Install a dynamic relocation if needed. */
3261 if ((info->shared && dyn_r_type != R_IA64_DTPREL64LSB)
3262 || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info)
3263 || elfNN_ia64_aix_vec (abfd->xvec)
3264 || (dynindx != -1 && dyn_r_type == R_IA64_FPTR64LSB))
3265 {
3266 if (dynindx == -1
3267 && dyn_r_type != R_IA64_TPREL64LSB
3268 && dyn_r_type != R_IA64_DTPMOD64LSB
3269 && dyn_r_type != R_IA64_DTPREL64LSB)
3270 {
3271 dyn_r_type = R_IA64_REL64LSB;
3272 dynindx = 0;
3273 addend = value;
3274 }
3275
3276 if (bfd_big_endian (abfd))
3277 {
3278 switch (dyn_r_type)
3279 {
3280 case R_IA64_REL64LSB:
3281 dyn_r_type = R_IA64_REL64MSB;
3282 break;
3283 case R_IA64_DIR64LSB:
3284 dyn_r_type = R_IA64_DIR64MSB;
3285 break;
3286 case R_IA64_FPTR64LSB:
3287 dyn_r_type = R_IA64_FPTR64MSB;
3288 break;
3289 case R_IA64_TPREL64LSB:
3290 dyn_r_type = R_IA64_TPREL64MSB;
3291 break;
3292 case R_IA64_DTPMOD64LSB:
3293 dyn_r_type = R_IA64_DTPMOD64MSB;
3294 break;
3295 case R_IA64_DTPREL64LSB:
3296 dyn_r_type = R_IA64_DTPREL64MSB;
3297 break;
3298 default:
3299 BFD_ASSERT (false);
3300 break;
3301 }
3302 }
3303
3304 elfNN_ia64_install_dyn_reloc (abfd, NULL, got_sec,
3305 ia64_info->rel_got_sec,
3306 got_offset, dyn_r_type,
3307 dynindx, addend);
3308 }
3309 }
3310
3311 /* Return the address of the linkage table entry. */
3312 value = (got_sec->output_section->vma
3313 + got_sec->output_offset
3314 + got_offset);
3315
3316 return value;
3317 }
3318
3319 /* Fill in a function descriptor consisting of the function's code
3320 address and its global pointer. Return the descriptor's address. */
3321
3322 static bfd_vma
3323 set_fptr_entry (abfd, info, dyn_i, value)
3324 bfd *abfd;
3325 struct bfd_link_info *info;
3326 struct elfNN_ia64_dyn_sym_info *dyn_i;
3327 bfd_vma value;
3328 {
3329 struct elfNN_ia64_link_hash_table *ia64_info;
3330 asection *fptr_sec;
3331
3332 ia64_info = elfNN_ia64_hash_table (info);
3333 fptr_sec = ia64_info->fptr_sec;
3334
3335 if (!dyn_i->fptr_done)
3336 {
3337 dyn_i->fptr_done = 1;
3338
3339 /* Fill in the function descriptor. */
3340 bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset);
3341 bfd_put_64 (abfd, _bfd_get_gp_value (abfd),
3342 fptr_sec->contents + dyn_i->fptr_offset + 8);
3343 }
3344
3345 /* Return the descriptor's address. */
3346 value = (fptr_sec->output_section->vma
3347 + fptr_sec->output_offset
3348 + dyn_i->fptr_offset);
3349
3350 return value;
3351 }
3352
3353 /* Fill in a PLTOFF entry consisting of the function's code address
3354 and its global pointer. Return the descriptor's address. */
3355
3356 static bfd_vma
3357 set_pltoff_entry (abfd, info, dyn_i, value, is_plt)
3358 bfd *abfd;
3359 struct bfd_link_info *info;
3360 struct elfNN_ia64_dyn_sym_info *dyn_i;
3361 bfd_vma value;
3362 boolean is_plt;
3363 {
3364 struct elfNN_ia64_link_hash_table *ia64_info;
3365 asection *pltoff_sec;
3366
3367 ia64_info = elfNN_ia64_hash_table (info);
3368 pltoff_sec = ia64_info->pltoff_sec;
3369
3370 /* Don't do anything if this symbol uses a real PLT entry. In
3371 that case, we'll fill this in during finish_dynamic_symbol. */
3372 if ((! dyn_i->want_plt || is_plt)
3373 && !dyn_i->pltoff_done)
3374 {
3375 bfd_vma gp = _bfd_get_gp_value (abfd);
3376
3377 /* Fill in the function descriptor. */
3378 bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset);
3379 bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
3380
3381 /* Install dynamic relocations if needed. */
3382 if (!is_plt && info->shared)
3383 {
3384 unsigned int dyn_r_type;
3385
3386 if (bfd_big_endian (abfd))
3387 dyn_r_type = R_IA64_REL64MSB;
3388 else
3389 dyn_r_type = R_IA64_REL64LSB;
3390
3391 elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec,
3392 ia64_info->rel_pltoff_sec,
3393 dyn_i->pltoff_offset,
3394 dyn_r_type, 0, value);
3395 elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec,
3396 ia64_info->rel_pltoff_sec,
3397 dyn_i->pltoff_offset + 8,
3398 dyn_r_type, 0, gp);
3399 }
3400
3401 dyn_i->pltoff_done = 1;
3402 }
3403
3404 /* Return the descriptor's address. */
3405 value = (pltoff_sec->output_section->vma
3406 + pltoff_sec->output_offset
3407 + dyn_i->pltoff_offset);
3408
3409 return value;
3410 }
3411
3412 /* Return the base VMA address which should be subtracted from real addresses
3413 when resolving @tprel() relocation.
3414 Main program TLS (whose template starts at PT_TLS p_vaddr)
3415 is assigned offset round(16, PT_TLS p_align). */
3416
3417 static bfd_vma
3418 elfNN_ia64_tprel_base (info)
3419 struct bfd_link_info *info;
3420 {
3421 struct elf_link_tls_segment *tls_segment
3422 = elf_hash_table (info)->tls_segment;
3423
3424 BFD_ASSERT (tls_segment != NULL);
3425 return (tls_segment->start
3426 - align_power ((bfd_vma) 16, tls_segment->align));
3427 }
3428
3429 /* Return the base VMA address which should be subtracted from real addresses
3430 when resolving @dtprel() relocation.
3431 This is PT_TLS segment p_vaddr. */
3432
3433 static bfd_vma
3434 elfNN_ia64_dtprel_base (info)
3435 struct bfd_link_info *info;
3436 {
3437 BFD_ASSERT (elf_hash_table (info)->tls_segment != NULL);
3438 return elf_hash_table (info)->tls_segment->start;
3439 }
3440
3441 /* Called through qsort to sort the .IA_64.unwind section during a
3442 non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd
3443 to the output bfd so we can do proper endianness frobbing. */
3444
3445 static bfd *elfNN_ia64_unwind_entry_compare_bfd;
3446
3447 static int
3448 elfNN_ia64_unwind_entry_compare (a, b)
3449 const PTR a;
3450 const PTR b;
3451 {
3452 bfd_vma av, bv;
3453
3454 av = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, a);
3455 bv = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, b);
3456
3457 return (av < bv ? -1 : av > bv ? 1 : 0);
3458 }
3459
3460 static boolean
3461 elfNN_ia64_final_link (abfd, info)
3462 bfd *abfd;
3463 struct bfd_link_info *info;
3464 {
3465 struct elfNN_ia64_link_hash_table *ia64_info;
3466 asection *unwind_output_sec;
3467
3468 ia64_info = elfNN_ia64_hash_table (info);
3469
3470 /* Make sure we've got ourselves a nice fat __gp value. */
3471 if (!info->relocateable)
3472 {
3473 bfd_vma min_vma = (bfd_vma) -1, max_vma = 0;
3474 bfd_vma min_short_vma = min_vma, max_short_vma = 0;
3475 struct elf_link_hash_entry *gp;
3476 bfd_vma gp_val;
3477 asection *os;
3478
3479 /* Find the min and max vma of all sections marked short. Also
3480 collect min and max vma of any type, for use in selecting a
3481 nice gp. */
3482 for (os = abfd->sections; os ; os = os->next)
3483 {
3484 bfd_vma lo, hi;
3485
3486 if ((os->flags & SEC_ALLOC) == 0)
3487 continue;
3488
3489 lo = os->vma;
3490 hi = os->vma + os->_raw_size;
3491 if (hi < lo)
3492 hi = (bfd_vma) -1;
3493
3494 if (min_vma > lo)
3495 min_vma = lo;
3496 if (max_vma < hi)
3497 max_vma = hi;
3498 if (os->flags & SEC_SMALL_DATA)
3499 {
3500 if (min_short_vma > lo)
3501 min_short_vma = lo;
3502 if (max_short_vma < hi)
3503 max_short_vma = hi;
3504 }
3505 }
3506
3507 /* See if the user wants to force a value. */
3508 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
3509 false, false);
3510
3511 if (gp
3512 && (gp->root.type == bfd_link_hash_defined
3513 || gp->root.type == bfd_link_hash_defweak))
3514 {
3515 asection *gp_sec = gp->root.u.def.section;
3516 gp_val = (gp->root.u.def.value
3517 + gp_sec->output_section->vma
3518 + gp_sec->output_offset);
3519 }
3520 else
3521 {
3522 /* Pick a sensible value. */
3523
3524 asection *got_sec = ia64_info->got_sec;
3525
3526 /* Start with just the address of the .got. */
3527 if (got_sec)
3528 gp_val = got_sec->output_section->vma;
3529 else if (max_short_vma != 0)
3530 gp_val = min_short_vma;
3531 else
3532 gp_val = min_vma;
3533
3534 /* If it is possible to address the entire image, but we
3535 don't with the choice above, adjust. */
3536 if (max_vma - min_vma < 0x400000
3537 && max_vma - gp_val <= 0x200000
3538 && gp_val - min_vma > 0x200000)
3539 gp_val = min_vma + 0x200000;
3540 else if (max_short_vma != 0)
3541 {
3542 /* If we don't cover all the short data, adjust. */
3543 if (max_short_vma - gp_val >= 0x200000)
3544 gp_val = min_short_vma + 0x200000;
3545
3546 /* If we're addressing stuff past the end, adjust back. */
3547 if (gp_val > max_vma)
3548 gp_val = max_vma - 0x200000 + 8;
3549 }
3550 }
3551
3552 /* Validate whether all SHF_IA_64_SHORT sections are within
3553 range of the chosen GP. */
3554
3555 if (max_short_vma != 0)
3556 {
3557 if (max_short_vma - min_short_vma >= 0x400000)
3558 {
3559 (*_bfd_error_handler)
3560 (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
3561 bfd_get_filename (abfd),
3562 (unsigned long) (max_short_vma - min_short_vma));
3563 return false;
3564 }
3565 else if ((gp_val > min_short_vma
3566 && gp_val - min_short_vma > 0x200000)
3567 || (gp_val < max_short_vma
3568 && max_short_vma - gp_val >= 0x200000))
3569 {
3570 (*_bfd_error_handler)
3571 (_("%s: __gp does not cover short data segment"),
3572 bfd_get_filename (abfd));
3573 return false;
3574 }
3575 }
3576
3577 _bfd_set_gp_value (abfd, gp_val);
3578
3579 if (gp)
3580 {
3581 gp->root.type = bfd_link_hash_defined;
3582 gp->root.u.def.value = gp_val;
3583 gp->root.u.def.section = bfd_abs_section_ptr;
3584 }
3585 }
3586
3587 /* If we're producing a final executable, we need to sort the contents
3588 of the .IA_64.unwind section. Force this section to be relocated
3589 into memory rather than written immediately to the output file. */
3590 unwind_output_sec = NULL;
3591 if (!info->relocateable)
3592 {
3593 asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind);
3594 if (s)
3595 {
3596 unwind_output_sec = s->output_section;
3597 unwind_output_sec->contents
3598 = bfd_malloc (unwind_output_sec->_raw_size);
3599 if (unwind_output_sec->contents == NULL)
3600 return false;
3601 }
3602 }
3603
3604 /* Invoke the regular ELF backend linker to do all the work. */
3605 if (!bfd_elfNN_bfd_final_link (abfd, info))
3606 return false;
3607
3608 if (unwind_output_sec)
3609 {
3610 elfNN_ia64_unwind_entry_compare_bfd = abfd;
3611 qsort (unwind_output_sec->contents,
3612 (size_t) (unwind_output_sec->_raw_size / 24),
3613 24,
3614 elfNN_ia64_unwind_entry_compare);
3615
3616 if (! bfd_set_section_contents (abfd, unwind_output_sec,
3617 unwind_output_sec->contents, (bfd_vma) 0,
3618 unwind_output_sec->_raw_size))
3619 return false;
3620 }
3621
3622 return true;
3623 }
3624
3625 static boolean
3626 elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
3627 contents, relocs, local_syms, local_sections)
3628 bfd *output_bfd;
3629 struct bfd_link_info *info;
3630 bfd *input_bfd;
3631 asection *input_section;
3632 bfd_byte *contents;
3633 Elf_Internal_Rela *relocs;
3634 Elf_Internal_Sym *local_syms;
3635 asection **local_sections;
3636 {
3637 struct elfNN_ia64_link_hash_table *ia64_info;
3638 Elf_Internal_Shdr *symtab_hdr;
3639 Elf_Internal_Rela *rel;
3640 Elf_Internal_Rela *relend;
3641 asection *srel;
3642 boolean ret_val = true; /* for non-fatal errors */
3643 bfd_vma gp_val;
3644
3645 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3646 ia64_info = elfNN_ia64_hash_table (info);
3647
3648 /* Infect various flags from the input section to the output section. */
3649 if (info->relocateable)
3650 {
3651 bfd_vma flags;
3652
3653 flags = elf_section_data(input_section)->this_hdr.sh_flags;
3654 flags &= SHF_IA_64_NORECOV;
3655
3656 elf_section_data(input_section->output_section)
3657 ->this_hdr.sh_flags |= flags;
3658 return true;
3659 }
3660
3661 gp_val = _bfd_get_gp_value (output_bfd);
3662 srel = get_reloc_section (input_bfd, ia64_info, input_section, false);
3663
3664 rel = relocs;
3665 relend = relocs + input_section->reloc_count;
3666 for (; rel < relend; ++rel)
3667 {
3668 struct elf_link_hash_entry *h;
3669 struct elfNN_ia64_dyn_sym_info *dyn_i;
3670 bfd_reloc_status_type r;
3671 reloc_howto_type *howto;
3672 unsigned long r_symndx;
3673 Elf_Internal_Sym *sym;
3674 unsigned int r_type;
3675 bfd_vma value;
3676 asection *sym_sec;
3677 bfd_byte *hit_addr;
3678 boolean dynamic_symbol_p;
3679 boolean undef_weak_ref;
3680
3681 r_type = ELFNN_R_TYPE (rel->r_info);
3682 if (r_type > R_IA64_MAX_RELOC_CODE)
3683 {
3684 (*_bfd_error_handler)
3685 (_("%s: unknown relocation type %d"),
3686 bfd_archive_filename (input_bfd), (int)r_type);
3687 bfd_set_error (bfd_error_bad_value);
3688 ret_val = false;
3689 continue;
3690 }
3691
3692 howto = lookup_howto (r_type);
3693 r_symndx = ELFNN_R_SYM (rel->r_info);
3694 h = NULL;
3695 sym = NULL;
3696 sym_sec = NULL;
3697 undef_weak_ref = false;
3698
3699 if (r_symndx < symtab_hdr->sh_info)
3700 {
3701 /* Reloc against local symbol. */
3702 sym = local_syms + r_symndx;
3703 sym_sec = local_sections[r_symndx];
3704 value = _bfd_elf_rela_local_sym (output_bfd, sym, sym_sec, rel);
3705 if ((sym_sec->flags & SEC_MERGE)
3706 && ELF_ST_TYPE (sym->st_info) == STT_SECTION
3707 && (elf_section_data (sym_sec)->sec_info_type
3708 == ELF_INFO_TYPE_MERGE))
3709 {
3710 struct elfNN_ia64_local_hash_entry *loc_h;
3711
3712 loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, false);
3713 if (loc_h && ! loc_h->sec_merge_done)
3714 {
3715 struct elfNN_ia64_dyn_sym_info *dynent;
3716 asection *msec;
3717
3718 for (dynent = loc_h->info; dynent; dynent = dynent->next)
3719 {
3720 msec = sym_sec;
3721 dynent->addend =
3722 _bfd_merged_section_offset (output_bfd, &msec,
3723 elf_section_data (msec)->
3724 sec_info,
3725 sym->st_value
3726 + dynent->addend,
3727 (bfd_vma) 0);
3728 dynent->addend -= sym->st_value;
3729 dynent->addend += msec->output_section->vma
3730 + msec->output_offset
3731 - sym_sec->output_section->vma
3732 - sym_sec->output_offset;
3733 }
3734 loc_h->sec_merge_done = 1;
3735 }
3736 }
3737 }
3738 else
3739 {
3740 long indx;
3741
3742 /* Reloc against global symbol. */
3743 indx = r_symndx - symtab_hdr->sh_info;
3744 h = elf_sym_hashes (input_bfd)[indx];
3745 while (h->root.type == bfd_link_hash_indirect
3746 || h->root.type == bfd_link_hash_warning)
3747 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3748
3749 value = 0;
3750 if (h->root.type == bfd_link_hash_defined
3751 || h->root.type == bfd_link_hash_defweak)
3752 {
3753 sym_sec = h->root.u.def.section;
3754
3755 /* Detect the cases that sym_sec->output_section is
3756 expected to be NULL -- all cases in which the symbol
3757 is defined in another shared module. This includes
3758 PLT relocs for which we've created a PLT entry and
3759 other relocs for which we're prepared to create
3760 dynamic relocations. */
3761 /* ??? Just accept it NULL and continue. */
3762
3763 if (sym_sec->output_section != NULL)
3764 {
3765 value = (h->root.u.def.value
3766 + sym_sec->output_section->vma
3767 + sym_sec->output_offset);
3768 }
3769 }
3770 else if (h->root.type == bfd_link_hash_undefweak)
3771 undef_weak_ref = true;
3772 else if (info->shared
3773 && (!info->symbolic || info->allow_shlib_undefined)
3774 && !info->no_undefined
3775 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3776 ;
3777 else
3778 {
3779 if (! ((*info->callbacks->undefined_symbol)
3780 (info, h->root.root.string, input_bfd,
3781 input_section, rel->r_offset,
3782 (!info->shared || info->no_undefined
3783 || ELF_ST_VISIBILITY (h->other)))))
3784 return false;
3785 ret_val = false;
3786 continue;
3787 }
3788 }
3789
3790 hit_addr = contents + rel->r_offset;
3791 value += rel->r_addend;
3792 dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info);
3793
3794 switch (r_type)
3795 {
3796 case R_IA64_NONE:
3797 case R_IA64_LDXMOV:
3798 continue;
3799
3800 case R_IA64_IMM14:
3801 case R_IA64_IMM22:
3802 case R_IA64_IMM64:
3803 case R_IA64_DIR32MSB:
3804 case R_IA64_DIR32LSB:
3805 case R_IA64_DIR64MSB:
3806 case R_IA64_DIR64LSB:
3807 /* Install a dynamic relocation for this reloc. */
3808 if ((dynamic_symbol_p || info->shared
3809 || (elfNN_ia64_aix_vec (info->hash->creator)
3810 /* Don't emit relocs for __GLOB_DATA_PTR on AIX. */
3811 && (!h || strcmp (h->root.root.string,
3812 "__GLOB_DATA_PTR") != 0)))
3813 && r_symndx != 0
3814 && (input_section->flags & SEC_ALLOC) != 0)
3815 {
3816 unsigned int dyn_r_type;
3817 long dynindx;
3818 bfd_vma addend;
3819
3820 BFD_ASSERT (srel != NULL);
3821
3822 /* If we don't need dynamic symbol lookup, find a
3823 matching RELATIVE relocation. */
3824 dyn_r_type = r_type;
3825 if (dynamic_symbol_p)
3826 {
3827 dynindx = h->dynindx;
3828 addend = rel->r_addend;
3829 value = 0;
3830 }
3831 else
3832 {
3833 switch (r_type)
3834 {
3835 case R_IA64_DIR32MSB:
3836 dyn_r_type = R_IA64_REL32MSB;
3837 break;
3838 case R_IA64_DIR32LSB:
3839 dyn_r_type = R_IA64_REL32LSB;
3840 break;
3841 case R_IA64_DIR64MSB:
3842 dyn_r_type = R_IA64_REL64MSB;
3843 break;
3844 case R_IA64_DIR64LSB:
3845 dyn_r_type = R_IA64_REL64LSB;
3846 break;
3847
3848 default:
3849 /* We can't represent this without a dynamic symbol.
3850 Adjust the relocation to be against an output
3851 section symbol, which are always present in the
3852 dynamic symbol table. */
3853 /* ??? People shouldn't be doing non-pic code in
3854 shared libraries. Hork. */
3855 (*_bfd_error_handler)
3856 (_("%s: linking non-pic code in a shared library"),
3857 bfd_archive_filename (input_bfd));
3858 ret_val = false;
3859 continue;
3860 }
3861 dynindx = 0;
3862 addend = value;
3863 }
3864
3865 if (elfNN_ia64_aix_vec (info->hash->creator))
3866 rel->r_addend = value;
3867 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
3868 srel, rel->r_offset, dyn_r_type,
3869 dynindx, addend);
3870 }
3871 /* FALLTHRU */
3872
3873 case R_IA64_LTV32MSB:
3874 case R_IA64_LTV32LSB:
3875 case R_IA64_LTV64MSB:
3876 case R_IA64_LTV64LSB:
3877 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
3878 break;
3879
3880 case R_IA64_GPREL22:
3881 case R_IA64_GPREL64I:
3882 case R_IA64_GPREL32MSB:
3883 case R_IA64_GPREL32LSB:
3884 case R_IA64_GPREL64MSB:
3885 case R_IA64_GPREL64LSB:
3886 if (dynamic_symbol_p)
3887 {
3888 (*_bfd_error_handler)
3889 (_("%s: @gprel relocation against dynamic symbol %s"),
3890 bfd_archive_filename (input_bfd), h->root.root.string);
3891 ret_val = false;
3892 continue;
3893 }
3894 value -= gp_val;
3895 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
3896 break;
3897
3898 case R_IA64_LTOFF22:
3899 case R_IA64_LTOFF22X:
3900 case R_IA64_LTOFF64I:
3901 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
3902 value = set_got_entry (input_bfd, info, dyn_i, (h ? h->dynindx : -1),
3903 rel->r_addend, value, R_IA64_DIR64LSB);
3904 value -= gp_val;
3905 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
3906 break;
3907
3908 case R_IA64_PLTOFF22:
3909 case R_IA64_PLTOFF64I:
3910 case R_IA64_PLTOFF64MSB:
3911 case R_IA64_PLTOFF64LSB:
3912 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
3913 value = set_pltoff_entry (output_bfd, info, dyn_i, value, false);
3914 value -= gp_val;
3915 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
3916 break;
3917
3918 case R_IA64_FPTR64I:
3919 case R_IA64_FPTR32MSB:
3920 case R_IA64_FPTR32LSB:
3921 case R_IA64_FPTR64MSB:
3922 case R_IA64_FPTR64LSB:
3923 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
3924 if (dyn_i->want_fptr)
3925 {
3926 if (!undef_weak_ref)
3927 value = set_fptr_entry (output_bfd, info, dyn_i, value);
3928 }
3929 else
3930 {
3931 long dynindx;
3932
3933 /* Otherwise, we expect the dynamic linker to create
3934 the entry. */
3935
3936 if (h)
3937 {
3938 if (h->dynindx != -1)
3939 dynindx = h->dynindx;
3940 else
3941 dynindx = (_bfd_elf_link_lookup_local_dynindx
3942 (info, h->root.u.def.section->owner,
3943 global_sym_index (h)));
3944 }
3945 else
3946 {
3947 dynindx = (_bfd_elf_link_lookup_local_dynindx
3948 (info, input_bfd, (long) r_symndx));
3949 }
3950
3951 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
3952 srel, rel->r_offset, r_type,
3953 dynindx, rel->r_addend);
3954 value = 0;
3955 }
3956
3957 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
3958 break;
3959
3960 case R_IA64_LTOFF_FPTR22:
3961 case R_IA64_LTOFF_FPTR64I:
3962 case R_IA64_LTOFF_FPTR32MSB:
3963 case R_IA64_LTOFF_FPTR32LSB:
3964 case R_IA64_LTOFF_FPTR64MSB:
3965 case R_IA64_LTOFF_FPTR64LSB:
3966 {
3967 long dynindx;
3968
3969 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
3970 if (dyn_i->want_fptr)
3971 {
3972 BFD_ASSERT (h == NULL || h->dynindx == -1)
3973 if (!undef_weak_ref)
3974 value = set_fptr_entry (output_bfd, info, dyn_i, value);
3975 dynindx = -1;
3976 }
3977 else
3978 {
3979 /* Otherwise, we expect the dynamic linker to create
3980 the entry. */
3981 if (h)
3982 {
3983 if (h->dynindx != -1)
3984 dynindx = h->dynindx;
3985 else
3986 dynindx = (_bfd_elf_link_lookup_local_dynindx
3987 (info, h->root.u.def.section->owner,
3988 global_sym_index (h)));
3989 }
3990 else
3991 dynindx = (_bfd_elf_link_lookup_local_dynindx
3992 (info, input_bfd, (long) r_symndx));
3993 value = 0;
3994 }
3995
3996 value = set_got_entry (output_bfd, info, dyn_i, dynindx,
3997 rel->r_addend, value, R_IA64_FPTR64LSB);
3998 value -= gp_val;
3999 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
4000 }
4001 break;
4002
4003 case R_IA64_PCREL32MSB:
4004 case R_IA64_PCREL32LSB:
4005 case R_IA64_PCREL64MSB:
4006 case R_IA64_PCREL64LSB:
4007 /* Install a dynamic relocation for this reloc. */
4008 if ((dynamic_symbol_p
4009 || elfNN_ia64_aix_vec (info->hash->creator))
4010 && r_symndx != 0)
4011 {
4012 BFD_ASSERT (srel != NULL);
4013
4014 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
4015 srel, rel->r_offset, r_type,
4016 h->dynindx, rel->r_addend);
4017 }
4018 goto finish_pcrel;
4019
4020 case R_IA64_PCREL21BI:
4021 case R_IA64_PCREL21F:
4022 case R_IA64_PCREL21M:
4023 /* ??? These two are only used for speculation fixup code.
4024 They should never be dynamic. */
4025 if (dynamic_symbol_p)
4026 {
4027 (*_bfd_error_handler)
4028 (_("%s: dynamic relocation against speculation fixup"),
4029 bfd_archive_filename (input_bfd));
4030 ret_val = false;
4031 continue;
4032 }
4033 if (undef_weak_ref)
4034 {
4035 (*_bfd_error_handler)
4036 (_("%s: speculation fixup against undefined weak symbol"),
4037 bfd_archive_filename (input_bfd));
4038 ret_val = false;
4039 continue;
4040 }
4041 goto finish_pcrel;
4042
4043 case R_IA64_PCREL21B:
4044 case R_IA64_PCREL60B:
4045 /* We should have created a PLT entry for any dynamic symbol. */
4046 dyn_i = NULL;
4047 if (h)
4048 dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
4049
4050 if (dyn_i && dyn_i->want_plt2)
4051 {
4052 /* Should have caught this earlier. */
4053 BFD_ASSERT (rel->r_addend == 0);
4054
4055 value = (ia64_info->plt_sec->output_section->vma
4056 + ia64_info->plt_sec->output_offset
4057 + dyn_i->plt2_offset);
4058 }
4059 else
4060 {
4061 /* Since there's no PLT entry, Validate that this is
4062 locally defined. */
4063 BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL);
4064
4065 /* If the symbol is undef_weak, we shouldn't be trying
4066 to call it. There's every chance that we'd wind up
4067 with an out-of-range fixup here. Don't bother setting
4068 any value at all. */
4069 if (undef_weak_ref)
4070 continue;
4071 }
4072 goto finish_pcrel;
4073
4074 case R_IA64_PCREL22:
4075 case R_IA64_PCREL64I:
4076 finish_pcrel:
4077 /* Make pc-relative. */
4078 value -= (input_section->output_section->vma
4079 + input_section->output_offset
4080 + rel->r_offset) & ~ (bfd_vma) 0x3;
4081 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
4082 break;
4083
4084 case R_IA64_SEGREL32MSB:
4085 case R_IA64_SEGREL32LSB:
4086 case R_IA64_SEGREL64MSB:
4087 case R_IA64_SEGREL64LSB:
4088 if (r_symndx == 0)
4089 {
4090 /* If the input section was discarded from the output, then
4091 do nothing. */
4092 r = bfd_reloc_ok;
4093 }
4094 else
4095 {
4096 struct elf_segment_map *m;
4097 Elf_Internal_Phdr *p;
4098
4099 /* Find the segment that contains the output_section. */
4100 for (m = elf_tdata (output_bfd)->segment_map,
4101 p = elf_tdata (output_bfd)->phdr;
4102 m != NULL;
4103 m = m->next, p++)
4104 {
4105 int i;
4106 for (i = m->count - 1; i >= 0; i--)
4107 if (m->sections[i] == sym_sec->output_section)
4108 break;
4109 if (i >= 0)
4110 break;
4111 }
4112
4113 if (m == NULL)
4114 {
4115 r = bfd_reloc_notsupported;
4116 }
4117 else
4118 {
4119 /* The VMA of the segment is the vaddr of the associated
4120 program header. */
4121 if (value > p->p_vaddr)
4122 value -= p->p_vaddr;
4123 else
4124 value = 0;
4125 r = elfNN_ia64_install_value (output_bfd, hit_addr, value,
4126 r_type);
4127 }
4128 break;
4129 }
4130
4131 case R_IA64_SECREL32MSB:
4132 case R_IA64_SECREL32LSB:
4133 case R_IA64_SECREL64MSB:
4134 case R_IA64_SECREL64LSB:
4135 /* Make output-section relative. */
4136 if (value > input_section->output_section->vma)
4137 value -= input_section->output_section->vma;
4138 else
4139 value = 0;
4140 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
4141 break;
4142
4143 case R_IA64_IPLTMSB:
4144 case R_IA64_IPLTLSB:
4145 /* Install a dynamic relocation for this reloc. */
4146 if ((dynamic_symbol_p || info->shared)
4147 && (input_section->flags & SEC_ALLOC) != 0)
4148 {
4149 BFD_ASSERT (srel != NULL);
4150
4151 /* If we don't need dynamic symbol lookup, install two
4152 RELATIVE relocations. */
4153 if (! dynamic_symbol_p)
4154 {
4155 unsigned int dyn_r_type;
4156
4157 if (r_type == R_IA64_IPLTMSB)
4158 dyn_r_type = R_IA64_REL64MSB;
4159 else
4160 dyn_r_type = R_IA64_REL64LSB;
4161
4162 elfNN_ia64_install_dyn_reloc (output_bfd, info,
4163 input_section,
4164 srel, rel->r_offset,
4165 dyn_r_type, 0, value);
4166 elfNN_ia64_install_dyn_reloc (output_bfd, info,
4167 input_section,
4168 srel, rel->r_offset + 8,
4169 dyn_r_type, 0, gp_val);
4170 }
4171 else
4172 elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section,
4173 srel, rel->r_offset, r_type,
4174 h->dynindx, rel->r_addend);
4175 }
4176
4177 if (r_type == R_IA64_IPLTMSB)
4178 r_type = R_IA64_DIR64MSB;
4179 else
4180 r_type = R_IA64_DIR64LSB;
4181 elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
4182 r = elfNN_ia64_install_value (output_bfd, hit_addr + 8, gp_val,
4183 r_type);
4184 break;
4185
4186 case R_IA64_TPREL14:
4187 case R_IA64_TPREL22:
4188 case R_IA64_TPREL64I:
4189 value -= elfNN_ia64_tprel_base (info);
4190 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
4191 break;
4192
4193 case R_IA64_DTPREL14:
4194 case R_IA64_DTPREL22:
4195 case R_IA64_DTPREL64I:
4196 value -= elfNN_ia64_dtprel_base (info);
4197 r = elfNN_ia64_install_value (output_bfd, hit_addr, value, r_type);
4198 break;
4199
4200 case R_IA64_LTOFF_TPREL22:
4201 case R_IA64_LTOFF_DTPMOD22:
4202 case R_IA64_LTOFF_DTPREL22:
4203 {
4204 int got_r_type;
4205
4206 switch (r_type)
4207 {
4208 default:
4209 case R_IA64_LTOFF_TPREL22:
4210 if (!dynamic_symbol_p && !info->shared)
4211 value -= elfNN_ia64_tprel_base (info);
4212 got_r_type = R_IA64_TPREL64LSB;
4213 break;
4214 case R_IA64_LTOFF_DTPMOD22:
4215 if (!dynamic_symbol_p && !info->shared)
4216 value = 1;
4217 got_r_type = R_IA64_DTPMOD64LSB;
4218 break;
4219 case R_IA64_LTOFF_DTPREL22:
4220 if (!dynamic_symbol_p)
4221 value -= elfNN_ia64_dtprel_base (info);
4222 got_r_type = R_IA64_DTPREL64LSB;
4223 break;
4224 }
4225 dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false);
4226 value = set_got_entry (input_bfd, info, dyn_i,
4227 (h ? h->dynindx : -1), rel->r_addend,
4228 value, got_r_type);
4229 value -= gp_val;
4230 r = elfNN_ia64_install_value (output_bfd, hit_addr, value,
4231 r_type);
4232 }
4233 break;
4234
4235 default:
4236 r = bfd_reloc_notsupported;
4237 break;
4238 }
4239
4240 switch (r)
4241 {
4242 case bfd_reloc_ok:
4243 break;
4244
4245 case bfd_reloc_undefined:
4246 /* This can happen for global table relative relocs if
4247 __gp is undefined. This is a panic situation so we
4248 don't try to continue. */
4249 (*info->callbacks->undefined_symbol)
4250 (info, "__gp", input_bfd, input_section, rel->r_offset, 1);
4251 return false;
4252
4253 case bfd_reloc_notsupported:
4254 {
4255 const char *name;
4256
4257 if (h)
4258 name = h->root.root.string;
4259 else
4260 {
4261 name = bfd_elf_string_from_elf_section (input_bfd,
4262 symtab_hdr->sh_link,
4263 sym->st_name);
4264 if (name == NULL)
4265 return false;
4266 if (*name == '\0')
4267 name = bfd_section_name (input_bfd, input_section);
4268 }
4269 if (!(*info->callbacks->warning) (info, _("unsupported reloc"),
4270 name, input_bfd,
4271 input_section, rel->r_offset))
4272 return false;
4273 ret_val = false;
4274 }
4275 break;
4276
4277 case bfd_reloc_dangerous:
4278 case bfd_reloc_outofrange:
4279 case bfd_reloc_overflow:
4280 default:
4281 {
4282 const char *name;
4283
4284 if (h)
4285 name = h->root.root.string;
4286 else
4287 {
4288 name = bfd_elf_string_from_elf_section (input_bfd,
4289 symtab_hdr->sh_link,
4290 sym->st_name);
4291 if (name == NULL)
4292 return false;
4293 if (*name == '\0')
4294 name = bfd_section_name (input_bfd, input_section);
4295 }
4296 if (!(*info->callbacks->reloc_overflow) (info, name,
4297 howto->name,
4298 (bfd_vma) 0,
4299 input_bfd,
4300 input_section,
4301 rel->r_offset))
4302 return false;
4303 ret_val = false;
4304 }
4305 break;
4306 }
4307 }
4308
4309 return ret_val;
4310 }
4311
4312 static boolean
4313 elfNN_ia64_finish_dynamic_symbol (output_bfd, info, h, sym)
4314 bfd *output_bfd;
4315 struct bfd_link_info *info;
4316 struct elf_link_hash_entry *h;
4317 Elf_Internal_Sym *sym;
4318 {
4319 struct elfNN_ia64_link_hash_table *ia64_info;
4320 struct elfNN_ia64_dyn_sym_info *dyn_i;
4321
4322 ia64_info = elfNN_ia64_hash_table (info);
4323 dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
4324
4325 /* Fill in the PLT data, if required. */
4326 if (dyn_i && dyn_i->want_plt)
4327 {
4328 Elf_Internal_Rela outrel;
4329 bfd_byte *loc;
4330 asection *plt_sec;
4331 bfd_vma plt_addr, pltoff_addr, gp_val, index;
4332 ElfNN_External_Rela *rel;
4333
4334 gp_val = _bfd_get_gp_value (output_bfd);
4335
4336 /* Initialize the minimal PLT entry. */
4337
4338 index = (dyn_i->plt_offset - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE;
4339 plt_sec = ia64_info->plt_sec;
4340 loc = plt_sec->contents + dyn_i->plt_offset;
4341
4342 memcpy (loc, plt_min_entry, PLT_MIN_ENTRY_SIZE);
4343 elfNN_ia64_install_value (output_bfd, loc, index, R_IA64_IMM22);
4344 elfNN_ia64_install_value (output_bfd, loc+2, -dyn_i->plt_offset,
4345 R_IA64_PCREL21B);
4346
4347 plt_addr = (plt_sec->output_section->vma
4348 + plt_sec->output_offset
4349 + dyn_i->plt_offset);
4350 pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, true);
4351
4352 /* Initialize the FULL PLT entry, if needed. */
4353 if (dyn_i->want_plt2)
4354 {
4355 loc = plt_sec->contents + dyn_i->plt2_offset;
4356
4357 memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE);
4358 elfNN_ia64_install_value (output_bfd, loc, pltoff_addr - gp_val,
4359 R_IA64_IMM22);
4360
4361 /* Mark the symbol as undefined, rather than as defined in the
4362 plt section. Leave the value alone. */
4363 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4364 first place. But perhaps elflink.h did some for us. */
4365 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4366 sym->st_shndx = SHN_UNDEF;
4367 }
4368
4369 /* Create the dynamic relocation. */
4370 outrel.r_offset = pltoff_addr;
4371 if (bfd_little_endian (output_bfd))
4372 outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTLSB);
4373 else
4374 outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTMSB);
4375 outrel.r_addend = 0;
4376
4377 /* This is fun. In the .IA_64.pltoff section, we've got entries
4378 that correspond both to real PLT entries, and those that
4379 happened to resolve to local symbols but need to be created
4380 to satisfy @pltoff relocations. The .rela.IA_64.pltoff
4381 relocations for the real PLT should come at the end of the
4382 section, so that they can be indexed by plt entry at runtime.
4383
4384 We emitted all of the relocations for the non-PLT @pltoff
4385 entries during relocate_section. So we can consider the
4386 existing sec->reloc_count to be the base of the array of
4387 PLT relocations. */
4388
4389 rel = (ElfNN_External_Rela *)ia64_info->rel_pltoff_sec->contents;
4390 rel += ia64_info->rel_pltoff_sec->reloc_count;
4391
4392 bfd_elfNN_swap_reloca_out (output_bfd, &outrel, rel + index);
4393 }
4394
4395 /* Mark some specially defined symbols as absolute. */
4396 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4397 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
4398 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4399 sym->st_shndx = SHN_ABS;
4400
4401 return true;
4402 }
4403
4404 static boolean
4405 elfNN_ia64_finish_dynamic_sections (abfd, info)
4406 bfd *abfd;
4407 struct bfd_link_info *info;
4408 {
4409 struct elfNN_ia64_link_hash_table *ia64_info;
4410 bfd *dynobj;
4411
4412 ia64_info = elfNN_ia64_hash_table (info);
4413 dynobj = ia64_info->root.dynobj;
4414
4415 if (elf_hash_table (info)->dynamic_sections_created)
4416 {
4417 ElfNN_External_Dyn *dyncon, *dynconend;
4418 asection *sdyn, *sgotplt;
4419 bfd_vma gp_val;
4420
4421 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4422 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
4423 BFD_ASSERT (sdyn != NULL);
4424 dyncon = (ElfNN_External_Dyn *) sdyn->contents;
4425 dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
4426
4427 gp_val = _bfd_get_gp_value (abfd);
4428
4429 for (; dyncon < dynconend; dyncon++)
4430 {
4431 Elf_Internal_Dyn dyn;
4432
4433 bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
4434
4435 switch (dyn.d_tag)
4436 {
4437 case DT_PLTGOT:
4438 dyn.d_un.d_ptr = gp_val;
4439 break;
4440
4441 case DT_PLTRELSZ:
4442 dyn.d_un.d_val = (ia64_info->minplt_entries
4443 * sizeof (ElfNN_External_Rela));
4444 break;
4445
4446 case DT_JMPREL:
4447 /* See the comment above in finish_dynamic_symbol. */
4448 dyn.d_un.d_ptr = (ia64_info->rel_pltoff_sec->output_section->vma
4449 + ia64_info->rel_pltoff_sec->output_offset
4450 + (ia64_info->rel_pltoff_sec->reloc_count
4451 * sizeof (ElfNN_External_Rela)));
4452 break;
4453
4454 case DT_IA_64_PLT_RESERVE:
4455 dyn.d_un.d_ptr = (sgotplt->output_section->vma
4456 + sgotplt->output_offset);
4457 break;
4458
4459 case DT_RELASZ:
4460 /* Do not have RELASZ include JMPREL. This makes things
4461 easier on ld.so. This is not what the rest of BFD set up. */
4462 dyn.d_un.d_val -= (ia64_info->minplt_entries
4463 * sizeof (ElfNN_External_Rela));
4464 break;
4465 }
4466
4467 bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon);
4468 }
4469
4470 /* Initialize the PLT0 entry */
4471 if (ia64_info->plt_sec)
4472 {
4473 bfd_byte *loc = ia64_info->plt_sec->contents;
4474 bfd_vma pltres;
4475
4476 memcpy (loc, plt_header, PLT_HEADER_SIZE);
4477
4478 pltres = (sgotplt->output_section->vma
4479 + sgotplt->output_offset
4480 - gp_val);
4481
4482 elfNN_ia64_install_value (abfd, loc+1, pltres, R_IA64_GPREL22);
4483 }
4484 }
4485
4486 return true;
4487 }
4488 \f
4489 /* ELF file flag handling: */
4490
4491 /* Function to keep IA-64 specific file flags. */
4492 static boolean
4493 elfNN_ia64_set_private_flags (abfd, flags)
4494 bfd *abfd;
4495 flagword flags;
4496 {
4497 BFD_ASSERT (!elf_flags_init (abfd)
4498 || elf_elfheader (abfd)->e_flags == flags);
4499
4500 elf_elfheader (abfd)->e_flags = flags;
4501 elf_flags_init (abfd) = true;
4502 return true;
4503 }
4504
4505 /* Merge backend specific data from an object file to the output
4506 object file when linking. */
4507 static boolean
4508 elfNN_ia64_merge_private_bfd_data (ibfd, obfd)
4509 bfd *ibfd, *obfd;
4510 {
4511 flagword out_flags;
4512 flagword in_flags;
4513 boolean ok = true;
4514
4515 /* Don't even pretend to support mixed-format linking. */
4516 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4517 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4518 return false;
4519
4520 in_flags = elf_elfheader (ibfd)->e_flags;
4521 out_flags = elf_elfheader (obfd)->e_flags;
4522
4523 if (! elf_flags_init (obfd))
4524 {
4525 elf_flags_init (obfd) = true;
4526 elf_elfheader (obfd)->e_flags = in_flags;
4527
4528 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4529 && bfd_get_arch_info (obfd)->the_default)
4530 {
4531 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
4532 bfd_get_mach (ibfd));
4533 }
4534
4535 return true;
4536 }
4537
4538 /* Check flag compatibility. */
4539 if (in_flags == out_flags)
4540 return true;
4541
4542 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4543 if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP))
4544 elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP;
4545
4546 if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL))
4547 {
4548 (*_bfd_error_handler)
4549 (_("%s: linking trap-on-NULL-dereference with non-trapping files"),
4550 bfd_archive_filename (ibfd));
4551
4552 bfd_set_error (bfd_error_bad_value);
4553 ok = false;
4554 }
4555 if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE))
4556 {
4557 (*_bfd_error_handler)
4558 (_("%s: linking big-endian files with little-endian files"),
4559 bfd_archive_filename (ibfd));
4560
4561 bfd_set_error (bfd_error_bad_value);
4562 ok = false;
4563 }
4564 if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64))
4565 {
4566 (*_bfd_error_handler)
4567 (_("%s: linking 64-bit files with 32-bit files"),
4568 bfd_archive_filename (ibfd));
4569
4570 bfd_set_error (bfd_error_bad_value);
4571 ok = false;
4572 }
4573 if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP))
4574 {
4575 (*_bfd_error_handler)
4576 (_("%s: linking constant-gp files with non-constant-gp files"),
4577 bfd_archive_filename (ibfd));
4578
4579 bfd_set_error (bfd_error_bad_value);
4580 ok = false;
4581 }
4582 if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP)
4583 != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
4584 {
4585 (*_bfd_error_handler)
4586 (_("%s: linking auto-pic files with non-auto-pic files"),
4587 bfd_archive_filename (ibfd));
4588
4589 bfd_set_error (bfd_error_bad_value);
4590 ok = false;
4591 }
4592
4593 return ok;
4594 }
4595
4596 static boolean
4597 elfNN_ia64_print_private_bfd_data (abfd, ptr)
4598 bfd *abfd;
4599 PTR ptr;
4600 {
4601 FILE *file = (FILE *) ptr;
4602 flagword flags = elf_elfheader (abfd)->e_flags;
4603
4604 BFD_ASSERT (abfd != NULL && ptr != NULL);
4605
4606 fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n",
4607 (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "",
4608 (flags & EF_IA_64_EXT) ? "EXT, " : "",
4609 (flags & EF_IA_64_BE) ? "BE, " : "LE, ",
4610 (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "",
4611 (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "",
4612 (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "",
4613 (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "",
4614 (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32");
4615
4616 _bfd_elf_print_private_bfd_data (abfd, ptr);
4617 return true;
4618 }
4619
4620 static enum elf_reloc_type_class
4621 elfNN_ia64_reloc_type_class (rela)
4622 const Elf_Internal_Rela *rela;
4623 {
4624 switch ((int) ELFNN_R_TYPE (rela->r_info))
4625 {
4626 case R_IA64_REL32MSB:
4627 case R_IA64_REL32LSB:
4628 case R_IA64_REL64MSB:
4629 case R_IA64_REL64LSB:
4630 return reloc_class_relative;
4631 case R_IA64_IPLTMSB:
4632 case R_IA64_IPLTLSB:
4633 return reloc_class_plt;
4634 case R_IA64_COPY:
4635 return reloc_class_copy;
4636 default:
4637 return reloc_class_normal;
4638 }
4639 }
4640
4641 static boolean
4642 elfNN_ia64_hpux_vec (const bfd_target *vec)
4643 {
4644 extern const bfd_target bfd_elfNN_ia64_hpux_big_vec;
4645 return (vec == & bfd_elfNN_ia64_hpux_big_vec);
4646 }
4647
4648 static void
4649 elfNN_hpux_post_process_headers (abfd, info)
4650 bfd *abfd;
4651 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4652 {
4653 Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
4654
4655 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX;
4656 i_ehdrp->e_ident[EI_ABIVERSION] = 1;
4657 }
4658
4659 boolean
4660 elfNN_hpux_backend_section_from_bfd_section (abfd, sec, retval)
4661 bfd *abfd ATTRIBUTE_UNUSED;
4662 asection *sec;
4663 int *retval;
4664 {
4665 if (bfd_is_com_section (sec))
4666 {
4667 *retval = SHN_IA_64_ANSI_COMMON;
4668 return true;
4669 }
4670 return false;
4671 }
4672 \f
4673 #define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec
4674 #define TARGET_LITTLE_NAME "elfNN-ia64-little"
4675 #define TARGET_BIG_SYM bfd_elfNN_ia64_big_vec
4676 #define TARGET_BIG_NAME "elfNN-ia64-big"
4677 #define ELF_ARCH bfd_arch_ia64
4678 #define ELF_MACHINE_CODE EM_IA_64
4679 #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */
4680 #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */
4681 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
4682
4683 #define elf_backend_section_from_shdr \
4684 elfNN_ia64_section_from_shdr
4685 #define elf_backend_section_flags \
4686 elfNN_ia64_section_flags
4687 #define elf_backend_fake_sections \
4688 elfNN_ia64_fake_sections
4689 #define elf_backend_final_write_processing \
4690 elfNN_ia64_final_write_processing
4691 #define elf_backend_add_symbol_hook \
4692 elfNN_ia64_add_symbol_hook
4693 #define elf_backend_additional_program_headers \
4694 elfNN_ia64_additional_program_headers
4695 #define elf_backend_modify_segment_map \
4696 elfNN_ia64_modify_segment_map
4697 #define elf_info_to_howto \
4698 elfNN_ia64_info_to_howto
4699
4700 #define bfd_elfNN_bfd_reloc_type_lookup \
4701 elfNN_ia64_reloc_type_lookup
4702 #define bfd_elfNN_bfd_is_local_label_name \
4703 elfNN_ia64_is_local_label_name
4704 #define bfd_elfNN_bfd_relax_section \
4705 elfNN_ia64_relax_section
4706
4707 /* Stuff for the BFD linker: */
4708 #define bfd_elfNN_bfd_link_hash_table_create \
4709 elfNN_ia64_hash_table_create
4710 #define elf_backend_create_dynamic_sections \
4711 elfNN_ia64_create_dynamic_sections
4712 #define elf_backend_check_relocs \
4713 elfNN_ia64_check_relocs
4714 #define elf_backend_adjust_dynamic_symbol \
4715 elfNN_ia64_adjust_dynamic_symbol
4716 #define elf_backend_size_dynamic_sections \
4717 elfNN_ia64_size_dynamic_sections
4718 #define elf_backend_relocate_section \
4719 elfNN_ia64_relocate_section
4720 #define elf_backend_finish_dynamic_symbol \
4721 elfNN_ia64_finish_dynamic_symbol
4722 #define elf_backend_finish_dynamic_sections \
4723 elfNN_ia64_finish_dynamic_sections
4724 #define bfd_elfNN_bfd_final_link \
4725 elfNN_ia64_final_link
4726
4727 #define bfd_elfNN_bfd_merge_private_bfd_data \
4728 elfNN_ia64_merge_private_bfd_data
4729 #define bfd_elfNN_bfd_set_private_flags \
4730 elfNN_ia64_set_private_flags
4731 #define bfd_elfNN_bfd_print_private_bfd_data \
4732 elfNN_ia64_print_private_bfd_data
4733
4734 #define elf_backend_plt_readonly 1
4735 #define elf_backend_want_plt_sym 0
4736 #define elf_backend_plt_alignment 5
4737 #define elf_backend_got_header_size 0
4738 #define elf_backend_plt_header_size PLT_HEADER_SIZE
4739 #define elf_backend_want_got_plt 1
4740 #define elf_backend_may_use_rel_p 1
4741 #define elf_backend_may_use_rela_p 1
4742 #define elf_backend_default_use_rela_p 1
4743 #define elf_backend_want_dynbss 0
4744 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
4745 #define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol
4746 #define elf_backend_reloc_type_class elfNN_ia64_reloc_type_class
4747 #define elf_backend_rela_normal 1
4748
4749 #include "elfNN-target.h"
4750
4751 /* AIX-specific vectors. */
4752
4753 #undef TARGET_LITTLE_SYM
4754 #define TARGET_LITTLE_SYM bfd_elfNN_ia64_aix_little_vec
4755 #undef TARGET_LITTLE_NAME
4756 #define TARGET_LITTLE_NAME "elfNN-ia64-aix-little"
4757 #undef TARGET_BIG_SYM
4758 #define TARGET_BIG_SYM bfd_elfNN_ia64_aix_big_vec
4759 #undef TARGET_BIG_NAME
4760 #define TARGET_BIG_NAME "elfNN-ia64-aix-big"
4761
4762 #undef elf_backend_add_symbol_hook
4763 #define elf_backend_add_symbol_hook elfNN_ia64_aix_add_symbol_hook
4764
4765 #undef bfd_elfNN_bfd_link_add_symbols
4766 #define bfd_elfNN_bfd_link_add_symbols elfNN_ia64_aix_link_add_symbols
4767
4768 #define elfNN_bed elfNN_ia64_aix_bed
4769
4770 #include "elfNN-target.h"
4771
4772 /* HPUX-specific vectors. */
4773
4774 #undef TARGET_LITTLE_SYM
4775 #undef TARGET_LITTLE_NAME
4776 #undef TARGET_BIG_SYM
4777 #define TARGET_BIG_SYM bfd_elfNN_ia64_hpux_big_vec
4778 #undef TARGET_BIG_NAME
4779 #define TARGET_BIG_NAME "elfNN-ia64-hpux-big"
4780
4781 /* We need to undo the AIX specific functions. */
4782
4783 #undef elf_backend_add_symbol_hook
4784 #define elf_backend_add_symbol_hook elfNN_ia64_add_symbol_hook
4785
4786 #undef bfd_elfNN_bfd_link_add_symbols
4787 #define bfd_elfNN_bfd_link_add_symbols _bfd_generic_link_add_symbols
4788
4789 /* These are HP-UX specific functions. */
4790
4791 #undef elf_backend_post_process_headers
4792 #define elf_backend_post_process_headers elfNN_hpux_post_process_headers
4793
4794 #undef elf_backend_section_from_bfd_section
4795 #define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section
4796
4797 #undef elf_backend_want_p_paddr_set_to_zero
4798 #define elf_backend_want_p_paddr_set_to_zero 1
4799
4800 #undef ELF_MAXPAGESIZE
4801 #define ELF_MAXPAGESIZE 0x1000 /* 1K */
4802
4803 #undef elfNN_bed
4804 #define elfNN_bed elfNN_ia64_hpux_bed
4805
4806 #include "elfNN-target.h"
4807
4808 #undef elf_backend_want_p_paddr_set_to_zero