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
* abfd
, bfd_reloc_code_real_type code
));
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
*abfd
, arelent
*reloc_entry
,
36 asymbol
*symbol
, PTR data
, asection
*input_section
,
37 bfd
*output_bfd
, char **error_message
));
39 /* GC mark and sweep. */
40 static asection
*elf32_m68hc11_gc_mark_hook
41 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
42 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
43 Elf_Internal_Sym
*sym
));
44 static boolean elf32_m68hc11_gc_sweep_hook
45 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
46 asection
*sec
, const Elf_Internal_Rela
*relocs
));
47 static boolean elf32_m68hc11_check_relocs
48 PARAMS ((bfd
* abfd
, struct bfd_link_info
* info
,
49 asection
* sec
, const Elf_Internal_Rela
* relocs
));
50 static boolean elf32_m68hc11_relocate_section
51 PARAMS ((bfd
*output_bfd
, struct bfd_link_info
*info
,
52 bfd
*input_bfd
, asection
*input_section
,
53 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
54 Elf_Internal_Sym
*local_syms
, asection
**local_sections
));
55 static boolean m68hc11_elf_relax_section
56 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
57 static void m68hc11_elf_relax_delete_bytes
58 PARAMS ((bfd
*abfd
, asection
*sec
, bfd_vma addr
, int count
));
59 static void m68hc11_relax_group
60 PARAMS ((bfd
*abfd
, asection
*sec
, bfd_byte
*contents
,
61 unsigned value
, unsigned long offset
, unsigned long end_group
));
62 static int compare_reloc
PARAMS ((const void*, const void*));
65 boolean _bfd_m68hc11_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
66 boolean _bfd_m68hc11_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
67 boolean _bfd_m68hc11_elf_print_private_bfd_data
PARAMS ((bfd
*, PTR
));
69 /* Use REL instead of RELA to save space */
72 /* The Motorola 68HC11 microcontroler only addresses 64Kb.
73 We must handle 8 and 16-bit relocations. The 32-bit relocation
74 is defined but not used except by gas when -gstabs is used (which
76 The 3-bit and 16-bit PC rel relocation is only used by 68HC12. */
77 static reloc_howto_type elf_m68hc11_howto_table
[] = {
78 /* This reloc does nothing. */
79 HOWTO (R_M68HC11_NONE
, /* type */
81 2, /* size (0 = byte, 1 = short, 2 = long) */
83 false, /* pc_relative */
85 complain_overflow_dont
,/* complain_on_overflow */
86 bfd_elf_generic_reloc
, /* special_function */
87 "R_M68HC11_NONE", /* name */
88 false, /* partial_inplace */
91 false), /* pcrel_offset */
93 /* A 8 bit absolute relocation */
94 HOWTO (R_M68HC11_8
, /* type */
96 0, /* size (0 = byte, 1 = short, 2 = long) */
98 false, /* pc_relative */
100 complain_overflow_bitfield
, /* complain_on_overflow */
101 bfd_elf_generic_reloc
, /* special_function */
102 "R_M68HC11_8", /* name */
103 false, /* partial_inplace */
104 0x00ff, /* src_mask */
105 0x00ff, /* dst_mask */
106 false), /* pcrel_offset */
108 /* A 8 bit absolute relocation (upper address) */
109 HOWTO (R_M68HC11_HI8
, /* type */
111 0, /* size (0 = byte, 1 = short, 2 = long) */
113 false, /* pc_relative */
115 complain_overflow_bitfield
, /* complain_on_overflow */
116 bfd_elf_generic_reloc
, /* special_function */
117 "R_M68HC11_HI8", /* name */
118 false, /* partial_inplace */
119 0x00ff, /* src_mask */
120 0x00ff, /* dst_mask */
121 false), /* pcrel_offset */
123 /* A 8 bit absolute relocation (upper address) */
124 HOWTO (R_M68HC11_LO8
, /* type */
126 0, /* size (0 = byte, 1 = short, 2 = long) */
128 false, /* pc_relative */
130 complain_overflow_dont
, /* complain_on_overflow */
131 bfd_elf_generic_reloc
, /* special_function */
132 "R_M68HC11_LO8", /* name */
133 false, /* partial_inplace */
134 0x00ff, /* src_mask */
135 0x00ff, /* dst_mask */
136 false), /* pcrel_offset */
138 /* A 8 bit PC-rel relocation */
139 HOWTO (R_M68HC11_PCREL_8
, /* type */
141 0, /* size (0 = byte, 1 = short, 2 = long) */
143 true, /* pc_relative */
145 complain_overflow_bitfield
, /* complain_on_overflow */
146 bfd_elf_generic_reloc
, /* special_function */
147 "R_M68HC11_PCREL_8", /* name */
148 false, /* partial_inplace */
149 0x00ff, /* src_mask */
150 0x00ff, /* dst_mask */
151 false), /* pcrel_offset */
153 /* A 16 bit absolute relocation */
154 HOWTO (R_M68HC11_16
, /* type */
156 1, /* size (0 = byte, 1 = short, 2 = long) */
158 false, /* pc_relative */
160 complain_overflow_dont
/*bitfield */ , /* complain_on_overflow */
161 bfd_elf_generic_reloc
, /* special_function */
162 "R_M68HC11_16", /* name */
163 false, /* partial_inplace */
164 0xffff, /* src_mask */
165 0xffff, /* dst_mask */
166 false), /* pcrel_offset */
168 /* A 32 bit absolute relocation. This one is never used for the
169 code relocation. It's used by gas for -gstabs generation. */
170 HOWTO (R_M68HC11_32
, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 false, /* pc_relative */
176 complain_overflow_bitfield
, /* complain_on_overflow */
177 bfd_elf_generic_reloc
, /* special_function */
178 "R_M68HC11_32", /* name */
179 false, /* partial_inplace */
180 0xffffffff, /* src_mask */
181 0xffffffff, /* dst_mask */
182 false), /* pcrel_offset */
184 /* A 3 bit absolute relocation */
185 HOWTO (R_M68HC11_3B
, /* type */
187 0, /* size (0 = byte, 1 = short, 2 = long) */
189 false, /* pc_relative */
191 complain_overflow_bitfield
, /* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_M68HC11_4B", /* name */
194 false, /* partial_inplace */
195 0x003, /* src_mask */
196 0x003, /* dst_mask */
197 false), /* pcrel_offset */
199 /* A 16 bit PC-rel relocation */
200 HOWTO (R_M68HC11_PCREL_16
, /* type */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
204 true, /* pc_relative */
206 complain_overflow_dont
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_M68HC11_PCREL_16", /* name */
209 false, /* partial_inplace */
210 0xffff, /* src_mask */
211 0xffff, /* dst_mask */
212 false), /* pcrel_offset */
214 /* GNU extension to record C++ vtable hierarchy */
215 HOWTO (R_M68HC11_GNU_VTINHERIT
, /* type */
217 1, /* size (0 = byte, 1 = short, 2 = long) */
219 false, /* pc_relative */
221 complain_overflow_dont
, /* complain_on_overflow */
222 NULL
, /* special_function */
223 "R_M68HC11_GNU_VTINHERIT", /* name */
224 false, /* partial_inplace */
227 false), /* pcrel_offset */
229 /* GNU extension to record C++ vtable member usage */
230 HOWTO (R_M68HC11_GNU_VTENTRY
, /* type */
232 1, /* size (0 = byte, 1 = short, 2 = long) */
234 false, /* pc_relative */
236 complain_overflow_dont
, /* complain_on_overflow */
237 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
238 "R_M68HC11_GNU_VTENTRY", /* name */
239 false, /* partial_inplace */
242 false), /* pcrel_offset */
244 /* A 24 bit relocation */
245 HOWTO (R_M68HC11_24
, /* type */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
249 false, /* pc_relative */
251 complain_overflow_bitfield
, /* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_M68HC11_24", /* name */
254 false, /* partial_inplace */
255 0xffff, /* src_mask */
256 0xffff, /* dst_mask */
257 false), /* pcrel_offset */
259 /* A 16-bit low relocation */
260 HOWTO (R_M68HC11_LO16
, /* type */
262 1, /* size (0 = byte, 1 = short, 2 = long) */
264 false, /* pc_relative */
266 complain_overflow_bitfield
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_M68HC11_LO16", /* name */
269 false, /* partial_inplace */
270 0xffff, /* src_mask */
271 0xffff, /* dst_mask */
272 false), /* pcrel_offset */
274 /* A page relocation */
275 HOWTO (R_M68HC11_PAGE
, /* type */
277 0, /* size (0 = byte, 1 = short, 2 = long) */
279 false, /* pc_relative */
281 complain_overflow_bitfield
, /* complain_on_overflow */
282 bfd_elf_generic_reloc
, /* special_function */
283 "R_M68HC11_PAGE", /* name */
284 false, /* partial_inplace */
285 0x00ff, /* src_mask */
286 0x00ff, /* dst_mask */
287 false), /* pcrel_offset */
296 /* Mark beginning of a jump instruction (any form). */
297 HOWTO (R_M68HC11_RL_JUMP
, /* type */
299 1, /* size (0 = byte, 1 = short, 2 = long) */
301 false, /* pc_relative */
303 complain_overflow_dont
, /* complain_on_overflow */
304 m68hc11_elf_ignore_reloc
, /* special_function */
305 "R_M68HC11_RL_JUMP", /* name */
306 true, /* partial_inplace */
309 true), /* pcrel_offset */
311 /* Mark beginning of Gcc relaxation group instruction. */
312 HOWTO (R_M68HC11_RL_GROUP
, /* type */
314 1, /* size (0 = byte, 1 = short, 2 = long) */
316 false, /* pc_relative */
318 complain_overflow_dont
, /* complain_on_overflow */
319 m68hc11_elf_ignore_reloc
, /* special_function */
320 "R_M68HC11_RL_GROUP", /* name */
321 true, /* partial_inplace */
324 true), /* pcrel_offset */
327 /* Map BFD reloc types to M68HC11 ELF reloc types. */
329 struct m68hc11_reloc_map
331 bfd_reloc_code_real_type bfd_reloc_val
;
332 unsigned char elf_reloc_val
;
335 static const struct m68hc11_reloc_map m68hc11_reloc_map
[] = {
336 {BFD_RELOC_NONE
, R_M68HC11_NONE
,},
337 {BFD_RELOC_8
, R_M68HC11_8
},
338 {BFD_RELOC_M68HC11_HI8
, R_M68HC11_HI8
},
339 {BFD_RELOC_M68HC11_LO8
, R_M68HC11_LO8
},
340 {BFD_RELOC_8_PCREL
, R_M68HC11_PCREL_8
},
341 {BFD_RELOC_16_PCREL
, R_M68HC11_PCREL_16
},
342 {BFD_RELOC_16
, R_M68HC11_16
},
343 {BFD_RELOC_32
, R_M68HC11_32
},
344 {BFD_RELOC_M68HC11_3B
, R_M68HC11_3B
},
346 {BFD_RELOC_VTABLE_INHERIT
, R_M68HC11_GNU_VTINHERIT
},
347 {BFD_RELOC_VTABLE_ENTRY
, R_M68HC11_GNU_VTENTRY
},
349 {BFD_RELOC_M68HC11_LO16
, R_M68HC11_LO16
},
350 {BFD_RELOC_M68HC11_PAGE
, R_M68HC11_PAGE
},
351 {BFD_RELOC_M68HC11_24
, R_M68HC11_24
},
353 {BFD_RELOC_M68HC11_RL_JUMP
, R_M68HC11_RL_JUMP
},
354 {BFD_RELOC_M68HC11_RL_GROUP
, R_M68HC11_RL_GROUP
},
357 static reloc_howto_type
*
358 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
359 bfd
*abfd ATTRIBUTE_UNUSED
;
360 bfd_reloc_code_real_type code
;
365 i
< sizeof (m68hc11_reloc_map
) / sizeof (struct m68hc11_reloc_map
);
368 if (m68hc11_reloc_map
[i
].bfd_reloc_val
== code
)
369 return &elf_m68hc11_howto_table
[m68hc11_reloc_map
[i
].elf_reloc_val
];
375 /* This function is used for relocs which are only used for relaxing,
376 which the linker should otherwise ignore. */
378 static bfd_reloc_status_type
379 m68hc11_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
380 output_bfd
, error_message
)
381 bfd
*abfd ATTRIBUTE_UNUSED
;
382 arelent
*reloc_entry
;
383 asymbol
*symbol ATTRIBUTE_UNUSED
;
384 PTR data ATTRIBUTE_UNUSED
;
385 asection
*input_section
;
387 char **error_message ATTRIBUTE_UNUSED
;
389 if (output_bfd
!= NULL
)
390 reloc_entry
->address
+= input_section
->output_offset
;
394 /* Set the howto pointer for an M68HC11 ELF reloc. */
397 m68hc11_info_to_howto_rel (abfd
, cache_ptr
, dst
)
398 bfd
*abfd ATTRIBUTE_UNUSED
;
400 Elf32_Internal_Rel
*dst
;
404 r_type
= ELF32_R_TYPE (dst
->r_info
);
405 BFD_ASSERT (r_type
< (unsigned int) R_M68HC11_max
);
406 cache_ptr
->howto
= &elf_m68hc11_howto_table
[r_type
];
410 elf32_m68hc11_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
412 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
413 Elf_Internal_Rela
*rel
;
414 struct elf_link_hash_entry
*h
;
415 Elf_Internal_Sym
*sym
;
419 switch (ELF32_R_TYPE (rel
->r_info
))
422 switch (h
->root
.type
)
424 case bfd_link_hash_defined
:
425 case bfd_link_hash_defweak
:
426 return h
->root
.u
.def
.section
;
428 case bfd_link_hash_common
:
429 return h
->root
.u
.c
.p
->section
;
438 if (!(elf_bad_symtab (abfd
)
439 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
440 && !((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
441 && sym
->st_shndx
!= SHN_COMMON
))
443 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
450 elf32_m68hc11_gc_sweep_hook (abfd
, info
, sec
, relocs
)
451 bfd
*abfd ATTRIBUTE_UNUSED
;
452 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
453 asection
*sec ATTRIBUTE_UNUSED
;
454 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
456 /* We don't use got and plt entries for 68hc11/68hc12. */
460 struct m68hc11_direct_relax
464 unsigned char direct_code
;
465 } m68hc11_direct_relax_table
[] = {
466 { "adca", 0xB9, 0x99 },
467 { "adcb", 0xF9, 0xD9 },
468 { "adda", 0xBB, 0x9B },
469 { "addb", 0xFB, 0xDB },
470 { "addd", 0xF3, 0xD3 },
471 { "anda", 0xB4, 0x94 },
472 { "andb", 0xF4, 0xD4 },
473 { "cmpa", 0xB1, 0x91 },
474 { "cmpb", 0xF1, 0xD1 },
475 { "cpd", 0xB3, 0x93 },
476 { "cpxy", 0xBC, 0x9C },
477 /* { "cpy", 0xBC, 0x9C }, */
478 { "eora", 0xB8, 0x98 },
479 { "eorb", 0xF8, 0xD8 },
480 { "jsr", 0xBD, 0x9D },
481 { "ldaa", 0xB6, 0x96 },
482 { "ldab", 0xF6, 0xD6 },
483 { "ldd", 0xFC, 0xDC },
484 { "lds", 0xBE, 0x9E },
485 { "ldxy", 0xFE, 0xDE },
486 /* { "ldy", 0xFE, 0xDE },*/
487 { "oraa", 0xBA, 0x9A },
488 { "orab", 0xFA, 0xDA },
489 { "sbca", 0xB2, 0x92 },
490 { "sbcb", 0xF2, 0xD2 },
491 { "staa", 0xB7, 0x97 },
492 { "stab", 0xF7, 0xD7 },
493 { "std", 0xFD, 0xDD },
494 { "sts", 0xBF, 0x9F },
495 { "stxy", 0xFF, 0xDF },
496 /* { "sty", 0xFF, 0xDF },*/
497 { "suba", 0xB0, 0x90 },
498 { "subb", 0xF0, 0xD0 },
499 { "subd", 0xB3, 0x93 },
503 static struct m68hc11_direct_relax
*
504 find_relaxable_insn (unsigned char code
)
508 for (i
= 0; m68hc11_direct_relax_table
[i
].name
; i
++)
509 if (m68hc11_direct_relax_table
[i
].code
== code
)
510 return &m68hc11_direct_relax_table
[i
];
516 compare_reloc (e1
, e2
)
520 const Elf_Internal_Rela
*i1
= (const Elf_Internal_Rela
*) e1
;
521 const Elf_Internal_Rela
*i2
= (const Elf_Internal_Rela
*) e2
;
523 if (i1
->r_offset
== i2
->r_offset
)
526 return i1
->r_offset
< i2
->r_offset
? -1 : 1;
529 #define M6811_OP_LDX_IMMEDIATE (0xCE)
532 m68hc11_relax_group (abfd
, sec
, contents
, value
, offset
, end_group
)
537 unsigned long offset
;
538 unsigned long end_group
;
541 unsigned long start_offset
;
542 unsigned long ldx_offset
= offset
;
543 unsigned long ldx_size
;
547 /* First instruction of the relax group must be a
548 LDX #value or LDY #value. If this is not the case,
549 ignore the relax group. */
550 code
= bfd_get_8 (abfd
, contents
+ offset
);
555 code
= bfd_get_8 (abfd
, contents
+ offset
);
557 ldx_size
= offset
- ldx_offset
+ 3;
559 if (code
!= M6811_OP_LDX_IMMEDIATE
|| offset
>= end_group
)
563 /* We can remove the LDX/LDY only when all bset/brclr instructions
564 of the relax group have been converted to use direct addressing
567 while (offset
< end_group
)
574 start_offset
= offset
;
575 code
= bfd_get_8 (abfd
, contents
+ offset
);
580 code
= bfd_get_8 (abfd
, contents
+ offset
);
583 /* Check the instruction and translate to use direct addressing mode. */
610 /* This instruction is not recognized and we are not
611 at end of the relax group. Ignore and don't remove
612 the first LDX (we don't know what it is used for...). */
616 new_value
= (unsigned) bfd_get_8 (abfd
, contents
+ offset
+ 1);
618 if ((new_value
& 0xff00) == 0 && bset_use_y
== relax_ldy
)
620 bfd_put_8 (abfd
, code
, contents
+ offset
);
621 bfd_put_8 (abfd
, new_value
, contents
+ offset
+ 1);
622 if (start_offset
!= offset
)
624 m68hc11_elf_relax_delete_bytes (abfd
, sec
, start_offset
,
625 offset
- start_offset
);
633 offset
= start_offset
+ isize
;
637 /* Remove the move instruction (3 or 4 bytes win). */
638 m68hc11_elf_relax_delete_bytes (abfd
, sec
, ldx_offset
, ldx_size
);
642 /* This function handles relaxing for the 68HC11.
645 and somewhat more difficult to support. */
648 m68hc11_elf_relax_section (abfd
, sec
, link_info
, again
)
651 struct bfd_link_info
*link_info
;
654 Elf_Internal_Shdr
*symtab_hdr
;
655 Elf_Internal_Shdr
*shndx_hdr
;
656 Elf_Internal_Rela
*internal_relocs
;
657 Elf_Internal_Rela
*free_relocs
= NULL
;
658 Elf_Internal_Rela
*irel
, *irelend
;
659 bfd_byte
*contents
= NULL
;
660 bfd_byte
*free_contents
= NULL
;
661 Elf32_External_Sym
*extsyms
= NULL
;
662 Elf32_External_Sym
*free_extsyms
= NULL
;
663 Elf_Internal_Rela
*prev_insn_branch
= NULL
;
664 Elf_Internal_Rela
*prev_insn_group
= NULL
;
665 unsigned insn_group_value
= 0;
666 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
668 /* Assume nothing changes. */
671 /* We don't have to do anything for a relocateable link, if
672 this section does not have relocs, or if this is not a
674 if (link_info
->relocateable
675 || (sec
->flags
& SEC_RELOC
) == 0
676 || sec
->reloc_count
== 0
677 || (sec
->flags
& SEC_CODE
) == 0)
680 /* If this is the first time we have been called for this section,
681 initialize the cooked size. */
682 if (sec
->_cooked_size
== 0)
683 sec
->_cooked_size
= sec
->_raw_size
;
685 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
686 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
688 /* Get a copy of the native relocations. */
689 internal_relocs
= (_bfd_elf32_link_read_relocs
690 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
691 link_info
->keep_memory
));
692 if (internal_relocs
== NULL
)
694 if (! link_info
->keep_memory
)
695 free_relocs
= internal_relocs
;
697 /* Checking for branch relaxation relies on the relocations to
698 be sorted on 'r_offset'. This is not guaranteed so we must sort. */
699 qsort (internal_relocs
, sec
->reloc_count
, sizeof (Elf_Internal_Rela
),
702 /* Walk through them looking for relaxing opportunities. */
703 irelend
= internal_relocs
+ sec
->reloc_count
;
704 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
708 Elf_Internal_Sym isym
;
710 /* If this isn't something that can be relaxed, then ignore
712 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_M68HC11_16
713 && ELF32_R_TYPE (irel
->r_info
) != (int) R_M68HC11_RL_JUMP
714 && ELF32_R_TYPE (irel
->r_info
) != (int) R_M68HC11_RL_GROUP
)
716 prev_insn_branch
= 0;
721 /* Get the section contents if we haven't done so already. */
722 if (contents
== NULL
)
724 /* Get cached copy if it exists. */
725 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
726 contents
= elf_section_data (sec
)->this_hdr
.contents
;
729 /* Go get them off disk. */
730 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
731 if (contents
== NULL
)
733 free_contents
= contents
;
735 if (! bfd_get_section_contents (abfd
, sec
, contents
,
736 (file_ptr
) 0, sec
->_raw_size
))
741 /* Try to eliminate an unconditional 8 bit pc-relative branch
742 which immediately follows a conditional 8 bit pc-relative
743 branch around the unconditional branch.
750 This happens when the bCC can't reach lab2 at assembly time,
751 but due to other relaxations it can reach at link time. */
752 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_RL_JUMP
)
754 Elf_Internal_Rela
*nrel
;
756 unsigned char roffset
;
758 prev_insn_branch
= 0;
761 /* Do nothing if this reloc is the last byte in the section. */
762 if (irel
->r_offset
== sec
->_cooked_size
)
765 /* See if the next instruction is an unconditional pc-relative
766 branch, more often than not this test will fail, so we
767 test it first to speed things up. */
768 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ 2);
772 /* Also make sure the next relocation applies to the next
773 instruction and that it's a pc-relative 8 bit branch. */
776 || irel
->r_offset
+ 3 != nrel
->r_offset
777 || ELF32_R_TYPE (nrel
->r_info
) != (int) R_M68HC11_16
)
780 /* Make sure our destination immediately follows the
781 unconditional branch. */
782 roffset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ 1);
786 prev_insn_branch
= irel
;
791 /* Read this BFD's symbols if we haven't done so already. */
794 /* Get cached copy if it exists. */
795 if (symtab_hdr
->contents
!= NULL
)
796 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
799 /* Go get them off disk. */
800 bfd_size_type amt
= symtab_hdr
->sh_size
;
801 extsyms
= (Elf32_External_Sym
*) bfd_malloc (amt
);
804 free_extsyms
= extsyms
;
805 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
806 || bfd_bread ((PTR
) extsyms
, amt
, abfd
) != amt
)
810 if (shndx_hdr
->sh_size
!= 0)
814 amt
= symtab_hdr
->sh_info
* sizeof (Elf_External_Sym_Shndx
);
815 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
816 if (shndx_buf
== NULL
)
818 if (bfd_seek (abfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
819 || bfd_bread ((PTR
) shndx_buf
, amt
, abfd
) != amt
)
821 shndx_hdr
->contents
= (PTR
) shndx_buf
;
825 /* Get the value of the symbol referred to by the reloc. */
826 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
828 Elf32_External_Sym
*esym
;
829 Elf_External_Sym_Shndx
*shndx
;
832 /* A local symbol. */
833 esym
= extsyms
+ ELF32_R_SYM (irel
->r_info
);
834 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irel
->r_info
) : 0);
835 bfd_elf32_swap_symbol_in (abfd
, esym
, shndx
, &isym
);
837 sym_sec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
838 symval
= (isym
.st_value
839 + sym_sec
->output_section
->vma
840 + sym_sec
->output_offset
);
845 struct elf_link_hash_entry
*h
;
847 /* An external symbol. */
848 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
849 h
= elf_sym_hashes (abfd
)[indx
];
850 BFD_ASSERT (h
!= NULL
);
851 if (h
->root
.type
!= bfd_link_hash_defined
852 && h
->root
.type
!= bfd_link_hash_defweak
)
854 /* This appears to be a reference to an undefined
855 symbol. Just ignore it--it will be caught by the
856 regular reloc processing. */
857 prev_insn_branch
= 0;
862 symval
= (h
->root
.u
.def
.value
863 + h
->root
.u
.def
.section
->output_section
->vma
864 + h
->root
.u
.def
.section
->output_offset
);
867 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_RL_GROUP
)
869 prev_insn_branch
= 0;
872 /* Do nothing if this reloc is the last byte in the section. */
873 if (irel
->r_offset
== sec
->_cooked_size
)
876 prev_insn_group
= irel
;
877 insn_group_value
= isym
.st_value
;
882 /* Try to turn a far branch to a near branch. */
883 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_16
889 offset
= value
- (prev_insn_branch
->r_offset
890 + sec
->output_section
->vma
891 + sec
->output_offset
+ 2);
893 /* If the offset is still out of -128..+127 range,
894 leave that far branch unchanged. */
895 if ((offset
& 0xff80) != 0 && (offset
& 0xff80) != 0xff80)
897 prev_insn_branch
= 0;
901 /* Shrink the branch. */
902 code
= bfd_get_8 (abfd
, contents
+ prev_insn_branch
->r_offset
);
906 bfd_put_8 (abfd
, code
, contents
+ prev_insn_branch
->r_offset
);
907 bfd_put_8 (abfd
, offset
,
908 contents
+ prev_insn_branch
->r_offset
+ 1);
909 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
911 m68hc11_elf_relax_delete_bytes (abfd
, sec
,
917 bfd_put_8 (abfd
, code
, contents
+ prev_insn_branch
->r_offset
);
918 bfd_put_8 (abfd
, offset
,
919 contents
+ prev_insn_branch
->r_offset
+ 1);
920 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
922 m68hc11_elf_relax_delete_bytes (abfd
, sec
,
923 irel
->r_offset
- 1, 3);
925 prev_insn_branch
= 0;
928 /* Try to turn a 16 bit address into a 8 bit page0 address. */
929 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_M68HC11_16
930 && (value
& 0xff00) == 0)
933 unsigned short offset
;
934 struct m68hc11_direct_relax
*rinfo
;
936 prev_insn_branch
= 0;
937 offset
= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
939 if ((offset
& 0xff00) != 0)
947 /* Note that we've changed the reldection contents, etc. */
948 elf_section_data (sec
)->relocs
= internal_relocs
;
951 elf_section_data (sec
)->this_hdr
.contents
= contents
;
952 free_contents
= NULL
;
954 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
957 m68hc11_relax_group (abfd
, sec
, contents
, offset
,
958 prev_insn_group
->r_offset
,
960 irel
= prev_insn_group
;
962 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
967 /* Get the opcode. */
968 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
969 rinfo
= find_relaxable_insn (code
);
976 /* Note that we've changed the reldection contents, etc. */
977 elf_section_data (sec
)->relocs
= internal_relocs
;
980 elf_section_data (sec
)->this_hdr
.contents
= contents
;
981 free_contents
= NULL
;
983 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
986 /* Fix the opcode. */
987 /* printf ("A relaxable case : 0x%02x (%s)\n",
988 code, rinfo->name); */
989 bfd_put_8 (abfd
, rinfo
->direct_code
,
990 contents
+ irel
->r_offset
- 1);
992 /* Delete one byte of data (upper byte of address). */
993 m68hc11_elf_relax_delete_bytes (abfd
, sec
, irel
->r_offset
, 1);
995 /* Fix the relocation's type. */
996 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
999 /* That will change things, so, we should relax again.
1000 Note that this is not required, and it may be slow. */
1003 else if (ELF32_R_TYPE (irel
->r_info
) == R_M68HC11_16
)
1008 prev_insn_branch
= 0;
1009 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
- 1);
1012 offset
= value
- (irel
->r_offset
1013 + sec
->output_section
->vma
1014 + sec
->output_offset
+ 1);
1015 offset
+= bfd_get_16 (abfd
, contents
+ irel
->r_offset
);
1017 /* If the offset is still out of -128..+127 range,
1018 leave that far branch unchanged. */
1019 if ((offset
& 0xff80) == 0 || (offset
& 0xff80) == 0xff80)
1022 /* Note that we've changed the reldection contents, etc. */
1023 elf_section_data (sec
)->relocs
= internal_relocs
;
1026 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1027 free_contents
= NULL
;
1029 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
1030 free_extsyms
= NULL
;
1032 /* Shrink the branch. */
1034 bfd_put_8 (abfd
, code
,
1035 contents
+ irel
->r_offset
- 1);
1036 bfd_put_8 (abfd
, offset
,
1037 contents
+ irel
->r_offset
);
1038 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1040 m68hc11_elf_relax_delete_bytes (abfd
, sec
,
1041 irel
->r_offset
+ 1, 1);
1045 prev_insn_branch
= 0;
1048 if (free_relocs
!= NULL
)
1054 if (free_contents
!= NULL
)
1056 if (! link_info
->keep_memory
)
1057 free (free_contents
);
1060 /* Cache the section contents for elf_link_input_bfd. */
1061 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1063 free_contents
= NULL
;
1066 if (free_extsyms
!= NULL
)
1068 if (! link_info
->keep_memory
)
1069 free (free_extsyms
);
1072 /* Cache the symbols for elf_link_input_bfd. */
1073 symtab_hdr
->contents
= (unsigned char *) extsyms
;
1075 free_extsyms
= NULL
;
1081 if (free_relocs
!= NULL
)
1083 if (free_contents
!= NULL
)
1084 free (free_contents
);
1085 if (free_extsyms
!= NULL
)
1086 free (free_extsyms
);
1090 /* Delete some bytes from a section while relaxing. */
1093 m68hc11_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
1099 Elf_Internal_Shdr
*symtab_hdr
;
1100 Elf_Internal_Shdr
*shndx_hdr
;
1101 Elf32_External_Sym
*extsyms
;
1102 unsigned int sec_shndx
;
1103 Elf_External_Sym_Shndx
*shndx
;
1105 Elf_Internal_Rela
*irel
, *irelend
;
1107 Elf32_External_Sym
*esym
, *esymend
;
1108 struct elf_link_hash_entry
**sym_hashes
;
1109 struct elf_link_hash_entry
**end_hashes
;
1110 unsigned int symcount
;
1112 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1113 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
1115 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
1117 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1119 toaddr
= sec
->_cooked_size
;
1121 irel
= elf_section_data (sec
)->relocs
;
1122 irelend
= irel
+ sec
->reloc_count
;
1124 /* Actually delete the bytes. */
1125 memmove (contents
+ addr
, contents
+ addr
+ count
,
1126 (size_t) (toaddr
- addr
- count
));
1127 sec
->_cooked_size
-= count
;
1129 /* Adjust all the relocs. */
1130 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
1133 unsigned char offset
;
1134 unsigned short raddr
;
1135 unsigned long old_offset
;
1138 old_offset
= irel
->r_offset
;
1140 /* See if this reloc was for the bytes we have deleted, in which
1141 case we no longer care about it. Don't delete relocs which
1142 represent addresses, though. */
1143 if (ELF32_R_TYPE (irel
->r_info
) != R_M68HC11_RL_JUMP
1144 && irel
->r_offset
>= addr
&& irel
->r_offset
< addr
+ count
)
1145 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1148 if (ELF32_R_TYPE (irel
->r_info
) == R_M68HC11_NONE
)
1151 /* Get the new reloc address. */
1152 if ((irel
->r_offset
> addr
1153 && irel
->r_offset
< toaddr
))
1154 irel
->r_offset
-= count
;
1156 /* If this is a PC relative reloc, see if the range it covers
1157 includes the bytes we have deleted. */
1158 switch (ELF32_R_TYPE (irel
->r_info
))
1163 case R_M68HC11_RL_JUMP
:
1164 code
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
);
1167 /* jsr and jmp instruction are also marked with RL_JUMP
1168 relocs but no adjustment must be made. */
1179 /* Special case when we translate a brclr N,y into brclr *<addr>
1180 In this case, the 0x18 page2 prefix is removed.
1181 The reloc offset is not modified but the instruction
1182 size is reduced by 1. */
1183 if (old_offset
== addr
)
1203 offset
= bfd_get_8 (abfd
, contents
+ irel
->r_offset
+ branch_pos
);
1204 raddr
+= old_offset
;
1205 raddr
+= ((unsigned short) offset
| ((offset
& 0x80) ? 0xff00 : 0));
1206 if (irel
->r_offset
< addr
&& raddr
>= addr
)
1209 bfd_put_8 (abfd
, offset
, contents
+ irel
->r_offset
+ branch_pos
);
1211 else if (irel
->r_offset
>= addr
&& raddr
<= addr
)
1214 bfd_put_8 (abfd
, offset
, contents
+ irel
->r_offset
+ branch_pos
);
1218 /*printf ("Not adjusted 0x%04x [0x%4x 0x%4x]\n", raddr,
1219 irel->r_offset, addr);*/
1226 /* Adjust the local symbols defined in this section. */
1227 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
1228 shndx
= (Elf_External_Sym_Shndx
*) shndx_hdr
->contents
;
1230 esymend
= esym
+ symtab_hdr
->sh_info
;
1231 for (; esym
< esymend
; esym
++, shndx
= (shndx
? shndx
+ 1 : NULL
))
1233 Elf_Internal_Sym isym
;
1234 Elf_External_Sym_Shndx dummy
;
1236 bfd_elf32_swap_symbol_in (abfd
, esym
, shndx
, &isym
);
1238 if (isym
.st_shndx
== sec_shndx
1239 && isym
.st_value
> addr
1240 && isym
.st_value
< toaddr
)
1242 isym
.st_value
-= count
;
1243 bfd_elf32_swap_symbol_out (abfd
, &isym
, esym
, &dummy
);
1247 /* Now adjust the global symbols defined in this section. */
1248 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
1249 - symtab_hdr
->sh_info
);
1250 sym_hashes
= elf_sym_hashes (abfd
);
1251 end_hashes
= sym_hashes
+ symcount
;
1252 for (; sym_hashes
< end_hashes
; sym_hashes
++)
1254 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
1255 if ((sym_hash
->root
.type
== bfd_link_hash_defined
1256 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
1257 && sym_hash
->root
.u
.def
.section
== sec
1258 && sym_hash
->root
.u
.def
.value
> addr
1259 && sym_hash
->root
.u
.def
.value
< toaddr
)
1261 sym_hash
->root
.u
.def
.value
-= count
;
1266 /* Look through the relocs for a section during the first phase.
1267 Since we don't do .gots or .plts, we just need to consider the
1268 virtual table relocs for gc. */
1271 elf32_m68hc11_check_relocs (abfd
, info
, sec
, relocs
)
1273 struct bfd_link_info
* info
;
1275 const Elf_Internal_Rela
* relocs
;
1277 Elf_Internal_Shdr
* symtab_hdr
;
1278 struct elf_link_hash_entry
** sym_hashes
;
1279 struct elf_link_hash_entry
** sym_hashes_end
;
1280 const Elf_Internal_Rela
* rel
;
1281 const Elf_Internal_Rela
* rel_end
;
1283 if (info
->relocateable
)
1286 symtab_hdr
= & elf_tdata (abfd
)->symtab_hdr
;
1287 sym_hashes
= elf_sym_hashes (abfd
);
1288 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
);
1289 if (!elf_bad_symtab (abfd
))
1290 sym_hashes_end
-= symtab_hdr
->sh_info
;
1292 rel_end
= relocs
+ sec
->reloc_count
;
1294 for (rel
= relocs
; rel
< rel_end
; rel
++)
1296 struct elf_link_hash_entry
* h
;
1297 unsigned long r_symndx
;
1299 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1301 if (r_symndx
< symtab_hdr
->sh_info
)
1304 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1306 switch (ELF32_R_TYPE (rel
->r_info
))
1308 /* This relocation describes the C++ object vtable hierarchy.
1309 Reconstruct it for later use during GC. */
1310 case R_M68HC11_GNU_VTINHERIT
:
1311 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1315 /* This relocation describes which C++ vtable entries are actually
1316 used. Record for later use during GC. */
1317 case R_M68HC11_GNU_VTENTRY
:
1318 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1327 /* Relocate a 68hc11/68hc12 ELF section. */
1329 elf32_m68hc11_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1330 contents
, relocs
, local_syms
, local_sections
)
1331 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1332 struct bfd_link_info
*info
;
1334 asection
*input_section
;
1336 Elf_Internal_Rela
*relocs
;
1337 Elf_Internal_Sym
*local_syms
;
1338 asection
**local_sections
;
1340 Elf_Internal_Shdr
*symtab_hdr
;
1341 struct elf_link_hash_entry
**sym_hashes
;
1342 Elf_Internal_Rela
*rel
, *relend
;
1345 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1346 sym_hashes
= elf_sym_hashes (input_bfd
);
1349 relend
= relocs
+ input_section
->reloc_count
;
1350 for (; rel
< relend
; rel
++)
1353 reloc_howto_type
*howto
;
1354 unsigned long r_symndx
;
1355 Elf_Internal_Sym
*sym
;
1357 struct elf_link_hash_entry
*h
;
1359 bfd_reloc_status_type r
;
1361 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1362 r_type
= ELF32_R_TYPE (rel
->r_info
);
1364 if (r_type
== R_M68HC11_GNU_VTENTRY
1365 || r_type
== R_M68HC11_GNU_VTINHERIT
)
1368 howto
= elf_m68hc11_howto_table
+ r_type
;
1370 if (info
->relocateable
)
1372 /* This is a relocateable link. We don't have to change
1373 anything, unless the reloc is against a section symbol,
1374 in which case we have to adjust according to where the
1375 section symbol winds up in the output section. */
1376 if (r_symndx
< symtab_hdr
->sh_info
)
1378 sym
= local_syms
+ r_symndx
;
1379 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1381 sec
= local_sections
[r_symndx
];
1382 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1389 /* This is a final link. */
1393 if (r_symndx
< symtab_hdr
->sh_info
)
1395 sym
= local_syms
+ r_symndx
;
1396 sec
= local_sections
[r_symndx
];
1397 relocation
= (sec
->output_section
->vma
1398 + sec
->output_offset
1403 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1404 while (h
->root
.type
== bfd_link_hash_indirect
1405 || h
->root
.type
== bfd_link_hash_warning
)
1406 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1407 if (h
->root
.type
== bfd_link_hash_defined
1408 || h
->root
.type
== bfd_link_hash_defweak
)
1410 sec
= h
->root
.u
.def
.section
;
1411 relocation
= (h
->root
.u
.def
.value
1412 + sec
->output_section
->vma
1413 + sec
->output_offset
);
1415 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1419 if (!((*info
->callbacks
->undefined_symbol
)
1420 (info
, h
->root
.root
.string
, input_bfd
,
1421 input_section
, rel
->r_offset
, true)))
1428 name
= h
->root
.root
.string
;
1431 name
= (bfd_elf_string_from_elf_section
1432 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
1433 if (name
== NULL
|| *name
== '\0')
1434 name
= bfd_section_name (input_bfd
, sec
);
1437 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1438 contents
, rel
->r_offset
,
1439 relocation
, rel
->r_addend
);
1441 if (r
!= bfd_reloc_ok
)
1443 const char * msg
= (const char *) 0;
1447 case bfd_reloc_overflow
:
1448 if (!((*info
->callbacks
->reloc_overflow
)
1449 (info
, name
, howto
->name
, (bfd_vma
) 0,
1450 input_bfd
, input_section
, rel
->r_offset
)))
1454 case bfd_reloc_undefined
:
1455 if (!((*info
->callbacks
->undefined_symbol
)
1456 (info
, name
, input_bfd
, input_section
,
1457 rel
->r_offset
, true)))
1461 case bfd_reloc_outofrange
:
1462 msg
= _ ("internal error: out of range error");
1465 case bfd_reloc_notsupported
:
1466 msg
= _ ("internal error: unsupported relocation error");
1469 case bfd_reloc_dangerous
:
1470 msg
= _ ("internal error: dangerous error");
1474 msg
= _ ("internal error: unknown error");
1478 if (!((*info
->callbacks
->warning
)
1479 (info
, msg
, name
, input_bfd
, input_section
,
1492 /* Set and control ELF flags in ELF header. */
1495 _bfd_m68hc11_elf_set_private_flags (abfd
, flags
)
1499 BFD_ASSERT (!elf_flags_init (abfd
)
1500 || elf_elfheader (abfd
)->e_flags
== flags
);
1502 elf_elfheader (abfd
)->e_flags
= flags
;
1503 elf_flags_init (abfd
) = true;
1507 /* Merge backend specific data from an object file to the output
1508 object file when linking. */
1511 _bfd_m68hc11_elf_merge_private_bfd_data (ibfd
, obfd
)
1519 /* Check if we have the same endianess */
1520 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
1523 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1524 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1527 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1528 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_M68HC11_ABI
;
1529 old_flags
= elf_elfheader (obfd
)->e_flags
;
1531 if (! elf_flags_init (obfd
))
1533 elf_flags_init (obfd
) = true;
1534 elf_elfheader (obfd
)->e_flags
= new_flags
;
1535 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
1536 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
1538 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
1539 && bfd_get_arch_info (obfd
)->the_default
)
1541 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
1542 bfd_get_mach (ibfd
)))
1549 /* Check ABI compatibility. */
1550 if ((new_flags
& E_M68HC11_I32
) != (old_flags
& E_M68HC11_I32
))
1552 (*_bfd_error_handler
)
1553 (_("%s: linking files compiled for 16-bit integers (-mshort) "
1554 "and others for 32-bit integers"),
1555 bfd_archive_filename (ibfd
));
1558 if ((new_flags
& E_M68HC11_F64
) != (old_flags
& E_M68HC11_F64
))
1560 (*_bfd_error_handler
)
1561 (_("%s: linking files compiled for 32-bit double (-fshort-double) "
1562 "and others for 64-bit double"),
1563 bfd_archive_filename (ibfd
));
1566 new_flags
&= ~EF_M68HC11_ABI
;
1567 old_flags
&= ~EF_M68HC11_ABI
;
1569 /* Warn about any other mismatches */
1570 if (new_flags
!= old_flags
)
1572 (*_bfd_error_handler
)
1573 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1574 bfd_archive_filename (ibfd
), (unsigned long) new_flags
,
1575 (unsigned long) old_flags
);
1581 bfd_set_error (bfd_error_bad_value
);
1589 _bfd_m68hc11_elf_print_private_bfd_data (abfd
, ptr
)
1593 FILE *file
= (FILE *) ptr
;
1595 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
1597 /* Print normal ELF private data. */
1598 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
1600 /* xgettext:c-format */
1601 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
1603 if (elf_elfheader (abfd
)->e_flags
& E_M68HC11_I32
)
1604 fprintf (file
, _("[abi=32-bit int,"));
1606 fprintf (file
, _("[abi=16-bit int,"));
1608 if (elf_elfheader (abfd
)->e_flags
& E_M68HC11_F64
)
1609 fprintf (file
, _(" 64-bit double]"));
1611 fprintf (file
, _(" 32-bit double]"));
1613 if (elf_elfheader (abfd
)->e_flags
& E_M68HC12_BANKS
)
1614 fprintf (file
, _(" [memory=bank-model]"));
1616 fprintf (file
, _(" [memory=flat]"));
1623 /* Below is the only difference between elf32-m68hc12.c and elf32-m68hc11.c.
1624 The Motorola spec says to use a different Elf machine code. */
1625 #define ELF_ARCH bfd_arch_m68hc11
1626 #define ELF_MACHINE_CODE EM_68HC11
1627 #define ELF_MAXPAGESIZE 0x1000
1629 #define TARGET_BIG_SYM bfd_elf32_m68hc11_vec
1630 #define TARGET_BIG_NAME "elf32-m68hc11"
1632 #define elf_info_to_howto 0
1633 #define elf_info_to_howto_rel m68hc11_info_to_howto_rel
1634 #define bfd_elf32_bfd_relax_section m68hc11_elf_relax_section
1635 #define elf_backend_gc_mark_hook elf32_m68hc11_gc_mark_hook
1636 #define elf_backend_gc_sweep_hook elf32_m68hc11_gc_sweep_hook
1637 #define elf_backend_check_relocs elf32_m68hc11_check_relocs
1638 #define elf_backend_relocate_section elf32_m68hc11_relocate_section
1639 #define elf_backend_object_p 0
1640 #define elf_backend_final_write_processing 0
1641 #define elf_backend_can_gc_sections 1
1642 #define bfd_elf32_bfd_merge_private_bfd_data \
1643 _bfd_m68hc11_elf_merge_private_bfd_data
1644 #define bfd_elf32_bfd_set_private_flags _bfd_m68hc11_elf_set_private_flags
1645 #define bfd_elf32_bfd_print_private_bfd_data \
1646 _bfd_m68hc11_elf_print_private_bfd_data
1648 #include "elf32-target.h"