Coverage Report

Created: 2026-07-25 10:20

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