Coverage Report

Created: 2026-09-14 08:07

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
60
{
274
60
  unsigned int r_type;
275
276
60
  r_type = ELF32_R_TYPE (dst->r_info);
277
60
  if (r_type >= R_VAX_max)
278
10
    {
279
      /* xgettext:c-format */
280
10
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
281
10
        abfd, r_type);
282
10
      bfd_set_error (bfd_error_bad_value);
283
10
      return false;
284
10
    }
285
50
  cache_ptr->howto = &howto_table[r_type];
286
50
  return true;
287
60
}
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
13
{
515
13
  FILE *file = (FILE *) ptr;
516
517
13
  BFD_ASSERT (abfd != NULL && ptr != NULL);
518
519
  /* Print normal ELF private data.  */
520
13
  _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
13
  fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
526
527
13
  if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
528
0
    fprintf (file, _(" [nonpic]"));
529
530
13
  if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
531
1
    fprintf (file, _(" [d-float]"));
532
533
13
  if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
534
0
    fprintf (file, _(" [g-float]"));
535
536
13
  fputc ('\n', file);
537
538
13
  return true;
539
13
}
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
0
        dynobj = _bfd_elf_link_dynobj (info);
599
0
        if (dynobj == NULL)
600
0
    return false;
601
0
      }
602
603
0
    if (!_bfd_elf_create_got_section (dynobj, info))
604
0
      return false;
605
606
0
    if (h != NULL)
607
0
      {
608
0
        struct elf_vax_link_hash_entry *eh;
609
610
0
        eh = (struct elf_vax_link_hash_entry *) h;
611
0
        if (h->got.refcount == -1)
612
0
    {
613
0
      h->got.refcount = 1;
614
0
      eh->got_addend = rel->r_addend;
615
0
    }
616
0
        else
617
0
    {
618
0
      h->got.refcount++;
619
0
      if (eh->got_addend != (bfd_vma) rel->r_addend)
620
0
        _bfd_error_handler
621
          /* xgettext:c-format */
622
0
          (_("%pB: warning: GOT addend of %" PRId64 " to `%s' does"
623
0
       " not match previous GOT addend of %" PRId64),
624
0
       abfd, (int64_t) rel->r_addend, h->root.root.string,
625
0
       (int64_t) eh->got_addend);
626
627
0
    }
628
0
      }
629
0
    break;
630
631
0
  case R_VAX_PLT32:
632
    /* This symbol requires a procedure linkage table entry.  We
633
       actually build the entry in adjust_dynamic_symbol,
634
       because this might be a case of linking PIC code which is
635
       never referenced by a dynamic object, in which case we
636
       don't need to generate a procedure linkage table entry
637
       after all.  */
638
0
    BFD_ASSERT (h != NULL);
639
640
    /* If this is a local symbol, we resolve it directly without
641
       creating a procedure linkage table entry.  */
642
0
    if (h->forced_local)
643
0
      break;
644
645
0
    h->needs_plt = 1;
646
0
    if (h->plt.refcount == -1)
647
0
      h->plt.refcount = 1;
648
0
    else
649
0
      h->plt.refcount++;
650
0
    break;
651
652
0
  case R_VAX_PC8:
653
0
  case R_VAX_PC16:
654
0
  case R_VAX_PC32:
655
    /* If we are creating a shared library and this is not a local
656
       symbol, we need to copy the reloc into the shared library.
657
       However when linking with -Bsymbolic and this is a global
658
       symbol which is defined in an object we are including in the
659
       link (i.e., DEF_REGULAR is set), then we can resolve the
660
       reloc directly.  At this point we have not seen all the input
661
       files, so it is possible that DEF_REGULAR is not set now but
662
       will be set later (it is never cleared).  We account for that
663
       possibility below by storing information in the
664
       pcrel_relocs_copied field of the hash table entry.  */
665
0
    if (!(bfd_link_pic (info)
666
0
    && (sec->flags & SEC_ALLOC) != 0
667
0
    && h != NULL
668
0
    && (!info->symbolic
669
0
        || !h->def_regular)))
670
0
      {
671
0
        if (h != NULL
672
0
      && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
673
0
      && !h->forced_local)
674
0
    {
675
      /* Make sure a plt entry is created for this symbol if
676
         it turns out to be a function defined by a dynamic
677
         object.  */
678
0
      if (h->plt.refcount == -1)
679
0
        h->plt.refcount = 1;
680
0
      else
681
0
        h->plt.refcount++;
682
0
    }
683
0
        break;
684
0
      }
685
    /* If this is a local symbol, we can resolve it directly.  */
686
0
    if (h != NULL
687
0
        && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
688
0
      || h->forced_local))
689
0
      break;
690
691
    /* Fall through.  */
692
0
  case R_VAX_8:
693
0
  case R_VAX_16:
694
0
  case R_VAX_32:
695
0
    if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
696
0
      {
697
        /* Make sure a plt entry is created for this symbol if it
698
     turns out to be a function defined by a dynamic object.  */
699
0
        if (h->plt.refcount == -1)
700
0
    h->plt.refcount = 1;
701
0
        else
702
0
    h->plt.refcount++;
703
0
      }
704
705
    /* Non-GOT reference may need a copy reloc in executable or
706
       a dynamic reloc in shared library.  */
707
0
    if (h != NULL)
708
0
      h->non_got_ref = 1;
709
710
    /* If we are creating a shared library, we need to copy the
711
       reloc into the shared library.  */
712
0
    if (bfd_link_pic (info)
713
0
        && (sec->flags & SEC_ALLOC) != 0)
714
0
      {
715
        /* When creating a shared object, we must copy these
716
     reloc types into the output file.  We create a reloc
717
     section in dynobj and make room for this reloc.  */
718
0
        if (sreloc == NULL)
719
0
    {
720
0
      sreloc = _bfd_elf_make_dynamic_reloc_section
721
0
        (sec, dynobj, 2, abfd, /*rela?*/ true);
722
723
0
      if (sreloc == NULL)
724
0
        return false;
725
726
0
      if (sec->flags & SEC_READONLY)
727
0
        info->flags |= DF_TEXTREL;
728
0
    }
729
730
0
        sreloc->size += sizeof (Elf32_External_Rela);
731
732
        /* If we are linking with -Bsymbolic, we count the number of
733
     PC relative relocations we have entered for this symbol,
734
     so that we can discard them again if the symbol is later
735
     defined by a regular object.  Note that this function is
736
     only called if we are using a vaxelf linker hash table,
737
     which means that h is really a pointer to an
738
     elf_vax_link_hash_entry.  */
739
0
        if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
740
0
       || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
741
0
       || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
742
0
      && info->symbolic)
743
0
    {
744
0
      struct elf_vax_link_hash_entry *eh;
745
0
      struct elf_vax_pcrel_relocs_copied *p;
746
747
0
      eh = (struct elf_vax_link_hash_entry *) h;
748
749
0
      for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
750
0
        if (p->section == sreloc)
751
0
          break;
752
753
0
      if (p == NULL)
754
0
        {
755
0
          p = ((struct elf_vax_pcrel_relocs_copied *)
756
0
         bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
757
0
          if (p == NULL)
758
0
      return false;
759
0
          p->next = eh->pcrel_relocs_copied;
760
0
          eh->pcrel_relocs_copied = p;
761
0
          p->section = sreloc;
762
0
          p->count = 0;
763
0
        }
764
765
0
      ++p->count;
766
0
    }
767
0
      }
768
769
0
    break;
770
771
    /* This relocation describes the C++ object vtable hierarchy.
772
       Reconstruct it for later use during GC.  */
773
0
  case R_VAX_GNU_VTINHERIT:
774
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
775
0
      return false;
776
0
    break;
777
778
    /* This relocation describes which C++ vtable entries are actually
779
       used.  Record for later use during GC.  */
780
0
  case R_VAX_GNU_VTENTRY:
781
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
782
0
      return false;
783
0
    break;
784
785
0
  default:
786
0
    break;
787
0
  }
788
0
    }
789
790
0
  return true;
791
0
}
792
793
/* Return the section that should be marked against GC for a given
794
   relocation.  */
795
796
static asection *
797
elf_vax_gc_mark_hook (asection *sec,
798
          struct bfd_link_info *info,
799
          struct elf_reloc_cookie *cookie,
800
          struct elf_link_hash_entry *h,
801
          unsigned int symndx)
802
0
{
803
0
  if (h != NULL)
804
0
    switch (ELF32_R_TYPE (cookie->rel->r_info))
805
0
      {
806
0
      case R_VAX_GNU_VTINHERIT:
807
0
      case R_VAX_GNU_VTENTRY:
808
0
  return NULL;
809
0
      }
810
811
0
  return _bfd_elf_gc_mark_hook (sec, info, cookie, h, symndx);
812
0
}
813
814
/* Adjust a symbol defined by a dynamic object and referenced by a
815
   regular object.  The current definition is in some section of the
816
   dynamic object, but we're not including those sections.  We have to
817
   change the definition to something the rest of the link can
818
   understand.  */
819
820
static bool
821
elf_vax_adjust_dynamic_symbol (struct bfd_link_info *info,
822
             struct elf_link_hash_entry *h)
823
0
{
824
0
  bfd *dynobj;
825
0
  asection *s;
826
827
0
  dynobj = elf_hash_table (info)->dynobj;
828
829
  /* Make sure we know what is going on here.  */
830
0
  BFD_ASSERT (dynobj != NULL
831
0
        && (h->needs_plt
832
0
      || h->is_weakalias
833
0
      || (h->def_dynamic
834
0
          && h->ref_regular
835
0
          && !h->def_regular)));
836
837
  /* If this is a function, put it in the procedure linkage table.  We
838
     will fill in the contents of the procedure linkage table later,
839
     when we know the address of the .got section.  */
840
0
  if (h->type == STT_FUNC
841
0
      || h->needs_plt)
842
0
    {
843
0
      if (h->plt.refcount <= 0
844
0
    || SYMBOL_CALLS_LOCAL (info, h)
845
0
    || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
846
0
        && h->root.type == bfd_link_hash_undefweak))
847
0
  {
848
    /* This case can occur if we saw a PLTxx reloc in an input
849
       file, but the symbol was never referred to by a dynamic
850
       object, or if all references were garbage collected.  In
851
       such a case, we don't actually need to build a procedure
852
       linkage table, and we can just do a PCxx reloc instead.  */
853
0
    h->plt.offset = (bfd_vma) -1;
854
0
    h->needs_plt = 0;
855
0
    return true;
856
0
  }
857
858
0
      s = elf_hash_table (info)->splt;
859
0
      BFD_ASSERT (s != NULL);
860
861
      /* If this is the first .plt entry, make room for the special
862
   first entry.  */
863
0
      if (s->size == 0)
864
0
  {
865
0
    s->size += PLT_ENTRY_SIZE;
866
0
  }
867
868
      /* If this symbol is not defined in a regular file, and we are
869
   not generating a shared library, then set the symbol to this
870
   location in the .plt.  This is required to make function
871
   pointers compare as equal between the normal executable and
872
   the shared library.  */
873
0
      if (!bfd_link_pic (info)
874
0
    && !h->def_regular)
875
0
  {
876
0
    h->root.u.def.section = s;
877
0
    h->root.u.def.value = s->size;
878
0
  }
879
880
0
      h->plt.offset = s->size;
881
882
      /* Make room for this entry.  */
883
0
      s->size += PLT_ENTRY_SIZE;
884
885
      /* We also need to make an entry in the .got.plt section, which
886
   will be placed in the .got section by the linker script.  */
887
888
0
      s = elf_hash_table (info)->sgotplt;
889
0
      BFD_ASSERT (s != NULL);
890
0
      s->size += 4;
891
892
      /* We also need to make an entry in the .rela.plt section.  */
893
894
0
      s = elf_hash_table (info)->srelplt;
895
0
      BFD_ASSERT (s != NULL);
896
0
      s->size += sizeof (Elf32_External_Rela);
897
898
0
      return true;
899
0
    }
900
901
  /* Reinitialize the plt offset now that it is not used as a reference
902
     count any more.  */
903
0
  h->plt.offset = (bfd_vma) -1;
904
905
  /* If this is a weak symbol, and there is a real definition, the
906
     processor independent code will have arranged for us to see the
907
     real definition first, and we can just use the same value.  */
908
0
  if (h->is_weakalias)
909
0
    {
910
0
      struct elf_link_hash_entry *def = weakdef (h);
911
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
912
0
      h->root.u.def.section = def->root.u.def.section;
913
0
      h->root.u.def.value = def->root.u.def.value;
914
0
      return true;
915
0
    }
916
917
  /* This is a reference to a symbol defined by a dynamic object which
918
     is not a function.  */
919
920
  /* If we are creating a shared library, we must presume that the
921
     only references to the symbol are via the global offset table.
922
     For such cases we need not do anything here; the relocations will
923
     be handled correctly by relocate_section.  */
924
0
  if (bfd_link_pic (info))
925
0
    return true;
926
927
  /* If there are no references to this symbol that do not use the
928
     GOT relocation, we don't need to generate a copy reloc.  */
929
0
  if (!h->non_got_ref)
930
0
    return true;
931
932
  /* We must allocate the symbol in our .dynbss section, which will
933
     become part of the .bss section of the executable.  There will be
934
     an entry for this symbol in the .dynsym section.  The dynamic
935
     object will contain position independent code, so all references
936
     from the dynamic object to this symbol will go through the global
937
     offset table.  The dynamic linker will use the .dynsym entry to
938
     determine the address it must put in the global offset table, so
939
     both the dynamic object and the regular object will refer to the
940
     same memory location for the variable.  */
941
942
0
  s = bfd_get_linker_section (dynobj, ".dynbss");
943
0
  BFD_ASSERT (s != NULL);
944
945
  /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
946
     copy the initial value out of the dynamic object and into the
947
     runtime process image.  We need to remember the offset into the
948
     .rela.bss section we are going to use.  */
949
0
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
950
0
    {
951
0
      asection *srel;
952
953
0
      srel = bfd_get_linker_section (dynobj, ".rela.bss");
954
0
      BFD_ASSERT (srel != NULL);
955
0
      srel->size += sizeof (Elf32_External_Rela);
956
0
      h->needs_copy = 1;
957
0
    }
958
959
0
  return _bfd_elf_adjust_dynamic_copy (info, h, s);
960
0
}
961
962
/* This function is called via elf_link_hash_traverse.  It resets GOT
963
   and PLT (.GOT) reference counts back to -1 so normal PC32 relocation
964
   will be done.  */
965
966
static bool
967
elf_vax_discard_got_entries (struct elf_link_hash_entry *h,
968
           void *infoptr ATTRIBUTE_UNUSED)
969
0
{
970
0
  h->got.refcount = -1;
971
0
  h->plt.refcount = -1;
972
973
0
  return true;
974
0
}
975
976
/* Discard unused dynamic data if this is a static link.  */
977
978
static bool
979
elf_vax_early_size_sections (struct bfd_link_info *info)
980
0
{
981
0
  bfd *dynobj;
982
0
  asection *s;
983
984
0
  dynobj = elf_hash_table (info)->dynobj;
985
986
0
  if (dynobj && !elf_hash_table (info)->dynamic_sections_created)
987
0
    {
988
      /* We may have created entries in the .rela.got and .got sections.
989
   However, if we are not creating the dynamic sections, we will
990
   not actually use these entries.  Reset the size of .rela.got
991
   and .got, which will cause them to get stripped from the output
992
   file below.  */
993
0
      s = elf_hash_table (info)->srelgot;
994
0
      if (s != NULL)
995
0
  s->size = 0;
996
0
      s = elf_hash_table (info)->sgotplt;
997
0
      if (s != NULL)
998
0
  s->size = 0;
999
0
      s = elf_hash_table (info)->sgot;
1000
0
      if (s != NULL)
1001
0
  s->size = 0;
1002
0
    }
1003
1004
  /* If this is a static link, we need to discard all the got entries we've
1005
     recorded.  */
1006
0
  if (!dynobj || !elf_hash_table (info)->dynamic_sections_created)
1007
0
    elf_link_hash_traverse (elf_hash_table (info),
1008
0
          elf_vax_discard_got_entries,
1009
0
          info);
1010
1011
0
  return true;
1012
0
}
1013
1014
/* Set the sizes of the dynamic sections.  */
1015
1016
static bool
1017
elf_vax_late_size_sections (struct bfd_link_info *info)
1018
0
{
1019
0
  bfd *dynobj;
1020
0
  asection *s;
1021
0
  bool relocs;
1022
1023
0
  dynobj = elf_hash_table (info)->dynobj;
1024
0
  if (dynobj == NULL)
1025
0
    return true;
1026
1027
0
  if (elf_hash_table (info)->dynamic_sections_created)
1028
0
    {
1029
      /* Set the contents of the .interp section to the interpreter.  */
1030
0
      if (bfd_link_executable (info) && !info->nointerp)
1031
0
  {
1032
0
    s = elf_hash_table (info)->interp;
1033
0
    BFD_ASSERT (s != NULL);
1034
0
    s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1035
0
    s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1036
0
    s->alloced = 1;
1037
0
  }
1038
0
    }
1039
1040
  /* If this is a -Bsymbolic shared link, then we need to discard all PC
1041
     relative relocs against symbols defined in a regular object.  We
1042
     allocated space for them in the check_relocs routine, but we will not
1043
     fill them in in the relocate_section routine.  */
1044
0
  if (bfd_link_pic (info) && info->symbolic)
1045
0
    elf_vax_link_hash_traverse (elf_hash_table (info),
1046
0
        elf_vax_discard_copies,
1047
0
        NULL);
1048
1049
  /* If this is a -Bsymbolic shared link, we need to discard all the got
1050
     entries we've recorded.  Otherwise, we need to instantiate (allocate
1051
     space for them).  */
1052
0
  elf_link_hash_traverse (elf_hash_table (info),
1053
0
        elf_vax_instantiate_got_entries,
1054
0
        info);
1055
1056
  /* The check_relocs and adjust_dynamic_symbol entry points have
1057
     determined the sizes of the various dynamic sections.  Allocate
1058
     memory for them.  */
1059
0
  relocs = false;
1060
0
  for (s = dynobj->sections; s != NULL; s = s->next)
1061
0
    {
1062
0
      const char *name;
1063
1064
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
1065
0
  continue;
1066
1067
      /* It's OK to base decisions on the section name, because none
1068
   of the dynobj section names depend upon the input files.  */
1069
0
      name = bfd_section_name (s);
1070
1071
0
      if (strcmp (name, ".plt") == 0)
1072
0
  {
1073
    /* Remember whether there is a PLT.  */
1074
0
    ;
1075
0
  }
1076
0
      else if (startswith (name, ".rela"))
1077
0
  {
1078
0
    if (s->size != 0)
1079
0
      {
1080
0
        if (strcmp (name, ".rela.plt") != 0)
1081
0
    relocs = true;
1082
1083
        /* We use the reloc_count field as a counter if we need
1084
     to copy relocs into the output file.  */
1085
0
        s->reloc_count = 0;
1086
0
      }
1087
0
  }
1088
0
      else if (! startswith (name, ".got")
1089
0
         && strcmp (name, ".dynbss") != 0)
1090
0
  {
1091
    /* It's not one of our sections, so don't allocate space.  */
1092
0
    continue;
1093
0
  }
1094
1095
0
      if (s->size == 0)
1096
0
  {
1097
    /* If we don't need this section, strip it from the
1098
       output file.  This is mostly to handle .rela.bss and
1099
       .rela.plt.  We must create both sections in
1100
       create_dynamic_sections, because they must be created
1101
       before the linker maps input sections to output
1102
       sections.  The linker does that before
1103
       adjust_dynamic_symbol is called, and it is that
1104
       function which decides whether anything needs to go
1105
       into these sections.  */
1106
0
    s->flags |= SEC_EXCLUDE;
1107
0
    continue;
1108
0
  }
1109
1110
0
      if ((s->flags & SEC_HAS_CONTENTS) == 0)
1111
0
  continue;
1112
1113
      /* Allocate memory for the section contents.  */
1114
0
      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1115
0
      if (s->contents == NULL)
1116
0
  return false;
1117
0
      s->alloced = 1;
1118
0
    }
1119
1120
0
  return _bfd_elf_add_dynamic_tags (info, relocs);
1121
0
}
1122
1123
/* This function is called via elf_vax_link_hash_traverse if we are
1124
   creating a shared object with -Bsymbolic.  It discards the space
1125
   allocated to copy PC relative relocs against symbols which are defined
1126
   in regular objects.  We allocated space for them in the check_relocs
1127
   routine, but we won't fill them in in the relocate_section routine.  */
1128
1129
static bool
1130
elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
1131
      void * ignore ATTRIBUTE_UNUSED)
1132
0
{
1133
0
  struct elf_vax_pcrel_relocs_copied *s;
1134
1135
  /* We only discard relocs for symbols defined in a regular object.  */
1136
0
  if (!h->root.def_regular)
1137
0
    return true;
1138
1139
0
  for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1140
0
    s->section->size -= s->count * sizeof (Elf32_External_Rela);
1141
1142
0
  return true;
1143
0
}
1144
1145
/* This function is called via elf_link_hash_traverse.  It looks for
1146
   entries that have GOT or PLT (.GOT) references.  If creating a shared
1147
   object with -Bsymbolic, or the symbol has been forced local, then it
1148
   resets the reference count back to -1 so normal PC32 relocation will
1149
   be done.  Otherwise space in the .got and .rela.got will be reserved
1150
   for the symbol.  */
1151
1152
static bool
1153
elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, void * infoptr)
1154
0
{
1155
0
  struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
1156
0
  bfd *dynobj;
1157
0
  asection *sgot;
1158
0
  asection *srelgot;
1159
1160
  /* We don't care about non-GOT (and non-PLT) entries.  */
1161
0
  if (h->got.refcount <= 0 && h->plt.refcount <= 0)
1162
0
    return true;
1163
1164
0
  dynobj = elf_hash_table (info)->dynobj;
1165
0
  BFD_ASSERT (dynobj != NULL);
1166
1167
0
  sgot = elf_hash_table (info)->sgot;
1168
0
  srelgot = elf_hash_table (info)->srelgot;
1169
1170
0
  if (SYMBOL_REFERENCES_LOCAL (info, h))
1171
0
    {
1172
0
      h->got.refcount = -1;
1173
0
      h->plt.refcount = -1;
1174
0
    }
1175
0
  else if (h->got.refcount > 0)
1176
0
    {
1177
      /* Make sure this symbol is output as a dynamic symbol.  */
1178
0
      if (h->dynindx == -1)
1179
0
  {
1180
0
    if (!bfd_elf_link_record_dynamic_symbol (info, h))
1181
0
      return false;
1182
0
  }
1183
1184
      /* Allocate space in the .got and .rela.got sections.  */
1185
0
      sgot->size += 4;
1186
0
      srelgot->size += sizeof (Elf32_External_Rela);
1187
0
    }
1188
1189
0
  return true;
1190
0
}
1191
1192
/* Relocate an VAX ELF section.  */
1193
1194
static int
1195
elf_vax_relocate_section (struct bfd_link_info *info,
1196
        bfd *input_bfd,
1197
        asection *input_section,
1198
        bfd_byte *contents,
1199
        Elf_Internal_Rela *relocs,
1200
        Elf_Internal_Sym *local_syms,
1201
        asection **local_sections)
1202
0
{
1203
0
  Elf_Internal_Shdr *symtab_hdr;
1204
0
  struct elf_link_hash_entry **sym_hashes;
1205
0
  bfd_vma plt_index;
1206
0
  bfd_vma got_offset;
1207
0
  asection *sgot;
1208
0
  asection *splt;
1209
0
  asection *sgotplt;
1210
0
  asection *sreloc;
1211
0
  Elf_Internal_Rela *rel;
1212
0
  Elf_Internal_Rela *relend;
1213
1214
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
1215
0
  sym_hashes = elf_sym_hashes (input_bfd);
1216
1217
0
  sgot = NULL;
1218
0
  splt = NULL;
1219
0
  sgotplt = NULL;
1220
1221
0
  rel = relocs;
1222
0
  relend = relocs + input_section->reloc_count;
1223
0
  for (; rel < relend; rel++)
1224
0
    {
1225
0
      int r_type;
1226
0
      reloc_howto_type *howto;
1227
0
      unsigned long r_symndx;
1228
0
      struct elf_link_hash_entry *h;
1229
0
      Elf_Internal_Sym *sym;
1230
0
      asection *sec;
1231
0
      bfd_vma relocation;
1232
0
      bfd_reloc_status_type r;
1233
1234
0
      r_type = ELF32_R_TYPE (rel->r_info);
1235
0
      if (r_type < 0 || r_type >= (int) R_VAX_max)
1236
0
  {
1237
0
    bfd_set_error (bfd_error_bad_value);
1238
0
    return false;
1239
0
  }
1240
0
      howto = howto_table + r_type;
1241
1242
0
      r_symndx = ELF32_R_SYM (rel->r_info);
1243
0
      h = NULL;
1244
0
      sym = NULL;
1245
0
      sec = NULL;
1246
0
      if (r_symndx < symtab_hdr->sh_info)
1247
0
  {
1248
0
    sym = local_syms + r_symndx;
1249
0
    sec = local_sections[r_symndx];
1250
0
    relocation = _bfd_elf_rela_local_sym (info->output_bfd,
1251
0
            sym, &sec, rel);
1252
0
  }
1253
0
      else
1254
0
  {
1255
0
    bool unresolved_reloc;
1256
0
    bool warned, ignored;
1257
1258
0
    RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1259
0
           r_symndx, symtab_hdr, sym_hashes,
1260
0
           h, sec, relocation,
1261
0
           unresolved_reloc, warned, ignored);
1262
1263
0
    if ((h->root.type == bfd_link_hash_defined
1264
0
        || h->root.type == bfd_link_hash_defweak)
1265
0
        && ((r_type == R_VAX_PLT32
1266
0
       && h->plt.offset != (bfd_vma) -1
1267
0
       && !h->forced_local
1268
0
       && elf_hash_table (info)->dynamic_sections_created)
1269
0
      || (r_type == R_VAX_GOT32
1270
0
          && h->got.offset != (bfd_vma) -1
1271
0
          && !h->forced_local
1272
0
          && elf_hash_table (info)->dynamic_sections_created
1273
0
          && (! bfd_link_pic (info)
1274
0
        || (! info->symbolic && h->dynindx != -1)
1275
0
        || !h->def_regular))
1276
0
      || (bfd_link_pic (info)
1277
0
          && ((! info->symbolic && h->dynindx != -1)
1278
0
        || !h->def_regular)
1279
0
          && ((input_section->flags & SEC_ALLOC) != 0
1280
        /* DWARF will emit R_VAX_32 relocations in its
1281
           sections against symbols defined externally
1282
           in shared libraries.  We can't do anything
1283
           with them here.  */
1284
1285
0
        || ((input_section->flags & SEC_DEBUGGING) != 0
1286
0
            && h->def_dynamic))
1287
0
          && (r_type == R_VAX_8
1288
0
        || r_type == R_VAX_16
1289
0
        || r_type == R_VAX_32))))
1290
      /* In these cases, we don't need the relocation
1291
         value.  We check specially because in some
1292
         obscure cases sec->output_section will be NULL.  */
1293
0
      relocation = 0;
1294
0
  }
1295
1296
0
      if (sec != NULL && discarded_section (sec))
1297
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1298
0
           rel, 1, relend, R_VAX_NONE,
1299
0
           howto, 0, contents);
1300
1301
0
      if (bfd_link_relocatable (info))
1302
0
  continue;
1303
1304
0
      switch (r_type)
1305
0
  {
1306
0
  case R_VAX_GOT32:
1307
    /* Relocation is to the address of the entry for this symbol
1308
       in the global offset table.  */
1309
1310
    /* Resolve a GOTxx reloc against a local symbol directly,
1311
       without using the global offset table.  */
1312
0
    if (h == NULL
1313
0
        || h->got.offset == (bfd_vma) -1)
1314
0
      break;
1315
1316
0
    {
1317
0
      bfd_vma off;
1318
1319
0
      sgot = elf_hash_table (info)->sgot;
1320
0
      BFD_ASSERT (sgot != NULL);
1321
1322
0
      off = h->got.offset;
1323
0
      BFD_ASSERT (off < sgot->size);
1324
1325
0
      bfd_put_32 (info->output_bfd, rel->r_addend, sgot->contents + off);
1326
1327
0
      relocation = sgot->output_offset + off;
1328
      /* The GOT relocation uses the addend.  */
1329
0
      rel->r_addend = 0;
1330
1331
      /* Change the reference to be indirect.  */
1332
0
      contents[rel->r_offset - 1] |= 0x10;
1333
0
      relocation += sgot->output_section->vma;
1334
0
    }
1335
0
    break;
1336
1337
0
  case R_VAX_PC32:
1338
    /* If we are creating an executable and the function this
1339
       reloc refers to is in a shared lib, then we made a PLT
1340
       entry for this symbol and need to handle the reloc like
1341
       a PLT reloc.  */
1342
0
    if (bfd_link_pic (info))
1343
0
       goto r_vax_pc32_shared;
1344
    /* Fall through.  */
1345
0
  case R_VAX_PLT32:
1346
    /* Relocation is to the entry for this symbol in the
1347
       procedure linkage table.  */
1348
1349
    /* Resolve a PLTxx reloc against a local symbol directly,
1350
       without using the procedure linkage table.  */
1351
0
    if (h == NULL
1352
0
        || h->plt.offset == (bfd_vma) -1)
1353
0
      break;
1354
1355
0
    splt = elf_hash_table (info)->splt;
1356
0
    BFD_ASSERT (splt != NULL);
1357
1358
0
    sgotplt = elf_hash_table (info)->sgotplt;
1359
0
    BFD_ASSERT (sgotplt != NULL);
1360
1361
0
    plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1362
1363
    /* Get the offset into the .got table of the entry that
1364
       corresponds to this function.  Each .got entry is 4 bytes.
1365
       The first two are reserved.  */
1366
0
    got_offset = (plt_index + 3) * 4;
1367
1368
    /* We want the relocation to point into the .got.plt instead
1369
       of the plt itself.  */
1370
0
    relocation = (sgotplt->output_section->vma
1371
0
      + sgotplt->output_offset
1372
0
      + got_offset);
1373
0
    contents[rel->r_offset-1] |= 0x10; /* make indirect */
1374
0
    if (rel->r_addend == 2)
1375
0
      {
1376
0
        h->plt.offset |= 1;
1377
0
      }
1378
0
    else if (rel->r_addend != 0)
1379
0
      _bfd_error_handler
1380
        /* xgettext:c-format */
1381
0
        (_("%pB: warning: PLT addend of %" PRId64 " to `%s'"
1382
0
     " from %pA section ignored"),
1383
0
         input_bfd, (int64_t) rel->r_addend, h->root.root.string,
1384
0
         input_section);
1385
0
    rel->r_addend = 0;
1386
1387
0
    break;
1388
1389
0
  case R_VAX_PC8:
1390
0
  case R_VAX_PC16:
1391
0
  r_vax_pc32_shared:
1392
0
    if (h == NULL
1393
0
        || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1394
0
        || h->forced_local)
1395
0
      break;
1396
    /* Fall through.  */
1397
0
  case R_VAX_8:
1398
0
  case R_VAX_16:
1399
0
  case R_VAX_32:
1400
0
    if (bfd_link_pic (info)
1401
0
        && r_symndx != STN_UNDEF
1402
0
        && (input_section->flags & SEC_ALLOC) != 0
1403
0
        && ((r_type != R_VAX_PC8
1404
0
       && r_type != R_VAX_PC16
1405
0
       && r_type != R_VAX_PC32)
1406
0
      || ((input_section->flags & SEC_CODE)
1407
0
          && (!info->symbolic
1408
0
        || (!h->def_regular && h->type != STT_SECTION)))))
1409
0
      {
1410
0
        Elf_Internal_Rela outrel;
1411
0
        bfd_byte *loc;
1412
0
        bool skip, relocate;
1413
1414
        /* When generating a shared object, these relocations
1415
     are copied into the output file to be resolved at run
1416
     time.  */
1417
0
        sreloc = elf_section_data (input_section)->sreloc;
1418
0
        if (sreloc == NULL)
1419
0
    return false;
1420
1421
0
        skip = false;
1422
0
        relocate = false;
1423
1424
0
        outrel.r_offset =
1425
0
    _bfd_elf_section_offset (info->output_bfd, info,
1426
0
           input_section, rel->r_offset);
1427
0
        if (outrel.r_offset == (bfd_vma) -1)
1428
0
    skip = true;
1429
0
        if (outrel.r_offset == (bfd_vma) -2)
1430
0
    skip = true, relocate = true;
1431
0
        outrel.r_offset += (input_section->output_section->vma
1432
0
          + input_section->output_offset);
1433
1434
0
        if (skip)
1435
0
      memset (&outrel, 0, sizeof outrel);
1436
        /* h->dynindx may be -1 if the symbol was marked to
1437
     become local.  */
1438
0
        else if (h != NULL
1439
0
           && ((! info->symbolic && h->dynindx != -1)
1440
0
         || !h->def_regular))
1441
0
    {
1442
0
      BFD_ASSERT (h->dynindx != -1);
1443
0
      outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1444
0
      outrel.r_addend = relocation + rel->r_addend;
1445
0
    }
1446
0
        else
1447
0
    {
1448
0
      if (r_type == R_VAX_32)
1449
0
        {
1450
0
          relocate = true;
1451
0
          outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1452
0
          BFD_ASSERT (bfd_get_signed_32 (input_bfd,
1453
0
                 &contents[rel->r_offset]) == 0);
1454
0
          outrel.r_addend = relocation + rel->r_addend;
1455
0
        }
1456
0
      else
1457
0
        {
1458
0
          long indx;
1459
1460
0
          if (bfd_is_abs_section (sec))
1461
0
      indx = 0;
1462
0
          else if (sec == NULL || sec->owner == NULL)
1463
0
      {
1464
0
        bfd_set_error (bfd_error_bad_value);
1465
0
        return false;
1466
0
      }
1467
0
          else
1468
0
      {
1469
0
        asection *osec;
1470
1471
        /* We are turning this relocation into one
1472
           against a section symbol.  It would be
1473
           proper to subtract the symbol's value,
1474
           osec->vma, from the emitted reloc addend,
1475
           but ld.so expects buggy relocs.  */
1476
0
        osec = sec->output_section;
1477
0
        indx = elf_section_data (osec)->dynindx;
1478
0
        if (indx == 0)
1479
0
          {
1480
0
            struct elf_link_hash_table *htab;
1481
0
            htab = elf_hash_table (info);
1482
0
            osec = htab->text_index_section;
1483
0
            indx = elf_section_data (osec)->dynindx;
1484
0
          }
1485
0
        BFD_ASSERT (indx != 0);
1486
0
      }
1487
1488
0
          outrel.r_info = ELF32_R_INFO (indx, r_type);
1489
0
          outrel.r_addend = relocation + rel->r_addend;
1490
0
        }
1491
0
    }
1492
1493
0
        if ((input_section->flags & SEC_CODE) != 0
1494
0
      || (ELF32_R_TYPE (outrel.r_info) != R_VAX_32
1495
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_RELATIVE
1496
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_COPY
1497
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_JMP_SLOT
1498
0
          && ELF32_R_TYPE (outrel.r_info) != R_VAX_GLOB_DAT))
1499
0
    {
1500
0
      if (h != NULL)
1501
0
        _bfd_error_handler
1502
          /* xgettext:c-format */
1503
0
          (_("%pB: warning: %s relocation against symbol `%s'"
1504
0
       " from %pA section"),
1505
0
          input_bfd, howto->name, h->root.root.string,
1506
0
          input_section);
1507
0
      else
1508
0
        _bfd_error_handler
1509
          /* xgettext:c-format */
1510
0
          (_("%pB: warning: %s relocation to %#" PRIx64
1511
0
       " from %pA section"),
1512
0
          input_bfd, howto->name, (uint64_t) outrel.r_addend,
1513
0
          input_section);
1514
0
    }
1515
0
        loc = sreloc->contents;
1516
0
        loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1517
0
        bfd_elf32_swap_reloca_out (info->output_bfd, &outrel, loc);
1518
1519
        /* This reloc will be computed at runtime, so there's no
1520
     need to do anything now, except for R_VAX_32
1521
     relocations that have been turned into
1522
     R_VAX_RELATIVE.  */
1523
0
        if (!relocate)
1524
0
    continue;
1525
0
      }
1526
1527
0
    break;
1528
1529
0
  case R_VAX_GNU_VTINHERIT:
1530
0
  case R_VAX_GNU_VTENTRY:
1531
    /* These are no-ops in the end.  */
1532
0
    continue;
1533
1534
0
  default:
1535
0
    break;
1536
0
  }
1537
1538
      /* VAX PCREL relocations are from the end of relocation, not the start.
1539
   So subtract the difference from the relocation amount since we can't
1540
   add it to the offset.  */
1541
0
      if (howto->pc_relative && howto->pcrel_offset)
1542
0
  relocation -= bfd_get_reloc_size(howto);
1543
1544
0
      r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1545
0
            contents, rel->r_offset,
1546
0
            relocation, rel->r_addend);
1547
1548
0
      if (r != bfd_reloc_ok)
1549
0
  {
1550
0
    switch (r)
1551
0
      {
1552
0
      default:
1553
0
      case bfd_reloc_outofrange:
1554
0
        abort ();
1555
0
      case bfd_reloc_overflow:
1556
0
        {
1557
0
    const char *name;
1558
1559
0
    if (h != NULL)
1560
0
      name = NULL;
1561
0
    else
1562
0
      {
1563
0
        name = bfd_elf_string_from_elf_section (input_bfd,
1564
0
                  symtab_hdr->sh_link,
1565
0
                  sym->st_name);
1566
0
        if (name == NULL)
1567
0
          return false;
1568
0
        if (*name == '\0')
1569
0
          name = bfd_section_name (sec);
1570
0
      }
1571
0
    info->callbacks->reloc_overflow
1572
0
      (info, (h ? &h->root : NULL), name, howto->name,
1573
0
       (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1574
0
        }
1575
0
        break;
1576
0
      }
1577
0
  }
1578
0
    }
1579
1580
0
  return true;
1581
0
}
1582
1583
/* Finish up dynamic symbol handling.  We set the contents of various
1584
   dynamic sections here.  */
1585
1586
static bool
1587
elf_vax_finish_dynamic_symbol (struct bfd_link_info *info,
1588
             struct elf_link_hash_entry *h,
1589
             Elf_Internal_Sym *sym)
1590
0
{
1591
0
  bfd *dynobj;
1592
1593
0
  dynobj = elf_hash_table (info)->dynobj;
1594
1595
0
  if (h->plt.offset != (bfd_vma) -1)
1596
0
    {
1597
0
      asection *splt;
1598
0
      asection *sgot;
1599
0
      asection *srela;
1600
0
      bfd_vma plt_index;
1601
0
      bfd_vma got_offset;
1602
0
      bfd_vma addend;
1603
0
      Elf_Internal_Rela rela;
1604
0
      bfd_byte *loc;
1605
1606
      /* This symbol has an entry in the procedure linkage table.  Set
1607
   it up.  */
1608
0
      BFD_ASSERT (h->dynindx != -1);
1609
1610
0
      splt = elf_hash_table (info)->splt;
1611
0
      sgot = elf_hash_table (info)->sgotplt;
1612
0
      srela = elf_hash_table (info)->srelplt;
1613
0
      BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1614
1615
0
      addend = 2 * (h->plt.offset & 1);
1616
0
      h->plt.offset &= ~1;
1617
1618
      /* Get the index in the procedure linkage table which
1619
   corresponds to this symbol.  This is the index of this symbol
1620
   in all the symbols for which we are making plt entries.  The
1621
   first entry in the procedure linkage table is reserved.  */
1622
0
      plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1623
1624
      /* Get the offset into the .got table of the entry that
1625
   corresponds to this function.  Each .got entry is 4 bytes.
1626
   The first two are reserved.  */
1627
0
      got_offset = (plt_index + 3) * 4;
1628
1629
      /* Fill in the entry in the procedure linkage table.  */
1630
0
      memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
1631
0
      PLT_ENTRY_SIZE);
1632
1633
      /* The offset is relative to the first extension word.  */
1634
0
      bfd_put_32 (info->output_bfd,
1635
0
      -(h->plt.offset + 8),
1636
0
      splt->contents + h->plt.offset + 4);
1637
1638
0
      bfd_put_32 (info->output_bfd, plt_index * sizeof (Elf32_External_Rela),
1639
0
      splt->contents + h->plt.offset + 8);
1640
1641
      /* Fill in the entry in the global offset table.  */
1642
0
      bfd_put_32 (info->output_bfd,
1643
0
      (splt->output_section->vma
1644
0
       + splt->output_offset
1645
0
       + h->plt.offset) + addend,
1646
0
      sgot->contents + got_offset);
1647
1648
      /* Fill in the entry in the .rela.plt section.  */
1649
0
      rela.r_offset = (sgot->output_section->vma
1650
0
           + sgot->output_offset
1651
0
           + got_offset);
1652
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
1653
0
      rela.r_addend = addend;
1654
0
      loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
1655
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1656
1657
0
      if (!h->def_regular)
1658
0
  {
1659
    /* Mark the symbol as undefined, rather than as defined in
1660
       the .plt section.  Leave the value alone.  */
1661
0
    sym->st_shndx = SHN_UNDEF;
1662
0
  }
1663
0
    }
1664
1665
0
  if (h->got.offset != (bfd_vma) -1)
1666
0
    {
1667
0
      asection *sgot;
1668
0
      asection *srela;
1669
0
      Elf_Internal_Rela rela;
1670
0
      bfd_byte *loc;
1671
1672
      /* This symbol has an entry in the global offset table.  Set it
1673
   up.  */
1674
0
      sgot = elf_hash_table (info)->sgot;
1675
0
      srela = elf_hash_table (info)->srelgot;
1676
0
      BFD_ASSERT (sgot != NULL && srela != NULL);
1677
1678
0
      rela.r_offset = (sgot->output_section->vma
1679
0
           + sgot->output_offset
1680
0
           + h->got.offset);
1681
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
1682
0
      rela.r_addend = bfd_get_signed_32 (info->output_bfd,
1683
0
           sgot->contents + h->got.offset);
1684
1685
0
      loc = srela->contents;
1686
0
      loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
1687
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1688
0
    }
1689
1690
0
  if (h->needs_copy)
1691
0
    {
1692
0
      asection *s;
1693
0
      Elf_Internal_Rela rela;
1694
0
      bfd_byte *loc;
1695
1696
      /* This symbol needs a copy reloc.  Set it up.  */
1697
0
      BFD_ASSERT (h->dynindx != -1
1698
0
      && (h->root.type == bfd_link_hash_defined
1699
0
          || h->root.type == bfd_link_hash_defweak));
1700
1701
0
      s = bfd_get_linker_section (dynobj, ".rela.bss");
1702
0
      BFD_ASSERT (s != NULL);
1703
1704
0
      rela.r_offset = (h->root.u.def.value
1705
0
           + h->root.u.def.section->output_section->vma
1706
0
           + h->root.u.def.section->output_offset);
1707
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
1708
0
      rela.r_addend = 0;
1709
0
      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
1710
0
      bfd_elf32_swap_reloca_out (info->output_bfd, &rela, loc);
1711
0
    }
1712
1713
  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
1714
0
  if (h == elf_hash_table (info)->hdynamic
1715
0
      || h == elf_hash_table (info)->hgot)
1716
0
    sym->st_shndx = SHN_ABS;
1717
1718
0
  return true;
1719
0
}
1720
1721
/* Finish up the dynamic sections.  */
1722
1723
static bool
1724
elf_vax_finish_dynamic_sections (struct bfd_link_info *info,
1725
         bfd_byte *buf ATTRIBUTE_UNUSED)
1726
0
{
1727
0
  bfd *dynobj;
1728
0
  asection *sgot;
1729
0
  asection *sdyn;
1730
1731
0
  dynobj = elf_hash_table (info)->dynobj;
1732
0
  sgot = elf_hash_table (info)->sgotplt;
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 && sgot != 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 != NULL && 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
1806
0
      if (elf_section_data (sgot->output_section) != NULL)
1807
0
  elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1808
0
    }
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"