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