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