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 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 3 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,
20 MA 02110-1301, USA. */
28 #include "opcode/m68k.h"
30 static reloc_howto_type *reloc_type_lookup
31 PARAMS ((bfd *, bfd_reloc_code_real_type));
32 static void rtype_to_howto
33 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
34 static struct bfd_hash_entry *elf_m68k_link_hash_newfunc
35 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
36 static struct bfd_link_hash_table *elf_m68k_link_hash_table_create
38 static bfd_boolean elf_m68k_check_relocs
39 PARAMS ((bfd *, struct bfd_link_info *, asection *,
40 const Elf_Internal_Rela *));
41 static bfd_boolean elf_m68k_adjust_dynamic_symbol
42 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
43 static bfd_boolean elf_m68k_size_dynamic_sections
44 PARAMS ((bfd *, struct bfd_link_info *));
45 static bfd_boolean elf_m68k_discard_copies
46 PARAMS ((struct elf_link_hash_entry *, PTR));
47 static bfd_boolean elf_m68k_relocate_section
48 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
49 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
50 static bfd_boolean elf_m68k_finish_dynamic_symbol
51 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
53 static bfd_boolean elf_m68k_finish_dynamic_sections
54 PARAMS ((bfd *, struct bfd_link_info *));
56 static bfd_boolean elf32_m68k_set_private_flags
57 PARAMS ((bfd *, flagword));
58 static bfd_boolean elf32_m68k_merge_private_bfd_data
59 PARAMS ((bfd *, bfd *));
60 static bfd_boolean elf32_m68k_print_private_bfd_data
61 PARAMS ((bfd *, PTR));
62 static enum elf_reloc_type_class elf32_m68k_reloc_type_class
63 PARAMS ((const Elf_Internal_Rela *));
65 static reloc_howto_type howto_table[] = {
66 HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE),
67 HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE),
68 HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE),
69 HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE),
70 HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE),
71 HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE),
72 HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE),
73 HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE),
74 HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE),
75 HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE),
76 HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE),
77 HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE),
78 HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE),
79 HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE),
80 HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE),
81 HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE),
82 HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE),
83 HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE),
84 HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE),
85 HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE),
86 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),
87 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),
88 HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE),
89 /* GNU extension to record C++ vtable hierarchy. */
90 HOWTO (R_68K_GNU_VTINHERIT, /* type */
92 2, /* size (0 = byte, 1 = short, 2 = long) */
94 FALSE, /* pc_relative */
96 complain_overflow_dont, /* complain_on_overflow */
97 NULL, /* special_function */
98 "R_68K_GNU_VTINHERIT", /* name */
99 FALSE, /* partial_inplace */
103 /* GNU extension to record C++ vtable member usage. */
104 HOWTO (R_68K_GNU_VTENTRY, /* type */
106 2, /* size (0 = byte, 1 = short, 2 = long) */
108 FALSE, /* pc_relative */
110 complain_overflow_dont, /* complain_on_overflow */
111 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
112 "R_68K_GNU_VTENTRY", /* name */
113 FALSE, /* partial_inplace */
120 rtype_to_howto (abfd, cache_ptr, dst)
121 bfd *abfd ATTRIBUTE_UNUSED;
123 Elf_Internal_Rela *dst;
125 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K_max);
126 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
129 #define elf_info_to_howto rtype_to_howto
133 bfd_reloc_code_real_type bfd_val;
136 { BFD_RELOC_NONE, R_68K_NONE },
137 { BFD_RELOC_32, R_68K_32 },
138 { BFD_RELOC_16, R_68K_16 },
139 { BFD_RELOC_8, R_68K_8 },
140 { BFD_RELOC_32_PCREL, R_68K_PC32 },
141 { BFD_RELOC_16_PCREL, R_68K_PC16 },
142 { BFD_RELOC_8_PCREL, R_68K_PC8 },
143 { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
144 { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
145 { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
146 { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
147 { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
148 { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
149 { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
150 { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
151 { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
152 { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
153 { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
154 { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
155 { BFD_RELOC_NONE, R_68K_COPY },
156 { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
157 { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
158 { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
159 { BFD_RELOC_CTOR, R_68K_32 },
160 { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
161 { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
164 static reloc_howto_type *
165 reloc_type_lookup (abfd, code)
166 bfd *abfd ATTRIBUTE_UNUSED;
167 bfd_reloc_code_real_type code;
170 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
172 if (reloc_map[i].bfd_val == code)
173 return &howto_table[reloc_map[i].elf_val];
178 static reloc_howto_type *
179 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
183 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
184 if (howto_table[i].name != NULL
185 && strcasecmp (howto_table[i].name, r_name) == 0)
186 return &howto_table[i];
191 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
192 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
193 #define ELF_ARCH bfd_arch_m68k
195 /* Functions for the m68k ELF linker. */
197 /* The name of the dynamic interpreter. This is put in the .interp
200 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
202 /* Describes one of the various PLT styles. */
204 struct elf_m68k_plt_info
206 /* The size of each PLT entry. */
209 /* The template for the first PLT entry. */
210 const bfd_byte *plt0_entry;
212 /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
213 The comments by each member indicate the value that the relocation
216 unsigned int got4; /* .got + 4 */
217 unsigned int got8; /* .got + 8 */
220 /* The template for a symbol's PLT entry. */
221 const bfd_byte *symbol_entry;
223 /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
224 The comments by each member indicate the value that the relocation
227 unsigned int got; /* the symbol's .got.plt entry */
228 unsigned int plt; /* .plt */
231 /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
232 The stub starts with "move.l #relocoffset,%d0". */
233 bfd_vma symbol_resolve_entry;
236 /* The size in bytes of an entry in the procedure linkage table. */
238 #define PLT_ENTRY_SIZE 20
240 /* The first entry in a procedure linkage table looks like this. See
241 the SVR4 ABI m68k supplement to see how this works. */
243 static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
245 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
246 0, 0, 0, 2, /* + (.got + 4) - . */
247 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
248 0, 0, 0, 2, /* + (.got + 8) - . */
249 0, 0, 0, 0 /* pad out to 20 bytes. */
252 /* Subsequent entries in a procedure linkage table look like this. */
254 static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
256 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
257 0, 0, 0, 2, /* + (.got.plt entry) - . */
258 0x2f, 0x3c, /* move.l #offset,-(%sp) */
259 0, 0, 0, 0, /* + reloc index */
260 0x60, 0xff, /* bra.l .plt */
261 0, 0, 0, 0 /* + .plt - . */
264 static const struct elf_m68k_plt_info elf_m68k_plt_info = {
266 elf_m68k_plt0_entry, { 4, 12 },
267 elf_m68k_plt_entry, { 4, 16 }, 8
270 #define ISAB_PLT_ENTRY_SIZE 24
272 static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
274 0x20, 0x3c, /* move.l #offset,%d0 */
275 0, 0, 0, 0, /* + (.got + 4) - . */
276 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
277 0x20, 0x3c, /* move.l #offset,%d0 */
278 0, 0, 0, 0, /* + (.got + 8) - . */
279 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
280 0x4e, 0xd0, /* jmp (%a0) */
284 /* Subsequent entries in a procedure linkage table look like this. */
286 static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
288 0x20, 0x3c, /* move.l #offset,%d0 */
289 0, 0, 0, 0, /* + (.got.plt entry) - . */
290 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
291 0x4e, 0xd0, /* jmp (%a0) */
292 0x2f, 0x3c, /* move.l #offset,-(%sp) */
293 0, 0, 0, 0, /* + reloc index */
294 0x60, 0xff, /* bra.l .plt */
295 0, 0, 0, 0 /* + .plt - . */
298 static const struct elf_m68k_plt_info elf_isab_plt_info = {
300 elf_isab_plt0_entry, { 2, 12 },
301 elf_isab_plt_entry, { 2, 20 }, 12
304 #define ISAC_PLT_ENTRY_SIZE 24
306 static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
308 0x20, 0x3c, /* move.l #offset,%d0 */
309 0, 0, 0, 0, /* replaced with .got + 4 - . */
310 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
311 0x20, 0x3c, /* move.l #offset,%d0 */
312 0, 0, 0, 0, /* replaced with .got + 8 - . */
313 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
314 0x4e, 0xd0, /* jmp (%a0) */
318 /* Subsequent entries in a procedure linkage table look like this. */
320 static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
322 0x20, 0x3c, /* move.l #offset,%d0 */
323 0, 0, 0, 0, /* replaced with (.got entry) - . */
324 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
325 0x4e, 0xd0, /* jmp (%a0) */
326 0x2f, 0x3c, /* move.l #offset,-(%sp) */
327 0, 0, 0, 0, /* replaced with offset into relocation table */
328 0x61, 0xff, /* bsr.l .plt */
329 0, 0, 0, 0 /* replaced with .plt - . */
332 static const struct elf_m68k_plt_info elf_isac_plt_info = {
334 elf_isac_plt0_entry, { 2, 12},
335 elf_isac_plt_entry, { 2, 20 }, 12
338 #define CPU32_PLT_ENTRY_SIZE 24
339 /* Procedure linkage table entries for the cpu32 */
340 static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
342 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
343 0, 0, 0, 2, /* + (.got + 4) - . */
344 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
345 0, 0, 0, 2, /* + (.got + 8) - . */
346 0x4e, 0xd1, /* jmp %a1@ */
347 0, 0, 0, 0, /* pad out to 24 bytes. */
351 static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
353 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
354 0, 0, 0, 2, /* + (.got.plt entry) - . */
355 0x4e, 0xd1, /* jmp %a1@ */
356 0x2f, 0x3c, /* move.l #offset,-(%sp) */
357 0, 0, 0, 0, /* + reloc index */
358 0x60, 0xff, /* bra.l .plt */
359 0, 0, 0, 0, /* + .plt - . */
363 static const struct elf_m68k_plt_info elf_cpu32_plt_info = {
364 CPU32_PLT_ENTRY_SIZE,
365 elf_cpu32_plt0_entry, { 4, 12 },
366 elf_cpu32_plt_entry, { 4, 18 }, 10
369 /* The m68k linker needs to keep track of the number of relocs that it
370 decides to copy in check_relocs for each symbol. This is so that it
371 can discard PC relative relocs if it doesn't need them when linking
372 with -Bsymbolic. We store the information in a field extending the
373 regular ELF linker hash table. */
375 /* This structure keeps track of the number of PC relative relocs we have
376 copied for a given symbol. */
378 struct elf_m68k_pcrel_relocs_copied
381 struct elf_m68k_pcrel_relocs_copied *next;
382 /* A section in dynobj. */
384 /* Number of relocs copied in this section. */
388 /* Forward declaration. */
389 struct elf_m68k_got_entry;
391 /* m68k ELF linker hash entry. */
393 struct elf_m68k_link_hash_entry
395 struct elf_link_hash_entry root;
397 /* Number of PC relative relocs copied for this symbol. */
398 struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
400 /* Key to got_entries. */
401 unsigned long got_entry_key;
403 /* List of GOT entries for this symbol. This list is build during
404 offset finalization and is used within elf_m68k_finish_dynamic_symbol
405 to traverse all GOT entries for a particular symbol.
407 ??? We could've used root.got.glist field instead, but having
408 a separate field is cleaner. */
409 struct elf_m68k_got_entry *glist;
412 #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
414 /* Key part of GOT entry in hashtable. */
415 struct elf_m68k_got_entry_key
417 /* BFD in which this symbol was defined. NULL for global symbols. */
420 /* Symbol index. Either local symbol index or h->got_entry_key. */
421 unsigned long symndx;
424 /* Entry of the GOT. */
425 struct elf_m68k_got_entry
427 /* GOT entries are put into a got->entries hashtable. This is the key. */
428 struct elf_m68k_got_entry_key key_;
430 /* GOT entry data. We need s1 before offset finalization and s2 after. */
435 /* Number of times this entry is referenced. It is used to
436 filter out unnecessary GOT slots in elf_m68k_gc_sweep_hook. */
439 /* Type is one of R_68K_GOT8O, R_68K_GOT16O or R_68K_GOT32O. */
445 /* Offset from the start of .got section. To calculate offset relative
446 to GOT pointer one should substract got->offset from this value. */
449 /* Pointer to the next GOT entry for this global symbol.
450 Symbols have at most one entry in one GOT, but might
451 have entries in more than one GOT.
452 Root of this list is h->glist.
453 NULL for local symbols. */
454 struct elf_m68k_got_entry *next;
459 /* Data structure representing a single GOT. */
462 /* Hashtable of 'struct elf_m68k_got_entry's.
463 Starting size of this table is the maximum number of
464 R_68K_GOT8O entries. */
467 /* Number of R_68K_GOT8O entries in this GOT.
468 This is used to detect the overflow of number of such entries. */
469 bfd_vma rel_8o_n_entries;
471 /* Cumulative count of R_68K_GOT8O and R_68K_GOT16O entries in this GOT.
472 This is used to detect the overflow of number of such entries. */
473 bfd_vma rel_8o_16o_n_entries;
475 /* Number of local (entry->key_.h == NULL) entries in this GOT.
476 This is only used to properly calculate size of .rela.got section;
477 see elf_m68k_partition_multi_got. */
478 bfd_vma local_n_entries;
480 /* Offset of this GOT relative to beginning of .got section. */
484 /* BFD and its GOT. This is an entry in multi_got->bfd2got hashtable. */
485 struct elf_m68k_bfd2got_entry
490 /* Assigned GOT. Before partitioning multi-GOT each BFD has its own
491 GOT structure. After partitioning several BFD's might [and often do]
492 share a single GOT. */
493 struct elf_m68k_got *got;
496 /* The main data structure holding all the pieces. */
497 struct elf_m68k_multi_got
499 /* Hashtable mapping each BFD to its GOT. If a BFD doesn't have an entry
500 here, then it doesn't need a GOT (this includes the case of a BFD
501 having an empty GOT).
503 ??? This hashtable can be replaced by an array indexed by bfd->id. */
506 /* Next symndx to assign a global symbol.
507 h->got_entry_key is initialized from this counter. */
508 unsigned long global_symndx;
511 /* m68k ELF linker hash table. */
513 struct elf_m68k_link_hash_table
515 struct elf_link_hash_table root;
517 /* Small local sym to section mapping cache. */
518 struct sym_sec_cache sym_sec;
520 /* The PLT format used by this link, or NULL if the format has not
522 const struct elf_m68k_plt_info *plt_info;
524 /* True, if GP is loaded within each function which uses it.
525 Set to TRUE when GOT negative offsets or multi-GOT is enabled. */
526 bfd_boolean local_gp_p;
528 /* Switch controlling use of negative offsets to double the size of GOTs. */
529 bfd_boolean use_neg_got_offsets_p;
531 /* Switch controlling generation of multiple GOTs. */
532 bfd_boolean allow_multigot_p;
534 /* Multi-GOT data structure. */
535 struct elf_m68k_multi_got multi_got_;
538 /* Get the m68k ELF linker hash table from a link_info structure. */
540 #define elf_m68k_hash_table(p) \
541 ((struct elf_m68k_link_hash_table *) (p)->hash)
543 /* Shortcut to multi-GOT data. */
544 #define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
546 /* Create an entry in an m68k ELF linker hash table. */
548 static struct bfd_hash_entry *
549 elf_m68k_link_hash_newfunc (entry, table, string)
550 struct bfd_hash_entry *entry;
551 struct bfd_hash_table *table;
554 struct bfd_hash_entry *ret = entry;
556 /* Allocate the structure if it has not already been allocated by a
559 ret = bfd_hash_allocate (table,
560 sizeof (struct elf_m68k_link_hash_entry));
564 /* Call the allocation method of the superclass. */
565 ret = _bfd_elf_link_hash_newfunc (ret, table, string);
568 elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
569 elf_m68k_hash_entry (ret)->got_entry_key = 0;
570 elf_m68k_hash_entry (ret)->glist = NULL;
576 /* Create an m68k ELF linker hash table. */
578 static struct bfd_link_hash_table *
579 elf_m68k_link_hash_table_create (abfd)
582 struct elf_m68k_link_hash_table *ret;
583 bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table);
585 ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt);
586 if (ret == (struct elf_m68k_link_hash_table *) NULL)
589 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
590 elf_m68k_link_hash_newfunc,
591 sizeof (struct elf_m68k_link_hash_entry)))
597 ret->sym_sec.abfd = NULL;
598 ret->plt_info = NULL;
599 ret->local_gp_p = FALSE;
600 ret->use_neg_got_offsets_p = FALSE;
601 ret->allow_multigot_p = FALSE;
602 ret->multi_got_.bfd2got = NULL;
603 ret->multi_got_.global_symndx = 1;
605 return &ret->root.root;
608 /* Destruct local data. */
611 elf_m68k_link_hash_table_free (struct bfd_link_hash_table *_htab)
613 struct elf_m68k_link_hash_table *htab;
615 htab = (struct elf_m68k_link_hash_table *) _htab;
617 if (htab->multi_got_.bfd2got != NULL)
619 htab_delete (htab->multi_got_.bfd2got);
620 htab->multi_got_.bfd2got = NULL;
624 /* Set the right machine number. */
627 elf32_m68k_object_p (bfd *abfd)
629 unsigned int mach = 0;
630 unsigned features = 0;
631 flagword eflags = elf_elfheader (abfd)->e_flags;
633 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
635 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
637 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
641 switch (eflags & EF_M68K_CF_ISA_MASK)
643 case EF_M68K_CF_ISA_A_NODIV:
644 features |= mcfisa_a;
646 case EF_M68K_CF_ISA_A:
647 features |= mcfisa_a|mcfhwdiv;
649 case EF_M68K_CF_ISA_A_PLUS:
650 features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
652 case EF_M68K_CF_ISA_B_NOUSP:
653 features |= mcfisa_a|mcfisa_b|mcfhwdiv;
655 case EF_M68K_CF_ISA_B:
656 features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
658 case EF_M68K_CF_ISA_C:
659 features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
661 case EF_M68K_CF_ISA_C_NODIV:
662 features |= mcfisa_a|mcfisa_c|mcfusp;
665 switch (eflags & EF_M68K_CF_MAC_MASK)
670 case EF_M68K_CF_EMAC:
674 if (eflags & EF_M68K_CF_FLOAT)
678 mach = bfd_m68k_features_to_mach (features);
679 bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
684 /* Keep m68k-specific flags in the ELF header. */
686 elf32_m68k_set_private_flags (abfd, flags)
690 elf_elfheader (abfd)->e_flags = flags;
691 elf_flags_init (abfd) = TRUE;
695 /* Merge backend specific data from an object file to the output
696 object file when linking. */
698 elf32_m68k_merge_private_bfd_data (ibfd, obfd)
706 const bfd_arch_info_type *arch_info;
708 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
709 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
712 /* Get the merged machine. This checks for incompatibility between
713 Coldfire & non-Coldfire flags, incompability between different
714 Coldfire ISAs, and incompability between different MAC types. */
715 arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE);
719 bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
721 in_flags = elf_elfheader (ibfd)->e_flags;
722 if (!elf_flags_init (obfd))
724 elf_flags_init (obfd) = TRUE;
725 out_flags = in_flags;
729 out_flags = elf_elfheader (obfd)->e_flags;
730 unsigned int variant_mask;
732 if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
734 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
736 else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
739 variant_mask = EF_M68K_CF_ISA_MASK;
741 in_isa = (in_flags & variant_mask);
742 out_isa = (out_flags & variant_mask);
743 if (in_isa > out_isa)
744 out_flags ^= in_isa ^ out_isa;
745 if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
746 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
747 || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
748 && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
749 out_flags = EF_M68K_FIDO;
751 out_flags |= in_flags ^ in_isa;
753 elf_elfheader (obfd)->e_flags = out_flags;
758 /* Display the flags field. */
761 elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
763 FILE *file = (FILE *) ptr;
764 flagword eflags = elf_elfheader (abfd)->e_flags;
766 BFD_ASSERT (abfd != NULL && ptr != NULL);
768 /* Print normal ELF private data. */
769 _bfd_elf_print_private_bfd_data (abfd, ptr);
771 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */
773 /* xgettext:c-format */
774 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
776 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
777 fprintf (file, " [m68000]");
778 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
779 fprintf (file, " [cpu32]");
780 else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
781 fprintf (file, " [fido]");
784 if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
785 fprintf (file, " [cfv4e]");
787 if (eflags & EF_M68K_CF_ISA_MASK)
789 char const *isa = _("unknown");
790 char const *mac = _("unknown");
791 char const *additional = "";
793 switch (eflags & EF_M68K_CF_ISA_MASK)
795 case EF_M68K_CF_ISA_A_NODIV:
797 additional = " [nodiv]";
799 case EF_M68K_CF_ISA_A:
802 case EF_M68K_CF_ISA_A_PLUS:
805 case EF_M68K_CF_ISA_B_NOUSP:
807 additional = " [nousp]";
809 case EF_M68K_CF_ISA_B:
812 case EF_M68K_CF_ISA_C:
815 case EF_M68K_CF_ISA_C_NODIV:
817 additional = " [nodiv]";
820 fprintf (file, " [isa %s]%s", isa, additional);
822 if (eflags & EF_M68K_CF_FLOAT)
823 fprintf (file, " [float]");
825 switch (eflags & EF_M68K_CF_MAC_MASK)
833 case EF_M68K_CF_EMAC:
838 fprintf (file, " [%s]", mac);
847 /* Multi-GOT support implementation design:
849 Multi-GOT starts in check_relocs hook. There we scan all
850 relocations of a BFD and build a local GOT (struct elf_m68k_got)
851 for it. If a single BFD appears to require too many GOT slots with
852 R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
854 After check_relocs has been invoked for each input BFD, we have
855 constructed a GOT for each input BFD.
857 To minimize total number of GOTs required for a particular output BFD
858 (as some environments support only 1 GOT per output object) we try
859 to merge some of the GOTs to share an offset space. Ideally [and in most
860 cases] we end up with a single GOT. In cases when there are too many
861 restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
862 several GOTs, assuming the environment can handle them.
864 Partitioning is done in elf_m68k_partition_multi_got. We start with
865 an empty GOT and traverse bfd2got hashtable putting got_entries from
866 local GOTs to the new 'big' one. We do that by constructing an
867 intermediate GOT holding all the entries the local GOT has and the big
868 GOT lacks. Then we check if there is room in the big GOT to accomodate
869 all the entries from diff. On success we add those entries to the big
870 GOT; on failure we start the new 'big' GOT and retry the adding of
871 entries from the local GOT. Note that this retry will always succeed as
872 each local GOT doesn't overflow the limits. After partitioning we
873 end up with each bfd assigned one of the big GOTs. GOT entries in the
874 big GOTs are initialized with GOT offsets. Note that big GOTs are
875 positioned consequently in program space and represent a single huge GOT
876 to the outside world.
878 After that we get to elf_m68k_relocate_section. There we
879 adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
880 relocations to refer to appropriate [assigned to current input_bfd]
885 GOT entry type: We have 3 types of GOT entries.
886 * R_68K_GOT8O type is used in entries for symbols that have
887 at least one R_68K_GOT8O relocation. We can have at most 0x40
888 such entries in one GOT.
889 * R_68K_GOT16O type is used in entries for symbols that have
890 at least one R_68K_GOT16O relocation and no R_68K_GOT8O relocations.
891 We can have at most 0x4000 such entries in one GOT.
892 * R_68K_GOT32O type is used in all other cases. We can have as many
893 such entries in one GOT as we like.
894 When counting relocations we have to include the count of the smaller
895 ranged relocations in the counts of the larger ranged ones in order
896 to correctly detect overflow.
898 Sorting the GOT: In each GOT starting offsets are assigned to
899 R_68K_GOT8O entries, which are followed by R_68K_GOT16O entries, and
900 R_68K_GOT32O entries go at the end. See finalize_got_offsets for details.
902 Negative GOT offsets: To double usable offset range of GOTs we use
903 negative offsets. As we assign entries with GOT offsets relative to
904 start of .got section, the offset values are positive. They become
905 negative only in relocate_section where got->offset value is
906 subtracted from them.
908 3 special GOT entries: There are 3 special GOT entries used internally
909 by loader. These entries happen to be placed to .got.plt section,
910 so we don't do anything about them in multi-GOT support.
912 Memory management: All data except for hashtables
913 multi_got->bfd2got and got->entries are allocated on
914 elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
915 to most functions), so we don't need to care to free them. At the
916 moment of allocation hashtables are being linked into main data
917 structure (multi_got), all pieces of which are reachable from
918 elf_m68k_multi_got (info). We deallocate them in
919 elf_m68k_link_hash_table_free. */
921 /* Initialize GOT. */
924 elf_m68k_init_got (struct elf_m68k_got *got,
926 bfd_vma rel_8o_n_entries,
927 bfd_vma rel_8o_16o_n_entries,
928 bfd_vma local_n_entries,
931 got->entries = entries;
932 got->rel_8o_n_entries = rel_8o_n_entries;
933 got->rel_8o_16o_n_entries = rel_8o_16o_n_entries;
934 got->local_n_entries = local_n_entries;
935 got->offset = offset;
941 elf_m68k_clear_got (struct elf_m68k_got *got)
943 if (got->entries != NULL)
945 htab_delete (got->entries);
950 /* Create and empty GOT structure. INFO is the context where memory
951 should be allocated. */
953 static struct elf_m68k_got *
954 elf_m68k_create_empty_got (struct bfd_link_info *info)
956 struct elf_m68k_got *got;
958 got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
962 elf_m68k_init_got (got, NULL, 0, 0, 0, (bfd_vma) -1);
967 /* Initialize KEY. */
970 elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
971 struct elf_link_hash_entry *h,
972 const bfd *abfd, unsigned long symndx)
977 key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
978 BFD_ASSERT (key->symndx != 0);
983 key->symndx = symndx;
987 /* Calculate hash of got_entry.
991 elf_m68k_got_entry_hash (const void *_entry)
993 const struct elf_m68k_got_entry_key *key;
995 key = &((const struct elf_m68k_got_entry *) _entry)->key_;
997 return key->symndx + (key->bfd != NULL
1002 /* Check if two got entries are equal. */
1005 elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
1007 const struct elf_m68k_got_entry_key *key1;
1008 const struct elf_m68k_got_entry_key *key2;
1010 key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
1011 key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
1013 return (key1->bfd == key2->bfd
1014 && key1->symndx == key2->symndx);
1017 /* Maximal number of R_68K_GOT8O entries in a single GOT. */
1018 #define ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT(INFO) \
1019 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1023 /* Maximal number of R_68K_GOT8O and R_68K_GOT16O entries in a single GOT. */
1024 #define ELF_M68K_REL_8O_16O_MAX_N_ENTRIES_IN_GOT(INFO) \
1025 (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p \
1029 /* SEARCH - simply search the hashtable, don't insert new entries or fail when
1030 the entry cannot be found.
1031 FIND_OR_CREATE - search for an existing entry, but create new if there's
1033 MUST_FIND - search for an existing entry and assert that it exist.
1034 MUST_CREATE - assert that there's no such entry and create new one. */
1035 enum elf_m68k_get_entry_howto
1043 /* Get or create (depending on HOWTO) entry with KEY in GOT.
1044 INFO is context in which memory should be allocated (can be NULL if
1045 HOWTO is SEARCH or MUST_FIND). */
1047 static struct elf_m68k_got_entry *
1048 elf_m68k_get_got_entry (struct elf_m68k_got *got,
1049 const struct elf_m68k_got_entry_key *key,
1050 enum elf_m68k_get_entry_howto howto,
1051 struct bfd_link_info *info)
1053 struct elf_m68k_got_entry entry_;
1054 struct elf_m68k_got_entry *entry;
1057 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1059 if (got->entries == NULL)
1060 /* This is the first entry in ABFD. Initialize hashtable. */
1062 if (howto == SEARCH)
1065 got->entries = htab_try_create (ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT
1067 elf_m68k_got_entry_hash,
1068 elf_m68k_got_entry_eq, NULL);
1069 if (got->entries == NULL)
1071 bfd_set_error (bfd_error_no_memory);
1077 ptr = htab_find_slot (got->entries, &entry_, (howto != SEARCH
1078 ? INSERT : NO_INSERT));
1081 if (howto == SEARCH)
1082 /* Entry not found. */
1085 /* We're out of memory. */
1086 bfd_set_error (bfd_error_no_memory);
1091 /* We didn't find the entry and we're asked to create a new one. */
1093 BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1095 entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
1099 /* Initialize new entry. */
1102 entry->u.s1.refcount = 0;
1103 entry->u.s1.type = R_68K_GOT32O;
1108 /* We found the entry. */
1110 BFD_ASSERT (howto != MUST_CREATE);
1118 /* Update GOT counters when merging entry of WAS type with entry of NEW type.
1119 Return the value to which ENTRY's type should be set. */
1122 elf_m68k_update_got_entry_type (struct elf_m68k_got *got, int was, int new)
1124 if (new == R_68K_GOT8O && was != R_68K_GOT8O)
1125 /* NEW overrides WAS. */
1127 ++got->rel_8o_n_entries;
1129 if (was != R_68K_GOT16O)
1130 /* Update this counter too. */
1131 ++got->rel_8o_16o_n_entries;
1133 else if (new == R_68K_GOT16O && was != R_68K_GOT8O && was != R_68K_GOT16O)
1134 /* NEW overrides WAS. */
1135 ++got->rel_8o_16o_n_entries;
1137 /* NEW doesn't override WAS. */
1143 /* Update GOT counters when removing an entry of type TYPE. */
1146 elf_m68k_remove_got_entry_type (struct elf_m68k_got *got, int type)
1151 BFD_ASSERT (got->rel_8o_n_entries > 0);
1153 --got->rel_8o_n_entries;
1157 BFD_ASSERT (got->rel_8o_16o_n_entries >= got->rel_8o_n_entries);
1159 --got->rel_8o_16o_n_entries;
1170 /* Add new or update existing entry to GOT.
1171 H, ABFD, TYPE and SYMNDX is data for the entry.
1172 INFO is a context where memory should be allocated. */
1174 static struct elf_m68k_got_entry *
1175 elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
1176 struct elf_link_hash_entry *h,
1178 int type, unsigned long symndx,
1179 struct bfd_link_info *info)
1181 struct elf_m68k_got_entry_key key_;
1182 struct elf_m68k_got_entry *entry;
1184 if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
1185 elf_m68k_hash_entry (h)->got_entry_key
1186 = elf_m68k_multi_got (info)->global_symndx++;
1188 elf_m68k_init_got_entry_key (&key_, h, abfd, symndx);
1190 entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
1194 /* Update refcount. */
1195 ++entry->u.s1.refcount;
1197 if (entry->u.s1.refcount == 1)
1198 /* We see this entry for the first time. */
1200 if (entry->key_.bfd != NULL)
1201 ++got->local_n_entries;
1204 /* Determine entry's type and update got->rel_*_n_entries counters. */
1205 entry->u.s1.type = elf_m68k_update_got_entry_type (got, entry->u.s1.type,
1208 if ((got->rel_8o_n_entries
1209 > ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT (info))
1210 || (got->rel_8o_16o_n_entries
1211 > ELF_M68K_REL_8O_16O_MAX_N_ENTRIES_IN_GOT (info)))
1212 /* This BFD has too many relocation. */
1214 if (got->rel_8o_n_entries
1215 > ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT (info))
1216 (*_bfd_error_handler) (_("%B: GOT overflow: "
1217 "Number of R_68K_GOT8O relocations > %d"),
1219 ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT (info));
1221 (*_bfd_error_handler) (_("%B: GOT overflow: "
1222 "Number of R_68K_GOT8O and R_68K_GOT16O "
1223 "relocations > %d"),
1225 ELF_M68K_REL_8O_16O_MAX_N_ENTRIES_IN_GOT (info));
1233 /* Compute the hash value of the bfd in a bfd2got hash entry. */
1236 elf_m68k_bfd2got_entry_hash (const void *entry)
1238 const struct elf_m68k_bfd2got_entry *e;
1240 e = (const struct elf_m68k_bfd2got_entry *) entry;
1245 /* Check whether two hash entries have the same bfd. */
1248 elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
1250 const struct elf_m68k_bfd2got_entry *e1;
1251 const struct elf_m68k_bfd2got_entry *e2;
1253 e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
1254 e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
1256 return e1->bfd == e2->bfd;
1259 /* Destruct a bfd2got entry. */
1262 elf_m68k_bfd2got_entry_del (void *_entry)
1264 struct elf_m68k_bfd2got_entry *entry;
1266 entry = (struct elf_m68k_bfd2got_entry *) _entry;
1268 BFD_ASSERT (entry->got != NULL);
1269 elf_m68k_clear_got (entry->got);
1272 /* Find existing or create new (depending on HOWTO) bfd2got entry in
1273 MULTI_GOT. ABFD is the bfd we need a GOT for. INFO is a context where
1274 memory should be allocated. */
1276 static struct elf_m68k_bfd2got_entry *
1277 elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
1279 enum elf_m68k_get_entry_howto howto,
1280 struct bfd_link_info *info)
1282 struct elf_m68k_bfd2got_entry entry_;
1284 struct elf_m68k_bfd2got_entry *entry;
1286 BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1288 if (multi_got->bfd2got == NULL)
1289 /* This is the first GOT. Initialize bfd2got. */
1291 if (howto == SEARCH)
1294 multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
1295 elf_m68k_bfd2got_entry_eq,
1296 elf_m68k_bfd2got_entry_del);
1297 if (multi_got->bfd2got == NULL)
1299 bfd_set_error (bfd_error_no_memory);
1305 ptr = htab_find_slot (multi_got->bfd2got, &entry_, (howto != SEARCH
1306 ? INSERT : NO_INSERT));
1309 if (howto == SEARCH)
1310 /* Entry not found. */
1313 /* We're out of memory. */
1314 bfd_set_error (bfd_error_no_memory);
1319 /* Entry was not found. Create new one. */
1321 BFD_ASSERT (howto != MUST_FIND && howto != SEARCH);
1323 entry = ((struct elf_m68k_bfd2got_entry *)
1324 bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
1330 entry->got = elf_m68k_create_empty_got (info);
1331 if (entry->got == NULL)
1338 BFD_ASSERT (howto != MUST_CREATE);
1340 /* Return existing entry. */
1347 struct elf_m68k_can_merge_gots_arg
1349 /* A current_got that we constructing a DIFF against. */
1350 struct elf_m68k_got *big;
1352 /* GOT holding entries not present or that should be changed in
1354 struct elf_m68k_got *diff;
1356 /* Context where to allocate memory. */
1357 struct bfd_link_info *info;
1360 bfd_boolean error_p;
1363 /* Process a single entry from the small GOT to see if it should be added
1364 or updated in the big GOT. */
1367 elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
1369 const struct elf_m68k_got_entry *entry1;
1370 struct elf_m68k_can_merge_gots_arg *arg;
1371 const struct elf_m68k_got_entry *entry2;
1374 entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
1375 arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
1377 entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
1381 type = elf_m68k_update_got_entry_type (arg->diff, entry2->u.s1.type,
1384 if (type == entry2->u.s1.type)
1385 /* ENTRY1 doesn't update data in ENTRY2. Skip it.
1386 To skip creation of difference entry we use the type,
1387 which we won't see in GOT entries for sure. */
1392 BFD_ASSERT (entry1->u.s1.type != R_68K_32);
1394 type = elf_m68k_update_got_entry_type (arg->diff, R_68K_GOT32O,
1397 /* Update local counter. */
1398 if (entry1->key_.bfd != NULL)
1399 ++arg->diff->local_n_entries;
1402 if (type != R_68K_32)
1403 /* Create an entry in DIFF. */
1405 struct elf_m68k_got_entry *entry;
1407 entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
1411 arg->error_p = TRUE;
1415 entry->u.s1.type = type;
1421 /* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1422 Construct DIFF GOT holding the entries which should be added or updated
1423 in BIG GOT to accumulate information from SMALL.
1424 INFO is the context where memory should be allocated. */
1427 elf_m68k_can_merge_gots (struct elf_m68k_got *big,
1428 const struct elf_m68k_got *small,
1429 struct bfd_link_info *info,
1430 struct elf_m68k_got *diff)
1432 struct elf_m68k_can_merge_gots_arg arg_;
1434 BFD_ASSERT (small->offset == (bfd_vma) -1);
1439 arg_.error_p = FALSE;
1440 htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
1447 /* Check for overflow. */
1448 if ((big->rel_8o_n_entries + arg_.diff->rel_8o_n_entries
1449 > ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT (info))
1450 || (big->rel_8o_16o_n_entries + arg_.diff->rel_8o_16o_n_entries
1451 > ELF_M68K_REL_8O_16O_MAX_N_ENTRIES_IN_GOT (info)))
1457 struct elf_m68k_merge_gots_arg
1460 struct elf_m68k_got *big;
1462 /* Context where memory should be allocated. */
1463 struct bfd_link_info *info;
1466 bfd_boolean error_p;
1469 /* Process a single entry from DIFF got. Add or update corresponding
1470 entry in the BIG got. */
1473 elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
1475 const struct elf_m68k_got_entry *from;
1476 struct elf_m68k_merge_gots_arg *arg;
1477 struct elf_m68k_got_entry *to;
1479 from = (const struct elf_m68k_got_entry *) *entry_ptr;
1480 arg = (struct elf_m68k_merge_gots_arg *) _arg;
1482 to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
1486 arg->error_p = TRUE;
1490 BFD_ASSERT (to->u.s1.refcount == 0);
1491 /* All we need to merge is TYPE. */
1492 to->u.s1.type = from->u.s1.type;
1497 /* Merge data from DIFF to BIG. INFO is context where memory should be
1501 elf_m68k_merge_gots (struct elf_m68k_got *big,
1502 struct elf_m68k_got *diff,
1503 struct bfd_link_info *info)
1505 if (diff->entries != NULL)
1506 /* DIFF is not empty. Merge it into BIG GOT. */
1508 struct elf_m68k_merge_gots_arg arg_;
1510 /* Merge entries. */
1513 arg_.error_p = FALSE;
1514 htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
1518 /* Merge counters. */
1519 big->rel_8o_n_entries += diff->rel_8o_n_entries;
1520 big->rel_8o_16o_n_entries += diff->rel_8o_16o_n_entries;
1521 big->local_n_entries += diff->local_n_entries;
1524 /* DIFF is empty. */
1526 BFD_ASSERT (diff->rel_8o_n_entries == 0);
1527 BFD_ASSERT (diff->rel_8o_16o_n_entries == 0);
1528 BFD_ASSERT (diff->local_n_entries == 0);
1531 BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
1532 || ((big->rel_8o_n_entries
1533 <= ELF_M68K_REL_8O_MAX_N_ENTRIES_IN_GOT (info))
1534 && (big->rel_8o_16o_n_entries
1535 <= ELF_M68K_REL_8O_16O_MAX_N_ENTRIES_IN_GOT (info))));
1540 struct elf_m68k_finalize_got_offsets_arg
1542 /* Offset for the next R_68K_GOT8O entry. */
1543 bfd_vma rel_8o_offset;
1545 /* Offset for the next R_68K_GOT16O entry. */
1546 bfd_vma rel_16o_offset;
1548 /* Offset for the next R_68K_GOT32O entry. */
1549 bfd_vma rel_32o_offset;
1551 /* Should we use negative (relative to GP) offsets for GOT entries. */
1552 bfd_boolean use_neg_got_offsets_p;
1554 /* Offset of this GOT relative to .got section. */
1557 /* Mapping from global symndx to global symbols.
1558 This is used to build lists of got entries for global symbols. */
1559 struct elf_m68k_link_hash_entry **symndx2h;
1562 /* Assign ENTRY an offset. Build list of GOT entries for global symbols
1566 elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
1568 struct elf_m68k_got_entry *entry;
1569 struct elf_m68k_finalize_got_offsets_arg *arg;
1571 entry = (struct elf_m68k_got_entry *) *entry_ptr;
1572 arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
1574 /* This should be a fresh entry created in elf_m68k_can_merge_gots. */
1575 BFD_ASSERT (entry->u.s1.refcount == 0);
1577 switch (entry->u.s1.type)
1580 entry->u.s2.offset = arg->rel_8o_offset;
1582 if (arg->use_neg_got_offsets_p)
1584 if (arg->rel_8o_offset >= arg->got_offset)
1585 /* We've assigned a positive offset to this entry,
1586 next entry should get (-abs(offset) - 4). */
1587 arg->rel_8o_offset = (arg->got_offset
1588 - (arg->rel_8o_offset - arg->got_offset)
1591 /* We've assigned a negative offset to this entry,
1592 next entry should get (+abs(offset) + 0). */
1593 arg->rel_8o_offset = (arg->got_offset
1594 + (arg->got_offset - arg->rel_8o_offset));
1597 /* Next entry will simply get next offset. */
1598 arg->rel_8o_offset += 4;
1603 entry->u.s2.offset = arg->rel_16o_offset;
1605 if (arg->use_neg_got_offsets_p)
1607 if (arg->rel_16o_offset >= arg->got_offset)
1608 /* We've assigned a positive offset to this entry,
1609 next entry should get (-abs(offset) - 4). */
1610 arg->rel_16o_offset = (arg->got_offset
1611 - (arg->rel_16o_offset - arg->got_offset)
1614 /* We've assigned a negative offset to this entry,
1615 next entry should get (+abs(offset) + 0). */
1616 arg->rel_16o_offset = (arg->got_offset
1617 + (arg->got_offset - arg->rel_16o_offset));
1620 /* Next entry will simply get next offset. */
1621 arg->rel_16o_offset += 4;
1626 entry->u.s2.offset = arg->rel_32o_offset;
1628 if (arg->use_neg_got_offsets_p)
1630 if (arg->rel_32o_offset >= arg->got_offset)
1631 /* We've assigned a positive offset to this entry,
1632 next entry should get (-abs(offset) - 4). */
1633 arg->rel_32o_offset = (arg->got_offset
1634 - (arg->rel_32o_offset - arg->got_offset)
1637 /* We've assigned a negative offset to this entry,
1638 next entry should get (+abs(offset) + 0). */
1639 arg->rel_32o_offset = (arg->got_offset
1640 + (arg->got_offset - arg->rel_32o_offset));
1643 /* Next entry will simply get next offset. */
1644 arg->rel_32o_offset += 4;
1653 if (entry->key_.bfd == NULL)
1654 /* Hook up this entry into the list of got_entries of H. */
1656 struct elf_m68k_link_hash_entry *h;
1658 BFD_ASSERT (entry->key_.symndx != 0);
1659 h = arg->symndx2h[entry->key_.symndx];
1660 BFD_ASSERT (h != NULL);
1662 entry->u.s2.next = h->glist;
1666 /* This entry is for local symbol. */
1667 entry->u.s2.next = NULL;
1672 /* Assign offsets within GOT. USE_NEG_GOT_OFFSETS_P indicates if we
1673 should use negative offsets.
1674 Build list of GOT entries for global symbols along the way.
1675 SYMNDX2H is mapping from global symbol indices to actual
1679 elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
1680 bfd_boolean use_neg_got_offsets_p,
1681 struct elf_m68k_link_hash_entry **symndx2h)
1683 struct elf_m68k_finalize_got_offsets_arg arg_;
1685 BFD_ASSERT (got->offset != (bfd_vma) -1);
1687 /* We set entry offsets relative to the .got section (and not the
1688 start of a particular GOT), so that we can use them in
1689 finish_dynamic_symbol without needing to know the GOT they come
1692 if (use_neg_got_offsets_p)
1696 /* Put GOT pointer in the middle of GOT. */
1697 n = htab_elements (got->entries);
1699 /* Even number of GOT entries. */
1700 got->offset += 2 * n;
1702 /* Odd number of GOT entries. */
1703 got->offset += 2 * (n - 1);
1705 /* R_68K_GOT8O entries shall start at GOT offset. */
1706 arg_.rel_8o_offset = got->offset;
1708 n = got->rel_8o_n_entries;
1710 /* Even number of R_68K_GOT8O entries.
1711 The last R_68K_GOT8O entry will be at
1712 (got->offset - 2 * n). Hence the first R_68K_GOT16O
1713 entry will be at offset ... */
1714 arg_.rel_16o_offset = got->offset + 2 * n;
1716 /* Odd number of R_68K_GOT8O entries.
1717 The last R_68K_GOT8O entry will be at
1718 (got->offset + 2 * (n - 1)). Hence the first R_68K_GOT16O
1719 entry will be at offset ... */
1720 arg_.rel_16o_offset = got->offset - 2 * (n - 1) - 4;
1722 n = got->rel_8o_16o_n_entries;
1724 /* Even number of R_68K_GOT8O and R_68K_GOT16O entries.
1725 The last R_68K_GOT8O entry will be at
1726 (got->offset - 2 * n). Hence the first R_68K_GOT32O
1727 entry will be at offset ... */
1728 arg_.rel_32o_offset = got->offset + 2 * n;
1730 /* Odd number of R_68K_GOT8O and R_68K_GOT16O entries.
1731 The last R_68K_GOT16O entry will be at
1732 (got->offset + 2 * (n - 1)). Hence the first R_68K_GOT32O
1733 entry will be at offset ... */
1734 arg_.rel_32o_offset = got->offset - 2 * (n - 1) - 4;
1736 arg_.use_neg_got_offsets_p = TRUE;
1738 arg_.got_offset = got->offset;
1742 arg_.rel_8o_offset = got->offset;
1743 arg_.rel_16o_offset = 4 * got->rel_8o_n_entries + got->offset;
1744 arg_.rel_32o_offset = 4 * got->rel_8o_16o_n_entries + got->offset;
1746 arg_.use_neg_got_offsets_p = FALSE;
1748 /* This shouldn't be used. */
1749 arg_.got_offset = (bfd_vma) -1;
1752 arg_.symndx2h = symndx2h;
1754 htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
1756 /* Calculate offset ranges we have actually assigned. */
1757 if (use_neg_got_offsets_p)
1759 if (arg_.rel_8o_offset == (bfd_vma) -4
1760 || arg_.rel_8o_offset < got->offset)
1761 arg_.rel_8o_offset = 2 * (got->offset - arg_.rel_8o_offset) - 4;
1763 arg_.rel_8o_offset = 2 * (arg_.rel_8o_offset - got->offset);
1765 if (arg_.rel_16o_offset == (bfd_vma) -4
1766 || arg_.rel_16o_offset < got->offset)
1767 arg_.rel_16o_offset = 2 * (got->offset - arg_.rel_16o_offset) - 4;
1769 arg_.rel_16o_offset = 2 * (arg_.rel_16o_offset - got->offset);
1771 if (arg_.rel_32o_offset == (bfd_vma) -4
1772 || arg_.rel_32o_offset < got->offset)
1773 arg_.rel_32o_offset = 2 * (got->offset - arg_.rel_32o_offset) - 4;
1775 arg_.rel_32o_offset = 2 * (arg_.rel_32o_offset - got->offset);
1779 arg_.rel_8o_offset -= got->offset;
1780 arg_.rel_16o_offset -= got->offset;
1781 arg_.rel_32o_offset -= got->offset;
1784 /* These asserts check that we got counting of entries right. */
1785 BFD_ASSERT (arg_.rel_8o_offset == 4 * got->rel_8o_n_entries);
1786 BFD_ASSERT (arg_.rel_16o_offset == 4 * got->rel_8o_16o_n_entries);
1787 BFD_ASSERT (arg_.rel_32o_offset == 4 * htab_elements (got->entries));
1790 struct elf_m68k_partition_multi_got_arg
1792 /* The GOT we are adding entries to. Aka big got. */
1793 struct elf_m68k_got *current_got;
1795 /* Offset to assign the next CURRENT_GOT. */
1798 /* Context where memory should be allocated. */
1799 struct bfd_link_info *info;
1801 /* Total number of entries in the .got section.
1802 This is used to calculate size of the .got and .rela.got sections. */
1805 /* Total number of local entries in the .got section.
1806 This is used to calculate size of the .rela.got section. */
1807 bfd_vma local_n_entries;
1810 bfd_boolean error_p;
1812 /* Mapping from global symndx to global symbols.
1813 This is used to build lists of got entries for global symbols. */
1814 struct elf_m68k_link_hash_entry **symndx2h;
1817 /* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
1818 or start a new CURRENT_GOT. */
1821 elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
1823 struct elf_m68k_bfd2got_entry *entry;
1824 struct elf_m68k_partition_multi_got_arg *arg;
1825 struct elf_m68k_got *got;
1826 struct elf_m68k_got *current_got;
1827 struct elf_m68k_got diff_;
1828 struct elf_m68k_got *diff;
1830 entry = (struct elf_m68k_bfd2got_entry *) *_entry;
1831 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
1834 BFD_ASSERT (got != NULL);
1835 BFD_ASSERT (got->offset == (bfd_vma) -1);
1839 if (arg->current_got != NULL)
1840 /* Construct diff. */
1843 elf_m68k_init_got (diff, NULL, 0, 0, 0, (bfd_vma) -1);
1845 if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
1847 if (diff->offset == 0)
1848 /* Offset set to 0 in the diff_ indicates an error. */
1850 arg->error_p = TRUE;
1854 if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
1856 elf_m68k_clear_got (diff);
1857 /* Schedule to finish up CURRENT_GOT and start new one. */
1861 Merge GOTs no matter what. If big GOT overflows,
1862 we'll fail in relocate_section due to truncated relocations.
1864 ??? May be fail earlier? E.g., in can_merge_gots. */
1868 /* Diff of got against empty current_got is got itself. */
1870 /* Create empty CURRENT_GOT to subsequent GOTs to. */
1871 arg->current_got = elf_m68k_create_empty_got (arg->info);
1872 if (arg->current_got == NULL)
1874 arg->error_p = TRUE;
1878 arg->current_got->offset = arg->offset;
1883 current_got = arg->current_got;
1887 if (!elf_m68k_merge_gots (current_got, diff, arg->info))
1889 arg->error_p = TRUE;
1893 /* Now we can free GOT. */
1894 elf_m68k_clear_got (got);
1896 entry->got = current_got;
1900 /* Schedule to start a new current_got. */
1901 arg->current_got = NULL;
1902 arg->offset = (current_got->offset
1903 + 4 * htab_elements (current_got->entries));
1905 /* Finish up current_got. */
1907 elf_m68k_finalize_got_offsets (current_got,
1908 elf_m68k_hash_table (arg->info)
1909 ->use_neg_got_offsets_p,
1912 arg->n_entries += htab_elements (current_got->entries);
1913 arg->local_n_entries += current_got->local_n_entries;
1915 BFD_ASSERT (arg->local_n_entries <= arg->n_entries);
1919 if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
1921 BFD_ASSERT (arg->error_p);
1928 elf_m68k_clear_got (diff);
1930 return arg->error_p == FALSE ? 1 : 0;
1933 /* Helper function to build symndx2h mapping. */
1936 elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
1939 struct elf_m68k_link_hash_entry *h;
1941 h = elf_m68k_hash_entry (_h);
1943 if (h->got_entry_key != 0)
1944 /* H has at least one entry in the GOT. */
1946 struct elf_m68k_partition_multi_got_arg *arg;
1948 arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
1950 BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
1951 arg->symndx2h[h->got_entry_key] = h;
1957 /* Merge GOTs of some BFDs, assign offsets to GOT entries and build
1958 lists of GOT entries for global symbols.
1959 Calculate sizes of .got and .rela.got sections. */
1962 elf_m68k_partition_multi_got (struct bfd_link_info *info)
1964 struct elf_m68k_multi_got *multi_got;
1965 struct elf_m68k_partition_multi_got_arg arg_;
1967 multi_got = elf_m68k_multi_got (info);
1969 arg_.current_got = NULL;
1973 arg_.local_n_entries = 0;
1974 arg_.error_p = FALSE;
1976 if (multi_got->bfd2got != NULL)
1978 /* Initialize symndx2h mapping. */
1980 arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
1981 * sizeof (*arg_.symndx2h));
1982 if (arg_.symndx2h == NULL)
1985 elf_link_hash_traverse (elf_hash_table (info),
1986 elf_m68k_init_symndx2h_1, &arg_);
1990 htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
1994 free (arg_.symndx2h);
1995 arg_.symndx2h = NULL;
2000 /* Finish up last current_got. */
2002 elf_m68k_finalize_got_offsets (arg_.current_got,
2003 elf_m68k_hash_table (info)
2004 ->use_neg_got_offsets_p, arg_.symndx2h);
2006 arg_.n_entries += htab_elements (arg_.current_got->entries);
2007 arg_.local_n_entries += arg_.current_got->local_n_entries;
2009 BFD_ASSERT (arg_.local_n_entries <= arg_.n_entries);
2012 free (arg_.symndx2h);
2015 if (elf_hash_table (info)->dynobj != NULL)
2016 /* Set sizes of .got and .rela.got sections. */
2020 s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".got");
2022 s->size = arg_.n_entries * 4;
2024 BFD_ASSERT (arg_.n_entries == 0);
2026 /* If we are generating a shared object, we need to
2027 output a R_68K_RELATIVE reloc so that the dynamic
2028 linker can adjust this GOT entry. Overwise we
2029 don't need space in .rela.got for local symbols. */
2032 BFD_ASSERT (arg_.local_n_entries <= arg_.n_entries);
2033 arg_.n_entries -= arg_.local_n_entries;
2036 s = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".rela.got");
2038 s->size = arg_.n_entries * sizeof (Elf32_External_Rela);
2040 BFD_ASSERT (arg_.n_entries == 0);
2043 BFD_ASSERT (multi_got->bfd2got == NULL);
2048 /* Specialized version of elf_m68k_get_got_entry that returns pointer
2049 to hashtable slot, thus allowing removal of entry via
2050 elf_m68k_remove_got_entry. */
2052 static struct elf_m68k_got_entry **
2053 elf_m68k_find_got_entry_ptr (struct elf_m68k_got *got,
2054 struct elf_m68k_got_entry_key *key)
2057 struct elf_m68k_got_entry entry_;
2058 struct elf_m68k_got_entry **entry_ptr;
2061 ptr = htab_find_slot (got->entries, &entry_, NO_INSERT);
2062 BFD_ASSERT (ptr != NULL);
2064 entry_ptr = (struct elf_m68k_got_entry **) ptr;
2069 /* Remove entry pointed to by ENTRY_PTR from GOT. */
2072 elf_m68k_remove_got_entry (struct elf_m68k_got *got,
2073 struct elf_m68k_got_entry **entry_ptr)
2075 struct elf_m68k_got_entry *entry;
2079 /* Check that offsets have not been finalized yet. */
2080 BFD_ASSERT (got->offset == (bfd_vma) -1);
2081 /* Check that this entry is indeed unused. */
2082 BFD_ASSERT (entry->u.s1.refcount == 0);
2084 elf_m68k_remove_got_entry_type (got, entry->u.s1.type);
2086 if (entry->key_.bfd != NULL)
2087 --got->local_n_entries;
2089 htab_clear_slot (got->entries, (void **) entry_ptr);
2092 /* Copy any information related to dynamic linking from a pre-existing
2093 symbol to a newly created symbol. Also called to copy flags and
2094 other back-end info to a weakdef, in which case the symbol is not
2095 newly created and plt/got refcounts and dynamic indices should not
2099 elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
2100 struct elf_link_hash_entry *_dir,
2101 struct elf_link_hash_entry *_ind)
2103 struct elf_m68k_link_hash_entry *dir;
2104 struct elf_m68k_link_hash_entry *ind;
2106 _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
2108 if (_ind->root.type != bfd_link_hash_indirect)
2111 dir = elf_m68k_hash_entry (_dir);
2112 ind = elf_m68k_hash_entry (_ind);
2114 /* We might have a direct symbol already having entries in the GOTs.
2115 Update its key only in case indirect symbol has GOT entries and
2116 assert that both indirect and direct symbols don't have GOT entries
2117 at the same time. */
2118 if (ind->got_entry_key != 0)
2120 BFD_ASSERT (dir->got_entry_key == 0);
2121 /* Assert that GOTs aren't partioned yet. */
2122 BFD_ASSERT (ind->glist == NULL);
2124 dir->got_entry_key = ind->got_entry_key;
2125 ind->got_entry_key = 0;
2129 /* Look through the relocs for a section during the first phase, and
2130 allocate space in the global offset table or procedure linkage
2134 elf_m68k_check_relocs (abfd, info, sec, relocs)
2136 struct bfd_link_info *info;
2138 const Elf_Internal_Rela *relocs;
2141 Elf_Internal_Shdr *symtab_hdr;
2142 struct elf_link_hash_entry **sym_hashes;
2143 const Elf_Internal_Rela *rel;
2144 const Elf_Internal_Rela *rel_end;
2148 struct elf_m68k_got *got;
2150 if (info->relocatable)
2153 dynobj = elf_hash_table (info)->dynobj;
2154 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2155 sym_hashes = elf_sym_hashes (abfd);
2163 rel_end = relocs + sec->reloc_count;
2164 for (rel = relocs; rel < rel_end; rel++)
2166 unsigned long r_symndx;
2167 struct elf_link_hash_entry *h;
2169 r_symndx = ELF32_R_SYM (rel->r_info);
2171 if (r_symndx < symtab_hdr->sh_info)
2175 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2176 while (h->root.type == bfd_link_hash_indirect
2177 || h->root.type == bfd_link_hash_warning)
2178 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2181 switch (ELF32_R_TYPE (rel->r_info))
2187 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2193 /* This symbol requires a global offset table entry. */
2197 /* Create the .got section. */
2198 elf_hash_table (info)->dynobj = dynobj = abfd;
2199 if (!_bfd_elf_create_got_section (dynobj, info))
2205 sgot = bfd_get_section_by_name (dynobj, ".got");
2206 BFD_ASSERT (sgot != NULL);
2210 && (h != NULL || info->shared))
2212 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2213 if (srelgot == NULL)
2215 srelgot = bfd_make_section_with_flags (dynobj,
2221 | SEC_LINKER_CREATED
2224 || !bfd_set_section_alignment (dynobj, srelgot, 2))
2231 struct elf_m68k_bfd2got_entry *bfd2got_entry;
2234 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2235 abfd, FIND_OR_CREATE, info);
2236 if (bfd2got_entry == NULL)
2239 got = bfd2got_entry->got;
2240 BFD_ASSERT (got != NULL);
2244 struct elf_m68k_got_entry *got_entry;
2246 /* Add entry to got. */
2247 got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
2248 ELF32_R_TYPE (rel->r_info),
2250 if (got_entry == NULL)
2253 if (got_entry->u.s1.refcount == 1)
2255 /* Make sure this symbol is output as a dynamic symbol. */
2258 && !h->forced_local)
2260 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2264 /* Allocate space in the .got section. */
2267 /* Allocate relocation space. */
2270 srelgot->size += sizeof (Elf32_External_Rela);
2279 /* This symbol requires a procedure linkage table entry. We
2280 actually build the entry in adjust_dynamic_symbol,
2281 because this might be a case of linking PIC code which is
2282 never referenced by a dynamic object, in which case we
2283 don't need to generate a procedure linkage table entry
2286 /* If this is a local symbol, we resolve it directly without
2287 creating a procedure linkage table entry. */
2298 /* This symbol requires a procedure linkage table entry. */
2302 /* It does not make sense to have this relocation for a
2303 local symbol. FIXME: does it? How to handle it if
2304 it does make sense? */
2305 bfd_set_error (bfd_error_bad_value);
2309 /* Make sure this symbol is output as a dynamic symbol. */
2310 if (h->dynindx == -1
2311 && !h->forced_local)
2313 if (!bfd_elf_link_record_dynamic_symbol (info, h))
2324 /* If we are creating a shared library and this is not a local
2325 symbol, we need to copy the reloc into the shared library.
2326 However when linking with -Bsymbolic and this is a global
2327 symbol which is defined in an object we are including in the
2328 link (i.e., DEF_REGULAR is set), then we can resolve the
2329 reloc directly. At this point we have not seen all the input
2330 files, so it is possible that DEF_REGULAR is not set now but
2331 will be set later (it is never cleared). We account for that
2332 possibility below by storing information in the
2333 pcrel_relocs_copied field of the hash table entry. */
2335 && (sec->flags & SEC_ALLOC) != 0
2338 || h->root.type == bfd_link_hash_defweak
2339 || !h->def_regular)))
2343 /* Make sure a plt entry is created for this symbol if
2344 it turns out to be a function defined by a dynamic
2356 /* Make sure a plt entry is created for this symbol if it
2357 turns out to be a function defined by a dynamic object. */
2361 /* If we are creating a shared library, we need to copy the
2362 reloc into the shared library. */
2364 && (sec->flags & SEC_ALLOC) != 0)
2366 /* When creating a shared object, we must copy these
2367 reloc types into the output file. We create a reloc
2368 section in dynobj and make room for this reloc. */
2371 sreloc = _bfd_elf_make_dynamic_reloc_section
2372 (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
2378 if (sec->flags & SEC_READONLY
2379 /* Don't set DF_TEXTREL yet for PC relative
2380 relocations, they might be discarded later. */
2381 && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2382 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2383 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
2384 info->flags |= DF_TEXTREL;
2386 sreloc->size += sizeof (Elf32_External_Rela);
2388 /* We count the number of PC relative relocations we have
2389 entered for this symbol, so that we can discard them
2390 again if, in the -Bsymbolic case, the symbol is later
2391 defined by a regular object, or, in the normal shared
2392 case, the symbol is forced to be local. Note that this
2393 function is only called if we are using an m68kelf linker
2394 hash table, which means that h is really a pointer to an
2395 elf_m68k_link_hash_entry. */
2396 if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2397 || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2398 || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
2400 struct elf_m68k_pcrel_relocs_copied *p;
2401 struct elf_m68k_pcrel_relocs_copied **head;
2405 struct elf_m68k_link_hash_entry *eh
2406 = elf_m68k_hash_entry (h);
2407 head = &eh->pcrel_relocs_copied;
2414 s = (bfd_section_from_r_symndx
2415 (abfd, &elf_m68k_hash_table (info)->sym_sec,
2420 vpp = &elf_section_data (s)->local_dynrel;
2421 head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
2424 for (p = *head; p != NULL; p = p->next)
2425 if (p->section == sreloc)
2430 p = ((struct elf_m68k_pcrel_relocs_copied *)
2431 bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
2436 p->section = sreloc;
2446 /* This relocation describes the C++ object vtable hierarchy.
2447 Reconstruct it for later use during GC. */
2448 case R_68K_GNU_VTINHERIT:
2449 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2453 /* This relocation describes which C++ vtable entries are actually
2454 used. Record for later use during GC. */
2455 case R_68K_GNU_VTENTRY:
2456 BFD_ASSERT (h != NULL);
2458 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2470 /* Return the section that should be marked against GC for a given
2474 elf_m68k_gc_mark_hook (asection *sec,
2475 struct bfd_link_info *info,
2476 Elf_Internal_Rela *rel,
2477 struct elf_link_hash_entry *h,
2478 Elf_Internal_Sym *sym)
2481 switch (ELF32_R_TYPE (rel->r_info))
2483 case R_68K_GNU_VTINHERIT:
2484 case R_68K_GNU_VTENTRY:
2488 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2491 /* Update the got entry reference counts for the section being removed. */
2494 elf_m68k_gc_sweep_hook (bfd *abfd,
2495 struct bfd_link_info *info,
2497 const Elf_Internal_Rela *relocs)
2499 Elf_Internal_Shdr *symtab_hdr;
2500 struct elf_link_hash_entry **sym_hashes;
2501 const Elf_Internal_Rela *rel, *relend;
2505 struct elf_m68k_got *got;
2507 if (info->relocatable)
2510 dynobj = elf_hash_table (info)->dynobj;
2514 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2515 sym_hashes = elf_sym_hashes (abfd);
2517 sgot = bfd_get_section_by_name (dynobj, ".got");
2518 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2521 relend = relocs + sec->reloc_count;
2522 for (rel = relocs; rel < relend; rel++)
2524 unsigned long r_symndx;
2525 struct elf_link_hash_entry *h = NULL;
2527 r_symndx = ELF32_R_SYM (rel->r_info);
2528 if (r_symndx >= symtab_hdr->sh_info)
2530 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2531 while (h->root.type == bfd_link_hash_indirect
2532 || h->root.type == bfd_link_hash_warning)
2533 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2536 switch (ELF32_R_TYPE (rel->r_info))
2542 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2551 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2552 abfd, MUST_FIND, NULL)->got;
2553 BFD_ASSERT (got != NULL);
2557 struct elf_m68k_got_entry_key key_;
2558 struct elf_m68k_got_entry **got_entry_ptr;
2559 struct elf_m68k_got_entry *got_entry;
2561 elf_m68k_init_got_entry_key (&key_, h, abfd, r_symndx);
2562 got_entry_ptr = elf_m68k_find_got_entry_ptr (got, &key_);
2564 got_entry = *got_entry_ptr;
2566 if (got_entry->u.s1.refcount > 0)
2568 --got_entry->u.s1.refcount;
2570 if (got_entry->u.s1.refcount == 0)
2571 /* We don't need the .got entry any more. */
2572 elf_m68k_remove_got_entry (got, got_entry_ptr);
2591 if (h->plt.refcount > 0)
2604 /* Return the type of PLT associated with OUTPUT_BFD. */
2606 static const struct elf_m68k_plt_info *
2607 elf_m68k_get_plt_info (bfd *output_bfd)
2609 unsigned int features;
2611 features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
2612 if (features & cpu32)
2613 return &elf_cpu32_plt_info;
2614 if (features & mcfisa_b)
2615 return &elf_isab_plt_info;
2616 if (features & mcfisa_c)
2617 return &elf_isac_plt_info;
2618 return &elf_m68k_plt_info;
2621 /* This function is called after all the input files have been read,
2622 and the input sections have been assigned to output sections.
2623 It's a convenient place to determine the PLT style. */
2626 elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
2628 /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
2630 if (!elf_m68k_partition_multi_got (info))
2633 elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
2637 /* Adjust a symbol defined by a dynamic object and referenced by a
2638 regular object. The current definition is in some section of the
2639 dynamic object, but we're not including those sections. We have to
2640 change the definition to something the rest of the link can
2644 elf_m68k_adjust_dynamic_symbol (info, h)
2645 struct bfd_link_info *info;
2646 struct elf_link_hash_entry *h;
2648 struct elf_m68k_link_hash_table *htab;
2652 htab = elf_m68k_hash_table (info);
2653 dynobj = elf_hash_table (info)->dynobj;
2655 /* Make sure we know what is going on here. */
2656 BFD_ASSERT (dynobj != NULL
2658 || h->u.weakdef != NULL
2661 && !h->def_regular)));
2663 /* If this is a function, put it in the procedure linkage table. We
2664 will fill in the contents of the procedure linkage table later,
2665 when we know the address of the .got section. */
2666 if (h->type == STT_FUNC
2669 if ((h->plt.refcount <= 0
2670 || SYMBOL_CALLS_LOCAL (info, h)
2671 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2672 && h->root.type == bfd_link_hash_undefweak))
2673 /* We must always create the plt entry if it was referenced
2674 by a PLTxxO relocation. In this case we already recorded
2675 it as a dynamic symbol. */
2676 && h->dynindx == -1)
2678 /* This case can occur if we saw a PLTxx reloc in an input
2679 file, but the symbol was never referred to by a dynamic
2680 object, or if all references were garbage collected. In
2681 such a case, we don't actually need to build a procedure
2682 linkage table, and we can just do a PCxx reloc instead. */
2683 h->plt.offset = (bfd_vma) -1;
2688 /* Make sure this symbol is output as a dynamic symbol. */
2689 if (h->dynindx == -1
2690 && !h->forced_local)
2692 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2696 s = bfd_get_section_by_name (dynobj, ".plt");
2697 BFD_ASSERT (s != NULL);
2699 /* If this is the first .plt entry, make room for the special
2702 s->size = htab->plt_info->size;
2704 /* If this symbol is not defined in a regular file, and we are
2705 not generating a shared library, then set the symbol to this
2706 location in the .plt. This is required to make function
2707 pointers compare as equal between the normal executable and
2708 the shared library. */
2712 h->root.u.def.section = s;
2713 h->root.u.def.value = s->size;
2716 h->plt.offset = s->size;
2718 /* Make room for this entry. */
2719 s->size += htab->plt_info->size;
2721 /* We also need to make an entry in the .got.plt section, which
2722 will be placed in the .got section by the linker script. */
2723 s = bfd_get_section_by_name (dynobj, ".got.plt");
2724 BFD_ASSERT (s != NULL);
2727 /* We also need to make an entry in the .rela.plt section. */
2728 s = bfd_get_section_by_name (dynobj, ".rela.plt");
2729 BFD_ASSERT (s != NULL);
2730 s->size += sizeof (Elf32_External_Rela);
2735 /* Reinitialize the plt offset now that it is not used as a reference
2737 h->plt.offset = (bfd_vma) -1;
2739 /* If this is a weak symbol, and there is a real definition, the
2740 processor independent code will have arranged for us to see the
2741 real definition first, and we can just use the same value. */
2742 if (h->u.weakdef != NULL)
2744 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2745 || h->u.weakdef->root.type == bfd_link_hash_defweak);
2746 h->root.u.def.section = h->u.weakdef->root.u.def.section;
2747 h->root.u.def.value = h->u.weakdef->root.u.def.value;
2751 /* This is a reference to a symbol defined by a dynamic object which
2752 is not a function. */
2754 /* If we are creating a shared library, we must presume that the
2755 only references to the symbol are via the global offset table.
2756 For such cases we need not do anything here; the relocations will
2757 be handled correctly by relocate_section. */
2763 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
2764 h->root.root.string);
2768 /* We must allocate the symbol in our .dynbss section, which will
2769 become part of the .bss section of the executable. There will be
2770 an entry for this symbol in the .dynsym section. The dynamic
2771 object will contain position independent code, so all references
2772 from the dynamic object to this symbol will go through the global
2773 offset table. The dynamic linker will use the .dynsym entry to
2774 determine the address it must put in the global offset table, so
2775 both the dynamic object and the regular object will refer to the
2776 same memory location for the variable. */
2778 s = bfd_get_section_by_name (dynobj, ".dynbss");
2779 BFD_ASSERT (s != NULL);
2781 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
2782 copy the initial value out of the dynamic object and into the
2783 runtime process image. We need to remember the offset into the
2784 .rela.bss section we are going to use. */
2785 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2789 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
2790 BFD_ASSERT (srel != NULL);
2791 srel->size += sizeof (Elf32_External_Rela);
2795 return _bfd_elf_adjust_dynamic_copy (h, s);
2798 /* Set the sizes of the dynamic sections. */
2801 elf_m68k_size_dynamic_sections (output_bfd, info)
2802 bfd *output_bfd ATTRIBUTE_UNUSED;
2803 struct bfd_link_info *info;
2810 dynobj = elf_hash_table (info)->dynobj;
2811 BFD_ASSERT (dynobj != NULL);
2813 if (elf_hash_table (info)->dynamic_sections_created)
2815 /* Set the contents of the .interp section to the interpreter. */
2816 if (info->executable)
2818 s = bfd_get_section_by_name (dynobj, ".interp");
2819 BFD_ASSERT (s != NULL);
2820 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
2821 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2826 /* We may have created entries in the .rela.got section.
2827 However, if we are not creating the dynamic sections, we will
2828 not actually use these entries. Reset the size of .rela.got,
2829 which will cause it to get stripped from the output file
2831 s = bfd_get_section_by_name (dynobj, ".rela.got");
2836 /* If this is a -Bsymbolic shared link, then we need to discard all
2837 PC relative relocs against symbols defined in a regular object.
2838 For the normal shared case we discard the PC relative relocs
2839 against symbols that have become local due to visibility changes.
2840 We allocated space for them in the check_relocs routine, but we
2841 will not fill them in in the relocate_section routine. */
2843 elf_link_hash_traverse (elf_hash_table (info),
2844 elf_m68k_discard_copies,
2847 /* The check_relocs and adjust_dynamic_symbol entry points have
2848 determined the sizes of the various dynamic sections. Allocate
2852 for (s = dynobj->sections; s != NULL; s = s->next)
2856 if ((s->flags & SEC_LINKER_CREATED) == 0)
2859 /* It's OK to base decisions on the section name, because none
2860 of the dynobj section names depend upon the input files. */
2861 name = bfd_get_section_name (dynobj, s);
2863 if (strcmp (name, ".plt") == 0)
2865 /* Remember whether there is a PLT. */
2868 else if (CONST_STRNEQ (name, ".rela"))
2874 /* We use the reloc_count field as a counter if we need
2875 to copy relocs into the output file. */
2879 else if (! CONST_STRNEQ (name, ".got")
2880 && strcmp (name, ".dynbss") != 0)
2882 /* It's not one of our sections, so don't allocate space. */
2888 /* If we don't need this section, strip it from the
2889 output file. This is mostly to handle .rela.bss and
2890 .rela.plt. We must create both sections in
2891 create_dynamic_sections, because they must be created
2892 before the linker maps input sections to output
2893 sections. The linker does that before
2894 adjust_dynamic_symbol is called, and it is that
2895 function which decides whether anything needs to go
2896 into these sections. */
2897 s->flags |= SEC_EXCLUDE;
2901 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2904 /* Allocate memory for the section contents. */
2905 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
2906 Unused entries should be reclaimed before the section's contents
2907 are written out, but at the moment this does not happen. Thus in
2908 order to prevent writing out garbage, we initialise the section's
2909 contents to zero. */
2910 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2911 if (s->contents == NULL)
2915 if (elf_hash_table (info)->dynamic_sections_created)
2917 /* Add some entries to the .dynamic section. We fill in the
2918 values later, in elf_m68k_finish_dynamic_sections, but we
2919 must add the entries now so that we get the correct size for
2920 the .dynamic section. The DT_DEBUG entry is filled in by the
2921 dynamic linker and used by the debugger. */
2922 #define add_dynamic_entry(TAG, VAL) \
2923 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2927 if (!add_dynamic_entry (DT_DEBUG, 0))
2933 if (!add_dynamic_entry (DT_PLTGOT, 0)
2934 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2935 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2936 || !add_dynamic_entry (DT_JMPREL, 0))
2942 if (!add_dynamic_entry (DT_RELA, 0)
2943 || !add_dynamic_entry (DT_RELASZ, 0)
2944 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
2948 if ((info->flags & DF_TEXTREL) != 0)
2950 if (!add_dynamic_entry (DT_TEXTREL, 0))
2954 #undef add_dynamic_entry
2959 /* This function is called via elf_link_hash_traverse if we are
2960 creating a shared object. In the -Bsymbolic case it discards the
2961 space allocated to copy PC relative relocs against symbols which
2962 are defined in regular objects. For the normal shared case, it
2963 discards space for pc-relative relocs that have become local due to
2964 symbol visibility changes. We allocated space for them in the
2965 check_relocs routine, but we won't fill them in in the
2966 relocate_section routine.
2968 We also check whether any of the remaining relocations apply
2969 against a readonly section, and set the DF_TEXTREL flag in this
2973 elf_m68k_discard_copies (h, inf)
2974 struct elf_link_hash_entry *h;
2977 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2978 struct elf_m68k_pcrel_relocs_copied *s;
2980 if (h->root.type == bfd_link_hash_warning)
2981 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2985 && !h->forced_local))
2987 if ((info->flags & DF_TEXTREL) == 0)
2989 /* Look for relocations against read-only sections. */
2990 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
2993 if ((s->section->flags & SEC_READONLY) != 0)
2995 info->flags |= DF_TEXTREL;
3003 for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3006 s->section->size -= s->count * sizeof (Elf32_External_Rela);
3011 /* Relocate an M68K ELF section. */
3014 elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section,
3015 contents, relocs, local_syms, local_sections)
3017 struct bfd_link_info *info;
3019 asection *input_section;
3021 Elf_Internal_Rela *relocs;
3022 Elf_Internal_Sym *local_syms;
3023 asection **local_sections;
3026 Elf_Internal_Shdr *symtab_hdr;
3027 struct elf_link_hash_entry **sym_hashes;
3031 struct elf_m68k_got *got;
3032 Elf_Internal_Rela *rel;
3033 Elf_Internal_Rela *relend;
3035 dynobj = elf_hash_table (info)->dynobj;
3036 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3037 sym_hashes = elf_sym_hashes (input_bfd);
3046 relend = relocs + input_section->reloc_count;
3047 for (; rel < relend; rel++)
3050 reloc_howto_type *howto;
3051 unsigned long r_symndx;
3052 struct elf_link_hash_entry *h;
3053 Elf_Internal_Sym *sym;
3056 bfd_boolean unresolved_reloc;
3057 bfd_reloc_status_type r;
3059 r_type = ELF32_R_TYPE (rel->r_info);
3060 if (r_type < 0 || r_type >= (int) R_68K_max)
3062 bfd_set_error (bfd_error_bad_value);
3065 howto = howto_table + r_type;
3067 r_symndx = ELF32_R_SYM (rel->r_info);
3072 unresolved_reloc = FALSE;
3074 if (r_symndx < symtab_hdr->sh_info)
3076 sym = local_syms + r_symndx;
3077 sec = local_sections[r_symndx];
3078 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3084 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3085 r_symndx, symtab_hdr, sym_hashes,
3087 unresolved_reloc, warned);
3090 if (sec != NULL && elf_discarded_section (sec))
3092 /* For relocs against symbols from removed linkonce sections,
3093 or sections discarded by a linker script, we just want the
3094 section contents zeroed. Avoid any special processing. */
3095 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
3101 if (info->relocatable)
3109 /* Relocation is to the address of the entry for this symbol
3110 in the global offset table. */
3112 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3114 if (elf_m68k_hash_table (info)->local_gp_p)
3116 bfd_vma sgot_output_offset;
3121 sgot = bfd_get_section_by_name (dynobj, ".got");
3124 sgot_output_offset = sgot->output_offset;
3126 /* In this case we have a reference to
3127 _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3129 ??? Issue a warning? */
3130 sgot_output_offset = 0;
3133 sgot_output_offset = sgot->output_offset;
3137 struct elf_m68k_bfd2got_entry *bfd2got_entry;
3140 = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3141 input_bfd, SEARCH, NULL);
3143 if (bfd2got_entry != NULL)
3145 got = bfd2got_entry->got;
3146 BFD_ASSERT (got != NULL);
3148 got_offset = got->offset;
3151 /* In this case we have a reference to
3152 _GLOBAL_OFFSET_TABLE_, but no other references
3153 accessing any GOT entries.
3154 ??? Issue a warning? */
3158 got_offset = got->offset;
3160 /* Adjust GOT pointer to point to the GOT
3161 assigned to input_bfd. */
3162 rel->r_addend += sgot_output_offset + got_offset;
3165 BFD_ASSERT (got == NULL || got->offset == 0);
3173 /* Relocation is the offset of the entry for this symbol in
3174 the global offset table. */
3177 struct elf_m68k_got_entry_key key_;
3183 sgot = bfd_get_section_by_name (dynobj, ".got");
3184 BFD_ASSERT (sgot != NULL);
3189 got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3190 input_bfd, MUST_FIND,
3192 BFD_ASSERT (got != NULL);
3195 /* Get GOT offset for this symbol. */
3196 elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx);
3197 off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
3205 dyn = elf_hash_table (info)->dynamic_sections_created;
3206 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3213 /* This is actually a static link, or it is a
3214 -Bsymbolic link and the symbol is defined
3215 locally, or the symbol was forced to be local
3216 because of a version file.. We must initialize
3217 this entry in the global offset table. Since
3218 the offset must always be a multiple of 4, we
3219 use the least significant bit to record whether
3220 we have initialized it already.
3222 When doing a dynamic link, we create a .rela.got
3223 relocation entry to initialize the value. This
3224 is done in the finish_dynamic_symbol routine. */
3229 bfd_put_32 (output_bfd, relocation,
3230 sgot->contents + off);
3235 unresolved_reloc = FALSE;
3239 /* The offset must always be a multiple of 4. We use
3240 the least significant bit to record whether we have
3241 already generated the necessary reloc. */
3246 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
3251 Elf_Internal_Rela outrel;
3254 s = bfd_get_section_by_name (dynobj, ".rela.got");
3255 BFD_ASSERT (s != NULL);
3257 outrel.r_offset = (sgot->output_section->vma
3258 + sgot->output_offset
3260 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3261 outrel.r_addend = relocation;
3263 loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
3264 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3271 if (r_type == R_68K_GOT8O
3272 || r_type == R_68K_GOT16O
3273 || r_type == R_68K_GOT32O)
3275 /* GOT pointer is adjusted to point to the start/middle
3276 of local GOT. Adjust the offset accordingly. */
3277 BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
3278 || off >= got->offset);
3280 if (elf_m68k_hash_table (info)->local_gp_p)
3281 relocation = off - got->offset;
3284 BFD_ASSERT (got->offset == 0);
3285 relocation = sgot->output_offset + off;
3288 /* This relocation does not use the addend. */
3289 BFD_ASSERT (rel->r_addend == 0);
3293 relocation = (sgot->output_section->vma + sgot->output_offset
3301 /* Relocation is to the entry for this symbol in the
3302 procedure linkage table. */
3304 /* Resolve a PLTxx reloc against a local symbol directly,
3305 without using the procedure linkage table. */
3309 if (h->plt.offset == (bfd_vma) -1
3310 || !elf_hash_table (info)->dynamic_sections_created)
3312 /* We didn't make a PLT entry for this symbol. This
3313 happens when statically linking PIC code, or when
3314 using -Bsymbolic. */
3320 splt = bfd_get_section_by_name (dynobj, ".plt");
3321 BFD_ASSERT (splt != NULL);
3324 relocation = (splt->output_section->vma
3325 + splt->output_offset
3327 unresolved_reloc = FALSE;
3333 /* Relocation is the offset of the entry for this symbol in
3334 the procedure linkage table. */
3335 BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
3339 splt = bfd_get_section_by_name (dynobj, ".plt");
3340 BFD_ASSERT (splt != NULL);
3343 relocation = h->plt.offset;
3344 unresolved_reloc = FALSE;
3346 /* This relocation does not use the addend. */
3356 && h->forced_local))
3364 && (input_section->flags & SEC_ALLOC) != 0
3366 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3367 || h->root.type != bfd_link_hash_undefweak)
3368 && ((r_type != R_68K_PC8
3369 && r_type != R_68K_PC16
3370 && r_type != R_68K_PC32)
3374 || !h->def_regular))))
3376 Elf_Internal_Rela outrel;
3378 bfd_boolean skip, relocate;
3380 /* When generating a shared object, these relocations
3381 are copied into the output file to be resolved at run
3388 _bfd_elf_section_offset (output_bfd, info, input_section,
3390 if (outrel.r_offset == (bfd_vma) -1)
3392 else if (outrel.r_offset == (bfd_vma) -2)
3393 skip = TRUE, relocate = TRUE;
3394 outrel.r_offset += (input_section->output_section->vma
3395 + input_section->output_offset);
3398 memset (&outrel, 0, sizeof outrel);
3401 && (r_type == R_68K_PC8
3402 || r_type == R_68K_PC16
3403 || r_type == R_68K_PC32
3406 || !h->def_regular))
3408 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3409 outrel.r_addend = rel->r_addend;
3413 /* This symbol is local, or marked to become local. */
3414 outrel.r_addend = relocation + rel->r_addend;
3416 if (r_type == R_68K_32)
3419 outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3425 if (bfd_is_abs_section (sec))
3427 else if (sec == NULL || sec->owner == NULL)
3429 bfd_set_error (bfd_error_bad_value);
3436 /* We are turning this relocation into one
3437 against a section symbol. It would be
3438 proper to subtract the symbol's value,
3439 osec->vma, from the emitted reloc addend,
3440 but ld.so expects buggy relocs. */
3441 osec = sec->output_section;
3442 indx = elf_section_data (osec)->dynindx;
3445 struct elf_link_hash_table *htab;
3446 htab = elf_hash_table (info);
3447 osec = htab->text_index_section;
3448 indx = elf_section_data (osec)->dynindx;
3450 BFD_ASSERT (indx != 0);
3453 outrel.r_info = ELF32_R_INFO (indx, r_type);
3457 sreloc = elf_section_data (input_section)->sreloc;
3461 loc = sreloc->contents;
3462 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
3463 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3465 /* This reloc will be computed at runtime, so there's no
3466 need to do anything now, except for R_68K_32
3467 relocations that have been turned into
3475 case R_68K_GNU_VTINHERIT:
3476 case R_68K_GNU_VTENTRY:
3477 /* These are no-ops in the end. */
3484 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3485 because such sections are not SEC_ALLOC and thus ld.so will
3486 not process them. */
3487 if (unresolved_reloc
3488 && !((input_section->flags & SEC_DEBUGGING) != 0
3491 (*_bfd_error_handler)
3492 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3495 (long) rel->r_offset,
3497 h->root.root.string);
3501 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3502 contents, rel->r_offset,
3503 relocation, rel->r_addend);
3505 if (r != bfd_reloc_ok)
3510 name = h->root.root.string;
3513 name = bfd_elf_string_from_elf_section (input_bfd,
3514 symtab_hdr->sh_link,
3519 name = bfd_section_name (input_bfd, sec);
3522 if (r == bfd_reloc_overflow)
3524 if (!(info->callbacks->reloc_overflow
3525 (info, (h ? &h->root : NULL), name, howto->name,
3526 (bfd_vma) 0, input_bfd, input_section,
3532 (*_bfd_error_handler)
3533 (_("%B(%A+0x%lx): reloc against `%s': error %d"),
3534 input_bfd, input_section,
3535 (long) rel->r_offset, name, (int) r);
3544 /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
3545 into section SEC. */
3548 elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
3550 /* Make VALUE PC-relative. */
3551 value -= sec->output_section->vma + offset;
3553 /* Apply any in-place addend. */
3554 value += bfd_get_32 (sec->owner, sec->contents + offset);
3556 bfd_put_32 (sec->owner, value, sec->contents + offset);
3559 /* Finish up dynamic symbol handling. We set the contents of various
3560 dynamic sections here. */
3563 elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym)
3565 struct bfd_link_info *info;
3566 struct elf_link_hash_entry *h;
3567 Elf_Internal_Sym *sym;
3571 dynobj = elf_hash_table (info)->dynobj;
3573 if (h->plt.offset != (bfd_vma) -1)
3575 const struct elf_m68k_plt_info *plt_info;
3581 Elf_Internal_Rela rela;
3584 /* This symbol has an entry in the procedure linkage table. Set
3587 BFD_ASSERT (h->dynindx != -1);
3589 plt_info = elf_m68k_hash_table (info)->plt_info;
3590 splt = bfd_get_section_by_name (dynobj, ".plt");
3591 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3592 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
3593 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
3595 /* Get the index in the procedure linkage table which
3596 corresponds to this symbol. This is the index of this symbol
3597 in all the symbols for which we are making plt entries. The
3598 first entry in the procedure linkage table is reserved. */
3599 plt_index = (h->plt.offset / plt_info->size) - 1;
3601 /* Get the offset into the .got table of the entry that
3602 corresponds to this function. Each .got entry is 4 bytes.
3603 The first three are reserved. */
3604 got_offset = (plt_index + 3) * 4;
3606 memcpy (splt->contents + h->plt.offset,
3607 plt_info->symbol_entry,
3610 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
3611 (sgot->output_section->vma
3612 + sgot->output_offset
3615 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
3618 + plt_info->symbol_resolve_entry + 2);
3620 elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
3621 splt->output_section->vma);
3623 /* Fill in the entry in the global offset table. */
3624 bfd_put_32 (output_bfd,
3625 (splt->output_section->vma
3626 + splt->output_offset
3628 + plt_info->symbol_resolve_entry),
3629 sgot->contents + got_offset);
3631 /* Fill in the entry in the .rela.plt section. */
3632 rela.r_offset = (sgot->output_section->vma
3633 + sgot->output_offset
3635 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
3637 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
3638 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3640 if (!h->def_regular)
3642 /* Mark the symbol as undefined, rather than as defined in
3643 the .plt section. Leave the value alone. */
3644 sym->st_shndx = SHN_UNDEF;
3648 if (elf_m68k_hash_entry (h)->glist != NULL)
3652 struct elf_m68k_got_entry *got_entry;
3654 /* This symbol has an entry in the global offset table. Set it
3657 sgot = bfd_get_section_by_name (dynobj, ".got");
3658 srela = bfd_get_section_by_name (dynobj, ".rela.got");
3659 BFD_ASSERT (sgot != NULL && srela != NULL);
3661 got_entry = elf_m68k_hash_entry (h)->glist;
3663 while (got_entry != NULL)
3665 Elf_Internal_Rela rela;
3668 rela.r_offset = (sgot->output_section->vma
3669 + sgot->output_offset
3670 + (got_entry->u.s2.offset &~ (bfd_vma) 1));
3672 /* If this is a -Bsymbolic link, and the symbol is defined
3673 locally, we just want to emit a RELATIVE reloc. Likewise if
3674 the symbol was forced to be local because of a version file.
3675 The entry in the global offset table will already have been
3676 initialized in the relocate_section function. */
3683 rela.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3684 rela.r_addend = bfd_get_signed_32 (output_bfd,
3686 + (got_entry->u.s2.offset
3691 bfd_put_32 (output_bfd, (bfd_vma) 0,
3692 sgot->contents + (got_entry->u.s2.offset
3694 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
3698 loc = srela->contents;
3699 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
3700 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3702 got_entry = got_entry->u.s2.next;
3709 Elf_Internal_Rela rela;
3712 /* This symbol needs a copy reloc. Set it up. */
3714 BFD_ASSERT (h->dynindx != -1
3715 && (h->root.type == bfd_link_hash_defined
3716 || h->root.type == bfd_link_hash_defweak));
3718 s = bfd_get_section_by_name (h->root.u.def.section->owner,
3720 BFD_ASSERT (s != NULL);
3722 rela.r_offset = (h->root.u.def.value
3723 + h->root.u.def.section->output_section->vma
3724 + h->root.u.def.section->output_offset);
3725 rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
3727 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
3728 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3731 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3732 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
3733 || h == elf_hash_table (info)->hgot)
3734 sym->st_shndx = SHN_ABS;
3739 /* Finish up the dynamic sections. */
3742 elf_m68k_finish_dynamic_sections (output_bfd, info)
3744 struct bfd_link_info *info;
3750 dynobj = elf_hash_table (info)->dynobj;
3752 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
3753 BFD_ASSERT (sgot != NULL);
3754 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3756 if (elf_hash_table (info)->dynamic_sections_created)
3759 Elf32_External_Dyn *dyncon, *dynconend;
3761 splt = bfd_get_section_by_name (dynobj, ".plt");
3762 BFD_ASSERT (splt != NULL && sdyn != NULL);
3764 dyncon = (Elf32_External_Dyn *) sdyn->contents;
3765 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
3766 for (; dyncon < dynconend; dyncon++)
3768 Elf_Internal_Dyn dyn;
3772 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
3785 s = bfd_get_section_by_name (output_bfd, name);
3786 BFD_ASSERT (s != NULL);
3787 dyn.d_un.d_ptr = s->vma;
3788 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3792 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3793 BFD_ASSERT (s != NULL);
3794 dyn.d_un.d_val = s->size;
3795 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3799 /* The procedure linkage table relocs (DT_JMPREL) should
3800 not be included in the overall relocs (DT_RELA).
3801 Therefore, we override the DT_RELASZ entry here to
3802 make it not include the JMPREL relocs. Since the
3803 linker script arranges for .rela.plt to follow all
3804 other relocation sections, we don't have to worry
3805 about changing the DT_RELA entry. */
3806 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
3808 dyn.d_un.d_val -= s->size;
3809 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
3814 /* Fill in the first entry in the procedure linkage table. */
3817 const struct elf_m68k_plt_info *plt_info;
3819 plt_info = elf_m68k_hash_table (info)->plt_info;
3820 memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
3822 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
3823 (sgot->output_section->vma
3824 + sgot->output_offset
3827 elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
3828 (sgot->output_section->vma
3829 + sgot->output_offset
3832 elf_section_data (splt->output_section)->this_hdr.sh_entsize
3837 /* Fill in the first three entries in the global offset table. */
3841 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3843 bfd_put_32 (output_bfd,
3844 sdyn->output_section->vma + sdyn->output_offset,
3846 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
3847 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
3850 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
3855 /* Given a .data section and a .emreloc in-memory section, store
3856 relocation information into the .emreloc section which can be
3857 used at runtime to relocate the section. This is called by the
3858 linker when the --embedded-relocs switch is used. This is called
3859 after the add_symbols entry point has been called for all the
3860 objects, and before the final_link entry point is called. */
3863 bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
3865 struct bfd_link_info *info;
3870 Elf_Internal_Shdr *symtab_hdr;
3871 Elf_Internal_Sym *isymbuf = NULL;
3872 Elf_Internal_Rela *internal_relocs = NULL;
3873 Elf_Internal_Rela *irel, *irelend;
3877 BFD_ASSERT (! info->relocatable);
3881 if (datasec->reloc_count == 0)
3884 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3886 /* Get a copy of the native relocations. */
3887 internal_relocs = (_bfd_elf_link_read_relocs
3888 (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
3889 info->keep_memory));
3890 if (internal_relocs == NULL)
3893 amt = (bfd_size_type) datasec->reloc_count * 12;
3894 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
3895 if (relsec->contents == NULL)
3898 p = relsec->contents;
3900 irelend = internal_relocs + datasec->reloc_count;
3901 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
3903 asection *targetsec;
3905 /* We are going to write a four byte longword into the runtime
3906 reloc section. The longword will be the address in the data
3907 section which must be relocated. It is followed by the name
3908 of the target section NUL-padded or truncated to 8
3911 /* We can only relocate absolute longword relocs at run time. */
3912 if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
3914 *errmsg = _("unsupported reloc type");
3915 bfd_set_error (bfd_error_bad_value);
3919 /* Get the target section referred to by the reloc. */
3920 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
3922 /* A local symbol. */
3923 Elf_Internal_Sym *isym;
3925 /* Read this BFD's local symbols if we haven't done so already. */
3926 if (isymbuf == NULL)
3928 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
3929 if (isymbuf == NULL)
3930 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
3931 symtab_hdr->sh_info, 0,
3933 if (isymbuf == NULL)
3937 isym = isymbuf + ELF32_R_SYM (irel->r_info);
3938 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3943 struct elf_link_hash_entry *h;
3945 /* An external symbol. */
3946 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
3947 h = elf_sym_hashes (abfd)[indx];
3948 BFD_ASSERT (h != NULL);
3949 if (h->root.type == bfd_link_hash_defined
3950 || h->root.type == bfd_link_hash_defweak)
3951 targetsec = h->root.u.def.section;
3956 bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
3957 memset (p + 4, 0, 8);
3958 if (targetsec != NULL)
3959 strncpy ((char *) p + 4, targetsec->output_section->name, 8);
3962 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3964 if (internal_relocs != NULL
3965 && elf_section_data (datasec)->relocs != internal_relocs)
3966 free (internal_relocs);
3970 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3972 if (internal_relocs != NULL
3973 && elf_section_data (datasec)->relocs != internal_relocs)
3974 free (internal_relocs);
3978 /* Set target options. */
3981 bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
3983 struct elf_m68k_link_hash_table *htab;
3985 htab = elf_m68k_hash_table (info);
3987 switch (got_handling)
3991 htab->local_gp_p = FALSE;
3992 htab->use_neg_got_offsets_p = FALSE;
3993 htab->allow_multigot_p = FALSE;
3997 /* --got=negative. */
3998 htab->local_gp_p = TRUE;
3999 htab->use_neg_got_offsets_p = TRUE;
4000 htab->allow_multigot_p = FALSE;
4004 /* --got=multigot. */
4005 htab->local_gp_p = TRUE;
4006 htab->use_neg_got_offsets_p = TRUE;
4007 htab->allow_multigot_p = TRUE;
4015 static enum elf_reloc_type_class
4016 elf32_m68k_reloc_type_class (rela)
4017 const Elf_Internal_Rela *rela;
4019 switch ((int) ELF32_R_TYPE (rela->r_info))
4021 case R_68K_RELATIVE:
4022 return reloc_class_relative;
4023 case R_68K_JMP_SLOT:
4024 return reloc_class_plt;
4026 return reloc_class_copy;
4028 return reloc_class_normal;
4032 /* Return address for Ith PLT stub in section PLT, for relocation REL
4033 or (bfd_vma) -1 if it should not be included. */
4036 elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
4037 const arelent *rel ATTRIBUTE_UNUSED)
4039 return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
4042 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
4043 #define TARGET_BIG_NAME "elf32-m68k"
4044 #define ELF_MACHINE_CODE EM_68K
4045 #define ELF_MAXPAGESIZE 0x2000
4046 #define elf_backend_create_dynamic_sections \
4047 _bfd_elf_create_dynamic_sections
4048 #define bfd_elf32_bfd_link_hash_table_create \
4049 elf_m68k_link_hash_table_create
4050 /* ??? Should it be this macro or bfd_elfNN_bfd_link_hash_table_create? */
4051 #define bfd_elf32_bfd_link_hash_table_free \
4052 elf_m68k_link_hash_table_free
4053 #define bfd_elf32_bfd_final_link bfd_elf_final_link
4055 #define elf_backend_check_relocs elf_m68k_check_relocs
4056 #define elf_backend_always_size_sections \
4057 elf_m68k_always_size_sections
4058 #define elf_backend_adjust_dynamic_symbol \
4059 elf_m68k_adjust_dynamic_symbol
4060 #define elf_backend_size_dynamic_sections \
4061 elf_m68k_size_dynamic_sections
4062 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
4063 #define elf_backend_relocate_section elf_m68k_relocate_section
4064 #define elf_backend_finish_dynamic_symbol \
4065 elf_m68k_finish_dynamic_symbol
4066 #define elf_backend_finish_dynamic_sections \
4067 elf_m68k_finish_dynamic_sections
4068 #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook
4069 #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook
4070 #define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4071 #define bfd_elf32_bfd_merge_private_bfd_data \
4072 elf32_m68k_merge_private_bfd_data
4073 #define bfd_elf32_bfd_set_private_flags \
4074 elf32_m68k_set_private_flags
4075 #define bfd_elf32_bfd_print_private_bfd_data \
4076 elf32_m68k_print_private_bfd_data
4077 #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class
4078 #define elf_backend_plt_sym_val elf_m68k_plt_sym_val
4079 #define elf_backend_object_p elf32_m68k_object_p
4081 #define elf_backend_can_gc_sections 1
4082 #define elf_backend_can_refcount 1
4083 #define elf_backend_want_got_plt 1
4084 #define elf_backend_plt_readonly 1
4085 #define elf_backend_want_plt_sym 0
4086 #define elf_backend_got_header_size 12
4087 #define elf_backend_rela_normal 1
4089 #include "elf32-target.h"