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