coff-sh.c revision 1.1.1.7 1 1.1 christos /* BFD back-end for Renesas Super-H COFF binaries.
2 1.1.1.7 christos Copyright (C) 1993-2020 Free Software Foundation, Inc.
3 1.1 christos Contributed by Cygnus Support.
4 1.1 christos Written by Steve Chamberlain, <sac (at) cygnus.com>.
5 1.1 christos Relaxing code written by Ian Lance Taylor, <ian (at) cygnus.com>.
6 1.1 christos
7 1.1 christos This file is part of BFD, the Binary File Descriptor library.
8 1.1 christos
9 1.1 christos This program is free software; you can redistribute it and/or modify
10 1.1 christos it under the terms of the GNU General Public License as published by
11 1.1 christos the Free Software Foundation; either version 3 of the License, or
12 1.1 christos (at your option) any later version.
13 1.1 christos
14 1.1 christos This program is distributed in the hope that it will be useful,
15 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
16 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 1.1 christos GNU General Public License for more details.
18 1.1 christos
19 1.1 christos You should have received a copy of the GNU General Public License
20 1.1 christos along with this program; if not, write to the Free Software
21 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 1.1 christos MA 02110-1301, USA. */
23 1.1 christos
24 1.1 christos #include "sysdep.h"
25 1.1 christos #include "bfd.h"
26 1.1 christos #include "libiberty.h"
27 1.1 christos #include "libbfd.h"
28 1.1 christos #include "bfdlink.h"
29 1.1 christos #include "coff/sh.h"
30 1.1 christos #include "coff/internal.h"
31 1.1 christos
32 1.1 christos #undef bfd_pe_print_pdata
33 1.1 christos
34 1.1 christos #ifdef COFF_WITH_PE
35 1.1 christos #include "coff/pe.h"
36 1.1 christos
37 1.1 christos #ifndef COFF_IMAGE_WITH_PE
38 1.1 christos static bfd_boolean sh_align_load_span
39 1.1.1.2 christos (bfd *, asection *, bfd_byte *,
40 1.1.1.2 christos bfd_boolean (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
41 1.1.1.2 christos void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *);
42 1.1 christos
43 1.1 christos #define _bfd_sh_align_load_span sh_align_load_span
44 1.1 christos #endif
45 1.1 christos
46 1.1 christos #define bfd_pe_print_pdata _bfd_pe_print_ce_compressed_pdata
47 1.1 christos
48 1.1 christos #else
49 1.1 christos
50 1.1 christos #define bfd_pe_print_pdata NULL
51 1.1 christos
52 1.1 christos #endif /* COFF_WITH_PE. */
53 1.1 christos
54 1.1 christos #include "libcoff.h"
55 1.1 christos
56 1.1 christos /* Internal functions. */
57 1.1 christos
58 1.1 christos #ifdef COFF_WITH_PE
59 1.1 christos /* Can't build import tables with 2**4 alignment. */
60 1.1 christos #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2
61 1.1 christos #else
62 1.1 christos /* Default section alignment to 2**4. */
63 1.1 christos #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 4
64 1.1 christos #endif
65 1.1 christos
66 1.1 christos #ifdef COFF_IMAGE_WITH_PE
67 1.1 christos /* Align PE executables. */
68 1.1 christos #define COFF_PAGE_SIZE 0x1000
69 1.1 christos #endif
70 1.1 christos
71 1.1 christos /* Generate long file names. */
72 1.1 christos #define COFF_LONG_FILENAMES
73 1.1 christos
74 1.1 christos #ifdef COFF_WITH_PE
75 1.1 christos /* Return TRUE if this relocation should
76 1.1 christos appear in the output .reloc section. */
77 1.1.1.2 christos
78 1.1.1.2 christos static bfd_boolean
79 1.1.1.2 christos in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
80 1.1.1.2 christos reloc_howto_type * howto)
81 1.1 christos {
82 1.1 christos return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE;
83 1.1 christos }
84 1.1 christos #endif
85 1.1 christos
86 1.1.1.2 christos static bfd_reloc_status_type
87 1.1.1.2 christos sh_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
88 1.1.1.2 christos static bfd_boolean
89 1.1.1.2 christos sh_relocate_section (bfd *, struct bfd_link_info *, bfd *, asection *,
90 1.1.1.2 christos bfd_byte *, struct internal_reloc *,
91 1.1.1.2 christos struct internal_syment *, asection **);
92 1.1.1.2 christos static bfd_boolean
93 1.1.1.2 christos sh_align_loads (bfd *, asection *, struct internal_reloc *,
94 1.1.1.2 christos bfd_byte *, bfd_boolean *);
95 1.1.1.2 christos
96 1.1 christos /* The supported relocations. There are a lot of relocations defined
97 1.1 christos in coff/internal.h which we do not expect to ever see. */
98 1.1 christos static reloc_howto_type sh_coff_howtos[] =
99 1.1 christos {
100 1.1 christos EMPTY_HOWTO (0),
101 1.1 christos EMPTY_HOWTO (1),
102 1.1 christos #ifdef COFF_WITH_PE
103 1.1 christos /* Windows CE */
104 1.1 christos HOWTO (R_SH_IMM32CE, /* type */
105 1.1 christos 0, /* rightshift */
106 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
107 1.1 christos 32, /* bitsize */
108 1.1 christos FALSE, /* pc_relative */
109 1.1 christos 0, /* bitpos */
110 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
111 1.1 christos sh_reloc, /* special_function */
112 1.1 christos "r_imm32ce", /* name */
113 1.1 christos TRUE, /* partial_inplace */
114 1.1 christos 0xffffffff, /* src_mask */
115 1.1 christos 0xffffffff, /* dst_mask */
116 1.1 christos FALSE), /* pcrel_offset */
117 1.1 christos #else
118 1.1 christos EMPTY_HOWTO (2),
119 1.1 christos #endif
120 1.1 christos EMPTY_HOWTO (3), /* R_SH_PCREL8 */
121 1.1 christos EMPTY_HOWTO (4), /* R_SH_PCREL16 */
122 1.1 christos EMPTY_HOWTO (5), /* R_SH_HIGH8 */
123 1.1 christos EMPTY_HOWTO (6), /* R_SH_IMM24 */
124 1.1 christos EMPTY_HOWTO (7), /* R_SH_LOW16 */
125 1.1 christos EMPTY_HOWTO (8),
126 1.1 christos EMPTY_HOWTO (9), /* R_SH_PCDISP8BY4 */
127 1.1 christos
128 1.1 christos HOWTO (R_SH_PCDISP8BY2, /* type */
129 1.1 christos 1, /* rightshift */
130 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
131 1.1 christos 8, /* bitsize */
132 1.1 christos TRUE, /* pc_relative */
133 1.1 christos 0, /* bitpos */
134 1.1 christos complain_overflow_signed, /* complain_on_overflow */
135 1.1 christos sh_reloc, /* special_function */
136 1.1 christos "r_pcdisp8by2", /* name */
137 1.1 christos TRUE, /* partial_inplace */
138 1.1 christos 0xff, /* src_mask */
139 1.1 christos 0xff, /* dst_mask */
140 1.1 christos TRUE), /* pcrel_offset */
141 1.1 christos
142 1.1 christos EMPTY_HOWTO (11), /* R_SH_PCDISP8 */
143 1.1 christos
144 1.1 christos HOWTO (R_SH_PCDISP, /* type */
145 1.1 christos 1, /* rightshift */
146 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
147 1.1 christos 12, /* bitsize */
148 1.1 christos TRUE, /* pc_relative */
149 1.1 christos 0, /* bitpos */
150 1.1 christos complain_overflow_signed, /* complain_on_overflow */
151 1.1 christos sh_reloc, /* special_function */
152 1.1 christos "r_pcdisp12by2", /* name */
153 1.1 christos TRUE, /* partial_inplace */
154 1.1 christos 0xfff, /* src_mask */
155 1.1 christos 0xfff, /* dst_mask */
156 1.1 christos TRUE), /* pcrel_offset */
157 1.1 christos
158 1.1 christos EMPTY_HOWTO (13),
159 1.1 christos
160 1.1 christos HOWTO (R_SH_IMM32, /* type */
161 1.1 christos 0, /* rightshift */
162 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
163 1.1 christos 32, /* bitsize */
164 1.1 christos FALSE, /* pc_relative */
165 1.1 christos 0, /* bitpos */
166 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
167 1.1 christos sh_reloc, /* special_function */
168 1.1 christos "r_imm32", /* name */
169 1.1 christos TRUE, /* partial_inplace */
170 1.1 christos 0xffffffff, /* src_mask */
171 1.1 christos 0xffffffff, /* dst_mask */
172 1.1 christos FALSE), /* pcrel_offset */
173 1.1 christos
174 1.1 christos EMPTY_HOWTO (15),
175 1.1 christos #ifdef COFF_WITH_PE
176 1.1.1.6 christos HOWTO (R_SH_IMAGEBASE, /* type */
177 1.1.1.6 christos 0, /* rightshift */
178 1.1.1.6 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
179 1.1.1.6 christos 32, /* bitsize */
180 1.1.1.6 christos FALSE, /* pc_relative */
181 1.1.1.6 christos 0, /* bitpos */
182 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
183 1.1.1.6 christos sh_reloc, /* special_function */
184 1.1.1.6 christos "rva32", /* name */
185 1.1.1.6 christos TRUE, /* partial_inplace */
186 1.1.1.6 christos 0xffffffff, /* src_mask */
187 1.1.1.6 christos 0xffffffff, /* dst_mask */
188 1.1.1.6 christos FALSE), /* pcrel_offset */
189 1.1 christos #else
190 1.1 christos EMPTY_HOWTO (16), /* R_SH_IMM8 */
191 1.1 christos #endif
192 1.1 christos EMPTY_HOWTO (17), /* R_SH_IMM8BY2 */
193 1.1 christos EMPTY_HOWTO (18), /* R_SH_IMM8BY4 */
194 1.1 christos EMPTY_HOWTO (19), /* R_SH_IMM4 */
195 1.1 christos EMPTY_HOWTO (20), /* R_SH_IMM4BY2 */
196 1.1 christos EMPTY_HOWTO (21), /* R_SH_IMM4BY4 */
197 1.1 christos
198 1.1 christos HOWTO (R_SH_PCRELIMM8BY2, /* type */
199 1.1 christos 1, /* rightshift */
200 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
201 1.1 christos 8, /* bitsize */
202 1.1 christos TRUE, /* pc_relative */
203 1.1 christos 0, /* bitpos */
204 1.1 christos complain_overflow_unsigned, /* complain_on_overflow */
205 1.1 christos sh_reloc, /* special_function */
206 1.1 christos "r_pcrelimm8by2", /* name */
207 1.1 christos TRUE, /* partial_inplace */
208 1.1 christos 0xff, /* src_mask */
209 1.1 christos 0xff, /* dst_mask */
210 1.1 christos TRUE), /* pcrel_offset */
211 1.1 christos
212 1.1 christos HOWTO (R_SH_PCRELIMM8BY4, /* type */
213 1.1 christos 2, /* rightshift */
214 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
215 1.1 christos 8, /* bitsize */
216 1.1 christos TRUE, /* pc_relative */
217 1.1 christos 0, /* bitpos */
218 1.1 christos complain_overflow_unsigned, /* complain_on_overflow */
219 1.1 christos sh_reloc, /* special_function */
220 1.1 christos "r_pcrelimm8by4", /* name */
221 1.1 christos TRUE, /* partial_inplace */
222 1.1 christos 0xff, /* src_mask */
223 1.1 christos 0xff, /* dst_mask */
224 1.1 christos TRUE), /* pcrel_offset */
225 1.1 christos
226 1.1 christos HOWTO (R_SH_IMM16, /* type */
227 1.1 christos 0, /* rightshift */
228 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
229 1.1 christos 16, /* bitsize */
230 1.1 christos FALSE, /* pc_relative */
231 1.1 christos 0, /* bitpos */
232 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
233 1.1 christos sh_reloc, /* special_function */
234 1.1 christos "r_imm16", /* name */
235 1.1 christos TRUE, /* partial_inplace */
236 1.1 christos 0xffff, /* src_mask */
237 1.1 christos 0xffff, /* dst_mask */
238 1.1 christos FALSE), /* pcrel_offset */
239 1.1 christos
240 1.1 christos HOWTO (R_SH_SWITCH16, /* type */
241 1.1 christos 0, /* rightshift */
242 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
243 1.1 christos 16, /* bitsize */
244 1.1 christos FALSE, /* pc_relative */
245 1.1 christos 0, /* bitpos */
246 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
247 1.1 christos sh_reloc, /* special_function */
248 1.1 christos "r_switch16", /* name */
249 1.1 christos TRUE, /* partial_inplace */
250 1.1 christos 0xffff, /* src_mask */
251 1.1 christos 0xffff, /* dst_mask */
252 1.1 christos FALSE), /* pcrel_offset */
253 1.1 christos
254 1.1 christos HOWTO (R_SH_SWITCH32, /* type */
255 1.1 christos 0, /* rightshift */
256 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
257 1.1 christos 32, /* bitsize */
258 1.1 christos FALSE, /* pc_relative */
259 1.1 christos 0, /* bitpos */
260 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
261 1.1 christos sh_reloc, /* special_function */
262 1.1 christos "r_switch32", /* name */
263 1.1 christos TRUE, /* partial_inplace */
264 1.1 christos 0xffffffff, /* src_mask */
265 1.1 christos 0xffffffff, /* dst_mask */
266 1.1 christos FALSE), /* pcrel_offset */
267 1.1 christos
268 1.1 christos HOWTO (R_SH_USES, /* type */
269 1.1 christos 0, /* rightshift */
270 1.1 christos 1, /* size (0 = byte, 1 = short, 2 = long) */
271 1.1 christos 16, /* bitsize */
272 1.1 christos FALSE, /* pc_relative */
273 1.1 christos 0, /* bitpos */
274 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
275 1.1 christos sh_reloc, /* special_function */
276 1.1 christos "r_uses", /* name */
277 1.1 christos TRUE, /* partial_inplace */
278 1.1 christos 0xffff, /* src_mask */
279 1.1 christos 0xffff, /* dst_mask */
280 1.1 christos FALSE), /* pcrel_offset */
281 1.1 christos
282 1.1 christos HOWTO (R_SH_COUNT, /* type */
283 1.1 christos 0, /* rightshift */
284 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
285 1.1 christos 32, /* bitsize */
286 1.1 christos FALSE, /* pc_relative */
287 1.1 christos 0, /* bitpos */
288 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
289 1.1 christos sh_reloc, /* special_function */
290 1.1 christos "r_count", /* name */
291 1.1 christos TRUE, /* partial_inplace */
292 1.1 christos 0xffffffff, /* src_mask */
293 1.1 christos 0xffffffff, /* dst_mask */
294 1.1 christos FALSE), /* pcrel_offset */
295 1.1 christos
296 1.1 christos HOWTO (R_SH_ALIGN, /* type */
297 1.1 christos 0, /* rightshift */
298 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
299 1.1 christos 32, /* bitsize */
300 1.1 christos FALSE, /* pc_relative */
301 1.1 christos 0, /* bitpos */
302 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
303 1.1 christos sh_reloc, /* special_function */
304 1.1 christos "r_align", /* name */
305 1.1 christos TRUE, /* partial_inplace */
306 1.1 christos 0xffffffff, /* src_mask */
307 1.1 christos 0xffffffff, /* dst_mask */
308 1.1 christos FALSE), /* pcrel_offset */
309 1.1 christos
310 1.1 christos HOWTO (R_SH_CODE, /* type */
311 1.1 christos 0, /* rightshift */
312 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
313 1.1 christos 32, /* bitsize */
314 1.1 christos FALSE, /* pc_relative */
315 1.1 christos 0, /* bitpos */
316 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
317 1.1 christos sh_reloc, /* special_function */
318 1.1 christos "r_code", /* name */
319 1.1 christos TRUE, /* partial_inplace */
320 1.1 christos 0xffffffff, /* src_mask */
321 1.1 christos 0xffffffff, /* dst_mask */
322 1.1 christos FALSE), /* pcrel_offset */
323 1.1 christos
324 1.1 christos HOWTO (R_SH_DATA, /* type */
325 1.1 christos 0, /* rightshift */
326 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
327 1.1 christos 32, /* bitsize */
328 1.1 christos FALSE, /* pc_relative */
329 1.1 christos 0, /* bitpos */
330 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
331 1.1 christos sh_reloc, /* special_function */
332 1.1 christos "r_data", /* name */
333 1.1 christos TRUE, /* partial_inplace */
334 1.1 christos 0xffffffff, /* src_mask */
335 1.1 christos 0xffffffff, /* dst_mask */
336 1.1 christos FALSE), /* pcrel_offset */
337 1.1 christos
338 1.1 christos HOWTO (R_SH_LABEL, /* type */
339 1.1 christos 0, /* rightshift */
340 1.1 christos 2, /* size (0 = byte, 1 = short, 2 = long) */
341 1.1 christos 32, /* bitsize */
342 1.1 christos FALSE, /* pc_relative */
343 1.1 christos 0, /* bitpos */
344 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
345 1.1 christos sh_reloc, /* special_function */
346 1.1 christos "r_label", /* name */
347 1.1 christos TRUE, /* partial_inplace */
348 1.1 christos 0xffffffff, /* src_mask */
349 1.1 christos 0xffffffff, /* dst_mask */
350 1.1 christos FALSE), /* pcrel_offset */
351 1.1 christos
352 1.1 christos HOWTO (R_SH_SWITCH8, /* type */
353 1.1 christos 0, /* rightshift */
354 1.1 christos 0, /* size (0 = byte, 1 = short, 2 = long) */
355 1.1 christos 8, /* bitsize */
356 1.1 christos FALSE, /* pc_relative */
357 1.1 christos 0, /* bitpos */
358 1.1 christos complain_overflow_bitfield, /* complain_on_overflow */
359 1.1 christos sh_reloc, /* special_function */
360 1.1 christos "r_switch8", /* name */
361 1.1 christos TRUE, /* partial_inplace */
362 1.1 christos 0xff, /* src_mask */
363 1.1 christos 0xff, /* dst_mask */
364 1.1 christos FALSE) /* pcrel_offset */
365 1.1 christos };
366 1.1 christos
367 1.1 christos #define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])
368 1.1 christos
369 1.1 christos /* Check for a bad magic number. */
370 1.1 christos #define BADMAG(x) SHBADMAG(x)
371 1.1 christos
372 1.1 christos /* Customize coffcode.h (this is not currently used). */
373 1.1 christos #define SH 1
374 1.1 christos
375 1.1 christos /* FIXME: This should not be set here. */
376 1.1 christos #define __A_MAGIC_SET__
377 1.1 christos
378 1.1 christos #ifndef COFF_WITH_PE
379 1.1 christos /* Swap the r_offset field in and out. */
380 1.1 christos #define SWAP_IN_RELOC_OFFSET H_GET_32
381 1.1 christos #define SWAP_OUT_RELOC_OFFSET H_PUT_32
382 1.1 christos
383 1.1 christos /* Swap out extra information in the reloc structure. */
384 1.1 christos #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
385 1.1 christos do \
386 1.1 christos { \
387 1.1 christos dst->r_stuff[0] = 'S'; \
388 1.1 christos dst->r_stuff[1] = 'C'; \
389 1.1 christos } \
390 1.1 christos while (0)
391 1.1 christos #endif
392 1.1 christos
393 1.1 christos /* Get the value of a symbol, when performing a relocation. */
394 1.1 christos
395 1.1 christos static long
396 1.1.1.2 christos get_symbol_value (asymbol *symbol)
397 1.1 christos {
398 1.1 christos bfd_vma relocation;
399 1.1 christos
400 1.1 christos if (bfd_is_com_section (symbol->section))
401 1.1 christos relocation = 0;
402 1.1 christos else
403 1.1 christos relocation = (symbol->value +
404 1.1 christos symbol->section->output_section->vma +
405 1.1 christos symbol->section->output_offset);
406 1.1 christos
407 1.1 christos return relocation;
408 1.1 christos }
409 1.1 christos
410 1.1 christos #ifdef COFF_WITH_PE
411 1.1 christos /* Convert an rtype to howto for the COFF backend linker.
412 1.1 christos Copied from coff-i386. */
413 1.1 christos #define coff_rtype_to_howto coff_sh_rtype_to_howto
414 1.1.1.2 christos
415 1.1 christos
416 1.1 christos static reloc_howto_type *
417 1.1.1.2 christos coff_sh_rtype_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
418 1.1.1.2 christos asection * sec,
419 1.1.1.2 christos struct internal_reloc * rel,
420 1.1.1.2 christos struct coff_link_hash_entry * h,
421 1.1.1.2 christos struct internal_syment * sym,
422 1.1.1.2 christos bfd_vma * addendp)
423 1.1 christos {
424 1.1 christos reloc_howto_type * howto;
425 1.1 christos
426 1.1 christos howto = sh_coff_howtos + rel->r_type;
427 1.1 christos
428 1.1 christos *addendp = 0;
429 1.1 christos
430 1.1 christos if (howto->pc_relative)
431 1.1 christos *addendp += sec->vma;
432 1.1 christos
433 1.1 christos if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
434 1.1 christos {
435 1.1 christos /* This is a common symbol. The section contents include the
436 1.1 christos size (sym->n_value) as an addend. The relocate_section
437 1.1 christos function will be adding in the final value of the symbol. We
438 1.1 christos need to subtract out the current size in order to get the
439 1.1 christos correct result. */
440 1.1 christos BFD_ASSERT (h != NULL);
441 1.1 christos }
442 1.1 christos
443 1.1 christos if (howto->pc_relative)
444 1.1 christos {
445 1.1 christos *addendp -= 4;
446 1.1 christos
447 1.1 christos /* If the symbol is defined, then the generic code is going to
448 1.1.1.6 christos add back the symbol value in order to cancel out an
449 1.1.1.6 christos adjustment it made to the addend. However, we set the addend
450 1.1.1.6 christos to 0 at the start of this function. We need to adjust here,
451 1.1.1.6 christos to avoid the adjustment the generic code will make. FIXME:
452 1.1.1.6 christos This is getting a bit hackish. */
453 1.1 christos if (sym != NULL && sym->n_scnum != 0)
454 1.1 christos *addendp -= sym->n_value;
455 1.1 christos }
456 1.1 christos
457 1.1 christos if (rel->r_type == R_SH_IMAGEBASE)
458 1.1 christos *addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
459 1.1 christos
460 1.1 christos return howto;
461 1.1 christos }
462 1.1 christos
463 1.1 christos #endif /* COFF_WITH_PE */
464 1.1 christos
465 1.1 christos /* This structure is used to map BFD reloc codes to SH PE relocs. */
466 1.1 christos struct shcoff_reloc_map
467 1.1 christos {
468 1.1 christos bfd_reloc_code_real_type bfd_reloc_val;
469 1.1 christos unsigned char shcoff_reloc_val;
470 1.1 christos };
471 1.1 christos
472 1.1 christos #ifdef COFF_WITH_PE
473 1.1 christos /* An array mapping BFD reloc codes to SH PE relocs. */
474 1.1 christos static const struct shcoff_reloc_map sh_reloc_map[] =
475 1.1 christos {
476 1.1 christos { BFD_RELOC_32, R_SH_IMM32CE },
477 1.1 christos { BFD_RELOC_RVA, R_SH_IMAGEBASE },
478 1.1 christos { BFD_RELOC_CTOR, R_SH_IMM32CE },
479 1.1 christos };
480 1.1 christos #else
481 1.1 christos /* An array mapping BFD reloc codes to SH PE relocs. */
482 1.1 christos static const struct shcoff_reloc_map sh_reloc_map[] =
483 1.1 christos {
484 1.1 christos { BFD_RELOC_32, R_SH_IMM32 },
485 1.1 christos { BFD_RELOC_CTOR, R_SH_IMM32 },
486 1.1 christos };
487 1.1 christos #endif
488 1.1 christos
489 1.1 christos /* Given a BFD reloc code, return the howto structure for the
490 1.1 christos corresponding SH PE reloc. */
491 1.1 christos #define coff_bfd_reloc_type_lookup sh_coff_reloc_type_lookup
492 1.1 christos #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup
493 1.1 christos
494 1.1 christos static reloc_howto_type *
495 1.1.1.6 christos sh_coff_reloc_type_lookup (bfd *abfd,
496 1.1.1.2 christos bfd_reloc_code_real_type code)
497 1.1 christos {
498 1.1 christos unsigned int i;
499 1.1 christos
500 1.1 christos for (i = ARRAY_SIZE (sh_reloc_map); i--;)
501 1.1 christos if (sh_reloc_map[i].bfd_reloc_val == code)
502 1.1 christos return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val];
503 1.1 christos
504 1.1.1.6 christos _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
505 1.1.1.6 christos abfd, (unsigned int) code);
506 1.1 christos return NULL;
507 1.1 christos }
508 1.1 christos
509 1.1 christos static reloc_howto_type *
510 1.1 christos sh_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
511 1.1 christos const char *r_name)
512 1.1 christos {
513 1.1 christos unsigned int i;
514 1.1 christos
515 1.1 christos for (i = 0; i < sizeof (sh_coff_howtos) / sizeof (sh_coff_howtos[0]); i++)
516 1.1 christos if (sh_coff_howtos[i].name != NULL
517 1.1 christos && strcasecmp (sh_coff_howtos[i].name, r_name) == 0)
518 1.1 christos return &sh_coff_howtos[i];
519 1.1 christos
520 1.1 christos return NULL;
521 1.1 christos }
522 1.1 christos
523 1.1 christos /* This macro is used in coffcode.h to get the howto corresponding to
524 1.1 christos an internal reloc. */
525 1.1 christos
526 1.1 christos #define RTYPE2HOWTO(relent, internal) \
527 1.1 christos ((relent)->howto = \
528 1.1 christos ((internal)->r_type < SH_COFF_HOWTO_COUNT \
529 1.1 christos ? &sh_coff_howtos[(internal)->r_type] \
530 1.1 christos : (reloc_howto_type *) NULL))
531 1.1 christos
532 1.1 christos /* This is the same as the macro in coffcode.h, except that it copies
533 1.1 christos r_offset into reloc_entry->addend for some relocs. */
534 1.1.1.3 christos #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
535 1.1.1.3 christos { \
536 1.1.1.3 christos coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
537 1.1.1.3 christos if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
538 1.1.1.3 christos coffsym = (obj_symbols (abfd) \
539 1.1.1.3 christos + (cache_ptr->sym_ptr_ptr - symbols)); \
540 1.1.1.3 christos else if (ptr) \
541 1.1.1.3 christos coffsym = coff_symbol_from (ptr); \
542 1.1.1.3 christos if (coffsym != (coff_symbol_type *) NULL \
543 1.1.1.3 christos && coffsym->native->u.syment.n_scnum == 0) \
544 1.1.1.3 christos cache_ptr->addend = 0; \
545 1.1.1.3 christos else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
546 1.1.1.3 christos && ptr->section != (asection *) NULL) \
547 1.1.1.3 christos cache_ptr->addend = - (ptr->section->vma + ptr->value); \
548 1.1.1.3 christos else \
549 1.1.1.3 christos cache_ptr->addend = 0; \
550 1.1 christos if ((reloc).r_type == R_SH_SWITCH8 \
551 1.1 christos || (reloc).r_type == R_SH_SWITCH16 \
552 1.1 christos || (reloc).r_type == R_SH_SWITCH32 \
553 1.1 christos || (reloc).r_type == R_SH_USES \
554 1.1 christos || (reloc).r_type == R_SH_COUNT \
555 1.1 christos || (reloc).r_type == R_SH_ALIGN) \
556 1.1 christos cache_ptr->addend = (reloc).r_offset; \
557 1.1 christos }
558 1.1 christos
559 1.1 christos /* This is the howto function for the SH relocations. */
560 1.1 christos
561 1.1 christos static bfd_reloc_status_type
562 1.1.1.2 christos sh_reloc (bfd * abfd,
563 1.1.1.2 christos arelent * reloc_entry,
564 1.1.1.2 christos asymbol * symbol_in,
565 1.1.1.2 christos void * data,
566 1.1.1.2 christos asection * input_section,
567 1.1.1.2 christos bfd * output_bfd,
568 1.1.1.2 christos char ** error_message ATTRIBUTE_UNUSED)
569 1.1 christos {
570 1.1.1.7 christos bfd_vma insn;
571 1.1 christos bfd_vma sym_value;
572 1.1 christos unsigned short r_type;
573 1.1 christos bfd_vma addr = reloc_entry->address;
574 1.1 christos bfd_byte *hit_data = addr + (bfd_byte *) data;
575 1.1 christos
576 1.1 christos r_type = reloc_entry->howto->type;
577 1.1 christos
578 1.1 christos if (output_bfd != NULL)
579 1.1 christos {
580 1.1 christos /* Partial linking--do nothing. */
581 1.1 christos reloc_entry->address += input_section->output_offset;
582 1.1 christos return bfd_reloc_ok;
583 1.1 christos }
584 1.1 christos
585 1.1 christos /* Almost all relocs have to do with relaxing. If any work must be
586 1.1 christos done for them, it has been done in sh_relax_section. */
587 1.1 christos if (r_type != R_SH_IMM32
588 1.1 christos #ifdef COFF_WITH_PE
589 1.1 christos && r_type != R_SH_IMM32CE
590 1.1 christos && r_type != R_SH_IMAGEBASE
591 1.1 christos #endif
592 1.1 christos && (r_type != R_SH_PCDISP
593 1.1 christos || (symbol_in->flags & BSF_LOCAL) != 0))
594 1.1 christos return bfd_reloc_ok;
595 1.1 christos
596 1.1 christos if (symbol_in != NULL
597 1.1 christos && bfd_is_und_section (symbol_in->section))
598 1.1 christos return bfd_reloc_undefined;
599 1.1 christos
600 1.1.1.6 christos if (addr > input_section->size)
601 1.1.1.6 christos return bfd_reloc_outofrange;
602 1.1.1.6 christos
603 1.1 christos sym_value = get_symbol_value (symbol_in);
604 1.1 christos
605 1.1 christos switch (r_type)
606 1.1 christos {
607 1.1 christos case R_SH_IMM32:
608 1.1 christos #ifdef COFF_WITH_PE
609 1.1 christos case R_SH_IMM32CE:
610 1.1 christos #endif
611 1.1 christos insn = bfd_get_32 (abfd, hit_data);
612 1.1 christos insn += sym_value + reloc_entry->addend;
613 1.1.1.7 christos bfd_put_32 (abfd, insn, hit_data);
614 1.1 christos break;
615 1.1 christos #ifdef COFF_WITH_PE
616 1.1 christos case R_SH_IMAGEBASE:
617 1.1 christos insn = bfd_get_32 (abfd, hit_data);
618 1.1 christos insn += sym_value + reloc_entry->addend;
619 1.1 christos insn -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase;
620 1.1.1.7 christos bfd_put_32 (abfd, insn, hit_data);
621 1.1 christos break;
622 1.1 christos #endif
623 1.1 christos case R_SH_PCDISP:
624 1.1 christos insn = bfd_get_16 (abfd, hit_data);
625 1.1 christos sym_value += reloc_entry->addend;
626 1.1 christos sym_value -= (input_section->output_section->vma
627 1.1 christos + input_section->output_offset
628 1.1 christos + addr
629 1.1 christos + 4);
630 1.1.1.7 christos sym_value += (((insn & 0xfff) ^ 0x800) - 0x800) << 1;
631 1.1.1.7 christos insn = (insn & 0xf000) | ((sym_value >> 1) & 0xfff);
632 1.1.1.7 christos bfd_put_16 (abfd, insn, hit_data);
633 1.1.1.7 christos if (sym_value + 0x1000 >= 0x2000 || (sym_value & 1) != 0)
634 1.1 christos return bfd_reloc_overflow;
635 1.1 christos break;
636 1.1 christos default:
637 1.1 christos abort ();
638 1.1 christos break;
639 1.1 christos }
640 1.1 christos
641 1.1 christos return bfd_reloc_ok;
642 1.1 christos }
643 1.1 christos
644 1.1 christos #define coff_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
645 1.1 christos
646 1.1 christos /* We can do relaxing. */
647 1.1 christos #define coff_bfd_relax_section sh_relax_section
648 1.1 christos
649 1.1 christos /* We use the special COFF backend linker. */
650 1.1 christos #define coff_relocate_section sh_relocate_section
651 1.1 christos
652 1.1 christos /* When relaxing, we need to use special code to get the relocated
653 1.1 christos section contents. */
654 1.1 christos #define coff_bfd_get_relocated_section_contents \
655 1.1 christos sh_coff_get_relocated_section_contents
656 1.1 christos
657 1.1 christos #include "coffcode.h"
658 1.1 christos
659 1.1.1.2 christos static bfd_boolean
661 1.1.1.2 christos sh_relax_delete_bytes (bfd *, asection *, bfd_vma, int);
662 1.1 christos
663 1.1 christos /* This function handles relaxing on the SH.
664 1.1 christos
665 1.1 christos Function calls on the SH look like this:
666 1.1 christos
667 1.1 christos movl L1,r0
668 1.1 christos ...
669 1.1 christos jsr @r0
670 1.1 christos ...
671 1.1 christos L1:
672 1.1 christos .long function
673 1.1 christos
674 1.1 christos The compiler and assembler will cooperate to create R_SH_USES
675 1.1 christos relocs on the jsr instructions. The r_offset field of the
676 1.1 christos R_SH_USES reloc is the PC relative offset to the instruction which
677 1.1 christos loads the register (the r_offset field is computed as though it
678 1.1 christos were a jump instruction, so the offset value is actually from four
679 1.1 christos bytes past the instruction). The linker can use this reloc to
680 1.1 christos determine just which function is being called, and thus decide
681 1.1 christos whether it is possible to replace the jsr with a bsr.
682 1.1 christos
683 1.1 christos If multiple function calls are all based on a single register load
684 1.1 christos (i.e., the same function is called multiple times), the compiler
685 1.1 christos guarantees that each function call will have an R_SH_USES reloc.
686 1.1 christos Therefore, if the linker is able to convert each R_SH_USES reloc
687 1.1 christos which refers to that address, it can safely eliminate the register
688 1.1 christos load.
689 1.1 christos
690 1.1 christos When the assembler creates an R_SH_USES reloc, it examines it to
691 1.1 christos determine which address is being loaded (L1 in the above example).
692 1.1 christos It then counts the number of references to that address, and
693 1.1 christos creates an R_SH_COUNT reloc at that address. The r_offset field of
694 1.1 christos the R_SH_COUNT reloc will be the number of references. If the
695 1.1 christos linker is able to eliminate a register load, it can use the
696 1.1 christos R_SH_COUNT reloc to see whether it can also eliminate the function
697 1.1 christos address.
698 1.1 christos
699 1.1 christos SH relaxing also handles another, unrelated, matter. On the SH, if
700 1.1 christos a load or store instruction is not aligned on a four byte boundary,
701 1.1 christos the memory cycle interferes with the 32 bit instruction fetch,
702 1.1 christos causing a one cycle bubble in the pipeline. Therefore, we try to
703 1.1 christos align load and store instructions on four byte boundaries if we
704 1.1 christos can, by swapping them with one of the adjacent instructions. */
705 1.1 christos
706 1.1.1.2 christos static bfd_boolean
707 1.1.1.2 christos sh_relax_section (bfd *abfd,
708 1.1.1.2 christos asection *sec,
709 1.1.1.2 christos struct bfd_link_info *link_info,
710 1.1 christos bfd_boolean *again)
711 1.1 christos {
712 1.1 christos struct internal_reloc *internal_relocs;
713 1.1 christos bfd_boolean have_code;
714 1.1 christos struct internal_reloc *irel, *irelend;
715 1.1 christos bfd_byte *contents = NULL;
716 1.1 christos
717 1.1 christos *again = FALSE;
718 1.1.1.4 christos
719 1.1 christos if (bfd_link_relocatable (link_info)
720 1.1 christos || (sec->flags & SEC_RELOC) == 0
721 1.1 christos || sec->reloc_count == 0)
722 1.1 christos return TRUE;
723 1.1 christos
724 1.1 christos if (coff_section_data (abfd, sec) == NULL)
725 1.1.1.7 christos {
726 1.1.1.2 christos size_t amt = sizeof (struct coff_section_tdata);
727 1.1 christos sec->used_by_bfd = bfd_zalloc (abfd, amt);
728 1.1 christos if (sec->used_by_bfd == NULL)
729 1.1 christos return FALSE;
730 1.1 christos }
731 1.1 christos
732 1.1 christos internal_relocs = (_bfd_coff_read_internal_relocs
733 1.1 christos (abfd, sec, link_info->keep_memory,
734 1.1 christos (bfd_byte *) NULL, FALSE,
735 1.1 christos (struct internal_reloc *) NULL));
736 1.1 christos if (internal_relocs == NULL)
737 1.1 christos goto error_return;
738 1.1 christos
739 1.1 christos have_code = FALSE;
740 1.1 christos
741 1.1 christos irelend = internal_relocs + sec->reloc_count;
742 1.1 christos for (irel = internal_relocs; irel < irelend; irel++)
743 1.1 christos {
744 1.1 christos bfd_vma laddr, paddr, symval;
745 1.1 christos unsigned short insn;
746 1.1 christos struct internal_reloc *irelfn, *irelscan, *irelcount;
747 1.1 christos struct internal_syment sym;
748 1.1 christos bfd_signed_vma foff;
749 1.1 christos
750 1.1 christos if (irel->r_type == R_SH_CODE)
751 1.1 christos have_code = TRUE;
752 1.1 christos
753 1.1 christos if (irel->r_type != R_SH_USES)
754 1.1 christos continue;
755 1.1 christos
756 1.1 christos /* Get the section contents. */
757 1.1 christos if (contents == NULL)
758 1.1 christos {
759 1.1 christos if (coff_section_data (abfd, sec)->contents != NULL)
760 1.1 christos contents = coff_section_data (abfd, sec)->contents;
761 1.1 christos else
762 1.1 christos {
763 1.1 christos if (!bfd_malloc_and_get_section (abfd, sec, &contents))
764 1.1 christos goto error_return;
765 1.1 christos }
766 1.1 christos }
767 1.1 christos
768 1.1.1.6 christos /* The r_offset field of the R_SH_USES reloc will point us to
769 1.1.1.6 christos the register load. The 4 is because the r_offset field is
770 1.1.1.6 christos computed as though it were a jump offset, which are based
771 1.1 christos from 4 bytes after the jump instruction. */
772 1.1 christos laddr = irel->r_vaddr - sec->vma + 4;
773 1.1 christos /* Careful to sign extend the 32-bit offset. */
774 1.1 christos laddr += ((irel->r_offset & 0xffffffff) ^ 0x80000000) - 0x80000000;
775 1.1 christos if (laddr >= sec->size)
776 1.1.1.5 christos {
777 1.1.1.6 christos /* xgettext: c-format */
778 1.1.1.6 christos _bfd_error_handler
779 1.1.1.6 christos (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES offset"),
780 1.1 christos abfd, (uint64_t) irel->r_vaddr);
781 1.1 christos continue;
782 1.1 christos }
783 1.1 christos insn = bfd_get_16 (abfd, contents + laddr);
784 1.1 christos
785 1.1 christos /* If the instruction is not mov.l NN,rN, we don't know what to do. */
786 1.1 christos if ((insn & 0xf000) != 0xd000)
787 1.1.1.5 christos {
788 1.1.1.5 christos _bfd_error_handler
789 1.1.1.6 christos /* xgettext: c-format */
790 1.1.1.6 christos (_("%pB: %#" PRIx64 ": warning: R_SH_USES points to unrecognized insn %#x"),
791 1.1 christos abfd, (uint64_t) irel->r_vaddr, insn);
792 1.1 christos continue;
793 1.1 christos }
794 1.1 christos
795 1.1.1.6 christos /* Get the address from which the register is being loaded. The
796 1.1.1.6 christos displacement in the mov.l instruction is quadrupled. It is a
797 1.1.1.6 christos displacement from four bytes after the movl instruction, but,
798 1.1.1.6 christos before adding in the PC address, two least significant bits
799 1.1.1.6 christos of the PC are cleared. We assume that the section is aligned
800 1.1 christos on a four byte boundary. */
801 1.1 christos paddr = insn & 0xff;
802 1.1 christos paddr *= 4;
803 1.1 christos paddr += (laddr + 4) &~ (bfd_vma) 3;
804 1.1 christos if (paddr >= sec->size)
805 1.1.1.5 christos {
806 1.1.1.5 christos _bfd_error_handler
807 1.1.1.6 christos /* xgettext: c-format */
808 1.1.1.6 christos (_("%pB: %#" PRIx64 ": warning: bad R_SH_USES load offset"),
809 1.1 christos abfd, (uint64_t) irel->r_vaddr);
810 1.1 christos continue;
811 1.1 christos }
812 1.1 christos
813 1.1.1.6 christos /* Get the reloc for the address from which the register is
814 1.1.1.6 christos being loaded. This reloc will tell us which function is
815 1.1 christos actually being called. */
816 1.1 christos paddr += sec->vma;
817 1.1 christos for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
818 1.1 christos if (irelfn->r_vaddr == paddr
819 1.1 christos #ifdef COFF_WITH_PE
820 1.1 christos && (irelfn->r_type == R_SH_IMM32
821 1.1 christos || irelfn->r_type == R_SH_IMM32CE
822 1.1 christos || irelfn->r_type == R_SH_IMAGEBASE)
823 1.1 christos
824 1.1 christos #else
825 1.1 christos && irelfn->r_type == R_SH_IMM32
826 1.1 christos #endif
827 1.1 christos )
828 1.1 christos break;
829 1.1 christos if (irelfn >= irelend)
830 1.1.1.5 christos {
831 1.1.1.5 christos _bfd_error_handler
832 1.1.1.6 christos /* xgettext: c-format */
833 1.1.1.6 christos (_("%pB: %#" PRIx64 ": warning: could not find expected reloc"),
834 1.1 christos abfd, (uint64_t) paddr);
835 1.1 christos continue;
836 1.1 christos }
837 1.1 christos
838 1.1 christos /* Get the value of the symbol referred to by the reloc. */
839 1.1 christos if (! _bfd_coff_get_external_symbols (abfd))
840 1.1 christos goto error_return;
841 1.1 christos bfd_coff_swap_sym_in (abfd,
842 1.1 christos ((bfd_byte *) obj_coff_external_syms (abfd)
843 1.1 christos + (irelfn->r_symndx
844 1.1 christos * bfd_coff_symesz (abfd))),
845 1.1 christos &sym);
846 1.1 christos if (sym.n_scnum != 0 && sym.n_scnum != sec->target_index)
847 1.1.1.5 christos {
848 1.1.1.5 christos _bfd_error_handler
849 1.1.1.6 christos /* xgettext: c-format */
850 1.1.1.6 christos (_("%pB: %#" PRIx64 ": warning: symbol in unexpected section"),
851 1.1 christos abfd, (uint64_t) paddr);
852 1.1 christos continue;
853 1.1 christos }
854 1.1 christos
855 1.1 christos if (sym.n_sclass != C_EXT)
856 1.1 christos {
857 1.1 christos symval = (sym.n_value
858 1.1 christos - sec->vma
859 1.1 christos + sec->output_section->vma
860 1.1 christos + sec->output_offset);
861 1.1 christos }
862 1.1 christos else
863 1.1 christos {
864 1.1 christos struct coff_link_hash_entry *h;
865 1.1 christos
866 1.1 christos h = obj_coff_sym_hashes (abfd)[irelfn->r_symndx];
867 1.1 christos BFD_ASSERT (h != NULL);
868 1.1 christos if (h->root.type != bfd_link_hash_defined
869 1.1 christos && h->root.type != bfd_link_hash_defweak)
870 1.1 christos {
871 1.1.1.6 christos /* This appears to be a reference to an undefined
872 1.1.1.6 christos symbol. Just ignore it--it will be caught by the
873 1.1 christos regular reloc processing. */
874 1.1 christos continue;
875 1.1 christos }
876 1.1 christos
877 1.1 christos symval = (h->root.u.def.value
878 1.1 christos + h->root.u.def.section->output_section->vma
879 1.1 christos + h->root.u.def.section->output_offset);
880 1.1 christos }
881 1.1 christos
882 1.1 christos symval += bfd_get_32 (abfd, contents + paddr - sec->vma);
883 1.1 christos
884 1.1 christos /* See if this function call can be shortened. */
885 1.1 christos foff = (symval
886 1.1 christos - (irel->r_vaddr
887 1.1 christos - sec->vma
888 1.1 christos + sec->output_section->vma
889 1.1 christos + sec->output_offset
890 1.1 christos + 4));
891 1.1 christos if (foff < -0x1000 || foff >= 0x1000)
892 1.1 christos {
893 1.1 christos /* After all that work, we can't shorten this function call. */
894 1.1 christos continue;
895 1.1 christos }
896 1.1 christos
897 1.1 christos /* Shorten the function call. */
898 1.1 christos
899 1.1 christos /* For simplicity of coding, we are going to modify the section
900 1.1 christos contents, the section relocs, and the BFD symbol table. We
901 1.1 christos must tell the rest of the code not to free up this
902 1.1 christos information. It would be possible to instead create a table
903 1.1 christos of changes which have to be made, as is done in coff-mips.c;
904 1.1 christos that would be more work, but would require less memory when
905 1.1 christos the linker is run. */
906 1.1 christos
907 1.1 christos coff_section_data (abfd, sec)->relocs = internal_relocs;
908 1.1 christos coff_section_data (abfd, sec)->keep_relocs = TRUE;
909 1.1 christos
910 1.1 christos coff_section_data (abfd, sec)->contents = contents;
911 1.1 christos coff_section_data (abfd, sec)->keep_contents = TRUE;
912 1.1 christos
913 1.1 christos obj_coff_keep_syms (abfd) = TRUE;
914 1.1 christos
915 1.1 christos /* Replace the jsr with a bsr. */
916 1.1 christos
917 1.1.1.6 christos /* Change the R_SH_USES reloc into an R_SH_PCDISP reloc, and
918 1.1 christos replace the jsr with a bsr. */
919 1.1 christos irel->r_type = R_SH_PCDISP;
920 1.1 christos irel->r_symndx = irelfn->r_symndx;
921 1.1 christos if (sym.n_sclass != C_EXT)
922 1.1 christos {
923 1.1.1.6 christos /* If this needs to be changed because of future relaxing,
924 1.1.1.6 christos it will be handled here like other internal PCDISP
925 1.1 christos relocs. */
926 1.1 christos bfd_put_16 (abfd,
927 1.1 christos (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
928 1.1 christos contents + irel->r_vaddr - sec->vma);
929 1.1 christos }
930 1.1 christos else
931 1.1 christos {
932 1.1.1.6 christos /* We can't fully resolve this yet, because the external
933 1.1.1.6 christos symbol value may be changed by future relaxing. We let
934 1.1 christos the final link phase handle it. */
935 1.1 christos bfd_put_16 (abfd, (bfd_vma) 0xb000,
936 1.1 christos contents + irel->r_vaddr - sec->vma);
937 1.1 christos }
938 1.1 christos
939 1.1.1.6 christos /* See if there is another R_SH_USES reloc referring to the same
940 1.1 christos register load. */
941 1.1 christos for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
942 1.1 christos if (irelscan->r_type == R_SH_USES
943 1.1 christos && laddr == irelscan->r_vaddr - sec->vma + 4 + irelscan->r_offset)
944 1.1 christos break;
945 1.1 christos if (irelscan < irelend)
946 1.1 christos {
947 1.1 christos /* Some other function call depends upon this register load,
948 1.1 christos and we have not yet converted that function call.
949 1.1 christos Indeed, we may never be able to convert it. There is
950 1.1 christos nothing else we can do at this point. */
951 1.1 christos continue;
952 1.1 christos }
953 1.1 christos
954 1.1.1.6 christos /* Look for a R_SH_COUNT reloc on the location where the
955 1.1.1.6 christos function address is stored. Do this before deleting any
956 1.1 christos bytes, to avoid confusion about the address. */
957 1.1 christos for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
958 1.1 christos if (irelcount->r_vaddr == paddr
959 1.1 christos && irelcount->r_type == R_SH_COUNT)
960 1.1 christos break;
961 1.1 christos
962 1.1 christos /* Delete the register load. */
963 1.1 christos if (! sh_relax_delete_bytes (abfd, sec, laddr, 2))
964 1.1 christos goto error_return;
965 1.1 christos
966 1.1.1.6 christos /* That will change things, so, just in case it permits some
967 1.1.1.6 christos other function call to come within range, we should relax
968 1.1 christos again. Note that this is not required, and it may be slow. */
969 1.1 christos *again = TRUE;
970 1.1 christos
971 1.1 christos /* Now check whether we got a COUNT reloc. */
972 1.1 christos if (irelcount >= irelend)
973 1.1.1.5 christos {
974 1.1.1.5 christos _bfd_error_handler
975 1.1.1.6 christos /* xgettext: c-format */
976 1.1.1.6 christos (_("%pB: %#" PRIx64 ": warning: could not find expected COUNT reloc"),
977 1.1 christos abfd, (uint64_t) paddr);
978 1.1 christos continue;
979 1.1 christos }
980 1.1 christos
981 1.1.1.6 christos /* The number of uses is stored in the r_offset field. We've
982 1.1 christos just deleted one. */
983 1.1 christos if (irelcount->r_offset == 0)
984 1.1.1.5 christos {
985 1.1.1.6 christos /* xgettext: c-format */
986 1.1.1.6 christos _bfd_error_handler (_("%pB: %#" PRIx64 ": warning: bad count"),
987 1.1 christos abfd, (uint64_t) paddr);
988 1.1 christos continue;
989 1.1 christos }
990 1.1 christos
991 1.1 christos --irelcount->r_offset;
992 1.1 christos
993 1.1.1.6 christos /* If there are no more uses, we can delete the address. Reload
994 1.1.1.6 christos the address from irelfn, in case it was changed by the
995 1.1 christos previous call to sh_relax_delete_bytes. */
996 1.1 christos if (irelcount->r_offset == 0)
997 1.1 christos {
998 1.1 christos if (! sh_relax_delete_bytes (abfd, sec,
999 1.1 christos irelfn->r_vaddr - sec->vma, 4))
1000 1.1 christos goto error_return;
1001 1.1 christos }
1002 1.1 christos
1003 1.1 christos /* We've done all we can with that function call. */
1004 1.1 christos }
1005 1.1 christos
1006 1.1 christos /* Look for load and store instructions that we can align on four
1007 1.1 christos byte boundaries. */
1008 1.1 christos if (have_code)
1009 1.1 christos {
1010 1.1 christos bfd_boolean swapped;
1011 1.1 christos
1012 1.1 christos /* Get the section contents. */
1013 1.1 christos if (contents == NULL)
1014 1.1 christos {
1015 1.1 christos if (coff_section_data (abfd, sec)->contents != NULL)
1016 1.1 christos contents = coff_section_data (abfd, sec)->contents;
1017 1.1 christos else
1018 1.1 christos {
1019 1.1 christos if (!bfd_malloc_and_get_section (abfd, sec, &contents))
1020 1.1 christos goto error_return;
1021 1.1 christos }
1022 1.1 christos }
1023 1.1 christos
1024 1.1 christos if (! sh_align_loads (abfd, sec, internal_relocs, contents, &swapped))
1025 1.1 christos goto error_return;
1026 1.1 christos
1027 1.1 christos if (swapped)
1028 1.1 christos {
1029 1.1 christos coff_section_data (abfd, sec)->relocs = internal_relocs;
1030 1.1 christos coff_section_data (abfd, sec)->keep_relocs = TRUE;
1031 1.1 christos
1032 1.1 christos coff_section_data (abfd, sec)->contents = contents;
1033 1.1 christos coff_section_data (abfd, sec)->keep_contents = TRUE;
1034 1.1 christos
1035 1.1 christos obj_coff_keep_syms (abfd) = TRUE;
1036 1.1 christos }
1037 1.1 christos }
1038 1.1 christos
1039 1.1 christos if (internal_relocs != NULL
1040 1.1 christos && internal_relocs != coff_section_data (abfd, sec)->relocs)
1041 1.1 christos {
1042 1.1 christos if (! link_info->keep_memory)
1043 1.1 christos free (internal_relocs);
1044 1.1 christos else
1045 1.1 christos coff_section_data (abfd, sec)->relocs = internal_relocs;
1046 1.1 christos }
1047 1.1 christos
1048 1.1 christos if (contents != NULL && contents != coff_section_data (abfd, sec)->contents)
1049 1.1 christos {
1050 1.1 christos if (! link_info->keep_memory)
1051 1.1 christos free (contents);
1052 1.1 christos else
1053 1.1 christos /* Cache the section contents for coff_link_input_bfd. */
1054 1.1 christos coff_section_data (abfd, sec)->contents = contents;
1055 1.1 christos }
1056 1.1 christos
1057 1.1 christos return TRUE;
1058 1.1 christos
1059 1.1.1.7 christos error_return:
1060 1.1 christos if (internal_relocs != coff_section_data (abfd, sec)->relocs)
1061 1.1.1.7 christos free (internal_relocs);
1062 1.1 christos if (contents != coff_section_data (abfd, sec)->contents)
1063 1.1 christos free (contents);
1064 1.1 christos return FALSE;
1065 1.1 christos }
1066 1.1 christos
1067 1.1 christos /* Delete some bytes from a section while relaxing. */
1068 1.1 christos
1069 1.1.1.2 christos static bfd_boolean
1070 1.1.1.2 christos sh_relax_delete_bytes (bfd *abfd,
1071 1.1.1.2 christos asection *sec,
1072 1.1.1.2 christos bfd_vma addr,
1073 1.1 christos int count)
1074 1.1 christos {
1075 1.1 christos bfd_byte *contents;
1076 1.1 christos struct internal_reloc *irel, *irelend;
1077 1.1 christos struct internal_reloc *irelalign;
1078 1.1 christos bfd_vma toaddr;
1079 1.1 christos bfd_byte *esym, *esymend;
1080 1.1 christos bfd_size_type symesz;
1081 1.1 christos struct coff_link_hash_entry **sym_hash;
1082 1.1 christos asection *o;
1083 1.1 christos
1084 1.1 christos contents = coff_section_data (abfd, sec)->contents;
1085 1.1.1.6 christos
1086 1.1 christos /* The deletion must stop at the next ALIGN reloc for an alignment
1087 1.1 christos power larger than the number of bytes we are deleting. */
1088 1.1 christos
1089 1.1 christos irelalign = NULL;
1090 1.1 christos toaddr = sec->size;
1091 1.1 christos
1092 1.1 christos irel = coff_section_data (abfd, sec)->relocs;
1093 1.1 christos irelend = irel + sec->reloc_count;
1094 1.1 christos for (; irel < irelend; irel++)
1095 1.1 christos {
1096 1.1 christos if (irel->r_type == R_SH_ALIGN
1097 1.1 christos && irel->r_vaddr - sec->vma > addr
1098 1.1 christos && count < (1 << irel->r_offset))
1099 1.1 christos {
1100 1.1 christos irelalign = irel;
1101 1.1 christos toaddr = irel->r_vaddr - sec->vma;
1102 1.1 christos break;
1103 1.1 christos }
1104 1.1 christos }
1105 1.1 christos
1106 1.1 christos /* Actually delete the bytes. */
1107 1.1 christos memmove (contents + addr, contents + addr + count,
1108 1.1 christos (size_t) (toaddr - addr - count));
1109 1.1 christos if (irelalign == NULL)
1110 1.1 christos sec->size -= count;
1111 1.1 christos else
1112 1.1 christos {
1113 1.1 christos int i;
1114 1.1 christos
1115 1.1 christos #define NOP_OPCODE (0x0009)
1116 1.1 christos
1117 1.1 christos BFD_ASSERT ((count & 1) == 0);
1118 1.1 christos for (i = 0; i < count; i += 2)
1119 1.1 christos bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
1120 1.1 christos }
1121 1.1 christos
1122 1.1 christos /* Adjust all the relocs. */
1123 1.1 christos for (irel = coff_section_data (abfd, sec)->relocs; irel < irelend; irel++)
1124 1.1 christos {
1125 1.1 christos bfd_vma nraddr, stop;
1126 1.1 christos bfd_vma start = 0;
1127 1.1 christos int insn = 0;
1128 1.1 christos struct internal_syment sym;
1129 1.1 christos int off, adjust, oinsn;
1130 1.1 christos bfd_signed_vma voff = 0;
1131 1.1 christos bfd_boolean overflow;
1132 1.1 christos
1133 1.1 christos /* Get the new reloc address. */
1134 1.1 christos nraddr = irel->r_vaddr - sec->vma;
1135 1.1 christos if ((irel->r_vaddr - sec->vma > addr
1136 1.1 christos && irel->r_vaddr - sec->vma < toaddr)
1137 1.1 christos || (irel->r_type == R_SH_ALIGN
1138 1.1 christos && irel->r_vaddr - sec->vma == toaddr))
1139 1.1 christos nraddr -= count;
1140 1.1 christos
1141 1.1 christos /* See if this reloc was for the bytes we have deleted, in which
1142 1.1 christos case we no longer care about it. Don't delete relocs which
1143 1.1 christos represent addresses, though. */
1144 1.1 christos if (irel->r_vaddr - sec->vma >= addr
1145 1.1 christos && irel->r_vaddr - sec->vma < addr + count
1146 1.1 christos && irel->r_type != R_SH_ALIGN
1147 1.1 christos && irel->r_type != R_SH_CODE
1148 1.1 christos && irel->r_type != R_SH_DATA
1149 1.1 christos && irel->r_type != R_SH_LABEL)
1150 1.1 christos irel->r_type = R_SH_UNUSED;
1151 1.1 christos
1152 1.1.1.6 christos /* If this is a PC relative reloc, see if the range it covers
1153 1.1 christos includes the bytes we have deleted. */
1154 1.1 christos switch (irel->r_type)
1155 1.1 christos {
1156 1.1 christos default:
1157 1.1 christos break;
1158 1.1 christos
1159 1.1 christos case R_SH_PCDISP8BY2:
1160 1.1 christos case R_SH_PCDISP:
1161 1.1 christos case R_SH_PCRELIMM8BY2:
1162 1.1 christos case R_SH_PCRELIMM8BY4:
1163 1.1 christos start = irel->r_vaddr - sec->vma;
1164 1.1 christos insn = bfd_get_16 (abfd, contents + nraddr);
1165 1.1 christos break;
1166 1.1 christos }
1167 1.1 christos
1168 1.1 christos switch (irel->r_type)
1169 1.1 christos {
1170 1.1 christos default:
1171 1.1 christos start = stop = addr;
1172 1.1 christos break;
1173 1.1 christos
1174 1.1 christos case R_SH_IMM32:
1175 1.1 christos #ifdef COFF_WITH_PE
1176 1.1 christos case R_SH_IMM32CE:
1177 1.1 christos case R_SH_IMAGEBASE:
1178 1.1 christos #endif
1179 1.1.1.6 christos /* If this reloc is against a symbol defined in this
1180 1.1.1.6 christos section, and the symbol will not be adjusted below, we
1181 1.1.1.6 christos must check the addend to see it will put the value in
1182 1.1 christos range to be adjusted, and hence must be changed. */
1183 1.1 christos bfd_coff_swap_sym_in (abfd,
1184 1.1 christos ((bfd_byte *) obj_coff_external_syms (abfd)
1185 1.1 christos + (irel->r_symndx
1186 1.1 christos * bfd_coff_symesz (abfd))),
1187 1.1 christos &sym);
1188 1.1 christos if (sym.n_sclass != C_EXT
1189 1.1 christos && sym.n_scnum == sec->target_index
1190 1.1 christos && ((bfd_vma) sym.n_value <= addr
1191 1.1 christos || (bfd_vma) sym.n_value >= toaddr))
1192 1.1 christos {
1193 1.1 christos bfd_vma val;
1194 1.1 christos
1195 1.1 christos val = bfd_get_32 (abfd, contents + nraddr);
1196 1.1 christos val += sym.n_value;
1197 1.1 christos if (val > addr && val < toaddr)
1198 1.1 christos bfd_put_32 (abfd, val - count, contents + nraddr);
1199 1.1 christos }
1200 1.1 christos start = stop = addr;
1201 1.1 christos break;
1202 1.1 christos
1203 1.1 christos case R_SH_PCDISP8BY2:
1204 1.1 christos off = insn & 0xff;
1205 1.1 christos if (off & 0x80)
1206 1.1 christos off -= 0x100;
1207 1.1 christos stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1208 1.1 christos break;
1209 1.1 christos
1210 1.1 christos case R_SH_PCDISP:
1211 1.1 christos bfd_coff_swap_sym_in (abfd,
1212 1.1 christos ((bfd_byte *) obj_coff_external_syms (abfd)
1213 1.1 christos + (irel->r_symndx
1214 1.1 christos * bfd_coff_symesz (abfd))),
1215 1.1 christos &sym);
1216 1.1 christos if (sym.n_sclass == C_EXT)
1217 1.1 christos start = stop = addr;
1218 1.1 christos else
1219 1.1 christos {
1220 1.1 christos off = insn & 0xfff;
1221 1.1 christos if (off & 0x800)
1222 1.1 christos off -= 0x1000;
1223 1.1 christos stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
1224 1.1 christos }
1225 1.1 christos break;
1226 1.1 christos
1227 1.1 christos case R_SH_PCRELIMM8BY2:
1228 1.1 christos off = insn & 0xff;
1229 1.1 christos stop = start + 4 + off * 2;
1230 1.1 christos break;
1231 1.1 christos
1232 1.1 christos case R_SH_PCRELIMM8BY4:
1233 1.1 christos off = insn & 0xff;
1234 1.1 christos stop = (start &~ (bfd_vma) 3) + 4 + off * 4;
1235 1.1 christos break;
1236 1.1 christos
1237 1.1 christos case R_SH_SWITCH8:
1238 1.1 christos case R_SH_SWITCH16:
1239 1.1 christos case R_SH_SWITCH32:
1240 1.1 christos /* These relocs types represent
1241 1.1 christos .word L2-L1
1242 1.1 christos The r_offset field holds the difference between the reloc
1243 1.1 christos address and L1. That is the start of the reloc, and
1244 1.1 christos adding in the contents gives us the top. We must adjust
1245 1.1 christos both the r_offset field and the section contents. */
1246 1.1 christos
1247 1.1 christos start = irel->r_vaddr - sec->vma;
1248 1.1 christos stop = (bfd_vma) ((bfd_signed_vma) start - (long) irel->r_offset);
1249 1.1 christos
1250 1.1 christos if (start > addr
1251 1.1 christos && start < toaddr
1252 1.1 christos && (stop <= addr || stop >= toaddr))
1253 1.1 christos irel->r_offset += count;
1254 1.1 christos else if (stop > addr
1255 1.1 christos && stop < toaddr
1256 1.1 christos && (start <= addr || start >= toaddr))
1257 1.1 christos irel->r_offset -= count;
1258 1.1 christos
1259 1.1 christos start = stop;
1260 1.1 christos
1261 1.1 christos if (irel->r_type == R_SH_SWITCH16)
1262 1.1 christos voff = bfd_get_signed_16 (abfd, contents + nraddr);
1263 1.1 christos else if (irel->r_type == R_SH_SWITCH8)
1264 1.1 christos voff = bfd_get_8 (abfd, contents + nraddr);
1265 1.1 christos else
1266 1.1 christos voff = bfd_get_signed_32 (abfd, contents + nraddr);
1267 1.1 christos stop = (bfd_vma) ((bfd_signed_vma) start + voff);
1268 1.1 christos
1269 1.1 christos break;
1270 1.1 christos
1271 1.1 christos case R_SH_USES:
1272 1.1 christos start = irel->r_vaddr - sec->vma;
1273 1.1 christos stop = (bfd_vma) ((bfd_signed_vma) start
1274 1.1 christos + (long) irel->r_offset
1275 1.1 christos + 4);
1276 1.1 christos break;
1277 1.1 christos }
1278 1.1 christos
1279 1.1 christos if (start > addr
1280 1.1 christos && start < toaddr
1281 1.1 christos && (stop <= addr || stop >= toaddr))
1282 1.1 christos adjust = count;
1283 1.1 christos else if (stop > addr
1284 1.1 christos && stop < toaddr
1285 1.1 christos && (start <= addr || start >= toaddr))
1286 1.1 christos adjust = - count;
1287 1.1 christos else
1288 1.1 christos adjust = 0;
1289 1.1 christos
1290 1.1 christos if (adjust != 0)
1291 1.1 christos {
1292 1.1 christos oinsn = insn;
1293 1.1 christos overflow = FALSE;
1294 1.1 christos switch (irel->r_type)
1295 1.1 christos {
1296 1.1 christos default:
1297 1.1 christos abort ();
1298 1.1 christos break;
1299 1.1 christos
1300 1.1 christos case R_SH_PCDISP8BY2:
1301 1.1 christos case R_SH_PCRELIMM8BY2:
1302 1.1 christos insn += adjust / 2;
1303 1.1 christos if ((oinsn & 0xff00) != (insn & 0xff00))
1304 1.1 christos overflow = TRUE;
1305 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1306 1.1 christos break;
1307 1.1 christos
1308 1.1 christos case R_SH_PCDISP:
1309 1.1 christos insn += adjust / 2;
1310 1.1 christos if ((oinsn & 0xf000) != (insn & 0xf000))
1311 1.1 christos overflow = TRUE;
1312 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1313 1.1 christos break;
1314 1.1 christos
1315 1.1 christos case R_SH_PCRELIMM8BY4:
1316 1.1 christos BFD_ASSERT (adjust == count || count >= 4);
1317 1.1 christos if (count >= 4)
1318 1.1 christos insn += adjust / 4;
1319 1.1 christos else
1320 1.1 christos {
1321 1.1 christos if ((irel->r_vaddr & 3) == 0)
1322 1.1 christos ++insn;
1323 1.1 christos }
1324 1.1 christos if ((oinsn & 0xff00) != (insn & 0xff00))
1325 1.1 christos overflow = TRUE;
1326 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
1327 1.1 christos break;
1328 1.1 christos
1329 1.1 christos case R_SH_SWITCH8:
1330 1.1 christos voff += adjust;
1331 1.1 christos if (voff < 0 || voff >= 0xff)
1332 1.1 christos overflow = TRUE;
1333 1.1 christos bfd_put_8 (abfd, (bfd_vma) voff, contents + nraddr);
1334 1.1 christos break;
1335 1.1 christos
1336 1.1 christos case R_SH_SWITCH16:
1337 1.1 christos voff += adjust;
1338 1.1 christos if (voff < - 0x8000 || voff >= 0x8000)
1339 1.1 christos overflow = TRUE;
1340 1.1 christos bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
1341 1.1 christos break;
1342 1.1 christos
1343 1.1 christos case R_SH_SWITCH32:
1344 1.1 christos voff += adjust;
1345 1.1 christos bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
1346 1.1 christos break;
1347 1.1 christos
1348 1.1 christos case R_SH_USES:
1349 1.1 christos irel->r_offset += adjust;
1350 1.1 christos break;
1351 1.1 christos }
1352 1.1 christos
1353 1.1 christos if (overflow)
1354 1.1.1.5 christos {
1355 1.1.1.5 christos _bfd_error_handler
1356 1.1.1.6 christos /* xgettext: c-format */
1357 1.1.1.6 christos (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"),
1358 1.1 christos abfd, (uint64_t) irel->r_vaddr);
1359 1.1 christos bfd_set_error (bfd_error_bad_value);
1360 1.1 christos return FALSE;
1361 1.1 christos }
1362 1.1 christos }
1363 1.1 christos
1364 1.1 christos irel->r_vaddr = nraddr + sec->vma;
1365 1.1 christos }
1366 1.1 christos
1367 1.1 christos /* Look through all the other sections. If there contain any IMM32
1368 1.1 christos relocs against internal symbols which we are not going to adjust
1369 1.1 christos below, we may need to adjust the addends. */
1370 1.1 christos for (o = abfd->sections; o != NULL; o = o->next)
1371 1.1 christos {
1372 1.1 christos struct internal_reloc *internal_relocs;
1373 1.1 christos struct internal_reloc *irelscan, *irelscanend;
1374 1.1 christos bfd_byte *ocontents;
1375 1.1 christos
1376 1.1 christos if (o == sec
1377 1.1 christos || (o->flags & SEC_RELOC) == 0
1378 1.1 christos || o->reloc_count == 0)
1379 1.1 christos continue;
1380 1.1 christos
1381 1.1.1.6 christos /* We always cache the relocs. Perhaps, if info->keep_memory is
1382 1.1.1.6 christos FALSE, we should free them, if we are permitted to, when we
1383 1.1 christos leave sh_coff_relax_section. */
1384 1.1 christos internal_relocs = (_bfd_coff_read_internal_relocs
1385 1.1 christos (abfd, o, TRUE, (bfd_byte *) NULL, FALSE,
1386 1.1 christos (struct internal_reloc *) NULL));
1387 1.1 christos if (internal_relocs == NULL)
1388 1.1 christos return FALSE;
1389 1.1 christos
1390 1.1 christos ocontents = NULL;
1391 1.1 christos irelscanend = internal_relocs + o->reloc_count;
1392 1.1 christos for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
1393 1.1 christos {
1394 1.1 christos struct internal_syment sym;
1395 1.1 christos
1396 1.1 christos #ifdef COFF_WITH_PE
1397 1.1 christos if (irelscan->r_type != R_SH_IMM32
1398 1.1 christos && irelscan->r_type != R_SH_IMAGEBASE
1399 1.1 christos && irelscan->r_type != R_SH_IMM32CE)
1400 1.1 christos #else
1401 1.1 christos if (irelscan->r_type != R_SH_IMM32)
1402 1.1 christos #endif
1403 1.1 christos continue;
1404 1.1 christos
1405 1.1 christos bfd_coff_swap_sym_in (abfd,
1406 1.1 christos ((bfd_byte *) obj_coff_external_syms (abfd)
1407 1.1 christos + (irelscan->r_symndx
1408 1.1 christos * bfd_coff_symesz (abfd))),
1409 1.1 christos &sym);
1410 1.1 christos if (sym.n_sclass != C_EXT
1411 1.1 christos && sym.n_scnum == sec->target_index
1412 1.1 christos && ((bfd_vma) sym.n_value <= addr
1413 1.1 christos || (bfd_vma) sym.n_value >= toaddr))
1414 1.1 christos {
1415 1.1 christos bfd_vma val;
1416 1.1 christos
1417 1.1 christos if (ocontents == NULL)
1418 1.1 christos {
1419 1.1 christos if (coff_section_data (abfd, o)->contents != NULL)
1420 1.1 christos ocontents = coff_section_data (abfd, o)->contents;
1421 1.1 christos else
1422 1.1 christos {
1423 1.1 christos if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
1424 1.1 christos return FALSE;
1425 1.1.1.6 christos /* We always cache the section contents.
1426 1.1.1.6 christos Perhaps, if info->keep_memory is FALSE, we
1427 1.1.1.6 christos should free them, if we are permitted to,
1428 1.1 christos when we leave sh_coff_relax_section. */
1429 1.1 christos coff_section_data (abfd, o)->contents = ocontents;
1430 1.1 christos }
1431 1.1 christos }
1432 1.1 christos
1433 1.1 christos val = bfd_get_32 (abfd, ocontents + irelscan->r_vaddr - o->vma);
1434 1.1 christos val += sym.n_value;
1435 1.1 christos if (val > addr && val < toaddr)
1436 1.1 christos bfd_put_32 (abfd, val - count,
1437 1.1 christos ocontents + irelscan->r_vaddr - o->vma);
1438 1.1 christos
1439 1.1 christos coff_section_data (abfd, o)->keep_contents = TRUE;
1440 1.1 christos }
1441 1.1 christos }
1442 1.1 christos }
1443 1.1 christos
1444 1.1 christos /* Adjusting the internal symbols will not work if something has
1445 1.1 christos already retrieved the generic symbols. It would be possible to
1446 1.1 christos make this work by adjusting the generic symbols at the same time.
1447 1.1 christos However, this case should not arise in normal usage. */
1448 1.1 christos if (obj_symbols (abfd) != NULL
1449 1.1 christos || obj_raw_syments (abfd) != NULL)
1450 1.1.1.5 christos {
1451 1.1.1.6 christos _bfd_error_handler
1452 1.1 christos (_("%pB: fatal: generic symbols retrieved before relaxing"), abfd);
1453 1.1 christos bfd_set_error (bfd_error_invalid_operation);
1454 1.1 christos return FALSE;
1455 1.1 christos }
1456 1.1 christos
1457 1.1 christos /* Adjust all the symbols. */
1458 1.1 christos sym_hash = obj_coff_sym_hashes (abfd);
1459 1.1 christos symesz = bfd_coff_symesz (abfd);
1460 1.1 christos esym = (bfd_byte *) obj_coff_external_syms (abfd);
1461 1.1 christos esymend = esym + obj_raw_syment_count (abfd) * symesz;
1462 1.1 christos while (esym < esymend)
1463 1.1 christos {
1464 1.1 christos struct internal_syment isym;
1465 1.1.1.2 christos
1466 1.1 christos bfd_coff_swap_sym_in (abfd, esym, &isym);
1467 1.1 christos
1468 1.1 christos if (isym.n_scnum == sec->target_index
1469 1.1 christos && (bfd_vma) isym.n_value > addr
1470 1.1 christos && (bfd_vma) isym.n_value < toaddr)
1471 1.1 christos {
1472 1.1 christos isym.n_value -= count;
1473 1.1.1.2 christos
1474 1.1 christos bfd_coff_swap_sym_out (abfd, &isym, esym);
1475 1.1 christos
1476 1.1 christos if (*sym_hash != NULL)
1477 1.1 christos {
1478 1.1 christos BFD_ASSERT ((*sym_hash)->root.type == bfd_link_hash_defined
1479 1.1 christos || (*sym_hash)->root.type == bfd_link_hash_defweak);
1480 1.1 christos BFD_ASSERT ((*sym_hash)->root.u.def.value >= addr
1481 1.1 christos && (*sym_hash)->root.u.def.value < toaddr);
1482 1.1 christos (*sym_hash)->root.u.def.value -= count;
1483 1.1 christos }
1484 1.1 christos }
1485 1.1 christos
1486 1.1 christos esym += (isym.n_numaux + 1) * symesz;
1487 1.1 christos sym_hash += isym.n_numaux + 1;
1488 1.1 christos }
1489 1.1 christos
1490 1.1 christos /* See if we can move the ALIGN reloc forward. We have adjusted
1491 1.1 christos r_vaddr for it already. */
1492 1.1 christos if (irelalign != NULL)
1493 1.1 christos {
1494 1.1 christos bfd_vma alignto, alignaddr;
1495 1.1 christos
1496 1.1 christos alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_offset);
1497 1.1 christos alignaddr = BFD_ALIGN (irelalign->r_vaddr - sec->vma,
1498 1.1 christos 1 << irelalign->r_offset);
1499 1.1 christos if (alignto != alignaddr)
1500 1.1 christos {
1501 1.1 christos /* Tail recursion. */
1502 1.1 christos return sh_relax_delete_bytes (abfd, sec, alignaddr,
1503 1.1 christos (int) (alignto - alignaddr));
1504 1.1 christos }
1505 1.1 christos }
1506 1.1 christos
1507 1.1 christos return TRUE;
1508 1.1 christos }
1509 1.1 christos
1510 1.1 christos /* This is yet another version of the SH opcode table, used to rapidly
1512 1.1 christos get information about a particular instruction. */
1513 1.1 christos
1514 1.1 christos /* The opcode map is represented by an array of these structures. The
1515 1.1 christos array is indexed by the high order four bits in the instruction. */
1516 1.1 christos
1517 1.1 christos struct sh_major_opcode
1518 1.1 christos {
1519 1.1 christos /* A pointer to the instruction list. This is an array which
1520 1.1 christos contains all the instructions with this major opcode. */
1521 1.1 christos const struct sh_minor_opcode *minor_opcodes;
1522 1.1 christos /* The number of elements in minor_opcodes. */
1523 1.1 christos unsigned short count;
1524 1.1 christos };
1525 1.1 christos
1526 1.1 christos /* This structure holds information for a set of SH opcodes. The
1527 1.1 christos instruction code is anded with the mask value, and the resulting
1528 1.1 christos value is used to search the order opcode list. */
1529 1.1 christos
1530 1.1 christos struct sh_minor_opcode
1531 1.1 christos {
1532 1.1 christos /* The sorted opcode list. */
1533 1.1 christos const struct sh_opcode *opcodes;
1534 1.1 christos /* The number of elements in opcodes. */
1535 1.1 christos unsigned short count;
1536 1.1 christos /* The mask value to use when searching the opcode list. */
1537 1.1 christos unsigned short mask;
1538 1.1 christos };
1539 1.1 christos
1540 1.1 christos /* This structure holds information for an SH instruction. An array
1541 1.1 christos of these structures is sorted in order by opcode. */
1542 1.1 christos
1543 1.1 christos struct sh_opcode
1544 1.1 christos {
1545 1.1 christos /* The code for this instruction, after it has been anded with the
1546 1.1 christos mask value in the sh_major_opcode structure. */
1547 1.1 christos unsigned short opcode;
1548 1.1 christos /* Flags for this instruction. */
1549 1.1 christos unsigned long flags;
1550 1.1 christos };
1551 1.1 christos
1552 1.1 christos /* Flag which appear in the sh_opcode structure. */
1553 1.1 christos
1554 1.1 christos /* This instruction loads a value from memory. */
1555 1.1 christos #define LOAD (0x1)
1556 1.1 christos
1557 1.1 christos /* This instruction stores a value to memory. */
1558 1.1 christos #define STORE (0x2)
1559 1.1 christos
1560 1.1 christos /* This instruction is a branch. */
1561 1.1 christos #define BRANCH (0x4)
1562 1.1 christos
1563 1.1 christos /* This instruction has a delay slot. */
1564 1.1 christos #define DELAY (0x8)
1565 1.1 christos
1566 1.1 christos /* This instruction uses the value in the register in the field at
1567 1.1 christos mask 0x0f00 of the instruction. */
1568 1.1 christos #define USES1 (0x10)
1569 1.1 christos #define USES1_REG(x) ((x & 0x0f00) >> 8)
1570 1.1 christos
1571 1.1 christos /* This instruction uses the value in the register in the field at
1572 1.1 christos mask 0x00f0 of the instruction. */
1573 1.1 christos #define USES2 (0x20)
1574 1.1 christos #define USES2_REG(x) ((x & 0x00f0) >> 4)
1575 1.1 christos
1576 1.1 christos /* This instruction uses the value in register 0. */
1577 1.1 christos #define USESR0 (0x40)
1578 1.1 christos
1579 1.1 christos /* This instruction sets the value in the register in the field at
1580 1.1 christos mask 0x0f00 of the instruction. */
1581 1.1 christos #define SETS1 (0x80)
1582 1.1 christos #define SETS1_REG(x) ((x & 0x0f00) >> 8)
1583 1.1 christos
1584 1.1 christos /* This instruction sets the value in the register in the field at
1585 1.1 christos mask 0x00f0 of the instruction. */
1586 1.1 christos #define SETS2 (0x100)
1587 1.1 christos #define SETS2_REG(x) ((x & 0x00f0) >> 4)
1588 1.1 christos
1589 1.1 christos /* This instruction sets register 0. */
1590 1.1 christos #define SETSR0 (0x200)
1591 1.1 christos
1592 1.1 christos /* This instruction sets a special register. */
1593 1.1 christos #define SETSSP (0x400)
1594 1.1 christos
1595 1.1 christos /* This instruction uses a special register. */
1596 1.1 christos #define USESSP (0x800)
1597 1.1 christos
1598 1.1 christos /* This instruction uses the floating point register in the field at
1599 1.1 christos mask 0x0f00 of the instruction. */
1600 1.1 christos #define USESF1 (0x1000)
1601 1.1 christos #define USESF1_REG(x) ((x & 0x0f00) >> 8)
1602 1.1 christos
1603 1.1 christos /* This instruction uses the floating point register in the field at
1604 1.1 christos mask 0x00f0 of the instruction. */
1605 1.1 christos #define USESF2 (0x2000)
1606 1.1 christos #define USESF2_REG(x) ((x & 0x00f0) >> 4)
1607 1.1 christos
1608 1.1 christos /* This instruction uses floating point register 0. */
1609 1.1 christos #define USESF0 (0x4000)
1610 1.1 christos
1611 1.1 christos /* This instruction sets the floating point register in the field at
1612 1.1 christos mask 0x0f00 of the instruction. */
1613 1.1 christos #define SETSF1 (0x8000)
1614 1.1 christos #define SETSF1_REG(x) ((x & 0x0f00) >> 8)
1615 1.1 christos
1616 1.1 christos #define USESAS (0x10000)
1617 1.1 christos #define USESAS_REG(x) (((((x) >> 8) - 2) & 3) + 2)
1618 1.1 christos #define USESR8 (0x20000)
1619 1.1 christos #define SETSAS (0x40000)
1620 1.1 christos #define SETSAS_REG(x) USESAS_REG (x)
1621 1.1 christos
1622 1.1 christos #define MAP(a) a, sizeof a / sizeof a[0]
1623 1.1 christos
1624 1.1 christos #ifndef COFF_IMAGE_WITH_PE
1625 1.1 christos
1626 1.1 christos /* The opcode maps. */
1627 1.1 christos
1628 1.1 christos static const struct sh_opcode sh_opcode00[] =
1629 1.1 christos {
1630 1.1 christos { 0x0008, SETSSP }, /* clrt */
1631 1.1 christos { 0x0009, 0 }, /* nop */
1632 1.1 christos { 0x000b, BRANCH | DELAY | USESSP }, /* rts */
1633 1.1 christos { 0x0018, SETSSP }, /* sett */
1634 1.1 christos { 0x0019, SETSSP }, /* div0u */
1635 1.1 christos { 0x001b, 0 }, /* sleep */
1636 1.1 christos { 0x0028, SETSSP }, /* clrmac */
1637 1.1 christos { 0x002b, BRANCH | DELAY | SETSSP }, /* rte */
1638 1.1 christos { 0x0038, USESSP | SETSSP }, /* ldtlb */
1639 1.1 christos { 0x0048, SETSSP }, /* clrs */
1640 1.1 christos { 0x0058, SETSSP } /* sets */
1641 1.1 christos };
1642 1.1 christos
1643 1.1 christos static const struct sh_opcode sh_opcode01[] =
1644 1.1 christos {
1645 1.1 christos { 0x0003, BRANCH | DELAY | USES1 | SETSSP }, /* bsrf rn */
1646 1.1 christos { 0x000a, SETS1 | USESSP }, /* sts mach,rn */
1647 1.1 christos { 0x001a, SETS1 | USESSP }, /* sts macl,rn */
1648 1.1 christos { 0x0023, BRANCH | DELAY | USES1 }, /* braf rn */
1649 1.1 christos { 0x0029, SETS1 | USESSP }, /* movt rn */
1650 1.1 christos { 0x002a, SETS1 | USESSP }, /* sts pr,rn */
1651 1.1 christos { 0x005a, SETS1 | USESSP }, /* sts fpul,rn */
1652 1.1 christos { 0x006a, SETS1 | USESSP }, /* sts fpscr,rn / sts dsr,rn */
1653 1.1 christos { 0x0083, LOAD | USES1 }, /* pref @rn */
1654 1.1 christos { 0x007a, SETS1 | USESSP }, /* sts a0,rn */
1655 1.1 christos { 0x008a, SETS1 | USESSP }, /* sts x0,rn */
1656 1.1 christos { 0x009a, SETS1 | USESSP }, /* sts x1,rn */
1657 1.1 christos { 0x00aa, SETS1 | USESSP }, /* sts y0,rn */
1658 1.1 christos { 0x00ba, SETS1 | USESSP } /* sts y1,rn */
1659 1.1 christos };
1660 1.1 christos
1661 1.1 christos static const struct sh_opcode sh_opcode02[] =
1662 1.1 christos {
1663 1.1 christos { 0x0002, SETS1 | USESSP }, /* stc <special_reg>,rn */
1664 1.1 christos { 0x0004, STORE | USES1 | USES2 | USESR0 }, /* mov.b rm,@(r0,rn) */
1665 1.1 christos { 0x0005, STORE | USES1 | USES2 | USESR0 }, /* mov.w rm,@(r0,rn) */
1666 1.1 christos { 0x0006, STORE | USES1 | USES2 | USESR0 }, /* mov.l rm,@(r0,rn) */
1667 1.1 christos { 0x0007, SETSSP | USES1 | USES2 }, /* mul.l rm,rn */
1668 1.1 christos { 0x000c, LOAD | SETS1 | USES2 | USESR0 }, /* mov.b @(r0,rm),rn */
1669 1.1 christos { 0x000d, LOAD | SETS1 | USES2 | USESR0 }, /* mov.w @(r0,rm),rn */
1670 1.1 christos { 0x000e, LOAD | SETS1 | USES2 | USESR0 }, /* mov.l @(r0,rm),rn */
1671 1.1 christos { 0x000f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.l @rm+,@rn+ */
1672 1.1 christos };
1673 1.1 christos
1674 1.1 christos static const struct sh_minor_opcode sh_opcode0[] =
1675 1.1 christos {
1676 1.1 christos { MAP (sh_opcode00), 0xffff },
1677 1.1 christos { MAP (sh_opcode01), 0xf0ff },
1678 1.1 christos { MAP (sh_opcode02), 0xf00f }
1679 1.1 christos };
1680 1.1 christos
1681 1.1 christos static const struct sh_opcode sh_opcode10[] =
1682 1.1 christos {
1683 1.1 christos { 0x1000, STORE | USES1 | USES2 } /* mov.l rm,@(disp,rn) */
1684 1.1 christos };
1685 1.1 christos
1686 1.1 christos static const struct sh_minor_opcode sh_opcode1[] =
1687 1.1 christos {
1688 1.1 christos { MAP (sh_opcode10), 0xf000 }
1689 1.1 christos };
1690 1.1 christos
1691 1.1 christos static const struct sh_opcode sh_opcode20[] =
1692 1.1 christos {
1693 1.1 christos { 0x2000, STORE | USES1 | USES2 }, /* mov.b rm,@rn */
1694 1.1 christos { 0x2001, STORE | USES1 | USES2 }, /* mov.w rm,@rn */
1695 1.1 christos { 0x2002, STORE | USES1 | USES2 }, /* mov.l rm,@rn */
1696 1.1 christos { 0x2004, STORE | SETS1 | USES1 | USES2 }, /* mov.b rm,@-rn */
1697 1.1 christos { 0x2005, STORE | SETS1 | USES1 | USES2 }, /* mov.w rm,@-rn */
1698 1.1 christos { 0x2006, STORE | SETS1 | USES1 | USES2 }, /* mov.l rm,@-rn */
1699 1.1 christos { 0x2007, SETSSP | USES1 | USES2 | USESSP }, /* div0s */
1700 1.1 christos { 0x2008, SETSSP | USES1 | USES2 }, /* tst rm,rn */
1701 1.1 christos { 0x2009, SETS1 | USES1 | USES2 }, /* and rm,rn */
1702 1.1 christos { 0x200a, SETS1 | USES1 | USES2 }, /* xor rm,rn */
1703 1.1 christos { 0x200b, SETS1 | USES1 | USES2 }, /* or rm,rn */
1704 1.1 christos { 0x200c, SETSSP | USES1 | USES2 }, /* cmp/str rm,rn */
1705 1.1 christos { 0x200d, SETS1 | USES1 | USES2 }, /* xtrct rm,rn */
1706 1.1 christos { 0x200e, SETSSP | USES1 | USES2 }, /* mulu.w rm,rn */
1707 1.1 christos { 0x200f, SETSSP | USES1 | USES2 } /* muls.w rm,rn */
1708 1.1 christos };
1709 1.1 christos
1710 1.1 christos static const struct sh_minor_opcode sh_opcode2[] =
1711 1.1 christos {
1712 1.1 christos { MAP (sh_opcode20), 0xf00f }
1713 1.1 christos };
1714 1.1 christos
1715 1.1 christos static const struct sh_opcode sh_opcode30[] =
1716 1.1 christos {
1717 1.1 christos { 0x3000, SETSSP | USES1 | USES2 }, /* cmp/eq rm,rn */
1718 1.1 christos { 0x3002, SETSSP | USES1 | USES2 }, /* cmp/hs rm,rn */
1719 1.1 christos { 0x3003, SETSSP | USES1 | USES2 }, /* cmp/ge rm,rn */
1720 1.1 christos { 0x3004, SETSSP | USESSP | USES1 | USES2 }, /* div1 rm,rn */
1721 1.1 christos { 0x3005, SETSSP | USES1 | USES2 }, /* dmulu.l rm,rn */
1722 1.1 christos { 0x3006, SETSSP | USES1 | USES2 }, /* cmp/hi rm,rn */
1723 1.1 christos { 0x3007, SETSSP | USES1 | USES2 }, /* cmp/gt rm,rn */
1724 1.1 christos { 0x3008, SETS1 | USES1 | USES2 }, /* sub rm,rn */
1725 1.1 christos { 0x300a, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* subc rm,rn */
1726 1.1 christos { 0x300b, SETS1 | SETSSP | USES1 | USES2 }, /* subv rm,rn */
1727 1.1 christos { 0x300c, SETS1 | USES1 | USES2 }, /* add rm,rn */
1728 1.1 christos { 0x300d, SETSSP | USES1 | USES2 }, /* dmuls.l rm,rn */
1729 1.1 christos { 0x300e, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* addc rm,rn */
1730 1.1 christos { 0x300f, SETS1 | SETSSP | USES1 | USES2 } /* addv rm,rn */
1731 1.1 christos };
1732 1.1 christos
1733 1.1 christos static const struct sh_minor_opcode sh_opcode3[] =
1734 1.1 christos {
1735 1.1 christos { MAP (sh_opcode30), 0xf00f }
1736 1.1 christos };
1737 1.1 christos
1738 1.1 christos static const struct sh_opcode sh_opcode40[] =
1739 1.1 christos {
1740 1.1 christos { 0x4000, SETS1 | SETSSP | USES1 }, /* shll rn */
1741 1.1 christos { 0x4001, SETS1 | SETSSP | USES1 }, /* shlr rn */
1742 1.1 christos { 0x4002, STORE | SETS1 | USES1 | USESSP }, /* sts.l mach,@-rn */
1743 1.1 christos { 0x4004, SETS1 | SETSSP | USES1 }, /* rotl rn */
1744 1.1 christos { 0x4005, SETS1 | SETSSP | USES1 }, /* rotr rn */
1745 1.1 christos { 0x4006, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,mach */
1746 1.1 christos { 0x4008, SETS1 | USES1 }, /* shll2 rn */
1747 1.1 christos { 0x4009, SETS1 | USES1 }, /* shlr2 rn */
1748 1.1 christos { 0x400a, SETSSP | USES1 }, /* lds rm,mach */
1749 1.1 christos { 0x400b, BRANCH | DELAY | USES1 }, /* jsr @rn */
1750 1.1 christos { 0x4010, SETS1 | SETSSP | USES1 }, /* dt rn */
1751 1.1 christos { 0x4011, SETSSP | USES1 }, /* cmp/pz rn */
1752 1.1 christos { 0x4012, STORE | SETS1 | USES1 | USESSP }, /* sts.l macl,@-rn */
1753 1.1 christos { 0x4014, SETSSP | USES1 }, /* setrc rm */
1754 1.1 christos { 0x4015, SETSSP | USES1 }, /* cmp/pl rn */
1755 1.1 christos { 0x4016, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,macl */
1756 1.1 christos { 0x4018, SETS1 | USES1 }, /* shll8 rn */
1757 1.1 christos { 0x4019, SETS1 | USES1 }, /* shlr8 rn */
1758 1.1 christos { 0x401a, SETSSP | USES1 }, /* lds rm,macl */
1759 1.1 christos { 0x401b, LOAD | SETSSP | USES1 }, /* tas.b @rn */
1760 1.1 christos { 0x4020, SETS1 | SETSSP | USES1 }, /* shal rn */
1761 1.1 christos { 0x4021, SETS1 | SETSSP | USES1 }, /* shar rn */
1762 1.1 christos { 0x4022, STORE | SETS1 | USES1 | USESSP }, /* sts.l pr,@-rn */
1763 1.1 christos { 0x4024, SETS1 | SETSSP | USES1 | USESSP }, /* rotcl rn */
1764 1.1 christos { 0x4025, SETS1 | SETSSP | USES1 | USESSP }, /* rotcr rn */
1765 1.1 christos { 0x4026, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,pr */
1766 1.1 christos { 0x4028, SETS1 | USES1 }, /* shll16 rn */
1767 1.1 christos { 0x4029, SETS1 | USES1 }, /* shlr16 rn */
1768 1.1 christos { 0x402a, SETSSP | USES1 }, /* lds rm,pr */
1769 1.1 christos { 0x402b, BRANCH | DELAY | USES1 }, /* jmp @rn */
1770 1.1 christos { 0x4052, STORE | SETS1 | USES1 | USESSP }, /* sts.l fpul,@-rn */
1771 1.1 christos { 0x4056, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,fpul */
1772 1.1 christos { 0x405a, SETSSP | USES1 }, /* lds.l rm,fpul */
1773 1.1 christos { 0x4062, STORE | SETS1 | USES1 | USESSP }, /* sts.l fpscr / dsr,@-rn */
1774 1.1 christos { 0x4066, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,fpscr / dsr */
1775 1.1 christos { 0x406a, SETSSP | USES1 }, /* lds rm,fpscr / lds rm,dsr */
1776 1.1 christos { 0x4072, STORE | SETS1 | USES1 | USESSP }, /* sts.l a0,@-rn */
1777 1.1 christos { 0x4076, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,a0 */
1778 1.1 christos { 0x407a, SETSSP | USES1 }, /* lds.l rm,a0 */
1779 1.1 christos { 0x4082, STORE | SETS1 | USES1 | USESSP }, /* sts.l x0,@-rn */
1780 1.1 christos { 0x4086, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,x0 */
1781 1.1 christos { 0x408a, SETSSP | USES1 }, /* lds.l rm,x0 */
1782 1.1 christos { 0x4092, STORE | SETS1 | USES1 | USESSP }, /* sts.l x1,@-rn */
1783 1.1 christos { 0x4096, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,x1 */
1784 1.1 christos { 0x409a, SETSSP | USES1 }, /* lds.l rm,x1 */
1785 1.1 christos { 0x40a2, STORE | SETS1 | USES1 | USESSP }, /* sts.l y0,@-rn */
1786 1.1 christos { 0x40a6, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,y0 */
1787 1.1 christos { 0x40aa, SETSSP | USES1 }, /* lds.l rm,y0 */
1788 1.1 christos { 0x40b2, STORE | SETS1 | USES1 | USESSP }, /* sts.l y1,@-rn */
1789 1.1 christos { 0x40b6, LOAD | SETS1 | SETSSP | USES1 }, /* lds.l @rm+,y1 */
1790 1.1 christos { 0x40ba, SETSSP | USES1 } /* lds.l rm,y1 */
1791 1.1 christos };
1792 1.1 christos
1793 1.1 christos static const struct sh_opcode sh_opcode41[] =
1794 1.1 christos {
1795 1.1 christos { 0x4003, STORE | SETS1 | USES1 | USESSP }, /* stc.l <special_reg>,@-rn */
1796 1.1 christos { 0x4007, LOAD | SETS1 | SETSSP | USES1 }, /* ldc.l @rm+,<special_reg> */
1797 1.1 christos { 0x400c, SETS1 | USES1 | USES2 }, /* shad rm,rn */
1798 1.1 christos { 0x400d, SETS1 | USES1 | USES2 }, /* shld rm,rn */
1799 1.1 christos { 0x400e, SETSSP | USES1 }, /* ldc rm,<special_reg> */
1800 1.1 christos { 0x400f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.w @rm+,@rn+ */
1801 1.1 christos };
1802 1.1 christos
1803 1.1 christos static const struct sh_minor_opcode sh_opcode4[] =
1804 1.1 christos {
1805 1.1 christos { MAP (sh_opcode40), 0xf0ff },
1806 1.1 christos { MAP (sh_opcode41), 0xf00f }
1807 1.1 christos };
1808 1.1 christos
1809 1.1 christos static const struct sh_opcode sh_opcode50[] =
1810 1.1 christos {
1811 1.1 christos { 0x5000, LOAD | SETS1 | USES2 } /* mov.l @(disp,rm),rn */
1812 1.1 christos };
1813 1.1 christos
1814 1.1 christos static const struct sh_minor_opcode sh_opcode5[] =
1815 1.1 christos {
1816 1.1 christos { MAP (sh_opcode50), 0xf000 }
1817 1.1 christos };
1818 1.1 christos
1819 1.1 christos static const struct sh_opcode sh_opcode60[] =
1820 1.1 christos {
1821 1.1 christos { 0x6000, LOAD | SETS1 | USES2 }, /* mov.b @rm,rn */
1822 1.1 christos { 0x6001, LOAD | SETS1 | USES2 }, /* mov.w @rm,rn */
1823 1.1 christos { 0x6002, LOAD | SETS1 | USES2 }, /* mov.l @rm,rn */
1824 1.1 christos { 0x6003, SETS1 | USES2 }, /* mov rm,rn */
1825 1.1 christos { 0x6004, LOAD | SETS1 | SETS2 | USES2 }, /* mov.b @rm+,rn */
1826 1.1 christos { 0x6005, LOAD | SETS1 | SETS2 | USES2 }, /* mov.w @rm+,rn */
1827 1.1 christos { 0x6006, LOAD | SETS1 | SETS2 | USES2 }, /* mov.l @rm+,rn */
1828 1.1 christos { 0x6007, SETS1 | USES2 }, /* not rm,rn */
1829 1.1 christos { 0x6008, SETS1 | USES2 }, /* swap.b rm,rn */
1830 1.1 christos { 0x6009, SETS1 | USES2 }, /* swap.w rm,rn */
1831 1.1 christos { 0x600a, SETS1 | SETSSP | USES2 | USESSP }, /* negc rm,rn */
1832 1.1 christos { 0x600b, SETS1 | USES2 }, /* neg rm,rn */
1833 1.1 christos { 0x600c, SETS1 | USES2 }, /* extu.b rm,rn */
1834 1.1 christos { 0x600d, SETS1 | USES2 }, /* extu.w rm,rn */
1835 1.1 christos { 0x600e, SETS1 | USES2 }, /* exts.b rm,rn */
1836 1.1 christos { 0x600f, SETS1 | USES2 } /* exts.w rm,rn */
1837 1.1 christos };
1838 1.1 christos
1839 1.1 christos static const struct sh_minor_opcode sh_opcode6[] =
1840 1.1 christos {
1841 1.1 christos { MAP (sh_opcode60), 0xf00f }
1842 1.1 christos };
1843 1.1 christos
1844 1.1 christos static const struct sh_opcode sh_opcode70[] =
1845 1.1 christos {
1846 1.1 christos { 0x7000, SETS1 | USES1 } /* add #imm,rn */
1847 1.1 christos };
1848 1.1 christos
1849 1.1 christos static const struct sh_minor_opcode sh_opcode7[] =
1850 1.1 christos {
1851 1.1 christos { MAP (sh_opcode70), 0xf000 }
1852 1.1 christos };
1853 1.1 christos
1854 1.1 christos static const struct sh_opcode sh_opcode80[] =
1855 1.1 christos {
1856 1.1 christos { 0x8000, STORE | USES2 | USESR0 }, /* mov.b r0,@(disp,rn) */
1857 1.1 christos { 0x8100, STORE | USES2 | USESR0 }, /* mov.w r0,@(disp,rn) */
1858 1.1 christos { 0x8200, SETSSP }, /* setrc #imm */
1859 1.1 christos { 0x8400, LOAD | SETSR0 | USES2 }, /* mov.b @(disp,rm),r0 */
1860 1.1 christos { 0x8500, LOAD | SETSR0 | USES2 }, /* mov.w @(disp,rn),r0 */
1861 1.1 christos { 0x8800, SETSSP | USESR0 }, /* cmp/eq #imm,r0 */
1862 1.1 christos { 0x8900, BRANCH | USESSP }, /* bt label */
1863 1.1 christos { 0x8b00, BRANCH | USESSP }, /* bf label */
1864 1.1 christos { 0x8c00, SETSSP }, /* ldrs @(disp,pc) */
1865 1.1 christos { 0x8d00, BRANCH | DELAY | USESSP }, /* bt/s label */
1866 1.1 christos { 0x8e00, SETSSP }, /* ldre @(disp,pc) */
1867 1.1 christos { 0x8f00, BRANCH | DELAY | USESSP } /* bf/s label */
1868 1.1 christos };
1869 1.1 christos
1870 1.1 christos static const struct sh_minor_opcode sh_opcode8[] =
1871 1.1 christos {
1872 1.1 christos { MAP (sh_opcode80), 0xff00 }
1873 1.1 christos };
1874 1.1 christos
1875 1.1 christos static const struct sh_opcode sh_opcode90[] =
1876 1.1 christos {
1877 1.1 christos { 0x9000, LOAD | SETS1 } /* mov.w @(disp,pc),rn */
1878 1.1 christos };
1879 1.1 christos
1880 1.1 christos static const struct sh_minor_opcode sh_opcode9[] =
1881 1.1 christos {
1882 1.1 christos { MAP (sh_opcode90), 0xf000 }
1883 1.1 christos };
1884 1.1 christos
1885 1.1 christos static const struct sh_opcode sh_opcodea0[] =
1886 1.1 christos {
1887 1.1 christos { 0xa000, BRANCH | DELAY } /* bra label */
1888 1.1 christos };
1889 1.1 christos
1890 1.1 christos static const struct sh_minor_opcode sh_opcodea[] =
1891 1.1 christos {
1892 1.1 christos { MAP (sh_opcodea0), 0xf000 }
1893 1.1 christos };
1894 1.1 christos
1895 1.1 christos static const struct sh_opcode sh_opcodeb0[] =
1896 1.1 christos {
1897 1.1 christos { 0xb000, BRANCH | DELAY } /* bsr label */
1898 1.1 christos };
1899 1.1 christos
1900 1.1 christos static const struct sh_minor_opcode sh_opcodeb[] =
1901 1.1 christos {
1902 1.1 christos { MAP (sh_opcodeb0), 0xf000 }
1903 1.1 christos };
1904 1.1 christos
1905 1.1 christos static const struct sh_opcode sh_opcodec0[] =
1906 1.1 christos {
1907 1.1 christos { 0xc000, STORE | USESR0 | USESSP }, /* mov.b r0,@(disp,gbr) */
1908 1.1 christos { 0xc100, STORE | USESR0 | USESSP }, /* mov.w r0,@(disp,gbr) */
1909 1.1 christos { 0xc200, STORE | USESR0 | USESSP }, /* mov.l r0,@(disp,gbr) */
1910 1.1 christos { 0xc300, BRANCH | USESSP }, /* trapa #imm */
1911 1.1 christos { 0xc400, LOAD | SETSR0 | USESSP }, /* mov.b @(disp,gbr),r0 */
1912 1.1 christos { 0xc500, LOAD | SETSR0 | USESSP }, /* mov.w @(disp,gbr),r0 */
1913 1.1 christos { 0xc600, LOAD | SETSR0 | USESSP }, /* mov.l @(disp,gbr),r0 */
1914 1.1 christos { 0xc700, SETSR0 }, /* mova @(disp,pc),r0 */
1915 1.1 christos { 0xc800, SETSSP | USESR0 }, /* tst #imm,r0 */
1916 1.1 christos { 0xc900, SETSR0 | USESR0 }, /* and #imm,r0 */
1917 1.1 christos { 0xca00, SETSR0 | USESR0 }, /* xor #imm,r0 */
1918 1.1 christos { 0xcb00, SETSR0 | USESR0 }, /* or #imm,r0 */
1919 1.1 christos { 0xcc00, LOAD | SETSSP | USESR0 | USESSP }, /* tst.b #imm,@(r0,gbr) */
1920 1.1 christos { 0xcd00, LOAD | STORE | USESR0 | USESSP }, /* and.b #imm,@(r0,gbr) */
1921 1.1 christos { 0xce00, LOAD | STORE | USESR0 | USESSP }, /* xor.b #imm,@(r0,gbr) */
1922 1.1 christos { 0xcf00, LOAD | STORE | USESR0 | USESSP } /* or.b #imm,@(r0,gbr) */
1923 1.1 christos };
1924 1.1 christos
1925 1.1 christos static const struct sh_minor_opcode sh_opcodec[] =
1926 1.1 christos {
1927 1.1 christos { MAP (sh_opcodec0), 0xff00 }
1928 1.1 christos };
1929 1.1 christos
1930 1.1 christos static const struct sh_opcode sh_opcoded0[] =
1931 1.1 christos {
1932 1.1 christos { 0xd000, LOAD | SETS1 } /* mov.l @(disp,pc),rn */
1933 1.1 christos };
1934 1.1 christos
1935 1.1 christos static const struct sh_minor_opcode sh_opcoded[] =
1936 1.1 christos {
1937 1.1 christos { MAP (sh_opcoded0), 0xf000 }
1938 1.1 christos };
1939 1.1 christos
1940 1.1 christos static const struct sh_opcode sh_opcodee0[] =
1941 1.1 christos {
1942 1.1 christos { 0xe000, SETS1 } /* mov #imm,rn */
1943 1.1 christos };
1944 1.1 christos
1945 1.1 christos static const struct sh_minor_opcode sh_opcodee[] =
1946 1.1 christos {
1947 1.1 christos { MAP (sh_opcodee0), 0xf000 }
1948 1.1 christos };
1949 1.1 christos
1950 1.1 christos static const struct sh_opcode sh_opcodef0[] =
1951 1.1 christos {
1952 1.1 christos { 0xf000, SETSF1 | USESF1 | USESF2 }, /* fadd fm,fn */
1953 1.1 christos { 0xf001, SETSF1 | USESF1 | USESF2 }, /* fsub fm,fn */
1954 1.1 christos { 0xf002, SETSF1 | USESF1 | USESF2 }, /* fmul fm,fn */
1955 1.1 christos { 0xf003, SETSF1 | USESF1 | USESF2 }, /* fdiv fm,fn */
1956 1.1 christos { 0xf004, SETSSP | USESF1 | USESF2 }, /* fcmp/eq fm,fn */
1957 1.1 christos { 0xf005, SETSSP | USESF1 | USESF2 }, /* fcmp/gt fm,fn */
1958 1.1 christos { 0xf006, LOAD | SETSF1 | USES2 | USESR0 }, /* fmov.s @(r0,rm),fn */
1959 1.1 christos { 0xf007, STORE | USES1 | USESF2 | USESR0 }, /* fmov.s fm,@(r0,rn) */
1960 1.1 christos { 0xf008, LOAD | SETSF1 | USES2 }, /* fmov.s @rm,fn */
1961 1.1 christos { 0xf009, LOAD | SETS2 | SETSF1 | USES2 }, /* fmov.s @rm+,fn */
1962 1.1 christos { 0xf00a, STORE | USES1 | USESF2 }, /* fmov.s fm,@rn */
1963 1.1 christos { 0xf00b, STORE | SETS1 | USES1 | USESF2 }, /* fmov.s fm,@-rn */
1964 1.1 christos { 0xf00c, SETSF1 | USESF2 }, /* fmov fm,fn */
1965 1.1 christos { 0xf00e, SETSF1 | USESF1 | USESF2 | USESF0 } /* fmac f0,fm,fn */
1966 1.1 christos };
1967 1.1 christos
1968 1.1 christos static const struct sh_opcode sh_opcodef1[] =
1969 1.1 christos {
1970 1.1 christos { 0xf00d, SETSF1 | USESSP }, /* fsts fpul,fn */
1971 1.1 christos { 0xf01d, SETSSP | USESF1 }, /* flds fn,fpul */
1972 1.1 christos { 0xf02d, SETSF1 | USESSP }, /* float fpul,fn */
1973 1.1 christos { 0xf03d, SETSSP | USESF1 }, /* ftrc fn,fpul */
1974 1.1 christos { 0xf04d, SETSF1 | USESF1 }, /* fneg fn */
1975 1.1 christos { 0xf05d, SETSF1 | USESF1 }, /* fabs fn */
1976 1.1 christos { 0xf06d, SETSF1 | USESF1 }, /* fsqrt fn */
1977 1.1 christos { 0xf07d, SETSSP | USESF1 }, /* ftst/nan fn */
1978 1.1 christos { 0xf08d, SETSF1 }, /* fldi0 fn */
1979 1.1 christos { 0xf09d, SETSF1 } /* fldi1 fn */
1980 1.1 christos };
1981 1.1 christos
1982 1.1 christos static const struct sh_minor_opcode sh_opcodef[] =
1983 1.1 christos {
1984 1.1 christos { MAP (sh_opcodef0), 0xf00f },
1985 1.1 christos { MAP (sh_opcodef1), 0xf0ff }
1986 1.1 christos };
1987 1.1 christos
1988 1.1 christos static struct sh_major_opcode sh_opcodes[] =
1989 1.1 christos {
1990 1.1 christos { MAP (sh_opcode0) },
1991 1.1 christos { MAP (sh_opcode1) },
1992 1.1 christos { MAP (sh_opcode2) },
1993 1.1 christos { MAP (sh_opcode3) },
1994 1.1 christos { MAP (sh_opcode4) },
1995 1.1 christos { MAP (sh_opcode5) },
1996 1.1 christos { MAP (sh_opcode6) },
1997 1.1 christos { MAP (sh_opcode7) },
1998 1.1 christos { MAP (sh_opcode8) },
1999 1.1 christos { MAP (sh_opcode9) },
2000 1.1 christos { MAP (sh_opcodea) },
2001 1.1 christos { MAP (sh_opcodeb) },
2002 1.1 christos { MAP (sh_opcodec) },
2003 1.1 christos { MAP (sh_opcoded) },
2004 1.1 christos { MAP (sh_opcodee) },
2005 1.1 christos { MAP (sh_opcodef) }
2006 1.1 christos };
2007 1.1 christos
2008 1.1 christos /* The double data transfer / parallel processing insns are not
2009 1.1 christos described here. This will cause sh_align_load_span to leave them alone. */
2010 1.1 christos
2011 1.1 christos static const struct sh_opcode sh_dsp_opcodef0[] =
2012 1.1 christos {
2013 1.1 christos { 0xf400, USESAS | SETSAS | LOAD | SETSSP }, /* movs.x @-as,ds */
2014 1.1 christos { 0xf401, USESAS | SETSAS | STORE | USESSP }, /* movs.x ds,@-as */
2015 1.1 christos { 0xf404, USESAS | LOAD | SETSSP }, /* movs.x @as,ds */
2016 1.1 christos { 0xf405, USESAS | STORE | USESSP }, /* movs.x ds,@as */
2017 1.1 christos { 0xf408, USESAS | SETSAS | LOAD | SETSSP }, /* movs.x @as+,ds */
2018 1.1 christos { 0xf409, USESAS | SETSAS | STORE | USESSP }, /* movs.x ds,@as+ */
2019 1.1 christos { 0xf40c, USESAS | SETSAS | LOAD | SETSSP | USESR8 }, /* movs.x @as+r8,ds */
2020 1.1 christos { 0xf40d, USESAS | SETSAS | STORE | USESSP | USESR8 } /* movs.x ds,@as+r8 */
2021 1.1 christos };
2022 1.1 christos
2023 1.1 christos static const struct sh_minor_opcode sh_dsp_opcodef[] =
2024 1.1 christos {
2025 1.1 christos { MAP (sh_dsp_opcodef0), 0xfc0d }
2026 1.1 christos };
2027 1.1 christos
2028 1.1 christos /* Given an instruction, return a pointer to the corresponding
2029 1.1 christos sh_opcode structure. Return NULL if the instruction is not
2030 1.1 christos recognized. */
2031 1.1.1.2 christos
2032 1.1 christos static const struct sh_opcode *
2033 1.1 christos sh_insn_info (unsigned int insn)
2034 1.1 christos {
2035 1.1 christos const struct sh_major_opcode *maj;
2036 1.1 christos const struct sh_minor_opcode *min, *minend;
2037 1.1 christos
2038 1.1 christos maj = &sh_opcodes[(insn & 0xf000) >> 12];
2039 1.1 christos min = maj->minor_opcodes;
2040 1.1 christos minend = min + maj->count;
2041 1.1 christos for (; min < minend; min++)
2042 1.1 christos {
2043 1.1 christos unsigned int l;
2044 1.1 christos const struct sh_opcode *op, *opend;
2045 1.1 christos
2046 1.1 christos l = insn & min->mask;
2047 1.1 christos op = min->opcodes;
2048 1.1 christos opend = op + min->count;
2049 1.1.1.6 christos
2050 1.1 christos /* Since the opcodes tables are sorted, we could use a binary
2051 1.1 christos search here if the count were above some cutoff value. */
2052 1.1 christos for (; op < opend; op++)
2053 1.1 christos if (op->opcode == l)
2054 1.1 christos return op;
2055 1.1 christos }
2056 1.1 christos
2057 1.1 christos return NULL;
2058 1.1 christos }
2059 1.1 christos
2060 1.1 christos /* See whether an instruction uses a general purpose register. */
2061 1.1.1.2 christos
2062 1.1.1.2 christos static bfd_boolean
2063 1.1.1.2 christos sh_insn_uses_reg (unsigned int insn,
2064 1.1 christos const struct sh_opcode *op,
2065 1.1 christos unsigned int reg)
2066 1.1 christos {
2067 1.1 christos unsigned int f;
2068 1.1 christos
2069 1.1 christos f = op->flags;
2070 1.1 christos
2071 1.1 christos if ((f & USES1) != 0
2072 1.1 christos && USES1_REG (insn) == reg)
2073 1.1 christos return TRUE;
2074 1.1 christos if ((f & USES2) != 0
2075 1.1 christos && USES2_REG (insn) == reg)
2076 1.1 christos return TRUE;
2077 1.1 christos if ((f & USESR0) != 0
2078 1.1 christos && reg == 0)
2079 1.1 christos return TRUE;
2080 1.1 christos if ((f & USESAS) && reg == USESAS_REG (insn))
2081 1.1 christos return TRUE;
2082 1.1 christos if ((f & USESR8) && reg == 8)
2083 1.1 christos return TRUE;
2084 1.1 christos
2085 1.1 christos return FALSE;
2086 1.1 christos }
2087 1.1 christos
2088 1.1 christos /* See whether an instruction sets a general purpose register. */
2089 1.1.1.2 christos
2090 1.1.1.2 christos static bfd_boolean
2091 1.1.1.2 christos sh_insn_sets_reg (unsigned int insn,
2092 1.1 christos const struct sh_opcode *op,
2093 1.1 christos unsigned int reg)
2094 1.1 christos {
2095 1.1 christos unsigned int f;
2096 1.1 christos
2097 1.1 christos f = op->flags;
2098 1.1 christos
2099 1.1 christos if ((f & SETS1) != 0
2100 1.1 christos && SETS1_REG (insn) == reg)
2101 1.1 christos return TRUE;
2102 1.1 christos if ((f & SETS2) != 0
2103 1.1 christos && SETS2_REG (insn) == reg)
2104 1.1 christos return TRUE;
2105 1.1 christos if ((f & SETSR0) != 0
2106 1.1 christos && reg == 0)
2107 1.1 christos return TRUE;
2108 1.1 christos if ((f & SETSAS) && reg == SETSAS_REG (insn))
2109 1.1 christos return TRUE;
2110 1.1 christos
2111 1.1 christos return FALSE;
2112 1.1.1.2 christos }
2113 1.1 christos
2114 1.1 christos /* See whether an instruction uses or sets a general purpose register */
2115 1.1.1.2 christos
2116 1.1.1.2 christos static bfd_boolean
2117 1.1.1.2 christos sh_insn_uses_or_sets_reg (unsigned int insn,
2118 1.1 christos const struct sh_opcode *op,
2119 1.1.1.2 christos unsigned int reg)
2120 1.1 christos {
2121 1.1 christos if (sh_insn_uses_reg (insn, op, reg))
2122 1.1.1.2 christos return TRUE;
2123 1.1 christos
2124 1.1 christos return sh_insn_sets_reg (insn, op, reg);
2125 1.1 christos }
2126 1.1 christos
2127 1.1 christos /* See whether an instruction uses a floating point register. */
2128 1.1.1.2 christos
2129 1.1.1.2 christos static bfd_boolean
2130 1.1.1.2 christos sh_insn_uses_freg (unsigned int insn,
2131 1.1 christos const struct sh_opcode *op,
2132 1.1 christos unsigned int freg)
2133 1.1 christos {
2134 1.1 christos unsigned int f;
2135 1.1 christos
2136 1.1 christos f = op->flags;
2137 1.1 christos
2138 1.1 christos /* We can't tell if this is a double-precision insn, so just play safe
2139 1.1 christos and assume that it might be. So not only have we test FREG against
2140 1.1 christos itself, but also even FREG against FREG+1 - if the using insn uses
2141 1.1 christos just the low part of a double precision value - but also an odd
2142 1.1 christos FREG against FREG-1 - if the setting insn sets just the low part
2143 1.1 christos of a double precision value.
2144 1.1 christos So what this all boils down to is that we have to ignore the lowest
2145 1.1 christos bit of the register number. */
2146 1.1 christos
2147 1.1 christos if ((f & USESF1) != 0
2148 1.1 christos && (USESF1_REG (insn) & 0xe) == (freg & 0xe))
2149 1.1 christos return TRUE;
2150 1.1 christos if ((f & USESF2) != 0
2151 1.1 christos && (USESF2_REG (insn) & 0xe) == (freg & 0xe))
2152 1.1 christos return TRUE;
2153 1.1 christos if ((f & USESF0) != 0
2154 1.1 christos && freg == 0)
2155 1.1 christos return TRUE;
2156 1.1 christos
2157 1.1 christos return FALSE;
2158 1.1 christos }
2159 1.1 christos
2160 1.1 christos /* See whether an instruction sets a floating point register. */
2161 1.1.1.2 christos
2162 1.1.1.2 christos static bfd_boolean
2163 1.1.1.2 christos sh_insn_sets_freg (unsigned int insn,
2164 1.1 christos const struct sh_opcode *op,
2165 1.1 christos unsigned int freg)
2166 1.1 christos {
2167 1.1 christos unsigned int f;
2168 1.1 christos
2169 1.1 christos f = op->flags;
2170 1.1 christos
2171 1.1 christos /* We can't tell if this is a double-precision insn, so just play safe
2172 1.1 christos and assume that it might be. So not only have we test FREG against
2173 1.1 christos itself, but also even FREG against FREG+1 - if the using insn uses
2174 1.1 christos just the low part of a double precision value - but also an odd
2175 1.1 christos FREG against FREG-1 - if the setting insn sets just the low part
2176 1.1 christos of a double precision value.
2177 1.1 christos So what this all boils down to is that we have to ignore the lowest
2178 1.1 christos bit of the register number. */
2179 1.1 christos
2180 1.1 christos if ((f & SETSF1) != 0
2181 1.1 christos && (SETSF1_REG (insn) & 0xe) == (freg & 0xe))
2182 1.1 christos return TRUE;
2183 1.1 christos
2184 1.1 christos return FALSE;
2185 1.1.1.2 christos }
2186 1.1.1.2 christos
2187 1.1.1.2 christos /* See whether an instruction uses or sets a floating point register */
2188 1.1.1.2 christos
2189 1.1.1.2 christos static bfd_boolean
2190 1.1.1.2 christos sh_insn_uses_or_sets_freg (unsigned int insn,
2191 1.1.1.2 christos const struct sh_opcode *op,
2192 1.1.1.2 christos unsigned int reg)
2193 1.1.1.2 christos {
2194 1.1.1.2 christos if (sh_insn_uses_freg (insn, op, reg))
2195 1.1.1.2 christos return TRUE;
2196 1.1.1.2 christos
2197 1.1.1.2 christos return sh_insn_sets_freg (insn, op, reg);
2198 1.1 christos }
2199 1.1 christos
2200 1.1 christos /* See whether instructions I1 and I2 conflict, assuming I1 comes
2201 1.1 christos before I2. OP1 and OP2 are the corresponding sh_opcode structures.
2202 1.1 christos This should return TRUE if there is a conflict, or FALSE if the
2203 1.1 christos instructions can be swapped safely. */
2204 1.1.1.2 christos
2205 1.1.1.2 christos static bfd_boolean
2206 1.1.1.2 christos sh_insns_conflict (unsigned int i1,
2207 1.1.1.2 christos const struct sh_opcode *op1,
2208 1.1 christos unsigned int i2,
2209 1.1 christos const struct sh_opcode *op2)
2210 1.1 christos {
2211 1.1 christos unsigned int f1, f2;
2212 1.1 christos
2213 1.1 christos f1 = op1->flags;
2214 1.1 christos f2 = op2->flags;
2215 1.1 christos
2216 1.1 christos /* Load of fpscr conflicts with floating point operations.
2217 1.1 christos FIXME: shouldn't test raw opcodes here. */
2218 1.1 christos if (((i1 & 0xf0ff) == 0x4066 && (i2 & 0xf000) == 0xf000)
2219 1.1 christos || ((i2 & 0xf0ff) == 0x4066 && (i1 & 0xf000) == 0xf000))
2220 1.1 christos return TRUE;
2221 1.1 christos
2222 1.1 christos if ((f1 & (BRANCH | DELAY)) != 0
2223 1.1 christos || (f2 & (BRANCH | DELAY)) != 0)
2224 1.1 christos return TRUE;
2225 1.1 christos
2226 1.1 christos if (((f1 | f2) & SETSSP)
2227 1.1 christos && (f1 & (SETSSP | USESSP))
2228 1.1 christos && (f2 & (SETSSP | USESSP)))
2229 1.1 christos return TRUE;
2230 1.1 christos
2231 1.1 christos if ((f1 & SETS1) != 0
2232 1.1 christos && sh_insn_uses_or_sets_reg (i2, op2, SETS1_REG (i1)))
2233 1.1 christos return TRUE;
2234 1.1 christos if ((f1 & SETS2) != 0
2235 1.1 christos && sh_insn_uses_or_sets_reg (i2, op2, SETS2_REG (i1)))
2236 1.1 christos return TRUE;
2237 1.1 christos if ((f1 & SETSR0) != 0
2238 1.1 christos && sh_insn_uses_or_sets_reg (i2, op2, 0))
2239 1.1 christos return TRUE;
2240 1.1 christos if ((f1 & SETSAS)
2241 1.1 christos && sh_insn_uses_or_sets_reg (i2, op2, SETSAS_REG (i1)))
2242 1.1 christos return TRUE;
2243 1.1 christos if ((f1 & SETSF1) != 0
2244 1.1 christos && sh_insn_uses_or_sets_freg (i2, op2, SETSF1_REG (i1)))
2245 1.1 christos return TRUE;
2246 1.1 christos
2247 1.1 christos if ((f2 & SETS1) != 0
2248 1.1 christos && sh_insn_uses_or_sets_reg (i1, op1, SETS1_REG (i2)))
2249 1.1 christos return TRUE;
2250 1.1 christos if ((f2 & SETS2) != 0
2251 1.1 christos && sh_insn_uses_or_sets_reg (i1, op1, SETS2_REG (i2)))
2252 1.1 christos return TRUE;
2253 1.1 christos if ((f2 & SETSR0) != 0
2254 1.1 christos && sh_insn_uses_or_sets_reg (i1, op1, 0))
2255 1.1 christos return TRUE;
2256 1.1 christos if ((f2 & SETSAS)
2257 1.1 christos && sh_insn_uses_or_sets_reg (i1, op1, SETSAS_REG (i2)))
2258 1.1 christos return TRUE;
2259 1.1 christos if ((f2 & SETSF1) != 0
2260 1.1 christos && sh_insn_uses_or_sets_freg (i1, op1, SETSF1_REG (i2)))
2261 1.1 christos return TRUE;
2262 1.1 christos
2263 1.1 christos /* The instructions do not conflict. */
2264 1.1 christos return FALSE;
2265 1.1 christos }
2266 1.1 christos
2267 1.1 christos /* I1 is a load instruction, and I2 is some other instruction. Return
2268 1.1 christos TRUE if I1 loads a register which I2 uses. */
2269 1.1.1.2 christos
2270 1.1.1.2 christos static bfd_boolean
2271 1.1.1.2 christos sh_load_use (unsigned int i1,
2272 1.1.1.2 christos const struct sh_opcode *op1,
2273 1.1 christos unsigned int i2,
2274 1.1 christos const struct sh_opcode *op2)
2275 1.1 christos {
2276 1.1 christos unsigned int f1;
2277 1.1 christos
2278 1.1 christos f1 = op1->flags;
2279 1.1 christos
2280 1.1 christos if ((f1 & LOAD) == 0)
2281 1.1 christos return FALSE;
2282 1.1 christos
2283 1.1 christos /* If both SETS1 and SETSSP are set, that means a load to a special
2284 1.1 christos register using postincrement addressing mode, which we don't care
2285 1.1 christos about here. */
2286 1.1 christos if ((f1 & SETS1) != 0
2287 1.1 christos && (f1 & SETSSP) == 0
2288 1.1 christos && sh_insn_uses_reg (i2, op2, (i1 & 0x0f00) >> 8))
2289 1.1 christos return TRUE;
2290 1.1 christos
2291 1.1 christos if ((f1 & SETSR0) != 0
2292 1.1 christos && sh_insn_uses_reg (i2, op2, 0))
2293 1.1 christos return TRUE;
2294 1.1 christos
2295 1.1 christos if ((f1 & SETSF1) != 0
2296 1.1 christos && sh_insn_uses_freg (i2, op2, (i1 & 0x0f00) >> 8))
2297 1.1 christos return TRUE;
2298 1.1 christos
2299 1.1 christos return FALSE;
2300 1.1 christos }
2301 1.1 christos
2302 1.1 christos /* Try to align loads and stores within a span of memory. This is
2303 1.1 christos called by both the ELF and the COFF sh targets. ABFD and SEC are
2304 1.1 christos the BFD and section we are examining. CONTENTS is the contents of
2305 1.1 christos the section. SWAP is the routine to call to swap two instructions.
2306 1.1 christos RELOCS is a pointer to the internal relocation information, to be
2307 1.1 christos passed to SWAP. PLABEL is a pointer to the current label in a
2308 1.1 christos sorted list of labels; LABEL_END is the end of the list. START and
2309 1.1 christos STOP are the range of memory to examine. If a swap is made,
2310 1.1 christos *PSWAPPED is set to TRUE. */
2311 1.1 christos
2312 1.1 christos #ifdef COFF_WITH_PE
2313 1.1 christos static
2314 1.1.1.2 christos #endif
2315 1.1.1.2 christos bfd_boolean
2316 1.1.1.2 christos _bfd_sh_align_load_span (bfd *abfd,
2317 1.1.1.2 christos asection *sec,
2318 1.1.1.2 christos bfd_byte *contents,
2319 1.1.1.2 christos bfd_boolean (*swap) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
2320 1.1.1.2 christos void * relocs,
2321 1.1.1.2 christos bfd_vma **plabel,
2322 1.1.1.2 christos bfd_vma *label_end,
2323 1.1.1.2 christos bfd_vma start,
2324 1.1 christos bfd_vma stop,
2325 1.1 christos bfd_boolean *pswapped)
2326 1.1 christos {
2327 1.1 christos int dsp = (abfd->arch_info->mach == bfd_mach_sh_dsp
2328 1.1 christos || abfd->arch_info->mach == bfd_mach_sh3_dsp);
2329 1.1 christos bfd_vma i;
2330 1.1 christos
2331 1.1 christos /* The SH4 has a Harvard architecture, hence aligning loads is not
2332 1.1 christos desirable. In fact, it is counter-productive, since it interferes
2333 1.1 christos with the schedules generated by the compiler. */
2334 1.1 christos if (abfd->arch_info->mach == bfd_mach_sh4)
2335 1.1 christos return TRUE;
2336 1.1 christos
2337 1.1 christos /* If we are linking sh[3]-dsp code, swap the FPU instructions for DSP
2338 1.1 christos instructions. */
2339 1.1 christos if (dsp)
2340 1.1.1.4 christos {
2341 1.1 christos sh_opcodes[0xf].minor_opcodes = sh_dsp_opcodef;
2342 1.1 christos sh_opcodes[0xf].count = sizeof sh_dsp_opcodef / sizeof sh_dsp_opcodef [0];
2343 1.1 christos }
2344 1.1 christos
2345 1.1 christos /* Instructions should be aligned on 2 byte boundaries. */
2346 1.1 christos if ((start & 1) == 1)
2347 1.1 christos ++start;
2348 1.1 christos
2349 1.1 christos /* Now look through the unaligned addresses. */
2350 1.1 christos i = start;
2351 1.1 christos if ((i & 2) == 0)
2352 1.1 christos i += 2;
2353 1.1 christos for (; i < stop; i += 4)
2354 1.1 christos {
2355 1.1 christos unsigned int insn;
2356 1.1 christos const struct sh_opcode *op;
2357 1.1 christos unsigned int prev_insn = 0;
2358 1.1 christos const struct sh_opcode *prev_op = NULL;
2359 1.1 christos
2360 1.1 christos insn = bfd_get_16 (abfd, contents + i);
2361 1.1 christos op = sh_insn_info (insn);
2362 1.1 christos if (op == NULL
2363 1.1 christos || (op->flags & (LOAD | STORE)) == 0)
2364 1.1 christos continue;
2365 1.1 christos
2366 1.1 christos /* This is a load or store which is not on a four byte boundary. */
2367 1.1 christos
2368 1.1 christos while (*plabel < label_end && **plabel < i)
2369 1.1 christos ++*plabel;
2370 1.1 christos
2371 1.1 christos if (i > start)
2372 1.1 christos {
2373 1.1 christos prev_insn = bfd_get_16 (abfd, contents + i - 2);
2374 1.1 christos /* If INSN is the field b of a parallel processing insn, it is not
2375 1.1 christos a load / store after all. Note that the test here might mistake
2376 1.1 christos the field_b of a pcopy insn for the starting code of a parallel
2377 1.1 christos processing insn; this might miss a swapping opportunity, but at
2378 1.1 christos least we're on the safe side. */
2379 1.1 christos if (dsp && (prev_insn & 0xfc00) == 0xf800)
2380 1.1 christos continue;
2381 1.1 christos
2382 1.1 christos /* Check if prev_insn is actually the field b of a parallel
2383 1.1 christos processing insn. Again, this can give a spurious match
2384 1.1 christos after a pcopy. */
2385 1.1 christos if (dsp && i - 2 > start)
2386 1.1 christos {
2387 1.1 christos unsigned pprev_insn = bfd_get_16 (abfd, contents + i - 4);
2388 1.1 christos
2389 1.1 christos if ((pprev_insn & 0xfc00) == 0xf800)
2390 1.1 christos prev_op = NULL;
2391 1.1 christos else
2392 1.1 christos prev_op = sh_insn_info (prev_insn);
2393 1.1 christos }
2394 1.1 christos else
2395 1.1 christos prev_op = sh_insn_info (prev_insn);
2396 1.1 christos
2397 1.1 christos /* If the load/store instruction is in a delay slot, we
2398 1.1 christos can't swap. */
2399 1.1 christos if (prev_op == NULL
2400 1.1 christos || (prev_op->flags & DELAY) != 0)
2401 1.1 christos continue;
2402 1.1 christos }
2403 1.1 christos if (i > start
2404 1.1 christos && (*plabel >= label_end || **plabel != i)
2405 1.1 christos && prev_op != NULL
2406 1.1 christos && (prev_op->flags & (LOAD | STORE)) == 0
2407 1.1 christos && ! sh_insns_conflict (prev_insn, prev_op, insn, op))
2408 1.1 christos {
2409 1.1 christos bfd_boolean ok;
2410 1.1 christos
2411 1.1 christos /* The load/store instruction does not have a label, and
2412 1.1 christos there is a previous instruction; PREV_INSN is not
2413 1.1 christos itself a load/store instruction, and PREV_INSN and
2414 1.1 christos INSN do not conflict. */
2415 1.1 christos
2416 1.1 christos ok = TRUE;
2417 1.1 christos
2418 1.1 christos if (i >= start + 4)
2419 1.1 christos {
2420 1.1 christos unsigned int prev2_insn;
2421 1.1 christos const struct sh_opcode *prev2_op;
2422 1.1 christos
2423 1.1 christos prev2_insn = bfd_get_16 (abfd, contents + i - 4);
2424 1.1 christos prev2_op = sh_insn_info (prev2_insn);
2425 1.1 christos
2426 1.1 christos /* If the instruction before PREV_INSN has a delay
2427 1.1 christos slot--that is, PREV_INSN is in a delay slot--we
2428 1.1 christos can not swap. */
2429 1.1 christos if (prev2_op == NULL
2430 1.1 christos || (prev2_op->flags & DELAY) != 0)
2431 1.1 christos ok = FALSE;
2432 1.1 christos
2433 1.1 christos /* If the instruction before PREV_INSN is a load,
2434 1.1 christos and it sets a register which INSN uses, then
2435 1.1 christos putting INSN immediately after PREV_INSN will
2436 1.1 christos cause a pipeline bubble, so there is no point to
2437 1.1 christos making the swap. */
2438 1.1 christos if (ok
2439 1.1 christos && (prev2_op->flags & LOAD) != 0
2440 1.1 christos && sh_load_use (prev2_insn, prev2_op, insn, op))
2441 1.1 christos ok = FALSE;
2442 1.1 christos }
2443 1.1 christos
2444 1.1 christos if (ok)
2445 1.1 christos {
2446 1.1 christos if (! (*swap) (abfd, sec, relocs, contents, i - 2))
2447 1.1 christos return FALSE;
2448 1.1 christos *pswapped = TRUE;
2449 1.1 christos continue;
2450 1.1 christos }
2451 1.1 christos }
2452 1.1 christos
2453 1.1 christos while (*plabel < label_end && **plabel < i + 2)
2454 1.1 christos ++*plabel;
2455 1.1 christos
2456 1.1 christos if (i + 2 < stop
2457 1.1 christos && (*plabel >= label_end || **plabel != i + 2))
2458 1.1 christos {
2459 1.1 christos unsigned int next_insn;
2460 1.1 christos const struct sh_opcode *next_op;
2461 1.1 christos
2462 1.1 christos /* There is an instruction after the load/store
2463 1.1 christos instruction, and it does not have a label. */
2464 1.1 christos next_insn = bfd_get_16 (abfd, contents + i + 2);
2465 1.1 christos next_op = sh_insn_info (next_insn);
2466 1.1 christos if (next_op != NULL
2467 1.1 christos && (next_op->flags & (LOAD | STORE)) == 0
2468 1.1 christos && ! sh_insns_conflict (insn, op, next_insn, next_op))
2469 1.1 christos {
2470 1.1 christos bfd_boolean ok;
2471 1.1 christos
2472 1.1 christos /* NEXT_INSN is not itself a load/store instruction,
2473 1.1 christos and it does not conflict with INSN. */
2474 1.1 christos
2475 1.1 christos ok = TRUE;
2476 1.1 christos
2477 1.1 christos /* If PREV_INSN is a load, and it sets a register
2478 1.1 christos which NEXT_INSN uses, then putting NEXT_INSN
2479 1.1 christos immediately after PREV_INSN will cause a pipeline
2480 1.1 christos bubble, so there is no reason to make this swap. */
2481 1.1 christos if (prev_op != NULL
2482 1.1 christos && (prev_op->flags & LOAD) != 0
2483 1.1 christos && sh_load_use (prev_insn, prev_op, next_insn, next_op))
2484 1.1 christos ok = FALSE;
2485 1.1 christos
2486 1.1 christos /* If INSN is a load, and it sets a register which
2487 1.1 christos the insn after NEXT_INSN uses, then doing the
2488 1.1 christos swap will cause a pipeline bubble, so there is no
2489 1.1 christos reason to make the swap. However, if the insn
2490 1.1 christos after NEXT_INSN is itself a load or store
2491 1.1 christos instruction, then it is misaligned, so
2492 1.1 christos optimistically hope that it will be swapped
2493 1.1 christos itself, and just live with the pipeline bubble if
2494 1.1 christos it isn't. */
2495 1.1 christos if (ok
2496 1.1 christos && i + 4 < stop
2497 1.1 christos && (op->flags & LOAD) != 0)
2498 1.1 christos {
2499 1.1 christos unsigned int next2_insn;
2500 1.1 christos const struct sh_opcode *next2_op;
2501 1.1 christos
2502 1.1 christos next2_insn = bfd_get_16 (abfd, contents + i + 4);
2503 1.1 christos next2_op = sh_insn_info (next2_insn);
2504 1.1 christos if (next2_op == NULL
2505 1.1 christos || ((next2_op->flags & (LOAD | STORE)) == 0
2506 1.1 christos && sh_load_use (insn, op, next2_insn, next2_op)))
2507 1.1 christos ok = FALSE;
2508 1.1 christos }
2509 1.1 christos
2510 1.1 christos if (ok)
2511 1.1 christos {
2512 1.1 christos if (! (*swap) (abfd, sec, relocs, contents, i))
2513 1.1 christos return FALSE;
2514 1.1 christos *pswapped = TRUE;
2515 1.1 christos continue;
2516 1.1 christos }
2517 1.1 christos }
2518 1.1 christos }
2519 1.1 christos }
2520 1.1 christos
2521 1.1 christos return TRUE;
2522 1.1 christos }
2523 1.1 christos #endif /* not COFF_IMAGE_WITH_PE */
2524 1.1 christos
2525 1.1 christos /* Swap two SH instructions. */
2526 1.1.1.2 christos
2527 1.1.1.2 christos static bfd_boolean
2528 1.1.1.2 christos sh_swap_insns (bfd * abfd,
2529 1.1.1.2 christos asection * sec,
2530 1.1.1.2 christos void * relocs,
2531 1.1 christos bfd_byte * contents,
2532 1.1 christos bfd_vma addr)
2533 1.1 christos {
2534 1.1 christos struct internal_reloc *internal_relocs = (struct internal_reloc *) relocs;
2535 1.1 christos unsigned short i1, i2;
2536 1.1 christos struct internal_reloc *irel, *irelend;
2537 1.1 christos
2538 1.1 christos /* Swap the instructions themselves. */
2539 1.1 christos i1 = bfd_get_16 (abfd, contents + addr);
2540 1.1 christos i2 = bfd_get_16 (abfd, contents + addr + 2);
2541 1.1 christos bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
2542 1.1 christos bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
2543 1.1 christos
2544 1.1 christos /* Adjust all reloc addresses. */
2545 1.1 christos irelend = internal_relocs + sec->reloc_count;
2546 1.1 christos for (irel = internal_relocs; irel < irelend; irel++)
2547 1.1 christos {
2548 1.1 christos int type, add;
2549 1.1.1.6 christos
2550 1.1.1.6 christos /* There are a few special types of relocs that we don't want to
2551 1.1 christos adjust. These relocs do not apply to the instruction itself,
2552 1.1 christos but are only associated with the address. */
2553 1.1 christos type = irel->r_type;
2554 1.1 christos if (type == R_SH_ALIGN
2555 1.1 christos || type == R_SH_CODE
2556 1.1 christos || type == R_SH_DATA
2557 1.1 christos || type == R_SH_LABEL)
2558 1.1 christos continue;
2559 1.1.1.6 christos
2560 1.1.1.6 christos /* If an R_SH_USES reloc points to one of the addresses being
2561 1.1.1.6 christos swapped, we must adjust it. It would be incorrect to do this
2562 1.1.1.6 christos for a jump, though, since we want to execute both
2563 1.1.1.6 christos instructions after the jump. (We have avoided swapping
2564 1.1 christos around a label, so the jump will not wind up executing an
2565 1.1 christos instruction it shouldn't). */
2566 1.1 christos if (type == R_SH_USES)
2567 1.1 christos {
2568 1.1 christos bfd_vma off;
2569 1.1 christos
2570 1.1 christos off = irel->r_vaddr - sec->vma + 4 + irel->r_offset;
2571 1.1 christos if (off == addr)
2572 1.1 christos irel->r_offset += 2;
2573 1.1 christos else if (off == addr + 2)
2574 1.1 christos irel->r_offset -= 2;
2575 1.1 christos }
2576 1.1 christos
2577 1.1 christos if (irel->r_vaddr - sec->vma == addr)
2578 1.1 christos {
2579 1.1 christos irel->r_vaddr += 2;
2580 1.1 christos add = -2;
2581 1.1 christos }
2582 1.1 christos else if (irel->r_vaddr - sec->vma == addr + 2)
2583 1.1 christos {
2584 1.1 christos irel->r_vaddr -= 2;
2585 1.1 christos add = 2;
2586 1.1 christos }
2587 1.1 christos else
2588 1.1 christos add = 0;
2589 1.1 christos
2590 1.1 christos if (add != 0)
2591 1.1 christos {
2592 1.1 christos bfd_byte *loc;
2593 1.1 christos unsigned short insn, oinsn;
2594 1.1 christos bfd_boolean overflow;
2595 1.1 christos
2596 1.1 christos loc = contents + irel->r_vaddr - sec->vma;
2597 1.1 christos overflow = FALSE;
2598 1.1 christos switch (type)
2599 1.1 christos {
2600 1.1 christos default:
2601 1.1 christos break;
2602 1.1 christos
2603 1.1 christos case R_SH_PCDISP8BY2:
2604 1.1 christos case R_SH_PCRELIMM8BY2:
2605 1.1 christos insn = bfd_get_16 (abfd, loc);
2606 1.1 christos oinsn = insn;
2607 1.1 christos insn += add / 2;
2608 1.1 christos if ((oinsn & 0xff00) != (insn & 0xff00))
2609 1.1 christos overflow = TRUE;
2610 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, loc);
2611 1.1 christos break;
2612 1.1 christos
2613 1.1 christos case R_SH_PCDISP:
2614 1.1 christos insn = bfd_get_16 (abfd, loc);
2615 1.1 christos oinsn = insn;
2616 1.1 christos insn += add / 2;
2617 1.1 christos if ((oinsn & 0xf000) != (insn & 0xf000))
2618 1.1 christos overflow = TRUE;
2619 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, loc);
2620 1.1 christos break;
2621 1.1 christos
2622 1.1.1.6 christos case R_SH_PCRELIMM8BY4:
2623 1.1.1.6 christos /* This reloc ignores the least significant 3 bits of
2624 1.1.1.6 christos the program counter before adding in the offset.
2625 1.1.1.6 christos This means that if ADDR is at an even address, the
2626 1.1.1.6 christos swap will not affect the offset. If ADDR is an at an
2627 1.1 christos odd address, then the instruction will be crossing a
2628 1.1 christos four byte boundary, and must be adjusted. */
2629 1.1 christos if ((addr & 3) != 0)
2630 1.1 christos {
2631 1.1 christos insn = bfd_get_16 (abfd, loc);
2632 1.1 christos oinsn = insn;
2633 1.1 christos insn += add / 2;
2634 1.1 christos if ((oinsn & 0xff00) != (insn & 0xff00))
2635 1.1 christos overflow = TRUE;
2636 1.1 christos bfd_put_16 (abfd, (bfd_vma) insn, loc);
2637 1.1 christos }
2638 1.1 christos
2639 1.1 christos break;
2640 1.1 christos }
2641 1.1 christos
2642 1.1.1.5 christos if (overflow)
2643 1.1.1.5 christos {
2644 1.1.1.6 christos _bfd_error_handler
2645 1.1.1.6 christos /* xgettext: c-format */
2646 1.1 christos (_("%pB: %#" PRIx64 ": fatal: reloc overflow while relaxing"),
2647 1.1 christos abfd, (uint64_t) irel->r_vaddr);
2648 1.1 christos bfd_set_error (bfd_error_bad_value);
2649 1.1 christos return FALSE;
2650 1.1 christos }
2651 1.1 christos }
2652 1.1 christos }
2653 1.1 christos
2654 1.1.1.2 christos return TRUE;
2655 1.1.1.2 christos }
2656 1.1.1.2 christos
2657 1.1.1.2 christos /* Look for loads and stores which we can align to four byte
2658 1.1.1.2 christos boundaries. See the longer comment above sh_relax_section for why
2659 1.1.1.2 christos this is desirable. This sets *PSWAPPED if some instruction was
2660 1.1.1.2 christos swapped. */
2661 1.1.1.2 christos
2662 1.1.1.2 christos static bfd_boolean
2663 1.1.1.2 christos sh_align_loads (bfd *abfd,
2664 1.1.1.2 christos asection *sec,
2665 1.1.1.2 christos struct internal_reloc *internal_relocs,
2666 1.1.1.2 christos bfd_byte *contents,
2667 1.1.1.2 christos bfd_boolean *pswapped)
2668 1.1.1.2 christos {
2669 1.1.1.2 christos struct internal_reloc *irel, *irelend;
2670 1.1.1.2 christos bfd_vma *labels = NULL;
2671 1.1.1.2 christos bfd_vma *label, *label_end;
2672 1.1.1.2 christos bfd_size_type amt;
2673 1.1.1.2 christos
2674 1.1.1.2 christos *pswapped = FALSE;
2675 1.1.1.2 christos
2676 1.1.1.2 christos irelend = internal_relocs + sec->reloc_count;
2677 1.1.1.2 christos
2678 1.1.1.2 christos /* Get all the addresses with labels on them. */
2679 1.1.1.2 christos amt = (bfd_size_type) sec->reloc_count * sizeof (bfd_vma);
2680 1.1.1.2 christos labels = (bfd_vma *) bfd_malloc (amt);
2681 1.1.1.2 christos if (labels == NULL)
2682 1.1.1.2 christos goto error_return;
2683 1.1.1.2 christos label_end = labels;
2684 1.1.1.2 christos for (irel = internal_relocs; irel < irelend; irel++)
2685 1.1.1.2 christos {
2686 1.1.1.2 christos if (irel->r_type == R_SH_LABEL)
2687 1.1.1.2 christos {
2688 1.1.1.2 christos *label_end = irel->r_vaddr - sec->vma;
2689 1.1.1.2 christos ++label_end;
2690 1.1.1.2 christos }
2691 1.1.1.2 christos }
2692 1.1.1.2 christos
2693 1.1.1.2 christos /* Note that the assembler currently always outputs relocs in
2694 1.1.1.2 christos address order. If that ever changes, this code will need to sort
2695 1.1.1.2 christos the label values and the relocs. */
2696 1.1.1.2 christos
2697 1.1.1.2 christos label = labels;
2698 1.1.1.2 christos
2699 1.1.1.2 christos for (irel = internal_relocs; irel < irelend; irel++)
2700 1.1.1.2 christos {
2701 1.1.1.2 christos bfd_vma start, stop;
2702 1.1.1.2 christos
2703 1.1.1.2 christos if (irel->r_type != R_SH_CODE)
2704 1.1.1.2 christos continue;
2705 1.1.1.2 christos
2706 1.1.1.2 christos start = irel->r_vaddr - sec->vma;
2707 1.1.1.2 christos
2708 1.1.1.2 christos for (irel++; irel < irelend; irel++)
2709 1.1.1.2 christos if (irel->r_type == R_SH_DATA)
2710 1.1.1.2 christos break;
2711 1.1.1.2 christos if (irel < irelend)
2712 1.1.1.2 christos stop = irel->r_vaddr - sec->vma;
2713 1.1.1.2 christos else
2714 1.1.1.2 christos stop = sec->size;
2715 1.1.1.2 christos
2716 1.1.1.2 christos if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_swap_insns,
2717 1.1.1.2 christos internal_relocs, &label,
2718 1.1.1.2 christos label_end, start, stop, pswapped))
2719 1.1.1.2 christos goto error_return;
2720 1.1.1.2 christos }
2721 1.1.1.2 christos
2722 1.1.1.2 christos free (labels);
2723 1.1.1.2 christos
2724 1.1.1.2 christos return TRUE;
2725 1.1.1.7 christos
2726 1.1.1.2 christos error_return:
2727 1.1.1.2 christos free (labels);
2728 1.1 christos return FALSE;
2729 1.1 christos }
2730 1.1 christos
2731 1.1 christos /* This is a modification of _bfd_coff_generic_relocate_section, which
2733 1.1.1.2 christos will handle SH relaxing. */
2734 1.1.1.2 christos
2735 1.1.1.2 christos static bfd_boolean
2736 1.1.1.2 christos sh_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
2737 1.1.1.2 christos struct bfd_link_info *info,
2738 1.1.1.2 christos bfd *input_bfd,
2739 1.1.1.2 christos asection *input_section,
2740 1.1.1.2 christos bfd_byte *contents,
2741 1.1 christos struct internal_reloc *relocs,
2742 1.1 christos struct internal_syment *syms,
2743 1.1 christos asection **sections)
2744 1.1 christos {
2745 1.1 christos struct internal_reloc *rel;
2746 1.1 christos struct internal_reloc *relend;
2747 1.1 christos
2748 1.1 christos rel = relocs;
2749 1.1 christos relend = rel + input_section->reloc_count;
2750 1.1 christos for (; rel < relend; rel++)
2751 1.1 christos {
2752 1.1 christos long symndx;
2753 1.1 christos struct coff_link_hash_entry *h;
2754 1.1 christos struct internal_syment *sym;
2755 1.1 christos bfd_vma addend;
2756 1.1 christos bfd_vma val;
2757 1.1 christos reloc_howto_type *howto;
2758 1.1.1.6 christos bfd_reloc_status_type rstat;
2759 1.1 christos
2760 1.1 christos /* Almost all relocs have to do with relaxing. If any work must
2761 1.1 christos be done for them, it has been done in sh_relax_section. */
2762 1.1 christos if (rel->r_type != R_SH_IMM32
2763 1.1 christos #ifdef COFF_WITH_PE
2764 1.1 christos && rel->r_type != R_SH_IMM32CE
2765 1.1 christos && rel->r_type != R_SH_IMAGEBASE
2766 1.1 christos #endif
2767 1.1 christos && rel->r_type != R_SH_PCDISP)
2768 1.1 christos continue;
2769 1.1 christos
2770 1.1 christos symndx = rel->r_symndx;
2771 1.1 christos
2772 1.1 christos if (symndx == -1)
2773 1.1 christos {
2774 1.1 christos h = NULL;
2775 1.1 christos sym = NULL;
2776 1.1 christos }
2777 1.1 christos else
2778 1.1 christos {
2779 1.1.1.5 christos if (symndx < 0
2780 1.1.1.5 christos || (unsigned long) symndx >= obj_raw_syment_count (input_bfd))
2781 1.1.1.6 christos {
2782 1.1 christos _bfd_error_handler
2783 1.1 christos /* xgettext: c-format */
2784 1.1 christos (_("%pB: illegal symbol index %ld in relocs"),
2785 1.1 christos input_bfd, symndx);
2786 1.1 christos bfd_set_error (bfd_error_bad_value);
2787 1.1 christos return FALSE;
2788 1.1 christos }
2789 1.1 christos h = obj_coff_sym_hashes (input_bfd)[symndx];
2790 1.1 christos sym = syms + symndx;
2791 1.1 christos }
2792 1.1 christos
2793 1.1 christos if (sym != NULL && sym->n_scnum != 0)
2794 1.1 christos addend = - sym->n_value;
2795 1.1 christos else
2796 1.1 christos addend = 0;
2797 1.1 christos
2798 1.1 christos if (rel->r_type == R_SH_PCDISP)
2799 1.1 christos addend -= 4;
2800 1.1 christos
2801 1.1 christos if (rel->r_type >= SH_COFF_HOWTO_COUNT)
2802 1.1 christos howto = NULL;
2803 1.1 christos else
2804 1.1 christos howto = &sh_coff_howtos[rel->r_type];
2805 1.1 christos
2806 1.1 christos if (howto == NULL)
2807 1.1 christos {
2808 1.1 christos bfd_set_error (bfd_error_bad_value);
2809 1.1 christos return FALSE;
2810 1.1 christos }
2811 1.1 christos
2812 1.1 christos #ifdef COFF_WITH_PE
2813 1.1 christos if (rel->r_type == R_SH_IMAGEBASE)
2814 1.1 christos addend -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase;
2815 1.1 christos #endif
2816 1.1 christos
2817 1.1 christos val = 0;
2818 1.1 christos
2819 1.1 christos if (h == NULL)
2820 1.1 christos {
2821 1.1 christos asection *sec;
2822 1.1 christos
2823 1.1 christos /* There is nothing to do for an internal PCDISP reloc. */
2824 1.1 christos if (rel->r_type == R_SH_PCDISP)
2825 1.1 christos continue;
2826 1.1 christos
2827 1.1 christos if (symndx == -1)
2828 1.1 christos {
2829 1.1 christos sec = bfd_abs_section_ptr;
2830 1.1 christos val = 0;
2831 1.1 christos }
2832 1.1.1.6 christos else
2833 1.1 christos {
2834 1.1 christos sec = sections[symndx];
2835 1.1 christos val = (sec->output_section->vma
2836 1.1 christos + sec->output_offset
2837 1.1 christos + sym->n_value
2838 1.1 christos - sec->vma);
2839 1.1 christos }
2840 1.1 christos }
2841 1.1 christos else
2842 1.1 christos {
2843 1.1 christos if (h->root.type == bfd_link_hash_defined
2844 1.1 christos || h->root.type == bfd_link_hash_defweak)
2845 1.1 christos {
2846 1.1 christos asection *sec;
2847 1.1 christos
2848 1.1 christos sec = h->root.u.def.section;
2849 1.1 christos val = (h->root.u.def.value
2850 1.1.1.4 christos + sec->output_section->vma
2851 1.1.1.4 christos + sec->output_offset);
2852 1.1.1.4 christos }
2853 1.1.1.4 christos else if (! bfd_link_relocatable (info))
2854 1.1 christos (*info->callbacks->undefined_symbol)
2855 1.1 christos (info, h->root.root.string, input_bfd, input_section,
2856 1.1 christos rel->r_vaddr - input_section->vma, TRUE);
2857 1.1 christos }
2858 1.1 christos
2859 1.1 christos rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
2860 1.1 christos contents,
2861 1.1 christos rel->r_vaddr - input_section->vma,
2862 1.1 christos val, addend);
2863 1.1 christos
2864 1.1 christos switch (rstat)
2865 1.1 christos {
2866 1.1 christos default:
2867 1.1 christos abort ();
2868 1.1 christos case bfd_reloc_ok:
2869 1.1 christos break;
2870 1.1 christos case bfd_reloc_overflow:
2871 1.1 christos {
2872 1.1 christos const char *name;
2873 1.1 christos char buf[SYMNMLEN + 1];
2874 1.1 christos
2875 1.1 christos if (symndx == -1)
2876 1.1 christos name = "*ABS*";
2877 1.1 christos else if (h != NULL)
2878 1.1 christos name = NULL;
2879 1.1 christos else if (sym->_n._n_n._n_zeroes == 0
2880 1.1 christos && sym->_n._n_n._n_offset != 0)
2881 1.1.1.6 christos name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset;
2882 1.1 christos else
2883 1.1 christos {
2884 1.1 christos strncpy (buf, sym->_n._n_name, SYMNMLEN);
2885 1.1 christos buf[SYMNMLEN] = '\0';
2886 1.1.1.4 christos name = buf;
2887 1.1.1.4 christos }
2888 1.1.1.4 christos
2889 1.1.1.4 christos (*info->callbacks->reloc_overflow)
2890 1.1 christos (info, (h ? &h->root : NULL), name, howto->name,
2891 1.1 christos (bfd_vma) 0, input_bfd, input_section,
2892 1.1 christos rel->r_vaddr - input_section->vma);
2893 1.1 christos }
2894 1.1 christos }
2895 1.1 christos }
2896 1.1 christos
2897 1.1 christos return TRUE;
2898 1.1 christos }
2899 1.1 christos
2900 1.1 christos /* This is a version of bfd_generic_get_relocated_section_contents
2901 1.1.1.2 christos which uses sh_relocate_section. */
2902 1.1.1.2 christos
2903 1.1.1.2 christos static bfd_byte *
2904 1.1.1.2 christos sh_coff_get_relocated_section_contents (bfd *output_bfd,
2905 1.1.1.2 christos struct bfd_link_info *link_info,
2906 1.1.1.2 christos struct bfd_link_order *link_order,
2907 1.1 christos bfd_byte *data,
2908 1.1 christos bfd_boolean relocatable,
2909 1.1 christos asymbol **symbols)
2910 1.1 christos {
2911 1.1 christos asection *input_section = link_order->u.indirect.section;
2912 1.1 christos bfd *input_bfd = input_section->owner;
2913 1.1 christos asection **sections = NULL;
2914 1.1 christos struct internal_reloc *internal_relocs = NULL;
2915 1.1 christos struct internal_syment *internal_syms = NULL;
2916 1.1 christos
2917 1.1 christos /* We only need to handle the case of relaxing, or of having a
2918 1.1 christos particular set of section contents, specially. */
2919 1.1 christos if (relocatable
2920 1.1 christos || coff_section_data (input_bfd, input_section) == NULL
2921 1.1 christos || coff_section_data (input_bfd, input_section)->contents == NULL)
2922 1.1 christos return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
2923 1.1 christos link_order, data,
2924 1.1 christos relocatable,
2925 1.1 christos symbols);
2926 1.1 christos
2927 1.1 christos memcpy (data, coff_section_data (input_bfd, input_section)->contents,
2928 1.1 christos (size_t) input_section->size);
2929 1.1 christos
2930 1.1 christos if ((input_section->flags & SEC_RELOC) != 0
2931 1.1 christos && input_section->reloc_count > 0)
2932 1.1 christos {
2933 1.1 christos bfd_size_type symesz = bfd_coff_symesz (input_bfd);
2934 1.1 christos bfd_byte *esym, *esymend;
2935 1.1 christos struct internal_syment *isymp;
2936 1.1 christos asection **secpp;
2937 1.1 christos bfd_size_type amt;
2938 1.1 christos
2939 1.1 christos if (! _bfd_coff_get_external_symbols (input_bfd))
2940 1.1 christos goto error_return;
2941 1.1 christos
2942 1.1 christos internal_relocs = (_bfd_coff_read_internal_relocs
2943 1.1 christos (input_bfd, input_section, FALSE, (bfd_byte *) NULL,
2944 1.1 christos FALSE, (struct internal_reloc *) NULL));
2945 1.1 christos if (internal_relocs == NULL)
2946 1.1 christos goto error_return;
2947 1.1 christos
2948 1.1 christos amt = obj_raw_syment_count (input_bfd);
2949 1.1 christos amt *= sizeof (struct internal_syment);
2950 1.1 christos internal_syms = (struct internal_syment *) bfd_malloc (amt);
2951 1.1 christos if (internal_syms == NULL)
2952 1.1 christos goto error_return;
2953 1.1 christos
2954 1.1 christos amt = obj_raw_syment_count (input_bfd);
2955 1.1 christos amt *= sizeof (asection *);
2956 1.1 christos sections = (asection **) bfd_malloc (amt);
2957 1.1 christos if (sections == NULL)
2958 1.1 christos goto error_return;
2959 1.1 christos
2960 1.1 christos isymp = internal_syms;
2961 1.1 christos secpp = sections;
2962 1.1 christos esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
2963 1.1.1.2 christos esymend = esym + obj_raw_syment_count (input_bfd) * symesz;
2964 1.1 christos while (esym < esymend)
2965 1.1 christos {
2966 1.1 christos bfd_coff_swap_sym_in (input_bfd, esym, isymp);
2967 1.1 christos
2968 1.1 christos if (isymp->n_scnum != 0)
2969 1.1 christos *secpp = coff_section_from_bfd_index (input_bfd, isymp->n_scnum);
2970 1.1 christos else
2971 1.1 christos {
2972 1.1 christos if (isymp->n_value == 0)
2973 1.1 christos *secpp = bfd_und_section_ptr;
2974 1.1 christos else
2975 1.1 christos *secpp = bfd_com_section_ptr;
2976 1.1 christos }
2977 1.1 christos
2978 1.1 christos esym += (isymp->n_numaux + 1) * symesz;
2979 1.1 christos secpp += isymp->n_numaux + 1;
2980 1.1 christos isymp += isymp->n_numaux + 1;
2981 1.1 christos }
2982 1.1 christos
2983 1.1 christos if (! sh_relocate_section (output_bfd, link_info, input_bfd,
2984 1.1 christos input_section, data, internal_relocs,
2985 1.1 christos internal_syms, sections))
2986 1.1 christos goto error_return;
2987 1.1 christos
2988 1.1 christos free (sections);
2989 1.1 christos sections = NULL;
2990 1.1 christos free (internal_syms);
2991 1.1 christos internal_syms = NULL;
2992 1.1 christos free (internal_relocs);
2993 1.1 christos internal_relocs = NULL;
2994 1.1 christos }
2995 1.1 christos
2996 1.1.1.7 christos return data;
2997 1.1.1.7 christos
2998 1.1.1.7 christos error_return:
2999 1.1 christos free (internal_relocs);
3000 1.1 christos free (internal_syms);
3001 1.1 christos free (sections);
3002 1.1 christos return NULL;
3003 1.1 christos }
3004 1.1 christos
3005 1.1.1.3 christos /* The target vectors. */
3006 1.1 christos
3007 1.1 christos #ifndef TARGET_SHL_SYM
3008 1.1 christos CREATE_BIG_COFF_TARGET_VEC (sh_coff_vec, "coff-sh", BFD_IS_RELAXABLE, 0, '_', NULL, COFF_SWAP_TABLE)
3009 1.1 christos #endif
3010 1.1 christos
3011 1.1.1.3 christos #ifdef TARGET_SHL_SYM
3012 1.1 christos #define TARGET_SYM TARGET_SHL_SYM
3013 1.1 christos #else
3014 1.1 christos #define TARGET_SYM sh_coff_le_vec
3015 1.1 christos #endif
3016 1.1 christos
3017 1.1 christos #ifndef TARGET_SHL_NAME
3018 1.1 christos #define TARGET_SHL_NAME "coff-shl"
3019 1.1 christos #endif
3020 1.1 christos
3021 1.1 christos #ifdef COFF_WITH_PE
3022 1.1 christos CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
3023 1.1 christos SEC_CODE | SEC_DATA, '_', NULL, COFF_SWAP_TABLE);
3024 1.1 christos #else
3025 1.1 christos CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
3026 1.1 christos 0, '_', NULL, COFF_SWAP_TABLE)
3027 1.1.1.2 christos #endif
3028 1.1 christos
3029 1.1 christos #ifndef TARGET_SHL_SYM
3030 1.1 christos
3031 1.1 christos /* Some people want versions of the SH COFF target which do not align
3032 1.1 christos to 16 byte boundaries. We implement that by adding a couple of new
3033 1.1 christos target vectors. These are just like the ones above, but they
3034 1.1 christos change the default section alignment. To generate them in the
3035 1.1 christos assembler, use -small. To use them in the linker, use -b
3036 1.1 christos coff-sh{l}-small and -oformat coff-sh{l}-small.
3037 1.1 christos
3038 1.1 christos Yes, this is a horrible hack. A general solution for setting
3039 1.1 christos section alignment in COFF is rather complex. ELF handles this
3040 1.1 christos correctly. */
3041 1.1 christos
3042 1.1.1.7 christos /* Only recognize the small versions if the target was not defaulted.
3043 1.1.1.2 christos Otherwise we won't recognize the non default endianness. */
3044 1.1 christos
3045 1.1 christos static bfd_cleanup
3046 1.1 christos coff_small_object_p (bfd *abfd)
3047 1.1 christos {
3048 1.1 christos if (abfd->target_defaulted)
3049 1.1 christos {
3050 1.1 christos bfd_set_error (bfd_error_wrong_format);
3051 1.1 christos return NULL;
3052 1.1 christos }
3053 1.1 christos return coff_object_p (abfd);
3054 1.1 christos }
3055 1.1 christos
3056 1.1.1.2 christos /* Set the section alignment for the small versions. */
3057 1.1 christos
3058 1.1 christos static bfd_boolean
3059 1.1 christos coff_small_new_section_hook (bfd *abfd, asection *section)
3060 1.1 christos {
3061 1.1 christos if (! coff_new_section_hook (abfd, section))
3062 1.1 christos return FALSE;
3063 1.1 christos
3064 1.1 christos /* We must align to at least a four byte boundary, because longword
3065 1.1 christos accesses must be on a four byte boundary. */
3066 1.1 christos if (section->alignment_power == COFF_DEFAULT_SECTION_ALIGNMENT_POWER)
3067 1.1 christos section->alignment_power = 2;
3068 1.1 christos
3069 1.1 christos return TRUE;
3070 1.1 christos }
3071 1.1 christos
3072 1.1 christos /* This is copied from bfd_coff_std_swap_table so that we can change
3073 1.1 christos the default section alignment power. */
3074 1.1 christos
3075 1.1 christos static bfd_coff_backend_data bfd_coff_small_swap_table =
3076 1.1 christos {
3077 1.1 christos coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in,
3078 1.1 christos coff_swap_aux_out, coff_swap_sym_out,
3079 1.1 christos coff_swap_lineno_out, coff_swap_reloc_out,
3080 1.1 christos coff_swap_filehdr_out, coff_swap_aouthdr_out,
3081 1.1 christos coff_swap_scnhdr_out,
3082 1.1 christos FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
3083 1.1 christos #ifdef COFF_LONG_FILENAMES
3084 1.1 christos TRUE,
3085 1.1 christos #else
3086 1.1 christos FALSE,
3087 1.1 christos #endif
3088 1.1 christos COFF_DEFAULT_LONG_SECTION_NAMES,
3089 1.1 christos 2,
3090 1.1 christos #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
3091 1.1 christos TRUE,
3092 1.1 christos #else
3093 1.1 christos FALSE,
3094 1.1 christos #endif
3095 1.1 christos #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
3096 1.1 christos 4,
3097 1.1.1.3 christos #else
3098 1.1 christos 2,
3099 1.1 christos #endif
3100 1.1 christos 32768,
3101 1.1 christos coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
3102 1.1 christos coff_swap_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
3103 1.1 christos coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
3104 1.1 christos coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
3105 1.1 christos coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
3106 1.1 christos coff_classify_symbol, coff_compute_section_file_positions,
3107 1.1 christos coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
3108 1.1 christos coff_adjust_symndx, coff_link_add_one_symbol,
3109 1.1 christos coff_link_output_has_begun, coff_final_link_postscript,
3110 1.1 christos bfd_pe_print_pdata
3111 1.1 christos };
3112 1.1 christos
3113 1.1 christos #define coff_small_close_and_cleanup \
3114 1.1 christos coff_close_and_cleanup
3115 1.1 christos #define coff_small_bfd_free_cached_info \
3116 1.1 christos coff_bfd_free_cached_info
3117 1.1 christos #define coff_small_get_section_contents \
3118 1.1 christos coff_get_section_contents
3119 1.1.1.3 christos #define coff_small_get_section_contents_in_window \
3120 1.1 christos coff_get_section_contents_in_window
3121 1.1.1.3 christos
3122 1.1 christos extern const bfd_target sh_coff_small_le_vec;
3123 1.1 christos
3124 1.1 christos const bfd_target sh_coff_small_vec =
3125 1.1 christos {
3126 1.1 christos "coff-sh-small", /* name */
3127 1.1 christos bfd_target_coff_flavour,
3128 1.1.1.6 christos BFD_ENDIAN_BIG, /* data byte order is big */
3129 1.1.1.6 christos BFD_ENDIAN_BIG, /* header byte order is big */
3130 1.1.1.6 christos
3131 1.1 christos (HAS_RELOC | EXEC_P /* object flags */
3132 1.1 christos | HAS_LINENO | HAS_DEBUG
3133 1.1 christos | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE),
3134 1.1 christos
3135 1.1 christos (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
3136 1.1.1.2 christos '_', /* leading symbol underscore */
3137 1.1 christos '/', /* ar_pad_char */
3138 1.1 christos 15, /* ar_max_namelen */
3139 1.1 christos 0, /* match priority. */
3140 1.1 christos bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3141 1.1 christos bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3142 1.1 christos bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
3143 1.1 christos bfd_getb64, bfd_getb_signed_64, bfd_putb64,
3144 1.1.1.6 christos bfd_getb32, bfd_getb_signed_32, bfd_putb32,
3145 1.1.1.6 christos bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
3146 1.1.1.6 christos
3147 1.1.1.6 christos { /* bfd_check_format */
3148 1.1.1.6 christos _bfd_dummy_target,
3149 1.1.1.6 christos coff_small_object_p,
3150 1.1.1.6 christos bfd_generic_archive_p,
3151 1.1.1.6 christos _bfd_dummy_target
3152 1.1.1.6 christos },
3153 1.1.1.6 christos { /* bfd_set_format */
3154 1.1.1.6 christos _bfd_bool_bfd_false_error,
3155 1.1.1.6 christos coff_mkobject,
3156 1.1.1.6 christos _bfd_generic_mkarchive,
3157 1.1.1.6 christos _bfd_bool_bfd_false_error
3158 1.1.1.6 christos },
3159 1.1.1.6 christos { /* bfd_write_contents */
3160 1.1.1.6 christos _bfd_bool_bfd_false_error,
3161 1.1.1.6 christos coff_write_object_contents,
3162 1.1 christos _bfd_write_archive_contents,
3163 1.1 christos _bfd_bool_bfd_false_error
3164 1.1 christos },
3165 1.1 christos
3166 1.1 christos BFD_JUMP_TABLE_GENERIC (coff_small),
3167 1.1 christos BFD_JUMP_TABLE_COPY (coff),
3168 1.1 christos BFD_JUMP_TABLE_CORE (_bfd_nocore),
3169 1.1 christos BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
3170 1.1 christos BFD_JUMP_TABLE_SYMBOLS (coff),
3171 1.1 christos BFD_JUMP_TABLE_RELOCS (coff),
3172 1.1 christos BFD_JUMP_TABLE_WRITE (coff),
3173 1.1.1.6 christos BFD_JUMP_TABLE_LINK (coff),
3174 1.1 christos BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3175 1.1.1.6 christos
3176 1.1 christos &sh_coff_small_le_vec,
3177 1.1 christos
3178 1.1.1.3 christos &bfd_coff_small_swap_table
3179 1.1 christos };
3180 1.1 christos
3181 1.1 christos const bfd_target sh_coff_small_le_vec =
3182 1.1 christos {
3183 1.1 christos "coff-shl-small", /* name */
3184 1.1 christos bfd_target_coff_flavour,
3185 1.1.1.6 christos BFD_ENDIAN_LITTLE, /* data byte order is little */
3186 1.1.1.6 christos BFD_ENDIAN_LITTLE, /* header byte order is little endian too*/
3187 1.1.1.6 christos
3188 1.1 christos (HAS_RELOC | EXEC_P /* object flags */
3189 1.1 christos | HAS_LINENO | HAS_DEBUG
3190 1.1 christos | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE),
3191 1.1 christos
3192 1.1 christos (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
3193 1.1.1.2 christos '_', /* leading symbol underscore */
3194 1.1 christos '/', /* ar_pad_char */
3195 1.1 christos 15, /* ar_max_namelen */
3196 1.1 christos 0, /* match priority. */
3197 1.1 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64,
3198 1.1 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32,
3199 1.1 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
3200 1.1 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64,
3201 1.1.1.6 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32,
3202 1.1.1.6 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
3203 1.1.1.6 christos
3204 1.1.1.6 christos { /* bfd_check_format */
3205 1.1.1.6 christos _bfd_dummy_target,
3206 1.1.1.6 christos coff_small_object_p,
3207 1.1.1.6 christos bfd_generic_archive_p,
3208 1.1.1.6 christos _bfd_dummy_target
3209 1.1.1.6 christos },
3210 1.1.1.6 christos { /* bfd_set_format */
3211 1.1.1.6 christos _bfd_bool_bfd_false_error,
3212 1.1.1.6 christos coff_mkobject,
3213 1.1.1.6 christos _bfd_generic_mkarchive,
3214 1.1.1.6 christos _bfd_bool_bfd_false_error
3215 1.1.1.6 christos },
3216 1.1.1.6 christos { /* bfd_write_contents */
3217 1.1.1.6 christos _bfd_bool_bfd_false_error,
3218 1.1.1.6 christos coff_write_object_contents,
3219 1.1 christos _bfd_write_archive_contents,
3220 1.1 christos _bfd_bool_bfd_false_error
3221 1.1 christos },
3222 1.1 christos
3223 1.1 christos BFD_JUMP_TABLE_GENERIC (coff_small),
3224 1.1 christos BFD_JUMP_TABLE_COPY (coff),
3225 1.1 christos BFD_JUMP_TABLE_CORE (_bfd_nocore),
3226 1.1 christos BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
3227 1.1 christos BFD_JUMP_TABLE_SYMBOLS (coff),
3228 1.1 christos BFD_JUMP_TABLE_RELOCS (coff),
3229 1.1 christos BFD_JUMP_TABLE_WRITE (coff),
3230 1.1.1.6 christos BFD_JUMP_TABLE_LINK (coff),
3231 1.1 christos BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
3232 1.1.1.6 christos
3233 1.1 christos &sh_coff_small_vec,
3234 1.1 christos
3235 &bfd_coff_small_swap_table
3236 };
3237 #endif
3238