daily update
[binutils.git] / bfd / elf32-vax.c
blob7d78e0ff3bdc23dbd4c36dabec1695c23e76d81b
1 /* VAX series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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 *, Elf_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 bfd_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 ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
42 struct elf_link_hash_entry *, Elf_Internal_Sym *));
43 static bfd_boolean elf_vax_gc_sweep_hook
44 PARAMS ((bfd *, struct bfd_link_info *, asection *,
45 const Elf_Internal_Rela *));
46 static bfd_boolean elf_vax_adjust_dynamic_symbol
47 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
48 static bfd_boolean elf_vax_size_dynamic_sections
49 PARAMS ((bfd *, struct bfd_link_info *));
50 static bfd_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 bfd_boolean elf_vax_finish_dynamic_symbol
54 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
55 Elf_Internal_Sym *));
56 static bfd_boolean elf_vax_finish_dynamic_sections
57 PARAMS ((bfd *, struct bfd_link_info *));
59 static bfd_boolean elf32_vax_set_private_flags
60 PARAMS ((bfd *, flagword));
61 static bfd_boolean elf32_vax_merge_private_bfd_data
62 PARAMS ((bfd *, bfd *));
63 static bfd_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 /* Functions for the VAX ELF linker. */
347 /* The name of the dynamic interpreter. This is put in the .interp
348 section. */
350 #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
352 /* The size in bytes of an entry in the procedure linkage table. */
354 #define PLT_ENTRY_SIZE 12
356 /* The first entry in a procedure linkage table looks like this. See
357 the SVR4 ABI VAX supplement to see how this works. */
359 static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
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 */
367 /* Subsequent entries in a procedure linkage table look like this. */
369 static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
371 0x40, 0x00, /* .word ^M<r6> */
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 */
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. */
383 /* This structure keeps track of the number of PC relative relocs we have
384 copied for a given symbol. */
386 struct elf_vax_pcrel_relocs_copied
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;
396 /* VAX ELF linker hash entry. */
398 struct elf_vax_link_hash_entry
400 struct elf_link_hash_entry root;
402 /* Number of PC relative relocs copied for this symbol. */
403 struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
405 bfd_vma got_addend;
408 /* VAX ELF linker hash table. */
410 struct elf_vax_link_hash_table
412 struct elf_link_hash_table root;
415 /* Declare this now that the above structures are defined. */
417 static bfd_boolean elf_vax_discard_copies
418 PARAMS ((struct elf_vax_link_hash_entry *, PTR));
420 /* Declare this now that the above structures are defined. */
422 static bfd_boolean elf_vax_instantiate_got_entries
423 PARAMS ((struct elf_link_hash_entry *, PTR));
425 /* Traverse an VAX ELF linker hash table. */
427 #define elf_vax_link_hash_traverse(table, func, info) \
428 (elf_link_hash_traverse \
429 (&(table)->root, \
430 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
431 (info)))
433 /* Get the VAX ELF linker hash table from a link_info structure. */
435 #define elf_vax_hash_table(p) \
436 ((struct elf_vax_link_hash_table *) (p)->hash)
438 /* Create an entry in an VAX ELF linker hash table. */
440 static struct bfd_hash_entry *
441 elf_vax_link_hash_newfunc (entry, table, string)
442 struct bfd_hash_entry *entry;
443 struct bfd_hash_table *table;
444 const char *string;
446 struct elf_vax_link_hash_entry *ret =
447 (struct elf_vax_link_hash_entry *) entry;
449 /* Allocate the structure if it has not already been allocated by a
450 subclass. */
451 if (ret == (struct elf_vax_link_hash_entry *) NULL)
452 ret = ((struct elf_vax_link_hash_entry *)
453 bfd_hash_allocate (table,
454 sizeof (struct elf_vax_link_hash_entry)));
455 if (ret == (struct elf_vax_link_hash_entry *) NULL)
456 return (struct bfd_hash_entry *) ret;
458 /* Call the allocation method of the superclass. */
459 ret = ((struct elf_vax_link_hash_entry *)
460 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
461 table, string));
462 if (ret != (struct elf_vax_link_hash_entry *) NULL)
464 ret->pcrel_relocs_copied = NULL;
467 return (struct bfd_hash_entry *) ret;
470 /* Create an VAX ELF linker hash table. */
472 static struct bfd_link_hash_table *
473 elf_vax_link_hash_table_create (abfd)
474 bfd *abfd;
476 struct elf_vax_link_hash_table *ret;
477 bfd_size_type amt = sizeof (struct elf_vax_link_hash_table);
479 ret = (struct elf_vax_link_hash_table *) bfd_malloc (amt);
480 if (ret == (struct elf_vax_link_hash_table *) NULL)
481 return NULL;
483 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
484 elf_vax_link_hash_newfunc))
486 free (ret);
487 return NULL;
490 return &ret->root.root;
493 /* Keep vax-specific flags in the ELF header */
494 static bfd_boolean
495 elf32_vax_set_private_flags (abfd, flags)
496 bfd *abfd;
497 flagword flags;
499 elf_elfheader (abfd)->e_flags = flags;
500 elf_flags_init (abfd) = TRUE;
501 return TRUE;
504 /* Merge backend specific data from an object file to the output
505 object file when linking. */
506 static bfd_boolean
507 elf32_vax_merge_private_bfd_data (ibfd, obfd)
508 bfd *ibfd;
509 bfd *obfd;
511 flagword out_flags;
512 flagword in_flags;
514 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
515 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
516 return TRUE;
518 in_flags = elf_elfheader (ibfd)->e_flags;
519 out_flags = elf_elfheader (obfd)->e_flags;
521 if (!elf_flags_init (obfd))
523 elf_flags_init (obfd) = TRUE;
524 elf_elfheader (obfd)->e_flags = in_flags;
527 return TRUE;
530 /* Display the flags field */
531 static bfd_boolean
532 elf32_vax_print_private_bfd_data (abfd, ptr)
533 bfd *abfd;
534 PTR ptr;
536 FILE *file = (FILE *) ptr;
538 BFD_ASSERT (abfd != NULL && ptr != NULL);
540 /* Print normal ELF private data. */
541 _bfd_elf_print_private_bfd_data (abfd, ptr);
543 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
545 /* xgettext:c-format */
546 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
548 if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
549 fprintf (file, _(" [nonpic]"));
551 if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
552 fprintf (file, _(" [d-float]"));
554 if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
555 fprintf (file, _(" [g-float]"));
557 fputc ('\n', file);
559 return TRUE;
561 /* Look through the relocs for a section during the first phase, and
562 allocate space in the global offset table or procedure linkage
563 table. */
565 static bfd_boolean
566 elf_vax_check_relocs (abfd, info, sec, relocs)
567 bfd *abfd;
568 struct bfd_link_info *info;
569 asection *sec;
570 const Elf_Internal_Rela *relocs;
572 bfd *dynobj;
573 Elf_Internal_Shdr *symtab_hdr;
574 struct elf_link_hash_entry **sym_hashes;
575 const Elf_Internal_Rela *rel;
576 const Elf_Internal_Rela *rel_end;
577 asection *sgot;
578 asection *srelgot;
579 asection *sreloc;
581 if (info->relocatable)
582 return TRUE;
584 dynobj = elf_hash_table (info)->dynobj;
585 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
586 sym_hashes = elf_sym_hashes (abfd);
588 sgot = NULL;
589 srelgot = NULL;
590 sreloc = NULL;
592 rel_end = relocs + sec->reloc_count;
593 for (rel = relocs; rel < rel_end; rel++)
595 unsigned long r_symndx;
596 struct elf_link_hash_entry *h;
598 r_symndx = ELF32_R_SYM (rel->r_info);
600 if (r_symndx < symtab_hdr->sh_info)
601 h = NULL;
602 else
603 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
605 switch (ELF32_R_TYPE (rel->r_info))
607 case R_VAX_GOT32:
608 if (h != NULL
609 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
610 break;
612 /* This symbol requires a global offset table entry. */
614 if (dynobj == NULL)
616 /* Create the .got section. */
617 elf_hash_table (info)->dynobj = dynobj = abfd;
618 if (!_bfd_elf_create_got_section (dynobj, info))
619 return FALSE;
622 if (sgot == NULL)
624 sgot = bfd_get_section_by_name (dynobj, ".got");
625 BFD_ASSERT (sgot != NULL);
628 if (srelgot == NULL
629 && (h != NULL || info->shared))
631 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
632 if (srelgot == NULL)
634 srelgot = bfd_make_section (dynobj, ".rela.got");
635 if (srelgot == NULL
636 || !bfd_set_section_flags (dynobj, srelgot,
637 (SEC_ALLOC
638 | SEC_LOAD
639 | SEC_HAS_CONTENTS
640 | SEC_IN_MEMORY
641 | SEC_LINKER_CREATED
642 | SEC_READONLY))
643 || !bfd_set_section_alignment (dynobj, srelgot, 2))
644 return FALSE;
648 if (h != NULL)
650 struct elf_vax_link_hash_entry *eh;
652 eh = (struct elf_vax_link_hash_entry *) h;
653 if (h->got.refcount == -1)
655 h->got.refcount = 1;
656 eh->got_addend = rel->r_addend;
658 else
660 h->got.refcount++;
661 if (eh->got_addend != (bfd_vma) rel->r_addend)
662 (*_bfd_error_handler)
663 (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
664 bfd_get_filename (abfd), rel->r_addend,
665 h->root.root.string,
666 eh->got_addend);
670 break;
672 case R_VAX_PLT32:
673 /* This symbol requires a procedure linkage table entry. We
674 actually build the entry in adjust_dynamic_symbol,
675 because this might be a case of linking PIC code which is
676 never referenced by a dynamic object, in which case we
677 don't need to generate a procedure linkage table entry
678 after all. */
680 /* If this is a local symbol, we resolve it directly without
681 creating a procedure linkage table entry. */
682 if (h == NULL)
683 continue;
685 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
686 if (h->plt.refcount == -1)
687 h->plt.refcount = 1;
688 else
689 h->plt.refcount++;
690 break;
692 case R_VAX_PC8:
693 case R_VAX_PC16:
694 case R_VAX_PC32:
695 /* If we are creating a shared library and this is not a local
696 symbol, we need to copy the reloc into the shared library.
697 However when linking with -Bsymbolic and this is a global
698 symbol which is defined in an object we are including in the
699 link (i.e., DEF_REGULAR is set), then we can resolve the
700 reloc directly. At this point we have not seen all the input
701 files, so it is possible that DEF_REGULAR is not set now but
702 will be set later (it is never cleared). We account for that
703 possibility below by storing information in the
704 pcrel_relocs_copied field of the hash table entry. */
705 if (!(info->shared
706 && (sec->flags & SEC_ALLOC) != 0
707 && h != NULL
708 && (!info->symbolic
709 || (h->elf_link_hash_flags
710 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
712 if (h != NULL)
714 /* Make sure a plt entry is created for this symbol if
715 it turns out to be a function defined by a dynamic
716 object. */
717 if (h->plt.refcount == -1)
718 h->plt.refcount = 1;
719 else
720 h->plt.refcount++;
722 break;
724 /* Fall through. */
725 case R_VAX_8:
726 case R_VAX_16:
727 case R_VAX_32:
728 if (h != NULL)
730 /* Make sure a plt entry is created for this symbol if it
731 turns out to be a function defined by a dynamic object. */
732 if (h->plt.refcount == -1)
733 h->plt.refcount = 1;
734 else
735 h->plt.refcount++;
738 /* If we are creating a shared library, we need to copy the
739 reloc into the shared library. */
740 if (info->shared
741 && (sec->flags & SEC_ALLOC) != 0)
743 /* When creating a shared object, we must copy these
744 reloc types into the output file. We create a reloc
745 section in dynobj and make room for this reloc. */
746 if (sreloc == NULL)
748 const char *name;
750 name = (bfd_elf_string_from_elf_section
751 (abfd,
752 elf_elfheader (abfd)->e_shstrndx,
753 elf_section_data (sec)->rel_hdr.sh_name));
754 if (name == NULL)
755 return FALSE;
757 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
758 && strcmp (bfd_get_section_name (abfd, sec),
759 name + 5) == 0);
761 sreloc = bfd_get_section_by_name (dynobj, name);
762 if (sreloc == NULL)
764 sreloc = bfd_make_section (dynobj, name);
765 if (sreloc == NULL
766 || !bfd_set_section_flags (dynobj, sreloc,
767 (SEC_ALLOC
768 | SEC_LOAD
769 | SEC_HAS_CONTENTS
770 | SEC_IN_MEMORY
771 | SEC_LINKER_CREATED
772 | SEC_READONLY))
773 || !bfd_set_section_alignment (dynobj, sreloc, 2))
774 return FALSE;
776 if (sec->flags & SEC_READONLY)
777 info->flags |= DF_TEXTREL;
780 sreloc->_raw_size += sizeof (Elf32_External_Rela);
782 /* If we are linking with -Bsymbolic, we count the number of
783 PC relative relocations we have entered for this symbol,
784 so that we can discard them again if the symbol is later
785 defined by a regular object. Note that this function is
786 only called if we are using a vaxelf linker hash table,
787 which means that h is really a pointer to an
788 elf_vax_link_hash_entry. */
789 if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
790 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
791 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
792 && info->symbolic)
794 struct elf_vax_link_hash_entry *eh;
795 struct elf_vax_pcrel_relocs_copied *p;
797 eh = (struct elf_vax_link_hash_entry *) h;
799 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
800 if (p->section == sreloc)
801 break;
803 if (p == NULL)
805 p = ((struct elf_vax_pcrel_relocs_copied *)
806 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
807 if (p == NULL)
808 return FALSE;
809 p->next = eh->pcrel_relocs_copied;
810 eh->pcrel_relocs_copied = p;
811 p->section = sreloc;
812 p->count = 0;
815 ++p->count;
819 break;
821 /* This relocation describes the C++ object vtable hierarchy.
822 Reconstruct it for later use during GC. */
823 case R_VAX_GNU_VTINHERIT:
824 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
825 return FALSE;
826 break;
828 /* This relocation describes which C++ vtable entries are actually
829 used. Record for later use during GC. */
830 case R_VAX_GNU_VTENTRY:
831 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
832 return FALSE;
833 break;
835 default:
836 break;
840 return TRUE;
843 /* Return the section that should be marked against GC for a given
844 relocation. */
846 static asection *
847 elf_vax_gc_mark_hook (sec, info, rel, h, sym)
848 asection *sec;
849 struct bfd_link_info *info ATTRIBUTE_UNUSED;
850 Elf_Internal_Rela *rel;
851 struct elf_link_hash_entry *h;
852 Elf_Internal_Sym *sym;
854 if (h != NULL)
856 switch (ELF32_R_TYPE (rel->r_info))
858 case R_VAX_GNU_VTINHERIT:
859 case R_VAX_GNU_VTENTRY:
860 break;
862 default:
863 switch (h->root.type)
865 default:
866 break;
868 case bfd_link_hash_defined:
869 case bfd_link_hash_defweak:
870 return h->root.u.def.section;
872 case bfd_link_hash_common:
873 return h->root.u.c.p->section;
877 else
878 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
880 return NULL;
883 /* Update the got entry reference counts for the section being removed. */
885 static bfd_boolean
886 elf_vax_gc_sweep_hook (abfd, info, sec, relocs)
887 bfd *abfd;
888 struct bfd_link_info *info;
889 asection *sec;
890 const Elf_Internal_Rela *relocs;
892 Elf_Internal_Shdr *symtab_hdr;
893 struct elf_link_hash_entry **sym_hashes;
894 const Elf_Internal_Rela *rel, *relend;
895 unsigned long r_symndx;
896 struct elf_link_hash_entry *h;
897 bfd *dynobj;
899 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
900 sym_hashes = elf_sym_hashes (abfd);
902 dynobj = elf_hash_table (info)->dynobj;
903 if (dynobj == NULL)
904 return TRUE;
906 relend = relocs + sec->reloc_count;
907 for (rel = relocs; rel < relend; rel++)
909 switch (ELF32_R_TYPE (rel->r_info))
911 case R_VAX_GOT32:
912 r_symndx = ELF32_R_SYM (rel->r_info);
913 if (r_symndx >= symtab_hdr->sh_info)
915 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
916 if (h->got.refcount > 0)
917 --h->got.refcount;
919 break;
921 case R_VAX_PLT32:
922 case R_VAX_PC8:
923 case R_VAX_PC16:
924 case R_VAX_PC32:
925 case R_VAX_8:
926 case R_VAX_16:
927 case R_VAX_32:
928 r_symndx = ELF32_R_SYM (rel->r_info);
929 if (r_symndx >= symtab_hdr->sh_info)
931 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
932 if (h->plt.refcount > 0)
933 --h->plt.refcount;
935 break;
937 default:
938 break;
942 return TRUE;
945 /* Adjust a symbol defined by a dynamic object and referenced by a
946 regular object. The current definition is in some section of the
947 dynamic object, but we're not including those sections. We have to
948 change the definition to something the rest of the link can
949 understand. */
951 static bfd_boolean
952 elf_vax_adjust_dynamic_symbol (info, h)
953 struct bfd_link_info *info;
954 struct elf_link_hash_entry *h;
956 bfd *dynobj;
957 asection *s;
958 unsigned int power_of_two;
960 dynobj = elf_hash_table (info)->dynobj;
962 /* Make sure we know what is going on here. */
963 BFD_ASSERT (dynobj != NULL
964 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
965 || h->weakdef != NULL
966 || ((h->elf_link_hash_flags
967 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
968 && (h->elf_link_hash_flags
969 & ELF_LINK_HASH_REF_REGULAR) != 0
970 && (h->elf_link_hash_flags
971 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
973 /* If this is a function, put it in the procedure linkage table. We
974 will fill in the contents of the procedure linkage table later,
975 when we know the address of the .got section. */
976 if (h->type == STT_FUNC
977 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
979 if (! info->shared
980 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
981 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
982 /* We must always create the plt entry if it was referenced
983 by a PLTxxO relocation. In this case we already recorded
984 it as a dynamic symbol. */
985 && h->dynindx == -1)
987 /* This case can occur if we saw a PLTxx reloc in an input
988 file, but the symbol was never referred to by a dynamic
989 object. In such a case, we don't actually need to build
990 a procedure linkage table, and we can just do a PCxx
991 reloc instead. */
992 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
993 h->plt.offset = (bfd_vma) -1;
994 return TRUE;
997 /* GC may have rendered this entry unused. */
998 if (h->plt.refcount <= 0)
1000 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1001 h->plt.offset = (bfd_vma) -1;
1002 return TRUE;
1005 /* Make sure this symbol is output as a dynamic symbol. */
1006 if (h->dynindx == -1)
1008 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1009 return FALSE;
1012 s = bfd_get_section_by_name (dynobj, ".plt");
1013 BFD_ASSERT (s != NULL);
1015 /* If this is the first .plt entry, make room for the special
1016 first entry. */
1017 if (s->_raw_size == 0)
1019 s->_raw_size += PLT_ENTRY_SIZE;
1022 /* If this symbol is not defined in a regular file, and we are
1023 not generating a shared library, then set the symbol to this
1024 location in the .plt. This is required to make function
1025 pointers compare as equal between the normal executable and
1026 the shared library. */
1027 if (!info->shared
1028 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1030 h->root.u.def.section = s;
1031 h->root.u.def.value = s->_raw_size;
1034 h->plt.offset = s->_raw_size;
1036 /* Make room for this entry. */
1037 s->_raw_size += PLT_ENTRY_SIZE;
1039 /* We also need to make an entry in the .got.plt section, which
1040 will be placed in the .got section by the linker script. */
1042 s = bfd_get_section_by_name (dynobj, ".got.plt");
1043 BFD_ASSERT (s != NULL);
1044 s->_raw_size += 4;
1046 /* We also need to make an entry in the .rela.plt section. */
1048 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1049 BFD_ASSERT (s != NULL);
1050 s->_raw_size += sizeof (Elf32_External_Rela);
1052 return TRUE;
1055 /* Reinitialize the plt offset now that it is not used as a reference
1056 count any more. */
1057 h->plt.offset = (bfd_vma) -1;
1059 /* If this is a weak symbol, and there is a real definition, the
1060 processor independent code will have arranged for us to see the
1061 real definition first, and we can just use the same value. */
1062 if (h->weakdef != NULL)
1064 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1065 || h->weakdef->root.type == bfd_link_hash_defweak);
1066 h->root.u.def.section = h->weakdef->root.u.def.section;
1067 h->root.u.def.value = h->weakdef->root.u.def.value;
1068 return TRUE;
1071 /* This is a reference to a symbol defined by a dynamic object which
1072 is not a function. */
1074 /* If we are creating a shared library, we must presume that the
1075 only references to the symbol are via the global offset table.
1076 For such cases we need not do anything here; the relocations will
1077 be handled correctly by relocate_section. */
1078 if (info->shared)
1079 return TRUE;
1081 /* We must allocate the symbol in our .dynbss section, which will
1082 become part of the .bss section of the executable. There will be
1083 an entry for this symbol in the .dynsym section. The dynamic
1084 object will contain position independent code, so all references
1085 from the dynamic object to this symbol will go through the global
1086 offset table. The dynamic linker will use the .dynsym entry to
1087 determine the address it must put in the global offset table, so
1088 both the dynamic object and the regular object will refer to the
1089 same memory location for the variable. */
1091 s = bfd_get_section_by_name (dynobj, ".dynbss");
1092 BFD_ASSERT (s != NULL);
1094 /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
1095 copy the initial value out of the dynamic object and into the
1096 runtime process image. We need to remember the offset into the
1097 .rela.bss section we are going to use. */
1098 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1100 asection *srel;
1102 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1103 BFD_ASSERT (srel != NULL);
1104 srel->_raw_size += sizeof (Elf32_External_Rela);
1105 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1108 /* We need to figure out the alignment required for this symbol. I
1109 have no idea how ELF linkers handle this. */
1110 power_of_two = bfd_log2 (h->size);
1111 if (power_of_two > 3)
1112 power_of_two = 3;
1114 /* Apply the required alignment. */
1115 s->_raw_size = BFD_ALIGN (s->_raw_size,
1116 (bfd_size_type) (1 << power_of_two));
1117 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1119 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
1120 return FALSE;
1123 /* Define the symbol as being at this point in the section. */
1124 h->root.u.def.section = s;
1125 h->root.u.def.value = s->_raw_size;
1127 /* Increment the section size to make room for the symbol. */
1128 s->_raw_size += h->size;
1130 return TRUE;
1133 /* Set the sizes of the dynamic sections. */
1135 static bfd_boolean
1136 elf_vax_size_dynamic_sections (output_bfd, info)
1137 bfd *output_bfd;
1138 struct bfd_link_info *info;
1140 bfd *dynobj;
1141 asection *s;
1142 bfd_boolean plt;
1143 bfd_boolean relocs;
1144 bfd_boolean reltext;
1146 dynobj = elf_hash_table (info)->dynobj;
1147 BFD_ASSERT (dynobj != NULL);
1149 if (elf_hash_table (info)->dynamic_sections_created)
1151 /* Set the contents of the .interp section to the interpreter. */
1152 if (!info->shared)
1154 s = bfd_get_section_by_name (dynobj, ".interp");
1155 BFD_ASSERT (s != NULL);
1156 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1157 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1160 else
1162 /* We may have created entries in the .rela.got and .got sections.
1163 However, if we are not creating the dynamic sections, we will
1164 not actually use these entries. Reset the size of .rela.got
1165 and .got, which will cause it to get stripped from the output
1166 file below. */
1167 s = bfd_get_section_by_name (dynobj, ".rela.got");
1168 if (s != NULL)
1169 s->_raw_size = 0;
1170 s = bfd_get_section_by_name (dynobj, ".got.plt");
1171 if (s != NULL)
1172 s->_raw_size = 0;
1173 s = bfd_get_section_by_name (dynobj, ".got");
1174 if (s != NULL)
1175 s->_raw_size = 0;
1178 /* If this is a -Bsymbolic shared link, then we need to discard all PC
1179 relative relocs against symbols defined in a regular object. We
1180 allocated space for them in the check_relocs routine, but we will not
1181 fill them in in the relocate_section routine. */
1182 if (info->shared && info->symbolic)
1183 elf_vax_link_hash_traverse (elf_vax_hash_table (info),
1184 elf_vax_discard_copies,
1185 (PTR) NULL);
1187 /* If this is a -Bsymbolic shared link or a static link, we need to
1188 discard all the got entries we've recorded. Otherwise, we need to
1189 instantiate (allocate space for them). */
1190 elf_link_hash_traverse (elf_hash_table (info),
1191 elf_vax_instantiate_got_entries,
1192 (PTR) info);
1194 /* The check_relocs and adjust_dynamic_symbol entry points have
1195 determined the sizes of the various dynamic sections. Allocate
1196 memory for them. */
1197 plt = FALSE;
1198 relocs = FALSE;
1199 reltext = FALSE;
1200 for (s = dynobj->sections; s != NULL; s = s->next)
1202 const char *name;
1203 bfd_boolean strip;
1205 if ((s->flags & SEC_LINKER_CREATED) == 0)
1206 continue;
1208 /* It's OK to base decisions on the section name, because none
1209 of the dynobj section names depend upon the input files. */
1210 name = bfd_get_section_name (dynobj, s);
1212 strip = FALSE;
1214 if (strcmp (name, ".plt") == 0)
1216 if (s->_raw_size == 0)
1218 /* Strip this section if we don't need it; see the
1219 comment below. */
1220 strip = TRUE;
1222 else
1224 /* Remember whether there is a PLT. */
1225 plt = TRUE;
1228 else if (strncmp (name, ".rela", 5) == 0)
1230 if (s->_raw_size == 0)
1232 /* If we don't need this section, strip it from the
1233 output file. This is mostly to handle .rela.bss and
1234 .rela.plt. We must create both sections in
1235 create_dynamic_sections, because they must be created
1236 before the linker maps input sections to output
1237 sections. The linker does that before
1238 adjust_dynamic_symbol is called, and it is that
1239 function which decides whether anything needs to go
1240 into these sections. */
1241 strip = TRUE;
1243 else
1245 asection *target;
1247 /* Remember whether there are any reloc sections other
1248 than .rela.plt. */
1249 if (strcmp (name, ".rela.plt") != 0)
1251 const char *outname;
1253 relocs = TRUE;
1255 /* If this relocation section applies to a read only
1256 section, then we probably need a DT_TEXTREL
1257 entry. .rela.plt is actually associated with
1258 .got.plt, which is never readonly. */
1259 outname = bfd_get_section_name (output_bfd,
1260 s->output_section);
1261 target = bfd_get_section_by_name (output_bfd, outname + 5);
1262 if (target != NULL
1263 && (target->flags & SEC_READONLY) != 0
1264 && (target->flags & SEC_ALLOC) != 0)
1265 reltext = TRUE;
1268 /* We use the reloc_count field as a counter if we need
1269 to copy relocs into the output file. */
1270 s->reloc_count = 0;
1273 else if (strncmp (name, ".got", 4) != 0)
1275 /* It's not one of our sections, so don't allocate space. */
1276 continue;
1279 if (strip)
1281 _bfd_strip_section_from_output (info, s);
1282 continue;
1285 /* Allocate memory for the section contents. */
1286 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1287 if (s->contents == NULL && s->_raw_size != 0)
1288 return FALSE;
1291 if (elf_hash_table (info)->dynamic_sections_created)
1293 /* Add some entries to the .dynamic section. We fill in the
1294 values later, in elf_vax_finish_dynamic_sections, but we
1295 must add the entries now so that we get the correct size for
1296 the .dynamic section. The DT_DEBUG entry is filled in by the
1297 dynamic linker and used by the debugger. */
1298 #define add_dynamic_entry(TAG, VAL) \
1299 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1301 if (!info->shared)
1303 if (!add_dynamic_entry (DT_DEBUG, 0))
1304 return FALSE;
1307 if (plt)
1309 if (!add_dynamic_entry (DT_PLTGOT, 0)
1310 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1311 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1312 || !add_dynamic_entry (DT_JMPREL, 0))
1313 return FALSE;
1316 if (relocs)
1318 if (!add_dynamic_entry (DT_RELA, 0)
1319 || !add_dynamic_entry (DT_RELASZ, 0)
1320 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1321 return FALSE;
1324 if (reltext || (info->flags & DF_TEXTREL) != 0)
1326 if (!add_dynamic_entry (DT_TEXTREL, 0))
1327 return FALSE;
1330 #undef add_dynamic_entry
1332 return TRUE;
1335 /* This function is called via elf_vax_link_hash_traverse if we are
1336 creating a shared object with -Bsymbolic. It discards the space
1337 allocated to copy PC relative relocs against symbols which are defined
1338 in regular objects. We allocated space for them in the check_relocs
1339 routine, but we won't fill them in in the relocate_section routine. */
1341 /*ARGSUSED*/
1342 static bfd_boolean
1343 elf_vax_discard_copies (h, ignore)
1344 struct elf_vax_link_hash_entry *h;
1345 PTR ignore ATTRIBUTE_UNUSED;
1347 struct elf_vax_pcrel_relocs_copied *s;
1349 if (h->root.root.type == bfd_link_hash_warning)
1350 h = (struct elf_vax_link_hash_entry *) h->root.root.u.i.link;
1352 /* We only discard relocs for symbols defined in a regular object. */
1353 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1354 return TRUE;
1356 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1357 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
1359 return TRUE;
1362 /* This function is called via elf_link_hash_traverse. It looks for entries
1363 that have GOT or PLT (.GOT) references. If creating a static object or a
1364 shared object with -Bsymbolic, it resets the reference count back to 0
1365 and sets the offset to -1 so normal PC32 relocation will be done. If
1366 creating a shared object or executable, space in the .got and .rela.got
1367 will be reserved for the symbol. */
1369 /*ARGSUSED*/
1370 static bfd_boolean
1371 elf_vax_instantiate_got_entries (h, infoptr)
1372 struct elf_link_hash_entry *h;
1373 PTR infoptr;
1375 struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
1376 bfd *dynobj;
1377 asection *sgot;
1378 asection *srelgot;
1380 /* We don't care about non-GOT (and non-PLT) entries. */
1381 if (h->got.refcount <= 0 && h->plt.refcount <= 0)
1382 return TRUE;
1384 dynobj = elf_hash_table (info)->dynobj;
1385 if (dynobj == NULL)
1386 return TRUE;
1388 sgot = bfd_get_section_by_name (dynobj, ".got");
1389 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1391 if (!elf_hash_table (info)->dynamic_sections_created
1392 || (info->shared && info->symbolic))
1394 h->got.refcount = 0;
1395 h->got.offset = (bfd_vma) -1;
1396 h->plt.refcount = 0;
1397 h->plt.offset = (bfd_vma) -1;
1399 else if (h->got.refcount > 0)
1401 /* Make sure this symbol is output as a dynamic symbol. */
1402 if (h->dynindx == -1)
1404 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
1405 return FALSE;
1408 /* Allocate space in the .got and .rela.got sections. */
1409 sgot->_raw_size += 4;
1410 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1413 return TRUE;
1416 /* Relocate an VAX ELF section. */
1418 static bfd_boolean
1419 elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
1420 contents, relocs, local_syms, local_sections)
1421 bfd *output_bfd;
1422 struct bfd_link_info *info;
1423 bfd *input_bfd;
1424 asection *input_section;
1425 bfd_byte *contents;
1426 Elf_Internal_Rela *relocs;
1427 Elf_Internal_Sym *local_syms;
1428 asection **local_sections;
1430 bfd *dynobj;
1431 Elf_Internal_Shdr *symtab_hdr;
1432 struct elf_link_hash_entry **sym_hashes;
1433 bfd_vma *local_got_offsets;
1434 bfd_vma plt_index;
1435 bfd_vma got_offset;
1436 asection *sgot;
1437 asection *splt;
1438 asection *sgotplt;
1439 asection *sreloc;
1440 Elf_Internal_Rela *rel;
1441 Elf_Internal_Rela *relend;
1443 if (info->relocatable)
1444 return TRUE;
1446 dynobj = elf_hash_table (info)->dynobj;
1447 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1448 sym_hashes = elf_sym_hashes (input_bfd);
1449 local_got_offsets = elf_local_got_offsets (input_bfd);
1451 sgot = NULL;
1452 splt = NULL;
1453 sgotplt = NULL;
1454 sreloc = NULL;
1456 rel = relocs;
1457 relend = relocs + input_section->reloc_count;
1458 for (; rel < relend; rel++)
1460 int r_type;
1461 reloc_howto_type *howto;
1462 unsigned long r_symndx;
1463 struct elf_link_hash_entry *h;
1464 Elf_Internal_Sym *sym;
1465 asection *sec;
1466 bfd_vma relocation;
1467 bfd_reloc_status_type r;
1469 r_type = ELF32_R_TYPE (rel->r_info);
1470 if (r_type < 0 || r_type >= (int) R_VAX_max)
1472 bfd_set_error (bfd_error_bad_value);
1473 return FALSE;
1475 howto = howto_table + r_type;
1477 /* This is a final link. */
1478 r_symndx = ELF32_R_SYM (rel->r_info);
1479 h = NULL;
1480 sym = NULL;
1481 sec = NULL;
1482 if (r_symndx < symtab_hdr->sh_info)
1484 sym = local_syms + r_symndx;
1485 sec = local_sections[r_symndx];
1486 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
1488 else
1490 bfd_boolean unresolved_reloc;
1491 bfd_boolean warned;
1493 RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx,
1494 symtab_hdr, relocation, sec,
1495 unresolved_reloc, info,
1496 warned);
1498 if ((h->root.type == bfd_link_hash_defined
1499 || h->root.type == bfd_link_hash_defweak)
1500 && ((r_type == R_VAX_PLT32
1501 && h->plt.offset != (bfd_vma) -1
1502 && elf_hash_table (info)->dynamic_sections_created)
1503 || (r_type == R_VAX_GOT32
1504 && strcmp (h->root.root.string,
1505 "_GLOBAL_OFFSET_TABLE_") != 0
1506 && elf_hash_table (info)->dynamic_sections_created
1507 && (! info->shared
1508 || (! info->symbolic && h->dynindx != -1)
1509 || (h->elf_link_hash_flags
1510 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1511 || (info->shared
1512 && ((! info->symbolic && h->dynindx != -1)
1513 || (h->elf_link_hash_flags
1514 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1515 && ((input_section->flags & SEC_ALLOC) != 0
1516 /* DWARF will emit R_VAX_32 relocations in its
1517 sections against symbols defined externally
1518 in shared libraries. We can't do anything
1519 with them here. */
1521 || ((input_section->flags & SEC_DEBUGGING) != 0
1522 && (h->elf_link_hash_flags
1523 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
1524 && (r_type == R_VAX_8
1525 || r_type == R_VAX_16
1526 || r_type == R_VAX_32
1527 || r_type == R_VAX_PC8
1528 || r_type == R_VAX_PC16
1529 || r_type == R_VAX_PC32))))
1530 /* In these cases, we don't need the relocation
1531 value. We check specially because in some
1532 obscure cases sec->output_section will be NULL. */
1533 relocation = 0;
1536 switch (r_type)
1538 case R_VAX_GOT32:
1539 /* Relocation is to the address of the entry for this symbol
1540 in the global offset table. */
1541 if (h == NULL || h->got.offset == (bfd_vma) -1)
1542 break;
1544 /* Relocation is the offset of the entry for this symbol in
1545 the global offset table. */
1548 bfd_vma off;
1550 if (sgot == NULL)
1552 sgot = bfd_get_section_by_name (dynobj, ".got");
1553 BFD_ASSERT (sgot != NULL);
1556 BFD_ASSERT (h != NULL);
1557 off = h->got.offset;
1558 BFD_ASSERT (off != (bfd_vma) -1);
1559 BFD_ASSERT (off < sgot->_raw_size);
1561 if (info->shared
1562 && h->dynindx == -1
1563 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1565 /* The symbol was forced to be local
1566 because of a version file.. We must initialize
1567 this entry in the global offset table. Since
1568 the offset must always be a multiple of 4, we
1569 use the least significant bit to record whether
1570 we have initialized it already.
1572 When doing a dynamic link, we create a .rela.got
1573 relocation entry to initialize the value. This
1574 is done in the finish_dynamic_symbol routine. */
1575 if ((off & 1) != 0)
1576 off &= ~1;
1577 else
1579 bfd_put_32 (output_bfd, relocation + rel->r_addend,
1580 sgot->contents + off);
1581 h->got.offset |= 1;
1583 } else {
1584 bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off);
1587 relocation = sgot->output_offset + off;
1588 /* The GOT relocation uses the addend. */
1589 rel->r_addend = 0;
1591 /* Change the reference to be indirect. */
1592 contents[rel->r_offset - 1] |= 0x10;
1593 relocation += sgot->output_section->vma;
1595 break;
1597 case R_VAX_PLT32:
1598 /* Relocation is to the entry for this symbol in the
1599 procedure linkage table. */
1601 /* Resolve a PLTxx reloc against a local symbol directly,
1602 without using the procedure linkage table. */
1603 if (h == NULL)
1604 break;
1606 if (h->plt.offset == (bfd_vma) -1
1607 || !elf_hash_table (info)->dynamic_sections_created)
1609 /* We didn't make a PLT entry for this symbol. This
1610 happens when statically linking PIC code, or when
1611 using -Bsymbolic. */
1612 break;
1615 if (splt == NULL)
1617 splt = bfd_get_section_by_name (dynobj, ".plt");
1618 BFD_ASSERT (splt != NULL);
1621 if (sgotplt == NULL)
1623 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1624 BFD_ASSERT (splt != NULL);
1627 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1629 /* Get the offset into the .got table of the entry that
1630 corresponds to this function. Each .got entry is 4 bytes.
1631 The first two are reserved. */
1632 got_offset = (plt_index + 3) * 4;
1634 /* We want the relocate to point into the .got.plt instead
1635 of the plt itself. */
1636 relocation = (sgotplt->output_section->vma
1637 + sgotplt->output_offset
1638 + got_offset);
1639 contents[rel->r_offset-1] |= 0x10; /* make indirect */
1640 if (rel->r_addend == 2)
1642 h->plt.offset |= 1;
1644 else if (rel->r_addend != 0)
1645 (*_bfd_error_handler)
1646 (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"),
1647 bfd_get_filename (input_bfd), rel->r_addend,
1648 h->root.root.string,
1649 bfd_get_section_name (input_bfd, input_section));
1650 rel->r_addend = 0;
1652 break;
1654 case R_VAX_PC8:
1655 case R_VAX_PC16:
1656 case R_VAX_PC32:
1657 if (h == NULL)
1658 break;
1659 /* Fall through. */
1660 case R_VAX_8:
1661 case R_VAX_16:
1662 case R_VAX_32:
1663 if (info->shared
1664 && r_symndx != 0
1665 && (input_section->flags & SEC_ALLOC) != 0
1666 && ((r_type != R_VAX_PC8
1667 && r_type != R_VAX_PC16
1668 && r_type != R_VAX_PC32)
1669 || (!info->symbolic
1670 || (h->elf_link_hash_flags
1671 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
1673 Elf_Internal_Rela outrel;
1674 bfd_byte *loc;
1675 bfd_boolean skip, relocate;
1677 /* When generating a shared object, these relocations
1678 are copied into the output file to be resolved at run
1679 time. */
1680 if (sreloc == NULL)
1682 const char *name;
1684 name = (bfd_elf_string_from_elf_section
1685 (input_bfd,
1686 elf_elfheader (input_bfd)->e_shstrndx,
1687 elf_section_data (input_section)->rel_hdr.sh_name));
1688 if (name == NULL)
1689 return FALSE;
1691 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1692 && strcmp (bfd_get_section_name (input_bfd,
1693 input_section),
1694 name + 5) == 0);
1696 sreloc = bfd_get_section_by_name (dynobj, name);
1697 BFD_ASSERT (sreloc != NULL);
1700 skip = FALSE;
1701 relocate = FALSE;
1703 outrel.r_offset =
1704 _bfd_elf_section_offset (output_bfd, info, input_section,
1705 rel->r_offset);
1706 if (outrel.r_offset == (bfd_vma) -1)
1707 skip = TRUE;
1708 if (outrel.r_offset == (bfd_vma) -2)
1709 skip = TRUE, relocate = TRUE;
1710 outrel.r_offset += (input_section->output_section->vma
1711 + input_section->output_offset);
1713 if (skip)
1714 memset (&outrel, 0, sizeof outrel);
1715 /* h->dynindx may be -1 if the symbol was marked to
1716 become local. */
1717 else if (h != NULL
1718 && ((! info->symbolic && h->dynindx != -1)
1719 || (h->elf_link_hash_flags
1720 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1722 BFD_ASSERT (h->dynindx != -1);
1723 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1724 outrel.r_addend = relocation + rel->r_addend;
1726 else
1728 if (r_type == R_VAX_32)
1730 relocate = TRUE;
1731 outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1732 BFD_ASSERT (bfd_get_signed_32 (input_bfd,
1733 &contents[rel->r_offset]) == 0);
1734 outrel.r_addend = relocation + rel->r_addend;
1736 else
1738 long indx;
1740 if (h == NULL)
1741 sec = local_sections[r_symndx];
1742 else
1744 BFD_ASSERT (h->root.type == bfd_link_hash_defined
1745 || (h->root.type
1746 == bfd_link_hash_defweak));
1747 sec = h->root.u.def.section;
1749 if (sec != NULL && bfd_is_abs_section (sec))
1750 indx = 0;
1751 else if (sec == NULL || sec->owner == NULL)
1753 bfd_set_error (bfd_error_bad_value);
1754 return FALSE;
1756 else
1758 asection *osec;
1760 osec = sec->output_section;
1761 indx = elf_section_data (osec)->dynindx;
1762 BFD_ASSERT (indx > 0);
1765 outrel.r_info = ELF32_R_INFO (indx, r_type);
1766 outrel.r_addend = relocation + rel->r_addend;
1770 if (!strcmp (bfd_get_section_name (input_bfd, input_section),
1771 ".text") != 0 ||
1772 (info->shared
1773 && ELF32_R_TYPE(outrel.r_info) != R_VAX_32
1774 && ELF32_R_TYPE(outrel.r_info) != R_VAX_RELATIVE
1775 && ELF32_R_TYPE(outrel.r_info) != R_VAX_COPY
1776 && ELF32_R_TYPE(outrel.r_info) != R_VAX_JMP_SLOT
1777 && ELF32_R_TYPE(outrel.r_info) != R_VAX_GLOB_DAT))
1779 if (h != NULL)
1780 (*_bfd_error_handler)
1781 (_("%s: warning: %s relocation against symbol `%s' from %s section"),
1782 bfd_get_filename (input_bfd), howto->name,
1783 h->root.root.string,
1784 bfd_get_section_name (input_bfd, input_section));
1785 else
1786 (*_bfd_error_handler)
1787 (_("%s: warning: %s relocation to 0x%x from %s section"),
1788 bfd_get_filename (input_bfd), howto->name,
1789 outrel.r_addend,
1790 bfd_get_section_name (input_bfd, input_section));
1792 loc = sreloc->contents;
1793 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1794 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1796 /* This reloc will be computed at runtime, so there's no
1797 need to do anything now, except for R_VAX_32
1798 relocations that have been turned into
1799 R_VAX_RELATIVE. */
1800 if (!relocate)
1801 continue;
1804 break;
1806 case R_VAX_GNU_VTINHERIT:
1807 case R_VAX_GNU_VTENTRY:
1808 /* These are no-ops in the end. */
1809 continue;
1811 default:
1812 break;
1815 /* VAX PCREL relocations are from the end of relocation, not the start.
1816 So subtract the difference from the relocation amount since we can't
1817 add it to the offset. */
1818 if (howto->pc_relative && howto->pcrel_offset)
1819 relocation -= bfd_get_reloc_size(howto);
1821 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1822 contents, rel->r_offset,
1823 relocation, rel->r_addend);
1825 if (r != bfd_reloc_ok)
1827 switch (r)
1829 default:
1830 case bfd_reloc_outofrange:
1831 abort ();
1832 case bfd_reloc_overflow:
1834 const char *name;
1836 if (h != NULL)
1837 name = h->root.root.string;
1838 else
1840 name = bfd_elf_string_from_elf_section (input_bfd,
1841 symtab_hdr->sh_link,
1842 sym->st_name);
1843 if (name == NULL)
1844 return FALSE;
1845 if (*name == '\0')
1846 name = bfd_section_name (input_bfd, sec);
1848 if (!(info->callbacks->reloc_overflow
1849 (info, name, howto->name, (bfd_vma) 0,
1850 input_bfd, input_section, rel->r_offset)))
1851 return FALSE;
1853 break;
1858 return TRUE;
1861 /* Finish up dynamic symbol handling. We set the contents of various
1862 dynamic sections here. */
1864 static bfd_boolean
1865 elf_vax_finish_dynamic_symbol (output_bfd, info, h, sym)
1866 bfd *output_bfd;
1867 struct bfd_link_info *info;
1868 struct elf_link_hash_entry *h;
1869 Elf_Internal_Sym *sym;
1871 bfd *dynobj;
1873 dynobj = elf_hash_table (info)->dynobj;
1875 if (h->plt.offset != (bfd_vma) -1)
1877 asection *splt;
1878 asection *sgot;
1879 asection *srela;
1880 bfd_vma plt_index;
1881 bfd_vma got_offset;
1882 bfd_vma addend;
1883 Elf_Internal_Rela rela;
1884 bfd_byte *loc;
1886 /* This symbol has an entry in the procedure linkage table. Set
1887 it up. */
1888 BFD_ASSERT (h->dynindx != -1);
1890 splt = bfd_get_section_by_name (dynobj, ".plt");
1891 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1892 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1893 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1895 addend = 2 * (h->plt.offset & 1);
1896 h->plt.offset &= ~1;
1898 /* Get the index in the procedure linkage table which
1899 corresponds to this symbol. This is the index of this symbol
1900 in all the symbols for which we are making plt entries. The
1901 first entry in the procedure linkage table is reserved. */
1902 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1904 /* Get the offset into the .got table of the entry that
1905 corresponds to this function. Each .got entry is 4 bytes.
1906 The first two are reserved. */
1907 got_offset = (plt_index + 3) * 4;
1909 /* Fill in the entry in the procedure linkage table. */
1910 memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
1911 PLT_ENTRY_SIZE);
1913 /* The offset is relative to the first extension word. */
1914 bfd_put_32 (output_bfd,
1915 -(h->plt.offset + 8),
1916 splt->contents + h->plt.offset + 4);
1918 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
1919 splt->contents + h->plt.offset + 8);
1921 /* Fill in the entry in the global offset table. */
1922 bfd_put_32 (output_bfd,
1923 (splt->output_section->vma
1924 + splt->output_offset
1925 + h->plt.offset) + addend,
1926 sgot->contents + got_offset);
1928 /* Fill in the entry in the .rela.plt section. */
1929 rela.r_offset = (sgot->output_section->vma
1930 + sgot->output_offset
1931 + got_offset);
1932 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
1933 rela.r_addend = addend;
1934 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
1935 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1937 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1939 /* Mark the symbol as undefined, rather than as defined in
1940 the .plt section. Leave the value alone. */
1941 sym->st_shndx = SHN_UNDEF;
1945 if (h->got.offset != (bfd_vma) -1)
1947 asection *sgot;
1948 asection *srela;
1949 Elf_Internal_Rela rela;
1950 bfd_byte *loc;
1952 /* This symbol has an entry in the global offset table. Set it
1953 up. */
1954 sgot = bfd_get_section_by_name (dynobj, ".got");
1955 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1956 BFD_ASSERT (sgot != NULL && srela != NULL);
1958 rela.r_offset = (sgot->output_section->vma
1959 + sgot->output_offset
1960 + (h->got.offset &~ 1));
1962 /* If the symbol was forced to be local because of a version file
1963 locally we just want to emit a RELATIVE reloc. The entry in
1964 the global offset table will already have been initialized in
1965 the relocate_section function. */
1966 if (info->shared
1967 && h->dynindx == -1
1968 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1970 rela.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1972 else
1974 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
1976 rela.r_addend = bfd_get_signed_32 (output_bfd,
1977 (sgot->contents
1978 + (h->got.offset & ~1)));
1980 loc = srela->contents;
1981 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
1982 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
1985 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1987 asection *s;
1988 Elf_Internal_Rela rela;
1989 bfd_byte *loc;
1991 /* This symbol needs a copy reloc. Set it up. */
1992 BFD_ASSERT (h->dynindx != -1
1993 && (h->root.type == bfd_link_hash_defined
1994 || h->root.type == bfd_link_hash_defweak));
1996 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1997 ".rela.bss");
1998 BFD_ASSERT (s != NULL);
2000 rela.r_offset = (h->root.u.def.value
2001 + h->root.u.def.section->output_section->vma
2002 + h->root.u.def.section->output_offset);
2003 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
2004 rela.r_addend = 0;
2005 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
2006 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2009 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2010 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2011 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2012 sym->st_shndx = SHN_ABS;
2014 return TRUE;
2017 /* Finish up the dynamic sections. */
2019 static bfd_boolean
2020 elf_vax_finish_dynamic_sections (output_bfd, info)
2021 bfd *output_bfd;
2022 struct bfd_link_info *info;
2024 bfd *dynobj;
2025 asection *sgot;
2026 asection *sdyn;
2028 dynobj = elf_hash_table (info)->dynobj;
2030 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
2031 BFD_ASSERT (sgot != NULL);
2032 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2034 if (elf_hash_table (info)->dynamic_sections_created)
2036 asection *splt;
2037 Elf32_External_Dyn *dyncon, *dynconend;
2039 splt = bfd_get_section_by_name (dynobj, ".plt");
2040 BFD_ASSERT (splt != NULL && sdyn != NULL);
2042 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2043 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2044 for (; dyncon < dynconend; dyncon++)
2046 Elf_Internal_Dyn dyn;
2047 const char *name;
2048 asection *s;
2050 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2052 switch (dyn.d_tag)
2054 default:
2055 break;
2057 case DT_PLTGOT:
2058 name = ".got";
2059 goto get_vma;
2060 case DT_JMPREL:
2061 name = ".rela.plt";
2062 get_vma:
2063 s = bfd_get_section_by_name (output_bfd, name);
2064 BFD_ASSERT (s != NULL);
2065 dyn.d_un.d_ptr = s->vma;
2066 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2067 break;
2069 case DT_PLTRELSZ:
2070 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2071 BFD_ASSERT (s != NULL);
2072 if (s->_cooked_size != 0)
2073 dyn.d_un.d_val = s->_cooked_size;
2074 else
2075 dyn.d_un.d_val = s->_raw_size;
2076 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2077 break;
2079 case DT_RELASZ:
2080 /* The procedure linkage table relocs (DT_JMPREL) should
2081 not be included in the overall relocs (DT_RELA).
2082 Therefore, we override the DT_RELASZ entry here to
2083 make it not include the JMPREL relocs. Since the
2084 linker script arranges for .rela.plt to follow all
2085 other relocation sections, we don't have to worry
2086 about changing the DT_RELA entry. */
2087 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2088 if (s != NULL)
2090 if (s->_cooked_size != 0)
2091 dyn.d_un.d_val -= s->_cooked_size;
2092 else
2093 dyn.d_un.d_val -= s->_raw_size;
2095 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2096 break;
2100 /* Fill in the first entry in the procedure linkage table. */
2101 if (splt->_raw_size > 0)
2103 memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
2104 bfd_put_32 (output_bfd,
2105 (sgot->output_section->vma
2106 + sgot->output_offset + 4
2107 - (splt->output_section->vma + 6)),
2108 splt->contents + 2);
2109 bfd_put_32 (output_bfd,
2110 (sgot->output_section->vma
2111 + sgot->output_offset + 8
2112 - (splt->output_section->vma + 12)),
2113 splt->contents + 8);
2114 elf_section_data (splt->output_section)->this_hdr.sh_entsize
2115 = PLT_ENTRY_SIZE;
2119 /* Fill in the first three entries in the global offset table. */
2120 if (sgot->_raw_size > 0)
2122 if (sdyn == NULL)
2123 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2124 else
2125 bfd_put_32 (output_bfd,
2126 sdyn->output_section->vma + sdyn->output_offset,
2127 sgot->contents);
2128 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
2129 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
2132 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2134 return TRUE;
2137 #define TARGET_LITTLE_SYM bfd_elf32_vax_vec
2138 #define TARGET_LITTLE_NAME "elf32-vax"
2139 #define ELF_MACHINE_CODE EM_VAX
2140 #define ELF_MAXPAGESIZE 0x1000
2142 #define elf_backend_create_dynamic_sections \
2143 _bfd_elf_create_dynamic_sections
2144 #define bfd_elf32_bfd_link_hash_table_create \
2145 elf_vax_link_hash_table_create
2146 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
2148 #define elf_backend_check_relocs elf_vax_check_relocs
2149 #define elf_backend_adjust_dynamic_symbol \
2150 elf_vax_adjust_dynamic_symbol
2151 #define elf_backend_size_dynamic_sections \
2152 elf_vax_size_dynamic_sections
2153 #define elf_backend_relocate_section elf_vax_relocate_section
2154 #define elf_backend_finish_dynamic_symbol \
2155 elf_vax_finish_dynamic_symbol
2156 #define elf_backend_finish_dynamic_sections \
2157 elf_vax_finish_dynamic_sections
2158 #define elf_backend_gc_mark_hook elf_vax_gc_mark_hook
2159 #define elf_backend_gc_sweep_hook elf_vax_gc_sweep_hook
2160 #define bfd_elf32_bfd_merge_private_bfd_data \
2161 elf32_vax_merge_private_bfd_data
2162 #define bfd_elf32_bfd_set_private_flags \
2163 elf32_vax_set_private_flags
2164 #define bfd_elf32_bfd_print_private_bfd_data \
2165 elf32_vax_print_private_bfd_data
2167 #define elf_backend_can_gc_sections 1
2168 #define elf_backend_want_got_plt 1
2169 #define elf_backend_plt_readonly 1
2170 #define elf_backend_want_plt_sym 0
2171 #define elf_backend_got_header_size 16
2172 #define elf_backend_rela_normal 1
2174 #include "elf32-target.h"