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