1 /* Motorola 68HC11-specific support for 32-bit ELF
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Stephane Carrez (stcarrez@nerim.fr)
4 (Heavily copied from the D10V port by Martin Hunt (hunt@cygnus.com))
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "elf/m68hc11.h"
29 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
30 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
31 static void m68hc11_info_to_howto_rel
32 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
34 static bfd_reloc_status_type m68hc11_elf_ignore_reloc
35 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
37 /* GC mark and sweep. */
38 static asection
*elf32_m68hc11_gc_mark_hook
39 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
40 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
41 static boolean elf32_m68hc11_gc_sweep_hook
42 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
43 const Elf_Internal_Rela
*));
44 static boolean elf32_m68hc11_check_relocs
45 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
46 const Elf_Internal_Rela
*));
47 static boolean elf32_m68hc11_relocate_section
48 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
49 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
50 static boolean m68hc11_elf_relax_section
51 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
52 static void m68hc11_elf_relax_delete_bytes
53 PARAMS ((bfd
*, asection
*, bfd_vma
, int));
54 static void m68hc11_relax_group
55 PARAMS ((bfd
*, asection
*, bfd_byte
*, unsigned,
56 unsigned long, unsigned long));
57 static int compare_reloc
PARAMS ((const void *, const void *));
60 boolean _bfd_m68hc11_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
61 boolean _bfd_m68hc11_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
62 boolean _bfd_m68hc11_elf_print_private_bfd_data
PARAMS ((bfd
*, PTR
));
64 /* Use REL instead of RELA to save space */
67 /* The Motorola 68HC11 microcontroler only addresses 64Kb.
68 We must handle 8 and 16-bit relocations. The 32-bit relocation
69 is defined but not used except by gas when -gstabs is used (which
71 The 3-bit and 16-bit PC rel relocation is only used by 68HC12. */
72 static reloc_howto_type elf_m68hc11_howto_table
[] = {
73 /* This reloc does nothing. */
74 HOWTO (R_M68HC11_NONE
, /* type */
76 2, /* size (0 = byte, 1 = short, 2 = long) */
78 false, /* pc_relative */
80 complain_overflow_dont
,/* complain_on_overflow */
81 bfd_elf_generic_reloc
, /* special_function */
82 "R_M68HC11_NONE", /* name */
83 false, /* partial_inplace */
86 false), /* pcrel_offset */
88 /* A 8 bit absolute relocation */
89 HOWTO (R_M68HC11_8
, /* type */
91 0, /* size (0 = byte, 1 = short, 2 = long) */
93 false, /* pc_relative */
95 complain_overflow_bitfield
, /* complain_on_overflow */
96 bfd_elf_generic_reloc
, /* special_function */
97 "R_M68HC11_8", /* name */
98 false, /* partial_inplace */
99 0x00ff, /* src_mask */
100 0x00ff, /* dst_mask */
101 false), /* pcrel_offset */
103 /* A 8 bit absolute relocation (upper address) */
104 HOWTO (R_M68HC11_HI8
, /* type */
106 0, /* size (0 = byte, 1 = short, 2 = long) */
108 false, /* pc_relative */
110 complain_overflow_bitfield
, /* complain_on_overflow */
111 bfd_elf_generic_reloc
, /* special_function */
112 "R_M68HC11_HI8", /* name */
113 false, /* partial_inplace */
114 0x00ff, /* src_mask */
115 0x00ff, /* dst_mask */
116 false), /* pcrel_offset */
118 /* A 8 bit absolute relocation (upper address) */
119 HOWTO (R_M68HC11_LO8
, /* type */
121 0, /* size (0 = byte, 1 = short, 2 = long) */
123 false, /* pc_relative */
125 complain_overflow_dont
, /* complain_on_overflow */
126 bfd_elf_generic_reloc
, /* special_function */
127 "R_M68HC11_LO8", /* name */
128 false, /* partial_inplace */
129 0x00ff, /* src_mask */
130 0x00ff, /* dst_mask */
131 false), /* pcrel_offset */
133 /* A 8 bit PC-rel relocation */
134 HOWTO (R_M68HC11_PCREL_8
, /* type */
136 0, /* size (0 = byte, 1 = short, 2 = long) */
138 true, /* pc_relative */
140 complain_overflow_bitfield
, /* complain_on_overflow */
141 bfd_elf_generic_reloc
, /* special_function */
142 "R_M68HC11_PCREL_8", /* name */
143 false, /* partial_inplace */
144 0x00ff, /* src_mask */
145 0x00ff, /* dst_mask */
146 false), /* pcrel_offset */
148 /* A 16 bit absolute relocation */
149 HOWTO (R_M68HC11_16
, /* type */
151 1, /* size (0 = byte, 1 = short, 2 = long) */
153 false, /* pc_relative */
155 complain_overflow_dont
/*bitfield */ , /* complain_on_overflow */
156 bfd_elf_generic_reloc
, /* special_function */
157 "R_M68HC11_16", /* name */
158 false, /* partial_inplace */
159 0xffff, /* src_mask */
160 0xffff, /* dst_mask */
161 false), /* pcrel_offset */
163 /* A 32 bit absolute relocation. This one is never used for the
164 code relocation. It's used by gas for -gstabs generation. */
165 HOWTO (R_M68HC11_32
, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 false, /* pc_relative */
171 complain_overflow_bitfield
, /* complain_on_overflow */
172 bfd_elf_generic_reloc
, /* special_function */
173 "R_M68HC11_32", /* name */
174 false, /* partial_inplace */
175 0xffffffff, /* src_mask */
176 0xffffffff, /* dst_mask */
177 false), /* pcrel_offset */
179 /* A 3 bit absolute relocation */
180 HOWTO (R_M68HC11_3B
, /* type */
182 0, /* size (0 = byte, 1 = short, 2 = long) */
184 false, /* pc_relative */
186 complain_overflow_bitfield
, /* complain_on_overflow */
187 bfd_elf_generic_reloc
, /* special_function */
188 "R_M68HC11_4B", /* name */
189 false, /* partial_inplace */
190 0x003, /* src_mask */
191 0x003, /* dst_mask */
192 false), /* pcrel_offset */
194 /* A 16 bit PC-rel relocation */
195 HOWTO (R_M68HC11_PCREL_16
, /* type */
197 1, /* size (0 = byte, 1 = short, 2 = long) */
199 true, /* pc_relative */
201 complain_overflow_dont
, /* complain_on_overflow */
202 bfd_elf_generic_reloc
, /* special_function */
203 "R_M68HC11_PCREL_16", /* name */
204 false, /* partial_inplace */
205 0xffff, /* src_mask */
206 0xffff, /* dst_mask */
207 false), /* pcrel_offset */
209 /* GNU extension to record C++ vtable hierarchy */
210 HOWTO (R_M68HC11_GNU_VTINHERIT
, /* type */
212 1, /* size (0 = byte, 1 = short, 2 = long) */
214 false, /* pc_relative */
216 complain_overflow_dont
, /* complain_on_overflow */
217 NULL
, /* special_function */
218 "R_M68HC11_GNU_VTINHERIT", /* name */
219 false, /* partial_inplace */
222 false), /* pcrel_offset */
224 /* GNU extension to record C++ vtable member usage */
225 HOWTO (R_M68HC11_GNU_VTENTRY
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_dont
, /* complain_on_overflow */
232 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
233 "R_M68HC11_GNU_VTENTRY", /* name */
234 false, /* partial_inplace */
237 false), /* pcrel_offset */
239 /* A 24 bit relocation */
240 HOWTO (R_M68HC11_24
, /* type */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
244 false, /* pc_relative */
246 complain_overflow_bitfield
, /* complain_on_overflow */
247 bfd_elf_generic_reloc
, /* special_function */
248 "R_M68HC11_24", /* name */
249 false, /* partial_inplace */
250 0xffff, /* src_mask */
251 0xffff, /* dst_mask */
252 false), /* pcrel_offset */
254 /* A 16-bit low relocation */
255 HOWTO (R_M68HC11_LO16
, /* type */
257 1, /* size (0 = byte, 1 = short, 2 = long) */
259 false, /* pc_relative */
261 complain_overflow_bitfield
, /* complain_on_overflow */
262 bfd_elf_generic_reloc
, /* special_function */
263 "R_M68HC11_LO16", /* name */
264 false, /* partial_inplace */
265 0xffff, /* src_mask */
266 0xffff, /* dst_mask */
267 false), /* pcrel_offset */
269 /* A page relocation */
270 HOWTO (R_M68HC11_PAGE
, /* type */
272 0, /* size (0 = byte, 1 = short, 2 = long) */
274 false, /* pc_relative */
276 complain_overflow_bitfield
, /* complain_on_overflow */
277 bfd_elf_generic_reloc
, /* special_function */
278 "R_M68HC11_PAGE", /* name */
279 false, /* partial_inplace */
280 0x00ff, /* src_mask */
281 0x00ff, /* dst_mask */
282 false), /* pcrel_offset */
291 /* Mark beginning of a jump instruction (any form). */
292 HOWTO (R_M68HC11_RL_JUMP
, /* type */
294 1, /* size (0 = byte, 1 = short, 2 = long) */
296 false, /* pc_relative */
298 complain_overflow_dont
, /* complain_on_overflow */
299 m68hc11_elf_ignore_reloc
, /* special_function */
300 "R_M68HC11_RL_JUMP", /* name */
301 true, /* partial_inplace */
304 true), /* pcrel_offset */
306 /* Mark beginning of Gcc relaxation group instruction. */
307 HOWTO (R_M68HC11_RL_GROUP
, /* type */
309 1, /* size (0 = byte, 1 = short, 2 = long) */
311 false, /* pc_relative */
313 complain_overflow_dont
, /* complain_on_overflow */
314 m68hc11_elf_ignore_reloc
, /* special_function */
315 "R_M68HC11_RL_GROUP", /* name */
316 true, /* partial_inplace */
319 true), /* pcrel_offset */
322 /* Map BFD reloc types to M68HC11 ELF reloc types. */
324 struct m68hc11_reloc_map
326 bfd_reloc_code_real_type bfd_reloc_val
;
327 unsigned char elf_reloc_val
;
330 static const struct m68hc11_reloc_map m68hc11_reloc_map
[] = {
331 {BFD_RELOC_NONE
, R_M68HC11_NONE
,},
332 {BFD_RELOC_8
, R_M68HC11_8
},
333 {BFD_RELOC_M68HC11_HI8
, R_M68HC11_HI8
},
334 {BFD_RELOC_M68HC11_LO8
, R_M68HC11_LO8
},
335 {BFD_RELOC_8_PCREL
, R_M68HC11_PCREL_8
},
336 {BFD_RELOC_16_PCREL
, R_M68HC11_PCREL_16
},
337 {BFD_RELOC_16
, R_M68HC11_16
},
338 {BFD_RELOC_32
, R_M68HC11_32
},
339 {BFD_RELOC_M68HC11_3B
, R_M68HC11_3B
},
341 {BFD_RELOC_VTABLE_INHERIT
, R_M68HC11_GNU_VTINHERIT
},
342 {BFD_RELOC_VTABLE_ENTRY
, R_M68HC11_GNU_VTENTRY
},
344 {BFD_RELOC_M68HC11_LO16
, R_M68HC11_LO16
},
345 {BFD_RELOC_M68HC11_PAGE
, R_M68HC11_PAGE
},
346 {BFD_RELOC_M68HC11_24
, R_M68HC11_24
},
348 {BFD_RELOC_M68HC11_RL_JUMP
, R_M68HC11_RL_JUMP
},
349 {BFD_RELOC_M68HC11_RL_GROUP
, R_M68HC11_RL_GROUP
},
352 static reloc_howto_type
*
353 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
354 bfd
*abfd ATTRIBUTE_UNUSED
;
355 bfd_reloc_code_real_type code
;
360 i
< sizeof (m68hc11_reloc_map
) / sizeof (struct m68hc11_reloc_map
);
363 if (m68hc11_reloc_map
[i
].bfd_reloc_val
== code
)
364 return &elf_m68hc11_howto_table
[m68hc11_reloc_map
[i
].elf_reloc_val
];
370 /* This function is used for relocs which are only used for relaxing,
371 which the linker should otherwise ignore. */
373 static bfd_reloc_status_type
374 m68hc11_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
375 output_bfd
, error_message
)
376 bfd
*abfd ATTRIBUTE_UNUSED
;
377 arelent
*reloc_entry
;
378 asymbol
*symbol ATTRIBUTE_UNUSED
;
379 PTR data ATTRIBUTE_UNUSED
;
380 asection
*input_section
;
382 char **error_message ATTRIBUTE_UNUSED
;
384 if (output_bfd
!= NULL
)
385 reloc_entry
->address
+= input_section
->output_offset
;
389 /* Set the howto pointer for an M68HC11 ELF reloc. */
392 m68hc11_info_to_howto_rel (abfd
, cache_ptr
, dst
)
393 bfd
*abfd ATTRIBUTE_UNUSED
;
395 Elf32_Internal_Rel
*dst
;
399 r_type
= ELF32_R_TYPE (dst
->r_info
);
400 BFD_ASSERT (r_type
< (unsigned int) R_M68HC11_max
);
401 cache_ptr
->howto
= &elf_m68hc11_howto_table
[r_type
];
405 elf32_m68hc11_gc_mark_hook (sec
, info
, rel
, h
, sym
)
407 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
408 Elf_Internal_Rela
*rel
;
409 struct elf_link_hash_entry
*h
;
410 Elf_Internal_Sym
*sym
;
414 switch (ELF32_R_TYPE (rel
->r_info
))
417 switch (h
->root
.type
)
419 case bfd_link_hash_defined
:
420 case bfd_link_hash_defweak
:
421 return h
->root
.u
.def
.section
;
423 case bfd_link_hash_common
:
424 return h
->root
.u
.c
.p
->section
;
432 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
438 elf32_m68hc11_gc_sweep_hook (abfd
, info
, sec
, relocs
)
439 bfd
*abfd ATTRIBUTE_UNUSED
;
440 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
441 asection
*sec ATTRIBUTE_UNUSED
;
442 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
444 /* We don't use got and plt entries for 68hc11/68hc12. */
448 struct m68hc11_direct_relax
452 unsigned char direct_code
;
453 } m68hc11_direct_relax_table
[] = {
454 { "adca", 0xB9, 0x99 },
455 { "adcb", 0xF9, 0xD9 },
456 { "adda", 0xBB, 0x9B },
457 { "addb", 0xFB, 0xDB },
458 { "addd", 0xF3, 0xD3 },
459 { "anda", 0xB4, 0x94 },
460 { "andb", 0xF4, 0xD4 },
461 { "cmpa", 0xB1, 0x91 },
462 { "cmpb", 0xF1, 0xD1 },
463 { "cpd", 0xB3, 0x93 },
464 { "cpxy", 0xBC, 0x9C },
465 /* { "cpy", 0xBC, 0x9C }, */
466 { "eora", 0xB8, 0x98 },
467 { "eorb", 0xF8, 0xD8 },
468 { "jsr", 0xBD, 0x9D },
469 { "ldaa", 0xB6, 0x96 },
470 { "ldab", 0xF6, 0xD6 },
471 { "ldd", 0xFC, 0xDC },
472 { "lds", 0xBE, 0x9E },
473 { "ldxy", 0xFE, 0xDE },
474 /* { "ldy", 0xFE, 0xDE },*/
475 { "oraa", 0xBA, 0x9A },
476 { "orab", 0xFA, 0xDA },
477 { "sbca", 0xB2, 0x92 },
478 { "sbcb", 0xF2, 0xD2 },
479 { "staa", 0xB7, 0x97 },
480 { "stab", 0xF7, 0xD7 },
481 { "std", 0xFD, 0xDD },
482 { "sts", 0xBF, 0x9F },
483 { "stxy", 0xFF, 0xDF },
484 /* { "sty", 0xFF, 0xDF },*/
485 { "suba", 0xB0, 0x90 },
486 { "subb", 0xF0, 0xD0 },
487 { "subd", 0xB3, 0x93 },
491 static struct m68hc11_direct_relax
*
492 find_relaxable_insn (unsigned char code
)
496 for (i
= 0; m68hc11_direct_relax_table
[i
].name
; i
++)
497 if (m68hc11_direct_relax_table
[i
].code
== code
)
498 return &m68hc11_direct_relax_table
[i
];
504 compare_reloc (e1
, e2
)
508 const Elf_Internal_Rela
*i1
= (const Elf_Internal_Rela
*) e1
;
509 const Elf_Internal_Rela
*i2
= (const Elf_Internal_Rela
*) e2
;
511 if (i1
->r_offset
== i2
->r_offset
)
514 return i1
->r_offset
< i2
->r_offset
? -1 : 1;
517 #define M6811_OP_LDX_IMMEDIATE (0xCE)
520 m68hc11_relax_group (abfd
, sec
, contents
, value
, offset
, end_group
)
525 unsigned long offset
;
526 unsigned long end_group
;
529 unsigned long start_offset
;
530 unsigned long ldx_offset
= offset
;
531 unsigned long ldx_size
;
535 /* First instruction of the relax group must be a
536 LDX #value or LDY #value. If this is not the case,
537 ignore the relax group. */
538 code
= bfd_get_8 (abfd
, contents
+ offset
);
543 code
= bfd_get_8 (abfd
, contents
+ offset
);
545 ldx_size
= offset
- ldx_offset
+ 3;
547 if (code
!= M6811_OP_LDX_IMMEDIATE
|| offset
>= end_group
)
551 /* We can remove the LDX/LDY only when all bset/brclr instructions
552 of the relax group have been converted to use direct addressing
555 while (offset
< end_group
)
562 start_offset
= offset
;
563 code
= bfd_get_8 (abfd
, contents
+ offset
);
568 code
= bfd_get_8 (abfd
, contents
+ offset
);
571 /* Check the instruction and translate to use direct addressing mode. */
598 /* This instruction is not recognized and we are not
599 at end of the relax group. Ignore and don't remove
600 the first LDX (we don't know what it is used for...). */
604 new_value
= (unsigned) bfd_get_8 (abfd
, contents
+ offset
+ 1);
606 if ((new_value
& 0xff00) == 0 && bset_use_y
== relax_ldy
)
608 bfd_put_8 (abfd
, code
, contents
+ offset
);
609 bfd_put_8 (abfd
, new_value
, contents
+ offset
+ 1);
610 if (start_offset
!= offset
)
612 m68hc11_elf_relax_delete_bytes (abfd
, sec
, start_offset
,
613 offset
- start_offset
);
621 offset
= start_offset
+ isize
;
625 /* Remove the move instruction (3 or 4 bytes win). */
626 m68hc11_elf_relax_delete_bytes (abfd
, sec
, ldx_offset
, ldx_size
);
630 /* This function handles relaxing for the 68HC11.
633 and somewhat more difficult to support. */
636 m68hc11_elf_relax_section (abfd
, sec
, link_info
, again
)
639 struct bfd_link_info
*link_info
;
642 Elf_Internal_Shdr
*symtab_hdr
;
643 Elf_Internal_Shdr
*shndx_hdr
;
644 Elf_Internal_Rela
*internal_relocs
;
645 Elf_Internal_Rela
*free_relocs
= NULL
;
646 Elf_Internal_Rela
*irel
, *irelend
;
647 bfd_byte
*contents
= NULL
;
648 bfd_byte
*free_contents
= NULL
;
649 Elf32_External_Sym
*extsyms
= NULL
;
650 Elf32_External_Sym
*free_extsyms
= NULL
;
651 Elf_Internal_Rela
*prev_insn_branch
= NULL
;
652 Elf_Internal_Rela
*prev_insn_group
= NULL
;
653 unsigned insn_group_value
= 0;
654 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
656 /* Assume nothing changes. */
659 /* We don't have to do anything for a relocateable link, if
660 this section does not have relocs, or if this is not a
662 if (link_info
->relocateable
663 || (sec
->flags
& SEC_RELOC
) == 0
664 || sec
->reloc_count
== 0
665 || (sec
->flags
& SEC_CODE
) == 0)
668 /* If this is the first time we have been called for this section,
669 initialize the cooked size. */
670 if (sec
->_cooked_size
== 0)
671 sec
->_cooked_size
= sec
->_raw_size
;
673 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
674 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
676 /* Get a copy of the native relocations. */
677 internal_relocs
= (_bfd_elf32_link_read_relocs
678 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
679 link_info
->keep_memory
));
680 if (internal_relocs
== NULL
)
682 if (! link_info
->keep_memory
)
683 free_relocs
= internal_relocs
;
685 /* Checking for branch relaxation relies on the relocations to
686 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
687 qsort (internal_relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
690 /* Walk through them looking for relaxing opportunities. */
691 irelend
= internal_relocs
+ sec
->reloc_count
;
692 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
696 Elf_Internal_Sym isym
;
698 /* If this isn't something that can be relaxed, then ignore
700 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_M68HC11_16
701 && ELF32_R_TYPE (irel
->r_info
) != (int) R_M68HC11_RL_JUMP
702 && ELF32_R_TYPE (irel
->r_info
) != (int) R_M68HC11_RL_GROUP
)
704 prev_insn_branch
= 0;
709 /* Get the section contents if we haven't done so already. */
710 if (contents
== NULL
)
712 /* Get cached copy if it exists. */
713 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
714 contents
= elf_section_data (sec
)->this_hdr
.contents
;
717 /* Go get them off disk. */
718 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
719 if (contents
== NULL
)
721 free_contents
= contents
;
723 if (! bfd_get_section_contents (abfd
, sec
, contents
,
724 (file_ptr
) 0, sec
->_raw_size
))
729 /* Try to eliminate an unconditional 8 bit pc-relative branch
730 which immediately follows a conditional 8 bit pc-relative
731 branch around the unconditional branch.
738 This happens when the bCC can't reach lab2 at assembly time,
739 but due to other relaxations it can reach at link time. */
740 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_RL_JUMP
)
742 Elf_Internal_Rela
*nrel
;
744 unsigned char roffset
;
746 prev_insn_branch
= 0;
749 /* Do nothing if this reloc is the last byte in the section. */
750 if (irel
->r_offset
== sec
->_cooked_size
)
753 /* See if the next instruction is an unconditional pc-relative
754 branch, more often than not this test will fail, so we
755 test it first to speed things up. */
756 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ 2);
760 /* Also make sure the next relocation applies to the next
761 instruction and that it's a pc-relative 8 bit branch. */
764 || irel
->r_offset
+ 3 != nrel
->r_offset
765 || ELF32_R_TYPE (nrel
->r_info
) != (int) R_M68HC11_16
)
768 /* Make sure our destination immediately follows the
769 unconditional branch. */
770 roffset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ 1);
774 prev_insn_branch
= irel
;
779 /* Read this BFD's symbols if we haven't done so already. */
782 /* Get cached copy if it exists. */
783 if (symtab_hdr
->contents
!= NULL
)
784 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
787 /* Go get them off disk. */
788 bfd_size_type amt
= symtab_hdr
->sh_size
;
789 extsyms
= (Elf32_External_Sym
*) bfd_malloc (amt
);
792 free_extsyms
= extsyms
;
793 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
794 || bfd_bread ((PTR
) extsyms
, amt
, abfd
) != amt
)
798 if (shndx_hdr
->sh_size
!= 0)
802 amt
= symtab_hdr
->sh_info
* sizeof (Elf_External_Sym_Shndx
);
803 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
804 if (shndx_buf
== NULL
)
806 if (bfd_seek (abfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
807 || bfd_bread ((PTR
) shndx_buf
, amt
, abfd
) != amt
)
809 shndx_hdr
->contents
= (PTR
) shndx_buf
;
813 /* Get the value of the symbol referred to by the reloc. */
814 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
816 Elf32_External_Sym
*esym
;
817 Elf_External_Sym_Shndx
*shndx
;
820 /* A local symbol. */
821 esym
= extsyms
+ ELF32_R_SYM (irel
->r_info
);
822 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irel
->r_info
) : 0);
823 bfd_elf32_swap_symbol_in (abfd
, esym
, shndx
, &isym
);
825 sym_sec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
826 symval
= (isym
.st_value
827 + sym_sec
->output_section
->vma
828 + sym_sec
->output_offset
);
833 struct elf_link_hash_entry
*h
;
835 /* An external symbol. */
836 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
837 h
= elf_sym_hashes (abfd
)[indx
];
838 BFD_ASSERT (h
!= NULL
);
839 if (h
->root
.type
!= bfd_link_hash_defined
840 && h
->root
.type
!= bfd_link_hash_defweak
)
842 /* This appears to be a reference to an undefined
843 symbol. Just ignore it--it will be caught by the
844 regular reloc processing. */
845 prev_insn_branch
= 0;
850 symval
= (h
->root
.u
.def
.value
851 + h
->root
.u
.def
.section
->output_section
->vma
852 + h
->root
.u
.def
.section
->output_offset
);
855 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_RL_GROUP
)
857 prev_insn_branch
= 0;
860 /* Do nothing if this reloc is the last byte in the section. */
861 if (irel
->r_offset
== sec
->_cooked_size
)
864 prev_insn_group
= irel
;
865 insn_group_value
= isym
.st_value
;
870 /* Try to turn a far branch to a near branch. */
871 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_16
877 offset
= value
- (prev_insn_branch
->r_offset
878 + sec
->output_section
->vma
879 + sec
->output_offset
+ 2);
881 /* If the offset is still out of -128..+127 range,
882 leave that far branch unchanged. */
883 if ((offset
& 0xff80) != 0 && (offset
& 0xff80) != 0xff80)
885 prev_insn_branch
= 0;
889 /* Shrink the branch. */
890 code
= bfd_get_8 (abfd
, contents
+ prev_insn_branch
->r_offset
);
894 bfd_put_8 (abfd
, code
, contents
+ prev_insn_branch
->r_offset
);
895 bfd_put_8 (abfd
, offset
,
896 contents
+ prev_insn_branch
->r_offset
+ 1);
897 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
899 m68hc11_elf_relax_delete_bytes (abfd
, sec
,
905 bfd_put_8 (abfd
, code
, contents
+ prev_insn_branch
->r_offset
);
906 bfd_put_8 (abfd
, offset
,
907 contents
+ prev_insn_branch
->r_offset
+ 1);
908 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
910 m68hc11_elf_relax_delete_bytes (abfd
, sec
,
911 irel
->r_offset
- 1, 3);
913 prev_insn_branch
= 0;
916 /* Try to turn a 16 bit address into a 8 bit page0 address. */
917 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_16
918 && (value
& 0xff00) == 0)
921 unsigned short offset
;
922 struct m68hc11_direct_relax
*rinfo
;
924 prev_insn_branch
= 0;
925 offset
= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
927 if ((offset
& 0xff00) != 0)
935 /* Note that we've changed the reldection contents, etc. */
936 elf_section_data (sec
)->relocs
= internal_relocs
;
939 elf_section_data (sec
)->this_hdr
.contents
= contents
;
940 free_contents
= NULL
;
942 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
945 m68hc11_relax_group (abfd
, sec
, contents
, offset
,
946 prev_insn_group
->r_offset
,
948 irel
= prev_insn_group
;
950 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
955 /* Get the opcode. */
956 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
957 rinfo
= find_relaxable_insn (code
);
964 /* Note that we've changed the reldection contents, etc. */
965 elf_section_data (sec
)->relocs
= internal_relocs
;
968 elf_section_data (sec
)->this_hdr
.contents
= contents
;
969 free_contents
= NULL
;
971 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
974 /* Fix the opcode. */
975 /* printf ("A relaxable case : 0x%02x (%s)\n",
976 code, rinfo->name); */
977 bfd_put_8 (abfd
, rinfo
->direct_code
,
978 contents
+ irel
->r_offset
- 1);
980 /* Delete one byte of data (upper byte of address). */
981 m68hc11_elf_relax_delete_bytes (abfd
, sec
, irel
->r_offset
, 1);
983 /* Fix the relocation's type. */
984 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
987 /* That will change things, so, we should relax again.
988 Note that this is not required, and it may be slow. */
991 else if (ELF32_R_TYPE (irel
->r_info
) == R_M68HC11_16
)
996 prev_insn_branch
= 0;
997 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
1000 offset
= value
- (irel
->r_offset
1001 + sec
->output_section
->vma
1002 + sec
->output_offset
+ 1);
1003 offset
+= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
1005 /* If the offset is still out of -128..+127 range,
1006 leave that far branch unchanged. */
1007 if ((offset
& 0xff80) == 0 || (offset
& 0xff80) == 0xff80)
1010 /* Note that we've changed the reldection contents, etc. */
1011 elf_section_data (sec
)->relocs
= internal_relocs
;
1014 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1015 free_contents
= NULL
;
1017 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
1018 free_extsyms
= NULL
;
1020 /* Shrink the branch. */
1022 bfd_put_8 (abfd
, code
,
1023 contents
+ irel
->r_offset
- 1);
1024 bfd_put_8 (abfd
, offset
,
1025 contents
+ irel
->r_offset
);
1026 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1028 m68hc11_elf_relax_delete_bytes (abfd
, sec
,
1029 irel
->r_offset
+ 1, 1);
1033 prev_insn_branch
= 0;
1036 if (free_relocs
!= NULL
)
1042 if (free_contents
!= NULL
)
1044 if (! link_info
->keep_memory
)
1045 free (free_contents
);
1048 /* Cache the section contents for elf_link_input_bfd. */
1049 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1051 free_contents
= NULL
;
1054 if (free_extsyms
!= NULL
)
1056 if (! link_info
->keep_memory
)
1057 free (free_extsyms
);
1060 /* Cache the symbols for elf_link_input_bfd. */
1061 symtab_hdr
->contents
= (unsigned char *) extsyms
;
1063 free_extsyms
= NULL
;
1069 if (free_relocs
!= NULL
)
1071 if (free_contents
!= NULL
)
1072 free (free_contents
);
1073 if (free_extsyms
!= NULL
)
1074 free (free_extsyms
);
1078 /* Delete some bytes from a section while relaxing. */
1081 m68hc11_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
1087 Elf_Internal_Shdr
*symtab_hdr
;
1088 Elf_Internal_Shdr
*shndx_hdr
;
1089 Elf32_External_Sym
*extsyms
;
1090 unsigned int sec_shndx
;
1091 Elf_External_Sym_Shndx
*shndx
;
1093 Elf_Internal_Rela
*irel
, *irelend
;
1095 Elf32_External_Sym
*esym
, *esymend
;
1096 struct elf_link_hash_entry
**sym_hashes
;
1097 struct elf_link_hash_entry
**end_hashes
;
1098 unsigned int symcount
;
1100 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1101 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
1103 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
1105 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1107 toaddr
= sec
->_cooked_size
;
1109 irel
= elf_section_data (sec
)->relocs
;
1110 irelend
= irel
+ sec
->reloc_count
;
1112 /* Actually delete the bytes. */
1113 memmove (contents
+ addr
, contents
+ addr
+ count
,
1114 (size_t) (toaddr
- addr
- count
));
1115 sec
->_cooked_size
-= count
;
1117 /* Adjust all the relocs. */
1118 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
1121 unsigned char offset
;
1122 unsigned short raddr
;
1123 unsigned long old_offset
;
1126 old_offset
= irel
->r_offset
;
1128 /* See if this reloc was for the bytes we have deleted, in which
1129 case we no longer care about it. Don't delete relocs which
1130 represent addresses, though. */
1131 if (ELF32_R_TYPE (irel
->r_info
) != R_M68HC11_RL_JUMP
1132 && irel
->r_offset
>= addr
&& irel
->r_offset
< addr
+ count
)
1133 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1136 if (ELF32_R_TYPE (irel
->r_info
) == R_M68HC11_NONE
)
1139 /* Get the new reloc address. */
1140 if ((irel
->r_offset
> addr
1141 && irel
->r_offset
< toaddr
))
1142 irel
->r_offset
-= count
;
1144 /* If this is a PC relative reloc, see if the range it covers
1145 includes the bytes we have deleted. */
1146 switch (ELF32_R_TYPE (irel
->r_info
))
1151 case R_M68HC11_RL_JUMP
:
1152 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
);
1155 /* jsr and jmp instruction are also marked with RL_JUMP
1156 relocs but no adjustment must be made. */
1167 /* Special case when we translate a brclr N,y into brclr *<addr>
1168 In this case, the 0x18 page2 prefix is removed.
1169 The reloc offset is not modified but the instruction
1170 size is reduced by 1. */
1171 if (old_offset
== addr
)
1191 offset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ branch_pos
);
1192 raddr
+= old_offset
;
1193 raddr
+= ((unsigned short) offset
| ((offset
& 0x80) ? 0xff00 : 0));
1194 if (irel
->r_offset
< addr
&& raddr
>= addr
)
1197 bfd_put_8 (abfd
, offset
, contents
+ irel
->r_offset
+ branch_pos
);
1199 else if (irel
->r_offset
>= addr
&& raddr
<= addr
)
1202 bfd_put_8 (abfd
, offset
, contents
+ irel
->r_offset
+ branch_pos
);
1206 /*printf ("Not adjusted 0x%04x [0x%4x 0x%4x]\n", raddr,
1207 irel->r_offset, addr);*/
1214 /* Adjust the local symbols defined in this section. */
1215 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
1216 shndx
= (Elf_External_Sym_Shndx
*) shndx_hdr
->contents
;
1218 esymend
= esym
+ symtab_hdr
->sh_info
;
1219 for (; esym
< esymend
; esym
++, shndx
= (shndx
? shndx
+ 1 : NULL
))
1221 Elf_Internal_Sym isym
;
1222 Elf_External_Sym_Shndx dummy
;
1224 bfd_elf32_swap_symbol_in (abfd
, esym
, shndx
, &isym
);
1226 if (isym
.st_shndx
== sec_shndx
1227 && isym
.st_value
> addr
1228 && isym
.st_value
< toaddr
)
1230 isym
.st_value
-= count
;
1231 bfd_elf32_swap_symbol_out (abfd
, &isym
, esym
, &dummy
);
1235 /* Now adjust the global symbols defined in this section. */
1236 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
1237 - symtab_hdr
->sh_info
);
1238 sym_hashes
= elf_sym_hashes (abfd
);
1239 end_hashes
= sym_hashes
+ symcount
;
1240 for (; sym_hashes
< end_hashes
; sym_hashes
++)
1242 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
1243 if ((sym_hash
->root
.type
== bfd_link_hash_defined
1244 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
1245 && sym_hash
->root
.u
.def
.section
== sec
1246 && sym_hash
->root
.u
.def
.value
> addr
1247 && sym_hash
->root
.u
.def
.value
< toaddr
)
1249 sym_hash
->root
.u
.def
.value
-= count
;
1254 /* Look through the relocs for a section during the first phase.
1255 Since we don't do .gots or .plts, we just need to consider the
1256 virtual table relocs for gc. */
1259 elf32_m68hc11_check_relocs (abfd
, info
, sec
, relocs
)
1261 struct bfd_link_info
* info
;
1263 const Elf_Internal_Rela
* relocs
;
1265 Elf_Internal_Shdr
* symtab_hdr
;
1266 struct elf_link_hash_entry
** sym_hashes
;
1267 struct elf_link_hash_entry
** sym_hashes_end
;
1268 const Elf_Internal_Rela
* rel
;
1269 const Elf_Internal_Rela
* rel_end
;
1271 if (info
->relocateable
)
1274 symtab_hdr
= & elf_tdata (abfd
)->symtab_hdr
;
1275 sym_hashes
= elf_sym_hashes (abfd
);
1276 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
1277 if (!elf_bad_symtab (abfd
))
1278 sym_hashes_end
-= symtab_hdr
->sh_info
;
1280 rel_end
= relocs
+ sec
->reloc_count
;
1282 for (rel
= relocs
; rel
< rel_end
; rel
++)
1284 struct elf_link_hash_entry
* h
;
1285 unsigned long r_symndx
;
1287 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1289 if (r_symndx
< symtab_hdr
->sh_info
)
1292 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1294 switch (ELF32_R_TYPE (rel
->r_info
))
1296 /* This relocation describes the C++ object vtable hierarchy.
1297 Reconstruct it for later use during GC. */
1298 case R_M68HC11_GNU_VTINHERIT
:
1299 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1303 /* This relocation describes which C++ vtable entries are actually
1304 used. Record for later use during GC. */
1305 case R_M68HC11_GNU_VTENTRY
:
1306 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1315 /* Relocate a 68hc11/68hc12 ELF section. */
1317 elf32_m68hc11_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1318 contents
, relocs
, local_syms
, local_sections
)
1319 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1320 struct bfd_link_info
*info
;
1322 asection
*input_section
;
1324 Elf_Internal_Rela
*relocs
;
1325 Elf_Internal_Sym
*local_syms
;
1326 asection
**local_sections
;
1328 Elf_Internal_Shdr
*symtab_hdr
;
1329 struct elf_link_hash_entry
**sym_hashes
;
1330 Elf_Internal_Rela
*rel
, *relend
;
1333 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1334 sym_hashes
= elf_sym_hashes (input_bfd
);
1337 relend
= relocs
+ input_section
->reloc_count
;
1338 for (; rel
< relend
; rel
++)
1341 reloc_howto_type
*howto
;
1342 unsigned long r_symndx
;
1343 Elf_Internal_Sym
*sym
;
1345 struct elf_link_hash_entry
*h
;
1347 bfd_reloc_status_type r
;
1349 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1350 r_type
= ELF32_R_TYPE (rel
->r_info
);
1352 if (r_type
== R_M68HC11_GNU_VTENTRY
1353 || r_type
== R_M68HC11_GNU_VTINHERIT
)
1356 howto
= elf_m68hc11_howto_table
+ r_type
;
1358 if (info
->relocateable
)
1360 /* This is a relocateable link. We don't have to change
1361 anything, unless the reloc is against a section symbol,
1362 in which case we have to adjust according to where the
1363 section symbol winds up in the output section. */
1364 if (r_symndx
< symtab_hdr
->sh_info
)
1366 sym
= local_syms
+ r_symndx
;
1367 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1369 sec
= local_sections
[r_symndx
];
1370 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1377 /* This is a final link. */
1381 if (r_symndx
< symtab_hdr
->sh_info
)
1383 sym
= local_syms
+ r_symndx
;
1384 sec
= local_sections
[r_symndx
];
1385 relocation
= (sec
->output_section
->vma
1386 + sec
->output_offset
1391 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1392 while (h
->root
.type
== bfd_link_hash_indirect
1393 || h
->root
.type
== bfd_link_hash_warning
)
1394 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1395 if (h
->root
.type
== bfd_link_hash_defined
1396 || h
->root
.type
== bfd_link_hash_defweak
)
1398 sec
= h
->root
.u
.def
.section
;
1399 relocation
= (h
->root
.u
.def
.value
1400 + sec
->output_section
->vma
1401 + sec
->output_offset
);
1403 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1407 if (!((*info
->callbacks
->undefined_symbol
)
1408 (info
, h
->root
.root
.string
, input_bfd
,
1409 input_section
, rel
->r_offset
, true)))
1416 name
= h
->root
.root
.string
;
1419 name
= (bfd_elf_string_from_elf_section
1420 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
1421 if (name
== NULL
|| *name
== '\0')
1422 name
= bfd_section_name (input_bfd
, sec
);
1425 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1426 contents
, rel
->r_offset
,
1427 relocation
, rel
->r_addend
);
1429 if (r
!= bfd_reloc_ok
)
1431 const char * msg
= (const char *) 0;
1435 case bfd_reloc_overflow
:
1436 if (!((*info
->callbacks
->reloc_overflow
)
1437 (info
, name
, howto
->name
, (bfd_vma
) 0,
1438 input_bfd
, input_section
, rel
->r_offset
)))
1442 case bfd_reloc_undefined
:
1443 if (!((*info
->callbacks
->undefined_symbol
)
1444 (info
, name
, input_bfd
, input_section
,
1445 rel
->r_offset
, true)))
1449 case bfd_reloc_outofrange
:
1450 msg
= _ ("internal error: out of range error");
1453 case bfd_reloc_notsupported
:
1454 msg
= _ ("internal error: unsupported relocation error");
1457 case bfd_reloc_dangerous
:
1458 msg
= _ ("internal error: dangerous error");
1462 msg
= _ ("internal error: unknown error");
1466 if (!((*info
->callbacks
->warning
)
1467 (info
, msg
, name
, input_bfd
, input_section
,
1480 /* Set and control ELF flags in ELF header. */
1483 _bfd_m68hc11_elf_set_private_flags (abfd
, flags
)
1487 BFD_ASSERT (!elf_flags_init (abfd
)
1488 || elf_elfheader (abfd
)->e_flags
== flags
);
1490 elf_elfheader (abfd
)->e_flags
= flags
;
1491 elf_flags_init (abfd
) = true;
1495 /* Merge backend specific data from an object file to the output
1496 object file when linking. */
1499 _bfd_m68hc11_elf_merge_private_bfd_data (ibfd
, obfd
)
1507 /* Check if we have the same endianess */
1508 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
1511 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1512 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1515 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1516 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_M68HC11_ABI
;
1517 old_flags
= elf_elfheader (obfd
)->e_flags
;
1519 if (! elf_flags_init (obfd
))
1521 elf_flags_init (obfd
) = true;
1522 elf_elfheader (obfd
)->e_flags
= new_flags
;
1523 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
1524 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
1526 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1527 && bfd_get_arch_info (obfd
)->the_default
)
1529 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
1530 bfd_get_mach (ibfd
)))
1537 /* Check ABI compatibility. */
1538 if ((new_flags
& E_M68HC11_I32
) != (old_flags
& E_M68HC11_I32
))
1540 (*_bfd_error_handler
)
1541 (_("%s: linking files compiled for 16-bit integers (-mshort) "
1542 "and others for 32-bit integers"),
1543 bfd_archive_filename (ibfd
));
1546 if ((new_flags
& E_M68HC11_F64
) != (old_flags
& E_M68HC11_F64
))
1548 (*_bfd_error_handler
)
1549 (_("%s: linking files compiled for 32-bit double (-fshort-double) "
1550 "and others for 64-bit double"),
1551 bfd_archive_filename (ibfd
));
1554 new_flags
&= ~EF_M68HC11_ABI
;
1555 old_flags
&= ~EF_M68HC11_ABI
;
1557 /* Warn about any other mismatches */
1558 if (new_flags
!= old_flags
)
1560 (*_bfd_error_handler
)
1561 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1562 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
1563 (unsigned long) old_flags
);
1569 bfd_set_error (bfd_error_bad_value
);
1577 _bfd_m68hc11_elf_print_private_bfd_data (abfd
, ptr
)
1581 FILE *file
= (FILE *) ptr
;
1583 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1585 /* Print normal ELF private data. */
1586 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1588 /* xgettext:c-format */
1589 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1591 if (elf_elfheader (abfd
)->e_flags
& E_M68HC11_I32
)
1592 fprintf (file
, _("[abi=32-bit int,"));
1594 fprintf (file
, _("[abi=16-bit int,"));
1596 if (elf_elfheader (abfd
)->e_flags
& E_M68HC11_F64
)
1597 fprintf (file
, _(" 64-bit double]"));
1599 fprintf (file
, _(" 32-bit double]"));
1601 if (elf_elfheader (abfd
)->e_flags
& E_M68HC12_BANKS
)
1602 fprintf (file
, _(" [memory=bank-model]"));
1604 fprintf (file
, _(" [memory=flat]"));
1611 /* Below is the only difference between elf32-m68hc12.c and elf32-m68hc11.c.
1612 The Motorola spec says to use a different Elf machine code. */
1613 #define ELF_ARCH bfd_arch_m68hc11
1614 #define ELF_MACHINE_CODE EM_68HC11
1615 #define ELF_MAXPAGESIZE 0x1000
1617 #define TARGET_BIG_SYM bfd_elf32_m68hc11_vec
1618 #define TARGET_BIG_NAME "elf32-m68hc11"
1620 #define elf_info_to_howto 0
1621 #define elf_info_to_howto_rel m68hc11_info_to_howto_rel
1622 #define bfd_elf32_bfd_relax_section m68hc11_elf_relax_section
1623 #define elf_backend_gc_mark_hook elf32_m68hc11_gc_mark_hook
1624 #define elf_backend_gc_sweep_hook elf32_m68hc11_gc_sweep_hook
1625 #define elf_backend_check_relocs elf32_m68hc11_check_relocs
1626 #define elf_backend_relocate_section elf32_m68hc11_relocate_section
1627 #define elf_backend_object_p 0
1628 #define elf_backend_final_write_processing 0
1629 #define elf_backend_can_gc_sections 1
1630 #define bfd_elf32_bfd_merge_private_bfd_data \
1631 _bfd_m68hc11_elf_merge_private_bfd_data
1632 #define bfd_elf32_bfd_set_private_flags _bfd_m68hc11_elf_set_private_flags
1633 #define bfd_elf32_bfd_print_private_bfd_data \
1634 _bfd_m68hc11_elf_print_private_bfd_data
1636 #include "elf32-target.h"