elf32-m68hc11.c revision 1.1.1.7 1 1.1 skrll /* Motorola 68HC11-specific support for 32-bit ELF
2 1.1.1.6 christos Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 1.1 skrll Contributed by Stephane Carrez (stcarrez (at) nerim.fr)
4 1.1 skrll (Heavily copied from the D10V port by Martin Hunt (hunt (at) cygnus.com))
5 1.1 skrll
6 1.1 skrll This file is part of BFD, the Binary File Descriptor library.
7 1.1 skrll
8 1.1 skrll This program is free software; you can redistribute it and/or modify
9 1.1 skrll it under the terms of the GNU General Public License as published by
10 1.1 skrll the Free Software Foundation; either version 3 of the License, or
11 1.1 skrll (at your option) any later version.
12 1.1 skrll
13 1.1 skrll This program is distributed in the hope that it will be useful,
14 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 skrll GNU General Public License for more details.
17 1.1 skrll
18 1.1 skrll You should have received a copy of the GNU General Public License
19 1.1 skrll along with this program; if not, write to the Free Software
20 1.1 skrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 1.1 skrll MA 02110-1301, USA. */
22 1.1 skrll
23 1.1 skrll #include "sysdep.h"
24 1.1 skrll #include "bfd.h"
25 1.1 skrll #include "bfdlink.h"
26 1.1 skrll #include "libbfd.h"
27 1.1 skrll #include "elf-bfd.h"
28 1.1 skrll #include "elf32-m68hc1x.h"
29 1.1 skrll #include "elf/m68hc11.h"
30 1.1 skrll #include "opcode/m68hc11.h"
31 1.1 skrll
32 1.1 skrll /* Relocation functions. */
33 1.1 skrll static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
34 1.1 skrll (bfd *, bfd_reloc_code_real_type);
35 1.1.1.7 christos static bfd_boolean m68hc11_info_to_howto_rel
36 1.1 skrll (bfd *, arelent *, Elf_Internal_Rela *);
37 1.1 skrll
38 1.1 skrll /* Trampoline generation. */
39 1.1 skrll static bfd_boolean m68hc11_elf_size_one_stub
40 1.1 skrll (struct bfd_hash_entry *gen_entry, void *in_arg);
41 1.1 skrll static bfd_boolean m68hc11_elf_build_one_stub
42 1.1 skrll (struct bfd_hash_entry *gen_entry, void *in_arg);
43 1.1 skrll static struct bfd_link_hash_table* m68hc11_elf_bfd_link_hash_table_create
44 1.1 skrll (bfd* abfd);
45 1.1 skrll
46 1.1 skrll /* Linker relaxation. */
47 1.1 skrll static bfd_boolean m68hc11_elf_relax_section
48 1.1 skrll (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
49 1.1 skrll static void m68hc11_elf_relax_delete_bytes
50 1.1 skrll (bfd *, asection *, bfd_vma, int);
51 1.1 skrll static void m68hc11_relax_group
52 1.1 skrll (bfd *, asection *, bfd_byte *, unsigned, unsigned long, unsigned long);
53 1.1 skrll static int compare_reloc (const void *, const void *);
54 1.1 skrll
55 1.1 skrll /* Use REL instead of RELA to save space */
56 1.1 skrll #define USE_REL 1
57 1.1 skrll
58 1.1 skrll /* The Motorola 68HC11 microcontroller only addresses 64Kb but we also
59 1.1 skrll support a memory bank switching mechanism similar to 68HC12.
60 1.1 skrll We must handle 8 and 16-bit relocations. The 32-bit relocation
61 1.1 skrll are used for debugging sections (DWARF2) to represent a virtual
62 1.1 skrll address.
63 1.1 skrll The 3-bit and 16-bit PC rel relocation is only used by 68HC12. */
64 1.1 skrll static reloc_howto_type elf_m68hc11_howto_table[] = {
65 1.1 skrll /* This reloc does nothing. */
66 1.1 skrll HOWTO (R_M68HC11_NONE, /* type */
67 1.1 skrll 0, /* rightshift */
68 1.1.1.4 christos 3, /* size (0 = byte, 1 = short, 2 = long) */
69 1.1.1.4 christos 0, /* bitsize */
70 1.1 skrll FALSE, /* pc_relative */
71 1.1 skrll 0, /* bitpos */
72 1.1 skrll complain_overflow_dont,/* complain_on_overflow */
73 1.1 skrll bfd_elf_generic_reloc, /* special_function */
74 1.1 skrll "R_M68HC11_NONE", /* name */
75 1.1 skrll FALSE, /* partial_inplace */
76 1.1 skrll 0, /* src_mask */
77 1.1 skrll 0, /* dst_mask */
78 1.1 skrll FALSE), /* pcrel_offset */
79 1.1 skrll
80 1.1 skrll /* A 8 bit absolute relocation */
81 1.1 skrll HOWTO (R_M68HC11_8, /* type */
82 1.1 skrll 0, /* rightshift */
83 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
84 1.1 skrll 8, /* bitsize */
85 1.1 skrll FALSE, /* pc_relative */
86 1.1 skrll 0, /* bitpos */
87 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
88 1.1 skrll bfd_elf_generic_reloc, /* special_function */
89 1.1 skrll "R_M68HC11_8", /* name */
90 1.1 skrll FALSE, /* partial_inplace */
91 1.1 skrll 0x00ff, /* src_mask */
92 1.1 skrll 0x00ff, /* dst_mask */
93 1.1 skrll FALSE), /* pcrel_offset */
94 1.1 skrll
95 1.1 skrll /* A 8 bit absolute relocation (upper address) */
96 1.1 skrll HOWTO (R_M68HC11_HI8, /* type */
97 1.1 skrll 8, /* rightshift */
98 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
99 1.1 skrll 8, /* bitsize */
100 1.1 skrll FALSE, /* pc_relative */
101 1.1 skrll 0, /* bitpos */
102 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
103 1.1 skrll bfd_elf_generic_reloc, /* special_function */
104 1.1 skrll "R_M68HC11_HI8", /* name */
105 1.1 skrll FALSE, /* partial_inplace */
106 1.1 skrll 0x00ff, /* src_mask */
107 1.1 skrll 0x00ff, /* dst_mask */
108 1.1 skrll FALSE), /* pcrel_offset */
109 1.1 skrll
110 1.1 skrll /* A 8 bit absolute relocation (upper address) */
111 1.1 skrll HOWTO (R_M68HC11_LO8, /* type */
112 1.1 skrll 0, /* rightshift */
113 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
114 1.1 skrll 8, /* bitsize */
115 1.1 skrll FALSE, /* pc_relative */
116 1.1 skrll 0, /* bitpos */
117 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
118 1.1 skrll bfd_elf_generic_reloc, /* special_function */
119 1.1 skrll "R_M68HC11_LO8", /* name */
120 1.1 skrll FALSE, /* partial_inplace */
121 1.1 skrll 0x00ff, /* src_mask */
122 1.1 skrll 0x00ff, /* dst_mask */
123 1.1 skrll FALSE), /* pcrel_offset */
124 1.1 skrll
125 1.1 skrll /* A 8 bit PC-rel relocation */
126 1.1 skrll HOWTO (R_M68HC11_PCREL_8, /* type */
127 1.1 skrll 0, /* rightshift */
128 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
129 1.1 skrll 8, /* bitsize */
130 1.1 skrll TRUE, /* pc_relative */
131 1.1 skrll 0, /* bitpos */
132 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
133 1.1 skrll bfd_elf_generic_reloc, /* special_function */
134 1.1 skrll "R_M68HC11_PCREL_8", /* name */
135 1.1 skrll FALSE, /* partial_inplace */
136 1.1 skrll 0x00ff, /* src_mask */
137 1.1 skrll 0x00ff, /* dst_mask */
138 1.1.1.6 christos TRUE), /* pcrel_offset */
139 1.1 skrll
140 1.1 skrll /* A 16 bit absolute relocation */
141 1.1 skrll HOWTO (R_M68HC11_16, /* type */
142 1.1 skrll 0, /* rightshift */
143 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
144 1.1 skrll 16, /* bitsize */
145 1.1 skrll FALSE, /* pc_relative */
146 1.1 skrll 0, /* bitpos */
147 1.1 skrll complain_overflow_dont /*bitfield */ , /* complain_on_overflow */
148 1.1 skrll bfd_elf_generic_reloc, /* special_function */
149 1.1 skrll "R_M68HC11_16", /* name */
150 1.1 skrll FALSE, /* partial_inplace */
151 1.1 skrll 0xffff, /* src_mask */
152 1.1 skrll 0xffff, /* dst_mask */
153 1.1 skrll FALSE), /* pcrel_offset */
154 1.1 skrll
155 1.1 skrll /* A 32 bit absolute relocation. This one is never used for the
156 1.1 skrll code relocation. It's used by gas for -gstabs generation. */
157 1.1 skrll HOWTO (R_M68HC11_32, /* type */
158 1.1 skrll 0, /* rightshift */
159 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
160 1.1 skrll 32, /* bitsize */
161 1.1 skrll FALSE, /* pc_relative */
162 1.1 skrll 0, /* bitpos */
163 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
164 1.1 skrll bfd_elf_generic_reloc, /* special_function */
165 1.1 skrll "R_M68HC11_32", /* name */
166 1.1 skrll FALSE, /* partial_inplace */
167 1.1 skrll 0xffffffff, /* src_mask */
168 1.1 skrll 0xffffffff, /* dst_mask */
169 1.1 skrll FALSE), /* pcrel_offset */
170 1.1 skrll
171 1.1 skrll /* A 3 bit absolute relocation */
172 1.1 skrll HOWTO (R_M68HC11_3B, /* type */
173 1.1 skrll 0, /* rightshift */
174 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
175 1.1 skrll 3, /* bitsize */
176 1.1 skrll FALSE, /* pc_relative */
177 1.1 skrll 0, /* bitpos */
178 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
179 1.1 skrll bfd_elf_generic_reloc, /* special_function */
180 1.1 skrll "R_M68HC11_4B", /* name */
181 1.1 skrll FALSE, /* partial_inplace */
182 1.1 skrll 0x003, /* src_mask */
183 1.1 skrll 0x003, /* dst_mask */
184 1.1 skrll FALSE), /* pcrel_offset */
185 1.1 skrll
186 1.1 skrll /* A 16 bit PC-rel relocation */
187 1.1 skrll HOWTO (R_M68HC11_PCREL_16, /* type */
188 1.1 skrll 0, /* rightshift */
189 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
190 1.1 skrll 16, /* bitsize */
191 1.1 skrll TRUE, /* pc_relative */
192 1.1 skrll 0, /* bitpos */
193 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
194 1.1 skrll bfd_elf_generic_reloc, /* special_function */
195 1.1 skrll "R_M68HC11_PCREL_16", /* name */
196 1.1 skrll FALSE, /* partial_inplace */
197 1.1 skrll 0xffff, /* src_mask */
198 1.1 skrll 0xffff, /* dst_mask */
199 1.1.1.6 christos TRUE), /* pcrel_offset */
200 1.1 skrll
201 1.1 skrll /* GNU extension to record C++ vtable hierarchy */
202 1.1 skrll HOWTO (R_M68HC11_GNU_VTINHERIT, /* type */
203 1.1 skrll 0, /* rightshift */
204 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
205 1.1 skrll 0, /* bitsize */
206 1.1 skrll FALSE, /* pc_relative */
207 1.1 skrll 0, /* bitpos */
208 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
209 1.1 skrll NULL, /* special_function */
210 1.1 skrll "R_M68HC11_GNU_VTINHERIT", /* name */
211 1.1 skrll FALSE, /* partial_inplace */
212 1.1 skrll 0, /* src_mask */
213 1.1 skrll 0, /* dst_mask */
214 1.1 skrll FALSE), /* pcrel_offset */
215 1.1 skrll
216 1.1 skrll /* GNU extension to record C++ vtable member usage */
217 1.1 skrll HOWTO (R_M68HC11_GNU_VTENTRY, /* type */
218 1.1 skrll 0, /* rightshift */
219 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
220 1.1 skrll 0, /* bitsize */
221 1.1 skrll FALSE, /* pc_relative */
222 1.1 skrll 0, /* bitpos */
223 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
224 1.1 skrll _bfd_elf_rel_vtable_reloc_fn, /* special_function */
225 1.1 skrll "R_M68HC11_GNU_VTENTRY", /* name */
226 1.1 skrll FALSE, /* partial_inplace */
227 1.1 skrll 0, /* src_mask */
228 1.1 skrll 0, /* dst_mask */
229 1.1 skrll FALSE), /* pcrel_offset */
230 1.1 skrll
231 1.1 skrll /* A 24 bit relocation */
232 1.1.1.6 christos HOWTO (R_M68HC11_24, /* type */
233 1.1 skrll 0, /* rightshift */
234 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
235 1.1 skrll 24, /* bitsize */
236 1.1 skrll FALSE, /* pc_relative */
237 1.1 skrll 0, /* bitpos */
238 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
239 1.1 skrll bfd_elf_generic_reloc, /* special_function */
240 1.1 skrll "R_M68HC11_24", /* name */
241 1.1 skrll FALSE, /* partial_inplace */
242 1.1 skrll 0xffffff, /* src_mask */
243 1.1 skrll 0xffffff, /* dst_mask */
244 1.1 skrll FALSE), /* pcrel_offset */
245 1.1 skrll
246 1.1 skrll /* A 16-bit low relocation */
247 1.1.1.6 christos HOWTO (R_M68HC11_LO16, /* type */
248 1.1 skrll 0, /* rightshift */
249 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
250 1.1 skrll 16, /* bitsize */
251 1.1 skrll FALSE, /* pc_relative */
252 1.1 skrll 0, /* bitpos */
253 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
254 1.1 skrll bfd_elf_generic_reloc, /* special_function */
255 1.1 skrll "R_M68HC11_LO16", /* name */
256 1.1 skrll FALSE, /* partial_inplace */
257 1.1 skrll 0xffff, /* src_mask */
258 1.1 skrll 0xffff, /* dst_mask */
259 1.1 skrll FALSE), /* pcrel_offset */
260 1.1 skrll
261 1.1 skrll /* A page relocation */
262 1.1.1.6 christos HOWTO (R_M68HC11_PAGE, /* type */
263 1.1 skrll 0, /* rightshift */
264 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
265 1.1 skrll 8, /* bitsize */
266 1.1 skrll FALSE, /* pc_relative */
267 1.1 skrll 0, /* bitpos */
268 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
269 1.1 skrll bfd_elf_generic_reloc, /* special_function */
270 1.1 skrll "R_M68HC11_PAGE", /* name */
271 1.1 skrll FALSE, /* partial_inplace */
272 1.1 skrll 0x00ff, /* src_mask */
273 1.1 skrll 0x00ff, /* dst_mask */
274 1.1 skrll FALSE), /* pcrel_offset */
275 1.1 skrll
276 1.1 skrll EMPTY_HOWTO (14),
277 1.1 skrll EMPTY_HOWTO (15),
278 1.1 skrll EMPTY_HOWTO (16),
279 1.1 skrll EMPTY_HOWTO (17),
280 1.1 skrll EMPTY_HOWTO (18),
281 1.1 skrll EMPTY_HOWTO (19),
282 1.1 skrll
283 1.1 skrll /* Mark beginning of a jump instruction (any form). */
284 1.1 skrll HOWTO (R_M68HC11_RL_JUMP, /* type */
285 1.1 skrll 0, /* rightshift */
286 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
287 1.1 skrll 0, /* bitsize */
288 1.1 skrll FALSE, /* pc_relative */
289 1.1 skrll 0, /* bitpos */
290 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
291 1.1 skrll m68hc11_elf_ignore_reloc, /* special_function */
292 1.1 skrll "R_M68HC11_RL_JUMP", /* name */
293 1.1 skrll TRUE, /* partial_inplace */
294 1.1 skrll 0, /* src_mask */
295 1.1 skrll 0, /* dst_mask */
296 1.1.1.6 christos TRUE), /* pcrel_offset */
297 1.1 skrll
298 1.1 skrll /* Mark beginning of Gcc relaxation group instruction. */
299 1.1 skrll HOWTO (R_M68HC11_RL_GROUP, /* type */
300 1.1 skrll 0, /* rightshift */
301 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
302 1.1 skrll 0, /* bitsize */
303 1.1 skrll FALSE, /* pc_relative */
304 1.1 skrll 0, /* bitpos */
305 1.1 skrll complain_overflow_dont, /* complain_on_overflow */
306 1.1 skrll m68hc11_elf_ignore_reloc, /* special_function */
307 1.1 skrll "R_M68HC11_RL_GROUP", /* name */
308 1.1 skrll TRUE, /* partial_inplace */
309 1.1 skrll 0, /* src_mask */
310 1.1 skrll 0, /* dst_mask */
311 1.1.1.6 christos TRUE), /* pcrel_offset */
312 1.1 skrll };
313 1.1 skrll
314 1.1 skrll /* Map BFD reloc types to M68HC11 ELF reloc types. */
315 1.1 skrll
316 1.1 skrll struct m68hc11_reloc_map
317 1.1 skrll {
318 1.1 skrll bfd_reloc_code_real_type bfd_reloc_val;
319 1.1 skrll unsigned char elf_reloc_val;
320 1.1 skrll };
321 1.1 skrll
322 1.1 skrll static const struct m68hc11_reloc_map m68hc11_reloc_map[] = {
323 1.1 skrll {BFD_RELOC_NONE, R_M68HC11_NONE,},
324 1.1 skrll {BFD_RELOC_8, R_M68HC11_8},
325 1.1 skrll {BFD_RELOC_M68HC11_HI8, R_M68HC11_HI8},
326 1.1 skrll {BFD_RELOC_M68HC11_LO8, R_M68HC11_LO8},
327 1.1 skrll {BFD_RELOC_8_PCREL, R_M68HC11_PCREL_8},
328 1.1 skrll {BFD_RELOC_16_PCREL, R_M68HC11_PCREL_16},
329 1.1 skrll {BFD_RELOC_16, R_M68HC11_16},
330 1.1 skrll {BFD_RELOC_32, R_M68HC11_32},
331 1.1 skrll {BFD_RELOC_M68HC11_3B, R_M68HC11_3B},
332 1.1 skrll
333 1.1 skrll {BFD_RELOC_VTABLE_INHERIT, R_M68HC11_GNU_VTINHERIT},
334 1.1 skrll {BFD_RELOC_VTABLE_ENTRY, R_M68HC11_GNU_VTENTRY},
335 1.1 skrll
336 1.1 skrll {BFD_RELOC_M68HC11_LO16, R_M68HC11_LO16},
337 1.1 skrll {BFD_RELOC_M68HC11_PAGE, R_M68HC11_PAGE},
338 1.1 skrll {BFD_RELOC_M68HC11_24, R_M68HC11_24},
339 1.1 skrll
340 1.1 skrll {BFD_RELOC_M68HC11_RL_JUMP, R_M68HC11_RL_JUMP},
341 1.1 skrll {BFD_RELOC_M68HC11_RL_GROUP, R_M68HC11_RL_GROUP},
342 1.1 skrll };
343 1.1 skrll
344 1.1 skrll static reloc_howto_type *
345 1.1 skrll bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
346 1.1.1.6 christos bfd_reloc_code_real_type code)
347 1.1 skrll {
348 1.1 skrll unsigned int i;
349 1.1 skrll
350 1.1 skrll for (i = 0;
351 1.1 skrll i < sizeof (m68hc11_reloc_map) / sizeof (struct m68hc11_reloc_map);
352 1.1 skrll i++)
353 1.1 skrll {
354 1.1 skrll if (m68hc11_reloc_map[i].bfd_reloc_val == code)
355 1.1 skrll return &elf_m68hc11_howto_table[m68hc11_reloc_map[i].elf_reloc_val];
356 1.1 skrll }
357 1.1 skrll
358 1.1 skrll return NULL;
359 1.1 skrll }
360 1.1 skrll
361 1.1 skrll static reloc_howto_type *
362 1.1 skrll bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
363 1.1 skrll const char *r_name)
364 1.1 skrll {
365 1.1 skrll unsigned int i;
366 1.1 skrll
367 1.1 skrll for (i = 0;
368 1.1 skrll i < (sizeof (elf_m68hc11_howto_table)
369 1.1 skrll / sizeof (elf_m68hc11_howto_table[0]));
370 1.1 skrll i++)
371 1.1 skrll if (elf_m68hc11_howto_table[i].name != NULL
372 1.1 skrll && strcasecmp (elf_m68hc11_howto_table[i].name, r_name) == 0)
373 1.1 skrll return &elf_m68hc11_howto_table[i];
374 1.1 skrll
375 1.1 skrll return NULL;
376 1.1 skrll }
377 1.1 skrll
378 1.1 skrll /* Set the howto pointer for an M68HC11 ELF reloc. */
379 1.1 skrll
380 1.1.1.7 christos static bfd_boolean
381 1.1.1.7 christos m68hc11_info_to_howto_rel (bfd *abfd,
382 1.1.1.6 christos arelent *cache_ptr, Elf_Internal_Rela *dst)
383 1.1 skrll {
384 1.1 skrll unsigned int r_type;
385 1.1 skrll
386 1.1 skrll r_type = ELF32_R_TYPE (dst->r_info);
387 1.1.1.4 christos if (r_type >= (unsigned int) R_M68HC11_max)
388 1.1.1.4 christos {
389 1.1.1.6 christos /* xgettext:c-format */
390 1.1.1.7 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
391 1.1.1.7 christos abfd, r_type);
392 1.1.1.7 christos bfd_set_error (bfd_error_bad_value);
393 1.1.1.7 christos return FALSE;
394 1.1.1.4 christos }
395 1.1 skrll cache_ptr->howto = &elf_m68hc11_howto_table[r_type];
396 1.1.1.7 christos return TRUE;
397 1.1 skrll }
398 1.1 skrll
399 1.1 skrll
400 1.1 skrll /* Far trampoline generation. */
402 1.1 skrll
403 1.1 skrll /* Build a 68HC11 trampoline stub. */
404 1.1 skrll static bfd_boolean
405 1.1 skrll m68hc11_elf_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
406 1.1 skrll {
407 1.1 skrll struct elf32_m68hc11_stub_hash_entry *stub_entry;
408 1.1 skrll struct bfd_link_info *info;
409 1.1 skrll struct m68hc11_elf_link_hash_table *htab;
410 1.1 skrll asection *stub_sec;
411 1.1 skrll bfd *stub_bfd;
412 1.1 skrll bfd_byte *loc;
413 1.1 skrll bfd_vma sym_value, phys_page, phys_addr;
414 1.1 skrll
415 1.1 skrll /* Massage our args to the form they really have. */
416 1.1 skrll stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry;
417 1.1 skrll info = (struct bfd_link_info *) in_arg;
418 1.1 skrll
419 1.1.1.2 christos htab = m68hc11_elf_hash_table (info);
420 1.1.1.2 christos if (htab == NULL)
421 1.1 skrll return FALSE;
422 1.1 skrll
423 1.1 skrll stub_sec = stub_entry->stub_sec;
424 1.1 skrll
425 1.1 skrll /* Make a note of the offset within the stubs for this entry. */
426 1.1 skrll stub_entry->stub_offset = stub_sec->size;
427 1.1 skrll stub_sec->size += 10;
428 1.1 skrll loc = stub_sec->contents + stub_entry->stub_offset;
429 1.1 skrll
430 1.1 skrll stub_bfd = stub_sec->owner;
431 1.1 skrll
432 1.1 skrll /* Create the trampoline call stub:
433 1.1 skrll
434 1.1 skrll pshb
435 1.1 skrll ldab #%page(symbol)
436 1.1 skrll ldy #%addr(symbol)
437 1.1 skrll jmp __trampoline
438 1.1 skrll
439 1.1 skrll */
440 1.1.1.6 christos sym_value = (stub_entry->target_value
441 1.1.1.6 christos + stub_entry->target_section->output_offset
442 1.1 skrll + stub_entry->target_section->output_section->vma);
443 1.1 skrll phys_addr = m68hc11_phys_addr (&htab->pinfo, sym_value);
444 1.1 skrll phys_page = m68hc11_phys_page (&htab->pinfo, sym_value);
445 1.1 skrll
446 1.1 skrll /* pshb; ldab #%page(sym) */
447 1.1 skrll bfd_put_8 (stub_bfd, 0x37, loc);
448 1.1 skrll bfd_put_8 (stub_bfd, 0xC6, loc + 1);
449 1.1 skrll bfd_put_8 (stub_bfd, phys_page, loc + 2);
450 1.1 skrll loc += 3;
451 1.1 skrll
452 1.1 skrll /* ldy #%addr(sym) */
453 1.1 skrll bfd_put_8 (stub_bfd, 0x18, loc);
454 1.1 skrll bfd_put_8 (stub_bfd, 0xCE, loc + 1);
455 1.1 skrll bfd_put_16 (stub_bfd, phys_addr, loc + 2);
456 1.1 skrll loc += 4;
457 1.1 skrll
458 1.1 skrll /* jmp __trampoline */
459 1.1 skrll bfd_put_8 (stub_bfd, 0x7E, loc);
460 1.1 skrll bfd_put_16 (stub_bfd, htab->pinfo.trampoline_addr, loc + 1);
461 1.1 skrll
462 1.1 skrll return TRUE;
463 1.1 skrll }
464 1.1 skrll
465 1.1 skrll /* As above, but don't actually build the stub. Just bump offset so
466 1.1 skrll we know stub section sizes. */
467 1.1 skrll
468 1.1 skrll static bfd_boolean
469 1.1.1.6 christos m68hc11_elf_size_one_stub (struct bfd_hash_entry *gen_entry,
470 1.1 skrll void *in_arg ATTRIBUTE_UNUSED)
471 1.1 skrll {
472 1.1 skrll struct elf32_m68hc11_stub_hash_entry *stub_entry;
473 1.1 skrll
474 1.1 skrll /* Massage our args to the form they really have. */
475 1.1 skrll stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry;
476 1.1 skrll
477 1.1 skrll stub_entry->stub_sec->size += 10;
478 1.1 skrll return TRUE;
479 1.1 skrll }
480 1.1 skrll
481 1.1 skrll /* Create a 68HC11 ELF linker hash table. */
482 1.1 skrll
483 1.1 skrll static struct bfd_link_hash_table *
484 1.1 skrll m68hc11_elf_bfd_link_hash_table_create (bfd *abfd)
485 1.1 skrll {
486 1.1 skrll struct m68hc11_elf_link_hash_table *ret;
487 1.1 skrll
488 1.1 skrll ret = m68hc11_elf_hash_table_create (abfd);
489 1.1 skrll if (ret == (struct m68hc11_elf_link_hash_table *) NULL)
490 1.1 skrll return NULL;
491 1.1 skrll
492 1.1 skrll ret->size_one_stub = m68hc11_elf_size_one_stub;
493 1.1 skrll ret->build_one_stub = m68hc11_elf_build_one_stub;
494 1.1 skrll
495 1.1 skrll return &ret->root.root;
496 1.1 skrll }
497 1.1 skrll
498 1.1 skrll
499 1.1 skrll /* 68HC11 Linker Relaxation. */
501 1.1 skrll
502 1.1 skrll struct m68hc11_direct_relax
503 1.1 skrll {
504 1.1 skrll const char *name;
505 1.1 skrll unsigned char code;
506 1.1 skrll unsigned char direct_code;
507 1.1 skrll } m68hc11_direct_relax_table[] = {
508 1.1 skrll { "adca", 0xB9, 0x99 },
509 1.1 skrll { "adcb", 0xF9, 0xD9 },
510 1.1 skrll { "adda", 0xBB, 0x9B },
511 1.1 skrll { "addb", 0xFB, 0xDB },
512 1.1 skrll { "addd", 0xF3, 0xD3 },
513 1.1 skrll { "anda", 0xB4, 0x94 },
514 1.1 skrll { "andb", 0xF4, 0xD4 },
515 1.1 skrll { "cmpa", 0xB1, 0x91 },
516 1.1 skrll { "cmpb", 0xF1, 0xD1 },
517 1.1 skrll { "cpd", 0xB3, 0x93 },
518 1.1 skrll { "cpxy", 0xBC, 0x9C },
519 1.1 skrll /* { "cpy", 0xBC, 0x9C }, */
520 1.1 skrll { "eora", 0xB8, 0x98 },
521 1.1 skrll { "eorb", 0xF8, 0xD8 },
522 1.1 skrll { "jsr", 0xBD, 0x9D },
523 1.1 skrll { "ldaa", 0xB6, 0x96 },
524 1.1 skrll { "ldab", 0xF6, 0xD6 },
525 1.1 skrll { "ldd", 0xFC, 0xDC },
526 1.1 skrll { "lds", 0xBE, 0x9E },
527 1.1 skrll { "ldxy", 0xFE, 0xDE },
528 1.1 skrll /* { "ldy", 0xFE, 0xDE },*/
529 1.1 skrll { "oraa", 0xBA, 0x9A },
530 1.1 skrll { "orab", 0xFA, 0xDA },
531 1.1 skrll { "sbca", 0xB2, 0x92 },
532 1.1 skrll { "sbcb", 0xF2, 0xD2 },
533 1.1 skrll { "staa", 0xB7, 0x97 },
534 1.1 skrll { "stab", 0xF7, 0xD7 },
535 1.1 skrll { "std", 0xFD, 0xDD },
536 1.1 skrll { "sts", 0xBF, 0x9F },
537 1.1 skrll { "stxy", 0xFF, 0xDF },
538 1.1 skrll /* { "sty", 0xFF, 0xDF },*/
539 1.1 skrll { "suba", 0xB0, 0x90 },
540 1.1 skrll { "subb", 0xF0, 0xD0 },
541 1.1 skrll { "subd", 0xB3, 0x93 },
542 1.1 skrll { 0, 0, 0 }
543 1.1 skrll };
544 1.1 skrll
545 1.1 skrll static struct m68hc11_direct_relax *
546 1.1 skrll find_relaxable_insn (unsigned char code)
547 1.1 skrll {
548 1.1 skrll int i;
549 1.1 skrll
550 1.1 skrll for (i = 0; m68hc11_direct_relax_table[i].name; i++)
551 1.1 skrll if (m68hc11_direct_relax_table[i].code == code)
552 1.1 skrll return &m68hc11_direct_relax_table[i];
553 1.1 skrll
554 1.1 skrll return 0;
555 1.1 skrll }
556 1.1 skrll
557 1.1 skrll static int
558 1.1 skrll compare_reloc (const void *e1, const void *e2)
559 1.1 skrll {
560 1.1 skrll const Elf_Internal_Rela *i1 = (const Elf_Internal_Rela *) e1;
561 1.1 skrll const Elf_Internal_Rela *i2 = (const Elf_Internal_Rela *) e2;
562 1.1 skrll
563 1.1 skrll if (i1->r_offset == i2->r_offset)
564 1.1 skrll return 0;
565 1.1 skrll else
566 1.1 skrll return i1->r_offset < i2->r_offset ? -1 : 1;
567 1.1 skrll }
568 1.1 skrll
569 1.1 skrll #define M6811_OP_LDX_IMMEDIATE (0xCE)
570 1.1 skrll
571 1.1.1.6 christos static void
572 1.1.1.6 christos m68hc11_relax_group (bfd *abfd, asection *sec, bfd_byte *contents,
573 1.1 skrll unsigned value, unsigned long offset,
574 1.1 skrll unsigned long end_group)
575 1.1 skrll {
576 1.1 skrll unsigned char code;
577 1.1 skrll unsigned long start_offset;
578 1.1 skrll unsigned long ldx_offset = offset;
579 1.1 skrll unsigned long ldx_size;
580 1.1 skrll int can_delete_ldx;
581 1.1 skrll int relax_ldy = 0;
582 1.1 skrll
583 1.1 skrll /* First instruction of the relax group must be a
584 1.1 skrll LDX #value or LDY #value. If this is not the case,
585 1.1 skrll ignore the relax group. */
586 1.1 skrll code = bfd_get_8 (abfd, contents + offset);
587 1.1 skrll if (code == 0x18)
588 1.1 skrll {
589 1.1 skrll relax_ldy++;
590 1.1 skrll offset++;
591 1.1 skrll code = bfd_get_8 (abfd, contents + offset);
592 1.1 skrll }
593 1.1 skrll ldx_size = offset - ldx_offset + 3;
594 1.1 skrll offset += 3;
595 1.1 skrll if (code != M6811_OP_LDX_IMMEDIATE || offset >= end_group)
596 1.1 skrll return;
597 1.1 skrll
598 1.1 skrll
599 1.1 skrll /* We can remove the LDX/LDY only when all bset/brclr instructions
600 1.1 skrll of the relax group have been converted to use direct addressing
601 1.1 skrll mode. */
602 1.1 skrll can_delete_ldx = 1;
603 1.1 skrll while (offset < end_group)
604 1.1 skrll {
605 1.1 skrll unsigned isize;
606 1.1 skrll unsigned new_value;
607 1.1 skrll int bset_use_y;
608 1.1 skrll
609 1.1 skrll bset_use_y = 0;
610 1.1 skrll start_offset = offset;
611 1.1.1.6 christos code = bfd_get_8 (abfd, contents + offset);
612 1.1.1.6 christos if (code == 0x18)
613 1.1.1.6 christos {
614 1.1.1.6 christos bset_use_y++;
615 1.1.1.6 christos offset++;
616 1.1 skrll code = bfd_get_8 (abfd, contents + offset);
617 1.1 skrll }
618 1.1 skrll
619 1.1.1.6 christos /* Check the instruction and translate to use direct addressing mode. */
620 1.1.1.6 christos switch (code)
621 1.1.1.6 christos {
622 1.1.1.6 christos /* bset */
623 1.1.1.6 christos case 0x1C:
624 1.1.1.6 christos code = 0x14;
625 1.1.1.6 christos isize = 3;
626 1.1.1.6 christos break;
627 1.1.1.6 christos
628 1.1.1.6 christos /* brclr */
629 1.1.1.6 christos case 0x1F:
630 1.1.1.6 christos code = 0x13;
631 1.1.1.6 christos isize = 4;
632 1.1.1.6 christos break;
633 1.1.1.6 christos
634 1.1.1.6 christos /* brset */
635 1.1.1.6 christos case 0x1E:
636 1.1.1.6 christos code = 0x12;
637 1.1.1.6 christos isize = 4;
638 1.1.1.6 christos break;
639 1.1.1.6 christos
640 1.1.1.6 christos /* bclr */
641 1.1.1.6 christos case 0x1D:
642 1.1.1.6 christos code = 0x15;
643 1.1.1.6 christos isize = 3;
644 1.1.1.6 christos break;
645 1.1.1.6 christos
646 1.1.1.6 christos /* This instruction is not recognized and we are not
647 1.1.1.6 christos at end of the relax group. Ignore and don't remove
648 1.1.1.6 christos the first LDX (we don't know what it is used for...). */
649 1.1.1.6 christos default:
650 1.1 skrll return;
651 1.1 skrll }
652 1.1 skrll new_value = (unsigned) bfd_get_8 (abfd, contents + offset + 1);
653 1.1.1.6 christos new_value += value;
654 1.1.1.6 christos if ((new_value & 0xff00) == 0 && bset_use_y == relax_ldy)
655 1.1.1.6 christos {
656 1.1.1.6 christos bfd_put_8 (abfd, code, contents + offset);
657 1.1.1.6 christos bfd_put_8 (abfd, new_value, contents + offset + 1);
658 1.1.1.6 christos if (start_offset != offset)
659 1.1.1.6 christos {
660 1.1.1.6 christos m68hc11_elf_relax_delete_bytes (abfd, sec, start_offset,
661 1.1.1.6 christos offset - start_offset);
662 1.1.1.6 christos end_group--;
663 1.1 skrll }
664 1.1.1.6 christos }
665 1.1.1.6 christos else
666 1.1.1.6 christos {
667 1.1 skrll can_delete_ldx = 0;
668 1.1 skrll }
669 1.1 skrll offset = start_offset + isize;
670 1.1 skrll }
671 1.1 skrll if (can_delete_ldx)
672 1.1 skrll {
673 1.1 skrll /* Remove the move instruction (3 or 4 bytes win). */
674 1.1 skrll m68hc11_elf_relax_delete_bytes (abfd, sec, ldx_offset, ldx_size);
675 1.1 skrll }
676 1.1 skrll }
677 1.1 skrll
678 1.1 skrll /* This function handles relaxing for the 68HC11.
679 1.1 skrll
680 1.1 skrll
681 1.1 skrll and somewhat more difficult to support. */
682 1.1 skrll
683 1.1.1.6 christos static bfd_boolean
684 1.1 skrll m68hc11_elf_relax_section (bfd *abfd, asection *sec,
685 1.1 skrll struct bfd_link_info *link_info, bfd_boolean *again)
686 1.1 skrll {
687 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
688 1.1 skrll Elf_Internal_Rela *internal_relocs;
689 1.1 skrll Elf_Internal_Rela *free_relocs = NULL;
690 1.1 skrll Elf_Internal_Rela *irel, *irelend;
691 1.1 skrll bfd_byte *contents = NULL;
692 1.1 skrll bfd_byte *free_contents = NULL;
693 1.1 skrll Elf32_External_Sym *free_extsyms = NULL;
694 1.1 skrll Elf_Internal_Rela *prev_insn_branch = NULL;
695 1.1 skrll Elf_Internal_Rela *prev_insn_group = NULL;
696 1.1 skrll unsigned insn_group_value = 0;
697 1.1 skrll Elf_Internal_Sym *isymbuf = NULL;
698 1.1 skrll
699 1.1 skrll /* Assume nothing changes. */
700 1.1 skrll *again = FALSE;
701 1.1 skrll
702 1.1 skrll /* We don't have to do anything for a relocatable link, if
703 1.1.1.4 christos this section does not have relocs, or if this is not a
704 1.1 skrll code section. */
705 1.1 skrll if (bfd_link_relocatable (link_info)
706 1.1 skrll || (sec->flags & SEC_RELOC) == 0
707 1.1 skrll || sec->reloc_count == 0
708 1.1 skrll || (sec->flags & SEC_CODE) == 0)
709 1.1 skrll return TRUE;
710 1.1 skrll
711 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
712 1.1 skrll
713 1.1.1.3 christos /* Get a copy of the native relocations. */
714 1.1 skrll internal_relocs = (_bfd_elf_link_read_relocs
715 1.1 skrll (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
716 1.1 skrll link_info->keep_memory));
717 1.1 skrll if (internal_relocs == NULL)
718 1.1 skrll goto error_return;
719 1.1 skrll if (! link_info->keep_memory)
720 1.1 skrll free_relocs = internal_relocs;
721 1.1 skrll
722 1.1 skrll /* Checking for branch relaxation relies on the relocations to
723 1.1.1.6 christos be sorted on 'r_offset'. This is not guaranteed so we must sort. */
724 1.1 skrll qsort (internal_relocs, sec->reloc_count, sizeof (Elf_Internal_Rela),
725 1.1 skrll compare_reloc);
726 1.1 skrll
727 1.1 skrll /* Walk through them looking for relaxing opportunities. */
728 1.1 skrll irelend = internal_relocs + sec->reloc_count;
729 1.1 skrll for (irel = internal_relocs; irel < irelend; irel++)
730 1.1 skrll {
731 1.1 skrll bfd_vma symval;
732 1.1 skrll bfd_vma value;
733 1.1 skrll Elf_Internal_Sym *isym;
734 1.1 skrll asection *sym_sec;
735 1.1 skrll int is_far = 0;
736 1.1 skrll
737 1.1 skrll /* If this isn't something that can be relaxed, then ignore
738 1.1.1.6 christos this reloc. */
739 1.1.1.6 christos if (ELF32_R_TYPE (irel->r_info) != (int) R_M68HC11_16
740 1.1.1.6 christos && ELF32_R_TYPE (irel->r_info) != (int) R_M68HC11_RL_JUMP
741 1.1.1.6 christos && ELF32_R_TYPE (irel->r_info) != (int) R_M68HC11_RL_GROUP)
742 1.1.1.6 christos {
743 1.1.1.6 christos prev_insn_branch = 0;
744 1.1.1.6 christos prev_insn_group = 0;
745 1.1 skrll continue;
746 1.1 skrll }
747 1.1 skrll
748 1.1 skrll /* Get the section contents if we haven't done so already. */
749 1.1 skrll if (contents == NULL)
750 1.1 skrll {
751 1.1 skrll /* Get cached copy if it exists. */
752 1.1 skrll if (elf_section_data (sec)->this_hdr.contents != NULL)
753 1.1 skrll contents = elf_section_data (sec)->this_hdr.contents;
754 1.1 skrll else
755 1.1 skrll {
756 1.1 skrll /* Go get them off disk. */
757 1.1 skrll if (!bfd_malloc_and_get_section (abfd, sec, &contents))
758 1.1 skrll goto error_return;
759 1.1 skrll }
760 1.1 skrll }
761 1.1 skrll
762 1.1 skrll /* Try to eliminate an unconditional 8 bit pc-relative branch
763 1.1 skrll which immediately follows a conditional 8 bit pc-relative
764 1.1 skrll branch around the unconditional branch.
765 1.1 skrll
766 1.1 skrll original: new:
767 1.1 skrll bCC lab1 bCC' lab2
768 1.1 skrll bra lab2
769 1.1 skrll lab1: lab1:
770 1.1 skrll
771 1.1 skrll This happens when the bCC can't reach lab2 at assembly time,
772 1.1 skrll but due to other relaxations it can reach at link time. */
773 1.1 skrll if (ELF32_R_TYPE (irel->r_info) == (int) R_M68HC11_RL_JUMP)
774 1.1 skrll {
775 1.1.1.6 christos Elf_Internal_Rela *nrel;
776 1.1 skrll unsigned char code;
777 1.1.1.6 christos unsigned char roffset;
778 1.1.1.6 christos
779 1.1 skrll prev_insn_branch = 0;
780 1.1 skrll prev_insn_group = 0;
781 1.1 skrll
782 1.1 skrll /* Do nothing if this reloc is the last byte in the section. */
783 1.1 skrll if (irel->r_offset + 2 >= sec->size)
784 1.1 skrll continue;
785 1.1 skrll
786 1.1 skrll /* See if the next instruction is an unconditional pc-relative
787 1.1 skrll branch, more often than not this test will fail, so we
788 1.1 skrll test it first to speed things up. */
789 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset + 2);
790 1.1 skrll if (code != 0x7e)
791 1.1 skrll continue;
792 1.1 skrll
793 1.1 skrll /* Also make sure the next relocation applies to the next
794 1.1 skrll instruction and that it's a pc-relative 8 bit branch. */
795 1.1 skrll nrel = irel + 1;
796 1.1 skrll if (nrel == irelend
797 1.1 skrll || irel->r_offset + 3 != nrel->r_offset
798 1.1 skrll || ELF32_R_TYPE (nrel->r_info) != (int) R_M68HC11_16)
799 1.1 skrll continue;
800 1.1 skrll
801 1.1.1.6 christos /* Make sure our destination immediately follows the
802 1.1.1.6 christos unconditional branch. */
803 1.1.1.6 christos roffset = bfd_get_8 (abfd, contents + irel->r_offset + 1);
804 1.1.1.6 christos if (roffset != 3)
805 1.1.1.6 christos continue;
806 1.1.1.6 christos
807 1.1.1.6 christos prev_insn_branch = irel;
808 1.1.1.6 christos prev_insn_group = 0;
809 1.1 skrll continue;
810 1.1 skrll }
811 1.1 skrll
812 1.1 skrll /* Read this BFD's symbols if we haven't done so already. */
813 1.1 skrll if (isymbuf == NULL && symtab_hdr->sh_info != 0)
814 1.1 skrll {
815 1.1 skrll isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
816 1.1 skrll if (isymbuf == NULL)
817 1.1 skrll isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
818 1.1 skrll symtab_hdr->sh_info, 0,
819 1.1 skrll NULL, NULL, NULL);
820 1.1 skrll if (isymbuf == NULL)
821 1.1 skrll goto error_return;
822 1.1 skrll }
823 1.1 skrll
824 1.1 skrll /* Get the value of the symbol referred to by the reloc. */
825 1.1 skrll if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
826 1.1 skrll {
827 1.1.1.6 christos /* A local symbol. */
828 1.1.1.6 christos isym = isymbuf + ELF32_R_SYM (irel->r_info);
829 1.1 skrll is_far = isym->st_other & STO_M68HC12_FAR;
830 1.1 skrll sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
831 1.1 skrll symval = (isym->st_value
832 1.1 skrll + sym_sec->output_section->vma
833 1.1 skrll + sym_sec->output_offset);
834 1.1 skrll }
835 1.1 skrll else
836 1.1 skrll {
837 1.1 skrll unsigned long indx;
838 1.1 skrll struct elf_link_hash_entry *h;
839 1.1 skrll
840 1.1 skrll /* An external symbol. */
841 1.1 skrll indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
842 1.1 skrll h = elf_sym_hashes (abfd)[indx];
843 1.1 skrll BFD_ASSERT (h != NULL);
844 1.1 skrll if (h->root.type != bfd_link_hash_defined
845 1.1 skrll && h->root.type != bfd_link_hash_defweak)
846 1.1.1.6 christos {
847 1.1.1.6 christos /* This appears to be a reference to an undefined
848 1.1.1.6 christos symbol. Just ignore it--it will be caught by the
849 1.1.1.6 christos regular reloc processing. */
850 1.1 skrll prev_insn_branch = 0;
851 1.1 skrll prev_insn_group = 0;
852 1.1 skrll continue;
853 1.1.1.6 christos }
854 1.1.1.6 christos
855 1.1.1.6 christos is_far = h->other & STO_M68HC12_FAR;
856 1.1 skrll isym = 0;
857 1.1 skrll sym_sec = h->root.u.def.section;
858 1.1 skrll symval = (h->root.u.def.value
859 1.1 skrll + sym_sec->output_section->vma
860 1.1 skrll + sym_sec->output_offset);
861 1.1 skrll }
862 1.1 skrll
863 1.1.1.6 christos if (ELF32_R_TYPE (irel->r_info) == (int) R_M68HC11_RL_GROUP)
864 1.1.1.6 christos {
865 1.1 skrll prev_insn_branch = 0;
866 1.1 skrll prev_insn_group = 0;
867 1.1 skrll
868 1.1 skrll /* Do nothing if this reloc is the last byte in the section. */
869 1.1 skrll if (irel->r_offset == sec->size)
870 1.1.1.6 christos continue;
871 1.1.1.6 christos
872 1.1.1.6 christos prev_insn_group = irel;
873 1.1.1.6 christos insn_group_value = isym->st_value;
874 1.1 skrll continue;
875 1.1 skrll }
876 1.1.1.6 christos
877 1.1.1.6 christos /* When we relax some bytes, the size of our section changes.
878 1.1.1.6 christos This affects the layout of next input sections that go in our
879 1.1.1.6 christos output section. When the symbol is part of another section that
880 1.1.1.6 christos will go in the same output section as the current one, it's
881 1.1.1.6 christos final address may now be incorrect (too far). We must let the
882 1.1.1.6 christos linker re-compute all section offsets before processing this
883 1.1.1.6 christos reloc. Code example:
884 1.1.1.6 christos
885 1.1.1.6 christos Initial Final
886 1.1.1.6 christos .sect .text section size = 6 section size = 4
887 1.1.1.6 christos jmp foo
888 1.1.1.6 christos jmp bar
889 1.1.1.6 christos .sect .text.foo_bar output_offset = 6 output_offset = 4
890 1.1 skrll foo: rts
891 1.1.1.6 christos bar: rts
892 1.1.1.6 christos
893 1.1 skrll If we process the reloc now, the jmp bar is replaced by a
894 1.1.1.6 christos relative branch to the initial bar address (output_offset 6). */
895 1.1.1.6 christos if (*again && sym_sec != sec
896 1.1.1.6 christos && sym_sec->output_section == sec->output_section)
897 1.1.1.6 christos {
898 1.1.1.6 christos prev_insn_group = 0;
899 1.1.1.6 christos prev_insn_branch = 0;
900 1.1 skrll continue;
901 1.1 skrll }
902 1.1 skrll
903 1.1 skrll value = symval;
904 1.1.1.6 christos /* Try to turn a far branch to a near branch. */
905 1.1.1.6 christos if (ELF32_R_TYPE (irel->r_info) == (int) R_M68HC11_16
906 1.1.1.6 christos && prev_insn_branch)
907 1.1.1.6 christos {
908 1.1.1.6 christos bfd_vma offset;
909 1.1.1.6 christos unsigned char code;
910 1.1.1.6 christos
911 1.1.1.6 christos offset = value - (prev_insn_branch->r_offset
912 1.1.1.6 christos + sec->output_section->vma
913 1.1.1.6 christos + sec->output_offset + 2);
914 1.1.1.6 christos
915 1.1.1.6 christos /* If the offset is still out of -128..+127 range,
916 1.1.1.6 christos leave that far branch unchanged. */
917 1.1.1.6 christos if ((offset & 0xff80) != 0 && (offset & 0xff80) != 0xff80)
918 1.1.1.6 christos {
919 1.1.1.6 christos prev_insn_branch = 0;
920 1.1.1.6 christos continue;
921 1.1.1.6 christos }
922 1.1.1.6 christos
923 1.1.1.6 christos /* Shrink the branch. */
924 1.1.1.6 christos code = bfd_get_8 (abfd, contents + prev_insn_branch->r_offset);
925 1.1.1.6 christos if (code == 0x7e)
926 1.1.1.6 christos {
927 1.1.1.6 christos code = 0x20;
928 1.1.1.6 christos bfd_put_8 (abfd, code, contents + prev_insn_branch->r_offset);
929 1.1.1.6 christos bfd_put_8 (abfd, 0xff,
930 1.1.1.6 christos contents + prev_insn_branch->r_offset + 1);
931 1.1.1.6 christos irel->r_offset = prev_insn_branch->r_offset + 1;
932 1.1.1.6 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
933 1.1.1.6 christos R_M68HC11_PCREL_8);
934 1.1.1.6 christos m68hc11_elf_relax_delete_bytes (abfd, sec,
935 1.1.1.6 christos irel->r_offset + 1, 1);
936 1.1.1.6 christos }
937 1.1.1.6 christos else
938 1.1.1.6 christos {
939 1.1.1.6 christos code ^= 0x1;
940 1.1.1.6 christos bfd_put_8 (abfd, code, contents + prev_insn_branch->r_offset);
941 1.1.1.6 christos bfd_put_8 (abfd, 0xff,
942 1.1.1.6 christos contents + prev_insn_branch->r_offset + 1);
943 1.1.1.6 christos irel->r_offset = prev_insn_branch->r_offset + 1;
944 1.1.1.6 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
945 1.1.1.6 christos R_M68HC11_PCREL_8);
946 1.1.1.6 christos m68hc11_elf_relax_delete_bytes (abfd, sec,
947 1.1.1.6 christos irel->r_offset + 1, 3);
948 1.1.1.6 christos }
949 1.1.1.6 christos prev_insn_branch = 0;
950 1.1 skrll *again = TRUE;
951 1.1 skrll }
952 1.1 skrll
953 1.1.1.6 christos /* Try to turn a 16 bit address into a 8 bit page0 address. */
954 1.1 skrll else if (ELF32_R_TYPE (irel->r_info) == (int) R_M68HC11_16
955 1.1.1.6 christos && (value & 0xff00) == 0)
956 1.1.1.6 christos {
957 1.1.1.6 christos unsigned char code;
958 1.1.1.6 christos unsigned short offset;
959 1.1.1.6 christos struct m68hc11_direct_relax *rinfo;
960 1.1.1.6 christos
961 1.1.1.6 christos prev_insn_branch = 0;
962 1.1.1.6 christos offset = bfd_get_16 (abfd, contents + irel->r_offset);
963 1.1.1.6 christos offset += value;
964 1.1.1.6 christos if ((offset & 0xff00) != 0)
965 1.1.1.6 christos {
966 1.1.1.6 christos prev_insn_group = 0;
967 1.1.1.6 christos continue;
968 1.1.1.6 christos }
969 1.1.1.6 christos
970 1.1.1.6 christos if (prev_insn_group)
971 1.1.1.6 christos {
972 1.1.1.6 christos unsigned long old_sec_size = sec->size;
973 1.1.1.6 christos
974 1.1.1.6 christos /* Note that we've changed the relocation contents, etc. */
975 1.1.1.6 christos elf_section_data (sec)->relocs = internal_relocs;
976 1.1.1.6 christos free_relocs = NULL;
977 1.1.1.6 christos
978 1.1.1.6 christos elf_section_data (sec)->this_hdr.contents = contents;
979 1.1.1.6 christos free_contents = NULL;
980 1.1.1.6 christos
981 1.1.1.6 christos symtab_hdr->contents = (bfd_byte *) isymbuf;
982 1.1.1.6 christos free_extsyms = NULL;
983 1.1.1.6 christos
984 1.1.1.6 christos m68hc11_relax_group (abfd, sec, contents, offset,
985 1.1.1.6 christos prev_insn_group->r_offset,
986 1.1.1.6 christos insn_group_value);
987 1.1.1.6 christos irel = prev_insn_group;
988 1.1.1.6 christos prev_insn_group = 0;
989 1.1.1.6 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
990 1.1.1.6 christos R_M68HC11_NONE);
991 1.1.1.6 christos if (sec->size != old_sec_size)
992 1.1.1.6 christos *again = TRUE;
993 1.1.1.6 christos continue;
994 1.1.1.6 christos }
995 1.1.1.6 christos
996 1.1.1.6 christos /* Get the opcode. */
997 1.1.1.6 christos code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
998 1.1.1.6 christos rinfo = find_relaxable_insn (code);
999 1.1.1.6 christos if (rinfo == 0)
1000 1.1.1.6 christos {
1001 1.1.1.6 christos prev_insn_group = 0;
1002 1.1.1.6 christos continue;
1003 1.1.1.6 christos }
1004 1.1.1.6 christos
1005 1.1.1.6 christos /* Note that we've changed the relocation contents, etc. */
1006 1.1.1.6 christos elf_section_data (sec)->relocs = internal_relocs;
1007 1.1.1.6 christos free_relocs = NULL;
1008 1.1.1.6 christos
1009 1.1.1.6 christos elf_section_data (sec)->this_hdr.contents = contents;
1010 1.1.1.6 christos free_contents = NULL;
1011 1.1.1.6 christos
1012 1.1.1.6 christos symtab_hdr->contents = (bfd_byte *) isymbuf;
1013 1.1.1.6 christos free_extsyms = NULL;
1014 1.1.1.6 christos
1015 1.1.1.6 christos /* Fix the opcode. */
1016 1.1.1.6 christos /* printf ("A relaxable case : 0x%02x (%s)\n",
1017 1.1.1.6 christos code, rinfo->name); */
1018 1.1.1.6 christos bfd_put_8 (abfd, rinfo->direct_code,
1019 1.1.1.6 christos contents + irel->r_offset - 1);
1020 1.1.1.6 christos
1021 1.1.1.6 christos /* Delete one byte of data (upper byte of address). */
1022 1.1.1.6 christos m68hc11_elf_relax_delete_bytes (abfd, sec, irel->r_offset, 1);
1023 1.1.1.6 christos
1024 1.1.1.6 christos /* Fix the relocation's type. */
1025 1.1.1.6 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1026 1.1.1.6 christos R_M68HC11_8);
1027 1.1.1.6 christos
1028 1.1.1.6 christos /* That will change things, so, we should relax again. */
1029 1.1 skrll *again = TRUE;
1030 1.1.1.6 christos }
1031 1.1.1.6 christos else if (ELF32_R_TYPE (irel->r_info) == R_M68HC11_16 && !is_far)
1032 1.1.1.6 christos {
1033 1.1.1.6 christos unsigned char code;
1034 1.1.1.6 christos bfd_vma offset;
1035 1.1.1.6 christos
1036 1.1.1.6 christos prev_insn_branch = 0;
1037 1.1.1.6 christos code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
1038 1.1.1.6 christos if (code == 0x7e || code == 0xbd)
1039 1.1.1.6 christos {
1040 1.1.1.6 christos offset = value - (irel->r_offset
1041 1.1.1.6 christos + sec->output_section->vma
1042 1.1.1.6 christos + sec->output_offset + 1);
1043 1.1.1.6 christos offset += bfd_get_16 (abfd, contents + irel->r_offset);
1044 1.1.1.6 christos
1045 1.1.1.6 christos /* If the offset is still out of -128..+127 range,
1046 1.1.1.6 christos leave that far branch unchanged. */
1047 1.1.1.6 christos if ((offset & 0xff80) == 0 || (offset & 0xff80) == 0xff80)
1048 1.1.1.6 christos {
1049 1.1.1.6 christos
1050 1.1.1.6 christos /* Note that we've changed the relocation contents, etc. */
1051 1.1.1.6 christos elf_section_data (sec)->relocs = internal_relocs;
1052 1.1.1.6 christos free_relocs = NULL;
1053 1.1.1.6 christos
1054 1.1.1.6 christos elf_section_data (sec)->this_hdr.contents = contents;
1055 1.1.1.6 christos free_contents = NULL;
1056 1.1.1.6 christos
1057 1.1.1.6 christos symtab_hdr->contents = (bfd_byte *) isymbuf;
1058 1.1.1.6 christos free_extsyms = NULL;
1059 1.1.1.6 christos
1060 1.1.1.6 christos /* Shrink the branch. */
1061 1.1.1.6 christos code = (code == 0x7e) ? 0x20 : 0x8d;
1062 1.1.1.6 christos bfd_put_8 (abfd, code,
1063 1.1.1.6 christos contents + irel->r_offset - 1);
1064 1.1.1.6 christos bfd_put_8 (abfd, 0xff,
1065 1.1.1.6 christos contents + irel->r_offset);
1066 1.1.1.6 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1067 1.1.1.6 christos R_M68HC11_PCREL_8);
1068 1.1.1.6 christos m68hc11_elf_relax_delete_bytes (abfd, sec,
1069 1.1.1.6 christos irel->r_offset + 1, 1);
1070 1.1.1.6 christos /* That will change things, so, we should relax again. */
1071 1.1.1.6 christos *again = TRUE;
1072 1.1.1.6 christos }
1073 1.1 skrll }
1074 1.1 skrll }
1075 1.1 skrll prev_insn_branch = 0;
1076 1.1 skrll prev_insn_group = 0;
1077 1.1 skrll }
1078 1.1 skrll
1079 1.1 skrll if (free_relocs != NULL)
1080 1.1 skrll {
1081 1.1 skrll free (free_relocs);
1082 1.1 skrll free_relocs = NULL;
1083 1.1 skrll }
1084 1.1 skrll
1085 1.1 skrll if (free_contents != NULL)
1086 1.1 skrll {
1087 1.1 skrll if (! link_info->keep_memory)
1088 1.1 skrll free (free_contents);
1089 1.1 skrll else
1090 1.1 skrll {
1091 1.1 skrll /* Cache the section contents for elf_link_input_bfd. */
1092 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
1093 1.1 skrll }
1094 1.1 skrll free_contents = NULL;
1095 1.1 skrll }
1096 1.1 skrll
1097 1.1 skrll if (free_extsyms != NULL)
1098 1.1 skrll {
1099 1.1 skrll if (! link_info->keep_memory)
1100 1.1 skrll free (free_extsyms);
1101 1.1 skrll else
1102 1.1 skrll {
1103 1.1 skrll /* Cache the symbols for elf_link_input_bfd. */
1104 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
1105 1.1 skrll }
1106 1.1 skrll free_extsyms = NULL;
1107 1.1 skrll }
1108 1.1 skrll
1109 1.1 skrll return TRUE;
1110 1.1 skrll
1111 1.1 skrll error_return:
1112 1.1 skrll if (free_relocs != NULL)
1113 1.1 skrll free (free_relocs);
1114 1.1 skrll if (free_contents != NULL)
1115 1.1 skrll free (free_contents);
1116 1.1 skrll if (free_extsyms != NULL)
1117 1.1 skrll free (free_extsyms);
1118 1.1 skrll return FALSE;
1119 1.1 skrll }
1120 1.1 skrll
1121 1.1 skrll /* Delete some bytes from a section while relaxing. */
1122 1.1 skrll
1123 1.1.1.6 christos static void
1124 1.1 skrll m68hc11_elf_relax_delete_bytes (bfd *abfd, asection *sec,
1125 1.1 skrll bfd_vma addr, int count)
1126 1.1 skrll {
1127 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
1128 1.1 skrll unsigned int sec_shndx;
1129 1.1 skrll bfd_byte *contents;
1130 1.1 skrll Elf_Internal_Rela *irel, *irelend;
1131 1.1 skrll bfd_vma toaddr;
1132 1.1 skrll Elf_Internal_Sym *isymbuf, *isym, *isymend;
1133 1.1 skrll struct elf_link_hash_entry **sym_hashes;
1134 1.1 skrll struct elf_link_hash_entry **end_hashes;
1135 1.1 skrll unsigned int symcount;
1136 1.1 skrll
1137 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1138 1.1 skrll isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1139 1.1 skrll
1140 1.1 skrll sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
1141 1.1 skrll
1142 1.1 skrll contents = elf_section_data (sec)->this_hdr.contents;
1143 1.1 skrll
1144 1.1 skrll toaddr = sec->size;
1145 1.1 skrll
1146 1.1 skrll irel = elf_section_data (sec)->relocs;
1147 1.1 skrll irelend = irel + sec->reloc_count;
1148 1.1 skrll
1149 1.1 skrll /* Actually delete the bytes. */
1150 1.1 skrll memmove (contents + addr, contents + addr + count,
1151 1.1 skrll (size_t) (toaddr - addr - count));
1152 1.1 skrll
1153 1.1 skrll sec->size -= count;
1154 1.1 skrll
1155 1.1 skrll /* Adjust all the relocs. */
1156 1.1 skrll for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
1157 1.1 skrll {
1158 1.1 skrll unsigned char code;
1159 1.1 skrll unsigned char offset;
1160 1.1 skrll unsigned short raddr;
1161 1.1 skrll unsigned long old_offset;
1162 1.1 skrll int branch_pos;
1163 1.1 skrll
1164 1.1 skrll old_offset = irel->r_offset;
1165 1.1 skrll
1166 1.1 skrll /* See if this reloc was for the bytes we have deleted, in which
1167 1.1 skrll case we no longer care about it. Don't delete relocs which
1168 1.1.1.6 christos represent addresses, though. */
1169 1.1.1.6 christos if (ELF32_R_TYPE (irel->r_info) != R_M68HC11_RL_JUMP
1170 1.1.1.6 christos && irel->r_offset >= addr && irel->r_offset < addr + count)
1171 1.1 skrll irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1172 1.1 skrll R_M68HC11_NONE);
1173 1.1.1.6 christos
1174 1.1 skrll if (ELF32_R_TYPE (irel->r_info) == R_M68HC11_NONE)
1175 1.1 skrll continue;
1176 1.1 skrll
1177 1.1 skrll /* Get the new reloc address. */
1178 1.1 skrll if ((irel->r_offset > addr
1179 1.1 skrll && irel->r_offset < toaddr))
1180 1.1 skrll irel->r_offset -= count;
1181 1.1.1.6 christos
1182 1.1 skrll /* If this is a PC relative reloc, see if the range it covers
1183 1.1 skrll includes the bytes we have deleted. */
1184 1.1 skrll switch (ELF32_R_TYPE (irel->r_info))
1185 1.1 skrll {
1186 1.1 skrll default:
1187 1.1 skrll break;
1188 1.1.1.6 christos
1189 1.1.1.6 christos case R_M68HC11_RL_JUMP:
1190 1.1.1.6 christos code = bfd_get_8 (abfd, contents + irel->r_offset);
1191 1.1.1.6 christos switch (code)
1192 1.1.1.6 christos {
1193 1.1.1.6 christos /* jsr and jmp instruction are also marked with RL_JUMP
1194 1.1.1.6 christos relocs but no adjustment must be made. */
1195 1.1.1.6 christos case 0x7e:
1196 1.1.1.6 christos case 0x9d:
1197 1.1 skrll case 0xbd:
1198 1.1.1.6 christos continue;
1199 1.1.1.6 christos
1200 1.1.1.6 christos case 0x12:
1201 1.1.1.6 christos case 0x13:
1202 1.1.1.6 christos branch_pos = 3;
1203 1.1.1.6 christos raddr = 4;
1204 1.1.1.6 christos
1205 1.1.1.6 christos /* Special case when we translate a brclr N,y into brclr *<addr>
1206 1.1.1.6 christos In this case, the 0x18 page2 prefix is removed.
1207 1.1.1.6 christos The reloc offset is not modified but the instruction
1208 1.1.1.6 christos size is reduced by 1. */
1209 1.1.1.6 christos if (old_offset == addr)
1210 1.1.1.6 christos raddr++;
1211 1.1.1.6 christos break;
1212 1.1.1.6 christos
1213 1.1.1.6 christos case 0x1e:
1214 1.1.1.6 christos case 0x1f:
1215 1.1.1.6 christos branch_pos = 3;
1216 1.1.1.6 christos raddr = 4;
1217 1.1.1.6 christos break;
1218 1.1.1.6 christos
1219 1.1.1.6 christos case 0x18:
1220 1.1.1.6 christos branch_pos = 4;
1221 1.1.1.6 christos raddr = 5;
1222 1.1.1.6 christos break;
1223 1.1.1.6 christos
1224 1.1.1.6 christos default:
1225 1.1.1.6 christos branch_pos = 1;
1226 1.1.1.6 christos raddr = 2;
1227 1.1.1.6 christos break;
1228 1.1.1.6 christos }
1229 1.1.1.6 christos offset = bfd_get_8 (abfd, contents + irel->r_offset + branch_pos);
1230 1.1.1.6 christos raddr += old_offset;
1231 1.1.1.6 christos raddr += ((unsigned short) offset | ((offset & 0x80) ? 0xff00 : 0));
1232 1.1.1.6 christos if (irel->r_offset < addr && raddr > addr)
1233 1.1.1.6 christos {
1234 1.1.1.6 christos offset -= count;
1235 1.1.1.6 christos bfd_put_8 (abfd, offset, contents + irel->r_offset + branch_pos);
1236 1.1.1.6 christos }
1237 1.1.1.6 christos else if (irel->r_offset >= addr && raddr <= addr)
1238 1.1.1.6 christos {
1239 1.1.1.6 christos offset += count;
1240 1.1.1.6 christos bfd_put_8 (abfd, offset, contents + irel->r_offset + branch_pos);
1241 1.1.1.6 christos }
1242 1.1.1.6 christos else
1243 1.1.1.6 christos {
1244 1.1.1.6 christos /*printf ("Not adjusted 0x%04x [0x%4x 0x%4x]\n", raddr,
1245 1.1.1.6 christos irel->r_offset, addr);*/
1246 1.1.1.6 christos }
1247 1.1 skrll
1248 1.1 skrll break;
1249 1.1 skrll }
1250 1.1 skrll }
1251 1.1 skrll
1252 1.1 skrll /* Adjust the local symbols defined in this section. */
1253 1.1 skrll isymend = isymbuf + symtab_hdr->sh_info;
1254 1.1 skrll for (isym = isymbuf; isym < isymend; isym++)
1255 1.1 skrll {
1256 1.1 skrll if (isym->st_shndx == sec_shndx
1257 1.1 skrll && isym->st_value > addr
1258 1.1 skrll && isym->st_value <= toaddr)
1259 1.1 skrll isym->st_value -= count;
1260 1.1 skrll }
1261 1.1 skrll
1262 1.1 skrll /* Now adjust the global symbols defined in this section. */
1263 1.1 skrll symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1264 1.1 skrll - symtab_hdr->sh_info);
1265 1.1 skrll sym_hashes = elf_sym_hashes (abfd);
1266 1.1 skrll end_hashes = sym_hashes + symcount;
1267 1.1 skrll for (; sym_hashes < end_hashes; sym_hashes++)
1268 1.1 skrll {
1269 1.1 skrll struct elf_link_hash_entry *sym_hash = *sym_hashes;
1270 1.1 skrll if ((sym_hash->root.type == bfd_link_hash_defined
1271 1.1 skrll || sym_hash->root.type == bfd_link_hash_defweak)
1272 1.1 skrll && sym_hash->root.u.def.section == sec
1273 1.1 skrll && sym_hash->root.u.def.value > addr
1274 1.1 skrll && sym_hash->root.u.def.value <= toaddr)
1275 1.1 skrll {
1276 1.1 skrll sym_hash->root.u.def.value -= count;
1277 1.1 skrll }
1278 1.1 skrll }
1279 1.1 skrll }
1280 1.1 skrll
1281 1.1 skrll /* Specific sections:
1282 1.1 skrll - The .page0 is a data section that is mapped in [0x0000..0x00FF].
1283 1.1 skrll Page0 accesses are faster on the M68HC11. Soft registers used by GCC-m6811
1284 1.1 skrll are located in .page0.
1285 1.1 skrll - The .vectors is the section that represents the interrupt
1286 1.1 skrll vectors. */
1287 1.1 skrll static const struct bfd_elf_special_section elf32_m68hc11_special_sections[] =
1288 1.1 skrll {
1289 1.1 skrll { STRING_COMMA_LEN (".eeprom"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
1290 1.1 skrll { STRING_COMMA_LEN (".page0"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
1291 1.1.1.6 christos { STRING_COMMA_LEN (".softregs"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
1292 1.1 skrll { STRING_COMMA_LEN (".vectors"), 0, SHT_PROGBITS, SHF_ALLOC },
1293 1.1 skrll { NULL, 0, 0, 0, 0 }
1294 1.1 skrll };
1295 1.1.1.2 christos
1296 1.1 skrll #define ELF_ARCH bfd_arch_m68hc11
1298 1.1 skrll #define ELF_TARGET_ID M68HC11_ELF_DATA
1299 1.1.1.6 christos #define ELF_MACHINE_CODE EM_68HC11
1300 1.1 skrll #define ELF_MAXPAGESIZE 0x1000
1301 1.1 skrll
1302 1.1.1.7 christos #define TARGET_BIG_SYM m68hc11_elf32_vec
1303 1.1 skrll #define TARGET_BIG_NAME "elf32-m68hc11"
1304 1.1 skrll
1305 1.1 skrll #define elf_info_to_howto NULL
1306 1.1 skrll #define elf_info_to_howto_rel m68hc11_info_to_howto_rel
1307 1.1 skrll #define bfd_elf32_bfd_relax_section m68hc11_elf_relax_section
1308 1.1 skrll #define elf_backend_check_relocs elf32_m68hc11_check_relocs
1309 1.1 skrll #define elf_backend_relocate_section elf32_m68hc11_relocate_section
1310 1.1 skrll #define elf_backend_add_symbol_hook elf32_m68hc11_add_symbol_hook
1311 1.1 skrll #define elf_backend_object_p 0
1312 1.1.1.3 christos #define elf_backend_final_write_processing 0
1313 1.1 skrll #define elf_backend_can_gc_sections 1
1314 1.1 skrll #define elf_backend_special_sections elf32_m68hc11_special_sections
1315 1.1.1.6 christos #define elf_backend_merge_symbol_attribute elf32_m68hc11_merge_symbol_attribute
1316 1.1 skrll
1317 1.1 skrll #define bfd_elf32_bfd_link_hash_table_create \
1318 1.1 skrll m68hc11_elf_bfd_link_hash_table_create
1319 1.1 skrll #define bfd_elf32_bfd_merge_private_bfd_data \
1320 1.1 skrll _bfd_m68hc11_elf_merge_private_bfd_data
1321 1.1 skrll #define bfd_elf32_bfd_set_private_flags _bfd_m68hc11_elf_set_private_flags
1322 1.1 skrll #define bfd_elf32_bfd_print_private_bfd_data \
1323 _bfd_m68hc11_elf_print_private_bfd_data
1324
1325 #include "elf32-target.h"
1326