2005-06-02 H.J. Lu <hjl@gnu.org>
[binutils.git] / bfd / elf32-vax.c
blobaecc6bc6c89f084980f81acb9e68216543cdbc41
1 /* VAX series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Matt Thomas <matt@3am-software.com>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "bfdlink.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf/vax.h"
29 static reloc_howto_type *reloc_type_lookup
30 PARAMS ((bfd *, bfd_reloc_code_real_type));
31 static void rtype_to_howto
32 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
33 static struct bfd_hash_entry *elf_vax_link_hash_newfunc
34 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
35 static struct bfd_link_hash_table *elf_vax_link_hash_table_create
36 PARAMS ((bfd *));
37 static boolean elf_vax_check_relocs
38 PARAMS ((bfd *, struct bfd_link_info *, asection *,
39 const Elf_Internal_Rela *));
40 static asection *elf_vax_gc_mark_hook
41 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
42 struct elf_link_hash_entry *, Elf_Internal_Sym *));
43 static boolean elf_vax_gc_sweep_hook
44 PARAMS ((bfd *, struct bfd_link_info *, asection *,
45 const Elf_Internal_Rela *));
46 static boolean elf_vax_adjust_dynamic_symbol
47 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
48 static boolean elf_vax_size_dynamic_sections
49 PARAMS ((bfd *, struct bfd_link_info *));
50 static boolean elf_vax_relocate_section
51 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
52 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
53 static boolean elf_vax_finish_dynamic_symbol
54 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
55 Elf_Internal_Sym *));
56 static boolean elf_vax_finish_dynamic_sections
57 PARAMS ((bfd *, struct bfd_link_info *));
59 static boolean elf32_vax_set_private_flags
60 PARAMS ((bfd *, flagword));
61 static boolean elf32_vax_merge_private_bfd_data
62 PARAMS ((bfd *, bfd *));
63 static boolean elf32_vax_print_private_bfd_data
64 PARAMS ((bfd *, PTR));
66 static reloc_howto_type howto_table[] = {
67 HOWTO (R_VAX_NONE, /* type */
68 0, /* rightshift */
69 0, /* size (0 = byte, 1 = short, 2 = long) */
70 0, /* bitsize */
71 false, /* pc_relative */
72 0, /* bitpos */
73 complain_overflow_dont, /* complain_on_overflow */
74 bfd_elf_generic_reloc, /* special_function */
75 "R_VAX_NONE", /* name */
76 false, /* partial_inplace */
77 0, /* src_mask */
78 0x00000000, /* dst_mask */
79 false), /* pcrel_offset */
81 HOWTO (R_VAX_32, /* type */
82 0, /* rightshift */
83 2, /* size (0 = byte, 1 = short, 2 = long) */
84 32, /* bitsize */
85 false, /* pc_relative */
86 0, /* bitpos */
87 complain_overflow_bitfield, /* complain_on_overflow */
88 bfd_elf_generic_reloc, /* special_function */
89 "R_VAX_32", /* name */
90 false, /* partial_inplace */
91 0, /* src_mask */
92 0xffffffff, /* dst_mask */
93 false), /* pcrel_offset */
95 HOWTO (R_VAX_16, /* type */
96 0, /* rightshift */
97 1, /* size (0 = byte, 1 = short, 2 = long) */
98 16, /* bitsize */
99 false, /* pc_relative */
100 0, /* bitpos */
101 complain_overflow_bitfield, /* complain_on_overflow */
102 bfd_elf_generic_reloc, /* special_function */
103 "R_VAX_16", /* name */
104 false, /* partial_inplace */
105 0, /* src_mask */
106 0x0000ffff, /* dst_mask */
107 false), /* pcrel_offset */
109 HOWTO (R_VAX_8, /* type */
110 0, /* rightshift */
111 0, /* size (0 = byte, 1 = short, 2 = long) */
112 8, /* bitsize */
113 false, /* pc_relative */
114 0, /* bitpos */
115 complain_overflow_bitfield, /* complain_on_overflow */
116 bfd_elf_generic_reloc, /* special_function */
117 "R_VAX_8", /* name */
118 false, /* partial_inplace */
119 0, /* src_mask */
120 0x000000ff, /* dst_mask */
121 false), /* pcrel_offset */
123 HOWTO (R_VAX_PC32, /* type */
124 0, /* rightshift */
125 2, /* size (0 = byte, 1 = short, 2 = long) */
126 32, /* bitsize */
127 true, /* pc_relative */
128 0, /* bitpos */
129 complain_overflow_bitfield, /* complain_on_overflow */
130 bfd_elf_generic_reloc, /* special_function */
131 "R_VAX_PC32", /* name */
132 false, /* partial_inplace */
133 0, /* src_mask */
134 0xffffffff, /* dst_mask */
135 true), /* pcrel_offset */
137 HOWTO (R_VAX_PC16, /* type */
138 0, /* rightshift */
139 1, /* size (0 = byte, 1 = short, 2 = long) */
140 16, /* bitsize */
141 true, /* pc_relative */
142 0, /* bitpos */
143 complain_overflow_signed, /* complain_on_overflow */
144 bfd_elf_generic_reloc, /* special_function */
145 "R_VAX_PC16", /* name */
146 false, /* partial_inplace */
147 0, /* src_mask */
148 0x0000ffff, /* dst_mask */
149 true), /* pcrel_offset */
151 HOWTO (R_VAX_PC8, /* type */
152 0, /* rightshift */
153 0, /* size (0 = byte, 1 = short, 2 = long) */
154 8, /* bitsize */
155 true, /* pc_relative */
156 0, /* bitpos */
157 complain_overflow_signed, /* complain_on_overflow */
158 bfd_elf_generic_reloc, /* special_function */
159 "R_VAX_PC8", /* name */
160 false, /* partial_inplace */
161 0, /* src_mask */
162 0x000000ff, /* dst_mask */
163 true), /* pcrel_offset */
165 HOWTO (R_VAX_GOT32, /* type */
166 0, /* rightshift */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
168 32, /* bitsize */
169 true, /* pc_relative */
170 0, /* bitpos */
171 complain_overflow_bitfield, /* complain_on_overflow */
172 bfd_elf_generic_reloc, /* special_function */
173 "R_VAX_GOT32", /* name */
174 false, /* partial_inplace */
175 0, /* src_mask */
176 0xffffffff, /* dst_mask */
177 true), /* pcrel_offset */
179 EMPTY_HOWTO (-1),
180 EMPTY_HOWTO (-1),
181 EMPTY_HOWTO (-1),
182 EMPTY_HOWTO (-1),
183 EMPTY_HOWTO (-1),
185 HOWTO (R_VAX_PLT32, /* type */
186 0, /* rightshift */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
188 32, /* bitsize */
189 true, /* pc_relative */
190 0, /* bitpos */
191 complain_overflow_bitfield, /* complain_on_overflow */
192 bfd_elf_generic_reloc, /* special_function */
193 "R_VAX_PLT32", /* name */
194 false, /* partial_inplace */
195 0, /* src_mask */
196 0xffffffff, /* dst_mask */
197 true), /* pcrel_offset */
199 EMPTY_HOWTO (-1),
200 EMPTY_HOWTO (-1),
201 EMPTY_HOWTO (-1),
202 EMPTY_HOWTO (-1),
203 EMPTY_HOWTO (-1),
205 HOWTO (R_VAX_COPY, /* type */
206 0, /* rightshift */
207 0, /* size (0 = byte, 1 = short, 2 = long) */
208 0, /* bitsize */
209 false, /* pc_relative */
210 0, /* bitpos */
211 complain_overflow_dont, /* complain_on_overflow */
212 bfd_elf_generic_reloc, /* special_function */
213 "R_VAX_COPY", /* name */
214 false, /* partial_inplace */
215 0, /* src_mask */
216 0xffffffff, /* dst_mask */
217 false), /* pcrel_offset */
219 HOWTO (R_VAX_GLOB_DAT, /* type */
220 0, /* rightshift */
221 2, /* size (0 = byte, 1 = short, 2 = long) */
222 32, /* bitsize */
223 false, /* pc_relative */
224 0, /* bitpos */
225 complain_overflow_dont, /* complain_on_overflow */
226 bfd_elf_generic_reloc, /* special_function */
227 "R_VAX_GLOB_DAT", /* name */
228 false, /* partial_inplace */
229 0, /* src_mask */
230 0xffffffff, /* dst_mask */
231 false), /* pcrel_offset */
233 HOWTO (R_VAX_JMP_SLOT, /* type */
234 0, /* rightshift */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
236 32, /* bitsize */
237 false, /* pc_relative */
238 0, /* bitpos */
239 complain_overflow_dont, /* complain_on_overflow */
240 bfd_elf_generic_reloc, /* special_function */
241 "R_VAX_JMP_SLOT", /* name */
242 false, /* partial_inplace */
243 0, /* src_mask */
244 0xffffffff, /* dst_mask */
245 false), /* pcrel_offset */
247 HOWTO (R_VAX_RELATIVE, /* type */
248 0, /* rightshift */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
250 32, /* bitsize */
251 false, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_dont, /* complain_on_overflow */
254 bfd_elf_generic_reloc, /* special_function */
255 "R_VAX_RELATIVE", /* name */
256 false, /* partial_inplace */
257 0, /* src_mask */
258 0xffffffff, /* dst_mask */
259 false), /* pcrel_offset */
261 /* GNU extension to record C++ vtable hierarchy */
262 HOWTO (R_VAX_GNU_VTINHERIT, /* type */
263 0, /* rightshift */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
265 0, /* bitsize */
266 false, /* pc_relative */
267 0, /* bitpos */
268 complain_overflow_dont, /* complain_on_overflow */
269 NULL, /* special_function */
270 "R_VAX_GNU_VTINHERIT", /* name */
271 false, /* partial_inplace */
272 0, /* src_mask */
273 0, /* dst_mask */
274 false), /* pcrel_offset */
276 /* GNU extension to record C++ vtable member usage */
277 HOWTO (R_VAX_GNU_VTENTRY, /* type */
278 0, /* rightshift */
279 2, /* size (0 = byte, 1 = short, 2 = long) */
280 0, /* bitsize */
281 false, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_dont, /* complain_on_overflow */
284 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
285 "R_VAX_GNU_VTENTRY", /* name */
286 false, /* partial_inplace */
287 0, /* src_mask */
288 0, /* dst_mask */
289 false), /* pcrel_offset */
292 static void
293 rtype_to_howto (abfd, cache_ptr, dst)
294 bfd *abfd ATTRIBUTE_UNUSED;
295 arelent *cache_ptr;
296 Elf_Internal_Rela *dst;
298 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_VAX_max);
299 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
302 #define elf_info_to_howto rtype_to_howto
304 static const struct
306 bfd_reloc_code_real_type bfd_val;
307 int elf_val;
308 } reloc_map[] = {
309 { BFD_RELOC_NONE, R_VAX_NONE },
310 { BFD_RELOC_32, R_VAX_32 },
311 { BFD_RELOC_16, R_VAX_16 },
312 { BFD_RELOC_8, R_VAX_8 },
313 { BFD_RELOC_32_PCREL, R_VAX_PC32 },
314 { BFD_RELOC_16_PCREL, R_VAX_PC16 },
315 { BFD_RELOC_8_PCREL, R_VAX_PC8 },
316 { BFD_RELOC_32_GOT_PCREL, R_VAX_GOT32 },
317 { BFD_RELOC_32_PLT_PCREL, R_VAX_PLT32 },
318 { BFD_RELOC_NONE, R_VAX_COPY },
319 { BFD_RELOC_VAX_GLOB_DAT, R_VAX_GLOB_DAT },
320 { BFD_RELOC_VAX_JMP_SLOT, R_VAX_JMP_SLOT },
321 { BFD_RELOC_VAX_RELATIVE, R_VAX_RELATIVE },
322 { BFD_RELOC_CTOR, R_VAX_32 },
323 { BFD_RELOC_VTABLE_INHERIT, R_VAX_GNU_VTINHERIT },
324 { BFD_RELOC_VTABLE_ENTRY, R_VAX_GNU_VTENTRY },
327 static reloc_howto_type *
328 reloc_type_lookup (abfd, code)
329 bfd *abfd ATTRIBUTE_UNUSED;
330 bfd_reloc_code_real_type code;
332 unsigned int i;
333 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
335 if (reloc_map[i].bfd_val == code)
336 return &howto_table[reloc_map[i].elf_val];
338 return 0;
341 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
342 #define ELF_ARCH bfd_arch_vax
343 /* end code generated by elf.el */
345 #define USE_RELA
347 /* Functions for the VAX ELF linker. */
349 /* The name of the dynamic interpreter. This is put in the .interp
350 section. */
352 #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
354 /* The size in bytes of an entry in the procedure linkage table. */
356 #define PLT_ENTRY_SIZE 12
358 /* The first entry in a procedure linkage table looks like this. See
359 the SVR4 ABI VAX supplement to see how this works. */
361 static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
363 0xdd, 0xef, /* pushl l^ */
364 0, 0, 0, 0, /* offset to .plt.got + 4 */
365 0x17, 0xff, /* jmp @L^(pc) */
366 0, 0, 0, 0, /* offset to .plt.got + 8 */
369 /* Subsequent entries in a procedure linkage table look like this. */
371 static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
373 0x40, 0x00, /* .word ^M<r6> */
374 0x16, 0xef, /* jsb L^(pc) */
375 0, 0, 0, 0, /* replaced with offset to start of .plt */
376 0, 0, 0, 0, /* index into .rela.plt */
379 /* The VAX linker needs to keep track of the number of relocs that it
380 decides to copy in check_relocs for each symbol. This is so that it
381 can discard PC relative relocs if it doesn't need them when linking
382 with -Bsymbolic. We store the information in a field extending the
383 regular ELF linker hash table. */
385 /* This structure keeps track of the number of PC relative relocs we have
386 copied for a given symbol. */
388 struct elf_vax_pcrel_relocs_copied
390 /* Next section. */
391 struct elf_vax_pcrel_relocs_copied *next;
392 /* A section in dynobj. */
393 asection *section;
394 /* Number of relocs copied in this section. */
395 bfd_size_type count;
398 /* VAX ELF linker hash entry. */
400 struct elf_vax_link_hash_entry
402 struct elf_link_hash_entry root;
404 /* Number of PC relative relocs copied for this symbol. */
405 struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
407 bfd_vma got_addend;
410 /* VAX ELF linker hash table. */
412 struct elf_vax_link_hash_table
414 struct elf_link_hash_table root;
417 /* Declare this now that the above structures are defined. */
419 static boolean elf_vax_discard_copies
420 PARAMS ((struct elf_vax_link_hash_entry *, PTR));
422 /* Traverse an VAX ELF linker hash table. */
424 #define elf_vax_link_hash_traverse(table, func, info) \
425 (elf_link_hash_traverse \
426 (&(table)->root, \
427 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
428 (info)))
430 /* Get the VAX ELF linker hash table from a link_info structure. */
432 #define elf_vax_hash_table(p) \
433 ((struct elf_vax_link_hash_table *) (p)->hash)
435 /* Create an entry in an VAX ELF linker hash table. */
437 static struct bfd_hash_entry *
438 elf_vax_link_hash_newfunc (entry, table, string)
439 struct bfd_hash_entry *entry;
440 struct bfd_hash_table *table;
441 const char *string;
443 struct elf_vax_link_hash_entry *ret =
444 (struct elf_vax_link_hash_entry *) entry;
446 /* Allocate the structure if it has not already been allocated by a
447 subclass. */
448 if (ret == (struct elf_vax_link_hash_entry *) NULL)
449 ret = ((struct elf_vax_link_hash_entry *)
450 bfd_hash_allocate (table,
451 sizeof (struct elf_vax_link_hash_entry)));
452 if (ret == (struct elf_vax_link_hash_entry *) NULL)
453 return (struct bfd_hash_entry *) ret;
455 /* Call the allocation method of the superclass. */
456 ret = ((struct elf_vax_link_hash_entry *)
457 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
458 table, string));
459 if (ret != (struct elf_vax_link_hash_entry *) NULL)
461 ret->pcrel_relocs_copied = NULL;
464 return (struct bfd_hash_entry *) ret;
467 /* Create an VAX ELF linker hash table. */
469 static struct bfd_link_hash_table *
470 elf_vax_link_hash_table_create (abfd)
471 bfd *abfd;
473 struct elf_vax_link_hash_table *ret;
474 bfd_size_type amt = sizeof (struct elf_vax_link_hash_table);
476 ret = (struct elf_vax_link_hash_table *) bfd_malloc (amt);
477 if (ret == (struct elf_vax_link_hash_table *) NULL)
478 return NULL;
480 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
481 elf_vax_link_hash_newfunc))
483 free (ret);
484 return NULL;
487 return &ret->root.root;
490 /* Keep vax-specific flags in the ELF header */
491 static boolean
492 elf32_vax_set_private_flags (abfd, flags)
493 bfd *abfd;
494 flagword flags;
496 elf_elfheader (abfd)->e_flags = flags;
497 elf_flags_init (abfd) = true;
498 return true;
501 /* Merge backend specific data from an object file to the output
502 object file when linking. */
503 static boolean
504 elf32_vax_merge_private_bfd_data (ibfd, obfd)
505 bfd *ibfd;
506 bfd *obfd;
508 flagword out_flags;
509 flagword in_flags;
511 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
512 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
513 return true;
515 in_flags = elf_elfheader (ibfd)->e_flags;
516 out_flags = elf_elfheader (obfd)->e_flags;
518 if (!elf_flags_init (obfd))
520 elf_flags_init (obfd) = true;
521 elf_elfheader (obfd)->e_flags = in_flags;
524 return true;
527 /* Display the flags field */
528 static boolean
529 elf32_vax_print_private_bfd_data (abfd, ptr)
530 bfd *abfd;
531 PTR ptr;
533 FILE *file = (FILE *) ptr;
535 BFD_ASSERT (abfd != NULL && ptr != NULL);
537 /* Print normal ELF private data. */
538 _bfd_elf_print_private_bfd_data (abfd, ptr);
540 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
542 /* xgettext:c-format */
543 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
545 if (elf_elfheader (abfd)->e_flags & EF_NONPIC)
546 fprintf (file, _(" [nonpic]"));
548 if (elf_elfheader (abfd)->e_flags & EF_DFLOAT)
549 fprintf (file, _(" [d-float]"));
551 if (elf_elfheader (abfd)->e_flags & EF_GFLOAT)
552 fprintf (file, _(" [g-float]"));
554 fputc ('\n', file);
556 return true;
558 /* Look through the relocs for a section during the first phase, and
559 allocate space in the global offset table or procedure linkage
560 table. */
562 static boolean
563 elf_vax_check_relocs (abfd, info, sec, relocs)
564 bfd *abfd;
565 struct bfd_link_info *info;
566 asection *sec;
567 const Elf_Internal_Rela *relocs;
569 bfd *dynobj;
570 Elf_Internal_Shdr *symtab_hdr;
571 struct elf_link_hash_entry **sym_hashes;
572 bfd_signed_vma *local_got_refcounts;
573 const Elf_Internal_Rela *rel;
574 const Elf_Internal_Rela *rel_end;
575 asection *sgot;
576 asection *srelgot;
577 asection *sreloc;
579 if (info->relocateable)
580 return true;
582 dynobj = elf_hash_table (info)->dynobj;
583 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
584 sym_hashes = elf_sym_hashes (abfd);
585 local_got_refcounts = elf_local_got_refcounts (abfd);
587 sgot = NULL;
588 srelgot = NULL;
589 sreloc = NULL;
591 rel_end = relocs + sec->reloc_count;
592 for (rel = relocs; rel < rel_end; rel++)
594 unsigned long r_symndx;
595 struct elf_link_hash_entry *h;
597 r_symndx = ELF32_R_SYM (rel->r_info);
599 if (r_symndx < symtab_hdr->sh_info)
600 h = NULL;
601 else
602 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
604 switch (ELF32_R_TYPE (rel->r_info))
606 case R_VAX_GOT32:
607 if (h != NULL
608 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
609 break;
611 /* This symbol requires a global offset table entry. */
613 if (dynobj == NULL)
615 /* Create the .got section. */
616 elf_hash_table (info)->dynobj = dynobj = abfd;
617 if (!_bfd_elf_create_got_section (dynobj, info))
618 return false;
621 if (sgot == NULL)
623 sgot = bfd_get_section_by_name (dynobj, ".got");
624 BFD_ASSERT (sgot != NULL);
627 if (srelgot == NULL
628 && (h != NULL || info->shared))
630 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
631 if (srelgot == NULL)
633 srelgot = bfd_make_section (dynobj, ".rela.got");
634 if (srelgot == NULL
635 || !bfd_set_section_flags (dynobj, srelgot,
636 (SEC_ALLOC
637 | SEC_LOAD
638 | SEC_HAS_CONTENTS
639 | SEC_IN_MEMORY
640 | SEC_LINKER_CREATED
641 | SEC_READONLY))
642 || !bfd_set_section_alignment (dynobj, srelgot, 2))
643 return false;
647 if (h != NULL)
649 struct elf_vax_link_hash_entry *eh;
651 eh = (struct elf_vax_link_hash_entry *) h;
652 if (h->got.refcount == -1)
654 h->got.refcount = 1;
655 eh->got_addend = rel->r_addend;
657 /* Make sure this symbol is output as a dynamic symbol. */
658 if (h->dynindx == -1)
660 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
661 return false;
664 /* Allocate space in the .got section. */
665 sgot->_raw_size += 4;
666 /* Allocate relocation space. */
667 srelgot->_raw_size += sizeof (Elf32_External_Rela);
669 else
671 h->got.refcount++;
672 if (eh->got_addend != (bfd_vma) rel->r_addend)
673 (*_bfd_error_handler)
674 (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
675 bfd_get_filename (abfd), rel->r_addend,
676 h->root.root.string,
677 eh->got_addend);
681 break;
683 case R_VAX_PLT32:
684 /* This symbol requires a procedure linkage table entry. We
685 actually build the entry in adjust_dynamic_symbol,
686 because this might be a case of linking PIC code which is
687 never referenced by a dynamic object, in which case we
688 don't need to generate a procedure linkage table entry
689 after all. */
691 /* If this is a local symbol, we resolve it directly without
692 creating a procedure linkage table entry. */
693 if (h == NULL)
694 continue;
696 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
697 if (h->plt.refcount == -1)
698 h->plt.refcount = 1;
699 else
700 h->plt.refcount++;
701 break;
703 case R_VAX_PC8:
704 case R_VAX_PC16:
705 case R_VAX_PC32:
706 /* If we are creating a shared library and this is not a local
707 symbol, we need to copy the reloc into the shared library.
708 However when linking with -Bsymbolic and this is a global
709 symbol which is defined in an object we are including in the
710 link (i.e., DEF_REGULAR is set), then we can resolve the
711 reloc directly. At this point we have not seen all the input
712 files, so it is possible that DEF_REGULAR is not set now but
713 will be set later (it is never cleared). We account for that
714 possibility below by storing information in the
715 pcrel_relocs_copied field of the hash table entry. */
716 if (!(info->shared
717 && (sec->flags & SEC_ALLOC) != 0
718 && h != NULL
719 && (!info->symbolic
720 || (h->elf_link_hash_flags
721 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
723 if (h != NULL)
725 /* Make sure a plt entry is created for this symbol if
726 it turns out to be a function defined by a dynamic
727 object. */
728 if (h->plt.refcount == -1)
729 h->plt.refcount = 1;
730 else
731 h->plt.refcount++;
733 break;
735 /* Fall through. */
736 case R_VAX_8:
737 case R_VAX_16:
738 case R_VAX_32:
739 if (h != NULL)
741 /* Make sure a plt entry is created for this symbol if it
742 turns out to be a function defined by a dynamic object. */
743 if (h->plt.refcount == -1)
744 h->plt.refcount = 1;
745 else
746 h->plt.refcount++;
749 /* If we are creating a shared library, we need to copy the
750 reloc into the shared library. */
751 if (info->shared
752 && (sec->flags & SEC_ALLOC) != 0)
754 /* When creating a shared object, we must copy these
755 reloc types into the output file. We create a reloc
756 section in dynobj and make room for this reloc. */
757 if (sreloc == NULL)
759 const char *name;
761 name = (bfd_elf_string_from_elf_section
762 (abfd,
763 elf_elfheader (abfd)->e_shstrndx,
764 elf_section_data (sec)->rel_hdr.sh_name));
765 if (name == NULL)
766 return false;
768 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
769 && strcmp (bfd_get_section_name (abfd, sec),
770 name + 5) == 0);
772 sreloc = bfd_get_section_by_name (dynobj, name);
773 if (sreloc == NULL)
775 sreloc = bfd_make_section (dynobj, name);
776 if (sreloc == NULL
777 || !bfd_set_section_flags (dynobj, sreloc,
778 (SEC_ALLOC
779 | SEC_LOAD
780 | SEC_HAS_CONTENTS
781 | SEC_IN_MEMORY
782 | SEC_LINKER_CREATED
783 | SEC_READONLY))
784 || !bfd_set_section_alignment (dynobj, sreloc, 2))
785 return false;
787 if (sec->flags & SEC_READONLY)
788 info->flags |= DF_TEXTREL;
791 sreloc->_raw_size += sizeof (Elf32_External_Rela);
793 /* If we are linking with -Bsymbolic, we count the number of
794 PC relative relocations we have entered for this symbol,
795 so that we can discard them again if the symbol is later
796 defined by a regular object. Note that this function is
797 only called if we are using an vaxelf linker hash table,
798 which means that h is really a pointer to an
799 elf_vax_link_hash_entry. */
800 if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
801 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
802 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
803 && info->symbolic)
805 struct elf_vax_link_hash_entry *eh;
806 struct elf_vax_pcrel_relocs_copied *p;
808 eh = (struct elf_vax_link_hash_entry *) h;
810 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
811 if (p->section == sreloc)
812 break;
814 if (p == NULL)
816 p = ((struct elf_vax_pcrel_relocs_copied *)
817 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
818 if (p == NULL)
819 return false;
820 p->next = eh->pcrel_relocs_copied;
821 eh->pcrel_relocs_copied = p;
822 p->section = sreloc;
823 p->count = 0;
826 ++p->count;
830 break;
832 /* This relocation describes the C++ object vtable hierarchy.
833 Reconstruct it for later use during GC. */
834 case R_VAX_GNU_VTINHERIT:
835 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
836 return false;
837 break;
839 /* This relocation describes which C++ vtable entries are actually
840 used. Record for later use during GC. */
841 case R_VAX_GNU_VTENTRY:
842 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
843 return false;
844 break;
846 default:
847 break;
851 return true;
854 /* Return the section that should be marked against GC for a given
855 relocation. */
857 static asection *
858 elf_vax_gc_mark_hook (abfd, info, rel, h, sym)
859 bfd *abfd;
860 struct bfd_link_info *info ATTRIBUTE_UNUSED;
861 Elf_Internal_Rela *rel;
862 struct elf_link_hash_entry *h;
863 Elf_Internal_Sym *sym;
865 if (h != NULL)
867 switch (ELF32_R_TYPE (rel->r_info))
869 case R_VAX_GNU_VTINHERIT:
870 case R_VAX_GNU_VTENTRY:
871 break;
873 default:
874 switch (h->root.type)
876 default:
877 break;
879 case bfd_link_hash_defined:
880 case bfd_link_hash_defweak:
881 return h->root.u.def.section;
883 case bfd_link_hash_common:
884 return h->root.u.c.p->section;
888 else
890 if (!(elf_bad_symtab (abfd)
891 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
892 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
893 && sym->st_shndx != SHN_COMMON))
895 return bfd_section_from_elf_index (abfd, sym->st_shndx);
899 return NULL;
902 /* Update the got entry reference counts for the section being removed. */
904 static boolean
905 elf_vax_gc_sweep_hook (abfd, info, sec, relocs)
906 bfd *abfd;
907 struct bfd_link_info *info;
908 asection *sec;
909 const Elf_Internal_Rela *relocs;
911 Elf_Internal_Shdr *symtab_hdr;
912 struct elf_link_hash_entry **sym_hashes;
913 bfd_signed_vma *local_got_refcounts;
914 const Elf_Internal_Rela *rel, *relend;
915 unsigned long r_symndx;
916 struct elf_link_hash_entry *h;
917 bfd *dynobj;
918 asection *sgot;
919 asection *srelgot;
921 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
922 sym_hashes = elf_sym_hashes (abfd);
923 local_got_refcounts = elf_local_got_refcounts (abfd);
925 dynobj = elf_hash_table (info)->dynobj;
926 if (dynobj == NULL)
927 return true;
929 sgot = bfd_get_section_by_name (dynobj, ".got");
930 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
932 relend = relocs + sec->reloc_count;
933 for (rel = relocs; rel < relend; rel++)
935 switch (ELF32_R_TYPE (rel->r_info))
937 case R_VAX_GOT32:
938 r_symndx = ELF32_R_SYM (rel->r_info);
939 if (r_symndx >= symtab_hdr->sh_info)
941 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
942 if (h->got.refcount > 0)
944 --h->got.refcount;
945 if (h->got.refcount == 0)
947 /* We don't need the .got entry any more. */
948 sgot->_raw_size -= 4;
949 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
953 else if (local_got_refcounts != NULL)
955 if (local_got_refcounts[r_symndx] > 0)
957 --local_got_refcounts[r_symndx];
958 if (local_got_refcounts[r_symndx] == 0)
960 /* We don't need the .got entry any more. */
961 sgot->_raw_size -= 4;
962 if (info->shared)
963 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
967 break;
969 case R_VAX_PLT32:
970 case R_VAX_PC8:
971 case R_VAX_PC16:
972 case R_VAX_PC32:
973 case R_VAX_8:
974 case R_VAX_16:
975 case R_VAX_32:
976 r_symndx = ELF32_R_SYM (rel->r_info);
977 if (r_symndx >= symtab_hdr->sh_info)
979 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
980 if (h->plt.refcount > 0)
981 --h->plt.refcount;
983 break;
985 default:
986 break;
990 return true;
993 /* Adjust a symbol defined by a dynamic object and referenced by a
994 regular object. The current definition is in some section of the
995 dynamic object, but we're not including those sections. We have to
996 change the definition to something the rest of the link can
997 understand. */
999 static boolean
1000 elf_vax_adjust_dynamic_symbol (info, h)
1001 struct bfd_link_info *info;
1002 struct elf_link_hash_entry *h;
1004 bfd *dynobj;
1005 asection *s;
1006 unsigned int power_of_two;
1008 dynobj = elf_hash_table (info)->dynobj;
1010 /* Make sure we know what is going on here. */
1011 BFD_ASSERT (dynobj != NULL
1012 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
1013 || h->weakdef != NULL
1014 || ((h->elf_link_hash_flags
1015 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1016 && (h->elf_link_hash_flags
1017 & ELF_LINK_HASH_REF_REGULAR) != 0
1018 && (h->elf_link_hash_flags
1019 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
1021 /* If this is a function, put it in the procedure linkage table. We
1022 will fill in the contents of the procedure linkage table later,
1023 when we know the address of the .got section. */
1024 if (h->type == STT_FUNC
1025 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1027 if (! info->shared
1028 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1029 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
1030 /* We must always create the plt entry if it was referenced
1031 by a PLTxxO relocation. In this case we already recorded
1032 it as a dynamic symbol. */
1033 && h->dynindx == -1)
1035 /* This case can occur if we saw a PLTxx reloc in an input
1036 file, but the symbol was never referred to by a dynamic
1037 object. In such a case, we don't actually need to build
1038 a procedure linkage table, and we can just do a PCxx
1039 reloc instead. */
1040 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
1041 h->plt.offset = (bfd_vma) -1;
1042 return true;
1045 /* GC may have rendered this entry unused. */
1046 if (h->plt.refcount <= 0)
1048 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1049 h->plt.offset = (bfd_vma) -1;
1050 return true;
1053 /* Make sure this symbol is output as a dynamic symbol. */
1054 if (h->dynindx == -1)
1056 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1057 return false;
1060 s = bfd_get_section_by_name (dynobj, ".plt");
1061 BFD_ASSERT (s != NULL);
1063 /* If this is the first .plt entry, make room for the special
1064 first entry. */
1065 if (s->_raw_size == 0)
1067 s->_raw_size += PLT_ENTRY_SIZE;
1070 /* If this symbol is not defined in a regular file, and we are
1071 not generating a shared library, then set the symbol to this
1072 location in the .plt. This is required to make function
1073 pointers compare as equal between the normal executable and
1074 the shared library. */
1075 if (!info->shared
1076 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1078 h->root.u.def.section = s;
1079 h->root.u.def.value = s->_raw_size;
1082 h->plt.offset = s->_raw_size;
1084 /* Make room for this entry. */
1085 s->_raw_size += PLT_ENTRY_SIZE;
1087 /* We also need to make an entry in the .got.plt section, which
1088 will be placed in the .got section by the linker script. */
1090 s = bfd_get_section_by_name (dynobj, ".got.plt");
1091 BFD_ASSERT (s != NULL);
1092 s->_raw_size += 4;
1094 /* We also need to make an entry in the .rela.plt section. */
1096 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1097 BFD_ASSERT (s != NULL);
1098 s->_raw_size += sizeof (Elf32_External_Rela);
1100 return true;
1103 /* Reinitialize the plt offset now that it is not used as a reference
1104 count any more. */
1105 h->plt.offset = (bfd_vma) -1;
1107 /* If this is a weak symbol, and there is a real definition, the
1108 processor independent code will have arranged for us to see the
1109 real definition first, and we can just use the same value. */
1110 if (h->weakdef != NULL)
1112 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1113 || h->weakdef->root.type == bfd_link_hash_defweak);
1114 h->root.u.def.section = h->weakdef->root.u.def.section;
1115 h->root.u.def.value = h->weakdef->root.u.def.value;
1116 return true;
1119 /* This is a reference to a symbol defined by a dynamic object which
1120 is not a function. */
1122 /* If we are creating a shared library, we must presume that the
1123 only references to the symbol are via the global offset table.
1124 For such cases we need not do anything here; the relocations will
1125 be handled correctly by relocate_section. */
1126 if (info->shared)
1127 return true;
1129 /* We must allocate the symbol in our .dynbss section, which will
1130 become part of the .bss section of the executable. There will be
1131 an entry for this symbol in the .dynsym section. The dynamic
1132 object will contain position independent code, so all references
1133 from the dynamic object to this symbol will go through the global
1134 offset table. The dynamic linker will use the .dynsym entry to
1135 determine the address it must put in the global offset table, so
1136 both the dynamic object and the regular object will refer to the
1137 same memory location for the variable. */
1139 s = bfd_get_section_by_name (dynobj, ".dynbss");
1140 BFD_ASSERT (s != NULL);
1142 /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
1143 copy the initial value out of the dynamic object and into the
1144 runtime process image. We need to remember the offset into the
1145 .rela.bss section we are going to use. */
1146 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1148 asection *srel;
1150 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1151 BFD_ASSERT (srel != NULL);
1152 srel->_raw_size += sizeof (Elf32_External_Rela);
1153 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1156 /* We need to figure out the alignment required for this symbol. I
1157 have no idea how ELF linkers handle this. */
1158 power_of_two = bfd_log2 (h->size);
1159 if (power_of_two > 3)
1160 power_of_two = 3;
1162 /* Apply the required alignment. */
1163 s->_raw_size = BFD_ALIGN (s->_raw_size,
1164 (bfd_size_type) (1 << power_of_two));
1165 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1167 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
1168 return false;
1171 /* Define the symbol as being at this point in the section. */
1172 h->root.u.def.section = s;
1173 h->root.u.def.value = s->_raw_size;
1175 /* Increment the section size to make room for the symbol. */
1176 s->_raw_size += h->size;
1178 return true;
1181 /* Set the sizes of the dynamic sections. */
1183 static boolean
1184 elf_vax_size_dynamic_sections (output_bfd, info)
1185 bfd *output_bfd;
1186 struct bfd_link_info *info;
1188 bfd *dynobj;
1189 asection *s;
1190 boolean plt;
1191 boolean relocs;
1192 boolean reltext;
1194 dynobj = elf_hash_table (info)->dynobj;
1195 BFD_ASSERT (dynobj != NULL);
1197 if (elf_hash_table (info)->dynamic_sections_created)
1199 /* Set the contents of the .interp section to the interpreter. */
1200 if (!info->shared)
1202 s = bfd_get_section_by_name (dynobj, ".interp");
1203 BFD_ASSERT (s != NULL);
1204 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1205 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1208 else
1210 /* We may have created entries in the .rela.got and .got sections.
1211 However, if we are not creating the dynamic sections, we will
1212 not actually use these entries. Reset the size of .rela.got
1213 and .got, which will cause it to get stripped from the output
1214 file below. */
1215 s = bfd_get_section_by_name (dynobj, ".rela.got");
1216 if (s != NULL)
1217 s->_raw_size = 0;
1218 s = bfd_get_section_by_name (dynobj, ".got.plt");
1219 if (s != NULL)
1220 s->_raw_size = 0;
1221 s = bfd_get_section_by_name (dynobj, ".got");
1222 if (s != NULL)
1223 s->_raw_size = 0;
1226 /* If this is a -Bsymbolic shared link, then we need to discard all PC
1227 relative relocs against symbols defined in a regular object. We
1228 allocated space for them in the check_relocs routine, but we will not
1229 fill them in in the relocate_section routine. */
1230 if (info->shared && info->symbolic)
1231 elf_vax_link_hash_traverse (elf_vax_hash_table (info),
1232 elf_vax_discard_copies,
1233 (PTR) NULL);
1235 /* The check_relocs and adjust_dynamic_symbol entry points have
1236 determined the sizes of the various dynamic sections. Allocate
1237 memory for them. */
1238 plt = false;
1239 relocs = false;
1240 reltext = false;
1241 for (s = dynobj->sections; s != NULL; s = s->next)
1243 const char *name;
1244 boolean strip;
1246 if ((s->flags & SEC_LINKER_CREATED) == 0)
1247 continue;
1249 /* It's OK to base decisions on the section name, because none
1250 of the dynobj section names depend upon the input files. */
1251 name = bfd_get_section_name (dynobj, s);
1253 strip = false;
1255 if (strcmp (name, ".plt") == 0)
1257 if (s->_raw_size == 0)
1259 /* Strip this section if we don't need it; see the
1260 comment below. */
1261 strip = true;
1263 else
1265 /* Remember whether there is a PLT. */
1266 plt = true;
1269 else if (strncmp (name, ".rela", 5) == 0)
1271 if (s->_raw_size == 0)
1273 /* If we don't need this section, strip it from the
1274 output file. This is mostly to handle .rela.bss and
1275 .rela.plt. We must create both sections in
1276 create_dynamic_sections, because they must be created
1277 before the linker maps input sections to output
1278 sections. The linker does that before
1279 adjust_dynamic_symbol is called, and it is that
1280 function which decides whether anything needs to go
1281 into these sections. */
1282 strip = true;
1284 else
1286 asection *target;
1288 /* Remember whether there are any reloc sections other
1289 than .rela.plt. */
1290 if (strcmp (name, ".rela.plt") != 0)
1292 const char *outname;
1294 relocs = true;
1296 /* If this relocation section applies to a read only
1297 section, then we probably need a DT_TEXTREL
1298 entry. .rela.plt is actually associated with
1299 .got.plt, which is never readonly. */
1300 outname = bfd_get_section_name (output_bfd,
1301 s->output_section);
1302 target = bfd_get_section_by_name (output_bfd, outname + 5);
1303 if (target != NULL
1304 && (target->flags & SEC_READONLY) != 0
1305 && (target->flags & SEC_ALLOC) != 0)
1306 reltext = true;
1309 /* We use the reloc_count field as a counter if we need
1310 to copy relocs into the output file. */
1311 s->reloc_count = 0;
1314 else if (strncmp (name, ".got", 4) != 0)
1316 /* It's not one of our sections, so don't allocate space. */
1317 continue;
1320 if (strip)
1322 _bfd_strip_section_from_output (info, s);
1323 continue;
1326 /* Allocate memory for the section contents. */
1327 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1328 if (s->contents == NULL && s->_raw_size != 0)
1329 return false;
1332 if (elf_hash_table (info)->dynamic_sections_created)
1334 /* Add some entries to the .dynamic section. We fill in the
1335 values later, in elf_vax_finish_dynamic_sections, but we
1336 must add the entries now so that we get the correct size for
1337 the .dynamic section. The DT_DEBUG entry is filled in by the
1338 dynamic linker and used by the debugger. */
1339 #define add_dynamic_entry(TAG, VAL) \
1340 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1342 if (!info->shared)
1344 if (!add_dynamic_entry (DT_DEBUG, 0))
1345 return false;
1348 if (plt)
1350 if (!add_dynamic_entry (DT_PLTGOT, 0)
1351 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1352 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1353 || !add_dynamic_entry (DT_JMPREL, 0))
1354 return false;
1357 if (relocs)
1359 if (!add_dynamic_entry (DT_RELA, 0)
1360 || !add_dynamic_entry (DT_RELASZ, 0)
1361 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1362 return false;
1365 if (reltext || (info->flags & DF_TEXTREL) != 0)
1367 if (!add_dynamic_entry (DT_TEXTREL, 0))
1368 return false;
1371 #undef add_dynamic_entry
1373 return true;
1376 /* This function is called via elf_vax_link_hash_traverse if we are
1377 creating a shared object with -Bsymbolic. It discards the space
1378 allocated to copy PC relative relocs against symbols which are defined
1379 in regular objects. We allocated space for them in the check_relocs
1380 routine, but we won't fill them in in the relocate_section routine. */
1382 /*ARGSUSED*/
1383 static boolean
1384 elf_vax_discard_copies (h, ignore)
1385 struct elf_vax_link_hash_entry *h;
1386 PTR ignore ATTRIBUTE_UNUSED;
1388 struct elf_vax_pcrel_relocs_copied *s;
1390 if (h->root.root.type == bfd_link_hash_warning)
1391 h = (struct elf_vax_link_hash_entry *) h->root.root.u.i.link;
1393 /* We only discard relocs for symbols defined in a regular object. */
1394 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1395 return true;
1397 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1398 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
1400 return true;
1403 /* Relocate an VAX ELF section. */
1405 static boolean
1406 elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
1407 contents, relocs, local_syms, local_sections)
1408 bfd *output_bfd;
1409 struct bfd_link_info *info;
1410 bfd *input_bfd;
1411 asection *input_section;
1412 bfd_byte *contents;
1413 Elf_Internal_Rela *relocs;
1414 Elf_Internal_Sym *local_syms;
1415 asection **local_sections;
1417 bfd *dynobj;
1418 Elf_Internal_Shdr *symtab_hdr;
1419 struct elf_link_hash_entry **sym_hashes;
1420 bfd_vma *local_got_offsets;
1421 bfd_vma plt_index;
1422 bfd_vma got_offset;
1423 asection *sgot;
1424 asection *splt;
1425 asection *sgotplt;
1426 asection *sreloc;
1427 Elf_Internal_Rela *rel;
1428 Elf_Internal_Rela *relend;
1430 dynobj = elf_hash_table (info)->dynobj;
1431 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1432 sym_hashes = elf_sym_hashes (input_bfd);
1433 local_got_offsets = elf_local_got_offsets (input_bfd);
1435 sgot = NULL;
1436 splt = NULL;
1437 sgotplt = NULL;
1438 sreloc = NULL;
1440 rel = relocs;
1441 relend = relocs + input_section->reloc_count;
1442 for (; rel < relend; rel++)
1444 int r_type;
1445 reloc_howto_type *howto;
1446 unsigned long r_symndx;
1447 struct elf_link_hash_entry *h;
1448 Elf_Internal_Sym *sym;
1449 asection *sec;
1450 bfd_vma relocation;
1451 bfd_reloc_status_type r;
1453 r_type = ELF32_R_TYPE (rel->r_info);
1454 if (r_type < 0 || r_type >= (int) R_VAX_max)
1456 bfd_set_error (bfd_error_bad_value);
1457 return false;
1459 howto = howto_table + r_type;
1461 r_symndx = ELF32_R_SYM (rel->r_info);
1463 if (info->relocateable)
1465 /* This is a relocateable link. We don't have to change
1466 anything, unless the reloc is against a section symbol,
1467 in which case we have to adjust according to where the
1468 section symbol winds up in the output section. */
1469 if (r_symndx < symtab_hdr->sh_info)
1471 sym = local_syms + r_symndx;
1472 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1474 sec = local_sections[r_symndx];
1475 rel->r_addend += sec->output_offset + sym->st_value;
1479 continue;
1482 /* This is a final link. */
1483 h = NULL;
1484 sym = NULL;
1485 sec = NULL;
1486 if (r_symndx < symtab_hdr->sh_info)
1488 sym = local_syms + r_symndx;
1489 sec = local_sections[r_symndx];
1490 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
1492 else
1494 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1495 while (h->root.type == bfd_link_hash_indirect
1496 || h->root.type == bfd_link_hash_warning)
1497 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1498 if (h->root.type == bfd_link_hash_defined
1499 || h->root.type == bfd_link_hash_defweak)
1501 sec = h->root.u.def.section;
1502 if ((r_type == R_VAX_PLT32
1503 && h->plt.offset != (bfd_vma) -1
1504 && elf_hash_table (info)->dynamic_sections_created)
1505 || (r_type == R_VAX_GOT32
1506 && strcmp (h->root.root.string,
1507 "_GLOBAL_OFFSET_TABLE_") != 0
1508 && elf_hash_table (info)->dynamic_sections_created
1509 && (! info->shared
1510 || (! info->symbolic && h->dynindx != -1)
1511 || (h->elf_link_hash_flags
1512 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1513 || (info->shared
1514 && ((! info->symbolic && h->dynindx != -1)
1515 || (h->elf_link_hash_flags
1516 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1517 && ((input_section->flags & SEC_ALLOC) != 0
1518 /* DWARF will emit R_VAX_32 relocations in its
1519 sections against symbols defined externally
1520 in shared libraries. We can't do anything
1521 with them here. */
1523 || ((input_section->flags & SEC_DEBUGGING) != 0
1524 && (h->elf_link_hash_flags
1525 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
1526 && (r_type == R_VAX_8
1527 || r_type == R_VAX_16
1528 || r_type == R_VAX_32
1529 || r_type == R_VAX_PC8
1530 || r_type == R_VAX_PC16
1531 || r_type == R_VAX_PC32)))
1533 /* In these cases, we don't need the relocation
1534 value. We check specially because in some
1535 obscure cases sec->output_section will be NULL. */
1536 relocation = 0;
1538 else
1539 relocation = (h->root.u.def.value
1540 + sec->output_section->vma
1541 + sec->output_offset);
1543 else if (h->root.type == bfd_link_hash_undefweak)
1544 relocation = 0;
1545 else if (info->shared
1546 && (!info->symbolic || info->allow_shlib_undefined)
1547 && !info->no_undefined
1548 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1549 relocation = 0;
1550 else
1552 if (!(info->callbacks->undefined_symbol
1553 (info, h->root.root.string, input_bfd,
1554 input_section, rel->r_offset,
1555 (!info->shared || info->no_undefined
1556 || ELF_ST_VISIBILITY (h->other)))))
1557 return false;
1558 relocation = 0;
1562 switch (r_type)
1564 case R_VAX_GOT32:
1565 /* Relocation is to the address of the entry for this symbol
1566 in the global offset table. */
1567 if (h != NULL
1568 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1569 break;
1571 /* Relocation is the offset of the entry for this symbol in
1572 the global offset table. */
1575 bfd_vma off;
1577 if (!elf_hash_table (info)->dynamic_sections_created
1578 || (h == NULL)
1579 || (info->shared
1580 && info->symbolic
1581 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1583 /* This is actually a static link, or it is a -Bsymbolic link
1584 and the symbol is defined locally or there is no symbol.
1585 Change the GOT32 entry to a PC32 entry. */
1586 break;
1589 if (sgot == NULL)
1591 sgot = bfd_get_section_by_name (dynobj, ".got");
1592 BFD_ASSERT (sgot != NULL);
1595 BFD_ASSERT (h != NULL);
1596 off = h->got.offset;
1597 BFD_ASSERT (off != (bfd_vma) -1);
1599 if (info->shared
1600 && h->dynindx == -1
1601 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1603 /* The symbol was forced to be local
1604 because of a version file.. We must initialize
1605 this entry in the global offset table. Since
1606 the offset must always be a multiple of 4, we
1607 use the least significant bit to record whether
1608 we have initialized it already.
1610 When doing a dynamic link, we create a .rela.got
1611 relocation entry to initialize the value. This
1612 is done in the finish_dynamic_symbol routine. */
1613 if ((off & 1) != 0)
1614 off &= ~1;
1615 else
1617 bfd_put_32 (output_bfd, relocation + rel->r_addend,
1618 sgot->contents + off);
1619 h->got.offset |= 1;
1621 } else {
1622 bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off);
1625 relocation = sgot->output_offset + off;
1626 /* Neither GOT relocation uses the addend. */
1627 rel->r_addend = 0;
1629 if (r_type == R_VAX_GOT32)
1631 /* Change the reference to be indirect */
1632 contents[rel->r_offset - 1] |= 0x10;
1633 relocation += sgot->output_section->vma;
1636 break;
1638 case R_VAX_PLT32:
1639 /* Relocation is to the entry for this symbol in the
1640 procedure linkage table. */
1642 /* Resolve a PLTxx reloc against a local symbol directly,
1643 without using the procedure linkage table. */
1644 if (h == NULL)
1645 break;
1647 if (h->plt.offset == (bfd_vma) -1
1648 || !elf_hash_table (info)->dynamic_sections_created)
1650 /* We didn't make a PLT entry for this symbol. This
1651 happens when statically linking PIC code, or when
1652 using -Bsymbolic. */
1653 break;
1656 if (splt == NULL)
1658 splt = bfd_get_section_by_name (dynobj, ".plt");
1659 BFD_ASSERT (splt != NULL);
1662 if (sgotplt == NULL)
1664 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1665 BFD_ASSERT (splt != NULL);
1668 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1670 /* Get the offset into the .got table of the entry that
1671 corresponds to this function. Each .got entry is 4 bytes.
1672 The first two are reserved. */
1673 got_offset = (plt_index + 3) * 4;
1675 /* We want the relocate to point into the .got.plt instead
1676 of the plt itself. */
1677 relocation = (sgotplt->output_section->vma
1678 + sgotplt->output_offset
1679 + got_offset);
1680 contents[rel->r_offset-1] |= 0x10; /* make indirect */
1681 if (rel->r_addend == 2)
1683 h->plt.offset |= 1;
1685 else if (rel->r_addend != 0)
1686 (*_bfd_error_handler)
1687 (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"),
1688 bfd_get_filename (input_bfd), rel->r_addend,
1689 h->root.root.string,
1690 bfd_get_section_name (input_bfd, input_section));
1691 rel->r_addend = 0;
1693 break;
1695 case R_VAX_PC8:
1696 case R_VAX_PC16:
1697 case R_VAX_PC32:
1698 if (h == NULL)
1699 break;
1700 /* Fall through. */
1701 case R_VAX_8:
1702 case R_VAX_16:
1703 case R_VAX_32:
1704 if (info->shared
1705 && r_symndx != 0
1706 && (input_section->flags & SEC_ALLOC) != 0
1707 && ((r_type != R_VAX_PC8
1708 && r_type != R_VAX_PC16
1709 && r_type != R_VAX_PC32)
1710 || (!info->symbolic
1711 || (h->elf_link_hash_flags
1712 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
1714 Elf_Internal_Rela outrel;
1715 boolean skip, relocate;
1717 /* When generating a shared object, these relocations
1718 are copied into the output file to be resolved at run
1719 time. */
1721 if (sreloc == NULL)
1723 const char *name;
1725 name = (bfd_elf_string_from_elf_section
1726 (input_bfd,
1727 elf_elfheader (input_bfd)->e_shstrndx,
1728 elf_section_data (input_section)->rel_hdr.sh_name));
1729 if (name == NULL)
1730 return false;
1732 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1733 && strcmp (bfd_get_section_name (input_bfd,
1734 input_section),
1735 name + 5) == 0);
1737 sreloc = bfd_get_section_by_name (dynobj, name);
1738 BFD_ASSERT (sreloc != NULL);
1741 skip = false;
1742 relocate = false;
1744 outrel.r_offset =
1745 _bfd_elf_section_offset (output_bfd, info, input_section,
1746 rel->r_offset);
1747 if (outrel.r_offset == (bfd_vma) -1)
1748 skip = true;
1749 if (outrel.r_offset == (bfd_vma) -2)
1750 skip = true, relocate = true;
1751 outrel.r_offset += (input_section->output_section->vma
1752 + input_section->output_offset);
1754 if (skip)
1755 memset (&outrel, 0, sizeof outrel);
1756 /* h->dynindx may be -1 if the symbol was marked to
1757 become local. */
1758 else if (h != NULL
1759 && ((! info->symbolic && h->dynindx != -1)
1760 || (h->elf_link_hash_flags
1761 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1763 BFD_ASSERT (h->dynindx != -1);
1764 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1765 outrel.r_addend = relocation + rel->r_addend;
1767 else
1769 if (r_type == R_VAX_32)
1771 relocate = true;
1772 outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1773 BFD_ASSERT (bfd_get_signed_32 (input_bfd,
1774 &contents[rel->r_offset]) == 0);
1775 outrel.r_addend = relocation + rel->r_addend;
1777 else
1779 long indx;
1781 if (h == NULL)
1782 sec = local_sections[r_symndx];
1783 else
1785 BFD_ASSERT (h->root.type == bfd_link_hash_defined
1786 || (h->root.type
1787 == bfd_link_hash_defweak));
1788 sec = h->root.u.def.section;
1790 if (sec != NULL && bfd_is_abs_section (sec))
1791 indx = 0;
1792 else if (sec == NULL || sec->owner == NULL)
1794 bfd_set_error (bfd_error_bad_value);
1795 return false;
1797 else
1799 asection *osec;
1801 osec = sec->output_section;
1802 indx = elf_section_data (osec)->dynindx;
1803 BFD_ASSERT (indx > 0);
1806 outrel.r_info = ELF32_R_INFO (indx, r_type);
1807 outrel.r_addend = relocation + rel->r_addend;
1811 if (!strcmp (bfd_get_section_name (input_bfd, input_section),
1812 ".text") != 0 ||
1813 (info->shared
1814 && ELF32_R_TYPE(outrel.r_info) != R_VAX_32
1815 && ELF32_R_TYPE(outrel.r_info) != R_VAX_RELATIVE
1816 && ELF32_R_TYPE(outrel.r_info) != R_VAX_COPY
1817 && ELF32_R_TYPE(outrel.r_info) != R_VAX_JMP_SLOT
1818 && ELF32_R_TYPE(outrel.r_info) != R_VAX_GLOB_DAT))
1820 if (h != NULL)
1821 (*_bfd_error_handler)
1822 (_("%s: warning: %s relocation against symbol `%s' from %s section"),
1823 bfd_get_filename (input_bfd), howto->name,
1824 h->root.root.string,
1825 bfd_get_section_name (input_bfd, input_section));
1826 else
1827 (*_bfd_error_handler)
1828 (_("%s: warning: %s relocation to 0x%x from %s section"),
1829 bfd_get_filename (input_bfd), howto->name,
1830 outrel.r_addend,
1831 bfd_get_section_name (input_bfd, input_section));
1833 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1834 (((Elf32_External_Rela *)
1835 sreloc->contents)
1836 + sreloc->reloc_count));
1837 ++sreloc->reloc_count;
1839 /* This reloc will be computed at runtime, so there's no
1840 need to do anything now, except for R_VAX_32
1841 relocations that have been turned into
1842 R_VAX_RELATIVE. */
1843 if (!relocate)
1844 continue;
1847 break;
1849 case R_VAX_GNU_VTINHERIT:
1850 case R_VAX_GNU_VTENTRY:
1851 /* These are no-ops in the end. */
1852 continue;
1854 default:
1855 break;
1858 /* VAX PCREL relocations are from the end of relocation, not the start */
1859 if (howto->pc_relative && howto->pcrel_offset)
1861 relocation -= bfd_get_reloc_size(howto);
1864 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1865 contents, rel->r_offset,
1866 relocation, rel->r_addend);
1868 if (r != bfd_reloc_ok)
1870 switch (r)
1872 default:
1873 case bfd_reloc_outofrange:
1874 abort ();
1875 case bfd_reloc_overflow:
1877 const char *name;
1879 if (h != NULL)
1880 name = h->root.root.string;
1881 else
1883 name = bfd_elf_string_from_elf_section (input_bfd,
1884 symtab_hdr->sh_link,
1885 sym->st_name);
1886 if (name == NULL)
1887 return false;
1888 if (*name == '\0')
1889 name = bfd_section_name (input_bfd, sec);
1891 if (!(info->callbacks->reloc_overflow
1892 (info, name, howto->name, (bfd_vma) 0,
1893 input_bfd, input_section, rel->r_offset)))
1894 return false;
1896 break;
1901 return true;
1904 /* Finish up dynamic symbol handling. We set the contents of various
1905 dynamic sections here. */
1907 static boolean
1908 elf_vax_finish_dynamic_symbol (output_bfd, info, h, sym)
1909 bfd *output_bfd;
1910 struct bfd_link_info *info;
1911 struct elf_link_hash_entry *h;
1912 Elf_Internal_Sym *sym;
1914 bfd *dynobj;
1916 dynobj = elf_hash_table (info)->dynobj;
1918 if (h->plt.offset != (bfd_vma) -1)
1920 asection *splt;
1921 asection *sgot;
1922 asection *srela;
1923 bfd_vma plt_index;
1924 bfd_vma got_offset;
1925 bfd_vma addend;
1926 Elf_Internal_Rela rela;
1928 /* This symbol has an entry in the procedure linkage table. Set
1929 it up. */
1931 BFD_ASSERT (h->dynindx != -1);
1933 splt = bfd_get_section_by_name (dynobj, ".plt");
1934 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1935 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1936 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1938 addend = 2 * (h->plt.offset & 1);
1939 h->plt.offset &= ~1;
1941 /* Get the index in the procedure linkage table which
1942 corresponds to this symbol. This is the index of this symbol
1943 in all the symbols for which we are making plt entries. The
1944 first entry in the procedure linkage table is reserved. */
1945 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1947 /* Get the offset into the .got table of the entry that
1948 corresponds to this function. Each .got entry is 4 bytes.
1949 The first two are reserved. */
1950 got_offset = (plt_index + 3) * 4;
1952 /* Fill in the entry in the procedure linkage table. */
1953 memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
1954 PLT_ENTRY_SIZE);
1956 /* The offset is relative to the first extension word. */
1957 bfd_put_32 (output_bfd,
1958 -(h->plt.offset + 8),
1959 splt->contents + h->plt.offset + 4);
1961 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
1962 splt->contents + h->plt.offset + 8);
1964 /* Fill in the entry in the global offset table. */
1965 bfd_put_32 (output_bfd,
1966 (splt->output_section->vma
1967 + splt->output_offset
1968 + h->plt.offset) + addend,
1969 sgot->contents + got_offset);
1971 /* Fill in the entry in the .rela.plt section. */
1972 rela.r_offset = (sgot->output_section->vma
1973 + sgot->output_offset
1974 + got_offset);
1975 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
1976 rela.r_addend = addend;
1977 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1978 ((Elf32_External_Rela *) srela->contents
1979 + plt_index));
1981 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1983 /* Mark the symbol as undefined, rather than as defined in
1984 the .plt section. Leave the value alone. */
1985 sym->st_shndx = SHN_UNDEF;
1989 if (h->got.offset != (bfd_vma) -1)
1991 asection *sgot;
1992 asection *srela;
1993 Elf_Internal_Rela rela;
1995 /* This symbol has an entry in the global offset table. Set it
1996 up. */
1998 sgot = bfd_get_section_by_name (dynobj, ".got");
1999 srela = bfd_get_section_by_name (dynobj, ".rela.got");
2000 BFD_ASSERT (sgot != NULL && srela != NULL);
2002 rela.r_offset = (sgot->output_section->vma
2003 + sgot->output_offset
2004 + (h->got.offset &~ 1));
2006 /* If the symbol was forced to be local because of a version file
2007 locally we just want to emit a RELATIVE reloc. The entry in
2008 the global offset table will already have been initialized in
2009 the relocate_section function. */
2010 if (info->shared
2011 && h->dynindx == -1
2012 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2014 rela.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
2016 else
2018 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
2020 rela.r_addend = bfd_get_signed_32 (output_bfd,
2021 (sgot->contents
2022 + (h->got.offset & ~1)));
2024 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2025 ((Elf32_External_Rela *) srela->contents
2026 + srela->reloc_count));
2027 ++srela->reloc_count;
2030 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2032 asection *s;
2033 Elf_Internal_Rela rela;
2035 /* This symbol needs a copy reloc. Set it up. */
2037 BFD_ASSERT (h->dynindx != -1
2038 && (h->root.type == bfd_link_hash_defined
2039 || h->root.type == bfd_link_hash_defweak));
2041 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2042 ".rela.bss");
2043 BFD_ASSERT (s != NULL);
2045 rela.r_offset = (h->root.u.def.value
2046 + h->root.u.def.section->output_section->vma
2047 + h->root.u.def.section->output_offset);
2048 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
2049 rela.r_addend = 0;
2050 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2051 ((Elf32_External_Rela *) s->contents
2052 + s->reloc_count));
2053 ++s->reloc_count;
2056 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2057 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2058 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2059 sym->st_shndx = SHN_ABS;
2061 return true;
2064 /* Finish up the dynamic sections. */
2066 static boolean
2067 elf_vax_finish_dynamic_sections (output_bfd, info)
2068 bfd *output_bfd;
2069 struct bfd_link_info *info;
2071 bfd *dynobj;
2072 asection *sgot;
2073 asection *sdyn;
2075 dynobj = elf_hash_table (info)->dynobj;
2077 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
2078 BFD_ASSERT (sgot != NULL);
2079 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2081 if (elf_hash_table (info)->dynamic_sections_created)
2083 asection *splt;
2084 Elf32_External_Dyn *dyncon, *dynconend;
2086 splt = bfd_get_section_by_name (dynobj, ".plt");
2087 BFD_ASSERT (splt != NULL && sdyn != NULL);
2089 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2090 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2091 for (; dyncon < dynconend; dyncon++)
2093 Elf_Internal_Dyn dyn;
2094 const char *name;
2095 asection *s;
2097 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2099 switch (dyn.d_tag)
2101 default:
2102 break;
2104 case DT_PLTGOT:
2105 name = ".got";
2106 goto get_vma;
2107 case DT_JMPREL:
2108 name = ".rela.plt";
2109 get_vma:
2110 s = bfd_get_section_by_name (output_bfd, name);
2111 BFD_ASSERT (s != NULL);
2112 dyn.d_un.d_ptr = s->vma;
2113 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2114 break;
2116 case DT_PLTRELSZ:
2117 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2118 BFD_ASSERT (s != NULL);
2119 if (s->_cooked_size != 0)
2120 dyn.d_un.d_val = s->_cooked_size;
2121 else
2122 dyn.d_un.d_val = s->_raw_size;
2123 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2124 break;
2126 case DT_RELASZ:
2127 /* The procedure linkage table relocs (DT_JMPREL) should
2128 not be included in the overall relocs (DT_RELA).
2129 Therefore, we override the DT_RELASZ entry here to
2130 make it not include the JMPREL relocs. Since the
2131 linker script arranges for .rela.plt to follow all
2132 other relocation sections, we don't have to worry
2133 about changing the DT_RELA entry. */
2134 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2135 if (s != NULL)
2137 if (s->_cooked_size != 0)
2138 dyn.d_un.d_val -= s->_cooked_size;
2139 else
2140 dyn.d_un.d_val -= s->_raw_size;
2142 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2143 break;
2147 /* Fill in the first entry in the procedure linkage table. */
2148 if (splt->_raw_size > 0)
2150 memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
2151 bfd_put_32 (output_bfd,
2152 (sgot->output_section->vma
2153 + sgot->output_offset + 4
2154 - (splt->output_section->vma + 6)),
2155 splt->contents + 2);
2156 bfd_put_32 (output_bfd,
2157 (sgot->output_section->vma
2158 + sgot->output_offset + 8
2159 - (splt->output_section->vma + 12)),
2160 splt->contents + 8);
2161 elf_section_data (splt->output_section)->this_hdr.sh_entsize
2162 = PLT_ENTRY_SIZE;
2166 /* Fill in the first three entries in the global offset table. */
2167 if (sgot->_raw_size > 0)
2169 if (sdyn == NULL)
2170 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2171 else
2172 bfd_put_32 (output_bfd,
2173 sdyn->output_section->vma + sdyn->output_offset,
2174 sgot->contents);
2175 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
2176 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
2179 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2181 return true;
2184 #define TARGET_LITTLE_SYM bfd_elf32_vax_vec
2185 #define TARGET_LITTLE_NAME "elf32-vax"
2186 #define ELF_MACHINE_CODE EM_VAX
2187 #define ELF_MAXPAGESIZE 0x1000
2189 #define elf_backend_create_dynamic_sections \
2190 _bfd_elf_create_dynamic_sections
2191 #define bfd_elf32_bfd_link_hash_table_create \
2192 elf_vax_link_hash_table_create
2193 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
2195 #define elf_backend_check_relocs elf_vax_check_relocs
2196 #define elf_backend_adjust_dynamic_symbol \
2197 elf_vax_adjust_dynamic_symbol
2198 #define elf_backend_size_dynamic_sections \
2199 elf_vax_size_dynamic_sections
2200 #define elf_backend_relocate_section elf_vax_relocate_section
2201 #define elf_backend_finish_dynamic_symbol \
2202 elf_vax_finish_dynamic_symbol
2203 #define elf_backend_finish_dynamic_sections \
2204 elf_vax_finish_dynamic_sections
2205 #define elf_backend_gc_mark_hook elf_vax_gc_mark_hook
2206 #define elf_backend_gc_sweep_hook elf_vax_gc_sweep_hook
2207 #define bfd_elf32_bfd_merge_private_bfd_data \
2208 elf32_vax_merge_private_bfd_data
2209 #define bfd_elf32_bfd_set_private_flags \
2210 elf32_vax_set_private_flags
2211 #define bfd_elf32_bfd_print_private_bfd_data \
2212 elf32_vax_print_private_bfd_data
2214 #define elf_backend_can_gc_sections 1
2215 #define elf_backend_want_got_plt 1
2216 #define elf_backend_plt_readonly 1
2217 #define elf_backend_want_plt_sym 0
2218 #define elf_backend_got_header_size 16
2220 #include "elf32-target.h"