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 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
27 #include "opcode/m68k.h"
29 static reloc_howto_type *reloc_type_lookup
30 PARAMS ((bfd *, bfd_reloc_code_real_type));
31 static void rtype_to_howto
32 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
33 static struct bfd_hash_entry *elf_m68k_link_hash_newfunc
34 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
35 static struct bfd_link_hash_table *elf_m68k_link_hash_table_create
37 static bfd_boolean elf_m68k_check_relocs
38 PARAMS ((bfd *, struct bfd_link_info *, asection *,
39 const Elf_Internal_Rela *));
40 static bfd_boolean elf_m68k_adjust_dynamic_symbol
41 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
42 static bfd_boolean elf_m68k_size_dynamic_sections
43 PARAMS ((bfd *, struct bfd_link_info *));
44 static bfd_boolean elf_m68k_discard_copies
45 PARAMS ((struct elf_link_hash_entry *, PTR));
46 static bfd_boolean elf_m68k_relocate_section
47 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
48 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
49 static bfd_boolean elf_m68k_finish_dynamic_symbol
50 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
52 static bfd_boolean elf_m68k_finish_dynamic_sections
53 PARAMS ((bfd *, struct bfd_link_info *));
55 static bfd_boolean elf32_m68k_set_private_flags
56 PARAMS ((bfd *, flagword));
57 static bfd_boolean elf32_m68k_merge_private_bfd_data
58 PARAMS ((bfd *, bfd *));
59 static bfd_boolean elf32_m68k_print_private_bfd_data
60 PARAMS ((bfd *, PTR));
61 static enum elf_reloc_type_class elf32_m68k_reloc_type_class
62 PARAMS ((const Elf_Internal_Rela *));
64 static reloc_howto_type howto_table[] = {
65 HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE),
66 HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE),
67 HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE),
68 HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE),
69 HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE),
70 HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE),
71 HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE),
72 HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE),
73 HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE),
74 HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE),
75 HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE),
76 HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE),
77 HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE),
78 HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE),
79 HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE),
80 HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE),
81 HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE),
82 HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE),
83 HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE),
84 HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE),
85 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),
86 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),
87 HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE),
88 /* GNU extension to record C++ vtable hierarchy. */
89 HOWTO (R_68K_GNU_VTINHERIT, /* type */
91 2, /* size (0 = byte, 1 = short, 2 = long) */
93 FALSE, /* pc_relative */
95 complain_overflow_dont, /* complain_on_overflow */
96 NULL, /* special_function */
97 "R_68K_GNU_VTINHERIT", /* name */
98 FALSE, /* partial_inplace */
102 /* GNU extension to record C++ vtable member usage. */
103 HOWTO (R_68K_GNU_VTENTRY, /* type */
105 2, /* size (0 = byte, 1 = short, 2 = long) */
107 FALSE, /* pc_relative */
109 complain_overflow_dont, /* complain_on_overflow */
110 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
111 "R_68K_GNU_VTENTRY", /* name */
112 FALSE, /* partial_inplace */
119 rtype_to_howto (abfd, cache_ptr, dst)
120 bfd *abfd ATTRIBUTE_UNUSED;
122 Elf_Internal_Rela *dst;
124 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K_max);
125 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
128 #define elf_info_to_howto rtype_to_howto
132 bfd_reloc_code_real_type bfd_val;
135 { BFD_RELOC_NONE, R_68K_NONE },
136 { BFD_RELOC_32, R_68K_32 },
137 { BFD_RELOC_16, R_68K_16 },
138 { BFD_RELOC_8, R_68K_8 },
139 { BFD_RELOC_32_PCREL, R_68K_PC32 },
140 { BFD_RELOC_16_PCREL, R_68K_PC16 },
141 { BFD_RELOC_8_PCREL, R_68K_PC8 },
142 { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
143 { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
144 { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
145 { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
146 { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
147 { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
148 { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
149 { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
150 { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
151 { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
152 { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
153 { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
154 { BFD_RELOC_NONE, R_68K_COPY },
155 { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
156 { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
157 { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
158 { BFD_RELOC_CTOR, R_68K_32 },
159 { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
160 { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
163 static reloc_howto_type *
164 reloc_type_lookup (abfd, code)
165 bfd *abfd ATTRIBUTE_UNUSED;
166 bfd_reloc_code_real_type code;
169 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
171 if (reloc_map[i].bfd_val == code)
172 return &howto_table[reloc_map[i].elf_val];
177 static reloc_howto_type *
178 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
182 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
183 if (howto_table[i].name != NULL
184 && strcasecmp (howto_table[i].name, r_name) == 0)
185 return &howto_table[i];
190 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
191 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
192 #define ELF_ARCH bfd_arch_m68k
194 /* Functions for the m68k ELF linker. */
196 /* The name of the dynamic interpreter. This is put in the .interp
199 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
201 /* Describes one of the various PLT styles. */
203 struct elf_m68k_plt_info
205 /* The size of each PLT entry. */
208 /* The template for the first PLT entry. */
209 const bfd_byte *plt0_entry;
211 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
212 The comments by each member indicate the value that the relocation
215 unsigned int got4; /* .got + 4 */
216 unsigned int got8; /* .got + 8 */
219 /* The template for a symbol's PLT entry. */
220 const bfd_byte *symbol_entry;
222 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
223 The comments by each member indicate the value that the relocation
226 unsigned int got; /* the symbol's .got.plt entry */
227 unsigned int plt; /* .plt */
230 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
231 The stub starts with "move.l #relocoffset,%d0". */
232 bfd_vma symbol_resolve_entry;
235 /* The size in bytes of an entry in the procedure linkage table. */
237 #define PLT_ENTRY_SIZE 20
239 /* The first entry in a procedure linkage table looks like this. See
240 the SVR4 ABI m68k supplement to see how this works. */
242 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
244 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
245 0, 0, 0, 2, /* + (.got + 4) - . */
246 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
247 0, 0, 0, 2, /* + (.got + 8) - . */
248 0, 0, 0, 0 /* pad out to 20 bytes. */
251 /* Subsequent entries in a procedure linkage table look like this. */
253 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
255 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
256 0, 0, 0, 2, /* + (.got.plt entry) - . */
257 0x2f, 0x3c, /* move.l #offset,-(%sp) */
258 0, 0, 0, 0, /* + reloc index */
259 0x60, 0xff, /* bra.l .plt */
260 0, 0, 0, 0 /* + .plt - . */
263 static const struct elf_m68k_plt_info elf_m68k_plt_info = {
265 elf_m68k_plt0_entry, { 4, 12 },
266 elf_m68k_plt_entry, { 4, 16 }, 8
269 #define ISAB_PLT_ENTRY_SIZE 24
271 static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
273 0x20, 0x3c, /* move.l #offset,%d0 */
274 0, 0, 0, 0, /* + (.got + 4) - . */
275 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
276 0x20, 0x3c, /* move.l #offset,%d0 */
277 0, 0, 0, 0, /* + (.got + 8) - . */
278 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
279 0x4e, 0xd0, /* jmp (%a0) */
283 /* Subsequent entries in a procedure linkage table look like this. */
285 static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
287 0x20, 0x3c, /* move.l #offset,%d0 */
288 0, 0, 0, 0, /* + (.got.plt entry) - . */
289 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
290 0x4e, 0xd0, /* jmp (%a0) */
291 0x2f, 0x3c, /* move.l #offset,-(%sp) */
292 0, 0, 0, 0, /* + reloc index */
293 0x60, 0xff, /* bra.l .plt */
294 0, 0, 0, 0 /* + .plt - . */
297 static const struct elf_m68k_plt_info elf_isab_plt_info = {
299 elf_isab_plt0_entry, { 2, 12 },
300 elf_isab_plt_entry, { 2, 20 }, 12
303 #define ISAC_PLT_ENTRY_SIZE 24
305 static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
307 0x20, 0x3c, /* move.l #offset,%d0 */
308 0, 0, 0, 0, /* replaced with .got + 4 - . */
309 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
310 0x20, 0x3c, /* move.l #offset,%d0 */
311 0, 0, 0, 0, /* replaced with .got + 8 - . */
312 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
313 0x4e, 0xd0, /* jmp (%a0) */
317 /* Subsequent entries in a procedure linkage table look like this. */
319 static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
321 0x20, 0x3c, /* move.l #offset,%d0 */
322 0, 0, 0, 0, /* replaced with (.got entry) - . */
323 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
324 0x4e, 0xd0, /* jmp (%a0) */
325 0x2f, 0x3c, /* move.l #offset,-(%sp) */
326 0, 0, 0, 0, /* replaced with offset into relocation table */
327 0x61, 0xff, /* bsr.l .plt */
328 0, 0, 0, 0 /* replaced with .plt - . */
331 static const struct elf_m68k_plt_info elf_isac_plt_info = {
333 elf_isac_plt0_entry, { 2, 12},
334 elf_isac_plt_entry, { 2, 20 }, 12
337 #define CPU32_PLT_ENTRY_SIZE 24
338 /* Procedure linkage table entries for the cpu32 */
339 static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
341 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
342 0, 0, 0, 2, /* + (.got + 4) - . */
343 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
344 0, 0, 0, 2, /* + (.got + 8) - . */
345 0x4e, 0xd1, /* jmp %a1@ */
346 0, 0, 0, 0, /* pad out to 24 bytes. */
350 static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
352 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
353 0, 0, 0, 2, /* + (.got.plt entry) - . */
354 0x4e, 0xd1, /* jmp %a1@ */
355 0x2f, 0x3c, /* move.l #offset,-(%sp) */
356 0, 0, 0, 0, /* + reloc index */
357 0x60, 0xff, /* bra.l .plt */
358 0, 0, 0, 0, /* + .plt - . */
362 static const struct elf_m68k_plt_info elf_cpu32_plt_info = {
363 CPU32_PLT_ENTRY_SIZE,
364 elf_cpu32_plt0_entry, { 4, 12 },
365 elf_cpu32_plt_entry, { 4, 18 }, 10
368 /* The m68k linker needs to keep track of the number of relocs that it
369 decides to copy in check_relocs for each symbol. This is so that it
370 can discard PC relative relocs if it doesn't need them when linking
371 with -Bsymbolic. We store the information in a field extending the
372 regular ELF linker hash table. */
374 /* This structure keeps track of the number of PC relative relocs we have
375 copied for a given symbol. */
377 struct elf_m68k_pcrel_relocs_copied
380 struct elf_m68k_pcrel_relocs_copied *next;
381 /* A section in dynobj. */
383 /* Number of relocs copied in this section. */
387 /* m68k ELF linker hash entry. */
389 struct elf_m68k_link_hash_entry
391 struct elf_link_hash_entry root;
393 /* Number of PC relative relocs copied for this symbol. */
394 struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
397 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
399 /* m68k ELF linker hash table. */
401 struct elf_m68k_link_hash_table
403 struct elf_link_hash_table root;
405 /* Small local sym to section mapping cache. */
406 struct sym_sec_cache sym_sec;
408 /* The PLT format used by this link, or NULL if the format has not
410 const struct elf_m68k_plt_info *plt_info;
413 /* Get the m68k ELF linker hash table from a link_info structure. */
415 #define elf_m68k_hash_table(p) \
416 ((struct elf_m68k_link_hash_table *) (p)->hash)
418 /* Create an entry in an m68k ELF linker hash table. */
420 static struct bfd_hash_entry *
421 elf_m68k_link_hash_newfunc (entry, table, string)
422 struct bfd_hash_entry *entry;
423 struct bfd_hash_table *table;
426 struct bfd_hash_entry *ret = entry;
428 /* Allocate the structure if it has not already been allocated by a
431 ret = bfd_hash_allocate (table,
432 sizeof (struct elf_m68k_link_hash_entry));
436 /* Call the allocation method of the superclass. */
437 ret = _bfd_elf_link_hash_newfunc (ret, table, string);
439 elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
444 /* Create an m68k ELF linker hash table. */
446 static struct bfd_link_hash_table *
447 elf_m68k_link_hash_table_create (abfd)
450 struct elf_m68k_link_hash_table *ret;
451 bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table);
453 ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt);
454 if (ret == (struct elf_m68k_link_hash_table *) NULL)
457 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
458 elf_m68k_link_hash_newfunc,
459 sizeof (struct elf_m68k_link_hash_entry)))
465 ret->sym_sec.abfd = NULL;
466 ret->plt_info = NULL;
468 return &ret->root.root;
471 /* Set the right machine number. */
474 elf32_m68k_object_p (bfd *abfd)
476 unsigned int mach = 0;
477 unsigned features = 0;
478 flagword eflags = elf_elfheader (abfd)->e_flags;
480 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
482 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
484 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
488 switch (eflags & EF_M68K_CF_ISA_MASK)
490 case EF_M68K_CF_ISA_A_NODIV:
491 features |= mcfisa_a;
493 case EF_M68K_CF_ISA_A:
494 features |= mcfisa_a|mcfhwdiv;
496 case EF_M68K_CF_ISA_A_PLUS:
497 features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
499 case EF_M68K_CF_ISA_B_NOUSP:
500 features |= mcfisa_a|mcfisa_b|mcfhwdiv;
502 case EF_M68K_CF_ISA_B:
503 features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
505 case EF_M68K_CF_ISA_C:
506 features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
509 switch (eflags & EF_M68K_CF_MAC_MASK)
514 case EF_M68K_CF_EMAC:
518 if (eflags & EF_M68K_CF_FLOAT)
522 mach = bfd_m68k_features_to_mach (features);
523 bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
528 /* Keep m68k-specific flags in the ELF header. */
530 elf32_m68k_set_private_flags (abfd, flags)
534 elf_elfheader (abfd)->e_flags = flags;
535 elf_flags_init (abfd) = TRUE;
539 /* Merge backend specific data from an object file to the output
540 object file when linking. */
542 elf32_m68k_merge_private_bfd_data (ibfd, obfd)
550 const bfd_arch_info_type *arch_info;
552 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
553 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
556 /* Get the merged machine. This checks for incompatibility between
557 Coldfire & non-Coldfire flags, incompability between different
558 Coldfire ISAs, and incompability between different MAC types. */
559 arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
563 bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
565 in_flags = elf_elfheader (ibfd)->e_flags;
566 if (!elf_flags_init (obfd))
568 elf_flags_init (obfd) = TRUE;
569 out_flags = in_flags;
573 out_flags = elf_elfheader (obfd)->e_flags;
574 unsigned int variant_mask;
576 if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
578 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
580 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
583 variant_mask = EF_M68K_CF_ISA_MASK;
585 in_isa = (in_flags & variant_mask);
586 out_isa = (out_flags & variant_mask);
587 if (in_isa > out_isa)
588 out_flags ^= in_isa ^ out_isa;
589 if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
590 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
591 || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
592 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
593 out_flags = EF_M68K_FIDO;
595 out_flags |= in_flags ^ in_isa;
597 elf_elfheader (obfd)->e_flags = out_flags;
602 /* Display the flags field. */
604 elf32_m68k_print_private_bfd_data (abfd, ptr)
608 FILE *file = (FILE *) ptr;
609 flagword eflags = elf_elfheader (abfd)->e_flags;
611 BFD_ASSERT (abfd != NULL && ptr != NULL);
613 /* Print normal ELF private data. */
614 _bfd_elf_print_private_bfd_data (abfd, ptr);
616 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
618 /* xgettext:c-format */
619 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
621 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
622 fprintf (file, " [m68000]");
623 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
624 fprintf (file, " [cpu32]");
625 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
626 fprintf (file, " [fido]");
629 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
630 fprintf (file, " [cfv4e]");
632 if (eflags & EF_M68K_CF_ISA_MASK)
634 char const *isa = _("unknown");
635 char const *mac = _("unknown");
636 char const *additional = "";
638 switch (eflags & EF_M68K_CF_ISA_MASK)
640 case EF_M68K_CF_ISA_A_NODIV:
642 additional = " [nodiv]";
644 case EF_M68K_CF_ISA_A:
647 case EF_M68K_CF_ISA_A_PLUS:
650 case EF_M68K_CF_ISA_B_NOUSP:
652 additional = " [nousp]";
654 case EF_M68K_CF_ISA_B:
657 case EF_M68K_CF_ISA_C:
661 fprintf (file, " [isa %s]%s", isa, additional);
662 if (eflags & EF_M68K_CF_FLOAT)
663 fprintf (file, " [float]");
664 switch (eflags & EF_M68K_CF_MAC_MASK)
672 case EF_M68K_CF_EMAC:
677 fprintf (file, " [%s]", mac);
685 /* Look through the relocs for a section during the first phase, and
686 allocate space in the global offset table or procedure linkage
690 elf_m68k_check_relocs (abfd, info, sec, relocs)
692 struct bfd_link_info *info;
694 const Elf_Internal_Rela *relocs;
697 Elf_Internal_Shdr *symtab_hdr;
698 struct elf_link_hash_entry **sym_hashes;
699 bfd_signed_vma *local_got_refcounts;
700 const Elf_Internal_Rela *rel;
701 const Elf_Internal_Rela *rel_end;
706 if (info->relocatable)
709 dynobj = elf_hash_table (info)->dynobj;
710 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
711 sym_hashes = elf_sym_hashes (abfd);
712 local_got_refcounts = elf_local_got_refcounts (abfd);
718 rel_end = relocs + sec->reloc_count;
719 for (rel = relocs; rel < rel_end; rel++)
721 unsigned long r_symndx;
722 struct elf_link_hash_entry *h;
724 r_symndx = ELF32_R_SYM (rel->r_info);
726 if (r_symndx < symtab_hdr->sh_info)
730 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
731 while (h->root.type == bfd_link_hash_indirect
732 || h->root.type == bfd_link_hash_warning)
733 h = (struct elf_link_hash_entry *) h->root.u.i.link;
736 switch (ELF32_R_TYPE (rel->r_info))
742 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
748 /* This symbol requires a global offset table entry. */
752 /* Create the .got section. */
753 elf_hash_table (info)->dynobj = dynobj = abfd;
754 if (!_bfd_elf_create_got_section (dynobj, info))
760 sgot = bfd_get_section_by_name (dynobj, ".got");
761 BFD_ASSERT (sgot != NULL);
765 && (h != NULL || info->shared))
767 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
770 srelgot = bfd_make_section_with_flags (dynobj,
779 || !bfd_set_section_alignment (dynobj, srelgot, 2))
786 if (h->got.refcount == 0)
788 /* Make sure this symbol is output as a dynamic symbol. */
792 if (!bfd_elf_link_record_dynamic_symbol (info, h))
796 /* Allocate space in the .got section. */
798 /* Allocate relocation space. */
799 srelgot->size += sizeof (Elf32_External_Rela);
805 /* This is a global offset table entry for a local symbol. */
806 if (local_got_refcounts == NULL)
810 size = symtab_hdr->sh_info;
811 size *= sizeof (bfd_signed_vma);
812 local_got_refcounts = ((bfd_signed_vma *)
813 bfd_zalloc (abfd, size));
814 if (local_got_refcounts == NULL)
816 elf_local_got_refcounts (abfd) = local_got_refcounts;
818 if (local_got_refcounts[r_symndx] == 0)
823 /* If we are generating a shared object, we need to
824 output a R_68K_RELATIVE reloc so that the dynamic
825 linker can adjust this GOT entry. */
826 srelgot->size += sizeof (Elf32_External_Rela);
829 local_got_refcounts[r_symndx]++;
836 /* This symbol requires a procedure linkage table entry. We
837 actually build the entry in adjust_dynamic_symbol,
838 because this might be a case of linking PIC code which is
839 never referenced by a dynamic object, in which case we
840 don't need to generate a procedure linkage table entry
843 /* If this is a local symbol, we resolve it directly without
844 creating a procedure linkage table entry. */
855 /* This symbol requires a procedure linkage table entry. */
859 /* It does not make sense to have this relocation for a
860 local symbol. FIXME: does it? How to handle it if
861 it does make sense? */
862 bfd_set_error (bfd_error_bad_value);
866 /* Make sure this symbol is output as a dynamic symbol. */
870 if (!bfd_elf_link_record_dynamic_symbol (info, h))
881 /* If we are creating a shared library and this is not a local
882 symbol, we need to copy the reloc into the shared library.
883 However when linking with -Bsymbolic and this is a global
884 symbol which is defined in an object we are including in the
885 link (i.e., DEF_REGULAR is set), then we can resolve the
886 reloc directly. At this point we have not seen all the input
887 files, so it is possible that DEF_REGULAR is not set now but
888 will be set later (it is never cleared). We account for that
889 possibility below by storing information in the
890 pcrel_relocs_copied field of the hash table entry. */
892 && (sec->flags & SEC_ALLOC) != 0
895 || h->root.type == bfd_link_hash_defweak
896 || !h->def_regular)))
900 /* Make sure a plt entry is created for this symbol if
901 it turns out to be a function defined by a dynamic
913 /* Make sure a plt entry is created for this symbol if it
914 turns out to be a function defined by a dynamic object. */
918 /* If we are creating a shared library, we need to copy the
919 reloc into the shared library. */
921 && (sec->flags & SEC_ALLOC) != 0)
923 /* When creating a shared object, we must copy these
924 reloc types into the output file. We create a reloc
925 section in dynobj and make room for this reloc. */
930 name = (bfd_elf_string_from_elf_section
932 elf_elfheader (abfd)->e_shstrndx,
933 elf_section_data (sec)->rel_hdr.sh_name));
937 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
938 && strcmp (bfd_get_section_name (abfd, sec),
941 sreloc = bfd_get_section_by_name (dynobj, name);
944 sreloc = bfd_make_section_with_flags (dynobj,
953 || !bfd_set_section_alignment (dynobj, sreloc, 2))
956 elf_section_data (sec)->sreloc = sreloc;
959 if (sec->flags & SEC_READONLY
960 /* Don't set DF_TEXTREL yet for PC relative
961 relocations, they might be discarded later. */
962 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
963 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
964 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
965 info->flags |= DF_TEXTREL;
967 sreloc->size += sizeof (Elf32_External_Rela);
969 /* We count the number of PC relative relocations we have
970 entered for this symbol, so that we can discard them
971 again if, in the -Bsymbolic case, the symbol is later
972 defined by a regular object, or, in the normal shared
973 case, the symbol is forced to be local. Note that this
974 function is only called if we are using an m68kelf linker
975 hash table, which means that h is really a pointer to an
976 elf_m68k_link_hash_entry. */
977 if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
978 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
979 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
981 struct elf_m68k_pcrel_relocs_copied *p;
982 struct elf_m68k_pcrel_relocs_copied **head;
986 struct elf_m68k_link_hash_entry *eh
987 = elf_m68k_hash_entry (h);
988 head = &eh->pcrel_relocs_copied;
995 s = (bfd_section_from_r_symndx
996 (abfd, &elf_m68k_hash_table (info)->sym_sec,
1001 vpp = &elf_section_data (s)->local_dynrel;
1002 head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
1005 for (p = *head; p != NULL; p = p->next)
1006 if (p->section == sreloc)
1011 p = ((struct elf_m68k_pcrel_relocs_copied *)
1012 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
1017 p->section = sreloc;
1027 /* This relocation describes the C++ object vtable hierarchy.
1028 Reconstruct it for later use during GC. */
1029 case R_68K_GNU_VTINHERIT:
1030 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1034 /* This relocation describes which C++ vtable entries are actually
1035 used. Record for later use during GC. */
1036 case R_68K_GNU_VTENTRY:
1037 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1049 /* Return the section that should be marked against GC for a given
1053 elf_m68k_gc_mark_hook (asection *sec,
1054 struct bfd_link_info *info,
1055 Elf_Internal_Rela *rel,
1056 struct elf_link_hash_entry *h,
1057 Elf_Internal_Sym *sym)
1060 switch (ELF32_R_TYPE (rel->r_info))
1062 case R_68K_GNU_VTINHERIT:
1063 case R_68K_GNU_VTENTRY:
1067 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1070 /* Update the got entry reference counts for the section being removed. */
1073 elf_m68k_gc_sweep_hook (bfd *abfd,
1074 struct bfd_link_info *info,
1076 const Elf_Internal_Rela *relocs)
1078 Elf_Internal_Shdr *symtab_hdr;
1079 struct elf_link_hash_entry **sym_hashes;
1080 bfd_signed_vma *local_got_refcounts;
1081 const Elf_Internal_Rela *rel, *relend;
1086 dynobj = elf_hash_table (info)->dynobj;
1090 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1091 sym_hashes = elf_sym_hashes (abfd);
1092 local_got_refcounts = elf_local_got_refcounts (abfd);
1094 sgot = bfd_get_section_by_name (dynobj, ".got");
1095 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1097 relend = relocs + sec->reloc_count;
1098 for (rel = relocs; rel < relend; rel++)
1100 unsigned long r_symndx;
1101 struct elf_link_hash_entry *h = NULL;
1103 r_symndx = ELF32_R_SYM (rel->r_info);
1104 if (r_symndx >= symtab_hdr->sh_info)
1106 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1107 while (h->root.type == bfd_link_hash_indirect
1108 || h->root.type == bfd_link_hash_warning)
1109 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1112 switch (ELF32_R_TYPE (rel->r_info))
1122 if (h->got.refcount > 0)
1125 if (h->got.refcount == 0)
1127 /* We don't need the .got entry any more. */
1129 srelgot->size -= sizeof (Elf32_External_Rela);
1133 else if (local_got_refcounts != NULL)
1135 if (local_got_refcounts[r_symndx] > 0)
1137 --local_got_refcounts[r_symndx];
1138 if (local_got_refcounts[r_symndx] == 0)
1140 /* We don't need the .got entry any more. */
1143 srelgot->size -= sizeof (Elf32_External_Rela);
1163 if (h->plt.refcount > 0)
1176 /* Return the type of PLT associated with OUTPUT_BFD. */
1178 static const struct elf_m68k_plt_info *
1179 elf_m68k_get_plt_info (bfd *output_bfd)
1181 unsigned int features;
1183 features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
1184 if (features & cpu32)
1185 return &elf_cpu32_plt_info;
1186 if (features & mcfisa_b)
1187 return &elf_isab_plt_info;
1188 if (features & mcfisa_c)
1189 return &elf_isac_plt_info;
1190 return &elf_m68k_plt_info;
1193 /* This function is called after all the input files have been read,
1194 and the input sections have been assigned to output sections.
1195 It's a convenient place to determine the PLT style. */
1198 elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
1200 elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
1204 /* Adjust a symbol defined by a dynamic object and referenced by a
1205 regular object. The current definition is in some section of the
1206 dynamic object, but we're not including those sections. We have to
1207 change the definition to something the rest of the link can
1211 elf_m68k_adjust_dynamic_symbol (info, h)
1212 struct bfd_link_info *info;
1213 struct elf_link_hash_entry *h;
1215 struct elf_m68k_link_hash_table *htab;
1218 unsigned int power_of_two;
1220 htab = elf_m68k_hash_table (info);
1221 dynobj = elf_hash_table (info)->dynobj;
1223 /* Make sure we know what is going on here. */
1224 BFD_ASSERT (dynobj != NULL
1226 || h->u.weakdef != NULL
1229 && !h->def_regular)));
1231 /* If this is a function, put it in the procedure linkage table. We
1232 will fill in the contents of the procedure linkage table later,
1233 when we know the address of the .got section. */
1234 if (h->type == STT_FUNC
1237 if ((h->plt.refcount <= 0
1238 || SYMBOL_CALLS_LOCAL (info, h)
1239 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1240 && h->root.type == bfd_link_hash_undefweak))
1241 /* We must always create the plt entry if it was referenced
1242 by a PLTxxO relocation. In this case we already recorded
1243 it as a dynamic symbol. */
1244 && h->dynindx == -1)
1246 /* This case can occur if we saw a PLTxx reloc in an input
1247 file, but the symbol was never referred to by a dynamic
1248 object, or if all references were garbage collected. In
1249 such a case, we don't actually need to build a procedure
1250 linkage table, and we can just do a PCxx reloc instead. */
1251 h->plt.offset = (bfd_vma) -1;
1256 /* Make sure this symbol is output as a dynamic symbol. */
1257 if (h->dynindx == -1
1258 && !h->forced_local)
1260 if (! bfd_elf_link_record_dynamic_symbol (info, h))
1264 s = bfd_get_section_by_name (dynobj, ".plt");
1265 BFD_ASSERT (s != NULL);
1267 /* If this is the first .plt entry, make room for the special
1270 s->size = htab->plt_info->size;
1272 /* If this symbol is not defined in a regular file, and we are
1273 not generating a shared library, then set the symbol to this
1274 location in the .plt. This is required to make function
1275 pointers compare as equal between the normal executable and
1276 the shared library. */
1280 h->root.u.def.section = s;
1281 h->root.u.def.value = s->size;
1284 h->plt.offset = s->size;
1286 /* Make room for this entry. */
1287 s->size += htab->plt_info->size;
1289 /* We also need to make an entry in the .got.plt section, which
1290 will be placed in the .got section by the linker script. */
1291 s = bfd_get_section_by_name (dynobj, ".got.plt");
1292 BFD_ASSERT (s != NULL);
1295 /* We also need to make an entry in the .rela.plt section. */
1296 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1297 BFD_ASSERT (s != NULL);
1298 s->size += sizeof (Elf32_External_Rela);
1303 /* Reinitialize the plt offset now that it is not used as a reference
1305 h->plt.offset = (bfd_vma) -1;
1307 /* If this is a weak symbol, and there is a real definition, the
1308 processor independent code will have arranged for us to see the
1309 real definition first, and we can just use the same value. */
1310 if (h->u.weakdef != NULL)
1312 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1313 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1314 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1315 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1319 /* This is a reference to a symbol defined by a dynamic object which
1320 is not a function. */
1322 /* If we are creating a shared library, we must presume that the
1323 only references to the symbol are via the global offset table.
1324 For such cases we need not do anything here; the relocations will
1325 be handled correctly by relocate_section. */
1331 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1332 h->root.root.string);
1336 /* We must allocate the symbol in our .dynbss section, which will
1337 become part of the .bss section of the executable. There will be
1338 an entry for this symbol in the .dynsym section. The dynamic
1339 object will contain position independent code, so all references
1340 from the dynamic object to this symbol will go through the global
1341 offset table. The dynamic linker will use the .dynsym entry to
1342 determine the address it must put in the global offset table, so
1343 both the dynamic object and the regular object will refer to the
1344 same memory location for the variable. */
1346 s = bfd_get_section_by_name (dynobj, ".dynbss");
1347 BFD_ASSERT (s != NULL);
1349 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
1350 copy the initial value out of the dynamic object and into the
1351 runtime process image. We need to remember the offset into the
1352 .rela.bss section we are going to use. */
1353 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1357 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1358 BFD_ASSERT (srel != NULL);
1359 srel->size += sizeof (Elf32_External_Rela);
1363 /* We need to figure out the alignment required for this symbol. I
1364 have no idea how ELF linkers handle this. */
1365 power_of_two = bfd_log2 (h->size);
1366 if (power_of_two > 3)
1369 /* Apply the required alignment. */
1370 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
1371 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1373 if (!bfd_set_section_alignment (dynobj, s, power_of_two))
1377 /* Define the symbol as being at this point in the section. */
1378 h->root.u.def.section = s;
1379 h->root.u.def.value = s->size;
1381 /* Increment the section size to make room for the symbol. */
1387 /* Set the sizes of the dynamic sections. */
1390 elf_m68k_size_dynamic_sections (output_bfd, info)
1391 bfd *output_bfd ATTRIBUTE_UNUSED;
1392 struct bfd_link_info *info;
1399 dynobj = elf_hash_table (info)->dynobj;
1400 BFD_ASSERT (dynobj != NULL);
1402 if (elf_hash_table (info)->dynamic_sections_created)
1404 /* Set the contents of the .interp section to the interpreter. */
1405 if (info->executable)
1407 s = bfd_get_section_by_name (dynobj, ".interp");
1408 BFD_ASSERT (s != NULL);
1409 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1410 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1415 /* We may have created entries in the .rela.got section.
1416 However, if we are not creating the dynamic sections, we will
1417 not actually use these entries. Reset the size of .rela.got,
1418 which will cause it to get stripped from the output file
1420 s = bfd_get_section_by_name (dynobj, ".rela.got");
1425 /* If this is a -Bsymbolic shared link, then we need to discard all
1426 PC relative relocs against symbols defined in a regular object.
1427 For the normal shared case we discard the PC relative relocs
1428 against symbols that have become local due to visibility changes.
1429 We allocated space for them in the check_relocs routine, but we
1430 will not fill them in in the relocate_section routine. */
1432 elf_link_hash_traverse (elf_hash_table (info),
1433 elf_m68k_discard_copies,
1436 /* The check_relocs and adjust_dynamic_symbol entry points have
1437 determined the sizes of the various dynamic sections. Allocate
1441 for (s = dynobj->sections; s != NULL; s = s->next)
1445 if ((s->flags & SEC_LINKER_CREATED) == 0)
1448 /* It's OK to base decisions on the section name, because none
1449 of the dynobj section names depend upon the input files. */
1450 name = bfd_get_section_name (dynobj, s);
1452 if (strcmp (name, ".plt") == 0)
1454 /* Remember whether there is a PLT. */
1457 else if (CONST_STRNEQ (name, ".rela"))
1463 /* We use the reloc_count field as a counter if we need
1464 to copy relocs into the output file. */
1468 else if (! CONST_STRNEQ (name, ".got")
1469 && strcmp (name, ".dynbss") != 0)
1471 /* It's not one of our sections, so don't allocate space. */
1477 /* If we don't need this section, strip it from the
1478 output file. This is mostly to handle .rela.bss and
1479 .rela.plt. We must create both sections in
1480 create_dynamic_sections, because they must be created
1481 before the linker maps input sections to output
1482 sections. The linker does that before
1483 adjust_dynamic_symbol is called, and it is that
1484 function which decides whether anything needs to go
1485 into these sections. */
1486 s->flags |= SEC_EXCLUDE;
1490 if ((s->flags & SEC_HAS_CONTENTS) == 0)
1493 /* Allocate memory for the section contents. */
1494 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
1495 Unused entries should be reclaimed before the section's contents
1496 are written out, but at the moment this does not happen. Thus in
1497 order to prevent writing out garbage, we initialise the section's
1498 contents to zero. */
1499 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1500 if (s->contents == NULL)
1504 if (elf_hash_table (info)->dynamic_sections_created)
1506 /* Add some entries to the .dynamic section. We fill in the
1507 values later, in elf_m68k_finish_dynamic_sections, but we
1508 must add the entries now so that we get the correct size for
1509 the .dynamic section. The DT_DEBUG entry is filled in by the
1510 dynamic linker and used by the debugger. */
1511 #define add_dynamic_entry(TAG, VAL) \
1512 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1516 if (!add_dynamic_entry (DT_DEBUG, 0))
1522 if (!add_dynamic_entry (DT_PLTGOT, 0)
1523 || !add_dynamic_entry (DT_PLTRELSZ, 0)
1524 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
1525 || !add_dynamic_entry (DT_JMPREL, 0))
1531 if (!add_dynamic_entry (DT_RELA, 0)
1532 || !add_dynamic_entry (DT_RELASZ, 0)
1533 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
1537 if ((info->flags & DF_TEXTREL) != 0)
1539 if (!add_dynamic_entry (DT_TEXTREL, 0))
1543 #undef add_dynamic_entry
1548 /* This function is called via elf_link_hash_traverse if we are
1549 creating a shared object. In the -Bsymbolic case it discards the
1550 space allocated to copy PC relative relocs against symbols which
1551 are defined in regular objects. For the normal shared case, it
1552 discards space for pc-relative relocs that have become local due to
1553 symbol visibility changes. We allocated space for them in the
1554 check_relocs routine, but we won't fill them in in the
1555 relocate_section routine.
1557 We also check whether any of the remaining relocations apply
1558 against a readonly section, and set the DF_TEXTREL flag in this
1562 elf_m68k_discard_copies (h, inf)
1563 struct elf_link_hash_entry *h;
1566 struct bfd_link_info *info = (struct bfd_link_info *) inf;
1567 struct elf_m68k_pcrel_relocs_copied *s;
1569 if (h->root.type == bfd_link_hash_warning)
1570 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1574 && !h->forced_local))
1576 if ((info->flags & DF_TEXTREL) == 0)
1578 /* Look for relocations against read-only sections. */
1579 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
1582 if ((s->section->flags & SEC_READONLY) != 0)
1584 info->flags |= DF_TEXTREL;
1592 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
1595 s->section->size -= s->count * sizeof (Elf32_External_Rela);
1600 /* Relocate an M68K ELF section. */
1603 elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section,
1604 contents, relocs, local_syms, local_sections)
1606 struct bfd_link_info *info;
1608 asection *input_section;
1610 Elf_Internal_Rela *relocs;
1611 Elf_Internal_Sym *local_syms;
1612 asection **local_sections;
1615 Elf_Internal_Shdr *symtab_hdr;
1616 struct elf_link_hash_entry **sym_hashes;
1617 bfd_vma *local_got_offsets;
1621 Elf_Internal_Rela *rel;
1622 Elf_Internal_Rela *relend;
1624 dynobj = elf_hash_table (info)->dynobj;
1625 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1626 sym_hashes = elf_sym_hashes (input_bfd);
1627 local_got_offsets = elf_local_got_offsets (input_bfd);
1634 relend = relocs + input_section->reloc_count;
1635 for (; rel < relend; rel++)
1638 reloc_howto_type *howto;
1639 unsigned long r_symndx;
1640 struct elf_link_hash_entry *h;
1641 Elf_Internal_Sym *sym;
1644 bfd_boolean unresolved_reloc;
1645 bfd_reloc_status_type r;
1647 r_type = ELF32_R_TYPE (rel->r_info);
1648 if (r_type < 0 || r_type >= (int) R_68K_max)
1650 bfd_set_error (bfd_error_bad_value);
1653 howto = howto_table + r_type;
1655 r_symndx = ELF32_R_SYM (rel->r_info);
1660 unresolved_reloc = FALSE;
1662 if (r_symndx < symtab_hdr->sh_info)
1664 sym = local_syms + r_symndx;
1665 sec = local_sections[r_symndx];
1666 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1672 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1673 r_symndx, symtab_hdr, sym_hashes,
1675 unresolved_reloc, warned);
1678 if (sec != NULL && elf_discarded_section (sec))
1680 /* For relocs against symbols from removed linkonce sections,
1681 or sections discarded by a linker script, we just want the
1682 section contents zeroed. Avoid any special processing. */
1683 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
1689 if (info->relocatable)
1697 /* Relocation is to the address of the entry for this symbol
1698 in the global offset table. */
1700 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1706 /* Relocation is the offset of the entry for this symbol in
1707 the global offset table. */
1714 sgot = bfd_get_section_by_name (dynobj, ".got");
1715 BFD_ASSERT (sgot != NULL);
1722 off = h->got.offset;
1723 BFD_ASSERT (off != (bfd_vma) -1);
1725 dyn = elf_hash_table (info)->dynamic_sections_created;
1726 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
1733 /* This is actually a static link, or it is a
1734 -Bsymbolic link and the symbol is defined
1735 locally, or the symbol was forced to be local
1736 because of a version file.. We must initialize
1737 this entry in the global offset table. Since
1738 the offset must always be a multiple of 4, we
1739 use the least significant bit to record whether
1740 we have initialized it already.
1742 When doing a dynamic link, we create a .rela.got
1743 relocation entry to initialize the value. This
1744 is done in the finish_dynamic_symbol routine. */
1749 bfd_put_32 (output_bfd, relocation,
1750 sgot->contents + off);
1755 unresolved_reloc = FALSE;
1759 BFD_ASSERT (local_got_offsets != NULL
1760 && local_got_offsets[r_symndx] != (bfd_vma) -1);
1762 off = local_got_offsets[r_symndx];
1764 /* The offset must always be a multiple of 4. We use
1765 the least significant bit to record whether we have
1766 already generated the necessary reloc. */
1771 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1776 Elf_Internal_Rela outrel;
1779 s = bfd_get_section_by_name (dynobj, ".rela.got");
1780 BFD_ASSERT (s != NULL);
1782 outrel.r_offset = (sgot->output_section->vma
1783 + sgot->output_offset
1785 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
1786 outrel.r_addend = relocation;
1788 loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
1789 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1792 local_got_offsets[r_symndx] |= 1;
1796 relocation = sgot->output_offset + off;
1797 if (r_type == R_68K_GOT8O
1798 || r_type == R_68K_GOT16O
1799 || r_type == R_68K_GOT32O)
1801 /* This relocation does not use the addend. */
1805 relocation += sgot->output_section->vma;
1812 /* Relocation is to the entry for this symbol in the
1813 procedure linkage table. */
1815 /* Resolve a PLTxx reloc against a local symbol directly,
1816 without using the procedure linkage table. */
1820 if (h->plt.offset == (bfd_vma) -1
1821 || !elf_hash_table (info)->dynamic_sections_created)
1823 /* We didn't make a PLT entry for this symbol. This
1824 happens when statically linking PIC code, or when
1825 using -Bsymbolic. */
1831 splt = bfd_get_section_by_name (dynobj, ".plt");
1832 BFD_ASSERT (splt != NULL);
1835 relocation = (splt->output_section->vma
1836 + splt->output_offset
1838 unresolved_reloc = FALSE;
1844 /* Relocation is the offset of the entry for this symbol in
1845 the procedure linkage table. */
1846 BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
1850 splt = bfd_get_section_by_name (dynobj, ".plt");
1851 BFD_ASSERT (splt != NULL);
1854 relocation = h->plt.offset;
1855 unresolved_reloc = FALSE;
1857 /* This relocation does not use the addend. */
1867 && h->forced_local))
1875 && (input_section->flags & SEC_ALLOC) != 0
1877 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1878 || h->root.type != bfd_link_hash_undefweak)
1879 && ((r_type != R_68K_PC8
1880 && r_type != R_68K_PC16
1881 && r_type != R_68K_PC32)
1885 || !h->def_regular))))
1887 Elf_Internal_Rela outrel;
1889 bfd_boolean skip, relocate;
1891 /* When generating a shared object, these relocations
1892 are copied into the output file to be resolved at run
1899 _bfd_elf_section_offset (output_bfd, info, input_section,
1901 if (outrel.r_offset == (bfd_vma) -1)
1903 else if (outrel.r_offset == (bfd_vma) -2)
1904 skip = TRUE, relocate = TRUE;
1905 outrel.r_offset += (input_section->output_section->vma
1906 + input_section->output_offset);
1909 memset (&outrel, 0, sizeof outrel);
1912 && (r_type == R_68K_PC8
1913 || r_type == R_68K_PC16
1914 || r_type == R_68K_PC32
1917 || !h->def_regular))
1919 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1920 outrel.r_addend = rel->r_addend;
1924 /* This symbol is local, or marked to become local. */
1925 outrel.r_addend = relocation + rel->r_addend;
1927 if (r_type == R_68K_32)
1930 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
1936 if (bfd_is_abs_section (sec))
1938 else if (sec == NULL || sec->owner == NULL)
1940 bfd_set_error (bfd_error_bad_value);
1947 /* We are turning this relocation into one
1948 against a section symbol. It would be
1949 proper to subtract the symbol's value,
1950 osec->vma, from the emitted reloc addend,
1951 but ld.so expects buggy relocs. */
1952 osec = sec->output_section;
1953 indx = elf_section_data (osec)->dynindx;
1956 struct elf_link_hash_table *htab;
1957 htab = elf_hash_table (info);
1958 osec = htab->text_index_section;
1959 indx = elf_section_data (osec)->dynindx;
1961 BFD_ASSERT (indx != 0);
1964 outrel.r_info = ELF32_R_INFO (indx, r_type);
1968 sreloc = elf_section_data (input_section)->sreloc;
1972 loc = sreloc->contents;
1973 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
1974 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1976 /* This reloc will be computed at runtime, so there's no
1977 need to do anything now, except for R_68K_32
1978 relocations that have been turned into
1986 case R_68K_GNU_VTINHERIT:
1987 case R_68K_GNU_VTENTRY:
1988 /* These are no-ops in the end. */
1995 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
1996 because such sections are not SEC_ALLOC and thus ld.so will
1997 not process them. */
1998 if (unresolved_reloc
1999 && !((input_section->flags & SEC_DEBUGGING) != 0
2002 (*_bfd_error_handler)
2003 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
2006 (long) rel->r_offset,
2008 h->root.root.string);
2012 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2013 contents, rel->r_offset,
2014 relocation, rel->r_addend);
2016 if (r != bfd_reloc_ok)
2021 name = h->root.root.string;
2024 name = bfd_elf_string_from_elf_section (input_bfd,
2025 symtab_hdr->sh_link,
2030 name = bfd_section_name (input_bfd, sec);
2033 if (r == bfd_reloc_overflow)
2035 if (!(info->callbacks->reloc_overflow
2036 (info, (h ? &h->root : NULL), name, howto->name,
2037 (bfd_vma) 0, input_bfd, input_section,
2043 (*_bfd_error_handler)
2044 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
2045 input_bfd, input_section,
2046 (long) rel->r_offset, name, (int) r);
2055 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
2056 into section SEC. */
2059 elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
2061 /* Make VALUE PC-relative. */
2062 value -= sec->output_section->vma + offset;
2064 /* Apply any in-place addend. */
2065 value += bfd_get_32 (sec->owner, sec->contents + offset);
2067 bfd_put_32 (sec->owner, value, sec->contents + offset);
2070 /* Finish up dynamic symbol handling. We set the contents of various
2071 dynamic sections here. */
2074 elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym)
2076 struct bfd_link_info *info;
2077 struct elf_link_hash_entry *h;
2078 Elf_Internal_Sym *sym;
2082 dynobj = elf_hash_table (info)->dynobj;
2084 if (h->plt.offset != (bfd_vma) -1)
2086 const struct elf_m68k_plt_info *plt_info;
2092 Elf_Internal_Rela rela;
2095 /* This symbol has an entry in the procedure linkage table. Set
2098 BFD_ASSERT (h->dynindx != -1);
2100 plt_info = elf_m68k_hash_table (info)->plt_info;
2101 splt = bfd_get_section_by_name (dynobj, ".plt");
2102 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
2103 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
2104 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
2106 /* Get the index in the procedure linkage table which
2107 corresponds to this symbol. This is the index of this symbol
2108 in all the symbols for which we are making plt entries. The
2109 first entry in the procedure linkage table is reserved. */
2110 plt_index = (h->plt.offset / plt_info->size) - 1;
2112 /* Get the offset into the .got table of the entry that
2113 corresponds to this function. Each .got entry is 4 bytes.
2114 The first three are reserved. */
2115 got_offset = (plt_index + 3) * 4;
2117 memcpy (splt->contents + h->plt.offset,
2118 plt_info->symbol_entry,
2121 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
2122 (sgot->output_section->vma
2123 + sgot->output_offset
2126 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
2129 + plt_info->symbol_resolve_entry + 2);
2131 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
2132 splt->output_section->vma);
2134 /* Fill in the entry in the global offset table. */
2135 bfd_put_32 (output_bfd,
2136 (splt->output_section->vma
2137 + splt->output_offset
2139 + plt_info->symbol_resolve_entry),
2140 sgot->contents + got_offset);
2142 /* Fill in the entry in the .rela.plt section. */
2143 rela.r_offset = (sgot->output_section->vma
2144 + sgot->output_offset
2146 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
2148 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
2149 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2151 if (!h->def_regular)
2153 /* Mark the symbol as undefined, rather than as defined in
2154 the .plt section. Leave the value alone. */
2155 sym->st_shndx = SHN_UNDEF;
2159 if (h->got.offset != (bfd_vma) -1)
2163 Elf_Internal_Rela rela;
2166 /* This symbol has an entry in the global offset table. Set it
2169 sgot = bfd_get_section_by_name (dynobj, ".got");
2170 srela = bfd_get_section_by_name (dynobj, ".rela.got");
2171 BFD_ASSERT (sgot != NULL && srela != NULL);
2173 rela.r_offset = (sgot->output_section->vma
2174 + sgot->output_offset
2175 + (h->got.offset &~ (bfd_vma) 1));
2177 /* If this is a -Bsymbolic link, and the symbol is defined
2178 locally, we just want to emit a RELATIVE reloc. Likewise if
2179 the symbol was forced to be local because of a version file.
2180 The entry in the global offset table will already have been
2181 initialized in the relocate_section function. */
2188 rela.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
2189 rela.r_addend = bfd_get_signed_32 (output_bfd,
2191 + (h->got.offset &~ (bfd_vma) 1)));
2195 bfd_put_32 (output_bfd, (bfd_vma) 0,
2196 sgot->contents + (h->got.offset &~ (bfd_vma) 1));
2197 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
2201 loc = srela->contents;
2202 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
2203 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2209 Elf_Internal_Rela rela;
2212 /* This symbol needs a copy reloc. Set it up. */
2214 BFD_ASSERT (h->dynindx != -1
2215 && (h->root.type == bfd_link_hash_defined
2216 || h->root.type == bfd_link_hash_defweak));
2218 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2220 BFD_ASSERT (s != NULL);
2222 rela.r_offset = (h->root.u.def.value
2223 + h->root.u.def.section->output_section->vma
2224 + h->root.u.def.section->output_offset);
2225 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
2227 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
2228 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
2231 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2232 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2233 || h == elf_hash_table (info)->hgot)
2234 sym->st_shndx = SHN_ABS;
2239 /* Finish up the dynamic sections. */
2242 elf_m68k_finish_dynamic_sections (output_bfd, info)
2244 struct bfd_link_info *info;
2250 dynobj = elf_hash_table (info)->dynobj;
2252 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
2253 BFD_ASSERT (sgot != NULL);
2254 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2256 if (elf_hash_table (info)->dynamic_sections_created)
2259 Elf32_External_Dyn *dyncon, *dynconend;
2261 splt = bfd_get_section_by_name (dynobj, ".plt");
2262 BFD_ASSERT (splt != NULL && sdyn != NULL);
2264 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2265 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
2266 for (; dyncon < dynconend; dyncon++)
2268 Elf_Internal_Dyn dyn;
2272 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2285 s = bfd_get_section_by_name (output_bfd, name);
2286 BFD_ASSERT (s != NULL);
2287 dyn.d_un.d_ptr = s->vma;
2288 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2292 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2293 BFD_ASSERT (s != NULL);
2294 dyn.d_un.d_val = s->size;
2295 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2299 /* The procedure linkage table relocs (DT_JMPREL) should
2300 not be included in the overall relocs (DT_RELA).
2301 Therefore, we override the DT_RELASZ entry here to
2302 make it not include the JMPREL relocs. Since the
2303 linker script arranges for .rela.plt to follow all
2304 other relocation sections, we don't have to worry
2305 about changing the DT_RELA entry. */
2306 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
2308 dyn.d_un.d_val -= s->size;
2309 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2314 /* Fill in the first entry in the procedure linkage table. */
2317 const struct elf_m68k_plt_info *plt_info;
2319 plt_info = elf_m68k_hash_table (info)->plt_info;
2320 memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
2322 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
2323 (sgot->output_section->vma
2324 + sgot->output_offset
2327 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
2328 (sgot->output_section->vma
2329 + sgot->output_offset
2332 elf_section_data (splt->output_section)->this_hdr.sh_entsize
2337 /* Fill in the first three entries in the global offset table. */
2341 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
2343 bfd_put_32 (output_bfd,
2344 sdyn->output_section->vma + sdyn->output_offset,
2346 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
2347 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
2350 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2355 /* Given a .data section and a .emreloc in-memory section, store
2356 relocation information into the .emreloc section which can be
2357 used at runtime to relocate the section. This is called by the
2358 linker when the --embedded-relocs switch is used. This is called
2359 after the add_symbols entry point has been called for all the
2360 objects, and before the final_link entry point is called. */
2363 bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
2365 struct bfd_link_info *info;
2370 Elf_Internal_Shdr *symtab_hdr;
2371 Elf_Internal_Sym *isymbuf = NULL;
2372 Elf_Internal_Rela *internal_relocs = NULL;
2373 Elf_Internal_Rela *irel, *irelend;
2377 BFD_ASSERT (! info->relocatable);
2381 if (datasec->reloc_count == 0)
2384 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2386 /* Get a copy of the native relocations. */
2387 internal_relocs = (_bfd_elf_link_read_relocs
2388 (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2389 info->keep_memory));
2390 if (internal_relocs == NULL)
2393 amt = (bfd_size_type) datasec->reloc_count * 12;
2394 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
2395 if (relsec->contents == NULL)
2398 p = relsec->contents;
2400 irelend = internal_relocs + datasec->reloc_count;
2401 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
2403 asection *targetsec;
2405 /* We are going to write a four byte longword into the runtime
2406 reloc section. The longword will be the address in the data
2407 section which must be relocated. It is followed by the name
2408 of the target section NUL-padded or truncated to 8
2411 /* We can only relocate absolute longword relocs at run time. */
2412 if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
2414 *errmsg = _("unsupported reloc type");
2415 bfd_set_error (bfd_error_bad_value);
2419 /* Get the target section referred to by the reloc. */
2420 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2422 /* A local symbol. */
2423 Elf_Internal_Sym *isym;
2425 /* Read this BFD's local symbols if we haven't done so already. */
2426 if (isymbuf == NULL)
2428 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2429 if (isymbuf == NULL)
2430 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2431 symtab_hdr->sh_info, 0,
2433 if (isymbuf == NULL)
2437 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2438 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2443 struct elf_link_hash_entry *h;
2445 /* An external symbol. */
2446 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2447 h = elf_sym_hashes (abfd)[indx];
2448 BFD_ASSERT (h != NULL);
2449 if (h->root.type == bfd_link_hash_defined
2450 || h->root.type == bfd_link_hash_defweak)
2451 targetsec = h->root.u.def.section;
2456 bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
2457 memset (p + 4, 0, 8);
2458 if (targetsec != NULL)
2459 strncpy ((char *) p + 4, targetsec->output_section->name, 8);
2462 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
2464 if (internal_relocs != NULL
2465 && elf_section_data (datasec)->relocs != internal_relocs)
2466 free (internal_relocs);
2470 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
2472 if (internal_relocs != NULL
2473 && elf_section_data (datasec)->relocs != internal_relocs)
2474 free (internal_relocs);
2478 static enum elf_reloc_type_class
2479 elf32_m68k_reloc_type_class (rela)
2480 const Elf_Internal_Rela *rela;
2482 switch ((int) ELF32_R_TYPE (rela->r_info))
2484 case R_68K_RELATIVE:
2485 return reloc_class_relative;
2486 case R_68K_JMP_SLOT:
2487 return reloc_class_plt;
2489 return reloc_class_copy;
2491 return reloc_class_normal;
2495 /* Return address for Ith PLT stub in section PLT, for relocation REL
2496 or (bfd_vma) -1 if it should not be included. */
2499 elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
2500 const arelent *rel ATTRIBUTE_UNUSED)
2502 return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
2505 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
2506 #define TARGET_BIG_NAME "elf32-m68k"
2507 #define ELF_MACHINE_CODE EM_68K
2508 #define ELF_MAXPAGESIZE 0x2000
2509 #define elf_backend_create_dynamic_sections \
2510 _bfd_elf_create_dynamic_sections
2511 #define bfd_elf32_bfd_link_hash_table_create \
2512 elf_m68k_link_hash_table_create
2513 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
2515 #define elf_backend_check_relocs elf_m68k_check_relocs
2516 #define elf_backend_always_size_sections \
2517 elf_m68k_always_size_sections
2518 #define elf_backend_adjust_dynamic_symbol \
2519 elf_m68k_adjust_dynamic_symbol
2520 #define elf_backend_size_dynamic_sections \
2521 elf_m68k_size_dynamic_sections
2522 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
2523 #define elf_backend_relocate_section elf_m68k_relocate_section
2524 #define elf_backend_finish_dynamic_symbol \
2525 elf_m68k_finish_dynamic_symbol
2526 #define elf_backend_finish_dynamic_sections \
2527 elf_m68k_finish_dynamic_sections
2528 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
2529 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
2530 #define bfd_elf32_bfd_merge_private_bfd_data \
2531 elf32_m68k_merge_private_bfd_data
2532 #define bfd_elf32_bfd_set_private_flags \
2533 elf32_m68k_set_private_flags
2534 #define bfd_elf32_bfd_print_private_bfd_data \
2535 elf32_m68k_print_private_bfd_data
2536 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
2537 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
2538 #define elf_backend_object_p elf32_m68k_object_p
2540 #define elf_backend_can_gc_sections 1
2541 #define elf_backend_can_refcount 1
2542 #define elf_backend_want_got_plt 1
2543 #define elf_backend_plt_readonly 1
2544 #define elf_backend_want_plt_sym 0
2545 #define elf_backend_got_header_size 12
2546 #define elf_backend_rela_normal 1
2548 #include "elf32-target.h"