Commit | Line | Data |
---|---|---|
800eeca4 JW |
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> | |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "bfd.h" | |
22 | #include "sysdep.h" | |
23 | #include "libbfd.h" | |
24 | #include "elf-bfd.h" | |
25 | #include "opcode/ia64.h" | |
26 | #include "elf/ia64.h" | |
27 | ||
28 | /* | |
29 | * THE RULES for all the stuff the linker creates -- | |
30 | * | |
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. | |
35 | * | |
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. | |
42 | * | |
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. | |
46 | * | |
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. | |
53 | * | |
54 | * MIN_PLT Created by PLTOFF entries against dynamic symbols. This | |
55 | * does not reqire dynamic relocations. | |
56 | */ | |
57 | ||
58 | #define USE_RELA /* we want RELA relocs, not REL */ | |
59 | ||
60 | #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0]))) | |
61 | ||
62 | typedef struct bfd_hash_entry *(*new_hash_entry_func) | |
63 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
64 | ||
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. */ | |
68 | ||
69 | struct elf64_ia64_dyn_sym_info | |
70 | { | |
71 | /* The addend for which this entry is relevant. */ | |
72 | bfd_vma addend; | |
73 | ||
74 | /* Next addend in the list. */ | |
75 | struct elf64_ia64_dyn_sym_info *next; | |
76 | ||
77 | bfd_vma got_offset; | |
78 | bfd_vma fptr_offset; | |
79 | bfd_vma pltoff_offset; | |
80 | bfd_vma plt_offset; | |
81 | bfd_vma plt2_offset; | |
82 | ||
83 | /* The symbol table entry, if any, that this was derrived from. */ | |
84 | struct elf_link_hash_entry *h; | |
85 | ||
86 | /* Used to count non-got, non-plt relocations for delayed sizing | |
87 | of relocation sections. */ | |
88 | struct elf64_ia64_dyn_reloc_entry | |
89 | { | |
90 | struct elf64_ia64_dyn_reloc_entry *next; | |
91 | asection *srel; | |
92 | int type; | |
93 | int count; | |
94 | } *reloc_entries; | |
95 | ||
96 | /* True when the section contents have been updated. */ | |
97 | unsigned got_done : 1; | |
98 | unsigned fptr_done : 1; | |
99 | unsigned pltoff_done : 1; | |
100 | ||
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; | |
108 | }; | |
109 | ||
110 | struct elf64_ia64_local_hash_entry | |
111 | { | |
112 | struct bfd_hash_entry root; | |
113 | struct elf64_ia64_dyn_sym_info *info; | |
114 | }; | |
115 | ||
116 | struct elf64_ia64_local_hash_table | |
117 | { | |
118 | struct bfd_hash_table root; | |
119 | /* No additional fields for now. */ | |
120 | }; | |
121 | ||
122 | struct elf64_ia64_link_hash_entry | |
123 | { | |
124 | struct elf_link_hash_entry root; | |
125 | struct elf64_ia64_dyn_sym_info *info; | |
126 | }; | |
127 | ||
128 | struct elf64_ia64_link_hash_table | |
129 | { | |
130 | /* The main hash table */ | |
131 | struct elf_link_hash_table root; | |
132 | ||
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 */ | |
139 | ||
140 | bfd_size_type minplt_entries; /* number of minplt entries */ | |
141 | ||
142 | struct elf64_ia64_local_hash_table loc_hash_table; | |
143 | }; | |
144 | ||
145 | #define elf64_ia64_hash_table(p) \ | |
146 | ((struct elf64_ia64_link_hash_table *) ((p)->hash)) | |
147 | ||
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, | |
164 | bfd_vma *valp)); | |
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), | |
188 | PTR info)); | |
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, | |
248 | bfd_vma value)); | |
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)); | |
273 | ||
274 | \f | |
275 | /* ia64-specific relocation */ | |
276 | ||
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) | |
282 | bfd *abfd; | |
283 | arelent *reloc; | |
284 | asymbol *sym; | |
285 | PTR data; | |
286 | asection *input_section; | |
287 | bfd *output_bfd; | |
288 | char **error_message; | |
289 | { | |
290 | if (output_bfd) | |
291 | { | |
292 | reloc->address += input_section->output_offset; | |
293 | return bfd_reloc_ok; | |
294 | } | |
295 | *error_message = "Unsupported call to elf64_ia64_reloc"; | |
296 | return bfd_reloc_notsupported; | |
297 | } | |
298 | ||
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) | |
302 | ||
303 | /* This table has to be sorted according to increasing number of the | |
304 | TYPE field. */ | |
305 | static reloc_howto_type ia64_howto_table[] = | |
306 | { | |
307 | IA64_HOWTO (R_IA64_NONE, "NONE", 0, false, true), | |
308 | ||
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), | |
316 | ||
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), | |
323 | ||
324 | IA64_HOWTO (R_IA64_LTOFF22, "LTOFF22", 0, false, true), | |
325 | IA64_HOWTO (R_IA64_LTOFF64I, "LTOFF64I", 0, false, true), | |
326 | ||
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), | |
331 | ||
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), | |
337 | ||
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), | |
345 | ||
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), | |
350 | ||
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), | |
356 | ||
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), | |
361 | ||
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), | |
366 | ||
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), | |
371 | ||
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), | |
379 | ||
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), | |
384 | }; | |
385 | ||
386 | static unsigned char elf_code_to_howto_index[R_IA64_MAX_RELOC_CODE + 1]; | |
387 | ||
388 | /* Given a BFD reloc type, return the matching HOWTO structure. */ | |
389 | ||
390 | static reloc_howto_type* | |
391 | lookup_howto (rtype) | |
392 | unsigned int rtype; | |
393 | { | |
394 | static int inited = 0; | |
395 | int i; | |
396 | ||
397 | if (!inited) | |
398 | { | |
399 | inited = 1; | |
400 | ||
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; | |
404 | } | |
405 | ||
406 | BFD_ASSERT (rtype <= R_IA64_MAX_RELOC_CODE); | |
407 | i = elf_code_to_howto_index[rtype]; | |
408 | if (i >= NELEMS (ia64_howto_table)) | |
409 | return 0; | |
410 | return ia64_howto_table + i; | |
411 | } | |
412 | ||
413 | static reloc_howto_type* | |
414 | elf64_ia64_reloc_type_lookup (abfd, bfd_code) | |
415 | bfd *abfd; | |
416 | bfd_reloc_code_real_type bfd_code; | |
417 | { | |
418 | unsigned int rtype; | |
419 | ||
420 | switch (bfd_code) | |
421 | { | |
422 | case BFD_RELOC_NONE: rtype = R_IA64_NONE; break; | |
423 | ||
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; | |
427 | ||
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; | |
432 | ||
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; | |
439 | ||
440 | case BFD_RELOC_IA64_LTOFF22: rtype = R_IA64_LTOFF22; break; | |
441 | case BFD_RELOC_IA64_LTOFF64I: rtype = R_IA64_LTOFF64I; break; | |
442 | ||
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; | |
452 | ||
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; | |
460 | ||
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; | |
465 | ||
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; | |
471 | ||
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; | |
476 | ||
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; | |
481 | ||
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; | |
486 | ||
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; | |
494 | ||
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; | |
499 | ||
500 | default: return 0; | |
501 | } | |
502 | return lookup_howto (rtype); | |
503 | } | |
504 | ||
505 | /* Given a ELF reloc, return the matching HOWTO structure. */ | |
506 | ||
507 | static void | |
508 | elf64_ia64_info_to_howto (abfd, bfd_reloc, elf_reloc) | |
509 | bfd *abfd; | |
510 | arelent *bfd_reloc; | |
511 | Elf64_Internal_Rela *elf_reloc; | |
512 | { | |
513 | bfd_reloc->howto = lookup_howto (ELF64_R_TYPE (elf_reloc->r_info)); | |
514 | } | |
515 | \f | |
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 | |
520 | ||
521 | static const bfd_byte plt_header[PLT_HEADER_SIZE] = | |
522 | { | |
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;; */ | |
532 | }; | |
533 | ||
534 | static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] = | |
535 | { | |
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>;; */ | |
539 | }; | |
540 | ||
541 | static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] = | |
542 | { | |
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;; */ | |
549 | }; | |
550 | ||
551 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
552 | \f | |
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. */ | |
555 | ||
556 | static boolean | |
557 | elf64_ia64_section_from_shdr (abfd, hdr, name) | |
558 | bfd *abfd; | |
559 | Elf64_Internal_Shdr *hdr; | |
560 | char *name; | |
561 | { | |
562 | asection *newsect; | |
563 | ||
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) | |
570 | { | |
571 | case SHT_IA_64_UNWIND: | |
572 | if (strcmp (name, ELF_STRING_ia64_unwind) != 0) | |
573 | return false; | |
574 | break; | |
575 | ||
576 | case SHT_IA_64_EXT: | |
577 | if (strcmp (name, ELF_STRING_ia64_archext) != 0) | |
578 | return false; | |
579 | break; | |
580 | ||
581 | default: | |
582 | return false; | |
583 | } | |
584 | ||
585 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | |
586 | return false; | |
587 | newsect = hdr->bfd_section; | |
588 | ||
589 | if (hdr->sh_flags & SHF_IA_64_SHORT) | |
590 | newsect->flags |= SEC_SMALL_DATA; | |
591 | ||
592 | return true; | |
593 | } | |
594 | ||
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. */ | |
597 | ||
598 | static boolean | |
599 | elf64_ia64_fake_sections (abfd, hdr, sec) | |
600 | bfd *abfd; | |
601 | Elf64_Internal_Shdr *hdr; | |
602 | asection *sec; | |
603 | { | |
604 | register const char *name; | |
605 | ||
606 | name = bfd_get_section_name (abfd, sec); | |
607 | ||
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) | |
613 | /* | |
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 | |
629 | * unlikely to bite. | |
630 | */ | |
631 | hdr->sh_type = SHT_PROGBITS; | |
632 | ||
633 | if (sec->flags & SEC_SMALL_DATA) | |
634 | hdr->sh_flags |= SHF_IA_64_SHORT; | |
635 | ||
636 | return true; | |
637 | } | |
638 | ||
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. */ | |
641 | ||
642 | static boolean | |
643 | elf64_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) | |
644 | bfd *abfd; | |
645 | struct bfd_link_info *info; | |
646 | const Elf_Internal_Sym *sym; | |
647 | const char **namep; | |
648 | flagword *flagsp; | |
649 | asection **secp; | |
650 | bfd_vma *valp; | |
651 | { | |
652 | if (sym->st_shndx == SHN_COMMON | |
653 | && !info->relocateable | |
654 | && sym->st_size <= bfd_get_gp_size (abfd)) | |
655 | { | |
656 | /* Common symbols less than or equal to -G nn bytes are | |
657 | automatically put into .sbss. */ | |
658 | ||
659 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); | |
660 | ||
661 | if (scomm == NULL) | |
662 | { | |
663 | scomm = bfd_make_section (abfd, ".scommon"); | |
664 | if (scomm == NULL | |
665 | || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC | |
666 | | SEC_IS_COMMON | |
667 | | SEC_LINKER_CREATED))) | |
668 | return false; | |
669 | } | |
670 | ||
671 | *secp = scomm; | |
672 | *valp = sym->st_size; | |
673 | } | |
674 | ||
675 | return true; | |
676 | } | |
677 | ||
678 | /* Return the number of additional phdrs we will need. */ | |
679 | ||
680 | static int | |
681 | elf64_ia64_additional_program_headers (abfd) | |
682 | bfd *abfd; | |
683 | { | |
684 | asection *s; | |
685 | int ret = 0; | |
686 | ||
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)) | |
690 | ++ret; | |
691 | ||
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)) | |
695 | ++ret; | |
696 | ||
697 | return ret; | |
698 | } | |
699 | ||
700 | static boolean | |
701 | elf64_ia64_modify_segment_map (abfd) | |
702 | bfd *abfd; | |
703 | { | |
704 | struct elf_segment_map *m, **pm; | |
705 | asection *s; | |
706 | ||
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)) | |
711 | { | |
712 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | |
713 | if (m->p_type == PT_IA_64_ARCHEXT) | |
714 | break; | |
715 | if (m == NULL) | |
716 | { | |
717 | m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); | |
718 | if (m == NULL) | |
719 | return false; | |
720 | ||
721 | m->p_type = PT_IA_64_ARCHEXT; | |
722 | m->count = 1; | |
723 | m->sections[0] = s; | |
724 | ||
725 | /* We want to put it after the PHDR and INTERP segments. */ | |
726 | pm = &elf_tdata (abfd)->segment_map; | |
727 | while (*pm != NULL | |
728 | && ((*pm)->p_type == PT_PHDR | |
729 | || (*pm)->p_type == PT_INTERP)) | |
730 | pm = &(*pm)->next; | |
731 | ||
732 | m->next = *pm; | |
733 | *pm = m; | |
734 | } | |
735 | } | |
736 | ||
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)) | |
740 | { | |
741 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | |
742 | if (m->p_type == PT_IA_64_UNWIND) | |
743 | break; | |
744 | if (m == NULL) | |
745 | { | |
746 | m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); | |
747 | if (m == NULL) | |
748 | return false; | |
749 | ||
750 | m->p_type = PT_IA_64_UNWIND; | |
751 | m->count = 1; | |
752 | m->sections[0] = s; | |
753 | m->next = NULL; | |
754 | ||
755 | /* We want to put it last. */ | |
756 | pm = &elf_tdata (abfd)->segment_map; | |
757 | while (*pm != NULL) | |
758 | pm = &(*pm)->next; | |
759 | *pm = m; | |
760 | } | |
761 | } | |
762 | ||
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) | |
768 | { | |
769 | int i; | |
770 | for (i = m->count - 1; i >= 0; --i) | |
771 | { | |
772 | struct bfd_link_order *order = m->sections[i]->link_order_head; | |
773 | while (order) | |
774 | { | |
775 | if (order->type == bfd_indirect_link_order) | |
776 | { | |
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) | |
780 | { | |
781 | m->p_flags |= PF_IA_64_NORECOV; | |
782 | goto found; | |
783 | } | |
784 | } | |
785 | order = order->next; | |
786 | } | |
787 | } | |
788 | found:; | |
789 | } | |
790 | ||
791 | return true; | |
792 | } | |
793 | ||
794 | ||
795 | /* According to the Tahoe assembler spec, all labels starting with a | |
796 | '.' are local. */ | |
797 | ||
798 | static boolean | |
799 | elf64_ia64_is_local_label_name (abfd, name) | |
800 | bfd *abfd; | |
801 | const char *name; | |
802 | { | |
803 | return name[0] == '.'; | |
804 | } | |
805 | ||
806 | /* Should we do dynamic things to this symbol? */ | |
807 | ||
808 | static boolean | |
809 | elf64_ia64_dynamic_symbol_p (h, info) | |
810 | struct elf_link_hash_entry *h; | |
811 | struct bfd_link_info *info; | |
812 | { | |
813 | if (h == NULL) | |
814 | return false; | |
815 | ||
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; | |
819 | ||
820 | if (h->dynindx == -1) | |
821 | return false; | |
822 | ||
823 | if (h->root.type == bfd_link_hash_undefweak | |
824 | || h->root.type == bfd_link_hash_defweak) | |
825 | return true; | |
826 | ||
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))) | |
831 | return true; | |
832 | ||
833 | return false; | |
834 | } | |
835 | \f | |
836 | static boolean | |
837 | elf64_ia64_local_hash_table_init (ht, abfd, new) | |
838 | struct elf64_ia64_local_hash_table *ht; | |
839 | bfd *abfd; | |
840 | new_hash_entry_func new; | |
841 | { | |
842 | memset (ht, 0, sizeof(*ht)); | |
843 | return bfd_hash_table_init (&ht->root, new); | |
844 | } | |
845 | ||
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; | |
850 | const char *string; | |
851 | { | |
852 | struct elf64_ia64_local_hash_entry *ret; | |
853 | ret = (struct elf64_ia64_local_hash_entry *) entry; | |
854 | ||
855 | /* Allocate the structure if it has not already been allocated by a | |
856 | subclass. */ | |
857 | if (!ret) | |
858 | ret = bfd_hash_allocate (table, sizeof (*ret)); | |
859 | ||
860 | if (!ret) | |
861 | return 0; | |
862 | ||
863 | /* Initialize our local data. All zeros, and definitely easier | |
864 | than setting a handful of bit fields. */ | |
865 | memset (ret, 0, sizeof(*ret)); | |
866 | ||
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)); | |
870 | ||
871 | return (struct bfd_hash_entry *) ret; | |
872 | } | |
873 | ||
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; | |
878 | const char *string; | |
879 | { | |
880 | struct elf64_ia64_link_hash_entry *ret; | |
881 | ret = (struct elf64_ia64_link_hash_entry *) entry; | |
882 | ||
883 | /* Allocate the structure if it has not already been allocated by a | |
884 | subclass. */ | |
885 | if (!ret) | |
886 | ret = bfd_hash_allocate (table, sizeof (*ret)); | |
887 | ||
888 | if (!ret) | |
889 | return 0; | |
890 | ||
891 | /* Initialize our local data. All zeros, and definitely easier | |
892 | than setting a handful of bit fields. */ | |
893 | memset (ret, 0, sizeof(*ret)); | |
894 | ||
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, | |
898 | table, string)); | |
899 | ||
900 | return (struct bfd_hash_entry *) ret; | |
901 | } | |
902 | ||
903 | static void | |
904 | elf64_ia64_hash_copy_indirect (xdir, xind) | |
905 | struct elf_link_hash_entry *xdir, *xind; | |
906 | { | |
907 | struct elf64_ia64_link_hash_entry *dir, *ind; | |
908 | ||
909 | dir = (struct elf64_ia64_link_hash_entry *)xdir; | |
910 | ind = (struct elf64_ia64_link_hash_entry *)xind; | |
911 | ||
912 | /* Copy down any references that we may have already seen to the | |
913 | symbol which just became indirect. */ | |
914 | ||
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)); | |
920 | ||
921 | /* Copy over the got and plt data. This would have been done | |
922 | by check_relocs. */ | |
923 | ||
924 | if (dir->info == NULL) | |
925 | { | |
926 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
927 | ||
928 | dir->info = dyn_i = ind->info; | |
929 | ind->info = NULL; | |
930 | ||
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; | |
934 | } | |
935 | BFD_ASSERT (ind->info == NULL); | |
936 | ||
937 | /* Copy over the dynindx. */ | |
938 | ||
939 | if (dir->root.dynindx == -1) | |
940 | { | |
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; | |
945 | } | |
946 | BFD_ASSERT (ind->root.dynindx == -1); | |
947 | } | |
948 | ||
949 | static void | |
950 | elf64_ia64_hash_hide_symbol (xh) | |
951 | struct elf_link_hash_entry *xh; | |
952 | { | |
953 | struct elf64_ia64_link_hash_entry *h; | |
954 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
955 | ||
956 | h = (struct elf64_ia64_link_hash_entry *)xh; | |
957 | ||
958 | h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
959 | h->root.dynindx = -1; | |
960 | ||
961 | for (dyn_i = h->info; dyn_i; dyn_i = dyn_i->next) | |
962 | dyn_i->want_plt2 = 0; | |
963 | } | |
964 | ||
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). */ | |
968 | ||
969 | static struct bfd_link_hash_table* | |
970 | elf64_ia64_hash_table_create (abfd) | |
971 | bfd *abfd; | |
972 | { | |
973 | struct elf64_ia64_link_hash_table *ret; | |
974 | ||
975 | ret = bfd_alloc (abfd, sizeof (*ret)); | |
976 | if (!ret) | |
977 | return 0; | |
978 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, | |
979 | elf64_ia64_new_elf_hash_entry)) | |
980 | { | |
981 | bfd_release (abfd, ret); | |
982 | return 0; | |
983 | } | |
984 | ||
985 | if (!elf64_ia64_local_hash_table_init (&ret->loc_hash_table, abfd, | |
986 | elf64_ia64_new_loc_hash_entry)) | |
987 | return 0; | |
988 | return &ret->root.root; | |
989 | } | |
990 | ||
991 | /* Look up an entry in a Alpha ELF linker hash table. */ | |
992 | ||
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; | |
996 | const char *string; | |
997 | boolean create, copy; | |
998 | { | |
999 | return ((struct elf64_ia64_local_hash_entry *) | |
1000 | bfd_hash_lookup (&table->root, string, create, copy)); | |
1001 | } | |
1002 | ||
1003 | /* Traverse both local and global hash tables. */ | |
1004 | ||
1005 | struct elf64_ia64_dyn_sym_traverse_data | |
1006 | { | |
1007 | boolean (*func) PARAMS ((struct elf64_ia64_dyn_sym_info *, PTR)); | |
1008 | PTR data; | |
1009 | }; | |
1010 | ||
1011 | static boolean | |
1012 | elf64_ia64_global_dyn_sym_thunk (xentry, xdata) | |
1013 | struct bfd_hash_entry *xentry; | |
1014 | PTR xdata; | |
1015 | { | |
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; | |
1021 | ||
1022 | for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next) | |
1023 | if (! (*data->func) (dyn_i, data->data)) | |
1024 | return false; | |
1025 | return true; | |
1026 | } | |
1027 | ||
1028 | static boolean | |
1029 | elf64_ia64_local_dyn_sym_thunk (xentry, xdata) | |
1030 | struct bfd_hash_entry *xentry; | |
1031 | PTR xdata; | |
1032 | { | |
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; | |
1038 | ||
1039 | for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next) | |
1040 | if (! (*data->func) (dyn_i, data->data)) | |
1041 | return false; | |
1042 | return true; | |
1043 | } | |
1044 | ||
1045 | static void | |
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)); | |
1049 | PTR data; | |
1050 | { | |
1051 | struct elf64_ia64_dyn_sym_traverse_data xdata; | |
1052 | ||
1053 | xdata.func = func; | |
1054 | xdata.data = data; | |
1055 | ||
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); | |
1060 | } | |
1061 | \f | |
1062 | static boolean | |
1063 | elf64_ia64_create_dynamic_sections (abfd, info) | |
1064 | bfd *abfd; | |
1065 | struct bfd_link_info *info; | |
1066 | { | |
1067 | struct elf64_ia64_link_hash_table *ia64_info; | |
1068 | struct elf_link_hash_entry *h; | |
1069 | asection *s; | |
1070 | ||
1071 | if (! _bfd_elf_create_dynamic_sections (abfd, info)) | |
1072 | return false; | |
1073 | ||
1074 | ia64_info = elf64_ia64_hash_table (info); | |
1075 | ||
1076 | ia64_info->plt_sec = bfd_get_section_by_name (abfd, ".plt"); | |
1077 | ia64_info->got_sec = bfd_get_section_by_name (abfd, ".got"); | |
1078 | ||
1079 | { | |
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); | |
1082 | } | |
1083 | ||
1084 | if (!get_pltoff (abfd, info, ia64_info)) | |
1085 | return false; | |
1086 | ||
1087 | s = bfd_make_section(abfd, ".rela.IA_64.pltoff"); | |
1088 | if (s == NULL | |
1089 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | |
1090 | | SEC_HAS_CONTENTS | |
1091 | | SEC_IN_MEMORY | |
1092 | | SEC_LINKER_CREATED | |
1093 | | SEC_READONLY)) | |
1094 | || !bfd_set_section_alignment (abfd, s, 3)) | |
1095 | return false; | |
1096 | ia64_info->rel_pltoff_sec = s; | |
1097 | ||
1098 | s = bfd_make_section(abfd, ".rela.got"); | |
1099 | if (s == NULL | |
1100 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | |
1101 | | SEC_HAS_CONTENTS | |
1102 | | SEC_IN_MEMORY | |
1103 | | SEC_LINKER_CREATED | |
1104 | | SEC_READONLY)) | |
1105 | || !bfd_set_section_alignment (abfd, s, 3)) | |
1106 | return false; | |
1107 | ia64_info->rel_got_sec = s; | |
1108 | ||
1109 | return true; | |
1110 | } | |
1111 | ||
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. */ | |
1114 | ||
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; | |
1119 | bfd *abfd; | |
1120 | const Elf_Internal_Rela *rel; | |
1121 | boolean create; | |
1122 | { | |
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; | |
1126 | ||
1127 | if (h) | |
1128 | pp = &((struct elf64_ia64_link_hash_entry *)h)->info; | |
1129 | else | |
1130 | { | |
1131 | struct elf64_ia64_local_hash_entry *loc_h; | |
1132 | char *addr_name; | |
1133 | size_t len; | |
1134 | ||
1135 | /* Construct a string for use in the elf64_ia64_local_hash_table. | |
1136 | The name describes what was once anonymous memory. */ | |
1137 | ||
1138 | len = sizeof(void*)*2 + 1 + sizeof(bfd_vma)*4 + 1 + 1; | |
1139 | len += 10; /* %p slop */ | |
1140 | ||
1141 | addr_name = alloca (len); | |
1142 | sprintf (addr_name, "%p:%lx", abfd, ELF64_R_SYM (rel->r_info)); | |
1143 | ||
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); | |
1147 | BFD_ASSERT (loc_h); | |
1148 | ||
1149 | pp = &loc_h->info; | |
1150 | } | |
1151 | ||
1152 | for (dyn_i = *pp; dyn_i && dyn_i->addend != addend; dyn_i = *pp) | |
1153 | pp = &dyn_i->next; | |
1154 | ||
1155 | if (dyn_i == NULL && create) | |
1156 | { | |
1157 | dyn_i = (struct elf64_ia64_dyn_sym_info *) | |
1158 | bfd_zalloc (abfd, sizeof *dyn_i); | |
1159 | *pp = dyn_i; | |
1160 | dyn_i->addend = addend; | |
1161 | } | |
1162 | ||
1163 | return dyn_i; | |
1164 | } | |
1165 | ||
1166 | static asection * | |
1167 | get_got (abfd, info, ia64_info) | |
1168 | bfd *abfd; | |
1169 | struct bfd_link_info *info; | |
1170 | struct elf64_ia64_link_hash_table *ia64_info; | |
1171 | { | |
1172 | asection *got, *srel; | |
1173 | bfd *dynobj; | |
1174 | ||
1175 | got = ia64_info->got_sec; | |
1176 | if (!got) | |
1177 | { | |
1178 | flagword flags; | |
1179 | ||
1180 | dynobj = ia64_info->root.dynobj; | |
1181 | if (!dynobj) | |
1182 | ia64_info->root.dynobj = dynobj = abfd; | |
1183 | if (!_bfd_elf_create_got_section (dynobj, info)) | |
1184 | return 0; | |
1185 | ||
1186 | got = bfd_get_section_by_name (dynobj, ".got"); | |
1187 | BFD_ASSERT (got); | |
1188 | ia64_info->got_sec = got; | |
1189 | ||
1190 | flags = bfd_get_section_flags (abfd, got); | |
1191 | bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags); | |
1192 | } | |
1193 | ||
1194 | return got; | |
1195 | } | |
1196 | ||
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. */ | |
1201 | ||
1202 | static asection * | |
1203 | get_fptr (abfd, info, ia64_info) | |
1204 | bfd *abfd; | |
1205 | struct bfd_link_info *info; | |
1206 | struct elf64_ia64_link_hash_table *ia64_info; | |
1207 | { | |
1208 | asection *fptr; | |
1209 | bfd *dynobj; | |
1210 | ||
1211 | fptr = ia64_info->fptr_sec; | |
1212 | if (!fptr) | |
1213 | { | |
1214 | dynobj = ia64_info->root.dynobj; | |
1215 | if (!dynobj) | |
1216 | ia64_info->root.dynobj = dynobj = abfd; | |
1217 | ||
1218 | fptr = bfd_make_section (dynobj, ".opd"); | |
1219 | if (!fptr | |
1220 | || !bfd_set_section_flags (dynobj, fptr, | |
1221 | (SEC_ALLOC | |
1222 | | SEC_LOAD | |
1223 | | SEC_HAS_CONTENTS | |
1224 | | SEC_IN_MEMORY | |
1225 | | SEC_READONLY | |
1226 | | SEC_LINKER_CREATED)) | |
1227 | || !bfd_set_section_alignment (abfd, fptr, 4)) | |
1228 | { | |
1229 | BFD_ASSERT (0); | |
1230 | return NULL; | |
1231 | } | |
1232 | ||
1233 | ia64_info->fptr_sec = fptr; | |
1234 | } | |
1235 | ||
1236 | return fptr; | |
1237 | } | |
1238 | ||
1239 | static asection * | |
1240 | get_pltoff (abfd, info, ia64_info) | |
1241 | bfd *abfd; | |
1242 | struct bfd_link_info *info; | |
1243 | struct elf64_ia64_link_hash_table *ia64_info; | |
1244 | { | |
1245 | asection *pltoff; | |
1246 | bfd *dynobj; | |
1247 | ||
1248 | pltoff = ia64_info->pltoff_sec; | |
1249 | if (!pltoff) | |
1250 | { | |
1251 | dynobj = ia64_info->root.dynobj; | |
1252 | if (!dynobj) | |
1253 | ia64_info->root.dynobj = dynobj = abfd; | |
1254 | ||
1255 | pltoff = bfd_make_section (dynobj, ELF_STRING_ia64_pltoff); | |
1256 | if (!pltoff | |
1257 | || !bfd_set_section_flags (dynobj, pltoff, | |
1258 | (SEC_ALLOC | |
1259 | | SEC_LOAD | |
1260 | | SEC_HAS_CONTENTS | |
1261 | | SEC_IN_MEMORY | |
1262 | | SEC_SMALL_DATA | |
1263 | | SEC_LINKER_CREATED)) | |
1264 | || !bfd_set_section_alignment (abfd, pltoff, 4)) | |
1265 | { | |
1266 | BFD_ASSERT (0); | |
1267 | return NULL; | |
1268 | } | |
1269 | ||
1270 | ia64_info->pltoff_sec = pltoff; | |
1271 | } | |
1272 | ||
1273 | return pltoff; | |
1274 | } | |
1275 | ||
1276 | static asection * | |
1277 | get_reloc_section (abfd, ia64_info, sec, create) | |
1278 | bfd *abfd; | |
1279 | struct elf64_ia64_link_hash_table *ia64_info; | |
1280 | asection *sec; | |
1281 | boolean create; | |
1282 | { | |
1283 | const char *srel_name; | |
1284 | asection *srel; | |
1285 | bfd *dynobj; | |
1286 | ||
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) | |
1291 | return NULL; | |
1292 | ||
1293 | BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0 | |
1294 | && strcmp (bfd_get_section_name (abfd, sec), | |
1295 | srel_name+5) == 0) | |
1296 | || (strncmp (srel_name, ".rel", 4) == 0 | |
1297 | && strcmp (bfd_get_section_name (abfd, sec), | |
1298 | srel_name+4) == 0)); | |
1299 | ||
1300 | dynobj = ia64_info->root.dynobj; | |
1301 | if (!dynobj) | |
1302 | ia64_info->root.dynobj = dynobj = abfd; | |
1303 | ||
1304 | srel = bfd_get_section_by_name (dynobj, srel_name); | |
1305 | if (srel == NULL && create) | |
1306 | { | |
1307 | srel = bfd_make_section (dynobj, srel_name); | |
1308 | if (srel == NULL | |
1309 | || !bfd_set_section_flags (dynobj, srel, | |
1310 | (SEC_ALLOC | |
1311 | | SEC_LOAD | |
1312 | | SEC_HAS_CONTENTS | |
1313 | | SEC_IN_MEMORY | |
1314 | | SEC_LINKER_CREATED | |
1315 | | SEC_READONLY)) | |
1316 | || !bfd_set_section_alignment (dynobj, srel, 3)) | |
1317 | return NULL; | |
1318 | } | |
1319 | ||
1320 | return srel; | |
1321 | } | |
1322 | ||
1323 | static boolean | |
1324 | count_dyn_reloc (abfd, dyn_i, srel, type) | |
1325 | bfd *abfd; | |
1326 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1327 | asection *srel; | |
1328 | int type; | |
1329 | { | |
1330 | struct elf64_ia64_dyn_reloc_entry *rent; | |
1331 | ||
1332 | for (rent = dyn_i->reloc_entries; rent; rent = rent->next) | |
1333 | if (rent->srel == srel && rent->type == type) | |
1334 | break; | |
1335 | ||
1336 | if (!rent) | |
1337 | { | |
1338 | rent = (struct elf64_ia64_dyn_reloc_entry *) | |
1339 | bfd_alloc (abfd, sizeof (*rent)); | |
1340 | if (!rent) | |
1341 | return false; | |
1342 | ||
1343 | rent->next = dyn_i->reloc_entries; | |
1344 | rent->srel = srel; | |
1345 | rent->type = type; | |
1346 | rent->count = 0; | |
1347 | dyn_i->reloc_entries = rent; | |
1348 | } | |
1349 | rent->count++; | |
1350 | ||
1351 | return true; | |
1352 | } | |
1353 | ||
1354 | static boolean | |
1355 | elf64_ia64_check_relocs (abfd, info, sec, relocs) | |
1356 | bfd *abfd; | |
1357 | struct bfd_link_info *info; | |
1358 | asection *sec; | |
1359 | const Elf_Internal_Rela *relocs; | |
1360 | { | |
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; | |
1366 | ||
1367 | if (info->relocateable) | |
1368 | return true; | |
1369 | ||
1370 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
1371 | ia64_info = elf64_ia64_hash_table (info); | |
1372 | ||
1373 | got = fptr = srel = NULL; | |
1374 | ||
1375 | relend = relocs + sec->reloc_count; | |
1376 | for (rel = relocs; rel < relend; ++rel) | |
1377 | { | |
1378 | enum { | |
1379 | NEED_GOT = 1, | |
1380 | NEED_FPTR = 2, | |
1381 | NEED_PLTOFF = 4, | |
1382 | NEED_MIN_PLT = 8, | |
1383 | NEED_FULL_PLT = 16, | |
1384 | NEED_DYNREL = 32, | |
1385 | NEED_LTOFF_FPTR = 64, | |
1386 | }; | |
1387 | ||
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; | |
1391 | int need_entry; | |
1392 | boolean maybe_dynamic; | |
1393 | int dynrel_type; | |
1394 | ||
1395 | if (r_symndx >= symtab_hdr->sh_info) | |
1396 | { | |
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; | |
1404 | ||
1405 | h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR; | |
1406 | } | |
1407 | ||
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; | |
1417 | ||
1418 | need_entry = 0; | |
1419 | switch (ELF64_R_TYPE (rel->r_info)) | |
1420 | { | |
1421 | case R_IA64_TPREL22: | |
1422 | case R_IA64_TPREL64MSB: | |
1423 | case R_IA64_TPREL64LSB: | |
1424 | case R_IA64_LTOFF_TP22: | |
1425 | return false; | |
1426 | ||
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; | |
1432 | break; | |
1433 | ||
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; | |
1441 | else | |
1442 | need_entry = NEED_FPTR; | |
1443 | dynrel_type = R_IA64_FPTR64LSB; | |
1444 | break; | |
1445 | ||
1446 | case R_IA64_LTOFF22: | |
1447 | case R_IA64_LTOFF22X: | |
1448 | case R_IA64_LTOFF64I: | |
1449 | need_entry = NEED_GOT; | |
1450 | break; | |
1451 | ||
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; | |
1457 | if (h) | |
1458 | { | |
1459 | if (maybe_dynamic) | |
1460 | need_entry |= NEED_MIN_PLT; | |
1461 | } | |
1462 | else | |
1463 | { | |
1464 | (*info->callbacks->warning) | |
1465 | (info, _("@pltoff reloc against local symbol"), 0, | |
1466 | abfd, 0, 0); | |
1467 | } | |
1468 | break; | |
1469 | ||
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; | |
1477 | break; | |
1478 | ||
1479 | case R_IA64_IMM14: | |
1480 | case R_IA64_IMM22: | |
1481 | case R_IA64_IMM64: | |
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; | |
1490 | break; | |
1491 | ||
1492 | case R_IA64_PCREL32MSB: | |
1493 | case R_IA64_PCREL32LSB: | |
1494 | case R_IA64_PCREL64MSB: | |
1495 | case R_IA64_PCREL64LSB: | |
1496 | if (maybe_dynamic) | |
1497 | need_entry = NEED_DYNREL; | |
1498 | dynrel_type = R_IA64_PCREL64LSB; | |
1499 | break; | |
1500 | } | |
1501 | ||
1502 | if (!need_entry) | |
1503 | continue; | |
1504 | ||
1505 | if ((need_entry & NEED_FPTR) != 0 | |
1506 | && rel->r_addend) | |
1507 | { | |
1508 | (*info->callbacks->warning) | |
1509 | (info, _("non-zero addend in @fptr reloc"), 0, | |
1510 | abfd, 0, 0); | |
1511 | } | |
1512 | ||
1513 | dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, true); | |
1514 | ||
1515 | /* Record whether or not this is a local symbol. */ | |
1516 | dyn_i->h = h; | |
1517 | ||
1518 | /* Create what's needed. */ | |
1519 | if (need_entry & NEED_GOT) | |
1520 | { | |
1521 | if (!got) | |
1522 | { | |
1523 | got = get_got (abfd, info, ia64_info); | |
1524 | if (!got) | |
1525 | return false; | |
1526 | } | |
1527 | dyn_i->want_got = 1; | |
1528 | } | |
1529 | if (need_entry & NEED_FPTR) | |
1530 | { | |
1531 | if (!fptr) | |
1532 | { | |
1533 | fptr = get_fptr (abfd, info, ia64_info); | |
1534 | if (!fptr) | |
1535 | return false; | |
1536 | } | |
1537 | ||
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) | |
1542 | { | |
1543 | if (! (_bfd_elf64_link_record_local_dynamic_symbol | |
1544 | (info, abfd, r_symndx))) | |
1545 | return false; | |
1546 | } | |
1547 | ||
1548 | dyn_i->want_fptr = 1; | |
1549 | } | |
1550 | if (need_entry & NEED_LTOFF_FPTR) | |
1551 | dyn_i->want_ltoff_fptr = 1; | |
1552 | if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT)) | |
1553 | { | |
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; | |
1558 | } | |
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)) | |
1564 | { | |
1565 | if (!srel) | |
1566 | { | |
1567 | srel = get_reloc_section (abfd, ia64_info, sec, true); | |
1568 | if (!srel) | |
1569 | return false; | |
1570 | } | |
1571 | if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type)) | |
1572 | return false; | |
1573 | } | |
1574 | } | |
1575 | ||
1576 | return true; | |
1577 | } | |
1578 | ||
1579 | struct elf64_ia64_allocate_data | |
1580 | { | |
1581 | struct bfd_link_info *info; | |
1582 | bfd_size_type ofs; | |
1583 | }; | |
1584 | ||
1585 | /* For cleanliness, and potentially faster dynamic loading, allocate | |
1586 | external GOT entries first. */ | |
1587 | ||
1588 | static boolean | |
1589 | allocate_global_data_got (dyn_i, data) | |
1590 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1591 | PTR data; | |
1592 | { | |
1593 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1594 | ||
1595 | if (dyn_i->want_got | |
1596 | && ! dyn_i->want_fptr | |
1597 | && elf64_ia64_dynamic_symbol_p (dyn_i->h, x->info)) | |
1598 | { | |
1599 | dyn_i->got_offset = x->ofs; | |
1600 | x->ofs += 8; | |
1601 | } | |
1602 | return true; | |
1603 | } | |
1604 | ||
1605 | /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */ | |
1606 | ||
1607 | static boolean | |
1608 | allocate_global_fptr_got (dyn_i, data) | |
1609 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1610 | PTR data; | |
1611 | { | |
1612 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1613 | ||
1614 | if (dyn_i->want_got | |
1615 | && dyn_i->want_fptr | |
1616 | && elf64_ia64_dynamic_symbol_p (dyn_i->h, x->info)) | |
1617 | { | |
1618 | dyn_i->got_offset = x->ofs; | |
1619 | x->ofs += 8; | |
1620 | } | |
1621 | return true; | |
1622 | } | |
1623 | ||
1624 | /* Lastly, allocate all the GOT entries for local data. */ | |
1625 | ||
1626 | static boolean | |
1627 | allocate_local_got (dyn_i, data) | |
1628 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1629 | PTR data; | |
1630 | { | |
1631 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1632 | ||
1633 | if (dyn_i->want_got | |
1634 | && ! elf64_ia64_dynamic_symbol_p (dyn_i->h, x->info)) | |
1635 | { | |
1636 | dyn_i->got_offset = x->ofs; | |
1637 | x->ofs += 8; | |
1638 | } | |
1639 | return true; | |
1640 | } | |
1641 | ||
1642 | /* Search for the index of a global symbol in it's defining object file. */ | |
1643 | ||
1644 | static unsigned long | |
1645 | global_sym_index (h) | |
1646 | struct elf_link_hash_entry *h; | |
1647 | { | |
1648 | struct elf_link_hash_entry **p; | |
1649 | bfd *obj; | |
1650 | ||
1651 | BFD_ASSERT (h->root.type == bfd_link_hash_defined | |
1652 | || h->root.type == bfd_link_hash_defweak); | |
1653 | ||
1654 | obj = h->root.u.def.section->owner; | |
1655 | for (p = elf_sym_hashes (obj); *p != h; ++p) | |
1656 | continue; | |
1657 | ||
1658 | return p - elf_sym_hashes (obj) + elf_tdata (obj)->symtab_hdr.sh_info; | |
1659 | } | |
1660 | ||
1661 | /* Allocate function descriptors. We can do these for every function | |
1662 | in a main executable that is not exported. */ | |
1663 | ||
1664 | static boolean | |
1665 | allocate_fptr (dyn_i, data) | |
1666 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1667 | PTR data; | |
1668 | { | |
1669 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1670 | ||
1671 | if (dyn_i->want_fptr) | |
1672 | { | |
1673 | struct elf_link_hash_entry *h = dyn_i->h; | |
1674 | ||
1675 | if (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; | |
1679 | ||
1680 | if (x->info->shared) | |
1681 | { | |
1682 | if (h && h->dynindx == -1) | |
1683 | { | |
1684 | BFD_ASSERT ((h->root.type == bfd_link_hash_defined) | |
1685 | || (h->root.type == bfd_link_hash_defweak)); | |
1686 | ||
1687 | if (!_bfd_elf64_link_record_local_dynamic_symbol | |
1688 | (x->info, h->root.u.def.section->owner, | |
1689 | global_sym_index (h))) | |
1690 | return false; | |
1691 | } | |
1692 | ||
1693 | dyn_i->want_fptr = 0; | |
1694 | } | |
1695 | else if (h == NULL || h->dynindx == -1) | |
1696 | { | |
1697 | dyn_i->fptr_offset = x->ofs; | |
1698 | x->ofs += 16; | |
1699 | } | |
1700 | else | |
1701 | dyn_i->want_fptr = 0; | |
1702 | } | |
1703 | return true; | |
1704 | } | |
1705 | ||
1706 | /* Allocate all the minimal PLT entries. */ | |
1707 | ||
1708 | static boolean | |
1709 | allocate_plt_entries (dyn_i, data) | |
1710 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1711 | PTR data; | |
1712 | { | |
1713 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1714 | ||
1715 | if (dyn_i->want_plt) | |
1716 | { | |
1717 | struct elf_link_hash_entry *h = dyn_i->h; | |
1718 | ||
1719 | if (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; | |
1723 | ||
1724 | /* ??? Versioned symbols seem to lose ELF_LINK_HASH_NEEDS_PLT. */ | |
1725 | if (elf64_ia64_dynamic_symbol_p (h, x->info)) | |
1726 | { | |
1727 | bfd_size_type offset = x->ofs; | |
1728 | if (offset == 0) | |
1729 | offset = PLT_HEADER_SIZE; | |
1730 | dyn_i->plt_offset = offset; | |
1731 | x->ofs = offset + PLT_MIN_ENTRY_SIZE; | |
1732 | ||
1733 | dyn_i->want_pltoff = 1; | |
1734 | } | |
1735 | else | |
1736 | { | |
1737 | dyn_i->want_plt = 0; | |
1738 | dyn_i->want_plt2 = 0; | |
1739 | } | |
1740 | } | |
1741 | return true; | |
1742 | } | |
1743 | ||
1744 | /* Allocate all the full PLT entries. */ | |
1745 | ||
1746 | static boolean | |
1747 | allocate_plt2_entries (dyn_i, data) | |
1748 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1749 | PTR data; | |
1750 | { | |
1751 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1752 | ||
1753 | if (dyn_i->want_plt2) | |
1754 | { | |
1755 | struct elf_link_hash_entry *h = dyn_i->h; | |
1756 | bfd_size_type ofs = x->ofs; | |
1757 | ||
1758 | dyn_i->plt2_offset = ofs; | |
1759 | x->ofs = ofs + PLT_FULL_ENTRY_SIZE; | |
1760 | ||
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; | |
1765 | } | |
1766 | return true; | |
1767 | } | |
1768 | ||
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. */ | |
1773 | ||
1774 | static boolean | |
1775 | allocate_pltoff_entries (dyn_i, data) | |
1776 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1777 | PTR data; | |
1778 | { | |
1779 | struct elf64_ia64_allocate_data *x = (struct elf64_ia64_allocate_data *)data; | |
1780 | ||
1781 | if (dyn_i->want_pltoff) | |
1782 | { | |
1783 | dyn_i->pltoff_offset = x->ofs; | |
1784 | x->ofs += 16; | |
1785 | } | |
1786 | return true; | |
1787 | } | |
1788 | ||
1789 | /* Allocate dynamic relocations for those symbols that turned out | |
1790 | to be dynamic. */ | |
1791 | ||
1792 | static boolean | |
1793 | allocate_dynrel_entries (dyn_i, data) | |
1794 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1795 | PTR data; | |
1796 | { | |
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; | |
1801 | ||
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; | |
1805 | ||
1806 | /* Take care of the normal data relocations. */ | |
1807 | ||
1808 | for (rent = dyn_i->reloc_entries; rent; rent = rent->next) | |
1809 | { | |
1810 | switch (rent->type) | |
1811 | { | |
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) | |
1817 | continue; | |
1818 | break; | |
1819 | case R_IA64_PCREL64LSB: | |
1820 | if (!dynamic_symbol) | |
1821 | continue; | |
1822 | break; | |
1823 | case R_IA64_DIR64LSB: | |
1824 | if (!dynamic_symbol && !shared) | |
1825 | continue; | |
1826 | break; | |
1827 | } | |
1828 | rent->srel->_raw_size += sizeof (Elf64_External_Rela) * rent->count; | |
1829 | } | |
1830 | ||
1831 | /* Take care of the GOT and PLT relocations. */ | |
1832 | ||
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); | |
1836 | ||
1837 | if (dyn_i->want_pltoff) | |
1838 | { | |
1839 | bfd_size_type t = 0; | |
1840 | ||
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. */ | |
1844 | if (dynamic_symbol) | |
1845 | t = sizeof (Elf64_External_Rela); | |
1846 | else if (shared) | |
1847 | t = 2 * sizeof (Elf64_External_Rela); | |
1848 | ||
1849 | ia64_info->rel_pltoff_sec->_raw_size += t; | |
1850 | } | |
1851 | ||
1852 | return true; | |
1853 | } | |
1854 | ||
1855 | static boolean | |
1856 | elf64_ia64_adjust_dynamic_symbol (info, h) | |
1857 | struct bfd_link_info *info; | |
1858 | struct elf_link_hash_entry *h; | |
1859 | { | |
1860 | /* ??? Undefined symbols with PLT entries should be re-defined | |
1861 | to be the PLT entry. */ | |
1862 | ||
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) | |
1867 | { | |
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; | |
1872 | return true; | |
1873 | } | |
1874 | ||
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. | |
1878 | ||
1879 | But IA-64 code is canonically PIC, so as a rule we can avoid this sort | |
1880 | of hackery. */ | |
1881 | ||
1882 | return true; | |
1883 | } | |
1884 | ||
1885 | static boolean | |
1886 | elf64_ia64_size_dynamic_sections (output_bfd, info) | |
1887 | bfd *output_bfd; | |
1888 | struct bfd_link_info *info; | |
1889 | { | |
1890 | struct elf64_ia64_allocate_data data; | |
1891 | struct elf64_ia64_link_hash_table *ia64_info; | |
1892 | asection *sec; | |
1893 | bfd *dynobj; | |
1894 | boolean reltext = false; | |
1895 | boolean relplt = false; | |
1896 | ||
1897 | dynobj = elf_hash_table(info)->dynobj; | |
1898 | ia64_info = elf64_ia64_hash_table (info); | |
1899 | BFD_ASSERT(dynobj != NULL); | |
1900 | data.info = info; | |
1901 | ||
1902 | /* Set the contents of the .interp section to the interpreter. */ | |
1903 | if (ia64_info->root.dynamic_sections_created | |
1904 | && !info->shared) | |
1905 | { | |
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; | |
1910 | } | |
1911 | ||
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) | |
1915 | { | |
1916 | struct elf_link_hash_entry *h; | |
1917 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
1918 | ||
1919 | if (info->init_function | |
1920 | && (h = elf_link_hash_lookup (elf_hash_table (info), | |
1921 | info->init_function, false, | |
1922 | false, false)) | |
1923 | && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
1924 | | ELF_LINK_HASH_DEF_REGULAR)) != 0) | |
1925 | { | |
1926 | dyn_i = get_dyn_sym_info (ia64_info, h, output_bfd, NULL, true); | |
1927 | dyn_i->want_pltoff = 1; | |
1928 | } | |
1929 | ||
1930 | if (info->fini_function | |
1931 | && (h = elf_link_hash_lookup (elf_hash_table (info), | |
1932 | info->fini_function, false, | |
1933 | false, false)) | |
1934 | && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
1935 | | ELF_LINK_HASH_DEF_REGULAR)) != 0) | |
1936 | { | |
1937 | dyn_i = get_dyn_sym_info (ia64_info, h, output_bfd, NULL, true); | |
1938 | dyn_i->want_pltoff = 1; | |
1939 | } | |
1940 | } | |
1941 | ||
1942 | /* Allocate the GOT entries. */ | |
1943 | ||
1944 | if (ia64_info->got_sec) | |
1945 | { | |
1946 | data.ofs = 0; | |
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; | |
1951 | } | |
1952 | ||
1953 | /* Allocate the FPTR entries. */ | |
1954 | ||
1955 | if (ia64_info->fptr_sec) | |
1956 | { | |
1957 | data.ofs = 0; | |
1958 | elf64_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data); | |
1959 | ia64_info->fptr_sec->_raw_size = data.ofs; | |
1960 | } | |
1961 | ||
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. */ | |
1966 | ||
1967 | data.ofs = 0; | |
1968 | elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data); | |
1969 | ||
1970 | ia64_info->minplt_entries = 0; | |
1971 | if (data.ofs) | |
1972 | { | |
1973 | ia64_info->minplt_entries | |
1974 | = (data.ofs - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE; | |
1975 | } | |
1976 | ||
1977 | /* Align the pointer for the plt2 entries. */ | |
1978 | data.ofs = (data.ofs + 31) & -32; | |
1979 | ||
1980 | elf64_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data); | |
1981 | if (data.ofs != 0) | |
1982 | { | |
1983 | BFD_ASSERT (ia64_info->root.dynamic_sections_created); | |
1984 | ||
1985 | ia64_info->plt_sec->_raw_size = data.ofs; | |
1986 | ||
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; | |
1991 | } | |
1992 | ||
1993 | /* Allocate the PLTOFF entries. */ | |
1994 | ||
1995 | if (ia64_info->pltoff_sec) | |
1996 | { | |
1997 | data.ofs = 0; | |
1998 | elf64_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data); | |
1999 | ia64_info->pltoff_sec->_raw_size = data.ofs; | |
2000 | } | |
2001 | ||
2002 | if (ia64_info->root.dynamic_sections_created) | |
2003 | { | |
2004 | /* Allocate space for the dynamic relocations that turned out to be | |
2005 | required. */ | |
2006 | ||
2007 | elf64_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data); | |
2008 | } | |
2009 | ||
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) | |
2013 | { | |
2014 | boolean strip; | |
2015 | ||
2016 | if (!(sec->flags & SEC_LINKER_CREATED)) | |
2017 | continue; | |
2018 | ||
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 | |
2025 | these sections. */ | |
2026 | ||
2027 | strip = (sec->_raw_size == 0); | |
2028 | ||
2029 | if (sec == ia64_info->got_sec) | |
2030 | strip = false; | |
2031 | else if (sec == ia64_info->rel_got_sec) | |
2032 | { | |
2033 | if (strip) | |
2034 | ia64_info->rel_got_sec = NULL; | |
2035 | else | |
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; | |
2039 | } | |
2040 | else if (sec == ia64_info->fptr_sec) | |
2041 | { | |
2042 | if (strip) | |
2043 | ia64_info->fptr_sec = NULL; | |
2044 | } | |
2045 | else if (sec == ia64_info->plt_sec) | |
2046 | { | |
2047 | if (strip) | |
2048 | ia64_info->plt_sec = NULL; | |
2049 | } | |
2050 | else if (sec == ia64_info->pltoff_sec) | |
2051 | { | |
2052 | if (strip) | |
2053 | ia64_info->pltoff_sec = NULL; | |
2054 | } | |
2055 | else if (sec == ia64_info->rel_pltoff_sec) | |
2056 | { | |
2057 | if (strip) | |
2058 | ia64_info->rel_pltoff_sec = NULL; | |
2059 | else | |
2060 | { | |
2061 | relplt = true; | |
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; | |
2065 | } | |
2066 | } | |
2067 | else | |
2068 | { | |
2069 | const char *name; | |
2070 | ||
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); | |
2074 | ||
2075 | if (strcmp (name, ".got.plt") == 0) | |
2076 | strip = false; | |
2077 | else if (strncmp (name, ".rel", 4) == 0) | |
2078 | { | |
2079 | if (!strip) | |
2080 | { | |
2081 | const char *outname; | |
2082 | asection *target; | |
2083 | ||
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') | |
2089 | outname += 5; | |
2090 | else | |
2091 | outname += 4; | |
2092 | ||
2093 | target = bfd_get_section_by_name (output_bfd, outname); | |
2094 | if (target != NULL | |
2095 | && (target->flags & SEC_READONLY) != 0 | |
2096 | && (target->flags & SEC_ALLOC) != 0) | |
2097 | reltext = true; | |
2098 | ||
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; | |
2102 | } | |
2103 | } | |
2104 | else | |
2105 | continue; | |
2106 | } | |
2107 | ||
2108 | if (strip) | |
2109 | _bfd_strip_section_from_output (info, sec); | |
2110 | else | |
2111 | { | |
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) | |
2115 | return false; | |
2116 | } | |
2117 | } | |
2118 | ||
2119 | if (elf_hash_table (info)->dynamic_sections_created) | |
2120 | { | |
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. */ | |
2124 | ||
2125 | if (!info->shared) | |
2126 | { | |
2127 | /* The DT_DEBUG entry is filled in by the dynamic linker and used | |
2128 | by the debugger. */ | |
2129 | if (!bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0)) | |
2130 | return false; | |
2131 | } | |
2132 | ||
2133 | if (! bfd_elf64_add_dynamic_entry (info, DT_IA_64_PLT_RESERVE, 0)) | |
2134 | return false; | |
2135 | if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)) | |
2136 | return false; | |
2137 | ||
2138 | if (relplt) | |
2139 | { | |
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)) | |
2143 | return false; | |
2144 | } | |
2145 | ||
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))) | |
2150 | return false; | |
2151 | ||
2152 | if (reltext) | |
2153 | { | |
2154 | if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0)) | |
2155 | return false; | |
2156 | } | |
2157 | } | |
2158 | ||
2159 | /* ??? Perhaps force __gp local. */ | |
2160 | ||
2161 | return true; | |
2162 | } | |
2163 | ||
2164 | static bfd_reloc_status_type | |
2165 | elf64_ia64_install_value (abfd, hit_addr, val, r_type) | |
2166 | bfd *abfd; | |
2167 | bfd_byte *hit_addr; | |
2168 | bfd_vma val; | |
2169 | unsigned int r_type; | |
2170 | { | |
2171 | const struct ia64_operand *op; | |
2172 | int bigendian = 0, shift = 0; | |
2173 | bfd_vma t0, t1, insn, dword; | |
2174 | enum ia64_opnd opnd; | |
2175 | const char *err; | |
2176 | size_t size = 8; | |
2177 | ||
2178 | opnd = IA64_OPND_NIL; | |
2179 | switch (r_type) | |
2180 | { | |
2181 | case R_IA64_NONE: | |
2182 | case R_IA64_LDXMOV: | |
2183 | return bfd_reloc_ok; | |
2184 | ||
2185 | /* Instruction relocations. */ | |
2186 | ||
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; | |
2191 | ||
2192 | case R_IA64_IMM22: | |
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; | |
2199 | break; | |
2200 | ||
2201 | case R_IA64_IMM64: | |
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; | |
2208 | break; | |
2209 | ||
2210 | /* Data relocations. */ | |
2211 | ||
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; | |
2220 | break; | |
2221 | ||
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; | |
2230 | break; | |
2231 | ||
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; | |
2242 | break; | |
2243 | ||
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; | |
2254 | break; | |
2255 | ||
2256 | /* Unsupported / Dynamic relocations. */ | |
2257 | ||
2258 | case R_IA64_REL32MSB: | |
2259 | case R_IA64_REL32LSB: | |
2260 | case R_IA64_REL64MSB: | |
2261 | case R_IA64_REL64LSB: | |
2262 | ||
2263 | case R_IA64_IPLTMSB: | |
2264 | case R_IA64_IPLTLSB: | |
2265 | case R_IA64_EPLTMSB: | |
2266 | case R_IA64_EPLTLSB: | |
2267 | case R_IA64_COPY: | |
2268 | ||
2269 | case R_IA64_SEGBASE: | |
2270 | ||
2271 | case R_IA64_TPREL22: | |
2272 | case R_IA64_TPREL64MSB: | |
2273 | case R_IA64_TPREL64LSB: | |
2274 | case R_IA64_LTOFF_TP22: | |
2275 | ||
2276 | default: | |
2277 | return bfd_reloc_notsupported; | |
2278 | } | |
2279 | ||
2280 | switch (opnd) | |
2281 | { | |
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); | |
2286 | ||
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 */ | |
2291 | ||
2292 | /* First, clear the bits that form the 64 bit constant. */ | |
2293 | t0 &= ~(0x3ffffLL << 46); | |
2294 | t1 &= ~(0x7fffffLL | |
2295 | | (( (0x07fLL << 13) | (0x1ffLL << 27) | |
2296 | | (0x01fLL << 22) | (0x001LL << 21) | |
2297 | | (0x001LL << 36)) << 23)); | |
2298 | ||
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 */ | |
2306 | ||
2307 | bfd_put_64 (abfd, t0, hit_addr); | |
2308 | bfd_put_64 (abfd, t1, hit_addr + 8); | |
2309 | break; | |
2310 | ||
2311 | default: | |
2312 | switch ((long) hit_addr & 0x3) | |
2313 | { | |
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... */ | |
2318 | } | |
2319 | dword = bfd_get_64 (abfd, hit_addr); | |
2320 | insn = (dword >> shift) & 0x1ffffffffffLL; | |
2321 | ||
2322 | op = elf64_ia64_operands + opnd; | |
2323 | err = (*op->insert) (op, val, &insn); | |
2324 | if (err) | |
2325 | return bfd_reloc_overflow; | |
2326 | ||
2327 | dword &= ~(0x1ffffffffffLL << shift); | |
2328 | dword |= (insn << shift); | |
2329 | bfd_put_64 (abfd, dword, hit_addr); | |
2330 | break; | |
2331 | ||
2332 | case IA64_OPND_NIL: | |
2333 | /* A data relocation. */ | |
2334 | if (bigendian) | |
2335 | if (size == 4) | |
2336 | bfd_putb32 (val, hit_addr); | |
2337 | else | |
2338 | bfd_putb64 (val, hit_addr); | |
2339 | else | |
2340 | if (size == 4) | |
2341 | bfd_putl32 (val, hit_addr); | |
2342 | else | |
2343 | bfd_putl64 (val, hit_addr); | |
2344 | break; | |
2345 | } | |
2346 | ||
2347 | return bfd_reloc_ok; | |
2348 | } | |
2349 | ||
2350 | static void | |
2351 | elf64_ia64_install_dyn_reloc (abfd, info, sec, srel, offset, type, | |
2352 | dynindx, addend) | |
2353 | bfd *abfd; | |
2354 | struct bfd_link_info *info; | |
2355 | asection *sec; | |
2356 | asection *srel; | |
2357 | bfd_vma offset; | |
2358 | unsigned int type; | |
2359 | long dynindx; | |
2360 | bfd_vma addend; | |
2361 | { | |
2362 | Elf_Internal_Rela outrel; | |
2363 | ||
2364 | outrel.r_offset = (sec->output_section->vma | |
2365 | + sec->output_offset | |
2366 | + offset); | |
2367 | ||
2368 | BFD_ASSERT (dynindx != -1); | |
2369 | outrel.r_info = ELF64_R_INFO (dynindx, type); | |
2370 | outrel.r_addend = addend; | |
2371 | ||
2372 | if (elf_section_data (sec)->stab_info != NULL) | |
2373 | { | |
2374 | /* This may be NULL for linker-generated relocations, as it is | |
2375 | inconvenient to pass all the bits around. And this shouldn't | |
2376 | happen. */ | |
2377 | BFD_ASSERT (info != NULL); | |
2378 | ||
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) | |
2383 | { | |
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; | |
2388 | offset = 0; | |
2389 | } | |
2390 | outrel.r_offset = offset; | |
2391 | } | |
2392 | ||
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); | |
2398 | } | |
2399 | ||
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. */ | |
2402 | ||
2403 | static bfd_vma | |
2404 | set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type) | |
2405 | bfd *abfd; | |
2406 | struct bfd_link_info *info; | |
2407 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
2408 | long dynindx; | |
2409 | bfd_vma addend; | |
2410 | bfd_vma value; | |
2411 | unsigned int dyn_r_type; | |
2412 | { | |
2413 | struct elf64_ia64_link_hash_table *ia64_info; | |
2414 | asection *got_sec; | |
2415 | ||
2416 | ia64_info = elf64_ia64_hash_table (info); | |
2417 | got_sec = ia64_info->got_sec; | |
2418 | ||
2419 | BFD_ASSERT ((dyn_i->got_offset & 7) == 0); | |
2420 | ||
2421 | if (! dyn_i->got_done) | |
2422 | { | |
2423 | dyn_i->got_done = true; | |
2424 | ||
2425 | /* Store the target address in the linkage table entry. */ | |
2426 | bfd_put_64 (abfd, value, got_sec->contents + dyn_i->got_offset); | |
2427 | ||
2428 | /* Install a dynamic relocation if needed. */ | |
2429 | if (info->shared | |
2430 | || elf64_ia64_dynamic_symbol_p (dyn_i->h, info) | |
2431 | || (dynindx != -1 && dyn_r_type == R_IA64_FPTR64LSB)) | |
2432 | { | |
2433 | if (dynindx == -1) | |
2434 | { | |
2435 | dyn_r_type = R_IA64_REL64LSB; | |
2436 | dynindx = 0; | |
2437 | addend = value; | |
2438 | } | |
2439 | ||
2440 | if (bfd_big_endian (abfd)) | |
2441 | { | |
2442 | switch (dyn_r_type) | |
2443 | { | |
2444 | case R_IA64_REL64LSB: | |
2445 | dyn_r_type = R_IA64_REL64MSB; | |
2446 | break; | |
2447 | case R_IA64_DIR64LSB: | |
2448 | dyn_r_type = R_IA64_DIR64MSB; | |
2449 | break; | |
2450 | case R_IA64_FPTR64LSB: | |
2451 | dyn_r_type = R_IA64_FPTR64MSB; | |
2452 | break; | |
2453 | default: | |
2454 | BFD_ASSERT (false); | |
2455 | break; | |
2456 | } | |
2457 | } | |
2458 | ||
2459 | elf64_ia64_install_dyn_reloc (abfd, NULL, got_sec, | |
2460 | ia64_info->rel_got_sec, | |
2461 | dyn_i->got_offset, dyn_r_type, | |
2462 | dynindx, addend); | |
2463 | } | |
2464 | } | |
2465 | ||
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); | |
2470 | ||
2471 | return value; | |
2472 | } | |
2473 | ||
2474 | /* Fill in a function descriptor consisting of the function's code | |
2475 | address and its global pointer. Return the descriptor's address. */ | |
2476 | ||
2477 | static bfd_vma | |
2478 | set_fptr_entry (abfd, info, dyn_i, value) | |
2479 | bfd *abfd; | |
2480 | struct bfd_link_info *info; | |
2481 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
2482 | bfd_vma value; | |
2483 | { | |
2484 | struct elf64_ia64_link_hash_table *ia64_info; | |
2485 | asection *fptr_sec; | |
2486 | ||
2487 | ia64_info = elf64_ia64_hash_table (info); | |
2488 | fptr_sec = ia64_info->fptr_sec; | |
2489 | ||
2490 | if (!dyn_i->fptr_done) | |
2491 | { | |
2492 | dyn_i->fptr_done = 1; | |
2493 | ||
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); | |
2498 | } | |
2499 | ||
2500 | /* Return the descriptor's address. */ | |
2501 | value = (fptr_sec->output_section->vma | |
2502 | + fptr_sec->output_offset | |
2503 | + dyn_i->fptr_offset); | |
2504 | ||
2505 | return value; | |
2506 | } | |
2507 | ||
2508 | /* Fill in a PLTOFF entry consisting of the function's code address | |
2509 | and its global pointer. Return the descriptor's address. */ | |
2510 | ||
2511 | static bfd_vma | |
2512 | set_pltoff_entry (abfd, info, dyn_i, value, is_plt) | |
2513 | bfd *abfd; | |
2514 | struct bfd_link_info *info; | |
2515 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
2516 | bfd_vma value; | |
2517 | boolean is_plt; | |
2518 | { | |
2519 | struct elf64_ia64_link_hash_table *ia64_info; | |
2520 | asection *pltoff_sec; | |
2521 | ||
2522 | ia64_info = elf64_ia64_hash_table (info); | |
2523 | pltoff_sec = ia64_info->pltoff_sec; | |
2524 | ||
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) | |
2529 | { | |
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); | |
2534 | ||
2535 | /* Install dynamic relocations if needed. */ | |
2536 | if (!is_plt && info->shared) | |
2537 | { | |
2538 | unsigned int dyn_r_type; | |
2539 | ||
2540 | if (bfd_big_endian (abfd)) | |
2541 | dyn_r_type = R_IA64_REL64MSB; | |
2542 | else | |
2543 | dyn_r_type = R_IA64_REL64LSB; | |
2544 | ||
2545 | elf64_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec, | |
2546 | ia64_info->rel_pltoff_sec, | |
2547 | dyn_i->pltoff_offset, | |
2548 | dyn_r_type, 0, 0); | |
2549 | elf64_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec, | |
2550 | ia64_info->rel_pltoff_sec, | |
2551 | dyn_i->pltoff_offset + 8, | |
2552 | dyn_r_type, 0, 0); | |
2553 | } | |
2554 | ||
2555 | dyn_i->pltoff_done = 1; | |
2556 | } | |
2557 | ||
2558 | /* Return the descriptor's address. */ | |
2559 | value = (pltoff_sec->output_section->vma | |
2560 | + pltoff_sec->output_offset | |
2561 | + dyn_i->pltoff_offset); | |
2562 | ||
2563 | return value; | |
2564 | } | |
2565 | ||
2566 | static boolean | |
2567 | elf64_ia64_final_link (abfd, info) | |
2568 | bfd *abfd; | |
2569 | struct bfd_link_info *info; | |
2570 | { | |
2571 | struct elf64_ia64_link_hash_table *ia64_info; | |
2572 | ia64_info = elf64_ia64_hash_table (info); | |
2573 | ||
2574 | /* Make sure we've got ourselves a nice fat __gp value. */ | |
2575 | if (!info->relocateable) | |
2576 | { | |
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; | |
2580 | bfd_vma gp_val; | |
2581 | asection *os; | |
2582 | ||
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 | |
2585 | nice gp. */ | |
2586 | for (os = abfd->sections; os ; os = os->next) | |
2587 | { | |
2588 | bfd_vma lo, hi; | |
2589 | ||
2590 | if ((os->flags & SEC_ALLOC) == 0) | |
2591 | continue; | |
2592 | ||
2593 | lo = os->vma; | |
2594 | hi = os->vma + os->_raw_size; | |
2595 | if (hi < lo) | |
2596 | hi = (bfd_vma) -1; | |
2597 | ||
2598 | if (min_vma > lo) | |
2599 | min_vma = lo; | |
2600 | if (max_vma < hi) | |
2601 | max_vma = hi; | |
2602 | if (os->flags & SEC_SMALL_DATA) | |
2603 | { | |
2604 | if (min_short_vma > lo) | |
2605 | min_short_vma = lo; | |
2606 | if (max_short_vma < hi) | |
2607 | max_short_vma = hi; | |
2608 | } | |
2609 | } | |
2610 | ||
2611 | /* See if the user wants to force a value. */ | |
2612 | gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false, | |
2613 | false, false); | |
2614 | ||
2615 | if (gp | |
2616 | && (gp->root.type == bfd_link_hash_defined | |
2617 | || gp->root.type == bfd_link_hash_defweak)) | |
2618 | { | |
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); | |
2623 | } | |
2624 | else | |
2625 | { | |
2626 | /* Pick a sensible value. */ | |
2627 | ||
2628 | asection *got_sec = ia64_info->got_sec; | |
2629 | ||
2630 | /* Start with just the address of the .got. */ | |
2631 | if (got_sec) | |
2632 | gp_val = got_sec->output_section->vma; | |
2633 | else if (max_short_vma != 0) | |
2634 | gp_val = min_short_vma; | |
2635 | else | |
2636 | gp_val = min_vma; | |
2637 | ||
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) | |
2645 | { | |
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; | |
2649 | ||
2650 | /* If we're addressing stuff past the end, adjust back. */ | |
2651 | if (gp_val > max_vma) | |
2652 | gp_val = max_vma - 0x200000 + 8; | |
2653 | } | |
2654 | } | |
2655 | ||
2656 | /* Validate whether all SHF_IA_64_SHORT sections are within | |
2657 | range of the chosen GP. */ | |
2658 | ||
2659 | if (max_short_vma != 0) | |
2660 | { | |
2661 | if (max_short_vma - min_short_vma >= 0x400000) | |
2662 | { | |
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)); | |
2667 | return false; | |
2668 | } | |
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)) | |
2673 | { | |
2674 | (*_bfd_error_handler) | |
2675 | (_("%s: __gp does not cover short data segment"), | |
2676 | bfd_get_filename (abfd)); | |
2677 | return false; | |
2678 | } | |
2679 | } | |
2680 | ||
2681 | _bfd_set_gp_value (abfd, gp_val); | |
2682 | } | |
2683 | ||
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) | |
2692 | { | |
2693 | struct elf_link_hash_entry *h; | |
2694 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
2695 | bfd_vma addr; | |
2696 | ||
2697 | if (info->init_function | |
2698 | && (h = elf_link_hash_lookup (elf_hash_table (info), | |
2699 | info->init_function, false, | |
2700 | false, false)) | |
2701 | && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
2702 | | ELF_LINK_HASH_DEF_REGULAR)) != 0) | |
2703 | { | |
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); | |
2709 | } | |
2710 | ||
2711 | if (info->fini_function | |
2712 | && (h = elf_link_hash_lookup (elf_hash_table (info), | |
2713 | info->fini_function, false, | |
2714 | false, false)) | |
2715 | && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR | |
2716 | | ELF_LINK_HASH_DEF_REGULAR)) != 0) | |
2717 | { | |
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); | |
2723 | } | |
2724 | } | |
2725 | ||
2726 | /* Invoke the regular ELF backend linker to do all the work. */ | |
2727 | return bfd_elf64_bfd_final_link (abfd, info); | |
2728 | } | |
2729 | ||
2730 | static boolean | |
2731 | elf64_ia64_relocate_section (output_bfd, info, input_bfd, input_section, | |
2732 | contents, relocs, local_syms, local_sections) | |
2733 | bfd *output_bfd; | |
2734 | struct bfd_link_info *info; | |
2735 | bfd *input_bfd; | |
2736 | asection *input_section; | |
2737 | bfd_byte *contents; | |
2738 | Elf_Internal_Rela *relocs; | |
2739 | Elf_Internal_Sym *local_syms; | |
2740 | asection **local_sections; | |
2741 | { | |
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; | |
2746 | asection *srel; | |
2747 | boolean ret_val = true; /* for non-fatal errors */ | |
2748 | bfd_vma gp_val; | |
2749 | ||
2750 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
2751 | ia64_info = elf64_ia64_hash_table (info); | |
2752 | ||
2753 | /* Infect various flags from the input section to the output section. */ | |
2754 | if (info->relocateable) | |
2755 | { | |
2756 | bfd_vma flags; | |
2757 | ||
2758 | flags = elf_section_data(input_section)->this_hdr.sh_flags; | |
2759 | flags &= SHF_IA_64_NORECOV; | |
2760 | ||
2761 | elf_section_data(input_section->output_section) | |
2762 | ->this_hdr.sh_flags |= flags; | |
2763 | } | |
2764 | ||
2765 | gp_val = _bfd_get_gp_value (output_bfd); | |
2766 | srel = get_reloc_section (input_bfd, ia64_info, input_section, false); | |
2767 | ||
2768 | rel = relocs; | |
2769 | relend = relocs + input_section->reloc_count; | |
2770 | for (; rel < relend; ++rel) | |
2771 | { | |
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; | |
2779 | bfd_vma value; | |
2780 | asection *sym_sec; | |
2781 | bfd_byte *hit_addr; | |
2782 | boolean dynamic_symbol_p; | |
2783 | boolean undef_weak_ref; | |
2784 | ||
2785 | r_type = ELF64_R_TYPE (rel->r_info); | |
2786 | if (r_type > R_IA64_MAX_RELOC_CODE) | |
2787 | { | |
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); | |
2792 | ret_val = false; | |
2793 | continue; | |
2794 | } | |
2795 | howto = lookup_howto (r_type); | |
2796 | r_symndx = ELF64_R_SYM (rel->r_info); | |
2797 | ||
2798 | if (info->relocateable) | |
2799 | { | |
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) | |
2805 | { | |
2806 | sym = local_syms + r_symndx; | |
2807 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
2808 | { | |
2809 | sym_sec = local_sections[r_symndx]; | |
2810 | rel->r_addend += sym_sec->output_offset; | |
2811 | } | |
2812 | } | |
2813 | continue; | |
2814 | } | |
2815 | ||
2816 | /* This is a final link. */ | |
2817 | ||
2818 | h = NULL; | |
2819 | sym = NULL; | |
2820 | sym_sec = NULL; | |
2821 | undef_weak_ref = false; | |
2822 | ||
2823 | if (r_symndx < symtab_hdr->sh_info) | |
2824 | { | |
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 | |
2830 | + sym->st_value); | |
2831 | } | |
2832 | else | |
2833 | { | |
2834 | long indx; | |
2835 | ||
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; | |
2842 | ||
2843 | value = 0; | |
2844 | if (h->root.type == bfd_link_hash_defined | |
2845 | || h->root.type == bfd_link_hash_defweak) | |
2846 | { | |
2847 | sym_sec = h->root.u.def.section; | |
2848 | ||
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. */ | |
2856 | ||
2857 | if (sym_sec->output_section != NULL) | |
2858 | { | |
2859 | value = (h->root.u.def.value | |
2860 | + sym_sec->output_section->vma | |
2861 | + sym_sec->output_offset); | |
2862 | } | |
2863 | } | |
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) | |
2867 | ; | |
2868 | else | |
2869 | { | |
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)))) | |
2874 | return false; | |
2875 | ret_val = false; | |
2876 | continue; | |
2877 | } | |
2878 | } | |
2879 | ||
2880 | hit_addr = contents + rel->r_offset; | |
2881 | value += rel->r_addend; | |
2882 | dynamic_symbol_p = elf64_ia64_dynamic_symbol_p (h, info); | |
2883 | ||
2884 | switch (r_type) | |
2885 | { | |
2886 | case R_IA64_NONE: | |
2887 | case R_IA64_LDXMOV: | |
2888 | continue; | |
2889 | ||
2890 | case R_IA64_IMM14: | |
2891 | case R_IA64_IMM22: | |
2892 | case R_IA64_IMM64: | |
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) | |
2900 | { | |
2901 | unsigned int dyn_r_type; | |
2902 | long dynindx; | |
2903 | ||
2904 | BFD_ASSERT (srel != NULL); | |
2905 | ||
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; | |
2911 | else | |
2912 | { | |
2913 | switch (r_type) | |
2914 | { | |
2915 | case R_IA64_DIR32MSB: | |
2916 | dyn_r_type = R_IA64_REL32MSB; | |
2917 | break; | |
2918 | case R_IA64_DIR32LSB: | |
2919 | dyn_r_type = R_IA64_REL32LSB; | |
2920 | break; | |
2921 | case R_IA64_DIR64MSB: | |
2922 | dyn_r_type = R_IA64_REL64MSB; | |
2923 | break; | |
2924 | case R_IA64_DIR64LSB: | |
2925 | dyn_r_type = R_IA64_REL64LSB; | |
2926 | break; | |
2927 | ||
2928 | default: | |
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)); | |
2938 | ret_val = false; | |
2939 | continue; | |
2940 | } | |
2941 | dynindx = 0; | |
2942 | } | |
2943 | ||
2944 | elf64_ia64_install_dyn_reloc (output_bfd, info, input_section, | |
2945 | srel, rel->r_offset, dyn_r_type, | |
2946 | dynindx, rel->r_addend); | |
2947 | } | |
2948 | /* FALLTHRU */ | |
2949 | ||
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); | |
2955 | break; | |
2956 | ||
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) | |
2964 | { | |
2965 | (*_bfd_error_handler) | |
2966 | (_("%s: @gprel relocation against dynamic symbol %s"), | |
2967 | bfd_get_filename (input_bfd), h->root.root.string); | |
2968 | ret_val = false; | |
2969 | continue; | |
2970 | } | |
2971 | value -= gp_val; | |
2972 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, r_type); | |
2973 | break; | |
2974 | ||
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); | |
2981 | value -= gp_val; | |
2982 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, r_type); | |
2983 | break; | |
2984 | ||
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); | |
2991 | value -= gp_val; | |
2992 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, r_type); | |
2993 | break; | |
2994 | ||
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) | |
3002 | { | |
3003 | if (!undef_weak_ref) | |
3004 | value = set_fptr_entry (output_bfd, info, dyn_i, value); | |
3005 | } | |
3006 | else | |
3007 | { | |
3008 | long dynindx; | |
3009 | ||
3010 | /* Otherwise, we expect the dynamic linker to create | |
3011 | the entry. */ | |
3012 | ||
3013 | if (h) | |
3014 | { | |
3015 | if (h->dynindx != -1) | |
3016 | dynindx = h->dynindx; | |
3017 | else | |
3018 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
3019 | (info, h->root.u.def.section->owner, | |
3020 | global_sym_index (h))); | |
3021 | } | |
3022 | else | |
3023 | { | |
3024 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
3025 | (info, input_bfd, r_symndx)); | |
3026 | } | |
3027 | ||
3028 | elf64_ia64_install_dyn_reloc (output_bfd, info, input_section, | |
3029 | srel, rel->r_offset, r_type, | |
3030 | dynindx, rel->r_addend); | |
3031 | value = 0; | |
3032 | } | |
3033 | ||
3034 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, r_type); | |
3035 | break; | |
3036 | ||
3037 | case R_IA64_LTOFF_FPTR22: | |
3038 | case R_IA64_LTOFF_FPTR64I: | |
3039 | case R_IA64_LTOFF_FPTR64MSB: | |
3040 | case R_IA64_LTOFF_FPTR64LSB: | |
3041 | { | |
3042 | long dynindx; | |
3043 | ||
3044 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, false); | |
3045 | if (dyn_i->want_fptr) | |
3046 | { | |
3047 | BFD_ASSERT (h == NULL || h->dynindx == -1) | |
3048 | if (!undef_weak_ref) | |
3049 | value = set_fptr_entry (output_bfd, info, dyn_i, value); | |
3050 | dynindx = -1; | |
3051 | } | |
3052 | else | |
3053 | { | |
3054 | /* Otherwise, we expect the dynamic linker to create | |
3055 | the entry. */ | |
3056 | if (h) | |
3057 | { | |
3058 | if (h->dynindx != -1) | |
3059 | dynindx = h->dynindx; | |
3060 | else | |
3061 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
3062 | (info, h->root.u.def.section->owner, | |
3063 | global_sym_index (h))); | |
3064 | } | |
3065 | else | |
3066 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
3067 | (info, input_bfd, r_symndx)); | |
3068 | value = 0; | |
3069 | } | |
3070 | ||
3071 | value = set_got_entry (output_bfd, info, dyn_i, dynindx, | |
3072 | rel->r_addend, value, R_IA64_FPTR64LSB); | |
3073 | value -= gp_val; | |
3074 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, r_type); | |
3075 | } | |
3076 | break; | |
3077 | ||
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) | |
3084 | { | |
3085 | BFD_ASSERT (srel != NULL); | |
3086 | ||
3087 | elf64_ia64_install_dyn_reloc (output_bfd, info, input_section, | |
3088 | srel, rel->r_offset, r_type, | |
3089 | h->dynindx, rel->r_addend); | |
3090 | } | |
3091 | goto finish_pcrel; | |
3092 | ||
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) | |
3098 | { | |
3099 | (*_bfd_error_handler) | |
3100 | (_("%s: dynamic relocation against speculation fixup"), | |
3101 | bfd_get_filename (input_bfd)); | |
3102 | ret_val = false; | |
3103 | continue; | |
3104 | } | |
3105 | if (undef_weak_ref) | |
3106 | { | |
3107 | (*_bfd_error_handler) | |
3108 | (_("%s: speculation fixup against undefined weak symbol"), | |
3109 | bfd_get_filename (input_bfd)); | |
3110 | ret_val = false; | |
3111 | continue; | |
3112 | } | |
3113 | goto finish_pcrel; | |
3114 | ||
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. */ | |
3119 | ||
3120 | dyn_i = NULL; | |
3121 | if (h) | |
3122 | dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); | |
3123 | ||
3124 | if (dyn_i && dyn_i->want_plt2) | |
3125 | { | |
3126 | /* Should have caught this earlier. */ | |
3127 | BFD_ASSERT (rel->r_addend == 0); | |
3128 | ||
3129 | value = (ia64_info->plt_sec->output_section->vma | |
3130 | + ia64_info->plt_sec->output_offset | |
3131 | + dyn_i->plt2_offset); | |
3132 | } | |
3133 | else | |
3134 | { | |
3135 | /* Since there's no PLT entry, Validate that this is | |
3136 | locally defined. */ | |
3137 | BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL); | |
3138 | ||
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. */ | |
3143 | if (undef_weak_ref) | |
3144 | continue; | |
3145 | } | |
3146 | goto finish_pcrel; | |
3147 | ||
3148 | finish_pcrel: | |
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); | |
3154 | break; | |
3155 | ||
3156 | case R_IA64_SEGREL32MSB: | |
3157 | case R_IA64_SEGREL32LSB: | |
3158 | case R_IA64_SEGREL64MSB: | |
3159 | case R_IA64_SEGREL64LSB: | |
3160 | { | |
3161 | struct elf_segment_map *m; | |
3162 | Elf_Internal_Phdr *p; | |
3163 | ||
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; | |
3167 | m != NULL; | |
3168 | m = m->next, p++) | |
3169 | { | |
3170 | int i; | |
3171 | for (i = m->count - 1; i >= 0; i--) | |
3172 | if (m->sections[i] == sym_sec->output_section) | |
3173 | break; | |
3174 | if (i >= 0) | |
3175 | break; | |
3176 | } | |
3177 | ||
3178 | if (m == NULL) | |
3179 | { | |
3180 | /* If the input section was discarded from the output, then | |
3181 | do nothing. */ | |
3182 | ||
3183 | if (bfd_is_abs_section (sym_sec->output_section)) | |
3184 | r = bfd_reloc_ok; | |
3185 | else | |
3186 | r = bfd_reloc_notsupported; | |
3187 | } | |
3188 | else | |
3189 | { | |
3190 | /* The VMA of the segment is the vaddr of the associated | |
3191 | program header. */ | |
3192 | if (value > p->p_vaddr) | |
3193 | value -= p->p_vaddr; | |
3194 | else | |
3195 | value = 0; | |
3196 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, | |
3197 | r_type); | |
3198 | } | |
3199 | break; | |
3200 | } | |
3201 | ||
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; | |
3209 | else | |
3210 | value = 0; | |
3211 | r = elf64_ia64_install_value (output_bfd, hit_addr, value, r_type); | |
3212 | break; | |
3213 | ||
3214 | case R_IA64_SEGBASE: | |
3215 | ||
3216 | case R_IA64_REL32MSB: | |
3217 | case R_IA64_REL32LSB: | |
3218 | case R_IA64_REL64MSB: | |
3219 | case R_IA64_REL64LSB: | |
3220 | ||
3221 | case R_IA64_IPLTMSB: | |
3222 | case R_IA64_IPLTLSB: | |
3223 | case R_IA64_EPLTMSB: | |
3224 | case R_IA64_EPLTLSB: | |
3225 | case R_IA64_COPY: | |
3226 | ||
3227 | case R_IA64_TPREL22: | |
3228 | case R_IA64_TPREL64MSB: | |
3229 | case R_IA64_TPREL64LSB: | |
3230 | case R_IA64_LTOFF_TP22: | |
3231 | default: | |
3232 | r = bfd_reloc_notsupported; | |
3233 | break; | |
3234 | } | |
3235 | ||
3236 | switch (r) | |
3237 | { | |
3238 | case bfd_reloc_ok: | |
3239 | break; | |
3240 | ||
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); | |
3247 | return false; | |
3248 | ||
3249 | case bfd_reloc_notsupported: | |
3250 | { | |
3251 | const char *name; | |
3252 | ||
3253 | if (h) | |
3254 | name = h->root.root.string; | |
3255 | else | |
3256 | { | |
3257 | name = bfd_elf_string_from_elf_section (input_bfd, | |
3258 | symtab_hdr->sh_link, | |
3259 | sym->st_name); | |
3260 | if (name == NULL) | |
3261 | return false; | |
3262 | if (*name == '\0') | |
3263 | name = bfd_section_name (input_bfd, input_section); | |
3264 | } | |
3265 | if (!(*info->callbacks->warning) (info, _("unsupported reloc"), | |
3266 | name, input_bfd, | |
3267 | input_section, rel->r_offset)) | |
3268 | return false; | |
3269 | ret_val = false; | |
3270 | } | |
3271 | break; | |
3272 | ||
3273 | case bfd_reloc_dangerous: | |
3274 | case bfd_reloc_outofrange: | |
3275 | case bfd_reloc_overflow: | |
3276 | default: | |
3277 | { | |
3278 | const char *name; | |
3279 | ||
3280 | if (h) | |
3281 | name = h->root.root.string; | |
3282 | else | |
3283 | { | |
3284 | name = bfd_elf_string_from_elf_section (input_bfd, | |
3285 | symtab_hdr->sh_link, | |
3286 | sym->st_name); | |
3287 | if (name == NULL) | |
3288 | return false; | |
3289 | if (*name == '\0') | |
3290 | name = bfd_section_name (input_bfd, input_section); | |
3291 | } | |
3292 | if (!(*info->callbacks->reloc_overflow) (info, name, | |
3293 | howto->name, 0, | |
3294 | input_bfd, | |
3295 | input_section, | |
3296 | rel->r_offset)) | |
3297 | return false; | |
3298 | ret_val = false; | |
3299 | } | |
3300 | break; | |
3301 | } | |
3302 | } | |
3303 | ||
3304 | return ret_val; | |
3305 | } | |
3306 | ||
3307 | static boolean | |
3308 | elf64_ia64_finish_dynamic_symbol (output_bfd, info, h, sym) | |
3309 | bfd *output_bfd; | |
3310 | struct bfd_link_info *info; | |
3311 | struct elf_link_hash_entry *h; | |
3312 | Elf_Internal_Sym *sym; | |
3313 | { | |
3314 | struct elf64_ia64_link_hash_table *ia64_info; | |
3315 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
3316 | ||
3317 | ia64_info = elf64_ia64_hash_table (info); | |
3318 | dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false); | |
3319 | ||
3320 | /* Fill in the PLT data, if required. */ | |
3321 | if (dyn_i && dyn_i->want_plt) | |
3322 | { | |
3323 | Elf_Internal_Rela outrel; | |
3324 | bfd_byte *loc; | |
3325 | asection *plt_sec; | |
3326 | bfd_vma plt_addr, pltoff_addr, gp_val, index; | |
3327 | Elf64_External_Rela *rel; | |
3328 | ||
3329 | gp_val = _bfd_get_gp_value (output_bfd); | |
3330 | ||
3331 | /* Initialize the minimal PLT entry. */ | |
3332 | ||
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; | |
3336 | ||
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, | |
3340 | R_IA64_PCREL21B); | |
3341 | ||
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); | |
3346 | ||
3347 | /* Initialize the FULL PLT entry, if needed. */ | |
3348 | if (dyn_i->want_plt2) | |
3349 | { | |
3350 | loc = plt_sec->contents + dyn_i->plt2_offset; | |
3351 | ||
3352 | memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE); | |
3353 | elf64_ia64_install_value (output_bfd, loc, pltoff_addr - gp_val, | |
3354 | R_IA64_IMM22); | |
3355 | ||
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; | |
3362 | } | |
3363 | ||
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); | |
3368 | else | |
3369 | outrel.r_info = ELF64_R_INFO (h->dynindx, R_IA64_IPLTMSB); | |
3370 | outrel.r_addend = 0; | |
3371 | ||
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. | |
3378 | ||
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 | |
3382 | PLT relocations. */ | |
3383 | ||
3384 | rel = (Elf64_External_Rela *)ia64_info->rel_pltoff_sec->contents; | |
3385 | rel += ia64_info->rel_pltoff_sec->reloc_count; | |
3386 | ||
3387 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, rel + index); | |
3388 | } | |
3389 | ||
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; | |
3395 | ||
3396 | return true; | |
3397 | } | |
3398 | ||
3399 | static boolean | |
3400 | elf64_ia64_finish_dynamic_sections (abfd, info) | |
3401 | bfd *abfd; | |
3402 | struct bfd_link_info *info; | |
3403 | { | |
3404 | struct elf64_ia64_link_hash_table *ia64_info; | |
3405 | bfd *dynobj; | |
3406 | ||
3407 | ia64_info = elf64_ia64_hash_table (info); | |
3408 | dynobj = ia64_info->root.dynobj; | |
3409 | ||
3410 | if (elf_hash_table (info)->dynamic_sections_created) | |
3411 | { | |
3412 | Elf64_External_Dyn *dyncon, *dynconend; | |
3413 | asection *sdyn, *sgotplt; | |
3414 | bfd_vma gp_val; | |
3415 | ||
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); | |
3421 | ||
3422 | gp_val = _bfd_get_gp_value (abfd); | |
3423 | ||
3424 | for (; dyncon < dynconend; dyncon++) | |
3425 | { | |
3426 | Elf_Internal_Dyn dyn; | |
3427 | const char *name; | |
3428 | asection *s; | |
3429 | ||
3430 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
3431 | ||
3432 | switch (dyn.d_tag) | |
3433 | { | |
3434 | case DT_PLTGOT: | |
3435 | dyn.d_un.d_ptr = gp_val; | |
3436 | break; | |
3437 | ||
3438 | case DT_PLTRELSZ: | |
3439 | dyn.d_un.d_val = (ia64_info->minplt_entries | |
3440 | * sizeof (Elf64_External_Rela)); | |
3441 | break; | |
3442 | ||
3443 | case DT_JMPREL: | |
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))); | |
3449 | break; | |
3450 | ||
3451 | case DT_IA_64_PLT_RESERVE: | |
3452 | dyn.d_un.d_ptr = (sgotplt->output_section->vma | |
3453 | + sgotplt->output_offset); | |
3454 | break; | |
3455 | ||
3456 | case DT_RELASZ: | |
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)); | |
3461 | break; | |
3462 | ||
3463 | case DT_INIT: | |
3464 | case DT_FINI: | |
3465 | { | |
3466 | struct elf_link_hash_entry *h; | |
3467 | struct elf64_ia64_dyn_sym_info *dyn_i; | |
3468 | const char *which; | |
3469 | ||
3470 | if (dyn.d_tag == DT_INIT) | |
3471 | which = info->init_function; | |
3472 | else | |
3473 | which = info->fini_function; | |
3474 | ||
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, | |
3479 | dyn.d_un.d_ptr, 0); | |
3480 | } | |
3481 | } | |
3482 | ||
3483 | bfd_elf64_swap_dyn_out (abfd, &dyn, dyncon); | |
3484 | } | |
3485 | ||
3486 | /* Initialize the PLT0 entry */ | |
3487 | if (ia64_info->plt_sec) | |
3488 | { | |
3489 | bfd_byte *loc = ia64_info->plt_sec->contents; | |
3490 | bfd_vma pltres; | |
3491 | ||
3492 | memcpy (loc, plt_header, PLT_HEADER_SIZE); | |
3493 | ||
3494 | pltres = (sgotplt->output_section->vma | |
3495 | + sgotplt->output_offset | |
3496 | - gp_val); | |
3497 | ||
3498 | elf64_ia64_install_value (abfd, loc+1, pltres, R_IA64_GPREL22); | |
3499 | } | |
3500 | } | |
3501 | ||
3502 | return true; | |
3503 | } | |
3504 | \f | |
3505 | /* ELF file flag handling: */ | |
3506 | ||
3507 | /* Function to keep IA-64 specific file flags. */ | |
3508 | static boolean | |
3509 | elf64_ia64_set_private_flags (abfd, flags) | |
3510 | bfd *abfd; | |
3511 | flagword flags; | |
3512 | { | |
3513 | BFD_ASSERT (!elf_flags_init (abfd) | |
3514 | || elf_elfheader (abfd)->e_flags == flags); | |
3515 | ||
3516 | elf_elfheader (abfd)->e_flags = flags; | |
3517 | elf_flags_init (abfd) = true; | |
3518 | return true; | |
3519 | } | |
3520 | ||
3521 | /* Copy backend specific data from one object module to another */ | |
3522 | static boolean | |
3523 | elf64_ia64_copy_private_bfd_data (ibfd, obfd) | |
3524 | bfd *ibfd, *obfd; | |
3525 | { | |
3526 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
3527 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
3528 | return true; | |
3529 | ||
3530 | BFD_ASSERT (!elf_flags_init (obfd) | |
3531 | || (elf_elfheader (obfd)->e_flags | |
3532 | == elf_elfheader (ibfd)->e_flags)); | |
3533 | ||
3534 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; | |
3535 | elf_flags_init (obfd) = true; | |
3536 | return true; | |
3537 | } | |
3538 | ||
3539 | /* Merge backend specific data from an object file to the output | |
3540 | object file when linking. */ | |
3541 | static boolean | |
3542 | elf64_ia64_merge_private_bfd_data (ibfd, obfd) | |
3543 | bfd *ibfd, *obfd; | |
3544 | { | |
3545 | flagword out_flags; | |
3546 | flagword in_flags; | |
3547 | boolean ok = true; | |
3548 | ||
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) | |
3552 | return false; | |
3553 | ||
3554 | in_flags = elf_elfheader (ibfd)->e_flags; | |
3555 | out_flags = elf_elfheader (obfd)->e_flags; | |
3556 | ||
3557 | if (! elf_flags_init (obfd)) | |
3558 | { | |
3559 | elf_flags_init (obfd) = true; | |
3560 | elf_elfheader (obfd)->e_flags = in_flags; | |
3561 | ||
3562 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
3563 | && bfd_get_arch_info (obfd)->the_default) | |
3564 | { | |
3565 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), | |
3566 | bfd_get_mach (ibfd)); | |
3567 | } | |
3568 | ||
3569 | return true; | |
3570 | } | |
3571 | ||
3572 | /* Check flag compatibility. */ | |
3573 | if (in_flags == out_flags) | |
3574 | return true; | |
3575 | ||
3576 | if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL)) | |
3577 | { | |
3578 | (*_bfd_error_handler) | |
3579 | (_("%s: linking trap-on-NULL-dereference with non-trapping files"), | |
3580 | bfd_get_filename (ibfd)); | |
3581 | ||
3582 | bfd_set_error (bfd_error_bad_value); | |
3583 | ok = false; | |
3584 | } | |
3585 | if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE)) | |
3586 | { | |
3587 | (*_bfd_error_handler) | |
3588 | (_("%s: linking big-endian files with little-endian files"), | |
3589 | bfd_get_filename (ibfd)); | |
3590 | ||
3591 | bfd_set_error (bfd_error_bad_value); | |
3592 | ok = false; | |
3593 | } | |
3594 | if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64)) | |
3595 | { | |
3596 | (*_bfd_error_handler) | |
3597 | (_("%s: linking 64-bit files with 32-bit files"), | |
3598 | bfd_get_filename (ibfd)); | |
3599 | ||
3600 | bfd_set_error (bfd_error_bad_value); | |
3601 | ok = false; | |
3602 | } | |
3603 | ||
3604 | return ok; | |
3605 | } | |
3606 | ||
3607 | static boolean | |
3608 | elf64_ia64_print_private_bfd_data (abfd, ptr) | |
3609 | bfd *abfd; | |
3610 | PTR ptr; | |
3611 | { | |
3612 | FILE *file = (FILE *) ptr; | |
3613 | flagword flags = elf_elfheader (abfd)->e_flags; | |
3614 | ||
3615 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
3616 | ||
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); | |
3623 | return true; | |
3624 | } | |
3625 | \f | |
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 */ | |
3635 | ||
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 | |
3648 | ||
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 | |
3653 | ||
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 | |
3673 | ||
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 | |
3682 | ||
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 | |
3695 | ||
3696 | #include "elf64-target.h" |