1 /* Motorola 68k series support for 32-bit ELF
2 Copyright (C) 1993-2020 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
27 #include "opcode/m68k.h"
29 #include "elf32-m68k.h"
32 elf_m68k_discard_copies (struct elf_link_hash_entry *, void *);
34 static reloc_howto_type howto_table[] =
36 HOWTO(R_68K_NONE, 0, 3, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE),
37 HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE),
38 HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE),
39 HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE),
40 HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE),
41 HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE),
42 HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE),
43 HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE),
44 HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE),
45 HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE),
46 HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE),
47 HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE),
48 HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE),
49 HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE),
50 HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE),
51 HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE),
52 HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE),
53 HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE),
54 HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE),
55 HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE),
56 HOWTO(R_68K_GLOB_DAT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", FALSE, 0, 0xffffffff,FALSE),
57 HOWTO(R_68K_JMP_SLOT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", FALSE, 0, 0xffffffff,FALSE),
58 HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE),
59 /* GNU extension to record C++ vtable hierarchy. */
60 HOWTO (R_68K_GNU_VTINHERIT, /* type */
62 2, /* size (0 = byte, 1 = short, 2 = long) */
64 FALSE, /* pc_relative */
66 complain_overflow_dont, /* complain_on_overflow */
67 NULL, /* special_function */
68 "R_68K_GNU_VTINHERIT", /* name */
69 FALSE, /* partial_inplace */
73 /* GNU extension to record C++ vtable member usage. */
74 HOWTO (R_68K_GNU_VTENTRY, /* type */
76 2, /* size (0 = byte, 1 = short, 2 = long) */
78 FALSE, /* pc_relative */
80 complain_overflow_dont, /* complain_on_overflow */
81 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
82 "R_68K_GNU_VTENTRY", /* name */
83 FALSE, /* partial_inplace */
88 /* TLS general dynamic variable reference. */
89 HOWTO (R_68K_TLS_GD32, /* type */
91 2, /* size (0 = byte, 1 = short, 2 = long) */
93 FALSE, /* pc_relative */
95 complain_overflow_bitfield, /* complain_on_overflow */
96 bfd_elf_generic_reloc, /* special_function */
97 "R_68K_TLS_GD32", /* name */
98 FALSE, /* partial_inplace */
100 0xffffffff, /* dst_mask */
101 FALSE), /* pcrel_offset */
103 HOWTO (R_68K_TLS_GD16, /* type */
105 1, /* size (0 = byte, 1 = short, 2 = long) */
107 FALSE, /* pc_relative */
109 complain_overflow_signed, /* complain_on_overflow */
110 bfd_elf_generic_reloc, /* special_function */
111 "R_68K_TLS_GD16", /* name */
112 FALSE, /* partial_inplace */
114 0x0000ffff, /* dst_mask */
115 FALSE), /* pcrel_offset */
117 HOWTO (R_68K_TLS_GD8, /* type */
119 0, /* size (0 = byte, 1 = short, 2 = long) */
121 FALSE, /* pc_relative */
123 complain_overflow_signed, /* complain_on_overflow */
124 bfd_elf_generic_reloc, /* special_function */
125 "R_68K_TLS_GD8", /* name */
126 FALSE, /* partial_inplace */
128 0x000000ff, /* dst_mask */
129 FALSE), /* pcrel_offset */
131 /* TLS local dynamic variable reference. */
132 HOWTO (R_68K_TLS_LDM32, /* type */
134 2, /* size (0 = byte, 1 = short, 2 = long) */
136 FALSE, /* pc_relative */
138 complain_overflow_bitfield, /* complain_on_overflow */
139 bfd_elf_generic_reloc, /* special_function */
140 "R_68K_TLS_LDM32", /* name */
141 FALSE, /* partial_inplace */
143 0xffffffff, /* dst_mask */
144 FALSE), /* pcrel_offset */
146 HOWTO (R_68K_TLS_LDM16, /* type */
148 1, /* size (0 = byte, 1 = short, 2 = long) */
150 FALSE, /* pc_relative */
152 complain_overflow_signed, /* complain_on_overflow */
153 bfd_elf_generic_reloc, /* special_function */
154 "R_68K_TLS_LDM16", /* name */
155 FALSE, /* partial_inplace */
157 0x0000ffff, /* dst_mask */
158 FALSE), /* pcrel_offset */
160 HOWTO (R_68K_TLS_LDM8, /* type */
162 0, /* size (0 = byte, 1 = short, 2 = long) */
164 FALSE, /* pc_relative */
166 complain_overflow_signed, /* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_68K_TLS_LDM8", /* name */
169 FALSE, /* partial_inplace */
171 0x000000ff, /* dst_mask */
172 FALSE), /* pcrel_offset */
174 HOWTO (R_68K_TLS_LDO32, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 FALSE, /* pc_relative */
180 complain_overflow_bitfield, /* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_68K_TLS_LDO32", /* name */
183 FALSE, /* partial_inplace */
185 0xffffffff, /* dst_mask */
186 FALSE), /* pcrel_offset */
188 HOWTO (R_68K_TLS_LDO16, /* type */
190 1, /* size (0 = byte, 1 = short, 2 = long) */
192 FALSE, /* pc_relative */
194 complain_overflow_signed, /* complain_on_overflow */
195 bfd_elf_generic_reloc, /* special_function */
196 "R_68K_TLS_LDO16", /* name */
197 FALSE, /* partial_inplace */
199 0x0000ffff, /* dst_mask */
200 FALSE), /* pcrel_offset */
202 HOWTO (R_68K_TLS_LDO8, /* type */
204 0, /* size (0 = byte, 1 = short, 2 = long) */
206 FALSE, /* pc_relative */
208 complain_overflow_signed, /* complain_on_overflow */
209 bfd_elf_generic_reloc, /* special_function */
210 "R_68K_TLS_LDO8", /* name */
211 FALSE, /* partial_inplace */
213 0x000000ff, /* dst_mask */
214 FALSE), /* pcrel_offset */
216 /* TLS initial execution variable reference. */
217 HOWTO (R_68K_TLS_IE32, /* type */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
221 FALSE, /* pc_relative */
223 complain_overflow_bitfield, /* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
225 "R_68K_TLS_IE32", /* name */
226 FALSE, /* partial_inplace */
228 0xffffffff, /* dst_mask */
229 FALSE), /* pcrel_offset */
231 HOWTO (R_68K_TLS_IE16, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 FALSE, /* pc_relative */
237 complain_overflow_signed, /* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_68K_TLS_IE16", /* name */
240 FALSE, /* partial_inplace */
242 0x0000ffff, /* dst_mask */
243 FALSE), /* pcrel_offset */
245 HOWTO (R_68K_TLS_IE8, /* type */
247 0, /* size (0 = byte, 1 = short, 2 = long) */
249 FALSE, /* pc_relative */
251 complain_overflow_signed, /* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_68K_TLS_IE8", /* name */
254 FALSE, /* partial_inplace */
256 0x000000ff, /* dst_mask */
257 FALSE), /* pcrel_offset */
259 /* TLS local execution variable reference. */
260 HOWTO (R_68K_TLS_LE32, /* type */
262 2, /* size (0 = byte, 1 = short, 2 = long) */
264 FALSE, /* pc_relative */
266 complain_overflow_bitfield, /* complain_on_overflow */
267 bfd_elf_generic_reloc, /* special_function */
268 "R_68K_TLS_LE32", /* name */
269 FALSE, /* partial_inplace */
271 0xffffffff, /* dst_mask */
272 FALSE), /* pcrel_offset */
274 HOWTO (R_68K_TLS_LE16, /* type */
276 1, /* size (0 = byte, 1 = short, 2 = long) */
278 FALSE, /* pc_relative */
280 complain_overflow_signed, /* complain_on_overflow */
281 bfd_elf_generic_reloc, /* special_function */
282 "R_68K_TLS_LE16", /* name */
283 FALSE, /* partial_inplace */
285 0x0000ffff, /* dst_mask */
286 FALSE), /* pcrel_offset */
288 HOWTO (R_68K_TLS_LE8, /* type */
290 0, /* size (0 = byte, 1 = short, 2 = long) */
292 FALSE, /* pc_relative */
294 complain_overflow_signed, /* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_68K_TLS_LE8", /* name */
297 FALSE, /* partial_inplace */
299 0x000000ff, /* dst_mask */
300 FALSE), /* pcrel_offset */
302 /* TLS GD/LD dynamic relocations. */
303 HOWTO (R_68K_TLS_DTPMOD32, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE, /* pc_relative */
309 complain_overflow_dont, /* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_68K_TLS_DTPMOD32", /* name */
312 FALSE, /* partial_inplace */
314 0xffffffff, /* dst_mask */
315 FALSE), /* pcrel_offset */
317 HOWTO (R_68K_TLS_DTPREL32, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 FALSE, /* pc_relative */
323 complain_overflow_dont, /* complain_on_overflow */
324 bfd_elf_generic_reloc, /* special_function */
325 "R_68K_TLS_DTPREL32", /* name */
326 FALSE, /* partial_inplace */
328 0xffffffff, /* dst_mask */
329 FALSE), /* pcrel_offset */
331 HOWTO (R_68K_TLS_TPREL32, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE, /* pc_relative */
337 complain_overflow_dont, /* complain_on_overflow */
338 bfd_elf_generic_reloc, /* special_function */
339 "R_68K_TLS_TPREL32", /* name */
340 FALSE, /* partial_inplace */
342 0xffffffff, /* dst_mask */
343 FALSE), /* pcrel_offset */
347 rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
349 unsigned int indx = ELF32_R_TYPE (dst->r_info);
351 if (indx >= (unsigned int) R_68K_max)
353 /* xgettext:c-format */
354 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
356 bfd_set_error (bfd_error_bad_value);
359 cache_ptr->howto = &howto_table[indx];
363 #define elf_info_to_howto rtype_to_howto
367 bfd_reloc_code_real_type bfd_val;
372 { BFD_RELOC_NONE, R_68K_NONE },
373 { BFD_RELOC_32, R_68K_32 },
374 { BFD_RELOC_16, R_68K_16 },
375 { BFD_RELOC_8, R_68K_8 },
376 { BFD_RELOC_32_PCREL, R_68K_PC32 },
377 { BFD_RELOC_16_PCREL, R_68K_PC16 },
378 { BFD_RELOC_8_PCREL, R_68K_PC8 },
379 { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
380 { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
381 { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
382 { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
383 { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
384 { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
385 { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
386 { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
387 { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
388 { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
389 { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
390 { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
391 { BFD_RELOC_NONE, R_68K_COPY },
392 { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
393 { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
394 { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
395 { BFD_RELOC_CTOR, R_68K_32 },
396 { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
397 { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
398 { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 },
399 { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 },
400 { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 },
401 { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 },
402 { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 },
403 { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 },
404 { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 },
405 { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 },
406 { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 },
407 { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 },
408 { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 },
409 { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 },
410 { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 },
411 { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 },
412 { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 },
415 static reloc_howto_type *
416 reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
417 bfd_reloc_code_real_type code)
420 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
422 if (reloc_map[i].bfd_val == code)
423 return &howto_table[reloc_map[i].elf_val];
428 static reloc_howto_type *
429 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
433 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
434 if (howto_table[i].name != NULL
435 && strcasecmp (howto_table[i].name, r_name) == 0)
436 return &howto_table[i];
441 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
442 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
443 #define ELF_ARCH bfd_arch_m68k
444 #define ELF_TARGET_ID M68K_ELF_DATA
446 /* Functions for the m68k ELF linker. */
448 /* The name of the dynamic interpreter. This is put in the .interp
451 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
453 /* Describes one of the various PLT styles. */
455 struct elf_m68k_plt_info
457 /* The size of each PLT entry. */
460 /* The template for the first PLT entry. */
461 const bfd_byte *plt0_entry;
463 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
464 The comments by each member indicate the value that the relocation
467 unsigned int got4; /* .got + 4 */
468 unsigned int got8; /* .got + 8 */
471 /* The template for a symbol's PLT entry. */
472 const bfd_byte *symbol_entry;
474 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
475 The comments by each member indicate the value that the relocation
478 unsigned int got; /* the symbol's .got.plt entry */
479 unsigned int plt; /* .plt */
482 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
483 The stub starts with "move.l #relocoffset,%d0". */
484 bfd_vma symbol_resolve_entry;
487 /* The size in bytes of an entry in the procedure linkage table. */
489 #define PLT_ENTRY_SIZE 20
491 /* The first entry in a procedure linkage table looks like this. See
492 the SVR4 ABI m68k supplement to see how this works. */
494 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
496 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
497 0, 0, 0, 2, /* + (.got + 4) - . */
498 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
499 0, 0, 0, 2, /* + (.got + 8) - . */
500 0, 0, 0, 0 /* pad out to 20 bytes. */
503 /* Subsequent entries in a procedure linkage table look like this. */
505 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
507 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
508 0, 0, 0, 2, /* + (.got.plt entry) - . */
509 0x2f, 0x3c, /* move.l #offset,-(%sp) */
510 0, 0, 0, 0, /* + reloc index */
511 0x60, 0xff, /* bra.l .plt */
512 0, 0, 0, 0 /* + .plt - . */
515 static const struct elf_m68k_plt_info elf_m68k_plt_info =
518 elf_m68k_plt0_entry, { 4, 12 },
519 elf_m68k_plt_entry, { 4, 16 }, 8
522 #define ISAB_PLT_ENTRY_SIZE 24
524 static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
526 0x20, 0x3c, /* move.l #offset,%d0 */
527 0, 0, 0, 0, /* + (.got + 4) - . */
528 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
529 0x20, 0x3c, /* move.l #offset,%d0 */
530 0, 0, 0, 0, /* + (.got + 8) - . */
531 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
532 0x4e, 0xd0, /* jmp (%a0) */
536 /* Subsequent entries in a procedure linkage table look like this. */
538 static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
540 0x20, 0x3c, /* move.l #offset,%d0 */
541 0, 0, 0, 0, /* + (.got.plt entry) - . */
542 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
543 0x4e, 0xd0, /* jmp (%a0) */
544 0x2f, 0x3c, /* move.l #offset,-(%sp) */
545 0, 0, 0, 0, /* + reloc index */
546 0x60, 0xff, /* bra.l .plt */
547 0, 0, 0, 0 /* + .plt - . */
550 static const struct elf_m68k_plt_info elf_isab_plt_info =
553 elf_isab_plt0_entry, { 2, 12 },
554 elf_isab_plt_entry, { 2, 20 }, 12
557 #define ISAC_PLT_ENTRY_SIZE 24
559 static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
561 0x20, 0x3c, /* move.l #offset,%d0 */
562 0, 0, 0, 0, /* replaced with .got + 4 - . */
563 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
564 0x20, 0x3c, /* move.l #offset,%d0 */
565 0, 0, 0, 0, /* replaced with .got + 8 - . */
566 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
567 0x4e, 0xd0, /* jmp (%a0) */
571 /* Subsequent entries in a procedure linkage table look like this. */
573 static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
575 0x20, 0x3c, /* move.l #offset,%d0 */
576 0, 0, 0, 0, /* replaced with (.got entry) - . */
577 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
578 0x4e, 0xd0, /* jmp (%a0) */
579 0x2f, 0x3c, /* move.l #offset,-(%sp) */
580 0, 0, 0, 0, /* replaced with offset into relocation table */
581 0x61, 0xff, /* bsr.l .plt */
582 0, 0, 0, 0 /* replaced with .plt - . */
585 static const struct elf_m68k_plt_info elf_isac_plt_info =
588 elf_isac_plt0_entry, { 2, 12},
589 elf_isac_plt_entry, { 2, 20 }, 12
592 #define CPU32_PLT_ENTRY_SIZE 24
593 /* Procedure linkage table entries for the cpu32 */
594 static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
596 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
597 0, 0, 0, 2, /* + (.got + 4) - . */
598 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
599 0, 0, 0, 2, /* + (.got + 8) - . */
600 0x4e, 0xd1, /* jmp %a1@ */
601 0, 0, 0, 0, /* pad out to 24 bytes. */
605 static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
607 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
608 0, 0, 0, 2, /* + (.got.plt entry) - . */
609 0x4e, 0xd1, /* jmp %a1@ */
610 0x2f, 0x3c, /* move.l #offset,-(%sp) */
611 0, 0, 0, 0, /* + reloc index */
612 0x60, 0xff, /* bra.l .plt */
613 0, 0, 0, 0, /* + .plt - . */
617 static const struct elf_m68k_plt_info elf_cpu32_plt_info =
619 CPU32_PLT_ENTRY_SIZE,
620 elf_cpu32_plt0_entry, { 4, 12 },
621 elf_cpu32_plt_entry, { 4, 18 }, 10
624 /* The m68k linker needs to keep track of the number of relocs that it
625 decides to copy in check_relocs for each symbol. This is so that it
626 can discard PC relative relocs if it doesn't need them when linking
627 with -Bsymbolic. We store the information in a field extending the
628 regular ELF linker hash table. */
630 /* This structure keeps track of the number of PC relative relocs we have
631 copied for a given symbol. */
633 struct elf_m68k_pcrel_relocs_copied
636 struct elf_m68k_pcrel_relocs_copied *next;
637 /* A section in dynobj. */
639 /* Number of relocs copied in this section. */
643 /* Forward declaration. */
644 struct elf_m68k_got_entry;
646 /* m68k ELF linker hash entry. */
648 struct elf_m68k_link_hash_entry
650 struct elf_link_hash_entry root;
652 /* Number of PC relative relocs copied for this symbol. */
653 struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
655 /* Key to got_entries. */
656 unsigned long got_entry_key;
658 /* List of GOT entries for this symbol. This list is build during
659 offset finalization and is used within elf_m68k_finish_dynamic_symbol
660 to traverse all GOT entries for a particular symbol.
662 ??? We could've used root.got.glist field instead, but having
663 a separate field is cleaner. */
664 struct elf_m68k_got_entry *glist;
667 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
669 /* Key part of GOT entry in hashtable. */
670 struct elf_m68k_got_entry_key
672 /* BFD in which this symbol was defined. NULL for global symbols. */
675 /* Symbol index. Either local symbol index or h->got_entry_key. */
676 unsigned long symndx;
678 /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
679 R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
681 From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
682 matters. That is, we distinguish between, say, R_68K_GOT16O
683 and R_68K_GOT32O when allocating offsets, but they are considered to be
684 the same when searching got->entries. */
685 enum elf_m68k_reloc_type type;
688 /* Size of the GOT offset suitable for relocation. */
689 enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST };
691 /* Entry of the GOT. */
692 struct elf_m68k_got_entry
694 /* GOT entries are put into a got->entries hashtable. This is the key. */
695 struct elf_m68k_got_entry_key key_;
697 /* GOT entry data. We need s1 before offset finalization and s2 after. */
702 /* Number of times this entry is referenced. */
708 /* Offset from the start of .got section. To calculate offset relative
709 to GOT pointer one should subtract got->offset from this value. */
712 /* Pointer to the next GOT entry for this global symbol.
713 Symbols have at most one entry in one GOT, but might
714 have entries in more than one GOT.
715 Root of this list is h->glist.
716 NULL for local symbols. */
717 struct elf_m68k_got_entry *next;
722 /* Return representative type for relocation R_TYPE.
723 This is used to avoid enumerating many relocations in comparisons,
726 static enum elf_m68k_reloc_type
727 elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type)
731 /* In most cases R_68K_GOTx relocations require the very same
732 handling as R_68K_GOT32O relocation. In cases when we need
733 to distinguish between the two, we use explicitly compare against
746 return R_68K_TLS_GD32;
748 case R_68K_TLS_LDM32:
749 case R_68K_TLS_LDM16:
751 return R_68K_TLS_LDM32;
756 return R_68K_TLS_IE32;
764 /* Return size of the GOT entry offset for relocation R_TYPE. */
766 static enum elf_m68k_got_offset_size
767 elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type)
771 case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8:
772 case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32:
776 case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16:
780 case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8:
790 /* Return number of GOT entries we need to allocate in GOT for
791 relocation R_TYPE. */
794 elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type)
796 switch (elf_m68k_reloc_got_type (r_type))
803 case R_68K_TLS_LDM32:
812 /* Return TRUE if relocation R_TYPE is a TLS one. */
815 elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type)
819 case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8:
820 case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8:
821 case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8:
822 case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8:
823 case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8:
824 case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32:
832 /* Data structure representing a single GOT. */
835 /* Hashtable of 'struct elf_m68k_got_entry's.
836 Starting size of this table is the maximum number of
837 R_68K_GOT8O entries. */
840 /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
843 n_slots[R_8] is the count of R_8 slots in this GOT.
844 n_slots[R_16] is the cumulative count of R_8 and R_16 slots
846 n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
847 in this GOT. This is the total number of slots. */
848 bfd_vma n_slots[R_LAST];
850 /* Number of local (entry->key_.h == NULL) slots in this GOT.
851 This is only used to properly calculate size of .rela.got section;
852 see elf_m68k_partition_multi_got. */
853 bfd_vma local_n_slots;
855 /* Offset of this GOT relative to beginning of .got section. */
859 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
860 struct elf_m68k_bfd2got_entry
865 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
866 GOT structure. After partitioning several BFD's might [and often do]
867 share a single GOT. */
868 struct elf_m68k_got *got;
871 /* The main data structure holding all the pieces. */
872 struct elf_m68k_multi_got
874 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
875 here, then it doesn't need a GOT (this includes the case of a BFD
876 having an empty GOT).
878 ??? This hashtable can be replaced by an array indexed by bfd->id. */
881 /* Next symndx to assign a global symbol.
882 h->got_entry_key is initialized from this counter. */
883 unsigned long global_symndx;
886 /* m68k ELF linker hash table. */
888 struct elf_m68k_link_hash_table
890 struct elf_link_hash_table root;
892 /* Small local sym cache. */
893 struct sym_cache sym_cache;
895 /* The PLT format used by this link, or NULL if the format has not
897 const struct elf_m68k_plt_info *plt_info;
899 /* True, if GP is loaded within each function which uses it.
900 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
901 bfd_boolean local_gp_p;
903 /* Switch controlling use of negative offsets to double the size of GOTs. */
904 bfd_boolean use_neg_got_offsets_p;
906 /* Switch controlling generation of multiple GOTs. */
907 bfd_boolean allow_multigot_p;
909 /* Multi-GOT data structure. */
910 struct elf_m68k_multi_got multi_got_;
913 /* Get the m68k ELF linker hash table from a link_info structure. */
915 #define elf_m68k_hash_table(p) \
916 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
917 == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
919 /* Shortcut to multi-GOT data. */
920 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
922 /* Create an entry in an m68k ELF linker hash table. */
924 static struct bfd_hash_entry *
925 elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry,
926 struct bfd_hash_table *table,
929 struct bfd_hash_entry *ret = entry;
931 /* Allocate the structure if it has not already been allocated by a
934 ret = bfd_hash_allocate (table,
935 sizeof (struct elf_m68k_link_hash_entry));
939 /* Call the allocation method of the superclass. */
940 ret = _bfd_elf_link_hash_newfunc (ret, table, string);
943 elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
944 elf_m68k_hash_entry (ret)->got_entry_key = 0;
945 elf_m68k_hash_entry (ret)->glist = NULL;
951 /* Destroy an m68k ELF linker hash table. */
954 elf_m68k_link_hash_table_free (bfd *obfd)
956 struct elf_m68k_link_hash_table *htab;
958 htab = (struct elf_m68k_link_hash_table *) obfd->link.hash;
960 if (htab->multi_got_.bfd2got != NULL)
962 htab_delete (htab->multi_got_.bfd2got);
963 htab->multi_got_.bfd2got = NULL;
965 _bfd_elf_link_hash_table_free (obfd);
968 /* Create an m68k ELF linker hash table. */
970 static struct bfd_link_hash_table *
971 elf_m68k_link_hash_table_create (bfd *abfd)
973 struct elf_m68k_link_hash_table *ret;
974 size_t amt = sizeof (struct elf_m68k_link_hash_table);
976 ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt);
977 if (ret == (struct elf_m68k_link_hash_table *) NULL)
980 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
981 elf_m68k_link_hash_newfunc,
982 sizeof (struct elf_m68k_link_hash_entry),
988 ret->root.root.hash_table_free = elf_m68k_link_hash_table_free;
990 ret->multi_got_.global_symndx = 1;
992 return &ret->root.root;
995 /* Set the right machine number. */
998 elf32_m68k_object_p (bfd *abfd)
1000 unsigned int mach = 0;
1001 unsigned features = 0;
1002 flagword eflags = elf_elfheader (abfd)->e_flags;
1004 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1006 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1008 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1012 switch (eflags & EF_M68K_CF_ISA_MASK)
1014 case EF_M68K_CF_ISA_A_NODIV:
1015 features |= mcfisa_a;
1017 case EF_M68K_CF_ISA_A:
1018 features |= mcfisa_a|mcfhwdiv;
1020 case EF_M68K_CF_ISA_A_PLUS:
1021 features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
1023 case EF_M68K_CF_ISA_B_NOUSP:
1024 features |= mcfisa_a|mcfisa_b|mcfhwdiv;
1026 case EF_M68K_CF_ISA_B:
1027 features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
1029 case EF_M68K_CF_ISA_C:
1030 features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
1032 case EF_M68K_CF_ISA_C_NODIV:
1033 features |= mcfisa_a|mcfisa_c|mcfusp;
1036 switch (eflags & EF_M68K_CF_MAC_MASK)
1038 case EF_M68K_CF_MAC:
1041 case EF_M68K_CF_EMAC:
1042 features |= mcfemac;
1045 if (eflags & EF_M68K_CF_FLOAT)
1049 mach = bfd_m68k_features_to_mach (features);
1050 bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
1055 /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1056 field based on the machine number. */
1059 elf_m68k_final_write_processing (bfd *abfd)
1061 int mach = bfd_get_mach (abfd);
1062 unsigned long e_flags = elf_elfheader (abfd)->e_flags;
1066 unsigned int arch_mask;
1068 arch_mask = bfd_m68k_mach_to_features (mach);
1070 if (arch_mask & m68000)
1071 e_flags = EF_M68K_M68000;
1072 else if (arch_mask & cpu32)
1073 e_flags = EF_M68K_CPU32;
1074 else if (arch_mask & fido_a)
1075 e_flags = EF_M68K_FIDO;
1079 & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp))
1082 e_flags |= EF_M68K_CF_ISA_A_NODIV;
1084 case mcfisa_a | mcfhwdiv:
1085 e_flags |= EF_M68K_CF_ISA_A;
1087 case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp:
1088 e_flags |= EF_M68K_CF_ISA_A_PLUS;
1090 case mcfisa_a | mcfisa_b | mcfhwdiv:
1091 e_flags |= EF_M68K_CF_ISA_B_NOUSP;
1093 case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp:
1094 e_flags |= EF_M68K_CF_ISA_B;
1096 case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp:
1097 e_flags |= EF_M68K_CF_ISA_C;
1099 case mcfisa_a | mcfisa_c | mcfusp:
1100 e_flags |= EF_M68K_CF_ISA_C_NODIV;
1103 if (arch_mask & mcfmac)
1104 e_flags |= EF_M68K_CF_MAC;
1105 else if (arch_mask & mcfemac)
1106 e_flags |= EF_M68K_CF_EMAC;
1107 if (arch_mask & cfloat)
1108 e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
1110 elf_elfheader (abfd)->e_flags = e_flags;
1112 return _bfd_elf_final_write_processing (abfd);
1115 /* Keep m68k-specific flags in the ELF header. */
1118 elf32_m68k_set_private_flags (bfd *abfd, flagword flags)
1120 elf_elfheader (abfd)->e_flags = flags;
1121 elf_flags_init (abfd) = TRUE;
1125 /* Merge backend specific data from an object file to the output
1126 object file when linking. */
1128 elf32_m68k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
1130 bfd *obfd = info->output_bfd;
1135 const bfd_arch_info_type *arch_info;
1137 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1138 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1139 /* PR 24523: For non-ELF files do not try to merge any private
1140 data, but also do not prevent the link from succeeding. */
1143 /* Get the merged machine. This checks for incompatibility between
1144 Coldfire & non-Coldfire flags, incompability between different
1145 Coldfire ISAs, and incompability between different MAC types. */
1146 arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
1150 bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
1152 in_flags = elf_elfheader (ibfd)->e_flags;
1153 if (!elf_flags_init (obfd))
1155 elf_flags_init (obfd) = TRUE;
1156 out_flags = in_flags;
1160 out_flags = elf_elfheader (obfd)->e_flags;
1161 unsigned int variant_mask;
1163 if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1165 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1167 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1170 variant_mask = EF_M68K_CF_ISA_MASK;
1172 in_isa = (in_flags & variant_mask);
1173 out_isa = (out_flags & variant_mask);
1174 if (in_isa > out_isa)
1175 out_flags ^= in_isa ^ out_isa;
1176 if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
1177 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1178 || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
1179 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
1180 out_flags = EF_M68K_FIDO;
1182 out_flags |= in_flags ^ in_isa;
1184 elf_elfheader (obfd)->e_flags = out_flags;
1189 /* Display the flags field. */
1192 elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
1194 FILE *file = (FILE *) ptr;
1195 flagword eflags = elf_elfheader (abfd)->e_flags;
1197 BFD_ASSERT (abfd != NULL && ptr != NULL);
1199 /* Print normal ELF private data. */
1200 _bfd_elf_print_private_bfd_data (abfd, ptr);
1202 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1204 /* xgettext:c-format */
1205 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
1207 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1208 fprintf (file, " [m68000]");
1209 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1210 fprintf (file, " [cpu32]");
1211 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1212 fprintf (file, " [fido]");
1215 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
1216 fprintf (file, " [cfv4e]");
1218 if (eflags & EF_M68K_CF_ISA_MASK)
1220 char const *isa = _("unknown");
1221 char const *mac = _("unknown");
1222 char const *additional = "";
1224 switch (eflags & EF_M68K_CF_ISA_MASK)
1226 case EF_M68K_CF_ISA_A_NODIV:
1228 additional = " [nodiv]";
1230 case EF_M68K_CF_ISA_A:
1233 case EF_M68K_CF_ISA_A_PLUS:
1236 case EF_M68K_CF_ISA_B_NOUSP:
1238 additional = " [nousp]";
1240 case EF_M68K_CF_ISA_B:
1243 case EF_M68K_CF_ISA_C:
1246 case EF_M68K_CF_ISA_C_NODIV:
1248 additional = " [nodiv]";
1251 fprintf (file, " [isa %s]%s", isa, additional);
1253 if (eflags & EF_M68K_CF_FLOAT)
1254 fprintf (file, " [float]");
1256 switch (eflags & EF_M68K_CF_MAC_MASK)
1261 case EF_M68K_CF_MAC:
1264 case EF_M68K_CF_EMAC:
1267 case EF_M68K_CF_EMAC_B:
1272 fprintf (file, " [%s]", mac);
1281 /* Multi-GOT support implementation design:
1283 Multi-GOT starts in check_relocs hook. There we scan all
1284 relocations of a BFD and build a local GOT (struct elf_m68k_got)
1285 for it. If a single BFD appears to require too many GOT slots with
1286 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1288 After check_relocs has been invoked for each input BFD, we have
1289 constructed a GOT for each input BFD.
1291 To minimize total number of GOTs required for a particular output BFD
1292 (as some environments support only 1 GOT per output object) we try
1293 to merge some of the GOTs to share an offset space. Ideally [and in most
1294 cases] we end up with a single GOT. In cases when there are too many
1295 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1296 several GOTs, assuming the environment can handle them.
1298 Partitioning is done in elf_m68k_partition_multi_got. We start with
1299 an empty GOT and traverse bfd2got hashtable putting got_entries from
1300 local GOTs to the new 'big' one. We do that by constructing an
1301 intermediate GOT holding all the entries the local GOT has and the big
1302 GOT lacks. Then we check if there is room in the big GOT to accomodate
1303 all the entries from diff. On success we add those entries to the big
1304 GOT; on failure we start the new 'big' GOT and retry the adding of
1305 entries from the local GOT. Note that this retry will always succeed as
1306 each local GOT doesn't overflow the limits. After partitioning we
1307 end up with each bfd assigned one of the big GOTs. GOT entries in the
1308 big GOTs are initialized with GOT offsets. Note that big GOTs are
1309 positioned consequently in program space and represent a single huge GOT
1310 to the outside world.
1312 After that we get to elf_m68k_relocate_section. There we
1313 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1314 relocations to refer to appropriate [assigned to current input_bfd]
1319 GOT entry type: We have several types of GOT entries.
1320 * R_8 type is used in entries for symbols that have at least one
1321 R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1322 such entries in one GOT.
1323 * R_16 type is used in entries for symbols that have at least one
1324 R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1325 We can have at most 0x4000 such entries in one GOT.
1326 * R_32 type is used in all other cases. We can have as many
1327 such entries in one GOT as we'd like.
1328 When counting relocations we have to include the count of the smaller
1329 ranged relocations in the counts of the larger ranged ones in order
1330 to correctly detect overflow.
1332 Sorting the GOT: In each GOT starting offsets are assigned to
1333 R_8 entries, which are followed by R_16 entries, and
1334 R_32 entries go at the end. See finalize_got_offsets for details.
1336 Negative GOT offsets: To double usable offset range of GOTs we use
1337 negative offsets. As we assign entries with GOT offsets relative to
1338 start of .got section, the offset values are positive. They become
1339 negative only in relocate_section where got->offset value is
1340 subtracted from them.
1342 3 special GOT entries: There are 3 special GOT entries used internally
1343 by loader. These entries happen to be placed to .got.plt section,
1344 so we don't do anything about them in multi-GOT support.
1346 Memory management: All data except for hashtables
1347 multi_got->bfd2got and got->entries are allocated on
1348 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1349 to most functions), so we don't need to care to free them. At the
1350 moment of allocation hashtables are being linked into main data
1351 structure (multi_got), all pieces of which are reachable from
1352 elf_m68k_multi_got (info). We deallocate them in
1353 elf_m68k_link_hash_table_free. */
1355 /* Initialize GOT. */
1358 elf_m68k_init_got (struct elf_m68k_got *got)
1360 got->entries = NULL;
1361 got->n_slots[R_8] = 0;
1362 got->n_slots[R_16] = 0;
1363 got->n_slots[R_32] = 0;
1364 got->local_n_slots = 0;
1365 got->offset = (bfd_vma) -1;
1371 elf_m68k_clear_got (struct elf_m68k_got *got)
1373 if (got->entries != NULL)
1375 htab_delete (got->entries);
1376 got->entries = NULL;
1380 /* Create and empty GOT structure. INFO is the context where memory
1381 should be allocated. */
1383 static struct elf_m68k_got *
1384 elf_m68k_create_empty_got (struct bfd_link_info *info)
1386 struct elf_m68k_got *got;
1388 got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
1392 elf_m68k_init_got (got);
1397 /* Initialize KEY. */
1400 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
1401 struct elf_link_hash_entry *h,
1402 const bfd *abfd, unsigned long symndx,
1403 enum elf_m68k_reloc_type reloc_type)
1405 if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32)
1406 /* All TLS_LDM relocations share a single GOT entry. */
1412 /* Global symbols are identified with their got_entry_key. */
1415 key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
1416 BFD_ASSERT (key->symndx != 0);
1419 /* Local symbols are identified by BFD they appear in and symndx. */
1422 key->symndx = symndx;
1425 key->type = reloc_type;
1428 /* Calculate hash of got_entry.
1432 elf_m68k_got_entry_hash (const void *_entry)
1434 const struct elf_m68k_got_entry_key *key;
1436 key = &((const struct elf_m68k_got_entry *) _entry)->key_;
1439 + (key->bfd != NULL ? (int) key->bfd->id : -1)
1440 + elf_m68k_reloc_got_type (key->type));
1443 /* Check if two got entries are equal. */
1446 elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
1448 const struct elf_m68k_got_entry_key *key1;
1449 const struct elf_m68k_got_entry_key *key2;
1451 key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
1452 key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
1454 return (key1->bfd == key2->bfd
1455 && key1->symndx == key2->symndx
1456 && (elf_m68k_reloc_got_type (key1->type)
1457 == elf_m68k_reloc_got_type (key2->type)));
1460 /* When using negative offsets, we allocate one extra R_8, one extra R_16
1461 and one extra R_32 slots to simplify handling of 2-slot entries during
1462 offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1464 /* Maximal number of R_8 slots in a single GOT. */
1465 #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1466 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1470 /* Maximal number of R_8 and R_16 slots in a single GOT. */
1471 #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1472 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1476 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1477 the entry cannot be found.
1478 FIND_OR_CREATE - search for an existing entry, but create new if there's
1480 MUST_FIND - search for an existing entry and assert that it exist.
1481 MUST_CREATE - assert that there's no such entry and create new one. */
1482 enum elf_m68k_get_entry_howto
1490 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1491 INFO is context in which memory should be allocated (can be NULL if
1492 HOWTO is SEARCH or MUST_FIND). */
1494 static struct elf_m68k_got_entry *
1495 elf_m68k_get_got_entry (struct elf_m68k_got *got,
1496 const struct elf_m68k_got_entry_key *key,
1497 enum elf_m68k_get_entry_howto howto,
1498 struct bfd_link_info *info)
1500 struct elf_m68k_got_entry entry_;
1501 struct elf_m68k_got_entry *entry;
1504 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1506 if (got->entries == NULL)
1507 /* This is the first entry in ABFD. Initialize hashtable. */
1509 if (howto == SEARCH)
1512 got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1514 elf_m68k_got_entry_hash,
1515 elf_m68k_got_entry_eq, NULL);
1516 if (got->entries == NULL)
1518 bfd_set_error (bfd_error_no_memory);
1524 ptr = htab_find_slot (got->entries, &entry_,
1525 (howto == SEARCH || howto == MUST_FIND ? NO_INSERT
1529 if (howto == SEARCH)
1530 /* Entry not found. */
1533 if (howto == MUST_FIND)
1536 /* We're out of memory. */
1537 bfd_set_error (bfd_error_no_memory);
1542 /* We didn't find the entry and we're asked to create a new one. */
1544 if (howto == MUST_FIND)
1547 BFD_ASSERT (howto != SEARCH);
1549 entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
1553 /* Initialize new entry. */
1556 entry->u.s1.refcount = 0;
1558 /* Mark the entry as not initialized. */
1559 entry->key_.type = R_68K_max;
1564 /* We found the entry. */
1566 BFD_ASSERT (howto != MUST_CREATE);
1574 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1575 Return the value to which ENTRY's type should be set. */
1577 static enum elf_m68k_reloc_type
1578 elf_m68k_update_got_entry_type (struct elf_m68k_got *got,
1579 enum elf_m68k_reloc_type was,
1580 enum elf_m68k_reloc_type new_reloc)
1582 enum elf_m68k_got_offset_size was_size;
1583 enum elf_m68k_got_offset_size new_size;
1586 if (was == R_68K_max)
1587 /* The type of the entry is not initialized yet. */
1589 /* Update all got->n_slots counters, including n_slots[R_32]. */
1596 /* !!! We, probably, should emit an error rather then fail on assert
1598 BFD_ASSERT (elf_m68k_reloc_got_type (was)
1599 == elf_m68k_reloc_got_type (new_reloc));
1601 was_size = elf_m68k_reloc_got_offset_size (was);
1604 new_size = elf_m68k_reloc_got_offset_size (new_reloc);
1605 n_slots = elf_m68k_reloc_got_n_slots (new_reloc);
1607 while (was_size > new_size)
1610 got->n_slots[was_size] += n_slots;
1613 if (new_reloc > was)
1614 /* Relocations are ordered from bigger got offset size to lesser,
1615 so choose the relocation type with lesser offset size. */
1621 /* Add new or update existing entry to GOT.
1622 H, ABFD, TYPE and SYMNDX is data for the entry.
1623 INFO is a context where memory should be allocated. */
1625 static struct elf_m68k_got_entry *
1626 elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
1627 struct elf_link_hash_entry *h,
1629 enum elf_m68k_reloc_type reloc_type,
1630 unsigned long symndx,
1631 struct bfd_link_info *info)
1633 struct elf_m68k_got_entry_key key_;
1634 struct elf_m68k_got_entry *entry;
1636 if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
1637 elf_m68k_hash_entry (h)->got_entry_key
1638 = elf_m68k_multi_got (info)->global_symndx++;
1640 elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type);
1642 entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
1646 /* Determine entry's type and update got->n_slots counters. */
1647 entry->key_.type = elf_m68k_update_got_entry_type (got,
1651 /* Update refcount. */
1652 ++entry->u.s1.refcount;
1654 if (entry->u.s1.refcount == 1)
1655 /* We see this entry for the first time. */
1657 if (entry->key_.bfd != NULL)
1658 got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type);
1661 BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
1663 if ((got->n_slots[R_8]
1664 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1665 || (got->n_slots[R_16]
1666 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1667 /* This BFD has too many relocation. */
1669 if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1670 /* xgettext:c-format */
1671 _bfd_error_handler (_("%pB: GOT overflow: "
1672 "number of relocations with 8-bit "
1675 ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info));
1677 /* xgettext:c-format */
1678 _bfd_error_handler (_("%pB: GOT overflow: "
1679 "number of relocations with 8- or 16-bit "
1682 ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info));
1690 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1693 elf_m68k_bfd2got_entry_hash (const void *entry)
1695 const struct elf_m68k_bfd2got_entry *e;
1697 e = (const struct elf_m68k_bfd2got_entry *) entry;
1702 /* Check whether two hash entries have the same bfd. */
1705 elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
1707 const struct elf_m68k_bfd2got_entry *e1;
1708 const struct elf_m68k_bfd2got_entry *e2;
1710 e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
1711 e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
1713 return e1->bfd == e2->bfd;
1716 /* Destruct a bfd2got entry. */
1719 elf_m68k_bfd2got_entry_del (void *_entry)
1721 struct elf_m68k_bfd2got_entry *entry;
1723 entry = (struct elf_m68k_bfd2got_entry *) _entry;
1725 BFD_ASSERT (entry->got != NULL);
1726 elf_m68k_clear_got (entry->got);
1729 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1730 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1731 memory should be allocated. */
1733 static struct elf_m68k_bfd2got_entry *
1734 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
1736 enum elf_m68k_get_entry_howto howto,
1737 struct bfd_link_info *info)
1739 struct elf_m68k_bfd2got_entry entry_;
1741 struct elf_m68k_bfd2got_entry *entry;
1743 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1745 if (multi_got->bfd2got == NULL)
1746 /* This is the first GOT. Initialize bfd2got. */
1748 if (howto == SEARCH)
1751 multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
1752 elf_m68k_bfd2got_entry_eq,
1753 elf_m68k_bfd2got_entry_del);
1754 if (multi_got->bfd2got == NULL)
1756 bfd_set_error (bfd_error_no_memory);
1762 ptr = htab_find_slot (multi_got->bfd2got, &entry_,
1763 (howto == SEARCH || howto == MUST_FIND ? NO_INSERT
1767 if (howto == SEARCH)
1768 /* Entry not found. */
1771 if (howto == MUST_FIND)
1774 /* We're out of memory. */
1775 bfd_set_error (bfd_error_no_memory);
1780 /* Entry was not found. Create new one. */
1782 if (howto == MUST_FIND)
1785 BFD_ASSERT (howto != SEARCH);
1787 entry = ((struct elf_m68k_bfd2got_entry *)
1788 bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
1794 entry->got = elf_m68k_create_empty_got (info);
1795 if (entry->got == NULL)
1802 BFD_ASSERT (howto != MUST_CREATE);
1804 /* Return existing entry. */
1811 struct elf_m68k_can_merge_gots_arg
1813 /* A current_got that we constructing a DIFF against. */
1814 struct elf_m68k_got *big;
1816 /* GOT holding entries not present or that should be changed in
1818 struct elf_m68k_got *diff;
1820 /* Context where to allocate memory. */
1821 struct bfd_link_info *info;
1824 bfd_boolean error_p;
1827 /* Process a single entry from the small GOT to see if it should be added
1828 or updated in the big GOT. */
1831 elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
1833 const struct elf_m68k_got_entry *entry1;
1834 struct elf_m68k_can_merge_gots_arg *arg;
1835 const struct elf_m68k_got_entry *entry2;
1836 enum elf_m68k_reloc_type type;
1838 entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
1839 arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
1841 entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
1844 /* We found an existing entry. Check if we should update it. */
1846 type = elf_m68k_update_got_entry_type (arg->diff,
1850 if (type == entry2->key_.type)
1851 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1852 To skip creation of difference entry we use the type,
1853 which we won't see in GOT entries for sure. */
1857 /* We didn't find the entry. Add entry1 to DIFF. */
1859 BFD_ASSERT (entry1->key_.type != R_68K_max);
1861 type = elf_m68k_update_got_entry_type (arg->diff,
1862 R_68K_max, entry1->key_.type);
1864 if (entry1->key_.bfd != NULL)
1865 arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type);
1868 if (type != R_68K_max)
1869 /* Create an entry in DIFF. */
1871 struct elf_m68k_got_entry *entry;
1873 entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
1877 arg->error_p = TRUE;
1881 entry->key_.type = type;
1887 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1888 Construct DIFF GOT holding the entries which should be added or updated
1889 in BIG GOT to accumulate information from SMALL.
1890 INFO is the context where memory should be allocated. */
1893 elf_m68k_can_merge_gots (struct elf_m68k_got *big,
1894 const struct elf_m68k_got *small,
1895 struct bfd_link_info *info,
1896 struct elf_m68k_got *diff)
1898 struct elf_m68k_can_merge_gots_arg arg_;
1900 BFD_ASSERT (small->offset == (bfd_vma) -1);
1905 arg_.error_p = FALSE;
1906 htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
1913 /* Check for overflow. */
1914 if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8]
1915 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1916 || (big->n_slots[R_16] + arg_.diff->n_slots[R_16]
1917 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1923 struct elf_m68k_merge_gots_arg
1926 struct elf_m68k_got *big;
1928 /* Context where memory should be allocated. */
1929 struct bfd_link_info *info;
1932 bfd_boolean error_p;
1935 /* Process a single entry from DIFF got. Add or update corresponding
1936 entry in the BIG got. */
1939 elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
1941 const struct elf_m68k_got_entry *from;
1942 struct elf_m68k_merge_gots_arg *arg;
1943 struct elf_m68k_got_entry *to;
1945 from = (const struct elf_m68k_got_entry *) *entry_ptr;
1946 arg = (struct elf_m68k_merge_gots_arg *) _arg;
1948 to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
1952 arg->error_p = TRUE;
1956 BFD_ASSERT (to->u.s1.refcount == 0);
1957 /* All we need to merge is TYPE. */
1958 to->key_.type = from->key_.type;
1963 /* Merge data from DIFF to BIG. INFO is context where memory should be
1967 elf_m68k_merge_gots (struct elf_m68k_got *big,
1968 struct elf_m68k_got *diff,
1969 struct bfd_link_info *info)
1971 if (diff->entries != NULL)
1972 /* DIFF is not empty. Merge it into BIG GOT. */
1974 struct elf_m68k_merge_gots_arg arg_;
1976 /* Merge entries. */
1979 arg_.error_p = FALSE;
1980 htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
1984 /* Merge counters. */
1985 big->n_slots[R_8] += diff->n_slots[R_8];
1986 big->n_slots[R_16] += diff->n_slots[R_16];
1987 big->n_slots[R_32] += diff->n_slots[R_32];
1988 big->local_n_slots += diff->local_n_slots;
1991 /* DIFF is empty. */
1993 BFD_ASSERT (diff->n_slots[R_8] == 0);
1994 BFD_ASSERT (diff->n_slots[R_16] == 0);
1995 BFD_ASSERT (diff->n_slots[R_32] == 0);
1996 BFD_ASSERT (diff->local_n_slots == 0);
1999 BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
2000 || ((big->n_slots[R_8]
2001 <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
2002 && (big->n_slots[R_16]
2003 <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))));
2008 struct elf_m68k_finalize_got_offsets_arg
2010 /* Ranges of the offsets for GOT entries.
2011 R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2012 R_x is R_8, R_16 and R_32. */
2016 /* Mapping from global symndx to global symbols.
2017 This is used to build lists of got entries for global symbols. */
2018 struct elf_m68k_link_hash_entry **symndx2h;
2020 bfd_vma n_ldm_entries;
2023 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
2027 elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
2029 struct elf_m68k_got_entry *entry;
2030 struct elf_m68k_finalize_got_offsets_arg *arg;
2032 enum elf_m68k_got_offset_size got_offset_size;
2035 entry = (struct elf_m68k_got_entry *) *entry_ptr;
2036 arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
2038 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2039 BFD_ASSERT (entry->u.s1.refcount == 0);
2041 /* Get GOT offset size for the entry . */
2042 got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type);
2044 /* Calculate entry size in bytes. */
2045 entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type);
2047 /* Check if we should switch to negative range of the offsets. */
2048 if (arg->offset1[got_offset_size] + entry_size
2049 > arg->offset2[got_offset_size])
2051 /* Verify that this is the only switch to negative range for
2052 got_offset_size. If this assertion fails, then we've miscalculated
2053 range for got_offset_size entries in
2054 elf_m68k_finalize_got_offsets. */
2055 BFD_ASSERT (arg->offset2[got_offset_size]
2056 != arg->offset2[-(int) got_offset_size - 1]);
2059 arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1];
2060 arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1];
2062 /* Verify that now we have enough room for the entry. */
2063 BFD_ASSERT (arg->offset1[got_offset_size] + entry_size
2064 <= arg->offset2[got_offset_size]);
2067 /* Assign offset to entry. */
2068 entry->u.s2.offset = arg->offset1[got_offset_size];
2069 arg->offset1[got_offset_size] += entry_size;
2071 if (entry->key_.bfd == NULL)
2072 /* Hook up this entry into the list of got_entries of H. */
2074 struct elf_m68k_link_hash_entry *h;
2076 h = arg->symndx2h[entry->key_.symndx];
2079 entry->u.s2.next = h->glist;
2083 /* This should be the entry for TLS_LDM relocation then. */
2085 BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type)
2087 && entry->key_.symndx == 0);
2089 ++arg->n_ldm_entries;
2093 /* This entry is for local symbol. */
2094 entry->u.s2.next = NULL;
2099 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2100 should use negative offsets.
2101 Build list of GOT entries for global symbols along the way.
2102 SYMNDX2H is mapping from global symbol indices to actual
2104 Return offset at which next GOT should start. */
2107 elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
2108 bfd_boolean use_neg_got_offsets_p,
2109 struct elf_m68k_link_hash_entry **symndx2h,
2110 bfd_vma *final_offset, bfd_vma *n_ldm_entries)
2112 struct elf_m68k_finalize_got_offsets_arg arg_;
2113 bfd_vma offset1_[2 * R_LAST];
2114 bfd_vma offset2_[2 * R_LAST];
2116 bfd_vma start_offset;
2118 BFD_ASSERT (got->offset != (bfd_vma) -1);
2120 /* We set entry offsets relative to the .got section (and not the
2121 start of a particular GOT), so that we can use them in
2122 finish_dynamic_symbol without needing to know the GOT which they come
2125 /* Put offset1 in the middle of offset1_, same for offset2. */
2126 arg_.offset1 = offset1_ + R_LAST;
2127 arg_.offset2 = offset2_ + R_LAST;
2129 start_offset = got->offset;
2131 if (use_neg_got_offsets_p)
2132 /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2133 i = -(int) R_32 - 1;
2135 /* Setup positives ranges for R_8, R_16 and R_32. */
2138 for (; i <= (int) R_32; ++i)
2143 /* Set beginning of the range of offsets I. */
2144 arg_.offset1[i] = start_offset;
2146 /* Calculate number of slots that require I offsets. */
2147 j = (i >= 0) ? i : -i - 1;
2148 n = (j >= 1) ? got->n_slots[j - 1] : 0;
2149 n = got->n_slots[j] - n;
2151 if (use_neg_got_offsets_p && n != 0)
2154 /* We first fill the positive side of the range, so we might
2155 end up with one empty slot at that side when we can't fit
2156 whole 2-slot entry. Account for that at negative side of
2157 the interval with one additional entry. */
2160 /* When the number of slots is odd, make positive side of the
2161 range one entry bigger. */
2165 /* N is the number of slots that require I offsets.
2166 Calculate length of the range for I offsets. */
2169 /* Set end of the range. */
2170 arg_.offset2[i] = start_offset + n;
2172 start_offset = arg_.offset2[i];
2175 if (!use_neg_got_offsets_p)
2176 /* Make sure that if we try to switch to negative offsets in
2177 elf_m68k_finalize_got_offsets_1, the assert therein will catch
2179 for (i = R_8; i <= R_32; ++i)
2180 arg_.offset2[-i - 1] = arg_.offset2[i];
2182 /* Setup got->offset. offset1[R_8] is either in the middle or at the
2183 beginning of GOT depending on use_neg_got_offsets_p. */
2184 got->offset = arg_.offset1[R_8];
2186 arg_.symndx2h = symndx2h;
2187 arg_.n_ldm_entries = 0;
2189 /* Assign offsets. */
2190 htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
2192 /* Check offset ranges we have actually assigned. */
2193 for (i = (int) R_8; i <= (int) R_32; ++i)
2194 BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4);
2196 *final_offset = start_offset;
2197 *n_ldm_entries = arg_.n_ldm_entries;
2200 struct elf_m68k_partition_multi_got_arg
2202 /* The GOT we are adding entries to. Aka big got. */
2203 struct elf_m68k_got *current_got;
2205 /* Offset to assign the next CURRENT_GOT. */
2208 /* Context where memory should be allocated. */
2209 struct bfd_link_info *info;
2211 /* Total number of slots in the .got section.
2212 This is used to calculate size of the .got and .rela.got sections. */
2215 /* Difference in numbers of allocated slots in the .got section
2216 and necessary relocations in the .rela.got section.
2217 This is used to calculate size of the .rela.got section. */
2218 bfd_vma slots_relas_diff;
2221 bfd_boolean error_p;
2223 /* Mapping from global symndx to global symbols.
2224 This is used to build lists of got entries for global symbols. */
2225 struct elf_m68k_link_hash_entry **symndx2h;
2229 elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg)
2231 bfd_vma n_ldm_entries;
2233 elf_m68k_finalize_got_offsets (arg->current_got,
2234 (elf_m68k_hash_table (arg->info)
2235 ->use_neg_got_offsets_p),
2237 &arg->offset, &n_ldm_entries);
2239 arg->n_slots += arg->current_got->n_slots[R_32];
2241 if (!bfd_link_pic (arg->info))
2242 /* If we are generating a shared object, we need to
2243 output a R_68K_RELATIVE reloc so that the dynamic
2244 linker can adjust this GOT entry. Overwise we
2245 don't need space in .rela.got for local symbols. */
2246 arg->slots_relas_diff += arg->current_got->local_n_slots;
2248 /* @LDM relocations require a 2-slot GOT entry, but only
2249 one relocation. Account for that. */
2250 arg->slots_relas_diff += n_ldm_entries;
2252 BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots);
2256 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2257 or start a new CURRENT_GOT. */
2260 elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
2262 struct elf_m68k_bfd2got_entry *entry;
2263 struct elf_m68k_partition_multi_got_arg *arg;
2264 struct elf_m68k_got *got;
2265 struct elf_m68k_got diff_;
2266 struct elf_m68k_got *diff;
2268 entry = (struct elf_m68k_bfd2got_entry *) *_entry;
2269 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2272 BFD_ASSERT (got != NULL);
2273 BFD_ASSERT (got->offset == (bfd_vma) -1);
2277 if (arg->current_got != NULL)
2278 /* Construct diff. */
2281 elf_m68k_init_got (diff);
2283 if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
2285 if (diff->offset == 0)
2286 /* Offset set to 0 in the diff_ indicates an error. */
2288 arg->error_p = TRUE;
2292 if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
2294 elf_m68k_clear_got (diff);
2295 /* Schedule to finish up current_got and start new one. */
2299 Merge GOTs no matter what. If big GOT overflows,
2300 we'll fail in relocate_section due to truncated relocations.
2302 ??? May be fail earlier? E.g., in can_merge_gots. */
2306 /* Diff of got against empty current_got is got itself. */
2308 /* Create empty current_got to put subsequent GOTs to. */
2309 arg->current_got = elf_m68k_create_empty_got (arg->info);
2310 if (arg->current_got == NULL)
2312 arg->error_p = TRUE;
2316 arg->current_got->offset = arg->offset;
2323 if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info))
2325 arg->error_p = TRUE;
2329 /* Now we can free GOT. */
2330 elf_m68k_clear_got (got);
2332 entry->got = arg->current_got;
2336 /* Finish up current_got. */
2337 elf_m68k_partition_multi_got_2 (arg);
2339 /* Schedule to start a new current_got. */
2340 arg->current_got = NULL;
2343 if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
2345 BFD_ASSERT (arg->error_p);
2352 elf_m68k_clear_got (diff);
2354 return !arg->error_p;
2357 /* Helper function to build symndx2h mapping. */
2360 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
2363 struct elf_m68k_link_hash_entry *h;
2365 h = elf_m68k_hash_entry (_h);
2367 if (h->got_entry_key != 0)
2368 /* H has at least one entry in the GOT. */
2370 struct elf_m68k_partition_multi_got_arg *arg;
2372 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2374 BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
2375 arg->symndx2h[h->got_entry_key] = h;
2381 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2382 lists of GOT entries for global symbols.
2383 Calculate sizes of .got and .rela.got sections. */
2386 elf_m68k_partition_multi_got (struct bfd_link_info *info)
2388 struct elf_m68k_multi_got *multi_got;
2389 struct elf_m68k_partition_multi_got_arg arg_;
2391 multi_got = elf_m68k_multi_got (info);
2393 arg_.current_got = NULL;
2397 arg_.slots_relas_diff = 0;
2398 arg_.error_p = FALSE;
2400 if (multi_got->bfd2got != NULL)
2402 /* Initialize symndx2h mapping. */
2404 arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
2405 * sizeof (*arg_.symndx2h));
2406 if (arg_.symndx2h == NULL)
2409 elf_link_hash_traverse (elf_hash_table (info),
2410 elf_m68k_init_symndx2h_1, &arg_);
2414 htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
2418 free (arg_.symndx2h);
2419 arg_.symndx2h = NULL;
2424 /* Finish up last current_got. */
2425 elf_m68k_partition_multi_got_2 (&arg_);
2427 free (arg_.symndx2h);
2430 if (elf_hash_table (info)->dynobj != NULL)
2431 /* Set sizes of .got and .rela.got sections. */
2435 s = elf_hash_table (info)->sgot;
2437 s->size = arg_.offset;
2439 BFD_ASSERT (arg_.offset == 0);
2441 BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots);
2442 arg_.n_slots -= arg_.slots_relas_diff;
2444 s = elf_hash_table (info)->srelgot;
2446 s->size = arg_.n_slots * sizeof (Elf32_External_Rela);
2448 BFD_ASSERT (arg_.n_slots == 0);
2451 BFD_ASSERT (multi_got->bfd2got == NULL);
2456 /* Copy any information related to dynamic linking from a pre-existing
2457 symbol to a newly created symbol. Also called to copy flags and
2458 other back-end info to a weakdef, in which case the symbol is not
2459 newly created and plt/got refcounts and dynamic indices should not
2463 elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
2464 struct elf_link_hash_entry *_dir,
2465 struct elf_link_hash_entry *_ind)
2467 struct elf_m68k_link_hash_entry *dir;
2468 struct elf_m68k_link_hash_entry *ind;
2470 _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
2472 if (_ind->root.type != bfd_link_hash_indirect)
2475 dir = elf_m68k_hash_entry (_dir);
2476 ind = elf_m68k_hash_entry (_ind);
2478 /* Any absolute non-dynamic relocations against an indirect or weak
2479 definition will be against the target symbol. */
2480 _dir->non_got_ref |= _ind->non_got_ref;
2482 /* We might have a direct symbol already having entries in the GOTs.
2483 Update its key only in case indirect symbol has GOT entries and
2484 assert that both indirect and direct symbols don't have GOT entries
2485 at the same time. */
2486 if (ind->got_entry_key != 0)
2488 BFD_ASSERT (dir->got_entry_key == 0);
2489 /* Assert that GOTs aren't partioned yet. */
2490 BFD_ASSERT (ind->glist == NULL);
2492 dir->got_entry_key = ind->got_entry_key;
2493 ind->got_entry_key = 0;
2497 /* Look through the relocs for a section during the first phase, and
2498 allocate space in the global offset table or procedure linkage
2502 elf_m68k_check_relocs (bfd *abfd,
2503 struct bfd_link_info *info,
2505 const Elf_Internal_Rela *relocs)
2508 Elf_Internal_Shdr *symtab_hdr;
2509 struct elf_link_hash_entry **sym_hashes;
2510 const Elf_Internal_Rela *rel;
2511 const Elf_Internal_Rela *rel_end;
2513 struct elf_m68k_got *got;
2515 if (bfd_link_relocatable (info))
2518 dynobj = elf_hash_table (info)->dynobj;
2519 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2520 sym_hashes = elf_sym_hashes (abfd);
2526 rel_end = relocs + sec->reloc_count;
2527 for (rel = relocs; rel < rel_end; rel++)
2529 unsigned long r_symndx;
2530 struct elf_link_hash_entry *h;
2532 r_symndx = ELF32_R_SYM (rel->r_info);
2534 if (r_symndx < symtab_hdr->sh_info)
2538 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2539 while (h->root.type == bfd_link_hash_indirect
2540 || h->root.type == bfd_link_hash_warning)
2541 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2544 switch (ELF32_R_TYPE (rel->r_info))
2550 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2554 /* Relative GOT relocations. */
2560 /* TLS relocations. */
2562 case R_68K_TLS_GD16:
2563 case R_68K_TLS_GD32:
2564 case R_68K_TLS_LDM8:
2565 case R_68K_TLS_LDM16:
2566 case R_68K_TLS_LDM32:
2568 case R_68K_TLS_IE16:
2569 case R_68K_TLS_IE32:
2571 case R_68K_TLS_TPREL32:
2572 case R_68K_TLS_DTPREL32:
2574 if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
2575 && bfd_link_pic (info))
2576 /* Do the special chorus for libraries with static TLS. */
2577 info->flags |= DF_STATIC_TLS;
2579 /* This symbol requires a global offset table entry. */
2583 /* Create the .got section. */
2584 elf_hash_table (info)->dynobj = dynobj = abfd;
2585 if (!_bfd_elf_create_got_section (dynobj, info))
2591 struct elf_m68k_bfd2got_entry *bfd2got_entry;
2594 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2595 abfd, FIND_OR_CREATE, info);
2596 if (bfd2got_entry == NULL)
2599 got = bfd2got_entry->got;
2600 BFD_ASSERT (got != NULL);
2604 struct elf_m68k_got_entry *got_entry;
2606 /* Add entry to got. */
2607 got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
2608 ELF32_R_TYPE (rel->r_info),
2610 if (got_entry == NULL)
2613 if (got_entry->u.s1.refcount == 1)
2615 /* Make sure this symbol is output as a dynamic symbol. */
2618 && !h->forced_local)
2620 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2631 /* This symbol requires a procedure linkage table entry. We
2632 actually build the entry in adjust_dynamic_symbol,
2633 because this might be a case of linking PIC code which is
2634 never referenced by a dynamic object, in which case we
2635 don't need to generate a procedure linkage table entry
2638 /* If this is a local symbol, we resolve it directly without
2639 creating a procedure linkage table entry. */
2650 /* This symbol requires a procedure linkage table entry. */
2654 /* It does not make sense to have this relocation for a
2655 local symbol. FIXME: does it? How to handle it if
2656 it does make sense? */
2657 bfd_set_error (bfd_error_bad_value);
2661 /* Make sure this symbol is output as a dynamic symbol. */
2662 if (h->dynindx == -1
2663 && !h->forced_local)
2665 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2676 /* If we are creating a shared library and this is not a local
2677 symbol, we need to copy the reloc into the shared library.
2678 However when linking with -Bsymbolic and this is a global
2679 symbol which is defined in an object we are including in the
2680 link (i.e., DEF_REGULAR is set), then we can resolve the
2681 reloc directly. At this point we have not seen all the input
2682 files, so it is possible that DEF_REGULAR is not set now but
2683 will be set later (it is never cleared). We account for that
2684 possibility below by storing information in the
2685 pcrel_relocs_copied field of the hash table entry. */
2686 if (!(bfd_link_pic (info)
2687 && (sec->flags & SEC_ALLOC) != 0
2689 && (!SYMBOLIC_BIND (info, h)
2690 || h->root.type == bfd_link_hash_defweak
2691 || !h->def_regular)))
2695 /* Make sure a plt entry is created for this symbol if
2696 it turns out to be a function defined by a dynamic
2706 /* We don't need to handle relocs into sections not going into
2707 the "real" output. */
2708 if ((sec->flags & SEC_ALLOC) == 0)
2713 /* Make sure a plt entry is created for this symbol if it
2714 turns out to be a function defined by a dynamic object. */
2717 if (bfd_link_executable (info))
2718 /* This symbol needs a non-GOT reference. */
2722 /* If we are creating a shared library, we need to copy the
2723 reloc into the shared library. */
2724 if (bfd_link_pic (info)
2726 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)))
2728 /* When creating a shared object, we must copy these
2729 reloc types into the output file. We create a reloc
2730 section in dynobj and make room for this reloc. */
2733 sreloc = _bfd_elf_make_dynamic_reloc_section
2734 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2740 if (sec->flags & SEC_READONLY
2741 /* Don't set DF_TEXTREL yet for PC relative
2742 relocations, they might be discarded later. */
2743 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2744 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2745 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
2746 info->flags |= DF_TEXTREL;
2748 sreloc->size += sizeof (Elf32_External_Rela);
2750 /* We count the number of PC relative relocations we have
2751 entered for this symbol, so that we can discard them
2752 again if, in the -Bsymbolic case, the symbol is later
2753 defined by a regular object, or, in the normal shared
2754 case, the symbol is forced to be local. Note that this
2755 function is only called if we are using an m68kelf linker
2756 hash table, which means that h is really a pointer to an
2757 elf_m68k_link_hash_entry. */
2758 if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2759 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2760 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
2762 struct elf_m68k_pcrel_relocs_copied *p;
2763 struct elf_m68k_pcrel_relocs_copied **head;
2767 struct elf_m68k_link_hash_entry *eh
2768 = elf_m68k_hash_entry (h);
2769 head = &eh->pcrel_relocs_copied;
2775 Elf_Internal_Sym *isym;
2777 isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->sym_cache,
2782 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2786 vpp = &elf_section_data (s)->local_dynrel;
2787 head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
2790 for (p = *head; p != NULL; p = p->next)
2791 if (p->section == sreloc)
2796 p = ((struct elf_m68k_pcrel_relocs_copied *)
2797 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
2802 p->section = sreloc;
2812 /* This relocation describes the C++ object vtable hierarchy.
2813 Reconstruct it for later use during GC. */
2814 case R_68K_GNU_VTINHERIT:
2815 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2819 /* This relocation describes which C++ vtable entries are actually
2820 used. Record for later use during GC. */
2821 case R_68K_GNU_VTENTRY:
2822 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2834 /* Return the section that should be marked against GC for a given
2838 elf_m68k_gc_mark_hook (asection *sec,
2839 struct bfd_link_info *info,
2840 Elf_Internal_Rela *rel,
2841 struct elf_link_hash_entry *h,
2842 Elf_Internal_Sym *sym)
2845 switch (ELF32_R_TYPE (rel->r_info))
2847 case R_68K_GNU_VTINHERIT:
2848 case R_68K_GNU_VTENTRY:
2852 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2855 /* Return the type of PLT associated with OUTPUT_BFD. */
2857 static const struct elf_m68k_plt_info *
2858 elf_m68k_get_plt_info (bfd *output_bfd)
2860 unsigned int features;
2862 features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
2863 if (features & cpu32)
2864 return &elf_cpu32_plt_info;
2865 if (features & mcfisa_b)
2866 return &elf_isab_plt_info;
2867 if (features & mcfisa_c)
2868 return &elf_isac_plt_info;
2869 return &elf_m68k_plt_info;
2872 /* This function is called after all the input files have been read,
2873 and the input sections have been assigned to output sections.
2874 It's a convenient place to determine the PLT style. */
2877 elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
2879 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
2881 if (!elf_m68k_partition_multi_got (info))
2884 elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
2888 /* Adjust a symbol defined by a dynamic object and referenced by a
2889 regular object. The current definition is in some section of the
2890 dynamic object, but we're not including those sections. We have to
2891 change the definition to something the rest of the link can
2895 elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info,
2896 struct elf_link_hash_entry *h)
2898 struct elf_m68k_link_hash_table *htab;
2902 htab = elf_m68k_hash_table (info);
2903 dynobj = htab->root.dynobj;
2905 /* Make sure we know what is going on here. */
2906 BFD_ASSERT (dynobj != NULL
2911 && !h->def_regular)));
2913 /* If this is a function, put it in the procedure linkage table. We
2914 will fill in the contents of the procedure linkage table later,
2915 when we know the address of the .got section. */
2916 if (h->type == STT_FUNC
2919 if ((h->plt.refcount <= 0
2920 || SYMBOL_CALLS_LOCAL (info, h)
2921 || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2922 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
2923 && h->root.type == bfd_link_hash_undefweak))
2924 /* We must always create the plt entry if it was referenced
2925 by a PLTxxO relocation. In this case we already recorded
2926 it as a dynamic symbol. */
2927 && h->dynindx == -1)
2929 /* This case can occur if we saw a PLTxx reloc in an input
2930 file, but the symbol was never referred to by a dynamic
2931 object, or if all references were garbage collected. In
2932 such a case, we don't actually need to build a procedure
2933 linkage table, and we can just do a PCxx reloc instead. */
2934 h->plt.offset = (bfd_vma) -1;
2939 /* Make sure this symbol is output as a dynamic symbol. */
2940 if (h->dynindx == -1
2941 && !h->forced_local)
2943 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2947 s = htab->root.splt;
2948 BFD_ASSERT (s != NULL);
2950 /* If this is the first .plt entry, make room for the special
2953 s->size = htab->plt_info->size;
2955 /* If this symbol is not defined in a regular file, and we are
2956 not generating a shared library, then set the symbol to this
2957 location in the .plt. This is required to make function
2958 pointers compare as equal between the normal executable and
2959 the shared library. */
2960 if (!bfd_link_pic (info)
2963 h->root.u.def.section = s;
2964 h->root.u.def.value = s->size;
2967 h->plt.offset = s->size;
2969 /* Make room for this entry. */
2970 s->size += htab->plt_info->size;
2972 /* We also need to make an entry in the .got.plt section, which
2973 will be placed in the .got section by the linker script. */
2974 s = htab->root.sgotplt;
2975 BFD_ASSERT (s != NULL);
2978 /* We also need to make an entry in the .rela.plt section. */
2979 s = htab->root.srelplt;
2980 BFD_ASSERT (s != NULL);
2981 s->size += sizeof (Elf32_External_Rela);
2986 /* Reinitialize the plt offset now that it is not used as a reference
2988 h->plt.offset = (bfd_vma) -1;
2990 /* If this is a weak symbol, and there is a real definition, the
2991 processor independent code will have arranged for us to see the
2992 real definition first, and we can just use the same value. */
2993 if (h->is_weakalias)
2995 struct elf_link_hash_entry *def = weakdef (h);
2996 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
2997 h->root.u.def.section = def->root.u.def.section;
2998 h->root.u.def.value = def->root.u.def.value;
3002 /* This is a reference to a symbol defined by a dynamic object which
3003 is not a function. */
3005 /* If we are creating a shared library, we must presume that the
3006 only references to the symbol are via the global offset table.
3007 For such cases we need not do anything here; the relocations will
3008 be handled correctly by relocate_section. */
3009 if (bfd_link_pic (info))
3012 /* If there are no references to this symbol that do not use the
3013 GOT, we don't need to generate a copy reloc. */
3014 if (!h->non_got_ref)
3017 /* We must allocate the symbol in our .dynbss section, which will
3018 become part of the .bss section of the executable. There will be
3019 an entry for this symbol in the .dynsym section. The dynamic
3020 object will contain position independent code, so all references
3021 from the dynamic object to this symbol will go through the global
3022 offset table. The dynamic linker will use the .dynsym entry to
3023 determine the address it must put in the global offset table, so
3024 both the dynamic object and the regular object will refer to the
3025 same memory location for the variable. */
3027 s = bfd_get_linker_section (dynobj, ".dynbss");
3028 BFD_ASSERT (s != NULL);
3030 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3031 copy the initial value out of the dynamic object and into the
3032 runtime process image. We need to remember the offset into the
3033 .rela.bss section we are going to use. */
3034 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3038 srel = bfd_get_linker_section (dynobj, ".rela.bss");
3039 BFD_ASSERT (srel != NULL);
3040 srel->size += sizeof (Elf32_External_Rela);
3044 return _bfd_elf_adjust_dynamic_copy (info, h, s);
3047 /* Set the sizes of the dynamic sections. */
3050 elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3051 struct bfd_link_info *info)
3058 dynobj = elf_hash_table (info)->dynobj;
3059 BFD_ASSERT (dynobj != NULL);
3061 if (elf_hash_table (info)->dynamic_sections_created)
3063 /* Set the contents of the .interp section to the interpreter. */
3064 if (bfd_link_executable (info) && !info->nointerp)
3066 s = bfd_get_linker_section (dynobj, ".interp");
3067 BFD_ASSERT (s != NULL);
3068 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3069 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3074 /* We may have created entries in the .rela.got section.
3075 However, if we are not creating the dynamic sections, we will
3076 not actually use these entries. Reset the size of .rela.got,
3077 which will cause it to get stripped from the output file
3079 s = elf_hash_table (info)->srelgot;
3084 /* If this is a -Bsymbolic shared link, then we need to discard all
3085 PC relative relocs against symbols defined in a regular object.
3086 For the normal shared case we discard the PC relative relocs
3087 against symbols that have become local due to visibility changes.
3088 We allocated space for them in the check_relocs routine, but we
3089 will not fill them in in the relocate_section routine. */
3090 if (bfd_link_pic (info))
3091 elf_link_hash_traverse (elf_hash_table (info),
3092 elf_m68k_discard_copies,
3095 /* The check_relocs and adjust_dynamic_symbol entry points have
3096 determined the sizes of the various dynamic sections. Allocate
3100 for (s = dynobj->sections; s != NULL; s = s->next)
3104 if ((s->flags & SEC_LINKER_CREATED) == 0)
3107 /* It's OK to base decisions on the section name, because none
3108 of the dynobj section names depend upon the input files. */
3109 name = bfd_section_name (s);
3111 if (strcmp (name, ".plt") == 0)
3113 /* Remember whether there is a PLT. */
3116 else if (CONST_STRNEQ (name, ".rela"))
3122 /* We use the reloc_count field as a counter if we need
3123 to copy relocs into the output file. */
3127 else if (! CONST_STRNEQ (name, ".got")
3128 && strcmp (name, ".dynbss") != 0)
3130 /* It's not one of our sections, so don't allocate space. */
3136 /* If we don't need this section, strip it from the
3137 output file. This is mostly to handle .rela.bss and
3138 .rela.plt. We must create both sections in
3139 create_dynamic_sections, because they must be created
3140 before the linker maps input sections to output
3141 sections. The linker does that before
3142 adjust_dynamic_symbol is called, and it is that
3143 function which decides whether anything needs to go
3144 into these sections. */
3145 s->flags |= SEC_EXCLUDE;
3149 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3152 /* Allocate memory for the section contents. */
3153 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3154 Unused entries should be reclaimed before the section's contents
3155 are written out, but at the moment this does not happen. Thus in
3156 order to prevent writing out garbage, we initialise the section's
3157 contents to zero. */
3158 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3159 if (s->contents == NULL)
3163 if (elf_hash_table (info)->dynamic_sections_created)
3165 /* Add some entries to the .dynamic section. We fill in the
3166 values later, in elf_m68k_finish_dynamic_sections, but we
3167 must add the entries now so that we get the correct size for
3168 the .dynamic section. The DT_DEBUG entry is filled in by the
3169 dynamic linker and used by the debugger. */
3170 #define add_dynamic_entry(TAG, VAL) \
3171 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3173 if (bfd_link_executable (info))
3175 if (!add_dynamic_entry (DT_DEBUG, 0))
3181 if (!add_dynamic_entry (DT_PLTGOT, 0)
3182 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3183 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3184 || !add_dynamic_entry (DT_JMPREL, 0))
3190 if (!add_dynamic_entry (DT_RELA, 0)
3191 || !add_dynamic_entry (DT_RELASZ, 0)
3192 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3196 if ((info->flags & DF_TEXTREL) != 0)
3198 if (!add_dynamic_entry (DT_TEXTREL, 0))
3202 #undef add_dynamic_entry
3207 /* This function is called via elf_link_hash_traverse if we are
3208 creating a shared object. In the -Bsymbolic case it discards the
3209 space allocated to copy PC relative relocs against symbols which
3210 are defined in regular objects. For the normal shared case, it
3211 discards space for pc-relative relocs that have become local due to
3212 symbol visibility changes. We allocated space for them in the
3213 check_relocs routine, but we won't fill them in in the
3214 relocate_section routine.
3216 We also check whether any of the remaining relocations apply
3217 against a readonly section, and set the DF_TEXTREL flag in this
3221 elf_m68k_discard_copies (struct elf_link_hash_entry *h,
3224 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3225 struct elf_m68k_pcrel_relocs_copied *s;
3227 if (!SYMBOL_CALLS_LOCAL (info, h))
3229 if ((info->flags & DF_TEXTREL) == 0)
3231 /* Look for relocations against read-only sections. */
3232 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3235 if ((s->section->flags & SEC_READONLY) != 0)
3237 info->flags |= DF_TEXTREL;
3242 /* Make sure undefined weak symbols are output as a dynamic symbol
3245 && h->root.type == bfd_link_hash_undefweak
3246 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3248 && !h->forced_local)
3250 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3257 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3260 s->section->size -= s->count * sizeof (Elf32_External_Rela);
3266 /* Install relocation RELA. */
3269 elf_m68k_install_rela (bfd *output_bfd,
3271 Elf_Internal_Rela *rela)
3275 loc = srela->contents;
3276 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
3277 bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
3280 /* Find the base offsets for thread-local storage in this object,
3281 for GD/LD and IE/LE respectively. */
3283 #define DTP_OFFSET 0x8000
3284 #define TP_OFFSET 0x7000
3287 dtpoff_base (struct bfd_link_info *info)
3289 /* If tls_sec is NULL, we should have signalled an error already. */
3290 if (elf_hash_table (info)->tls_sec == NULL)
3292 return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET;
3296 tpoff_base (struct bfd_link_info *info)
3298 /* If tls_sec is NULL, we should have signalled an error already. */
3299 if (elf_hash_table (info)->tls_sec == NULL)
3301 return elf_hash_table (info)->tls_sec->vma + TP_OFFSET;
3304 /* Output necessary relocation to handle a symbol during static link.
3305 This function is called from elf_m68k_relocate_section. */
3308 elf_m68k_init_got_entry_static (struct bfd_link_info *info,
3310 enum elf_m68k_reloc_type r_type,
3312 bfd_vma got_entry_offset,
3315 switch (elf_m68k_reloc_got_type (r_type))
3318 bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset);
3321 case R_68K_TLS_GD32:
3322 /* We know the offset within the module,
3323 put it into the second GOT slot. */
3324 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3325 sgot->contents + got_entry_offset + 4);
3328 case R_68K_TLS_LDM32:
3329 /* Mark it as belonging to module 1, the executable. */
3330 bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset);
3333 case R_68K_TLS_IE32:
3334 bfd_put_32 (output_bfd, relocation - tpoff_base (info),
3335 sgot->contents + got_entry_offset);
3343 /* Output necessary relocation to handle a local symbol
3344 during dynamic link.
3345 This function is called either from elf_m68k_relocate_section
3346 or from elf_m68k_finish_dynamic_symbol. */
3349 elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info,
3351 enum elf_m68k_reloc_type r_type,
3353 bfd_vma got_entry_offset,
3357 Elf_Internal_Rela outrel;
3359 switch (elf_m68k_reloc_got_type (r_type))
3362 /* Emit RELATIVE relocation to initialize GOT slot
3364 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3365 outrel.r_addend = relocation;
3368 case R_68K_TLS_GD32:
3369 /* We know the offset within the module,
3370 put it into the second GOT slot. */
3371 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3372 sgot->contents + got_entry_offset + 4);
3375 case R_68K_TLS_LDM32:
3376 /* We don't know the module number,
3377 create a relocation for it. */
3378 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
3379 outrel.r_addend = 0;
3382 case R_68K_TLS_IE32:
3383 /* Emit TPREL relocation to initialize GOT slot
3385 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
3386 outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma;
3393 /* Offset of the GOT entry. */
3394 outrel.r_offset = (sgot->output_section->vma
3395 + sgot->output_offset
3396 + got_entry_offset);
3398 /* Install one of the above relocations. */
3399 elf_m68k_install_rela (output_bfd, srela, &outrel);
3401 bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset);
3404 /* Relocate an M68K ELF section. */
3407 elf_m68k_relocate_section (bfd *output_bfd,
3408 struct bfd_link_info *info,
3410 asection *input_section,
3412 Elf_Internal_Rela *relocs,
3413 Elf_Internal_Sym *local_syms,
3414 asection **local_sections)
3416 Elf_Internal_Shdr *symtab_hdr;
3417 struct elf_link_hash_entry **sym_hashes;
3422 struct elf_m68k_got *got;
3423 Elf_Internal_Rela *rel;
3424 Elf_Internal_Rela *relend;
3426 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3427 sym_hashes = elf_sym_hashes (input_bfd);
3437 relend = relocs + input_section->reloc_count;
3438 for (; rel < relend; rel++)
3441 reloc_howto_type *howto;
3442 unsigned long r_symndx;
3443 struct elf_link_hash_entry *h;
3444 Elf_Internal_Sym *sym;
3447 bfd_boolean unresolved_reloc;
3448 bfd_reloc_status_type r;
3449 bfd_boolean resolved_to_zero;
3451 r_type = ELF32_R_TYPE (rel->r_info);
3452 if (r_type < 0 || r_type >= (int) R_68K_max)
3454 bfd_set_error (bfd_error_bad_value);
3457 howto = howto_table + r_type;
3459 r_symndx = ELF32_R_SYM (rel->r_info);
3464 unresolved_reloc = FALSE;
3466 if (r_symndx < symtab_hdr->sh_info)
3468 sym = local_syms + r_symndx;
3469 sec = local_sections[r_symndx];
3470 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3474 bfd_boolean warned, ignored;
3476 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3477 r_symndx, symtab_hdr, sym_hashes,
3479 unresolved_reloc, warned, ignored);
3482 if (sec != NULL && discarded_section (sec))
3483 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3484 rel, 1, relend, howto, 0, contents);
3486 if (bfd_link_relocatable (info))
3489 resolved_to_zero = (h != NULL
3490 && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
3497 /* Relocation is to the address of the entry for this symbol
3498 in the global offset table. */
3500 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3502 if (elf_m68k_hash_table (info)->local_gp_p)
3504 bfd_vma sgot_output_offset;
3507 sgot = elf_hash_table (info)->sgot;
3510 sgot_output_offset = sgot->output_offset;
3512 /* In this case we have a reference to
3513 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3515 ??? Issue a warning? */
3516 sgot_output_offset = 0;
3520 struct elf_m68k_bfd2got_entry *bfd2got_entry;
3523 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3524 input_bfd, SEARCH, NULL);
3526 if (bfd2got_entry != NULL)
3528 got = bfd2got_entry->got;
3529 BFD_ASSERT (got != NULL);
3531 got_offset = got->offset;
3534 /* In this case we have a reference to
3535 _GLOBAL_OFFSET_TABLE_, but no other references
3536 accessing any GOT entries.
3537 ??? Issue a warning? */
3541 got_offset = got->offset;
3543 /* Adjust GOT pointer to point to the GOT
3544 assigned to input_bfd. */
3545 rel->r_addend += sgot_output_offset + got_offset;
3548 BFD_ASSERT (got == NULL || got->offset == 0);
3557 case R_68K_TLS_LDM32:
3558 case R_68K_TLS_LDM16:
3559 case R_68K_TLS_LDM8:
3562 case R_68K_TLS_GD16:
3563 case R_68K_TLS_GD32:
3566 case R_68K_TLS_IE16:
3567 case R_68K_TLS_IE32:
3569 /* Relocation is the offset of the entry for this symbol in
3570 the global offset table. */
3573 struct elf_m68k_got_entry_key key_;
3577 sgot = elf_hash_table (info)->sgot;
3578 BFD_ASSERT (sgot != NULL);
3581 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3582 input_bfd, MUST_FIND,
3585 /* Get GOT offset for this symbol. */
3586 elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx,
3588 off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
3592 /* The offset must always be a multiple of 4. We use
3593 the least significant bit to record whether we have
3594 already generated the necessary reloc. */
3600 /* @TLSLDM relocations are bounded to the module, in
3601 which the symbol is defined -- not to the symbol
3603 && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32)
3607 dyn = elf_hash_table (info)->dynamic_sections_created;
3608 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
3609 bfd_link_pic (info),
3611 || (bfd_link_pic (info)
3612 && SYMBOL_REFERENCES_LOCAL (info, h))
3613 || ((ELF_ST_VISIBILITY (h->other)
3614 || resolved_to_zero)
3615 && h->root.type == bfd_link_hash_undefweak))
3617 /* This is actually a static link, or it is a
3618 -Bsymbolic link and the symbol is defined
3619 locally, or the symbol was forced to be local
3620 because of a version file. We must initialize
3621 this entry in the global offset table. Since
3622 the offset must always be a multiple of 4, we
3623 use the least significant bit to record whether
3624 we have initialized it already.
3626 When doing a dynamic link, we create a .rela.got
3627 relocation entry to initialize the value. This
3628 is done in the finish_dynamic_symbol routine. */
3630 elf_m68k_init_got_entry_static (info,
3640 unresolved_reloc = FALSE;
3642 else if (bfd_link_pic (info)) /* && h == NULL */
3643 /* Process local symbol during dynamic link. */
3645 srela = elf_hash_table (info)->srelgot;
3646 BFD_ASSERT (srela != NULL);
3648 elf_m68k_init_got_entry_local_shared (info,
3658 else /* h == NULL && !bfd_link_pic (info) */
3660 elf_m68k_init_got_entry_static (info,
3671 /* We don't use elf_m68k_reloc_got_type in the condition below
3672 because this is the only place where difference between
3673 R_68K_GOTx and R_68K_GOTxO relocations matters. */
3674 if (r_type == R_68K_GOT32O
3675 || r_type == R_68K_GOT16O
3676 || r_type == R_68K_GOT8O
3677 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32
3678 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32
3679 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32)
3681 /* GOT pointer is adjusted to point to the start/middle
3682 of local GOT. Adjust the offset accordingly. */
3683 BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
3684 || off >= got->offset);
3686 if (elf_m68k_hash_table (info)->local_gp_p)
3687 relocation = off - got->offset;
3690 BFD_ASSERT (got->offset == 0);
3691 relocation = sgot->output_offset + off;
3694 /* This relocation does not use the addend. */
3698 relocation = (sgot->output_section->vma + sgot->output_offset
3703 case R_68K_TLS_LDO32:
3704 case R_68K_TLS_LDO16:
3705 case R_68K_TLS_LDO8:
3706 relocation -= dtpoff_base (info);
3709 case R_68K_TLS_LE32:
3710 case R_68K_TLS_LE16:
3712 if (bfd_link_dll (info))
3715 /* xgettext:c-format */
3716 (_("%pB(%pA+%#" PRIx64 "): "
3717 "%s relocation not permitted in shared object"),
3718 input_bfd, input_section, (uint64_t) rel->r_offset,
3724 relocation -= tpoff_base (info);
3731 /* Relocation is to the entry for this symbol in the
3732 procedure linkage table. */
3734 /* Resolve a PLTxx reloc against a local symbol directly,
3735 without using the procedure linkage table. */
3739 if (h->plt.offset == (bfd_vma) -1
3740 || !elf_hash_table (info)->dynamic_sections_created)
3742 /* We didn't make a PLT entry for this symbol. This
3743 happens when statically linking PIC code, or when
3744 using -Bsymbolic. */
3748 splt = elf_hash_table (info)->splt;
3749 BFD_ASSERT (splt != NULL);
3751 relocation = (splt->output_section->vma
3752 + splt->output_offset
3754 unresolved_reloc = FALSE;
3760 /* Relocation is the offset of the entry for this symbol in
3761 the procedure linkage table. */
3762 BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
3764 splt = elf_hash_table (info)->splt;
3765 BFD_ASSERT (splt != NULL);
3767 relocation = h->plt.offset;
3768 unresolved_reloc = FALSE;
3770 /* This relocation does not use the addend. */
3781 if (bfd_link_pic (info)
3782 && r_symndx != STN_UNDEF
3783 && (input_section->flags & SEC_ALLOC) != 0
3785 || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3786 && !resolved_to_zero)
3787 || h->root.type != bfd_link_hash_undefweak)
3788 && ((r_type != R_68K_PC8
3789 && r_type != R_68K_PC16
3790 && r_type != R_68K_PC32)
3791 || !SYMBOL_CALLS_LOCAL (info, h)))
3793 Elf_Internal_Rela outrel;
3795 bfd_boolean skip, relocate;
3797 /* When generating a shared object, these relocations
3798 are copied into the output file to be resolved at run
3805 _bfd_elf_section_offset (output_bfd, info, input_section,
3807 if (outrel.r_offset == (bfd_vma) -1)
3809 else if (outrel.r_offset == (bfd_vma) -2)
3810 skip = TRUE, relocate = TRUE;
3811 outrel.r_offset += (input_section->output_section->vma
3812 + input_section->output_offset);
3815 memset (&outrel, 0, sizeof outrel);
3818 && (r_type == R_68K_PC8
3819 || r_type == R_68K_PC16
3820 || r_type == R_68K_PC32
3821 || !bfd_link_pic (info)
3822 || !SYMBOLIC_BIND (info, h)
3823 || !h->def_regular))
3825 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3826 outrel.r_addend = rel->r_addend;
3830 /* This symbol is local, or marked to become local. */
3831 outrel.r_addend = relocation + rel->r_addend;
3833 if (r_type == R_68K_32)
3836 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3842 if (bfd_is_abs_section (sec))
3844 else if (sec == NULL || sec->owner == NULL)
3846 bfd_set_error (bfd_error_bad_value);
3853 /* We are turning this relocation into one
3854 against a section symbol. It would be
3855 proper to subtract the symbol's value,
3856 osec->vma, from the emitted reloc addend,
3857 but ld.so expects buggy relocs. */
3858 osec = sec->output_section;
3859 indx = elf_section_data (osec)->dynindx;
3862 struct elf_link_hash_table *htab;
3863 htab = elf_hash_table (info);
3864 osec = htab->text_index_section;
3865 indx = elf_section_data (osec)->dynindx;
3867 BFD_ASSERT (indx != 0);
3870 outrel.r_info = ELF32_R_INFO (indx, r_type);
3874 sreloc = elf_section_data (input_section)->sreloc;
3878 loc = sreloc->contents;
3879 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
3880 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3882 /* This reloc will be computed at runtime, so there's no
3883 need to do anything now, except for R_68K_32
3884 relocations that have been turned into
3892 case R_68K_GNU_VTINHERIT:
3893 case R_68K_GNU_VTENTRY:
3894 /* These are no-ops in the end. */
3901 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3902 because such sections are not SEC_ALLOC and thus ld.so will
3903 not process them. */
3904 if (unresolved_reloc
3905 && !((input_section->flags & SEC_DEBUGGING) != 0
3907 && _bfd_elf_section_offset (output_bfd, info, input_section,
3908 rel->r_offset) != (bfd_vma) -1)
3911 /* xgettext:c-format */
3912 (_("%pB(%pA+%#" PRIx64 "): "
3913 "unresolvable %s relocation against symbol `%s'"),
3916 (uint64_t) rel->r_offset,
3918 h->root.root.string);
3922 if (r_symndx != STN_UNDEF
3923 && r_type != R_68K_NONE
3925 || h->root.type == bfd_link_hash_defined
3926 || h->root.type == bfd_link_hash_defweak))
3930 sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type;
3932 if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS))
3937 name = h->root.root.string;
3940 name = (bfd_elf_string_from_elf_section
3941 (input_bfd, symtab_hdr->sh_link, sym->st_name));
3942 if (name == NULL || *name == '\0')
3943 name = bfd_section_name (sec);
3947 ((sym_type == STT_TLS
3948 /* xgettext:c-format */
3949 ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
3950 /* xgettext:c-format */
3951 : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
3954 (uint64_t) rel->r_offset,
3960 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3961 contents, rel->r_offset,
3962 relocation, rel->r_addend);
3964 if (r != bfd_reloc_ok)
3969 name = h->root.root.string;
3972 name = bfd_elf_string_from_elf_section (input_bfd,
3973 symtab_hdr->sh_link,
3978 name = bfd_section_name (sec);
3981 if (r == bfd_reloc_overflow)
3982 (*info->callbacks->reloc_overflow)
3983 (info, (h ? &h->root : NULL), name, howto->name,
3984 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
3988 /* xgettext:c-format */
3989 (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
3990 input_bfd, input_section,
3991 (uint64_t) rel->r_offset, name, (int) r);
4000 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4001 into section SEC. */
4004 elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
4006 /* Make VALUE PC-relative. */
4007 value -= sec->output_section->vma + offset;
4009 /* Apply any in-place addend. */
4010 value += bfd_get_32 (sec->owner, sec->contents + offset);
4012 bfd_put_32 (sec->owner, value, sec->contents + offset);
4015 /* Finish up dynamic symbol handling. We set the contents of various
4016 dynamic sections here. */
4019 elf_m68k_finish_dynamic_symbol (bfd *output_bfd,
4020 struct bfd_link_info *info,
4021 struct elf_link_hash_entry *h,
4022 Elf_Internal_Sym *sym)
4026 dynobj = elf_hash_table (info)->dynobj;
4028 if (h->plt.offset != (bfd_vma) -1)
4030 const struct elf_m68k_plt_info *plt_info;
4036 Elf_Internal_Rela rela;
4039 /* This symbol has an entry in the procedure linkage table. Set
4042 BFD_ASSERT (h->dynindx != -1);
4044 plt_info = elf_m68k_hash_table (info)->plt_info;
4045 splt = elf_hash_table (info)->splt;
4046 sgot = elf_hash_table (info)->sgotplt;
4047 srela = elf_hash_table (info)->srelplt;
4048 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
4050 /* Get the index in the procedure linkage table which
4051 corresponds to this symbol. This is the index of this symbol
4052 in all the symbols for which we are making plt entries. The
4053 first entry in the procedure linkage table is reserved. */
4054 plt_index = (h->plt.offset / plt_info->size) - 1;
4056 /* Get the offset into the .got table of the entry that
4057 corresponds to this function. Each .got entry is 4 bytes.
4058 The first three are reserved. */
4059 got_offset = (plt_index + 3) * 4;
4061 memcpy (splt->contents + h->plt.offset,
4062 plt_info->symbol_entry,
4065 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
4066 (sgot->output_section->vma
4067 + sgot->output_offset
4070 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4073 + plt_info->symbol_resolve_entry + 2);
4075 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
4076 splt->output_section->vma);
4078 /* Fill in the entry in the global offset table. */
4079 bfd_put_32 (output_bfd,
4080 (splt->output_section->vma
4081 + splt->output_offset
4083 + plt_info->symbol_resolve_entry),
4084 sgot->contents + got_offset);
4086 /* Fill in the entry in the .rela.plt section. */
4087 rela.r_offset = (sgot->output_section->vma
4088 + sgot->output_offset
4090 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
4092 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
4093 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4095 if (!h->def_regular)
4097 /* Mark the symbol as undefined, rather than as defined in
4098 the .plt section. Leave the value alone. */
4099 sym->st_shndx = SHN_UNDEF;
4103 if (elf_m68k_hash_entry (h)->glist != NULL)
4107 struct elf_m68k_got_entry *got_entry;
4109 /* This symbol has an entry in the global offset table. Set it
4112 sgot = elf_hash_table (info)->sgot;
4113 srela = elf_hash_table (info)->srelgot;
4114 BFD_ASSERT (sgot != NULL && srela != NULL);
4116 got_entry = elf_m68k_hash_entry (h)->glist;
4118 while (got_entry != NULL)
4120 enum elf_m68k_reloc_type r_type;
4121 bfd_vma got_entry_offset;
4123 r_type = got_entry->key_.type;
4124 got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1;
4126 /* If this is a -Bsymbolic link, and the symbol is defined
4127 locally, we just want to emit a RELATIVE reloc. Likewise if
4128 the symbol was forced to be local because of a version file.
4129 The entry in the global offset table already have been
4130 initialized in the relocate_section function. */
4131 if (bfd_link_pic (info)
4132 && SYMBOL_REFERENCES_LOCAL (info, h))
4136 relocation = bfd_get_signed_32 (output_bfd,
4138 + got_entry_offset));
4141 switch (elf_m68k_reloc_got_type (r_type))
4144 case R_68K_TLS_LDM32:
4147 case R_68K_TLS_GD32:
4148 /* The value for this relocation is actually put in
4149 the second GOT slot. */
4150 relocation = bfd_get_signed_32 (output_bfd,
4152 + got_entry_offset + 4));
4153 relocation += dtpoff_base (info);
4156 case R_68K_TLS_IE32:
4157 relocation += tpoff_base (info);
4164 elf_m68k_init_got_entry_local_shared (info,
4174 Elf_Internal_Rela rela;
4176 /* Put zeros to GOT slots that will be initialized
4181 n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type);
4183 bfd_put_32 (output_bfd, (bfd_vma) 0,
4184 (sgot->contents + got_entry_offset
4189 rela.r_offset = (sgot->output_section->vma
4190 + sgot->output_offset
4191 + got_entry_offset);
4193 switch (elf_m68k_reloc_got_type (r_type))
4196 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
4197 elf_m68k_install_rela (output_bfd, srela, &rela);
4200 case R_68K_TLS_GD32:
4201 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32);
4202 elf_m68k_install_rela (output_bfd, srela, &rela);
4205 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32);
4206 elf_m68k_install_rela (output_bfd, srela, &rela);
4209 case R_68K_TLS_IE32:
4210 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32);
4211 elf_m68k_install_rela (output_bfd, srela, &rela);
4220 got_entry = got_entry->u.s2.next;
4227 Elf_Internal_Rela rela;
4230 /* This symbol needs a copy reloc. Set it up. */
4232 BFD_ASSERT (h->dynindx != -1
4233 && (h->root.type == bfd_link_hash_defined
4234 || h->root.type == bfd_link_hash_defweak));
4236 s = bfd_get_linker_section (dynobj, ".rela.bss");
4237 BFD_ASSERT (s != NULL);
4239 rela.r_offset = (h->root.u.def.value
4240 + h->root.u.def.section->output_section->vma
4241 + h->root.u.def.section->output_offset);
4242 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
4244 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4245 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4251 /* Finish up the dynamic sections. */
4254 elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4260 dynobj = elf_hash_table (info)->dynobj;
4262 sgot = elf_hash_table (info)->sgotplt;
4263 BFD_ASSERT (sgot != NULL);
4264 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4266 if (elf_hash_table (info)->dynamic_sections_created)
4269 Elf32_External_Dyn *dyncon, *dynconend;
4271 splt = elf_hash_table (info)->splt;
4272 BFD_ASSERT (splt != NULL && sdyn != NULL);
4274 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4275 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4276 for (; dyncon < dynconend; dyncon++)
4278 Elf_Internal_Dyn dyn;
4281 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4289 s = elf_hash_table (info)->sgotplt;
4292 s = elf_hash_table (info)->srelplt;
4294 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4295 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4299 s = elf_hash_table (info)->srelplt;
4300 dyn.d_un.d_val = s->size;
4301 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4306 /* Fill in the first entry in the procedure linkage table. */
4309 const struct elf_m68k_plt_info *plt_info;
4311 plt_info = elf_m68k_hash_table (info)->plt_info;
4312 memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
4314 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
4315 (sgot->output_section->vma
4316 + sgot->output_offset
4319 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
4320 (sgot->output_section->vma
4321 + sgot->output_offset
4324 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4329 /* Fill in the first three entries in the global offset table. */
4333 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4335 bfd_put_32 (output_bfd,
4336 sdyn->output_section->vma + sdyn->output_offset,
4338 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4339 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4342 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4347 /* Given a .data section and a .emreloc in-memory section, store
4348 relocation information into the .emreloc section which can be
4349 used at runtime to relocate the section. This is called by the
4350 linker when the --embedded-relocs switch is used. This is called
4351 after the add_symbols entry point has been called for all the
4352 objects, and before the final_link entry point is called. */
4355 bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
4356 asection *datasec, asection *relsec,
4359 Elf_Internal_Shdr *symtab_hdr;
4360 Elf_Internal_Sym *isymbuf = NULL;
4361 Elf_Internal_Rela *internal_relocs = NULL;
4362 Elf_Internal_Rela *irel, *irelend;
4366 BFD_ASSERT (! bfd_link_relocatable (info));
4370 if (datasec->reloc_count == 0)
4373 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4375 /* Get a copy of the native relocations. */
4376 internal_relocs = (_bfd_elf_link_read_relocs
4377 (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL,
4378 info->keep_memory));
4379 if (internal_relocs == NULL)
4382 amt = (bfd_size_type) datasec->reloc_count * 12;
4383 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
4384 if (relsec->contents == NULL)
4387 p = relsec->contents;
4389 irelend = internal_relocs + datasec->reloc_count;
4390 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
4392 asection *targetsec;
4394 /* We are going to write a four byte longword into the runtime
4395 reloc section. The longword will be the address in the data
4396 section which must be relocated. It is followed by the name
4397 of the target section NUL-padded or truncated to 8
4400 /* We can only relocate absolute longword relocs at run time. */
4401 if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
4403 *errmsg = _("unsupported relocation type");
4404 bfd_set_error (bfd_error_bad_value);
4408 /* Get the target section referred to by the reloc. */
4409 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4411 /* A local symbol. */
4412 Elf_Internal_Sym *isym;
4414 /* Read this BFD's local symbols if we haven't done so already. */
4415 if (isymbuf == NULL)
4417 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4418 if (isymbuf == NULL)
4419 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4420 symtab_hdr->sh_info, 0,
4422 if (isymbuf == NULL)
4426 isym = isymbuf + ELF32_R_SYM (irel->r_info);
4427 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4432 struct elf_link_hash_entry *h;
4434 /* An external symbol. */
4435 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4436 h = elf_sym_hashes (abfd)[indx];
4437 BFD_ASSERT (h != NULL);
4438 if (h->root.type == bfd_link_hash_defined
4439 || h->root.type == bfd_link_hash_defweak)
4440 targetsec = h->root.u.def.section;
4445 bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
4446 memset (p + 4, 0, 8);
4447 if (targetsec != NULL)
4448 strncpy ((char *) p + 4, targetsec->output_section->name, 8);
4451 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4453 if (internal_relocs != NULL
4454 && elf_section_data (datasec)->relocs != internal_relocs)
4455 free (internal_relocs);
4459 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4461 if (internal_relocs != NULL
4462 && elf_section_data (datasec)->relocs != internal_relocs)
4463 free (internal_relocs);
4467 /* Set target options. */
4470 bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
4472 struct elf_m68k_link_hash_table *htab;
4473 bfd_boolean use_neg_got_offsets_p;
4474 bfd_boolean allow_multigot_p;
4475 bfd_boolean local_gp_p;
4477 switch (got_handling)
4482 use_neg_got_offsets_p = FALSE;
4483 allow_multigot_p = FALSE;
4487 /* --got=negative. */
4489 use_neg_got_offsets_p = TRUE;
4490 allow_multigot_p = FALSE;
4494 /* --got=multigot. */
4496 use_neg_got_offsets_p = TRUE;
4497 allow_multigot_p = TRUE;
4505 htab = elf_m68k_hash_table (info);
4508 htab->local_gp_p = local_gp_p;
4509 htab->use_neg_got_offsets_p = use_neg_got_offsets_p;
4510 htab->allow_multigot_p = allow_multigot_p;
4514 static enum elf_reloc_type_class
4515 elf32_m68k_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
4516 const asection *rel_sec ATTRIBUTE_UNUSED,
4517 const Elf_Internal_Rela *rela)
4519 switch ((int) ELF32_R_TYPE (rela->r_info))
4521 case R_68K_RELATIVE:
4522 return reloc_class_relative;
4523 case R_68K_JMP_SLOT:
4524 return reloc_class_plt;
4526 return reloc_class_copy;
4528 return reloc_class_normal;
4532 /* Return address for Ith PLT stub in section PLT, for relocation REL
4533 or (bfd_vma) -1 if it should not be included. */
4536 elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
4537 const arelent *rel ATTRIBUTE_UNUSED)
4539 return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
4542 /* Support for core dump NOTE sections. */
4545 elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4550 switch (note->descsz)
4555 case 154: /* Linux/m68k */
4557 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
4560 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22);
4569 /* Make a ".reg/999" section. */
4570 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
4571 size, note->descpos + offset);
4575 elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4577 switch (note->descsz)
4582 case 124: /* Linux/m68k elf_prpsinfo. */
4583 elf_tdata (abfd)->core->pid
4584 = bfd_get_32 (abfd, note->descdata + 12);
4585 elf_tdata (abfd)->core->program
4586 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
4587 elf_tdata (abfd)->core->command
4588 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
4591 /* Note that for some reason, a spurious space is tacked
4592 onto the end of the args in some (at least one anyway)
4593 implementations, so strip it off if it exists. */
4595 char *command = elf_tdata (abfd)->core->command;
4596 int n = strlen (command);
4598 if (n > 0 && command[n - 1] == ' ')
4599 command[n - 1] = '\0';
4605 #define TARGET_BIG_SYM m68k_elf32_vec
4606 #define TARGET_BIG_NAME "elf32-m68k"
4607 #define ELF_MACHINE_CODE EM_68K
4608 #define ELF_MAXPAGESIZE 0x2000
4609 #define elf_backend_create_dynamic_sections \
4610 _bfd_elf_create_dynamic_sections
4611 #define bfd_elf32_bfd_link_hash_table_create \
4612 elf_m68k_link_hash_table_create
4613 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4615 #define elf_backend_check_relocs elf_m68k_check_relocs
4616 #define elf_backend_always_size_sections \
4617 elf_m68k_always_size_sections
4618 #define elf_backend_adjust_dynamic_symbol \
4619 elf_m68k_adjust_dynamic_symbol
4620 #define elf_backend_size_dynamic_sections \
4621 elf_m68k_size_dynamic_sections
4622 #define elf_backend_final_write_processing elf_m68k_final_write_processing
4623 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4624 #define elf_backend_relocate_section elf_m68k_relocate_section
4625 #define elf_backend_finish_dynamic_symbol \
4626 elf_m68k_finish_dynamic_symbol
4627 #define elf_backend_finish_dynamic_sections \
4628 elf_m68k_finish_dynamic_sections
4629 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4630 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4631 #define bfd_elf32_bfd_merge_private_bfd_data \
4632 elf32_m68k_merge_private_bfd_data
4633 #define bfd_elf32_bfd_set_private_flags \
4634 elf32_m68k_set_private_flags
4635 #define bfd_elf32_bfd_print_private_bfd_data \
4636 elf32_m68k_print_private_bfd_data
4637 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4638 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4639 #define elf_backend_object_p elf32_m68k_object_p
4640 #define elf_backend_grok_prstatus elf_m68k_grok_prstatus
4641 #define elf_backend_grok_psinfo elf_m68k_grok_psinfo
4643 #define elf_backend_can_gc_sections 1
4644 #define elf_backend_can_refcount 1
4645 #define elf_backend_want_got_plt 1
4646 #define elf_backend_plt_readonly 1
4647 #define elf_backend_want_plt_sym 0
4648 #define elf_backend_got_header_size 12
4649 #define elf_backend_rela_normal 1
4650 #define elf_backend_dtrel_excludes_plt 1
4652 #define elf_backend_linux_prpsinfo32_ugid16 TRUE
4654 #include "elf32-target.h"