Coverage Report

Created: 2026-09-14 08:07

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