1 /* IA-64 support for 64-bit ELF
2 Copyright 1998, 1999 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 elf64_ia64_dyn_sym_info
71 /* The addend for which this entry is relevant. */
74 /* Next addend in the list. */
75 struct elf64_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 elf64_ia64_dyn_reloc_entry
90 struct elf64_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 elf64_ia64_local_hash_entry
112 struct bfd_hash_entry root
;
113 struct elf64_ia64_dyn_sym_info
*info
;
116 struct elf64_ia64_local_hash_table
118 struct bfd_hash_table root
;
119 /* No additional fields for now. */
122 struct elf64_ia64_link_hash_entry
124 struct elf_link_hash_entry root
;
125 struct elf64_ia64_dyn_sym_info
*info
;
128 struct elf64_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 elf64_ia64_local_hash_table loc_hash_table
;
145 #define elf64_ia64_hash_table(p) \
146 ((struct elf64_ia64_link_hash_table *) ((p)->hash))
148 static bfd_reloc_status_type elf64_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
*elf64_ia64_reloc_type_lookup
154 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type bfd_code
));
155 static void elf64_ia64_info_to_howto
156 PARAMS ((bfd
*abfd
, arelent
*bfd_reloc
, Elf64_Internal_Rela
*elf_reloc
));
157 static boolean elf64_ia64_section_from_shdr
158 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, char *));
159 static boolean elf64_ia64_fake_sections
160 PARAMS ((bfd
*abfd
, Elf64_Internal_Shdr
*hdr
, asection
*sec
));
161 static boolean elf64_ia64_add_symbol_hook
162 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, const Elf_Internal_Sym
*sym
,
163 const char **namep
, flagword
*flagsp
, asection
**secp
,
165 static int elf64_ia64_additional_program_headers
166 PARAMS ((bfd
*abfd
));
167 static boolean elf64_ia64_is_local_label_name
168 PARAMS ((bfd
*abfd
, const char *name
));
169 static boolean elf64_ia64_dynamic_symbol_p
170 PARAMS ((struct elf_link_hash_entry
*h
, struct bfd_link_info
*info
));
171 static boolean elf64_ia64_local_hash_table_init
172 PARAMS ((struct elf64_ia64_local_hash_table
*ht
, bfd
*abfd
,
173 new_hash_entry_func
new));
174 static struct bfd_hash_entry
*elf64_ia64_new_loc_hash_entry
175 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
176 const char *string
));
177 static struct bfd_hash_entry
*elf64_ia64_new_elf_hash_entry
178 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
179 const char *string
));
180 static struct bfd_link_hash_table
*elf64_ia64_hash_table_create
181 PARAMS ((bfd
*abfd
));
182 static struct elf64_ia64_local_hash_entry
*elf64_ia64_local_hash_lookup
183 PARAMS ((struct elf64_ia64_local_hash_table
*table
, const char *string
,
184 boolean create
, boolean copy
));
185 static void elf64_ia64_dyn_sym_traverse
186 PARAMS ((struct elf64_ia64_link_hash_table
*ia64_info
,
187 boolean (*func
)(struct elf64_ia64_dyn_sym_info
*, PTR
),
189 static boolean elf64_ia64_create_dynamic_sections
190 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
191 static struct elf64_ia64_dyn_sym_info
* get_dyn_sym_info
192 PARAMS ((struct elf64_ia64_link_hash_table
*ia64_info
,
193 struct elf_link_hash_entry
*h
,
194 bfd
*abfd
, const Elf_Internal_Rela
*rel
, boolean create
));
195 static asection
*get_got
196 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
197 struct elf64_ia64_link_hash_table
*ia64_info
));
198 static asection
*get_fptr
199 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
200 struct elf64_ia64_link_hash_table
*ia64_info
));
201 static asection
*get_pltoff
202 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
203 struct elf64_ia64_link_hash_table
*ia64_info
));
204 static asection
*get_reloc_section
205 PARAMS ((bfd
*abfd
, struct elf64_ia64_link_hash_table
*ia64_info
,
206 asection
*sec
, boolean create
));
207 static boolean count_dyn_reloc
208 PARAMS ((bfd
*abfd
, struct elf64_ia64_dyn_sym_info
*dyn_i
,
209 asection
*srel
, int type
));
210 static boolean elf64_ia64_check_relocs
211 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
212 const Elf_Internal_Rela
*relocs
));
213 static boolean elf64_ia64_adjust_dynamic_symbol
214 PARAMS ((struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
));
215 static unsigned long global_sym_index
216 PARAMS ((struct elf_link_hash_entry
*h
));
217 static boolean allocate_fptr
218 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
219 static boolean allocate_global_data_got
220 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
221 static boolean allocate_global_fptr_got
222 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
223 static boolean allocate_local_got
224 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
225 static boolean allocate_pltoff_entries
226 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
227 static boolean allocate_plt_entries
228 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
229 static boolean allocate_plt2_entries
230 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
231 static boolean allocate_dynrel_entries
232 PARAMS ((struct elf64_ia64_dyn_sym_info
*dyn_i
, PTR data
));
233 static boolean elf64_ia64_size_dynamic_sections
234 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
));
235 static bfd_reloc_status_type elf64_ia64_install_value
236 PARAMS ((bfd
*abfd
, bfd_byte
*hit_addr
, bfd_vma val
, unsigned int r_type
));
237 static void elf64_ia64_install_dyn_reloc
238 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
239 asection
*srel
, bfd_vma offset
, unsigned int type
,
240 long dynindx
, bfd_vma addend
));
241 static bfd_vma set_got_entry
242 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
243 struct elf64_ia64_dyn_sym_info
*dyn_i
, long dynindx
,
244 bfd_vma addend
, bfd_vma value
, unsigned int dyn_r_type
));
245 static bfd_vma set_fptr_entry
246 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
247 struct elf64_ia64_dyn_sym_info
*dyn_i
,
249 static bfd_vma set_pltoff_entry
250 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
251 struct elf64_ia64_dyn_sym_info
*dyn_i
,
252 bfd_vma value
, boolean
));
253 static boolean elf64_ia64_final_link
254 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
255 static boolean elf64_ia64_relocate_section
256 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
, bfd
*input_bfd
,
257 asection
*input_section
, bfd_byte
*contents
,
258 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
259 asection
**local_sections
));
260 static boolean elf64_ia64_finish_dynamic_symbol
261 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
,
262 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
263 static boolean elf64_ia64_finish_dynamic_sections
264 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
));
265 static boolean elf64_ia64_set_private_flags
266 PARAMS ((bfd
*abfd
, flagword flags
));
267 static boolean elf64_ia64_copy_private_bfd_data
268 PARAMS ((bfd
*ibfd
, bfd
*obfd
));
269 static boolean elf64_ia64_merge_private_bfd_data
270 PARAMS ((bfd
*ibfd
, bfd
*obfd
));
271 static boolean elf64_ia64_print_private_bfd_data
272 PARAMS ((bfd
*abfd
, PTR ptr
));
275 /* ia64-specific relocation */
277 /* Perform a relocation. Not much to do here as all the hard work is
278 done in elf64_ia64_final_link_relocate. */
279 static bfd_reloc_status_type
280 elf64_ia64_reloc (abfd
, reloc
, sym
, data
, input_section
,
281 output_bfd
, error_message
)
286 asection
*input_section
;
288 char **error_message
;
292 reloc
->address
+= input_section
->output_offset
;
295 *error_message
= "Unsupported call to elf64_ia64_reloc";
296 return bfd_reloc_notsupported
;
299 #define IA64_HOWTO(TYPE, NAME, SIZE, PCREL, IN) \
300 HOWTO (TYPE, 0, SIZE, 0, PCREL, 0, complain_overflow_signed, \
301 elf64_ia64_reloc, NAME, false, 0, 0, IN)
303 /* This table has to be sorted according to increasing number of the
305 static reloc_howto_type ia64_howto_table
[] =
307 IA64_HOWTO (R_IA64_NONE
, "NONE", 0, false, true),
309 IA64_HOWTO (R_IA64_IMM14
, "IMM14", 0, false, true),
310 IA64_HOWTO (R_IA64_IMM22
, "IMM22", 0, false, true),
311 IA64_HOWTO (R_IA64_IMM64
, "IMM64", 0, false, true),
312 IA64_HOWTO (R_IA64_DIR32MSB
, "DIR32MSB", 2, false, true),
313 IA64_HOWTO (R_IA64_DIR32LSB
, "DIR32LSB", 2, false, true),
314 IA64_HOWTO (R_IA64_DIR64MSB
, "DIR64MSB", 4, false, true),
315 IA64_HOWTO (R_IA64_DIR64LSB
, "DIR64LSB", 4, false, true),
317 IA64_HOWTO (R_IA64_GPREL22
, "GPREL22", 0, false, true),
318 IA64_HOWTO (R_IA64_GPREL64I
, "GPREL64I", 0, false, true),
319 IA64_HOWTO (R_IA64_GPREL32MSB
, "GPREL32MSB", 2, false, true),
320 IA64_HOWTO (R_IA64_GPREL32LSB
, "GPREL32LSB", 2, false, true),
321 IA64_HOWTO (R_IA64_GPREL64MSB
, "GPREL64MSB", 4, false, true),
322 IA64_HOWTO (R_IA64_GPREL64LSB
, "GPREL64LSB", 4, false, true),
324 IA64_HOWTO (R_IA64_LTOFF22
, "LTOFF22", 0, false, true),
325 IA64_HOWTO (R_IA64_LTOFF64I
, "LTOFF64I", 0, false, true),
327 IA64_HOWTO (R_IA64_PLTOFF22
, "PLTOFF22", 0, false, true),
328 IA64_HOWTO (R_IA64_PLTOFF64I
, "PLTOFF64I", 0, false, true),
329 IA64_HOWTO (R_IA64_PLTOFF64MSB
, "PLTOFF64MSB", 4, false, true),
330 IA64_HOWTO (R_IA64_PLTOFF64LSB
, "PLTOFF64LSB", 4, false, true),
332 IA64_HOWTO (R_IA64_FPTR64I
, "FPTR64I", 4, false, true),
333 IA64_HOWTO (R_IA64_FPTR32MSB
, "FPTR32MSB", 2, false, true),
334 IA64_HOWTO (R_IA64_FPTR32LSB
, "FPTR32LSB", 2, false, true),
335 IA64_HOWTO (R_IA64_FPTR64MSB
, "FPTR64MSB", 4, false, true),
336 IA64_HOWTO (R_IA64_FPTR64LSB
, "FPTR64LSB", 4, false, true),
338 IA64_HOWTO (R_IA64_PCREL21B
, "PCREL21B", 0, true, true),
339 IA64_HOWTO (R_IA64_PCREL21M
, "PCREL21M", 0, true, true),
340 IA64_HOWTO (R_IA64_PCREL21F
, "PCREL21F", 0, true, true),
341 IA64_HOWTO (R_IA64_PCREL32MSB
, "PCREL32MSB", 2, true, true),
342 IA64_HOWTO (R_IA64_PCREL32LSB
, "PCREL32LSB", 2, true, true),
343 IA64_HOWTO (R_IA64_PCREL64MSB
, "PCREL64MSB", 4, true, true),
344 IA64_HOWTO (R_IA64_PCREL64LSB
, "PCREL64LSB", 4, true, true),
346 IA64_HOWTO (R_IA64_LTOFF_FPTR22
, "LTOFF_FPTR22", 4, false, true),
347 IA64_HOWTO (R_IA64_LTOFF_FPTR64I
, "LTOFF_FPTR64I", 4, false, true),
348 IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB
, "LTOFF_FPTR64MSB", 4, false, true),
349 IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB
, "LTOFF_FPTR64LSB", 4, false, true),
351 IA64_HOWTO (R_IA64_SEGBASE
, "SEGBASE", 4, false, true),
352 IA64_HOWTO (R_IA64_SEGREL32MSB
, "SEGREL32MSB", 2, false, true),
353 IA64_HOWTO (R_IA64_SEGREL32LSB
, "SEGREL32LSB", 2, false, true),
354 IA64_HOWTO (R_IA64_SEGREL64MSB
, "SEGREL64MSB", 4, false, true),
355 IA64_HOWTO (R_IA64_SEGREL64LSB
, "SEGREL64LSB", 4, false, true),
357 IA64_HOWTO (R_IA64_SECREL32MSB
, "SECREL32MSB", 2, false, true),
358 IA64_HOWTO (R_IA64_SECREL32LSB
, "SECREL32LSB", 2, false, true),
359 IA64_HOWTO (R_IA64_SECREL64MSB
, "SECREL64MSB", 4, false, true),
360 IA64_HOWTO (R_IA64_SECREL64LSB
, "SECREL64LSB", 4, false, true),
362 IA64_HOWTO (R_IA64_REL32MSB
, "REL32MSB", 2, false, true),
363 IA64_HOWTO (R_IA64_REL32LSB
, "REL32LSB", 2, false, true),
364 IA64_HOWTO (R_IA64_REL64MSB
, "REL64MSB", 4, false, true),
365 IA64_HOWTO (R_IA64_REL64LSB
, "REL64LSB", 4, false, true),
367 IA64_HOWTO (R_IA64_LTV32MSB
, "LTV32MSB", 2, false, true),
368 IA64_HOWTO (R_IA64_LTV32LSB
, "LTV32LSB", 2, false, true),
369 IA64_HOWTO (R_IA64_LTV64MSB
, "LTV64MSB", 4, false, true),
370 IA64_HOWTO (R_IA64_LTV64LSB
, "LTV64LSB", 4, false, true),
372 IA64_HOWTO (R_IA64_IPLTMSB
, "IPLTMSB", 4, false, true),
373 IA64_HOWTO (R_IA64_IPLTLSB
, "IPLTLSB", 4, false, true),
374 IA64_HOWTO (R_IA64_EPLTMSB
, "EPLTMSB", 4, false, true),
375 IA64_HOWTO (R_IA64_EPLTLSB
, "EPLTLSB", 4, false, true),
376 IA64_HOWTO (R_IA64_COPY
, "COPY", 4, false, true),
377 IA64_HOWTO (R_IA64_LTOFF22X
, "LTOFF22X", 0, false, true),
378 IA64_HOWTO (R_IA64_LDXMOV
, "LDXMOV", 0, false, true),
380 IA64_HOWTO (R_IA64_TPREL22
, "TPREL22", 4, false, false),
381 IA64_HOWTO (R_IA64_TPREL64MSB
, "TPREL64MSB", 8, false, false),
382 IA64_HOWTO (R_IA64_TPREL64LSB
, "TPREL64LSB", 8, false, false),
383 IA64_HOWTO (R_IA64_LTOFF_TP22
, "LTOFF_TP22", 4, false, false),
386 static unsigned char elf_code_to_howto_index
[R_IA64_MAX_RELOC_CODE
+ 1];
388 /* Given a BFD reloc type, return the matching HOWTO structure. */
390 static reloc_howto_type
*
394 static int inited
= 0;
401 memset (elf_code_to_howto_index
, 0xff, sizeof (elf_code_to_howto_index
));
402 for (i
= 0; i
< NELEMS (ia64_howto_table
); ++i
)
403 elf_code_to_howto_index
[ia64_howto_table
[i
].type
] = i
;
406 BFD_ASSERT (rtype
<= R_IA64_MAX_RELOC_CODE
);
407 i
= elf_code_to_howto_index
[rtype
];
408 if (i
>= NELEMS (ia64_howto_table
))
410 return ia64_howto_table
+ i
;
413 static reloc_howto_type
*
414 elf64_ia64_reloc_type_lookup (abfd
, bfd_code
)
416 bfd_reloc_code_real_type bfd_code
;
422 case BFD_RELOC_NONE
: rtype
= R_IA64_NONE
; break;
424 case BFD_RELOC_IA64_IMM14
: rtype
= R_IA64_IMM14
; break;
425 case BFD_RELOC_IA64_IMM22
: rtype
= R_IA64_IMM22
; break;
426 case BFD_RELOC_IA64_IMM64
: rtype
= R_IA64_IMM64
; break;
428 case BFD_RELOC_IA64_DIR32MSB
: rtype
= R_IA64_DIR32MSB
; break;
429 case BFD_RELOC_IA64_DIR32LSB
: rtype
= R_IA64_DIR32LSB
; break;
430 case BFD_RELOC_IA64_DIR64MSB
: rtype
= R_IA64_DIR64MSB
; break;
431 case BFD_RELOC_IA64_DIR64LSB
: rtype
= R_IA64_DIR64LSB
; break;
433 case BFD_RELOC_IA64_GPREL22
: rtype
= R_IA64_GPREL22
; break;
434 case BFD_RELOC_IA64_GPREL64I
: rtype
= R_IA64_GPREL64I
; break;
435 case BFD_RELOC_IA64_GPREL32MSB
: rtype
= R_IA64_GPREL32MSB
; break;
436 case BFD_RELOC_IA64_GPREL32LSB
: rtype
= R_IA64_GPREL32LSB
; break;
437 case BFD_RELOC_IA64_GPREL64MSB
: rtype
= R_IA64_GPREL64MSB
; break;
438 case BFD_RELOC_IA64_GPREL64LSB
: rtype
= R_IA64_GPREL64LSB
; break;
440 case BFD_RELOC_IA64_LTOFF22
: rtype
= R_IA64_LTOFF22
; break;
441 case BFD_RELOC_IA64_LTOFF64I
: rtype
= R_IA64_LTOFF64I
; break;
443 case BFD_RELOC_IA64_PLTOFF22
: rtype
= R_IA64_PLTOFF22
; break;
444 case BFD_RELOC_IA64_PLTOFF64I
: rtype
= R_IA64_PLTOFF64I
; break;
445 case BFD_RELOC_IA64_PLTOFF64MSB
: rtype
= R_IA64_PLTOFF64MSB
; break;
446 case BFD_RELOC_IA64_PLTOFF64LSB
: rtype
= R_IA64_PLTOFF64LSB
; break;
447 case BFD_RELOC_IA64_FPTR64I
: rtype
= R_IA64_FPTR64I
; break;
448 case BFD_RELOC_IA64_FPTR32MSB
: rtype
= R_IA64_FPTR32MSB
; break;
449 case BFD_RELOC_IA64_FPTR32LSB
: rtype
= R_IA64_FPTR32LSB
; break;
450 case BFD_RELOC_IA64_FPTR64MSB
: rtype
= R_IA64_FPTR64MSB
; break;
451 case BFD_RELOC_IA64_FPTR64LSB
: rtype
= R_IA64_FPTR64LSB
; break;
453 case BFD_RELOC_IA64_PCREL21B
: rtype
= R_IA64_PCREL21B
; break;
454 case BFD_RELOC_IA64_PCREL21M
: rtype
= R_IA64_PCREL21M
; break;
455 case BFD_RELOC_IA64_PCREL21F
: rtype
= R_IA64_PCREL21F
; break;
456 case BFD_RELOC_IA64_PCREL32MSB
: rtype
= R_IA64_PCREL32MSB
; break;
457 case BFD_RELOC_IA64_PCREL32LSB
: rtype
= R_IA64_PCREL32LSB
; break;
458 case BFD_RELOC_IA64_PCREL64MSB
: rtype
= R_IA64_PCREL64MSB
; break;
459 case BFD_RELOC_IA64_PCREL64LSB
: rtype
= R_IA64_PCREL64LSB
; break;
461 case BFD_RELOC_IA64_LTOFF_FPTR22
: rtype
= R_IA64_LTOFF_FPTR22
; break;
462 case BFD_RELOC_IA64_LTOFF_FPTR64I
: rtype
= R_IA64_LTOFF_FPTR64I
; break;
463 case BFD_RELOC_IA64_LTOFF_FPTR64MSB
: rtype
= R_IA64_LTOFF_FPTR64MSB
; break;
464 case BFD_RELOC_IA64_LTOFF_FPTR64LSB
: rtype
= R_IA64_LTOFF_FPTR64LSB
; break;
466 case BFD_RELOC_IA64_SEGBASE
: rtype
= R_IA64_SEGBASE
; break;
467 case BFD_RELOC_IA64_SEGREL32MSB
: rtype
= R_IA64_SEGREL32MSB
; break;
468 case BFD_RELOC_IA64_SEGREL32LSB
: rtype
= R_IA64_SEGREL32LSB
; break;
469 case BFD_RELOC_IA64_SEGREL64MSB
: rtype
= R_IA64_SEGREL64MSB
; break;
470 case BFD_RELOC_IA64_SEGREL64LSB
: rtype
= R_IA64_SEGREL64LSB
; break;
472 case BFD_RELOC_IA64_SECREL32MSB
: rtype
= R_IA64_SECREL32MSB
; break;
473 case BFD_RELOC_IA64_SECREL32LSB
: rtype
= R_IA64_SECREL32LSB
; break;
474 case BFD_RELOC_IA64_SECREL64MSB
: rtype
= R_IA64_SECREL64MSB
; break;
475 case BFD_RELOC_IA64_SECREL64LSB
: rtype
= R_IA64_SECREL64LSB
; break;
477 case BFD_RELOC_IA64_REL32MSB
: rtype
= R_IA64_REL32MSB
; break;
478 case BFD_RELOC_IA64_REL32LSB
: rtype
= R_IA64_REL32LSB
; break;
479 case BFD_RELOC_IA64_REL64MSB
: rtype
= R_IA64_REL64MSB
; break;
480 case BFD_RELOC_IA64_REL64LSB
: rtype
= R_IA64_REL64LSB
; break;
482 case BFD_RELOC_IA64_LTV32MSB
: rtype
= R_IA64_LTV32MSB
; break;
483 case BFD_RELOC_IA64_LTV32LSB
: rtype
= R_IA64_LTV32LSB
; break;
484 case BFD_RELOC_IA64_LTV64MSB
: rtype
= R_IA64_LTV64MSB
; break;
485 case BFD_RELOC_IA64_LTV64LSB
: rtype
= R_IA64_LTV64LSB
; break;
487 case BFD_RELOC_IA64_IPLTMSB
: rtype
= R_IA64_IPLTMSB
; break;
488 case BFD_RELOC_IA64_IPLTLSB
: rtype
= R_IA64_IPLTLSB
; break;
489 case BFD_RELOC_IA64_EPLTMSB
: rtype
= R_IA64_EPLTMSB
; break;
490 case BFD_RELOC_IA64_EPLTLSB
: rtype
= R_IA64_EPLTLSB
; break;
491 case BFD_RELOC_IA64_COPY
: rtype
= R_IA64_COPY
; break;
492 case BFD_RELOC_IA64_LTOFF22X
: rtype
= R_IA64_LTOFF22X
; break;
493 case BFD_RELOC_IA64_LDXMOV
: rtype
= R_IA64_LDXMOV
; break;
495 case BFD_RELOC_IA64_TPREL22
: rtype
= R_IA64_TPREL22
; break;
496 case BFD_RELOC_IA64_TPREL64MSB
: rtype
= R_IA64_TPREL64MSB
; break;
497 case BFD_RELOC_IA64_TPREL64LSB
: rtype
= R_IA64_TPREL64LSB
; break;
498 case BFD_RELOC_IA64_LTOFF_TP22
: rtype
= R_IA64_LTOFF_TP22
; break;
502 return lookup_howto (rtype
);
505 /* Given a ELF reloc, return the matching HOWTO structure. */
508 elf64_ia64_info_to_howto (abfd
, bfd_reloc
, elf_reloc
)
511 Elf64_Internal_Rela
*elf_reloc
;
513 bfd_reloc
->howto
= lookup_howto (ELF64_R_TYPE (elf_reloc
->r_info
));
516 #define PLT_HEADER_SIZE (3 * 16)
517 #define PLT_MIN_ENTRY_SIZE (1 * 16)
518 #define PLT_FULL_ENTRY_SIZE (2 * 16)
519 #define PLT_RESERVED_WORDS 3
521 static const bfd_byte plt_header
[PLT_HEADER_SIZE
] =
523 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */
524 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */
525 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
526 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */
527 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */
528 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */
529 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */
530 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */
531 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
534 static const bfd_byte plt_min_entry
[PLT_MIN_ENTRY_SIZE
] =
536 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */
537 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */
538 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */
541 static const bfd_byte plt_full_entry
[PLT_FULL_ENTRY_SIZE
] =
543 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */
544 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */
545 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */
546 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */
547 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */
548 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */
551 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
553 /* Handle an IA-64 specific section when reading an object file. This
554 is called when elfcode.h finds a section with an unknown type. */
557 elf64_ia64_section_from_shdr (abfd
, hdr
, name
)
559 Elf64_Internal_Shdr
*hdr
;
564 /* There ought to be a place to keep ELF backend specific flags, but
565 at the moment there isn't one. We just keep track of the
566 sections by their name, instead. Fortunately, the ABI gives
567 suggested names for all the MIPS specific sections, so we will
568 probably get away with this. */
569 switch (hdr
->sh_type
)
571 case SHT_IA_64_UNWIND
:
572 if (strcmp (name
, ELF_STRING_ia64_unwind
) != 0)
577 if (strcmp (name
, ELF_STRING_ia64_archext
) != 0)
585 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
587 newsect
= hdr
->bfd_section
;
589 if (hdr
->sh_flags
& SHF_IA_64_SHORT
)
590 newsect
->flags
|= SEC_SMALL_DATA
;
595 /* Set the correct type for an IA-64 ELF section. We do this by the
596 section name, which is a hack, but ought to work. */
599 elf64_ia64_fake_sections (abfd
, hdr
, sec
)
601 Elf64_Internal_Shdr
*hdr
;
604 register const char *name
;
606 name
= bfd_get_section_name (abfd
, sec
);
608 if (strcmp (name
, ELF_STRING_ia64_unwind
) == 0)
609 hdr
->sh_type
= SHT_IA_64_UNWIND
;
610 else if (strcmp (name
, ELF_STRING_ia64_archext
) == 0)
611 hdr
->sh_type
= SHT_IA_64_EXT
;
612 else if (strcmp (name
, ".reloc") == 0)
614 * This is an ugly, but unfortunately necessary hack that is
615 * needed when producing EFI binaries on IA-64. It tells
616 * elf.c:elf_fake_sections() not to consider ".reloc" as a section
617 * containing ELF relocation info. We need this hack in order to
618 * be able to generate ELF binaries that can be translated into
619 * EFI applications (which are essentially COFF objects). Those
620 * files contain a COFF ".reloc" section inside an ELF64 object,
621 * which would normally cause BFD to segfault because it would
622 * attempt to interpret this section as containing relocation
623 * entries for section "oc". With this hack enabled, ".reloc"
624 * will be treated as a normal data section, which will avoid the
625 * segfault. However, you won't be able to create an ELF64 binary
626 * with a section named "oc" that needs relocations, but that's
627 * the kind of ugly side-effects you get when detecting section
628 * types based on their names... In practice, this limitation is
631 hdr
->sh_type
= SHT_PROGBITS
;
633 if (sec
->flags
& SEC_SMALL_DATA
)
634 hdr
->sh_flags
|= SHF_IA_64_SHORT
;
639 /* Hook called by the linker routine which adds symbols from an object
640 file. We use it to put .comm items in .sbss, and not .bss. */
643 elf64_ia64_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
645 struct bfd_link_info
*info
;
646 const Elf_Internal_Sym
*sym
;
652 if (sym
->st_shndx
== SHN_COMMON
653 && !info
->relocateable
654 && sym
->st_size
<= bfd_get_gp_size (abfd
))
656 /* Common symbols less than or equal to -G nn bytes are
657 automatically put into .sbss. */
659 asection
*scomm
= bfd_get_section_by_name (abfd
, ".scommon");
663 scomm
= bfd_make_section (abfd
, ".scommon");
665 || !bfd_set_section_flags (abfd
, scomm
, (SEC_ALLOC
667 | SEC_LINKER_CREATED
)))
672 *valp
= sym
->st_size
;
678 /* Return the number of additional phdrs we will need. */
681 elf64_ia64_additional_program_headers (abfd
)
687 /* See if we need a PT_IA_64_ARCHEXT segment. */
688 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_archext
);
689 if (s
&& (s
->flags
& SEC_LOAD
))
692 /* See if we need a PT_IA_64_UNWIND segment. */
693 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
694 if (s
&& (s
->flags
& SEC_LOAD
))
701 elf64_ia64_modify_segment_map (abfd
)
704 struct elf_segment_map
*m
, **pm
;
707 /* If we need a PT_IA_64_ARCHEXT segment, it must come before
708 all PT_LOAD segments. */
709 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_archext
);
710 if (s
&& (s
->flags
& SEC_LOAD
))
712 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
713 if (m
->p_type
== PT_IA_64_ARCHEXT
)
717 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
721 m
->p_type
= PT_IA_64_ARCHEXT
;
725 /* We want to put it after the PHDR and INTERP segments. */
726 pm
= &elf_tdata (abfd
)->segment_map
;
728 && ((*pm
)->p_type
== PT_PHDR
729 || (*pm
)->p_type
== PT_INTERP
))
737 /* Install the PT_IA_64_UNWIND segment, if needed. */
738 s
= bfd_get_section_by_name (abfd
, ELF_STRING_ia64_unwind
);
739 if (s
&& (s
->flags
& SEC_LOAD
))
741 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
742 if (m
->p_type
== PT_IA_64_UNWIND
)
746 m
= (struct elf_segment_map
*) bfd_zalloc (abfd
, sizeof *m
);
750 m
->p_type
= PT_IA_64_UNWIND
;
755 /* We want to put it last. */
756 pm
= &elf_tdata (abfd
)->segment_map
;
763 /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of
764 the input sections for each output section in the segment and testing
765 for SHF_IA_64_NORECOV on each. */
766 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
767 if (m
->p_type
== PT_LOAD
)
770 for (i
= m
->count
- 1; i
>= 0; --i
)
772 struct bfd_link_order
*order
= m
->sections
[i
]->link_order_head
;
775 if (order
->type
== bfd_indirect_link_order
)
777 asection
*is
= order
->u
.indirect
.section
;
778 bfd_vma flags
= elf_section_data(is
)->this_hdr
.sh_flags
;
779 if (flags
& SHF_IA_64_NORECOV
)
781 m
->p_flags
|= PF_IA_64_NORECOV
;
795 /* According to the Tahoe assembler spec, all labels starting with a
799 elf64_ia64_is_local_label_name (abfd
, name
)
803 return name
[0] == '.';
806 /* Should we do dynamic things to this symbol? */
809 elf64_ia64_dynamic_symbol_p (h
, info
)
810 struct elf_link_hash_entry
*h
;
811 struct bfd_link_info
*info
;
816 while (h
->root
.type
== bfd_link_hash_indirect
817 || h
->root
.type
== bfd_link_hash_warning
)
818 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
820 if (h
->dynindx
== -1)
823 if (h
->root
.type
== bfd_link_hash_undefweak
824 || h
->root
.type
== bfd_link_hash_defweak
)
827 if ((info
->shared
&& !info
->symbolic
)
828 || ((h
->elf_link_hash_flags
829 & (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
))
830 == (ELF_LINK_HASH_DEF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
)))
837 elf64_ia64_local_hash_table_init (ht
, abfd
, new)
838 struct elf64_ia64_local_hash_table
*ht
;
840 new_hash_entry_func
new;
842 memset (ht
, 0, sizeof(*ht
));
843 return bfd_hash_table_init (&ht
->root
, new);
846 static struct bfd_hash_entry
*
847 elf64_ia64_new_loc_hash_entry (entry
, table
, string
)
848 struct bfd_hash_entry
*entry
;
849 struct bfd_hash_table
*table
;
852 struct elf64_ia64_local_hash_entry
*ret
;
853 ret
= (struct elf64_ia64_local_hash_entry
*) entry
;
855 /* Allocate the structure if it has not already been allocated by a
858 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
863 /* Initialize our local data. All zeros, and definitely easier
864 than setting a handful of bit fields. */
865 memset (ret
, 0, sizeof(*ret
));
867 /* Call the allocation method of the superclass. */
868 ret
= ((struct elf64_ia64_local_hash_entry
*)
869 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
871 return (struct bfd_hash_entry
*) ret
;
874 static struct bfd_hash_entry
*
875 elf64_ia64_new_elf_hash_entry (entry
, table
, string
)
876 struct bfd_hash_entry
*entry
;
877 struct bfd_hash_table
*table
;
880 struct elf64_ia64_link_hash_entry
*ret
;
881 ret
= (struct elf64_ia64_link_hash_entry
*) entry
;
883 /* Allocate the structure if it has not already been allocated by a
886 ret
= bfd_hash_allocate (table
, sizeof (*ret
));
891 /* Initialize our local data. All zeros, and definitely easier
892 than setting a handful of bit fields. */
893 memset (ret
, 0, sizeof(*ret
));
895 /* Call the allocation method of the superclass. */
896 ret
= ((struct elf64_ia64_link_hash_entry
*)
897 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
900 return (struct bfd_hash_entry
*) ret
;
904 elf64_ia64_hash_copy_indirect (xdir
, xind
)
905 struct elf_link_hash_entry
*xdir
, *xind
;
907 struct elf64_ia64_link_hash_entry
*dir
, *ind
;
909 dir
= (struct elf64_ia64_link_hash_entry
*)xdir
;
910 ind
= (struct elf64_ia64_link_hash_entry
*)xind
;
912 /* Copy down any references that we may have already seen to the
913 symbol which just became indirect. */
915 dir
->root
.elf_link_hash_flags
|=
916 (ind
->root
.elf_link_hash_flags
917 & (ELF_LINK_HASH_REF_DYNAMIC
918 | ELF_LINK_HASH_REF_REGULAR
919 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
921 /* Copy over the got and plt data. This would have been done
924 if (dir
->info
== NULL
)
926 struct elf64_ia64_dyn_sym_info
*dyn_i
;
928 dir
->info
= dyn_i
= ind
->info
;
931 /* Fix up the dyn_sym_info pointers to the global symbol. */
932 for (; dyn_i
; dyn_i
= dyn_i
->next
)
933 dyn_i
->h
= &dir
->root
;
935 BFD_ASSERT (ind
->info
== NULL
);
937 /* Copy over the dynindx. */
939 if (dir
->root
.dynindx
== -1)
941 dir
->root
.dynindx
= ind
->root
.dynindx
;
942 dir
->root
.dynstr_index
= ind
->root
.dynstr_index
;
943 ind
->root
.dynindx
= -1;
944 ind
->root
.dynstr_index
= 0;
946 BFD_ASSERT (ind
->root
.dynindx
== -1);
950 elf64_ia64_hash_hide_symbol (xh
)
951 struct elf_link_hash_entry
*xh
;
953 struct elf64_ia64_link_hash_entry
*h
;
954 struct elf64_ia64_dyn_sym_info
*dyn_i
;
956 h
= (struct elf64_ia64_link_hash_entry
*)xh
;
958 h
->root
.elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
959 h
->root
.dynindx
= -1;
961 for (dyn_i
= h
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
962 dyn_i
->want_plt2
= 0;
965 /* Create the derived linker hash table. The IA-64 ELF port uses this
966 derived hash table to keep information specific to the IA-64 ElF
967 linker (without using static variables). */
969 static struct bfd_link_hash_table
*
970 elf64_ia64_hash_table_create (abfd
)
973 struct elf64_ia64_link_hash_table
*ret
;
975 ret
= bfd_alloc (abfd
, sizeof (*ret
));
978 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
979 elf64_ia64_new_elf_hash_entry
))
981 bfd_release (abfd
, ret
);
985 if (!elf64_ia64_local_hash_table_init (&ret
->loc_hash_table
, abfd
,
986 elf64_ia64_new_loc_hash_entry
))
988 return &ret
->root
.root
;
991 /* Look up an entry in a Alpha ELF linker hash table. */
993 static INLINE
struct elf64_ia64_local_hash_entry
*
994 elf64_ia64_local_hash_lookup(table
, string
, create
, copy
)
995 struct elf64_ia64_local_hash_table
*table
;
997 boolean create
, copy
;
999 return ((struct elf64_ia64_local_hash_entry
*)
1000 bfd_hash_lookup (&table
->root
, string
, create
, copy
));
1003 /* Traverse both local and global hash tables. */
1005 struct elf64_ia64_dyn_sym_traverse_data
1007 boolean (*func
) PARAMS ((struct elf64_ia64_dyn_sym_info
*, PTR
));
1012 elf64_ia64_global_dyn_sym_thunk (xentry
, xdata
)
1013 struct bfd_hash_entry
*xentry
;
1016 struct elf64_ia64_link_hash_entry
*entry
1017 = (struct elf64_ia64_link_hash_entry
*) xentry
;
1018 struct elf64_ia64_dyn_sym_traverse_data
*data
1019 = (struct elf64_ia64_dyn_sym_traverse_data
*) xdata
;
1020 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1022 for (dyn_i
= entry
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1023 if (! (*data
->func
) (dyn_i
, data
->data
))
1029 elf64_ia64_local_dyn_sym_thunk (xentry
, xdata
)
1030 struct bfd_hash_entry
*xentry
;
1033 struct elf64_ia64_local_hash_entry
*entry
1034 = (struct elf64_ia64_local_hash_entry
*) xentry
;
1035 struct elf64_ia64_dyn_sym_traverse_data
*data
1036 = (struct elf64_ia64_dyn_sym_traverse_data
*) xdata
;
1037 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1039 for (dyn_i
= entry
->info
; dyn_i
; dyn_i
= dyn_i
->next
)
1040 if (! (*data
->func
) (dyn_i
, data
->data
))
1046 elf64_ia64_dyn_sym_traverse (ia64_info
, func
, data
)
1047 struct elf64_ia64_link_hash_table
*ia64_info
;
1048 boolean (*func
) PARAMS ((struct elf64_ia64_dyn_sym_info
*, PTR
));
1051 struct elf64_ia64_dyn_sym_traverse_data xdata
;
1056 elf_link_hash_traverse (&ia64_info
->root
,
1057 elf64_ia64_global_dyn_sym_thunk
, &xdata
);
1058 bfd_hash_traverse (&ia64_info
->loc_hash_table
.root
,
1059 elf64_ia64_local_dyn_sym_thunk
, &xdata
);
1063 elf64_ia64_create_dynamic_sections (abfd
, info
)
1065 struct bfd_link_info
*info
;
1067 struct elf64_ia64_link_hash_table
*ia64_info
;
1068 struct elf_link_hash_entry
*h
;
1071 if (! _bfd_elf_create_dynamic_sections (abfd
, info
))
1074 ia64_info
= elf64_ia64_hash_table (info
);
1076 ia64_info
->plt_sec
= bfd_get_section_by_name (abfd
, ".plt");
1077 ia64_info
->got_sec
= bfd_get_section_by_name (abfd
, ".got");
1080 flagword flags
= bfd_get_section_flags (abfd
, ia64_info
->got_sec
);
1081 bfd_set_section_flags (abfd
, ia64_info
->got_sec
, SEC_SMALL_DATA
| flags
);
1084 if (!get_pltoff (abfd
, info
, ia64_info
))
1087 s
= bfd_make_section(abfd
, ".rela.IA_64.pltoff");
1089 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1092 | SEC_LINKER_CREATED
1094 || !bfd_set_section_alignment (abfd
, s
, 3))
1096 ia64_info
->rel_pltoff_sec
= s
;
1098 s
= bfd_make_section(abfd
, ".rela.got");
1100 || !bfd_set_section_flags (abfd
, s
, (SEC_ALLOC
| SEC_LOAD
1103 | SEC_LINKER_CREATED
1105 || !bfd_set_section_alignment (abfd
, s
, 3))
1107 ia64_info
->rel_got_sec
= s
;
1112 /* Find and/or create a descriptor for dynamic symbol info. This will
1113 vary based on global or local symbol, and the addend to the reloc. */
1115 static struct elf64_ia64_dyn_sym_info
*
1116 get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, create
)
1117 struct elf64_ia64_link_hash_table
*ia64_info
;
1118 struct elf_link_hash_entry
*h
;
1120 const Elf_Internal_Rela
*rel
;
1123 struct elf64_ia64_dyn_sym_info
**pp
;
1124 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1125 bfd_vma addend
= rel
? rel
->r_addend
: 0;
1128 pp
= &((struct elf64_ia64_link_hash_entry
*)h
)->info
;
1131 struct elf64_ia64_local_hash_entry
*loc_h
;
1135 /* Construct a string for use in the elf64_ia64_local_hash_table.
1136 The name describes what was once anonymous memory. */
1138 len
= sizeof(void*)*2 + 1 + sizeof(bfd_vma
)*4 + 1 + 1;
1139 len
+= 10; /* %p slop */
1141 addr_name
= alloca (len
);
1142 sprintf (addr_name
, "%p:%lx", abfd
, ELF64_R_SYM (rel
->r_info
));
1144 /* Collect the canonical entry data for this address. */
1145 loc_h
= elf64_ia64_local_hash_lookup (&ia64_info
->loc_hash_table
,
1146 addr_name
, create
, create
);
1152 for (dyn_i
= *pp
; dyn_i
&& dyn_i
->addend
!= addend
; dyn_i
= *pp
)
1155 if (dyn_i
== NULL
&& create
)
1157 dyn_i
= (struct elf64_ia64_dyn_sym_info
*)
1158 bfd_zalloc (abfd
, sizeof *dyn_i
);
1160 dyn_i
->addend
= addend
;
1167 get_got (abfd
, info
, ia64_info
)
1169 struct bfd_link_info
*info
;
1170 struct elf64_ia64_link_hash_table
*ia64_info
;
1172 asection
*got
, *srel
;
1175 got
= ia64_info
->got_sec
;
1180 dynobj
= ia64_info
->root
.dynobj
;
1182 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1183 if (!_bfd_elf_create_got_section (dynobj
, info
))
1186 got
= bfd_get_section_by_name (dynobj
, ".got");
1188 ia64_info
->got_sec
= got
;
1190 flags
= bfd_get_section_flags (abfd
, got
);
1191 bfd_set_section_flags (abfd
, got
, SEC_SMALL_DATA
| flags
);
1197 /* Create function descriptor section (.opd). This section is called .opd
1198 because it contains "official prodecure descriptors". The "official"
1199 refers to the fact that these descriptors are used when taking the address
1200 of a procedure, thus ensuring a unique address for each procedure. */
1203 get_fptr (abfd
, info
, ia64_info
)
1205 struct bfd_link_info
*info
;
1206 struct elf64_ia64_link_hash_table
*ia64_info
;
1211 fptr
= ia64_info
->fptr_sec
;
1214 dynobj
= ia64_info
->root
.dynobj
;
1216 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1218 fptr
= bfd_make_section (dynobj
, ".opd");
1220 || !bfd_set_section_flags (dynobj
, fptr
,
1226 | SEC_LINKER_CREATED
))
1227 || !bfd_set_section_alignment (abfd
, fptr
, 4))
1233 ia64_info
->fptr_sec
= fptr
;
1240 get_pltoff (abfd
, info
, ia64_info
)
1242 struct bfd_link_info
*info
;
1243 struct elf64_ia64_link_hash_table
*ia64_info
;
1248 pltoff
= ia64_info
->pltoff_sec
;
1251 dynobj
= ia64_info
->root
.dynobj
;
1253 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1255 pltoff
= bfd_make_section (dynobj
, ELF_STRING_ia64_pltoff
);
1257 || !bfd_set_section_flags (dynobj
, pltoff
,
1263 | SEC_LINKER_CREATED
))
1264 || !bfd_set_section_alignment (abfd
, pltoff
, 4))
1270 ia64_info
->pltoff_sec
= pltoff
;
1277 get_reloc_section (abfd
, ia64_info
, sec
, create
)
1279 struct elf64_ia64_link_hash_table
*ia64_info
;
1283 const char *srel_name
;
1287 srel_name
= (bfd_elf_string_from_elf_section
1288 (abfd
, elf_elfheader(abfd
)->e_shstrndx
,
1289 elf_section_data(sec
)->rel_hdr
.sh_name
));
1290 if (srel_name
== NULL
)
1293 BFD_ASSERT ((strncmp (srel_name
, ".rela", 5) == 0
1294 && strcmp (bfd_get_section_name (abfd
, sec
),
1296 || (strncmp (srel_name
, ".rel", 4) == 0
1297 && strcmp (bfd_get_section_name (abfd
, sec
),
1298 srel_name
+4) == 0));
1300 dynobj
= ia64_info
->root
.dynobj
;
1302 ia64_info
->root
.dynobj
= dynobj
= abfd
;
1304 srel
= bfd_get_section_by_name (dynobj
, srel_name
);
1305 if (srel
== NULL
&& create
)
1307 srel
= bfd_make_section (dynobj
, srel_name
);
1309 || !bfd_set_section_flags (dynobj
, srel
,
1314 | SEC_LINKER_CREATED
1316 || !bfd_set_section_alignment (dynobj
, srel
, 3))
1324 count_dyn_reloc (abfd
, dyn_i
, srel
, type
)
1326 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1330 struct elf64_ia64_dyn_reloc_entry
*rent
;
1332 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
1333 if (rent
->srel
== srel
&& rent
->type
== type
)
1338 rent
= (struct elf64_ia64_dyn_reloc_entry
*)
1339 bfd_alloc (abfd
, sizeof (*rent
));
1343 rent
->next
= dyn_i
->reloc_entries
;
1347 dyn_i
->reloc_entries
= rent
;
1355 elf64_ia64_check_relocs (abfd
, info
, sec
, relocs
)
1357 struct bfd_link_info
*info
;
1359 const Elf_Internal_Rela
*relocs
;
1361 struct elf64_ia64_link_hash_table
*ia64_info
;
1362 const Elf_Internal_Rela
*relend
;
1363 Elf_Internal_Shdr
*symtab_hdr
;
1364 const Elf_Internal_Rela
*rel
;
1365 asection
*got
, *fptr
, *srel
;
1367 if (info
->relocateable
)
1370 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1371 ia64_info
= elf64_ia64_hash_table (info
);
1373 got
= fptr
= srel
= NULL
;
1375 relend
= relocs
+ sec
->reloc_count
;
1376 for (rel
= relocs
; rel
< relend
; ++rel
)
1385 NEED_LTOFF_FPTR
= 64,
1388 struct elf_link_hash_entry
*h
= NULL
;
1389 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
1390 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1392 boolean maybe_dynamic
;
1395 if (r_symndx
>= symtab_hdr
->sh_info
)
1397 /* We're dealing with a global symbol -- find its hash entry
1398 and mark it as being referenced. */
1399 long indx
= r_symndx
- symtab_hdr
->sh_info
;
1400 h
= elf_sym_hashes (abfd
)[indx
];
1401 while (h
->root
.type
== bfd_link_hash_indirect
1402 || h
->root
.type
== bfd_link_hash_warning
)
1403 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1405 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
1408 /* We can only get preliminary data on whether a symbol is
1409 locally or externally defined, as not all of the input files
1410 have yet been processed. Do something with what we know, as
1411 this may help reduce memory usage and processing time later. */
1412 maybe_dynamic
= false;
1413 if (h
&& ((info
->shared
&& ! info
->symbolic
)
1414 || ! (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)
1415 || h
->root
.type
== bfd_link_hash_defweak
))
1416 maybe_dynamic
= true;
1419 switch (ELF64_R_TYPE (rel
->r_info
))
1421 case R_IA64_TPREL22
:
1422 case R_IA64_TPREL64MSB
:
1423 case R_IA64_TPREL64LSB
:
1424 case R_IA64_LTOFF_TP22
:
1427 case R_IA64_LTOFF_FPTR22
:
1428 case R_IA64_LTOFF_FPTR64I
:
1429 case R_IA64_LTOFF_FPTR64MSB
:
1430 case R_IA64_LTOFF_FPTR64LSB
:
1431 need_entry
= NEED_FPTR
| NEED_GOT
| NEED_LTOFF_FPTR
;
1434 case R_IA64_FPTR64I
:
1435 case R_IA64_FPTR32MSB
:
1436 case R_IA64_FPTR32LSB
:
1437 case R_IA64_FPTR64MSB
:
1438 case R_IA64_FPTR64LSB
:
1439 if (info
->shared
|| h
)
1440 need_entry
= NEED_FPTR
| NEED_DYNREL
;
1442 need_entry
= NEED_FPTR
;
1443 dynrel_type
= R_IA64_FPTR64LSB
;
1446 case R_IA64_LTOFF22
:
1447 case R_IA64_LTOFF22X
:
1448 case R_IA64_LTOFF64I
:
1449 need_entry
= NEED_GOT
;
1452 case R_IA64_PLTOFF22
:
1453 case R_IA64_PLTOFF64I
:
1454 case R_IA64_PLTOFF64MSB
:
1455 case R_IA64_PLTOFF64LSB
:
1456 need_entry
= NEED_PLTOFF
;
1460 need_entry
|= NEED_MIN_PLT
;
1464 (*info
->callbacks
->warning
)
1465 (info
, _("@pltoff reloc against local symbol"), 0,
1470 case R_IA64_PCREL21B
:
1471 /* Depending on where this symbol is defined, we may or may not
1472 need a full plt entry. Only skip if we know we'll not need
1473 the entry -- static or symbolic, and the symbol definition
1474 has already been seen. */
1475 if (maybe_dynamic
&& rel
->r_addend
== 0)
1476 need_entry
= NEED_FULL_PLT
;
1482 case R_IA64_DIR32MSB
:
1483 case R_IA64_DIR32LSB
:
1484 case R_IA64_DIR64MSB
:
1485 case R_IA64_DIR64LSB
:
1486 /* Shared objects will always need at least a REL relocation. */
1487 if (info
->shared
|| maybe_dynamic
)
1488 need_entry
= NEED_DYNREL
;
1489 dynrel_type
= R_IA64_DIR64LSB
;
1492 case R_IA64_PCREL32MSB
:
1493 case R_IA64_PCREL32LSB
:
1494 case R_IA64_PCREL64MSB
:
1495 case R_IA64_PCREL64LSB
:
1497 need_entry
= NEED_DYNREL
;
1498 dynrel_type
= R_IA64_PCREL64LSB
;
1505 if ((need_entry
& NEED_FPTR
) != 0
1508 (*info
->callbacks
->warning
)
1509 (info
, _("non-zero addend in @fptr reloc"), 0,
1513 dyn_i
= get_dyn_sym_info (ia64_info
, h
, abfd
, rel
, true);
1515 /* Record whether or not this is a local symbol. */
1518 /* Create what's needed. */
1519 if (need_entry
& NEED_GOT
)
1523 got
= get_got (abfd
, info
, ia64_info
);
1527 dyn_i
->want_got
= 1;
1529 if (need_entry
& NEED_FPTR
)
1533 fptr
= get_fptr (abfd
, info
, ia64_info
);
1538 /* FPTRs for shared libraries are allocated by the dynamic
1539 linker. Make sure this local symbol will appear in the
1540 dynamic symbol table. */
1541 if (!h
&& info
->shared
)
1543 if (! (_bfd_elf64_link_record_local_dynamic_symbol
1544 (info
, abfd
, r_symndx
)))
1548 dyn_i
->want_fptr
= 1;
1550 if (need_entry
& NEED_LTOFF_FPTR
)
1551 dyn_i
->want_ltoff_fptr
= 1;
1552 if (need_entry
& (NEED_MIN_PLT
| NEED_FULL_PLT
))
1554 if (!ia64_info
->root
.dynobj
)
1555 ia64_info
->root
.dynobj
= abfd
;
1556 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1557 dyn_i
->want_plt
= 1;
1559 if (need_entry
& NEED_FULL_PLT
)
1560 dyn_i
->want_plt2
= 1;
1561 if (need_entry
& NEED_PLTOFF
)
1562 dyn_i
->want_pltoff
= 1;
1563 if ((need_entry
& NEED_DYNREL
) && (sec
->flags
& SEC_ALLOC
))
1567 srel
= get_reloc_section (abfd
, ia64_info
, sec
, true);
1571 if (!count_dyn_reloc (abfd
, dyn_i
, srel
, dynrel_type
))
1579 struct elf64_ia64_allocate_data
1581 struct bfd_link_info
*info
;
1585 /* For cleanliness, and potentially faster dynamic loading, allocate
1586 external GOT entries first. */
1589 allocate_global_data_got (dyn_i
, data
)
1590 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1593 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1596 && ! dyn_i
->want_fptr
1597 && elf64_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
))
1599 dyn_i
->got_offset
= x
->ofs
;
1605 /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */
1608 allocate_global_fptr_got (dyn_i
, data
)
1609 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1612 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1616 && elf64_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
))
1618 dyn_i
->got_offset
= x
->ofs
;
1624 /* Lastly, allocate all the GOT entries for local data. */
1627 allocate_local_got (dyn_i
, data
)
1628 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1631 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1634 && ! elf64_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
))
1636 dyn_i
->got_offset
= x
->ofs
;
1642 /* Search for the index of a global symbol in it's defining object file. */
1644 static unsigned long
1645 global_sym_index (h
)
1646 struct elf_link_hash_entry
*h
;
1648 struct elf_link_hash_entry
**p
;
1651 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1652 || h
->root
.type
== bfd_link_hash_defweak
);
1654 obj
= h
->root
.u
.def
.section
->owner
;
1655 for (p
= elf_sym_hashes (obj
); *p
!= h
; ++p
)
1658 return p
- elf_sym_hashes (obj
) + elf_tdata (obj
)->symtab_hdr
.sh_info
;
1661 /* Allocate function descriptors. We can do these for every function
1662 in a main executable that is not exported. */
1665 allocate_fptr (dyn_i
, data
)
1666 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1669 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1671 if (dyn_i
->want_fptr
)
1673 struct elf_link_hash_entry
*h
= dyn_i
->h
;
1676 while (h
->root
.type
== bfd_link_hash_indirect
1677 || h
->root
.type
== bfd_link_hash_warning
)
1678 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1680 if (x
->info
->shared
)
1682 if (h
&& h
->dynindx
== -1)
1684 BFD_ASSERT ((h
->root
.type
== bfd_link_hash_defined
)
1685 || (h
->root
.type
== bfd_link_hash_defweak
));
1687 if (!_bfd_elf64_link_record_local_dynamic_symbol
1688 (x
->info
, h
->root
.u
.def
.section
->owner
,
1689 global_sym_index (h
)))
1693 dyn_i
->want_fptr
= 0;
1695 else if (h
== NULL
|| h
->dynindx
== -1)
1697 dyn_i
->fptr_offset
= x
->ofs
;
1701 dyn_i
->want_fptr
= 0;
1706 /* Allocate all the minimal PLT entries. */
1709 allocate_plt_entries (dyn_i
, data
)
1710 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1713 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1715 if (dyn_i
->want_plt
)
1717 struct elf_link_hash_entry
*h
= dyn_i
->h
;
1720 while (h
->root
.type
== bfd_link_hash_indirect
1721 || h
->root
.type
== bfd_link_hash_warning
)
1722 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1724 /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */
1725 if (elf64_ia64_dynamic_symbol_p (h
, x
->info
))
1727 bfd_size_type offset
= x
->ofs
;
1729 offset
= PLT_HEADER_SIZE
;
1730 dyn_i
->plt_offset
= offset
;
1731 x
->ofs
= offset
+ PLT_MIN_ENTRY_SIZE
;
1733 dyn_i
->want_pltoff
= 1;
1737 dyn_i
->want_plt
= 0;
1738 dyn_i
->want_plt2
= 0;
1744 /* Allocate all the full PLT entries. */
1747 allocate_plt2_entries (dyn_i
, data
)
1748 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1751 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1753 if (dyn_i
->want_plt2
)
1755 struct elf_link_hash_entry
*h
= dyn_i
->h
;
1756 bfd_size_type ofs
= x
->ofs
;
1758 dyn_i
->plt2_offset
= ofs
;
1759 x
->ofs
= ofs
+ PLT_FULL_ENTRY_SIZE
;
1761 while (h
->root
.type
== bfd_link_hash_indirect
1762 || h
->root
.type
== bfd_link_hash_warning
)
1763 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1764 dyn_i
->h
->plt
.offset
= ofs
;
1769 /* Allocate all the PLTOFF entries requested by relocations and
1770 plt entries. We can't share space with allocated FPTR entries,
1771 because the latter are not necessarily addressable by the GP.
1772 ??? Relaxation might be able to determine that they are. */
1775 allocate_pltoff_entries (dyn_i
, data
)
1776 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1779 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1781 if (dyn_i
->want_pltoff
)
1783 dyn_i
->pltoff_offset
= x
->ofs
;
1789 /* Allocate dynamic relocations for those symbols that turned out
1793 allocate_dynrel_entries (dyn_i
, data
)
1794 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1797 struct elf64_ia64_allocate_data
*x
= (struct elf64_ia64_allocate_data
*)data
;
1798 struct elf64_ia64_link_hash_table
*ia64_info
;
1799 struct elf64_ia64_dyn_reloc_entry
*rent
;
1800 boolean dynamic_symbol
, shared
;
1802 ia64_info
= elf64_ia64_hash_table (x
->info
);
1803 dynamic_symbol
= elf64_ia64_dynamic_symbol_p (dyn_i
->h
, x
->info
);
1804 shared
= x
->info
->shared
;
1806 /* Take care of the normal data relocations. */
1808 for (rent
= dyn_i
->reloc_entries
; rent
; rent
= rent
->next
)
1812 case R_IA64_FPTR64LSB
:
1813 /* Allocate one iff !want_fptr, which by this point will
1814 be true only if we're actually allocating one statically
1815 in the main executable. */
1816 if (dyn_i
->want_fptr
)
1819 case R_IA64_PCREL64LSB
:
1820 if (!dynamic_symbol
)
1823 case R_IA64_DIR64LSB
:
1824 if (!dynamic_symbol
&& !shared
)
1828 rent
->srel
->_raw_size
+= sizeof (Elf64_External_Rela
) * rent
->count
;
1831 /* Take care of the GOT and PLT relocations. */
1833 if (((dynamic_symbol
|| shared
) && dyn_i
->want_got
)
1834 || (dyn_i
->want_ltoff_fptr
&& dyn_i
->h
&& dyn_i
->h
->dynindx
!= -1))
1835 ia64_info
->rel_got_sec
->_raw_size
+= sizeof (Elf64_External_Rela
);
1837 if (dyn_i
->want_pltoff
)
1839 bfd_size_type t
= 0;
1841 /* Dynamic symbols get one IPLT relocation. Local symbols in
1842 shared libraries get two REL relocations. Local symbols in
1843 main applications get nothing. */
1845 t
= sizeof (Elf64_External_Rela
);
1847 t
= 2 * sizeof (Elf64_External_Rela
);
1849 ia64_info
->rel_pltoff_sec
->_raw_size
+= t
;
1856 elf64_ia64_adjust_dynamic_symbol (info
, h
)
1857 struct bfd_link_info
*info
;
1858 struct elf_link_hash_entry
*h
;
1860 /* ??? Undefined symbols with PLT entries should be re-defined
1861 to be the PLT entry. */
1863 /* If this is a weak symbol, and there is a real definition, the
1864 processor independent code will have arranged for us to see the
1865 real definition first, and we can just use the same value. */
1866 if (h
->weakdef
!= NULL
)
1868 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1869 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1870 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1871 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1875 /* If this is a reference to a symbol defined by a dynamic object which
1876 is not a function, we might allocate the symbol in our .dynbss section
1877 and allocate a COPY dynamic relocation.
1879 But IA-64 code is canonically PIC, so as a rule we can avoid this sort
1886 elf64_ia64_size_dynamic_sections (output_bfd
, info
)
1888 struct bfd_link_info
*info
;
1890 struct elf64_ia64_allocate_data data
;
1891 struct elf64_ia64_link_hash_table
*ia64_info
;
1894 boolean reltext
= false;
1895 boolean relplt
= false;
1897 dynobj
= elf_hash_table(info
)->dynobj
;
1898 ia64_info
= elf64_ia64_hash_table (info
);
1899 BFD_ASSERT(dynobj
!= NULL
);
1902 /* Set the contents of the .interp section to the interpreter. */
1903 if (ia64_info
->root
.dynamic_sections_created
1906 sec
= bfd_get_section_by_name (dynobj
, ".interp");
1907 BFD_ASSERT (sec
!= NULL
);
1908 sec
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
1909 sec
->_raw_size
= strlen (ELF_DYNAMIC_INTERPRETER
) + 1;
1912 /* DT_INIT and DT_FINI get function descriptors not raw code addresses.
1913 Force their symbols to have pltoff entries so we can use those. */
1914 if (ia64_info
->root
.dynamic_sections_created
)
1916 struct elf_link_hash_entry
*h
;
1917 struct elf64_ia64_dyn_sym_info
*dyn_i
;
1919 if (info
->init_function
1920 && (h
= elf_link_hash_lookup (elf_hash_table (info
),
1921 info
->init_function
, false,
1923 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
1924 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
1926 dyn_i
= get_dyn_sym_info (ia64_info
, h
, output_bfd
, NULL
, true);
1927 dyn_i
->want_pltoff
= 1;
1930 if (info
->fini_function
1931 && (h
= elf_link_hash_lookup (elf_hash_table (info
),
1932 info
->fini_function
, false,
1934 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
1935 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
1937 dyn_i
= get_dyn_sym_info (ia64_info
, h
, output_bfd
, NULL
, true);
1938 dyn_i
->want_pltoff
= 1;
1942 /* Allocate the GOT entries. */
1944 if (ia64_info
->got_sec
)
1947 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_global_data_got
, &data
);
1948 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_global_fptr_got
, &data
);
1949 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_local_got
, &data
);
1950 ia64_info
->got_sec
->_raw_size
= data
.ofs
;
1953 /* Allocate the FPTR entries. */
1955 if (ia64_info
->fptr_sec
)
1958 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_fptr
, &data
);
1959 ia64_info
->fptr_sec
->_raw_size
= data
.ofs
;
1962 /* Now that we've seen all of the input files, we can decide which
1963 symbols need plt entries. Allocate the minimal PLT entries first.
1964 We do this even though dynamic_sections_created may be false, because
1965 this has the side-effect of clearing want_plt and want_plt2. */
1968 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_plt_entries
, &data
);
1970 ia64_info
->minplt_entries
= 0;
1973 ia64_info
->minplt_entries
1974 = (data
.ofs
- PLT_HEADER_SIZE
) / PLT_MIN_ENTRY_SIZE
;
1977 /* Align the pointer for the plt2 entries. */
1978 data
.ofs
= (data
.ofs
+ 31) & -32;
1980 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_plt2_entries
, &data
);
1983 BFD_ASSERT (ia64_info
->root
.dynamic_sections_created
);
1985 ia64_info
->plt_sec
->_raw_size
= data
.ofs
;
1987 /* If we've got a .plt, we need some extra memory for the dynamic
1988 linker. We stuff these in .got.plt. */
1989 sec
= bfd_get_section_by_name (dynobj
, ".got.plt");
1990 sec
->_raw_size
= 8 * PLT_RESERVED_WORDS
;
1993 /* Allocate the PLTOFF entries. */
1995 if (ia64_info
->pltoff_sec
)
1998 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_pltoff_entries
, &data
);
1999 ia64_info
->pltoff_sec
->_raw_size
= data
.ofs
;
2002 if (ia64_info
->root
.dynamic_sections_created
)
2004 /* Allocate space for the dynamic relocations that turned out to be
2007 elf64_ia64_dyn_sym_traverse (ia64_info
, allocate_dynrel_entries
, &data
);
2010 /* We have now determined the sizes of the various dynamic sections.
2011 Allocate memory for them. */
2012 for (sec
= dynobj
->sections
; sec
!= NULL
; sec
= sec
->next
)
2016 if (!(sec
->flags
& SEC_LINKER_CREATED
))
2019 /* If we don't need this section, strip it from the output file.
2020 There were several sections primarily related to dynamic
2021 linking that must be create before the linker maps input
2022 sections to output sections. The linker does that before
2023 bfd_elf_size_dynamic_sections is called, and it is that
2024 function which decides whether anything needs to go into
2027 strip
= (sec
->_raw_size
== 0);
2029 if (sec
== ia64_info
->got_sec
)
2031 else if (sec
== ia64_info
->rel_got_sec
)
2034 ia64_info
->rel_got_sec
= NULL
;
2036 /* We use the reloc_count field as a counter if we need to
2037 copy relocs into the output file. */
2038 sec
->reloc_count
= 0;
2040 else if (sec
== ia64_info
->fptr_sec
)
2043 ia64_info
->fptr_sec
= NULL
;
2045 else if (sec
== ia64_info
->plt_sec
)
2048 ia64_info
->plt_sec
= NULL
;
2050 else if (sec
== ia64_info
->pltoff_sec
)
2053 ia64_info
->pltoff_sec
= NULL
;
2055 else if (sec
== ia64_info
->rel_pltoff_sec
)
2058 ia64_info
->rel_pltoff_sec
= NULL
;
2062 /* We use the reloc_count field as a counter if we need to
2063 copy relocs into the output file. */
2064 sec
->reloc_count
= 0;
2071 /* It's OK to base decisions on the section name, because none
2072 of the dynobj section names depend upon the input files. */
2073 name
= bfd_get_section_name (dynobj
, sec
);
2075 if (strcmp (name
, ".got.plt") == 0)
2077 else if (strncmp (name
, ".rel", 4) == 0)
2081 const char *outname
;
2084 /* If this relocation section applies to a read only
2085 section, then we probably need a DT_TEXTREL entry. */
2086 outname
= bfd_get_section_name (output_bfd
,
2087 sec
->output_section
);
2088 if (outname
[4] == 'a')
2093 target
= bfd_get_section_by_name (output_bfd
, outname
);
2095 && (target
->flags
& SEC_READONLY
) != 0
2096 && (target
->flags
& SEC_ALLOC
) != 0)
2099 /* We use the reloc_count field as a counter if we need to
2100 copy relocs into the output file. */
2101 sec
->reloc_count
= 0;
2109 _bfd_strip_section_from_output (info
, sec
);
2112 /* Allocate memory for the section contents. */
2113 sec
->contents
= (bfd_byte
*) bfd_zalloc(dynobj
, sec
->_raw_size
);
2114 if (sec
->contents
== NULL
&& sec
->_raw_size
!= 0)
2119 if (elf_hash_table (info
)->dynamic_sections_created
)
2121 /* Add some entries to the .dynamic section. We fill in the values
2122 later (in finish_dynamic_sections) but we must add the entries now
2123 so that we get the correct size for the .dynamic section. */
2127 /* The DT_DEBUG entry is filled in by the dynamic linker and used
2129 if (!bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
2133 if (! bfd_elf64_add_dynamic_entry (info
, DT_IA_64_PLT_RESERVE
, 0))
2135 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0))
2140 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2141 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2142 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
2146 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
2147 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
2148 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
2149 sizeof(Elf64_External_Rela
)))
2154 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2159 /* ??? Perhaps force __gp local. */
2164 static bfd_reloc_status_type
2165 elf64_ia64_install_value (abfd
, hit_addr
, val
, r_type
)
2169 unsigned int r_type
;
2171 const struct ia64_operand
*op
;
2172 int bigendian
= 0, shift
= 0;
2173 bfd_vma t0
, t1
, insn
, dword
;
2174 enum ia64_opnd opnd
;
2178 opnd
= IA64_OPND_NIL
;
2183 return bfd_reloc_ok
;
2185 /* Instruction relocations. */
2187 case R_IA64_IMM14
: opnd
= IA64_OPND_IMM14
; break;
2188 case R_IA64_PCREL21F
: opnd
= IA64_OPND_TGT25
; break;
2189 case R_IA64_PCREL21M
: opnd
= IA64_OPND_TGT25b
; break;
2190 case R_IA64_PCREL21B
: opnd
= IA64_OPND_TGT25c
; break;
2193 case R_IA64_GPREL22
:
2194 case R_IA64_LTOFF22
:
2195 case R_IA64_LTOFF22X
:
2196 case R_IA64_PLTOFF22
:
2197 case R_IA64_LTOFF_FPTR22
:
2198 opnd
= IA64_OPND_IMM22
;
2202 case R_IA64_GPREL64I
:
2203 case R_IA64_LTOFF64I
:
2204 case R_IA64_PLTOFF64I
:
2205 case R_IA64_FPTR64I
:
2206 case R_IA64_LTOFF_FPTR64I
:
2207 opnd
= IA64_OPND_IMMU64
;
2210 /* Data relocations. */
2212 case R_IA64_DIR32MSB
:
2213 case R_IA64_GPREL32MSB
:
2214 case R_IA64_FPTR32MSB
:
2215 case R_IA64_PCREL32MSB
:
2216 case R_IA64_SEGREL32MSB
:
2217 case R_IA64_SECREL32MSB
:
2218 case R_IA64_LTV32MSB
:
2219 size
= 4; bigendian
= 1;
2222 case R_IA64_DIR32LSB
:
2223 case R_IA64_GPREL32LSB
:
2224 case R_IA64_FPTR32LSB
:
2225 case R_IA64_PCREL32LSB
:
2226 case R_IA64_SEGREL32LSB
:
2227 case R_IA64_SECREL32LSB
:
2228 case R_IA64_LTV32LSB
:
2229 size
= 4; bigendian
= 0;
2232 case R_IA64_DIR64MSB
:
2233 case R_IA64_GPREL64MSB
:
2234 case R_IA64_PLTOFF64MSB
:
2235 case R_IA64_FPTR64MSB
:
2236 case R_IA64_PCREL64MSB
:
2237 case R_IA64_LTOFF_FPTR64MSB
:
2238 case R_IA64_SEGREL64MSB
:
2239 case R_IA64_SECREL64MSB
:
2240 case R_IA64_LTV64MSB
:
2241 size
= 8; bigendian
= 1;
2244 case R_IA64_DIR64LSB
:
2245 case R_IA64_GPREL64LSB
:
2246 case R_IA64_PLTOFF64LSB
:
2247 case R_IA64_FPTR64LSB
:
2248 case R_IA64_PCREL64LSB
:
2249 case R_IA64_LTOFF_FPTR64LSB
:
2250 case R_IA64_SEGREL64LSB
:
2251 case R_IA64_SECREL64LSB
:
2252 case R_IA64_LTV64LSB
:
2253 size
= 8; bigendian
= 0;
2256 /* Unsupported / Dynamic relocations. */
2258 case R_IA64_REL32MSB
:
2259 case R_IA64_REL32LSB
:
2260 case R_IA64_REL64MSB
:
2261 case R_IA64_REL64LSB
:
2263 case R_IA64_IPLTMSB
:
2264 case R_IA64_IPLTLSB
:
2265 case R_IA64_EPLTMSB
:
2266 case R_IA64_EPLTLSB
:
2269 case R_IA64_SEGBASE
:
2271 case R_IA64_TPREL22
:
2272 case R_IA64_TPREL64MSB
:
2273 case R_IA64_TPREL64LSB
:
2274 case R_IA64_LTOFF_TP22
:
2277 return bfd_reloc_notsupported
;
2282 case IA64_OPND_IMMU64
:
2283 hit_addr
-= (long) hit_addr
& 0x3;
2284 t0
= bfd_get_64 (abfd
, hit_addr
);
2285 t1
= bfd_get_64 (abfd
, hit_addr
+ 8);
2287 /* tmpl/s: bits 0.. 5 in t0
2288 slot 0: bits 5..45 in t0
2289 slot 1: bits 46..63 in t0, bits 0..22 in t1
2290 slot 2: bits 23..63 in t1 */
2292 /* First, clear the bits that form the 64 bit constant. */
2293 t0
&= ~(0x3ffffLL
<< 46);
2295 | (( (0x07fLL
<< 13) | (0x1ffLL
<< 27)
2296 | (0x01fLL
<< 22) | (0x001LL
<< 21)
2297 | (0x001LL
<< 36)) << 23));
2299 t0
|= ((val
>> 22) & 0x03ffffLL
) << 46; /* 18 lsbs of imm41 */
2300 t1
|= ((val
>> 40) & 0x7fffffLL
) << 0; /* 23 msbs of imm41 */
2301 t1
|= ( (((val
>> 0) & 0x07f) << 13) /* imm7b */
2302 | (((val
>> 7) & 0x1ff) << 27) /* imm9d */
2303 | (((val
>> 16) & 0x01f) << 22) /* imm5c */
2304 | (((val
>> 21) & 0x001) << 21) /* ic */
2305 | (((val
>> 63) & 0x001) << 36)) << 23; /* i */
2307 bfd_put_64 (abfd
, t0
, hit_addr
);
2308 bfd_put_64 (abfd
, t1
, hit_addr
+ 8);
2312 switch ((long) hit_addr
& 0x3)
2314 case 0: shift
= 5; break;
2315 case 1: shift
= 14; hit_addr
+= 3; break;
2316 case 2: shift
= 23; hit_addr
+= 6; break;
2317 case 3: return bfd_reloc_notsupported
; /* shouldn't happen... */
2319 dword
= bfd_get_64 (abfd
, hit_addr
);
2320 insn
= (dword
>> shift
) & 0x1ffffffffffLL
;
2322 op
= elf64_ia64_operands
+ opnd
;
2323 err
= (*op
->insert
) (op
, val
, &insn
);
2325 return bfd_reloc_overflow
;
2327 dword
&= ~(0x1ffffffffffLL
<< shift
);
2328 dword
|= (insn
<< shift
);
2329 bfd_put_64 (abfd
, dword
, hit_addr
);
2333 /* A data relocation. */
2336 bfd_putb32 (val
, hit_addr
);
2338 bfd_putb64 (val
, hit_addr
);
2341 bfd_putl32 (val
, hit_addr
);
2343 bfd_putl64 (val
, hit_addr
);
2347 return bfd_reloc_ok
;
2351 elf64_ia64_install_dyn_reloc (abfd
, info
, sec
, srel
, offset
, type
,
2354 struct bfd_link_info
*info
;
2362 Elf_Internal_Rela outrel
;
2364 outrel
.r_offset
= (sec
->output_section
->vma
2365 + sec
->output_offset
2368 BFD_ASSERT (dynindx
!= -1);
2369 outrel
.r_info
= ELF64_R_INFO (dynindx
, type
);
2370 outrel
.r_addend
= addend
;
2372 if (elf_section_data (sec
)->stab_info
!= NULL
)
2374 /* This may be NULL for linker-generated relocations, as it is
2375 inconvenient to pass all the bits around. And this shouldn't
2377 BFD_ASSERT (info
!= NULL
);
2379 offset
= (_bfd_stab_section_offset
2380 (abfd
, &elf_hash_table (info
)->stab_info
, sec
,
2381 &elf_section_data (sec
)->stab_info
, offset
));
2382 if (offset
== (bfd_vma
) -1)
2384 /* Run for the hills. We shouldn't be outputting a relocation
2385 for this. So do what everyone else does and output a no-op. */
2386 outrel
.r_info
= ELF64_R_INFO (0, R_IA64_NONE
);
2387 outrel
.r_addend
= 0;
2390 outrel
.r_offset
= offset
;
2393 bfd_elf64_swap_reloca_out (abfd
, &outrel
,
2394 ((Elf64_External_Rela
*) srel
->contents
2395 + srel
->reloc_count
++));
2396 BFD_ASSERT (sizeof(Elf64_External_Rela
) * srel
->reloc_count
2397 <= srel
->_cooked_size
);
2400 /* Store an entry for target address TARGET_ADDR in the linkage table
2401 and return the gp-relative address of the linkage table entry. */
2404 set_got_entry (abfd
, info
, dyn_i
, dynindx
, addend
, value
, dyn_r_type
)
2406 struct bfd_link_info
*info
;
2407 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2411 unsigned int dyn_r_type
;
2413 struct elf64_ia64_link_hash_table
*ia64_info
;
2416 ia64_info
= elf64_ia64_hash_table (info
);
2417 got_sec
= ia64_info
->got_sec
;
2419 BFD_ASSERT ((dyn_i
->got_offset
& 7) == 0);
2421 if (! dyn_i
->got_done
)
2423 dyn_i
->got_done
= true;
2425 /* Store the target address in the linkage table entry. */
2426 bfd_put_64 (abfd
, value
, got_sec
->contents
+ dyn_i
->got_offset
);
2428 /* Install a dynamic relocation if needed. */
2430 || elf64_ia64_dynamic_symbol_p (dyn_i
->h
, info
)
2431 || (dynindx
!= -1 && dyn_r_type
== R_IA64_FPTR64LSB
))
2435 dyn_r_type
= R_IA64_REL64LSB
;
2440 if (bfd_big_endian (abfd
))
2444 case R_IA64_REL64LSB
:
2445 dyn_r_type
= R_IA64_REL64MSB
;
2447 case R_IA64_DIR64LSB
:
2448 dyn_r_type
= R_IA64_DIR64MSB
;
2450 case R_IA64_FPTR64LSB
:
2451 dyn_r_type
= R_IA64_FPTR64MSB
;
2459 elf64_ia64_install_dyn_reloc (abfd
, NULL
, got_sec
,
2460 ia64_info
->rel_got_sec
,
2461 dyn_i
->got_offset
, dyn_r_type
,
2466 /* Return the address of the linkage table entry. */
2467 value
= (got_sec
->output_section
->vma
2468 + got_sec
->output_offset
2469 + dyn_i
->got_offset
);
2474 /* Fill in a function descriptor consisting of the function's code
2475 address and its global pointer. Return the descriptor's address. */
2478 set_fptr_entry (abfd
, info
, dyn_i
, value
)
2480 struct bfd_link_info
*info
;
2481 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2484 struct elf64_ia64_link_hash_table
*ia64_info
;
2487 ia64_info
= elf64_ia64_hash_table (info
);
2488 fptr_sec
= ia64_info
->fptr_sec
;
2490 if (!dyn_i
->fptr_done
)
2492 dyn_i
->fptr_done
= 1;
2494 /* Fill in the function descriptor. */
2495 bfd_put_64 (abfd
, value
, fptr_sec
->contents
+ dyn_i
->fptr_offset
);
2496 bfd_put_64 (abfd
, _bfd_get_gp_value (abfd
),
2497 fptr_sec
->contents
+ dyn_i
->fptr_offset
+ 8);
2500 /* Return the descriptor's address. */
2501 value
= (fptr_sec
->output_section
->vma
2502 + fptr_sec
->output_offset
2503 + dyn_i
->fptr_offset
);
2508 /* Fill in a PLTOFF entry consisting of the function's code address
2509 and its global pointer. Return the descriptor's address. */
2512 set_pltoff_entry (abfd
, info
, dyn_i
, value
, is_plt
)
2514 struct bfd_link_info
*info
;
2515 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2519 struct elf64_ia64_link_hash_table
*ia64_info
;
2520 asection
*pltoff_sec
;
2522 ia64_info
= elf64_ia64_hash_table (info
);
2523 pltoff_sec
= ia64_info
->pltoff_sec
;
2525 /* Don't do anything if this symbol uses a real PLT entry. In
2526 that case, we'll fill this in during finish_dynamic_symbol. */
2527 if ((! dyn_i
->want_plt
|| is_plt
)
2528 && !dyn_i
->pltoff_done
)
2530 /* Fill in the function descriptor. */
2531 bfd_put_64 (abfd
, value
, pltoff_sec
->contents
+ dyn_i
->pltoff_offset
);
2532 bfd_put_64 (abfd
, _bfd_get_gp_value (abfd
),
2533 pltoff_sec
->contents
+ dyn_i
->pltoff_offset
+ 8);
2535 /* Install dynamic relocations if needed. */
2536 if (!is_plt
&& info
->shared
)
2538 unsigned int dyn_r_type
;
2540 if (bfd_big_endian (abfd
))
2541 dyn_r_type
= R_IA64_REL64MSB
;
2543 dyn_r_type
= R_IA64_REL64LSB
;
2545 elf64_ia64_install_dyn_reloc (abfd
, NULL
, pltoff_sec
,
2546 ia64_info
->rel_pltoff_sec
,
2547 dyn_i
->pltoff_offset
,
2549 elf64_ia64_install_dyn_reloc (abfd
, NULL
, pltoff_sec
,
2550 ia64_info
->rel_pltoff_sec
,
2551 dyn_i
->pltoff_offset
+ 8,
2555 dyn_i
->pltoff_done
= 1;
2558 /* Return the descriptor's address. */
2559 value
= (pltoff_sec
->output_section
->vma
2560 + pltoff_sec
->output_offset
2561 + dyn_i
->pltoff_offset
);
2567 elf64_ia64_final_link (abfd
, info
)
2569 struct bfd_link_info
*info
;
2571 struct elf64_ia64_link_hash_table
*ia64_info
;
2572 ia64_info
= elf64_ia64_hash_table (info
);
2574 /* Make sure we've got ourselves a nice fat __gp value. */
2575 if (!info
->relocateable
)
2577 bfd_vma min_vma
= (bfd_vma
) -1, max_vma
= 0;
2578 bfd_vma min_short_vma
= min_vma
, max_short_vma
= 0;
2579 struct elf_link_hash_entry
*gp
;
2583 /* Find the min and max vma of all sections marked short. Also
2584 collect min and max vma of any type, for use in selecting a
2586 for (os
= abfd
->sections
; os
; os
= os
->next
)
2590 if ((os
->flags
& SEC_ALLOC
) == 0)
2594 hi
= os
->vma
+ os
->_raw_size
;
2602 if (os
->flags
& SEC_SMALL_DATA
)
2604 if (min_short_vma
> lo
)
2606 if (max_short_vma
< hi
)
2611 /* See if the user wants to force a value. */
2612 gp
= elf_link_hash_lookup (elf_hash_table (info
), "__gp", false,
2616 && (gp
->root
.type
== bfd_link_hash_defined
2617 || gp
->root
.type
== bfd_link_hash_defweak
))
2619 asection
*gp_sec
= gp
->root
.u
.def
.section
;
2620 gp_val
= (gp
->root
.u
.def
.value
2621 + gp_sec
->output_section
->vma
2622 + gp_sec
->output_offset
);
2626 /* Pick a sensible value. */
2628 asection
*got_sec
= ia64_info
->got_sec
;
2630 /* Start with just the address of the .got. */
2632 gp_val
= got_sec
->output_section
->vma
;
2633 else if (max_short_vma
!= 0)
2634 gp_val
= min_short_vma
;
2638 /* If it is possible to address the entire image, but we
2639 don't with the choice above, adjust. */
2640 if (max_vma
- min_vma
< 0x400000
2641 && max_vma
- gp_val
<= 0x200000
2642 && gp_val
- min_vma
> 0x200000)
2643 gp_val
= min_vma
+ 0x200000;
2644 else if (max_short_vma
!= 0)
2646 /* If we don't cover all the short data, adjust. */
2647 if (max_short_vma
- gp_val
>= 0x200000)
2648 gp_val
= min_short_vma
+ 0x200000;
2650 /* If we're addressing stuff past the end, adjust back. */
2651 if (gp_val
> max_vma
)
2652 gp_val
= max_vma
- 0x200000 + 8;
2656 /* Validate whether all SHF_IA_64_SHORT sections are within
2657 range of the chosen GP. */
2659 if (max_short_vma
!= 0)
2661 if (max_short_vma
- min_short_vma
>= 0x400000)
2663 (*_bfd_error_handler
)
2664 (_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
2665 bfd_get_filename (abfd
),
2666 (unsigned long)(max_short_vma
- min_short_vma
));
2669 else if ((gp_val
> min_short_vma
2670 && gp_val
- min_short_vma
> 0x200000)
2671 || (gp_val
< max_short_vma
2672 && max_short_vma
- gp_val
>= 0x200000))
2674 (*_bfd_error_handler
)
2675 (_("%s: __gp does not cover short data segment"),
2676 bfd_get_filename (abfd
));
2681 _bfd_set_gp_value (abfd
, gp_val
);
2684 /* Tricky bits. DT_INIT and DT_FINI use a pltoff entry, which is
2685 normally initialized in finish_dynamic_sections. Except that
2686 we need all non-plt pltoff entries to be initialized before
2687 finish_dynamic_symbols. This because the array of relocations
2688 used for plt entries (aka DT_JMPREL) begins after all the
2689 non-plt pltoff relocations. If the order gets confused, we
2690 munge either the array or the array base. */
2691 if (ia64_info
->root
.dynamic_sections_created
)
2693 struct elf_link_hash_entry
*h
;
2694 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2697 if (info
->init_function
2698 && (h
= elf_link_hash_lookup (elf_hash_table (info
),
2699 info
->init_function
, false,
2701 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2702 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
2704 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
2705 addr
= (h
->root
.u
.def
.section
->output_section
->vma
2706 + h
->root
.u
.def
.section
->output_offset
2707 + h
->root
.u
.def
.value
);
2708 (void) set_pltoff_entry (abfd
, info
, dyn_i
, addr
, false);
2711 if (info
->fini_function
2712 && (h
= elf_link_hash_lookup (elf_hash_table (info
),
2713 info
->fini_function
, false,
2715 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
2716 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
2718 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
2719 addr
= (h
->root
.u
.def
.section
->output_section
->vma
2720 + h
->root
.u
.def
.section
->output_offset
2721 + h
->root
.u
.def
.value
);
2722 (void) set_pltoff_entry (abfd
, info
, dyn_i
, addr
, false);
2726 /* Invoke the regular ELF backend linker to do all the work. */
2727 return bfd_elf64_bfd_final_link (abfd
, info
);
2731 elf64_ia64_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2732 contents
, relocs
, local_syms
, local_sections
)
2734 struct bfd_link_info
*info
;
2736 asection
*input_section
;
2738 Elf_Internal_Rela
*relocs
;
2739 Elf_Internal_Sym
*local_syms
;
2740 asection
**local_sections
;
2742 struct elf64_ia64_link_hash_table
*ia64_info
;
2743 Elf_Internal_Shdr
*symtab_hdr
;
2744 Elf_Internal_Rela
*rel
;
2745 Elf_Internal_Rela
*relend
;
2747 boolean ret_val
= true; /* for non-fatal errors */
2750 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2751 ia64_info
= elf64_ia64_hash_table (info
);
2753 /* Infect various flags from the input section to the output section. */
2754 if (info
->relocateable
)
2758 flags
= elf_section_data(input_section
)->this_hdr
.sh_flags
;
2759 flags
&= SHF_IA_64_NORECOV
;
2761 elf_section_data(input_section
->output_section
)
2762 ->this_hdr
.sh_flags
|= flags
;
2765 gp_val
= _bfd_get_gp_value (output_bfd
);
2766 srel
= get_reloc_section (input_bfd
, ia64_info
, input_section
, false);
2769 relend
= relocs
+ input_section
->reloc_count
;
2770 for (; rel
< relend
; ++rel
)
2772 struct elf_link_hash_entry
*h
;
2773 struct elf64_ia64_dyn_sym_info
*dyn_i
;
2774 bfd_reloc_status_type r
;
2775 reloc_howto_type
*howto
;
2776 unsigned long r_symndx
;
2777 Elf_Internal_Sym
*sym
;
2778 unsigned int r_type
;
2782 boolean dynamic_symbol_p
;
2783 boolean undef_weak_ref
;
2785 r_type
= ELF64_R_TYPE (rel
->r_info
);
2786 if (r_type
> R_IA64_MAX_RELOC_CODE
)
2788 (*_bfd_error_handler
)
2789 (_("%s: unknown relocation type %d"),
2790 bfd_get_filename (input_bfd
), (int)r_type
);
2791 bfd_set_error (bfd_error_bad_value
);
2795 howto
= lookup_howto (r_type
);
2796 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2798 if (info
->relocateable
)
2800 /* This is a relocateable link. We don't have to change
2801 anything, unless the reloc is against a section symbol,
2802 in which case we have to adjust according to where the
2803 section symbol winds up in the output section. */
2804 if (r_symndx
< symtab_hdr
->sh_info
)
2806 sym
= local_syms
+ r_symndx
;
2807 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2809 sym_sec
= local_sections
[r_symndx
];
2810 rel
->r_addend
+= sym_sec
->output_offset
;
2816 /* This is a final link. */
2821 undef_weak_ref
= false;
2823 if (r_symndx
< symtab_hdr
->sh_info
)
2825 /* Reloc against local symbol. */
2826 sym
= local_syms
+ r_symndx
;
2827 sym_sec
= local_sections
[r_symndx
];
2828 value
= (sym_sec
->output_section
->vma
2829 + sym_sec
->output_offset
2836 /* Reloc against global symbol. */
2837 indx
= r_symndx
- symtab_hdr
->sh_info
;
2838 h
= elf_sym_hashes (input_bfd
)[indx
];
2839 while (h
->root
.type
== bfd_link_hash_indirect
2840 || h
->root
.type
== bfd_link_hash_warning
)
2841 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2844 if (h
->root
.type
== bfd_link_hash_defined
2845 || h
->root
.type
== bfd_link_hash_defweak
)
2847 sym_sec
= h
->root
.u
.def
.section
;
2849 /* Detect the cases that sym_sec->output_section is
2850 expected to be NULL -- all cases in which the symbol
2851 is defined in another shared module. This includes
2852 PLT relocs for which we've created a PLT entry and
2853 other relocs for which we're prepared to create
2854 dynamic relocations. */
2855 /* ??? Just accept it NULL and continue. */
2857 if (sym_sec
->output_section
!= NULL
)
2859 value
= (h
->root
.u
.def
.value
2860 + sym_sec
->output_section
->vma
2861 + sym_sec
->output_offset
);
2864 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2865 undef_weak_ref
= true;
2866 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
2870 if (! ((*info
->callbacks
->undefined_symbol
)
2871 (info
, h
->root
.root
.string
, input_bfd
,
2872 input_section
, rel
->r_offset
,
2873 (!info
->shared
|| info
->no_undefined
))))
2880 hit_addr
= contents
+ rel
->r_offset
;
2881 value
+= rel
->r_addend
;
2882 dynamic_symbol_p
= elf64_ia64_dynamic_symbol_p (h
, info
);
2893 case R_IA64_DIR32MSB
:
2894 case R_IA64_DIR32LSB
:
2895 case R_IA64_DIR64MSB
:
2896 case R_IA64_DIR64LSB
:
2897 /* Install a dynamic relocation for this reloc. */
2898 if ((dynamic_symbol_p
|| info
->shared
)
2899 && (input_section
->flags
& SEC_ALLOC
) != 0)
2901 unsigned int dyn_r_type
;
2904 BFD_ASSERT (srel
!= NULL
);
2906 /* If we don't need dynamic symbol lookup, find a
2907 matching RELATIVE relocation. */
2908 dyn_r_type
= r_type
;
2909 if (dynamic_symbol_p
)
2910 dynindx
= h
->dynindx
;
2915 case R_IA64_DIR32MSB
:
2916 dyn_r_type
= R_IA64_REL32MSB
;
2918 case R_IA64_DIR32LSB
:
2919 dyn_r_type
= R_IA64_REL32LSB
;
2921 case R_IA64_DIR64MSB
:
2922 dyn_r_type
= R_IA64_REL64MSB
;
2924 case R_IA64_DIR64LSB
:
2925 dyn_r_type
= R_IA64_REL64LSB
;
2929 /* We can't represent this without a dynamic symbol.
2930 Adjust the relocation to be against an output
2931 section symbol, which are always present in the
2932 dynamic symbol table. */
2933 /* ??? People shouldn't be doing non-pic code in
2934 shared libraries. Hork. */
2935 (*_bfd_error_handler
)
2936 (_("%s: linking non-pic code in a shared library"),
2937 bfd_get_filename (input_bfd
));
2944 elf64_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
2945 srel
, rel
->r_offset
, dyn_r_type
,
2946 dynindx
, rel
->r_addend
);
2950 case R_IA64_LTV32MSB
:
2951 case R_IA64_LTV32LSB
:
2952 case R_IA64_LTV64MSB
:
2953 case R_IA64_LTV64LSB
:
2954 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
2957 case R_IA64_GPREL22
:
2958 case R_IA64_GPREL64I
:
2959 case R_IA64_GPREL32MSB
:
2960 case R_IA64_GPREL32LSB
:
2961 case R_IA64_GPREL64MSB
:
2962 case R_IA64_GPREL64LSB
:
2963 if (dynamic_symbol_p
)
2965 (*_bfd_error_handler
)
2966 (_("%s: @gprel relocation against dynamic symbol %s"),
2967 bfd_get_filename (input_bfd
), h
->root
.root
.string
);
2972 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
2975 case R_IA64_LTOFF22
:
2976 case R_IA64_LTOFF22X
:
2977 case R_IA64_LTOFF64I
:
2978 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
2979 value
= set_got_entry (input_bfd
, info
, dyn_i
, (h
? h
->dynindx
: -1),
2980 rel
->r_addend
, value
, R_IA64_DIR64LSB
);
2982 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
2985 case R_IA64_PLTOFF22
:
2986 case R_IA64_PLTOFF64I
:
2987 case R_IA64_PLTOFF64MSB
:
2988 case R_IA64_PLTOFF64LSB
:
2989 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
2990 value
= set_pltoff_entry (output_bfd
, info
, dyn_i
, value
, false);
2992 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
2995 case R_IA64_FPTR64I
:
2996 case R_IA64_FPTR32MSB
:
2997 case R_IA64_FPTR32LSB
:
2998 case R_IA64_FPTR64MSB
:
2999 case R_IA64_FPTR64LSB
:
3000 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3001 if (dyn_i
->want_fptr
)
3003 if (!undef_weak_ref
)
3004 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3010 /* Otherwise, we expect the dynamic linker to create
3015 if (h
->dynindx
!= -1)
3016 dynindx
= h
->dynindx
;
3018 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3019 (info
, h
->root
.u
.def
.section
->owner
,
3020 global_sym_index (h
)));
3024 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3025 (info
, input_bfd
, r_symndx
));
3028 elf64_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3029 srel
, rel
->r_offset
, r_type
,
3030 dynindx
, rel
->r_addend
);
3034 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3037 case R_IA64_LTOFF_FPTR22
:
3038 case R_IA64_LTOFF_FPTR64I
:
3039 case R_IA64_LTOFF_FPTR64MSB
:
3040 case R_IA64_LTOFF_FPTR64LSB
:
3044 dyn_i
= get_dyn_sym_info (ia64_info
, h
, input_bfd
, rel
, false);
3045 if (dyn_i
->want_fptr
)
3047 BFD_ASSERT (h
== NULL
|| h
->dynindx
== -1)
3048 if (!undef_weak_ref
)
3049 value
= set_fptr_entry (output_bfd
, info
, dyn_i
, value
);
3054 /* Otherwise, we expect the dynamic linker to create
3058 if (h
->dynindx
!= -1)
3059 dynindx
= h
->dynindx
;
3061 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3062 (info
, h
->root
.u
.def
.section
->owner
,
3063 global_sym_index (h
)));
3066 dynindx
= (_bfd_elf_link_lookup_local_dynindx
3067 (info
, input_bfd
, r_symndx
));
3071 value
= set_got_entry (output_bfd
, info
, dyn_i
, dynindx
,
3072 rel
->r_addend
, value
, R_IA64_FPTR64LSB
);
3074 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3078 case R_IA64_PCREL32MSB
:
3079 case R_IA64_PCREL32LSB
:
3080 case R_IA64_PCREL64MSB
:
3081 case R_IA64_PCREL64LSB
:
3082 /* Install a dynamic relocation for this reloc. */
3083 if (dynamic_symbol_p
)
3085 BFD_ASSERT (srel
!= NULL
);
3087 elf64_ia64_install_dyn_reloc (output_bfd
, info
, input_section
,
3088 srel
, rel
->r_offset
, r_type
,
3089 h
->dynindx
, rel
->r_addend
);
3093 case R_IA64_PCREL21F
:
3094 case R_IA64_PCREL21M
:
3095 /* ??? These two are only used for speculation fixup code.
3096 They should never be dynamic. */
3097 if (dynamic_symbol_p
)
3099 (*_bfd_error_handler
)
3100 (_("%s: dynamic relocation against speculation fixup"),
3101 bfd_get_filename (input_bfd
));
3107 (*_bfd_error_handler
)
3108 (_("%s: speculation fixup against undefined weak symbol"),
3109 bfd_get_filename (input_bfd
));
3115 case R_IA64_PCREL21B
:
3116 /* We should have created a PLT entry for any dynamic symbol. */
3117 /* ??? How to handle out of range branches, which are supposed
3118 to be fixed up by a conforming linker. */
3122 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
3124 if (dyn_i
&& dyn_i
->want_plt2
)
3126 /* Should have caught this earlier. */
3127 BFD_ASSERT (rel
->r_addend
== 0);
3129 value
= (ia64_info
->plt_sec
->output_section
->vma
3130 + ia64_info
->plt_sec
->output_offset
3131 + dyn_i
->plt2_offset
);
3135 /* Since there's no PLT entry, Validate that this is
3137 BFD_ASSERT (undef_weak_ref
|| sym_sec
->output_section
!= NULL
);
3139 /* If the symbol is undef_weak, we shouldn't be trying
3140 to call it. There's every chance that we'd wind up
3141 with an out-of-range fixup here. Don't bother setting
3142 any value at all. */
3149 /* Make pc-relative. */
3150 value
-= (input_section
->output_section
->vma
3151 + input_section
->output_offset
3152 + rel
->r_offset
) & ~ (bfd_vma
) 0x3;
3153 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3156 case R_IA64_SEGREL32MSB
:
3157 case R_IA64_SEGREL32LSB
:
3158 case R_IA64_SEGREL64MSB
:
3159 case R_IA64_SEGREL64LSB
:
3161 struct elf_segment_map
*m
;
3162 Elf_Internal_Phdr
*p
;
3164 /* Find the segment that contains the output_section. */
3165 for (m
= elf_tdata (output_bfd
)->segment_map
,
3166 p
= elf_tdata (output_bfd
)->phdr
;
3171 for (i
= m
->count
- 1; i
>= 0; i
--)
3172 if (m
->sections
[i
] == sym_sec
->output_section
)
3180 /* If the input section was discarded from the output, then
3183 if (bfd_is_abs_section (sym_sec
->output_section
))
3186 r
= bfd_reloc_notsupported
;
3190 /* The VMA of the segment is the vaddr of the associated
3192 if (value
> p
->p_vaddr
)
3193 value
-= p
->p_vaddr
;
3196 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
,
3202 case R_IA64_SECREL32MSB
:
3203 case R_IA64_SECREL32LSB
:
3204 case R_IA64_SECREL64MSB
:
3205 case R_IA64_SECREL64LSB
:
3206 /* Make output-section relative. */
3207 if (value
> input_section
->output_section
->vma
)
3208 value
-= input_section
->output_section
->vma
;
3211 r
= elf64_ia64_install_value (output_bfd
, hit_addr
, value
, r_type
);
3214 case R_IA64_SEGBASE
:
3216 case R_IA64_REL32MSB
:
3217 case R_IA64_REL32LSB
:
3218 case R_IA64_REL64MSB
:
3219 case R_IA64_REL64LSB
:
3221 case R_IA64_IPLTMSB
:
3222 case R_IA64_IPLTLSB
:
3223 case R_IA64_EPLTMSB
:
3224 case R_IA64_EPLTLSB
:
3227 case R_IA64_TPREL22
:
3228 case R_IA64_TPREL64MSB
:
3229 case R_IA64_TPREL64LSB
:
3230 case R_IA64_LTOFF_TP22
:
3232 r
= bfd_reloc_notsupported
;
3241 case bfd_reloc_undefined
:
3242 /* This can happen for global table relative relocs if
3243 __gp is undefined. This is a panic situation so we
3244 don't try to continue. */
3245 (*info
->callbacks
->undefined_symbol
)
3246 (info
, "__gp", input_bfd
, input_section
, rel
->r_offset
, 1);
3249 case bfd_reloc_notsupported
:
3254 name
= h
->root
.root
.string
;
3257 name
= bfd_elf_string_from_elf_section (input_bfd
,
3258 symtab_hdr
->sh_link
,
3263 name
= bfd_section_name (input_bfd
, input_section
);
3265 if (!(*info
->callbacks
->warning
) (info
, _("unsupported reloc"),
3267 input_section
, rel
->r_offset
))
3273 case bfd_reloc_dangerous
:
3274 case bfd_reloc_outofrange
:
3275 case bfd_reloc_overflow
:
3281 name
= h
->root
.root
.string
;
3284 name
= bfd_elf_string_from_elf_section (input_bfd
,
3285 symtab_hdr
->sh_link
,
3290 name
= bfd_section_name (input_bfd
, input_section
);
3292 if (!(*info
->callbacks
->reloc_overflow
) (info
, name
,
3308 elf64_ia64_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3310 struct bfd_link_info
*info
;
3311 struct elf_link_hash_entry
*h
;
3312 Elf_Internal_Sym
*sym
;
3314 struct elf64_ia64_link_hash_table
*ia64_info
;
3315 struct elf64_ia64_dyn_sym_info
*dyn_i
;
3317 ia64_info
= elf64_ia64_hash_table (info
);
3318 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
3320 /* Fill in the PLT data, if required. */
3321 if (dyn_i
&& dyn_i
->want_plt
)
3323 Elf_Internal_Rela outrel
;
3326 bfd_vma plt_addr
, pltoff_addr
, gp_val
, index
;
3327 Elf64_External_Rela
*rel
;
3329 gp_val
= _bfd_get_gp_value (output_bfd
);
3331 /* Initialize the minimal PLT entry. */
3333 index
= (dyn_i
->plt_offset
- PLT_HEADER_SIZE
) / PLT_MIN_ENTRY_SIZE
;
3334 plt_sec
= ia64_info
->plt_sec
;
3335 loc
= plt_sec
->contents
+ dyn_i
->plt_offset
;
3337 memcpy (loc
, plt_min_entry
, PLT_MIN_ENTRY_SIZE
);
3338 elf64_ia64_install_value (output_bfd
, loc
, index
, R_IA64_IMM22
);
3339 elf64_ia64_install_value (output_bfd
, loc
+2, -dyn_i
->plt_offset
,
3342 plt_addr
= (plt_sec
->output_section
->vma
3343 + plt_sec
->output_offset
3344 + dyn_i
->plt_offset
);
3345 pltoff_addr
= set_pltoff_entry (output_bfd
, info
, dyn_i
, plt_addr
, true);
3347 /* Initialize the FULL PLT entry, if needed. */
3348 if (dyn_i
->want_plt2
)
3350 loc
= plt_sec
->contents
+ dyn_i
->plt2_offset
;
3352 memcpy (loc
, plt_full_entry
, PLT_FULL_ENTRY_SIZE
);
3353 elf64_ia64_install_value (output_bfd
, loc
, pltoff_addr
- gp_val
,
3356 /* Mark the symbol as undefined, rather than as defined in the
3357 plt section. Leave the value alone. */
3358 /* ??? We didn't redefine it in adjust_dynamic_symbol in the
3359 first place. But perhaps elflink.h did some for us. */
3360 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3361 sym
->st_shndx
= SHN_UNDEF
;
3364 /* Create the dynamic relocation. */
3365 outrel
.r_offset
= pltoff_addr
;
3366 if (bfd_little_endian (output_bfd
))
3367 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_IA64_IPLTLSB
);
3369 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, R_IA64_IPLTMSB
);
3370 outrel
.r_addend
= 0;
3372 /* This is fun. In the .IA_64.pltoff section, we've got entries
3373 that correspond both to real PLT entries, and those that
3374 happened to resolve to local symbols but need to be created
3375 to satisfy @pltoff relocations. The .rela.IA_64.pltoff
3376 relocations for the real PLT should come at the end of the
3377 section, so that they can be indexed by plt entry at runtime.
3379 We emitted all of the relocations for the non-PLT @pltoff
3380 entries during relocate_section. So we can consider the
3381 existing sec->reloc_count to be the base of the array of
3384 rel
= (Elf64_External_Rela
*)ia64_info
->rel_pltoff_sec
->contents
;
3385 rel
+= ia64_info
->rel_pltoff_sec
->reloc_count
;
3387 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, rel
+ index
);
3390 /* Mark some specially defined symbols as absolute. */
3391 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3392 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3393 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
3394 sym
->st_shndx
= SHN_ABS
;
3400 elf64_ia64_finish_dynamic_sections (abfd
, info
)
3402 struct bfd_link_info
*info
;
3404 struct elf64_ia64_link_hash_table
*ia64_info
;
3407 ia64_info
= elf64_ia64_hash_table (info
);
3408 dynobj
= ia64_info
->root
.dynobj
;
3410 if (elf_hash_table (info
)->dynamic_sections_created
)
3412 Elf64_External_Dyn
*dyncon
, *dynconend
;
3413 asection
*sdyn
, *sgotplt
;
3416 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3417 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3418 BFD_ASSERT (sdyn
!= NULL
);
3419 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3420 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3422 gp_val
= _bfd_get_gp_value (abfd
);
3424 for (; dyncon
< dynconend
; dyncon
++)
3426 Elf_Internal_Dyn dyn
;
3430 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3435 dyn
.d_un
.d_ptr
= gp_val
;
3439 dyn
.d_un
.d_val
= (ia64_info
->minplt_entries
3440 * sizeof (Elf64_External_Rela
));
3444 /* See the comment above in finish_dynamic_symbol. */
3445 dyn
.d_un
.d_ptr
= (ia64_info
->rel_pltoff_sec
->output_section
->vma
3446 + ia64_info
->rel_pltoff_sec
->output_offset
3447 + (ia64_info
->rel_pltoff_sec
->reloc_count
3448 * sizeof (Elf64_External_Rela
)));
3451 case DT_IA_64_PLT_RESERVE
:
3452 dyn
.d_un
.d_ptr
= (sgotplt
->output_section
->vma
3453 + sgotplt
->output_offset
);
3457 /* Do not have RELASZ include JMPREL. This makes things
3458 easier on ld.so. This is not what the rest of BFD set up. */
3459 dyn
.d_un
.d_val
-= (ia64_info
->minplt_entries
3460 * sizeof (Elf64_External_Rela
));
3466 struct elf_link_hash_entry
*h
;
3467 struct elf64_ia64_dyn_sym_info
*dyn_i
;
3470 if (dyn
.d_tag
== DT_INIT
)
3471 which
= info
->init_function
;
3473 which
= info
->fini_function
;
3475 h
= elf_link_hash_lookup (elf_hash_table (info
), which
,
3476 false, false, false);
3477 dyn_i
= get_dyn_sym_info (ia64_info
, h
, NULL
, NULL
, false);
3478 dyn
.d_un
.d_ptr
= set_pltoff_entry (abfd
, info
, dyn_i
,
3483 bfd_elf64_swap_dyn_out (abfd
, &dyn
, dyncon
);
3486 /* Initialize the PLT0 entry */
3487 if (ia64_info
->plt_sec
)
3489 bfd_byte
*loc
= ia64_info
->plt_sec
->contents
;
3492 memcpy (loc
, plt_header
, PLT_HEADER_SIZE
);
3494 pltres
= (sgotplt
->output_section
->vma
3495 + sgotplt
->output_offset
3498 elf64_ia64_install_value (abfd
, loc
+1, pltres
, R_IA64_GPREL22
);
3505 /* ELF file flag handling: */
3507 /* Function to keep IA-64 specific file flags. */
3509 elf64_ia64_set_private_flags (abfd
, flags
)
3513 BFD_ASSERT (!elf_flags_init (abfd
)
3514 || elf_elfheader (abfd
)->e_flags
== flags
);
3516 elf_elfheader (abfd
)->e_flags
= flags
;
3517 elf_flags_init (abfd
) = true;
3521 /* Copy backend specific data from one object module to another */
3523 elf64_ia64_copy_private_bfd_data (ibfd
, obfd
)
3526 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3527 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3530 BFD_ASSERT (!elf_flags_init (obfd
)
3531 || (elf_elfheader (obfd
)->e_flags
3532 == elf_elfheader (ibfd
)->e_flags
));
3534 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
3535 elf_flags_init (obfd
) = true;
3539 /* Merge backend specific data from an object file to the output
3540 object file when linking. */
3542 elf64_ia64_merge_private_bfd_data (ibfd
, obfd
)
3549 /* Don't even pretend to support mixed-format linking. */
3550 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3551 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3554 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3555 out_flags
= elf_elfheader (obfd
)->e_flags
;
3557 if (! elf_flags_init (obfd
))
3559 elf_flags_init (obfd
) = true;
3560 elf_elfheader (obfd
)->e_flags
= in_flags
;
3562 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3563 && bfd_get_arch_info (obfd
)->the_default
)
3565 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
3566 bfd_get_mach (ibfd
));
3572 /* Check flag compatibility. */
3573 if (in_flags
== out_flags
)
3576 if ((in_flags
& EF_IA_64_TRAPNIL
) != (out_flags
& EF_IA_64_TRAPNIL
))
3578 (*_bfd_error_handler
)
3579 (_("%s: linking trap-on-NULL-dereference with non-trapping files"),
3580 bfd_get_filename (ibfd
));
3582 bfd_set_error (bfd_error_bad_value
);
3585 if ((in_flags
& EF_IA_64_BE
) != (out_flags
& EF_IA_64_BE
))
3587 (*_bfd_error_handler
)
3588 (_("%s: linking big-endian files with little-endian files"),
3589 bfd_get_filename (ibfd
));
3591 bfd_set_error (bfd_error_bad_value
);
3594 if ((in_flags
& EF_IA_64_ABI64
) != (out_flags
& EF_IA_64_ABI64
))
3596 (*_bfd_error_handler
)
3597 (_("%s: linking 64-bit files with 32-bit files"),
3598 bfd_get_filename (ibfd
));
3600 bfd_set_error (bfd_error_bad_value
);
3608 elf64_ia64_print_private_bfd_data (abfd
, ptr
)
3612 FILE *file
= (FILE *) ptr
;
3613 flagword flags
= elf_elfheader (abfd
)->e_flags
;
3615 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3617 fprintf (file
, "private flags = %s%s%s%s\n",
3618 (flags
& EF_IA_64_TRAPNIL
) ? "TRAPNIL, " : "",
3619 (flags
& EF_IA_64_EXT
) ? "EXT, " : "",
3620 (flags
& EF_IA_64_BE
) ? "BE, " : "LE, ",
3621 (flags
& EF_IA_64_ABI64
) ? "ABI64" : "ABI32");
3622 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3626 #define TARGET_LITTLE_SYM bfd_elf64_ia64_little_vec
3627 #define TARGET_LITTLE_NAME "elf64-ia64-little"
3628 #define TARGET_BIG_SYM bfd_elf64_ia64_big_vec
3629 #define TARGET_BIG_NAME "elf64-ia64-big"
3630 #define ELF_ARCH bfd_arch_ia64
3631 #define ELF_MACHINE_CODE EM_IA_64
3632 #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */
3633 #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */
3634 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
3636 #define elf_backend_section_from_shdr \
3637 elf64_ia64_section_from_shdr
3638 #define elf_backend_fake_sections \
3639 elf64_ia64_fake_sections
3640 #define elf_backend_add_symbol_hook \
3641 elf64_ia64_add_symbol_hook
3642 #define elf_backend_additional_program_headers \
3643 elf64_ia64_additional_program_headers
3644 #define elf_backend_modify_segment_map \
3645 elf64_ia64_modify_segment_map
3646 #define elf_info_to_howto \
3647 elf64_ia64_info_to_howto
3649 #define bfd_elf64_bfd_reloc_type_lookup \
3650 elf64_ia64_reloc_type_lookup
3651 #define bfd_elf64_bfd_is_local_label_name \
3652 elf64_ia64_is_local_label_name
3654 /* Stuff for the BFD linker: */
3655 #define bfd_elf64_bfd_link_hash_table_create \
3656 elf64_ia64_hash_table_create
3657 #define elf_backend_create_dynamic_sections \
3658 elf64_ia64_create_dynamic_sections
3659 #define elf_backend_check_relocs \
3660 elf64_ia64_check_relocs
3661 #define elf_backend_adjust_dynamic_symbol \
3662 elf64_ia64_adjust_dynamic_symbol
3663 #define elf_backend_size_dynamic_sections \
3664 elf64_ia64_size_dynamic_sections
3665 #define elf_backend_relocate_section \
3666 elf64_ia64_relocate_section
3667 #define elf_backend_finish_dynamic_symbol \
3668 elf64_ia64_finish_dynamic_symbol
3669 #define elf_backend_finish_dynamic_sections \
3670 elf64_ia64_finish_dynamic_sections
3671 #define bfd_elf64_bfd_final_link \
3672 elf64_ia64_final_link
3674 #define bfd_elf64_bfd_copy_private_bfd_data \
3675 elf64_ia64_copy_private_bfd_data
3676 #define bfd_elf64_bfd_merge_private_bfd_data \
3677 elf64_ia64_merge_private_bfd_data
3678 #define bfd_elf64_bfd_set_private_flags \
3679 elf64_ia64_set_private_flags
3680 #define bfd_elf64_bfd_print_private_bfd_data \
3681 elf64_ia64_print_private_bfd_data
3683 #define elf_backend_plt_readonly 1
3684 #define elf_backend_want_plt_sym 0
3685 #define elf_backend_plt_alignment 5
3686 #define elf_backend_got_header_size 0
3687 #define elf_backend_plt_header_size PLT_HEADER_SIZE
3688 #define elf_backend_want_got_plt 1
3689 #define elf_backend_may_use_rel_p 1
3690 #define elf_backend_may_use_rela_p 1
3691 #define elf_backend_default_use_rela_p 1
3692 #define elf_backend_want_dynbss 0
3693 #define elf_backend_copy_indirect_symbol elf64_ia64_hash_copy_indirect
3694 #define elf_backend_hide_symbol elf64_ia64_hash_hide_symbol
3696 #include "elf64-target.h"