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