* elf-hppa.h (elf_hppa_relocate_section): If relocatable, return
[deliverable/binutils-gdb.git] / bfd / elf32-vax.c
CommitLineData
90ace9e9
JT
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>.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
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"
28
29static reloc_howto_type *reloc_type_lookup
30 PARAMS ((bfd *, bfd_reloc_code_real_type));
31static void rtype_to_howto
32 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
33static struct bfd_hash_entry *elf_vax_link_hash_newfunc
34 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
35static struct bfd_link_hash_table *elf_vax_link_hash_table_create
36 PARAMS ((bfd *));
37static boolean elf_vax_check_relocs
38 PARAMS ((bfd *, struct bfd_link_info *, asection *,
39 const Elf_Internal_Rela *));
40static asection *elf_vax_gc_mark_hook
1e2f5b6e 41 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
90ace9e9
JT
42 struct elf_link_hash_entry *, Elf_Internal_Sym *));
43static boolean elf_vax_gc_sweep_hook
44 PARAMS ((bfd *, struct bfd_link_info *, asection *,
45 const Elf_Internal_Rela *));
46static boolean elf_vax_adjust_dynamic_symbol
47 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
48static boolean elf_vax_size_dynamic_sections
49 PARAMS ((bfd *, struct bfd_link_info *));
50static boolean elf_vax_relocate_section
51 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
52 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
53static boolean elf_vax_finish_dynamic_symbol
54 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
55 Elf_Internal_Sym *));
56static boolean elf_vax_finish_dynamic_sections
57 PARAMS ((bfd *, struct bfd_link_info *));
58
59static boolean elf32_vax_set_private_flags
60 PARAMS ((bfd *, flagword));
61static boolean elf32_vax_merge_private_bfd_data
62 PARAMS ((bfd *, bfd *));
63static boolean elf32_vax_print_private_bfd_data
64 PARAMS ((bfd *, PTR));
65
66static 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 */
80
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 */
94
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 */
108
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 */
122
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 */
136
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 */
150
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 */
164
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 */
178
179 EMPTY_HOWTO (-1),
180 EMPTY_HOWTO (-1),
181 EMPTY_HOWTO (-1),
182 EMPTY_HOWTO (-1),
183 EMPTY_HOWTO (-1),
184
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 */
198
199 EMPTY_HOWTO (-1),
200 EMPTY_HOWTO (-1),
201 EMPTY_HOWTO (-1),
202 EMPTY_HOWTO (-1),
203 EMPTY_HOWTO (-1),
204
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 */
218
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 */
232
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 */
246
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 */
260
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 */
275
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 */
290};
291
292static void
293rtype_to_howto (abfd, cache_ptr, dst)
294 bfd *abfd ATTRIBUTE_UNUSED;
295 arelent *cache_ptr;
296 Elf_Internal_Rela *dst;
297{
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)];
300}
301
302#define elf_info_to_howto rtype_to_howto
303
304static const struct
305{
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 },
325};
326
327static reloc_howto_type *
328reloc_type_lookup (abfd, code)
329 bfd *abfd ATTRIBUTE_UNUSED;
330 bfd_reloc_code_real_type code;
331{
332 unsigned int i;
333 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
334 {
335 if (reloc_map[i].bfd_val == code)
336 return &howto_table[reloc_map[i].elf_val];
337 }
338 return 0;
339}
340
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 */
90ace9e9
JT
344\f
345/* Functions for the VAX ELF linker. */
346
347/* The name of the dynamic interpreter. This is put in the .interp
348 section. */
349
350#define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
351
352/* The size in bytes of an entry in the procedure linkage table. */
353
354#define PLT_ENTRY_SIZE 12
355
356/* The first entry in a procedure linkage table looks like this. See
357 the SVR4 ABI VAX supplement to see how this works. */
358
359static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
360{
361 0xdd, 0xef, /* pushl l^ */
362 0, 0, 0, 0, /* offset to .plt.got + 4 */
363 0x17, 0xff, /* jmp @L^(pc) */
364 0, 0, 0, 0, /* offset to .plt.got + 8 */
365};
366
367/* Subsequent entries in a procedure linkage table look like this. */
368
369static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
370{
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 */
375};
376
377/* The VAX linker needs to keep track of the number of relocs that it
378 decides to copy in check_relocs for each symbol. This is so that it
379 can discard PC relative relocs if it doesn't need them when linking
380 with -Bsymbolic. We store the information in a field extending the
381 regular ELF linker hash table. */
382
383/* This structure keeps track of the number of PC relative relocs we have
384 copied for a given symbol. */
385
386struct elf_vax_pcrel_relocs_copied
387{
388 /* Next section. */
389 struct elf_vax_pcrel_relocs_copied *next;
390 /* A section in dynobj. */
391 asection *section;
392 /* Number of relocs copied in this section. */
393 bfd_size_type count;
394};
395
396/* VAX ELF linker hash entry. */
397
398struct elf_vax_link_hash_entry
399{
400 struct elf_link_hash_entry root;
401
402 /* Number of PC relative relocs copied for this symbol. */
403 struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
404
405 bfd_vma got_addend;
406};
407
408/* VAX ELF linker hash table. */
409
410struct elf_vax_link_hash_table
411{
412 struct elf_link_hash_table root;
413};
414
415/* Declare this now that the above structures are defined. */
416
417static boolean elf_vax_discard_copies
418 PARAMS ((struct elf_vax_link_hash_entry *, PTR));
419
420/* Traverse an VAX ELF linker hash table. */
421
422#define elf_vax_link_hash_traverse(table, func, info) \
423 (elf_link_hash_traverse \
424 (&(table)->root, \
425 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
426 (info)))
427
428/* Get the VAX ELF linker hash table from a link_info structure. */
429
430#define elf_vax_hash_table(p) \
431 ((struct elf_vax_link_hash_table *) (p)->hash)
432
433/* Create an entry in an VAX ELF linker hash table. */
434
435static struct bfd_hash_entry *
436elf_vax_link_hash_newfunc (entry, table, string)
437 struct bfd_hash_entry *entry;
438 struct bfd_hash_table *table;
439 const char *string;
440{
441 struct elf_vax_link_hash_entry *ret =
442 (struct elf_vax_link_hash_entry *) entry;
443
444 /* Allocate the structure if it has not already been allocated by a
445 subclass. */
446 if (ret == (struct elf_vax_link_hash_entry *) NULL)
447 ret = ((struct elf_vax_link_hash_entry *)
448 bfd_hash_allocate (table,
449 sizeof (struct elf_vax_link_hash_entry)));
450 if (ret == (struct elf_vax_link_hash_entry *) NULL)
451 return (struct bfd_hash_entry *) ret;
452
453 /* Call the allocation method of the superclass. */
454 ret = ((struct elf_vax_link_hash_entry *)
455 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
456 table, string));
457 if (ret != (struct elf_vax_link_hash_entry *) NULL)
458 {
459 ret->pcrel_relocs_copied = NULL;
460 }
461
462 return (struct bfd_hash_entry *) ret;
463}
464
465/* Create an VAX ELF linker hash table. */
466
467static struct bfd_link_hash_table *
468elf_vax_link_hash_table_create (abfd)
469 bfd *abfd;
470{
471 struct elf_vax_link_hash_table *ret;
472 bfd_size_type amt = sizeof (struct elf_vax_link_hash_table);
473
474 ret = (struct elf_vax_link_hash_table *) bfd_malloc (amt);
475 if (ret == (struct elf_vax_link_hash_table *) NULL)
476 return NULL;
477
478 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
479 elf_vax_link_hash_newfunc))
480 {
481 free (ret);
482 return NULL;
483 }
484
485 return &ret->root.root;
486}
487
488/* Keep vax-specific flags in the ELF header */
489static boolean
490elf32_vax_set_private_flags (abfd, flags)
491 bfd *abfd;
492 flagword flags;
493{
494 elf_elfheader (abfd)->e_flags = flags;
495 elf_flags_init (abfd) = true;
496 return true;
497}
498
499/* Merge backend specific data from an object file to the output
500 object file when linking. */
501static boolean
502elf32_vax_merge_private_bfd_data (ibfd, obfd)
503 bfd *ibfd;
504 bfd *obfd;
505{
506 flagword out_flags;
507 flagword in_flags;
508
509 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
510 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
511 return true;
512
513 in_flags = elf_elfheader (ibfd)->e_flags;
514 out_flags = elf_elfheader (obfd)->e_flags;
515
516 if (!elf_flags_init (obfd))
517 {
518 elf_flags_init (obfd) = true;
519 elf_elfheader (obfd)->e_flags = in_flags;
520 }
521
522 return true;
523}
524
525/* Display the flags field */
526static boolean
527elf32_vax_print_private_bfd_data (abfd, ptr)
528 bfd *abfd;
529 PTR ptr;
530{
531 FILE *file = (FILE *) ptr;
532
533 BFD_ASSERT (abfd != NULL && ptr != NULL);
534
535 /* Print normal ELF private data. */
536 _bfd_elf_print_private_bfd_data (abfd, ptr);
537
538 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
539
540 /* xgettext:c-format */
541 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
542
179d3252 543 if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
90ace9e9
JT
544 fprintf (file, _(" [nonpic]"));
545
179d3252 546 if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
90ace9e9
JT
547 fprintf (file, _(" [d-float]"));
548
179d3252 549 if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
90ace9e9
JT
550 fprintf (file, _(" [g-float]"));
551
552 fputc ('\n', file);
553
554 return true;
555}
556/* Look through the relocs for a section during the first phase, and
557 allocate space in the global offset table or procedure linkage
558 table. */
559
560static boolean
561elf_vax_check_relocs (abfd, info, sec, relocs)
562 bfd *abfd;
563 struct bfd_link_info *info;
564 asection *sec;
565 const Elf_Internal_Rela *relocs;
566{
567 bfd *dynobj;
568 Elf_Internal_Shdr *symtab_hdr;
569 struct elf_link_hash_entry **sym_hashes;
570 bfd_signed_vma *local_got_refcounts;
571 const Elf_Internal_Rela *rel;
572 const Elf_Internal_Rela *rel_end;
573 asection *sgot;
574 asection *srelgot;
575 asection *sreloc;
576
577 if (info->relocateable)
578 return true;
579
580 dynobj = elf_hash_table (info)->dynobj;
581 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
582 sym_hashes = elf_sym_hashes (abfd);
583 local_got_refcounts = elf_local_got_refcounts (abfd);
584
585 sgot = NULL;
586 srelgot = NULL;
587 sreloc = NULL;
588
589 rel_end = relocs + sec->reloc_count;
590 for (rel = relocs; rel < rel_end; rel++)
591 {
592 unsigned long r_symndx;
593 struct elf_link_hash_entry *h;
594
595 r_symndx = ELF32_R_SYM (rel->r_info);
596
597 if (r_symndx < symtab_hdr->sh_info)
598 h = NULL;
599 else
600 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
601
602 switch (ELF32_R_TYPE (rel->r_info))
603 {
604 case R_VAX_GOT32:
605 if (h != NULL
606 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
607 break;
608
609 /* This symbol requires a global offset table entry. */
610
611 if (dynobj == NULL)
612 {
613 /* Create the .got section. */
614 elf_hash_table (info)->dynobj = dynobj = abfd;
615 if (!_bfd_elf_create_got_section (dynobj, info))
616 return false;
617 }
618
619 if (sgot == NULL)
620 {
621 sgot = bfd_get_section_by_name (dynobj, ".got");
622 BFD_ASSERT (sgot != NULL);
623 }
624
625 if (srelgot == NULL
626 && (h != NULL || info->shared))
627 {
628 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
629 if (srelgot == NULL)
630 {
631 srelgot = bfd_make_section (dynobj, ".rela.got");
632 if (srelgot == NULL
633 || !bfd_set_section_flags (dynobj, srelgot,
634 (SEC_ALLOC
635 | SEC_LOAD
636 | SEC_HAS_CONTENTS
637 | SEC_IN_MEMORY
638 | SEC_LINKER_CREATED
639 | SEC_READONLY))
640 || !bfd_set_section_alignment (dynobj, srelgot, 2))
641 return false;
642 }
643 }
644
645 if (h != NULL)
646 {
647 struct elf_vax_link_hash_entry *eh;
648
649 eh = (struct elf_vax_link_hash_entry *) h;
650 if (h->got.refcount == -1)
651 {
652 h->got.refcount = 1;
653 eh->got_addend = rel->r_addend;
654
655 /* Make sure this symbol is output as a dynamic symbol. */
656 if (h->dynindx == -1)
657 {
658 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
659 return false;
660 }
661
662 /* Allocate space in the .got section. */
663 sgot->_raw_size += 4;
664 /* Allocate relocation space. */
665 srelgot->_raw_size += sizeof (Elf32_External_Rela);
666 }
667 else
668 {
669 h->got.refcount++;
670 if (eh->got_addend != (bfd_vma) rel->r_addend)
671 (*_bfd_error_handler)
672 (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
673 bfd_get_filename (abfd), rel->r_addend,
674 h->root.root.string,
675 eh->got_addend);
cedb70c5 676
90ace9e9
JT
677 }
678 }
679 break;
680
681 case R_VAX_PLT32:
682 /* This symbol requires a procedure linkage table entry. We
683 actually build the entry in adjust_dynamic_symbol,
684 because this might be a case of linking PIC code which is
685 never referenced by a dynamic object, in which case we
686 don't need to generate a procedure linkage table entry
687 after all. */
688
689 /* If this is a local symbol, we resolve it directly without
690 creating a procedure linkage table entry. */
691 if (h == NULL)
692 continue;
693
694 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
695 if (h->plt.refcount == -1)
696 h->plt.refcount = 1;
697 else
698 h->plt.refcount++;
699 break;
700
701 case R_VAX_PC8:
702 case R_VAX_PC16:
703 case R_VAX_PC32:
704 /* If we are creating a shared library and this is not a local
705 symbol, we need to copy the reloc into the shared library.
706 However when linking with -Bsymbolic and this is a global
707 symbol which is defined in an object we are including in the
708 link (i.e., DEF_REGULAR is set), then we can resolve the
709 reloc directly. At this point we have not seen all the input
710 files, so it is possible that DEF_REGULAR is not set now but
711 will be set later (it is never cleared). We account for that
712 possibility below by storing information in the
713 pcrel_relocs_copied field of the hash table entry. */
714 if (!(info->shared
715 && (sec->flags & SEC_ALLOC) != 0
716 && h != NULL
717 && (!info->symbolic
718 || (h->elf_link_hash_flags
719 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
720 {
721 if (h != NULL)
722 {
723 /* Make sure a plt entry is created for this symbol if
724 it turns out to be a function defined by a dynamic
725 object. */
726 if (h->plt.refcount == -1)
727 h->plt.refcount = 1;
728 else
729 h->plt.refcount++;
730 }
731 break;
732 }
733 /* Fall through. */
734 case R_VAX_8:
735 case R_VAX_16:
736 case R_VAX_32:
737 if (h != NULL)
738 {
739 /* Make sure a plt entry is created for this symbol if it
740 turns out to be a function defined by a dynamic object. */
741 if (h->plt.refcount == -1)
742 h->plt.refcount = 1;
743 else
744 h->plt.refcount++;
745 }
746
747 /* If we are creating a shared library, we need to copy the
748 reloc into the shared library. */
749 if (info->shared
750 && (sec->flags & SEC_ALLOC) != 0)
751 {
752 /* When creating a shared object, we must copy these
753 reloc types into the output file. We create a reloc
754 section in dynobj and make room for this reloc. */
755 if (sreloc == NULL)
756 {
757 const char *name;
758
759 name = (bfd_elf_string_from_elf_section
760 (abfd,
761 elf_elfheader (abfd)->e_shstrndx,
762 elf_section_data (sec)->rel_hdr.sh_name));
763 if (name == NULL)
764 return false;
765
766 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
767 && strcmp (bfd_get_section_name (abfd, sec),
768 name + 5) == 0);
769
770 sreloc = bfd_get_section_by_name (dynobj, name);
771 if (sreloc == NULL)
772 {
773 sreloc = bfd_make_section (dynobj, name);
774 if (sreloc == NULL
775 || !bfd_set_section_flags (dynobj, sreloc,
776 (SEC_ALLOC
777 | SEC_LOAD
778 | SEC_HAS_CONTENTS
779 | SEC_IN_MEMORY
780 | SEC_LINKER_CREATED
781 | SEC_READONLY))
782 || !bfd_set_section_alignment (dynobj, sreloc, 2))
783 return false;
784 }
785 if (sec->flags & SEC_READONLY)
786 info->flags |= DF_TEXTREL;
787 }
788
789 sreloc->_raw_size += sizeof (Elf32_External_Rela);
790
791 /* If we are linking with -Bsymbolic, we count the number of
792 PC relative relocations we have entered for this symbol,
793 so that we can discard them again if the symbol is later
794 defined by a regular object. Note that this function is
795 only called if we are using an vaxelf linker hash table,
796 which means that h is really a pointer to an
797 elf_vax_link_hash_entry. */
798 if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
799 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
800 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
801 && info->symbolic)
802 {
803 struct elf_vax_link_hash_entry *eh;
804 struct elf_vax_pcrel_relocs_copied *p;
805
806 eh = (struct elf_vax_link_hash_entry *) h;
807
808 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
809 if (p->section == sreloc)
810 break;
811
812 if (p == NULL)
813 {
814 p = ((struct elf_vax_pcrel_relocs_copied *)
815 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
816 if (p == NULL)
817 return false;
818 p->next = eh->pcrel_relocs_copied;
819 eh->pcrel_relocs_copied = p;
820 p->section = sreloc;
821 p->count = 0;
822 }
823
824 ++p->count;
825 }
826 }
827
828 break;
829
830 /* This relocation describes the C++ object vtable hierarchy.
831 Reconstruct it for later use during GC. */
832 case R_VAX_GNU_VTINHERIT:
833 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
834 return false;
835 break;
836
837 /* This relocation describes which C++ vtable entries are actually
838 used. Record for later use during GC. */
839 case R_VAX_GNU_VTENTRY:
840 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
841 return false;
842 break;
843
844 default:
845 break;
846 }
847 }
848
849 return true;
850}
851
852/* Return the section that should be marked against GC for a given
853 relocation. */
854
855static asection *
1e2f5b6e
AM
856elf_vax_gc_mark_hook (sec, info, rel, h, sym)
857 asection *sec;
90ace9e9
JT
858 struct bfd_link_info *info ATTRIBUTE_UNUSED;
859 Elf_Internal_Rela *rel;
860 struct elf_link_hash_entry *h;
861 Elf_Internal_Sym *sym;
862{
863 if (h != NULL)
864 {
865 switch (ELF32_R_TYPE (rel->r_info))
866 {
867 case R_VAX_GNU_VTINHERIT:
868 case R_VAX_GNU_VTENTRY:
869 break;
870
871 default:
872 switch (h->root.type)
873 {
874 default:
875 break;
876
877 case bfd_link_hash_defined:
878 case bfd_link_hash_defweak:
879 return h->root.u.def.section;
880
881 case bfd_link_hash_common:
882 return h->root.u.c.p->section;
883 }
884 }
885 }
886 else
1e2f5b6e 887 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
90ace9e9
JT
888
889 return NULL;
890}
891
892/* Update the got entry reference counts for the section being removed. */
893
894static boolean
895elf_vax_gc_sweep_hook (abfd, info, sec, relocs)
896 bfd *abfd;
897 struct bfd_link_info *info;
898 asection *sec;
899 const Elf_Internal_Rela *relocs;
900{
901 Elf_Internal_Shdr *symtab_hdr;
902 struct elf_link_hash_entry **sym_hashes;
903 bfd_signed_vma *local_got_refcounts;
904 const Elf_Internal_Rela *rel, *relend;
905 unsigned long r_symndx;
906 struct elf_link_hash_entry *h;
907 bfd *dynobj;
908 asection *sgot;
909 asection *srelgot;
910
911 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
912 sym_hashes = elf_sym_hashes (abfd);
913 local_got_refcounts = elf_local_got_refcounts (abfd);
914
915 dynobj = elf_hash_table (info)->dynobj;
916 if (dynobj == NULL)
917 return true;
918
919 sgot = bfd_get_section_by_name (dynobj, ".got");
920 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
921
922 relend = relocs + sec->reloc_count;
923 for (rel = relocs; rel < relend; rel++)
924 {
925 switch (ELF32_R_TYPE (rel->r_info))
926 {
927 case R_VAX_GOT32:
928 r_symndx = ELF32_R_SYM (rel->r_info);
929 if (r_symndx >= symtab_hdr->sh_info)
930 {
931 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
932 if (h->got.refcount > 0)
933 {
934 --h->got.refcount;
935 if (h->got.refcount == 0)
936 {
937 /* We don't need the .got entry any more. */
938 sgot->_raw_size -= 4;
939 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
940 }
941 }
942 }
943 else if (local_got_refcounts != NULL)
944 {
945 if (local_got_refcounts[r_symndx] > 0)
946 {
947 --local_got_refcounts[r_symndx];
948 if (local_got_refcounts[r_symndx] == 0)
949 {
950 /* We don't need the .got entry any more. */
951 sgot->_raw_size -= 4;
952 if (info->shared)
953 srelgot->_raw_size -= sizeof (Elf32_External_Rela);
954 }
955 }
956 }
957 break;
958
959 case R_VAX_PLT32:
960 case R_VAX_PC8:
961 case R_VAX_PC16:
962 case R_VAX_PC32:
963 case R_VAX_8:
964 case R_VAX_16:
965 case R_VAX_32:
966 r_symndx = ELF32_R_SYM (rel->r_info);
967 if (r_symndx >= symtab_hdr->sh_info)
968 {
969 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
970 if (h->plt.refcount > 0)
971 --h->plt.refcount;
972 }
973 break;
974
975 default:
976 break;
977 }
978 }
979
980 return true;
981}
982
983/* Adjust a symbol defined by a dynamic object and referenced by a
984 regular object. The current definition is in some section of the
985 dynamic object, but we're not including those sections. We have to
986 change the definition to something the rest of the link can
987 understand. */
988
989static boolean
990elf_vax_adjust_dynamic_symbol (info, h)
991 struct bfd_link_info *info;
992 struct elf_link_hash_entry *h;
993{
994 bfd *dynobj;
995 asection *s;
996 unsigned int power_of_two;
997
998 dynobj = elf_hash_table (info)->dynobj;
999
1000 /* Make sure we know what is going on here. */
1001 BFD_ASSERT (dynobj != NULL
1002 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
1003 || h->weakdef != NULL
1004 || ((h->elf_link_hash_flags
1005 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1006 && (h->elf_link_hash_flags
1007 & ELF_LINK_HASH_REF_REGULAR) != 0
1008 && (h->elf_link_hash_flags
1009 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
1010
1011 /* If this is a function, put it in the procedure linkage table. We
1012 will fill in the contents of the procedure linkage table later,
1013 when we know the address of the .got section. */
1014 if (h->type == STT_FUNC
1015 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1016 {
1017 if (! info->shared
1018 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1019 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
1020 /* We must always create the plt entry if it was referenced
1021 by a PLTxxO relocation. In this case we already recorded
1022 it as a dynamic symbol. */
1023 && h->dynindx == -1)
1024 {
1025 /* This case can occur if we saw a PLTxx reloc in an input
1026 file, but the symbol was never referred to by a dynamic
1027 object. In such a case, we don't actually need to build
1028 a procedure linkage table, and we can just do a PCxx
1029 reloc instead. */
1030 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
1031 h->plt.offset = (bfd_vma) -1;
1032 return true;
1033 }
1034
1035 /* GC may have rendered this entry unused. */
1036 if (h->plt.refcount <= 0)
1037 {
1038 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1039 h->plt.offset = (bfd_vma) -1;
1040 return true;
1041 }
1042
1043 /* Make sure this symbol is output as a dynamic symbol. */
1044 if (h->dynindx == -1)
1045 {
1046 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1047 return false;
1048 }
1049
1050 s = bfd_get_section_by_name (dynobj, ".plt");
1051 BFD_ASSERT (s != NULL);
1052
1053 /* If this is the first .plt entry, make room for the special
1054 first entry. */
1055 if (s->_raw_size == 0)
1056 {
1057 s->_raw_size += PLT_ENTRY_SIZE;
1058 }
1059
1060 /* If this symbol is not defined in a regular file, and we are
1061 not generating a shared library, then set the symbol to this
1062 location in the .plt. This is required to make function
1063 pointers compare as equal between the normal executable and
1064 the shared library. */
1065 if (!info->shared
1066 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1067 {
1068 h->root.u.def.section = s;
1069 h->root.u.def.value = s->_raw_size;
1070 }
1071
1072 h->plt.offset = s->_raw_size;
1073
1074 /* Make room for this entry. */
1075 s->_raw_size += PLT_ENTRY_SIZE;
1076
1077 /* We also need to make an entry in the .got.plt section, which
1078 will be placed in the .got section by the linker script. */
1079
1080 s = bfd_get_section_by_name (dynobj, ".got.plt");
1081 BFD_ASSERT (s != NULL);
1082 s->_raw_size += 4;
1083
1084 /* We also need to make an entry in the .rela.plt section. */
1085
1086 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1087 BFD_ASSERT (s != NULL);
1088 s->_raw_size += sizeof (Elf32_External_Rela);
1089
1090 return true;
1091 }
1092
1093 /* Reinitialize the plt offset now that it is not used as a reference
1094 count any more. */
1095 h->plt.offset = (bfd_vma) -1;
1096
1097 /* If this is a weak symbol, and there is a real definition, the
1098 processor independent code will have arranged for us to see the
1099 real definition first, and we can just use the same value. */
1100 if (h->weakdef != NULL)
1101 {
1102 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1103 || h->weakdef->root.type == bfd_link_hash_defweak);
1104 h->root.u.def.section = h->weakdef->root.u.def.section;
1105 h->root.u.def.value = h->weakdef->root.u.def.value;
1106 return true;
1107 }
1108
1109 /* This is a reference to a symbol defined by a dynamic object which
1110 is not a function. */
1111
1112 /* If we are creating a shared library, we must presume that the
1113 only references to the symbol are via the global offset table.
1114 For such cases we need not do anything here; the relocations will
1115 be handled correctly by relocate_section. */
1116 if (info->shared)
1117 return true;
1118
1119 /* We must allocate the symbol in our .dynbss section, which will
1120 become part of the .bss section of the executable. There will be
1121 an entry for this symbol in the .dynsym section. The dynamic
1122 object will contain position independent code, so all references
1123 from the dynamic object to this symbol will go through the global
1124 offset table. The dynamic linker will use the .dynsym entry to
1125 determine the address it must put in the global offset table, so
1126 both the dynamic object and the regular object will refer to the
1127 same memory location for the variable. */
1128
1129 s = bfd_get_section_by_name (dynobj, ".dynbss");
1130 BFD_ASSERT (s != NULL);
1131
1132 /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
1133 copy the initial value out of the dynamic object and into the
1134 runtime process image. We need to remember the offset into the
1135 .rela.bss section we are going to use. */
1136 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1137 {
1138 asection *srel;
1139
1140 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1141 BFD_ASSERT (srel != NULL);
1142 srel->_raw_size += sizeof (Elf32_External_Rela);
1143 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1144 }
1145
1146 /* We need to figure out the alignment required for this symbol. I
1147 have no idea how ELF linkers handle this. */
1148 power_of_two = bfd_log2 (h->size);
1149 if (power_of_two > 3)
1150 power_of_two = 3;
1151
1152 /* Apply the required alignment. */
1153 s->_raw_size = BFD_ALIGN (s->_raw_size,
1154 (bfd_size_type) (1 << power_of_two));
1155 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1156 {
1157 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
1158 return false;
1159 }
1160
1161 /* Define the symbol as being at this point in the section. */
1162 h->root.u.def.section = s;
1163 h->root.u.def.value = s->_raw_size;
1164
1165 /* Increment the section size to make room for the symbol. */
1166 s->_raw_size += h->size;
1167
1168 return true;
1169}
1170
1171/* Set the sizes of the dynamic sections. */
1172
1173static boolean
1174elf_vax_size_dynamic_sections (output_bfd, info)
1175 bfd *output_bfd;
1176 struct bfd_link_info *info;
1177{
1178 bfd *dynobj;
1179 asection *s;
1180 boolean plt;
1181 boolean relocs;
1182 boolean reltext;
1183
1184 dynobj = elf_hash_table (info)->dynobj;
1185 BFD_ASSERT (dynobj != NULL);
1186
1187 if (elf_hash_table (info)->dynamic_sections_created)
1188 {
1189 /* Set the contents of the .interp section to the interpreter. */
1190 if (!info->shared)
1191 {
1192 s = bfd_get_section_by_name (dynobj, ".interp");
1193 BFD_ASSERT (s != NULL);
1194 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1195 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1196 }
1197 }
1198 else
1199 {
1200 /* We may have created entries in the .rela.got and .got sections.
1201 However, if we are not creating the dynamic sections, we will
1202 not actually use these entries. Reset the size of .rela.got
1203 and .got, which will cause it to get stripped from the output
1204 file below. */
1205 s = bfd_get_section_by_name (dynobj, ".rela.got");
1206 if (s != NULL)
1207 s->_raw_size = 0;
1208 s = bfd_get_section_by_name (dynobj, ".got.plt");
1209 if (s != NULL)
1210 s->_raw_size = 0;
1211 s = bfd_get_section_by_name (dynobj, ".got");
1212 if (s != NULL)
1213 s->_raw_size = 0;
1214 }
1215
1216 /* If this is a -Bsymbolic shared link, then we need to discard all PC
1217 relative relocs against symbols defined in a regular object. We
1218 allocated space for them in the check_relocs routine, but we will not
1219 fill them in in the relocate_section routine. */
1220 if (info->shared && info->symbolic)
1221 elf_vax_link_hash_traverse (elf_vax_hash_table (info),
1222 elf_vax_discard_copies,
1223 (PTR) NULL);
1224
1225 /* The check_relocs and adjust_dynamic_symbol entry points have
1226 determined the sizes of the various dynamic sections. Allocate
1227 memory for them. */
1228 plt = false;
1229 relocs = false;
1230 reltext = false;
1231 for (s = dynobj->sections; s != NULL; s = s->next)
1232 {
1233 const char *name;
1234 boolean strip;
1235
1236 if ((s->flags & SEC_LINKER_CREATED) == 0)
1237 continue;
1238
1239 /* It's OK to base decisions on the section name, because none
1240 of the dynobj section names depend upon the input files. */
1241 name = bfd_get_section_name (dynobj, s);
1242
1243 strip = false;
1244
1245 if (strcmp (name, ".plt") == 0)
1246 {
1247 if (s->_raw_size == 0)
1248 {
1249 /* Strip this section if we don't need it; see the
1250 comment below. */
1251 strip = true;
1252 }
1253 else
1254 {
1255 /* Remember whether there is a PLT. */
1256 plt = true;
1257 }
1258 }
1259 else if (strncmp (name, ".rela", 5) == 0)
1260 {
1261 if (s->_raw_size == 0)
1262 {
1263 /* If we don't need this section, strip it from the
1264 output file. This is mostly to handle .rela.bss and
1265 .rela.plt. We must create both sections in
1266 create_dynamic_sections, because they must be created
1267 before the linker maps input sections to output
1268 sections. The linker does that before
1269 adjust_dynamic_symbol is called, and it is that
1270 function which decides whether anything needs to go
1271 into these sections. */
1272 strip = true;
1273 }
1274 else
1275 {
1276 asection *target;
1277
1278 /* Remember whether there are any reloc sections other
1279 than .rela.plt. */
1280 if (strcmp (name, ".rela.plt") != 0)
1281 {
1282 const char *outname;
1283
1284 relocs = true;
1285
1286 /* If this relocation section applies to a read only
1287 section, then we probably need a DT_TEXTREL
1288 entry. .rela.plt is actually associated with
1289 .got.plt, which is never readonly. */
1290 outname = bfd_get_section_name (output_bfd,
1291 s->output_section);
1292 target = bfd_get_section_by_name (output_bfd, outname + 5);
1293 if (target != NULL
1294 && (target->flags & SEC_READONLY) != 0
1295 && (target->flags & SEC_ALLOC) != 0)
1296 reltext = true;
1297 }
1298
1299 /* We use the reloc_count field as a counter if we need
1300 to copy relocs into the output file. */
1301 s->reloc_count = 0;
1302 }
1303 }
1304 else if (strncmp (name, ".got", 4) != 0)
1305 {
1306 /* It's not one of our sections, so don't allocate space. */
1307 continue;
1308 }
1309
1310 if (strip)
1311 {
1312 _bfd_strip_section_from_output (info, s);
1313 continue;
1314 }
1315
1316 /* Allocate memory for the section contents. */
1317 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1318 if (s->contents == NULL && s->_raw_size != 0)
1319 return false;
1320 }
1321
1322 if (elf_hash_table (info)->dynamic_sections_created)
1323 {
1324 /* Add some entries to the .dynamic section. We fill in the
1325 values later, in elf_vax_finish_dynamic_sections, but we
1326 must add the entries now so that we get the correct size for
1327 the .dynamic section. The DT_DEBUG entry is filled in by the
1328 dynamic linker and used by the debugger. */
1329#define add_dynamic_entry(TAG, VAL) \
1330 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
1331
1332 if (!info->shared)
1333 {
1334 if (!add_dynamic_entry (DT_DEBUG, 0))
1335 return false;
1336 }
1337
1338 if (plt)
1339 {
1340 if (!add_dynamic_entry (DT_PLTGOT, 0)
1341 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1342 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1343 || !add_dynamic_entry (DT_JMPREL, 0))
1344 return false;
1345 }
1346
1347 if (relocs)
1348 {
1349 if (!add_dynamic_entry (DT_RELA, 0)
1350 || !add_dynamic_entry (DT_RELASZ, 0)
1351 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1352 return false;
1353 }
1354
1355 if (reltext || (info->flags & DF_TEXTREL) != 0)
1356 {
1357 if (!add_dynamic_entry (DT_TEXTREL, 0))
1358 return false;
1359 }
1360 }
1361#undef add_dynamic_entry
1362
1363 return true;
1364}
1365
1366/* This function is called via elf_vax_link_hash_traverse if we are
1367 creating a shared object with -Bsymbolic. It discards the space
1368 allocated to copy PC relative relocs against symbols which are defined
1369 in regular objects. We allocated space for them in the check_relocs
1370 routine, but we won't fill them in in the relocate_section routine. */
1371
1372/*ARGSUSED*/
1373static boolean
1374elf_vax_discard_copies (h, ignore)
1375 struct elf_vax_link_hash_entry *h;
1376 PTR ignore ATTRIBUTE_UNUSED;
1377{
1378 struct elf_vax_pcrel_relocs_copied *s;
1379
1380 if (h->root.root.type == bfd_link_hash_warning)
1381 h = (struct elf_vax_link_hash_entry *) h->root.root.u.i.link;
1382
1383 /* We only discard relocs for symbols defined in a regular object. */
1384 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1385 return true;
1386
1387 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
1388 s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
1389
1390 return true;
1391}
1392
1393/* Relocate an VAX ELF section. */
1394
1395static boolean
1396elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
1397 contents, relocs, local_syms, local_sections)
1398 bfd *output_bfd;
1399 struct bfd_link_info *info;
1400 bfd *input_bfd;
1401 asection *input_section;
1402 bfd_byte *contents;
1403 Elf_Internal_Rela *relocs;
1404 Elf_Internal_Sym *local_syms;
1405 asection **local_sections;
1406{
1407 bfd *dynobj;
1408 Elf_Internal_Shdr *symtab_hdr;
1409 struct elf_link_hash_entry **sym_hashes;
1410 bfd_vma *local_got_offsets;
1411 bfd_vma plt_index;
1412 bfd_vma got_offset;
1413 asection *sgot;
1414 asection *splt;
1415 asection *sgotplt;
1416 asection *sreloc;
1417 Elf_Internal_Rela *rel;
1418 Elf_Internal_Rela *relend;
1419
f0fe0e16
AM
1420 if (info->relocateable)
1421 return true;
1422
90ace9e9
JT
1423 dynobj = elf_hash_table (info)->dynobj;
1424 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1425 sym_hashes = elf_sym_hashes (input_bfd);
1426 local_got_offsets = elf_local_got_offsets (input_bfd);
1427
1428 sgot = NULL;
1429 splt = NULL;
1430 sgotplt = NULL;
1431 sreloc = NULL;
1432
1433 rel = relocs;
1434 relend = relocs + input_section->reloc_count;
1435 for (; rel < relend; rel++)
1436 {
1437 int r_type;
1438 reloc_howto_type *howto;
1439 unsigned long r_symndx;
1440 struct elf_link_hash_entry *h;
1441 Elf_Internal_Sym *sym;
1442 asection *sec;
1443 bfd_vma relocation;
1444 bfd_reloc_status_type r;
1445
1446 r_type = ELF32_R_TYPE (rel->r_info);
1447 if (r_type < 0 || r_type >= (int) R_VAX_max)
1448 {
1449 bfd_set_error (bfd_error_bad_value);
1450 return false;
1451 }
1452 howto = howto_table + r_type;
1453
90ace9e9 1454 /* This is a final link. */
f0fe0e16 1455 r_symndx = ELF32_R_SYM (rel->r_info);
90ace9e9
JT
1456 h = NULL;
1457 sym = NULL;
1458 sec = NULL;
1459 if (r_symndx < symtab_hdr->sh_info)
1460 {
1461 sym = local_syms + r_symndx;
1462 sec = local_sections[r_symndx];
1463 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
1464 }
1465 else
1466 {
1467 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1468 while (h->root.type == bfd_link_hash_indirect
1469 || h->root.type == bfd_link_hash_warning)
1470 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1471 if (h->root.type == bfd_link_hash_defined
1472 || h->root.type == bfd_link_hash_defweak)
1473 {
1474 sec = h->root.u.def.section;
1475 if ((r_type == R_VAX_PLT32
1476 && h->plt.offset != (bfd_vma) -1
1477 && elf_hash_table (info)->dynamic_sections_created)
1478 || (r_type == R_VAX_GOT32
1479 && strcmp (h->root.root.string,
1480 "_GLOBAL_OFFSET_TABLE_") != 0
1481 && elf_hash_table (info)->dynamic_sections_created
1482 && (! info->shared
1483 || (! info->symbolic && h->dynindx != -1)
1484 || (h->elf_link_hash_flags
1485 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1486 || (info->shared
1487 && ((! info->symbolic && h->dynindx != -1)
1488 || (h->elf_link_hash_flags
1489 & ELF_LINK_HASH_DEF_REGULAR) == 0)
1490 && ((input_section->flags & SEC_ALLOC) != 0
1491 /* DWARF will emit R_VAX_32 relocations in its
1492 sections against symbols defined externally
1493 in shared libraries. We can't do anything
1494 with them here. */
1495
1496 || ((input_section->flags & SEC_DEBUGGING) != 0
1497 && (h->elf_link_hash_flags
1498 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
1499 && (r_type == R_VAX_8
1500 || r_type == R_VAX_16
1501 || r_type == R_VAX_32
1502 || r_type == R_VAX_PC8
1503 || r_type == R_VAX_PC16
1504 || r_type == R_VAX_PC32)))
1505 {
1506 /* In these cases, we don't need the relocation
1507 value. We check specially because in some
1508 obscure cases sec->output_section will be NULL. */
1509 relocation = 0;
1510 }
1511 else
1512 relocation = (h->root.u.def.value
1513 + sec->output_section->vma
1514 + sec->output_offset);
1515 }
1516 else if (h->root.type == bfd_link_hash_undefweak)
1517 relocation = 0;
1518 else if (info->shared
1519 && (!info->symbolic || info->allow_shlib_undefined)
1520 && !info->no_undefined
1521 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
1522 relocation = 0;
1523 else
1524 {
1525 if (!(info->callbacks->undefined_symbol
1526 (info, h->root.root.string, input_bfd,
1527 input_section, rel->r_offset,
1528 (!info->shared || info->no_undefined
1529 || ELF_ST_VISIBILITY (h->other)))))
1530 return false;
1531 relocation = 0;
1532 }
1533 }
1534
1535 switch (r_type)
1536 {
1537 case R_VAX_GOT32:
1538 /* Relocation is to the address of the entry for this symbol
1539 in the global offset table. */
1540 if (h != NULL
1541 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1542 break;
1543
1544 /* Relocation is the offset of the entry for this symbol in
1545 the global offset table. */
1546
1547 {
1548 bfd_vma off;
1549
1550 if (!elf_hash_table (info)->dynamic_sections_created
1551 || (h == NULL)
1552 || (info->shared
1553 && info->symbolic
1554 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1555 {
1556 /* This is actually a static link, or it is a -Bsymbolic link
1557 and the symbol is defined locally or there is no symbol.
cedb70c5 1558 Change the GOT32 entry to a PC32 entry. */
90ace9e9
JT
1559 break;
1560 }
1561
1562 if (sgot == NULL)
1563 {
1564 sgot = bfd_get_section_by_name (dynobj, ".got");
1565 BFD_ASSERT (sgot != NULL);
1566 }
1567
1568 BFD_ASSERT (h != NULL);
1569 off = h->got.offset;
1570 BFD_ASSERT (off != (bfd_vma) -1);
1571
1572 if (info->shared
1573 && h->dynindx == -1
1574 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1575 {
1576 /* The symbol was forced to be local
1577 because of a version file.. We must initialize
1578 this entry in the global offset table. Since
1579 the offset must always be a multiple of 4, we
1580 use the least significant bit to record whether
1581 we have initialized it already.
1582
1583 When doing a dynamic link, we create a .rela.got
1584 relocation entry to initialize the value. This
1585 is done in the finish_dynamic_symbol routine. */
1586 if ((off & 1) != 0)
1587 off &= ~1;
1588 else
1589 {
1590 bfd_put_32 (output_bfd, relocation + rel->r_addend,
1591 sgot->contents + off);
1592 h->got.offset |= 1;
1593 }
1594 } else {
1595 bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off);
1596 }
1597
1598 relocation = sgot->output_offset + off;
1599 /* Neither GOT relocation uses the addend. */
1600 rel->r_addend = 0;
1601
1602 if (r_type == R_VAX_GOT32)
1603 {
1604 /* Change the reference to be indirect */
1605 contents[rel->r_offset - 1] |= 0x10;
1606 relocation += sgot->output_section->vma;
1607 }
1608 }
1609 break;
1610
1611 case R_VAX_PLT32:
1612 /* Relocation is to the entry for this symbol in the
1613 procedure linkage table. */
1614
1615 /* Resolve a PLTxx reloc against a local symbol directly,
1616 without using the procedure linkage table. */
1617 if (h == NULL)
1618 break;
1619
1620 if (h->plt.offset == (bfd_vma) -1
1621 || !elf_hash_table (info)->dynamic_sections_created)
1622 {
1623 /* We didn't make a PLT entry for this symbol. This
1624 happens when statically linking PIC code, or when
1625 using -Bsymbolic. */
1626 break;
1627 }
1628
1629 if (splt == NULL)
1630 {
1631 splt = bfd_get_section_by_name (dynobj, ".plt");
1632 BFD_ASSERT (splt != NULL);
1633 }
1634
1635 if (sgotplt == NULL)
1636 {
1637 sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1638 BFD_ASSERT (splt != NULL);
1639 }
1640
1641 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1642
1643 /* Get the offset into the .got table of the entry that
1644 corresponds to this function. Each .got entry is 4 bytes.
1645 The first two are reserved. */
1646 got_offset = (plt_index + 3) * 4;
1647
1648 /* We want the relocate to point into the .got.plt instead
cedb70c5 1649 of the plt itself. */
90ace9e9
JT
1650 relocation = (sgotplt->output_section->vma
1651 + sgotplt->output_offset
1652 + got_offset);
1653 contents[rel->r_offset-1] |= 0x10; /* make indirect */
1654 if (rel->r_addend == 2)
1655 {
1656 h->plt.offset |= 1;
1657 }
1658 else if (rel->r_addend != 0)
1659 (*_bfd_error_handler)
1660 (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"),
1661 bfd_get_filename (input_bfd), rel->r_addend,
1662 h->root.root.string,
1663 bfd_get_section_name (input_bfd, input_section));
1664 rel->r_addend = 0;
1665
1666 break;
1667
1668 case R_VAX_PC8:
1669 case R_VAX_PC16:
1670 case R_VAX_PC32:
1671 if (h == NULL)
1672 break;
1673 /* Fall through. */
1674 case R_VAX_8:
1675 case R_VAX_16:
1676 case R_VAX_32:
1677 if (info->shared
1678 && r_symndx != 0
1679 && (input_section->flags & SEC_ALLOC) != 0
1680 && ((r_type != R_VAX_PC8
1681 && r_type != R_VAX_PC16
1682 && r_type != R_VAX_PC32)
1683 || (!info->symbolic
1684 || (h->elf_link_hash_flags
1685 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
1686 {
1687 Elf_Internal_Rela outrel;
1688 boolean skip, relocate;
1689
1690 /* When generating a shared object, these relocations
1691 are copied into the output file to be resolved at run
1692 time. */
1693
1694 if (sreloc == NULL)
1695 {
1696 const char *name;
1697
1698 name = (bfd_elf_string_from_elf_section
1699 (input_bfd,
1700 elf_elfheader (input_bfd)->e_shstrndx,
1701 elf_section_data (input_section)->rel_hdr.sh_name));
1702 if (name == NULL)
1703 return false;
1704
1705 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1706 && strcmp (bfd_get_section_name (input_bfd,
1707 input_section),
1708 name + 5) == 0);
1709
1710 sreloc = bfd_get_section_by_name (dynobj, name);
1711 BFD_ASSERT (sreloc != NULL);
1712 }
1713
1714 skip = false;
1715 relocate = false;
1716
1717 outrel.r_offset =
1718 _bfd_elf_section_offset (output_bfd, info, input_section,
1719 rel->r_offset);
1720 if (outrel.r_offset == (bfd_vma) -1)
1721 skip = true;
1722 if (outrel.r_offset == (bfd_vma) -2)
1723 skip = true, relocate = true;
1724 outrel.r_offset += (input_section->output_section->vma
1725 + input_section->output_offset);
1726
1727 if (skip)
1728 memset (&outrel, 0, sizeof outrel);
1729 /* h->dynindx may be -1 if the symbol was marked to
1730 become local. */
1731 else if (h != NULL
1732 && ((! info->symbolic && h->dynindx != -1)
1733 || (h->elf_link_hash_flags
1734 & ELF_LINK_HASH_DEF_REGULAR) == 0))
1735 {
1736 BFD_ASSERT (h->dynindx != -1);
1737 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1738 outrel.r_addend = relocation + rel->r_addend;
1739 }
1740 else
1741 {
1742 if (r_type == R_VAX_32)
1743 {
1744 relocate = true;
1745 outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1746 BFD_ASSERT (bfd_get_signed_32 (input_bfd,
1747 &contents[rel->r_offset]) == 0);
1748 outrel.r_addend = relocation + rel->r_addend;
1749 }
1750 else
1751 {
1752 long indx;
1753
1754 if (h == NULL)
1755 sec = local_sections[r_symndx];
1756 else
1757 {
1758 BFD_ASSERT (h->root.type == bfd_link_hash_defined
1759 || (h->root.type
1760 == bfd_link_hash_defweak));
1761 sec = h->root.u.def.section;
1762 }
1763 if (sec != NULL && bfd_is_abs_section (sec))
1764 indx = 0;
1765 else if (sec == NULL || sec->owner == NULL)
1766 {
1767 bfd_set_error (bfd_error_bad_value);
1768 return false;
1769 }
1770 else
1771 {
1772 asection *osec;
1773
1774 osec = sec->output_section;
1775 indx = elf_section_data (osec)->dynindx;
1776 BFD_ASSERT (indx > 0);
1777 }
1778
1779 outrel.r_info = ELF32_R_INFO (indx, r_type);
1780 outrel.r_addend = relocation + rel->r_addend;
1781 }
1782 }
1783
1784 if (!strcmp (bfd_get_section_name (input_bfd, input_section),
cedb70c5 1785 ".text") != 0 ||
90ace9e9
JT
1786 (info->shared
1787 && ELF32_R_TYPE(outrel.r_info) != R_VAX_32
1788 && ELF32_R_TYPE(outrel.r_info) != R_VAX_RELATIVE
1789 && ELF32_R_TYPE(outrel.r_info) != R_VAX_COPY
1790 && ELF32_R_TYPE(outrel.r_info) != R_VAX_JMP_SLOT
1791 && ELF32_R_TYPE(outrel.r_info) != R_VAX_GLOB_DAT))
1792 {
1793 if (h != NULL)
1794 (*_bfd_error_handler)
1795 (_("%s: warning: %s relocation against symbol `%s' from %s section"),
1796 bfd_get_filename (input_bfd), howto->name,
1797 h->root.root.string,
1798 bfd_get_section_name (input_bfd, input_section));
1799 else
1800 (*_bfd_error_handler)
1801 (_("%s: warning: %s relocation to 0x%x from %s section"),
1802 bfd_get_filename (input_bfd), howto->name,
1803 outrel.r_addend,
1804 bfd_get_section_name (input_bfd, input_section));
1805 }
1806 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1807 (((Elf32_External_Rela *)
1808 sreloc->contents)
1809 + sreloc->reloc_count));
1810 ++sreloc->reloc_count;
1811
1812 /* This reloc will be computed at runtime, so there's no
1813 need to do anything now, except for R_VAX_32
1814 relocations that have been turned into
1815 R_VAX_RELATIVE. */
1816 if (!relocate)
1817 continue;
1818 }
1819
1820 break;
1821
1822 case R_VAX_GNU_VTINHERIT:
1823 case R_VAX_GNU_VTENTRY:
1824 /* These are no-ops in the end. */
1825 continue;
1826
1827 default:
1828 break;
1829 }
1830
1831 /* VAX PCREL relocations are from the end of relocation, not the start */
1832 if (howto->pc_relative && howto->pcrel_offset)
1833 {
1834 relocation -= bfd_get_reloc_size(howto);
1835 }
1836
1837 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1838 contents, rel->r_offset,
1839 relocation, rel->r_addend);
1840
1841 if (r != bfd_reloc_ok)
1842 {
1843 switch (r)
1844 {
1845 default:
1846 case bfd_reloc_outofrange:
1847 abort ();
1848 case bfd_reloc_overflow:
1849 {
1850 const char *name;
1851
1852 if (h != NULL)
1853 name = h->root.root.string;
1854 else
1855 {
1856 name = bfd_elf_string_from_elf_section (input_bfd,
1857 symtab_hdr->sh_link,
1858 sym->st_name);
1859 if (name == NULL)
1860 return false;
1861 if (*name == '\0')
1862 name = bfd_section_name (input_bfd, sec);
1863 }
1864 if (!(info->callbacks->reloc_overflow
1865 (info, name, howto->name, (bfd_vma) 0,
1866 input_bfd, input_section, rel->r_offset)))
1867 return false;
1868 }
1869 break;
1870 }
1871 }
1872 }
1873
1874 return true;
1875}
1876
1877/* Finish up dynamic symbol handling. We set the contents of various
1878 dynamic sections here. */
1879
1880static boolean
1881elf_vax_finish_dynamic_symbol (output_bfd, info, h, sym)
1882 bfd *output_bfd;
1883 struct bfd_link_info *info;
1884 struct elf_link_hash_entry *h;
1885 Elf_Internal_Sym *sym;
1886{
1887 bfd *dynobj;
1888
1889 dynobj = elf_hash_table (info)->dynobj;
1890
1891 if (h->plt.offset != (bfd_vma) -1)
1892 {
1893 asection *splt;
1894 asection *sgot;
1895 asection *srela;
1896 bfd_vma plt_index;
1897 bfd_vma got_offset;
1898 bfd_vma addend;
1899 Elf_Internal_Rela rela;
1900
1901 /* This symbol has an entry in the procedure linkage table. Set
1902 it up. */
1903
1904 BFD_ASSERT (h->dynindx != -1);
1905
1906 splt = bfd_get_section_by_name (dynobj, ".plt");
1907 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
1908 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1909 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
1910
1911 addend = 2 * (h->plt.offset & 1);
1912 h->plt.offset &= ~1;
1913
1914 /* Get the index in the procedure linkage table which
1915 corresponds to this symbol. This is the index of this symbol
1916 in all the symbols for which we are making plt entries. The
1917 first entry in the procedure linkage table is reserved. */
1918 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
1919
1920 /* Get the offset into the .got table of the entry that
1921 corresponds to this function. Each .got entry is 4 bytes.
1922 The first two are reserved. */
1923 got_offset = (plt_index + 3) * 4;
1924
1925 /* Fill in the entry in the procedure linkage table. */
1926 memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
1927 PLT_ENTRY_SIZE);
1928
1929 /* The offset is relative to the first extension word. */
1930 bfd_put_32 (output_bfd,
1931 -(h->plt.offset + 8),
1932 splt->contents + h->plt.offset + 4);
1933
1934 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
1935 splt->contents + h->plt.offset + 8);
1936
1937 /* Fill in the entry in the global offset table. */
1938 bfd_put_32 (output_bfd,
1939 (splt->output_section->vma
1940 + splt->output_offset
1941 + h->plt.offset) + addend,
1942 sgot->contents + got_offset);
1943
1944 /* Fill in the entry in the .rela.plt section. */
1945 rela.r_offset = (sgot->output_section->vma
1946 + sgot->output_offset
1947 + got_offset);
1948 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
1949 rela.r_addend = addend;
1950 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1951 ((Elf32_External_Rela *) srela->contents
1952 + plt_index));
1953
1954 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1955 {
1956 /* Mark the symbol as undefined, rather than as defined in
1957 the .plt section. Leave the value alone. */
1958 sym->st_shndx = SHN_UNDEF;
1959 }
1960 }
1961
1962 if (h->got.offset != (bfd_vma) -1)
1963 {
1964 asection *sgot;
1965 asection *srela;
1966 Elf_Internal_Rela rela;
1967
1968 /* This symbol has an entry in the global offset table. Set it
1969 up. */
1970
1971 sgot = bfd_get_section_by_name (dynobj, ".got");
1972 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1973 BFD_ASSERT (sgot != NULL && srela != NULL);
1974
1975 rela.r_offset = (sgot->output_section->vma
1976 + sgot->output_offset
1977 + (h->got.offset &~ 1));
1978
1979 /* If the symbol was forced to be local because of a version file
1980 locally we just want to emit a RELATIVE reloc. The entry in
1981 the global offset table will already have been initialized in
1982 the relocate_section function. */
1983 if (info->shared
1984 && h->dynindx == -1
1985 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1986 {
1987 rela.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
1988 }
1989 else
1990 {
1991 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
1992 }
1993 rela.r_addend = bfd_get_signed_32 (output_bfd,
1994 (sgot->contents
1995 + (h->got.offset & ~1)));
1996
1997 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1998 ((Elf32_External_Rela *) srela->contents
1999 + srela->reloc_count));
2000 ++srela->reloc_count;
2001 }
2002
2003 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2004 {
2005 asection *s;
2006 Elf_Internal_Rela rela;
2007
2008 /* This symbol needs a copy reloc. Set it up. */
2009
2010 BFD_ASSERT (h->dynindx != -1
2011 && (h->root.type == bfd_link_hash_defined
2012 || h->root.type == bfd_link_hash_defweak));
2013
2014 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2015 ".rela.bss");
2016 BFD_ASSERT (s != NULL);
2017
2018 rela.r_offset = (h->root.u.def.value
2019 + h->root.u.def.section->output_section->vma
2020 + h->root.u.def.section->output_offset);
2021 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
2022 rela.r_addend = 0;
2023 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2024 ((Elf32_External_Rela *) s->contents
2025 + s->reloc_count));
2026 ++s->reloc_count;
2027 }
2028
2029 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2030 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2031 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2032 sym->st_shndx = SHN_ABS;
2033
2034 return true;
2035}
2036
2037/* Finish up the dynamic sections. */
2038
2039static boolean
2040elf_vax_finish_dynamic_sections (output_bfd, info)
2041 bfd *output_bfd;
2042 struct bfd_link_info *info;
2043{
2044 bfd *dynobj;
2045 asection *sgot;
2046 asection *sdyn;
2047
2048 dynobj = elf_hash_table (info)->dynobj;
2049
2050 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
2051 BFD_ASSERT (sgot != NULL);
2052 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2053
2054 if (elf_hash_table (info)->dynamic_sections_created)
2055 {
2056 asection *splt;
2057 Elf32_External_Dyn *dyncon, *dynconend;
2058
2059 splt = bfd_get_section_by_name (dynobj, ".plt");
2060 BFD_ASSERT (splt != NULL && sdyn != NULL);
2061
2062 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2063 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2064 for (; dyncon < dynconend; dyncon++)
2065 {
2066 Elf_Internal_Dyn dyn;
2067 const char *name;
2068 asection *s;
2069
2070 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2071
2072 switch (dyn.d_tag)
2073 {
2074 default:
2075 break;
2076
2077 case DT_PLTGOT:
2078 name = ".got";
2079 goto get_vma;
2080 case DT_JMPREL:
2081 name = ".rela.plt";
2082 get_vma:
2083 s = bfd_get_section_by_name (output_bfd, name);
2084 BFD_ASSERT (s != NULL);
2085 dyn.d_un.d_ptr = s->vma;
2086 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2087 break;
2088
2089 case DT_PLTRELSZ:
2090 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2091 BFD_ASSERT (s != NULL);
2092 if (s->_cooked_size != 0)
2093 dyn.d_un.d_val = s->_cooked_size;
2094 else
2095 dyn.d_un.d_val = s->_raw_size;
2096 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2097 break;
2098
2099 case DT_RELASZ:
2100 /* The procedure linkage table relocs (DT_JMPREL) should
2101 not be included in the overall relocs (DT_RELA).
2102 Therefore, we override the DT_RELASZ entry here to
2103 make it not include the JMPREL relocs. Since the
2104 linker script arranges for .rela.plt to follow all
2105 other relocation sections, we don't have to worry
2106 about changing the DT_RELA entry. */
2107 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2108 if (s != NULL)
2109 {
2110 if (s->_cooked_size != 0)
2111 dyn.d_un.d_val -= s->_cooked_size;
2112 else
2113 dyn.d_un.d_val -= s->_raw_size;
2114 }
2115 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2116 break;
2117 }
2118 }
2119
2120 /* Fill in the first entry in the procedure linkage table. */
2121 if (splt->_raw_size > 0)
2122 {
2123 memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
2124 bfd_put_32 (output_bfd,
2125 (sgot->output_section->vma
2126 + sgot->output_offset + 4
2127 - (splt->output_section->vma + 6)),
2128 splt->contents + 2);
2129 bfd_put_32 (output_bfd,
2130 (sgot->output_section->vma
2131 + sgot->output_offset + 8
2132 - (splt->output_section->vma + 12)),
2133 splt->contents + 8);
cedb70c5 2134 elf_section_data (splt->output_section)->this_hdr.sh_entsize
90ace9e9
JT
2135 = PLT_ENTRY_SIZE;
2136 }
2137 }
2138
2139 /* Fill in the first three entries in the global offset table. */
2140 if (sgot->_raw_size > 0)
2141 {
2142 if (sdyn == NULL)
2143 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2144 else
2145 bfd_put_32 (output_bfd,
2146 sdyn->output_section->vma + sdyn->output_offset,
2147 sgot->contents);
2148 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
2149 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
2150 }
2151
2152 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2153
2154 return true;
2155}
2156
2157#define TARGET_LITTLE_SYM bfd_elf32_vax_vec
2158#define TARGET_LITTLE_NAME "elf32-vax"
2159#define ELF_MACHINE_CODE EM_VAX
2160#define ELF_MAXPAGESIZE 0x1000
2161
2162#define elf_backend_create_dynamic_sections \
2163 _bfd_elf_create_dynamic_sections
2164#define bfd_elf32_bfd_link_hash_table_create \
2165 elf_vax_link_hash_table_create
2166#define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
2167
2168#define elf_backend_check_relocs elf_vax_check_relocs
2169#define elf_backend_adjust_dynamic_symbol \
2170 elf_vax_adjust_dynamic_symbol
2171#define elf_backend_size_dynamic_sections \
2172 elf_vax_size_dynamic_sections
2173#define elf_backend_relocate_section elf_vax_relocate_section
2174#define elf_backend_finish_dynamic_symbol \
2175 elf_vax_finish_dynamic_symbol
2176#define elf_backend_finish_dynamic_sections \
2177 elf_vax_finish_dynamic_sections
2178#define elf_backend_gc_mark_hook elf_vax_gc_mark_hook
2179#define elf_backend_gc_sweep_hook elf_vax_gc_sweep_hook
2180#define bfd_elf32_bfd_merge_private_bfd_data \
2181 elf32_vax_merge_private_bfd_data
2182#define bfd_elf32_bfd_set_private_flags \
2183 elf32_vax_set_private_flags
2184#define bfd_elf32_bfd_print_private_bfd_data \
2185 elf32_vax_print_private_bfd_data
2186
2187#define elf_backend_can_gc_sections 1
2188#define elf_backend_want_got_plt 1
2189#define elf_backend_plt_readonly 1
2190#define elf_backend_want_plt_sym 0
2191#define elf_backend_got_header_size 16
f0fe0e16 2192#define elf_backend_rela_normal 1
90ace9e9
JT
2193
2194#include "elf32-target.h"
This page took 0.116318 seconds and 4 git commands to generate.