1 /* VAX series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004 Free Software Foundation, Inc.
4 Contributed by Matt Thomas <matt@3am-software.com>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 static reloc_howto_type
*reloc_type_lookup
30 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
31 static void rtype_to_howto
32 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
33 static struct bfd_hash_entry
*elf_vax_link_hash_newfunc
34 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
35 static struct bfd_link_hash_table
*elf_vax_link_hash_table_create
37 static bfd_boolean elf_vax_check_relocs
38 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
39 const Elf_Internal_Rela
*));
40 static asection
*elf_vax_gc_mark_hook
41 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
42 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
43 static bfd_boolean elf_vax_gc_sweep_hook
44 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
45 const Elf_Internal_Rela
*));
46 static bfd_boolean elf_vax_adjust_dynamic_symbol
47 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
48 static bfd_boolean elf_vax_size_dynamic_sections
49 PARAMS ((bfd
*, struct bfd_link_info
*));
50 static bfd_boolean elf_vax_relocate_section
51 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
52 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
53 static bfd_boolean elf_vax_finish_dynamic_symbol
54 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
56 static bfd_boolean elf_vax_finish_dynamic_sections
57 PARAMS ((bfd
*, struct bfd_link_info
*));
59 static bfd_boolean elf32_vax_set_private_flags
60 PARAMS ((bfd
*, flagword
));
61 static bfd_boolean elf32_vax_merge_private_bfd_data
62 PARAMS ((bfd
*, bfd
*));
63 static bfd_boolean elf32_vax_print_private_bfd_data
64 PARAMS ((bfd
*, PTR
));
66 static reloc_howto_type howto_table
[] = {
67 HOWTO (R_VAX_NONE
, /* type */
69 0, /* size (0 = byte, 1 = short, 2 = long) */
71 FALSE
, /* pc_relative */
73 complain_overflow_dont
, /* complain_on_overflow */
74 bfd_elf_generic_reloc
, /* special_function */
75 "R_VAX_NONE", /* name */
76 FALSE
, /* partial_inplace */
78 0x00000000, /* dst_mask */
79 FALSE
), /* pcrel_offset */
81 HOWTO (R_VAX_32
, /* type */
83 2, /* size (0 = byte, 1 = short, 2 = long) */
85 FALSE
, /* pc_relative */
87 complain_overflow_bitfield
, /* complain_on_overflow */
88 bfd_elf_generic_reloc
, /* special_function */
89 "R_VAX_32", /* name */
90 FALSE
, /* partial_inplace */
92 0xffffffff, /* dst_mask */
93 FALSE
), /* pcrel_offset */
95 HOWTO (R_VAX_16
, /* type */
97 1, /* size (0 = byte, 1 = short, 2 = long) */
99 FALSE
, /* pc_relative */
101 complain_overflow_bitfield
, /* complain_on_overflow */
102 bfd_elf_generic_reloc
, /* special_function */
103 "R_VAX_16", /* name */
104 FALSE
, /* partial_inplace */
106 0x0000ffff, /* dst_mask */
107 FALSE
), /* pcrel_offset */
109 HOWTO (R_VAX_8
, /* type */
111 0, /* size (0 = byte, 1 = short, 2 = long) */
113 FALSE
, /* pc_relative */
115 complain_overflow_bitfield
, /* complain_on_overflow */
116 bfd_elf_generic_reloc
, /* special_function */
117 "R_VAX_8", /* name */
118 FALSE
, /* partial_inplace */
120 0x000000ff, /* dst_mask */
121 FALSE
), /* pcrel_offset */
123 HOWTO (R_VAX_PC32
, /* type */
125 2, /* size (0 = byte, 1 = short, 2 = long) */
127 TRUE
, /* pc_relative */
129 complain_overflow_bitfield
, /* complain_on_overflow */
130 bfd_elf_generic_reloc
, /* special_function */
131 "R_VAX_PC32", /* name */
132 FALSE
, /* partial_inplace */
134 0xffffffff, /* dst_mask */
135 TRUE
), /* pcrel_offset */
137 HOWTO (R_VAX_PC16
, /* type */
139 1, /* size (0 = byte, 1 = short, 2 = long) */
141 TRUE
, /* pc_relative */
143 complain_overflow_signed
, /* complain_on_overflow */
144 bfd_elf_generic_reloc
, /* special_function */
145 "R_VAX_PC16", /* name */
146 FALSE
, /* partial_inplace */
148 0x0000ffff, /* dst_mask */
149 TRUE
), /* pcrel_offset */
151 HOWTO (R_VAX_PC8
, /* type */
153 0, /* size (0 = byte, 1 = short, 2 = long) */
155 TRUE
, /* pc_relative */
157 complain_overflow_signed
, /* complain_on_overflow */
158 bfd_elf_generic_reloc
, /* special_function */
159 "R_VAX_PC8", /* name */
160 FALSE
, /* partial_inplace */
162 0x000000ff, /* dst_mask */
163 TRUE
), /* pcrel_offset */
165 HOWTO (R_VAX_GOT32
, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 TRUE
, /* pc_relative */
171 complain_overflow_bitfield
, /* complain_on_overflow */
172 bfd_elf_generic_reloc
, /* special_function */
173 "R_VAX_GOT32", /* name */
174 FALSE
, /* partial_inplace */
176 0xffffffff, /* dst_mask */
177 TRUE
), /* pcrel_offset */
185 HOWTO (R_VAX_PLT32
, /* type */
187 2, /* size (0 = byte, 1 = short, 2 = long) */
189 TRUE
, /* pc_relative */
191 complain_overflow_bitfield
, /* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_VAX_PLT32", /* name */
194 FALSE
, /* partial_inplace */
196 0xffffffff, /* dst_mask */
197 TRUE
), /* pcrel_offset */
205 HOWTO (R_VAX_COPY
, /* type */
207 0, /* size (0 = byte, 1 = short, 2 = long) */
209 FALSE
, /* pc_relative */
211 complain_overflow_dont
, /* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_VAX_COPY", /* name */
214 FALSE
, /* partial_inplace */
216 0xffffffff, /* dst_mask */
217 FALSE
), /* pcrel_offset */
219 HOWTO (R_VAX_GLOB_DAT
, /* type */
221 2, /* size (0 = byte, 1 = short, 2 = long) */
223 FALSE
, /* pc_relative */
225 complain_overflow_dont
, /* complain_on_overflow */
226 bfd_elf_generic_reloc
, /* special_function */
227 "R_VAX_GLOB_DAT", /* name */
228 FALSE
, /* partial_inplace */
230 0xffffffff, /* dst_mask */
231 FALSE
), /* pcrel_offset */
233 HOWTO (R_VAX_JMP_SLOT
, /* type */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 FALSE
, /* pc_relative */
239 complain_overflow_dont
, /* complain_on_overflow */
240 bfd_elf_generic_reloc
, /* special_function */
241 "R_VAX_JMP_SLOT", /* name */
242 FALSE
, /* partial_inplace */
244 0xffffffff, /* dst_mask */
245 FALSE
), /* pcrel_offset */
247 HOWTO (R_VAX_RELATIVE
, /* type */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
251 FALSE
, /* pc_relative */
253 complain_overflow_dont
, /* complain_on_overflow */
254 bfd_elf_generic_reloc
, /* special_function */
255 "R_VAX_RELATIVE", /* name */
256 FALSE
, /* partial_inplace */
258 0xffffffff, /* dst_mask */
259 FALSE
), /* pcrel_offset */
261 /* GNU extension to record C++ vtable hierarchy */
262 HOWTO (R_VAX_GNU_VTINHERIT
, /* type */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
266 FALSE
, /* pc_relative */
268 complain_overflow_dont
, /* complain_on_overflow */
269 NULL
, /* special_function */
270 "R_VAX_GNU_VTINHERIT", /* name */
271 FALSE
, /* partial_inplace */
274 FALSE
), /* pcrel_offset */
276 /* GNU extension to record C++ vtable member usage */
277 HOWTO (R_VAX_GNU_VTENTRY
, /* type */
279 2, /* size (0 = byte, 1 = short, 2 = long) */
281 FALSE
, /* pc_relative */
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 */
289 FALSE
), /* pcrel_offset */
293 rtype_to_howto (abfd
, cache_ptr
, dst
)
294 bfd
*abfd ATTRIBUTE_UNUSED
;
296 Elf_Internal_Rela
*dst
;
298 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_VAX_max
);
299 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
302 #define elf_info_to_howto rtype_to_howto
306 bfd_reloc_code_real_type bfd_val
;
309 { BFD_RELOC_NONE
, R_VAX_NONE
},
310 { BFD_RELOC_32
, R_VAX_32
},
311 { BFD_RELOC_16
, R_VAX_16
},
312 { BFD_RELOC_8
, R_VAX_8
},
313 { BFD_RELOC_32_PCREL
, R_VAX_PC32
},
314 { BFD_RELOC_16_PCREL
, R_VAX_PC16
},
315 { BFD_RELOC_8_PCREL
, R_VAX_PC8
},
316 { BFD_RELOC_32_GOT_PCREL
, R_VAX_GOT32
},
317 { BFD_RELOC_32_PLT_PCREL
, R_VAX_PLT32
},
318 { BFD_RELOC_NONE
, R_VAX_COPY
},
319 { BFD_RELOC_VAX_GLOB_DAT
, R_VAX_GLOB_DAT
},
320 { BFD_RELOC_VAX_JMP_SLOT
, R_VAX_JMP_SLOT
},
321 { BFD_RELOC_VAX_RELATIVE
, R_VAX_RELATIVE
},
322 { BFD_RELOC_CTOR
, R_VAX_32
},
323 { BFD_RELOC_VTABLE_INHERIT
, R_VAX_GNU_VTINHERIT
},
324 { BFD_RELOC_VTABLE_ENTRY
, R_VAX_GNU_VTENTRY
},
327 static reloc_howto_type
*
328 reloc_type_lookup (abfd
, code
)
329 bfd
*abfd ATTRIBUTE_UNUSED
;
330 bfd_reloc_code_real_type code
;
333 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
335 if (reloc_map
[i
].bfd_val
== code
)
336 return &howto_table
[reloc_map
[i
].elf_val
];
341 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
342 #define ELF_ARCH bfd_arch_vax
343 /* end code generated by elf.el */
345 /* Functions for the VAX ELF linker. */
347 /* The name of the dynamic interpreter. This is put in the .interp
350 #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
352 /* The size in bytes of an entry in the procedure linkage table. */
354 #define PLT_ENTRY_SIZE 12
356 /* The first entry in a procedure linkage table looks like this. See
357 the SVR4 ABI VAX supplement to see how this works. */
359 static const bfd_byte elf_vax_plt0_entry
[PLT_ENTRY_SIZE
] =
361 0xdd, 0xef, /* pushl l^ */
362 0, 0, 0, 0, /* offset to .plt.got + 4 */
363 0x17, 0xff, /* jmp @L^(pc) */
364 0, 0, 0, 0, /* offset to .plt.got + 8 */
367 /* Subsequent entries in a procedure linkage table look like this. */
369 static const bfd_byte elf_vax_plt_entry
[PLT_ENTRY_SIZE
] =
371 0x40, 0x00, /* .word ^M<r6> */
372 0x16, 0xef, /* jsb L^(pc) */
373 0, 0, 0, 0, /* replaced with offset to start of .plt */
374 0, 0, 0, 0, /* index into .rela.plt */
377 /* The VAX linker needs to keep track of the number of relocs that it
378 decides to copy in check_relocs for each symbol. This is so that it
379 can discard PC relative relocs if it doesn't need them when linking
380 with -Bsymbolic. We store the information in a field extending the
381 regular ELF linker hash table. */
383 /* This structure keeps track of the number of PC relative relocs we have
384 copied for a given symbol. */
386 struct elf_vax_pcrel_relocs_copied
389 struct elf_vax_pcrel_relocs_copied
*next
;
390 /* A section in dynobj. */
392 /* Number of relocs copied in this section. */
396 /* VAX ELF linker hash entry. */
398 struct elf_vax_link_hash_entry
400 struct elf_link_hash_entry root
;
402 /* Number of PC relative relocs copied for this symbol. */
403 struct elf_vax_pcrel_relocs_copied
*pcrel_relocs_copied
;
408 /* VAX ELF linker hash table. */
410 struct elf_vax_link_hash_table
412 struct elf_link_hash_table root
;
415 /* Declare this now that the above structures are defined. */
417 static bfd_boolean elf_vax_discard_copies
418 PARAMS ((struct elf_vax_link_hash_entry
*, PTR
));
420 /* Declare this now that the above structures are defined. */
422 static bfd_boolean elf_vax_instantiate_got_entries
423 PARAMS ((struct elf_link_hash_entry
*, PTR
));
425 /* Traverse an VAX ELF linker hash table. */
427 #define elf_vax_link_hash_traverse(table, func, info) \
428 (elf_link_hash_traverse \
430 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
433 /* Get the VAX ELF linker hash table from a link_info structure. */
435 #define elf_vax_hash_table(p) \
436 ((struct elf_vax_link_hash_table *) (p)->hash)
438 /* Create an entry in an VAX ELF linker hash table. */
440 static struct bfd_hash_entry
*
441 elf_vax_link_hash_newfunc (entry
, table
, string
)
442 struct bfd_hash_entry
*entry
;
443 struct bfd_hash_table
*table
;
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
451 if (ret
== (struct elf_vax_link_hash_entry
*) NULL
)
452 ret
= ((struct elf_vax_link_hash_entry
*)
453 bfd_hash_allocate (table
,
454 sizeof (struct elf_vax_link_hash_entry
)));
455 if (ret
== (struct elf_vax_link_hash_entry
*) NULL
)
456 return (struct bfd_hash_entry
*) ret
;
458 /* Call the allocation method of the superclass. */
459 ret
= ((struct elf_vax_link_hash_entry
*)
460 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
462 if (ret
!= (struct elf_vax_link_hash_entry
*) NULL
)
464 ret
->pcrel_relocs_copied
= NULL
;
467 return (struct bfd_hash_entry
*) ret
;
470 /* Create an VAX ELF linker hash table. */
472 static struct bfd_link_hash_table
*
473 elf_vax_link_hash_table_create (abfd
)
476 struct elf_vax_link_hash_table
*ret
;
477 bfd_size_type amt
= sizeof (struct elf_vax_link_hash_table
);
479 ret
= (struct elf_vax_link_hash_table
*) bfd_malloc (amt
);
480 if (ret
== (struct elf_vax_link_hash_table
*) NULL
)
483 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
484 elf_vax_link_hash_newfunc
))
490 return &ret
->root
.root
;
493 /* Keep vax-specific flags in the ELF header */
495 elf32_vax_set_private_flags (abfd
, flags
)
499 elf_elfheader (abfd
)->e_flags
= flags
;
500 elf_flags_init (abfd
) = TRUE
;
504 /* Merge backend specific data from an object file to the output
505 object file when linking. */
507 elf32_vax_merge_private_bfd_data (ibfd
, obfd
)
514 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
515 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
518 in_flags
= elf_elfheader (ibfd
)->e_flags
;
519 out_flags
= elf_elfheader (obfd
)->e_flags
;
521 if (!elf_flags_init (obfd
))
523 elf_flags_init (obfd
) = TRUE
;
524 elf_elfheader (obfd
)->e_flags
= in_flags
;
530 /* Display the flags field */
532 elf32_vax_print_private_bfd_data (abfd
, ptr
)
536 FILE *file
= (FILE *) ptr
;
538 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
540 /* Print normal ELF private data. */
541 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
543 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
545 /* xgettext:c-format */
546 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
548 if (elf_elfheader (abfd
)->e_flags
& EF_VAX_NONPIC
)
549 fprintf (file
, _(" [nonpic]"));
551 if (elf_elfheader (abfd
)->e_flags
& EF_VAX_DFLOAT
)
552 fprintf (file
, _(" [d-float]"));
554 if (elf_elfheader (abfd
)->e_flags
& EF_VAX_GFLOAT
)
555 fprintf (file
, _(" [g-float]"));
561 /* Look through the relocs for a section during the first phase, and
562 allocate space in the global offset table or procedure linkage
566 elf_vax_check_relocs (abfd
, info
, sec
, relocs
)
568 struct bfd_link_info
*info
;
570 const Elf_Internal_Rela
*relocs
;
573 Elf_Internal_Shdr
*symtab_hdr
;
574 struct elf_link_hash_entry
**sym_hashes
;
575 const Elf_Internal_Rela
*rel
;
576 const Elf_Internal_Rela
*rel_end
;
581 if (info
->relocatable
)
584 dynobj
= elf_hash_table (info
)->dynobj
;
585 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
586 sym_hashes
= elf_sym_hashes (abfd
);
592 rel_end
= relocs
+ sec
->reloc_count
;
593 for (rel
= relocs
; rel
< rel_end
; rel
++)
595 unsigned long r_symndx
;
596 struct elf_link_hash_entry
*h
;
598 r_symndx
= ELF32_R_SYM (rel
->r_info
);
600 if (r_symndx
< symtab_hdr
->sh_info
)
603 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
605 switch (ELF32_R_TYPE (rel
->r_info
))
609 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
612 /* This symbol requires a global offset table entry. */
616 /* Create the .got section. */
617 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
618 if (!_bfd_elf_create_got_section (dynobj
, info
))
624 sgot
= bfd_get_section_by_name (dynobj
, ".got");
625 BFD_ASSERT (sgot
!= NULL
);
629 && (h
!= NULL
|| info
->shared
))
631 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
634 srelgot
= bfd_make_section (dynobj
, ".rela.got");
636 || !bfd_set_section_flags (dynobj
, srelgot
,
643 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
650 struct elf_vax_link_hash_entry
*eh
;
652 eh
= (struct elf_vax_link_hash_entry
*) h
;
653 if (h
->got
.refcount
== -1)
656 eh
->got_addend
= rel
->r_addend
;
661 if (eh
->got_addend
!= (bfd_vma
) rel
->r_addend
)
662 (*_bfd_error_handler
)
663 (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
664 bfd_get_filename (abfd
), rel
->r_addend
,
673 /* This symbol requires a procedure linkage table entry. We
674 actually build the entry in adjust_dynamic_symbol,
675 because this might be a case of linking PIC code which is
676 never referenced by a dynamic object, in which case we
677 don't need to generate a procedure linkage table entry
680 /* If this is a local symbol, we resolve it directly without
681 creating a procedure linkage table entry. */
685 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
686 if (h
->plt
.refcount
== -1)
695 /* If we are creating a shared library and this is not a local
696 symbol, we need to copy the reloc into the shared library.
697 However when linking with -Bsymbolic and this is a global
698 symbol which is defined in an object we are including in the
699 link (i.e., DEF_REGULAR is set), then we can resolve the
700 reloc directly. At this point we have not seen all the input
701 files, so it is possible that DEF_REGULAR is not set now but
702 will be set later (it is never cleared). We account for that
703 possibility below by storing information in the
704 pcrel_relocs_copied field of the hash table entry. */
706 && (sec
->flags
& SEC_ALLOC
) != 0
709 || (h
->elf_link_hash_flags
710 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
714 /* Make sure a plt entry is created for this symbol if
715 it turns out to be a function defined by a dynamic
717 if (h
->plt
.refcount
== -1)
730 /* Make sure a plt entry is created for this symbol if it
731 turns out to be a function defined by a dynamic object. */
732 if (h
->plt
.refcount
== -1)
738 /* If we are creating a shared library, we need to copy the
739 reloc into the shared library. */
741 && (sec
->flags
& SEC_ALLOC
) != 0)
743 /* When creating a shared object, we must copy these
744 reloc types into the output file. We create a reloc
745 section in dynobj and make room for this reloc. */
750 name
= (bfd_elf_string_from_elf_section
752 elf_elfheader (abfd
)->e_shstrndx
,
753 elf_section_data (sec
)->rel_hdr
.sh_name
));
757 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
758 && strcmp (bfd_get_section_name (abfd
, sec
),
761 sreloc
= bfd_get_section_by_name (dynobj
, name
);
764 sreloc
= bfd_make_section (dynobj
, name
);
766 || !bfd_set_section_flags (dynobj
, sreloc
,
773 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
776 if (sec
->flags
& SEC_READONLY
)
777 info
->flags
|= DF_TEXTREL
;
780 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
782 /* If we are linking with -Bsymbolic, we count the number of
783 PC relative relocations we have entered for this symbol,
784 so that we can discard them again if the symbol is later
785 defined by a regular object. Note that this function is
786 only called if we are using a vaxelf linker hash table,
787 which means that h is really a pointer to an
788 elf_vax_link_hash_entry. */
789 if ((ELF32_R_TYPE (rel
->r_info
) == R_VAX_PC8
790 || ELF32_R_TYPE (rel
->r_info
) == R_VAX_PC16
791 || ELF32_R_TYPE (rel
->r_info
) == R_VAX_PC32
)
794 struct elf_vax_link_hash_entry
*eh
;
795 struct elf_vax_pcrel_relocs_copied
*p
;
797 eh
= (struct elf_vax_link_hash_entry
*) h
;
799 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
800 if (p
->section
== sreloc
)
805 p
= ((struct elf_vax_pcrel_relocs_copied
*)
806 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
809 p
->next
= eh
->pcrel_relocs_copied
;
810 eh
->pcrel_relocs_copied
= p
;
821 /* This relocation describes the C++ object vtable hierarchy.
822 Reconstruct it for later use during GC. */
823 case R_VAX_GNU_VTINHERIT
:
824 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
828 /* This relocation describes which C++ vtable entries are actually
829 used. Record for later use during GC. */
830 case R_VAX_GNU_VTENTRY
:
831 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
843 /* Return the section that should be marked against GC for a given
847 elf_vax_gc_mark_hook (sec
, info
, rel
, h
, sym
)
849 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
850 Elf_Internal_Rela
*rel
;
851 struct elf_link_hash_entry
*h
;
852 Elf_Internal_Sym
*sym
;
856 switch (ELF32_R_TYPE (rel
->r_info
))
858 case R_VAX_GNU_VTINHERIT
:
859 case R_VAX_GNU_VTENTRY
:
863 switch (h
->root
.type
)
868 case bfd_link_hash_defined
:
869 case bfd_link_hash_defweak
:
870 return h
->root
.u
.def
.section
;
872 case bfd_link_hash_common
:
873 return h
->root
.u
.c
.p
->section
;
878 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
883 /* Update the got entry reference counts for the section being removed. */
886 elf_vax_gc_sweep_hook (abfd
, info
, sec
, relocs
)
888 struct bfd_link_info
*info
;
890 const Elf_Internal_Rela
*relocs
;
892 Elf_Internal_Shdr
*symtab_hdr
;
893 struct elf_link_hash_entry
**sym_hashes
;
894 const Elf_Internal_Rela
*rel
, *relend
;
897 dynobj
= elf_hash_table (info
)->dynobj
;
901 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
902 sym_hashes
= elf_sym_hashes (abfd
);
904 relend
= relocs
+ sec
->reloc_count
;
905 for (rel
= relocs
; rel
< relend
; rel
++)
907 unsigned long r_symndx
;
908 struct elf_link_hash_entry
*h
;
910 switch (ELF32_R_TYPE (rel
->r_info
))
913 r_symndx
= ELF32_R_SYM (rel
->r_info
);
914 if (r_symndx
>= symtab_hdr
->sh_info
)
916 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
917 if (h
->got
.refcount
> 0)
929 r_symndx
= ELF32_R_SYM (rel
->r_info
);
930 if (r_symndx
>= symtab_hdr
->sh_info
)
932 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
933 if (h
->plt
.refcount
> 0)
946 /* Adjust a symbol defined by a dynamic object and referenced by a
947 regular object. The current definition is in some section of the
948 dynamic object, but we're not including those sections. We have to
949 change the definition to something the rest of the link can
953 elf_vax_adjust_dynamic_symbol (info
, h
)
954 struct bfd_link_info
*info
;
955 struct elf_link_hash_entry
*h
;
959 unsigned int power_of_two
;
961 dynobj
= elf_hash_table (info
)->dynobj
;
963 /* Make sure we know what is going on here. */
964 BFD_ASSERT (dynobj
!= NULL
965 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
966 || h
->weakdef
!= NULL
967 || ((h
->elf_link_hash_flags
968 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
969 && (h
->elf_link_hash_flags
970 & ELF_LINK_HASH_REF_REGULAR
) != 0
971 && (h
->elf_link_hash_flags
972 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
974 /* If this is a function, put it in the procedure linkage table. We
975 will fill in the contents of the procedure linkage table later,
976 when we know the address of the .got section. */
977 if (h
->type
== STT_FUNC
978 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
981 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
982 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
983 /* We must always create the plt entry if it was referenced
984 by a PLTxxO relocation. In this case we already recorded
985 it as a dynamic symbol. */
988 /* This case can occur if we saw a PLTxx reloc in an input
989 file, but the symbol was never referred to by a dynamic
990 object. In such a case, we don't actually need to build
991 a procedure linkage table, and we can just do a PCxx
993 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
994 h
->plt
.offset
= (bfd_vma
) -1;
998 /* GC may have rendered this entry unused. */
999 if (h
->plt
.refcount
<= 0)
1001 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1002 h
->plt
.offset
= (bfd_vma
) -1;
1006 /* Make sure this symbol is output as a dynamic symbol. */
1007 if (h
->dynindx
== -1)
1009 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
1013 s
= bfd_get_section_by_name (dynobj
, ".plt");
1014 BFD_ASSERT (s
!= NULL
);
1016 /* If this is the first .plt entry, make room for the special
1018 if (s
->_raw_size
== 0)
1020 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1023 /* If this symbol is not defined in a regular file, and we are
1024 not generating a shared library, then set the symbol to this
1025 location in the .plt. This is required to make function
1026 pointers compare as equal between the normal executable and
1027 the shared library. */
1029 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1031 h
->root
.u
.def
.section
= s
;
1032 h
->root
.u
.def
.value
= s
->_raw_size
;
1035 h
->plt
.offset
= s
->_raw_size
;
1037 /* Make room for this entry. */
1038 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1040 /* We also need to make an entry in the .got.plt section, which
1041 will be placed in the .got section by the linker script. */
1043 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
1044 BFD_ASSERT (s
!= NULL
);
1047 /* We also need to make an entry in the .rela.plt section. */
1049 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1050 BFD_ASSERT (s
!= NULL
);
1051 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1056 /* Reinitialize the plt offset now that it is not used as a reference
1058 h
->plt
.offset
= (bfd_vma
) -1;
1060 /* If this is a weak symbol, and there is a real definition, the
1061 processor independent code will have arranged for us to see the
1062 real definition first, and we can just use the same value. */
1063 if (h
->weakdef
!= NULL
)
1065 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1066 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1067 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1068 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1072 /* This is a reference to a symbol defined by a dynamic object which
1073 is not a function. */
1075 /* If we are creating a shared library, we must presume that the
1076 only references to the symbol are via the global offset table.
1077 For such cases we need not do anything here; the relocations will
1078 be handled correctly by relocate_section. */
1082 /* We must allocate the symbol in our .dynbss section, which will
1083 become part of the .bss section of the executable. There will be
1084 an entry for this symbol in the .dynsym section. The dynamic
1085 object will contain position independent code, so all references
1086 from the dynamic object to this symbol will go through the global
1087 offset table. The dynamic linker will use the .dynsym entry to
1088 determine the address it must put in the global offset table, so
1089 both the dynamic object and the regular object will refer to the
1090 same memory location for the variable. */
1092 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1093 BFD_ASSERT (s
!= NULL
);
1095 /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
1096 copy the initial value out of the dynamic object and into the
1097 runtime process image. We need to remember the offset into the
1098 .rela.bss section we are going to use. */
1099 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1103 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1104 BFD_ASSERT (srel
!= NULL
);
1105 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1106 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1109 /* We need to figure out the alignment required for this symbol. I
1110 have no idea how ELF linkers handle this. */
1111 power_of_two
= bfd_log2 (h
->size
);
1112 if (power_of_two
> 3)
1115 /* Apply the required alignment. */
1116 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1117 (bfd_size_type
) (1 << power_of_two
));
1118 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1120 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1124 /* Define the symbol as being at this point in the section. */
1125 h
->root
.u
.def
.section
= s
;
1126 h
->root
.u
.def
.value
= s
->_raw_size
;
1128 /* Increment the section size to make room for the symbol. */
1129 s
->_raw_size
+= h
->size
;
1134 /* Set the sizes of the dynamic sections. */
1137 elf_vax_size_dynamic_sections (output_bfd
, info
)
1139 struct bfd_link_info
*info
;
1145 bfd_boolean reltext
;
1147 dynobj
= elf_hash_table (info
)->dynobj
;
1148 BFD_ASSERT (dynobj
!= NULL
);
1150 if (elf_hash_table (info
)->dynamic_sections_created
)
1152 /* Set the contents of the .interp section to the interpreter. */
1153 if (info
->executable
)
1155 s
= bfd_get_section_by_name (dynobj
, ".interp");
1156 BFD_ASSERT (s
!= NULL
);
1157 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1158 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1163 /* We may have created entries in the .rela.got and .got sections.
1164 However, if we are not creating the dynamic sections, we will
1165 not actually use these entries. Reset the size of .rela.got
1166 and .got, which will cause it to get stripped from the output
1168 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1171 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
1174 s
= bfd_get_section_by_name (dynobj
, ".got");
1179 /* If this is a -Bsymbolic shared link, then we need to discard all PC
1180 relative relocs against symbols defined in a regular object. We
1181 allocated space for them in the check_relocs routine, but we will not
1182 fill them in in the relocate_section routine. */
1183 if (info
->shared
&& info
->symbolic
)
1184 elf_vax_link_hash_traverse (elf_vax_hash_table (info
),
1185 elf_vax_discard_copies
,
1188 /* If this is a -Bsymbolic shared link or a static link, we need to
1189 discard all the got entries we've recorded. Otherwise, we need to
1190 instantiate (allocate space for them). */
1191 elf_link_hash_traverse (elf_hash_table (info
),
1192 elf_vax_instantiate_got_entries
,
1195 /* The check_relocs and adjust_dynamic_symbol entry points have
1196 determined the sizes of the various dynamic sections. Allocate
1201 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1206 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1209 /* It's OK to base decisions on the section name, because none
1210 of the dynobj section names depend upon the input files. */
1211 name
= bfd_get_section_name (dynobj
, s
);
1215 if (strcmp (name
, ".plt") == 0)
1217 if (s
->_raw_size
== 0)
1219 /* Strip this section if we don't need it; see the
1225 /* Remember whether there is a PLT. */
1229 else if (strncmp (name
, ".rela", 5) == 0)
1231 if (s
->_raw_size
== 0)
1233 /* If we don't need this section, strip it from the
1234 output file. This is mostly to handle .rela.bss and
1235 .rela.plt. We must create both sections in
1236 create_dynamic_sections, because they must be created
1237 before the linker maps input sections to output
1238 sections. The linker does that before
1239 adjust_dynamic_symbol is called, and it is that
1240 function which decides whether anything needs to go
1241 into these sections. */
1248 /* Remember whether there are any reloc sections other
1250 if (strcmp (name
, ".rela.plt") != 0)
1252 const char *outname
;
1256 /* If this relocation section applies to a read only
1257 section, then we probably need a DT_TEXTREL
1258 entry. .rela.plt is actually associated with
1259 .got.plt, which is never readonly. */
1260 outname
= bfd_get_section_name (output_bfd
,
1262 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
1264 && (target
->flags
& SEC_READONLY
) != 0
1265 && (target
->flags
& SEC_ALLOC
) != 0)
1269 /* We use the reloc_count field as a counter if we need
1270 to copy relocs into the output file. */
1274 else if (strncmp (name
, ".got", 4) != 0)
1276 /* It's not one of our sections, so don't allocate space. */
1282 _bfd_strip_section_from_output (info
, s
);
1286 /* Allocate memory for the section contents. */
1287 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1288 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1292 if (elf_hash_table (info
)->dynamic_sections_created
)
1294 /* Add some entries to the .dynamic section. We fill in the
1295 values later, in elf_vax_finish_dynamic_sections, but we
1296 must add the entries now so that we get the correct size for
1297 the .dynamic section. The DT_DEBUG entry is filled in by the
1298 dynamic linker and used by the debugger. */
1299 #define add_dynamic_entry(TAG, VAL) \
1300 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1304 if (!add_dynamic_entry (DT_DEBUG
, 0))
1310 if (!add_dynamic_entry (DT_PLTGOT
, 0)
1311 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
1312 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
1313 || !add_dynamic_entry (DT_JMPREL
, 0))
1319 if (!add_dynamic_entry (DT_RELA
, 0)
1320 || !add_dynamic_entry (DT_RELASZ
, 0)
1321 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
1325 if (reltext
|| (info
->flags
& DF_TEXTREL
) != 0)
1327 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1331 #undef add_dynamic_entry
1336 /* This function is called via elf_vax_link_hash_traverse if we are
1337 creating a shared object with -Bsymbolic. It discards the space
1338 allocated to copy PC relative relocs against symbols which are defined
1339 in regular objects. We allocated space for them in the check_relocs
1340 routine, but we won't fill them in in the relocate_section routine. */
1343 elf_vax_discard_copies (h
, ignore
)
1344 struct elf_vax_link_hash_entry
*h
;
1345 PTR ignore ATTRIBUTE_UNUSED
;
1347 struct elf_vax_pcrel_relocs_copied
*s
;
1349 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1350 h
= (struct elf_vax_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1352 /* We only discard relocs for symbols defined in a regular object. */
1353 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1356 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
1357 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
1362 /* This function is called via elf_link_hash_traverse. It looks for entries
1363 that have GOT or PLT (.GOT) references. If creating a static object or a
1364 shared object with -Bsymbolic, it resets the reference count back to 0
1365 and sets the offset to -1 so normal PC32 relocation will be done. If
1366 creating a shared object or executable, space in the .got and .rela.got
1367 will be reserved for the symbol. */
1370 elf_vax_instantiate_got_entries (h
, infoptr
)
1371 struct elf_link_hash_entry
*h
;
1374 struct bfd_link_info
*info
= (struct bfd_link_info
*) infoptr
;
1379 /* We don't care about non-GOT (and non-PLT) entries. */
1380 if (h
->got
.refcount
<= 0 && h
->plt
.refcount
<= 0)
1383 dynobj
= elf_hash_table (info
)->dynobj
;
1387 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1388 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1390 if (!elf_hash_table (info
)->dynamic_sections_created
1391 || (info
->shared
&& info
->symbolic
))
1393 h
->got
.refcount
= 0;
1394 h
->got
.offset
= (bfd_vma
) -1;
1395 h
->plt
.refcount
= 0;
1396 h
->plt
.offset
= (bfd_vma
) -1;
1398 else if (h
->got
.refcount
> 0)
1400 /* Make sure this symbol is output as a dynamic symbol. */
1401 if (h
->dynindx
== -1)
1403 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
1407 /* Allocate space in the .got and .rela.got sections. */
1408 sgot
->_raw_size
+= 4;
1409 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1415 /* Relocate an VAX ELF section. */
1418 elf_vax_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1419 contents
, relocs
, local_syms
, local_sections
)
1421 struct bfd_link_info
*info
;
1423 asection
*input_section
;
1425 Elf_Internal_Rela
*relocs
;
1426 Elf_Internal_Sym
*local_syms
;
1427 asection
**local_sections
;
1430 Elf_Internal_Shdr
*symtab_hdr
;
1431 struct elf_link_hash_entry
**sym_hashes
;
1432 bfd_vma
*local_got_offsets
;
1439 Elf_Internal_Rela
*rel
;
1440 Elf_Internal_Rela
*relend
;
1442 if (info
->relocatable
)
1445 dynobj
= elf_hash_table (info
)->dynobj
;
1446 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1447 sym_hashes
= elf_sym_hashes (input_bfd
);
1448 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1456 relend
= relocs
+ input_section
->reloc_count
;
1457 for (; rel
< relend
; rel
++)
1460 reloc_howto_type
*howto
;
1461 unsigned long r_symndx
;
1462 struct elf_link_hash_entry
*h
;
1463 Elf_Internal_Sym
*sym
;
1466 bfd_reloc_status_type r
;
1468 r_type
= ELF32_R_TYPE (rel
->r_info
);
1469 if (r_type
< 0 || r_type
>= (int) R_VAX_max
)
1471 bfd_set_error (bfd_error_bad_value
);
1474 howto
= howto_table
+ r_type
;
1476 /* This is a final link. */
1477 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1481 if (r_symndx
< symtab_hdr
->sh_info
)
1483 sym
= local_syms
+ r_symndx
;
1484 sec
= local_sections
[r_symndx
];
1485 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1489 bfd_boolean unresolved_reloc
;
1492 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1493 r_symndx
, symtab_hdr
, sym_hashes
,
1495 unresolved_reloc
, warned
);
1497 if ((h
->root
.type
== bfd_link_hash_defined
1498 || h
->root
.type
== bfd_link_hash_defweak
)
1499 && ((r_type
== R_VAX_PLT32
1500 && h
->plt
.offset
!= (bfd_vma
) -1
1501 && elf_hash_table (info
)->dynamic_sections_created
)
1502 || (r_type
== R_VAX_GOT32
1503 && strcmp (h
->root
.root
.string
,
1504 "_GLOBAL_OFFSET_TABLE_") != 0
1505 && elf_hash_table (info
)->dynamic_sections_created
1507 || (! info
->symbolic
&& h
->dynindx
!= -1)
1508 || (h
->elf_link_hash_flags
1509 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1511 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1512 || (h
->elf_link_hash_flags
1513 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1514 && ((input_section
->flags
& SEC_ALLOC
) != 0
1515 /* DWARF will emit R_VAX_32 relocations in its
1516 sections against symbols defined externally
1517 in shared libraries. We can't do anything
1520 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
1521 && (h
->elf_link_hash_flags
1522 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
1523 && (r_type
== R_VAX_8
1524 || r_type
== R_VAX_16
1525 || r_type
== R_VAX_32
1526 || r_type
== R_VAX_PC8
1527 || r_type
== R_VAX_PC16
1528 || r_type
== R_VAX_PC32
))))
1529 /* In these cases, we don't need the relocation
1530 value. We check specially because in some
1531 obscure cases sec->output_section will be NULL. */
1538 /* Relocation is to the address of the entry for this symbol
1539 in the global offset table. */
1540 if (h
== NULL
|| h
->got
.offset
== (bfd_vma
) -1)
1543 /* Relocation is the offset of the entry for this symbol in
1544 the global offset table. */
1551 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1552 BFD_ASSERT (sgot
!= NULL
);
1555 BFD_ASSERT (h
!= NULL
);
1556 off
= h
->got
.offset
;
1557 BFD_ASSERT (off
!= (bfd_vma
) -1);
1558 BFD_ASSERT (off
< sgot
->_raw_size
);
1562 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1564 /* The symbol was forced to be local
1565 because of a version file.. We must initialize
1566 this entry in the global offset table. Since
1567 the offset must always be a multiple of 4, we
1568 use the least significant bit to record whether
1569 we have initialized it already.
1571 When doing a dynamic link, we create a .rela.got
1572 relocation entry to initialize the value. This
1573 is done in the finish_dynamic_symbol routine. */
1578 bfd_put_32 (output_bfd
, relocation
+ rel
->r_addend
,
1579 sgot
->contents
+ off
);
1583 bfd_put_32 (output_bfd
, rel
->r_addend
, sgot
->contents
+ off
);
1586 relocation
= sgot
->output_offset
+ off
;
1587 /* The GOT relocation uses the addend. */
1590 /* Change the reference to be indirect. */
1591 contents
[rel
->r_offset
- 1] |= 0x10;
1592 relocation
+= sgot
->output_section
->vma
;
1597 /* Relocation is to the entry for this symbol in the
1598 procedure linkage table. */
1600 /* Resolve a PLTxx reloc against a local symbol directly,
1601 without using the procedure linkage table. */
1605 if (h
->plt
.offset
== (bfd_vma
) -1
1606 || !elf_hash_table (info
)->dynamic_sections_created
)
1608 /* We didn't make a PLT entry for this symbol. This
1609 happens when statically linking PIC code, or when
1610 using -Bsymbolic. */
1616 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1617 BFD_ASSERT (splt
!= NULL
);
1620 if (sgotplt
== NULL
)
1622 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1623 BFD_ASSERT (splt
!= NULL
);
1626 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1628 /* Get the offset into the .got table of the entry that
1629 corresponds to this function. Each .got entry is 4 bytes.
1630 The first two are reserved. */
1631 got_offset
= (plt_index
+ 3) * 4;
1633 /* We want the relocate to point into the .got.plt instead
1634 of the plt itself. */
1635 relocation
= (sgotplt
->output_section
->vma
1636 + sgotplt
->output_offset
1638 contents
[rel
->r_offset
-1] |= 0x10; /* make indirect */
1639 if (rel
->r_addend
== 2)
1643 else if (rel
->r_addend
!= 0)
1644 (*_bfd_error_handler
)
1645 (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"),
1646 bfd_get_filename (input_bfd
), rel
->r_addend
,
1647 h
->root
.root
.string
,
1648 bfd_get_section_name (input_bfd
, input_section
));
1664 && (input_section
->flags
& SEC_ALLOC
) != 0
1665 && ((r_type
!= R_VAX_PC8
1666 && r_type
!= R_VAX_PC16
1667 && r_type
!= R_VAX_PC32
)
1669 || (h
->elf_link_hash_flags
1670 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1672 Elf_Internal_Rela outrel
;
1674 bfd_boolean skip
, relocate
;
1676 /* When generating a shared object, these relocations
1677 are copied into the output file to be resolved at run
1683 name
= (bfd_elf_string_from_elf_section
1685 elf_elfheader (input_bfd
)->e_shstrndx
,
1686 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1690 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1691 && strcmp (bfd_get_section_name (input_bfd
,
1695 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1696 BFD_ASSERT (sreloc
!= NULL
);
1703 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
1705 if (outrel
.r_offset
== (bfd_vma
) -1)
1707 if (outrel
.r_offset
== (bfd_vma
) -2)
1708 skip
= TRUE
, relocate
= TRUE
;
1709 outrel
.r_offset
+= (input_section
->output_section
->vma
1710 + input_section
->output_offset
);
1713 memset (&outrel
, 0, sizeof outrel
);
1714 /* h->dynindx may be -1 if the symbol was marked to
1717 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1718 || (h
->elf_link_hash_flags
1719 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1721 BFD_ASSERT (h
->dynindx
!= -1);
1722 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1723 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1727 if (r_type
== R_VAX_32
)
1730 outrel
.r_info
= ELF32_R_INFO (0, R_VAX_RELATIVE
);
1731 BFD_ASSERT (bfd_get_signed_32 (input_bfd
,
1732 &contents
[rel
->r_offset
]) == 0);
1733 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1739 if (bfd_is_abs_section (sec
))
1741 else if (sec
== NULL
|| sec
->owner
== NULL
)
1743 bfd_set_error (bfd_error_bad_value
);
1750 osec
= sec
->output_section
;
1751 indx
= elf_section_data (osec
)->dynindx
;
1752 BFD_ASSERT (indx
> 0);
1755 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1756 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1760 if (!strcmp (bfd_get_section_name (input_bfd
, input_section
),
1763 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_32
1764 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_RELATIVE
1765 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_COPY
1766 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_JMP_SLOT
1767 && ELF32_R_TYPE(outrel
.r_info
) != R_VAX_GLOB_DAT
))
1770 (*_bfd_error_handler
)
1771 (_("%s: warning: %s relocation against symbol `%s' from %s section"),
1772 bfd_get_filename (input_bfd
), howto
->name
,
1773 h
->root
.root
.string
,
1774 bfd_get_section_name (input_bfd
, input_section
));
1776 (*_bfd_error_handler
)
1777 (_("%s: warning: %s relocation to 0x%x from %s section"),
1778 bfd_get_filename (input_bfd
), howto
->name
,
1780 bfd_get_section_name (input_bfd
, input_section
));
1782 loc
= sreloc
->contents
;
1783 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1784 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1786 /* This reloc will be computed at runtime, so there's no
1787 need to do anything now, except for R_VAX_32
1788 relocations that have been turned into
1796 case R_VAX_GNU_VTINHERIT
:
1797 case R_VAX_GNU_VTENTRY
:
1798 /* These are no-ops in the end. */
1805 /* VAX PCREL relocations are from the end of relocation, not the start.
1806 So subtract the difference from the relocation amount since we can't
1807 add it to the offset. */
1808 if (howto
->pc_relative
&& howto
->pcrel_offset
)
1809 relocation
-= bfd_get_reloc_size(howto
);
1811 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1812 contents
, rel
->r_offset
,
1813 relocation
, rel
->r_addend
);
1815 if (r
!= bfd_reloc_ok
)
1820 case bfd_reloc_outofrange
:
1822 case bfd_reloc_overflow
:
1827 name
= h
->root
.root
.string
;
1830 name
= bfd_elf_string_from_elf_section (input_bfd
,
1831 symtab_hdr
->sh_link
,
1836 name
= bfd_section_name (input_bfd
, sec
);
1838 if (!(info
->callbacks
->reloc_overflow
1839 (info
, name
, howto
->name
, (bfd_vma
) 0,
1840 input_bfd
, input_section
, rel
->r_offset
)))
1851 /* Finish up dynamic symbol handling. We set the contents of various
1852 dynamic sections here. */
1855 elf_vax_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1857 struct bfd_link_info
*info
;
1858 struct elf_link_hash_entry
*h
;
1859 Elf_Internal_Sym
*sym
;
1863 dynobj
= elf_hash_table (info
)->dynobj
;
1865 if (h
->plt
.offset
!= (bfd_vma
) -1)
1873 Elf_Internal_Rela rela
;
1876 /* This symbol has an entry in the procedure linkage table. Set
1878 BFD_ASSERT (h
->dynindx
!= -1);
1880 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1881 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1882 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1883 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1885 addend
= 2 * (h
->plt
.offset
& 1);
1886 h
->plt
.offset
&= ~1;
1888 /* Get the index in the procedure linkage table which
1889 corresponds to this symbol. This is the index of this symbol
1890 in all the symbols for which we are making plt entries. The
1891 first entry in the procedure linkage table is reserved. */
1892 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1894 /* Get the offset into the .got table of the entry that
1895 corresponds to this function. Each .got entry is 4 bytes.
1896 The first two are reserved. */
1897 got_offset
= (plt_index
+ 3) * 4;
1899 /* Fill in the entry in the procedure linkage table. */
1900 memcpy (splt
->contents
+ h
->plt
.offset
, elf_vax_plt_entry
,
1903 /* The offset is relative to the first extension word. */
1904 bfd_put_32 (output_bfd
,
1905 -(h
->plt
.offset
+ 8),
1906 splt
->contents
+ h
->plt
.offset
+ 4);
1908 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
1909 splt
->contents
+ h
->plt
.offset
+ 8);
1911 /* Fill in the entry in the global offset table. */
1912 bfd_put_32 (output_bfd
,
1913 (splt
->output_section
->vma
1914 + splt
->output_offset
1915 + h
->plt
.offset
) + addend
,
1916 sgot
->contents
+ got_offset
);
1918 /* Fill in the entry in the .rela.plt section. */
1919 rela
.r_offset
= (sgot
->output_section
->vma
1920 + sgot
->output_offset
1922 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_VAX_JMP_SLOT
);
1923 rela
.r_addend
= addend
;
1924 loc
= srela
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
1925 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1927 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1929 /* Mark the symbol as undefined, rather than as defined in
1930 the .plt section. Leave the value alone. */
1931 sym
->st_shndx
= SHN_UNDEF
;
1935 if (h
->got
.offset
!= (bfd_vma
) -1)
1939 Elf_Internal_Rela rela
;
1942 /* This symbol has an entry in the global offset table. Set it
1944 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1945 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1946 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1948 rela
.r_offset
= (sgot
->output_section
->vma
1949 + sgot
->output_offset
1950 + (h
->got
.offset
&~ 1));
1952 /* If the symbol was forced to be local because of a version file
1953 locally we just want to emit a RELATIVE reloc. The entry in
1954 the global offset table will already have been initialized in
1955 the relocate_section function. */
1958 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1960 rela
.r_info
= ELF32_R_INFO (0, R_VAX_RELATIVE
);
1964 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_VAX_GLOB_DAT
);
1966 rela
.r_addend
= bfd_get_signed_32 (output_bfd
,
1968 + (h
->got
.offset
& ~1)));
1970 loc
= srela
->contents
;
1971 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1972 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1975 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1978 Elf_Internal_Rela rela
;
1981 /* This symbol needs a copy reloc. Set it up. */
1982 BFD_ASSERT (h
->dynindx
!= -1
1983 && (h
->root
.type
== bfd_link_hash_defined
1984 || h
->root
.type
== bfd_link_hash_defweak
));
1986 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1988 BFD_ASSERT (s
!= NULL
);
1990 rela
.r_offset
= (h
->root
.u
.def
.value
1991 + h
->root
.u
.def
.section
->output_section
->vma
1992 + h
->root
.u
.def
.section
->output_offset
);
1993 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_VAX_COPY
);
1995 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
1996 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
1999 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2000 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2001 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2002 sym
->st_shndx
= SHN_ABS
;
2007 /* Finish up the dynamic sections. */
2010 elf_vax_finish_dynamic_sections (output_bfd
, info
)
2012 struct bfd_link_info
*info
;
2018 dynobj
= elf_hash_table (info
)->dynobj
;
2020 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
2021 BFD_ASSERT (sgot
!= NULL
);
2022 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2024 if (elf_hash_table (info
)->dynamic_sections_created
)
2027 Elf32_External_Dyn
*dyncon
, *dynconend
;
2029 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2030 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2032 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2033 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2034 for (; dyncon
< dynconend
; dyncon
++)
2036 Elf_Internal_Dyn dyn
;
2040 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2053 s
= bfd_get_section_by_name (output_bfd
, name
);
2054 BFD_ASSERT (s
!= NULL
);
2055 dyn
.d_un
.d_ptr
= s
->vma
;
2056 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2060 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
2061 BFD_ASSERT (s
!= NULL
);
2062 if (s
->_cooked_size
!= 0)
2063 dyn
.d_un
.d_val
= s
->_cooked_size
;
2065 dyn
.d_un
.d_val
= s
->_raw_size
;
2066 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2070 /* The procedure linkage table relocs (DT_JMPREL) should
2071 not be included in the overall relocs (DT_RELA).
2072 Therefore, we override the DT_RELASZ entry here to
2073 make it not include the JMPREL relocs. Since the
2074 linker script arranges for .rela.plt to follow all
2075 other relocation sections, we don't have to worry
2076 about changing the DT_RELA entry. */
2077 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
2080 if (s
->_cooked_size
!= 0)
2081 dyn
.d_un
.d_val
-= s
->_cooked_size
;
2083 dyn
.d_un
.d_val
-= s
->_raw_size
;
2085 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2090 /* Fill in the first entry in the procedure linkage table. */
2091 if (splt
->_raw_size
> 0)
2093 memcpy (splt
->contents
, elf_vax_plt0_entry
, PLT_ENTRY_SIZE
);
2094 bfd_put_32 (output_bfd
,
2095 (sgot
->output_section
->vma
2096 + sgot
->output_offset
+ 4
2097 - (splt
->output_section
->vma
+ 6)),
2098 splt
->contents
+ 2);
2099 bfd_put_32 (output_bfd
,
2100 (sgot
->output_section
->vma
2101 + sgot
->output_offset
+ 8
2102 - (splt
->output_section
->vma
+ 12)),
2103 splt
->contents
+ 8);
2104 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
2109 /* Fill in the first three entries in the global offset table. */
2110 if (sgot
->_raw_size
> 0)
2113 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2115 bfd_put_32 (output_bfd
,
2116 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2118 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
2119 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
2122 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2127 #define TARGET_LITTLE_SYM bfd_elf32_vax_vec
2128 #define TARGET_LITTLE_NAME "elf32-vax"
2129 #define ELF_MACHINE_CODE EM_VAX
2130 #define ELF_MAXPAGESIZE 0x1000
2132 #define elf_backend_create_dynamic_sections \
2133 _bfd_elf_create_dynamic_sections
2134 #define bfd_elf32_bfd_link_hash_table_create \
2135 elf_vax_link_hash_table_create
2136 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
2138 #define elf_backend_check_relocs elf_vax_check_relocs
2139 #define elf_backend_adjust_dynamic_symbol \
2140 elf_vax_adjust_dynamic_symbol
2141 #define elf_backend_size_dynamic_sections \
2142 elf_vax_size_dynamic_sections
2143 #define elf_backend_relocate_section elf_vax_relocate_section
2144 #define elf_backend_finish_dynamic_symbol \
2145 elf_vax_finish_dynamic_symbol
2146 #define elf_backend_finish_dynamic_sections \
2147 elf_vax_finish_dynamic_sections
2148 #define elf_backend_gc_mark_hook elf_vax_gc_mark_hook
2149 #define elf_backend_gc_sweep_hook elf_vax_gc_sweep_hook
2150 #define bfd_elf32_bfd_merge_private_bfd_data \
2151 elf32_vax_merge_private_bfd_data
2152 #define bfd_elf32_bfd_set_private_flags \
2153 elf32_vax_set_private_flags
2154 #define bfd_elf32_bfd_print_private_bfd_data \
2155 elf32_vax_print_private_bfd_data
2157 #define elf_backend_can_gc_sections 1
2158 #define elf_backend_want_got_plt 1
2159 #define elf_backend_plt_readonly 1
2160 #define elf_backend_want_plt_sym 0
2161 #define elf_backend_got_header_size 16
2162 #define elf_backend_rela_normal 1
2164 #include "elf32-target.h"