1 /* IA-64 support for 64-bit ELF
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "opcode/ia64.h"
29 * THE RULES for all the stuff the linker creates --
31 * GOT Entries created in response to LTOFF or LTOFF_FPTR
32 * relocations. Dynamic relocs created for dynamic
33 * symbols in an application; REL relocs for locals
34 * in a shared library.
36 * FPTR The canonical function descriptor. Created for local
37 * symbols in applications. Descriptors for dynamic symbols
38 * and local symbols in shared libraries are created by
39 * ld.so. Thus there are no dynamic relocs against these
40 * objects. The FPTR relocs for such _are_ passed through
41 * to the dynamic relocation tables.
43 * FULL_PLT Created for a PCREL21B relocation against a dynamic symbol.
44 * Requires the creation of a PLTOFF entry. This does not
45 * require any dynamic relocations.
47 * PLTOFF Created by PLTOFF relocations. For local symbols, this
48 * is an alternate function descriptor, and in shared libraries
49 * requires two REL relocations. Note that this cannot be
50 * transformed into an FPTR relocation, since it must be in
51 * range of the GP. For dynamic symbols, this is a function
52 * descriptor for a MIN_PLT entry, and requires one IPLT reloc.
54 * MIN_PLT Created by PLTOFF entries against dynamic symbols. This
55 * does not reqire dynamic relocations.
58 #define USE_RELA /* we want RELA relocs, not REL */
60 #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0])))
62 typedef struct bfd_hash_entry
*(*new_hash_entry_func
)
63 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
65 /* In dynamically (linker-) created sections, we generally need to keep track
66 of the place a symbol or expression got allocated to. This is done via hash
67 tables that store entries of the following type. */
69 struct elfNN_ia64_dyn_sym_info
71 /* The addend for which this entry is relevant. */
74 /* Next addend in the list. */
75 struct elfNN_ia64_dyn_sym_info
*next
;
79 bfd_vma pltoff_offset
;
83 /* The symbol table entry, if any, that this was derrived from. */
84 struct elf_link_hash_entry
*h
;
86 /* Used to count non-got, non-plt relocations for delayed sizing
87 of relocation sections. */
88 struct elfNN_ia64_dyn_reloc_entry
90 struct elfNN_ia64_dyn_reloc_entry
*next
;
96 /* True when the section contents have been updated. */
97 unsigned got_done
: 1;
98 unsigned fptr_done
: 1;
99 unsigned pltoff_done
: 1;
101 /* True for the different kinds of linker data we want created. */
102 unsigned want_got
: 1;
103 unsigned want_fptr
: 1;
104 unsigned want_ltoff_fptr
: 1;
105 unsigned want_plt
: 1;
106 unsigned want_plt2
: 1;
107 unsigned want_pltoff
: 1;
110 struct elfNN_ia64_local_hash_entry
112 struct bfd_hash_entry root
;
113 struct elfNN_ia64_dyn_sym_info
*info
;
116 struct elfNN_ia64_local_hash_table
118 struct bfd_hash_table root
;
119 /* No additional fields for now. */
122 struct elfNN_ia64_link_hash_entry
124 struct elf_link_hash_entry root
;
125 struct elfNN_ia64_dyn_sym_info
*info
;
128 struct elfNN_ia64_link_hash_table
130 /* The main hash table */
131 struct elf_link_hash_table root
;
133 asection
*got_sec
; /* the linkage table section (or NULL) */
134 asection
*rel_got_sec
; /* dynamic relocation section for same */
135 asection
*fptr_sec
; /* function descriptor table (or NULL) */
136 asection
*plt_sec
; /* the primary plt section (or NULL) */
137 asection
*pltoff_sec
; /* private descriptors for plt (or NULL) */
138 asection
*rel_pltoff_sec
; /* dynamic relocation section for same */
140 bfd_size_type minplt_entries
; /* number of minplt entries */
142 struct elfNN_ia64_local_hash_table loc_hash_table
;
145 #define elfNN_ia64_hash_table(p) \
146 ((struct elfNN_ia64_link_hash_table *) ((p)->hash))
148 static bfd_reloc_status_type elfNN_ia64_reloc
149 PARAMS ((bfd
*abfd
, arelent
*reloc
, asymbol
*sym
, PTR data
,
150 asection
*input_section
, bfd
*output_bfd
, char **error_message
));
151 static reloc_howto_type
* lookup_howto
152 PARAMS ((unsigned int rtype
));
153 static reloc_howto_type
*elfNN_ia64_reloc_type_lookup
154 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type bfd_code
));
155 static void elfNN_ia64_info_to_howto
156 PARAMS ((bfd
*abfd
, arelent
*bfd_reloc
, ElfNN_Internal_Rela
*elf_reloc
));
157 static boolean elfNN_ia64_relax_section
158 PARAMS((bfd
*abfd
, asection
*sec
, struct bfd_link_info
*link_info
,
160 static boolean is_unwind_section_name
161 PARAMS ((const char *));
162 static boolean elfNN_ia64_section_from_shdr
163 PARAMS ((bfd
*, ElfNN_Internal_Shdr
*, char *));
164 static boolean elfNN_ia64_fake_sections
165 PARAMS ((bfd
*abfd
, ElfNN_Internal_Shdr
*hdr
, asection
*sec
));
166 static void elfNN_ia64_final_write_processing
167 PARAMS ((bfd
*abfd
, boolean linker
));
168 static boolean elfNN_ia64_add_symbol_hook
169 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, const Elf_Internal_Sym
*sym
,
170 const char **namep
, flagword
*flagsp
, asection
**secp
,
172 static boolean elfNN_ia64_aix_vec
173 PARAMS ((const bfd_target
*vec
));
174 static boolean elfNN_ia64_aix_add_symbol_hook
175 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, const Elf_Internal_Sym
*sym
,
176 const char **namep
, flagword
*flagsp
, asection
**secp
,
178 static boolean elfNN_ia64_aix_link_add_symbols
179 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
180 static int elfNN_ia64_additional_program_headers
181 PARAMS ((bfd
*abfd
));
182 static boolean elfNN_ia64_is_local_label_name
183 PARAMS ((bfd
*abfd
, const char *name
));
184 static boolean elfNN_ia64_dynamic_symbol_p
185 PARAMS ((struct elf_link_hash_entry
*h
, struct bfd_link_info
*info
));
186 static boolean elfNN_ia64_local_hash_table_init
187 PARAMS ((struct elfNN_ia64_local_hash_table
*ht
, bfd
*abfd
,
188 new_hash_entry_func
new));
189 static struct bfd_hash_entry
*elfNN_ia64_new_loc_hash_entry
190 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
191 const char *string
));
192 static struct bfd_hash_entry
*elfNN_ia64_new_elf_hash_entry
193 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
194 const char *string
));
195 static struct bfd_link_hash_table
*elfNN_ia64_hash_table_create
196 PARAMS ((bfd
*abfd
));
197 static struct elfNN_ia64_local_hash_entry
*elfNN_ia64_local_hash_lookup
198 PARAMS ((struct elfNN_ia64_local_hash_table
*table
, const char *string
,
199 boolean create
, boolean copy
));
200 static void elfNN_ia64_dyn_sym_traverse
201 PARAMS ((struct elfNN_ia64_link_hash_table
*ia64_info
,
202 boolean (*func
) (struct elfNN_ia64_dyn_sym_info
*, PTR
),
204 static boolean elfNN_ia64_create_dynamic_sections
205 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
206 static struct elfNN_ia64_dyn_sym_info
* get_dyn_sym_info
207 PARAMS ((struct elfNN_ia64_link_hash_table
*ia64_info
,
208 struct elf_link_hash_entry
*h
,
209 bfd
*abfd
, const Elf_Internal_Rela
*rel
, boolean create
));
210 static asection
*get_got
211 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
212 struct elfNN_ia64_link_hash_table
*ia64_info
));
213 static asection
*get_fptr
214 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
215 struct elfNN_ia64_link_hash_table
*ia64_info
));
216 static asection
*get_pltoff
217 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
218 struct elfNN_ia64_link_hash_table
*ia64_info
));
219 static asection
*get_reloc_section
220 PARAMS ((bfd
*abfd
, struct elfNN_ia64_link_hash_table
*ia64_info
,
221 asection
*sec
, boolean create
));
222 static boolean count_dyn_reloc
223 PARAMS ((bfd
*abfd
, struct elfNN_ia64_dyn_sym_info
*dyn_i
,
224 asection
*srel
, int type
));
225 static boolean elfNN_ia64_check_relocs
226 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
227 const Elf_Internal_Rela
*relocs
));
228 static boolean elfNN_ia64_adjust_dynamic_symbol
229 PARAMS ((struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
));
230 static unsigned long global_sym_index
231 PARAMS ((struct elf_link_hash_entry
*h
));
232 static boolean allocate_fptr
233 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
234 static boolean allocate_global_data_got
235 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
236 static boolean allocate_global_fptr_got
237 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
238 static boolean allocate_local_got
239 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
240 static boolean allocate_pltoff_entries
241 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
242 static boolean allocate_plt_entries
243 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
244 static boolean allocate_plt2_entries
245 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
246 static boolean allocate_dynrel_entries
247 PARAMS ((struct elfNN_ia64_dyn_sym_info
*dyn_i
, PTR data
));
248 static boolean elfNN_ia64_size_dynamic_sections
249 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
));
250 static bfd_reloc_status_type elfNN_ia64_install_value
251 PARAMS ((bfd
*abfd
, bfd_byte
*hit_addr
, bfd_vma val
, unsigned int r_type
));
252 static void elfNN_ia64_install_dyn_reloc
253 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
254 asection
*srel
, bfd_vma offset
, unsigned int type
,
255 long dynindx
, bfd_vma addend
));
256 static bfd_vma set_got_entry
257 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
258 struct elfNN_ia64_dyn_sym_info
*dyn_i
, long dynindx
,
259 bfd_vma addend
, bfd_vma value
, unsigned int dyn_r_type
));
260 static bfd_vma set_fptr_entry
261 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
262 struct elfNN_ia64_dyn_sym_info
*dyn_i
,
264 static bfd_vma set_pltoff_entry
265 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
266 struct elfNN_ia64_dyn_sym_info
*dyn_i
,
267 bfd_vma value
, boolean
));
268 static boolean elfNN_ia64_final_link
269 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
270 static boolean elfNN_ia64_relocate_section
271 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
, bfd
*input_bfd
,
272 asection
*input_section
, bfd_byte
*contents
,
273 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
274 asection
**local_sections
));
275 static boolean elfNN_ia64_finish_dynamic_symbol
276 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
,
277 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
278 static boolean elfNN_ia64_finish_dynamic_sections
279 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
280 static boolean elfNN_ia64_set_private_flags
281 PARAMS ((bfd
*abfd
, flagword flags
));
282 static boolean elfNN_ia64_copy_private_bfd_data
283 PARAMS ((bfd
*ibfd
, bfd
*obfd
));
284 static boolean elfNN_ia64_merge_private_bfd_data
285 PARAMS ((bfd
*ibfd
, bfd
*obfd
));
286 static boolean elfNN_ia64_print_private_bfd_data
287 PARAMS ((bfd
*abfd
, PTR ptr
));
289 /* ia64-specific relocation */
291 /* Perform a relocation. Not much to do here as all the hard work is
292 done in elfNN_ia64_final_link_relocate. */
293 static bfd_reloc_status_type
294 elfNN_ia64_reloc (abfd
, reloc
, sym
, data
, input_section
,
295 output_bfd
, error_message
)
296 bfd
*abfd ATTRIBUTE_UNUSED
;
298 asymbol
*sym ATTRIBUTE_UNUSED
;
299 PTR data ATTRIBUTE_UNUSED
;
300 asection
*input_section
;
302 char **error_message
;
306 reloc
->address
+= input_section
->output_offset
;
309 *error_message
= "Unsupported call to elfNN_ia64_reloc";
310 return bfd_reloc_notsupported
;
313 #define IA64_HOWTO(TYPE, NAME, SIZE, PCREL, IN) \
314 HOWTO (TYPE, 0, SIZE, 0, PCREL, 0, complain_overflow_signed, \
315 elfNN_ia64_reloc, NAME, false, 0, 0, IN)
317 /* This table has to be sorted according to increasing number of the
319 static reloc_howto_type ia64_howto_table
[] =
321 IA64_HOWTO (R_IA64_NONE
, "NONE", 0, false, true),
323 IA64_HOWTO (R_IA64_IMM14
, "IMM14", 0, false, true),
324 IA64_HOWTO (R_IA64_IMM22
, "IMM22", 0, false, true),
325 IA64_HOWTO (R_IA64_IMM64
, "IMM64", 0, false, true),
326 IA64_HOWTO (R_IA64_DIR32MSB
, "DIR32MSB", 2, false, true),
327 IA64_HOWTO (R_IA64_DIR32LSB
, "DIR32LSB", 2, false, true),
328 IA64_HOWTO (R_IA64_DIR64MSB
, "DIR64MSB", 4, false, true),
329 IA64_HOWTO (R_IA64_DIR64LSB
, "DIR64LSB", 4, false, true),
331 IA64_HOWTO (R_IA64_GPREL22
, "GPREL22", 0, false, true),
332 IA64_HOWTO (R_IA64_GPREL64I
, "GPREL64I", 0, false, true),
333 IA64_HOWTO (R_IA64_GPREL32MSB
, "GPREL32MSB", 2, false, true),
334 IA64_HOWTO (R_IA64_GPREL32LSB
, "GPREL32LSB", 2, false, true),
335 IA64_HOWTO (R_IA64_GPREL64MSB
, "GPREL64MSB", 4, false, true),
336 IA64_HOWTO (R_IA64_GPREL64LSB
, "GPREL64LSB", 4, false, true),
338 IA64_HOWTO (R_IA64_LTOFF22
, "LTOFF22", 0, false, true),
339 IA64_HOWTO (R_IA64_LTOFF64I
, "LTOFF64I", 0, false, true),
341 IA64_HOWTO (R_IA64_PLTOFF22
, "PLTOFF22", 0, false, true),
342 IA64_HOWTO (R_IA64_PLTOFF64I
, "PLTOFF64I", 0, false, true),
343 IA64_HOWTO (R_IA64_PLTOFF64MSB
, "PLTOFF64MSB", 4, false, true),
344 IA64_HOWTO (R_IA64_PLTOFF64LSB
, "PLTOFF64LSB", 4, false, true),
346 IA64_HOWTO (R_IA64_FPTR64I
, "FPTR64I", 0, false, true),
347 IA64_HOWTO (R_IA64_FPTR32MSB
, "FPTR32MSB", 2, false, true),
348 IA64_HOWTO (R_IA64_FPTR32LSB
, "FPTR32LSB", 2, false, true),
349 IA64_HOWTO (R_IA64_FPTR64MSB
, "FPTR64MSB", 4, false, true),
350 IA64_HOWTO (R_IA64_FPTR64LSB
, "FPTR64LSB", 4, false, true),
352 IA64_HOWTO (R_IA64_PCREL60B
, "PCREL60B", 0, true, true),
353 IA64_HOWTO (R_IA64_PCREL21B
, "PCREL21B", 0, true, true),
354 IA64_HOWTO (R_IA64_PCREL21M
, "PCREL21M", 0, true, true),
355 IA64_HOWTO (R_IA64_PCREL21F
, "PCREL21F", 0, true, true),
356 IA64_HOWTO (R_IA64_PCREL32MSB
, "PCREL32MSB", 2, true, true),
357 IA64_HOWTO (R_IA64_PCREL32LSB
, "PCREL32LSB", 2, true, true),
358 IA64_HOWTO (R_IA64_PCREL64MSB
, "PCREL64MSB", 4, true, true),
359 IA64_HOWTO (R_IA64_PCREL64LSB
, "PCREL64LSB", 4, true, true),
361 IA64_HOWTO (R_IA64_LTOFF_FPTR22
, "LTOFF_FPTR22", 0, false, true),
362 IA64_HOWTO (R_IA64_LTOFF_FPTR64I
, "LTOFF_FPTR64I", 0, false, true),
363 IA64_HOWTO (R_IA64_LTOFF_FPTR32MSB
, "LTOFF_FPTR32MSB", 2, false, true),
364 IA64_HOWTO (R_IA64_LTOFF_FPTR32LSB
, "LTOFF_FPTR32LSB", 2, false, true),
365 IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB
, "LTOFF_FPTR64MSB", 4, false, true),
366 IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB
, "LTOFF_FPTR64LSB", 4, false, true),
368 IA64_HOWTO (R_IA64_SEGREL32MSB
, "SEGREL32MSB", 2, false, true),
369 IA64_HOWTO (R_IA64_SEGREL32LSB
, "SEGREL32LSB", 2, false, true),
370 IA64_HOWTO (R_IA64_SEGREL64MSB
, "SEGREL64MSB", 4, false, true),
371 IA64_HOWTO (R_IA64_SEGREL64LSB
, "SEGREL64LSB", 4, false, true),
373 IA64_HOWTO (R_IA64_SECREL32MSB
, "SECREL32MSB", 2, false, true),
374 IA64_HOWTO (R_IA64_SECREL32LSB
, "SECREL32LSB", 2, false, true),
375 IA64_HOWTO (R_IA64_SECREL64MSB
, "SECREL64MSB", 4, false, true),
376 IA64_HOWTO (R_IA64_SECREL64LSB
, "SECREL64LSB", 4, false, true),
378 IA64_HOWTO (R_IA64_REL32MSB
, "REL32MSB", 2, false, true),
379 IA64_HOWTO (R_IA64_REL32LSB
, "REL32LSB", 2, false, true),
380 IA64_HOWTO (R_IA64_REL64MSB
, "REL64MSB", 4, false, true),
381 IA64_HOWTO (R_IA64_REL64LSB
, "REL64LSB", 4, false, true),
383 IA64_HOWTO (R_IA64_LTV32MSB
, "LTV32MSB", 2, false, true),
384 IA64_HOWTO (R_IA64_LTV32LSB
, "LTV32LSB", 2, false, true),
385 IA64_HOWTO (R_IA64_LTV64MSB
, "LTV64MSB", 4, false, true),
386 IA64_HOWTO (R_IA64_LTV64LSB
, "LTV64LSB", 4, false, true),
388 IA64_HOWTO (R_IA64_PCREL21BI
, "PCREL21BI", 0, true, true),
389 IA64_HOWTO (R_IA64_PCREL22
, "PCREL22", 0, true, true),
390 IA64_HOWTO (R_IA64_PCREL64I
, "PCREL64I", 0, true, true),
392 IA64_HOWTO (R_IA64_IPLTMSB
, "IPLTMSB", 4, false, true),
393 IA64_HOWTO (R_IA64_IPLTLSB
, "IPLTLSB", 4, false, true),
394 IA64_HOWTO (R_IA64_COPY
, "COPY", 4, false, true),
395 IA64_HOWTO (R_IA64_LTOFF22X
, "LTOFF22X", 0, false, true),
396 IA64_HOWTO (R_IA64_LDXMOV
, "LDXMOV", 0, false, true),
398 IA64_HOWTO (R_IA64_TPREL22
, "TPREL22", 0, false, false),
399 IA64_HOWTO (R_IA64_TPREL64MSB
, "TPREL64MSB", 8, false, false),
400 IA64_HOWTO (R_IA64_TPREL64LSB
, "TPREL64LSB", 8, false, false),
401 IA64_HOWTO (R_IA64_LTOFF_TP22
, "LTOFF_TP22", 0, false, false),
404 static unsigned char elf_code_to_howto_index
[R_IA64_MAX_RELOC_CODE
+ 1];
406 /* Given a BFD reloc type, return the matching HOWTO structure. */
408 static reloc_howto_type
*
412 static int inited
= 0;
419 memset (elf_code_to_howto_index
, 0xff, sizeof (elf_code_to_howto_index
));
420 for (i
= 0; i
< NELEMS (ia64_howto_table
); ++i
)
421 elf_code_to_howto_index
[ia64_howto_table
[i
].type
] = i
;
424 BFD_ASSERT (rtype
<= R_IA64_MAX_RELOC_CODE
);
425 i
= elf_code_to_howto_index
[rtype
];
426 if (i
>= NELEMS (ia64_howto_table
))
428 return ia64_howto_table
+ i
;
431 static reloc_howto_type
*
432 elfNN_ia64_reloc_type_lookup (abfd
, bfd_code
)
433 bfd
*abfd ATTRIBUTE_UNUSED
;
434 bfd_reloc_code_real_type bfd_code
;
440 case BFD_RELOC_NONE
: rtype
= R_IA64_NONE
; break;
442 case BFD_RELOC_IA64_IMM14
: rtype
= R_IA64_IMM14
; break;
443 case BFD_RELOC_IA64_IMM22
: rtype
= R_IA64_IMM22
; break;
444 case BFD_RELOC_IA64_IMM64
: rtype
= R_IA64_IMM64
; break;
446 case BFD_RELOC_IA64_DIR32MSB
: rtype
= R_IA64_DIR32MSB
; break;
447 case BFD_RELOC_IA64_DIR32LSB
: rtype
= R_IA64_DIR32LSB
; break;
448 case BFD_RELOC_IA64_DIR64MSB
: rtype
= R_IA64_DIR64MSB
; break;
449 case BFD_RELOC_IA64_DIR64LSB
: rtype
= R_IA64_DIR64LSB
; break;
451 case BFD_RELOC_IA64_GPREL22
: rtype
= R_IA64_GPREL22
; break;
452 case BFD_RELOC_IA64_GPREL64I
: rtype
= R_IA64_GPREL64I
; break;
453 case BFD_RELOC_IA64_GPREL32MSB
: rtype
= R_IA64_GPREL32MSB
; break;
454 case BFD_RELOC_IA64_GPREL32LSB
: rtype
= R_IA64_GPREL32LSB
; break;
455 case BFD_RELOC_IA64_GPREL64MSB
: rtype
= R_IA64_GPREL64MSB
; break;
456 case BFD_RELOC_IA64_GPREL64LSB
: rtype
= R_IA64_GPREL64LSB
; break;
458 case BFD_RELOC_IA64_LTOFF22
: rtype
= R_IA64_LTOFF22
; break;
459 case BFD_RELOC_IA64_LTOFF64I
: rtype
= R_IA64_LTOFF64I
; break;
461 case BFD_RELOC_IA64_PLTOFF22
: rtype
= R_IA64_PLTOFF22
; break;
462 case BFD_RELOC_IA64_PLTOFF64I
: rtype
= R_IA64_PLTOFF64I
; break;
463 case BFD_RELOC_IA64_PLTOFF64MSB
: rtype
= R_IA64_PLTOFF64MSB
; break;
464 case BFD_RELOC_IA64_PLTOFF64LSB
: rtype
= R_IA64_PLTOFF64LSB
; break;
465 case BFD_RELOC_IA64_FPTR64I
: rtype
= R_IA64_FPTR64I
; break;
466 case BFD_RELOC_IA64_FPTR32MSB
: rtype
= R_IA64_FPTR32MSB
; break;
467 case BFD_RELOC_IA64_FPTR32LSB
: rtype
= R_IA64_FPTR32LSB
; break;
468 case BFD_RELOC_IA64_FPTR64MSB
: rtype
= R_IA64_FPTR64MSB
; break;
469 case BFD_RELOC_IA64_FPTR64LSB
: rtype
= R_IA64_FPTR64LSB
; break;
471 case BFD_RELOC_IA64_PCREL21B
: rtype
= R_IA64_PCREL21B
; break;
472 case BFD_RELOC_IA64_PCREL21BI
: rtype
= R_IA64_PCREL21BI
; break;
473 case BFD_RELOC_IA64_PCREL21M
: rtype
= R_IA64_PCREL21M
; break;
474 case BFD_RELOC_IA64_PCREL21F
: rtype
= R_IA64_PCREL21F
; break;
475 case BFD_RELOC_IA64_PCREL22
: rtype
= R_IA64_PCREL22
; break;
476 case BFD_RELOC_IA64_PCREL60B
: rtype
= R_IA64_PCREL60B
; break;
477 case BFD_RELOC_IA64_PCREL64I
: rtype
= R_IA64_PCREL64I
; break;
478 case BFD_RELOC_IA64_PCREL32MSB
: rtype
= R_IA64_PCREL32MSB
; break;
479 case BFD_RELOC_IA64_PCREL32LSB
: rtype
= R_IA64_PCREL32LSB
; break;
480 case BFD_RELOC_IA64_PCREL64MSB
: rtype
= R_IA64_PCREL64MSB
; break;
481 case BFD_RELOC_IA64_PCREL64LSB
: rtype
= R_IA64_PCREL64LSB
; break;
483 case BFD_RELOC_IA64_LTOFF_FPTR22
: rtype
= R_IA64_LTOFF_FPTR22
; break;
484 case BFD_RELOC_IA64_LTOFF_FPTR64I
: rtype
= R_IA64_LTOFF_FPTR64I
; break;
485 case BFD_RELOC_IA64_LTOFF_FPTR32MSB
: rtype
= R_IA64_LTOFF_FPTR32MSB
; break;
486 case BFD_RELOC_IA64_LTOFF_FPTR32LSB
: rtype
= R_IA64_LTOFF_FPTR32LSB
; break;
487 case BFD_RELOC_IA64_LTOFF_FPTR64MSB
: rtype
= R_IA64_LTOFF_FPTR64MSB
; break;
488 case BFD_RELOC_IA64_LTOFF_FPTR64LSB
: rtype
= R_IA64_LTOFF_FPTR64LSB
; break;
490 case BFD_RELOC_IA64_SEGREL32MSB
: rtype
= R_IA64_SEGREL32MSB
; break;
491 case BFD_RELOC_IA64_SEGREL32LSB
: rtype
= R_IA64_SEGREL32LSB
; break;
492 case BFD_RELOC_IA64_SEGREL64MSB
: rtype
= R_IA64_SEGREL64MSB
; break;
493 case BFD_RELOC_IA64_SEGREL64LSB
: rtype
= R_IA64_SEGREL64LSB
; break;
495 case BFD_RELOC_IA64_SECREL32MSB
: rtype
= R_IA64_SECREL32MSB
; break;
496 case BFD_RELOC_IA64_SECREL32LSB
: rtype
= R_IA64_SECREL32LSB
; break;
497 case BFD_RELOC_IA64_SECREL64MSB
: rtype
= R_IA64_SECREL64MSB
; break;
498 case BFD_RELOC_IA64_SECREL64LSB
: rtype
= R_IA64_SECREL64LSB
; break;
500 case BFD_RELOC_IA64_REL32MSB
: rtype
= R_IA64_REL32MSB
; break;
501 case BFD_RELOC_IA64_REL32LSB
: rtype
= R_IA64_REL32LSB
; break;
502 case BFD_RELOC_IA64_REL64MSB
: rtype
= R_IA64_REL64MSB
; break;
503 case BFD_RELOC_IA64_REL64LSB
: rtype
= R_IA64_REL64LSB
; break;
505 case BFD_RELOC_IA64_LTV32MSB
: rtype
= R_IA64_LTV32MSB
; break;
506 case BFD_RELOC_IA64_LTV32LSB
: rtype
= R_IA64_LTV32LSB
; break;
507 case BFD_RELOC_IA64_LTV64MSB
: rtype
= R_IA64_LTV64MSB
; break;
508 case BFD_RELOC_IA64_LTV64LSB
: rtype
= R_IA64_LTV64LSB
; break;
510 case BFD_RELOC_IA64_IPLTMSB
: rtype
= R_IA64_IPLTMSB
; break;
511 case BFD_RELOC_IA64_IPLTLSB
: rtype
= R_IA64_IPLTLSB
; break;
512 case BFD_RELOC_IA64_COPY
: rtype
= R_IA64_COPY
; break;
513 case BFD_RELOC_IA64_LTOFF22X
: rtype
= R_IA64_LTOFF22X
; break;
514 case BFD_RELOC_IA64_LDXMOV
: rtype
= R_IA64_LDXMOV
; break;
516 case BFD_RELOC_IA64_TPREL22
: rtype
= R_IA64_TPREL22
; break;
517 case BFD_RELOC_IA64_TPREL64MSB
: rtype
= R_IA64_TPREL64MSB
; break;
518 case BFD_RELOC_IA64_TPREL64LSB
: rtype
= R_IA64_TPREL64LSB
; break;
519 case BFD_RELOC_IA64_LTOFF_TP22
: rtype
= R_IA64_LTOFF_TP22
; break;
523 return lookup_howto (rtype
);
526 /* Given a ELF reloc, return the matching HOWTO structure. */
529 elfNN_ia64_info_to_howto (abfd
, bfd_reloc
, elf_reloc
)
530 bfd
*abfd ATTRIBUTE_UNUSED
;
532 ElfNN_Internal_Rela
*elf_reloc
;
534 bfd_reloc
->howto
= lookup_howto (ELFNN_R_TYPE (elf_reloc
->r_info
));
537 #define PLT_HEADER_SIZE (3 * 16)
538 #define PLT_MIN_ENTRY_SIZE (1 * 16)
539 #define PLT_FULL_ENTRY_SIZE (2 * 16)
540 #define PLT_RESERVED_WORDS 3
542 static const bfd_byte plt_header
[PLT_HEADER_SIZE
] =
544 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */
545 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */
546 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
547 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */
548 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */
549 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
550 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */
551 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */
552 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
555 static const bfd_byte plt_min_entry
[PLT_MIN_ENTRY_SIZE
] =
557 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */
558 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */
559 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */
562 static const bfd_byte plt_full_entry
[PLT_FULL_ENTRY_SIZE
] =
564 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
565 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */
566 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
567 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
568 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
569 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
572 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
573 #define AIX_DYNAMIC_INTERPRETER "/usr/lib/ia64l64/libc.so.1"
574 #define DYNAMIC_INTERPRETER(abfd) \
575 (elfNN_ia64_aix_vec (abfd->xvec) ? AIX_DYNAMIC_INTERPRETER : ELF_DYNAMIC_INTERPRETER)
577 /* Select out of range branch fixup type. Note that Itanium does
578 not support brl, and so it gets emulated by the kernel. */
581 static const bfd_byte oor_brl
[16] =
583 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
584 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */
585 0x00, 0x00, 0x00, 0xc0
588 static const bfd_byte oor_ip
[48] =
590 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
591 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */
592 0x01, 0x00, 0x00, 0x60,
593 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */
594 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */
595 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */
596 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */
597 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
598 0x60, 0x00, 0x80, 0x00 /* br b6;; */
601 /* These functions do relaxation for IA-64 ELF.
603 This is primarily to support branches to targets out of range;
604 relaxation of R_IA64_LTOFF22X and R_IA64_LDXMOV not yet supported. */
607 elfNN_ia64_relax_section (abfd
, sec
, link_info
, again
)
610 struct bfd_link_info
*link_info
;
615 struct one_fixup
*next
;
621 Elf_Internal_Shdr
*symtab_hdr
;
622 Elf_Internal_Rela
*internal_relocs
;
623 Elf_Internal_Rela
*free_relocs
= NULL
;
624 Elf_Internal_Rela
*irel
, *irelend
;
626 bfd_byte
*free_contents
= NULL
;
627 ElfNN_External_Sym
*extsyms
;
628 ElfNN_External_Sym
*free_extsyms
= NULL
;
629 struct elfNN_ia64_link_hash_table
*ia64_info
;
630 struct one_fixup
*fixups
= NULL
;
631 boolean changed_contents
= false;
632 boolean changed_relocs
= false;
634 /* Assume we're not going to change any sizes, and we'll only need
638 /* Nothing to do if there are no relocations. */
639 if ((sec
->flags
& SEC_RELOC
) == 0
640 || sec
->reloc_count
== 0)
643 /* If this is the first time we have been called for this section,
644 initialize the cooked size. */
645 if (sec
->_cooked_size
== 0)
646 sec
->_cooked_size
= sec
->_raw_size
;
648 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
650 /* Load the relocations for this section. */
651 internal_relocs
= (_bfd_elfNN_link_read_relocs
652 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
653 link_info
->keep_memory
));
654 if (internal_relocs
== NULL
)
657 if (! link_info
->keep_memory
)
658 free_relocs
= internal_relocs
;
660 ia64_info
= elfNN_ia64_hash_table (link_info
);
661 irelend
= internal_relocs
+ sec
->reloc_count
;
663 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
664 if (ELFNN_R_TYPE (irel
->r_info
) == (int) R_IA64_PCREL21B
)
667 /* No branch-type relocations. */
670 if (free_relocs
!= NULL
)
675 /* Get the section contents. */
676 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
677 contents
= elf_section_data (sec
)->this_hdr
.contents
;
680 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
681 if (contents
== NULL
)
683 free_contents
= contents
;
685 if (! bfd_get_section_contents (abfd
, sec
, contents
,
686 (file_ptr
) 0, sec
->_raw_size
))
690 /* Read this BFD's symbols. */
691 if (symtab_hdr
->contents
!= NULL
)
692 extsyms
= (ElfNN_External_Sym
*) symtab_hdr
->contents
;
695 extsyms
= (ElfNN_External_Sym
*) bfd_malloc (symtab_hdr
->sh_size
);
698 free_extsyms
= extsyms
;
699 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
700 || (bfd_read (extsyms
, 1, symtab_hdr
->sh_size
, abfd
)
701 != symtab_hdr
->sh_size
))
705 for (; irel
< irelend
; irel
++)
707 bfd_vma symaddr
, reladdr
, trampoff
, toff
, roff
;
708 Elf_Internal_Sym isym
;
712 if (ELFNN_R_TYPE (irel
->r_info
) != (int) R_IA64_PCREL21B
)
715 /* Get the value of the symbol referred to by the reloc. */
716 if (ELFNN_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
718 /* A local symbol. */
719 bfd_elfNN_swap_symbol_in (abfd
,
720 extsyms
+ ELFNN_R_SYM (irel
->r_info
),
722 if (isym
.st_shndx
== SHN_UNDEF
)
723 continue; /* We can't do anthing with undefined symbols. */
724 else if (isym
.st_shndx
== SHN_ABS
)
725 tsec
= bfd_abs_section_ptr
;
726 else if (isym
.st_shndx
== SHN_COMMON
)
727 tsec
= bfd_com_section_ptr
;
728 else if (isym
.st_shndx
> 0 && isym
.st_shndx
< SHN_LORESERVE
)
729 tsec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
731 continue; /* who knows. */
733 toff
= isym
.st_value
;
738 struct elf_link_hash_entry
*h
;
739 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
741 indx
= ELFNN_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
742 h
= elf_sym_hashes (abfd
)[indx
];
743 BFD_ASSERT (h
!= NULL
);
745 while (h
->root
.type
== bfd_link_hash_indirect
746 || h
->root
.type
== bfd_link_hash_warning
)
747 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
749 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, irel
, false);
751 /* For branches to dynamic symbols, we're interested instead
752 in a branch to the PLT entry. */
753 if (dyn_i
&& dyn_i
->want_plt2
)
755 tsec
= ia64_info
->plt_sec
;
756 toff
= dyn_i
->plt2_offset
;
760 /* We can't do anthing with undefined symbols. */
761 if (h
->root
.type
== bfd_link_hash_undefined
762 || h
->root
.type
== bfd_link_hash_undefweak
)
765 tsec
= h
->root
.u
.def
.section
;
766 toff
= h
->root
.u
.def
.value
;
770 symaddr
= (tsec
->output_section
->vma
771 + tsec
->output_offset
775 roff
= irel
->r_offset
;
776 reladdr
= (sec
->output_section
->vma
780 /* If the branch is in range, no need to do anything. */
781 if ((bfd_signed_vma
) (symaddr
- reladdr
) >= -0x1000000
782 && (bfd_signed_vma
) (symaddr
- reladdr
) <= 0x0FFFFF0)
785 /* If the branch and target are in the same section, you've
786 got one honking big section and we can't help you. You'll
787 get an error message later. */
791 /* Look for an existing fixup to this address. */
792 for (f
= fixups
; f
; f
= f
->next
)
793 if (f
->tsec
== tsec
&& f
->toff
== toff
)
798 /* Two alternatives: If it's a branch to a PLT entry, we can
799 make a copy of the FULL_PLT entry. Otherwise, we'll have
800 to use a `brl' insn to get where we're going. */
804 if (tsec
== ia64_info
->plt_sec
)
805 size
= sizeof (plt_full_entry
);
809 size
= sizeof (oor_brl
);
811 size
= sizeof (oor_ip
);
815 /* Resize the current section to make room for the new branch. */
816 trampoff
= (sec
->_cooked_size
+ 15) & -16;
817 contents
= (bfd_byte
*) bfd_realloc (contents
, trampoff
+ size
);
818 if (contents
== NULL
)
820 sec
->_cooked_size
= trampoff
+ size
;
822 if (tsec
== ia64_info
->plt_sec
)
824 memcpy (contents
+ trampoff
, plt_full_entry
, size
);
826 /* Hijack the old relocation for use as the PLTOFF reloc. */
827 irel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (irel
->r_info
),
829 irel
->r_offset
= trampoff
;
834 memcpy (contents
+ trampoff
, oor_brl
, size
);
835 irel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (irel
->r_info
),
837 irel
->r_offset
= trampoff
+ 2;
839 memcpy (contents
+ trampoff
, oor_ip
, size
);
840 irel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (irel
->r_info
),
842 irel
->r_addend
-= 16;
843 irel
->r_offset
= trampoff
+ 2;
847 /* Record the fixup so we don't do it again this section. */
848 f
= (struct one_fixup
*) bfd_malloc (sizeof (*f
));
852 f
->trampoff
= trampoff
;
857 /* Nop out the reloc, since we're finalizing things here. */
858 irel
->r_info
= ELFNN_R_INFO (0, R_IA64_NONE
);
861 /* Fix up the existing branch to hit the trampoline. Hope like
862 hell this doesn't overflow too. */
863 if (elfNN_ia64_install_value (abfd
, contents
+ roff
,
864 f
->trampoff
- (roff
& -4),
865 R_IA64_PCREL21B
) != bfd_reloc_ok
)
868 changed_contents
= true;
869 changed_relocs
= true;
872 /* Clean up and go home. */
875 struct one_fixup
*f
= fixups
;
876 fixups
= fixups
->next
;
881 elf_section_data (sec
)->relocs
= internal_relocs
;
882 else if (free_relocs
!= NULL
)
885 if (changed_contents
)
886 elf_section_data (sec
)->this_hdr
.contents
= contents
;
887 else if (free_contents
!= NULL
)
889 if (! link_info
->keep_memory
)
890 free (free_contents
);
893 /* Cache the section contents for elf_link_input_bfd. */
894 elf_section_data (sec
)->this_hdr
.contents
= contents
;
898 if (free_extsyms
!= NULL
)
900 if (! link_info
->keep_memory
)
904 /* Cache the symbols for elf_link_input_bfd. */
905 symtab_hdr
->contents
= extsyms
;
909 *again
= changed_contents
|| changed_relocs
;
913 if (free_relocs
!= NULL
)
915 if (free_contents
!= NULL
)
916 free (free_contents
);
917 if (free_extsyms
!= NULL
)
922 /* Return true if NAME is an unwind table section name. */
924 static inline boolean
925 is_unwind_section_name (name
)
928 size_t len1
, len2
, len3
;
930 len1
= sizeof (ELF_STRING_ia64_unwind
) - 1;
931 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
932 len3
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
933 return ((strncmp (name
, ELF_STRING_ia64_unwind
, len1
) == 0
934 && strncmp (name
, ELF_STRING_ia64_unwind_info
, len2
) != 0)
935 || strncmp (name
, ELF_STRING_ia64_unwind_once
, len3
) == 0);
938 /* Handle an IA-64 specific section when reading an object file. This
939 is called when elfcode.h finds a section with an unknown type. */
942 elfNN_ia64_section_from_shdr (abfd
, hdr
, name
)
944 ElfNN_Internal_Shdr
*hdr
;
949 /* There ought to be a place to keep ELF backend specific flags, but
950 at the moment there isn't one. We just keep track of the
951 sections by their name, instead. Fortunately, the ABI gives
952 suggested names for all the MIPS specific sections, so we will
953 probably get away with this. */
954 switch (hdr
->sh_type
)
956 case SHT_IA_64_UNWIND
:
960 if (strcmp (name
, ELF_STRING_ia64_archext
) != 0)
968 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
970 newsect
= hdr
->bfd_section
;
975 /* Convert IA-64 specific section flags to bfd internal section flags. */
977 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
981 elfNN_ia64_section_flags (flags
, hdr
)
983 ElfNN_Internal_Shdr
*hdr
;
985 if (hdr
->sh_flags
& SHF_IA_64_SHORT
)
986 *flags
|= SEC_SMALL_DATA
;
991 /* Set the correct type for an IA-64 ELF section. We do this by the
992 section name, which is a hack, but ought to work. */
995 elfNN_ia64_fake_sections (abfd
, hdr
, sec
)
996 bfd
*abfd ATTRIBUTE_UNUSED
;
997 ElfNN_Internal_Shdr
*hdr
;
1000 register const char *name
;
1002 name
= bfd_get_section_name (abfd
, sec
);
1004 if (is_unwind_section_name (name
))
1006 /* We don't have the sections numbered at this point, so sh_info
1007 is set later, in elfNN_ia64_final_write_processing. */
1008 hdr
->sh_type
= SHT_IA_64_UNWIND
;
1009 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1011 else if (strcmp (name
, ELF_STRING_ia64_archext
) == 0)
1012 hdr
->sh_type
= SHT_IA_64_EXT
;
1013 else if (strcmp (name
, ".reloc") == 0)
1015 * This is an ugly, but unfortunately necessary hack that is
1016 * needed when producing EFI binaries on IA-64. It tells
1017 * elf.c:elf_fake_sections() not to consider ".reloc" as a section
1018 * containing ELF relocation info. We need this hack in order to
1019 * be able to generate ELF binaries that can be translated into
1020 * EFI applications (which are essentially COFF objects). Those
1021 * files contain a COFF ".reloc" section inside an ELFNN object,
1022 * which would normally cause BFD to segfault because it would
1023 * attempt to interpret this section as containing relocation
1024 * entries for section "oc". With this hack enabled, ".reloc"
1025 * will be treated as a normal data section, which will avoid the
1026 * segfault. However, you won't be able to create an ELFNN binary
1027 * with a section named "oc" that needs relocations, but that's
1028 * the kind of ugly side-effects you get when detecting section
1029 * types based on their names... In practice, this limitation is
1032 hdr
->sh_type
= SHT_PROGBITS
;
1034 if (sec
->flags
& SEC_SMALL_DATA
)
1035 hdr
->sh_flags
|= SHF_IA_64_SHORT
;
1040 /* The final processing done just before writing out an IA-64 ELF
1044 elfNN_ia64_final_write_processing (abfd
, linker
)
1046 boolean linker ATTRIBUTE_UNUSED
;
1048 Elf_Internal_Shdr
*hdr
;
1050 asection
*text_sect
, *s
;
1053 for (s
= abfd
->sections
; s
; s
= s
->next
)
1055 hdr
= &elf_section_data (s
)->this_hdr
;
1056 switch (hdr
->sh_type
)
1058 case SHT_IA_64_UNWIND
:
1059 /* See comments in gas/config/tc-ia64.c:dot_endp on why we
1061 sname
= bfd_get_section_name (abfd
, s
);
1062 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
1063 if (sname
&& strncmp (sname
, ELF_STRING_ia64_unwind
, len
) == 0)
1067 if (sname
[0] == '\0')
1068 /* .IA_64.unwind -> .text */
1069 text_sect
= bfd_get_section_by_name (abfd
, ".text");
1071 /* .IA_64.unwindFOO -> FOO */
1072 text_sect
= bfd_get_section_by_name (abfd
, sname
);
1075 && (len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1,
1076 strncmp (sname
, ELF_STRING_ia64_unwind_once
, len
)) == 0)
1078 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.t.FOO */
1079 size_t len2
= sizeof (".gnu.linkonce.t.") - 1;
1080 char *once_name
= alloca (len2
+ strlen (sname
) - len
+ 1);
1082 memcpy (once_name
, ".gnu.linkonce.t.", len2
);
1083 strcpy (once_name
+ len2
, sname
+ len
);
1084 text_sect
= bfd_get_section_by_name (abfd
, once_name
);
1087 /* last resort: fall back on .text */
1088 text_sect
= bfd_get_section_by_name (abfd
, ".text");
1092 /* The IA-64 processor-specific ABI requires setting
1093 sh_link to the unwind section, whereas HP-UX requires
1094 sh_info to do so. For maximum compatibility, we'll
1095 set both for now... */
1096 hdr
->sh_link
= elf_section_data (text_sect
)->this_idx
;
1097 hdr
->sh_info
= elf_section_data (text_sect
)->this_idx
;
1104 /* Hook called by the linker routine which adds symbols from an object
1105 file. We use it to put .comm items in .sbss, and not .bss. */
1108 elfNN_ia64_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1110 struct bfd_link_info
*info
;
1111 const Elf_Internal_Sym
*sym
;
1112 const char **namep ATTRIBUTE_UNUSED
;
1113 flagword
*flagsp ATTRIBUTE_UNUSED
;
1117 if (sym
->st_shndx
== SHN_COMMON
1118 && !info
->relocateable
1119 && sym
->st_size
<= (unsigned) bfd_get_gp_size (abfd
))
1121 /* Common symbols less than or equal to -G nn bytes are
1122 automatically put into .sbss. */
1124 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
1128 scomm
= bfd_make_section (abfd
, ".scommon");
1130 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
1132 | SEC_LINKER_CREATED
)))
1137 *valp
= sym
->st_size
;
1144 elfNN_ia64_aix_vec (const bfd_target
*vec
)
1146 extern const bfd_target bfd_elfNN_ia64_aix_little_vec
;
1147 extern const bfd_target bfd_elfNN_ia64_aix_big_vec
;
1149 return (/**/vec
== & bfd_elfNN_ia64_aix_little_vec
1150 || vec
== & bfd_elfNN_ia64_aix_big_vec
);
1153 /* Hook called by the linker routine which adds symbols from an object
1154 file. We use it to handle OS-specific symbols. */
1157 elfNN_ia64_aix_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1159 struct bfd_link_info
*info
;
1160 const Elf_Internal_Sym
*sym
;
1166 if (strcmp (*namep
, "__GLOB_DATA_PTR") == 0)
1168 /* Define __GLOB_DATA_PTR when it is encountered. This is expected to
1169 be a linker-defined symbol by the Aix C runtime startup code. IBM sez
1170 no one else should use it b/c it is undocumented. */
1171 struct elf_link_hash_entry
*h
;
1173 h
= (struct elf_link_hash_entry
*) bfd_link_hash_lookup (info
->hash
, *namep
, false, false, false);
1176 struct elf_backend_data
*bed
;
1177 struct elfNN_ia64_link_hash_table
*ia64_info
;
1179 bed
= get_elf_backend_data (abfd
);
1180 ia64_info
= elfNN_ia64_hash_table (info
);
1182 if (!(_bfd_generic_link_add_one_symbol
1183 (info
, abfd
, *namep
, BSF_GLOBAL
,
1184 bfd_get_section_by_name (abfd
, ".bss"),
1185 bed
->got_symbol_offset
, (const char *) NULL
, false,
1186 bed
->collect
, (struct bfd_link_hash_entry
**) &h
)))
1189 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1190 h
->type
= STT_OBJECT
;
1192 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1198 else if (sym
->st_shndx
== SHN_LOOS
)
1202 /* SHN_AIX_SYSCALL: Treat this as any other symbol. The special symbol
1203 is only relevant when compiling code for extended system calls.
1204 Replace the "special" section with .text, if possible.
1205 Note that these symbols are always assumed to be in .text. */
1206 for (i
= 1; i
< elf_elfheader (abfd
)->e_shnum
; i
++)
1208 asection
* sec
= bfd_section_from_elf_index (abfd
, i
);
1210 if (sec
&& strcmp (sec
->name
, ".text") == 0)
1218 *secp
= bfd_abs_section_ptr
;
1220 *valp
= sym
->st_size
;
1226 return elfNN_ia64_add_symbol_hook (abfd
, info
, sym
,
1227 namep
, flagsp
, secp
, valp
);
1232 elfNN_ia64_aix_link_add_symbols (abfd
, info
)
1234 struct bfd_link_info
*info
;
1236 /* Make sure dynamic sections are always created. */
1237 if (! elf_hash_table (info
)->dynamic_sections_created
1238 && abfd
->xvec
== info
->hash
->creator
)
1240 if (! bfd_elfNN_link_create_dynamic_sections (abfd
, info
))
1244 /* Now do the standard call. */
1245 return bfd_elfNN_bfd_link_add_symbols (abfd
, info
);
1248 /* Return the number of additional phdrs we will need. */
1251 elfNN_ia64_additional_program_headers (abfd
)
1257 /* See if we need a PT_IA_64_ARCHEXT segment. */
1258 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_archext
);
1259 if (s
&& (s
->flags
& SEC_LOAD
))
1262 /* Count how many PT_IA_64_UNWIND segments we need. */
1263 for (s
= abfd
->sections
; s
; s
= s
->next
)
1264 if (is_unwind_section_name(s
->name
) && (s
->flags
& SEC_LOAD
))
1271 elfNN_ia64_modify_segment_map (abfd
)
1274 struct elf_segment_map
*m
, **pm
;
1275 Elf_Internal_Shdr
*hdr
;
1278 /* If we need a PT_IA_64_ARCHEXT segment, it must come before
1279 all PT_LOAD segments. */
1280 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_archext
);
1281 if (s
&& (s
->flags
& SEC_LOAD
))
1283 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
1284 if (m
->p_type
== PT_IA_64_ARCHEXT
)
1288 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
1292 m
->p_type
= PT_IA_64_ARCHEXT
;
1296 /* We want to put it after the PHDR and INTERP segments. */
1297 pm
= &elf_tdata (abfd
)->segment_map
;
1299 && ((*pm
)->p_type
== PT_PHDR
1300 || (*pm
)->p_type
== PT_INTERP
))
1308 /* Install PT_IA_64_UNWIND segments, if needed. */
1309 for (s
= abfd
->sections
; s
; s
= s
->next
)
1311 hdr
= &elf_section_data (s
)->this_hdr
;
1312 if (hdr
->sh_type
!= SHT_IA_64_UNWIND
)
1315 if (s
&& (s
->flags
& SEC_LOAD
))
1317 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
1318 if (m
->p_type
== PT_IA_64_UNWIND
&& m
->sections
[0] == s
)
1323 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
1327 m
->p_type
= PT_IA_64_UNWIND
;
1332 /* We want to put it last. */
1333 pm
= &elf_tdata (abfd
)->segment_map
;
1341 /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of
1342 the input sections for each output section in the segment and testing
1343 for SHF_IA_64_NORECOV on each. */
1344 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
1345 if (m
->p_type
== PT_LOAD
)
1348 for (i
= m
->count
- 1; i
>= 0; --i
)
1350 struct bfd_link_order
*order
= m
->sections
[i
]->link_order_head
;
1353 if (order
->type
== bfd_indirect_link_order
)
1355 asection
*is
= order
->u
.indirect
.section
;
1356 bfd_vma flags
= elf_section_data(is
)->this_hdr
.sh_flags
;
1357 if (flags
& SHF_IA_64_NORECOV
)
1359 m
->p_flags
|= PF_IA_64_NORECOV
;
1363 order
= order
->next
;
1372 /* According to the Tahoe assembler spec, all labels starting with a
1376 elfNN_ia64_is_local_label_name (abfd
, name
)
1377 bfd
*abfd ATTRIBUTE_UNUSED
;
1380 return name
[0] == '.';
1383 /* Should we do dynamic things to this symbol? */
1386 elfNN_ia64_dynamic_symbol_p (h
, info
)
1387 struct elf_link_hash_entry
*h
;
1388 struct bfd_link_info
*info
;
1393 while (h
->root
.type
== bfd_link_hash_indirect
1394 || h
->root
.type
== bfd_link_hash_warning
)
1395 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1397 if (h
->dynindx
== -1)
1399 switch (ELF_ST_VISIBILITY (h
->other
))
1406 if (h
->root
.type
== bfd_link_hash_undefweak
1407 || h
->root
.type
== bfd_link_hash_defweak
)
1410 if ((info
->shared
&& !info
->symbolic
)
1411 || ((h
->elf_link_hash_flags
1412 & (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
))
1413 == (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
)))
1420 elfNN_ia64_local_hash_table_init (ht
, abfd
, new)
1421 struct elfNN_ia64_local_hash_table
*ht
;
1422 bfd
*abfd ATTRIBUTE_UNUSED
;
1423 new_hash_entry_func
new;
1425 memset (ht
, 0, sizeof (*ht
));
1426 return bfd_hash_table_init (&ht
->root
, new);
1429 static struct bfd_hash_entry
*
1430 elfNN_ia64_new_loc_hash_entry (entry
, table
, string
)
1431 struct bfd_hash_entry
*entry
;
1432 struct bfd_hash_table
*table
;
1435 struct elfNN_ia64_local_hash_entry
*ret
;
1436 ret
= (struct elfNN_ia64_local_hash_entry
*) entry
;
1438 /* Allocate the structure if it has not already been allocated by a
1441 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
1446 /* Initialize our local data. All zeros, and definitely easier
1447 than setting a handful of bit fields. */
1448 memset (ret
, 0, sizeof (*ret
));
1450 /* Call the allocation method of the superclass. */
1451 ret
= ((struct elfNN_ia64_local_hash_entry
*)
1452 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
1454 return (struct bfd_hash_entry
*) ret
;
1457 static struct bfd_hash_entry
*
1458 elfNN_ia64_new_elf_hash_entry (entry
, table
, string
)
1459 struct bfd_hash_entry
*entry
;
1460 struct bfd_hash_table
*table
;
1463 struct elfNN_ia64_link_hash_entry
*ret
;
1464 ret
= (struct elfNN_ia64_link_hash_entry
*) entry
;
1466 /* Allocate the structure if it has not already been allocated by a
1469 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
1474 /* Initialize our local data. All zeros, and definitely easier
1475 than setting a handful of bit fields. */
1476 memset (ret
, 0, sizeof (*ret
));
1478 /* Call the allocation method of the superclass. */
1479 ret
= ((struct elfNN_ia64_link_hash_entry
*)
1480 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1483 return (struct bfd_hash_entry
*) ret
;
1487 elfNN_ia64_hash_copy_indirect (xdir
, xind
)
1488 struct elf_link_hash_entry
*xdir
, *xind
;
1490 struct elfNN_ia64_link_hash_entry
*dir
, *ind
;
1492 dir
= (struct elfNN_ia64_link_hash_entry
*)xdir
;
1493 ind
= (struct elfNN_ia64_link_hash_entry
*)xind
;
1495 /* Copy down any references that we may have already seen to the
1496 symbol which just became indirect. */
1498 dir
->root
.elf_link_hash_flags
|=
1499 (ind
->root
.elf_link_hash_flags
1500 & (ELF_LINK_HASH_REF_DYNAMIC
1501 | ELF_LINK_HASH_REF_REGULAR
1502 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
1504 /* Copy over the got and plt data. This would have been done
1507 if (dir
->info
== NULL
)
1509 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1511 dir
->info
= dyn_i
= ind
->info
;
1514 /* Fix up the dyn_sym_info pointers to the global symbol. */
1515 for (; dyn_i
; dyn_i
= dyn_i
->next
)
1516 dyn_i
->h
= &dir
->root
;
1518 BFD_ASSERT (ind
->info
== NULL
);
1520 /* Copy over the dynindx. */
1522 if (dir
->root
.dynindx
== -1)
1524 dir
->root
.dynindx
= ind
->root
.dynindx
;
1525 dir
->root
.dynstr_index
= ind
->root
.dynstr_index
;
1526 ind
->root
.dynindx
= -1;
1527 ind
->root
.dynstr_index
= 0;
1529 BFD_ASSERT (ind
->root
.dynindx
== -1);
1533 elfNN_ia64_hash_hide_symbol (info
, xh
)
1534 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1535 struct elf_link_hash_entry
*xh
;
1537 struct elfNN_ia64_link_hash_entry
*h
;
1538 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1540 h
= (struct elfNN_ia64_link_hash_entry
*)xh
;
1542 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1543 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
1544 h
->root
.dynindx
= -1;
1546 for (dyn_i
= h
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1547 dyn_i
->want_plt2
= 0;
1550 /* Create the derived linker hash table. The IA-64 ELF port uses this
1551 derived hash table to keep information specific to the IA-64 ElF
1552 linker (without using static variables). */
1554 static struct bfd_link_hash_table
*
1555 elfNN_ia64_hash_table_create (abfd
)
1558 struct elfNN_ia64_link_hash_table
*ret
;
1560 ret
= bfd_alloc (abfd
, sizeof (*ret
));
1563 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1564 elfNN_ia64_new_elf_hash_entry
))
1566 bfd_release (abfd
, ret
);
1570 if (!elfNN_ia64_local_hash_table_init (&ret
->loc_hash_table
, abfd
,
1571 elfNN_ia64_new_loc_hash_entry
))
1573 return &ret
->root
.root
;
1576 /* Look up an entry in a Alpha ELF linker hash table. */
1578 static INLINE
struct elfNN_ia64_local_hash_entry
*
1579 elfNN_ia64_local_hash_lookup(table
, string
, create
, copy
)
1580 struct elfNN_ia64_local_hash_table
*table
;
1582 boolean create
, copy
;
1584 return ((struct elfNN_ia64_local_hash_entry
*)
1585 bfd_hash_lookup (&table
->root
, string
, create
, copy
));
1588 /* Traverse both local and global hash tables. */
1590 struct elfNN_ia64_dyn_sym_traverse_data
1592 boolean (*func
) PARAMS ((struct elfNN_ia64_dyn_sym_info
*, PTR
));
1597 elfNN_ia64_global_dyn_sym_thunk (xentry
, xdata
)
1598 struct bfd_hash_entry
*xentry
;
1601 struct elfNN_ia64_link_hash_entry
*entry
1602 = (struct elfNN_ia64_link_hash_entry
*) xentry
;
1603 struct elfNN_ia64_dyn_sym_traverse_data
*data
1604 = (struct elfNN_ia64_dyn_sym_traverse_data
*) xdata
;
1605 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1607 for (dyn_i
= entry
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1608 if (! (*data
->func
) (dyn_i
, data
->data
))
1614 elfNN_ia64_local_dyn_sym_thunk (xentry
, xdata
)
1615 struct bfd_hash_entry
*xentry
;
1618 struct elfNN_ia64_local_hash_entry
*entry
1619 = (struct elfNN_ia64_local_hash_entry
*) xentry
;
1620 struct elfNN_ia64_dyn_sym_traverse_data
*data
1621 = (struct elfNN_ia64_dyn_sym_traverse_data
*) xdata
;
1622 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1624 for (dyn_i
= entry
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1625 if (! (*data
->func
) (dyn_i
, data
->data
))
1631 elfNN_ia64_dyn_sym_traverse (ia64_info
, func
, data
)
1632 struct elfNN_ia64_link_hash_table
*ia64_info
;
1633 boolean (*func
) PARAMS ((struct elfNN_ia64_dyn_sym_info
*, PTR
));
1636 struct elfNN_ia64_dyn_sym_traverse_data xdata
;
1641 elf_link_hash_traverse (&ia64_info
->root
,
1642 elfNN_ia64_global_dyn_sym_thunk
, &xdata
);
1643 bfd_hash_traverse (&ia64_info
->loc_hash_table
.root
,
1644 elfNN_ia64_local_dyn_sym_thunk
, &xdata
);
1648 elfNN_ia64_create_dynamic_sections (abfd
, info
)
1650 struct bfd_link_info
*info
;
1652 struct elfNN_ia64_link_hash_table
*ia64_info
;
1655 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1658 ia64_info
= elfNN_ia64_hash_table (info
);
1660 ia64_info
->plt_sec
= bfd_get_section_by_name (abfd
, ".plt");
1661 ia64_info
->got_sec
= bfd_get_section_by_name (abfd
, ".got");
1664 flagword flags
= bfd_get_section_flags (abfd
, ia64_info
->got_sec
);
1665 bfd_set_section_flags (abfd
, ia64_info
->got_sec
, SEC_SMALL_DATA
| flags
);
1668 if (!get_pltoff (abfd
, info
, ia64_info
))
1671 s
= bfd_make_section(abfd
, ".rela.IA_64.pltoff");
1673 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1676 | SEC_LINKER_CREATED
1678 || !bfd_set_section_alignment (abfd
, s
, 3))
1680 ia64_info
->rel_pltoff_sec
= s
;
1682 s
= bfd_make_section(abfd
, ".rela.got");
1684 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1687 | SEC_LINKER_CREATED
1689 || !bfd_set_section_alignment (abfd
, s
, 3))
1691 ia64_info
->rel_got_sec
= s
;
1696 /* Find and/or create a descriptor for dynamic symbol info. This will
1697 vary based on global or local symbol, and the addend to the reloc. */
1699 static struct elfNN_ia64_dyn_sym_info
*
1700 get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, create
)
1701 struct elfNN_ia64_link_hash_table
*ia64_info
;
1702 struct elf_link_hash_entry
*h
;
1704 const Elf_Internal_Rela
*rel
;
1707 struct elfNN_ia64_dyn_sym_info
**pp
;
1708 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1709 bfd_vma addend
= rel
? rel
->r_addend
: 0;
1712 pp
= &((struct elfNN_ia64_link_hash_entry
*)h
)->info
;
1715 struct elfNN_ia64_local_hash_entry
*loc_h
;
1719 /* Construct a string for use in the elfNN_ia64_local_hash_table.
1720 The name describes what was once anonymous memory. */
1722 len
= sizeof (void*)*2 + 1 + sizeof (bfd_vma
)*4 + 1 + 1;
1723 len
+= 10; /* %p slop */
1725 addr_name
= alloca (len
);
1726 sprintf (addr_name
, "%p:%lx", (void *) abfd
, ELFNN_R_SYM (rel
->r_info
));
1728 /* Collect the canonical entry data for this address. */
1729 loc_h
= elfNN_ia64_local_hash_lookup (&ia64_info
->loc_hash_table
,
1730 addr_name
, create
, create
);
1736 for (dyn_i
= *pp
; dyn_i
&& dyn_i
->addend
!= addend
; dyn_i
= *pp
)
1739 if (dyn_i
== NULL
&& create
)
1741 dyn_i
= (struct elfNN_ia64_dyn_sym_info
*)
1742 bfd_zalloc (abfd
, sizeof *dyn_i
);
1744 dyn_i
->addend
= addend
;
1751 get_got (abfd
, info
, ia64_info
)
1753 struct bfd_link_info
*info
;
1754 struct elfNN_ia64_link_hash_table
*ia64_info
;
1759 got
= ia64_info
->got_sec
;
1764 dynobj
= ia64_info
->root
.dynobj
;
1766 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1767 if (!_bfd_elf_create_got_section (dynobj
, info
))
1770 got
= bfd_get_section_by_name (dynobj
, ".got");
1772 ia64_info
->got_sec
= got
;
1774 flags
= bfd_get_section_flags (abfd
, got
);
1775 bfd_set_section_flags (abfd
, got
, SEC_SMALL_DATA
| flags
);
1781 /* Create function descriptor section (.opd). This section is called .opd
1782 because it contains "official prodecure descriptors". The "official"
1783 refers to the fact that these descriptors are used when taking the address
1784 of a procedure, thus ensuring a unique address for each procedure. */
1787 get_fptr (abfd
, info
, ia64_info
)
1789 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1790 struct elfNN_ia64_link_hash_table
*ia64_info
;
1795 fptr
= ia64_info
->fptr_sec
;
1798 dynobj
= ia64_info
->root
.dynobj
;
1800 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1802 fptr
= bfd_make_section (dynobj
, ".opd");
1804 || !bfd_set_section_flags (dynobj
, fptr
,
1810 | SEC_LINKER_CREATED
))
1811 || !bfd_set_section_alignment (abfd
, fptr
, 4))
1817 ia64_info
->fptr_sec
= fptr
;
1824 get_pltoff (abfd
, info
, ia64_info
)
1826 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1827 struct elfNN_ia64_link_hash_table
*ia64_info
;
1832 pltoff
= ia64_info
->pltoff_sec
;
1835 dynobj
= ia64_info
->root
.dynobj
;
1837 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1839 pltoff
= bfd_make_section (dynobj
, ELF_STRING_ia64_pltoff
);
1841 || !bfd_set_section_flags (dynobj
, pltoff
,
1847 | SEC_LINKER_CREATED
))
1848 || !bfd_set_section_alignment (abfd
, pltoff
, 4))
1854 ia64_info
->pltoff_sec
= pltoff
;
1861 get_reloc_section (abfd
, ia64_info
, sec
, create
)
1863 struct elfNN_ia64_link_hash_table
*ia64_info
;
1867 const char *srel_name
;
1871 srel_name
= (bfd_elf_string_from_elf_section
1872 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1873 elf_section_data(sec
)->rel_hdr
.sh_name
));
1874 if (srel_name
== NULL
)
1877 BFD_ASSERT ((strncmp (srel_name
, ".rela", 5) == 0
1878 && strcmp (bfd_get_section_name (abfd
, sec
),
1880 || (strncmp (srel_name
, ".rel", 4) == 0
1881 && strcmp (bfd_get_section_name (abfd
, sec
),
1882 srel_name
+4) == 0));
1884 dynobj
= ia64_info
->root
.dynobj
;
1886 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1888 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
1889 if (srel
== NULL
&& create
)
1891 srel
= bfd_make_section (dynobj
, srel_name
);
1893 || !bfd_set_section_flags (dynobj
, srel
,
1898 | SEC_LINKER_CREATED
1900 || !bfd_set_section_alignment (dynobj
, srel
, 3))
1908 count_dyn_reloc (abfd
, dyn_i
, srel
, type
)
1910 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1914 struct elfNN_ia64_dyn_reloc_entry
*rent
;
1916 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
1917 if (rent
->srel
== srel
&& rent
->type
== type
)
1922 rent
= (struct elfNN_ia64_dyn_reloc_entry
*)
1923 bfd_alloc (abfd
, sizeof (*rent
));
1927 rent
->next
= dyn_i
->reloc_entries
;
1931 dyn_i
->reloc_entries
= rent
;
1939 elfNN_ia64_check_relocs (abfd
, info
, sec
, relocs
)
1941 struct bfd_link_info
*info
;
1943 const Elf_Internal_Rela
*relocs
;
1945 struct elfNN_ia64_link_hash_table
*ia64_info
;
1946 const Elf_Internal_Rela
*relend
;
1947 Elf_Internal_Shdr
*symtab_hdr
;
1948 const Elf_Internal_Rela
*rel
;
1949 asection
*got
, *fptr
, *srel
;
1951 if (info
->relocateable
)
1954 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1955 ia64_info
= elfNN_ia64_hash_table (info
);
1957 got
= fptr
= srel
= NULL
;
1959 relend
= relocs
+ sec
->reloc_count
;
1960 for (rel
= relocs
; rel
< relend
; ++rel
)
1969 NEED_LTOFF_FPTR
= 64,
1972 struct elf_link_hash_entry
*h
= NULL
;
1973 unsigned long r_symndx
= ELFNN_R_SYM (rel
->r_info
);
1974 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1976 boolean maybe_dynamic
;
1977 int dynrel_type
= R_IA64_NONE
;
1979 if (r_symndx
>= symtab_hdr
->sh_info
)
1981 /* We're dealing with a global symbol -- find its hash entry
1982 and mark it as being referenced. */
1983 long indx
= r_symndx
- symtab_hdr
->sh_info
;
1984 h
= elf_sym_hashes (abfd
)[indx
];
1985 while (h
->root
.type
== bfd_link_hash_indirect
1986 || h
->root
.type
== bfd_link_hash_warning
)
1987 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1989 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
1992 /* We can only get preliminary data on whether a symbol is
1993 locally or externally defined, as not all of the input files
1994 have yet been processed. Do something with what we know, as
1995 this may help reduce memory usage and processing time later. */
1996 maybe_dynamic
= false;
1997 if (h
&& ((info
->shared
&& ! info
->symbolic
)
1998 || ! (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
1999 || h
->root
.type
== bfd_link_hash_defweak
2000 || elfNN_ia64_aix_vec (abfd
->xvec
)))
2001 maybe_dynamic
= true;
2004 switch (ELFNN_R_TYPE (rel
->r_info
))
2006 case R_IA64_TPREL22
:
2007 case R_IA64_TPREL64MSB
:
2008 case R_IA64_TPREL64LSB
:
2009 case R_IA64_LTOFF_TP22
:
2012 case R_IA64_LTOFF_FPTR22
:
2013 case R_IA64_LTOFF_FPTR64I
:
2014 case R_IA64_LTOFF_FPTR32MSB
:
2015 case R_IA64_LTOFF_FPTR32LSB
:
2016 case R_IA64_LTOFF_FPTR64MSB
:
2017 case R_IA64_LTOFF_FPTR64LSB
:
2018 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
2021 case R_IA64_FPTR64I
:
2022 case R_IA64_FPTR32MSB
:
2023 case R_IA64_FPTR32LSB
:
2024 case R_IA64_FPTR64MSB
:
2025 case R_IA64_FPTR64LSB
:
2026 if (info
->shared
|| h
|| elfNN_ia64_aix_vec (abfd
->xvec
))
2027 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2029 need_entry
= NEED_FPTR
;
2030 dynrel_type
= R_IA64_FPTR64LSB
;
2033 case R_IA64_LTOFF22
:
2034 case R_IA64_LTOFF22X
:
2035 case R_IA64_LTOFF64I
:
2036 need_entry
= NEED_GOT
;
2039 case R_IA64_PLTOFF22
:
2040 case R_IA64_PLTOFF64I
:
2041 case R_IA64_PLTOFF64MSB
:
2042 case R_IA64_PLTOFF64LSB
:
2043 need_entry
= NEED_PLTOFF
;
2047 need_entry
|= NEED_MIN_PLT
;
2051 (*info
->callbacks
->warning
)
2052 (info
, _("@pltoff reloc against local symbol"), 0,
2057 case R_IA64_PCREL21B
:
2058 case R_IA64_PCREL60B
:
2059 /* Depending on where this symbol is defined, we may or may not
2060 need a full plt entry. Only skip if we know we'll not need
2061 the entry -- static or symbolic, and the symbol definition
2062 has already been seen. */
2063 if (maybe_dynamic
&& rel
->r_addend
== 0)
2064 need_entry
= NEED_FULL_PLT
;
2070 case R_IA64_DIR32MSB
:
2071 case R_IA64_DIR32LSB
:
2072 case R_IA64_DIR64MSB
:
2073 case R_IA64_DIR64LSB
:
2074 /* Shared objects will always need at least a REL relocation. */
2075 if (info
->shared
|| maybe_dynamic
2076 || (elfNN_ia64_aix_vec (abfd
->xvec
)
2077 && (!h
|| strcmp (h
->root
.root
.string
,
2078 "__GLOB_DATA_PTR") != 0)))
2079 need_entry
= NEED_DYNREL
;
2080 dynrel_type
= R_IA64_DIR64LSB
;
2083 case R_IA64_IPLTMSB
:
2084 case R_IA64_IPLTLSB
:
2085 /* Shared objects will always need at least a REL relocation. */
2086 if (info
->shared
|| maybe_dynamic
)
2087 need_entry
= NEED_DYNREL
;
2088 dynrel_type
= R_IA64_IPLTLSB
;
2091 case R_IA64_PCREL22
:
2092 case R_IA64_PCREL64I
:
2093 case R_IA64_PCREL32MSB
:
2094 case R_IA64_PCREL32LSB
:
2095 case R_IA64_PCREL64MSB
:
2096 case R_IA64_PCREL64LSB
:
2098 need_entry
= NEED_DYNREL
;
2099 dynrel_type
= R_IA64_PCREL64LSB
;
2106 if ((need_entry
& NEED_FPTR
) != 0
2109 (*info
->callbacks
->warning
)
2110 (info
, _("non-zero addend in @fptr reloc"), 0,
2114 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, true);
2116 /* Record whether or not this is a local symbol. */
2119 /* Create what's needed. */
2120 if (need_entry
& NEED_GOT
)
2124 got
= get_got (abfd
, info
, ia64_info
);
2128 dyn_i
->want_got
= 1;
2130 if (need_entry
& NEED_FPTR
)
2134 fptr
= get_fptr (abfd
, info
, ia64_info
);
2139 /* FPTRs for shared libraries are allocated by the dynamic
2140 linker. Make sure this local symbol will appear in the
2141 dynamic symbol table. */
2142 if (!h
&& (info
->shared
2143 /* AIX also needs one */
2144 || elfNN_ia64_aix_vec (abfd
->xvec
)))
2146 if (! (_bfd_elfNN_link_record_local_dynamic_symbol
2147 (info
, abfd
, r_symndx
)))
2151 dyn_i
->want_fptr
= 1;
2153 if (need_entry
& NEED_LTOFF_FPTR
)
2154 dyn_i
->want_ltoff_fptr
= 1;
2155 if (need_entry
& (NEED_MIN_PLT
| NEED_FULL_PLT
))
2157 if (!ia64_info
->root
.dynobj
)
2158 ia64_info
->root
.dynobj
= abfd
;
2159 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2160 dyn_i
->want_plt
= 1;
2162 if (need_entry
& NEED_FULL_PLT
)
2163 dyn_i
->want_plt2
= 1;
2164 if (need_entry
& NEED_PLTOFF
)
2165 dyn_i
->want_pltoff
= 1;
2166 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
2170 srel
= get_reloc_section (abfd
, ia64_info
, sec
, true);
2174 if (!count_dyn_reloc (abfd
, dyn_i
, srel
, dynrel_type
))
2182 struct elfNN_ia64_allocate_data
2184 struct bfd_link_info
*info
;
2188 /* For cleanliness, and potentially faster dynamic loading, allocate
2189 external GOT entries first. */
2192 allocate_global_data_got (dyn_i
, data
)
2193 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2196 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2199 && ! dyn_i
->want_fptr
2200 && (elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2201 || (elfNN_ia64_aix_vec (x
->info
->hash
->creator
)
2202 && (!dyn_i
->h
|| strcmp (dyn_i
->h
->root
.root
.string
,
2203 "__GLOB_DATA_PTR") != 0))))
2205 dyn_i
->got_offset
= x
->ofs
;
2211 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2214 allocate_global_fptr_got (dyn_i
, data
)
2215 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2218 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2222 && (elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2223 || elfNN_ia64_aix_vec (x
->info
->hash
->creator
)))
2225 dyn_i
->got_offset
= x
->ofs
;
2231 /* Lastly, allocate all the GOT entries for local data. */
2234 allocate_local_got (dyn_i
, data
)
2235 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2238 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2241 && ! (elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2242 || elfNN_ia64_aix_vec (x
->info
->hash
->creator
)))
2244 dyn_i
->got_offset
= x
->ofs
;
2250 /* Search for the index of a global symbol in it's defining object file. */
2252 static unsigned long
2253 global_sym_index (h
)
2254 struct elf_link_hash_entry
*h
;
2256 struct elf_link_hash_entry
**p
;
2259 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2260 || h
->root
.type
== bfd_link_hash_defweak
);
2262 obj
= h
->root
.u
.def
.section
->owner
;
2263 for (p
= elf_sym_hashes (obj
); *p
!= h
; ++p
)
2266 return p
- elf_sym_hashes (obj
) + elf_tdata (obj
)->symtab_hdr
.sh_info
;
2269 /* Allocate function descriptors. We can do these for every function
2270 in a main executable that is not exported. */
2273 allocate_fptr (dyn_i
, data
)
2274 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2277 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2279 if (dyn_i
->want_fptr
)
2281 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2284 while (h
->root
.type
== bfd_link_hash_indirect
2285 || h
->root
.type
== bfd_link_hash_warning
)
2286 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2289 /* AIX needs an FPTR in this case. */
2290 || (elfNN_ia64_aix_vec (x
->info
->hash
->creator
)
2292 || h
->root
.type
== bfd_link_hash_defined
2293 || h
->root
.type
== bfd_link_hash_defweak
)))
2295 if (h
&& h
->dynindx
== -1)
2297 BFD_ASSERT ((h
->root
.type
== bfd_link_hash_defined
)
2298 || (h
->root
.type
== bfd_link_hash_defweak
));
2300 if (!_bfd_elfNN_link_record_local_dynamic_symbol
2301 (x
->info
, h
->root
.u
.def
.section
->owner
,
2302 global_sym_index (h
)))
2306 dyn_i
->want_fptr
= 0;
2308 else if (h
== NULL
|| h
->dynindx
== -1)
2310 dyn_i
->fptr_offset
= x
->ofs
;
2314 dyn_i
->want_fptr
= 0;
2319 /* Allocate all the minimal PLT entries. */
2322 allocate_plt_entries (dyn_i
, data
)
2323 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2326 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2328 if (dyn_i
->want_plt
)
2330 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2333 while (h
->root
.type
== bfd_link_hash_indirect
2334 || h
->root
.type
== bfd_link_hash_warning
)
2335 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2337 /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */
2338 if (elfNN_ia64_dynamic_symbol_p (h
, x
->info
))
2340 bfd_size_type offset
= x
->ofs
;
2342 offset
= PLT_HEADER_SIZE
;
2343 dyn_i
->plt_offset
= offset
;
2344 x
->ofs
= offset
+ PLT_MIN_ENTRY_SIZE
;
2346 dyn_i
->want_pltoff
= 1;
2350 dyn_i
->want_plt
= 0;
2351 dyn_i
->want_plt2
= 0;
2357 /* Allocate all the full PLT entries. */
2360 allocate_plt2_entries (dyn_i
, data
)
2361 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2364 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2366 if (dyn_i
->want_plt2
)
2368 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2369 bfd_size_type ofs
= x
->ofs
;
2371 dyn_i
->plt2_offset
= ofs
;
2372 x
->ofs
= ofs
+ PLT_FULL_ENTRY_SIZE
;
2374 while (h
->root
.type
== bfd_link_hash_indirect
2375 || h
->root
.type
== bfd_link_hash_warning
)
2376 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2377 dyn_i
->h
->plt
.offset
= ofs
;
2382 /* Allocate all the PLTOFF entries requested by relocations and
2383 plt entries. We can't share space with allocated FPTR entries,
2384 because the latter are not necessarily addressable by the GP.
2385 ??? Relaxation might be able to determine that they are. */
2388 allocate_pltoff_entries (dyn_i
, data
)
2389 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2392 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2394 if (dyn_i
->want_pltoff
)
2396 dyn_i
->pltoff_offset
= x
->ofs
;
2402 /* Allocate dynamic relocations for those symbols that turned out
2406 allocate_dynrel_entries (dyn_i
, data
)
2407 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2410 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2411 struct elfNN_ia64_link_hash_table
*ia64_info
;
2412 struct elfNN_ia64_dyn_reloc_entry
*rent
;
2413 boolean dynamic_symbol
, shared
;
2415 ia64_info
= elfNN_ia64_hash_table (x
->info
);
2416 dynamic_symbol
= elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2417 || (elfNN_ia64_aix_vec (x
->info
->hash
->creator
)
2418 /* Don't allocate an entry for __GLOB_DATA_PTR */
2419 && (!dyn_i
->h
|| strcmp (dyn_i
->h
->root
.root
.string
,
2420 "__GLOB_DATA_PTR") != 0));
2421 shared
= x
->info
->shared
;
2423 /* Take care of the normal data relocations. */
2425 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
2427 int count
= rent
->count
;
2431 case R_IA64_FPTR64LSB
:
2432 /* Allocate one iff !want_fptr, which by this point will
2433 be true only if we're actually allocating one statically
2434 in the main executable. */
2435 if (dyn_i
->want_fptr
)
2438 case R_IA64_PCREL64LSB
:
2439 if (!dynamic_symbol
)
2442 case R_IA64_DIR64LSB
:
2443 if (!dynamic_symbol
&& !shared
)
2446 case R_IA64_IPLTLSB
:
2447 if (!dynamic_symbol
&& !shared
)
2449 /* Use two REL relocations for IPLT relocations
2450 against local symbols. */
2451 if (!dynamic_symbol
)
2457 rent
->srel
->_raw_size
+= sizeof (ElfNN_External_Rela
) * count
;
2460 /* Take care of the GOT and PLT relocations. */
2462 if (((dynamic_symbol
|| shared
) && dyn_i
->want_got
)
2463 || (dyn_i
->want_ltoff_fptr
&& dyn_i
->h
&& dyn_i
->h
->dynindx
!= -1))
2464 ia64_info
->rel_got_sec
->_raw_size
+= sizeof (ElfNN_External_Rela
);
2466 if (dyn_i
->want_pltoff
)
2468 bfd_size_type t
= 0;
2470 /* Dynamic symbols get one IPLT relocation. Local symbols in
2471 shared libraries get two REL relocations. Local symbols in
2472 main applications get nothing. */
2474 t
= sizeof (ElfNN_External_Rela
);
2476 t
= 2 * sizeof (ElfNN_External_Rela
);
2478 ia64_info
->rel_pltoff_sec
->_raw_size
+= t
;
2485 elfNN_ia64_adjust_dynamic_symbol (info
, h
)
2486 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2487 struct elf_link_hash_entry
*h
;
2489 /* ??? Undefined symbols with PLT entries should be re-defined
2490 to be the PLT entry. */
2492 /* If this is a weak symbol, and there is a real definition, the
2493 processor independent code will have arranged for us to see the
2494 real definition first, and we can just use the same value. */
2495 if (h
->weakdef
!= NULL
)
2497 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2498 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2499 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2500 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2504 /* If this is a reference to a symbol defined by a dynamic object which
2505 is not a function, we might allocate the symbol in our .dynbss section
2506 and allocate a COPY dynamic relocation.
2508 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
2515 elfNN_ia64_size_dynamic_sections (output_bfd
, info
)
2517 struct bfd_link_info
*info
;
2519 struct elfNN_ia64_allocate_data data
;
2520 struct elfNN_ia64_link_hash_table
*ia64_info
;
2523 boolean reltext
= false;
2524 boolean relplt
= false;
2526 dynobj
= elf_hash_table(info
)->dynobj
;
2527 ia64_info
= elfNN_ia64_hash_table (info
);
2528 BFD_ASSERT(dynobj
!= NULL
);
2531 /* Set the contents of the .interp section to the interpreter. */
2532 if (ia64_info
->root
.dynamic_sections_created
2535 sec
= bfd_get_section_by_name (dynobj
, ".interp");
2536 BFD_ASSERT (sec
!= NULL
);
2537 sec
->contents
= (bfd_byte
*) DYNAMIC_INTERPRETER (output_bfd
);
2538 sec
->_raw_size
= strlen (DYNAMIC_INTERPRETER (output_bfd
)) + 1;
2541 /* Allocate the GOT entries. */
2543 if (ia64_info
->got_sec
)
2546 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_global_data_got
, &data
);
2547 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_global_fptr_got
, &data
);
2548 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_local_got
, &data
);
2549 ia64_info
->got_sec
->_raw_size
= data
.ofs
;
2552 /* Allocate the FPTR entries. */
2554 if (ia64_info
->fptr_sec
)
2557 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_fptr
, &data
);
2558 ia64_info
->fptr_sec
->_raw_size
= data
.ofs
;
2561 /* Now that we've seen all of the input files, we can decide which
2562 symbols need plt entries. Allocate the minimal PLT entries first.
2563 We do this even though dynamic_sections_created may be false, because
2564 this has the side-effect of clearing want_plt and want_plt2. */
2567 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_plt_entries
, &data
);
2569 ia64_info
->minplt_entries
= 0;
2572 ia64_info
->minplt_entries
2573 = (data
.ofs
- PLT_HEADER_SIZE
) / PLT_MIN_ENTRY_SIZE
;
2576 /* Align the pointer for the plt2 entries. */
2577 data
.ofs
= (data
.ofs
+ 31) & -32;
2579 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_plt2_entries
, &data
);
2582 BFD_ASSERT (ia64_info
->root
.dynamic_sections_created
);
2584 ia64_info
->plt_sec
->_raw_size
= data
.ofs
;
2586 /* If we've got a .plt, we need some extra memory for the dynamic
2587 linker. We stuff these in .got.plt. */
2588 sec
= bfd_get_section_by_name (dynobj
, ".got.plt");
2589 sec
->_raw_size
= 8 * PLT_RESERVED_WORDS
;
2592 /* Allocate the PLTOFF entries. */
2594 if (ia64_info
->pltoff_sec
)
2597 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_pltoff_entries
, &data
);
2598 ia64_info
->pltoff_sec
->_raw_size
= data
.ofs
;
2601 if (ia64_info
->root
.dynamic_sections_created
)
2603 /* Allocate space for the dynamic relocations that turned out to be
2606 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_dynrel_entries
, &data
);
2609 /* We have now determined the sizes of the various dynamic sections.
2610 Allocate memory for them. */
2611 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2615 if (!(sec
->flags
& SEC_LINKER_CREATED
))
2618 /* If we don't need this section, strip it from the output file.
2619 There were several sections primarily related to dynamic
2620 linking that must be create before the linker maps input
2621 sections to output sections. The linker does that before
2622 bfd_elf_size_dynamic_sections is called, and it is that
2623 function which decides whether anything needs to go into
2626 strip
= (sec
->_raw_size
== 0);
2628 if (sec
== ia64_info
->got_sec
)
2630 else if (sec
== ia64_info
->rel_got_sec
)
2633 ia64_info
->rel_got_sec
= NULL
;
2635 /* We use the reloc_count field as a counter if we need to
2636 copy relocs into the output file. */
2637 sec
->reloc_count
= 0;
2639 else if (sec
== ia64_info
->fptr_sec
)
2642 ia64_info
->fptr_sec
= NULL
;
2644 else if (sec
== ia64_info
->plt_sec
)
2647 ia64_info
->plt_sec
= NULL
;
2649 else if (sec
== ia64_info
->pltoff_sec
)
2652 ia64_info
->pltoff_sec
= NULL
;
2654 else if (sec
== ia64_info
->rel_pltoff_sec
)
2657 ia64_info
->rel_pltoff_sec
= NULL
;
2661 /* We use the reloc_count field as a counter if we need to
2662 copy relocs into the output file. */
2663 sec
->reloc_count
= 0;
2670 /* It's OK to base decisions on the section name, because none
2671 of the dynobj section names depend upon the input files. */
2672 name
= bfd_get_section_name (dynobj
, sec
);
2674 if (strcmp (name
, ".got.plt") == 0)
2676 else if (strncmp (name
, ".rel", 4) == 0)
2680 const char *outname
;
2683 /* If this relocation section applies to a read only
2684 section, then we probably need a DT_TEXTREL entry. */
2685 outname
= bfd_get_section_name (output_bfd
,
2686 sec
->output_section
);
2687 if (outname
[4] == 'a')
2692 target
= bfd_get_section_by_name (output_bfd
, outname
);
2694 && (target
->flags
& SEC_READONLY
) != 0
2695 && (target
->flags
& SEC_ALLOC
) != 0)
2698 /* We use the reloc_count field as a counter if we need to
2699 copy relocs into the output file. */
2700 sec
->reloc_count
= 0;
2708 _bfd_strip_section_from_output (info
, sec
);
2711 /* Allocate memory for the section contents. */
2712 sec
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, sec
->_raw_size
);
2713 if (sec
->contents
== NULL
&& sec
->_raw_size
!= 0)
2718 if (elf_hash_table (info
)->dynamic_sections_created
)
2720 /* Add some entries to the .dynamic section. We fill in the values
2721 later (in finish_dynamic_sections) but we must add the entries now
2722 so that we get the correct size for the .dynamic section. */
2726 /* The DT_DEBUG entry is filled in by the dynamic linker and used
2728 if (!bfd_elfNN_add_dynamic_entry (info
, DT_DEBUG
, 0))
2732 if (! bfd_elfNN_add_dynamic_entry (info
, DT_IA_64_PLT_RESERVE
, 0))
2734 if (! bfd_elfNN_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2739 if (! bfd_elfNN_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2740 || ! bfd_elfNN_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2741 || ! bfd_elfNN_add_dynamic_entry (info
, DT_JMPREL
, 0))
2745 if (! bfd_elfNN_add_dynamic_entry (info
, DT_RELA
, 0)
2746 || ! bfd_elfNN_add_dynamic_entry (info
, DT_RELASZ
, 0)
2747 || ! bfd_elfNN_add_dynamic_entry (info
, DT_RELAENT
,
2748 sizeof (ElfNN_External_Rela
)))
2753 if (! bfd_elfNN_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2755 info
->flags
|= DF_TEXTREL
;
2759 /* ??? Perhaps force __gp local. */
2764 static bfd_reloc_status_type
2765 elfNN_ia64_install_value (abfd
, hit_addr
, val
, r_type
)
2769 unsigned int r_type
;
2771 const struct ia64_operand
*op
;
2772 int bigendian
= 0, shift
= 0;
2773 bfd_vma t0
, t1
, insn
, dword
;
2774 enum ia64_opnd opnd
;
2778 opnd
= IA64_OPND_NIL
;
2783 return bfd_reloc_ok
;
2785 /* Instruction relocations. */
2787 case R_IA64_IMM14
: opnd
= IA64_OPND_IMM14
; break;
2789 case R_IA64_PCREL21F
: opnd
= IA64_OPND_TGT25
; break;
2790 case R_IA64_PCREL21M
: opnd
= IA64_OPND_TGT25b
; break;
2791 case R_IA64_PCREL60B
: opnd
= IA64_OPND_TGT64
; break;
2792 case R_IA64_PCREL21B
:
2793 case R_IA64_PCREL21BI
:
2794 opnd
= IA64_OPND_TGT25c
;
2798 case R_IA64_GPREL22
:
2799 case R_IA64_LTOFF22
:
2800 case R_IA64_LTOFF22X
:
2801 case R_IA64_PLTOFF22
:
2802 case R_IA64_PCREL22
:
2803 case R_IA64_LTOFF_FPTR22
:
2804 opnd
= IA64_OPND_IMM22
;
2808 case R_IA64_GPREL64I
:
2809 case R_IA64_LTOFF64I
:
2810 case R_IA64_PLTOFF64I
:
2811 case R_IA64_PCREL64I
:
2812 case R_IA64_FPTR64I
:
2813 case R_IA64_LTOFF_FPTR64I
:
2814 opnd
= IA64_OPND_IMMU64
;
2817 /* Data relocations. */
2819 case R_IA64_DIR32MSB
:
2820 case R_IA64_GPREL32MSB
:
2821 case R_IA64_FPTR32MSB
:
2822 case R_IA64_PCREL32MSB
:
2823 case R_IA64_LTOFF_FPTR32MSB
:
2824 case R_IA64_SEGREL32MSB
:
2825 case R_IA64_SECREL32MSB
:
2826 case R_IA64_LTV32MSB
:
2827 size
= 4; bigendian
= 1;
2830 case R_IA64_DIR32LSB
:
2831 case R_IA64_GPREL32LSB
:
2832 case R_IA64_FPTR32LSB
:
2833 case R_IA64_PCREL32LSB
:
2834 case R_IA64_LTOFF_FPTR32LSB
:
2835 case R_IA64_SEGREL32LSB
:
2836 case R_IA64_SECREL32LSB
:
2837 case R_IA64_LTV32LSB
:
2838 size
= 4; bigendian
= 0;
2841 case R_IA64_DIR64MSB
:
2842 case R_IA64_GPREL64MSB
:
2843 case R_IA64_PLTOFF64MSB
:
2844 case R_IA64_FPTR64MSB
:
2845 case R_IA64_PCREL64MSB
:
2846 case R_IA64_LTOFF_FPTR64MSB
:
2847 case R_IA64_SEGREL64MSB
:
2848 case R_IA64_SECREL64MSB
:
2849 case R_IA64_LTV64MSB
:
2850 size
= 8; bigendian
= 1;
2853 case R_IA64_DIR64LSB
:
2854 case R_IA64_GPREL64LSB
:
2855 case R_IA64_PLTOFF64LSB
:
2856 case R_IA64_FPTR64LSB
:
2857 case R_IA64_PCREL64LSB
:
2858 case R_IA64_LTOFF_FPTR64LSB
:
2859 case R_IA64_SEGREL64LSB
:
2860 case R_IA64_SECREL64LSB
:
2861 case R_IA64_LTV64LSB
:
2862 size
= 8; bigendian
= 0;
2865 /* Unsupported / Dynamic relocations. */
2867 return bfd_reloc_notsupported
;
2872 case IA64_OPND_IMMU64
:
2873 hit_addr
-= (long) hit_addr
& 0x3;
2874 t0
= bfd_get_64 (abfd
, hit_addr
);
2875 t1
= bfd_get_64 (abfd
, hit_addr
+ 8);
2877 /* tmpl/s: bits 0.. 5 in t0
2878 slot 0: bits 5..45 in t0
2879 slot 1: bits 46..63 in t0, bits 0..22 in t1
2880 slot 2: bits 23..63 in t1 */
2882 /* First, clear the bits that form the 64 bit constant. */
2883 t0
&= ~(0x3ffffLL
<< 46);
2885 | (( (0x07fLL
<< 13) | (0x1ffLL
<< 27)
2886 | (0x01fLL
<< 22) | (0x001LL
<< 21)
2887 | (0x001LL
<< 36)) << 23));
2889 t0
|= ((val
>> 22) & 0x03ffffLL
) << 46; /* 18 lsbs of imm41 */
2890 t1
|= ((val
>> 40) & 0x7fffffLL
) << 0; /* 23 msbs of imm41 */
2891 t1
|= ( (((val
>> 0) & 0x07f) << 13) /* imm7b */
2892 | (((val
>> 7) & 0x1ff) << 27) /* imm9d */
2893 | (((val
>> 16) & 0x01f) << 22) /* imm5c */
2894 | (((val
>> 21) & 0x001) << 21) /* ic */
2895 | (((val
>> 63) & 0x001) << 36)) << 23; /* i */
2897 bfd_put_64 (abfd
, t0
, hit_addr
);
2898 bfd_put_64 (abfd
, t1
, hit_addr
+ 8);
2901 case IA64_OPND_TGT64
:
2902 hit_addr
-= (long) hit_addr
& 0x3;
2903 t0
= bfd_get_64 (abfd
, hit_addr
);
2904 t1
= bfd_get_64 (abfd
, hit_addr
+ 8);
2906 /* tmpl/s: bits 0.. 5 in t0
2907 slot 0: bits 5..45 in t0
2908 slot 1: bits 46..63 in t0, bits 0..22 in t1
2909 slot 2: bits 23..63 in t1 */
2911 /* First, clear the bits that form the 64 bit constant. */
2912 t0
&= ~(0x3ffffLL
<< 46);
2914 | ((1LL << 36 | 0xfffffLL
<< 13) << 23));
2917 t0
|= ((val
>> 20) & 0xffffLL
) << 2 << 46; /* 16 lsbs of imm39 */
2918 t1
|= ((val
>> 36) & 0x7fffffLL
) << 0; /* 23 msbs of imm39 */
2919 t1
|= ((((val
>> 0) & 0xfffffLL
) << 13) /* imm20b */
2920 | (((val
>> 59) & 0x1LL
) << 36)) << 23; /* i */
2922 bfd_put_64 (abfd
, t0
, hit_addr
);
2923 bfd_put_64 (abfd
, t1
, hit_addr
+ 8);
2927 switch ((long) hit_addr
& 0x3)
2929 case 0: shift
= 5; break;
2930 case 1: shift
= 14; hit_addr
+= 3; break;
2931 case 2: shift
= 23; hit_addr
+= 6; break;
2932 case 3: return bfd_reloc_notsupported
; /* shouldn't happen... */
2934 dword
= bfd_get_64 (abfd
, hit_addr
);
2935 insn
= (dword
>> shift
) & 0x1ffffffffffLL
;
2937 op
= elf64_ia64_operands
+ opnd
;
2938 err
= (*op
->insert
) (op
, val
, &insn
);
2940 return bfd_reloc_overflow
;
2942 dword
&= ~(0x1ffffffffffLL
<< shift
);
2943 dword
|= (insn
<< shift
);
2944 bfd_put_64 (abfd
, dword
, hit_addr
);
2948 /* A data relocation. */
2951 bfd_putb32 (val
, hit_addr
);
2953 bfd_putb64 (val
, hit_addr
);
2956 bfd_putl32 (val
, hit_addr
);
2958 bfd_putl64 (val
, hit_addr
);
2962 return bfd_reloc_ok
;
2966 elfNN_ia64_install_dyn_reloc (abfd
, info
, sec
, srel
, offset
, type
,
2969 struct bfd_link_info
*info
;
2977 Elf_Internal_Rela outrel
;
2979 outrel
.r_offset
= (sec
->output_section
->vma
2980 + sec
->output_offset
2983 BFD_ASSERT (dynindx
!= -1);
2984 outrel
.r_info
= ELFNN_R_INFO (dynindx
, type
);
2985 outrel
.r_addend
= addend
;
2987 if (elf_section_data (sec
)->stab_info
!= NULL
)
2989 /* This may be NULL for linker-generated relocations, as it is
2990 inconvenient to pass all the bits around. And this shouldn't
2992 BFD_ASSERT (info
!= NULL
);
2994 offset
= (_bfd_stab_section_offset
2995 (abfd
, &elf_hash_table (info
)->stab_info
, sec
,
2996 &elf_section_data (sec
)->stab_info
, offset
));
2997 if (offset
== (bfd_vma
) -1)
2999 /* Run for the hills. We shouldn't be outputting a relocation
3000 for this. So do what everyone else does and output a no-op. */
3001 outrel
.r_info
= ELFNN_R_INFO (0, R_IA64_NONE
);
3002 outrel
.r_addend
= 0;
3005 outrel
.r_offset
= offset
;
3008 bfd_elfNN_swap_reloca_out (abfd
, &outrel
,
3009 ((ElfNN_External_Rela
*) srel
->contents
3010 + srel
->reloc_count
++));
3011 BFD_ASSERT (sizeof (ElfNN_External_Rela
) * srel
->reloc_count
3012 <= srel
->_cooked_size
);
3015 /* Store an entry for target address TARGET_ADDR in the linkage table
3016 and return the gp-relative address of the linkage table entry. */
3019 set_got_entry (abfd
, info
, dyn_i
, dynindx
, addend
, value
, dyn_r_type
)
3021 struct bfd_link_info
*info
;
3022 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3026 unsigned int dyn_r_type
;
3028 struct elfNN_ia64_link_hash_table
*ia64_info
;
3031 ia64_info
= elfNN_ia64_hash_table (info
);
3032 got_sec
= ia64_info
->got_sec
;
3034 BFD_ASSERT ((dyn_i
->got_offset
& 7) == 0);
3036 if (! dyn_i
->got_done
)
3038 dyn_i
->got_done
= true;
3040 /* Store the target address in the linkage table entry. */
3041 bfd_put_64 (abfd
, value
, got_sec
->contents
+ dyn_i
->got_offset
);
3043 /* Install a dynamic relocation if needed. */
3045 || elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, info
)
3046 || elfNN_ia64_aix_vec (abfd
->xvec
)
3047 || (dynindx
!= -1 && dyn_r_type
== R_IA64_FPTR64LSB
))
3051 dyn_r_type
= R_IA64_REL64LSB
;
3056 if (bfd_big_endian (abfd
))
3060 case R_IA64_REL64LSB
:
3061 dyn_r_type
= R_IA64_REL64MSB
;
3063 case R_IA64_DIR64LSB
:
3064 dyn_r_type
= R_IA64_DIR64MSB
;
3066 case R_IA64_FPTR64LSB
:
3067 dyn_r_type
= R_IA64_FPTR64MSB
;
3075 elfNN_ia64_install_dyn_reloc (abfd
, NULL
, got_sec
,
3076 ia64_info
->rel_got_sec
,
3077 dyn_i
->got_offset
, dyn_r_type
,
3082 /* Return the address of the linkage table entry. */
3083 value
= (got_sec
->output_section
->vma
3084 + got_sec
->output_offset
3085 + dyn_i
->got_offset
);
3090 /* Fill in a function descriptor consisting of the function's code
3091 address and its global pointer. Return the descriptor's address. */
3094 set_fptr_entry (abfd
, info
, dyn_i
, value
)
3096 struct bfd_link_info
*info
;
3097 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3100 struct elfNN_ia64_link_hash_table
*ia64_info
;
3103 ia64_info
= elfNN_ia64_hash_table (info
);
3104 fptr_sec
= ia64_info
->fptr_sec
;
3106 if (!dyn_i
->fptr_done
)
3108 dyn_i
->fptr_done
= 1;
3110 /* Fill in the function descriptor. */
3111 bfd_put_64 (abfd
, value
, fptr_sec
->contents
+ dyn_i
->fptr_offset
);
3112 bfd_put_64 (abfd
, _bfd_get_gp_value (abfd
),
3113 fptr_sec
->contents
+ dyn_i
->fptr_offset
+ 8);
3116 /* Return the descriptor's address. */
3117 value
= (fptr_sec
->output_section
->vma
3118 + fptr_sec
->output_offset
3119 + dyn_i
->fptr_offset
);
3124 /* Fill in a PLTOFF entry consisting of the function's code address
3125 and its global pointer. Return the descriptor's address. */
3128 set_pltoff_entry (abfd
, info
, dyn_i
, value
, is_plt
)
3130 struct bfd_link_info
*info
;
3131 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3135 struct elfNN_ia64_link_hash_table
*ia64_info
;
3136 asection
*pltoff_sec
;
3138 ia64_info
= elfNN_ia64_hash_table (info
);
3139 pltoff_sec
= ia64_info
->pltoff_sec
;
3141 /* Don't do anything if this symbol uses a real PLT entry. In
3142 that case, we'll fill this in during finish_dynamic_symbol. */
3143 if ((! dyn_i
->want_plt
|| is_plt
)
3144 && !dyn_i
->pltoff_done
)
3146 bfd_vma gp
= _bfd_get_gp_value (abfd
);
3148 /* Fill in the function descriptor. */
3149 bfd_put_64 (abfd
, value
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
);
3150 bfd_put_64 (abfd
, gp
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
+ 8);
3152 /* Install dynamic relocations if needed. */
3153 if (!is_plt
&& info
->shared
)
3155 unsigned int dyn_r_type
;
3157 if (bfd_big_endian (abfd
))
3158 dyn_r_type
= R_IA64_REL64MSB
;
3160 dyn_r_type
= R_IA64_REL64LSB
;
3162 elfNN_ia64_install_dyn_reloc (abfd
, NULL
, pltoff_sec
,
3163 ia64_info
->rel_pltoff_sec
,
3164 dyn_i
->pltoff_offset
,
3165 dyn_r_type
, 0, value
);
3166 elfNN_ia64_install_dyn_reloc (abfd
, NULL
, pltoff_sec
,
3167 ia64_info
->rel_pltoff_sec
,
3168 dyn_i
->pltoff_offset
+ 8,
3172 dyn_i
->pltoff_done
= 1;
3175 /* Return the descriptor's address. */
3176 value
= (pltoff_sec
->output_section
->vma
3177 + pltoff_sec
->output_offset
3178 + dyn_i
->pltoff_offset
);
3183 /* Called through qsort to sort the .IA_64.unwind section during a
3184 non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd
3185 to the output bfd so we can do proper endianness frobbing. */
3187 static bfd
*elfNN_ia64_unwind_entry_compare_bfd
;
3190 elfNN_ia64_unwind_entry_compare (a
, b
)
3196 av
= bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd
, a
);
3197 bv
= bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd
, b
);
3199 return (av
< bv
? -1 : av
> bv
? 1 : 0);
3203 elfNN_ia64_final_link (abfd
, info
)
3205 struct bfd_link_info
*info
;
3207 struct elfNN_ia64_link_hash_table
*ia64_info
;
3208 asection
*unwind_output_sec
;
3210 ia64_info
= elfNN_ia64_hash_table (info
);
3212 /* Make sure we've got ourselves a nice fat __gp value. */
3213 if (!info
->relocateable
)
3215 bfd_vma min_vma
= (bfd_vma
) -1, max_vma
= 0;
3216 bfd_vma min_short_vma
= min_vma
, max_short_vma
= 0;
3217 struct elf_link_hash_entry
*gp
;
3221 /* Find the min and max vma of all sections marked short. Also
3222 collect min and max vma of any type, for use in selecting a
3224 for (os
= abfd
->sections
; os
; os
= os
->next
)
3228 if ((os
->flags
& SEC_ALLOC
) == 0)
3232 hi
= os
->vma
+ os
->_raw_size
;
3240 if (os
->flags
& SEC_SMALL_DATA
)
3242 if (min_short_vma
> lo
)
3244 if (max_short_vma
< hi
)
3249 /* See if the user wants to force a value. */
3250 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", false,
3254 && (gp
->root
.type
== bfd_link_hash_defined
3255 || gp
->root
.type
== bfd_link_hash_defweak
))
3257 asection
*gp_sec
= gp
->root
.u
.def
.section
;
3258 gp_val
= (gp
->root
.u
.def
.value
3259 + gp_sec
->output_section
->vma
3260 + gp_sec
->output_offset
);
3264 /* Pick a sensible value. */
3266 asection
*got_sec
= ia64_info
->got_sec
;
3268 /* Start with just the address of the .got. */
3270 gp_val
= got_sec
->output_section
->vma
;
3271 else if (max_short_vma
!= 0)
3272 gp_val
= min_short_vma
;
3276 /* If it is possible to address the entire image, but we
3277 don't with the choice above, adjust. */
3278 if (max_vma
- min_vma
< 0x400000
3279 && max_vma
- gp_val
<= 0x200000
3280 && gp_val
- min_vma
> 0x200000)
3281 gp_val
= min_vma
+ 0x200000;
3282 else if (max_short_vma
!= 0)
3284 /* If we don't cover all the short data, adjust. */
3285 if (max_short_vma
- gp_val
>= 0x200000)
3286 gp_val
= min_short_vma
+ 0x200000;
3288 /* If we're addressing stuff past the end, adjust back. */
3289 if (gp_val
> max_vma
)
3290 gp_val
= max_vma
- 0x200000 + 8;
3294 /* Validate whether all SHF_IA_64_SHORT sections are within
3295 range of the chosen GP. */
3297 if (max_short_vma
!= 0)
3299 if (max_short_vma
- min_short_vma
>= 0x400000)
3301 (*_bfd_error_handler
)
3302 (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
3303 bfd_get_filename (abfd
),
3304 (unsigned long) (max_short_vma
- min_short_vma
));
3307 else if ((gp_val
> min_short_vma
3308 && gp_val
- min_short_vma
> 0x200000)
3309 || (gp_val
< max_short_vma
3310 && max_short_vma
- gp_val
>= 0x200000))
3312 (*_bfd_error_handler
)
3313 (_("%s: __gp does not cover short data segment"),
3314 bfd_get_filename (abfd
));
3319 _bfd_set_gp_value (abfd
, gp_val
);
3323 gp
->root
.type
= bfd_link_hash_defined
;
3324 gp
->root
.u
.def
.value
= gp_val
;
3325 gp
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3329 /* If we're producing a final executable, we need to sort the contents
3330 of the .IA_64.unwind section. Force this section to be relocated
3331 into memory rather than written immediately to the output file. */
3332 unwind_output_sec
= NULL
;
3333 if (!info
->relocateable
)
3335 asection
*s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
3338 unwind_output_sec
= s
->output_section
;
3339 unwind_output_sec
->contents
3340 = bfd_malloc (unwind_output_sec
->_raw_size
);
3341 if (unwind_output_sec
->contents
== NULL
)
3346 /* Invoke the regular ELF backend linker to do all the work. */
3347 if (!bfd_elfNN_bfd_final_link (abfd
, info
))
3350 if (unwind_output_sec
)
3352 elfNN_ia64_unwind_entry_compare_bfd
= abfd
;
3353 qsort (unwind_output_sec
->contents
, unwind_output_sec
->_raw_size
/ 24,
3354 24, elfNN_ia64_unwind_entry_compare
);
3356 if (! bfd_set_section_contents (abfd
, unwind_output_sec
,
3357 unwind_output_sec
->contents
, 0,
3358 unwind_output_sec
->_raw_size
))
3366 elfNN_ia64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3367 contents
, relocs
, local_syms
, local_sections
)
3369 struct bfd_link_info
*info
;
3371 asection
*input_section
;
3373 Elf_Internal_Rela
*relocs
;
3374 Elf_Internal_Sym
*local_syms
;
3375 asection
**local_sections
;
3377 struct elfNN_ia64_link_hash_table
*ia64_info
;
3378 Elf_Internal_Shdr
*symtab_hdr
;
3379 Elf_Internal_Rela
*rel
;
3380 Elf_Internal_Rela
*relend
;
3382 boolean ret_val
= true; /* for non-fatal errors */
3385 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3386 ia64_info
= elfNN_ia64_hash_table (info
);
3388 /* Infect various flags from the input section to the output section. */
3389 if (info
->relocateable
)
3393 flags
= elf_section_data(input_section
)->this_hdr
.sh_flags
;
3394 flags
&= SHF_IA_64_NORECOV
;
3396 elf_section_data(input_section
->output_section
)
3397 ->this_hdr
.sh_flags
|= flags
;
3400 gp_val
= _bfd_get_gp_value (output_bfd
);
3401 srel
= get_reloc_section (input_bfd
, ia64_info
, input_section
, false);
3404 relend
= relocs
+ input_section
->reloc_count
;
3405 for (; rel
< relend
; ++rel
)
3407 struct elf_link_hash_entry
*h
;
3408 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3409 bfd_reloc_status_type r
;
3410 reloc_howto_type
*howto
;
3411 unsigned long r_symndx
;
3412 Elf_Internal_Sym
*sym
;
3413 unsigned int r_type
;
3417 boolean dynamic_symbol_p
;
3418 boolean undef_weak_ref
;
3420 r_type
= ELFNN_R_TYPE (rel
->r_info
);
3421 if (r_type
> R_IA64_MAX_RELOC_CODE
)
3423 (*_bfd_error_handler
)
3424 (_("%s: unknown relocation type %d"),
3425 bfd_get_filename (input_bfd
), (int)r_type
);
3426 bfd_set_error (bfd_error_bad_value
);
3430 howto
= lookup_howto (r_type
);
3431 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
3433 if (info
->relocateable
)
3435 /* This is a relocateable link. We don't have to change
3436 anything, unless the reloc is against a section symbol,
3437 in which case we have to adjust according to where the
3438 section symbol winds up in the output section. */
3439 if (r_symndx
< symtab_hdr
->sh_info
)
3441 sym
= local_syms
+ r_symndx
;
3442 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3444 sym_sec
= local_sections
[r_symndx
];
3445 rel
->r_addend
+= sym_sec
->output_offset
;
3451 /* This is a final link. */
3456 undef_weak_ref
= false;
3458 if (r_symndx
< symtab_hdr
->sh_info
)
3460 /* Reloc against local symbol. */
3461 sym
= local_syms
+ r_symndx
;
3462 sym_sec
= local_sections
[r_symndx
];
3463 value
= (sym_sec
->output_section
->vma
3464 + sym_sec
->output_offset
3471 /* Reloc against global symbol. */
3472 indx
= r_symndx
- symtab_hdr
->sh_info
;
3473 h
= elf_sym_hashes (input_bfd
)[indx
];
3474 while (h
->root
.type
== bfd_link_hash_indirect
3475 || h
->root
.type
== bfd_link_hash_warning
)
3476 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3479 if (h
->root
.type
== bfd_link_hash_defined
3480 || h
->root
.type
== bfd_link_hash_defweak
)
3482 sym_sec
= h
->root
.u
.def
.section
;
3484 /* Detect the cases that sym_sec->output_section is
3485 expected to be NULL -- all cases in which the symbol
3486 is defined in another shared module. This includes
3487 PLT relocs for which we've created a PLT entry and
3488 other relocs for which we're prepared to create
3489 dynamic relocations. */
3490 /* ??? Just accept it NULL and continue. */
3492 if (sym_sec
->output_section
!= NULL
)
3494 value
= (h
->root
.u
.def
.value
3495 + sym_sec
->output_section
->vma
3496 + sym_sec
->output_offset
);
3499 else if (h
->root
.type
== bfd_link_hash_undefweak
)
3500 undef_weak_ref
= true;
3501 else if (info
->shared
&& !info
->symbolic
3502 && !info
->no_undefined
3503 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3507 if (! ((*info
->callbacks
->undefined_symbol
)
3508 (info
, h
->root
.root
.string
, input_bfd
,
3509 input_section
, rel
->r_offset
,
3510 (!info
->shared
|| info
->no_undefined
3511 || ELF_ST_VISIBILITY (h
->other
)))))
3518 hit_addr
= contents
+ rel
->r_offset
;
3519 value
+= rel
->r_addend
;
3520 dynamic_symbol_p
= elfNN_ia64_dynamic_symbol_p (h
, info
);
3531 case R_IA64_DIR32MSB
:
3532 case R_IA64_DIR32LSB
:
3533 case R_IA64_DIR64MSB
:
3534 case R_IA64_DIR64LSB
:
3535 /* Install a dynamic relocation for this reloc. */
3536 if ((dynamic_symbol_p
|| info
->shared
3537 || (elfNN_ia64_aix_vec (info
->hash
->creator
)
3538 /* Don't emit relocs for __GLOB_DATA_PTR on AIX. */
3539 && (!h
|| strcmp (h
->root
.root
.string
,
3540 "__GLOB_DATA_PTR") != 0)))
3541 && (input_section
->flags
& SEC_ALLOC
) != 0)
3543 unsigned int dyn_r_type
;
3547 BFD_ASSERT (srel
!= NULL
);
3549 /* If we don't need dynamic symbol lookup, find a
3550 matching RELATIVE relocation. */
3551 dyn_r_type
= r_type
;
3552 if (dynamic_symbol_p
)
3554 dynindx
= h
->dynindx
;
3555 addend
= rel
->r_addend
;
3562 case R_IA64_DIR32MSB
:
3563 dyn_r_type
= R_IA64_REL32MSB
;
3565 case R_IA64_DIR32LSB
:
3566 dyn_r_type
= R_IA64_REL32LSB
;
3568 case R_IA64_DIR64MSB
:
3569 dyn_r_type
= R_IA64_REL64MSB
;
3571 case R_IA64_DIR64LSB
:
3572 dyn_r_type
= R_IA64_REL64LSB
;
3576 /* We can't represent this without a dynamic symbol.
3577 Adjust the relocation to be against an output
3578 section symbol, which are always present in the
3579 dynamic symbol table. */
3580 /* ??? People shouldn't be doing non-pic code in
3581 shared libraries. Hork. */
3582 (*_bfd_error_handler
)
3583 (_("%s: linking non-pic code in a shared library"),
3584 bfd_get_filename (input_bfd
));
3592 if (elfNN_ia64_aix_vec (info
->hash
->creator
))
3593 rel
->r_addend
= value
;
3594 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3595 srel
, rel
->r_offset
, dyn_r_type
,
3600 case R_IA64_LTV32MSB
:
3601 case R_IA64_LTV32LSB
:
3602 case R_IA64_LTV64MSB
:
3603 case R_IA64_LTV64LSB
:
3604 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3607 case R_IA64_GPREL22
:
3608 case R_IA64_GPREL64I
:
3609 case R_IA64_GPREL32MSB
:
3610 case R_IA64_GPREL32LSB
:
3611 case R_IA64_GPREL64MSB
:
3612 case R_IA64_GPREL64LSB
:
3613 if (dynamic_symbol_p
)
3615 (*_bfd_error_handler
)
3616 (_("%s: @gprel relocation against dynamic symbol %s"),
3617 bfd_get_filename (input_bfd
), h
->root
.root
.string
);
3622 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3625 case R_IA64_LTOFF22
:
3626 case R_IA64_LTOFF22X
:
3627 case R_IA64_LTOFF64I
:
3628 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3629 value
= set_got_entry (input_bfd
, info
, dyn_i
, (h
? h
->dynindx
: -1),
3630 rel
->r_addend
, value
, R_IA64_DIR64LSB
);
3632 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3635 case R_IA64_PLTOFF22
:
3636 case R_IA64_PLTOFF64I
:
3637 case R_IA64_PLTOFF64MSB
:
3638 case R_IA64_PLTOFF64LSB
:
3639 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3640 value
= set_pltoff_entry (output_bfd
, info
, dyn_i
, value
, false);
3642 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3645 case R_IA64_FPTR64I
:
3646 case R_IA64_FPTR32MSB
:
3647 case R_IA64_FPTR32LSB
:
3648 case R_IA64_FPTR64MSB
:
3649 case R_IA64_FPTR64LSB
:
3650 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3651 if (dyn_i
->want_fptr
)
3653 if (!undef_weak_ref
)
3654 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3660 /* Otherwise, we expect the dynamic linker to create
3665 if (h
->dynindx
!= -1)
3666 dynindx
= h
->dynindx
;
3668 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3669 (info
, h
->root
.u
.def
.section
->owner
,
3670 global_sym_index (h
)));
3674 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3675 (info
, input_bfd
, r_symndx
));
3678 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3679 srel
, rel
->r_offset
, r_type
,
3680 dynindx
, rel
->r_addend
);
3684 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3687 case R_IA64_LTOFF_FPTR22
:
3688 case R_IA64_LTOFF_FPTR64I
:
3689 case R_IA64_LTOFF_FPTR32MSB
:
3690 case R_IA64_LTOFF_FPTR32LSB
:
3691 case R_IA64_LTOFF_FPTR64MSB
:
3692 case R_IA64_LTOFF_FPTR64LSB
:
3696 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3697 if (dyn_i
->want_fptr
)
3699 BFD_ASSERT (h
== NULL
|| h
->dynindx
== -1)
3700 if (!undef_weak_ref
)
3701 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3706 /* Otherwise, we expect the dynamic linker to create
3710 if (h
->dynindx
!= -1)
3711 dynindx
= h
->dynindx
;
3713 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3714 (info
, h
->root
.u
.def
.section
->owner
,
3715 global_sym_index (h
)));
3718 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3719 (info
, input_bfd
, r_symndx
));
3723 value
= set_got_entry (output_bfd
, info
, dyn_i
, dynindx
,
3724 rel
->r_addend
, value
, R_IA64_FPTR64LSB
);
3726 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3730 case R_IA64_PCREL32MSB
:
3731 case R_IA64_PCREL32LSB
:
3732 case R_IA64_PCREL64MSB
:
3733 case R_IA64_PCREL64LSB
:
3734 /* Install a dynamic relocation for this reloc. */
3735 if (dynamic_symbol_p
3736 || elfNN_ia64_aix_vec (info
->hash
->creator
))
3738 BFD_ASSERT (srel
!= NULL
);
3740 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3741 srel
, rel
->r_offset
, r_type
,
3742 h
->dynindx
, rel
->r_addend
);
3746 case R_IA64_PCREL21BI
:
3747 case R_IA64_PCREL21F
:
3748 case R_IA64_PCREL21M
:
3749 /* ??? These two are only used for speculation fixup code.
3750 They should never be dynamic. */
3751 if (dynamic_symbol_p
)
3753 (*_bfd_error_handler
)
3754 (_("%s: dynamic relocation against speculation fixup"),
3755 bfd_get_filename (input_bfd
));
3761 (*_bfd_error_handler
)
3762 (_("%s: speculation fixup against undefined weak symbol"),
3763 bfd_get_filename (input_bfd
));
3769 case R_IA64_PCREL21B
:
3770 case R_IA64_PCREL60B
:
3771 /* We should have created a PLT entry for any dynamic symbol. */
3774 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
3776 if (dyn_i
&& dyn_i
->want_plt2
)
3778 /* Should have caught this earlier. */
3779 BFD_ASSERT (rel
->r_addend
== 0);
3781 value
= (ia64_info
->plt_sec
->output_section
->vma
3782 + ia64_info
->plt_sec
->output_offset
3783 + dyn_i
->plt2_offset
);
3787 /* Since there's no PLT entry, Validate that this is
3789 BFD_ASSERT (undef_weak_ref
|| sym_sec
->output_section
!= NULL
);
3791 /* If the symbol is undef_weak, we shouldn't be trying
3792 to call it. There's every chance that we'd wind up
3793 with an out-of-range fixup here. Don't bother setting
3794 any value at all. */
3800 case R_IA64_PCREL22
:
3801 case R_IA64_PCREL64I
:
3803 /* Make pc-relative. */
3804 value
-= (input_section
->output_section
->vma
3805 + input_section
->output_offset
3806 + rel
->r_offset
) & ~ (bfd_vma
) 0x3;
3807 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3810 case R_IA64_SEGREL32MSB
:
3811 case R_IA64_SEGREL32LSB
:
3812 case R_IA64_SEGREL64MSB
:
3813 case R_IA64_SEGREL64LSB
:
3815 struct elf_segment_map
*m
;
3816 Elf_Internal_Phdr
*p
;
3818 /* Find the segment that contains the output_section. */
3819 for (m
= elf_tdata (output_bfd
)->segment_map
,
3820 p
= elf_tdata (output_bfd
)->phdr
;
3825 for (i
= m
->count
- 1; i
>= 0; i
--)
3826 if (m
->sections
[i
] == sym_sec
->output_section
)
3834 /* If the input section was discarded from the output, then
3837 if (bfd_is_abs_section (sym_sec
->output_section
))
3840 r
= bfd_reloc_notsupported
;
3844 /* The VMA of the segment is the vaddr of the associated
3846 if (value
> p
->p_vaddr
)
3847 value
-= p
->p_vaddr
;
3850 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
,
3856 case R_IA64_SECREL32MSB
:
3857 case R_IA64_SECREL32LSB
:
3858 case R_IA64_SECREL64MSB
:
3859 case R_IA64_SECREL64LSB
:
3860 /* Make output-section relative. */
3861 if (value
> input_section
->output_section
->vma
)
3862 value
-= input_section
->output_section
->vma
;
3865 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3868 case R_IA64_IPLTMSB
:
3869 case R_IA64_IPLTLSB
:
3870 /* Install a dynamic relocation for this reloc. */
3871 if ((dynamic_symbol_p
|| info
->shared
)
3872 && (input_section
->flags
& SEC_ALLOC
) != 0)
3874 BFD_ASSERT (srel
!= NULL
);
3876 /* If we don't need dynamic symbol lookup, install two
3877 RELATIVE relocations. */
3878 if (! dynamic_symbol_p
)
3880 unsigned int dyn_r_type
;
3882 if (r_type
== R_IA64_IPLTMSB
)
3883 dyn_r_type
= R_IA64_REL64MSB
;
3885 dyn_r_type
= R_IA64_REL64LSB
;
3887 elfNN_ia64_install_dyn_reloc (output_bfd
, info
,
3889 srel
, rel
->r_offset
,
3890 dyn_r_type
, 0, value
);
3891 elfNN_ia64_install_dyn_reloc (output_bfd
, info
,
3893 srel
, rel
->r_offset
+ 8,
3894 dyn_r_type
, 0, gp_val
);
3897 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3898 srel
, rel
->r_offset
, r_type
,
3899 h
->dynindx
, rel
->r_addend
);
3902 if (r_type
== R_IA64_IPLTMSB
)
3903 r_type
= R_IA64_DIR64MSB
;
3905 r_type
= R_IA64_DIR64LSB
;
3906 elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3907 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
+ 8, gp_val
,
3912 r
= bfd_reloc_notsupported
;
3921 case bfd_reloc_undefined
:
3922 /* This can happen for global table relative relocs if
3923 __gp is undefined. This is a panic situation so we
3924 don't try to continue. */
3925 (*info
->callbacks
->undefined_symbol
)
3926 (info
, "__gp", input_bfd
, input_section
, rel
->r_offset
, 1);
3929 case bfd_reloc_notsupported
:
3934 name
= h
->root
.root
.string
;
3937 name
= bfd_elf_string_from_elf_section (input_bfd
,
3938 symtab_hdr
->sh_link
,
3943 name
= bfd_section_name (input_bfd
, input_section
);
3945 if (!(*info
->callbacks
->warning
) (info
, _("unsupported reloc"),
3947 input_section
, rel
->r_offset
))
3953 case bfd_reloc_dangerous
:
3954 case bfd_reloc_outofrange
:
3955 case bfd_reloc_overflow
:
3961 name
= h
->root
.root
.string
;
3964 name
= bfd_elf_string_from_elf_section (input_bfd
,
3965 symtab_hdr
->sh_link
,
3970 name
= bfd_section_name (input_bfd
, input_section
);
3972 if (!(*info
->callbacks
->reloc_overflow
) (info
, name
,
3988 elfNN_ia64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3990 struct bfd_link_info
*info
;
3991 struct elf_link_hash_entry
*h
;
3992 Elf_Internal_Sym
*sym
;
3994 struct elfNN_ia64_link_hash_table
*ia64_info
;
3995 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3997 ia64_info
= elfNN_ia64_hash_table (info
);
3998 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
4000 /* Fill in the PLT data, if required. */
4001 if (dyn_i
&& dyn_i
->want_plt
)
4003 Elf_Internal_Rela outrel
;
4006 bfd_vma plt_addr
, pltoff_addr
, gp_val
, index
;
4007 ElfNN_External_Rela
*rel
;
4009 gp_val
= _bfd_get_gp_value (output_bfd
);
4011 /* Initialize the minimal PLT entry. */
4013 index
= (dyn_i
->plt_offset
- PLT_HEADER_SIZE
) / PLT_MIN_ENTRY_SIZE
;
4014 plt_sec
= ia64_info
->plt_sec
;
4015 loc
= plt_sec
->contents
+ dyn_i
->plt_offset
;
4017 memcpy (loc
, plt_min_entry
, PLT_MIN_ENTRY_SIZE
);
4018 elfNN_ia64_install_value (output_bfd
, loc
, index
, R_IA64_IMM22
);
4019 elfNN_ia64_install_value (output_bfd
, loc
+2, -dyn_i
->plt_offset
,
4022 plt_addr
= (plt_sec
->output_section
->vma
4023 + plt_sec
->output_offset
4024 + dyn_i
->plt_offset
);
4025 pltoff_addr
= set_pltoff_entry (output_bfd
, info
, dyn_i
, plt_addr
, true);
4027 /* Initialize the FULL PLT entry, if needed. */
4028 if (dyn_i
->want_plt2
)
4030 loc
= plt_sec
->contents
+ dyn_i
->plt2_offset
;
4032 memcpy (loc
, plt_full_entry
, PLT_FULL_ENTRY_SIZE
);
4033 elfNN_ia64_install_value (output_bfd
, loc
, pltoff_addr
- gp_val
,
4036 /* Mark the symbol as undefined, rather than as defined in the
4037 plt section. Leave the value alone. */
4038 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4039 first place. But perhaps elflink.h did some for us. */
4040 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4041 sym
->st_shndx
= SHN_UNDEF
;
4044 /* Create the dynamic relocation. */
4045 outrel
.r_offset
= pltoff_addr
;
4046 if (bfd_little_endian (output_bfd
))
4047 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, R_IA64_IPLTLSB
);
4049 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, R_IA64_IPLTMSB
);
4050 outrel
.r_addend
= 0;
4052 /* This is fun. In the .IA_64.pltoff section, we've got entries
4053 that correspond both to real PLT entries, and those that
4054 happened to resolve to local symbols but need to be created
4055 to satisfy @pltoff relocations. The .rela.IA_64.pltoff
4056 relocations for the real PLT should come at the end of the
4057 section, so that they can be indexed by plt entry at runtime.
4059 We emitted all of the relocations for the non-PLT @pltoff
4060 entries during relocate_section. So we can consider the
4061 existing sec->reloc_count to be the base of the array of
4064 rel
= (ElfNN_External_Rela
*)ia64_info
->rel_pltoff_sec
->contents
;
4065 rel
+= ia64_info
->rel_pltoff_sec
->reloc_count
;
4067 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, rel
+ index
);
4070 /* Mark some specially defined symbols as absolute. */
4071 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4072 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4073 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4074 sym
->st_shndx
= SHN_ABS
;
4080 elfNN_ia64_finish_dynamic_sections (abfd
, info
)
4082 struct bfd_link_info
*info
;
4084 struct elfNN_ia64_link_hash_table
*ia64_info
;
4087 ia64_info
= elfNN_ia64_hash_table (info
);
4088 dynobj
= ia64_info
->root
.dynobj
;
4090 if (elf_hash_table (info
)->dynamic_sections_created
)
4092 ElfNN_External_Dyn
*dyncon
, *dynconend
;
4093 asection
*sdyn
, *sgotplt
;
4096 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4097 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
4098 BFD_ASSERT (sdyn
!= NULL
);
4099 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
4100 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4102 gp_val
= _bfd_get_gp_value (abfd
);
4104 for (; dyncon
< dynconend
; dyncon
++)
4106 Elf_Internal_Dyn dyn
;
4108 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4113 dyn
.d_un
.d_ptr
= gp_val
;
4117 dyn
.d_un
.d_val
= (ia64_info
->minplt_entries
4118 * sizeof (ElfNN_External_Rela
));
4122 /* See the comment above in finish_dynamic_symbol. */
4123 dyn
.d_un
.d_ptr
= (ia64_info
->rel_pltoff_sec
->output_section
->vma
4124 + ia64_info
->rel_pltoff_sec
->output_offset
4125 + (ia64_info
->rel_pltoff_sec
->reloc_count
4126 * sizeof (ElfNN_External_Rela
)));
4129 case DT_IA_64_PLT_RESERVE
:
4130 dyn
.d_un
.d_ptr
= (sgotplt
->output_section
->vma
4131 + sgotplt
->output_offset
);
4135 /* Do not have RELASZ include JMPREL. This makes things
4136 easier on ld.so. This is not what the rest of BFD set up. */
4137 dyn
.d_un
.d_val
-= (ia64_info
->minplt_entries
4138 * sizeof (ElfNN_External_Rela
));
4142 bfd_elfNN_swap_dyn_out (abfd
, &dyn
, dyncon
);
4145 /* Initialize the PLT0 entry */
4146 if (ia64_info
->plt_sec
)
4148 bfd_byte
*loc
= ia64_info
->plt_sec
->contents
;
4151 memcpy (loc
, plt_header
, PLT_HEADER_SIZE
);
4153 pltres
= (sgotplt
->output_section
->vma
4154 + sgotplt
->output_offset
4157 elfNN_ia64_install_value (abfd
, loc
+1, pltres
, R_IA64_GPREL22
);
4164 /* ELF file flag handling: */
4166 /* Function to keep IA-64 specific file flags. */
4168 elfNN_ia64_set_private_flags (abfd
, flags
)
4172 BFD_ASSERT (!elf_flags_init (abfd
)
4173 || elf_elfheader (abfd
)->e_flags
== flags
);
4175 elf_elfheader (abfd
)->e_flags
= flags
;
4176 elf_flags_init (abfd
) = true;
4180 /* Copy backend specific data from one object module to another */
4182 elfNN_ia64_copy_private_bfd_data (ibfd
, obfd
)
4185 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4186 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4189 BFD_ASSERT (!elf_flags_init (obfd
)
4190 || (elf_elfheader (obfd
)->e_flags
4191 == elf_elfheader (ibfd
)->e_flags
));
4193 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
4194 elf_flags_init (obfd
) = true;
4198 /* Merge backend specific data from an object file to the output
4199 object file when linking. */
4201 elfNN_ia64_merge_private_bfd_data (ibfd
, obfd
)
4208 /* Don't even pretend to support mixed-format linking. */
4209 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4210 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4213 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4214 out_flags
= elf_elfheader (obfd
)->e_flags
;
4216 if (! elf_flags_init (obfd
))
4218 elf_flags_init (obfd
) = true;
4219 elf_elfheader (obfd
)->e_flags
= in_flags
;
4221 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
4222 && bfd_get_arch_info (obfd
)->the_default
)
4224 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
4225 bfd_get_mach (ibfd
));
4231 /* Check flag compatibility. */
4232 if (in_flags
== out_flags
)
4235 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4236 if (!(in_flags
& EF_IA_64_REDUCEDFP
) && (out_flags
& EF_IA_64_REDUCEDFP
))
4237 elf_elfheader (obfd
)->e_flags
&= ~EF_IA_64_REDUCEDFP
;
4239 if ((in_flags
& EF_IA_64_TRAPNIL
) != (out_flags
& EF_IA_64_TRAPNIL
))
4241 (*_bfd_error_handler
)
4242 (_("%s: linking trap-on-NULL-dereference with non-trapping files"),
4243 bfd_get_filename (ibfd
));
4245 bfd_set_error (bfd_error_bad_value
);
4248 if ((in_flags
& EF_IA_64_BE
) != (out_flags
& EF_IA_64_BE
))
4250 (*_bfd_error_handler
)
4251 (_("%s: linking big-endian files with little-endian files"),
4252 bfd_get_filename (ibfd
));
4254 bfd_set_error (bfd_error_bad_value
);
4257 if ((in_flags
& EF_IA_64_ABI64
) != (out_flags
& EF_IA_64_ABI64
))
4259 (*_bfd_error_handler
)
4260 (_("%s: linking 64-bit files with 32-bit files"),
4261 bfd_get_filename (ibfd
));
4263 bfd_set_error (bfd_error_bad_value
);
4266 if ((in_flags
& EF_IA_64_CONS_GP
) != (out_flags
& EF_IA_64_CONS_GP
))
4268 (*_bfd_error_handler
)
4269 (_("%s: linking constant-gp files with non-constant-gp files"),
4270 bfd_get_filename (ibfd
));
4272 bfd_set_error (bfd_error_bad_value
);
4275 if ((in_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
)
4276 != (out_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4278 (*_bfd_error_handler
)
4279 (_("%s: linking auto-pic files with non-auto-pic files"),
4280 bfd_get_filename (ibfd
));
4282 bfd_set_error (bfd_error_bad_value
);
4290 elfNN_ia64_print_private_bfd_data (abfd
, ptr
)
4294 FILE *file
= (FILE *) ptr
;
4295 flagword flags
= elf_elfheader (abfd
)->e_flags
;
4297 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4299 fprintf (file
, "private flags = %s%s%s%s%s%s%s%s\n",
4300 (flags
& EF_IA_64_TRAPNIL
) ? "TRAPNIL, " : "",
4301 (flags
& EF_IA_64_EXT
) ? "EXT, " : "",
4302 (flags
& EF_IA_64_BE
) ? "BE, " : "LE, ",
4303 (flags
& EF_IA_64_REDUCEDFP
) ? "REDUCEDFP, " : "",
4304 (flags
& EF_IA_64_CONS_GP
) ? "CONS_GP, " : "",
4305 (flags
& EF_IA_64_NOFUNCDESC_CONS_GP
) ? "NOFUNCDESC_CONS_GP, " : "",
4306 (flags
& EF_IA_64_ABSOLUTE
) ? "ABSOLUTE, " : "",
4307 (flags
& EF_IA_64_ABI64
) ? "ABI64" : "ABI32");
4309 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4313 #define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec
4314 #define TARGET_LITTLE_NAME "elfNN-ia64-little"
4315 #define TARGET_BIG_SYM bfd_elfNN_ia64_big_vec
4316 #define TARGET_BIG_NAME "elfNN-ia64-big"
4317 #define ELF_ARCH bfd_arch_ia64
4318 #define ELF_MACHINE_CODE EM_IA_64
4319 #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */
4320 #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */
4321 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
4323 #define elf_backend_section_from_shdr \
4324 elfNN_ia64_section_from_shdr
4325 #define elf_backend_section_flags \
4326 elfNN_ia64_section_flags
4327 #define elf_backend_fake_sections \
4328 elfNN_ia64_fake_sections
4329 #define elf_backend_final_write_processing \
4330 elfNN_ia64_final_write_processing
4331 #define elf_backend_add_symbol_hook \
4332 elfNN_ia64_add_symbol_hook
4333 #define elf_backend_additional_program_headers \
4334 elfNN_ia64_additional_program_headers
4335 #define elf_backend_modify_segment_map \
4336 elfNN_ia64_modify_segment_map
4337 #define elf_info_to_howto \
4338 elfNN_ia64_info_to_howto
4340 #define bfd_elfNN_bfd_reloc_type_lookup \
4341 elfNN_ia64_reloc_type_lookup
4342 #define bfd_elfNN_bfd_is_local_label_name \
4343 elfNN_ia64_is_local_label_name
4344 #define bfd_elfNN_bfd_relax_section \
4345 elfNN_ia64_relax_section
4347 /* Stuff for the BFD linker: */
4348 #define bfd_elfNN_bfd_link_hash_table_create \
4349 elfNN_ia64_hash_table_create
4350 #define elf_backend_create_dynamic_sections \
4351 elfNN_ia64_create_dynamic_sections
4352 #define elf_backend_check_relocs \
4353 elfNN_ia64_check_relocs
4354 #define elf_backend_adjust_dynamic_symbol \
4355 elfNN_ia64_adjust_dynamic_symbol
4356 #define elf_backend_size_dynamic_sections \
4357 elfNN_ia64_size_dynamic_sections
4358 #define elf_backend_relocate_section \
4359 elfNN_ia64_relocate_section
4360 #define elf_backend_finish_dynamic_symbol \
4361 elfNN_ia64_finish_dynamic_symbol
4362 #define elf_backend_finish_dynamic_sections \
4363 elfNN_ia64_finish_dynamic_sections
4364 #define bfd_elfNN_bfd_final_link \
4365 elfNN_ia64_final_link
4367 #define bfd_elfNN_bfd_copy_private_bfd_data \
4368 elfNN_ia64_copy_private_bfd_data
4369 #define bfd_elfNN_bfd_merge_private_bfd_data \
4370 elfNN_ia64_merge_private_bfd_data
4371 #define bfd_elfNN_bfd_set_private_flags \
4372 elfNN_ia64_set_private_flags
4373 #define bfd_elfNN_bfd_print_private_bfd_data \
4374 elfNN_ia64_print_private_bfd_data
4376 #define elf_backend_plt_readonly 1
4377 #define elf_backend_want_plt_sym 0
4378 #define elf_backend_plt_alignment 5
4379 #define elf_backend_got_header_size 0
4380 #define elf_backend_plt_header_size PLT_HEADER_SIZE
4381 #define elf_backend_want_got_plt 1
4382 #define elf_backend_may_use_rel_p 1
4383 #define elf_backend_may_use_rela_p 1
4384 #define elf_backend_default_use_rela_p 1
4385 #define elf_backend_want_dynbss 0
4386 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
4387 #define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol
4389 #include "elfNN-target.h"
4391 /* AIX-specific vectors. */
4393 #undef TARGET_LITTLE_SYM
4394 #define TARGET_LITTLE_SYM bfd_elfNN_ia64_aix_little_vec
4395 #undef TARGET_LITTLE_NAME
4396 #define TARGET_LITTLE_NAME "elfNN-ia64-aix-little"
4397 #undef TARGET_BIG_SYM
4398 #define TARGET_BIG_SYM bfd_elfNN_ia64_aix_big_vec
4399 #undef TARGET_BIG_NAME
4400 #define TARGET_BIG_NAME "elfNN-ia64-aix-big"
4402 #undef elf_backend_add_symbol_hook
4403 #define elf_backend_add_symbol_hook elfNN_ia64_aix_add_symbol_hook
4405 #undef bfd_elfNN_bfd_link_add_symbols
4406 #define bfd_elfNN_bfd_link_add_symbols elfNN_ia64_aix_link_add_symbols
4408 #define elfNN_bed elfNN_ia64_aix_bed
4410 #include "elfNN-target.h"