1 /* Matsushita 10300 specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 #include "elf/mn10300.h"
27 static bfd_reloc_status_type mn10300_elf_final_link_relocate
28 PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
29 bfd_vma, bfd_vma, bfd_vma,
30 struct elf_link_hash_entry *, unsigned long, struct bfd_link_info *,
32 static bfd_boolean mn10300_elf_relocate_section
33 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
34 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
35 static bfd_boolean mn10300_elf_relax_section
36 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
37 static bfd_byte * mn10300_elf_get_relocated_section_contents
38 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
39 bfd_byte *, bfd_boolean, asymbol **));
40 static unsigned long elf_mn10300_mach
42 void _bfd_mn10300_elf_final_write_processing
43 PARAMS ((bfd *, bfd_boolean));
44 bfd_boolean _bfd_mn10300_elf_object_p
46 bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data
47 PARAMS ((bfd *,bfd *));
49 /* The mn10300 linker needs to keep track of the number of relocs that
50 it decides to copy in check_relocs for each symbol. This is so
51 that it can discard PC relative relocs if it doesn't need them when
52 linking with -Bsymbolic. We store the information in a field
53 extending the regular ELF linker hash table. */
55 struct elf32_mn10300_link_hash_entry {
56 /* The basic elf link hash table entry. */
57 struct elf_link_hash_entry root;
59 /* For function symbols, the number of times this function is
60 called directly (ie by name). */
61 unsigned int direct_calls;
63 /* For function symbols, the size of this function's stack
64 (if <= 255 bytes). We stuff this into "call" instructions
65 to this target when it's valid and profitable to do so.
67 This does not include stack allocated by movm! */
68 unsigned char stack_size;
70 /* For function symbols, arguments (if any) for movm instruction
71 in the prologue. We stuff this value into "call" instructions
72 to the target when it's valid and profitable to do so. */
73 unsigned char movm_args;
75 /* For function symbols, the amount of stack space that would be allocated
76 by the movm instruction. This is redundant with movm_args, but we
77 add it to the hash table to avoid computing it over and over. */
78 unsigned char movm_stack_size;
80 /* When set, convert all "call" instructions to this target into "calls"
82 #define MN10300_CONVERT_CALL_TO_CALLS 0x1
84 /* Used to mark functions which have had redundant parts of their
86 #define MN10300_DELETED_PROLOGUE_BYTES 0x2
89 /* Calculated value. */
93 /* We derive a hash table from the main elf linker hash table so
94 we can store state variables and a secondary hash table without
95 resorting to global variables. */
96 struct elf32_mn10300_link_hash_table {
97 /* The main hash table. */
98 struct elf_link_hash_table root;
100 /* A hash table for static functions. We could derive a new hash table
101 instead of using the full elf32_mn10300_link_hash_table if we wanted
102 to save some memory. */
103 struct elf32_mn10300_link_hash_table *static_hash_table;
105 /* Random linker state flags. */
106 #define MN10300_HASH_ENTRIES_INITIALIZED 0x1
110 /* For MN10300 linker hash table. */
112 /* Get the MN10300 ELF linker hash table from a link_info structure. */
114 #define elf32_mn10300_hash_table(p) \
115 ((struct elf32_mn10300_link_hash_table *) ((p)->hash))
117 #define elf32_mn10300_link_hash_traverse(table, func, info) \
118 (elf_link_hash_traverse \
120 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
123 static struct bfd_hash_entry *elf32_mn10300_link_hash_newfunc
124 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
125 static struct bfd_link_hash_table *elf32_mn10300_link_hash_table_create
127 static void elf32_mn10300_link_hash_table_free
128 PARAMS ((struct bfd_link_hash_table *));
130 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
131 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
132 static void mn10300_info_to_howto
133 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
134 static bfd_boolean mn10300_elf_check_relocs
135 PARAMS ((bfd *, struct bfd_link_info *, asection *,
136 const Elf_Internal_Rela *));
137 static asection *mn10300_elf_gc_mark_hook
138 PARAMS ((asection *, struct bfd_link_info *info, Elf_Internal_Rela *,
139 struct elf_link_hash_entry *, Elf_Internal_Sym *));
140 static bfd_boolean mn10300_elf_relax_delete_bytes
141 PARAMS ((bfd *, asection *, bfd_vma, int));
142 static bfd_boolean mn10300_elf_symbol_address_p
143 PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
144 static bfd_boolean elf32_mn10300_finish_hash_table_entry
145 PARAMS ((struct bfd_hash_entry *, PTR));
146 static void compute_function_info
147 PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *,
148 bfd_vma, unsigned char *));
150 static bfd_boolean _bfd_mn10300_elf_create_got_section
151 PARAMS ((bfd *, struct bfd_link_info *));
152 static bfd_boolean _bfd_mn10300_elf_create_dynamic_sections
153 PARAMS ((bfd *, struct bfd_link_info *));
154 static bfd_boolean _bfd_mn10300_elf_adjust_dynamic_symbol
155 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
156 static bfd_boolean _bfd_mn10300_elf_size_dynamic_sections
157 PARAMS ((bfd *, struct bfd_link_info *));
158 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_symbol
159 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
160 Elf_Internal_Sym *));
161 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_sections
162 PARAMS ((bfd *, struct bfd_link_info *));
164 static reloc_howto_type elf_mn10300_howto_table[] = {
165 /* Dummy relocation. Does nothing. */
166 HOWTO (R_MN10300_NONE,
172 complain_overflow_bitfield,
173 bfd_elf_generic_reloc,
179 /* Standard 32 bit reloc. */
186 complain_overflow_bitfield,
187 bfd_elf_generic_reloc,
193 /* Standard 16 bit reloc. */
200 complain_overflow_bitfield,
201 bfd_elf_generic_reloc,
207 /* Standard 8 bit reloc. */
214 complain_overflow_bitfield,
215 bfd_elf_generic_reloc,
221 /* Standard 32bit pc-relative reloc. */
222 HOWTO (R_MN10300_PCREL32,
228 complain_overflow_bitfield,
229 bfd_elf_generic_reloc,
235 /* Standard 16bit pc-relative reloc. */
236 HOWTO (R_MN10300_PCREL16,
242 complain_overflow_bitfield,
243 bfd_elf_generic_reloc,
249 /* Standard 8 pc-relative reloc. */
250 HOWTO (R_MN10300_PCREL8,
256 complain_overflow_bitfield,
257 bfd_elf_generic_reloc,
264 /* GNU extension to record C++ vtable hierarchy */
265 HOWTO (R_MN10300_GNU_VTINHERIT, /* type */
267 0, /* size (0 = byte, 1 = short, 2 = long) */
269 FALSE, /* pc_relative */
271 complain_overflow_dont, /* complain_on_overflow */
272 NULL, /* special_function */
273 "R_MN10300_GNU_VTINHERIT", /* name */
274 FALSE, /* partial_inplace */
277 FALSE), /* pcrel_offset */
279 /* GNU extension to record C++ vtable member usage */
280 HOWTO (R_MN10300_GNU_VTENTRY, /* type */
282 0, /* size (0 = byte, 1 = short, 2 = long) */
284 FALSE, /* pc_relative */
286 complain_overflow_dont, /* complain_on_overflow */
287 NULL, /* special_function */
288 "R_MN10300_GNU_VTENTRY", /* name */
289 FALSE, /* partial_inplace */
292 FALSE), /* pcrel_offset */
294 /* Standard 24 bit reloc. */
301 complain_overflow_bitfield,
302 bfd_elf_generic_reloc,
308 HOWTO (R_MN10300_GOTPC32, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 TRUE, /* pc_relative */
314 complain_overflow_bitfield, /* complain_on_overflow */
315 bfd_elf_generic_reloc, /* */
316 "R_MN10300_GOTPC32", /* name */
317 FALSE, /* partial_inplace */
318 0xffffffff, /* src_mask */
319 0xffffffff, /* dst_mask */
320 TRUE), /* pcrel_offset */
322 HOWTO (R_MN10300_GOTPC16, /* type */
324 1, /* size (0 = byte, 1 = short, 2 = long) */
326 TRUE, /* pc_relative */
328 complain_overflow_bitfield, /* complain_on_overflow */
329 bfd_elf_generic_reloc, /* */
330 "R_MN10300_GOTPC16", /* name */
331 FALSE, /* partial_inplace */
332 0xffff, /* src_mask */
333 0xffff, /* dst_mask */
334 TRUE), /* pcrel_offset */
336 HOWTO (R_MN10300_GOTOFF32, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE, /* pc_relative */
342 complain_overflow_bitfield, /* complain_on_overflow */
343 bfd_elf_generic_reloc, /* */
344 "R_MN10300_GOTOFF32", /* name */
345 FALSE, /* partial_inplace */
346 0xffffffff, /* src_mask */
347 0xffffffff, /* dst_mask */
348 FALSE), /* pcrel_offset */
350 HOWTO (R_MN10300_GOTOFF24, /* type */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
354 FALSE, /* pc_relative */
356 complain_overflow_bitfield, /* complain_on_overflow */
357 bfd_elf_generic_reloc, /* */
358 "R_MN10300_GOTOFF24", /* name */
359 FALSE, /* partial_inplace */
360 0xffffff, /* src_mask */
361 0xffffff, /* dst_mask */
362 FALSE), /* pcrel_offset */
364 HOWTO (R_MN10300_GOTOFF16, /* type */
366 1, /* size (0 = byte, 1 = short, 2 = long) */
368 FALSE, /* pc_relative */
370 complain_overflow_bitfield, /* complain_on_overflow */
371 bfd_elf_generic_reloc, /* */
372 "R_MN10300_GOTOFF16", /* name */
373 FALSE, /* partial_inplace */
374 0xffff, /* src_mask */
375 0xffff, /* dst_mask */
376 FALSE), /* pcrel_offset */
378 HOWTO (R_MN10300_PLT32, /* type */
380 2, /* size (0 = byte, 1 = short, 2 = long) */
382 TRUE, /* pc_relative */
384 complain_overflow_bitfield, /* complain_on_overflow */
385 bfd_elf_generic_reloc, /* */
386 "R_MN10300_PLT32", /* name */
387 FALSE, /* partial_inplace */
388 0xffffffff, /* src_mask */
389 0xffffffff, /* dst_mask */
390 TRUE), /* pcrel_offset */
392 HOWTO (R_MN10300_PLT16, /* type */
394 1, /* size (0 = byte, 1 = short, 2 = long) */
396 TRUE, /* pc_relative */
398 complain_overflow_bitfield, /* complain_on_overflow */
399 bfd_elf_generic_reloc, /* */
400 "R_MN10300_PLT16", /* name */
401 FALSE, /* partial_inplace */
402 0xffff, /* src_mask */
403 0xffff, /* dst_mask */
404 TRUE), /* pcrel_offset */
406 HOWTO (R_MN10300_GOT32, /* type */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE, /* pc_relative */
412 complain_overflow_bitfield, /* complain_on_overflow */
413 bfd_elf_generic_reloc, /* */
414 "R_MN10300_GOT32", /* name */
415 FALSE, /* partial_inplace */
416 0xffffffff, /* src_mask */
417 0xffffffff, /* dst_mask */
418 FALSE), /* pcrel_offset */
420 HOWTO (R_MN10300_GOT24, /* type */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
424 FALSE, /* pc_relative */
426 complain_overflow_bitfield, /* complain_on_overflow */
427 bfd_elf_generic_reloc, /* */
428 "R_MN10300_GOT24", /* name */
429 FALSE, /* partial_inplace */
430 0xffffffff, /* src_mask */
431 0xffffffff, /* dst_mask */
432 FALSE), /* pcrel_offset */
434 HOWTO (R_MN10300_GOT16, /* type */
436 1, /* size (0 = byte, 1 = short, 2 = long) */
438 FALSE, /* pc_relative */
440 complain_overflow_bitfield, /* complain_on_overflow */
441 bfd_elf_generic_reloc, /* */
442 "R_MN10300_GOT16", /* name */
443 FALSE, /* partial_inplace */
444 0xffffffff, /* src_mask */
445 0xffffffff, /* dst_mask */
446 FALSE), /* pcrel_offset */
448 HOWTO (R_MN10300_COPY, /* type */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE, /* pc_relative */
454 complain_overflow_bitfield, /* complain_on_overflow */
455 bfd_elf_generic_reloc, /* */
456 "R_MN10300_COPY", /* name */
457 FALSE, /* partial_inplace */
458 0xffffffff, /* src_mask */
459 0xffffffff, /* dst_mask */
460 FALSE), /* pcrel_offset */
462 HOWTO (R_MN10300_GLOB_DAT, /* type */
464 2, /* size (0 = byte, 1 = short, 2 = long) */
466 FALSE, /* pc_relative */
468 complain_overflow_bitfield, /* complain_on_overflow */
469 bfd_elf_generic_reloc, /* */
470 "R_MN10300_GLOB_DAT", /* name */
471 FALSE, /* partial_inplace */
472 0xffffffff, /* src_mask */
473 0xffffffff, /* dst_mask */
474 FALSE), /* pcrel_offset */
476 HOWTO (R_MN10300_JMP_SLOT, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE, /* pc_relative */
482 complain_overflow_bitfield, /* complain_on_overflow */
483 bfd_elf_generic_reloc, /* */
484 "R_MN10300_JMP_SLOT", /* name */
485 FALSE, /* partial_inplace */
486 0xffffffff, /* src_mask */
487 0xffffffff, /* dst_mask */
488 FALSE), /* pcrel_offset */
490 HOWTO (R_MN10300_RELATIVE, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 FALSE, /* pc_relative */
496 complain_overflow_bitfield, /* complain_on_overflow */
497 bfd_elf_generic_reloc, /* */
498 "R_MN10300_RELATIVE", /* name */
499 FALSE, /* partial_inplace */
500 0xffffffff, /* src_mask */
501 0xffffffff, /* dst_mask */
502 FALSE), /* pcrel_offset */
506 struct mn10300_reloc_map {
507 bfd_reloc_code_real_type bfd_reloc_val;
508 unsigned char elf_reloc_val;
511 static const struct mn10300_reloc_map mn10300_reloc_map[] = {
512 { BFD_RELOC_NONE, R_MN10300_NONE, },
513 { BFD_RELOC_32, R_MN10300_32, },
514 { BFD_RELOC_16, R_MN10300_16, },
515 { BFD_RELOC_8, R_MN10300_8, },
516 { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, },
517 { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, },
518 { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, },
519 { BFD_RELOC_24, R_MN10300_24, },
520 { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },
521 { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },
522 { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 },
523 { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 },
524 { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 },
525 { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 },
526 { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 },
527 { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 },
528 { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 },
529 { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 },
530 { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 },
531 { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 },
532 { BFD_RELOC_MN10300_COPY, R_MN10300_COPY },
533 { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT },
534 { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT },
535 { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE },
538 /* Create the GOT section. */
541 _bfd_mn10300_elf_create_got_section (abfd, info)
543 struct bfd_link_info * info;
548 struct elf_link_hash_entry * h;
549 const struct elf_backend_data * bed = get_elf_backend_data (abfd);
552 /* This function may be called more than once. */
553 if (bfd_get_section_by_name (abfd, ".got") != NULL)
556 switch (bed->s->arch_size)
567 bfd_set_error (bfd_error_bad_value);
571 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
572 | SEC_LINKER_CREATED);
575 pltflags |= SEC_CODE;
576 if (bed->plt_not_loaded)
577 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
578 if (bed->plt_readonly)
579 pltflags |= SEC_READONLY;
581 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
583 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
586 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
588 if (bed->want_plt_sym)
590 h = _bfd_elf_define_linkage_sym (abfd, info, s,
591 "_PROCEDURE_LINKAGE_TABLE_");
592 elf_hash_table (info)->hplt = h;
597 s = bfd_make_section_with_flags (abfd, ".got", flags);
599 || ! bfd_set_section_alignment (abfd, s, ptralign))
602 if (bed->want_got_plt)
604 s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
606 || ! bfd_set_section_alignment (abfd, s, ptralign))
610 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
611 (or .got.plt) section. We don't do this in the linker script
612 because we don't want to define the symbol if we are not creating
613 a global offset table. */
614 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
615 elf_hash_table (info)->hgot = h;
619 /* The first bit of the global offset table is the header. */
620 s->size += bed->got_header_size;
625 static reloc_howto_type *
626 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
627 bfd *abfd ATTRIBUTE_UNUSED;
628 bfd_reloc_code_real_type code;
633 i < sizeof (mn10300_reloc_map) / sizeof (struct mn10300_reloc_map);
636 if (mn10300_reloc_map[i].bfd_reloc_val == code)
637 return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
643 /* Set the howto pointer for an MN10300 ELF reloc. */
646 mn10300_info_to_howto (abfd, cache_ptr, dst)
647 bfd *abfd ATTRIBUTE_UNUSED;
649 Elf_Internal_Rela *dst;
653 r_type = ELF32_R_TYPE (dst->r_info);
654 BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX);
655 cache_ptr->howto = &elf_mn10300_howto_table[r_type];
658 /* Look through the relocs for a section during the first phase.
659 Since we don't do .gots or .plts, we just need to consider the
660 virtual table relocs for gc. */
663 mn10300_elf_check_relocs (abfd, info, sec, relocs)
665 struct bfd_link_info *info;
667 const Elf_Internal_Rela *relocs;
669 Elf_Internal_Shdr *symtab_hdr;
670 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
671 const Elf_Internal_Rela *rel;
672 const Elf_Internal_Rela *rel_end;
674 bfd_vma * local_got_offsets;
683 if (info->relocatable)
686 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
687 sym_hashes = elf_sym_hashes (abfd);
688 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
689 if (!elf_bad_symtab (abfd))
690 sym_hashes_end -= symtab_hdr->sh_info;
692 dynobj = elf_hash_table (info)->dynobj;
693 local_got_offsets = elf_local_got_offsets (abfd);
694 rel_end = relocs + sec->reloc_count;
695 for (rel = relocs; rel < rel_end; rel++)
697 struct elf_link_hash_entry *h;
698 unsigned long r_symndx;
700 r_symndx = ELF32_R_SYM (rel->r_info);
701 if (r_symndx < symtab_hdr->sh_info)
705 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
706 while (h->root.type == bfd_link_hash_indirect
707 || h->root.type == bfd_link_hash_warning)
708 h = (struct elf_link_hash_entry *) h->root.u.i.link;
711 /* Some relocs require a global offset table. */
714 switch (ELF32_R_TYPE (rel->r_info))
716 case R_MN10300_GOT32:
717 case R_MN10300_GOT24:
718 case R_MN10300_GOT16:
719 case R_MN10300_GOTOFF32:
720 case R_MN10300_GOTOFF24:
721 case R_MN10300_GOTOFF16:
722 case R_MN10300_GOTPC32:
723 case R_MN10300_GOTPC16:
724 elf_hash_table (info)->dynobj = dynobj = abfd;
725 if (! _bfd_mn10300_elf_create_got_section (dynobj, info))
734 switch (ELF32_R_TYPE (rel->r_info))
736 /* This relocation describes the C++ object vtable hierarchy.
737 Reconstruct it for later use during GC. */
738 case R_MN10300_GNU_VTINHERIT:
739 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
743 /* This relocation describes which C++ vtable entries are actually
744 used. Record for later use during GC. */
745 case R_MN10300_GNU_VTENTRY:
746 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
749 case R_MN10300_GOT32:
750 case R_MN10300_GOT24:
751 case R_MN10300_GOT16:
752 /* This symbol requires a global offset table entry. */
756 sgot = bfd_get_section_by_name (dynobj, ".got");
757 BFD_ASSERT (sgot != NULL);
761 && (h != NULL || info->shared))
763 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
766 srelgot = bfd_make_section_with_flags (dynobj,
775 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
782 if (h->got.offset != (bfd_vma) -1)
783 /* We have already allocated space in the .got. */
786 h->got.offset = sgot->size;
788 /* Make sure this symbol is output as a dynamic symbol. */
789 if (h->dynindx == -1)
791 if (! bfd_elf_link_record_dynamic_symbol (info, h))
795 srelgot->size += sizeof (Elf32_External_Rela);
799 /* This is a global offset table entry for a local
801 if (local_got_offsets == NULL)
806 size = symtab_hdr->sh_info * sizeof (bfd_vma);
807 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
809 if (local_got_offsets == NULL)
811 elf_local_got_offsets (abfd) = local_got_offsets;
813 for (i = 0; i < symtab_hdr->sh_info; i++)
814 local_got_offsets[i] = (bfd_vma) -1;
817 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
818 /* We have already allocated space in the .got. */
821 local_got_offsets[r_symndx] = sgot->size;
824 /* If we are generating a shared object, we need to
825 output a R_MN10300_RELATIVE reloc so that the dynamic
826 linker can adjust this GOT entry. */
827 srelgot->size += sizeof (Elf32_External_Rela);
834 case R_MN10300_PLT32:
835 case R_MN10300_PLT16:
836 /* This symbol requires a procedure linkage table entry. We
837 actually build the entry in adjust_dynamic_symbol,
838 because this might be a case of linking PIC code which is
839 never referenced by a dynamic object, in which case we
840 don't need to generate a procedure linkage table entry
843 /* If this is a local symbol, we resolve it directly without
844 creating a procedure linkage table entry. */
848 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
849 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
859 case R_MN10300_PCREL32:
860 case R_MN10300_PCREL16:
861 case R_MN10300_PCREL8:
870 /* If we are creating a shared library, then we need to copy
871 the reloc into the shared library. */
873 && (sec->flags & SEC_ALLOC) != 0)
875 /* When creating a shared object, we must copy these
876 reloc types into the output file. We create a reloc
877 section in dynobj and make room for this reloc. */
882 name = (bfd_elf_string_from_elf_section
884 elf_elfheader (abfd)->e_shstrndx,
885 elf_section_data (sec)->rel_hdr.sh_name));
889 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
890 && strcmp (bfd_get_section_name (abfd, sec),
893 sreloc = bfd_get_section_by_name (dynobj, name);
898 flags = (SEC_HAS_CONTENTS | SEC_READONLY
899 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
900 if ((sec->flags & SEC_ALLOC) != 0)
901 flags |= SEC_ALLOC | SEC_LOAD;
902 sreloc = bfd_make_section_with_flags (dynobj,
906 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
911 sreloc->size += sizeof (Elf32_External_Rela);
921 /* Return the section that should be marked against GC for a given
925 mn10300_elf_gc_mark_hook (sec, info, rel, h, sym)
927 struct bfd_link_info *info ATTRIBUTE_UNUSED;
928 Elf_Internal_Rela *rel;
929 struct elf_link_hash_entry *h;
930 Elf_Internal_Sym *sym;
934 switch (ELF32_R_TYPE (rel->r_info))
936 case R_MN10300_GNU_VTINHERIT:
937 case R_MN10300_GNU_VTENTRY:
941 switch (h->root.type)
943 case bfd_link_hash_defined:
944 case bfd_link_hash_defweak:
945 return h->root.u.def.section;
947 case bfd_link_hash_common:
948 return h->root.u.c.p->section;
956 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
961 /* Perform a relocation as part of a final link. */
962 static bfd_reloc_status_type
963 mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
964 input_section, contents, offset, value,
965 addend, h, symndx, info, sym_sec, is_local)
966 reloc_howto_type *howto;
968 bfd *output_bfd ATTRIBUTE_UNUSED;
969 asection *input_section;
974 struct elf_link_hash_entry * h;
975 unsigned long symndx;
976 struct bfd_link_info *info;
977 asection *sym_sec ATTRIBUTE_UNUSED;
978 int is_local ATTRIBUTE_UNUSED;
980 unsigned long r_type = howto->type;
981 bfd_byte *hit_data = contents + offset;
983 bfd_vma * local_got_offsets;
988 dynobj = elf_hash_table (info)->dynobj;
989 local_got_offsets = elf_local_got_offsets (input_bfd);
1000 case R_MN10300_PCREL8:
1001 case R_MN10300_PCREL16:
1002 case R_MN10300_PCREL32:
1003 case R_MN10300_GOTOFF32:
1004 case R_MN10300_GOTOFF24:
1005 case R_MN10300_GOTOFF16:
1007 && (input_section->flags & SEC_ALLOC) != 0
1009 && ! SYMBOL_REFERENCES_LOCAL (info, h))
1010 return bfd_reloc_dangerous;
1015 case R_MN10300_NONE:
1016 return bfd_reloc_ok;
1020 && (input_section->flags & SEC_ALLOC) != 0)
1022 Elf_Internal_Rela outrel;
1023 bfd_boolean skip, relocate;
1025 /* When generating a shared object, these relocations are
1026 copied into the output file to be resolved at run
1032 name = (bfd_elf_string_from_elf_section
1034 elf_elfheader (input_bfd)->e_shstrndx,
1035 elf_section_data (input_section)->rel_hdr.sh_name));
1039 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1040 && strcmp (bfd_get_section_name (input_bfd,
1044 sreloc = bfd_get_section_by_name (dynobj, name);
1045 BFD_ASSERT (sreloc != NULL);
1050 outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
1051 input_section, offset);
1052 if (outrel.r_offset == (bfd_vma) -1)
1055 outrel.r_offset += (input_section->output_section->vma
1056 + input_section->output_offset);
1060 memset (&outrel, 0, sizeof outrel);
1065 /* h->dynindx may be -1 if this symbol was marked to
1068 || SYMBOL_REFERENCES_LOCAL (info, h))
1071 outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1072 outrel.r_addend = value + addend;
1076 BFD_ASSERT (h->dynindx != -1);
1078 outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32);
1079 outrel.r_addend = value + addend;
1083 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1084 (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
1085 + sreloc->reloc_count));
1086 ++sreloc->reloc_count;
1088 /* If this reloc is against an external symbol, we do
1089 not want to fiddle with the addend. Otherwise, we
1090 need to include the symbol value so that it becomes
1091 an addend for the dynamic reloc. */
1093 return bfd_reloc_ok;
1096 bfd_put_32 (input_bfd, value, hit_data);
1097 return bfd_reloc_ok;
1102 if ((long) value > 0x7fffff || (long) value < -0x800000)
1103 return bfd_reloc_overflow;
1105 bfd_put_8 (input_bfd, value & 0xff, hit_data);
1106 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1107 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1108 return bfd_reloc_ok;
1113 if ((long) value > 0x7fff || (long) value < -0x8000)
1114 return bfd_reloc_overflow;
1116 bfd_put_16 (input_bfd, value, hit_data);
1117 return bfd_reloc_ok;
1122 if ((long) value > 0x7f || (long) value < -0x80)
1123 return bfd_reloc_overflow;
1125 bfd_put_8 (input_bfd, value, hit_data);
1126 return bfd_reloc_ok;
1128 case R_MN10300_PCREL8:
1129 value -= (input_section->output_section->vma
1130 + input_section->output_offset);
1134 if ((long) value > 0xff || (long) value < -0x100)
1135 return bfd_reloc_overflow;
1137 bfd_put_8 (input_bfd, value, hit_data);
1138 return bfd_reloc_ok;
1140 case R_MN10300_PCREL16:
1141 value -= (input_section->output_section->vma
1142 + input_section->output_offset);
1146 if ((long) value > 0xffff || (long) value < -0x10000)
1147 return bfd_reloc_overflow;
1149 bfd_put_16 (input_bfd, value, hit_data);
1150 return bfd_reloc_ok;
1152 case R_MN10300_PCREL32:
1153 value -= (input_section->output_section->vma
1154 + input_section->output_offset);
1158 bfd_put_32 (input_bfd, value, hit_data);
1159 return bfd_reloc_ok;
1161 case R_MN10300_GNU_VTINHERIT:
1162 case R_MN10300_GNU_VTENTRY:
1163 return bfd_reloc_ok;
1165 case R_MN10300_GOTPC32:
1166 /* Use global offset table as symbol value. */
1168 value = bfd_get_section_by_name (dynobj,
1169 ".got")->output_section->vma;
1170 value -= (input_section->output_section->vma
1171 + input_section->output_offset);
1175 bfd_put_32 (input_bfd, value, hit_data);
1176 return bfd_reloc_ok;
1178 case R_MN10300_GOTPC16:
1179 /* Use global offset table as symbol value. */
1181 value = bfd_get_section_by_name (dynobj,
1182 ".got")->output_section->vma;
1183 value -= (input_section->output_section->vma
1184 + input_section->output_offset);
1188 if ((long) value > 0xffff || (long) value < -0x10000)
1189 return bfd_reloc_overflow;
1191 bfd_put_16 (input_bfd, value, hit_data);
1192 return bfd_reloc_ok;
1194 case R_MN10300_GOTOFF32:
1195 value -= bfd_get_section_by_name (dynobj,
1196 ".got")->output_section->vma;
1199 bfd_put_32 (input_bfd, value, hit_data);
1200 return bfd_reloc_ok;
1202 case R_MN10300_GOTOFF24:
1203 value -= bfd_get_section_by_name (dynobj,
1204 ".got")->output_section->vma;
1207 if ((long) value > 0x7fffff || (long) value < -0x800000)
1208 return bfd_reloc_overflow;
1210 bfd_put_8 (input_bfd, value, hit_data);
1211 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1212 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1213 return bfd_reloc_ok;
1215 case R_MN10300_GOTOFF16:
1216 value -= bfd_get_section_by_name (dynobj,
1217 ".got")->output_section->vma;
1220 if ((long) value > 0xffff || (long) value < -0x10000)
1221 return bfd_reloc_overflow;
1223 bfd_put_16 (input_bfd, value, hit_data);
1224 return bfd_reloc_ok;
1226 case R_MN10300_PLT32:
1228 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1229 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1230 && h->plt.offset != (bfd_vma) -1)
1234 splt = bfd_get_section_by_name (dynobj, ".plt");
1236 value = (splt->output_section->vma
1237 + splt->output_offset
1238 + h->plt.offset) - value;
1241 value -= (input_section->output_section->vma
1242 + input_section->output_offset);
1246 bfd_put_32 (input_bfd, value, hit_data);
1247 return bfd_reloc_ok;
1249 case R_MN10300_PLT16:
1251 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1252 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1253 && h->plt.offset != (bfd_vma) -1)
1257 splt = bfd_get_section_by_name (dynobj, ".plt");
1259 value = (splt->output_section->vma
1260 + splt->output_offset
1261 + h->plt.offset) - value;
1264 value -= (input_section->output_section->vma
1265 + input_section->output_offset);
1269 if ((long) value > 0xffff || (long) value < -0x10000)
1270 return bfd_reloc_overflow;
1272 bfd_put_16 (input_bfd, value, hit_data);
1273 return bfd_reloc_ok;
1275 case R_MN10300_GOT32:
1276 case R_MN10300_GOT24:
1277 case R_MN10300_GOT16:
1281 sgot = bfd_get_section_by_name (dynobj, ".got");
1287 off = h->got.offset;
1288 BFD_ASSERT (off != (bfd_vma) -1);
1290 if (! elf_hash_table (info)->dynamic_sections_created
1291 || SYMBOL_REFERENCES_LOCAL (info, h))
1292 /* This is actually a static link, or it is a
1293 -Bsymbolic link and the symbol is defined
1294 locally, or the symbol was forced to be local
1295 because of a version file. We must initialize
1296 this entry in the global offset table.
1298 When doing a dynamic link, we create a .rela.got
1299 relocation entry to initialize the value. This
1300 is done in the finish_dynamic_symbol routine. */
1301 bfd_put_32 (output_bfd, value,
1302 sgot->contents + off);
1304 value = sgot->output_offset + off;
1310 off = elf_local_got_offsets (input_bfd)[symndx];
1312 bfd_put_32 (output_bfd, value, sgot->contents + off);
1317 Elf_Internal_Rela outrel;
1319 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1320 BFD_ASSERT (srelgot != NULL);
1322 outrel.r_offset = (sgot->output_section->vma
1323 + sgot->output_offset
1325 outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1326 outrel.r_addend = value;
1327 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1328 (bfd_byte *) (((Elf32_External_Rela *)
1330 + srelgot->reloc_count));
1331 ++ srelgot->reloc_count;
1334 value = sgot->output_offset + off;
1340 if (r_type == R_MN10300_GOT32)
1342 bfd_put_32 (input_bfd, value, hit_data);
1343 return bfd_reloc_ok;
1345 else if (r_type == R_MN10300_GOT24)
1347 if ((long) value > 0x7fffff || (long) value < -0x800000)
1348 return bfd_reloc_overflow;
1350 bfd_put_8 (input_bfd, value & 0xff, hit_data);
1351 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1352 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1353 return bfd_reloc_ok;
1355 else if (r_type == R_MN10300_GOT16)
1357 if ((long) value > 0xffff || (long) value < -0x10000)
1358 return bfd_reloc_overflow;
1360 bfd_put_16 (input_bfd, value, hit_data);
1361 return bfd_reloc_ok;
1366 return bfd_reloc_notsupported;
1370 /* Relocate an MN10300 ELF section. */
1372 mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1373 contents, relocs, local_syms, local_sections)
1375 struct bfd_link_info *info;
1377 asection *input_section;
1379 Elf_Internal_Rela *relocs;
1380 Elf_Internal_Sym *local_syms;
1381 asection **local_sections;
1383 Elf_Internal_Shdr *symtab_hdr;
1384 struct elf_link_hash_entry **sym_hashes;
1385 Elf_Internal_Rela *rel, *relend;
1387 if (info->relocatable)
1390 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1391 sym_hashes = elf_sym_hashes (input_bfd);
1394 relend = relocs + input_section->reloc_count;
1395 for (; rel < relend; rel++)
1398 reloc_howto_type *howto;
1399 unsigned long r_symndx;
1400 Elf_Internal_Sym *sym;
1402 struct elf32_mn10300_link_hash_entry *h;
1404 bfd_reloc_status_type r;
1406 r_symndx = ELF32_R_SYM (rel->r_info);
1407 r_type = ELF32_R_TYPE (rel->r_info);
1408 howto = elf_mn10300_howto_table + r_type;
1410 /* Just skip the vtable gc relocs. */
1411 if (r_type == R_MN10300_GNU_VTINHERIT
1412 || r_type == R_MN10300_GNU_VTENTRY)
1418 if (r_symndx < symtab_hdr->sh_info)
1420 sym = local_syms + r_symndx;
1421 sec = local_sections[r_symndx];
1422 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1426 bfd_boolean unresolved_reloc;
1428 struct elf_link_hash_entry *hh;
1430 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1431 r_symndx, symtab_hdr, sym_hashes,
1432 hh, sec, relocation,
1433 unresolved_reloc, warned);
1435 h = (struct elf32_mn10300_link_hash_entry *) hh;
1437 if ((h->root.root.type == bfd_link_hash_defined
1438 || h->root.root.type == bfd_link_hash_defweak)
1439 && ( r_type == R_MN10300_GOTPC32
1440 || r_type == R_MN10300_GOTPC16
1441 || (( r_type == R_MN10300_PLT32
1442 || r_type == R_MN10300_PLT16)
1443 && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
1444 && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
1445 && h->root.plt.offset != (bfd_vma) -1)
1446 || (( r_type == R_MN10300_GOT32
1447 || r_type == R_MN10300_GOT24
1448 || r_type == R_MN10300_GOT16)
1449 && elf_hash_table (info)->dynamic_sections_created
1450 && !SYMBOL_REFERENCES_LOCAL (info, hh))
1451 || (r_type == R_MN10300_32
1452 && !SYMBOL_REFERENCES_LOCAL (info, hh)
1453 && ((input_section->flags & SEC_ALLOC) != 0
1454 /* DWARF will emit R_MN10300_32 relocations
1455 in its sections against symbols defined
1456 externally in shared libraries. We can't
1457 do anything with them here. */
1458 || ((input_section->flags & SEC_DEBUGGING) != 0
1459 && h->root.def_dynamic)))))
1460 /* In these cases, we don't need the relocation
1461 value. We check specially because in some
1462 obscure cases sec->output_section will be NULL. */
1465 else if (unresolved_reloc)
1466 (*_bfd_error_handler)
1467 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1470 (long) rel->r_offset,
1472 h->root.root.root.string);
1475 r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
1477 contents, rel->r_offset,
1478 relocation, rel->r_addend,
1479 (struct elf_link_hash_entry *)h,
1481 info, sec, h == NULL);
1483 if (r != bfd_reloc_ok)
1486 const char *msg = (const char *) 0;
1489 name = h->root.root.root.string;
1492 name = (bfd_elf_string_from_elf_section
1493 (input_bfd, symtab_hdr->sh_link, sym->st_name));
1494 if (name == NULL || *name == '\0')
1495 name = bfd_section_name (input_bfd, sec);
1500 case bfd_reloc_overflow:
1501 if (! ((*info->callbacks->reloc_overflow)
1502 (info, (h ? &h->root.root : NULL), name,
1503 howto->name, (bfd_vma) 0, input_bfd,
1504 input_section, rel->r_offset)))
1508 case bfd_reloc_undefined:
1509 if (! ((*info->callbacks->undefined_symbol)
1510 (info, name, input_bfd, input_section,
1511 rel->r_offset, TRUE)))
1515 case bfd_reloc_outofrange:
1516 msg = _("internal error: out of range error");
1519 case bfd_reloc_notsupported:
1520 msg = _("internal error: unsupported relocation error");
1523 case bfd_reloc_dangerous:
1524 msg = _("internal error: dangerous error");
1528 msg = _("internal error: unknown error");
1532 if (!((*info->callbacks->warning)
1533 (info, msg, name, input_bfd, input_section,
1544 /* Finish initializing one hash table entry. */
1546 elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
1547 struct bfd_hash_entry *gen_entry;
1550 struct elf32_mn10300_link_hash_entry *entry;
1551 struct bfd_link_info *link_info = (struct bfd_link_info *)in_args;
1552 unsigned int byte_count = 0;
1554 entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
1556 if (entry->root.root.type == bfd_link_hash_warning)
1557 entry = (struct elf32_mn10300_link_hash_entry *) entry->root.root.u.i.link;
1559 /* If we already know we want to convert "call" to "calls" for calls
1560 to this symbol, then return now. */
1561 if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
1564 /* If there are no named calls to this symbol, or there's nothing we
1565 can move from the function itself into the "call" instruction,
1566 then note that all "call" instructions should be converted into
1567 "calls" instructions and return. If a symbol is available for
1568 dynamic symbol resolution (overridable or overriding), avoid
1569 custom calling conventions. */
1570 if (entry->direct_calls == 0
1571 || (entry->stack_size == 0 && entry->movm_args == 0)
1572 || (elf_hash_table (link_info)->dynamic_sections_created
1573 && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
1574 && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
1576 /* Make a note that we should convert "call" instructions to "calls"
1577 instructions for calls to this symbol. */
1578 entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1582 /* We may be able to move some instructions from the function itself into
1583 the "call" instruction. Count how many bytes we might be able to
1584 eliminate in the function itself. */
1586 /* A movm instruction is two bytes. */
1587 if (entry->movm_args)
1590 /* Count the insn to allocate stack space too. */
1591 if (entry->stack_size > 0)
1593 if (entry->stack_size <= 128)
1599 /* If using "call" will result in larger code, then turn all
1600 the associated "call" instructions into "calls" instructions. */
1601 if (byte_count < entry->direct_calls)
1602 entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1604 /* This routine never fails. */
1608 /* Used to count hash table entries. */
1610 elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED,
1613 int *count = (int *)in_args;
1619 /* Used to enumerate hash table entries into a linear array. */
1621 elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry,
1624 struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args;
1631 /* Used to sort the array created by the above. */
1633 sort_by_value (const void *va, const void *vb)
1635 struct elf32_mn10300_link_hash_entry *a
1636 = *(struct elf32_mn10300_link_hash_entry **)va;
1637 struct elf32_mn10300_link_hash_entry *b
1638 = *(struct elf32_mn10300_link_hash_entry **)vb;
1640 return a->value - b->value;
1644 /* This function handles relaxing for the mn10300.
1646 There are quite a few relaxing opportunities available on the mn10300:
1648 * calls:32 -> calls:16 2 bytes
1649 * call:32 -> call:16 2 bytes
1651 * call:32 -> calls:32 1 byte
1652 * call:16 -> calls:16 1 byte
1653 * These are done anytime using "calls" would result
1654 in smaller code, or when necessary to preserve the
1655 meaning of the program.
1659 * In some circumstances we can move instructions
1660 from a function prologue into a "call" instruction.
1661 This is only done if the resulting code is no larger
1662 than the original code.
1664 * jmp:32 -> jmp:16 2 bytes
1665 * jmp:16 -> bra:8 1 byte
1667 * If the previous instruction is a conditional branch
1668 around the jump/bra, we may be able to reverse its condition
1669 and change its target to the jump's target. The jump/bra
1670 can then be deleted. 2 bytes
1672 * mov abs32 -> mov abs16 1 or 2 bytes
1674 * Most instructions which accept imm32 can relax to imm16 1 or 2 bytes
1675 - Most instructions which accept imm16 can relax to imm8 1 or 2 bytes
1677 * Most instructions which accept d32 can relax to d16 1 or 2 bytes
1678 - Most instructions which accept d16 can relax to d8 1 or 2 bytes
1680 We don't handle imm16->imm8 or d16->d8 as they're very rare
1681 and somewhat more difficult to support. */
1684 mn10300_elf_relax_section (abfd, sec, link_info, again)
1687 struct bfd_link_info *link_info;
1690 Elf_Internal_Shdr *symtab_hdr;
1691 Elf_Internal_Rela *internal_relocs = NULL;
1692 Elf_Internal_Rela *irel, *irelend;
1693 bfd_byte *contents = NULL;
1694 Elf_Internal_Sym *isymbuf = NULL;
1695 struct elf32_mn10300_link_hash_table *hash_table;
1696 asection *section = sec;
1698 /* Assume nothing changes. */
1701 /* We need a pointer to the mn10300 specific hash table. */
1702 hash_table = elf32_mn10300_hash_table (link_info);
1704 /* Initialize fields in each hash table entry the first time through. */
1705 if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0)
1709 /* Iterate over all the input bfds. */
1710 for (input_bfd = link_info->input_bfds;
1712 input_bfd = input_bfd->link_next)
1714 /* We're going to need all the symbols for each bfd. */
1715 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1716 if (symtab_hdr->sh_info != 0)
1718 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1719 if (isymbuf == NULL)
1720 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
1721 symtab_hdr->sh_info, 0,
1723 if (isymbuf == NULL)
1727 /* Iterate over each section in this bfd. */
1728 for (section = input_bfd->sections;
1730 section = section->next)
1732 struct elf32_mn10300_link_hash_entry *hash;
1733 Elf_Internal_Sym *sym;
1734 asection *sym_sec = NULL;
1735 const char *sym_name;
1738 /* If there's nothing to do in this section, skip it. */
1739 if (! ((section->flags & SEC_RELOC) != 0
1740 && section->reloc_count != 0))
1742 if ((section->flags & SEC_ALLOC) == 0)
1745 /* Get cached copy of section contents if it exists. */
1746 if (elf_section_data (section)->this_hdr.contents != NULL)
1747 contents = elf_section_data (section)->this_hdr.contents;
1748 else if (section->size != 0)
1750 /* Go get them off disk. */
1751 if (!bfd_malloc_and_get_section (input_bfd, section,
1758 /* If there aren't any relocs, then there's nothing to do. */
1759 if ((section->flags & SEC_RELOC) != 0
1760 && section->reloc_count != 0)
1763 /* Get a copy of the native relocations. */
1764 internal_relocs = (_bfd_elf_link_read_relocs
1765 (input_bfd, section, (PTR) NULL,
1766 (Elf_Internal_Rela *) NULL,
1767 link_info->keep_memory));
1768 if (internal_relocs == NULL)
1771 /* Now examine each relocation. */
1772 irel = internal_relocs;
1773 irelend = irel + section->reloc_count;
1774 for (; irel < irelend; irel++)
1777 unsigned long r_index;
1780 r_type = ELF32_R_TYPE (irel->r_info);
1781 r_index = ELF32_R_SYM (irel->r_info);
1783 if (r_type < 0 || r_type >= (int) R_MN10300_MAX)
1786 /* We need the name and hash table entry of the target
1792 if (r_index < symtab_hdr->sh_info)
1794 /* A local symbol. */
1795 Elf_Internal_Sym *isym;
1796 struct elf_link_hash_table *elftab;
1799 isym = isymbuf + r_index;
1800 if (isym->st_shndx == SHN_UNDEF)
1801 sym_sec = bfd_und_section_ptr;
1802 else if (isym->st_shndx == SHN_ABS)
1803 sym_sec = bfd_abs_section_ptr;
1804 else if (isym->st_shndx == SHN_COMMON)
1805 sym_sec = bfd_com_section_ptr;
1808 = bfd_section_from_elf_index (input_bfd,
1812 = bfd_elf_string_from_elf_section (input_bfd,
1817 /* If it isn't a function, then we don't care
1819 if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
1822 /* Tack on an ID so we can uniquely identify this
1823 local symbol in the global hash table. */
1824 amt = strlen (sym_name) + 10;
1825 new_name = bfd_malloc (amt);
1829 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
1830 sym_name = new_name;
1832 elftab = &hash_table->static_hash_table->root;
1833 hash = ((struct elf32_mn10300_link_hash_entry *)
1834 elf_link_hash_lookup (elftab, sym_name,
1835 TRUE, TRUE, FALSE));
1840 r_index -= symtab_hdr->sh_info;
1841 hash = (struct elf32_mn10300_link_hash_entry *)
1842 elf_sym_hashes (input_bfd)[r_index];
1845 sym_name = hash->root.root.root.string;
1846 if ((section->flags & SEC_CODE) != 0)
1848 /* If this is not a "call" instruction, then we
1849 should convert "call" instructions to "calls"
1851 code = bfd_get_8 (input_bfd,
1852 contents + irel->r_offset - 1);
1853 if (code != 0xdd && code != 0xcd)
1854 hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1857 /* If this is a jump/call, then bump the
1858 direct_calls counter. Else force "call" to
1859 "calls" conversions. */
1860 if (r_type == R_MN10300_PCREL32
1861 || r_type == R_MN10300_PLT32
1862 || r_type == R_MN10300_PLT16
1863 || r_type == R_MN10300_PCREL16)
1864 hash->direct_calls++;
1866 hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1870 /* Now look at the actual contents to get the stack size,
1871 and a list of what registers were saved in the prologue
1873 if ((section->flags & SEC_CODE) != 0)
1875 Elf_Internal_Sym *isym, *isymend;
1876 unsigned int sec_shndx;
1877 struct elf_link_hash_entry **hashes;
1878 struct elf_link_hash_entry **end_hashes;
1879 unsigned int symcount;
1881 sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
1884 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1885 - symtab_hdr->sh_info);
1886 hashes = elf_sym_hashes (input_bfd);
1887 end_hashes = hashes + symcount;
1889 /* Look at each function defined in this section and
1890 update info for that function. */
1891 isymend = isymbuf + symtab_hdr->sh_info;
1892 for (isym = isymbuf; isym < isymend; isym++)
1894 if (isym->st_shndx == sec_shndx
1895 && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
1897 struct elf_link_hash_table *elftab;
1899 struct elf_link_hash_entry **lhashes = hashes;
1901 /* Skip a local symbol if it aliases a
1903 for (; lhashes < end_hashes; lhashes++)
1905 hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
1906 if ((hash->root.root.type == bfd_link_hash_defined
1907 || hash->root.root.type == bfd_link_hash_defweak)
1908 && hash->root.root.u.def.section == section
1909 && hash->root.type == STT_FUNC
1910 && hash->root.root.u.def.value == isym->st_value)
1913 if (lhashes != end_hashes)
1916 if (isym->st_shndx == SHN_UNDEF)
1917 sym_sec = bfd_und_section_ptr;
1918 else if (isym->st_shndx == SHN_ABS)
1919 sym_sec = bfd_abs_section_ptr;
1920 else if (isym->st_shndx == SHN_COMMON)
1921 sym_sec = bfd_com_section_ptr;
1924 = bfd_section_from_elf_index (input_bfd,
1927 sym_name = (bfd_elf_string_from_elf_section
1928 (input_bfd, symtab_hdr->sh_link,
1931 /* Tack on an ID so we can uniquely identify this
1932 local symbol in the global hash table. */
1933 amt = strlen (sym_name) + 10;
1934 new_name = bfd_malloc (amt);
1938 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
1939 sym_name = new_name;
1941 elftab = &hash_table->static_hash_table->root;
1942 hash = ((struct elf32_mn10300_link_hash_entry *)
1943 elf_link_hash_lookup (elftab, sym_name,
1944 TRUE, TRUE, FALSE));
1946 compute_function_info (input_bfd, hash,
1947 isym->st_value, contents);
1948 hash->value = isym->st_value;
1952 for (; hashes < end_hashes; hashes++)
1954 hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
1955 if ((hash->root.root.type == bfd_link_hash_defined
1956 || hash->root.root.type == bfd_link_hash_defweak)
1957 && hash->root.root.u.def.section == section
1958 && hash->root.type == STT_FUNC)
1959 compute_function_info (input_bfd, hash,
1960 (hash)->root.root.u.def.value,
1965 /* Cache or free any memory we allocated for the relocs. */
1966 if (internal_relocs != NULL
1967 && elf_section_data (section)->relocs != internal_relocs)
1968 free (internal_relocs);
1969 internal_relocs = NULL;
1971 /* Cache or free any memory we allocated for the contents. */
1972 if (contents != NULL
1973 && elf_section_data (section)->this_hdr.contents != contents)
1975 if (! link_info->keep_memory)
1979 /* Cache the section contents for elf_link_input_bfd. */
1980 elf_section_data (section)->this_hdr.contents = contents;
1986 /* Cache or free any memory we allocated for the symbols. */
1988 && symtab_hdr->contents != (unsigned char *) isymbuf)
1990 if (! link_info->keep_memory)
1994 /* Cache the symbols for elf_link_input_bfd. */
1995 symtab_hdr->contents = (unsigned char *) isymbuf;
2001 /* Now iterate on each symbol in the hash table and perform
2002 the final initialization steps on each. */
2003 elf32_mn10300_link_hash_traverse (hash_table,
2004 elf32_mn10300_finish_hash_table_entry,
2006 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2007 elf32_mn10300_finish_hash_table_entry,
2011 /* This section of code collects all our local symbols, sorts
2012 them by value, and looks for multiple symbols referring to
2013 the same address. For those symbols, the flags are merged.
2014 At this point, the only flag that can be set is
2015 MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
2017 int static_count = 0, i;
2018 struct elf32_mn10300_link_hash_entry **entries;
2019 struct elf32_mn10300_link_hash_entry **ptr;
2021 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2022 elf32_mn10300_count_hash_table_entries,
2025 entries = (struct elf32_mn10300_link_hash_entry **)
2026 bfd_malloc (static_count * sizeof (struct elf32_mn10300_link_hash_entry *));
2029 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2030 elf32_mn10300_list_hash_table_entries,
2033 qsort (entries, static_count, sizeof(entries[0]), sort_by_value);
2035 for (i=0; i<static_count-1; i++)
2036 if (entries[i]->value && entries[i]->value == entries[i+1]->value)
2038 int v = entries[i]->flags;
2040 for (j=i+1; j<static_count && entries[j]->value == entries[i]->value; j++)
2041 v |= entries[j]->flags;
2042 for (j=i; j<static_count && entries[j]->value == entries[i]->value; j++)
2043 entries[j]->flags = v;
2048 /* All entries in the hash table are fully initialized. */
2049 hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
2051 /* Now that everything has been initialized, go through each
2052 code section and delete any prologue insns which will be
2053 redundant because their operations will be performed by
2054 a "call" instruction. */
2055 for (input_bfd = link_info->input_bfds;
2057 input_bfd = input_bfd->link_next)
2059 /* We're going to need all the local symbols for each bfd. */
2060 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2061 if (symtab_hdr->sh_info != 0)
2063 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2064 if (isymbuf == NULL)
2065 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2066 symtab_hdr->sh_info, 0,
2068 if (isymbuf == NULL)
2072 /* Walk over each section in this bfd. */
2073 for (section = input_bfd->sections;
2075 section = section->next)
2077 unsigned int sec_shndx;
2078 Elf_Internal_Sym *isym, *isymend;
2079 struct elf_link_hash_entry **hashes;
2080 struct elf_link_hash_entry **end_hashes;
2081 unsigned int symcount;
2083 /* Skip non-code sections and empty sections. */
2084 if ((section->flags & SEC_CODE) == 0 || section->size == 0)
2087 if (section->reloc_count != 0)
2089 /* Get a copy of the native relocations. */
2090 internal_relocs = (_bfd_elf_link_read_relocs
2091 (input_bfd, section, (PTR) NULL,
2092 (Elf_Internal_Rela *) NULL,
2093 link_info->keep_memory));
2094 if (internal_relocs == NULL)
2098 /* Get cached copy of section contents if it exists. */
2099 if (elf_section_data (section)->this_hdr.contents != NULL)
2100 contents = elf_section_data (section)->this_hdr.contents;
2103 /* Go get them off disk. */
2104 if (!bfd_malloc_and_get_section (input_bfd, section,
2109 sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
2112 /* Now look for any function in this section which needs
2113 insns deleted from its prologue. */
2114 isymend = isymbuf + symtab_hdr->sh_info;
2115 for (isym = isymbuf; isym < isymend; isym++)
2117 struct elf32_mn10300_link_hash_entry *sym_hash;
2118 asection *sym_sec = NULL;
2119 const char *sym_name;
2121 struct elf_link_hash_table *elftab;
2124 if (isym->st_shndx != sec_shndx)
2127 if (isym->st_shndx == SHN_UNDEF)
2128 sym_sec = bfd_und_section_ptr;
2129 else if (isym->st_shndx == SHN_ABS)
2130 sym_sec = bfd_abs_section_ptr;
2131 else if (isym->st_shndx == SHN_COMMON)
2132 sym_sec = bfd_com_section_ptr;
2135 = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
2138 = bfd_elf_string_from_elf_section (input_bfd,
2139 symtab_hdr->sh_link,
2142 /* Tack on an ID so we can uniquely identify this
2143 local symbol in the global hash table. */
2144 amt = strlen (sym_name) + 10;
2145 new_name = bfd_malloc (amt);
2148 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2149 sym_name = new_name;
2151 elftab = &hash_table->static_hash_table->root;
2152 sym_hash = ((struct elf32_mn10300_link_hash_entry *)
2153 elf_link_hash_lookup (elftab, sym_name,
2154 FALSE, FALSE, FALSE));
2157 if (sym_hash == NULL)
2160 if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
2161 && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
2165 /* Note that we've changed things. */
2166 elf_section_data (section)->relocs = internal_relocs;
2167 elf_section_data (section)->this_hdr.contents = contents;
2168 symtab_hdr->contents = (unsigned char *) isymbuf;
2170 /* Count how many bytes we're going to delete. */
2171 if (sym_hash->movm_args)
2174 if (sym_hash->stack_size > 0)
2176 if (sym_hash->stack_size <= 128)
2182 /* Note that we've deleted prologue bytes for this
2184 sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
2186 /* Actually delete the bytes. */
2187 if (!mn10300_elf_relax_delete_bytes (input_bfd,
2193 /* Something changed. Not strictly necessary, but
2194 may lead to more relaxing opportunities. */
2199 /* Look for any global functions in this section which
2200 need insns deleted from their prologues. */
2201 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2202 - symtab_hdr->sh_info);
2203 hashes = elf_sym_hashes (input_bfd);
2204 end_hashes = hashes + symcount;
2205 for (; hashes < end_hashes; hashes++)
2207 struct elf32_mn10300_link_hash_entry *sym_hash;
2209 sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
2210 if ((sym_hash->root.root.type == bfd_link_hash_defined
2211 || sym_hash->root.root.type == bfd_link_hash_defweak)
2212 && sym_hash->root.root.u.def.section == section
2213 && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
2214 && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
2219 /* Note that we've changed things. */
2220 elf_section_data (section)->relocs = internal_relocs;
2221 elf_section_data (section)->this_hdr.contents = contents;
2222 symtab_hdr->contents = (unsigned char *) isymbuf;
2224 /* Count how many bytes we're going to delete. */
2225 if (sym_hash->movm_args)
2228 if (sym_hash->stack_size > 0)
2230 if (sym_hash->stack_size <= 128)
2236 /* Note that we've deleted prologue bytes for this
2238 sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
2240 /* Actually delete the bytes. */
2241 symval = sym_hash->root.root.u.def.value;
2242 if (!mn10300_elf_relax_delete_bytes (input_bfd,
2248 /* Something changed. Not strictly necessary, but
2249 may lead to more relaxing opportunities. */
2254 /* Cache or free any memory we allocated for the relocs. */
2255 if (internal_relocs != NULL
2256 && elf_section_data (section)->relocs != internal_relocs)
2257 free (internal_relocs);
2258 internal_relocs = NULL;
2260 /* Cache or free any memory we allocated for the contents. */
2261 if (contents != NULL
2262 && elf_section_data (section)->this_hdr.contents != contents)
2264 if (! link_info->keep_memory)
2268 /* Cache the section contents for elf_link_input_bfd. */
2269 elf_section_data (section)->this_hdr.contents = contents;
2275 /* Cache or free any memory we allocated for the symbols. */
2277 && symtab_hdr->contents != (unsigned char *) isymbuf)
2279 if (! link_info->keep_memory)
2283 /* Cache the symbols for elf_link_input_bfd. */
2284 symtab_hdr->contents = (unsigned char *) isymbuf;
2291 /* (Re)initialize for the basic instruction shortening/relaxing pass. */
2293 internal_relocs = NULL;
2295 /* For error_return. */
2298 /* We don't have to do anything for a relocatable link, if
2299 this section does not have relocs, or if this is not a
2301 if (link_info->relocatable
2302 || (sec->flags & SEC_RELOC) == 0
2303 || sec->reloc_count == 0
2304 || (sec->flags & SEC_CODE) == 0)
2307 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2309 /* Get a copy of the native relocations. */
2310 internal_relocs = (_bfd_elf_link_read_relocs
2311 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2312 link_info->keep_memory));
2313 if (internal_relocs == NULL)
2316 /* Walk through them looking for relaxing opportunities. */
2317 irelend = internal_relocs + sec->reloc_count;
2318 for (irel = internal_relocs; irel < irelend; irel++)
2321 struct elf32_mn10300_link_hash_entry *h = NULL;
2323 /* If this isn't something that can be relaxed, then ignore
2325 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE
2326 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8
2327 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX)
2330 /* Get the section contents if we haven't done so already. */
2331 if (contents == NULL)
2333 /* Get cached copy if it exists. */
2334 if (elf_section_data (sec)->this_hdr.contents != NULL)
2335 contents = elf_section_data (sec)->this_hdr.contents;
2338 /* Go get them off disk. */
2339 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2344 /* Read this BFD's symbols if we haven't done so already. */
2345 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2347 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2348 if (isymbuf == NULL)
2349 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2350 symtab_hdr->sh_info, 0,
2352 if (isymbuf == NULL)
2356 /* Get the value of the symbol referred to by the reloc. */
2357 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2359 Elf_Internal_Sym *isym;
2360 asection *sym_sec = NULL;
2361 const char *sym_name;
2363 bfd_vma saved_addend;
2365 /* A local symbol. */
2366 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2367 if (isym->st_shndx == SHN_UNDEF)
2368 sym_sec = bfd_und_section_ptr;
2369 else if (isym->st_shndx == SHN_ABS)
2370 sym_sec = bfd_abs_section_ptr;
2371 else if (isym->st_shndx == SHN_COMMON)
2372 sym_sec = bfd_com_section_ptr;
2374 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2376 sym_name = bfd_elf_string_from_elf_section (abfd,
2377 symtab_hdr->sh_link,
2380 if ((sym_sec->flags & SEC_MERGE)
2381 && ELF_ST_TYPE (isym->st_info) == STT_SECTION
2382 && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
2384 saved_addend = irel->r_addend;
2385 symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
2386 symval += irel->r_addend;
2387 irel->r_addend = saved_addend;
2391 symval = (isym->st_value
2392 + sym_sec->output_section->vma
2393 + sym_sec->output_offset);
2395 /* Tack on an ID so we can uniquely identify this
2396 local symbol in the global hash table. */
2397 new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
2400 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2401 sym_name = new_name;
2403 h = (struct elf32_mn10300_link_hash_entry *)
2404 elf_link_hash_lookup (&hash_table->static_hash_table->root,
2405 sym_name, FALSE, FALSE, FALSE);
2412 /* An external symbol. */
2413 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2414 h = (struct elf32_mn10300_link_hash_entry *)
2415 (elf_sym_hashes (abfd)[indx]);
2416 BFD_ASSERT (h != NULL);
2417 if (h->root.root.type != bfd_link_hash_defined
2418 && h->root.root.type != bfd_link_hash_defweak)
2420 /* This appears to be a reference to an undefined
2421 symbol. Just ignore it--it will be caught by the
2422 regular reloc processing. */
2426 symval = (h->root.root.u.def.value
2427 + h->root.root.u.def.section->output_section->vma
2428 + h->root.root.u.def.section->output_offset);
2431 /* For simplicity of coding, we are going to modify the section
2432 contents, the section relocs, and the BFD symbol table. We
2433 must tell the rest of the code not to free up this
2434 information. It would be possible to instead create a table
2435 of changes which have to be made, as is done in coff-mips.c;
2436 that would be more work, but would require less memory when
2437 the linker is run. */
2439 /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
2440 branch/call, also deal with "call" -> "calls" conversions and
2441 insertion of prologue data into "call" instructions. */
2442 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
2443 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
2445 bfd_vma value = symval;
2447 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
2449 && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
2450 && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
2451 && h->root.plt.offset != (bfd_vma) -1)
2455 splt = bfd_get_section_by_name (elf_hash_table (link_info)
2458 value = ((splt->output_section->vma
2459 + splt->output_offset
2460 + h->root.plt.offset)
2461 - (sec->output_section->vma
2462 + sec->output_offset
2466 /* If we've got a "call" instruction that needs to be turned
2467 into a "calls" instruction, do so now. It saves a byte. */
2468 if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
2472 /* Get the opcode. */
2473 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2475 /* Make sure we're working with a "call" instruction! */
2478 /* Note that we've changed the relocs, section contents,
2480 elf_section_data (sec)->relocs = internal_relocs;
2481 elf_section_data (sec)->this_hdr.contents = contents;
2482 symtab_hdr->contents = (unsigned char *) isymbuf;
2484 /* Fix the opcode. */
2485 bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
2486 bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
2488 /* Fix irel->r_offset and irel->r_addend. */
2489 irel->r_offset += 1;
2490 irel->r_addend += 1;
2492 /* Delete one byte of data. */
2493 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2494 irel->r_offset + 3, 1))
2497 /* That will change things, so, we should relax again.
2498 Note that this is not required, and it may be slow. */
2504 /* We've got a "call" instruction which needs some data
2505 from target function filled in. */
2508 /* Get the opcode. */
2509 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2511 /* Insert data from the target function into the "call"
2512 instruction if needed. */
2515 bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4);
2516 bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
2517 contents + irel->r_offset + 5);
2521 /* Deal with pc-relative gunk. */
2522 value -= (sec->output_section->vma + sec->output_offset);
2523 value -= irel->r_offset;
2524 value += irel->r_addend;
2526 /* See if the value will fit in 16 bits, note the high value is
2527 0x7fff + 2 as the target will be two bytes closer if we are
2529 if ((long) value < 0x8001 && (long) value > -0x8000)
2533 /* Get the opcode. */
2534 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2536 if (code != 0xdc && code != 0xdd && code != 0xff)
2539 /* Note that we've changed the relocs, section contents, etc. */
2540 elf_section_data (sec)->relocs = internal_relocs;
2541 elf_section_data (sec)->this_hdr.contents = contents;
2542 symtab_hdr->contents = (unsigned char *) isymbuf;
2544 /* Fix the opcode. */
2546 bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1);
2547 else if (code == 0xdd)
2548 bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1);
2549 else if (code == 0xff)
2550 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
2552 /* Fix the relocation's type. */
2553 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2554 (ELF32_R_TYPE (irel->r_info)
2555 == (int) R_MN10300_PLT32)
2559 /* Delete two bytes of data. */
2560 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2561 irel->r_offset + 1, 2))
2564 /* That will change things, so, we should relax again.
2565 Note that this is not required, and it may be slow. */
2570 /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
2572 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16)
2574 bfd_vma value = symval;
2576 /* If we've got a "call" instruction that needs to be turned
2577 into a "calls" instruction, do so now. It saves a byte. */
2578 if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
2582 /* Get the opcode. */
2583 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2585 /* Make sure we're working with a "call" instruction! */
2588 /* Note that we've changed the relocs, section contents,
2590 elf_section_data (sec)->relocs = internal_relocs;
2591 elf_section_data (sec)->this_hdr.contents = contents;
2592 symtab_hdr->contents = (unsigned char *) isymbuf;
2594 /* Fix the opcode. */
2595 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
2596 bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
2598 /* Fix irel->r_offset and irel->r_addend. */
2599 irel->r_offset += 1;
2600 irel->r_addend += 1;
2602 /* Delete one byte of data. */
2603 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2604 irel->r_offset + 1, 1))
2607 /* That will change things, so, we should relax again.
2608 Note that this is not required, and it may be slow. */
2616 /* Get the opcode. */
2617 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2619 /* Insert data from the target function into the "call"
2620 instruction if needed. */
2623 bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2);
2624 bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
2625 contents + irel->r_offset + 3);
2629 /* Deal with pc-relative gunk. */
2630 value -= (sec->output_section->vma + sec->output_offset);
2631 value -= irel->r_offset;
2632 value += irel->r_addend;
2634 /* See if the value will fit in 8 bits, note the high value is
2635 0x7f + 1 as the target will be one bytes closer if we are
2637 if ((long) value < 0x80 && (long) value > -0x80)
2641 /* Get the opcode. */
2642 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2647 /* Note that we've changed the relocs, section contents, etc. */
2648 elf_section_data (sec)->relocs = internal_relocs;
2649 elf_section_data (sec)->this_hdr.contents = contents;
2650 symtab_hdr->contents = (unsigned char *) isymbuf;
2652 /* Fix the opcode. */
2653 bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
2655 /* Fix the relocation's type. */
2656 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2659 /* Delete one byte of data. */
2660 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2661 irel->r_offset + 1, 1))
2664 /* That will change things, so, we should relax again.
2665 Note that this is not required, and it may be slow. */
2670 /* Try to eliminate an unconditional 8 bit pc-relative branch
2671 which immediately follows a conditional 8 bit pc-relative
2672 branch around the unconditional branch.
2679 This happens when the bCC can't reach lab2 at assembly time,
2680 but due to other relaxations it can reach at link time. */
2681 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8)
2683 Elf_Internal_Rela *nrel;
2684 bfd_vma value = symval;
2687 /* Deal with pc-relative gunk. */
2688 value -= (sec->output_section->vma + sec->output_offset);
2689 value -= irel->r_offset;
2690 value += irel->r_addend;
2692 /* Do nothing if this reloc is the last byte in the section. */
2693 if (irel->r_offset == sec->size)
2696 /* See if the next instruction is an unconditional pc-relative
2697 branch, more often than not this test will fail, so we
2698 test it first to speed things up. */
2699 code = bfd_get_8 (abfd, contents + irel->r_offset + 1);
2703 /* Also make sure the next relocation applies to the next
2704 instruction and that it's a pc-relative 8 bit branch. */
2707 || irel->r_offset + 2 != nrel->r_offset
2708 || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8)
2711 /* Make sure our destination immediately follows the
2712 unconditional branch. */
2713 if (symval != (sec->output_section->vma + sec->output_offset
2714 + irel->r_offset + 3))
2717 /* Now make sure we are a conditional branch. This may not
2718 be necessary, but why take the chance.
2720 Note these checks assume that R_MN10300_PCREL8 relocs
2721 only occur on bCC and bCCx insns. If they occured
2722 elsewhere, we'd need to know the start of this insn
2723 for this check to be accurate. */
2724 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2725 if (code != 0xc0 && code != 0xc1 && code != 0xc2
2726 && code != 0xc3 && code != 0xc4 && code != 0xc5
2727 && code != 0xc6 && code != 0xc7 && code != 0xc8
2728 && code != 0xc9 && code != 0xe8 && code != 0xe9
2729 && code != 0xea && code != 0xeb)
2732 /* We also have to be sure there is no symbol/label
2733 at the unconditional branch. */
2734 if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
2735 irel->r_offset + 1))
2738 /* Note that we've changed the relocs, section contents, etc. */
2739 elf_section_data (sec)->relocs = internal_relocs;
2740 elf_section_data (sec)->this_hdr.contents = contents;
2741 symtab_hdr->contents = (unsigned char *) isymbuf;
2743 /* Reverse the condition of the first branch. */
2789 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
2791 /* Set the reloc type and symbol for the first branch
2792 from the second branch. */
2793 irel->r_info = nrel->r_info;
2795 /* Make the reloc for the second branch a null reloc. */
2796 nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),
2799 /* Delete two bytes of data. */
2800 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2801 irel->r_offset + 1, 2))
2804 /* That will change things, so, we should relax again.
2805 Note that this is not required, and it may be slow. */
2809 /* Try to turn a 24 immediate, displacement or absolute address
2810 into a 8 immediate, displacement or absolute address. */
2811 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24)
2813 bfd_vma value = symval;
2814 value += irel->r_addend;
2816 /* See if the value will fit in 8 bits. */
2817 if ((long) value < 0x7f && (long) value > -0x80)
2821 /* AM33 insns which have 24 operands are 6 bytes long and
2822 will have 0xfd as the first byte. */
2824 /* Get the first opcode. */
2825 code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
2829 /* Get the second opcode. */
2830 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2832 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2833 equivalent instructions exists. */
2834 if (code != 0x6b && code != 0x7b
2835 && code != 0x8b && code != 0x9b
2836 && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2837 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2838 || (code & 0x0f) == 0x0e))
2840 /* Not safe if the high bit is on as relaxing may
2841 move the value out of high mem and thus not fit
2842 in a signed 8bit value. This is currently over
2844 if ((value & 0x80) == 0)
2846 /* Note that we've changed the relocation contents,
2848 elf_section_data (sec)->relocs = internal_relocs;
2849 elf_section_data (sec)->this_hdr.contents = contents;
2850 symtab_hdr->contents = (unsigned char *) isymbuf;
2852 /* Fix the opcode. */
2853 bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
2854 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
2856 /* Fix the relocation's type. */
2858 ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2861 /* Delete two bytes of data. */
2862 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2863 irel->r_offset + 1, 2))
2866 /* That will change things, so, we should relax
2867 again. Note that this is not required, and it
2877 /* Try to turn a 32bit immediate, displacement or absolute address
2878 into a 16bit immediate, displacement or absolute address. */
2879 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
2880 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
2881 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2883 bfd_vma value = symval;
2885 if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
2889 sgot = bfd_get_section_by_name (elf_hash_table (link_info)
2892 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
2894 value = sgot->output_offset;
2897 value += h->root.got.offset;
2899 value += (elf_local_got_offsets
2900 (abfd)[ELF32_R_SYM (irel->r_info)]);
2902 else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2903 value -= sgot->output_section->vma;
2904 else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
2905 value = (sgot->output_section->vma
2906 - (sec->output_section->vma
2907 + sec->output_offset
2913 value += irel->r_addend;
2915 /* See if the value will fit in 24 bits.
2916 We allow any 16bit match here. We prune those we can't
2918 if ((long) value < 0x7fffff && (long) value > -0x800000)
2922 /* AM33 insns which have 32bit operands are 7 bytes long and
2923 will have 0xfe as the first byte. */
2925 /* Get the first opcode. */
2926 code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
2930 /* Get the second opcode. */
2931 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2933 /* All the am33 32 -> 24 relaxing possibilities. */
2934 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2935 equivalent instructions exists. */
2936 if (code != 0x6b && code != 0x7b
2937 && code != 0x8b && code != 0x9b
2938 && (ELF32_R_TYPE (irel->r_info)
2939 != (int) R_MN10300_GOTPC32)
2940 && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2941 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2942 || (code & 0x0f) == 0x0e))
2944 /* Not safe if the high bit is on as relaxing may
2945 move the value out of high mem and thus not fit
2946 in a signed 16bit value. This is currently over
2948 if ((value & 0x8000) == 0)
2950 /* Note that we've changed the relocation contents,
2952 elf_section_data (sec)->relocs = internal_relocs;
2953 elf_section_data (sec)->this_hdr.contents = contents;
2954 symtab_hdr->contents = (unsigned char *) isymbuf;
2956 /* Fix the opcode. */
2957 bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
2958 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
2960 /* Fix the relocation's type. */
2962 ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2963 (ELF32_R_TYPE (irel->r_info)
2964 == (int) R_MN10300_GOTOFF32)
2965 ? R_MN10300_GOTOFF24
2966 : (ELF32_R_TYPE (irel->r_info)
2967 == (int) R_MN10300_GOT32)
2971 /* Delete one byte of data. */
2972 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2973 irel->r_offset + 3, 1))
2976 /* That will change things, so, we should relax
2977 again. Note that this is not required, and it
2986 /* See if the value will fit in 16 bits.
2987 We allow any 16bit match here. We prune those we can't
2989 if ((long) value < 0x7fff && (long) value > -0x8000)
2993 /* Most insns which have 32bit operands are 6 bytes long;
2994 exceptions are pcrel insns and bit insns.
2996 We handle pcrel insns above. We don't bother trying
2997 to handle the bit insns here.
2999 The first byte of the remaining insns will be 0xfc. */
3001 /* Get the first opcode. */
3002 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
3007 /* Get the second opcode. */
3008 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
3010 if ((code & 0xf0) < 0x80)
3011 switch (code & 0xf0)
3013 /* mov (d32,am),dn -> mov (d32,am),dn
3014 mov dm,(d32,am) -> mov dn,(d32,am)
3015 mov (d32,am),an -> mov (d32,am),an
3016 mov dm,(d32,am) -> mov dn,(d32,am)
3017 movbu (d32,am),dn -> movbu (d32,am),dn
3018 movbu dm,(d32,am) -> movbu dn,(d32,am)
3019 movhu (d32,am),dn -> movhu (d32,am),dn
3020 movhu dm,(d32,am) -> movhu dn,(d32,am) */
3029 /* Not safe if the high bit is on as relaxing may
3030 move the value out of high mem and thus not fit
3031 in a signed 16bit value. */
3033 && (value & 0x8000))
3036 /* Note that we've changed the relocation contents, etc. */
3037 elf_section_data (sec)->relocs = internal_relocs;
3038 elf_section_data (sec)->this_hdr.contents = contents;
3039 symtab_hdr->contents = (unsigned char *) isymbuf;
3041 /* Fix the opcode. */
3042 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3043 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3045 /* Fix the relocation's type. */
3046 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3047 (ELF32_R_TYPE (irel->r_info)
3048 == (int) R_MN10300_GOTOFF32)
3049 ? R_MN10300_GOTOFF16
3050 : (ELF32_R_TYPE (irel->r_info)
3051 == (int) R_MN10300_GOT32)
3053 : (ELF32_R_TYPE (irel->r_info)
3054 == (int) R_MN10300_GOTPC32)
3055 ? R_MN10300_GOTPC16 :
3058 /* Delete two bytes of data. */
3059 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3060 irel->r_offset + 2, 2))
3063 /* That will change things, so, we should relax again.
3064 Note that this is not required, and it may be slow. */
3068 else if ((code & 0xf0) == 0x80
3069 || (code & 0xf0) == 0x90)
3070 switch (code & 0xf3)
3072 /* mov dn,(abs32) -> mov dn,(abs16)
3073 movbu dn,(abs32) -> movbu dn,(abs16)
3074 movhu dn,(abs32) -> movhu dn,(abs16) */
3078 /* Note that we've changed the relocation contents, etc. */
3079 elf_section_data (sec)->relocs = internal_relocs;
3080 elf_section_data (sec)->this_hdr.contents = contents;
3081 symtab_hdr->contents = (unsigned char *) isymbuf;
3083 if ((code & 0xf3) == 0x81)
3084 code = 0x01 + (code & 0x0c);
3085 else if ((code & 0xf3) == 0x82)
3086 code = 0x02 + (code & 0x0c);
3087 else if ((code & 0xf3) == 0x83)
3088 code = 0x03 + (code & 0x0c);
3092 /* Fix the opcode. */
3093 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3095 /* Fix the relocation's type. */
3096 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3097 (ELF32_R_TYPE (irel->r_info)
3098 == (int) R_MN10300_GOTOFF32)
3099 ? R_MN10300_GOTOFF16
3100 : (ELF32_R_TYPE (irel->r_info)
3101 == (int) R_MN10300_GOT32)
3103 : (ELF32_R_TYPE (irel->r_info)
3104 == (int) R_MN10300_GOTPC32)
3105 ? R_MN10300_GOTPC16 :
3108 /* The opcode got shorter too, so we have to fix the
3109 addend and offset too! */
3110 irel->r_offset -= 1;
3112 /* Delete three bytes of data. */
3113 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3114 irel->r_offset + 1, 3))
3117 /* That will change things, so, we should relax again.
3118 Note that this is not required, and it may be slow. */
3122 /* mov am,(abs32) -> mov am,(abs16)
3123 mov am,(d32,sp) -> mov am,(d16,sp)
3124 mov dm,(d32,sp) -> mov dm,(d32,sp)
3125 movbu dm,(d32,sp) -> movbu dm,(d32,sp)
3126 movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
3132 /* sp-based offsets are zero-extended. */
3133 if (code >= 0x90 && code <= 0x93
3137 /* Note that we've changed the relocation contents, etc. */
3138 elf_section_data (sec)->relocs = internal_relocs;
3139 elf_section_data (sec)->this_hdr.contents = contents;
3140 symtab_hdr->contents = (unsigned char *) isymbuf;
3142 /* Fix the opcode. */
3143 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3144 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3146 /* Fix the relocation's type. */
3147 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3148 (ELF32_R_TYPE (irel->r_info)
3149 == (int) R_MN10300_GOTOFF32)
3150 ? R_MN10300_GOTOFF16
3151 : (ELF32_R_TYPE (irel->r_info)
3152 == (int) R_MN10300_GOT32)
3154 : (ELF32_R_TYPE (irel->r_info)
3155 == (int) R_MN10300_GOTPC32)
3156 ? R_MN10300_GOTPC16 :
3159 /* Delete two bytes of data. */
3160 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3161 irel->r_offset + 2, 2))
3164 /* That will change things, so, we should relax again.
3165 Note that this is not required, and it may be slow. */
3169 else if ((code & 0xf0) < 0xf0)
3170 switch (code & 0xfc)
3172 /* mov imm32,dn -> mov imm16,dn
3173 mov imm32,an -> mov imm16,an
3174 mov (abs32),dn -> mov (abs16),dn
3175 movbu (abs32),dn -> movbu (abs16),dn
3176 movhu (abs32),dn -> movhu (abs16),dn */
3182 /* Not safe if the high bit is on as relaxing may
3183 move the value out of high mem and thus not fit
3184 in a signed 16bit value. */
3186 && (value & 0x8000))
3189 /* mov imm16, an zero-extends the immediate. */
3194 /* Note that we've changed the relocation contents, etc. */
3195 elf_section_data (sec)->relocs = internal_relocs;
3196 elf_section_data (sec)->this_hdr.contents = contents;
3197 symtab_hdr->contents = (unsigned char *) isymbuf;
3199 if ((code & 0xfc) == 0xcc)
3200 code = 0x2c + (code & 0x03);
3201 else if ((code & 0xfc) == 0xdc)
3202 code = 0x24 + (code & 0x03);
3203 else if ((code & 0xfc) == 0xa4)
3204 code = 0x30 + (code & 0x03);
3205 else if ((code & 0xfc) == 0xa8)
3206 code = 0x34 + (code & 0x03);
3207 else if ((code & 0xfc) == 0xac)
3208 code = 0x38 + (code & 0x03);
3212 /* Fix the opcode. */
3213 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3215 /* Fix the relocation's type. */
3216 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3217 (ELF32_R_TYPE (irel->r_info)
3218 == (int) R_MN10300_GOTOFF32)
3219 ? R_MN10300_GOTOFF16
3220 : (ELF32_R_TYPE (irel->r_info)
3221 == (int) R_MN10300_GOT32)
3223 : (ELF32_R_TYPE (irel->r_info)
3224 == (int) R_MN10300_GOTPC32)
3225 ? R_MN10300_GOTPC16 :
3228 /* The opcode got shorter too, so we have to fix the
3229 addend and offset too! */
3230 irel->r_offset -= 1;
3232 /* Delete three bytes of data. */
3233 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3234 irel->r_offset + 1, 3))
3237 /* That will change things, so, we should relax again.
3238 Note that this is not required, and it may be slow. */
3242 /* mov (abs32),an -> mov (abs16),an
3243 mov (d32,sp),an -> mov (d16,sp),an
3244 mov (d32,sp),dn -> mov (d16,sp),dn
3245 movbu (d32,sp),dn -> movbu (d16,sp),dn
3246 movhu (d32,sp),dn -> movhu (d16,sp),dn
3247 add imm32,dn -> add imm16,dn
3248 cmp imm32,dn -> cmp imm16,dn
3249 add imm32,an -> add imm16,an
3250 cmp imm32,an -> cmp imm16,an
3251 and imm32,dn -> and imm16,dn
3252 or imm32,dn -> or imm16,dn
3253 xor imm32,dn -> xor imm16,dn
3254 btst imm32,dn -> btst imm16,dn */
3270 /* cmp imm16, an zero-extends the immediate. */
3275 /* So do sp-based offsets. */
3276 if (code >= 0xb0 && code <= 0xb3
3280 /* Note that we've changed the relocation contents, etc. */
3281 elf_section_data (sec)->relocs = internal_relocs;
3282 elf_section_data (sec)->this_hdr.contents = contents;
3283 symtab_hdr->contents = (unsigned char *) isymbuf;
3285 /* Fix the opcode. */
3286 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3287 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3289 /* Fix the relocation's type. */
3290 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3291 (ELF32_R_TYPE (irel->r_info)
3292 == (int) R_MN10300_GOTOFF32)
3293 ? R_MN10300_GOTOFF16
3294 : (ELF32_R_TYPE (irel->r_info)
3295 == (int) R_MN10300_GOT32)
3297 : (ELF32_R_TYPE (irel->r_info)
3298 == (int) R_MN10300_GOTPC32)
3299 ? R_MN10300_GOTPC16 :
3302 /* Delete two bytes of data. */
3303 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3304 irel->r_offset + 2, 2))
3307 /* That will change things, so, we should relax again.
3308 Note that this is not required, and it may be slow. */
3312 else if (code == 0xfe)
3314 /* add imm32,sp -> add imm16,sp */
3316 /* Note that we've changed the relocation contents, etc. */
3317 elf_section_data (sec)->relocs = internal_relocs;
3318 elf_section_data (sec)->this_hdr.contents = contents;
3319 symtab_hdr->contents = (unsigned char *) isymbuf;
3321 /* Fix the opcode. */
3322 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3323 bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1);
3325 /* Fix the relocation's type. */
3326 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3327 (ELF32_R_TYPE (irel->r_info)
3328 == (int) R_MN10300_GOT32)
3330 : (ELF32_R_TYPE (irel->r_info)
3331 == (int) R_MN10300_GOTOFF32)
3332 ? R_MN10300_GOTOFF16
3333 : (ELF32_R_TYPE (irel->r_info)
3334 == (int) R_MN10300_GOTPC32)
3335 ? R_MN10300_GOTPC16 :
3338 /* Delete two bytes of data. */
3339 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3340 irel->r_offset + 2, 2))
3343 /* That will change things, so, we should relax again.
3344 Note that this is not required, and it may be slow. */
3353 && symtab_hdr->contents != (unsigned char *) isymbuf)
3355 if (! link_info->keep_memory)
3359 /* Cache the symbols for elf_link_input_bfd. */
3360 symtab_hdr->contents = (unsigned char *) isymbuf;
3364 if (contents != NULL
3365 && elf_section_data (sec)->this_hdr.contents != contents)
3367 if (! link_info->keep_memory)
3371 /* Cache the section contents for elf_link_input_bfd. */
3372 elf_section_data (sec)->this_hdr.contents = contents;
3376 if (internal_relocs != NULL
3377 && elf_section_data (sec)->relocs != internal_relocs)
3378 free (internal_relocs);
3384 && symtab_hdr->contents != (unsigned char *) isymbuf)
3386 if (contents != NULL
3387 && elf_section_data (section)->this_hdr.contents != contents)
3389 if (internal_relocs != NULL
3390 && elf_section_data (section)->relocs != internal_relocs)
3391 free (internal_relocs);
3396 /* Compute the stack size and movm arguments for the function
3397 referred to by HASH at address ADDR in section with
3398 contents CONTENTS, store the information in the hash table. */
3400 compute_function_info (abfd, hash, addr, contents)
3402 struct elf32_mn10300_link_hash_entry *hash;
3404 unsigned char *contents;
3406 unsigned char byte1, byte2;
3407 /* We only care about a very small subset of the possible prologue
3408 sequences here. Basically we look for:
3410 movm [d2,d3,a2,a3],sp (optional)
3411 add <size>,sp (optional, and only for sizes which fit in an unsigned
3414 If we find anything else, we quit. */
3416 /* Look for movm [regs],sp */
3417 byte1 = bfd_get_8 (abfd, contents + addr);
3418 byte2 = bfd_get_8 (abfd, contents + addr + 1);
3422 hash->movm_args = byte2;
3424 byte1 = bfd_get_8 (abfd, contents + addr);
3425 byte2 = bfd_get_8 (abfd, contents + addr + 1);
3428 /* Now figure out how much stack space will be allocated by the movm
3429 instruction. We need this kept separate from the function's normal
3431 if (hash->movm_args)
3434 if (hash->movm_args & 0x80)
3435 hash->movm_stack_size += 4;
3438 if (hash->movm_args & 0x40)
3439 hash->movm_stack_size += 4;
3442 if (hash->movm_args & 0x20)
3443 hash->movm_stack_size += 4;
3446 if (hash->movm_args & 0x10)
3447 hash->movm_stack_size += 4;
3449 /* "other" space. d0, d1, a0, a1, mdr, lir, lar, 4 byte pad. */
3450 if (hash->movm_args & 0x08)
3451 hash->movm_stack_size += 8 * 4;
3453 if (bfd_get_mach (abfd) == bfd_mach_am33
3454 || bfd_get_mach (abfd) == bfd_mach_am33_2)
3456 /* "exother" space. e0, e1, mdrq, mcrh, mcrl, mcvf */
3457 if (hash->movm_args & 0x1)
3458 hash->movm_stack_size += 6 * 4;
3460 /* exreg1 space. e4, e5, e6, e7 */
3461 if (hash->movm_args & 0x2)
3462 hash->movm_stack_size += 4 * 4;
3464 /* exreg0 space. e2, e3 */
3465 if (hash->movm_args & 0x4)
3466 hash->movm_stack_size += 2 * 4;
3470 /* Now look for the two stack adjustment variants. */
3471 if (byte1 == 0xf8 && byte2 == 0xfe)
3473 int temp = bfd_get_8 (abfd, contents + addr + 2);
3474 temp = ((temp & 0xff) ^ (~0x7f)) + 0x80;
3476 hash->stack_size = -temp;
3478 else if (byte1 == 0xfa && byte2 == 0xfe)
3480 int temp = bfd_get_16 (abfd, contents + addr + 2);
3481 temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000;
3485 hash->stack_size = temp;
3488 /* If the total stack to be allocated by the call instruction is more
3489 than 255 bytes, then we can't remove the stack adjustment by using
3490 "call" (we might still be able to remove the "movm" instruction. */
3491 if (hash->stack_size + hash->movm_stack_size > 255)
3492 hash->stack_size = 0;
3497 /* Delete some bytes from a section while relaxing. */
3500 mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
3506 Elf_Internal_Shdr *symtab_hdr;
3507 unsigned int sec_shndx;
3509 Elf_Internal_Rela *irel, *irelend;
3510 Elf_Internal_Rela *irelalign;
3512 Elf_Internal_Sym *isym, *isymend;
3513 struct elf_link_hash_entry **sym_hashes;
3514 struct elf_link_hash_entry **end_hashes;
3515 unsigned int symcount;
3517 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
3519 contents = elf_section_data (sec)->this_hdr.contents;
3521 /* The deletion must stop at the next ALIGN reloc for an aligment
3522 power larger than the number of bytes we are deleting. */
3527 irel = elf_section_data (sec)->relocs;
3528 irelend = irel + sec->reloc_count;
3530 /* Actually delete the bytes. */
3531 memmove (contents + addr, contents + addr + count,
3532 (size_t) (toaddr - addr - count));
3535 /* Adjust all the relocs. */
3536 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
3538 /* Get the new reloc address. */
3539 if ((irel->r_offset > addr
3540 && irel->r_offset < toaddr))
3541 irel->r_offset -= count;
3544 /* Adjust the local symbols defined in this section. */
3545 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3546 isym = (Elf_Internal_Sym *) symtab_hdr->contents;
3547 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
3549 if (isym->st_shndx == sec_shndx
3550 && isym->st_value > addr
3551 && isym->st_value < toaddr)
3552 isym->st_value -= count;
3555 /* Now adjust the global symbols defined in this section. */
3556 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3557 - symtab_hdr->sh_info);
3558 sym_hashes = elf_sym_hashes (abfd);
3559 end_hashes = sym_hashes + symcount;
3560 for (; sym_hashes < end_hashes; sym_hashes++)
3562 struct elf_link_hash_entry *sym_hash = *sym_hashes;
3563 if ((sym_hash->root.type == bfd_link_hash_defined
3564 || sym_hash->root.type == bfd_link_hash_defweak)
3565 && sym_hash->root.u.def.section == sec
3566 && sym_hash->root.u.def.value > addr
3567 && sym_hash->root.u.def.value < toaddr)
3569 sym_hash->root.u.def.value -= count;
3576 /* Return TRUE if a symbol exists at the given address, else return
3579 mn10300_elf_symbol_address_p (abfd, sec, isym, addr)
3582 Elf_Internal_Sym *isym;
3585 Elf_Internal_Shdr *symtab_hdr;
3586 unsigned int sec_shndx;
3587 Elf_Internal_Sym *isymend;
3588 struct elf_link_hash_entry **sym_hashes;
3589 struct elf_link_hash_entry **end_hashes;
3590 unsigned int symcount;
3592 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
3594 /* Examine all the symbols. */
3595 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3596 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
3598 if (isym->st_shndx == sec_shndx
3599 && isym->st_value == addr)
3603 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3604 - symtab_hdr->sh_info);
3605 sym_hashes = elf_sym_hashes (abfd);
3606 end_hashes = sym_hashes + symcount;
3607 for (; sym_hashes < end_hashes; sym_hashes++)
3609 struct elf_link_hash_entry *sym_hash = *sym_hashes;
3610 if ((sym_hash->root.type == bfd_link_hash_defined
3611 || sym_hash->root.type == bfd_link_hash_defweak)
3612 && sym_hash->root.u.def.section == sec
3613 && sym_hash->root.u.def.value == addr)
3620 /* This is a version of bfd_generic_get_relocated_section_contents
3621 which uses mn10300_elf_relocate_section. */
3624 mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
3625 data, relocatable, symbols)
3627 struct bfd_link_info *link_info;
3628 struct bfd_link_order *link_order;
3630 bfd_boolean relocatable;
3633 Elf_Internal_Shdr *symtab_hdr;
3634 asection *input_section = link_order->u.indirect.section;
3635 bfd *input_bfd = input_section->owner;
3636 asection **sections = NULL;
3637 Elf_Internal_Rela *internal_relocs = NULL;
3638 Elf_Internal_Sym *isymbuf = NULL;
3640 /* We only need to handle the case of relaxing, or of having a
3641 particular set of section contents, specially. */
3643 || elf_section_data (input_section)->this_hdr.contents == NULL)
3644 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
3649 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3651 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
3652 (size_t) input_section->size);
3654 if ((input_section->flags & SEC_RELOC) != 0
3655 && input_section->reloc_count > 0)
3658 Elf_Internal_Sym *isym, *isymend;
3661 internal_relocs = (_bfd_elf_link_read_relocs
3662 (input_bfd, input_section, (PTR) NULL,
3663 (Elf_Internal_Rela *) NULL, FALSE));
3664 if (internal_relocs == NULL)
3667 if (symtab_hdr->sh_info != 0)
3669 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
3670 if (isymbuf == NULL)
3671 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3672 symtab_hdr->sh_info, 0,
3674 if (isymbuf == NULL)
3678 amt = symtab_hdr->sh_info;
3679 amt *= sizeof (asection *);
3680 sections = (asection **) bfd_malloc (amt);
3681 if (sections == NULL && amt != 0)
3684 isymend = isymbuf + symtab_hdr->sh_info;
3685 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
3689 if (isym->st_shndx == SHN_UNDEF)
3690 isec = bfd_und_section_ptr;
3691 else if (isym->st_shndx == SHN_ABS)
3692 isec = bfd_abs_section_ptr;
3693 else if (isym->st_shndx == SHN_COMMON)
3694 isec = bfd_com_section_ptr;
3696 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
3701 if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
3702 input_section, data, internal_relocs,
3706 if (sections != NULL)
3708 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3710 if (internal_relocs != elf_section_data (input_section)->relocs)
3711 free (internal_relocs);
3717 if (sections != NULL)
3719 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3721 if (internal_relocs != NULL
3722 && internal_relocs != elf_section_data (input_section)->relocs)
3723 free (internal_relocs);
3727 /* Assorted hash table functions. */
3729 /* Initialize an entry in the link hash table. */
3731 /* Create an entry in an MN10300 ELF linker hash table. */
3733 static struct bfd_hash_entry *
3734 elf32_mn10300_link_hash_newfunc (entry, table, string)
3735 struct bfd_hash_entry *entry;
3736 struct bfd_hash_table *table;
3739 struct elf32_mn10300_link_hash_entry *ret =
3740 (struct elf32_mn10300_link_hash_entry *) entry;
3742 /* Allocate the structure if it has not already been allocated by a
3744 if (ret == (struct elf32_mn10300_link_hash_entry *) NULL)
3745 ret = ((struct elf32_mn10300_link_hash_entry *)
3746 bfd_hash_allocate (table,
3747 sizeof (struct elf32_mn10300_link_hash_entry)));
3748 if (ret == (struct elf32_mn10300_link_hash_entry *) NULL)
3749 return (struct bfd_hash_entry *) ret;
3751 /* Call the allocation method of the superclass. */
3752 ret = ((struct elf32_mn10300_link_hash_entry *)
3753 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3755 if (ret != (struct elf32_mn10300_link_hash_entry *) NULL)
3757 ret->direct_calls = 0;
3758 ret->stack_size = 0;
3760 ret->movm_stack_size = 0;
3765 return (struct bfd_hash_entry *) ret;
3768 /* Create an mn10300 ELF linker hash table. */
3770 static struct bfd_link_hash_table *
3771 elf32_mn10300_link_hash_table_create (abfd)
3774 struct elf32_mn10300_link_hash_table *ret;
3775 bfd_size_type amt = sizeof (struct elf32_mn10300_link_hash_table);
3777 ret = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
3778 if (ret == (struct elf32_mn10300_link_hash_table *) NULL)
3781 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
3782 elf32_mn10300_link_hash_newfunc,
3783 sizeof (struct elf32_mn10300_link_hash_entry)))
3790 amt = sizeof (struct elf_link_hash_table);
3791 ret->static_hash_table
3792 = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
3793 if (ret->static_hash_table == NULL)
3799 if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd,
3800 elf32_mn10300_link_hash_newfunc,
3801 sizeof (struct elf32_mn10300_link_hash_entry)))
3803 free (ret->static_hash_table);
3807 return &ret->root.root;
3810 /* Free an mn10300 ELF linker hash table. */
3813 elf32_mn10300_link_hash_table_free (hash)
3814 struct bfd_link_hash_table *hash;
3816 struct elf32_mn10300_link_hash_table *ret
3817 = (struct elf32_mn10300_link_hash_table *) hash;
3819 _bfd_generic_link_hash_table_free
3820 ((struct bfd_link_hash_table *) ret->static_hash_table);
3821 _bfd_generic_link_hash_table_free
3822 ((struct bfd_link_hash_table *) ret);
3825 static unsigned long
3826 elf_mn10300_mach (flags)
3829 switch (flags & EF_MN10300_MACH)
3831 case E_MN10300_MACH_MN10300:
3833 return bfd_mach_mn10300;
3835 case E_MN10300_MACH_AM33:
3836 return bfd_mach_am33;
3838 case E_MN10300_MACH_AM33_2:
3839 return bfd_mach_am33_2;
3843 /* The final processing done just before writing out a MN10300 ELF object
3844 file. This gets the MN10300 architecture right based on the machine
3848 _bfd_mn10300_elf_final_write_processing (abfd, linker)
3850 bfd_boolean linker ATTRIBUTE_UNUSED;
3854 switch (bfd_get_mach (abfd))
3857 case bfd_mach_mn10300:
3858 val = E_MN10300_MACH_MN10300;
3862 val = E_MN10300_MACH_AM33;
3865 case bfd_mach_am33_2:
3866 val = E_MN10300_MACH_AM33_2;
3870 elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
3871 elf_elfheader (abfd)->e_flags |= val;
3875 _bfd_mn10300_elf_object_p (abfd)
3878 bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
3879 elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
3883 /* Merge backend specific data from an object file to the output
3884 object file when linking. */
3887 _bfd_mn10300_elf_merge_private_bfd_data (ibfd, obfd)
3891 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3892 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3895 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3896 && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
3898 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3899 bfd_get_mach (ibfd)))
3906 #define PLT0_ENTRY_SIZE 15
3907 #define PLT_ENTRY_SIZE 20
3908 #define PIC_PLT_ENTRY_SIZE 24
3910 static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
3912 0xfc, 0xa0, 0, 0, 0, 0, /* mov (.got+8),a0 */
3913 0xfe, 0xe, 0x10, 0, 0, 0, 0, /* mov (.got+4),r1 */
3914 0xf0, 0xf4, /* jmp (a0) */
3917 static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
3919 0xfc, 0xa0, 0, 0, 0, 0, /* mov (nameN@GOT + .got),a0 */
3920 0xf0, 0xf4, /* jmp (a0) */
3921 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3922 0xdc, 0, 0, 0, 0, /* jmp .plt0 */
3925 static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
3927 0xfc, 0x22, 0, 0, 0, 0, /* mov (nameN@GOT,a2),a0 */
3928 0xf0, 0xf4, /* jmp (a0) */
3929 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3930 0xf8, 0x22, 8, /* mov (8,a2),a0 */
3931 0xfb, 0xa, 0x1a, 4, /* mov (4,a2),r1 */
3932 0xf0, 0xf4, /* jmp (a0) */
3935 /* Return size of the first PLT entry. */
3936 #define elf_mn10300_sizeof_plt0(info) \
3937 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
3939 /* Return size of a PLT entry. */
3940 #define elf_mn10300_sizeof_plt(info) \
3941 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
3943 /* Return offset of the PLT0 address in an absolute PLT entry. */
3944 #define elf_mn10300_plt_plt0_offset(info) 16
3946 /* Return offset of the linker in PLT0 entry. */
3947 #define elf_mn10300_plt0_linker_offset(info) 2
3949 /* Return offset of the GOT id in PLT0 entry. */
3950 #define elf_mn10300_plt0_gotid_offset(info) 9
3952 /* Return offset of the temporary in PLT entry */
3953 #define elf_mn10300_plt_temp_offset(info) 8
3955 /* Return offset of the symbol in PLT entry. */
3956 #define elf_mn10300_plt_symbol_offset(info) 2
3958 /* Return offset of the relocation in PLT entry. */
3959 #define elf_mn10300_plt_reloc_offset(info) 11
3961 /* The name of the dynamic interpreter. This is put in the .interp
3964 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
3966 /* Create dynamic sections when linking against a dynamic object. */
3969 _bfd_mn10300_elf_create_dynamic_sections (abfd, info)
3971 struct bfd_link_info *info;
3975 const struct elf_backend_data * bed = get_elf_backend_data (abfd);
3978 switch (bed->s->arch_size)
3989 bfd_set_error (bfd_error_bad_value);
3993 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3994 .rel[a].bss sections. */
3996 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3997 | SEC_LINKER_CREATED);
3999 s = bfd_make_section_with_flags (abfd,
4000 (bed->default_use_rela_p
4001 ? ".rela.plt" : ".rel.plt"),
4002 flags | SEC_READONLY);
4004 || ! bfd_set_section_alignment (abfd, s, ptralign))
4007 if (! _bfd_mn10300_elf_create_got_section (abfd, info))
4011 const char * secname;
4016 for (sec = abfd->sections; sec; sec = sec->next)
4018 secflags = bfd_get_section_flags (abfd, sec);
4019 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
4020 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
4023 secname = bfd_get_section_name (abfd, sec);
4024 relname = (char *) bfd_malloc (strlen (secname) + 6);
4025 strcpy (relname, ".rela");
4026 strcat (relname, secname);
4028 s = bfd_make_section_with_flags (abfd, relname,
4029 flags | SEC_READONLY);
4031 || ! bfd_set_section_alignment (abfd, s, ptralign))
4036 if (bed->want_dynbss)
4038 /* The .dynbss section is a place to put symbols which are defined
4039 by dynamic objects, are referenced by regular objects, and are
4040 not functions. We must allocate space for them in the process
4041 image and use a R_*_COPY reloc to tell the dynamic linker to
4042 initialize them at run time. The linker script puts the .dynbss
4043 section into the .bss section of the final image. */
4044 s = bfd_make_section_with_flags (abfd, ".dynbss",
4045 SEC_ALLOC | SEC_LINKER_CREATED);
4049 /* The .rel[a].bss section holds copy relocs. This section is not
4050 normally needed. We need to create it here, though, so that the
4051 linker will map it to an output section. We can't just create it
4052 only if we need it, because we will not know whether we need it
4053 until we have seen all the input files, and the first time the
4054 main linker code calls BFD after examining all the input files
4055 (size_dynamic_sections) the input sections have already been
4056 mapped to the output sections. If the section turns out not to
4057 be needed, we can discard it later. We will never need this
4058 section when generating a shared object, since they do not use
4062 s = bfd_make_section_with_flags (abfd,
4063 (bed->default_use_rela_p
4064 ? ".rela.bss" : ".rel.bss"),
4065 flags | SEC_READONLY);
4067 || ! bfd_set_section_alignment (abfd, s, ptralign))
4075 /* Adjust a symbol defined by a dynamic object and referenced by a
4076 regular object. The current definition is in some section of the
4077 dynamic object, but we're not including those sections. We have to
4078 change the definition to something the rest of the link can
4082 _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
4083 struct bfd_link_info * info;
4084 struct elf_link_hash_entry * h;
4088 unsigned int power_of_two;
4090 dynobj = elf_hash_table (info)->dynobj;
4092 /* Make sure we know what is going on here. */
4093 BFD_ASSERT (dynobj != NULL
4095 || h->u.weakdef != NULL
4098 && !h->def_regular)));
4100 /* If this is a function, put it in the procedure linkage table. We
4101 will fill in the contents of the procedure linkage table later,
4102 when we know the address of the .got section. */
4103 if (h->type == STT_FUNC
4110 /* This case can occur if we saw a PLT reloc in an input
4111 file, but the symbol was never referred to by a dynamic
4112 object. In such a case, we don't actually need to build
4113 a procedure linkage table, and we can just do a REL32
4115 BFD_ASSERT (h->needs_plt);
4119 /* Make sure this symbol is output as a dynamic symbol. */
4120 if (h->dynindx == -1)
4122 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4126 s = bfd_get_section_by_name (dynobj, ".plt");
4127 BFD_ASSERT (s != NULL);
4129 /* If this is the first .plt entry, make room for the special
4132 s->size += elf_mn10300_sizeof_plt0 (info);
4134 /* If this symbol is not defined in a regular file, and we are
4135 not generating a shared library, then set the symbol to this
4136 location in the .plt. This is required to make function
4137 pointers compare as equal between the normal executable and
4138 the shared library. */
4142 h->root.u.def.section = s;
4143 h->root.u.def.value = s->size;
4146 h->plt.offset = s->size;
4148 /* Make room for this entry. */
4149 s->size += elf_mn10300_sizeof_plt (info);
4151 /* We also need to make an entry in the .got.plt section, which
4152 will be placed in the .got section by the linker script. */
4154 s = bfd_get_section_by_name (dynobj, ".got.plt");
4155 BFD_ASSERT (s != NULL);
4158 /* We also need to make an entry in the .rela.plt section. */
4160 s = bfd_get_section_by_name (dynobj, ".rela.plt");
4161 BFD_ASSERT (s != NULL);
4162 s->size += sizeof (Elf32_External_Rela);
4167 /* If this is a weak symbol, and there is a real definition, the
4168 processor independent code will have arranged for us to see the
4169 real definition first, and we can just use the same value. */
4170 if (h->u.weakdef != NULL)
4172 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4173 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4174 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4175 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4179 /* This is a reference to a symbol defined by a dynamic object which
4180 is not a function. */
4182 /* If we are creating a shared library, we must presume that the
4183 only references to the symbol are via the global offset table.
4184 For such cases we need not do anything here; the relocations will
4185 be handled correctly by relocate_section. */
4189 /* If there are no references to this symbol that do not use the
4190 GOT, we don't need to generate a copy reloc. */
4191 if (!h->non_got_ref)
4196 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
4197 h->root.root.string);
4201 /* We must allocate the symbol in our .dynbss section, which will
4202 become part of the .bss section of the executable. There will be
4203 an entry for this symbol in the .dynsym section. The dynamic
4204 object will contain position independent code, so all references
4205 from the dynamic object to this symbol will go through the global
4206 offset table. The dynamic linker will use the .dynsym entry to
4207 determine the address it must put in the global offset table, so
4208 both the dynamic object and the regular object will refer to the
4209 same memory location for the variable. */
4211 s = bfd_get_section_by_name (dynobj, ".dynbss");
4212 BFD_ASSERT (s != NULL);
4214 /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
4215 copy the initial value out of the dynamic object and into the
4216 runtime process image. We need to remember the offset into the
4217 .rela.bss section we are going to use. */
4218 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4222 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
4223 BFD_ASSERT (srel != NULL);
4224 srel->size += sizeof (Elf32_External_Rela);
4228 /* We need to figure out the alignment required for this symbol. I
4229 have no idea how ELF linkers handle this. */
4230 power_of_two = bfd_log2 (h->size);
4231 if (power_of_two > 3)
4234 /* Apply the required alignment. */
4235 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4236 if (power_of_two > bfd_get_section_alignment (dynobj, s))
4238 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
4242 /* Define the symbol as being at this point in the section. */
4243 h->root.u.def.section = s;
4244 h->root.u.def.value = s->size;
4246 /* Increment the section size to make room for the symbol. */
4252 /* Set the sizes of the dynamic sections. */
4255 _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
4257 struct bfd_link_info * info;
4263 bfd_boolean reltext;
4265 dynobj = elf_hash_table (info)->dynobj;
4266 BFD_ASSERT (dynobj != NULL);
4268 if (elf_hash_table (info)->dynamic_sections_created)
4270 /* Set the contents of the .interp section to the interpreter. */
4271 if (info->executable)
4273 s = bfd_get_section_by_name (dynobj, ".interp");
4274 BFD_ASSERT (s != NULL);
4275 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4276 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4281 /* We may have created entries in the .rela.got section.
4282 However, if we are not creating the dynamic sections, we will
4283 not actually use these entries. Reset the size of .rela.got,
4284 which will cause it to get stripped from the output file
4286 s = bfd_get_section_by_name (dynobj, ".rela.got");
4291 /* The check_relocs and adjust_dynamic_symbol entry points have
4292 determined the sizes of the various dynamic sections. Allocate
4297 for (s = dynobj->sections; s != NULL; s = s->next)
4301 if ((s->flags & SEC_LINKER_CREATED) == 0)
4304 /* It's OK to base decisions on the section name, because none
4305 of the dynobj section names depend upon the input files. */
4306 name = bfd_get_section_name (dynobj, s);
4308 if (strcmp (name, ".plt") == 0)
4310 /* Remember whether there is a PLT. */
4313 else if (strncmp (name, ".rela", 5) == 0)
4319 /* Remember whether there are any reloc sections other
4321 if (strcmp (name, ".rela.plt") != 0)
4323 const char * outname;
4327 /* If this relocation section applies to a read only
4328 section, then we probably need a DT_TEXTREL
4329 entry. The entries in the .rela.plt section
4330 really apply to the .got section, which we
4331 created ourselves and so know is not readonly. */
4332 outname = bfd_get_section_name (output_bfd,
4334 target = bfd_get_section_by_name (output_bfd, outname + 5);
4336 && (target->flags & SEC_READONLY) != 0
4337 && (target->flags & SEC_ALLOC) != 0)
4341 /* We use the reloc_count field as a counter if we need
4342 to copy relocs into the output file. */
4346 else if (strncmp (name, ".got", 4) != 0
4347 && strcmp (name, ".dynbss") != 0)
4348 /* It's not one of our sections, so don't allocate space. */
4353 /* If we don't need this section, strip it from the
4354 output file. This is mostly to handle .rela.bss and
4355 .rela.plt. We must create both sections in
4356 create_dynamic_sections, because they must be created
4357 before the linker maps input sections to output
4358 sections. The linker does that before
4359 adjust_dynamic_symbol is called, and it is that
4360 function which decides whether anything needs to go
4361 into these sections. */
4362 s->flags |= SEC_EXCLUDE;
4366 if ((s->flags & SEC_HAS_CONTENTS) == 0)
4369 /* Allocate memory for the section contents. We use bfd_zalloc
4370 here in case unused entries are not reclaimed before the
4371 section's contents are written out. This should not happen,
4372 but this way if it does, we get a R_MN10300_NONE reloc
4373 instead of garbage. */
4374 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4375 if (s->contents == NULL)
4379 if (elf_hash_table (info)->dynamic_sections_created)
4381 /* Add some entries to the .dynamic section. We fill in the
4382 values later, in _bfd_mn10300_elf_finish_dynamic_sections,
4383 but we must add the entries now so that we get the correct
4384 size for the .dynamic section. The DT_DEBUG entry is filled
4385 in by the dynamic linker and used by the debugger. */
4388 if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
4394 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
4395 || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
4396 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
4397 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
4403 if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
4404 || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
4405 || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
4406 sizeof (Elf32_External_Rela)))
4412 if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
4420 /* Finish up dynamic symbol handling. We set the contents of various
4421 dynamic sections here. */
4424 _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
4426 struct bfd_link_info * info;
4427 struct elf_link_hash_entry * h;
4428 Elf_Internal_Sym * sym;
4432 dynobj = elf_hash_table (info)->dynobj;
4434 if (h->plt.offset != (bfd_vma) -1)
4441 Elf_Internal_Rela rel;
4443 /* This symbol has an entry in the procedure linkage table. Set
4446 BFD_ASSERT (h->dynindx != -1);
4448 splt = bfd_get_section_by_name (dynobj, ".plt");
4449 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4450 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4451 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
4453 /* Get the index in the procedure linkage table which
4454 corresponds to this symbol. This is the index of this symbol
4455 in all the symbols for which we are making plt entries. The
4456 first entry in the procedure linkage table is reserved. */
4457 plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
4458 / elf_mn10300_sizeof_plt (info));
4460 /* Get the offset into the .got table of the entry that
4461 corresponds to this function. Each .got entry is 4 bytes.
4462 The first three are reserved. */
4463 got_offset = (plt_index + 3) * 4;
4465 /* Fill in the entry in the procedure linkage table. */
4468 memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
4469 elf_mn10300_sizeof_plt (info));
4470 bfd_put_32 (output_bfd,
4471 (sgot->output_section->vma
4472 + sgot->output_offset
4474 (splt->contents + h->plt.offset
4475 + elf_mn10300_plt_symbol_offset (info)));
4477 bfd_put_32 (output_bfd,
4478 (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
4479 (splt->contents + h->plt.offset
4480 + elf_mn10300_plt_plt0_offset (info)));
4484 memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
4485 elf_mn10300_sizeof_plt (info));
4487 bfd_put_32 (output_bfd, got_offset,
4488 (splt->contents + h->plt.offset
4489 + elf_mn10300_plt_symbol_offset (info)));
4492 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4493 (splt->contents + h->plt.offset
4494 + elf_mn10300_plt_reloc_offset (info)));
4496 /* Fill in the entry in the global offset table. */
4497 bfd_put_32 (output_bfd,
4498 (splt->output_section->vma
4499 + splt->output_offset
4501 + elf_mn10300_plt_temp_offset (info)),
4502 sgot->contents + got_offset);
4504 /* Fill in the entry in the .rela.plt section. */
4505 rel.r_offset = (sgot->output_section->vma
4506 + sgot->output_offset
4508 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
4510 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4511 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4514 if (!h->def_regular)
4515 /* Mark the symbol as undefined, rather than as defined in
4516 the .plt section. Leave the value alone. */
4517 sym->st_shndx = SHN_UNDEF;
4520 if (h->got.offset != (bfd_vma) -1)
4524 Elf_Internal_Rela rel;
4526 /* This symbol has an entry in the global offset table. Set it up. */
4528 sgot = bfd_get_section_by_name (dynobj, ".got");
4529 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4530 BFD_ASSERT (sgot != NULL && srel != NULL);
4532 rel.r_offset = (sgot->output_section->vma
4533 + sgot->output_offset
4534 + (h->got.offset &~ 1));
4536 /* If this is a -Bsymbolic link, and the symbol is defined
4537 locally, we just want to emit a RELATIVE reloc. Likewise if
4538 the symbol was forced to be local because of a version file.
4539 The entry in the global offset table will already have been
4540 initialized in the relocate_section function. */
4542 && (info->symbolic || h->dynindx == -1)
4545 rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
4546 rel.r_addend = (h->root.u.def.value
4547 + h->root.u.def.section->output_section->vma
4548 + h->root.u.def.section->output_offset);
4552 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
4553 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
4557 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4558 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4559 + srel->reloc_count));
4560 ++ srel->reloc_count;
4566 Elf_Internal_Rela rel;
4568 /* This symbol needs a copy reloc. Set it up. */
4569 BFD_ASSERT (h->dynindx != -1
4570 && (h->root.type == bfd_link_hash_defined
4571 || h->root.type == bfd_link_hash_defweak));
4573 s = bfd_get_section_by_name (h->root.u.def.section->owner,
4575 BFD_ASSERT (s != NULL);
4577 rel.r_offset = (h->root.u.def.value
4578 + h->root.u.def.section->output_section->vma
4579 + h->root.u.def.section->output_offset);
4580 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
4582 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4583 (bfd_byte *) ((Elf32_External_Rela *) s->contents
4588 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4589 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4590 || h == elf_hash_table (info)->hgot)
4591 sym->st_shndx = SHN_ABS;
4596 /* Finish up the dynamic sections. */
4599 _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
4601 struct bfd_link_info * info;
4607 dynobj = elf_hash_table (info)->dynobj;
4609 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4610 BFD_ASSERT (sgot != NULL);
4611 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4613 if (elf_hash_table (info)->dynamic_sections_created)
4616 Elf32_External_Dyn * dyncon;
4617 Elf32_External_Dyn * dynconend;
4619 BFD_ASSERT (sdyn != NULL);
4621 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4622 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4624 for (; dyncon < dynconend; dyncon++)
4626 Elf_Internal_Dyn dyn;
4630 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4644 s = bfd_get_section_by_name (output_bfd, name);
4645 BFD_ASSERT (s != NULL);
4646 dyn.d_un.d_ptr = s->vma;
4647 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4651 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4652 BFD_ASSERT (s != NULL);
4653 dyn.d_un.d_val = s->size;
4654 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4658 /* My reading of the SVR4 ABI indicates that the
4659 procedure linkage table relocs (DT_JMPREL) should be
4660 included in the overall relocs (DT_RELA). This is
4661 what Solaris does. However, UnixWare can not handle
4662 that case. Therefore, we override the DT_RELASZ entry
4663 here to make it not include the JMPREL relocs. Since
4664 the linker script arranges for .rela.plt to follow all
4665 other relocation sections, we don't have to worry
4666 about changing the DT_RELA entry. */
4667 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4669 dyn.d_un.d_val -= s->size;
4670 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4675 /* Fill in the first entry in the procedure linkage table. */
4676 splt = bfd_get_section_by_name (dynobj, ".plt");
4677 if (splt && splt->size > 0)
4681 memcpy (splt->contents, elf_mn10300_pic_plt_entry,
4682 elf_mn10300_sizeof_plt (info));
4686 memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
4687 bfd_put_32 (output_bfd,
4688 sgot->output_section->vma + sgot->output_offset + 4,
4689 splt->contents + elf_mn10300_plt0_gotid_offset (info));
4690 bfd_put_32 (output_bfd,
4691 sgot->output_section->vma + sgot->output_offset + 8,
4692 splt->contents + elf_mn10300_plt0_linker_offset (info));
4695 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4696 really seem like the right value. */
4697 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
4701 /* Fill in the first three entries in the global offset table. */
4705 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4707 bfd_put_32 (output_bfd,
4708 sdyn->output_section->vma + sdyn->output_offset,
4710 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4711 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4714 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4719 /* Classify relocation types, such that combreloc can sort them
4722 static enum elf_reloc_type_class
4723 _bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela *rela)
4725 switch ((int) ELF32_R_TYPE (rela->r_info))
4727 case R_MN10300_RELATIVE:
4728 return reloc_class_relative;
4729 case R_MN10300_JMP_SLOT:
4730 return reloc_class_plt;
4731 case R_MN10300_COPY:
4732 return reloc_class_copy;
4734 return reloc_class_normal;
4739 #define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec
4740 #define TARGET_LITTLE_NAME "elf32-mn10300"
4741 #define ELF_ARCH bfd_arch_mn10300
4742 #define ELF_MACHINE_CODE EM_MN10300
4743 #define ELF_MACHINE_ALT1 EM_CYGNUS_MN10300
4744 #define ELF_MAXPAGESIZE 0x1000
4747 #define elf_info_to_howto mn10300_info_to_howto
4748 #define elf_info_to_howto_rel 0
4749 #define elf_backend_can_gc_sections 1
4750 #define elf_backend_rela_normal 1
4751 #define elf_backend_check_relocs mn10300_elf_check_relocs
4752 #define elf_backend_gc_mark_hook mn10300_elf_gc_mark_hook
4753 #define elf_backend_relocate_section mn10300_elf_relocate_section
4754 #define bfd_elf32_bfd_relax_section mn10300_elf_relax_section
4755 #define bfd_elf32_bfd_get_relocated_section_contents \
4756 mn10300_elf_get_relocated_section_contents
4757 #define bfd_elf32_bfd_link_hash_table_create \
4758 elf32_mn10300_link_hash_table_create
4759 #define bfd_elf32_bfd_link_hash_table_free \
4760 elf32_mn10300_link_hash_table_free
4762 #ifndef elf_symbol_leading_char
4763 #define elf_symbol_leading_char '_'
4766 /* So we can set bits in e_flags. */
4767 #define elf_backend_final_write_processing \
4768 _bfd_mn10300_elf_final_write_processing
4769 #define elf_backend_object_p _bfd_mn10300_elf_object_p
4771 #define bfd_elf32_bfd_merge_private_bfd_data \
4772 _bfd_mn10300_elf_merge_private_bfd_data
4774 #define elf_backend_can_gc_sections 1
4775 #define elf_backend_create_dynamic_sections \
4776 _bfd_mn10300_elf_create_dynamic_sections
4777 #define elf_backend_adjust_dynamic_symbol \
4778 _bfd_mn10300_elf_adjust_dynamic_symbol
4779 #define elf_backend_size_dynamic_sections \
4780 _bfd_mn10300_elf_size_dynamic_sections
4781 #define elf_backend_finish_dynamic_symbol \
4782 _bfd_mn10300_elf_finish_dynamic_symbol
4783 #define elf_backend_finish_dynamic_sections \
4784 _bfd_mn10300_elf_finish_dynamic_sections
4786 #define elf_backend_reloc_type_class \
4787 _bfd_mn10300_elf_reloc_type_class
4789 #define elf_backend_want_got_plt 1
4790 #define elf_backend_plt_readonly 1
4791 #define elf_backend_want_plt_sym 0
4792 #define elf_backend_got_header_size 12
4794 #include "elf32-target.h"