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