1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
29 #include "opcode/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, 0, 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 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
357 cache_ptr->howto = &howto_table[indx];
360 #define elf_info_to_howto rtype_to_howto
364 bfd_reloc_code_real_type bfd_val;
369 { BFD_RELOC_NONE, R_68K_NONE },
370 { BFD_RELOC_32, R_68K_32 },
371 { BFD_RELOC_16, R_68K_16 },
372 { BFD_RELOC_8, R_68K_8 },
373 { BFD_RELOC_32_PCREL, R_68K_PC32 },
374 { BFD_RELOC_16_PCREL, R_68K_PC16 },
375 { BFD_RELOC_8_PCREL, R_68K_PC8 },
376 { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
377 { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
378 { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
379 { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
380 { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
381 { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
382 { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
383 { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
384 { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
385 { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
386 { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
387 { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
388 { BFD_RELOC_NONE, R_68K_COPY },
389 { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
390 { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
391 { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
392 { BFD_RELOC_CTOR, R_68K_32 },
393 { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
394 { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
395 { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 },
396 { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 },
397 { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 },
398 { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 },
399 { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 },
400 { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 },
401 { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 },
402 { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 },
403 { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 },
404 { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 },
405 { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 },
406 { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 },
407 { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 },
408 { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 },
409 { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 },
412 static reloc_howto_type *
413 reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
414 bfd_reloc_code_real_type code)
417 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
419 if (reloc_map[i].bfd_val == code)
420 return &howto_table[reloc_map[i].elf_val];
425 static reloc_howto_type *
426 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
430 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
431 if (howto_table[i].name != NULL
432 && strcasecmp (howto_table[i].name, r_name) == 0)
433 return &howto_table[i];
438 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
439 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
440 #define ELF_ARCH bfd_arch_m68k
441 #define ELF_TARGET_ID M68K_ELF_DATA
443 /* Functions for the m68k ELF linker. */
445 /* The name of the dynamic interpreter. This is put in the .interp
448 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
450 /* Describes one of the various PLT styles. */
452 struct elf_m68k_plt_info
454 /* The size of each PLT entry. */
457 /* The template for the first PLT entry. */
458 const bfd_byte *plt0_entry;
460 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
461 The comments by each member indicate the value that the relocation
464 unsigned int got4; /* .got + 4 */
465 unsigned int got8; /* .got + 8 */
468 /* The template for a symbol's PLT entry. */
469 const bfd_byte *symbol_entry;
471 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
472 The comments by each member indicate the value that the relocation
475 unsigned int got; /* the symbol's .got.plt entry */
476 unsigned int plt; /* .plt */
479 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
480 The stub starts with "move.l #relocoffset,%d0". */
481 bfd_vma symbol_resolve_entry;
484 /* The size in bytes of an entry in the procedure linkage table. */
486 #define PLT_ENTRY_SIZE 20
488 /* The first entry in a procedure linkage table looks like this. See
489 the SVR4 ABI m68k supplement to see how this works. */
491 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
493 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
494 0, 0, 0, 2, /* + (.got + 4) - . */
495 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
496 0, 0, 0, 2, /* + (.got + 8) - . */
497 0, 0, 0, 0 /* pad out to 20 bytes. */
500 /* Subsequent entries in a procedure linkage table look like this. */
502 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
504 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
505 0, 0, 0, 2, /* + (.got.plt entry) - . */
506 0x2f, 0x3c, /* move.l #offset,-(%sp) */
507 0, 0, 0, 0, /* + reloc index */
508 0x60, 0xff, /* bra.l .plt */
509 0, 0, 0, 0 /* + .plt - . */
512 static const struct elf_m68k_plt_info elf_m68k_plt_info = {
514 elf_m68k_plt0_entry, { 4, 12 },
515 elf_m68k_plt_entry, { 4, 16 }, 8
518 #define ISAB_PLT_ENTRY_SIZE 24
520 static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
522 0x20, 0x3c, /* move.l #offset,%d0 */
523 0, 0, 0, 0, /* + (.got + 4) - . */
524 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
525 0x20, 0x3c, /* move.l #offset,%d0 */
526 0, 0, 0, 0, /* + (.got + 8) - . */
527 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
528 0x4e, 0xd0, /* jmp (%a0) */
532 /* Subsequent entries in a procedure linkage table look like this. */
534 static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
536 0x20, 0x3c, /* move.l #offset,%d0 */
537 0, 0, 0, 0, /* + (.got.plt entry) - . */
538 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
539 0x4e, 0xd0, /* jmp (%a0) */
540 0x2f, 0x3c, /* move.l #offset,-(%sp) */
541 0, 0, 0, 0, /* + reloc index */
542 0x60, 0xff, /* bra.l .plt */
543 0, 0, 0, 0 /* + .plt - . */
546 static const struct elf_m68k_plt_info elf_isab_plt_info = {
548 elf_isab_plt0_entry, { 2, 12 },
549 elf_isab_plt_entry, { 2, 20 }, 12
552 #define ISAC_PLT_ENTRY_SIZE 24
554 static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
556 0x20, 0x3c, /* move.l #offset,%d0 */
557 0, 0, 0, 0, /* replaced with .got + 4 - . */
558 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
559 0x20, 0x3c, /* move.l #offset,%d0 */
560 0, 0, 0, 0, /* replaced with .got + 8 - . */
561 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
562 0x4e, 0xd0, /* jmp (%a0) */
566 /* Subsequent entries in a procedure linkage table look like this. */
568 static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
570 0x20, 0x3c, /* move.l #offset,%d0 */
571 0, 0, 0, 0, /* replaced with (.got entry) - . */
572 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
573 0x4e, 0xd0, /* jmp (%a0) */
574 0x2f, 0x3c, /* move.l #offset,-(%sp) */
575 0, 0, 0, 0, /* replaced with offset into relocation table */
576 0x61, 0xff, /* bsr.l .plt */
577 0, 0, 0, 0 /* replaced with .plt - . */
580 static const struct elf_m68k_plt_info elf_isac_plt_info = {
582 elf_isac_plt0_entry, { 2, 12},
583 elf_isac_plt_entry, { 2, 20 }, 12
586 #define CPU32_PLT_ENTRY_SIZE 24
587 /* Procedure linkage table entries for the cpu32 */
588 static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
590 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
591 0, 0, 0, 2, /* + (.got + 4) - . */
592 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
593 0, 0, 0, 2, /* + (.got + 8) - . */
594 0x4e, 0xd1, /* jmp %a1@ */
595 0, 0, 0, 0, /* pad out to 24 bytes. */
599 static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
601 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
602 0, 0, 0, 2, /* + (.got.plt entry) - . */
603 0x4e, 0xd1, /* jmp %a1@ */
604 0x2f, 0x3c, /* move.l #offset,-(%sp) */
605 0, 0, 0, 0, /* + reloc index */
606 0x60, 0xff, /* bra.l .plt */
607 0, 0, 0, 0, /* + .plt - . */
611 static const struct elf_m68k_plt_info elf_cpu32_plt_info = {
612 CPU32_PLT_ENTRY_SIZE,
613 elf_cpu32_plt0_entry, { 4, 12 },
614 elf_cpu32_plt_entry, { 4, 18 }, 10
617 /* The m68k linker needs to keep track of the number of relocs that it
618 decides to copy in check_relocs for each symbol. This is so that it
619 can discard PC relative relocs if it doesn't need them when linking
620 with -Bsymbolic. We store the information in a field extending the
621 regular ELF linker hash table. */
623 /* This structure keeps track of the number of PC relative relocs we have
624 copied for a given symbol. */
626 struct elf_m68k_pcrel_relocs_copied
629 struct elf_m68k_pcrel_relocs_copied *next;
630 /* A section in dynobj. */
632 /* Number of relocs copied in this section. */
636 /* Forward declaration. */
637 struct elf_m68k_got_entry;
639 /* m68k ELF linker hash entry. */
641 struct elf_m68k_link_hash_entry
643 struct elf_link_hash_entry root;
645 /* Number of PC relative relocs copied for this symbol. */
646 struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
648 /* Key to got_entries. */
649 unsigned long got_entry_key;
651 /* List of GOT entries for this symbol. This list is build during
652 offset finalization and is used within elf_m68k_finish_dynamic_symbol
653 to traverse all GOT entries for a particular symbol.
655 ??? We could've used root.got.glist field instead, but having
656 a separate field is cleaner. */
657 struct elf_m68k_got_entry *glist;
660 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
662 /* Key part of GOT entry in hashtable. */
663 struct elf_m68k_got_entry_key
665 /* BFD in which this symbol was defined. NULL for global symbols. */
668 /* Symbol index. Either local symbol index or h->got_entry_key. */
669 unsigned long symndx;
671 /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
672 R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
674 From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
675 matters. That is, we distinguish between, say, R_68K_GOT16O
676 and R_68K_GOT32O when allocating offsets, but they are considered to be
677 the same when searching got->entries. */
678 enum elf_m68k_reloc_type type;
681 /* Size of the GOT offset suitable for relocation. */
682 enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST };
684 /* Entry of the GOT. */
685 struct elf_m68k_got_entry
687 /* GOT entries are put into a got->entries hashtable. This is the key. */
688 struct elf_m68k_got_entry_key key_;
690 /* GOT entry data. We need s1 before offset finalization and s2 after. */
695 /* Number of times this entry is referenced. It is used to
696 filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */
702 /* Offset from the start of .got section. To calculate offset relative
703 to GOT pointer one should substract got->offset from this value. */
706 /* Pointer to the next GOT entry for this global symbol.
707 Symbols have at most one entry in one GOT, but might
708 have entries in more than one GOT.
709 Root of this list is h->glist.
710 NULL for local symbols. */
711 struct elf_m68k_got_entry *next;
716 /* Return representative type for relocation R_TYPE.
717 This is used to avoid enumerating many relocations in comparisons,
720 static enum elf_m68k_reloc_type
721 elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type)
725 /* In most cases R_68K_GOTx relocations require the very same
726 handling as R_68K_GOT32O relocation. In cases when we need
727 to distinguish between the two, we use explicitly compare against
740 return R_68K_TLS_GD32;
742 case R_68K_TLS_LDM32:
743 case R_68K_TLS_LDM16:
745 return R_68K_TLS_LDM32;
750 return R_68K_TLS_IE32;
758 /* Return size of the GOT entry offset for relocation R_TYPE. */
760 static enum elf_m68k_got_offset_size
761 elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type)
765 case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8:
766 case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32:
770 case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16:
774 case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8:
784 /* Return number of GOT entries we need to allocate in GOT for
785 relocation R_TYPE. */
788 elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type)
790 switch (elf_m68k_reloc_got_type (r_type))
797 case R_68K_TLS_LDM32:
806 /* Return TRUE if relocation R_TYPE is a TLS one. */
809 elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type)
813 case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8:
814 case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8:
815 case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8:
816 case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8:
817 case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8:
818 case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32:
826 /* Data structure representing a single GOT. */
829 /* Hashtable of 'struct elf_m68k_got_entry's.
830 Starting size of this table is the maximum number of
831 R_68K_GOT8O entries. */
834 /* Number of R_x slots in this GOT. Some (e.g., TLS) entries require
837 n_slots[R_8] is the count of R_8 slots in this GOT.
838 n_slots[R_16] is the cumulative count of R_8 and R_16 slots
840 n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
841 in this GOT. This is the total number of slots. */
842 bfd_vma n_slots[R_LAST];
844 /* Number of local (entry->key_.h == NULL) slots in this GOT.
845 This is only used to properly calculate size of .rela.got section;
846 see elf_m68k_partition_multi_got. */
847 bfd_vma local_n_slots;
849 /* Offset of this GOT relative to beginning of .got section. */
853 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
854 struct elf_m68k_bfd2got_entry
859 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
860 GOT structure. After partitioning several BFD's might [and often do]
861 share a single GOT. */
862 struct elf_m68k_got *got;
865 /* The main data structure holding all the pieces. */
866 struct elf_m68k_multi_got
868 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
869 here, then it doesn't need a GOT (this includes the case of a BFD
870 having an empty GOT).
872 ??? This hashtable can be replaced by an array indexed by bfd->id. */
875 /* Next symndx to assign a global symbol.
876 h->got_entry_key is initialized from this counter. */
877 unsigned long global_symndx;
880 /* m68k ELF linker hash table. */
882 struct elf_m68k_link_hash_table
884 struct elf_link_hash_table root;
886 /* Small local sym cache. */
887 struct sym_cache sym_cache;
889 /* The PLT format used by this link, or NULL if the format has not
891 const struct elf_m68k_plt_info *plt_info;
893 /* True, if GP is loaded within each function which uses it.
894 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
895 bfd_boolean local_gp_p;
897 /* Switch controlling use of negative offsets to double the size of GOTs. */
898 bfd_boolean use_neg_got_offsets_p;
900 /* Switch controlling generation of multiple GOTs. */
901 bfd_boolean allow_multigot_p;
903 /* Multi-GOT data structure. */
904 struct elf_m68k_multi_got multi_got_;
907 /* Get the m68k ELF linker hash table from a link_info structure. */
909 #define elf_m68k_hash_table(p) \
910 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
911 == M68K_ELF_DATA ? ((struct elf_m68k_link_hash_table *) ((p)->hash)) : NULL)
913 /* Shortcut to multi-GOT data. */
914 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
916 /* Create an entry in an m68k ELF linker hash table. */
918 static struct bfd_hash_entry *
919 elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry,
920 struct bfd_hash_table *table,
923 struct bfd_hash_entry *ret = entry;
925 /* Allocate the structure if it has not already been allocated by a
928 ret = bfd_hash_allocate (table,
929 sizeof (struct elf_m68k_link_hash_entry));
933 /* Call the allocation method of the superclass. */
934 ret = _bfd_elf_link_hash_newfunc (ret, table, string);
937 elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
938 elf_m68k_hash_entry (ret)->got_entry_key = 0;
939 elf_m68k_hash_entry (ret)->glist = NULL;
945 /* Create an m68k ELF linker hash table. */
947 static struct bfd_link_hash_table *
948 elf_m68k_link_hash_table_create (bfd *abfd)
950 struct elf_m68k_link_hash_table *ret;
951 bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table);
953 ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt);
954 if (ret == (struct elf_m68k_link_hash_table *) NULL)
957 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
958 elf_m68k_link_hash_newfunc,
959 sizeof (struct elf_m68k_link_hash_entry),
966 ret->multi_got_.global_symndx = 1;
968 return &ret->root.root;
971 /* Destruct local data. */
974 elf_m68k_link_hash_table_free (struct bfd_link_hash_table *_htab)
976 struct elf_m68k_link_hash_table *htab;
978 htab = (struct elf_m68k_link_hash_table *) _htab;
980 if (htab->multi_got_.bfd2got != NULL)
982 htab_delete (htab->multi_got_.bfd2got);
983 htab->multi_got_.bfd2got = NULL;
985 _bfd_elf_link_hash_table_free (_htab);
988 /* Set the right machine number. */
991 elf32_m68k_object_p (bfd *abfd)
993 unsigned int mach = 0;
994 unsigned features = 0;
995 flagword eflags = elf_elfheader (abfd)->e_flags;
997 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
999 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1001 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1005 switch (eflags & EF_M68K_CF_ISA_MASK)
1007 case EF_M68K_CF_ISA_A_NODIV:
1008 features |= mcfisa_a;
1010 case EF_M68K_CF_ISA_A:
1011 features |= mcfisa_a|mcfhwdiv;
1013 case EF_M68K_CF_ISA_A_PLUS:
1014 features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
1016 case EF_M68K_CF_ISA_B_NOUSP:
1017 features |= mcfisa_a|mcfisa_b|mcfhwdiv;
1019 case EF_M68K_CF_ISA_B:
1020 features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
1022 case EF_M68K_CF_ISA_C:
1023 features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
1025 case EF_M68K_CF_ISA_C_NODIV:
1026 features |= mcfisa_a|mcfisa_c|mcfusp;
1029 switch (eflags & EF_M68K_CF_MAC_MASK)
1031 case EF_M68K_CF_MAC:
1034 case EF_M68K_CF_EMAC:
1035 features |= mcfemac;
1038 if (eflags & EF_M68K_CF_FLOAT)
1042 mach = bfd_m68k_features_to_mach (features);
1043 bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
1048 /* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1049 field based on the machine number. */
1052 elf_m68k_final_write_processing (bfd *abfd,
1053 bfd_boolean linker ATTRIBUTE_UNUSED)
1055 int mach = bfd_get_mach (abfd);
1056 unsigned long e_flags = elf_elfheader (abfd)->e_flags;
1060 unsigned int arch_mask;
1062 arch_mask = bfd_m68k_mach_to_features (mach);
1064 if (arch_mask & m68000)
1065 e_flags = EF_M68K_M68000;
1066 else if (arch_mask & cpu32)
1067 e_flags = EF_M68K_CPU32;
1068 else if (arch_mask & fido_a)
1069 e_flags = EF_M68K_FIDO;
1073 & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp))
1076 e_flags |= EF_M68K_CF_ISA_A_NODIV;
1078 case mcfisa_a | mcfhwdiv:
1079 e_flags |= EF_M68K_CF_ISA_A;
1081 case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp:
1082 e_flags |= EF_M68K_CF_ISA_A_PLUS;
1084 case mcfisa_a | mcfisa_b | mcfhwdiv:
1085 e_flags |= EF_M68K_CF_ISA_B_NOUSP;
1087 case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp:
1088 e_flags |= EF_M68K_CF_ISA_B;
1090 case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp:
1091 e_flags |= EF_M68K_CF_ISA_C;
1093 case mcfisa_a | mcfisa_c | mcfusp:
1094 e_flags |= EF_M68K_CF_ISA_C_NODIV;
1097 if (arch_mask & mcfmac)
1098 e_flags |= EF_M68K_CF_MAC;
1099 else if (arch_mask & mcfemac)
1100 e_flags |= EF_M68K_CF_EMAC;
1101 if (arch_mask & cfloat)
1102 e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
1104 elf_elfheader (abfd)->e_flags = e_flags;
1108 /* Keep m68k-specific flags in the ELF header. */
1111 elf32_m68k_set_private_flags (bfd *abfd, flagword flags)
1113 elf_elfheader (abfd)->e_flags = flags;
1114 elf_flags_init (abfd) = TRUE;
1118 /* Merge backend specific data from an object file to the output
1119 object file when linking. */
1121 elf32_m68k_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
1127 const bfd_arch_info_type *arch_info;
1129 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1130 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1133 /* Get the merged machine. This checks for incompatibility between
1134 Coldfire & non-Coldfire flags, incompability between different
1135 Coldfire ISAs, and incompability between different MAC types. */
1136 arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
1140 bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
1142 in_flags = elf_elfheader (ibfd)->e_flags;
1143 if (!elf_flags_init (obfd))
1145 elf_flags_init (obfd) = TRUE;
1146 out_flags = in_flags;
1150 out_flags = elf_elfheader (obfd)->e_flags;
1151 unsigned int variant_mask;
1153 if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1155 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1157 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1160 variant_mask = EF_M68K_CF_ISA_MASK;
1162 in_isa = (in_flags & variant_mask);
1163 out_isa = (out_flags & variant_mask);
1164 if (in_isa > out_isa)
1165 out_flags ^= in_isa ^ out_isa;
1166 if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
1167 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1168 || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
1169 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
1170 out_flags = EF_M68K_FIDO;
1172 out_flags |= in_flags ^ in_isa;
1174 elf_elfheader (obfd)->e_flags = out_flags;
1179 /* Display the flags field. */
1182 elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
1184 FILE *file = (FILE *) ptr;
1185 flagword eflags = elf_elfheader (abfd)->e_flags;
1187 BFD_ASSERT (abfd != NULL && ptr != NULL);
1189 /* Print normal ELF private data. */
1190 _bfd_elf_print_private_bfd_data (abfd, ptr);
1192 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
1194 /* xgettext:c-format */
1195 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
1197 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1198 fprintf (file, " [m68000]");
1199 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1200 fprintf (file, " [cpu32]");
1201 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1202 fprintf (file, " [fido]");
1205 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
1206 fprintf (file, " [cfv4e]");
1208 if (eflags & EF_M68K_CF_ISA_MASK)
1210 char const *isa = _("unknown");
1211 char const *mac = _("unknown");
1212 char const *additional = "";
1214 switch (eflags & EF_M68K_CF_ISA_MASK)
1216 case EF_M68K_CF_ISA_A_NODIV:
1218 additional = " [nodiv]";
1220 case EF_M68K_CF_ISA_A:
1223 case EF_M68K_CF_ISA_A_PLUS:
1226 case EF_M68K_CF_ISA_B_NOUSP:
1228 additional = " [nousp]";
1230 case EF_M68K_CF_ISA_B:
1233 case EF_M68K_CF_ISA_C:
1236 case EF_M68K_CF_ISA_C_NODIV:
1238 additional = " [nodiv]";
1241 fprintf (file, " [isa %s]%s", isa, additional);
1243 if (eflags & EF_M68K_CF_FLOAT)
1244 fprintf (file, " [float]");
1246 switch (eflags & EF_M68K_CF_MAC_MASK)
1251 case EF_M68K_CF_MAC:
1254 case EF_M68K_CF_EMAC:
1257 case EF_M68K_CF_EMAC_B:
1262 fprintf (file, " [%s]", mac);
1271 /* Multi-GOT support implementation design:
1273 Multi-GOT starts in check_relocs hook. There we scan all
1274 relocations of a BFD and build a local GOT (struct elf_m68k_got)
1275 for it. If a single BFD appears to require too many GOT slots with
1276 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1278 After check_relocs has been invoked for each input BFD, we have
1279 constructed a GOT for each input BFD.
1281 To minimize total number of GOTs required for a particular output BFD
1282 (as some environments support only 1 GOT per output object) we try
1283 to merge some of the GOTs to share an offset space. Ideally [and in most
1284 cases] we end up with a single GOT. In cases when there are too many
1285 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1286 several GOTs, assuming the environment can handle them.
1288 Partitioning is done in elf_m68k_partition_multi_got. We start with
1289 an empty GOT and traverse bfd2got hashtable putting got_entries from
1290 local GOTs to the new 'big' one. We do that by constructing an
1291 intermediate GOT holding all the entries the local GOT has and the big
1292 GOT lacks. Then we check if there is room in the big GOT to accomodate
1293 all the entries from diff. On success we add those entries to the big
1294 GOT; on failure we start the new 'big' GOT and retry the adding of
1295 entries from the local GOT. Note that this retry will always succeed as
1296 each local GOT doesn't overflow the limits. After partitioning we
1297 end up with each bfd assigned one of the big GOTs. GOT entries in the
1298 big GOTs are initialized with GOT offsets. Note that big GOTs are
1299 positioned consequently in program space and represent a single huge GOT
1300 to the outside world.
1302 After that we get to elf_m68k_relocate_section. There we
1303 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1304 relocations to refer to appropriate [assigned to current input_bfd]
1309 GOT entry type: We have several types of GOT entries.
1310 * R_8 type is used in entries for symbols that have at least one
1311 R_68K_GOT8O or R_68K_TLS_*8 relocation. We can have at most 0x40
1312 such entries in one GOT.
1313 * R_16 type is used in entries for symbols that have at least one
1314 R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1315 We can have at most 0x4000 such entries in one GOT.
1316 * R_32 type is used in all other cases. We can have as many
1317 such entries in one GOT as we'd like.
1318 When counting relocations we have to include the count of the smaller
1319 ranged relocations in the counts of the larger ranged ones in order
1320 to correctly detect overflow.
1322 Sorting the GOT: In each GOT starting offsets are assigned to
1323 R_8 entries, which are followed by R_16 entries, and
1324 R_32 entries go at the end. See finalize_got_offsets for details.
1326 Negative GOT offsets: To double usable offset range of GOTs we use
1327 negative offsets. As we assign entries with GOT offsets relative to
1328 start of .got section, the offset values are positive. They become
1329 negative only in relocate_section where got->offset value is
1330 subtracted from them.
1332 3 special GOT entries: There are 3 special GOT entries used internally
1333 by loader. These entries happen to be placed to .got.plt section,
1334 so we don't do anything about them in multi-GOT support.
1336 Memory management: All data except for hashtables
1337 multi_got->bfd2got and got->entries are allocated on
1338 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1339 to most functions), so we don't need to care to free them. At the
1340 moment of allocation hashtables are being linked into main data
1341 structure (multi_got), all pieces of which are reachable from
1342 elf_m68k_multi_got (info). We deallocate them in
1343 elf_m68k_link_hash_table_free. */
1345 /* Initialize GOT. */
1348 elf_m68k_init_got (struct elf_m68k_got *got)
1350 got->entries = NULL;
1351 got->n_slots[R_8] = 0;
1352 got->n_slots[R_16] = 0;
1353 got->n_slots[R_32] = 0;
1354 got->local_n_slots = 0;
1355 got->offset = (bfd_vma) -1;
1361 elf_m68k_clear_got (struct elf_m68k_got *got)
1363 if (got->entries != NULL)
1365 htab_delete (got->entries);
1366 got->entries = NULL;
1370 /* Create and empty GOT structure. INFO is the context where memory
1371 should be allocated. */
1373 static struct elf_m68k_got *
1374 elf_m68k_create_empty_got (struct bfd_link_info *info)
1376 struct elf_m68k_got *got;
1378 got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
1382 elf_m68k_init_got (got);
1387 /* Initialize KEY. */
1390 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
1391 struct elf_link_hash_entry *h,
1392 const bfd *abfd, unsigned long symndx,
1393 enum elf_m68k_reloc_type reloc_type)
1395 if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32)
1396 /* All TLS_LDM relocations share a single GOT entry. */
1402 /* Global symbols are identified with their got_entry_key. */
1405 key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
1406 BFD_ASSERT (key->symndx != 0);
1409 /* Local symbols are identified by BFD they appear in and symndx. */
1412 key->symndx = symndx;
1415 key->type = reloc_type;
1418 /* Calculate hash of got_entry.
1422 elf_m68k_got_entry_hash (const void *_entry)
1424 const struct elf_m68k_got_entry_key *key;
1426 key = &((const struct elf_m68k_got_entry *) _entry)->key_;
1429 + (key->bfd != NULL ? (int) key->bfd->id : -1)
1430 + elf_m68k_reloc_got_type (key->type));
1433 /* Check if two got entries are equal. */
1436 elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
1438 const struct elf_m68k_got_entry_key *key1;
1439 const struct elf_m68k_got_entry_key *key2;
1441 key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
1442 key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
1444 return (key1->bfd == key2->bfd
1445 && key1->symndx == key2->symndx
1446 && (elf_m68k_reloc_got_type (key1->type)
1447 == elf_m68k_reloc_got_type (key2->type)));
1450 /* When using negative offsets, we allocate one extra R_8, one extra R_16
1451 and one extra R_32 slots to simplify handling of 2-slot entries during
1452 offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots. */
1454 /* Maximal number of R_8 slots in a single GOT. */
1455 #define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO) \
1456 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1460 /* Maximal number of R_8 and R_16 slots in a single GOT. */
1461 #define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO) \
1462 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1466 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1467 the entry cannot be found.
1468 FIND_OR_CREATE - search for an existing entry, but create new if there's
1470 MUST_FIND - search for an existing entry and assert that it exist.
1471 MUST_CREATE - assert that there's no such entry and create new one. */
1472 enum elf_m68k_get_entry_howto
1480 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1481 INFO is context in which memory should be allocated (can be NULL if
1482 HOWTO is SEARCH or MUST_FIND). */
1484 static struct elf_m68k_got_entry *
1485 elf_m68k_get_got_entry (struct elf_m68k_got *got,
1486 const struct elf_m68k_got_entry_key *key,
1487 enum elf_m68k_get_entry_howto howto,
1488 struct bfd_link_info *info)
1490 struct elf_m68k_got_entry entry_;
1491 struct elf_m68k_got_entry *entry;
1494 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1496 if (got->entries == NULL)
1497 /* This is the first entry in ABFD. Initialize hashtable. */
1499 if (howto == SEARCH)
1502 got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1504 elf_m68k_got_entry_hash,
1505 elf_m68k_got_entry_eq, NULL);
1506 if (got->entries == NULL)
1508 bfd_set_error (bfd_error_no_memory);
1514 ptr = htab_find_slot (got->entries, &entry_, (howto != SEARCH
1515 ? INSERT : NO_INSERT));
1518 if (howto == SEARCH)
1519 /* Entry not found. */
1522 /* We're out of memory. */
1523 bfd_set_error (bfd_error_no_memory);
1528 /* We didn't find the entry and we're asked to create a new one. */
1530 BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1532 entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
1536 /* Initialize new entry. */
1539 entry->u.s1.refcount = 0;
1541 /* Mark the entry as not initialized. */
1542 entry->key_.type = R_68K_max;
1547 /* We found the entry. */
1549 BFD_ASSERT (howto != MUST_CREATE);
1557 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1558 Return the value to which ENTRY's type should be set. */
1560 static enum elf_m68k_reloc_type
1561 elf_m68k_update_got_entry_type (struct elf_m68k_got *got,
1562 enum elf_m68k_reloc_type was,
1563 enum elf_m68k_reloc_type new_reloc)
1565 enum elf_m68k_got_offset_size was_size;
1566 enum elf_m68k_got_offset_size new_size;
1569 if (was == R_68K_max)
1570 /* The type of the entry is not initialized yet. */
1572 /* Update all got->n_slots counters, including n_slots[R_32]. */
1579 /* !!! We, probably, should emit an error rather then fail on assert
1581 BFD_ASSERT (elf_m68k_reloc_got_type (was)
1582 == elf_m68k_reloc_got_type (new_reloc));
1584 was_size = elf_m68k_reloc_got_offset_size (was);
1587 new_size = elf_m68k_reloc_got_offset_size (new_reloc);
1588 n_slots = elf_m68k_reloc_got_n_slots (new_reloc);
1590 while (was_size > new_size)
1593 got->n_slots[was_size] += n_slots;
1596 if (new_reloc > was)
1597 /* Relocations are ordered from bigger got offset size to lesser,
1598 so choose the relocation type with lesser offset size. */
1604 /* Update GOT counters when removing an entry of type TYPE. */
1607 elf_m68k_remove_got_entry_type (struct elf_m68k_got *got,
1608 enum elf_m68k_reloc_type type)
1610 enum elf_m68k_got_offset_size os;
1613 n_slots = elf_m68k_reloc_got_n_slots (type);
1615 /* Decrese counter of slots with offset size corresponding to TYPE
1616 and all greater offset sizes. */
1617 for (os = elf_m68k_reloc_got_offset_size (type); os <= R_32; ++os)
1619 BFD_ASSERT (got->n_slots[os] >= n_slots);
1621 got->n_slots[os] -= n_slots;
1625 /* Add new or update existing entry to GOT.
1626 H, ABFD, TYPE and SYMNDX is data for the entry.
1627 INFO is a context where memory should be allocated. */
1629 static struct elf_m68k_got_entry *
1630 elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
1631 struct elf_link_hash_entry *h,
1633 enum elf_m68k_reloc_type reloc_type,
1634 unsigned long symndx,
1635 struct bfd_link_info *info)
1637 struct elf_m68k_got_entry_key key_;
1638 struct elf_m68k_got_entry *entry;
1640 if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
1641 elf_m68k_hash_entry (h)->got_entry_key
1642 = elf_m68k_multi_got (info)->global_symndx++;
1644 elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type);
1646 entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
1650 /* Determine entry's type and update got->n_slots counters. */
1651 entry->key_.type = elf_m68k_update_got_entry_type (got,
1655 /* Update refcount. */
1656 ++entry->u.s1.refcount;
1658 if (entry->u.s1.refcount == 1)
1659 /* We see this entry for the first time. */
1661 if (entry->key_.bfd != NULL)
1662 got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type);
1665 BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
1667 if ((got->n_slots[R_8]
1668 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1669 || (got->n_slots[R_16]
1670 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1671 /* This BFD has too many relocation. */
1673 if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1674 (*_bfd_error_handler) (_("%B: GOT overflow: "
1675 "Number of relocations with 8-bit "
1678 ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info));
1680 (*_bfd_error_handler) (_("%B: GOT overflow: "
1681 "Number of relocations with 8- or 16-bit "
1684 ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info));
1692 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1695 elf_m68k_bfd2got_entry_hash (const void *entry)
1697 const struct elf_m68k_bfd2got_entry *e;
1699 e = (const struct elf_m68k_bfd2got_entry *) entry;
1704 /* Check whether two hash entries have the same bfd. */
1707 elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
1709 const struct elf_m68k_bfd2got_entry *e1;
1710 const struct elf_m68k_bfd2got_entry *e2;
1712 e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
1713 e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
1715 return e1->bfd == e2->bfd;
1718 /* Destruct a bfd2got entry. */
1721 elf_m68k_bfd2got_entry_del (void *_entry)
1723 struct elf_m68k_bfd2got_entry *entry;
1725 entry = (struct elf_m68k_bfd2got_entry *) _entry;
1727 BFD_ASSERT (entry->got != NULL);
1728 elf_m68k_clear_got (entry->got);
1731 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1732 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1733 memory should be allocated. */
1735 static struct elf_m68k_bfd2got_entry *
1736 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
1738 enum elf_m68k_get_entry_howto howto,
1739 struct bfd_link_info *info)
1741 struct elf_m68k_bfd2got_entry entry_;
1743 struct elf_m68k_bfd2got_entry *entry;
1745 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1747 if (multi_got->bfd2got == NULL)
1748 /* This is the first GOT. Initialize bfd2got. */
1750 if (howto == SEARCH)
1753 multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
1754 elf_m68k_bfd2got_entry_eq,
1755 elf_m68k_bfd2got_entry_del);
1756 if (multi_got->bfd2got == NULL)
1758 bfd_set_error (bfd_error_no_memory);
1764 ptr = htab_find_slot (multi_got->bfd2got, &entry_, (howto != SEARCH
1765 ? INSERT : NO_INSERT));
1768 if (howto == SEARCH)
1769 /* Entry not found. */
1772 /* We're out of memory. */
1773 bfd_set_error (bfd_error_no_memory);
1778 /* Entry was not found. Create new one. */
1780 BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1782 entry = ((struct elf_m68k_bfd2got_entry *)
1783 bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
1789 entry->got = elf_m68k_create_empty_got (info);
1790 if (entry->got == NULL)
1797 BFD_ASSERT (howto != MUST_CREATE);
1799 /* Return existing entry. */
1806 struct elf_m68k_can_merge_gots_arg
1808 /* A current_got that we constructing a DIFF against. */
1809 struct elf_m68k_got *big;
1811 /* GOT holding entries not present or that should be changed in
1813 struct elf_m68k_got *diff;
1815 /* Context where to allocate memory. */
1816 struct bfd_link_info *info;
1819 bfd_boolean error_p;
1822 /* Process a single entry from the small GOT to see if it should be added
1823 or updated in the big GOT. */
1826 elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
1828 const struct elf_m68k_got_entry *entry1;
1829 struct elf_m68k_can_merge_gots_arg *arg;
1830 const struct elf_m68k_got_entry *entry2;
1831 enum elf_m68k_reloc_type type;
1833 entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
1834 arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
1836 entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
1839 /* We found an existing entry. Check if we should update it. */
1841 type = elf_m68k_update_got_entry_type (arg->diff,
1845 if (type == entry2->key_.type)
1846 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1847 To skip creation of difference entry we use the type,
1848 which we won't see in GOT entries for sure. */
1852 /* We didn't find the entry. Add entry1 to DIFF. */
1854 BFD_ASSERT (entry1->key_.type != R_68K_max);
1856 type = elf_m68k_update_got_entry_type (arg->diff,
1857 R_68K_max, entry1->key_.type);
1859 if (entry1->key_.bfd != NULL)
1860 arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type);
1863 if (type != R_68K_max)
1864 /* Create an entry in DIFF. */
1866 struct elf_m68k_got_entry *entry;
1868 entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
1872 arg->error_p = TRUE;
1876 entry->key_.type = type;
1882 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1883 Construct DIFF GOT holding the entries which should be added or updated
1884 in BIG GOT to accumulate information from SMALL.
1885 INFO is the context where memory should be allocated. */
1888 elf_m68k_can_merge_gots (struct elf_m68k_got *big,
1889 const struct elf_m68k_got *small,
1890 struct bfd_link_info *info,
1891 struct elf_m68k_got *diff)
1893 struct elf_m68k_can_merge_gots_arg arg_;
1895 BFD_ASSERT (small->offset == (bfd_vma) -1);
1900 arg_.error_p = FALSE;
1901 htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
1908 /* Check for overflow. */
1909 if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8]
1910 > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1911 || (big->n_slots[R_16] + arg_.diff->n_slots[R_16]
1912 > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1918 struct elf_m68k_merge_gots_arg
1921 struct elf_m68k_got *big;
1923 /* Context where memory should be allocated. */
1924 struct bfd_link_info *info;
1927 bfd_boolean error_p;
1930 /* Process a single entry from DIFF got. Add or update corresponding
1931 entry in the BIG got. */
1934 elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
1936 const struct elf_m68k_got_entry *from;
1937 struct elf_m68k_merge_gots_arg *arg;
1938 struct elf_m68k_got_entry *to;
1940 from = (const struct elf_m68k_got_entry *) *entry_ptr;
1941 arg = (struct elf_m68k_merge_gots_arg *) _arg;
1943 to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
1947 arg->error_p = TRUE;
1951 BFD_ASSERT (to->u.s1.refcount == 0);
1952 /* All we need to merge is TYPE. */
1953 to->key_.type = from->key_.type;
1958 /* Merge data from DIFF to BIG. INFO is context where memory should be
1962 elf_m68k_merge_gots (struct elf_m68k_got *big,
1963 struct elf_m68k_got *diff,
1964 struct bfd_link_info *info)
1966 if (diff->entries != NULL)
1967 /* DIFF is not empty. Merge it into BIG GOT. */
1969 struct elf_m68k_merge_gots_arg arg_;
1971 /* Merge entries. */
1974 arg_.error_p = FALSE;
1975 htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
1979 /* Merge counters. */
1980 big->n_slots[R_8] += diff->n_slots[R_8];
1981 big->n_slots[R_16] += diff->n_slots[R_16];
1982 big->n_slots[R_32] += diff->n_slots[R_32];
1983 big->local_n_slots += diff->local_n_slots;
1986 /* DIFF is empty. */
1988 BFD_ASSERT (diff->n_slots[R_8] == 0);
1989 BFD_ASSERT (diff->n_slots[R_16] == 0);
1990 BFD_ASSERT (diff->n_slots[R_32] == 0);
1991 BFD_ASSERT (diff->local_n_slots == 0);
1994 BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
1995 || ((big->n_slots[R_8]
1996 <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1997 && (big->n_slots[R_16]
1998 <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))));
2003 struct elf_m68k_finalize_got_offsets_arg
2005 /* Ranges of the offsets for GOT entries.
2006 R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2007 R_x is R_8, R_16 and R_32. */
2011 /* Mapping from global symndx to global symbols.
2012 This is used to build lists of got entries for global symbols. */
2013 struct elf_m68k_link_hash_entry **symndx2h;
2015 bfd_vma n_ldm_entries;
2018 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
2022 elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
2024 struct elf_m68k_got_entry *entry;
2025 struct elf_m68k_finalize_got_offsets_arg *arg;
2027 enum elf_m68k_got_offset_size got_offset_size;
2030 entry = (struct elf_m68k_got_entry *) *entry_ptr;
2031 arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
2033 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
2034 BFD_ASSERT (entry->u.s1.refcount == 0);
2036 /* Get GOT offset size for the entry . */
2037 got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type);
2039 /* Calculate entry size in bytes. */
2040 entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type);
2042 /* Check if we should switch to negative range of the offsets. */
2043 if (arg->offset1[got_offset_size] + entry_size
2044 > arg->offset2[got_offset_size])
2046 /* Verify that this is the only switch to negative range for
2047 got_offset_size. If this assertion fails, then we've miscalculated
2048 range for got_offset_size entries in
2049 elf_m68k_finalize_got_offsets. */
2050 BFD_ASSERT (arg->offset2[got_offset_size]
2051 != arg->offset2[-(int) got_offset_size - 1]);
2054 arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1];
2055 arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1];
2057 /* Verify that now we have enough room for the entry. */
2058 BFD_ASSERT (arg->offset1[got_offset_size] + entry_size
2059 <= arg->offset2[got_offset_size]);
2062 /* Assign offset to entry. */
2063 entry->u.s2.offset = arg->offset1[got_offset_size];
2064 arg->offset1[got_offset_size] += entry_size;
2066 if (entry->key_.bfd == NULL)
2067 /* Hook up this entry into the list of got_entries of H. */
2069 struct elf_m68k_link_hash_entry *h;
2071 h = arg->symndx2h[entry->key_.symndx];
2074 entry->u.s2.next = h->glist;
2078 /* This should be the entry for TLS_LDM relocation then. */
2080 BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type)
2082 && entry->key_.symndx == 0);
2084 ++arg->n_ldm_entries;
2088 /* This entry is for local symbol. */
2089 entry->u.s2.next = NULL;
2094 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
2095 should use negative offsets.
2096 Build list of GOT entries for global symbols along the way.
2097 SYMNDX2H is mapping from global symbol indices to actual
2099 Return offset at which next GOT should start. */
2102 elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
2103 bfd_boolean use_neg_got_offsets_p,
2104 struct elf_m68k_link_hash_entry **symndx2h,
2105 bfd_vma *final_offset, bfd_vma *n_ldm_entries)
2107 struct elf_m68k_finalize_got_offsets_arg arg_;
2108 bfd_vma offset1_[2 * R_LAST];
2109 bfd_vma offset2_[2 * R_LAST];
2111 bfd_vma start_offset;
2113 BFD_ASSERT (got->offset != (bfd_vma) -1);
2115 /* We set entry offsets relative to the .got section (and not the
2116 start of a particular GOT), so that we can use them in
2117 finish_dynamic_symbol without needing to know the GOT which they come
2120 /* Put offset1 in the middle of offset1_, same for offset2. */
2121 arg_.offset1 = offset1_ + R_LAST;
2122 arg_.offset2 = offset2_ + R_LAST;
2124 start_offset = got->offset;
2126 if (use_neg_got_offsets_p)
2127 /* Setup both negative and positive ranges for R_8, R_16 and R_32. */
2128 i = -(int) R_32 - 1;
2130 /* Setup positives ranges for R_8, R_16 and R_32. */
2133 for (; i <= (int) R_32; ++i)
2138 /* Set beginning of the range of offsets I. */
2139 arg_.offset1[i] = start_offset;
2141 /* Calculate number of slots that require I offsets. */
2142 j = (i >= 0) ? i : -i - 1;
2143 n = (j >= 1) ? got->n_slots[j - 1] : 0;
2144 n = got->n_slots[j] - n;
2146 if (use_neg_got_offsets_p && n != 0)
2149 /* We first fill the positive side of the range, so we might
2150 end up with one empty slot at that side when we can't fit
2151 whole 2-slot entry. Account for that at negative side of
2152 the interval with one additional entry. */
2155 /* When the number of slots is odd, make positive side of the
2156 range one entry bigger. */
2160 /* N is the number of slots that require I offsets.
2161 Calculate length of the range for I offsets. */
2164 /* Set end of the range. */
2165 arg_.offset2[i] = start_offset + n;
2167 start_offset = arg_.offset2[i];
2170 if (!use_neg_got_offsets_p)
2171 /* Make sure that if we try to switch to negative offsets in
2172 elf_m68k_finalize_got_offsets_1, the assert therein will catch
2174 for (i = R_8; i <= R_32; ++i)
2175 arg_.offset2[-i - 1] = arg_.offset2[i];
2177 /* Setup got->offset. offset1[R_8] is either in the middle or at the
2178 beginning of GOT depending on use_neg_got_offsets_p. */
2179 got->offset = arg_.offset1[R_8];
2181 arg_.symndx2h = symndx2h;
2182 arg_.n_ldm_entries = 0;
2184 /* Assign offsets. */
2185 htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
2187 /* Check offset ranges we have actually assigned. */
2188 for (i = (int) R_8; i <= (int) R_32; ++i)
2189 BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4);
2191 *final_offset = start_offset;
2192 *n_ldm_entries = arg_.n_ldm_entries;
2195 struct elf_m68k_partition_multi_got_arg
2197 /* The GOT we are adding entries to. Aka big got. */
2198 struct elf_m68k_got *current_got;
2200 /* Offset to assign the next CURRENT_GOT. */
2203 /* Context where memory should be allocated. */
2204 struct bfd_link_info *info;
2206 /* Total number of slots in the .got section.
2207 This is used to calculate size of the .got and .rela.got sections. */
2210 /* Difference in numbers of allocated slots in the .got section
2211 and necessary relocations in the .rela.got section.
2212 This is used to calculate size of the .rela.got section. */
2213 bfd_vma slots_relas_diff;
2216 bfd_boolean error_p;
2218 /* Mapping from global symndx to global symbols.
2219 This is used to build lists of got entries for global symbols. */
2220 struct elf_m68k_link_hash_entry **symndx2h;
2224 elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg)
2226 bfd_vma n_ldm_entries;
2228 elf_m68k_finalize_got_offsets (arg->current_got,
2229 (elf_m68k_hash_table (arg->info)
2230 ->use_neg_got_offsets_p),
2232 &arg->offset, &n_ldm_entries);
2234 arg->n_slots += arg->current_got->n_slots[R_32];
2236 if (!arg->info->shared)
2237 /* If we are generating a shared object, we need to
2238 output a R_68K_RELATIVE reloc so that the dynamic
2239 linker can adjust this GOT entry. Overwise we
2240 don't need space in .rela.got for local symbols. */
2241 arg->slots_relas_diff += arg->current_got->local_n_slots;
2243 /* @LDM relocations require a 2-slot GOT entry, but only
2244 one relocation. Account for that. */
2245 arg->slots_relas_diff += n_ldm_entries;
2247 BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots);
2251 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2252 or start a new CURRENT_GOT. */
2255 elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
2257 struct elf_m68k_bfd2got_entry *entry;
2258 struct elf_m68k_partition_multi_got_arg *arg;
2259 struct elf_m68k_got *got;
2260 struct elf_m68k_got diff_;
2261 struct elf_m68k_got *diff;
2263 entry = (struct elf_m68k_bfd2got_entry *) *_entry;
2264 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2267 BFD_ASSERT (got != NULL);
2268 BFD_ASSERT (got->offset == (bfd_vma) -1);
2272 if (arg->current_got != NULL)
2273 /* Construct diff. */
2276 elf_m68k_init_got (diff);
2278 if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
2280 if (diff->offset == 0)
2281 /* Offset set to 0 in the diff_ indicates an error. */
2283 arg->error_p = TRUE;
2287 if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
2289 elf_m68k_clear_got (diff);
2290 /* Schedule to finish up current_got and start new one. */
2294 Merge GOTs no matter what. If big GOT overflows,
2295 we'll fail in relocate_section due to truncated relocations.
2297 ??? May be fail earlier? E.g., in can_merge_gots. */
2301 /* Diff of got against empty current_got is got itself. */
2303 /* Create empty current_got to put subsequent GOTs to. */
2304 arg->current_got = elf_m68k_create_empty_got (arg->info);
2305 if (arg->current_got == NULL)
2307 arg->error_p = TRUE;
2311 arg->current_got->offset = arg->offset;
2318 if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info))
2320 arg->error_p = TRUE;
2324 /* Now we can free GOT. */
2325 elf_m68k_clear_got (got);
2327 entry->got = arg->current_got;
2331 /* Finish up current_got. */
2332 elf_m68k_partition_multi_got_2 (arg);
2334 /* Schedule to start a new current_got. */
2335 arg->current_got = NULL;
2338 if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
2340 BFD_ASSERT (arg->error_p);
2347 elf_m68k_clear_got (diff);
2349 return arg->error_p == FALSE ? 1 : 0;
2352 /* Helper function to build symndx2h mapping. */
2355 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
2358 struct elf_m68k_link_hash_entry *h;
2360 h = elf_m68k_hash_entry (_h);
2362 if (h->got_entry_key != 0)
2363 /* H has at least one entry in the GOT. */
2365 struct elf_m68k_partition_multi_got_arg *arg;
2367 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2369 BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
2370 arg->symndx2h[h->got_entry_key] = h;
2376 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2377 lists of GOT entries for global symbols.
2378 Calculate sizes of .got and .rela.got sections. */
2381 elf_m68k_partition_multi_got (struct bfd_link_info *info)
2383 struct elf_m68k_multi_got *multi_got;
2384 struct elf_m68k_partition_multi_got_arg arg_;
2386 multi_got = elf_m68k_multi_got (info);
2388 arg_.current_got = NULL;
2392 arg_.slots_relas_diff = 0;
2393 arg_.error_p = FALSE;
2395 if (multi_got->bfd2got != NULL)
2397 /* Initialize symndx2h mapping. */
2399 arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
2400 * sizeof (*arg_.symndx2h));
2401 if (arg_.symndx2h == NULL)
2404 elf_link_hash_traverse (elf_hash_table (info),
2405 elf_m68k_init_symndx2h_1, &arg_);
2409 htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
2413 free (arg_.symndx2h);
2414 arg_.symndx2h = NULL;
2419 /* Finish up last current_got. */
2420 elf_m68k_partition_multi_got_2 (&arg_);
2422 free (arg_.symndx2h);
2425 if (elf_hash_table (info)->dynobj != NULL)
2426 /* Set sizes of .got and .rela.got sections. */
2430 s = bfd_get_linker_section (elf_hash_table (info)->dynobj, ".got");
2432 s->size = arg_.offset;
2434 BFD_ASSERT (arg_.offset == 0);
2436 BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots);
2437 arg_.n_slots -= arg_.slots_relas_diff;
2439 s = bfd_get_linker_section (elf_hash_table (info)->dynobj, ".rela.got");
2441 s->size = arg_.n_slots * sizeof (Elf32_External_Rela);
2443 BFD_ASSERT (arg_.n_slots == 0);
2446 BFD_ASSERT (multi_got->bfd2got == NULL);
2451 /* Specialized version of elf_m68k_get_got_entry that returns pointer
2452 to hashtable slot, thus allowing removal of entry via
2453 elf_m68k_remove_got_entry. */
2455 static struct elf_m68k_got_entry **
2456 elf_m68k_find_got_entry_ptr (struct elf_m68k_got *got,
2457 struct elf_m68k_got_entry_key *key)
2460 struct elf_m68k_got_entry entry_;
2461 struct elf_m68k_got_entry **entry_ptr;
2464 ptr = htab_find_slot (got->entries, &entry_, NO_INSERT);
2465 BFD_ASSERT (ptr != NULL);
2467 entry_ptr = (struct elf_m68k_got_entry **) ptr;
2472 /* Remove entry pointed to by ENTRY_PTR from GOT. */
2475 elf_m68k_remove_got_entry (struct elf_m68k_got *got,
2476 struct elf_m68k_got_entry **entry_ptr)
2478 struct elf_m68k_got_entry *entry;
2482 /* Check that offsets have not been finalized yet. */
2483 BFD_ASSERT (got->offset == (bfd_vma) -1);
2484 /* Check that this entry is indeed unused. */
2485 BFD_ASSERT (entry->u.s1.refcount == 0);
2487 elf_m68k_remove_got_entry_type (got, entry->key_.type);
2489 if (entry->key_.bfd != NULL)
2490 got->local_n_slots -= elf_m68k_reloc_got_n_slots (entry->key_.type);
2492 BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
2494 htab_clear_slot (got->entries, (void **) entry_ptr);
2497 /* Copy any information related to dynamic linking from a pre-existing
2498 symbol to a newly created symbol. Also called to copy flags and
2499 other back-end info to a weakdef, in which case the symbol is not
2500 newly created and plt/got refcounts and dynamic indices should not
2504 elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
2505 struct elf_link_hash_entry *_dir,
2506 struct elf_link_hash_entry *_ind)
2508 struct elf_m68k_link_hash_entry *dir;
2509 struct elf_m68k_link_hash_entry *ind;
2511 _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
2513 if (_ind->root.type != bfd_link_hash_indirect)
2516 dir = elf_m68k_hash_entry (_dir);
2517 ind = elf_m68k_hash_entry (_ind);
2519 /* Any absolute non-dynamic relocations against an indirect or weak
2520 definition will be against the target symbol. */
2521 _dir->non_got_ref |= _ind->non_got_ref;
2523 /* We might have a direct symbol already having entries in the GOTs.
2524 Update its key only in case indirect symbol has GOT entries and
2525 assert that both indirect and direct symbols don't have GOT entries
2526 at the same time. */
2527 if (ind->got_entry_key != 0)
2529 BFD_ASSERT (dir->got_entry_key == 0);
2530 /* Assert that GOTs aren't partioned yet. */
2531 BFD_ASSERT (ind->glist == NULL);
2533 dir->got_entry_key = ind->got_entry_key;
2534 ind->got_entry_key = 0;
2538 /* Look through the relocs for a section during the first phase, and
2539 allocate space in the global offset table or procedure linkage
2543 elf_m68k_check_relocs (bfd *abfd,
2544 struct bfd_link_info *info,
2546 const Elf_Internal_Rela *relocs)
2549 Elf_Internal_Shdr *symtab_hdr;
2550 struct elf_link_hash_entry **sym_hashes;
2551 const Elf_Internal_Rela *rel;
2552 const Elf_Internal_Rela *rel_end;
2556 struct elf_m68k_got *got;
2558 if (info->relocatable)
2561 dynobj = elf_hash_table (info)->dynobj;
2562 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2563 sym_hashes = elf_sym_hashes (abfd);
2571 rel_end = relocs + sec->reloc_count;
2572 for (rel = relocs; rel < rel_end; rel++)
2574 unsigned long r_symndx;
2575 struct elf_link_hash_entry *h;
2577 r_symndx = ELF32_R_SYM (rel->r_info);
2579 if (r_symndx < symtab_hdr->sh_info)
2583 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2584 while (h->root.type == bfd_link_hash_indirect
2585 || h->root.type == bfd_link_hash_warning)
2586 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2589 switch (ELF32_R_TYPE (rel->r_info))
2595 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2599 /* Relative GOT relocations. */
2605 /* TLS relocations. */
2607 case R_68K_TLS_GD16:
2608 case R_68K_TLS_GD32:
2609 case R_68K_TLS_LDM8:
2610 case R_68K_TLS_LDM16:
2611 case R_68K_TLS_LDM32:
2613 case R_68K_TLS_IE16:
2614 case R_68K_TLS_IE32:
2616 case R_68K_TLS_TPREL32:
2617 case R_68K_TLS_DTPREL32:
2619 if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
2621 /* Do the special chorus for libraries with static TLS. */
2622 info->flags |= DF_STATIC_TLS;
2624 /* This symbol requires a global offset table entry. */
2628 /* Create the .got section. */
2629 elf_hash_table (info)->dynobj = dynobj = abfd;
2630 if (!_bfd_elf_create_got_section (dynobj, info))
2636 sgot = bfd_get_linker_section (dynobj, ".got");
2637 BFD_ASSERT (sgot != NULL);
2641 && (h != NULL || info->shared))
2643 srelgot = bfd_get_linker_section (dynobj, ".rela.got");
2644 if (srelgot == NULL)
2646 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2647 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2649 srelgot = bfd_make_section_anyway_with_flags (dynobj,
2653 || !bfd_set_section_alignment (dynobj, srelgot, 2))
2660 struct elf_m68k_bfd2got_entry *bfd2got_entry;
2663 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2664 abfd, FIND_OR_CREATE, info);
2665 if (bfd2got_entry == NULL)
2668 got = bfd2got_entry->got;
2669 BFD_ASSERT (got != NULL);
2673 struct elf_m68k_got_entry *got_entry;
2675 /* Add entry to got. */
2676 got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
2677 ELF32_R_TYPE (rel->r_info),
2679 if (got_entry == NULL)
2682 if (got_entry->u.s1.refcount == 1)
2684 /* Make sure this symbol is output as a dynamic symbol. */
2687 && !h->forced_local)
2689 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2700 /* This symbol requires a procedure linkage table entry. We
2701 actually build the entry in adjust_dynamic_symbol,
2702 because this might be a case of linking PIC code which is
2703 never referenced by a dynamic object, in which case we
2704 don't need to generate a procedure linkage table entry
2707 /* If this is a local symbol, we resolve it directly without
2708 creating a procedure linkage table entry. */
2719 /* This symbol requires a procedure linkage table entry. */
2723 /* It does not make sense to have this relocation for a
2724 local symbol. FIXME: does it? How to handle it if
2725 it does make sense? */
2726 bfd_set_error (bfd_error_bad_value);
2730 /* Make sure this symbol is output as a dynamic symbol. */
2731 if (h->dynindx == -1
2732 && !h->forced_local)
2734 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2745 /* If we are creating a shared library and this is not a local
2746 symbol, we need to copy the reloc into the shared library.
2747 However when linking with -Bsymbolic and this is a global
2748 symbol which is defined in an object we are including in the
2749 link (i.e., DEF_REGULAR is set), then we can resolve the
2750 reloc directly. At this point we have not seen all the input
2751 files, so it is possible that DEF_REGULAR is not set now but
2752 will be set later (it is never cleared). We account for that
2753 possibility below by storing information in the
2754 pcrel_relocs_copied field of the hash table entry. */
2756 && (sec->flags & SEC_ALLOC) != 0
2759 || h->root.type == bfd_link_hash_defweak
2760 || !h->def_regular)))
2764 /* Make sure a plt entry is created for this symbol if
2765 it turns out to be a function defined by a dynamic
2775 /* We don't need to handle relocs into sections not going into
2776 the "real" output. */
2777 if ((sec->flags & SEC_ALLOC) == 0)
2782 /* Make sure a plt entry is created for this symbol if it
2783 turns out to be a function defined by a dynamic object. */
2786 if (info->executable)
2787 /* This symbol needs a non-GOT reference. */
2791 /* If we are creating a shared library, we need to copy the
2792 reloc into the shared library. */
2795 /* When creating a shared object, we must copy these
2796 reloc types into the output file. We create a reloc
2797 section in dynobj and make room for this reloc. */
2800 sreloc = _bfd_elf_make_dynamic_reloc_section
2801 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2807 if (sec->flags & SEC_READONLY
2808 /* Don't set DF_TEXTREL yet for PC relative
2809 relocations, they might be discarded later. */
2810 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2811 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2812 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
2813 info->flags |= DF_TEXTREL;
2815 sreloc->size += sizeof (Elf32_External_Rela);
2817 /* We count the number of PC relative relocations we have
2818 entered for this symbol, so that we can discard them
2819 again if, in the -Bsymbolic case, the symbol is later
2820 defined by a regular object, or, in the normal shared
2821 case, the symbol is forced to be local. Note that this
2822 function is only called if we are using an m68kelf linker
2823 hash table, which means that h is really a pointer to an
2824 elf_m68k_link_hash_entry. */
2825 if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2826 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2827 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
2829 struct elf_m68k_pcrel_relocs_copied *p;
2830 struct elf_m68k_pcrel_relocs_copied **head;
2834 struct elf_m68k_link_hash_entry *eh
2835 = elf_m68k_hash_entry (h);
2836 head = &eh->pcrel_relocs_copied;
2842 Elf_Internal_Sym *isym;
2844 isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->sym_cache,
2849 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2853 vpp = &elf_section_data (s)->local_dynrel;
2854 head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
2857 for (p = *head; p != NULL; p = p->next)
2858 if (p->section == sreloc)
2863 p = ((struct elf_m68k_pcrel_relocs_copied *)
2864 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
2869 p->section = sreloc;
2879 /* This relocation describes the C++ object vtable hierarchy.
2880 Reconstruct it for later use during GC. */
2881 case R_68K_GNU_VTINHERIT:
2882 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2886 /* This relocation describes which C++ vtable entries are actually
2887 used. Record for later use during GC. */
2888 case R_68K_GNU_VTENTRY:
2889 BFD_ASSERT (h != NULL);
2891 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2903 /* Return the section that should be marked against GC for a given
2907 elf_m68k_gc_mark_hook (asection *sec,
2908 struct bfd_link_info *info,
2909 Elf_Internal_Rela *rel,
2910 struct elf_link_hash_entry *h,
2911 Elf_Internal_Sym *sym)
2914 switch (ELF32_R_TYPE (rel->r_info))
2916 case R_68K_GNU_VTINHERIT:
2917 case R_68K_GNU_VTENTRY:
2921 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2924 /* Update the got entry reference counts for the section being removed. */
2927 elf_m68k_gc_sweep_hook (bfd *abfd,
2928 struct bfd_link_info *info,
2930 const Elf_Internal_Rela *relocs)
2932 Elf_Internal_Shdr *symtab_hdr;
2933 struct elf_link_hash_entry **sym_hashes;
2934 const Elf_Internal_Rela *rel, *relend;
2936 struct elf_m68k_got *got;
2938 if (info->relocatable)
2941 dynobj = elf_hash_table (info)->dynobj;
2945 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2946 sym_hashes = elf_sym_hashes (abfd);
2949 relend = relocs + sec->reloc_count;
2950 for (rel = relocs; rel < relend; rel++)
2952 unsigned long r_symndx;
2953 struct elf_link_hash_entry *h = NULL;
2955 r_symndx = ELF32_R_SYM (rel->r_info);
2956 if (r_symndx >= symtab_hdr->sh_info)
2958 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2959 while (h->root.type == bfd_link_hash_indirect
2960 || h->root.type == bfd_link_hash_warning)
2961 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2964 switch (ELF32_R_TYPE (rel->r_info))
2970 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2979 /* TLS relocations. */
2981 case R_68K_TLS_GD16:
2982 case R_68K_TLS_GD32:
2983 case R_68K_TLS_LDM8:
2984 case R_68K_TLS_LDM16:
2985 case R_68K_TLS_LDM32:
2987 case R_68K_TLS_IE16:
2988 case R_68K_TLS_IE32:
2990 case R_68K_TLS_TPREL32:
2991 case R_68K_TLS_DTPREL32:
2995 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2996 abfd, MUST_FIND, NULL)->got;
2997 BFD_ASSERT (got != NULL);
3001 struct elf_m68k_got_entry_key key_;
3002 struct elf_m68k_got_entry **got_entry_ptr;
3003 struct elf_m68k_got_entry *got_entry;
3005 elf_m68k_init_got_entry_key (&key_, h, abfd, r_symndx,
3006 ELF32_R_TYPE (rel->r_info));
3007 got_entry_ptr = elf_m68k_find_got_entry_ptr (got, &key_);
3009 got_entry = *got_entry_ptr;
3011 if (got_entry->u.s1.refcount > 0)
3013 --got_entry->u.s1.refcount;
3015 if (got_entry->u.s1.refcount == 0)
3016 /* We don't need the .got entry any more. */
3017 elf_m68k_remove_got_entry (got, got_entry_ptr);
3036 if (h->plt.refcount > 0)
3049 /* Return the type of PLT associated with OUTPUT_BFD. */
3051 static const struct elf_m68k_plt_info *
3052 elf_m68k_get_plt_info (bfd *output_bfd)
3054 unsigned int features;
3056 features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
3057 if (features & cpu32)
3058 return &elf_cpu32_plt_info;
3059 if (features & mcfisa_b)
3060 return &elf_isab_plt_info;
3061 if (features & mcfisa_c)
3062 return &elf_isac_plt_info;
3063 return &elf_m68k_plt_info;
3066 /* This function is called after all the input files have been read,
3067 and the input sections have been assigned to output sections.
3068 It's a convenient place to determine the PLT style. */
3071 elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3073 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
3075 if (!elf_m68k_partition_multi_got (info))
3078 elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
3082 /* Adjust a symbol defined by a dynamic object and referenced by a
3083 regular object. The current definition is in some section of the
3084 dynamic object, but we're not including those sections. We have to
3085 change the definition to something the rest of the link can
3089 elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info,
3090 struct elf_link_hash_entry *h)
3092 struct elf_m68k_link_hash_table *htab;
3096 htab = elf_m68k_hash_table (info);
3097 dynobj = elf_hash_table (info)->dynobj;
3099 /* Make sure we know what is going on here. */
3100 BFD_ASSERT (dynobj != NULL
3102 || h->u.weakdef != NULL
3105 && !h->def_regular)));
3107 /* If this is a function, put it in the procedure linkage table. We
3108 will fill in the contents of the procedure linkage table later,
3109 when we know the address of the .got section. */
3110 if (h->type == STT_FUNC
3113 if ((h->plt.refcount <= 0
3114 || SYMBOL_CALLS_LOCAL (info, h)
3115 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3116 && h->root.type == bfd_link_hash_undefweak))
3117 /* We must always create the plt entry if it was referenced
3118 by a PLTxxO relocation. In this case we already recorded
3119 it as a dynamic symbol. */
3120 && h->dynindx == -1)
3122 /* This case can occur if we saw a PLTxx reloc in an input
3123 file, but the symbol was never referred to by a dynamic
3124 object, or if all references were garbage collected. In
3125 such a case, we don't actually need to build a procedure
3126 linkage table, and we can just do a PCxx reloc instead. */
3127 h->plt.offset = (bfd_vma) -1;
3132 /* Make sure this symbol is output as a dynamic symbol. */
3133 if (h->dynindx == -1
3134 && !h->forced_local)
3136 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3140 s = bfd_get_linker_section (dynobj, ".plt");
3141 BFD_ASSERT (s != NULL);
3143 /* If this is the first .plt entry, make room for the special
3146 s->size = htab->plt_info->size;
3148 /* If this symbol is not defined in a regular file, and we are
3149 not generating a shared library, then set the symbol to this
3150 location in the .plt. This is required to make function
3151 pointers compare as equal between the normal executable and
3152 the shared library. */
3156 h->root.u.def.section = s;
3157 h->root.u.def.value = s->size;
3160 h->plt.offset = s->size;
3162 /* Make room for this entry. */
3163 s->size += htab->plt_info->size;
3165 /* We also need to make an entry in the .got.plt section, which
3166 will be placed in the .got section by the linker script. */
3167 s = bfd_get_linker_section (dynobj, ".got.plt");
3168 BFD_ASSERT (s != NULL);
3171 /* We also need to make an entry in the .rela.plt section. */
3172 s = bfd_get_linker_section (dynobj, ".rela.plt");
3173 BFD_ASSERT (s != NULL);
3174 s->size += sizeof (Elf32_External_Rela);
3179 /* Reinitialize the plt offset now that it is not used as a reference
3181 h->plt.offset = (bfd_vma) -1;
3183 /* If this is a weak symbol, and there is a real definition, the
3184 processor independent code will have arranged for us to see the
3185 real definition first, and we can just use the same value. */
3186 if (h->u.weakdef != NULL)
3188 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3189 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3190 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3191 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3195 /* This is a reference to a symbol defined by a dynamic object which
3196 is not a function. */
3198 /* If we are creating a shared library, we must presume that the
3199 only references to the symbol are via the global offset table.
3200 For such cases we need not do anything here; the relocations will
3201 be handled correctly by relocate_section. */
3205 /* If there are no references to this symbol that do not use the
3206 GOT, we don't need to generate a copy reloc. */
3207 if (!h->non_got_ref)
3210 /* We must allocate the symbol in our .dynbss section, which will
3211 become part of the .bss section of the executable. There will be
3212 an entry for this symbol in the .dynsym section. The dynamic
3213 object will contain position independent code, so all references
3214 from the dynamic object to this symbol will go through the global
3215 offset table. The dynamic linker will use the .dynsym entry to
3216 determine the address it must put in the global offset table, so
3217 both the dynamic object and the regular object will refer to the
3218 same memory location for the variable. */
3220 s = bfd_get_linker_section (dynobj, ".dynbss");
3221 BFD_ASSERT (s != NULL);
3223 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3224 copy the initial value out of the dynamic object and into the
3225 runtime process image. We need to remember the offset into the
3226 .rela.bss section we are going to use. */
3227 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3231 srel = bfd_get_linker_section (dynobj, ".rela.bss");
3232 BFD_ASSERT (srel != NULL);
3233 srel->size += sizeof (Elf32_External_Rela);
3237 return _bfd_elf_adjust_dynamic_copy (h, s);
3240 /* Set the sizes of the dynamic sections. */
3243 elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3244 struct bfd_link_info *info)
3251 dynobj = elf_hash_table (info)->dynobj;
3252 BFD_ASSERT (dynobj != NULL);
3254 if (elf_hash_table (info)->dynamic_sections_created)
3256 /* Set the contents of the .interp section to the interpreter. */
3257 if (info->executable)
3259 s = bfd_get_linker_section (dynobj, ".interp");
3260 BFD_ASSERT (s != NULL);
3261 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3262 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3267 /* We may have created entries in the .rela.got section.
3268 However, if we are not creating the dynamic sections, we will
3269 not actually use these entries. Reset the size of .rela.got,
3270 which will cause it to get stripped from the output file
3272 s = bfd_get_linker_section (dynobj, ".rela.got");
3277 /* If this is a -Bsymbolic shared link, then we need to discard all
3278 PC relative relocs against symbols defined in a regular object.
3279 For the normal shared case we discard the PC relative relocs
3280 against symbols that have become local due to visibility changes.
3281 We allocated space for them in the check_relocs routine, but we
3282 will not fill them in in the relocate_section routine. */
3284 elf_link_hash_traverse (elf_hash_table (info),
3285 elf_m68k_discard_copies,
3288 /* The check_relocs and adjust_dynamic_symbol entry points have
3289 determined the sizes of the various dynamic sections. Allocate
3293 for (s = dynobj->sections; s != NULL; s = s->next)
3297 if ((s->flags & SEC_LINKER_CREATED) == 0)
3300 /* It's OK to base decisions on the section name, because none
3301 of the dynobj section names depend upon the input files. */
3302 name = bfd_get_section_name (dynobj, s);
3304 if (strcmp (name, ".plt") == 0)
3306 /* Remember whether there is a PLT. */
3309 else if (CONST_STRNEQ (name, ".rela"))
3315 /* We use the reloc_count field as a counter if we need
3316 to copy relocs into the output file. */
3320 else if (! CONST_STRNEQ (name, ".got")
3321 && strcmp (name, ".dynbss") != 0)
3323 /* It's not one of our sections, so don't allocate space. */
3329 /* If we don't need this section, strip it from the
3330 output file. This is mostly to handle .rela.bss and
3331 .rela.plt. We must create both sections in
3332 create_dynamic_sections, because they must be created
3333 before the linker maps input sections to output
3334 sections. The linker does that before
3335 adjust_dynamic_symbol is called, and it is that
3336 function which decides whether anything needs to go
3337 into these sections. */
3338 s->flags |= SEC_EXCLUDE;
3342 if ((s->flags & SEC_HAS_CONTENTS) == 0)
3345 /* Allocate memory for the section contents. */
3346 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3347 Unused entries should be reclaimed before the section's contents
3348 are written out, but at the moment this does not happen. Thus in
3349 order to prevent writing out garbage, we initialise the section's
3350 contents to zero. */
3351 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3352 if (s->contents == NULL)
3356 if (elf_hash_table (info)->dynamic_sections_created)
3358 /* Add some entries to the .dynamic section. We fill in the
3359 values later, in elf_m68k_finish_dynamic_sections, but we
3360 must add the entries now so that we get the correct size for
3361 the .dynamic section. The DT_DEBUG entry is filled in by the
3362 dynamic linker and used by the debugger. */
3363 #define add_dynamic_entry(TAG, VAL) \
3364 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3368 if (!add_dynamic_entry (DT_DEBUG, 0))
3374 if (!add_dynamic_entry (DT_PLTGOT, 0)
3375 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3376 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3377 || !add_dynamic_entry (DT_JMPREL, 0))
3383 if (!add_dynamic_entry (DT_RELA, 0)
3384 || !add_dynamic_entry (DT_RELASZ, 0)
3385 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3389 if ((info->flags & DF_TEXTREL) != 0)
3391 if (!add_dynamic_entry (DT_TEXTREL, 0))
3395 #undef add_dynamic_entry
3400 /* This function is called via elf_link_hash_traverse if we are
3401 creating a shared object. In the -Bsymbolic case it discards the
3402 space allocated to copy PC relative relocs against symbols which
3403 are defined in regular objects. For the normal shared case, it
3404 discards space for pc-relative relocs that have become local due to
3405 symbol visibility changes. We allocated space for them in the
3406 check_relocs routine, but we won't fill them in in the
3407 relocate_section routine.
3409 We also check whether any of the remaining relocations apply
3410 against a readonly section, and set the DF_TEXTREL flag in this
3414 elf_m68k_discard_copies (struct elf_link_hash_entry *h,
3417 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3418 struct elf_m68k_pcrel_relocs_copied *s;
3420 if (!SYMBOL_CALLS_LOCAL (info, h))
3422 if ((info->flags & DF_TEXTREL) == 0)
3424 /* Look for relocations against read-only sections. */
3425 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3428 if ((s->section->flags & SEC_READONLY) != 0)
3430 info->flags |= DF_TEXTREL;
3435 /* Make sure undefined weak symbols are output as a dynamic symbol
3438 && h->root.type == bfd_link_hash_undefweak
3439 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3441 && !h->forced_local)
3443 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3450 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3453 s->section->size -= s->count * sizeof (Elf32_External_Rela);
3459 /* Install relocation RELA. */
3462 elf_m68k_install_rela (bfd *output_bfd,
3464 Elf_Internal_Rela *rela)
3468 loc = srela->contents;
3469 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
3470 bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
3473 /* Find the base offsets for thread-local storage in this object,
3474 for GD/LD and IE/LE respectively. */
3476 #define DTP_OFFSET 0x8000
3477 #define TP_OFFSET 0x7000
3480 dtpoff_base (struct bfd_link_info *info)
3482 /* If tls_sec is NULL, we should have signalled an error already. */
3483 if (elf_hash_table (info)->tls_sec == NULL)
3485 return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET;
3489 tpoff_base (struct bfd_link_info *info)
3491 /* If tls_sec is NULL, we should have signalled an error already. */
3492 if (elf_hash_table (info)->tls_sec == NULL)
3494 return elf_hash_table (info)->tls_sec->vma + TP_OFFSET;
3497 /* Output necessary relocation to handle a symbol during static link.
3498 This function is called from elf_m68k_relocate_section. */
3501 elf_m68k_init_got_entry_static (struct bfd_link_info *info,
3503 enum elf_m68k_reloc_type r_type,
3505 bfd_vma got_entry_offset,
3508 switch (elf_m68k_reloc_got_type (r_type))
3511 bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset);
3514 case R_68K_TLS_GD32:
3515 /* We know the offset within the module,
3516 put it into the second GOT slot. */
3517 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3518 sgot->contents + got_entry_offset + 4);
3521 case R_68K_TLS_LDM32:
3522 /* Mark it as belonging to module 1, the executable. */
3523 bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset);
3526 case R_68K_TLS_IE32:
3527 bfd_put_32 (output_bfd, relocation - tpoff_base (info),
3528 sgot->contents + got_entry_offset);
3536 /* Output necessary relocation to handle a local symbol
3537 during dynamic link.
3538 This function is called either from elf_m68k_relocate_section
3539 or from elf_m68k_finish_dynamic_symbol. */
3542 elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info,
3544 enum elf_m68k_reloc_type r_type,
3546 bfd_vma got_entry_offset,
3550 Elf_Internal_Rela outrel;
3552 switch (elf_m68k_reloc_got_type (r_type))
3555 /* Emit RELATIVE relocation to initialize GOT slot
3557 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3558 outrel.r_addend = relocation;
3561 case R_68K_TLS_GD32:
3562 /* We know the offset within the module,
3563 put it into the second GOT slot. */
3564 bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3565 sgot->contents + got_entry_offset + 4);
3568 case R_68K_TLS_LDM32:
3569 /* We don't know the module number,
3570 create a relocation for it. */
3571 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
3572 outrel.r_addend = 0;
3575 case R_68K_TLS_IE32:
3576 /* Emit TPREL relocation to initialize GOT slot
3578 outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
3579 outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma;
3586 /* Offset of the GOT entry. */
3587 outrel.r_offset = (sgot->output_section->vma
3588 + sgot->output_offset
3589 + got_entry_offset);
3591 /* Install one of the above relocations. */
3592 elf_m68k_install_rela (output_bfd, srela, &outrel);
3594 bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset);
3597 /* Relocate an M68K ELF section. */
3600 elf_m68k_relocate_section (bfd *output_bfd,
3601 struct bfd_link_info *info,
3603 asection *input_section,
3605 Elf_Internal_Rela *relocs,
3606 Elf_Internal_Sym *local_syms,
3607 asection **local_sections)
3610 Elf_Internal_Shdr *symtab_hdr;
3611 struct elf_link_hash_entry **sym_hashes;
3616 struct elf_m68k_got *got;
3617 Elf_Internal_Rela *rel;
3618 Elf_Internal_Rela *relend;
3620 dynobj = elf_hash_table (info)->dynobj;
3621 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3622 sym_hashes = elf_sym_hashes (input_bfd);
3632 relend = relocs + input_section->reloc_count;
3633 for (; rel < relend; rel++)
3636 reloc_howto_type *howto;
3637 unsigned long r_symndx;
3638 struct elf_link_hash_entry *h;
3639 Elf_Internal_Sym *sym;
3642 bfd_boolean unresolved_reloc;
3643 bfd_reloc_status_type r;
3645 r_type = ELF32_R_TYPE (rel->r_info);
3646 if (r_type < 0 || r_type >= (int) R_68K_max)
3648 bfd_set_error (bfd_error_bad_value);
3651 howto = howto_table + r_type;
3653 r_symndx = ELF32_R_SYM (rel->r_info);
3658 unresolved_reloc = FALSE;
3660 if (r_symndx < symtab_hdr->sh_info)
3662 sym = local_syms + r_symndx;
3663 sec = local_sections[r_symndx];
3664 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3670 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3671 r_symndx, symtab_hdr, sym_hashes,
3673 unresolved_reloc, warned);
3676 if (sec != NULL && discarded_section (sec))
3677 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3678 rel, 1, relend, howto, 0, contents);
3680 if (info->relocatable)
3688 /* Relocation is to the address of the entry for this symbol
3689 in the global offset table. */
3691 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3693 if (elf_m68k_hash_table (info)->local_gp_p)
3695 bfd_vma sgot_output_offset;
3700 sgot = bfd_get_linker_section (dynobj, ".got");
3703 sgot_output_offset = sgot->output_offset;
3705 /* In this case we have a reference to
3706 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3708 ??? Issue a warning? */
3709 sgot_output_offset = 0;
3712 sgot_output_offset = sgot->output_offset;
3716 struct elf_m68k_bfd2got_entry *bfd2got_entry;
3719 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3720 input_bfd, SEARCH, NULL);
3722 if (bfd2got_entry != NULL)
3724 got = bfd2got_entry->got;
3725 BFD_ASSERT (got != NULL);
3727 got_offset = got->offset;
3730 /* In this case we have a reference to
3731 _GLOBAL_OFFSET_TABLE_, but no other references
3732 accessing any GOT entries.
3733 ??? Issue a warning? */
3737 got_offset = got->offset;
3739 /* Adjust GOT pointer to point to the GOT
3740 assigned to input_bfd. */
3741 rel->r_addend += sgot_output_offset + got_offset;
3744 BFD_ASSERT (got == NULL || got->offset == 0);
3753 case R_68K_TLS_LDM32:
3754 case R_68K_TLS_LDM16:
3755 case R_68K_TLS_LDM8:
3758 case R_68K_TLS_GD16:
3759 case R_68K_TLS_GD32:
3762 case R_68K_TLS_IE16:
3763 case R_68K_TLS_IE32:
3765 /* Relocation is the offset of the entry for this symbol in
3766 the global offset table. */
3769 struct elf_m68k_got_entry_key key_;
3775 sgot = bfd_get_linker_section (dynobj, ".got");
3776 BFD_ASSERT (sgot != NULL);
3781 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3782 input_bfd, MUST_FIND,
3784 BFD_ASSERT (got != NULL);
3787 /* Get GOT offset for this symbol. */
3788 elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx,
3790 off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
3794 /* The offset must always be a multiple of 4. We use
3795 the least significant bit to record whether we have
3796 already generated the necessary reloc. */
3802 /* @TLSLDM relocations are bounded to the module, in
3803 which the symbol is defined -- not to the symbol
3805 && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32)
3809 dyn = elf_hash_table (info)->dynamic_sections_created;
3810 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3812 && SYMBOL_REFERENCES_LOCAL (info, h))
3813 || (ELF_ST_VISIBILITY (h->other)
3814 && h->root.type == bfd_link_hash_undefweak))
3816 /* This is actually a static link, or it is a
3817 -Bsymbolic link and the symbol is defined
3818 locally, or the symbol was forced to be local
3819 because of a version file. We must initialize
3820 this entry in the global offset table. Since
3821 the offset must always be a multiple of 4, we
3822 use the least significant bit to record whether
3823 we have initialized it already.
3825 When doing a dynamic link, we create a .rela.got
3826 relocation entry to initialize the value. This
3827 is done in the finish_dynamic_symbol routine. */
3829 elf_m68k_init_got_entry_static (info,
3839 unresolved_reloc = FALSE;
3841 else if (info->shared) /* && h == NULL */
3842 /* Process local symbol during dynamic link. */
3846 srela = bfd_get_linker_section (dynobj, ".rela.got");
3847 BFD_ASSERT (srela != NULL);
3850 elf_m68k_init_got_entry_local_shared (info,
3860 else /* h == NULL && !info->shared */
3862 elf_m68k_init_got_entry_static (info,
3873 /* We don't use elf_m68k_reloc_got_type in the condition below
3874 because this is the only place where difference between
3875 R_68K_GOTx and R_68K_GOTxO relocations matters. */
3876 if (r_type == R_68K_GOT32O
3877 || r_type == R_68K_GOT16O
3878 || r_type == R_68K_GOT8O
3879 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32
3880 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32
3881 || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32)
3883 /* GOT pointer is adjusted to point to the start/middle
3884 of local GOT. Adjust the offset accordingly. */
3885 BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
3886 || off >= got->offset);
3888 if (elf_m68k_hash_table (info)->local_gp_p)
3889 relocation = off - got->offset;
3892 BFD_ASSERT (got->offset == 0);
3893 relocation = sgot->output_offset + off;
3896 /* This relocation does not use the addend. */
3900 relocation = (sgot->output_section->vma + sgot->output_offset
3905 case R_68K_TLS_LDO32:
3906 case R_68K_TLS_LDO16:
3907 case R_68K_TLS_LDO8:
3908 relocation -= dtpoff_base (info);
3911 case R_68K_TLS_LE32:
3912 case R_68K_TLS_LE16:
3914 if (info->shared && !info->pie)
3916 (*_bfd_error_handler)
3917 (_("%B(%A+0x%lx): R_68K_TLS_LE32 relocation not permitted "
3918 "in shared object"),
3919 input_bfd, input_section, (long) rel->r_offset, howto->name);
3924 relocation -= tpoff_base (info);
3931 /* Relocation is to the entry for this symbol in the
3932 procedure linkage table. */
3934 /* Resolve a PLTxx reloc against a local symbol directly,
3935 without using the procedure linkage table. */
3939 if (h->plt.offset == (bfd_vma) -1
3940 || !elf_hash_table (info)->dynamic_sections_created)
3942 /* We didn't make a PLT entry for this symbol. This
3943 happens when statically linking PIC code, or when
3944 using -Bsymbolic. */
3950 splt = bfd_get_linker_section (dynobj, ".plt");
3951 BFD_ASSERT (splt != NULL);
3954 relocation = (splt->output_section->vma
3955 + splt->output_offset
3957 unresolved_reloc = FALSE;
3963 /* Relocation is the offset of the entry for this symbol in
3964 the procedure linkage table. */
3965 BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
3969 splt = bfd_get_linker_section (dynobj, ".plt");
3970 BFD_ASSERT (splt != NULL);
3973 relocation = h->plt.offset;
3974 unresolved_reloc = FALSE;
3976 /* This relocation does not use the addend. */
3988 && r_symndx != STN_UNDEF
3989 && (input_section->flags & SEC_ALLOC) != 0
3991 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3992 || h->root.type != bfd_link_hash_undefweak)
3993 && ((r_type != R_68K_PC8
3994 && r_type != R_68K_PC16
3995 && r_type != R_68K_PC32)
3996 || !SYMBOL_CALLS_LOCAL (info, h)))
3998 Elf_Internal_Rela outrel;
4000 bfd_boolean skip, relocate;
4002 /* When generating a shared object, these relocations
4003 are copied into the output file to be resolved at run
4010 _bfd_elf_section_offset (output_bfd, info, input_section,
4012 if (outrel.r_offset == (bfd_vma) -1)
4014 else if (outrel.r_offset == (bfd_vma) -2)
4015 skip = TRUE, relocate = TRUE;
4016 outrel.r_offset += (input_section->output_section->vma
4017 + input_section->output_offset);
4020 memset (&outrel, 0, sizeof outrel);
4023 && (r_type == R_68K_PC8
4024 || r_type == R_68K_PC16
4025 || r_type == R_68K_PC32
4028 || !h->def_regular))
4030 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4031 outrel.r_addend = rel->r_addend;
4035 /* This symbol is local, or marked to become local. */
4036 outrel.r_addend = relocation + rel->r_addend;
4038 if (r_type == R_68K_32)
4041 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
4047 if (bfd_is_abs_section (sec))
4049 else if (sec == NULL || sec->owner == NULL)
4051 bfd_set_error (bfd_error_bad_value);
4058 /* We are turning this relocation into one
4059 against a section symbol. It would be
4060 proper to subtract the symbol's value,
4061 osec->vma, from the emitted reloc addend,
4062 but ld.so expects buggy relocs. */
4063 osec = sec->output_section;
4064 indx = elf_section_data (osec)->dynindx;
4067 struct elf_link_hash_table *htab;
4068 htab = elf_hash_table (info);
4069 osec = htab->text_index_section;
4070 indx = elf_section_data (osec)->dynindx;
4072 BFD_ASSERT (indx != 0);
4075 outrel.r_info = ELF32_R_INFO (indx, r_type);
4079 sreloc = elf_section_data (input_section)->sreloc;
4083 loc = sreloc->contents;
4084 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4085 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4087 /* This reloc will be computed at runtime, so there's no
4088 need to do anything now, except for R_68K_32
4089 relocations that have been turned into
4097 case R_68K_GNU_VTINHERIT:
4098 case R_68K_GNU_VTENTRY:
4099 /* These are no-ops in the end. */
4106 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4107 because such sections are not SEC_ALLOC and thus ld.so will
4108 not process them. */
4109 if (unresolved_reloc
4110 && !((input_section->flags & SEC_DEBUGGING) != 0
4112 && _bfd_elf_section_offset (output_bfd, info, input_section,
4113 rel->r_offset) != (bfd_vma) -1)
4115 (*_bfd_error_handler)
4116 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4119 (long) rel->r_offset,
4121 h->root.root.string);
4125 if (r_symndx != STN_UNDEF
4126 && r_type != R_68K_NONE
4128 || h->root.type == bfd_link_hash_defined
4129 || h->root.type == bfd_link_hash_defweak))
4133 sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type;
4135 if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS))
4140 name = h->root.root.string;
4143 name = (bfd_elf_string_from_elf_section
4144 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4145 if (name == NULL || *name == '\0')
4146 name = bfd_section_name (input_bfd, sec);
4149 (*_bfd_error_handler)
4150 ((sym_type == STT_TLS
4151 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4152 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4155 (long) rel->r_offset,
4161 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4162 contents, rel->r_offset,
4163 relocation, rel->r_addend);
4165 if (r != bfd_reloc_ok)
4170 name = h->root.root.string;
4173 name = bfd_elf_string_from_elf_section (input_bfd,
4174 symtab_hdr->sh_link,
4179 name = bfd_section_name (input_bfd, sec);
4182 if (r == bfd_reloc_overflow)
4184 if (!(info->callbacks->reloc_overflow
4185 (info, (h ? &h->root : NULL), name, howto->name,
4186 (bfd_vma) 0, input_bfd, input_section,
4192 (*_bfd_error_handler)
4193 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
4194 input_bfd, input_section,
4195 (long) rel->r_offset, name, (int) r);
4204 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4205 into section SEC. */
4208 elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
4210 /* Make VALUE PC-relative. */
4211 value -= sec->output_section->vma + offset;
4213 /* Apply any in-place addend. */
4214 value += bfd_get_32 (sec->owner, sec->contents + offset);
4216 bfd_put_32 (sec->owner, value, sec->contents + offset);
4219 /* Finish up dynamic symbol handling. We set the contents of various
4220 dynamic sections here. */
4223 elf_m68k_finish_dynamic_symbol (bfd *output_bfd,
4224 struct bfd_link_info *info,
4225 struct elf_link_hash_entry *h,
4226 Elf_Internal_Sym *sym)
4230 dynobj = elf_hash_table (info)->dynobj;
4232 if (h->plt.offset != (bfd_vma) -1)
4234 const struct elf_m68k_plt_info *plt_info;
4240 Elf_Internal_Rela rela;
4243 /* This symbol has an entry in the procedure linkage table. Set
4246 BFD_ASSERT (h->dynindx != -1);
4248 plt_info = elf_m68k_hash_table (info)->plt_info;
4249 splt = bfd_get_linker_section (dynobj, ".plt");
4250 sgot = bfd_get_linker_section (dynobj, ".got.plt");
4251 srela = bfd_get_linker_section (dynobj, ".rela.plt");
4252 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
4254 /* Get the index in the procedure linkage table which
4255 corresponds to this symbol. This is the index of this symbol
4256 in all the symbols for which we are making plt entries. The
4257 first entry in the procedure linkage table is reserved. */
4258 plt_index = (h->plt.offset / plt_info->size) - 1;
4260 /* Get the offset into the .got table of the entry that
4261 corresponds to this function. Each .got entry is 4 bytes.
4262 The first three are reserved. */
4263 got_offset = (plt_index + 3) * 4;
4265 memcpy (splt->contents + h->plt.offset,
4266 plt_info->symbol_entry,
4269 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
4270 (sgot->output_section->vma
4271 + sgot->output_offset
4274 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4277 + plt_info->symbol_resolve_entry + 2);
4279 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
4280 splt->output_section->vma);
4282 /* Fill in the entry in the global offset table. */
4283 bfd_put_32 (output_bfd,
4284 (splt->output_section->vma
4285 + splt->output_offset
4287 + plt_info->symbol_resolve_entry),
4288 sgot->contents + got_offset);
4290 /* Fill in the entry in the .rela.plt section. */
4291 rela.r_offset = (sgot->output_section->vma
4292 + sgot->output_offset
4294 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
4296 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
4297 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4299 if (!h->def_regular)
4301 /* Mark the symbol as undefined, rather than as defined in
4302 the .plt section. Leave the value alone. */
4303 sym->st_shndx = SHN_UNDEF;
4307 if (elf_m68k_hash_entry (h)->glist != NULL)
4311 struct elf_m68k_got_entry *got_entry;
4313 /* This symbol has an entry in the global offset table. Set it
4316 sgot = bfd_get_linker_section (dynobj, ".got");
4317 srela = bfd_get_linker_section (dynobj, ".rela.got");
4318 BFD_ASSERT (sgot != NULL && srela != NULL);
4320 got_entry = elf_m68k_hash_entry (h)->glist;
4322 while (got_entry != NULL)
4324 enum elf_m68k_reloc_type r_type;
4325 bfd_vma got_entry_offset;
4327 r_type = got_entry->key_.type;
4328 got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1;
4330 /* If this is a -Bsymbolic link, and the symbol is defined
4331 locally, we just want to emit a RELATIVE reloc. Likewise if
4332 the symbol was forced to be local because of a version file.
4333 The entry in the global offset table already have been
4334 initialized in the relocate_section function. */
4336 && SYMBOL_REFERENCES_LOCAL (info, h))
4340 relocation = bfd_get_signed_32 (output_bfd,
4342 + got_entry_offset));
4345 switch (elf_m68k_reloc_got_type (r_type))
4348 case R_68K_TLS_LDM32:
4351 case R_68K_TLS_GD32:
4352 /* The value for this relocation is actually put in
4353 the second GOT slot. */
4354 relocation = bfd_get_signed_32 (output_bfd,
4356 + got_entry_offset + 4));
4357 relocation += dtpoff_base (info);
4360 case R_68K_TLS_IE32:
4361 relocation += tpoff_base (info);
4368 elf_m68k_init_got_entry_local_shared (info,
4378 Elf_Internal_Rela rela;
4380 /* Put zeros to GOT slots that will be initialized
4385 n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type);
4387 bfd_put_32 (output_bfd, (bfd_vma) 0,
4388 (sgot->contents + got_entry_offset
4393 rela.r_offset = (sgot->output_section->vma
4394 + sgot->output_offset
4395 + got_entry_offset);
4397 switch (elf_m68k_reloc_got_type (r_type))
4400 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
4401 elf_m68k_install_rela (output_bfd, srela, &rela);
4404 case R_68K_TLS_GD32:
4405 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32);
4406 elf_m68k_install_rela (output_bfd, srela, &rela);
4409 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32);
4410 elf_m68k_install_rela (output_bfd, srela, &rela);
4413 case R_68K_TLS_IE32:
4414 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32);
4415 elf_m68k_install_rela (output_bfd, srela, &rela);
4424 got_entry = got_entry->u.s2.next;
4431 Elf_Internal_Rela rela;
4434 /* This symbol needs a copy reloc. Set it up. */
4436 BFD_ASSERT (h->dynindx != -1
4437 && (h->root.type == bfd_link_hash_defined
4438 || h->root.type == bfd_link_hash_defweak));
4440 s = bfd_get_linker_section (dynobj, ".rela.bss");
4441 BFD_ASSERT (s != NULL);
4443 rela.r_offset = (h->root.u.def.value
4444 + h->root.u.def.section->output_section->vma
4445 + h->root.u.def.section->output_offset);
4446 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
4448 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4449 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4455 /* Finish up the dynamic sections. */
4458 elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4464 dynobj = elf_hash_table (info)->dynobj;
4466 sgot = bfd_get_linker_section (dynobj, ".got.plt");
4467 BFD_ASSERT (sgot != NULL);
4468 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4470 if (elf_hash_table (info)->dynamic_sections_created)
4473 Elf32_External_Dyn *dyncon, *dynconend;
4475 splt = bfd_get_linker_section (dynobj, ".plt");
4476 BFD_ASSERT (splt != NULL && sdyn != NULL);
4478 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4479 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4480 for (; dyncon < dynconend; dyncon++)
4482 Elf_Internal_Dyn dyn;
4486 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4499 s = bfd_get_section_by_name (output_bfd, name);
4500 BFD_ASSERT (s != NULL);
4501 dyn.d_un.d_ptr = s->vma;
4502 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4506 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4507 BFD_ASSERT (s != NULL);
4508 dyn.d_un.d_val = s->size;
4509 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4513 /* The procedure linkage table relocs (DT_JMPREL) should
4514 not be included in the overall relocs (DT_RELA).
4515 Therefore, we override the DT_RELASZ entry here to
4516 make it not include the JMPREL relocs. Since the
4517 linker script arranges for .rela.plt to follow all
4518 other relocation sections, we don't have to worry
4519 about changing the DT_RELA entry. */
4520 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4522 dyn.d_un.d_val -= s->size;
4523 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4528 /* Fill in the first entry in the procedure linkage table. */
4531 const struct elf_m68k_plt_info *plt_info;
4533 plt_info = elf_m68k_hash_table (info)->plt_info;
4534 memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
4536 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
4537 (sgot->output_section->vma
4538 + sgot->output_offset
4541 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
4542 (sgot->output_section->vma
4543 + sgot->output_offset
4546 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4551 /* Fill in the first three entries in the global offset table. */
4555 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4557 bfd_put_32 (output_bfd,
4558 sdyn->output_section->vma + sdyn->output_offset,
4560 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4561 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4564 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4569 /* Given a .data section and a .emreloc in-memory section, store
4570 relocation information into the .emreloc section which can be
4571 used at runtime to relocate the section. This is called by the
4572 linker when the --embedded-relocs switch is used. This is called
4573 after the add_symbols entry point has been called for all the
4574 objects, and before the final_link entry point is called. */
4577 bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
4579 struct bfd_link_info *info;
4584 Elf_Internal_Shdr *symtab_hdr;
4585 Elf_Internal_Sym *isymbuf = NULL;
4586 Elf_Internal_Rela *internal_relocs = NULL;
4587 Elf_Internal_Rela *irel, *irelend;
4591 BFD_ASSERT (! info->relocatable);
4595 if (datasec->reloc_count == 0)
4598 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4600 /* Get a copy of the native relocations. */
4601 internal_relocs = (_bfd_elf_link_read_relocs
4602 (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL,
4603 info->keep_memory));
4604 if (internal_relocs == NULL)
4607 amt = (bfd_size_type) datasec->reloc_count * 12;
4608 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
4609 if (relsec->contents == NULL)
4612 p = relsec->contents;
4614 irelend = internal_relocs + datasec->reloc_count;
4615 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
4617 asection *targetsec;
4619 /* We are going to write a four byte longword into the runtime
4620 reloc section. The longword will be the address in the data
4621 section which must be relocated. It is followed by the name
4622 of the target section NUL-padded or truncated to 8
4625 /* We can only relocate absolute longword relocs at run time. */
4626 if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
4628 *errmsg = _("unsupported reloc type");
4629 bfd_set_error (bfd_error_bad_value);
4633 /* Get the target section referred to by the reloc. */
4634 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4636 /* A local symbol. */
4637 Elf_Internal_Sym *isym;
4639 /* Read this BFD's local symbols if we haven't done so already. */
4640 if (isymbuf == NULL)
4642 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4643 if (isymbuf == NULL)
4644 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4645 symtab_hdr->sh_info, 0,
4647 if (isymbuf == NULL)
4651 isym = isymbuf + ELF32_R_SYM (irel->r_info);
4652 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4657 struct elf_link_hash_entry *h;
4659 /* An external symbol. */
4660 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4661 h = elf_sym_hashes (abfd)[indx];
4662 BFD_ASSERT (h != NULL);
4663 if (h->root.type == bfd_link_hash_defined
4664 || h->root.type == bfd_link_hash_defweak)
4665 targetsec = h->root.u.def.section;
4670 bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
4671 memset (p + 4, 0, 8);
4672 if (targetsec != NULL)
4673 strncpy ((char *) p + 4, targetsec->output_section->name, 8);
4676 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4678 if (internal_relocs != NULL
4679 && elf_section_data (datasec)->relocs != internal_relocs)
4680 free (internal_relocs);
4684 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
4686 if (internal_relocs != NULL
4687 && elf_section_data (datasec)->relocs != internal_relocs)
4688 free (internal_relocs);
4692 /* Set target options. */
4695 bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
4697 struct elf_m68k_link_hash_table *htab;
4698 bfd_boolean use_neg_got_offsets_p;
4699 bfd_boolean allow_multigot_p;
4700 bfd_boolean local_gp_p;
4702 switch (got_handling)
4707 use_neg_got_offsets_p = FALSE;
4708 allow_multigot_p = FALSE;
4712 /* --got=negative. */
4714 use_neg_got_offsets_p = TRUE;
4715 allow_multigot_p = FALSE;
4719 /* --got=multigot. */
4721 use_neg_got_offsets_p = TRUE;
4722 allow_multigot_p = TRUE;
4730 htab = elf_m68k_hash_table (info);
4733 htab->local_gp_p = local_gp_p;
4734 htab->use_neg_got_offsets_p = use_neg_got_offsets_p;
4735 htab->allow_multigot_p = allow_multigot_p;
4739 static enum elf_reloc_type_class
4740 elf32_m68k_reloc_type_class (const Elf_Internal_Rela *rela)
4742 switch ((int) ELF32_R_TYPE (rela->r_info))
4744 case R_68K_RELATIVE:
4745 return reloc_class_relative;
4746 case R_68K_JMP_SLOT:
4747 return reloc_class_plt;
4749 return reloc_class_copy;
4751 return reloc_class_normal;
4755 /* Return address for Ith PLT stub in section PLT, for relocation REL
4756 or (bfd_vma) -1 if it should not be included. */
4759 elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
4760 const arelent *rel ATTRIBUTE_UNUSED)
4762 return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
4765 /* Support for core dump NOTE sections. */
4768 elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4773 switch (note->descsz)
4778 case 154: /* Linux/m68k */
4780 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
4783 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 22);
4792 /* Make a ".reg/999" section. */
4793 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
4794 size, note->descpos + offset);
4798 elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4800 switch (note->descsz)
4805 case 124: /* Linux/m68k elf_prpsinfo. */
4806 elf_tdata (abfd)->core_pid
4807 = bfd_get_32 (abfd, note->descdata + 12);
4808 elf_tdata (abfd)->core_program
4809 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
4810 elf_tdata (abfd)->core_command
4811 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
4814 /* Note that for some reason, a spurious space is tacked
4815 onto the end of the args in some (at least one anyway)
4816 implementations, so strip it off if it exists. */
4818 char *command = elf_tdata (abfd)->core_command;
4819 int n = strlen (command);
4821 if (n > 0 && command[n - 1] == ' ')
4822 command[n - 1] = '\0';
4828 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
4829 #define TARGET_BIG_NAME "elf32-m68k"
4830 #define ELF_MACHINE_CODE EM_68K
4831 #define ELF_MAXPAGESIZE 0x2000
4832 #define elf_backend_create_dynamic_sections \
4833 _bfd_elf_create_dynamic_sections
4834 #define bfd_elf32_bfd_link_hash_table_create \
4835 elf_m68k_link_hash_table_create
4836 /* ??? Should it be this macro or bfd_elfNN_bfd_link_hash_table_create? */
4837 #define bfd_elf32_bfd_link_hash_table_free \
4838 elf_m68k_link_hash_table_free
4839 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4841 #define elf_backend_check_relocs elf_m68k_check_relocs
4842 #define elf_backend_always_size_sections \
4843 elf_m68k_always_size_sections
4844 #define elf_backend_adjust_dynamic_symbol \
4845 elf_m68k_adjust_dynamic_symbol
4846 #define elf_backend_size_dynamic_sections \
4847 elf_m68k_size_dynamic_sections
4848 #define elf_backend_final_write_processing elf_m68k_final_write_processing
4849 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4850 #define elf_backend_relocate_section elf_m68k_relocate_section
4851 #define elf_backend_finish_dynamic_symbol \
4852 elf_m68k_finish_dynamic_symbol
4853 #define elf_backend_finish_dynamic_sections \
4854 elf_m68k_finish_dynamic_sections
4855 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4856 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
4857 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4858 #define bfd_elf32_bfd_merge_private_bfd_data \
4859 elf32_m68k_merge_private_bfd_data
4860 #define bfd_elf32_bfd_set_private_flags \
4861 elf32_m68k_set_private_flags
4862 #define bfd_elf32_bfd_print_private_bfd_data \
4863 elf32_m68k_print_private_bfd_data
4864 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4865 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4866 #define elf_backend_object_p elf32_m68k_object_p
4867 #define elf_backend_grok_prstatus elf_m68k_grok_prstatus
4868 #define elf_backend_grok_psinfo elf_m68k_grok_psinfo
4870 #define elf_backend_can_gc_sections 1
4871 #define elf_backend_can_refcount 1
4872 #define elf_backend_want_got_plt 1
4873 #define elf_backend_plt_readonly 1
4874 #define elf_backend_want_plt_sym 0
4875 #define elf_backend_got_header_size 12
4876 #define elf_backend_rela_normal 1
4878 #include "elf32-target.h"