source: trunk/src/binutils/bfd/elf64-hppa.c@ 29

Last change on this file since 29 was 10, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 78.3 KB
Line 
1/* Support for HPPA 64-bit ELF
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "alloca-conf.h"
21#include "bfd.h"
22#include "sysdep.h"
23#include "libbfd.h"
24#include "elf-bfd.h"
25#include "elf/hppa.h"
26#include "libhppa.h"
27#include "elf64-hppa.h"
28#define ARCH_SIZE 64
29
30#define PLT_ENTRY_SIZE 0x10
31#define DLT_ENTRY_SIZE 0x8
32#define OPD_ENTRY_SIZE 0x20
33
34#define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
35
36/* The stub is supposed to load the target address and target's DP
37 value out of the PLT, then do an external branch to the target
38 address.
39
40 LDD PLTOFF(%r27),%r1
41 BVE (%r1)
42 LDD PLTOFF+8(%r27),%r27
43
44 Note that we must use the LDD with a 14 bit displacement, not the one
45 with a 5 bit displacement. */
46static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
47 0x53, 0x7b, 0x00, 0x00 };
48
49struct elf64_hppa_dyn_hash_entry
50{
51 struct bfd_hash_entry root;
52
53 /* Offsets for this symbol in various linker sections. */
54 bfd_vma dlt_offset;
55 bfd_vma plt_offset;
56 bfd_vma opd_offset;
57 bfd_vma stub_offset;
58
59 /* The symbol table entry, if any, that this was derived from. */
60 struct elf_link_hash_entry *h;
61
62 /* The index of the (possibly local) symbol in the input bfd and its
63 associated BFD. Needed so that we can have relocs against local
64 symbols in shared libraries. */
65 unsigned long sym_indx;
66 bfd *owner;
67
68 /* Dynamic symbols may need to have two different values. One for
69 the dynamic symbol table, one for the normal symbol table.
70
71 In such cases we store the symbol's real value and section
72 index here so we can restore the real value before we write
73 the normal symbol table. */
74 bfd_vma st_value;
75 int st_shndx;
76
77 /* Used to count non-got, non-plt relocations for delayed sizing
78 of relocation sections. */
79 struct elf64_hppa_dyn_reloc_entry
80 {
81 /* Next relocation in the chain. */
82 struct elf64_hppa_dyn_reloc_entry *next;
83
84 /* The type of the relocation. */
85 int type;
86
87 /* The input section of the relocation. */
88 asection *sec;
89
90 /* The index of the section symbol for the input section of
91 the relocation. Only needed when building shared libraries. */
92 int sec_symndx;
93
94 /* The offset within the input section of the relocation. */
95 bfd_vma offset;
96
97 /* The addend for the relocation. */
98 bfd_vma addend;
99
100 } *reloc_entries;
101
102 /* Nonzero if this symbol needs an entry in one of the linker
103 sections. */
104 unsigned want_dlt;
105 unsigned want_plt;
106 unsigned want_opd;
107 unsigned want_stub;
108};
109
110struct elf64_hppa_dyn_hash_table
111{
112 struct bfd_hash_table root;
113};
114
115struct elf64_hppa_link_hash_table
116{
117 struct elf_link_hash_table root;
118
119 /* Shortcuts to get to the various linker defined sections. */
120 asection *dlt_sec;
121 asection *dlt_rel_sec;
122 asection *plt_sec;
123 asection *plt_rel_sec;
124 asection *opd_sec;
125 asection *opd_rel_sec;
126 asection *other_rel_sec;
127
128 /* Offset of __gp within .plt section. When the PLT gets large we want
129 to slide __gp into the PLT section so that we can continue to use
130 single DP relative instructions to load values out of the PLT. */
131 bfd_vma gp_offset;
132
133 /* Note this is not strictly correct. We should create a stub section for
134 each input section with calls. The stub section should be placed before
135 the section with the call. */
136 asection *stub_sec;
137
138 bfd_vma text_segment_base;
139 bfd_vma data_segment_base;
140
141 struct elf64_hppa_dyn_hash_table dyn_hash_table;
142
143 /* We build tables to map from an input section back to its
144 symbol index. This is the BFD for which we currently have
145 a map. */
146 bfd *section_syms_bfd;
147
148 /* Array of symbol numbers for each input section attached to the
149 current BFD. */
150 int *section_syms;
151};
152
153#define elf64_hppa_hash_table(p) \
154 ((struct elf64_hppa_link_hash_table *) ((p)->hash))
155
156typedef struct bfd_hash_entry *(*new_hash_entry_func)
157 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
158
159static boolean elf64_hppa_dyn_hash_table_init
160 PARAMS ((struct elf64_hppa_dyn_hash_table *ht, bfd *abfd,
161 new_hash_entry_func new));
162static struct bfd_hash_entry *elf64_hppa_new_dyn_hash_entry
163 PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
164 const char *string));
165static struct bfd_link_hash_table *elf64_hppa_hash_table_create
166 PARAMS ((bfd *abfd));
167static struct elf64_hppa_dyn_hash_entry *elf64_hppa_dyn_hash_lookup
168 PARAMS ((struct elf64_hppa_dyn_hash_table *table, const char *string,
169 boolean create, boolean copy));
170static void elf64_hppa_dyn_hash_traverse
171 PARAMS ((struct elf64_hppa_dyn_hash_table *table,
172 boolean (*func) (struct elf64_hppa_dyn_hash_entry *, PTR),
173 PTR info));
174
175static const char *get_dyn_name
176 PARAMS ((asection *, struct elf_link_hash_entry *,
177 const Elf_Internal_Rela *, char **, size_t *));
178
179/* This must follow the definitions of the various derived linker
180 hash tables and shared functions. */
181#include "elf-hppa.h"
182
183static boolean elf64_hppa_object_p
184 PARAMS ((bfd *));
185
186static boolean elf64_hppa_section_from_shdr
187 PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
188
189static void elf64_hppa_post_process_headers
190 PARAMS ((bfd *, struct bfd_link_info *));
191
192static boolean elf64_hppa_create_dynamic_sections
193 PARAMS ((bfd *, struct bfd_link_info *));
194
195static boolean elf64_hppa_adjust_dynamic_symbol
196 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
197
198static boolean elf64_hppa_size_dynamic_sections
199 PARAMS ((bfd *, struct bfd_link_info *));
200
201static boolean elf64_hppa_finish_dynamic_symbol
202 PARAMS ((bfd *, struct bfd_link_info *,
203 struct elf_link_hash_entry *, Elf_Internal_Sym *));
204
205static boolean elf64_hppa_finish_dynamic_sections
206 PARAMS ((bfd *, struct bfd_link_info *));
207
208static boolean elf64_hppa_check_relocs
209 PARAMS ((bfd *, struct bfd_link_info *,
210 asection *, const Elf_Internal_Rela *));
211
212static boolean elf64_hppa_dynamic_symbol_p
213 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
214
215static boolean elf64_hppa_mark_exported_functions
216 PARAMS ((struct elf_link_hash_entry *, PTR));
217
218static boolean elf64_hppa_finalize_opd
219 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
220
221static boolean elf64_hppa_finalize_dlt
222 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
223
224static boolean allocate_global_data_dlt
225 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
226
227static boolean allocate_global_data_plt
228 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
229
230static boolean allocate_global_data_stub
231 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
232
233static boolean allocate_global_data_opd
234 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
235
236static boolean get_reloc_section
237 PARAMS ((bfd *, struct elf64_hppa_link_hash_table *, asection *));
238
239static boolean count_dyn_reloc
240 PARAMS ((bfd *, struct elf64_hppa_dyn_hash_entry *,
241 int, asection *, int, bfd_vma, bfd_vma));
242
243static boolean allocate_dynrel_entries
244 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
245
246static boolean elf64_hppa_finalize_dynreloc
247 PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
248
249static boolean get_opd
250 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
251
252static boolean get_plt
253 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
254
255static boolean get_dlt
256 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
257
258static boolean get_stub
259 PARAMS ((bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *));
260
261static int elf64_hppa_elf_get_symbol_type
262 PARAMS ((Elf_Internal_Sym *, int));
263
264static boolean
265elf64_hppa_dyn_hash_table_init (ht, abfd, new)
266 struct elf64_hppa_dyn_hash_table *ht;
267 bfd *abfd ATTRIBUTE_UNUSED;
268 new_hash_entry_func new;
269{
270 memset (ht, 0, sizeof (*ht));
271 return bfd_hash_table_init (&ht->root, new);
272}
273
274static struct bfd_hash_entry*
275elf64_hppa_new_dyn_hash_entry (entry, table, string)
276 struct bfd_hash_entry *entry;
277 struct bfd_hash_table *table;
278 const char *string;
279{
280 struct elf64_hppa_dyn_hash_entry *ret;
281 ret = (struct elf64_hppa_dyn_hash_entry *) entry;
282
283 /* Allocate the structure if it has not already been allocated by a
284 subclass. */
285 if (!ret)
286 ret = bfd_hash_allocate (table, sizeof (*ret));
287
288 if (!ret)
289 return 0;
290
291 /* Initialize our local data. All zeros, and definitely easier
292 than setting 8 bit fields. */
293 memset (ret, 0, sizeof (*ret));
294
295 /* Call the allocation method of the superclass. */
296 ret = ((struct elf64_hppa_dyn_hash_entry *)
297 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
298
299 return &ret->root;
300}
301
302/* Create the derived linker hash table. The PA64 ELF port uses this
303 derived hash table to keep information specific to the PA ElF
304 linker (without using static variables). */
305
306static struct bfd_link_hash_table*
307elf64_hppa_hash_table_create (abfd)
308 bfd *abfd;
309{
310 struct elf64_hppa_link_hash_table *ret;
311
312 ret = bfd_zalloc (abfd, sizeof (*ret));
313 if (!ret)
314 return 0;
315 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
316 _bfd_elf_link_hash_newfunc))
317 {
318 bfd_release (abfd, ret);
319 return 0;
320 }
321
322 if (!elf64_hppa_dyn_hash_table_init (&ret->dyn_hash_table, abfd,
323 elf64_hppa_new_dyn_hash_entry))
324 return 0;
325 return &ret->root.root;
326}
327
328/* Look up an entry in a PA64 ELF linker hash table. */
329
330static struct elf64_hppa_dyn_hash_entry *
331elf64_hppa_dyn_hash_lookup(table, string, create, copy)
332 struct elf64_hppa_dyn_hash_table *table;
333 const char *string;
334 boolean create, copy;
335{
336 return ((struct elf64_hppa_dyn_hash_entry *)
337 bfd_hash_lookup (&table->root, string, create, copy));
338}
339
340/* Traverse a PA64 ELF linker hash table. */
341
342static void
343elf64_hppa_dyn_hash_traverse (table, func, info)
344 struct elf64_hppa_dyn_hash_table *table;
345 boolean (*func) PARAMS ((struct elf64_hppa_dyn_hash_entry *, PTR));
346 PTR info;
347{
348 (bfd_hash_traverse
349 (&table->root,
350 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) func,
351 info));
352}
353
354
355/* Return nonzero if ABFD represents a PA2.0 ELF64 file.
356
357 Additionally we set the default architecture and machine. */
358static boolean
359elf64_hppa_object_p (abfd)
360 bfd *abfd;
361{
362 Elf_Internal_Ehdr * i_ehdrp;
363 unsigned int flags;
364
365 i_ehdrp = elf_elfheader (abfd);
366 if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
367 {
368 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX)
369 return false;
370 }
371 else
372 {
373 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX)
374 return false;
375 }
376
377 flags = i_ehdrp->e_flags;
378 switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
379 {
380 case EFA_PARISC_1_0:
381 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
382 case EFA_PARISC_1_1:
383 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
384 case EFA_PARISC_2_0:
385 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
386 case EFA_PARISC_2_0 | EF_PARISC_WIDE:
387 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
388 }
389 /* Don't be fussy. */
390 return true;
391}
392
393/* Given section type (hdr->sh_type), return a boolean indicating
394 whether or not the section is an elf64-hppa specific section. */
395static boolean
396elf64_hppa_section_from_shdr (abfd, hdr, name)
397 bfd *abfd;
398 Elf64_Internal_Shdr *hdr;
399 char *name;
400{
401 asection *newsect;
402
403 switch (hdr->sh_type)
404 {
405 case SHT_PARISC_EXT:
406 if (strcmp (name, ".PARISC.archext") != 0)
407 return false;
408 break;
409 case SHT_PARISC_UNWIND:
410 if (strcmp (name, ".PARISC.unwind") != 0)
411 return false;
412 break;
413 case SHT_PARISC_DOC:
414 case SHT_PARISC_ANNOT:
415 default:
416 return false;
417 }
418
419 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
420 return false;
421 newsect = hdr->bfd_section;
422
423 return true;
424}
425
426/* Construct a string for use in the elf64_hppa_dyn_hash_table. The
427 name describes what was once potentially anonymous memory. We
428 allocate memory as necessary, possibly reusing PBUF/PLEN. */
429
430static const char *
431get_dyn_name (sec, h, rel, pbuf, plen)
432 asection *sec;
433 struct elf_link_hash_entry *h;
434 const Elf_Internal_Rela *rel;
435 char **pbuf;
436 size_t *plen;
437{
438 size_t nlen, tlen;
439 char *buf;
440 size_t len;
441
442 if (h && rel->r_addend == 0)
443 return h->root.root.string;
444
445 if (h)
446 nlen = strlen (h->root.root.string);
447 else
448 nlen = 8 + 1 + sizeof (rel->r_info) * 2 - 8;
449 tlen = nlen + 1 + sizeof (rel->r_addend) * 2 + 1;
450
451 len = *plen;
452 buf = *pbuf;
453 if (len < tlen)
454 {
455 if (buf)
456 free (buf);
457 *pbuf = buf = malloc (tlen);
458 *plen = len = tlen;
459 if (!buf)
460 return NULL;
461 }
462
463 if (h)
464 {
465 memcpy (buf, h->root.root.string, nlen);
466 buf[nlen++] = '+';
467 sprintf_vma (buf + nlen, rel->r_addend);
468 }
469 else
470 {
471 nlen = sprintf (buf, "%x:%lx",
472 sec->id & 0xffffffff,
473 (long) ELF64_R_SYM (rel->r_info));
474 if (rel->r_addend)
475 {
476 buf[nlen++] = '+';
477 sprintf_vma (buf + nlen, rel->r_addend);
478 }
479 }
480
481 return buf;
482}
483
484/* SEC is a section containing relocs for an input BFD when linking; return
485 a suitable section for holding relocs in the output BFD for a link. */
486
487static boolean
488get_reloc_section (abfd, hppa_info, sec)
489 bfd *abfd;
490 struct elf64_hppa_link_hash_table *hppa_info;
491 asection *sec;
492{
493 const char *srel_name;
494 asection *srel;
495 bfd *dynobj;
496
497 srel_name = (bfd_elf_string_from_elf_section
498 (abfd, elf_elfheader(abfd)->e_shstrndx,
499 elf_section_data(sec)->rel_hdr.sh_name));
500 if (srel_name == NULL)
501 return false;
502
503 BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0
504 && strcmp (bfd_get_section_name (abfd, sec),
505 srel_name+5) == 0)
506 || (strncmp (srel_name, ".rel", 4) == 0
507 && strcmp (bfd_get_section_name (abfd, sec),
508 srel_name+4) == 0));
509
510 dynobj = hppa_info->root.dynobj;
511 if (!dynobj)
512 hppa_info->root.dynobj = dynobj = abfd;
513
514 srel = bfd_get_section_by_name (dynobj, srel_name);
515 if (srel == NULL)
516 {
517 srel = bfd_make_section (dynobj, srel_name);
518 if (srel == NULL
519 || !bfd_set_section_flags (dynobj, srel,
520 (SEC_ALLOC
521 | SEC_LOAD
522 | SEC_HAS_CONTENTS
523 | SEC_IN_MEMORY
524 | SEC_LINKER_CREATED
525 | SEC_READONLY))
526 || !bfd_set_section_alignment (dynobj, srel, 3))
527 return false;
528 }
529
530 hppa_info->other_rel_sec = srel;
531 return true;
532}
533
534/* Add a new entry to the list of dynamic relocations against DYN_H.
535
536 We use this to keep a record of all the FPTR relocations against a
537 particular symbol so that we can create FPTR relocations in the
538 output file. */
539
540static boolean
541count_dyn_reloc (abfd, dyn_h, type, sec, sec_symndx, offset, addend)
542 bfd *abfd;
543 struct elf64_hppa_dyn_hash_entry *dyn_h;
544 int type;
545 asection *sec;
546 int sec_symndx;
547 bfd_vma offset;
548 bfd_vma addend;
549{
550 struct elf64_hppa_dyn_reloc_entry *rent;
551
552 rent = (struct elf64_hppa_dyn_reloc_entry *)
553 bfd_alloc (abfd, sizeof (*rent));
554 if (!rent)
555 return false;
556
557 rent->next = dyn_h->reloc_entries;
558 rent->type = type;
559 rent->sec = sec;
560 rent->sec_symndx = sec_symndx;
561 rent->offset = offset;
562 rent->addend = addend;
563 dyn_h->reloc_entries = rent;
564
565 return true;
566}
567
568/* Scan the RELOCS and record the type of dynamic entries that each
569 referenced symbol needs. */
570
571static boolean
572elf64_hppa_check_relocs (abfd, info, sec, relocs)
573 bfd *abfd;
574 struct bfd_link_info *info;
575 asection *sec;
576 const Elf_Internal_Rela *relocs;
577{
578 struct elf64_hppa_link_hash_table *hppa_info;
579 const Elf_Internal_Rela *relend;
580 Elf_Internal_Shdr *symtab_hdr;
581 const Elf_Internal_Rela *rel;
582 asection *dlt, *plt, *stubs;
583 char *buf;
584 size_t buf_len;
585 int sec_symndx;
586
587 if (info->relocateable)
588 return true;
589
590 /* If this is the first dynamic object found in the link, create
591 the special sections required for dynamic linking. */
592 if (! elf_hash_table (info)->dynamic_sections_created)
593 {
594 if (! bfd_elf64_link_create_dynamic_sections (abfd, info))
595 return false;
596 }
597
598 hppa_info = elf64_hppa_hash_table (info);
599 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
600
601 /* If necessary, build a new table holding section symbols indices
602 for this BFD. This is disgusting. */
603
604 if (info->shared && hppa_info->section_syms_bfd != abfd)
605 {
606 unsigned long i;
607 int highest_shndx;
608 Elf_Internal_Sym *local_syms, *isym;
609 Elf64_External_Sym *ext_syms, *esym;
610
611 /* We're done with the old cache of section index to section symbol
612 index information. Free it.
613
614 ?!? Note we leak the last section_syms array. Presumably we
615 could free it in one of the later routines in this file. */
616 if (hppa_info->section_syms)
617 free (hppa_info->section_syms);
618
619 /* Allocate memory for the internal and external symbols. */
620 local_syms
621 = (Elf_Internal_Sym *) bfd_malloc (symtab_hdr->sh_info
622 * sizeof (Elf_Internal_Sym));
623 if (local_syms == NULL)
624 return false;
625
626 ext_syms
627 = (Elf64_External_Sym *) bfd_malloc (symtab_hdr->sh_info
628 * sizeof (Elf64_External_Sym));
629 if (ext_syms == NULL)
630 {
631 free (local_syms);
632 return false;
633 }
634
635 /* Read in the local symbols. */
636 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
637 || bfd_read (ext_syms, 1,
638 (symtab_hdr->sh_info
639 * sizeof (Elf64_External_Sym)), abfd)
640 != (symtab_hdr->sh_info * sizeof (Elf64_External_Sym)))
641 {
642 free (local_syms);
643 free (ext_syms);
644 return false;
645 }
646
647 /* Swap in the local symbols, also record the highest section index
648 referenced by the local symbols. */
649 isym = local_syms;
650 esym = ext_syms;
651 highest_shndx = 0;
652 for (i = 0; i < symtab_hdr->sh_info; i++, esym++, isym++)
653 {
654 bfd_elf64_swap_symbol_in (abfd, esym, isym);
655 if (isym->st_shndx > highest_shndx)
656 highest_shndx = isym->st_shndx;
657 }
658
659 /* Now we can free the external symbols. */
660 free (ext_syms);
661
662 /* Allocate an array to hold the section index to section symbol index
663 mapping. Bump by one since we start counting at zero. */
664 highest_shndx++;
665 hppa_info->section_syms = (int *) bfd_malloc (highest_shndx
666 * sizeof (int));
667
668 /* Now walk the local symbols again. If we find a section symbol,
669 record the index of the symbol into the section_syms array. */
670 for (isym = local_syms, i = 0; i < symtab_hdr->sh_info; i++, isym++)
671 {
672 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
673 hppa_info->section_syms[isym->st_shndx] = i;
674 }
675
676 /* We are finished with the local symbols. Get rid of them. */
677 free (local_syms);
678
679 /* Record which BFD we built the section_syms mapping for. */
680 hppa_info->section_syms_bfd = abfd;
681 }
682
683 /* Record the symbol index for this input section. We may need it for
684 relocations when building shared libraries. When not building shared
685 libraries this value is never really used, but assign it to zero to
686 prevent out of bounds memory accesses in other routines. */
687 if (info->shared)
688 {
689 sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec);
690
691 /* If we did not find a section symbol for this section, then
692 something went terribly wrong above. */
693 if (sec_symndx == -1)
694 return false;
695
696 sec_symndx = hppa_info->section_syms[sec_symndx];
697 }
698 else
699 sec_symndx = 0;
700
701 dlt = plt = stubs = NULL;
702 buf = NULL;
703 buf_len = 0;
704
705 relend = relocs + sec->reloc_count;
706 for (rel = relocs; rel < relend; ++rel)
707 {
708 enum {
709 NEED_DLT = 1,
710 NEED_PLT = 2,
711 NEED_STUB = 4,
712 NEED_OPD = 8,
713 NEED_DYNREL = 16,
714 };
715
716 struct elf_link_hash_entry *h = NULL;
717 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
718 struct elf64_hppa_dyn_hash_entry *dyn_h;
719 int need_entry;
720 const char *addr_name;
721 boolean maybe_dynamic;
722 int dynrel_type = R_PARISC_NONE;
723 static reloc_howto_type *howto;
724
725 if (r_symndx >= symtab_hdr->sh_info)
726 {
727 /* We're dealing with a global symbol -- find its hash entry
728 and mark it as being referenced. */
729 long indx = r_symndx - symtab_hdr->sh_info;
730 h = elf_sym_hashes (abfd)[indx];
731 while (h->root.type == bfd_link_hash_indirect
732 || h->root.type == bfd_link_hash_warning)
733 h = (struct elf_link_hash_entry *) h->root.u.i.link;
734
735 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
736 }
737
738 /* We can only get preliminary data on whether a symbol is
739 locally or externally defined, as not all of the input files
740 have yet been processed. Do something with what we know, as
741 this may help reduce memory usage and processing time later. */
742 maybe_dynamic = false;
743 if (h && ((info->shared && ! info->symbolic)
744 || ! (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
745 || h->root.type == bfd_link_hash_defweak))
746 maybe_dynamic = true;
747
748 howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info);
749 need_entry = 0;
750 switch (howto->type)
751 {
752 /* These are simple indirect references to symbols through the
753 DLT. We need to create a DLT entry for any symbols which
754 appears in a DLTIND relocation. */
755 case R_PARISC_DLTIND21L:
756 case R_PARISC_DLTIND14R:
757 case R_PARISC_DLTIND14F:
758 case R_PARISC_DLTIND14WR:
759 case R_PARISC_DLTIND14DR:
760 need_entry = NEED_DLT;
761 break;
762
763 /* ?!? These need a DLT entry. But I have no idea what to do with
764 the "link time TP value. */
765 case R_PARISC_LTOFF_TP21L:
766 case R_PARISC_LTOFF_TP14R:
767 case R_PARISC_LTOFF_TP14F:
768 case R_PARISC_LTOFF_TP64:
769 case R_PARISC_LTOFF_TP14WR:
770 case R_PARISC_LTOFF_TP14DR:
771 case R_PARISC_LTOFF_TP16F:
772 case R_PARISC_LTOFF_TP16WF:
773 case R_PARISC_LTOFF_TP16DF:
774 need_entry = NEED_DLT;
775 break;
776
777 /* These are function calls. Depending on their precise target we
778 may need to make a stub for them. The stub uses the PLT, so we
779 need to create PLT entries for these symbols too. */
780 case R_PARISC_PCREL12F:
781 case R_PARISC_PCREL17F:
782 case R_PARISC_PCREL22F:
783 case R_PARISC_PCREL32:
784 case R_PARISC_PCREL64:
785 case R_PARISC_PCREL21L:
786 case R_PARISC_PCREL17R:
787 case R_PARISC_PCREL17C:
788 case R_PARISC_PCREL14R:
789 case R_PARISC_PCREL14F:
790 case R_PARISC_PCREL22C:
791 case R_PARISC_PCREL14WR:
792 case R_PARISC_PCREL14DR:
793 case R_PARISC_PCREL16F:
794 case R_PARISC_PCREL16WF:
795 case R_PARISC_PCREL16DF:
796 need_entry = (NEED_PLT | NEED_STUB);
797 break;
798
799 case R_PARISC_PLTOFF21L:
800 case R_PARISC_PLTOFF14R:
801 case R_PARISC_PLTOFF14F:
802 case R_PARISC_PLTOFF14WR:
803 case R_PARISC_PLTOFF14DR:
804 case R_PARISC_PLTOFF16F:
805 case R_PARISC_PLTOFF16WF:
806 case R_PARISC_PLTOFF16DF:
807 need_entry = (NEED_PLT);
808 break;
809
810 case R_PARISC_DIR64:
811 if (info->shared || maybe_dynamic)
812 need_entry = (NEED_DYNREL);
813 dynrel_type = R_PARISC_DIR64;
814 break;
815
816 /* This is an indirect reference through the DLT to get the address
817 of a OPD descriptor. Thus we need to make a DLT entry that points
818 to an OPD entry. */
819 case R_PARISC_LTOFF_FPTR21L:
820 case R_PARISC_LTOFF_FPTR14R:
821 case R_PARISC_LTOFF_FPTR14WR:
822 case R_PARISC_LTOFF_FPTR14DR:
823 case R_PARISC_LTOFF_FPTR32:
824 case R_PARISC_LTOFF_FPTR64:
825 case R_PARISC_LTOFF_FPTR16F:
826 case R_PARISC_LTOFF_FPTR16WF:
827 case R_PARISC_LTOFF_FPTR16DF:
828 if (info->shared || maybe_dynamic)
829 need_entry = (NEED_DLT | NEED_OPD);
830 else
831 need_entry = (NEED_DLT | NEED_OPD);
832 dynrel_type = R_PARISC_FPTR64;
833 break;
834
835 /* This is a simple OPD entry. */
836 case R_PARISC_FPTR64:
837 if (info->shared || maybe_dynamic)
838 need_entry = (NEED_OPD | NEED_DYNREL);
839 else
840 need_entry = (NEED_OPD);
841 dynrel_type = R_PARISC_FPTR64;
842 break;
843
844 /* Add more cases as needed. */
845 }
846
847 if (!need_entry)
848 continue;
849
850 /* Collect a canonical name for this address. */
851 addr_name = get_dyn_name (sec, h, rel, &buf, &buf_len);
852
853 /* Collect the canonical entry data for this address. */
854 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
855 addr_name, true, true);
856 BFD_ASSERT (dyn_h);
857
858 /* Stash away enough information to be able to find this symbol
859 regardless of whether or not it is local or global. */
860 dyn_h->h = h;
861 dyn_h->owner = abfd;
862 dyn_h->sym_indx = r_symndx;
863
864 /* ?!? We may need to do some error checking in here. */
865 /* Create what's needed. */
866 if (need_entry & NEED_DLT)
867 {
868 if (! hppa_info->dlt_sec
869 && ! get_dlt (abfd, info, hppa_info))
870 goto err_out;
871 dyn_h->want_dlt = 1;
872 }
873
874 if (need_entry & NEED_PLT)
875 {
876 if (! hppa_info->plt_sec
877 && ! get_plt (abfd, info, hppa_info))
878 goto err_out;
879 dyn_h->want_plt = 1;
880 }
881
882 if (need_entry & NEED_STUB)
883 {
884 if (! hppa_info->stub_sec
885 && ! get_stub (abfd, info, hppa_info))
886 goto err_out;
887 dyn_h->want_stub = 1;
888 }
889
890 if (need_entry & NEED_OPD)
891 {
892 if (! hppa_info->opd_sec
893 && ! get_opd (abfd, info, hppa_info))
894 goto err_out;
895
896 dyn_h->want_opd = 1;
897
898 /* FPTRs are not allocated by the dynamic linker for PA64, though
899 it is possible that will change in the future. */
900
901 /* This could be a local function that had its address taken, in
902 which case H will be NULL. */
903 if (h)
904 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
905 }
906
907 /* Add a new dynamic relocation to the chain of dynamic
908 relocations for this symbol. */
909 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
910 {
911 if (! hppa_info->other_rel_sec
912 && ! get_reloc_section (abfd, hppa_info, sec))
913 goto err_out;
914
915 if (!count_dyn_reloc (abfd, dyn_h, dynrel_type, sec,
916 sec_symndx, rel->r_offset, rel->r_addend))
917 goto err_out;
918
919 /* If we are building a shared library and we just recorded
920 a dynamic R_PARISC_FPTR64 relocation, then make sure the
921 section symbol for this section ends up in the dynamic
922 symbol table. */
923 if (info->shared && dynrel_type == R_PARISC_FPTR64
924 && ! (_bfd_elf64_link_record_local_dynamic_symbol
925 (info, abfd, sec_symndx)))
926 return false;
927 }
928 }
929
930 if (buf)
931 free (buf);
932 return true;
933
934 err_out:
935 if (buf)
936 free (buf);
937 return false;
938}
939
940struct elf64_hppa_allocate_data
941{
942 struct bfd_link_info *info;
943 bfd_size_type ofs;
944};
945
946/* Should we do dynamic things to this symbol? */
947
948static boolean
949elf64_hppa_dynamic_symbol_p (h, info)
950 struct elf_link_hash_entry *h;
951 struct bfd_link_info *info;
952{
953 if (h == NULL)
954 return false;
955
956 while (h->root.type == bfd_link_hash_indirect
957 || h->root.type == bfd_link_hash_warning)
958 h = (struct elf_link_hash_entry *) h->root.u.i.link;
959
960 if (h->dynindx == -1)
961 return false;
962
963 if (h->root.type == bfd_link_hash_undefweak
964 || h->root.type == bfd_link_hash_defweak)
965 return true;
966
967 if (h->root.root.string[0] == '$' && h->root.root.string[1] == '$')
968 return false;
969
970 if ((info->shared && !info->symbolic)
971 || ((h->elf_link_hash_flags
972 & (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR))
973 == (ELF_LINK_HASH_DEF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR)))
974 return true;
975
976 return false;
977}
978
979/* Mark all funtions exported by this file so that we can later allocate
980 entries in .opd for them. */
981
982static boolean
983elf64_hppa_mark_exported_functions (h, data)
984 struct elf_link_hash_entry *h;
985 PTR data;
986{
987 struct bfd_link_info *info = (struct bfd_link_info *)data;
988 struct elf64_hppa_link_hash_table *hppa_info;
989
990 hppa_info = elf64_hppa_hash_table (info);
991
992 if (h
993 && (h->root.type == bfd_link_hash_defined
994 || h->root.type == bfd_link_hash_defweak)
995 && h->root.u.def.section->output_section != NULL
996 && h->type == STT_FUNC)
997 {
998 struct elf64_hppa_dyn_hash_entry *dyn_h;
999
1000 /* Add this symbol to the PA64 linker hash table. */
1001 dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
1002 h->root.root.string, true, true);
1003 BFD_ASSERT (dyn_h);
1004 dyn_h->h = h;
1005
1006 if (! hppa_info->opd_sec
1007 && ! get_opd (hppa_info->root.dynobj, info, hppa_info))
1008 return false;
1009
1010 dyn_h->want_opd = 1;
1011 /* Put a flag here for output_symbol_hook. */
1012 dyn_h->st_shndx = -1;
1013 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1014 }
1015
1016 return true;
1017}
1018
1019/* Allocate space for a DLT entry. */
1020
1021static boolean
1022allocate_global_data_dlt (dyn_h, data)
1023 struct elf64_hppa_dyn_hash_entry *dyn_h;
1024 PTR data;
1025{
1026 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1027
1028 if (dyn_h->want_dlt)
1029 {
1030 struct elf_link_hash_entry *h = dyn_h->h;
1031
1032 if (x->info->shared)
1033 {
1034 /* Possibly add the symbol to the local dynamic symbol
1035 table since we might need to create a dynamic relocation
1036 against it. */
1037 if (! h
1038 || (h && h->dynindx == -1))
1039 {
1040 bfd *owner;
1041 owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
1042
1043 if (!_bfd_elf64_link_record_local_dynamic_symbol
1044 (x->info, owner, dyn_h->sym_indx))
1045 return false;
1046 }
1047 }
1048
1049 dyn_h->dlt_offset = x->ofs;
1050 x->ofs += DLT_ENTRY_SIZE;
1051 }
1052 return true;
1053}
1054
1055/* Allocate space for a DLT.PLT entry. */
1056
1057static boolean
1058allocate_global_data_plt (dyn_h, data)
1059 struct elf64_hppa_dyn_hash_entry *dyn_h;
1060 PTR data;
1061{
1062 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1063
1064 if (dyn_h->want_plt
1065 && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info)
1066 && !((dyn_h->h->root.type == bfd_link_hash_defined
1067 || dyn_h->h->root.type == bfd_link_hash_defweak)
1068 && dyn_h->h->root.u.def.section->output_section != NULL))
1069 {
1070 dyn_h->plt_offset = x->ofs;
1071 x->ofs += PLT_ENTRY_SIZE;
1072 if (dyn_h->plt_offset < 0x2000)
1073 elf64_hppa_hash_table (x->info)->gp_offset = dyn_h->plt_offset;
1074 }
1075 else
1076 dyn_h->want_plt = 0;
1077
1078 return true;
1079}
1080
1081/* Allocate space for a STUB entry. */
1082
1083static boolean
1084allocate_global_data_stub (dyn_h, data)
1085 struct elf64_hppa_dyn_hash_entry *dyn_h;
1086 PTR data;
1087{
1088 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1089
1090 if (dyn_h->want_stub
1091 && elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info)
1092 && !((dyn_h->h->root.type == bfd_link_hash_defined
1093 || dyn_h->h->root.type == bfd_link_hash_defweak)
1094 && dyn_h->h->root.u.def.section->output_section != NULL))
1095 {
1096 dyn_h->stub_offset = x->ofs;
1097 x->ofs += sizeof (plt_stub);
1098 }
1099 else
1100 dyn_h->want_stub = 0;
1101 return true;
1102}
1103
1104/* Allocate space for a FPTR entry. */
1105
1106static boolean
1107allocate_global_data_opd (dyn_h, data)
1108 struct elf64_hppa_dyn_hash_entry *dyn_h;
1109 PTR data;
1110{
1111 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1112
1113 if (dyn_h->want_opd)
1114 {
1115 struct elf_link_hash_entry *h = dyn_h->h;
1116
1117 if (h)
1118 while (h->root.type == bfd_link_hash_indirect
1119 || h->root.type == bfd_link_hash_warning)
1120 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1121
1122 /* We never need an opd entry for a symbol which is not
1123 defined by this output file. */
1124 if (h && h->root.type == bfd_link_hash_undefined)
1125 dyn_h->want_opd = 0;
1126
1127 /* If we are creating a shared library, took the address of a local
1128 function or might export this function from this object file, then
1129 we have to create an opd descriptor. */
1130 else if (x->info->shared
1131 || h == NULL
1132 || h->dynindx == -1
1133 || ((h->root.type == bfd_link_hash_defined
1134 || h->root.type == bfd_link_hash_defweak)
1135 && h->root.u.def.section->output_section != NULL))
1136 {
1137 /* If we are creating a shared library, then we will have to
1138 create a runtime relocation for the symbol to properly
1139 initialize the .opd entry. Make sure the symbol gets
1140 added to the dynamic symbol table. */
1141 if (x->info->shared
1142 && (h == NULL || (h->dynindx == -1)))
1143 {
1144 bfd *owner;
1145 owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
1146
1147 if (!_bfd_elf64_link_record_local_dynamic_symbol
1148 (x->info, owner, dyn_h->sym_indx))
1149 return false;
1150 }
1151
1152 /* This may not be necessary or desirable anymore now that
1153 we have some support for dealing with section symbols
1154 in dynamic relocs. But name munging does make the result
1155 much easier to debug. ie, the EPLT reloc will reference
1156 a symbol like .foobar, instead of .text + offset. */
1157 if (x->info->shared && h)
1158 {
1159 char *new_name;
1160 struct elf_link_hash_entry *nh;
1161
1162 new_name = alloca (strlen (h->root.root.string) + 2);
1163 new_name[0] = '.';
1164 strcpy (new_name + 1, h->root.root.string);
1165
1166 nh = elf_link_hash_lookup (elf_hash_table (x->info),
1167 new_name, true, true, true);
1168
1169 nh->root.type = h->root.type;
1170 nh->root.u.def.value = h->root.u.def.value;
1171 nh->root.u.def.section = h->root.u.def.section;
1172
1173 if (! bfd_elf64_link_record_dynamic_symbol (x->info, nh))
1174 return false;
1175
1176 }
1177 dyn_h->opd_offset = x->ofs;
1178 x->ofs += OPD_ENTRY_SIZE;
1179 }
1180
1181 /* Otherwise we do not need an opd entry. */
1182 else
1183 dyn_h->want_opd = 0;
1184 }
1185 return true;
1186}
1187
1188/* HP requires the EI_OSABI field to be filled in. The assignment to
1189 EI_ABIVERSION may not be strictly necessary. */
1190
1191static void
1192elf64_hppa_post_process_headers (abfd, link_info)
1193 bfd * abfd;
1194 struct bfd_link_info * link_info ATTRIBUTE_UNUSED;
1195{
1196 Elf_Internal_Ehdr * i_ehdrp;
1197
1198 i_ehdrp = elf_elfheader (abfd);
1199
1200 if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
1201 {
1202 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX;
1203 }
1204 else
1205 {
1206 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX;
1207 i_ehdrp->e_ident[EI_ABIVERSION] = 1;
1208 }
1209}
1210
1211/* Create function descriptor section (.opd). This section is called .opd
1212 because it contains "official prodecure descriptors". The "official"
1213 refers to the fact that these descriptors are used when taking the address
1214 of a procedure, thus ensuring a unique address for each procedure. */
1215
1216static boolean
1217get_opd (abfd, info, hppa_info)
1218 bfd *abfd;
1219 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1220 struct elf64_hppa_link_hash_table *hppa_info;
1221{
1222 asection *opd;
1223 bfd *dynobj;
1224
1225 opd = hppa_info->opd_sec;
1226 if (!opd)
1227 {
1228 dynobj = hppa_info->root.dynobj;
1229 if (!dynobj)
1230 hppa_info->root.dynobj = dynobj = abfd;
1231
1232 opd = bfd_make_section (dynobj, ".opd");
1233 if (!opd
1234 || !bfd_set_section_flags (dynobj, opd,
1235 (SEC_ALLOC
1236 | SEC_LOAD
1237 | SEC_HAS_CONTENTS
1238 | SEC_IN_MEMORY
1239 | SEC_LINKER_CREATED))
1240 || !bfd_set_section_alignment (abfd, opd, 3))
1241 {
1242 BFD_ASSERT (0);
1243 return false;
1244 }
1245
1246 hppa_info->opd_sec = opd;
1247 }
1248
1249 return true;
1250}
1251
1252/* Create the PLT section. */
1253
1254static boolean
1255get_plt (abfd, info, hppa_info)
1256 bfd *abfd;
1257 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1258 struct elf64_hppa_link_hash_table *hppa_info;
1259{
1260 asection *plt;
1261 bfd *dynobj;
1262
1263 plt = hppa_info->plt_sec;
1264 if (!plt)
1265 {
1266 dynobj = hppa_info->root.dynobj;
1267 if (!dynobj)
1268 hppa_info->root.dynobj = dynobj = abfd;
1269
1270 plt = bfd_make_section (dynobj, ".plt");
1271 if (!plt
1272 || !bfd_set_section_flags (dynobj, plt,
1273 (SEC_ALLOC
1274 | SEC_LOAD
1275 | SEC_HAS_CONTENTS
1276 | SEC_IN_MEMORY
1277 | SEC_LINKER_CREATED))
1278 || !bfd_set_section_alignment (abfd, plt, 3))
1279 {
1280 BFD_ASSERT (0);
1281 return false;
1282 }
1283
1284 hppa_info->plt_sec = plt;
1285 }
1286
1287 return true;
1288}
1289
1290/* Create the DLT section. */
1291
1292static boolean
1293get_dlt (abfd, info, hppa_info)
1294 bfd *abfd;
1295 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1296 struct elf64_hppa_link_hash_table *hppa_info;
1297{
1298 asection *dlt;
1299 bfd *dynobj;
1300
1301 dlt = hppa_info->dlt_sec;
1302 if (!dlt)
1303 {
1304 dynobj = hppa_info->root.dynobj;
1305 if (!dynobj)
1306 hppa_info->root.dynobj = dynobj = abfd;
1307
1308 dlt = bfd_make_section (dynobj, ".dlt");
1309 if (!dlt
1310 || !bfd_set_section_flags (dynobj, dlt,
1311 (SEC_ALLOC
1312 | SEC_LOAD
1313 | SEC_HAS_CONTENTS
1314 | SEC_IN_MEMORY
1315 | SEC_LINKER_CREATED))
1316 || !bfd_set_section_alignment (abfd, dlt, 3))
1317 {
1318 BFD_ASSERT (0);
1319 return false;
1320 }
1321
1322 hppa_info->dlt_sec = dlt;
1323 }
1324
1325 return true;
1326}
1327
1328/* Create the stubs section. */
1329
1330static boolean
1331get_stub (abfd, info, hppa_info)
1332 bfd *abfd;
1333 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1334 struct elf64_hppa_link_hash_table *hppa_info;
1335{
1336 asection *stub;
1337 bfd *dynobj;
1338
1339 stub = hppa_info->stub_sec;
1340 if (!stub)
1341 {
1342 dynobj = hppa_info->root.dynobj;
1343 if (!dynobj)
1344 hppa_info->root.dynobj = dynobj = abfd;
1345
1346 stub = bfd_make_section (dynobj, ".stub");
1347 if (!stub
1348 || !bfd_set_section_flags (dynobj, stub,
1349 (SEC_ALLOC
1350 | SEC_LOAD
1351 | SEC_HAS_CONTENTS
1352 | SEC_IN_MEMORY
1353 | SEC_READONLY
1354 | SEC_LINKER_CREATED))
1355 || !bfd_set_section_alignment (abfd, stub, 3))
1356 {
1357 BFD_ASSERT (0);
1358 return false;
1359 }
1360
1361 hppa_info->stub_sec = stub;
1362 }
1363
1364 return true;
1365}
1366
1367/* Create sections necessary for dynamic linking. This is only a rough
1368 cut and will likely change as we learn more about the somewhat
1369 unusual dynamic linking scheme HP uses.
1370
1371 .stub:
1372 Contains code to implement cross-space calls. The first time one
1373 of the stubs is used it will call into the dynamic linker, later
1374 calls will go straight to the target.
1375
1376 The only stub we support right now looks like
1377
1378 ldd OFFSET(%dp),%r1
1379 bve %r0(%r1)
1380 ldd OFFSET+8(%dp),%dp
1381
1382 Other stubs may be needed in the future. We may want the remove
1383 the break/nop instruction. It is only used right now to keep the
1384 offset of a .plt entry and a .stub entry in sync.
1385
1386 .dlt:
1387 This is what most people call the .got. HP used a different name.
1388 Losers.
1389
1390 .rela.dlt:
1391 Relocations for the DLT.
1392
1393 .plt:
1394 Function pointers as address,gp pairs.
1395
1396 .rela.plt:
1397 Should contain dynamic IPLT (and EPLT?) relocations.
1398
1399 .opd:
1400 FPTRS
1401
1402 .rela.opd:
1403 EPLT relocations for symbols exported from shared libraries. */
1404
1405static boolean
1406elf64_hppa_create_dynamic_sections (abfd, info)
1407 bfd *abfd;
1408 struct bfd_link_info *info;
1409{
1410 asection *s;
1411
1412 if (! get_stub (abfd, info, elf64_hppa_hash_table (info)))
1413 return false;
1414
1415 if (! get_dlt (abfd, info, elf64_hppa_hash_table (info)))
1416 return false;
1417
1418 if (! get_plt (abfd, info, elf64_hppa_hash_table (info)))
1419 return false;
1420
1421 if (! get_opd (abfd, info, elf64_hppa_hash_table (info)))
1422 return false;
1423
1424 s = bfd_make_section(abfd, ".rela.dlt");
1425 if (s == NULL
1426 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1427 | SEC_HAS_CONTENTS
1428 | SEC_IN_MEMORY
1429 | SEC_READONLY
1430 | SEC_LINKER_CREATED))
1431 || !bfd_set_section_alignment (abfd, s, 3))
1432 return false;
1433 elf64_hppa_hash_table (info)->dlt_rel_sec = s;
1434
1435 s = bfd_make_section(abfd, ".rela.plt");
1436 if (s == NULL
1437 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1438 | SEC_HAS_CONTENTS
1439 | SEC_IN_MEMORY
1440 | SEC_READONLY
1441 | SEC_LINKER_CREATED))
1442 || !bfd_set_section_alignment (abfd, s, 3))
1443 return false;
1444 elf64_hppa_hash_table (info)->plt_rel_sec = s;
1445
1446 s = bfd_make_section(abfd, ".rela.data");
1447 if (s == NULL
1448 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1449 | SEC_HAS_CONTENTS
1450 | SEC_IN_MEMORY
1451 | SEC_READONLY
1452 | SEC_LINKER_CREATED))
1453 || !bfd_set_section_alignment (abfd, s, 3))
1454 return false;
1455 elf64_hppa_hash_table (info)->other_rel_sec = s;
1456
1457 s = bfd_make_section(abfd, ".rela.opd");
1458 if (s == NULL
1459 || !bfd_set_section_flags (abfd, s, (SEC_ALLOC | SEC_LOAD
1460 | SEC_HAS_CONTENTS
1461 | SEC_IN_MEMORY
1462 | SEC_READONLY
1463 | SEC_LINKER_CREATED))
1464 || !bfd_set_section_alignment (abfd, s, 3))
1465 return false;
1466 elf64_hppa_hash_table (info)->opd_rel_sec = s;
1467
1468 return true;
1469}
1470
1471/* Allocate dynamic relocations for those symbols that turned out
1472 to be dynamic. */
1473
1474static boolean
1475allocate_dynrel_entries (dyn_h, data)
1476 struct elf64_hppa_dyn_hash_entry *dyn_h;
1477 PTR data;
1478{
1479 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1480 struct elf64_hppa_link_hash_table *hppa_info;
1481 struct elf64_hppa_dyn_reloc_entry *rent;
1482 boolean dynamic_symbol, shared;
1483
1484 hppa_info = elf64_hppa_hash_table (x->info);
1485 dynamic_symbol = elf64_hppa_dynamic_symbol_p (dyn_h->h, x->info);
1486 shared = x->info->shared;
1487
1488 /* We may need to allocate relocations for a non-dynamic symbol
1489 when creating a shared library. */
1490 if (!dynamic_symbol && !shared)
1491 return true;
1492
1493 /* Take care of the normal data relocations. */
1494