1 /* VAX series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
30 static reloc_howto_type
*reloc_type_lookup (bfd
*, bfd_reloc_code_real_type
);
31 static void rtype_to_howto (bfd
*, arelent
*, Elf_Internal_Rela
*);
32 static struct bfd_hash_entry
*elf_vax_link_hash_newfunc (struct bfd_hash_entry
*,
33 struct bfd_hash_table
*,
35 static struct bfd_link_hash_table
*elf_vax_link_hash_table_create (bfd
*);
36 static bfd_boolean
elf_vax_check_relocs (bfd
*, struct bfd_link_info
*,
37 asection
*, const Elf_Internal_Rela
*);
38 static bfd_boolean
elf_vax_adjust_dynamic_symbol (struct bfd_link_info
*,
39 struct elf_link_hash_entry
*);
40 static bfd_boolean
elf_vax_size_dynamic_sections (bfd
*, struct bfd_link_info
*);
41 static bfd_boolean
elf_vax_relocate_section (bfd
*, struct bfd_link_info
*,
42 bfd
*, asection
*, bfd_byte
*,
44 Elf_Internal_Sym
*, asection
**);
45 static bfd_boolean
elf_vax_finish_dynamic_symbol (bfd
*, struct bfd_link_info
*,
46 struct elf_link_hash_entry
*,
48 static bfd_boolean
elf_vax_finish_dynamic_sections (bfd
*,
49 struct bfd_link_info
*);
50 static bfd_vma
elf_vax_plt_sym_val (bfd_vma
, const asection
*,
53 static bfd_boolean
elf32_vax_set_private_flags (bfd
*, flagword
);
54 static bfd_boolean
elf32_vax_merge_private_bfd_data (bfd
*, bfd
*);
55 static bfd_boolean
elf32_vax_print_private_bfd_data (bfd
*, PTR
);
57 static reloc_howto_type howto_table
[] = {
58 HOWTO (R_VAX_NONE
, /* type */
60 0, /* size (0 = byte, 1 = short, 2 = long) */
62 FALSE
, /* pc_relative */
64 complain_overflow_dont
, /* complain_on_overflow */
65 bfd_elf_generic_reloc
, /* special_function */
66 "R_VAX_NONE", /* name */
67 FALSE
, /* partial_inplace */
69 0x00000000, /* dst_mask */
70 FALSE
), /* pcrel_offset */
72 HOWTO (R_VAX_32
, /* type */
74 2, /* size (0 = byte, 1 = short, 2 = long) */
76 FALSE
, /* pc_relative */
78 complain_overflow_bitfield
, /* complain_on_overflow */
79 bfd_elf_generic_reloc
, /* special_function */
80 "R_VAX_32", /* name */
81 FALSE
, /* partial_inplace */
83 0xffffffff, /* dst_mask */
84 FALSE
), /* pcrel_offset */
86 HOWTO (R_VAX_16
, /* type */
88 1, /* size (0 = byte, 1 = short, 2 = long) */
90 FALSE
, /* pc_relative */
92 complain_overflow_bitfield
, /* complain_on_overflow */
93 bfd_elf_generic_reloc
, /* special_function */
94 "R_VAX_16", /* name */
95 FALSE
, /* partial_inplace */
97 0x0000ffff, /* dst_mask */
98 FALSE
), /* pcrel_offset */
100 HOWTO (R_VAX_8
, /* type */
102 0, /* size (0 = byte, 1 = short, 2 = long) */
104 FALSE
, /* pc_relative */
106 complain_overflow_bitfield
, /* complain_on_overflow */
107 bfd_elf_generic_reloc
, /* special_function */
108 "R_VAX_8", /* name */
109 FALSE
, /* partial_inplace */
111 0x000000ff, /* dst_mask */
112 FALSE
), /* pcrel_offset */
114 HOWTO (R_VAX_PC32
, /* type */
116 2, /* size (0 = byte, 1 = short, 2 = long) */
118 TRUE
, /* pc_relative */
120 complain_overflow_bitfield
, /* complain_on_overflow */
121 bfd_elf_generic_reloc
, /* special_function */
122 "R_VAX_PC32", /* name */
123 FALSE
, /* partial_inplace */
125 0xffffffff, /* dst_mask */
126 TRUE
), /* pcrel_offset */
128 HOWTO (R_VAX_PC16
, /* type */
130 1, /* size (0 = byte, 1 = short, 2 = long) */
132 TRUE
, /* pc_relative */
134 complain_overflow_signed
, /* complain_on_overflow */
135 bfd_elf_generic_reloc
, /* special_function */
136 "R_VAX_PC16", /* name */
137 FALSE
, /* partial_inplace */
139 0x0000ffff, /* dst_mask */
140 TRUE
), /* pcrel_offset */
142 HOWTO (R_VAX_PC8
, /* type */
144 0, /* size (0 = byte, 1 = short, 2 = long) */
146 TRUE
, /* pc_relative */
148 complain_overflow_signed
, /* complain_on_overflow */
149 bfd_elf_generic_reloc
, /* special_function */
150 "R_VAX_PC8", /* name */
151 FALSE
, /* partial_inplace */
153 0x000000ff, /* dst_mask */
154 TRUE
), /* pcrel_offset */
156 HOWTO (R_VAX_GOT32
, /* type */
158 2, /* size (0 = byte, 1 = short, 2 = long) */
160 TRUE
, /* pc_relative */
162 complain_overflow_bitfield
, /* complain_on_overflow */
163 bfd_elf_generic_reloc
, /* special_function */
164 "R_VAX_GOT32", /* name */
165 FALSE
, /* partial_inplace */
167 0xffffffff, /* dst_mask */
168 TRUE
), /* pcrel_offset */
176 HOWTO (R_VAX_PLT32
, /* type */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
180 TRUE
, /* pc_relative */
182 complain_overflow_bitfield
, /* complain_on_overflow */
183 bfd_elf_generic_reloc
, /* special_function */
184 "R_VAX_PLT32", /* name */
185 FALSE
, /* partial_inplace */
187 0xffffffff, /* dst_mask */
188 TRUE
), /* pcrel_offset */
196 HOWTO (R_VAX_COPY
, /* type */
198 0, /* size (0 = byte, 1 = short, 2 = long) */
200 FALSE
, /* pc_relative */
202 complain_overflow_dont
, /* complain_on_overflow */
203 bfd_elf_generic_reloc
, /* special_function */
204 "R_VAX_COPY", /* name */
205 FALSE
, /* partial_inplace */
207 0xffffffff, /* dst_mask */
208 FALSE
), /* pcrel_offset */
210 HOWTO (R_VAX_GLOB_DAT
, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE
, /* pc_relative */
216 complain_overflow_dont
, /* complain_on_overflow */
217 bfd_elf_generic_reloc
, /* special_function */
218 "R_VAX_GLOB_DAT", /* name */
219 FALSE
, /* partial_inplace */
221 0xffffffff, /* dst_mask */
222 FALSE
), /* pcrel_offset */
224 HOWTO (R_VAX_JMP_SLOT
, /* type */
226 2, /* size (0 = byte, 1 = short, 2 = long) */
228 FALSE
, /* pc_relative */
230 complain_overflow_dont
, /* complain_on_overflow */
231 bfd_elf_generic_reloc
, /* special_function */
232 "R_VAX_JMP_SLOT", /* name */
233 FALSE
, /* partial_inplace */
235 0xffffffff, /* dst_mask */
236 FALSE
), /* pcrel_offset */
238 HOWTO (R_VAX_RELATIVE
, /* type */
240 2, /* size (0 = byte, 1 = short, 2 = long) */
242 FALSE
, /* pc_relative */
244 complain_overflow_dont
, /* complain_on_overflow */
245 bfd_elf_generic_reloc
, /* special_function */
246 "R_VAX_RELATIVE", /* name */
247 FALSE
, /* partial_inplace */
249 0xffffffff, /* dst_mask */
250 FALSE
), /* pcrel_offset */
252 /* GNU extension to record C++ vtable hierarchy */
253 HOWTO (R_VAX_GNU_VTINHERIT
, /* type */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
257 FALSE
, /* pc_relative */
259 complain_overflow_dont
, /* complain_on_overflow */
260 NULL
, /* special_function */
261 "R_VAX_GNU_VTINHERIT", /* name */
262 FALSE
, /* partial_inplace */
265 FALSE
), /* pcrel_offset */
267 /* GNU extension to record C++ vtable member usage */
268 HOWTO (R_VAX_GNU_VTENTRY
, /* type */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
272 FALSE
, /* pc_relative */
274 complain_overflow_dont
, /* complain_on_overflow */
275 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
276 "R_VAX_GNU_VTENTRY", /* name */
277 FALSE
, /* partial_inplace */
280 FALSE
), /* pcrel_offset */
284 rtype_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
285 Elf_Internal_Rela
*dst
)
287 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_VAX_max
);
288 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
291 #define elf_info_to_howto rtype_to_howto
295 bfd_reloc_code_real_type bfd_val
;
298 { BFD_RELOC_NONE
, R_VAX_NONE
},
299 { BFD_RELOC_32
, R_VAX_32
},
300 { BFD_RELOC_16
, R_VAX_16
},
301 { BFD_RELOC_8
, R_VAX_8
},
302 { BFD_RELOC_32_PCREL
, R_VAX_PC32
},
303 { BFD_RELOC_16_PCREL
, R_VAX_PC16
},
304 { BFD_RELOC_8_PCREL
, R_VAX_PC8
},
305 { BFD_RELOC_32_GOT_PCREL
, R_VAX_GOT32
},
306 { BFD_RELOC_32_PLT_PCREL
, R_VAX_PLT32
},
307 { BFD_RELOC_NONE
, R_VAX_COPY
},
308 { BFD_RELOC_VAX_GLOB_DAT
, R_VAX_GLOB_DAT
},
309 { BFD_RELOC_VAX_JMP_SLOT
, R_VAX_JMP_SLOT
},
310 { BFD_RELOC_VAX_RELATIVE
, R_VAX_RELATIVE
},
311 { BFD_RELOC_CTOR
, R_VAX_32
},
312 { BFD_RELOC_VTABLE_INHERIT
, R_VAX_GNU_VTINHERIT
},
313 { BFD_RELOC_VTABLE_ENTRY
, R_VAX_GNU_VTENTRY
},
316 static reloc_howto_type
*
317 reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_reloc_code_real_type code
)
320 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
322 if (reloc_map
[i
].bfd_val
== code
)
323 return &howto_table
[reloc_map
[i
].elf_val
];
328 static reloc_howto_type
*
329 reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
334 for (i
= 0; i
< sizeof (howto_table
) / sizeof (howto_table
[0]); i
++)
335 if (howto_table
[i
].name
!= NULL
336 && strcasecmp (howto_table
[i
].name
, r_name
) == 0)
337 return &howto_table
[i
];
342 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
343 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
344 #define ELF_ARCH bfd_arch_vax
345 /* end code generated by elf.el */
347 /* Functions for the VAX ELF linker. */
349 /* The name of the dynamic interpreter. This is put in the .interp
352 #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
354 /* The size in bytes of an entry in the procedure linkage table. */
356 #define PLT_ENTRY_SIZE 12
358 /* The first entry in a procedure linkage table looks like this. See
359 the SVR4 ABI VAX supplement to see how this works. */
361 static const bfd_byte elf_vax_plt0_entry
[PLT_ENTRY_SIZE
] =
363 0xdd, 0xef, /* pushl l^ */
364 0, 0, 0, 0, /* offset to .plt.got + 4 */
365 0x17, 0xff, /* jmp @L^(pc) */
366 0, 0, 0, 0, /* offset to .plt.got + 8 */
369 /* Subsequent entries in a procedure linkage table look like this. */
371 static const bfd_byte elf_vax_plt_entry
[PLT_ENTRY_SIZE
] =
373 0xfc, 0x0f, /* .word ^M<r11:r2> */
374 0x16, 0xef, /* jsb L^(pc) */
375 0, 0, 0, 0, /* replaced with offset to start of .plt */
376 0, 0, 0, 0, /* index into .rela.plt */
379 /* The VAX linker needs to keep track of the number of relocs that it
380 decides to copy in check_relocs for each symbol. This is so that it
381 can discard PC relative relocs if it doesn't need them when linking
382 with -Bsymbolic. We store the information in a field extending the
383 regular ELF linker hash table. */
385 /* This structure keeps track of the number of PC relative relocs we have
386 copied for a given symbol. */
388 struct elf_vax_pcrel_relocs_copied
391 struct elf_vax_pcrel_relocs_copied
*next
;
392 /* A section in dynobj. */
394 /* Number of relocs copied in this section. */
398 /* VAX ELF linker hash entry. */
400 struct elf_vax_link_hash_entry
402 struct elf_link_hash_entry root
;
404 /* Number of PC relative relocs copied for this symbol. */
405 struct elf_vax_pcrel_relocs_copied
*pcrel_relocs_copied
;
410 /* VAX ELF linker hash table. */
412 struct elf_vax_link_hash_table
414 struct elf_link_hash_table root
;
417 /* Declare this now that the above structures are defined. */
419 static bfd_boolean
elf_vax_discard_copies (struct elf_vax_link_hash_entry
*,
422 /* Declare this now that the above structures are defined. */
424 static bfd_boolean
elf_vax_instantiate_got_entries (struct elf_link_hash_entry
*,
427 /* Traverse an VAX ELF linker hash table. */
429 #define elf_vax_link_hash_traverse(table, func, info) \
430 (elf_link_hash_traverse \
432 (bfd_boolean (*) (struct elf_link_hash_entry *, PTR)) (func), \
435 /* Get the VAX ELF linker hash table from a link_info structure. */
437 #define elf_vax_hash_table(p) ((struct elf_vax_link_hash_table *) (p)->hash)
439 /* Create an entry in an VAX ELF linker hash table. */
441 static struct bfd_hash_entry
*
442 elf_vax_link_hash_newfunc (struct bfd_hash_entry
*entry
,
443 struct bfd_hash_table
*table
,
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
452 ret
= ((struct elf_vax_link_hash_entry
*)
453 bfd_hash_allocate (table
,
454 sizeof (struct elf_vax_link_hash_entry
)));
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
,
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 (bfd
*abfd
)
475 struct elf_vax_link_hash_table
*ret
;
476 bfd_size_type amt
= sizeof (struct elf_vax_link_hash_table
);
478 ret
= bfd_malloc (amt
);
482 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
483 elf_vax_link_hash_newfunc
,
484 sizeof (struct elf_vax_link_hash_entry
)))
490 return &ret
->root
.root
;
493 /* Keep vax-specific flags in the ELF header */
495 elf32_vax_set_private_flags (bfd
*abfd
, flagword flags
)
497 elf_elfheader (abfd
)->e_flags
= flags
;
498 elf_flags_init (abfd
) = TRUE
;
502 /* Merge backend specific data from an object file to the output
503 object file when linking. */
505 elf32_vax_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
510 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
511 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
514 in_flags
= elf_elfheader (ibfd
)->e_flags
;
515 out_flags
= elf_elfheader (obfd
)->e_flags
;
517 if (!elf_flags_init (obfd
))
519 elf_flags_init (obfd
) = TRUE
;
520 elf_elfheader (obfd
)->e_flags
= in_flags
;
526 /* Display the flags field */
528 elf32_vax_print_private_bfd_data (bfd
*abfd
, PTR ptr
)
530 FILE *file
= (FILE *) ptr
;
532 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
534 /* Print normal ELF private data. */
535 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
537 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
539 /* xgettext:c-format */
540 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
542 if (elf_elfheader (abfd
)->e_flags
& EF_VAX_NONPIC
)
543 fprintf (file
, _(" [nonpic]"));
545 if (elf_elfheader (abfd
)->e_flags
& EF_VAX_DFLOAT
)
546 fprintf (file
, _(" [d-float]"));
548 if (elf_elfheader (abfd
)->e_flags
& EF_VAX_GFLOAT
)
549 fprintf (file
, _(" [g-float]"));
555 /* Look through the relocs for a section during the first phase, and
556 allocate space in the global offset table or procedure linkage
560 elf_vax_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
561 const Elf_Internal_Rela
*relocs
)
564 Elf_Internal_Shdr
*symtab_hdr
;
565 struct elf_link_hash_entry
**sym_hashes
;
566 const Elf_Internal_Rela
*rel
;
567 const Elf_Internal_Rela
*rel_end
;
572 if (info
->relocatable
)
575 dynobj
= elf_hash_table (info
)->dynobj
;
576 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
577 sym_hashes
= elf_sym_hashes (abfd
);
583 rel_end
= relocs
+ sec
->reloc_count
;
584 for (rel
= relocs
; rel
< rel_end
; rel
++)
586 unsigned long r_symndx
;
587 struct elf_link_hash_entry
*h
;
589 r_symndx
= ELF32_R_SYM (rel
->r_info
);
591 if (r_symndx
< symtab_hdr
->sh_info
)
595 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
596 while (h
->root
.type
== bfd_link_hash_indirect
597 || h
->root
.type
== bfd_link_hash_warning
)
598 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
601 switch (ELF32_R_TYPE (rel
->r_info
))
604 BFD_ASSERT (h
!= NULL
);
606 || h
== elf_hash_table (info
)->hgot
607 || h
== elf_hash_table (info
)->hplt
)
610 /* If this is a local symbol, we resolve it directly without
611 creating a global offset table entry. */
612 if (h
== NULL
|| ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
615 /* This symbol requires a global offset table entry. */
619 /* Create the .got section. */
620 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
621 if (!_bfd_elf_create_got_section (dynobj
, info
))
627 sgot
= bfd_get_section_by_name (dynobj
, ".got");
628 BFD_ASSERT (sgot
!= NULL
);
632 && (h
!= NULL
|| info
->shared
))
634 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
637 srelgot
= bfd_make_section_with_flags (dynobj
,
646 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
653 struct elf_vax_link_hash_entry
*eh
;
655 eh
= (struct elf_vax_link_hash_entry
*) h
;
656 if (h
->got
.refcount
== -1)
659 eh
->got_addend
= rel
->r_addend
;
664 if (eh
->got_addend
!= (bfd_vma
) rel
->r_addend
)
665 (*_bfd_error_handler
)
666 (_("%s: warning: GOT addend of %ld to `%s' does"
667 " not match previous GOT addend of %ld"),
668 bfd_get_filename (abfd
), rel
->r_addend
,
677 /* This symbol requires a procedure linkage table entry. We
678 actually build the entry in adjust_dynamic_symbol,
679 because this might be a case of linking PIC code which is
680 never referenced by a dynamic object, in which case we
681 don't need to generate a procedure linkage table entry
684 /* If this is a local symbol, we resolve it directly without
685 creating a procedure linkage table entry. */
686 BFD_ASSERT (h
!= NULL
);
687 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
|| h
->forced_local
)
691 if (h
->plt
.refcount
== -1)
700 /* If we are creating a shared library and this is not a local
701 symbol, we need to copy the reloc into the shared library.
702 However when linking with -Bsymbolic and this is a global
703 symbol which is defined in an object we are including in the
704 link (i.e., DEF_REGULAR is set), then we can resolve the
705 reloc directly. At this point we have not seen all the input
706 files, so it is possible that DEF_REGULAR is not set now but
707 will be set later (it is never cleared). We account for that
708 possibility below by storing information in the
709 pcrel_relocs_copied field of the hash table entry. */
711 && (sec
->flags
& SEC_ALLOC
) != 0
714 || !h
->def_regular
)))
717 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
720 /* Make sure a plt entry is created for this symbol if
721 it turns out to be a function defined by a dynamic
723 if (h
->plt
.refcount
== -1)
730 /* If this is a local symbol, we can resolve it directly. */
732 && (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
740 if (h
!= NULL
&& ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
742 /* Make sure a plt entry is created for this symbol if it
743 turns out to be a function defined by a dynamic object. */
744 if (h
->plt
.refcount
== -1)
750 /* If we are creating a shared library, we need to copy the
751 reloc into the shared library. */
753 && (sec
->flags
& SEC_ALLOC
) != 0)
755 /* When creating a shared object, we must copy these
756 reloc types into the output file. We create a reloc
757 section in dynobj and make room for this reloc. */
760 sreloc
= _bfd_elf_make_dynamic_reloc_section
761 (sec
, dynobj
, 2, abfd
, /*rela?*/ TRUE
);
766 if (sec
->flags
& SEC_READONLY
)
767 info
->flags
|= DF_TEXTREL
;
770 sreloc
->size
+= sizeof (Elf32_External_Rela
);
772 /* If we are linking with -Bsymbolic, we count the number of
773 PC relative relocations we have entered for this symbol,
774 so that we can discard them again if the symbol is later
775 defined by a regular object. Note that this function is
776 only called if we are using a vaxelf linker hash table,
777 which means that h is really a pointer to an
778 elf_vax_link_hash_entry. */
779 if ((ELF32_R_TYPE (rel
->r_info
) == R_VAX_PC8
780 || ELF32_R_TYPE (rel
->r_info
) == R_VAX_PC16
781 || ELF32_R_TYPE (rel
->r_info
) == R_VAX_PC32
)
784 struct elf_vax_link_hash_entry
*eh
;
785 struct elf_vax_pcrel_relocs_copied
*p
;
787 eh
= (struct elf_vax_link_hash_entry
*) h
;
789 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
790 if (p
->section
== sreloc
)
795 p
= ((struct elf_vax_pcrel_relocs_copied
*)
796 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
799 p
->next
= eh
->pcrel_relocs_copied
;
800 eh
->pcrel_relocs_copied
= p
;
811 /* This relocation describes the C++ object vtable hierarchy.
812 Reconstruct it for later use during GC. */
813 case R_VAX_GNU_VTINHERIT
:
814 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
818 /* This relocation describes which C++ vtable entries are actually
819 used. Record for later use during GC. */
820 case R_VAX_GNU_VTENTRY
:
821 BFD_ASSERT (h
!= NULL
);
823 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
835 /* Return the section that should be marked against GC for a given
839 elf_vax_gc_mark_hook (asection
*sec
,
840 struct bfd_link_info
*info
,
841 Elf_Internal_Rela
*rel
,
842 struct elf_link_hash_entry
*h
,
843 Elf_Internal_Sym
*sym
)
846 switch (ELF32_R_TYPE (rel
->r_info
))
848 case R_VAX_GNU_VTINHERIT
:
849 case R_VAX_GNU_VTENTRY
:
853 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
856 /* Update the got entry reference counts for the section being removed. */
859 elf_vax_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
860 const Elf_Internal_Rela
*relocs
)
862 Elf_Internal_Shdr
*symtab_hdr
;
863 struct elf_link_hash_entry
**sym_hashes
;
864 const Elf_Internal_Rela
*rel
, *relend
;
867 if (info
->relocatable
)
870 dynobj
= elf_hash_table (info
)->dynobj
;
874 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
875 sym_hashes
= elf_sym_hashes (abfd
);
877 relend
= relocs
+ sec
->reloc_count
;
878 for (rel
= relocs
; rel
< relend
; rel
++)
880 unsigned long r_symndx
;
881 struct elf_link_hash_entry
*h
= NULL
;
883 r_symndx
= ELF32_R_SYM (rel
->r_info
);
884 if (r_symndx
>= symtab_hdr
->sh_info
)
886 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
887 while (h
->root
.type
== bfd_link_hash_indirect
888 || h
->root
.type
== bfd_link_hash_warning
)
889 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
892 switch (ELF32_R_TYPE (rel
->r_info
))
895 if (h
!= NULL
&& h
->got
.refcount
> 0)
906 if (h
!= NULL
&& h
->plt
.refcount
> 0)
918 /* Adjust a symbol defined by a dynamic object and referenced by a
919 regular object. The current definition is in some section of the
920 dynamic object, but we're not including those sections. We have to
921 change the definition to something the rest of the link can
925 elf_vax_adjust_dynamic_symbol (info
, h
)
926 struct bfd_link_info
*info
;
927 struct elf_link_hash_entry
*h
;
932 dynobj
= elf_hash_table (info
)->dynobj
;
934 /* Make sure we know what is going on here. */
935 BFD_ASSERT (dynobj
!= NULL
937 || h
->u
.weakdef
!= NULL
940 && !h
->def_regular
)));
942 /* If this is a function, put it in the procedure linkage table. We
943 will fill in the contents of the procedure linkage table later,
944 when we know the address of the .got section. */
945 if (h
->type
== STT_FUNC
951 /* We must always create the plt entry if it was referenced
952 by a PLTxxO relocation. In this case we already recorded
953 it as a dynamic symbol. */
956 /* This case can occur if we saw a PLTxx reloc in an input
957 file, but the symbol was never referred to by a dynamic
958 object. In such a case, we don't actually need to build
959 a procedure linkage table, and we can just do a PCxx
961 BFD_ASSERT (h
->needs_plt
);
962 h
->plt
.offset
= (bfd_vma
) -1;
966 /* GC may have rendered this entry unused. */
967 if (h
->plt
.refcount
<= 0)
970 h
->plt
.offset
= (bfd_vma
) -1;
974 /* Make sure this symbol is output as a dynamic symbol. */
975 if (h
->dynindx
== -1)
977 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
981 s
= bfd_get_section_by_name (dynobj
, ".plt");
982 BFD_ASSERT (s
!= NULL
);
984 /* If this is the first .plt entry, make room for the special
988 s
->size
+= PLT_ENTRY_SIZE
;
991 /* If this symbol is not defined in a regular file, and we are
992 not generating a shared library, then set the symbol to this
993 location in the .plt. This is required to make function
994 pointers compare as equal between the normal executable and
995 the shared library. */
999 h
->root
.u
.def
.section
= s
;
1000 h
->root
.u
.def
.value
= s
->size
;
1003 h
->plt
.offset
= s
->size
;
1005 /* Make room for this entry. */
1006 s
->size
+= PLT_ENTRY_SIZE
;
1008 /* We also need to make an entry in the .got.plt section, which
1009 will be placed in the .got section by the linker script. */
1011 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
1012 BFD_ASSERT (s
!= NULL
);
1015 /* We also need to make an entry in the .rela.plt section. */
1017 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1018 BFD_ASSERT (s
!= NULL
);
1019 s
->size
+= sizeof (Elf32_External_Rela
);
1024 /* Reinitialize the plt offset now that it is not used as a reference
1026 h
->plt
.offset
= (bfd_vma
) -1;
1028 /* If this is a weak symbol, and there is a real definition, the
1029 processor independent code will have arranged for us to see the
1030 real definition first, and we can just use the same value. */
1031 if (h
->u
.weakdef
!= NULL
)
1033 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1034 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1035 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1036 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1040 /* This is a reference to a symbol defined by a dynamic object which
1041 is not a function. */
1043 /* If we are creating a shared library, we must presume that the
1044 only references to the symbol are via the global offset table.
1045 For such cases we need not do anything here; the relocations will
1046 be handled correctly by relocate_section. */
1052 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
1053 h
->root
.root
.string
);
1057 /* We must allocate the symbol in our .dynbss section, which will
1058 become part of the .bss section of the executable. There will be
1059 an entry for this symbol in the .dynsym section. The dynamic
1060 object will contain position independent code, so all references
1061 from the dynamic object to this symbol will go through the global
1062 offset table. The dynamic linker will use the .dynsym entry to
1063 determine the address it must put in the global offset table, so
1064 both the dynamic object and the regular object will refer to the
1065 same memory location for the variable. */
1067 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1068 BFD_ASSERT (s
!= NULL
);
1070 /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
1071 copy the initial value out of the dynamic object and into the
1072 runtime process image. We need to remember the offset into the
1073 .rela.bss section we are going to use. */
1074 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1078 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1079 BFD_ASSERT (srel
!= NULL
);
1080 srel
->size
+= sizeof (Elf32_External_Rela
);
1084 return _bfd_elf_adjust_dynamic_copy (h
, s
);
1087 /* Set the sizes of the dynamic sections. */
1090 elf_vax_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1096 bfd_boolean reltext
;
1098 dynobj
= elf_hash_table (info
)->dynobj
;
1099 BFD_ASSERT (dynobj
!= NULL
);
1101 if (elf_hash_table (info
)->dynamic_sections_created
)
1103 /* Set the contents of the .interp section to the interpreter. */
1104 if (info
->executable
)
1106 s
= bfd_get_section_by_name (dynobj
, ".interp");
1107 BFD_ASSERT (s
!= NULL
);
1108 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1109 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1114 /* We may have created entries in the .rela.got and .got sections.
1115 However, if we are not creating the dynamic sections, we will
1116 not actually use these entries. Reset the size of .rela.got
1117 and .got, which will cause it to get stripped from the output
1119 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1122 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
1125 s
= bfd_get_section_by_name (dynobj
, ".got");
1130 /* If this is a -Bsymbolic shared link, then we need to discard all PC
1131 relative relocs against symbols defined in a regular object. We
1132 allocated space for them in the check_relocs routine, but we will not
1133 fill them in in the relocate_section routine. */
1134 if (info
->shared
&& info
->symbolic
)
1135 elf_vax_link_hash_traverse (elf_vax_hash_table (info
),
1136 elf_vax_discard_copies
,
1139 /* If this is a -Bsymbolic shared link or a static link, we need to
1140 discard all the got entries we've recorded. Otherwise, we need to
1141 instantiate (allocate space for them). */
1142 elf_link_hash_traverse (elf_hash_table (info
),
1143 elf_vax_instantiate_got_entries
,
1146 /* The check_relocs and adjust_dynamic_symbol entry points have
1147 determined the sizes of the various dynamic sections. Allocate
1152 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1156 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1159 /* It's OK to base decisions on the section name, because none
1160 of the dynobj section names depend upon the input files. */
1161 name
= bfd_get_section_name (dynobj
, s
);
1163 if (strcmp (name
, ".plt") == 0)
1165 /* Remember whether there is a PLT. */
1168 else if (CONST_STRNEQ (name
, ".rela"))
1174 /* Remember whether there are any reloc sections other
1176 if (strcmp (name
, ".rela.plt") != 0)
1178 const char *outname
;
1182 /* If this relocation section applies to a read only
1183 section, then we probably need a DT_TEXTREL
1184 entry. .rela.plt is actually associated with
1185 .got.plt, which is never readonly. */
1186 outname
= bfd_get_section_name (output_bfd
,
1188 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
1190 && (target
->flags
& SEC_READONLY
) != 0
1191 && (target
->flags
& SEC_ALLOC
) != 0)
1195 /* We use the reloc_count field as a counter if we need
1196 to copy relocs into the output file. */
1200 else if (! CONST_STRNEQ (name
, ".got")
1201 && strcmp (name
, ".dynbss") != 0)
1203 /* It's not one of our sections, so don't allocate space. */
1209 /* If we don't need this section, strip it from the
1210 output file. This is mostly to handle .rela.bss and
1211 .rela.plt. We must create both sections in
1212 create_dynamic_sections, because they must be created
1213 before the linker maps input sections to output
1214 sections. The linker does that before
1215 adjust_dynamic_symbol is called, and it is that
1216 function which decides whether anything needs to go
1217 into these sections. */
1218 s
->flags
|= SEC_EXCLUDE
;
1222 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
1225 /* Allocate memory for the section contents. */
1226 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->size
);
1227 if (s
->contents
== NULL
)
1231 if (elf_hash_table (info
)->dynamic_sections_created
)
1233 /* Add some entries to the .dynamic section. We fill in the
1234 values later, in elf_vax_finish_dynamic_sections, but we
1235 must add the entries now so that we get the correct size for
1236 the .dynamic section. The DT_DEBUG entry is filled in by the
1237 dynamic linker and used by the debugger. */
1238 #define add_dynamic_entry(TAG, VAL) \
1239 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1243 if (!add_dynamic_entry (DT_DEBUG
, 0))
1249 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1250 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1251 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1252 || !add_dynamic_entry (DT_JMPREL
, 0))
1258 if (!add_dynamic_entry (DT_RELA
, 0)
1259 || !add_dynamic_entry (DT_RELASZ
, 0)
1260 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
1264 if (reltext
|| (info
->flags
& DF_TEXTREL
) != 0)
1266 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1270 #undef add_dynamic_entry
1275 /* This function is called via elf_vax_link_hash_traverse if we are
1276 creating a shared object with -Bsymbolic. It discards the space
1277 allocated to copy PC relative relocs against symbols which are defined
1278 in regular objects. We allocated space for them in the check_relocs
1279 routine, but we won't fill them in in the relocate_section routine. */
1282 elf_vax_discard_copies (struct elf_vax_link_hash_entry
*h
,
1283 PTR ignore ATTRIBUTE_UNUSED
)
1285 struct elf_vax_pcrel_relocs_copied
*s
;
1287 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1288 h
= (struct elf_vax_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1290 /* We only discard relocs for symbols defined in a regular object. */
1291 if (!h
->root
.def_regular
)
1294 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
1295 s
->section
->size
-= s
->count
* sizeof (Elf32_External_Rela
);
1300 /* This function is called via elf_link_hash_traverse. It looks for entries
1301 that have GOT or PLT (.GOT) references. If creating a static object or a
1302 shared object with -Bsymbolic, it resets the reference count back to 0
1303 and sets the offset to -1 so normal PC32 relocation will be done. If
1304 creating a shared object or executable, space in the .got and .rela.got
1305 will be reserved for the symbol. */
1308 elf_vax_instantiate_got_entries (struct elf_link_hash_entry
*h
, PTR infoptr
)
1310 struct bfd_link_info
*info
= (struct bfd_link_info
*) infoptr
;
1315 /* We don't care about non-GOT (and non-PLT) entries. */
1316 if (h
->got
.refcount
<= 0 && h
->plt
.refcount
<= 0)
1319 dynobj
= elf_hash_table (info
)->dynobj
;
1323 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1324 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1326 if (!elf_hash_table (info
)->dynamic_sections_created
1327 || (info
->shared
&& info
->symbolic
)
1330 h
->got
.refcount
= 0;
1331 h
->got
.offset
= (bfd_vma
) -1;
1332 h
->plt
.refcount
= 0;
1333 h
->plt
.offset
= (bfd_vma
) -1;
1335 else if (h
->got
.refcount
> 0)
1339 /* Make sure this symbol is output as a dynamic symbol. */
1340 if (h
->dynindx
== -1)
1342 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
1346 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
1347 /* Allocate space in the .got and .rela.got sections. */
1348 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1350 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
1353 srelgot
->size
+= sizeof (Elf32_External_Rela
);
1360 /* Relocate an VAX ELF section. */
1363 elf_vax_relocate_section (bfd
*output_bfd
,
1364 struct bfd_link_info
*info
,
1366 asection
*input_section
,
1368 Elf_Internal_Rela
*relocs
,
1369 Elf_Internal_Sym
*local_syms
,
1370 asection
**local_sections
)
1373 Elf_Internal_Shdr
*symtab_hdr
;
1374 struct elf_link_hash_entry
**sym_hashes
;
1375 bfd_vma
*local_got_offsets
;
1382 Elf_Internal_Rela
*rel
;
1383 Elf_Internal_Rela
*relend
;
1385 dynobj
= elf_hash_table (info
)->dynobj
;
1386 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1387 sym_hashes
= elf_sym_hashes (input_bfd
);
1388 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1396 relend
= relocs
+ input_section
->reloc_count
;
1397 for (; rel
< relend
; rel
++)
1400 reloc_howto_type
*howto
;
1401 unsigned long r_symndx
;
1402 struct elf_link_hash_entry
*h
;
1403 Elf_Internal_Sym
*sym
;
1406 bfd_reloc_status_type r
;
1408 r_type
= ELF32_R_TYPE (rel
->r_info
);
1409 if (r_type
< 0 || r_type
>= (int) R_VAX_max
)
1411 bfd_set_error (bfd_error_bad_value
);
1414 howto
= howto_table
+ r_type
;
1416 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1420 if (r_symndx
< symtab_hdr
->sh_info
)
1422 sym
= local_syms
+ r_symndx
;
1423 sec
= local_sections
[r_symndx
];
1424 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1428 bfd_boolean unresolved_reloc
;
1431 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1432 r_symndx
, symtab_hdr
, sym_hashes
,
1434 unresolved_reloc
, warned
);
1436 if ((h
->root
.type
== bfd_link_hash_defined
1437 || h
->root
.type
== bfd_link_hash_defweak
)
1438 && ((r_type
== R_VAX_PLT32
1439 && h
->plt
.offset
!= (bfd_vma
) -1
1441 && elf_hash_table (info
)->dynamic_sections_created
)
1442 || (r_type
== R_VAX_GOT32
1443 && h
->got
.offset
!= (bfd_vma
) -1
1445 && elf_hash_table (info
)->dynamic_sections_created
1447 || (! info
->symbolic
&& h
->dynindx
!= -1)
1448 || !h
->def_regular
))
1450 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1452 && ((input_section
->flags
& SEC_ALLOC
) != 0
1453 /* DWARF will emit R_VAX_32 relocations in its
1454 sections against symbols defined externally
1455 in shared libraries. We can't do anything
1458 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
1460 && (r_type
== R_VAX_8
1461 || r_type
== R_VAX_16
1462 || r_type
== R_VAX_32
))))
1463 /* In these cases, we don't need the relocation
1464 value. We check specially because in some
1465 obscure cases sec->output_section will be NULL. */
1469 if (sec
!= NULL
&& elf_discarded_section (sec
))
1471 /* For relocs against symbols from removed linkonce sections,
1472 or sections discarded by a linker script, we just want the
1473 section contents zeroed. Avoid any special processing. */
1474 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
1480 if (info
->relocatable
)
1486 /* Relocation is to the address of the entry for this symbol
1487 in the global offset table. */
1489 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1490 || h
->got
.offset
== (bfd_vma
) -1
1494 /* Relocation is the offset of the entry for this symbol in
1495 the global offset table. */
1503 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1504 BFD_ASSERT (sgot
!= NULL
);
1507 BFD_ASSERT (h
!= NULL
);
1508 off
= h
->got
.offset
;
1509 BFD_ASSERT (off
!= (bfd_vma
) -1);
1510 BFD_ASSERT (off
< sgot
->size
);
1512 dyn
= elf_hash_table (info
)->dynamic_sections_created
;
1513 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
1515 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
1517 /* The symbol was forced to be local
1518 because of a version file.. We must initialize
1519 this entry in the global offset table. Since
1520 the offset must always be a multiple of 4, we
1521 use the least significant bit to record whether
1522 we have initialized it already.
1524 When doing a dynamic link, we create a .rela.got
1525 relocation entry to initialize the value. This
1526 is done in the finish_dynamic_symbol routine. */
1531 bfd_put_32 (output_bfd
, relocation
+ rel
->r_addend
,
1532 sgot
->contents
+ off
);
1536 bfd_put_32 (output_bfd
, rel
->r_addend
, sgot
->contents
+ off
);
1539 relocation
= sgot
->output_offset
+ off
;
1540 /* The GOT relocation uses the addend. */
1543 /* Change the reference to be indirect. */
1544 contents
[rel
->r_offset
- 1] |= 0x10;
1545 relocation
+= sgot
->output_section
->vma
;
1550 /* If we are creating an executable and the function this
1551 reloc refers to is in a shared lib, then we made a PLT
1552 entry for this symbol and need to handle the reloc like
1555 goto r_vax_pc32_shared
;
1558 /* Relocation is to the entry for this symbol in the
1559 procedure linkage table. */
1561 /* Resolve a PLTxx reloc against a local symbol directly,
1562 without using the procedure linkage table. */
1564 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1568 if (h
->plt
.offset
== (bfd_vma
) -1
1569 || !elf_hash_table (info
)->dynamic_sections_created
)
1571 /* We didn't make a PLT entry for this symbol. This
1572 happens when statically linking PIC code, or when
1573 using -Bsymbolic. */
1579 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1580 BFD_ASSERT (splt
!= NULL
);
1583 if (sgotplt
== NULL
)
1585 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1586 BFD_ASSERT (sgotplt
!= NULL
);
1589 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1591 /* Get the offset into the .got table of the entry that
1592 corresponds to this function. Each .got entry is 4 bytes.
1593 The first two are reserved. */
1594 got_offset
= (plt_index
+ 3) * 4;
1596 /* We want the relocation to point into the .got.plt instead
1597 of the plt itself. */
1598 relocation
= (sgotplt
->output_section
->vma
1599 + sgotplt
->output_offset
1601 contents
[rel
->r_offset
-1] |= 0x10; /* make indirect */
1602 if (rel
->r_addend
== 2)
1606 else if (rel
->r_addend
!= 0)
1607 (*_bfd_error_handler
)
1608 (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"),
1609 bfd_get_filename (input_bfd
), rel
->r_addend
,
1610 h
->root
.root
.string
,
1611 bfd_get_section_name (input_bfd
, input_section
));
1620 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1629 && (input_section
->flags
& SEC_ALLOC
) != 0
1630 && ((r_type
!= R_VAX_PC8
1631 && r_type
!= R_VAX_PC16
1632 && r_type
!= R_VAX_PC32
)
1633 || ((input_section
->flags
& SEC_CODE
)
1635 || (!h
->def_regular
&& h
->type
!= STT_SECTION
)))))
1637 Elf_Internal_Rela outrel
;
1639 bfd_boolean skip
, relocate
;
1641 /* When generating a shared object, these relocations
1642 are copied into the output file to be resolved at run
1646 sreloc
= _bfd_elf_get_dynamic_reloc_section
1647 (input_bfd
, input_section
, /*rela?*/ TRUE
);
1656 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1658 if (outrel
.r_offset
== (bfd_vma
) -1)
1660 if (outrel
.r_offset
== (bfd_vma
) -2)
1661 skip
= TRUE
, relocate
= TRUE
;
1662 outrel
.r_offset
+= (input_section
->output_section
->vma
1663 + input_section
->output_offset
);
1666 memset (&outrel
, 0, sizeof outrel
);
1667 /* h->dynindx may be -1 if the symbol was marked to
1670 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1671 || !h
->def_regular
))
1673 BFD_ASSERT (h
->dynindx
!= -1);
1674 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1675 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1679 if (r_type
== R_VAX_32
)
1682 outrel
.r_info
= ELF32_R_INFO (0, R_VAX_RELATIVE
);
1683 BFD_ASSERT (bfd_get_signed_32 (input_bfd
,
1684 &contents
[rel
->r_offset
]) == 0);
1685 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1691 if (bfd_is_abs_section (sec
))
1693 else if (sec
== NULL
|| sec
->owner
== NULL
)
1695 bfd_set_error (bfd_error_bad_value
);
1702 /* We are turning this relocation into one
1703 against a section symbol. It would be
1704 proper to subtract the symbol's value,
1705 osec->vma, from the emitted reloc addend,
1706 but ld.so expects buggy relocs. */
1707 osec
= sec
->output_section
;
1708 indx
= elf_section_data (osec
)->dynindx
;
1711 struct elf_link_hash_table
*htab
;
1712 htab
= elf_hash_table (info
);
1713 osec
= htab
->text_index_section
;
1714 indx
= elf_section_data (osec
)->dynindx
;
1716 BFD_ASSERT (indx
!= 0);
1719 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1720 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1724 if (!strcmp (bfd_get_section_name (input_bfd
, input_section
),
1727 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_32
1728 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_RELATIVE
1729 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_COPY
1730 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_JMP_SLOT
1731 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_GLOB_DAT
))
1734 (*_bfd_error_handler
)
1735 (_("%s: warning: %s relocation against symbol `%s' from %s section"),
1736 bfd_get_filename (input_bfd
), howto
->name
,
1737 h
->root
.root
.string
,
1738 bfd_get_section_name (input_bfd
, input_section
));
1740 (*_bfd_error_handler
)
1741 (_("%s: warning: %s relocation to 0x%x from %s section"),
1742 bfd_get_filename (input_bfd
), howto
->name
,
1744 bfd_get_section_name (input_bfd
, input_section
));
1746 loc
= sreloc
->contents
;
1747 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1748 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1750 /* This reloc will be computed at runtime, so there's no
1751 need to do anything now, except for R_VAX_32
1752 relocations that have been turned into
1760 case R_VAX_GNU_VTINHERIT
:
1761 case R_VAX_GNU_VTENTRY
:
1762 /* These are no-ops in the end. */
1769 /* VAX PCREL relocations are from the end of relocation, not the start.
1770 So subtract the difference from the relocation amount since we can't
1771 add it to the offset. */
1772 if (howto
->pc_relative
&& howto
->pcrel_offset
)
1773 relocation
-= bfd_get_reloc_size(howto
);
1775 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1776 contents
, rel
->r_offset
,
1777 relocation
, rel
->r_addend
);
1779 if (r
!= bfd_reloc_ok
)
1784 case bfd_reloc_outofrange
:
1786 case bfd_reloc_overflow
:
1794 name
= bfd_elf_string_from_elf_section (input_bfd
,
1795 symtab_hdr
->sh_link
,
1800 name
= bfd_section_name (input_bfd
, sec
);
1802 if (!(info
->callbacks
->reloc_overflow
1803 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
1804 (bfd_vma
) 0, input_bfd
, input_section
,
1816 /* Finish up dynamic symbol handling. We set the contents of various
1817 dynamic sections here. */
1820 elf_vax_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
1821 struct elf_link_hash_entry
*h
,
1822 Elf_Internal_Sym
*sym
)
1826 dynobj
= elf_hash_table (info
)->dynobj
;
1828 if (h
->plt
.offset
!= (bfd_vma
) -1)
1836 Elf_Internal_Rela rela
;
1839 /* This symbol has an entry in the procedure linkage table. Set
1841 BFD_ASSERT (h
->dynindx
!= -1);
1843 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1844 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1845 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1846 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1848 addend
= 2 * (h
->plt
.offset
& 1);
1849 h
->plt
.offset
&= ~1;
1851 /* Get the index in the procedure linkage table which
1852 corresponds to this symbol. This is the index of this symbol
1853 in all the symbols for which we are making plt entries. The
1854 first entry in the procedure linkage table is reserved. */
1855 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1857 /* Get the offset into the .got table of the entry that
1858 corresponds to this function. Each .got entry is 4 bytes.
1859 The first two are reserved. */
1860 got_offset
= (plt_index
+ 3) * 4;
1862 /* Fill in the entry in the procedure linkage table. */
1863 memcpy (splt
->contents
+ h
->plt
.offset
, elf_vax_plt_entry
,
1866 /* The offset is relative to the first extension word. */
1867 bfd_put_32 (output_bfd
,
1868 -(h
->plt
.offset
+ 8),
1869 splt
->contents
+ h
->plt
.offset
+ 4);
1871 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
1872 splt
->contents
+ h
->plt
.offset
+ 8);
1874 /* Fill in the entry in the global offset table. */
1875 bfd_put_32 (output_bfd
,
1876 (splt
->output_section
->vma
1877 + splt
->output_offset
1878 + h
->plt
.offset
) + addend
,
1879 sgot
->contents
+ got_offset
);
1881 /* Fill in the entry in the .rela.plt section. */
1882 rela
.r_offset
= (sgot
->output_section
->vma
1883 + sgot
->output_offset
1885 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_VAX_JMP_SLOT
);
1886 rela
.r_addend
= addend
;
1887 loc
= srela
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
1888 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1890 if (!h
->def_regular
)
1892 /* Mark the symbol as undefined, rather than as defined in
1893 the .plt section. Leave the value alone. */
1894 sym
->st_shndx
= SHN_UNDEF
;
1898 if (h
->got
.offset
!= (bfd_vma
) -1)
1902 Elf_Internal_Rela rela
;
1905 /* This symbol has an entry in the global offset table. Set it
1907 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1908 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1909 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1911 rela
.r_offset
= (sgot
->output_section
->vma
1912 + sgot
->output_offset
1913 + (h
->got
.offset
&~ 1));
1915 /* If the symbol was forced to be local because of a version file
1916 locally we just want to emit a RELATIVE reloc. The entry in
1917 the global offset table will already have been initialized in
1918 the relocate_section function. */
1923 rela
.r_info
= ELF32_R_INFO (0, R_VAX_RELATIVE
);
1927 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_VAX_GLOB_DAT
);
1929 rela
.r_addend
= bfd_get_signed_32 (output_bfd
,
1931 + (h
->got
.offset
& ~1)));
1933 loc
= srela
->contents
;
1934 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1935 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1941 Elf_Internal_Rela rela
;
1944 /* This symbol needs a copy reloc. Set it up. */
1945 BFD_ASSERT (h
->dynindx
!= -1
1946 && (h
->root
.type
== bfd_link_hash_defined
1947 || h
->root
.type
== bfd_link_hash_defweak
));
1949 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1951 BFD_ASSERT (s
!= NULL
);
1953 rela
.r_offset
= (h
->root
.u
.def
.value
1954 + h
->root
.u
.def
.section
->output_section
->vma
1955 + h
->root
.u
.def
.section
->output_offset
);
1956 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_VAX_COPY
);
1958 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1959 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1962 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1963 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1964 || h
== elf_hash_table (info
)->hgot
)
1965 sym
->st_shndx
= SHN_ABS
;
1970 /* Finish up the dynamic sections. */
1973 elf_vax_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
1979 dynobj
= elf_hash_table (info
)->dynobj
;
1981 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1982 BFD_ASSERT (sgot
!= NULL
);
1983 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1985 if (elf_hash_table (info
)->dynamic_sections_created
)
1988 Elf32_External_Dyn
*dyncon
, *dynconend
;
1990 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1991 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1993 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1994 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
1995 for (; dyncon
< dynconend
; dyncon
++)
1997 Elf_Internal_Dyn dyn
;
2001 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2014 s
= bfd_get_section_by_name (output_bfd
, name
);
2015 BFD_ASSERT (s
!= NULL
);
2016 dyn
.d_un
.d_ptr
= s
->vma
;
2017 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2021 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
2022 BFD_ASSERT (s
!= NULL
);
2023 dyn
.d_un
.d_val
= s
->size
;
2024 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2028 /* The procedure linkage table relocs (DT_JMPREL) should
2029 not be included in the overall relocs (DT_RELA).
2030 Therefore, we override the DT_RELASZ entry here to
2031 make it not include the JMPREL relocs. Since the
2032 linker script arranges for .rela.plt to follow all
2033 other relocation sections, we don't have to worry
2034 about changing the DT_RELA entry. */
2035 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
2037 dyn
.d_un
.d_val
-= s
->size
;
2038 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2043 /* Fill in the first entry in the procedure linkage table. */
2046 memcpy (splt
->contents
, elf_vax_plt0_entry
, PLT_ENTRY_SIZE
);
2047 bfd_put_32 (output_bfd
,
2048 (sgot
->output_section
->vma
2049 + sgot
->output_offset
+ 4
2050 - (splt
->output_section
->vma
+ 6)),
2051 splt
->contents
+ 2);
2052 bfd_put_32 (output_bfd
,
2053 (sgot
->output_section
->vma
2054 + sgot
->output_offset
+ 8
2055 - (splt
->output_section
->vma
+ 12)),
2056 splt
->contents
+ 8);
2057 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
2062 /* Fill in the first three entries in the global offset table. */
2066 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2068 bfd_put_32 (output_bfd
,
2069 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2071 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
2072 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
2075 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2080 static enum elf_reloc_type_class
2081 elf_vax_reloc_type_class (const Elf_Internal_Rela
*rela
)
2083 switch ((int) ELF32_R_TYPE (rela
->r_info
))
2085 case R_VAX_RELATIVE
:
2086 return reloc_class_relative
;
2087 case R_VAX_JMP_SLOT
:
2088 return reloc_class_plt
;
2090 return reloc_class_copy
;
2092 return reloc_class_normal
;
2097 elf_vax_plt_sym_val (bfd_vma i
, const asection
*plt
,
2098 const arelent
*rel ATTRIBUTE_UNUSED
)
2100 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
2103 #define TARGET_LITTLE_SYM bfd_elf32_vax_vec
2104 #define TARGET_LITTLE_NAME "elf32-vax"
2105 #define ELF_MACHINE_CODE EM_VAX
2106 #define ELF_MAXPAGESIZE 0x1000
2108 #define elf_backend_create_dynamic_sections \
2109 _bfd_elf_create_dynamic_sections
2110 #define bfd_elf32_bfd_link_hash_table_create \
2111 elf_vax_link_hash_table_create
2112 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
2114 #define elf_backend_check_relocs elf_vax_check_relocs
2115 #define elf_backend_adjust_dynamic_symbol \
2116 elf_vax_adjust_dynamic_symbol
2117 #define elf_backend_size_dynamic_sections \
2118 elf_vax_size_dynamic_sections
2119 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
2120 #define elf_backend_relocate_section elf_vax_relocate_section
2121 #define elf_backend_finish_dynamic_symbol \
2122 elf_vax_finish_dynamic_symbol
2123 #define elf_backend_finish_dynamic_sections \
2124 elf_vax_finish_dynamic_sections
2125 #define elf_backend_reloc_type_class elf_vax_reloc_type_class
2126 #define elf_backend_gc_mark_hook elf_vax_gc_mark_hook
2127 #define elf_backend_gc_sweep_hook elf_vax_gc_sweep_hook
2128 #define elf_backend_plt_sym_val elf_vax_plt_sym_val
2129 #define bfd_elf32_bfd_merge_private_bfd_data \
2130 elf32_vax_merge_private_bfd_data
2131 #define bfd_elf32_bfd_set_private_flags \
2132 elf32_vax_set_private_flags
2133 #define bfd_elf32_bfd_print_private_bfd_data \
2134 elf32_vax_print_private_bfd_data
2136 #define elf_backend_can_gc_sections 1
2137 #define elf_backend_want_got_plt 1
2138 #define elf_backend_plt_readonly 1
2139 #define elf_backend_want_plt_sym 0
2140 #define elf_backend_got_header_size 16
2141 #define elf_backend_rela_normal 1
2143 #include "elf32-target.h"