Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Alpha specific support for 64-bit ELF |
73896efb | 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
7898deda | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Contributed by Richard Henderson <rth@tamu.edu>. |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | /* We need a published ABI spec for this. Until one comes out, don't | |
23 | assume this'll remain unchanged forever. */ | |
24 | ||
25 | #include "bfd.h" | |
26 | #include "sysdep.h" | |
27 | #include "libbfd.h" | |
28 | #include "elf-bfd.h" | |
29 | ||
30 | #include "elf/alpha.h" | |
31 | ||
32 | #define ALPHAECOFF | |
33 | ||
34 | #define NO_COFF_RELOCS | |
35 | #define NO_COFF_SYMBOLS | |
36 | #define NO_COFF_LINENOS | |
37 | ||
fe8bc63d | 38 | /* Get the ECOFF swapping routines. Needed for the debug information. */ |
252b5132 RH |
39 | #include "coff/internal.h" |
40 | #include "coff/sym.h" | |
41 | #include "coff/symconst.h" | |
42 | #include "coff/ecoff.h" | |
43 | #include "coff/alpha.h" | |
44 | #include "aout/ar.h" | |
45 | #include "libcoff.h" | |
46 | #include "libecoff.h" | |
47 | #define ECOFF_64 | |
48 | #include "ecoffswap.h" | |
49 | ||
8fb35fed RH |
50 | static int alpha_elf_dynamic_symbol_p |
51 | PARAMS((struct elf_link_hash_entry *, struct bfd_link_info *)); | |
252b5132 RH |
52 | static struct bfd_hash_entry * elf64_alpha_link_hash_newfunc |
53 | PARAMS((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
54 | static struct bfd_link_hash_table * elf64_alpha_bfd_link_hash_table_create | |
55 | PARAMS((bfd *)); | |
56 | ||
57 | static bfd_reloc_status_type elf64_alpha_reloc_nil | |
58 | PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
59 | static bfd_reloc_status_type elf64_alpha_reloc_bad | |
60 | PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
61 | static bfd_reloc_status_type elf64_alpha_do_reloc_gpdisp | |
62 | PARAMS((bfd *, bfd_vma, bfd_byte *, bfd_byte *)); | |
63 | static bfd_reloc_status_type elf64_alpha_reloc_gpdisp | |
64 | PARAMS((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
65 | ||
66 | static reloc_howto_type * elf64_alpha_bfd_reloc_type_lookup | |
67 | PARAMS((bfd *, bfd_reloc_code_real_type)); | |
68 | static void elf64_alpha_info_to_howto | |
69 | PARAMS((bfd *, arelent *, Elf64_Internal_Rela *)); | |
70 | ||
8fb35fed RH |
71 | static boolean elf64_alpha_mkobject |
72 | PARAMS((bfd *)); | |
252b5132 RH |
73 | static boolean elf64_alpha_object_p |
74 | PARAMS((bfd *)); | |
75 | static boolean elf64_alpha_section_from_shdr | |
90937f86 | 76 | PARAMS((bfd *, Elf64_Internal_Shdr *, const char *)); |
204692d7 RH |
77 | static boolean elf64_alpha_section_flags |
78 | PARAMS((flagword *, Elf64_Internal_Shdr *)); | |
252b5132 RH |
79 | static boolean elf64_alpha_fake_sections |
80 | PARAMS((bfd *, Elf64_Internal_Shdr *, asection *)); | |
81 | static boolean elf64_alpha_create_got_section | |
82 | PARAMS((bfd *, struct bfd_link_info *)); | |
83 | static boolean elf64_alpha_create_dynamic_sections | |
84 | PARAMS((bfd *, struct bfd_link_info *)); | |
85 | ||
86 | static boolean elf64_alpha_read_ecoff_info | |
87 | PARAMS((bfd *, asection *, struct ecoff_debug_info *)); | |
88 | static boolean elf64_alpha_is_local_label_name | |
89 | PARAMS((bfd *, const char *)); | |
90 | static boolean elf64_alpha_find_nearest_line | |
91 | PARAMS((bfd *, asection *, asymbol **, bfd_vma, const char **, | |
92 | const char **, unsigned int *)); | |
93 | ||
94 | #if defined(__STDC__) || defined(ALMOST_STDC) | |
95 | struct alpha_elf_link_hash_entry; | |
96 | #endif | |
97 | ||
98 | static boolean elf64_alpha_output_extsym | |
99 | PARAMS((struct alpha_elf_link_hash_entry *, PTR)); | |
100 | ||
101 | static boolean elf64_alpha_can_merge_gots | |
102 | PARAMS((bfd *, bfd *)); | |
103 | static void elf64_alpha_merge_gots | |
104 | PARAMS((bfd *, bfd *)); | |
105 | static boolean elf64_alpha_calc_got_offsets_for_symbol | |
106 | PARAMS ((struct alpha_elf_link_hash_entry *, PTR)); | |
107 | static void elf64_alpha_calc_got_offsets PARAMS ((struct bfd_link_info *)); | |
108 | static boolean elf64_alpha_size_got_sections | |
f44f99a5 RH |
109 | PARAMS ((struct bfd_link_info *)); |
110 | static boolean elf64_alpha_size_plt_section | |
111 | PARAMS ((struct bfd_link_info *)); | |
112 | static boolean elf64_alpha_size_plt_section_1 | |
113 | PARAMS ((struct alpha_elf_link_hash_entry *, PTR)); | |
252b5132 RH |
114 | static boolean elf64_alpha_always_size_sections |
115 | PARAMS ((bfd *, struct bfd_link_info *)); | |
3765b1be RH |
116 | static int alpha_dynamic_entries_for_reloc |
117 | PARAMS ((int, int, int)); | |
252b5132 RH |
118 | static boolean elf64_alpha_calc_dynrel_sizes |
119 | PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *)); | |
f44f99a5 RH |
120 | static boolean elf64_alpha_size_rela_got_section |
121 | PARAMS ((struct bfd_link_info *)); | |
122 | static boolean elf64_alpha_size_rela_got_1 | |
123 | PARAMS ((struct alpha_elf_link_hash_entry *, struct bfd_link_info *)); | |
252b5132 RH |
124 | static boolean elf64_alpha_add_symbol_hook |
125 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, | |
126 | const char **, flagword *, asection **, bfd_vma *)); | |
3765b1be RH |
127 | static struct alpha_elf_got_entry *get_got_entry |
128 | PARAMS ((bfd *, struct alpha_elf_link_hash_entry *, unsigned long, | |
129 | unsigned long, bfd_vma)); | |
252b5132 RH |
130 | static boolean elf64_alpha_check_relocs |
131 | PARAMS((bfd *, struct bfd_link_info *, asection *sec, | |
132 | const Elf_Internal_Rela *)); | |
133 | static boolean elf64_alpha_adjust_dynamic_symbol | |
134 | PARAMS((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
135 | static boolean elf64_alpha_size_dynamic_sections | |
136 | PARAMS((bfd *, struct bfd_link_info *)); | |
4a67a098 RH |
137 | static boolean elf64_alpha_relocate_section_r |
138 | PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
139 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
252b5132 RH |
140 | static boolean elf64_alpha_relocate_section |
141 | PARAMS((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
142 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
143 | static boolean elf64_alpha_finish_dynamic_symbol | |
144 | PARAMS((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
145 | Elf_Internal_Sym *)); | |
146 | static boolean elf64_alpha_finish_dynamic_sections | |
147 | PARAMS((bfd *, struct bfd_link_info *)); | |
148 | static boolean elf64_alpha_final_link | |
149 | PARAMS((bfd *, struct bfd_link_info *)); | |
cd6f9321 L |
150 | static boolean elf64_alpha_merge_ind_symbols |
151 | PARAMS((struct alpha_elf_link_hash_entry *, PTR)); | |
152 | static Elf_Internal_Rela * elf64_alpha_find_reloc_at_ofs | |
153 | PARAMS ((Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_vma, int)); | |
fcfbdf31 | 154 | static enum elf_reloc_type_class elf64_alpha_reloc_type_class |
f51e552e | 155 | PARAMS ((const Elf_Internal_Rela *)); |
252b5132 RH |
156 | \f |
157 | struct alpha_elf_link_hash_entry | |
158 | { | |
159 | struct elf_link_hash_entry root; | |
160 | ||
161 | /* External symbol information. */ | |
162 | EXTR esym; | |
163 | ||
164 | /* Cumulative flags for all the .got entries. */ | |
165 | int flags; | |
166 | ||
9e756d64 | 167 | /* Contexts in which a literal was referenced. */ |
3765b1be RH |
168 | #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01 |
169 | #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02 | |
170 | #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04 | |
171 | #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08 | |
172 | #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10 | |
173 | #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20 | |
174 | #define ALPHA_ELF_LINK_HASH_LU_FUNC 0x38 | |
9e756d64 | 175 | #define ALPHA_ELF_LINK_HASH_TLS_IE 0x40 |
252b5132 RH |
176 | |
177 | /* Used to implement multiple .got subsections. */ | |
178 | struct alpha_elf_got_entry | |
179 | { | |
180 | struct alpha_elf_got_entry *next; | |
181 | ||
182 | /* which .got subsection? */ | |
183 | bfd *gotobj; | |
184 | ||
185 | /* the addend in effect for this entry. */ | |
dc810e39 | 186 | bfd_vma addend; |
252b5132 RH |
187 | |
188 | /* the .got offset for this entry. */ | |
189 | int got_offset; | |
190 | ||
3765b1be RH |
191 | /* How many references to this entry? */ |
192 | int use_count; | |
252b5132 | 193 | |
3765b1be RH |
194 | /* The relocation type of this entry. */ |
195 | unsigned char reloc_type; | |
252b5132 | 196 | |
3765b1be RH |
197 | /* How a LITERAL is used. */ |
198 | unsigned char flags; | |
199 | ||
200 | /* Have we initialized the dynamic relocation for this entry? */ | |
201 | unsigned char reloc_done; | |
202 | ||
203 | /* Have we adjusted this entry for SEC_MERGE? */ | |
204 | unsigned char reloc_xlated; | |
252b5132 RH |
205 | } *got_entries; |
206 | ||
207 | /* used to count non-got, non-plt relocations for delayed sizing | |
208 | of relocation sections. */ | |
209 | struct alpha_elf_reloc_entry | |
210 | { | |
211 | struct alpha_elf_reloc_entry *next; | |
212 | ||
213 | /* which .reloc section? */ | |
214 | asection *srel; | |
215 | ||
216 | /* what kind of relocation? */ | |
fcfbdf31 JJ |
217 | unsigned int rtype; |
218 | ||
219 | /* is this against read-only section? */ | |
220 | unsigned int reltext : 1; | |
252b5132 RH |
221 | |
222 | /* how many did we find? */ | |
223 | unsigned long count; | |
224 | } *reloc_entries; | |
225 | }; | |
226 | ||
227 | /* Alpha ELF linker hash table. */ | |
228 | ||
229 | struct alpha_elf_link_hash_table | |
230 | { | |
231 | struct elf_link_hash_table root; | |
232 | ||
233 | /* The head of a list of .got subsections linked through | |
234 | alpha_elf_tdata(abfd)->got_link_next. */ | |
235 | bfd *got_list; | |
236 | }; | |
237 | ||
238 | /* Look up an entry in a Alpha ELF linker hash table. */ | |
239 | ||
240 | #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \ | |
241 | ((struct alpha_elf_link_hash_entry *) \ | |
242 | elf_link_hash_lookup (&(table)->root, (string), (create), \ | |
243 | (copy), (follow))) | |
244 | ||
245 | /* Traverse a Alpha ELF linker hash table. */ | |
246 | ||
247 | #define alpha_elf_link_hash_traverse(table, func, info) \ | |
248 | (elf_link_hash_traverse \ | |
249 | (&(table)->root, \ | |
250 | (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ | |
251 | (info))) | |
252 | ||
253 | /* Get the Alpha ELF linker hash table from a link_info structure. */ | |
254 | ||
255 | #define alpha_elf_hash_table(p) \ | |
256 | ((struct alpha_elf_link_hash_table *) ((p)->hash)) | |
257 | ||
258 | /* Get the object's symbols as our own entry type. */ | |
259 | ||
260 | #define alpha_elf_sym_hashes(abfd) \ | |
261 | ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd)) | |
262 | ||
263 | /* Should we do dynamic things to this symbol? */ | |
264 | ||
8fb35fed RH |
265 | static int |
266 | alpha_elf_dynamic_symbol_p (h, info) | |
267 | struct elf_link_hash_entry *h; | |
268 | struct bfd_link_info *info; | |
269 | { | |
270 | if (h == NULL) | |
271 | return false; | |
272 | ||
273 | while (h->root.type == bfd_link_hash_indirect | |
274 | || h->root.type == bfd_link_hash_warning) | |
275 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
276 | ||
277 | if (h->dynindx == -1) | |
278 | return false; | |
ca88208a RH |
279 | |
280 | if (h->root.type == bfd_link_hash_undefweak | |
281 | || h->root.type == bfd_link_hash_defweak) | |
282 | return true; | |
283 | ||
2719f880 L |
284 | switch (ELF_ST_VISIBILITY (h->other)) |
285 | { | |
ca88208a RH |
286 | case STV_DEFAULT: |
287 | break; | |
2719f880 | 288 | case STV_HIDDEN: |
ca88208a | 289 | case STV_INTERNAL: |
2719f880 | 290 | return false; |
ca88208a RH |
291 | case STV_PROTECTED: |
292 | if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) | |
293 | return false; | |
294 | break; | |
2719f880 | 295 | } |
8fb35fed | 296 | |
8fb35fed RH |
297 | if ((info->shared && !info->symbolic) |
298 | || ((h->elf_link_hash_flags | |
299 | & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)) | |
300 | == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))) | |
301 | return true; | |
302 | ||
303 | return false; | |
304 | } | |
252b5132 RH |
305 | |
306 | /* Create an entry in a Alpha ELF linker hash table. */ | |
307 | ||
308 | static struct bfd_hash_entry * | |
309 | elf64_alpha_link_hash_newfunc (entry, table, string) | |
310 | struct bfd_hash_entry *entry; | |
311 | struct bfd_hash_table *table; | |
312 | const char *string; | |
313 | { | |
314 | struct alpha_elf_link_hash_entry *ret = | |
315 | (struct alpha_elf_link_hash_entry *) entry; | |
316 | ||
317 | /* Allocate the structure if it has not already been allocated by a | |
318 | subclass. */ | |
319 | if (ret == (struct alpha_elf_link_hash_entry *) NULL) | |
320 | ret = ((struct alpha_elf_link_hash_entry *) | |
321 | bfd_hash_allocate (table, | |
322 | sizeof (struct alpha_elf_link_hash_entry))); | |
323 | if (ret == (struct alpha_elf_link_hash_entry *) NULL) | |
324 | return (struct bfd_hash_entry *) ret; | |
325 | ||
326 | /* Call the allocation method of the superclass. */ | |
327 | ret = ((struct alpha_elf_link_hash_entry *) | |
328 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
329 | table, string)); | |
330 | if (ret != (struct alpha_elf_link_hash_entry *) NULL) | |
331 | { | |
332 | /* Set local fields. */ | |
333 | memset (&ret->esym, 0, sizeof (EXTR)); | |
334 | /* We use -2 as a marker to indicate that the information has | |
335 | not been set. -1 means there is no associated ifd. */ | |
336 | ret->esym.ifd = -2; | |
337 | ret->flags = 0; | |
338 | ret->got_entries = NULL; | |
339 | ret->reloc_entries = NULL; | |
340 | } | |
341 | ||
342 | return (struct bfd_hash_entry *) ret; | |
343 | } | |
344 | ||
345 | /* Create a Alpha ELF linker hash table. */ | |
346 | ||
347 | static struct bfd_link_hash_table * | |
348 | elf64_alpha_bfd_link_hash_table_create (abfd) | |
349 | bfd *abfd; | |
350 | { | |
351 | struct alpha_elf_link_hash_table *ret; | |
dc810e39 | 352 | bfd_size_type amt = sizeof (struct alpha_elf_link_hash_table); |
252b5132 | 353 | |
e2d34d7d | 354 | ret = (struct alpha_elf_link_hash_table *) bfd_zmalloc (amt); |
252b5132 RH |
355 | if (ret == (struct alpha_elf_link_hash_table *) NULL) |
356 | return NULL; | |
357 | ||
358 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, | |
359 | elf64_alpha_link_hash_newfunc)) | |
360 | { | |
e2d34d7d | 361 | free (ret); |
252b5132 RH |
362 | return NULL; |
363 | } | |
364 | ||
365 | return &ret->root.root; | |
366 | } | |
367 | \f | |
368 | /* We have some private fields hanging off of the elf_tdata structure. */ | |
369 | ||
370 | struct alpha_elf_obj_tdata | |
371 | { | |
372 | struct elf_obj_tdata root; | |
373 | ||
374 | /* For every input file, these are the got entries for that object's | |
375 | local symbols. */ | |
376 | struct alpha_elf_got_entry ** local_got_entries; | |
377 | ||
378 | /* For every input file, this is the object that owns the got that | |
379 | this input file uses. */ | |
380 | bfd *gotobj; | |
381 | ||
382 | /* For every got, this is a linked list through the objects using this got */ | |
383 | bfd *in_got_link_next; | |
384 | ||
385 | /* For every got, this is a link to the next got subsegment. */ | |
386 | bfd *got_link_next; | |
387 | ||
388 | /* For every got, this is the section. */ | |
389 | asection *got; | |
390 | ||
3765b1be RH |
391 | /* For every got, this is it's total number of words. */ |
392 | int total_got_size; | |
252b5132 | 393 | |
3765b1be | 394 | /* For every got, this is the sum of the number of words required |
252b5132 | 395 | to hold all of the member object's local got. */ |
3765b1be | 396 | int local_got_size; |
252b5132 RH |
397 | }; |
398 | ||
399 | #define alpha_elf_tdata(abfd) \ | |
400 | ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any) | |
401 | ||
402 | static boolean | |
403 | elf64_alpha_mkobject (abfd) | |
404 | bfd *abfd; | |
405 | { | |
dc810e39 AM |
406 | bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata); |
407 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
252b5132 RH |
408 | if (abfd->tdata.any == NULL) |
409 | return false; | |
410 | return true; | |
411 | } | |
412 | ||
413 | static boolean | |
414 | elf64_alpha_object_p (abfd) | |
415 | bfd *abfd; | |
416 | { | |
417 | /* Allocate our special target data. */ | |
418 | struct alpha_elf_obj_tdata *new_tdata; | |
dc810e39 AM |
419 | bfd_size_type amt = sizeof (struct alpha_elf_obj_tdata); |
420 | new_tdata = bfd_zalloc (abfd, amt); | |
252b5132 RH |
421 | if (new_tdata == NULL) |
422 | return false; | |
423 | new_tdata->root = *abfd->tdata.elf_obj_data; | |
424 | abfd->tdata.any = new_tdata; | |
425 | ||
426 | /* Set the right machine number for an Alpha ELF file. */ | |
427 | return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0); | |
428 | } | |
429 | \f | |
430 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
431 | from smaller values. Start with zero, widen, *then* decrement. */ | |
432 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
433 | ||
dfe57ca0 RH |
434 | #define SKIP_HOWTO(N) \ |
435 | HOWTO(N, 0, 0, 0, 0, 0, 0, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0) | |
436 | ||
252b5132 RH |
437 | static reloc_howto_type elf64_alpha_howto_table[] = |
438 | { | |
439 | HOWTO (R_ALPHA_NONE, /* type */ | |
440 | 0, /* rightshift */ | |
441 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
442 | 8, /* bitsize */ | |
443 | true, /* pc_relative */ | |
444 | 0, /* bitpos */ | |
445 | complain_overflow_dont, /* complain_on_overflow */ | |
446 | elf64_alpha_reloc_nil, /* special_function */ | |
447 | "NONE", /* name */ | |
448 | false, /* partial_inplace */ | |
449 | 0, /* src_mask */ | |
450 | 0, /* dst_mask */ | |
451 | true), /* pcrel_offset */ | |
452 | ||
453 | /* A 32 bit reference to a symbol. */ | |
454 | HOWTO (R_ALPHA_REFLONG, /* type */ | |
455 | 0, /* rightshift */ | |
456 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
457 | 32, /* bitsize */ | |
458 | false, /* pc_relative */ | |
459 | 0, /* bitpos */ | |
460 | complain_overflow_bitfield, /* complain_on_overflow */ | |
461 | 0, /* special_function */ | |
462 | "REFLONG", /* name */ | |
463 | false, /* partial_inplace */ | |
464 | 0xffffffff, /* src_mask */ | |
465 | 0xffffffff, /* dst_mask */ | |
466 | false), /* pcrel_offset */ | |
467 | ||
468 | /* A 64 bit reference to a symbol. */ | |
469 | HOWTO (R_ALPHA_REFQUAD, /* type */ | |
470 | 0, /* rightshift */ | |
471 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
472 | 64, /* bitsize */ | |
473 | false, /* pc_relative */ | |
474 | 0, /* bitpos */ | |
475 | complain_overflow_bitfield, /* complain_on_overflow */ | |
476 | 0, /* special_function */ | |
477 | "REFQUAD", /* name */ | |
478 | false, /* partial_inplace */ | |
479 | MINUS_ONE, /* src_mask */ | |
480 | MINUS_ONE, /* dst_mask */ | |
481 | false), /* pcrel_offset */ | |
482 | ||
483 | /* A 32 bit GP relative offset. This is just like REFLONG except | |
484 | that when the value is used the value of the gp register will be | |
485 | added in. */ | |
486 | HOWTO (R_ALPHA_GPREL32, /* type */ | |
487 | 0, /* rightshift */ | |
488 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
489 | 32, /* bitsize */ | |
490 | false, /* pc_relative */ | |
491 | 0, /* bitpos */ | |
492 | complain_overflow_bitfield, /* complain_on_overflow */ | |
493 | 0, /* special_function */ | |
494 | "GPREL32", /* name */ | |
495 | false, /* partial_inplace */ | |
496 | 0xffffffff, /* src_mask */ | |
497 | 0xffffffff, /* dst_mask */ | |
498 | false), /* pcrel_offset */ | |
499 | ||
500 | /* Used for an instruction that refers to memory off the GP register. */ | |
501 | HOWTO (R_ALPHA_LITERAL, /* type */ | |
502 | 0, /* rightshift */ | |
dfe57ca0 | 503 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 RH |
504 | 16, /* bitsize */ |
505 | false, /* pc_relative */ | |
506 | 0, /* bitpos */ | |
507 | complain_overflow_signed, /* complain_on_overflow */ | |
508 | 0, /* special_function */ | |
509 | "ELF_LITERAL", /* name */ | |
510 | false, /* partial_inplace */ | |
511 | 0xffff, /* src_mask */ | |
512 | 0xffff, /* dst_mask */ | |
513 | false), /* pcrel_offset */ | |
514 | ||
515 | /* This reloc only appears immediately following an ELF_LITERAL reloc. | |
516 | It identifies a use of the literal. The symbol index is special: | |
517 | 1 means the literal address is in the base register of a memory | |
518 | format instruction; 2 means the literal address is in the byte | |
519 | offset register of a byte-manipulation instruction; 3 means the | |
520 | literal address is in the target register of a jsr instruction. | |
521 | This does not actually do any relocation. */ | |
522 | HOWTO (R_ALPHA_LITUSE, /* type */ | |
523 | 0, /* rightshift */ | |
dfe57ca0 | 524 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 RH |
525 | 32, /* bitsize */ |
526 | false, /* pc_relative */ | |
527 | 0, /* bitpos */ | |
528 | complain_overflow_dont, /* complain_on_overflow */ | |
529 | elf64_alpha_reloc_nil, /* special_function */ | |
530 | "LITUSE", /* name */ | |
531 | false, /* partial_inplace */ | |
532 | 0, /* src_mask */ | |
533 | 0, /* dst_mask */ | |
534 | false), /* pcrel_offset */ | |
535 | ||
536 | /* Load the gp register. This is always used for a ldah instruction | |
537 | which loads the upper 16 bits of the gp register. The symbol | |
538 | index of the GPDISP instruction is an offset in bytes to the lda | |
539 | instruction that loads the lower 16 bits. The value to use for | |
540 | the relocation is the difference between the GP value and the | |
541 | current location; the load will always be done against a register | |
542 | holding the current address. | |
543 | ||
544 | NOTE: Unlike ECOFF, partial in-place relocation is not done. If | |
545 | any offset is present in the instructions, it is an offset from | |
546 | the register to the ldah instruction. This lets us avoid any | |
547 | stupid hackery like inventing a gp value to do partial relocation | |
548 | against. Also unlike ECOFF, we do the whole relocation off of | |
549 | the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd, | |
550 | space consuming bit, that, since all the information was present | |
551 | in the GPDISP_HI16 reloc. */ | |
552 | HOWTO (R_ALPHA_GPDISP, /* type */ | |
553 | 16, /* rightshift */ | |
554 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
555 | 16, /* bitsize */ | |
556 | false, /* pc_relative */ | |
557 | 0, /* bitpos */ | |
558 | complain_overflow_dont, /* complain_on_overflow */ | |
559 | elf64_alpha_reloc_gpdisp, /* special_function */ | |
560 | "GPDISP", /* name */ | |
561 | false, /* partial_inplace */ | |
562 | 0xffff, /* src_mask */ | |
563 | 0xffff, /* dst_mask */ | |
564 | true), /* pcrel_offset */ | |
565 | ||
566 | /* A 21 bit branch. */ | |
567 | HOWTO (R_ALPHA_BRADDR, /* type */ | |
568 | 2, /* rightshift */ | |
569 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
570 | 21, /* bitsize */ | |
571 | true, /* pc_relative */ | |
572 | 0, /* bitpos */ | |
573 | complain_overflow_signed, /* complain_on_overflow */ | |
574 | 0, /* special_function */ | |
575 | "BRADDR", /* name */ | |
576 | false, /* partial_inplace */ | |
577 | 0x1fffff, /* src_mask */ | |
578 | 0x1fffff, /* dst_mask */ | |
579 | true), /* pcrel_offset */ | |
580 | ||
581 | /* A hint for a jump to a register. */ | |
582 | HOWTO (R_ALPHA_HINT, /* type */ | |
583 | 2, /* rightshift */ | |
dfe57ca0 | 584 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 RH |
585 | 14, /* bitsize */ |
586 | true, /* pc_relative */ | |
587 | 0, /* bitpos */ | |
588 | complain_overflow_dont, /* complain_on_overflow */ | |
589 | 0, /* special_function */ | |
590 | "HINT", /* name */ | |
591 | false, /* partial_inplace */ | |
592 | 0x3fff, /* src_mask */ | |
593 | 0x3fff, /* dst_mask */ | |
594 | true), /* pcrel_offset */ | |
595 | ||
596 | /* 16 bit PC relative offset. */ | |
597 | HOWTO (R_ALPHA_SREL16, /* type */ | |
598 | 0, /* rightshift */ | |
599 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
600 | 16, /* bitsize */ | |
601 | true, /* pc_relative */ | |
602 | 0, /* bitpos */ | |
603 | complain_overflow_signed, /* complain_on_overflow */ | |
604 | 0, /* special_function */ | |
605 | "SREL16", /* name */ | |
606 | false, /* partial_inplace */ | |
607 | 0xffff, /* src_mask */ | |
608 | 0xffff, /* dst_mask */ | |
16b65e4e | 609 | true), /* pcrel_offset */ |
252b5132 RH |
610 | |
611 | /* 32 bit PC relative offset. */ | |
612 | HOWTO (R_ALPHA_SREL32, /* type */ | |
613 | 0, /* rightshift */ | |
614 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
615 | 32, /* bitsize */ | |
616 | true, /* pc_relative */ | |
617 | 0, /* bitpos */ | |
618 | complain_overflow_signed, /* complain_on_overflow */ | |
619 | 0, /* special_function */ | |
620 | "SREL32", /* name */ | |
621 | false, /* partial_inplace */ | |
622 | 0xffffffff, /* src_mask */ | |
623 | 0xffffffff, /* dst_mask */ | |
16b65e4e | 624 | true), /* pcrel_offset */ |
252b5132 RH |
625 | |
626 | /* A 64 bit PC relative offset. */ | |
627 | HOWTO (R_ALPHA_SREL64, /* type */ | |
628 | 0, /* rightshift */ | |
629 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
630 | 64, /* bitsize */ | |
631 | true, /* pc_relative */ | |
632 | 0, /* bitpos */ | |
633 | complain_overflow_signed, /* complain_on_overflow */ | |
634 | 0, /* special_function */ | |
635 | "SREL64", /* name */ | |
636 | false, /* partial_inplace */ | |
637 | MINUS_ONE, /* src_mask */ | |
638 | MINUS_ONE, /* dst_mask */ | |
16b65e4e | 639 | true), /* pcrel_offset */ |
252b5132 | 640 | |
dfe57ca0 RH |
641 | /* Skip 12 - 16; deprecated ECOFF relocs. */ |
642 | SKIP_HOWTO (12), | |
643 | SKIP_HOWTO (13), | |
644 | SKIP_HOWTO (14), | |
645 | SKIP_HOWTO (15), | |
646 | SKIP_HOWTO (16), | |
252b5132 RH |
647 | |
648 | /* The high 16 bits of the displacement from GP to the target. */ | |
649 | HOWTO (R_ALPHA_GPRELHIGH, | |
650 | 0, /* rightshift */ | |
dfe57ca0 | 651 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 RH |
652 | 16, /* bitsize */ |
653 | false, /* pc_relative */ | |
654 | 0, /* bitpos */ | |
655 | complain_overflow_signed, /* complain_on_overflow */ | |
dfe57ca0 | 656 | 0, /* special_function */ |
252b5132 RH |
657 | "GPRELHIGH", /* name */ |
658 | false, /* partial_inplace */ | |
659 | 0xffff, /* src_mask */ | |
660 | 0xffff, /* dst_mask */ | |
661 | false), /* pcrel_offset */ | |
662 | ||
663 | /* The low 16 bits of the displacement from GP to the target. */ | |
664 | HOWTO (R_ALPHA_GPRELLOW, | |
665 | 0, /* rightshift */ | |
dfe57ca0 | 666 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 RH |
667 | 16, /* bitsize */ |
668 | false, /* pc_relative */ | |
669 | 0, /* bitpos */ | |
670 | complain_overflow_dont, /* complain_on_overflow */ | |
dfe57ca0 | 671 | 0, /* special_function */ |
252b5132 RH |
672 | "GPRELLOW", /* name */ |
673 | false, /* partial_inplace */ | |
674 | 0xffff, /* src_mask */ | |
675 | 0xffff, /* dst_mask */ | |
676 | false), /* pcrel_offset */ | |
677 | ||
678 | /* A 16-bit displacement from the GP to the target. */ | |
dfe57ca0 | 679 | HOWTO (R_ALPHA_GPREL16, |
252b5132 | 680 | 0, /* rightshift */ |
dfe57ca0 | 681 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 RH |
682 | 16, /* bitsize */ |
683 | false, /* pc_relative */ | |
684 | 0, /* bitpos */ | |
685 | complain_overflow_signed, /* complain_on_overflow */ | |
686 | 0, /* special_function */ | |
dfe57ca0 | 687 | "GPREL16", /* name */ |
252b5132 RH |
688 | false, /* partial_inplace */ |
689 | 0xffff, /* src_mask */ | |
690 | 0xffff, /* dst_mask */ | |
691 | false), /* pcrel_offset */ | |
692 | ||
dfe57ca0 RH |
693 | /* Skip 20 - 23; deprecated ECOFF relocs. */ |
694 | SKIP_HOWTO (20), | |
695 | SKIP_HOWTO (21), | |
696 | SKIP_HOWTO (22), | |
697 | SKIP_HOWTO (23), | |
252b5132 | 698 | |
fe8bc63d | 699 | /* Misc ELF relocations. */ |
252b5132 RH |
700 | |
701 | /* A dynamic relocation to copy the target into our .dynbss section. */ | |
702 | /* Not generated, as all Alpha objects use PIC, so it is not needed. It | |
703 | is present because every other ELF has one, but should not be used | |
704 | because .dynbss is an ugly thing. */ | |
705 | HOWTO (R_ALPHA_COPY, | |
706 | 0, | |
707 | 0, | |
708 | 0, | |
709 | false, | |
710 | 0, | |
711 | complain_overflow_dont, | |
712 | bfd_elf_generic_reloc, | |
713 | "COPY", | |
714 | false, | |
715 | 0, | |
716 | 0, | |
717 | true), | |
718 | ||
719 | /* A dynamic relocation for a .got entry. */ | |
720 | HOWTO (R_ALPHA_GLOB_DAT, | |
721 | 0, | |
722 | 0, | |
723 | 0, | |
724 | false, | |
725 | 0, | |
726 | complain_overflow_dont, | |
727 | bfd_elf_generic_reloc, | |
728 | "GLOB_DAT", | |
729 | false, | |
730 | 0, | |
731 | 0, | |
732 | true), | |
733 | ||
734 | /* A dynamic relocation for a .plt entry. */ | |
735 | HOWTO (R_ALPHA_JMP_SLOT, | |
736 | 0, | |
737 | 0, | |
738 | 0, | |
739 | false, | |
740 | 0, | |
741 | complain_overflow_dont, | |
742 | bfd_elf_generic_reloc, | |
743 | "JMP_SLOT", | |
744 | false, | |
745 | 0, | |
746 | 0, | |
747 | true), | |
748 | ||
749 | /* A dynamic relocation to add the base of the DSO to a 64-bit field. */ | |
750 | HOWTO (R_ALPHA_RELATIVE, | |
751 | 0, | |
752 | 0, | |
753 | 0, | |
754 | false, | |
755 | 0, | |
756 | complain_overflow_dont, | |
757 | bfd_elf_generic_reloc, | |
758 | "RELATIVE", | |
759 | false, | |
760 | 0, | |
761 | 0, | |
7793f4d0 RH |
762 | true), |
763 | ||
764 | /* A 21 bit branch that adjusts for gp loads. */ | |
765 | HOWTO (R_ALPHA_BRSGP, /* type */ | |
766 | 2, /* rightshift */ | |
767 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
768 | 21, /* bitsize */ | |
769 | true, /* pc_relative */ | |
770 | 0, /* bitpos */ | |
771 | complain_overflow_signed, /* complain_on_overflow */ | |
772 | 0, /* special_function */ | |
773 | "BRSGP", /* name */ | |
774 | false, /* partial_inplace */ | |
775 | 0x1fffff, /* src_mask */ | |
776 | 0x1fffff, /* dst_mask */ | |
777 | true), /* pcrel_offset */ | |
3765b1be RH |
778 | |
779 | /* Creates a tls_index for the symbol in the got. */ | |
780 | HOWTO (R_ALPHA_TLSGD, /* type */ | |
781 | 0, /* rightshift */ | |
782 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
783 | 16, /* bitsize */ | |
784 | false, /* pc_relative */ | |
785 | 0, /* bitpos */ | |
786 | complain_overflow_signed, /* complain_on_overflow */ | |
787 | 0, /* special_function */ | |
788 | "TLSGD", /* name */ | |
789 | false, /* partial_inplace */ | |
790 | 0xffff, /* src_mask */ | |
791 | 0xffff, /* dst_mask */ | |
792 | false), /* pcrel_offset */ | |
793 | ||
794 | /* Creates a tls_index for the (current) module in the got. */ | |
795 | HOWTO (R_ALPHA_TLSLDM, /* type */ | |
796 | 0, /* rightshift */ | |
797 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
798 | 16, /* bitsize */ | |
799 | false, /* pc_relative */ | |
800 | 0, /* bitpos */ | |
801 | complain_overflow_signed, /* complain_on_overflow */ | |
802 | 0, /* special_function */ | |
803 | "TLSLDM", /* name */ | |
804 | false, /* partial_inplace */ | |
805 | 0xffff, /* src_mask */ | |
806 | 0xffff, /* dst_mask */ | |
807 | false), /* pcrel_offset */ | |
808 | ||
809 | /* A dynamic relocation for a DTP module entry. */ | |
810 | HOWTO (R_ALPHA_DTPMOD64, /* type */ | |
811 | 0, /* rightshift */ | |
812 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
813 | 64, /* bitsize */ | |
814 | false, /* pc_relative */ | |
815 | 0, /* bitpos */ | |
816 | complain_overflow_bitfield, /* complain_on_overflow */ | |
817 | 0, /* special_function */ | |
818 | "DTPMOD64", /* name */ | |
819 | false, /* partial_inplace */ | |
820 | MINUS_ONE, /* src_mask */ | |
821 | MINUS_ONE, /* dst_mask */ | |
822 | false), /* pcrel_offset */ | |
823 | ||
824 | /* Creates a 64-bit offset in the got for the displacement | |
825 | from DTP to the target. */ | |
826 | HOWTO (R_ALPHA_GOTDTPREL, /* type */ | |
827 | 0, /* rightshift */ | |
828 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
829 | 16, /* bitsize */ | |
830 | false, /* pc_relative */ | |
831 | 0, /* bitpos */ | |
832 | complain_overflow_signed, /* complain_on_overflow */ | |
833 | 0, /* special_function */ | |
834 | "GOTDTPREL", /* name */ | |
835 | false, /* partial_inplace */ | |
836 | 0xffff, /* src_mask */ | |
837 | 0xffff, /* dst_mask */ | |
838 | false), /* pcrel_offset */ | |
839 | ||
840 | /* A dynamic relocation for a displacement from DTP to the target. */ | |
841 | HOWTO (R_ALPHA_DTPREL64, /* type */ | |
842 | 0, /* rightshift */ | |
843 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
844 | 64, /* bitsize */ | |
845 | false, /* pc_relative */ | |
846 | 0, /* bitpos */ | |
847 | complain_overflow_bitfield, /* complain_on_overflow */ | |
848 | 0, /* special_function */ | |
849 | "DTPREL64", /* name */ | |
850 | false, /* partial_inplace */ | |
851 | MINUS_ONE, /* src_mask */ | |
852 | MINUS_ONE, /* dst_mask */ | |
853 | false), /* pcrel_offset */ | |
854 | ||
855 | /* The high 16 bits of the displacement from DTP to the target. */ | |
856 | HOWTO (R_ALPHA_DTPRELHI, /* type */ | |
857 | 0, /* rightshift */ | |
858 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
859 | 16, /* bitsize */ | |
860 | false, /* pc_relative */ | |
861 | 0, /* bitpos */ | |
862 | complain_overflow_signed, /* complain_on_overflow */ | |
863 | 0, /* special_function */ | |
864 | "DTPRELHI", /* name */ | |
865 | false, /* partial_inplace */ | |
866 | 0xffff, /* src_mask */ | |
867 | 0xffff, /* dst_mask */ | |
868 | false), /* pcrel_offset */ | |
869 | ||
870 | /* The low 16 bits of the displacement from DTP to the target. */ | |
871 | HOWTO (R_ALPHA_DTPRELLO, /* type */ | |
872 | 0, /* rightshift */ | |
873 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
874 | 16, /* bitsize */ | |
875 | false, /* pc_relative */ | |
876 | 0, /* bitpos */ | |
877 | complain_overflow_dont, /* complain_on_overflow */ | |
878 | 0, /* special_function */ | |
879 | "DTPRELLO", /* name */ | |
880 | false, /* partial_inplace */ | |
881 | 0xffff, /* src_mask */ | |
882 | 0xffff, /* dst_mask */ | |
883 | false), /* pcrel_offset */ | |
884 | ||
885 | /* A 16-bit displacement from DTP to the target. */ | |
886 | HOWTO (R_ALPHA_DTPREL16, /* type */ | |
887 | 0, /* rightshift */ | |
888 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
889 | 16, /* bitsize */ | |
890 | false, /* pc_relative */ | |
891 | 0, /* bitpos */ | |
892 | complain_overflow_signed, /* complain_on_overflow */ | |
893 | 0, /* special_function */ | |
894 | "DTPREL16", /* name */ | |
895 | false, /* partial_inplace */ | |
896 | 0xffff, /* src_mask */ | |
897 | 0xffff, /* dst_mask */ | |
898 | false), /* pcrel_offset */ | |
899 | ||
900 | /* Creates a 64-bit offset in the got for the displacement | |
901 | from TP to the target. */ | |
902 | HOWTO (R_ALPHA_GOTTPREL, /* type */ | |
903 | 0, /* rightshift */ | |
904 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
905 | 16, /* bitsize */ | |
906 | false, /* pc_relative */ | |
907 | 0, /* bitpos */ | |
908 | complain_overflow_signed, /* complain_on_overflow */ | |
909 | 0, /* special_function */ | |
910 | "GOTTPREL", /* name */ | |
911 | false, /* partial_inplace */ | |
912 | 0xffff, /* src_mask */ | |
913 | 0xffff, /* dst_mask */ | |
914 | false), /* pcrel_offset */ | |
915 | ||
916 | /* A dynamic relocation for a displacement from TP to the target. */ | |
917 | HOWTO (R_ALPHA_TPREL64, /* type */ | |
918 | 0, /* rightshift */ | |
919 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
920 | 64, /* bitsize */ | |
921 | false, /* pc_relative */ | |
922 | 0, /* bitpos */ | |
923 | complain_overflow_bitfield, /* complain_on_overflow */ | |
924 | 0, /* special_function */ | |
925 | "TPREL64", /* name */ | |
926 | false, /* partial_inplace */ | |
927 | MINUS_ONE, /* src_mask */ | |
928 | MINUS_ONE, /* dst_mask */ | |
929 | false), /* pcrel_offset */ | |
930 | ||
931 | /* The high 16 bits of the displacement from TP to the target. */ | |
932 | HOWTO (R_ALPHA_TPRELHI, /* type */ | |
933 | 0, /* rightshift */ | |
934 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
935 | 16, /* bitsize */ | |
936 | false, /* pc_relative */ | |
937 | 0, /* bitpos */ | |
938 | complain_overflow_signed, /* complain_on_overflow */ | |
939 | 0, /* special_function */ | |
940 | "TPRELHI", /* name */ | |
941 | false, /* partial_inplace */ | |
942 | 0xffff, /* src_mask */ | |
943 | 0xffff, /* dst_mask */ | |
944 | false), /* pcrel_offset */ | |
945 | ||
946 | /* The low 16 bits of the displacement from TP to the target. */ | |
947 | HOWTO (R_ALPHA_TPRELLO, /* type */ | |
948 | 0, /* rightshift */ | |
949 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
950 | 16, /* bitsize */ | |
951 | false, /* pc_relative */ | |
952 | 0, /* bitpos */ | |
953 | complain_overflow_dont, /* complain_on_overflow */ | |
954 | 0, /* special_function */ | |
955 | "TPRELLO", /* name */ | |
956 | false, /* partial_inplace */ | |
957 | 0xffff, /* src_mask */ | |
958 | 0xffff, /* dst_mask */ | |
959 | false), /* pcrel_offset */ | |
960 | ||
961 | /* A 16-bit displacement from TP to the target. */ | |
962 | HOWTO (R_ALPHA_TPREL16, /* type */ | |
963 | 0, /* rightshift */ | |
964 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
965 | 16, /* bitsize */ | |
966 | false, /* pc_relative */ | |
967 | 0, /* bitpos */ | |
968 | complain_overflow_signed, /* complain_on_overflow */ | |
969 | 0, /* special_function */ | |
970 | "TPREL16", /* name */ | |
971 | false, /* partial_inplace */ | |
972 | 0xffff, /* src_mask */ | |
973 | 0xffff, /* dst_mask */ | |
974 | false), /* pcrel_offset */ | |
252b5132 RH |
975 | }; |
976 | ||
977 | /* A relocation function which doesn't do anything. */ | |
978 | ||
979 | static bfd_reloc_status_type | |
980 | elf64_alpha_reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message) | |
56fc028e | 981 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 982 | arelent *reloc; |
56fc028e AJ |
983 | asymbol *sym ATTRIBUTE_UNUSED; |
984 | PTR data ATTRIBUTE_UNUSED; | |
252b5132 RH |
985 | asection *sec; |
986 | bfd *output_bfd; | |
56fc028e | 987 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
988 | { |
989 | if (output_bfd) | |
990 | reloc->address += sec->output_offset; | |
991 | return bfd_reloc_ok; | |
992 | } | |
993 | ||
994 | /* A relocation function used for an unsupported reloc. */ | |
995 | ||
996 | static bfd_reloc_status_type | |
997 | elf64_alpha_reloc_bad (abfd, reloc, sym, data, sec, output_bfd, error_message) | |
56fc028e | 998 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 999 | arelent *reloc; |
56fc028e AJ |
1000 | asymbol *sym ATTRIBUTE_UNUSED; |
1001 | PTR data ATTRIBUTE_UNUSED; | |
252b5132 RH |
1002 | asection *sec; |
1003 | bfd *output_bfd; | |
56fc028e | 1004 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
1005 | { |
1006 | if (output_bfd) | |
1007 | reloc->address += sec->output_offset; | |
1008 | return bfd_reloc_notsupported; | |
1009 | } | |
1010 | ||
1011 | /* Do the work of the GPDISP relocation. */ | |
1012 | ||
1013 | static bfd_reloc_status_type | |
1014 | elf64_alpha_do_reloc_gpdisp (abfd, gpdisp, p_ldah, p_lda) | |
1015 | bfd *abfd; | |
1016 | bfd_vma gpdisp; | |
1017 | bfd_byte *p_ldah; | |
1018 | bfd_byte *p_lda; | |
1019 | { | |
1020 | bfd_reloc_status_type ret = bfd_reloc_ok; | |
1021 | bfd_vma addend; | |
1022 | unsigned long i_ldah, i_lda; | |
1023 | ||
1024 | i_ldah = bfd_get_32 (abfd, p_ldah); | |
1025 | i_lda = bfd_get_32 (abfd, p_lda); | |
1026 | ||
1027 | /* Complain if the instructions are not correct. */ | |
1028 | if (((i_ldah >> 26) & 0x3f) != 0x09 | |
1029 | || ((i_lda >> 26) & 0x3f) != 0x08) | |
1030 | ret = bfd_reloc_dangerous; | |
1031 | ||
1032 | /* Extract the user-supplied offset, mirroring the sign extensions | |
1033 | that the instructions perform. */ | |
1034 | addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff); | |
1035 | addend = (addend ^ 0x80008000) - 0x80008000; | |
1036 | ||
1037 | gpdisp += addend; | |
1038 | ||
1039 | if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000 | |
1040 | || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000) | |
1041 | ret = bfd_reloc_overflow; | |
1042 | ||
1043 | /* compensate for the sign extension again. */ | |
1044 | i_ldah = ((i_ldah & 0xffff0000) | |
1045 | | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff)); | |
1046 | i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff); | |
1047 | ||
dc810e39 AM |
1048 | bfd_put_32 (abfd, (bfd_vma) i_ldah, p_ldah); |
1049 | bfd_put_32 (abfd, (bfd_vma) i_lda, p_lda); | |
252b5132 RH |
1050 | |
1051 | return ret; | |
1052 | } | |
1053 | ||
1054 | /* The special function for the GPDISP reloc. */ | |
1055 | ||
1056 | static bfd_reloc_status_type | |
1057 | elf64_alpha_reloc_gpdisp (abfd, reloc_entry, sym, data, input_section, | |
1058 | output_bfd, err_msg) | |
1059 | bfd *abfd; | |
1060 | arelent *reloc_entry; | |
56fc028e | 1061 | asymbol *sym ATTRIBUTE_UNUSED; |
252b5132 RH |
1062 | PTR data; |
1063 | asection *input_section; | |
1064 | bfd *output_bfd; | |
1065 | char **err_msg; | |
1066 | { | |
1067 | bfd_reloc_status_type ret; | |
1068 | bfd_vma gp, relocation; | |
1069 | bfd_byte *p_ldah, *p_lda; | |
1070 | ||
1071 | /* Don't do anything if we're not doing a final link. */ | |
1072 | if (output_bfd) | |
1073 | { | |
1074 | reloc_entry->address += input_section->output_offset; | |
1075 | return bfd_reloc_ok; | |
1076 | } | |
1077 | ||
1078 | if (reloc_entry->address > input_section->_cooked_size || | |
1079 | reloc_entry->address + reloc_entry->addend > input_section->_cooked_size) | |
1080 | return bfd_reloc_outofrange; | |
1081 | ||
1082 | /* The gp used in the portion of the output object to which this | |
1083 | input object belongs is cached on the input bfd. */ | |
1084 | gp = _bfd_get_gp_value (abfd); | |
1085 | ||
1086 | relocation = (input_section->output_section->vma | |
1087 | + input_section->output_offset | |
1088 | + reloc_entry->address); | |
1089 | ||
1090 | p_ldah = (bfd_byte *) data + reloc_entry->address; | |
1091 | p_lda = p_ldah + reloc_entry->addend; | |
1092 | ||
1093 | ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda); | |
1094 | ||
1095 | /* Complain if the instructions are not correct. */ | |
1096 | if (ret == bfd_reloc_dangerous) | |
1097 | *err_msg = _("GPDISP relocation did not find ldah and lda instructions"); | |
1098 | ||
1099 | return ret; | |
1100 | } | |
1101 | ||
1102 | /* A mapping from BFD reloc types to Alpha ELF reloc types. */ | |
1103 | ||
1104 | struct elf_reloc_map | |
1105 | { | |
1106 | bfd_reloc_code_real_type bfd_reloc_val; | |
1107 | int elf_reloc_val; | |
1108 | }; | |
1109 | ||
1110 | static const struct elf_reloc_map elf64_alpha_reloc_map[] = | |
1111 | { | |
dfe57ca0 RH |
1112 | {BFD_RELOC_NONE, R_ALPHA_NONE}, |
1113 | {BFD_RELOC_32, R_ALPHA_REFLONG}, | |
1114 | {BFD_RELOC_64, R_ALPHA_REFQUAD}, | |
1115 | {BFD_RELOC_CTOR, R_ALPHA_REFQUAD}, | |
1116 | {BFD_RELOC_GPREL32, R_ALPHA_GPREL32}, | |
1117 | {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL}, | |
1118 | {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE}, | |
1119 | {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP}, | |
1120 | {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR}, | |
1121 | {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT}, | |
1122 | {BFD_RELOC_16_PCREL, R_ALPHA_SREL16}, | |
1123 | {BFD_RELOC_32_PCREL, R_ALPHA_SREL32}, | |
1124 | {BFD_RELOC_64_PCREL, R_ALPHA_SREL64}, | |
1125 | {BFD_RELOC_ALPHA_GPREL_HI16, R_ALPHA_GPRELHIGH}, | |
1126 | {BFD_RELOC_ALPHA_GPREL_LO16, R_ALPHA_GPRELLOW}, | |
1127 | {BFD_RELOC_GPREL16, R_ALPHA_GPREL16}, | |
7793f4d0 | 1128 | {BFD_RELOC_ALPHA_BRSGP, R_ALPHA_BRSGP}, |
3765b1be RH |
1129 | {BFD_RELOC_ALPHA_TLSGD, R_ALPHA_TLSGD}, |
1130 | {BFD_RELOC_ALPHA_TLSLDM, R_ALPHA_TLSLDM}, | |
1131 | {BFD_RELOC_ALPHA_DTPMOD64, R_ALPHA_DTPMOD64}, | |
1132 | {BFD_RELOC_ALPHA_GOTDTPREL16, R_ALPHA_GOTDTPREL}, | |
1133 | {BFD_RELOC_ALPHA_DTPREL64, R_ALPHA_DTPREL64}, | |
1134 | {BFD_RELOC_ALPHA_DTPREL_HI16, R_ALPHA_DTPRELHI}, | |
1135 | {BFD_RELOC_ALPHA_DTPREL_LO16, R_ALPHA_DTPRELLO}, | |
1136 | {BFD_RELOC_ALPHA_DTPREL16, R_ALPHA_DTPREL16}, | |
1137 | {BFD_RELOC_ALPHA_GOTTPREL16, R_ALPHA_GOTTPREL}, | |
1138 | {BFD_RELOC_ALPHA_TPREL64, R_ALPHA_TPREL64}, | |
1139 | {BFD_RELOC_ALPHA_TPREL_HI16, R_ALPHA_TPRELHI}, | |
1140 | {BFD_RELOC_ALPHA_TPREL_LO16, R_ALPHA_TPRELLO}, | |
1141 | {BFD_RELOC_ALPHA_TPREL16, R_ALPHA_TPREL16}, | |
252b5132 RH |
1142 | }; |
1143 | ||
1144 | /* Given a BFD reloc type, return a HOWTO structure. */ | |
1145 | ||
1146 | static reloc_howto_type * | |
1147 | elf64_alpha_bfd_reloc_type_lookup (abfd, code) | |
56fc028e | 1148 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1149 | bfd_reloc_code_real_type code; |
1150 | { | |
1151 | const struct elf_reloc_map *i, *e; | |
1152 | i = e = elf64_alpha_reloc_map; | |
1153 | e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map); | |
1154 | for (; i != e; ++i) | |
1155 | { | |
1156 | if (i->bfd_reloc_val == code) | |
1157 | return &elf64_alpha_howto_table[i->elf_reloc_val]; | |
1158 | } | |
1159 | return 0; | |
1160 | } | |
1161 | ||
1162 | /* Given an Alpha ELF reloc type, fill in an arelent structure. */ | |
1163 | ||
1164 | static void | |
1165 | elf64_alpha_info_to_howto (abfd, cache_ptr, dst) | |
56fc028e | 1166 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1167 | arelent *cache_ptr; |
1168 | Elf64_Internal_Rela *dst; | |
1169 | { | |
1170 | unsigned r_type; | |
1171 | ||
1172 | r_type = ELF64_R_TYPE(dst->r_info); | |
1173 | BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max); | |
1174 | cache_ptr->howto = &elf64_alpha_howto_table[r_type]; | |
1175 | } | |
3765b1be RH |
1176 | |
1177 | /* These two relocations create a two-word entry in the got. */ | |
1178 | #define alpha_got_entry_size(r_type) \ | |
1179 | (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8) | |
9e756d64 RH |
1180 | |
1181 | /* This is PT_TLS segment p_vaddr. */ | |
1182 | #define alpha_get_dtprel_base(tlss) \ | |
1183 | ((tlss)->start) | |
1184 | ||
1185 | /* Main program TLS (whose template starts at PT_TLS p_vaddr) | |
1186 | is assigned offset round(16, PT_TLS p_align). */ | |
1187 | #define alpha_get_tprel_base(tlss) \ | |
1188 | ((tlss)->start - align_power ((bfd_vma) 16, (tlss)->align)) | |
252b5132 | 1189 | \f |
fe8bc63d | 1190 | /* These functions do relaxation for Alpha ELF. |
252b5132 RH |
1191 | |
1192 | Currently I'm only handling what I can do with existing compiler | |
1193 | and assembler support, which means no instructions are removed, | |
1194 | though some may be nopped. At this time GCC does not emit enough | |
1195 | information to do all of the relaxing that is possible. It will | |
1196 | take some not small amount of work for that to happen. | |
1197 | ||
1198 | There are a couple of interesting papers that I once read on this | |
1199 | subject, that I cannot find references to at the moment, that | |
1200 | related to Alpha in particular. They are by David Wall, then of | |
1201 | DEC WRL. */ | |
1202 | ||
1203 | #define OP_LDA 0x08 | |
1204 | #define OP_LDAH 0x09 | |
1205 | #define INSN_JSR 0x68004000 | |
1206 | #define INSN_JSR_MASK 0xfc00c000 | |
1207 | #define OP_LDQ 0x29 | |
1208 | #define OP_BR 0x30 | |
1209 | #define OP_BSR 0x34 | |
f304919d | 1210 | #define INSN_UNOP 0x2ffe0000 |
9e756d64 RH |
1211 | #define INSN_ADDQ 0x40000400 |
1212 | #define INSN_RDUNIQ 0x0000009e | |
252b5132 RH |
1213 | |
1214 | struct alpha_relax_info | |
1215 | { | |
1216 | bfd *abfd; | |
1217 | asection *sec; | |
1218 | bfd_byte *contents; | |
9e756d64 | 1219 | Elf_Internal_Shdr *symtab_hdr; |
252b5132 RH |
1220 | Elf_Internal_Rela *relocs, *relend; |
1221 | struct bfd_link_info *link_info; | |
9e756d64 | 1222 | struct elf_link_tls_segment *tls_segment; |
252b5132 RH |
1223 | bfd_vma gp; |
1224 | bfd *gotobj; | |
1225 | asection *tsec; | |
1226 | struct alpha_elf_link_hash_entry *h; | |
9e756d64 | 1227 | struct alpha_elf_got_entry **first_gotent; |
252b5132 | 1228 | struct alpha_elf_got_entry *gotent; |
9e756d64 RH |
1229 | boolean changed_contents; |
1230 | boolean changed_relocs; | |
252b5132 RH |
1231 | unsigned char other; |
1232 | }; | |
1233 | ||
9e756d64 | 1234 | static boolean elf64_alpha_relax_with_lituse |
fe8bc63d | 1235 | PARAMS((struct alpha_relax_info *info, bfd_vma symval, |
252b5132 | 1236 | Elf_Internal_Rela *irel)); |
252b5132 RH |
1237 | static bfd_vma elf64_alpha_relax_opt_call |
1238 | PARAMS((struct alpha_relax_info *info, bfd_vma symval)); | |
9e756d64 RH |
1239 | static boolean elf64_alpha_relax_got_load |
1240 | PARAMS((struct alpha_relax_info *info, bfd_vma symval, | |
1241 | Elf_Internal_Rela *irel, unsigned long)); | |
1242 | static boolean elf64_alpha_relax_gprelhilo | |
1243 | PARAMS((struct alpha_relax_info *info, bfd_vma symval, | |
1244 | Elf_Internal_Rela *irel, boolean)); | |
1245 | static boolean elf64_alpha_relax_tls_get_addr | |
1246 | PARAMS((struct alpha_relax_info *info, bfd_vma symval, | |
1247 | Elf_Internal_Rela *irel, boolean)); | |
1248 | static struct elf_link_tls_segment *elf64_alpha_relax_find_tls_segment | |
1249 | PARAMS((struct alpha_relax_info *, struct elf_link_tls_segment *)); | |
252b5132 RH |
1250 | static boolean elf64_alpha_relax_section |
1251 | PARAMS((bfd *abfd, asection *sec, struct bfd_link_info *link_info, | |
1252 | boolean *again)); | |
1253 | ||
1254 | static Elf_Internal_Rela * | |
1255 | elf64_alpha_find_reloc_at_ofs (rel, relend, offset, type) | |
1256 | Elf_Internal_Rela *rel, *relend; | |
1257 | bfd_vma offset; | |
1258 | int type; | |
1259 | { | |
1260 | while (rel < relend) | |
1261 | { | |
52b9d213 AM |
1262 | if (rel->r_offset == offset |
1263 | && ELF64_R_TYPE (rel->r_info) == (unsigned int) type) | |
252b5132 RH |
1264 | return rel; |
1265 | ++rel; | |
1266 | } | |
1267 | return NULL; | |
1268 | } | |
1269 | ||
9e756d64 RH |
1270 | static boolean |
1271 | elf64_alpha_relax_with_lituse (info, symval, irel) | |
252b5132 RH |
1272 | struct alpha_relax_info *info; |
1273 | bfd_vma symval; | |
9e756d64 | 1274 | Elf_Internal_Rela *irel; |
252b5132 | 1275 | { |
9e756d64 | 1276 | Elf_Internal_Rela *urel, *irelend = info->relend; |
252b5132 RH |
1277 | int flags, count, i; |
1278 | bfd_signed_vma disp; | |
1279 | boolean fits16; | |
1280 | boolean fits32; | |
1281 | boolean lit_reused = false; | |
1282 | boolean all_optimized = true; | |
1283 | unsigned int lit_insn; | |
1284 | ||
1285 | lit_insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset); | |
1286 | if (lit_insn >> 26 != OP_LDQ) | |
1287 | { | |
1288 | ((*_bfd_error_handler) | |
1289 | ("%s: %s+0x%lx: warning: LITERAL relocation against unexpected insn", | |
8f615d07 AM |
1290 | bfd_archive_filename (info->abfd), info->sec->name, |
1291 | (unsigned long) irel->r_offset)); | |
9e756d64 | 1292 | return true; |
252b5132 RH |
1293 | } |
1294 | ||
9e756d64 RH |
1295 | /* Can't relax dynamic symbols. */ |
1296 | if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info)) | |
1297 | return true; | |
1298 | ||
252b5132 RH |
1299 | /* Summarize how this particular LITERAL is used. */ |
1300 | for (urel = irel+1, flags = count = 0; urel < irelend; ++urel, ++count) | |
1301 | { | |
1302 | if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE) | |
1303 | break; | |
1e738b87 | 1304 | if (urel->r_addend <= 3) |
252b5132 RH |
1305 | flags |= 1 << urel->r_addend; |
1306 | } | |
1307 | ||
fe8bc63d | 1308 | /* A little preparation for the loop... */ |
252b5132 | 1309 | disp = symval - info->gp; |
252b5132 RH |
1310 | |
1311 | for (urel = irel+1, i = 0; i < count; ++i, ++urel) | |
1312 | { | |
1313 | unsigned int insn; | |
ffcb7aff NC |
1314 | int insn_disp; |
1315 | bfd_signed_vma xdisp; | |
1316 | ||
252b5132 RH |
1317 | insn = bfd_get_32 (info->abfd, info->contents + urel->r_offset); |
1318 | ||
1319 | switch (urel->r_addend) | |
1320 | { | |
9e756d64 RH |
1321 | case LITUSE_ALPHA_ADDR: |
1322 | default: | |
252b5132 RH |
1323 | /* This type is really just a placeholder to note that all |
1324 | uses cannot be optimized, but to still allow some. */ | |
1325 | all_optimized = false; | |
1326 | break; | |
1327 | ||
9e756d64 | 1328 | case LITUSE_ALPHA_BASE: |
252b5132 | 1329 | /* We can always optimize 16-bit displacements. */ |
ffcb7aff NC |
1330 | |
1331 | /* Extract the displacement from the instruction, sign-extending | |
1332 | it if necessary, then test whether it is within 16 or 32 bits | |
1333 | displacement from GP. */ | |
1334 | insn_disp = insn & 0x0000ffff; | |
9e756d64 RH |
1335 | if (insn_disp & 0x8000) |
1336 | insn_disp |= ~0xffff; /* Negative: sign-extend. */ | |
ffcb7aff NC |
1337 | |
1338 | xdisp = disp + insn_disp; | |
9e756d64 RH |
1339 | fits16 = (xdisp >= - (bfd_signed_vma) 0x8000 && xdisp < 0x8000); |
1340 | fits32 = (xdisp >= - (bfd_signed_vma) 0x80000000 | |
1341 | && xdisp < 0x7fff8000); | |
ffcb7aff | 1342 | |
252b5132 RH |
1343 | if (fits16) |
1344 | { | |
ffcb7aff | 1345 | /* Take the op code and dest from this insn, take the base |
fe8bc63d | 1346 | register from the literal insn. Leave the offset alone. */ |
ffcb7aff | 1347 | insn = (insn & 0xffe0ffff) | (lit_insn & 0x001f0000); |
252b5132 | 1348 | urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), |
dfe57ca0 | 1349 | R_ALPHA_GPREL16); |
252b5132 RH |
1350 | urel->r_addend = irel->r_addend; |
1351 | info->changed_relocs = true; | |
1352 | ||
dc810e39 AM |
1353 | bfd_put_32 (info->abfd, (bfd_vma) insn, |
1354 | info->contents + urel->r_offset); | |
252b5132 RH |
1355 | info->changed_contents = true; |
1356 | } | |
1357 | ||
1358 | /* If all mem+byte, we can optimize 32-bit mem displacements. */ | |
1359 | else if (fits32 && !(flags & ~6)) | |
1360 | { | |
ffcb7aff | 1361 | /* FIXME: sanity check that lit insn Ra is mem insn Rb. */ |
252b5132 RH |
1362 | |
1363 | irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1364 | R_ALPHA_GPRELHIGH); | |
1365 | lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000); | |
dc810e39 | 1366 | bfd_put_32 (info->abfd, (bfd_vma) lit_insn, |
252b5132 RH |
1367 | info->contents + irel->r_offset); |
1368 | lit_reused = true; | |
1369 | info->changed_contents = true; | |
1370 | ||
1371 | urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1372 | R_ALPHA_GPRELLOW); | |
1373 | urel->r_addend = irel->r_addend; | |
1374 | info->changed_relocs = true; | |
1375 | } | |
1376 | else | |
1377 | all_optimized = false; | |
1378 | break; | |
1379 | ||
9e756d64 | 1380 | case LITUSE_ALPHA_BYTOFF: |
252b5132 RH |
1381 | /* We can always optimize byte instructions. */ |
1382 | ||
1383 | /* FIXME: sanity check the insn for byte op. Check that the | |
1384 | literal dest reg is indeed Rb in the byte insn. */ | |
1385 | ||
dc810e39 AM |
1386 | insn &= ~ (unsigned) 0x001ff000; |
1387 | insn |= ((symval & 7) << 13) | 0x1000; | |
252b5132 RH |
1388 | |
1389 | urel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1390 | urel->r_addend = 0; | |
1391 | info->changed_relocs = true; | |
1392 | ||
dc810e39 AM |
1393 | bfd_put_32 (info->abfd, (bfd_vma) insn, |
1394 | info->contents + urel->r_offset); | |
252b5132 RH |
1395 | info->changed_contents = true; |
1396 | break; | |
1397 | ||
9e756d64 RH |
1398 | case LITUSE_ALPHA_JSR: |
1399 | case LITUSE_ALPHA_TLSGD: | |
1400 | case LITUSE_ALPHA_TLSLDM: | |
252b5132 | 1401 | { |
f44f99a5 | 1402 | bfd_vma optdest, org; |
252b5132 RH |
1403 | bfd_signed_vma odisp; |
1404 | ||
f44f99a5 RH |
1405 | /* If not zero, place to jump without needing pv. */ |
1406 | optdest = elf64_alpha_relax_opt_call (info, symval); | |
1407 | org = (info->sec->output_section->vma | |
1408 | + info->sec->output_offset | |
1409 | + urel->r_offset + 4); | |
252b5132 | 1410 | odisp = (optdest ? optdest : symval) - org; |
f44f99a5 | 1411 | |
252b5132 RH |
1412 | if (odisp >= -0x400000 && odisp < 0x400000) |
1413 | { | |
1414 | Elf_Internal_Rela *xrel; | |
1415 | ||
fe8bc63d | 1416 | /* Preserve branch prediction call stack when possible. */ |
252b5132 RH |
1417 | if ((insn & INSN_JSR_MASK) == INSN_JSR) |
1418 | insn = (OP_BSR << 26) | (insn & 0x03e00000); | |
1419 | else | |
1420 | insn = (OP_BR << 26) | (insn & 0x03e00000); | |
fe8bc63d | 1421 | |
252b5132 RH |
1422 | urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), |
1423 | R_ALPHA_BRADDR); | |
1424 | urel->r_addend = irel->r_addend; | |
1425 | ||
1426 | if (optdest) | |
1427 | urel->r_addend += optdest - symval; | |
1428 | else | |
1429 | all_optimized = false; | |
1430 | ||
dc810e39 AM |
1431 | bfd_put_32 (info->abfd, (bfd_vma) insn, |
1432 | info->contents + urel->r_offset); | |
252b5132 RH |
1433 | |
1434 | /* Kill any HINT reloc that might exist for this insn. */ | |
1435 | xrel = (elf64_alpha_find_reloc_at_ofs | |
fe8bc63d | 1436 | (info->relocs, info->relend, urel->r_offset, |
252b5132 RH |
1437 | R_ALPHA_HINT)); |
1438 | if (xrel) | |
1439 | xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1440 | ||
1441 | info->changed_contents = true; | |
1442 | info->changed_relocs = true; | |
1443 | } | |
1444 | else | |
1445 | all_optimized = false; | |
1446 | ||
1cd6895c RH |
1447 | /* Even if the target is not in range for a direct branch, |
1448 | if we share a GP, we can eliminate the gp reload. */ | |
1449 | if (optdest) | |
1450 | { | |
1451 | Elf_Internal_Rela *gpdisp | |
1452 | = (elf64_alpha_find_reloc_at_ofs | |
9e756d64 RH |
1453 | (info->relocs, irelend, urel->r_offset + 4, |
1454 | R_ALPHA_GPDISP)); | |
1cd6895c RH |
1455 | if (gpdisp) |
1456 | { | |
cedb70c5 | 1457 | bfd_byte *p_ldah = info->contents + gpdisp->r_offset; |
1cd6895c RH |
1458 | bfd_byte *p_lda = p_ldah + gpdisp->r_addend; |
1459 | unsigned int ldah = bfd_get_32 (info->abfd, p_ldah); | |
1460 | unsigned int lda = bfd_get_32 (info->abfd, p_lda); | |
1461 | ||
1462 | /* Verify that the instruction is "ldah $29,0($26)". | |
1463 | Consider a function that ends in a noreturn call, | |
1464 | and that the next function begins with an ldgp, | |
1465 | and that by accident there is no padding between. | |
1466 | In that case the insn would use $27 as the base. */ | |
1467 | if (ldah == 0x27ba0000 && lda == 0x23bd0000) | |
1468 | { | |
dc810e39 AM |
1469 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_ldah); |
1470 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, p_lda); | |
1cd6895c RH |
1471 | |
1472 | gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1473 | info->changed_contents = true; | |
1474 | info->changed_relocs = true; | |
1475 | } | |
1476 | } | |
1477 | } | |
252b5132 RH |
1478 | } |
1479 | break; | |
1480 | } | |
1481 | } | |
1482 | ||
1483 | /* If all cases were optimized, we can reduce the use count on this | |
1484 | got entry by one, possibly eliminating it. */ | |
1485 | if (all_optimized) | |
1486 | { | |
3765b1be RH |
1487 | if (--info->gotent->use_count == 0) |
1488 | { | |
9e756d64 RH |
1489 | int sz = alpha_got_entry_size (R_ALPHA_LITERAL); |
1490 | alpha_elf_tdata (info->gotobj)->total_got_size -= sz; | |
3765b1be | 1491 | if (!info->h) |
9e756d64 | 1492 | alpha_elf_tdata (info->gotobj)->local_got_size -= sz; |
3765b1be | 1493 | } |
252b5132 RH |
1494 | |
1495 | /* If the literal instruction is no longer needed (it may have been | |
3765b1be RH |
1496 | reused. We can eliminate it. */ |
1497 | /* ??? For now, I don't want to deal with compacting the section, | |
252b5132 RH |
1498 | so just nop it out. */ |
1499 | if (!lit_reused) | |
1500 | { | |
1501 | irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1502 | info->changed_relocs = true; | |
1503 | ||
dc810e39 AM |
1504 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, |
1505 | info->contents + irel->r_offset); | |
252b5132 RH |
1506 | info->changed_contents = true; |
1507 | } | |
1508 | } | |
1509 | ||
9e756d64 | 1510 | return true; |
252b5132 RH |
1511 | } |
1512 | ||
1513 | static bfd_vma | |
1514 | elf64_alpha_relax_opt_call (info, symval) | |
1515 | struct alpha_relax_info *info; | |
1516 | bfd_vma symval; | |
1517 | { | |
1518 | /* If the function has the same gp, and we can identify that the | |
1519 | function does not use its function pointer, we can eliminate the | |
1520 | address load. */ | |
1521 | ||
1522 | /* If the symbol is marked NOPV, we are being told the function never | |
1523 | needs its procedure value. */ | |
c810873d | 1524 | if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV) |
252b5132 RH |
1525 | return symval; |
1526 | ||
1527 | /* If the symbol is marked STD_GP, we are being told the function does | |
fe8bc63d | 1528 | a normal ldgp in the first two words. */ |
c810873d | 1529 | else if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD) |
252b5132 RH |
1530 | ; |
1531 | ||
1532 | /* Otherwise, we may be able to identify a GP load in the first two | |
1533 | words, which we can then skip. */ | |
fe8bc63d | 1534 | else |
252b5132 RH |
1535 | { |
1536 | Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp; | |
1537 | bfd_vma ofs; | |
1538 | ||
fe8bc63d | 1539 | /* Load the relocations from the section that the target symbol is in. */ |
252b5132 RH |
1540 | if (info->sec == info->tsec) |
1541 | { | |
1542 | tsec_relocs = info->relocs; | |
1543 | tsec_relend = info->relend; | |
1544 | tsec_free = NULL; | |
1545 | } | |
1546 | else | |
1547 | { | |
1548 | tsec_relocs = (_bfd_elf64_link_read_relocs | |
1549 | (info->abfd, info->tsec, (PTR) NULL, | |
1550 | (Elf_Internal_Rela *) NULL, | |
1551 | info->link_info->keep_memory)); | |
1552 | if (tsec_relocs == NULL) | |
1553 | return 0; | |
1554 | tsec_relend = tsec_relocs + info->tsec->reloc_count; | |
1555 | tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs); | |
1556 | } | |
1557 | ||
1558 | /* Recover the symbol's offset within the section. */ | |
1559 | ofs = (symval - info->tsec->output_section->vma | |
1560 | - info->tsec->output_offset); | |
fe8bc63d | 1561 | |
252b5132 RH |
1562 | /* Look for a GPDISP reloc. */ |
1563 | gpdisp = (elf64_alpha_find_reloc_at_ofs | |
1564 | (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP)); | |
1565 | ||
1566 | if (!gpdisp || gpdisp->r_addend != 4) | |
1567 | { | |
1568 | if (tsec_free) | |
1569 | free (tsec_free); | |
1570 | return 0; | |
1571 | } | |
1572 | if (tsec_free) | |
1573 | free (tsec_free); | |
1574 | } | |
1575 | ||
fe8bc63d | 1576 | /* We've now determined that we can skip an initial gp load. Verify |
252b5132 RH |
1577 | that the call and the target use the same gp. */ |
1578 | if (info->link_info->hash->creator != info->tsec->owner->xvec | |
1579 | || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj) | |
1580 | return 0; | |
1581 | ||
1582 | return symval + 8; | |
1583 | } | |
1584 | ||
1585 | static boolean | |
9e756d64 | 1586 | elf64_alpha_relax_got_load (info, symval, irel, r_type) |
252b5132 RH |
1587 | struct alpha_relax_info *info; |
1588 | bfd_vma symval; | |
1589 | Elf_Internal_Rela *irel; | |
9e756d64 | 1590 | unsigned long r_type; |
252b5132 RH |
1591 | { |
1592 | unsigned int insn; | |
1593 | bfd_signed_vma disp; | |
1594 | ||
1595 | /* Get the instruction. */ | |
1596 | insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset); | |
1597 | ||
1598 | if (insn >> 26 != OP_LDQ) | |
1599 | { | |
9e756d64 | 1600 | reloc_howto_type *howto = elf64_alpha_howto_table + r_type; |
252b5132 | 1601 | ((*_bfd_error_handler) |
9e756d64 | 1602 | ("%s: %s+0x%lx: warning: %s relocation against unexpected insn", |
8f615d07 | 1603 | bfd_archive_filename (info->abfd), info->sec->name, |
9e756d64 | 1604 | (unsigned long) irel->r_offset, howto->name)); |
252b5132 RH |
1605 | return true; |
1606 | } | |
1607 | ||
9e756d64 RH |
1608 | /* Can't relax dynamic symbols. */ |
1609 | if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info)) | |
1610 | return true; | |
252b5132 | 1611 | |
9e756d64 RH |
1612 | /* Can't use local-exec relocations in shared libraries. */ |
1613 | if (r_type == R_ALPHA_GOTTPREL && info->link_info->shared) | |
252b5132 RH |
1614 | return true; |
1615 | ||
9e756d64 RH |
1616 | if (r_type == R_ALPHA_LITERAL) |
1617 | disp = symval - info->gp; | |
1618 | else | |
1619 | { | |
1620 | bfd_vma dtp_base, tp_base; | |
1621 | ||
1622 | BFD_ASSERT (info->tls_segment != NULL); | |
1623 | dtp_base = alpha_get_dtprel_base (info->tls_segment); | |
1624 | tp_base = alpha_get_tprel_base (info->tls_segment); | |
1625 | disp = symval - (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base); | |
1626 | } | |
252b5132 | 1627 | |
9e756d64 RH |
1628 | if (disp < -0x8000 || disp >= 0x8000) |
1629 | return true; | |
1630 | ||
1631 | /* Exchange LDQ for LDA. In the case of the TLS relocs, we're loading | |
1632 | a constant, so force the base register to be $31. */ | |
1633 | if (r_type == R_ALPHA_LITERAL) | |
1634 | insn = (OP_LDA << 26) | (insn & 0x03ff0000); | |
1635 | else | |
1636 | insn = (OP_LDA << 26) | (insn & (31 << 21)) | (31 << 16); | |
dc810e39 | 1637 | bfd_put_32 (info->abfd, (bfd_vma) insn, info->contents + irel->r_offset); |
252b5132 | 1638 | info->changed_contents = true; |
cedb70c5 | 1639 | |
9e756d64 RH |
1640 | switch (r_type) |
1641 | { | |
1642 | case R_ALPHA_LITERAL: | |
1643 | r_type = R_ALPHA_GPREL16; | |
1644 | break; | |
1645 | case R_ALPHA_GOTDTPREL: | |
1646 | r_type = R_ALPHA_DTPREL16; | |
1647 | break; | |
1648 | case R_ALPHA_GOTTPREL: | |
1649 | r_type = R_ALPHA_TPREL16; | |
1650 | break; | |
1651 | default: | |
1652 | BFD_ASSERT (0); | |
1653 | return false; | |
1654 | } | |
252b5132 | 1655 | |
9e756d64 | 1656 | irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), r_type); |
252b5132 RH |
1657 | info->changed_relocs = true; |
1658 | ||
1659 | /* Reduce the use count on this got entry by one, possibly | |
1660 | eliminating it. */ | |
3765b1be RH |
1661 | if (--info->gotent->use_count == 0) |
1662 | { | |
9e756d64 RH |
1663 | int sz = alpha_got_entry_size (r_type); |
1664 | alpha_elf_tdata (info->gotobj)->total_got_size -= sz; | |
3765b1be | 1665 | if (!info->h) |
9e756d64 | 1666 | alpha_elf_tdata (info->gotobj)->local_got_size -= sz; |
3765b1be | 1667 | } |
252b5132 RH |
1668 | |
1669 | /* ??? Search forward through this basic block looking for insns | |
1670 | that use the target register. Stop after an insn modifying the | |
1671 | register is seen, or after a branch or call. | |
1672 | ||
1673 | Any such memory load insn may be substituted by a load directly | |
1674 | off the GP. This allows the memory load insn to be issued before | |
fe8bc63d | 1675 | the calculated GP register would otherwise be ready. |
252b5132 RH |
1676 | |
1677 | Any such jsr insn can be replaced by a bsr if it is in range. | |
1678 | ||
1679 | This would mean that we'd have to _add_ relocations, the pain of | |
1680 | which gives one pause. */ | |
1681 | ||
1682 | return true; | |
1683 | } | |
1684 | ||
9e756d64 RH |
1685 | static boolean |
1686 | elf64_alpha_relax_gprelhilo (info, symval, irel, hi) | |
1687 | struct alpha_relax_info *info; | |
1688 | bfd_vma symval; | |
1689 | Elf_Internal_Rela *irel; | |
1690 | boolean hi; | |
1691 | { | |
1692 | unsigned int insn; | |
1693 | bfd_signed_vma disp; | |
1694 | bfd_byte *pos = info->contents + irel->r_offset; | |
1695 | ||
1696 | /* ??? This assumes that the compiler doesn't render | |
1697 | ||
1698 | array[i] | |
1699 | as | |
1700 | ldah t, array(gp) !gprelhigh | |
1701 | s8addl i, t, t | |
1702 | ldq r, array(t) !gprellow | |
1703 | ||
1704 | which would indeed be the most efficient way to implement this. */ | |
1705 | ||
1706 | return true; | |
1707 | ||
1708 | disp = symval - info->gp; | |
1709 | if (disp < -0x8000 || disp >= 0x8000) | |
1710 | return true; | |
1711 | ||
1712 | if (hi) | |
1713 | { | |
1714 | /* Nop out the high instruction. */ | |
1715 | ||
1716 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos); | |
1717 | info->changed_contents = true; | |
1718 | ||
1719 | irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1720 | irel->r_addend = 0; | |
1721 | info->changed_relocs = true; | |
1722 | } | |
1723 | else | |
1724 | { | |
1725 | /* Adjust the low instruction to reference GP directly. */ | |
1726 | ||
1727 | insn = bfd_get_32 (info->abfd, pos); | |
1728 | insn = (insn & 0xffe00000) | (29 << 16); | |
1729 | bfd_put_32 (info->abfd, (bfd_vma) insn, pos); | |
1730 | info->changed_contents = true; | |
1731 | ||
1732 | irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1733 | R_ALPHA_GPREL16); | |
1734 | info->changed_relocs = true; | |
1735 | } | |
1736 | ||
1737 | return true; | |
1738 | } | |
1739 | ||
1740 | static boolean | |
1741 | elf64_alpha_relax_tls_get_addr (info, symval, irel, is_gd) | |
1742 | struct alpha_relax_info *info; | |
1743 | bfd_vma symval; | |
1744 | Elf_Internal_Rela *irel; | |
1745 | boolean is_gd; | |
1746 | { | |
1747 | bfd_byte *pos[5]; | |
1748 | unsigned int insn; | |
1749 | Elf_Internal_Rela *gpdisp, *hint; | |
1750 | boolean dynamic, use_gottprel; | |
1751 | ||
1752 | dynamic = alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info); | |
1753 | ||
1754 | /* ??? For LD relaxation, we need a symbol referencing the beginning | |
1755 | of the TLS segment. */ | |
1756 | if (!is_gd) | |
1757 | return true; | |
1758 | ||
1759 | /* If a TLS symbol is accessed using IE at least once, there is no point | |
1760 | to use dynamic model for it. */ | |
1761 | if (is_gd && info->h && (info->h->flags & ALPHA_ELF_LINK_HASH_TLS_IE)) | |
1762 | ; | |
1763 | ||
1764 | /* If the symbol is local, and we've already committed to DF_STATIC_TLS, | |
1765 | then we might as well relax to IE. */ | |
1766 | else if (info->link_info->shared && !dynamic | |
1767 | && (info->link_info->flags & DF_STATIC_TLS)) | |
1768 | ; | |
1769 | ||
1770 | /* Otherwise we must be building an executable to do anything. */ | |
1771 | else if (info->link_info->shared) | |
1772 | return true; | |
1773 | ||
1774 | /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and | |
1775 | the matching LITUSE_TLS relocations. */ | |
1776 | if (irel + 2 >= info->relend) | |
1777 | return true; | |
1778 | if (ELF64_R_TYPE (irel[1].r_info) != R_ALPHA_LITERAL | |
1779 | || ELF64_R_TYPE (irel[2].r_info) != R_ALPHA_LITUSE | |
1780 | || irel[2].r_addend != (is_gd ? LITUSE_ALPHA_TLSGD : LITUSE_ALPHA_TLSLDM)) | |
1781 | return true; | |
1782 | ||
1783 | /* There must be a GPDISP relocation positioned immediately after the | |
1784 | LITUSE relocation. */ | |
1785 | gpdisp = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend, | |
1786 | irel[2].r_offset + 4, R_ALPHA_GPDISP); | |
1787 | if (!gpdisp) | |
1788 | return true; | |
1789 | ||
1790 | pos[0] = info->contents + irel[0].r_offset; | |
1791 | pos[1] = info->contents + irel[1].r_offset; | |
1792 | pos[2] = info->contents + irel[2].r_offset; | |
1793 | pos[3] = info->contents + gpdisp->r_offset; | |
1794 | pos[4] = pos[3] + gpdisp->r_addend; | |
1795 | ||
1796 | /* Only positions 0 and 1 are allowed to be out of order. */ | |
1797 | if (pos[1] < pos[0]) | |
1798 | { | |
1799 | bfd_byte *tmp = pos[0]; | |
1800 | pos[0] = pos[1]; | |
1801 | pos[1] = tmp; | |
1802 | } | |
1803 | if (pos[1] >= pos[2] || pos[2] >= pos[3] || pos[3] >= pos[4]) | |
1804 | return true; | |
1805 | ||
1806 | /* Reduce the use count on the LITERAL relocation. Do this before we | |
1807 | smash the symndx when we adjust the relocations below. */ | |
1808 | { | |
1809 | struct alpha_elf_got_entry *lit_gotent; | |
1810 | struct alpha_elf_link_hash_entry *lit_h; | |
1811 | unsigned long indx; | |
1812 | ||
1813 | BFD_ASSERT (ELF64_R_SYM (irel[1].r_info) >= info->symtab_hdr->sh_info); | |
1814 | indx = ELF64_R_SYM (irel[1].r_info) - info->symtab_hdr->sh_info; | |
1815 | lit_h = alpha_elf_sym_hashes (info->abfd)[indx]; | |
1816 | ||
1817 | while (lit_h->root.root.type == bfd_link_hash_indirect | |
1818 | || lit_h->root.root.type == bfd_link_hash_warning) | |
1819 | lit_h = (struct alpha_elf_link_hash_entry *) lit_h->root.root.u.i.link; | |
1820 | ||
1821 | for (lit_gotent = lit_h->got_entries; lit_gotent ; | |
1822 | lit_gotent = lit_gotent->next) | |
1823 | if (lit_gotent->gotobj == info->gotobj | |
1824 | && lit_gotent->reloc_type == R_ALPHA_LITERAL | |
1825 | && lit_gotent->addend == irel[1].r_addend) | |
1826 | break; | |
1827 | BFD_ASSERT (lit_gotent); | |
1828 | ||
1829 | if (--lit_gotent->use_count == 0) | |
1830 | { | |
1831 | int sz = alpha_got_entry_size (R_ALPHA_LITERAL); | |
1832 | alpha_elf_tdata (info->gotobj)->total_got_size -= sz; | |
1833 | } | |
1834 | } | |
1835 | ||
1836 | /* Change | |
1837 | ||
1838 | lda $16,x($gp) !tlsgd!1 | |
1839 | ldq $27,__tls_get_addr($gp) !literal!1 | |
1840 | jsr $26,($27)__tls_get_addr !lituse_tlsgd!1 | |
1841 | ldah $29,0($26) !gpdisp!2 | |
1842 | lda $29,0($29) !gpdisp!2 | |
1843 | to | |
1844 | ldq $16,x($gp) !gottprel | |
1845 | unop | |
1846 | call_pal rduniq | |
1847 | addq $16,$0,$0 | |
1848 | unop | |
1849 | or the first pair to | |
1850 | lda $16,x($gp) !tprel | |
1851 | unop | |
1852 | or | |
1853 | ldah $16,x($gp) !tprelhi | |
1854 | lda $16,x($16) !tprello | |
1855 | ||
1856 | as appropriate. */ | |
1857 | ||
1858 | use_gottprel = false; | |
1859 | switch (!dynamic && !info->link_info->shared) | |
1860 | { | |
1861 | case 1: | |
1862 | { | |
1863 | bfd_vma tp_base; | |
1864 | bfd_signed_vma disp; | |
1865 | ||
1866 | BFD_ASSERT (info->tls_segment != NULL); | |
1867 | tp_base = alpha_get_tprel_base (info->tls_segment); | |
1868 | disp = symval - tp_base; | |
1869 | ||
1870 | if (disp >= -0x8000 && disp < 0x8000) | |
1871 | { | |
1872 | insn = (OP_LDA << 26) | (16 << 21) | (31 << 16); | |
1873 | bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]); | |
1874 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]); | |
1875 | ||
1876 | irel[0].r_offset = pos[0] - info->contents; | |
1877 | irel[0].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1878 | R_ALPHA_TPREL16); | |
1879 | irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1880 | break; | |
1881 | } | |
1882 | else if (disp >= -(bfd_signed_vma) 0x80000000 | |
1883 | && disp < (bfd_signed_vma) 0x7fff8000) | |
1884 | { | |
1885 | insn = (OP_LDAH << 26) | (16 << 21) | (31 << 16); | |
1886 | bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]); | |
1887 | insn = (OP_LDA << 26) | (16 << 21) | (16 << 16); | |
1888 | bfd_put_32 (info->abfd, (bfd_vma) insn, pos[1]); | |
1889 | ||
1890 | irel[0].r_offset = pos[0] - info->contents; | |
1891 | irel[0].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1892 | R_ALPHA_TPRELHI); | |
1893 | irel[1].r_offset = pos[1] - info->contents; | |
1894 | irel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1895 | R_ALPHA_TPRELLO); | |
1896 | break; | |
1897 | } | |
1898 | } | |
1899 | /* FALLTHRU */ | |
1900 | ||
1901 | default: | |
1902 | use_gottprel = true; | |
1903 | ||
1904 | insn = (OP_LDQ << 26) | (16 << 21) | (29 << 16); | |
1905 | bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]); | |
1906 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]); | |
1907 | ||
1908 | irel[0].r_offset = pos[0] - info->contents; | |
1909 | irel[0].r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), | |
1910 | R_ALPHA_GOTTPREL); | |
1911 | irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1912 | break; | |
1913 | } | |
1914 | ||
1915 | bfd_put_32 (info->abfd, (bfd_vma) INSN_RDUNIQ, pos[2]); | |
1916 | ||
1917 | insn = INSN_ADDQ | (16 << 21) | (0 << 16) | (0 << 0); | |
1918 | bfd_put_32 (info->abfd, (bfd_vma) insn, pos[3]); | |
1919 | ||
1920 | bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[4]); | |
1921 | ||
1922 | irel[2].r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1923 | gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1924 | ||
1925 | hint = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend, | |
1926 | irel[2].r_offset, R_ALPHA_HINT); | |
1927 | if (hint) | |
1928 | hint->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); | |
1929 | ||
1930 | info->changed_contents = true; | |
1931 | info->changed_relocs = true; | |
1932 | ||
1933 | /* Reduce the use count on the TLSGD/TLSLDM relocation. */ | |
1934 | if (--info->gotent->use_count == 0) | |
1935 | { | |
1936 | int sz = alpha_got_entry_size (info->gotent->reloc_type); | |
1937 | alpha_elf_tdata (info->gotobj)->total_got_size -= sz; | |
1938 | if (!info->h) | |
1939 | alpha_elf_tdata (info->gotobj)->local_got_size -= sz; | |
1940 | } | |
1941 | ||
1942 | /* If we've switched to a GOTTPREL relocation, increment the reference | |
1943 | count on that got entry. */ | |
1944 | if (use_gottprel) | |
1945 | { | |
1946 | struct alpha_elf_got_entry *tprel_gotent; | |
1947 | ||
1948 | for (tprel_gotent = *info->first_gotent; tprel_gotent ; | |
1949 | tprel_gotent = tprel_gotent->next) | |
1950 | if (tprel_gotent->gotobj == info->gotobj | |
1951 | && tprel_gotent->reloc_type == R_ALPHA_GOTTPREL | |
1952 | && tprel_gotent->addend == irel->r_addend) | |
1953 | break; | |
1954 | if (tprel_gotent) | |
1955 | tprel_gotent->use_count++; | |
1956 | else | |
1957 | { | |
1958 | if (info->gotent->use_count == 0) | |
1959 | tprel_gotent = info->gotent; | |
1960 | else | |
1961 | { | |
1962 | tprel_gotent = (struct alpha_elf_got_entry *) | |
1963 | bfd_alloc (info->abfd, sizeof (struct alpha_elf_got_entry)); | |
1964 | if (!tprel_gotent) | |
1965 | return false; | |
1966 | ||
1967 | tprel_gotent->next = *info->first_gotent; | |
1968 | *info->first_gotent = tprel_gotent; | |
1969 | ||
1970 | tprel_gotent->gotobj = info->gotobj; | |
1971 | tprel_gotent->addend = irel->r_addend; | |
1972 | tprel_gotent->got_offset = -1; | |
1973 | tprel_gotent->reloc_done = 0; | |
1974 | tprel_gotent->reloc_xlated = 0; | |
1975 | } | |
1976 | ||
1977 | tprel_gotent->use_count = 1; | |
1978 | tprel_gotent->reloc_type = R_ALPHA_GOTTPREL; | |
1979 | } | |
1980 | } | |
1981 | ||
1982 | return true; | |
1983 | } | |
1984 | ||
1985 | static struct elf_link_tls_segment * | |
1986 | elf64_alpha_relax_find_tls_segment (info, seg) | |
1987 | struct alpha_relax_info *info; | |
1988 | struct elf_link_tls_segment *seg; | |
1989 | { | |
1990 | bfd *output_bfd = info->sec->output_section->owner; | |
048d873d | 1991 | asection *o; |
9e756d64 RH |
1992 | unsigned int align; |
1993 | bfd_vma base, end; | |
1994 | ||
1995 | for (o = output_bfd->sections; o ; o = o->next) | |
1996 | if ((o->flags & SEC_THREAD_LOCAL) != 0 | |
1997 | && (o->flags & SEC_LOAD) != 0) | |
048d873d RH |
1998 | break; |
1999 | if (!o) | |
9e756d64 RH |
2000 | return NULL; |
2001 | ||
048d873d | 2002 | base = o->vma; |
9e756d64 RH |
2003 | align = 0; |
2004 | ||
048d873d | 2005 | do |
9e756d64 RH |
2006 | { |
2007 | bfd_vma size; | |
2008 | ||
2009 | if (bfd_get_section_alignment (output_bfd, o) > align) | |
2010 | align = bfd_get_section_alignment (output_bfd, o); | |
2011 | ||
2012 | size = o->_raw_size; | |
2013 | if (size == 0 && (o->flags & SEC_HAS_CONTENTS) == 0) | |
2014 | { | |
2015 | struct bfd_link_order *lo; | |
2016 | for (lo = o->link_order_head; lo ; lo = lo->next) | |
2017 | if (size < lo->offset + lo->size) | |
2018 | size = lo->offset + lo->size; | |
2019 | } | |
2020 | end = o->vma + size; | |
048d873d | 2021 | o = o->next; |
9e756d64 | 2022 | } |
048d873d | 2023 | while (o && (o->flags & SEC_THREAD_LOCAL)); |
9e756d64 RH |
2024 | |
2025 | seg->start = base; | |
2026 | seg->size = end - base; | |
2027 | seg->align = align; | |
2028 | ||
2029 | return seg; | |
2030 | } | |
2031 | ||
252b5132 RH |
2032 | static boolean |
2033 | elf64_alpha_relax_section (abfd, sec, link_info, again) | |
2034 | bfd *abfd; | |
2035 | asection *sec; | |
2036 | struct bfd_link_info *link_info; | |
2037 | boolean *again; | |
2038 | { | |
2039 | Elf_Internal_Shdr *symtab_hdr; | |
2040 | Elf_Internal_Rela *internal_relocs; | |
252b5132 | 2041 | Elf_Internal_Rela *irel, *irelend; |
6cdc0ccc | 2042 | Elf_Internal_Sym *isymbuf = NULL; |
252b5132 RH |
2043 | struct alpha_elf_got_entry **local_got_entries; |
2044 | struct alpha_relax_info info; | |
9e756d64 | 2045 | struct elf_link_tls_segment tls_segment; |
252b5132 RH |
2046 | |
2047 | /* We are not currently changing any sizes, so only one pass. */ | |
2048 | *again = false; | |
2049 | ||
2050 | if (link_info->relocateable | |
2051 | || (sec->flags & SEC_RELOC) == 0 | |
2052 | || sec->reloc_count == 0) | |
2053 | return true; | |
2054 | ||
2055 | /* If this is the first time we have been called for this section, | |
2056 | initialize the cooked size. */ | |
2057 | if (sec->_cooked_size == 0) | |
2058 | sec->_cooked_size = sec->_raw_size; | |
2059 | ||
2060 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2061 | local_got_entries = alpha_elf_tdata(abfd)->local_got_entries; | |
2062 | ||
2063 | /* Load the relocations for this section. */ | |
2064 | internal_relocs = (_bfd_elf64_link_read_relocs | |
2065 | (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, | |
2066 | link_info->keep_memory)); | |
2067 | if (internal_relocs == NULL) | |
6cdc0ccc | 2068 | return false; |
252b5132 | 2069 | |
fe8bc63d | 2070 | memset(&info, 0, sizeof (info)); |
252b5132 RH |
2071 | info.abfd = abfd; |
2072 | info.sec = sec; | |
2073 | info.link_info = link_info; | |
9e756d64 | 2074 | info.symtab_hdr = symtab_hdr; |
252b5132 RH |
2075 | info.relocs = internal_relocs; |
2076 | info.relend = irelend = internal_relocs + sec->reloc_count; | |
2077 | ||
cedb70c5 | 2078 | /* Find the GP for this object. Do not store the result back via |
b646261c | 2079 | _bfd_set_gp_value, since this could change again before final. */ |
252b5132 RH |
2080 | info.gotobj = alpha_elf_tdata (abfd)->gotobj; |
2081 | if (info.gotobj) | |
2082 | { | |
2083 | asection *sgot = alpha_elf_tdata (info.gotobj)->got; | |
b646261c RH |
2084 | info.gp = (sgot->output_section->vma |
2085 | + sgot->output_offset | |
2086 | + 0x8000); | |
252b5132 RH |
2087 | } |
2088 | ||
9e756d64 RH |
2089 | /* Get the section contents. */ |
2090 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2091 | info.contents = elf_section_data (sec)->this_hdr.contents; | |
2092 | else | |
252b5132 | 2093 | { |
9e756d64 | 2094 | info.contents = (bfd_byte *) bfd_malloc (sec->_raw_size); |
252b5132 | 2095 | if (info.contents == NULL) |
9e756d64 | 2096 | goto error_return; |
252b5132 | 2097 | |
9e756d64 RH |
2098 | if (! bfd_get_section_contents (abfd, sec, info.contents, |
2099 | (file_ptr) 0, sec->_raw_size)) | |
2100 | goto error_return; | |
2101 | } | |
252b5132 | 2102 | |
9e756d64 RH |
2103 | /* Compute the TLS segment information. The version normally found in |
2104 | elf_hash_table (link_info)->tls_segment isn't built until final_link. | |
2105 | ??? Probably should look into extracting this into a common function. */ | |
2106 | info.tls_segment = elf64_alpha_relax_find_tls_segment (&info, &tls_segment); | |
2107 | ||
2108 | for (irel = internal_relocs; irel < irelend; irel++) | |
2109 | { | |
2110 | bfd_vma symval; | |
9e756d64 RH |
2111 | struct alpha_elf_got_entry *gotent; |
2112 | unsigned long r_type = ELF64_R_TYPE (irel->r_info); | |
2113 | ||
2114 | /* Early exit for unhandled or unrelaxable relocations. */ | |
2115 | switch (r_type) | |
2116 | { | |
2117 | case R_ALPHA_LITERAL: | |
2118 | case R_ALPHA_GPRELHIGH: | |
2119 | case R_ALPHA_GPRELLOW: | |
2120 | case R_ALPHA_GOTDTPREL: | |
2121 | case R_ALPHA_GOTTPREL: | |
2122 | case R_ALPHA_TLSGD: | |
2123 | case R_ALPHA_TLSLDM: | |
2124 | break; | |
2125 | default: | |
2126 | continue; | |
252b5132 RH |
2127 | } |
2128 | ||
2129 | /* Get the value of the symbol referred to by the reloc. */ | |
2130 | if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info) | |
2131 | { | |
2132 | /* A local symbol. */ | |
6cdc0ccc AM |
2133 | Elf_Internal_Sym *isym; |
2134 | ||
2135 | /* Read this BFD's local symbols. */ | |
2136 | if (isymbuf == NULL) | |
2137 | { | |
2138 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
2139 | if (isymbuf == NULL) | |
2140 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
2141 | symtab_hdr->sh_info, 0, | |
2142 | NULL, NULL, NULL); | |
2143 | if (isymbuf == NULL) | |
2144 | goto error_return; | |
2145 | } | |
2146 | ||
2147 | isym = isymbuf + ELF64_R_SYM (irel->r_info); | |
2148 | if (isym->st_shndx == SHN_UNDEF) | |
4a67a098 | 2149 | continue; |
6cdc0ccc | 2150 | else if (isym->st_shndx == SHN_ABS) |
252b5132 | 2151 | info.tsec = bfd_abs_section_ptr; |
6cdc0ccc | 2152 | else if (isym->st_shndx == SHN_COMMON) |
252b5132 | 2153 | info.tsec = bfd_com_section_ptr; |
fe8bc63d | 2154 | else |
6cdc0ccc | 2155 | info.tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
252b5132 RH |
2156 | |
2157 | info.h = NULL; | |
6cdc0ccc | 2158 | info.other = isym->st_other; |
9e756d64 | 2159 | info.first_gotent = &local_got_entries[ELF64_R_SYM(irel->r_info)]; |
6cdc0ccc | 2160 | symval = isym->st_value; |
252b5132 RH |
2161 | } |
2162 | else | |
2163 | { | |
2164 | unsigned long indx; | |
2165 | struct alpha_elf_link_hash_entry *h; | |
2166 | ||
2167 | indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info; | |
2168 | h = alpha_elf_sym_hashes (abfd)[indx]; | |
2169 | BFD_ASSERT (h != NULL); | |
2170 | ||
2171 | while (h->root.root.type == bfd_link_hash_indirect | |
2172 | || h->root.root.type == bfd_link_hash_warning) | |
2173 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; | |
2174 | ||
4a67a098 RH |
2175 | /* If the symbol is undefined, we can't do anything with it. */ |
2176 | if (h->root.root.type == bfd_link_hash_undefweak | |
2177 | || h->root.root.type == bfd_link_hash_undefined) | |
2178 | continue; | |
2179 | ||
2180 | /* If the symbol isn't defined in the current module, again | |
2181 | we can't do anything. */ | |
2182 | if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
2183 | continue; | |
2184 | ||
252b5132 | 2185 | info.h = h; |
252b5132 RH |
2186 | info.tsec = h->root.root.u.def.section; |
2187 | info.other = h->root.other; | |
9e756d64 | 2188 | info.first_gotent = &h->got_entries; |
252b5132 RH |
2189 | symval = h->root.root.u.def.value; |
2190 | } | |
2191 | ||
2192 | /* Search for the got entry to be used by this relocation. */ | |
9e756d64 RH |
2193 | for (gotent = *info.first_gotent; gotent ; gotent = gotent->next) |
2194 | if (gotent->gotobj == info.gotobj | |
2195 | && gotent->reloc_type == r_type | |
2196 | && gotent->addend == irel->r_addend) | |
2197 | break; | |
252b5132 RH |
2198 | info.gotent = gotent; |
2199 | ||
2200 | symval += info.tsec->output_section->vma + info.tsec->output_offset; | |
2201 | symval += irel->r_addend; | |
2202 | ||
9e756d64 RH |
2203 | switch (r_type) |
2204 | { | |
2205 | case R_ALPHA_LITERAL: | |
2206 | BFD_ASSERT(info.gotent != NULL); | |
252b5132 | 2207 | |
9e756d64 RH |
2208 | /* If there exist LITUSE relocations immediately following, this |
2209 | opens up all sorts of interesting optimizations, because we | |
2210 | now know every location that this address load is used. */ | |
2211 | if (irel+1 < irelend | |
2212 | && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE) | |
2213 | { | |
2214 | if (!elf64_alpha_relax_with_lituse (&info, symval, irel)) | |
2215 | goto error_return; | |
2216 | } | |
2217 | else | |
2218 | { | |
2219 | if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type)) | |
2220 | goto error_return; | |
2221 | } | |
2222 | break; | |
252b5132 | 2223 | |
9e756d64 RH |
2224 | case R_ALPHA_GPRELHIGH: |
2225 | case R_ALPHA_GPRELLOW: | |
2226 | if (!elf64_alpha_relax_gprelhilo (&info, symval, irel, | |
2227 | r_type == R_ALPHA_GPRELHIGH)) | |
252b5132 | 2228 | goto error_return; |
9e756d64 RH |
2229 | break; |
2230 | ||
2231 | case R_ALPHA_GOTDTPREL: | |
2232 | case R_ALPHA_GOTTPREL: | |
2233 | BFD_ASSERT(info.gotent != NULL); | |
2234 | if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type)) | |
252b5132 | 2235 | goto error_return; |
9e756d64 RH |
2236 | break; |
2237 | ||
2238 | case R_ALPHA_TLSGD: | |
2239 | case R_ALPHA_TLSLDM: | |
2240 | BFD_ASSERT(info.gotent != NULL); | |
2241 | if (!elf64_alpha_relax_tls_get_addr (&info, symval, irel, | |
2242 | r_type == R_ALPHA_TLSGD)) | |
2243 | goto error_return; | |
2244 | break; | |
252b5132 RH |
2245 | } |
2246 | } | |
2247 | ||
f44f99a5 RH |
2248 | if (!elf64_alpha_size_plt_section (link_info)) |
2249 | return false; | |
2250 | if (!elf64_alpha_size_got_sections (link_info)) | |
2251 | return false; | |
2252 | if (!elf64_alpha_size_rela_got_section (link_info)) | |
252b5132 RH |
2253 | return false; |
2254 | ||
6cdc0ccc AM |
2255 | if (isymbuf != NULL |
2256 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
2257 | { | |
2258 | if (!link_info->keep_memory) | |
2259 | free (isymbuf); | |
2260 | else | |
2261 | { | |
2262 | /* Cache the symbols for elf_link_input_bfd. */ | |
2263 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
2264 | } | |
2265 | } | |
252b5132 | 2266 | |
6cdc0ccc AM |
2267 | if (info.contents != NULL |
2268 | && elf_section_data (sec)->this_hdr.contents != info.contents) | |
252b5132 | 2269 | { |
6cdc0ccc AM |
2270 | if (!info.changed_contents && !link_info->keep_memory) |
2271 | free (info.contents); | |
252b5132 RH |
2272 | else |
2273 | { | |
2274 | /* Cache the section contents for elf_link_input_bfd. */ | |
2275 | elf_section_data (sec)->this_hdr.contents = info.contents; | |
2276 | } | |
2277 | } | |
2278 | ||
6cdc0ccc | 2279 | if (elf_section_data (sec)->relocs != internal_relocs) |
252b5132 | 2280 | { |
6cdc0ccc AM |
2281 | if (!info.changed_relocs) |
2282 | free (internal_relocs); | |
252b5132 | 2283 | else |
6cdc0ccc | 2284 | elf_section_data (sec)->relocs = internal_relocs; |
252b5132 RH |
2285 | } |
2286 | ||
2287 | *again = info.changed_contents || info.changed_relocs; | |
2288 | ||
2289 | return true; | |
2290 | ||
2291 | error_return: | |
6cdc0ccc AM |
2292 | if (isymbuf != NULL |
2293 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
2294 | free (isymbuf); | |
2295 | if (info.contents != NULL | |
2296 | && elf_section_data (sec)->this_hdr.contents != info.contents) | |
2297 | free (info.contents); | |
2298 | if (internal_relocs != NULL | |
2299 | && elf_section_data (sec)->relocs != internal_relocs) | |
2300 | free (internal_relocs); | |
252b5132 RH |
2301 | return false; |
2302 | } | |
2303 | \f | |
2304 | /* PLT/GOT Stuff */ | |
2305 | #define PLT_HEADER_SIZE 32 | |
dc810e39 AM |
2306 | #define PLT_HEADER_WORD1 (bfd_vma) 0xc3600000 /* br $27,.+4 */ |
2307 | #define PLT_HEADER_WORD2 (bfd_vma) 0xa77b000c /* ldq $27,12($27) */ | |
2308 | #define PLT_HEADER_WORD3 (bfd_vma) 0x47ff041f /* nop */ | |
2309 | #define PLT_HEADER_WORD4 (bfd_vma) 0x6b7b0000 /* jmp $27,($27) */ | |
252b5132 RH |
2310 | |
2311 | #define PLT_ENTRY_SIZE 12 | |
2312 | #define PLT_ENTRY_WORD1 0xc3800000 /* br $28, plt0 */ | |
2313 | #define PLT_ENTRY_WORD2 0 | |
2314 | #define PLT_ENTRY_WORD3 0 | |
2315 | ||
3765b1be | 2316 | #define MAX_GOT_SIZE (64*1024) |
252b5132 RH |
2317 | |
2318 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so" | |
2319 | \f | |
2320 | /* Handle an Alpha specific section when reading an object file. This | |
2321 | is called when elfcode.h finds a section with an unknown type. | |
2322 | FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure | |
2323 | how to. */ | |
2324 | ||
2325 | static boolean | |
2326 | elf64_alpha_section_from_shdr (abfd, hdr, name) | |
2327 | bfd *abfd; | |
2328 | Elf64_Internal_Shdr *hdr; | |
90937f86 | 2329 | const char *name; |
252b5132 RH |
2330 | { |
2331 | asection *newsect; | |
2332 | ||
2333 | /* There ought to be a place to keep ELF backend specific flags, but | |
2334 | at the moment there isn't one. We just keep track of the | |
2335 | sections by their name, instead. Fortunately, the ABI gives | |
2336 | suggested names for all the MIPS specific sections, so we will | |
2337 | probably get away with this. */ | |
2338 | switch (hdr->sh_type) | |
2339 | { | |
2340 | case SHT_ALPHA_DEBUG: | |
2341 | if (strcmp (name, ".mdebug") != 0) | |
2342 | return false; | |
2343 | break; | |
252b5132 RH |
2344 | default: |
2345 | return false; | |
2346 | } | |
2347 | ||
2348 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | |
2349 | return false; | |
2350 | newsect = hdr->bfd_section; | |
2351 | ||
2352 | if (hdr->sh_type == SHT_ALPHA_DEBUG) | |
2353 | { | |
2354 | if (! bfd_set_section_flags (abfd, newsect, | |
2355 | (bfd_get_section_flags (abfd, newsect) | |
2356 | | SEC_DEBUGGING))) | |
2357 | return false; | |
2358 | } | |
2359 | ||
252b5132 RH |
2360 | return true; |
2361 | } | |
2362 | ||
204692d7 RH |
2363 | /* Convert Alpha specific section flags to bfd internal section flags. */ |
2364 | ||
2365 | static boolean | |
2366 | elf64_alpha_section_flags (flags, hdr) | |
2367 | flagword *flags; | |
2368 | Elf64_Internal_Shdr *hdr; | |
2369 | { | |
2370 | if (hdr->sh_flags & SHF_ALPHA_GPREL) | |
2371 | *flags |= SEC_SMALL_DATA; | |
2372 | ||
2373 | return true; | |
2374 | } | |
2375 | ||
252b5132 RH |
2376 | /* Set the correct type for an Alpha ELF section. We do this by the |
2377 | section name, which is a hack, but ought to work. */ | |
2378 | ||
2379 | static boolean | |
2380 | elf64_alpha_fake_sections (abfd, hdr, sec) | |
2381 | bfd *abfd; | |
2382 | Elf64_Internal_Shdr *hdr; | |
2383 | asection *sec; | |
2384 | { | |
2385 | register const char *name; | |
2386 | ||
2387 | name = bfd_get_section_name (abfd, sec); | |
2388 | ||
2389 | if (strcmp (name, ".mdebug") == 0) | |
2390 | { | |
2391 | hdr->sh_type = SHT_ALPHA_DEBUG; | |
2392 | /* In a shared object on Irix 5.3, the .mdebug section has an | |
2393 | entsize of 0. FIXME: Does this matter? */ | |
2394 | if ((abfd->flags & DYNAMIC) != 0 ) | |
2395 | hdr->sh_entsize = 0; | |
2396 | else | |
2397 | hdr->sh_entsize = 1; | |
2398 | } | |
204692d7 RH |
2399 | else if ((sec->flags & SEC_SMALL_DATA) |
2400 | || strcmp (name, ".sdata") == 0 | |
252b5132 RH |
2401 | || strcmp (name, ".sbss") == 0 |
2402 | || strcmp (name, ".lit4") == 0 | |
2403 | || strcmp (name, ".lit8") == 0) | |
2404 | hdr->sh_flags |= SHF_ALPHA_GPREL; | |
2405 | ||
2406 | return true; | |
2407 | } | |
2408 | ||
2409 | /* Hook called by the linker routine which adds symbols from an object | |
2410 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
2411 | ||
2412 | static boolean | |
2413 | elf64_alpha_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) | |
2414 | bfd *abfd; | |
2415 | struct bfd_link_info *info; | |
2416 | const Elf_Internal_Sym *sym; | |
56fc028e AJ |
2417 | const char **namep ATTRIBUTE_UNUSED; |
2418 | flagword *flagsp ATTRIBUTE_UNUSED; | |
252b5132 RH |
2419 | asection **secp; |
2420 | bfd_vma *valp; | |
2421 | { | |
2422 | if (sym->st_shndx == SHN_COMMON | |
2423 | && !info->relocateable | |
c0846b23 | 2424 | && sym->st_size <= elf_gp_size (abfd)) |
252b5132 RH |
2425 | { |
2426 | /* Common symbols less than or equal to -G nn bytes are | |
2427 | automatically put into .sbss. */ | |
2428 | ||
2429 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); | |
2430 | ||
2431 | if (scomm == NULL) | |
2432 | { | |
2433 | scomm = bfd_make_section (abfd, ".scommon"); | |
2434 | if (scomm == NULL | |
2435 | || !bfd_set_section_flags (abfd, scomm, (SEC_ALLOC | |
2436 | | SEC_IS_COMMON | |
2437 | | SEC_LINKER_CREATED))) | |
2438 | return false; | |
2439 | } | |
2440 | ||
2441 | *secp = scomm; | |
2442 | *valp = sym->st_size; | |
2443 | } | |
2444 | ||
2445 | return true; | |
2446 | } | |
2447 | ||
2448 | /* Create the .got section. */ | |
2449 | ||
2450 | static boolean | |
2451 | elf64_alpha_create_got_section(abfd, info) | |
2452 | bfd *abfd; | |
56fc028e | 2453 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
252b5132 RH |
2454 | { |
2455 | asection *s; | |
2456 | ||
2457 | if (bfd_get_section_by_name (abfd, ".got")) | |
2458 | return true; | |
2459 | ||
2460 | s = bfd_make_section (abfd, ".got"); | |
2461 | if (s == NULL | |
2462 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | |
2463 | | SEC_HAS_CONTENTS | |
2464 | | SEC_IN_MEMORY | |
2465 | | SEC_LINKER_CREATED)) | |
2466 | || !bfd_set_section_alignment (abfd, s, 3)) | |
2467 | return false; | |
2468 | ||
2469 | alpha_elf_tdata (abfd)->got = s; | |
2470 | ||
2471 | return true; | |
2472 | } | |
2473 | ||
2474 | /* Create all the dynamic sections. */ | |
2475 | ||
2476 | static boolean | |
2477 | elf64_alpha_create_dynamic_sections (abfd, info) | |
2478 | bfd *abfd; | |
2479 | struct bfd_link_info *info; | |
2480 | { | |
2481 | asection *s; | |
2482 | struct elf_link_hash_entry *h; | |
14a793b2 | 2483 | struct bfd_link_hash_entry *bh; |
252b5132 RH |
2484 | |
2485 | /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */ | |
2486 | ||
2487 | s = bfd_make_section (abfd, ".plt"); | |
2488 | if (s == NULL | |
2489 | || ! bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | |
2490 | | SEC_HAS_CONTENTS | |
2491 | | SEC_IN_MEMORY | |
2492 | | SEC_LINKER_CREATED | |
2493 | | SEC_CODE)) | |
2494 | || ! bfd_set_section_alignment (abfd, s, 3)) | |
2495 | return false; | |
2496 | ||
2497 | /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the | |
2498 | .plt section. */ | |
14a793b2 | 2499 | bh = NULL; |
252b5132 RH |
2500 | if (! (_bfd_generic_link_add_one_symbol |
2501 | (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, | |
2502 | (bfd_vma) 0, (const char *) NULL, false, | |
14a793b2 | 2503 | get_elf_backend_data (abfd)->collect, &bh))) |
252b5132 | 2504 | return false; |
14a793b2 | 2505 | h = (struct elf_link_hash_entry *) bh; |
252b5132 RH |
2506 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
2507 | h->type = STT_OBJECT; | |
2508 | ||
2509 | if (info->shared | |
2510 | && ! _bfd_elf_link_record_dynamic_symbol (info, h)) | |
2511 | return false; | |
2512 | ||
2513 | s = bfd_make_section (abfd, ".rela.plt"); | |
2514 | if (s == NULL | |
2515 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | |
2516 | | SEC_HAS_CONTENTS | |
2517 | | SEC_IN_MEMORY | |
2518 | | SEC_LINKER_CREATED | |
2519 | | SEC_READONLY)) | |
2520 | || ! bfd_set_section_alignment (abfd, s, 3)) | |
2521 | return false; | |
2522 | ||
2523 | /* We may or may not have created a .got section for this object, but | |
2524 | we definitely havn't done the rest of the work. */ | |
2525 | ||
2526 | if (!elf64_alpha_create_got_section (abfd, info)) | |
2527 | return false; | |
2528 | ||
2529 | s = bfd_make_section(abfd, ".rela.got"); | |
2530 | if (s == NULL | |
2531 | || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD | |
2532 | | SEC_HAS_CONTENTS | |
2533 | | SEC_IN_MEMORY | |
2534 | | SEC_LINKER_CREATED | |
2535 | | SEC_READONLY)) | |
2536 | || !bfd_set_section_alignment (abfd, s, 3)) | |
2537 | return false; | |
2538 | ||
2539 | /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the | |
2540 | dynobj's .got section. We don't do this in the linker script | |
2541 | because we don't want to define the symbol if we are not creating | |
2542 | a global offset table. */ | |
14a793b2 | 2543 | bh = NULL; |
252b5132 RH |
2544 | if (!(_bfd_generic_link_add_one_symbol |
2545 | (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, | |
2546 | alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL, | |
14a793b2 | 2547 | false, get_elf_backend_data (abfd)->collect, &bh))) |
252b5132 | 2548 | return false; |
14a793b2 | 2549 | h = (struct elf_link_hash_entry *) bh; |
252b5132 RH |
2550 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
2551 | h->type = STT_OBJECT; | |
2552 | ||
2553 | if (info->shared | |
2554 | && ! _bfd_elf_link_record_dynamic_symbol (info, h)) | |
2555 | return false; | |
2556 | ||
2557 | elf_hash_table (info)->hgot = h; | |
2558 | ||
2559 | return true; | |
2560 | } | |
2561 | \f | |
2562 | /* Read ECOFF debugging information from a .mdebug section into a | |
2563 | ecoff_debug_info structure. */ | |
2564 | ||
2565 | static boolean | |
2566 | elf64_alpha_read_ecoff_info (abfd, section, debug) | |
2567 | bfd *abfd; | |
2568 | asection *section; | |
2569 | struct ecoff_debug_info *debug; | |
2570 | { | |
2571 | HDRR *symhdr; | |
2572 | const struct ecoff_debug_swap *swap; | |
2573 | char *ext_hdr = NULL; | |
2574 | ||
2575 | swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
fe8bc63d | 2576 | memset (debug, 0, sizeof (*debug)); |
252b5132 | 2577 | |
dc810e39 | 2578 | ext_hdr = (char *) bfd_malloc (swap->external_hdr_size); |
252b5132 RH |
2579 | if (ext_hdr == NULL && swap->external_hdr_size != 0) |
2580 | goto error_return; | |
2581 | ||
82e51918 AM |
2582 | if (! bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0, |
2583 | swap->external_hdr_size)) | |
252b5132 RH |
2584 | goto error_return; |
2585 | ||
2586 | symhdr = &debug->symbolic_header; | |
2587 | (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr); | |
2588 | ||
2589 | /* The symbolic header contains absolute file offsets and sizes to | |
2590 | read. */ | |
2591 | #define READ(ptr, offset, count, size, type) \ | |
2592 | if (symhdr->count == 0) \ | |
2593 | debug->ptr = NULL; \ | |
2594 | else \ | |
2595 | { \ | |
dc810e39 AM |
2596 | bfd_size_type amt = (bfd_size_type) size * symhdr->count; \ |
2597 | debug->ptr = (type) bfd_malloc (amt); \ | |
252b5132 RH |
2598 | if (debug->ptr == NULL) \ |
2599 | goto error_return; \ | |
2600 | if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \ | |
dc810e39 | 2601 | || bfd_bread (debug->ptr, amt, abfd) != amt) \ |
252b5132 RH |
2602 | goto error_return; \ |
2603 | } | |
2604 | ||
2605 | READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *); | |
2606 | READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR); | |
2607 | READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR); | |
2608 | READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR); | |
2609 | READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR); | |
2610 | READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext), | |
2611 | union aux_ext *); | |
2612 | READ (ss, cbSsOffset, issMax, sizeof (char), char *); | |
2613 | READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *); | |
2614 | READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR); | |
2615 | READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR); | |
2616 | READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR); | |
2617 | #undef READ | |
2618 | ||
2619 | debug->fdr = NULL; | |
2620 | debug->adjust = NULL; | |
2621 | ||
2622 | return true; | |
2623 | ||
2624 | error_return: | |
2625 | if (ext_hdr != NULL) | |
2626 | free (ext_hdr); | |
2627 | if (debug->line != NULL) | |
2628 | free (debug->line); | |
2629 | if (debug->external_dnr != NULL) | |
2630 | free (debug->external_dnr); | |
2631 | if (debug->external_pdr != NULL) | |
2632 | free (debug->external_pdr); | |
2633 | if (debug->external_sym != NULL) | |
2634 | free (debug->external_sym); | |
2635 | if (debug->external_opt != NULL) | |
2636 | free (debug->external_opt); | |
2637 | if (debug->external_aux != NULL) | |
2638 | free (debug->external_aux); | |
2639 | if (debug->ss != NULL) | |
2640 | free (debug->ss); | |
2641 | if (debug->ssext != NULL) | |
2642 | free (debug->ssext); | |
2643 | if (debug->external_fdr != NULL) | |
2644 | free (debug->external_fdr); | |
2645 | if (debug->external_rfd != NULL) | |
2646 | free (debug->external_rfd); | |
2647 | if (debug->external_ext != NULL) | |
2648 | free (debug->external_ext); | |
2649 | return false; | |
2650 | } | |
2651 | ||
2652 | /* Alpha ELF local labels start with '$'. */ | |
2653 | ||
2654 | static boolean | |
2655 | elf64_alpha_is_local_label_name (abfd, name) | |
56fc028e | 2656 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
2657 | const char *name; |
2658 | { | |
2659 | return name[0] == '$'; | |
2660 | } | |
2661 | ||
2662 | /* Alpha ELF follows MIPS ELF in using a special find_nearest_line | |
2663 | routine in order to handle the ECOFF debugging information. We | |
2664 | still call this mips_elf_find_line because of the slot | |
2665 | find_line_info in elf_obj_tdata is declared that way. */ | |
2666 | ||
2667 | struct mips_elf_find_line | |
2668 | { | |
2669 | struct ecoff_debug_info d; | |
2670 | struct ecoff_find_line i; | |
2671 | }; | |
2672 | ||
2673 | static boolean | |
2674 | elf64_alpha_find_nearest_line (abfd, section, symbols, offset, filename_ptr, | |
2675 | functionname_ptr, line_ptr) | |
2676 | bfd *abfd; | |
2677 | asection *section; | |
2678 | asymbol **symbols; | |
2679 | bfd_vma offset; | |
2680 | const char **filename_ptr; | |
2681 | const char **functionname_ptr; | |
2682 | unsigned int *line_ptr; | |
2683 | { | |
2684 | asection *msec; | |
2685 | ||
95404643 RH |
2686 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, |
2687 | filename_ptr, functionname_ptr, | |
2688 | line_ptr, 0, | |
2689 | &elf_tdata (abfd)->dwarf2_find_line_info)) | |
2690 | return true; | |
2691 | ||
252b5132 RH |
2692 | msec = bfd_get_section_by_name (abfd, ".mdebug"); |
2693 | if (msec != NULL) | |
2694 | { | |
2695 | flagword origflags; | |
2696 | struct mips_elf_find_line *fi; | |
2697 | const struct ecoff_debug_swap * const swap = | |
2698 | get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
2699 | ||
2700 | /* If we are called during a link, alpha_elf_final_link may have | |
2701 | cleared the SEC_HAS_CONTENTS field. We force it back on here | |
2702 | if appropriate (which it normally will be). */ | |
2703 | origflags = msec->flags; | |
2704 | if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS) | |
2705 | msec->flags |= SEC_HAS_CONTENTS; | |
2706 | ||
2707 | fi = elf_tdata (abfd)->find_line_info; | |
2708 | if (fi == NULL) | |
2709 | { | |
2710 | bfd_size_type external_fdr_size; | |
2711 | char *fraw_src; | |
2712 | char *fraw_end; | |
2713 | struct fdr *fdr_ptr; | |
dc810e39 | 2714 | bfd_size_type amt = sizeof (struct mips_elf_find_line); |
252b5132 | 2715 | |
dc810e39 | 2716 | fi = (struct mips_elf_find_line *) bfd_zalloc (abfd, amt); |
252b5132 RH |
2717 | if (fi == NULL) |
2718 | { | |
2719 | msec->flags = origflags; | |
2720 | return false; | |
2721 | } | |
2722 | ||
2723 | if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d)) | |
2724 | { | |
2725 | msec->flags = origflags; | |
2726 | return false; | |
2727 | } | |
2728 | ||
2729 | /* Swap in the FDR information. */ | |
dc810e39 AM |
2730 | amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr); |
2731 | fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt); | |
252b5132 RH |
2732 | if (fi->d.fdr == NULL) |
2733 | { | |
2734 | msec->flags = origflags; | |
2735 | return false; | |
2736 | } | |
2737 | external_fdr_size = swap->external_fdr_size; | |
2738 | fdr_ptr = fi->d.fdr; | |
2739 | fraw_src = (char *) fi->d.external_fdr; | |
2740 | fraw_end = (fraw_src | |
2741 | + fi->d.symbolic_header.ifdMax * external_fdr_size); | |
2742 | for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++) | |
2743 | (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr); | |
2744 | ||
2745 | elf_tdata (abfd)->find_line_info = fi; | |
2746 | ||
2747 | /* Note that we don't bother to ever free this information. | |
2748 | find_nearest_line is either called all the time, as in | |
2749 | objdump -l, so the information should be saved, or it is | |
2750 | rarely called, as in ld error messages, so the memory | |
2751 | wasted is unimportant. Still, it would probably be a | |
2752 | good idea for free_cached_info to throw it away. */ | |
2753 | } | |
2754 | ||
2755 | if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap, | |
2756 | &fi->i, filename_ptr, functionname_ptr, | |
2757 | line_ptr)) | |
2758 | { | |
2759 | msec->flags = origflags; | |
2760 | return true; | |
2761 | } | |
2762 | ||
2763 | msec->flags = origflags; | |
2764 | } | |
2765 | ||
2766 | /* Fall back on the generic ELF find_nearest_line routine. */ | |
2767 | ||
2768 | return _bfd_elf_find_nearest_line (abfd, section, symbols, offset, | |
2769 | filename_ptr, functionname_ptr, | |
2770 | line_ptr); | |
2771 | } | |
2772 | \f | |
2773 | /* Structure used to pass information to alpha_elf_output_extsym. */ | |
2774 | ||
2775 | struct extsym_info | |
2776 | { | |
2777 | bfd *abfd; | |
2778 | struct bfd_link_info *info; | |
2779 | struct ecoff_debug_info *debug; | |
2780 | const struct ecoff_debug_swap *swap; | |
2781 | boolean failed; | |
2782 | }; | |
2783 | ||
2784 | static boolean | |
2785 | elf64_alpha_output_extsym (h, data) | |
2786 | struct alpha_elf_link_hash_entry *h; | |
2787 | PTR data; | |
2788 | { | |
2789 | struct extsym_info *einfo = (struct extsym_info *) data; | |
2790 | boolean strip; | |
2791 | asection *sec, *output_section; | |
2792 | ||
e92d460e AM |
2793 | if (h->root.root.type == bfd_link_hash_warning) |
2794 | h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link; | |
2795 | ||
252b5132 RH |
2796 | if (h->root.indx == -2) |
2797 | strip = false; | |
2798 | else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
e92d460e AM |
2799 | || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0) |
2800 | && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
2801 | && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0) | |
252b5132 RH |
2802 | strip = true; |
2803 | else if (einfo->info->strip == strip_all | |
e92d460e AM |
2804 | || (einfo->info->strip == strip_some |
2805 | && bfd_hash_lookup (einfo->info->keep_hash, | |
2806 | h->root.root.root.string, | |
2807 | false, false) == NULL)) | |
252b5132 RH |
2808 | strip = true; |
2809 | else | |
2810 | strip = false; | |
2811 | ||
2812 | if (strip) | |
2813 | return true; | |
2814 | ||
2815 | if (h->esym.ifd == -2) | |
2816 | { | |
2817 | h->esym.jmptbl = 0; | |
2818 | h->esym.cobol_main = 0; | |
2819 | h->esym.weakext = 0; | |
2820 | h->esym.reserved = 0; | |
2821 | h->esym.ifd = ifdNil; | |
2822 | h->esym.asym.value = 0; | |
2823 | h->esym.asym.st = stGlobal; | |
2824 | ||
2825 | if (h->root.root.type != bfd_link_hash_defined | |
e92d460e AM |
2826 | && h->root.root.type != bfd_link_hash_defweak) |
2827 | h->esym.asym.sc = scAbs; | |
252b5132 | 2828 | else |
e92d460e AM |
2829 | { |
2830 | const char *name; | |
2831 | ||
2832 | sec = h->root.root.u.def.section; | |
2833 | output_section = sec->output_section; | |
2834 | ||
2835 | /* When making a shared library and symbol h is the one from | |
2836 | the another shared library, OUTPUT_SECTION may be null. */ | |
2837 | if (output_section == NULL) | |
2838 | h->esym.asym.sc = scUndefined; | |
2839 | else | |
2840 | { | |
2841 | name = bfd_section_name (output_section->owner, output_section); | |
2842 | ||
2843 | if (strcmp (name, ".text") == 0) | |
2844 | h->esym.asym.sc = scText; | |
2845 | else if (strcmp (name, ".data") == 0) | |
2846 | h->esym.asym.sc = scData; | |
2847 | else if (strcmp (name, ".sdata") == 0) | |
2848 | h->esym.asym.sc = scSData; | |
2849 | else if (strcmp (name, ".rodata") == 0 | |
2850 | || strcmp (name, ".rdata") == 0) | |
2851 | h->esym.asym.sc = scRData; | |
2852 | else if (strcmp (name, ".bss") == 0) | |
2853 | h->esym.asym.sc = scBss; | |
2854 | else if (strcmp (name, ".sbss") == 0) | |
2855 | h->esym.asym.sc = scSBss; | |
2856 | else if (strcmp (name, ".init") == 0) | |
2857 | h->esym.asym.sc = scInit; | |
2858 | else if (strcmp (name, ".fini") == 0) | |
2859 | h->esym.asym.sc = scFini; | |
2860 | else | |
2861 | h->esym.asym.sc = scAbs; | |
2862 | } | |
2863 | } | |
252b5132 RH |
2864 | |
2865 | h->esym.asym.reserved = 0; | |
2866 | h->esym.asym.index = indexNil; | |
2867 | } | |
2868 | ||
2869 | if (h->root.root.type == bfd_link_hash_common) | |
2870 | h->esym.asym.value = h->root.root.u.c.size; | |
2871 | else if (h->root.root.type == bfd_link_hash_defined | |
2872 | || h->root.root.type == bfd_link_hash_defweak) | |
2873 | { | |
2874 | if (h->esym.asym.sc == scCommon) | |
e92d460e | 2875 | h->esym.asym.sc = scBss; |
252b5132 | 2876 | else if (h->esym.asym.sc == scSCommon) |
e92d460e | 2877 | h->esym.asym.sc = scSBss; |
252b5132 RH |
2878 | |
2879 | sec = h->root.root.u.def.section; | |
2880 | output_section = sec->output_section; | |
2881 | if (output_section != NULL) | |
e92d460e AM |
2882 | h->esym.asym.value = (h->root.root.u.def.value |
2883 | + sec->output_offset | |
2884 | + output_section->vma); | |
252b5132 | 2885 | else |
e92d460e | 2886 | h->esym.asym.value = 0; |
252b5132 RH |
2887 | } |
2888 | else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
2889 | { | |
2890 | /* Set type and value for a symbol with a function stub. */ | |
2891 | h->esym.asym.st = stProc; | |
2892 | sec = bfd_get_section_by_name (einfo->abfd, ".plt"); | |
2893 | if (sec == NULL) | |
2894 | h->esym.asym.value = 0; | |
2895 | else | |
2896 | { | |
2897 | output_section = sec->output_section; | |
2898 | if (output_section != NULL) | |
2899 | h->esym.asym.value = (h->root.plt.offset | |
2900 | + sec->output_offset | |
2901 | + output_section->vma); | |
2902 | else | |
2903 | h->esym.asym.value = 0; | |
2904 | } | |
252b5132 RH |
2905 | } |
2906 | ||
2907 | if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap, | |
e92d460e AM |
2908 | h->root.root.root.string, |
2909 | &h->esym)) | |
252b5132 RH |
2910 | { |
2911 | einfo->failed = true; | |
2912 | return false; | |
2913 | } | |
2914 | ||
2915 | return true; | |
2916 | } | |
252b5132 | 2917 | \f |
3765b1be RH |
2918 | /* Search for and possibly create a got entry. */ |
2919 | ||
2920 | static struct alpha_elf_got_entry * | |
2921 | get_got_entry (abfd, h, r_type, r_symndx, r_addend) | |
2922 | bfd *abfd; | |
2923 | struct alpha_elf_link_hash_entry *h; | |
2924 | unsigned long r_type, r_symndx; | |
2925 | bfd_vma r_addend; | |
2926 | { | |
2927 | struct alpha_elf_got_entry *gotent; | |
2928 | struct alpha_elf_got_entry **slot; | |
2929 | ||
2930 | if (h) | |
2931 | slot = &h->got_entries; | |
2932 | else | |
2933 | { | |
2934 | /* This is a local .got entry -- record for merge. */ | |
2935 | ||
2936 | struct alpha_elf_got_entry **local_got_entries; | |
2937 | ||
2938 | local_got_entries = alpha_elf_tdata(abfd)->local_got_entries; | |
2939 | if (!local_got_entries) | |
2940 | { | |
2941 | bfd_size_type size; | |
2942 | Elf_Internal_Shdr *symtab_hdr; | |
2943 | ||
2944 | symtab_hdr = &elf_tdata(abfd)->symtab_hdr; | |
2945 | size = symtab_hdr->sh_info; | |
2946 | size *= sizeof (struct alpha_elf_got_entry *); | |
2947 | ||
2948 | local_got_entries | |
9bab7074 | 2949 | = (struct alpha_elf_got_entry **) bfd_zalloc (abfd, size); |
3765b1be RH |
2950 | if (!local_got_entries) |
2951 | return NULL; | |
2952 | ||
3765b1be RH |
2953 | alpha_elf_tdata (abfd)->local_got_entries = local_got_entries; |
2954 | } | |
2955 | ||
2956 | slot = &local_got_entries[r_symndx]; | |
2957 | } | |
2958 | ||
2959 | for (gotent = *slot; gotent ; gotent = gotent->next) | |
2960 | if (gotent->gotobj == abfd | |
2961 | && gotent->reloc_type == r_type | |
2962 | && gotent->addend == r_addend) | |
2963 | break; | |
2964 | ||
2965 | if (!gotent) | |
2966 | { | |
2967 | int entry_size; | |
2968 | bfd_size_type amt; | |
2969 | ||
2970 | amt = sizeof (struct alpha_elf_got_entry); | |
2971 | gotent = (struct alpha_elf_got_entry *) bfd_alloc (abfd, amt); | |
2972 | if (!gotent) | |
2973 | return NULL; | |
2974 | ||
2975 | gotent->gotobj = abfd; | |
2976 | gotent->addend = r_addend; | |
2977 | gotent->got_offset = -1; | |
2978 | gotent->use_count = 1; | |
2979 | gotent->reloc_type = r_type; | |
2980 | gotent->reloc_done = 0; | |
2981 | gotent->reloc_xlated = 0; | |
2982 | ||
2983 | gotent->next = *slot; | |
2984 | *slot = gotent; | |
2985 | ||
2986 | entry_size = alpha_got_entry_size (r_type); | |
2987 | alpha_elf_tdata (abfd)->total_got_size += entry_size; | |
2988 | if (!h) | |
2989 | alpha_elf_tdata(abfd)->local_got_size += entry_size; | |
2990 | } | |
2991 | else | |
2992 | gotent->use_count += 1; | |
2993 | ||
2994 | return gotent; | |
2995 | } | |
2996 | ||
252b5132 RH |
2997 | /* Handle dynamic relocations when doing an Alpha ELF link. */ |
2998 | ||
2999 | static boolean | |
3000 | elf64_alpha_check_relocs (abfd, info, sec, relocs) | |
3001 | bfd *abfd; | |
3002 | struct bfd_link_info *info; | |
3003 | asection *sec; | |
3004 | const Elf_Internal_Rela *relocs; | |
3005 | { | |
3006 | bfd *dynobj; | |
3007 | asection *sreloc; | |
3008 | const char *rel_sec_name; | |
3009 | Elf_Internal_Shdr *symtab_hdr; | |
3010 | struct alpha_elf_link_hash_entry **sym_hashes; | |
252b5132 | 3011 | const Elf_Internal_Rela *rel, *relend; |
3765b1be | 3012 | boolean got_created; |
dc810e39 | 3013 | bfd_size_type amt; |
252b5132 RH |
3014 | |
3015 | if (info->relocateable) | |
3016 | return true; | |
3017 | ||
3018 | dynobj = elf_hash_table(info)->dynobj; | |
3019 | if (dynobj == NULL) | |
3020 | elf_hash_table(info)->dynobj = dynobj = abfd; | |
3021 | ||
3022 | sreloc = NULL; | |
3023 | rel_sec_name = NULL; | |
3024 | symtab_hdr = &elf_tdata(abfd)->symtab_hdr; | |
3025 | sym_hashes = alpha_elf_sym_hashes(abfd); | |
3765b1be | 3026 | got_created = false; |
252b5132 RH |
3027 | |
3028 | relend = relocs + sec->reloc_count; | |
3029 | for (rel = relocs; rel < relend; ++rel) | |
3030 | { | |
3765b1be RH |
3031 | enum { |
3032 | NEED_GOT = 1, | |
3033 | NEED_GOT_ENTRY = 2, | |
3034 | NEED_DYNREL = 4 | |
3035 | }; | |
3036 | ||
252b5132 RH |
3037 | unsigned long r_symndx, r_type; |
3038 | struct alpha_elf_link_hash_entry *h; | |
3765b1be RH |
3039 | unsigned int gotent_flags; |
3040 | boolean maybe_dynamic; | |
3041 | unsigned int need; | |
3042 | bfd_vma addend; | |
252b5132 RH |
3043 | |
3044 | r_symndx = ELF64_R_SYM (rel->r_info); | |
3045 | if (r_symndx < symtab_hdr->sh_info) | |
3046 | h = NULL; | |
3047 | else | |
3048 | { | |
3049 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3050 | ||
3051 | while (h->root.root.type == bfd_link_hash_indirect | |
3052 | || h->root.root.type == bfd_link_hash_warning) | |
3053 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; | |
3054 | ||
3055 | h->root.elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR; | |
3056 | } | |
3765b1be RH |
3057 | |
3058 | /* We can only get preliminary data on whether a symbol is | |
3059 | locally or externally defined, as not all of the input files | |
3060 | have yet been processed. Do something with what we know, as | |
3061 | this may help reduce memory usage and processing time later. */ | |
3062 | maybe_dynamic = false; | |
3063 | if (h && ((info->shared | |
3064 | && (!info->symbolic || info->allow_shlib_undefined)) | |
3065 | || ! (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) | |
c853d7f6 | 3066 | || h->root.root.type == bfd_link_hash_defweak)) |
3765b1be RH |
3067 | maybe_dynamic = true; |
3068 | ||
3069 | need = 0; | |
3070 | gotent_flags = 0; | |
252b5132 | 3071 | r_type = ELF64_R_TYPE (rel->r_info); |
3765b1be | 3072 | addend = rel->r_addend; |
252b5132 RH |
3073 | |
3074 | switch (r_type) | |
3075 | { | |
3076 | case R_ALPHA_LITERAL: | |
3765b1be RH |
3077 | need = NEED_GOT | NEED_GOT_ENTRY; |
3078 | ||
3079 | /* Remember how this literal is used from its LITUSEs. | |
3080 | This will be important when it comes to decide if we can | |
3081 | create a .plt entry for a function symbol. */ | |
3082 | while (++rel < relend && ELF64_R_TYPE (rel->r_info) == R_ALPHA_LITUSE) | |
3083 | if (rel->r_addend >= 1 && rel->r_addend <= 5) | |
3084 | gotent_flags |= 1 << rel->r_addend; | |
3085 | --rel; | |
3086 | ||
3087 | /* No LITUSEs -- presumably the address is used somehow. */ | |
3088 | if (gotent_flags == 0) | |
3089 | gotent_flags = ALPHA_ELF_LINK_HASH_LU_ADDR; | |
3090 | break; | |
252b5132 RH |
3091 | |
3092 | case R_ALPHA_GPDISP: | |
dfe57ca0 | 3093 | case R_ALPHA_GPREL16: |
252b5132 RH |
3094 | case R_ALPHA_GPREL32: |
3095 | case R_ALPHA_GPRELHIGH: | |
3096 | case R_ALPHA_GPRELLOW: | |
7793f4d0 | 3097 | case R_ALPHA_BRSGP: |
3765b1be RH |
3098 | need = NEED_GOT; |
3099 | break; | |
3100 | ||
3101 | case R_ALPHA_REFLONG: | |
3102 | case R_ALPHA_REFQUAD: | |
3103 | if (info->shared || maybe_dynamic) | |
3104 | need = NEED_DYNREL; | |
3105 | break; | |
3106 | ||
3107 | case R_ALPHA_TLSGD: | |
3108 | case R_ALPHA_TLSLDM: | |
3109 | case R_ALPHA_GOTDTPREL: | |
3110 | need = NEED_GOT | NEED_GOT_ENTRY; | |
3111 | break; | |
3112 | ||
3113 | case R_ALPHA_GOTTPREL: | |
3114 | need = NEED_GOT | NEED_GOT_ENTRY; | |
9e756d64 | 3115 | gotent_flags = ALPHA_ELF_LINK_HASH_TLS_IE; |
3765b1be RH |
3116 | if (info->shared) |
3117 | info->flags |= DF_STATIC_TLS; | |
3118 | break; | |
3119 | ||
3120 | case R_ALPHA_TPREL64: | |
3121 | if (info->shared || maybe_dynamic) | |
3122 | need = NEED_DYNREL; | |
3123 | if (info->shared) | |
3124 | info->flags |= DF_STATIC_TLS; | |
3125 | break; | |
3126 | } | |
3127 | ||
3128 | if (need & NEED_GOT) | |
3129 | { | |
252b5132 RH |
3130 | if (!got_created) |
3131 | { | |
3132 | if (!elf64_alpha_create_got_section (abfd, info)) | |
3133 | return false; | |
3134 | ||
3135 | /* Make sure the object's gotobj is set to itself so | |
3136 | that we default to every object with its own .got. | |
3137 | We'll merge .gots later once we've collected each | |
3138 | object's info. */ | |
3139 | alpha_elf_tdata(abfd)->gotobj = abfd; | |
3140 | ||
3141 | got_created = 1; | |
3142 | } | |
3765b1be | 3143 | } |
252b5132 | 3144 | |
3765b1be RH |
3145 | if (need & NEED_GOT_ENTRY) |
3146 | { | |
3147 | struct alpha_elf_got_entry *gotent; | |
252b5132 | 3148 | |
3765b1be RH |
3149 | gotent = get_got_entry (abfd, h, r_type, r_symndx, addend); |
3150 | if (!gotent) | |
3151 | return false; | |
3152 | ||
3153 | if (gotent_flags) | |
3154 | { | |
3155 | gotent->flags |= gotent_flags; | |
3156 | if (h) | |
3157 | { | |
3158 | gotent_flags |= h->flags; | |
3159 | h->flags = gotent_flags; | |
3160 | ||
3161 | /* Make a guess as to whether a .plt entry is needed. */ | |
3162 | if ((gotent_flags & ALPHA_ELF_LINK_HASH_LU_FUNC) | |
3163 | && !(gotent_flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC)) | |
3164 | h->root.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3165 | else | |
3166 | h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3167 | } | |
3168 | } | |
3169 | } | |
3170 | ||
3171 | if (need & NEED_DYNREL) | |
3172 | { | |
252b5132 RH |
3173 | if (rel_sec_name == NULL) |
3174 | { | |
3175 | rel_sec_name = (bfd_elf_string_from_elf_section | |
3176 | (abfd, elf_elfheader(abfd)->e_shstrndx, | |
3177 | elf_section_data(sec)->rel_hdr.sh_name)); | |
3178 | if (rel_sec_name == NULL) | |
3179 | return false; | |
3180 | ||
3181 | BFD_ASSERT (strncmp (rel_sec_name, ".rela", 5) == 0 | |
3182 | && strcmp (bfd_get_section_name (abfd, sec), | |
3183 | rel_sec_name+5) == 0); | |
3184 | } | |
3185 | ||
3186 | /* We need to create the section here now whether we eventually | |
3187 | use it or not so that it gets mapped to an output section by | |
3188 | the linker. If not used, we'll kill it in | |
3189 | size_dynamic_sections. */ | |
3190 | if (sreloc == NULL) | |
3191 | { | |
3192 | sreloc = bfd_get_section_by_name (dynobj, rel_sec_name); | |
3193 | if (sreloc == NULL) | |
3194 | { | |
dc810e39 AM |
3195 | flagword flags; |
3196 | ||
252b5132 | 3197 | sreloc = bfd_make_section (dynobj, rel_sec_name); |
dc810e39 AM |
3198 | flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY |
3199 | | SEC_LINKER_CREATED | SEC_READONLY); | |
3200 | if (sec->flags & SEC_ALLOC) | |
3201 | flags |= SEC_ALLOC | SEC_LOAD; | |
252b5132 | 3202 | if (sreloc == NULL |
dc810e39 | 3203 | || !bfd_set_section_flags (dynobj, sreloc, flags) |
252b5132 RH |
3204 | || !bfd_set_section_alignment (dynobj, sreloc, 3)) |
3205 | return false; | |
3206 | } | |
3207 | } | |
3208 | ||
3209 | if (h) | |
3210 | { | |
3211 | /* Since we havn't seen all of the input symbols yet, we | |
3212 | don't know whether we'll actually need a dynamic relocation | |
3213 | entry for this reloc. So make a record of it. Once we | |
3214 | find out if this thing needs dynamic relocation we'll | |
fe8bc63d | 3215 | expand the relocation sections by the appropriate amount. */ |
252b5132 RH |
3216 | |
3217 | struct alpha_elf_reloc_entry *rent; | |
3218 | ||
3219 | for (rent = h->reloc_entries; rent; rent = rent->next) | |
3220 | if (rent->rtype == r_type && rent->srel == sreloc) | |
3221 | break; | |
3222 | ||
3223 | if (!rent) | |
3224 | { | |
dc810e39 AM |
3225 | amt = sizeof (struct alpha_elf_reloc_entry); |
3226 | rent = (struct alpha_elf_reloc_entry *) bfd_alloc (abfd, amt); | |
252b5132 RH |
3227 | if (!rent) |
3228 | return false; | |
3229 | ||
3230 | rent->srel = sreloc; | |
3231 | rent->rtype = r_type; | |
3232 | rent->count = 1; | |
73896efb RH |
3233 | rent->reltext = ((sec->flags & (SEC_READONLY | SEC_ALLOC)) |
3234 | == (SEC_READONLY | SEC_ALLOC)); | |
252b5132 RH |
3235 | |
3236 | rent->next = h->reloc_entries; | |
3237 | h->reloc_entries = rent; | |
3238 | } | |
3239 | else | |
3240 | rent->count++; | |
3241 | } | |
c853d7f6 | 3242 | else if (info->shared) |
252b5132 | 3243 | { |
c555c5c5 AM |
3244 | /* If this is a shared library, and the section is to be |
3245 | loaded into memory, we need a RELATIVE reloc. */ | |
252b5132 | 3246 | sreloc->_raw_size += sizeof (Elf64_External_Rela); |
c853d7f6 RH |
3247 | if ((sec->flags & (SEC_READONLY | SEC_ALLOC)) |
3248 | == (SEC_READONLY | SEC_ALLOC)) | |
fcfbdf31 | 3249 | info->flags |= DF_TEXTREL; |
252b5132 | 3250 | } |
252b5132 RH |
3251 | } |
3252 | } | |
3253 | ||
3254 | return true; | |
3255 | } | |
3256 | ||
3257 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
3258 | regular object. The current definition is in some section of the | |
3259 | dynamic object, but we're not including those sections. We have to | |
3260 | change the definition to something the rest of the link can | |
3261 | understand. */ | |
3262 | ||
3263 | static boolean | |
3264 | elf64_alpha_adjust_dynamic_symbol (info, h) | |
3265 | struct bfd_link_info *info; | |
3266 | struct elf_link_hash_entry *h; | |
3267 | { | |
3268 | bfd *dynobj; | |
3269 | asection *s; | |
3270 | struct alpha_elf_link_hash_entry *ah; | |
3271 | ||
3272 | dynobj = elf_hash_table(info)->dynobj; | |
3273 | ah = (struct alpha_elf_link_hash_entry *)h; | |
3274 | ||
3275 | /* Now that we've seen all of the input symbols, finalize our decision | |
3276 | about whether this symbol should get a .plt entry. */ | |
3277 | ||
8ba89f17 | 3278 | if (alpha_elf_dynamic_symbol_p (h, info) |
252b5132 RH |
3279 | && ((h->type == STT_FUNC |
3280 | && !(ah->flags & ALPHA_ELF_LINK_HASH_LU_ADDR)) | |
3281 | || (h->type == STT_NOTYPE | |
3765b1be RH |
3282 | && (ah->flags & ALPHA_ELF_LINK_HASH_LU_FUNC) |
3283 | && !(ah->flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC))) | |
252b5132 RH |
3284 | /* Don't prevent otherwise valid programs from linking by attempting |
3285 | to create a new .got entry somewhere. A Correct Solution would be | |
3286 | to add a new .got section to a new object file and let it be merged | |
3287 | somewhere later. But for now don't bother. */ | |
3288 | && ah->got_entries) | |
3289 | { | |
3290 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
3291 | ||
3292 | s = bfd_get_section_by_name(dynobj, ".plt"); | |
3293 | if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info)) | |
3294 | return false; | |
3295 | ||
3296 | /* The first bit of the .plt is reserved. */ | |
3297 | if (s->_raw_size == 0) | |
3298 | s->_raw_size = PLT_HEADER_SIZE; | |
3299 | ||
3300 | h->plt.offset = s->_raw_size; | |
3301 | s->_raw_size += PLT_ENTRY_SIZE; | |
3302 | ||
3303 | /* If this symbol is not defined in a regular file, and we are not | |
3304 | generating a shared library, then set the symbol to the location | |
3305 | in the .plt. This is required to make function pointers compare | |
3306 | equal between the normal executable and the shared library. */ | |
3307 | if (! info->shared | |
3308 | && h->root.type != bfd_link_hash_defweak) | |
3309 | { | |
3310 | h->root.u.def.section = s; | |
3311 | h->root.u.def.value = h->plt.offset; | |
3312 | } | |
3313 | ||
3314 | /* We also need a JMP_SLOT entry in the .rela.plt section. */ | |
3315 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3316 | BFD_ASSERT (s != NULL); | |
3317 | s->_raw_size += sizeof (Elf64_External_Rela); | |
3318 | ||
3319 | return true; | |
3320 | } | |
3321 | else | |
3322 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3323 | ||
3324 | /* If this is a weak symbol, and there is a real definition, the | |
3325 | processor independent code will have arranged for us to see the | |
3326 | real definition first, and we can just use the same value. */ | |
3327 | if (h->weakdef != NULL) | |
3328 | { | |
3329 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
3330 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
3331 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
3332 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
3333 | return true; | |
3334 | } | |
3335 | ||
3336 | /* This is a reference to a symbol defined by a dynamic object which | |
3337 | is not a function. The Alpha, since it uses .got entries for all | |
3338 | symbols even in regular objects, does not need the hackery of a | |
3339 | .dynbss section and COPY dynamic relocations. */ | |
3340 | ||
3341 | return true; | |
3342 | } | |
3343 | ||
3344 | /* Symbol versioning can create new symbols, and make our old symbols | |
3345 | indirect to the new ones. Consolidate the got and reloc information | |
3346 | in these situations. */ | |
3347 | ||
3348 | static boolean | |
3349 | elf64_alpha_merge_ind_symbols (hi, dummy) | |
3350 | struct alpha_elf_link_hash_entry *hi; | |
56fc028e | 3351 | PTR dummy ATTRIBUTE_UNUSED; |
252b5132 RH |
3352 | { |
3353 | struct alpha_elf_link_hash_entry *hs; | |
3354 | ||
3355 | if (hi->root.root.type != bfd_link_hash_indirect) | |
3356 | return true; | |
3357 | hs = hi; | |
3358 | do { | |
3359 | hs = (struct alpha_elf_link_hash_entry *)hs->root.root.u.i.link; | |
3360 | } while (hs->root.root.type == bfd_link_hash_indirect); | |
3361 | ||
3362 | /* Merge the flags. Whee. */ | |
3363 | ||
3364 | hs->flags |= hi->flags; | |
3365 | ||
3366 | /* Merge the .got entries. Cannibalize the old symbol's list in | |
3367 | doing so, since we don't need it anymore. */ | |
3368 | ||
3369 | if (hs->got_entries == NULL) | |
3370 | hs->got_entries = hi->got_entries; | |
3371 | else | |
3372 | { | |
3373 | struct alpha_elf_got_entry *gi, *gs, *gin, *gsh; | |
3374 | ||
3375 | gsh = hs->got_entries; | |
3376 | for (gi = hi->got_entries; gi ; gi = gin) | |
3377 | { | |
3378 | gin = gi->next; | |
3379 | for (gs = gsh; gs ; gs = gs->next) | |
3765b1be RH |
3380 | if (gi->gotobj == gs->gotobj |
3381 | && gi->reloc_type == gs->reloc_type | |
3382 | && gi->addend == gs->addend) | |
3383 | { | |
3384 | gi->use_count += gs->use_count; | |
3385 | goto got_found; | |
3386 | } | |
252b5132 RH |
3387 | gi->next = hs->got_entries; |
3388 | hs->got_entries = gi; | |
3389 | got_found:; | |
3390 | } | |
3391 | } | |
3392 | hi->got_entries = NULL; | |
3393 | ||
3394 | /* And similar for the reloc entries. */ | |
3395 | ||
3396 | if (hs->reloc_entries == NULL) | |
3397 | hs->reloc_entries = hi->reloc_entries; | |
3398 | else | |
3399 | { | |
3400 | struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh; | |
3401 | ||
3402 | rsh = hs->reloc_entries; | |
3403 | for (ri = hi->reloc_entries; ri ; ri = rin) | |
3404 | { | |
3405 | rin = ri->next; | |
3406 | for (rs = rsh; rs ; rs = rs->next) | |
82988bff | 3407 | if (ri->rtype == rs->rtype && ri->srel == rs->srel) |
252b5132 RH |
3408 | { |
3409 | rs->count += ri->count; | |
3410 | goto found_reloc; | |
3411 | } | |
3412 | ri->next = hs->reloc_entries; | |
3413 | hs->reloc_entries = ri; | |
3414 | found_reloc:; | |
3415 | } | |
3416 | } | |
3417 | hi->reloc_entries = NULL; | |
3418 | ||
3419 | return true; | |
3420 | } | |
3421 | ||
3422 | /* Is it possible to merge two object file's .got tables? */ | |
3423 | ||
3424 | static boolean | |
3425 | elf64_alpha_can_merge_gots (a, b) | |
3426 | bfd *a, *b; | |
3427 | { | |
3765b1be | 3428 | int total = alpha_elf_tdata (a)->total_got_size; |
252b5132 RH |
3429 | bfd *bsub; |
3430 | ||
3431 | /* Trivial quick fallout test. */ | |
3765b1be | 3432 | if (total + alpha_elf_tdata (b)->total_got_size <= MAX_GOT_SIZE) |
252b5132 RH |
3433 | return true; |
3434 | ||
3435 | /* By their nature, local .got entries cannot be merged. */ | |
3765b1be | 3436 | if ((total += alpha_elf_tdata (b)->local_got_size) > MAX_GOT_SIZE) |
252b5132 RH |
3437 | return false; |
3438 | ||
3439 | /* Failing the common trivial comparison, we must effectively | |
3440 | perform the merge. Not actually performing the merge means that | |
3441 | we don't have to store undo information in case we fail. */ | |
3442 | for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next) | |
3443 | { | |
3444 | struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub); | |
3445 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr; | |
3446 | int i, n; | |
3447 | ||
d9bc7a44 | 3448 | n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info; |
252b5132 RH |
3449 | for (i = 0; i < n; ++i) |
3450 | { | |
3451 | struct alpha_elf_got_entry *ae, *be; | |
3452 | struct alpha_elf_link_hash_entry *h; | |
3453 | ||
3454 | h = hashes[i]; | |
3455 | while (h->root.root.type == bfd_link_hash_indirect | |
3456 | || h->root.root.type == bfd_link_hash_warning) | |
3457 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; | |
3458 | ||
3459 | for (be = h->got_entries; be ; be = be->next) | |
3460 | { | |
3461 | if (be->use_count == 0) | |
3462 | continue; | |
3463 | if (be->gotobj != b) | |
3464 | continue; | |
3465 | ||
3466 | for (ae = h->got_entries; ae ; ae = ae->next) | |
3765b1be RH |
3467 | if (ae->gotobj == a |
3468 | && ae->reloc_type == be->reloc_type | |
3469 | && ae->addend == be->addend) | |
252b5132 RH |
3470 | goto global_found; |
3471 | ||
3765b1be RH |
3472 | total += alpha_got_entry_size (be->reloc_type); |
3473 | if (total > MAX_GOT_SIZE) | |
252b5132 RH |
3474 | return false; |
3475 | global_found:; | |
3476 | } | |
3477 | } | |
3478 | } | |
3479 | ||
3480 | return true; | |
3481 | } | |
3482 | ||
3483 | /* Actually merge two .got tables. */ | |
3484 | ||
3485 | static void | |
3486 | elf64_alpha_merge_gots (a, b) | |
3487 | bfd *a, *b; | |
3488 | { | |
3765b1be | 3489 | int total = alpha_elf_tdata (a)->total_got_size; |
252b5132 RH |
3490 | bfd *bsub; |
3491 | ||
3492 | /* Remember local expansion. */ | |
3493 | { | |
3765b1be | 3494 | int e = alpha_elf_tdata (b)->local_got_size; |
252b5132 | 3495 | total += e; |
3765b1be | 3496 | alpha_elf_tdata (a)->local_got_size += e; |
252b5132 RH |
3497 | } |
3498 | ||
3499 | for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next) | |
3500 | { | |
3501 | struct alpha_elf_got_entry **local_got_entries; | |
3502 | struct alpha_elf_link_hash_entry **hashes; | |
3503 | Elf_Internal_Shdr *symtab_hdr; | |
3504 | int i, n; | |
3505 | ||
3506 | /* Let the local .got entries know they are part of a new subsegment. */ | |
3507 | local_got_entries = alpha_elf_tdata (bsub)->local_got_entries; | |
3508 | if (local_got_entries) | |
3509 | { | |
3510 | n = elf_tdata (bsub)->symtab_hdr.sh_info; | |
3511 | for (i = 0; i < n; ++i) | |
3512 | { | |
3513 | struct alpha_elf_got_entry *ent; | |
3514 | for (ent = local_got_entries[i]; ent; ent = ent->next) | |
3515 | ent->gotobj = a; | |
3516 | } | |
3517 | } | |
3518 | ||
3519 | /* Merge the global .got entries. */ | |
3520 | hashes = alpha_elf_sym_hashes (bsub); | |
3521 | symtab_hdr = &elf_tdata (bsub)->symtab_hdr; | |
3522 | ||
d9bc7a44 | 3523 | n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info; |
252b5132 RH |
3524 | for (i = 0; i < n; ++i) |
3525 | { | |
3526 | struct alpha_elf_got_entry *ae, *be, **pbe, **start; | |
3527 | struct alpha_elf_link_hash_entry *h; | |
3528 | ||
3529 | h = hashes[i]; | |
3530 | while (h->root.root.type == bfd_link_hash_indirect | |
3531 | || h->root.root.type == bfd_link_hash_warning) | |
3532 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; | |
3533 | ||
3534 | start = &h->got_entries; | |
3535 | for (pbe = start, be = *start; be ; pbe = &be->next, be = be->next) | |
3536 | { | |
3537 | if (be->use_count == 0) | |
3538 | { | |
3539 | *pbe = be->next; | |
3540 | continue; | |
3541 | } | |
3542 | if (be->gotobj != b) | |
3543 | continue; | |
3544 | ||
3545 | for (ae = *start; ae ; ae = ae->next) | |
3765b1be RH |
3546 | if (ae->gotobj == a |
3547 | && ae->reloc_type == be->reloc_type | |
3548 | && ae->addend == be->addend) | |
252b5132 RH |
3549 | { |
3550 | ae->flags |= be->flags; | |
3551 | ae->use_count += be->use_count; | |
3552 | *pbe = be->next; | |
3553 | goto global_found; | |
3554 | } | |
3555 | be->gotobj = a; | |
3765b1be | 3556 | total += alpha_got_entry_size (be->reloc_type); |
252b5132 RH |
3557 | |
3558 | global_found:; | |
3559 | } | |
3560 | } | |
3561 | ||
3562 | alpha_elf_tdata (bsub)->gotobj = a; | |
3563 | } | |
3765b1be | 3564 | alpha_elf_tdata (a)->total_got_size = total; |
252b5132 RH |
3565 | |
3566 | /* Merge the two in_got chains. */ | |
3567 | { | |
3568 | bfd *next; | |
3569 | ||
3570 | bsub = a; | |
3571 | while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL) | |
3572 | bsub = next; | |
3573 | ||
3574 | alpha_elf_tdata (bsub)->in_got_link_next = b; | |
3575 | } | |
3576 | } | |
3577 | ||
3578 | /* Calculate the offsets for the got entries. */ | |
3579 | ||
3580 | static boolean | |
3581 | elf64_alpha_calc_got_offsets_for_symbol (h, arg) | |
3582 | struct alpha_elf_link_hash_entry *h; | |
52b9d213 | 3583 | PTR arg ATTRIBUTE_UNUSED; |
252b5132 RH |
3584 | { |
3585 | struct alpha_elf_got_entry *gotent; | |
3586 | ||
e92d460e AM |
3587 | if (h->root.root.type == bfd_link_hash_warning) |
3588 | h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link; | |
3589 | ||
252b5132 RH |
3590 | for (gotent = h->got_entries; gotent; gotent = gotent->next) |
3591 | if (gotent->use_count > 0) | |
3592 | { | |
3593 | bfd_size_type *plge | |
3594 | = &alpha_elf_tdata (gotent->gotobj)->got->_raw_size; | |
3595 | ||
3596 | gotent->got_offset = *plge; | |
3765b1be | 3597 | *plge += alpha_got_entry_size (gotent->reloc_type); |
252b5132 RH |
3598 | } |
3599 | ||
3600 | return true; | |
3601 | } | |
3602 | ||
3603 | static void | |
3604 | elf64_alpha_calc_got_offsets (info) | |
3605 | struct bfd_link_info *info; | |
3606 | { | |
3607 | bfd *i, *got_list = alpha_elf_hash_table(info)->got_list; | |
3608 | ||
3609 | /* First, zero out the .got sizes, as we may be recalculating the | |
3610 | .got after optimizing it. */ | |
3611 | for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next) | |
3612 | alpha_elf_tdata(i)->got->_raw_size = 0; | |
3613 | ||
3614 | /* Next, fill in the offsets for all the global entries. */ | |
3615 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), | |
3616 | elf64_alpha_calc_got_offsets_for_symbol, | |
3617 | NULL); | |
3618 | ||
3619 | /* Finally, fill in the offsets for the local entries. */ | |
3620 | for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next) | |
3621 | { | |
3622 | bfd_size_type got_offset = alpha_elf_tdata(i)->got->_raw_size; | |
3623 | bfd *j; | |
3624 | ||
3625 | for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next) | |
3626 | { | |
3627 | struct alpha_elf_got_entry **local_got_entries, *gotent; | |
3628 | int k, n; | |
3629 | ||
3630 | local_got_entries = alpha_elf_tdata(j)->local_got_entries; | |
3631 | if (!local_got_entries) | |
3632 | continue; | |
3633 | ||
3634 | for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k) | |
3635 | for (gotent = local_got_entries[k]; gotent; gotent = gotent->next) | |
3636 | if (gotent->use_count > 0) | |
3637 | { | |
3638 | gotent->got_offset = got_offset; | |
3765b1be | 3639 | got_offset += alpha_got_entry_size (gotent->reloc_type); |
252b5132 RH |
3640 | } |
3641 | } | |
3642 | ||
3643 | alpha_elf_tdata(i)->got->_raw_size = got_offset; | |
3644 | alpha_elf_tdata(i)->got->_cooked_size = got_offset; | |
3645 | } | |
3646 | } | |
3647 | ||
3648 | /* Constructs the gots. */ | |
3649 | ||
3650 | static boolean | |
f44f99a5 | 3651 | elf64_alpha_size_got_sections (info) |
252b5132 RH |
3652 | struct bfd_link_info *info; |
3653 | { | |
52b9d213 | 3654 | bfd *i, *got_list, *cur_got_obj = NULL; |
252b5132 RH |
3655 | int something_changed = 0; |
3656 | ||
3657 | got_list = alpha_elf_hash_table (info)->got_list; | |
3658 | ||
3659 | /* On the first time through, pretend we have an existing got list | |
3660 | consisting of all of the input files. */ | |
3661 | if (got_list == NULL) | |
3662 | { | |
3663 | for (i = info->input_bfds; i ; i = i->link_next) | |
3664 | { | |
3665 | bfd *this_got = alpha_elf_tdata (i)->gotobj; | |
3666 | if (this_got == NULL) | |
3667 | continue; | |
3668 | ||
3669 | /* We are assuming no merging has yet ocurred. */ | |
3670 | BFD_ASSERT (this_got == i); | |
3671 | ||
3765b1be | 3672 | if (alpha_elf_tdata (this_got)->total_got_size > MAX_GOT_SIZE) |
252b5132 RH |
3673 | { |
3674 | /* Yikes! A single object file has too many entries. */ | |
3675 | (*_bfd_error_handler) | |
3676 | (_("%s: .got subsegment exceeds 64K (size %d)"), | |
8f615d07 | 3677 | bfd_archive_filename (i), |
3765b1be | 3678 | alpha_elf_tdata (this_got)->total_got_size); |
252b5132 RH |
3679 | return false; |
3680 | } | |
3681 | ||
3682 | if (got_list == NULL) | |
3683 | got_list = this_got; | |
3684 | else | |
3685 | alpha_elf_tdata(cur_got_obj)->got_link_next = this_got; | |
3686 | cur_got_obj = this_got; | |
3687 | } | |
3688 | ||
3689 | /* Strange degenerate case of no got references. */ | |
3690 | if (got_list == NULL) | |
3691 | return true; | |
3692 | ||
3693 | alpha_elf_hash_table (info)->got_list = got_list; | |
3694 | ||
3695 | /* Force got offsets to be recalculated. */ | |
3696 | something_changed = 1; | |
3697 | } | |
3698 | ||
3699 | cur_got_obj = got_list; | |
3700 | i = alpha_elf_tdata(cur_got_obj)->got_link_next; | |
3701 | while (i != NULL) | |
3702 | { | |
3703 | if (elf64_alpha_can_merge_gots (cur_got_obj, i)) | |
3704 | { | |
3705 | elf64_alpha_merge_gots (cur_got_obj, i); | |
3706 | i = alpha_elf_tdata(i)->got_link_next; | |
3707 | alpha_elf_tdata(cur_got_obj)->got_link_next = i; | |
3708 | something_changed = 1; | |
3709 | } | |
3710 | else | |
3711 | { | |
3712 | cur_got_obj = i; | |
3713 | i = alpha_elf_tdata(i)->got_link_next; | |
3714 | } | |
3715 | } | |
3716 | ||
3717 | /* Once the gots have been merged, fill in the got offsets for | |
3718 | everything therein. */ | |
3719 | if (1 || something_changed) | |
3720 | elf64_alpha_calc_got_offsets (info); | |
3721 | ||
3722 | return true; | |
3723 | } | |
3724 | ||
cedb70c5 | 3725 | /* Called from relax_section to rebuild the PLT in light of |
f44f99a5 RH |
3726 | potential changes in the function's status. */ |
3727 | ||
3728 | static boolean | |
3729 | elf64_alpha_size_plt_section (info) | |
3730 | struct bfd_link_info *info; | |
3731 | { | |
3732 | asection *splt, *spltrel; | |
3733 | unsigned long entries; | |
3734 | bfd *dynobj; | |
3735 | ||
3736 | dynobj = elf_hash_table(info)->dynobj; | |
3737 | splt = bfd_get_section_by_name(dynobj, ".plt"); | |
3738 | if (splt == NULL) | |
3739 | return true; | |
3740 | ||
3741 | splt->_raw_size = 0; | |
3742 | ||
3743 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), | |
3744 | elf64_alpha_size_plt_section_1, splt); | |
3745 | ||
3746 | splt->_cooked_size = splt->_raw_size; | |
3747 | ||
3748 | /* Every plt entry requires a JMP_SLOT relocation. */ | |
3749 | spltrel = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
3750 | if (splt->_raw_size) | |
3751 | entries = (splt->_raw_size - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE; | |
3752 | else | |
3753 | entries = 0; | |
3754 | spltrel->_raw_size = entries * sizeof (Elf64_External_Rela); | |
3755 | spltrel->_cooked_size = spltrel->_raw_size; | |
3756 | ||
3757 | return true; | |
3758 | } | |
3759 | ||
3760 | static boolean | |
3761 | elf64_alpha_size_plt_section_1 (h, data) | |
3762 | struct alpha_elf_link_hash_entry *h; | |
3763 | PTR data; | |
3764 | { | |
3765 | asection *splt = (asection *) data; | |
3766 | struct alpha_elf_got_entry *gotent; | |
3767 | ||
3768 | /* If we didn't need an entry before, we still don't. */ | |
3769 | if (!(h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)) | |
3770 | return true; | |
3771 | ||
3772 | /* There must still be a LITERAL got entry for the function. */ | |
3773 | for (gotent = h->got_entries; gotent ; gotent = gotent->next) | |
3774 | if (gotent->reloc_type == R_ALPHA_LITERAL | |
3775 | && gotent->use_count > 0) | |
3776 | break; | |
3777 | ||
3778 | /* If there is, reset the PLT offset. If not, there's no longer | |
3779 | a need for the PLT entry. */ | |
3780 | if (gotent) | |
3781 | { | |
3782 | if (splt->_raw_size == 0) | |
3783 | splt->_raw_size = PLT_HEADER_SIZE; | |
3784 | h->root.plt.offset = splt->_raw_size; | |
3785 | splt->_raw_size += PLT_ENTRY_SIZE; | |
3786 | } | |
3787 | else | |
3788 | { | |
3789 | h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3790 | h->root.plt.offset = -1; | |
3791 | } | |
3792 | ||
3793 | return true; | |
3794 | } | |
3795 | ||
252b5132 RH |
3796 | static boolean |
3797 | elf64_alpha_always_size_sections (output_bfd, info) | |
f44f99a5 | 3798 | bfd *output_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
3799 | struct bfd_link_info *info; |
3800 | { | |
3801 | bfd *i; | |
3802 | ||
3803 | if (info->relocateable) | |
3804 | return true; | |
3805 | ||
3806 | /* First, take care of the indirect symbols created by versioning. */ | |
3807 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), | |
3808 | elf64_alpha_merge_ind_symbols, | |
3809 | NULL); | |
3810 | ||
f44f99a5 | 3811 | if (!elf64_alpha_size_got_sections (info)) |
252b5132 RH |
3812 | return false; |
3813 | ||
3814 | /* Allocate space for all of the .got subsections. */ | |
3815 | i = alpha_elf_hash_table (info)->got_list; | |
3816 | for ( ; i ; i = alpha_elf_tdata(i)->got_link_next) | |
3817 | { | |
3818 | asection *s = alpha_elf_tdata(i)->got; | |
3819 | if (s->_raw_size > 0) | |
3820 | { | |
3821 | s->contents = (bfd_byte *) bfd_zalloc (i, s->_raw_size); | |
3822 | if (s->contents == NULL) | |
3823 | return false; | |
3824 | } | |
3825 | } | |
3826 | ||
3827 | return true; | |
3828 | } | |
3829 | ||
3765b1be RH |
3830 | /* The number of dynamic relocations required by a static relocation. */ |
3831 | ||
3832 | static int | |
3833 | alpha_dynamic_entries_for_reloc (r_type, dynamic, shared) | |
3834 | int r_type, dynamic, shared; | |
3835 | { | |
3836 | switch (r_type) | |
3837 | { | |
3838 | /* May appear in GOT entries. */ | |
3839 | case R_ALPHA_TLSGD: | |
3840 | return (dynamic ? 2 : shared ? 1 : 0); | |
3841 | case R_ALPHA_TLSLDM: | |
3842 | return shared; | |
3843 | case R_ALPHA_LITERAL: | |
3844 | return dynamic || shared; | |
3845 | case R_ALPHA_GOTDTPREL: | |
3846 | case R_ALPHA_GOTTPREL: | |
3847 | return dynamic; | |
3848 | ||
3849 | /* May appear in data sections. */ | |
3850 | case R_ALPHA_REFLONG: | |
3851 | case R_ALPHA_REFQUAD: | |
3852 | return dynamic || shared; | |
3853 | case R_ALPHA_SREL64: | |
3854 | case R_ALPHA_TPREL64: | |
3855 | return dynamic; | |
3856 | ||
3857 | /* Everything else is illegal. We'll issue an error during | |
3858 | relocate_section. */ | |
3859 | default: | |
3860 | return 0; | |
3861 | } | |
3862 | } | |
3863 | ||
252b5132 RH |
3864 | /* Work out the sizes of the dynamic relocation entries. */ |
3865 | ||
3866 | static boolean | |
3867 | elf64_alpha_calc_dynrel_sizes (h, info) | |
3868 | struct alpha_elf_link_hash_entry *h; | |
3869 | struct bfd_link_info *info; | |
3870 | { | |
3765b1be RH |
3871 | boolean dynamic; |
3872 | struct alpha_elf_reloc_entry *relent; | |
f44f99a5 | 3873 | unsigned long entries; |
3765b1be | 3874 | |
e92d460e AM |
3875 | if (h->root.root.type == bfd_link_hash_warning) |
3876 | h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link; | |
3877 | ||
252b5132 RH |
3878 | /* If the symbol was defined as a common symbol in a regular object |
3879 | file, and there was no definition in any dynamic object, then the | |
3880 | linker will have allocated space for the symbol in a common | |
3881 | section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been | |
3882 | set. This is done for dynamic symbols in | |
3883 | elf_adjust_dynamic_symbol but this is not done for non-dynamic | |
3884 | symbols, somehow. */ | |
3885 | if (((h->root.elf_link_hash_flags | |
3886 | & (ELF_LINK_HASH_DEF_REGULAR | |
3887 | | ELF_LINK_HASH_REF_REGULAR | |
3888 | | ELF_LINK_HASH_DEF_DYNAMIC)) | |
3889 | == ELF_LINK_HASH_REF_REGULAR) | |
3890 | && (h->root.root.type == bfd_link_hash_defined | |
3891 | || h->root.root.type == bfd_link_hash_defweak) | |
3892 | && !(h->root.root.u.def.section->owner->flags & DYNAMIC)) | |
f44f99a5 | 3893 | h->root.elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
252b5132 RH |
3894 | |
3895 | /* If the symbol is dynamic, we'll need all the relocations in their | |
3896 | natural form. If this is a shared object, and it has been forced | |
3897 | local, we'll need the same number of RELATIVE relocations. */ | |
3898 | ||
3765b1be | 3899 | dynamic = alpha_elf_dynamic_symbol_p (&h->root, info); |
252b5132 | 3900 | |
3765b1be RH |
3901 | for (relent = h->reloc_entries; relent; relent = relent->next) |
3902 | { | |
3903 | entries = alpha_dynamic_entries_for_reloc (relent->rtype, dynamic, | |
3904 | info->shared); | |
3905 | if (entries) | |
3906 | { | |
3907 | relent->srel->_raw_size += | |
3908 | entries * sizeof (Elf64_External_Rela) * relent->count; | |
3909 | if (relent->reltext) | |
3910 | info->flags |= DT_TEXTREL; | |
3911 | } | |
3912 | } | |
252b5132 | 3913 | |
f44f99a5 RH |
3914 | return true; |
3915 | } | |
3916 | ||
3917 | /* Set the sizes of the dynamic relocation sections. */ | |
3918 | ||
3919 | static boolean | |
3920 | elf64_alpha_size_rela_got_section (info) | |
3921 | struct bfd_link_info *info; | |
3922 | { | |
3923 | unsigned long entries; | |
3924 | bfd *i, *dynobj; | |
3925 | asection *srel; | |
3926 | ||
3927 | /* Shared libraries often require RELATIVE relocs, and some relocs | |
3928 | require attention for the main application as well. */ | |
cedb70c5 | 3929 | |
f44f99a5 RH |
3930 | entries = 0; |
3931 | for (i = alpha_elf_hash_table(info)->got_list; | |
3932 | i ; i = alpha_elf_tdata(i)->got_link_next) | |
3933 | { | |
3934 | bfd *j; | |
3935 | ||
3936 | for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next) | |
3937 | { | |
3938 | struct alpha_elf_got_entry **local_got_entries, *gotent; | |
3939 | int k, n; | |
3940 | ||
3941 | local_got_entries = alpha_elf_tdata(j)->local_got_entries; | |
3942 | if (!local_got_entries) | |
3943 | continue; | |
3944 | ||
3945 | for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k) | |
3946 | for (gotent = local_got_entries[k]; | |
3947 | gotent ; gotent = gotent->next) | |
3948 | if (gotent->use_count > 0) | |
3949 | entries += (alpha_dynamic_entries_for_reloc | |
3950 | (gotent->reloc_type, 0, info->shared)); | |
3951 | } | |
3952 | } | |
3953 | ||
3954 | dynobj = elf_hash_table(info)->dynobj; | |
3955 | srel = bfd_get_section_by_name (dynobj, ".rela.got"); | |
3956 | if (!srel) | |
3957 | { | |
3958 | BFD_ASSERT (entries == 0); | |
3959 | return true; | |
3960 | } | |
3961 | srel->_raw_size = sizeof (Elf64_External_Rela) * entries; | |
3962 | ||
3963 | /* Now do the non-local symbols. */ | |
3964 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), | |
3965 | elf64_alpha_size_rela_got_1, info); | |
3966 | ||
3967 | srel->_cooked_size = srel->_raw_size; | |
3968 | ||
3969 | return true; | |
3970 | } | |
3971 | ||
3972 | /* Subroutine of elf64_alpha_size_rela_got_section for doing the | |
3973 | global symbols. */ | |
3974 | ||
3975 | static boolean | |
3976 | elf64_alpha_size_rela_got_1 (h, info) | |
3977 | struct alpha_elf_link_hash_entry *h; | |
3978 | struct bfd_link_info *info; | |
3979 | { | |
3980 | boolean dynamic; | |
3981 | struct alpha_elf_got_entry *gotent; | |
3982 | unsigned long entries; | |
3983 | ||
3984 | if (h->root.root.type == bfd_link_hash_warning) | |
3985 | h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link; | |
3986 | ||
3987 | /* If the symbol is dynamic, we'll need all the relocations in their | |
3988 | natural form. If this is a shared object, and it has been forced | |
3989 | local, we'll need the same number of RELATIVE relocations. */ | |
3990 | ||
3991 | dynamic = alpha_elf_dynamic_symbol_p (&h->root, info); | |
3992 | ||
3765b1be RH |
3993 | entries = 0; |
3994 | for (gotent = h->got_entries; gotent ; gotent = gotent->next) | |
f44f99a5 RH |
3995 | if (gotent->use_count > 0) |
3996 | entries += alpha_dynamic_entries_for_reloc (gotent->reloc_type, | |
3997 | dynamic, info->shared); | |
252b5132 | 3998 | |
3765b1be RH |
3999 | /* If we are using a .plt entry, subtract one, as the first |
4000 | reference uses a .rela.plt entry instead. */ | |
4001 | if (h->root.plt.offset != MINUS_ONE) | |
4002 | entries--; | |
252b5132 | 4003 | |
3765b1be RH |
4004 | if (entries > 0) |
4005 | { | |
4006 | bfd *dynobj = elf_hash_table(info)->dynobj; | |
4007 | asection *srel = bfd_get_section_by_name (dynobj, ".rela.got"); | |
4008 | BFD_ASSERT (srel != NULL); | |
4009 | srel->_raw_size += sizeof (Elf64_External_Rela) * entries; | |
252b5132 RH |
4010 | } |
4011 | ||
4012 | return true; | |
4013 | } | |
4014 | ||
4015 | /* Set the sizes of the dynamic sections. */ | |
4016 | ||
4017 | static boolean | |
4018 | elf64_alpha_size_dynamic_sections (output_bfd, info) | |
24a35864 | 4019 | bfd *output_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
4020 | struct bfd_link_info *info; |
4021 | { | |
4022 | bfd *dynobj; | |
4023 | asection *s; | |
252b5132 RH |
4024 | boolean relplt; |
4025 | ||
4026 | dynobj = elf_hash_table(info)->dynobj; | |
4027 | BFD_ASSERT(dynobj != NULL); | |
4028 | ||
4029 | if (elf_hash_table (info)->dynamic_sections_created) | |
4030 | { | |
4031 | /* Set the contents of the .interp section to the interpreter. */ | |
4032 | if (!info->shared) | |
4033 | { | |
4034 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
4035 | BFD_ASSERT (s != NULL); | |
4036 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
4037 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
4038 | } | |
4039 | ||
4040 | /* Now that we've seen all of the input files, we can decide which | |
4041 | symbols need dynamic relocation entries and which don't. We've | |
4042 | collected information in check_relocs that we can now apply to | |
4043 | size the dynamic relocation sections. */ | |
4044 | alpha_elf_link_hash_traverse (alpha_elf_hash_table (info), | |
f44f99a5 | 4045 | elf64_alpha_calc_dynrel_sizes, info); |
252b5132 | 4046 | |
f44f99a5 | 4047 | elf64_alpha_size_rela_got_section (info); |
252b5132 RH |
4048 | } |
4049 | /* else we're not dynamic and by definition we don't need such things. */ | |
4050 | ||
4051 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
4052 | determined the sizes of the various dynamic sections. Allocate | |
4053 | memory for them. */ | |
252b5132 RH |
4054 | relplt = false; |
4055 | for (s = dynobj->sections; s != NULL; s = s->next) | |
4056 | { | |
4057 | const char *name; | |
4058 | boolean strip; | |
4059 | ||
4060 | if (!(s->flags & SEC_LINKER_CREATED)) | |
4061 | continue; | |
4062 | ||
4063 | /* It's OK to base decisions on the section name, because none | |
4064 | of the dynobj section names depend upon the input files. */ | |
4065 | name = bfd_get_section_name (dynobj, s); | |
4066 | ||
4067 | /* If we don't need this section, strip it from the output file. | |
4068 | This is to handle .rela.bss and .rela.plt. We must create it | |
4069 | in create_dynamic_sections, because it must be created before | |
4070 | the linker maps input sections to output sections. The | |
4071 | linker does that before adjust_dynamic_symbol is called, and | |
4072 | it is that function which decides whether anything needs to | |
4073 | go into these sections. */ | |
4074 | ||
4075 | strip = false; | |
4076 | ||
4077 | if (strncmp (name, ".rela", 5) == 0) | |
4078 | { | |
4079 | strip = (s->_raw_size == 0); | |
4080 | ||
4081 | if (!strip) | |
4082 | { | |
252b5132 RH |
4083 | if (strcmp(name, ".rela.plt") == 0) |
4084 | relplt = true; | |
4085 | ||
4086 | /* We use the reloc_count field as a counter if we need | |
4087 | to copy relocs into the output file. */ | |
4088 | s->reloc_count = 0; | |
4089 | } | |
4090 | } | |
4091 | else if (strcmp (name, ".plt") != 0) | |
4092 | { | |
4093 | /* It's not one of our dynamic sections, so don't allocate space. */ | |
4094 | continue; | |
4095 | } | |
4096 | ||
4097 | if (strip) | |
7f8d5fc9 | 4098 | _bfd_strip_section_from_output (info, s); |
252b5132 RH |
4099 | else |
4100 | { | |
4101 | /* Allocate memory for the section contents. */ | |
dc810e39 | 4102 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); |
252b5132 RH |
4103 | if (s->contents == NULL && s->_raw_size != 0) |
4104 | return false; | |
4105 | } | |
4106 | } | |
4107 | ||
252b5132 RH |
4108 | if (elf_hash_table (info)->dynamic_sections_created) |
4109 | { | |
4110 | /* Add some entries to the .dynamic section. We fill in the | |
4111 | values later, in elf64_alpha_finish_dynamic_sections, but we | |
4112 | must add the entries now so that we get the correct size for | |
4113 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
4114 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
4115 | #define add_dynamic_entry(TAG, VAL) \ |
4116 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
4117 | ||
252b5132 RH |
4118 | if (!info->shared) |
4119 | { | |
dc810e39 | 4120 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
252b5132 RH |
4121 | return false; |
4122 | } | |
4123 | ||
252b5132 RH |
4124 | if (relplt) |
4125 | { | |
c0647bfc JT |
4126 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
4127 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
dc810e39 AM |
4128 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) |
4129 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
252b5132 RH |
4130 | return false; |
4131 | } | |
4132 | ||
dc810e39 AM |
4133 | if (!add_dynamic_entry (DT_RELA, 0) |
4134 | || !add_dynamic_entry (DT_RELASZ, 0) | |
4135 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
252b5132 RH |
4136 | return false; |
4137 | ||
fcfbdf31 | 4138 | if (info->flags & DF_TEXTREL) |
252b5132 | 4139 | { |
dc810e39 | 4140 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
252b5132 RH |
4141 | return false; |
4142 | } | |
4143 | } | |
dc810e39 | 4144 | #undef add_dynamic_entry |
252b5132 RH |
4145 | |
4146 | return true; | |
4147 | } | |
4148 | ||
4a67a098 RH |
4149 | /* Relocate an Alpha ELF section for a relocatable link. |
4150 | ||
4151 | We don't have to change anything unless the reloc is against a section | |
4152 | symbol, in which case we have to adjust according to where the section | |
4153 | symbol winds up in the output section. */ | |
4154 | ||
4155 | static boolean | |
4156 | elf64_alpha_relocate_section_r (output_bfd, info, input_bfd, input_section, | |
4157 | contents, relocs, local_syms, local_sections) | |
4158 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
4159 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
4160 | bfd *input_bfd; | |
4161 | asection *input_section; | |
4162 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
4163 | Elf_Internal_Rela *relocs; | |
4164 | Elf_Internal_Sym *local_syms; | |
4165 | asection **local_sections; | |
4166 | { | |
4167 | unsigned long symtab_hdr_sh_info; | |
4168 | Elf_Internal_Rela *rel; | |
4169 | Elf_Internal_Rela *relend; | |
4170 | boolean ret_val = true; | |
4171 | ||
4172 | symtab_hdr_sh_info = elf_tdata (input_bfd)->symtab_hdr.sh_info; | |
4173 | ||
4174 | relend = relocs + input_section->reloc_count; | |
4175 | for (rel = relocs; rel < relend; rel++) | |
4176 | { | |
4177 | unsigned long r_symndx; | |
4178 | Elf_Internal_Sym *sym; | |
4179 | asection *sec; | |
4180 | unsigned long r_type; | |
4181 | ||
4182 | r_type = ELF64_R_TYPE(rel->r_info); | |
4183 | if (r_type >= R_ALPHA_max) | |
4184 | { | |
4185 | (*_bfd_error_handler) | |
4186 | (_("%s: unknown relocation type %d"), | |
4187 | bfd_archive_filename (input_bfd), (int)r_type); | |
4188 | bfd_set_error (bfd_error_bad_value); | |
4189 | ret_val = false; | |
4190 | continue; | |
4191 | } | |
4192 | ||
4193 | r_symndx = ELF64_R_SYM(rel->r_info); | |
4194 | ||
4195 | /* The symbol associated with GPDISP and LITUSE is | |
4196 | immaterial. Only the addend is significant. */ | |
4197 | if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE) | |
4198 | continue; | |
4199 | ||
4200 | if (r_symndx < symtab_hdr_sh_info) | |
4201 | { | |
4202 | sym = local_syms + r_symndx; | |
4203 | if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) | |
4204 | { | |
4205 | sec = local_sections[r_symndx]; | |
4206 | rel->r_addend += sec->output_offset + sym->st_value; | |
4207 | } | |
4208 | } | |
4209 | } | |
4210 | ||
4211 | return ret_val; | |
4212 | } | |
4213 | ||
252b5132 RH |
4214 | /* Relocate an Alpha ELF section. */ |
4215 | ||
4216 | static boolean | |
4217 | elf64_alpha_relocate_section (output_bfd, info, input_bfd, input_section, | |
4218 | contents, relocs, local_syms, local_sections) | |
4219 | bfd *output_bfd; | |
4220 | struct bfd_link_info *info; | |
4221 | bfd *input_bfd; | |
4222 | asection *input_section; | |
4223 | bfd_byte *contents; | |
4224 | Elf_Internal_Rela *relocs; | |
4225 | Elf_Internal_Sym *local_syms; | |
4226 | asection **local_sections; | |
4227 | { | |
4a67a098 | 4228 | Elf_Internal_Shdr *symtab_hdr; |
252b5132 RH |
4229 | Elf_Internal_Rela *rel; |
4230 | Elf_Internal_Rela *relend; | |
4a67a098 RH |
4231 | struct elf_link_tls_segment *tls_segment; |
4232 | asection *sgot, *srel, *srelgot; | |
4233 | bfd *dynobj, *gotobj; | |
4234 | bfd_vma gp, tp_base, dtp_base; | |
4235 | struct alpha_elf_got_entry **local_got_entries; | |
4236 | boolean ret_val; | |
4237 | const char *section_name; | |
252b5132 | 4238 | |
4a67a098 RH |
4239 | /* Handle relocatable links with a smaller loop. */ |
4240 | if (info->relocateable) | |
4241 | return elf64_alpha_relocate_section_r (output_bfd, info, input_bfd, | |
4242 | input_section, contents, relocs, | |
4243 | local_syms, local_sections); | |
4244 | ||
4245 | /* This is a final link. */ | |
4246 | ||
4247 | ret_val = true; | |
252b5132 | 4248 | |
4a67a098 | 4249 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
3765b1be | 4250 | |
4a67a098 RH |
4251 | dynobj = elf_hash_table (info)->dynobj; |
4252 | if (dynobj) | |
4253 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | |
4254 | else | |
4255 | srelgot = NULL; | |
4256 | ||
4257 | section_name = (bfd_elf_string_from_elf_section | |
4258 | (input_bfd, elf_elfheader(input_bfd)->e_shstrndx, | |
4259 | elf_section_data(input_section)->rel_hdr.sh_name)); | |
4260 | BFD_ASSERT(section_name != NULL); | |
4261 | srel = bfd_get_section_by_name (dynobj, section_name); | |
3765b1be | 4262 | |
4a67a098 RH |
4263 | /* Find the gp value for this input bfd. */ |
4264 | gotobj = alpha_elf_tdata (input_bfd)->gotobj; | |
4265 | if (gotobj) | |
4266 | { | |
4267 | sgot = alpha_elf_tdata (gotobj)->got; | |
4268 | gp = _bfd_get_gp_value (gotobj); | |
4269 | if (gp == 0) | |
252b5132 | 4270 | { |
4a67a098 RH |
4271 | gp = (sgot->output_section->vma |
4272 | + sgot->output_offset | |
4273 | + 0x8000); | |
4274 | _bfd_set_gp_value (gotobj, gp); | |
4275 | } | |
4276 | } | |
4277 | else | |
4278 | { | |
4279 | sgot = NULL; | |
4280 | gp = 0; | |
4281 | } | |
3765b1be | 4282 | |
4a67a098 RH |
4283 | local_got_entries = alpha_elf_tdata(input_bfd)->local_got_entries; |
4284 | ||
4285 | tls_segment = elf_hash_table (info)->tls_segment; | |
4286 | if (tls_segment) | |
4287 | { | |
4288 | dtp_base = alpha_get_dtprel_base (tls_segment); | |
4289 | tp_base = alpha_get_tprel_base (tls_segment); | |
252b5132 | 4290 | } |
4a67a098 RH |
4291 | else |
4292 | dtp_base = tp_base = 0; | |
252b5132 | 4293 | |
252b5132 | 4294 | relend = relocs + input_section->reloc_count; |
4a67a098 | 4295 | for (rel = relocs; rel < relend; rel++) |
252b5132 | 4296 | { |
4a67a098 | 4297 | struct alpha_elf_link_hash_entry *h = NULL; |
3765b1be RH |
4298 | struct alpha_elf_got_entry *gotent; |
4299 | bfd_reloc_status_type r; | |
252b5132 RH |
4300 | reloc_howto_type *howto; |
4301 | unsigned long r_symndx; | |
4a67a098 RH |
4302 | Elf_Internal_Sym *sym = NULL; |
4303 | asection *sec = NULL; | |
3765b1be | 4304 | bfd_vma value; |
dc810e39 | 4305 | bfd_vma addend; |
3765b1be | 4306 | boolean dynamic_symbol_p; |
4a67a098 | 4307 | boolean undef_weak_ref = false; |
3765b1be | 4308 | unsigned long r_type; |
252b5132 RH |
4309 | |
4310 | r_type = ELF64_R_TYPE(rel->r_info); | |
3765b1be | 4311 | if (r_type >= R_ALPHA_max) |
252b5132 | 4312 | { |
3765b1be RH |
4313 | (*_bfd_error_handler) |
4314 | (_("%s: unknown relocation type %d"), | |
4315 | bfd_archive_filename (input_bfd), (int)r_type); | |
252b5132 | 4316 | bfd_set_error (bfd_error_bad_value); |
3765b1be RH |
4317 | ret_val = false; |
4318 | continue; | |
252b5132 | 4319 | } |
252b5132 | 4320 | |
3765b1be | 4321 | howto = elf64_alpha_howto_table + r_type; |
252b5132 RH |
4322 | r_symndx = ELF64_R_SYM(rel->r_info); |
4323 | ||
252b5132 RH |
4324 | if (r_symndx < symtab_hdr->sh_info) |
4325 | { | |
4326 | sym = local_syms + r_symndx; | |
4327 | sec = local_sections[r_symndx]; | |
3765b1be RH |
4328 | value = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
4329 | ||
4a67a098 RH |
4330 | if (local_got_entries) |
4331 | gotent = local_got_entries[r_symndx]; | |
4332 | else | |
4333 | gotent = NULL; | |
3765b1be RH |
4334 | |
4335 | /* Need to adjust local GOT entries' addends for SEC_MERGE | |
4336 | unless it has been done already. */ | |
4337 | if ((sec->flags & SEC_MERGE) | |
048d873d RH |
4338 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION |
4339 | && (elf_section_data (sec)->sec_info_type | |
4340 | == ELF_INFO_TYPE_MERGE) | |
4341 | && gotent | |
4342 | && !gotent->reloc_xlated) | |
3765b1be RH |
4343 | { |
4344 | struct alpha_elf_got_entry *ent; | |
4345 | asection *msec; | |
4346 | ||
4347 | for (ent = gotent; ent; ent = ent->next) | |
4348 | { | |
4349 | ent->reloc_xlated = 1; | |
4350 | if (ent->use_count == 0) | |
4351 | continue; | |
4352 | msec = sec; | |
4353 | ent->addend = | |
4354 | _bfd_merged_section_offset (output_bfd, &msec, | |
4355 | elf_section_data (sec)-> | |
4356 | sec_info, | |
4357 | sym->st_value + ent->addend, | |
4358 | (bfd_vma) 0); | |
4359 | ent->addend -= sym->st_value; | |
4360 | ent->addend += msec->output_section->vma | |
4361 | + msec->output_offset | |
4362 | - sec->output_section->vma | |
4363 | - sec->output_offset; | |
4364 | } | |
4365 | } | |
4366 | ||
4367 | dynamic_symbol_p = false; | |
252b5132 RH |
4368 | } |
4369 | else | |
4370 | { | |
4371 | h = alpha_elf_sym_hashes (input_bfd)[r_symndx - symtab_hdr->sh_info]; | |
4372 | ||
4373 | while (h->root.root.type == bfd_link_hash_indirect | |
4374 | || h->root.root.type == bfd_link_hash_warning) | |
4375 | h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; | |
4376 | ||
3765b1be | 4377 | value = 0; |
252b5132 RH |
4378 | if (h->root.root.type == bfd_link_hash_defined |
4379 | || h->root.root.type == bfd_link_hash_defweak) | |
4380 | { | |
4381 | sec = h->root.root.u.def.section; | |
4382 | ||
3765b1be RH |
4383 | /* Detect the cases that sym_sec->output_section is |
4384 | expected to be NULL -- all cases in which the symbol | |
4385 | is defined in another shared module. This includes | |
4386 | PLT relocs for which we've created a PLT entry and | |
4387 | other relocs for which we're prepared to create | |
4388 | dynamic relocations. */ | |
4389 | /* ??? Just accept it NULL and continue. */ | |
4390 | ||
4391 | if (sec->output_section != NULL) | |
4392 | value = (h->root.root.u.def.value | |
4393 | + sec->output_section->vma | |
4394 | + sec->output_offset); | |
252b5132 RH |
4395 | } |
4396 | else if (h->root.root.type == bfd_link_hash_undefweak) | |
3765b1be | 4397 | undef_weak_ref = true; |
671bae9c NC |
4398 | else if (info->shared |
4399 | && (!info->symbolic || info->allow_shlib_undefined) | |
3a27a730 | 4400 | && !info->no_undefined |
edb72b3b | 4401 | && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT) |
3765b1be | 4402 | ; |
252b5132 RH |
4403 | else |
4404 | { | |
4405 | if (!((*info->callbacks->undefined_symbol) | |
4406 | (info, h->root.root.root.string, input_bfd, | |
5cc7c785 | 4407 | input_section, rel->r_offset, |
3a27a730 | 4408 | (!info->shared || info->no_undefined |
edb72b3b | 4409 | || ELF_ST_VISIBILITY (h->root.other))))) |
3765b1be RH |
4410 | return false; |
4411 | ret_val = false; | |
4412 | continue; | |
252b5132 | 4413 | } |
3765b1be RH |
4414 | |
4415 | dynamic_symbol_p = alpha_elf_dynamic_symbol_p (&h->root, info); | |
4416 | gotent = h->got_entries; | |
252b5132 | 4417 | } |
3765b1be | 4418 | |
252b5132 | 4419 | addend = rel->r_addend; |
3765b1be RH |
4420 | value += addend; |
4421 | ||
4422 | /* Search for the proper got entry. */ | |
4423 | for (; gotent ; gotent = gotent->next) | |
4424 | if (gotent->gotobj == gotobj | |
4425 | && gotent->reloc_type == r_type | |
4426 | && gotent->addend == addend) | |
4427 | break; | |
252b5132 RH |
4428 | |
4429 | switch (r_type) | |
4430 | { | |
4431 | case R_ALPHA_GPDISP: | |
4432 | { | |
4433 | bfd_byte *p_ldah, *p_lda; | |
4434 | ||
4435 | BFD_ASSERT(gp != 0); | |
4436 | ||
3765b1be RH |
4437 | value = (input_section->output_section->vma |
4438 | + input_section->output_offset | |
4439 | + rel->r_offset); | |
252b5132 | 4440 | |
3765b1be | 4441 | p_ldah = contents + rel->r_offset; |
252b5132 RH |
4442 | p_lda = p_ldah + rel->r_addend; |
4443 | ||
3765b1be | 4444 | r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - value, |
252b5132 RH |
4445 | p_ldah, p_lda); |
4446 | } | |
4447 | break; | |
4448 | ||
252b5132 | 4449 | case R_ALPHA_LITERAL: |
3765b1be RH |
4450 | BFD_ASSERT(sgot != NULL); |
4451 | BFD_ASSERT(gp != 0); | |
4452 | BFD_ASSERT(gotent != NULL); | |
4453 | BFD_ASSERT(gotent->use_count >= 1); | |
f7460f5f | 4454 | |
3765b1be RH |
4455 | if (!gotent->reloc_done) |
4456 | { | |
4457 | gotent->reloc_done = 1; | |
252b5132 | 4458 | |
3765b1be RH |
4459 | bfd_put_64 (output_bfd, value, |
4460 | sgot->contents + gotent->got_offset); | |
252b5132 | 4461 | |
3765b1be RH |
4462 | /* If the symbol has been forced local, output a |
4463 | RELATIVE reloc, otherwise it will be handled in | |
4464 | finish_dynamic_symbol. */ | |
4465 | if (info->shared && !dynamic_symbol_p) | |
4466 | { | |
4467 | Elf_Internal_Rela outrel; | |
252b5132 | 4468 | |
3765b1be | 4469 | BFD_ASSERT(srelgot != NULL); |
252b5132 | 4470 | |
3765b1be RH |
4471 | outrel.r_offset = (sgot->output_section->vma |
4472 | + sgot->output_offset | |
4473 | + gotent->got_offset); | |
4474 | outrel.r_info = ELF64_R_INFO (0, R_ALPHA_RELATIVE); | |
4475 | outrel.r_addend = value; | |
252b5132 | 4476 | |
3765b1be RH |
4477 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, |
4478 | ((Elf64_External_Rela *) | |
4479 | srelgot->contents) | |
4480 | + srelgot->reloc_count++); | |
4481 | BFD_ASSERT (sizeof (Elf64_External_Rela) | |
4482 | * srelgot->reloc_count | |
4483 | <= srelgot->_cooked_size); | |
4484 | } | |
4485 | } | |
252b5132 | 4486 | |
3765b1be RH |
4487 | value = (sgot->output_section->vma |
4488 | + sgot->output_offset | |
4489 | + gotent->got_offset); | |
4490 | value -= gp; | |
252b5132 RH |
4491 | goto default_reloc; |
4492 | ||
dfe57ca0 | 4493 | case R_ALPHA_GPREL16: |
252b5132 RH |
4494 | case R_ALPHA_GPREL32: |
4495 | case R_ALPHA_GPRELLOW: | |
3765b1be | 4496 | if (dynamic_symbol_p) |
f16fbd61 RH |
4497 | { |
4498 | (*_bfd_error_handler) | |
4499 | (_("%s: gp-relative relocation against dynamic symbol %s"), | |
8f615d07 | 4500 | bfd_archive_filename (input_bfd), h->root.root.root.string); |
f16fbd61 RH |
4501 | ret_val = false; |
4502 | } | |
252b5132 | 4503 | BFD_ASSERT(gp != 0); |
3765b1be | 4504 | value -= gp; |
252b5132 RH |
4505 | goto default_reloc; |
4506 | ||
4507 | case R_ALPHA_GPRELHIGH: | |
3765b1be | 4508 | if (dynamic_symbol_p) |
f16fbd61 RH |
4509 | { |
4510 | (*_bfd_error_handler) | |
4511 | (_("%s: gp-relative relocation against dynamic symbol %s"), | |
8f615d07 | 4512 | bfd_archive_filename (input_bfd), h->root.root.root.string); |
f16fbd61 RH |
4513 | ret_val = false; |
4514 | } | |
252b5132 | 4515 | BFD_ASSERT(gp != 0); |
3765b1be RH |
4516 | value -= gp; |
4517 | value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1); | |
252b5132 RH |
4518 | goto default_reloc; |
4519 | ||
252b5132 | 4520 | case R_ALPHA_HINT: |
f94952df RH |
4521 | /* A call to a dynamic symbol is definitely out of range of |
4522 | the 16-bit displacement. Don't bother writing anything. */ | |
3765b1be | 4523 | if (dynamic_symbol_p) |
f94952df RH |
4524 | { |
4525 | r = bfd_reloc_ok; | |
4526 | break; | |
4527 | } | |
3765b1be RH |
4528 | /* The regular PC-relative stuff measures from the start of |
4529 | the instruction rather than the end. */ | |
4530 | value -= 4; | |
4531 | goto default_reloc; | |
f94952df RH |
4532 | |
4533 | case R_ALPHA_BRADDR: | |
3765b1be RH |
4534 | if (dynamic_symbol_p) |
4535 | { | |
4536 | (*_bfd_error_handler) | |
4537 | (_("%s: pc-relative relocation against dynamic symbol %s"), | |
4538 | bfd_archive_filename (input_bfd), h->root.root.root.string); | |
4539 | ret_val = false; | |
4540 | } | |
252b5132 RH |
4541 | /* The regular PC-relative stuff measures from the start of |
4542 | the instruction rather than the end. */ | |
3765b1be | 4543 | value -= 4; |
252b5132 RH |
4544 | goto default_reloc; |
4545 | ||
7793f4d0 RH |
4546 | case R_ALPHA_BRSGP: |
4547 | { | |
4548 | int other; | |
4549 | const char *name; | |
4550 | ||
4551 | /* The regular PC-relative stuff measures from the start of | |
4552 | the instruction rather than the end. */ | |
3765b1be | 4553 | value -= 4; |
7793f4d0 | 4554 | |
ccf00ab6 RH |
4555 | /* The source and destination gp must be the same. Note that |
4556 | the source will always have an assigned gp, since we forced | |
4557 | one in check_relocs, but that the destination may not, as | |
cedb70c5 | 4558 | it might not have had any relocations at all. Also take |
ccf00ab6 RH |
4559 | care not to crash if H is an undefined symbol. */ |
4560 | if (h != NULL && sec != NULL | |
4561 | && alpha_elf_tdata (sec->owner)->gotobj | |
7793f4d0 RH |
4562 | && gotobj != alpha_elf_tdata (sec->owner)->gotobj) |
4563 | { | |
7793f4d0 RH |
4564 | (*_bfd_error_handler) |
4565 | (_("%s: change in gp: BRSGP %s"), | |
ccf00ab6 | 4566 | bfd_archive_filename (input_bfd), h->root.root.root.string); |
7793f4d0 RH |
4567 | ret_val = false; |
4568 | } | |
4569 | ||
4570 | /* The symbol should be marked either NOPV or STD_GPLOAD. */ | |
4571 | if (h != NULL) | |
4572 | other = h->root.other; | |
4573 | else | |
4574 | other = sym->st_other; | |
4575 | switch (other & STO_ALPHA_STD_GPLOAD) | |
4576 | { | |
4577 | case STO_ALPHA_NOPV: | |
4578 | break; | |
4579 | case STO_ALPHA_STD_GPLOAD: | |
64e04ecd | 4580 | value += 8; |
7793f4d0 RH |
4581 | break; |
4582 | default: | |
4583 | if (h != NULL) | |
4584 | name = h->root.root.root.string; | |
4585 | else | |
4586 | { | |
4587 | name = (bfd_elf_string_from_elf_section | |
4588 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
4589 | if (name == NULL) | |
4590 | name = _("<unknown>"); | |
4591 | else if (name[0] == 0) | |
4592 | name = bfd_section_name (input_bfd, sec); | |
4593 | } | |
4594 | (*_bfd_error_handler) | |
4595 | (_("%s: !samegp reloc against symbol without .prologue: %s"), | |
4596 | bfd_archive_filename (input_bfd), name); | |
4597 | ret_val = false; | |
4598 | break; | |
4599 | } | |
4600 | ||
4601 | goto default_reloc; | |
4602 | } | |
4603 | ||
252b5132 RH |
4604 | case R_ALPHA_REFLONG: |
4605 | case R_ALPHA_REFQUAD: | |
3765b1be RH |
4606 | case R_ALPHA_DTPREL64: |
4607 | case R_ALPHA_TPREL64: | |
252b5132 RH |
4608 | { |
4609 | Elf_Internal_Rela outrel; | |
252b5132 RH |
4610 | |
4611 | /* Careful here to remember RELATIVE relocations for global | |
4612 | variables for symbolic shared objects. */ | |
4613 | ||
3765b1be | 4614 | if (dynamic_symbol_p) |
252b5132 RH |
4615 | { |
4616 | BFD_ASSERT(h->root.dynindx != -1); | |
3765b1be | 4617 | outrel.r_info = ELF64_R_INFO (h->root.dynindx, r_type); |
252b5132 | 4618 | outrel.r_addend = addend; |
3765b1be RH |
4619 | addend = 0, value = 0; |
4620 | } | |
4621 | else if (r_type == R_ALPHA_DTPREL64) | |
4622 | { | |
4623 | BFD_ASSERT(tls_segment != NULL); | |
4624 | value -= dtp_base; | |
4625 | goto default_reloc; | |
4626 | } | |
4627 | else if (r_type == R_ALPHA_TPREL64) | |
4628 | { | |
4629 | BFD_ASSERT(tls_segment != NULL); | |
4630 | value -= dtp_base; | |
4631 | goto default_reloc; | |
252b5132 | 4632 | } |
ec338859 AM |
4633 | else if (info->shared |
4634 | && r_symndx != 0 | |
4635 | && (input_section->flags & SEC_ALLOC)) | |
252b5132 | 4636 | { |
3765b1be RH |
4637 | if (r_type == R_ALPHA_REFLONG) |
4638 | { | |
4639 | (*_bfd_error_handler) | |
4640 | (_("%s: unhandled dynamic relocation against %s"), | |
4641 | bfd_archive_filename (input_bfd), | |
4642 | h->root.root.root.string); | |
4643 | ret_val = false; | |
4644 | } | |
4645 | outrel.r_info = ELF64_R_INFO (0, R_ALPHA_RELATIVE); | |
4646 | outrel.r_addend = value; | |
252b5132 RH |
4647 | } |
4648 | else | |
4649 | goto default_reloc; | |
4650 | ||
3765b1be | 4651 | BFD_ASSERT(srel != NULL); |
252b5132 | 4652 | |
c629eae0 JJ |
4653 | outrel.r_offset = |
4654 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
4655 | rel->r_offset); | |
0bb2d96a | 4656 | if ((outrel.r_offset | 1) != (bfd_vma) -1) |
252b5132 RH |
4657 | outrel.r_offset += (input_section->output_section->vma |
4658 | + input_section->output_offset); | |
4659 | else | |
4660 | memset (&outrel, 0, sizeof outrel); | |
4661 | ||
4662 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, | |
4663 | ((Elf64_External_Rela *) | |
4664 | srel->contents) | |
4665 | + srel->reloc_count++); | |
fe8bc63d | 4666 | BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count |
252b5132 RH |
4667 | <= srel->_cooked_size); |
4668 | } | |
4669 | goto default_reloc; | |
4670 | ||
3765b1be | 4671 | case R_ALPHA_SREL16: |
84de6048 RH |
4672 | case R_ALPHA_SREL32: |
4673 | case R_ALPHA_SREL64: | |
3765b1be RH |
4674 | if (dynamic_symbol_p) |
4675 | { | |
4676 | (*_bfd_error_handler) | |
4677 | (_("%s: pc-relative relocation against dynamic symbol %s"), | |
4678 | bfd_archive_filename (input_bfd), h->root.root.root.string); | |
4679 | ret_val = false; | |
4680 | } | |
4681 | ||
84de6048 RH |
4682 | /* ??? .eh_frame references to discarded sections will be smashed |
4683 | to relocations against SHN_UNDEF. The .eh_frame format allows | |
4684 | NULL to be encoded as 0 in any format, so this works here. */ | |
4685 | if (r_symndx == 0) | |
4686 | howto = (elf64_alpha_howto_table | |
4687 | + (r_type - R_ALPHA_SREL32 + R_ALPHA_REFLONG)); | |
4688 | goto default_reloc; | |
4689 | ||
3765b1be RH |
4690 | case R_ALPHA_TLSLDM: |
4691 | /* Ignore the symbol for the relocation. The result is always | |
4692 | the current module. */ | |
4693 | dynamic_symbol_p = 0; | |
4694 | /* FALLTHRU */ | |
4695 | ||
4696 | case R_ALPHA_TLSGD: | |
4697 | if (!gotent->reloc_done) | |
4698 | { | |
4699 | gotent->reloc_done = 1; | |
4700 | ||
4701 | /* Note that the module index for the main program is 1. */ | |
4702 | bfd_put_64 (output_bfd, !info->shared && !dynamic_symbol_p, | |
4703 | sgot->contents + gotent->got_offset); | |
4704 | ||
4705 | /* If the symbol has been forced local, output a | |
4706 | DTPMOD64 reloc, otherwise it will be handled in | |
4707 | finish_dynamic_symbol. */ | |
4708 | if (info->shared && !dynamic_symbol_p) | |
4709 | { | |
4710 | Elf_Internal_Rela outrel; | |
4711 | ||
4712 | BFD_ASSERT(srelgot != NULL); | |
4713 | ||
4714 | outrel.r_offset = (sgot->output_section->vma | |
4715 | + sgot->output_offset | |
4716 | + gotent->got_offset); | |
4717 | /* ??? Proper dynindx here. */ | |
4718 | outrel.r_info = ELF64_R_INFO (0, R_ALPHA_DTPMOD64); | |
4719 | outrel.r_addend = 0; | |
4720 | ||
4721 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, | |
4722 | ((Elf64_External_Rela *) | |
4723 | srelgot->contents) | |
4724 | + srelgot->reloc_count++); | |
4725 | BFD_ASSERT (sizeof (Elf64_External_Rela) | |
4726 | * srelgot->reloc_count | |
4727 | <= srelgot->_cooked_size); | |
4728 | } | |
4729 | ||
4730 | if (dynamic_symbol_p || r_type == R_ALPHA_TLSLDM) | |
4731 | value = 0; | |
4732 | else | |
4733 | { | |
4734 | BFD_ASSERT(tls_segment != NULL); | |
4735 | value -= dtp_base; | |
4736 | } | |
4737 | bfd_put_64 (output_bfd, value, | |
4738 | sgot->contents + gotent->got_offset + 8); | |
4739 | } | |
4740 | ||
4741 | value = (sgot->output_section->vma | |
4742 | + sgot->output_offset | |
4743 | + gotent->got_offset); | |
4744 | value -= gp; | |
4745 | goto default_reloc; | |
4746 | ||
4747 | case R_ALPHA_DTPRELHI: | |
4748 | case R_ALPHA_DTPRELLO: | |
4749 | case R_ALPHA_DTPREL16: | |
4750 | if (dynamic_symbol_p) | |
4751 | { | |
4752 | (*_bfd_error_handler) | |
4753 | (_("%s: dtp-relative relocation against dynamic symbol %s"), | |
4754 | bfd_archive_filename (input_bfd), h->root.root.root.string); | |
4755 | ret_val = false; | |
4756 | } | |
4757 | BFD_ASSERT(tls_segment != NULL); | |
4758 | value -= dtp_base; | |
9e756d64 RH |
4759 | if (r_type == R_ALPHA_DTPRELHI) |
4760 | value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1); | |
3765b1be RH |
4761 | goto default_reloc; |
4762 | ||
4763 | case R_ALPHA_TPRELHI: | |
4764 | case R_ALPHA_TPRELLO: | |
4765 | case R_ALPHA_TPREL16: | |
9e756d64 RH |
4766 | if (info->shared) |
4767 | { | |
4768 | (*_bfd_error_handler) | |
4769 | (_("%s: TLS local exec code cannot be linked into shared objects"), | |
4770 | bfd_archive_filename (input_bfd)); | |
4771 | ret_val = false; | |
4772 | } | |
4773 | else if (dynamic_symbol_p) | |
3765b1be RH |
4774 | { |
4775 | (*_bfd_error_handler) | |
4776 | (_("%s: tp-relative relocation against dynamic symbol %s"), | |
4777 | bfd_archive_filename (input_bfd), h->root.root.root.string); | |
4778 | ret_val = false; | |
4779 | } | |
4780 | BFD_ASSERT(tls_segment != NULL); | |
4781 | value -= tp_base; | |
9e756d64 RH |
4782 | if (r_type == R_ALPHA_TPRELHI) |
4783 | value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1); | |
3765b1be RH |
4784 | goto default_reloc; |
4785 | ||
4786 | case R_ALPHA_GOTDTPREL: | |
4787 | case R_ALPHA_GOTTPREL: | |
4788 | BFD_ASSERT(sgot != NULL); | |
4789 | BFD_ASSERT(gp != 0); | |
4790 | BFD_ASSERT(gotent != NULL); | |
4791 | BFD_ASSERT(gotent->use_count >= 1); | |
4792 | ||
4793 | if (!gotent->reloc_done) | |
4794 | { | |
4795 | gotent->reloc_done = 1; | |
4796 | ||
4797 | if (dynamic_symbol_p) | |
4798 | value = 0; | |
4799 | else | |
4800 | { | |
4801 | BFD_ASSERT(tls_segment != NULL); | |
4802 | value -= (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base); | |
4803 | } | |
4804 | bfd_put_64 (output_bfd, value, | |
4805 | sgot->contents + gotent->got_offset); | |
4806 | } | |
4807 | ||
4808 | value = (sgot->output_section->vma | |
4809 | + sgot->output_offset | |
4810 | + gotent->got_offset); | |
4811 | value -= gp; | |
4812 | goto default_reloc; | |
4813 | ||
252b5132 RH |
4814 | default: |
4815 | default_reloc: | |
4816 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
3765b1be | 4817 | contents, rel->r_offset, value, 0); |
252b5132 RH |
4818 | break; |
4819 | } | |
4820 | ||
4821 | switch (r) | |
4822 | { | |
4823 | case bfd_reloc_ok: | |
4824 | break; | |
4825 | ||
4826 | case bfd_reloc_overflow: | |
4827 | { | |
4828 | const char *name; | |
4829 | ||
ed4de5e2 JJ |
4830 | /* Don't warn if the overflow is due to pc relative reloc |
4831 | against discarded section. Section optimization code should | |
4832 | handle it. */ | |
4833 | ||
4834 | if (r_symndx < symtab_hdr->sh_info | |
4835 | && sec != NULL && howto->pc_relative | |
4836 | && elf_discarded_section (sec)) | |
4837 | break; | |
4838 | ||
252b5132 RH |
4839 | if (h != NULL) |
4840 | name = h->root.root.root.string; | |
4841 | else | |
4842 | { | |
4843 | name = (bfd_elf_string_from_elf_section | |
4844 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
4845 | if (name == NULL) | |
4846 | return false; | |
4847 | if (*name == '\0') | |
4848 | name = bfd_section_name (input_bfd, sec); | |
4849 | } | |
4850 | if (! ((*info->callbacks->reloc_overflow) | |
4851 | (info, name, howto->name, (bfd_vma) 0, | |
4852 | input_bfd, input_section, rel->r_offset))) | |
f16fbd61 | 4853 | ret_val = false; |
252b5132 RH |
4854 | } |
4855 | break; | |
4856 | ||
4857 | default: | |
4858 | case bfd_reloc_outofrange: | |
4859 | abort (); | |
4860 | } | |
4861 | } | |
4862 | ||
f16fbd61 | 4863 | return ret_val; |
252b5132 RH |
4864 | } |
4865 | ||
4866 | /* Finish up dynamic symbol handling. We set the contents of various | |
4867 | dynamic sections here. */ | |
4868 | ||
4869 | static boolean | |
4870 | elf64_alpha_finish_dynamic_symbol (output_bfd, info, h, sym) | |
4871 | bfd *output_bfd; | |
4872 | struct bfd_link_info *info; | |
4873 | struct elf_link_hash_entry *h; | |
4874 | Elf_Internal_Sym *sym; | |
4875 | { | |
4876 | bfd *dynobj = elf_hash_table(info)->dynobj; | |
4877 | ||
4878 | if (h->plt.offset != MINUS_ONE) | |
4879 | { | |
4880 | /* Fill in the .plt entry for this symbol. */ | |
4881 | asection *splt, *sgot, *srel; | |
4882 | Elf_Internal_Rela outrel; | |
4883 | bfd_vma got_addr, plt_addr; | |
4884 | bfd_vma plt_index; | |
4885 | struct alpha_elf_got_entry *gotent; | |
4886 | ||
4887 | BFD_ASSERT (h->dynindx != -1); | |
4888 | ||
4889 | /* The first .got entry will be updated by the .plt with the | |
4890 | address of the target function. */ | |
4891 | gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries; | |
4892 | BFD_ASSERT (gotent && gotent->addend == 0); | |
4893 | ||
4894 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
4895 | BFD_ASSERT (splt != NULL); | |
4896 | srel = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
4897 | BFD_ASSERT (srel != NULL); | |
4898 | sgot = alpha_elf_tdata (gotent->gotobj)->got; | |
4899 | BFD_ASSERT (sgot != NULL); | |
4900 | ||
4901 | got_addr = (sgot->output_section->vma | |
4902 | + sgot->output_offset | |
4903 | + gotent->got_offset); | |
4904 | plt_addr = (splt->output_section->vma | |
4905 | + splt->output_offset | |
4906 | + h->plt.offset); | |
4907 | ||
4908 | plt_index = (h->plt.offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE; | |
4909 | ||
4910 | /* Fill in the entry in the procedure linkage table. */ | |
4911 | { | |
dc810e39 | 4912 | bfd_vma insn1, insn2, insn3; |
252b5132 RH |
4913 | |
4914 | insn1 = PLT_ENTRY_WORD1 | ((-(h->plt.offset + 4) >> 2) & 0x1fffff); | |
4915 | insn2 = PLT_ENTRY_WORD2; | |
4916 | insn3 = PLT_ENTRY_WORD3; | |
4917 | ||
4918 | bfd_put_32 (output_bfd, insn1, splt->contents + h->plt.offset); | |
4919 | bfd_put_32 (output_bfd, insn2, splt->contents + h->plt.offset + 4); | |
4920 | bfd_put_32 (output_bfd, insn3, splt->contents + h->plt.offset + 8); | |
4921 | } | |
4922 | ||
4923 | /* Fill in the entry in the .rela.plt section. */ | |
4924 | outrel.r_offset = got_addr; | |
4925 | outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT); | |
4926 | outrel.r_addend = 0; | |
4927 | ||
4928 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, | |
4929 | ((Elf64_External_Rela *)srel->contents | |
4930 | + plt_index)); | |
4931 | ||
4932 | if (!(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) | |
4933 | { | |
4934 | /* Mark the symbol as undefined, rather than as defined in the | |
4935 | .plt section. Leave the value alone. */ | |
4936 | sym->st_shndx = SHN_UNDEF; | |
4937 | } | |
4938 | ||
4939 | /* Fill in the entries in the .got. */ | |
4940 | bfd_put_64 (output_bfd, plt_addr, sgot->contents + gotent->got_offset); | |
4941 | ||
4942 | /* Subsequent .got entries will continue to bounce through the .plt. */ | |
4943 | if (gotent->next) | |
4944 | { | |
4945 | srel = bfd_get_section_by_name (dynobj, ".rela.got"); | |
4946 | BFD_ASSERT (! info->shared || srel != NULL); | |
4947 | ||
4948 | gotent = gotent->next; | |
4949 | do | |
4950 | { | |
4951 | sgot = alpha_elf_tdata(gotent->gotobj)->got; | |
4952 | BFD_ASSERT(sgot != NULL); | |
4953 | BFD_ASSERT(gotent->addend == 0); | |
4954 | ||
4955 | bfd_put_64 (output_bfd, plt_addr, | |
4956 | sgot->contents + gotent->got_offset); | |
4957 | ||
4958 | if (info->shared) | |
4959 | { | |
4960 | outrel.r_offset = (sgot->output_section->vma | |
4961 | + sgot->output_offset | |
4962 | + gotent->got_offset); | |
4963 | outrel.r_info = ELF64_R_INFO(0, R_ALPHA_RELATIVE); | |
28cfee26 | 4964 | outrel.r_addend = plt_addr; |
252b5132 RH |
4965 | |
4966 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, | |
4967 | ((Elf64_External_Rela *) | |
4968 | srel->contents) | |
4969 | + srel->reloc_count++); | |
fe8bc63d | 4970 | BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count |
252b5132 RH |
4971 | <= srel->_cooked_size); |
4972 | } | |
4973 | ||
4974 | gotent = gotent->next; | |
4975 | } | |
4976 | while (gotent != NULL); | |
4977 | } | |
4978 | } | |
4979 | else if (alpha_elf_dynamic_symbol_p (h, info)) | |
4980 | { | |
4981 | /* Fill in the dynamic relocations for this symbol's .got entries. */ | |
4982 | asection *srel; | |
4983 | Elf_Internal_Rela outrel; | |
4984 | struct alpha_elf_got_entry *gotent; | |
4985 | ||
4986 | srel = bfd_get_section_by_name (dynobj, ".rela.got"); | |
4987 | BFD_ASSERT (srel != NULL); | |
4988 | ||
252b5132 RH |
4989 | for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries; |
4990 | gotent != NULL; | |
4991 | gotent = gotent->next) | |
4992 | { | |
f44f99a5 | 4993 | asection *sgot; |
3765b1be RH |
4994 | int r_type; |
4995 | ||
f44f99a5 RH |
4996 | if (gotent->use_count == 0) |
4997 | continue; | |
4998 | ||
4999 | sgot = alpha_elf_tdata (gotent->gotobj)->got; | |
252b5132 RH |
5000 | outrel.r_offset = (sgot->output_section->vma |
5001 | + sgot->output_offset | |
5002 | + gotent->got_offset); | |
3765b1be RH |
5003 | |
5004 | r_type = gotent->reloc_type; | |
5005 | switch (r_type) | |
5006 | { | |
5007 | case R_ALPHA_LITERAL: | |
5008 | r_type = R_ALPHA_GLOB_DAT; | |
5009 | break; | |
5010 | case R_ALPHA_TLSGD: | |
5011 | r_type = R_ALPHA_DTPMOD64; | |
5012 | break; | |
5013 | case R_ALPHA_GOTDTPREL: | |
5014 | r_type = R_ALPHA_DTPREL64; | |
5015 | break; | |
5016 | case R_ALPHA_GOTTPREL: | |
5017 | r_type = R_ALPHA_TPREL64; | |
5018 | break; | |
5019 | case R_ALPHA_TLSLDM: | |
5020 | default: | |
5021 | abort (); | |
5022 | } | |
5023 | ||
5024 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); | |
252b5132 RH |
5025 | outrel.r_addend = gotent->addend; |
5026 | ||
5027 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, | |
5028 | ((Elf64_External_Rela *)srel->contents | |
5029 | + srel->reloc_count++)); | |
3765b1be RH |
5030 | |
5031 | if (gotent->reloc_type == R_ALPHA_TLSGD) | |
5032 | { | |
5033 | outrel.r_offset += 8; | |
5034 | outrel.r_info = ELF64_R_INFO (h->dynindx, R_ALPHA_DTPREL64); | |
5035 | ||
5036 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, | |
5037 | ((Elf64_External_Rela *)srel->contents | |
5038 | + srel->reloc_count++)); | |
5039 | } | |
5040 | ||
fe8bc63d | 5041 | BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count |
252b5132 RH |
5042 | <= srel->_cooked_size); |
5043 | } | |
5044 | } | |
5045 | ||
5046 | /* Mark some specially defined symbols as absolute. */ | |
5047 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
5048 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 | |
5049 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) | |
5050 | sym->st_shndx = SHN_ABS; | |
5051 | ||
5052 | return true; | |
5053 | } | |
5054 | ||
5055 | /* Finish up the dynamic sections. */ | |
5056 | ||
5057 | static boolean | |
5058 | elf64_alpha_finish_dynamic_sections (output_bfd, info) | |
5059 | bfd *output_bfd; | |
5060 | struct bfd_link_info *info; | |
5061 | { | |
5062 | bfd *dynobj; | |
5063 | asection *sdyn; | |
5064 | ||
5065 | dynobj = elf_hash_table (info)->dynobj; | |
5066 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
5067 | ||
5068 | if (elf_hash_table (info)->dynamic_sections_created) | |
5069 | { | |
5070 | asection *splt; | |
5071 | Elf64_External_Dyn *dyncon, *dynconend; | |
5072 | ||
5073 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
5074 | BFD_ASSERT (splt != NULL && sdyn != NULL); | |
5075 | ||
5076 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
5077 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
5078 | for (; dyncon < dynconend; dyncon++) | |
5079 | { | |
5080 | Elf_Internal_Dyn dyn; | |
5081 | const char *name; | |
5082 | asection *s; | |
5083 | ||
5084 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
5085 | ||
5086 | switch (dyn.d_tag) | |
5087 | { | |
5088 | case DT_PLTGOT: | |
5089 | name = ".plt"; | |
5090 | goto get_vma; | |
5091 | case DT_PLTRELSZ: | |
5092 | name = ".rela.plt"; | |
5093 | goto get_size; | |
5094 | case DT_JMPREL: | |
5095 | name = ".rela.plt"; | |
5096 | goto get_vma; | |
5097 | ||
5098 | case DT_RELASZ: | |
5099 | /* My interpretation of the TIS v1.1 ELF document indicates | |
5100 | that RELASZ should not include JMPREL. This is not what | |
5101 | the rest of the BFD does. It is, however, what the | |
5102 | glibc ld.so wants. Do this fixup here until we found | |
5103 | out who is right. */ | |
5104 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); | |
5105 | if (s) | |
5106 | { | |
5107 | dyn.d_un.d_val -= | |
5108 | (s->_cooked_size ? s->_cooked_size : s->_raw_size); | |
5109 | } | |
5110 | break; | |
5111 | ||
5112 | get_vma: | |
5113 | s = bfd_get_section_by_name (output_bfd, name); | |
5114 | dyn.d_un.d_ptr = (s ? s->vma : 0); | |
5115 | break; | |
5116 | ||
5117 | get_size: | |
5118 | s = bfd_get_section_by_name (output_bfd, name); | |
5119 | dyn.d_un.d_val = | |
5120 | (s->_cooked_size ? s->_cooked_size : s->_raw_size); | |
5121 | break; | |
5122 | } | |
5123 | ||
5124 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5125 | } | |
5126 | ||
5127 | /* Initialize the PLT0 entry */ | |
5128 | if (splt->_raw_size > 0) | |
5129 | { | |
5130 | bfd_put_32 (output_bfd, PLT_HEADER_WORD1, splt->contents); | |
5131 | bfd_put_32 (output_bfd, PLT_HEADER_WORD2, splt->contents + 4); | |
5132 | bfd_put_32 (output_bfd, PLT_HEADER_WORD3, splt->contents + 8); | |
5133 | bfd_put_32 (output_bfd, PLT_HEADER_WORD4, splt->contents + 12); | |
5134 | ||
5135 | /* The next two words will be filled in by ld.so */ | |
dc810e39 AM |
5136 | bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 16); |
5137 | bfd_put_64 (output_bfd, (bfd_vma) 0, splt->contents + 24); | |
252b5132 RH |
5138 | |
5139 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = | |
5140 | PLT_HEADER_SIZE; | |
5141 | } | |
5142 | } | |
5143 | ||
252b5132 RH |
5144 | return true; |
5145 | } | |
5146 | ||
96e2734b RH |
5147 | /* We need to use a special link routine to handle the .mdebug section. |
5148 | We need to merge all instances of these sections together, not write | |
5149 | them all out sequentially. */ | |
252b5132 RH |
5150 | |
5151 | static boolean | |
5152 | elf64_alpha_final_link (abfd, info) | |
5153 | bfd *abfd; | |
5154 | struct bfd_link_info *info; | |
5155 | { | |
5156 | asection *o; | |
5157 | struct bfd_link_order *p; | |
96e2734b | 5158 | asection *mdebug_sec; |
252b5132 RH |
5159 | struct ecoff_debug_info debug; |
5160 | const struct ecoff_debug_swap *swap | |
5161 | = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
5162 | HDRR *symhdr = &debug.symbolic_header; | |
5163 | PTR mdebug_handle = NULL; | |
5164 | ||
96e2734b | 5165 | /* Go through the sections and collect the mdebug information. */ |
252b5132 | 5166 | mdebug_sec = NULL; |
252b5132 RH |
5167 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) |
5168 | { | |
252b5132 RH |
5169 | if (strcmp (o->name, ".mdebug") == 0) |
5170 | { | |
5171 | struct extsym_info einfo; | |
5172 | ||
5173 | /* We have found the .mdebug section in the output file. | |
5174 | Look through all the link_orders comprising it and merge | |
5175 | the information together. */ | |
5176 | symhdr->magic = swap->sym_magic; | |
5177 | /* FIXME: What should the version stamp be? */ | |
5178 | symhdr->vstamp = 0; | |
5179 | symhdr->ilineMax = 0; | |
5180 | symhdr->cbLine = 0; | |
5181 | symhdr->idnMax = 0; | |
5182 | symhdr->ipdMax = 0; | |
5183 | symhdr->isymMax = 0; | |
5184 | symhdr->ioptMax = 0; | |
5185 | symhdr->iauxMax = 0; | |
5186 | symhdr->issMax = 0; | |
5187 | symhdr->issExtMax = 0; | |
5188 | symhdr->ifdMax = 0; | |
5189 | symhdr->crfd = 0; | |
5190 | symhdr->iextMax = 0; | |
5191 | ||
5192 | /* We accumulate the debugging information itself in the | |
5193 | debug_info structure. */ | |
5194 | debug.line = NULL; | |
5195 | debug.external_dnr = NULL; | |
5196 | debug.external_pdr = NULL; | |
5197 | debug.external_sym = NULL; | |
5198 | debug.external_opt = NULL; | |
5199 | debug.external_aux = NULL; | |
5200 | debug.ss = NULL; | |
5201 | debug.ssext = debug.ssext_end = NULL; | |
5202 | debug.external_fdr = NULL; | |
5203 | debug.external_rfd = NULL; | |
5204 | debug.external_ext = debug.external_ext_end = NULL; | |
5205 | ||
5206 | mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info); | |
5207 | if (mdebug_handle == (PTR) NULL) | |
5208 | return false; | |
5209 | ||
5210 | if (1) | |
5211 | { | |
5212 | asection *s; | |
5213 | EXTR esym; | |
52b9d213 | 5214 | bfd_vma last = 0; |
252b5132 RH |
5215 | unsigned int i; |
5216 | static const char * const name[] = | |
5217 | { | |
5218 | ".text", ".init", ".fini", ".data", | |
5219 | ".rodata", ".sdata", ".sbss", ".bss" | |
5220 | }; | |
5221 | static const int sc[] = { scText, scInit, scFini, scData, | |
5222 | scRData, scSData, scSBss, scBss }; | |
5223 | ||
5224 | esym.jmptbl = 0; | |
5225 | esym.cobol_main = 0; | |
5226 | esym.weakext = 0; | |
5227 | esym.reserved = 0; | |
5228 | esym.ifd = ifdNil; | |
5229 | esym.asym.iss = issNil; | |
5230 | esym.asym.st = stLocal; | |
5231 | esym.asym.reserved = 0; | |
5232 | esym.asym.index = indexNil; | |
5233 | for (i = 0; i < 8; i++) | |
5234 | { | |
5235 | esym.asym.sc = sc[i]; | |
5236 | s = bfd_get_section_by_name (abfd, name[i]); | |
5237 | if (s != NULL) | |
5238 | { | |
5239 | esym.asym.value = s->vma; | |
5240 | last = s->vma + s->_raw_size; | |
5241 | } | |
5242 | else | |
5243 | esym.asym.value = last; | |
5244 | ||
5245 | if (! bfd_ecoff_debug_one_external (abfd, &debug, swap, | |
5246 | name[i], &esym)) | |
5247 | return false; | |
5248 | } | |
5249 | } | |
5250 | ||
5251 | for (p = o->link_order_head; | |
5252 | p != (struct bfd_link_order *) NULL; | |
5253 | p = p->next) | |
5254 | { | |
5255 | asection *input_section; | |
5256 | bfd *input_bfd; | |
5257 | const struct ecoff_debug_swap *input_swap; | |
5258 | struct ecoff_debug_info input_debug; | |
5259 | char *eraw_src; | |
5260 | char *eraw_end; | |
5261 | ||
5262 | if (p->type != bfd_indirect_link_order) | |
5263 | { | |
fd96f80f | 5264 | if (p->type == bfd_data_link_order) |
252b5132 RH |
5265 | continue; |
5266 | abort (); | |
5267 | } | |
5268 | ||
5269 | input_section = p->u.indirect.section; | |
5270 | input_bfd = input_section->owner; | |
5271 | ||
5272 | if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour | |
5273 | || (get_elf_backend_data (input_bfd) | |
5274 | ->elf_backend_ecoff_debug_swap) == NULL) | |
5275 | { | |
5276 | /* I don't know what a non ALPHA ELF bfd would be | |
5277 | doing with a .mdebug section, but I don't really | |
5278 | want to deal with it. */ | |
5279 | continue; | |
5280 | } | |
5281 | ||
5282 | input_swap = (get_elf_backend_data (input_bfd) | |
5283 | ->elf_backend_ecoff_debug_swap); | |
5284 | ||
5285 | BFD_ASSERT (p->size == input_section->_raw_size); | |
5286 | ||
5287 | /* The ECOFF linking code expects that we have already | |
5288 | read in the debugging information and set up an | |
5289 | ecoff_debug_info structure, so we do that now. */ | |
5290 | if (!elf64_alpha_read_ecoff_info (input_bfd, input_section, | |
5291 | &input_debug)) | |
5292 | return false; | |
5293 | ||
5294 | if (! (bfd_ecoff_debug_accumulate | |
5295 | (mdebug_handle, abfd, &debug, swap, input_bfd, | |
5296 | &input_debug, input_swap, info))) | |
5297 | return false; | |
5298 | ||
5299 | /* Loop through the external symbols. For each one with | |
5300 | interesting information, try to find the symbol in | |
5301 | the linker global hash table and save the information | |
5302 | for the output external symbols. */ | |
5303 | eraw_src = input_debug.external_ext; | |
5304 | eraw_end = (eraw_src | |
5305 | + (input_debug.symbolic_header.iextMax | |
5306 | * input_swap->external_ext_size)); | |
5307 | for (; | |
5308 | eraw_src < eraw_end; | |
5309 | eraw_src += input_swap->external_ext_size) | |
5310 | { | |
5311 | EXTR ext; | |
5312 | const char *name; | |
5313 | struct alpha_elf_link_hash_entry *h; | |
5314 | ||
5315 | (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext); | |
5316 | if (ext.asym.sc == scNil | |
5317 | || ext.asym.sc == scUndefined | |
5318 | || ext.asym.sc == scSUndefined) | |
5319 | continue; | |
5320 | ||
5321 | name = input_debug.ssext + ext.asym.iss; | |
5322 | h = alpha_elf_link_hash_lookup (alpha_elf_hash_table (info), | |
5323 | name, false, false, true); | |
5324 | if (h == NULL || h->esym.ifd != -2) | |
5325 | continue; | |
5326 | ||
5327 | if (ext.ifd != -1) | |
5328 | { | |
5329 | BFD_ASSERT (ext.ifd | |
5330 | < input_debug.symbolic_header.ifdMax); | |
5331 | ext.ifd = input_debug.ifdmap[ext.ifd]; | |
5332 | } | |
5333 | ||
5334 | h->esym = ext; | |
5335 | } | |
5336 | ||
5337 | /* Free up the information we just read. */ | |
5338 | free (input_debug.line); | |
5339 | free (input_debug.external_dnr); | |
5340 | free (input_debug.external_pdr); | |
5341 | free (input_debug.external_sym); | |
5342 | free (input_debug.external_opt); | |
5343 | free (input_debug.external_aux); | |
5344 | free (input_debug.ss); | |
5345 | free (input_debug.ssext); | |
5346 | free (input_debug.external_fdr); | |
5347 | free (input_debug.external_rfd); | |
5348 | free (input_debug.external_ext); | |
5349 | ||
5350 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
5351 | elf_link_input_bfd ignores this section. */ | |
5352 | input_section->flags &=~ SEC_HAS_CONTENTS; | |
5353 | } | |
5354 | ||
252b5132 RH |
5355 | /* Build the external symbol information. */ |
5356 | einfo.abfd = abfd; | |
5357 | einfo.info = info; | |
5358 | einfo.debug = &debug; | |
5359 | einfo.swap = swap; | |
5360 | einfo.failed = false; | |
5361 | elf_link_hash_traverse (elf_hash_table (info), | |
5362 | elf64_alpha_output_extsym, | |
5363 | (PTR) &einfo); | |
5364 | if (einfo.failed) | |
5365 | return false; | |
5366 | ||
5367 | /* Set the size of the .mdebug section. */ | |
5368 | o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap); | |
5369 | ||
5370 | /* Skip this section later on (I don't think this currently | |
5371 | matters, but someday it might). */ | |
5372 | o->link_order_head = (struct bfd_link_order *) NULL; | |
5373 | ||
5374 | mdebug_sec = o; | |
5375 | } | |
252b5132 RH |
5376 | } |
5377 | ||
5378 | /* Invoke the regular ELF backend linker to do all the work. */ | |
5379 | if (! bfd_elf64_bfd_final_link (abfd, info)) | |
5380 | return false; | |
5381 | ||
5382 | /* Now write out the computed sections. */ | |
5383 | ||
5384 | /* The .got subsections... */ | |
5385 | { | |
5386 | bfd *i, *dynobj = elf_hash_table(info)->dynobj; | |
5387 | for (i = alpha_elf_hash_table(info)->got_list; | |
5388 | i != NULL; | |
5389 | i = alpha_elf_tdata(i)->got_link_next) | |
5390 | { | |
5391 | asection *sgot; | |
5392 | ||
5393 | /* elf_bfd_final_link already did everything in dynobj. */ | |
5394 | if (i == dynobj) | |
5395 | continue; | |
5396 | ||
5397 | sgot = alpha_elf_tdata(i)->got; | |
5398 | if (! bfd_set_section_contents (abfd, sgot->output_section, | |
dc810e39 AM |
5399 | sgot->contents, |
5400 | (file_ptr) sgot->output_offset, | |
252b5132 RH |
5401 | sgot->_raw_size)) |
5402 | return false; | |
5403 | } | |
5404 | } | |
5405 | ||
252b5132 RH |
5406 | if (mdebug_sec != (asection *) NULL) |
5407 | { | |
5408 | BFD_ASSERT (abfd->output_has_begun); | |
5409 | if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug, | |
5410 | swap, info, | |
5411 | mdebug_sec->filepos)) | |
5412 | return false; | |
5413 | ||
5414 | bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info); | |
5415 | } | |
5416 | ||
252b5132 RH |
5417 | return true; |
5418 | } | |
fcfbdf31 JJ |
5419 | |
5420 | static enum elf_reloc_type_class | |
f51e552e AM |
5421 | elf64_alpha_reloc_type_class (rela) |
5422 | const Elf_Internal_Rela *rela; | |
fcfbdf31 | 5423 | { |
f51e552e | 5424 | switch ((int) ELF64_R_TYPE (rela->r_info)) |
fcfbdf31 JJ |
5425 | { |
5426 | case R_ALPHA_RELATIVE: | |
5427 | return reloc_class_relative; | |
5428 | case R_ALPHA_JMP_SLOT: | |
5429 | return reloc_class_plt; | |
5430 | case R_ALPHA_COPY: | |
5431 | return reloc_class_copy; | |
5432 | default: | |
5433 | return reloc_class_normal; | |
5434 | } | |
5435 | } | |
252b5132 RH |
5436 | \f |
5437 | /* ECOFF swapping routines. These are used when dealing with the | |
5438 | .mdebug section, which is in the ECOFF debugging format. Copied | |
fe8bc63d | 5439 | from elf32-mips.c. */ |
252b5132 RH |
5440 | static const struct ecoff_debug_swap |
5441 | elf64_alpha_ecoff_debug_swap = | |
5442 | { | |
5443 | /* Symbol table magic number. */ | |
5444 | magicSym2, | |
5445 | /* Alignment of debugging information. E.g., 4. */ | |
5446 | 8, | |
5447 | /* Sizes of external symbolic information. */ | |
5448 | sizeof (struct hdr_ext), | |
5449 | sizeof (struct dnr_ext), | |
5450 | sizeof (struct pdr_ext), | |
5451 | sizeof (struct sym_ext), | |
5452 | sizeof (struct opt_ext), | |
5453 | sizeof (struct fdr_ext), | |
5454 | sizeof (struct rfd_ext), | |
5455 | sizeof (struct ext_ext), | |
5456 | /* Functions to swap in external symbolic data. */ | |
5457 | ecoff_swap_hdr_in, | |
5458 | ecoff_swap_dnr_in, | |
5459 | ecoff_swap_pdr_in, | |
5460 | ecoff_swap_sym_in, | |
5461 | ecoff_swap_opt_in, | |
5462 | ecoff_swap_fdr_in, | |
5463 | ecoff_swap_rfd_in, | |
5464 | ecoff_swap_ext_in, | |
5465 | _bfd_ecoff_swap_tir_in, | |
5466 | _bfd_ecoff_swap_rndx_in, | |
5467 | /* Functions to swap out external symbolic data. */ | |
5468 | ecoff_swap_hdr_out, | |
5469 | ecoff_swap_dnr_out, | |
5470 | ecoff_swap_pdr_out, | |
5471 | ecoff_swap_sym_out, | |
5472 | ecoff_swap_opt_out, | |
5473 | ecoff_swap_fdr_out, | |
5474 | ecoff_swap_rfd_out, | |
5475 | ecoff_swap_ext_out, | |
5476 | _bfd_ecoff_swap_tir_out, | |
5477 | _bfd_ecoff_swap_rndx_out, | |
5478 | /* Function to read in symbolic data. */ | |
5479 | elf64_alpha_read_ecoff_info | |
5480 | }; | |
5481 | \f | |
70bcb145 JW |
5482 | /* Use a non-standard hash bucket size of 8. */ |
5483 | ||
562ace6b | 5484 | static const struct elf_size_info alpha_elf_size_info = |
70bcb145 JW |
5485 | { |
5486 | sizeof (Elf64_External_Ehdr), | |
5487 | sizeof (Elf64_External_Phdr), | |
5488 | sizeof (Elf64_External_Shdr), | |
5489 | sizeof (Elf64_External_Rel), | |
5490 | sizeof (Elf64_External_Rela), | |
5491 | sizeof (Elf64_External_Sym), | |
5492 | sizeof (Elf64_External_Dyn), | |
5493 | sizeof (Elf_External_Note), | |
5494 | 8, | |
5495 | 1, | |
5496 | 64, 8, | |
5497 | ELFCLASS64, EV_CURRENT, | |
5498 | bfd_elf64_write_out_phdrs, | |
5499 | bfd_elf64_write_shdrs_and_ehdr, | |
5500 | bfd_elf64_write_relocs, | |
73ff0d56 | 5501 | bfd_elf64_swap_symbol_in, |
70bcb145 JW |
5502 | bfd_elf64_swap_symbol_out, |
5503 | bfd_elf64_slurp_reloc_table, | |
5504 | bfd_elf64_slurp_symbol_table, | |
5505 | bfd_elf64_swap_dyn_in, | |
5506 | bfd_elf64_swap_dyn_out, | |
5507 | NULL, | |
5508 | NULL, | |
5509 | NULL, | |
5510 | NULL | |
5511 | }; | |
5512 | ||
252b5132 RH |
5513 | #define TARGET_LITTLE_SYM bfd_elf64_alpha_vec |
5514 | #define TARGET_LITTLE_NAME "elf64-alpha" | |
5515 | #define ELF_ARCH bfd_arch_alpha | |
56fc028e AJ |
5516 | #define ELF_MACHINE_CODE EM_ALPHA |
5517 | #define ELF_MAXPAGESIZE 0x10000 | |
252b5132 RH |
5518 | |
5519 | #define bfd_elf64_bfd_link_hash_table_create \ | |
5520 | elf64_alpha_bfd_link_hash_table_create | |
5521 | ||
5522 | #define bfd_elf64_bfd_reloc_type_lookup \ | |
5523 | elf64_alpha_bfd_reloc_type_lookup | |
5524 | #define elf_info_to_howto \ | |
5525 | elf64_alpha_info_to_howto | |
5526 | ||
5527 | #define bfd_elf64_mkobject \ | |
5528 | elf64_alpha_mkobject | |
5529 | #define elf_backend_object_p \ | |
5530 | elf64_alpha_object_p | |
5531 | ||
5532 | #define elf_backend_section_from_shdr \ | |
5533 | elf64_alpha_section_from_shdr | |
204692d7 RH |
5534 | #define elf_backend_section_flags \ |
5535 | elf64_alpha_section_flags | |
252b5132 RH |
5536 | #define elf_backend_fake_sections \ |
5537 | elf64_alpha_fake_sections | |
5538 | ||
5539 | #define bfd_elf64_bfd_is_local_label_name \ | |
5540 | elf64_alpha_is_local_label_name | |
5541 | #define bfd_elf64_find_nearest_line \ | |
5542 | elf64_alpha_find_nearest_line | |
5543 | #define bfd_elf64_bfd_relax_section \ | |
5544 | elf64_alpha_relax_section | |
5545 | ||
5546 | #define elf_backend_add_symbol_hook \ | |
5547 | elf64_alpha_add_symbol_hook | |
5548 | #define elf_backend_check_relocs \ | |
5549 | elf64_alpha_check_relocs | |
5550 | #define elf_backend_create_dynamic_sections \ | |
5551 | elf64_alpha_create_dynamic_sections | |
5552 | #define elf_backend_adjust_dynamic_symbol \ | |
5553 | elf64_alpha_adjust_dynamic_symbol | |
5554 | #define elf_backend_always_size_sections \ | |
5555 | elf64_alpha_always_size_sections | |
5556 | #define elf_backend_size_dynamic_sections \ | |
5557 | elf64_alpha_size_dynamic_sections | |
5558 | #define elf_backend_relocate_section \ | |
5559 | elf64_alpha_relocate_section | |
5560 | #define elf_backend_finish_dynamic_symbol \ | |
5561 | elf64_alpha_finish_dynamic_symbol | |
5562 | #define elf_backend_finish_dynamic_sections \ | |
5563 | elf64_alpha_finish_dynamic_sections | |
5564 | #define bfd_elf64_bfd_final_link \ | |
5565 | elf64_alpha_final_link | |
fcfbdf31 JJ |
5566 | #define elf_backend_reloc_type_class \ |
5567 | elf64_alpha_reloc_type_class | |
252b5132 RH |
5568 | |
5569 | #define elf_backend_ecoff_debug_swap \ | |
5570 | &elf64_alpha_ecoff_debug_swap | |
5571 | ||
70bcb145 JW |
5572 | #define elf_backend_size_info \ |
5573 | alpha_elf_size_info | |
5574 | ||
38b1a46c | 5575 | /* A few constants that determine how the .plt section is set up. */ |
252b5132 RH |
5576 | #define elf_backend_want_got_plt 0 |
5577 | #define elf_backend_plt_readonly 0 | |
5578 | #define elf_backend_want_plt_sym 1 | |
5579 | #define elf_backend_got_header_size 0 | |
5580 | #define elf_backend_plt_header_size PLT_HEADER_SIZE | |
5581 | ||
5582 | #include "elf64-target.h" | |
2238051f RH |
5583 | \f |
5584 | /* FreeBSD support. */ | |
5585 | ||
5586 | #undef TARGET_LITTLE_SYM | |
5587 | #define TARGET_LITTLE_SYM bfd_elf64_alpha_freebsd_vec | |
5588 | #undef TARGET_LITTLE_NAME | |
5589 | #define TARGET_LITTLE_NAME "elf64-alpha-freebsd" | |
5590 | ||
5591 | /* The kernel recognizes executables as valid only if they carry a | |
5592 | "FreeBSD" label in the ELF header. So we put this label on all | |
5593 | executables and (for simplicity) also all other object files. */ | |
5594 | ||
5595 | static void elf64_alpha_fbsd_post_process_headers | |
5596 | PARAMS ((bfd *, struct bfd_link_info *)); | |
5597 | ||
5598 | static void | |
5599 | elf64_alpha_fbsd_post_process_headers (abfd, link_info) | |
5600 | bfd * abfd; | |
5601 | struct bfd_link_info * link_info ATTRIBUTE_UNUSED; | |
5602 | { | |
5603 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ | |
5604 | ||
5605 | i_ehdrp = elf_elfheader (abfd); | |
5606 | ||
5607 | /* Put an ABI label supported by FreeBSD >= 4.1. */ | |
5608 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; | |
5609 | #ifdef OLD_FREEBSD_ABI_LABEL | |
5610 | /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */ | |
5611 | memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8); | |
5612 | #endif | |
5613 | } | |
5614 | ||
5615 | #undef elf_backend_post_process_headers | |
5616 | #define elf_backend_post_process_headers \ | |
5617 | elf64_alpha_fbsd_post_process_headers | |
5618 | ||
5619 | #define elf64_bed elf64_alpha_fbsd_bed | |
5620 | ||
5621 | #include "elf64-target.h" |