OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [bfd/] [elf64-hppa.c] - Blame information for rev 853

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
/* Support for HPPA 64-bit ELF
2
   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3
   2010  Free Software Foundation, Inc.
4
 
5
   This file is part of BFD, the Binary File Descriptor library.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
 
22
#include "alloca-conf.h"
23
#include "sysdep.h"
24
#include "bfd.h"
25
#include "libbfd.h"
26
#include "elf-bfd.h"
27
#include "elf/hppa.h"
28
#include "libhppa.h"
29
#include "elf64-hppa.h"
30
 
31
 
32
#define ARCH_SIZE              64
33
 
34
#define PLT_ENTRY_SIZE 0x10
35
#define DLT_ENTRY_SIZE 0x8
36
#define OPD_ENTRY_SIZE 0x20
37
 
38
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl"
39
 
40
/* The stub is supposed to load the target address and target's DP
41
   value out of the PLT, then do an external branch to the target
42
   address.
43
 
44
   LDD PLTOFF(%r27),%r1
45
   BVE (%r1)
46
   LDD PLTOFF+8(%r27),%r27
47
 
48
   Note that we must use the LDD with a 14 bit displacement, not the one
49
   with a 5 bit displacement.  */
50
static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00,
51
                          0x53, 0x7b, 0x00, 0x00 };
52
 
53
struct elf64_hppa_link_hash_entry
54
{
55
  struct elf_link_hash_entry eh;
56
 
57
  /* Offsets for this symbol in various linker sections.  */
58
  bfd_vma dlt_offset;
59
  bfd_vma plt_offset;
60
  bfd_vma opd_offset;
61
  bfd_vma stub_offset;
62
 
63
  /* The index of the (possibly local) symbol in the input bfd and its
64
     associated BFD.  Needed so that we can have relocs against local
65
     symbols in shared libraries.  */
66
  long sym_indx;
67
  bfd *owner;
68
 
69
  /* Dynamic symbols may need to have two different values.  One for
70
     the dynamic symbol table, one for the normal symbol table.
71
 
72
     In such cases we store the symbol's real value and section
73
     index here so we can restore the real value before we write
74
     the normal symbol table.  */
75
  bfd_vma st_value;
76
  int st_shndx;
77
 
78
  /* Used to count non-got, non-plt relocations for delayed sizing
79
     of relocation sections.  */
80
  struct elf64_hppa_dyn_reloc_entry
81
  {
82
    /* Next relocation in the chain.  */
83
    struct elf64_hppa_dyn_reloc_entry *next;
84
 
85
    /* The type of the relocation.  */
86
    int type;
87
 
88
    /* The input section of the relocation.  */
89
    asection *sec;
90
 
91
    /* Number of relocs copied in this section.  */
92
    bfd_size_type count;
93
 
94
    /* The index of the section symbol for the input section of
95
       the relocation.  Only needed when building shared libraries.  */
96
    int sec_symndx;
97
 
98
    /* The offset within the input section of the relocation.  */
99
    bfd_vma offset;
100
 
101
    /* The addend for the relocation.  */
102
    bfd_vma addend;
103
 
104
  } *reloc_entries;
105
 
106
  /* Nonzero if this symbol needs an entry in one of the linker
107
     sections.  */
108
  unsigned want_dlt;
109
  unsigned want_plt;
110
  unsigned want_opd;
111
  unsigned want_stub;
112
};
113
 
114
struct elf64_hppa_link_hash_table
115
{
116
  struct elf_link_hash_table root;
117
 
118
  /* Shortcuts to get to the various linker defined sections.  */
119
  asection *dlt_sec;
120
  asection *dlt_rel_sec;
121
  asection *plt_sec;
122
  asection *plt_rel_sec;
123
  asection *opd_sec;
124
  asection *opd_rel_sec;
125
  asection *other_rel_sec;
126
 
127
  /* Offset of __gp within .plt section.  When the PLT gets large we want
128
     to slide __gp into the PLT section so that we can continue to use
129
     single DP relative instructions to load values out of the PLT.  */
130
  bfd_vma gp_offset;
131
 
132
  /* Note this is not strictly correct.  We should create a stub section for
133
     each input section with calls.  The stub section should be placed before
134
     the section with the call.  */
135
  asection *stub_sec;
136
 
137
  bfd_vma text_segment_base;
138
  bfd_vma data_segment_base;
139
 
140
  /* We build tables to map from an input section back to its
141
     symbol index.  This is the BFD for which we currently have
142
     a map.  */
143
  bfd *section_syms_bfd;
144
 
145
  /* Array of symbol numbers for each input section attached to the
146
     current BFD.  */
147
  int *section_syms;
148
};
149
 
150
#define hppa_link_hash_table(p) \
151
  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
152
  == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL)
153
 
154
#define hppa_elf_hash_entry(ent) \
155
  ((struct elf64_hppa_link_hash_entry *)(ent))
156
 
157
#define eh_name(eh) \
158
  (eh ? eh->root.root.string : "<undef>")
159
 
160
typedef struct bfd_hash_entry *(*new_hash_entry_func)
161
  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
162
 
163
static struct bfd_link_hash_table *elf64_hppa_hash_table_create
164
  (bfd *abfd);
165
 
166
/* This must follow the definitions of the various derived linker
167
   hash tables and shared functions.  */
168
#include "elf-hppa.h"
169
 
170
static bfd_boolean elf64_hppa_object_p
171
  (bfd *);
172
 
173
static void elf64_hppa_post_process_headers
174
  (bfd *, struct bfd_link_info *);
175
 
176
static bfd_boolean elf64_hppa_create_dynamic_sections
177
  (bfd *, struct bfd_link_info *);
178
 
179
static bfd_boolean elf64_hppa_adjust_dynamic_symbol
180
  (struct bfd_link_info *, struct elf_link_hash_entry *);
181
 
182
static bfd_boolean elf64_hppa_mark_milli_and_exported_functions
183
  (struct elf_link_hash_entry *, void *);
184
 
185
static bfd_boolean elf64_hppa_size_dynamic_sections
186
  (bfd *, struct bfd_link_info *);
187
 
188
static int elf64_hppa_link_output_symbol_hook
189
  (struct bfd_link_info *, const char *, Elf_Internal_Sym *,
190
   asection *, struct elf_link_hash_entry *);
191
 
192
static bfd_boolean elf64_hppa_finish_dynamic_symbol
193
  (bfd *, struct bfd_link_info *,
194
   struct elf_link_hash_entry *, Elf_Internal_Sym *);
195
 
196
static enum elf_reloc_type_class elf64_hppa_reloc_type_class
197
  (const Elf_Internal_Rela *);
198
 
199
static bfd_boolean elf64_hppa_finish_dynamic_sections
200
  (bfd *, struct bfd_link_info *);
201
 
202
static bfd_boolean elf64_hppa_check_relocs
203
  (bfd *, struct bfd_link_info *,
204
   asection *, const Elf_Internal_Rela *);
205
 
206
static bfd_boolean elf64_hppa_dynamic_symbol_p
207
  (struct elf_link_hash_entry *, struct bfd_link_info *);
208
 
209
static bfd_boolean elf64_hppa_mark_exported_functions
210
  (struct elf_link_hash_entry *, void *);
211
 
212
static bfd_boolean elf64_hppa_finalize_opd
213
  (struct elf_link_hash_entry *, void *);
214
 
215
static bfd_boolean elf64_hppa_finalize_dlt
216
  (struct elf_link_hash_entry *, void *);
217
 
218
static bfd_boolean allocate_global_data_dlt
219
  (struct elf_link_hash_entry *, void *);
220
 
221
static bfd_boolean allocate_global_data_plt
222
  (struct elf_link_hash_entry *, void *);
223
 
224
static bfd_boolean allocate_global_data_stub
225
  (struct elf_link_hash_entry *, void *);
226
 
227
static bfd_boolean allocate_global_data_opd
228
  (struct elf_link_hash_entry *, void *);
229
 
230
static bfd_boolean get_reloc_section
231
  (bfd *, struct elf64_hppa_link_hash_table *, asection *);
232
 
233
static bfd_boolean count_dyn_reloc
234
  (bfd *, struct elf64_hppa_link_hash_entry *,
235
   int, asection *, int, bfd_vma, bfd_vma);
236
 
237
static bfd_boolean allocate_dynrel_entries
238
  (struct elf_link_hash_entry *, void *);
239
 
240
static bfd_boolean elf64_hppa_finalize_dynreloc
241
  (struct elf_link_hash_entry *, void *);
242
 
243
static bfd_boolean get_opd
244
  (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
245
 
246
static bfd_boolean get_plt
247
  (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
248
 
249
static bfd_boolean get_dlt
250
  (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
251
 
252
static bfd_boolean get_stub
253
  (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *);
254
 
255
static int elf64_hppa_elf_get_symbol_type
256
  (Elf_Internal_Sym *, int);
257
 
258
/* Initialize an entry in the link hash table.  */
259
 
260
static struct bfd_hash_entry *
261
hppa64_link_hash_newfunc (struct bfd_hash_entry *entry,
262
                          struct bfd_hash_table *table,
263
                          const char *string)
264
{
265
  /* Allocate the structure if it has not already been allocated by a
266
     subclass.  */
267
  if (entry == NULL)
268
    {
269
      entry = bfd_hash_allocate (table,
270
                                 sizeof (struct elf64_hppa_link_hash_entry));
271
      if (entry == NULL)
272
        return entry;
273
    }
274
 
275
  /* Call the allocation method of the superclass.  */
276
  entry = _bfd_elf_link_hash_newfunc (entry, table, string);
277
  if (entry != NULL)
278
    {
279
      struct elf64_hppa_link_hash_entry *hh;
280
 
281
      /* Initialize our local data.  All zeros.  */
282
      hh = hppa_elf_hash_entry (entry);
283
      memset (&hh->dlt_offset, 0,
284
              (sizeof (struct elf64_hppa_link_hash_entry)
285
               - offsetof (struct elf64_hppa_link_hash_entry, dlt_offset)));
286
    }
287
 
288
  return entry;
289
}
290
 
291
/* Create the derived linker hash table.  The PA64 ELF port uses this
292
   derived hash table to keep information specific to the PA ElF
293
   linker (without using static variables).  */
294
 
295
static struct bfd_link_hash_table*
296
elf64_hppa_hash_table_create (bfd *abfd)
297
{
298
  struct elf64_hppa_link_hash_table *htab;
299
  bfd_size_type amt = sizeof (*htab);
300
 
301
  htab = bfd_zalloc (abfd, amt);
302
  if (htab == NULL)
303
    return NULL;
304
 
305
  if (!_bfd_elf_link_hash_table_init (&htab->root, abfd,
306
                                      hppa64_link_hash_newfunc,
307
                                      sizeof (struct elf64_hppa_link_hash_entry),
308
                                      HPPA64_ELF_DATA))
309
    {
310
      bfd_release (abfd, htab);
311
      return NULL;
312
    }
313
 
314
  htab->text_segment_base = (bfd_vma) -1;
315
  htab->data_segment_base = (bfd_vma) -1;
316
 
317
  return &htab->root.root;
318
}
319
 
320
/* Return nonzero if ABFD represents a PA2.0 ELF64 file.
321
 
322
   Additionally we set the default architecture and machine.  */
323
static bfd_boolean
324
elf64_hppa_object_p (bfd *abfd)
325
{
326
  Elf_Internal_Ehdr * i_ehdrp;
327
  unsigned int flags;
328
 
329
  i_ehdrp = elf_elfheader (abfd);
330
  if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0)
331
    {
332
      /* GCC on hppa-linux produces binaries with OSABI=Linux,
333
         but the kernel produces corefiles with OSABI=SysV.  */
334
      if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX
335
          && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
336
        return FALSE;
337
    }
338
  else
339
    {
340
      /* HPUX produces binaries with OSABI=HPUX,
341
         but the kernel produces corefiles with OSABI=SysV.  */
342
      if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX
343
          && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
344
        return FALSE;
345
    }
346
 
347
  flags = i_ehdrp->e_flags;
348
  switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
349
    {
350
    case EFA_PARISC_1_0:
351
      return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
352
    case EFA_PARISC_1_1:
353
      return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
354
    case EFA_PARISC_2_0:
355
      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
356
        return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
357
      else
358
        return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
359
    case EFA_PARISC_2_0 | EF_PARISC_WIDE:
360
      return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
361
    }
362
  /* Don't be fussy.  */
363
  return TRUE;
364
}
365
 
366
/* Given section type (hdr->sh_type), return a boolean indicating
367
   whether or not the section is an elf64-hppa specific section.  */
368
static bfd_boolean
369
elf64_hppa_section_from_shdr (bfd *abfd,
370
                              Elf_Internal_Shdr *hdr,
371
                              const char *name,
372
                              int shindex)
373
{
374
  asection *newsect;
375
 
376
  switch (hdr->sh_type)
377
    {
378
    case SHT_PARISC_EXT:
379
      if (strcmp (name, ".PARISC.archext") != 0)
380
        return FALSE;
381
      break;
382
    case SHT_PARISC_UNWIND:
383
      if (strcmp (name, ".PARISC.unwind") != 0)
384
        return FALSE;
385
      break;
386
    case SHT_PARISC_DOC:
387
    case SHT_PARISC_ANNOT:
388
    default:
389
      return FALSE;
390
    }
391
 
392
  if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
393
    return FALSE;
394
  newsect = hdr->bfd_section;
395
 
396
  return TRUE;
397
}
398
 
399
/* SEC is a section containing relocs for an input BFD when linking; return
400
   a suitable section for holding relocs in the output BFD for a link.  */
401
 
402
static bfd_boolean
403
get_reloc_section (bfd *abfd,
404
                   struct elf64_hppa_link_hash_table *hppa_info,
405
                   asection *sec)
406
{
407
  const char *srel_name;
408
  asection *srel;
409
  bfd *dynobj;
410
 
411
  srel_name = (bfd_elf_string_from_elf_section
412
               (abfd, elf_elfheader(abfd)->e_shstrndx,
413
                elf_section_data(sec)->rel_hdr.sh_name));
414
  if (srel_name == NULL)
415
    return FALSE;
416
 
417
  BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
418
               && strcmp (bfd_get_section_name (abfd, sec),
419
                          srel_name + 5) == 0)
420
              || (CONST_STRNEQ (srel_name, ".rel")
421
                  && strcmp (bfd_get_section_name (abfd, sec),
422
                             srel_name + 4) == 0));
423
 
424
  dynobj = hppa_info->root.dynobj;
425
  if (!dynobj)
426
    hppa_info->root.dynobj = dynobj = abfd;
427
 
428
  srel = bfd_get_section_by_name (dynobj, srel_name);
429
  if (srel == NULL)
430
    {
431
      srel = bfd_make_section_with_flags (dynobj, srel_name,
432
                                          (SEC_ALLOC
433
                                           | SEC_LOAD
434
                                           | SEC_HAS_CONTENTS
435
                                           | SEC_IN_MEMORY
436
                                           | SEC_LINKER_CREATED
437
                                           | SEC_READONLY));
438
      if (srel == NULL
439
          || !bfd_set_section_alignment (dynobj, srel, 3))
440
        return FALSE;
441
    }
442
 
443
  hppa_info->other_rel_sec = srel;
444
  return TRUE;
445
}
446
 
447
/* Add a new entry to the list of dynamic relocations against DYN_H.
448
 
449
   We use this to keep a record of all the FPTR relocations against a
450
   particular symbol so that we can create FPTR relocations in the
451
   output file.  */
452
 
453
static bfd_boolean
454
count_dyn_reloc (bfd *abfd,
455
                 struct elf64_hppa_link_hash_entry *hh,
456
                 int type,
457
                 asection *sec,
458
                 int sec_symndx,
459
                 bfd_vma offset,
460
                 bfd_vma addend)
461
{
462
  struct elf64_hppa_dyn_reloc_entry *rent;
463
 
464
  rent = (struct elf64_hppa_dyn_reloc_entry *)
465
  bfd_alloc (abfd, (bfd_size_type) sizeof (*rent));
466
  if (!rent)
467
    return FALSE;
468
 
469
  rent->next = hh->reloc_entries;
470
  rent->type = type;
471
  rent->sec = sec;
472
  rent->sec_symndx = sec_symndx;
473
  rent->offset = offset;
474
  rent->addend = addend;
475
  hh->reloc_entries = rent;
476
 
477
  return TRUE;
478
}
479
 
480
/* Return a pointer to the local DLT, PLT and OPD reference counts
481
   for ABFD.  Returns NULL if the storage allocation fails.  */
482
 
483
static bfd_signed_vma *
484
hppa64_elf_local_refcounts (bfd *abfd)
485
{
486
  Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
487
  bfd_signed_vma *local_refcounts;
488
 
489
  local_refcounts = elf_local_got_refcounts (abfd);
490
  if (local_refcounts == NULL)
491
    {
492
      bfd_size_type size;
493
 
494
      /* Allocate space for local DLT, PLT and OPD reference
495
         counts.  Done this way to save polluting elf_obj_tdata
496
         with another target specific pointer.  */
497
      size = symtab_hdr->sh_info;
498
      size *= 3 * sizeof (bfd_signed_vma);
499
      local_refcounts = bfd_zalloc (abfd, size);
500
      elf_local_got_refcounts (abfd) = local_refcounts;
501
    }
502
  return local_refcounts;
503
}
504
 
505
/* Scan the RELOCS and record the type of dynamic entries that each
506
   referenced symbol needs.  */
507
 
508
static bfd_boolean
509
elf64_hppa_check_relocs (bfd *abfd,
510
                         struct bfd_link_info *info,
511
                         asection *sec,
512
                         const Elf_Internal_Rela *relocs)
513
{
514
  struct elf64_hppa_link_hash_table *hppa_info;
515
  const Elf_Internal_Rela *relend;
516
  Elf_Internal_Shdr *symtab_hdr;
517
  const Elf_Internal_Rela *rel;
518
  asection *dlt, *plt, *stubs;
519
  char *buf;
520
  size_t buf_len;
521
  unsigned int sec_symndx;
522
 
523
  if (info->relocatable)
524
    return TRUE;
525
 
526
  /* If this is the first dynamic object found in the link, create
527
     the special sections required for dynamic linking.  */
528
  if (! elf_hash_table (info)->dynamic_sections_created)
529
    {
530
      if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
531
        return FALSE;
532
    }
533
 
534
  hppa_info = hppa_link_hash_table (info);
535
  if (hppa_info == NULL)
536
    return FALSE;
537
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
538
 
539
  /* If necessary, build a new table holding section symbols indices
540
     for this BFD.  */
541
 
542
  if (info->shared && hppa_info->section_syms_bfd != abfd)
543
    {
544
      unsigned long i;
545
      unsigned int highest_shndx;
546
      Elf_Internal_Sym *local_syms = NULL;
547
      Elf_Internal_Sym *isym, *isymend;
548
      bfd_size_type amt;
549
 
550
      /* We're done with the old cache of section index to section symbol
551
         index information.  Free it.
552
 
553
         ?!? Note we leak the last section_syms array.  Presumably we
554
         could free it in one of the later routines in this file.  */
555
      if (hppa_info->section_syms)
556
        free (hppa_info->section_syms);
557
 
558
      /* Read this BFD's local symbols.  */
559
      if (symtab_hdr->sh_info != 0)
560
        {
561
          local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
562
          if (local_syms == NULL)
563
            local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
564
                                               symtab_hdr->sh_info, 0,
565
                                               NULL, NULL, NULL);
566
          if (local_syms == NULL)
567
            return FALSE;
568
        }
569
 
570
      /* Record the highest section index referenced by the local symbols.  */
571
      highest_shndx = 0;
572
      isymend = local_syms + symtab_hdr->sh_info;
573
      for (isym = local_syms; isym < isymend; isym++)
574
        {
575
          if (isym->st_shndx > highest_shndx
576
              && isym->st_shndx < SHN_LORESERVE)
577
            highest_shndx = isym->st_shndx;
578
        }
579
 
580
      /* Allocate an array to hold the section index to section symbol index
581
         mapping.  Bump by one since we start counting at zero.  */
582
      highest_shndx++;
583
      amt = highest_shndx;
584
      amt *= sizeof (int);
585
      hppa_info->section_syms = (int *) bfd_malloc (amt);
586
 
587
      /* Now walk the local symbols again.  If we find a section symbol,
588
         record the index of the symbol into the section_syms array.  */
589
      for (i = 0, isym = local_syms; isym < isymend; i++, isym++)
590
        {
591
          if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
592
            hppa_info->section_syms[isym->st_shndx] = i;
593
        }
594
 
595
      /* We are finished with the local symbols.  */
596
      if (local_syms != NULL
597
          && symtab_hdr->contents != (unsigned char *) local_syms)
598
        {
599
          if (! info->keep_memory)
600
            free (local_syms);
601
          else
602
            {
603
              /* Cache the symbols for elf_link_input_bfd.  */
604
              symtab_hdr->contents = (unsigned char *) local_syms;
605
            }
606
        }
607
 
608
      /* Record which BFD we built the section_syms mapping for.  */
609
      hppa_info->section_syms_bfd = abfd;
610
    }
611
 
612
  /* Record the symbol index for this input section.  We may need it for
613
     relocations when building shared libraries.  When not building shared
614
     libraries this value is never really used, but assign it to zero to
615
     prevent out of bounds memory accesses in other routines.  */
616
  if (info->shared)
617
    {
618
      sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec);
619
 
620
      /* If we did not find a section symbol for this section, then
621
         something went terribly wrong above.  */
622
      if (sec_symndx == SHN_BAD)
623
        return FALSE;
624
 
625
      if (sec_symndx < SHN_LORESERVE)
626
        sec_symndx = hppa_info->section_syms[sec_symndx];
627
      else
628
        sec_symndx = 0;
629
    }
630
  else
631
    sec_symndx = 0;
632
 
633
  dlt = plt = stubs = NULL;
634
  buf = NULL;
635
  buf_len = 0;
636
 
637
  relend = relocs + sec->reloc_count;
638
  for (rel = relocs; rel < relend; ++rel)
639
    {
640
      enum
641
        {
642
          NEED_DLT = 1,
643
          NEED_PLT = 2,
644
          NEED_STUB = 4,
645
          NEED_OPD = 8,
646
          NEED_DYNREL = 16,
647
        };
648
 
649
      unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
650
      struct elf64_hppa_link_hash_entry *hh;
651
      int need_entry;
652
      bfd_boolean maybe_dynamic;
653
      int dynrel_type = R_PARISC_NONE;
654
      static reloc_howto_type *howto;
655
 
656
      if (r_symndx >= symtab_hdr->sh_info)
657
        {
658
          /* We're dealing with a global symbol -- find its hash entry
659
             and mark it as being referenced.  */
660
          long indx = r_symndx - symtab_hdr->sh_info;
661
          hh = hppa_elf_hash_entry (elf_sym_hashes (abfd)[indx]);
662
          while (hh->eh.root.type == bfd_link_hash_indirect
663
                 || hh->eh.root.type == bfd_link_hash_warning)
664
            hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
665
 
666
          hh->eh.ref_regular = 1;
667
        }
668
      else
669
        hh = NULL;
670
 
671
      /* We can only get preliminary data on whether a symbol is
672
         locally or externally defined, as not all of the input files
673
         have yet been processed.  Do something with what we know, as
674
         this may help reduce memory usage and processing time later.  */
675
      maybe_dynamic = FALSE;
676
      if (hh && ((info->shared
677
                 && (!info->symbolic
678
                     || info->unresolved_syms_in_shared_libs == RM_IGNORE))
679
                || !hh->eh.def_regular
680
                || hh->eh.root.type == bfd_link_hash_defweak))
681
        maybe_dynamic = TRUE;
682
 
683
      howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info);
684
      need_entry = 0;
685
      switch (howto->type)
686
        {
687
        /* These are simple indirect references to symbols through the
688
           DLT.  We need to create a DLT entry for any symbols which
689
           appears in a DLTIND relocation.  */
690
        case R_PARISC_DLTIND21L:
691
        case R_PARISC_DLTIND14R:
692
        case R_PARISC_DLTIND14F:
693
        case R_PARISC_DLTIND14WR:
694
        case R_PARISC_DLTIND14DR:
695
          need_entry = NEED_DLT;
696
          break;
697
 
698
        /* ?!?  These need a DLT entry.  But I have no idea what to do with
699
           the "link time TP value.  */
700
        case R_PARISC_LTOFF_TP21L:
701
        case R_PARISC_LTOFF_TP14R:
702
        case R_PARISC_LTOFF_TP14F:
703
        case R_PARISC_LTOFF_TP64:
704
        case R_PARISC_LTOFF_TP14WR:
705
        case R_PARISC_LTOFF_TP14DR:
706
        case R_PARISC_LTOFF_TP16F:
707
        case R_PARISC_LTOFF_TP16WF:
708
        case R_PARISC_LTOFF_TP16DF:
709
          need_entry = NEED_DLT;
710
          break;
711
 
712
        /* These are function calls.  Depending on their precise target we
713
           may need to make a stub for them.  The stub uses the PLT, so we
714
           need to create PLT entries for these symbols too.  */
715
        case R_PARISC_PCREL12F:
716
        case R_PARISC_PCREL17F:
717
        case R_PARISC_PCREL22F:
718
        case R_PARISC_PCREL32:
719
        case R_PARISC_PCREL64:
720
        case R_PARISC_PCREL21L:
721
        case R_PARISC_PCREL17R:
722
        case R_PARISC_PCREL17C:
723
        case R_PARISC_PCREL14R:
724
        case R_PARISC_PCREL14F:
725
        case R_PARISC_PCREL22C:
726
        case R_PARISC_PCREL14WR:
727
        case R_PARISC_PCREL14DR:
728
        case R_PARISC_PCREL16F:
729
        case R_PARISC_PCREL16WF:
730
        case R_PARISC_PCREL16DF:
731
          /* Function calls might need to go through the .plt, and
732
             might need a long branch stub.  */
733
          if (hh != NULL && hh->eh.type != STT_PARISC_MILLI)
734
            need_entry = (NEED_PLT | NEED_STUB);
735
          else
736
            need_entry = 0;
737
          break;
738
 
739
        case R_PARISC_PLTOFF21L:
740
        case R_PARISC_PLTOFF14R:
741
        case R_PARISC_PLTOFF14F:
742
        case R_PARISC_PLTOFF14WR:
743
        case R_PARISC_PLTOFF14DR:
744
        case R_PARISC_PLTOFF16F:
745
        case R_PARISC_PLTOFF16WF:
746
        case R_PARISC_PLTOFF16DF:
747
          need_entry = (NEED_PLT);
748
          break;
749
 
750
        case R_PARISC_DIR64:
751
          if (info->shared || maybe_dynamic)
752
            need_entry = (NEED_DYNREL);
753
          dynrel_type = R_PARISC_DIR64;
754
          break;
755
 
756
        /* This is an indirect reference through the DLT to get the address
757
           of a OPD descriptor.  Thus we need to make a DLT entry that points
758
           to an OPD entry.  */
759
        case R_PARISC_LTOFF_FPTR21L:
760
        case R_PARISC_LTOFF_FPTR14R:
761
        case R_PARISC_LTOFF_FPTR14WR:
762
        case R_PARISC_LTOFF_FPTR14DR:
763
        case R_PARISC_LTOFF_FPTR32:
764
        case R_PARISC_LTOFF_FPTR64:
765
        case R_PARISC_LTOFF_FPTR16F:
766
        case R_PARISC_LTOFF_FPTR16WF:
767
        case R_PARISC_LTOFF_FPTR16DF:
768
          if (info->shared || maybe_dynamic)
769
            need_entry = (NEED_DLT | NEED_OPD | NEED_PLT);
770
          else
771
            need_entry = (NEED_DLT | NEED_OPD | NEED_PLT);
772
          dynrel_type = R_PARISC_FPTR64;
773
          break;
774
 
775
        /* This is a simple OPD entry.  */
776
        case R_PARISC_FPTR64:
777
          if (info->shared || maybe_dynamic)
778
            need_entry = (NEED_OPD | NEED_PLT | NEED_DYNREL);
779
          else
780
            need_entry = (NEED_OPD | NEED_PLT);
781
          dynrel_type = R_PARISC_FPTR64;
782
          break;
783
 
784
        /* Add more cases as needed.  */
785
        }
786
 
787
      if (!need_entry)
788
        continue;
789
 
790
      if (hh)
791
        {
792
          /* Stash away enough information to be able to find this symbol
793
             regardless of whether or not it is local or global.  */
794
          hh->owner = abfd;
795
          hh->sym_indx = r_symndx;
796
        }
797
 
798
      /* Create what's needed.  */
799
      if (need_entry & NEED_DLT)
800
        {
801
          /* Allocate space for a DLT entry, as well as a dynamic
802
             relocation for this entry.  */
803
          if (! hppa_info->dlt_sec
804
              && ! get_dlt (abfd, info, hppa_info))
805
            goto err_out;
806
 
807
          if (hh != NULL)
808
            {
809
              hh->want_dlt = 1;
810
              hh->eh.got.refcount += 1;
811
            }
812
          else
813
            {
814
              bfd_signed_vma *local_dlt_refcounts;
815
 
816
              /* This is a DLT entry for a local symbol.  */
817
              local_dlt_refcounts = hppa64_elf_local_refcounts (abfd);
818
              if (local_dlt_refcounts == NULL)
819
                return FALSE;
820
              local_dlt_refcounts[r_symndx] += 1;
821
            }
822
        }
823
 
824
      if (need_entry & NEED_PLT)
825
        {
826
          if (! hppa_info->plt_sec
827
              && ! get_plt (abfd, info, hppa_info))
828
            goto err_out;
829
 
830
          if (hh != NULL)
831
            {
832
              hh->want_plt = 1;
833
              hh->eh.needs_plt = 1;
834
              hh->eh.plt.refcount += 1;
835
            }
836
          else
837
            {
838
              bfd_signed_vma *local_dlt_refcounts;
839
              bfd_signed_vma *local_plt_refcounts;
840
 
841
              /* This is a PLT entry for a local symbol.  */
842
              local_dlt_refcounts = hppa64_elf_local_refcounts (abfd);
843
              if (local_dlt_refcounts == NULL)
844
                return FALSE;
845
              local_plt_refcounts = local_dlt_refcounts + symtab_hdr->sh_info;
846
              local_plt_refcounts[r_symndx] += 1;
847
            }
848
        }
849
 
850
      if (need_entry & NEED_STUB)
851
        {
852
          if (! hppa_info->stub_sec
853
              && ! get_stub (abfd, info, hppa_info))
854
            goto err_out;
855
          if (hh)
856
            hh->want_stub = 1;
857
        }
858
 
859
      if (need_entry & NEED_OPD)
860
        {
861
          if (! hppa_info->opd_sec
862
              && ! get_opd (abfd, info, hppa_info))
863
            goto err_out;
864
 
865
          /* FPTRs are not allocated by the dynamic linker for PA64,
866
             though it is possible that will change in the future.  */
867
 
868
          if (hh != NULL)
869
            hh->want_opd = 1;
870
          else
871
            {
872
              bfd_signed_vma *local_dlt_refcounts;
873
              bfd_signed_vma *local_opd_refcounts;
874
 
875
              /* This is a OPD for a local symbol.  */
876
              local_dlt_refcounts = hppa64_elf_local_refcounts (abfd);
877
              if (local_dlt_refcounts == NULL)
878
                return FALSE;
879
              local_opd_refcounts = (local_dlt_refcounts
880
                                     + 2 * symtab_hdr->sh_info);
881
              local_opd_refcounts[r_symndx] += 1;
882
            }
883
        }
884
 
885
      /* Add a new dynamic relocation to the chain of dynamic
886
         relocations for this symbol.  */
887
      if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC))
888
        {
889
          if (! hppa_info->other_rel_sec
890
              && ! get_reloc_section (abfd, hppa_info, sec))
891
            goto err_out;
892
 
893
          /* Count dynamic relocations against global symbols.  */
894
          if (hh != NULL
895
              && !count_dyn_reloc (abfd, hh, dynrel_type, sec,
896
                                   sec_symndx, rel->r_offset, rel->r_addend))
897
            goto err_out;
898
 
899
          /* If we are building a shared library and we just recorded
900
             a dynamic R_PARISC_FPTR64 relocation, then make sure the
901
             section symbol for this section ends up in the dynamic
902
             symbol table.  */
903
          if (info->shared && dynrel_type == R_PARISC_FPTR64
904
              && ! (bfd_elf_link_record_local_dynamic_symbol
905
                    (info, abfd, sec_symndx)))
906
            return FALSE;
907
        }
908
    }
909
 
910
  if (buf)
911
    free (buf);
912
  return TRUE;
913
 
914
 err_out:
915
  if (buf)
916
    free (buf);
917
  return FALSE;
918
}
919
 
920
struct elf64_hppa_allocate_data
921
{
922
  struct bfd_link_info *info;
923
  bfd_size_type ofs;
924
};
925
 
926
/* Should we do dynamic things to this symbol?  */
927
 
928
static bfd_boolean
929
elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry *eh,
930
                             struct bfd_link_info *info)
931
{
932
  /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols
933
     and relocations that retrieve a function descriptor?  Assume the
934
     worst for now.  */
935
  if (_bfd_elf_dynamic_symbol_p (eh, info, 1))
936
    {
937
      /* ??? Why is this here and not elsewhere is_local_label_name.  */
938
      if (eh->root.root.string[0] == '$' && eh->root.root.string[1] == '$')
939
        return FALSE;
940
 
941
      return TRUE;
942
    }
943
  else
944
    return FALSE;
945
}
946
 
947
/* Mark all functions exported by this file so that we can later allocate
948
   entries in .opd for them.  */
949
 
950
static bfd_boolean
951
elf64_hppa_mark_exported_functions (struct elf_link_hash_entry *eh, void *data)
952
{
953
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
954
  struct bfd_link_info *info = (struct bfd_link_info *)data;
955
  struct elf64_hppa_link_hash_table *hppa_info;
956
 
957
  hppa_info = hppa_link_hash_table (info);
958
  if (hppa_info == NULL)
959
    return FALSE;
960
 
961
  if (eh->root.type == bfd_link_hash_warning)
962
    eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
963
 
964
  if (eh
965
      && (eh->root.type == bfd_link_hash_defined
966
          || eh->root.type == bfd_link_hash_defweak)
967
      && eh->root.u.def.section->output_section != NULL
968
      && eh->type == STT_FUNC)
969
    {
970
      if (! hppa_info->opd_sec
971
          && ! get_opd (hppa_info->root.dynobj, info, hppa_info))
972
        return FALSE;
973
 
974
      hh->want_opd = 1;
975
 
976
      /* Put a flag here for output_symbol_hook.  */
977
      hh->st_shndx = -1;
978
      eh->needs_plt = 1;
979
    }
980
 
981
  return TRUE;
982
}
983
 
984
/* Allocate space for a DLT entry.  */
985
 
986
static bfd_boolean
987
allocate_global_data_dlt (struct elf_link_hash_entry *eh, void *data)
988
{
989
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
990
  struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
991
 
992
  if (hh->want_dlt)
993
    {
994
      if (x->info->shared)
995
        {
996
          /* Possibly add the symbol to the local dynamic symbol
997
             table since we might need to create a dynamic relocation
998
             against it.  */
999
          if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI)
1000
            {
1001
              bfd *owner = eh->root.u.def.section->owner;
1002
 
1003
              if (! (bfd_elf_link_record_local_dynamic_symbol
1004
                     (x->info, owner, hh->sym_indx)))
1005
                return FALSE;
1006
            }
1007
        }
1008
 
1009
      hh->dlt_offset = x->ofs;
1010
      x->ofs += DLT_ENTRY_SIZE;
1011
    }
1012
  return TRUE;
1013
}
1014
 
1015
/* Allocate space for a DLT.PLT entry.  */
1016
 
1017
static bfd_boolean
1018
allocate_global_data_plt (struct elf_link_hash_entry *eh, void *data)
1019
{
1020
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1021
  struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *) data;
1022
 
1023
  if (hh->want_plt
1024
      && elf64_hppa_dynamic_symbol_p (eh, x->info)
1025
      && !((eh->root.type == bfd_link_hash_defined
1026
            || eh->root.type == bfd_link_hash_defweak)
1027
           && eh->root.u.def.section->output_section != NULL))
1028
    {
1029
      hh->plt_offset = x->ofs;
1030
      x->ofs += PLT_ENTRY_SIZE;
1031
      if (hh->plt_offset < 0x2000)
1032
        {
1033
          struct elf64_hppa_link_hash_table *hppa_info;
1034
 
1035
          hppa_info = hppa_link_hash_table (x->info);
1036
          if (hppa_info == NULL)
1037
            return FALSE;
1038
 
1039
          hppa_info->gp_offset = hh->plt_offset;
1040
        }
1041
    }
1042
  else
1043
    hh->want_plt = 0;
1044
 
1045
  return TRUE;
1046
}
1047
 
1048
/* Allocate space for a STUB entry.  */
1049
 
1050
static bfd_boolean
1051
allocate_global_data_stub (struct elf_link_hash_entry *eh, void *data)
1052
{
1053
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1054
  struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1055
 
1056
  if (hh->want_stub
1057
      && elf64_hppa_dynamic_symbol_p (eh, x->info)
1058
      && !((eh->root.type == bfd_link_hash_defined
1059
            || eh->root.type == bfd_link_hash_defweak)
1060
           && eh->root.u.def.section->output_section != NULL))
1061
    {
1062
      hh->stub_offset = x->ofs;
1063
      x->ofs += sizeof (plt_stub);
1064
    }
1065
  else
1066
    hh->want_stub = 0;
1067
  return TRUE;
1068
}
1069
 
1070
/* Allocate space for a FPTR entry.  */
1071
 
1072
static bfd_boolean
1073
allocate_global_data_opd (struct elf_link_hash_entry *eh, void *data)
1074
{
1075
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1076
  struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1077
 
1078
  if (hh && hh->want_opd)
1079
    {
1080
      while (hh->eh.root.type == bfd_link_hash_indirect
1081
             || hh->eh.root.type == bfd_link_hash_warning)
1082
        hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
1083
 
1084
      /* We never need an opd entry for a symbol which is not
1085
         defined by this output file.  */
1086
      if (hh && (hh->eh.root.type == bfd_link_hash_undefined
1087
                 || hh->eh.root.type == bfd_link_hash_undefweak
1088
                 || hh->eh.root.u.def.section->output_section == NULL))
1089
        hh->want_opd = 0;
1090
 
1091
      /* If we are creating a shared library, took the address of a local
1092
         function or might export this function from this object file, then
1093
         we have to create an opd descriptor.  */
1094
      else if (x->info->shared
1095
               || hh == NULL
1096
               || (hh->eh.dynindx == -1 && hh->eh.type != STT_PARISC_MILLI)
1097
               || (hh->eh.root.type == bfd_link_hash_defined
1098
                   || hh->eh.root.type == bfd_link_hash_defweak))
1099
        {
1100
          /* If we are creating a shared library, then we will have to
1101
             create a runtime relocation for the symbol to properly
1102
             initialize the .opd entry.  Make sure the symbol gets
1103
             added to the dynamic symbol table.  */
1104
          if (x->info->shared
1105
              && (hh == NULL || (hh->eh.dynindx == -1)))
1106
            {
1107
              bfd *owner;
1108
              /* PR 6511: Default to using the dynamic symbol table.  */
1109
              owner = (hh->owner ? hh->owner: eh->root.u.def.section->owner);
1110
 
1111
              if (!bfd_elf_link_record_local_dynamic_symbol
1112
                    (x->info, owner, hh->sym_indx))
1113
                return FALSE;
1114
            }
1115
 
1116
          /* This may not be necessary or desirable anymore now that
1117
             we have some support for dealing with section symbols
1118
             in dynamic relocs.  But name munging does make the result
1119
             much easier to debug.  ie, the EPLT reloc will reference
1120
             a symbol like .foobar, instead of .text + offset.  */
1121
          if (x->info->shared && eh)
1122
            {
1123
              char *new_name;
1124
              struct elf_link_hash_entry *nh;
1125
 
1126
              new_name = alloca (strlen (eh->root.root.string) + 2);
1127
              new_name[0] = '.';
1128
              strcpy (new_name + 1, eh->root.root.string);
1129
 
1130
              nh = elf_link_hash_lookup (elf_hash_table (x->info),
1131
                                         new_name, TRUE, TRUE, TRUE);
1132
 
1133
              nh->root.type = eh->root.type;
1134
              nh->root.u.def.value = eh->root.u.def.value;
1135
              nh->root.u.def.section = eh->root.u.def.section;
1136
 
1137
              if (! bfd_elf_link_record_dynamic_symbol (x->info, nh))
1138
                return FALSE;
1139
 
1140
             }
1141
          hh->opd_offset = x->ofs;
1142
          x->ofs += OPD_ENTRY_SIZE;
1143
        }
1144
 
1145
      /* Otherwise we do not need an opd entry.  */
1146
      else
1147
        hh->want_opd = 0;
1148
    }
1149
  return TRUE;
1150
}
1151
 
1152
/* HP requires the EI_OSABI field to be filled in.  The assignment to
1153
   EI_ABIVERSION may not be strictly necessary.  */
1154
 
1155
static void
1156
elf64_hppa_post_process_headers (bfd *abfd,
1157
                         struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
1158
{
1159
  Elf_Internal_Ehdr * i_ehdrp;
1160
 
1161
  i_ehdrp = elf_elfheader (abfd);
1162
 
1163
  i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
1164
  i_ehdrp->e_ident[EI_ABIVERSION] = 1;
1165
}
1166
 
1167
/* Create function descriptor section (.opd).  This section is called .opd
1168
   because it contains "official procedure descriptors".  The "official"
1169
   refers to the fact that these descriptors are used when taking the address
1170
   of a procedure, thus ensuring a unique address for each procedure.  */
1171
 
1172
static bfd_boolean
1173
get_opd (bfd *abfd,
1174
         struct bfd_link_info *info ATTRIBUTE_UNUSED,
1175
         struct elf64_hppa_link_hash_table *hppa_info)
1176
{
1177
  asection *opd;
1178
  bfd *dynobj;
1179
 
1180
  opd = hppa_info->opd_sec;
1181
  if (!opd)
1182
    {
1183
      dynobj = hppa_info->root.dynobj;
1184
      if (!dynobj)
1185
        hppa_info->root.dynobj = dynobj = abfd;
1186
 
1187
      opd = bfd_make_section_with_flags (dynobj, ".opd",
1188
                                         (SEC_ALLOC
1189
                                          | SEC_LOAD
1190
                                          | SEC_HAS_CONTENTS
1191
                                          | SEC_IN_MEMORY
1192
                                          | SEC_LINKER_CREATED));
1193
      if (!opd
1194
          || !bfd_set_section_alignment (abfd, opd, 3))
1195
        {
1196
          BFD_ASSERT (0);
1197
          return FALSE;
1198
        }
1199
 
1200
      hppa_info->opd_sec = opd;
1201
    }
1202
 
1203
  return TRUE;
1204
}
1205
 
1206
/* Create the PLT section.  */
1207
 
1208
static bfd_boolean
1209
get_plt (bfd *abfd,
1210
         struct bfd_link_info *info ATTRIBUTE_UNUSED,
1211
         struct elf64_hppa_link_hash_table *hppa_info)
1212
{
1213
  asection *plt;
1214
  bfd *dynobj;
1215
 
1216
  plt = hppa_info->plt_sec;
1217
  if (!plt)
1218
    {
1219
      dynobj = hppa_info->root.dynobj;
1220
      if (!dynobj)
1221
        hppa_info->root.dynobj = dynobj = abfd;
1222
 
1223
      plt = bfd_make_section_with_flags (dynobj, ".plt",
1224
                                         (SEC_ALLOC
1225
                                          | SEC_LOAD
1226
                                          | SEC_HAS_CONTENTS
1227
                                          | SEC_IN_MEMORY
1228
                                          | SEC_LINKER_CREATED));
1229
      if (!plt
1230
          || !bfd_set_section_alignment (abfd, plt, 3))
1231
        {
1232
          BFD_ASSERT (0);
1233
          return FALSE;
1234
        }
1235
 
1236
      hppa_info->plt_sec = plt;
1237
    }
1238
 
1239
  return TRUE;
1240
}
1241
 
1242
/* Create the DLT section.  */
1243
 
1244
static bfd_boolean
1245
get_dlt (bfd *abfd,
1246
         struct bfd_link_info *info ATTRIBUTE_UNUSED,
1247
         struct elf64_hppa_link_hash_table *hppa_info)
1248
{
1249
  asection *dlt;
1250
  bfd *dynobj;
1251
 
1252
  dlt = hppa_info->dlt_sec;
1253
  if (!dlt)
1254
    {
1255
      dynobj = hppa_info->root.dynobj;
1256
      if (!dynobj)
1257
        hppa_info->root.dynobj = dynobj = abfd;
1258
 
1259
      dlt = bfd_make_section_with_flags (dynobj, ".dlt",
1260
                                         (SEC_ALLOC
1261
                                          | SEC_LOAD
1262
                                          | SEC_HAS_CONTENTS
1263
                                          | SEC_IN_MEMORY
1264
                                          | SEC_LINKER_CREATED));
1265
      if (!dlt
1266
          || !bfd_set_section_alignment (abfd, dlt, 3))
1267
        {
1268
          BFD_ASSERT (0);
1269
          return FALSE;
1270
        }
1271
 
1272
      hppa_info->dlt_sec = dlt;
1273
    }
1274
 
1275
  return TRUE;
1276
}
1277
 
1278
/* Create the stubs section.  */
1279
 
1280
static bfd_boolean
1281
get_stub (bfd *abfd,
1282
          struct bfd_link_info *info ATTRIBUTE_UNUSED,
1283
          struct elf64_hppa_link_hash_table *hppa_info)
1284
{
1285
  asection *stub;
1286
  bfd *dynobj;
1287
 
1288
  stub = hppa_info->stub_sec;
1289
  if (!stub)
1290
    {
1291
      dynobj = hppa_info->root.dynobj;
1292
      if (!dynobj)
1293
        hppa_info->root.dynobj = dynobj = abfd;
1294
 
1295
      stub = bfd_make_section_with_flags (dynobj, ".stub",
1296
                                          (SEC_ALLOC | SEC_LOAD
1297
                                           | SEC_HAS_CONTENTS
1298
                                           | SEC_IN_MEMORY
1299
                                           | SEC_READONLY
1300
                                           | SEC_LINKER_CREATED));
1301
      if (!stub
1302
          || !bfd_set_section_alignment (abfd, stub, 3))
1303
        {
1304
          BFD_ASSERT (0);
1305
          return FALSE;
1306
        }
1307
 
1308
      hppa_info->stub_sec = stub;
1309
    }
1310
 
1311
  return TRUE;
1312
}
1313
 
1314
/* Create sections necessary for dynamic linking.  This is only a rough
1315
   cut and will likely change as we learn more about the somewhat
1316
   unusual dynamic linking scheme HP uses.
1317
 
1318
   .stub:
1319
        Contains code to implement cross-space calls.  The first time one
1320
        of the stubs is used it will call into the dynamic linker, later
1321
        calls will go straight to the target.
1322
 
1323
        The only stub we support right now looks like
1324
 
1325
        ldd OFFSET(%dp),%r1
1326
        bve %r0(%r1)
1327
        ldd OFFSET+8(%dp),%dp
1328
 
1329
        Other stubs may be needed in the future.  We may want the remove
1330
        the break/nop instruction.  It is only used right now to keep the
1331
        offset of a .plt entry and a .stub entry in sync.
1332
 
1333
   .dlt:
1334
        This is what most people call the .got.  HP used a different name.
1335
        Losers.
1336
 
1337
   .rela.dlt:
1338
        Relocations for the DLT.
1339
 
1340
   .plt:
1341
        Function pointers as address,gp pairs.
1342
 
1343
   .rela.plt:
1344
        Should contain dynamic IPLT (and EPLT?) relocations.
1345
 
1346
   .opd:
1347
        FPTRS
1348
 
1349
   .rela.opd:
1350
        EPLT relocations for symbols exported from shared libraries.  */
1351
 
1352
static bfd_boolean
1353
elf64_hppa_create_dynamic_sections (bfd *abfd,
1354
                                    struct bfd_link_info *info)
1355
{
1356
  asection *s;
1357
  struct elf64_hppa_link_hash_table *hppa_info;
1358
 
1359
  hppa_info = hppa_link_hash_table (info);
1360
  if (hppa_info == NULL)
1361
    return FALSE;
1362
 
1363
  if (! get_stub (abfd, info, hppa_info))
1364
    return FALSE;
1365
 
1366
  if (! get_dlt (abfd, info, hppa_info))
1367
    return FALSE;
1368
 
1369
  if (! get_plt (abfd, info, hppa_info))
1370
    return FALSE;
1371
 
1372
  if (! get_opd (abfd, info, hppa_info))
1373
    return FALSE;
1374
 
1375
  s = bfd_make_section_with_flags (abfd, ".rela.dlt",
1376
                                   (SEC_ALLOC | SEC_LOAD
1377
                                    | SEC_HAS_CONTENTS
1378
                                    | SEC_IN_MEMORY
1379
                                    | SEC_READONLY
1380
                                    | SEC_LINKER_CREATED));
1381
  if (s == NULL
1382
      || !bfd_set_section_alignment (abfd, s, 3))
1383
    return FALSE;
1384
  hppa_info->dlt_rel_sec = s;
1385
 
1386
  s = bfd_make_section_with_flags (abfd, ".rela.plt",
1387
                                   (SEC_ALLOC | SEC_LOAD
1388
                                    | SEC_HAS_CONTENTS
1389
                                    | SEC_IN_MEMORY
1390
                                    | SEC_READONLY
1391
                                    | SEC_LINKER_CREATED));
1392
  if (s == NULL
1393
      || !bfd_set_section_alignment (abfd, s, 3))
1394
    return FALSE;
1395
  hppa_info->plt_rel_sec = s;
1396
 
1397
  s = bfd_make_section_with_flags (abfd, ".rela.data",
1398
                                   (SEC_ALLOC | SEC_LOAD
1399
                                    | SEC_HAS_CONTENTS
1400
                                    | SEC_IN_MEMORY
1401
                                    | SEC_READONLY
1402
                                    | SEC_LINKER_CREATED));
1403
  if (s == NULL
1404
      || !bfd_set_section_alignment (abfd, s, 3))
1405
    return FALSE;
1406
  hppa_info->other_rel_sec = s;
1407
 
1408
  s = bfd_make_section_with_flags (abfd, ".rela.opd",
1409
                                   (SEC_ALLOC | SEC_LOAD
1410
                                    | SEC_HAS_CONTENTS
1411
                                    | SEC_IN_MEMORY
1412
                                    | SEC_READONLY
1413
                                    | SEC_LINKER_CREATED));
1414
  if (s == NULL
1415
      || !bfd_set_section_alignment (abfd, s, 3))
1416
    return FALSE;
1417
  hppa_info->opd_rel_sec = s;
1418
 
1419
  return TRUE;
1420
}
1421
 
1422
/* Allocate dynamic relocations for those symbols that turned out
1423
   to be dynamic.  */
1424
 
1425
static bfd_boolean
1426
allocate_dynrel_entries (struct elf_link_hash_entry *eh, void *data)
1427
{
1428
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1429
  struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data;
1430
  struct elf64_hppa_link_hash_table *hppa_info;
1431
  struct elf64_hppa_dyn_reloc_entry *rent;
1432
  bfd_boolean dynamic_symbol, shared;
1433
 
1434
  hppa_info = hppa_link_hash_table (x->info);
1435
  if (hppa_info == NULL)
1436
    return FALSE;
1437
 
1438
  dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, x->info);
1439
  shared = x->info->shared;
1440
 
1441
  /* We may need to allocate relocations for a non-dynamic symbol
1442
     when creating a shared library.  */
1443
  if (!dynamic_symbol && !shared)
1444
    return TRUE;
1445
 
1446
  /* Take care of the normal data relocations.  */
1447
 
1448
  for (rent = hh->reloc_entries; rent; rent = rent->next)
1449
    {
1450
      /* Allocate one iff we are building a shared library, the relocation
1451
         isn't a R_PARISC_FPTR64, or we don't want an opd entry.  */
1452
      if (!shared && rent->type == R_PARISC_FPTR64 && hh->want_opd)
1453
        continue;
1454
 
1455
      hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela);
1456
 
1457
      /* Make sure this symbol gets into the dynamic symbol table if it is
1458
         not already recorded.  ?!? This should not be in the loop since
1459
         the symbol need only be added once.  */
1460
      if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI)
1461
        if (!bfd_elf_link_record_local_dynamic_symbol
1462
            (x->info, rent->sec->owner, hh->sym_indx))
1463
          return FALSE;
1464
    }
1465
 
1466
  /* Take care of the GOT and PLT relocations.  */
1467
 
1468
  if ((dynamic_symbol || shared) && hh->want_dlt)
1469
    hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela);
1470
 
1471
  /* If we are building a shared library, then every symbol that has an
1472
     opd entry will need an EPLT relocation to relocate the symbol's address
1473
     and __gp value based on the runtime load address.  */
1474
  if (shared && hh->want_opd)
1475
    hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela);
1476
 
1477
  if (hh->want_plt && dynamic_symbol)
1478
    {
1479
      bfd_size_type t = 0;
1480
 
1481
      /* Dynamic symbols get one IPLT relocation.  Local symbols in
1482
         shared libraries get two REL relocations.  Local symbols in
1483
         main applications get nothing.  */
1484
      if (dynamic_symbol)
1485
        t = sizeof (Elf64_External_Rela);
1486
      else if (shared)
1487
        t = 2 * sizeof (Elf64_External_Rela);
1488
 
1489
      hppa_info->plt_rel_sec->size += t;
1490
    }
1491
 
1492
  return TRUE;
1493
}
1494
 
1495
/* Adjust a symbol defined by a dynamic object and referenced by a
1496
   regular object.  */
1497
 
1498
static bfd_boolean
1499
elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1500
                                  struct elf_link_hash_entry *eh)
1501
{
1502
  /* ??? Undefined symbols with PLT entries should be re-defined
1503
     to be the PLT entry.  */
1504
 
1505
  /* If this is a weak symbol, and there is a real definition, the
1506
     processor independent code will have arranged for us to see the
1507
     real definition first, and we can just use the same value.  */
1508
  if (eh->u.weakdef != NULL)
1509
    {
1510
      BFD_ASSERT (eh->u.weakdef->root.type == bfd_link_hash_defined
1511
                  || eh->u.weakdef->root.type == bfd_link_hash_defweak);
1512
      eh->root.u.def.section = eh->u.weakdef->root.u.def.section;
1513
      eh->root.u.def.value = eh->u.weakdef->root.u.def.value;
1514
      return TRUE;
1515
    }
1516
 
1517
  /* If this is a reference to a symbol defined by a dynamic object which
1518
     is not a function, we might allocate the symbol in our .dynbss section
1519
     and allocate a COPY dynamic relocation.
1520
 
1521
     But PA64 code is canonically PIC, so as a rule we can avoid this sort
1522
     of hackery.  */
1523
 
1524
  return TRUE;
1525
}
1526
 
1527
/* This function is called via elf_link_hash_traverse to mark millicode
1528
   symbols with a dynindx of -1 and to remove the string table reference
1529
   from the dynamic symbol table.  If the symbol is not a millicode symbol,
1530
   elf64_hppa_mark_exported_functions is called.  */
1531
 
1532
static bfd_boolean
1533
elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry *eh,
1534
                                              void *data)
1535
{
1536
  struct elf_link_hash_entry *elf = eh;
1537
  struct bfd_link_info *info = (struct bfd_link_info *)data;
1538
 
1539
  if (elf->root.type == bfd_link_hash_warning)
1540
    elf = (struct elf_link_hash_entry *) elf->root.u.i.link;
1541
 
1542
  if (elf->type == STT_PARISC_MILLI)
1543
    {
1544
      if (elf->dynindx != -1)
1545
        {
1546
          elf->dynindx = -1;
1547
          _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1548
                                  elf->dynstr_index);
1549
        }
1550
      return TRUE;
1551
    }
1552
 
1553
  return elf64_hppa_mark_exported_functions (eh, data);
1554
}
1555
 
1556
/* Set the final sizes of the dynamic sections and allocate memory for
1557
   the contents of our special sections.  */
1558
 
1559
static bfd_boolean
1560
elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
1561
{
1562
  struct elf64_hppa_link_hash_table *hppa_info;
1563
  struct elf64_hppa_allocate_data data;
1564
  bfd *dynobj;
1565
  bfd *ibfd;
1566
  asection *sec;
1567
  bfd_boolean plt;
1568
  bfd_boolean relocs;
1569
  bfd_boolean reltext;
1570
 
1571
  hppa_info = hppa_link_hash_table (info);
1572
  if (hppa_info == NULL)
1573
    return FALSE;
1574
 
1575
  dynobj = elf_hash_table (info)->dynobj;
1576
  BFD_ASSERT (dynobj != NULL);
1577
 
1578
  /* Mark each function this program exports so that we will allocate
1579
     space in the .opd section for each function's FPTR.  If we are
1580
     creating dynamic sections, change the dynamic index of millicode
1581
     symbols to -1 and remove them from the string table for .dynstr.
1582
 
1583
     We have to traverse the main linker hash table since we have to
1584
     find functions which may not have been mentioned in any relocs.  */
1585
  elf_link_hash_traverse (elf_hash_table (info),
1586
                          (elf_hash_table (info)->dynamic_sections_created
1587
                           ? elf64_hppa_mark_milli_and_exported_functions
1588
                           : elf64_hppa_mark_exported_functions),
1589
                          info);
1590
 
1591
  if (elf_hash_table (info)->dynamic_sections_created)
1592
    {
1593
      /* Set the contents of the .interp section to the interpreter.  */
1594
      if (info->executable)
1595
        {
1596
          sec = bfd_get_section_by_name (dynobj, ".interp");
1597
          BFD_ASSERT (sec != NULL);
1598
          sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
1599
          sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1600
        }
1601
    }
1602
  else
1603
    {
1604
      /* We may have created entries in the .rela.got section.
1605
         However, if we are not creating the dynamic sections, we will
1606
         not actually use these entries.  Reset the size of .rela.dlt,
1607
         which will cause it to get stripped from the output file
1608
         below.  */
1609
      sec = bfd_get_section_by_name (dynobj, ".rela.dlt");
1610
      if (sec != NULL)
1611
        sec->size = 0;
1612
    }
1613
 
1614
  /* Set up DLT, PLT and OPD offsets for local syms, and space for local
1615
     dynamic relocs.  */
1616
  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
1617
    {
1618
      bfd_signed_vma *local_dlt;
1619
      bfd_signed_vma *end_local_dlt;
1620
      bfd_signed_vma *local_plt;
1621
      bfd_signed_vma *end_local_plt;
1622
      bfd_signed_vma *local_opd;
1623
      bfd_signed_vma *end_local_opd;
1624
      bfd_size_type locsymcount;
1625
      Elf_Internal_Shdr *symtab_hdr;
1626
      asection *srel;
1627
 
1628
      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
1629
        continue;
1630
 
1631
      for (sec = ibfd->sections; sec != NULL; sec = sec->next)
1632
        {
1633
          struct elf64_hppa_dyn_reloc_entry *hdh_p;
1634
 
1635
          for (hdh_p = ((struct elf64_hppa_dyn_reloc_entry *)
1636
                    elf_section_data (sec)->local_dynrel);
1637
               hdh_p != NULL;
1638
               hdh_p = hdh_p->next)
1639
            {
1640
              if (!bfd_is_abs_section (hdh_p->sec)
1641
                  && bfd_is_abs_section (hdh_p->sec->output_section))
1642
                {
1643
                  /* Input section has been discarded, either because
1644
                     it is a copy of a linkonce section or due to
1645
                     linker script /DISCARD/, so we'll be discarding
1646
                     the relocs too.  */
1647
                }
1648
              else if (hdh_p->count != 0)
1649
                {
1650
                  srel = elf_section_data (hdh_p->sec)->sreloc;
1651
                  srel->size += hdh_p->count * sizeof (Elf64_External_Rela);
1652
                  if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0)
1653
                    info->flags |= DF_TEXTREL;
1654
                }
1655
            }
1656
        }
1657
 
1658
      local_dlt = elf_local_got_refcounts (ibfd);
1659
      if (!local_dlt)
1660
        continue;
1661
 
1662
      symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
1663
      locsymcount = symtab_hdr->sh_info;
1664
      end_local_dlt = local_dlt + locsymcount;
1665
      sec = hppa_info->dlt_sec;
1666
      srel = hppa_info->dlt_rel_sec;
1667
      for (; local_dlt < end_local_dlt; ++local_dlt)
1668
        {
1669
          if (*local_dlt > 0)
1670
            {
1671
              *local_dlt = sec->size;
1672
              sec->size += DLT_ENTRY_SIZE;
1673
              if (info->shared)
1674
                {
1675
                  srel->size += sizeof (Elf64_External_Rela);
1676
                }
1677
            }
1678
          else
1679
            *local_dlt = (bfd_vma) -1;
1680
        }
1681
 
1682
      local_plt = end_local_dlt;
1683
      end_local_plt = local_plt + locsymcount;
1684
      if (! hppa_info->root.dynamic_sections_created)
1685
        {
1686
          /* Won't be used, but be safe.  */
1687
          for (; local_plt < end_local_plt; ++local_plt)
1688
            *local_plt = (bfd_vma) -1;
1689
        }
1690
      else
1691
        {
1692
          sec = hppa_info->plt_sec;
1693
          srel = hppa_info->plt_rel_sec;
1694
          for (; local_plt < end_local_plt; ++local_plt)
1695
            {
1696
              if (*local_plt > 0)
1697
                {
1698
                  *local_plt = sec->size;
1699
                  sec->size += PLT_ENTRY_SIZE;
1700
                  if (info->shared)
1701
                    srel->size += sizeof (Elf64_External_Rela);
1702
                }
1703
              else
1704
                *local_plt = (bfd_vma) -1;
1705
            }
1706
        }
1707
 
1708
      local_opd = end_local_plt;
1709
      end_local_opd = local_opd + locsymcount;
1710
      if (! hppa_info->root.dynamic_sections_created)
1711
        {
1712
          /* Won't be used, but be safe.  */
1713
          for (; local_opd < end_local_opd; ++local_opd)
1714
            *local_opd = (bfd_vma) -1;
1715
        }
1716
      else
1717
        {
1718
          sec = hppa_info->opd_sec;
1719
          srel = hppa_info->opd_rel_sec;
1720
          for (; local_opd < end_local_opd; ++local_opd)
1721
            {
1722
              if (*local_opd > 0)
1723
                {
1724
                  *local_opd = sec->size;
1725
                  sec->size += OPD_ENTRY_SIZE;
1726
                  if (info->shared)
1727
                    srel->size += sizeof (Elf64_External_Rela);
1728
                }
1729
              else
1730
                *local_opd = (bfd_vma) -1;
1731
            }
1732
        }
1733
    }
1734
 
1735
  /* Allocate the GOT entries.  */
1736
 
1737
  data.info = info;
1738
  if (hppa_info->dlt_sec)
1739
    {
1740
      data.ofs = hppa_info->dlt_sec->size;
1741
      elf_link_hash_traverse (elf_hash_table (info),
1742
                              allocate_global_data_dlt, &data);
1743
      hppa_info->dlt_sec->size = data.ofs;
1744
    }
1745
 
1746
  if (hppa_info->plt_sec)
1747
    {
1748
      data.ofs = hppa_info->plt_sec->size;
1749
      elf_link_hash_traverse (elf_hash_table (info),
1750
                              allocate_global_data_plt, &data);
1751
      hppa_info->plt_sec->size = data.ofs;
1752
    }
1753
 
1754
  if (hppa_info->stub_sec)
1755
    {
1756
      data.ofs = 0x0;
1757
      elf_link_hash_traverse (elf_hash_table (info),
1758
                              allocate_global_data_stub, &data);
1759
      hppa_info->stub_sec->size = data.ofs;
1760
    }
1761
 
1762
  /* Allocate space for entries in the .opd section.  */
1763
  if (hppa_info->opd_sec)
1764
    {
1765
      data.ofs = hppa_info->opd_sec->size;
1766
      elf_link_hash_traverse (elf_hash_table (info),
1767
                              allocate_global_data_opd, &data);
1768
      hppa_info->opd_sec->size = data.ofs;
1769
    }
1770
 
1771
  /* Now allocate space for dynamic relocations, if necessary.  */
1772
  if (hppa_info->root.dynamic_sections_created)
1773
    elf_link_hash_traverse (elf_hash_table (info),
1774
                            allocate_dynrel_entries, &data);
1775
 
1776
  /* The sizes of all the sections are set.  Allocate memory for them.  */
1777
  plt = FALSE;
1778
  relocs = FALSE;
1779
  reltext = FALSE;
1780
  for (sec = dynobj->sections; sec != NULL; sec = sec->next)
1781
    {
1782
      const char *name;
1783
 
1784
      if ((sec->flags & SEC_LINKER_CREATED) == 0)
1785
        continue;
1786
 
1787
      /* It's OK to base decisions on the section name, because none
1788
         of the dynobj section names depend upon the input files.  */
1789
      name = bfd_get_section_name (dynobj, sec);
1790
 
1791
      if (strcmp (name, ".plt") == 0)
1792
        {
1793
          /* Remember whether there is a PLT.  */
1794
          plt = sec->size != 0;
1795
        }
1796
      else if (strcmp (name, ".opd") == 0
1797
               || CONST_STRNEQ (name, ".dlt")
1798
               || strcmp (name, ".stub") == 0
1799
               || strcmp (name, ".got") == 0)
1800
        {
1801
          /* Strip this section if we don't need it; see the comment below.  */
1802
        }
1803
      else if (CONST_STRNEQ (name, ".rela"))
1804
        {
1805
          if (sec->size != 0)
1806
            {
1807
              asection *target;
1808
 
1809
              /* Remember whether there are any reloc sections other
1810
                 than .rela.plt.  */
1811
              if (strcmp (name, ".rela.plt") != 0)
1812
                {
1813
                  const char *outname;
1814
 
1815
                  relocs = TRUE;
1816
 
1817
                  /* If this relocation section applies to a read only
1818
                     section, then we probably need a DT_TEXTREL
1819
                     entry.  The entries in the .rela.plt section
1820
                     really apply to the .got section, which we
1821
                     created ourselves and so know is not readonly.  */
1822
                  outname = bfd_get_section_name (output_bfd,
1823
                                                  sec->output_section);
1824
                  target = bfd_get_section_by_name (output_bfd, outname + 4);
1825
                  if (target != NULL
1826
                      && (target->flags & SEC_READONLY) != 0
1827
                      && (target->flags & SEC_ALLOC) != 0)
1828
                    reltext = TRUE;
1829
                }
1830
 
1831
              /* We use the reloc_count field as a counter if we need
1832
                 to copy relocs into the output file.  */
1833
              sec->reloc_count = 0;
1834
            }
1835
        }
1836
      else
1837
        {
1838
          /* It's not one of our sections, so don't allocate space.  */
1839
          continue;
1840
        }
1841
 
1842
      if (sec->size == 0)
1843
        {
1844
          /* If we don't need this section, strip it from the
1845
             output file.  This is mostly to handle .rela.bss and
1846
             .rela.plt.  We must create both sections in
1847
             create_dynamic_sections, because they must be created
1848
             before the linker maps input sections to output
1849
             sections.  The linker does that before
1850
             adjust_dynamic_symbol is called, and it is that
1851
             function which decides whether anything needs to go
1852
             into these sections.  */
1853
          sec->flags |= SEC_EXCLUDE;
1854
          continue;
1855
        }
1856
 
1857
      if ((sec->flags & SEC_HAS_CONTENTS) == 0)
1858
        continue;
1859
 
1860
      /* Allocate memory for the section contents if it has not
1861
         been allocated already.  We use bfd_zalloc here in case
1862
         unused entries are not reclaimed before the section's
1863
         contents are written out.  This should not happen, but this
1864
         way if it does, we get a R_PARISC_NONE reloc instead of
1865
         garbage.  */
1866
      if (sec->contents == NULL)
1867
        {
1868
          sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
1869
          if (sec->contents == NULL)
1870
            return FALSE;
1871
        }
1872
    }
1873
 
1874
  if (elf_hash_table (info)->dynamic_sections_created)
1875
    {
1876
      /* Always create a DT_PLTGOT.  It actually has nothing to do with
1877
         the PLT, it is how we communicate the __gp value of a load
1878
         module to the dynamic linker.  */
1879
#define add_dynamic_entry(TAG, VAL) \
1880
  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1881
 
1882
      if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
1883
          || !add_dynamic_entry (DT_PLTGOT, 0))
1884
        return FALSE;
1885
 
1886
      /* Add some entries to the .dynamic section.  We fill in the
1887
         values later, in elf64_hppa_finish_dynamic_sections, but we
1888
         must add the entries now so that we get the correct size for
1889
         the .dynamic section.  The DT_DEBUG entry is filled in by the
1890
         dynamic linker and used by the debugger.  */
1891
      if (! info->shared)
1892
        {
1893
          if (!add_dynamic_entry (DT_DEBUG, 0)
1894
              || !add_dynamic_entry (DT_HP_DLD_HOOK, 0)
1895
              || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
1896
            return FALSE;
1897
        }
1898
 
1899
      /* Force DT_FLAGS to always be set.
1900
         Required by HPUX 11.00 patch PHSS_26559.  */
1901
      if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
1902
        return FALSE;
1903
 
1904
      if (plt)
1905
        {
1906
          if (!add_dynamic_entry (DT_PLTRELSZ, 0)
1907
              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1908
              || !add_dynamic_entry (DT_JMPREL, 0))
1909
            return FALSE;
1910
        }
1911
 
1912
      if (relocs)
1913
        {
1914
          if (!add_dynamic_entry (DT_RELA, 0)
1915
              || !add_dynamic_entry (DT_RELASZ, 0)
1916
              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
1917
            return FALSE;
1918
        }
1919
 
1920
      if (reltext)
1921
        {
1922
          if (!add_dynamic_entry (DT_TEXTREL, 0))
1923
            return FALSE;
1924
          info->flags |= DF_TEXTREL;
1925
        }
1926
    }
1927
#undef add_dynamic_entry
1928
 
1929
  return TRUE;
1930
}
1931
 
1932
/* Called after we have output the symbol into the dynamic symbol
1933
   table, but before we output the symbol into the normal symbol
1934
   table.
1935
 
1936
   For some symbols we had to change their address when outputting
1937
   the dynamic symbol table.  We undo that change here so that
1938
   the symbols have their expected value in the normal symbol
1939
   table.  Ick.  */
1940
 
1941
static int
1942
elf64_hppa_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1943
                                    const char *name,
1944
                                    Elf_Internal_Sym *sym,
1945
                                    asection *input_sec ATTRIBUTE_UNUSED,
1946
                                    struct elf_link_hash_entry *eh)
1947
{
1948
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1949
 
1950
  /* We may be called with the file symbol or section symbols.
1951
     They never need munging, so it is safe to ignore them.  */
1952
  if (!name || !eh)
1953
    return 1;
1954
 
1955
  /* Function symbols for which we created .opd entries *may* have been
1956
     munged by finish_dynamic_symbol and have to be un-munged here.
1957
 
1958
     Note that finish_dynamic_symbol sometimes turns dynamic symbols
1959
     into non-dynamic ones, so we initialize st_shndx to -1 in
1960
     mark_exported_functions and check to see if it was overwritten
1961
     here instead of just checking eh->dynindx.  */
1962
  if (hh->want_opd && hh->st_shndx != -1)
1963
    {
1964
      /* Restore the saved value and section index.  */
1965
      sym->st_value = hh->st_value;
1966
      sym->st_shndx = hh->st_shndx;
1967
    }
1968
 
1969
  return 1;
1970
}
1971
 
1972
/* Finish up dynamic symbol handling.  We set the contents of various
1973
   dynamic sections here.  */
1974
 
1975
static bfd_boolean
1976
elf64_hppa_finish_dynamic_symbol (bfd *output_bfd,
1977
                                  struct bfd_link_info *info,
1978
                                  struct elf_link_hash_entry *eh,
1979
                                  Elf_Internal_Sym *sym)
1980
{
1981
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
1982
  asection *stub, *splt, *sdlt, *sopd, *spltrel, *sdltrel;
1983
  struct elf64_hppa_link_hash_table *hppa_info;
1984
 
1985
  hppa_info = hppa_link_hash_table (info);
1986
  if (hppa_info == NULL)
1987
    return FALSE;
1988
 
1989
  stub = hppa_info->stub_sec;
1990
  splt = hppa_info->plt_sec;
1991
  sdlt = hppa_info->dlt_sec;
1992
  sopd = hppa_info->opd_sec;
1993
  spltrel = hppa_info->plt_rel_sec;
1994
  sdltrel = hppa_info->dlt_rel_sec;
1995
 
1996
  /* Incredible.  It is actually necessary to NOT use the symbol's real
1997
     value when building the dynamic symbol table for a shared library.
1998
     At least for symbols that refer to functions.
1999
 
2000
     We will store a new value and section index into the symbol long
2001
     enough to output it into the dynamic symbol table, then we restore
2002
     the original values (in elf64_hppa_link_output_symbol_hook).  */
2003
  if (hh->want_opd)
2004
    {
2005
      BFD_ASSERT (sopd != NULL);
2006
 
2007
      /* Save away the original value and section index so that we
2008
         can restore them later.  */
2009
      hh->st_value = sym->st_value;
2010
      hh->st_shndx = sym->st_shndx;
2011
 
2012
      /* For the dynamic symbol table entry, we want the value to be
2013
         address of this symbol's entry within the .opd section.  */
2014
      sym->st_value = (hh->opd_offset
2015
                       + sopd->output_offset
2016
                       + sopd->output_section->vma);
2017
      sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
2018
                                                         sopd->output_section);
2019
    }
2020
 
2021
  /* Initialize a .plt entry if requested.  */
2022
  if (hh->want_plt
2023
      && elf64_hppa_dynamic_symbol_p (eh, info))
2024
    {
2025
      bfd_vma value;
2026
      Elf_Internal_Rela rel;
2027
      bfd_byte *loc;
2028
 
2029
      BFD_ASSERT (splt != NULL && spltrel != NULL);
2030
 
2031
      /* We do not actually care about the value in the PLT entry
2032
         if we are creating a shared library and the symbol is
2033
         still undefined, we create a dynamic relocation to fill
2034
         in the correct value.  */
2035
      if (info->shared && eh->root.type == bfd_link_hash_undefined)
2036
        value = 0;
2037
      else
2038
        value = (eh->root.u.def.value + eh->root.u.def.section->vma);
2039
 
2040
      /* Fill in the entry in the procedure linkage table.
2041
 
2042
         The format of a plt entry is
2043
         <funcaddr> <__gp>.
2044
 
2045
         plt_offset is the offset within the PLT section at which to
2046
         install the PLT entry.
2047
 
2048
         We are modifying the in-memory PLT contents here, so we do not add
2049
         in the output_offset of the PLT section.  */
2050
 
2051
      bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset);
2052
      value = _bfd_get_gp_value (splt->output_section->owner);
2053
      bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset + 0x8);
2054
 
2055
      /* Create a dynamic IPLT relocation for this entry.
2056
 
2057
         We are creating a relocation in the output file's PLT section,
2058
         which is included within the DLT secton.  So we do need to include
2059
         the PLT's output_offset in the computation of the relocation's
2060
         address.  */
2061
      rel.r_offset = (hh->plt_offset + splt->output_offset
2062
                      + splt->output_section->vma);
2063
      rel.r_info = ELF64_R_INFO (hh->eh.dynindx, R_PARISC_IPLT);
2064
      rel.r_addend = 0;
2065
 
2066
      loc = spltrel->contents;
2067
      loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2068
      bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc);
2069
    }
2070
 
2071
  /* Initialize an external call stub entry if requested.  */
2072
  if (hh->want_stub
2073
      && elf64_hppa_dynamic_symbol_p (eh, info))
2074
    {
2075
      bfd_vma value;
2076
      int insn;
2077
      unsigned int max_offset;
2078
 
2079
      BFD_ASSERT (stub != NULL);
2080
 
2081
      /* Install the generic stub template.
2082
 
2083
         We are modifying the contents of the stub section, so we do not
2084
         need to include the stub section's output_offset here.  */
2085
      memcpy (stub->contents + hh->stub_offset, plt_stub, sizeof (plt_stub));
2086
 
2087
      /* Fix up the first ldd instruction.
2088
 
2089
         We are modifying the contents of the STUB section in memory,
2090
         so we do not need to include its output offset in this computation.
2091
 
2092
         Note the plt_offset value is the value of the PLT entry relative to
2093
         the start of the PLT section.  These instructions will reference
2094
         data relative to the value of __gp, which may not necessarily have
2095
         the same address as the start of the PLT section.
2096
 
2097
         gp_offset contains the offset of __gp within the PLT section.  */
2098
      value = hh->plt_offset - hppa_info->gp_offset;
2099
 
2100
      insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset);
2101
      if (output_bfd->arch_info->mach >= 25)
2102
        {
2103
          /* Wide mode allows 16 bit offsets.  */
2104
          max_offset = 32768;
2105
          insn &= ~ 0xfff1;
2106
          insn |= re_assemble_16 ((int) value);
2107
        }
2108
      else
2109
        {
2110
          max_offset = 8192;
2111
          insn &= ~ 0x3ff1;
2112
          insn |= re_assemble_14 ((int) value);
2113
        }
2114
 
2115
      if ((value & 7) || value + max_offset >= 2*max_offset - 8)
2116
        {
2117
          (*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"),
2118
                                 hh->eh.root.root.string,
2119
                                 (long) value);
2120
          return FALSE;
2121
        }
2122
 
2123
      bfd_put_32 (stub->owner, (bfd_vma) insn,
2124
                  stub->contents + hh->stub_offset);
2125
 
2126
      /* Fix up the second ldd instruction.  */
2127
      value += 8;
2128
      insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset + 8);
2129
      if (output_bfd->arch_info->mach >= 25)
2130
        {
2131
          insn &= ~ 0xfff1;
2132
          insn |= re_assemble_16 ((int) value);
2133
        }
2134
      else
2135
        {
2136
          insn &= ~ 0x3ff1;
2137
          insn |= re_assemble_14 ((int) value);
2138
        }
2139
      bfd_put_32 (stub->owner, (bfd_vma) insn,
2140
                  stub->contents + hh->stub_offset + 8);
2141
    }
2142
 
2143
  return TRUE;
2144
}
2145
 
2146
/* The .opd section contains FPTRs for each function this file
2147
   exports.  Initialize the FPTR entries.  */
2148
 
2149
static bfd_boolean
2150
elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data)
2151
{
2152
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2153
  struct bfd_link_info *info = (struct bfd_link_info *)data;
2154
  struct elf64_hppa_link_hash_table *hppa_info;
2155
  asection *sopd;
2156
  asection *sopdrel;
2157
 
2158
  hppa_info = hppa_link_hash_table (info);
2159
  if (hppa_info == NULL)
2160
    return FALSE;
2161
 
2162
  sopd = hppa_info->opd_sec;
2163
  sopdrel = hppa_info->opd_rel_sec;
2164
 
2165
  if (hh->want_opd)
2166
    {
2167
      bfd_vma value;
2168
 
2169
      /* The first two words of an .opd entry are zero.
2170
 
2171
         We are modifying the contents of the OPD section in memory, so we
2172
         do not need to include its output offset in this computation.  */
2173
      memset (sopd->contents + hh->opd_offset, 0, 16);
2174
 
2175
      value = (eh->root.u.def.value
2176
               + eh->root.u.def.section->output_section->vma
2177
               + eh->root.u.def.section->output_offset);
2178
 
2179
      /* The next word is the address of the function.  */
2180
      bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 16);
2181
 
2182
      /* The last word is our local __gp value.  */
2183
      value = _bfd_get_gp_value (sopd->output_section->owner);
2184
      bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 24);
2185
    }
2186
 
2187
  /* If we are generating a shared library, we must generate EPLT relocations
2188
     for each entry in the .opd, even for static functions (they may have
2189
     had their address taken).  */
2190
  if (info->shared && hh->want_opd)
2191
    {
2192
      Elf_Internal_Rela rel;
2193
      bfd_byte *loc;
2194
      int dynindx;
2195
 
2196
      /* We may need to do a relocation against a local symbol, in
2197
         which case we have to look up it's dynamic symbol index off
2198
         the local symbol hash table.  */
2199
      if (eh->dynindx != -1)
2200
        dynindx = eh->dynindx;
2201
      else
2202
        dynindx
2203
          = _bfd_elf_link_lookup_local_dynindx (info, hh->owner,
2204
                                                hh->sym_indx);
2205
 
2206
      /* The offset of this relocation is the absolute address of the
2207
         .opd entry for this symbol.  */
2208
      rel.r_offset = (hh->opd_offset + sopd->output_offset
2209
                      + sopd->output_section->vma);
2210
 
2211
      /* If H is non-null, then we have an external symbol.
2212
 
2213
         It is imperative that we use a different dynamic symbol for the
2214
         EPLT relocation if the symbol has global scope.
2215
 
2216
         In the dynamic symbol table, the function symbol will have a value
2217
         which is address of the function's .opd entry.
2218
 
2219
         Thus, we can not use that dynamic symbol for the EPLT relocation
2220
         (if we did, the data in the .opd would reference itself rather
2221
         than the actual address of the function).  Instead we have to use
2222
         a new dynamic symbol which has the same value as the original global
2223
         function symbol.
2224
 
2225
         We prefix the original symbol with a "." and use the new symbol in
2226
         the EPLT relocation.  This new symbol has already been recorded in
2227
         the symbol table, we just have to look it up and use it.
2228
 
2229
         We do not have such problems with static functions because we do
2230
         not make their addresses in the dynamic symbol table point to
2231
         the .opd entry.  Ultimately this should be safe since a static
2232
         function can not be directly referenced outside of its shared
2233
         library.
2234
 
2235
         We do have to play similar games for FPTR relocations in shared
2236
         libraries, including those for static symbols.  See the FPTR
2237
         handling in elf64_hppa_finalize_dynreloc.  */
2238
      if (eh)
2239
        {
2240
          char *new_name;
2241
          struct elf_link_hash_entry *nh;
2242
 
2243
          new_name = alloca (strlen (eh->root.root.string) + 2);
2244
          new_name[0] = '.';
2245
          strcpy (new_name + 1, eh->root.root.string);
2246
 
2247
          nh = elf_link_hash_lookup (elf_hash_table (info),
2248
                                     new_name, TRUE, TRUE, FALSE);
2249
 
2250
          /* All we really want from the new symbol is its dynamic
2251
             symbol index.  */
2252
          if (nh)
2253
            dynindx = nh->dynindx;
2254
        }
2255
 
2256
      rel.r_addend = 0;
2257
      rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
2258
 
2259
      loc = sopdrel->contents;
2260
      loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
2261
      bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc);
2262
    }
2263
  return TRUE;
2264
}
2265
 
2266
/* The .dlt section contains addresses for items referenced through the
2267
   dlt.  Note that we can have a DLTIND relocation for a local symbol, thus
2268
   we can not depend on finish_dynamic_symbol to initialize the .dlt.  */
2269
 
2270
static bfd_boolean
2271
elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data)
2272
{
2273
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2274
  struct bfd_link_info *info = (struct bfd_link_info *)data;
2275
  struct elf64_hppa_link_hash_table *hppa_info;
2276
  asection *sdlt, *sdltrel;
2277
 
2278
  hppa_info = hppa_link_hash_table (info);
2279
  if (hppa_info == NULL)
2280
    return FALSE;
2281
 
2282
  sdlt = hppa_info->dlt_sec;
2283
  sdltrel = hppa_info->dlt_rel_sec;
2284
 
2285
  /* H/DYN_H may refer to a local variable and we know it's
2286
     address, so there is no need to create a relocation.  Just install
2287
     the proper value into the DLT, note this shortcut can not be
2288
     skipped when building a shared library.  */
2289
  if (! info->shared && hh && hh->want_dlt)
2290
    {
2291
      bfd_vma value;
2292
 
2293
      /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2294
         to point to the FPTR entry in the .opd section.
2295
 
2296
         We include the OPD's output offset in this computation as
2297
         we are referring to an absolute address in the resulting
2298
         object file.  */
2299
      if (hh->want_opd)
2300
        {
2301
          value = (hh->opd_offset
2302
                   + hppa_info->opd_sec->output_offset
2303
                   + hppa_info->opd_sec->output_section->vma);
2304
        }
2305
      else if ((eh->root.type == bfd_link_hash_defined
2306
                || eh->root.type == bfd_link_hash_defweak)
2307
               && eh->root.u.def.section)
2308
        {
2309
          value = eh->root.u.def.value + eh->root.u.def.section->output_offset;
2310
          if (eh->root.u.def.section->output_section)
2311
            value += eh->root.u.def.section->output_section->vma;
2312
          else
2313
            value += eh->root.u.def.section->vma;
2314
        }
2315
      else
2316
        /* We have an undefined function reference.  */
2317
        value = 0;
2318
 
2319
      /* We do not need to include the output offset of the DLT section
2320
         here because we are modifying the in-memory contents.  */
2321
      bfd_put_64 (sdlt->owner, value, sdlt->contents + hh->dlt_offset);
2322
    }
2323
 
2324
  /* Create a relocation for the DLT entry associated with this symbol.
2325
     When building a shared library the symbol does not have to be dynamic.  */
2326
  if (hh->want_dlt
2327
      && (elf64_hppa_dynamic_symbol_p (eh, info) || info->shared))
2328
    {
2329
      Elf_Internal_Rela rel;
2330
      bfd_byte *loc;
2331
      int dynindx;
2332
 
2333
      /* We may need to do a relocation against a local symbol, in
2334
         which case we have to look up it's dynamic symbol index off
2335
         the local symbol hash table.  */
2336
      if (eh && eh->dynindx != -1)
2337
        dynindx = eh->dynindx;
2338
      else
2339
        dynindx
2340
          = _bfd_elf_link_lookup_local_dynindx (info, hh->owner,
2341
                                                hh->sym_indx);
2342
 
2343
      /* Create a dynamic relocation for this entry.  Do include the output
2344
         offset of the DLT entry since we need an absolute address in the
2345
         resulting object file.  */
2346
      rel.r_offset = (hh->dlt_offset + sdlt->output_offset
2347
                      + sdlt->output_section->vma);
2348
      if (eh && eh->type == STT_FUNC)
2349
          rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64);
2350
      else
2351
          rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
2352
      rel.r_addend = 0;
2353
 
2354
      loc = sdltrel->contents;
2355
      loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2356
      bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc);
2357
    }
2358
  return TRUE;
2359
}
2360
 
2361
/* Finalize the dynamic relocations.  Specifically the FPTR relocations
2362
   for dynamic functions used to initialize static data.  */
2363
 
2364
static bfd_boolean
2365
elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh,
2366
                              void *data)
2367
{
2368
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2369
  struct bfd_link_info *info = (struct bfd_link_info *)data;
2370
  struct elf64_hppa_link_hash_table *hppa_info;
2371
  int dynamic_symbol;
2372
 
2373
  dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, info);
2374
 
2375
  if (!dynamic_symbol && !info->shared)
2376
    return TRUE;
2377
 
2378
  if (hh->reloc_entries)
2379
    {
2380
      struct elf64_hppa_dyn_reloc_entry *rent;
2381
      int dynindx;
2382
 
2383
      hppa_info = hppa_link_hash_table (info);
2384
      if (hppa_info == NULL)
2385
        return FALSE;
2386
 
2387
      /* We may need to do a relocation against a local symbol, in
2388
         which case we have to look up it's dynamic symbol index off
2389
         the local symbol hash table.  */
2390
      if (eh->dynindx != -1)
2391
        dynindx = eh->dynindx;
2392
      else
2393
        dynindx
2394
          = _bfd_elf_link_lookup_local_dynindx (info, hh->owner,
2395
                                                hh->sym_indx);
2396
 
2397
      for (rent = hh->reloc_entries; rent; rent = rent->next)
2398
        {
2399
          Elf_Internal_Rela rel;
2400
          bfd_byte *loc;
2401
 
2402
          /* Allocate one iff we are building a shared library, the relocation
2403
             isn't a R_PARISC_FPTR64, or we don't want an opd entry.  */
2404
          if (!info->shared && rent->type == R_PARISC_FPTR64 && hh->want_opd)
2405
            continue;
2406
 
2407
          /* Create a dynamic relocation for this entry.
2408
 
2409
             We need the output offset for the reloc's section because
2410
             we are creating an absolute address in the resulting object
2411
             file.  */
2412
          rel.r_offset = (rent->offset + rent->sec->output_offset
2413
                          + rent->sec->output_section->vma);
2414
 
2415
          /* An FPTR64 relocation implies that we took the address of
2416
             a function and that the function has an entry in the .opd
2417
             section.  We want the FPTR64 relocation to reference the
2418
             entry in .opd.
2419
 
2420
             We could munge the symbol value in the dynamic symbol table
2421
             (in fact we already do for functions with global scope) to point
2422
             to the .opd entry.  Then we could use that dynamic symbol in
2423
             this relocation.
2424
 
2425
             Or we could do something sensible, not munge the symbol's
2426
             address and instead just use a different symbol to reference
2427
             the .opd entry.  At least that seems sensible until you
2428
             realize there's no local dynamic symbols we can use for that
2429
             purpose.  Thus the hair in the check_relocs routine.
2430
 
2431
             We use a section symbol recorded by check_relocs as the
2432
             base symbol for the relocation.  The addend is the difference
2433
             between the section symbol and the address of the .opd entry.  */
2434
          if (info->shared && rent->type == R_PARISC_FPTR64 && hh->want_opd)
2435
            {
2436
              bfd_vma value, value2;
2437
 
2438
              /* First compute the address of the opd entry for this symbol.  */
2439
              value = (hh->opd_offset
2440
                       + hppa_info->opd_sec->output_section->vma
2441
                       + hppa_info->opd_sec->output_offset);
2442
 
2443
              /* Compute the value of the start of the section with
2444
                 the relocation.  */
2445
              value2 = (rent->sec->output_section->vma
2446
                        + rent->sec->output_offset);
2447
 
2448
              /* Compute the difference between the start of the section
2449
                 with the relocation and the opd entry.  */
2450
              value -= value2;
2451
 
2452
              /* The result becomes the addend of the relocation.  */
2453
              rel.r_addend = value;
2454
 
2455
              /* The section symbol becomes the symbol for the dynamic
2456
                 relocation.  */
2457
              dynindx
2458
                = _bfd_elf_link_lookup_local_dynindx (info,
2459
                                                      rent->sec->owner,
2460
                                                      rent->sec_symndx);
2461
            }
2462
          else
2463
            rel.r_addend = rent->addend;
2464
 
2465
          rel.r_info = ELF64_R_INFO (dynindx, rent->type);
2466
 
2467
          loc = hppa_info->other_rel_sec->contents;
2468
          loc += (hppa_info->other_rel_sec->reloc_count++
2469
                  * sizeof (Elf64_External_Rela));
2470
          bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner,
2471
                                     &rel, loc);
2472
        }
2473
    }
2474
 
2475
  return TRUE;
2476
}
2477
 
2478
/* Used to decide how to sort relocs in an optimal manner for the
2479
   dynamic linker, before writing them out.  */
2480
 
2481
static enum elf_reloc_type_class
2482
elf64_hppa_reloc_type_class (const Elf_Internal_Rela *rela)
2483
{
2484
  if (ELF64_R_SYM (rela->r_info) == 0)
2485
    return reloc_class_relative;
2486
 
2487
  switch ((int) ELF64_R_TYPE (rela->r_info))
2488
    {
2489
    case R_PARISC_IPLT:
2490
      return reloc_class_plt;
2491
    case R_PARISC_COPY:
2492
      return reloc_class_copy;
2493
    default:
2494
      return reloc_class_normal;
2495
    }
2496
}
2497
 
2498
/* Finish up the dynamic sections.  */
2499
 
2500
static bfd_boolean
2501
elf64_hppa_finish_dynamic_sections (bfd *output_bfd,
2502
                                    struct bfd_link_info *info)
2503
{
2504
  bfd *dynobj;
2505
  asection *sdyn;
2506
  struct elf64_hppa_link_hash_table *hppa_info;
2507
 
2508
  hppa_info = hppa_link_hash_table (info);
2509
  if (hppa_info == NULL)
2510
    return FALSE;
2511
 
2512
  /* Finalize the contents of the .opd section.  */
2513
  elf_link_hash_traverse (elf_hash_table (info),
2514
                          elf64_hppa_finalize_opd,
2515
                          info);
2516
 
2517
  elf_link_hash_traverse (elf_hash_table (info),
2518
                          elf64_hppa_finalize_dynreloc,
2519
                          info);
2520
 
2521
  /* Finalize the contents of the .dlt section.  */
2522
  dynobj = elf_hash_table (info)->dynobj;
2523
  /* Finalize the contents of the .dlt section.  */
2524
  elf_link_hash_traverse (elf_hash_table (info),
2525
                          elf64_hppa_finalize_dlt,
2526
                          info);
2527
 
2528
  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2529
 
2530
  if (elf_hash_table (info)->dynamic_sections_created)
2531
    {
2532
      Elf64_External_Dyn *dyncon, *dynconend;
2533
 
2534
      BFD_ASSERT (sdyn != NULL);
2535
 
2536
      dyncon = (Elf64_External_Dyn *) sdyn->contents;
2537
      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
2538
      for (; dyncon < dynconend; dyncon++)
2539
        {
2540
          Elf_Internal_Dyn dyn;
2541
          asection *s;
2542
 
2543
          bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2544
 
2545
          switch (dyn.d_tag)
2546
            {
2547
            default:
2548
              break;
2549
 
2550
            case DT_HP_LOAD_MAP:
2551
              /* Compute the absolute address of 16byte scratchpad area
2552
                 for the dynamic linker.
2553
 
2554
                 By convention the linker script will allocate the scratchpad
2555
                 area at the start of the .data section.  So all we have to
2556
                 to is find the start of the .data section.  */
2557
              s = bfd_get_section_by_name (output_bfd, ".data");
2558
              dyn.d_un.d_ptr = s->vma;
2559
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2560
              break;
2561
 
2562
            case DT_PLTGOT:
2563
              /* HP's use PLTGOT to set the GOT register.  */
2564
              dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd);
2565
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2566
              break;
2567
 
2568
            case DT_JMPREL:
2569
              s = hppa_info->plt_rel_sec;
2570
              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2571
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2572
              break;
2573
 
2574
            case DT_PLTRELSZ:
2575
              s = hppa_info->plt_rel_sec;
2576
              dyn.d_un.d_val = s->size;
2577
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2578
              break;
2579
 
2580
            case DT_RELA:
2581
              s = hppa_info->other_rel_sec;
2582
              if (! s || ! s->size)
2583
                s = hppa_info->dlt_rel_sec;
2584
              if (! s || ! s->size)
2585
                s = hppa_info->opd_rel_sec;
2586
              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2587
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2588
              break;
2589
 
2590
            case DT_RELASZ:
2591
              s = hppa_info->other_rel_sec;
2592
              dyn.d_un.d_val = s->size;
2593
              s = hppa_info->dlt_rel_sec;
2594
              dyn.d_un.d_val += s->size;
2595
              s = hppa_info->opd_rel_sec;
2596
              dyn.d_un.d_val += s->size;
2597
              /* There is some question about whether or not the size of
2598
                 the PLT relocs should be included here.  HP's tools do
2599
                 it, so we'll emulate them.  */
2600
              s = hppa_info->plt_rel_sec;
2601
              dyn.d_un.d_val += s->size;
2602
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
2603
              break;
2604
 
2605
            }
2606
        }
2607
    }
2608
 
2609
  return TRUE;
2610
}
2611
 
2612
/* Support for core dump NOTE sections.  */
2613
 
2614
static bfd_boolean
2615
elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2616
{
2617
  int offset;
2618
  size_t size;
2619
 
2620
  switch (note->descsz)
2621
    {
2622
      default:
2623
        return FALSE;
2624
 
2625
      case 760:         /* Linux/hppa */
2626
        /* pr_cursig */
2627
        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2628
 
2629
        /* pr_pid */
2630
        elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32);
2631
 
2632
        /* pr_reg */
2633
        offset = 112;
2634
        size = 640;
2635
 
2636
        break;
2637
    }
2638
 
2639
  /* Make a ".reg/999" section.  */
2640
  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2641
                                          size, note->descpos + offset);
2642
}
2643
 
2644
static bfd_boolean
2645
elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2646
{
2647
  char * command;
2648
  int n;
2649
 
2650
  switch (note->descsz)
2651
    {
2652
    default:
2653
      return FALSE;
2654
 
2655
    case 136:           /* Linux/hppa elf_prpsinfo.  */
2656
      elf_tdata (abfd)->core_program
2657
        = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2658
      elf_tdata (abfd)->core_command
2659
        = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2660
    }
2661
 
2662
  /* Note that for some reason, a spurious space is tacked
2663
     onto the end of the args in some (at least one anyway)
2664
     implementations, so strip it off if it exists.  */
2665
  command = elf_tdata (abfd)->core_command;
2666
  n = strlen (command);
2667
 
2668
  if (0 < n && command[n - 1] == ' ')
2669
    command[n - 1] = '\0';
2670
 
2671
  return TRUE;
2672
}
2673
 
2674
/* Return the number of additional phdrs we will need.
2675
 
2676
   The generic ELF code only creates PT_PHDRs for executables.  The HP
2677
   dynamic linker requires PT_PHDRs for dynamic libraries too.
2678
 
2679
   This routine indicates that the backend needs one additional program
2680
   header for that case.
2681
 
2682
   Note we do not have access to the link info structure here, so we have
2683
   to guess whether or not we are building a shared library based on the
2684
   existence of a .interp section.  */
2685
 
2686
static int
2687
elf64_hppa_additional_program_headers (bfd *abfd,
2688
                                struct bfd_link_info *info ATTRIBUTE_UNUSED)
2689
{
2690
  asection *s;
2691
 
2692
  /* If we are creating a shared library, then we have to create a
2693
     PT_PHDR segment.  HP's dynamic linker chokes without it.  */
2694
  s = bfd_get_section_by_name (abfd, ".interp");
2695
  if (! s)
2696
    return 1;
2697
  return 0;
2698
}
2699
 
2700
/* Allocate and initialize any program headers required by this
2701
   specific backend.
2702
 
2703
   The generic ELF code only creates PT_PHDRs for executables.  The HP
2704
   dynamic linker requires PT_PHDRs for dynamic libraries too.
2705
 
2706
   This allocates the PT_PHDR and initializes it in a manner suitable
2707
   for the HP linker.
2708
 
2709
   Note we do not have access to the link info structure here, so we have
2710
   to guess whether or not we are building a shared library based on the
2711
   existence of a .interp section.  */
2712
 
2713
static bfd_boolean
2714
elf64_hppa_modify_segment_map (bfd *abfd,
2715
                               struct bfd_link_info *info ATTRIBUTE_UNUSED)
2716
{
2717
  struct elf_segment_map *m;
2718
  asection *s;
2719
 
2720
  s = bfd_get_section_by_name (abfd, ".interp");
2721
  if (! s)
2722
    {
2723
      for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2724
        if (m->p_type == PT_PHDR)
2725
          break;
2726
      if (m == NULL)
2727
        {
2728
          m = ((struct elf_segment_map *)
2729
               bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
2730
          if (m == NULL)
2731
            return FALSE;
2732
 
2733
          m->p_type = PT_PHDR;
2734
          m->p_flags = PF_R | PF_X;
2735
          m->p_flags_valid = 1;
2736
          m->p_paddr_valid = 1;
2737
          m->includes_phdrs = 1;
2738
 
2739
          m->next = elf_tdata (abfd)->segment_map;
2740
          elf_tdata (abfd)->segment_map = m;
2741
        }
2742
    }
2743
 
2744
  for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
2745
    if (m->p_type == PT_LOAD)
2746
      {
2747
        unsigned int i;
2748
 
2749
        for (i = 0; i < m->count; i++)
2750
          {
2751
            /* The code "hint" is not really a hint.  It is a requirement
2752
               for certain versions of the HP dynamic linker.  Worse yet,
2753
               it must be set even if the shared library does not have
2754
               any code in its "text" segment (thus the check for .hash
2755
               to catch this situation).  */
2756
            if (m->sections[i]->flags & SEC_CODE
2757
                || (strcmp (m->sections[i]->name, ".hash") == 0))
2758
              m->p_flags |= (PF_X | PF_HP_CODE);
2759
          }
2760
      }
2761
 
2762
  return TRUE;
2763
}
2764
 
2765
/* Called when writing out an object file to decide the type of a
2766
   symbol.  */
2767
static int
2768
elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym,
2769
                                int type)
2770
{
2771
  if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
2772
    return STT_PARISC_MILLI;
2773
  else
2774
    return type;
2775
}
2776
 
2777
/* Support HP specific sections for core files.  */
2778
 
2779
static bfd_boolean
2780
elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int sec_index,
2781
                              const char *typename)
2782
{
2783
  if (hdr->p_type == PT_HP_CORE_KERNEL)
2784
    {
2785
      asection *sect;
2786
 
2787
      if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename))
2788
        return FALSE;
2789
 
2790
      sect = bfd_make_section_anyway (abfd, ".kernel");
2791
      if (sect == NULL)
2792
        return FALSE;
2793
      sect->size = hdr->p_filesz;
2794
      sect->filepos = hdr->p_offset;
2795
      sect->flags = SEC_HAS_CONTENTS | SEC_READONLY;
2796
      return TRUE;
2797
    }
2798
 
2799
  if (hdr->p_type == PT_HP_CORE_PROC)
2800
    {
2801
      int sig;
2802
 
2803
      if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0)
2804
        return FALSE;
2805
      if (bfd_bread (&sig, 4, abfd) != 4)
2806
        return FALSE;
2807
 
2808
      elf_tdata (abfd)->core_signal = sig;
2809
 
2810
      if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename))
2811
        return FALSE;
2812
 
2813
      /* GDB uses the ".reg" section to read register contents.  */
2814
      return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz,
2815
                                              hdr->p_offset);
2816
    }
2817
 
2818
  if (hdr->p_type == PT_HP_CORE_LOADABLE
2819
      || hdr->p_type == PT_HP_CORE_STACK
2820
      || hdr->p_type == PT_HP_CORE_MMF)
2821
    hdr->p_type = PT_LOAD;
2822
 
2823
  return _bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename);
2824
}
2825
 
2826
/* Hook called by the linker routine which adds symbols from an object
2827
   file.  HP's libraries define symbols with HP specific section
2828
   indices, which we have to handle.  */
2829
 
2830
static bfd_boolean
2831
elf_hppa_add_symbol_hook (bfd *abfd,
2832
                          struct bfd_link_info *info ATTRIBUTE_UNUSED,
2833
                          Elf_Internal_Sym *sym,
2834
                          const char **namep ATTRIBUTE_UNUSED,
2835
                          flagword *flagsp ATTRIBUTE_UNUSED,
2836
                          asection **secp,
2837
                          bfd_vma *valp)
2838
{
2839
  unsigned int sec_index = sym->st_shndx;
2840
 
2841
  switch (sec_index)
2842
    {
2843
    case SHN_PARISC_ANSI_COMMON:
2844
      *secp = bfd_make_section_old_way (abfd, ".PARISC.ansi.common");
2845
      (*secp)->flags |= SEC_IS_COMMON;
2846
      *valp = sym->st_size;
2847
      break;
2848
 
2849
    case SHN_PARISC_HUGE_COMMON:
2850
      *secp = bfd_make_section_old_way (abfd, ".PARISC.huge.common");
2851
      (*secp)->flags |= SEC_IS_COMMON;
2852
      *valp = sym->st_size;
2853
      break;
2854
    }
2855
 
2856
  return TRUE;
2857
}
2858
 
2859
static bfd_boolean
2860
elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
2861
                                         void *data)
2862
{
2863
  struct bfd_link_info *info = data;
2864
 
2865
  if (h->root.type == bfd_link_hash_warning)
2866
    h = (struct elf_link_hash_entry *) h->root.u.i.link;
2867
 
2868
  /* If we are not creating a shared library, and this symbol is
2869
     referenced by a shared library but is not defined anywhere, then
2870
     the generic code will warn that it is undefined.
2871
 
2872
     This behavior is undesirable on HPs since the standard shared
2873
     libraries contain references to undefined symbols.
2874
 
2875
     So we twiddle the flags associated with such symbols so that they
2876
     will not trigger the warning.  ?!? FIXME.  This is horribly fragile.
2877
 
2878
     Ultimately we should have better controls over the generic ELF BFD
2879
     linker code.  */
2880
  if (! info->relocatable
2881
      && info->unresolved_syms_in_shared_libs != RM_IGNORE
2882
      && h->root.type == bfd_link_hash_undefined
2883
      && h->ref_dynamic
2884
      && !h->ref_regular)
2885
    {
2886
      h->ref_dynamic = 0;
2887
      h->pointer_equality_needed = 1;
2888
    }
2889
 
2890
  return TRUE;
2891
}
2892
 
2893
static bfd_boolean
2894
elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
2895
                                         void *data)
2896
{
2897
  struct bfd_link_info *info = data;
2898
 
2899
  if (h->root.type == bfd_link_hash_warning)
2900
    h = (struct elf_link_hash_entry *) h->root.u.i.link;
2901
 
2902
  /* If we are not creating a shared library, and this symbol is
2903
     referenced by a shared library but is not defined anywhere, then
2904
     the generic code will warn that it is undefined.
2905
 
2906
     This behavior is undesirable on HPs since the standard shared
2907
     libraries contain references to undefined symbols.
2908
 
2909
     So we twiddle the flags associated with such symbols so that they
2910
     will not trigger the warning.  ?!? FIXME.  This is horribly fragile.
2911
 
2912
     Ultimately we should have better controls over the generic ELF BFD
2913
     linker code.  */
2914
  if (! info->relocatable
2915
      && info->unresolved_syms_in_shared_libs != RM_IGNORE
2916
      && h->root.type == bfd_link_hash_undefined
2917
      && !h->ref_dynamic
2918
      && !h->ref_regular
2919
      && h->pointer_equality_needed)
2920
    {
2921
      h->ref_dynamic = 1;
2922
      h->pointer_equality_needed = 0;
2923
    }
2924
 
2925
  return TRUE;
2926
}
2927
 
2928
static bfd_boolean
2929
elf_hppa_is_dynamic_loader_symbol (const char *name)
2930
{
2931
  return (! strcmp (name, "__CPU_REVISION")
2932
          || ! strcmp (name, "__CPU_KEYBITS_1")
2933
          || ! strcmp (name, "__SYSTEM_ID_D")
2934
          || ! strcmp (name, "__FPU_MODEL")
2935
          || ! strcmp (name, "__FPU_REVISION")
2936
          || ! strcmp (name, "__ARGC")
2937
          || ! strcmp (name, "__ARGV")
2938
          || ! strcmp (name, "__ENVP")
2939
          || ! strcmp (name, "__TLS_SIZE_D")
2940
          || ! strcmp (name, "__LOAD_INFO")
2941
          || ! strcmp (name, "__systab"));
2942
}
2943
 
2944
/* Record the lowest address for the data and text segments.  */
2945
static void
2946
elf_hppa_record_segment_addrs (bfd *abfd,
2947
                               asection *section,
2948
                               void *data)
2949
{
2950
  struct elf64_hppa_link_hash_table *hppa_info = data;
2951
 
2952
  if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2953
    {
2954
      bfd_vma value;
2955
      Elf_Internal_Phdr *p;
2956
 
2957
      p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
2958
      BFD_ASSERT (p != NULL);
2959
      value = p->p_vaddr;
2960
 
2961
      if (section->flags & SEC_READONLY)
2962
        {
2963
          if (value < hppa_info->text_segment_base)
2964
            hppa_info->text_segment_base = value;
2965
        }
2966
      else
2967
        {
2968
          if (value < hppa_info->data_segment_base)
2969
            hppa_info->data_segment_base = value;
2970
        }
2971
    }
2972
}
2973
 
2974
/* Called after we have seen all the input files/sections, but before
2975
   final symbol resolution and section placement has been determined.
2976
 
2977
   We use this hook to (possibly) provide a value for __gp, then we
2978
   fall back to the generic ELF final link routine.  */
2979
 
2980
static bfd_boolean
2981
elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
2982
{
2983
  bfd_boolean retval;
2984
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
2985
 
2986
  if (hppa_info == NULL)
2987
    return FALSE;
2988
 
2989
  if (! info->relocatable)
2990
    {
2991
      struct elf_link_hash_entry *gp;
2992
      bfd_vma gp_val;
2993
 
2994
      /* The linker script defines a value for __gp iff it was referenced
2995
         by one of the objects being linked.  First try to find the symbol
2996
         in the hash table.  If that fails, just compute the value __gp
2997
         should have had.  */
2998
      gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
2999
                                 FALSE, FALSE);
3000
 
3001
      if (gp)
3002
        {
3003
 
3004
          /* Adjust the value of __gp as we may want to slide it into the
3005
             .plt section so that the stubs can access PLT entries without
3006
             using an addil sequence.  */
3007
          gp->root.u.def.value += hppa_info->gp_offset;
3008
 
3009
          gp_val = (gp->root.u.def.section->output_section->vma
3010
                    + gp->root.u.def.section->output_offset
3011
                    + gp->root.u.def.value);
3012
        }
3013
      else
3014
        {
3015
          asection *sec;
3016
 
3017
          /* First look for a .plt section.  If found, then __gp is the
3018
             address of the .plt + gp_offset.
3019
 
3020
             If no .plt is found, then look for .dlt, .opd and .data (in
3021
             that order) and set __gp to the base address of whichever
3022
             section is found first.  */
3023
 
3024
          sec = hppa_info->plt_sec;
3025
          if (sec && ! (sec->flags & SEC_EXCLUDE))
3026
            gp_val = (sec->output_offset
3027
                      + sec->output_section->vma
3028
                      + hppa_info->gp_offset);
3029
          else
3030
            {
3031
              sec = hppa_info->dlt_sec;
3032
              if (!sec || (sec->flags & SEC_EXCLUDE))
3033
                sec = hppa_info->opd_sec;
3034
              if (!sec || (sec->flags & SEC_EXCLUDE))
3035
                sec = bfd_get_section_by_name (abfd, ".data");
3036
              if (!sec || (sec->flags & SEC_EXCLUDE))
3037
                gp_val = 0;
3038
              else
3039
                gp_val = sec->output_offset + sec->output_section->vma;
3040
            }
3041
        }
3042
 
3043
      /* Install whatever value we found/computed for __gp.  */
3044
      _bfd_set_gp_value (abfd, gp_val);
3045
    }
3046
 
3047
  /* We need to know the base of the text and data segments so that we
3048
     can perform SEGREL relocations.  We will record the base addresses
3049
     when we encounter the first SEGREL relocation.  */
3050
  hppa_info->text_segment_base = (bfd_vma)-1;
3051
  hppa_info->data_segment_base = (bfd_vma)-1;
3052
 
3053
  /* HP's shared libraries have references to symbols that are not
3054
     defined anywhere.  The generic ELF BFD linker code will complain
3055
     about such symbols.
3056
 
3057
     So we detect the losing case and arrange for the flags on the symbol
3058
     to indicate that it was never referenced.  This keeps the generic
3059
     ELF BFD link code happy and appears to not create any secondary
3060
     problems.  Ultimately we need a way to control the behavior of the
3061
     generic ELF BFD link code better.  */
3062
  elf_link_hash_traverse (elf_hash_table (info),
3063
                          elf_hppa_unmark_useless_dynamic_symbols,
3064
                          info);
3065
 
3066
  /* Invoke the regular ELF backend linker to do all the work.  */
3067
  retval = bfd_elf_final_link (abfd, info);
3068
 
3069
  elf_link_hash_traverse (elf_hash_table (info),
3070
                          elf_hppa_remark_useless_dynamic_symbols,
3071
                          info);
3072
 
3073
  /* If we're producing a final executable, sort the contents of the
3074
     unwind section. */
3075
  if (retval && !info->relocatable)
3076
    retval = elf_hppa_sort_unwind (abfd);
3077
 
3078
  return retval;
3079
}
3080
 
3081
/* Relocate the given INSN.  VALUE should be the actual value we want
3082
   to insert into the instruction, ie by this point we should not be
3083
   concerned with computing an offset relative to the DLT, PC, etc.
3084
   Instead this routine is meant to handle the bit manipulations needed
3085
   to insert the relocation into the given instruction.  */
3086
 
3087
static int
3088
elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type)
3089
{
3090
  switch (r_type)
3091
    {
3092
    /* This is any 22 bit branch.  In PA2.0 syntax it corresponds to
3093
       the "B" instruction.  */
3094
    case R_PARISC_PCREL22F:
3095
    case R_PARISC_PCREL22C:
3096
      return (insn & ~0x3ff1ffd) | re_assemble_22 (sym_value);
3097
 
3098
      /* This is any 12 bit branch.  */
3099
    case R_PARISC_PCREL12F:
3100
      return (insn & ~0x1ffd) | re_assemble_12 (sym_value);
3101
 
3102
    /* This is any 17 bit branch.  In PA2.0 syntax it also corresponds
3103
       to the "B" instruction as well as BE.  */
3104
    case R_PARISC_PCREL17F:
3105
    case R_PARISC_DIR17F:
3106
    case R_PARISC_DIR17R:
3107
    case R_PARISC_PCREL17C:
3108
    case R_PARISC_PCREL17R:
3109
      return (insn & ~0x1f1ffd) | re_assemble_17 (sym_value);
3110
 
3111
    /* ADDIL or LDIL instructions.  */
3112
    case R_PARISC_DLTREL21L:
3113
    case R_PARISC_DLTIND21L:
3114
    case R_PARISC_LTOFF_FPTR21L:
3115
    case R_PARISC_PCREL21L:
3116
    case R_PARISC_LTOFF_TP21L:
3117
    case R_PARISC_DPREL21L:
3118
    case R_PARISC_PLTOFF21L:
3119
    case R_PARISC_DIR21L:
3120
      return (insn & ~0x1fffff) | re_assemble_21 (sym_value);
3121
 
3122
    /* LDO and integer loads/stores with 14 bit displacements.  */
3123
    case R_PARISC_DLTREL14R:
3124
    case R_PARISC_DLTREL14F:
3125
    case R_PARISC_DLTIND14R:
3126
    case R_PARISC_DLTIND14F:
3127
    case R_PARISC_LTOFF_FPTR14R:
3128
    case R_PARISC_PCREL14R:
3129
    case R_PARISC_PCREL14F:
3130
    case R_PARISC_LTOFF_TP14R:
3131
    case R_PARISC_LTOFF_TP14F:
3132
    case R_PARISC_DPREL14R:
3133
    case R_PARISC_DPREL14F:
3134
    case R_PARISC_PLTOFF14R:
3135
    case R_PARISC_PLTOFF14F:
3136
    case R_PARISC_DIR14R:
3137
    case R_PARISC_DIR14F:
3138
      return (insn & ~0x3fff) | low_sign_unext (sym_value, 14);
3139
 
3140
    /* PA2.0W LDO and integer loads/stores with 16 bit displacements.  */
3141
    case R_PARISC_LTOFF_FPTR16F:
3142
    case R_PARISC_PCREL16F:
3143
    case R_PARISC_LTOFF_TP16F:
3144
    case R_PARISC_GPREL16F:
3145
    case R_PARISC_PLTOFF16F:
3146
    case R_PARISC_DIR16F:
3147
    case R_PARISC_LTOFF16F:
3148
      return (insn & ~0xffff) | re_assemble_16 (sym_value);
3149
 
3150
    /* Doubleword loads and stores with a 14 bit displacement.  */
3151
    case R_PARISC_DLTREL14DR:
3152
    case R_PARISC_DLTIND14DR:
3153
    case R_PARISC_LTOFF_FPTR14DR:
3154
    case R_PARISC_LTOFF_FPTR16DF:
3155
    case R_PARISC_PCREL14DR:
3156
    case R_PARISC_PCREL16DF:
3157
    case R_PARISC_LTOFF_TP14DR:
3158
    case R_PARISC_LTOFF_TP16DF:
3159
    case R_PARISC_DPREL14DR:
3160
    case R_PARISC_GPREL16DF:
3161
    case R_PARISC_PLTOFF14DR:
3162
    case R_PARISC_PLTOFF16DF:
3163
    case R_PARISC_DIR14DR:
3164
    case R_PARISC_DIR16DF:
3165
    case R_PARISC_LTOFF16DF:
3166
      return (insn & ~0x3ff1) | (((sym_value & 0x2000) >> 13)
3167
                                 | ((sym_value & 0x1ff8) << 1));
3168
 
3169
    /* Floating point single word load/store instructions.  */
3170
    case R_PARISC_DLTREL14WR:
3171
    case R_PARISC_DLTIND14WR:
3172
    case R_PARISC_LTOFF_FPTR14WR:
3173
    case R_PARISC_LTOFF_FPTR16WF:
3174
    case R_PARISC_PCREL14WR:
3175
    case R_PARISC_PCREL16WF:
3176
    case R_PARISC_LTOFF_TP14WR:
3177
    case R_PARISC_LTOFF_TP16WF:
3178
    case R_PARISC_DPREL14WR:
3179
    case R_PARISC_GPREL16WF:
3180
    case R_PARISC_PLTOFF14WR:
3181
    case R_PARISC_PLTOFF16WF:
3182
    case R_PARISC_DIR16WF:
3183
    case R_PARISC_DIR14WR:
3184
    case R_PARISC_LTOFF16WF:
3185
      return (insn & ~0x3ff9) | (((sym_value & 0x2000) >> 13)
3186
                                 | ((sym_value & 0x1ffc) << 1));
3187
 
3188
    default:
3189
      return insn;
3190
    }
3191
}
3192
 
3193
/* Compute the value for a relocation (REL) during a final link stage,
3194
   then insert the value into the proper location in CONTENTS.
3195
 
3196
   VALUE is a tentative value for the relocation and may be overridden
3197
   and modified here based on the specific relocation to be performed.
3198
 
3199
   For example we do conversions for PC-relative branches in this routine
3200
   or redirection of calls to external routines to stubs.
3201
 
3202
   The work of actually applying the relocation is left to a helper
3203
   routine in an attempt to reduce the complexity and size of this
3204
   function.  */
3205
 
3206
static bfd_reloc_status_type
3207
elf_hppa_final_link_relocate (Elf_Internal_Rela *rel,
3208
                              bfd *input_bfd,
3209
                              bfd *output_bfd,
3210
                              asection *input_section,
3211
                              bfd_byte *contents,
3212
                              bfd_vma value,
3213
                              struct bfd_link_info *info,
3214
                              asection *sym_sec,
3215
                              struct elf_link_hash_entry *eh)
3216
{
3217
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3218
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
3219
  bfd_vma *local_offsets;
3220
  Elf_Internal_Shdr *symtab_hdr;
3221
  int insn;
3222
  bfd_vma max_branch_offset = 0;
3223
  bfd_vma offset = rel->r_offset;
3224
  bfd_signed_vma addend = rel->r_addend;
3225
  reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
3226
  unsigned int r_symndx = ELF_R_SYM (rel->r_info);
3227
  unsigned int r_type = howto->type;
3228
  bfd_byte *hit_data = contents + offset;
3229
 
3230
  if (hppa_info == NULL)
3231
    return bfd_reloc_notsupported;
3232
 
3233
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3234
  local_offsets = elf_local_got_offsets (input_bfd);
3235
  insn = bfd_get_32 (input_bfd, hit_data);
3236
 
3237
  switch (r_type)
3238
    {
3239
    case R_PARISC_NONE:
3240
      break;
3241
 
3242
    /* Basic function call support.
3243
 
3244
       Note for a call to a function defined in another dynamic library
3245
       we want to redirect the call to a stub.  */
3246
 
3247
    /* PC relative relocs without an implicit offset.  */
3248
    case R_PARISC_PCREL21L:
3249
    case R_PARISC_PCREL14R:
3250
    case R_PARISC_PCREL14F:
3251
    case R_PARISC_PCREL14WR:
3252
    case R_PARISC_PCREL14DR:
3253
    case R_PARISC_PCREL16F:
3254
    case R_PARISC_PCREL16WF:
3255
    case R_PARISC_PCREL16DF:
3256
      {
3257
        /* If this is a call to a function defined in another dynamic
3258
           library, then redirect the call to the local stub for this
3259
           function.  */
3260
        if (sym_sec == NULL || sym_sec->output_section == NULL)
3261
          value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3262
                   + hppa_info->stub_sec->output_section->vma);
3263
 
3264
        /* Turn VALUE into a proper PC relative address.  */
3265
        value -= (offset + input_section->output_offset
3266
                  + input_section->output_section->vma);
3267
 
3268
        /* Adjust for any field selectors.  */
3269
        if (r_type == R_PARISC_PCREL21L)
3270
          value = hppa_field_adjust (value, -8 + addend, e_lsel);
3271
        else if (r_type == R_PARISC_PCREL14F
3272
                 || r_type == R_PARISC_PCREL16F
3273
                 || r_type == R_PARISC_PCREL16WF
3274
                 || r_type == R_PARISC_PCREL16DF)
3275
          value = hppa_field_adjust (value, -8 + addend, e_fsel);
3276
        else
3277
          value = hppa_field_adjust (value, -8 + addend, e_rsel);
3278
 
3279
        /* Apply the relocation to the given instruction.  */
3280
        insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3281
        break;
3282
      }
3283
 
3284
    case R_PARISC_PCREL12F:
3285
    case R_PARISC_PCREL22F:
3286
    case R_PARISC_PCREL17F:
3287
    case R_PARISC_PCREL22C:
3288
    case R_PARISC_PCREL17C:
3289
    case R_PARISC_PCREL17R:
3290
      {
3291
        /* If this is a call to a function defined in another dynamic
3292
           library, then redirect the call to the local stub for this
3293
           function.  */
3294
        if (sym_sec == NULL || sym_sec->output_section == NULL)
3295
          value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3296
                   + hppa_info->stub_sec->output_section->vma);
3297
 
3298
        /* Turn VALUE into a proper PC relative address.  */
3299
        value -= (offset + input_section->output_offset
3300
                  + input_section->output_section->vma);
3301
        addend -= 8;
3302
 
3303
        if (r_type == (unsigned int) R_PARISC_PCREL22F)
3304
          max_branch_offset = (1 << (22-1)) << 2;
3305
        else if (r_type == (unsigned int) R_PARISC_PCREL17F)
3306
          max_branch_offset = (1 << (17-1)) << 2;
3307
        else if (r_type == (unsigned int) R_PARISC_PCREL12F)
3308
          max_branch_offset = (1 << (12-1)) << 2;
3309
 
3310
        /* Make sure we can reach the branch target.  */
3311
        if (max_branch_offset != 0
3312
            && value + addend + max_branch_offset >= 2*max_branch_offset)
3313
          {
3314
            (*_bfd_error_handler)
3315
              (_("%B(%A+0x%lx): cannot reach %s"),
3316
              input_bfd,
3317
              input_section,
3318
              offset,
3319
              eh->root.root.string);
3320
            bfd_set_error (bfd_error_bad_value);
3321
            return bfd_reloc_notsupported;
3322
          }
3323
 
3324
        /* Adjust for any field selectors.  */
3325
        if (r_type == R_PARISC_PCREL17R)
3326
          value = hppa_field_adjust (value, addend, e_rsel);
3327
        else
3328
          value = hppa_field_adjust (value, addend, e_fsel);
3329
 
3330
        /* All branches are implicitly shifted by 2 places.  */
3331
        value >>= 2;
3332
 
3333
        /* Apply the relocation to the given instruction.  */
3334
        insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3335
        break;
3336
      }
3337
 
3338
    /* Indirect references to data through the DLT.  */
3339
    case R_PARISC_DLTIND14R:
3340
    case R_PARISC_DLTIND14F:
3341
    case R_PARISC_DLTIND14DR:
3342
    case R_PARISC_DLTIND14WR:
3343
    case R_PARISC_DLTIND21L:
3344
    case R_PARISC_LTOFF_FPTR14R:
3345
    case R_PARISC_LTOFF_FPTR14DR:
3346
    case R_PARISC_LTOFF_FPTR14WR:
3347
    case R_PARISC_LTOFF_FPTR21L:
3348
    case R_PARISC_LTOFF_FPTR16F:
3349
    case R_PARISC_LTOFF_FPTR16WF:
3350
    case R_PARISC_LTOFF_FPTR16DF:
3351
    case R_PARISC_LTOFF_TP21L:
3352
    case R_PARISC_LTOFF_TP14R:
3353
    case R_PARISC_LTOFF_TP14F:
3354
    case R_PARISC_LTOFF_TP14WR:
3355
    case R_PARISC_LTOFF_TP14DR:
3356
    case R_PARISC_LTOFF_TP16F:
3357
    case R_PARISC_LTOFF_TP16WF:
3358
    case R_PARISC_LTOFF_TP16DF:
3359
    case R_PARISC_LTOFF16F:
3360
    case R_PARISC_LTOFF16WF:
3361
    case R_PARISC_LTOFF16DF:
3362
      {
3363
        bfd_vma off;
3364
 
3365
        /* If this relocation was against a local symbol, then we still
3366
           have not set up the DLT entry (it's not convenient to do so
3367
           in the "finalize_dlt" routine because it is difficult to get
3368
           to the local symbol's value).
3369
 
3370
           So, if this is a local symbol (h == NULL), then we need to
3371
           fill in its DLT entry.
3372
 
3373
           Similarly we may still need to set up an entry in .opd for
3374
           a local function which had its address taken.  */
3375
        if (hh == NULL)
3376
          {
3377
            bfd_vma *local_opd_offsets, *local_dlt_offsets;
3378
 
3379
            if (local_offsets == NULL)
3380
              abort ();
3381
 
3382
            /* Now do .opd creation if needed.  */
3383
            if (r_type == R_PARISC_LTOFF_FPTR14R
3384
                || r_type == R_PARISC_LTOFF_FPTR14DR
3385
                || r_type == R_PARISC_LTOFF_FPTR14WR
3386
                || r_type == R_PARISC_LTOFF_FPTR21L
3387
                || r_type == R_PARISC_LTOFF_FPTR16F
3388
                || r_type == R_PARISC_LTOFF_FPTR16WF
3389
                || r_type == R_PARISC_LTOFF_FPTR16DF)
3390
              {
3391
                local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
3392
                off = local_opd_offsets[r_symndx];
3393
 
3394
                /* The last bit records whether we've already initialised
3395
                   this local .opd entry.  */
3396
                if ((off & 1) != 0)
3397
                  {
3398
                    BFD_ASSERT (off != (bfd_vma) -1);
3399
                    off &= ~1;
3400
                  }
3401
                else
3402
                  {
3403
                    local_opd_offsets[r_symndx] |= 1;
3404
 
3405
                    /* The first two words of an .opd entry are zero.  */
3406
                    memset (hppa_info->opd_sec->contents + off, 0, 16);
3407
 
3408
                    /* The next word is the address of the function.  */
3409
                    bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3410
                                (hppa_info->opd_sec->contents + off + 16));
3411
 
3412
                    /* The last word is our local __gp value.  */
3413
                    value = _bfd_get_gp_value
3414
                              (hppa_info->opd_sec->output_section->owner);
3415
                    bfd_put_64 (hppa_info->opd_sec->owner, value,
3416
                                (hppa_info->opd_sec->contents + off + 24));
3417
                  }
3418
 
3419
                /* The DLT value is the address of the .opd entry.  */
3420
                value = (off
3421
                         + hppa_info->opd_sec->output_offset
3422
                         + hppa_info->opd_sec->output_section->vma);
3423
                addend = 0;
3424
              }
3425
 
3426
            local_dlt_offsets = local_offsets;
3427
            off = local_dlt_offsets[r_symndx];
3428
 
3429
            if ((off & 1) != 0)
3430
              {
3431
                BFD_ASSERT (off != (bfd_vma) -1);
3432
                off &= ~1;
3433
              }
3434
            else
3435
              {
3436
                local_dlt_offsets[r_symndx] |= 1;
3437
                bfd_put_64 (hppa_info->dlt_sec->owner,
3438
                            value + addend,
3439
                            hppa_info->dlt_sec->contents + off);
3440
              }
3441
          }
3442
        else
3443
          off = hh->dlt_offset;
3444
 
3445
        /* We want the value of the DLT offset for this symbol, not
3446
           the symbol's actual address.  Note that __gp may not point
3447
           to the start of the DLT, so we have to compute the absolute
3448
           address, then subtract out the value of __gp.  */
3449
        value = (off
3450
                 + hppa_info->dlt_sec->output_offset
3451
                 + hppa_info->dlt_sec->output_section->vma);
3452
        value -= _bfd_get_gp_value (output_bfd);
3453
 
3454
        /* All DLTIND relocations are basically the same at this point,
3455
           except that we need different field selectors for the 21bit
3456
           version vs the 14bit versions.  */
3457
        if (r_type == R_PARISC_DLTIND21L
3458
            || r_type == R_PARISC_LTOFF_FPTR21L
3459
            || r_type == R_PARISC_LTOFF_TP21L)
3460
          value = hppa_field_adjust (value, 0, e_lsel);
3461
        else if (r_type == R_PARISC_DLTIND14F
3462
                 || r_type == R_PARISC_LTOFF_FPTR16F
3463
                 || r_type == R_PARISC_LTOFF_FPTR16WF
3464
                 || r_type == R_PARISC_LTOFF_FPTR16DF
3465
                 || r_type == R_PARISC_LTOFF16F
3466
                 || r_type == R_PARISC_LTOFF16DF
3467
                 || r_type == R_PARISC_LTOFF16WF
3468
                 || r_type == R_PARISC_LTOFF_TP16F
3469
                 || r_type == R_PARISC_LTOFF_TP16WF
3470
                 || r_type == R_PARISC_LTOFF_TP16DF)
3471
          value = hppa_field_adjust (value, 0, e_fsel);
3472
        else
3473
          value = hppa_field_adjust (value, 0, e_rsel);
3474
 
3475
        insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3476
        break;
3477
      }
3478
 
3479
    case R_PARISC_DLTREL14R:
3480
    case R_PARISC_DLTREL14F:
3481
    case R_PARISC_DLTREL14DR:
3482
    case R_PARISC_DLTREL14WR:
3483
    case R_PARISC_DLTREL21L:
3484
    case R_PARISC_DPREL21L:
3485
    case R_PARISC_DPREL14WR:
3486
    case R_PARISC_DPREL14DR:
3487
    case R_PARISC_DPREL14R:
3488
    case R_PARISC_DPREL14F:
3489
    case R_PARISC_GPREL16F:
3490
    case R_PARISC_GPREL16WF:
3491
    case R_PARISC_GPREL16DF:
3492
      {
3493
        /* Subtract out the global pointer value to make value a DLT
3494
           relative address.  */
3495
        value -= _bfd_get_gp_value (output_bfd);
3496
 
3497
        /* All DLTREL relocations are basically the same at this point,
3498
           except that we need different field selectors for the 21bit
3499
           version vs the 14bit versions.  */
3500
        if (r_type == R_PARISC_DLTREL21L
3501
            || r_type == R_PARISC_DPREL21L)
3502
          value = hppa_field_adjust (value, addend, e_lrsel);
3503
        else if (r_type == R_PARISC_DLTREL14F
3504
                 || r_type == R_PARISC_DPREL14F
3505
                 || r_type == R_PARISC_GPREL16F
3506
                 || r_type == R_PARISC_GPREL16WF
3507
                 || r_type == R_PARISC_GPREL16DF)
3508
          value = hppa_field_adjust (value, addend, e_fsel);
3509
        else
3510
          value = hppa_field_adjust (value, addend, e_rrsel);
3511
 
3512
        insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3513
        break;
3514
      }
3515
 
3516
    case R_PARISC_DIR21L:
3517
    case R_PARISC_DIR17R:
3518
    case R_PARISC_DIR17F:
3519
    case R_PARISC_DIR14R:
3520
    case R_PARISC_DIR14F:
3521
    case R_PARISC_DIR14WR:
3522
    case R_PARISC_DIR14DR:
3523
    case R_PARISC_DIR16F:
3524
    case R_PARISC_DIR16WF:
3525
    case R_PARISC_DIR16DF:
3526
      {
3527
        /* All DIR relocations are basically the same at this point,
3528
           except that branch offsets need to be divided by four, and
3529
           we need different field selectors.  Note that we don't
3530
           redirect absolute calls to local stubs.  */
3531
 
3532
        if (r_type == R_PARISC_DIR21L)
3533
          value = hppa_field_adjust (value, addend, e_lrsel);
3534
        else if (r_type == R_PARISC_DIR17F
3535
                 || r_type == R_PARISC_DIR16F
3536
                 || r_type == R_PARISC_DIR16WF
3537
                 || r_type == R_PARISC_DIR16DF
3538
                 || r_type == R_PARISC_DIR14F)
3539
          value = hppa_field_adjust (value, addend, e_fsel);
3540
        else
3541
          value = hppa_field_adjust (value, addend, e_rrsel);
3542
 
3543
        if (r_type == R_PARISC_DIR17R || r_type == R_PARISC_DIR17F)
3544
          /* All branches are implicitly shifted by 2 places.  */
3545
          value >>= 2;
3546
 
3547
        insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3548
        break;
3549
      }
3550
 
3551
    case R_PARISC_PLTOFF21L:
3552
    case R_PARISC_PLTOFF14R:
3553
    case R_PARISC_PLTOFF14F:
3554
    case R_PARISC_PLTOFF14WR:
3555
    case R_PARISC_PLTOFF14DR:
3556
    case R_PARISC_PLTOFF16F:
3557
    case R_PARISC_PLTOFF16WF:
3558
    case R_PARISC_PLTOFF16DF:
3559
      {
3560
        /* We want the value of the PLT offset for this symbol, not
3561
           the symbol's actual address.  Note that __gp may not point
3562
           to the start of the DLT, so we have to compute the absolute
3563
           address, then subtract out the value of __gp.  */
3564
        value = (hh->plt_offset
3565
                 + hppa_info->plt_sec->output_offset
3566
                 + hppa_info->plt_sec->output_section->vma);
3567
        value -= _bfd_get_gp_value (output_bfd);
3568
 
3569
        /* All PLTOFF relocations are basically the same at this point,
3570
           except that we need different field selectors for the 21bit
3571
           version vs the 14bit versions.  */
3572
        if (r_type == R_PARISC_PLTOFF21L)
3573
          value = hppa_field_adjust (value, addend, e_lrsel);
3574
        else if (r_type == R_PARISC_PLTOFF14F
3575
                 || r_type == R_PARISC_PLTOFF16F
3576
                 || r_type == R_PARISC_PLTOFF16WF
3577
                 || r_type == R_PARISC_PLTOFF16DF)
3578
          value = hppa_field_adjust (value, addend, e_fsel);
3579
        else
3580
          value = hppa_field_adjust (value, addend, e_rrsel);
3581
 
3582
        insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3583
        break;
3584
      }
3585
 
3586
    case R_PARISC_LTOFF_FPTR32:
3587
      {
3588
        /* We may still need to create the FPTR itself if it was for
3589
           a local symbol.  */
3590
        if (hh == NULL)
3591
          {
3592
            /* The first two words of an .opd entry are zero.  */
3593
            memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16);
3594
 
3595
            /* The next word is the address of the function.  */
3596
            bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3597
                        (hppa_info->opd_sec->contents
3598
                         + hh->opd_offset + 16));
3599
 
3600
            /* The last word is our local __gp value.  */
3601
            value = _bfd_get_gp_value
3602
                      (hppa_info->opd_sec->output_section->owner);
3603
            bfd_put_64 (hppa_info->opd_sec->owner, value,
3604
                        hppa_info->opd_sec->contents + hh->opd_offset + 24);
3605
 
3606
            /* The DLT value is the address of the .opd entry.  */
3607
            value = (hh->opd_offset
3608
                     + hppa_info->opd_sec->output_offset
3609
                     + hppa_info->opd_sec->output_section->vma);
3610
 
3611
            bfd_put_64 (hppa_info->dlt_sec->owner,
3612
                        value,
3613
                        hppa_info->dlt_sec->contents + hh->dlt_offset);
3614
          }
3615
 
3616
        /* We want the value of the DLT offset for this symbol, not
3617
           the symbol's actual address.  Note that __gp may not point
3618
           to the start of the DLT, so we have to compute the absolute
3619
           address, then subtract out the value of __gp.  */
3620
        value = (hh->dlt_offset
3621
                 + hppa_info->dlt_sec->output_offset
3622
                 + hppa_info->dlt_sec->output_section->vma);
3623
        value -= _bfd_get_gp_value (output_bfd);
3624
        bfd_put_32 (input_bfd, value, hit_data);
3625
        return bfd_reloc_ok;
3626
      }
3627
 
3628
    case R_PARISC_LTOFF_FPTR64:
3629
    case R_PARISC_LTOFF_TP64:
3630
      {
3631
        /* We may still need to create the FPTR itself if it was for
3632
           a local symbol.  */
3633
        if (eh == NULL && r_type == R_PARISC_LTOFF_FPTR64)
3634
          {
3635
            /* The first two words of an .opd entry are zero.  */
3636
            memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16);
3637
 
3638
            /* The next word is the address of the function.  */
3639
            bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3640
                        (hppa_info->opd_sec->contents
3641
                         + hh->opd_offset + 16));
3642
 
3643
            /* The last word is our local __gp value.  */
3644
            value = _bfd_get_gp_value
3645
                      (hppa_info->opd_sec->output_section->owner);
3646
            bfd_put_64 (hppa_info->opd_sec->owner, value,
3647
                        hppa_info->opd_sec->contents + hh->opd_offset + 24);
3648
 
3649
            /* The DLT value is the address of the .opd entry.  */
3650
            value = (hh->opd_offset
3651
                     + hppa_info->opd_sec->output_offset
3652
                     + hppa_info->opd_sec->output_section->vma);
3653
 
3654
            bfd_put_64 (hppa_info->dlt_sec->owner,
3655
                        value,
3656
                        hppa_info->dlt_sec->contents + hh->dlt_offset);
3657
          }
3658
 
3659
        /* We want the value of the DLT offset for this symbol, not
3660
           the symbol's actual address.  Note that __gp may not point
3661
           to the start of the DLT, so we have to compute the absolute
3662
           address, then subtract out the value of __gp.  */
3663
        value = (hh->dlt_offset
3664
                 + hppa_info->dlt_sec->output_offset
3665
                 + hppa_info->dlt_sec->output_section->vma);
3666
        value -= _bfd_get_gp_value (output_bfd);
3667
        bfd_put_64 (input_bfd, value, hit_data);
3668
        return bfd_reloc_ok;
3669
      }
3670
 
3671
    case R_PARISC_DIR32:
3672
      bfd_put_32 (input_bfd, value + addend, hit_data);
3673
      return bfd_reloc_ok;
3674
 
3675
    case R_PARISC_DIR64:
3676
      bfd_put_64 (input_bfd, value + addend, hit_data);
3677
      return bfd_reloc_ok;
3678
 
3679
    case R_PARISC_GPREL64:
3680
      /* Subtract out the global pointer value to make value a DLT
3681
         relative address.  */
3682
      value -= _bfd_get_gp_value (output_bfd);
3683
 
3684
      bfd_put_64 (input_bfd, value + addend, hit_data);
3685
      return bfd_reloc_ok;
3686
 
3687
    case R_PARISC_LTOFF64:
3688
        /* We want the value of the DLT offset for this symbol, not
3689
           the symbol's actual address.  Note that __gp may not point
3690
           to the start of the DLT, so we have to compute the absolute
3691
           address, then subtract out the value of __gp.  */
3692
      value = (hh->dlt_offset
3693
               + hppa_info->dlt_sec->output_offset
3694
               + hppa_info->dlt_sec->output_section->vma);
3695
      value -= _bfd_get_gp_value (output_bfd);
3696
 
3697
      bfd_put_64 (input_bfd, value + addend, hit_data);
3698
      return bfd_reloc_ok;
3699
 
3700
    case R_PARISC_PCREL32:
3701
      {
3702
        /* If this is a call to a function defined in another dynamic
3703
           library, then redirect the call to the local stub for this
3704
           function.  */
3705
        if (sym_sec == NULL || sym_sec->output_section == NULL)
3706
          value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3707
                   + hppa_info->stub_sec->output_section->vma);
3708
 
3709
        /* Turn VALUE into a proper PC relative address.  */
3710
        value -= (offset + input_section->output_offset
3711
                  + input_section->output_section->vma);
3712
 
3713
        value += addend;
3714
        value -= 8;
3715
        bfd_put_32 (input_bfd, value, hit_data);
3716
        return bfd_reloc_ok;
3717
      }
3718
 
3719
    case R_PARISC_PCREL64:
3720
      {
3721
        /* If this is a call to a function defined in another dynamic
3722
           library, then redirect the call to the local stub for this
3723
           function.  */
3724
        if (sym_sec == NULL || sym_sec->output_section == NULL)
3725
          value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3726
                   + hppa_info->stub_sec->output_section->vma);
3727
 
3728
        /* Turn VALUE into a proper PC relative address.  */
3729
        value -= (offset + input_section->output_offset
3730
                  + input_section->output_section->vma);
3731
 
3732
        value += addend;
3733
        value -= 8;
3734
        bfd_put_64 (input_bfd, value, hit_data);
3735
        return bfd_reloc_ok;
3736
      }
3737
 
3738
    case R_PARISC_FPTR64:
3739
      {
3740
        bfd_vma off;
3741
 
3742
        /* We may still need to create the FPTR itself if it was for
3743
           a local symbol.  */
3744
        if (hh == NULL)
3745
          {
3746
            bfd_vma *local_opd_offsets;
3747
 
3748
            if (local_offsets == NULL)
3749
              abort ();
3750
 
3751
            local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
3752
            off = local_opd_offsets[r_symndx];
3753
 
3754
            /* The last bit records whether we've already initialised
3755
               this local .opd entry.  */
3756
            if ((off & 1) != 0)
3757
              {
3758
                BFD_ASSERT (off != (bfd_vma) -1);
3759
                off &= ~1;
3760
              }
3761
            else
3762
              {
3763
                /* The first two words of an .opd entry are zero.  */
3764
                memset (hppa_info->opd_sec->contents + off, 0, 16);
3765
 
3766
                /* The next word is the address of the function.  */
3767
                bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3768
                            (hppa_info->opd_sec->contents + off + 16));
3769
 
3770
                /* The last word is our local __gp value.  */
3771
                value = _bfd_get_gp_value
3772
                          (hppa_info->opd_sec->output_section->owner);
3773
                bfd_put_64 (hppa_info->opd_sec->owner, value,
3774
                            hppa_info->opd_sec->contents + off + 24);
3775
              }
3776
          }
3777
        else
3778
          off = hh->opd_offset;
3779
 
3780
        if (hh == NULL || hh->want_opd)
3781
          /* We want the value of the OPD offset for this symbol.  */
3782
          value = (off
3783
                   + hppa_info->opd_sec->output_offset
3784
                   + hppa_info->opd_sec->output_section->vma);
3785
        else
3786
          /* We want the address of the symbol.  */
3787
          value += addend;
3788
 
3789
        bfd_put_64 (input_bfd, value, hit_data);
3790
        return bfd_reloc_ok;
3791
      }
3792
 
3793
    case R_PARISC_SECREL32:
3794
      if (sym_sec)
3795
        value -= sym_sec->output_section->vma;
3796
      bfd_put_32 (input_bfd, value + addend, hit_data);
3797
      return bfd_reloc_ok;
3798
 
3799
    case R_PARISC_SEGREL32:
3800
    case R_PARISC_SEGREL64:
3801
      {
3802
        /* If this is the first SEGREL relocation, then initialize
3803
           the segment base values.  */
3804
        if (hppa_info->text_segment_base == (bfd_vma) -1)
3805
          bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs,
3806
                                 hppa_info);
3807
 
3808
        /* VALUE holds the absolute address.  We want to include the
3809
           addend, then turn it into a segment relative address.
3810
 
3811
           The segment is derived from SYM_SEC.  We assume that there are
3812
           only two segments of note in the resulting executable/shlib.
3813
           A readonly segment (.text) and a readwrite segment (.data).  */
3814
        value += addend;
3815
 
3816
        if (sym_sec->flags & SEC_CODE)
3817
          value -= hppa_info->text_segment_base;
3818
        else
3819
          value -= hppa_info->data_segment_base;
3820
 
3821
        if (r_type == R_PARISC_SEGREL32)
3822
          bfd_put_32 (input_bfd, value, hit_data);
3823
        else
3824
          bfd_put_64 (input_bfd, value, hit_data);
3825
        return bfd_reloc_ok;
3826
      }
3827
 
3828
    /* Something we don't know how to handle.  */
3829
    default:
3830
      return bfd_reloc_notsupported;
3831
    }
3832
 
3833
  /* Update the instruction word.  */
3834
  bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data);
3835
  return bfd_reloc_ok;
3836
}
3837
 
3838
/* Relocate an HPPA ELF section.  */
3839
 
3840
static bfd_boolean
3841
elf64_hppa_relocate_section (bfd *output_bfd,
3842
                           struct bfd_link_info *info,
3843
                           bfd *input_bfd,
3844
                           asection *input_section,
3845
                           bfd_byte *contents,
3846
                           Elf_Internal_Rela *relocs,
3847
                           Elf_Internal_Sym *local_syms,
3848
                           asection **local_sections)
3849
{
3850
  Elf_Internal_Shdr *symtab_hdr;
3851
  Elf_Internal_Rela *rel;
3852
  Elf_Internal_Rela *relend;
3853
  struct elf64_hppa_link_hash_table *hppa_info;
3854
 
3855
  hppa_info = hppa_link_hash_table (info);
3856
  if (hppa_info == NULL)
3857
    return FALSE;
3858
 
3859
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3860
 
3861
  rel = relocs;
3862
  relend = relocs + input_section->reloc_count;
3863
  for (; rel < relend; rel++)
3864
    {
3865
      int r_type;
3866
      reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
3867
      unsigned long r_symndx;
3868
      struct elf_link_hash_entry *eh;
3869
      Elf_Internal_Sym *sym;
3870
      asection *sym_sec;
3871
      bfd_vma relocation;
3872
      bfd_reloc_status_type r;
3873
      bfd_boolean warned_undef;
3874
 
3875
      r_type = ELF_R_TYPE (rel->r_info);
3876
      if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED)
3877
        {
3878
          bfd_set_error (bfd_error_bad_value);
3879
          return FALSE;
3880
        }
3881
      if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
3882
          || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT)
3883
        continue;
3884
 
3885
      /* This is a final link.  */
3886
      r_symndx = ELF_R_SYM (rel->r_info);
3887
      eh = NULL;
3888
      sym = NULL;
3889
      sym_sec = NULL;
3890
      warned_undef = FALSE;
3891
      if (r_symndx < symtab_hdr->sh_info)
3892
        {
3893
          /* This is a local symbol, hh defaults to NULL.  */
3894
          sym = local_syms + r_symndx;
3895
          sym_sec = local_sections[r_symndx];
3896
          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel);
3897
        }
3898
      else
3899
        {
3900
          /* This is not a local symbol.  */
3901
          bfd_boolean unresolved_reloc;
3902
          struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
3903
 
3904
          /* It seems this can happen with erroneous or unsupported
3905
             input (mixing a.out and elf in an archive, for example.)  */
3906
          if (sym_hashes == NULL)
3907
            return FALSE;
3908
 
3909
          eh = sym_hashes[r_symndx - symtab_hdr->sh_info];
3910
 
3911
          while (eh->root.type == bfd_link_hash_indirect
3912
                 || eh->root.type == bfd_link_hash_warning)
3913
            eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
3914
 
3915
          warned_undef = FALSE;
3916
          unresolved_reloc = FALSE;
3917
          relocation = 0;
3918
          if (eh->root.type == bfd_link_hash_defined
3919
              || eh->root.type == bfd_link_hash_defweak)
3920
            {
3921
              sym_sec = eh->root.u.def.section;
3922
              if (sym_sec == NULL
3923
                  || sym_sec->output_section == NULL)
3924
                /* Set a flag that will be cleared later if we find a
3925
                   relocation value for this symbol.  output_section
3926
                   is typically NULL for symbols satisfied by a shared
3927
                   library.  */
3928
                unresolved_reloc = TRUE;
3929
              else
3930
                relocation = (eh->root.u.def.value
3931
                              + sym_sec->output_section->vma
3932
                              + sym_sec->output_offset);
3933
            }
3934
          else if (eh->root.type == bfd_link_hash_undefweak)
3935
            ;
3936
          else if (info->unresolved_syms_in_objects == RM_IGNORE
3937
                   && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT)
3938
            ;
3939
          else if (!info->relocatable
3940
                   && elf_hppa_is_dynamic_loader_symbol (eh->root.root.string))
3941
            continue;
3942
          else if (!info->relocatable)
3943
            {
3944
              bfd_boolean err;
3945
              err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
3946
                     || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT);
3947
              if (!info->callbacks->undefined_symbol (info,
3948
                                                      eh->root.root.string,
3949
                                                      input_bfd,
3950
                                                      input_section,
3951
                                                      rel->r_offset, err))
3952
                return FALSE;
3953
              warned_undef = TRUE;
3954
            }
3955
 
3956
          if (!info->relocatable
3957
              && relocation == 0
3958
              && eh->root.type != bfd_link_hash_defined
3959
              && eh->root.type != bfd_link_hash_defweak
3960
              && eh->root.type != bfd_link_hash_undefweak)
3961
            {
3962
              if (info->unresolved_syms_in_objects == RM_IGNORE
3963
                  && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT
3964
                  && eh->type == STT_PARISC_MILLI)
3965
                {
3966
                  if (! info->callbacks->undefined_symbol
3967
                      (info, eh_name (eh), input_bfd,
3968
                       input_section, rel->r_offset, FALSE))
3969
                    return FALSE;
3970
                  warned_undef = TRUE;
3971
                }
3972
            }
3973
        }
3974
 
3975
      if (sym_sec != NULL && elf_discarded_section (sym_sec))
3976
        {
3977
          /* For relocs against symbols from removed linkonce sections,
3978
             or sections discarded by a linker script, we just want the
3979
             section contents zeroed.  Avoid any special processing.  */
3980
          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
3981
          rel->r_info = 0;
3982
          rel->r_addend = 0;
3983
          continue;
3984
        }
3985
 
3986
      if (info->relocatable)
3987
        continue;
3988
 
3989
      r = elf_hppa_final_link_relocate (rel, input_bfd, output_bfd,
3990
                                        input_section, contents,
3991
                                        relocation, info, sym_sec,
3992
                                        eh);
3993
 
3994
      if (r != bfd_reloc_ok)
3995
        {
3996
          switch (r)
3997
            {
3998
            default:
3999
              abort ();
4000
            case bfd_reloc_overflow:
4001
              {
4002
                const char *sym_name;
4003
 
4004
                if (eh != NULL)
4005
                  sym_name = NULL;
4006
                else
4007
                  {
4008
                    sym_name = bfd_elf_string_from_elf_section (input_bfd,
4009
                                                                symtab_hdr->sh_link,
4010
                                                                sym->st_name);
4011
                    if (sym_name == NULL)
4012
                      return FALSE;
4013
                    if (*sym_name == '\0')
4014
                      sym_name = bfd_section_name (input_bfd, sym_sec);
4015
                  }
4016
 
4017
                if (!((*info->callbacks->reloc_overflow)
4018
                      (info, (eh ? &eh->root : NULL), sym_name,
4019
                       howto->name, (bfd_vma) 0, input_bfd,
4020
                       input_section, rel->r_offset)))
4021
                  return FALSE;
4022
              }
4023
              break;
4024
            }
4025
        }
4026
    }
4027
  return TRUE;
4028
}
4029
 
4030
static const struct bfd_elf_special_section elf64_hppa_special_sections[] =
4031
{
4032
  { STRING_COMMA_LEN (".fini"),  0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4033
  { STRING_COMMA_LEN (".init"),  0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4034
  { STRING_COMMA_LEN (".plt"),   0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4035
  { STRING_COMMA_LEN (".dlt"),   0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4036
  { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4037
  { STRING_COMMA_LEN (".sbss"),  0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4038
  { STRING_COMMA_LEN (".tbss"),  0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS },
4039
  { NULL,                    0,  0, 0,            0 }
4040
};
4041
 
4042
/* The hash bucket size is the standard one, namely 4.  */
4043
 
4044
const struct elf_size_info hppa64_elf_size_info =
4045
{
4046
  sizeof (Elf64_External_Ehdr),
4047
  sizeof (Elf64_External_Phdr),
4048
  sizeof (Elf64_External_Shdr),
4049
  sizeof (Elf64_External_Rel),
4050
  sizeof (Elf64_External_Rela),
4051
  sizeof (Elf64_External_Sym),
4052
  sizeof (Elf64_External_Dyn),
4053
  sizeof (Elf_External_Note),
4054
  4,
4055
  1,
4056
  64, 3,
4057
  ELFCLASS64, EV_CURRENT,
4058
  bfd_elf64_write_out_phdrs,
4059
  bfd_elf64_write_shdrs_and_ehdr,
4060
  bfd_elf64_checksum_contents,
4061
  bfd_elf64_write_relocs,
4062
  bfd_elf64_swap_symbol_in,
4063
  bfd_elf64_swap_symbol_out,
4064
  bfd_elf64_slurp_reloc_table,
4065
  bfd_elf64_slurp_symbol_table,
4066
  bfd_elf64_swap_dyn_in,
4067
  bfd_elf64_swap_dyn_out,
4068
  bfd_elf64_swap_reloc_in,
4069
  bfd_elf64_swap_reloc_out,
4070
  bfd_elf64_swap_reloca_in,
4071
  bfd_elf64_swap_reloca_out
4072
};
4073
 
4074
#define TARGET_BIG_SYM                  bfd_elf64_hppa_vec
4075
#define TARGET_BIG_NAME                 "elf64-hppa"
4076
#define ELF_ARCH                        bfd_arch_hppa
4077
#define ELF_MACHINE_CODE                EM_PARISC
4078
/* This is not strictly correct.  The maximum page size for PA2.0 is
4079
   64M.  But everything still uses 4k.  */
4080
#define ELF_MAXPAGESIZE                 0x1000
4081
#define ELF_OSABI                       ELFOSABI_HPUX
4082
 
4083
#define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4084
#define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4085
#define bfd_elf64_bfd_is_local_label_name       elf_hppa_is_local_label_name
4086
#define elf_info_to_howto               elf_hppa_info_to_howto
4087
#define elf_info_to_howto_rel           elf_hppa_info_to_howto_rel
4088
 
4089
#define elf_backend_section_from_shdr   elf64_hppa_section_from_shdr
4090
#define elf_backend_object_p            elf64_hppa_object_p
4091
#define elf_backend_final_write_processing \
4092
                                        elf_hppa_final_write_processing
4093
#define elf_backend_fake_sections       elf_hppa_fake_sections
4094
#define elf_backend_add_symbol_hook     elf_hppa_add_symbol_hook
4095
 
4096
#define elf_backend_relocate_section    elf_hppa_relocate_section
4097
 
4098
#define bfd_elf64_bfd_final_link        elf_hppa_final_link
4099
 
4100
#define elf_backend_create_dynamic_sections \
4101
                                        elf64_hppa_create_dynamic_sections
4102
#define elf_backend_post_process_headers        elf64_hppa_post_process_headers
4103
 
4104
#define elf_backend_omit_section_dynsym \
4105
  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4106
#define elf_backend_adjust_dynamic_symbol \
4107
                                        elf64_hppa_adjust_dynamic_symbol
4108
 
4109
#define elf_backend_size_dynamic_sections \
4110
                                        elf64_hppa_size_dynamic_sections
4111
 
4112
#define elf_backend_finish_dynamic_symbol \
4113
                                        elf64_hppa_finish_dynamic_symbol
4114
#define elf_backend_finish_dynamic_sections \
4115
                                        elf64_hppa_finish_dynamic_sections
4116
#define elf_backend_grok_prstatus       elf64_hppa_grok_prstatus
4117
#define elf_backend_grok_psinfo         elf64_hppa_grok_psinfo
4118
 
4119
/* Stuff for the BFD linker: */
4120
#define bfd_elf64_bfd_link_hash_table_create \
4121
        elf64_hppa_hash_table_create
4122
 
4123
#define elf_backend_check_relocs \
4124
        elf64_hppa_check_relocs
4125
 
4126
#define elf_backend_size_info \
4127
  hppa64_elf_size_info
4128
 
4129
#define elf_backend_additional_program_headers \
4130
        elf64_hppa_additional_program_headers
4131
 
4132
#define elf_backend_modify_segment_map \
4133
        elf64_hppa_modify_segment_map
4134
 
4135
#define elf_backend_link_output_symbol_hook \
4136
        elf64_hppa_link_output_symbol_hook
4137
 
4138
#define elf_backend_want_got_plt        0
4139
#define elf_backend_plt_readonly        0
4140
#define elf_backend_want_plt_sym        0
4141
#define elf_backend_got_header_size     0
4142
#define elf_backend_type_change_ok      TRUE
4143
#define elf_backend_get_symbol_type     elf64_hppa_elf_get_symbol_type
4144
#define elf_backend_reloc_type_class    elf64_hppa_reloc_type_class
4145
#define elf_backend_rela_normal         1
4146
#define elf_backend_special_sections    elf64_hppa_special_sections
4147
#define elf_backend_action_discarded    elf_hppa_action_discarded
4148
#define elf_backend_section_from_phdr   elf64_hppa_section_from_phdr
4149
 
4150
#define elf64_bed                       elf64_hppa_hpux_bed
4151
 
4152
#include "elf64-target.h"
4153
 
4154
#undef TARGET_BIG_SYM
4155
#define TARGET_BIG_SYM                  bfd_elf64_hppa_linux_vec
4156
#undef TARGET_BIG_NAME
4157
#define TARGET_BIG_NAME                 "elf64-hppa-linux"
4158
#undef ELF_OSABI
4159
#define ELF_OSABI                       ELFOSABI_LINUX
4160
#undef elf_backend_post_process_headers
4161
#define elf_backend_post_process_headers _bfd_elf_set_osabi
4162
#undef elf64_bed
4163
#define elf64_bed                       elf64_hppa_linux_bed
4164
 
4165
#include "elf64-target.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.