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