elf32-h8300.c revision 1.1.1.6.2.1 1 1.1 skrll /* BFD back-end for Renesas H8/300 ELF binaries.
2 1.1.1.6 christos Copyright (C) 1993-2018 Free Software Foundation, Inc.
3 1.1 skrll
4 1.1 skrll This file is part of BFD, the Binary File Descriptor library.
5 1.1 skrll
6 1.1 skrll This program is free software; you can redistribute it and/or modify
7 1.1 skrll it under the terms of the GNU General Public License as published by
8 1.1 skrll the Free Software Foundation; either version 3 of the License, or
9 1.1 skrll (at your option) any later version.
10 1.1 skrll
11 1.1 skrll This program is distributed in the hope that it will be useful,
12 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 skrll GNU General Public License for more details.
15 1.1 skrll
16 1.1 skrll You should have received a copy of the GNU General Public License
17 1.1 skrll along with this program; if not, write to the Free Software
18 1.1 skrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 1.1 skrll MA 02110-1301, USA. */
20 1.1 skrll
21 1.1 skrll #include "sysdep.h"
22 1.1 skrll #include "bfd.h"
23 1.1 skrll #include "libbfd.h"
24 1.1 skrll #include "elf-bfd.h"
25 1.1 skrll #include "elf/h8.h"
26 1.1 skrll
27 1.1 skrll static reloc_howto_type *elf32_h8_reloc_type_lookup
28 1.1 skrll (bfd *abfd, bfd_reloc_code_real_type code);
29 1.1.1.6.2.1 christos static bfd_boolean elf32_h8_info_to_howto
30 1.1 skrll (bfd *, arelent *, Elf_Internal_Rela *);
31 1.1.1.6.2.1 christos static bfd_boolean elf32_h8_info_to_howto_rel
32 1.1 skrll (bfd *, arelent *, Elf_Internal_Rela *);
33 1.1 skrll static unsigned long elf32_h8_mach (flagword);
34 1.1 skrll static void elf32_h8_final_write_processing (bfd *, bfd_boolean);
35 1.1 skrll static bfd_boolean elf32_h8_object_p (bfd *);
36 1.1.1.6 christos static bfd_boolean elf32_h8_merge_private_bfd_data
37 1.1.1.6 christos (bfd *, struct bfd_link_info *);
38 1.1 skrll static bfd_boolean elf32_h8_relax_section
39 1.1 skrll (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
40 1.1 skrll static bfd_boolean elf32_h8_relax_delete_bytes
41 1.1 skrll (bfd *, asection *, bfd_vma, int);
42 1.1 skrll static bfd_boolean elf32_h8_symbol_address_p (bfd *, asection *, bfd_vma);
43 1.1 skrll static bfd_byte *elf32_h8_get_relocated_section_contents
44 1.1 skrll (bfd *, struct bfd_link_info *, struct bfd_link_order *,
45 1.1 skrll bfd_byte *, bfd_boolean, asymbol **);
46 1.1 skrll static bfd_reloc_status_type elf32_h8_final_link_relocate
47 1.1 skrll (unsigned long, bfd *, bfd *, asection *,
48 1.1 skrll bfd_byte *, bfd_vma, bfd_vma, bfd_vma,
49 1.1 skrll struct bfd_link_info *, asection *, int);
50 1.1 skrll static bfd_boolean elf32_h8_relocate_section
51 1.1 skrll (bfd *, struct bfd_link_info *, bfd *, asection *,
52 1.1 skrll bfd_byte *, Elf_Internal_Rela *,
53 1.1 skrll Elf_Internal_Sym *, asection **);
54 1.1 skrll static bfd_reloc_status_type special
55 1.1.1.3 christos (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
56 1.1 skrll
57 1.1 skrll /* This does not include any relocation information, but should be
58 1.1 skrll good enough for GDB or objdump to read the file. */
59 1.1 skrll
60 1.1.1.3 christos static reloc_howto_type h8_elf_howto_table[] =
61 1.1.1.3 christos {
62 1.1 skrll #define R_H8_NONE_X 0
63 1.1 skrll HOWTO (R_H8_NONE, /* type */
64 1.1 skrll 0, /* rightshift */
65 1.1.1.4 christos 3, /* size (0 = byte, 1 = short, 2 = long) */
66 1.1 skrll 0, /* bitsize */
67 1.1 skrll FALSE, /* pc_relative */
68 1.1 skrll 0, /* bitpos */
69 1.1 skrll complain_overflow_dont,/* complain_on_overflow */
70 1.1 skrll special, /* special_function */
71 1.1 skrll "R_H8_NONE", /* name */
72 1.1 skrll FALSE, /* partial_inplace */
73 1.1 skrll 0, /* src_mask */
74 1.1 skrll 0, /* dst_mask */
75 1.1 skrll FALSE), /* pcrel_offset */
76 1.1 skrll #define R_H8_DIR32_X (R_H8_NONE_X + 1)
77 1.1 skrll HOWTO (R_H8_DIR32, /* type */
78 1.1 skrll 0, /* rightshift */
79 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
80 1.1 skrll 32, /* bitsize */
81 1.1 skrll FALSE, /* pc_relative */
82 1.1 skrll 0, /* bitpos */
83 1.1 skrll complain_overflow_dont,/* complain_on_overflow */
84 1.1 skrll special, /* special_function */
85 1.1 skrll "R_H8_DIR32", /* name */
86 1.1 skrll FALSE, /* partial_inplace */
87 1.1 skrll 0, /* src_mask */
88 1.1 skrll 0xffffffff, /* dst_mask */
89 1.1 skrll FALSE), /* pcrel_offset */
90 1.1 skrll #define R_H8_DIR16_X (R_H8_DIR32_X + 1)
91 1.1 skrll HOWTO (R_H8_DIR16, /* type */
92 1.1 skrll 0, /* rightshift */
93 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
94 1.1 skrll 16, /* bitsize */
95 1.1 skrll FALSE, /* pc_relative */
96 1.1 skrll 0, /* bitpos */
97 1.1 skrll complain_overflow_dont,/* complain_on_overflow */
98 1.1 skrll special, /* special_function */
99 1.1 skrll "R_H8_DIR16", /* name */
100 1.1 skrll FALSE, /* partial_inplace */
101 1.1 skrll 0, /* src_mask */
102 1.1 skrll 0x0000ffff, /* dst_mask */
103 1.1 skrll FALSE), /* pcrel_offset */
104 1.1 skrll #define R_H8_DIR8_X (R_H8_DIR16_X + 1)
105 1.1 skrll HOWTO (R_H8_DIR8, /* type */
106 1.1 skrll 0, /* rightshift */
107 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
108 1.1 skrll 8, /* bitsize */
109 1.1 skrll FALSE, /* pc_relative */
110 1.1 skrll 0, /* bitpos */
111 1.1 skrll complain_overflow_dont,/* complain_on_overflow */
112 1.1 skrll special, /* special_function */
113 1.1 skrll "R_H8_DIR8", /* name */
114 1.1 skrll FALSE, /* partial_inplace */
115 1.1 skrll 0, /* src_mask */
116 1.1 skrll 0x000000ff, /* dst_mask */
117 1.1 skrll FALSE), /* pcrel_offset */
118 1.1 skrll #define R_H8_DIR16A8_X (R_H8_DIR8_X + 1)
119 1.1 skrll HOWTO (R_H8_DIR16A8, /* type */
120 1.1 skrll 0, /* rightshift */
121 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
122 1.1 skrll 16, /* bitsize */
123 1.1 skrll FALSE, /* pc_relative */
124 1.1 skrll 0, /* bitpos */
125 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
126 1.1 skrll special, /* special_function */
127 1.1 skrll "R_H8_DIR16A8", /* name */
128 1.1 skrll FALSE, /* partial_inplace */
129 1.1 skrll 0, /* src_mask */
130 1.1 skrll 0x0000ffff, /* dst_mask */
131 1.1 skrll FALSE), /* pcrel_offset */
132 1.1 skrll #define R_H8_DIR16R8_X (R_H8_DIR16A8_X + 1)
133 1.1 skrll HOWTO (R_H8_DIR16R8, /* type */
134 1.1 skrll 0, /* rightshift */
135 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
136 1.1 skrll 16, /* bitsize */
137 1.1 skrll FALSE, /* pc_relative */
138 1.1 skrll 0, /* bitpos */
139 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
140 1.1 skrll special, /* special_function */
141 1.1 skrll "R_H8_DIR16R8", /* name */
142 1.1 skrll FALSE, /* partial_inplace */
143 1.1 skrll 0, /* src_mask */
144 1.1 skrll 0x0000ffff, /* dst_mask */
145 1.1 skrll FALSE), /* pcrel_offset */
146 1.1 skrll #define R_H8_DIR24A8_X (R_H8_DIR16R8_X + 1)
147 1.1 skrll HOWTO (R_H8_DIR24A8, /* type */
148 1.1 skrll 0, /* rightshift */
149 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
150 1.1 skrll 24, /* bitsize */
151 1.1 skrll FALSE, /* pc_relative */
152 1.1 skrll 0, /* bitpos */
153 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
154 1.1 skrll special, /* special_function */
155 1.1 skrll "R_H8_DIR24A8", /* name */
156 1.1 skrll TRUE, /* partial_inplace */
157 1.1 skrll 0xff000000, /* src_mask */
158 1.1 skrll 0x00ffffff, /* dst_mask */
159 1.1 skrll FALSE), /* pcrel_offset */
160 1.1 skrll #define R_H8_DIR24R8_X (R_H8_DIR24A8_X + 1)
161 1.1 skrll HOWTO (R_H8_DIR24R8, /* type */
162 1.1 skrll 0, /* rightshift */
163 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
164 1.1 skrll 24, /* bitsize */
165 1.1 skrll FALSE, /* pc_relative */
166 1.1 skrll 0, /* bitpos */
167 1.1 skrll complain_overflow_bitfield, /* complain_on_overflow */
168 1.1 skrll special, /* special_function */
169 1.1 skrll "R_H8_DIR24R8", /* name */
170 1.1 skrll TRUE, /* partial_inplace */
171 1.1 skrll 0xff000000, /* src_mask */
172 1.1 skrll 0x00ffffff, /* dst_mask */
173 1.1 skrll FALSE), /* pcrel_offset */
174 1.1 skrll #define R_H8_DIR32A16_X (R_H8_DIR24R8_X + 1)
175 1.1 skrll HOWTO (R_H8_DIR32A16, /* type */
176 1.1 skrll 0, /* rightshift */
177 1.1 skrll 2, /* size (0 = byte, 1 = short, 2 = long) */
178 1.1 skrll 32, /* bitsize */
179 1.1 skrll FALSE, /* pc_relative */
180 1.1 skrll 0, /* bitpos */
181 1.1 skrll complain_overflow_dont,/* complain_on_overflow */
182 1.1 skrll special, /* special_function */
183 1.1 skrll "R_H8_DIR32A16", /* name */
184 1.1 skrll FALSE, /* partial_inplace */
185 1.1 skrll 0, /* src_mask */
186 1.1 skrll 0xffffffff, /* dst_mask */
187 1.1 skrll FALSE), /* pcrel_offset */
188 1.1.1.4 christos #define R_H8_DISP32A16_X (R_H8_DIR32A16_X + 1)
189 1.1.1.4 christos HOWTO (R_H8_DISP32A16, /* type */
190 1.1.1.4 christos 0, /* rightshift */
191 1.1.1.4 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
192 1.1.1.4 christos 32, /* bitsize */
193 1.1.1.4 christos FALSE, /* pc_relative */
194 1.1.1.4 christos 0, /* bitpos */
195 1.1.1.4 christos complain_overflow_dont,/* complain_on_overflow */
196 1.1.1.4 christos special, /* special_function */
197 1.1.1.4 christos "R_H8_DISP32A16", /* name */
198 1.1.1.4 christos FALSE, /* partial_inplace */
199 1.1.1.4 christos 0, /* src_mask */
200 1.1.1.4 christos 0xffffffff, /* dst_mask */
201 1.1.1.4 christos FALSE), /* pcrel_offset */
202 1.1.1.4 christos #define R_H8_PCREL16_X (R_H8_DISP32A16_X + 1)
203 1.1 skrll HOWTO (R_H8_PCREL16, /* type */
204 1.1 skrll 0, /* rightshift */
205 1.1 skrll 1, /* size (0 = byte, 1 = short, 2 = long) */
206 1.1 skrll 16, /* bitsize */
207 1.1 skrll TRUE, /* pc_relative */
208 1.1 skrll 0, /* bitpos */
209 1.1 skrll complain_overflow_signed,/* complain_on_overflow */
210 1.1 skrll special, /* special_function */
211 1.1 skrll "R_H8_PCREL16", /* name */
212 1.1 skrll FALSE, /* partial_inplace */
213 1.1 skrll 0xffff, /* src_mask */
214 1.1 skrll 0xffff, /* dst_mask */
215 1.1 skrll TRUE), /* pcrel_offset */
216 1.1 skrll #define R_H8_PCREL8_X (R_H8_PCREL16_X + 1)
217 1.1 skrll HOWTO (R_H8_PCREL8, /* type */
218 1.1 skrll 0, /* rightshift */
219 1.1 skrll 0, /* size (0 = byte, 1 = short, 2 = long) */
220 1.1 skrll 8, /* bitsize */
221 1.1 skrll TRUE, /* pc_relative */
222 1.1 skrll 0, /* bitpos */
223 1.1 skrll complain_overflow_signed,/* complain_on_overflow */
224 1.1 skrll special, /* special_function */
225 1.1 skrll "R_H8_PCREL8", /* name */
226 1.1 skrll FALSE, /* partial_inplace */
227 1.1 skrll 0xff, /* src_mask */
228 1.1 skrll 0xff, /* dst_mask */
229 1.1 skrll TRUE), /* pcrel_offset */
230 1.1 skrll };
231 1.1 skrll
232 1.1 skrll /* This structure is used to map BFD reloc codes to H8 ELF relocs. */
233 1.1 skrll
234 1.1 skrll struct elf_reloc_map {
235 1.1 skrll bfd_reloc_code_real_type bfd_reloc_val;
236 1.1 skrll unsigned char howto_index;
237 1.1 skrll };
238 1.1 skrll
239 1.1 skrll /* An array mapping BFD reloc codes to H8 ELF relocs. */
240 1.1 skrll
241 1.1 skrll static const struct elf_reloc_map h8_reloc_map[] = {
242 1.1 skrll { BFD_RELOC_NONE, R_H8_NONE_X },
243 1.1 skrll { BFD_RELOC_32, R_H8_DIR32_X },
244 1.1 skrll { BFD_RELOC_16, R_H8_DIR16_X },
245 1.1 skrll { BFD_RELOC_8, R_H8_DIR8_X },
246 1.1 skrll { BFD_RELOC_H8_DIR16A8, R_H8_DIR16A8_X },
247 1.1 skrll { BFD_RELOC_H8_DIR16R8, R_H8_DIR16R8_X },
248 1.1 skrll { BFD_RELOC_H8_DIR24A8, R_H8_DIR24A8_X },
249 1.1 skrll { BFD_RELOC_H8_DIR24R8, R_H8_DIR24R8_X },
250 1.1 skrll { BFD_RELOC_H8_DIR32A16, R_H8_DIR32A16_X },
251 1.1.1.4 christos { BFD_RELOC_H8_DISP32A16, R_H8_DISP32A16_X },
252 1.1 skrll { BFD_RELOC_16_PCREL, R_H8_PCREL16_X },
253 1.1 skrll { BFD_RELOC_8_PCREL, R_H8_PCREL8_X },
254 1.1 skrll };
255 1.1 skrll
256 1.1 skrll
257 1.1 skrll static reloc_howto_type *
258 1.1 skrll elf32_h8_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
259 1.1 skrll bfd_reloc_code_real_type code)
260 1.1 skrll {
261 1.1 skrll unsigned int i;
262 1.1 skrll
263 1.1 skrll for (i = 0; i < sizeof (h8_reloc_map) / sizeof (struct elf_reloc_map); i++)
264 1.1 skrll {
265 1.1 skrll if (h8_reloc_map[i].bfd_reloc_val == code)
266 1.1 skrll return &h8_elf_howto_table[(int) h8_reloc_map[i].howto_index];
267 1.1 skrll }
268 1.1 skrll return NULL;
269 1.1 skrll }
270 1.1 skrll
271 1.1 skrll static reloc_howto_type *
272 1.1 skrll elf32_h8_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
273 1.1 skrll const char *r_name)
274 1.1 skrll {
275 1.1 skrll unsigned int i;
276 1.1 skrll
277 1.1 skrll for (i = 0;
278 1.1 skrll i < sizeof (h8_elf_howto_table) / sizeof (h8_elf_howto_table[0]);
279 1.1 skrll i++)
280 1.1 skrll if (h8_elf_howto_table[i].name != NULL
281 1.1 skrll && strcasecmp (h8_elf_howto_table[i].name, r_name) == 0)
282 1.1 skrll return &h8_elf_howto_table[i];
283 1.1 skrll
284 1.1 skrll return NULL;
285 1.1 skrll }
286 1.1 skrll
287 1.1.1.6.2.1 christos static bfd_boolean
288 1.1 skrll elf32_h8_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
289 1.1 skrll Elf_Internal_Rela *elf_reloc)
290 1.1 skrll {
291 1.1 skrll unsigned int r;
292 1.1 skrll unsigned int i;
293 1.1 skrll
294 1.1 skrll r = ELF32_R_TYPE (elf_reloc->r_info);
295 1.1 skrll for (i = 0; i < sizeof (h8_elf_howto_table) / sizeof (reloc_howto_type); i++)
296 1.1 skrll if (h8_elf_howto_table[i].type == r)
297 1.1 skrll {
298 1.1 skrll bfd_reloc->howto = &h8_elf_howto_table[i];
299 1.1.1.6.2.1 christos return TRUE;
300 1.1 skrll }
301 1.1.1.6.2.1 christos /* xgettext:c-format */
302 1.1.1.6.2.1 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r);
303 1.1.1.6.2.1 christos bfd_set_error (bfd_error_bad_value);
304 1.1.1.6.2.1 christos return FALSE;
305 1.1 skrll }
306 1.1 skrll
307 1.1.1.6.2.1 christos static bfd_boolean
308 1.1.1.6.2.1 christos elf32_h8_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
309 1.1.1.6.2.1 christos arelent *bfd_reloc ATTRIBUTE_UNUSED,
310 1.1 skrll Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED)
311 1.1 skrll {
312 1.1.1.6.2.1 christos return FALSE;
313 1.1 skrll }
314 1.1 skrll
315 1.1 skrll /* Special handling for H8/300 relocs.
316 1.1 skrll We only come here for pcrel stuff and return normally if not an -r link.
317 1.1 skrll When doing -r, we can't do any arithmetic for the pcrel stuff, because
318 1.1 skrll we support relaxing on the H8/300 series chips. */
319 1.1 skrll static bfd_reloc_status_type
320 1.1 skrll special (bfd *abfd ATTRIBUTE_UNUSED,
321 1.1 skrll arelent *reloc_entry ATTRIBUTE_UNUSED,
322 1.1 skrll asymbol *symbol ATTRIBUTE_UNUSED,
323 1.1.1.3 christos void * data ATTRIBUTE_UNUSED,
324 1.1 skrll asection *input_section ATTRIBUTE_UNUSED,
325 1.1 skrll bfd *output_bfd,
326 1.1 skrll char **error_message ATTRIBUTE_UNUSED)
327 1.1 skrll {
328 1.1 skrll if (output_bfd == (bfd *) NULL)
329 1.1 skrll return bfd_reloc_continue;
330 1.1 skrll
331 1.1 skrll /* Adjust the reloc address to that in the output section. */
332 1.1 skrll reloc_entry->address += input_section->output_offset;
333 1.1 skrll return bfd_reloc_ok;
334 1.1 skrll }
335 1.1 skrll
336 1.1 skrll /* Perform a relocation as part of a final link. */
337 1.1 skrll static bfd_reloc_status_type
338 1.1 skrll elf32_h8_final_link_relocate (unsigned long r_type, bfd *input_bfd,
339 1.1 skrll bfd *output_bfd ATTRIBUTE_UNUSED,
340 1.1 skrll asection *input_section ATTRIBUTE_UNUSED,
341 1.1 skrll bfd_byte *contents, bfd_vma offset,
342 1.1 skrll bfd_vma value, bfd_vma addend,
343 1.1 skrll struct bfd_link_info *info ATTRIBUTE_UNUSED,
344 1.1 skrll asection *sym_sec ATTRIBUTE_UNUSED,
345 1.1 skrll int is_local ATTRIBUTE_UNUSED)
346 1.1 skrll {
347 1.1 skrll bfd_byte *hit_data = contents + offset;
348 1.1 skrll
349 1.1 skrll switch (r_type)
350 1.1 skrll {
351 1.1 skrll case R_H8_NONE:
352 1.1 skrll return bfd_reloc_ok;
353 1.1 skrll
354 1.1 skrll case R_H8_DIR32:
355 1.1 skrll case R_H8_DIR32A16:
356 1.1.1.4 christos case R_H8_DISP32A16:
357 1.1 skrll case R_H8_DIR24A8:
358 1.1 skrll value += addend;
359 1.1 skrll bfd_put_32 (input_bfd, value, hit_data);
360 1.1 skrll return bfd_reloc_ok;
361 1.1 skrll
362 1.1 skrll case R_H8_DIR16:
363 1.1 skrll case R_H8_DIR16A8:
364 1.1 skrll case R_H8_DIR16R8:
365 1.1 skrll value += addend;
366 1.1 skrll bfd_put_16 (input_bfd, value, hit_data);
367 1.1 skrll return bfd_reloc_ok;
368 1.1 skrll
369 1.1 skrll /* AKA R_RELBYTE */
370 1.1 skrll case R_H8_DIR8:
371 1.1 skrll value += addend;
372 1.1 skrll
373 1.1 skrll bfd_put_8 (input_bfd, value, hit_data);
374 1.1 skrll return bfd_reloc_ok;
375 1.1 skrll
376 1.1 skrll case R_H8_DIR24R8:
377 1.1 skrll value += addend;
378 1.1 skrll
379 1.1 skrll /* HIT_DATA is the address for the first byte for the relocated
380 1.1 skrll value. Subtract 1 so that we can manipulate the data in 32-bit
381 1.1 skrll hunks. */
382 1.1 skrll hit_data--;
383 1.1 skrll
384 1.1 skrll /* Clear out the top byte in value. */
385 1.1 skrll value &= 0xffffff;
386 1.1 skrll
387 1.1 skrll /* Retrieve the type byte for value from the section contents. */
388 1.1 skrll value |= (bfd_get_32 (input_bfd, hit_data) & 0xff000000);
389 1.1 skrll
390 1.1 skrll /* Now scribble it out in one 32-bit hunk. */
391 1.1 skrll bfd_put_32 (input_bfd, value, hit_data);
392 1.1 skrll return bfd_reloc_ok;
393 1.1 skrll
394 1.1 skrll case R_H8_PCREL16:
395 1.1 skrll value -= (input_section->output_section->vma
396 1.1 skrll + input_section->output_offset);
397 1.1 skrll value -= offset;
398 1.1 skrll value += addend;
399 1.1 skrll
400 1.1 skrll /* The value is relative to the start of the instruction,
401 1.1 skrll not the relocation offset. Subtract 2 to account for
402 1.1 skrll this minor issue. */
403 1.1 skrll value -= 2;
404 1.1 skrll
405 1.1 skrll bfd_put_16 (input_bfd, value, hit_data);
406 1.1 skrll return bfd_reloc_ok;
407 1.1 skrll
408 1.1 skrll case R_H8_PCREL8:
409 1.1 skrll value -= (input_section->output_section->vma
410 1.1 skrll + input_section->output_offset);
411 1.1 skrll value -= offset;
412 1.1 skrll value += addend;
413 1.1 skrll
414 1.1 skrll /* The value is relative to the start of the instruction,
415 1.1 skrll not the relocation offset. Subtract 1 to account for
416 1.1 skrll this minor issue. */
417 1.1 skrll value -= 1;
418 1.1 skrll
419 1.1 skrll bfd_put_8 (input_bfd, value, hit_data);
420 1.1 skrll return bfd_reloc_ok;
421 1.1 skrll
422 1.1 skrll default:
423 1.1 skrll return bfd_reloc_notsupported;
424 1.1 skrll }
425 1.1 skrll }
426 1.1 skrll
427 1.1 skrll /* Relocate an H8 ELF section. */
429 1.1 skrll static bfd_boolean
430 1.1 skrll elf32_h8_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
431 1.1 skrll bfd *input_bfd, asection *input_section,
432 1.1 skrll bfd_byte *contents, Elf_Internal_Rela *relocs,
433 1.1 skrll Elf_Internal_Sym *local_syms,
434 1.1 skrll asection **local_sections)
435 1.1 skrll {
436 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
437 1.1 skrll struct elf_link_hash_entry **sym_hashes;
438 1.1 skrll Elf_Internal_Rela *rel, *relend;
439 1.1 skrll
440 1.1 skrll symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
441 1.1 skrll sym_hashes = elf_sym_hashes (input_bfd);
442 1.1 skrll
443 1.1 skrll rel = relocs;
444 1.1 skrll relend = relocs + input_section->reloc_count;
445 1.1 skrll for (; rel < relend; rel++)
446 1.1 skrll {
447 1.1 skrll unsigned int r_type;
448 1.1 skrll unsigned long r_symndx;
449 1.1 skrll Elf_Internal_Sym *sym;
450 1.1 skrll asection *sec;
451 1.1 skrll struct elf_link_hash_entry *h;
452 1.1 skrll bfd_vma relocation;
453 1.1 skrll bfd_reloc_status_type r;
454 1.1 skrll arelent bfd_reloc;
455 1.1 skrll reloc_howto_type *howto;
456 1.1.1.6.2.1 christos
457 1.1.1.6.2.1 christos if (! elf32_h8_info_to_howto (input_bfd, &bfd_reloc, rel))
458 1.1 skrll continue;
459 1.1 skrll howto = bfd_reloc.howto;
460 1.1 skrll
461 1.1 skrll r_symndx = ELF32_R_SYM (rel->r_info);
462 1.1 skrll r_type = ELF32_R_TYPE (rel->r_info);
463 1.1 skrll h = NULL;
464 1.1 skrll sym = NULL;
465 1.1 skrll sec = NULL;
466 1.1 skrll if (r_symndx < symtab_hdr->sh_info)
467 1.1 skrll {
468 1.1 skrll sym = local_syms + r_symndx;
469 1.1 skrll sec = local_sections[r_symndx];
470 1.1 skrll relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
471 1.1 skrll }
472 1.1 skrll else
473 1.1.1.4 christos {
474 1.1 skrll bfd_boolean unresolved_reloc, warned, ignored;
475 1.1 skrll
476 1.1 skrll RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
477 1.1 skrll r_symndx, symtab_hdr, sym_hashes,
478 1.1.1.4 christos h, sec, relocation,
479 1.1 skrll unresolved_reloc, warned, ignored);
480 1.1 skrll }
481 1.1.1.3 christos
482 1.1.1.2 christos if (sec != NULL && discarded_section (sec))
483 1.1.1.3 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
484 1.1 skrll rel, 1, relend, howto, 0, contents);
485 1.1.1.4 christos
486 1.1 skrll if (bfd_link_relocatable (info))
487 1.1 skrll continue;
488 1.1 skrll
489 1.1 skrll r = elf32_h8_final_link_relocate (r_type, input_bfd, output_bfd,
490 1.1 skrll input_section,
491 1.1 skrll contents, rel->r_offset,
492 1.1 skrll relocation, rel->r_addend,
493 1.1 skrll info, sec, h == NULL);
494 1.1 skrll
495 1.1 skrll if (r != bfd_reloc_ok)
496 1.1 skrll {
497 1.1 skrll const char *name;
498 1.1 skrll const char *msg = (const char *) 0;
499 1.1 skrll
500 1.1 skrll if (h != NULL)
501 1.1 skrll name = h->root.root.string;
502 1.1 skrll else
503 1.1 skrll {
504 1.1 skrll name = (bfd_elf_string_from_elf_section
505 1.1 skrll (input_bfd, symtab_hdr->sh_link, sym->st_name));
506 1.1 skrll if (name == NULL || *name == '\0')
507 1.1 skrll name = bfd_section_name (input_bfd, sec);
508 1.1 skrll }
509 1.1 skrll
510 1.1 skrll switch (r)
511 1.1 skrll {
512 1.1.1.5 christos case bfd_reloc_overflow:
513 1.1.1.5 christos (*info->callbacks->reloc_overflow)
514 1.1.1.5 christos (info, (h ? &h->root : NULL), name, howto->name,
515 1.1 skrll (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
516 1.1 skrll break;
517 1.1 skrll
518 1.1.1.5 christos case bfd_reloc_undefined:
519 1.1.1.5 christos (*info->callbacks->undefined_symbol)
520 1.1 skrll (info, name, input_bfd, input_section, rel->r_offset, TRUE);
521 1.1 skrll break;
522 1.1 skrll
523 1.1 skrll case bfd_reloc_outofrange:
524 1.1 skrll msg = _("internal error: out of range error");
525 1.1 skrll goto common_error;
526 1.1 skrll
527 1.1 skrll case bfd_reloc_notsupported:
528 1.1 skrll msg = _("internal error: unsupported relocation error");
529 1.1 skrll goto common_error;
530 1.1 skrll
531 1.1 skrll case bfd_reloc_dangerous:
532 1.1 skrll msg = _("internal error: dangerous error");
533 1.1 skrll goto common_error;
534 1.1 skrll
535 1.1 skrll default:
536 1.1 skrll msg = _("internal error: unknown error");
537 1.1 skrll /* fall through */
538 1.1 skrll
539 1.1.1.5 christos common_error:
540 1.1.1.5 christos (*info->callbacks->warning) (info, msg, name, input_bfd,
541 1.1 skrll input_section, rel->r_offset);
542 1.1 skrll break;
543 1.1 skrll }
544 1.1 skrll }
545 1.1 skrll }
546 1.1 skrll
547 1.1 skrll return TRUE;
548 1.1 skrll }
549 1.1 skrll
550 1.1 skrll /* Object files encode the specific H8 model they were compiled
551 1.1 skrll for in the ELF flags field.
552 1.1 skrll
553 1.1 skrll Examine that field and return the proper BFD machine type for
554 1.1 skrll the object file. */
555 1.1 skrll static unsigned long
556 1.1 skrll elf32_h8_mach (flagword flags)
557 1.1 skrll {
558 1.1 skrll switch (flags & EF_H8_MACH)
559 1.1 skrll {
560 1.1 skrll case E_H8_MACH_H8300:
561 1.1 skrll default:
562 1.1 skrll return bfd_mach_h8300;
563 1.1 skrll
564 1.1 skrll case E_H8_MACH_H8300H:
565 1.1 skrll return bfd_mach_h8300h;
566 1.1 skrll
567 1.1 skrll case E_H8_MACH_H8300S:
568 1.1 skrll return bfd_mach_h8300s;
569 1.1 skrll
570 1.1 skrll case E_H8_MACH_H8300HN:
571 1.1 skrll return bfd_mach_h8300hn;
572 1.1 skrll
573 1.1 skrll case E_H8_MACH_H8300SN:
574 1.1 skrll return bfd_mach_h8300sn;
575 1.1 skrll
576 1.1 skrll case E_H8_MACH_H8300SX:
577 1.1 skrll return bfd_mach_h8300sx;
578 1.1 skrll
579 1.1 skrll case E_H8_MACH_H8300SXN:
580 1.1 skrll return bfd_mach_h8300sxn;
581 1.1 skrll }
582 1.1 skrll }
583 1.1 skrll
584 1.1 skrll /* The final processing done just before writing out a H8 ELF object
585 1.1 skrll file. We use this opportunity to encode the BFD machine type
586 1.1 skrll into the flags field in the object file. */
587 1.1 skrll
588 1.1 skrll static void
589 1.1 skrll elf32_h8_final_write_processing (bfd *abfd,
590 1.1 skrll bfd_boolean linker ATTRIBUTE_UNUSED)
591 1.1 skrll {
592 1.1 skrll unsigned long val;
593 1.1 skrll
594 1.1 skrll switch (bfd_get_mach (abfd))
595 1.1 skrll {
596 1.1 skrll default:
597 1.1 skrll case bfd_mach_h8300:
598 1.1 skrll val = E_H8_MACH_H8300;
599 1.1 skrll break;
600 1.1 skrll
601 1.1 skrll case bfd_mach_h8300h:
602 1.1 skrll val = E_H8_MACH_H8300H;
603 1.1 skrll break;
604 1.1 skrll
605 1.1 skrll case bfd_mach_h8300s:
606 1.1 skrll val = E_H8_MACH_H8300S;
607 1.1 skrll break;
608 1.1 skrll
609 1.1 skrll case bfd_mach_h8300hn:
610 1.1 skrll val = E_H8_MACH_H8300HN;
611 1.1 skrll break;
612 1.1 skrll
613 1.1 skrll case bfd_mach_h8300sn:
614 1.1 skrll val = E_H8_MACH_H8300SN;
615 1.1 skrll break;
616 1.1 skrll
617 1.1 skrll case bfd_mach_h8300sx:
618 1.1 skrll val = E_H8_MACH_H8300SX;
619 1.1 skrll break;
620 1.1 skrll
621 1.1 skrll case bfd_mach_h8300sxn:
622 1.1 skrll val = E_H8_MACH_H8300SXN;
623 1.1 skrll break;
624 1.1 skrll }
625 1.1 skrll
626 1.1 skrll elf_elfheader (abfd)->e_flags &= ~ (EF_H8_MACH);
627 1.1 skrll elf_elfheader (abfd)->e_flags |= val;
628 1.1 skrll }
629 1.1 skrll
630 1.1 skrll /* Return nonzero if ABFD represents a valid H8 ELF object file; also
631 1.1 skrll record the encoded machine type found in the ELF flags. */
632 1.1 skrll
633 1.1 skrll static bfd_boolean
634 1.1 skrll elf32_h8_object_p (bfd *abfd)
635 1.1 skrll {
636 1.1 skrll bfd_default_set_arch_mach (abfd, bfd_arch_h8300,
637 1.1 skrll elf32_h8_mach (elf_elfheader (abfd)->e_flags));
638 1.1 skrll return TRUE;
639 1.1 skrll }
640 1.1 skrll
641 1.1 skrll /* Merge backend specific data from an object file to the output
642 1.1 skrll object file when linking. The only data we need to copy at this
643 1.1 skrll time is the architecture/machine information. */
644 1.1 skrll
645 1.1.1.6 christos static bfd_boolean
646 1.1 skrll elf32_h8_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
647 1.1.1.6 christos {
648 1.1.1.6 christos bfd *obfd = info->output_bfd;
649 1.1 skrll
650 1.1 skrll if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
651 1.1 skrll || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
652 1.1 skrll return TRUE;
653 1.1 skrll
654 1.1 skrll if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
655 1.1 skrll && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
656 1.1 skrll {
657 1.1 skrll if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
658 1.1 skrll bfd_get_mach (ibfd)))
659 1.1 skrll return FALSE;
660 1.1 skrll }
661 1.1 skrll
662 1.1 skrll return TRUE;
663 1.1 skrll }
664 1.1 skrll
665 1.1 skrll /* This function handles relaxing for the H8..
666 1.1 skrll
667 1.1 skrll There are a few relaxing opportunities available on the H8:
668 1.1.1.6 christos
669 1.1 skrll jmp/jsr:24 -> bra/bsr:8 2 bytes
670 1.1 skrll The jmp may be completely eliminated if the previous insn is a
671 1.1 skrll conditional branch to the insn after the jump. In that case
672 1.1 skrll we invert the branch and delete the jump and save 4 bytes.
673 1.1.1.6 christos
674 1.1.1.6 christos bCC:16 -> bCC:8 2 bytes
675 1.1 skrll bsr:16 -> bsr:8 2 bytes
676 1.1.1.6 christos
677 1.1.1.6 christos bset:16 -> bset:8 2 bytes
678 1.1 skrll bset:24/32 -> bset:8 4 bytes
679 1.1 skrll (also applicable to other bit manipulation instructions)
680 1.1.1.6 christos
681 1.1.1.6 christos mov.b:16 -> mov.b:8 2 bytes
682 1.1 skrll mov.b:24/32 -> mov.b:8 4 bytes
683 1.1.1.6 christos
684 1.1 skrll bset:24/32 -> bset:16 2 bytes
685 1.1 skrll (also applicable to other bit manipulation instructions)
686 1.1.1.6 christos
687 1.1.1.4 christos mov.[bwl]:24/32 -> mov.[bwl]:16 2 bytes
688 1.1.1.6 christos
689 1.1 skrll mov.[bwl] @(displ:24/32+ERx) -> mov.[bwl] @(displ:16+ERx) 4 bytes. */
690 1.1 skrll
691 1.1 skrll static bfd_boolean
692 1.1 skrll elf32_h8_relax_section (bfd *abfd, asection *sec,
693 1.1 skrll struct bfd_link_info *link_info, bfd_boolean *again)
694 1.1 skrll {
695 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
696 1.1 skrll Elf_Internal_Rela *internal_relocs;
697 1.1 skrll Elf_Internal_Rela *irel, *irelend;
698 1.1 skrll bfd_byte *contents = NULL;
699 1.1 skrll Elf_Internal_Sym *isymbuf = NULL;
700 1.1 skrll static asection *last_input_section = NULL;
701 1.1 skrll static Elf_Internal_Rela *last_reloc = NULL;
702 1.1 skrll
703 1.1 skrll /* Assume nothing changes. */
704 1.1 skrll *again = FALSE;
705 1.1 skrll
706 1.1 skrll /* We don't have to do anything for a relocatable link, if
707 1.1 skrll this section does not have relocs, or if this is not a
708 1.1.1.4 christos code section. */
709 1.1 skrll if (bfd_link_relocatable (link_info)
710 1.1 skrll || (sec->flags & SEC_RELOC) == 0
711 1.1 skrll || sec->reloc_count == 0
712 1.1 skrll || (sec->flags & SEC_CODE) == 0)
713 1.1 skrll return TRUE;
714 1.1 skrll
715 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
716 1.1 skrll
717 1.1 skrll /* Get a copy of the native relocations. */
718 1.1.1.3 christos internal_relocs = (_bfd_elf_link_read_relocs
719 1.1 skrll (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
720 1.1 skrll link_info->keep_memory));
721 1.1 skrll if (internal_relocs == NULL)
722 1.1 skrll goto error_return;
723 1.1 skrll
724 1.1 skrll if (sec != last_input_section)
725 1.1 skrll last_reloc = NULL;
726 1.1 skrll
727 1.1 skrll last_input_section = sec;
728 1.1 skrll
729 1.1 skrll /* Walk through the relocs looking for relaxing opportunities. */
730 1.1 skrll irelend = internal_relocs + sec->reloc_count;
731 1.1 skrll for (irel = internal_relocs; irel < irelend; irel++)
732 1.1 skrll {
733 1.1 skrll bfd_vma symval;
734 1.1.1.2 christos
735 1.1.1.2 christos {
736 1.1.1.2 christos arelent bfd_reloc;
737 1.1.1.6.2.1 christos
738 1.1.1.6.2.1 christos if (! elf32_h8_info_to_howto (abfd, &bfd_reloc, irel))
739 1.1.1.2 christos continue;
740 1.1 skrll }
741 1.1 skrll /* Keep track of the previous reloc so that we can delete
742 1.1 skrll some long jumps created by the compiler. */
743 1.1 skrll if (irel != internal_relocs)
744 1.1 skrll last_reloc = irel - 1;
745 1.1.1.4 christos
746 1.1.1.4 christos switch(ELF32_R_TYPE (irel->r_info))
747 1.1.1.4 christos {
748 1.1.1.4 christos case R_H8_DIR24R8:
749 1.1.1.4 christos case R_H8_PCREL16:
750 1.1.1.4 christos case R_H8_DIR16A8:
751 1.1.1.4 christos case R_H8_DIR24A8:
752 1.1.1.4 christos case R_H8_DIR32A16:
753 1.1.1.4 christos case R_H8_DISP32A16:
754 1.1.1.4 christos break;
755 1.1.1.4 christos default:
756 1.1.1.4 christos continue;
757 1.1 skrll }
758 1.1 skrll
759 1.1 skrll /* Get the section contents if we haven't done so already. */
760 1.1 skrll if (contents == NULL)
761 1.1 skrll {
762 1.1 skrll /* Get cached copy if it exists. */
763 1.1 skrll if (elf_section_data (sec)->this_hdr.contents != NULL)
764 1.1 skrll contents = elf_section_data (sec)->this_hdr.contents;
765 1.1 skrll else
766 1.1 skrll {
767 1.1 skrll /* Go get them off disk. */
768 1.1 skrll if (!bfd_malloc_and_get_section (abfd, sec, &contents))
769 1.1 skrll goto error_return;
770 1.1 skrll }
771 1.1 skrll }
772 1.1 skrll
773 1.1 skrll /* Read this BFD's local symbols if we haven't done so already. */
774 1.1 skrll if (isymbuf == NULL && symtab_hdr->sh_info != 0)
775 1.1 skrll {
776 1.1 skrll isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
777 1.1 skrll if (isymbuf == NULL)
778 1.1 skrll isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
779 1.1 skrll symtab_hdr->sh_info, 0,
780 1.1 skrll NULL, NULL, NULL);
781 1.1 skrll if (isymbuf == NULL)
782 1.1 skrll goto error_return;
783 1.1 skrll }
784 1.1 skrll
785 1.1 skrll /* Get the value of the symbol referred to by the reloc. */
786 1.1 skrll if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
787 1.1 skrll {
788 1.1 skrll /* A local symbol. */
789 1.1 skrll Elf_Internal_Sym *isym;
790 1.1 skrll asection *sym_sec;
791 1.1 skrll
792 1.1 skrll isym = isymbuf + ELF32_R_SYM (irel->r_info);
793 1.1 skrll sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
794 1.1 skrll symval = isym->st_value;
795 1.1 skrll /* If the reloc is absolute, it will not have
796 1.1 skrll a symbol or section associated with it. */
797 1.1 skrll if (sym_sec)
798 1.1 skrll symval += sym_sec->output_section->vma
799 1.1 skrll + sym_sec->output_offset;
800 1.1 skrll }
801 1.1 skrll else
802 1.1 skrll {
803 1.1 skrll unsigned long indx;
804 1.1 skrll struct elf_link_hash_entry *h;
805 1.1 skrll
806 1.1 skrll /* An external symbol. */
807 1.1 skrll indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
808 1.1 skrll h = elf_sym_hashes (abfd)[indx];
809 1.1 skrll BFD_ASSERT (h != NULL);
810 1.1 skrll if (h->root.type != bfd_link_hash_defined
811 1.1 skrll && h->root.type != bfd_link_hash_defweak)
812 1.1 skrll {
813 1.1.1.6 christos /* This appears to be a reference to an undefined
814 1.1.1.6 christos symbol. Just ignore it--it will be caught by the
815 1.1 skrll regular reloc processing. */
816 1.1 skrll continue;
817 1.1 skrll }
818 1.1 skrll
819 1.1 skrll symval = (h->root.u.def.value
820 1.1 skrll + h->root.u.def.section->output_section->vma
821 1.1 skrll + h->root.u.def.section->output_offset);
822 1.1 skrll }
823 1.1 skrll
824 1.1 skrll /* For simplicity of coding, we are going to modify the section
825 1.1 skrll contents, the section relocs, and the BFD symbol table. We
826 1.1 skrll must tell the rest of the code not to free up this
827 1.1 skrll information. It would be possible to instead create a table
828 1.1 skrll of changes which have to be made, as is done in coff-mips.c;
829 1.1 skrll that would be more work, but would require less memory when
830 1.1 skrll the linker is run. */
831 1.1 skrll switch (ELF32_R_TYPE (irel->r_info))
832 1.1.1.4 christos {
833 1.1.1.4 christos /* Try to turn a 24-bit absolute branch/call into an 8-bit
834 1.1 skrll pc-relative branch/call. */
835 1.1 skrll case R_H8_DIR24R8:
836 1.1 skrll {
837 1.1 skrll bfd_vma value = symval + irel->r_addend;
838 1.1 skrll bfd_vma dot, gap;
839 1.1 skrll
840 1.1 skrll /* Get the address of this instruction. */
841 1.1 skrll dot = (sec->output_section->vma
842 1.1 skrll + sec->output_offset + irel->r_offset - 1);
843 1.1 skrll
844 1.1 skrll /* Compute the distance from this insn to the branch target. */
845 1.1 skrll gap = value - dot;
846 1.1 skrll
847 1.1 skrll /* If the distance is within -126..+130 inclusive, then we can
848 1.1 skrll relax this jump. +130 is valid since the target will move
849 1.1 skrll two bytes closer if we do relax this branch. */
850 1.1 skrll if ((int) gap >= -126 && (int) gap <= 130)
851 1.1 skrll {
852 1.1 skrll unsigned char code;
853 1.1 skrll
854 1.1 skrll /* Note that we've changed the relocs, section contents,
855 1.1 skrll etc. */
856 1.1 skrll elf_section_data (sec)->relocs = internal_relocs;
857 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
858 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
859 1.1 skrll
860 1.1 skrll /* Get the instruction code being relaxed. */
861 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
862 1.1 skrll
863 1.1 skrll /* If the previous instruction conditionally jumped around
864 1.1 skrll this instruction, we may be able to reverse the condition
865 1.1 skrll and redirect the previous instruction to the target of
866 1.1 skrll this instruction.
867 1.1 skrll
868 1.1 skrll Such sequences are used by the compiler to deal with
869 1.1 skrll long conditional branches.
870 1.1 skrll
871 1.1 skrll Only perform this optimisation for jumps (code 0x5a) not
872 1.1 skrll subroutine calls, as otherwise it could transform:
873 1.1.1.4 christos
874 1.1.1.4 christos mov.w r0,r0
875 1.1.1.4 christos beq .L1
876 1.1.1.4 christos jsr @_bar
877 1.1.1.4 christos .L1: rts
878 1.1 skrll _bar: rts
879 1.1.1.4 christos into:
880 1.1.1.4 christos mov.w r0,r0
881 1.1.1.4 christos bne _bar
882 1.1.1.4 christos rts
883 1.1 skrll _bar: rts
884 1.1 skrll
885 1.1.1.4 christos which changes the call (jsr) into a branch (bne). */
886 1.1 skrll if (code == 0x5a /* jmp24. */
887 1.1 skrll && (int) gap <= 130
888 1.1 skrll && (int) gap >= -128
889 1.1 skrll && last_reloc
890 1.1 skrll && ELF32_R_TYPE (last_reloc->r_info) == R_H8_PCREL8
891 1.1 skrll && ELF32_R_SYM (last_reloc->r_info) < symtab_hdr->sh_info)
892 1.1 skrll {
893 1.1 skrll bfd_vma last_value;
894 1.1 skrll asection *last_sym_sec;
895 1.1 skrll Elf_Internal_Sym *last_sym;
896 1.1 skrll
897 1.1 skrll /* We will need to examine the symbol used by the
898 1.1 skrll previous relocation. */
899 1.1 skrll
900 1.1 skrll last_sym = isymbuf + ELF32_R_SYM (last_reloc->r_info);
901 1.1 skrll last_sym_sec
902 1.1 skrll = bfd_section_from_elf_index (abfd, last_sym->st_shndx);
903 1.1 skrll last_value = (last_sym->st_value
904 1.1 skrll + last_sym_sec->output_section->vma
905 1.1 skrll + last_sym_sec->output_offset);
906 1.1 skrll
907 1.1 skrll /* Verify that the previous relocation was for a
908 1.1 skrll branch around this instruction and that no symbol
909 1.1 skrll exists at the current location. */
910 1.1 skrll if (last_value == dot + 4
911 1.1 skrll && last_reloc->r_offset + 2 == irel->r_offset
912 1.1 skrll && ! elf32_h8_symbol_address_p (abfd, sec, dot))
913 1.1 skrll {
914 1.1 skrll /* We can eliminate this jump. Twiddle the
915 1.1 skrll previous relocation as necessary. */
916 1.1 skrll irel->r_info
917 1.1 skrll = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
918 1.1 skrll ELF32_R_TYPE (R_H8_NONE));
919 1.1 skrll
920 1.1 skrll last_reloc->r_info
921 1.1 skrll = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
922 1.1 skrll ELF32_R_TYPE (R_H8_PCREL8));
923 1.1 skrll last_reloc->r_addend = irel->r_addend;
924 1.1 skrll
925 1.1 skrll code = bfd_get_8 (abfd,
926 1.1 skrll contents + last_reloc->r_offset - 1);
927 1.1 skrll code ^= 1;
928 1.1 skrll bfd_put_8 (abfd,
929 1.1.1.4 christos code,
930 1.1 skrll contents + last_reloc->r_offset - 1);
931 1.1 skrll
932 1.1 skrll /* Delete four bytes of data. */
933 1.1 skrll if (!elf32_h8_relax_delete_bytes (abfd, sec,
934 1.1 skrll irel->r_offset - 1,
935 1.1 skrll 4))
936 1.1 skrll goto error_return;
937 1.1 skrll
938 1.1 skrll *again = TRUE;
939 1.1 skrll break;
940 1.1 skrll }
941 1.1 skrll }
942 1.1 skrll
943 1.1.1.4 christos if (code == 0x5e)
944 1.1.1.4 christos /* This is jsr24 */
945 1.1 skrll bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 1); /* bsr8. */
946 1.1.1.4 christos else if (code == 0x5a)
947 1.1.1.4 christos /* This is jmp24 */
948 1.1 skrll bfd_put_8 (abfd, 0x40, contents + irel->r_offset - 1); /* bra8. */
949 1.1 skrll else
950 1.1 skrll abort ();
951 1.1 skrll
952 1.1 skrll /* Fix the relocation's type. */
953 1.1 skrll irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
954 1.1 skrll R_H8_PCREL8);
955 1.1 skrll
956 1.1 skrll /* Delete two bytes of data. */
957 1.1 skrll if (!elf32_h8_relax_delete_bytes (abfd, sec,
958 1.1 skrll irel->r_offset + 1, 2))
959 1.1 skrll goto error_return;
960 1.1 skrll
961 1.1 skrll /* That will change things, so, we should relax again.
962 1.1 skrll Note that this is not required, and it may be slow. */
963 1.1 skrll *again = TRUE;
964 1.1 skrll }
965 1.1 skrll break;
966 1.1 skrll }
967 1.1.1.4 christos
968 1.1.1.4 christos /* Try to turn a 16-bit pc-relative branch into a 8-bit pc-relative
969 1.1 skrll branch. */
970 1.1 skrll case R_H8_PCREL16:
971 1.1 skrll {
972 1.1 skrll bfd_vma value = symval + irel->r_addend;
973 1.1 skrll bfd_vma dot;
974 1.1 skrll bfd_vma gap;
975 1.1 skrll
976 1.1 skrll /* Get the address of this instruction. */
977 1.1 skrll dot = (sec->output_section->vma
978 1.1 skrll + sec->output_offset
979 1.1 skrll + irel->r_offset - 2);
980 1.1 skrll
981 1.1 skrll gap = value - dot;
982 1.1 skrll
983 1.1 skrll /* If the distance is within -126..+130 inclusive, then we can
984 1.1 skrll relax this jump. +130 is valid since the target will move
985 1.1 skrll two bytes closer if we do relax this branch. */
986 1.1 skrll if ((int) gap >= -126 && (int) gap <= 130)
987 1.1 skrll {
988 1.1 skrll unsigned char code;
989 1.1 skrll
990 1.1 skrll /* Note that we've changed the relocs, section contents,
991 1.1 skrll etc. */
992 1.1 skrll elf_section_data (sec)->relocs = internal_relocs;
993 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
994 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
995 1.1 skrll
996 1.1 skrll /* Get the opcode. */
997 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
998 1.1 skrll
999 1.1 skrll if (code == 0x58)
1000 1.1 skrll {
1001 1.1 skrll /* bCC:16 -> bCC:8 */
1002 1.1 skrll /* Get the second byte of the original insn, which
1003 1.1 skrll contains the condition code. */
1004 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
1005 1.1.1.4 christos
1006 1.1 skrll /* Compute the first byte of the relaxed
1007 1.1 skrll instruction. The original sequence 0x58 0xX0
1008 1.1 skrll is relaxed to 0x4X, where X represents the
1009 1.1 skrll condition code. */
1010 1.1 skrll code &= 0xf0;
1011 1.1 skrll code >>= 4;
1012 1.1.1.4 christos code |= 0x40;
1013 1.1 skrll bfd_put_8 (abfd, code, contents + irel->r_offset - 2); /* bCC:8. */
1014 1.1.1.4 christos }
1015 1.1 skrll else if (code == 0x5c) /* bsr16. */
1016 1.1.1.4 christos /* This is bsr. */
1017 1.1 skrll bfd_put_8 (abfd, 0x55, contents + irel->r_offset - 2); /* bsr8. */
1018 1.1.1.2 christos else
1019 1.1.1.2 christos /* Might be MOVSD. */
1020 1.1 skrll break;
1021 1.1 skrll
1022 1.1 skrll /* Fix the relocation's type. */
1023 1.1 skrll irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1024 1.1 skrll R_H8_PCREL8);
1025 1.1 skrll irel->r_offset--;
1026 1.1 skrll
1027 1.1 skrll /* Delete two bytes of data. */
1028 1.1 skrll if (!elf32_h8_relax_delete_bytes (abfd, sec,
1029 1.1 skrll irel->r_offset + 1, 2))
1030 1.1 skrll goto error_return;
1031 1.1 skrll
1032 1.1 skrll /* That will change things, so, we should relax again.
1033 1.1 skrll Note that this is not required, and it may be slow. */
1034 1.1 skrll *again = TRUE;
1035 1.1 skrll }
1036 1.1 skrll break;
1037 1.1 skrll }
1038 1.1.1.4 christos
1039 1.1.1.4 christos /* This is a 16-bit absolute address in one of the following
1040 1.1 skrll instructions:
1041 1.1 skrll
1042 1.1 skrll "band", "bclr", "biand", "bild", "bior", "bist", "bixor",
1043 1.1 skrll "bld", "bnot", "bor", "bset", "bst", "btst", "bxor", and
1044 1.1 skrll "mov.b"
1045 1.1.1.4 christos
1046 1.1.1.4 christos We may relax this into an 8-bit absolute address if it's in
1047 1.1 skrll the right range. */
1048 1.1 skrll case R_H8_DIR16A8:
1049 1.1 skrll {
1050 1.1 skrll bfd_vma value;
1051 1.1 skrll
1052 1.1 skrll value = bfd_h8300_pad_address (abfd, symval + irel->r_addend);
1053 1.1 skrll if (value >= 0xffffff00u)
1054 1.1 skrll {
1055 1.1 skrll unsigned char code;
1056 1.1 skrll unsigned char temp_code;
1057 1.1 skrll
1058 1.1 skrll /* Note that we've changed the relocs, section contents,
1059 1.1 skrll etc. */
1060 1.1 skrll elf_section_data (sec)->relocs = internal_relocs;
1061 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
1062 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
1063 1.1 skrll
1064 1.1 skrll /* Get the opcode. */
1065 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
1066 1.1 skrll
1067 1.1 skrll /* All instructions with R_H8_DIR16A8 start with
1068 1.1 skrll 0x6a. */
1069 1.1 skrll if (code != 0x6a)
1070 1.1 skrll abort ();
1071 1.1 skrll
1072 1.1 skrll temp_code = code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
1073 1.1 skrll /* If this is a mov.b instruction, clear the lower
1074 1.1 skrll nibble, which contains the source/destination
1075 1.1 skrll register number. */
1076 1.1 skrll if ((temp_code & 0x10) != 0x10)
1077 1.1 skrll temp_code &= 0xf0;
1078 1.1 skrll
1079 1.1 skrll switch (temp_code)
1080 1.1 skrll {
1081 1.1 skrll case 0x00:
1082 1.1 skrll /* This is mov.b @aa:16,Rd. */
1083 1.1 skrll bfd_put_8 (abfd, (code & 0xf) | 0x20,
1084 1.1 skrll contents + irel->r_offset - 2);
1085 1.1 skrll break;
1086 1.1 skrll case 0x80:
1087 1.1 skrll /* This is mov.b Rs,@aa:16. */
1088 1.1 skrll bfd_put_8 (abfd, (code & 0xf) | 0x30,
1089 1.1 skrll contents + irel->r_offset - 2);
1090 1.1 skrll break;
1091 1.1 skrll case 0x18:
1092 1.1 skrll /* This is a bit-maniputation instruction that
1093 1.1 skrll stores one bit into memory, one of "bclr",
1094 1.1 skrll "bist", "bnot", "bset", and "bst". */
1095 1.1 skrll bfd_put_8 (abfd, 0x7f, contents + irel->r_offset - 2);
1096 1.1 skrll break;
1097 1.1 skrll case 0x10:
1098 1.1 skrll /* This is a bit-maniputation instruction that
1099 1.1 skrll loads one bit from memory, one of "band",
1100 1.1 skrll "biand", "bild", "bior", "bixor", "bld", "bor",
1101 1.1 skrll "btst", and "bxor". */
1102 1.1 skrll bfd_put_8 (abfd, 0x7e, contents + irel->r_offset - 2);
1103 1.1 skrll break;
1104 1.1 skrll default:
1105 1.1 skrll abort ();
1106 1.1 skrll }
1107 1.1 skrll
1108 1.1 skrll /* Fix the relocation's type. */
1109 1.1 skrll irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1110 1.1 skrll R_H8_DIR8);
1111 1.1 skrll
1112 1.1 skrll /* Move the relocation. */
1113 1.1 skrll irel->r_offset--;
1114 1.1 skrll
1115 1.1 skrll /* Delete two bytes of data. */
1116 1.1 skrll if (!elf32_h8_relax_delete_bytes (abfd, sec,
1117 1.1 skrll irel->r_offset + 1, 2))
1118 1.1 skrll goto error_return;
1119 1.1 skrll
1120 1.1 skrll /* That will change things, so, we should relax again.
1121 1.1 skrll Note that this is not required, and it may be slow. */
1122 1.1 skrll *again = TRUE;
1123 1.1 skrll }
1124 1.1 skrll break;
1125 1.1 skrll }
1126 1.1.1.4 christos
1127 1.1.1.4 christos /* This is a 24-bit absolute address in one of the following
1128 1.1 skrll instructions:
1129 1.1 skrll
1130 1.1 skrll "band", "bclr", "biand", "bild", "bior", "bist", "bixor",
1131 1.1 skrll "bld", "bnot", "bor", "bset", "bst", "btst", "bxor", and
1132 1.1 skrll "mov.b"
1133 1.1.1.4 christos
1134 1.1.1.4 christos We may relax this into an 8-bit absolute address if it's in
1135 1.1 skrll the right range. */
1136 1.1 skrll case R_H8_DIR24A8:
1137 1.1 skrll {
1138 1.1 skrll bfd_vma value;
1139 1.1 skrll
1140 1.1 skrll value = bfd_h8300_pad_address (abfd, symval + irel->r_addend);
1141 1.1 skrll if (value >= 0xffffff00u)
1142 1.1 skrll {
1143 1.1 skrll unsigned char code;
1144 1.1 skrll unsigned char temp_code;
1145 1.1 skrll
1146 1.1 skrll /* Note that we've changed the relocs, section contents,
1147 1.1 skrll etc. */
1148 1.1 skrll elf_section_data (sec)->relocs = internal_relocs;
1149 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
1150 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
1151 1.1 skrll
1152 1.1 skrll /* Get the opcode. */
1153 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
1154 1.1 skrll
1155 1.1 skrll /* All instructions with R_H8_DIR24A8 start with
1156 1.1 skrll 0x6a. */
1157 1.1 skrll if (code != 0x6a)
1158 1.1 skrll abort ();
1159 1.1 skrll
1160 1.1 skrll temp_code = code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
1161 1.1 skrll
1162 1.1 skrll /* If this is a mov.b instruction, clear the lower
1163 1.1 skrll nibble, which contains the source/destination
1164 1.1 skrll register number. */
1165 1.1 skrll if ((temp_code & 0x30) != 0x30)
1166 1.1 skrll temp_code &= 0xf0;
1167 1.1 skrll
1168 1.1 skrll switch (temp_code)
1169 1.1 skrll {
1170 1.1 skrll case 0x20:
1171 1.1 skrll /* This is mov.b @aa:24/32,Rd. */
1172 1.1 skrll bfd_put_8 (abfd, (code & 0xf) | 0x20,
1173 1.1 skrll contents + irel->r_offset - 2);
1174 1.1 skrll break;
1175 1.1 skrll case 0xa0:
1176 1.1 skrll /* This is mov.b Rs,@aa:24/32. */
1177 1.1 skrll bfd_put_8 (abfd, (code & 0xf) | 0x30,
1178 1.1 skrll contents + irel->r_offset - 2);
1179 1.1 skrll break;
1180 1.1 skrll case 0x38:
1181 1.1 skrll /* This is a bit-maniputation instruction that
1182 1.1 skrll stores one bit into memory, one of "bclr",
1183 1.1 skrll "bist", "bnot", "bset", and "bst". */
1184 1.1 skrll bfd_put_8 (abfd, 0x7f, contents + irel->r_offset - 2);
1185 1.1 skrll break;
1186 1.1 skrll case 0x30:
1187 1.1 skrll /* This is a bit-maniputation instruction that
1188 1.1 skrll loads one bit from memory, one of "band",
1189 1.1 skrll "biand", "bild", "bior", "bixor", "bld", "bor",
1190 1.1 skrll "btst", and "bxor". */
1191 1.1 skrll bfd_put_8 (abfd, 0x7e, contents + irel->r_offset - 2);
1192 1.1 skrll break;
1193 1.1 skrll default:
1194 1.1 skrll abort();
1195 1.1 skrll }
1196 1.1 skrll
1197 1.1 skrll /* Fix the relocation's type. */
1198 1.1 skrll irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1199 1.1 skrll R_H8_DIR8);
1200 1.1 skrll irel->r_offset--;
1201 1.1.1.4 christos
1202 1.1 skrll /* Delete four bytes of data. */
1203 1.1 skrll if (!elf32_h8_relax_delete_bytes (abfd, sec,
1204 1.1 skrll irel->r_offset + 1, 4))
1205 1.1 skrll goto error_return;
1206 1.1 skrll
1207 1.1 skrll /* That will change things, so, we should relax again.
1208 1.1 skrll Note that this is not required, and it may be slow. */
1209 1.1 skrll *again = TRUE;
1210 1.1 skrll break;
1211 1.1 skrll }
1212 1.1 skrll }
1213 1.1 skrll
1214 1.1 skrll /* Fall through. */
1215 1.1 skrll
1216 1.1 skrll /* This is a 24-/32-bit absolute address in one of the
1217 1.1 skrll following instructions:
1218 1.1.1.4 christos
1219 1.1.1.4 christos "band", "bclr", "biand", "bild", "bior", "bist",
1220 1.1.1.4 christos "bixor", "bld", "bnot", "bor", "bset", "bst", "btst",
1221 1.1 skrll "bxor", "ldc.w", "stc.w" and "mov.[bwl]"
1222 1.1 skrll
1223 1.1 skrll We may relax this into an 16-bit absolute address if it's
1224 1.1 skrll in the right range. */
1225 1.1 skrll case R_H8_DIR32A16:
1226 1.1 skrll {
1227 1.1 skrll bfd_vma value;
1228 1.1 skrll
1229 1.1 skrll value = bfd_h8300_pad_address (abfd, symval + irel->r_addend);
1230 1.1 skrll if (value <= 0x7fff || value >= 0xffff8000u)
1231 1.1 skrll {
1232 1.1.1.2 christos unsigned char code;
1233 1.1.1.2 christos unsigned char op0, op1, op2, op3;
1234 1.1 skrll unsigned char *op_ptr;
1235 1.1 skrll
1236 1.1 skrll /* Note that we've changed the relocs, section contents,
1237 1.1 skrll etc. */
1238 1.1 skrll elf_section_data (sec)->relocs = internal_relocs;
1239 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
1240 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
1241 1.1.1.2 christos
1242 1.1.1.2 christos if (irel->r_offset >= 4)
1243 1.1.1.4 christos {
1244 1.1.1.2 christos /* Check for 4-byte MOVA relaxation (SH-specific). */
1245 1.1.1.2 christos int second_reloc = 0;
1246 1.1.1.2 christos
1247 1.1.1.2 christos op_ptr = contents + irel->r_offset - 4;
1248 1.1.1.2 christos
1249 1.1.1.2 christos if (last_reloc)
1250 1.1.1.2 christos {
1251 1.1.1.2 christos arelent bfd_reloc;
1252 1.1.1.2 christos reloc_howto_type *h;
1253 1.1.1.2 christos bfd_vma last_reloc_size;
1254 1.1.1.6.2.1 christos
1255 1.1.1.6.2.1 christos if (! elf32_h8_info_to_howto (abfd, &bfd_reloc, last_reloc))
1256 1.1.1.2 christos break;
1257 1.1.1.2 christos h = bfd_reloc.howto;
1258 1.1.1.2 christos last_reloc_size = 1 << h->size;
1259 1.1.1.2 christos if (last_reloc->r_offset + last_reloc_size
1260 1.1.1.2 christos == irel->r_offset)
1261 1.1.1.2 christos {
1262 1.1.1.2 christos op_ptr -= last_reloc_size;
1263 1.1.1.2 christos second_reloc = 1;
1264 1.1.1.2 christos }
1265 1.1.1.4 christos }
1266 1.1.1.4 christos
1267 1.1.1.2 christos if (irel + 1 < irelend)
1268 1.1.1.2 christos {
1269 1.1.1.2 christos Elf_Internal_Rela *next_reloc = irel + 1;
1270 1.1.1.2 christos arelent bfd_reloc;
1271 1.1.1.2 christos reloc_howto_type *h;
1272 1.1.1.2 christos bfd_vma next_reloc_size;
1273 1.1.1.6.2.1 christos
1274 1.1.1.6.2.1 christos if (! elf32_h8_info_to_howto (abfd, &bfd_reloc, next_reloc))
1275 1.1.1.2 christos break;
1276 1.1.1.2 christos h = bfd_reloc.howto;
1277 1.1.1.2 christos next_reloc_size = 1 << h->size;
1278 1.1.1.2 christos if (next_reloc->r_offset + next_reloc_size
1279 1.1.1.2 christos == irel->r_offset)
1280 1.1.1.2 christos {
1281 1.1.1.2 christos op_ptr -= next_reloc_size;
1282 1.1.1.2 christos second_reloc = 1;
1283 1.1.1.2 christos }
1284 1.1.1.2 christos }
1285 1.1.1.2 christos
1286 1.1.1.2 christos op0 = bfd_get_8 (abfd, op_ptr + 0);
1287 1.1.1.2 christos op1 = bfd_get_8 (abfd, op_ptr + 1);
1288 1.1.1.2 christos op2 = bfd_get_8 (abfd, op_ptr + 2);
1289 1.1.1.2 christos op3 = bfd_get_8 (abfd, op_ptr + 3);
1290 1.1.1.2 christos
1291 1.1.1.2 christos if (op0 == 0x01
1292 1.1.1.2 christos && (op1 & 0xdf) == 0x5f
1293 1.1.1.2 christos && (op2 & 0x40) == 0x40
1294 1.1.1.2 christos && (op3 & 0x80) == 0x80)
1295 1.1.1.2 christos {
1296 1.1.1.2 christos if ((op2 & 0x08) == 0)
1297 1.1.1.2 christos second_reloc = 1;
1298 1.1.1.2 christos
1299 1.1.1.2 christos if (second_reloc)
1300 1.1.1.2 christos {
1301 1.1.1.2 christos op3 &= ~0x08;
1302 1.1.1.2 christos bfd_put_8 (abfd, op3, op_ptr + 3);
1303 1.1.1.2 christos }
1304 1.1.1.2 christos else
1305 1.1.1.2 christos {
1306 1.1.1.2 christos op2 &= ~0x08;
1307 1.1.1.2 christos bfd_put_8 (abfd, op2, op_ptr + 2);
1308 1.1.1.2 christos }
1309 1.1.1.2 christos goto r_h8_dir32a16_common;
1310 1.1.1.2 christos }
1311 1.1.1.2 christos }
1312 1.1.1.4 christos
1313 1.1.1.2 christos /* Now check for short version of MOVA. (SH-specific) */
1314 1.1.1.2 christos op_ptr = contents + irel->r_offset - 2;
1315 1.1.1.2 christos op0 = bfd_get_8 (abfd, op_ptr + 0);
1316 1.1.1.2 christos op1 = bfd_get_8 (abfd, op_ptr + 1);
1317 1.1.1.2 christos
1318 1.1.1.2 christos if (op0 == 0x7a
1319 1.1.1.2 christos && (op1 & 0x88) == 0x80)
1320 1.1.1.2 christos {
1321 1.1.1.2 christos op1 |= 0x08;
1322 1.1.1.2 christos bfd_put_8 (abfd, op1, op_ptr + 1);
1323 1.1.1.2 christos goto r_h8_dir32a16_common;
1324 1.1.1.2 christos }
1325 1.1 skrll
1326 1.1 skrll /* Get the opcode. */
1327 1.1 skrll code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
1328 1.1 skrll
1329 1.1 skrll /* Fix the opcode. For all the instructions that
1330 1.1 skrll belong to this relaxation, we simply need to turn
1331 1.1 skrll off bit 0x20 in the previous byte. */
1332 1.1 skrll code &= ~0x20;
1333 1.1 skrll
1334 1.1 skrll bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
1335 1.1.1.2 christos
1336 1.1 skrll r_h8_dir32a16_common:
1337 1.1 skrll /* Fix the relocation's type. */
1338 1.1 skrll irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
1339 1.1 skrll R_H8_DIR16);
1340 1.1 skrll
1341 1.1 skrll /* Delete two bytes of data. */
1342 1.1 skrll if (!elf32_h8_relax_delete_bytes (abfd, sec,
1343 1.1 skrll irel->r_offset + 1, 2))
1344 1.1 skrll goto error_return;
1345 1.1 skrll
1346 1.1 skrll /* That will change things, so, we should relax again.
1347 1.1 skrll Note that this is not required, and it may be slow. */
1348 1.1 skrll *again = TRUE;
1349 1.1.1.4 christos }
1350 1.1.1.4 christos break; /* case R_H8_DIR32A16 */
1351 1.1.1.4 christos }
1352 1.1.1.4 christos
1353 1.1.1.4 christos case R_H8_DISP32A16:
1354 1.1.1.4 christos /* mov.[bwl] @(displ:24/32+ERx) -> mov.[bwl] @(displ:16+ERx) 4 bytes
1355 1.1.1.4 christos It is assured that instruction uses at least 4 bytes opcode before
1356 1.1.1.4 christos reloc entry addressing mode "register indirect with displacement"
1357 1.1.1.4 christos relaxing options (all saving 4 bytes):
1358 1.1.1.4 christos 0x78 0sss0000 0x6A 0010dddd disp:32 mov.b @(d:32,ERs),Rd ->
1359 1.1.1.4 christos 0x6E 0sssdddd disp:16 mov.b @(d:16,ERs),Rd
1360 1.1.1.4 christos 0x78 0sss0000 0x6B 0010dddd disp:32 mov.w @(d:32,ERs),Rd ->
1361 1.1.1.4 christos 0x6F 0sssdddd disp:16 mov.w @(d:16,ERs),Rd
1362 1.1.1.4 christos 0x01 0x00 0x78 0sss0000 0x6B 00100ddd disp:32 mov.l @(d:32,ERs),ERd ->
1363 1.1.1.4 christos 0x01 0x00 0x6F 0sss0ddd disp:16 mov.l @(d:16,ERs),ERd
1364 1.1.1.4 christos
1365 1.1.1.4 christos 0x78 0ddd0000 0x6A 1010ssss disp:32 mov.b Rs,@(d:32,ERd) ->
1366 1.1.1.4 christos 0x6E 1dddssss disp:16 mov.b Rs,@(d:16,ERd)
1367 1.1.1.4 christos 0x78 0ddd0000 0x6B 1010ssss disp:32 mov.w Rs,@(d:32,ERd) ->
1368 1.1.1.4 christos 0x6F 1dddssss disp:16 mov.w Rs,@(d:16,ERd)
1369 1.1.1.4 christos 0x01 0x00 0x78 xddd0000 0x6B 10100sss disp:32 mov.l ERs,@(d:32,ERd) ->
1370 1.1.1.4 christos 0x01 0x00 0x6F 1ddd0sss disp:16 mov.l ERs,@(d:16,ERd)
1371 1.1.1.4 christos mov.l prefix 0x01 0x00 can be left as is and mov.l handled same
1372 1.1.1.4 christos as mov.w/ */
1373 1.1.1.4 christos {
1374 1.1.1.4 christos bfd_vma value;
1375 1.1.1.4 christos
1376 1.1.1.4 christos value = bfd_h8300_pad_address (abfd, symval + irel->r_addend);
1377 1.1.1.4 christos if (value <= 0x7fff || value >= 0xffff8000u)
1378 1.1.1.4 christos {
1379 1.1.1.4 christos unsigned char op0, op1, op2, op3, op0n, op1n;
1380 1.1.1.4 christos int relax = 0;
1381 1.1.1.4 christos
1382 1.1.1.4 christos /* Note that we've changed the relocs, section contents,
1383 1.1.1.4 christos etc. */
1384 1.1.1.4 christos elf_section_data (sec)->relocs = internal_relocs;
1385 1.1.1.4 christos elf_section_data (sec)->this_hdr.contents = contents;
1386 1.1.1.4 christos symtab_hdr->contents = (unsigned char *) isymbuf;
1387 1.1.1.4 christos
1388 1.1.1.4 christos if (irel->r_offset >= 4)
1389 1.1.1.4 christos {
1390 1.1.1.4 christos op0 = bfd_get_8 (abfd, contents + irel->r_offset - 4);
1391 1.1.1.4 christos op1 = bfd_get_8 (abfd, contents + irel->r_offset - 3);
1392 1.1.1.4 christos op2 = bfd_get_8 (abfd, contents + irel->r_offset - 2);
1393 1.1.1.4 christos op3 = bfd_get_8 (abfd, contents + irel->r_offset - 1);
1394 1.1.1.4 christos
1395 1.1.1.4 christos if (op0 == 0x78)
1396 1.1.1.4 christos {
1397 1.1.1.4 christos switch(op2)
1398 1.1.1.4 christos {
1399 1.1.1.4 christos case 0x6A:
1400 1.1.1.4 christos if ((op1 & 0x8F) == 0x00 && (op3 & 0x70) == 0x20)
1401 1.1.1.4 christos {
1402 1.1.1.4 christos /* mov.b. */
1403 1.1.1.4 christos op0n = 0x6E;
1404 1.1.1.4 christos relax = 1;
1405 1.1.1.4 christos }
1406 1.1.1.4 christos break;
1407 1.1.1.4 christos case 0x6B:
1408 1.1.1.4 christos if ((op1 & 0x0F) == 0x00 && (op3 & 0x70) == 0x20)
1409 1.1.1.4 christos {
1410 1.1.1.4 christos /* mov.w/l. */
1411 1.1.1.4 christos op0n = 0x6F;
1412 1.1.1.4 christos relax = 1;
1413 1.1.1.4 christos }
1414 1.1.1.4 christos break;
1415 1.1.1.4 christos default:
1416 1.1.1.4 christos break;
1417 1.1.1.4 christos }
1418 1.1.1.4 christos }
1419 1.1.1.4 christos }
1420 1.1.1.4 christos
1421 1.1.1.4 christos if (relax)
1422 1.1.1.4 christos {
1423 1.1.1.4 christos op1n = (op3 & 0x8F) | (op1 & 0x70);
1424 1.1.1.4 christos bfd_put_8 (abfd, op0n, contents + irel->r_offset - 4);
1425 1.1.1.4 christos bfd_put_8 (abfd, op1n, contents + irel->r_offset - 3);
1426 1.1.1.4 christos
1427 1.1.1.4 christos /* Fix the relocation's type. */
1428 1.1.1.4 christos irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_H8_DIR16);
1429 1.1.1.4 christos irel->r_offset -= 2;
1430 1.1.1.4 christos
1431 1.1.1.4 christos /* Delete four bytes of data. */
1432 1.1.1.4 christos if (!elf32_h8_relax_delete_bytes (abfd, sec, irel->r_offset + 2, 4))
1433 1.1.1.4 christos goto error_return;
1434 1.1.1.4 christos
1435 1.1.1.4 christos /* That will change things, so, we should relax again.
1436 1.1.1.4 christos Note that this is not required, and it may be slow. */
1437 1.1.1.4 christos *again = TRUE;
1438 1.1.1.4 christos }
1439 1.1 skrll }
1440 1.1.1.4 christos }
1441 1.1 skrll break;
1442 1.1 skrll
1443 1.1 skrll default:
1444 1.1 skrll break;
1445 1.1 skrll }
1446 1.1 skrll }
1447 1.1 skrll
1448 1.1 skrll if (isymbuf != NULL
1449 1.1 skrll && symtab_hdr->contents != (unsigned char *) isymbuf)
1450 1.1 skrll {
1451 1.1 skrll if (! link_info->keep_memory)
1452 1.1 skrll free (isymbuf);
1453 1.1 skrll else
1454 1.1 skrll symtab_hdr->contents = (unsigned char *) isymbuf;
1455 1.1 skrll }
1456 1.1 skrll
1457 1.1 skrll if (contents != NULL
1458 1.1 skrll && elf_section_data (sec)->this_hdr.contents != contents)
1459 1.1 skrll {
1460 1.1 skrll if (! link_info->keep_memory)
1461 1.1 skrll free (contents);
1462 1.1 skrll else
1463 1.1 skrll {
1464 1.1 skrll /* Cache the section contents for elf_link_input_bfd. */
1465 1.1 skrll elf_section_data (sec)->this_hdr.contents = contents;
1466 1.1 skrll }
1467 1.1 skrll }
1468 1.1 skrll
1469 1.1 skrll if (internal_relocs != NULL
1470 1.1 skrll && elf_section_data (sec)->relocs != internal_relocs)
1471 1.1 skrll free (internal_relocs);
1472 1.1 skrll
1473 1.1 skrll return TRUE;
1474 1.1 skrll
1475 1.1 skrll error_return:
1476 1.1 skrll if (isymbuf != NULL
1477 1.1 skrll && symtab_hdr->contents != (unsigned char *) isymbuf)
1478 1.1 skrll free (isymbuf);
1479 1.1 skrll if (contents != NULL
1480 1.1 skrll && elf_section_data (sec)->this_hdr.contents != contents)
1481 1.1 skrll free (contents);
1482 1.1 skrll if (internal_relocs != NULL
1483 1.1 skrll && elf_section_data (sec)->relocs != internal_relocs)
1484 1.1 skrll free (internal_relocs);
1485 1.1 skrll return FALSE;
1486 1.1 skrll }
1487 1.1 skrll
1488 1.1 skrll /* Delete some bytes from a section while relaxing. */
1489 1.1 skrll
1490 1.1 skrll static bfd_boolean
1491 1.1 skrll elf32_h8_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr, int count)
1492 1.1 skrll {
1493 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
1494 1.1 skrll unsigned int sec_shndx;
1495 1.1 skrll bfd_byte *contents;
1496 1.1 skrll Elf_Internal_Rela *irel, *irelend;
1497 1.1 skrll Elf_Internal_Sym *isym;
1498 1.1 skrll Elf_Internal_Sym *isymend;
1499 1.1 skrll bfd_vma toaddr;
1500 1.1 skrll struct elf_link_hash_entry **sym_hashes;
1501 1.1 skrll struct elf_link_hash_entry **end_hashes;
1502 1.1 skrll unsigned int symcount;
1503 1.1 skrll
1504 1.1 skrll sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
1505 1.1 skrll
1506 1.1 skrll contents = elf_section_data (sec)->this_hdr.contents;
1507 1.1 skrll
1508 1.1 skrll toaddr = sec->size;
1509 1.1 skrll
1510 1.1 skrll irel = elf_section_data (sec)->relocs;
1511 1.1 skrll irelend = irel + sec->reloc_count;
1512 1.1 skrll
1513 1.1 skrll /* Actually delete the bytes. */
1514 1.1 skrll memmove (contents + addr, contents + addr + count,
1515 1.1 skrll (size_t) (toaddr - addr - count));
1516 1.1 skrll sec->size -= count;
1517 1.1 skrll
1518 1.1 skrll /* Adjust all the relocs. */
1519 1.1 skrll for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
1520 1.1 skrll {
1521 1.1 skrll /* Get the new reloc address. */
1522 1.1.1.4 christos if ((irel->r_offset > addr
1523 1.1 skrll && irel->r_offset <= toaddr))
1524 1.1 skrll irel->r_offset -= count;
1525 1.1 skrll }
1526 1.1 skrll
1527 1.1 skrll /* Adjust the local symbols defined in this section. */
1528 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1529 1.1 skrll isym = (Elf_Internal_Sym *) symtab_hdr->contents;
1530 1.1 skrll isymend = isym + symtab_hdr->sh_info;
1531 1.1 skrll for (; isym < isymend; isym++)
1532 1.1 skrll {
1533 1.1 skrll if (isym->st_shndx == sec_shndx
1534 1.1.1.4 christos && isym->st_value > addr
1535 1.1 skrll && isym->st_value <= toaddr)
1536 1.1 skrll isym->st_value -= count;
1537 1.1 skrll }
1538 1.1 skrll
1539 1.1 skrll /* Now adjust the global symbols defined in this section. */
1540 1.1 skrll symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1541 1.1 skrll - symtab_hdr->sh_info);
1542 1.1 skrll sym_hashes = elf_sym_hashes (abfd);
1543 1.1 skrll end_hashes = sym_hashes + symcount;
1544 1.1 skrll for (; sym_hashes < end_hashes; sym_hashes++)
1545 1.1 skrll {
1546 1.1.1.4 christos struct elf_link_hash_entry *sym_hash = *sym_hashes;
1547 1.1 skrll
1548 1.1 skrll if ((sym_hash->root.type == bfd_link_hash_defined
1549 1.1 skrll || sym_hash->root.type == bfd_link_hash_defweak)
1550 1.1 skrll && sym_hash->root.u.def.section == sec
1551 1.1.1.4 christos && sym_hash->root.u.def.value > addr
1552 1.1.1.4 christos && sym_hash->root.u.def.value <= toaddr)
1553 1.1 skrll sym_hash->root.u.def.value -= count;
1554 1.1 skrll }
1555 1.1 skrll
1556 1.1 skrll return TRUE;
1557 1.1 skrll }
1558 1.1 skrll
1559 1.1 skrll /* Return TRUE if a symbol exists at the given address, else return
1560 1.1 skrll FALSE. */
1561 1.1 skrll static bfd_boolean
1562 1.1 skrll elf32_h8_symbol_address_p (bfd *abfd, asection *sec, bfd_vma addr)
1563 1.1 skrll {
1564 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
1565 1.1 skrll unsigned int sec_shndx;
1566 1.1 skrll Elf_Internal_Sym *isym;
1567 1.1 skrll Elf_Internal_Sym *isymend;
1568 1.1 skrll struct elf_link_hash_entry **sym_hashes;
1569 1.1 skrll struct elf_link_hash_entry **end_hashes;
1570 1.1 skrll unsigned int symcount;
1571 1.1 skrll
1572 1.1 skrll sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
1573 1.1 skrll
1574 1.1 skrll /* Examine all the symbols. */
1575 1.1 skrll symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1576 1.1 skrll isym = (Elf_Internal_Sym *) symtab_hdr->contents;
1577 1.1 skrll isymend = isym + symtab_hdr->sh_info;
1578 1.1 skrll for (; isym < isymend; isym++)
1579 1.1 skrll {
1580 1.1 skrll if (isym->st_shndx == sec_shndx
1581 1.1 skrll && isym->st_value == addr)
1582 1.1 skrll return TRUE;
1583 1.1 skrll }
1584 1.1 skrll
1585 1.1 skrll symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1586 1.1 skrll - symtab_hdr->sh_info);
1587 1.1 skrll sym_hashes = elf_sym_hashes (abfd);
1588 1.1 skrll end_hashes = sym_hashes + symcount;
1589 1.1 skrll for (; sym_hashes < end_hashes; sym_hashes++)
1590 1.1 skrll {
1591 1.1 skrll struct elf_link_hash_entry *sym_hash = *sym_hashes;
1592 1.1 skrll if ((sym_hash->root.type == bfd_link_hash_defined
1593 1.1 skrll || sym_hash->root.type == bfd_link_hash_defweak)
1594 1.1 skrll && sym_hash->root.u.def.section == sec
1595 1.1 skrll && sym_hash->root.u.def.value == addr)
1596 1.1 skrll return TRUE;
1597 1.1 skrll }
1598 1.1 skrll
1599 1.1 skrll return FALSE;
1600 1.1 skrll }
1601 1.1 skrll
1602 1.1 skrll /* This is a version of bfd_generic_get_relocated_section_contents
1603 1.1 skrll which uses elf32_h8_relocate_section. */
1604 1.1 skrll
1605 1.1 skrll static bfd_byte *
1606 1.1 skrll elf32_h8_get_relocated_section_contents (bfd *output_bfd,
1607 1.1 skrll struct bfd_link_info *link_info,
1608 1.1 skrll struct bfd_link_order *link_order,
1609 1.1 skrll bfd_byte *data,
1610 1.1 skrll bfd_boolean relocatable,
1611 1.1 skrll asymbol **symbols)
1612 1.1 skrll {
1613 1.1 skrll Elf_Internal_Shdr *symtab_hdr;
1614 1.1 skrll asection *input_section = link_order->u.indirect.section;
1615 1.1 skrll bfd *input_bfd = input_section->owner;
1616 1.1 skrll asection **sections = NULL;
1617 1.1 skrll Elf_Internal_Rela *internal_relocs = NULL;
1618 1.1 skrll Elf_Internal_Sym *isymbuf = NULL;
1619 1.1 skrll
1620 1.1 skrll /* We only need to handle the case of relaxing, or of having a
1621 1.1 skrll particular set of section contents, specially. */
1622 1.1 skrll if (relocatable
1623 1.1 skrll || elf_section_data (input_section)->this_hdr.contents == NULL)
1624 1.1 skrll return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
1625 1.1 skrll link_order, data,
1626 1.1 skrll relocatable,
1627 1.1 skrll symbols);
1628 1.1 skrll
1629 1.1 skrll symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1630 1.1 skrll
1631 1.1 skrll memcpy (data, elf_section_data (input_section)->this_hdr.contents,
1632 1.1 skrll (size_t) input_section->size);
1633 1.1 skrll
1634 1.1 skrll if ((input_section->flags & SEC_RELOC) != 0
1635 1.1 skrll && input_section->reloc_count > 0)
1636 1.1 skrll {
1637 1.1 skrll asection **secpp;
1638 1.1 skrll Elf_Internal_Sym *isym, *isymend;
1639 1.1 skrll bfd_size_type amt;
1640 1.1 skrll
1641 1.1.1.3 christos internal_relocs = (_bfd_elf_link_read_relocs
1642 1.1 skrll (input_bfd, input_section, NULL,
1643 1.1 skrll (Elf_Internal_Rela *) NULL, FALSE));
1644 1.1 skrll if (internal_relocs == NULL)
1645 1.1 skrll goto error_return;
1646 1.1 skrll
1647 1.1 skrll if (symtab_hdr->sh_info != 0)
1648 1.1 skrll {
1649 1.1 skrll isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1650 1.1 skrll if (isymbuf == NULL)
1651 1.1 skrll isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
1652 1.1 skrll symtab_hdr->sh_info, 0,
1653 1.1 skrll NULL, NULL, NULL);
1654 1.1 skrll if (isymbuf == NULL)
1655 1.1 skrll goto error_return;
1656 1.1 skrll }
1657 1.1 skrll
1658 1.1 skrll amt = symtab_hdr->sh_info;
1659 1.1 skrll amt *= sizeof (asection *);
1660 1.1 skrll sections = (asection **) bfd_malloc (amt);
1661 1.1 skrll if (sections == NULL && amt != 0)
1662 1.1 skrll goto error_return;
1663 1.1 skrll
1664 1.1 skrll isymend = isymbuf + symtab_hdr->sh_info;
1665 1.1 skrll for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
1666 1.1 skrll {
1667 1.1 skrll asection *isec;
1668 1.1 skrll
1669 1.1 skrll if (isym->st_shndx == SHN_UNDEF)
1670 1.1 skrll isec = bfd_und_section_ptr;
1671 1.1 skrll else if (isym->st_shndx == SHN_ABS)
1672 1.1 skrll isec = bfd_abs_section_ptr;
1673 1.1 skrll else if (isym->st_shndx == SHN_COMMON)
1674 1.1 skrll isec = bfd_com_section_ptr;
1675 1.1 skrll else
1676 1.1 skrll isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
1677 1.1 skrll
1678 1.1 skrll *secpp = isec;
1679 1.1 skrll }
1680 1.1 skrll
1681 1.1 skrll if (! elf32_h8_relocate_section (output_bfd, link_info, input_bfd,
1682 1.1 skrll input_section, data, internal_relocs,
1683 1.1 skrll isymbuf, sections))
1684 1.1 skrll goto error_return;
1685 1.1 skrll
1686 1.1 skrll if (sections != NULL)
1687 1.1 skrll free (sections);
1688 1.1 skrll if (isymbuf != NULL
1689 1.1 skrll && symtab_hdr->contents != (unsigned char *) isymbuf)
1690 1.1 skrll free (isymbuf);
1691 1.1 skrll if (elf_section_data (input_section)->relocs != internal_relocs)
1692 1.1 skrll free (internal_relocs);
1693 1.1 skrll }
1694 1.1 skrll
1695 1.1 skrll return data;
1696 1.1 skrll
1697 1.1 skrll error_return:
1698 1.1 skrll if (sections != NULL)
1699 1.1 skrll free (sections);
1700 1.1 skrll if (isymbuf != NULL
1701 1.1 skrll && symtab_hdr->contents != (unsigned char *) isymbuf)
1702 1.1 skrll free (isymbuf);
1703 1.1 skrll if (internal_relocs != NULL
1704 1.1 skrll && elf_section_data (input_section)->relocs != internal_relocs)
1705 1.1 skrll free (internal_relocs);
1706 1.1 skrll return NULL;
1707 1.1 skrll }
1708 1.1 skrll
1709 1.1.1.4 christos
1710 1.1 skrll #define TARGET_BIG_SYM h8300_elf32_vec
1711 1.1 skrll #define TARGET_BIG_NAME "elf32-h8300"
1712 1.1 skrll #define ELF_ARCH bfd_arch_h8300
1713 1.1 skrll #define ELF_MACHINE_CODE EM_H8_300
1714 1.1 skrll #define ELF_MAXPAGESIZE 0x1
1715 1.1 skrll #define bfd_elf32_bfd_reloc_type_lookup elf32_h8_reloc_type_lookup
1716 1.1 skrll #define bfd_elf32_bfd_reloc_name_lookup elf32_h8_reloc_name_lookup
1717 1.1 skrll #define elf_info_to_howto elf32_h8_info_to_howto
1718 1.1 skrll #define elf_info_to_howto_rel elf32_h8_info_to_howto_rel
1719 1.1 skrll
1720 1.1 skrll /* So we can set/examine bits in e_flags to get the specific
1721 1.1 skrll H8 architecture in use. */
1722 1.1 skrll #define elf_backend_final_write_processing \
1723 1.1 skrll elf32_h8_final_write_processing
1724 1.1 skrll #define elf_backend_object_p \
1725 1.1 skrll elf32_h8_object_p
1726 1.1 skrll #define bfd_elf32_bfd_merge_private_bfd_data \
1727 1.1 skrll elf32_h8_merge_private_bfd_data
1728 1.1 skrll
1729 1.1 skrll /* ??? when elf_backend_relocate_section is not defined, elf32-target.h
1730 1.1 skrll defaults to using _bfd_generic_link_hash_table_create, but
1731 1.1 skrll bfd_elf_size_dynamic_sections uses
1732 1.1 skrll dynobj = elf_hash_table (info)->dynobj;
1733 1.1 skrll and thus requires an elf hash table. */
1734 1.1 skrll #define bfd_elf32_bfd_link_hash_table_create _bfd_elf_link_hash_table_create
1735 1.1 skrll
1736 1.1 skrll /* Use an H8 specific linker, not the ELF generic linker. */
1737 1.1 skrll #define elf_backend_relocate_section elf32_h8_relocate_section
1738 1.1 skrll #define elf_backend_rela_normal 1
1739 1.1 skrll #define elf_backend_can_gc_sections 1
1740 1.1 skrll
1741 1.1 skrll /* And relaxing stuff. */
1742 1.1 skrll #define bfd_elf32_bfd_relax_section elf32_h8_relax_section
1743 1.1.1.6 christos #define bfd_elf32_bfd_get_relocated_section_contents \
1744 1.1 skrll elf32_h8_get_relocated_section_contents
1745 1.1.1.2 christos
1746 1.1 skrll #define elf_symbol_leading_char '_'
1747 1.1 skrll
1748 1.1.1.4 christos #include "elf32-target.h"
1749 1.1.1.4 christos
1750 1.1.1.4 christos #undef TARGET_BIG_SYM
1751 1.1.1.4 christos #define TARGET_BIG_SYM h8300_elf32_linux_vec
1752 1.1.1.4 christos #undef TARGET_BIG_NAME
1753 1.1.1.4 christos #define TARGET_BIG_NAME "elf32-h8300-linux"
1754 1.1.1.4 christos #undef elf_symbol_leading_char
1755 1.1.1.4 christos #define elf32_bed elf32_h8300_linux_bed
1756 1.1.1.4 christos
1757 #include "elf32-target.h"
1758