* elf32-xtensa.c (analyze_relocations): Zero src_count if not relaxing.
[binutils.git] / bfd / elf-m10300.c
blobdf2d4ab2b573d63362860d5f28aeb39fe43b2fcc
1 /* Matsushita 10300 specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include "elf-bfd.h"
25 #include "elf/mn10300.h"
27 static bfd_reloc_status_type mn10300_elf_final_link_relocate
28 PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, bfd_byte *,
29 bfd_vma, bfd_vma, bfd_vma,
30 struct elf_link_hash_entry *, unsigned long, struct bfd_link_info *,
31 asection *, int));
32 static bfd_boolean mn10300_elf_relocate_section
33 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
34 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
35 static bfd_boolean mn10300_elf_relax_section
36 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
37 static bfd_byte * mn10300_elf_get_relocated_section_contents
38 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
39 bfd_byte *, bfd_boolean, asymbol **));
40 static unsigned long elf_mn10300_mach
41 PARAMS ((flagword));
42 void _bfd_mn10300_elf_final_write_processing
43 PARAMS ((bfd *, bfd_boolean));
44 bfd_boolean _bfd_mn10300_elf_object_p
45 PARAMS ((bfd *));
46 bfd_boolean _bfd_mn10300_elf_merge_private_bfd_data
47 PARAMS ((bfd *,bfd *));
49 /* The mn10300 linker needs to keep track of the number of relocs that
50 it decides to copy in check_relocs for each symbol. This is so
51 that it can discard PC relative relocs if it doesn't need them when
52 linking with -Bsymbolic. We store the information in a field
53 extending the regular ELF linker hash table. */
55 struct elf32_mn10300_link_hash_entry {
56 /* The basic elf link hash table entry. */
57 struct elf_link_hash_entry root;
59 /* For function symbols, the number of times this function is
60 called directly (ie by name). */
61 unsigned int direct_calls;
63 /* For function symbols, the size of this function's stack
64 (if <= 255 bytes). We stuff this into "call" instructions
65 to this target when it's valid and profitable to do so.
67 This does not include stack allocated by movm! */
68 unsigned char stack_size;
70 /* For function symbols, arguments (if any) for movm instruction
71 in the prologue. We stuff this value into "call" instructions
72 to the target when it's valid and profitable to do so. */
73 unsigned char movm_args;
75 /* For function symbols, the amount of stack space that would be allocated
76 by the movm instruction. This is redundant with movm_args, but we
77 add it to the hash table to avoid computing it over and over. */
78 unsigned char movm_stack_size;
80 /* When set, convert all "call" instructions to this target into "calls"
81 instructions. */
82 #define MN10300_CONVERT_CALL_TO_CALLS 0x1
84 /* Used to mark functions which have had redundant parts of their
85 prologue deleted. */
86 #define MN10300_DELETED_PROLOGUE_BYTES 0x2
87 unsigned char flags;
89 /* Calculated value. */
90 bfd_vma value;
93 /* We derive a hash table from the main elf linker hash table so
94 we can store state variables and a secondary hash table without
95 resorting to global variables. */
96 struct elf32_mn10300_link_hash_table {
97 /* The main hash table. */
98 struct elf_link_hash_table root;
100 /* A hash table for static functions. We could derive a new hash table
101 instead of using the full elf32_mn10300_link_hash_table if we wanted
102 to save some memory. */
103 struct elf32_mn10300_link_hash_table *static_hash_table;
105 /* Random linker state flags. */
106 #define MN10300_HASH_ENTRIES_INITIALIZED 0x1
107 char flags;
110 /* For MN10300 linker hash table. */
112 /* Get the MN10300 ELF linker hash table from a link_info structure. */
114 #define elf32_mn10300_hash_table(p) \
115 ((struct elf32_mn10300_link_hash_table *) ((p)->hash))
117 #define elf32_mn10300_link_hash_traverse(table, func, info) \
118 (elf_link_hash_traverse \
119 (&(table)->root, \
120 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
121 (info)))
123 static struct bfd_hash_entry *elf32_mn10300_link_hash_newfunc
124 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
125 static struct bfd_link_hash_table *elf32_mn10300_link_hash_table_create
126 PARAMS ((bfd *));
127 static void elf32_mn10300_link_hash_table_free
128 PARAMS ((struct bfd_link_hash_table *));
130 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
131 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
132 static void mn10300_info_to_howto
133 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
134 static bfd_boolean mn10300_elf_check_relocs
135 PARAMS ((bfd *, struct bfd_link_info *, asection *,
136 const Elf_Internal_Rela *));
137 static bfd_boolean mn10300_elf_relax_delete_bytes
138 PARAMS ((bfd *, asection *, bfd_vma, int));
139 static bfd_boolean mn10300_elf_symbol_address_p
140 PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma));
141 static bfd_boolean elf32_mn10300_finish_hash_table_entry
142 PARAMS ((struct bfd_hash_entry *, PTR));
143 static void compute_function_info
144 PARAMS ((bfd *, struct elf32_mn10300_link_hash_entry *,
145 bfd_vma, unsigned char *));
147 static bfd_boolean _bfd_mn10300_elf_create_got_section
148 PARAMS ((bfd *, struct bfd_link_info *));
149 static bfd_boolean _bfd_mn10300_elf_create_dynamic_sections
150 PARAMS ((bfd *, struct bfd_link_info *));
151 static bfd_boolean _bfd_mn10300_elf_adjust_dynamic_symbol
152 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
153 static bfd_boolean _bfd_mn10300_elf_size_dynamic_sections
154 PARAMS ((bfd *, struct bfd_link_info *));
155 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_symbol
156 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
157 Elf_Internal_Sym *));
158 static bfd_boolean _bfd_mn10300_elf_finish_dynamic_sections
159 PARAMS ((bfd *, struct bfd_link_info *));
161 static reloc_howto_type elf_mn10300_howto_table[] = {
162 /* Dummy relocation. Does nothing. */
163 HOWTO (R_MN10300_NONE,
167 FALSE,
169 complain_overflow_bitfield,
170 bfd_elf_generic_reloc,
171 "R_MN10300_NONE",
172 FALSE,
175 FALSE),
176 /* Standard 32 bit reloc. */
177 HOWTO (R_MN10300_32,
181 FALSE,
183 complain_overflow_bitfield,
184 bfd_elf_generic_reloc,
185 "R_MN10300_32",
186 FALSE,
187 0xffffffff,
188 0xffffffff,
189 FALSE),
190 /* Standard 16 bit reloc. */
191 HOWTO (R_MN10300_16,
195 FALSE,
197 complain_overflow_bitfield,
198 bfd_elf_generic_reloc,
199 "R_MN10300_16",
200 FALSE,
201 0xffff,
202 0xffff,
203 FALSE),
204 /* Standard 8 bit reloc. */
205 HOWTO (R_MN10300_8,
209 FALSE,
211 complain_overflow_bitfield,
212 bfd_elf_generic_reloc,
213 "R_MN10300_8",
214 FALSE,
215 0xff,
216 0xff,
217 FALSE),
218 /* Standard 32bit pc-relative reloc. */
219 HOWTO (R_MN10300_PCREL32,
223 TRUE,
225 complain_overflow_bitfield,
226 bfd_elf_generic_reloc,
227 "R_MN10300_PCREL32",
228 FALSE,
229 0xffffffff,
230 0xffffffff,
231 TRUE),
232 /* Standard 16bit pc-relative reloc. */
233 HOWTO (R_MN10300_PCREL16,
237 TRUE,
239 complain_overflow_bitfield,
240 bfd_elf_generic_reloc,
241 "R_MN10300_PCREL16",
242 FALSE,
243 0xffff,
244 0xffff,
245 TRUE),
246 /* Standard 8 pc-relative reloc. */
247 HOWTO (R_MN10300_PCREL8,
251 TRUE,
253 complain_overflow_bitfield,
254 bfd_elf_generic_reloc,
255 "R_MN10300_PCREL8",
256 FALSE,
257 0xff,
258 0xff,
259 TRUE),
261 /* GNU extension to record C++ vtable hierarchy */
262 HOWTO (R_MN10300_GNU_VTINHERIT, /* type */
263 0, /* rightshift */
264 0, /* size (0 = byte, 1 = short, 2 = long) */
265 0, /* bitsize */
266 FALSE, /* pc_relative */
267 0, /* bitpos */
268 complain_overflow_dont, /* complain_on_overflow */
269 NULL, /* special_function */
270 "R_MN10300_GNU_VTINHERIT", /* name */
271 FALSE, /* partial_inplace */
272 0, /* src_mask */
273 0, /* dst_mask */
274 FALSE), /* pcrel_offset */
276 /* GNU extension to record C++ vtable member usage */
277 HOWTO (R_MN10300_GNU_VTENTRY, /* type */
278 0, /* rightshift */
279 0, /* size (0 = byte, 1 = short, 2 = long) */
280 0, /* bitsize */
281 FALSE, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_dont, /* complain_on_overflow */
284 NULL, /* special_function */
285 "R_MN10300_GNU_VTENTRY", /* name */
286 FALSE, /* partial_inplace */
287 0, /* src_mask */
288 0, /* dst_mask */
289 FALSE), /* pcrel_offset */
291 /* Standard 24 bit reloc. */
292 HOWTO (R_MN10300_24,
296 FALSE,
298 complain_overflow_bitfield,
299 bfd_elf_generic_reloc,
300 "R_MN10300_24",
301 FALSE,
302 0xffffff,
303 0xffffff,
304 FALSE),
305 HOWTO (R_MN10300_GOTPC32, /* type */
306 0, /* rightshift */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
308 32, /* bitsize */
309 TRUE, /* pc_relative */
310 0, /* bitpos */
311 complain_overflow_bitfield, /* complain_on_overflow */
312 bfd_elf_generic_reloc, /* */
313 "R_MN10300_GOTPC32", /* name */
314 FALSE, /* partial_inplace */
315 0xffffffff, /* src_mask */
316 0xffffffff, /* dst_mask */
317 TRUE), /* pcrel_offset */
319 HOWTO (R_MN10300_GOTPC16, /* type */
320 0, /* rightshift */
321 1, /* size (0 = byte, 1 = short, 2 = long) */
322 16, /* bitsize */
323 TRUE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_bitfield, /* complain_on_overflow */
326 bfd_elf_generic_reloc, /* */
327 "R_MN10300_GOTPC16", /* name */
328 FALSE, /* partial_inplace */
329 0xffff, /* src_mask */
330 0xffff, /* dst_mask */
331 TRUE), /* pcrel_offset */
333 HOWTO (R_MN10300_GOTOFF32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_bitfield, /* complain_on_overflow */
340 bfd_elf_generic_reloc, /* */
341 "R_MN10300_GOTOFF32", /* name */
342 FALSE, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
347 HOWTO (R_MN10300_GOTOFF24, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 24, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_bitfield, /* complain_on_overflow */
354 bfd_elf_generic_reloc, /* */
355 "R_MN10300_GOTOFF24", /* name */
356 FALSE, /* partial_inplace */
357 0xffffff, /* src_mask */
358 0xffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
361 HOWTO (R_MN10300_GOTOFF16, /* type */
362 0, /* rightshift */
363 1, /* size (0 = byte, 1 = short, 2 = long) */
364 16, /* bitsize */
365 FALSE, /* pc_relative */
366 0, /* bitpos */
367 complain_overflow_bitfield, /* complain_on_overflow */
368 bfd_elf_generic_reloc, /* */
369 "R_MN10300_GOTOFF16", /* name */
370 FALSE, /* partial_inplace */
371 0xffff, /* src_mask */
372 0xffff, /* dst_mask */
373 FALSE), /* pcrel_offset */
375 HOWTO (R_MN10300_PLT32, /* type */
376 0, /* rightshift */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
378 32, /* bitsize */
379 TRUE, /* pc_relative */
380 0, /* bitpos */
381 complain_overflow_bitfield, /* complain_on_overflow */
382 bfd_elf_generic_reloc, /* */
383 "R_MN10300_PLT32", /* name */
384 FALSE, /* partial_inplace */
385 0xffffffff, /* src_mask */
386 0xffffffff, /* dst_mask */
387 TRUE), /* pcrel_offset */
389 HOWTO (R_MN10300_PLT16, /* type */
390 0, /* rightshift */
391 1, /* size (0 = byte, 1 = short, 2 = long) */
392 16, /* bitsize */
393 TRUE, /* pc_relative */
394 0, /* bitpos */
395 complain_overflow_bitfield, /* complain_on_overflow */
396 bfd_elf_generic_reloc, /* */
397 "R_MN10300_PLT16", /* name */
398 FALSE, /* partial_inplace */
399 0xffff, /* src_mask */
400 0xffff, /* dst_mask */
401 TRUE), /* pcrel_offset */
403 HOWTO (R_MN10300_GOT32, /* type */
404 0, /* rightshift */
405 2, /* size (0 = byte, 1 = short, 2 = long) */
406 32, /* bitsize */
407 FALSE, /* pc_relative */
408 0, /* bitpos */
409 complain_overflow_bitfield, /* complain_on_overflow */
410 bfd_elf_generic_reloc, /* */
411 "R_MN10300_GOT32", /* name */
412 FALSE, /* partial_inplace */
413 0xffffffff, /* src_mask */
414 0xffffffff, /* dst_mask */
415 FALSE), /* pcrel_offset */
417 HOWTO (R_MN10300_GOT24, /* type */
418 0, /* rightshift */
419 2, /* size (0 = byte, 1 = short, 2 = long) */
420 24, /* bitsize */
421 FALSE, /* pc_relative */
422 0, /* bitpos */
423 complain_overflow_bitfield, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* */
425 "R_MN10300_GOT24", /* name */
426 FALSE, /* partial_inplace */
427 0xffffffff, /* src_mask */
428 0xffffffff, /* dst_mask */
429 FALSE), /* pcrel_offset */
431 HOWTO (R_MN10300_GOT16, /* type */
432 0, /* rightshift */
433 1, /* size (0 = byte, 1 = short, 2 = long) */
434 16, /* bitsize */
435 FALSE, /* pc_relative */
436 0, /* bitpos */
437 complain_overflow_bitfield, /* complain_on_overflow */
438 bfd_elf_generic_reloc, /* */
439 "R_MN10300_GOT16", /* name */
440 FALSE, /* partial_inplace */
441 0xffffffff, /* src_mask */
442 0xffffffff, /* dst_mask */
443 FALSE), /* pcrel_offset */
445 HOWTO (R_MN10300_COPY, /* type */
446 0, /* rightshift */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
448 32, /* bitsize */
449 FALSE, /* pc_relative */
450 0, /* bitpos */
451 complain_overflow_bitfield, /* complain_on_overflow */
452 bfd_elf_generic_reloc, /* */
453 "R_MN10300_COPY", /* name */
454 FALSE, /* partial_inplace */
455 0xffffffff, /* src_mask */
456 0xffffffff, /* dst_mask */
457 FALSE), /* pcrel_offset */
459 HOWTO (R_MN10300_GLOB_DAT, /* type */
460 0, /* rightshift */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
462 32, /* bitsize */
463 FALSE, /* pc_relative */
464 0, /* bitpos */
465 complain_overflow_bitfield, /* complain_on_overflow */
466 bfd_elf_generic_reloc, /* */
467 "R_MN10300_GLOB_DAT", /* name */
468 FALSE, /* partial_inplace */
469 0xffffffff, /* src_mask */
470 0xffffffff, /* dst_mask */
471 FALSE), /* pcrel_offset */
473 HOWTO (R_MN10300_JMP_SLOT, /* type */
474 0, /* rightshift */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
476 32, /* bitsize */
477 FALSE, /* pc_relative */
478 0, /* bitpos */
479 complain_overflow_bitfield, /* complain_on_overflow */
480 bfd_elf_generic_reloc, /* */
481 "R_MN10300_JMP_SLOT", /* name */
482 FALSE, /* partial_inplace */
483 0xffffffff, /* src_mask */
484 0xffffffff, /* dst_mask */
485 FALSE), /* pcrel_offset */
487 HOWTO (R_MN10300_RELATIVE, /* type */
488 0, /* rightshift */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
490 32, /* bitsize */
491 FALSE, /* pc_relative */
492 0, /* bitpos */
493 complain_overflow_bitfield, /* complain_on_overflow */
494 bfd_elf_generic_reloc, /* */
495 "R_MN10300_RELATIVE", /* name */
496 FALSE, /* partial_inplace */
497 0xffffffff, /* src_mask */
498 0xffffffff, /* dst_mask */
499 FALSE), /* pcrel_offset */
503 struct mn10300_reloc_map {
504 bfd_reloc_code_real_type bfd_reloc_val;
505 unsigned char elf_reloc_val;
508 static const struct mn10300_reloc_map mn10300_reloc_map[] = {
509 { BFD_RELOC_NONE, R_MN10300_NONE, },
510 { BFD_RELOC_32, R_MN10300_32, },
511 { BFD_RELOC_16, R_MN10300_16, },
512 { BFD_RELOC_8, R_MN10300_8, },
513 { BFD_RELOC_32_PCREL, R_MN10300_PCREL32, },
514 { BFD_RELOC_16_PCREL, R_MN10300_PCREL16, },
515 { BFD_RELOC_8_PCREL, R_MN10300_PCREL8, },
516 { BFD_RELOC_24, R_MN10300_24, },
517 { BFD_RELOC_VTABLE_INHERIT, R_MN10300_GNU_VTINHERIT },
518 { BFD_RELOC_VTABLE_ENTRY, R_MN10300_GNU_VTENTRY },
519 { BFD_RELOC_32_GOT_PCREL, R_MN10300_GOTPC32 },
520 { BFD_RELOC_16_GOT_PCREL, R_MN10300_GOTPC16 },
521 { BFD_RELOC_32_GOTOFF, R_MN10300_GOTOFF32 },
522 { BFD_RELOC_MN10300_GOTOFF24, R_MN10300_GOTOFF24 },
523 { BFD_RELOC_16_GOTOFF, R_MN10300_GOTOFF16 },
524 { BFD_RELOC_32_PLT_PCREL, R_MN10300_PLT32 },
525 { BFD_RELOC_16_PLT_PCREL, R_MN10300_PLT16 },
526 { BFD_RELOC_MN10300_GOT32, R_MN10300_GOT32 },
527 { BFD_RELOC_MN10300_GOT24, R_MN10300_GOT24 },
528 { BFD_RELOC_MN10300_GOT16, R_MN10300_GOT16 },
529 { BFD_RELOC_MN10300_COPY, R_MN10300_COPY },
530 { BFD_RELOC_MN10300_GLOB_DAT, R_MN10300_GLOB_DAT },
531 { BFD_RELOC_MN10300_JMP_SLOT, R_MN10300_JMP_SLOT },
532 { BFD_RELOC_MN10300_RELATIVE, R_MN10300_RELATIVE },
535 /* Create the GOT section. */
537 static bfd_boolean
538 _bfd_mn10300_elf_create_got_section (abfd, info)
539 bfd * abfd;
540 struct bfd_link_info * info;
542 flagword flags;
543 flagword pltflags;
544 asection * s;
545 struct elf_link_hash_entry * h;
546 const struct elf_backend_data * bed = get_elf_backend_data (abfd);
547 int ptralign;
549 /* This function may be called more than once. */
550 if (bfd_get_section_by_name (abfd, ".got") != NULL)
551 return TRUE;
553 switch (bed->s->arch_size)
555 case 32:
556 ptralign = 2;
557 break;
559 case 64:
560 ptralign = 3;
561 break;
563 default:
564 bfd_set_error (bfd_error_bad_value);
565 return FALSE;
568 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
569 | SEC_LINKER_CREATED);
571 pltflags = flags;
572 pltflags |= SEC_CODE;
573 if (bed->plt_not_loaded)
574 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
575 if (bed->plt_readonly)
576 pltflags |= SEC_READONLY;
578 s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
579 if (s == NULL
580 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
581 return FALSE;
583 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
584 .plt section. */
585 if (bed->want_plt_sym)
587 h = _bfd_elf_define_linkage_sym (abfd, info, s,
588 "_PROCEDURE_LINKAGE_TABLE_");
589 elf_hash_table (info)->hplt = h;
590 if (h == NULL)
591 return FALSE;
594 s = bfd_make_section_with_flags (abfd, ".got", flags);
595 if (s == NULL
596 || ! bfd_set_section_alignment (abfd, s, ptralign))
597 return FALSE;
599 if (bed->want_got_plt)
601 s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
602 if (s == NULL
603 || ! bfd_set_section_alignment (abfd, s, ptralign))
604 return FALSE;
607 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
608 (or .got.plt) section. We don't do this in the linker script
609 because we don't want to define the symbol if we are not creating
610 a global offset table. */
611 h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
612 elf_hash_table (info)->hgot = h;
613 if (h == NULL)
614 return FALSE;
616 /* The first bit of the global offset table is the header. */
617 s->size += bed->got_header_size;
619 return TRUE;
622 static reloc_howto_type *
623 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
624 bfd *abfd ATTRIBUTE_UNUSED;
625 bfd_reloc_code_real_type code;
627 unsigned int i;
629 for (i = 0;
630 i < sizeof (mn10300_reloc_map) / sizeof (struct mn10300_reloc_map);
631 i++)
633 if (mn10300_reloc_map[i].bfd_reloc_val == code)
634 return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
637 return NULL;
640 /* Set the howto pointer for an MN10300 ELF reloc. */
642 static void
643 mn10300_info_to_howto (abfd, cache_ptr, dst)
644 bfd *abfd ATTRIBUTE_UNUSED;
645 arelent *cache_ptr;
646 Elf_Internal_Rela *dst;
648 unsigned int r_type;
650 r_type = ELF32_R_TYPE (dst->r_info);
651 BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX);
652 cache_ptr->howto = &elf_mn10300_howto_table[r_type];
655 /* Look through the relocs for a section during the first phase.
656 Since we don't do .gots or .plts, we just need to consider the
657 virtual table relocs for gc. */
659 static bfd_boolean
660 mn10300_elf_check_relocs (abfd, info, sec, relocs)
661 bfd *abfd;
662 struct bfd_link_info *info;
663 asection *sec;
664 const Elf_Internal_Rela *relocs;
666 Elf_Internal_Shdr *symtab_hdr;
667 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
668 const Elf_Internal_Rela *rel;
669 const Elf_Internal_Rela *rel_end;
670 bfd * dynobj;
671 bfd_vma * local_got_offsets;
672 asection * sgot;
673 asection * srelgot;
674 asection * sreloc;
676 sgot = NULL;
677 srelgot = NULL;
678 sreloc = NULL;
680 if (info->relocatable)
681 return TRUE;
683 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
684 sym_hashes = elf_sym_hashes (abfd);
685 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
686 if (!elf_bad_symtab (abfd))
687 sym_hashes_end -= symtab_hdr->sh_info;
689 dynobj = elf_hash_table (info)->dynobj;
690 local_got_offsets = elf_local_got_offsets (abfd);
691 rel_end = relocs + sec->reloc_count;
692 for (rel = relocs; rel < rel_end; rel++)
694 struct elf_link_hash_entry *h;
695 unsigned long r_symndx;
697 r_symndx = ELF32_R_SYM (rel->r_info);
698 if (r_symndx < symtab_hdr->sh_info)
699 h = NULL;
700 else
702 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
703 while (h->root.type == bfd_link_hash_indirect
704 || h->root.type == bfd_link_hash_warning)
705 h = (struct elf_link_hash_entry *) h->root.u.i.link;
708 /* Some relocs require a global offset table. */
709 if (dynobj == NULL)
711 switch (ELF32_R_TYPE (rel->r_info))
713 case R_MN10300_GOT32:
714 case R_MN10300_GOT24:
715 case R_MN10300_GOT16:
716 case R_MN10300_GOTOFF32:
717 case R_MN10300_GOTOFF24:
718 case R_MN10300_GOTOFF16:
719 case R_MN10300_GOTPC32:
720 case R_MN10300_GOTPC16:
721 elf_hash_table (info)->dynobj = dynobj = abfd;
722 if (! _bfd_mn10300_elf_create_got_section (dynobj, info))
723 return FALSE;
724 break;
726 default:
727 break;
731 switch (ELF32_R_TYPE (rel->r_info))
733 /* This relocation describes the C++ object vtable hierarchy.
734 Reconstruct it for later use during GC. */
735 case R_MN10300_GNU_VTINHERIT:
736 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
737 return FALSE;
738 break;
740 /* This relocation describes which C++ vtable entries are actually
741 used. Record for later use during GC. */
742 case R_MN10300_GNU_VTENTRY:
743 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
744 return FALSE;
745 break;
746 case R_MN10300_GOT32:
747 case R_MN10300_GOT24:
748 case R_MN10300_GOT16:
749 /* This symbol requires a global offset table entry. */
751 if (sgot == NULL)
753 sgot = bfd_get_section_by_name (dynobj, ".got");
754 BFD_ASSERT (sgot != NULL);
757 if (srelgot == NULL
758 && (h != NULL || info->shared))
760 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
761 if (srelgot == NULL)
763 srelgot = bfd_make_section_with_flags (dynobj,
764 ".rela.got",
765 (SEC_ALLOC
766 | SEC_LOAD
767 | SEC_HAS_CONTENTS
768 | SEC_IN_MEMORY
769 | SEC_LINKER_CREATED
770 | SEC_READONLY));
771 if (srelgot == NULL
772 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
773 return FALSE;
777 if (h != NULL)
779 if (h->got.offset != (bfd_vma) -1)
780 /* We have already allocated space in the .got. */
781 break;
783 h->got.offset = sgot->size;
785 /* Make sure this symbol is output as a dynamic symbol. */
786 if (h->dynindx == -1)
788 if (! bfd_elf_link_record_dynamic_symbol (info, h))
789 return FALSE;
792 srelgot->size += sizeof (Elf32_External_Rela);
794 else
796 /* This is a global offset table entry for a local
797 symbol. */
798 if (local_got_offsets == NULL)
800 size_t size;
801 unsigned int i;
803 size = symtab_hdr->sh_info * sizeof (bfd_vma);
804 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
806 if (local_got_offsets == NULL)
807 return FALSE;
808 elf_local_got_offsets (abfd) = local_got_offsets;
810 for (i = 0; i < symtab_hdr->sh_info; i++)
811 local_got_offsets[i] = (bfd_vma) -1;
814 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
815 /* We have already allocated space in the .got. */
816 break;
818 local_got_offsets[r_symndx] = sgot->size;
820 if (info->shared)
821 /* If we are generating a shared object, we need to
822 output a R_MN10300_RELATIVE reloc so that the dynamic
823 linker can adjust this GOT entry. */
824 srelgot->size += sizeof (Elf32_External_Rela);
827 sgot->size += 4;
829 break;
831 case R_MN10300_PLT32:
832 case R_MN10300_PLT16:
833 /* This symbol requires a procedure linkage table entry. We
834 actually build the entry in adjust_dynamic_symbol,
835 because this might be a case of linking PIC code which is
836 never referenced by a dynamic object, in which case we
837 don't need to generate a procedure linkage table entry
838 after all. */
840 /* If this is a local symbol, we resolve it directly without
841 creating a procedure linkage table entry. */
842 if (h == NULL)
843 continue;
845 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
846 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
847 break;
849 h->needs_plt = 1;
851 break;
853 case R_MN10300_24:
854 case R_MN10300_16:
855 case R_MN10300_8:
856 case R_MN10300_PCREL32:
857 case R_MN10300_PCREL16:
858 case R_MN10300_PCREL8:
859 if (h != NULL)
860 h->non_got_ref = 1;
861 break;
863 case R_MN10300_32:
864 if (h != NULL)
865 h->non_got_ref = 1;
867 /* If we are creating a shared library, then we need to copy
868 the reloc into the shared library. */
869 if (info->shared
870 && (sec->flags & SEC_ALLOC) != 0)
872 /* When creating a shared object, we must copy these
873 reloc types into the output file. We create a reloc
874 section in dynobj and make room for this reloc. */
875 if (sreloc == NULL)
877 const char * name;
879 name = (bfd_elf_string_from_elf_section
880 (abfd,
881 elf_elfheader (abfd)->e_shstrndx,
882 elf_section_data (sec)->rel_hdr.sh_name));
883 if (name == NULL)
884 return FALSE;
886 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
887 && strcmp (bfd_get_section_name (abfd, sec),
888 name + 5) == 0);
890 sreloc = bfd_get_section_by_name (dynobj, name);
891 if (sreloc == NULL)
893 flagword flags;
895 flags = (SEC_HAS_CONTENTS | SEC_READONLY
896 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
897 if ((sec->flags & SEC_ALLOC) != 0)
898 flags |= SEC_ALLOC | SEC_LOAD;
899 sreloc = bfd_make_section_with_flags (dynobj,
900 name,
901 flags);
902 if (sreloc == NULL
903 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
904 return FALSE;
908 sreloc->size += sizeof (Elf32_External_Rela);
911 break;
915 return TRUE;
918 /* Return the section that should be marked against GC for a given
919 relocation. */
921 static asection *
922 mn10300_elf_gc_mark_hook (asection *sec,
923 struct bfd_link_info *info,
924 Elf_Internal_Rela *rel,
925 struct elf_link_hash_entry *h,
926 Elf_Internal_Sym *sym)
928 if (h != NULL)
929 switch (ELF32_R_TYPE (rel->r_info))
931 case R_MN10300_GNU_VTINHERIT:
932 case R_MN10300_GNU_VTENTRY:
933 return NULL;
936 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
939 /* Perform a relocation as part of a final link. */
940 static bfd_reloc_status_type
941 mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
942 input_section, contents, offset, value,
943 addend, h, symndx, info, sym_sec, is_local)
944 reloc_howto_type *howto;
945 bfd *input_bfd;
946 bfd *output_bfd ATTRIBUTE_UNUSED;
947 asection *input_section;
948 bfd_byte *contents;
949 bfd_vma offset;
950 bfd_vma value;
951 bfd_vma addend;
952 struct elf_link_hash_entry * h;
953 unsigned long symndx;
954 struct bfd_link_info *info;
955 asection *sym_sec ATTRIBUTE_UNUSED;
956 int is_local ATTRIBUTE_UNUSED;
958 unsigned long r_type = howto->type;
959 bfd_byte *hit_data = contents + offset;
960 bfd * dynobj;
961 bfd_vma * local_got_offsets;
962 asection * sgot;
963 asection * splt;
964 asection * sreloc;
966 dynobj = elf_hash_table (info)->dynobj;
967 local_got_offsets = elf_local_got_offsets (input_bfd);
969 sgot = NULL;
970 splt = NULL;
971 sreloc = NULL;
973 switch (r_type)
975 case R_MN10300_24:
976 case R_MN10300_16:
977 case R_MN10300_8:
978 case R_MN10300_PCREL8:
979 case R_MN10300_PCREL16:
980 case R_MN10300_PCREL32:
981 case R_MN10300_GOTOFF32:
982 case R_MN10300_GOTOFF24:
983 case R_MN10300_GOTOFF16:
984 if (info->shared
985 && (input_section->flags & SEC_ALLOC) != 0
986 && h != NULL
987 && ! SYMBOL_REFERENCES_LOCAL (info, h))
988 return bfd_reloc_dangerous;
991 switch (r_type)
993 case R_MN10300_NONE:
994 return bfd_reloc_ok;
996 case R_MN10300_32:
997 if (info->shared
998 && (input_section->flags & SEC_ALLOC) != 0)
1000 Elf_Internal_Rela outrel;
1001 bfd_boolean skip, relocate;
1003 /* When generating a shared object, these relocations are
1004 copied into the output file to be resolved at run
1005 time. */
1006 if (sreloc == NULL)
1008 const char * name;
1010 name = (bfd_elf_string_from_elf_section
1011 (input_bfd,
1012 elf_elfheader (input_bfd)->e_shstrndx,
1013 elf_section_data (input_section)->rel_hdr.sh_name));
1014 if (name == NULL)
1015 return FALSE;
1017 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
1018 && strcmp (bfd_get_section_name (input_bfd,
1019 input_section),
1020 name + 5) == 0);
1022 sreloc = bfd_get_section_by_name (dynobj, name);
1023 BFD_ASSERT (sreloc != NULL);
1026 skip = FALSE;
1028 outrel.r_offset = _bfd_elf_section_offset (input_bfd, info,
1029 input_section, offset);
1030 if (outrel.r_offset == (bfd_vma) -1)
1031 skip = TRUE;
1033 outrel.r_offset += (input_section->output_section->vma
1034 + input_section->output_offset);
1036 if (skip)
1038 memset (&outrel, 0, sizeof outrel);
1039 relocate = FALSE;
1041 else
1043 /* h->dynindx may be -1 if this symbol was marked to
1044 become local. */
1045 if (h == NULL
1046 || SYMBOL_REFERENCES_LOCAL (info, h))
1048 relocate = TRUE;
1049 outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1050 outrel.r_addend = value + addend;
1052 else
1054 BFD_ASSERT (h->dynindx != -1);
1055 relocate = FALSE;
1056 outrel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_32);
1057 outrel.r_addend = value + addend;
1061 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1062 (bfd_byte *) (((Elf32_External_Rela *) sreloc->contents)
1063 + sreloc->reloc_count));
1064 ++sreloc->reloc_count;
1066 /* If this reloc is against an external symbol, we do
1067 not want to fiddle with the addend. Otherwise, we
1068 need to include the symbol value so that it becomes
1069 an addend for the dynamic reloc. */
1070 if (! relocate)
1071 return bfd_reloc_ok;
1073 value += addend;
1074 bfd_put_32 (input_bfd, value, hit_data);
1075 return bfd_reloc_ok;
1077 case R_MN10300_24:
1078 value += addend;
1080 if ((long) value > 0x7fffff || (long) value < -0x800000)
1081 return bfd_reloc_overflow;
1083 bfd_put_8 (input_bfd, value & 0xff, hit_data);
1084 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1085 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1086 return bfd_reloc_ok;
1088 case R_MN10300_16:
1089 value += addend;
1091 if ((long) value > 0x7fff || (long) value < -0x8000)
1092 return bfd_reloc_overflow;
1094 bfd_put_16 (input_bfd, value, hit_data);
1095 return bfd_reloc_ok;
1097 case R_MN10300_8:
1098 value += addend;
1100 if ((long) value > 0x7f || (long) value < -0x80)
1101 return bfd_reloc_overflow;
1103 bfd_put_8 (input_bfd, value, hit_data);
1104 return bfd_reloc_ok;
1106 case R_MN10300_PCREL8:
1107 value -= (input_section->output_section->vma
1108 + input_section->output_offset);
1109 value -= offset;
1110 value += addend;
1112 if ((long) value > 0xff || (long) value < -0x100)
1113 return bfd_reloc_overflow;
1115 bfd_put_8 (input_bfd, value, hit_data);
1116 return bfd_reloc_ok;
1118 case R_MN10300_PCREL16:
1119 value -= (input_section->output_section->vma
1120 + input_section->output_offset);
1121 value -= offset;
1122 value += addend;
1124 if ((long) value > 0xffff || (long) value < -0x10000)
1125 return bfd_reloc_overflow;
1127 bfd_put_16 (input_bfd, value, hit_data);
1128 return bfd_reloc_ok;
1130 case R_MN10300_PCREL32:
1131 value -= (input_section->output_section->vma
1132 + input_section->output_offset);
1133 value -= offset;
1134 value += addend;
1136 bfd_put_32 (input_bfd, value, hit_data);
1137 return bfd_reloc_ok;
1139 case R_MN10300_GNU_VTINHERIT:
1140 case R_MN10300_GNU_VTENTRY:
1141 return bfd_reloc_ok;
1143 case R_MN10300_GOTPC32:
1144 /* Use global offset table as symbol value. */
1146 value = bfd_get_section_by_name (dynobj,
1147 ".got")->output_section->vma;
1148 value -= (input_section->output_section->vma
1149 + input_section->output_offset);
1150 value -= offset;
1151 value += addend;
1153 bfd_put_32 (input_bfd, value, hit_data);
1154 return bfd_reloc_ok;
1156 case R_MN10300_GOTPC16:
1157 /* Use global offset table as symbol value. */
1159 value = bfd_get_section_by_name (dynobj,
1160 ".got")->output_section->vma;
1161 value -= (input_section->output_section->vma
1162 + input_section->output_offset);
1163 value -= offset;
1164 value += addend;
1166 if ((long) value > 0xffff || (long) value < -0x10000)
1167 return bfd_reloc_overflow;
1169 bfd_put_16 (input_bfd, value, hit_data);
1170 return bfd_reloc_ok;
1172 case R_MN10300_GOTOFF32:
1173 value -= bfd_get_section_by_name (dynobj,
1174 ".got")->output_section->vma;
1175 value += addend;
1177 bfd_put_32 (input_bfd, value, hit_data);
1178 return bfd_reloc_ok;
1180 case R_MN10300_GOTOFF24:
1181 value -= bfd_get_section_by_name (dynobj,
1182 ".got")->output_section->vma;
1183 value += addend;
1185 if ((long) value > 0x7fffff || (long) value < -0x800000)
1186 return bfd_reloc_overflow;
1188 bfd_put_8 (input_bfd, value, hit_data);
1189 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1190 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1191 return bfd_reloc_ok;
1193 case R_MN10300_GOTOFF16:
1194 value -= bfd_get_section_by_name (dynobj,
1195 ".got")->output_section->vma;
1196 value += addend;
1198 if ((long) value > 0xffff || (long) value < -0x10000)
1199 return bfd_reloc_overflow;
1201 bfd_put_16 (input_bfd, value, hit_data);
1202 return bfd_reloc_ok;
1204 case R_MN10300_PLT32:
1205 if (h != NULL
1206 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1207 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1208 && h->plt.offset != (bfd_vma) -1)
1210 asection * splt;
1212 splt = bfd_get_section_by_name (dynobj, ".plt");
1214 value = (splt->output_section->vma
1215 + splt->output_offset
1216 + h->plt.offset) - value;
1219 value -= (input_section->output_section->vma
1220 + input_section->output_offset);
1221 value -= offset;
1222 value += addend;
1224 bfd_put_32 (input_bfd, value, hit_data);
1225 return bfd_reloc_ok;
1227 case R_MN10300_PLT16:
1228 if (h != NULL
1229 && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
1230 && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
1231 && h->plt.offset != (bfd_vma) -1)
1233 asection * splt;
1235 splt = bfd_get_section_by_name (dynobj, ".plt");
1237 value = (splt->output_section->vma
1238 + splt->output_offset
1239 + h->plt.offset) - value;
1242 value -= (input_section->output_section->vma
1243 + input_section->output_offset);
1244 value -= offset;
1245 value += addend;
1247 if ((long) value > 0xffff || (long) value < -0x10000)
1248 return bfd_reloc_overflow;
1250 bfd_put_16 (input_bfd, value, hit_data);
1251 return bfd_reloc_ok;
1253 case R_MN10300_GOT32:
1254 case R_MN10300_GOT24:
1255 case R_MN10300_GOT16:
1257 asection * sgot;
1259 sgot = bfd_get_section_by_name (dynobj, ".got");
1261 if (h != NULL)
1263 bfd_vma off;
1265 off = h->got.offset;
1266 BFD_ASSERT (off != (bfd_vma) -1);
1268 if (! elf_hash_table (info)->dynamic_sections_created
1269 || SYMBOL_REFERENCES_LOCAL (info, h))
1270 /* This is actually a static link, or it is a
1271 -Bsymbolic link and the symbol is defined
1272 locally, or the symbol was forced to be local
1273 because of a version file. We must initialize
1274 this entry in the global offset table.
1276 When doing a dynamic link, we create a .rela.got
1277 relocation entry to initialize the value. This
1278 is done in the finish_dynamic_symbol routine. */
1279 bfd_put_32 (output_bfd, value,
1280 sgot->contents + off);
1282 value = sgot->output_offset + off;
1284 else
1286 bfd_vma off;
1288 off = elf_local_got_offsets (input_bfd)[symndx];
1290 bfd_put_32 (output_bfd, value, sgot->contents + off);
1292 if (info->shared)
1294 asection * srelgot;
1295 Elf_Internal_Rela outrel;
1297 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1298 BFD_ASSERT (srelgot != NULL);
1300 outrel.r_offset = (sgot->output_section->vma
1301 + sgot->output_offset
1302 + off);
1303 outrel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
1304 outrel.r_addend = value;
1305 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
1306 (bfd_byte *) (((Elf32_External_Rela *)
1307 srelgot->contents)
1308 + srelgot->reloc_count));
1309 ++ srelgot->reloc_count;
1312 value = sgot->output_offset + off;
1316 value += addend;
1318 if (r_type == R_MN10300_GOT32)
1320 bfd_put_32 (input_bfd, value, hit_data);
1321 return bfd_reloc_ok;
1323 else if (r_type == R_MN10300_GOT24)
1325 if ((long) value > 0x7fffff || (long) value < -0x800000)
1326 return bfd_reloc_overflow;
1328 bfd_put_8 (input_bfd, value & 0xff, hit_data);
1329 bfd_put_8 (input_bfd, (value >> 8) & 0xff, hit_data + 1);
1330 bfd_put_8 (input_bfd, (value >> 16) & 0xff, hit_data + 2);
1331 return bfd_reloc_ok;
1333 else if (r_type == R_MN10300_GOT16)
1335 if ((long) value > 0xffff || (long) value < -0x10000)
1336 return bfd_reloc_overflow;
1338 bfd_put_16 (input_bfd, value, hit_data);
1339 return bfd_reloc_ok;
1341 /* Fall through. */
1343 default:
1344 return bfd_reloc_notsupported;
1348 /* Relocate an MN10300 ELF section. */
1349 static bfd_boolean
1350 mn10300_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1351 contents, relocs, local_syms, local_sections)
1352 bfd *output_bfd;
1353 struct bfd_link_info *info;
1354 bfd *input_bfd;
1355 asection *input_section;
1356 bfd_byte *contents;
1357 Elf_Internal_Rela *relocs;
1358 Elf_Internal_Sym *local_syms;
1359 asection **local_sections;
1361 Elf_Internal_Shdr *symtab_hdr;
1362 struct elf_link_hash_entry **sym_hashes;
1363 Elf_Internal_Rela *rel, *relend;
1365 if (info->relocatable)
1366 return TRUE;
1368 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1369 sym_hashes = elf_sym_hashes (input_bfd);
1371 rel = relocs;
1372 relend = relocs + input_section->reloc_count;
1373 for (; rel < relend; rel++)
1375 int r_type;
1376 reloc_howto_type *howto;
1377 unsigned long r_symndx;
1378 Elf_Internal_Sym *sym;
1379 asection *sec;
1380 struct elf32_mn10300_link_hash_entry *h;
1381 bfd_vma relocation;
1382 bfd_reloc_status_type r;
1384 r_symndx = ELF32_R_SYM (rel->r_info);
1385 r_type = ELF32_R_TYPE (rel->r_info);
1386 howto = elf_mn10300_howto_table + r_type;
1388 /* Just skip the vtable gc relocs. */
1389 if (r_type == R_MN10300_GNU_VTINHERIT
1390 || r_type == R_MN10300_GNU_VTENTRY)
1391 continue;
1393 h = NULL;
1394 sym = NULL;
1395 sec = NULL;
1396 if (r_symndx < symtab_hdr->sh_info)
1398 sym = local_syms + r_symndx;
1399 sec = local_sections[r_symndx];
1400 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1402 else
1404 bfd_boolean unresolved_reloc;
1405 bfd_boolean warned;
1406 struct elf_link_hash_entry *hh;
1408 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1409 r_symndx, symtab_hdr, sym_hashes,
1410 hh, sec, relocation,
1411 unresolved_reloc, warned);
1413 h = (struct elf32_mn10300_link_hash_entry *) hh;
1415 if ((h->root.root.type == bfd_link_hash_defined
1416 || h->root.root.type == bfd_link_hash_defweak)
1417 && ( r_type == R_MN10300_GOTPC32
1418 || r_type == R_MN10300_GOTPC16
1419 || (( r_type == R_MN10300_PLT32
1420 || r_type == R_MN10300_PLT16)
1421 && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
1422 && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
1423 && h->root.plt.offset != (bfd_vma) -1)
1424 || (( r_type == R_MN10300_GOT32
1425 || r_type == R_MN10300_GOT24
1426 || r_type == R_MN10300_GOT16)
1427 && elf_hash_table (info)->dynamic_sections_created
1428 && !SYMBOL_REFERENCES_LOCAL (info, hh))
1429 || (r_type == R_MN10300_32
1430 && !SYMBOL_REFERENCES_LOCAL (info, hh)
1431 && ((input_section->flags & SEC_ALLOC) != 0
1432 /* DWARF will emit R_MN10300_32 relocations
1433 in its sections against symbols defined
1434 externally in shared libraries. We can't
1435 do anything with them here. */
1436 || ((input_section->flags & SEC_DEBUGGING) != 0
1437 && h->root.def_dynamic)))))
1438 /* In these cases, we don't need the relocation
1439 value. We check specially because in some
1440 obscure cases sec->output_section will be NULL. */
1441 relocation = 0;
1443 else if (unresolved_reloc)
1444 (*_bfd_error_handler)
1445 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
1446 input_bfd,
1447 input_section,
1448 (long) rel->r_offset,
1449 howto->name,
1450 h->root.root.root.string);
1453 r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd,
1454 input_section,
1455 contents, rel->r_offset,
1456 relocation, rel->r_addend,
1457 (struct elf_link_hash_entry *)h,
1458 r_symndx,
1459 info, sec, h == NULL);
1461 if (r != bfd_reloc_ok)
1463 const char *name;
1464 const char *msg = (const char *) 0;
1466 if (h != NULL)
1467 name = h->root.root.root.string;
1468 else
1470 name = (bfd_elf_string_from_elf_section
1471 (input_bfd, symtab_hdr->sh_link, sym->st_name));
1472 if (name == NULL || *name == '\0')
1473 name = bfd_section_name (input_bfd, sec);
1476 switch (r)
1478 case bfd_reloc_overflow:
1479 if (! ((*info->callbacks->reloc_overflow)
1480 (info, (h ? &h->root.root : NULL), name,
1481 howto->name, (bfd_vma) 0, input_bfd,
1482 input_section, rel->r_offset)))
1483 return FALSE;
1484 break;
1486 case bfd_reloc_undefined:
1487 if (! ((*info->callbacks->undefined_symbol)
1488 (info, name, input_bfd, input_section,
1489 rel->r_offset, TRUE)))
1490 return FALSE;
1491 break;
1493 case bfd_reloc_outofrange:
1494 msg = _("internal error: out of range error");
1495 goto common_error;
1497 case bfd_reloc_notsupported:
1498 msg = _("internal error: unsupported relocation error");
1499 goto common_error;
1501 case bfd_reloc_dangerous:
1502 if (r_type == R_MN10300_PCREL32)
1503 msg = _("error: inappropriate relocation type for shared"
1504 " library (did you forget -fpic?)");
1505 else
1506 msg = _("internal error: suspicious relocation type used"
1507 " in shared library");
1508 goto common_error;
1510 default:
1511 msg = _("internal error: unknown error");
1512 /* fall through */
1514 common_error:
1515 if (!((*info->callbacks->warning)
1516 (info, msg, name, input_bfd, input_section,
1517 rel->r_offset)))
1518 return FALSE;
1519 break;
1524 return TRUE;
1527 /* Finish initializing one hash table entry. */
1528 static bfd_boolean
1529 elf32_mn10300_finish_hash_table_entry (gen_entry, in_args)
1530 struct bfd_hash_entry *gen_entry;
1531 PTR in_args;
1533 struct elf32_mn10300_link_hash_entry *entry;
1534 struct bfd_link_info *link_info = (struct bfd_link_info *)in_args;
1535 unsigned int byte_count = 0;
1537 entry = (struct elf32_mn10300_link_hash_entry *) gen_entry;
1539 if (entry->root.root.type == bfd_link_hash_warning)
1540 entry = (struct elf32_mn10300_link_hash_entry *) entry->root.root.u.i.link;
1542 /* If we already know we want to convert "call" to "calls" for calls
1543 to this symbol, then return now. */
1544 if (entry->flags == MN10300_CONVERT_CALL_TO_CALLS)
1545 return TRUE;
1547 /* If there are no named calls to this symbol, or there's nothing we
1548 can move from the function itself into the "call" instruction,
1549 then note that all "call" instructions should be converted into
1550 "calls" instructions and return. If a symbol is available for
1551 dynamic symbol resolution (overridable or overriding), avoid
1552 custom calling conventions. */
1553 if (entry->direct_calls == 0
1554 || (entry->stack_size == 0 && entry->movm_args == 0)
1555 || (elf_hash_table (link_info)->dynamic_sections_created
1556 && ELF_ST_VISIBILITY (entry->root.other) != STV_INTERNAL
1557 && ELF_ST_VISIBILITY (entry->root.other) != STV_HIDDEN))
1559 /* Make a note that we should convert "call" instructions to "calls"
1560 instructions for calls to this symbol. */
1561 entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1562 return TRUE;
1565 /* We may be able to move some instructions from the function itself into
1566 the "call" instruction. Count how many bytes we might be able to
1567 eliminate in the function itself. */
1569 /* A movm instruction is two bytes. */
1570 if (entry->movm_args)
1571 byte_count += 2;
1573 /* Count the insn to allocate stack space too. */
1574 if (entry->stack_size > 0)
1576 if (entry->stack_size <= 128)
1577 byte_count += 3;
1578 else
1579 byte_count += 4;
1582 /* If using "call" will result in larger code, then turn all
1583 the associated "call" instructions into "calls" instructions. */
1584 if (byte_count < entry->direct_calls)
1585 entry->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1587 /* This routine never fails. */
1588 return TRUE;
1591 /* Used to count hash table entries. */
1592 static bfd_boolean
1593 elf32_mn10300_count_hash_table_entries (struct bfd_hash_entry *gen_entry ATTRIBUTE_UNUSED,
1594 PTR in_args)
1596 int *count = (int *)in_args;
1598 (*count) ++;
1599 return TRUE;
1602 /* Used to enumerate hash table entries into a linear array. */
1603 static bfd_boolean
1604 elf32_mn10300_list_hash_table_entries (struct bfd_hash_entry *gen_entry,
1605 PTR in_args)
1607 struct bfd_hash_entry ***ptr = (struct bfd_hash_entry ***) in_args;
1609 **ptr = gen_entry;
1610 (*ptr) ++;
1611 return TRUE;
1614 /* Used to sort the array created by the above. */
1615 static int
1616 sort_by_value (const void *va, const void *vb)
1618 struct elf32_mn10300_link_hash_entry *a
1619 = *(struct elf32_mn10300_link_hash_entry **)va;
1620 struct elf32_mn10300_link_hash_entry *b
1621 = *(struct elf32_mn10300_link_hash_entry **)vb;
1623 return a->value - b->value;
1627 /* This function handles relaxing for the mn10300.
1629 There are quite a few relaxing opportunities available on the mn10300:
1631 * calls:32 -> calls:16 2 bytes
1632 * call:32 -> call:16 2 bytes
1634 * call:32 -> calls:32 1 byte
1635 * call:16 -> calls:16 1 byte
1636 * These are done anytime using "calls" would result
1637 in smaller code, or when necessary to preserve the
1638 meaning of the program.
1640 * call:32 varies
1641 * call:16
1642 * In some circumstances we can move instructions
1643 from a function prologue into a "call" instruction.
1644 This is only done if the resulting code is no larger
1645 than the original code.
1647 * jmp:32 -> jmp:16 2 bytes
1648 * jmp:16 -> bra:8 1 byte
1650 * If the previous instruction is a conditional branch
1651 around the jump/bra, we may be able to reverse its condition
1652 and change its target to the jump's target. The jump/bra
1653 can then be deleted. 2 bytes
1655 * mov abs32 -> mov abs16 1 or 2 bytes
1657 * Most instructions which accept imm32 can relax to imm16 1 or 2 bytes
1658 - Most instructions which accept imm16 can relax to imm8 1 or 2 bytes
1660 * Most instructions which accept d32 can relax to d16 1 or 2 bytes
1661 - Most instructions which accept d16 can relax to d8 1 or 2 bytes
1663 We don't handle imm16->imm8 or d16->d8 as they're very rare
1664 and somewhat more difficult to support. */
1666 static bfd_boolean
1667 mn10300_elf_relax_section (abfd, sec, link_info, again)
1668 bfd *abfd;
1669 asection *sec;
1670 struct bfd_link_info *link_info;
1671 bfd_boolean *again;
1673 Elf_Internal_Shdr *symtab_hdr;
1674 Elf_Internal_Rela *internal_relocs = NULL;
1675 Elf_Internal_Rela *irel, *irelend;
1676 bfd_byte *contents = NULL;
1677 Elf_Internal_Sym *isymbuf = NULL;
1678 struct elf32_mn10300_link_hash_table *hash_table;
1679 asection *section = sec;
1681 /* Assume nothing changes. */
1682 *again = FALSE;
1684 /* We need a pointer to the mn10300 specific hash table. */
1685 hash_table = elf32_mn10300_hash_table (link_info);
1687 /* Initialize fields in each hash table entry the first time through. */
1688 if ((hash_table->flags & MN10300_HASH_ENTRIES_INITIALIZED) == 0)
1690 bfd *input_bfd;
1692 /* Iterate over all the input bfds. */
1693 for (input_bfd = link_info->input_bfds;
1694 input_bfd != NULL;
1695 input_bfd = input_bfd->link_next)
1697 /* We're going to need all the symbols for each bfd. */
1698 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1699 if (symtab_hdr->sh_info != 0)
1701 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1702 if (isymbuf == NULL)
1703 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
1704 symtab_hdr->sh_info, 0,
1705 NULL, NULL, NULL);
1706 if (isymbuf == NULL)
1707 goto error_return;
1710 /* Iterate over each section in this bfd. */
1711 for (section = input_bfd->sections;
1712 section != NULL;
1713 section = section->next)
1715 struct elf32_mn10300_link_hash_entry *hash;
1716 Elf_Internal_Sym *sym;
1717 asection *sym_sec = NULL;
1718 const char *sym_name;
1719 char *new_name;
1721 /* If there's nothing to do in this section, skip it. */
1722 if (! ((section->flags & SEC_RELOC) != 0
1723 && section->reloc_count != 0))
1724 continue;
1725 if ((section->flags & SEC_ALLOC) == 0)
1726 continue;
1728 /* Get cached copy of section contents if it exists. */
1729 if (elf_section_data (section)->this_hdr.contents != NULL)
1730 contents = elf_section_data (section)->this_hdr.contents;
1731 else if (section->size != 0)
1733 /* Go get them off disk. */
1734 if (!bfd_malloc_and_get_section (input_bfd, section,
1735 &contents))
1736 goto error_return;
1738 else
1739 contents = NULL;
1741 /* If there aren't any relocs, then there's nothing to do. */
1742 if ((section->flags & SEC_RELOC) != 0
1743 && section->reloc_count != 0)
1746 /* Get a copy of the native relocations. */
1747 internal_relocs = (_bfd_elf_link_read_relocs
1748 (input_bfd, section, (PTR) NULL,
1749 (Elf_Internal_Rela *) NULL,
1750 link_info->keep_memory));
1751 if (internal_relocs == NULL)
1752 goto error_return;
1754 /* Now examine each relocation. */
1755 irel = internal_relocs;
1756 irelend = irel + section->reloc_count;
1757 for (; irel < irelend; irel++)
1759 long r_type;
1760 unsigned long r_index;
1761 unsigned char code;
1763 r_type = ELF32_R_TYPE (irel->r_info);
1764 r_index = ELF32_R_SYM (irel->r_info);
1766 if (r_type < 0 || r_type >= (int) R_MN10300_MAX)
1767 goto error_return;
1769 /* We need the name and hash table entry of the target
1770 symbol! */
1771 hash = NULL;
1772 sym = NULL;
1773 sym_sec = NULL;
1775 if (r_index < symtab_hdr->sh_info)
1777 /* A local symbol. */
1778 Elf_Internal_Sym *isym;
1779 struct elf_link_hash_table *elftab;
1780 bfd_size_type amt;
1782 isym = isymbuf + r_index;
1783 if (isym->st_shndx == SHN_UNDEF)
1784 sym_sec = bfd_und_section_ptr;
1785 else if (isym->st_shndx == SHN_ABS)
1786 sym_sec = bfd_abs_section_ptr;
1787 else if (isym->st_shndx == SHN_COMMON)
1788 sym_sec = bfd_com_section_ptr;
1789 else
1790 sym_sec
1791 = bfd_section_from_elf_index (input_bfd,
1792 isym->st_shndx);
1794 sym_name
1795 = bfd_elf_string_from_elf_section (input_bfd,
1796 (symtab_hdr
1797 ->sh_link),
1798 isym->st_name);
1800 /* If it isn't a function, then we don't care
1801 about it. */
1802 if (ELF_ST_TYPE (isym->st_info) != STT_FUNC)
1803 continue;
1805 /* Tack on an ID so we can uniquely identify this
1806 local symbol in the global hash table. */
1807 amt = strlen (sym_name) + 10;
1808 new_name = bfd_malloc (amt);
1809 if (new_name == 0)
1810 goto error_return;
1812 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
1813 sym_name = new_name;
1815 elftab = &hash_table->static_hash_table->root;
1816 hash = ((struct elf32_mn10300_link_hash_entry *)
1817 elf_link_hash_lookup (elftab, sym_name,
1818 TRUE, TRUE, FALSE));
1819 free (new_name);
1821 else
1823 r_index -= symtab_hdr->sh_info;
1824 hash = (struct elf32_mn10300_link_hash_entry *)
1825 elf_sym_hashes (input_bfd)[r_index];
1828 sym_name = hash->root.root.root.string;
1829 if ((section->flags & SEC_CODE) != 0)
1831 /* If this is not a "call" instruction, then we
1832 should convert "call" instructions to "calls"
1833 instructions. */
1834 code = bfd_get_8 (input_bfd,
1835 contents + irel->r_offset - 1);
1836 if (code != 0xdd && code != 0xcd)
1837 hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1840 /* If this is a jump/call, then bump the
1841 direct_calls counter. Else force "call" to
1842 "calls" conversions. */
1843 if (r_type == R_MN10300_PCREL32
1844 || r_type == R_MN10300_PLT32
1845 || r_type == R_MN10300_PLT16
1846 || r_type == R_MN10300_PCREL16)
1847 hash->direct_calls++;
1848 else
1849 hash->flags |= MN10300_CONVERT_CALL_TO_CALLS;
1853 /* Now look at the actual contents to get the stack size,
1854 and a list of what registers were saved in the prologue
1855 (ie movm_args). */
1856 if ((section->flags & SEC_CODE) != 0)
1858 Elf_Internal_Sym *isym, *isymend;
1859 unsigned int sec_shndx;
1860 struct elf_link_hash_entry **hashes;
1861 struct elf_link_hash_entry **end_hashes;
1862 unsigned int symcount;
1864 sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
1865 section);
1867 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1868 - symtab_hdr->sh_info);
1869 hashes = elf_sym_hashes (input_bfd);
1870 end_hashes = hashes + symcount;
1872 /* Look at each function defined in this section and
1873 update info for that function. */
1874 isymend = isymbuf + symtab_hdr->sh_info;
1875 for (isym = isymbuf; isym < isymend; isym++)
1877 if (isym->st_shndx == sec_shndx
1878 && ELF_ST_TYPE (isym->st_info) == STT_FUNC)
1880 struct elf_link_hash_table *elftab;
1881 bfd_size_type amt;
1882 struct elf_link_hash_entry **lhashes = hashes;
1884 /* Skip a local symbol if it aliases a
1885 global one. */
1886 for (; lhashes < end_hashes; lhashes++)
1888 hash = (struct elf32_mn10300_link_hash_entry *) *lhashes;
1889 if ((hash->root.root.type == bfd_link_hash_defined
1890 || hash->root.root.type == bfd_link_hash_defweak)
1891 && hash->root.root.u.def.section == section
1892 && hash->root.type == STT_FUNC
1893 && hash->root.root.u.def.value == isym->st_value)
1894 break;
1896 if (lhashes != end_hashes)
1897 continue;
1899 if (isym->st_shndx == SHN_UNDEF)
1900 sym_sec = bfd_und_section_ptr;
1901 else if (isym->st_shndx == SHN_ABS)
1902 sym_sec = bfd_abs_section_ptr;
1903 else if (isym->st_shndx == SHN_COMMON)
1904 sym_sec = bfd_com_section_ptr;
1905 else
1906 sym_sec
1907 = bfd_section_from_elf_index (input_bfd,
1908 isym->st_shndx);
1910 sym_name = (bfd_elf_string_from_elf_section
1911 (input_bfd, symtab_hdr->sh_link,
1912 isym->st_name));
1914 /* Tack on an ID so we can uniquely identify this
1915 local symbol in the global hash table. */
1916 amt = strlen (sym_name) + 10;
1917 new_name = bfd_malloc (amt);
1918 if (new_name == 0)
1919 goto error_return;
1921 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
1922 sym_name = new_name;
1924 elftab = &hash_table->static_hash_table->root;
1925 hash = ((struct elf32_mn10300_link_hash_entry *)
1926 elf_link_hash_lookup (elftab, sym_name,
1927 TRUE, TRUE, FALSE));
1928 free (new_name);
1929 compute_function_info (input_bfd, hash,
1930 isym->st_value, contents);
1931 hash->value = isym->st_value;
1935 for (; hashes < end_hashes; hashes++)
1937 hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
1938 if ((hash->root.root.type == bfd_link_hash_defined
1939 || hash->root.root.type == bfd_link_hash_defweak)
1940 && hash->root.root.u.def.section == section
1941 && hash->root.type == STT_FUNC)
1942 compute_function_info (input_bfd, hash,
1943 (hash)->root.root.u.def.value,
1944 contents);
1948 /* Cache or free any memory we allocated for the relocs. */
1949 if (internal_relocs != NULL
1950 && elf_section_data (section)->relocs != internal_relocs)
1951 free (internal_relocs);
1952 internal_relocs = NULL;
1954 /* Cache or free any memory we allocated for the contents. */
1955 if (contents != NULL
1956 && elf_section_data (section)->this_hdr.contents != contents)
1958 if (! link_info->keep_memory)
1959 free (contents);
1960 else
1962 /* Cache the section contents for elf_link_input_bfd. */
1963 elf_section_data (section)->this_hdr.contents = contents;
1966 contents = NULL;
1969 /* Cache or free any memory we allocated for the symbols. */
1970 if (isymbuf != NULL
1971 && symtab_hdr->contents != (unsigned char *) isymbuf)
1973 if (! link_info->keep_memory)
1974 free (isymbuf);
1975 else
1977 /* Cache the symbols for elf_link_input_bfd. */
1978 symtab_hdr->contents = (unsigned char *) isymbuf;
1981 isymbuf = NULL;
1984 /* Now iterate on each symbol in the hash table and perform
1985 the final initialization steps on each. */
1986 elf32_mn10300_link_hash_traverse (hash_table,
1987 elf32_mn10300_finish_hash_table_entry,
1988 link_info);
1989 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
1990 elf32_mn10300_finish_hash_table_entry,
1991 link_info);
1994 /* This section of code collects all our local symbols, sorts
1995 them by value, and looks for multiple symbols referring to
1996 the same address. For those symbols, the flags are merged.
1997 At this point, the only flag that can be set is
1998 MN10300_CONVERT_CALL_TO_CALLS, so we simply OR the flags
1999 together. */
2000 int static_count = 0, i;
2001 struct elf32_mn10300_link_hash_entry **entries;
2002 struct elf32_mn10300_link_hash_entry **ptr;
2004 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2005 elf32_mn10300_count_hash_table_entries,
2006 &static_count);
2008 entries = (struct elf32_mn10300_link_hash_entry **)
2009 bfd_malloc (static_count * sizeof (struct elf32_mn10300_link_hash_entry *));
2011 ptr = entries;
2012 elf32_mn10300_link_hash_traverse (hash_table->static_hash_table,
2013 elf32_mn10300_list_hash_table_entries,
2014 &ptr);
2016 qsort (entries, static_count, sizeof(entries[0]), sort_by_value);
2018 for (i=0; i<static_count-1; i++)
2019 if (entries[i]->value && entries[i]->value == entries[i+1]->value)
2021 int v = entries[i]->flags;
2022 int j;
2023 for (j=i+1; j<static_count && entries[j]->value == entries[i]->value; j++)
2024 v |= entries[j]->flags;
2025 for (j=i; j<static_count && entries[j]->value == entries[i]->value; j++)
2026 entries[j]->flags = v;
2027 i = j-1;
2031 /* All entries in the hash table are fully initialized. */
2032 hash_table->flags |= MN10300_HASH_ENTRIES_INITIALIZED;
2034 /* Now that everything has been initialized, go through each
2035 code section and delete any prologue insns which will be
2036 redundant because their operations will be performed by
2037 a "call" instruction. */
2038 for (input_bfd = link_info->input_bfds;
2039 input_bfd != NULL;
2040 input_bfd = input_bfd->link_next)
2042 /* We're going to need all the local symbols for each bfd. */
2043 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2044 if (symtab_hdr->sh_info != 0)
2046 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2047 if (isymbuf == NULL)
2048 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
2049 symtab_hdr->sh_info, 0,
2050 NULL, NULL, NULL);
2051 if (isymbuf == NULL)
2052 goto error_return;
2055 /* Walk over each section in this bfd. */
2056 for (section = input_bfd->sections;
2057 section != NULL;
2058 section = section->next)
2060 unsigned int sec_shndx;
2061 Elf_Internal_Sym *isym, *isymend;
2062 struct elf_link_hash_entry **hashes;
2063 struct elf_link_hash_entry **end_hashes;
2064 unsigned int symcount;
2066 /* Skip non-code sections and empty sections. */
2067 if ((section->flags & SEC_CODE) == 0 || section->size == 0)
2068 continue;
2070 if (section->reloc_count != 0)
2072 /* Get a copy of the native relocations. */
2073 internal_relocs = (_bfd_elf_link_read_relocs
2074 (input_bfd, section, (PTR) NULL,
2075 (Elf_Internal_Rela *) NULL,
2076 link_info->keep_memory));
2077 if (internal_relocs == NULL)
2078 goto error_return;
2081 /* Get cached copy of section contents if it exists. */
2082 if (elf_section_data (section)->this_hdr.contents != NULL)
2083 contents = elf_section_data (section)->this_hdr.contents;
2084 else
2086 /* Go get them off disk. */
2087 if (!bfd_malloc_and_get_section (input_bfd, section,
2088 &contents))
2089 goto error_return;
2092 sec_shndx = _bfd_elf_section_from_bfd_section (input_bfd,
2093 section);
2095 /* Now look for any function in this section which needs
2096 insns deleted from its prologue. */
2097 isymend = isymbuf + symtab_hdr->sh_info;
2098 for (isym = isymbuf; isym < isymend; isym++)
2100 struct elf32_mn10300_link_hash_entry *sym_hash;
2101 asection *sym_sec = NULL;
2102 const char *sym_name;
2103 char *new_name;
2104 struct elf_link_hash_table *elftab;
2105 bfd_size_type amt;
2107 if (isym->st_shndx != sec_shndx)
2108 continue;
2110 if (isym->st_shndx == SHN_UNDEF)
2111 sym_sec = bfd_und_section_ptr;
2112 else if (isym->st_shndx == SHN_ABS)
2113 sym_sec = bfd_abs_section_ptr;
2114 else if (isym->st_shndx == SHN_COMMON)
2115 sym_sec = bfd_com_section_ptr;
2116 else
2117 sym_sec
2118 = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
2120 sym_name
2121 = bfd_elf_string_from_elf_section (input_bfd,
2122 symtab_hdr->sh_link,
2123 isym->st_name);
2125 /* Tack on an ID so we can uniquely identify this
2126 local symbol in the global hash table. */
2127 amt = strlen (sym_name) + 10;
2128 new_name = bfd_malloc (amt);
2129 if (new_name == 0)
2130 goto error_return;
2131 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2132 sym_name = new_name;
2134 elftab = &hash_table->static_hash_table->root;
2135 sym_hash = ((struct elf32_mn10300_link_hash_entry *)
2136 elf_link_hash_lookup (elftab, sym_name,
2137 FALSE, FALSE, FALSE));
2139 free (new_name);
2140 if (sym_hash == NULL)
2141 continue;
2143 if (! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
2144 && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
2146 int bytes = 0;
2148 /* Note that we've changed things. */
2149 elf_section_data (section)->relocs = internal_relocs;
2150 elf_section_data (section)->this_hdr.contents = contents;
2151 symtab_hdr->contents = (unsigned char *) isymbuf;
2153 /* Count how many bytes we're going to delete. */
2154 if (sym_hash->movm_args)
2155 bytes += 2;
2157 if (sym_hash->stack_size > 0)
2159 if (sym_hash->stack_size <= 128)
2160 bytes += 3;
2161 else
2162 bytes += 4;
2165 /* Note that we've deleted prologue bytes for this
2166 function. */
2167 sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
2169 /* Actually delete the bytes. */
2170 if (!mn10300_elf_relax_delete_bytes (input_bfd,
2171 section,
2172 isym->st_value,
2173 bytes))
2174 goto error_return;
2176 /* Something changed. Not strictly necessary, but
2177 may lead to more relaxing opportunities. */
2178 *again = TRUE;
2182 /* Look for any global functions in this section which
2183 need insns deleted from their prologues. */
2184 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2185 - symtab_hdr->sh_info);
2186 hashes = elf_sym_hashes (input_bfd);
2187 end_hashes = hashes + symcount;
2188 for (; hashes < end_hashes; hashes++)
2190 struct elf32_mn10300_link_hash_entry *sym_hash;
2192 sym_hash = (struct elf32_mn10300_link_hash_entry *) *hashes;
2193 if ((sym_hash->root.root.type == bfd_link_hash_defined
2194 || sym_hash->root.root.type == bfd_link_hash_defweak)
2195 && sym_hash->root.root.u.def.section == section
2196 && ! (sym_hash->flags & MN10300_CONVERT_CALL_TO_CALLS)
2197 && ! (sym_hash->flags & MN10300_DELETED_PROLOGUE_BYTES))
2199 int bytes = 0;
2200 bfd_vma symval;
2202 /* Note that we've changed things. */
2203 elf_section_data (section)->relocs = internal_relocs;
2204 elf_section_data (section)->this_hdr.contents = contents;
2205 symtab_hdr->contents = (unsigned char *) isymbuf;
2207 /* Count how many bytes we're going to delete. */
2208 if (sym_hash->movm_args)
2209 bytes += 2;
2211 if (sym_hash->stack_size > 0)
2213 if (sym_hash->stack_size <= 128)
2214 bytes += 3;
2215 else
2216 bytes += 4;
2219 /* Note that we've deleted prologue bytes for this
2220 function. */
2221 sym_hash->flags |= MN10300_DELETED_PROLOGUE_BYTES;
2223 /* Actually delete the bytes. */
2224 symval = sym_hash->root.root.u.def.value;
2225 if (!mn10300_elf_relax_delete_bytes (input_bfd,
2226 section,
2227 symval,
2228 bytes))
2229 goto error_return;
2231 /* Something changed. Not strictly necessary, but
2232 may lead to more relaxing opportunities. */
2233 *again = TRUE;
2237 /* Cache or free any memory we allocated for the relocs. */
2238 if (internal_relocs != NULL
2239 && elf_section_data (section)->relocs != internal_relocs)
2240 free (internal_relocs);
2241 internal_relocs = NULL;
2243 /* Cache or free any memory we allocated for the contents. */
2244 if (contents != NULL
2245 && elf_section_data (section)->this_hdr.contents != contents)
2247 if (! link_info->keep_memory)
2248 free (contents);
2249 else
2251 /* Cache the section contents for elf_link_input_bfd. */
2252 elf_section_data (section)->this_hdr.contents = contents;
2255 contents = NULL;
2258 /* Cache or free any memory we allocated for the symbols. */
2259 if (isymbuf != NULL
2260 && symtab_hdr->contents != (unsigned char *) isymbuf)
2262 if (! link_info->keep_memory)
2263 free (isymbuf);
2264 else
2266 /* Cache the symbols for elf_link_input_bfd. */
2267 symtab_hdr->contents = (unsigned char *) isymbuf;
2270 isymbuf = NULL;
2274 /* (Re)initialize for the basic instruction shortening/relaxing pass. */
2275 contents = NULL;
2276 internal_relocs = NULL;
2277 isymbuf = NULL;
2278 /* For error_return. */
2279 section = sec;
2281 /* We don't have to do anything for a relocatable link, if
2282 this section does not have relocs, or if this is not a
2283 code section. */
2284 if (link_info->relocatable
2285 || (sec->flags & SEC_RELOC) == 0
2286 || sec->reloc_count == 0
2287 || (sec->flags & SEC_CODE) == 0)
2288 return TRUE;
2290 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2292 /* Get a copy of the native relocations. */
2293 internal_relocs = (_bfd_elf_link_read_relocs
2294 (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
2295 link_info->keep_memory));
2296 if (internal_relocs == NULL)
2297 goto error_return;
2299 /* Walk through them looking for relaxing opportunities. */
2300 irelend = internal_relocs + sec->reloc_count;
2301 for (irel = internal_relocs; irel < irelend; irel++)
2303 bfd_vma symval;
2304 struct elf32_mn10300_link_hash_entry *h = NULL;
2306 /* If this isn't something that can be relaxed, then ignore
2307 this reloc. */
2308 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_NONE
2309 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_8
2310 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_MAX)
2311 continue;
2313 /* Get the section contents if we haven't done so already. */
2314 if (contents == NULL)
2316 /* Get cached copy if it exists. */
2317 if (elf_section_data (sec)->this_hdr.contents != NULL)
2318 contents = elf_section_data (sec)->this_hdr.contents;
2319 else
2321 /* Go get them off disk. */
2322 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2323 goto error_return;
2327 /* Read this BFD's symbols if we haven't done so already. */
2328 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2330 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2331 if (isymbuf == NULL)
2332 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2333 symtab_hdr->sh_info, 0,
2334 NULL, NULL, NULL);
2335 if (isymbuf == NULL)
2336 goto error_return;
2339 /* Get the value of the symbol referred to by the reloc. */
2340 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2342 Elf_Internal_Sym *isym;
2343 asection *sym_sec = NULL;
2344 const char *sym_name;
2345 char *new_name;
2346 bfd_vma saved_addend;
2348 /* A local symbol. */
2349 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2350 if (isym->st_shndx == SHN_UNDEF)
2351 sym_sec = bfd_und_section_ptr;
2352 else if (isym->st_shndx == SHN_ABS)
2353 sym_sec = bfd_abs_section_ptr;
2354 else if (isym->st_shndx == SHN_COMMON)
2355 sym_sec = bfd_com_section_ptr;
2356 else
2357 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2359 sym_name = bfd_elf_string_from_elf_section (abfd,
2360 symtab_hdr->sh_link,
2361 isym->st_name);
2363 if ((sym_sec->flags & SEC_MERGE)
2364 && ELF_ST_TYPE (isym->st_info) == STT_SECTION
2365 && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
2367 saved_addend = irel->r_addend;
2368 symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
2369 symval += irel->r_addend;
2370 irel->r_addend = saved_addend;
2372 else
2374 symval = (isym->st_value
2375 + sym_sec->output_section->vma
2376 + sym_sec->output_offset);
2378 /* Tack on an ID so we can uniquely identify this
2379 local symbol in the global hash table. */
2380 new_name = bfd_malloc ((bfd_size_type) strlen (sym_name) + 10);
2381 if (new_name == 0)
2382 goto error_return;
2383 sprintf (new_name, "%s_%08x", sym_name, sym_sec->id);
2384 sym_name = new_name;
2386 h = (struct elf32_mn10300_link_hash_entry *)
2387 elf_link_hash_lookup (&hash_table->static_hash_table->root,
2388 sym_name, FALSE, FALSE, FALSE);
2389 free (new_name);
2391 else
2393 unsigned long indx;
2395 /* An external symbol. */
2396 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2397 h = (struct elf32_mn10300_link_hash_entry *)
2398 (elf_sym_hashes (abfd)[indx]);
2399 BFD_ASSERT (h != NULL);
2400 if (h->root.root.type != bfd_link_hash_defined
2401 && h->root.root.type != bfd_link_hash_defweak)
2403 /* This appears to be a reference to an undefined
2404 symbol. Just ignore it--it will be caught by the
2405 regular reloc processing. */
2406 continue;
2409 symval = (h->root.root.u.def.value
2410 + h->root.root.u.def.section->output_section->vma
2411 + h->root.root.u.def.section->output_offset);
2414 /* For simplicity of coding, we are going to modify the section
2415 contents, the section relocs, and the BFD symbol table. We
2416 must tell the rest of the code not to free up this
2417 information. It would be possible to instead create a table
2418 of changes which have to be made, as is done in coff-mips.c;
2419 that would be more work, but would require less memory when
2420 the linker is run. */
2422 /* Try to turn a 32bit pc-relative branch/call into a 16bit pc-relative
2423 branch/call, also deal with "call" -> "calls" conversions and
2424 insertion of prologue data into "call" instructions. */
2425 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL32
2426 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32)
2428 bfd_vma value = symval;
2430 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PLT32
2431 && h != NULL
2432 && ELF_ST_VISIBILITY (h->root.other) != STV_INTERNAL
2433 && ELF_ST_VISIBILITY (h->root.other) != STV_HIDDEN
2434 && h->root.plt.offset != (bfd_vma) -1)
2436 asection * splt;
2438 splt = bfd_get_section_by_name (elf_hash_table (link_info)
2439 ->dynobj, ".plt");
2441 value = ((splt->output_section->vma
2442 + splt->output_offset
2443 + h->root.plt.offset)
2444 - (sec->output_section->vma
2445 + sec->output_offset
2446 + irel->r_offset));
2449 /* If we've got a "call" instruction that needs to be turned
2450 into a "calls" instruction, do so now. It saves a byte. */
2451 if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
2453 unsigned char code;
2455 /* Get the opcode. */
2456 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2458 /* Make sure we're working with a "call" instruction! */
2459 if (code == 0xdd)
2461 /* Note that we've changed the relocs, section contents,
2462 etc. */
2463 elf_section_data (sec)->relocs = internal_relocs;
2464 elf_section_data (sec)->this_hdr.contents = contents;
2465 symtab_hdr->contents = (unsigned char *) isymbuf;
2467 /* Fix the opcode. */
2468 bfd_put_8 (abfd, 0xfc, contents + irel->r_offset - 1);
2469 bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
2471 /* Fix irel->r_offset and irel->r_addend. */
2472 irel->r_offset += 1;
2473 irel->r_addend += 1;
2475 /* Delete one byte of data. */
2476 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2477 irel->r_offset + 3, 1))
2478 goto error_return;
2480 /* That will change things, so, we should relax again.
2481 Note that this is not required, and it may be slow. */
2482 *again = TRUE;
2485 else if (h)
2487 /* We've got a "call" instruction which needs some data
2488 from target function filled in. */
2489 unsigned char code;
2491 /* Get the opcode. */
2492 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2494 /* Insert data from the target function into the "call"
2495 instruction if needed. */
2496 if (code == 0xdd)
2498 bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 4);
2499 bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
2500 contents + irel->r_offset + 5);
2504 /* Deal with pc-relative gunk. */
2505 value -= (sec->output_section->vma + sec->output_offset);
2506 value -= irel->r_offset;
2507 value += irel->r_addend;
2509 /* See if the value will fit in 16 bits, note the high value is
2510 0x7fff + 2 as the target will be two bytes closer if we are
2511 able to relax. */
2512 if ((long) value < 0x8001 && (long) value > -0x8000)
2514 unsigned char code;
2516 /* Get the opcode. */
2517 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2519 if (code != 0xdc && code != 0xdd && code != 0xff)
2520 continue;
2522 /* Note that we've changed the relocs, section contents, etc. */
2523 elf_section_data (sec)->relocs = internal_relocs;
2524 elf_section_data (sec)->this_hdr.contents = contents;
2525 symtab_hdr->contents = (unsigned char *) isymbuf;
2527 /* Fix the opcode. */
2528 if (code == 0xdc)
2529 bfd_put_8 (abfd, 0xcc, contents + irel->r_offset - 1);
2530 else if (code == 0xdd)
2531 bfd_put_8 (abfd, 0xcd, contents + irel->r_offset - 1);
2532 else if (code == 0xff)
2533 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
2535 /* Fix the relocation's type. */
2536 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2537 (ELF32_R_TYPE (irel->r_info)
2538 == (int) R_MN10300_PLT32)
2539 ? R_MN10300_PLT16 :
2540 R_MN10300_PCREL16);
2542 /* Delete two bytes of data. */
2543 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2544 irel->r_offset + 1, 2))
2545 goto error_return;
2547 /* That will change things, so, we should relax again.
2548 Note that this is not required, and it may be slow. */
2549 *again = TRUE;
2553 /* Try to turn a 16bit pc-relative branch into a 8bit pc-relative
2554 branch. */
2555 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL16)
2557 bfd_vma value = symval;
2559 /* If we've got a "call" instruction that needs to be turned
2560 into a "calls" instruction, do so now. It saves a byte. */
2561 if (h && (h->flags & MN10300_CONVERT_CALL_TO_CALLS))
2563 unsigned char code;
2565 /* Get the opcode. */
2566 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2568 /* Make sure we're working with a "call" instruction! */
2569 if (code == 0xcd)
2571 /* Note that we've changed the relocs, section contents,
2572 etc. */
2573 elf_section_data (sec)->relocs = internal_relocs;
2574 elf_section_data (sec)->this_hdr.contents = contents;
2575 symtab_hdr->contents = (unsigned char *) isymbuf;
2577 /* Fix the opcode. */
2578 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 1);
2579 bfd_put_8 (abfd, 0xff, contents + irel->r_offset);
2581 /* Fix irel->r_offset and irel->r_addend. */
2582 irel->r_offset += 1;
2583 irel->r_addend += 1;
2585 /* Delete one byte of data. */
2586 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2587 irel->r_offset + 1, 1))
2588 goto error_return;
2590 /* That will change things, so, we should relax again.
2591 Note that this is not required, and it may be slow. */
2592 *again = TRUE;
2595 else if (h)
2597 unsigned char code;
2599 /* Get the opcode. */
2600 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2602 /* Insert data from the target function into the "call"
2603 instruction if needed. */
2604 if (code == 0xcd)
2606 bfd_put_8 (abfd, h->movm_args, contents + irel->r_offset + 2);
2607 bfd_put_8 (abfd, h->stack_size + h->movm_stack_size,
2608 contents + irel->r_offset + 3);
2612 /* Deal with pc-relative gunk. */
2613 value -= (sec->output_section->vma + sec->output_offset);
2614 value -= irel->r_offset;
2615 value += irel->r_addend;
2617 /* See if the value will fit in 8 bits, note the high value is
2618 0x7f + 1 as the target will be one bytes closer if we are
2619 able to relax. */
2620 if ((long) value < 0x80 && (long) value > -0x80)
2622 unsigned char code;
2624 /* Get the opcode. */
2625 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2627 if (code != 0xcc)
2628 continue;
2630 /* Note that we've changed the relocs, section contents, etc. */
2631 elf_section_data (sec)->relocs = internal_relocs;
2632 elf_section_data (sec)->this_hdr.contents = contents;
2633 symtab_hdr->contents = (unsigned char *) isymbuf;
2635 /* Fix the opcode. */
2636 bfd_put_8 (abfd, 0xca, contents + irel->r_offset - 1);
2638 /* Fix the relocation's type. */
2639 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2640 R_MN10300_PCREL8);
2642 /* Delete one byte of data. */
2643 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2644 irel->r_offset + 1, 1))
2645 goto error_return;
2647 /* That will change things, so, we should relax again.
2648 Note that this is not required, and it may be slow. */
2649 *again = TRUE;
2653 /* Try to eliminate an unconditional 8 bit pc-relative branch
2654 which immediately follows a conditional 8 bit pc-relative
2655 branch around the unconditional branch.
2657 original: new:
2658 bCC lab1 bCC' lab2
2659 bra lab2
2660 lab1: lab1:
2662 This happens when the bCC can't reach lab2 at assembly time,
2663 but due to other relaxations it can reach at link time. */
2664 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8)
2666 Elf_Internal_Rela *nrel;
2667 bfd_vma value = symval;
2668 unsigned char code;
2670 /* Deal with pc-relative gunk. */
2671 value -= (sec->output_section->vma + sec->output_offset);
2672 value -= irel->r_offset;
2673 value += irel->r_addend;
2675 /* Do nothing if this reloc is the last byte in the section. */
2676 if (irel->r_offset == sec->size)
2677 continue;
2679 /* See if the next instruction is an unconditional pc-relative
2680 branch, more often than not this test will fail, so we
2681 test it first to speed things up. */
2682 code = bfd_get_8 (abfd, contents + irel->r_offset + 1);
2683 if (code != 0xca)
2684 continue;
2686 /* Also make sure the next relocation applies to the next
2687 instruction and that it's a pc-relative 8 bit branch. */
2688 nrel = irel + 1;
2689 if (nrel == irelend
2690 || irel->r_offset + 2 != nrel->r_offset
2691 || ELF32_R_TYPE (nrel->r_info) != (int) R_MN10300_PCREL8)
2692 continue;
2694 /* Make sure our destination immediately follows the
2695 unconditional branch. */
2696 if (symval != (sec->output_section->vma + sec->output_offset
2697 + irel->r_offset + 3))
2698 continue;
2700 /* Now make sure we are a conditional branch. This may not
2701 be necessary, but why take the chance.
2703 Note these checks assume that R_MN10300_PCREL8 relocs
2704 only occur on bCC and bCCx insns. If they occured
2705 elsewhere, we'd need to know the start of this insn
2706 for this check to be accurate. */
2707 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2708 if (code != 0xc0 && code != 0xc1 && code != 0xc2
2709 && code != 0xc3 && code != 0xc4 && code != 0xc5
2710 && code != 0xc6 && code != 0xc7 && code != 0xc8
2711 && code != 0xc9 && code != 0xe8 && code != 0xe9
2712 && code != 0xea && code != 0xeb)
2713 continue;
2715 /* We also have to be sure there is no symbol/label
2716 at the unconditional branch. */
2717 if (mn10300_elf_symbol_address_p (abfd, sec, isymbuf,
2718 irel->r_offset + 1))
2719 continue;
2721 /* Note that we've changed the relocs, section contents, etc. */
2722 elf_section_data (sec)->relocs = internal_relocs;
2723 elf_section_data (sec)->this_hdr.contents = contents;
2724 symtab_hdr->contents = (unsigned char *) isymbuf;
2726 /* Reverse the condition of the first branch. */
2727 switch (code)
2729 case 0xc8:
2730 code = 0xc9;
2731 break;
2732 case 0xc9:
2733 code = 0xc8;
2734 break;
2735 case 0xc0:
2736 code = 0xc2;
2737 break;
2738 case 0xc2:
2739 code = 0xc0;
2740 break;
2741 case 0xc3:
2742 code = 0xc1;
2743 break;
2744 case 0xc1:
2745 code = 0xc3;
2746 break;
2747 case 0xc4:
2748 code = 0xc6;
2749 break;
2750 case 0xc6:
2751 code = 0xc4;
2752 break;
2753 case 0xc7:
2754 code = 0xc5;
2755 break;
2756 case 0xc5:
2757 code = 0xc7;
2758 break;
2759 case 0xe8:
2760 code = 0xe9;
2761 break;
2762 case 0x9d:
2763 code = 0xe8;
2764 break;
2765 case 0xea:
2766 code = 0xeb;
2767 break;
2768 case 0xeb:
2769 code = 0xea;
2770 break;
2772 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
2774 /* Set the reloc type and symbol for the first branch
2775 from the second branch. */
2776 irel->r_info = nrel->r_info;
2778 /* Make the reloc for the second branch a null reloc. */
2779 nrel->r_info = ELF32_R_INFO (ELF32_R_SYM (nrel->r_info),
2780 R_MN10300_NONE);
2782 /* Delete two bytes of data. */
2783 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2784 irel->r_offset + 1, 2))
2785 goto error_return;
2787 /* That will change things, so, we should relax again.
2788 Note that this is not required, and it may be slow. */
2789 *again = TRUE;
2792 /* Try to turn a 24 immediate, displacement or absolute address
2793 into a 8 immediate, displacement or absolute address. */
2794 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_24)
2796 bfd_vma value = symval;
2797 value += irel->r_addend;
2799 /* See if the value will fit in 8 bits. */
2800 if ((long) value < 0x7f && (long) value > -0x80)
2802 unsigned char code;
2804 /* AM33 insns which have 24 operands are 6 bytes long and
2805 will have 0xfd as the first byte. */
2807 /* Get the first opcode. */
2808 code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
2810 if (code == 0xfd)
2812 /* Get the second opcode. */
2813 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2815 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2816 equivalent instructions exists. */
2817 if (code != 0x6b && code != 0x7b
2818 && code != 0x8b && code != 0x9b
2819 && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2820 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2821 || (code & 0x0f) == 0x0e))
2823 /* Not safe if the high bit is on as relaxing may
2824 move the value out of high mem and thus not fit
2825 in a signed 8bit value. This is currently over
2826 conservative. */
2827 if ((value & 0x80) == 0)
2829 /* Note that we've changed the relocation contents,
2830 etc. */
2831 elf_section_data (sec)->relocs = internal_relocs;
2832 elf_section_data (sec)->this_hdr.contents = contents;
2833 symtab_hdr->contents = (unsigned char *) isymbuf;
2835 /* Fix the opcode. */
2836 bfd_put_8 (abfd, 0xfb, contents + irel->r_offset - 3);
2837 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
2839 /* Fix the relocation's type. */
2840 irel->r_info =
2841 ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2842 R_MN10300_8);
2844 /* Delete two bytes of data. */
2845 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2846 irel->r_offset + 1, 2))
2847 goto error_return;
2849 /* That will change things, so, we should relax
2850 again. Note that this is not required, and it
2851 may be slow. */
2852 *again = TRUE;
2853 break;
2860 /* Try to turn a 32bit immediate, displacement or absolute address
2861 into a 16bit immediate, displacement or absolute address. */
2862 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_32
2863 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32
2864 || ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2866 bfd_vma value = symval;
2868 if (ELF32_R_TYPE (irel->r_info) != (int) R_MN10300_32)
2870 asection * sgot;
2872 sgot = bfd_get_section_by_name (elf_hash_table (link_info)
2873 ->dynobj, ".got");
2875 if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOT32)
2877 value = sgot->output_offset;
2879 if (h)
2880 value += h->root.got.offset;
2881 else
2882 value += (elf_local_got_offsets
2883 (abfd)[ELF32_R_SYM (irel->r_info)]);
2885 else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTOFF32)
2886 value -= sgot->output_section->vma;
2887 else if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_GOTPC32)
2888 value = (sgot->output_section->vma
2889 - (sec->output_section->vma
2890 + sec->output_offset
2891 + irel->r_offset));
2892 else
2893 abort ();
2896 value += irel->r_addend;
2898 /* See if the value will fit in 24 bits.
2899 We allow any 16bit match here. We prune those we can't
2900 handle below. */
2901 if ((long) value < 0x7fffff && (long) value > -0x800000)
2903 unsigned char code;
2905 /* AM33 insns which have 32bit operands are 7 bytes long and
2906 will have 0xfe as the first byte. */
2908 /* Get the first opcode. */
2909 code = bfd_get_8 (abfd, contents + irel->r_offset - 3);
2911 if (code == 0xfe)
2913 /* Get the second opcode. */
2914 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2916 /* All the am33 32 -> 24 relaxing possibilities. */
2917 /* We can not relax 0x6b, 0x7b, 0x8b, 0x9b as no 24bit
2918 equivalent instructions exists. */
2919 if (code != 0x6b && code != 0x7b
2920 && code != 0x8b && code != 0x9b
2921 && (ELF32_R_TYPE (irel->r_info)
2922 != (int) R_MN10300_GOTPC32)
2923 && ((code & 0x0f) == 0x09 || (code & 0x0f) == 0x08
2924 || (code & 0x0f) == 0x0a || (code & 0x0f) == 0x0b
2925 || (code & 0x0f) == 0x0e))
2927 /* Not safe if the high bit is on as relaxing may
2928 move the value out of high mem and thus not fit
2929 in a signed 16bit value. This is currently over
2930 conservative. */
2931 if ((value & 0x8000) == 0)
2933 /* Note that we've changed the relocation contents,
2934 etc. */
2935 elf_section_data (sec)->relocs = internal_relocs;
2936 elf_section_data (sec)->this_hdr.contents = contents;
2937 symtab_hdr->contents = (unsigned char *) isymbuf;
2939 /* Fix the opcode. */
2940 bfd_put_8 (abfd, 0xfd, contents + irel->r_offset - 3);
2941 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
2943 /* Fix the relocation's type. */
2944 irel->r_info =
2945 ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2946 (ELF32_R_TYPE (irel->r_info)
2947 == (int) R_MN10300_GOTOFF32)
2948 ? R_MN10300_GOTOFF24
2949 : (ELF32_R_TYPE (irel->r_info)
2950 == (int) R_MN10300_GOT32)
2951 ? R_MN10300_GOT24 :
2952 R_MN10300_24);
2954 /* Delete one byte of data. */
2955 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
2956 irel->r_offset + 3, 1))
2957 goto error_return;
2959 /* That will change things, so, we should relax
2960 again. Note that this is not required, and it
2961 may be slow. */
2962 *again = TRUE;
2963 break;
2969 /* See if the value will fit in 16 bits.
2970 We allow any 16bit match here. We prune those we can't
2971 handle below. */
2972 if ((long) value < 0x7fff && (long) value > -0x8000)
2974 unsigned char code;
2976 /* Most insns which have 32bit operands are 6 bytes long;
2977 exceptions are pcrel insns and bit insns.
2979 We handle pcrel insns above. We don't bother trying
2980 to handle the bit insns here.
2982 The first byte of the remaining insns will be 0xfc. */
2984 /* Get the first opcode. */
2985 code = bfd_get_8 (abfd, contents + irel->r_offset - 2);
2987 if (code != 0xfc)
2988 continue;
2990 /* Get the second opcode. */
2991 code = bfd_get_8 (abfd, contents + irel->r_offset - 1);
2993 if ((code & 0xf0) < 0x80)
2994 switch (code & 0xf0)
2996 /* mov (d32,am),dn -> mov (d32,am),dn
2997 mov dm,(d32,am) -> mov dn,(d32,am)
2998 mov (d32,am),an -> mov (d32,am),an
2999 mov dm,(d32,am) -> mov dn,(d32,am)
3000 movbu (d32,am),dn -> movbu (d32,am),dn
3001 movbu dm,(d32,am) -> movbu dn,(d32,am)
3002 movhu (d32,am),dn -> movhu (d32,am),dn
3003 movhu dm,(d32,am) -> movhu dn,(d32,am) */
3004 case 0x00:
3005 case 0x10:
3006 case 0x20:
3007 case 0x30:
3008 case 0x40:
3009 case 0x50:
3010 case 0x60:
3011 case 0x70:
3012 /* Not safe if the high bit is on as relaxing may
3013 move the value out of high mem and thus not fit
3014 in a signed 16bit value. */
3015 if (code == 0xcc
3016 && (value & 0x8000))
3017 continue;
3019 /* Note that we've changed the relocation contents, etc. */
3020 elf_section_data (sec)->relocs = internal_relocs;
3021 elf_section_data (sec)->this_hdr.contents = contents;
3022 symtab_hdr->contents = (unsigned char *) isymbuf;
3024 /* Fix the opcode. */
3025 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3026 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3028 /* Fix the relocation's type. */
3029 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3030 (ELF32_R_TYPE (irel->r_info)
3031 == (int) R_MN10300_GOTOFF32)
3032 ? R_MN10300_GOTOFF16
3033 : (ELF32_R_TYPE (irel->r_info)
3034 == (int) R_MN10300_GOT32)
3035 ? R_MN10300_GOT16
3036 : (ELF32_R_TYPE (irel->r_info)
3037 == (int) R_MN10300_GOTPC32)
3038 ? R_MN10300_GOTPC16 :
3039 R_MN10300_16);
3041 /* Delete two bytes of data. */
3042 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3043 irel->r_offset + 2, 2))
3044 goto error_return;
3046 /* That will change things, so, we should relax again.
3047 Note that this is not required, and it may be slow. */
3048 *again = TRUE;
3049 break;
3051 else if ((code & 0xf0) == 0x80
3052 || (code & 0xf0) == 0x90)
3053 switch (code & 0xf3)
3055 /* mov dn,(abs32) -> mov dn,(abs16)
3056 movbu dn,(abs32) -> movbu dn,(abs16)
3057 movhu dn,(abs32) -> movhu dn,(abs16) */
3058 case 0x81:
3059 case 0x82:
3060 case 0x83:
3061 /* Note that we've changed the relocation contents, etc. */
3062 elf_section_data (sec)->relocs = internal_relocs;
3063 elf_section_data (sec)->this_hdr.contents = contents;
3064 symtab_hdr->contents = (unsigned char *) isymbuf;
3066 if ((code & 0xf3) == 0x81)
3067 code = 0x01 + (code & 0x0c);
3068 else if ((code & 0xf3) == 0x82)
3069 code = 0x02 + (code & 0x0c);
3070 else if ((code & 0xf3) == 0x83)
3071 code = 0x03 + (code & 0x0c);
3072 else
3073 abort ();
3075 /* Fix the opcode. */
3076 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3078 /* Fix the relocation's type. */
3079 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3080 (ELF32_R_TYPE (irel->r_info)
3081 == (int) R_MN10300_GOTOFF32)
3082 ? R_MN10300_GOTOFF16
3083 : (ELF32_R_TYPE (irel->r_info)
3084 == (int) R_MN10300_GOT32)
3085 ? R_MN10300_GOT16
3086 : (ELF32_R_TYPE (irel->r_info)
3087 == (int) R_MN10300_GOTPC32)
3088 ? R_MN10300_GOTPC16 :
3089 R_MN10300_16);
3091 /* The opcode got shorter too, so we have to fix the
3092 addend and offset too! */
3093 irel->r_offset -= 1;
3095 /* Delete three bytes of data. */
3096 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3097 irel->r_offset + 1, 3))
3098 goto error_return;
3100 /* That will change things, so, we should relax again.
3101 Note that this is not required, and it may be slow. */
3102 *again = TRUE;
3103 break;
3105 /* mov am,(abs32) -> mov am,(abs16)
3106 mov am,(d32,sp) -> mov am,(d16,sp)
3107 mov dm,(d32,sp) -> mov dm,(d32,sp)
3108 movbu dm,(d32,sp) -> movbu dm,(d32,sp)
3109 movhu dm,(d32,sp) -> movhu dm,(d32,sp) */
3110 case 0x80:
3111 case 0x90:
3112 case 0x91:
3113 case 0x92:
3114 case 0x93:
3115 /* sp-based offsets are zero-extended. */
3116 if (code >= 0x90 && code <= 0x93
3117 && (long)value < 0)
3118 continue;
3120 /* Note that we've changed the relocation contents, etc. */
3121 elf_section_data (sec)->relocs = internal_relocs;
3122 elf_section_data (sec)->this_hdr.contents = contents;
3123 symtab_hdr->contents = (unsigned char *) isymbuf;
3125 /* Fix the opcode. */
3126 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3127 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3129 /* Fix the relocation's type. */
3130 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3131 (ELF32_R_TYPE (irel->r_info)
3132 == (int) R_MN10300_GOTOFF32)
3133 ? R_MN10300_GOTOFF16
3134 : (ELF32_R_TYPE (irel->r_info)
3135 == (int) R_MN10300_GOT32)
3136 ? R_MN10300_GOT16
3137 : (ELF32_R_TYPE (irel->r_info)
3138 == (int) R_MN10300_GOTPC32)
3139 ? R_MN10300_GOTPC16 :
3140 R_MN10300_16);
3142 /* Delete two bytes of data. */
3143 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3144 irel->r_offset + 2, 2))
3145 goto error_return;
3147 /* That will change things, so, we should relax again.
3148 Note that this is not required, and it may be slow. */
3149 *again = TRUE;
3150 break;
3152 else if ((code & 0xf0) < 0xf0)
3153 switch (code & 0xfc)
3155 /* mov imm32,dn -> mov imm16,dn
3156 mov imm32,an -> mov imm16,an
3157 mov (abs32),dn -> mov (abs16),dn
3158 movbu (abs32),dn -> movbu (abs16),dn
3159 movhu (abs32),dn -> movhu (abs16),dn */
3160 case 0xcc:
3161 case 0xdc:
3162 case 0xa4:
3163 case 0xa8:
3164 case 0xac:
3165 /* Not safe if the high bit is on as relaxing may
3166 move the value out of high mem and thus not fit
3167 in a signed 16bit value. */
3168 if (code == 0xcc
3169 && (value & 0x8000))
3170 continue;
3172 /* mov imm16, an zero-extends the immediate. */
3173 if (code == 0xdc
3174 && (long)value < 0)
3175 continue;
3177 /* Note that we've changed the relocation contents, etc. */
3178 elf_section_data (sec)->relocs = internal_relocs;
3179 elf_section_data (sec)->this_hdr.contents = contents;
3180 symtab_hdr->contents = (unsigned char *) isymbuf;
3182 if ((code & 0xfc) == 0xcc)
3183 code = 0x2c + (code & 0x03);
3184 else if ((code & 0xfc) == 0xdc)
3185 code = 0x24 + (code & 0x03);
3186 else if ((code & 0xfc) == 0xa4)
3187 code = 0x30 + (code & 0x03);
3188 else if ((code & 0xfc) == 0xa8)
3189 code = 0x34 + (code & 0x03);
3190 else if ((code & 0xfc) == 0xac)
3191 code = 0x38 + (code & 0x03);
3192 else
3193 abort ();
3195 /* Fix the opcode. */
3196 bfd_put_8 (abfd, code, contents + irel->r_offset - 2);
3198 /* Fix the relocation's type. */
3199 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3200 (ELF32_R_TYPE (irel->r_info)
3201 == (int) R_MN10300_GOTOFF32)
3202 ? R_MN10300_GOTOFF16
3203 : (ELF32_R_TYPE (irel->r_info)
3204 == (int) R_MN10300_GOT32)
3205 ? R_MN10300_GOT16
3206 : (ELF32_R_TYPE (irel->r_info)
3207 == (int) R_MN10300_GOTPC32)
3208 ? R_MN10300_GOTPC16 :
3209 R_MN10300_16);
3211 /* The opcode got shorter too, so we have to fix the
3212 addend and offset too! */
3213 irel->r_offset -= 1;
3215 /* Delete three bytes of data. */
3216 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3217 irel->r_offset + 1, 3))
3218 goto error_return;
3220 /* That will change things, so, we should relax again.
3221 Note that this is not required, and it may be slow. */
3222 *again = TRUE;
3223 break;
3225 /* mov (abs32),an -> mov (abs16),an
3226 mov (d32,sp),an -> mov (d16,sp),an
3227 mov (d32,sp),dn -> mov (d16,sp),dn
3228 movbu (d32,sp),dn -> movbu (d16,sp),dn
3229 movhu (d32,sp),dn -> movhu (d16,sp),dn
3230 add imm32,dn -> add imm16,dn
3231 cmp imm32,dn -> cmp imm16,dn
3232 add imm32,an -> add imm16,an
3233 cmp imm32,an -> cmp imm16,an
3234 and imm32,dn -> and imm16,dn
3235 or imm32,dn -> or imm16,dn
3236 xor imm32,dn -> xor imm16,dn
3237 btst imm32,dn -> btst imm16,dn */
3239 case 0xa0:
3240 case 0xb0:
3241 case 0xb1:
3242 case 0xb2:
3243 case 0xb3:
3244 case 0xc0:
3245 case 0xc8:
3247 case 0xd0:
3248 case 0xd8:
3249 case 0xe0:
3250 case 0xe1:
3251 case 0xe2:
3252 case 0xe3:
3253 /* cmp imm16, an zero-extends the immediate. */
3254 if (code == 0xdc
3255 && (long)value < 0)
3256 continue;
3258 /* So do sp-based offsets. */
3259 if (code >= 0xb0 && code <= 0xb3
3260 && (long)value < 0)
3261 continue;
3263 /* Note that we've changed the relocation contents, etc. */
3264 elf_section_data (sec)->relocs = internal_relocs;
3265 elf_section_data (sec)->this_hdr.contents = contents;
3266 symtab_hdr->contents = (unsigned char *) isymbuf;
3268 /* Fix the opcode. */
3269 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3270 bfd_put_8 (abfd, code, contents + irel->r_offset - 1);
3272 /* Fix the relocation's type. */
3273 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3274 (ELF32_R_TYPE (irel->r_info)
3275 == (int) R_MN10300_GOTOFF32)
3276 ? R_MN10300_GOTOFF16
3277 : (ELF32_R_TYPE (irel->r_info)
3278 == (int) R_MN10300_GOT32)
3279 ? R_MN10300_GOT16
3280 : (ELF32_R_TYPE (irel->r_info)
3281 == (int) R_MN10300_GOTPC32)
3282 ? R_MN10300_GOTPC16 :
3283 R_MN10300_16);
3285 /* Delete two bytes of data. */
3286 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3287 irel->r_offset + 2, 2))
3288 goto error_return;
3290 /* That will change things, so, we should relax again.
3291 Note that this is not required, and it may be slow. */
3292 *again = TRUE;
3293 break;
3295 else if (code == 0xfe)
3297 /* add imm32,sp -> add imm16,sp */
3299 /* Note that we've changed the relocation contents, etc. */
3300 elf_section_data (sec)->relocs = internal_relocs;
3301 elf_section_data (sec)->this_hdr.contents = contents;
3302 symtab_hdr->contents = (unsigned char *) isymbuf;
3304 /* Fix the opcode. */
3305 bfd_put_8 (abfd, 0xfa, contents + irel->r_offset - 2);
3306 bfd_put_8 (abfd, 0xfe, contents + irel->r_offset - 1);
3308 /* Fix the relocation's type. */
3309 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
3310 (ELF32_R_TYPE (irel->r_info)
3311 == (int) R_MN10300_GOT32)
3312 ? R_MN10300_GOT16
3313 : (ELF32_R_TYPE (irel->r_info)
3314 == (int) R_MN10300_GOTOFF32)
3315 ? R_MN10300_GOTOFF16
3316 : (ELF32_R_TYPE (irel->r_info)
3317 == (int) R_MN10300_GOTPC32)
3318 ? R_MN10300_GOTPC16 :
3319 R_MN10300_16);
3321 /* Delete two bytes of data. */
3322 if (!mn10300_elf_relax_delete_bytes (abfd, sec,
3323 irel->r_offset + 2, 2))
3324 goto error_return;
3326 /* That will change things, so, we should relax again.
3327 Note that this is not required, and it may be slow. */
3328 *again = TRUE;
3329 break;
3335 if (isymbuf != NULL
3336 && symtab_hdr->contents != (unsigned char *) isymbuf)
3338 if (! link_info->keep_memory)
3339 free (isymbuf);
3340 else
3342 /* Cache the symbols for elf_link_input_bfd. */
3343 symtab_hdr->contents = (unsigned char *) isymbuf;
3347 if (contents != NULL
3348 && elf_section_data (sec)->this_hdr.contents != contents)
3350 if (! link_info->keep_memory)
3351 free (contents);
3352 else
3354 /* Cache the section contents for elf_link_input_bfd. */
3355 elf_section_data (sec)->this_hdr.contents = contents;
3359 if (internal_relocs != NULL
3360 && elf_section_data (sec)->relocs != internal_relocs)
3361 free (internal_relocs);
3363 return TRUE;
3365 error_return:
3366 if (isymbuf != NULL
3367 && symtab_hdr->contents != (unsigned char *) isymbuf)
3368 free (isymbuf);
3369 if (contents != NULL
3370 && elf_section_data (section)->this_hdr.contents != contents)
3371 free (contents);
3372 if (internal_relocs != NULL
3373 && elf_section_data (section)->relocs != internal_relocs)
3374 free (internal_relocs);
3376 return FALSE;
3379 /* Compute the stack size and movm arguments for the function
3380 referred to by HASH at address ADDR in section with
3381 contents CONTENTS, store the information in the hash table. */
3382 static void
3383 compute_function_info (abfd, hash, addr, contents)
3384 bfd *abfd;
3385 struct elf32_mn10300_link_hash_entry *hash;
3386 bfd_vma addr;
3387 unsigned char *contents;
3389 unsigned char byte1, byte2;
3390 /* We only care about a very small subset of the possible prologue
3391 sequences here. Basically we look for:
3393 movm [d2,d3,a2,a3],sp (optional)
3394 add <size>,sp (optional, and only for sizes which fit in an unsigned
3395 8 bit number)
3397 If we find anything else, we quit. */
3399 /* Look for movm [regs],sp */
3400 byte1 = bfd_get_8 (abfd, contents + addr);
3401 byte2 = bfd_get_8 (abfd, contents + addr + 1);
3403 if (byte1 == 0xcf)
3405 hash->movm_args = byte2;
3406 addr += 2;
3407 byte1 = bfd_get_8 (abfd, contents + addr);
3408 byte2 = bfd_get_8 (abfd, contents + addr + 1);
3411 /* Now figure out how much stack space will be allocated by the movm
3412 instruction. We need this kept separate from the function's normal
3413 stack space. */
3414 if (hash->movm_args)
3416 /* Space for d2. */
3417 if (hash->movm_args & 0x80)
3418 hash->movm_stack_size += 4;
3420 /* Space for d3. */
3421 if (hash->movm_args & 0x40)
3422 hash->movm_stack_size += 4;
3424 /* Space for a2. */
3425 if (hash->movm_args & 0x20)
3426 hash->movm_stack_size += 4;
3428 /* Space for a3. */
3429 if (hash->movm_args & 0x10)
3430 hash->movm_stack_size += 4;
3432 /* "other" space. d0, d1, a0, a1, mdr, lir, lar, 4 byte pad. */
3433 if (hash->movm_args & 0x08)
3434 hash->movm_stack_size += 8 * 4;
3436 if (bfd_get_mach (abfd) == bfd_mach_am33
3437 || bfd_get_mach (abfd) == bfd_mach_am33_2)
3439 /* "exother" space. e0, e1, mdrq, mcrh, mcrl, mcvf */
3440 if (hash->movm_args & 0x1)
3441 hash->movm_stack_size += 6 * 4;
3443 /* exreg1 space. e4, e5, e6, e7 */
3444 if (hash->movm_args & 0x2)
3445 hash->movm_stack_size += 4 * 4;
3447 /* exreg0 space. e2, e3 */
3448 if (hash->movm_args & 0x4)
3449 hash->movm_stack_size += 2 * 4;
3453 /* Now look for the two stack adjustment variants. */
3454 if (byte1 == 0xf8 && byte2 == 0xfe)
3456 int temp = bfd_get_8 (abfd, contents + addr + 2);
3457 temp = ((temp & 0xff) ^ (~0x7f)) + 0x80;
3459 hash->stack_size = -temp;
3461 else if (byte1 == 0xfa && byte2 == 0xfe)
3463 int temp = bfd_get_16 (abfd, contents + addr + 2);
3464 temp = ((temp & 0xffff) ^ (~0x7fff)) + 0x8000;
3465 temp = -temp;
3467 if (temp < 255)
3468 hash->stack_size = temp;
3471 /* If the total stack to be allocated by the call instruction is more
3472 than 255 bytes, then we can't remove the stack adjustment by using
3473 "call" (we might still be able to remove the "movm" instruction. */
3474 if (hash->stack_size + hash->movm_stack_size > 255)
3475 hash->stack_size = 0;
3477 return;
3480 /* Delete some bytes from a section while relaxing. */
3482 static bfd_boolean
3483 mn10300_elf_relax_delete_bytes (abfd, sec, addr, count)
3484 bfd *abfd;
3485 asection *sec;
3486 bfd_vma addr;
3487 int count;
3489 Elf_Internal_Shdr *symtab_hdr;
3490 unsigned int sec_shndx;
3491 bfd_byte *contents;
3492 Elf_Internal_Rela *irel, *irelend;
3493 Elf_Internal_Rela *irelalign;
3494 bfd_vma toaddr;
3495 Elf_Internal_Sym *isym, *isymend;
3496 struct elf_link_hash_entry **sym_hashes;
3497 struct elf_link_hash_entry **end_hashes;
3498 unsigned int symcount;
3500 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
3502 contents = elf_section_data (sec)->this_hdr.contents;
3504 /* The deletion must stop at the next ALIGN reloc for an aligment
3505 power larger than the number of bytes we are deleting. */
3507 irelalign = NULL;
3508 toaddr = sec->size;
3510 irel = elf_section_data (sec)->relocs;
3511 irelend = irel + sec->reloc_count;
3513 /* Actually delete the bytes. */
3514 memmove (contents + addr, contents + addr + count,
3515 (size_t) (toaddr - addr - count));
3516 sec->size -= count;
3518 /* Adjust all the relocs. */
3519 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
3521 /* Get the new reloc address. */
3522 if ((irel->r_offset > addr
3523 && irel->r_offset < toaddr))
3524 irel->r_offset -= count;
3527 /* Adjust the local symbols defined in this section. */
3528 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3529 isym = (Elf_Internal_Sym *) symtab_hdr->contents;
3530 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
3532 if (isym->st_shndx == sec_shndx
3533 && isym->st_value > addr
3534 && isym->st_value < toaddr)
3535 isym->st_value -= count;
3538 /* Now adjust the global symbols defined in this section. */
3539 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3540 - symtab_hdr->sh_info);
3541 sym_hashes = elf_sym_hashes (abfd);
3542 end_hashes = sym_hashes + symcount;
3543 for (; sym_hashes < end_hashes; sym_hashes++)
3545 struct elf_link_hash_entry *sym_hash = *sym_hashes;
3546 if ((sym_hash->root.type == bfd_link_hash_defined
3547 || sym_hash->root.type == bfd_link_hash_defweak)
3548 && sym_hash->root.u.def.section == sec
3549 && sym_hash->root.u.def.value > addr
3550 && sym_hash->root.u.def.value < toaddr)
3552 sym_hash->root.u.def.value -= count;
3556 return TRUE;
3559 /* Return TRUE if a symbol exists at the given address, else return
3560 FALSE. */
3561 static bfd_boolean
3562 mn10300_elf_symbol_address_p (abfd, sec, isym, addr)
3563 bfd *abfd;
3564 asection *sec;
3565 Elf_Internal_Sym *isym;
3566 bfd_vma addr;
3568 Elf_Internal_Shdr *symtab_hdr;
3569 unsigned int sec_shndx;
3570 Elf_Internal_Sym *isymend;
3571 struct elf_link_hash_entry **sym_hashes;
3572 struct elf_link_hash_entry **end_hashes;
3573 unsigned int symcount;
3575 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
3577 /* Examine all the symbols. */
3578 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3579 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
3581 if (isym->st_shndx == sec_shndx
3582 && isym->st_value == addr)
3583 return TRUE;
3586 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
3587 - symtab_hdr->sh_info);
3588 sym_hashes = elf_sym_hashes (abfd);
3589 end_hashes = sym_hashes + symcount;
3590 for (; sym_hashes < end_hashes; sym_hashes++)
3592 struct elf_link_hash_entry *sym_hash = *sym_hashes;
3593 if ((sym_hash->root.type == bfd_link_hash_defined
3594 || sym_hash->root.type == bfd_link_hash_defweak)
3595 && sym_hash->root.u.def.section == sec
3596 && sym_hash->root.u.def.value == addr)
3597 return TRUE;
3600 return FALSE;
3603 /* This is a version of bfd_generic_get_relocated_section_contents
3604 which uses mn10300_elf_relocate_section. */
3606 static bfd_byte *
3607 mn10300_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
3608 data, relocatable, symbols)
3609 bfd *output_bfd;
3610 struct bfd_link_info *link_info;
3611 struct bfd_link_order *link_order;
3612 bfd_byte *data;
3613 bfd_boolean relocatable;
3614 asymbol **symbols;
3616 Elf_Internal_Shdr *symtab_hdr;
3617 asection *input_section = link_order->u.indirect.section;
3618 bfd *input_bfd = input_section->owner;
3619 asection **sections = NULL;
3620 Elf_Internal_Rela *internal_relocs = NULL;
3621 Elf_Internal_Sym *isymbuf = NULL;
3623 /* We only need to handle the case of relaxing, or of having a
3624 particular set of section contents, specially. */
3625 if (relocatable
3626 || elf_section_data (input_section)->this_hdr.contents == NULL)
3627 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
3628 link_order, data,
3629 relocatable,
3630 symbols);
3632 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3634 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
3635 (size_t) input_section->size);
3637 if ((input_section->flags & SEC_RELOC) != 0
3638 && input_section->reloc_count > 0)
3640 asection **secpp;
3641 Elf_Internal_Sym *isym, *isymend;
3642 bfd_size_type amt;
3644 internal_relocs = (_bfd_elf_link_read_relocs
3645 (input_bfd, input_section, (PTR) NULL,
3646 (Elf_Internal_Rela *) NULL, FALSE));
3647 if (internal_relocs == NULL)
3648 goto error_return;
3650 if (symtab_hdr->sh_info != 0)
3652 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
3653 if (isymbuf == NULL)
3654 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3655 symtab_hdr->sh_info, 0,
3656 NULL, NULL, NULL);
3657 if (isymbuf == NULL)
3658 goto error_return;
3661 amt = symtab_hdr->sh_info;
3662 amt *= sizeof (asection *);
3663 sections = (asection **) bfd_malloc (amt);
3664 if (sections == NULL && amt != 0)
3665 goto error_return;
3667 isymend = isymbuf + symtab_hdr->sh_info;
3668 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
3670 asection *isec;
3672 if (isym->st_shndx == SHN_UNDEF)
3673 isec = bfd_und_section_ptr;
3674 else if (isym->st_shndx == SHN_ABS)
3675 isec = bfd_abs_section_ptr;
3676 else if (isym->st_shndx == SHN_COMMON)
3677 isec = bfd_com_section_ptr;
3678 else
3679 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
3681 *secpp = isec;
3684 if (! mn10300_elf_relocate_section (output_bfd, link_info, input_bfd,
3685 input_section, data, internal_relocs,
3686 isymbuf, sections))
3687 goto error_return;
3689 if (sections != NULL)
3690 free (sections);
3691 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3692 free (isymbuf);
3693 if (internal_relocs != elf_section_data (input_section)->relocs)
3694 free (internal_relocs);
3697 return data;
3699 error_return:
3700 if (sections != NULL)
3701 free (sections);
3702 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
3703 free (isymbuf);
3704 if (internal_relocs != NULL
3705 && internal_relocs != elf_section_data (input_section)->relocs)
3706 free (internal_relocs);
3707 return NULL;
3710 /* Assorted hash table functions. */
3712 /* Initialize an entry in the link hash table. */
3714 /* Create an entry in an MN10300 ELF linker hash table. */
3716 static struct bfd_hash_entry *
3717 elf32_mn10300_link_hash_newfunc (entry, table, string)
3718 struct bfd_hash_entry *entry;
3719 struct bfd_hash_table *table;
3720 const char *string;
3722 struct elf32_mn10300_link_hash_entry *ret =
3723 (struct elf32_mn10300_link_hash_entry *) entry;
3725 /* Allocate the structure if it has not already been allocated by a
3726 subclass. */
3727 if (ret == (struct elf32_mn10300_link_hash_entry *) NULL)
3728 ret = ((struct elf32_mn10300_link_hash_entry *)
3729 bfd_hash_allocate (table,
3730 sizeof (struct elf32_mn10300_link_hash_entry)));
3731 if (ret == (struct elf32_mn10300_link_hash_entry *) NULL)
3732 return (struct bfd_hash_entry *) ret;
3734 /* Call the allocation method of the superclass. */
3735 ret = ((struct elf32_mn10300_link_hash_entry *)
3736 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3737 table, string));
3738 if (ret != (struct elf32_mn10300_link_hash_entry *) NULL)
3740 ret->direct_calls = 0;
3741 ret->stack_size = 0;
3742 ret->movm_args = 0;
3743 ret->movm_stack_size = 0;
3744 ret->flags = 0;
3745 ret->value = 0;
3748 return (struct bfd_hash_entry *) ret;
3751 /* Create an mn10300 ELF linker hash table. */
3753 static struct bfd_link_hash_table *
3754 elf32_mn10300_link_hash_table_create (abfd)
3755 bfd *abfd;
3757 struct elf32_mn10300_link_hash_table *ret;
3758 bfd_size_type amt = sizeof (struct elf32_mn10300_link_hash_table);
3760 ret = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
3761 if (ret == (struct elf32_mn10300_link_hash_table *) NULL)
3762 return NULL;
3764 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
3765 elf32_mn10300_link_hash_newfunc,
3766 sizeof (struct elf32_mn10300_link_hash_entry)))
3768 free (ret);
3769 return NULL;
3772 ret->flags = 0;
3773 amt = sizeof (struct elf_link_hash_table);
3774 ret->static_hash_table
3775 = (struct elf32_mn10300_link_hash_table *) bfd_malloc (amt);
3776 if (ret->static_hash_table == NULL)
3778 free (ret);
3779 return NULL;
3782 if (!_bfd_elf_link_hash_table_init (&ret->static_hash_table->root, abfd,
3783 elf32_mn10300_link_hash_newfunc,
3784 sizeof (struct elf32_mn10300_link_hash_entry)))
3786 free (ret->static_hash_table);
3787 free (ret);
3788 return NULL;
3790 return &ret->root.root;
3793 /* Free an mn10300 ELF linker hash table. */
3795 static void
3796 elf32_mn10300_link_hash_table_free (hash)
3797 struct bfd_link_hash_table *hash;
3799 struct elf32_mn10300_link_hash_table *ret
3800 = (struct elf32_mn10300_link_hash_table *) hash;
3802 _bfd_generic_link_hash_table_free
3803 ((struct bfd_link_hash_table *) ret->static_hash_table);
3804 _bfd_generic_link_hash_table_free
3805 ((struct bfd_link_hash_table *) ret);
3808 static unsigned long
3809 elf_mn10300_mach (flags)
3810 flagword flags;
3812 switch (flags & EF_MN10300_MACH)
3814 case E_MN10300_MACH_MN10300:
3815 default:
3816 return bfd_mach_mn10300;
3818 case E_MN10300_MACH_AM33:
3819 return bfd_mach_am33;
3821 case E_MN10300_MACH_AM33_2:
3822 return bfd_mach_am33_2;
3826 /* The final processing done just before writing out a MN10300 ELF object
3827 file. This gets the MN10300 architecture right based on the machine
3828 number. */
3830 void
3831 _bfd_mn10300_elf_final_write_processing (abfd, linker)
3832 bfd *abfd;
3833 bfd_boolean linker ATTRIBUTE_UNUSED;
3835 unsigned long val;
3837 switch (bfd_get_mach (abfd))
3839 default:
3840 case bfd_mach_mn10300:
3841 val = E_MN10300_MACH_MN10300;
3842 break;
3844 case bfd_mach_am33:
3845 val = E_MN10300_MACH_AM33;
3846 break;
3848 case bfd_mach_am33_2:
3849 val = E_MN10300_MACH_AM33_2;
3850 break;
3853 elf_elfheader (abfd)->e_flags &= ~ (EF_MN10300_MACH);
3854 elf_elfheader (abfd)->e_flags |= val;
3857 bfd_boolean
3858 _bfd_mn10300_elf_object_p (abfd)
3859 bfd *abfd;
3861 bfd_default_set_arch_mach (abfd, bfd_arch_mn10300,
3862 elf_mn10300_mach (elf_elfheader (abfd)->e_flags));
3863 return TRUE;
3866 /* Merge backend specific data from an object file to the output
3867 object file when linking. */
3869 bfd_boolean
3870 _bfd_mn10300_elf_merge_private_bfd_data (ibfd, obfd)
3871 bfd *ibfd;
3872 bfd *obfd;
3874 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3875 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3876 return TRUE;
3878 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3879 && bfd_get_mach (obfd) < bfd_get_mach (ibfd))
3881 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
3882 bfd_get_mach (ibfd)))
3883 return FALSE;
3886 return TRUE;
3889 #define PLT0_ENTRY_SIZE 15
3890 #define PLT_ENTRY_SIZE 20
3891 #define PIC_PLT_ENTRY_SIZE 24
3893 static const bfd_byte elf_mn10300_plt0_entry[PLT0_ENTRY_SIZE] =
3895 0xfc, 0xa0, 0, 0, 0, 0, /* mov (.got+8),a0 */
3896 0xfe, 0xe, 0x10, 0, 0, 0, 0, /* mov (.got+4),r1 */
3897 0xf0, 0xf4, /* jmp (a0) */
3900 static const bfd_byte elf_mn10300_plt_entry[PLT_ENTRY_SIZE] =
3902 0xfc, 0xa0, 0, 0, 0, 0, /* mov (nameN@GOT + .got),a0 */
3903 0xf0, 0xf4, /* jmp (a0) */
3904 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3905 0xdc, 0, 0, 0, 0, /* jmp .plt0 */
3908 static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] =
3910 0xfc, 0x22, 0, 0, 0, 0, /* mov (nameN@GOT,a2),a0 */
3911 0xf0, 0xf4, /* jmp (a0) */
3912 0xfe, 8, 0, 0, 0, 0, 0, /* mov reloc-table-address,r0 */
3913 0xf8, 0x22, 8, /* mov (8,a2),a0 */
3914 0xfb, 0xa, 0x1a, 4, /* mov (4,a2),r1 */
3915 0xf0, 0xf4, /* jmp (a0) */
3918 /* Return size of the first PLT entry. */
3919 #define elf_mn10300_sizeof_plt0(info) \
3920 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE)
3922 /* Return size of a PLT entry. */
3923 #define elf_mn10300_sizeof_plt(info) \
3924 (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE)
3926 /* Return offset of the PLT0 address in an absolute PLT entry. */
3927 #define elf_mn10300_plt_plt0_offset(info) 16
3929 /* Return offset of the linker in PLT0 entry. */
3930 #define elf_mn10300_plt0_linker_offset(info) 2
3932 /* Return offset of the GOT id in PLT0 entry. */
3933 #define elf_mn10300_plt0_gotid_offset(info) 9
3935 /* Return offset of the temporary in PLT entry */
3936 #define elf_mn10300_plt_temp_offset(info) 8
3938 /* Return offset of the symbol in PLT entry. */
3939 #define elf_mn10300_plt_symbol_offset(info) 2
3941 /* Return offset of the relocation in PLT entry. */
3942 #define elf_mn10300_plt_reloc_offset(info) 11
3944 /* The name of the dynamic interpreter. This is put in the .interp
3945 section. */
3947 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
3949 /* Create dynamic sections when linking against a dynamic object. */
3951 static bfd_boolean
3952 _bfd_mn10300_elf_create_dynamic_sections (abfd, info)
3953 bfd *abfd;
3954 struct bfd_link_info *info;
3956 flagword flags;
3957 asection * s;
3958 const struct elf_backend_data * bed = get_elf_backend_data (abfd);
3959 int ptralign = 0;
3961 switch (bed->s->arch_size)
3963 case 32:
3964 ptralign = 2;
3965 break;
3967 case 64:
3968 ptralign = 3;
3969 break;
3971 default:
3972 bfd_set_error (bfd_error_bad_value);
3973 return FALSE;
3976 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3977 .rel[a].bss sections. */
3979 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3980 | SEC_LINKER_CREATED);
3982 s = bfd_make_section_with_flags (abfd,
3983 (bed->default_use_rela_p
3984 ? ".rela.plt" : ".rel.plt"),
3985 flags | SEC_READONLY);
3986 if (s == NULL
3987 || ! bfd_set_section_alignment (abfd, s, ptralign))
3988 return FALSE;
3990 if (! _bfd_mn10300_elf_create_got_section (abfd, info))
3991 return FALSE;
3994 const char * secname;
3995 char * relname;
3996 flagword secflags;
3997 asection * sec;
3999 for (sec = abfd->sections; sec; sec = sec->next)
4001 secflags = bfd_get_section_flags (abfd, sec);
4002 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
4003 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
4004 continue;
4006 secname = bfd_get_section_name (abfd, sec);
4007 relname = (char *) bfd_malloc (strlen (secname) + 6);
4008 strcpy (relname, ".rela");
4009 strcat (relname, secname);
4011 s = bfd_make_section_with_flags (abfd, relname,
4012 flags | SEC_READONLY);
4013 if (s == NULL
4014 || ! bfd_set_section_alignment (abfd, s, ptralign))
4015 return FALSE;
4019 if (bed->want_dynbss)
4021 /* The .dynbss section is a place to put symbols which are defined
4022 by dynamic objects, are referenced by regular objects, and are
4023 not functions. We must allocate space for them in the process
4024 image and use a R_*_COPY reloc to tell the dynamic linker to
4025 initialize them at run time. The linker script puts the .dynbss
4026 section into the .bss section of the final image. */
4027 s = bfd_make_section_with_flags (abfd, ".dynbss",
4028 SEC_ALLOC | SEC_LINKER_CREATED);
4029 if (s == NULL)
4030 return FALSE;
4032 /* The .rel[a].bss section holds copy relocs. This section is not
4033 normally needed. We need to create it here, though, so that the
4034 linker will map it to an output section. We can't just create it
4035 only if we need it, because we will not know whether we need it
4036 until we have seen all the input files, and the first time the
4037 main linker code calls BFD after examining all the input files
4038 (size_dynamic_sections) the input sections have already been
4039 mapped to the output sections. If the section turns out not to
4040 be needed, we can discard it later. We will never need this
4041 section when generating a shared object, since they do not use
4042 copy relocs. */
4043 if (! info->shared)
4045 s = bfd_make_section_with_flags (abfd,
4046 (bed->default_use_rela_p
4047 ? ".rela.bss" : ".rel.bss"),
4048 flags | SEC_READONLY);
4049 if (s == NULL
4050 || ! bfd_set_section_alignment (abfd, s, ptralign))
4051 return FALSE;
4055 return TRUE;
4058 /* Adjust a symbol defined by a dynamic object and referenced by a
4059 regular object. The current definition is in some section of the
4060 dynamic object, but we're not including those sections. We have to
4061 change the definition to something the rest of the link can
4062 understand. */
4064 static bfd_boolean
4065 _bfd_mn10300_elf_adjust_dynamic_symbol (info, h)
4066 struct bfd_link_info * info;
4067 struct elf_link_hash_entry * h;
4069 bfd * dynobj;
4070 asection * s;
4071 unsigned int power_of_two;
4073 dynobj = elf_hash_table (info)->dynobj;
4075 /* Make sure we know what is going on here. */
4076 BFD_ASSERT (dynobj != NULL
4077 && (h->needs_plt
4078 || h->u.weakdef != NULL
4079 || (h->def_dynamic
4080 && h->ref_regular
4081 && !h->def_regular)));
4083 /* If this is a function, put it in the procedure linkage table. We
4084 will fill in the contents of the procedure linkage table later,
4085 when we know the address of the .got section. */
4086 if (h->type == STT_FUNC
4087 || h->needs_plt)
4089 if (! info->shared
4090 && !h->def_dynamic
4091 && !h->ref_dynamic)
4093 /* This case can occur if we saw a PLT reloc in an input
4094 file, but the symbol was never referred to by a dynamic
4095 object. In such a case, we don't actually need to build
4096 a procedure linkage table, and we can just do a REL32
4097 reloc instead. */
4098 BFD_ASSERT (h->needs_plt);
4099 return TRUE;
4102 /* Make sure this symbol is output as a dynamic symbol. */
4103 if (h->dynindx == -1)
4105 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4106 return FALSE;
4109 s = bfd_get_section_by_name (dynobj, ".plt");
4110 BFD_ASSERT (s != NULL);
4112 /* If this is the first .plt entry, make room for the special
4113 first entry. */
4114 if (s->size == 0)
4115 s->size += elf_mn10300_sizeof_plt0 (info);
4117 /* If this symbol is not defined in a regular file, and we are
4118 not generating a shared library, then set the symbol to this
4119 location in the .plt. This is required to make function
4120 pointers compare as equal between the normal executable and
4121 the shared library. */
4122 if (! info->shared
4123 && !h->def_regular)
4125 h->root.u.def.section = s;
4126 h->root.u.def.value = s->size;
4129 h->plt.offset = s->size;
4131 /* Make room for this entry. */
4132 s->size += elf_mn10300_sizeof_plt (info);
4134 /* We also need to make an entry in the .got.plt section, which
4135 will be placed in the .got section by the linker script. */
4137 s = bfd_get_section_by_name (dynobj, ".got.plt");
4138 BFD_ASSERT (s != NULL);
4139 s->size += 4;
4141 /* We also need to make an entry in the .rela.plt section. */
4143 s = bfd_get_section_by_name (dynobj, ".rela.plt");
4144 BFD_ASSERT (s != NULL);
4145 s->size += sizeof (Elf32_External_Rela);
4147 return TRUE;
4150 /* If this is a weak symbol, and there is a real definition, the
4151 processor independent code will have arranged for us to see the
4152 real definition first, and we can just use the same value. */
4153 if (h->u.weakdef != NULL)
4155 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4156 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4157 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4158 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4159 return TRUE;
4162 /* This is a reference to a symbol defined by a dynamic object which
4163 is not a function. */
4165 /* If we are creating a shared library, we must presume that the
4166 only references to the symbol are via the global offset table.
4167 For such cases we need not do anything here; the relocations will
4168 be handled correctly by relocate_section. */
4169 if (info->shared)
4170 return TRUE;
4172 /* If there are no references to this symbol that do not use the
4173 GOT, we don't need to generate a copy reloc. */
4174 if (!h->non_got_ref)
4175 return TRUE;
4177 if (h->size == 0)
4179 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
4180 h->root.root.string);
4181 return TRUE;
4184 /* We must allocate the symbol in our .dynbss section, which will
4185 become part of the .bss section of the executable. There will be
4186 an entry for this symbol in the .dynsym section. The dynamic
4187 object will contain position independent code, so all references
4188 from the dynamic object to this symbol will go through the global
4189 offset table. The dynamic linker will use the .dynsym entry to
4190 determine the address it must put in the global offset table, so
4191 both the dynamic object and the regular object will refer to the
4192 same memory location for the variable. */
4194 s = bfd_get_section_by_name (dynobj, ".dynbss");
4195 BFD_ASSERT (s != NULL);
4197 /* We must generate a R_MN10300_COPY reloc to tell the dynamic linker to
4198 copy the initial value out of the dynamic object and into the
4199 runtime process image. We need to remember the offset into the
4200 .rela.bss section we are going to use. */
4201 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4203 asection * srel;
4205 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
4206 BFD_ASSERT (srel != NULL);
4207 srel->size += sizeof (Elf32_External_Rela);
4208 h->needs_copy = 1;
4211 /* We need to figure out the alignment required for this symbol. I
4212 have no idea how ELF linkers handle this. */
4213 power_of_two = bfd_log2 (h->size);
4214 if (power_of_two > 3)
4215 power_of_two = 3;
4217 /* Apply the required alignment. */
4218 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4219 if (power_of_two > bfd_get_section_alignment (dynobj, s))
4221 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
4222 return FALSE;
4225 /* Define the symbol as being at this point in the section. */
4226 h->root.u.def.section = s;
4227 h->root.u.def.value = s->size;
4229 /* Increment the section size to make room for the symbol. */
4230 s->size += h->size;
4232 return TRUE;
4235 /* Set the sizes of the dynamic sections. */
4237 static bfd_boolean
4238 _bfd_mn10300_elf_size_dynamic_sections (output_bfd, info)
4239 bfd * output_bfd;
4240 struct bfd_link_info * info;
4242 bfd * dynobj;
4243 asection * s;
4244 bfd_boolean plt;
4245 bfd_boolean relocs;
4246 bfd_boolean reltext;
4248 dynobj = elf_hash_table (info)->dynobj;
4249 BFD_ASSERT (dynobj != NULL);
4251 if (elf_hash_table (info)->dynamic_sections_created)
4253 /* Set the contents of the .interp section to the interpreter. */
4254 if (info->executable)
4256 s = bfd_get_section_by_name (dynobj, ".interp");
4257 BFD_ASSERT (s != NULL);
4258 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4259 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4262 else
4264 /* We may have created entries in the .rela.got section.
4265 However, if we are not creating the dynamic sections, we will
4266 not actually use these entries. Reset the size of .rela.got,
4267 which will cause it to get stripped from the output file
4268 below. */
4269 s = bfd_get_section_by_name (dynobj, ".rela.got");
4270 if (s != NULL)
4271 s->size = 0;
4274 /* The check_relocs and adjust_dynamic_symbol entry points have
4275 determined the sizes of the various dynamic sections. Allocate
4276 memory for them. */
4277 plt = FALSE;
4278 relocs = FALSE;
4279 reltext = FALSE;
4280 for (s = dynobj->sections; s != NULL; s = s->next)
4282 const char * name;
4284 if ((s->flags & SEC_LINKER_CREATED) == 0)
4285 continue;
4287 /* It's OK to base decisions on the section name, because none
4288 of the dynobj section names depend upon the input files. */
4289 name = bfd_get_section_name (dynobj, s);
4291 if (strcmp (name, ".plt") == 0)
4293 /* Remember whether there is a PLT. */
4294 plt = s->size != 0;
4296 else if (CONST_STRNEQ (name, ".rela"))
4298 if (s->size != 0)
4300 asection * target;
4302 /* Remember whether there are any reloc sections other
4303 than .rela.plt. */
4304 if (strcmp (name, ".rela.plt") != 0)
4306 const char * outname;
4308 relocs = TRUE;
4310 /* If this relocation section applies to a read only
4311 section, then we probably need a DT_TEXTREL
4312 entry. The entries in the .rela.plt section
4313 really apply to the .got section, which we
4314 created ourselves and so know is not readonly. */
4315 outname = bfd_get_section_name (output_bfd,
4316 s->output_section);
4317 target = bfd_get_section_by_name (output_bfd, outname + 5);
4318 if (target != NULL
4319 && (target->flags & SEC_READONLY) != 0
4320 && (target->flags & SEC_ALLOC) != 0)
4321 reltext = TRUE;
4324 /* We use the reloc_count field as a counter if we need
4325 to copy relocs into the output file. */
4326 s->reloc_count = 0;
4329 else if (! CONST_STRNEQ (name, ".got")
4330 && strcmp (name, ".dynbss") != 0)
4331 /* It's not one of our sections, so don't allocate space. */
4332 continue;
4334 if (s->size == 0)
4336 /* If we don't need this section, strip it from the
4337 output file. This is mostly to handle .rela.bss and
4338 .rela.plt. We must create both sections in
4339 create_dynamic_sections, because they must be created
4340 before the linker maps input sections to output
4341 sections. The linker does that before
4342 adjust_dynamic_symbol is called, and it is that
4343 function which decides whether anything needs to go
4344 into these sections. */
4345 s->flags |= SEC_EXCLUDE;
4346 continue;
4349 if ((s->flags & SEC_HAS_CONTENTS) == 0)
4350 continue;
4352 /* Allocate memory for the section contents. We use bfd_zalloc
4353 here in case unused entries are not reclaimed before the
4354 section's contents are written out. This should not happen,
4355 but this way if it does, we get a R_MN10300_NONE reloc
4356 instead of garbage. */
4357 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4358 if (s->contents == NULL)
4359 return FALSE;
4362 if (elf_hash_table (info)->dynamic_sections_created)
4364 /* Add some entries to the .dynamic section. We fill in the
4365 values later, in _bfd_mn10300_elf_finish_dynamic_sections,
4366 but we must add the entries now so that we get the correct
4367 size for the .dynamic section. The DT_DEBUG entry is filled
4368 in by the dynamic linker and used by the debugger. */
4369 if (! info->shared)
4371 if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
4372 return FALSE;
4375 if (plt)
4377 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
4378 || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
4379 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
4380 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
4381 return FALSE;
4384 if (relocs)
4386 if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
4387 || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
4388 || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
4389 sizeof (Elf32_External_Rela)))
4390 return FALSE;
4393 if (reltext)
4395 if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
4396 return FALSE;
4400 return TRUE;
4403 /* Finish up dynamic symbol handling. We set the contents of various
4404 dynamic sections here. */
4406 static bfd_boolean
4407 _bfd_mn10300_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
4408 bfd * output_bfd;
4409 struct bfd_link_info * info;
4410 struct elf_link_hash_entry * h;
4411 Elf_Internal_Sym * sym;
4413 bfd * dynobj;
4415 dynobj = elf_hash_table (info)->dynobj;
4417 if (h->plt.offset != (bfd_vma) -1)
4419 asection * splt;
4420 asection * sgot;
4421 asection * srel;
4422 bfd_vma plt_index;
4423 bfd_vma got_offset;
4424 Elf_Internal_Rela rel;
4426 /* This symbol has an entry in the procedure linkage table. Set
4427 it up. */
4429 BFD_ASSERT (h->dynindx != -1);
4431 splt = bfd_get_section_by_name (dynobj, ".plt");
4432 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4433 srel = bfd_get_section_by_name (dynobj, ".rela.plt");
4434 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
4436 /* Get the index in the procedure linkage table which
4437 corresponds to this symbol. This is the index of this symbol
4438 in all the symbols for which we are making plt entries. The
4439 first entry in the procedure linkage table is reserved. */
4440 plt_index = ((h->plt.offset - elf_mn10300_sizeof_plt0 (info))
4441 / elf_mn10300_sizeof_plt (info));
4443 /* Get the offset into the .got table of the entry that
4444 corresponds to this function. Each .got entry is 4 bytes.
4445 The first three are reserved. */
4446 got_offset = (plt_index + 3) * 4;
4448 /* Fill in the entry in the procedure linkage table. */
4449 if (! info->shared)
4451 memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry,
4452 elf_mn10300_sizeof_plt (info));
4453 bfd_put_32 (output_bfd,
4454 (sgot->output_section->vma
4455 + sgot->output_offset
4456 + got_offset),
4457 (splt->contents + h->plt.offset
4458 + elf_mn10300_plt_symbol_offset (info)));
4460 bfd_put_32 (output_bfd,
4461 (1 - h->plt.offset - elf_mn10300_plt_plt0_offset (info)),
4462 (splt->contents + h->plt.offset
4463 + elf_mn10300_plt_plt0_offset (info)));
4465 else
4467 memcpy (splt->contents + h->plt.offset, elf_mn10300_pic_plt_entry,
4468 elf_mn10300_sizeof_plt (info));
4470 bfd_put_32 (output_bfd, got_offset,
4471 (splt->contents + h->plt.offset
4472 + elf_mn10300_plt_symbol_offset (info)));
4475 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4476 (splt->contents + h->plt.offset
4477 + elf_mn10300_plt_reloc_offset (info)));
4479 /* Fill in the entry in the global offset table. */
4480 bfd_put_32 (output_bfd,
4481 (splt->output_section->vma
4482 + splt->output_offset
4483 + h->plt.offset
4484 + elf_mn10300_plt_temp_offset (info)),
4485 sgot->contents + got_offset);
4487 /* Fill in the entry in the .rela.plt section. */
4488 rel.r_offset = (sgot->output_section->vma
4489 + sgot->output_offset
4490 + got_offset);
4491 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_JMP_SLOT);
4492 rel.r_addend = 0;
4493 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4494 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4495 + plt_index));
4497 if (!h->def_regular)
4498 /* Mark the symbol as undefined, rather than as defined in
4499 the .plt section. Leave the value alone. */
4500 sym->st_shndx = SHN_UNDEF;
4503 if (h->got.offset != (bfd_vma) -1)
4505 asection * sgot;
4506 asection * srel;
4507 Elf_Internal_Rela rel;
4509 /* This symbol has an entry in the global offset table. Set it up. */
4511 sgot = bfd_get_section_by_name (dynobj, ".got");
4512 srel = bfd_get_section_by_name (dynobj, ".rela.got");
4513 BFD_ASSERT (sgot != NULL && srel != NULL);
4515 rel.r_offset = (sgot->output_section->vma
4516 + sgot->output_offset
4517 + (h->got.offset &~ 1));
4519 /* If this is a -Bsymbolic link, and the symbol is defined
4520 locally, we just want to emit a RELATIVE reloc. Likewise if
4521 the symbol was forced to be local because of a version file.
4522 The entry in the global offset table will already have been
4523 initialized in the relocate_section function. */
4524 if (info->shared
4525 && (info->symbolic || h->dynindx == -1)
4526 && h->def_regular)
4528 rel.r_info = ELF32_R_INFO (0, R_MN10300_RELATIVE);
4529 rel.r_addend = (h->root.u.def.value
4530 + h->root.u.def.section->output_section->vma
4531 + h->root.u.def.section->output_offset);
4533 else
4535 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
4536 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_GLOB_DAT);
4537 rel.r_addend = 0;
4540 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4541 (bfd_byte *) ((Elf32_External_Rela *) srel->contents
4542 + srel->reloc_count));
4543 ++ srel->reloc_count;
4546 if (h->needs_copy)
4548 asection * s;
4549 Elf_Internal_Rela rel;
4551 /* This symbol needs a copy reloc. Set it up. */
4552 BFD_ASSERT (h->dynindx != -1
4553 && (h->root.type == bfd_link_hash_defined
4554 || h->root.type == bfd_link_hash_defweak));
4556 s = bfd_get_section_by_name (h->root.u.def.section->owner,
4557 ".rela.bss");
4558 BFD_ASSERT (s != NULL);
4560 rel.r_offset = (h->root.u.def.value
4561 + h->root.u.def.section->output_section->vma
4562 + h->root.u.def.section->output_offset);
4563 rel.r_info = ELF32_R_INFO (h->dynindx, R_MN10300_COPY);
4564 rel.r_addend = 0;
4565 bfd_elf32_swap_reloca_out (output_bfd, &rel,
4566 (bfd_byte *) ((Elf32_External_Rela *) s->contents
4567 + s->reloc_count));
4568 ++ s->reloc_count;
4571 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4572 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4573 || h == elf_hash_table (info)->hgot)
4574 sym->st_shndx = SHN_ABS;
4576 return TRUE;
4579 /* Finish up the dynamic sections. */
4581 static bfd_boolean
4582 _bfd_mn10300_elf_finish_dynamic_sections (output_bfd, info)
4583 bfd * output_bfd;
4584 struct bfd_link_info * info;
4586 bfd * dynobj;
4587 asection * sgot;
4588 asection * sdyn;
4590 dynobj = elf_hash_table (info)->dynobj;
4592 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4593 BFD_ASSERT (sgot != NULL);
4594 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4596 if (elf_hash_table (info)->dynamic_sections_created)
4598 asection * splt;
4599 Elf32_External_Dyn * dyncon;
4600 Elf32_External_Dyn * dynconend;
4602 BFD_ASSERT (sdyn != NULL);
4604 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4605 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4607 for (; dyncon < dynconend; dyncon++)
4609 Elf_Internal_Dyn dyn;
4610 const char * name;
4611 asection * s;
4613 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4615 switch (dyn.d_tag)
4617 default:
4618 break;
4620 case DT_PLTGOT:
4621 name = ".got";
4622 goto get_vma;
4624 case DT_JMPREL:
4625 name = ".rela.plt";
4626 get_vma:
4627 s = bfd_get_section_by_name (output_bfd, name);
4628 BFD_ASSERT (s != NULL);
4629 dyn.d_un.d_ptr = s->vma;
4630 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4631 break;
4633 case DT_PLTRELSZ:
4634 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4635 BFD_ASSERT (s != NULL);
4636 dyn.d_un.d_val = s->size;
4637 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4638 break;
4640 case DT_RELASZ:
4641 /* My reading of the SVR4 ABI indicates that the
4642 procedure linkage table relocs (DT_JMPREL) should be
4643 included in the overall relocs (DT_RELA). This is
4644 what Solaris does. However, UnixWare can not handle
4645 that case. Therefore, we override the DT_RELASZ entry
4646 here to make it not include the JMPREL relocs. Since
4647 the linker script arranges for .rela.plt to follow all
4648 other relocation sections, we don't have to worry
4649 about changing the DT_RELA entry. */
4650 s = bfd_get_section_by_name (output_bfd, ".rela.plt");
4651 if (s != NULL)
4652 dyn.d_un.d_val -= s->size;
4653 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4654 break;
4658 /* Fill in the first entry in the procedure linkage table. */
4659 splt = bfd_get_section_by_name (dynobj, ".plt");
4660 if (splt && splt->size > 0)
4662 if (info->shared)
4664 memcpy (splt->contents, elf_mn10300_pic_plt_entry,
4665 elf_mn10300_sizeof_plt (info));
4667 else
4669 memcpy (splt->contents, elf_mn10300_plt0_entry, PLT0_ENTRY_SIZE);
4670 bfd_put_32 (output_bfd,
4671 sgot->output_section->vma + sgot->output_offset + 4,
4672 splt->contents + elf_mn10300_plt0_gotid_offset (info));
4673 bfd_put_32 (output_bfd,
4674 sgot->output_section->vma + sgot->output_offset + 8,
4675 splt->contents + elf_mn10300_plt0_linker_offset (info));
4678 /* UnixWare sets the entsize of .plt to 4, although that doesn't
4679 really seem like the right value. */
4680 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
4684 /* Fill in the first three entries in the global offset table. */
4685 if (sgot->size > 0)
4687 if (sdyn == NULL)
4688 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4689 else
4690 bfd_put_32 (output_bfd,
4691 sdyn->output_section->vma + sdyn->output_offset,
4692 sgot->contents);
4693 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4694 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4697 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4699 return TRUE;
4702 /* Classify relocation types, such that combreloc can sort them
4703 properly. */
4705 static enum elf_reloc_type_class
4706 _bfd_mn10300_elf_reloc_type_class (const Elf_Internal_Rela *rela)
4708 switch ((int) ELF32_R_TYPE (rela->r_info))
4710 case R_MN10300_RELATIVE:
4711 return reloc_class_relative;
4712 case R_MN10300_JMP_SLOT:
4713 return reloc_class_plt;
4714 case R_MN10300_COPY:
4715 return reloc_class_copy;
4716 default:
4717 return reloc_class_normal;
4721 #ifndef ELF_ARCH
4722 #define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec
4723 #define TARGET_LITTLE_NAME "elf32-mn10300"
4724 #define ELF_ARCH bfd_arch_mn10300
4725 #define ELF_MACHINE_CODE EM_MN10300
4726 #define ELF_MACHINE_ALT1 EM_CYGNUS_MN10300
4727 #define ELF_MAXPAGESIZE 0x1000
4728 #endif
4730 #define elf_info_to_howto mn10300_info_to_howto
4731 #define elf_info_to_howto_rel 0
4732 #define elf_backend_can_gc_sections 1
4733 #define elf_backend_rela_normal 1
4734 #define elf_backend_check_relocs mn10300_elf_check_relocs
4735 #define elf_backend_gc_mark_hook mn10300_elf_gc_mark_hook
4736 #define elf_backend_relocate_section mn10300_elf_relocate_section
4737 #define bfd_elf32_bfd_relax_section mn10300_elf_relax_section
4738 #define bfd_elf32_bfd_get_relocated_section_contents \
4739 mn10300_elf_get_relocated_section_contents
4740 #define bfd_elf32_bfd_link_hash_table_create \
4741 elf32_mn10300_link_hash_table_create
4742 #define bfd_elf32_bfd_link_hash_table_free \
4743 elf32_mn10300_link_hash_table_free
4745 #ifndef elf_symbol_leading_char
4746 #define elf_symbol_leading_char '_'
4747 #endif
4749 /* So we can set bits in e_flags. */
4750 #define elf_backend_final_write_processing \
4751 _bfd_mn10300_elf_final_write_processing
4752 #define elf_backend_object_p _bfd_mn10300_elf_object_p
4754 #define bfd_elf32_bfd_merge_private_bfd_data \
4755 _bfd_mn10300_elf_merge_private_bfd_data
4757 #define elf_backend_can_gc_sections 1
4758 #define elf_backend_create_dynamic_sections \
4759 _bfd_mn10300_elf_create_dynamic_sections
4760 #define elf_backend_adjust_dynamic_symbol \
4761 _bfd_mn10300_elf_adjust_dynamic_symbol
4762 #define elf_backend_size_dynamic_sections \
4763 _bfd_mn10300_elf_size_dynamic_sections
4764 #define elf_backend_omit_section_dynsym \
4765 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4766 #define elf_backend_finish_dynamic_symbol \
4767 _bfd_mn10300_elf_finish_dynamic_symbol
4768 #define elf_backend_finish_dynamic_sections \
4769 _bfd_mn10300_elf_finish_dynamic_sections
4771 #define elf_backend_reloc_type_class \
4772 _bfd_mn10300_elf_reloc_type_class
4774 #define elf_backend_want_got_plt 1
4775 #define elf_backend_plt_readonly 1
4776 #define elf_backend_want_plt_sym 0
4777 #define elf_backend_got_header_size 12
4779 #include "elf32-target.h"