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_FPTR64MSB
, "LTOFF_FPTR64MSB", 4, false, true),
364 IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB
, "LTOFF_FPTR64LSB", 4, false, true),
366 IA64_HOWTO (R_IA64_SEGREL32MSB
, "SEGREL32MSB", 2, false, true),
367 IA64_HOWTO (R_IA64_SEGREL32LSB
, "SEGREL32LSB", 2, false, true),
368 IA64_HOWTO (R_IA64_SEGREL64MSB
, "SEGREL64MSB", 4, false, true),
369 IA64_HOWTO (R_IA64_SEGREL64LSB
, "SEGREL64LSB", 4, false, true),
371 IA64_HOWTO (R_IA64_SECREL32MSB
, "SECREL32MSB", 2, false, true),
372 IA64_HOWTO (R_IA64_SECREL32LSB
, "SECREL32LSB", 2, false, true),
373 IA64_HOWTO (R_IA64_SECREL64MSB
, "SECREL64MSB", 4, false, true),
374 IA64_HOWTO (R_IA64_SECREL64LSB
, "SECREL64LSB", 4, false, true),
376 IA64_HOWTO (R_IA64_REL32MSB
, "REL32MSB", 2, false, true),
377 IA64_HOWTO (R_IA64_REL32LSB
, "REL32LSB", 2, false, true),
378 IA64_HOWTO (R_IA64_REL64MSB
, "REL64MSB", 4, false, true),
379 IA64_HOWTO (R_IA64_REL64LSB
, "REL64LSB", 4, false, true),
381 IA64_HOWTO (R_IA64_LTV32MSB
, "LTV32MSB", 2, false, true),
382 IA64_HOWTO (R_IA64_LTV32LSB
, "LTV32LSB", 2, false, true),
383 IA64_HOWTO (R_IA64_LTV64MSB
, "LTV64MSB", 4, false, true),
384 IA64_HOWTO (R_IA64_LTV64LSB
, "LTV64LSB", 4, false, true),
386 IA64_HOWTO (R_IA64_PCREL21BI
, "PCREL21BI", 0, true, true),
387 IA64_HOWTO (R_IA64_PCREL22
, "PCREL22", 0, true, true),
388 IA64_HOWTO (R_IA64_PCREL64I
, "PCREL64I", 0, true, true),
390 IA64_HOWTO (R_IA64_IPLTMSB
, "IPLTMSB", 4, false, true),
391 IA64_HOWTO (R_IA64_IPLTLSB
, "IPLTLSB", 4, false, true),
392 IA64_HOWTO (R_IA64_COPY
, "COPY", 4, false, true),
393 IA64_HOWTO (R_IA64_LTOFF22X
, "LTOFF22X", 0, false, true),
394 IA64_HOWTO (R_IA64_LDXMOV
, "LDXMOV", 0, false, true),
396 IA64_HOWTO (R_IA64_TPREL22
, "TPREL22", 0, false, false),
397 IA64_HOWTO (R_IA64_TPREL64MSB
, "TPREL64MSB", 8, false, false),
398 IA64_HOWTO (R_IA64_TPREL64LSB
, "TPREL64LSB", 8, false, false),
399 IA64_HOWTO (R_IA64_LTOFF_TP22
, "LTOFF_TP22", 0, false, false),
402 static unsigned char elf_code_to_howto_index
[R_IA64_MAX_RELOC_CODE
+ 1];
404 /* Given a BFD reloc type, return the matching HOWTO structure. */
406 static reloc_howto_type
*
410 static int inited
= 0;
417 memset (elf_code_to_howto_index
, 0xff, sizeof (elf_code_to_howto_index
));
418 for (i
= 0; i
< NELEMS (ia64_howto_table
); ++i
)
419 elf_code_to_howto_index
[ia64_howto_table
[i
].type
] = i
;
422 BFD_ASSERT (rtype
<= R_IA64_MAX_RELOC_CODE
);
423 i
= elf_code_to_howto_index
[rtype
];
424 if (i
>= NELEMS (ia64_howto_table
))
426 return ia64_howto_table
+ i
;
429 static reloc_howto_type
*
430 elfNN_ia64_reloc_type_lookup (abfd
, bfd_code
)
431 bfd
*abfd ATTRIBUTE_UNUSED
;
432 bfd_reloc_code_real_type bfd_code
;
438 case BFD_RELOC_NONE
: rtype
= R_IA64_NONE
; break;
440 case BFD_RELOC_IA64_IMM14
: rtype
= R_IA64_IMM14
; break;
441 case BFD_RELOC_IA64_IMM22
: rtype
= R_IA64_IMM22
; break;
442 case BFD_RELOC_IA64_IMM64
: rtype
= R_IA64_IMM64
; break;
444 case BFD_RELOC_IA64_DIR32MSB
: rtype
= R_IA64_DIR32MSB
; break;
445 case BFD_RELOC_IA64_DIR32LSB
: rtype
= R_IA64_DIR32LSB
; break;
446 case BFD_RELOC_IA64_DIR64MSB
: rtype
= R_IA64_DIR64MSB
; break;
447 case BFD_RELOC_IA64_DIR64LSB
: rtype
= R_IA64_DIR64LSB
; break;
449 case BFD_RELOC_IA64_GPREL22
: rtype
= R_IA64_GPREL22
; break;
450 case BFD_RELOC_IA64_GPREL64I
: rtype
= R_IA64_GPREL64I
; break;
451 case BFD_RELOC_IA64_GPREL32MSB
: rtype
= R_IA64_GPREL32MSB
; break;
452 case BFD_RELOC_IA64_GPREL32LSB
: rtype
= R_IA64_GPREL32LSB
; break;
453 case BFD_RELOC_IA64_GPREL64MSB
: rtype
= R_IA64_GPREL64MSB
; break;
454 case BFD_RELOC_IA64_GPREL64LSB
: rtype
= R_IA64_GPREL64LSB
; break;
456 case BFD_RELOC_IA64_LTOFF22
: rtype
= R_IA64_LTOFF22
; break;
457 case BFD_RELOC_IA64_LTOFF64I
: rtype
= R_IA64_LTOFF64I
; break;
459 case BFD_RELOC_IA64_PLTOFF22
: rtype
= R_IA64_PLTOFF22
; break;
460 case BFD_RELOC_IA64_PLTOFF64I
: rtype
= R_IA64_PLTOFF64I
; break;
461 case BFD_RELOC_IA64_PLTOFF64MSB
: rtype
= R_IA64_PLTOFF64MSB
; break;
462 case BFD_RELOC_IA64_PLTOFF64LSB
: rtype
= R_IA64_PLTOFF64LSB
; break;
463 case BFD_RELOC_IA64_FPTR64I
: rtype
= R_IA64_FPTR64I
; break;
464 case BFD_RELOC_IA64_FPTR32MSB
: rtype
= R_IA64_FPTR32MSB
; break;
465 case BFD_RELOC_IA64_FPTR32LSB
: rtype
= R_IA64_FPTR32LSB
; break;
466 case BFD_RELOC_IA64_FPTR64MSB
: rtype
= R_IA64_FPTR64MSB
; break;
467 case BFD_RELOC_IA64_FPTR64LSB
: rtype
= R_IA64_FPTR64LSB
; break;
469 case BFD_RELOC_IA64_PCREL21B
: rtype
= R_IA64_PCREL21B
; break;
470 case BFD_RELOC_IA64_PCREL21BI
: rtype
= R_IA64_PCREL21BI
; break;
471 case BFD_RELOC_IA64_PCREL21M
: rtype
= R_IA64_PCREL21M
; break;
472 case BFD_RELOC_IA64_PCREL21F
: rtype
= R_IA64_PCREL21F
; break;
473 case BFD_RELOC_IA64_PCREL22
: rtype
= R_IA64_PCREL22
; break;
474 case BFD_RELOC_IA64_PCREL60B
: rtype
= R_IA64_PCREL60B
; break;
475 case BFD_RELOC_IA64_PCREL64I
: rtype
= R_IA64_PCREL64I
; break;
476 case BFD_RELOC_IA64_PCREL32MSB
: rtype
= R_IA64_PCREL32MSB
; break;
477 case BFD_RELOC_IA64_PCREL32LSB
: rtype
= R_IA64_PCREL32LSB
; break;
478 case BFD_RELOC_IA64_PCREL64MSB
: rtype
= R_IA64_PCREL64MSB
; break;
479 case BFD_RELOC_IA64_PCREL64LSB
: rtype
= R_IA64_PCREL64LSB
; break;
481 case BFD_RELOC_IA64_LTOFF_FPTR22
: rtype
= R_IA64_LTOFF_FPTR22
; break;
482 case BFD_RELOC_IA64_LTOFF_FPTR64I
: rtype
= R_IA64_LTOFF_FPTR64I
; break;
483 case BFD_RELOC_IA64_LTOFF_FPTR64MSB
: rtype
= R_IA64_LTOFF_FPTR64MSB
; break;
484 case BFD_RELOC_IA64_LTOFF_FPTR64LSB
: rtype
= R_IA64_LTOFF_FPTR64LSB
; break;
486 case BFD_RELOC_IA64_SEGREL32MSB
: rtype
= R_IA64_SEGREL32MSB
; break;
487 case BFD_RELOC_IA64_SEGREL32LSB
: rtype
= R_IA64_SEGREL32LSB
; break;
488 case BFD_RELOC_IA64_SEGREL64MSB
: rtype
= R_IA64_SEGREL64MSB
; break;
489 case BFD_RELOC_IA64_SEGREL64LSB
: rtype
= R_IA64_SEGREL64LSB
; break;
491 case BFD_RELOC_IA64_SECREL32MSB
: rtype
= R_IA64_SECREL32MSB
; break;
492 case BFD_RELOC_IA64_SECREL32LSB
: rtype
= R_IA64_SECREL32LSB
; break;
493 case BFD_RELOC_IA64_SECREL64MSB
: rtype
= R_IA64_SECREL64MSB
; break;
494 case BFD_RELOC_IA64_SECREL64LSB
: rtype
= R_IA64_SECREL64LSB
; break;
496 case BFD_RELOC_IA64_REL32MSB
: rtype
= R_IA64_REL32MSB
; break;
497 case BFD_RELOC_IA64_REL32LSB
: rtype
= R_IA64_REL32LSB
; break;
498 case BFD_RELOC_IA64_REL64MSB
: rtype
= R_IA64_REL64MSB
; break;
499 case BFD_RELOC_IA64_REL64LSB
: rtype
= R_IA64_REL64LSB
; break;
501 case BFD_RELOC_IA64_LTV32MSB
: rtype
= R_IA64_LTV32MSB
; break;
502 case BFD_RELOC_IA64_LTV32LSB
: rtype
= R_IA64_LTV32LSB
; break;
503 case BFD_RELOC_IA64_LTV64MSB
: rtype
= R_IA64_LTV64MSB
; break;
504 case BFD_RELOC_IA64_LTV64LSB
: rtype
= R_IA64_LTV64LSB
; break;
506 case BFD_RELOC_IA64_IPLTMSB
: rtype
= R_IA64_IPLTMSB
; break;
507 case BFD_RELOC_IA64_IPLTLSB
: rtype
= R_IA64_IPLTLSB
; break;
508 case BFD_RELOC_IA64_COPY
: rtype
= R_IA64_COPY
; break;
509 case BFD_RELOC_IA64_LTOFF22X
: rtype
= R_IA64_LTOFF22X
; break;
510 case BFD_RELOC_IA64_LDXMOV
: rtype
= R_IA64_LDXMOV
; break;
512 case BFD_RELOC_IA64_TPREL22
: rtype
= R_IA64_TPREL22
; break;
513 case BFD_RELOC_IA64_TPREL64MSB
: rtype
= R_IA64_TPREL64MSB
; break;
514 case BFD_RELOC_IA64_TPREL64LSB
: rtype
= R_IA64_TPREL64LSB
; break;
515 case BFD_RELOC_IA64_LTOFF_TP22
: rtype
= R_IA64_LTOFF_TP22
; break;
519 return lookup_howto (rtype
);
522 /* Given a ELF reloc, return the matching HOWTO structure. */
525 elfNN_ia64_info_to_howto (abfd
, bfd_reloc
, elf_reloc
)
526 bfd
*abfd ATTRIBUTE_UNUSED
;
528 ElfNN_Internal_Rela
*elf_reloc
;
530 bfd_reloc
->howto
= lookup_howto (ELFNN_R_TYPE (elf_reloc
->r_info
));
533 #define PLT_HEADER_SIZE (3 * 16)
534 #define PLT_MIN_ENTRY_SIZE (1 * 16)
535 #define PLT_FULL_ENTRY_SIZE (2 * 16)
536 #define PLT_RESERVED_WORDS 3
538 static const bfd_byte plt_header
[PLT_HEADER_SIZE
] =
540 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */
541 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */
542 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
543 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */
544 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */
545 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
546 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */
547 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */
548 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
551 static const bfd_byte plt_min_entry
[PLT_MIN_ENTRY_SIZE
] =
553 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */
554 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */
555 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */
558 static const bfd_byte plt_full_entry
[PLT_FULL_ENTRY_SIZE
] =
560 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
561 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */
562 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
563 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
564 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
565 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
568 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
569 #define AIX_DYNAMIC_INTERPRETER "/usr/lib/ia64l64/libc.so.1"
570 #define DYNAMIC_INTERPRETER(abfd) \
571 (elfNN_ia64_aix_vec (abfd->xvec) ? AIX_DYNAMIC_INTERPRETER : ELF_DYNAMIC_INTERPRETER)
573 /* Select out of range branch fixup type. Note that Itanium does
574 not support brl, and so it gets emulated by the kernel. */
577 static const bfd_byte oor_brl
[16] =
579 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
580 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */
581 0x00, 0x00, 0x00, 0xc0
584 static const bfd_byte oor_ip
[48] =
586 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */
587 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */
588 0x01, 0x00, 0x00, 0x60,
589 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */
590 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */
591 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */
592 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */
593 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
594 0x60, 0x00, 0x80, 0x00 /* br b6;; */
597 /* These functions do relaxation for IA-64 ELF.
599 This is primarily to support branches to targets out of range;
600 relaxation of R_IA64_LTOFF22X and R_IA64_LDXMOV not yet supported. */
603 elfNN_ia64_relax_section (abfd
, sec
, link_info
, again
)
606 struct bfd_link_info
*link_info
;
611 struct one_fixup
*next
;
617 Elf_Internal_Shdr
*symtab_hdr
;
618 Elf_Internal_Rela
*internal_relocs
;
619 Elf_Internal_Rela
*free_relocs
= NULL
;
620 Elf_Internal_Rela
*irel
, *irelend
;
622 bfd_byte
*free_contents
= NULL
;
623 ElfNN_External_Sym
*extsyms
;
624 ElfNN_External_Sym
*free_extsyms
= NULL
;
625 struct elfNN_ia64_link_hash_table
*ia64_info
;
626 struct one_fixup
*fixups
= NULL
;
627 boolean changed_contents
= false;
628 boolean changed_relocs
= false;
630 /* Assume we're not going to change any sizes, and we'll only need
634 /* Nothing to do if there are no relocations. */
635 if ((sec
->flags
& SEC_RELOC
) == 0
636 || sec
->reloc_count
== 0)
639 /* If this is the first time we have been called for this section,
640 initialize the cooked size. */
641 if (sec
->_cooked_size
== 0)
642 sec
->_cooked_size
= sec
->_raw_size
;
644 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
646 /* Load the relocations for this section. */
647 internal_relocs
= (_bfd_elfNN_link_read_relocs
648 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
649 link_info
->keep_memory
));
650 if (internal_relocs
== NULL
)
653 if (! link_info
->keep_memory
)
654 free_relocs
= internal_relocs
;
656 ia64_info
= elfNN_ia64_hash_table (link_info
);
657 irelend
= internal_relocs
+ sec
->reloc_count
;
659 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
660 if (ELFNN_R_TYPE (irel
->r_info
) == (int) R_IA64_PCREL21B
)
663 /* No branch-type relocations. */
666 if (free_relocs
!= NULL
)
671 /* Get the section contents. */
672 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
673 contents
= elf_section_data (sec
)->this_hdr
.contents
;
676 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
677 if (contents
== NULL
)
679 free_contents
= contents
;
681 if (! bfd_get_section_contents (abfd
, sec
, contents
,
682 (file_ptr
) 0, sec
->_raw_size
))
686 /* Read this BFD's symbols. */
687 if (symtab_hdr
->contents
!= NULL
)
688 extsyms
= (ElfNN_External_Sym
*) symtab_hdr
->contents
;
691 extsyms
= (ElfNN_External_Sym
*) bfd_malloc (symtab_hdr
->sh_size
);
694 free_extsyms
= extsyms
;
695 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
696 || (bfd_read (extsyms
, 1, symtab_hdr
->sh_size
, abfd
)
697 != symtab_hdr
->sh_size
))
701 for (; irel
< irelend
; irel
++)
703 bfd_vma symaddr
, reladdr
, trampoff
, toff
, roff
;
704 Elf_Internal_Sym isym
;
708 if (ELFNN_R_TYPE (irel
->r_info
) != (int) R_IA64_PCREL21B
)
711 /* Get the value of the symbol referred to by the reloc. */
712 if (ELFNN_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
714 /* A local symbol. */
715 bfd_elfNN_swap_symbol_in (abfd
,
716 extsyms
+ ELFNN_R_SYM (irel
->r_info
),
718 if (isym
.st_shndx
== SHN_UNDEF
)
719 continue; /* We can't do anthing with undefined symbols. */
720 else if (isym
.st_shndx
== SHN_ABS
)
721 tsec
= bfd_abs_section_ptr
;
722 else if (isym
.st_shndx
== SHN_COMMON
)
723 tsec
= bfd_com_section_ptr
;
724 else if (isym
.st_shndx
> 0 && isym
.st_shndx
< SHN_LORESERVE
)
725 tsec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
727 continue; /* who knows. */
729 toff
= isym
.st_value
;
734 struct elf_link_hash_entry
*h
;
735 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
737 indx
= ELFNN_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
738 h
= elf_sym_hashes (abfd
)[indx
];
739 BFD_ASSERT (h
!= NULL
);
741 while (h
->root
.type
== bfd_link_hash_indirect
742 || h
->root
.type
== bfd_link_hash_warning
)
743 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
745 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, irel
, false);
747 /* For branches to dynamic symbols, we're interested instead
748 in a branch to the PLT entry. */
749 if (dyn_i
&& dyn_i
->want_plt2
)
751 tsec
= ia64_info
->plt_sec
;
752 toff
= dyn_i
->plt2_offset
;
756 /* We can't do anthing with undefined symbols. */
757 if (h
->root
.type
== bfd_link_hash_undefined
758 || h
->root
.type
== bfd_link_hash_undefweak
)
761 tsec
= h
->root
.u
.def
.section
;
762 toff
= h
->root
.u
.def
.value
;
766 symaddr
= (tsec
->output_section
->vma
767 + tsec
->output_offset
771 roff
= irel
->r_offset
;
772 reladdr
= (sec
->output_section
->vma
776 /* If the branch is in range, no need to do anything. */
777 if ((bfd_signed_vma
) (symaddr
- reladdr
) >= -0x1000000
778 && (bfd_signed_vma
) (symaddr
- reladdr
) <= 0x0FFFFF0)
781 /* If the branch and target are in the same section, you've
782 got one honking big section and we can't help you. You'll
783 get an error message later. */
787 /* Look for an existing fixup to this address. */
788 for (f
= fixups
; f
; f
= f
->next
)
789 if (f
->tsec
== tsec
&& f
->toff
== toff
)
794 /* Two alternatives: If it's a branch to a PLT entry, we can
795 make a copy of the FULL_PLT entry. Otherwise, we'll have
796 to use a `brl' insn to get where we're going. */
800 if (tsec
== ia64_info
->plt_sec
)
801 size
= sizeof (plt_full_entry
);
805 size
= sizeof (oor_brl
);
807 size
= sizeof (oor_ip
);
811 /* Resize the current section to make room for the new branch. */
812 trampoff
= (sec
->_cooked_size
+ 15) & -16;
813 contents
= (bfd_byte
*) bfd_realloc (contents
, trampoff
+ size
);
814 if (contents
== NULL
)
816 sec
->_cooked_size
= trampoff
+ size
;
818 if (tsec
== ia64_info
->plt_sec
)
820 memcpy (contents
+ trampoff
, plt_full_entry
, size
);
822 /* Hijack the old relocation for use as the PLTOFF reloc. */
823 irel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (irel
->r_info
),
825 irel
->r_offset
= trampoff
;
830 memcpy (contents
+ trampoff
, oor_brl
, size
);
831 irel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (irel
->r_info
),
833 irel
->r_offset
= trampoff
+ 2;
835 memcpy (contents
+ trampoff
, oor_ip
, size
);
836 irel
->r_info
= ELFNN_R_INFO (ELFNN_R_SYM (irel
->r_info
),
838 irel
->r_addend
-= 16;
839 irel
->r_offset
= trampoff
+ 2;
843 /* Record the fixup so we don't do it again this section. */
844 f
= (struct one_fixup
*) bfd_malloc (sizeof (*f
));
848 f
->trampoff
= trampoff
;
853 /* Nop out the reloc, since we're finalizing things here. */
854 irel
->r_info
= ELFNN_R_INFO (0, R_IA64_NONE
);
857 /* Fix up the existing branch to hit the trampoline. Hope like
858 hell this doesn't overflow too. */
859 if (elfNN_ia64_install_value (abfd
, contents
+ roff
,
860 f
->trampoff
- (roff
& -4),
861 R_IA64_PCREL21B
) != bfd_reloc_ok
)
864 changed_contents
= true;
865 changed_relocs
= true;
868 /* Clean up and go home. */
871 struct one_fixup
*f
= fixups
;
872 fixups
= fixups
->next
;
877 elf_section_data (sec
)->relocs
= internal_relocs
;
878 else if (free_relocs
!= NULL
)
881 if (changed_contents
)
882 elf_section_data (sec
)->this_hdr
.contents
= contents
;
883 else if (free_contents
!= NULL
)
885 if (! link_info
->keep_memory
)
886 free (free_contents
);
889 /* Cache the section contents for elf_link_input_bfd. */
890 elf_section_data (sec
)->this_hdr
.contents
= contents
;
894 if (free_extsyms
!= NULL
)
896 if (! link_info
->keep_memory
)
900 /* Cache the symbols for elf_link_input_bfd. */
901 symtab_hdr
->contents
= extsyms
;
905 *again
= changed_contents
|| changed_relocs
;
909 if (free_relocs
!= NULL
)
911 if (free_contents
!= NULL
)
912 free (free_contents
);
913 if (free_extsyms
!= NULL
)
918 /* Return true if NAME is an unwind table section name. */
920 static inline boolean
921 is_unwind_section_name (name
)
926 len1
= sizeof (ELF_STRING_ia64_unwind
) - 1;
927 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
928 return (strncmp (name
, ELF_STRING_ia64_unwind
, len1
) == 0
929 && strncmp (name
, ELF_STRING_ia64_unwind_info
, len2
) != 0);
932 /* Handle an IA-64 specific section when reading an object file. This
933 is called when elfcode.h finds a section with an unknown type. */
936 elfNN_ia64_section_from_shdr (abfd
, hdr
, name
)
938 ElfNN_Internal_Shdr
*hdr
;
943 /* There ought to be a place to keep ELF backend specific flags, but
944 at the moment there isn't one. We just keep track of the
945 sections by their name, instead. Fortunately, the ABI gives
946 suggested names for all the MIPS specific sections, so we will
947 probably get away with this. */
948 switch (hdr
->sh_type
)
950 case SHT_IA_64_UNWIND
:
954 if (strcmp (name
, ELF_STRING_ia64_archext
) != 0)
962 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
964 newsect
= hdr
->bfd_section
;
969 /* Convert IA-64 specific section flags to bfd internal section flags. */
971 /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV
975 elfNN_ia64_section_flags (flags
, hdr
)
977 ElfNN_Internal_Shdr
*hdr
;
979 if (hdr
->sh_flags
& SHF_IA_64_SHORT
)
980 *flags
|= SEC_SMALL_DATA
;
985 /* Set the correct type for an IA-64 ELF section. We do this by the
986 section name, which is a hack, but ought to work. */
989 elfNN_ia64_fake_sections (abfd
, hdr
, sec
)
990 bfd
*abfd ATTRIBUTE_UNUSED
;
991 ElfNN_Internal_Shdr
*hdr
;
994 register const char *name
;
996 name
= bfd_get_section_name (abfd
, sec
);
998 if (is_unwind_section_name (name
))
1000 /* We don't have the sections numbered at this point, so sh_info
1001 is set later, in elfNN_ia64_final_write_processing. */
1002 hdr
->sh_type
= SHT_IA_64_UNWIND
;
1003 hdr
->sh_flags
|= SHF_LINK_ORDER
;
1005 else if (strcmp (name
, ELF_STRING_ia64_archext
) == 0)
1006 hdr
->sh_type
= SHT_IA_64_EXT
;
1007 else if (strcmp (name
, ".reloc") == 0)
1009 * This is an ugly, but unfortunately necessary hack that is
1010 * needed when producing EFI binaries on IA-64. It tells
1011 * elf.c:elf_fake_sections() not to consider ".reloc" as a section
1012 * containing ELF relocation info. We need this hack in order to
1013 * be able to generate ELF binaries that can be translated into
1014 * EFI applications (which are essentially COFF objects). Those
1015 * files contain a COFF ".reloc" section inside an ELFNN object,
1016 * which would normally cause BFD to segfault because it would
1017 * attempt to interpret this section as containing relocation
1018 * entries for section "oc". With this hack enabled, ".reloc"
1019 * will be treated as a normal data section, which will avoid the
1020 * segfault. However, you won't be able to create an ELFNN binary
1021 * with a section named "oc" that needs relocations, but that's
1022 * the kind of ugly side-effects you get when detecting section
1023 * types based on their names... In practice, this limitation is
1026 hdr
->sh_type
= SHT_PROGBITS
;
1028 if (sec
->flags
& SEC_SMALL_DATA
)
1029 hdr
->sh_flags
|= SHF_IA_64_SHORT
;
1034 /* The final processing done just before writing out an IA-64 ELF
1038 elfNN_ia64_final_write_processing (abfd
, linker
)
1040 boolean linker ATTRIBUTE_UNUSED
;
1042 Elf_Internal_Shdr
*hdr
;
1044 asection
*text_sect
, *s
;
1047 for (s
= abfd
->sections
; s
; s
= s
->next
)
1049 hdr
= &elf_section_data (s
)->this_hdr
;
1050 switch (hdr
->sh_type
)
1052 case SHT_IA_64_UNWIND
:
1053 /* See comments in gas/config/tc-ia64.c:dot_endp on why we
1055 sname
= bfd_get_section_name (abfd
, s
);
1056 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
1057 if (sname
&& strncmp (sname
, ELF_STRING_ia64_unwind
, len
) == 0)
1061 if (sname
[0] == '\0')
1062 /* .IA_64.unwind -> .text */
1063 text_sect
= bfd_get_section_by_name (abfd
, ".text");
1065 /* .IA_64.unwindFOO -> FOO */
1066 text_sect
= bfd_get_section_by_name (abfd
, sname
);
1069 /* last resort: fall back on .text */
1070 text_sect
= bfd_get_section_by_name (abfd
, ".text");
1074 /* The IA-64 processor-specific ABI requires setting
1075 sh_link to the unwind section, whereas HP-UX requires
1076 sh_info to do so. For maximum compatibility, we'll
1077 set both for now... */
1078 hdr
->sh_link
= elf_section_data (text_sect
)->this_idx
;
1079 hdr
->sh_info
= elf_section_data (text_sect
)->this_idx
;
1086 /* Hook called by the linker routine which adds symbols from an object
1087 file. We use it to put .comm items in .sbss, and not .bss. */
1090 elfNN_ia64_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1092 struct bfd_link_info
*info
;
1093 const Elf_Internal_Sym
*sym
;
1094 const char **namep ATTRIBUTE_UNUSED
;
1095 flagword
*flagsp ATTRIBUTE_UNUSED
;
1099 if (sym
->st_shndx
== SHN_COMMON
1100 && !info
->relocateable
1101 && sym
->st_size
<= (unsigned) bfd_get_gp_size (abfd
))
1103 /* Common symbols less than or equal to -G nn bytes are
1104 automatically put into .sbss. */
1106 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
1110 scomm
= bfd_make_section (abfd
, ".scommon");
1112 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
1114 | SEC_LINKER_CREATED
)))
1119 *valp
= sym
->st_size
;
1126 elfNN_ia64_aix_vec (const bfd_target
*vec
)
1128 extern const bfd_target bfd_elfNN_ia64_aix_little_vec
;
1129 extern const bfd_target bfd_elfNN_ia64_aix_big_vec
;
1131 return (/**/vec
== & bfd_elfNN_ia64_aix_little_vec
1132 || vec
== & bfd_elfNN_ia64_aix_big_vec
);
1135 /* Hook called by the linker routine which adds symbols from an object
1136 file. We use it to handle OS-specific symbols. */
1139 elfNN_ia64_aix_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1141 struct bfd_link_info
*info
;
1142 const Elf_Internal_Sym
*sym
;
1148 if (strcmp (*namep
, "__GLOB_DATA_PTR") == 0)
1150 /* Define __GLOB_DATA_PTR. This is expected to be a linker-defined
1151 symbol by the Aix C runtime startup code. Define the symbol
1152 when it is encountered. IBM sez no one else should use it b/c it is
1154 struct elf_link_hash_entry
*h
;
1156 h
= (struct elf_link_hash_entry
*) bfd_link_hash_lookup (info
->hash
, *namep
, false, false, false);
1159 struct elf_backend_data
*bed
;
1160 struct elfNN_ia64_link_hash_table
*ia64_info
;
1162 bed
= get_elf_backend_data (abfd
);
1163 ia64_info
= elfNN_ia64_hash_table (info
);
1165 if (!(_bfd_generic_link_add_one_symbol
1166 (info
, abfd
, *namep
, BSF_GLOBAL
, ia64_info
->got_sec
,
1167 bed
->got_symbol_offset
, (const char *) NULL
, false,
1168 bed
->collect
, (struct bfd_link_hash_entry
**) &h
)))
1171 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
1172 h
->type
= STT_OBJECT
;
1175 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1181 else if (sym
->st_shndx
== SHN_LOOS
)
1185 /* SHN_AIX_SYSCALL: Treat this as any other symbol. The special symbol
1186 is only relevant when compiling code for extended system calls.
1187 Replace the "special" section with .text, if possible. */
1188 /* FIXME need to determine the proper section instead of defaulting to
1190 for (i
= 1; i
< elf_elfheader (abfd
)->e_shnum
; i
++)
1192 asection
* sec
= bfd_section_from_elf_index (abfd
, i
);
1194 if (sec
&& strcmp (sec
->name
, ".text") == 0)
1202 *secp
= bfd_abs_section_ptr
;
1204 *valp
= sym
->st_size
;
1210 return elfNN_ia64_add_symbol_hook (abfd
, info
, sym
,
1211 namep
, flagsp
, secp
, valp
);
1216 elfNN_ia64_aix_link_add_symbols (abfd
, info
)
1218 struct bfd_link_info
*info
;
1220 /* Make sure dynamic sections are always created. */
1221 if (! elf_hash_table (info
)->dynamic_sections_created
1222 && abfd
->xvec
== info
->hash
->creator
)
1224 if (! bfd_elfNN_link_create_dynamic_sections (abfd
, info
))
1228 /* Now do the standard call. */
1229 return bfd_elfNN_bfd_link_add_symbols (abfd
, info
);
1232 /* Return the number of additional phdrs we will need. */
1235 elfNN_ia64_additional_program_headers (abfd
)
1241 /* See if we need a PT_IA_64_ARCHEXT segment. */
1242 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_archext
);
1243 if (s
&& (s
->flags
& SEC_LOAD
))
1246 /* Count how many PT_IA_64_UNWIND segments we need. */
1247 for (s
= abfd
->sections
; s
; s
= s
->next
)
1248 if (is_unwind_section_name(s
->name
) && (s
->flags
& SEC_LOAD
))
1255 elfNN_ia64_modify_segment_map (abfd
)
1258 struct elf_segment_map
*m
, **pm
;
1259 Elf_Internal_Shdr
*hdr
;
1262 /* If we need a PT_IA_64_ARCHEXT segment, it must come before
1263 all PT_LOAD segments. */
1264 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_archext
);
1265 if (s
&& (s
->flags
& SEC_LOAD
))
1267 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
1268 if (m
->p_type
== PT_IA_64_ARCHEXT
)
1272 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
1276 m
->p_type
= PT_IA_64_ARCHEXT
;
1280 /* We want to put it after the PHDR and INTERP segments. */
1281 pm
= &elf_tdata (abfd
)->segment_map
;
1283 && ((*pm
)->p_type
== PT_PHDR
1284 || (*pm
)->p_type
== PT_INTERP
))
1292 /* Install PT_IA_64_UNWIND segments, if needed. */
1293 for (s
= abfd
->sections
; s
; s
= s
->next
)
1295 hdr
= &elf_section_data (s
)->this_hdr
;
1296 if (hdr
->sh_type
!= SHT_IA_64_UNWIND
)
1299 if (s
&& (s
->flags
& SEC_LOAD
))
1301 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
1302 if (m
->p_type
== PT_IA_64_UNWIND
&& m
->sections
[0] == s
)
1307 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
1311 m
->p_type
= PT_IA_64_UNWIND
;
1316 /* We want to put it last. */
1317 pm
= &elf_tdata (abfd
)->segment_map
;
1325 /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of
1326 the input sections for each output section in the segment and testing
1327 for SHF_IA_64_NORECOV on each. */
1328 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
1329 if (m
->p_type
== PT_LOAD
)
1332 for (i
= m
->count
- 1; i
>= 0; --i
)
1334 struct bfd_link_order
*order
= m
->sections
[i
]->link_order_head
;
1337 if (order
->type
== bfd_indirect_link_order
)
1339 asection
*is
= order
->u
.indirect
.section
;
1340 bfd_vma flags
= elf_section_data(is
)->this_hdr
.sh_flags
;
1341 if (flags
& SHF_IA_64_NORECOV
)
1343 m
->p_flags
|= PF_IA_64_NORECOV
;
1347 order
= order
->next
;
1356 /* According to the Tahoe assembler spec, all labels starting with a
1360 elfNN_ia64_is_local_label_name (abfd
, name
)
1361 bfd
*abfd ATTRIBUTE_UNUSED
;
1364 return name
[0] == '.';
1367 /* Should we do dynamic things to this symbol? */
1370 elfNN_ia64_dynamic_symbol_p (h
, info
)
1371 struct elf_link_hash_entry
*h
;
1372 struct bfd_link_info
*info
;
1377 while (h
->root
.type
== bfd_link_hash_indirect
1378 || h
->root
.type
== bfd_link_hash_warning
)
1379 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1381 if (h
->dynindx
== -1)
1383 switch (ELF_ST_VISIBILITY (h
->other
))
1390 if (h
->root
.type
== bfd_link_hash_undefweak
1391 || h
->root
.type
== bfd_link_hash_defweak
)
1394 if ((info
->shared
&& !info
->symbolic
)
1395 || ((h
->elf_link_hash_flags
1396 & (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
))
1397 == (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
)))
1404 elfNN_ia64_local_hash_table_init (ht
, abfd
, new)
1405 struct elfNN_ia64_local_hash_table
*ht
;
1406 bfd
*abfd ATTRIBUTE_UNUSED
;
1407 new_hash_entry_func
new;
1409 memset (ht
, 0, sizeof (*ht
));
1410 return bfd_hash_table_init (&ht
->root
, new);
1413 static struct bfd_hash_entry
*
1414 elfNN_ia64_new_loc_hash_entry (entry
, table
, string
)
1415 struct bfd_hash_entry
*entry
;
1416 struct bfd_hash_table
*table
;
1419 struct elfNN_ia64_local_hash_entry
*ret
;
1420 ret
= (struct elfNN_ia64_local_hash_entry
*) entry
;
1422 /* Allocate the structure if it has not already been allocated by a
1425 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
1430 /* Initialize our local data. All zeros, and definitely easier
1431 than setting a handful of bit fields. */
1432 memset (ret
, 0, sizeof (*ret
));
1434 /* Call the allocation method of the superclass. */
1435 ret
= ((struct elfNN_ia64_local_hash_entry
*)
1436 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
1438 return (struct bfd_hash_entry
*) ret
;
1441 static struct bfd_hash_entry
*
1442 elfNN_ia64_new_elf_hash_entry (entry
, table
, string
)
1443 struct bfd_hash_entry
*entry
;
1444 struct bfd_hash_table
*table
;
1447 struct elfNN_ia64_link_hash_entry
*ret
;
1448 ret
= (struct elfNN_ia64_link_hash_entry
*) entry
;
1450 /* Allocate the structure if it has not already been allocated by a
1453 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
1458 /* Initialize our local data. All zeros, and definitely easier
1459 than setting a handful of bit fields. */
1460 memset (ret
, 0, sizeof (*ret
));
1462 /* Call the allocation method of the superclass. */
1463 ret
= ((struct elfNN_ia64_link_hash_entry
*)
1464 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1467 return (struct bfd_hash_entry
*) ret
;
1471 elfNN_ia64_hash_copy_indirect (xdir
, xind
)
1472 struct elf_link_hash_entry
*xdir
, *xind
;
1474 struct elfNN_ia64_link_hash_entry
*dir
, *ind
;
1476 dir
= (struct elfNN_ia64_link_hash_entry
*)xdir
;
1477 ind
= (struct elfNN_ia64_link_hash_entry
*)xind
;
1479 /* Copy down any references that we may have already seen to the
1480 symbol which just became indirect. */
1482 dir
->root
.elf_link_hash_flags
|=
1483 (ind
->root
.elf_link_hash_flags
1484 & (ELF_LINK_HASH_REF_DYNAMIC
1485 | ELF_LINK_HASH_REF_REGULAR
1486 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
1488 /* Copy over the got and plt data. This would have been done
1491 if (dir
->info
== NULL
)
1493 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1495 dir
->info
= dyn_i
= ind
->info
;
1498 /* Fix up the dyn_sym_info pointers to the global symbol. */
1499 for (; dyn_i
; dyn_i
= dyn_i
->next
)
1500 dyn_i
->h
= &dir
->root
;
1502 BFD_ASSERT (ind
->info
== NULL
);
1504 /* Copy over the dynindx. */
1506 if (dir
->root
.dynindx
== -1)
1508 dir
->root
.dynindx
= ind
->root
.dynindx
;
1509 dir
->root
.dynstr_index
= ind
->root
.dynstr_index
;
1510 ind
->root
.dynindx
= -1;
1511 ind
->root
.dynstr_index
= 0;
1513 BFD_ASSERT (ind
->root
.dynindx
== -1);
1517 elfNN_ia64_hash_hide_symbol (info
, xh
)
1518 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1519 struct elf_link_hash_entry
*xh
;
1521 struct elfNN_ia64_link_hash_entry
*h
;
1522 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1524 h
= (struct elfNN_ia64_link_hash_entry
*)xh
;
1526 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1527 h
->root
.dynindx
= -1;
1529 for (dyn_i
= h
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1530 dyn_i
->want_plt2
= 0;
1533 /* Create the derived linker hash table. The IA-64 ELF port uses this
1534 derived hash table to keep information specific to the IA-64 ElF
1535 linker (without using static variables). */
1537 static struct bfd_link_hash_table
*
1538 elfNN_ia64_hash_table_create (abfd
)
1541 struct elfNN_ia64_link_hash_table
*ret
;
1543 ret
= bfd_alloc (abfd
, sizeof (*ret
));
1546 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1547 elfNN_ia64_new_elf_hash_entry
))
1549 bfd_release (abfd
, ret
);
1553 if (!elfNN_ia64_local_hash_table_init (&ret
->loc_hash_table
, abfd
,
1554 elfNN_ia64_new_loc_hash_entry
))
1556 return &ret
->root
.root
;
1559 /* Look up an entry in a Alpha ELF linker hash table. */
1561 static INLINE
struct elfNN_ia64_local_hash_entry
*
1562 elfNN_ia64_local_hash_lookup(table
, string
, create
, copy
)
1563 struct elfNN_ia64_local_hash_table
*table
;
1565 boolean create
, copy
;
1567 return ((struct elfNN_ia64_local_hash_entry
*)
1568 bfd_hash_lookup (&table
->root
, string
, create
, copy
));
1571 /* Traverse both local and global hash tables. */
1573 struct elfNN_ia64_dyn_sym_traverse_data
1575 boolean (*func
) PARAMS ((struct elfNN_ia64_dyn_sym_info
*, PTR
));
1580 elfNN_ia64_global_dyn_sym_thunk (xentry
, xdata
)
1581 struct bfd_hash_entry
*xentry
;
1584 struct elfNN_ia64_link_hash_entry
*entry
1585 = (struct elfNN_ia64_link_hash_entry
*) xentry
;
1586 struct elfNN_ia64_dyn_sym_traverse_data
*data
1587 = (struct elfNN_ia64_dyn_sym_traverse_data
*) xdata
;
1588 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1590 for (dyn_i
= entry
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1591 if (! (*data
->func
) (dyn_i
, data
->data
))
1597 elfNN_ia64_local_dyn_sym_thunk (xentry
, xdata
)
1598 struct bfd_hash_entry
*xentry
;
1601 struct elfNN_ia64_local_hash_entry
*entry
1602 = (struct elfNN_ia64_local_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_dyn_sym_traverse (ia64_info
, func
, data
)
1615 struct elfNN_ia64_link_hash_table
*ia64_info
;
1616 boolean (*func
) PARAMS ((struct elfNN_ia64_dyn_sym_info
*, PTR
));
1619 struct elfNN_ia64_dyn_sym_traverse_data xdata
;
1624 elf_link_hash_traverse (&ia64_info
->root
,
1625 elfNN_ia64_global_dyn_sym_thunk
, &xdata
);
1626 bfd_hash_traverse (&ia64_info
->loc_hash_table
.root
,
1627 elfNN_ia64_local_dyn_sym_thunk
, &xdata
);
1631 elfNN_ia64_create_dynamic_sections (abfd
, info
)
1633 struct bfd_link_info
*info
;
1635 struct elfNN_ia64_link_hash_table
*ia64_info
;
1638 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1641 ia64_info
= elfNN_ia64_hash_table (info
);
1643 ia64_info
->plt_sec
= bfd_get_section_by_name (abfd
, ".plt");
1644 ia64_info
->got_sec
= bfd_get_section_by_name (abfd
, ".got");
1647 flagword flags
= bfd_get_section_flags (abfd
, ia64_info
->got_sec
);
1648 bfd_set_section_flags (abfd
, ia64_info
->got_sec
, SEC_SMALL_DATA
| flags
);
1651 if (!get_pltoff (abfd
, info
, ia64_info
))
1654 s
= bfd_make_section(abfd
, ".rela.IA_64.pltoff");
1656 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1659 | SEC_LINKER_CREATED
1661 || !bfd_set_section_alignment (abfd
, s
, 3))
1663 ia64_info
->rel_pltoff_sec
= s
;
1665 s
= bfd_make_section(abfd
, ".rela.got");
1667 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1670 | SEC_LINKER_CREATED
1672 || !bfd_set_section_alignment (abfd
, s
, 3))
1674 ia64_info
->rel_got_sec
= s
;
1679 /* Find and/or create a descriptor for dynamic symbol info. This will
1680 vary based on global or local symbol, and the addend to the reloc. */
1682 static struct elfNN_ia64_dyn_sym_info
*
1683 get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, create
)
1684 struct elfNN_ia64_link_hash_table
*ia64_info
;
1685 struct elf_link_hash_entry
*h
;
1687 const Elf_Internal_Rela
*rel
;
1690 struct elfNN_ia64_dyn_sym_info
**pp
;
1691 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1692 bfd_vma addend
= rel
? rel
->r_addend
: 0;
1695 pp
= &((struct elfNN_ia64_link_hash_entry
*)h
)->info
;
1698 struct elfNN_ia64_local_hash_entry
*loc_h
;
1702 /* Construct a string for use in the elfNN_ia64_local_hash_table.
1703 The name describes what was once anonymous memory. */
1705 len
= sizeof (void*)*2 + 1 + sizeof (bfd_vma
)*4 + 1 + 1;
1706 len
+= 10; /* %p slop */
1708 addr_name
= alloca (len
);
1709 sprintf (addr_name
, "%p:%lx", (void *) abfd
, ELFNN_R_SYM (rel
->r_info
));
1711 /* Collect the canonical entry data for this address. */
1712 loc_h
= elfNN_ia64_local_hash_lookup (&ia64_info
->loc_hash_table
,
1713 addr_name
, create
, create
);
1719 for (dyn_i
= *pp
; dyn_i
&& dyn_i
->addend
!= addend
; dyn_i
= *pp
)
1722 if (dyn_i
== NULL
&& create
)
1724 dyn_i
= (struct elfNN_ia64_dyn_sym_info
*)
1725 bfd_zalloc (abfd
, sizeof *dyn_i
);
1727 dyn_i
->addend
= addend
;
1734 get_got (abfd
, info
, ia64_info
)
1736 struct bfd_link_info
*info
;
1737 struct elfNN_ia64_link_hash_table
*ia64_info
;
1742 got
= ia64_info
->got_sec
;
1747 dynobj
= ia64_info
->root
.dynobj
;
1749 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1750 if (!_bfd_elf_create_got_section (dynobj
, info
))
1753 got
= bfd_get_section_by_name (dynobj
, ".got");
1755 ia64_info
->got_sec
= got
;
1757 flags
= bfd_get_section_flags (abfd
, got
);
1758 bfd_set_section_flags (abfd
, got
, SEC_SMALL_DATA
| flags
);
1764 /* Create function descriptor section (.opd). This section is called .opd
1765 because it contains "official prodecure descriptors". The "official"
1766 refers to the fact that these descriptors are used when taking the address
1767 of a procedure, thus ensuring a unique address for each procedure. */
1770 get_fptr (abfd
, info
, ia64_info
)
1772 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1773 struct elfNN_ia64_link_hash_table
*ia64_info
;
1778 fptr
= ia64_info
->fptr_sec
;
1781 dynobj
= ia64_info
->root
.dynobj
;
1783 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1785 fptr
= bfd_make_section (dynobj
, ".opd");
1787 || !bfd_set_section_flags (dynobj
, fptr
,
1793 | SEC_LINKER_CREATED
))
1794 || !bfd_set_section_alignment (abfd
, fptr
, 4))
1800 ia64_info
->fptr_sec
= fptr
;
1807 get_pltoff (abfd
, info
, ia64_info
)
1809 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1810 struct elfNN_ia64_link_hash_table
*ia64_info
;
1815 pltoff
= ia64_info
->pltoff_sec
;
1818 dynobj
= ia64_info
->root
.dynobj
;
1820 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1822 pltoff
= bfd_make_section (dynobj
, ELF_STRING_ia64_pltoff
);
1824 || !bfd_set_section_flags (dynobj
, pltoff
,
1830 | SEC_LINKER_CREATED
))
1831 || !bfd_set_section_alignment (abfd
, pltoff
, 4))
1837 ia64_info
->pltoff_sec
= pltoff
;
1844 get_reloc_section (abfd
, ia64_info
, sec
, create
)
1846 struct elfNN_ia64_link_hash_table
*ia64_info
;
1850 const char *srel_name
;
1854 srel_name
= (bfd_elf_string_from_elf_section
1855 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1856 elf_section_data(sec
)->rel_hdr
.sh_name
));
1857 if (srel_name
== NULL
)
1860 BFD_ASSERT ((strncmp (srel_name
, ".rela", 5) == 0
1861 && strcmp (bfd_get_section_name (abfd
, sec
),
1863 || (strncmp (srel_name
, ".rel", 4) == 0
1864 && strcmp (bfd_get_section_name (abfd
, sec
),
1865 srel_name
+4) == 0));
1867 dynobj
= ia64_info
->root
.dynobj
;
1869 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1871 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
1872 if (srel
== NULL
&& create
)
1874 srel
= bfd_make_section (dynobj
, srel_name
);
1876 || !bfd_set_section_flags (dynobj
, srel
,
1881 | SEC_LINKER_CREATED
1883 || !bfd_set_section_alignment (dynobj
, srel
, 3))
1891 count_dyn_reloc (abfd
, dyn_i
, srel
, type
)
1893 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1897 struct elfNN_ia64_dyn_reloc_entry
*rent
;
1899 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
1900 if (rent
->srel
== srel
&& rent
->type
== type
)
1905 rent
= (struct elfNN_ia64_dyn_reloc_entry
*)
1906 bfd_alloc (abfd
, sizeof (*rent
));
1910 rent
->next
= dyn_i
->reloc_entries
;
1914 dyn_i
->reloc_entries
= rent
;
1922 elfNN_ia64_check_relocs (abfd
, info
, sec
, relocs
)
1924 struct bfd_link_info
*info
;
1926 const Elf_Internal_Rela
*relocs
;
1928 struct elfNN_ia64_link_hash_table
*ia64_info
;
1929 const Elf_Internal_Rela
*relend
;
1930 Elf_Internal_Shdr
*symtab_hdr
;
1931 const Elf_Internal_Rela
*rel
;
1932 asection
*got
, *fptr
, *srel
;
1934 if (info
->relocateable
)
1937 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1938 ia64_info
= elfNN_ia64_hash_table (info
);
1940 got
= fptr
= srel
= NULL
;
1942 relend
= relocs
+ sec
->reloc_count
;
1943 for (rel
= relocs
; rel
< relend
; ++rel
)
1952 NEED_LTOFF_FPTR
= 64,
1955 struct elf_link_hash_entry
*h
= NULL
;
1956 unsigned long r_symndx
= ELFNN_R_SYM (rel
->r_info
);
1957 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
1959 boolean maybe_dynamic
;
1960 int dynrel_type
= R_IA64_NONE
;
1962 if (r_symndx
>= symtab_hdr
->sh_info
)
1964 /* We're dealing with a global symbol -- find its hash entry
1965 and mark it as being referenced. */
1966 long indx
= r_symndx
- symtab_hdr
->sh_info
;
1967 h
= elf_sym_hashes (abfd
)[indx
];
1968 while (h
->root
.type
== bfd_link_hash_indirect
1969 || h
->root
.type
== bfd_link_hash_warning
)
1970 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1972 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
1975 /* We can only get preliminary data on whether a symbol is
1976 locally or externally defined, as not all of the input files
1977 have yet been processed. Do something with what we know, as
1978 this may help reduce memory usage and processing time later. */
1979 maybe_dynamic
= false;
1980 if (h
&& ((info
->shared
&& ! info
->symbolic
)
1981 || ! (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
1982 || h
->root
.type
== bfd_link_hash_defweak
1983 || elfNN_ia64_aix_vec (abfd
->xvec
)))
1984 maybe_dynamic
= true;
1987 switch (ELFNN_R_TYPE (rel
->r_info
))
1989 case R_IA64_TPREL22
:
1990 case R_IA64_TPREL64MSB
:
1991 case R_IA64_TPREL64LSB
:
1992 case R_IA64_LTOFF_TP22
:
1995 case R_IA64_LTOFF_FPTR22
:
1996 case R_IA64_LTOFF_FPTR64I
:
1997 case R_IA64_LTOFF_FPTR64MSB
:
1998 case R_IA64_LTOFF_FPTR64LSB
:
1999 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
2002 case R_IA64_FPTR64I
:
2003 case R_IA64_FPTR32MSB
:
2004 case R_IA64_FPTR32LSB
:
2005 case R_IA64_FPTR64MSB
:
2006 case R_IA64_FPTR64LSB
:
2007 if (elfNN_ia64_aix_vec (abfd
->xvec
))
2008 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2009 else if (info
->shared
|| h
)
2010 need_entry
= NEED_FPTR
| NEED_DYNREL
;
2012 need_entry
= NEED_FPTR
;
2013 dynrel_type
= R_IA64_FPTR64LSB
;
2016 case R_IA64_LTOFF22
:
2017 case R_IA64_LTOFF22X
:
2018 case R_IA64_LTOFF64I
:
2019 need_entry
= NEED_GOT
;
2022 case R_IA64_PLTOFF22
:
2023 case R_IA64_PLTOFF64I
:
2024 case R_IA64_PLTOFF64MSB
:
2025 case R_IA64_PLTOFF64LSB
:
2026 need_entry
= NEED_PLTOFF
;
2030 need_entry
|= NEED_MIN_PLT
;
2034 (*info
->callbacks
->warning
)
2035 (info
, _("@pltoff reloc against local symbol"), 0,
2040 case R_IA64_PCREL21B
:
2041 case R_IA64_PCREL60B
:
2042 /* Depending on where this symbol is defined, we may or may not
2043 need a full plt entry. Only skip if we know we'll not need
2044 the entry -- static or symbolic, and the symbol definition
2045 has already been seen. */
2046 if (maybe_dynamic
&& rel
->r_addend
== 0)
2047 need_entry
= NEED_FULL_PLT
;
2053 case R_IA64_DIR32MSB
:
2054 case R_IA64_DIR32LSB
:
2055 case R_IA64_DIR64MSB
:
2056 case R_IA64_DIR64LSB
:
2057 /* Shared objects will always need at least a REL relocation. */
2058 if (info
->shared
|| maybe_dynamic
2059 /* On AIX, we always need a relocation, but make sure
2060 __GLOB_DATA_PTR doesn't get an entry. */
2061 || (elfNN_ia64_aix_vec (abfd
->xvec
)
2062 && (!h
|| strcmp (h
->root
.root
.string
,
2063 "__GLOB_DATA_PTR") != 0)))
2064 need_entry
= NEED_DYNREL
;
2065 dynrel_type
= R_IA64_DIR64LSB
;
2068 case R_IA64_IPLTMSB
:
2069 case R_IA64_IPLTLSB
:
2070 /* Shared objects will always need at least a REL relocation. */
2071 if (info
->shared
|| maybe_dynamic
)
2072 need_entry
= NEED_DYNREL
;
2073 dynrel_type
= R_IA64_IPLTLSB
;
2076 case R_IA64_PCREL22
:
2077 case R_IA64_PCREL64I
:
2078 case R_IA64_PCREL32MSB
:
2079 case R_IA64_PCREL32LSB
:
2080 case R_IA64_PCREL64MSB
:
2081 case R_IA64_PCREL64LSB
:
2083 need_entry
= NEED_DYNREL
;
2084 dynrel_type
= R_IA64_PCREL64LSB
;
2091 if ((need_entry
& NEED_FPTR
) != 0
2094 (*info
->callbacks
->warning
)
2095 (info
, _("non-zero addend in @fptr reloc"), 0,
2099 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, true);
2101 /* Record whether or not this is a local symbol. */
2104 /* Create what's needed. */
2105 if (need_entry
& NEED_GOT
)
2109 got
= get_got (abfd
, info
, ia64_info
);
2113 dyn_i
->want_got
= 1;
2115 if (need_entry
& NEED_FPTR
)
2119 fptr
= get_fptr (abfd
, info
, ia64_info
);
2124 /* FPTRs for shared libraries are allocated by the dynamic
2125 linker. Make sure this local symbol will appear in the
2126 dynamic symbol table. */
2127 if (!h
&& (info
->shared
2128 /* AIX also needs one */
2129 || elfNN_ia64_aix_vec (abfd
->xvec
)))
2131 if (! (_bfd_elfNN_link_record_local_dynamic_symbol
2132 (info
, abfd
, r_symndx
)))
2136 dyn_i
->want_fptr
= 1;
2138 if (need_entry
& NEED_LTOFF_FPTR
)
2139 dyn_i
->want_ltoff_fptr
= 1;
2140 if (need_entry
& (NEED_MIN_PLT
| NEED_FULL_PLT
))
2142 if (!ia64_info
->root
.dynobj
)
2143 ia64_info
->root
.dynobj
= abfd
;
2144 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2145 dyn_i
->want_plt
= 1;
2147 if (need_entry
& NEED_FULL_PLT
)
2148 dyn_i
->want_plt2
= 1;
2149 if (need_entry
& NEED_PLTOFF
)
2150 dyn_i
->want_pltoff
= 1;
2151 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
2155 srel
= get_reloc_section (abfd
, ia64_info
, sec
, true);
2159 if (!count_dyn_reloc (abfd
, dyn_i
, srel
, dynrel_type
))
2167 struct elfNN_ia64_allocate_data
2169 struct bfd_link_info
*info
;
2173 /* For cleanliness, and potentially faster dynamic loading, allocate
2174 external GOT entries first. */
2177 allocate_global_data_got (dyn_i
, data
)
2178 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2181 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2184 && ! dyn_i
->want_fptr
2185 && (elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2186 || elfNN_ia64_aix_vec (x
->info
->hash
->creator
)))
2188 dyn_i
->got_offset
= x
->ofs
;
2194 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
2197 allocate_global_fptr_got (dyn_i
, data
)
2198 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2201 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2205 && (elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2206 || elfNN_ia64_aix_vec (x
->info
->hash
->creator
)))
2208 dyn_i
->got_offset
= x
->ofs
;
2214 /* Lastly, allocate all the GOT entries for local data. */
2217 allocate_local_got (dyn_i
, data
)
2218 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2221 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2224 && ! (elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2225 || elfNN_ia64_aix_vec (x
->info
->hash
->creator
)))
2227 dyn_i
->got_offset
= x
->ofs
;
2233 /* Search for the index of a global symbol in it's defining object file. */
2235 static unsigned long
2236 global_sym_index (h
)
2237 struct elf_link_hash_entry
*h
;
2239 struct elf_link_hash_entry
**p
;
2242 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2243 || h
->root
.type
== bfd_link_hash_defweak
);
2245 obj
= h
->root
.u
.def
.section
->owner
;
2246 for (p
= elf_sym_hashes (obj
); *p
!= h
; ++p
)
2249 return p
- elf_sym_hashes (obj
) + elf_tdata (obj
)->symtab_hdr
.sh_info
;
2252 /* Allocate function descriptors. We can do these for every function
2253 in a main executable that is not exported. */
2256 allocate_fptr (dyn_i
, data
)
2257 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2260 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2262 if (dyn_i
->want_fptr
)
2264 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2267 while (h
->root
.type
== bfd_link_hash_indirect
2268 || h
->root
.type
== bfd_link_hash_warning
)
2269 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2272 /* AIX needs an FPTR in this case. */
2273 || (elfNN_ia64_aix_vec (x
->info
->hash
->creator
)
2275 || h
->root
.type
== bfd_link_hash_defined
2276 || h
->root
.type
== bfd_link_hash_defweak
)))
2278 if (h
&& h
->dynindx
== -1)
2280 BFD_ASSERT ((h
->root
.type
== bfd_link_hash_defined
)
2281 || (h
->root
.type
== bfd_link_hash_defweak
));
2283 if (!_bfd_elfNN_link_record_local_dynamic_symbol
2284 (x
->info
, h
->root
.u
.def
.section
->owner
,
2285 global_sym_index (h
)))
2289 dyn_i
->want_fptr
= 0;
2291 else if (h
== NULL
|| h
->dynindx
== -1)
2293 dyn_i
->fptr_offset
= x
->ofs
;
2297 dyn_i
->want_fptr
= 0;
2302 /* Allocate all the minimal PLT entries. */
2305 allocate_plt_entries (dyn_i
, data
)
2306 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2309 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2311 if (dyn_i
->want_plt
)
2313 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2316 while (h
->root
.type
== bfd_link_hash_indirect
2317 || h
->root
.type
== bfd_link_hash_warning
)
2318 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2320 /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */
2321 if (elfNN_ia64_dynamic_symbol_p (h
, x
->info
))
2323 bfd_size_type offset
= x
->ofs
;
2325 offset
= PLT_HEADER_SIZE
;
2326 dyn_i
->plt_offset
= offset
;
2327 x
->ofs
= offset
+ PLT_MIN_ENTRY_SIZE
;
2329 dyn_i
->want_pltoff
= 1;
2333 dyn_i
->want_plt
= 0;
2334 dyn_i
->want_plt2
= 0;
2340 /* Allocate all the full PLT entries. */
2343 allocate_plt2_entries (dyn_i
, data
)
2344 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2347 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2349 if (dyn_i
->want_plt2
)
2351 struct elf_link_hash_entry
*h
= dyn_i
->h
;
2352 bfd_size_type ofs
= x
->ofs
;
2354 dyn_i
->plt2_offset
= ofs
;
2355 x
->ofs
= ofs
+ PLT_FULL_ENTRY_SIZE
;
2357 while (h
->root
.type
== bfd_link_hash_indirect
2358 || h
->root
.type
== bfd_link_hash_warning
)
2359 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2360 dyn_i
->h
->plt
.offset
= ofs
;
2365 /* Allocate all the PLTOFF entries requested by relocations and
2366 plt entries. We can't share space with allocated FPTR entries,
2367 because the latter are not necessarily addressable by the GP.
2368 ??? Relaxation might be able to determine that they are. */
2371 allocate_pltoff_entries (dyn_i
, data
)
2372 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2375 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2377 if (dyn_i
->want_pltoff
)
2379 dyn_i
->pltoff_offset
= x
->ofs
;
2385 /* Allocate dynamic relocations for those symbols that turned out
2389 allocate_dynrel_entries (dyn_i
, data
)
2390 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
2393 struct elfNN_ia64_allocate_data
*x
= (struct elfNN_ia64_allocate_data
*)data
;
2394 struct elfNN_ia64_link_hash_table
*ia64_info
;
2395 struct elfNN_ia64_dyn_reloc_entry
*rent
;
2396 boolean dynamic_symbol
, shared
;
2398 ia64_info
= elfNN_ia64_hash_table (x
->info
);
2399 dynamic_symbol
= elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
)
2400 || elfNN_ia64_aix_vec (x
->info
->hash
->creator
);
2401 shared
= x
->info
->shared
;
2403 /* Take care of the normal data relocations. */
2405 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
2407 int count
= rent
->count
;
2411 case R_IA64_FPTR64LSB
:
2412 /* Allocate one iff !want_fptr, which by this point will
2413 be true only if we're actually allocating one statically
2414 in the main executable. */
2415 if (dyn_i
->want_fptr
)
2418 case R_IA64_PCREL64LSB
:
2419 if (!dynamic_symbol
)
2422 case R_IA64_DIR64LSB
:
2423 if (!dynamic_symbol
&& !shared
)
2426 case R_IA64_IPLTLSB
:
2427 if (!dynamic_symbol
&& !shared
)
2429 /* Use two REL relocations for IPLT relocations
2430 against local symbols. */
2431 if (!dynamic_symbol
)
2437 rent
->srel
->_raw_size
+= sizeof (ElfNN_External_Rela
) * count
;
2440 /* Take care of the GOT and PLT relocations. */
2442 if (((dynamic_symbol
|| shared
) && dyn_i
->want_got
)
2443 || (dyn_i
->want_ltoff_fptr
&& dyn_i
->h
&& dyn_i
->h
->dynindx
!= -1))
2444 ia64_info
->rel_got_sec
->_raw_size
+= sizeof (ElfNN_External_Rela
);
2446 if (dyn_i
->want_pltoff
)
2448 bfd_size_type t
= 0;
2450 /* Dynamic symbols get one IPLT relocation. Local symbols in
2451 shared libraries get two REL relocations. Local symbols in
2452 main applications get nothing. */
2454 t
= sizeof (ElfNN_External_Rela
);
2456 t
= 2 * sizeof (ElfNN_External_Rela
);
2458 ia64_info
->rel_pltoff_sec
->_raw_size
+= t
;
2465 elfNN_ia64_adjust_dynamic_symbol (info
, h
)
2466 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2467 struct elf_link_hash_entry
*h
;
2469 /* ??? Undefined symbols with PLT entries should be re-defined
2470 to be the PLT entry. */
2472 /* If this is a weak symbol, and there is a real definition, the
2473 processor independent code will have arranged for us to see the
2474 real definition first, and we can just use the same value. */
2475 if (h
->weakdef
!= NULL
)
2477 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2478 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2479 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2480 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2484 /* If this is a reference to a symbol defined by a dynamic object which
2485 is not a function, we might allocate the symbol in our .dynbss section
2486 and allocate a COPY dynamic relocation.
2488 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
2495 elfNN_ia64_size_dynamic_sections (output_bfd
, info
)
2497 struct bfd_link_info
*info
;
2499 struct elfNN_ia64_allocate_data data
;
2500 struct elfNN_ia64_link_hash_table
*ia64_info
;
2503 boolean reltext
= false;
2504 boolean relplt
= false;
2506 dynobj
= elf_hash_table(info
)->dynobj
;
2507 ia64_info
= elfNN_ia64_hash_table (info
);
2508 BFD_ASSERT(dynobj
!= NULL
);
2511 /* Set the contents of the .interp section to the interpreter. */
2512 if (ia64_info
->root
.dynamic_sections_created
2515 sec
= bfd_get_section_by_name (dynobj
, ".interp");
2516 BFD_ASSERT (sec
!= NULL
);
2517 sec
->contents
= (bfd_byte
*) DYNAMIC_INTERPRETER (output_bfd
);
2518 sec
->_raw_size
= strlen (DYNAMIC_INTERPRETER (output_bfd
)) + 1;
2521 /* Allocate the GOT entries. */
2523 if (ia64_info
->got_sec
)
2526 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_global_data_got
, &data
);
2527 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_global_fptr_got
, &data
);
2528 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_local_got
, &data
);
2529 ia64_info
->got_sec
->_raw_size
= data
.ofs
;
2532 /* Allocate the FPTR entries. */
2534 if (ia64_info
->fptr_sec
)
2537 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_fptr
, &data
);
2538 ia64_info
->fptr_sec
->_raw_size
= data
.ofs
;
2541 /* Now that we've seen all of the input files, we can decide which
2542 symbols need plt entries. Allocate the minimal PLT entries first.
2543 We do this even though dynamic_sections_created may be false, because
2544 this has the side-effect of clearing want_plt and want_plt2. */
2547 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_plt_entries
, &data
);
2549 ia64_info
->minplt_entries
= 0;
2552 ia64_info
->minplt_entries
2553 = (data
.ofs
- PLT_HEADER_SIZE
) / PLT_MIN_ENTRY_SIZE
;
2556 /* Align the pointer for the plt2 entries. */
2557 data
.ofs
= (data
.ofs
+ 31) & -32;
2559 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_plt2_entries
, &data
);
2562 BFD_ASSERT (ia64_info
->root
.dynamic_sections_created
);
2564 ia64_info
->plt_sec
->_raw_size
= data
.ofs
;
2566 /* If we've got a .plt, we need some extra memory for the dynamic
2567 linker. We stuff these in .got.plt. */
2568 sec
= bfd_get_section_by_name (dynobj
, ".got.plt");
2569 sec
->_raw_size
= 8 * PLT_RESERVED_WORDS
;
2572 /* Allocate the PLTOFF entries. */
2574 if (ia64_info
->pltoff_sec
)
2577 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_pltoff_entries
, &data
);
2578 ia64_info
->pltoff_sec
->_raw_size
= data
.ofs
;
2581 if (ia64_info
->root
.dynamic_sections_created
)
2583 /* Allocate space for the dynamic relocations that turned out to be
2586 elfNN_ia64_dyn_sym_traverse (ia64_info
, allocate_dynrel_entries
, &data
);
2589 /* We have now determined the sizes of the various dynamic sections.
2590 Allocate memory for them. */
2591 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2595 if (!(sec
->flags
& SEC_LINKER_CREATED
))
2598 /* If we don't need this section, strip it from the output file.
2599 There were several sections primarily related to dynamic
2600 linking that must be create before the linker maps input
2601 sections to output sections. The linker does that before
2602 bfd_elf_size_dynamic_sections is called, and it is that
2603 function which decides whether anything needs to go into
2606 strip
= (sec
->_raw_size
== 0);
2608 if (sec
== ia64_info
->got_sec
)
2610 else if (sec
== ia64_info
->rel_got_sec
)
2613 ia64_info
->rel_got_sec
= NULL
;
2615 /* We use the reloc_count field as a counter if we need to
2616 copy relocs into the output file. */
2617 sec
->reloc_count
= 0;
2619 else if (sec
== ia64_info
->fptr_sec
)
2622 ia64_info
->fptr_sec
= NULL
;
2624 else if (sec
== ia64_info
->plt_sec
)
2627 ia64_info
->plt_sec
= NULL
;
2629 else if (sec
== ia64_info
->pltoff_sec
)
2632 ia64_info
->pltoff_sec
= NULL
;
2634 else if (sec
== ia64_info
->rel_pltoff_sec
)
2637 ia64_info
->rel_pltoff_sec
= NULL
;
2641 /* We use the reloc_count field as a counter if we need to
2642 copy relocs into the output file. */
2643 sec
->reloc_count
= 0;
2650 /* It's OK to base decisions on the section name, because none
2651 of the dynobj section names depend upon the input files. */
2652 name
= bfd_get_section_name (dynobj
, sec
);
2654 if (strcmp (name
, ".got.plt") == 0)
2656 else if (strncmp (name
, ".rel", 4) == 0)
2660 const char *outname
;
2663 /* If this relocation section applies to a read only
2664 section, then we probably need a DT_TEXTREL entry. */
2665 outname
= bfd_get_section_name (output_bfd
,
2666 sec
->output_section
);
2667 if (outname
[4] == 'a')
2672 target
= bfd_get_section_by_name (output_bfd
, outname
);
2674 && (target
->flags
& SEC_READONLY
) != 0
2675 && (target
->flags
& SEC_ALLOC
) != 0)
2678 /* We use the reloc_count field as a counter if we need to
2679 copy relocs into the output file. */
2680 sec
->reloc_count
= 0;
2688 _bfd_strip_section_from_output (info
, sec
);
2691 /* Allocate memory for the section contents. */
2692 sec
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, sec
->_raw_size
);
2693 if (sec
->contents
== NULL
&& sec
->_raw_size
!= 0)
2698 if (elf_hash_table (info
)->dynamic_sections_created
)
2700 /* Add some entries to the .dynamic section. We fill in the values
2701 later (in finish_dynamic_sections) but we must add the entries now
2702 so that we get the correct size for the .dynamic section. */
2706 /* The DT_DEBUG entry is filled in by the dynamic linker and used
2708 if (!bfd_elfNN_add_dynamic_entry (info
, DT_DEBUG
, 0))
2712 if (! bfd_elfNN_add_dynamic_entry (info
, DT_IA_64_PLT_RESERVE
, 0))
2714 if (! bfd_elfNN_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2719 if (! bfd_elfNN_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2720 || ! bfd_elfNN_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2721 || ! bfd_elfNN_add_dynamic_entry (info
, DT_JMPREL
, 0))
2725 if (! bfd_elfNN_add_dynamic_entry (info
, DT_RELA
, 0)
2726 || ! bfd_elfNN_add_dynamic_entry (info
, DT_RELASZ
, 0)
2727 || ! bfd_elfNN_add_dynamic_entry (info
, DT_RELAENT
,
2728 sizeof (ElfNN_External_Rela
)))
2733 if (! bfd_elfNN_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2735 info
->flags
|= DF_TEXTREL
;
2739 /* ??? Perhaps force __gp local. */
2744 static bfd_reloc_status_type
2745 elfNN_ia64_install_value (abfd
, hit_addr
, val
, r_type
)
2749 unsigned int r_type
;
2751 const struct ia64_operand
*op
;
2752 int bigendian
= 0, shift
= 0;
2753 bfd_vma t0
, t1
, insn
, dword
;
2754 enum ia64_opnd opnd
;
2758 opnd
= IA64_OPND_NIL
;
2763 return bfd_reloc_ok
;
2765 /* Instruction relocations. */
2767 case R_IA64_IMM14
: opnd
= IA64_OPND_IMM14
; break;
2769 case R_IA64_PCREL21F
: opnd
= IA64_OPND_TGT25
; break;
2770 case R_IA64_PCREL21M
: opnd
= IA64_OPND_TGT25b
; break;
2771 case R_IA64_PCREL60B
: opnd
= IA64_OPND_TGT64
; break;
2772 case R_IA64_PCREL21B
:
2773 case R_IA64_PCREL21BI
:
2774 opnd
= IA64_OPND_TGT25c
;
2778 case R_IA64_GPREL22
:
2779 case R_IA64_LTOFF22
:
2780 case R_IA64_LTOFF22X
:
2781 case R_IA64_PLTOFF22
:
2782 case R_IA64_PCREL22
:
2783 case R_IA64_LTOFF_FPTR22
:
2784 opnd
= IA64_OPND_IMM22
;
2788 case R_IA64_GPREL64I
:
2789 case R_IA64_LTOFF64I
:
2790 case R_IA64_PLTOFF64I
:
2791 case R_IA64_PCREL64I
:
2792 case R_IA64_FPTR64I
:
2793 case R_IA64_LTOFF_FPTR64I
:
2794 opnd
= IA64_OPND_IMMU64
;
2797 /* Data relocations. */
2799 case R_IA64_DIR32MSB
:
2800 case R_IA64_GPREL32MSB
:
2801 case R_IA64_FPTR32MSB
:
2802 case R_IA64_PCREL32MSB
:
2803 case R_IA64_SEGREL32MSB
:
2804 case R_IA64_SECREL32MSB
:
2805 case R_IA64_LTV32MSB
:
2806 size
= 4; bigendian
= 1;
2809 case R_IA64_DIR32LSB
:
2810 case R_IA64_GPREL32LSB
:
2811 case R_IA64_FPTR32LSB
:
2812 case R_IA64_PCREL32LSB
:
2813 case R_IA64_SEGREL32LSB
:
2814 case R_IA64_SECREL32LSB
:
2815 case R_IA64_LTV32LSB
:
2816 size
= 4; bigendian
= 0;
2819 case R_IA64_DIR64MSB
:
2820 case R_IA64_GPREL64MSB
:
2821 case R_IA64_PLTOFF64MSB
:
2822 case R_IA64_FPTR64MSB
:
2823 case R_IA64_PCREL64MSB
:
2824 case R_IA64_LTOFF_FPTR64MSB
:
2825 case R_IA64_SEGREL64MSB
:
2826 case R_IA64_SECREL64MSB
:
2827 case R_IA64_LTV64MSB
:
2828 size
= 8; bigendian
= 1;
2831 case R_IA64_DIR64LSB
:
2832 case R_IA64_GPREL64LSB
:
2833 case R_IA64_PLTOFF64LSB
:
2834 case R_IA64_FPTR64LSB
:
2835 case R_IA64_PCREL64LSB
:
2836 case R_IA64_LTOFF_FPTR64LSB
:
2837 case R_IA64_SEGREL64LSB
:
2838 case R_IA64_SECREL64LSB
:
2839 case R_IA64_LTV64LSB
:
2840 size
= 8; bigendian
= 0;
2843 /* Unsupported / Dynamic relocations. */
2845 return bfd_reloc_notsupported
;
2850 case IA64_OPND_IMMU64
:
2851 hit_addr
-= (long) hit_addr
& 0x3;
2852 t0
= bfd_get_64 (abfd
, hit_addr
);
2853 t1
= bfd_get_64 (abfd
, hit_addr
+ 8);
2855 /* tmpl/s: bits 0.. 5 in t0
2856 slot 0: bits 5..45 in t0
2857 slot 1: bits 46..63 in t0, bits 0..22 in t1
2858 slot 2: bits 23..63 in t1 */
2860 /* First, clear the bits that form the 64 bit constant. */
2861 t0
&= ~(0x3ffffLL
<< 46);
2863 | (( (0x07fLL
<< 13) | (0x1ffLL
<< 27)
2864 | (0x01fLL
<< 22) | (0x001LL
<< 21)
2865 | (0x001LL
<< 36)) << 23));
2867 t0
|= ((val
>> 22) & 0x03ffffLL
) << 46; /* 18 lsbs of imm41 */
2868 t1
|= ((val
>> 40) & 0x7fffffLL
) << 0; /* 23 msbs of imm41 */
2869 t1
|= ( (((val
>> 0) & 0x07f) << 13) /* imm7b */
2870 | (((val
>> 7) & 0x1ff) << 27) /* imm9d */
2871 | (((val
>> 16) & 0x01f) << 22) /* imm5c */
2872 | (((val
>> 21) & 0x001) << 21) /* ic */
2873 | (((val
>> 63) & 0x001) << 36)) << 23; /* i */
2875 bfd_put_64 (abfd
, t0
, hit_addr
);
2876 bfd_put_64 (abfd
, t1
, hit_addr
+ 8);
2879 case IA64_OPND_TGT64
:
2880 hit_addr
-= (long) hit_addr
& 0x3;
2881 t0
= bfd_get_64 (abfd
, hit_addr
);
2882 t1
= bfd_get_64 (abfd
, hit_addr
+ 8);
2884 /* tmpl/s: bits 0.. 5 in t0
2885 slot 0: bits 5..45 in t0
2886 slot 1: bits 46..63 in t0, bits 0..22 in t1
2887 slot 2: bits 23..63 in t1 */
2889 /* First, clear the bits that form the 64 bit constant. */
2890 t0
&= ~(0x3ffffLL
<< 46);
2892 | ((1LL << 36 | 0xfffffLL
<< 13) << 23));
2895 t0
|= ((val
>> 20) & 0xffffLL
) << 2 << 46; /* 16 lsbs of imm39 */
2896 t1
|= ((val
>> 36) & 0x7fffffLL
) << 0; /* 23 msbs of imm39 */
2897 t1
|= ((((val
>> 0) & 0xfffffLL
) << 13) /* imm20b */
2898 | (((val
>> 59) & 0x1LL
) << 36)) << 23; /* i */
2900 bfd_put_64 (abfd
, t0
, hit_addr
);
2901 bfd_put_64 (abfd
, t1
, hit_addr
+ 8);
2905 switch ((long) hit_addr
& 0x3)
2907 case 0: shift
= 5; break;
2908 case 1: shift
= 14; hit_addr
+= 3; break;
2909 case 2: shift
= 23; hit_addr
+= 6; break;
2910 case 3: return bfd_reloc_notsupported
; /* shouldn't happen... */
2912 dword
= bfd_get_64 (abfd
, hit_addr
);
2913 insn
= (dword
>> shift
) & 0x1ffffffffffLL
;
2915 op
= elf64_ia64_operands
+ opnd
;
2916 err
= (*op
->insert
) (op
, val
, &insn
);
2918 return bfd_reloc_overflow
;
2920 dword
&= ~(0x1ffffffffffLL
<< shift
);
2921 dword
|= (insn
<< shift
);
2922 bfd_put_64 (abfd
, dword
, hit_addr
);
2926 /* A data relocation. */
2929 bfd_putb32 (val
, hit_addr
);
2931 bfd_putb64 (val
, hit_addr
);
2934 bfd_putl32 (val
, hit_addr
);
2936 bfd_putl64 (val
, hit_addr
);
2940 return bfd_reloc_ok
;
2944 elfNN_ia64_install_dyn_reloc (abfd
, info
, sec
, srel
, offset
, type
,
2947 struct bfd_link_info
*info
;
2955 Elf_Internal_Rela outrel
;
2957 outrel
.r_offset
= (sec
->output_section
->vma
2958 + sec
->output_offset
2961 BFD_ASSERT (dynindx
!= -1);
2962 outrel
.r_info
= ELFNN_R_INFO (dynindx
, type
);
2963 outrel
.r_addend
= addend
;
2965 if (elf_section_data (sec
)->stab_info
!= NULL
)
2967 /* This may be NULL for linker-generated relocations, as it is
2968 inconvenient to pass all the bits around. And this shouldn't
2970 BFD_ASSERT (info
!= NULL
);
2972 offset
= (_bfd_stab_section_offset
2973 (abfd
, &elf_hash_table (info
)->stab_info
, sec
,
2974 &elf_section_data (sec
)->stab_info
, offset
));
2975 if (offset
== (bfd_vma
) -1)
2977 /* Run for the hills. We shouldn't be outputting a relocation
2978 for this. So do what everyone else does and output a no-op. */
2979 outrel
.r_info
= ELFNN_R_INFO (0, R_IA64_NONE
);
2980 outrel
.r_addend
= 0;
2983 outrel
.r_offset
= offset
;
2986 bfd_elfNN_swap_reloca_out (abfd
, &outrel
,
2987 ((ElfNN_External_Rela
*) srel
->contents
2988 + srel
->reloc_count
++));
2989 BFD_ASSERT (sizeof (ElfNN_External_Rela
) * srel
->reloc_count
2990 <= srel
->_cooked_size
);
2993 /* Store an entry for target address TARGET_ADDR in the linkage table
2994 and return the gp-relative address of the linkage table entry. */
2997 set_got_entry (abfd
, info
, dyn_i
, dynindx
, addend
, value
, dyn_r_type
)
2999 struct bfd_link_info
*info
;
3000 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3004 unsigned int dyn_r_type
;
3006 struct elfNN_ia64_link_hash_table
*ia64_info
;
3009 ia64_info
= elfNN_ia64_hash_table (info
);
3010 got_sec
= ia64_info
->got_sec
;
3012 BFD_ASSERT ((dyn_i
->got_offset
& 7) == 0);
3014 if (! dyn_i
->got_done
)
3016 dyn_i
->got_done
= true;
3018 /* Store the target address in the linkage table entry. */
3019 bfd_put_64 (abfd
, value
, got_sec
->contents
+ dyn_i
->got_offset
);
3021 /* Install a dynamic relocation if needed. */
3023 || elfNN_ia64_dynamic_symbol_p (dyn_i
->h
, info
)
3024 || elfNN_ia64_aix_vec (abfd
->xvec
)
3025 || (dynindx
!= -1 && dyn_r_type
== R_IA64_FPTR64LSB
))
3029 dyn_r_type
= R_IA64_REL64LSB
;
3034 if (bfd_big_endian (abfd
))
3038 case R_IA64_REL64LSB
:
3039 dyn_r_type
= R_IA64_REL64MSB
;
3041 case R_IA64_DIR64LSB
:
3042 dyn_r_type
= R_IA64_DIR64MSB
;
3044 case R_IA64_FPTR64LSB
:
3045 dyn_r_type
= R_IA64_FPTR64MSB
;
3053 elfNN_ia64_install_dyn_reloc (abfd
, NULL
, got_sec
,
3054 ia64_info
->rel_got_sec
,
3055 dyn_i
->got_offset
, dyn_r_type
,
3060 /* Return the address of the linkage table entry. */
3061 value
= (got_sec
->output_section
->vma
3062 + got_sec
->output_offset
3063 + dyn_i
->got_offset
);
3068 /* Fill in a function descriptor consisting of the function's code
3069 address and its global pointer. Return the descriptor's address. */
3072 set_fptr_entry (abfd
, info
, dyn_i
, value
)
3074 struct bfd_link_info
*info
;
3075 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3078 struct elfNN_ia64_link_hash_table
*ia64_info
;
3081 ia64_info
= elfNN_ia64_hash_table (info
);
3082 fptr_sec
= ia64_info
->fptr_sec
;
3084 if (!dyn_i
->fptr_done
)
3086 dyn_i
->fptr_done
= 1;
3088 /* Fill in the function descriptor. */
3089 bfd_put_64 (abfd
, value
, fptr_sec
->contents
+ dyn_i
->fptr_offset
);
3090 bfd_put_64 (abfd
, _bfd_get_gp_value (abfd
),
3091 fptr_sec
->contents
+ dyn_i
->fptr_offset
+ 8);
3094 /* Return the descriptor's address. */
3095 value
= (fptr_sec
->output_section
->vma
3096 + fptr_sec
->output_offset
3097 + dyn_i
->fptr_offset
);
3102 /* Fill in a PLTOFF entry consisting of the function's code address
3103 and its global pointer. Return the descriptor's address. */
3106 set_pltoff_entry (abfd
, info
, dyn_i
, value
, is_plt
)
3108 struct bfd_link_info
*info
;
3109 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3113 struct elfNN_ia64_link_hash_table
*ia64_info
;
3114 asection
*pltoff_sec
;
3116 ia64_info
= elfNN_ia64_hash_table (info
);
3117 pltoff_sec
= ia64_info
->pltoff_sec
;
3119 /* Don't do anything if this symbol uses a real PLT entry. In
3120 that case, we'll fill this in during finish_dynamic_symbol. */
3121 if ((! dyn_i
->want_plt
|| is_plt
)
3122 && !dyn_i
->pltoff_done
)
3124 bfd_vma gp
= _bfd_get_gp_value (abfd
);
3126 /* Fill in the function descriptor. */
3127 bfd_put_64 (abfd
, value
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
);
3128 bfd_put_64 (abfd
, gp
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
+ 8);
3130 /* Install dynamic relocations if needed. */
3131 if (!is_plt
&& info
->shared
)
3133 unsigned int dyn_r_type
;
3135 if (bfd_big_endian (abfd
))
3136 dyn_r_type
= R_IA64_REL64MSB
;
3138 dyn_r_type
= R_IA64_REL64LSB
;
3140 elfNN_ia64_install_dyn_reloc (abfd
, NULL
, pltoff_sec
,
3141 ia64_info
->rel_pltoff_sec
,
3142 dyn_i
->pltoff_offset
,
3143 dyn_r_type
, 0, value
);
3144 elfNN_ia64_install_dyn_reloc (abfd
, NULL
, pltoff_sec
,
3145 ia64_info
->rel_pltoff_sec
,
3146 dyn_i
->pltoff_offset
+ 8,
3150 dyn_i
->pltoff_done
= 1;
3153 /* Return the descriptor's address. */
3154 value
= (pltoff_sec
->output_section
->vma
3155 + pltoff_sec
->output_offset
3156 + dyn_i
->pltoff_offset
);
3161 /* Called through qsort to sort the .IA_64.unwind section during a
3162 non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd
3163 to the output bfd so we can do proper endianness frobbing. */
3165 static bfd
*elfNN_ia64_unwind_entry_compare_bfd
;
3168 elfNN_ia64_unwind_entry_compare (a
, b
)
3174 av
= bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd
, a
);
3175 bv
= bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd
, b
);
3177 return (av
< bv
? -1 : av
> bv
? 1 : 0);
3181 elfNN_ia64_final_link (abfd
, info
)
3183 struct bfd_link_info
*info
;
3185 struct elfNN_ia64_link_hash_table
*ia64_info
;
3186 asection
*unwind_output_sec
;
3188 ia64_info
= elfNN_ia64_hash_table (info
);
3190 /* Make sure we've got ourselves a nice fat __gp value. */
3191 if (!info
->relocateable
)
3193 bfd_vma min_vma
= (bfd_vma
) -1, max_vma
= 0;
3194 bfd_vma min_short_vma
= min_vma
, max_short_vma
= 0;
3195 struct elf_link_hash_entry
*gp
;
3199 /* Find the min and max vma of all sections marked short. Also
3200 collect min and max vma of any type, for use in selecting a
3202 for (os
= abfd
->sections
; os
; os
= os
->next
)
3206 if ((os
->flags
& SEC_ALLOC
) == 0)
3210 hi
= os
->vma
+ os
->_raw_size
;
3218 if (os
->flags
& SEC_SMALL_DATA
)
3220 if (min_short_vma
> lo
)
3222 if (max_short_vma
< hi
)
3227 /* See if the user wants to force a value. */
3228 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", false,
3232 && (gp
->root
.type
== bfd_link_hash_defined
3233 || gp
->root
.type
== bfd_link_hash_defweak
))
3235 asection
*gp_sec
= gp
->root
.u
.def
.section
;
3236 gp_val
= (gp
->root
.u
.def
.value
3237 + gp_sec
->output_section
->vma
3238 + gp_sec
->output_offset
);
3242 /* Pick a sensible value. */
3244 asection
*got_sec
= ia64_info
->got_sec
;
3246 /* Start with just the address of the .got. */
3248 gp_val
= got_sec
->output_section
->vma
;
3249 else if (max_short_vma
!= 0)
3250 gp_val
= min_short_vma
;
3254 /* If it is possible to address the entire image, but we
3255 don't with the choice above, adjust. */
3256 if (max_vma
- min_vma
< 0x400000
3257 && max_vma
- gp_val
<= 0x200000
3258 && gp_val
- min_vma
> 0x200000)
3259 gp_val
= min_vma
+ 0x200000;
3260 else if (max_short_vma
!= 0)
3262 /* If we don't cover all the short data, adjust. */
3263 if (max_short_vma
- gp_val
>= 0x200000)
3264 gp_val
= min_short_vma
+ 0x200000;
3266 /* If we're addressing stuff past the end, adjust back. */
3267 if (gp_val
> max_vma
)
3268 gp_val
= max_vma
- 0x200000 + 8;
3272 /* Validate whether all SHF_IA_64_SHORT sections are within
3273 range of the chosen GP. */
3275 if (max_short_vma
!= 0)
3277 if (max_short_vma
- min_short_vma
>= 0x400000)
3279 (*_bfd_error_handler
)
3280 (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
3281 bfd_get_filename (abfd
),
3282 (unsigned long) (max_short_vma
- min_short_vma
));
3285 else if ((gp_val
> min_short_vma
3286 && gp_val
- min_short_vma
> 0x200000)
3287 || (gp_val
< max_short_vma
3288 && max_short_vma
- gp_val
>= 0x200000))
3290 (*_bfd_error_handler
)
3291 (_("%s: __gp does not cover short data segment"),
3292 bfd_get_filename (abfd
));
3297 _bfd_set_gp_value (abfd
, gp_val
);
3301 gp
->root
.type
= bfd_link_hash_defined
;
3302 gp
->root
.u
.def
.value
= gp_val
;
3303 gp
->root
.u
.def
.section
= bfd_abs_section_ptr
;
3307 /* If we're producing a final executable, we need to sort the contents
3308 of the .IA_64.unwind section. Force this section to be relocated
3309 into memory rather than written immediately to the output file. */
3310 unwind_output_sec
= NULL
;
3311 if (!info
->relocateable
)
3313 asection
*s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
3316 unwind_output_sec
= s
->output_section
;
3317 unwind_output_sec
->contents
3318 = bfd_malloc (unwind_output_sec
->_raw_size
);
3319 if (unwind_output_sec
->contents
== NULL
)
3324 /* Invoke the regular ELF backend linker to do all the work. */
3325 if (!bfd_elfNN_bfd_final_link (abfd
, info
))
3328 if (unwind_output_sec
)
3330 elfNN_ia64_unwind_entry_compare_bfd
= abfd
;
3331 qsort (unwind_output_sec
->contents
, unwind_output_sec
->_raw_size
/ 24,
3332 24, elfNN_ia64_unwind_entry_compare
);
3334 if (! bfd_set_section_contents (abfd
, unwind_output_sec
,
3335 unwind_output_sec
->contents
, 0,
3336 unwind_output_sec
->_raw_size
))
3344 elfNN_ia64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3345 contents
, relocs
, local_syms
, local_sections
)
3347 struct bfd_link_info
*info
;
3349 asection
*input_section
;
3351 Elf_Internal_Rela
*relocs
;
3352 Elf_Internal_Sym
*local_syms
;
3353 asection
**local_sections
;
3355 struct elfNN_ia64_link_hash_table
*ia64_info
;
3356 Elf_Internal_Shdr
*symtab_hdr
;
3357 Elf_Internal_Rela
*rel
;
3358 Elf_Internal_Rela
*relend
;
3360 boolean ret_val
= true; /* for non-fatal errors */
3363 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3364 ia64_info
= elfNN_ia64_hash_table (info
);
3366 /* Infect various flags from the input section to the output section. */
3367 if (info
->relocateable
)
3371 flags
= elf_section_data(input_section
)->this_hdr
.sh_flags
;
3372 flags
&= SHF_IA_64_NORECOV
;
3374 elf_section_data(input_section
->output_section
)
3375 ->this_hdr
.sh_flags
|= flags
;
3378 gp_val
= _bfd_get_gp_value (output_bfd
);
3379 srel
= get_reloc_section (input_bfd
, ia64_info
, input_section
, false);
3382 relend
= relocs
+ input_section
->reloc_count
;
3383 for (; rel
< relend
; ++rel
)
3385 struct elf_link_hash_entry
*h
;
3386 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3387 bfd_reloc_status_type r
;
3388 reloc_howto_type
*howto
;
3389 unsigned long r_symndx
;
3390 Elf_Internal_Sym
*sym
;
3391 unsigned int r_type
;
3395 boolean dynamic_symbol_p
;
3396 boolean undef_weak_ref
;
3398 r_type
= ELFNN_R_TYPE (rel
->r_info
);
3399 if (r_type
> R_IA64_MAX_RELOC_CODE
)
3401 (*_bfd_error_handler
)
3402 (_("%s: unknown relocation type %d"),
3403 bfd_get_filename (input_bfd
), (int)r_type
);
3404 bfd_set_error (bfd_error_bad_value
);
3408 howto
= lookup_howto (r_type
);
3409 r_symndx
= ELFNN_R_SYM (rel
->r_info
);
3411 if (info
->relocateable
)
3413 /* This is a relocateable link. We don't have to change
3414 anything, unless the reloc is against a section symbol,
3415 in which case we have to adjust according to where the
3416 section symbol winds up in the output section. */
3417 if (r_symndx
< symtab_hdr
->sh_info
)
3419 sym
= local_syms
+ r_symndx
;
3420 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3422 sym_sec
= local_sections
[r_symndx
];
3423 rel
->r_addend
+= sym_sec
->output_offset
;
3429 /* This is a final link. */
3434 undef_weak_ref
= false;
3436 if (r_symndx
< symtab_hdr
->sh_info
)
3438 /* Reloc against local symbol. */
3439 sym
= local_syms
+ r_symndx
;
3440 sym_sec
= local_sections
[r_symndx
];
3441 value
= (sym_sec
->output_section
->vma
3442 + sym_sec
->output_offset
3449 /* Reloc against global symbol. */
3450 indx
= r_symndx
- symtab_hdr
->sh_info
;
3451 h
= elf_sym_hashes (input_bfd
)[indx
];
3452 while (h
->root
.type
== bfd_link_hash_indirect
3453 || h
->root
.type
== bfd_link_hash_warning
)
3454 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3457 if (h
->root
.type
== bfd_link_hash_defined
3458 || h
->root
.type
== bfd_link_hash_defweak
)
3460 sym_sec
= h
->root
.u
.def
.section
;
3462 /* Detect the cases that sym_sec->output_section is
3463 expected to be NULL -- all cases in which the symbol
3464 is defined in another shared module. This includes
3465 PLT relocs for which we've created a PLT entry and
3466 other relocs for which we're prepared to create
3467 dynamic relocations. */
3468 /* ??? Just accept it NULL and continue. */
3470 if (sym_sec
->output_section
!= NULL
)
3472 value
= (h
->root
.u
.def
.value
3473 + sym_sec
->output_section
->vma
3474 + sym_sec
->output_offset
);
3477 else if (h
->root
.type
== bfd_link_hash_undefweak
)
3478 undef_weak_ref
= true;
3479 else if (info
->shared
&& !info
->symbolic
3480 && !info
->no_undefined
3481 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3485 if (! ((*info
->callbacks
->undefined_symbol
)
3486 (info
, h
->root
.root
.string
, input_bfd
,
3487 input_section
, rel
->r_offset
,
3488 (!info
->shared
|| info
->no_undefined
3489 || ELF_ST_VISIBILITY (h
->other
)))))
3496 hit_addr
= contents
+ rel
->r_offset
;
3497 value
+= rel
->r_addend
;
3498 dynamic_symbol_p
= elfNN_ia64_dynamic_symbol_p (h
, info
);
3509 case R_IA64_DIR32MSB
:
3510 case R_IA64_DIR32LSB
:
3511 case R_IA64_DIR64MSB
:
3512 case R_IA64_DIR64LSB
:
3513 /* Install a dynamic relocation for this reloc. */
3514 if ((dynamic_symbol_p
|| info
->shared
3515 || (elfNN_ia64_aix_vec (info
->hash
->creator
)
3516 /* We want REL relocation for _GLOB_DATA_PTR, which would
3517 otherwise be an IMM64, which isn't handled below. The
3518 symbol comes from the C runtime. */
3520 strcmp (h
->root
.root
.string
, "__GLOB_DATA_PTR") != 0)))
3521 && (input_section
->flags
& SEC_ALLOC
) != 0)
3523 unsigned int dyn_r_type
;
3527 BFD_ASSERT (srel
!= NULL
);
3529 /* If we don't need dynamic symbol lookup, find a
3530 matching RELATIVE relocation. */
3531 dyn_r_type
= r_type
;
3532 if (dynamic_symbol_p
)
3534 dynindx
= h
->dynindx
;
3535 addend
= rel
->r_addend
;
3542 case R_IA64_DIR32MSB
:
3543 dyn_r_type
= R_IA64_REL32MSB
;
3545 case R_IA64_DIR32LSB
:
3546 dyn_r_type
= R_IA64_REL32LSB
;
3548 case R_IA64_DIR64MSB
:
3549 dyn_r_type
= R_IA64_REL64MSB
;
3551 case R_IA64_DIR64LSB
:
3552 dyn_r_type
= R_IA64_REL64LSB
;
3556 /* We can't represent this without a dynamic symbol.
3557 Adjust the relocation to be against an output
3558 section symbol, which are always present in the
3559 dynamic symbol table. */
3560 /* ??? People shouldn't be doing non-pic code in
3561 shared libraries. Hork. */
3562 (*_bfd_error_handler
)
3563 (_("%s: linking non-pic code in a shared library"),
3564 bfd_get_filename (input_bfd
));
3572 if (elfNN_ia64_aix_vec (info
->hash
->creator
))
3573 rel
->r_addend
= value
;
3574 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3575 srel
, rel
->r_offset
, dyn_r_type
,
3580 case R_IA64_LTV32MSB
:
3581 case R_IA64_LTV32LSB
:
3582 case R_IA64_LTV64MSB
:
3583 case R_IA64_LTV64LSB
:
3584 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3587 case R_IA64_GPREL22
:
3588 case R_IA64_GPREL64I
:
3589 case R_IA64_GPREL32MSB
:
3590 case R_IA64_GPREL32LSB
:
3591 case R_IA64_GPREL64MSB
:
3592 case R_IA64_GPREL64LSB
:
3593 if (dynamic_symbol_p
)
3595 (*_bfd_error_handler
)
3596 (_("%s: @gprel relocation against dynamic symbol %s"),
3597 bfd_get_filename (input_bfd
), h
->root
.root
.string
);
3602 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3605 case R_IA64_LTOFF22
:
3606 case R_IA64_LTOFF22X
:
3607 case R_IA64_LTOFF64I
:
3608 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3609 value
= set_got_entry (input_bfd
, info
, dyn_i
, (h
? h
->dynindx
: -1),
3610 rel
->r_addend
, value
, R_IA64_DIR64LSB
);
3612 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3615 case R_IA64_PLTOFF22
:
3616 case R_IA64_PLTOFF64I
:
3617 case R_IA64_PLTOFF64MSB
:
3618 case R_IA64_PLTOFF64LSB
:
3619 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3620 value
= set_pltoff_entry (output_bfd
, info
, dyn_i
, value
, false);
3622 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3625 case R_IA64_FPTR64I
:
3626 case R_IA64_FPTR32MSB
:
3627 case R_IA64_FPTR32LSB
:
3628 case R_IA64_FPTR64MSB
:
3629 case R_IA64_FPTR64LSB
:
3630 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3631 if (dyn_i
->want_fptr
)
3633 if (!undef_weak_ref
)
3634 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3640 /* Otherwise, we expect the dynamic linker to create
3645 if (h
->dynindx
!= -1)
3646 dynindx
= h
->dynindx
;
3648 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3649 (info
, h
->root
.u
.def
.section
->owner
,
3650 global_sym_index (h
)));
3654 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3655 (info
, input_bfd
, r_symndx
));
3658 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3659 srel
, rel
->r_offset
, r_type
,
3660 dynindx
, rel
->r_addend
);
3664 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3667 case R_IA64_LTOFF_FPTR22
:
3668 case R_IA64_LTOFF_FPTR64I
:
3669 case R_IA64_LTOFF_FPTR64MSB
:
3670 case R_IA64_LTOFF_FPTR64LSB
:
3674 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3675 if (dyn_i
->want_fptr
)
3677 BFD_ASSERT (h
== NULL
|| h
->dynindx
== -1)
3678 if (!undef_weak_ref
)
3679 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3684 /* Otherwise, we expect the dynamic linker to create
3688 if (h
->dynindx
!= -1)
3689 dynindx
= h
->dynindx
;
3691 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3692 (info
, h
->root
.u
.def
.section
->owner
,
3693 global_sym_index (h
)));
3696 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3697 (info
, input_bfd
, r_symndx
));
3701 value
= set_got_entry (output_bfd
, info
, dyn_i
, dynindx
,
3702 rel
->r_addend
, value
, R_IA64_FPTR64LSB
);
3704 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3708 case R_IA64_PCREL32MSB
:
3709 case R_IA64_PCREL32LSB
:
3710 case R_IA64_PCREL64MSB
:
3711 case R_IA64_PCREL64LSB
:
3712 /* Install a dynamic relocation for this reloc. */
3713 if (dynamic_symbol_p
3714 || elfNN_ia64_aix_vec (info
->hash
->creator
))
3716 BFD_ASSERT (srel
!= NULL
);
3718 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3719 srel
, rel
->r_offset
, r_type
,
3720 h
->dynindx
, rel
->r_addend
);
3724 case R_IA64_PCREL21BI
:
3725 case R_IA64_PCREL21F
:
3726 case R_IA64_PCREL21M
:
3727 /* ??? These two are only used for speculation fixup code.
3728 They should never be dynamic. */
3729 if (dynamic_symbol_p
)
3731 (*_bfd_error_handler
)
3732 (_("%s: dynamic relocation against speculation fixup"),
3733 bfd_get_filename (input_bfd
));
3739 (*_bfd_error_handler
)
3740 (_("%s: speculation fixup against undefined weak symbol"),
3741 bfd_get_filename (input_bfd
));
3747 case R_IA64_PCREL21B
:
3748 case R_IA64_PCREL60B
:
3749 /* We should have created a PLT entry for any dynamic symbol. */
3752 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
3754 if (dyn_i
&& dyn_i
->want_plt2
)
3756 /* Should have caught this earlier. */
3757 BFD_ASSERT (rel
->r_addend
== 0);
3759 value
= (ia64_info
->plt_sec
->output_section
->vma
3760 + ia64_info
->plt_sec
->output_offset
3761 + dyn_i
->plt2_offset
);
3765 /* Since there's no PLT entry, Validate that this is
3767 BFD_ASSERT (undef_weak_ref
|| sym_sec
->output_section
!= NULL
);
3769 /* If the symbol is undef_weak, we shouldn't be trying
3770 to call it. There's every chance that we'd wind up
3771 with an out-of-range fixup here. Don't bother setting
3772 any value at all. */
3778 case R_IA64_PCREL22
:
3779 case R_IA64_PCREL64I
:
3781 /* Make pc-relative. */
3782 value
-= (input_section
->output_section
->vma
3783 + input_section
->output_offset
3784 + rel
->r_offset
) & ~ (bfd_vma
) 0x3;
3785 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3788 case R_IA64_SEGREL32MSB
:
3789 case R_IA64_SEGREL32LSB
:
3790 case R_IA64_SEGREL64MSB
:
3791 case R_IA64_SEGREL64LSB
:
3793 struct elf_segment_map
*m
;
3794 Elf_Internal_Phdr
*p
;
3796 /* Find the segment that contains the output_section. */
3797 for (m
= elf_tdata (output_bfd
)->segment_map
,
3798 p
= elf_tdata (output_bfd
)->phdr
;
3803 for (i
= m
->count
- 1; i
>= 0; i
--)
3804 if (m
->sections
[i
] == sym_sec
->output_section
)
3812 /* If the input section was discarded from the output, then
3815 if (bfd_is_abs_section (sym_sec
->output_section
))
3818 r
= bfd_reloc_notsupported
;
3822 /* The VMA of the segment is the vaddr of the associated
3824 if (value
> p
->p_vaddr
)
3825 value
-= p
->p_vaddr
;
3828 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
,
3834 case R_IA64_SECREL32MSB
:
3835 case R_IA64_SECREL32LSB
:
3836 case R_IA64_SECREL64MSB
:
3837 case R_IA64_SECREL64LSB
:
3838 /* Make output-section relative. */
3839 if (value
> input_section
->output_section
->vma
)
3840 value
-= input_section
->output_section
->vma
;
3843 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3846 case R_IA64_IPLTMSB
:
3847 case R_IA64_IPLTLSB
:
3848 /* Install a dynamic relocation for this reloc. */
3849 if ((dynamic_symbol_p
|| info
->shared
)
3850 && (input_section
->flags
& SEC_ALLOC
) != 0)
3852 BFD_ASSERT (srel
!= NULL
);
3854 /* If we don't need dynamic symbol lookup, install two
3855 RELATIVE relocations. */
3856 if (! dynamic_symbol_p
)
3858 unsigned int dyn_r_type
;
3860 if (r_type
== R_IA64_IPLTMSB
)
3861 dyn_r_type
= R_IA64_REL64MSB
;
3863 dyn_r_type
= R_IA64_REL64LSB
;
3865 elfNN_ia64_install_dyn_reloc (output_bfd
, info
,
3867 srel
, rel
->r_offset
,
3868 dyn_r_type
, 0, value
);
3869 elfNN_ia64_install_dyn_reloc (output_bfd
, info
,
3871 srel
, rel
->r_offset
+ 8,
3872 dyn_r_type
, 0, gp_val
);
3875 elfNN_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3876 srel
, rel
->r_offset
, r_type
,
3877 h
->dynindx
, rel
->r_addend
);
3880 if (r_type
== R_IA64_IPLTMSB
)
3881 r_type
= R_IA64_DIR64MSB
;
3883 r_type
= R_IA64_DIR64LSB
;
3884 elfNN_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3885 r
= elfNN_ia64_install_value (output_bfd
, hit_addr
+ 8, gp_val
,
3890 r
= bfd_reloc_notsupported
;
3899 case bfd_reloc_undefined
:
3900 /* This can happen for global table relative relocs if
3901 __gp is undefined. This is a panic situation so we
3902 don't try to continue. */
3903 (*info
->callbacks
->undefined_symbol
)
3904 (info
, "__gp", input_bfd
, input_section
, rel
->r_offset
, 1);
3907 case bfd_reloc_notsupported
:
3912 name
= h
->root
.root
.string
;
3915 name
= bfd_elf_string_from_elf_section (input_bfd
,
3916 symtab_hdr
->sh_link
,
3921 name
= bfd_section_name (input_bfd
, input_section
);
3923 if (!(*info
->callbacks
->warning
) (info
, _("unsupported reloc"),
3925 input_section
, rel
->r_offset
))
3931 case bfd_reloc_dangerous
:
3932 case bfd_reloc_outofrange
:
3933 case bfd_reloc_overflow
:
3939 name
= h
->root
.root
.string
;
3942 name
= bfd_elf_string_from_elf_section (input_bfd
,
3943 symtab_hdr
->sh_link
,
3948 name
= bfd_section_name (input_bfd
, input_section
);
3950 if (!(*info
->callbacks
->reloc_overflow
) (info
, name
,
3966 elfNN_ia64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3968 struct bfd_link_info
*info
;
3969 struct elf_link_hash_entry
*h
;
3970 Elf_Internal_Sym
*sym
;
3972 struct elfNN_ia64_link_hash_table
*ia64_info
;
3973 struct elfNN_ia64_dyn_sym_info
*dyn_i
;
3975 ia64_info
= elfNN_ia64_hash_table (info
);
3976 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
3978 /* Fill in the PLT data, if required. */
3979 if (dyn_i
&& dyn_i
->want_plt
)
3981 Elf_Internal_Rela outrel
;
3984 bfd_vma plt_addr
, pltoff_addr
, gp_val
, index
;
3985 ElfNN_External_Rela
*rel
;
3987 gp_val
= _bfd_get_gp_value (output_bfd
);
3989 /* Initialize the minimal PLT entry. */
3991 index
= (dyn_i
->plt_offset
- PLT_HEADER_SIZE
) / PLT_MIN_ENTRY_SIZE
;
3992 plt_sec
= ia64_info
->plt_sec
;
3993 loc
= plt_sec
->contents
+ dyn_i
->plt_offset
;
3995 memcpy (loc
, plt_min_entry
, PLT_MIN_ENTRY_SIZE
);
3996 elfNN_ia64_install_value (output_bfd
, loc
, index
, R_IA64_IMM22
);
3997 elfNN_ia64_install_value (output_bfd
, loc
+2, -dyn_i
->plt_offset
,
4000 plt_addr
= (plt_sec
->output_section
->vma
4001 + plt_sec
->output_offset
4002 + dyn_i
->plt_offset
);
4003 pltoff_addr
= set_pltoff_entry (output_bfd
, info
, dyn_i
, plt_addr
, true);
4005 /* Initialize the FULL PLT entry, if needed. */
4006 if (dyn_i
->want_plt2
)
4008 loc
= plt_sec
->contents
+ dyn_i
->plt2_offset
;
4010 memcpy (loc
, plt_full_entry
, PLT_FULL_ENTRY_SIZE
);
4011 elfNN_ia64_install_value (output_bfd
, loc
, pltoff_addr
- gp_val
,
4014 /* Mark the symbol as undefined, rather than as defined in the
4015 plt section. Leave the value alone. */
4016 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4017 first place. But perhaps elflink.h did some for us. */
4018 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4019 sym
->st_shndx
= SHN_UNDEF
;
4022 /* Create the dynamic relocation. */
4023 outrel
.r_offset
= pltoff_addr
;
4024 if (bfd_little_endian (output_bfd
))
4025 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, R_IA64_IPLTLSB
);
4027 outrel
.r_info
= ELFNN_R_INFO (h
->dynindx
, R_IA64_IPLTMSB
);
4028 outrel
.r_addend
= 0;
4030 /* This is fun. In the .IA_64.pltoff section, we've got entries
4031 that correspond both to real PLT entries, and those that
4032 happened to resolve to local symbols but need to be created
4033 to satisfy @pltoff relocations. The .rela.IA_64.pltoff
4034 relocations for the real PLT should come at the end of the
4035 section, so that they can be indexed by plt entry at runtime.
4037 We emitted all of the relocations for the non-PLT @pltoff
4038 entries during relocate_section. So we can consider the
4039 existing sec->reloc_count to be the base of the array of
4042 rel
= (ElfNN_External_Rela
*)ia64_info
->rel_pltoff_sec
->contents
;
4043 rel
+= ia64_info
->rel_pltoff_sec
->reloc_count
;
4045 bfd_elfNN_swap_reloca_out (output_bfd
, &outrel
, rel
+ index
);
4048 /* Mark some specially defined symbols as absolute. */
4049 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4050 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4051 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4052 sym
->st_shndx
= SHN_ABS
;
4058 elfNN_ia64_finish_dynamic_sections (abfd
, info
)
4060 struct bfd_link_info
*info
;
4062 struct elfNN_ia64_link_hash_table
*ia64_info
;
4065 ia64_info
= elfNN_ia64_hash_table (info
);
4066 dynobj
= ia64_info
->root
.dynobj
;
4068 if (elf_hash_table (info
)->dynamic_sections_created
)
4070 ElfNN_External_Dyn
*dyncon
, *dynconend
;
4071 asection
*sdyn
, *sgotplt
;
4074 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4075 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
4076 BFD_ASSERT (sdyn
!= NULL
);
4077 dyncon
= (ElfNN_External_Dyn
*) sdyn
->contents
;
4078 dynconend
= (ElfNN_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4080 gp_val
= _bfd_get_gp_value (abfd
);
4082 for (; dyncon
< dynconend
; dyncon
++)
4084 Elf_Internal_Dyn dyn
;
4086 bfd_elfNN_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4091 dyn
.d_un
.d_ptr
= gp_val
;
4095 dyn
.d_un
.d_val
= (ia64_info
->minplt_entries
4096 * sizeof (ElfNN_External_Rela
));
4100 /* See the comment above in finish_dynamic_symbol. */
4101 dyn
.d_un
.d_ptr
= (ia64_info
->rel_pltoff_sec
->output_section
->vma
4102 + ia64_info
->rel_pltoff_sec
->output_offset
4103 + (ia64_info
->rel_pltoff_sec
->reloc_count
4104 * sizeof (ElfNN_External_Rela
)));
4107 case DT_IA_64_PLT_RESERVE
:
4108 dyn
.d_un
.d_ptr
= (sgotplt
->output_section
->vma
4109 + sgotplt
->output_offset
);
4113 /* Do not have RELASZ include JMPREL. This makes things
4114 easier on ld.so. This is not what the rest of BFD set up. */
4115 dyn
.d_un
.d_val
-= (ia64_info
->minplt_entries
4116 * sizeof (ElfNN_External_Rela
));
4120 bfd_elfNN_swap_dyn_out (abfd
, &dyn
, dyncon
);
4123 /* Initialize the PLT0 entry */
4124 if (ia64_info
->plt_sec
)
4126 bfd_byte
*loc
= ia64_info
->plt_sec
->contents
;
4129 memcpy (loc
, plt_header
, PLT_HEADER_SIZE
);
4131 pltres
= (sgotplt
->output_section
->vma
4132 + sgotplt
->output_offset
4135 elfNN_ia64_install_value (abfd
, loc
+1, pltres
, R_IA64_GPREL22
);
4142 /* ELF file flag handling: */
4144 /* Function to keep IA-64 specific file flags. */
4146 elfNN_ia64_set_private_flags (abfd
, flags
)
4150 BFD_ASSERT (!elf_flags_init (abfd
)
4151 || elf_elfheader (abfd
)->e_flags
== flags
);
4153 elf_elfheader (abfd
)->e_flags
= flags
;
4154 elf_flags_init (abfd
) = true;
4158 /* Copy backend specific data from one object module to another */
4160 elfNN_ia64_copy_private_bfd_data (ibfd
, obfd
)
4163 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4164 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4167 BFD_ASSERT (!elf_flags_init (obfd
)
4168 || (elf_elfheader (obfd
)->e_flags
4169 == elf_elfheader (ibfd
)->e_flags
));
4171 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
4172 elf_flags_init (obfd
) = true;
4176 /* Merge backend specific data from an object file to the output
4177 object file when linking. */
4179 elfNN_ia64_merge_private_bfd_data (ibfd
, obfd
)
4186 /* Don't even pretend to support mixed-format linking. */
4187 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
4188 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
4191 in_flags
= elf_elfheader (ibfd
)->e_flags
;
4192 out_flags
= elf_elfheader (obfd
)->e_flags
;
4194 if (! elf_flags_init (obfd
))
4196 elf_flags_init (obfd
) = true;
4197 elf_elfheader (obfd
)->e_flags
= in_flags
;
4199 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
4200 && bfd_get_arch_info (obfd
)->the_default
)
4202 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
4203 bfd_get_mach (ibfd
));
4209 /* Check flag compatibility. */
4210 if (in_flags
== out_flags
)
4213 /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */
4214 if (!(in_flags
& EF_IA_64_REDUCEDFP
) && (out_flags
& EF_IA_64_REDUCEDFP
))
4215 elf_elfheader (obfd
)->e_flags
&= ~EF_IA_64_REDUCEDFP
;
4217 if ((in_flags
& EF_IA_64_TRAPNIL
) != (out_flags
& EF_IA_64_TRAPNIL
))
4219 (*_bfd_error_handler
)
4220 (_("%s: linking trap-on-NULL-dereference with non-trapping files"),
4221 bfd_get_filename (ibfd
));
4223 bfd_set_error (bfd_error_bad_value
);
4226 if ((in_flags
& EF_IA_64_BE
) != (out_flags
& EF_IA_64_BE
))
4228 (*_bfd_error_handler
)
4229 (_("%s: linking big-endian files with little-endian files"),
4230 bfd_get_filename (ibfd
));
4232 bfd_set_error (bfd_error_bad_value
);
4235 if ((in_flags
& EF_IA_64_ABI64
) != (out_flags
& EF_IA_64_ABI64
))
4237 (*_bfd_error_handler
)
4238 (_("%s: linking 64-bit files with 32-bit files"),
4239 bfd_get_filename (ibfd
));
4241 bfd_set_error (bfd_error_bad_value
);
4244 if ((in_flags
& EF_IA_64_CONS_GP
) != (out_flags
& EF_IA_64_CONS_GP
))
4246 (*_bfd_error_handler
)
4247 (_("%s: linking constant-gp files with non-constant-gp files"),
4248 bfd_get_filename (ibfd
));
4250 bfd_set_error (bfd_error_bad_value
);
4253 if ((in_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
)
4254 != (out_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
4256 (*_bfd_error_handler
)
4257 (_("%s: linking auto-pic files with non-auto-pic files"),
4258 bfd_get_filename (ibfd
));
4260 bfd_set_error (bfd_error_bad_value
);
4268 elfNN_ia64_print_private_bfd_data (abfd
, ptr
)
4272 FILE *file
= (FILE *) ptr
;
4273 flagword flags
= elf_elfheader (abfd
)->e_flags
;
4275 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
4277 fprintf (file
, "private flags = %s%s%s%s%s%s%s%s\n",
4278 (flags
& EF_IA_64_TRAPNIL
) ? "TRAPNIL, " : "",
4279 (flags
& EF_IA_64_EXT
) ? "EXT, " : "",
4280 (flags
& EF_IA_64_BE
) ? "BE, " : "LE, ",
4281 (flags
& EF_IA_64_REDUCEDFP
) ? "REDUCEDFP, " : "",
4282 (flags
& EF_IA_64_CONS_GP
) ? "CONS_GP, " : "",
4283 (flags
& EF_IA_64_NOFUNCDESC_CONS_GP
) ? "NOFUNCDESC_CONS_GP, " : "",
4284 (flags
& EF_IA_64_ABSOLUTE
) ? "ABSOLUTE, " : "",
4285 (flags
& EF_IA_64_ABI64
) ? "ABI64" : "ABI32");
4287 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4291 #define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec
4292 #define TARGET_LITTLE_NAME "elfNN-ia64-little"
4293 #define TARGET_BIG_SYM bfd_elfNN_ia64_big_vec
4294 #define TARGET_BIG_NAME "elfNN-ia64-big"
4295 #define ELF_ARCH bfd_arch_ia64
4296 #define ELF_MACHINE_CODE EM_IA_64
4297 #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */
4298 #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */
4299 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
4301 #define elf_backend_section_from_shdr \
4302 elfNN_ia64_section_from_shdr
4303 #define elf_backend_section_flags \
4304 elfNN_ia64_section_flags
4305 #define elf_backend_fake_sections \
4306 elfNN_ia64_fake_sections
4307 #define elf_backend_final_write_processing \
4308 elfNN_ia64_final_write_processing
4309 #define elf_backend_add_symbol_hook \
4310 elfNN_ia64_add_symbol_hook
4311 #define elf_backend_additional_program_headers \
4312 elfNN_ia64_additional_program_headers
4313 #define elf_backend_modify_segment_map \
4314 elfNN_ia64_modify_segment_map
4315 #define elf_info_to_howto \
4316 elfNN_ia64_info_to_howto
4318 #define bfd_elfNN_bfd_reloc_type_lookup \
4319 elfNN_ia64_reloc_type_lookup
4320 #define bfd_elfNN_bfd_is_local_label_name \
4321 elfNN_ia64_is_local_label_name
4322 #define bfd_elfNN_bfd_relax_section \
4323 elfNN_ia64_relax_section
4325 /* Stuff for the BFD linker: */
4326 #define bfd_elfNN_bfd_link_hash_table_create \
4327 elfNN_ia64_hash_table_create
4328 #define elf_backend_create_dynamic_sections \
4329 elfNN_ia64_create_dynamic_sections
4330 #define elf_backend_check_relocs \
4331 elfNN_ia64_check_relocs
4332 #define elf_backend_adjust_dynamic_symbol \
4333 elfNN_ia64_adjust_dynamic_symbol
4334 #define elf_backend_size_dynamic_sections \
4335 elfNN_ia64_size_dynamic_sections
4336 #define elf_backend_relocate_section \
4337 elfNN_ia64_relocate_section
4338 #define elf_backend_finish_dynamic_symbol \
4339 elfNN_ia64_finish_dynamic_symbol
4340 #define elf_backend_finish_dynamic_sections \
4341 elfNN_ia64_finish_dynamic_sections
4342 #define bfd_elfNN_bfd_final_link \
4343 elfNN_ia64_final_link
4345 #define bfd_elfNN_bfd_copy_private_bfd_data \
4346 elfNN_ia64_copy_private_bfd_data
4347 #define bfd_elfNN_bfd_merge_private_bfd_data \
4348 elfNN_ia64_merge_private_bfd_data
4349 #define bfd_elfNN_bfd_set_private_flags \
4350 elfNN_ia64_set_private_flags
4351 #define bfd_elfNN_bfd_print_private_bfd_data \
4352 elfNN_ia64_print_private_bfd_data
4354 #define elf_backend_plt_readonly 1
4355 #define elf_backend_want_plt_sym 0
4356 #define elf_backend_plt_alignment 5
4357 #define elf_backend_got_header_size 0
4358 #define elf_backend_plt_header_size PLT_HEADER_SIZE
4359 #define elf_backend_want_got_plt 1
4360 #define elf_backend_may_use_rel_p 1
4361 #define elf_backend_may_use_rela_p 1
4362 #define elf_backend_default_use_rela_p 1
4363 #define elf_backend_want_dynbss 0
4364 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
4365 #define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol
4367 #include "elfNN-target.h"
4369 /* AIX-specific vectors. */
4371 #undef TARGET_LITTLE_SYM
4372 #define TARGET_LITTLE_SYM bfd_elfNN_ia64_aix_little_vec
4373 #undef TARGET_LITTLE_NAME
4374 #define TARGET_LITTLE_NAME "elfNN-ia64-aix-little"
4375 #undef TARGET_BIG_SYM
4376 #define TARGET_BIG_SYM bfd_elfNN_ia64_aix_big_vec
4377 #undef TARGET_BIG_NAME
4378 #define TARGET_BIG_NAME "elfNN-ia64-aix-big"
4380 #undef elf_backend_add_symbol_hook
4381 #define elf_backend_add_symbol_hook elfNN_ia64_aix_add_symbol_hook
4383 #undef bfd_elfNN_bfd_link_add_symbols
4384 #define bfd_elfNN_bfd_link_add_symbols elfNN_ia64_aix_link_add_symbols
4386 #define elfNN_bed elfNN_ia64_aix_bed
4388 #include "elfNN-target.h"