1 /* Matsushita 10300 specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 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. */
26 #include "elf/mn10300.h"
28 static bfd_reloc_status_type mn10300_elf_final_link_relocate
29 PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
30 bfd_vma, bfd_vma, bfd_vma,
31 struct elf_link_hash_entry *, unsigned long, struct bfd_link_info *,
33 static bfd_boolean mn10300_elf_relocate_section
34 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
35 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
36 static bfd_boolean mn10300_elf_relax_section
37 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
38 static bfd_byte * mn10300_elf_get_relocated_section_contents
39 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
40 bfd_byte *, bfd_boolean, asymbol **));
41 static unsigned long elf_mn10300_mach
43 void _bfd_mn10300_elf_final_write_processing
44 PARAMS ((bfd *, bfd_boolean));
45 bfd_boolean _bfd_mn10300_elf_object_p
47 bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data
48 PARAMS ((bfd *,bfd *));
50 /* The mn10300 linker needs to keep track of the number of relocs that
51 it decides to copy in check_relocs for each symbol. This is so
52 that it can discard PC relative relocs if it doesn't need them when
53 linking with -Bsymbolic. We store the information in a field
54 extending the regular ELF linker hash table. */
56 struct elf32_mn10300_link_hash_entry {
57 /* The basic elf link hash table entry. */
58 struct elf_link_hash_entry root;
60 /* For function symbols, the number of times this function is
61 called directly (ie by name). */
62 unsigned int direct_calls;
64 /* For function symbols, the size of this function's stack
65 (if <= 255 bytes). We stuff this into "call" instructions
66 to this target when it's valid and profitable to do so.
68 This does not include stack allocated by movm! */
69 unsigned char stack_size;
71 /* For function symbols, arguments (if any) for movm instruction
72 in the prologue. We stuff this value into "call" instructions
73 to the target when it's valid and profitable to do so. */
74 unsigned char movm_args;
76 /* For function symbols, the amount of stack space that would be allocated
77 by the movm instruction. This is redundant with movm_args, but we
78 add it to the hash table to avoid computing it over and over. */
79 unsigned char movm_stack_size;
81 /* When set, convert all "call" instructions to this target into "calls"
83 #define MN10300_CONVERT_CALL_TO_CALLS 0x1
85 /* Used to mark functions which have had redundant parts of their
87 #define MN10300_DELETED_PROLOGUE_BYTES 0x2
90 /* Calculated value. */
94 /* We derive a hash table from the main elf linker hash table so
95 we can store state variables and a secondary hash table without
96 resorting to global variables. */
97 struct elf32_mn10300_link_hash_table {
98 /* The main hash table. */
99 struct elf_link_hash_table root;
101 /* A hash table for static functions. We could derive a new hash table
102 instead of using the full elf32_mn10300_link_hash_table if we wanted
103 to save some memory. */
104 struct elf32_mn10300_link_hash_table *static_hash_table;
106 /* Random linker state flags. */
107 #define MN10300_HASH_ENTRIES_INITIALIZED 0x1
111 /* For MN10300 linker hash table. */
113 /* Get the MN10300 ELF linker hash table from a link_info structure. */
115 #define elf32_mn10300_hash_table(p) \
116 ((struct elf32_mn10300_link_hash_table *) ((p)->hash))
118 #define elf32_mn10300_link_hash_traverse(table, func, info) \
119 (elf_link_hash_traverse \
121 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
124 static struct bfd_hash_entry *elf32_mn10300_link_hash_newfunc
125 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
126 static struct bfd_link_hash_table *elf32_mn10300_link_hash_table_create
128 static void elf32_mn10300_link_hash_table_free
129 PARAMS ((struct bfd_link_hash_table *));
131 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
132 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
133 static void mn10300_info_to_howto
134 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
135 static bfd_boolean mn10300_elf_check_relocs
136 PARAMS ((bfd *, struct bfd_link_info *, asection *,
137 const Elf_Internal_Rela *));
138 static bfd_boolean mn10300_elf_relax_delete_bytes
139 PARAMS ((bfd *, asection *, bfd_vma, int));
140 static bfd_boolean mn10300_elf_symbol_address_p
141 PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
142 static bfd_boolean elf32_mn10300_finish_hash_table_entry
143 PARAMS ((struct bfd_hash_entry *, PTR));
144 static void compute_function_info
145 PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *,
146 bfd_vma, unsigned char *));
148 static bfd_boolean _bfd_mn10300_elf_create_got_section
149 PARAMS ((bfd *, struct bfd_link_info *));
150 static bfd_boolean _bfd_mn10300_elf_create_dynamic_sections
151 PARAMS ((bfd *, struct bfd_link_info *));
152 static bfd_boolean _bfd_mn10300_elf_adjust_dynamic_symbol
153 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
154 static bfd_boolean _bfd_mn10300_elf_size_dynamic_sections
155 PARAMS ((bfd *, struct bfd_link_info *));
156 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_symbol
157 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
158 Elf_Internal_Sym *));
159 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_sections
160 PARAMS ((bfd *, struct bfd_link_info *));
162 static reloc_howto_type elf_mn10300_howto_table[] = {
163 /* Dummy relocation. Does nothing. */
164 HOWTO (R_MN10300_NONE,
170 complain_overflow_bitfield,
171 bfd_elf_generic_reloc,
177 /* Standard 32 bit reloc. */
184 complain_overflow_bitfield,
185 bfd_elf_generic_reloc,
191 /* Standard 16 bit reloc. */
198 complain_overflow_bitfield,
199 bfd_elf_generic_reloc,
205 /* Standard 8 bit reloc. */
212 complain_overflow_bitfield,
213 bfd_elf_generic_reloc,
219 /* Standard 32bit pc-relative reloc. */
220 HOWTO (R_MN10300_PCREL32,
226 complain_overflow_bitfield,
227 bfd_elf_generic_reloc,
233 /* Standard 16bit pc-relative reloc. */
234 HOWTO (R_MN10300_PCREL16,
240 complain_overflow_bitfield,
241 bfd_elf_generic_reloc,
247 /* Standard 8 pc-relative reloc. */
248 HOWTO (R_MN10300_PCREL8,
254 complain_overflow_bitfield,
255 bfd_elf_generic_reloc,
262 /* GNU extension to record C++ vtable hierarchy */
263 HOWTO (R_MN10300_GNU_VTINHERIT, /* type */
265 0, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE, /* pc_relative */
269 complain_overflow_dont, /* complain_on_overflow */
270 NULL, /* special_function */
271 "R_MN10300_GNU_VTINHERIT", /* name */
272 FALSE, /* partial_inplace */
275 FALSE), /* pcrel_offset */
277 /* GNU extension to record C++ vtable member usage */
278 HOWTO (R_MN10300_GNU_VTENTRY, /* type */
280 0, /* size (0 = byte, 1 = short, 2 = long) */
282 FALSE, /* pc_relative */
284 complain_overflow_dont, /* complain_on_overflow */
285 NULL, /* special_function */
286 "R_MN10300_GNU_VTENTRY", /* name */
287 FALSE, /* partial_inplace */
290 FALSE), /* pcrel_offset */
292 /* Standard 24 bit reloc. */
299 complain_overflow_bitfield,
300 bfd_elf_generic_reloc,
306 HOWTO (R_MN10300_GOTPC32, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 TRUE, /* pc_relative */
312 complain_overflow_bitfield, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* */
314 "R_MN10300_GOTPC32", /* name */
315 FALSE, /* partial_inplace */
316 0xffffffff, /* src_mask */
317 0xffffffff, /* dst_mask */
318 TRUE), /* pcrel_offset */
320 HOWTO (R_MN10300_GOTPC16, /* type */
322 1, /* size (0 = byte, 1 = short, 2 = long) */
324 TRUE, /* pc_relative */
326 complain_overflow_bitfield, /* complain_on_overflow */
327 bfd_elf_generic_reloc, /* */
328 "R_MN10300_GOTPC16", /* name */
329 FALSE, /* partial_inplace */
330 0xffff, /* src_mask */
331 0xffff, /* dst_mask */
332 TRUE), /* pcrel_offset */
334 HOWTO (R_MN10300_GOTOFF32, /* type */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
338 FALSE, /* pc_relative */
340 complain_overflow_bitfield, /* complain_on_overflow */
341 bfd_elf_generic_reloc, /* */
342 "R_MN10300_GOTOFF32", /* name */
343 FALSE, /* partial_inplace */
344 0xffffffff, /* src_mask */
345 0xffffffff, /* dst_mask */
346 FALSE), /* pcrel_offset */
348 HOWTO (R_MN10300_GOTOFF24, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 FALSE, /* pc_relative */
354 complain_overflow_bitfield, /* complain_on_overflow */
355 bfd_elf_generic_reloc, /* */
356 "R_MN10300_GOTOFF24", /* name */
357 FALSE, /* partial_inplace */
358 0xffffff, /* src_mask */
359 0xffffff, /* dst_mask */
360 FALSE), /* pcrel_offset */
362 HOWTO (R_MN10300_GOTOFF16, /* type */
364 1, /* size (0 = byte, 1 = short, 2 = long) */
366 FALSE, /* pc_relative */
368 complain_overflow_bitfield, /* complain_on_overflow */
369 bfd_elf_generic_reloc, /* */
370 "R_MN10300_GOTOFF16", /* name */
371 FALSE, /* partial_inplace */
372 0xffff, /* src_mask */
373 0xffff, /* dst_mask */
374 FALSE), /* pcrel_offset */
376 HOWTO (R_MN10300_PLT32, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 TRUE, /* pc_relative */
382 complain_overflow_bitfield, /* complain_on_overflow */
383 bfd_elf_generic_reloc, /* */
384 "R_MN10300_PLT32", /* name */
385 FALSE, /* partial_inplace */
386 0xffffffff, /* src_mask */
387 0xffffffff, /* dst_mask */
388 TRUE), /* pcrel_offset */
390 HOWTO (R_MN10300_PLT16, /* type */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
394 TRUE, /* pc_relative */
396 complain_overflow_bitfield, /* complain_on_overflow */
397 bfd_elf_generic_reloc, /* */
398 "R_MN10300_PLT16", /* name */
399 FALSE, /* partial_inplace */
400 0xffff, /* src_mask */
401 0xffff, /* dst_mask */
402 TRUE), /* pcrel_offset */
404 HOWTO (R_MN10300_GOT32, /* type */
406 2, /* size (0 = byte, 1 = short, 2 = long) */
408 FALSE, /* pc_relative */
410 complain_overflow_bitfield, /* complain_on_overflow */
411 bfd_elf_generic_reloc, /* */
412 "R_MN10300_GOT32", /* name */
413 FALSE, /* partial_inplace */
414 0xffffffff, /* src_mask */
415 0xffffffff, /* dst_mask */
416 FALSE), /* pcrel_offset */
418 HOWTO (R_MN10300_GOT24, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE, /* pc_relative */
424 complain_overflow_bitfield, /* complain_on_overflow */
425 bfd_elf_generic_reloc, /* */
426 "R_MN10300_GOT24", /* name */
427 FALSE, /* partial_inplace */
428 0xffffffff, /* src_mask */
429 0xffffffff, /* dst_mask */
430 FALSE), /* pcrel_offset */
432 HOWTO (R_MN10300_GOT16, /* type */
434 1, /* size (0 = byte, 1 = short, 2 = long) */
436 FALSE, /* pc_relative */
438 complain_overflow_bitfield, /* complain_on_overflow */
439 bfd_elf_generic_reloc, /* */
440 "R_MN10300_GOT16", /* name */
441 FALSE, /* partial_inplace */
442 0xffffffff, /* src_mask */
443 0xffffffff, /* dst_mask */
444 FALSE), /* pcrel_offset */
446 HOWTO (R_MN10300_COPY, /* type */
448 2, /* size (0 = byte, 1 = short, 2 = long) */
450 FALSE, /* pc_relative */
452 complain_overflow_bitfield, /* complain_on_overflow */
453 bfd_elf_generic_reloc, /* */
454 "R_MN10300_COPY", /* name */
455 FALSE, /* partial_inplace */
456 0xffffffff, /* src_mask */
457 0xffffffff, /* dst_mask */
458 FALSE), /* pcrel_offset */
460 HOWTO (R_MN10300_GLOB_DAT, /* type */
462 2, /* size (0 = byte, 1 = short, 2 = long) */
464 FALSE, /* pc_relative */
466 complain_overflow_bitfield, /* complain_on_overflow */
467 bfd_elf_generic_reloc, /* */
468 "R_MN10300_GLOB_DAT", /* name */
469 FALSE, /* partial_inplace */
470 0xffffffff, /* src_mask */
471 0xffffffff, /* dst_mask */
472 FALSE), /* pcrel_offset */
474 HOWTO (R_MN10300_JMP_SLOT, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 FALSE, /* pc_relative */
480 complain_overflow_bitfield, /* complain_on_overflow */
481 bfd_elf_generic_reloc, /* */
482 "R_MN10300_JMP_SLOT", /* name */
483 FALSE, /* partial_inplace */
484 0xffffffff, /* src_mask */
485 0xffffffff, /* dst_mask */
486 FALSE), /* pcrel_offset */
488 HOWTO (R_MN10300_RELATIVE, /* type */
490 2, /* size (0 = byte, 1 = short, 2 = long) */
492 FALSE, /* pc_relative */
494 complain_overflow_bitfield, /* complain_on_overflow */
495 bfd_elf_generic_reloc, /* */
496 "R_MN10300_RELATIVE", /* name */
497 FALSE, /* partial_inplace */
498 0xffffffff, /* src_mask */
499 0xffffffff, /* dst_mask */
500 FALSE), /* pcrel_offset */
504 struct mn10300_reloc_map {
505 bfd_reloc_code_real_type bfd_reloc_val;
506 unsigned char elf_reloc_val;
509 static const struct mn10300_reloc_map mn10300_reloc_map[] = {
510 { BFD_RELOC_NONE, R_MN10300_NONE, },
511 { BFD_RELOC_32, R_MN10300_32, },
512 { BFD_RELOC_16, R_MN10300_16, },
513 { BFD_RELOC_8, R_MN10300_8, },
514 { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, },
515 { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, },
516 { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, },
517 { BFD_RELOC_24, R_MN10300_24, },
518 { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },
519 { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },
520 { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 },
521 { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 },
522 { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 },
523 { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 },
524 { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 },
525 { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 },
526 { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 },
527 { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 },
528 { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 },
529 { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 },
530 { BFD_RELOC_MN10300_COPY, R_MN10300_COPY },
531 { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT },
532 { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT },
533 { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE },
536 /* Create the GOT section. */
539 _bfd_mn10300_elf_create_got_section (abfd, info)
541 struct bfd_link_info * info;
546 struct elf_link_hash_entry * h;
547 const struct elf_backend_data * bed = get_elf_backend_data (abfd);
550 /* This function may be called more than once. */
551 if (bfd_get_section_by_name (abfd, ".got") != NULL)
554 switch (bed->s->arch_size)
565 bfd_set_error (bfd_error_bad_value);
569 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
570 | SEC_LINKER_CREATED);
573 pltflags |= SEC_CODE;
574 if (bed->plt_not_loaded)
575 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
576 if (bed->plt_readonly)
577 pltflags |= SEC_READONLY;
579 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
581 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
584 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
586 if (bed->want_plt_sym)
588 h = _bfd_elf_define_linkage_sym (abfd, info, s,
589 "_PROCEDURE_LINKAGE_TABLE_");
590 elf_hash_table (info)->hplt = h;
595 s = bfd_make_section_with_flags (abfd, ".got", flags);
597 || ! bfd_set_section_alignment (abfd, s, ptralign))
600 if (bed->want_got_plt)
602 s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
604 || ! bfd_set_section_alignment (abfd, s, ptralign))
608 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
609 (or .got.plt) section. We don't do this in the linker script
610 because we don't want to define the symbol if we are not creating
611 a global offset table. */
612 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
613 elf_hash_table (info)->hgot = h;
617 /* The first bit of the global offset table is the header. */
618 s->size += bed->got_header_size;
623 static reloc_howto_type *
624 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
625 bfd *abfd ATTRIBUTE_UNUSED;
626 bfd_reloc_code_real_type code;
631 i < sizeof (mn10300_reloc_map) / sizeof (struct mn10300_reloc_map);
634 if (mn10300_reloc_map[i].bfd_reloc_val == code)
635 return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
641 static reloc_howto_type *
642 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
648 i < (sizeof (elf_mn10300_howto_table)
649 / sizeof (elf_mn10300_howto_table[0]));
651 if (elf_mn10300_howto_table[i].name != NULL
652 && strcasecmp (elf_mn10300_howto_table[i].name, r_name) == 0)
653 return &elf_mn10300_howto_table[i];
658 /* Set the howto pointer for an MN10300 ELF reloc. */
661 mn10300_info_to_howto (abfd, cache_ptr, dst)
662 bfd *abfd ATTRIBUTE_UNUSED;
664 Elf_Internal_Rela *dst;
668 r_type = ELF32_R_TYPE (dst->r_info);
669 BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX);
670 cache_ptr->howto = &elf_mn10300_howto_table[r_type];
673 /* Look through the relocs for a section during the first phase.
674 Since we don't do .gots or .plts, we just need to consider the
675 virtual table relocs for gc. */
678 mn10300_elf_check_relocs (abfd, info, sec, relocs)
680 struct bfd_link_info *info;
682 const Elf_Internal_Rela *relocs;
684 Elf_Internal_Shdr *symtab_hdr;
685 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
686 const Elf_Internal_Rela *rel;
687 const Elf_Internal_Rela *rel_end;
689 bfd_vma * local_got_offsets;
698 if (info->relocatable)
701 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
702 sym_hashes = elf_sym_hashes (abfd);
703 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
704 if (!elf_bad_symtab (abfd))
705 sym_hashes_end -= symtab_hdr->sh_info;
707 dynobj = elf_hash_table (info)->dynobj;
708 local_got_offsets = elf_local_got_offsets (abfd);
709 rel_end = relocs + sec->reloc_count;
710 for (rel = relocs; rel < rel_end; rel++)
712 struct elf_link_hash_entry *h;
713 unsigned long r_symndx;
715 r_symndx = ELF32_R_SYM (rel->r_info);
716 if (r_symndx < symtab_hdr->sh_info)
720 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
721 while (h->root.type == bfd_link_hash_indirect
722 || h->root.type == bfd_link_hash_warning)
723 h = (struct elf_link_hash_entry *) h->root.u.i.link;
726 /* Some relocs require a global offset table. */
729 switch (ELF32_R_TYPE (rel->r_info))
731 case R_MN10300_GOT32:
732 case R_MN10300_GOT24:
733 case R_MN10300_GOT16:
734 case R_MN10300_GOTOFF32:
735 case R_MN10300_GOTOFF24:
736 case R_MN10300_GOTOFF16:
737 case R_MN10300_GOTPC32:
738 case R_MN10300_GOTPC16:
739 elf_hash_table (info)->dynobj = dynobj = abfd;
740 if (! _bfd_mn10300_elf_create_got_section (dynobj, info))
749 switch (ELF32_R_TYPE (rel->r_info))
751 /* This relocation describes the C++ object vtable hierarchy.
752 Reconstruct it for later use during GC. */
753 case R_MN10300_GNU_VTINHERIT:
754 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
758 /* This relocation describes which C++ vtable entries are actually
759 used. Record for later use during GC. */
760 case R_MN10300_GNU_VTENTRY:
761 BFD_ASSERT (h != NULL);
763 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
766 case R_MN10300_GOT32:
767 case R_MN10300_GOT24:
768 case R_MN10300_GOT16:
769 /* This symbol requires a global offset table entry. */
773 sgot = bfd_get_section_by_name (dynobj, ".got");
774 BFD_ASSERT (sgot != NULL);
778 && (h != NULL || info->shared))
780 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
783 srelgot = bfd_make_section_with_flags (dynobj,
792 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
799 if (h->got.offset != (bfd_vma) -1)
800 /* We have already allocated space in the .got. */
803 h->got.offset = sgot->size;
805 /* Make sure this symbol is output as a dynamic symbol. */
806 if (h->dynindx == -1)
808 if (! bfd_elf_link_record_dynamic_symbol (info, h))
812 srelgot->size += sizeof (Elf32_External_Rela);
816 /* This is a global offset table entry for a local
818 if (local_got_offsets == NULL)
823 size = symtab_hdr->sh_info * sizeof (bfd_vma);
824 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
826 if (local_got_offsets == NULL)
828 elf_local_got_offsets (abfd) = local_got_offsets;
830 for (i = 0; i < symtab_hdr->sh_info; i++)
831 local_got_offsets[i] = (bfd_vma) -1;
834 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
835 /* We have already allocated space in the .got. */
838 local_got_offsets[r_symndx] = sgot->size;
841 /* If we are generating a shared object, we need to
842 output a R_MN10300_RELATIVE reloc so that the dynamic
843 linker can adjust this GOT entry. */
844 srelgot->size += sizeof (Elf32_External_Rela);
851 case R_MN10300_PLT32:
852 case R_MN10300_PLT16:
853 /* This symbol requires a procedure linkage table entry. We
854 actually build the entry in adjust_dynamic_symbol,
855 because this might be a case of linking PIC code which is
856 never referenced by a dynamic object, in which case we
857 don't need to generate a procedure linkage table entry
860 /* If this is a local symbol, we resolve it directly without
861 creating a procedure linkage table entry. */
865 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
866 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
876 case R_MN10300_PCREL32:
877 case R_MN10300_PCREL16:
878 case R_MN10300_PCREL8:
887 /* If we are creating a shared library, then we need to copy
888 the reloc into the shared library. */
890 && (sec->flags & SEC_ALLOC) != 0)
892 /* When creating a shared object, we must copy these
893 reloc types into the output file. We create a reloc
894 section in dynobj and make room for this reloc. */
899 name = (bfd_elf_string_from_elf_section
901 elf_elfheader (abfd)->e_shstrndx,
902 elf_section_data (sec)->rel_hdr.sh_name));
906 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
907 && strcmp (bfd_get_section_name (abfd, sec),
910 sreloc = bfd_get_section_by_name (dynobj, name);
915 flags = (SEC_HAS_CONTENTS | SEC_READONLY
916 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
917 if ((sec->flags & SEC_ALLOC) != 0)
918 flags |= SEC_ALLOC | SEC_LOAD;
919 sreloc = bfd_make_section_with_flags (dynobj,
923 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
928 sreloc->size += sizeof (Elf32_External_Rela);
938 /* Return the section that should be marked against GC for a given
942 mn10300_elf_gc_mark_hook (asection *sec,
943 struct bfd_link_info *info,
944 Elf_Internal_Rela *rel,
945 struct elf_link_hash_entry *h,
946 Elf_Internal_Sym *sym)
949 switch (ELF32_R_TYPE (rel->r_info))
951 case R_MN10300_GNU_VTINHERIT:
952 case R_MN10300_GNU_VTENTRY:
956 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
959 /* Perform a relocation as part of a final link. */
960 static bfd_reloc_status_type
961 mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
962 input_section, contents, offset, value,
963 addend, h, symndx, info, sym_sec, is_local)
964 reloc_howto_type *howto;
966 bfd *output_bfd ATTRIBUTE_UNUSED;
967 asection *input_section;
972 struct elf_link_hash_entry * h;
973 unsigned long symndx;
974 struct bfd_link_info *info;
975 asection *sym_sec ATTRIBUTE_UNUSED;
976 int is_local ATTRIBUTE_UNUSED;
978 unsigned long r_type = howto->type;
979 bfd_byte *hit_data = contents + offset;
981 bfd_vma * local_got_offsets;
986 dynobj = elf_hash_table (info)->dynobj;
987 local_got_offsets = elf_local_got_offsets (input_bfd);
998 case R_MN10300_PCREL8:
999 case R_MN10300_PCREL16:
1000 case R_MN10300_PCREL32:
1001 case R_MN10300_GOTOFF32:
1002 case R_MN10300_GOTOFF24:
1003 case R_MN10300_GOTOFF16:
1005 && (input_section->flags & SEC_ALLOC) != 0
1007 && ! SYMBOL_REFERENCES_LOCAL (info, h))
1008 return bfd_reloc_dangerous;
1013 case R_MN10300_NONE:
1014 return bfd_reloc_ok;
1018 && (input_section->flags & SEC_ALLOC) != 0)
1020 Elf_Internal_Rela outrel;
1021 bfd_boolean skip, relocate;
1023 /* When generating a shared object, these relocations are
1024 copied into the output file to be resolved at run
1030 name = (bfd_elf_string_from_elf_section
1032 elf_elfheader (input_bfd)->e_shstrndx,
1033 elf_section_data (input_section)->rel_hdr.sh_name));
1037 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
1038 && strcmp (bfd_get_section_name (input_bfd,
1042 sreloc = bfd_get_section_by_name (dynobj, name);
1043 BFD_ASSERT (sreloc != NULL);
1048 outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
1049 input_section, offset);
1050 if (outrel.r_offset == (bfd_vma) -1)
1053 outrel.r_offset += (input_section->output_section->vma
1054 + input_section->output_offset);
1058 memset (&outrel, 0, sizeof outrel);
1063 /* h->dynindx may be -1 if this symbol was marked to
1066 || SYMBOL_REFERENCES_LOCAL (info, h))
1069 outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1070 outrel.r_addend = value + addend;
1074 BFD_ASSERT (h->dynindx != -1);
1076 outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32);
1077 outrel.r_addend = value + addend;
1081 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1082 (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
1083 + sreloc->reloc_count));
1084 ++sreloc->reloc_count;
1086 /* If this reloc is against an external symbol, we do
1087 not want to fiddle with the addend. Otherwise, we
1088 need to include the symbol value so that it becomes
1089 an addend for the dynamic reloc. */
1091 return bfd_reloc_ok;
1094 bfd_put_32 (input_bfd, value, hit_data);
1095 return bfd_reloc_ok;
1100 if ((long) value > 0x7fffff || (long) value < -0x800000)
1101 return bfd_reloc_overflow;
1103 bfd_put_8 (input_bfd, value & 0xff, hit_data);
1104 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1105 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1106 return bfd_reloc_ok;
1111 if ((long) value > 0x7fff || (long) value < -0x8000)
1112 return bfd_reloc_overflow;
1114 bfd_put_16 (input_bfd, value, hit_data);
1115 return bfd_reloc_ok;
1120 if ((long) value > 0x7f || (long) value < -0x80)
1121 return bfd_reloc_overflow;
1123 bfd_put_8 (input_bfd, value, hit_data);
1124 return bfd_reloc_ok;
1126 case R_MN10300_PCREL8:
1127 value -= (input_section->output_section->vma
1128 + input_section->output_offset);
1132 if ((long) value > 0xff || (long) value < -0x100)
1133 return bfd_reloc_overflow;
1135 bfd_put_8 (input_bfd, value, hit_data);
1136 return bfd_reloc_ok;
1138 case R_MN10300_PCREL16:
1139 value -= (input_section->output_section->vma
1140 + input_section->output_offset);
1144 if ((long) value > 0xffff || (long) value < -0x10000)
1145 return bfd_reloc_overflow;
1147 bfd_put_16 (input_bfd, value, hit_data);
1148 return bfd_reloc_ok;
1150 case R_MN10300_PCREL32:
1151 value -= (input_section->output_section->vma
1152 + input_section->output_offset);
1156 bfd_put_32 (input_bfd, value, hit_data);
1157 return bfd_reloc_ok;
1159 case R_MN10300_GNU_VTINHERIT:
1160 case R_MN10300_GNU_VTENTRY:
1161 return bfd_reloc_ok;
1163 case R_MN10300_GOTPC32:
1164 /* Use global offset table as symbol value. */
1166 value = bfd_get_section_by_name (dynobj,
1167 ".got")->output_section->vma;
1168 value -= (input_section->output_section->vma
1169 + input_section->output_offset);
1173 bfd_put_32 (input_bfd, value, hit_data);
1174 return bfd_reloc_ok;
1176 case R_MN10300_GOTPC16:
1177 /* Use global offset table as symbol value. */
1179 value = bfd_get_section_by_name (dynobj,
1180 ".got")->output_section->vma;
1181 value -= (input_section->output_section->vma
1182 + input_section->output_offset);
1186 if ((long) value > 0xffff || (long) value < -0x10000)
1187 return bfd_reloc_overflow;
1189 bfd_put_16 (input_bfd, value, hit_data);
1190 return bfd_reloc_ok;
1192 case R_MN10300_GOTOFF32:
1193 value -= bfd_get_section_by_name (dynobj,
1194 ".got")->output_section->vma;
1197 bfd_put_32 (input_bfd, value, hit_data);
1198 return bfd_reloc_ok;
1200 case R_MN10300_GOTOFF24:
1201 value -= bfd_get_section_by_name (dynobj,
1202 ".got")->output_section->vma;
1205 if ((long) value > 0x7fffff || (long) value < -0x800000)
1206 return bfd_reloc_overflow;
1208 bfd_put_8 (input_bfd, value, hit_data);
1209 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1210 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1211 return bfd_reloc_ok;
1213 case R_MN10300_GOTOFF16:
1214 value -= bfd_get_section_by_name (dynobj,
1215 ".got")->output_section->vma;
1218 if ((long) value > 0xffff || (long) value < -0x10000)
1219 return bfd_reloc_overflow;
1221 bfd_put_16 (input_bfd, value, hit_data);
1222 return bfd_reloc_ok;
1224 case R_MN10300_PLT32:
1226 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1227 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1228 && h->plt.offset != (bfd_vma) -1)
1232 splt = bfd_get_section_by_name (dynobj, ".plt");
1234 value = (splt->output_section->vma
1235 + splt->output_offset
1236 + h->plt.offset) - value;
1239 value -= (input_section->output_section->vma
1240 + input_section->output_offset);
1244 bfd_put_32 (input_bfd, value, hit_data);
1245 return bfd_reloc_ok;
1247 case R_MN10300_PLT16:
1249 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1250 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1251 && h->plt.offset != (bfd_vma) -1)
1255 splt = bfd_get_section_by_name (dynobj, ".plt");
1257 value = (splt->output_section->vma
1258 + splt->output_offset
1259 + h->plt.offset) - value;
1262 value -= (input_section->output_section->vma
1263 + input_section->output_offset);
1267 if ((long) value > 0xffff || (long) value < -0x10000)
1268 return bfd_reloc_overflow;
1270 bfd_put_16 (input_bfd, value, hit_data);
1271 return bfd_reloc_ok;
1273 case R_MN10300_GOT32:
1274 case R_MN10300_GOT24:
1275 case R_MN10300_GOT16:
1279 sgot = bfd_get_section_by_name (dynobj, ".got");
1285 off = h->got.offset;
1286 BFD_ASSERT (off != (bfd_vma) -1);
1288 if (! elf_hash_table (info)->dynamic_sections_created
1289 || SYMBOL_REFERENCES_LOCAL (info, h))
1290 /* This is actually a static link, or it is a
1291 -Bsymbolic link and the symbol is defined
1292 locally, or the symbol was forced to be local
1293 because of a version file. We must initialize
1294 this entry in the global offset table.
1296 When doing a dynamic link, we create a .rela.got
1297 relocation entry to initialize the value. This
1298 is done in the finish_dynamic_symbol routine. */
1299 bfd_put_32 (output_bfd, value,
1300 sgot->contents + off);
1302 value = sgot->output_offset + off;
1308 off = elf_local_got_offsets (input_bfd)[symndx];
1310 bfd_put_32 (output_bfd, value, sgot->contents + off);
1315 Elf_Internal_Rela outrel;
1317 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1318 BFD_ASSERT (srelgot != NULL);
1320 outrel.r_offset = (sgot->output_section->vma
1321 + sgot->output_offset
1323 outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1324 outrel.r_addend = value;
1325 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1326 (bfd_byte *) (((Elf32_External_Rela *)
1328 + srelgot->reloc_count));
1329 ++ srelgot->reloc_count;
1332 value = sgot->output_offset + off;
1338 if (r_type == R_MN10300_GOT32)
1340 bfd_put_32 (input_bfd, value, hit_data);
1341 return bfd_reloc_ok;
1343 else if (r_type == R_MN10300_GOT24)
1345 if ((long) value > 0x7fffff || (long) value < -0x800000)
1346 return bfd_reloc_overflow;
1348 bfd_put_8 (input_bfd, value & 0xff, hit_data);
1349 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1350 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1351 return bfd_reloc_ok;
1353 else if (r_type == R_MN10300_GOT16)
1355 if ((long) value > 0xffff || (long) value < -0x10000)
1356 return bfd_reloc_overflow;
1358 bfd_put_16 (input_bfd, value, hit_data);
1359 return bfd_reloc_ok;
1364 return bfd_reloc_notsupported;
1368 /* Relocate an MN10300 ELF section. */
1370 mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1371 contents, relocs, local_syms, local_sections)
1373 struct bfd_link_info *info;
1375 asection *input_section;
1377 Elf_Internal_Rela *relocs;
1378 Elf_Internal_Sym *local_syms;
1379 asection **local_sections;
1381 Elf_Internal_Shdr *symtab_hdr;
1382 struct elf_link_hash_entry **sym_hashes;
1383 Elf_Internal_Rela *rel, *relend;
1385 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1386 sym_hashes = elf_sym_hashes (input_bfd);
1389 relend = relocs + input_section->reloc_count;
1390 for (; rel < relend; rel++)
1393 reloc_howto_type *howto;
1394 unsigned long r_symndx;
1395 Elf_Internal_Sym *sym;
1397 struct elf32_mn10300_link_hash_entry *h;
1399 bfd_reloc_status_type r;
1401 r_symndx = ELF32_R_SYM (rel->r_info);
1402 r_type = ELF32_R_TYPE (rel->r_info);
1403 howto = elf_mn10300_howto_table + r_type;
1405 /* Just skip the vtable gc relocs. */
1406 if (r_type == R_MN10300_GNU_VTINHERIT
1407 || r_type == R_MN10300_GNU_VTENTRY)
1413 if (r_symndx < symtab_hdr->sh_info)
1415 sym = local_syms + r_symndx;
1416 sec = local_sections[r_symndx];
1417 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1421 bfd_boolean unresolved_reloc;
1423 struct elf_link_hash_entry *hh;
1425 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1426 r_symndx, symtab_hdr, sym_hashes,
1427 hh, sec, relocation,
1428 unresolved_reloc, warned);
1430 h = (struct elf32_mn10300_link_hash_entry *) hh;
1432 if ((h->root.root.type == bfd_link_hash_defined
1433 || h->root.root.type == bfd_link_hash_defweak)
1434 && ( r_type == R_MN10300_GOTPC32
1435 || r_type == R_MN10300_GOTPC16
1436 || (( r_type == R_MN10300_PLT32
1437 || r_type == R_MN10300_PLT16)
1438 && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
1439 && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
1440 && h->root.plt.offset != (bfd_vma) -1)
1441 || (( r_type == R_MN10300_GOT32
1442 || r_type == R_MN10300_GOT24
1443 || r_type == R_MN10300_GOT16)
1444 && elf_hash_table (info)->dynamic_sections_created
1445 && !SYMBOL_REFERENCES_LOCAL (info, hh))
1446 || (r_type == R_MN10300_32
1447 && !SYMBOL_REFERENCES_LOCAL (info, hh)
1448 && ((input_section->flags & SEC_ALLOC) != 0
1449 /* DWARF will emit R_MN10300_32 relocations
1450 in its sections against symbols defined
1451 externally in shared libraries. We can't
1452 do anything with them here. */
1453 || ((input_section->flags & SEC_DEBUGGING) != 0
1454 && h->root.def_dynamic)))))
1455 /* In these cases, we don't need the relocation
1456 value. We check specially because in some
1457 obscure cases sec->output_section will be NULL. */
1460 else if (!info->relocatable && unresolved_reloc)
1461 (*_bfd_error_handler)
1462 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1465 (long) rel->r_offset,
1467 h->root.root.root.string);
1470 if (sec != NULL && elf_discarded_section (sec))
1472 /* For relocs against symbols from removed linkonce sections,
1473 or sections discarded by a linker script, we just want the
1474 section contents zeroed. Avoid any special processing. */
1475 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
1481 if (info->relocatable)
1484 r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
1486 contents, rel->r_offset,
1487 relocation, rel->r_addend,
1488 (struct elf_link_hash_entry *)h,
1490 info, sec, h == NULL);
1492 if (r != bfd_reloc_ok)
1495 const char *msg = (const char *) 0;
1498 name = h->root.root.root.string;
1501 name = (bfd_elf_string_from_elf_section
1502 (input_bfd, symtab_hdr->sh_link, sym->st_name));
1503 if (name == NULL || *name == '\0')
1504 name = bfd_section_name (input_bfd, sec);
1509 case bfd_reloc_overflow:
1510 if (! ((*info->callbacks->reloc_overflow)
1511 (info, (h ? &h->root.root : NULL), name,
1512 howto->name, (bfd_vma) 0, input_bfd,
1513 input_section, rel->r_offset)))
1517 case bfd_reloc_undefined:
1518 if (! ((*info->callbacks->undefined_symbol)
1519 (info, name, input_bfd, input_section,
1520 rel->r_offset, TRUE)))
1524 case bfd_reloc_outofrange:
1525 msg = _("internal error: out of range error");
1528 case bfd_reloc_notsupported:
1529 msg = _("internal error: unsupported relocation error");
1532 case bfd_reloc_dangerous:
1533 if (r_type == R_MN10300_PCREL32)
1534 msg = _("error: inappropriate relocation type for shared"
1535 " library (did you forget -fpic?)");
1537 msg = _("internal error: suspicious relocation type used"
1538 " in shared library");
1542 msg = _("internal error: unknown error");
1546 if (!((*info->callbacks->warning)
1547 (info, msg, name, input_bfd, input_section,
1558 /* Finish initializing one hash table entry. */
1560 elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
1561 struct bfd_hash_entry *gen_entry;
1564 struct elf32_mn10300_link_hash_entry *entry;
1565 struct bfd_link_info *link_info = (struct bfd_link_info *)in_args;
1566 unsigned int byte_count = 0;
1568 entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
1570 if (entry->root.root.type == bfd_link_hash_warning)
1571 entry = (struct elf32_mn10300_link_hash_entry *) entry->root.root.u.i.link;
1573 /* If we already know we want to convert "call" to "calls" for calls
1574 to this symbol, then return now. */
1575 if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
1578 /* If there are no named calls to this symbol, or there's nothing we
1579 can move from the function itself into the "call" instruction,
1580 then note that all "call" instructions should be converted into
1581 "calls" instructions and return. If a symbol is available for
1582 dynamic symbol resolution (overridable or overriding), avoid
1583 custom calling conventions. */
1584 if (entry->direct_calls == 0
1585 || (entry->stack_size == 0 && entry->movm_args == 0)
1586 || (elf_hash_table (link_info)->dynamic_sections_created
1587 && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
1588 && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
1590 /* Make a note that we should convert "call" instructions to "calls"
1591 instructions for calls to this symbol. */
1592 entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1596 /* We may be able to move some instructions from the function itself into
1597 the "call" instruction. Count how many bytes we might be able to
1598 eliminate in the function itself. */
1600 /* A movm instruction is two bytes. */
1601 if (entry->movm_args)
1604 /* Count the insn to allocate stack space too. */
1605 if (entry->stack_size > 0)
1607 if (entry->stack_size <= 128)
1613 /* If using "call" will result in larger code, then turn all
1614 the associated "call" instructions into "calls" instructions. */
1615 if (byte_count < entry->direct_calls)
1616 entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1618 /* This routine never fails. */
1622 /* Used to count hash table entries. */
1624 elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED,
1627 int *count = (int *)in_args;
1633 /* Used to enumerate hash table entries into a linear array. */
1635 elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry,
1638 struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args;
1645 /* Used to sort the array created by the above. */
1647 sort_by_value (const void *va, const void *vb)
1649 struct elf32_mn10300_link_hash_entry *a
1650 = *(struct elf32_mn10300_link_hash_entry **)va;
1651 struct elf32_mn10300_link_hash_entry *b
1652 = *(struct elf32_mn10300_link_hash_entry **)vb;
1654 return a->value - b->value;
1658 /* This function handles relaxing for the mn10300.
1660 There are quite a few relaxing opportunities available on the mn10300:
1662 * calls:32 -> calls:16 2 bytes
1663 * call:32 -> call:16 2 bytes
1665 * call:32 -> calls:32 1 byte
1666 * call:16 -> calls:16 1 byte
1667 * These are done anytime using "calls" would result
1668 in smaller code, or when necessary to preserve the
1669 meaning of the program.
1673 * In some circumstances we can move instructions
1674 from a function prologue into a "call" instruction.
1675 This is only done if the resulting code is no larger
1676 than the original code.
1678 * jmp:32 -> jmp:16 2 bytes
1679 * jmp:16 -> bra:8 1 byte
1681 * If the previous instruction is a conditional branch
1682 around the jump/bra, we may be able to reverse its condition
1683 and change its target to the jump's target. The jump/bra
1684 can then be deleted. 2 bytes
1686 * mov abs32 -> mov abs16 1 or 2 bytes
1688 * Most instructions which accept imm32 can relax to imm16 1 or 2 bytes
1689 - Most instructions which accept imm16 can relax to imm8 1 or 2 bytes
1691 * Most instructions which accept d32 can relax to d16 1 or 2 bytes
1692 - Most instructions which accept d16 can relax to d8 1 or 2 bytes
1694 We don't handle imm16->imm8 or d16->d8 as they're very rare
1695 and somewhat more difficult to support. */
1698 mn10300_elf_relax_section (abfd, sec, link_info, again)
1701 struct bfd_link_info *link_info;
1704 Elf_Internal_Shdr *symtab_hdr;
1705 Elf_Internal_Rela *internal_relocs = NULL;
1706 Elf_Internal_Rela *irel, *irelend;
1707 bfd_byte *contents = NULL;
1708 Elf_Internal_Sym *isymbuf = NULL;
1709 struct elf32_mn10300_link_hash_table *hash_table;
1710 asection *section = sec;
1712 /* Assume nothing changes. */
1715 /* We need a pointer to the mn10300 specific hash table. */
1716 hash_table = elf32_mn10300_hash_table (link_info);
1718 /* Initialize fields in each hash table entry the first time through. */
1719 if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0)
1723 /* Iterate over all the input bfds. */
1724 for (input_bfd = link_info->input_bfds;
1726 input_bfd = input_bfd->link_next)
1728 /* We're going to need all the symbols for each bfd. */
1729 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1730 if (symtab_hdr->sh_info != 0)
1732 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1733 if (isymbuf == NULL)
1734 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
1735 symtab_hdr->sh_info, 0,
1737 if (isymbuf == NULL)
1741 /* Iterate over each section in this bfd. */
1742 for (section = input_bfd->sections;
1744 section = section->next)
1746 struct elf32_mn10300_link_hash_entry *hash;
1747 Elf_Internal_Sym *sym;
1748 asection *sym_sec = NULL;
1749 const char *sym_name;
1752 /* If there's nothing to do in this section, skip it. */
1753 if (! ((section->flags & SEC_RELOC) != 0
1754 && section->reloc_count != 0))
1756 if ((section->flags & SEC_ALLOC) == 0)
1759 /* Get cached copy of section contents if it exists. */
1760 if (elf_section_data (section)->this_hdr.contents != NULL)
1761 contents = elf_section_data (section)->this_hdr.contents;
1762 else if (section->size != 0)
1764 /* Go get them off disk. */
1765 if (!bfd_malloc_and_get_section (input_bfd, section,
1772 /* If there aren't any relocs, then there's nothing to do. */
1773 if ((section->flags & SEC_RELOC) != 0
1774 && section->reloc_count != 0)
1777 /* Get a copy of the native relocations. */
1778 internal_relocs = (_bfd_elf_link_read_relocs
1779 (input_bfd, section, (PTR) NULL,
1780 (Elf_Internal_Rela *) NULL,
1781 link_info->keep_memory));
1782 if (internal_relocs == NULL)
1785 /* Now examine each relocation. */
1786 irel = internal_relocs;
1787 irelend = irel + section->reloc_count;
1788 for (; irel < irelend; irel++)
1791 unsigned long r_index;
1794 r_type = ELF32_R_TYPE (irel->r_info);
1795 r_index = ELF32_R_SYM (irel->r_info);
1797 if (r_type < 0 || r_type >= (int) R_MN10300_MAX)
1800 /* We need the name and hash table entry of the target
1806 if (r_index < symtab_hdr->sh_info)
1808 /* A local symbol. */
1809 Elf_Internal_Sym *isym;
1810 struct elf_link_hash_table *elftab;
1813 isym = isymbuf + r_index;
1814 if (isym->st_shndx == SHN_UNDEF)
1815 sym_sec = bfd_und_section_ptr;
1816 else if (isym->st_shndx == SHN_ABS)
1817 sym_sec = bfd_abs_section_ptr;
1818 else if (isym->st_shndx == SHN_COMMON)
1819 sym_sec = bfd_com_section_ptr;
1822 = bfd_section_from_elf_index (input_bfd,
1826 = bfd_elf_string_from_elf_section (input_bfd,
1831 /* If it isn't a function, then we don't care
1833 if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
1836 /* Tack on an ID so we can uniquely identify this
1837 local symbol in the global hash table. */
1838 amt = strlen (sym_name) + 10;
1839 new_name = bfd_malloc (amt);
1843 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
1844 sym_name = new_name;
1846 elftab = &hash_table->static_hash_table->root;
1847 hash = ((struct elf32_mn10300_link_hash_entry *)
1848 elf_link_hash_lookup (elftab, sym_name,
1849 TRUE, TRUE, FALSE));
1854 r_index -= symtab_hdr->sh_info;
1855 hash = (struct elf32_mn10300_link_hash_entry *)
1856 elf_sym_hashes (input_bfd)[r_index];
1859 sym_name = hash->root.root.root.string;
1860 if ((section->flags & SEC_CODE) != 0)
1862 /* If this is not a "call" instruction, then we
1863 should convert "call" instructions to "calls"
1865 code = bfd_get_8 (input_bfd,
1866 contents + irel->r_offset - 1);
1867 if (code != 0xdd && code != 0xcd)
1868 hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1871 /* If this is a jump/call, then bump the
1872 direct_calls counter. Else force "call" to
1873 "calls" conversions. */
1874 if (r_type == R_MN10300_PCREL32
1875 || r_type == R_MN10300_PLT32
1876 || r_type == R_MN10300_PLT16
1877 || r_type == R_MN10300_PCREL16)
1878 hash->direct_calls++;
1880 hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1884 /* Now look at the actual contents to get the stack size,
1885 and a list of what registers were saved in the prologue
1887 if ((section->flags & SEC_CODE) != 0)
1889 Elf_Internal_Sym *isym, *isymend;
1890 unsigned int sec_shndx;
1891 struct elf_link_hash_entry **hashes;
1892 struct elf_link_hash_entry **end_hashes;
1893 unsigned int symcount;
1895 sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
1898 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1899 - symtab_hdr->sh_info);
1900 hashes = elf_sym_hashes (input_bfd);
1901 end_hashes = hashes + symcount;
1903 /* Look at each function defined in this section and
1904 update info for that function. */
1905 isymend = isymbuf + symtab_hdr->sh_info;
1906 for (isym = isymbuf; isym < isymend; isym++)
1908 if (isym->st_shndx == sec_shndx
1909 && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
1911 struct elf_link_hash_table *elftab;
1913 struct elf_link_hash_entry **lhashes = hashes;
1915 /* Skip a local symbol if it aliases a
1917 for (; lhashes < end_hashes; lhashes++)
1919 hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
1920 if ((hash->root.root.type == bfd_link_hash_defined
1921 || hash->root.root.type == bfd_link_hash_defweak)
1922 && hash->root.root.u.def.section == section
1923 && hash->root.type == STT_FUNC
1924 && hash->root.root.u.def.value == isym->st_value)
1927 if (lhashes != end_hashes)
1930 if (isym->st_shndx == SHN_UNDEF)
1931 sym_sec = bfd_und_section_ptr;
1932 else if (isym->st_shndx == SHN_ABS)
1933 sym_sec = bfd_abs_section_ptr;
1934 else if (isym->st_shndx == SHN_COMMON)
1935 sym_sec = bfd_com_section_ptr;
1938 = bfd_section_from_elf_index (input_bfd,
1941 sym_name = (bfd_elf_string_from_elf_section
1942 (input_bfd, symtab_hdr->sh_link,
1945 /* Tack on an ID so we can uniquely identify this
1946 local symbol in the global hash table. */
1947 amt = strlen (sym_name) + 10;
1948 new_name = bfd_malloc (amt);
1952 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
1953 sym_name = new_name;
1955 elftab = &hash_table->static_hash_table->root;
1956 hash = ((struct elf32_mn10300_link_hash_entry *)
1957 elf_link_hash_lookup (elftab, sym_name,
1958 TRUE, TRUE, FALSE));
1960 compute_function_info (input_bfd, hash,
1961 isym->st_value, contents);
1962 hash->value = isym->st_value;
1966 for (; hashes < end_hashes; hashes++)
1968 hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
1969 if ((hash->root.root.type == bfd_link_hash_defined
1970 || hash->root.root.type == bfd_link_hash_defweak)
1971 && hash->root.root.u.def.section == section
1972 && hash->root.type == STT_FUNC)
1973 compute_function_info (input_bfd, hash,
1974 (hash)->root.root.u.def.value,
1979 /* Cache or free any memory we allocated for the relocs. */
1980 if (internal_relocs != NULL
1981 && elf_section_data (section)->relocs != internal_relocs)
1982 free (internal_relocs);
1983 internal_relocs = NULL;
1985 /* Cache or free any memory we allocated for the contents. */
1986 if (contents != NULL
1987 && elf_section_data (section)->this_hdr.contents != contents)
1989 if (! link_info->keep_memory)
1993 /* Cache the section contents for elf_link_input_bfd. */
1994 elf_section_data (section)->this_hdr.contents = contents;
2000 /* Cache or free any memory we allocated for the symbols. */
2002 && symtab_hdr->contents != (unsigned char *) isymbuf)
2004 if (! link_info->keep_memory)
2008 /* Cache the symbols for elf_link_input_bfd. */
2009 symtab_hdr->contents = (unsigned char *) isymbuf;
2015 /* Now iterate on each symbol in the hash table and perform
2016 the final initialization steps on each. */
2017 elf32_mn10300_link_hash_traverse (hash_table,
2018 elf32_mn10300_finish_hash_table_entry,
2020 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2021 elf32_mn10300_finish_hash_table_entry,
2025 /* This section of code collects all our local symbols, sorts
2026 them by value, and looks for multiple symbols referring to
2027 the same address. For those symbols, the flags are merged.
2028 At this point, the only flag that can be set is
2029 MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
2031 int static_count = 0, i;
2032 struct elf32_mn10300_link_hash_entry **entries;
2033 struct elf32_mn10300_link_hash_entry **ptr;
2035 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2036 elf32_mn10300_count_hash_table_entries,
2039 entries = (struct elf32_mn10300_link_hash_entry **)
2040 bfd_malloc (static_count * sizeof (struct elf32_mn10300_link_hash_entry *));
2043 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2044 elf32_mn10300_list_hash_table_entries,
2047 qsort (entries, static_count, sizeof(entries[0]), sort_by_value);
2049 for (i=0; i<static_count-1; i++)
2050 if (entries[i]->value && entries[i]->value == entries[i+1]->value)
2052 int v = entries[i]->flags;
2054 for (j=i+1; j<static_count && entries[j]->value == entries[i]->value; j++)
2055 v |= entries[j]->flags;
2056 for (j=i; j<static_count && entries[j]->value == entries[i]->value; j++)
2057 entries[j]->flags = v;
2062 /* All entries in the hash table are fully initialized. */
2063 hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
2065 /* Now that everything has been initialized, go through each
2066 code section and delete any prologue insns which will be
2067 redundant because their operations will be performed by
2068 a "call" instruction. */
2069 for (input_bfd = link_info->input_bfds;
2071 input_bfd = input_bfd->link_next)
2073 /* We're going to need all the local symbols for each bfd. */
2074 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2075 if (symtab_hdr->sh_info != 0)
2077 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2078 if (isymbuf == NULL)
2079 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2080 symtab_hdr->sh_info, 0,
2082 if (isymbuf == NULL)
2086 /* Walk over each section in this bfd. */
2087 for (section = input_bfd->sections;
2089 section = section->next)
2091 unsigned int sec_shndx;
2092 Elf_Internal_Sym *isym, *isymend;
2093 struct elf_link_hash_entry **hashes;
2094 struct elf_link_hash_entry **end_hashes;
2095 unsigned int symcount;
2097 /* Skip non-code sections and empty sections. */
2098 if ((section->flags & SEC_CODE) == 0 || section->size == 0)
2101 if (section->reloc_count != 0)
2103 /* Get a copy of the native relocations. */
2104 internal_relocs = (_bfd_elf_link_read_relocs
2105 (input_bfd, section, (PTR) NULL,
2106 (Elf_Internal_Rela *) NULL,
2107 link_info->keep_memory));
2108 if (internal_relocs == NULL)
2112 /* Get cached copy of section contents if it exists. */
2113 if (elf_section_data (section)->this_hdr.contents != NULL)
2114 contents = elf_section_data (section)->this_hdr.contents;
2117 /* Go get them off disk. */
2118 if (!bfd_malloc_and_get_section (input_bfd, section,
2123 sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
2126 /* Now look for any function in this section which needs
2127 insns deleted from its prologue. */
2128 isymend = isymbuf + symtab_hdr->sh_info;
2129 for (isym = isymbuf; isym < isymend; isym++)
2131 struct elf32_mn10300_link_hash_entry *sym_hash;
2132 asection *sym_sec = NULL;
2133 const char *sym_name;
2135 struct elf_link_hash_table *elftab;
2138 if (isym->st_shndx != sec_shndx)
2141 if (isym->st_shndx == SHN_UNDEF)
2142 sym_sec = bfd_und_section_ptr;
2143 else if (isym->st_shndx == SHN_ABS)
2144 sym_sec = bfd_abs_section_ptr;
2145 else if (isym->st_shndx == SHN_COMMON)
2146 sym_sec = bfd_com_section_ptr;
2149 = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
2152 = bfd_elf_string_from_elf_section (input_bfd,
2153 symtab_hdr->sh_link,
2156 /* Tack on an ID so we can uniquely identify this
2157 local symbol in the global hash table. */
2158 amt = strlen (sym_name) + 10;
2159 new_name = bfd_malloc (amt);
2162 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2163 sym_name = new_name;
2165 elftab = &hash_table->static_hash_table->root;
2166 sym_hash = ((struct elf32_mn10300_link_hash_entry *)
2167 elf_link_hash_lookup (elftab, sym_name,
2168 FALSE, FALSE, FALSE));
2171 if (sym_hash == NULL)
2174 if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
2175 && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
2179 /* Note that we've changed things. */
2180 elf_section_data (section)->relocs = internal_relocs;
2181 elf_section_data (section)->this_hdr.contents = contents;
2182 symtab_hdr->contents = (unsigned char *) isymbuf;
2184 /* Count how many bytes we're going to delete. */
2185 if (sym_hash->movm_args)
2188 if (sym_hash->stack_size > 0)
2190 if (sym_hash->stack_size <= 128)
2196 /* Note that we've deleted prologue bytes for this
2198 sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
2200 /* Actually delete the bytes. */
2201 if (!mn10300_elf_relax_delete_bytes (input_bfd,
2207 /* Something changed. Not strictly necessary, but
2208 may lead to more relaxing opportunities. */
2213 /* Look for any global functions in this section which
2214 need insns deleted from their prologues. */
2215 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2216 - symtab_hdr->sh_info);
2217 hashes = elf_sym_hashes (input_bfd);
2218 end_hashes = hashes + symcount;
2219 for (; hashes < end_hashes; hashes++)
2221 struct elf32_mn10300_link_hash_entry *sym_hash;
2223 sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
2224 if ((sym_hash->root.root.type == bfd_link_hash_defined
2225 || sym_hash->root.root.type == bfd_link_hash_defweak)
2226 && sym_hash->root.root.u.def.section == section
2227 && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
2228 && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
2233 /* Note that we've changed things. */
2234 elf_section_data (section)->relocs = internal_relocs;
2235 elf_section_data (section)->this_hdr.contents = contents;
2236 symtab_hdr->contents = (unsigned char *) isymbuf;
2238 /* Count how many bytes we're going to delete. */
2239 if (sym_hash->movm_args)
2242 if (sym_hash->stack_size > 0)
2244 if (sym_hash->stack_size <= 128)
2250 /* Note that we've deleted prologue bytes for this
2252 sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
2254 /* Actually delete the bytes. */
2255 symval = sym_hash->root.root.u.def.value;
2256 if (!mn10300_elf_relax_delete_bytes (input_bfd,
2262 /* Something changed. Not strictly necessary, but
2263 may lead to more relaxing opportunities. */
2268 /* Cache or free any memory we allocated for the relocs. */
2269 if (internal_relocs != NULL
2270 && elf_section_data (section)->relocs != internal_relocs)
2271 free (internal_relocs);
2272 internal_relocs = NULL;
2274 /* Cache or free any memory we allocated for the contents. */
2275 if (contents != NULL
2276 && elf_section_data (section)->this_hdr.contents != contents)
2278 if (! link_info->keep_memory)
2282 /* Cache the section contents for elf_link_input_bfd. */
2283 elf_section_data (section)->this_hdr.contents = contents;
2289 /* Cache or free any memory we allocated for the symbols. */
2291 && symtab_hdr->contents != (unsigned char *) isymbuf)
2293 if (! link_info->keep_memory)
2297 /* Cache the symbols for elf_link_input_bfd. */
2298 symtab_hdr->contents = (unsigned char *) isymbuf;
2305 /* (Re)initialize for the basic instruction shortening/relaxing pass. */
2307 internal_relocs = NULL;
2309 /* For error_return. */
2312 /* We don't have to do anything for a relocatable link, if
2313 this section does not have relocs, or if this is not a
2315 if (link_info->relocatable
2316 || (sec->flags & SEC_RELOC) == 0
2317 || sec->reloc_count == 0
2318 || (sec->flags & SEC_CODE) == 0)
2321 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2323 /* Get a copy of the native relocations. */
2324 internal_relocs = (_bfd_elf_link_read_relocs
2325 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2326 link_info->keep_memory));
2327 if (internal_relocs == NULL)
2330 /* Walk through them looking for relaxing opportunities. */
2331 irelend = internal_relocs + sec->reloc_count;
2332 for (irel = internal_relocs; irel < irelend; irel++)
2335 struct elf32_mn10300_link_hash_entry *h = NULL;
2337 /* If this isn't something that can be relaxed, then ignore
2339 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE
2340 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8
2341 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX)
2344 /* Get the section contents if we haven't done so already. */
2345 if (contents == NULL)
2347 /* Get cached copy if it exists. */
2348 if (elf_section_data (sec)->this_hdr.contents != NULL)
2349 contents = elf_section_data (sec)->this_hdr.contents;
2352 /* Go get them off disk. */
2353 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2358 /* Read this BFD's symbols if we haven't done so already. */
2359 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2361 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2362 if (isymbuf == NULL)
2363 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2364 symtab_hdr->sh_info, 0,
2366 if (isymbuf == NULL)
2370 /* Get the value of the symbol referred to by the reloc. */
2371 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2373 Elf_Internal_Sym *isym;
2374 asection *sym_sec = NULL;
2375 const char *sym_name;
2377 bfd_vma saved_addend;
2379 /* A local symbol. */
2380 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2381 if (isym->st_shndx == SHN_UNDEF)
2382 sym_sec = bfd_und_section_ptr;
2383 else if (isym->st_shndx == SHN_ABS)
2384 sym_sec = bfd_abs_section_ptr;
2385 else if (isym->st_shndx == SHN_COMMON)
2386 sym_sec = bfd_com_section_ptr;
2388 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2390 sym_name = bfd_elf_string_from_elf_section (abfd,
2391 symtab_hdr->sh_link,
2394 if ((sym_sec->flags & SEC_MERGE)
2395 && ELF_ST_TYPE (isym->st_info) == STT_SECTION
2396 && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
2398 saved_addend = irel->r_addend;
2399 symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
2400 symval += irel->r_addend;
2401 irel->r_addend = saved_addend;
2405 symval = (isym->st_value
2406 + sym_sec->output_section->vma
2407 + sym_sec->output_offset);
2409 /* Tack on an ID so we can uniquely identify this
2410 local symbol in the global hash table. */
2411 new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
2414 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2415 sym_name = new_name;
2417 h = (struct elf32_mn10300_link_hash_entry *)
2418 elf_link_hash_lookup (&hash_table->static_hash_table->root,
2419 sym_name, FALSE, FALSE, FALSE);
2426 /* An external symbol. */
2427 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2428 h = (struct elf32_mn10300_link_hash_entry *)
2429 (elf_sym_hashes (abfd)[indx]);
2430 BFD_ASSERT (h != NULL);
2431 if (h->root.root.type != bfd_link_hash_defined
2432 && h->root.root.type != bfd_link_hash_defweak)
2434 /* This appears to be a reference to an undefined
2435 symbol. Just ignore it--it will be caught by the
2436 regular reloc processing. */
2440 symval = (h->root.root.u.def.value
2441 + h->root.root.u.def.section->output_section->vma
2442 + h->root.root.u.def.section->output_offset);
2445 /* For simplicity of coding, we are going to modify the section
2446 contents, the section relocs, and the BFD symbol table. We
2447 must tell the rest of the code not to free up this
2448 information. It would be possible to instead create a table
2449 of changes which have to be made, as is done in coff-mips.c;
2450 that would be more work, but would require less memory when
2451 the linker is run. */
2453 /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
2454 branch/call, also deal with "call" -> "calls" conversions and
2455 insertion of prologue data into "call" instructions. */
2456 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
2457 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
2459 bfd_vma value = symval;
2461 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
2463 && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
2464 && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
2465 && h->root.plt.offset != (bfd_vma) -1)
2469 splt = bfd_get_section_by_name (elf_hash_table (link_info)
2472 value = ((splt->output_section->vma
2473 + splt->output_offset
2474 + h->root.plt.offset)
2475 - (sec->output_section->vma
2476 + sec->output_offset
2480 /* If we've got a "call" instruction that needs to be turned
2481 into a "calls" instruction, do so now. It saves a byte. */
2482 if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
2486 /* Get the opcode. */
2487 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2489 /* Make sure we're working with a "call" instruction! */
2492 /* Note that we've changed the relocs, section contents,
2494 elf_section_data (sec)->relocs = internal_relocs;
2495 elf_section_data (sec)->this_hdr.contents = contents;
2496 symtab_hdr->contents = (unsigned char *) isymbuf;
2498 /* Fix the opcode. */
2499 bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
2500 bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
2502 /* Fix irel->r_offset and irel->r_addend. */
2503 irel->r_offset += 1;
2504 irel->r_addend += 1;
2506 /* Delete one byte of data. */
2507 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2508 irel->r_offset + 3, 1))
2511 /* That will change things, so, we should relax again.
2512 Note that this is not required, and it may be slow. */
2518 /* We've got a "call" instruction which needs some data
2519 from target function filled in. */
2522 /* Get the opcode. */
2523 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2525 /* Insert data from the target function into the "call"
2526 instruction if needed. */
2529 bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4);
2530 bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
2531 contents + irel->r_offset + 5);
2535 /* Deal with pc-relative gunk. */
2536 value -= (sec->output_section->vma + sec->output_offset);
2537 value -= irel->r_offset;
2538 value += irel->r_addend;
2540 /* See if the value will fit in 16 bits, note the high value is
2541 0x7fff + 2 as the target will be two bytes closer if we are
2543 if ((long) value < 0x8001 && (long) value > -0x8000)
2547 /* Get the opcode. */
2548 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2550 if (code != 0xdc && code != 0xdd && code != 0xff)
2553 /* Note that we've changed the relocs, section contents, etc. */
2554 elf_section_data (sec)->relocs = internal_relocs;
2555 elf_section_data (sec)->this_hdr.contents = contents;
2556 symtab_hdr->contents = (unsigned char *) isymbuf;
2558 /* Fix the opcode. */
2560 bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1);
2561 else if (code == 0xdd)
2562 bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1);
2563 else if (code == 0xff)
2564 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
2566 /* Fix the relocation's type. */
2567 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2568 (ELF32_R_TYPE (irel->r_info)
2569 == (int) R_MN10300_PLT32)
2573 /* Delete two bytes of data. */
2574 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2575 irel->r_offset + 1, 2))
2578 /* That will change things, so, we should relax again.
2579 Note that this is not required, and it may be slow. */
2584 /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
2586 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16)
2588 bfd_vma value = symval;
2590 /* If we've got a "call" instruction that needs to be turned
2591 into a "calls" instruction, do so now. It saves a byte. */
2592 if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
2596 /* Get the opcode. */
2597 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2599 /* Make sure we're working with a "call" instruction! */
2602 /* Note that we've changed the relocs, section contents,
2604 elf_section_data (sec)->relocs = internal_relocs;
2605 elf_section_data (sec)->this_hdr.contents = contents;
2606 symtab_hdr->contents = (unsigned char *) isymbuf;
2608 /* Fix the opcode. */
2609 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
2610 bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
2612 /* Fix irel->r_offset and irel->r_addend. */
2613 irel->r_offset += 1;
2614 irel->r_addend += 1;
2616 /* Delete one byte of data. */
2617 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2618 irel->r_offset + 1, 1))
2621 /* That will change things, so, we should relax again.
2622 Note that this is not required, and it may be slow. */
2630 /* Get the opcode. */
2631 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2633 /* Insert data from the target function into the "call"
2634 instruction if needed. */
2637 bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2);
2638 bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
2639 contents + irel->r_offset + 3);
2643 /* Deal with pc-relative gunk. */
2644 value -= (sec->output_section->vma + sec->output_offset);
2645 value -= irel->r_offset;
2646 value += irel->r_addend;
2648 /* See if the value will fit in 8 bits, note the high value is
2649 0x7f + 1 as the target will be one bytes closer if we are
2651 if ((long) value < 0x80 && (long) value > -0x80)
2655 /* Get the opcode. */
2656 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2661 /* Note that we've changed the relocs, section contents, etc. */
2662 elf_section_data (sec)->relocs = internal_relocs;
2663 elf_section_data (sec)->this_hdr.contents = contents;
2664 symtab_hdr->contents = (unsigned char *) isymbuf;
2666 /* Fix the opcode. */
2667 bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
2669 /* Fix the relocation's type. */
2670 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2673 /* Delete one byte of data. */
2674 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2675 irel->r_offset + 1, 1))
2678 /* That will change things, so, we should relax again.
2679 Note that this is not required, and it may be slow. */
2684 /* Try to eliminate an unconditional 8 bit pc-relative branch
2685 which immediately follows a conditional 8 bit pc-relative
2686 branch around the unconditional branch.
2693 This happens when the bCC can't reach lab2 at assembly time,
2694 but due to other relaxations it can reach at link time. */
2695 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8)
2697 Elf_Internal_Rela *nrel;
2698 bfd_vma value = symval;
2701 /* Deal with pc-relative gunk. */
2702 value -= (sec->output_section->vma + sec->output_offset);
2703 value -= irel->r_offset;
2704 value += irel->r_addend;
2706 /* Do nothing if this reloc is the last byte in the section. */
2707 if (irel->r_offset == sec->size)
2710 /* See if the next instruction is an unconditional pc-relative
2711 branch, more often than not this test will fail, so we
2712 test it first to speed things up. */
2713 code = bfd_get_8 (abfd, contents + irel->r_offset + 1);
2717 /* Also make sure the next relocation applies to the next
2718 instruction and that it's a pc-relative 8 bit branch. */
2721 || irel->r_offset + 2 != nrel->r_offset
2722 || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8)
2725 /* Make sure our destination immediately follows the
2726 unconditional branch. */
2727 if (symval != (sec->output_section->vma + sec->output_offset
2728 + irel->r_offset + 3))
2731 /* Now make sure we are a conditional branch. This may not
2732 be necessary, but why take the chance.
2734 Note these checks assume that R_MN10300_PCREL8 relocs
2735 only occur on bCC and bCCx insns. If they occured
2736 elsewhere, we'd need to know the start of this insn
2737 for this check to be accurate. */
2738 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2739 if (code != 0xc0 && code != 0xc1 && code != 0xc2
2740 && code != 0xc3 && code != 0xc4 && code != 0xc5
2741 && code != 0xc6 && code != 0xc7 && code != 0xc8
2742 && code != 0xc9 && code != 0xe8 && code != 0xe9
2743 && code != 0xea && code != 0xeb)
2746 /* We also have to be sure there is no symbol/label
2747 at the unconditional branch. */
2748 if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
2749 irel->r_offset + 1))
2752 /* Note that we've changed the relocs, section contents, etc. */
2753 elf_section_data (sec)->relocs = internal_relocs;
2754 elf_section_data (sec)->this_hdr.contents = contents;
2755 symtab_hdr->contents = (unsigned char *) isymbuf;
2757 /* Reverse the condition of the first branch. */
2803 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
2805 /* Set the reloc type and symbol for the first branch
2806 from the second branch. */
2807 irel->r_info = nrel->r_info;
2809 /* Make the reloc for the second branch a null reloc. */
2810 nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),
2813 /* Delete two bytes of data. */
2814 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2815 irel->r_offset + 1, 2))
2818 /* That will change things, so, we should relax again.
2819 Note that this is not required, and it may be slow. */
2823 /* Try to turn a 24 immediate, displacement or absolute address
2824 into a 8 immediate, displacement or absolute address. */
2825 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24)
2827 bfd_vma value = symval;
2828 value += irel->r_addend;
2830 /* See if the value will fit in 8 bits. */
2831 if ((long) value < 0x7f && (long) value > -0x80)
2835 /* AM33 insns which have 24 operands are 6 bytes long and
2836 will have 0xfd as the first byte. */
2838 /* Get the first opcode. */
2839 code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
2843 /* Get the second opcode. */
2844 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2846 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2847 equivalent instructions exists. */
2848 if (code != 0x6b && code != 0x7b
2849 && code != 0x8b && code != 0x9b
2850 && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2851 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2852 || (code & 0x0f) == 0x0e))
2854 /* Not safe if the high bit is on as relaxing may
2855 move the value out of high mem and thus not fit
2856 in a signed 8bit value. This is currently over
2858 if ((value & 0x80) == 0)
2860 /* Note that we've changed the relocation contents,
2862 elf_section_data (sec)->relocs = internal_relocs;
2863 elf_section_data (sec)->this_hdr.contents = contents;
2864 symtab_hdr->contents = (unsigned char *) isymbuf;
2866 /* Fix the opcode. */
2867 bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
2868 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
2870 /* Fix the relocation's type. */
2872 ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2875 /* Delete two bytes of data. */
2876 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2877 irel->r_offset + 1, 2))
2880 /* That will change things, so, we should relax
2881 again. Note that this is not required, and it
2891 /* Try to turn a 32bit immediate, displacement or absolute address
2892 into a 16bit immediate, displacement or absolute address. */
2893 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
2894 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
2895 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2897 bfd_vma value = symval;
2899 if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
2903 sgot = bfd_get_section_by_name (elf_hash_table (link_info)
2906 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
2908 value = sgot->output_offset;
2911 value += h->root.got.offset;
2913 value += (elf_local_got_offsets
2914 (abfd)[ELF32_R_SYM (irel->r_info)]);
2916 else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2917 value -= sgot->output_section->vma;
2918 else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
2919 value = (sgot->output_section->vma
2920 - (sec->output_section->vma
2921 + sec->output_offset
2927 value += irel->r_addend;
2929 /* See if the value will fit in 24 bits.
2930 We allow any 16bit match here. We prune those we can't
2932 if ((long) value < 0x7fffff && (long) value > -0x800000)
2936 /* AM33 insns which have 32bit operands are 7 bytes long and
2937 will have 0xfe as the first byte. */
2939 /* Get the first opcode. */
2940 code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
2944 /* Get the second opcode. */
2945 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2947 /* All the am33 32 -> 24 relaxing possibilities. */
2948 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2949 equivalent instructions exists. */
2950 if (code != 0x6b && code != 0x7b
2951 && code != 0x8b && code != 0x9b
2952 && (ELF32_R_TYPE (irel->r_info)
2953 != (int) R_MN10300_GOTPC32)
2954 && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2955 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2956 || (code & 0x0f) == 0x0e))
2958 /* Not safe if the high bit is on as relaxing may
2959 move the value out of high mem and thus not fit
2960 in a signed 16bit value. This is currently over
2962 if ((value & 0x8000) == 0)
2964 /* Note that we've changed the relocation contents,
2966 elf_section_data (sec)->relocs = internal_relocs;
2967 elf_section_data (sec)->this_hdr.contents = contents;
2968 symtab_hdr->contents = (unsigned char *) isymbuf;
2970 /* Fix the opcode. */
2971 bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
2972 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
2974 /* Fix the relocation's type. */
2976 ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2977 (ELF32_R_TYPE (irel->r_info)
2978 == (int) R_MN10300_GOTOFF32)
2979 ? R_MN10300_GOTOFF24
2980 : (ELF32_R_TYPE (irel->r_info)
2981 == (int) R_MN10300_GOT32)
2985 /* Delete one byte of data. */
2986 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2987 irel->r_offset + 3, 1))
2990 /* That will change things, so, we should relax
2991 again. Note that this is not required, and it
3000 /* See if the value will fit in 16 bits.
3001 We allow any 16bit match here. We prune those we can't
3003 if ((long) value < 0x7fff && (long) value > -0x8000)
3007 /* Most insns which have 32bit operands are 6 bytes long;
3008 exceptions are pcrel insns and bit insns.
3010 We handle pcrel insns above. We don't bother trying
3011 to handle the bit insns here.
3013 The first byte of the remaining insns will be 0xfc. */
3015 /* Get the first opcode. */
3016 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
3021 /* Get the second opcode. */
3022 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3024 if ((code & 0xf0) < 0x80)
3025 switch (code & 0xf0)
3027 /* mov (d32,am),dn -> mov (d32,am),dn
3028 mov dm,(d32,am) -> mov dn,(d32,am)
3029 mov (d32,am),an -> mov (d32,am),an
3030 mov dm,(d32,am) -> mov dn,(d32,am)
3031 movbu (d32,am),dn -> movbu (d32,am),dn
3032 movbu dm,(d32,am) -> movbu dn,(d32,am)
3033 movhu (d32,am),dn -> movhu (d32,am),dn
3034 movhu dm,(d32,am) -> movhu dn,(d32,am) */
3043 /* Not safe if the high bit is on as relaxing may
3044 move the value out of high mem and thus not fit
3045 in a signed 16bit value. */
3047 && (value & 0x8000))
3050 /* Note that we've changed the relocation contents, etc. */
3051 elf_section_data (sec)->relocs = internal_relocs;
3052 elf_section_data (sec)->this_hdr.contents = contents;
3053 symtab_hdr->contents = (unsigned char *) isymbuf;
3055 /* Fix the opcode. */
3056 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3057 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3059 /* Fix the relocation's type. */
3060 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3061 (ELF32_R_TYPE (irel->r_info)
3062 == (int) R_MN10300_GOTOFF32)
3063 ? R_MN10300_GOTOFF16
3064 : (ELF32_R_TYPE (irel->r_info)
3065 == (int) R_MN10300_GOT32)
3067 : (ELF32_R_TYPE (irel->r_info)
3068 == (int) R_MN10300_GOTPC32)
3069 ? R_MN10300_GOTPC16 :
3072 /* Delete two bytes of data. */
3073 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3074 irel->r_offset + 2, 2))
3077 /* That will change things, so, we should relax again.
3078 Note that this is not required, and it may be slow. */
3082 else if ((code & 0xf0) == 0x80
3083 || (code & 0xf0) == 0x90)
3084 switch (code & 0xf3)
3086 /* mov dn,(abs32) -> mov dn,(abs16)
3087 movbu dn,(abs32) -> movbu dn,(abs16)
3088 movhu dn,(abs32) -> movhu dn,(abs16) */
3092 /* Note that we've changed the relocation contents, etc. */
3093 elf_section_data (sec)->relocs = internal_relocs;
3094 elf_section_data (sec)->this_hdr.contents = contents;
3095 symtab_hdr->contents = (unsigned char *) isymbuf;
3097 if ((code & 0xf3) == 0x81)
3098 code = 0x01 + (code & 0x0c);
3099 else if ((code & 0xf3) == 0x82)
3100 code = 0x02 + (code & 0x0c);
3101 else if ((code & 0xf3) == 0x83)
3102 code = 0x03 + (code & 0x0c);
3106 /* Fix the opcode. */
3107 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3109 /* Fix the relocation's type. */
3110 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3111 (ELF32_R_TYPE (irel->r_info)
3112 == (int) R_MN10300_GOTOFF32)
3113 ? R_MN10300_GOTOFF16
3114 : (ELF32_R_TYPE (irel->r_info)
3115 == (int) R_MN10300_GOT32)
3117 : (ELF32_R_TYPE (irel->r_info)
3118 == (int) R_MN10300_GOTPC32)
3119 ? R_MN10300_GOTPC16 :
3122 /* The opcode got shorter too, so we have to fix the
3123 addend and offset too! */
3124 irel->r_offset -= 1;
3126 /* Delete three bytes of data. */
3127 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3128 irel->r_offset + 1, 3))
3131 /* That will change things, so, we should relax again.
3132 Note that this is not required, and it may be slow. */
3136 /* mov am,(abs32) -> mov am,(abs16)
3137 mov am,(d32,sp) -> mov am,(d16,sp)
3138 mov dm,(d32,sp) -> mov dm,(d32,sp)
3139 movbu dm,(d32,sp) -> movbu dm,(d32,sp)
3140 movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
3146 /* sp-based offsets are zero-extended. */
3147 if (code >= 0x90 && code <= 0x93
3151 /* Note that we've changed the relocation contents, etc. */
3152 elf_section_data (sec)->relocs = internal_relocs;
3153 elf_section_data (sec)->this_hdr.contents = contents;
3154 symtab_hdr->contents = (unsigned char *) isymbuf;
3156 /* Fix the opcode. */
3157 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3158 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3160 /* Fix the relocation's type. */
3161 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3162 (ELF32_R_TYPE (irel->r_info)
3163 == (int) R_MN10300_GOTOFF32)
3164 ? R_MN10300_GOTOFF16
3165 : (ELF32_R_TYPE (irel->r_info)
3166 == (int) R_MN10300_GOT32)
3168 : (ELF32_R_TYPE (irel->r_info)
3169 == (int) R_MN10300_GOTPC32)
3170 ? R_MN10300_GOTPC16 :
3173 /* Delete two bytes of data. */
3174 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3175 irel->r_offset + 2, 2))
3178 /* That will change things, so, we should relax again.
3179 Note that this is not required, and it may be slow. */
3183 else if ((code & 0xf0) < 0xf0)
3184 switch (code & 0xfc)
3186 /* mov imm32,dn -> mov imm16,dn
3187 mov imm32,an -> mov imm16,an
3188 mov (abs32),dn -> mov (abs16),dn
3189 movbu (abs32),dn -> movbu (abs16),dn
3190 movhu (abs32),dn -> movhu (abs16),dn */
3196 /* Not safe if the high bit is on as relaxing may
3197 move the value out of high mem and thus not fit
3198 in a signed 16bit value. */
3200 && (value & 0x8000))
3203 /* mov imm16, an zero-extends the immediate. */
3208 /* Note that we've changed the relocation contents, etc. */
3209 elf_section_data (sec)->relocs = internal_relocs;
3210 elf_section_data (sec)->this_hdr.contents = contents;
3211 symtab_hdr->contents = (unsigned char *) isymbuf;
3213 if ((code & 0xfc) == 0xcc)
3214 code = 0x2c + (code & 0x03);
3215 else if ((code & 0xfc) == 0xdc)
3216 code = 0x24 + (code & 0x03);
3217 else if ((code & 0xfc) == 0xa4)
3218 code = 0x30 + (code & 0x03);
3219 else if ((code & 0xfc) == 0xa8)
3220 code = 0x34 + (code & 0x03);
3221 else if ((code & 0xfc) == 0xac)
3222 code = 0x38 + (code & 0x03);
3226 /* Fix the opcode. */
3227 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3229 /* Fix the relocation's type. */
3230 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3231 (ELF32_R_TYPE (irel->r_info)
3232 == (int) R_MN10300_GOTOFF32)
3233 ? R_MN10300_GOTOFF16
3234 : (ELF32_R_TYPE (irel->r_info)
3235 == (int) R_MN10300_GOT32)
3237 : (ELF32_R_TYPE (irel->r_info)
3238 == (int) R_MN10300_GOTPC32)
3239 ? R_MN10300_GOTPC16 :
3242 /* The opcode got shorter too, so we have to fix the
3243 addend and offset too! */
3244 irel->r_offset -= 1;
3246 /* Delete three bytes of data. */
3247 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3248 irel->r_offset + 1, 3))
3251 /* That will change things, so, we should relax again.
3252 Note that this is not required, and it may be slow. */
3256 /* mov (abs32),an -> mov (abs16),an
3257 mov (d32,sp),an -> mov (d16,sp),an
3258 mov (d32,sp),dn -> mov (d16,sp),dn
3259 movbu (d32,sp),dn -> movbu (d16,sp),dn
3260 movhu (d32,sp),dn -> movhu (d16,sp),dn
3261 add imm32,dn -> add imm16,dn
3262 cmp imm32,dn -> cmp imm16,dn
3263 add imm32,an -> add imm16,an
3264 cmp imm32,an -> cmp imm16,an
3265 and imm32,dn -> and imm16,dn
3266 or imm32,dn -> or imm16,dn
3267 xor imm32,dn -> xor imm16,dn
3268 btst imm32,dn -> btst imm16,dn */
3284 /* cmp imm16, an zero-extends the immediate. */
3289 /* So do sp-based offsets. */
3290 if (code >= 0xb0 && code <= 0xb3
3294 /* Note that we've changed the relocation contents, etc. */
3295 elf_section_data (sec)->relocs = internal_relocs;
3296 elf_section_data (sec)->this_hdr.contents = contents;
3297 symtab_hdr->contents = (unsigned char *) isymbuf;
3299 /* Fix the opcode. */
3300 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3301 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3303 /* Fix the relocation's type. */
3304 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3305 (ELF32_R_TYPE (irel->r_info)
3306 == (int) R_MN10300_GOTOFF32)
3307 ? R_MN10300_GOTOFF16
3308 : (ELF32_R_TYPE (irel->r_info)
3309 == (int) R_MN10300_GOT32)
3311 : (ELF32_R_TYPE (irel->r_info)
3312 == (int) R_MN10300_GOTPC32)
3313 ? R_MN10300_GOTPC16 :
3316 /* Delete two bytes of data. */
3317 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3318 irel->r_offset + 2, 2))
3321 /* That will change things, so, we should relax again.
3322 Note that this is not required, and it may be slow. */
3326 else if (code == 0xfe)
3328 /* add imm32,sp -> add imm16,sp */
3330 /* Note that we've changed the relocation contents, etc. */
3331 elf_section_data (sec)->relocs = internal_relocs;
3332 elf_section_data (sec)->this_hdr.contents = contents;
3333 symtab_hdr->contents = (unsigned char *) isymbuf;
3335 /* Fix the opcode. */
3336 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3337 bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1);
3339 /* Fix the relocation's type. */
3340 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3341 (ELF32_R_TYPE (irel->r_info)
3342 == (int) R_MN10300_GOT32)
3344 : (ELF32_R_TYPE (irel->r_info)
3345 == (int) R_MN10300_GOTOFF32)
3346 ? R_MN10300_GOTOFF16
3347 : (ELF32_R_TYPE (irel->r_info)
3348 == (int) R_MN10300_GOTPC32)
3349 ? R_MN10300_GOTPC16 :
3352 /* Delete two bytes of data. */
3353 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3354 irel->r_offset + 2, 2))
3357 /* That will change things, so, we should relax again.
3358 Note that this is not required, and it may be slow. */
3367 && symtab_hdr->contents != (unsigned char *) isymbuf)
3369 if (! link_info->keep_memory)
3373 /* Cache the symbols for elf_link_input_bfd. */
3374 symtab_hdr->contents = (unsigned char *) isymbuf;
3378 if (contents != NULL
3379 && elf_section_data (sec)->this_hdr.contents != contents)
3381 if (! link_info->keep_memory)
3385 /* Cache the section contents for elf_link_input_bfd. */
3386 elf_section_data (sec)->this_hdr.contents = contents;
3390 if (internal_relocs != NULL
3391 && elf_section_data (sec)->relocs != internal_relocs)
3392 free (internal_relocs);
3398 && symtab_hdr->contents != (unsigned char *) isymbuf)
3400 if (contents != NULL
3401 && elf_section_data (section)->this_hdr.contents != contents)
3403 if (internal_relocs != NULL
3404 && elf_section_data (section)->relocs != internal_relocs)
3405 free (internal_relocs);
3410 /* Compute the stack size and movm arguments for the function
3411 referred to by HASH at address ADDR in section with
3412 contents CONTENTS, store the information in the hash table. */
3414 compute_function_info (abfd, hash, addr, contents)
3416 struct elf32_mn10300_link_hash_entry *hash;
3418 unsigned char *contents;
3420 unsigned char byte1, byte2;
3421 /* We only care about a very small subset of the possible prologue
3422 sequences here. Basically we look for:
3424 movm [d2,d3,a2,a3],sp (optional)
3425 add <size>,sp (optional, and only for sizes which fit in an unsigned
3428 If we find anything else, we quit. */
3430 /* Look for movm [regs],sp */
3431 byte1 = bfd_get_8 (abfd, contents + addr);
3432 byte2 = bfd_get_8 (abfd, contents + addr + 1);
3436 hash->movm_args = byte2;
3438 byte1 = bfd_get_8 (abfd, contents + addr);
3439 byte2 = bfd_get_8 (abfd, contents + addr + 1);
3442 /* Now figure out how much stack space will be allocated by the movm
3443 instruction. We need this kept separate from the function's normal
3445 if (hash->movm_args)
3448 if (hash->movm_args & 0x80)
3449 hash->movm_stack_size += 4;
3452 if (hash->movm_args & 0x40)
3453 hash->movm_stack_size += 4;
3456 if (hash->movm_args & 0x20)
3457 hash->movm_stack_size += 4;
3460 if (hash->movm_args & 0x10)
3461 hash->movm_stack_size += 4;
3463 /* "other" space. d0, d1, a0, a1, mdr, lir, lar, 4 byte pad. */
3464 if (hash->movm_args & 0x08)
3465 hash->movm_stack_size += 8 * 4;
3467 if (bfd_get_mach (abfd) == bfd_mach_am33
3468 || bfd_get_mach (abfd) == bfd_mach_am33_2)
3470 /* "exother" space. e0, e1, mdrq, mcrh, mcrl, mcvf */
3471 if (hash->movm_args & 0x1)
3472 hash->movm_stack_size += 6 * 4;
3474 /* exreg1 space. e4, e5, e6, e7 */
3475 if (hash->movm_args & 0x2)
3476 hash->movm_stack_size += 4 * 4;
3478 /* exreg0 space. e2, e3 */
3479 if (hash->movm_args & 0x4)
3480 hash->movm_stack_size += 2 * 4;
3484 /* Now look for the two stack adjustment variants. */
3485 if (byte1 == 0xf8 && byte2 == 0xfe)
3487 int temp = bfd_get_8 (abfd, contents + addr + 2);
3488 temp = ((temp & 0xff) ^ (~0x7f)) + 0x80;
3490 hash->stack_size = -temp;
3492 else if (byte1 == 0xfa && byte2 == 0xfe)
3494 int temp = bfd_get_16 (abfd, contents + addr + 2);
3495 temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000;
3499 hash->stack_size = temp;
3502 /* If the total stack to be allocated by the call instruction is more
3503 than 255 bytes, then we can't remove the stack adjustment by using
3504 "call" (we might still be able to remove the "movm" instruction. */
3505 if (hash->stack_size + hash->movm_stack_size > 255)
3506 hash->stack_size = 0;
3511 /* Delete some bytes from a section while relaxing. */
3514 mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
3520 Elf_Internal_Shdr *symtab_hdr;
3521 unsigned int sec_shndx;
3523 Elf_Internal_Rela *irel, *irelend;
3524 Elf_Internal_Rela *irelalign;
3526 Elf_Internal_Sym *isym, *isymend;
3527 struct elf_link_hash_entry **sym_hashes;
3528 struct elf_link_hash_entry **end_hashes;
3529 unsigned int symcount;
3531 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
3533 contents = elf_section_data (sec)->this_hdr.contents;
3535 /* The deletion must stop at the next ALIGN reloc for an aligment
3536 power larger than the number of bytes we are deleting. */
3541 irel = elf_section_data (sec)->relocs;
3542 irelend = irel + sec->reloc_count;
3544 /* Actually delete the bytes. */
3545 memmove (contents + addr, contents + addr + count,
3546 (size_t) (toaddr - addr - count));
3549 /* Adjust all the relocs. */
3550 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
3552 /* Get the new reloc address. */
3553 if ((irel->r_offset > addr
3554 && irel->r_offset < toaddr))
3555 irel->r_offset -= count;
3558 /* Adjust the local symbols defined in this section. */
3559 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3560 isym = (Elf_Internal_Sym *) symtab_hdr->contents;
3561 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
3563 if (isym->st_shndx == sec_shndx
3564 && isym->st_value > addr
3565 && isym->st_value < toaddr)
3566 isym->st_value -= count;
3569 /* Now adjust the global symbols defined in this section. */
3570 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3571 - symtab_hdr->sh_info);
3572 sym_hashes = elf_sym_hashes (abfd);
3573 end_hashes = sym_hashes + symcount;
3574 for (; sym_hashes < end_hashes; sym_hashes++)
3576 struct elf_link_hash_entry *sym_hash = *sym_hashes;
3577 if ((sym_hash->root.type == bfd_link_hash_defined
3578 || sym_hash->root.type == bfd_link_hash_defweak)
3579 && sym_hash->root.u.def.section == sec
3580 && sym_hash->root.u.def.value > addr
3581 && sym_hash->root.u.def.value < toaddr)
3583 sym_hash->root.u.def.value -= count;
3590 /* Return TRUE if a symbol exists at the given address, else return
3593 mn10300_elf_symbol_address_p (abfd, sec, isym, addr)
3596 Elf_Internal_Sym *isym;
3599 Elf_Internal_Shdr *symtab_hdr;
3600 unsigned int sec_shndx;
3601 Elf_Internal_Sym *isymend;
3602 struct elf_link_hash_entry **sym_hashes;
3603 struct elf_link_hash_entry **end_hashes;
3604 unsigned int symcount;
3606 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
3608 /* Examine all the symbols. */
3609 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3610 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
3612 if (isym->st_shndx == sec_shndx
3613 && isym->st_value == addr)
3617 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3618 - symtab_hdr->sh_info);
3619 sym_hashes = elf_sym_hashes (abfd);
3620 end_hashes = sym_hashes + symcount;
3621 for (; sym_hashes < end_hashes; sym_hashes++)
3623 struct elf_link_hash_entry *sym_hash = *sym_hashes;
3624 if ((sym_hash->root.type == bfd_link_hash_defined
3625 || sym_hash->root.type == bfd_link_hash_defweak)
3626 && sym_hash->root.u.def.section == sec
3627 && sym_hash->root.u.def.value == addr)
3634 /* This is a version of bfd_generic_get_relocated_section_contents
3635 which uses mn10300_elf_relocate_section. */
3638 mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
3639 data, relocatable, symbols)
3641 struct bfd_link_info *link_info;
3642 struct bfd_link_order *link_order;
3644 bfd_boolean relocatable;
3647 Elf_Internal_Shdr *symtab_hdr;
3648 asection *input_section = link_order->u.indirect.section;
3649 bfd *input_bfd = input_section->owner;
3650 asection **sections = NULL;
3651 Elf_Internal_Rela *internal_relocs = NULL;
3652 Elf_Internal_Sym *isymbuf = NULL;
3654 /* We only need to handle the case of relaxing, or of having a
3655 particular set of section contents, specially. */
3657 || elf_section_data (input_section)->this_hdr.contents == NULL)
3658 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
3663 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3665 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
3666 (size_t) input_section->size);
3668 if ((input_section->flags & SEC_RELOC) != 0
3669 && input_section->reloc_count > 0)
3672 Elf_Internal_Sym *isym, *isymend;
3675 internal_relocs = (_bfd_elf_link_read_relocs
3676 (input_bfd, input_section, (PTR) NULL,
3677 (Elf_Internal_Rela *) NULL, FALSE));
3678 if (internal_relocs == NULL)
3681 if (symtab_hdr->sh_info != 0)
3683 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
3684 if (isymbuf == NULL)
3685 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3686 symtab_hdr->sh_info, 0,
3688 if (isymbuf == NULL)
3692 amt = symtab_hdr->sh_info;
3693 amt *= sizeof (asection *);
3694 sections = (asection **) bfd_malloc (amt);
3695 if (sections == NULL && amt != 0)
3698 isymend = isymbuf + symtab_hdr->sh_info;
3699 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
3703 if (isym->st_shndx == SHN_UNDEF)
3704 isec = bfd_und_section_ptr;
3705 else if (isym->st_shndx == SHN_ABS)
3706 isec = bfd_abs_section_ptr;
3707 else if (isym->st_shndx == SHN_COMMON)
3708 isec = bfd_com_section_ptr;
3710 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
3715 if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
3716 input_section, data, internal_relocs,
3720 if (sections != NULL)
3722 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3724 if (internal_relocs != elf_section_data (input_section)->relocs)
3725 free (internal_relocs);
3731 if (sections != NULL)
3733 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3735 if (internal_relocs != NULL
3736 && internal_relocs != elf_section_data (input_section)->relocs)
3737 free (internal_relocs);
3741 /* Assorted hash table functions. */
3743 /* Initialize an entry in the link hash table. */
3745 /* Create an entry in an MN10300 ELF linker hash table. */
3747 static struct bfd_hash_entry *
3748 elf32_mn10300_link_hash_newfunc (entry, table, string)
3749 struct bfd_hash_entry *entry;
3750 struct bfd_hash_table *table;
3753 struct elf32_mn10300_link_hash_entry *ret =
3754 (struct elf32_mn10300_link_hash_entry *) entry;
3756 /* Allocate the structure if it has not already been allocated by a
3758 if (ret == (struct elf32_mn10300_link_hash_entry *) NULL)
3759 ret = ((struct elf32_mn10300_link_hash_entry *)
3760 bfd_hash_allocate (table,
3761 sizeof (struct elf32_mn10300_link_hash_entry)));
3762 if (ret == (struct elf32_mn10300_link_hash_entry *) NULL)
3763 return (struct bfd_hash_entry *) ret;
3765 /* Call the allocation method of the superclass. */
3766 ret = ((struct elf32_mn10300_link_hash_entry *)
3767 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3769 if (ret != (struct elf32_mn10300_link_hash_entry *) NULL)
3771 ret->direct_calls = 0;
3772 ret->stack_size = 0;
3774 ret->movm_stack_size = 0;
3779 return (struct bfd_hash_entry *) ret;
3782 /* Create an mn10300 ELF linker hash table. */
3784 static struct bfd_link_hash_table *
3785 elf32_mn10300_link_hash_table_create (abfd)
3788 struct elf32_mn10300_link_hash_table *ret;
3789 bfd_size_type amt = sizeof (struct elf32_mn10300_link_hash_table);
3791 ret = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
3792 if (ret == (struct elf32_mn10300_link_hash_table *) NULL)
3795 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
3796 elf32_mn10300_link_hash_newfunc,
3797 sizeof (struct elf32_mn10300_link_hash_entry)))
3804 amt = sizeof (struct elf_link_hash_table);
3805 ret->static_hash_table
3806 = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
3807 if (ret->static_hash_table == NULL)
3813 if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd,
3814 elf32_mn10300_link_hash_newfunc,
3815 sizeof (struct elf32_mn10300_link_hash_entry)))
3817 free (ret->static_hash_table);
3821 return &ret->root.root;
3824 /* Free an mn10300 ELF linker hash table. */
3827 elf32_mn10300_link_hash_table_free (hash)
3828 struct bfd_link_hash_table *hash;
3830 struct elf32_mn10300_link_hash_table *ret
3831 = (struct elf32_mn10300_link_hash_table *) hash;
3833 _bfd_generic_link_hash_table_free
3834 ((struct bfd_link_hash_table *) ret->static_hash_table);
3835 _bfd_generic_link_hash_table_free
3836 ((struct bfd_link_hash_table *) ret);
3839 static unsigned long
3840 elf_mn10300_mach (flags)
3843 switch (flags & EF_MN10300_MACH)
3845 case E_MN10300_MACH_MN10300:
3847 return bfd_mach_mn10300;
3849 case E_MN10300_MACH_AM33:
3850 return bfd_mach_am33;
3852 case E_MN10300_MACH_AM33_2:
3853 return bfd_mach_am33_2;
3857 /* The final processing done just before writing out a MN10300 ELF object
3858 file. This gets the MN10300 architecture right based on the machine
3862 _bfd_mn10300_elf_final_write_processing (abfd, linker)
3864 bfd_boolean linker ATTRIBUTE_UNUSED;
3868 switch (bfd_get_mach (abfd))
3871 case bfd_mach_mn10300:
3872 val = E_MN10300_MACH_MN10300;
3876 val = E_MN10300_MACH_AM33;
3879 case bfd_mach_am33_2:
3880 val = E_MN10300_MACH_AM33_2;
3884 elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
3885 elf_elfheader (abfd)->e_flags |= val;
3889 _bfd_mn10300_elf_object_p (abfd)
3892 bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
3893 elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
3897 /* Merge backend specific data from an object file to the output
3898 object file when linking. */
3901 _bfd_mn10300_elf_merge_private_bfd_data (ibfd, obfd)
3905 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3906 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3909 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3910 && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
3912 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3913 bfd_get_mach (ibfd)))
3920 #define PLT0_ENTRY_SIZE 15
3921 #define PLT_ENTRY_SIZE 20
3922 #define PIC_PLT_ENTRY_SIZE 24
3924 static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
3926 0xfc, 0xa0, 0, 0, 0, 0, /* mov (.got+8),a0 */
3927 0xfe, 0xe, 0x10, 0, 0, 0, 0, /* mov (.got+4),r1 */
3928 0xf0, 0xf4, /* jmp (a0) */
3931 static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
3933 0xfc, 0xa0, 0, 0, 0, 0, /* mov (nameN@GOT + .got),a0 */
3934 0xf0, 0xf4, /* jmp (a0) */
3935 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3936 0xdc, 0, 0, 0, 0, /* jmp .plt0 */
3939 static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
3941 0xfc, 0x22, 0, 0, 0, 0, /* mov (nameN@GOT,a2),a0 */
3942 0xf0, 0xf4, /* jmp (a0) */
3943 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3944 0xf8, 0x22, 8, /* mov (8,a2),a0 */
3945 0xfb, 0xa, 0x1a, 4, /* mov (4,a2),r1 */
3946 0xf0, 0xf4, /* jmp (a0) */
3949 /* Return size of the first PLT entry. */
3950 #define elf_mn10300_sizeof_plt0(info) \
3951 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
3953 /* Return size of a PLT entry. */
3954 #define elf_mn10300_sizeof_plt(info) \
3955 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
3957 /* Return offset of the PLT0 address in an absolute PLT entry. */
3958 #define elf_mn10300_plt_plt0_offset(info) 16
3960 /* Return offset of the linker in PLT0 entry. */
3961 #define elf_mn10300_plt0_linker_offset(info) 2
3963 /* Return offset of the GOT id in PLT0 entry. */
3964 #define elf_mn10300_plt0_gotid_offset(info) 9
3966 /* Return offset of the temporary in PLT entry */
3967 #define elf_mn10300_plt_temp_offset(info) 8
3969 /* Return offset of the symbol in PLT entry. */
3970 #define elf_mn10300_plt_symbol_offset(info) 2
3972 /* Return offset of the relocation in PLT entry. */
3973 #define elf_mn10300_plt_reloc_offset(info) 11
3975 /* The name of the dynamic interpreter. This is put in the .interp
3978 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
3980 /* Create dynamic sections when linking against a dynamic object. */
3983 _bfd_mn10300_elf_create_dynamic_sections (abfd, info)
3985 struct bfd_link_info *info;
3989 const struct elf_backend_data * bed = get_elf_backend_data (abfd);
3992 switch (bed->s->arch_size)
4003 bfd_set_error (bfd_error_bad_value);
4007 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
4008 .rel[a].bss sections. */
4010 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4011 | SEC_LINKER_CREATED);
4013 s = bfd_make_section_with_flags (abfd,
4014 (bed->default_use_rela_p
4015 ? ".rela.plt" : ".rel.plt"),
4016 flags | SEC_READONLY);
4018 || ! bfd_set_section_alignment (abfd, s, ptralign))
4021 if (! _bfd_mn10300_elf_create_got_section (abfd, info))
4025 const char * secname;
4030 for (sec = abfd->sections; sec; sec = sec->next)
4032 secflags = bfd_get_section_flags (abfd, sec);
4033 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
4034 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
4037 secname = bfd_get_section_name (abfd, sec);
4038 relname = (char *) bfd_malloc (strlen (secname) + 6);
4039 strcpy (relname, ".rela");
4040 strcat (relname, secname);
4042 s = bfd_make_section_with_flags (abfd, relname,
4043 flags | SEC_READONLY);
4045 || ! bfd_set_section_alignment (abfd, s, ptralign))
4050 if (bed->want_dynbss)
4052 /* The .dynbss section is a place to put symbols which are defined
4053 by dynamic objects, are referenced by regular objects, and are
4054 not functions. We must allocate space for them in the process
4055 image and use a R_*_COPY reloc to tell the dynamic linker to
4056 initialize them at run time. The linker script puts the .dynbss
4057 section into the .bss section of the final image. */
4058 s = bfd_make_section_with_flags (abfd, ".dynbss",
4059 SEC_ALLOC | SEC_LINKER_CREATED);
4063 /* The .rel[a].bss section holds copy relocs. This section is not
4064 normally needed. We need to create it here, though, so that the
4065 linker will map it to an output section. We can't just create it
4066 only if we need it, because we will not know whether we need it
4067 until we have seen all the input files, and the first time the
4068 main linker code calls BFD after examining all the input files
4069 (size_dynamic_sections) the input sections have already been
4070 mapped to the output sections. If the section turns out not to
4071 be needed, we can discard it later. We will never need this
4072 section when generating a shared object, since they do not use
4076 s = bfd_make_section_with_flags (abfd,
4077 (bed->default_use_rela_p
4078 ? ".rela.bss" : ".rel.bss"),
4079 flags | SEC_READONLY);
4081 || ! bfd_set_section_alignment (abfd, s, ptralign))
4089 /* Adjust a symbol defined by a dynamic object and referenced by a
4090 regular object. The current definition is in some section of the
4091 dynamic object, but we're not including those sections. We have to
4092 change the definition to something the rest of the link can
4096 _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
4097 struct bfd_link_info * info;
4098 struct elf_link_hash_entry * h;
4103 dynobj = elf_hash_table (info)->dynobj;
4105 /* Make sure we know what is going on here. */
4106 BFD_ASSERT (dynobj != NULL
4108 || h->u.weakdef != NULL
4111 && !h->def_regular)));
4113 /* If this is a function, put it in the procedure linkage table. We
4114 will fill in the contents of the procedure linkage table later,
4115 when we know the address of the .got section. */
4116 if (h->type == STT_FUNC
4123 /* This case can occur if we saw a PLT reloc in an input
4124 file, but the symbol was never referred to by a dynamic
4125 object. In such a case, we don't actually need to build
4126 a procedure linkage table, and we can just do a REL32
4128 BFD_ASSERT (h->needs_plt);
4132 /* Make sure this symbol is output as a dynamic symbol. */
4133 if (h->dynindx == -1)
4135 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4139 s = bfd_get_section_by_name (dynobj, ".plt");
4140 BFD_ASSERT (s != NULL);
4142 /* If this is the first .plt entry, make room for the special
4145 s->size += elf_mn10300_sizeof_plt0 (info);
4147 /* If this symbol is not defined in a regular file, and we are
4148 not generating a shared library, then set the symbol to this
4149 location in the .plt. This is required to make function
4150 pointers compare as equal between the normal executable and
4151 the shared library. */
4155 h->root.u.def.section = s;
4156 h->root.u.def.value = s->size;
4159 h->plt.offset = s->size;
4161 /* Make room for this entry. */
4162 s->size += elf_mn10300_sizeof_plt (info);
4164 /* We also need to make an entry in the .got.plt section, which
4165 will be placed in the .got section by the linker script. */
4167 s = bfd_get_section_by_name (dynobj, ".got.plt");
4168 BFD_ASSERT (s != NULL);
4171 /* We also need to make an entry in the .rela.plt section. */
4173 s = bfd_get_section_by_name (dynobj, ".rela.plt");
4174 BFD_ASSERT (s != NULL);
4175 s->size += sizeof (Elf32_External_Rela);
4180 /* If this is a weak symbol, and there is a real definition, the
4181 processor independent code will have arranged for us to see the
4182 real definition first, and we can just use the same value. */
4183 if (h->u.weakdef != NULL)
4185 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4186 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4187 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4188 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4192 /* This is a reference to a symbol defined by a dynamic object which
4193 is not a function. */
4195 /* If we are creating a shared library, we must presume that the
4196 only references to the symbol are via the global offset table.
4197 For such cases we need not do anything here; the relocations will
4198 be handled correctly by relocate_section. */
4202 /* If there are no references to this symbol that do not use the
4203 GOT, we don't need to generate a copy reloc. */
4204 if (!h->non_got_ref)
4209 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
4210 h->root.root.string);
4214 /* We must allocate the symbol in our .dynbss section, which will
4215 become part of the .bss section of the executable. There will be
4216 an entry for this symbol in the .dynsym section. The dynamic
4217 object will contain position independent code, so all references
4218 from the dynamic object to this symbol will go through the global
4219 offset table. The dynamic linker will use the .dynsym entry to
4220 determine the address it must put in the global offset table, so
4221 both the dynamic object and the regular object will refer to the
4222 same memory location for the variable. */
4224 s = bfd_get_section_by_name (dynobj, ".dynbss");
4225 BFD_ASSERT (s != NULL);
4227 /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
4228 copy the initial value out of the dynamic object and into the
4229 runtime process image. We need to remember the offset into the
4230 .rela.bss section we are going to use. */
4231 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4235 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
4236 BFD_ASSERT (srel != NULL);
4237 srel->size += sizeof (Elf32_External_Rela);
4241 return _bfd_elf_adjust_dynamic_copy (h, s);
4244 /* Set the sizes of the dynamic sections. */
4247 _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
4249 struct bfd_link_info * info;
4255 bfd_boolean reltext;
4257 dynobj = elf_hash_table (info)->dynobj;
4258 BFD_ASSERT (dynobj != NULL);
4260 if (elf_hash_table (info)->dynamic_sections_created)
4262 /* Set the contents of the .interp section to the interpreter. */
4263 if (info->executable)
4265 s = bfd_get_section_by_name (dynobj, ".interp");
4266 BFD_ASSERT (s != NULL);
4267 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4268 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4273 /* We may have created entries in the .rela.got section.
4274 However, if we are not creating the dynamic sections, we will
4275 not actually use these entries. Reset the size of .rela.got,
4276 which will cause it to get stripped from the output file
4278 s = bfd_get_section_by_name (dynobj, ".rela.got");
4283 /* The check_relocs and adjust_dynamic_symbol entry points have
4284 determined the sizes of the various dynamic sections. Allocate
4289 for (s = dynobj->sections; s != NULL; s = s->next)
4293 if ((s->flags & SEC_LINKER_CREATED) == 0)
4296 /* It's OK to base decisions on the section name, because none
4297 of the dynobj section names depend upon the input files. */
4298 name = bfd_get_section_name (dynobj, s);
4300 if (strcmp (name, ".plt") == 0)
4302 /* Remember whether there is a PLT. */
4305 else if (CONST_STRNEQ (name, ".rela"))
4311 /* Remember whether there are any reloc sections other
4313 if (strcmp (name, ".rela.plt") != 0)
4315 const char * outname;
4319 /* If this relocation section applies to a read only
4320 section, then we probably need a DT_TEXTREL
4321 entry. The entries in the .rela.plt section
4322 really apply to the .got section, which we
4323 created ourselves and so know is not readonly. */
4324 outname = bfd_get_section_name (output_bfd,
4326 target = bfd_get_section_by_name (output_bfd, outname + 5);
4328 && (target->flags & SEC_READONLY) != 0
4329 && (target->flags & SEC_ALLOC) != 0)
4333 /* We use the reloc_count field as a counter if we need
4334 to copy relocs into the output file. */
4338 else if (! CONST_STRNEQ (name, ".got")
4339 && strcmp (name, ".dynbss") != 0)
4340 /* It's not one of our sections, so don't allocate space. */
4345 /* If we don't need this section, strip it from the
4346 output file. This is mostly to handle .rela.bss and
4347 .rela.plt. We must create both sections in
4348 create_dynamic_sections, because they must be created
4349 before the linker maps input sections to output
4350 sections. The linker does that before
4351 adjust_dynamic_symbol is called, and it is that
4352 function which decides whether anything needs to go
4353 into these sections. */
4354 s->flags |= SEC_EXCLUDE;
4358 if ((s->flags & SEC_HAS_CONTENTS) == 0)
4361 /* Allocate memory for the section contents. We use bfd_zalloc
4362 here in case unused entries are not reclaimed before the
4363 section's contents are written out. This should not happen,
4364 but this way if it does, we get a R_MN10300_NONE reloc
4365 instead of garbage. */
4366 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4367 if (s->contents == NULL)
4371 if (elf_hash_table (info)->dynamic_sections_created)
4373 /* Add some entries to the .dynamic section. We fill in the
4374 values later, in _bfd_mn10300_elf_finish_dynamic_sections,
4375 but we must add the entries now so that we get the correct
4376 size for the .dynamic section. The DT_DEBUG entry is filled
4377 in by the dynamic linker and used by the debugger. */
4380 if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
4386 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
4387 || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
4388 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
4389 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
4395 if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
4396 || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
4397 || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
4398 sizeof (Elf32_External_Rela)))
4404 if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
4412 /* Finish up dynamic symbol handling. We set the contents of various
4413 dynamic sections here. */
4416 _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
4418 struct bfd_link_info * info;
4419 struct elf_link_hash_entry * h;
4420 Elf_Internal_Sym * sym;
4424 dynobj = elf_hash_table (info)->dynobj;
4426 if (h->plt.offset != (bfd_vma) -1)
4433 Elf_Internal_Rela rel;
4435 /* This symbol has an entry in the procedure linkage table. Set
4438 BFD_ASSERT (h->dynindx != -1);
4440 splt = bfd_get_section_by_name (dynobj, ".plt");
4441 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4442 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4443 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
4445 /* Get the index in the procedure linkage table which
4446 corresponds to this symbol. This is the index of this symbol
4447 in all the symbols for which we are making plt entries. The
4448 first entry in the procedure linkage table is reserved. */
4449 plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
4450 / elf_mn10300_sizeof_plt (info));
4452 /* Get the offset into the .got table of the entry that
4453 corresponds to this function. Each .got entry is 4 bytes.
4454 The first three are reserved. */
4455 got_offset = (plt_index + 3) * 4;
4457 /* Fill in the entry in the procedure linkage table. */
4460 memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
4461 elf_mn10300_sizeof_plt (info));
4462 bfd_put_32 (output_bfd,
4463 (sgot->output_section->vma
4464 + sgot->output_offset
4466 (splt->contents + h->plt.offset
4467 + elf_mn10300_plt_symbol_offset (info)));
4469 bfd_put_32 (output_bfd,
4470 (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
4471 (splt->contents + h->plt.offset
4472 + elf_mn10300_plt_plt0_offset (info)));
4476 memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
4477 elf_mn10300_sizeof_plt (info));
4479 bfd_put_32 (output_bfd, got_offset,
4480 (splt->contents + h->plt.offset
4481 + elf_mn10300_plt_symbol_offset (info)));
4484 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4485 (splt->contents + h->plt.offset
4486 + elf_mn10300_plt_reloc_offset (info)));
4488 /* Fill in the entry in the global offset table. */
4489 bfd_put_32 (output_bfd,
4490 (splt->output_section->vma
4491 + splt->output_offset
4493 + elf_mn10300_plt_temp_offset (info)),
4494 sgot->contents + got_offset);
4496 /* Fill in the entry in the .rela.plt section. */
4497 rel.r_offset = (sgot->output_section->vma
4498 + sgot->output_offset
4500 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
4502 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4503 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4506 if (!h->def_regular)
4507 /* Mark the symbol as undefined, rather than as defined in
4508 the .plt section. Leave the value alone. */
4509 sym->st_shndx = SHN_UNDEF;
4512 if (h->got.offset != (bfd_vma) -1)
4516 Elf_Internal_Rela rel;
4518 /* This symbol has an entry in the global offset table. Set it up. */
4520 sgot = bfd_get_section_by_name (dynobj, ".got");
4521 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4522 BFD_ASSERT (sgot != NULL && srel != NULL);
4524 rel.r_offset = (sgot->output_section->vma
4525 + sgot->output_offset
4526 + (h->got.offset &~ 1));
4528 /* If this is a -Bsymbolic link, and the symbol is defined
4529 locally, we just want to emit a RELATIVE reloc. Likewise if
4530 the symbol was forced to be local because of a version file.
4531 The entry in the global offset table will already have been
4532 initialized in the relocate_section function. */
4534 && (info->symbolic || h->dynindx == -1)
4537 rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
4538 rel.r_addend = (h->root.u.def.value
4539 + h->root.u.def.section->output_section->vma
4540 + h->root.u.def.section->output_offset);
4544 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
4545 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
4549 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4550 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4551 + srel->reloc_count));
4552 ++ srel->reloc_count;
4558 Elf_Internal_Rela rel;
4560 /* This symbol needs a copy reloc. Set it up. */
4561 BFD_ASSERT (h->dynindx != -1
4562 && (h->root.type == bfd_link_hash_defined
4563 || h->root.type == bfd_link_hash_defweak));
4565 s = bfd_get_section_by_name (h->root.u.def.section->owner,
4567 BFD_ASSERT (s != NULL);
4569 rel.r_offset = (h->root.u.def.value
4570 + h->root.u.def.section->output_section->vma
4571 + h->root.u.def.section->output_offset);
4572 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
4574 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4575 (bfd_byte *) ((Elf32_External_Rela *) s->contents
4580 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4581 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4582 || h == elf_hash_table (info)->hgot)
4583 sym->st_shndx = SHN_ABS;
4588 /* Finish up the dynamic sections. */
4591 _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
4593 struct bfd_link_info * info;
4599 dynobj = elf_hash_table (info)->dynobj;
4601 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4602 BFD_ASSERT (sgot != NULL);
4603 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4605 if (elf_hash_table (info)->dynamic_sections_created)
4608 Elf32_External_Dyn * dyncon;
4609 Elf32_External_Dyn * dynconend;
4611 BFD_ASSERT (sdyn != NULL);
4613 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4614 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4616 for (; dyncon < dynconend; dyncon++)
4618 Elf_Internal_Dyn dyn;
4622 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4636 s = bfd_get_section_by_name (output_bfd, name);
4637 BFD_ASSERT (s != NULL);
4638 dyn.d_un.d_ptr = s->vma;
4639 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4643 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4644 BFD_ASSERT (s != NULL);
4645 dyn.d_un.d_val = s->size;
4646 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4650 /* My reading of the SVR4 ABI indicates that the
4651 procedure linkage table relocs (DT_JMPREL) should be
4652 included in the overall relocs (DT_RELA). This is
4653 what Solaris does. However, UnixWare can not handle
4654 that case. Therefore, we override the DT_RELASZ entry
4655 here to make it not include the JMPREL relocs. Since
4656 the linker script arranges for .rela.plt to follow all
4657 other relocation sections, we don't have to worry
4658 about changing the DT_RELA entry. */
4659 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4661 dyn.d_un.d_val -= s->size;
4662 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4667 /* Fill in the first entry in the procedure linkage table. */
4668 splt = bfd_get_section_by_name (dynobj, ".plt");
4669 if (splt && splt->size > 0)
4673 memcpy (splt->contents, elf_mn10300_pic_plt_entry,
4674 elf_mn10300_sizeof_plt (info));
4678 memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
4679 bfd_put_32 (output_bfd,
4680 sgot->output_section->vma + sgot->output_offset + 4,
4681 splt->contents + elf_mn10300_plt0_gotid_offset (info));
4682 bfd_put_32 (output_bfd,
4683 sgot->output_section->vma + sgot->output_offset + 8,
4684 splt->contents + elf_mn10300_plt0_linker_offset (info));
4687 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4688 really seem like the right value. */
4689 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
4693 /* Fill in the first three entries in the global offset table. */
4697 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4699 bfd_put_32 (output_bfd,
4700 sdyn->output_section->vma + sdyn->output_offset,
4702 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4703 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4706 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4711 /* Classify relocation types, such that combreloc can sort them
4714 static enum elf_reloc_type_class
4715 _bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela *rela)
4717 switch ((int) ELF32_R_TYPE (rela->r_info))
4719 case R_MN10300_RELATIVE:
4720 return reloc_class_relative;
4721 case R_MN10300_JMP_SLOT:
4722 return reloc_class_plt;
4723 case R_MN10300_COPY:
4724 return reloc_class_copy;
4726 return reloc_class_normal;
4731 #define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec
4732 #define TARGET_LITTLE_NAME "elf32-mn10300"
4733 #define ELF_ARCH bfd_arch_mn10300
4734 #define ELF_MACHINE_CODE EM_MN10300
4735 #define ELF_MACHINE_ALT1 EM_CYGNUS_MN10300
4736 #define ELF_MAXPAGESIZE 0x1000
4739 #define elf_info_to_howto mn10300_info_to_howto
4740 #define elf_info_to_howto_rel 0
4741 #define elf_backend_can_gc_sections 1
4742 #define elf_backend_rela_normal 1
4743 #define elf_backend_check_relocs mn10300_elf_check_relocs
4744 #define elf_backend_gc_mark_hook mn10300_elf_gc_mark_hook
4745 #define elf_backend_relocate_section mn10300_elf_relocate_section
4746 #define bfd_elf32_bfd_relax_section mn10300_elf_relax_section
4747 #define bfd_elf32_bfd_get_relocated_section_contents \
4748 mn10300_elf_get_relocated_section_contents
4749 #define bfd_elf32_bfd_link_hash_table_create \
4750 elf32_mn10300_link_hash_table_create
4751 #define bfd_elf32_bfd_link_hash_table_free \
4752 elf32_mn10300_link_hash_table_free
4754 #ifndef elf_symbol_leading_char
4755 #define elf_symbol_leading_char '_'
4758 /* So we can set bits in e_flags. */
4759 #define elf_backend_final_write_processing \
4760 _bfd_mn10300_elf_final_write_processing
4761 #define elf_backend_object_p _bfd_mn10300_elf_object_p
4763 #define bfd_elf32_bfd_merge_private_bfd_data \
4764 _bfd_mn10300_elf_merge_private_bfd_data
4766 #define elf_backend_can_gc_sections 1
4767 #define elf_backend_create_dynamic_sections \
4768 _bfd_mn10300_elf_create_dynamic_sections
4769 #define elf_backend_adjust_dynamic_symbol \
4770 _bfd_mn10300_elf_adjust_dynamic_symbol
4771 #define elf_backend_size_dynamic_sections \
4772 _bfd_mn10300_elf_size_dynamic_sections
4773 #define elf_backend_omit_section_dynsym \
4774 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4775 #define elf_backend_finish_dynamic_symbol \
4776 _bfd_mn10300_elf_finish_dynamic_symbol
4777 #define elf_backend_finish_dynamic_sections \
4778 _bfd_mn10300_elf_finish_dynamic_sections
4780 #define elf_backend_reloc_type_class \
4781 _bfd_mn10300_elf_reloc_type_class
4783 #define elf_backend_want_got_plt 1
4784 #define elf_backend_plt_readonly 1
4785 #define elf_backend_want_plt_sym 0
4786 #define elf_backend_got_header_size 12
4788 #include "elf32-target.h"