1 /* Matsushita 10300 specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
26 #include "elf/mn10300.h"
27 #include "libiberty.h"
29 /* The mn10300 linker needs to keep track of the number of relocs that
30 it decides to copy in check_relocs for each symbol. This is so
31 that it can discard PC relative relocs if it doesn't need them when
32 linking with -Bsymbolic. We store the information in a field
33 extending the regular ELF linker hash table. */
35 struct elf32_mn10300_link_hash_entry
37 /* The basic elf link hash table entry. */
38 struct elf_link_hash_entry root
;
40 /* For function symbols, the number of times this function is
41 called directly (ie by name). */
42 unsigned int direct_calls
;
44 /* For function symbols, the size of this function's stack
45 (if <= 255 bytes). We stuff this into "call" instructions
46 to this target when it's valid and profitable to do so.
48 This does not include stack allocated by movm! */
49 unsigned char stack_size
;
51 /* For function symbols, arguments (if any) for movm instruction
52 in the prologue. We stuff this value into "call" instructions
53 to the target when it's valid and profitable to do so. */
54 unsigned char movm_args
;
56 /* For function symbols, the amount of stack space that would be allocated
57 by the movm instruction. This is redundant with movm_args, but we
58 add it to the hash table to avoid computing it over and over. */
59 unsigned char movm_stack_size
;
61 /* When set, convert all "call" instructions to this target into "calls"
63 #define MN10300_CONVERT_CALL_TO_CALLS 0x1
65 /* Used to mark functions which have had redundant parts of their
67 #define MN10300_DELETED_PROLOGUE_BYTES 0x2
70 /* Calculated value. */
74 /* We derive a hash table from the main elf linker hash table so
75 we can store state variables and a secondary hash table without
76 resorting to global variables. */
77 struct elf32_mn10300_link_hash_table
79 /* The main hash table. */
80 struct elf_link_hash_table root
;
82 /* A hash table for static functions. We could derive a new hash table
83 instead of using the full elf32_mn10300_link_hash_table if we wanted
84 to save some memory. */
85 struct elf32_mn10300_link_hash_table
*static_hash_table
;
87 /* Random linker state flags. */
88 #define MN10300_HASH_ENTRIES_INITIALIZED 0x1
93 #define streq(a, b) (strcmp ((a),(b)) == 0)
96 /* For MN10300 linker hash table. */
98 /* Get the MN10300 ELF linker hash table from a link_info structure. */
100 #define elf32_mn10300_hash_table(p) \
101 ((struct elf32_mn10300_link_hash_table *) ((p)->hash))
103 #define elf32_mn10300_link_hash_traverse(table, func, info) \
104 (elf_link_hash_traverse \
106 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
109 static reloc_howto_type elf_mn10300_howto_table
[] =
111 /* Dummy relocation. Does nothing. */
112 HOWTO (R_MN10300_NONE
,
118 complain_overflow_bitfield
,
119 bfd_elf_generic_reloc
,
125 /* Standard 32 bit reloc. */
132 complain_overflow_bitfield
,
133 bfd_elf_generic_reloc
,
139 /* Standard 16 bit reloc. */
146 complain_overflow_bitfield
,
147 bfd_elf_generic_reloc
,
153 /* Standard 8 bit reloc. */
160 complain_overflow_bitfield
,
161 bfd_elf_generic_reloc
,
167 /* Standard 32bit pc-relative reloc. */
168 HOWTO (R_MN10300_PCREL32
,
174 complain_overflow_bitfield
,
175 bfd_elf_generic_reloc
,
181 /* Standard 16bit pc-relative reloc. */
182 HOWTO (R_MN10300_PCREL16
,
188 complain_overflow_bitfield
,
189 bfd_elf_generic_reloc
,
195 /* Standard 8 pc-relative reloc. */
196 HOWTO (R_MN10300_PCREL8
,
202 complain_overflow_bitfield
,
203 bfd_elf_generic_reloc
,
210 /* GNU extension to record C++ vtable hierarchy. */
211 HOWTO (R_MN10300_GNU_VTINHERIT
, /* type */
213 0, /* size (0 = byte, 1 = short, 2 = long) */
215 FALSE
, /* pc_relative */
217 complain_overflow_dont
, /* complain_on_overflow */
218 NULL
, /* special_function */
219 "R_MN10300_GNU_VTINHERIT", /* name */
220 FALSE
, /* partial_inplace */
223 FALSE
), /* pcrel_offset */
225 /* GNU extension to record C++ vtable member usage */
226 HOWTO (R_MN10300_GNU_VTENTRY
, /* type */
228 0, /* size (0 = byte, 1 = short, 2 = long) */
230 FALSE
, /* pc_relative */
232 complain_overflow_dont
, /* complain_on_overflow */
233 NULL
, /* special_function */
234 "R_MN10300_GNU_VTENTRY", /* name */
235 FALSE
, /* partial_inplace */
238 FALSE
), /* pcrel_offset */
240 /* Standard 24 bit reloc. */
247 complain_overflow_bitfield
,
248 bfd_elf_generic_reloc
,
254 HOWTO (R_MN10300_GOTPC32
, /* type */
256 2, /* size (0 = byte, 1 = short, 2 = long) */
258 TRUE
, /* pc_relative */
260 complain_overflow_bitfield
, /* complain_on_overflow */
261 bfd_elf_generic_reloc
, /* */
262 "R_MN10300_GOTPC32", /* name */
263 FALSE
, /* partial_inplace */
264 0xffffffff, /* src_mask */
265 0xffffffff, /* dst_mask */
266 TRUE
), /* pcrel_offset */
268 HOWTO (R_MN10300_GOTPC16
, /* type */
270 1, /* size (0 = byte, 1 = short, 2 = long) */
272 TRUE
, /* pc_relative */
274 complain_overflow_bitfield
, /* complain_on_overflow */
275 bfd_elf_generic_reloc
, /* */
276 "R_MN10300_GOTPC16", /* name */
277 FALSE
, /* partial_inplace */
278 0xffff, /* src_mask */
279 0xffff, /* dst_mask */
280 TRUE
), /* pcrel_offset */
282 HOWTO (R_MN10300_GOTOFF32
, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_bitfield
, /* complain_on_overflow */
289 bfd_elf_generic_reloc
, /* */
290 "R_MN10300_GOTOFF32", /* name */
291 FALSE
, /* partial_inplace */
292 0xffffffff, /* src_mask */
293 0xffffffff, /* dst_mask */
294 FALSE
), /* pcrel_offset */
296 HOWTO (R_MN10300_GOTOFF24
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 FALSE
, /* pc_relative */
302 complain_overflow_bitfield
, /* complain_on_overflow */
303 bfd_elf_generic_reloc
, /* */
304 "R_MN10300_GOTOFF24", /* name */
305 FALSE
, /* partial_inplace */
306 0xffffff, /* src_mask */
307 0xffffff, /* dst_mask */
308 FALSE
), /* pcrel_offset */
310 HOWTO (R_MN10300_GOTOFF16
, /* type */
312 1, /* size (0 = byte, 1 = short, 2 = long) */
314 FALSE
, /* pc_relative */
316 complain_overflow_bitfield
, /* complain_on_overflow */
317 bfd_elf_generic_reloc
, /* */
318 "R_MN10300_GOTOFF16", /* name */
319 FALSE
, /* partial_inplace */
320 0xffff, /* src_mask */
321 0xffff, /* dst_mask */
322 FALSE
), /* pcrel_offset */
324 HOWTO (R_MN10300_PLT32
, /* type */
326 2, /* size (0 = byte, 1 = short, 2 = long) */
328 TRUE
, /* pc_relative */
330 complain_overflow_bitfield
, /* complain_on_overflow */
331 bfd_elf_generic_reloc
, /* */
332 "R_MN10300_PLT32", /* name */
333 FALSE
, /* partial_inplace */
334 0xffffffff, /* src_mask */
335 0xffffffff, /* dst_mask */
336 TRUE
), /* pcrel_offset */
338 HOWTO (R_MN10300_PLT16
, /* type */
340 1, /* size (0 = byte, 1 = short, 2 = long) */
342 TRUE
, /* pc_relative */
344 complain_overflow_bitfield
, /* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* */
346 "R_MN10300_PLT16", /* name */
347 FALSE
, /* partial_inplace */
348 0xffff, /* src_mask */
349 0xffff, /* dst_mask */
350 TRUE
), /* pcrel_offset */
352 HOWTO (R_MN10300_GOT32
, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE
, /* pc_relative */
358 complain_overflow_bitfield
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* */
360 "R_MN10300_GOT32", /* name */
361 FALSE
, /* partial_inplace */
362 0xffffffff, /* src_mask */
363 0xffffffff, /* dst_mask */
364 FALSE
), /* pcrel_offset */
366 HOWTO (R_MN10300_GOT24
, /* type */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
370 FALSE
, /* pc_relative */
372 complain_overflow_bitfield
, /* complain_on_overflow */
373 bfd_elf_generic_reloc
, /* */
374 "R_MN10300_GOT24", /* name */
375 FALSE
, /* partial_inplace */
376 0xffffffff, /* src_mask */
377 0xffffffff, /* dst_mask */
378 FALSE
), /* pcrel_offset */
380 HOWTO (R_MN10300_GOT16
, /* type */
382 1, /* size (0 = byte, 1 = short, 2 = long) */
384 FALSE
, /* pc_relative */
386 complain_overflow_bitfield
, /* complain_on_overflow */
387 bfd_elf_generic_reloc
, /* */
388 "R_MN10300_GOT16", /* name */
389 FALSE
, /* partial_inplace */
390 0xffffffff, /* src_mask */
391 0xffffffff, /* dst_mask */
392 FALSE
), /* pcrel_offset */
394 HOWTO (R_MN10300_COPY
, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 FALSE
, /* pc_relative */
400 complain_overflow_bitfield
, /* complain_on_overflow */
401 bfd_elf_generic_reloc
, /* */
402 "R_MN10300_COPY", /* name */
403 FALSE
, /* partial_inplace */
404 0xffffffff, /* src_mask */
405 0xffffffff, /* dst_mask */
406 FALSE
), /* pcrel_offset */
408 HOWTO (R_MN10300_GLOB_DAT
, /* type */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
412 FALSE
, /* pc_relative */
414 complain_overflow_bitfield
, /* complain_on_overflow */
415 bfd_elf_generic_reloc
, /* */
416 "R_MN10300_GLOB_DAT", /* name */
417 FALSE
, /* partial_inplace */
418 0xffffffff, /* src_mask */
419 0xffffffff, /* dst_mask */
420 FALSE
), /* pcrel_offset */
422 HOWTO (R_MN10300_JMP_SLOT
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE
, /* pc_relative */
428 complain_overflow_bitfield
, /* complain_on_overflow */
429 bfd_elf_generic_reloc
, /* */
430 "R_MN10300_JMP_SLOT", /* name */
431 FALSE
, /* partial_inplace */
432 0xffffffff, /* src_mask */
433 0xffffffff, /* dst_mask */
434 FALSE
), /* pcrel_offset */
436 HOWTO (R_MN10300_RELATIVE
, /* type */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
440 FALSE
, /* pc_relative */
442 complain_overflow_bitfield
, /* complain_on_overflow */
443 bfd_elf_generic_reloc
, /* */
444 "R_MN10300_RELATIVE", /* name */
445 FALSE
, /* partial_inplace */
446 0xffffffff, /* src_mask */
447 0xffffffff, /* dst_mask */
448 FALSE
), /* pcrel_offset */
451 struct mn10300_reloc_map
453 bfd_reloc_code_real_type bfd_reloc_val
;
454 unsigned char elf_reloc_val
;
457 static const struct mn10300_reloc_map mn10300_reloc_map
[] =
459 { BFD_RELOC_NONE
, R_MN10300_NONE
, },
460 { BFD_RELOC_32
, R_MN10300_32
, },
461 { BFD_RELOC_16
, R_MN10300_16
, },
462 { BFD_RELOC_8
, R_MN10300_8
, },
463 { BFD_RELOC_32_PCREL
, R_MN10300_PCREL32
, },
464 { BFD_RELOC_16_PCREL
, R_MN10300_PCREL16
, },
465 { BFD_RELOC_8_PCREL
, R_MN10300_PCREL8
, },
466 { BFD_RELOC_24
, R_MN10300_24
, },
467 { BFD_RELOC_VTABLE_INHERIT
, R_MN10300_GNU_VTINHERIT
},
468 { BFD_RELOC_VTABLE_ENTRY
, R_MN10300_GNU_VTENTRY
},
469 { BFD_RELOC_32_GOT_PCREL
, R_MN10300_GOTPC32
},
470 { BFD_RELOC_16_GOT_PCREL
, R_MN10300_GOTPC16
},
471 { BFD_RELOC_32_GOTOFF
, R_MN10300_GOTOFF32
},
472 { BFD_RELOC_MN10300_GOTOFF24
, R_MN10300_GOTOFF24
},
473 { BFD_RELOC_16_GOTOFF
, R_MN10300_GOTOFF16
},
474 { BFD_RELOC_32_PLT_PCREL
, R_MN10300_PLT32
},
475 { BFD_RELOC_16_PLT_PCREL
, R_MN10300_PLT16
},
476 { BFD_RELOC_MN10300_GOT32
, R_MN10300_GOT32
},
477 { BFD_RELOC_MN10300_GOT24
, R_MN10300_GOT24
},
478 { BFD_RELOC_MN10300_GOT16
, R_MN10300_GOT16
},
479 { BFD_RELOC_MN10300_COPY
, R_MN10300_COPY
},
480 { BFD_RELOC_MN10300_GLOB_DAT
, R_MN10300_GLOB_DAT
},
481 { BFD_RELOC_MN10300_JMP_SLOT
, R_MN10300_JMP_SLOT
},
482 { BFD_RELOC_MN10300_RELATIVE
, R_MN10300_RELATIVE
},
485 /* Create the GOT section. */
488 _bfd_mn10300_elf_create_got_section (bfd
* abfd
,
489 struct bfd_link_info
* info
)
494 struct elf_link_hash_entry
* h
;
495 const struct elf_backend_data
* bed
= get_elf_backend_data (abfd
);
498 /* This function may be called more than once. */
499 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
502 switch (bed
->s
->arch_size
)
513 bfd_set_error (bfd_error_bad_value
);
517 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
518 | SEC_LINKER_CREATED
);
521 pltflags
|= SEC_CODE
;
522 if (bed
->plt_not_loaded
)
523 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
524 if (bed
->plt_readonly
)
525 pltflags
|= SEC_READONLY
;
527 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
529 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
532 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
534 if (bed
->want_plt_sym
)
536 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
537 "_PROCEDURE_LINKAGE_TABLE_");
538 elf_hash_table (info
)->hplt
= h
;
543 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
545 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
548 if (bed
->want_got_plt
)
550 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
552 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
556 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
557 (or .got.plt) section. We don't do this in the linker script
558 because we don't want to define the symbol if we are not creating
559 a global offset table. */
560 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
561 elf_hash_table (info
)->hgot
= h
;
565 /* The first bit of the global offset table is the header. */
566 s
->size
+= bed
->got_header_size
;
571 static reloc_howto_type
*
572 bfd_elf32_bfd_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
573 bfd_reloc_code_real_type code
)
577 for (i
= ARRAY_SIZE (mn10300_reloc_map
); i
--;)
578 if (mn10300_reloc_map
[i
].bfd_reloc_val
== code
)
579 return &elf_mn10300_howto_table
[mn10300_reloc_map
[i
].elf_reloc_val
];
584 static reloc_howto_type
*
585 bfd_elf32_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
590 for (i
= ARRAY_SIZE (elf_mn10300_howto_table
); i
--;)
591 if (elf_mn10300_howto_table
[i
].name
!= NULL
592 && strcasecmp (elf_mn10300_howto_table
[i
].name
, r_name
) == 0)
593 return elf_mn10300_howto_table
+ i
;
598 /* Set the howto pointer for an MN10300 ELF reloc. */
601 mn10300_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
603 Elf_Internal_Rela
*dst
)
607 r_type
= ELF32_R_TYPE (dst
->r_info
);
608 BFD_ASSERT (r_type
< (unsigned int) R_MN10300_MAX
);
609 cache_ptr
->howto
= elf_mn10300_howto_table
+ r_type
;
612 /* Look through the relocs for a section during the first phase.
613 Since we don't do .gots or .plts, we just need to consider the
614 virtual table relocs for gc. */
617 mn10300_elf_check_relocs (bfd
*abfd
,
618 struct bfd_link_info
*info
,
620 const Elf_Internal_Rela
*relocs
)
622 Elf_Internal_Shdr
*symtab_hdr
;
623 struct elf_link_hash_entry
**sym_hashes
;
624 const Elf_Internal_Rela
*rel
;
625 const Elf_Internal_Rela
*rel_end
;
627 bfd_vma
* local_got_offsets
;
636 if (info
->relocatable
)
639 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
640 sym_hashes
= elf_sym_hashes (abfd
);
642 dynobj
= elf_hash_table (info
)->dynobj
;
643 local_got_offsets
= elf_local_got_offsets (abfd
);
644 rel_end
= relocs
+ sec
->reloc_count
;
646 for (rel
= relocs
; rel
< rel_end
; rel
++)
648 struct elf_link_hash_entry
*h
;
649 unsigned long r_symndx
;
651 r_symndx
= ELF32_R_SYM (rel
->r_info
);
652 if (r_symndx
< symtab_hdr
->sh_info
)
656 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
657 while (h
->root
.type
== bfd_link_hash_indirect
658 || h
->root
.type
== bfd_link_hash_warning
)
659 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
662 /* Some relocs require a global offset table. */
665 switch (ELF32_R_TYPE (rel
->r_info
))
667 case R_MN10300_GOT32
:
668 case R_MN10300_GOT24
:
669 case R_MN10300_GOT16
:
670 case R_MN10300_GOTOFF32
:
671 case R_MN10300_GOTOFF24
:
672 case R_MN10300_GOTOFF16
:
673 case R_MN10300_GOTPC32
:
674 case R_MN10300_GOTPC16
:
675 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
676 if (! _bfd_mn10300_elf_create_got_section (dynobj
, info
))
685 switch (ELF32_R_TYPE (rel
->r_info
))
687 /* This relocation describes the C++ object vtable hierarchy.
688 Reconstruct it for later use during GC. */
689 case R_MN10300_GNU_VTINHERIT
:
690 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
694 /* This relocation describes which C++ vtable entries are actually
695 used. Record for later use during GC. */
696 case R_MN10300_GNU_VTENTRY
:
697 BFD_ASSERT (h
!= NULL
);
699 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
702 case R_MN10300_GOT32
:
703 case R_MN10300_GOT24
:
704 case R_MN10300_GOT16
:
705 /* This symbol requires a global offset table entry. */
709 sgot
= bfd_get_section_by_name (dynobj
, ".got");
710 BFD_ASSERT (sgot
!= NULL
);
714 && (h
!= NULL
|| info
->shared
))
716 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
719 srelgot
= bfd_make_section_with_flags (dynobj
,
728 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
735 if (h
->got
.offset
!= (bfd_vma
) -1)
736 /* We have already allocated space in the .got. */
739 h
->got
.offset
= sgot
->size
;
741 /* Make sure this symbol is output as a dynamic symbol. */
742 if (h
->dynindx
== -1)
744 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
748 srelgot
->size
+= sizeof (Elf32_External_Rela
);
752 /* This is a global offset table entry for a local
754 if (local_got_offsets
== NULL
)
759 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
760 local_got_offsets
= bfd_alloc (abfd
, size
);
762 if (local_got_offsets
== NULL
)
764 elf_local_got_offsets (abfd
) = local_got_offsets
;
766 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
767 local_got_offsets
[i
] = (bfd_vma
) -1;
770 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
771 /* We have already allocated space in the .got. */
774 local_got_offsets
[r_symndx
] = sgot
->size
;
777 /* If we are generating a shared object, we need to
778 output a R_MN10300_RELATIVE reloc so that the dynamic
779 linker can adjust this GOT entry. */
780 srelgot
->size
+= sizeof (Elf32_External_Rela
);
786 case R_MN10300_PLT32
:
787 case R_MN10300_PLT16
:
788 /* This symbol requires a procedure linkage table entry. We
789 actually build the entry in adjust_dynamic_symbol,
790 because this might be a case of linking PIC code which is
791 never referenced by a dynamic object, in which case we
792 don't need to generate a procedure linkage table entry
795 /* If this is a local symbol, we resolve it directly without
796 creating a procedure linkage table entry. */
800 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
801 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
810 case R_MN10300_PCREL32
:
811 case R_MN10300_PCREL16
:
812 case R_MN10300_PCREL8
:
821 /* If we are creating a shared library, then we need to copy
822 the reloc into the shared library. */
824 && (sec
->flags
& SEC_ALLOC
) != 0)
826 /* When creating a shared object, we must copy these
827 reloc types into the output file. We create a reloc
828 section in dynobj and make room for this reloc. */
833 name
= (bfd_elf_string_from_elf_section
835 elf_elfheader (abfd
)->e_shstrndx
,
836 elf_section_data (sec
)->rel_hdr
.sh_name
));
840 BFD_ASSERT (CONST_STRNEQ (name
, ".rela")
841 && streq (bfd_get_section_name (abfd
, sec
), name
+ 5));
843 sreloc
= bfd_get_section_by_name (dynobj
, name
);
848 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
849 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
850 if ((sec
->flags
& SEC_ALLOC
) != 0)
851 flags
|= SEC_ALLOC
| SEC_LOAD
;
852 sreloc
= bfd_make_section_with_flags (dynobj
, name
, flags
);
854 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
859 sreloc
->size
+= sizeof (Elf32_External_Rela
);
869 /* Return the section that should be marked against GC for a given
873 mn10300_elf_gc_mark_hook (asection
*sec
,
874 struct bfd_link_info
*info
,
875 Elf_Internal_Rela
*rel
,
876 struct elf_link_hash_entry
*h
,
877 Elf_Internal_Sym
*sym
)
880 switch (ELF32_R_TYPE (rel
->r_info
))
882 case R_MN10300_GNU_VTINHERIT
:
883 case R_MN10300_GNU_VTENTRY
:
887 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
890 /* Perform a relocation as part of a final link. */
892 static bfd_reloc_status_type
893 mn10300_elf_final_link_relocate (reloc_howto_type
*howto
,
895 bfd
*output_bfd ATTRIBUTE_UNUSED
,
896 asection
*input_section
,
901 struct elf_link_hash_entry
* h
,
902 unsigned long symndx
,
903 struct bfd_link_info
*info
,
904 asection
*sym_sec ATTRIBUTE_UNUSED
,
905 int is_local ATTRIBUTE_UNUSED
)
907 unsigned long r_type
= howto
->type
;
908 bfd_byte
* hit_data
= contents
+ offset
;
910 bfd_vma
* local_got_offsets
;
915 dynobj
= elf_hash_table (info
)->dynobj
;
916 local_got_offsets
= elf_local_got_offsets (input_bfd
);
927 case R_MN10300_PCREL8
:
928 case R_MN10300_PCREL16
:
929 case R_MN10300_PCREL32
:
930 case R_MN10300_GOTOFF32
:
931 case R_MN10300_GOTOFF24
:
932 case R_MN10300_GOTOFF16
:
934 && (input_section
->flags
& SEC_ALLOC
) != 0
936 && ! SYMBOL_REFERENCES_LOCAL (info
, h
))
937 return bfd_reloc_dangerous
;
947 && (input_section
->flags
& SEC_ALLOC
) != 0)
949 Elf_Internal_Rela outrel
;
950 bfd_boolean skip
, relocate
;
952 /* When generating a shared object, these relocations are
953 copied into the output file to be resolved at run
959 name
= (bfd_elf_string_from_elf_section
961 elf_elfheader (input_bfd
)->e_shstrndx
,
962 elf_section_data (input_section
)->rel_hdr
.sh_name
));
966 BFD_ASSERT (CONST_STRNEQ (name
, ".rela")
967 && streq (bfd_get_section_name (input_bfd
,
971 sreloc
= bfd_get_section_by_name (dynobj
, name
);
972 BFD_ASSERT (sreloc
!= NULL
);
977 outrel
.r_offset
= _bfd_elf_section_offset (input_bfd
, info
,
978 input_section
, offset
);
979 if (outrel
.r_offset
== (bfd_vma
) -1)
982 outrel
.r_offset
+= (input_section
->output_section
->vma
983 + input_section
->output_offset
);
987 memset (&outrel
, 0, sizeof outrel
);
992 /* h->dynindx may be -1 if this symbol was marked to
995 || SYMBOL_REFERENCES_LOCAL (info
, h
))
998 outrel
.r_info
= ELF32_R_INFO (0, R_MN10300_RELATIVE
);
999 outrel
.r_addend
= value
+ addend
;
1003 BFD_ASSERT (h
->dynindx
!= -1);
1005 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MN10300_32
);
1006 outrel
.r_addend
= value
+ addend
;
1010 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1011 (bfd_byte
*) (((Elf32_External_Rela
*) sreloc
->contents
)
1012 + sreloc
->reloc_count
));
1013 ++sreloc
->reloc_count
;
1015 /* If this reloc is against an external symbol, we do
1016 not want to fiddle with the addend. Otherwise, we
1017 need to include the symbol value so that it becomes
1018 an addend for the dynamic reloc. */
1020 return bfd_reloc_ok
;
1023 bfd_put_32 (input_bfd
, value
, hit_data
);
1024 return bfd_reloc_ok
;
1029 if ((long) value
> 0x7fffff || (long) value
< -0x800000)
1030 return bfd_reloc_overflow
;
1032 bfd_put_8 (input_bfd
, value
& 0xff, hit_data
);
1033 bfd_put_8 (input_bfd
, (value
>> 8) & 0xff, hit_data
+ 1);
1034 bfd_put_8 (input_bfd
, (value
>> 16) & 0xff, hit_data
+ 2);
1035 return bfd_reloc_ok
;
1040 if ((long) value
> 0x7fff || (long) value
< -0x8000)
1041 return bfd_reloc_overflow
;
1043 bfd_put_16 (input_bfd
, value
, hit_data
);
1044 return bfd_reloc_ok
;
1049 if ((long) value
> 0x7f || (long) value
< -0x80)
1050 return bfd_reloc_overflow
;
1052 bfd_put_8 (input_bfd
, value
, hit_data
);
1053 return bfd_reloc_ok
;
1055 case R_MN10300_PCREL8
:
1056 value
-= (input_section
->output_section
->vma
1057 + input_section
->output_offset
);
1061 if ((long) value
> 0xff || (long) value
< -0x100)
1062 return bfd_reloc_overflow
;
1064 bfd_put_8 (input_bfd
, value
, hit_data
);
1065 return bfd_reloc_ok
;
1067 case R_MN10300_PCREL16
:
1068 value
-= (input_section
->output_section
->vma
1069 + input_section
->output_offset
);
1073 if ((long) value
> 0xffff || (long) value
< -0x10000)
1074 return bfd_reloc_overflow
;
1076 bfd_put_16 (input_bfd
, value
, hit_data
);
1077 return bfd_reloc_ok
;
1079 case R_MN10300_PCREL32
:
1080 value
-= (input_section
->output_section
->vma
1081 + input_section
->output_offset
);
1085 bfd_put_32 (input_bfd
, value
, hit_data
);
1086 return bfd_reloc_ok
;
1088 case R_MN10300_GNU_VTINHERIT
:
1089 case R_MN10300_GNU_VTENTRY
:
1090 return bfd_reloc_ok
;
1092 case R_MN10300_GOTPC32
:
1093 /* Use global offset table as symbol value. */
1094 value
= bfd_get_section_by_name (dynobj
,
1095 ".got")->output_section
->vma
;
1096 value
-= (input_section
->output_section
->vma
1097 + input_section
->output_offset
);
1101 bfd_put_32 (input_bfd
, value
, hit_data
);
1102 return bfd_reloc_ok
;
1104 case R_MN10300_GOTPC16
:
1105 /* Use global offset table as symbol value. */
1106 value
= bfd_get_section_by_name (dynobj
,
1107 ".got")->output_section
->vma
;
1108 value
-= (input_section
->output_section
->vma
1109 + input_section
->output_offset
);
1113 if ((long) value
> 0xffff || (long) value
< -0x10000)
1114 return bfd_reloc_overflow
;
1116 bfd_put_16 (input_bfd
, value
, hit_data
);
1117 return bfd_reloc_ok
;
1119 case R_MN10300_GOTOFF32
:
1120 value
-= bfd_get_section_by_name (dynobj
,
1121 ".got")->output_section
->vma
;
1124 bfd_put_32 (input_bfd
, value
, hit_data
);
1125 return bfd_reloc_ok
;
1127 case R_MN10300_GOTOFF24
:
1128 value
-= bfd_get_section_by_name (dynobj
,
1129 ".got")->output_section
->vma
;
1132 if ((long) value
> 0x7fffff || (long) value
< -0x800000)
1133 return bfd_reloc_overflow
;
1135 bfd_put_8 (input_bfd
, value
, hit_data
);
1136 bfd_put_8 (input_bfd
, (value
>> 8) & 0xff, hit_data
+ 1);
1137 bfd_put_8 (input_bfd
, (value
>> 16) & 0xff, hit_data
+ 2);
1138 return bfd_reloc_ok
;
1140 case R_MN10300_GOTOFF16
:
1141 value
-= bfd_get_section_by_name (dynobj
,
1142 ".got")->output_section
->vma
;
1145 if ((long) value
> 0xffff || (long) value
< -0x10000)
1146 return bfd_reloc_overflow
;
1148 bfd_put_16 (input_bfd
, value
, hit_data
);
1149 return bfd_reloc_ok
;
1151 case R_MN10300_PLT32
:
1153 && ELF_ST_VISIBILITY (h
->other
) != STV_INTERNAL
1154 && ELF_ST_VISIBILITY (h
->other
) != STV_HIDDEN
1155 && h
->plt
.offset
!= (bfd_vma
) -1)
1159 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1161 value
= (splt
->output_section
->vma
1162 + splt
->output_offset
1163 + h
->plt
.offset
) - value
;
1166 value
-= (input_section
->output_section
->vma
1167 + input_section
->output_offset
);
1171 bfd_put_32 (input_bfd
, value
, hit_data
);
1172 return bfd_reloc_ok
;
1174 case R_MN10300_PLT16
:
1176 && ELF_ST_VISIBILITY (h
->other
) != STV_INTERNAL
1177 && ELF_ST_VISIBILITY (h
->other
) != STV_HIDDEN
1178 && h
->plt
.offset
!= (bfd_vma
) -1)
1182 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1184 value
= (splt
->output_section
->vma
1185 + splt
->output_offset
1186 + h
->plt
.offset
) - value
;
1189 value
-= (input_section
->output_section
->vma
1190 + input_section
->output_offset
);
1194 if ((long) value
> 0xffff || (long) value
< -0x10000)
1195 return bfd_reloc_overflow
;
1197 bfd_put_16 (input_bfd
, value
, hit_data
);
1198 return bfd_reloc_ok
;
1200 case R_MN10300_GOT32
:
1201 case R_MN10300_GOT24
:
1202 case R_MN10300_GOT16
:
1206 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1212 off
= h
->got
.offset
;
1213 BFD_ASSERT (off
!= (bfd_vma
) -1);
1215 if (! elf_hash_table (info
)->dynamic_sections_created
1216 || SYMBOL_REFERENCES_LOCAL (info
, h
))
1217 /* This is actually a static link, or it is a
1218 -Bsymbolic link and the symbol is defined
1219 locally, or the symbol was forced to be local
1220 because of a version file. We must initialize
1221 this entry in the global offset table.
1223 When doing a dynamic link, we create a .rela.got
1224 relocation entry to initialize the value. This
1225 is done in the finish_dynamic_symbol routine. */
1226 bfd_put_32 (output_bfd
, value
,
1227 sgot
->contents
+ off
);
1229 value
= sgot
->output_offset
+ off
;
1235 off
= elf_local_got_offsets (input_bfd
)[symndx
];
1237 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ off
);
1242 Elf_Internal_Rela outrel
;
1244 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1245 BFD_ASSERT (srelgot
!= NULL
);
1247 outrel
.r_offset
= (sgot
->output_section
->vma
1248 + sgot
->output_offset
1250 outrel
.r_info
= ELF32_R_INFO (0, R_MN10300_RELATIVE
);
1251 outrel
.r_addend
= value
;
1252 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1253 (bfd_byte
*) (((Elf32_External_Rela
*)
1255 + srelgot
->reloc_count
));
1256 ++ srelgot
->reloc_count
;
1259 value
= sgot
->output_offset
+ off
;
1265 if (r_type
== R_MN10300_GOT32
)
1267 bfd_put_32 (input_bfd
, value
, hit_data
);
1268 return bfd_reloc_ok
;
1270 else if (r_type
== R_MN10300_GOT24
)
1272 if ((long) value
> 0x7fffff || (long) value
< -0x800000)
1273 return bfd_reloc_overflow
;
1275 bfd_put_8 (input_bfd
, value
& 0xff, hit_data
);
1276 bfd_put_8 (input_bfd
, (value
>> 8) & 0xff, hit_data
+ 1);
1277 bfd_put_8 (input_bfd
, (value
>> 16) & 0xff, hit_data
+ 2);
1278 return bfd_reloc_ok
;
1280 else if (r_type
== R_MN10300_GOT16
)
1282 if ((long) value
> 0xffff || (long) value
< -0x10000)
1283 return bfd_reloc_overflow
;
1285 bfd_put_16 (input_bfd
, value
, hit_data
);
1286 return bfd_reloc_ok
;
1291 return bfd_reloc_notsupported
;
1295 /* Relocate an MN10300 ELF section. */
1298 mn10300_elf_relocate_section (bfd
*output_bfd
,
1299 struct bfd_link_info
*info
,
1301 asection
*input_section
,
1303 Elf_Internal_Rela
*relocs
,
1304 Elf_Internal_Sym
*local_syms
,
1305 asection
**local_sections
)
1307 Elf_Internal_Shdr
*symtab_hdr
;
1308 struct elf_link_hash_entry
**sym_hashes
;
1309 Elf_Internal_Rela
*rel
, *relend
;
1311 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1312 sym_hashes
= elf_sym_hashes (input_bfd
);
1315 relend
= relocs
+ input_section
->reloc_count
;
1316 for (; rel
< relend
; rel
++)
1319 reloc_howto_type
*howto
;
1320 unsigned long r_symndx
;
1321 Elf_Internal_Sym
*sym
;
1323 struct elf32_mn10300_link_hash_entry
*h
;
1325 bfd_reloc_status_type r
;
1327 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1328 r_type
= ELF32_R_TYPE (rel
->r_info
);
1329 howto
= elf_mn10300_howto_table
+ r_type
;
1331 /* Just skip the vtable gc relocs. */
1332 if (r_type
== R_MN10300_GNU_VTINHERIT
1333 || r_type
== R_MN10300_GNU_VTENTRY
)
1339 if (r_symndx
< symtab_hdr
->sh_info
)
1341 sym
= local_syms
+ r_symndx
;
1342 sec
= local_sections
[r_symndx
];
1343 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
1347 bfd_boolean unresolved_reloc
;
1349 struct elf_link_hash_entry
*hh
;
1351 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
1352 r_symndx
, symtab_hdr
, sym_hashes
,
1353 hh
, sec
, relocation
,
1354 unresolved_reloc
, warned
);
1356 h
= (struct elf32_mn10300_link_hash_entry
*) hh
;
1358 if ((h
->root
.root
.type
== bfd_link_hash_defined
1359 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1360 && ( r_type
== R_MN10300_GOTPC32
1361 || r_type
== R_MN10300_GOTPC16
1362 || (( r_type
== R_MN10300_PLT32
1363 || r_type
== R_MN10300_PLT16
)
1364 && ELF_ST_VISIBILITY (h
->root
.other
) != STV_INTERNAL
1365 && ELF_ST_VISIBILITY (h
->root
.other
) != STV_HIDDEN
1366 && h
->root
.plt
.offset
!= (bfd_vma
) -1)
1367 || (( r_type
== R_MN10300_GOT32
1368 || r_type
== R_MN10300_GOT24
1369 || r_type
== R_MN10300_GOT16
)
1370 && elf_hash_table (info
)->dynamic_sections_created
1371 && !SYMBOL_REFERENCES_LOCAL (info
, hh
))
1372 || (r_type
== R_MN10300_32
1373 && !SYMBOL_REFERENCES_LOCAL (info
, hh
)
1374 && ((input_section
->flags
& SEC_ALLOC
) != 0
1375 /* DWARF will emit R_MN10300_32 relocations
1376 in its sections against symbols defined
1377 externally in shared libraries. We can't
1378 do anything with them here. */
1379 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
1380 && h
->root
.def_dynamic
)))))
1381 /* In these cases, we don't need the relocation
1382 value. We check specially because in some
1383 obscure cases sec->output_section will be NULL. */
1386 else if (!info
->relocatable
&& unresolved_reloc
)
1387 (*_bfd_error_handler
)
1388 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1391 (long) rel
->r_offset
,
1393 h
->root
.root
.root
.string
);
1396 if (sec
!= NULL
&& elf_discarded_section (sec
))
1398 /* For relocs against symbols from removed linkonce sections,
1399 or sections discarded by a linker script, we just want the
1400 section contents zeroed. Avoid any special processing. */
1401 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
1407 if (info
->relocatable
)
1410 r
= mn10300_elf_final_link_relocate (howto
, input_bfd
, output_bfd
,
1412 contents
, rel
->r_offset
,
1413 relocation
, rel
->r_addend
,
1414 (struct elf_link_hash_entry
*) h
,
1416 info
, sec
, h
== NULL
);
1418 if (r
!= bfd_reloc_ok
)
1421 const char *msg
= NULL
;
1424 name
= h
->root
.root
.root
.string
;
1427 name
= (bfd_elf_string_from_elf_section
1428 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
1429 if (name
== NULL
|| *name
== '\0')
1430 name
= bfd_section_name (input_bfd
, sec
);
1435 case bfd_reloc_overflow
:
1436 if (! ((*info
->callbacks
->reloc_overflow
)
1437 (info
, (h
? &h
->root
.root
: NULL
), name
,
1438 howto
->name
, (bfd_vma
) 0, input_bfd
,
1439 input_section
, rel
->r_offset
)))
1443 case bfd_reloc_undefined
:
1444 if (! ((*info
->callbacks
->undefined_symbol
)
1445 (info
, name
, input_bfd
, input_section
,
1446 rel
->r_offset
, TRUE
)))
1450 case bfd_reloc_outofrange
:
1451 msg
= _("internal error: out of range error");
1454 case bfd_reloc_notsupported
:
1455 msg
= _("internal error: unsupported relocation error");
1458 case bfd_reloc_dangerous
:
1459 if (r_type
== R_MN10300_PCREL32
)
1460 msg
= _("error: inappropriate relocation type for shared"
1461 " library (did you forget -fpic?)");
1463 msg
= _("internal error: suspicious relocation type used"
1464 " in shared library");
1468 msg
= _("internal error: unknown error");
1472 if (!((*info
->callbacks
->warning
)
1473 (info
, msg
, name
, input_bfd
, input_section
,
1484 /* Finish initializing one hash table entry. */
1487 elf32_mn10300_finish_hash_table_entry (struct bfd_hash_entry
*gen_entry
,
1490 struct elf32_mn10300_link_hash_entry
*entry
;
1491 struct bfd_link_info
*link_info
= (struct bfd_link_info
*) in_args
;
1492 unsigned int byte_count
= 0;
1494 entry
= (struct elf32_mn10300_link_hash_entry
*) gen_entry
;
1496 if (entry
->root
.root
.type
== bfd_link_hash_warning
)
1497 entry
= (struct elf32_mn10300_link_hash_entry
*) entry
->root
.root
.u
.i
.link
;
1499 /* If we already know we want to convert "call" to "calls" for calls
1500 to this symbol, then return now. */
1501 if (entry
->flags
== MN10300_CONVERT_CALL_TO_CALLS
)
1504 /* If there are no named calls to this symbol, or there's nothing we
1505 can move from the function itself into the "call" instruction,
1506 then note that all "call" instructions should be converted into
1507 "calls" instructions and return. If a symbol is available for
1508 dynamic symbol resolution (overridable or overriding), avoid
1509 custom calling conventions. */
1510 if (entry
->direct_calls
== 0
1511 || (entry
->stack_size
== 0 && entry
->movm_args
== 0)
1512 || (elf_hash_table (link_info
)->dynamic_sections_created
1513 && ELF_ST_VISIBILITY (entry
->root
.other
) != STV_INTERNAL
1514 && ELF_ST_VISIBILITY (entry
->root
.other
) != STV_HIDDEN
))
1516 /* Make a note that we should convert "call" instructions to "calls"
1517 instructions for calls to this symbol. */
1518 entry
->flags
|= MN10300_CONVERT_CALL_TO_CALLS
;
1522 /* We may be able to move some instructions from the function itself into
1523 the "call" instruction. Count how many bytes we might be able to
1524 eliminate in the function itself. */
1526 /* A movm instruction is two bytes. */
1527 if (entry
->movm_args
)
1530 /* Count the insn to allocate stack space too. */
1531 if (entry
->stack_size
> 0)
1533 if (entry
->stack_size
<= 128)
1539 /* If using "call" will result in larger code, then turn all
1540 the associated "call" instructions into "calls" instructions. */
1541 if (byte_count
< entry
->direct_calls
)
1542 entry
->flags
|= MN10300_CONVERT_CALL_TO_CALLS
;
1544 /* This routine never fails. */
1548 /* Used to count hash table entries. */
1551 elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry
*gen_entry ATTRIBUTE_UNUSED
,
1554 int *count
= (int *)in_args
;
1560 /* Used to enumerate hash table entries into a linear array. */
1563 elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry
*gen_entry
,
1566 struct bfd_hash_entry
***ptr
= (struct bfd_hash_entry
***) in_args
;
1573 /* Used to sort the array created by the above. */
1576 sort_by_value (const void *va
, const void *vb
)
1578 struct elf32_mn10300_link_hash_entry
*a
1579 = *(struct elf32_mn10300_link_hash_entry
**)va
;
1580 struct elf32_mn10300_link_hash_entry
*b
1581 = *(struct elf32_mn10300_link_hash_entry
**)vb
;
1583 return a
->value
- b
->value
;
1586 /* Compute the stack size and movm arguments for the function
1587 referred to by HASH at address ADDR in section with
1588 contents CONTENTS, store the information in the hash table. */
1591 compute_function_info (bfd
*abfd
,
1592 struct elf32_mn10300_link_hash_entry
*hash
,
1594 unsigned char *contents
)
1596 unsigned char byte1
, byte2
;
1597 /* We only care about a very small subset of the possible prologue
1598 sequences here. Basically we look for:
1600 movm [d2,d3,a2,a3],sp (optional)
1601 add <size>,sp (optional, and only for sizes which fit in an unsigned
1604 If we find anything else, we quit. */
1606 /* Look for movm [regs],sp. */
1607 byte1
= bfd_get_8 (abfd
, contents
+ addr
);
1608 byte2
= bfd_get_8 (abfd
, contents
+ addr
+ 1);
1612 hash
->movm_args
= byte2
;
1614 byte1
= bfd_get_8 (abfd
, contents
+ addr
);
1615 byte2
= bfd_get_8 (abfd
, contents
+ addr
+ 1);
1618 /* Now figure out how much stack space will be allocated by the movm
1619 instruction. We need this kept separate from the function's normal
1621 if (hash
->movm_args
)
1624 if (hash
->movm_args
& 0x80)
1625 hash
->movm_stack_size
+= 4;
1628 if (hash
->movm_args
& 0x40)
1629 hash
->movm_stack_size
+= 4;
1632 if (hash
->movm_args
& 0x20)
1633 hash
->movm_stack_size
+= 4;
1636 if (hash
->movm_args
& 0x10)
1637 hash
->movm_stack_size
+= 4;
1639 /* "other" space. d0, d1, a0, a1, mdr, lir, lar, 4 byte pad. */
1640 if (hash
->movm_args
& 0x08)
1641 hash
->movm_stack_size
+= 8 * 4;
1643 if (bfd_get_mach (abfd
) == bfd_mach_am33
1644 || bfd_get_mach (abfd
) == bfd_mach_am33_2
)
1646 /* "exother" space. e0, e1, mdrq, mcrh, mcrl, mcvf */
1647 if (hash
->movm_args
& 0x1)
1648 hash
->movm_stack_size
+= 6 * 4;
1650 /* exreg1 space. e4, e5, e6, e7 */
1651 if (hash
->movm_args
& 0x2)
1652 hash
->movm_stack_size
+= 4 * 4;
1654 /* exreg0 space. e2, e3 */
1655 if (hash
->movm_args
& 0x4)
1656 hash
->movm_stack_size
+= 2 * 4;
1660 /* Now look for the two stack adjustment variants. */
1661 if (byte1
== 0xf8 && byte2
== 0xfe)
1663 int temp
= bfd_get_8 (abfd
, contents
+ addr
+ 2);
1664 temp
= ((temp
& 0xff) ^ (~0x7f)) + 0x80;
1666 hash
->stack_size
= -temp
;
1668 else if (byte1
== 0xfa && byte2
== 0xfe)
1670 int temp
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
1671 temp
= ((temp
& 0xffff) ^ (~0x7fff)) + 0x8000;
1675 hash
->stack_size
= temp
;
1678 /* If the total stack to be allocated by the call instruction is more
1679 than 255 bytes, then we can't remove the stack adjustment by using
1680 "call" (we might still be able to remove the "movm" instruction. */
1681 if (hash
->stack_size
+ hash
->movm_stack_size
> 255)
1682 hash
->stack_size
= 0;
1685 /* Delete some bytes from a section while relaxing. */
1688 mn10300_elf_relax_delete_bytes (bfd
*abfd
,
1693 Elf_Internal_Shdr
*symtab_hdr
;
1694 unsigned int sec_shndx
;
1696 Elf_Internal_Rela
*irel
, *irelend
;
1697 Elf_Internal_Rela
*irelalign
;
1699 Elf_Internal_Sym
*isym
, *isymend
;
1700 struct elf_link_hash_entry
**sym_hashes
;
1701 struct elf_link_hash_entry
**end_hashes
;
1702 unsigned int symcount
;
1704 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
1706 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1708 /* The deletion must stop at the next ALIGN reloc for an aligment
1709 power larger than the number of bytes we are deleting. */
1714 irel
= elf_section_data (sec
)->relocs
;
1715 irelend
= irel
+ sec
->reloc_count
;
1717 /* Actually delete the bytes. */
1718 memmove (contents
+ addr
, contents
+ addr
+ count
,
1719 (size_t) (toaddr
- addr
- count
));
1722 /* Adjust all the relocs. */
1723 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
1725 /* Get the new reloc address. */
1726 if ((irel
->r_offset
> addr
1727 && irel
->r_offset
< toaddr
))
1728 irel
->r_offset
-= count
;
1731 /* Adjust the local symbols defined in this section. */
1732 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1733 isym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1734 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
1736 if (isym
->st_shndx
== sec_shndx
1737 && isym
->st_value
> addr
1738 && isym
->st_value
< toaddr
)
1739 isym
->st_value
-= count
;
1742 /* Now adjust the global symbols defined in this section. */
1743 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
1744 - symtab_hdr
->sh_info
);
1745 sym_hashes
= elf_sym_hashes (abfd
);
1746 end_hashes
= sym_hashes
+ symcount
;
1747 for (; sym_hashes
< end_hashes
; sym_hashes
++)
1749 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
1751 if ((sym_hash
->root
.type
== bfd_link_hash_defined
1752 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
1753 && sym_hash
->root
.u
.def
.section
== sec
1754 && sym_hash
->root
.u
.def
.value
> addr
1755 && sym_hash
->root
.u
.def
.value
< toaddr
)
1756 sym_hash
->root
.u
.def
.value
-= count
;
1762 /* Return TRUE if a symbol exists at the given address, else return
1766 mn10300_elf_symbol_address_p (bfd
*abfd
,
1768 Elf_Internal_Sym
*isym
,
1771 Elf_Internal_Shdr
*symtab_hdr
;
1772 unsigned int sec_shndx
;
1773 Elf_Internal_Sym
*isymend
;
1774 struct elf_link_hash_entry
**sym_hashes
;
1775 struct elf_link_hash_entry
**end_hashes
;
1776 unsigned int symcount
;
1778 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
1780 /* Examine all the symbols. */
1781 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1782 for (isymend
= isym
+ symtab_hdr
->sh_info
; isym
< isymend
; isym
++)
1783 if (isym
->st_shndx
== sec_shndx
1784 && isym
->st_value
== addr
)
1787 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
1788 - symtab_hdr
->sh_info
);
1789 sym_hashes
= elf_sym_hashes (abfd
);
1790 end_hashes
= sym_hashes
+ symcount
;
1791 for (; sym_hashes
< end_hashes
; sym_hashes
++)
1793 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
1795 if ((sym_hash
->root
.type
== bfd_link_hash_defined
1796 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
1797 && sym_hash
->root
.u
.def
.section
== sec
1798 && sym_hash
->root
.u
.def
.value
== addr
)
1805 /* This function handles relaxing for the mn10300.
1807 There are quite a few relaxing opportunities available on the mn10300:
1809 * calls:32 -> calls:16 2 bytes
1810 * call:32 -> call:16 2 bytes
1812 * call:32 -> calls:32 1 byte
1813 * call:16 -> calls:16 1 byte
1814 * These are done anytime using "calls" would result
1815 in smaller code, or when necessary to preserve the
1816 meaning of the program.
1820 * In some circumstances we can move instructions
1821 from a function prologue into a "call" instruction.
1822 This is only done if the resulting code is no larger
1823 than the original code.
1825 * jmp:32 -> jmp:16 2 bytes
1826 * jmp:16 -> bra:8 1 byte
1828 * If the previous instruction is a conditional branch
1829 around the jump/bra, we may be able to reverse its condition
1830 and change its target to the jump's target. The jump/bra
1831 can then be deleted. 2 bytes
1833 * mov abs32 -> mov abs16 1 or 2 bytes
1835 * Most instructions which accept imm32 can relax to imm16 1 or 2 bytes
1836 - Most instructions which accept imm16 can relax to imm8 1 or 2 bytes
1838 * Most instructions which accept d32 can relax to d16 1 or 2 bytes
1839 - Most instructions which accept d16 can relax to d8 1 or 2 bytes
1841 We don't handle imm16->imm8 or d16->d8 as they're very rare
1842 and somewhat more difficult to support. */
1845 mn10300_elf_relax_section (bfd
*abfd
,
1847 struct bfd_link_info
*link_info
,
1850 Elf_Internal_Shdr
*symtab_hdr
;
1851 Elf_Internal_Rela
*internal_relocs
= NULL
;
1852 Elf_Internal_Rela
*irel
, *irelend
;
1853 bfd_byte
*contents
= NULL
;
1854 Elf_Internal_Sym
*isymbuf
= NULL
;
1855 struct elf32_mn10300_link_hash_table
*hash_table
;
1856 asection
*section
= sec
;
1858 /* Assume nothing changes. */
1861 /* We need a pointer to the mn10300 specific hash table. */
1862 hash_table
= elf32_mn10300_hash_table (link_info
);
1864 /* Initialize fields in each hash table entry the first time through. */
1865 if ((hash_table
->flags
& MN10300_HASH_ENTRIES_INITIALIZED
) == 0)
1869 /* Iterate over all the input bfds. */
1870 for (input_bfd
= link_info
->input_bfds
;
1872 input_bfd
= input_bfd
->link_next
)
1874 /* We're going to need all the symbols for each bfd. */
1875 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1876 if (symtab_hdr
->sh_info
!= 0)
1878 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1879 if (isymbuf
== NULL
)
1880 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
1881 symtab_hdr
->sh_info
, 0,
1883 if (isymbuf
== NULL
)
1887 /* Iterate over each section in this bfd. */
1888 for (section
= input_bfd
->sections
;
1890 section
= section
->next
)
1892 struct elf32_mn10300_link_hash_entry
*hash
;
1893 Elf_Internal_Sym
*sym
;
1894 asection
*sym_sec
= NULL
;
1895 const char *sym_name
;
1898 /* If there's nothing to do in this section, skip it. */
1899 if (! ((section
->flags
& SEC_RELOC
) != 0
1900 && section
->reloc_count
!= 0))
1902 if ((section
->flags
& SEC_ALLOC
) == 0)
1905 /* Get cached copy of section contents if it exists. */
1906 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
1907 contents
= elf_section_data (section
)->this_hdr
.contents
;
1908 else if (section
->size
!= 0)
1910 /* Go get them off disk. */
1911 if (!bfd_malloc_and_get_section (input_bfd
, section
,
1918 /* If there aren't any relocs, then there's nothing to do. */
1919 if ((section
->flags
& SEC_RELOC
) != 0
1920 && section
->reloc_count
!= 0)
1922 /* Get a copy of the native relocations. */
1923 internal_relocs
= _bfd_elf_link_read_relocs (input_bfd
, section
,
1925 link_info
->keep_memory
);
1926 if (internal_relocs
== NULL
)
1929 /* Now examine each relocation. */
1930 irel
= internal_relocs
;
1931 irelend
= irel
+ section
->reloc_count
;
1932 for (; irel
< irelend
; irel
++)
1935 unsigned long r_index
;
1938 r_type
= ELF32_R_TYPE (irel
->r_info
);
1939 r_index
= ELF32_R_SYM (irel
->r_info
);
1941 if (r_type
< 0 || r_type
>= (int) R_MN10300_MAX
)
1944 /* We need the name and hash table entry of the target
1950 if (r_index
< symtab_hdr
->sh_info
)
1952 /* A local symbol. */
1953 Elf_Internal_Sym
*isym
;
1954 struct elf_link_hash_table
*elftab
;
1957 isym
= isymbuf
+ r_index
;
1958 if (isym
->st_shndx
== SHN_UNDEF
)
1959 sym_sec
= bfd_und_section_ptr
;
1960 else if (isym
->st_shndx
== SHN_ABS
)
1961 sym_sec
= bfd_abs_section_ptr
;
1962 else if (isym
->st_shndx
== SHN_COMMON
)
1963 sym_sec
= bfd_com_section_ptr
;
1966 = bfd_section_from_elf_index (input_bfd
,
1970 = bfd_elf_string_from_elf_section (input_bfd
,
1975 /* If it isn't a function, then we don't care
1977 if (ELF_ST_TYPE (isym
->st_info
) != STT_FUNC
)
1980 /* Tack on an ID so we can uniquely identify this
1981 local symbol in the global hash table. */
1982 amt
= strlen (sym_name
) + 10;
1983 new_name
= bfd_malloc (amt
);
1987 sprintf (new_name
, "%s_%08x", sym_name
, sym_sec
->id
);
1988 sym_name
= new_name
;
1990 elftab
= &hash_table
->static_hash_table
->root
;
1991 hash
= ((struct elf32_mn10300_link_hash_entry
*)
1992 elf_link_hash_lookup (elftab
, sym_name
,
1993 TRUE
, TRUE
, FALSE
));
1998 r_index
-= symtab_hdr
->sh_info
;
1999 hash
= (struct elf32_mn10300_link_hash_entry
*)
2000 elf_sym_hashes (input_bfd
)[r_index
];
2003 sym_name
= hash
->root
.root
.root
.string
;
2004 if ((section
->flags
& SEC_CODE
) != 0)
2006 /* If this is not a "call" instruction, then we
2007 should convert "call" instructions to "calls"
2009 code
= bfd_get_8 (input_bfd
,
2010 contents
+ irel
->r_offset
- 1);
2011 if (code
!= 0xdd && code
!= 0xcd)
2012 hash
->flags
|= MN10300_CONVERT_CALL_TO_CALLS
;
2015 /* If this is a jump/call, then bump the
2016 direct_calls counter. Else force "call" to
2017 "calls" conversions. */
2018 if (r_type
== R_MN10300_PCREL32
2019 || r_type
== R_MN10300_PLT32
2020 || r_type
== R_MN10300_PLT16
2021 || r_type
== R_MN10300_PCREL16
)
2022 hash
->direct_calls
++;
2024 hash
->flags
|= MN10300_CONVERT_CALL_TO_CALLS
;
2028 /* Now look at the actual contents to get the stack size,
2029 and a list of what registers were saved in the prologue
2031 if ((section
->flags
& SEC_CODE
) != 0)
2033 Elf_Internal_Sym
*isym
, *isymend
;
2034 unsigned int sec_shndx
;
2035 struct elf_link_hash_entry
**hashes
;
2036 struct elf_link_hash_entry
**end_hashes
;
2037 unsigned int symcount
;
2039 sec_shndx
= _bfd_elf_section_from_bfd_section (input_bfd
,
2042 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2043 - symtab_hdr
->sh_info
);
2044 hashes
= elf_sym_hashes (input_bfd
);
2045 end_hashes
= hashes
+ symcount
;
2047 /* Look at each function defined in this section and
2048 update info for that function. */
2049 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2050 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2052 if (isym
->st_shndx
== sec_shndx
2053 && ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
)
2055 struct elf_link_hash_table
*elftab
;
2057 struct elf_link_hash_entry
**lhashes
= hashes
;
2059 /* Skip a local symbol if it aliases a
2061 for (; lhashes
< end_hashes
; lhashes
++)
2063 hash
= (struct elf32_mn10300_link_hash_entry
*) *lhashes
;
2064 if ((hash
->root
.root
.type
== bfd_link_hash_defined
2065 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
2066 && hash
->root
.root
.u
.def
.section
== section
2067 && hash
->root
.type
== STT_FUNC
2068 && hash
->root
.root
.u
.def
.value
== isym
->st_value
)
2071 if (lhashes
!= end_hashes
)
2074 if (isym
->st_shndx
== SHN_UNDEF
)
2075 sym_sec
= bfd_und_section_ptr
;
2076 else if (isym
->st_shndx
== SHN_ABS
)
2077 sym_sec
= bfd_abs_section_ptr
;
2078 else if (isym
->st_shndx
== SHN_COMMON
)
2079 sym_sec
= bfd_com_section_ptr
;
2082 = bfd_section_from_elf_index (input_bfd
,
2085 sym_name
= (bfd_elf_string_from_elf_section
2086 (input_bfd
, symtab_hdr
->sh_link
,
2089 /* Tack on an ID so we can uniquely identify this
2090 local symbol in the global hash table. */
2091 amt
= strlen (sym_name
) + 10;
2092 new_name
= bfd_malloc (amt
);
2096 sprintf (new_name
, "%s_%08x", sym_name
, sym_sec
->id
);
2097 sym_name
= new_name
;
2099 elftab
= &hash_table
->static_hash_table
->root
;
2100 hash
= ((struct elf32_mn10300_link_hash_entry
*)
2101 elf_link_hash_lookup (elftab
, sym_name
,
2102 TRUE
, TRUE
, FALSE
));
2104 compute_function_info (input_bfd
, hash
,
2105 isym
->st_value
, contents
);
2106 hash
->value
= isym
->st_value
;
2110 for (; hashes
< end_hashes
; hashes
++)
2112 hash
= (struct elf32_mn10300_link_hash_entry
*) *hashes
;
2113 if ((hash
->root
.root
.type
== bfd_link_hash_defined
2114 || hash
->root
.root
.type
== bfd_link_hash_defweak
)
2115 && hash
->root
.root
.u
.def
.section
== section
2116 && hash
->root
.type
== STT_FUNC
)
2117 compute_function_info (input_bfd
, hash
,
2118 (hash
)->root
.root
.u
.def
.value
,
2123 /* Cache or free any memory we allocated for the relocs. */
2124 if (internal_relocs
!= NULL
2125 && elf_section_data (section
)->relocs
!= internal_relocs
)
2126 free (internal_relocs
);
2127 internal_relocs
= NULL
;
2129 /* Cache or free any memory we allocated for the contents. */
2130 if (contents
!= NULL
2131 && elf_section_data (section
)->this_hdr
.contents
!= contents
)
2133 if (! link_info
->keep_memory
)
2137 /* Cache the section contents for elf_link_input_bfd. */
2138 elf_section_data (section
)->this_hdr
.contents
= contents
;
2144 /* Cache or free any memory we allocated for the symbols. */
2146 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2148 if (! link_info
->keep_memory
)
2152 /* Cache the symbols for elf_link_input_bfd. */
2153 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2159 /* Now iterate on each symbol in the hash table and perform
2160 the final initialization steps on each. */
2161 elf32_mn10300_link_hash_traverse (hash_table
,
2162 elf32_mn10300_finish_hash_table_entry
,
2164 elf32_mn10300_link_hash_traverse (hash_table
->static_hash_table
,
2165 elf32_mn10300_finish_hash_table_entry
,
2169 /* This section of code collects all our local symbols, sorts
2170 them by value, and looks for multiple symbols referring to
2171 the same address. For those symbols, the flags are merged.
2172 At this point, the only flag that can be set is
2173 MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
2175 int static_count
= 0, i
;
2176 struct elf32_mn10300_link_hash_entry
**entries
;
2177 struct elf32_mn10300_link_hash_entry
**ptr
;
2179 elf32_mn10300_link_hash_traverse (hash_table
->static_hash_table
,
2180 elf32_mn10300_count_hash_table_entries
,
2183 entries
= bfd_malloc (static_count
* sizeof (* ptr
));
2186 elf32_mn10300_link_hash_traverse (hash_table
->static_hash_table
,
2187 elf32_mn10300_list_hash_table_entries
,
2190 qsort (entries
, static_count
, sizeof (entries
[0]), sort_by_value
);
2192 for (i
= 0; i
< static_count
- 1; i
++)
2193 if (entries
[i
]->value
&& entries
[i
]->value
== entries
[i
+1]->value
)
2195 int v
= entries
[i
]->flags
;
2198 for (j
= i
+ 1; j
< static_count
&& entries
[j
]->value
== entries
[i
]->value
; j
++)
2199 v
|= entries
[j
]->flags
;
2201 for (j
= i
; j
< static_count
&& entries
[j
]->value
== entries
[i
]->value
; j
++)
2202 entries
[j
]->flags
= v
;
2208 /* All entries in the hash table are fully initialized. */
2209 hash_table
->flags
|= MN10300_HASH_ENTRIES_INITIALIZED
;
2211 /* Now that everything has been initialized, go through each
2212 code section and delete any prologue insns which will be
2213 redundant because their operations will be performed by
2214 a "call" instruction. */
2215 for (input_bfd
= link_info
->input_bfds
;
2217 input_bfd
= input_bfd
->link_next
)
2219 /* We're going to need all the local symbols for each bfd. */
2220 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2221 if (symtab_hdr
->sh_info
!= 0)
2223 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2224 if (isymbuf
== NULL
)
2225 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
2226 symtab_hdr
->sh_info
, 0,
2228 if (isymbuf
== NULL
)
2232 /* Walk over each section in this bfd. */
2233 for (section
= input_bfd
->sections
;
2235 section
= section
->next
)
2237 unsigned int sec_shndx
;
2238 Elf_Internal_Sym
*isym
, *isymend
;
2239 struct elf_link_hash_entry
**hashes
;
2240 struct elf_link_hash_entry
**end_hashes
;
2241 unsigned int symcount
;
2243 /* Skip non-code sections and empty sections. */
2244 if ((section
->flags
& SEC_CODE
) == 0 || section
->size
== 0)
2247 if (section
->reloc_count
!= 0)
2249 /* Get a copy of the native relocations. */
2250 internal_relocs
= _bfd_elf_link_read_relocs (input_bfd
, section
,
2252 link_info
->keep_memory
);
2253 if (internal_relocs
== NULL
)
2257 /* Get cached copy of section contents if it exists. */
2258 if (elf_section_data (section
)->this_hdr
.contents
!= NULL
)
2259 contents
= elf_section_data (section
)->this_hdr
.contents
;
2262 /* Go get them off disk. */
2263 if (!bfd_malloc_and_get_section (input_bfd
, section
,
2268 sec_shndx
= _bfd_elf_section_from_bfd_section (input_bfd
,
2271 /* Now look for any function in this section which needs
2272 insns deleted from its prologue. */
2273 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2274 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2276 struct elf32_mn10300_link_hash_entry
*sym_hash
;
2277 asection
*sym_sec
= NULL
;
2278 const char *sym_name
;
2280 struct elf_link_hash_table
*elftab
;
2283 if (isym
->st_shndx
!= sec_shndx
)
2286 if (isym
->st_shndx
== SHN_UNDEF
)
2287 sym_sec
= bfd_und_section_ptr
;
2288 else if (isym
->st_shndx
== SHN_ABS
)
2289 sym_sec
= bfd_abs_section_ptr
;
2290 else if (isym
->st_shndx
== SHN_COMMON
)
2291 sym_sec
= bfd_com_section_ptr
;
2294 = bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
2297 = bfd_elf_string_from_elf_section (input_bfd
,
2298 symtab_hdr
->sh_link
,
2301 /* Tack on an ID so we can uniquely identify this
2302 local symbol in the global hash table. */
2303 amt
= strlen (sym_name
) + 10;
2304 new_name
= bfd_malloc (amt
);
2307 sprintf (new_name
, "%s_%08x", sym_name
, sym_sec
->id
);
2308 sym_name
= new_name
;
2310 elftab
= & hash_table
->static_hash_table
->root
;
2311 sym_hash
= (struct elf32_mn10300_link_hash_entry
*)
2312 elf_link_hash_lookup (elftab
, sym_name
,
2313 FALSE
, FALSE
, FALSE
);
2316 if (sym_hash
== NULL
)
2319 if (! (sym_hash
->flags
& MN10300_CONVERT_CALL_TO_CALLS
)
2320 && ! (sym_hash
->flags
& MN10300_DELETED_PROLOGUE_BYTES
))
2324 /* Note that we've changed things. */
2325 elf_section_data (section
)->relocs
= internal_relocs
;
2326 elf_section_data (section
)->this_hdr
.contents
= contents
;
2327 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2329 /* Count how many bytes we're going to delete. */
2330 if (sym_hash
->movm_args
)
2333 if (sym_hash
->stack_size
> 0)
2335 if (sym_hash
->stack_size
<= 128)
2341 /* Note that we've deleted prologue bytes for this
2343 sym_hash
->flags
|= MN10300_DELETED_PROLOGUE_BYTES
;
2345 /* Actually delete the bytes. */
2346 if (!mn10300_elf_relax_delete_bytes (input_bfd
,
2352 /* Something changed. Not strictly necessary, but
2353 may lead to more relaxing opportunities. */
2358 /* Look for any global functions in this section which
2359 need insns deleted from their prologues. */
2360 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2361 - symtab_hdr
->sh_info
);
2362 hashes
= elf_sym_hashes (input_bfd
);
2363 end_hashes
= hashes
+ symcount
;
2364 for (; hashes
< end_hashes
; hashes
++)
2366 struct elf32_mn10300_link_hash_entry
*sym_hash
;
2368 sym_hash
= (struct elf32_mn10300_link_hash_entry
*) *hashes
;
2369 if ((sym_hash
->root
.root
.type
== bfd_link_hash_defined
2370 || sym_hash
->root
.root
.type
== bfd_link_hash_defweak
)
2371 && sym_hash
->root
.root
.u
.def
.section
== section
2372 && ! (sym_hash
->flags
& MN10300_CONVERT_CALL_TO_CALLS
)
2373 && ! (sym_hash
->flags
& MN10300_DELETED_PROLOGUE_BYTES
))
2378 /* Note that we've changed things. */
2379 elf_section_data (section
)->relocs
= internal_relocs
;
2380 elf_section_data (section
)->this_hdr
.contents
= contents
;
2381 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2383 /* Count how many bytes we're going to delete. */
2384 if (sym_hash
->movm_args
)
2387 if (sym_hash
->stack_size
> 0)
2389 if (sym_hash
->stack_size
<= 128)
2395 /* Note that we've deleted prologue bytes for this
2397 sym_hash
->flags
|= MN10300_DELETED_PROLOGUE_BYTES
;
2399 /* Actually delete the bytes. */
2400 symval
= sym_hash
->root
.root
.u
.def
.value
;
2401 if (!mn10300_elf_relax_delete_bytes (input_bfd
,
2407 /* Something changed. Not strictly necessary, but
2408 may lead to more relaxing opportunities. */
2413 /* Cache or free any memory we allocated for the relocs. */
2414 if (internal_relocs
!= NULL
2415 && elf_section_data (section
)->relocs
!= internal_relocs
)
2416 free (internal_relocs
);
2417 internal_relocs
= NULL
;
2419 /* Cache or free any memory we allocated for the contents. */
2420 if (contents
!= NULL
2421 && elf_section_data (section
)->this_hdr
.contents
!= contents
)
2423 if (! link_info
->keep_memory
)
2426 /* Cache the section contents for elf_link_input_bfd. */
2427 elf_section_data (section
)->this_hdr
.contents
= contents
;
2432 /* Cache or free any memory we allocated for the symbols. */
2434 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2436 if (! link_info
->keep_memory
)
2439 /* Cache the symbols for elf_link_input_bfd. */
2440 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2446 /* (Re)initialize for the basic instruction shortening/relaxing pass. */
2448 internal_relocs
= NULL
;
2450 /* For error_return. */
2453 /* We don't have to do anything for a relocatable link, if
2454 this section does not have relocs, or if this is not a
2456 if (link_info
->relocatable
2457 || (sec
->flags
& SEC_RELOC
) == 0
2458 || sec
->reloc_count
== 0
2459 || (sec
->flags
& SEC_CODE
) == 0)
2462 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2464 /* Get a copy of the native relocations. */
2465 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
2466 link_info
->keep_memory
);
2467 if (internal_relocs
== NULL
)
2470 /* Walk through them looking for relaxing opportunities. */
2471 irelend
= internal_relocs
+ sec
->reloc_count
;
2472 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2475 struct elf32_mn10300_link_hash_entry
*h
= NULL
;
2477 /* If this isn't something that can be relaxed, then ignore
2479 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_NONE
2480 || ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_8
2481 || ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_MAX
)
2484 /* Get the section contents if we haven't done so already. */
2485 if (contents
== NULL
)
2487 /* Get cached copy if it exists. */
2488 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2489 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2492 /* Go get them off disk. */
2493 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
2498 /* Read this BFD's symbols if we haven't done so already. */
2499 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2501 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2502 if (isymbuf
== NULL
)
2503 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2504 symtab_hdr
->sh_info
, 0,
2506 if (isymbuf
== NULL
)
2510 /* Get the value of the symbol referred to by the reloc. */
2511 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2513 Elf_Internal_Sym
*isym
;
2514 asection
*sym_sec
= NULL
;
2515 const char *sym_name
;
2517 bfd_vma saved_addend
;
2519 /* A local symbol. */
2520 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2521 if (isym
->st_shndx
== SHN_UNDEF
)
2522 sym_sec
= bfd_und_section_ptr
;
2523 else if (isym
->st_shndx
== SHN_ABS
)
2524 sym_sec
= bfd_abs_section_ptr
;
2525 else if (isym
->st_shndx
== SHN_COMMON
)
2526 sym_sec
= bfd_com_section_ptr
;
2528 sym_sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
2530 sym_name
= bfd_elf_string_from_elf_section (abfd
,
2531 symtab_hdr
->sh_link
,
2534 if ((sym_sec
->flags
& SEC_MERGE
)
2535 && ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
2536 && sym_sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
2538 saved_addend
= irel
->r_addend
;
2539 symval
= _bfd_elf_rela_local_sym (abfd
, isym
, &sym_sec
, irel
);
2540 symval
+= irel
->r_addend
;
2541 irel
->r_addend
= saved_addend
;
2545 symval
= (isym
->st_value
2546 + sym_sec
->output_section
->vma
2547 + sym_sec
->output_offset
);
2550 /* Tack on an ID so we can uniquely identify this
2551 local symbol in the global hash table. */
2552 new_name
= bfd_malloc ((bfd_size_type
) strlen (sym_name
) + 10);
2555 sprintf (new_name
, "%s_%08x", sym_name
, sym_sec
->id
);
2556 sym_name
= new_name
;
2558 h
= (struct elf32_mn10300_link_hash_entry
*)
2559 elf_link_hash_lookup (&hash_table
->static_hash_table
->root
,
2560 sym_name
, FALSE
, FALSE
, FALSE
);
2567 /* An external symbol. */
2568 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
2569 h
= (struct elf32_mn10300_link_hash_entry
*)
2570 (elf_sym_hashes (abfd
)[indx
]);
2571 BFD_ASSERT (h
!= NULL
);
2572 if (h
->root
.root
.type
!= bfd_link_hash_defined
2573 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2574 /* This appears to be a reference to an undefined
2575 symbol. Just ignore it--it will be caught by the
2576 regular reloc processing. */
2579 symval
= (h
->root
.root
.u
.def
.value
2580 + h
->root
.root
.u
.def
.section
->output_section
->vma
2581 + h
->root
.root
.u
.def
.section
->output_offset
);
2584 /* For simplicity of coding, we are going to modify the section
2585 contents, the section relocs, and the BFD symbol table. We
2586 must tell the rest of the code not to free up this
2587 information. It would be possible to instead create a table
2588 of changes which have to be made, as is done in coff-mips.c;
2589 that would be more work, but would require less memory when
2590 the linker is run. */
2592 /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
2593 branch/call, also deal with "call" -> "calls" conversions and
2594 insertion of prologue data into "call" instructions. */
2595 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_PCREL32
2596 || ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_PLT32
)
2598 bfd_vma value
= symval
;
2600 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_PLT32
2602 && ELF_ST_VISIBILITY (h
->root
.other
) != STV_INTERNAL
2603 && ELF_ST_VISIBILITY (h
->root
.other
) != STV_HIDDEN
2604 && h
->root
.plt
.offset
!= (bfd_vma
) -1)
2608 splt
= bfd_get_section_by_name (elf_hash_table (link_info
)
2611 value
= ((splt
->output_section
->vma
2612 + splt
->output_offset
2613 + h
->root
.plt
.offset
)
2614 - (sec
->output_section
->vma
2615 + sec
->output_offset
2619 /* If we've got a "call" instruction that needs to be turned
2620 into a "calls" instruction, do so now. It saves a byte. */
2621 if (h
&& (h
->flags
& MN10300_CONVERT_CALL_TO_CALLS
))
2625 /* Get the opcode. */
2626 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2628 /* Make sure we're working with a "call" instruction! */
2631 /* Note that we've changed the relocs, section contents,
2633 elf_section_data (sec
)->relocs
= internal_relocs
;
2634 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2635 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2637 /* Fix the opcode. */
2638 bfd_put_8 (abfd
, 0xfc, contents
+ irel
->r_offset
- 1);
2639 bfd_put_8 (abfd
, 0xff, contents
+ irel
->r_offset
);
2641 /* Fix irel->r_offset and irel->r_addend. */
2642 irel
->r_offset
+= 1;
2643 irel
->r_addend
+= 1;
2645 /* Delete one byte of data. */
2646 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
2647 irel
->r_offset
+ 3, 1))
2650 /* That will change things, so, we should relax again.
2651 Note that this is not required, and it may be slow. */
2657 /* We've got a "call" instruction which needs some data
2658 from target function filled in. */
2661 /* Get the opcode. */
2662 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2664 /* Insert data from the target function into the "call"
2665 instruction if needed. */
2668 bfd_put_8 (abfd
, h
->movm_args
, contents
+ irel
->r_offset
+ 4);
2669 bfd_put_8 (abfd
, h
->stack_size
+ h
->movm_stack_size
,
2670 contents
+ irel
->r_offset
+ 5);
2674 /* Deal with pc-relative gunk. */
2675 value
-= (sec
->output_section
->vma
+ sec
->output_offset
);
2676 value
-= irel
->r_offset
;
2677 value
+= irel
->r_addend
;
2679 /* See if the value will fit in 16 bits, note the high value is
2680 0x7fff + 2 as the target will be two bytes closer if we are
2682 if ((long) value
< 0x8001 && (long) value
> -0x8000)
2686 /* Get the opcode. */
2687 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2689 if (code
!= 0xdc && code
!= 0xdd && code
!= 0xff)
2692 /* Note that we've changed the relocs, section contents, etc. */
2693 elf_section_data (sec
)->relocs
= internal_relocs
;
2694 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2695 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2697 /* Fix the opcode. */
2699 bfd_put_8 (abfd
, 0xcc, contents
+ irel
->r_offset
- 1);
2700 else if (code
== 0xdd)
2701 bfd_put_8 (abfd
, 0xcd, contents
+ irel
->r_offset
- 1);
2702 else if (code
== 0xff)
2703 bfd_put_8 (abfd
, 0xfa, contents
+ irel
->r_offset
- 2);
2705 /* Fix the relocation's type. */
2706 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2707 (ELF32_R_TYPE (irel
->r_info
)
2708 == (int) R_MN10300_PLT32
)
2712 /* Delete two bytes of data. */
2713 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
2714 irel
->r_offset
+ 1, 2))
2717 /* That will change things, so, we should relax again.
2718 Note that this is not required, and it may be slow. */
2723 /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
2725 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_PCREL16
)
2727 bfd_vma value
= symval
;
2729 /* If we've got a "call" instruction that needs to be turned
2730 into a "calls" instruction, do so now. It saves a byte. */
2731 if (h
&& (h
->flags
& MN10300_CONVERT_CALL_TO_CALLS
))
2735 /* Get the opcode. */
2736 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2738 /* Make sure we're working with a "call" instruction! */
2741 /* Note that we've changed the relocs, section contents,
2743 elf_section_data (sec
)->relocs
= internal_relocs
;
2744 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2745 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2747 /* Fix the opcode. */
2748 bfd_put_8 (abfd
, 0xfa, contents
+ irel
->r_offset
- 1);
2749 bfd_put_8 (abfd
, 0xff, contents
+ irel
->r_offset
);
2751 /* Fix irel->r_offset and irel->r_addend. */
2752 irel
->r_offset
+= 1;
2753 irel
->r_addend
+= 1;
2755 /* Delete one byte of data. */
2756 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
2757 irel
->r_offset
+ 1, 1))
2760 /* That will change things, so, we should relax again.
2761 Note that this is not required, and it may be slow. */
2769 /* Get the opcode. */
2770 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2772 /* Insert data from the target function into the "call"
2773 instruction if needed. */
2776 bfd_put_8 (abfd
, h
->movm_args
, contents
+ irel
->r_offset
+ 2);
2777 bfd_put_8 (abfd
, h
->stack_size
+ h
->movm_stack_size
,
2778 contents
+ irel
->r_offset
+ 3);
2782 /* Deal with pc-relative gunk. */
2783 value
-= (sec
->output_section
->vma
+ sec
->output_offset
);
2784 value
-= irel
->r_offset
;
2785 value
+= irel
->r_addend
;
2787 /* See if the value will fit in 8 bits, note the high value is
2788 0x7f + 1 as the target will be one bytes closer if we are
2790 if ((long) value
< 0x80 && (long) value
> -0x80)
2794 /* Get the opcode. */
2795 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2800 /* Note that we've changed the relocs, section contents, etc. */
2801 elf_section_data (sec
)->relocs
= internal_relocs
;
2802 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2803 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2805 /* Fix the opcode. */
2806 bfd_put_8 (abfd
, 0xca, contents
+ irel
->r_offset
- 1);
2808 /* Fix the relocation's type. */
2809 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2812 /* Delete one byte of data. */
2813 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
2814 irel
->r_offset
+ 1, 1))
2817 /* That will change things, so, we should relax again.
2818 Note that this is not required, and it may be slow. */
2823 /* Try to eliminate an unconditional 8 bit pc-relative branch
2824 which immediately follows a conditional 8 bit pc-relative
2825 branch around the unconditional branch.
2832 This happens when the bCC can't reach lab2 at assembly time,
2833 but due to other relaxations it can reach at link time. */
2834 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_PCREL8
)
2836 Elf_Internal_Rela
*nrel
;
2837 bfd_vma value
= symval
;
2840 /* Deal with pc-relative gunk. */
2841 value
-= (sec
->output_section
->vma
+ sec
->output_offset
);
2842 value
-= irel
->r_offset
;
2843 value
+= irel
->r_addend
;
2845 /* Do nothing if this reloc is the last byte in the section. */
2846 if (irel
->r_offset
== sec
->size
)
2849 /* See if the next instruction is an unconditional pc-relative
2850 branch, more often than not this test will fail, so we
2851 test it first to speed things up. */
2852 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ 1);
2856 /* Also make sure the next relocation applies to the next
2857 instruction and that it's a pc-relative 8 bit branch. */
2860 || irel
->r_offset
+ 2 != nrel
->r_offset
2861 || ELF32_R_TYPE (nrel
->r_info
) != (int) R_MN10300_PCREL8
)
2864 /* Make sure our destination immediately follows the
2865 unconditional branch. */
2866 if (symval
!= (sec
->output_section
->vma
+ sec
->output_offset
2867 + irel
->r_offset
+ 3))
2870 /* Now make sure we are a conditional branch. This may not
2871 be necessary, but why take the chance.
2873 Note these checks assume that R_MN10300_PCREL8 relocs
2874 only occur on bCC and bCCx insns. If they occured
2875 elsewhere, we'd need to know the start of this insn
2876 for this check to be accurate. */
2877 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
2878 if (code
!= 0xc0 && code
!= 0xc1 && code
!= 0xc2
2879 && code
!= 0xc3 && code
!= 0xc4 && code
!= 0xc5
2880 && code
!= 0xc6 && code
!= 0xc7 && code
!= 0xc8
2881 && code
!= 0xc9 && code
!= 0xe8 && code
!= 0xe9
2882 && code
!= 0xea && code
!= 0xeb)
2885 /* We also have to be sure there is no symbol/label
2886 at the unconditional branch. */
2887 if (mn10300_elf_symbol_address_p (abfd
, sec
, isymbuf
,
2888 irel
->r_offset
+ 1))
2891 /* Note that we've changed the relocs, section contents, etc. */
2892 elf_section_data (sec
)->relocs
= internal_relocs
;
2893 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2894 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2896 /* Reverse the condition of the first branch. */
2942 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 1);
2944 /* Set the reloc type and symbol for the first branch
2945 from the second branch. */
2946 irel
->r_info
= nrel
->r_info
;
2948 /* Make the reloc for the second branch a null reloc. */
2949 nrel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (nrel
->r_info
),
2952 /* Delete two bytes of data. */
2953 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
2954 irel
->r_offset
+ 1, 2))
2957 /* That will change things, so, we should relax again.
2958 Note that this is not required, and it may be slow. */
2962 /* Try to turn a 24 immediate, displacement or absolute address
2963 into a 8 immediate, displacement or absolute address. */
2964 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_24
)
2966 bfd_vma value
= symval
;
2967 value
+= irel
->r_addend
;
2969 /* See if the value will fit in 8 bits. */
2970 if ((long) value
< 0x7f && (long) value
> -0x80)
2974 /* AM33 insns which have 24 operands are 6 bytes long and
2975 will have 0xfd as the first byte. */
2977 /* Get the first opcode. */
2978 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 3);
2982 /* Get the second opcode. */
2983 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2);
2985 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2986 equivalent instructions exists. */
2987 if (code
!= 0x6b && code
!= 0x7b
2988 && code
!= 0x8b && code
!= 0x9b
2989 && ((code
& 0x0f) == 0x09 || (code
& 0x0f) == 0x08
2990 || (code
& 0x0f) == 0x0a || (code
& 0x0f) == 0x0b
2991 || (code
& 0x0f) == 0x0e))
2993 /* Not safe if the high bit is on as relaxing may
2994 move the value out of high mem and thus not fit
2995 in a signed 8bit value. This is currently over
2997 if ((value
& 0x80) == 0)
2999 /* Note that we've changed the relocation contents,
3001 elf_section_data (sec
)->relocs
= internal_relocs
;
3002 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3003 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3005 /* Fix the opcode. */
3006 bfd_put_8 (abfd
, 0xfb, contents
+ irel
->r_offset
- 3);
3007 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 2);
3009 /* Fix the relocation's type. */
3011 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3014 /* Delete two bytes of data. */
3015 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3016 irel
->r_offset
+ 1, 2))
3019 /* That will change things, so, we should relax
3020 again. Note that this is not required, and it
3030 /* Try to turn a 32bit immediate, displacement or absolute address
3031 into a 16bit immediate, displacement or absolute address. */
3032 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_32
3033 || ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_GOT32
3034 || ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_GOTOFF32
)
3036 bfd_vma value
= symval
;
3038 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_MN10300_32
)
3042 sgot
= bfd_get_section_by_name (elf_hash_table (link_info
)
3045 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_GOT32
)
3047 value
= sgot
->output_offset
;
3050 value
+= h
->root
.got
.offset
;
3052 value
+= (elf_local_got_offsets
3053 (abfd
)[ELF32_R_SYM (irel
->r_info
)]);
3055 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_GOTOFF32
)
3056 value
-= sgot
->output_section
->vma
;
3057 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_MN10300_GOTPC32
)
3058 value
= (sgot
->output_section
->vma
3059 - (sec
->output_section
->vma
3060 + sec
->output_offset
3066 value
+= irel
->r_addend
;
3068 /* See if the value will fit in 24 bits.
3069 We allow any 16bit match here. We prune those we can't
3071 if ((long) value
< 0x7fffff && (long) value
> -0x800000)
3075 /* AM33 insns which have 32bit operands are 7 bytes long and
3076 will have 0xfe as the first byte. */
3078 /* Get the first opcode. */
3079 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 3);
3083 /* Get the second opcode. */
3084 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2);
3086 /* All the am33 32 -> 24 relaxing possibilities. */
3087 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
3088 equivalent instructions exists. */
3089 if (code
!= 0x6b && code
!= 0x7b
3090 && code
!= 0x8b && code
!= 0x9b
3091 && (ELF32_R_TYPE (irel
->r_info
)
3092 != (int) R_MN10300_GOTPC32
)
3093 && ((code
& 0x0f) == 0x09 || (code
& 0x0f) == 0x08
3094 || (code
& 0x0f) == 0x0a || (code
& 0x0f) == 0x0b
3095 || (code
& 0x0f) == 0x0e))
3097 /* Not safe if the high bit is on as relaxing may
3098 move the value out of high mem and thus not fit
3099 in a signed 16bit value. This is currently over
3101 if ((value
& 0x8000) == 0)
3103 /* Note that we've changed the relocation contents,
3105 elf_section_data (sec
)->relocs
= internal_relocs
;
3106 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3107 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3109 /* Fix the opcode. */
3110 bfd_put_8 (abfd
, 0xfd, contents
+ irel
->r_offset
- 3);
3111 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 2);
3113 /* Fix the relocation's type. */
3115 ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3116 (ELF32_R_TYPE (irel
->r_info
)
3117 == (int) R_MN10300_GOTOFF32
)
3118 ? R_MN10300_GOTOFF24
3119 : (ELF32_R_TYPE (irel
->r_info
)
3120 == (int) R_MN10300_GOT32
)
3124 /* Delete one byte of data. */
3125 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3126 irel
->r_offset
+ 3, 1))
3129 /* That will change things, so, we should relax
3130 again. Note that this is not required, and it
3139 /* See if the value will fit in 16 bits.
3140 We allow any 16bit match here. We prune those we can't
3142 if ((long) value
< 0x7fff && (long) value
> -0x8000)
3146 /* Most insns which have 32bit operands are 6 bytes long;
3147 exceptions are pcrel insns and bit insns.
3149 We handle pcrel insns above. We don't bother trying
3150 to handle the bit insns here.
3152 The first byte of the remaining insns will be 0xfc. */
3154 /* Get the first opcode. */
3155 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 2);
3160 /* Get the second opcode. */
3161 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
3163 if ((code
& 0xf0) < 0x80)
3164 switch (code
& 0xf0)
3166 /* mov (d32,am),dn -> mov (d32,am),dn
3167 mov dm,(d32,am) -> mov dn,(d32,am)
3168 mov (d32,am),an -> mov (d32,am),an
3169 mov dm,(d32,am) -> mov dn,(d32,am)
3170 movbu (d32,am),dn -> movbu (d32,am),dn
3171 movbu dm,(d32,am) -> movbu dn,(d32,am)
3172 movhu (d32,am),dn -> movhu (d32,am),dn
3173 movhu dm,(d32,am) -> movhu dn,(d32,am) */
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 /* Note that we've changed the relocation contents, etc. */
3190 elf_section_data (sec
)->relocs
= internal_relocs
;
3191 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3192 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3194 /* Fix the opcode. */
3195 bfd_put_8 (abfd
, 0xfa, contents
+ irel
->r_offset
- 2);
3196 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 1);
3198 /* Fix the relocation's type. */
3199 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3200 (ELF32_R_TYPE (irel
->r_info
)
3201 == (int) R_MN10300_GOTOFF32
)
3202 ? R_MN10300_GOTOFF16
3203 : (ELF32_R_TYPE (irel
->r_info
)
3204 == (int) R_MN10300_GOT32
)
3206 : (ELF32_R_TYPE (irel
->r_info
)
3207 == (int) R_MN10300_GOTPC32
)
3208 ? R_MN10300_GOTPC16
:
3211 /* Delete two bytes of data. */
3212 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3213 irel
->r_offset
+ 2, 2))
3216 /* That will change things, so, we should relax again.
3217 Note that this is not required, and it may be slow. */
3221 else if ((code
& 0xf0) == 0x80
3222 || (code
& 0xf0) == 0x90)
3223 switch (code
& 0xf3)
3225 /* mov dn,(abs32) -> mov dn,(abs16)
3226 movbu dn,(abs32) -> movbu dn,(abs16)
3227 movhu dn,(abs32) -> movhu dn,(abs16) */
3231 /* Note that we've changed the relocation contents, etc. */
3232 elf_section_data (sec
)->relocs
= internal_relocs
;
3233 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3234 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3236 if ((code
& 0xf3) == 0x81)
3237 code
= 0x01 + (code
& 0x0c);
3238 else if ((code
& 0xf3) == 0x82)
3239 code
= 0x02 + (code
& 0x0c);
3240 else if ((code
& 0xf3) == 0x83)
3241 code
= 0x03 + (code
& 0x0c);
3245 /* Fix the opcode. */
3246 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 2);
3248 /* Fix the relocation's type. */
3249 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3250 (ELF32_R_TYPE (irel
->r_info
)
3251 == (int) R_MN10300_GOTOFF32
)
3252 ? R_MN10300_GOTOFF16
3253 : (ELF32_R_TYPE (irel
->r_info
)
3254 == (int) R_MN10300_GOT32
)
3256 : (ELF32_R_TYPE (irel
->r_info
)
3257 == (int) R_MN10300_GOTPC32
)
3258 ? R_MN10300_GOTPC16
:
3261 /* The opcode got shorter too, so we have to fix the
3262 addend and offset too! */
3263 irel
->r_offset
-= 1;
3265 /* Delete three bytes of data. */
3266 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3267 irel
->r_offset
+ 1, 3))
3270 /* That will change things, so, we should relax again.
3271 Note that this is not required, and it may be slow. */
3275 /* mov am,(abs32) -> mov am,(abs16)
3276 mov am,(d32,sp) -> mov am,(d16,sp)
3277 mov dm,(d32,sp) -> mov dm,(d32,sp)
3278 movbu dm,(d32,sp) -> movbu dm,(d32,sp)
3279 movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
3285 /* sp-based offsets are zero-extended. */
3286 if (code
>= 0x90 && code
<= 0x93
3290 /* Note that we've changed the relocation contents, etc. */
3291 elf_section_data (sec
)->relocs
= internal_relocs
;
3292 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3293 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3295 /* Fix the opcode. */
3296 bfd_put_8 (abfd
, 0xfa, contents
+ irel
->r_offset
- 2);
3297 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 1);
3299 /* Fix the relocation's type. */
3300 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3301 (ELF32_R_TYPE (irel
->r_info
)
3302 == (int) R_MN10300_GOTOFF32
)
3303 ? R_MN10300_GOTOFF16
3304 : (ELF32_R_TYPE (irel
->r_info
)
3305 == (int) R_MN10300_GOT32
)
3307 : (ELF32_R_TYPE (irel
->r_info
)
3308 == (int) R_MN10300_GOTPC32
)
3309 ? R_MN10300_GOTPC16
:
3312 /* Delete two bytes of data. */
3313 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3314 irel
->r_offset
+ 2, 2))
3317 /* That will change things, so, we should relax again.
3318 Note that this is not required, and it may be slow. */
3322 else if ((code
& 0xf0) < 0xf0)
3323 switch (code
& 0xfc)
3325 /* mov imm32,dn -> mov imm16,dn
3326 mov imm32,an -> mov imm16,an
3327 mov (abs32),dn -> mov (abs16),dn
3328 movbu (abs32),dn -> movbu (abs16),dn
3329 movhu (abs32),dn -> movhu (abs16),dn */
3335 /* Not safe if the high bit is on as relaxing may
3336 move the value out of high mem and thus not fit
3337 in a signed 16bit value. */
3339 && (value
& 0x8000))
3342 /* mov imm16, an zero-extends the immediate. */
3347 /* Note that we've changed the relocation contents, etc. */
3348 elf_section_data (sec
)->relocs
= internal_relocs
;
3349 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3350 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3352 if ((code
& 0xfc) == 0xcc)
3353 code
= 0x2c + (code
& 0x03);
3354 else if ((code
& 0xfc) == 0xdc)
3355 code
= 0x24 + (code
& 0x03);
3356 else if ((code
& 0xfc) == 0xa4)
3357 code
= 0x30 + (code
& 0x03);
3358 else if ((code
& 0xfc) == 0xa8)
3359 code
= 0x34 + (code
& 0x03);
3360 else if ((code
& 0xfc) == 0xac)
3361 code
= 0x38 + (code
& 0x03);
3365 /* Fix the opcode. */
3366 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 2);
3368 /* Fix the relocation's type. */
3369 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3370 (ELF32_R_TYPE (irel
->r_info
)
3371 == (int) R_MN10300_GOTOFF32
)
3372 ? R_MN10300_GOTOFF16
3373 : (ELF32_R_TYPE (irel
->r_info
)
3374 == (int) R_MN10300_GOT32
)
3376 : (ELF32_R_TYPE (irel
->r_info
)
3377 == (int) R_MN10300_GOTPC32
)
3378 ? R_MN10300_GOTPC16
:
3381 /* The opcode got shorter too, so we have to fix the
3382 addend and offset too! */
3383 irel
->r_offset
-= 1;
3385 /* Delete three bytes of data. */
3386 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3387 irel
->r_offset
+ 1, 3))
3390 /* That will change things, so, we should relax again.
3391 Note that this is not required, and it may be slow. */
3395 /* mov (abs32),an -> mov (abs16),an
3396 mov (d32,sp),an -> mov (d16,sp),an
3397 mov (d32,sp),dn -> mov (d16,sp),dn
3398 movbu (d32,sp),dn -> movbu (d16,sp),dn
3399 movhu (d32,sp),dn -> movhu (d16,sp),dn
3400 add imm32,dn -> add imm16,dn
3401 cmp imm32,dn -> cmp imm16,dn
3402 add imm32,an -> add imm16,an
3403 cmp imm32,an -> cmp imm16,an
3404 and imm32,dn -> and imm16,dn
3405 or imm32,dn -> or imm16,dn
3406 xor imm32,dn -> xor imm16,dn
3407 btst imm32,dn -> btst imm16,dn */
3423 /* cmp imm16, an zero-extends the immediate. */
3428 /* So do sp-based offsets. */
3429 if (code
>= 0xb0 && code
<= 0xb3
3433 /* Note that we've changed the relocation contents, etc. */
3434 elf_section_data (sec
)->relocs
= internal_relocs
;
3435 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3436 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3438 /* Fix the opcode. */
3439 bfd_put_8 (abfd
, 0xfa, contents
+ irel
->r_offset
- 2);
3440 bfd_put_8 (abfd
, code
, contents
+ irel
->r_offset
- 1);
3442 /* Fix the relocation's type. */
3443 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3444 (ELF32_R_TYPE (irel
->r_info
)
3445 == (int) R_MN10300_GOTOFF32
)
3446 ? R_MN10300_GOTOFF16
3447 : (ELF32_R_TYPE (irel
->r_info
)
3448 == (int) R_MN10300_GOT32
)
3450 : (ELF32_R_TYPE (irel
->r_info
)
3451 == (int) R_MN10300_GOTPC32
)
3452 ? R_MN10300_GOTPC16
:
3455 /* Delete two bytes of data. */
3456 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3457 irel
->r_offset
+ 2, 2))
3460 /* That will change things, so, we should relax again.
3461 Note that this is not required, and it may be slow. */
3465 else if (code
== 0xfe)
3467 /* add imm32,sp -> add imm16,sp */
3469 /* Note that we've changed the relocation contents, etc. */
3470 elf_section_data (sec
)->relocs
= internal_relocs
;
3471 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3472 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3474 /* Fix the opcode. */
3475 bfd_put_8 (abfd
, 0xfa, contents
+ irel
->r_offset
- 2);
3476 bfd_put_8 (abfd
, 0xfe, contents
+ irel
->r_offset
- 1);
3478 /* Fix the relocation's type. */
3479 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
3480 (ELF32_R_TYPE (irel
->r_info
)
3481 == (int) R_MN10300_GOT32
)
3483 : (ELF32_R_TYPE (irel
->r_info
)
3484 == (int) R_MN10300_GOTOFF32
)
3485 ? R_MN10300_GOTOFF16
3486 : (ELF32_R_TYPE (irel
->r_info
)
3487 == (int) R_MN10300_GOTPC32
)
3488 ? R_MN10300_GOTPC16
:
3491 /* Delete two bytes of data. */
3492 if (!mn10300_elf_relax_delete_bytes (abfd
, sec
,
3493 irel
->r_offset
+ 2, 2))
3496 /* That will change things, so, we should relax again.
3497 Note that this is not required, and it may be slow. */
3506 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3508 if (! link_info
->keep_memory
)
3512 /* Cache the symbols for elf_link_input_bfd. */
3513 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
3517 if (contents
!= NULL
3518 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
3520 if (! link_info
->keep_memory
)
3524 /* Cache the section contents for elf_link_input_bfd. */
3525 elf_section_data (sec
)->this_hdr
.contents
= contents
;
3529 if (internal_relocs
!= NULL
3530 && elf_section_data (sec
)->relocs
!= internal_relocs
)
3531 free (internal_relocs
);
3537 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3539 if (contents
!= NULL
3540 && elf_section_data (section
)->this_hdr
.contents
!= contents
)
3542 if (internal_relocs
!= NULL
3543 && elf_section_data (section
)->relocs
!= internal_relocs
)
3544 free (internal_relocs
);
3549 /* This is a version of bfd_generic_get_relocated_section_contents
3550 which uses mn10300_elf_relocate_section. */
3553 mn10300_elf_get_relocated_section_contents (bfd
*output_bfd
,
3554 struct bfd_link_info
*link_info
,
3555 struct bfd_link_order
*link_order
,
3557 bfd_boolean relocatable
,
3560 Elf_Internal_Shdr
*symtab_hdr
;
3561 asection
*input_section
= link_order
->u
.indirect
.section
;
3562 bfd
*input_bfd
= input_section
->owner
;
3563 asection
**sections
= NULL
;
3564 Elf_Internal_Rela
*internal_relocs
= NULL
;
3565 Elf_Internal_Sym
*isymbuf
= NULL
;
3567 /* We only need to handle the case of relaxing, or of having a
3568 particular set of section contents, specially. */
3570 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
3571 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
3576 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3578 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
3579 (size_t) input_section
->size
);
3581 if ((input_section
->flags
& SEC_RELOC
) != 0
3582 && input_section
->reloc_count
> 0)
3585 Elf_Internal_Sym
*isym
, *isymend
;
3588 internal_relocs
= _bfd_elf_link_read_relocs (input_bfd
, input_section
,
3590 if (internal_relocs
== NULL
)
3593 if (symtab_hdr
->sh_info
!= 0)
3595 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3596 if (isymbuf
== NULL
)
3597 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
3598 symtab_hdr
->sh_info
, 0,
3600 if (isymbuf
== NULL
)
3604 amt
= symtab_hdr
->sh_info
;
3605 amt
*= sizeof (asection
*);
3606 sections
= bfd_malloc (amt
);
3607 if (sections
== NULL
&& amt
!= 0)
3610 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
3611 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
3615 if (isym
->st_shndx
== SHN_UNDEF
)
3616 isec
= bfd_und_section_ptr
;
3617 else if (isym
->st_shndx
== SHN_ABS
)
3618 isec
= bfd_abs_section_ptr
;
3619 else if (isym
->st_shndx
== SHN_COMMON
)
3620 isec
= bfd_com_section_ptr
;
3622 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
3627 if (! mn10300_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
3628 input_section
, data
, internal_relocs
,
3632 if (sections
!= NULL
)
3634 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3636 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
3637 free (internal_relocs
);
3643 if (sections
!= NULL
)
3645 if (isymbuf
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
3647 if (internal_relocs
!= NULL
3648 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
3649 free (internal_relocs
);
3653 /* Assorted hash table functions. */
3655 /* Initialize an entry in the link hash table. */
3657 /* Create an entry in an MN10300 ELF linker hash table. */
3659 static struct bfd_hash_entry
*
3660 elf32_mn10300_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3661 struct bfd_hash_table
*table
,
3664 struct elf32_mn10300_link_hash_entry
*ret
=
3665 (struct elf32_mn10300_link_hash_entry
*) entry
;
3667 /* Allocate the structure if it has not already been allocated by a
3670 ret
= (struct elf32_mn10300_link_hash_entry
*)
3671 bfd_hash_allocate (table
, sizeof (* ret
));
3673 return (struct bfd_hash_entry
*) ret
;
3675 /* Call the allocation method of the superclass. */
3676 ret
= (struct elf32_mn10300_link_hash_entry
*)
3677 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3681 ret
->direct_calls
= 0;
3682 ret
->stack_size
= 0;
3684 ret
->movm_stack_size
= 0;
3689 return (struct bfd_hash_entry
*) ret
;
3692 /* Create an mn10300 ELF linker hash table. */
3694 static struct bfd_link_hash_table
*
3695 elf32_mn10300_link_hash_table_create (bfd
*abfd
)
3697 struct elf32_mn10300_link_hash_table
*ret
;
3698 bfd_size_type amt
= sizeof (* ret
);
3700 ret
= bfd_malloc (amt
);
3704 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3705 elf32_mn10300_link_hash_newfunc
,
3706 sizeof (struct elf32_mn10300_link_hash_entry
)))
3713 amt
= sizeof (struct elf_link_hash_table
);
3714 ret
->static_hash_table
= bfd_malloc (amt
);
3715 if (ret
->static_hash_table
== NULL
)
3721 if (!_bfd_elf_link_hash_table_init (&ret
->static_hash_table
->root
, abfd
,
3722 elf32_mn10300_link_hash_newfunc
,
3723 sizeof (struct elf32_mn10300_link_hash_entry
)))
3725 free (ret
->static_hash_table
);
3729 return & ret
->root
.root
;
3732 /* Free an mn10300 ELF linker hash table. */
3735 elf32_mn10300_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3737 struct elf32_mn10300_link_hash_table
*ret
3738 = (struct elf32_mn10300_link_hash_table
*) hash
;
3740 _bfd_generic_link_hash_table_free
3741 ((struct bfd_link_hash_table
*) ret
->static_hash_table
);
3742 _bfd_generic_link_hash_table_free
3743 ((struct bfd_link_hash_table
*) ret
);
3746 static unsigned long
3747 elf_mn10300_mach (flagword flags
)
3749 switch (flags
& EF_MN10300_MACH
)
3751 case E_MN10300_MACH_MN10300
:
3753 return bfd_mach_mn10300
;
3755 case E_MN10300_MACH_AM33
:
3756 return bfd_mach_am33
;
3758 case E_MN10300_MACH_AM33_2
:
3759 return bfd_mach_am33_2
;
3763 /* The final processing done just before writing out a MN10300 ELF object
3764 file. This gets the MN10300 architecture right based on the machine
3768 _bfd_mn10300_elf_final_write_processing (bfd
*abfd
,
3769 bfd_boolean linker ATTRIBUTE_UNUSED
)
3773 switch (bfd_get_mach (abfd
))
3776 case bfd_mach_mn10300
:
3777 val
= E_MN10300_MACH_MN10300
;
3781 val
= E_MN10300_MACH_AM33
;
3784 case bfd_mach_am33_2
:
3785 val
= E_MN10300_MACH_AM33_2
;
3789 elf_elfheader (abfd
)->e_flags
&= ~ (EF_MN10300_MACH
);
3790 elf_elfheader (abfd
)->e_flags
|= val
;
3794 _bfd_mn10300_elf_object_p (bfd
*abfd
)
3796 bfd_default_set_arch_mach (abfd
, bfd_arch_mn10300
,
3797 elf_mn10300_mach (elf_elfheader (abfd
)->e_flags
));
3801 /* Merge backend specific data from an object file to the output
3802 object file when linking. */
3805 _bfd_mn10300_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3807 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3808 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3811 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3812 && bfd_get_mach (obfd
) < bfd_get_mach (ibfd
))
3814 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
3815 bfd_get_mach (ibfd
)))
3822 #define PLT0_ENTRY_SIZE 15
3823 #define PLT_ENTRY_SIZE 20
3824 #define PIC_PLT_ENTRY_SIZE 24
3826 static const bfd_byte elf_mn10300_plt0_entry
[PLT0_ENTRY_SIZE
] =
3828 0xfc, 0xa0, 0, 0, 0, 0, /* mov (.got+8),a0 */
3829 0xfe, 0xe, 0x10, 0, 0, 0, 0, /* mov (.got+4),r1 */
3830 0xf0, 0xf4, /* jmp (a0) */
3833 static const bfd_byte elf_mn10300_plt_entry
[PLT_ENTRY_SIZE
] =
3835 0xfc, 0xa0, 0, 0, 0, 0, /* mov (nameN@GOT + .got),a0 */
3836 0xf0, 0xf4, /* jmp (a0) */
3837 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3838 0xdc, 0, 0, 0, 0, /* jmp .plt0 */
3841 static const bfd_byte elf_mn10300_pic_plt_entry
[PIC_PLT_ENTRY_SIZE
] =
3843 0xfc, 0x22, 0, 0, 0, 0, /* mov (nameN@GOT,a2),a0 */
3844 0xf0, 0xf4, /* jmp (a0) */
3845 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3846 0xf8, 0x22, 8, /* mov (8,a2),a0 */
3847 0xfb, 0xa, 0x1a, 4, /* mov (4,a2),r1 */
3848 0xf0, 0xf4, /* jmp (a0) */
3851 /* Return size of the first PLT entry. */
3852 #define elf_mn10300_sizeof_plt0(info) \
3853 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
3855 /* Return size of a PLT entry. */
3856 #define elf_mn10300_sizeof_plt(info) \
3857 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
3859 /* Return offset of the PLT0 address in an absolute PLT entry. */
3860 #define elf_mn10300_plt_plt0_offset(info) 16
3862 /* Return offset of the linker in PLT0 entry. */
3863 #define elf_mn10300_plt0_linker_offset(info) 2
3865 /* Return offset of the GOT id in PLT0 entry. */
3866 #define elf_mn10300_plt0_gotid_offset(info) 9
3868 /* Return offset of the temporary in PLT entry. */
3869 #define elf_mn10300_plt_temp_offset(info) 8
3871 /* Return offset of the symbol in PLT entry. */
3872 #define elf_mn10300_plt_symbol_offset(info) 2
3874 /* Return offset of the relocation in PLT entry. */
3875 #define elf_mn10300_plt_reloc_offset(info) 11
3877 /* The name of the dynamic interpreter. This is put in the .interp
3880 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
3882 /* Create dynamic sections when linking against a dynamic object. */
3885 _bfd_mn10300_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3889 const struct elf_backend_data
* bed
= get_elf_backend_data (abfd
);
3892 switch (bed
->s
->arch_size
)
3903 bfd_set_error (bfd_error_bad_value
);
3907 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3908 .rel[a].bss sections. */
3909 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3910 | SEC_LINKER_CREATED
);
3912 s
= bfd_make_section_with_flags (abfd
,
3913 (bed
->default_use_rela_p
3914 ? ".rela.plt" : ".rel.plt"),
3915 flags
| SEC_READONLY
);
3917 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3920 if (! _bfd_mn10300_elf_create_got_section (abfd
, info
))
3924 const char * secname
;
3929 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3931 secflags
= bfd_get_section_flags (abfd
, sec
);
3932 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3933 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3936 secname
= bfd_get_section_name (abfd
, sec
);
3937 relname
= bfd_malloc (strlen (secname
) + 6);
3938 strcpy (relname
, ".rela");
3939 strcat (relname
, secname
);
3941 s
= bfd_make_section_with_flags (abfd
, relname
,
3942 flags
| SEC_READONLY
);
3944 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3949 if (bed
->want_dynbss
)
3951 /* The .dynbss section is a place to put symbols which are defined
3952 by dynamic objects, are referenced by regular objects, and are
3953 not functions. We must allocate space for them in the process
3954 image and use a R_*_COPY reloc to tell the dynamic linker to
3955 initialize them at run time. The linker script puts the .dynbss
3956 section into the .bss section of the final image. */
3957 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
3958 SEC_ALLOC
| SEC_LINKER_CREATED
);
3962 /* The .rel[a].bss section holds copy relocs. This section is not
3963 normally needed. We need to create it here, though, so that the
3964 linker will map it to an output section. We can't just create it
3965 only if we need it, because we will not know whether we need it
3966 until we have seen all the input files, and the first time the
3967 main linker code calls BFD after examining all the input files
3968 (size_dynamic_sections) the input sections have already been
3969 mapped to the output sections. If the section turns out not to
3970 be needed, we can discard it later. We will never need this
3971 section when generating a shared object, since they do not use
3975 s
= bfd_make_section_with_flags (abfd
,
3976 (bed
->default_use_rela_p
3977 ? ".rela.bss" : ".rel.bss"),
3978 flags
| SEC_READONLY
);
3980 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3988 /* Adjust a symbol defined by a dynamic object and referenced by a
3989 regular object. The current definition is in some section of the
3990 dynamic object, but we're not including those sections. We have to
3991 change the definition to something the rest of the link can
3995 _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info
* info
,
3996 struct elf_link_hash_entry
* h
)
4001 dynobj
= elf_hash_table (info
)->dynobj
;
4003 /* Make sure we know what is going on here. */
4004 BFD_ASSERT (dynobj
!= NULL
4006 || h
->u
.weakdef
!= NULL
4009 && !h
->def_regular
)));
4011 /* If this is a function, put it in the procedure linkage table. We
4012 will fill in the contents of the procedure linkage table later,
4013 when we know the address of the .got section. */
4014 if (h
->type
== STT_FUNC
4021 /* This case can occur if we saw a PLT reloc in an input
4022 file, but the symbol was never referred to by a dynamic
4023 object. In such a case, we don't actually need to build
4024 a procedure linkage table, and we can just do a REL32
4026 BFD_ASSERT (h
->needs_plt
);
4030 /* Make sure this symbol is output as a dynamic symbol. */
4031 if (h
->dynindx
== -1)
4033 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4037 s
= bfd_get_section_by_name (dynobj
, ".plt");
4038 BFD_ASSERT (s
!= NULL
);
4040 /* If this is the first .plt entry, make room for the special
4043 s
->size
+= elf_mn10300_sizeof_plt0 (info
);
4045 /* If this symbol is not defined in a regular file, and we are
4046 not generating a shared library, then set the symbol to this
4047 location in the .plt. This is required to make function
4048 pointers compare as equal between the normal executable and
4049 the shared library. */
4053 h
->root
.u
.def
.section
= s
;
4054 h
->root
.u
.def
.value
= s
->size
;
4057 h
->plt
.offset
= s
->size
;
4059 /* Make room for this entry. */
4060 s
->size
+= elf_mn10300_sizeof_plt (info
);
4062 /* We also need to make an entry in the .got.plt section, which
4063 will be placed in the .got section by the linker script. */
4064 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
4065 BFD_ASSERT (s
!= NULL
);
4068 /* We also need to make an entry in the .rela.plt section. */
4069 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4070 BFD_ASSERT (s
!= NULL
);
4071 s
->size
+= sizeof (Elf32_External_Rela
);
4076 /* If this is a weak symbol, and there is a real definition, the
4077 processor independent code will have arranged for us to see the
4078 real definition first, and we can just use the same value. */
4079 if (h
->u
.weakdef
!= NULL
)
4081 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
4082 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
4083 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
4084 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
4088 /* This is a reference to a symbol defined by a dynamic object which
4089 is not a function. */
4091 /* If we are creating a shared library, we must presume that the
4092 only references to the symbol are via the global offset table.
4093 For such cases we need not do anything here; the relocations will
4094 be handled correctly by relocate_section. */
4098 /* If there are no references to this symbol that do not use the
4099 GOT, we don't need to generate a copy reloc. */
4100 if (!h
->non_got_ref
)
4105 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
4106 h
->root
.root
.string
);
4110 /* We must allocate the symbol in our .dynbss section, which will
4111 become part of the .bss section of the executable. There will be
4112 an entry for this symbol in the .dynsym section. The dynamic
4113 object will contain position independent code, so all references
4114 from the dynamic object to this symbol will go through the global
4115 offset table. The dynamic linker will use the .dynsym entry to
4116 determine the address it must put in the global offset table, so
4117 both the dynamic object and the regular object will refer to the
4118 same memory location for the variable. */
4120 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
4121 BFD_ASSERT (s
!= NULL
);
4123 /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
4124 copy the initial value out of the dynamic object and into the
4125 runtime process image. We need to remember the offset into the
4126 .rela.bss section we are going to use. */
4127 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4131 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
4132 BFD_ASSERT (srel
!= NULL
);
4133 srel
->size
+= sizeof (Elf32_External_Rela
);
4137 return _bfd_elf_adjust_dynamic_copy (h
, s
);
4140 /* Set the sizes of the dynamic sections. */
4143 _bfd_mn10300_elf_size_dynamic_sections (bfd
* output_bfd
,
4144 struct bfd_link_info
* info
)
4150 bfd_boolean reltext
;
4152 dynobj
= elf_hash_table (info
)->dynobj
;
4153 BFD_ASSERT (dynobj
!= NULL
);
4155 if (elf_hash_table (info
)->dynamic_sections_created
)
4157 /* Set the contents of the .interp section to the interpreter. */
4158 if (info
->executable
)
4160 s
= bfd_get_section_by_name (dynobj
, ".interp");
4161 BFD_ASSERT (s
!= NULL
);
4162 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4163 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4168 /* We may have created entries in the .rela.got section.
4169 However, if we are not creating the dynamic sections, we will
4170 not actually use these entries. Reset the size of .rela.got,
4171 which will cause it to get stripped from the output file
4173 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
4178 /* The check_relocs and adjust_dynamic_symbol entry points have
4179 determined the sizes of the various dynamic sections. Allocate
4184 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4188 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4191 /* It's OK to base decisions on the section name, because none
4192 of the dynobj section names depend upon the input files. */
4193 name
= bfd_get_section_name (dynobj
, s
);
4195 if (streq (name
, ".plt"))
4197 /* Remember whether there is a PLT. */
4200 else if (CONST_STRNEQ (name
, ".rela"))
4206 /* Remember whether there are any reloc sections other
4208 if (! streq (name
, ".rela.plt"))
4210 const char * outname
;
4214 /* If this relocation section applies to a read only
4215 section, then we probably need a DT_TEXTREL
4216 entry. The entries in the .rela.plt section
4217 really apply to the .got section, which we
4218 created ourselves and so know is not readonly. */
4219 outname
= bfd_get_section_name (output_bfd
,
4221 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
4223 && (target
->flags
& SEC_READONLY
) != 0
4224 && (target
->flags
& SEC_ALLOC
) != 0)
4228 /* We use the reloc_count field as a counter if we need
4229 to copy relocs into the output file. */
4233 else if (! CONST_STRNEQ (name
, ".got")
4234 && ! streq (name
, ".dynbss"))
4235 /* It's not one of our sections, so don't allocate space. */
4240 /* If we don't need this section, strip it from the
4241 output file. This is mostly to handle .rela.bss and
4242 .rela.plt. We must create both sections in
4243 create_dynamic_sections, because they must be created
4244 before the linker maps input sections to output
4245 sections. The linker does that before
4246 adjust_dynamic_symbol is called, and it is that
4247 function which decides whether anything needs to go
4248 into these sections. */
4249 s
->flags
|= SEC_EXCLUDE
;
4253 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
4256 /* Allocate memory for the section contents. We use bfd_zalloc
4257 here in case unused entries are not reclaimed before the
4258 section's contents are written out. This should not happen,
4259 but this way if it does, we get a R_MN10300_NONE reloc
4260 instead of garbage. */
4261 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
4262 if (s
->contents
== NULL
)
4266 if (elf_hash_table (info
)->dynamic_sections_created
)
4268 /* Add some entries to the .dynamic section. We fill in the
4269 values later, in _bfd_mn10300_elf_finish_dynamic_sections,
4270 but we must add the entries now so that we get the correct
4271 size for the .dynamic section. The DT_DEBUG entry is filled
4272 in by the dynamic linker and used by the debugger. */
4275 if (!_bfd_elf_add_dynamic_entry (info
, DT_DEBUG
, 0))
4281 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0)
4282 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
4283 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
4284 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0))
4290 if (!_bfd_elf_add_dynamic_entry (info
, DT_RELA
, 0)
4291 || !_bfd_elf_add_dynamic_entry (info
, DT_RELASZ
, 0)
4292 || !_bfd_elf_add_dynamic_entry (info
, DT_RELAENT
,
4293 sizeof (Elf32_External_Rela
)))
4299 if (!_bfd_elf_add_dynamic_entry (info
, DT_TEXTREL
, 0))
4307 /* Finish up dynamic symbol handling. We set the contents of various
4308 dynamic sections here. */
4311 _bfd_mn10300_elf_finish_dynamic_symbol (bfd
* output_bfd
,
4312 struct bfd_link_info
* info
,
4313 struct elf_link_hash_entry
* h
,
4314 Elf_Internal_Sym
* sym
)
4318 dynobj
= elf_hash_table (info
)->dynobj
;
4320 if (h
->plt
.offset
!= (bfd_vma
) -1)
4327 Elf_Internal_Rela rel
;
4329 /* This symbol has an entry in the procedure linkage table. Set
4332 BFD_ASSERT (h
->dynindx
!= -1);
4334 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4335 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
4336 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
4337 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
4339 /* Get the index in the procedure linkage table which
4340 corresponds to this symbol. This is the index of this symbol
4341 in all the symbols for which we are making plt entries. The
4342 first entry in the procedure linkage table is reserved. */
4343 plt_index
= ((h
->plt
.offset
- elf_mn10300_sizeof_plt0 (info
))
4344 / elf_mn10300_sizeof_plt (info
));
4346 /* Get the offset into the .got table of the entry that
4347 corresponds to this function. Each .got entry is 4 bytes.
4348 The first three are reserved. */
4349 got_offset
= (plt_index
+ 3) * 4;
4351 /* Fill in the entry in the procedure linkage table. */
4354 memcpy (splt
->contents
+ h
->plt
.offset
, elf_mn10300_plt_entry
,
4355 elf_mn10300_sizeof_plt (info
));
4356 bfd_put_32 (output_bfd
,
4357 (sgot
->output_section
->vma
4358 + sgot
->output_offset
4360 (splt
->contents
+ h
->plt
.offset
4361 + elf_mn10300_plt_symbol_offset (info
)));
4363 bfd_put_32 (output_bfd
,
4364 (1 - h
->plt
.offset
- elf_mn10300_plt_plt0_offset (info
)),
4365 (splt
->contents
+ h
->plt
.offset
4366 + elf_mn10300_plt_plt0_offset (info
)));
4370 memcpy (splt
->contents
+ h
->plt
.offset
, elf_mn10300_pic_plt_entry
,
4371 elf_mn10300_sizeof_plt (info
));
4373 bfd_put_32 (output_bfd
, got_offset
,
4374 (splt
->contents
+ h
->plt
.offset
4375 + elf_mn10300_plt_symbol_offset (info
)));
4378 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
4379 (splt
->contents
+ h
->plt
.offset
4380 + elf_mn10300_plt_reloc_offset (info
)));
4382 /* Fill in the entry in the global offset table. */
4383 bfd_put_32 (output_bfd
,
4384 (splt
->output_section
->vma
4385 + splt
->output_offset
4387 + elf_mn10300_plt_temp_offset (info
)),
4388 sgot
->contents
+ got_offset
);
4390 /* Fill in the entry in the .rela.plt section. */
4391 rel
.r_offset
= (sgot
->output_section
->vma
4392 + sgot
->output_offset
4394 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MN10300_JMP_SLOT
);
4396 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4397 (bfd_byte
*) ((Elf32_External_Rela
*) srel
->contents
4400 if (!h
->def_regular
)
4401 /* Mark the symbol as undefined, rather than as defined in
4402 the .plt section. Leave the value alone. */
4403 sym
->st_shndx
= SHN_UNDEF
;
4406 if (h
->got
.offset
!= (bfd_vma
) -1)
4410 Elf_Internal_Rela rel
;
4412 /* This symbol has an entry in the global offset table. Set it up. */
4413 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4414 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
4415 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
4417 rel
.r_offset
= (sgot
->output_section
->vma
4418 + sgot
->output_offset
4419 + (h
->got
.offset
& ~1));
4421 /* If this is a -Bsymbolic link, and the symbol is defined
4422 locally, we just want to emit a RELATIVE reloc. Likewise if
4423 the symbol was forced to be local because of a version file.
4424 The entry in the global offset table will already have been
4425 initialized in the relocate_section function. */
4427 && (info
->symbolic
|| h
->dynindx
== -1)
4430 rel
.r_info
= ELF32_R_INFO (0, R_MN10300_RELATIVE
);
4431 rel
.r_addend
= (h
->root
.u
.def
.value
4432 + h
->root
.u
.def
.section
->output_section
->vma
4433 + h
->root
.u
.def
.section
->output_offset
);
4437 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
4438 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MN10300_GLOB_DAT
);
4442 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
4443 (bfd_byte
*) ((Elf32_External_Rela
*) srel
->contents
4444 + srel
->reloc_count
));
4445 ++ srel
->reloc_count
;
4451 Elf_Internal_Rela rel
;
4453 /* This symbol needs a copy reloc. Set it up. */
4454 BFD_ASSERT (h
->dynindx
!= -1
4455 && (h
->root
.type
== bfd_link_hash_defined
4456 || h
->root
.type
== bfd_link_hash_defweak
));
4458 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
4460 BFD_ASSERT (s
!= NULL
);
4462 rel
.r_offset
= (h
->root
.u
.def
.value
4463 + h
->root
.u
.def
.section
->output_section
->vma
4464 + h
->root
.u
.def
.section
->output_offset
);
4465 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MN10300_COPY
);
4467 bfd_elf32_swap_reloca_out (output_bfd
, & rel
,
4468 (bfd_byte
*) ((Elf32_External_Rela
*) s
->contents
4473 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4474 if (streq (h
->root
.root
.string
, "_DYNAMIC")
4475 || h
== elf_hash_table (info
)->hgot
)
4476 sym
->st_shndx
= SHN_ABS
;
4481 /* Finish up the dynamic sections. */
4484 _bfd_mn10300_elf_finish_dynamic_sections (bfd
* output_bfd
,
4485 struct bfd_link_info
* info
)
4491 dynobj
= elf_hash_table (info
)->dynobj
;
4493 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
4494 BFD_ASSERT (sgot
!= NULL
);
4495 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
4497 if (elf_hash_table (info
)->dynamic_sections_created
)
4500 Elf32_External_Dyn
* dyncon
;
4501 Elf32_External_Dyn
* dynconend
;
4503 BFD_ASSERT (sdyn
!= NULL
);
4505 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4506 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4508 for (; dyncon
< dynconend
; dyncon
++)
4510 Elf_Internal_Dyn dyn
;
4514 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
4528 s
= bfd_get_section_by_name (output_bfd
, name
);
4529 BFD_ASSERT (s
!= NULL
);
4530 dyn
.d_un
.d_ptr
= s
->vma
;
4531 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4535 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4536 BFD_ASSERT (s
!= NULL
);
4537 dyn
.d_un
.d_val
= s
->size
;
4538 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4542 /* My reading of the SVR4 ABI indicates that the
4543 procedure linkage table relocs (DT_JMPREL) should be
4544 included in the overall relocs (DT_RELA). This is
4545 what Solaris does. However, UnixWare can not handle
4546 that case. Therefore, we override the DT_RELASZ entry
4547 here to make it not include the JMPREL relocs. Since
4548 the linker script arranges for .rela.plt to follow all
4549 other relocation sections, we don't have to worry
4550 about changing the DT_RELA entry. */
4551 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
4553 dyn
.d_un
.d_val
-= s
->size
;
4554 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4559 /* Fill in the first entry in the procedure linkage table. */
4560 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4561 if (splt
&& splt
->size
> 0)
4565 memcpy (splt
->contents
, elf_mn10300_pic_plt_entry
,
4566 elf_mn10300_sizeof_plt (info
));
4570 memcpy (splt
->contents
, elf_mn10300_plt0_entry
, PLT0_ENTRY_SIZE
);
4571 bfd_put_32 (output_bfd
,
4572 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
4573 splt
->contents
+ elf_mn10300_plt0_gotid_offset (info
));
4574 bfd_put_32 (output_bfd
,
4575 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
4576 splt
->contents
+ elf_mn10300_plt0_linker_offset (info
));
4579 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4580 really seem like the right value. */
4581 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
4585 /* Fill in the first three entries in the global offset table. */
4589 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
4591 bfd_put_32 (output_bfd
,
4592 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4594 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
4595 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
4598 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
4603 /* Classify relocation types, such that combreloc can sort them
4606 static enum elf_reloc_type_class
4607 _bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
4609 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4611 case R_MN10300_RELATIVE
: return reloc_class_relative
;
4612 case R_MN10300_JMP_SLOT
: return reloc_class_plt
;
4613 case R_MN10300_COPY
: return reloc_class_copy
;
4614 default: return reloc_class_normal
;
4619 #define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec
4620 #define TARGET_LITTLE_NAME "elf32-mn10300"
4621 #define ELF_ARCH bfd_arch_mn10300
4622 #define ELF_MACHINE_CODE EM_MN10300
4623 #define ELF_MACHINE_ALT1 EM_CYGNUS_MN10300
4624 #define ELF_MAXPAGESIZE 0x1000
4627 #define elf_info_to_howto mn10300_info_to_howto
4628 #define elf_info_to_howto_rel 0
4629 #define elf_backend_can_gc_sections 1
4630 #define elf_backend_rela_normal 1
4631 #define elf_backend_check_relocs mn10300_elf_check_relocs
4632 #define elf_backend_gc_mark_hook mn10300_elf_gc_mark_hook
4633 #define elf_backend_relocate_section mn10300_elf_relocate_section
4634 #define bfd_elf32_bfd_relax_section mn10300_elf_relax_section
4635 #define bfd_elf32_bfd_get_relocated_section_contents \
4636 mn10300_elf_get_relocated_section_contents
4637 #define bfd_elf32_bfd_link_hash_table_create \
4638 elf32_mn10300_link_hash_table_create
4639 #define bfd_elf32_bfd_link_hash_table_free \
4640 elf32_mn10300_link_hash_table_free
4642 #ifndef elf_symbol_leading_char
4643 #define elf_symbol_leading_char '_'
4646 /* So we can set bits in e_flags. */
4647 #define elf_backend_final_write_processing \
4648 _bfd_mn10300_elf_final_write_processing
4649 #define elf_backend_object_p _bfd_mn10300_elf_object_p
4651 #define bfd_elf32_bfd_merge_private_bfd_data \
4652 _bfd_mn10300_elf_merge_private_bfd_data
4654 #define elf_backend_can_gc_sections 1
4655 #define elf_backend_create_dynamic_sections \
4656 _bfd_mn10300_elf_create_dynamic_sections
4657 #define elf_backend_adjust_dynamic_symbol \
4658 _bfd_mn10300_elf_adjust_dynamic_symbol
4659 #define elf_backend_size_dynamic_sections \
4660 _bfd_mn10300_elf_size_dynamic_sections
4661 #define elf_backend_omit_section_dynsym \
4662 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4663 #define elf_backend_finish_dynamic_symbol \
4664 _bfd_mn10300_elf_finish_dynamic_symbol
4665 #define elf_backend_finish_dynamic_sections \
4666 _bfd_mn10300_elf_finish_dynamic_sections
4668 #define elf_backend_reloc_type_class \
4669 _bfd_mn10300_elf_reloc_type_class
4671 #define elf_backend_want_got_plt 1
4672 #define elf_backend_plt_readonly 1
4673 #define elf_backend_want_plt_sym 0
4674 #define elf_backend_got_header_size 12
4676 #include "elf32-target.h"