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