Coverage Report

Created: 2026-07-25 10:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/elf32-vax.c
Line
Count
Source
1
/* VAX series support for 32-bit ELF
2
   Copyright (C) 1993-2026 Free Software Foundation, Inc.
3
   Contributed by Matt Thomas <matt@3am-software.com>.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "bfd.h"
24
#include "bfdlink.h"
25
#include "libbfd.h"
26
#include "elf-bfd.h"
27
#include "elf/vax.h"
28
29
static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
30
static bool rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
31
static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *,
32
               struct bfd_hash_table *,
33
               const char *);
34
static struct bfd_link_hash_table *elf_vax_link_hash_table_create (bfd *);
35
static bool elf_vax_check_relocs (bfd *, struct bfd_link_info *,
36
          asection *, const Elf_Internal_Rela *);
37
static bool elf_vax_adjust_dynamic_symbol (struct bfd_link_info *,
38
             struct elf_link_hash_entry *);
39
static bfd_vma elf_vax_plt_sym_val (bfd_vma, const asection *,
40
            const arelent *);
41
42
static bool elf32_vax_set_private_flags (bfd *, flagword);
43
static bool elf32_vax_print_private_bfd_data (bfd *, void *);
44
45
static reloc_howto_type howto_table[] = {
46
  HOWTO (R_VAX_NONE,    /* type */
47
   0,     /* rightshift */
48
   0,     /* size */
49
   0,     /* bitsize */
50
   false,     /* pc_relative */
51
   0,     /* bitpos */
52
   complain_overflow_dont, /* complain_on_overflow */
53
   bfd_elf_generic_reloc, /* special_function */
54
   "R_VAX_NONE",    /* name */
55
   false,     /* partial_inplace */
56
   0,     /* src_mask */
57
   0x00000000,    /* dst_mask */
58
   false),    /* pcrel_offset */
59
60
  HOWTO (R_VAX_32,    /* type */
61
   0,     /* rightshift */
62
   4,     /* size */
63
   32,      /* bitsize */
64
   false,     /* pc_relative */
65
   0,     /* bitpos */
66
   complain_overflow_bitfield, /* complain_on_overflow */
67
   bfd_elf_generic_reloc, /* special_function */
68
   "R_VAX_32",    /* name */
69
   false,     /* partial_inplace */
70
   0,     /* src_mask */
71
   0xffffffff,    /* dst_mask */
72
   false),    /* pcrel_offset */
73
74
  HOWTO (R_VAX_16,    /* type */
75
   0,     /* rightshift */
76
   2,     /* size */
77
   16,      /* bitsize */
78
   false,     /* pc_relative */
79
   0,     /* bitpos */
80
   complain_overflow_bitfield, /* complain_on_overflow */
81
   bfd_elf_generic_reloc, /* special_function */
82
   "R_VAX_16",    /* name */
83
   false,     /* partial_inplace */
84
   0,     /* src_mask */
85
   0x0000ffff,    /* dst_mask */
86
   false),    /* pcrel_offset */
87
88
  HOWTO (R_VAX_8,   /* type */
89
   0,     /* rightshift */
90
   1,     /* size */
91
   8,     /* bitsize */
92
   false,     /* pc_relative */
93
   0,     /* bitpos */
94
   complain_overflow_bitfield, /* complain_on_overflow */
95
   bfd_elf_generic_reloc, /* special_function */
96
   "R_VAX_8",   /* name */
97
   false,     /* partial_inplace */
98
   0,     /* src_mask */
99
   0x000000ff,    /* dst_mask */
100
   false),    /* pcrel_offset */
101
102
  HOWTO (R_VAX_PC32,    /* type */
103
   0,     /* rightshift */
104
   4,     /* size */
105
   32,      /* bitsize */
106
   true,      /* pc_relative */
107
   0,     /* bitpos */
108
   complain_overflow_bitfield, /* complain_on_overflow */
109
   bfd_elf_generic_reloc, /* special_function */
110
   "R_VAX_PC32",    /* name */
111
   false,     /* partial_inplace */
112
   0,     /* src_mask */
113
   0xffffffff,    /* dst_mask */
114
   true),     /* pcrel_offset */
115
116
  HOWTO (R_VAX_PC16,    /* type */
117
   0,     /* rightshift */
118
   2,     /* size */
119
   16,      /* bitsize */
120
   true,      /* pc_relative */
121
   0,     /* bitpos */
122
   complain_overflow_signed, /* complain_on_overflow */
123
   bfd_elf_generic_reloc, /* special_function */
124
   "R_VAX_PC16",    /* name */
125
   false,     /* partial_inplace */
126
   0,     /* src_mask */
127
   0x0000ffff,    /* dst_mask */
128
   true),     /* pcrel_offset */
129
130
  HOWTO (R_VAX_PC8,   /* type */
131
   0,     /* rightshift */
132
   1,     /* size */
133
   8,     /* bitsize */
134
   true,      /* pc_relative */
135
   0,     /* bitpos */
136
   complain_overflow_signed, /* complain_on_overflow */
137
   bfd_elf_generic_reloc, /* special_function */
138
   "R_VAX_PC8",   /* name */
139
   false,     /* partial_inplace */
140
   0,     /* src_mask */
141
   0x000000ff,    /* dst_mask */
142
   true),     /* pcrel_offset */
143
144
  HOWTO (R_VAX_GOT32,   /* type */
145
   0,     /* rightshift */
146
   4,     /* size */
147
   32,      /* bitsize */
148
   true,      /* pc_relative */
149
   0,     /* bitpos */
150
   complain_overflow_bitfield, /* complain_on_overflow */
151
   bfd_elf_generic_reloc, /* special_function */
152
   "R_VAX_GOT32",   /* name */
153
   false,     /* partial_inplace */
154
   0,     /* src_mask */
155
   0xffffffff,    /* dst_mask */
156
   true),     /* pcrel_offset */
157
158
  EMPTY_HOWTO (-1),
159
  EMPTY_HOWTO (-1),
160
  EMPTY_HOWTO (-1),
161
  EMPTY_HOWTO (-1),
162
  EMPTY_HOWTO (-1),
163
164
  HOWTO (R_VAX_PLT32,   /* type */
165
   0,     /* rightshift */
166
   4,     /* size */
167
   32,      /* bitsize */
168
   true,      /* pc_relative */
169
   0,     /* bitpos */
170
   complain_overflow_bitfield, /* complain_on_overflow */
171
   bfd_elf_generic_reloc, /* special_function */
172
   "R_VAX_PLT32",   /* name */
173
   false,     /* partial_inplace */
174
   0,     /* src_mask */
175
   0xffffffff,    /* dst_mask */
176
   true),     /* pcrel_offset */
177
178
  EMPTY_HOWTO (-1),
179
  EMPTY_HOWTO (-1),
180
  EMPTY_HOWTO (-1),
181
  EMPTY_HOWTO (-1),
182
  EMPTY_HOWTO (-1),
183
184
  HOWTO (R_VAX_COPY,    /* type */
185
   0,     /* rightshift */
186
   0,     /* size */
187
   0,     /* bitsize */
188
   false,     /* pc_relative */
189
   0,     /* bitpos */
190
   complain_overflow_dont, /* complain_on_overflow */
191
   bfd_elf_generic_reloc, /* special_function */
192
   "R_VAX_COPY",    /* name */
193
   false,     /* partial_inplace */
194
   0,     /* src_mask */
195
   0xffffffff,    /* dst_mask */
196
   false),    /* pcrel_offset */
197
198
  HOWTO (R_VAX_GLOB_DAT,  /* type */
199
   0,     /* rightshift */
200
   4,     /* size */
201
   32,      /* bitsize */
202
   false,     /* pc_relative */
203
   0,     /* bitpos */
204
   complain_overflow_dont, /* complain_on_overflow */
205
   bfd_elf_generic_reloc, /* special_function */
206
   "R_VAX_GLOB_DAT",  /* name */
207
   false,     /* partial_inplace */
208
   0,     /* src_mask */
209
   0xffffffff,    /* dst_mask */
210
   false),    /* pcrel_offset */
211
212
  HOWTO (R_VAX_JMP_SLOT,  /* type */
213
   0,     /* rightshift */
214
   4,     /* size */
215
   32,      /* bitsize */
216
   false,     /* pc_relative */
217
   0,     /* bitpos */
218
   complain_overflow_dont, /* complain_on_overflow */
219
   bfd_elf_generic_reloc, /* special_function */
220
   "R_VAX_JMP_SLOT",  /* name */
221
   false,     /* partial_inplace */
222
   0,     /* src_mask */
223
   0xffffffff,    /* dst_mask */
224
   false),    /* pcrel_offset */
225
226
  HOWTO (R_VAX_RELATIVE,  /* type */
227
   0,     /* rightshift */
228
   4,     /* size */
229
   32,      /* bitsize */
230
   false,     /* pc_relative */
231
   0,     /* bitpos */
232
   complain_overflow_dont, /* complain_on_overflow */
233
   bfd_elf_generic_reloc, /* special_function */
234
   "R_VAX_RELATIVE",  /* name */
235
   false,     /* partial_inplace */
236
   0,     /* src_mask */
237
   0xffffffff,    /* dst_mask */
238
   false),    /* pcrel_offset */
239
240
  /* GNU extension to record C++ vtable hierarchy */
241
  HOWTO (R_VAX_GNU_VTINHERIT, /* type */
242
   0,     /* rightshift */
243
   4,     /* size */
244
   0,     /* bitsize */
245
   false,     /* pc_relative */
246
   0,     /* bitpos */
247
   complain_overflow_dont, /* complain_on_overflow */
248
   NULL,      /* special_function */
249
   "R_VAX_GNU_VTINHERIT", /* name */
250
   false,     /* partial_inplace */
251
   0,     /* src_mask */
252
   0,     /* dst_mask */
253
   false),    /* pcrel_offset */
254
255
  /* GNU extension to record C++ vtable member usage */
256
  HOWTO (R_VAX_GNU_VTENTRY, /* type */
257
   0,     /* rightshift */
258
   4,     /* size */
259
   0,     /* bitsize */
260
   false,     /* pc_relative */
261
   0,     /* bitpos */
262
   complain_overflow_dont, /* complain_on_overflow */
263
   _bfd_elf_rel_vtable_reloc_fn, /* special_function */
264
   "R_VAX_GNU_VTENTRY", /* name */
265
   false,     /* partial_inplace */
266
   0,     /* src_mask */
267
   0,     /* dst_mask */
268
   false),    /* pcrel_offset */
269
};
270
271
static bool
272
rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
273
58
{
274
58
  unsigned int r_type;
275
276
58
  r_type = ELF32_R_TYPE (dst->r_info);
277
58
  if (r_type >= R_VAX_max)
278
9
    {
279
      /* xgettext:c-format */
280
9
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
281
9
        abfd, r_type);
282
9
      bfd_set_error (bfd_error_bad_value);
283
9
      return false;
284
9
    }
285
49
  cache_ptr->howto = &howto_table[r_type];
286
49
  return true;
287
58
}
288
289
#define elf_info_to_howto rtype_to_howto
290
291
static const struct
292
{
293
  bfd_reloc_code_real_type bfd_val;
294
  int elf_val;
295
} reloc_map[] = {
296
  { BFD_RELOC_NONE, R_VAX_NONE },
297
  { BFD_RELOC_32, R_VAX_32 },
298
  { BFD_RELOC_16, R_VAX_16 },
299
  { BFD_RELOC_8, R_VAX_8 },
300
  { BFD_RELOC_32_PCREL, R_VAX_PC32 },
301
  { BFD_RELOC_16_PCREL, R_VAX_PC16 },
302
  { BFD_RELOC_8_PCREL, R_VAX_PC8 },
303
  { BFD_RELOC_32_GOT_PCREL, R_VAX_GOT32 },
304
  { BFD_RELOC_32_PLT_PCREL, R_VAX_PLT32 },
305
  { BFD_RELOC_NONE, R_VAX_COPY },
306
  { BFD_RELOC_GLOB_DAT, R_VAX_GLOB_DAT },
307
  { BFD_RELOC_JMP_SLOT, R_VAX_JMP_SLOT },
308
  { BFD_RELOC_RELATIVE, R_VAX_RELATIVE },
309
  { BFD_RELOC_CTOR, R_VAX_32 },
310
  { BFD_RELOC_VTABLE_INHERIT, R_VAX_GNU_VTINHERIT },
311
  { BFD_RELOC_VTABLE_ENTRY, R_VAX_GNU_VTENTRY },
312
};
313
314
static reloc_howto_type *
315
reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
316
0
{
317
0
  unsigned int i;
318
0
  for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
319
0
    {
320
0
      if (reloc_map[i].bfd_val == code)
321
0
  return &howto_table[reloc_map[i].elf_val];
322
0
    }
323
0
  return 0;
324
0
}
325
326
static reloc_howto_type *
327
reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
328
       const char *r_name)
329
0
{
330
0
  unsigned int i;
331
332
0
  for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
333
0
    if (howto_table[i].name != NULL
334
0
  && strcasecmp (howto_table[i].name, r_name) == 0)
335
0
      return &howto_table[i];
336
337
0
  return NULL;
338
0
}
339
340
#define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
341
#define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
342
#define ELF_ARCH bfd_arch_vax
343
/* end code generated by elf.el */
344

345
/* Functions for the VAX ELF linker.  */
346
347
/* The name of the dynamic interpreter.  This is put in the .interp
348
   section.  */
349
350
0
#define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
351
352
/* The size in bytes of an entry in the procedure linkage table.  */
353
354
0
#define PLT_ENTRY_SIZE 12
355
356
/* The first entry in a procedure linkage table looks like this.  See
357
   the SVR4 ABI VAX supplement to see how this works.  */
358
359
static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
360
{
361
  0xdd, 0xef,   /* pushl l^ */
362
  0, 0, 0, 0,   /* offset to .plt.got + 4 */
363
  0x17, 0xff,   /* jmp @L^(pc) */
364
  0, 0, 0, 0,   /* offset to .plt.got + 8 */
365
};
366
367
/* Subsequent entries in a procedure linkage table look like this.  */
368
369
static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
370
{
371
  0xfc, 0x0f,   /* .word ^M<r11:r2> */
372
  0x16, 0xef,   /* jsb L^(pc) */
373
  0, 0, 0, 0,   /* replaced with offset to start of .plt  */
374
  0, 0, 0, 0,   /* index into .rela.plt */
375
};
376
377
/* The VAX linker needs to keep track of the number of relocs that it
378
   decides to copy in check_relocs for each symbol.  This is so that it
379
   can discard PC relative relocs if it doesn't need them when linking
380
   with -Bsymbolic.  We store the information in a field extending the
381
   regular ELF linker hash table.  */
382
383
/* This structure keeps track of the number of PC relative relocs we have
384
   copied for a given symbol.  */
385
386
struct elf_vax_pcrel_relocs_copied
387
{
388
  /* Next section.  */
389
  struct elf_vax_pcrel_relocs_copied *next;
390
  /* A section in dynobj.  */
391
  asection *section;
392
  /* Number of relocs copied in this section.  */
393
  bfd_size_type count;
394
};
395
396
/* VAX ELF linker hash entry.  */
397
398
struct elf_vax_link_hash_entry
399
{
400
  struct elf_link_hash_entry root;
401
402
  /* Number of PC relative relocs copied for this symbol.  */
403
  struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
404
405
  bfd_vma got_addend;
406
};
407
408
/* Declare this now that the above structures are defined.  */
409
410
static bool elf_vax_discard_copies (struct elf_vax_link_hash_entry *,
411
            void *);
412
413
/* Declare this now that the above structures are defined.  */
414
415
static bool elf_vax_instantiate_got_entries (struct elf_link_hash_entry *,
416
               void *);
417
418
/* Traverse an VAX ELF linker hash table.  */
419
420
#define elf_vax_link_hash_traverse(table, func, info)     \
421
0
  (elf_link_hash_traverse           \
422
0
   ((table),                \
423
0
    (bool (*) (struct elf_link_hash_entry *, void *)) (func),   \
424
0
    (info)))
425
426
/* Create an entry in an VAX ELF linker hash table.  */
427
428
static struct bfd_hash_entry *
429
elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry,
430
         struct bfd_hash_table *table,
431
         const char *string)
432
0
{
433
0
  struct elf_vax_link_hash_entry *ret =
434
0
    (struct elf_vax_link_hash_entry *) entry;
435
436
  /* Allocate the structure if it has not already been allocated by a
437
     subclass.  */
438
0
  if (ret == NULL)
439
0
    ret = ((struct elf_vax_link_hash_entry *)
440
0
     bfd_hash_allocate (table,
441
0
            sizeof (struct elf_vax_link_hash_entry)));
442
0
  if (ret == NULL)
443
0
    return (struct bfd_hash_entry *) ret;
444
445
  /* Call the allocation method of the superclass.  */
446
0
  ret = ((struct elf_vax_link_hash_entry *)
447
0
   _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
448
0
             table, string));
449
0
  if (ret != NULL)
450
0
    {
451
0
      ret->pcrel_relocs_copied = NULL;
452
0
    }
453
454
0
  return (struct bfd_hash_entry *) ret;
455
0
}
456
457
/* Create an VAX ELF linker hash table.  */
458
459
static struct bfd_link_hash_table *
460
elf_vax_link_hash_table_create (bfd *abfd)
461
0
{
462
0
  struct elf_link_hash_table *ret;
463
0
  size_t amt = sizeof (struct elf_link_hash_table);
464
465
0
  ret = bfd_zmalloc (amt);
466
0
  if (ret == NULL)
467
0
    return NULL;
468
469
0
  if (!_bfd_elf_link_hash_table_init (ret, abfd,
470
0
              elf_vax_link_hash_newfunc,
471
0
              sizeof (struct elf_vax_link_hash_entry)))
472
0
    {
473
0
      free (ret);
474
0
      return NULL;
475
0
    }
476
477
0
  return &ret->root;
478
0
}
479
480
/* Keep vax-specific flags in the ELF header */
481
static bool
482
elf32_vax_set_private_flags (bfd *abfd, flagword flags)
483
0
{
484
0
  elf_elfheader (abfd)->e_flags = flags;
485
0
  elf_flags_init (abfd) = true;
486
0
  return true;
487
0
}
488
489
/* Merge backend specific data from an object file to the output
490
   object file when linking.  */
491
static bool
492
elf32_vax_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
493
0
{
494
0
  bfd *obfd = info->output_bfd;
495
0
  flagword in_flags;
496
497
0
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
498
0
    return true;
499
500
0
  in_flags  = elf_elfheader (ibfd)->e_flags;
501
502
0
  if (!elf_flags_init (obfd))
503
0
    {
504
0
      elf_flags_init (obfd) = true;
505
0
      elf_elfheader (obfd)->e_flags = in_flags;
506
0
    }
507
508
0
  return true;
509
0
}
510
511
/* Display the flags field */
512
static bool
513
elf32_vax_print_private_bfd_data (bfd *abfd, void * ptr)
514
10
{
515
10
  FILE *file = (FILE *) ptr;
516
517
10
  BFD_ASSERT (abfd != NULL && ptr != NULL);
518
519
  /* Print normal ELF private data.  */
520
10
  _bfd_elf_print_private_bfd_data (abfd, ptr);
521
522
  /* Ignore init flag - it may not be set, despite the flags field containing valid data.  */
523
524
  /* xgettext:c-format */
525
10
  fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
526
527
10
  if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
528
0
    fprintf (file, _(" [nonpic]"));
529
530
10
  if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
531
2
    fprintf (file, _(" [d-float]"));
532
533
10
  if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
534
0
    fprintf (file, _(" [g-float]"));
535
536
10
  fputc ('\n', file);
537
538
10
  return true;
539
10
}
540
/* Look through the relocs for a section during the first phase, and
541
   allocate space in the global offset table or procedure linkage
542
   table.  */
543
544
static bool
545
elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
546
          const Elf_Internal_Rela *relocs)
547
0
{
548
0
  bfd *dynobj;
549
0
  Elf_Internal_Shdr *symtab_hdr;
550
0
  struct elf_link_hash_entry **sym_hashes;
551
0
  const Elf_Internal_Rela *rel;
552
0
  const Elf_Internal_Rela *rel_end;
553
0
  asection *sreloc;
554
555
0
  if (bfd_link_relocatable (info))
556
0
    return true;
557
558
0
  dynobj = elf_hash_table (info)->dynobj;
559
0
  symtab_hdr = &elf_symtab_hdr (abfd);
560
0
  sym_hashes = elf_sym_hashes (abfd);
561
562
0
  sreloc = NULL;
563
564
0
  rel_end = relocs + sec->reloc_count;
565
0
  for (rel = relocs; rel < rel_end; rel++)
566
0
    {
567
0
      unsigned long r_symndx;
568
0
      struct elf_link_hash_entry *h;
569
570
0
      r_symndx = ELF32_R_SYM (rel->r_info);
571
572
0
      if (r_symndx < symtab_hdr->sh_info)
573
0
  h = NULL;
574
0
      else
575
0
  {
576
0
    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
577
0
    while (h->root.type == bfd_link_hash_indirect
578
0
     || h->root.type == bfd_link_hash_warning)
579
0
      h = (struct elf_link_hash_entry *) h->root.u.i.link;
580
0
  }
581
582
0
      switch (ELF32_R_TYPE (rel->r_info))
583
0
  {
584
0
  case R_VAX_GOT32:
585
0
    BFD_ASSERT (h != NULL);
586
587
    /* If this is a local symbol, we resolve it directly without
588
       creating a global offset table entry.  */
589
0
    if (SYMBOL_REFERENCES_LOCAL (info, h)
590
0
        || h == elf_hash_table (info)->hgot
591
0
        || h == elf_hash_table (info)->hplt)
592
0
      break;
593
594
    /* This symbol requires a global offset table entry.  */
595
596
0
    if (dynobj == NULL)
597
0
      {
598
        /* Create the .got section.  */
599
0
        elf_hash_table (info)->dynobj = dynobj = abfd;
600
0
        if (!_bfd_elf_create_got_section (dynobj, info))
601
0
    return false;
602
0
      }
603
604
0
    if (h != NULL)
605
0
      {
606
0
        struct elf_vax_link_hash_entry *eh;
607
608
0
        eh = (struct elf_vax_link_hash_entry *) h;
609
0
        if (h->got.refcount == -1)
610
0
    {
611
0
      h->got.refcount = 1;
612
0
      eh->got_addend = rel->r_addend;
613
0
    }
614
0
        else
615
0
    {
616
0
      h->got.refcount++;
617
0
      if (eh->got_addend != (bfd_vma) rel->r_addend)
618
0
        _bfd_error_handler
619
          /* xgettext:c-format */
620
0
          (_("%pB: warning: GOT addend of %" PRId64 " to `%s' does"
621
0
       " not match previous GOT addend of %" PRId64),
622
0
       abfd, (int64_t) rel->r_addend, h->root.root.string,
623
0
       (int64_t) eh->got_addend);
624
625
0
    }
626
0
      }
627
0
    break;
628
629
0
  case R_VAX_PLT32:
630
    /* This symbol requires a procedure linkage table entry.  We
631
       actually build the entry in adjust_dynamic_symbol,
632
       because this might be a case of linking PIC code which is
633
       never referenced by a dynamic object, in which case we
634
       don't need to generate a procedure linkage table entry
635
       after all.  */
636
0
    BFD_ASSERT (h != NULL);
637
638
    /* If this is a local symbol, we resolve it directly without
639
       creating a procedure linkage table entry.  */
640
0
    if (h->forced_local)
641
0
      break;
642
643
0
    h->needs_plt = 1;
644
0
    if (h->plt.refcount == -1)
645
0
      h->plt.refcount = 1;
646
0
    else
647
0
      h->plt.refcount++;
648
0
    break;
649
650
0
  case R_VAX_PC8:
651
0
  case R_VAX_PC16:
652
0
  case R_VAX_PC32:
653
    /* If we are creating a shared library and this is not a local
654
       symbol, we need to copy the reloc into the shared library.
655
       However when linking with -Bsymbolic and this is a global
656
       symbol which is defined in an object we are including in the
657
       link (i.e., DEF_REGULAR is set), then we can resolve the
658
       reloc directly.  At this point we have not seen all the input
659
       files, so it is possible that DEF_REGULAR is not set now but
660
       will be set later (it is never cleared).  We account for that
661
       possibility below by storing information in the
662
       pcrel_relocs_copied field of the hash table entry.  */
663
0
    if (!(bfd_link_pic (info)
664
0
    && (sec->flags & SEC_ALLOC) != 0
665
0
    && h != NULL
666
0
    && (!info->symbolic
667
0
        || !h->def_regular)))
668
0
      {
669
0
        if (h != NULL
670
0
      && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
671
0
      && !h->forced_local)
672
0
    {
673
      /* Make sure a plt entry is created for this symbol if
674
         it turns out to be a function defined by a dynamic
675
         object.  */
676
0
      if (h->plt.refcount == -1)
677
0
        h->plt.refcount = 1;
678
0
      else
679
0
        h->plt.refcount++;
680
0
    }
681
0
        break;
682
0
      }
683
    /* If this is a local symbol, we can resolve it directly.  */
684
0
    if (h != NULL
685
0
        && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
686
0
      || h->forced_local))
687
0
      break;
688
689
    /* Fall through.  */
690
0
  case R_VAX_8:
691
0
  case R_VAX_16:
692
0
  case R_VAX_32:
693
0
    if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
694
0
      {
695
        /* Make sure a plt entry is created for this symbol if it
696
     turns out to be a function defined by a dynamic object.  */
697
0
        if (h->plt.refcount == -1)
698
0
    h->plt.refcount = 1;
699
0
        else
700
0
    h->plt.refcount++;
701
0
      }
702
703
    /* Non-GOT reference may need a copy reloc in executable or
704
       a dynamic reloc in shared library.  */
705
0
    if (h != NULL)
706
0
      h->non_got_ref = 1;
707
708
    /* If we are creating a shared library, we need to copy the
709
       reloc into the shared library.  */
710
0
    if (bfd_link_pic (info)
711
0
        && (sec->flags & SEC_ALLOC) != 0)
712
0
      {
713
        /* When creating a shared object, we must copy these
714
     reloc types into the output file.  We create a reloc
715
     section in dynobj and make room for this reloc.  */
716
0
        if (sreloc == NULL)
717
0
    {
718
0
      sreloc = _bfd_elf_make_dynamic_reloc_section
719
0
        (sec, dynobj, 2, abfd, /*rela?*/ true);
720
721
0
      if (sreloc == NULL)
722
0
        return false;
723
724
0
      if (sec->flags & SEC_READONLY)
725
0
        info->flags |= DF_TEXTREL;
726
0
    }
727
728
0
        sreloc->size += sizeof (Elf32_External_Rela);
729
730
        /* If we are linking with -Bsymbolic, we count the number of
731
     PC relative relocations we have entered for this symbol,
732
     so that we can discard them again if the symbol is later
733
     defined by a regular object.  Note that this function is
734
     only called if we are using a vaxelf linker hash table,
735
     which means that h is really a pointer to an
736
     elf_vax_link_hash_entry.  */
737
0
        if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
738
0
       || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
739
0
       || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
740
0
      && info->symbolic)
741
0
    {
742
0
      struct elf_vax_link_hash_entry *eh;
743
0
      struct elf_vax_pcrel_relocs_copied *p;
744
745
0
      eh = (struct elf_vax_link_hash_entry *) h;
746
747
0
      for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
748
0
        if (p->section == sreloc)
749
0
          break;
750
751
0
      if (p == NULL)
752
0
        {
753
0
          p = ((struct elf_vax_pcrel_relocs_copied *)
754
0
         bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
755
0
          if (p == NULL)
756
0
      return false;
757
0
          p->next = eh->pcrel_relocs_copied;
758
0
          eh->pcrel_relocs_copied = p;
759
0
          p->section = sreloc;
760
0
          p->count = 0;
761
0
        }
762
763
0
      ++p->count;
764
0
    }
765
0
      }
766
767
0
    break;
768
769
    /* This relocation describes the C++ object vtable hierarchy.
770
       Reconstruct it for later use during GC.  */
771
0
  case R_VAX_GNU_VTINHERIT:
772
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
773
0
      return false;
774
0
    break;
775
776
    /* This relocation describes which C++ vtable entries are actually
777
       used.  Record for later use during GC.  */
778
0
  case R_VAX_GNU_VTENTRY:
779
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
780
0
      return false;
781
0
    break;
782
783
0
  default:
784
0
    break;
785
0
  }
786
0
    }
787
788
0
  return true;
789
0
}
790
791
/* Return the section that should be marked against GC for a given
792
   relocation.  */
793
794
static asection *
795
elf_vax_gc_mark_hook (asection *sec,
796
          struct bfd_link_info *info,
797
          struct elf_reloc_cookie *cookie,
798
          struct elf_link_hash_entry *h,
799
          unsigned int symndx)
800
0
{
801
0
  if (h != NULL)
802
0
    switch (ELF32_R_TYPE (cookie->rel->r_info))
803
0
      {
804
0
      case R_VAX_GNU_VTINHERIT:
805
0
      case R_VAX_GNU_VTENTRY:
806
0
  return NULL;
807
0
      }
808
809
0
  return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx);
810
0
}
811
812
/* Adjust a symbol defined by a dynamic object and referenced by a
813
   regular object.  The current definition is in some section of the
814
   dynamic object, but we're not including those sections.  We have to
815
   change the definition to something the rest of the link can
816
   understand.  */
817
818
static bool
819
elf_vax_adjust_dynamic_symbol (struct bfd_link_info *info,
820
             struct elf_link_hash_entry *h)
821
0
{
822
0
  bfd *dynobj;
823
0
  asection *s;
824
825
0
  dynobj = elf_hash_table (info)->dynobj;
826
827
  /* Make sure we know what is going on here.  */
828
0
  BFD_ASSERT (dynobj != NULL
829
0
        && (h->needs_plt
830
0
      || h->is_weakalias
831
0
      || (h->def_dynamic
832
0
          && h->ref_regular
833
0
          && !h->def_regular)));
834
835
  /* If this is a function, put it in the procedure linkage table.  We
836
     will fill in the contents of the procedure linkage table later,
837
     when we know the address of the .got section.  */
838
0
  if (h->type == STT_FUNC
839
0
      || h->needs_plt)
840
0
    {
841
0
      if (h->plt.refcount <= 0
842
0
    || SYMBOL_CALLS_LOCAL (info, h)
843
0
    || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
844
0
        && h->root.type == bfd_link_hash_undefweak))
845
0
  {
846
    /* This case can occur if we saw a PLTxx reloc in an input
847
       file, but the symbol was never referred to by a dynamic
848
       object, or if all references were garbage collected.  In
849
       such a case, we don't actually need to build a procedure
850
       linkage table, and we can just do a PCxx reloc instead.  */
851
0
    h->plt.offset = (bfd_vma) -1;
852
0
    h->needs_plt = 0;
853
0
    return true;
854
0
  }
855
856
0
      s = elf_hash_table (info)->splt;
857
0
      BFD_ASSERT (s != NULL);
858
859
      /* If this is the first .plt entry, make room for the special
860
   first entry.  */
861
0
      if (s->size == 0)
862
0
  {
863
0
    s->size += PLT_ENTRY_SIZE;
864
0
  }
865
866
      /* If this symbol is not defined in a regular file, and we are
867
   not generating a shared library, then set the symbol to this
868
   location in the .plt.  This is required to make function
869
   pointers compare as equal between the normal executable and
870
   the shared library.  */
871
0
      if (!bfd_link_pic (info)
872
0
    && !h->def_regular)
873
0
  {
874
0
    h->root.u.def.section = s;
875
0
    h->root.u.def.value = s->size;
876
0
  }
877
878
0
      h->plt.offset = s->size;
879
880
      /* Make room for this entry.  */
881
0
      s->size += PLT_ENTRY_SIZE;
882
883
      /* We also need to make an entry in the .got.plt section, which
884
   will be placed in the .got section by the linker script.  */
885
886
0
      s = elf_hash_table (info)->sgotplt;
887
0
      BFD_ASSERT (s != NULL);
888
0
      s->size += 4;
889
890
      /* We also need to make an entry in the .rela.plt section.  */
891
892
0
      s = elf_hash_table (info)->srelplt;
893
0
      BFD_ASSERT (s != NULL);
894
0
      s->size += sizeof (Elf32_External_Rela);
895
896
0
      return true;
897
0
    }
898
899
  /* Reinitialize the plt offset now that it is not used as a reference
900
     count any more.  */
901
0
  h->plt.offset = (bfd_vma) -1;
902
903
  /* If this is a weak symbol, and there is a real definition, the
904
     processor independent code will have arranged for us to see the
905
     real definition first, and we can just use the same value.  */
906
0
  if (h->is_weakalias)
907
0
    {
908
0
      struct elf_link_hash_entry *def = weakdef (h);
909
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
910
0
      h->root.u.def.section = def->root.u.def.section;
911
0
      h->root.u.def.value = def->root.u.def.value;
912
0
      return true;
913
0
    }
914
915
  /* This is a reference to a symbol defined by a dynamic object which
916
     is not a function.  */
917
918
  /* If we are creating a shared library, we must presume that the
919
     only references to the symbol are via the global offset table.
920
     For such cases we need not do anything here; the relocations will
921
     be handled correctly by relocate_section.  */
922
0
  if (bfd_link_pic (info))
923
0
    return true;
924
925
  /* If there are no references to this symbol that do not use the
926
     GOT relocation, we don't need to generate a copy reloc.  */
927
0
  if (!h->non_got_ref)
928
0
    return true;
929
930
  /* We must allocate the symbol in our .dynbss section, which will
931
     become part of the .bss section of the executable.  There will be
932
     an entry for this symbol in the .dynsym section.  The dynamic
933
     object will contain position independent code, so all references
934
     from the dynamic object to this symbol will go through the global
935
     offset table.  The dynamic linker will use the .dynsym entry to
936
     determine the address it must put in the global offset table, so
937
     both the dynamic object and the regular object will refer to the
938
     same memory location for the variable.  */
939
940
0
  s = bfd_get_linker_section (dynobj, ".dynbss");
941
0
  BFD_ASSERT (s != NULL);
942
943
  /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
944
     copy the initial value out of the dynamic object and into the
945
     runtime process image.  We need to remember the offset into the
946
     .rela.bss section we are going to use.  */
947
0
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
948
0
    {
949
0
      asection *srel;
950
951
0
      srel = bfd_get_linker_section (dynobj, ".rela.bss");
952
0
      BFD_ASSERT (srel != NULL);
953
0
      srel->size += sizeof (Elf32_External_Rela);
954
0
      h->needs_copy = 1;
955
0
    }
956
957
0
  return _bfd_elf_adjust_dynamic_copy (info, h, s);
958
0
}
959
960
/* This function is called via elf_link_hash_traverse.  It resets GOT
961
   and PLT (.GOT) reference counts back to -1 so normal PC32 relocation
962
   will be done.  */
963
964
static bool
965
elf_vax_discard_got_entries (struct elf_link_hash_entry *h,
966
           void *infoptr ATTRIBUTE_UNUSED)
967
0
{
968
0
  h->got.refcount = -1;
969
0
  h->plt.refcount = -1;
970
971
0
  return true;
972
0
}
973
974
/* Discard unused dynamic data if this is a static link.  */
975
976
static bool
977
elf_vax_early_size_sections (struct bfd_link_info *info)
978
0
{
979
0
  bfd *dynobj;
980
0
  asection *s;
981
982
0
  dynobj = elf_hash_table (info)->dynobj;
983
984
0
  if (dynobj && !elf_hash_table (info)->dynamic_sections_created)
985
0
    {
986
      /* We may have created entries in the .rela.got and .got sections.
987
   However, if we are not creating the dynamic sections, we will
988
   not actually use these entries.  Reset the size of .rela.got
989
   and .got, which will cause them to get stripped from the output
990
   file below.  */
991
0
      s = elf_hash_table (info)->srelgot;
992
0
      if (s != NULL)
993
0
  s->size = 0;
994
0
      s = elf_hash_table (info)->sgotplt;
995
0
      if (s != NULL)
996
0
  s->size = 0;
997
0
      s = elf_hash_table (info)->sgot;
998
0
      if (s != NULL)
999
0
  s->size = 0;
1000
0
    }
1001
1002
  /* If this is a static link, we need to discard all the got entries we've
1003
     recorded.  */
1004
0
  if (!dynobj || !elf_hash_table (info)->dynamic_sections_created)
1005
0
    elf_link_hash_traverse (elf_hash_table (info),
1006
0
          elf_vax_discard_got_entries,
1007
0
          info);
1008
1009
0
  return true;
1010
0
}
1011
1012
/* Set the sizes of the dynamic sections.  */
1013
1014
static bool
1015
elf_vax_late_size_sections (struct bfd_link_info *info)
1016
0
{
1017
0
  bfd *dynobj;
1018
0
  asection *s;
1019
0
  bool relocs;
1020
1021
0
  dynobj = elf_hash_table (info)->dynobj;
1022
0
  if (dynobj == NULL)
1023
0
    return true;
1024
1025
0
  if (elf_hash_table (info)->dynamic_sections_created)
1026
0
    {
1027
      /* Set the contents of the .interp section to the interpreter.  */
1028
0
      if (bfd_link_executable (info) && !info->nointerp)
1029
0
  {
1030
0
    s = elf_hash_table (info)->interp;
1031
0
    BFD_ASSERT (s != NULL);
1032
0
    s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1033
0
    s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1034
0
    s->alloced = 1;
1035
0
  }
1036
0
    }
1037
1038
  /* If this is a -Bsymbolic shared link, then we need to discard all PC
1039
     relative relocs against symbols defined in a regular object.  We
1040
     allocated space for them in the check_relocs routine, but we will not
1041
     fill them in in the relocate_section routine.  */
1042
0
  if (bfd_link_pic (info) && info->symbolic)
1043
0
    elf_vax_link_hash_traverse (elf_hash_table (info),
1044
0
        elf_vax_discard_copies,
1045
0
        NULL);
1046
1047
  /* If this is a -Bsymbolic shared link, we need to discard all the got
1048
     entries we've recorded.  Otherwise, we need to instantiate (allocate
1049
     space for them).  */
1050
0
  elf_link_hash_traverse (elf_hash_table (info),
1051
0
        elf_vax_instantiate_got_entries,
1052
0
        info);
1053
1054
  /* The check_relocs and adjust_dynamic_symbol entry points have
1055
     determined the sizes of the various dynamic sections.  Allocate
1056
     memory for them.  */
1057
0
  relocs = false;
1058
0
  for (s = dynobj->sections; s != NULL; s = s->next)
1059
0
    {
1060
0
      const char *name;
1061
1062
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
1063
0
  continue;
1064
1065
      /* It's OK to base decisions on the section name, because none
1066
   of the dynobj section names depend upon the input files.  */
1067
0
      name = bfd_section_name (s);
1068
1069
0
      if (strcmp (name, ".plt") == 0)
1070
0
  {
1071
    /* Remember whether there is a PLT.  */
1072
0
    ;
1073
0
  }
1074
0
      else if (startswith (name, ".rela"))
1075
0
  {
1076
0
    if (s->size != 0)
1077
0
      {
1078
0
        if (strcmp (name, ".rela.plt") != 0)
1079
0
    relocs = true;
1080
1081
        /* We use the reloc_count field as a counter if we need
1082
     to copy relocs into the output file.  */
1083
0
        s->reloc_count = 0;
1084
0
      }
1085
0
  }
1086
0
      else if (! startswith (name, ".got")
1087
0
         && strcmp (name, ".dynbss") != 0)
1088
0
  {
1089
    /* It's not one of our sections, so don't allocate space.  */
1090
0
    continue;
1091
0
  }
1092
1093
0
      if (s->size == 0)
1094
0
  {
1095
    /* If we don't need this section, strip it from the
1096
       output file.  This is mostly to handle .rela.bss and
1097
       .rela.plt.  We must create both sections in
1098
       create_dynamic_sections, because they must be created
1099
       before the linker maps input sections to output
1100
       sections.  The linker does that before
1101
       adjust_dynamic_symbol is called, and it is that
1102
       function which decides whether anything needs to go
1103
       into these sections.  */
1104
0
    s->flags |= SEC_EXCLUDE;
1105
0
    continue;
1106
0
  }
1107
1108
0
      if ((s->flags & SEC_HAS_CONTENTS) == 0)
1109
0
  continue;
1110
1111
      /* Allocate memory for the section contents.  */
1112
0
      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1113
0
      if (s->contents == NULL)
1114
0
  return false;
1115
0
      s->alloced = 1;
1116
0
    }
1117
1118
0
  return _bfd_elf_add_dynamic_tags (info, relocs);
1119
0
}
1120
1121
/* This function is called via elf_vax_link_hash_traverse if we are
1122
   creating a shared object with -Bsymbolic.  It discards the space
1123
   allocated to copy PC relative relocs against symbols which are defined
1124
   in regular objects.  We allocated space for them in the check_relocs
1125
   routine, but we won't fill them in in the relocate_section routine.  */
1126
1127
static bool
1128
elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
1129
      void * ignore ATTRIBUTE_UNUSED)
1130
0
{
1131
0
  struct elf_vax_pcrel_relocs_copied *s;
1132
1133
  /* We only discard relocs for symbols defined in a regular object.  */
1134
0
  if (!h->root.def_regular)
1135
0
    return true;
1136
1137
0
  for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1138
0
    s->section->size -= s->count * sizeof (Elf32_External_Rela);
1139
1140
0
  return true;
1141
0
}
1142
1143
/* This function is called via elf_link_hash_traverse.  It looks for
1144
   entries that have GOT or PLT (.GOT) references.  If creating a shared
1145
   object with -Bsymbolic, or the symbol has been forced local, then it
1146
   resets the reference count back to -1 so normal PC32 relocation will
1147
   be done.  Otherwise space in the .got and .rela.got will be reserved
1148
   for the symbol.  */
1149
1150
static bool
1151
elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, void * infoptr)
1152
0
{
1153
0
  struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
1154
0
  bfd *dynobj;
1155
0
  asection *sgot;
1156
0
  asection *srelgot;
1157
1158
  /* We don't care about non-GOT (and non-PLT) entries.  */
1159
0
  if (h->got.refcount <= 0 && h->plt.refcount <= 0)
1160
0
    return true;
1161
1162
0
  dynobj = elf_hash_table (info)->dynobj;
1163
0
  BFD_ASSERT (dynobj != NULL);
1164
1165
0
  sgot = elf_hash_table (info)->sgot;
1166
0
  srelgot = elf_hash_table (info)->srelgot;
1167
1168
0
  if (SYMBOL_REFERENCES_LOCAL (info, h))
1169
0
    {
1170
0
      h->got.refcount = -1;
1171
0
      h->plt.refcount = -1;
1172
0
    }
1173
0
  else if (h->got.refcount > 0)
1174
0
    {
1175
      /* Make sure this symbol is output as a dynamic symbol.  */
1176
0
      if (h->dynindx == -1)
1177
0
  {
1178
0
    if (!bfd_elf_link_record_dynamic_symbol (info, h))
1179
0
      return false;
1180
0
  }
1181
1182
      /* Allocate space in the .got and .rela.got sections.  */
1183
0
      sgot->size += 4;
1184
0
      srelgot->size += sizeof (Elf32_External_Rela);
1185
0
    }
1186
1187
0
  return true;
1188
0
}
1189
1190
/* Relocate an VAX ELF section.  */
1191
1192
static int
1193
elf_vax_relocate_section (struct bfd_link_info *info,
1194
        bfd *input_bfd,
1195
        asection *input_section,
1196
        bfd_byte *contents,
1197
        Elf_Internal_Rela *relocs,
1198
        Elf_Internal_Sym *local_syms,
1199
        asection **local_sections)
1200
0
{
1201
0
  Elf_Internal_Shdr *symtab_hdr;
1202
0
  struct elf_link_hash_entry **sym_hashes;
1203
0
  bfd_vma plt_index;
1204
0
  bfd_vma got_offset;
1205
0
  asection *sgot;
1206
0
  asection *splt;
1207
0
  asection *sgotplt;
1208
0
  asection *sreloc;
1209
0
  Elf_Internal_Rela *rel;
1210
0
  Elf_Internal_Rela *relend;
1211
1212
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
1213
0
  sym_hashes = elf_sym_hashes (input_bfd);
1214
1215
0
  sgot = NULL;
1216
0
  splt = NULL;
1217
0
  sgotplt = NULL;
1218
1219
0
  rel = relocs;
1220
0
  relend = relocs + input_section->reloc_count;
1221
0
  for (; rel < relend; rel++)
1222
0
    {
1223
0
      int r_type;
1224
0
      reloc_howto_type *howto;
1225
0
      unsigned long r_symndx;
1226
0
      struct elf_link_hash_entry *h;
1227
0
      Elf_Internal_Sym *sym;
1228
0
      asection *sec;
1229
0
      bfd_vma relocation;
1230
0
      bfd_reloc_status_type r;
1231
1232
0
      r_type = ELF32_R_TYPE (rel->r_info);
1233
0
      if (r_type < 0 || r_type >= (int) R_VAX_max)
1234
0
  {
1235
0
    bfd_set_error (bfd_error_bad_value);
1236
0
    return false;
1237
0
  }
1238
0
      howto = howto_table + r_type;
1239
1240
0
      r_symndx = ELF32_R_SYM (rel->r_info);
1241
0
      h = NULL;
1242
0
      sym = NULL;
1243
0
      sec = NULL;
1244
0
      if (r_symndx < symtab_hdr->sh_info)
1245
0
  {
1246
0
    sym = local_syms + r_symndx;
1247
0
    sec = local_sections[r_symndx];
1248
0
    relocation = _bfd_elf_rela_local_sym (info->output_bfd,
1249
0
            sym, &sec, rel);
1250
0
  }
1251
0
      else
1252
0
  {
1253
0
    bool unresolved_reloc;
1254
0
    bool warned, ignored;
1255
1256
0
    RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1257
0
           r_symndx, symtab_hdr, sym_hashes,
1258
0
           h, sec, relocation,
1259
0
           unresolved_reloc, warned, ignored);
1260
1261
0
    if ((h->root.type == bfd_link_hash_defined
1262
0
        || h->root.type == bfd_link_hash_defweak)
1263
0
        && ((r_type == R_VAX_PLT32
1264
0
       && h->plt.offset != (bfd_vma) -1
1265
0
       && !h->forced_local
1266
0
       && elf_hash_table (info)->dynamic_sections_created)
1267
0
      || (r_type == R_VAX_GOT32
1268
0
          && h->got.offset != (bfd_vma) -1
1269
0
          && !h->forced_local
1270
0
          && elf_hash_table (info)->dynamic_sections_created
1271
0
          && (! bfd_link_pic (info)
1272
0
        || (! info->symbolic && h->dynindx != -1)
1273
0
        || !h->def_regular))
1274
0
      || (bfd_link_pic (info)
1275
0
          && ((! info->symbolic && h->dynindx != -1)
1276
0
        || !h->def_regular)
1277
0
          && ((input_section->flags & SEC_ALLOC) != 0
1278
        /* DWARF will emit R_VAX_32 relocations in its
1279
           sections against symbols defined externally
1280
           in shared libraries.  We can't do anything
1281
           with them here.  */
1282
1283
0
        || ((input_section->flags & SEC_DEBUGGING) != 0
1284
0
            && h->def_dynamic))
1285
0
          && (r_type == R_VAX_8
1286
0
        || r_type == R_VAX_16
1287
0
        || r_type == R_VAX_32))))
1288
      /* In these cases, we don't need the relocation
1289
         value.  We check specially because in some
1290
         obscure cases sec->output_section will be NULL.  */
1291
0
      relocation = 0;
1292
0
  }
1293
1294
0
      if (sec != NULL && discarded_section (sec))
1295
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1296
0
           rel, 1, relend, R_VAX_NONE,
1297
0
           howto, 0, contents);
1298
1299
0
      if (bfd_link_relocatable (info))
1300
0
  continue;
1301
1302
0
      switch (r_type)
1303
0
  {
1304
0
  case R_VAX_GOT32:
1305
    /* Relocation is to the address of the entry for this symbol
1306
       in the global offset table.  */
1307
1308
    /* Resolve a GOTxx reloc against a local symbol directly,
1309
       without using the global offset table.  */
1310
0
    if (h == NULL
1311
0
        || h->got.offset == (bfd_vma) -1)
1312
0
      break;
1313
1314
0
    {
1315
0
      bfd_vma off;
1316
1317
0
      sgot = elf_hash_table (info)->sgot;
1318
0
      BFD_ASSERT (sgot != NULL);
1319
1320
0
      off = h->got.offset;
1321
0
      BFD_ASSERT (off < sgot->size);
1322
1323
0
      bfd_put_32 (info->output_bfd, rel->r_addend, sgot->contents + off);
1324
1325
0
      relocation = sgot->output_offset + off;
1326
      /* The GOT relocation uses the addend.  */
1327
0
      rel->r_addend = 0;
1328
1329
      /* Change the reference to be indirect.  */
1330
0
      contents[rel->r_offset - 1] |= 0x10;
1331
0
      relocation += sgot->output_section->vma;
1332
0
    }
1333
0
    break;
1334
1335
0
  case R_VAX_PC32:
1336
    /* If we are creating an executable and the function this
1337
       reloc refers to is in a shared lib, then we made a PLT
1338
       entry for this symbol and need to handle the reloc like
1339
       a PLT reloc.  */
1340
0
    if (bfd_link_pic (info))
1341
0
       goto r_vax_pc32_shared;
1342
    /* Fall through.  */
1343
0
  case R_VAX_PLT32:
1344
    /* Relocation is to the entry for this symbol in the
1345
       procedure linkage table.  */
1346
1347
    /* Resolve a PLTxx reloc against a local symbol directly,
1348
       without using the procedure linkage table.  */
1349
0
    if (h == NULL
1350
0
        || h->plt.offset == (bfd_vma) -1)
1351
0
      break;
1352
1353
0
    splt = elf_hash_table (info)->splt;
1354
0
    BFD_ASSERT (splt != NULL);
1355
1356
0
    sgotplt = elf_hash_table (info)->sgotplt;
1357
0
    BFD_ASSERT (sgotplt != NULL);
1358
1359
0
    plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1360
1361
    /* Get the offset into the .got table of the entry that
1362
       corresponds to this function.  Each .got entry is 4 bytes.
1363
       The first two are reserved.  */
1364
0
    got_offset = (plt_index + 3) * 4;
1365
1366
    /* We want the relocation to point into the .got.plt instead
1367
       of the plt itself.  */
1368
0
    relocation = (sgotplt->output_section->vma
1369
0
      + sgotplt->output_offset
1370
0
      + got_offset);
1371
0
    contents[rel->r_offset-1] |= 0x10; /* make indirect */
1372
0
    if (rel->r_addend == 2)
1373
0
      {
1374
0
        h->plt.offset |= 1;
1375
0
      }
1376
0
    else if (rel->r_addend != 0)
1377
0
      _bfd_error_handler
1378
        /* xgettext:c-format */
1379
0
        (_("%pB: warning: PLT addend of %" PRId64 " to `%s'"
1380
0
     " from %pA section ignored"),
1381
0
         input_bfd, (int64_t) rel->r_addend, h->root.root.string,
1382
0
         input_section);
1383
0
    rel->r_addend = 0;
1384
1385
0
    break;
1386
1387
0
  case R_VAX_PC8:
1388
0
  case R_VAX_PC16:
1389
0
  r_vax_pc32_shared:
1390
0
    if (h == NULL
1391
0
        || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1392
0
        || h->forced_local)
1393
0
      break;
1394
    /* Fall through.  */
1395
0
  case R_VAX_8:
1396
0
  case R_VAX_16:
1397
0
  case R_VAX_32:
1398
0
    if (bfd_link_pic (info)
1399
0
        && r_symndx != STN_UNDEF
1400
0
        && (input_section->flags & SEC_ALLOC) != 0
1401
0
        && ((r_type != R_VAX_PC8
1402
0
       && r_type != R_VAX_PC16
1403
0
       && r_type != R_VAX_PC32)
1404
0
      || ((input_section->flags & SEC_CODE)
1405
0
          && (!info->symbolic
1406
0
        || (!h->def_regular && h->type != STT_SECTION)))))
1407
0
      {
1408
0
        Elf_Internal_Rela outrel;
1409
0
        bfd_byte *loc;
1410
0
        bool skip, relocate;
1411
1412
        /* When generating a shared object, these relocations
1413
     are copied into the output file to be resolved at run
1414
     time.  */
1415
0
        sreloc = elf_section_data (input_section)->sreloc;
1416
0
        if (sreloc == NULL)
1417
0
    return false;
1418
1419
0
        skip = false;
1420
0
        relocate = false;
1421
1422
0
        outrel.r_offset =
1423
0
    _bfd_elf_section_offset (info->output_bfd, info,
1424
0
           input_section, rel->r_offset);
1425
0
        if (outrel.r_offset == (bfd_vma) -1)
1426
0
    skip = true;
1427
0
        if (outrel.r_offset == (bfd_vma) -2)
1428
0
    skip = true, relocate = true;
1429
0
        outrel.r_offset += (input_section->output_section->vma
1430
0
          + input_section->output_offset);
1431
1432
0
        if (skip)
1433
0
      memset (&outrel, 0, sizeof outrel);
1434
        /* h->dynindx may be -1 if the symbol was marked to
1435
     become local.  */
1436
0
        else if (h != NULL
1437
0
           && ((! info->symbolic && h->dynindx != -1)
1438
0
         || !h->def_regular))
1439
0
    {
1440
0
      BFD_ASSERT (h->dynindx != -1);
1441
0
      outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1442
0
      outrel.r_addend = relocation + rel->r_addend;
1443
0
    }
1444
0
        else
1445
0
    {
1446
0
      if (r_type == R_VAX_32)
1447
0
        {
1448
0
          relocate = true;
1449
0
          outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1450
0
          BFD_ASSERT (bfd_get_signed_32 (input_bfd,
1451
0
                 &contents[rel->r_offset]) == 0);
1452
0
          outrel.r_addend = relocation + rel->r_addend;
1453
0
        }
1454
0
      else
1455
0
        {
1456
0
          long indx;
1457
1458
0
          if (bfd_is_abs_section (sec))
1459
0
      indx = 0;
1460
0
          else if (sec == NULL || sec->owner == NULL)
1461
0
      {
1462
0
        bfd_set_error (bfd_error_bad_value);
1463
0
        return false;
1464
0
      }
1465
0
          else
1466
0
      {
1467
0
        asection *osec;
1468
1469
        /* We are turning this relocation into one
1470
           against a section symbol.  It would be
1471
           proper to subtract the symbol's value,
1472
           osec->vma, from the emitted reloc addend,
1473
           but ld.so expects buggy relocs.  */
1474
0
        osec = sec->output_section;
1475
0
        indx = elf_section_data (osec)->dynindx;
1476
0
        if (indx == 0)
1477
0
          {
1478
0
            struct elf_link_hash_table *htab;
1479
0
            htab = elf_hash_table (info);
1480
0
            osec = htab->text_index_section;
1481
0
            indx = elf_section_data (osec)->dynindx;
1482
0
          }
1483
0
        BFD_ASSERT (indx != 0);
1484
0
      }
1485
1486
0
          outrel.r_info = ELF32_R_INFO (indx, r_type);
1487
0
          outrel.r_addend = relocation + rel->r_addend;
1488
0
        }
1489
0
    }
1490
1491
0
        if ((input_section->flags & SEC_CODE) != 0
1492
0
      || (ELF32_R_TYPE (outrel.r_info) != R_VAX_32
1493
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_RELATIVE
1494
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_COPY
1495
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_JMP_SLOT
1496
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_GLOB_DAT))
1497
0
    {
1498
0
      if (h != NULL)
1499
0
        _bfd_error_handler
1500
          /* xgettext:c-format */
1501
0
          (_("%pB: warning: %s relocation against symbol `%s'"
1502
0
       " from %pA section"),
1503
0
          input_bfd, howto->name, h->root.root.string,
1504
0
          input_section);
1505
0
      else
1506
0
        _bfd_error_handler
1507
          /* xgettext:c-format */
1508
0
          (_("%pB: warning: %s relocation to %#" PRIx64
1509
0
       " from %pA section"),
1510
0
          input_bfd, howto->name, (uint64_t) outrel.r_addend,
1511
0
          input_section);
1512
0
    }
1513
0
        loc = sreloc->contents;
1514
0
        loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1515
0
        bfd_elf32_swap_reloca_out (info->output_bfd, &outrel, loc);
1516
1517
        /* This reloc will be computed at runtime, so there's no
1518
     need to do anything now, except for R_VAX_32
1519
     relocations that have been turned into
1520
     R_VAX_RELATIVE.  */
1521
0
        if (!relocate)
1522
0
    continue;
1523
0
      }
1524
1525
0
    break;
1526
1527
0
  case R_VAX_GNU_VTINHERIT:
1528
0
  case R_VAX_GNU_VTENTRY:
1529
    /* These are no-ops in the end.  */
1530
0
    continue;
1531
1532
0
  default:
1533
0
    break;
1534
0
  }
1535
1536
      /* VAX PCREL relocations are from the end of relocation, not the start.
1537
   So subtract the difference from the relocation amount since we can't
1538
   add it to the offset.  */
1539
0
      if (howto->pc_relative && howto->pcrel_offset)
1540
0
  relocation -= bfd_get_reloc_size(howto);
1541
1542
0
      r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1543
0
            contents, rel->r_offset,
1544
0
            relocation, rel->r_addend);
1545
1546
0
      if (r != bfd_reloc_ok)
1547
0
  {
1548
0
    switch (r)
1549
0
      {
1550
0
      default:
1551
0
      case bfd_reloc_outofrange:
1552
0
        abort ();
1553
0
      case bfd_reloc_overflow:
1554
0
        {
1555
0
    const char *name;
1556
1557
0
    if (h != NULL)
1558
0
      name = NULL;
1559
0
    else
1560
0
      {
1561
0
        name = bfd_elf_string_from_elf_section (input_bfd,
1562
0
                  symtab_hdr->sh_link,
1563
0
                  sym->st_name);
1564
0
        if (name == NULL)
1565
0
          return false;
1566
0
        if (*name == '\0')
1567
0
          name = bfd_section_name (sec);
1568
0
      }
1569
0
    info->callbacks->reloc_overflow
1570
0
      (info, (h ? &h->root : NULL), name, howto->name,
1571
0
       (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1572
0
        }
1573
0
        break;
1574
0
      }
1575
0
  }
1576
0
    }
1577
1578
0
  return true;
1579
0
}
1580
1581
/* Finish up dynamic symbol handling.  We set the contents of various
1582
   dynamic sections here.  */
1583
1584
static bool
1585
elf_vax_finish_dynamic_symbol (struct bfd_link_info *info,
1586
             struct elf_link_hash_entry *h,
1587
             Elf_Internal_Sym *sym)
1588
0
{
1589
0
  bfd *dynobj;
1590
1591
0
  dynobj = elf_hash_table (info)->dynobj;
1592
1593
0
  if (h->plt.offset != (bfd_vma) -1)
1594
0
    {
1595
0
      asection *splt;
1596
0
      asection *sgot;
1597
0
      asection *srela;
1598
0
      bfd_vma plt_index;
1599
0
      bfd_vma got_offset;
1600
0
      bfd_vma addend;
1601
0
      Elf_Internal_Rela rela;
1602
0
      bfd_byte *loc;
1603
1604
      /* This symbol has an entry in the procedure linkage table.  Set
1605
   it up.  */
1606
0
      BFD_ASSERT (h->dynindx != -1);
1607
1608
0
      splt = elf_hash_table (info)->splt;
1609
0
      sgot = elf_hash_table (info)->sgotplt;
1610
0
      srela = elf_hash_table (info)->srelplt;
1611
0
      BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1612
1613
0
      addend = 2 * (h->plt.offset & 1);
1614
0
      h->plt.offset &= ~1;
1615
1616
      /* Get the index in the procedure linkage table which
1617
   corresponds to this symbol.  This is the index of this symbol
1618
   in all the symbols for which we are making plt entries.  The
1619
   first entry in the procedure linkage table is reserved.  */
1620
0
      plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1621
1622
      /* Get the offset into the .got table of the entry that
1623
   corresponds to this function.  Each .got entry is 4 bytes.
1624
   The first two are reserved.  */
1625
0
      got_offset = (plt_index + 3) * 4;
1626
1627
      /* Fill in the entry in the procedure linkage table.  */
1628
0
      memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
1629
0
      PLT_ENTRY_SIZE);
1630
1631
      /* The offset is relative to the first extension word.  */
1632
0
      bfd_put_32 (info->output_bfd,
1633
0
      -(h->plt.offset + 8),
1634
0
      splt->contents + h->plt.offset + 4);
1635
1636
0
      bfd_put_32 (info->output_bfd, plt_index * sizeof (Elf32_External_Rela),
1637
0
      splt->contents + h->plt.offset + 8);
1638
1639
      /* Fill in the entry in the global offset table.  */
1640
0
      bfd_put_32 (info->output_bfd,
1641
0
      (splt->output_section->vma
1642
0
       + splt->output_offset
1643
0
       + h->plt.offset) + addend,
1644
0
      sgot->contents + got_offset);
1645
1646
      /* Fill in the entry in the .rela.plt section.  */
1647
0
      rela.r_offset = (sgot->output_section->vma
1648
0
           + sgot->output_offset
1649
0
           + got_offset);
1650
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
1651
0
      rela.r_addend = addend;
1652
0
      loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
1653
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1654
1655
0
      if (!h->def_regular)
1656
0
  {
1657
    /* Mark the symbol as undefined, rather than as defined in
1658
       the .plt section.  Leave the value alone.  */
1659
0
    sym->st_shndx = SHN_UNDEF;
1660
0
  }
1661
0
    }
1662
1663
0
  if (h->got.offset != (bfd_vma) -1)
1664
0
    {
1665
0
      asection *sgot;
1666
0
      asection *srela;
1667
0
      Elf_Internal_Rela rela;
1668
0
      bfd_byte *loc;
1669
1670
      /* This symbol has an entry in the global offset table.  Set it
1671
   up.  */
1672
0
      sgot = elf_hash_table (info)->sgot;
1673
0
      srela = elf_hash_table (info)->srelgot;
1674
0
      BFD_ASSERT (sgot != NULL && srela != NULL);
1675
1676
0
      rela.r_offset = (sgot->output_section->vma
1677
0
           + sgot->output_offset
1678
0
           + h->got.offset);
1679
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
1680
0
      rela.r_addend = bfd_get_signed_32 (info->output_bfd,
1681
0
           sgot->contents + h->got.offset);
1682
1683
0
      loc = srela->contents;
1684
0
      loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
1685
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1686
0
    }
1687
1688
0
  if (h->needs_copy)
1689
0
    {
1690
0
      asection *s;
1691
0
      Elf_Internal_Rela rela;
1692
0
      bfd_byte *loc;
1693
1694
      /* This symbol needs a copy reloc.  Set it up.  */
1695
0
      BFD_ASSERT (h->dynindx != -1
1696
0
      && (h->root.type == bfd_link_hash_defined
1697
0
          || h->root.type == bfd_link_hash_defweak));
1698
1699
0
      s = bfd_get_linker_section (dynobj, ".rela.bss");
1700
0
      BFD_ASSERT (s != NULL);
1701
1702
0
      rela.r_offset = (h->root.u.def.value
1703
0
           + h->root.u.def.section->output_section->vma
1704
0
           + h->root.u.def.section->output_offset);
1705
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
1706
0
      rela.r_addend = 0;
1707
0
      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
1708
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1709
0
    }
1710
1711
  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
1712
0
  if (h == elf_hash_table (info)->hdynamic
1713
0
      || h == elf_hash_table (info)->hgot)
1714
0
    sym->st_shndx = SHN_ABS;
1715
1716
0
  return true;
1717
0
}
1718
1719
/* Finish up the dynamic sections.  */
1720
1721
static bool
1722
elf_vax_finish_dynamic_sections (struct bfd_link_info *info,
1723
         bfd_byte *buf ATTRIBUTE_UNUSED)
1724
0
{
1725
0
  bfd *dynobj;
1726
0
  asection *sgot;
1727
0
  asection *sdyn;
1728
1729
0
  dynobj = elf_hash_table (info)->dynobj;
1730
1731
0
  sgot = elf_hash_table (info)->sgotplt;
1732
0
  BFD_ASSERT (sgot != NULL);
1733
0
  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
1734
1735
0
  if (elf_hash_table (info)->dynamic_sections_created)
1736
0
    {
1737
0
      asection *splt;
1738
0
      Elf32_External_Dyn *dyncon, *dynconend;
1739
1740
0
      splt = elf_hash_table (info)->splt;
1741
0
      BFD_ASSERT (splt != NULL && sdyn != NULL);
1742
1743
0
      dyncon = (Elf32_External_Dyn *) sdyn->contents;
1744
0
      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
1745
0
      for (; dyncon < dynconend; dyncon++)
1746
0
  {
1747
0
    Elf_Internal_Dyn dyn;
1748
0
    asection *s;
1749
1750
0
    bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1751
1752
0
    switch (dyn.d_tag)
1753
0
      {
1754
0
      default:
1755
0
        break;
1756
1757
0
      case DT_PLTGOT:
1758
0
        s = elf_hash_table (info)->sgotplt;
1759
0
        goto get_vma;
1760
0
      case DT_JMPREL:
1761
0
        s = elf_hash_table (info)->srelplt;
1762
0
      get_vma:
1763
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
1764
0
        bfd_elf32_swap_dyn_out (info->output_bfd, &dyn, dyncon);
1765
0
        break;
1766
1767
0
      case DT_PLTRELSZ:
1768
0
        s = elf_hash_table (info)->srelplt;
1769
0
        dyn.d_un.d_val = s->size;
1770
0
        bfd_elf32_swap_dyn_out (info->output_bfd, &dyn, dyncon);
1771
0
        break;
1772
0
      }
1773
0
  }
1774
1775
      /* Fill in the first entry in the procedure linkage table.  */
1776
0
      if (splt->size > 0)
1777
0
  {
1778
0
    memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
1779
0
    bfd_put_32 (info->output_bfd,
1780
0
        (sgot->output_section->vma
1781
0
         + sgot->output_offset + 4
1782
0
         - (splt->output_section->vma + 6)),
1783
0
        splt->contents + 2);
1784
0
    bfd_put_32 (info->output_bfd,
1785
0
        (sgot->output_section->vma
1786
0
         + sgot->output_offset + 8
1787
0
         - (splt->output_section->vma + 12)),
1788
0
        splt->contents + 8);
1789
0
    elf_section_data (splt->output_section)->this_hdr.sh_entsize
1790
0
     = PLT_ENTRY_SIZE;
1791
0
  }
1792
0
    }
1793
1794
  /* Fill in the first three entries in the global offset table.  */
1795
0
  if (sgot->size > 0)
1796
0
    {
1797
0
      if (sdyn == NULL)
1798
0
  bfd_put_32 (info->output_bfd, 0, sgot->contents);
1799
0
      else
1800
0
  bfd_put_32 (info->output_bfd,
1801
0
        sdyn->output_section->vma + sdyn->output_offset,
1802
0
        sgot->contents);
1803
0
      bfd_put_32 (info->output_bfd, 0, sgot->contents + 4);
1804
0
      bfd_put_32 (info->output_bfd, 0, sgot->contents + 8);
1805
0
    }
1806
1807
0
  if (elf_section_data (sgot->output_section) != NULL)
1808
0
    elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1809
1810
0
  return true;
1811
0
}
1812
1813
static enum elf_reloc_type_class
1814
elf_vax_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
1815
        const asection *rel_sec ATTRIBUTE_UNUSED,
1816
        const Elf_Internal_Rela *rela)
1817
0
{
1818
0
  switch ((int) ELF32_R_TYPE (rela->r_info))
1819
0
    {
1820
0
    case R_VAX_RELATIVE:
1821
0
      return reloc_class_relative;
1822
0
    case R_VAX_JMP_SLOT:
1823
0
      return reloc_class_plt;
1824
0
    case R_VAX_COPY:
1825
0
      return reloc_class_copy;
1826
0
    default:
1827
0
      return reloc_class_normal;
1828
0
    }
1829
0
}
1830
1831
static bfd_vma
1832
elf_vax_plt_sym_val (bfd_vma i, const asection *plt,
1833
         const arelent *rel ATTRIBUTE_UNUSED)
1834
0
{
1835
0
  return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
1836
0
}
1837
1838
#define TARGET_LITTLE_SYM   vax_elf32_vec
1839
#define TARGET_LITTLE_NAME    "elf32-vax"
1840
#define ELF_TARGET_ID     VAX_ELF_DATA
1841
#define ELF_MACHINE_CODE    EM_VAX
1842
#define ELF_MAXPAGESIZE     0x1000
1843
1844
#define elf_backend_create_dynamic_sections \
1845
          _bfd_elf_create_dynamic_sections
1846
#define bfd_elf32_bfd_link_hash_table_create \
1847
          elf_vax_link_hash_table_create
1848
#define bfd_elf32_bfd_final_link  _bfd_elf_gc_common_final_link
1849
1850
#define elf_backend_check_relocs  elf_vax_check_relocs
1851
#define elf_backend_adjust_dynamic_symbol \
1852
          elf_vax_adjust_dynamic_symbol
1853
#define elf_backend_early_size_sections elf_vax_early_size_sections
1854
#define elf_backend_late_size_sections  elf_vax_late_size_sections
1855
#define elf_backend_init_index_section  _bfd_elf_init_1_index_section
1856
#define elf_backend_relocate_section  elf_vax_relocate_section
1857
#define elf_backend_finish_dynamic_symbol \
1858
          elf_vax_finish_dynamic_symbol
1859
#define elf_backend_finish_dynamic_sections \
1860
          elf_vax_finish_dynamic_sections
1861
#define elf_backend_reloc_type_class  elf_vax_reloc_type_class
1862
#define elf_backend_gc_mark_hook  elf_vax_gc_mark_hook
1863
#define elf_backend_plt_sym_val   elf_vax_plt_sym_val
1864
#define bfd_elf32_bfd_merge_private_bfd_data \
1865
          elf32_vax_merge_private_bfd_data
1866
#define bfd_elf32_bfd_set_private_flags \
1867
          elf32_vax_set_private_flags
1868
#define bfd_elf32_bfd_print_private_bfd_data \
1869
          elf32_vax_print_private_bfd_data
1870
1871
#define elf_backend_can_gc_sections 1
1872
#define elf_backend_want_got_plt  1
1873
#define elf_backend_plt_readonly  1
1874
#define elf_backend_want_plt_sym  0
1875
#define elf_backend_got_header_size 16
1876
#define elf_backend_rela_normal   1
1877
#define elf_backend_dtrel_excludes_plt  1
1878
1879
#include "elf32-target.h"