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