Coverage Report

Created: 2026-10-02 09:53

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
90
{
311
90
  Elf_Internal_Ehdr * i_ehdrp;
312
90
  unsigned int flags;
313
314
90
  i_ehdrp = elf_elfheader (abfd);
315
90
  if (abfd->xvec == & hppa_elf64_linux_vec)
316
42
    {
317
      /* GCC on hppa-linux produces binaries with OSABI=GNU,
318
   but the kernel produces corefiles with OSABI=SysV.  */
319
42
      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
42
    }
323
48
  else
324
48
    {
325
      /* HPUX produces binaries with OSABI=HPUX,
326
   but the kernel produces corefiles with OSABI=SysV.  */
327
48
      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
48
    }
331
332
90
  flags = i_ehdrp->e_flags;
333
90
  switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
334
90
    {
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
90
    }
347
  /* Don't be fussy.  */
348
62
  return true;
349
90
}
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
24
{
359
24
  switch (hdr->sh_type)
360
24
    {
361
0
    case SHT_PARISC_EXT:
362
0
      if (strcmp (name, ".PARISC.archext") != 0)
363
0
  return false;
364
0
      break;
365
1
    case SHT_PARISC_UNWIND:
366
1
      if (strcmp (name, ".PARISC.unwind") != 0)
367
1
  return false;
368
0
      break;
369
0
    case SHT_PARISC_DOC:
370
0
    case SHT_PARISC_ANNOT:
371
23
    default:
372
23
      return false;
373
24
    }
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
      if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
1685
0
  continue;
1686
1687
0
      for (sec = ibfd->sections; sec != NULL; sec = sec->next)
1688
0
  {
1689
0
    struct elf64_hppa_dyn_reloc_entry *hdh_p;
1690
1691
0
    if (discarded_section (sec))
1692
0
      continue;
1693
1694
0
    for (hdh_p = ((struct elf64_hppa_dyn_reloc_entry *)
1695
0
        elf_section_data (sec)->local_dynrel);
1696
0
         hdh_p != NULL;
1697
0
         hdh_p = hdh_p->next)
1698
0
      {
1699
0
        if (!bfd_is_abs_section (hdh_p->sec)
1700
0
      && bfd_is_abs_section (hdh_p->sec->output_section))
1701
0
    {
1702
      /* Input section has been discarded, either because
1703
         it is a copy of a linkonce section or due to
1704
         linker script /DISCARD/, so we'll be discarding
1705
         the relocs too.  */
1706
0
    }
1707
0
        else if (hdh_p->count != 0)
1708
0
    {
1709
0
      srel = hppa_info->other_rel_sec;
1710
0
      srel->size += hdh_p->count * sizeof (Elf64_External_Rela);
1711
0
      if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0)
1712
0
        info->flags |= DF_TEXTREL;
1713
0
    }
1714
0
      }
1715
0
  }
1716
1717
0
      start_local_dlt = elf_local_got_refcounts (ibfd);
1718
0
      if (!start_local_dlt)
1719
0
  continue;
1720
1721
0
      symtab_hdr = &elf_symtab_hdr (ibfd);
1722
0
      locsymcount = symtab_hdr->sh_info;
1723
1724
0
      end_local_dlt = start_local_dlt + locsymcount;
1725
0
      start_local_plt = end_local_dlt;
1726
0
      end_local_plt = start_local_plt + locsymcount;
1727
0
      start_local_opd = end_local_plt;
1728
0
      end_local_opd = start_local_opd + locsymcount;
1729
1730
0
      sec = hppa_info->dlt_sec;
1731
0
      srel = hppa_info->dlt_rel_sec;
1732
0
      for (local_dlt = start_local_dlt, indx = 0;
1733
0
     local_dlt < end_local_dlt;
1734
0
     ++local_dlt, ++indx)
1735
0
  {
1736
0
    if (*local_dlt > 0)
1737
0
      {
1738
0
        *local_dlt = sec->size;
1739
0
        sec->size += DLT_ENTRY_SIZE;
1740
0
        if (bfd_link_pic (info) || start_local_opd[indx] > 0)
1741
0
    srel->size += sizeof (Elf64_External_Rela);
1742
0
      }
1743
0
    else
1744
0
      *local_dlt = (bfd_vma) -1;
1745
0
  }
1746
1747
0
      if (! hppa_info->root.dynamic_sections_created)
1748
0
  {
1749
    /* Won't be used, but be safe.  */
1750
0
    for (local_plt = start_local_plt;
1751
0
         local_plt < end_local_plt;
1752
0
         ++local_plt)
1753
0
      *local_plt = (bfd_vma) -1;
1754
0
  }
1755
0
      else
1756
0
  {
1757
0
    sec = hppa_info->root.splt;
1758
0
    srel = hppa_info->root.srelplt;
1759
0
    for (local_plt = start_local_plt;
1760
0
         local_plt < end_local_plt;
1761
0
         ++local_plt)
1762
0
      {
1763
0
        if (*local_plt > 0)
1764
0
    {
1765
0
      *local_plt = sec->size;
1766
0
      sec->size += PLT_ENTRY_SIZE;
1767
0
      if (bfd_link_pic (info))
1768
0
        srel->size += sizeof (Elf64_External_Rela);
1769
0
    }
1770
0
        else
1771
0
    *local_plt = (bfd_vma) -1;
1772
0
      }
1773
0
  }
1774
1775
0
      if (! hppa_info->root.dynamic_sections_created)
1776
0
  {
1777
    /* Won't be used, but be safe.  */
1778
0
    for (local_opd = start_local_opd;
1779
0
         local_opd < end_local_opd;
1780
0
         ++local_opd)
1781
0
      *local_opd = (bfd_vma) -1;
1782
0
  }
1783
0
      else
1784
0
  {
1785
0
    sec = hppa_info->opd_sec;
1786
0
    srel = hppa_info->opd_rel_sec;
1787
0
    for (local_opd = start_local_opd;
1788
0
         local_opd < end_local_opd;
1789
0
         ++local_opd)
1790
0
      {
1791
0
        if (*local_opd > 0)
1792
0
    {
1793
0
      if (!sec->size)
1794
0
        sec->size += OPD_ENTRY_SIZE;
1795
0
      *local_opd = sec->size - OPD_ENTRY_SIZE;
1796
0
      sec->size += OPD_ENTRY_SIZE;
1797
1798
      /* We need a EPLT relocation if we are building a
1799
         shared library.  */
1800
0
      if (bfd_link_pic (info))
1801
0
        srel->size += sizeof (Elf64_External_Rela);
1802
0
    }
1803
0
        else
1804
0
    *local_opd = (bfd_vma) -1;
1805
0
      }
1806
0
  }
1807
0
    }
1808
1809
  /* Add __text_seg section symbol to dynamic table.  */
1810
0
  if (hppa_info->root.dynamic_sections_created && !hppa_info->text_hash_entry)
1811
0
    {
1812
0
      asection *s;
1813
1814
0
      s = bfd_get_section_by_name (info->output_bfd, ".dynamic");
1815
0
      if (s == NULL || (s->flags & SEC_CODE) == 0)
1816
0
  s = bfd_get_section_by_name (info->output_bfd, ".text");
1817
0
      if (s != NULL)
1818
0
  {
1819
0
    struct elf_link_hash_entry *nh;
1820
1821
0
    nh = elf_link_hash_lookup (elf_hash_table (info),
1822
0
             "__text_seg", true, false, false);
1823
0
    if (nh != NULL)
1824
0
      {
1825
0
        nh->type = STT_SECTION;
1826
0
        nh->root.type = bfd_link_hash_defined;
1827
0
        nh->root.u.def.value = 0;
1828
0
        nh->root.u.def.section = s;
1829
0
        nh->forced_local = 1;
1830
0
        nh->other = STV_DEFAULT;
1831
0
        bfd_elf_link_record_dynamic_symbol (info, nh);
1832
0
        hppa_info->text_hash_entry = nh;
1833
0
        hppa_info->root.has_local_dynsyms = true;
1834
0
      }
1835
0
  }
1836
0
    }
1837
1838
  /* Add __data_seg section symbol to dynamic table.  */
1839
0
  if (hppa_info->root.dynamic_sections_created && !hppa_info->data_hash_entry)
1840
0
    {
1841
0
      asection *s;
1842
1843
      /* The .data section isn't always present nor is it always the
1844
   first section in the data segment.  It's too early to call
1845
   bfd_map_over_sections, so we assume we don't need any data
1846
   segment relocations when .data is missing.  */
1847
0
      s = bfd_get_section_by_name (info->output_bfd, ".data");
1848
0
      if (s != NULL)
1849
0
  {
1850
0
    struct elf_link_hash_entry *nh;
1851
1852
0
    nh = elf_link_hash_lookup (elf_hash_table (info),
1853
0
             "__data_seg", true, false, false);
1854
0
    if (nh != NULL)
1855
0
      {
1856
0
        nh->type = STT_SECTION;
1857
0
        nh->root.type = bfd_link_hash_defined;
1858
0
        nh->root.u.def.value = 0;
1859
0
        nh->root.u.def.section = s;
1860
0
        nh->forced_local = 1;
1861
0
        nh->other = STV_DEFAULT;
1862
0
        bfd_elf_link_record_dynamic_symbol (info, nh);
1863
0
        hppa_info->data_hash_entry = nh;
1864
0
        hppa_info->root.has_local_dynsyms = true;
1865
0
      }
1866
0
  }
1867
0
    }
1868
1869
  /* Allocate the GOT entries.  */
1870
1871
0
  data.info = info;
1872
0
  if (hppa_info->dlt_sec)
1873
0
    {
1874
0
      data.ofs = hppa_info->dlt_sec->size;
1875
0
      elf_link_hash_traverse (&hppa_info->root,
1876
0
            allocate_global_data_dlt, &data);
1877
0
      hppa_info->dlt_sec->size = data.ofs;
1878
0
    }
1879
1880
0
  if (hppa_info->root.splt)
1881
0
    {
1882
0
      data.ofs = hppa_info->root.splt->size;
1883
0
      elf_link_hash_traverse (&hppa_info->root,
1884
0
            allocate_global_data_plt, &data);
1885
0
      hppa_info->root.splt->size = data.ofs;
1886
0
    }
1887
1888
0
  if (hppa_info->stub_sec)
1889
0
    {
1890
0
      data.ofs = 0x0;
1891
0
      elf_link_hash_traverse (&hppa_info->root,
1892
0
            allocate_global_data_stub, &data);
1893
0
      hppa_info->stub_sec->size = data.ofs;
1894
0
    }
1895
1896
  /* Allocate space for entries in the .opd section.  */
1897
0
  if (hppa_info->opd_sec)
1898
0
    {
1899
0
      data.ofs = hppa_info->opd_sec->size;
1900
0
      elf_link_hash_traverse (&hppa_info->root,
1901
0
            allocate_global_data_opd, &data);
1902
0
      hppa_info->opd_sec->size = data.ofs;
1903
0
    }
1904
1905
  /* Now allocate space for dynamic relocations, if necessary.  */
1906
0
  if (hppa_info->root.dynamic_sections_created)
1907
0
    elf_link_hash_traverse (&hppa_info->root,
1908
0
          allocate_dynrel_entries, &data);
1909
1910
  /* The sizes of all the sections are set.  Allocate memory for them.  */
1911
0
  relocs = false;
1912
0
  for (sec = dynobj->sections; sec != NULL; sec = sec->next)
1913
0
    {
1914
0
      const char *name;
1915
1916
0
      if ((sec->flags & SEC_LINKER_CREATED) == 0)
1917
0
  continue;
1918
1919
      /* It's OK to base decisions on the section name, because none
1920
   of the dynobj section names depend upon the input files.  */
1921
0
      name = bfd_section_name (sec);
1922
1923
0
      if (strcmp (name, ".plt") == 0)
1924
0
  {
1925
    /* Remember whether there is a PLT.  */
1926
0
    ;
1927
0
  }
1928
0
      else if (strcmp (name, ".opd") == 0
1929
0
         || startswith (name, ".dlt")
1930
0
         || strcmp (name, ".stub") == 0
1931
0
         || strcmp (name, ".got") == 0)
1932
0
  {
1933
    /* Strip this section if we don't need it; see the comment below.  */
1934
0
  }
1935
0
      else if (startswith (name, ".rela"))
1936
0
  {
1937
0
    if (sec->size != 0)
1938
0
      {
1939
        /* Remember whether there are any reloc sections other
1940
     than .rela.plt.  */
1941
0
        if (strcmp (name, ".rela.plt") != 0)
1942
0
    relocs = true;
1943
1944
        /* We use the reloc_count field as a counter if we need
1945
     to copy relocs into the output file.  */
1946
0
        sec->reloc_count = 0;
1947
0
      }
1948
0
  }
1949
0
      else
1950
0
  {
1951
    /* It's not one of our sections, so don't allocate space.  */
1952
0
    continue;
1953
0
  }
1954
1955
0
      if (sec->size == 0)
1956
0
  {
1957
    /* If we don't need this section, strip it from the
1958
       output file.  This is mostly to handle .rela.bss and
1959
       .rela.plt.  We must create both sections in
1960
       create_dynamic_sections, because they must be created
1961
       before the linker maps input sections to output
1962
       sections.  The linker does that before
1963
       adjust_dynamic_symbol is called, and it is that
1964
       function which decides whether anything needs to go
1965
       into these sections.  */
1966
0
    sec->flags |= SEC_EXCLUDE;
1967
0
    continue;
1968
0
  }
1969
1970
0
      if ((sec->flags & SEC_HAS_CONTENTS) == 0)
1971
0
  continue;
1972
1973
      /* Allocate memory for the section contents if it has not
1974
   been allocated already.  We use bfd_zalloc here in case
1975
   unused entries are not reclaimed before the section's
1976
   contents are written out.  This should not happen, but this
1977
   way if it does, we get a R_PARISC_NONE reloc instead of
1978
   garbage.  */
1979
0
      if (sec->contents == NULL)
1980
0
  {
1981
0
    sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size);
1982
0
    if (sec->contents == NULL)
1983
0
      return false;
1984
0
    sec->alloced = 1;
1985
0
  }
1986
0
    }
1987
1988
0
  if (hppa_info->root.dynamic_sections_created)
1989
0
    {
1990
      /* Always create a DT_PLTGOT.  It actually has nothing to do with
1991
   the PLT, it is how we communicate the __gp value of a load
1992
   module to the dynamic linker.  */
1993
0
#define add_dynamic_entry(TAG, VAL) \
1994
0
  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1995
1996
0
      if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0))
1997
0
  return false;
1998
1999
      /* Add some entries to the .dynamic section.  We fill in the
2000
   values later, in elf64_hppa_finish_dynamic_sections, but we
2001
   must add the entries now so that we get the correct size for
2002
   the .dynamic section.  The DT_DEBUG entry is filled in by the
2003
   dynamic linker and used by the debugger.  */
2004
0
      if (! bfd_link_pic (info))
2005
0
  {
2006
0
    if (!add_dynamic_entry (DT_HP_DLD_HOOK, 0)
2007
0
        || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
2008
0
      return false;
2009
0
  }
2010
2011
      /* Force DT_FLAGS to always be set.
2012
   Required by HPUX 11.00 patch PHSS_26559.
2013
   PR 30743: But do not set them for non-HPUX targets.  */
2014
0
      if (info->output_bfd->xvec == &hppa_elf64_vec)
2015
0
  {
2016
0
    if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
2017
0
      return false;
2018
0
  }
2019
2020
      /* If we have a dynamic relocation against a readonly section,
2021
   we need a DT_TEXTREL entry.  */
2022
0
      if (relocs && (info->flags & DF_TEXTREL) != 0)
2023
0
  {
2024
0
    if (!add_dynamic_entry (DT_TEXTREL, 0))
2025
0
      return false;
2026
0
  }
2027
0
    }
2028
0
#undef add_dynamic_entry
2029
2030
0
  return _bfd_elf_add_dynamic_tags (info, relocs);
2031
0
}
2032
2033
/* Called after we have output the symbol into the dynamic symbol
2034
   table, but before we output the symbol into the normal symbol
2035
   table.
2036
2037
   For some symbols we had to change their address when outputting
2038
   the dynamic symbol table.  We undo that change here so that
2039
   the symbols have their expected value in the normal symbol
2040
   table.  Ick.  */
2041
2042
static int
2043
elf64_hppa_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2044
            const char *name,
2045
            Elf_Internal_Sym *sym,
2046
            asection *input_sec ATTRIBUTE_UNUSED,
2047
            struct elf_link_hash_entry *eh)
2048
0
{
2049
0
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2050
2051
  /* We may be called with the file symbol or section symbols.
2052
     They never need munging, so it is safe to ignore them.  */
2053
0
  if (!name || !eh)
2054
0
    return 1;
2055
2056
  /* Function symbols for which we created .opd entries *may* have been
2057
     munged by finish_dynamic_symbol and have to be un-munged here.
2058
2059
     Note that finish_dynamic_symbol sometimes turns dynamic symbols
2060
     into non-dynamic ones, so we initialize st_shndx to -1 in
2061
     mark_exported_functions and check to see if it was overwritten
2062
     here instead of just checking eh->dynindx.  */
2063
0
  if (hh->want_opd && hh->st_shndx != -1)
2064
0
    {
2065
      /* Restore the saved value and section index.  */
2066
0
      sym->st_value = hh->st_value;
2067
0
      sym->st_shndx = hh->st_shndx;
2068
0
    }
2069
2070
0
  return 1;
2071
0
}
2072
2073
/* Finish up dynamic symbol handling.  We set the contents of various
2074
   dynamic sections here.  */
2075
2076
static bool
2077
elf64_hppa_finish_dynamic_symbol (struct bfd_link_info *info,
2078
          struct elf_link_hash_entry *eh,
2079
          Elf_Internal_Sym *sym)
2080
0
{
2081
0
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2082
0
  asection *stub, *splt, *sopd, *spltrel;
2083
0
  struct elf64_hppa_link_hash_table *hppa_info;
2084
2085
0
  hppa_info = hppa_link_hash_table (info);
2086
2087
0
  stub = hppa_info->stub_sec;
2088
0
  splt = hppa_info->root.splt;
2089
0
  sopd = hppa_info->opd_sec;
2090
0
  spltrel = hppa_info->root.srelplt;
2091
2092
  /* Incredible.  It is actually necessary to NOT use the symbol's real
2093
     value when building the dynamic symbol table for a shared library.
2094
     At least for symbols that refer to functions.
2095
2096
     We will store a new value and section index into the symbol long
2097
     enough to output it into the dynamic symbol table, then we restore
2098
     the original values (in elf64_hppa_link_output_symbol_hook).  */
2099
0
  if (hh->want_opd)
2100
0
    {
2101
0
      BFD_ASSERT (sopd != NULL);
2102
2103
      /* Save away the original value and section index so that we
2104
   can restore them later.  */
2105
0
      hh->st_value = sym->st_value;
2106
0
      hh->st_shndx = sym->st_shndx;
2107
2108
      /* For the dynamic symbol table entry, we want the value to be
2109
   address of this symbol's entry within the .opd section.  */
2110
0
      sym->st_value = (hh->opd_offset
2111
0
           + sopd->output_offset
2112
0
           + sopd->output_section->vma);
2113
0
      sym->st_shndx = _bfd_elf_section_from_bfd_section (info->output_bfd,
2114
0
               sopd->output_section);
2115
0
    }
2116
2117
  /* Initialize a .plt entry if requested.  */
2118
0
  if (hh->want_plt)
2119
0
    {
2120
0
      bfd_vma value;
2121
0
      Elf_Internal_Rela rel;
2122
0
      bfd_byte *loc;
2123
2124
0
      BFD_ASSERT (splt != NULL && spltrel != NULL);
2125
2126
      /* We do not actually care about the value in the PLT entry
2127
   if we are creating a shared library and the symbol is
2128
   still undefined, we create a dynamic relocation to fill
2129
   in the correct value.  */
2130
0
      if (eh->root.type == bfd_link_hash_undefined
2131
0
    || eh->root.type == bfd_link_hash_undefweak)
2132
0
  value = 0;
2133
0
      else
2134
0
  {
2135
0
    BFD_ASSERT (eh->root.type == bfd_link_hash_defined
2136
0
          || eh->root.type == bfd_link_hash_defweak);
2137
2138
0
    value = eh->root.u.def.value + eh->root.u.def.section->vma;
2139
0
  }
2140
2141
      /* Fill in the entry in the procedure linkage table.
2142
2143
   The format of a plt entry is
2144
   <funcaddr> <__gp>.
2145
2146
   plt_offset is the offset within the PLT section at which to
2147
   install the PLT entry.
2148
2149
   We are modifying the in-memory PLT contents here, so we do not add
2150
   in the output_offset of the PLT section.  */
2151
2152
0
      bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset);
2153
0
      value = _bfd_get_gp_value (info->output_bfd);
2154
0
      bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset + 0x8);
2155
2156
      /* Create a dynamic IPLT relocation for this entry.
2157
2158
   We are creating a relocation in the output file's PLT section,
2159
   which is included within the DLT secton.  So we do need to include
2160
   the PLT's output_offset in the computation of the relocation's
2161
   address.  */
2162
0
      rel.r_offset = (hh->plt_offset + splt->output_offset
2163
0
          + splt->output_section->vma);
2164
0
      rel.r_info = ELF64_R_INFO (eh->dynindx, R_PARISC_IPLT);
2165
0
      rel.r_addend = 0;
2166
2167
0
      loc = spltrel->contents;
2168
0
      loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2169
0
      bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc);
2170
0
    }
2171
2172
  /* Initialize an external call stub entry if requested.  */
2173
0
  if (hh->want_stub)
2174
0
    {
2175
0
      bfd_vma value;
2176
0
      int insn;
2177
0
      unsigned int max_offset;
2178
2179
0
      BFD_ASSERT (stub != NULL);
2180
2181
      /* Install the generic stub template.
2182
2183
   We are modifying the contents of the stub section, so we do not
2184
   need to include the stub section's output_offset here.  */
2185
0
      memcpy (stub->contents + hh->stub_offset, plt_stub, sizeof (plt_stub));
2186
2187
      /* Fix up the first ldd instruction.
2188
2189
   We are modifying the contents of the STUB section in memory,
2190
   so we do not need to include its output offset in this computation.
2191
2192
   Note the plt_offset value is the value of the PLT entry relative to
2193
   the start of the PLT section.  These instructions will reference
2194
   data relative to the value of __gp, which may not necessarily have
2195
   the same address as the start of the PLT section.
2196
2197
   gp_offset contains the offset of __gp within the PLT section.  */
2198
0
      value = hh->plt_offset - hppa_info->gp_offset;
2199
2200
0
      insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset);
2201
0
      if (info->output_bfd->arch_info->mach >= 25)
2202
0
  {
2203
    /* Wide mode allows 16 bit offsets.  */
2204
0
    max_offset = 32768;
2205
0
    insn &= ~ 0xfff1;
2206
0
    insn |= re_assemble_16 ((int) value);
2207
0
  }
2208
0
      else
2209
0
  {
2210
0
    max_offset = 8192;
2211
0
    insn &= ~ 0x3ff1;
2212
0
    insn |= re_assemble_14 ((int) value);
2213
0
  }
2214
2215
0
      if ((value & 7) || value + max_offset >= 2*max_offset - 8)
2216
0
  {
2217
0
    _bfd_error_handler
2218
      /* xgettext:c-format */
2219
0
      (_("stub entry for %s cannot load .plt, dp offset = %" PRId64),
2220
0
       hh->eh.root.root.string, (int64_t) value);
2221
0
    return false;
2222
0
  }
2223
2224
0
      bfd_put_32 (stub->owner, (bfd_vma) insn,
2225
0
      stub->contents + hh->stub_offset);
2226
2227
      /* Fix up the second ldd instruction.  */
2228
0
      value += 8;
2229
0
      insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset + 8);
2230
0
      if (info->output_bfd->arch_info->mach >= 25)
2231
0
  {
2232
0
    insn &= ~ 0xfff1;
2233
0
    insn |= re_assemble_16 ((int) value);
2234
0
  }
2235
0
      else
2236
0
  {
2237
0
    insn &= ~ 0x3ff1;
2238
0
    insn |= re_assemble_14 ((int) value);
2239
0
  }
2240
0
      bfd_put_32 (stub->owner, (bfd_vma) insn,
2241
0
      stub->contents + hh->stub_offset + 8);
2242
0
    }
2243
2244
0
  return true;
2245
0
}
2246
2247
/* The .opd section contains FPTRs for each function this file
2248
   exports.  Initialize the FPTR entries.  */
2249
2250
static bool
2251
elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data)
2252
0
{
2253
0
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2254
0
  struct bfd_link_info *info = (struct bfd_link_info *)data;
2255
0
  struct elf64_hppa_link_hash_table *hppa_info;
2256
0
  asection *sopd;
2257
0
  asection *sopdrel;
2258
2259
0
  hppa_info = hppa_link_hash_table (info);
2260
0
  if (hppa_info == NULL)
2261
0
    return false;
2262
2263
0
  sopd = hppa_info->opd_sec;
2264
0
  sopdrel = hppa_info->opd_rel_sec;
2265
2266
0
  if (hh->want_opd)
2267
0
    {
2268
0
      bfd_vma value;
2269
2270
0
      BFD_ASSERT (eh->root.type == bfd_link_hash_defined
2271
0
      || eh->root.type == bfd_link_hash_defweak);
2272
2273
0
      value = (eh->root.u.def.value
2274
0
         + eh->root.u.def.section->output_section->vma
2275
0
         + eh->root.u.def.section->output_offset);
2276
2277
      /* The first word is the address of the function.  */
2278
0
      bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 16);
2279
2280
      /* The last word is our local __gp value.  */
2281
0
      value = _bfd_get_gp_value (info->output_bfd);
2282
0
      bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 24);
2283
0
    }
2284
2285
  /* If we are generating a shared library, we must generate EPLT
2286
     relocations for each entry in the .opd.  Here we handle EPLT
2287
     relocations for global symbols.  */
2288
0
  if (bfd_link_pic (info) && hh->want_opd)
2289
0
    {
2290
0
      bfd_vma value, value2;
2291
0
      Elf_Internal_Rela rel;
2292
0
      bfd_byte *loc;
2293
0
      long dynindx;
2294
0
      asection *sec;
2295
2296
      /* The offset of this relocation is the absolute address of the
2297
   .opd entry for this symbol.  */
2298
0
      rel.r_offset = (hh->opd_offset + sopd->output_offset
2299
0
          + sopd->output_section->vma);
2300
0
      rel.r_addend = 0;
2301
2302
      /* If H is non-null, then we have an external symbol.
2303
2304
   It is imperative that we use a different dynamic symbol for the
2305
   EPLT relocation if the symbol has global scope.
2306
2307
   In the dynamic symbol table, the function symbol will have a value
2308
   which is address of the function's .opd entry.
2309
2310
   Thus, we can not use that dynamic symbol for the EPLT relocation
2311
   (if we did, the data in the .opd would reference itself rather
2312
   than the actual address of the function).  To resolve this issue,
2313
   we use offsets relative to the local section symbol __text_seg.  */
2314
2315
      /* First compute the address of this symbol.  */
2316
0
      value = (eh->root.u.def.value
2317
0
         + eh->root.u.def.section->output_section->vma
2318
0
         + eh->root.u.def.section->output_offset);
2319
2320
      /* Compute the base address of the segment with this symbol.  */
2321
0
      sec = hppa_info->text_hash_entry->root.u.def.section;
2322
0
      value2 = sec->output_offset + sec->output_section->vma;
2323
2324
      /* Compute the difference between the symbol and the text segment
2325
   base address.  */
2326
0
      value -= value2;
2327
2328
      /* The result becomes the addend of the relocation.  */
2329
0
      rel.r_addend += value;
2330
2331
0
      dynindx = hppa_info->text_hash_entry->dynindx;
2332
0
      rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
2333
2334
0
      loc = sopdrel->contents;
2335
0
      loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
2336
0
      bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc);
2337
0
    }
2338
0
  return true;
2339
0
}
2340
2341
/* The .dlt section contains addresses for items referenced through the
2342
   dlt.  Note that we can have a DLTIND relocation for a local symbol, thus
2343
   we can not depend on finish_dynamic_symbol to initialize the .dlt.  */
2344
2345
static bool
2346
elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data)
2347
0
{
2348
0
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2349
0
  struct bfd_link_info *info = (struct bfd_link_info *)data;
2350
0
  struct elf64_hppa_link_hash_table *hppa_info;
2351
0
  asection *sdlt, *sdltrel;
2352
2353
0
  hppa_info = hppa_link_hash_table (info);
2354
0
  if (hppa_info == NULL)
2355
0
    return false;
2356
2357
0
  sdlt = hppa_info->dlt_sec;
2358
0
  sdltrel = hppa_info->dlt_rel_sec;
2359
2360
0
  if (! bfd_link_pic (info) && hh->want_dlt)
2361
0
    {
2362
0
      bfd_vma value;
2363
2364
      /* If we had an LTOFF_FPTR style relocation we want the DLT entry
2365
   to point to the FPTR entry in the .opd section.
2366
2367
   We include the OPD's output offset in this computation as
2368
   we are referring to an absolute address in the resulting
2369
   object file.  */
2370
0
      if (hh->want_opd)
2371
0
  {
2372
0
    value = (hh->opd_offset
2373
0
       + hppa_info->opd_sec->output_offset
2374
0
       + hppa_info->opd_sec->output_section->vma);
2375
0
  }
2376
0
      else if ((eh->root.type == bfd_link_hash_defined
2377
0
    || eh->root.type == bfd_link_hash_defweak)
2378
0
         && eh->root.u.def.section)
2379
0
  {
2380
0
    value = eh->root.u.def.value + eh->root.u.def.section->output_offset;
2381
0
    if (eh->root.u.def.section->output_section)
2382
0
      value += eh->root.u.def.section->output_section->vma;
2383
0
    else
2384
0
      value += eh->root.u.def.section->vma;
2385
0
  }
2386
0
      else
2387
  /* We have an undefined function reference.  */
2388
0
  value = 0;
2389
2390
      /* We do not need to include the output offset of the DLT section
2391
   here because we are modifying the in-memory contents.  */
2392
0
      bfd_put_64 (sdlt->owner, value, sdlt->contents + hh->dlt_offset);
2393
0
    }
2394
2395
  /* Create a relocation for the DLT entry associated with this symbol.
2396
     When building a shared library the symbol does not have to be dynamic.  */
2397
0
  if (hh->want_dlt
2398
0
      && (elf64_hppa_dynamic_symbol_p (eh, info) || bfd_link_pic (info)))
2399
0
    {
2400
0
      Elf_Internal_Rela rel;
2401
0
      bfd_byte *loc;
2402
0
      long dynindx;
2403
0
      struct elf_link_hash_entry *baseh;
2404
0
      asection *sec;
2405
0
      bfd_vma value, value2;
2406
2407
0
      if (eh->dynindx == -1)
2408
0
  {
2409
0
    BFD_ASSERT (eh->root.type == bfd_link_hash_defined
2410
0
          || eh->root.type == bfd_link_hash_defweak);
2411
2412
0
    value = (eh->root.u.def.value
2413
0
       + eh->root.u.def.section->output_section->vma
2414
0
       + eh->root.u.def.section->output_offset);
2415
2416
0
    if (eh->root.u.def.section->flags & SEC_READONLY)
2417
0
      baseh = hppa_info->text_hash_entry;
2418
0
    else
2419
0
      baseh = hppa_info->data_hash_entry;
2420
2421
0
    sec = baseh->root.u.def.section;
2422
0
    value2 = sec->output_offset + sec->output_section->vma;
2423
0
    dynindx = baseh->dynindx;
2424
0
    rel.r_addend = value - value2;
2425
0
  }
2426
0
      else
2427
0
  {
2428
0
    dynindx = eh->dynindx;
2429
0
    rel.r_addend = 0;
2430
0
  }
2431
2432
      /* Create a dynamic relocation for this entry.  Do include the output
2433
   offset of the DLT entry since we need an absolute address in the
2434
   resulting object file.  */
2435
0
      rel.r_offset = (hh->dlt_offset + sdlt->output_offset
2436
0
          + sdlt->output_section->vma);
2437
0
      if (eh->type == STT_FUNC)
2438
0
    rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64);
2439
0
      else
2440
0
    rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
2441
2442
0
      loc = sdltrel->contents;
2443
0
      loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
2444
0
      bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc);
2445
0
    }
2446
0
  return true;
2447
0
}
2448
2449
/* Finalize the dynamic relocations.  Specifically the FPTR relocations
2450
   for dynamic functions used to initialize static data.  */
2451
2452
static bool
2453
elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh,
2454
            void *data)
2455
0
{
2456
0
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
2457
0
  struct bfd_link_info *info = (struct bfd_link_info *)data;
2458
0
  struct elf64_hppa_link_hash_table *hppa_info;
2459
0
  bool dynamic_symbol, shared;
2460
2461
0
  dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, info);
2462
0
  shared = bfd_link_pic (info);
2463
2464
0
  hppa_info = hppa_link_hash_table (info);
2465
0
  if (hppa_info == NULL)
2466
0
    return false;
2467
2468
0
  if (hppa_info->other_rel_sec == NULL
2469
0
      || discarded_section (hppa_info->other_rel_sec))
2470
0
    return true;
2471
2472
0
  if (hh->reloc_entries)
2473
0
    {
2474
0
      struct elf64_hppa_dyn_reloc_entry *rent;
2475
0
      long dynindx;
2476
2477
0
      for (rent = hh->reloc_entries; rent; rent = rent->next)
2478
0
  {
2479
0
    Elf_Internal_Rela rel;
2480
0
    bfd_byte *loc;
2481
2482
0
    switch (rent->type)
2483
0
      {
2484
0
      case R_PARISC_FPTR64:
2485
        /* Allocate one if we are building a shared library, or
2486
     we don't want an OPD entry.  Ignore text relocations.  */
2487
0
        if ((hh->want_opd && !shared)
2488
0
      || (rent->sec->flags & SEC_READONLY))
2489
0
    continue;
2490
0
        break;
2491
0
      case R_PARISC_DIR64:
2492
0
        if (!dynamic_symbol && !shared)
2493
0
    continue;
2494
0
        break;
2495
0
      default:
2496
0
        abort();
2497
0
      }
2498
2499
0
    if (discarded_section (rent->sec)
2500
0
        || discarded_section (hppa_info->other_rel_sec))
2501
0
      continue;
2502
2503
    /* Create a dynamic relocation for this entry.
2504
2505
       We need the output offset for the reloc's section because
2506
       we are creating an absolute address in the resulting object
2507
       file.  */
2508
0
    rel.r_offset = (rent->offset + rent->sec->output_offset
2509
0
        + rent->sec->output_section->vma);
2510
2511
0
    if (eh->dynindx == -1)
2512
0
      {
2513
0
        struct elf_link_hash_entry *baseh;
2514
0
        asection *sec, *sopd;
2515
0
        bfd_vma value, value2;
2516
2517
0
        if (rent->type == R_PARISC_FPTR64)
2518
0
          {
2519
0
      if (!hh->want_opd)
2520
0
        continue;
2521
0
      BFD_ASSERT (rent->addend == 0);
2522
0
      sopd = hppa_info->opd_sec;
2523
0
      value = (hh->opd_offset + sopd->output_offset
2524
0
           + sopd->output_section->vma);
2525
2526
0
      sec = hppa_info->data_hash_entry->root.u.def.section;
2527
0
      value2 = sec->output_offset + sec->output_section->vma;
2528
0
      dynindx = hppa_info->data_hash_entry->dynindx;
2529
0
    }
2530
0
        else
2531
0
    {
2532
0
      if (discarded_section (eh->root.u.def.section))
2533
0
        continue;
2534
2535
0
      BFD_ASSERT (eh->root.type == bfd_link_hash_defined
2536
0
            || eh->root.type == bfd_link_hash_defweak);
2537
2538
0
      value = (eh->root.u.def.value
2539
0
         + eh->root.u.def.section->output_section->vma
2540
0
         + eh->root.u.def.section->output_offset
2541
0
         + rent->addend);
2542
2543
0
      if (eh->root.u.def.section->flags & SEC_READONLY)
2544
0
        baseh = hppa_info->text_hash_entry;
2545
0
      else
2546
0
        baseh = hppa_info->data_hash_entry;
2547
2548
0
      sec = baseh->root.u.def.section;
2549
0
      value2 = sec->output_offset + sec->output_section->vma;
2550
0
      dynindx = baseh->dynindx;
2551
0
    }
2552
0
        rel.r_addend = value - value2;
2553
0
      }
2554
0
    else
2555
0
      {
2556
0
        rel.r_addend = rent->addend;
2557
0
        dynindx = eh->dynindx;
2558
0
      }
2559
2560
0
    rel.r_info = ELF64_R_INFO (dynindx, rent->type);
2561
2562
0
    loc = hppa_info->other_rel_sec->contents;
2563
0
    BFD_ASSERT ((hppa_info->other_rel_sec->reloc_count
2564
0
           * sizeof (Elf64_External_Rela))
2565
0
          < hppa_info->other_rel_sec->size);
2566
0
    loc += (hppa_info->other_rel_sec->reloc_count++
2567
0
      * sizeof (Elf64_External_Rela));
2568
0
    bfd_elf64_swap_reloca_out (info->output_bfd, &rel, loc);
2569
0
  }
2570
0
    }
2571
2572
0
  return true;
2573
0
}
2574
2575
/* Used to decide how to sort relocs in an optimal manner for the
2576
   dynamic linker, before writing them out.  */
2577
2578
static enum elf_reloc_type_class
2579
elf64_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
2580
           const asection *rel_sec ATTRIBUTE_UNUSED,
2581
           const Elf_Internal_Rela *rela)
2582
0
{
2583
0
  if (ELF64_R_SYM (rela->r_info) == STN_UNDEF)
2584
0
    return reloc_class_relative;
2585
2586
0
  switch ((int) ELF64_R_TYPE (rela->r_info))
2587
0
    {
2588
0
    case R_PARISC_IPLT:
2589
0
      return reloc_class_plt;
2590
0
    case R_PARISC_COPY:
2591
0
      return reloc_class_copy;
2592
0
    default:
2593
0
      return reloc_class_normal;
2594
0
    }
2595
0
}
2596
2597
/* Finish up the dynamic sections.  */
2598
2599
static bool
2600
elf64_hppa_finish_dynamic_sections (struct bfd_link_info *info,
2601
            bfd_byte *buf ATTRIBUTE_UNUSED)
2602
0
{
2603
0
  bfd *dynobj;
2604
0
  asection *sdyn;
2605
0
  struct elf64_hppa_link_hash_table *hppa_info;
2606
2607
0
  hppa_info = hppa_link_hash_table (info);
2608
0
  if (hppa_info == NULL)
2609
0
    return false;
2610
2611
  /* Finalize the contents of the .opd section.  */
2612
0
  elf_link_hash_traverse (elf_hash_table (info),
2613
0
        elf64_hppa_finalize_opd,
2614
0
        info);
2615
2616
0
  elf_link_hash_traverse (elf_hash_table (info),
2617
0
        elf64_hppa_finalize_dynreloc,
2618
0
        info);
2619
2620
0
  dynobj = elf_hash_table (info)->dynobj;
2621
2622
  /* Finalize the contents of the .dlt section.  */
2623
0
  elf_link_hash_traverse (elf_hash_table (info),
2624
0
        elf64_hppa_finalize_dlt,
2625
0
        info);
2626
2627
0
  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
2628
2629
0
  if (elf_hash_table (info)->dynamic_sections_created)
2630
0
    {
2631
0
      Elf64_External_Dyn *dyncon, *dynconend;
2632
2633
0
      BFD_ASSERT (sdyn != NULL);
2634
2635
0
      dyncon = (Elf64_External_Dyn *) sdyn->contents;
2636
0
      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
2637
0
      for (; dyncon < dynconend; dyncon++)
2638
0
  {
2639
0
    Elf_Internal_Dyn dyn;
2640
0
    asection *s;
2641
2642
0
    bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
2643
2644
0
    switch (dyn.d_tag)
2645
0
      {
2646
0
      default:
2647
0
        break;
2648
2649
0
      case DT_HP_LOAD_MAP:
2650
        /* Compute the absolute address of 16-byte scratchpad area
2651
     for the dynamic linker.
2652
2653
     By convention the linker script will allocate the scratchpad
2654
     area at the start of the .data section.
2655
2656
     In HPUX 11.11, HP ld now allocates the region at the end
2657
     of the .bss section.  This avoids adding 16 bytes to the
2658
     start of .data.  This may affect relocation offsets.  */
2659
0
        if (info->output_bfd->xvec == & hppa_elf64_vec
2660
0
            && ! bfd_link_pic (info))
2661
0
    {
2662
0
      s = bfd_get_section_by_name (info->output_bfd, ".bss");
2663
0
      if (!s)
2664
0
        break;
2665
0
      dyn.d_un.d_ptr = s->vma + s->size - 16;
2666
0
      bfd_elf64_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2667
0
    }
2668
0
        break;
2669
2670
0
      case DT_PLTGOT:
2671
        /* HP's use PLTGOT to set the GOT register.  */
2672
0
        dyn.d_un.d_ptr = _bfd_get_gp_value (info->output_bfd);
2673
0
        bfd_elf64_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2674
0
        break;
2675
2676
0
      case DT_JMPREL:
2677
0
        s = hppa_info->root.srelplt;
2678
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2679
0
        bfd_elf64_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2680
0
        break;
2681
2682
0
      case DT_PLTRELSZ:
2683
0
        s = hppa_info->root.srelplt;
2684
0
        dyn.d_un.d_val = s->size;
2685
0
        bfd_elf64_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2686
0
        break;
2687
2688
0
      case DT_RELA:
2689
0
        s = hppa_info->other_rel_sec;
2690
0
        if (! s || ! s->size)
2691
0
    s = hppa_info->dlt_rel_sec;
2692
0
        if (! s || ! s->size)
2693
0
    s = hppa_info->opd_rel_sec;
2694
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
2695
0
        bfd_elf64_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2696
0
        break;
2697
2698
0
      case DT_RELASZ:
2699
0
        s = hppa_info->other_rel_sec;
2700
0
        dyn.d_un.d_val = s->size;
2701
0
        s = hppa_info->dlt_rel_sec;
2702
0
        dyn.d_un.d_val += s->size;
2703
0
        s = hppa_info->opd_rel_sec;
2704
0
        dyn.d_un.d_val += s->size;
2705
        /* There is some question about whether or not the size of
2706
     the PLT relocs should be included here.  HP's tools do
2707
     it, so we'll emulate them.  */
2708
0
        s = hppa_info->root.srelplt;
2709
0
        dyn.d_un.d_val += s->size;
2710
0
        bfd_elf64_swap_dyn_out (info->output_bfd, &dyn, dyncon);
2711
0
        break;
2712
2713
0
      }
2714
0
  }
2715
0
    }
2716
2717
0
  return true;
2718
0
}
2719
2720
/* Support for core dump NOTE sections.  */
2721
2722
static bool
2723
elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2724
0
{
2725
0
  int offset;
2726
0
  size_t size;
2727
2728
0
  switch (note->descsz)
2729
0
    {
2730
0
      default:
2731
0
  return false;
2732
2733
0
      case 760:   /* Linux/hppa */
2734
  /* pr_cursig */
2735
0
  elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2736
2737
  /* pr_pid */
2738
0
  elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
2739
2740
  /* pr_reg */
2741
0
  offset = 112;
2742
0
  size = 640;
2743
2744
0
  break;
2745
0
    }
2746
2747
  /* Make a ".reg/999" section.  */
2748
0
  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2749
0
            size, note->descpos + offset);
2750
0
}
2751
2752
static bool
2753
elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2754
0
{
2755
0
  char * command;
2756
0
  int n;
2757
2758
0
  switch (note->descsz)
2759
0
    {
2760
0
    default:
2761
0
      return false;
2762
2763
0
    case 136:   /* Linux/hppa elf_prpsinfo.  */
2764
0
      elf_tdata (abfd)->core->program
2765
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2766
0
      elf_tdata (abfd)->core->command
2767
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2768
0
    }
2769
2770
  /* Note that for some reason, a spurious space is tacked
2771
     onto the end of the args in some (at least one anyway)
2772
     implementations, so strip it off if it exists.  */
2773
0
  command = elf_tdata (abfd)->core->command;
2774
0
  n = strlen (command);
2775
2776
0
  if (0 < n && command[n - 1] == ' ')
2777
0
    command[n - 1] = '\0';
2778
2779
0
  return true;
2780
0
}
2781
2782
/* Return the number of additional phdrs we will need.
2783
2784
   The generic ELF code only creates PT_PHDRs for executables.  The HP
2785
   dynamic linker requires PT_PHDRs for dynamic libraries too.
2786
2787
   This routine indicates that the backend needs one additional program
2788
   header for that case.
2789
2790
   Note we do not have access to the link info structure here, so we have
2791
   to guess whether or not we are building a shared library based on the
2792
   existence of a .interp section.  */
2793
2794
static int
2795
elf64_hppa_additional_program_headers (bfd *abfd,
2796
        struct bfd_link_info *info ATTRIBUTE_UNUSED)
2797
0
{
2798
0
  asection *s;
2799
2800
  /* If we are creating a shared library, then we have to create a
2801
     PT_PHDR segment.  HP's dynamic linker chokes without it.  */
2802
0
  s = bfd_get_section_by_name (abfd, ".interp");
2803
0
  if (! s)
2804
0
    return 1;
2805
0
  return 0;
2806
0
}
2807
2808
static bool
2809
elf64_hppa_allow_non_load_phdr (bfd *abfd ATTRIBUTE_UNUSED,
2810
        const Elf_Internal_Phdr *phdr ATTRIBUTE_UNUSED,
2811
        unsigned int count ATTRIBUTE_UNUSED)
2812
0
{
2813
0
  return true;
2814
0
}
2815
2816
/* Allocate and initialize any program headers required by this
2817
   specific backend.
2818
2819
   The generic ELF code only creates PT_PHDRs for executables.  The HP
2820
   dynamic linker requires PT_PHDRs for dynamic libraries too.
2821
2822
   This allocates the PT_PHDR and initializes it in a manner suitable
2823
   for the HP linker.
2824
2825
   Note we do not have access to the link info structure here, so we have
2826
   to guess whether or not we are building a shared library based on the
2827
   existence of a .interp section.  */
2828
2829
static bool
2830
elf64_hppa_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
2831
0
{
2832
0
  struct elf_segment_map *m;
2833
2834
0
  m = elf_seg_map (abfd);
2835
0
  if (info != NULL && !info->user_phdrs && m != NULL && m->p_type != PT_PHDR)
2836
0
    {
2837
0
      m = ((struct elf_segment_map *)
2838
0
     bfd_zalloc (abfd, (bfd_size_type) sizeof *m));
2839
0
      if (m == NULL)
2840
0
  return false;
2841
2842
0
      m->p_type = PT_PHDR;
2843
0
      m->p_flags = PF_R | PF_X;
2844
0
      m->p_flags_valid = 1;
2845
0
      m->p_paddr_valid = 1;
2846
0
      m->includes_phdrs = 1;
2847
2848
0
      m->next = elf_seg_map (abfd);
2849
0
      elf_seg_map (abfd) = m;
2850
0
    }
2851
2852
0
  for (m = elf_seg_map (abfd) ; m != NULL; m = m->next)
2853
0
    if (m->p_type == PT_LOAD)
2854
0
      {
2855
0
  unsigned int i;
2856
2857
0
  for (i = 0; i < m->count; i++)
2858
0
    {
2859
      /* The code "hint" is not really a hint.  It is a requirement
2860
         for certain versions of the HP dynamic linker.  Worse yet,
2861
         it must be set even if the shared library does not have
2862
         any code in its "text" segment (thus the check for .hash
2863
         to catch this situation).  */
2864
0
      if (m->sections[i]->flags & SEC_CODE
2865
0
    || (strcmp (m->sections[i]->name, ".hash") == 0))
2866
0
        m->p_flags |= (PF_X | PF_HP_CODE);
2867
0
    }
2868
0
      }
2869
2870
0
  return true;
2871
0
}
2872
2873
/* Called when writing out an object file to decide the type of a
2874
   symbol.  */
2875
static int
2876
elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym,
2877
        int type)
2878
0
{
2879
0
  if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
2880
0
    return STT_PARISC_MILLI;
2881
0
  else
2882
0
    return type;
2883
0
}
2884
2885
/* Support HP specific sections for core files.  */
2886
2887
static bool
2888
elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int sec_index,
2889
            const char *typename)
2890
0
{
2891
0
  if (hdr->p_type == PT_HP_CORE_KERNEL)
2892
0
    {
2893
0
      asection *sect;
2894
2895
0
      if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename))
2896
0
  return false;
2897
2898
0
      sect = bfd_make_section_anyway (abfd, ".kernel");
2899
0
      if (sect == NULL)
2900
0
  return false;
2901
0
      sect->size = hdr->p_filesz;
2902
0
      sect->filepos = hdr->p_offset;
2903
0
      sect->flags = SEC_HAS_CONTENTS | SEC_READONLY;
2904
0
      return true;
2905
0
    }
2906
2907
0
  if (hdr->p_type == PT_HP_CORE_PROC)
2908
0
    {
2909
0
      int sig;
2910
2911
0
      if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0)
2912
0
  return false;
2913
0
      if (bfd_read (&sig, 4, abfd) != 4)
2914
0
  return false;
2915
2916
0
      elf_tdata (abfd)->core->signal = sig;
2917
2918
0
      if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename))
2919
0
  return false;
2920
2921
      /* GDB uses the ".reg" section to read register contents.  */
2922
0
      return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz,
2923
0
                hdr->p_offset);
2924
0
    }
2925
2926
0
  if (hdr->p_type == PT_HP_CORE_LOADABLE
2927
0
      || hdr->p_type == PT_HP_CORE_STACK
2928
0
      || hdr->p_type == PT_HP_CORE_MMF)
2929
0
    hdr->p_type = PT_LOAD;
2930
2931
0
  return _bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename);
2932
0
}
2933
2934
/* Hook called by the linker routine which adds symbols from an object
2935
   file.  HP's libraries define symbols with HP specific section
2936
   indices, which we have to handle.  */
2937
2938
static bool
2939
elf_hppa_add_symbol_hook (bfd *abfd,
2940
        struct bfd_link_info *info ATTRIBUTE_UNUSED,
2941
        Elf_Internal_Sym *sym,
2942
        const char **namep ATTRIBUTE_UNUSED,
2943
        flagword *flagsp ATTRIBUTE_UNUSED,
2944
        asection **secp,
2945
        bfd_vma *valp)
2946
0
{
2947
0
  unsigned int sec_index = sym->st_shndx;
2948
2949
0
  switch (sec_index)
2950
0
    {
2951
0
    case SHN_PARISC_ANSI_COMMON:
2952
0
      *secp = bfd_make_section_old_way (abfd, ".PARISC.ansi.common");
2953
0
      (*secp)->flags |= SEC_IS_COMMON;
2954
0
      *valp = sym->st_size;
2955
0
      break;
2956
2957
0
    case SHN_PARISC_HUGE_COMMON:
2958
0
      *secp = bfd_make_section_old_way (abfd, ".PARISC.huge.common");
2959
0
      (*secp)->flags |= SEC_IS_COMMON;
2960
0
      *valp = sym->st_size;
2961
0
      break;
2962
0
    }
2963
2964
0
  return true;
2965
0
}
2966
2967
static bool
2968
elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
2969
           void *data)
2970
0
{
2971
0
  struct bfd_link_info *info = data;
2972
2973
  /* If we are not creating a shared library, and this symbol is
2974
     referenced by a shared library but is not defined anywhere, then
2975
     the generic code will warn that it is undefined.
2976
2977
     This behavior is undesirable on HPs since the standard shared
2978
     libraries contain references to undefined symbols.
2979
2980
     So we twiddle the flags associated with such symbols so that they
2981
     will not trigger the warning.  ?!? FIXME.  This is horribly fragile.
2982
2983
     Ultimately we should have better controls over the generic ELF BFD
2984
     linker code.  */
2985
0
  if (! bfd_link_relocatable (info)
2986
0
      && info->unresolved_syms_in_shared_libs != RM_IGNORE
2987
0
      && h->root.type == bfd_link_hash_undefined
2988
0
      && h->ref_dynamic
2989
0
      && !h->ref_regular)
2990
0
    {
2991
0
      h->ref_dynamic = 0;
2992
0
      h->pointer_equality_needed = 1;
2993
0
    }
2994
2995
0
  return true;
2996
0
}
2997
2998
static bool
2999
elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h,
3000
           void *data)
3001
0
{
3002
0
  struct bfd_link_info *info = data;
3003
3004
  /* If we are not creating a shared library, and this symbol is
3005
     referenced by a shared library but is not defined anywhere, then
3006
     the generic code will warn that it is undefined.
3007
3008
     This behavior is undesirable on HPs since the standard shared
3009
     libraries contain references to undefined symbols.
3010
3011
     So we twiddle the flags associated with such symbols so that they
3012
     will not trigger the warning.  ?!? FIXME.  This is horribly fragile.
3013
3014
     Ultimately we should have better controls over the generic ELF BFD
3015
     linker code.  */
3016
0
  if (! bfd_link_relocatable (info)
3017
0
      && info->unresolved_syms_in_shared_libs != RM_IGNORE
3018
0
      && h->root.type == bfd_link_hash_undefined
3019
0
      && !h->ref_dynamic
3020
0
      && !h->ref_regular
3021
0
      && h->pointer_equality_needed)
3022
0
    {
3023
0
      h->ref_dynamic = 1;
3024
0
      h->pointer_equality_needed = 0;
3025
0
    }
3026
3027
0
  return true;
3028
0
}
3029
3030
static bool
3031
elf_hppa_is_dynamic_loader_symbol (const char *name)
3032
0
{
3033
  /* HP-UX linker provided symbols.  */
3034
0
  return (! strcmp (name, "__SYSTEM_ID")
3035
0
    || ! strcmp (name, "_FPU_STATUS")
3036
0
    || ! strcmp (name, "__TLS_SIZE")
3037
0
    || ! strcmp (name, "__TLS_INIT_SIZE")
3038
0
    || ! strcmp (name, "__TLS_INIT_START")
3039
0
    || ! strcmp (name, "__TLS_INIT_A")
3040
0
    || ! strcmp (name, "__TLS_PREALLOC_DTV_A"));
3041
0
}
3042
3043
/* Record the lowest address for the data and text segments.  */
3044
static void
3045
elf_hppa_record_segment_addrs (bfd *abfd,
3046
             asection *section,
3047
             void *data)
3048
0
{
3049
0
  struct elf64_hppa_link_hash_table *hppa_info = data;
3050
3051
0
  if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
3052
0
    {
3053
0
      bfd_vma value;
3054
0
      Elf_Internal_Phdr *p;
3055
3056
0
      p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
3057
0
      BFD_ASSERT (p != NULL);
3058
0
      value = p->p_vaddr;
3059
3060
0
      if (section->flags & SEC_READONLY)
3061
0
  {
3062
0
    if (value < hppa_info->text_segment_base)
3063
0
      hppa_info->text_segment_base = value;
3064
0
  }
3065
0
      else
3066
0
  {
3067
0
    if (value < hppa_info->data_segment_base)
3068
0
      hppa_info->data_segment_base = value;
3069
0
  }
3070
0
    }
3071
0
}
3072
3073
/* Called after we have seen all the input files/sections, but before
3074
   final symbol resolution and section placement has been determined.
3075
3076
   We use this hook to (possibly) provide a value for __gp, then we
3077
   fall back to the generic ELF final link routine.  */
3078
3079
static bool
3080
elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
3081
0
{
3082
0
  struct stat buf;
3083
0
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3084
3085
0
  if (hppa_info == NULL)
3086
0
    return false;
3087
3088
0
  if (! bfd_link_relocatable (info))
3089
0
    {
3090
0
      struct elf_link_hash_entry *gp;
3091
0
      bfd_vma gp_val;
3092
3093
      /* The linker script defines a value for __gp iff it was referenced
3094
   by one of the objects being linked.  First try to find the symbol
3095
   in the hash table.  If that fails, just compute the value __gp
3096
   should have had.  */
3097
0
      gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", false,
3098
0
         false, false);
3099
3100
0
      if (gp)
3101
0
  {
3102
3103
    /* Adjust the value of __gp as we may want to slide it into the
3104
       .plt section so that the stubs can access PLT entries without
3105
       using an addil sequence.  */
3106
0
    gp->root.u.def.value += hppa_info->gp_offset;
3107
3108
0
    gp_val = (gp->root.u.def.section->output_section->vma
3109
0
        + gp->root.u.def.section->output_offset
3110
0
        + gp->root.u.def.value);
3111
0
  }
3112
0
      else
3113
0
  {
3114
0
    asection *sec;
3115
3116
    /* First look for a .plt section.  If found, then __gp is the
3117
       address of the .plt + gp_offset.
3118
3119
       If no .plt is found, then look for .dlt, .opd and .data (in
3120
       that order) and set __gp to the base address of whichever
3121
       section is found first.  */
3122
3123
0
    sec = hppa_info->root.splt;
3124
0
    if (sec && ! (sec->flags & SEC_EXCLUDE))
3125
0
      gp_val = (sec->output_offset
3126
0
          + sec->output_section->vma
3127
0
          + hppa_info->gp_offset);
3128
0
    else
3129
0
      {
3130
0
        sec = hppa_info->dlt_sec;
3131
0
        if (!sec || (sec->flags & SEC_EXCLUDE))
3132
0
    sec = hppa_info->opd_sec;
3133
0
        if (!sec || (sec->flags & SEC_EXCLUDE))
3134
0
    sec = bfd_get_section_by_name (abfd, ".data");
3135
0
        if (!sec || (sec->flags & SEC_EXCLUDE))
3136
0
    gp_val = 0;
3137
0
        else
3138
0
    gp_val = sec->output_offset + sec->output_section->vma;
3139
0
      }
3140
0
  }
3141
3142
      /* Install whatever value we found/computed for __gp.  */
3143
0
      _bfd_set_gp_value (abfd, gp_val);
3144
0
    }
3145
3146
  /* We need to know the base of the text and data segments so that we
3147
     can perform SEGREL relocations.  We will record the base addresses
3148
     when we encounter the first SEGREL relocation.  */
3149
0
  hppa_info->text_segment_base = (bfd_vma)-1;
3150
0
  hppa_info->data_segment_base = (bfd_vma)-1;
3151
3152
  /* HP's shared libraries have references to symbols that are not
3153
     defined anywhere.  The generic ELF BFD linker code will complain
3154
     about such symbols.
3155
3156
     So we detect the losing case and arrange for the flags on the symbol
3157
     to indicate that it was never referenced.  This keeps the generic
3158
     ELF BFD link code happy and appears to not create any secondary
3159
     problems.  Ultimately we need a way to control the behavior of the
3160
     generic ELF BFD link code better.  */
3161
0
  elf_link_hash_traverse (elf_hash_table (info),
3162
0
        elf_hppa_unmark_useless_dynamic_symbols,
3163
0
        info);
3164
3165
  /* Invoke the regular ELF backend linker to do all the work.  */
3166
0
  if (!_bfd_elf_final_link (abfd, info))
3167
0
    return false;
3168
3169
0
  elf_link_hash_traverse (elf_hash_table (info),
3170
0
        elf_hppa_remark_useless_dynamic_symbols,
3171
0
        info);
3172
3173
  /* If we're producing a final executable, sort the contents of the
3174
     unwind section. */
3175
0
  if (bfd_link_relocatable (info))
3176
0
    return true;
3177
3178
  /* Do not attempt to sort non-regular files.  This is here
3179
     especially for configure scripts and kernel builds which run
3180
     tests with "ld [...] -o /dev/null".  */
3181
0
  if (stat (bfd_get_filename (abfd), &buf) != 0
3182
0
      || !S_ISREG(buf.st_mode))
3183
0
    return true;
3184
3185
0
  return elf_hppa_sort_unwind (abfd);
3186
0
}
3187
3188
/* Relocate the given INSN.  VALUE should be the actual value we want
3189
   to insert into the instruction, ie by this point we should not be
3190
   concerned with computing an offset relative to the DLT, PC, etc.
3191
   Instead this routine is meant to handle the bit manipulations needed
3192
   to insert the relocation into the given instruction.  */
3193
3194
static int
3195
elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type)
3196
0
{
3197
0
  switch (r_type)
3198
0
    {
3199
    /* This is any 22 bit branch.  In PA2.0 syntax it corresponds to
3200
       the "B" instruction.  */
3201
0
    case R_PARISC_PCREL22F:
3202
0
    case R_PARISC_PCREL22C:
3203
0
      return (insn & ~0x3ff1ffd) | re_assemble_22 (sym_value);
3204
3205
      /* This is any 12 bit branch.  */
3206
0
    case R_PARISC_PCREL12F:
3207
0
      return (insn & ~0x1ffd) | re_assemble_12 (sym_value);
3208
3209
    /* This is any 17 bit branch.  In PA2.0 syntax it also corresponds
3210
       to the "B" instruction as well as BE.  */
3211
0
    case R_PARISC_PCREL17F:
3212
0
    case R_PARISC_DIR17F:
3213
0
    case R_PARISC_DIR17R:
3214
0
    case R_PARISC_PCREL17C:
3215
0
    case R_PARISC_PCREL17R:
3216
0
      return (insn & ~0x1f1ffd) | re_assemble_17 (sym_value);
3217
3218
    /* ADDIL or LDIL instructions.  */
3219
0
    case R_PARISC_DLTREL21L:
3220
0
    case R_PARISC_DLTIND21L:
3221
0
    case R_PARISC_LTOFF_FPTR21L:
3222
0
    case R_PARISC_PCREL21L:
3223
0
    case R_PARISC_LTOFF_TP21L:
3224
0
    case R_PARISC_DPREL21L:
3225
0
    case R_PARISC_PLTOFF21L:
3226
0
    case R_PARISC_DIR21L:
3227
0
      return (insn & ~0x1fffff) | re_assemble_21 (sym_value);
3228
3229
    /* LDO and integer loads/stores with 14 bit displacements.  */
3230
0
    case R_PARISC_DLTREL14R:
3231
0
    case R_PARISC_DLTREL14F:
3232
0
    case R_PARISC_DLTIND14R:
3233
0
    case R_PARISC_DLTIND14F:
3234
0
    case R_PARISC_LTOFF_FPTR14R:
3235
0
    case R_PARISC_PCREL14R:
3236
0
    case R_PARISC_PCREL14F:
3237
0
    case R_PARISC_LTOFF_TP14R:
3238
0
    case R_PARISC_LTOFF_TP14F:
3239
0
    case R_PARISC_DPREL14R:
3240
0
    case R_PARISC_DPREL14F:
3241
0
    case R_PARISC_PLTOFF14R:
3242
0
    case R_PARISC_PLTOFF14F:
3243
0
    case R_PARISC_DIR14R:
3244
0
    case R_PARISC_DIR14F:
3245
0
      return (insn & ~0x3fff) | low_sign_unext (sym_value, 14);
3246
3247
    /* PA2.0W LDO and integer loads/stores with 16 bit displacements.  */
3248
0
    case R_PARISC_LTOFF_FPTR16F:
3249
0
    case R_PARISC_PCREL16F:
3250
0
    case R_PARISC_LTOFF_TP16F:
3251
0
    case R_PARISC_GPREL16F:
3252
0
    case R_PARISC_PLTOFF16F:
3253
0
    case R_PARISC_DIR16F:
3254
0
    case R_PARISC_LTOFF16F:
3255
0
      return (insn & ~0xffff) | re_assemble_16 (sym_value);
3256
3257
    /* Doubleword loads and stores with a 14 bit displacement.  */
3258
0
    case R_PARISC_DLTREL14DR:
3259
0
    case R_PARISC_DLTIND14DR:
3260
0
    case R_PARISC_LTOFF_FPTR14DR:
3261
0
    case R_PARISC_LTOFF_FPTR16DF:
3262
0
    case R_PARISC_PCREL14DR:
3263
0
    case R_PARISC_PCREL16DF:
3264
0
    case R_PARISC_LTOFF_TP14DR:
3265
0
    case R_PARISC_LTOFF_TP16DF:
3266
0
    case R_PARISC_DPREL14DR:
3267
0
    case R_PARISC_GPREL16DF:
3268
0
    case R_PARISC_PLTOFF14DR:
3269
0
    case R_PARISC_PLTOFF16DF:
3270
0
    case R_PARISC_DIR14DR:
3271
0
    case R_PARISC_DIR16DF:
3272
0
    case R_PARISC_LTOFF16DF:
3273
0
      return (insn & ~0x3ff1) | (((sym_value & 0x2000) >> 13)
3274
0
         | ((sym_value & 0x1ff8) << 1));
3275
3276
    /* Floating point single word load/store instructions.  */
3277
0
    case R_PARISC_DLTREL14WR:
3278
0
    case R_PARISC_DLTIND14WR:
3279
0
    case R_PARISC_LTOFF_FPTR14WR:
3280
0
    case R_PARISC_LTOFF_FPTR16WF:
3281
0
    case R_PARISC_PCREL14WR:
3282
0
    case R_PARISC_PCREL16WF:
3283
0
    case R_PARISC_LTOFF_TP14WR:
3284
0
    case R_PARISC_LTOFF_TP16WF:
3285
0
    case R_PARISC_DPREL14WR:
3286
0
    case R_PARISC_GPREL16WF:
3287
0
    case R_PARISC_PLTOFF14WR:
3288
0
    case R_PARISC_PLTOFF16WF:
3289
0
    case R_PARISC_DIR16WF:
3290
0
    case R_PARISC_DIR14WR:
3291
0
    case R_PARISC_LTOFF16WF:
3292
0
      return (insn & ~0x3ff9) | (((sym_value & 0x2000) >> 13)
3293
0
         | ((sym_value & 0x1ffc) << 1));
3294
3295
0
    default:
3296
0
      return insn;
3297
0
    }
3298
0
}
3299
3300
/* Output DLT relocation for a local symbol.  */
3301
3302
static void
3303
elf_hppa_dlt_dynrel_reloc (Elf_Internal_Rela *rel,
3304
         bfd_vma relocation,
3305
         struct bfd_link_info *info,
3306
         asection *sym_sec,
3307
         bfd_vma dlt_offset,
3308
         int dynrel_type)
3309
0
{
3310
0
  Elf_Internal_Rela rela;
3311
0
  bfd_byte *loc;
3312
0
  long dynindx;
3313
0
  struct elf_link_hash_entry *baseh;
3314
0
  asection *sec;
3315
0
  asection *sdlt, *sdltrel;
3316
0
  bfd_signed_vma addend = rel->r_addend;
3317
0
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3318
3319
0
  sdlt = hppa_info->dlt_sec;
3320
0
  sdltrel = hppa_info->dlt_rel_sec;
3321
3322
  /* The offset of this relocation is the absolute address
3323
     of the .dlt entry.  */
3324
0
  rela.r_offset = dlt_offset + sdlt->output_offset + sdlt->output_section->vma;
3325
3326
0
  if (sym_sec->flags & SEC_READONLY)
3327
0
    baseh = hppa_info->text_hash_entry;
3328
0
  else
3329
0
    baseh = hppa_info->data_hash_entry;
3330
3331
0
  sec = baseh->root.u.def.section;
3332
0
  dynindx = baseh->dynindx;
3333
3334
  /* Adjust addend using the difference of the symbol's
3335
     location and the section symbol's address.  */
3336
0
  rela.r_addend = (relocation + addend - sec->output_offset
3337
0
       - sec->output_section->vma);
3338
3339
0
  rela.r_info = ELF64_R_INFO (dynindx, dynrel_type);
3340
3341
0
  loc = sdltrel->contents;
3342
0
  loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela);
3343
0
  bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
3344
0
}
3345
3346
/* Output OPD EPLT relocation for a local symbol.  */
3347
3348
static void
3349
elf_hppa_opd_eplt_reloc (Elf_Internal_Rela *rel,
3350
       bfd_vma relocation,
3351
       struct bfd_link_info *info,
3352
       bfd_vma opd_offset)
3353
0
{
3354
0
  Elf_Internal_Rela rela;
3355
0
  bfd_byte *loc;
3356
0
  long dynindx;
3357
0
  asection *sopd, *sopdrel;
3358
0
  asection *sec;
3359
0
  bfd_vma value;
3360
0
  bfd_signed_vma addend = rel->r_addend;
3361
0
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3362
3363
0
  sopd = hppa_info->opd_sec;
3364
0
  sopdrel = hppa_info->opd_rel_sec;
3365
3366
  /* We need a EPLT relocation if we are building a shared library.  */
3367
0
  if (bfd_link_pic (info))
3368
0
    {
3369
      /* The offset of the EPLT relocation is the absolute address
3370
   of the .opd entry for this symbol.  */
3371
0
      rela.r_offset = (opd_offset + sopd->output_offset
3372
0
           + sopd->output_section->vma);
3373
3374
      /* Select text base segment and its dynindx.  */
3375
0
      sec = hppa_info->text_hash_entry->root.u.def.section;
3376
0
      dynindx = hppa_info->text_hash_entry->dynindx;
3377
3378
      /* Adjust the addend with the difference between the
3379
   symbol's address and the base segment's address.  */
3380
0
      value = (relocation + addend - sec->output_offset
3381
0
         - sec->output_section->vma);
3382
3383
      /* The result becomes the addend of the relocation.  */
3384
0
      rela.r_addend = value;
3385
3386
0
      rela.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT);
3387
3388
0
      loc = sopdrel->contents;
3389
0
      loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela);
3390
0
      bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
3391
0
    }
3392
0
}
3393
3394
/* Output OPD FPTR64 relocation for a local symbol.  */
3395
3396
static void
3397
elf_hppa_opd_fptr_reloc (struct bfd_link_info *info,
3398
       bfd_vma opd_offset,
3399
       bfd_vma fptr_offset)
3400
0
{
3401
0
  Elf_Internal_Rela rela;
3402
0
  bfd_byte *loc;
3403
0
  long dynindx;
3404
0
  asection *sopd;
3405
0
  asection *sec, *s;
3406
0
  bfd_vma value;
3407
0
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3408
3409
0
  sopd = hppa_info->opd_sec;
3410
3411
  /* FPTR offset.  */
3412
0
  rela.r_offset = fptr_offset;
3413
3414
  /* OPD's address.  */
3415
0
  value = opd_offset + sopd->output_offset + sopd->output_section->vma;
3416
3417
  /* Select data base segment and its dynindx.  */
3418
0
  sec = hppa_info->data_hash_entry->root.u.def.section;
3419
0
  dynindx = hppa_info->data_hash_entry->dynindx;
3420
3421
  /* Compute the difference between the opd's address
3422
     and the base segment's address.  */
3423
0
  value -= sec->output_offset + sec->output_section->vma;
3424
3425
  /* The result becomes the addend of the relocation.  */
3426
0
  rela.r_addend = value;
3427
3428
0
  rela.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64);
3429
3430
0
  s = hppa_info->other_rel_sec;
3431
0
  loc = s->contents;
3432
0
  BFD_ASSERT (s->reloc_count * sizeof (Elf64_External_Rela) < s->size);
3433
0
  loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
3434
0
  bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
3435
0
}
3436
3437
/* Compute the value for a relocation (REL) during a final link stage,
3438
   then insert the value into the proper location in CONTENTS.
3439
3440
   VALUE is a tentative value for the relocation and may be overridden
3441
   and modified here based on the specific relocation to be performed.
3442
3443
   For example we do conversions for PC-relative branches in this routine
3444
   or redirection of calls to external routines to stubs.
3445
3446
   The work of actually applying the relocation is left to a helper
3447
   routine in an attempt to reduce the complexity and size of this
3448
   function.  */
3449
3450
static bfd_reloc_status_type
3451
elf_hppa_final_link_relocate (Elf_Internal_Rela *rel,
3452
            bfd *input_bfd,
3453
            bfd *output_bfd,
3454
            asection *input_section,
3455
            bfd_byte *contents,
3456
            bfd_vma value,
3457
            struct bfd_link_info *info,
3458
            Elf_Internal_Sym *sym,
3459
            asection *sym_sec,
3460
            struct elf_link_hash_entry *eh)
3461
0
{
3462
0
  struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
3463
0
  struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh);
3464
0
  bfd_vma *local_offsets;
3465
0
  Elf_Internal_Shdr *symtab_hdr;
3466
0
  int insn;
3467
0
  bfd_vma max_branch_offset = 0;
3468
0
  bfd_vma offset = rel->r_offset;
3469
0
  bfd_signed_vma addend = rel->r_addend;
3470
0
  reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
3471
0
  unsigned int r_symndx = ELF_R_SYM (rel->r_info);
3472
0
  unsigned int r_type = howto->type;
3473
0
  bfd_byte *hit_data = contents + offset;
3474
3475
0
  if (hppa_info == NULL)
3476
0
    return bfd_reloc_notsupported;
3477
3478
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
3479
0
  local_offsets = elf_local_got_offsets (input_bfd);
3480
0
  insn = bfd_get_32 (input_bfd, hit_data);
3481
3482
0
  switch (r_type)
3483
0
    {
3484
0
    case R_PARISC_NONE:
3485
0
      return bfd_reloc_ok;
3486
3487
    /* Basic function call support.
3488
3489
       Note for a call to a function defined in another dynamic library
3490
       we want to redirect the call to a stub.  */
3491
3492
    /* PC relative relocs without an implicit offset.  */
3493
0
    case R_PARISC_PCREL21L:
3494
0
    case R_PARISC_PCREL14R:
3495
0
    case R_PARISC_PCREL14F:
3496
0
    case R_PARISC_PCREL14WR:
3497
0
    case R_PARISC_PCREL14DR:
3498
0
    case R_PARISC_PCREL16F:
3499
0
    case R_PARISC_PCREL16WF:
3500
0
    case R_PARISC_PCREL16DF:
3501
0
      {
3502
  /* If this is a pc-relative call to a dynamic function, then
3503
     redirect the call to the local stub for this function.  */
3504
0
  if (hh && hh->want_stub)
3505
0
    value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3506
0
       + hppa_info->stub_sec->output_section->vma);
3507
3508
  /* Turn VALUE into a proper PC relative address.  */
3509
0
  value -= (offset + input_section->output_offset
3510
0
      + input_section->output_section->vma);
3511
3512
  /* Adjust for any field selectors.  */
3513
0
  if (r_type == R_PARISC_PCREL21L)
3514
0
    value = hppa_field_adjust (value, -8 + addend, e_lsel);
3515
0
  else if (r_type == R_PARISC_PCREL14F
3516
0
     || r_type == R_PARISC_PCREL16F
3517
0
     || r_type == R_PARISC_PCREL16WF
3518
0
     || r_type == R_PARISC_PCREL16DF)
3519
0
    value = hppa_field_adjust (value, -8 + addend, e_fsel);
3520
0
  else
3521
0
    value = hppa_field_adjust (value, -8 + addend, e_rsel);
3522
3523
  /* Apply the relocation to the given instruction.  */
3524
0
  insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3525
0
  break;
3526
0
      }
3527
3528
0
    case R_PARISC_PCREL12F:
3529
0
    case R_PARISC_PCREL22F:
3530
0
    case R_PARISC_PCREL17F:
3531
0
    case R_PARISC_PCREL22C:
3532
0
    case R_PARISC_PCREL17C:
3533
0
    case R_PARISC_PCREL17R:
3534
0
      {
3535
  /* If this is a pc-relative call to a dynamic function, then
3536
     redirect the call to the local stub for this function.  */
3537
0
  if (hh && hh->want_stub)
3538
0
    value = (hh->stub_offset + hppa_info->stub_sec->output_offset
3539
0
       + hppa_info->stub_sec->output_section->vma);
3540
3541
  /* Turn VALUE into a proper PC relative address.  */
3542
0
  value -= (offset + input_section->output_offset
3543
0
      + input_section->output_section->vma);
3544
0
  addend -= 8;
3545
3546
0
  if (r_type == (unsigned int) R_PARISC_PCREL22F)
3547
0
    max_branch_offset = (1 << (22-1)) << 2;
3548
0
  else if (r_type == (unsigned int) R_PARISC_PCREL17F)
3549
0
    max_branch_offset = (1 << (17-1)) << 2;
3550
0
  else if (r_type == (unsigned int) R_PARISC_PCREL12F)
3551
0
    max_branch_offset = (1 << (12-1)) << 2;
3552
3553
  /* Make sure we can reach the branch target.  */
3554
0
  if (max_branch_offset != 0
3555
0
      && value + addend + max_branch_offset >= 2*max_branch_offset)
3556
0
    {
3557
0
      _bfd_error_handler
3558
        /* xgettext:c-format */
3559
0
        (_("%pB(%pA+%#" PRIx64 "): cannot reach %s"),
3560
0
        input_bfd,
3561
0
        input_section,
3562
0
        (uint64_t) offset,
3563
0
        eh ? eh->root.root.string : "unknown");
3564
0
      bfd_set_error (bfd_error_bad_value);
3565
0
      return bfd_reloc_overflow;
3566
0
    }
3567
3568
  /* Adjust for any field selectors.  */
3569
0
  if (r_type == R_PARISC_PCREL17R)
3570
0
    value = hppa_field_adjust (value, addend, e_rsel);
3571
0
  else
3572
0
    value = hppa_field_adjust (value, addend, e_fsel);
3573
3574
  /* All branches are implicitly shifted by 2 places.  */
3575
0
  value >>= 2;
3576
3577
  /* Apply the relocation to the given instruction.  */
3578
0
  insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3579
0
  break;
3580
0
      }
3581
3582
    /* Indirect references to data through the DLT.  */
3583
0
    case R_PARISC_DLTIND14R:
3584
0
    case R_PARISC_DLTIND14F:
3585
0
    case R_PARISC_DLTIND14DR:
3586
0
    case R_PARISC_DLTIND14WR:
3587
0
    case R_PARISC_DLTIND21L:
3588
0
    case R_PARISC_LTOFF_FPTR14R:
3589
0
    case R_PARISC_LTOFF_FPTR14DR:
3590
0
    case R_PARISC_LTOFF_FPTR14WR:
3591
0
    case R_PARISC_LTOFF_FPTR21L:
3592
0
    case R_PARISC_LTOFF_FPTR16F:
3593
0
    case R_PARISC_LTOFF_FPTR16WF:
3594
0
    case R_PARISC_LTOFF_FPTR16DF:
3595
0
    case R_PARISC_LTOFF_TP21L:
3596
0
    case R_PARISC_LTOFF_TP14R:
3597
0
    case R_PARISC_LTOFF_TP14F:
3598
0
    case R_PARISC_LTOFF_TP14WR:
3599
0
    case R_PARISC_LTOFF_TP14DR:
3600
0
    case R_PARISC_LTOFF_TP16F:
3601
0
    case R_PARISC_LTOFF_TP16WF:
3602
0
    case R_PARISC_LTOFF_TP16DF:
3603
0
    case R_PARISC_LTOFF16F:
3604
0
    case R_PARISC_LTOFF16WF:
3605
0
    case R_PARISC_LTOFF16DF:
3606
0
      {
3607
0
  bfd_vma dlt_off, fptr_off, opd_off;
3608
0
  bfd_vma relocation = value;
3609
0
  asection *sopd;
3610
0
  bool need_dlt_reloc = false;
3611
0
  int dynrel_type = R_PARISC_NONE;
3612
3613
0
  sopd = hppa_info->opd_sec;
3614
3615
  /* If this relocation was against a local symbol, then we still
3616
     have not set up the DLT entry (it's not convenient to do so
3617
     in the "finalize_dlt" routine because it is difficult to get
3618
     to the local symbol's value).
3619
3620
     So, if this is a local symbol (h == NULL), then we need to
3621
     fill in its DLT entry.
3622
3623
     Similarly we may still need to set up an entry in .opd for
3624
     a local function which had its address taken.  */
3625
0
  if (hh == NULL)
3626
0
    {
3627
0
      bfd_vma *local_opd_offsets, *local_dlt_offsets;
3628
3629
0
      if (local_offsets == NULL)
3630
0
        abort ();
3631
3632
0
      local_dlt_offsets = local_offsets;
3633
0
      dlt_off = local_dlt_offsets[r_symndx];
3634
3635
0
      if ((dlt_off & 1) != 0)
3636
0
        {
3637
0
    BFD_ASSERT (dlt_off != (bfd_vma) -1);
3638
0
    dlt_off &= ~1;
3639
0
        }
3640
0
      else
3641
0
        {
3642
0
    local_dlt_offsets[r_symndx] |= 1;
3643
3644
0
    if (bfd_link_pic (info))
3645
0
      {
3646
0
        if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
3647
0
          dynrel_type = R_PARISC_FPTR64;
3648
0
        else
3649
0
          dynrel_type = R_PARISC_DIR64;
3650
0
        need_dlt_reloc = true;
3651
0
      }
3652
3653
0
    bfd_put_64 (hppa_info->dlt_sec->owner,
3654
0
          value + addend,
3655
0
          hppa_info->dlt_sec->contents + dlt_off);
3656
0
        }
3657
3658
      /* Now do .opd creation if needed.  */
3659
0
      if (r_type == R_PARISC_LTOFF_FPTR14R
3660
0
    || r_type == R_PARISC_LTOFF_FPTR14DR
3661
0
    || r_type == R_PARISC_LTOFF_FPTR14WR
3662
0
    || r_type == R_PARISC_LTOFF_FPTR21L
3663
0
    || r_type == R_PARISC_LTOFF_FPTR16F
3664
0
    || r_type == R_PARISC_LTOFF_FPTR16WF
3665
0
    || r_type == R_PARISC_LTOFF_FPTR16DF)
3666
0
        {
3667
0
    local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
3668
0
    opd_off = local_opd_offsets[r_symndx];
3669
3670
    /* The last bit records whether we've already initialised
3671
       this local .opd entry.  */
3672
0
    if ((opd_off & 1) != 0)
3673
0
      {
3674
0
        BFD_ASSERT (opd_off != (bfd_vma) -1);
3675
0
        opd_off &= ~1;
3676
0
      }
3677
0
    else
3678
0
      {
3679
0
        local_opd_offsets[r_symndx] |= 1;
3680
3681
        /* If we are building a shared library, we need an EPLT
3682
           relocation for each OPD entry.  */
3683
0
        elf_hppa_opd_eplt_reloc (rel, relocation, info, opd_off);
3684
3685
        /* Adjust the relocation to point to the OPD.  */
3686
0
        relocation = (opd_off + sopd->output_offset
3687
0
          + sopd->output_section->vma);
3688
0
        sym_sec = sopd;
3689
0
        rel->r_addend = 0;
3690
0
        need_dlt_reloc = true;
3691
0
        dynrel_type = R_PARISC_FPTR64;
3692
3693
        /* The third word is the address of the function.  */
3694
0
        bfd_put_64 (sopd->owner, value + addend,
3695
0
        sopd->contents + opd_off + 16);
3696
3697
        /* The last word is our local __gp value.  */
3698
0
        value = _bfd_get_gp_value (info->output_bfd);
3699
0
        bfd_put_64 (sopd->owner, value,
3700
0
        sopd->contents + opd_off + 24);
3701
0
      }
3702
3703
    /* Output a FPTR64 relocation for dynamic local symbols.
3704
       Note dynamic relocs are not propagated for SEC_DEBUGGING
3705
       sections because such sections are not SEC_ALLOC and thus
3706
       ld.so will not process them.  */
3707
0
    if (bfd_link_pic (info)
3708
0
        && (input_section->flags & SEC_DEBUGGING) == 0
3709
0
        && _bfd_elf_link_lookup_local_dynindx (info, input_bfd,
3710
0
                 r_symndx) != -1)
3711
0
      {
3712
        /* FPTR offset is absolute address of DLT entry.  */
3713
0
        fptr_off = (dlt_off
3714
0
        + hppa_info->dlt_sec->output_offset
3715
0
        + hppa_info->dlt_sec->output_section->vma);
3716
3717
        /* Output FPTR64 relocation for local symbol.  */
3718
0
        elf_hppa_opd_fptr_reloc (info, opd_off, fptr_off);
3719
0
      }
3720
0
        }
3721
0
    }
3722
0
  else
3723
0
    dlt_off = hh->dlt_offset;
3724
3725
0
  if (need_dlt_reloc)
3726
0
    elf_hppa_dlt_dynrel_reloc (rel, relocation, info, sym_sec,
3727
0
             dlt_off, dynrel_type);
3728
3729
  /* We want the value of the DLT offset for this symbol, not
3730
     the symbol's actual address.  Note that __gp may not point
3731
     to the start of the DLT, so we have to compute the absolute
3732
     address, then subtract out the value of __gp.  */
3733
0
  value = (dlt_off
3734
0
     + hppa_info->dlt_sec->output_offset
3735
0
     + hppa_info->dlt_sec->output_section->vma);
3736
0
  value -= _bfd_get_gp_value (output_bfd);
3737
3738
  /* All DLTIND relocations are basically the same at this point,
3739
     except that we need different field selectors for the 21bit
3740
     version vs the 14bit versions.  */
3741
0
  if (r_type == R_PARISC_DLTIND21L
3742
0
      || r_type == R_PARISC_LTOFF_FPTR21L
3743
0
      || r_type == R_PARISC_LTOFF_TP21L)
3744
0
    value = hppa_field_adjust (value, 0, e_lsel);
3745
0
  else if (r_type == R_PARISC_DLTIND14F
3746
0
     || r_type == R_PARISC_LTOFF_FPTR16F
3747
0
     || r_type == R_PARISC_LTOFF_FPTR16WF
3748
0
     || r_type == R_PARISC_LTOFF_FPTR16DF
3749
0
     || r_type == R_PARISC_LTOFF16F
3750
0
     || r_type == R_PARISC_LTOFF16DF
3751
0
     || r_type == R_PARISC_LTOFF16WF
3752
0
     || r_type == R_PARISC_LTOFF_TP16F
3753
0
     || r_type == R_PARISC_LTOFF_TP16WF
3754
0
     || r_type == R_PARISC_LTOFF_TP16DF)
3755
0
    value = hppa_field_adjust (value, 0, e_fsel);
3756
0
  else
3757
0
    value = hppa_field_adjust (value, 0, e_rsel);
3758
3759
0
  insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3760
0
  break;
3761
0
      }
3762
3763
0
    case R_PARISC_DLTREL14R:
3764
0
    case R_PARISC_DLTREL14F:
3765
0
    case R_PARISC_DLTREL14DR:
3766
0
    case R_PARISC_DLTREL14WR:
3767
0
    case R_PARISC_DLTREL21L:
3768
0
    case R_PARISC_DPREL21L:
3769
0
    case R_PARISC_DPREL14WR:
3770
0
    case R_PARISC_DPREL14DR:
3771
0
    case R_PARISC_DPREL14R:
3772
0
    case R_PARISC_DPREL14F:
3773
0
    case R_PARISC_GPREL16F:
3774
0
    case R_PARISC_GPREL16WF:
3775
0
    case R_PARISC_GPREL16DF:
3776
0
      {
3777
  /* Subtract out the global pointer value to make value a DLT
3778
     relative address.  */
3779
0
  value -= _bfd_get_gp_value (output_bfd);
3780
3781
  /* All DLTREL relocations are basically the same at this point,
3782
     except that we need different field selectors for the 21bit
3783
     version vs the 14bit versions.  */
3784
0
  if (r_type == R_PARISC_DLTREL21L
3785
0
      || r_type == R_PARISC_DPREL21L)
3786
0
    value = hppa_field_adjust (value, addend, e_lrsel);
3787
0
  else if (r_type == R_PARISC_DLTREL14F
3788
0
     || r_type == R_PARISC_DPREL14F
3789
0
     || r_type == R_PARISC_GPREL16F
3790
0
     || r_type == R_PARISC_GPREL16WF
3791
0
     || r_type == R_PARISC_GPREL16DF)
3792
0
    value = hppa_field_adjust (value, addend, e_fsel);
3793
0
  else
3794
0
    value = hppa_field_adjust (value, addend, e_rrsel);
3795
3796
0
  insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3797
0
  break;
3798
0
      }
3799
3800
0
    case R_PARISC_DIR21L:
3801
0
    case R_PARISC_DIR17R:
3802
0
    case R_PARISC_DIR17F:
3803
0
    case R_PARISC_DIR14R:
3804
0
    case R_PARISC_DIR14F:
3805
0
    case R_PARISC_DIR14WR:
3806
0
    case R_PARISC_DIR14DR:
3807
0
    case R_PARISC_DIR16F:
3808
0
    case R_PARISC_DIR16WF:
3809
0
    case R_PARISC_DIR16DF:
3810
0
      {
3811
  /* All DIR relocations are basically the same at this point,
3812
     except that branch offsets need to be divided by four, and
3813
     we need different field selectors.  Note that we don't
3814
     redirect absolute calls to local stubs.  */
3815
3816
0
  if (r_type == R_PARISC_DIR21L)
3817
0
    value = hppa_field_adjust (value, addend, e_lrsel);
3818
0
  else if (r_type == R_PARISC_DIR17F
3819
0
     || r_type == R_PARISC_DIR16F
3820
0
     || r_type == R_PARISC_DIR16WF
3821
0
     || r_type == R_PARISC_DIR16DF
3822
0
     || r_type == R_PARISC_DIR14F)
3823
0
    value = hppa_field_adjust (value, addend, e_fsel);
3824
0
  else
3825
0
    value = hppa_field_adjust (value, addend, e_rrsel);
3826
3827
0
  if (r_type == R_PARISC_DIR17R || r_type == R_PARISC_DIR17F)
3828
    /* All branches are implicitly shifted by 2 places.  */
3829
0
    value >>= 2;
3830
3831
0
  insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3832
0
  break;
3833
0
      }
3834
3835
0
    case R_PARISC_PLTOFF21L:
3836
0
    case R_PARISC_PLTOFF14R:
3837
0
    case R_PARISC_PLTOFF14F:
3838
0
    case R_PARISC_PLTOFF14WR:
3839
0
    case R_PARISC_PLTOFF14DR:
3840
0
    case R_PARISC_PLTOFF16F:
3841
0
    case R_PARISC_PLTOFF16WF:
3842
0
    case R_PARISC_PLTOFF16DF:
3843
0
      {
3844
  /* We want the value of the PLT offset for this symbol, not
3845
     the symbol's actual address.  Note that __gp may not point
3846
     to the start of the DLT, so we have to compute the absolute
3847
     address, then subtract out the value of __gp.  */
3848
0
  value = (hh->plt_offset
3849
0
     + hppa_info->root.splt->output_offset
3850
0
     + hppa_info->root.splt->output_section->vma);
3851
0
  value -= _bfd_get_gp_value (output_bfd);
3852
3853
  /* All PLTOFF relocations are basically the same at this point,
3854
     except that we need different field selectors for the 21bit
3855
     version vs the 14bit versions.  */
3856
0
  if (r_type == R_PARISC_PLTOFF21L)
3857
0
    value = hppa_field_adjust (value, addend, e_lrsel);
3858
0
  else if (r_type == R_PARISC_PLTOFF14F
3859
0
     || r_type == R_PARISC_PLTOFF16F
3860
0
     || r_type == R_PARISC_PLTOFF16WF
3861
0
     || r_type == R_PARISC_PLTOFF16DF)
3862
0
    value = hppa_field_adjust (value, addend, e_fsel);
3863
0
  else
3864
0
    value = hppa_field_adjust (value, addend, e_rrsel);
3865
3866
0
  insn = elf_hppa_relocate_insn (insn, (int) value, r_type);
3867
0
  break;
3868
0
      }
3869
3870
0
    case R_PARISC_LTOFF_FPTR32:
3871
0
      {
3872
  /* FIXME: There used to be code here to create the FPTR itself if
3873
     the relocation was against a local symbol.  But the code could
3874
     never have worked.  If the assert below is ever triggered then
3875
     the code will need to be reinstated and fixed so that it does
3876
     what is needed.  */
3877
0
  BFD_ASSERT (hh != NULL);
3878
3879
  /* We want the value of the DLT offset for this symbol, not
3880
     the symbol's actual address.  Note that __gp may not point
3881
     to the start of the DLT, so we have to compute the absolute
3882
     address, then subtract out the value of __gp.  */
3883
0
  value = (hh->dlt_offset
3884
0
     + hppa_info->dlt_sec->output_offset
3885
0
     + hppa_info->dlt_sec->output_section->vma);
3886
0
  value -= _bfd_get_gp_value (output_bfd);
3887
0
  bfd_put_32 (output_bfd, value, hit_data);
3888
0
  return bfd_reloc_ok;
3889
0
      }
3890
3891
0
    case R_PARISC_LTOFF_FPTR64:
3892
0
    case R_PARISC_LTOFF_TP64:
3893
0
      {
3894
0
  bfd_vma relocation = value;
3895
0
  bfd_vma *local_opd_offsets, *local_dlt_offsets;
3896
0
  bfd_vma dlt_off, fptr_off;
3897
0
  bfd_vma opd_off = (bfd_vma) -1;
3898
0
  bool need_dlt_reloc = false;
3899
0
  int dynrel_type = R_PARISC_NONE;
3900
3901
0
  if (eh == NULL)
3902
0
    {
3903
0
      local_dlt_offsets = local_offsets;
3904
0
      dlt_off = local_dlt_offsets[r_symndx];
3905
3906
0
      if ((dlt_off & 1) != 0)
3907
0
        {
3908
0
    BFD_ASSERT (dlt_off != (bfd_vma) -1);
3909
0
    dlt_off &= ~1;
3910
0
        }
3911
0
      else
3912
0
        {
3913
0
    local_dlt_offsets[r_symndx] |= 1;
3914
0
    if (bfd_link_pic (info))
3915
0
      {
3916
0
        if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
3917
0
          dynrel_type = R_PARISC_FPTR64;
3918
0
        else
3919
0
          dynrel_type = R_PARISC_DIR64;
3920
0
        need_dlt_reloc = true;
3921
0
      }
3922
0
        }
3923
3924
0
      if (r_type == R_PARISC_LTOFF_FPTR64)
3925
0
        {
3926
0
    local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
3927
0
    opd_off = local_opd_offsets[r_symndx];
3928
3929
    /* The last bit records whether we've already initialised
3930
       this local .opd entry.  */
3931
0
    if ((opd_off & 1) != 0)
3932
0
      {
3933
0
        BFD_ASSERT (opd_off != (bfd_vma) -1);
3934
0
        opd_off &= ~1;
3935
0
      }
3936
0
    else
3937
0
      {
3938
0
        asection *sopd = hppa_info->opd_sec;
3939
3940
0
        local_opd_offsets[r_symndx] |= 1;
3941
3942
        /* If we are building a shared library, we need an EPLT
3943
           relocation for each OPD entry.  */
3944
0
        elf_hppa_opd_eplt_reloc (rel, relocation, info, opd_off);
3945
3946
        /* Adjust the DLT relocation to point to the OPD.  */
3947
0
        relocation = (opd_off + sopd->output_offset
3948
0
          + sopd->output_section->vma);
3949
0
        sym_sec = sopd;
3950
0
        rel->r_addend = 0;
3951
0
        need_dlt_reloc = true;
3952
0
        dynrel_type = R_PARISC_FPTR64;
3953
0
      }
3954
3955
    /* Output a FPTR64 relocation for dynamic local symbols.
3956
       Note dynamic relocs are not propagated for SEC_DEBUGGING
3957
       sections because such sections are not SEC_ALLOC and thus
3958
       ld.so will not process them.  */
3959
0
    if (bfd_link_pic (info)
3960
0
        && (input_section->flags & SEC_DEBUGGING) == 0
3961
0
        && _bfd_elf_link_lookup_local_dynindx (info, input_bfd,
3962
0
                 r_symndx) != -1)
3963
0
      {
3964
        /* FPTR offset is absolute address of DLT entry.  */
3965
0
        fptr_off = (dlt_off
3966
0
        + hppa_info->dlt_sec->output_offset
3967
0
        + hppa_info->dlt_sec->output_section->vma);
3968
3969
        /* Output FPTR64 relocation for local symbol.  */
3970
0
        elf_hppa_opd_fptr_reloc (info, opd_off, fptr_off);
3971
0
      }
3972
0
        }
3973
0
    }
3974
0
  else
3975
0
    {
3976
0
      opd_off = hh->opd_offset;
3977
0
      dlt_off = hh->dlt_offset;
3978
0
    }
3979
3980
0
  if (need_dlt_reloc)
3981
0
    elf_hppa_dlt_dynrel_reloc (rel, relocation, info, sym_sec,
3982
0
             dlt_off, dynrel_type);
3983
3984
  /* We may still need to create the FPTR itself if it was for
3985
     a local symbol.  */
3986
0
  if (eh == NULL && r_type == R_PARISC_LTOFF_FPTR64)
3987
0
    {
3988
      /* The first word is the address of the function.  */
3989
0
      bfd_put_64 (hppa_info->opd_sec->owner, value + addend,
3990
0
      (hppa_info->opd_sec->contents + opd_off + 16));
3991
3992
      /* The last word is our local __gp value.  */
3993
0
      value = _bfd_get_gp_value (info->output_bfd);
3994
0
      bfd_put_64 (hppa_info->opd_sec->owner, value,
3995
0
      hppa_info->opd_sec->contents + opd_off + 24);
3996
3997
      /* The DLT value is the address of the .opd entry.  */
3998
0
      value = (opd_off
3999
0
         + hppa_info->opd_sec->output_offset
4000
0
         + hppa_info->opd_sec->output_section->vma);
4001
4002
0
      bfd_put_64 (hppa_info->dlt_sec->owner,
4003
0
      value,
4004
0
      hppa_info->dlt_sec->contents + dlt_off);
4005
0
    }
4006
4007
  /* We want the value of the DLT offset for this symbol, not
4008
     the symbol's actual address.  Note that __gp may not point
4009
     to the start of the DLT, so we have to compute the absolute
4010
     address, then subtract out the value of __gp.  */
4011
0
  value = (dlt_off
4012
0
     + hppa_info->dlt_sec->output_offset
4013
0
     + hppa_info->dlt_sec->output_section->vma);
4014
0
  value -= _bfd_get_gp_value (output_bfd);
4015
0
  bfd_put_64 (output_bfd, value, hit_data);
4016
0
  return bfd_reloc_ok;
4017
0
      }
4018
4019
0
    case R_PARISC_DIR32:
4020
0
      bfd_put_32 (output_bfd, value + addend, hit_data);
4021
0
      return bfd_reloc_ok;
4022
4023
0
    case R_PARISC_DIR64:
4024
0
      if (hh == NULL)
4025
0
  {
4026
0
    long dynindx;
4027
0
    Elf_Internal_Rela rela;
4028
0
    bfd_byte *loc;
4029
0
    asection *s, *sec;
4030
4031
    /* Output a DIR64 relocation for dynamic local symbols.
4032
       Note dynamic relocs are not propagated for SEC_DEBUGGING
4033
       sections because such sections are not SEC_ALLOC and thus
4034
       ld.so will not process them.  */
4035
0
    if (bfd_link_pic (info)
4036
0
        && (input_section->flags & SEC_DEBUGGING) == 0
4037
0
        && _bfd_elf_link_lookup_local_dynindx (info, input_bfd,
4038
0
                 r_symndx) != -1)
4039
0
      {
4040
0
        bfd_vma out_off;
4041
0
        bool skip;
4042
0
        struct elf_link_hash_entry *baseh;
4043
4044
0
        out_off = _bfd_elf_section_offset (output_bfd, info,
4045
0
             input_section,
4046
0
             rel->r_offset);
4047
0
        skip = out_off == (bfd_vma) -1 || out_off == (bfd_vma) -2;
4048
4049
        /* The HP dynamic linker doesn't support relocations with
4050
     the R_PARISC_NONE type.  So, we can't just output a zero
4051
     relocation if we encounter an invalid offset.  We reserve
4052
     16 bytes at the start of the data section that aren't
4053
     used.  */
4054
0
        if (skip && output_bfd->xvec == &hppa_elf64_vec)
4055
0
    {
4056
      /* Set the relocation offset to the start of the
4057
         data section.  */
4058
0
      skip = false;
4059
0
      baseh = hppa_info->data_hash_entry;
4060
0
      sec = baseh->root.u.def.section;
4061
0
      rela.r_offset = (sec->output_offset
4062
0
           + sec->output_section->vma);
4063
0
    }
4064
0
        else if (!skip)
4065
0
    {
4066
      /* This is the output relocation offset.  */
4067
0
      rela.r_offset = (out_off
4068
0
           + input_section->output_offset
4069
0
           + input_section->output_section->vma);
4070
0
    }
4071
4072
0
        if (skip)
4073
0
    memset (&rela, 0, sizeof (rela));
4074
0
        else
4075
0
    {
4076
      /* Select base segment.  */
4077
0
      if (sym_sec->flags & SEC_READONLY)
4078
0
        baseh = hppa_info->text_hash_entry;
4079
0
      else
4080
0
        baseh = hppa_info->data_hash_entry;
4081
4082
0
      sec = baseh->root.u.def.section;
4083
0
      dynindx = baseh->dynindx;
4084
4085
      /* Adjust addend using the difference of the symbol's
4086
         location and the section symbol's address.  */
4087
0
      rela.r_addend = (value + addend - sec->output_offset
4088
0
           - sec->output_section->vma);
4089
4090
      /* We need a dynamic relocation for this symbol.  */
4091
0
      rela.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64);
4092
0
    }
4093
4094
0
        s = hppa_info->other_rel_sec;
4095
0
        loc = s->contents;
4096
0
        loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
4097
0
        bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
4098
0
      }
4099
0
  }
4100
4101
0
      bfd_put_64 (output_bfd, value + addend, hit_data);
4102
0
      return bfd_reloc_ok;
4103
4104
0
    case R_PARISC_GPREL64:
4105
      /* Subtract out the global pointer value to make value a DLT
4106
   relative address.  */
4107
0
      value -= _bfd_get_gp_value (output_bfd);
4108
4109
0
      bfd_put_64 (output_bfd, value + addend, hit_data);
4110
0
      return bfd_reloc_ok;
4111
4112
0
    case R_PARISC_LTOFF64:
4113
  /* We want the value of the DLT offset for this symbol, not
4114
     the symbol's actual address.  Note that __gp may not point
4115
     to the start of the DLT, so we have to compute the absolute
4116
     address, then subtract out the value of __gp.  */
4117
0
      value = (hh->dlt_offset
4118
0
         + hppa_info->dlt_sec->output_offset
4119
0
         + hppa_info->dlt_sec->output_section->vma);
4120
0
      value -= _bfd_get_gp_value (output_bfd);
4121
4122
0
      bfd_put_64 (output_bfd, value + addend, hit_data);
4123
0
      return bfd_reloc_ok;
4124
4125
0
    case R_PARISC_PCREL32:
4126
0
      {
4127
  /* If this is a pc-relative call to a dynamic function, then
4128
     redirect the call to the local stub for this function.  */
4129
0
  if (hh && hh->want_stub)
4130
0
    value = (hh->stub_offset + hppa_info->stub_sec->output_offset
4131
0
       + hppa_info->stub_sec->output_section->vma);
4132
4133
  /* Turn VALUE into a proper PC relative address.  */
4134
0
  value -= (offset + input_section->output_offset
4135
0
      + input_section->output_section->vma);
4136
4137
0
  value += addend;
4138
0
  value -= 8;
4139
0
  bfd_put_32 (output_bfd, value, hit_data);
4140
0
  return bfd_reloc_ok;
4141
0
      }
4142
4143
0
    case R_PARISC_PCREL64:
4144
0
      {
4145
  /* If this is a pc-relative call to a dynamic function, then
4146
     redirect the call to the local stub for this function.  */
4147
0
  if (hh && hh->want_stub)
4148
0
    value = (hh->stub_offset + hppa_info->stub_sec->output_offset
4149
0
       + hppa_info->stub_sec->output_section->vma);
4150
4151
  /* Turn VALUE into a proper PC relative address.  */
4152
0
  value -= (offset + input_section->output_offset
4153
0
      + input_section->output_section->vma);
4154
4155
0
  value += addend;
4156
0
  value -= 8;
4157
0
  bfd_put_64 (output_bfd, value, hit_data);
4158
0
  return bfd_reloc_ok;
4159
0
      }
4160
4161
0
    case R_PARISC_FPTR64:
4162
0
      {
4163
0
  bfd_vma fptr_off, opd_off;
4164
0
  bfd_vma relocation = value;
4165
0
  asection *sopd;
4166
4167
0
  sopd = hppa_info->opd_sec;
4168
4169
  /* We may still need to create the FPTR itself if it was for
4170
     a local symbol.  */
4171
0
  if (hh == NULL)
4172
0
    {
4173
0
      bfd_vma *local_opd_offsets;
4174
4175
0
      if (local_offsets == NULL || symtab_hdr->sh_info == 0)
4176
0
        abort ();
4177
4178
0
      local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info;
4179
0
      opd_off = local_opd_offsets[r_symndx];
4180
4181
      /* The last bit records whether we've already initialised
4182
         this local .opd entry.  */
4183
0
      if ((opd_off & 1) != 0)
4184
0
        {
4185
0
    BFD_ASSERT (opd_off != (bfd_vma) -1);
4186
0
    opd_off &= ~1;
4187
0
        }
4188
0
      else
4189
0
        {
4190
0
    local_opd_offsets[r_symndx] |= 1;
4191
4192
0
    if (input_section->flags & SEC_READONLY)
4193
0
      {
4194
0
        _bfd_error_handler
4195
          /* xgettext:c-format */
4196
0
          (_("%pB(%pA+%#" PRIx64
4197
0
       "): R_PARISC_FPTR64 relocation in readonly section"),
4198
0
      input_bfd,
4199
0
      input_section,
4200
0
      (uint64_t) offset);
4201
0
        return bfd_reloc_notsupported;
4202
0
      }
4203
4204
    /* If we are building a shared library, we need an EPLT
4205
       relocation for each OPD entry.  */
4206
0
    elf_hppa_opd_eplt_reloc (rel, relocation, info, opd_off);
4207
4208
    /* The third word is the address of the function.  */
4209
0
    bfd_put_64 (sopd->owner, value + addend,
4210
0
          (sopd->contents + opd_off + 16));
4211
4212
    /* The last word is our local __gp value.  */
4213
0
    value = _bfd_get_gp_value (info->output_bfd);
4214
0
    bfd_put_64 (sopd->owner, value, sopd->contents + opd_off + 24);
4215
0
        }
4216
4217
      /* Output a FPTR64 relocation for dynamic local symbols.
4218
         Note dynamic relocs are not propagated for SEC_DEBUGGING
4219
         sections because such sections are not SEC_ALLOC and thus
4220
         ld.so will not process them.  */
4221
0
      if (bfd_link_pic (info)
4222
0
    && (input_section->flags & SEC_DEBUGGING) == 0
4223
0
    && _bfd_elf_link_lookup_local_dynindx (info, input_bfd,
4224
0
                   r_symndx) != -1)
4225
0
        {
4226
    /* The offset of the FPTR relocation is the absolute address
4227
       of this relocation.  */
4228
0
    fptr_off = (rel->r_offset + input_section->output_offset
4229
0
          + input_section->output_section->vma);
4230
4231
    /* Output FPTR64 relocation for local symbol.  */
4232
0
    elf_hppa_opd_fptr_reloc (info, opd_off, fptr_off);
4233
0
        }
4234
0
    }
4235
0
  else
4236
0
    opd_off = hh->opd_offset;
4237
4238
0
  if (hh == NULL || hh->want_opd)
4239
    /* We want the value of the OPD offset for this symbol.  */
4240
0
    value = opd_off + sopd->output_offset + sopd->output_section->vma;
4241
0
  else
4242
    /* We want the address of the symbol.  */
4243
0
    value += addend;
4244
4245
0
  bfd_put_64 (output_bfd, value, hit_data);
4246
0
  return bfd_reloc_ok;
4247
0
      }
4248
4249
0
    case R_PARISC_SECREL32:
4250
0
      if (sym_sec && sym_sec->output_section)
4251
0
  value -= sym_sec->output_section->vma;
4252
0
      bfd_put_32 (output_bfd, value + addend, hit_data);
4253
0
      return bfd_reloc_ok;
4254
4255
0
    case R_PARISC_SEGREL32:
4256
0
    case R_PARISC_SEGREL64:
4257
0
      {
4258
  /* Initialize the segment base values.  */
4259
0
  if (hppa_info->text_segment_base == (bfd_vma) -1)
4260
0
    bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs,
4261
0
         hppa_info);
4262
4263
  /* VALUE holds the absolute address.  We want to include the
4264
     addend, then turn it into a segment relative address.
4265
4266
     The segment is derived from SYM_SEC.  We assume that there are
4267
     only two segments of note in the resulting executable/shlib.
4268
     A readonly segment (.text) and a readwrite segment (.data).  */
4269
0
  value += addend;
4270
4271
0
  if (sym_sec->flags & SEC_CODE)
4272
0
    value -= hppa_info->text_segment_base;
4273
0
  else
4274
0
    value -= hppa_info->data_segment_base;
4275
4276
0
  if (r_type == R_PARISC_SEGREL32)
4277
0
    bfd_put_32 (output_bfd, value, hit_data);
4278
0
  else
4279
0
    bfd_put_64 (output_bfd, value, hit_data);
4280
0
  return bfd_reloc_ok;
4281
0
      }
4282
4283
    /* Something we don't know how to handle.  */
4284
0
    default:
4285
0
      return bfd_reloc_notsupported;
4286
0
    }
4287
4288
  /* Update the instruction word.  */
4289
0
  bfd_put_32 (output_bfd, (bfd_vma) insn, hit_data);
4290
0
  return bfd_reloc_ok;
4291
0
}
4292
4293
/* Relocate an HPPA ELF section.  */
4294
4295
static int
4296
elf64_hppa_relocate_section (struct bfd_link_info *info,
4297
           bfd *input_bfd,
4298
           asection *input_section,
4299
           bfd_byte *contents,
4300
           Elf_Internal_Rela *relocs,
4301
           Elf_Internal_Sym *local_syms,
4302
           asection **local_sections)
4303
0
{
4304
0
  Elf_Internal_Shdr *symtab_hdr;
4305
0
  Elf_Internal_Rela *rel;
4306
0
  Elf_Internal_Rela *relend;
4307
0
  struct elf64_hppa_link_hash_table *hppa_info;
4308
4309
0
  hppa_info = hppa_link_hash_table (info);
4310
0
  if (hppa_info == NULL)
4311
0
    return false;
4312
4313
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
4314
4315
0
  rel = relocs;
4316
0
  relend = relocs + input_section->reloc_count;
4317
0
  for (; rel < relend; rel++)
4318
0
    {
4319
0
      int r_type;
4320
0
      reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info);
4321
0
      unsigned long r_symndx;
4322
0
      struct elf_link_hash_entry *eh;
4323
0
      Elf_Internal_Sym *sym;
4324
0
      asection *sym_sec;
4325
0
      bfd_vma relocation;
4326
0
      bfd_reloc_status_type r;
4327
4328
0
      r_type = ELF_R_TYPE (rel->r_info);
4329
0
      if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED)
4330
0
  {
4331
0
    bfd_set_error (bfd_error_bad_value);
4332
0
    return false;
4333
0
  }
4334
0
      if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
4335
0
    || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT)
4336
0
  continue;
4337
4338
      /* This is a final link.  */
4339
0
      r_symndx = ELF_R_SYM (rel->r_info);
4340
0
      eh = NULL;
4341
0
      sym = NULL;
4342
0
      sym_sec = NULL;
4343
0
      if (r_symndx < symtab_hdr->sh_info)
4344
0
  {
4345
    /* This is a local symbol, hh defaults to NULL.  */
4346
0
    sym = local_syms + r_symndx;
4347
0
    sym_sec = local_sections[r_symndx];
4348
0
    relocation = _bfd_elf_rela_local_sym (info->output_bfd,
4349
0
            sym, &sym_sec, rel);
4350
0
  }
4351
0
      else
4352
0
  {
4353
    /* This is not a local symbol.  */
4354
0
    struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
4355
4356
    /* It seems this can happen with erroneous or unsupported
4357
       input (mixing a.out and elf in an archive, for example.)  */
4358
0
    if (sym_hashes == NULL)
4359
0
      return false;
4360
4361
0
    eh = sym_hashes[r_symndx - symtab_hdr->sh_info];
4362
4363
0
    if (info->wrap_hash != NULL
4364
0
        && (input_section->flags & SEC_DEBUGGING) != 0)
4365
0
      eh = ((struct elf_link_hash_entry *)
4366
0
      unwrap_hash_lookup (info, input_bfd, &eh->root));
4367
4368
0
    while (eh->root.type == bfd_link_hash_indirect
4369
0
     || eh->root.type == bfd_link_hash_warning)
4370
0
      eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
4371
4372
0
    relocation = 0;
4373
0
    if (eh->root.type == bfd_link_hash_defined
4374
0
        || eh->root.type == bfd_link_hash_defweak)
4375
0
      {
4376
0
        sym_sec = eh->root.u.def.section;
4377
0
        if (sym_sec != NULL
4378
0
      && sym_sec->output_section != NULL)
4379
0
    relocation = (eh->root.u.def.value
4380
0
            + sym_sec->output_section->vma
4381
0
            + sym_sec->output_offset);
4382
0
      }
4383
0
    else if (eh->root.type == bfd_link_hash_undefweak)
4384
0
      ;
4385
0
    else if (info->unresolved_syms_in_objects == RM_IGNORE
4386
0
       && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT)
4387
0
      ;
4388
0
    else if (!bfd_link_relocatable (info)
4389
0
       && elf_hppa_is_dynamic_loader_symbol (eh->root.root.string))
4390
0
      continue;
4391
0
    else if (!bfd_link_relocatable (info))
4392
0
      {
4393
0
        bool err;
4394
4395
0
        err = (info->unresolved_syms_in_objects == RM_DIAGNOSE
4396
0
         && !info->warn_unresolved_syms)
4397
0
    || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT;
4398
4399
0
        info->callbacks->undefined_symbol
4400
0
    (info, eh->root.root.string, input_bfd,
4401
0
     input_section, rel->r_offset, err);
4402
0
      }
4403
4404
0
    if (!bfd_link_relocatable (info)
4405
0
        && relocation == 0
4406
0
        && eh->root.type != bfd_link_hash_defined
4407
0
        && eh->root.type != bfd_link_hash_defweak
4408
0
        && eh->root.type != bfd_link_hash_undefweak)
4409
0
      {
4410
0
        if (info->unresolved_syms_in_objects == RM_IGNORE
4411
0
      && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT
4412
0
      && eh->type == STT_PARISC_MILLI)
4413
0
    info->callbacks->undefined_symbol
4414
0
      (info, eh_name (eh), input_bfd,
4415
0
       input_section, rel->r_offset, false);
4416
0
      }
4417
0
  }
4418
4419
0
      if (sym_sec != NULL && discarded_section (sym_sec))
4420
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
4421
0
           rel, 1, relend, R_PARISC_NONE,
4422
0
           howto, 0, contents);
4423
4424
0
      if (bfd_link_relocatable (info))
4425
0
  continue;
4426
4427
0
      r = elf_hppa_final_link_relocate (rel, input_bfd, info->output_bfd,
4428
0
          input_section, contents,
4429
0
          relocation, info, sym, sym_sec,
4430
0
          eh);
4431
4432
0
      if (r != bfd_reloc_ok)
4433
0
  {
4434
0
    switch (r)
4435
0
      {
4436
0
      default:
4437
0
        abort ();
4438
0
      case bfd_reloc_overflow:
4439
0
        {
4440
0
    const char *sym_name;
4441
4442
0
    if (eh != NULL)
4443
0
      sym_name = NULL;
4444
0
    else
4445
0
      {
4446
0
        sym_name = bfd_elf_string_from_elf_section (input_bfd,
4447
0
                symtab_hdr->sh_link,
4448
0
                sym->st_name);
4449
0
        if (sym_name == NULL)
4450
0
          return false;
4451
0
        if (*sym_name == '\0')
4452
0
          sym_name = bfd_section_name (sym_sec);
4453
0
      }
4454
4455
0
    (*info->callbacks->reloc_overflow)
4456
0
      (info, (eh ? &eh->root : NULL), sym_name, howto->name,
4457
0
       (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4458
0
        }
4459
0
        break;
4460
0
      }
4461
0
  }
4462
0
    }
4463
0
  return true;
4464
0
}
4465
4466
static const struct bfd_elf_special_section elf64_hppa_special_sections[] =
4467
{
4468
  { STRING_COMMA_LEN (".tbss"),  0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS },
4469
  { STRING_COMMA_LEN (".fini"),  0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4470
  { STRING_COMMA_LEN (".init"),  0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
4471
  { STRING_COMMA_LEN (".plt"),   0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4472
  { STRING_COMMA_LEN (".dlt"),   0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4473
  { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4474
  { STRING_COMMA_LEN (".sbss"),  0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT },
4475
  { NULL,        0,  0, 0,      0 }
4476
};
4477
4478
/* The hash bucket size is the standard one, namely 4.  */
4479
4480
static const struct elf_size_info hppa64_elf_size_info =
4481
{
4482
  sizeof (Elf64_External_Ehdr),
4483
  sizeof (Elf64_External_Phdr),
4484
  sizeof (Elf64_External_Shdr),
4485
  sizeof (Elf64_External_Rel),
4486
  sizeof (Elf64_External_Rela),
4487
  sizeof (Elf64_External_Sym),
4488
  sizeof (Elf64_External_Dyn),
4489
  sizeof (Elf_External_Note),
4490
  4,
4491
  1,
4492
  64, 3,
4493
  ELFCLASS64, EV_CURRENT,
4494
  bfd_elf64_write_out_phdrs,
4495
  bfd_elf64_write_shdrs_and_ehdr,
4496
  bfd_elf64_checksum_contents,
4497
  bfd_elf64_write_relocs,
4498
  bfd_elf64_swap_symbol_in,
4499
  bfd_elf64_swap_symbol_out,
4500
  bfd_elf64_slurp_reloc_table,
4501
  bfd_elf64_slurp_symbol_table,
4502
  bfd_elf64_swap_dyn_in,
4503
  bfd_elf64_swap_dyn_out,
4504
  bfd_elf64_swap_reloc_in,
4505
  bfd_elf64_swap_reloc_out,
4506
  bfd_elf64_swap_reloca_in,
4507
  bfd_elf64_swap_reloca_out
4508
};
4509
4510
#define TARGET_BIG_SYM      hppa_elf64_vec
4511
#define TARGET_BIG_NAME     "elf64-hppa"
4512
#define ELF_ARCH      bfd_arch_hppa
4513
#define ELF_TARGET_ID     HPPA64_ELF_DATA
4514
#define ELF_MACHINE_CODE    EM_PARISC
4515
/* This is not strictly correct.  The maximum page size for PA2.0 is
4516
   64M.  But everything still uses 4k.  However, the HP-UX linker
4517
   aligns the file offset for the data segment to 256k.  */
4518
#define ELF_MAXPAGESIZE     0x1000
4519
#define ELF_OSABI     ELFOSABI_HPUX
4520
#define ELF_OSABI_EXACT     1
4521
4522
#define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
4523
#define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
4524
#define bfd_elf64_bfd_is_local_label_name       elf_hppa_is_local_label_name
4525
#define elf_info_to_howto   elf_hppa_info_to_howto
4526
#define elf_info_to_howto_rel   elf_hppa_info_to_howto_rel
4527
4528
#define elf_backend_section_from_shdr elf64_hppa_section_from_shdr
4529
#define elf_backend_object_p    elf64_hppa_object_p
4530
#define elf_backend_final_write_processing \
4531
          elf_hppa_final_write_processing
4532
#define elf_backend_fake_sections elf_hppa_fake_sections
4533
#define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook
4534
4535
#define elf_backend_relocate_section  elf_hppa_relocate_section
4536
4537
#define bfd_elf64_bfd_final_link  elf_hppa_final_link
4538
4539
#define elf_backend_create_dynamic_sections \
4540
          elf64_hppa_create_dynamic_sections
4541
#define elf_backend_init_file_header  elf64_hppa_init_file_header
4542
4543
#define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
4544
4545
#define elf_backend_adjust_dynamic_symbol \
4546
          elf64_hppa_adjust_dynamic_symbol
4547
4548
#define elf_backend_late_size_sections  elf64_hppa_late_size_sections
4549
4550
#define elf_backend_finish_dynamic_symbol \
4551
          elf64_hppa_finish_dynamic_symbol
4552
#define elf_backend_finish_dynamic_sections \
4553
          elf64_hppa_finish_dynamic_sections
4554
#define elf_backend_grok_prstatus elf64_hppa_grok_prstatus
4555
#define elf_backend_grok_psinfo   elf64_hppa_grok_psinfo
4556
#define elf_backend_gc_mark_hook  elf64_hppa_gc_mark_hook
4557
4558
/* Stuff for the BFD linker: */
4559
#define bfd_elf64_bfd_link_hash_table_create \
4560
  elf64_hppa_hash_table_create
4561
4562
#define elf_backend_check_relocs \
4563
  elf64_hppa_check_relocs
4564
4565
#define elf_backend_size_info \
4566
  hppa64_elf_size_info
4567
4568
#define elf_backend_additional_program_headers \
4569
  elf64_hppa_additional_program_headers
4570
4571
#define elf_backend_modify_segment_map \
4572
  elf64_hppa_modify_segment_map
4573
4574
#define elf_backend_allow_non_load_phdr \
4575
  elf64_hppa_allow_non_load_phdr
4576
4577
#define elf_backend_link_output_symbol_hook \
4578
  elf64_hppa_link_output_symbol_hook
4579
4580
#define elf_backend_can_gc_sections 1
4581
#define elf_backend_want_got_plt  0
4582
#define elf_backend_plt_readonly  0
4583
#define elf_backend_want_plt_sym  0
4584
#define elf_backend_got_header_size     0
4585
#define elf_backend_type_change_ok  true
4586
#define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type
4587
#define elf_backend_reloc_type_class  elf64_hppa_reloc_type_class
4588
#define elf_backend_rela_normal   1
4589
#define elf_backend_special_sections  elf64_hppa_special_sections
4590
#define elf_backend_action_discarded  elf_hppa_action_discarded
4591
#define elf_backend_section_from_phdr   elf64_hppa_section_from_phdr
4592
#define elf_backend_want_p_paddr_set_to_zero 1
4593
4594
#define elf64_bed     elf64_hppa_hpux_bed
4595
4596
#include "elf64-target.h"
4597
4598
#undef TARGET_BIG_SYM
4599
#define TARGET_BIG_SYM      hppa_elf64_linux_vec
4600
#undef TARGET_BIG_NAME
4601
#define TARGET_BIG_NAME     "elf64-hppa-linux"
4602
#undef ELF_OSABI
4603
#define ELF_OSABI     ELFOSABI_GNU
4604
#undef elf64_bed
4605
#define elf64_bed     elf64_hppa_linux_bed
4606
#undef elf_backend_special_sections
4607
#define elf_backend_special_sections  (elf64_hppa_special_sections + 1)
4608
#undef elf_backend_modify_segment_map
4609
#undef elf_backend_want_p_paddr_set_to_zero
4610
#undef elf_backend_want_dynrelro
4611
#define elf_backend_want_dynrelro 1
4612
4613
#include "elf64-target.h"