Commit | Line | Data |
---|---|---|
a01362cc | 1 | /* Matsushita 10300 specific support for 32-bit ELF |
4db4e912 | 2 | Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. |
a01362cc JL |
3 | |
4 | This file is part of BFD, the Binary File Descriptor library. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "bfd.h" | |
21 | #include "sysdep.h" | |
22 | #include "libbfd.h" | |
23 | #include "elf-bfd.h" | |
4db4e912 JL |
24 | #include "elf/mn10300.h" |
25 | ||
26 | struct elf32_mn10300_link_hash_entry | |
27 | { | |
28 | /* The basic elf link hash table entry. */ | |
29 | struct elf_link_hash_entry root; | |
30 | ||
31 | /* For function symbols, the number of times this function is | |
32 | called directly (ie by name). */ | |
33 | unsigned int direct_calls; | |
34 | ||
35 | /* For function symbols, the size of this function's stack | |
36 | (if <= 255 bytes). We stuff this into "call" instructions | |
37 | to this target when it's valid and profitable to do so. */ | |
38 | unsigned char stack_size; | |
39 | ||
40 | /* For function symbols, arguments (if any) for movm instruction | |
41 | in the prologue. We stuff this value into "call" instructions | |
42 | to the target when it's valid and profitable to do so. */ | |
43 | unsigned char movm_args; | |
44 | ||
45 | /* When set, convert all "call" instructions to this target into "calls" | |
46 | instructions. */ | |
47 | #define MN10300_CONVERT_CALL_TO_CALLS 0x1 | |
48 | ||
49 | /* Used to mark functions which have had redundant parts of their | |
50 | prologue deleted. */ | |
51 | #define MN10300_DELETED_PROLOGUE_BYTES 0x2 | |
52 | unsigned char flags; | |
53 | }; | |
54 | ||
55 | /* We derive a hash table from the main elf linker hash table so | |
56 | we can store state variables and a secondary hash table without | |
57 | resorting to global variables. */ | |
58 | struct elf32_mn10300_link_hash_table | |
59 | { | |
60 | /* The main hash table. */ | |
61 | struct elf_link_hash_table root; | |
62 | ||
63 | /* A hash table for static functions. We could derive a new hash table | |
64 | instead of using the full elf32_mn10300_link_hash_table if we wanted | |
65 | to save some memory. */ | |
66 | struct elf32_mn10300_link_hash_table *static_hash_table; | |
67 | ||
68 | /* Random linker state flags. */ | |
69 | #define MN10300_HASH_ENTRIES_INITIALIZED 0x1 | |
70 | char flags; | |
71 | }; | |
72 | ||
73 | /* For MN10300 linker hash table. */ | |
74 | ||
75 | /* Get the MN10300 ELF linker hash table from a link_info structure. */ | |
76 | ||
77 | #define elf32_mn10300_hash_table(p) \ | |
78 | ((struct elf32_mn10300_link_hash_table *) ((p)->hash)) | |
79 | ||
80 | #define elf32_mn10300_link_hash_traverse(table, func, info) \ | |
81 | (elf_link_hash_traverse \ | |
82 | (&(table)->root, \ | |
83 | (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ | |
84 | (info))) | |
85 | ||
86 | static struct bfd_hash_entry *elf32_mn10300_link_hash_newfunc | |
87 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
88 | static struct bfd_link_hash_table *elf32_mn10300_link_hash_table_create | |
89 | PARAMS ((bfd *)); | |
a01362cc JL |
90 | |
91 | static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup | |
92 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
93 | static void mn10300_info_to_howto | |
94 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *)); | |
303b4cc6 RH |
95 | static boolean mn10300_elf_check_relocs |
96 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
97 | const Elf_Internal_Rela *)); | |
98 | static asection *mn10300_elf_gc_mark_hook | |
99 | PARAMS ((bfd *, struct bfd_link_info *info, Elf_Internal_Rela *, | |
100 | struct elf_link_hash_entry *, Elf_Internal_Sym *)); | |
a01362cc JL |
101 | static boolean mn10300_elf_relax_delete_bytes |
102 | PARAMS ((bfd *, asection *, bfd_vma, int)); | |
103 | static boolean mn10300_elf_symbol_address_p | |
104 | PARAMS ((bfd *, asection *, Elf32_External_Sym *, bfd_vma)); | |
4db4e912 JL |
105 | static boolean elf32_mn10300_finish_hash_table_entry |
106 | PARAMS ((struct bfd_hash_entry *, PTR)); | |
107 | static void compute_function_info | |
108 | PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *, | |
109 | bfd_vma, unsigned char *)); | |
a01362cc JL |
110 | |
111 | /* We have to use RELA instructions since md_apply_fix3 in the assembler | |
112 | does absolutely nothing. */ | |
113 | #define USE_RELA | |
114 | ||
115 | enum reloc_type | |
116 | { | |
117 | R_MN10300_NONE = 0, | |
118 | R_MN10300_32, | |
119 | R_MN10300_16, | |
120 | R_MN10300_8, | |
121 | R_MN10300_PCREL32, | |
122 | R_MN10300_PCREL16, | |
123 | R_MN10300_PCREL8, | |
303b4cc6 RH |
124 | |
125 | /* These are GNU extensions to enable C++ vtable garbage collection. */ | |
126 | R_MN10300_GNU_VTINHERIT, | |
127 | R_MN10300_GNU_VTENTRY, | |
128 | ||
a01362cc JL |
129 | R_MN10300_MAX |
130 | }; | |
131 | ||
132 | static reloc_howto_type elf_mn10300_howto_table[] = | |
133 | { | |
134 | /* Dummy relocation. Does nothing. */ | |
135 | HOWTO (R_MN10300_NONE, | |
136 | 0, | |
137 | 2, | |
138 | 16, | |
139 | false, | |
140 | 0, | |
141 | complain_overflow_bitfield, | |
142 | bfd_elf_generic_reloc, | |
143 | "R_MN10300_NONE", | |
144 | false, | |
145 | 0, | |
146 | 0, | |
147 | false), | |
148 | /* Standard 32 bit reloc. */ | |
149 | HOWTO (R_MN10300_32, | |
150 | 0, | |
151 | 2, | |
152 | 32, | |
153 | false, | |
154 | 0, | |
155 | complain_overflow_bitfield, | |
156 | bfd_elf_generic_reloc, | |
157 | "R_MN10300_32", | |
158 | false, | |
159 | 0xffffffff, | |
160 | 0xffffffff, | |
161 | false), | |
162 | /* Standard 16 bit reloc. */ | |
163 | HOWTO (R_MN10300_16, | |
164 | 0, | |
165 | 1, | |
166 | 16, | |
167 | false, | |
168 | 0, | |
169 | complain_overflow_bitfield, | |
170 | bfd_elf_generic_reloc, | |
171 | "R_MN10300_16", | |
172 | false, | |
173 | 0xffff, | |
174 | 0xffff, | |
175 | false), | |
176 | /* Standard 8 bit reloc. */ | |
177 | HOWTO (R_MN10300_8, | |
178 | 0, | |
179 | 0, | |
180 | 8, | |
181 | false, | |
182 | 0, | |
183 | complain_overflow_bitfield, | |
184 | bfd_elf_generic_reloc, | |
185 | "R_MN10300_8", | |
186 | false, | |
187 | 0xff, | |
188 | 0xff, | |
189 | false), | |
190 | /* Standard 32bit pc-relative reloc. */ | |
191 | HOWTO (R_MN10300_PCREL32, | |
192 | 0, | |
193 | 2, | |
194 | 32, | |
195 | true, | |
196 | 0, | |
197 | complain_overflow_bitfield, | |
198 | bfd_elf_generic_reloc, | |
199 | "R_MN10300_PCREL32", | |
200 | false, | |
201 | 0xffffffff, | |
202 | 0xffffffff, | |
203 | true), | |
204 | /* Standard 16bit pc-relative reloc. */ | |
205 | HOWTO (R_MN10300_PCREL16, | |
206 | 0, | |
207 | 1, | |
208 | 16, | |
209 | true, | |
210 | 0, | |
211 | complain_overflow_bitfield, | |
212 | bfd_elf_generic_reloc, | |
213 | "R_MN10300_PCREL16", | |
214 | false, | |
215 | 0xffff, | |
216 | 0xffff, | |
217 | true), | |
218 | /* Standard 8 pc-relative reloc. */ | |
219 | HOWTO (R_MN10300_PCREL8, | |
220 | 0, | |
221 | 0, | |
222 | 8, | |
223 | true, | |
224 | 0, | |
225 | complain_overflow_bitfield, | |
226 | bfd_elf_generic_reloc, | |
227 | "R_MN10300_PCREL8", | |
228 | false, | |
229 | 0xff, | |
230 | 0xff, | |
231 | true), | |
303b4cc6 RH |
232 | |
233 | /* GNU extension to record C++ vtable hierarchy */ | |
234 | HOWTO (R_MN10300_GNU_VTINHERIT, /* type */ | |
235 | 0, /* rightshift */ | |
236 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
237 | 0, /* bitsize */ | |
238 | false, /* pc_relative */ | |
239 | 0, /* bitpos */ | |
240 | complain_overflow_dont, /* complain_on_overflow */ | |
241 | NULL, /* special_function */ | |
242 | "R_MN10300_GNU_VTINHERIT", /* name */ | |
243 | false, /* partial_inplace */ | |
244 | 0, /* src_mask */ | |
245 | 0, /* dst_mask */ | |
246 | false), /* pcrel_offset */ | |
247 | ||
248 | /* GNU extension to record C++ vtable member usage */ | |
249 | HOWTO (R_MN10300_GNU_VTENTRY, /* type */ | |
250 | 0, /* rightshift */ | |
251 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
252 | 0, /* bitsize */ | |
253 | false, /* pc_relative */ | |
254 | 0, /* bitpos */ | |
255 | complain_overflow_dont, /* complain_on_overflow */ | |
256 | NULL, /* special_function */ | |
257 | "R_MN10300_GNU_VTENTRY", /* name */ | |
258 | false, /* partial_inplace */ | |
259 | 0, /* src_mask */ | |
260 | 0, /* dst_mask */ | |
261 | false), /* pcrel_offset */ | |
a01362cc JL |
262 | }; |
263 | ||
264 | struct mn10300_reloc_map | |
265 | { | |
266 | unsigned char bfd_reloc_val; | |
267 | unsigned char elf_reloc_val; | |
268 | }; | |
269 | ||
270 | static const struct mn10300_reloc_map mn10300_reloc_map[] = | |
271 | { | |
272 | { BFD_RELOC_NONE, R_MN10300_NONE, }, | |
273 | { BFD_RELOC_32, R_MN10300_32, }, | |
274 | { BFD_RELOC_16, R_MN10300_16, }, | |
275 | { BFD_RELOC_8, R_MN10300_8, }, | |
276 | { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, }, | |
277 | { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, }, | |
278 | { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, }, | |
303b4cc6 RH |
279 | { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT }, |
280 | { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY }, | |
a01362cc JL |
281 | }; |
282 | ||
283 | static reloc_howto_type * | |
284 | bfd_elf32_bfd_reloc_type_lookup (abfd, code) | |
285 | bfd *abfd; | |
286 | bfd_reloc_code_real_type code; | |
287 | { | |
288 | unsigned int i; | |
289 | ||
290 | for (i = 0; | |
291 | i < sizeof (mn10300_reloc_map) / sizeof (struct mn10300_reloc_map); | |
292 | i++) | |
293 | { | |
294 | if (mn10300_reloc_map[i].bfd_reloc_val == code) | |
295 | return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val]; | |
296 | } | |
297 | ||
298 | return NULL; | |
299 | } | |
300 | ||
301 | /* Set the howto pointer for an MN10300 ELF reloc. */ | |
302 | ||
303 | static void | |
304 | mn10300_info_to_howto (abfd, cache_ptr, dst) | |
305 | bfd *abfd; | |
306 | arelent *cache_ptr; | |
307 | Elf32_Internal_Rela *dst; | |
308 | { | |
309 | unsigned int r_type; | |
310 | ||
311 | r_type = ELF32_R_TYPE (dst->r_info); | |
312 | BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX); | |
313 | cache_ptr->howto = &elf_mn10300_howto_table[r_type]; | |
314 | } | |
315 | ||
303b4cc6 RH |
316 | /* Look through the relocs for a section during the first phase. |
317 | Since we don't do .gots or .plts, we just need to consider the | |
318 | virtual table relocs for gc. */ | |
319 | ||
320 | static boolean | |
321 | mn10300_elf_check_relocs (abfd, info, sec, relocs) | |
322 | bfd *abfd; | |
323 | struct bfd_link_info *info; | |
324 | asection *sec; | |
325 | const Elf_Internal_Rela *relocs; | |
326 | { | |
327 | Elf_Internal_Shdr *symtab_hdr; | |
328 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
329 | const Elf_Internal_Rela *rel; | |
330 | const Elf_Internal_Rela *rel_end; | |
331 | ||
332 | if (info->relocateable) | |
333 | return true; | |
334 | ||
335 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
336 | sym_hashes = elf_sym_hashes (abfd); | |
337 | sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym); | |
338 | if (!elf_bad_symtab (abfd)) | |
339 | sym_hashes_end -= symtab_hdr->sh_info; | |
340 | ||
341 | rel_end = relocs + sec->reloc_count; | |
342 | for (rel = relocs; rel < rel_end; rel++) | |
343 | { | |
344 | struct elf_link_hash_entry *h; | |
345 | unsigned long r_symndx; | |
346 | ||
347 | r_symndx = ELF32_R_SYM (rel->r_info); | |
348 | if (r_symndx < symtab_hdr->sh_info) | |
349 | h = NULL; | |
350 | else | |
351 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
352 | ||
353 | switch (ELF32_R_TYPE (rel->r_info)) | |
354 | { | |
355 | /* This relocation describes the C++ object vtable hierarchy. | |
356 | Reconstruct it for later use during GC. */ | |
357 | case R_MN10300_GNU_VTINHERIT: | |
358 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
359 | return false; | |
360 | break; | |
361 | ||
362 | /* This relocation describes which C++ vtable entries are actually | |
363 | used. Record for later use during GC. */ | |
364 | case R_MN10300_GNU_VTENTRY: | |
365 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
366 | return false; | |
367 | break; | |
368 | } | |
369 | } | |
370 | ||
371 | return true; | |
372 | } | |
373 | ||
374 | /* Return the section that should be marked against GC for a given | |
375 | relocation. */ | |
376 | ||
377 | static asection * | |
378 | mn10300_elf_gc_mark_hook (abfd, info, rel, h, sym) | |
379 | bfd *abfd; | |
380 | struct bfd_link_info *info; | |
381 | Elf_Internal_Rela *rel; | |
382 | struct elf_link_hash_entry *h; | |
383 | Elf_Internal_Sym *sym; | |
384 | { | |
385 | if (h != NULL) | |
386 | { | |
387 | switch (ELF32_R_TYPE (rel->r_info)) | |
388 | { | |
389 | case R_MN10300_GNU_VTINHERIT: | |
390 | case R_MN10300_GNU_VTENTRY: | |
391 | break; | |
392 | ||
393 | default: | |
394 | switch (h->root.type) | |
395 | { | |
396 | case bfd_link_hash_defined: | |
397 | case bfd_link_hash_defweak: | |
398 | return h->root.u.def.section; | |
399 | ||
400 | case bfd_link_hash_common: | |
401 | return h->root.u.c.p->section; | |
402 | } | |
403 | } | |
404 | } | |
405 | else | |
406 | { | |
407 | if (!(elf_bad_symtab (abfd) | |
408 | && ELF_ST_BIND (sym->st_info) != STB_LOCAL) | |
409 | && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) | |
410 | && sym->st_shndx != SHN_COMMON)) | |
411 | { | |
412 | return bfd_section_from_elf_index (abfd, sym->st_shndx); | |
413 | } | |
414 | } | |
415 | ||
416 | return NULL; | |
417 | } | |
418 | ||
a01362cc JL |
419 | /* Perform a relocation as part of a final link. */ |
420 | static bfd_reloc_status_type | |
421 | mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, | |
422 | input_section, contents, offset, value, | |
423 | addend, info, sym_sec, is_local) | |
424 | reloc_howto_type *howto; | |
425 | bfd *input_bfd; | |
426 | bfd *output_bfd; | |
427 | asection *input_section; | |
428 | bfd_byte *contents; | |
429 | bfd_vma offset; | |
430 | bfd_vma value; | |
431 | bfd_vma addend; | |
432 | struct bfd_link_info *info; | |
433 | asection *sym_sec; | |
434 | int is_local; | |
435 | { | |
436 | unsigned long r_type = howto->type; | |
437 | bfd_byte *hit_data = contents + offset; | |
438 | ||
439 | switch (r_type) | |
440 | { | |
a01362cc JL |
441 | case R_MN10300_NONE: |
442 | return bfd_reloc_ok; | |
443 | ||
444 | case R_MN10300_32: | |
445 | value += addend; | |
446 | bfd_put_32 (input_bfd, value, hit_data); | |
447 | return bfd_reloc_ok; | |
448 | ||
449 | case R_MN10300_16: | |
450 | value += addend; | |
451 | ||
452 | if ((long)value > 0x7fff || (long)value < -0x8000) | |
453 | return bfd_reloc_overflow; | |
454 | ||
455 | bfd_put_16 (input_bfd, value, hit_data); | |
456 | return bfd_reloc_ok; | |
457 | ||
458 | case R_MN10300_8: | |
459 | value += addend; | |
460 | ||
461 | if ((long)value > 0x7fff || (long)value < -0x8000) | |
462 | return bfd_reloc_overflow; | |
463 | ||
464 | bfd_put_8 (input_bfd, value, hit_data); | |
465 | return bfd_reloc_ok; | |
466 | ||
467 | case R_MN10300_PCREL8: | |
468 | value -= (input_section->output_section->vma | |
469 | + input_section->output_offset); | |
470 | value -= offset; | |
471 | value += addend; | |
472 | ||
473 | if ((long)value > 0xff || (long)value < -0x100) | |
4db4e912 | 474 | return bfd_reloc_overflow; |
a01362cc JL |
475 | |
476 | bfd_put_8 (input_bfd, value, hit_data); | |
477 | return bfd_reloc_ok; | |
478 | ||
479 | case R_MN10300_PCREL16: | |
480 | value -= (input_section->output_section->vma | |
481 | + input_section->output_offset); | |
482 | value -= offset; | |
483 | value += addend; | |
484 | ||
485 | if ((long)value > 0xffff || (long)value < -0x10000) | |
4db4e912 | 486 | return bfd_reloc_overflow; |
a01362cc JL |
487 | |
488 | bfd_put_16 (input_bfd, value, hit_data); | |
489 | return bfd_reloc_ok; | |
490 | ||
491 | case R_MN10300_PCREL32: | |
492 | value -= (input_section->output_section->vma | |
493 | + input_section->output_offset); | |
494 | value -= offset; | |
495 | value += addend; | |
496 | ||
497 | bfd_put_32 (input_bfd, value, hit_data); | |
498 | return bfd_reloc_ok; | |
499 | ||
303b4cc6 RH |
500 | case R_MN10300_GNU_VTINHERIT: |
501 | case R_MN10300_GNU_VTENTRY: | |
502 | return bfd_reloc_ok; | |
503 | ||
a01362cc JL |
504 | default: |
505 | return bfd_reloc_notsupported; | |
506 | } | |
507 | } | |
508 | ||
509 | \f | |
510 | /* Relocate an MN10300 ELF section. */ | |
511 | static boolean | |
512 | mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section, | |
513 | contents, relocs, local_syms, local_sections) | |
514 | bfd *output_bfd; | |
515 | struct bfd_link_info *info; | |
516 | bfd *input_bfd; | |
517 | asection *input_section; | |
518 | bfd_byte *contents; | |
519 | Elf_Internal_Rela *relocs; | |
520 | Elf_Internal_Sym *local_syms; | |
521 | asection **local_sections; | |
522 | { | |
523 | Elf_Internal_Shdr *symtab_hdr; | |
4db4e912 | 524 | struct elf32_mn10300_link_hash_entry **sym_hashes; |
a01362cc JL |
525 | Elf_Internal_Rela *rel, *relend; |
526 | ||
527 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
4db4e912 JL |
528 | sym_hashes = (struct elf32_mn10300_link_hash_entry **) |
529 | (elf_sym_hashes (input_bfd)); | |
a01362cc JL |
530 | |
531 | rel = relocs; | |
532 | relend = relocs + input_section->reloc_count; | |
533 | for (; rel < relend; rel++) | |
534 | { | |
535 | int r_type; | |
536 | reloc_howto_type *howto; | |
537 | unsigned long r_symndx; | |
538 | Elf_Internal_Sym *sym; | |
539 | asection *sec; | |
4db4e912 | 540 | struct elf32_mn10300_link_hash_entry *h; |
a01362cc JL |
541 | bfd_vma relocation; |
542 | bfd_reloc_status_type r; | |
543 | ||
544 | r_symndx = ELF32_R_SYM (rel->r_info); | |
545 | r_type = ELF32_R_TYPE (rel->r_info); | |
546 | howto = elf_mn10300_howto_table + r_type; | |
547 | ||
303b4cc6 RH |
548 | /* Just skip the vtable gc relocs. */ |
549 | if (r_type == R_MN10300_GNU_VTINHERIT | |
550 | || r_type == R_MN10300_GNU_VTENTRY) | |
551 | continue; | |
552 | ||
a01362cc JL |
553 | if (info->relocateable) |
554 | { | |
555 | /* This is a relocateable link. We don't have to change | |
4db4e912 JL |
556 | anything, unless the reloc is against a section symbol, |
557 | in which case we have to adjust according to where the | |
558 | section symbol winds up in the output section. */ | |
a01362cc JL |
559 | if (r_symndx < symtab_hdr->sh_info) |
560 | { | |
561 | sym = local_syms + r_symndx; | |
562 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
563 | { | |
564 | sec = local_sections[r_symndx]; | |
565 | rel->r_addend += sec->output_offset + sym->st_value; | |
566 | } | |
567 | } | |
568 | ||
569 | continue; | |
570 | } | |
571 | ||
572 | /* This is a final link. */ | |
573 | h = NULL; | |
574 | sym = NULL; | |
575 | sec = NULL; | |
576 | if (r_symndx < symtab_hdr->sh_info) | |
577 | { | |
578 | sym = local_syms + r_symndx; | |
579 | sec = local_sections[r_symndx]; | |
580 | relocation = (sec->output_section->vma | |
581 | + sec->output_offset | |
582 | + sym->st_value); | |
583 | } | |
584 | else | |
585 | { | |
586 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
587 | while (h->root.type == bfd_link_hash_indirect | |
588 | || h->root.type == bfd_link_hash_warning) | |
4db4e912 JL |
589 | h = (struct elf32_mn10300_link_hash_entry *) h->root.root.u.i.link; |
590 | if (h->root.root.type == bfd_link_hash_defined | |
591 | || h->root.root.type == bfd_link_hash_defweak) | |
a01362cc | 592 | { |
4db4e912 JL |
593 | sec = h->root.root.u.def.section; |
594 | relocation = (h->root.root.u.def.value | |
a01362cc JL |
595 | + sec->output_section->vma |
596 | + sec->output_offset); | |
597 | } | |
4db4e912 | 598 | else if (h->root.root.type == bfd_link_hash_undefweak) |
a01362cc JL |
599 | relocation = 0; |
600 | else | |
601 | { | |
602 | if (! ((*info->callbacks->undefined_symbol) | |
4db4e912 | 603 | (info, h->root.root.root.string, input_bfd, |
a01362cc JL |
604 | input_section, rel->r_offset))) |
605 | return false; | |
606 | relocation = 0; | |
607 | } | |
608 | } | |
609 | ||
610 | r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, | |
611 | input_section, | |
612 | contents, rel->r_offset, | |
613 | relocation, rel->r_addend, | |
614 | info, sec, h == NULL); | |
615 | ||
616 | if (r != bfd_reloc_ok) | |
617 | { | |
618 | const char *name; | |
619 | const char *msg = (const char *)0; | |
620 | ||
621 | if (h != NULL) | |
4db4e912 | 622 | name = h->root.root.root.string; |
a01362cc JL |
623 | else |
624 | { | |
625 | name = (bfd_elf_string_from_elf_section | |
626 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
627 | if (name == NULL || *name == '\0') | |
628 | name = bfd_section_name (input_bfd, sec); | |
629 | } | |
630 | ||
631 | switch (r) | |
632 | { | |
633 | case bfd_reloc_overflow: | |
634 | if (! ((*info->callbacks->reloc_overflow) | |
635 | (info, name, howto->name, (bfd_vma) 0, | |
636 | input_bfd, input_section, rel->r_offset))) | |
637 | return false; | |
638 | break; | |
639 | ||
640 | case bfd_reloc_undefined: | |
641 | if (! ((*info->callbacks->undefined_symbol) | |
642 | (info, name, input_bfd, input_section, | |
643 | rel->r_offset))) | |
644 | return false; | |
645 | break; | |
646 | ||
647 | case bfd_reloc_outofrange: | |
4db4e912 | 648 | msg = _("internal error: out of range error"); |
a01362cc JL |
649 | goto common_error; |
650 | ||
651 | case bfd_reloc_notsupported: | |
4db4e912 | 652 | msg = _("internal error: unsupported relocation error"); |
a01362cc JL |
653 | goto common_error; |
654 | ||
655 | case bfd_reloc_dangerous: | |
4db4e912 | 656 | msg = _("internal error: dangerous error"); |
a01362cc JL |
657 | goto common_error; |
658 | ||
659 | default: | |
4db4e912 | 660 | msg = _("internal error: unknown error"); |
a01362cc JL |
661 | /* fall through */ |
662 | ||
663 | common_error: | |
664 | if (!((*info->callbacks->warning) | |
665 | (info, msg, name, input_bfd, input_section, | |
666 | rel->r_offset))) | |
667 | return false; | |
668 | break; | |
669 | } | |
670 | } | |
671 | } | |
672 | ||
673 | return true; | |
674 | } | |
675 | ||
4db4e912 JL |
676 | /* Finish initializing one hash table entry. */ |
677 | static boolean | |
678 | elf32_mn10300_finish_hash_table_entry (gen_entry, in_args) | |
679 | struct bfd_hash_entry *gen_entry; | |
680 | PTR in_args; | |
681 | { | |
682 | struct elf32_mn10300_link_hash_entry *entry; | |
683 | unsigned int byte_count = 0; | |
684 | ||
685 | entry = (struct elf32_mn10300_link_hash_entry *)gen_entry; | |
686 | ||
687 | /* If we already know we want to convert "call" to "calls" for calls | |
688 | to this symbol, then return now. */ | |
689 | if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS) | |
690 | return true; | |
691 | ||
692 | /* If there are no named calls to this symbol, or there's nothing we | |
693 | can move from the function itself into the "call" instruction, then | |
694 | note that all "call" instructions should be converted into "calls" | |
695 | instructions and return. */ | |
696 | if (entry->direct_calls == 0 | |
697 | || (entry->stack_size == 0 && entry->movm_args == 0)) | |
698 | { | |
699 | /* Make a note that we should convert "call" instructions to "calls" | |
700 | instructions for calls to this symbol. */ | |
701 | entry->flags |= MN10300_CONVERT_CALL_TO_CALLS; | |
702 | return true; | |
703 | } | |
704 | ||
705 | /* We may be able to move some instructions from the function itself into | |
706 | the "call" instruction. Count how many bytes we might be able to | |
707 | eliminate in the function itself. */ | |
708 | ||
709 | /* A movm instruction is two bytes. */ | |
710 | if (entry->movm_args) | |
711 | byte_count += 2; | |
712 | ||
713 | /* Count the insn to allocate stack space too. */ | |
714 | if (entry->stack_size > 0 && entry->stack_size <= 128) | |
715 | byte_count += 3; | |
716 | else if (entry->stack_size > 0 && entry->stack_size < 256) | |
717 | byte_count += 4; | |
718 | ||
719 | /* If using "call" will result in larger code, then turn all | |
720 | the associated "call" instructions into "calls" instrutions. */ | |
721 | if (byte_count < entry->direct_calls) | |
722 | entry->flags |= MN10300_CONVERT_CALL_TO_CALLS; | |
723 | ||
724 | /* This routine never fails. */ | |
725 | return true; | |
726 | } | |
727 | ||
a01362cc JL |
728 | /* This function handles relaxing for the mn10300. |
729 | ||
730 | There's quite a few relaxing opportunites available on the mn10300: | |
731 | ||
732 | * calls:32 -> calls:16 2 bytes | |
4db4e912 JL |
733 | * call:32 -> call:16 2 bytes |
734 | ||
735 | * call:32 -> calls:32 1 byte | |
736 | * call:16 -> calls:16 1 byte | |
737 | * These are done anytime using "calls" would result | |
738 | in smaller code, or when necessary to preserve the | |
739 | meaning of the program. | |
a01362cc | 740 | |
4db4e912 JL |
741 | * call:32 varies |
742 | * call:16 | |
743 | * In some circumstances we can move instructions | |
744 | from a function prologue into a "call" instruction. | |
745 | This is only done if the resulting code is no larger | |
746 | than the original code. | |
747 | ||
748 | ||
749 | * jmp:32 -> jmp:16 2 bytes | |
a01362cc JL |
750 | * jmp:16 -> bra:8 1 byte |
751 | ||
752 | * If the previous instruction is a conditional branch | |
753 | around the jump/bra, we may be able to reverse its condition | |
754 | and change its target to the jump's target. The jump/bra | |
755 | can then be deleted. 2 bytes | |
756 | ||
4db4e912 | 757 | * mov abs32 -> mov abs16 1 or 2 bytes |
a01362cc | 758 | |
4db4e912 JL |
759 | * Most instructions which accept imm32 can relax to imm16 1 or 2 bytes |
760 | - Most instructions which accept imm16 can relax to imm8 1 or 2 bytes | |
a01362cc | 761 | |
4db4e912 JL |
762 | * Most instructions which accept d32 can relax to d16 1 or 2 bytes |
763 | - Most instructions which accept d16 can relax to d8 1 or 2 bytes | |
a01362cc | 764 | |
a01362cc JL |
765 | We don't handle imm16->imm8 or d16->d8 as they're very rare |
766 | and somewhat more difficult to support. */ | |
767 | ||
768 | static boolean | |
769 | mn10300_elf_relax_section (abfd, sec, link_info, again) | |
770 | bfd *abfd; | |
771 | asection *sec; | |
772 | struct bfd_link_info *link_info; | |
773 | boolean *again; | |
774 | { | |
775 | Elf_Internal_Shdr *symtab_hdr; | |
4db4e912 | 776 | Elf_Internal_Rela *internal_relocs = NULL; |
a01362cc JL |
777 | Elf_Internal_Rela *free_relocs = NULL; |
778 | Elf_Internal_Rela *irel, *irelend; | |
779 | bfd_byte *contents = NULL; | |
780 | bfd_byte *free_contents = NULL; | |
781 | Elf32_External_Sym *extsyms = NULL; | |
782 | Elf32_External_Sym *free_extsyms = NULL; | |
4db4e912 | 783 | struct elf32_mn10300_link_hash_table *hash_table; |
a01362cc JL |
784 | |
785 | /* Assume nothing changes. */ | |
786 | *again = false; | |
787 | ||
4db4e912 JL |
788 | /* We need a pointer to the mn10300 specific hash table. */ |
789 | hash_table = elf32_mn10300_hash_table (link_info); | |
790 | ||
791 | /* Initialize fields in each hash table entry the first time through. */ | |
792 | if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0) | |
793 | { | |
794 | bfd *input_bfd; | |
795 | ||
796 | /* Iterate over all the input bfds. */ | |
797 | for (input_bfd = link_info->input_bfds; | |
798 | input_bfd != NULL; | |
799 | input_bfd = input_bfd->link_next) | |
800 | { | |
801 | asection *section; | |
802 | ||
803 | /* We're going to need all the symbols for each bfd. */ | |
804 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
805 | ||
806 | /* Get cached copy if it exists. */ | |
807 | if (symtab_hdr->contents != NULL) | |
808 | extsyms = (Elf32_External_Sym *) symtab_hdr->contents; | |
809 | else | |
810 | { | |
811 | /* Go get them off disk. */ | |
812 | extsyms = ((Elf32_External_Sym *) | |
813 | bfd_malloc (symtab_hdr->sh_size)); | |
814 | if (extsyms == NULL) | |
815 | goto error_return; | |
816 | free_extsyms = extsyms; | |
817 | if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 | |
818 | || (bfd_read (extsyms, 1, symtab_hdr->sh_size, input_bfd) | |
819 | != symtab_hdr->sh_size)) | |
820 | goto error_return; | |
821 | } | |
822 | ||
823 | /* Iterate over each section in this bfd. */ | |
824 | for (section = input_bfd->sections; | |
825 | section != NULL; | |
826 | section = section->next) | |
827 | { | |
828 | struct elf32_mn10300_link_hash_entry *hash; | |
829 | Elf_Internal_Sym *sym; | |
830 | asection *sym_sec; | |
831 | const char *sym_name; | |
832 | char *new_name; | |
833 | Elf_Internal_Shdr *hdr; | |
834 | ||
835 | /* Get cached copy of section contents if it exists. */ | |
836 | if (elf_section_data (section)->this_hdr.contents != NULL) | |
837 | contents = elf_section_data (section)->this_hdr.contents; | |
838 | else if (section->_raw_size != 0) | |
839 | { | |
840 | /* Go get them off disk. */ | |
841 | contents = (bfd_byte *)bfd_malloc (section->_raw_size); | |
842 | if (contents == NULL) | |
843 | goto error_return; | |
844 | free_contents = contents; | |
845 | ||
846 | if (!bfd_get_section_contents (input_bfd, section, | |
847 | contents, (file_ptr) 0, | |
848 | section->_raw_size)) | |
849 | goto error_return; | |
850 | } | |
851 | else | |
852 | { | |
853 | contents = NULL; | |
854 | free_contents = NULL; | |
855 | } | |
856 | ||
857 | /* If there aren't any relocs, then there's nothing to do. */ | |
858 | if ((section->flags & SEC_RELOC) != 0 | |
859 | && section->reloc_count != 0) | |
860 | { | |
861 | ||
862 | /* Get a copy of the native relocations. */ | |
863 | internal_relocs = (_bfd_elf32_link_read_relocs | |
864 | (input_bfd, section, (PTR) NULL, | |
865 | (Elf_Internal_Rela *) NULL, | |
866 | link_info->keep_memory)); | |
867 | if (internal_relocs == NULL) | |
868 | goto error_return; | |
869 | if (! link_info->keep_memory) | |
870 | free_relocs = internal_relocs; | |
871 | ||
872 | /* Now examine each relocation. */ | |
873 | irel = internal_relocs; | |
874 | irelend = irel + section->reloc_count; | |
875 | for (; irel < irelend; irel++) | |
876 | { | |
877 | long r_type; | |
878 | unsigned long r_index; | |
879 | unsigned char code; | |
880 | ||
881 | r_type = ELF32_R_TYPE (irel->r_info); | |
882 | r_index = ELF32_R_SYM (irel->r_info); | |
883 | ||
884 | if (r_type < 0 || r_type >= (int)R_MN10300_MAX) | |
885 | goto error_return; | |
886 | ||
887 | /* We need the name and hash table entry of the target | |
888 | symbol! */ | |
889 | hash = NULL; | |
890 | sym = NULL; | |
891 | sym_sec = NULL; | |
892 | ||
893 | if (r_index < symtab_hdr->sh_info) | |
894 | { | |
895 | /* A local symbol. */ | |
896 | Elf_Internal_Sym isym; | |
897 | ||
898 | bfd_elf32_swap_symbol_in (input_bfd, | |
899 | extsyms + r_index, &isym); | |
900 | ||
901 | if (isym.st_shndx == SHN_UNDEF) | |
902 | sym_sec = bfd_und_section_ptr; | |
903 | else if (isym.st_shndx > 0 | |
904 | && isym.st_shndx < SHN_LORESERVE) | |
905 | sym_sec | |
906 | = bfd_section_from_elf_index (input_bfd, | |
907 | isym.st_shndx); | |
908 | else if (isym.st_shndx == SHN_ABS) | |
909 | sym_sec = bfd_abs_section_ptr; | |
910 | else if (isym.st_shndx == SHN_COMMON) | |
911 | sym_sec = bfd_com_section_ptr; | |
912 | ||
913 | sym_name = bfd_elf_string_from_elf_section (input_bfd, | |
914 | symtab_hdr->sh_link, | |
915 | isym.st_name); | |
916 | ||
917 | /* If it isn't a function, then we don't care | |
918 | about it. */ | |
919 | if (r_index < symtab_hdr->sh_info | |
920 | && ELF_ST_TYPE (isym.st_info) != STT_FUNC) | |
921 | continue; | |
922 | ||
923 | /* Tack on an ID so we can uniquely identify this | |
924 | local symbol in the global hash table. */ | |
925 | new_name = alloca (strlen (sym_name) + 10); | |
926 | sprintf (new_name, "%s_%08x", sym_name, (int)sym_sec); | |
927 | sym_name = new_name; | |
928 | ||
929 | hash = (struct elf32_mn10300_link_hash_entry *) | |
930 | elf_link_hash_lookup (&hash_table->static_hash_table->root, | |
931 | sym_name, true, | |
932 | true, false); | |
933 | } | |
934 | else | |
935 | { | |
936 | r_index -= symtab_hdr->sh_info; | |
937 | hash = (struct elf32_mn10300_link_hash_entry *) | |
938 | elf_sym_hashes (input_bfd)[r_index]; | |
939 | } | |
940 | ||
941 | /* If this is not a "call" instruction, then we | |
942 | should convert "call" instructions to "calls" | |
943 | instructions. */ | |
944 | code = bfd_get_8 (input_bfd, | |
945 | contents + irel->r_offset - 1); | |
946 | if (code != 0xdd && code != 0xcd) | |
947 | hash->flags |= MN10300_CONVERT_CALL_TO_CALLS; | |
948 | ||
949 | /* If this is a jump/call, then bump the direct_calls | |
950 | counter. Else force "call" to "calls" conversions. */ | |
951 | if (r_type == R_MN10300_PCREL32 | |
952 | || r_type == R_MN10300_PCREL16) | |
953 | hash->direct_calls++; | |
954 | else | |
955 | hash->flags |= MN10300_CONVERT_CALL_TO_CALLS; | |
956 | } | |
957 | } | |
958 | ||
959 | /* Now look at the actual contents to get the stack size, | |
960 | and a list of what registers were saved in the prologue | |
961 | (ie movm_args). */ | |
962 | if ((section->flags & SEC_CODE) != 0) | |
963 | { | |
964 | ||
965 | Elf32_External_Sym *esym, *esymend; | |
966 | int idx, shndx; | |
967 | ||
968 | shndx = _bfd_elf_section_from_bfd_section (input_bfd, | |
969 | section); | |
970 | ||
971 | ||
972 | /* Look at each function defined in this section and | |
973 | update info for that function. */ | |
974 | esym = extsyms; | |
975 | esymend = esym + symtab_hdr->sh_info; | |
976 | for (; esym < esymend; esym++) | |
977 | { | |
978 | Elf_Internal_Sym isym; | |
979 | ||
980 | bfd_elf32_swap_symbol_in (input_bfd, esym, &isym); | |
981 | if (isym.st_shndx == shndx | |
982 | && ELF_ST_TYPE (isym.st_info) == STT_FUNC) | |
983 | { | |
984 | if (isym.st_shndx == SHN_UNDEF) | |
985 | sym_sec = bfd_und_section_ptr; | |
986 | else if (isym.st_shndx > 0 | |
987 | && isym.st_shndx < SHN_LORESERVE) | |
988 | sym_sec | |
989 | = bfd_section_from_elf_index (input_bfd, | |
990 | isym.st_shndx); | |
991 | else if (isym.st_shndx == SHN_ABS) | |
992 | sym_sec = bfd_abs_section_ptr; | |
993 | else if (isym.st_shndx == SHN_COMMON) | |
994 | sym_sec = bfd_com_section_ptr; | |
995 | ||
996 | sym_name = bfd_elf_string_from_elf_section (input_bfd, | |
997 | symtab_hdr->sh_link, | |
998 | isym.st_name); | |
999 | ||
1000 | /* Tack on an ID so we can uniquely identify this | |
1001 | local symbol in the global hash table. */ | |
1002 | new_name = alloca (strlen (sym_name) + 10); | |
1003 | sprintf (new_name, "%s_%08x", sym_name, (int)sym_sec); | |
1004 | sym_name = new_name; | |
1005 | ||
1006 | hash = (struct elf32_mn10300_link_hash_entry *) | |
1007 | elf_link_hash_lookup (&hash_table->static_hash_table->root, | |
1008 | sym_name, true, | |
1009 | true, false); | |
1010 | compute_function_info (input_bfd, hash, | |
1011 | isym.st_value, contents); | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | esym = extsyms + symtab_hdr->sh_info; | |
1016 | esymend = extsyms + (symtab_hdr->sh_size | |
1017 | / sizeof (Elf32_External_Sym)); | |
1018 | for (idx = 0; esym < esymend; esym++, idx++) | |
1019 | { | |
1020 | Elf_Internal_Sym isym; | |
1021 | ||
1022 | bfd_elf32_swap_symbol_in (input_bfd, esym, &isym); | |
1023 | hash = (struct elf32_mn10300_link_hash_entry *) | |
1024 | elf_sym_hashes (input_bfd)[idx]; | |
1025 | if (isym.st_shndx == shndx | |
1026 | && ELF_ST_TYPE (isym.st_info) == STT_FUNC | |
1027 | && (hash)->root.root.u.def.section == section | |
1028 | && ((hash)->root.root.type == bfd_link_hash_defined | |
1029 | || (hash)->root.root.type == bfd_link_hash_defweak)) | |
1030 | compute_function_info (input_bfd, hash, | |
1031 | (hash)->root.root.u.def.value, | |
1032 | contents); | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | /* Cache or free any memory we allocated for the relocs. */ | |
1037 | if (free_relocs != NULL) | |
1038 | { | |
1039 | free (free_relocs); | |
1040 | free_relocs = NULL; | |
1041 | } | |
1042 | ||
1043 | /* Cache or free any memory we allocated for the contents. */ | |
1044 | if (free_contents != NULL) | |
1045 | { | |
1046 | if (! link_info->keep_memory) | |
1047 | free (free_contents); | |
1048 | else | |
1049 | { | |
1050 | /* Cache the section contents for elf_link_input_bfd. */ | |
1051 | elf_section_data (section)->this_hdr.contents = contents; | |
1052 | } | |
1053 | free_contents = NULL; | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | /* Cache or free any memory we allocated for the symbols. */ | |
1058 | if (free_extsyms != NULL) | |
1059 | { | |
1060 | if (! link_info->keep_memory) | |
1061 | free (free_extsyms); | |
1062 | else | |
1063 | { | |
1064 | /* Cache the symbols for elf_link_input_bfd. */ | |
1065 | symtab_hdr->contents = extsyms; | |
1066 | } | |
1067 | free_extsyms = NULL; | |
1068 | } | |
1069 | } | |
1070 | ||
1071 | /* Now iterate on each symbol in the hash table and perform | |
1072 | the final initialization steps on each. */ | |
1073 | elf32_mn10300_link_hash_traverse (hash_table, | |
1074 | elf32_mn10300_finish_hash_table_entry, | |
1075 | NULL); | |
1076 | elf32_mn10300_link_hash_traverse (hash_table->static_hash_table, | |
1077 | elf32_mn10300_finish_hash_table_entry, | |
1078 | NULL); | |
1079 | ||
1080 | /* All entries in the hash table are fully initialized. */ | |
1081 | hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED; | |
1082 | ||
1083 | /* Now that everything has been initialized, go through each | |
1084 | code section and delete any prologue insns which will be | |
1085 | redundant because their operations will be performed by | |
1086 | a "call" instruction. */ | |
1087 | for (input_bfd = link_info->input_bfds; | |
1088 | input_bfd != NULL; | |
1089 | input_bfd = input_bfd->link_next) | |
1090 | { | |
1091 | asection *section; | |
1092 | ||
1093 | /* We're going to need all the symbols for each bfd. */ | |
1094 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
1095 | ||
1096 | /* Get cached copy if it exists. */ | |
1097 | if (symtab_hdr->contents != NULL) | |
1098 | extsyms = (Elf32_External_Sym *) symtab_hdr->contents; | |
1099 | else | |
1100 | { | |
1101 | /* Go get them off disk. */ | |
1102 | extsyms = ((Elf32_External_Sym *) | |
1103 | bfd_malloc (symtab_hdr->sh_size)); | |
1104 | if (extsyms == NULL) | |
1105 | goto error_return; | |
1106 | free_extsyms = extsyms; | |
1107 | if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 | |
1108 | || (bfd_read (extsyms, 1, symtab_hdr->sh_size, input_bfd) | |
1109 | != symtab_hdr->sh_size)) | |
1110 | goto error_return; | |
1111 | } | |
1112 | ||
1113 | /* Walk over each section in this bfd. */ | |
1114 | for (section = input_bfd->sections; | |
1115 | section != NULL; | |
1116 | section = section->next) | |
1117 | { | |
1118 | int shndx; | |
1119 | Elf32_External_Sym *esym, *esymend; | |
1120 | int idx; | |
1121 | ||
1122 | /* Skip non-code sections and empty sections. */ | |
1123 | if ((section->flags & SEC_CODE) == 0 || section->_raw_size == 0) | |
1124 | continue; | |
1125 | ||
1126 | if (section->reloc_count != 0) | |
1127 | { | |
1128 | /* Get a copy of the native relocations. */ | |
1129 | internal_relocs = (_bfd_elf32_link_read_relocs | |
1130 | (input_bfd, section, (PTR) NULL, | |
1131 | (Elf_Internal_Rela *) NULL, | |
1132 | link_info->keep_memory)); | |
1133 | if (internal_relocs == NULL) | |
1134 | goto error_return; | |
1135 | if (! link_info->keep_memory) | |
1136 | free_relocs = internal_relocs; | |
1137 | } | |
1138 | ||
1139 | /* Get cached copy of section contents if it exists. */ | |
1140 | if (elf_section_data (section)->this_hdr.contents != NULL) | |
1141 | contents = elf_section_data (section)->this_hdr.contents; | |
1142 | else | |
1143 | { | |
1144 | /* Go get them off disk. */ | |
1145 | contents = (bfd_byte *)bfd_malloc (section->_raw_size); | |
1146 | if (contents == NULL) | |
1147 | goto error_return; | |
1148 | free_contents = contents; | |
1149 | ||
1150 | if (!bfd_get_section_contents (input_bfd, section, | |
1151 | contents, (file_ptr) 0, | |
1152 | section->_raw_size)) | |
1153 | goto error_return; | |
1154 | } | |
1155 | ||
1156 | ||
1157 | shndx = _bfd_elf_section_from_bfd_section (input_bfd, section); | |
1158 | ||
1159 | /* Now look for any function in this section which needs | |
1160 | insns deleted from its prologue. */ | |
1161 | esym = extsyms; | |
1162 | esymend = esym + symtab_hdr->sh_info; | |
1163 | for (; esym < esymend; esym++) | |
1164 | { | |
1165 | Elf_Internal_Sym isym; | |
1166 | struct elf32_mn10300_link_hash_entry *sym_hash; | |
1167 | asection *sym_sec; | |
1168 | const char *sym_name; | |
1169 | Elf_Internal_Shdr *hdr; | |
1170 | char *new_name; | |
1171 | ||
1172 | bfd_elf32_swap_symbol_in (input_bfd, esym, &isym); | |
1173 | ||
1174 | if (isym.st_shndx != shndx) | |
1175 | continue; | |
1176 | ||
1177 | if (isym.st_shndx == SHN_UNDEF) | |
1178 | sym_sec = bfd_und_section_ptr; | |
1179 | else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE) | |
1180 | sym_sec | |
1181 | = bfd_section_from_elf_index (input_bfd, isym.st_shndx); | |
1182 | else if (isym.st_shndx == SHN_ABS) | |
1183 | sym_sec = bfd_abs_section_ptr; | |
1184 | else if (isym.st_shndx == SHN_COMMON) | |
1185 | sym_sec = bfd_com_section_ptr; | |
1186 | ||
1187 | sym_name = bfd_elf_string_from_elf_section (input_bfd, | |
1188 | symtab_hdr->sh_link, | |
1189 | isym.st_name); | |
1190 | ||
1191 | /* Tack on an ID so we can uniquely identify this | |
1192 | local symbol in the global hash table. */ | |
1193 | new_name = alloca (strlen (sym_name) + 10); | |
1194 | sprintf (new_name, "%s_%08x", sym_name, (int)sym_sec); | |
1195 | sym_name = new_name; | |
1196 | ||
1197 | sym_hash = (struct elf32_mn10300_link_hash_entry *) | |
1198 | elf_link_hash_lookup (&hash_table->static_hash_table->root, | |
1199 | sym_name, false, | |
1200 | false, false); | |
1201 | ||
1202 | if (sym_hash == NULL) | |
1203 | continue; | |
1204 | ||
1205 | if (! ((sym_hash)->flags & MN10300_CONVERT_CALL_TO_CALLS) | |
1206 | && ! ((sym_hash)->flags & MN10300_DELETED_PROLOGUE_BYTES)) | |
1207 | { | |
1208 | int bytes = 0; | |
1209 | ||
1210 | /* Note that we've changed things. */ | |
1211 | elf_section_data (section)->relocs = internal_relocs; | |
1212 | free_relocs = NULL; | |
1213 | ||
1214 | elf_section_data (section)->this_hdr.contents = contents; | |
1215 | free_contents = NULL; | |
1216 | ||
1217 | symtab_hdr->contents = (bfd_byte *)extsyms; | |
1218 | free_extsyms = NULL; | |
1219 | ||
1220 | /* Count how many bytes we're going to delete. */ | |
1221 | if (sym_hash->movm_args) | |
1222 | bytes += 2; | |
1223 | ||
1224 | if (sym_hash->stack_size && sym_hash->stack_size <= 128) | |
1225 | bytes += 3; | |
1226 | else if (sym_hash->stack_size | |
1227 | && sym_hash->stack_size < 256) | |
1228 | bytes += 4; | |
1229 | ||
1230 | /* Note that we've deleted prologue bytes for this | |
1231 | function. */ | |
1232 | sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES; | |
1233 | ||
1234 | /* Actually delete the bytes. */ | |
1235 | if (!mn10300_elf_relax_delete_bytes (input_bfd, | |
1236 | section, | |
1237 | isym.st_value, | |
1238 | bytes)) | |
1239 | goto error_return; | |
1240 | ||
1241 | /* Something changed. Not strictly necessary, but | |
1242 | may lead to more relaxing opportunities. */ | |
1243 | *again = true; | |
1244 | } | |
1245 | } | |
1246 | ||
1247 | /* Look for any global functions in this section which | |
1248 | need insns deleted from their prologues. */ | |
1249 | esym = extsyms + symtab_hdr->sh_info; | |
1250 | esymend = extsyms + (symtab_hdr->sh_size | |
1251 | / sizeof (Elf32_External_Sym)); | |
1252 | for (idx = 0; esym < esymend; esym++, idx++) | |
1253 | { | |
1254 | Elf_Internal_Sym isym; | |
1255 | struct elf32_mn10300_link_hash_entry *sym_hash; | |
1256 | ||
1257 | bfd_elf32_swap_symbol_in (input_bfd, esym, &isym); | |
1258 | sym_hash = (struct elf32_mn10300_link_hash_entry *) | |
1259 | (elf_sym_hashes (input_bfd)[idx]); | |
1260 | if (isym.st_shndx == shndx | |
1261 | && (sym_hash)->root.root.u.def.section == section | |
1262 | && ! ((sym_hash)->flags & MN10300_CONVERT_CALL_TO_CALLS) | |
1263 | && ! ((sym_hash)->flags & MN10300_DELETED_PROLOGUE_BYTES)) | |
1264 | { | |
1265 | int bytes = 0; | |
1266 | ||
1267 | /* Note that we've changed things. */ | |
1268 | elf_section_data (section)->relocs = internal_relocs; | |
1269 | free_relocs = NULL; | |
1270 | ||
1271 | elf_section_data (section)->this_hdr.contents = contents; | |
1272 | free_contents = NULL; | |
1273 | ||
1274 | symtab_hdr->contents = (bfd_byte *)extsyms; | |
1275 | free_extsyms = NULL; | |
1276 | ||
1277 | /* Count how many bytes we're going to delete. */ | |
1278 | if (sym_hash->movm_args) | |
1279 | bytes += 2; | |
1280 | ||
1281 | if (sym_hash->stack_size && sym_hash->stack_size <= 128) | |
1282 | bytes += 3; | |
1283 | else if (sym_hash->stack_size | |
1284 | && sym_hash->stack_size < 256) | |
1285 | bytes += 4; | |
1286 | ||
1287 | /* Note that we've deleted prologue bytes for this | |
1288 | function. */ | |
1289 | sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES; | |
1290 | ||
1291 | /* Actually delete the bytes. */ | |
1292 | if (!mn10300_elf_relax_delete_bytes (input_bfd, | |
1293 | section, | |
1294 | (sym_hash)->root.root.u.def.value, | |
1295 | bytes)) | |
1296 | goto error_return; | |
1297 | ||
1298 | /* Something changed. Not strictly necessary, but | |
1299 | may lead to more relaxing opportunities. */ | |
1300 | *again = true; | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | /* Cache or free any memory we allocated for the relocs. */ | |
1305 | if (free_relocs != NULL) | |
1306 | { | |
1307 | free (free_relocs); | |
1308 | free_relocs = NULL; | |
1309 | } | |
1310 | ||
1311 | /* Cache or free any memory we allocated for the contents. */ | |
1312 | if (free_contents != NULL) | |
1313 | { | |
1314 | if (! link_info->keep_memory) | |
1315 | free (free_contents); | |
1316 | else | |
1317 | { | |
1318 | /* Cache the section contents for elf_link_input_bfd. */ | |
1319 | elf_section_data (section)->this_hdr.contents = contents; | |
1320 | } | |
1321 | free_contents = NULL; | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | /* Cache or free any memory we allocated for the symbols. */ | |
1326 | if (free_extsyms != NULL) | |
1327 | { | |
1328 | if (! link_info->keep_memory) | |
1329 | free (free_extsyms); | |
1330 | else | |
1331 | { | |
1332 | /* Cache the symbols for elf_link_input_bfd. */ | |
1333 | symtab_hdr->contents = extsyms; | |
1334 | } | |
1335 | free_extsyms = NULL; | |
1336 | } | |
1337 | } | |
1338 | } | |
1339 | ||
1340 | ||
1341 | /* (Re)initialize for the basic instruction shortening/relaxing pass. */ | |
1342 | contents = NULL; | |
1343 | extsyms = NULL; | |
1344 | internal_relocs = NULL; | |
1345 | free_relocs = NULL; | |
1346 | free_contents = NULL; | |
1347 | free_extsyms = NULL; | |
1348 | ||
a01362cc JL |
1349 | /* We don't have to do anything for a relocateable link, if |
1350 | this section does not have relocs, or if this is not a | |
1351 | code section. */ | |
1352 | if (link_info->relocateable | |
1353 | || (sec->flags & SEC_RELOC) == 0 | |
1354 | || sec->reloc_count == 0 | |
1355 | || (sec->flags & SEC_CODE) == 0) | |
1356 | return true; | |
1357 | ||
1358 | /* If this is the first time we have been called for this section, | |
1359 | initialize the cooked size. */ | |
1360 | if (sec->_cooked_size == 0) | |
1361 | sec->_cooked_size = sec->_raw_size; | |
1362 | ||
1363 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
1364 | ||
1365 | /* Get a copy of the native relocations. */ | |
1366 | internal_relocs = (_bfd_elf32_link_read_relocs | |
1367 | (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, | |
1368 | link_info->keep_memory)); | |
1369 | if (internal_relocs == NULL) | |
1370 | goto error_return; | |
1371 | if (! link_info->keep_memory) | |
1372 | free_relocs = internal_relocs; | |
1373 | ||
1374 | /* Walk through them looking for relaxing opportunities. */ | |
1375 | irelend = internal_relocs + sec->reloc_count; | |
1376 | for (irel = internal_relocs; irel < irelend; irel++) | |
1377 | { | |
1378 | bfd_vma symval; | |
4db4e912 | 1379 | struct elf32_mn10300_link_hash_entry *h = NULL; |
a01362cc JL |
1380 | |
1381 | /* If this isn't something that can be relaxed, then ignore | |
1382 | this reloc. */ | |
1383 | if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE | |
1384 | || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8 | |
1385 | || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX) | |
1386 | continue; | |
1387 | ||
1388 | /* Get the section contents if we haven't done so already. */ | |
1389 | if (contents == NULL) | |
1390 | { | |
1391 | /* Get cached copy if it exists. */ | |
1392 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
1393 | contents = elf_section_data (sec)->this_hdr.contents; | |
1394 | else | |
1395 | { | |
1396 | /* Go get them off disk. */ | |
1397 | contents = (bfd_byte *) bfd_malloc (sec->_raw_size); | |
1398 | if (contents == NULL) | |
1399 | goto error_return; | |
1400 | free_contents = contents; | |
1401 | ||
1402 | if (! bfd_get_section_contents (abfd, sec, contents, | |
1403 | (file_ptr) 0, sec->_raw_size)) | |
1404 | goto error_return; | |
1405 | } | |
1406 | } | |
1407 | ||
4db4e912 | 1408 | /* Read this BFD's symbols if we haven't done so already. */ |
a01362cc JL |
1409 | if (extsyms == NULL) |
1410 | { | |
1411 | /* Get cached copy if it exists. */ | |
1412 | if (symtab_hdr->contents != NULL) | |
1413 | extsyms = (Elf32_External_Sym *) symtab_hdr->contents; | |
1414 | else | |
1415 | { | |
1416 | /* Go get them off disk. */ | |
1417 | extsyms = ((Elf32_External_Sym *) | |
4db4e912 | 1418 | bfd_malloc (symtab_hdr->sh_size)); |
a01362cc JL |
1419 | if (extsyms == NULL) |
1420 | goto error_return; | |
1421 | free_extsyms = extsyms; | |
1422 | if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0 | |
4db4e912 JL |
1423 | || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd) |
1424 | != symtab_hdr->sh_size)) | |
a01362cc JL |
1425 | goto error_return; |
1426 | } | |
1427 | } | |
1428 | ||
1429 | /* Get the value of the symbol referred to by the reloc. */ | |
1430 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) | |
1431 | { | |
1432 | Elf_Internal_Sym isym; | |
1433 | asection *sym_sec; | |
4db4e912 JL |
1434 | Elf_Internal_Shdr *hdr; |
1435 | const char *sym_name; | |
1436 | char *new_name; | |
a01362cc JL |
1437 | |
1438 | /* A local symbol. */ | |
1439 | bfd_elf32_swap_symbol_in (abfd, | |
1440 | extsyms + ELF32_R_SYM (irel->r_info), | |
1441 | &isym); | |
1442 | ||
4db4e912 JL |
1443 | if (isym.st_shndx == SHN_UNDEF) |
1444 | sym_sec = bfd_und_section_ptr; | |
1445 | else if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE) | |
1446 | sym_sec = bfd_section_from_elf_index (abfd, isym.st_shndx); | |
1447 | else if (isym.st_shndx == SHN_ABS) | |
1448 | sym_sec = bfd_abs_section_ptr; | |
1449 | else if (isym.st_shndx == SHN_COMMON) | |
1450 | sym_sec = bfd_com_section_ptr; | |
1451 | ||
a01362cc JL |
1452 | symval = (isym.st_value |
1453 | + sym_sec->output_section->vma | |
1454 | + sym_sec->output_offset); | |
4db4e912 JL |
1455 | sym_name = bfd_elf_string_from_elf_section (abfd, |
1456 | symtab_hdr->sh_link, | |
1457 | isym.st_name); | |
1458 | ||
1459 | /* Tack on an ID so we can uniquely identify this | |
1460 | local symbol in the global hash table. */ | |
1461 | new_name = alloca (strlen (sym_name) + 10); | |
1462 | sprintf (new_name, "%s_%08x", sym_name, (int)sym_sec); | |
1463 | sym_name = new_name; | |
1464 | ||
1465 | h = (struct elf32_mn10300_link_hash_entry *) | |
1466 | elf_link_hash_lookup (&hash_table->static_hash_table->root, | |
1467 | sym_name, false, false, false); | |
a01362cc JL |
1468 | } |
1469 | else | |
1470 | { | |
1471 | unsigned long indx; | |
a01362cc JL |
1472 | |
1473 | /* An external symbol. */ | |
1474 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; | |
4db4e912 JL |
1475 | h = (struct elf32_mn10300_link_hash_entry *) |
1476 | (elf_sym_hashes (abfd)[indx]); | |
a01362cc | 1477 | BFD_ASSERT (h != NULL); |
4db4e912 JL |
1478 | if (h->root.root.type != bfd_link_hash_defined |
1479 | && h->root.root.type != bfd_link_hash_defweak) | |
a01362cc JL |
1480 | { |
1481 | /* This appears to be a reference to an undefined | |
4db4e912 JL |
1482 | symbol. Just ignore it--it will be caught by the |
1483 | regular reloc processing. */ | |
a01362cc JL |
1484 | continue; |
1485 | } | |
1486 | ||
4db4e912 JL |
1487 | symval = (h->root.root.u.def.value |
1488 | + h->root.root.u.def.section->output_section->vma | |
1489 | + h->root.root.u.def.section->output_offset); | |
a01362cc JL |
1490 | } |
1491 | ||
1492 | /* For simplicity of coding, we are going to modify the section | |
1493 | contents, the section relocs, and the BFD symbol table. We | |
1494 | must tell the rest of the code not to free up this | |
1495 | information. It would be possible to instead create a table | |
1496 | of changes which have to be made, as is done in coff-mips.c; | |
1497 | that would be more work, but would require less memory when | |
1498 | the linker is run. */ | |
1499 | ||
a01362cc | 1500 | /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative |
4db4e912 JL |
1501 | branch/call, also deal with "call" -> "calls" conversions and |
1502 | insertion of prologue data into "call" instructions. */ | |
a01362cc JL |
1503 | if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32) |
1504 | { | |
1505 | bfd_vma value = symval; | |
1506 | ||
4db4e912 JL |
1507 | /* If we've got a "call" instruction that needs to be turned |
1508 | into a "calls" instruction, do so now. It saves a byte. */ | |
1509 | if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS)) | |
1510 | { | |
1511 | unsigned char code; | |
1512 | ||
1513 | /* Get the opcode. */ | |
1514 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1515 | ||
1516 | /* Make sure we're working with a "call" instruction! */ | |
1517 | if (code == 0xdd) | |
1518 | { | |
1519 | /* Note that we've changed the relocs, section contents, | |
1520 | etc. */ | |
1521 | elf_section_data (sec)->relocs = internal_relocs; | |
1522 | free_relocs = NULL; | |
1523 | ||
1524 | elf_section_data (sec)->this_hdr.contents = contents; | |
1525 | free_contents = NULL; | |
1526 | ||
1527 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1528 | free_extsyms = NULL; | |
1529 | ||
1530 | /* Fix the opcode. */ | |
1531 | bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1); | |
1532 | bfd_put_8 (abfd, 0xff, contents + irel->r_offset); | |
1533 | ||
1534 | /* Fix irel->r_offset and irel->r_addend. */ | |
1535 | irel->r_offset += 1; | |
1536 | irel->r_addend += 1; | |
1537 | ||
1538 | /* Delete one byte of data. */ | |
1539 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
1540 | irel->r_offset + 3, 1)) | |
1541 | goto error_return; | |
1542 | ||
1543 | /* That will change things, so, we should relax again. | |
1544 | Note that this is not required, and it may be slow. */ | |
1545 | *again = true; | |
1546 | } | |
1547 | } | |
1548 | else if (h) | |
1549 | { | |
1550 | /* We've got a "call" instruction which needs some data | |
1551 | from target function filled in. */ | |
1552 | unsigned char code; | |
1553 | ||
1554 | /* Get the opcode. */ | |
1555 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1556 | ||
1557 | /* Insert data from the target function into the "call" | |
1558 | instruction if needed. */ | |
1559 | if (code == 0xdd) | |
1560 | { | |
1561 | bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4); | |
1562 | bfd_put_8 (abfd, h->stack_size, | |
1563 | contents + irel->r_offset + 5); | |
1564 | } | |
1565 | } | |
1566 | ||
a01362cc JL |
1567 | /* Deal with pc-relative gunk. */ |
1568 | value -= (sec->output_section->vma + sec->output_offset); | |
1569 | value -= irel->r_offset; | |
1570 | value += irel->r_addend; | |
1571 | ||
1572 | /* See if the value will fit in 16 bits, note the high value is | |
1573 | 0x7fff + 2 as the target will be two bytes closer if we are | |
1574 | able to relax. */ | |
1575 | if ((long)value < 0x8001 && (long)value > -0x8000) | |
1576 | { | |
1577 | unsigned char code; | |
1578 | ||
1579 | /* Get the opcode. */ | |
1580 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1581 | ||
4db4e912 | 1582 | if (code != 0xdc && code != 0xdd && code != 0xff) |
a01362cc JL |
1583 | continue; |
1584 | ||
1585 | /* Note that we've changed the relocs, section contents, etc. */ | |
1586 | elf_section_data (sec)->relocs = internal_relocs; | |
1587 | free_relocs = NULL; | |
1588 | ||
1589 | elf_section_data (sec)->this_hdr.contents = contents; | |
1590 | free_contents = NULL; | |
1591 | ||
1592 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1593 | free_extsyms = NULL; | |
1594 | ||
1595 | /* Fix the opcode. */ | |
1596 | if (code == 0xdc) | |
1597 | bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1); | |
4db4e912 JL |
1598 | else if (code == 0xdd) |
1599 | bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1); | |
a01362cc JL |
1600 | else if (code == 0xff) |
1601 | bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); | |
1602 | ||
1603 | /* Fix the relocation's type. */ | |
1604 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
1605 | R_MN10300_PCREL16); | |
1606 | ||
1607 | /* Delete two bytes of data. */ | |
1608 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
1609 | irel->r_offset + 1, 2)) | |
1610 | goto error_return; | |
1611 | ||
1612 | /* That will change things, so, we should relax again. | |
1613 | Note that this is not required, and it may be slow. */ | |
1614 | *again = true; | |
1615 | } | |
1616 | } | |
1617 | ||
1618 | /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative | |
1619 | branch. */ | |
1620 | if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16) | |
1621 | { | |
1622 | bfd_vma value = symval; | |
1623 | ||
4db4e912 JL |
1624 | /* If we've got a "call" instruction that needs to be turned |
1625 | into a "calls" instruction, do so now. It saves a byte. */ | |
1626 | if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS)) | |
1627 | { | |
1628 | unsigned char code; | |
1629 | ||
1630 | /* Get the opcode. */ | |
1631 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1632 | ||
1633 | /* Make sure we're working with a "call" instruction! */ | |
1634 | if (code == 0xcd) | |
1635 | { | |
1636 | /* Note that we've changed the relocs, section contents, | |
1637 | etc. */ | |
1638 | elf_section_data (sec)->relocs = internal_relocs; | |
1639 | free_relocs = NULL; | |
1640 | ||
1641 | elf_section_data (sec)->this_hdr.contents = contents; | |
1642 | free_contents = NULL; | |
1643 | ||
1644 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1645 | free_extsyms = NULL; | |
1646 | ||
1647 | /* Fix the opcode. */ | |
1648 | bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1); | |
1649 | bfd_put_8 (abfd, 0xff, contents + irel->r_offset); | |
1650 | ||
1651 | /* Fix irel->r_offset and irel->r_addend. */ | |
1652 | irel->r_offset += 1; | |
1653 | irel->r_addend += 1; | |
1654 | ||
1655 | /* Delete one byte of data. */ | |
1656 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
1657 | irel->r_offset + 1, 1)) | |
1658 | goto error_return; | |
1659 | ||
1660 | /* That will change things, so, we should relax again. | |
1661 | Note that this is not required, and it may be slow. */ | |
1662 | *again = true; | |
1663 | } | |
1664 | } | |
1665 | else if (h) | |
1666 | { | |
1667 | unsigned char code; | |
1668 | ||
1669 | /* Get the opcode. */ | |
1670 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1671 | ||
1672 | /* Insert data from the target function into the "call" | |
1673 | instruction if needed. */ | |
1674 | if (code == 0xcd) | |
1675 | { | |
1676 | bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2); | |
1677 | bfd_put_8 (abfd, h->stack_size, | |
1678 | contents + irel->r_offset + 3); | |
1679 | } | |
1680 | } | |
1681 | ||
a01362cc JL |
1682 | /* Deal with pc-relative gunk. */ |
1683 | value -= (sec->output_section->vma + sec->output_offset); | |
1684 | value -= irel->r_offset; | |
1685 | value += irel->r_addend; | |
1686 | ||
1687 | /* See if the value will fit in 8 bits, note the high value is | |
1688 | 0x7f + 1 as the target will be one bytes closer if we are | |
1689 | able to relax. */ | |
1690 | if ((long)value < 0x80 && (long)value > -0x80) | |
1691 | { | |
1692 | unsigned char code; | |
1693 | ||
1694 | /* Get the opcode. */ | |
1695 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1696 | ||
1697 | if (code != 0xcc) | |
1698 | continue; | |
1699 | ||
1700 | /* Note that we've changed the relocs, section contents, etc. */ | |
1701 | elf_section_data (sec)->relocs = internal_relocs; | |
1702 | free_relocs = NULL; | |
1703 | ||
1704 | elf_section_data (sec)->this_hdr.contents = contents; | |
1705 | free_contents = NULL; | |
1706 | ||
1707 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1708 | free_extsyms = NULL; | |
1709 | ||
1710 | /* Fix the opcode. */ | |
1711 | bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1); | |
1712 | ||
1713 | /* Fix the relocation's type. */ | |
1714 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
1715 | R_MN10300_PCREL8); | |
1716 | ||
1717 | /* Delete one byte of data. */ | |
1718 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
1719 | irel->r_offset + 1, 1)) | |
1720 | goto error_return; | |
1721 | ||
1722 | /* That will change things, so, we should relax again. | |
1723 | Note that this is not required, and it may be slow. */ | |
1724 | *again = true; | |
1725 | } | |
1726 | } | |
1727 | ||
1728 | /* Try to eliminate an unconditional 8 bit pc-relative branch | |
1729 | which immediately follows a conditional 8 bit pc-relative | |
1730 | branch around the unconditional branch. | |
1731 | ||
1732 | original: new: | |
1733 | bCC lab1 bCC' lab2 | |
1734 | bra lab2 | |
1735 | lab1: lab1: | |
1736 | ||
1737 | ||
1738 | This happens when the bCC can't reach lab2 at assembly time, | |
1739 | but due to other relaxations it can reach at link time. */ | |
1740 | if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8) | |
1741 | { | |
1742 | Elf_Internal_Rela *nrel; | |
1743 | bfd_vma value = symval; | |
1744 | unsigned char code; | |
1745 | ||
1746 | /* Deal with pc-relative gunk. */ | |
1747 | value -= (sec->output_section->vma + sec->output_offset); | |
1748 | value -= irel->r_offset; | |
1749 | value += irel->r_addend; | |
1750 | ||
1751 | /* Do nothing if this reloc is the last byte in the section. */ | |
1752 | if (irel->r_offset == sec->_cooked_size) | |
1753 | continue; | |
1754 | ||
1755 | /* See if the next instruction is an unconditional pc-relative | |
1756 | branch, more often than not this test will fail, so we | |
1757 | test it first to speed things up. */ | |
1758 | code = bfd_get_8 (abfd, contents + irel->r_offset + 1); | |
1759 | if (code != 0xca) | |
1760 | continue; | |
1761 | ||
1762 | /* Also make sure the next relocation applies to the next | |
1763 | instruction and that it's a pc-relative 8 bit branch. */ | |
1764 | nrel = irel + 1; | |
1765 | if (nrel == irelend | |
1766 | || irel->r_offset + 2 != nrel->r_offset | |
1767 | || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8) | |
1768 | continue; | |
1769 | ||
1770 | /* Make sure our destination immediately follows the | |
1771 | unconditional branch. */ | |
1772 | if (symval != (sec->output_section->vma + sec->output_offset | |
1773 | + irel->r_offset + 3)) | |
1774 | continue; | |
1775 | ||
1776 | /* Now make sure we are a conditional branch. This may not | |
1777 | be necessary, but why take the chance. | |
1778 | ||
1779 | Note these checks assume that R_MN10300_PCREL8 relocs | |
1780 | only occur on bCC and bCCx insns. If they occured | |
1781 | elsewhere, we'd need to know the start of this insn | |
1782 | for this check to be accurate. */ | |
1783 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1784 | if (code != 0xc0 && code != 0xc1 && code != 0xc2 | |
1785 | && code != 0xc3 && code != 0xc4 && code != 0xc5 | |
1786 | && code != 0xc6 && code != 0xc7 && code != 0xc8 | |
1787 | && code != 0xc9 && code != 0xe8 && code != 0xe9 | |
1788 | && code != 0xea && code != 0xeb) | |
1789 | continue; | |
1790 | ||
1791 | /* We also have to be sure there is no symbol/label | |
1792 | at the unconditional branch. */ | |
1793 | if (mn10300_elf_symbol_address_p (abfd, sec, extsyms, | |
1794 | irel->r_offset + 1)) | |
1795 | continue; | |
1796 | ||
1797 | /* Note that we've changed the relocs, section contents, etc. */ | |
1798 | elf_section_data (sec)->relocs = internal_relocs; | |
1799 | free_relocs = NULL; | |
1800 | ||
1801 | elf_section_data (sec)->this_hdr.contents = contents; | |
1802 | free_contents = NULL; | |
1803 | ||
1804 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1805 | free_extsyms = NULL; | |
1806 | ||
1807 | /* Reverse the condition of the first branch. */ | |
1808 | switch (code) | |
1809 | { | |
1810 | case 0xc8: | |
1811 | code = 0xc9; | |
1812 | break; | |
1813 | case 0xc9: | |
1814 | code = 0xc8; | |
1815 | break; | |
1816 | case 0xc0: | |
1817 | code = 0xc2; | |
1818 | break; | |
1819 | case 0xc2: | |
1820 | code = 0xc0; | |
1821 | break; | |
1822 | case 0xc3: | |
1823 | code = 0xc1; | |
1824 | break; | |
1825 | case 0xc1: | |
1826 | code = 0xc3; | |
1827 | break; | |
1828 | case 0xc4: | |
1829 | code = 0xc6; | |
1830 | break; | |
1831 | case 0xc6: | |
1832 | code = 0xc4; | |
1833 | break; | |
1834 | case 0xc7: | |
1835 | code = 0xc5; | |
1836 | break; | |
1837 | case 0xc5: | |
1838 | code = 0xc7; | |
1839 | break; | |
1840 | case 0xe8: | |
1841 | code = 0xe9; | |
1842 | break; | |
1843 | case 0x9d: | |
1844 | code = 0xe8; | |
1845 | break; | |
1846 | case 0xea: | |
1847 | code = 0xeb; | |
1848 | break; | |
1849 | case 0xeb: | |
1850 | code = 0xea; | |
1851 | break; | |
1852 | } | |
1853 | bfd_put_8 (abfd, code, contents + irel->r_offset - 1); | |
1854 | ||
1855 | /* Set the reloc type and symbol for the first branch | |
1856 | from the second branch. */ | |
1857 | irel->r_info = nrel->r_info; | |
1858 | ||
1859 | /* Make the reloc for the second branch a null reloc. */ | |
1860 | nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info), | |
1861 | R_MN10300_NONE); | |
1862 | ||
1863 | /* Delete two bytes of data. */ | |
1864 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
1865 | irel->r_offset + 1, 2)) | |
1866 | goto error_return; | |
1867 | ||
1868 | /* That will change things, so, we should relax again. | |
1869 | Note that this is not required, and it may be slow. */ | |
1870 | *again = true; | |
1871 | } | |
1872 | ||
1873 | /* Try to turn a 32bit immediate, displacement or absolute address | |
1874 | into a 16bit immediate, displacement or absolute address. */ | |
1875 | if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32) | |
1876 | { | |
1877 | bfd_vma value = symval; | |
4db4e912 | 1878 | value += irel->r_addend; |
a01362cc JL |
1879 | |
1880 | /* See if the value will fit in 16 bits. | |
1881 | We allow any 16bit match here. We prune those we can't | |
1882 | handle below. */ | |
1883 | if ((long)value < 0x7fff && (long)value > -0x8000) | |
1884 | { | |
1885 | unsigned char code; | |
1886 | ||
1887 | /* Most insns which have 32bit operands are 6 bytes long; | |
1888 | exceptions are pcrel insns and bit insns. | |
1889 | ||
1890 | We handle pcrel insns above. We don't bother trying | |
1891 | to handle the bit insns here. | |
1892 | ||
1893 | The first byte of the remaining insns will be 0xfc. */ | |
1894 | ||
1895 | /* Get the first opcode. */ | |
1896 | code = bfd_get_8 (abfd, contents + irel->r_offset - 2); | |
1897 | ||
1898 | if (code != 0xfc) | |
1899 | continue; | |
1900 | ||
1901 | /* Get the second opcode. */ | |
1902 | code = bfd_get_8 (abfd, contents + irel->r_offset - 1); | |
1903 | ||
1904 | if ((code & 0xf0) < 0x80) | |
1905 | switch (code & 0xf0) | |
1906 | { | |
1907 | /* mov (d32,am),dn -> mov (d32,am),dn | |
1908 | mov dm,(d32,am) -> mov dn,(d32,am) | |
1909 | mov (d32,am),an -> mov (d32,am),an | |
1910 | mov dm,(d32,am) -> mov dn,(d32,am) | |
1911 | movbu (d32,am),dn -> movbu (d32,am),dn | |
1912 | movbu dm,(d32,am) -> movbu dn,(d32,am) | |
1913 | movhu (d32,am),dn -> movhu (d32,am),dn | |
1914 | movhu dm,(d32,am) -> movhu dn,(d32,am) */ | |
1915 | case 0x00: | |
1916 | case 0x10: | |
1917 | case 0x20: | |
1918 | case 0x30: | |
1919 | case 0x40: | |
1920 | case 0x50: | |
1921 | case 0x60: | |
1922 | case 0x70: | |
1923 | /* Not safe if the high bit is on as relaxing may | |
1924 | move the value out of high mem and thus not fit | |
1925 | in a signed 16bit value. */ | |
1926 | if (code == 0xcc | |
1927 | && (value & 0x8000)) | |
1928 | continue; | |
1929 | ||
1930 | /* Note that we've changed the relocation contents, etc. */ | |
1931 | elf_section_data (sec)->relocs = internal_relocs; | |
1932 | free_relocs = NULL; | |
1933 | ||
1934 | elf_section_data (sec)->this_hdr.contents = contents; | |
1935 | free_contents = NULL; | |
1936 | ||
1937 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1938 | free_extsyms = NULL; | |
1939 | ||
1940 | /* Fix the opcode. */ | |
1941 | bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); | |
1942 | bfd_put_8 (abfd, code, contents + irel->r_offset - 1); | |
1943 | ||
1944 | /* Fix the relocation's type. */ | |
1945 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
1946 | R_MN10300_16); | |
1947 | ||
1948 | /* Delete two bytes of data. */ | |
1949 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
1950 | irel->r_offset + 2, 2)) | |
1951 | goto error_return; | |
1952 | ||
1953 | /* That will change things, so, we should relax again. | |
1954 | Note that this is not required, and it may be slow. */ | |
1955 | *again = true; | |
1956 | break; | |
1957 | } | |
1958 | else if ((code & 0xf0) == 0x80 | |
1959 | || (code & 0xf0) == 0x90) | |
4db4e912 | 1960 | switch (code & 0xf3) |
a01362cc JL |
1961 | { |
1962 | /* mov dn,(abs32) -> mov dn,(abs16) | |
1963 | movbu dn,(abs32) -> movbu dn,(abs16) | |
1964 | movhu dn,(abs32) -> movhu dn,(abs16) */ | |
1965 | case 0x81: | |
1966 | case 0x82: | |
1967 | case 0x83: | |
1968 | /* Note that we've changed the relocation contents, etc. */ | |
1969 | elf_section_data (sec)->relocs = internal_relocs; | |
1970 | free_relocs = NULL; | |
1971 | ||
1972 | elf_section_data (sec)->this_hdr.contents = contents; | |
1973 | free_contents = NULL; | |
1974 | ||
1975 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
1976 | free_extsyms = NULL; | |
1977 | ||
1978 | if ((code & 0xf3) == 0x81) | |
1979 | code = 0x01 + (code & 0x0c); | |
1980 | else if ((code & 0xf3) == 0x82) | |
1981 | code = 0x02 + (code & 0x0c); | |
1982 | else if ((code & 0xf3) == 0x83) | |
1983 | code = 0x03 + (code & 0x0c); | |
1984 | else | |
1985 | abort (); | |
1986 | ||
1987 | /* Fix the opcode. */ | |
1988 | bfd_put_8 (abfd, code, contents + irel->r_offset - 2); | |
1989 | ||
1990 | /* Fix the relocation's type. */ | |
1991 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
1992 | R_MN10300_16); | |
1993 | ||
1994 | /* The opcode got shorter too, so we have to fix the | |
1995 | addend and offset too! */ | |
1996 | irel->r_offset -= 1; | |
1997 | ||
1998 | /* Delete three bytes of data. */ | |
1999 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
2000 | irel->r_offset + 1, 3)) | |
2001 | goto error_return; | |
2002 | ||
2003 | /* That will change things, so, we should relax again. | |
2004 | Note that this is not required, and it may be slow. */ | |
2005 | *again = true; | |
2006 | break; | |
2007 | ||
2008 | /* mov am,(abs32) -> mov am,(abs16) | |
2009 | mov am,(d32,sp) -> mov am,(d16,sp) | |
2010 | mov dm,(d32,sp) -> mov dm,(d32,sp) | |
2011 | movbu dm,(d32,sp) -> movbu dm,(d32,sp) | |
2012 | movhu dm,(d32,sp) -> movhu dm,(d32,sp) */ | |
2013 | case 0x80: | |
2014 | case 0x90: | |
2015 | case 0x91: | |
2016 | case 0x92: | |
2017 | case 0x93: | |
2018 | /* Note that we've changed the relocation contents, etc. */ | |
2019 | elf_section_data (sec)->relocs = internal_relocs; | |
2020 | free_relocs = NULL; | |
2021 | ||
2022 | elf_section_data (sec)->this_hdr.contents = contents; | |
2023 | free_contents = NULL; | |
2024 | ||
2025 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
2026 | free_extsyms = NULL; | |
2027 | ||
2028 | /* Fix the opcode. */ | |
2029 | bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); | |
2030 | bfd_put_8 (abfd, code, contents + irel->r_offset - 1); | |
2031 | ||
2032 | /* Fix the relocation's type. */ | |
2033 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
2034 | R_MN10300_16); | |
2035 | ||
2036 | /* Delete two bytes of data. */ | |
2037 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
2038 | irel->r_offset + 2, 2)) | |
2039 | goto error_return; | |
2040 | ||
2041 | /* That will change things, so, we should relax again. | |
2042 | Note that this is not required, and it may be slow. */ | |
2043 | *again = true; | |
2044 | break; | |
2045 | } | |
2046 | else if ((code & 0xf0) < 0xf0) | |
4db4e912 | 2047 | switch (code & 0xfc) |
a01362cc JL |
2048 | { |
2049 | /* mov imm32,dn -> mov imm16,dn | |
2050 | mov imm32,an -> mov imm16,an | |
2051 | mov (abs32),dn -> mov (abs16),dn | |
2052 | movbu (abs32),dn -> movbu (abs16),dn | |
2053 | movhu (abs32),dn -> movhu (abs16),dn */ | |
2054 | case 0xcc: | |
2055 | case 0xdc: | |
2056 | case 0xa4: | |
2057 | case 0xa8: | |
2058 | case 0xac: | |
2059 | /* Not safe if the high bit is on as relaxing may | |
2060 | move the value out of high mem and thus not fit | |
2061 | in a signed 16bit value. */ | |
2062 | if (code == 0xcc | |
2063 | && (value & 0x8000)) | |
2064 | continue; | |
2065 | ||
2066 | /* Note that we've changed the relocation contents, etc. */ | |
2067 | elf_section_data (sec)->relocs = internal_relocs; | |
2068 | free_relocs = NULL; | |
2069 | ||
2070 | elf_section_data (sec)->this_hdr.contents = contents; | |
2071 | free_contents = NULL; | |
2072 | ||
2073 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
2074 | free_extsyms = NULL; | |
2075 | ||
2076 | if ((code & 0xfc) == 0xcc) | |
2077 | code = 0x2c + (code & 0x03); | |
2078 | else if ((code & 0xfc) == 0xdc) | |
2079 | code = 0x24 + (code & 0x03); | |
2080 | else if ((code & 0xfc) == 0xa4) | |
2081 | code = 0x30 + (code & 0x03); | |
2082 | else if ((code & 0xfc) == 0xa8) | |
2083 | code = 0x34 + (code & 0x03); | |
2084 | else if ((code & 0xfc) == 0xac) | |
2085 | code = 0x38 + (code & 0x03); | |
2086 | else | |
2087 | abort (); | |
2088 | ||
2089 | /* Fix the opcode. */ | |
2090 | bfd_put_8 (abfd, code, contents + irel->r_offset - 2); | |
2091 | ||
2092 | /* Fix the relocation's type. */ | |
2093 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
2094 | R_MN10300_16); | |
2095 | ||
2096 | /* The opcode got shorter too, so we have to fix the | |
2097 | addend and offset too! */ | |
2098 | irel->r_offset -= 1; | |
2099 | ||
2100 | /* Delete three bytes of data. */ | |
2101 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
2102 | irel->r_offset + 1, 3)) | |
2103 | goto error_return; | |
2104 | ||
2105 | /* That will change things, so, we should relax again. | |
2106 | Note that this is not required, and it may be slow. */ | |
2107 | *again = true; | |
2108 | break; | |
2109 | ||
2110 | /* mov (abs32),an -> mov (abs16),an | |
2111 | mov (d32,sp),an -> mov (d32,sp),an | |
2112 | mov (d32,sp),dn -> mov (d32,sp),dn | |
2113 | movbu (d32,sp),dn -> movbu (d32,sp),dn | |
2114 | movhu (d32,sp),dn -> movhu (d32,sp),dn | |
2115 | add imm32,dn -> add imm16,dn | |
2116 | cmp imm32,dn -> cmp imm16,dn | |
2117 | add imm32,an -> add imm16,an | |
2118 | cmp imm32,an -> cmp imm16,an | |
2119 | and imm32,dn -> and imm32,dn | |
2120 | or imm32,dn -> or imm32,dn | |
2121 | xor imm32,dn -> xor imm32,dn | |
2122 | btst imm32,dn -> btst imm32,dn */ | |
2123 | ||
2124 | case 0xa0: | |
2125 | case 0xb0: | |
2126 | case 0xb1: | |
2127 | case 0xb2: | |
2128 | case 0xb3: | |
2129 | case 0xc0: | |
2130 | case 0xc8: | |
2131 | ||
2132 | case 0xd0: | |
a01362cc | 2133 | case 0xd8: |
a01362cc JL |
2134 | case 0xe0: |
2135 | case 0xe1: | |
2136 | case 0xe2: | |
2137 | case 0xe3: | |
2138 | /* Note that we've changed the relocation contents, etc. */ | |
2139 | elf_section_data (sec)->relocs = internal_relocs; | |
2140 | free_relocs = NULL; | |
2141 | ||
2142 | elf_section_data (sec)->this_hdr.contents = contents; | |
2143 | free_contents = NULL; | |
2144 | ||
2145 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
2146 | free_extsyms = NULL; | |
2147 | ||
2148 | /* Fix the opcode. */ | |
2149 | bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); | |
2150 | bfd_put_8 (abfd, code, contents + irel->r_offset - 1); | |
2151 | ||
2152 | /* Fix the relocation's type. */ | |
2153 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
2154 | R_MN10300_16); | |
2155 | ||
2156 | /* Delete two bytes of data. */ | |
2157 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
2158 | irel->r_offset + 2, 2)) | |
2159 | goto error_return; | |
2160 | ||
2161 | /* That will change things, so, we should relax again. | |
2162 | Note that this is not required, and it may be slow. */ | |
2163 | *again = true; | |
2164 | break; | |
2165 | } | |
2166 | else if (code == 0xfe) | |
2167 | { | |
2168 | /* add imm32,sp -> add imm16,sp */ | |
2169 | ||
2170 | /* Note that we've changed the relocation contents, etc. */ | |
2171 | elf_section_data (sec)->relocs = internal_relocs; | |
2172 | free_relocs = NULL; | |
2173 | ||
2174 | elf_section_data (sec)->this_hdr.contents = contents; | |
2175 | free_contents = NULL; | |
2176 | ||
2177 | symtab_hdr->contents = (bfd_byte *) extsyms; | |
2178 | free_extsyms = NULL; | |
2179 | ||
2180 | /* Fix the opcode. */ | |
2181 | bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2); | |
2182 | bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1); | |
2183 | ||
2184 | /* Fix the relocation's type. */ | |
2185 | irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), | |
2186 | R_MN10300_16); | |
2187 | ||
2188 | /* Delete two bytes of data. */ | |
2189 | if (!mn10300_elf_relax_delete_bytes (abfd, sec, | |
2190 | irel->r_offset + 2, 2)) | |
2191 | goto error_return; | |
2192 | ||
2193 | /* That will change things, so, we should relax again. | |
2194 | Note that this is not required, and it may be slow. */ | |
2195 | *again = true; | |
2196 | break; | |
2197 | } | |
2198 | } | |
2199 | } | |
2200 | } | |
2201 | ||
2202 | if (free_relocs != NULL) | |
2203 | { | |
2204 | free (free_relocs); | |
2205 | free_relocs = NULL; | |
2206 | } | |
2207 | ||
2208 | if (free_contents != NULL) | |
2209 | { | |
2210 | if (! link_info->keep_memory) | |
2211 | free (free_contents); | |
2212 | else | |
2213 | { | |
2214 | /* Cache the section contents for elf_link_input_bfd. */ | |
2215 | elf_section_data (sec)->this_hdr.contents = contents; | |
2216 | } | |
2217 | free_contents = NULL; | |
2218 | } | |
2219 | ||
2220 | if (free_extsyms != NULL) | |
2221 | { | |
2222 | if (! link_info->keep_memory) | |
2223 | free (free_extsyms); | |
2224 | else | |
2225 | { | |
2226 | /* Cache the symbols for elf_link_input_bfd. */ | |
2227 | symtab_hdr->contents = extsyms; | |
2228 | } | |
2229 | free_extsyms = NULL; | |
2230 | } | |
2231 | ||
2232 | return true; | |
2233 | ||
2234 | error_return: | |
2235 | if (free_relocs != NULL) | |
2236 | free (free_relocs); | |
2237 | if (free_contents != NULL) | |
2238 | free (free_contents); | |
2239 | if (free_extsyms != NULL) | |
2240 | free (free_extsyms); | |
2241 | return false; | |
2242 | } | |
2243 | ||
4db4e912 JL |
2244 | /* Compute the stack size and movm arguments for the function |
2245 | referred to by HASH at address ADDR in section with | |
2246 | contents CONTENTS, store the information in the hash table. */ | |
2247 | static void | |
2248 | compute_function_info (abfd, hash, addr, contents) | |
2249 | bfd *abfd; | |
2250 | struct elf32_mn10300_link_hash_entry *hash; | |
2251 | bfd_vma addr; | |
2252 | unsigned char *contents; | |
2253 | { | |
2254 | unsigned char byte1, byte2; | |
2255 | /* We only care about a very small subset of the possible prologue | |
2256 | sequences here. Basically we look for: | |
2257 | ||
2258 | movm [d2,d3,a2,a3],sp (optional) | |
2259 | add <size>,sp (optional, and only for sizes which fit in an unsigned | |
2260 | 8 bit number) | |
2261 | ||
2262 | If we find anything else, we quit. */ | |
2263 | ||
2264 | /* Look for movm [regs],sp */ | |
2265 | byte1 = bfd_get_8 (abfd, contents + addr); | |
2266 | byte2 = bfd_get_8 (abfd, contents + addr + 1); | |
2267 | ||
2268 | if (byte1 == 0xcf) | |
2269 | { | |
2270 | hash->movm_args = byte2; | |
2271 | addr += 2; | |
2272 | byte1 = bfd_get_8 (abfd, contents + addr); | |
2273 | byte2 = bfd_get_8 (abfd, contents + addr + 1); | |
2274 | } | |
2275 | ||
2276 | /* Now look for the two stack adjustment variants. */ | |
2277 | if (byte1 == 0xf8 && byte2 == 0xfe) | |
2278 | { | |
2279 | int temp = bfd_get_8 (abfd, contents + addr + 2); | |
2280 | temp = ((temp & 0xff) ^ (~0x7f)) + 0x80; | |
2281 | ||
2282 | hash->stack_size = -temp; | |
2283 | } | |
2284 | else if (byte1 == 0xfa && byte2 == 0xfe) | |
2285 | { | |
2286 | int temp = bfd_get_16 (abfd, contents + addr + 2); | |
2287 | temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000; | |
2288 | temp = -temp; | |
2289 | ||
2290 | if (temp <= 255) | |
2291 | hash->stack_size = temp; | |
2292 | } | |
2293 | return; | |
2294 | } | |
2295 | ||
a01362cc JL |
2296 | /* Delete some bytes from a section while relaxing. */ |
2297 | ||
2298 | static boolean | |
2299 | mn10300_elf_relax_delete_bytes (abfd, sec, addr, count) | |
2300 | bfd *abfd; | |
2301 | asection *sec; | |
2302 | bfd_vma addr; | |
2303 | int count; | |
2304 | { | |
2305 | Elf_Internal_Shdr *symtab_hdr; | |
2306 | Elf32_External_Sym *extsyms; | |
4db4e912 | 2307 | int shndx, index; |
a01362cc JL |
2308 | bfd_byte *contents; |
2309 | Elf_Internal_Rela *irel, *irelend; | |
2310 | Elf_Internal_Rela *irelalign; | |
2311 | bfd_vma toaddr; | |
2312 | Elf32_External_Sym *esym, *esymend; | |
4db4e912 | 2313 | struct elf32_mn10300_link_hash_entry *sym_hash; |
a01362cc JL |
2314 | |
2315 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2316 | extsyms = (Elf32_External_Sym *) symtab_hdr->contents; | |
2317 | ||
2318 | shndx = _bfd_elf_section_from_bfd_section (abfd, sec); | |
2319 | ||
2320 | contents = elf_section_data (sec)->this_hdr.contents; | |
2321 | ||
2322 | /* The deletion must stop at the next ALIGN reloc for an aligment | |
2323 | power larger than the number of bytes we are deleting. */ | |
2324 | ||
2325 | irelalign = NULL; | |
2326 | toaddr = sec->_cooked_size; | |
2327 | ||
2328 | irel = elf_section_data (sec)->relocs; | |
2329 | irelend = irel + sec->reloc_count; | |
2330 | ||
2331 | /* Actually delete the bytes. */ | |
2332 | memmove (contents + addr, contents + addr + count, toaddr - addr - count); | |
2333 | sec->_cooked_size -= count; | |
2334 | ||
2335 | /* Adjust all the relocs. */ | |
2336 | for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) | |
2337 | { | |
2338 | /* Get the new reloc address. */ | |
2339 | if ((irel->r_offset > addr | |
2340 | && irel->r_offset < toaddr)) | |
2341 | irel->r_offset -= count; | |
2342 | } | |
2343 | ||
4db4e912 | 2344 | /* Adjust the local symbols defined in this section. */ |
a01362cc JL |
2345 | esym = extsyms; |
2346 | esymend = esym + symtab_hdr->sh_info; | |
2347 | for (; esym < esymend; esym++) | |
2348 | { | |
2349 | Elf_Internal_Sym isym; | |
2350 | ||
2351 | bfd_elf32_swap_symbol_in (abfd, esym, &isym); | |
2352 | ||
2353 | if (isym.st_shndx == shndx | |
2354 | && isym.st_value > addr | |
2355 | && isym.st_value < toaddr) | |
2356 | { | |
2357 | isym.st_value -= count; | |
2358 | bfd_elf32_swap_symbol_out (abfd, &isym, esym); | |
2359 | } | |
2360 | } | |
2361 | ||
4db4e912 JL |
2362 | /* Now adjust the global symbols defined in this section. */ |
2363 | esym = extsyms + symtab_hdr->sh_info; | |
2364 | esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)); | |
2365 | for (index = 0; esym < esymend; esym++, index++) | |
a01362cc | 2366 | { |
4db4e912 JL |
2367 | Elf_Internal_Sym isym; |
2368 | ||
2369 | bfd_elf32_swap_symbol_in (abfd, esym, &isym); | |
2370 | sym_hash = (struct elf32_mn10300_link_hash_entry *) | |
2371 | (elf_sym_hashes (abfd)[index]); | |
2372 | if (isym.st_shndx == shndx | |
2373 | && ((sym_hash)->root.root.type == bfd_link_hash_defined | |
2374 | || (sym_hash)->root.root.type == bfd_link_hash_defweak) | |
2375 | && (sym_hash)->root.root.u.def.section == sec | |
2376 | && (sym_hash)->root.root.u.def.value > addr | |
2377 | && (sym_hash)->root.root.u.def.value < toaddr) | |
a01362cc | 2378 | { |
4db4e912 | 2379 | (sym_hash)->root.root.u.def.value -= count; |
a01362cc JL |
2380 | } |
2381 | } | |
2382 | ||
2383 | return true; | |
2384 | } | |
2385 | ||
2386 | /* Return true if a symbol exists at the given address, else return | |
2387 | false. */ | |
2388 | static boolean | |
2389 | mn10300_elf_symbol_address_p (abfd, sec, extsyms, addr) | |
2390 | bfd *abfd; | |
2391 | asection *sec; | |
2392 | Elf32_External_Sym *extsyms; | |
2393 | bfd_vma addr; | |
2394 | { | |
2395 | Elf_Internal_Shdr *symtab_hdr; | |
2396 | int shndx; | |
2397 | Elf32_External_Sym *esym, *esymend; | |
4db4e912 | 2398 | struct elf32_mn10300_link_hash_entry **sym_hash, **sym_hash_end; |
a01362cc JL |
2399 | |
2400 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2401 | shndx = _bfd_elf_section_from_bfd_section (abfd, sec); | |
2402 | ||
2403 | /* Examine all the symbols. */ | |
2404 | esym = extsyms; | |
2405 | esymend = esym + symtab_hdr->sh_info; | |
2406 | for (; esym < esymend; esym++) | |
2407 | { | |
2408 | Elf_Internal_Sym isym; | |
2409 | ||
2410 | bfd_elf32_swap_symbol_in (abfd, esym, &isym); | |
2411 | ||
2412 | if (isym.st_shndx == shndx | |
2413 | && isym.st_value == addr) | |
2414 | return true; | |
2415 | } | |
2416 | ||
4db4e912 | 2417 | sym_hash = (struct elf32_mn10300_link_hash_entry **)(elf_sym_hashes (abfd)); |
a01362cc JL |
2418 | sym_hash_end = (sym_hash |
2419 | + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) | |
2420 | - symtab_hdr->sh_info)); | |
2421 | for (; sym_hash < sym_hash_end; sym_hash++) | |
2422 | { | |
4db4e912 JL |
2423 | if (((*sym_hash)->root.root.type == bfd_link_hash_defined |
2424 | || (*sym_hash)->root.root.type == bfd_link_hash_defweak) | |
2425 | && (*sym_hash)->root.root.u.def.section == sec | |
2426 | && (*sym_hash)->root.root.u.def.value == addr) | |
a01362cc JL |
2427 | return true; |
2428 | } | |
2429 | return false; | |
2430 | } | |
2431 | ||
2432 | /* This is a version of bfd_generic_get_relocated_section_contents | |
2433 | which uses mn10300_elf_relocate_section. */ | |
2434 | ||
2435 | static bfd_byte * | |
2436 | mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order, | |
2437 | data, relocateable, symbols) | |
2438 | bfd *output_bfd; | |
2439 | struct bfd_link_info *link_info; | |
2440 | struct bfd_link_order *link_order; | |
2441 | bfd_byte *data; | |
2442 | boolean relocateable; | |
2443 | asymbol **symbols; | |
2444 | { | |
2445 | Elf_Internal_Shdr *symtab_hdr; | |
2446 | asection *input_section = link_order->u.indirect.section; | |
2447 | bfd *input_bfd = input_section->owner; | |
2448 | asection **sections = NULL; | |
2449 | Elf_Internal_Rela *internal_relocs = NULL; | |
2450 | Elf32_External_Sym *external_syms = NULL; | |
2451 | Elf_Internal_Sym *internal_syms = NULL; | |
2452 | ||
2453 | /* We only need to handle the case of relaxing, or of having a | |
2454 | particular set of section contents, specially. */ | |
2455 | if (relocateable | |
2456 | || elf_section_data (input_section)->this_hdr.contents == NULL) | |
2457 | return bfd_generic_get_relocated_section_contents (output_bfd, link_info, | |
2458 | link_order, data, | |
2459 | relocateable, | |
2460 | symbols); | |
2461 | ||
2462 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
2463 | ||
2464 | memcpy (data, elf_section_data (input_section)->this_hdr.contents, | |
2465 | input_section->_raw_size); | |
2466 | ||
2467 | if ((input_section->flags & SEC_RELOC) != 0 | |
2468 | && input_section->reloc_count > 0) | |
2469 | { | |
2470 | Elf_Internal_Sym *isymp; | |
2471 | asection **secpp; | |
2472 | Elf32_External_Sym *esym, *esymend; | |
2473 | ||
2474 | if (symtab_hdr->contents != NULL) | |
2475 | external_syms = (Elf32_External_Sym *) symtab_hdr->contents; | |
2476 | else | |
2477 | { | |
2478 | external_syms = ((Elf32_External_Sym *) | |
2479 | bfd_malloc (symtab_hdr->sh_info | |
2480 | * sizeof (Elf32_External_Sym))); | |
2481 | if (external_syms == NULL && symtab_hdr->sh_info > 0) | |
2482 | goto error_return; | |
2483 | if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 | |
2484 | || (bfd_read (external_syms, sizeof (Elf32_External_Sym), | |
2485 | symtab_hdr->sh_info, input_bfd) | |
2486 | != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)))) | |
2487 | goto error_return; | |
2488 | } | |
2489 | ||
2490 | internal_relocs = (_bfd_elf32_link_read_relocs | |
2491 | (input_bfd, input_section, (PTR) NULL, | |
2492 | (Elf_Internal_Rela *) NULL, false)); | |
2493 | if (internal_relocs == NULL) | |
2494 | goto error_return; | |
2495 | ||
2496 | internal_syms = ((Elf_Internal_Sym *) | |
2497 | bfd_malloc (symtab_hdr->sh_info | |
2498 | * sizeof (Elf_Internal_Sym))); | |
2499 | if (internal_syms == NULL && symtab_hdr->sh_info > 0) | |
2500 | goto error_return; | |
2501 | ||
2502 | sections = (asection **) bfd_malloc (symtab_hdr->sh_info | |
2503 | * sizeof (asection *)); | |
2504 | if (sections == NULL && symtab_hdr->sh_info > 0) | |
2505 | goto error_return; | |
2506 | ||
2507 | isymp = internal_syms; | |
2508 | secpp = sections; | |
2509 | esym = external_syms; | |
2510 | esymend = esym + symtab_hdr->sh_info; | |
2511 | for (; esym < esymend; ++esym, ++isymp, ++secpp) | |
2512 | { | |
2513 | asection *isec; | |
2514 | ||
2515 | bfd_elf32_swap_symbol_in (input_bfd, esym, isymp); | |
2516 | ||
2517 | if (isymp->st_shndx == SHN_UNDEF) | |
2518 | isec = bfd_und_section_ptr; | |
2519 | else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE) | |
2520 | isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx); | |
2521 | else if (isymp->st_shndx == SHN_ABS) | |
2522 | isec = bfd_abs_section_ptr; | |
2523 | else if (isymp->st_shndx == SHN_COMMON) | |
2524 | isec = bfd_com_section_ptr; | |
2525 | else | |
2526 | { | |
2527 | /* Who knows? */ | |
2528 | isec = NULL; | |
2529 | } | |
2530 | ||
2531 | *secpp = isec; | |
2532 | } | |
2533 | ||
2534 | if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd, | |
2535 | input_section, data, internal_relocs, | |
2536 | internal_syms, sections)) | |
2537 | goto error_return; | |
2538 | ||
2539 | if (sections != NULL) | |
2540 | free (sections); | |
2541 | sections = NULL; | |
2542 | if (internal_syms != NULL) | |
2543 | free (internal_syms); | |
2544 | internal_syms = NULL; | |
2545 | if (external_syms != NULL && symtab_hdr->contents == NULL) | |
2546 | free (external_syms); | |
2547 | external_syms = NULL; | |
2548 | if (internal_relocs != elf_section_data (input_section)->relocs) | |
2549 | free (internal_relocs); | |
2550 | internal_relocs = NULL; | |
2551 | } | |
2552 | ||
2553 | return data; | |
2554 | ||
2555 | error_return: | |
2556 | if (internal_relocs != NULL | |
2557 | && internal_relocs != elf_section_data (input_section)->relocs) | |
2558 | free (internal_relocs); | |
2559 | if (external_syms != NULL && symtab_hdr->contents == NULL) | |
2560 | free (external_syms); | |
2561 | if (internal_syms != NULL) | |
2562 | free (internal_syms); | |
2563 | if (sections != NULL) | |
2564 | free (sections); | |
2565 | return NULL; | |
2566 | } | |
2567 | ||
4db4e912 JL |
2568 | /* Assorted hash table functions. */ |
2569 | ||
2570 | /* Initialize an entry in the link hash table. */ | |
2571 | ||
2572 | /* Create an entry in an MN10300 ELF linker hash table. */ | |
2573 | ||
2574 | static struct bfd_hash_entry * | |
2575 | elf32_mn10300_link_hash_newfunc (entry, table, string) | |
2576 | struct bfd_hash_entry *entry; | |
2577 | struct bfd_hash_table *table; | |
2578 | const char *string; | |
2579 | { | |
2580 | struct elf32_mn10300_link_hash_entry *ret = | |
2581 | (struct elf32_mn10300_link_hash_entry *) entry; | |
2582 | ||
2583 | /* Allocate the structure if it has not already been allocated by a | |
2584 | subclass. */ | |
2585 | if (ret == (struct elf32_mn10300_link_hash_entry *) NULL) | |
2586 | ret = ((struct elf32_mn10300_link_hash_entry *) | |
2587 | bfd_hash_allocate (table, | |
2588 | sizeof (struct elf32_mn10300_link_hash_entry))); | |
2589 | if (ret == (struct elf32_mn10300_link_hash_entry *) NULL) | |
2590 | return (struct bfd_hash_entry *) ret; | |
2591 | ||
2592 | /* Call the allocation method of the superclass. */ | |
2593 | ret = ((struct elf32_mn10300_link_hash_entry *) | |
2594 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
2595 | table, string)); | |
2596 | if (ret != (struct elf32_mn10300_link_hash_entry *) NULL) | |
2597 | { | |
2598 | ret->direct_calls = 0; | |
2599 | ret->stack_size = 0; | |
2600 | ret->flags = 0; | |
2601 | ret->movm_args = 0; | |
2602 | } | |
2603 | ||
2604 | return (struct bfd_hash_entry *) ret; | |
2605 | } | |
2606 | ||
2607 | /* Create an mn10300 ELF linker hash table. */ | |
2608 | ||
2609 | static struct bfd_link_hash_table * | |
2610 | elf32_mn10300_link_hash_table_create (abfd) | |
2611 | bfd *abfd; | |
2612 | { | |
2613 | struct elf32_mn10300_link_hash_table *ret; | |
2614 | ||
2615 | ret = ((struct elf32_mn10300_link_hash_table *) | |
2616 | bfd_alloc (abfd, sizeof (struct elf32_mn10300_link_hash_table))); | |
2617 | if (ret == (struct elf32_mn10300_link_hash_table *) NULL) | |
2618 | return NULL; | |
2619 | ||
2620 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, | |
2621 | elf32_mn10300_link_hash_newfunc)) | |
2622 | { | |
2623 | bfd_release (abfd, ret); | |
2624 | return NULL; | |
2625 | } | |
2626 | ||
2627 | ret->flags = 0; | |
2628 | ret->static_hash_table | |
2629 | = ((struct elf32_mn10300_link_hash_table *) | |
2630 | bfd_alloc (abfd, sizeof (struct elf_link_hash_table))); | |
2631 | if (ret->static_hash_table == NULL) | |
2632 | { | |
2633 | bfd_release (abfd, ret); | |
2634 | return NULL; | |
2635 | } | |
2636 | ||
2637 | if (! _bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd, | |
2638 | elf32_mn10300_link_hash_newfunc)) | |
2639 | { | |
2640 | bfd_release (abfd, ret->static_hash_table); | |
2641 | bfd_release (abfd, ret); | |
2642 | return NULL; | |
2643 | } | |
2644 | return &ret->root.root; | |
2645 | } | |
2646 | ||
2647 | static int | |
2648 | elf_mn10300_mach (flags) | |
2649 | flagword flags; | |
2650 | { | |
2651 | switch (flags & EF_MN10300_MACH) | |
2652 | { | |
2653 | case E_MN10300_MACH_MN10300: | |
2654 | default: | |
2655 | return bfd_mach_mn10300; | |
2656 | ||
2657 | /* start-sanitize-am33 */ | |
2658 | case E_MN10300_MACH_AM33: | |
2659 | return bfd_mach_am33; | |
2660 | /* end-sanitize-am33 */ | |
2661 | } | |
2662 | } | |
a01362cc | 2663 | |
4db4e912 JL |
2664 | /* The final processing done just before writing out a MN10300 ELF object |
2665 | file. This gets the MN10300 architecture right based on the machine | |
2666 | number. */ | |
2667 | ||
2668 | /*ARGSUSED*/ | |
2669 | void | |
2670 | _bfd_mn10300_elf_final_write_processing (abfd, linker) | |
2671 | bfd *abfd; | |
2672 | boolean linker; | |
2673 | { | |
2674 | unsigned long val; | |
2675 | unsigned int i; | |
2676 | Elf_Internal_Shdr **hdrpp; | |
2677 | const char *name; | |
2678 | asection *sec; | |
2679 | ||
2680 | switch (bfd_get_mach (abfd)) | |
2681 | { | |
2682 | default: | |
2683 | case bfd_mach_mn10300: | |
2684 | val = E_MN10300_MACH_MN10300; | |
2685 | break; | |
2686 | ||
2687 | /* start-sanitize-am33 */ | |
2688 | case bfd_mach_am33: | |
2689 | val = E_MN10300_MACH_AM33; | |
2690 | break; | |
2691 | /* end-sanitize-am33 */ | |
2692 | } | |
2693 | ||
2694 | elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH); | |
2695 | elf_elfheader (abfd)->e_flags |= val; | |
2696 | } | |
2697 | ||
2698 | boolean | |
2699 | _bfd_mn10300_elf_object_p (abfd) | |
2700 | bfd *abfd; | |
2701 | { | |
2702 | bfd_default_set_arch_mach (abfd, bfd_arch_mn10300, | |
2703 | elf_mn10300_mach (elf_elfheader (abfd)->e_flags)); | |
2704 | return true; | |
2705 | } | |
a01362cc JL |
2706 | |
2707 | #define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec | |
2708 | #define TARGET_LITTLE_NAME "elf32-mn10300" | |
2709 | #define ELF_ARCH bfd_arch_mn10300 | |
2710 | #define ELF_MACHINE_CODE EM_CYGNUS_MN10300 | |
2711 | #define ELF_MAXPAGESIZE 0x1000 | |
2712 | ||
303b4cc6 RH |
2713 | #define elf_info_to_howto mn10300_info_to_howto |
2714 | #define elf_info_to_howto_rel 0 | |
2715 | #define elf_backend_can_gc_sections 1 | |
2716 | #define elf_backend_check_relocs mn10300_elf_check_relocs | |
2717 | #define elf_backend_gc_mark_hook mn10300_elf_gc_mark_hook | |
2718 | #define elf_backend_relocate_section mn10300_elf_relocate_section | |
a01362cc JL |
2719 | #define bfd_elf32_bfd_relax_section mn10300_elf_relax_section |
2720 | #define bfd_elf32_bfd_get_relocated_section_contents \ | |
2721 | mn10300_elf_get_relocated_section_contents | |
4db4e912 JL |
2722 | #define bfd_elf32_bfd_link_hash_table_create \ |
2723 | elf32_mn10300_link_hash_table_create | |
a01362cc JL |
2724 | |
2725 | #define elf_symbol_leading_char '_' | |
2726 | ||
4db4e912 JL |
2727 | /* So we can set bits in e_flags. */ |
2728 | #define elf_backend_final_write_processing \ | |
2729 | _bfd_mn10300_elf_final_write_processing | |
2730 | #define elf_backend_object_p _bfd_mn10300_elf_object_p | |
2731 | ||
2732 | ||
a01362cc | 2733 | #include "elf32-target.h" |