1 /* M32R-specific support for 32-bit ELF.
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 static bfd_reloc_status_type m32r_elf_10_pcrel_reloc
28 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
29 static bfd_reloc_status_type m32r_elf_do_10_pcrel_reloc
30 PARAMS ((bfd
*, reloc_howto_type
*, asection
*,
31 bfd_byte
*, bfd_vma
, asection
*, bfd_vma
, bfd_vma
));
32 static bfd_reloc_status_type m32r_elf_hi16_reloc
33 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
34 static void m32r_elf_relocate_hi16
35 PARAMS ((bfd
*, int, Elf_Internal_Rela
*, Elf_Internal_Rela
*,
36 bfd_byte
*, bfd_vma
));
37 bfd_reloc_status_type m32r_elf_lo16_reloc
38 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
39 bfd_reloc_status_type m32r_elf_generic_reloc
40 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
41 static bfd_reloc_status_type m32r_elf_sda16_reloc
42 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
43 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
44 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
45 static void m32r_info_to_howto_rel
46 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
47 static void m32r_info_to_howto
48 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
49 bfd_boolean _bfd_m32r_elf_section_from_bfd_section
50 PARAMS ((bfd
*, asection
*, int *));
51 void _bfd_m32r_elf_symbol_processing
52 PARAMS ((bfd
*, asymbol
*));
53 static bfd_boolean m32r_elf_add_symbol_hook
54 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Sym
*,
55 const char **, flagword
*, asection
**, bfd_vma
*));
56 static bfd_boolean m32r_elf_relocate_section
57 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
58 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
59 static bfd_reloc_status_type m32r_elf_final_sda_base
60 PARAMS ((bfd
*, struct bfd_link_info
*, const char **, bfd_vma
*));
61 static bfd_boolean m32r_elf_object_p
63 static void m32r_elf_final_write_processing
64 PARAMS ((bfd
*, bfd_boolean
));
65 static bfd_boolean m32r_elf_set_private_flags
66 PARAMS ((bfd
*, flagword
));
67 static bfd_boolean m32r_elf_merge_private_bfd_data
68 PARAMS ((bfd
*, bfd
*));
69 static bfd_boolean m32r_elf_print_private_bfd_data
70 PARAMS ((bfd
*, PTR
));
71 static bfd_boolean m32r_elf_gc_sweep_hook
72 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
73 const Elf_Internal_Rela
*));
74 static bfd_boolean m32r_elf_check_relocs
75 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
76 const Elf_Internal_Rela
*));
78 static bfd_boolean m32r_elf_adjust_dynamic_symbol
79 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
80 static bfd_boolean m32r_elf_size_dynamic_sections
81 PARAMS ((bfd
*, struct bfd_link_info
*));
83 asection
* m32r_elf_gc_mark_hook
84 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
85 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
87 static bfd_boolean m32r_elf_create_dynamic_sections
88 PARAMS ((bfd
*, struct bfd_link_info
*));
90 static bfd_boolean m32r_elf_finish_dynamic_sections
91 PARAMS ((bfd
*, struct bfd_link_info
*));
93 static bfd_boolean m32r_elf_finish_dynamic_symbol
94 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
97 static bfd_boolean allocate_dynrelocs
98 PARAMS ((struct elf_link_hash_entry
*, PTR
));
99 static bfd_boolean readonly_dynrelocs
100 PARAMS ((struct elf_link_hash_entry
*, PTR
));
101 static enum elf_reloc_type_class m32r_elf_reloc_type_class
102 PARAMS ((const Elf_Internal_Rela
*));
103 static bfd_boolean m32r_elf_fake_sections
104 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
106 #define NOP_INSN 0x7000
107 #define MAKE_PARALLEL(insn) ((insn) | 0x8000)
109 /* Use REL instead of RELA to save space.
110 This only saves space in libraries and object files, but perhaps
111 relocs will be put in ROM? All in all though, REL relocs are a pain
118 /* Use RELA. But use REL to link old objects for backwords compatibility. */
120 /* Functions for the M32R ELF linker. */
122 /* The name of the dynamic interpreter. This is put in the .interp
125 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
127 /* The nop opcode we use. */
129 #define M32R_NOP 0x7000f000
131 #define PLT_EMPTY 0x10101010 /* RIE -> RIE */
133 /* The size in bytes of an entry in the procedure linkage table. */
135 #define PLT_ENTRY_SIZE 20
136 #define PLT_HEADER_SIZE 20
138 /* The first one entries in a procedure linkage table are reserved,
139 and the initial contents are unimportant (we zero them out).
140 Subsequent entries look like this. */
142 #define PLT0_ENTRY_WORD0 0xd6c00000 /* seth r6, #high(.got+4) */
143 #define PLT0_ENTRY_WORD1 0x86e60000 /* or3 r6, r6, #low(.got)+4) */
144 #define PLT0_ENTRY_WORD2 0x24e626c6 /* ld r4, @r6+ -> ld r6, @r6 */
145 #define PLT0_ENTRY_WORD3 0x1fc6f000 /* jmp r6 || pnop */
146 #define PLT0_ENTRY_WORD4 PLT_EMPTY /* RIE -> RIE */
148 #define PLT0_PIC_ENTRY_WORD0 0xa4cc0004 /* ld r4, @(4,r12) */
149 #define PLT0_PIC_ENTRY_WORD1 0xa6cc0008 /* ld r6, @(8,r12) */
150 #define PLT0_PIC_ENTRY_WORD2 0x1fc6f000 /* jmp r6 || nop */
151 #define PLT0_PIC_ENTRY_WORD3 PLT_EMPTY /* RIE -> RIE */
152 #define PLT0_PIC_ENTRY_WORD4 PLT_EMPTY /* RIE -> RIE */
154 #define PLT_ENTRY_WORD0 0xe6000000 /* ld24 r6, .name_in_GOT */
155 #define PLT_ENTRY_WORD1 0x06acf000 /* add r6, r12 || nop */
156 #define PLT_ENTRY_WORD0b 0xd6c00000 /* seth r6, #high(.name_in_GOT) */
157 #define PLT_ENTRY_WORD1b 0x86e60000 /* or3 r6, r6, #low(.name_in_GOT) */
158 #define PLT_ENTRY_WORD2 0x26c61fc6 /* ld r6, @r6 -> jmp r6 */
159 #define PLT_ENTRY_WORD3 0xe5000000 /* ld24 r5, $offset */
160 #define PLT_ENTRY_WORD4 0xff000000 /* bra .plt0. */
163 static reloc_howto_type m32r_elf_howto_table
[] =
165 /* This reloc does nothing. */
166 HOWTO (R_M32R_NONE
, /* type */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
170 FALSE
, /* pc_relative */
172 complain_overflow_bitfield
, /* complain_on_overflow */
173 bfd_elf_generic_reloc
, /* special_function */
174 "R_M32R_NONE", /* name */
175 FALSE
, /* partial_inplace */
178 FALSE
), /* pcrel_offset */
180 /* A 16 bit absolute relocation. */
181 HOWTO (R_M32R_16
, /* type */
183 1, /* size (0 = byte, 1 = short, 2 = long) */
185 FALSE
, /* pc_relative */
187 complain_overflow_bitfield
, /* complain_on_overflow */
188 m32r_elf_generic_reloc
,/* special_function */
189 "R_M32R_16", /* name */
190 TRUE
, /* partial_inplace */
191 0xffff, /* src_mask */
192 0xffff, /* dst_mask */
193 FALSE
), /* pcrel_offset */
195 /* A 32 bit absolute relocation. */
196 HOWTO (R_M32R_32
, /* type */
198 2, /* size (0 = byte, 1 = short, 2 = long) */
200 FALSE
, /* pc_relative */
202 complain_overflow_bitfield
, /* complain_on_overflow */
203 m32r_elf_generic_reloc
,/* special_function */
204 "R_M32R_32", /* name */
205 TRUE
, /* partial_inplace */
206 0xffffffff, /* src_mask */
207 0xffffffff, /* dst_mask */
208 FALSE
), /* pcrel_offset */
210 /* A 24 bit address. */
211 HOWTO (R_M32R_24
, /* type */
213 2, /* size (0 = byte, 1 = short, 2 = long) */
215 FALSE
, /* pc_relative */
217 complain_overflow_unsigned
, /* complain_on_overflow */
218 m32r_elf_generic_reloc
,/* special_function */
219 "R_M32R_24", /* name */
220 TRUE
, /* partial_inplace */
221 0xffffff, /* src_mask */
222 0xffffff, /* dst_mask */
223 FALSE
), /* pcrel_offset */
225 /* An PC Relative 10-bit relocation, shifted by 2.
226 This reloc is complicated because relocations are relative to pc & -4.
227 i.e. branches in the right insn slot use the address of the left insn
229 /* ??? It's not clear whether this should have partial_inplace set or not.
230 Branch relaxing in the assembler can store the addend in the insn,
231 and if bfd_install_relocation gets called the addend may get added
233 HOWTO (R_M32R_10_PCREL
, /* type */
235 1, /* size (0 = byte, 1 = short, 2 = long) */
237 TRUE
, /* pc_relative */
239 complain_overflow_signed
, /* complain_on_overflow */
240 m32r_elf_10_pcrel_reloc
, /* special_function */
241 "R_M32R_10_PCREL", /* name */
242 FALSE
, /* partial_inplace */
245 TRUE
), /* pcrel_offset */
247 /* A relative 18 bit relocation, right shifted by 2. */
248 HOWTO (R_M32R_18_PCREL
, /* type */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 TRUE
, /* pc_relative */
254 complain_overflow_signed
, /* complain_on_overflow */
255 bfd_elf_generic_reloc
, /* special_function */
256 "R_M32R_18_PCREL", /* name */
257 FALSE
, /* partial_inplace */
258 0xffff, /* src_mask */
259 0xffff, /* dst_mask */
260 TRUE
), /* pcrel_offset */
262 /* A relative 26 bit relocation, right shifted by 2. */
263 /* ??? It's not clear whether this should have partial_inplace set or not.
264 Branch relaxing in the assembler can store the addend in the insn,
265 and if bfd_install_relocation gets called the addend may get added
267 HOWTO (R_M32R_26_PCREL
, /* type */
269 2, /* size (0 = byte, 1 = short, 2 = long) */
271 TRUE
, /* pc_relative */
273 complain_overflow_signed
, /* complain_on_overflow */
274 bfd_elf_generic_reloc
, /* special_function */
275 "R_M32R_26_PCREL", /* name */
276 FALSE
, /* partial_inplace */
277 0xffffff, /* src_mask */
278 0xffffff, /* dst_mask */
279 TRUE
), /* pcrel_offset */
281 /* High 16 bits of address when lower 16 is or'd in. */
282 HOWTO (R_M32R_HI16_ULO
, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_dont
, /* complain_on_overflow */
289 m32r_elf_hi16_reloc
, /* special_function */
290 "R_M32R_HI16_ULO", /* name */
291 TRUE
, /* partial_inplace */
292 0x0000ffff, /* src_mask */
293 0x0000ffff, /* dst_mask */
294 FALSE
), /* pcrel_offset */
296 /* High 16 bits of address when lower 16 is added in. */
297 HOWTO (R_M32R_HI16_SLO
, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE
, /* pc_relative */
303 complain_overflow_dont
, /* complain_on_overflow */
304 m32r_elf_hi16_reloc
, /* special_function */
305 "R_M32R_HI16_SLO", /* name */
306 TRUE
, /* partial_inplace */
307 0x0000ffff, /* src_mask */
308 0x0000ffff, /* dst_mask */
309 FALSE
), /* pcrel_offset */
311 /* Lower 16 bits of address. */
312 HOWTO (R_M32R_LO16
, /* type */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
316 FALSE
, /* pc_relative */
318 complain_overflow_dont
, /* complain_on_overflow */
319 m32r_elf_lo16_reloc
, /* special_function */
320 "R_M32R_LO16", /* name */
321 TRUE
, /* partial_inplace */
322 0x0000ffff, /* src_mask */
323 0x0000ffff, /* dst_mask */
324 FALSE
), /* pcrel_offset */
326 /* Small data area 16 bits offset. */
327 HOWTO (R_M32R_SDA16
, /* type */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
331 FALSE
, /* pc_relative */
333 complain_overflow_signed
, /* complain_on_overflow */
334 m32r_elf_sda16_reloc
, /* special_function */
335 "R_M32R_SDA16", /* name */
336 TRUE
, /* partial_inplace */ /* FIXME: correct? */
337 0x0000ffff, /* src_mask */
338 0x0000ffff, /* dst_mask */
339 FALSE
), /* pcrel_offset */
341 /* GNU extension to record C++ vtable hierarchy */
342 HOWTO (R_M32R_GNU_VTINHERIT
, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 FALSE
, /* pc_relative */
348 complain_overflow_dont
, /* complain_on_overflow */
349 NULL
, /* special_function */
350 "R_M32R_GNU_VTINHERIT", /* name */
351 FALSE
, /* partial_inplace */
354 FALSE
), /* pcrel_offset */
356 /* GNU extension to record C++ vtable member usage */
357 HOWTO (R_M32R_GNU_VTENTRY
, /* type */
359 2, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE
, /* pc_relative */
363 complain_overflow_dont
, /* complain_on_overflow */
364 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
365 "R_M32R_GNU_VTENTRY", /* name */
366 FALSE
, /* partial_inplace */
369 FALSE
), /* pcrel_offset */
392 /* A 16 bit absolute relocation. */
393 HOWTO (R_M32R_16_RELA
, /* type */
395 1, /* size (0 = byte, 1 = short, 2 = long) */
397 FALSE
, /* pc_relative */
399 complain_overflow_bitfield
, /* complain_on_overflow */
400 bfd_elf_generic_reloc
, /* special_function */
401 "R_M32R_16_RELA", /* name */
402 FALSE
, /* partial_inplace */
403 0xffff, /* src_mask */
404 0xffff, /* dst_mask */
405 FALSE
), /* pcrel_offset */
407 /* A 32 bit absolute relocation. */
408 HOWTO (R_M32R_32_RELA
, /* type */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
412 FALSE
, /* pc_relative */
414 complain_overflow_bitfield
, /* complain_on_overflow */
415 bfd_elf_generic_reloc
,/* special_function */
416 "R_M32R_32_RELA", /* name */
417 FALSE
, /* partial_inplace */
418 0xffffffff, /* src_mask */
419 0xffffffff, /* dst_mask */
420 FALSE
), /* pcrel_offset */
422 /* A 24 bit address. */
423 HOWTO (R_M32R_24_RELA
, /* type */
425 2, /* size (0 = byte, 1 = short, 2 = long) */
427 FALSE
, /* pc_relative */
429 complain_overflow_unsigned
, /* complain_on_overflow */
430 bfd_elf_generic_reloc
,/* special_function */
431 "R_M32R_24_RELA", /* name */
432 FALSE
, /* partial_inplace */
433 0xffffff, /* src_mask */
434 0xffffff, /* dst_mask */
435 FALSE
), /* pcrel_offset */
437 HOWTO (R_M32R_10_PCREL_RELA
, /* type */
439 1, /* size (0 = byte, 1 = short, 2 = long) */
441 TRUE
, /* pc_relative */
443 complain_overflow_signed
, /* complain_on_overflow */
444 m32r_elf_10_pcrel_reloc
, /* special_function */
445 "R_M32R_10_PCREL_RELA",/* name */
446 FALSE
, /* partial_inplace */
449 TRUE
), /* pcrel_offset */
451 /* A relative 18 bit relocation, right shifted by 2. */
452 HOWTO (R_M32R_18_PCREL_RELA
, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 TRUE
, /* pc_relative */
458 complain_overflow_signed
, /* complain_on_overflow */
459 bfd_elf_generic_reloc
, /* special_function */
460 "R_M32R_18_PCREL_RELA",/* name */
461 FALSE
, /* partial_inplace */
462 0xffff, /* src_mask */
463 0xffff, /* dst_mask */
464 TRUE
), /* pcrel_offset */
466 /* A relative 26 bit relocation, right shifted by 2. */
467 HOWTO (R_M32R_26_PCREL_RELA
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 TRUE
, /* pc_relative */
473 complain_overflow_signed
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 "R_M32R_26_PCREL_RELA",/* name */
476 FALSE
, /* partial_inplace */
477 0xffffff, /* src_mask */
478 0xffffff, /* dst_mask */
479 TRUE
), /* pcrel_offset */
481 /* High 16 bits of address when lower 16 is or'd in. */
482 HOWTO (R_M32R_HI16_ULO_RELA
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
488 complain_overflow_dont
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_M32R_HI16_ULO_RELA",/* name */
491 FALSE
, /* partial_inplace */
492 0x0000ffff, /* src_mask */
493 0x0000ffff, /* dst_mask */
494 FALSE
), /* pcrel_offset */
496 /* High 16 bits of address when lower 16 is added in. */
497 HOWTO (R_M32R_HI16_SLO_RELA
, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE
, /* pc_relative */
503 complain_overflow_dont
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_M32R_HI16_SLO_RELA",/* name */
506 FALSE
, /* partial_inplace */
507 0x0000ffff, /* src_mask */
508 0x0000ffff, /* dst_mask */
509 FALSE
), /* pcrel_offset */
511 /* Lower 16 bits of address. */
512 HOWTO (R_M32R_LO16_RELA
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE
, /* pc_relative */
518 complain_overflow_dont
, /* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 "R_M32R_LO16_RELA", /* name */
521 FALSE
, /* partial_inplace */
522 0x0000ffff, /* src_mask */
523 0x0000ffff, /* dst_mask */
524 FALSE
), /* pcrel_offset */
526 /* Small data area 16 bits offset. */
527 HOWTO (R_M32R_SDA16_RELA
, /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 FALSE
, /* pc_relative */
533 complain_overflow_signed
, /* complain_on_overflow */
534 bfd_elf_generic_reloc
, /* special_function */
535 "R_M32R_SDA16_RELA", /* name */
536 TRUE
, /* partial_inplace */ /* FIXME: correct? */
537 0x0000ffff, /* src_mask */
538 0x0000ffff, /* dst_mask */
539 FALSE
), /* pcrel_offset */
541 /* GNU extension to record C++ vtable hierarchy */
542 HOWTO (R_M32R_RELA_GNU_VTINHERIT
, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE
, /* pc_relative */
548 complain_overflow_dont
, /* complain_on_overflow */
549 NULL
, /* special_function */
550 "R_M32R_RELA_GNU_VTINHERIT", /* name */
551 FALSE
, /* partial_inplace */
554 FALSE
), /* pcrel_offset */
556 /* GNU extension to record C++ vtable member usage */
557 HOWTO (R_M32R_RELA_GNU_VTENTRY
, /* type */
559 2, /* size (0 = byte, 1 = short, 2 = long) */
561 FALSE
, /* pc_relative */
563 complain_overflow_dont
, /* complain_on_overflow */
564 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
565 "R_M32R_RELA_GNU_VTENTRY", /* name */
566 FALSE
, /* partial_inplace */
569 FALSE
), /* pcrel_offset */
575 /* Like R_M32R_24, but referring to the GOT table entry for
577 HOWTO (R_M32R_GOT24
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 FALSE
, /* pc_relative */
583 complain_overflow_unsigned
, /* complain_on_overflow */
584 bfd_elf_generic_reloc
, /* special_function */
585 "R_M32R_GOT24", /* name */
586 FALSE
, /* partial_inplace */
587 0xffffff, /* src_mask */
588 0xffffff, /* dst_mask */
589 FALSE
), /* pcrel_offset */
591 /* Like R_M32R_PCREL, but referring to the procedure linkage table
592 entry for the symbol. */
593 HOWTO (R_M32R_26_PLTREL
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 TRUE
, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 bfd_elf_generic_reloc
, /* special_function */
601 "R_M32R_26_PLTREL", /* name */
602 FALSE
, /* partial_inplace */
603 0xffffff, /* src_mask */
604 0xffffff, /* dst_mask */
605 TRUE
), /* pcrel_offset */
607 /* This is used only by the dynamic linker. The symbol should exist
608 both in the object being run and in some shared library. The
609 dynamic linker copies the data addressed by the symbol from the
610 shared library into the object, because the object being
611 run has to have the data at some particular address. */
612 HOWTO (R_M32R_COPY
, /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE
, /* pc_relative */
618 complain_overflow_bitfield
, /* complain_on_overflow */
619 bfd_elf_generic_reloc
, /* special_function */
620 "R_M32R_COPY", /* name */
621 FALSE
, /* partial_inplace */
622 0xffffffff, /* src_mask */
623 0xffffffff, /* dst_mask */
624 FALSE
), /* pcrel_offset */
626 /* Like R_M32R_24, but used when setting global offset table
628 HOWTO (R_M32R_GLOB_DAT
, /* type */
630 2, /* size (0 = byte, 1 = short, 2 = long) */
632 FALSE
, /* pc_relative */
634 complain_overflow_bitfield
, /* complain_on_overflow */
635 bfd_elf_generic_reloc
, /* special_function */
636 "R_M32R_GLOB_DAT", /* name */
637 FALSE
, /* partial_inplace */
638 0xffffffff, /* src_mask */
639 0xffffffff, /* dst_mask */
640 FALSE
), /* pcrel_offset */
642 /* Marks a procedure linkage table entry for a symbol. */
643 HOWTO (R_M32R_JMP_SLOT
, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE
, /* pc_relative */
649 complain_overflow_bitfield
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_M32R_JMP_SLOT", /* name */
652 FALSE
, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE
), /* pcrel_offset */
657 /* Used only by the dynamic linker. When the object is run, this
658 longword is set to the load address of the object, plus the
660 HOWTO (R_M32R_RELATIVE
, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_bitfield
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_M32R_RELATIVE", /* name */
669 FALSE
, /* partial_inplace */
670 0xffffffff, /* src_mask */
671 0xffffffff, /* dst_mask */
672 FALSE
), /* pcrel_offset */
674 HOWTO (R_M32R_GOTOFF
, /* type */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
678 FALSE
, /* pc_relative */
680 complain_overflow_bitfield
, /* complain_on_overflow */
681 bfd_elf_generic_reloc
, /* special_function */
682 "R_M32R_GOTOFF", /* name */
683 FALSE
, /* partial_inplace */
684 0xffffff, /* src_mask */
685 0xffffff, /* dst_mask */
686 FALSE
), /* pcrel_offset */
688 /* An PC Relative 24-bit relocation used when setting PIC offset
690 HOWTO (R_M32R_GOTPC24
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 TRUE
, /* pc_relative */
696 complain_overflow_unsigned
, /* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_M32R_GOTPC24", /* name */
699 FALSE
, /* partial_inplace */
700 0xffffff, /* src_mask */
701 0xffffff, /* dst_mask */
702 TRUE
), /* pcrel_offset */
704 /* Like R_M32R_HI16_ULO, but referring to the GOT table entry for
706 HOWTO (R_M32R_GOT16_HI_ULO
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE
, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_M32R_GOT16_HI_ULO", /* name */
715 FALSE
, /* partial_inplace */
716 0x0000ffff, /* src_mask */
717 0x0000ffff, /* dst_mask */
718 FALSE
), /* pcrel_offset */
720 /* Like R_M32R_HI16_SLO, but referring to the GOT table entry for
722 HOWTO (R_M32R_GOT16_HI_SLO
, /* type */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE
, /* pc_relative */
728 complain_overflow_dont
, /* complain_on_overflow */
729 bfd_elf_generic_reloc
, /* special_function */
730 "R_M32R_GOT16_HI_SLO", /* name */
731 FALSE
, /* partial_inplace */
732 0x0000ffff, /* src_mask */
733 0x0000ffff, /* dst_mask */
734 FALSE
), /* pcrel_offset */
736 /* Like R_M32R_LO16, but referring to the GOT table entry for
738 HOWTO (R_M32R_GOT16_LO
, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 FALSE
, /* pc_relative */
744 complain_overflow_dont
, /* complain_on_overflow */
745 bfd_elf_generic_reloc
, /* special_function */
746 "R_M32R_GOT16_LO", /* name */
747 FALSE
, /* partial_inplace */
748 0x0000ffff, /* src_mask */
749 0x0000ffff, /* dst_mask */
750 FALSE
), /* pcrel_offset */
752 /* An PC Relative relocation used when setting PIC offset table register.
753 Like R_M32R_HI16_ULO, but referring to the GOT table entry for
755 HOWTO (R_M32R_GOTPC_HI_ULO
, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_dont
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_M32R_GOTPC_HI_ULO", /* name */
764 FALSE
, /* partial_inplace */
765 0x0000ffff, /* src_mask */
766 0x0000ffff, /* dst_mask */
767 TRUE
), /* pcrel_offset */
769 /* An PC Relative relocation used when setting PIC offset table register.
770 Like R_M32R_HI16_SLO, but referring to the GOT table entry for
772 HOWTO (R_M32R_GOTPC_HI_SLO
, /* type */
774 2, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE
, /* pc_relative */
778 complain_overflow_dont
, /* complain_on_overflow */
779 bfd_elf_generic_reloc
, /* special_function */
780 "R_M32R_GOTPC_HI_SLO", /* name */
781 FALSE
, /* partial_inplace */
782 0x0000ffff, /* src_mask */
783 0x0000ffff, /* dst_mask */
784 TRUE
), /* pcrel_offset */
786 /* An PC Relative relocation used when setting PIC offset table register.
787 Like R_M32R_LO16, but referring to the GOT table entry for
789 HOWTO (R_M32R_GOTPC_LO
, /* type */
791 2, /* size (0 = byte, 1 = short, 2 = long) */
793 FALSE
, /* pc_relative */
795 complain_overflow_dont
, /* complain_on_overflow */
796 bfd_elf_generic_reloc
, /* special_function */
797 "R_M32R_GOTPC_LO", /* name */
798 FALSE
, /* partial_inplace */
799 0x0000ffff, /* src_mask */
800 0x0000ffff, /* dst_mask */
801 TRUE
), /* pcrel_offset */
803 HOWTO (R_M32R_GOTOFF_HI_ULO
, /* type */
805 2, /* size (0 = byte, 1 = short, 2 = long) */
807 FALSE
, /* pc_relative */
809 complain_overflow_dont
, /* complain_on_overflow */
810 bfd_elf_generic_reloc
, /* special_function */
811 "R_M32R_GOTOFF_HI_ULO",/* name */
812 FALSE
, /* partial_inplace */
813 0x0000ffff, /* src_mask */
814 0x0000ffff, /* dst_mask */
815 FALSE
), /* pcrel_offset */
817 HOWTO (R_M32R_GOTOFF_HI_SLO
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 FALSE
, /* pc_relative */
823 complain_overflow_dont
, /* complain_on_overflow */
824 bfd_elf_generic_reloc
, /* special_function */
825 "R_M32R_GOTOFF_HI_SLO",/* name */
826 FALSE
, /* partial_inplace */
827 0x0000ffff, /* src_mask */
828 0x0000ffff, /* dst_mask */
829 FALSE
), /* pcrel_offset */
831 HOWTO (R_M32R_GOTOFF_LO
, /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 FALSE
, /* pc_relative */
837 complain_overflow_dont
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_M32R_GOTOFF_LO", /* name */
840 FALSE
, /* partial_inplace */
841 0x0000ffff, /* src_mask */
842 0x0000ffff, /* dst_mask */
843 FALSE
), /* pcrel_offset */
846 /* Handle the R_M32R_10_PCREL reloc. */
848 static bfd_reloc_status_type
849 m32r_elf_10_pcrel_reloc (abfd
, reloc_entry
, symbol
, data
,
850 input_section
, output_bfd
, error_message
)
852 arelent
* reloc_entry
;
855 asection
* input_section
;
857 char ** error_message ATTRIBUTE_UNUSED
;
859 /* This part is from bfd_elf_generic_reloc. */
860 if (output_bfd
!= (bfd
*) NULL
861 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
862 && (! reloc_entry
->howto
->partial_inplace
863 || reloc_entry
->addend
== 0))
865 reloc_entry
->address
+= input_section
->output_offset
;
869 if (output_bfd
!= NULL
)
871 /* FIXME: See bfd_perform_relocation. Is this right? */
872 return bfd_reloc_continue
;
875 return m32r_elf_do_10_pcrel_reloc (abfd
, reloc_entry
->howto
,
877 data
, reloc_entry
->address
,
880 + symbol
->section
->output_section
->vma
881 + symbol
->section
->output_offset
),
882 reloc_entry
->addend
);
885 /* Utility to actually perform an R_M32R_10_PCREL reloc. */
887 static bfd_reloc_status_type
888 m32r_elf_do_10_pcrel_reloc (abfd
, howto
, input_section
, data
, offset
,
889 symbol_section
, symbol_value
, addend
)
891 reloc_howto_type
*howto
;
892 asection
*input_section
;
895 asection
*symbol_section ATTRIBUTE_UNUSED
;
896 bfd_vma symbol_value
;
899 bfd_signed_vma relocation
;
901 bfd_reloc_status_type status
;
903 /* Sanity check the address (offset in section). */
904 if (offset
> bfd_get_section_limit (abfd
, input_section
))
905 return bfd_reloc_outofrange
;
907 relocation
= symbol_value
+ addend
;
908 /* Make it pc relative. */
909 relocation
-= (input_section
->output_section
->vma
910 + input_section
->output_offset
);
911 /* These jumps mask off the lower two bits of the current address
912 before doing pcrel calculations. */
913 relocation
-= (offset
& -(bfd_vma
) 4);
915 if (relocation
< -0x200 || relocation
> 0x1ff)
916 status
= bfd_reloc_overflow
;
918 status
= bfd_reloc_ok
;
920 x
= bfd_get_16 (abfd
, data
+ offset
);
921 relocation
>>= howto
->rightshift
;
922 relocation
<<= howto
->bitpos
;
923 x
= (x
& ~howto
->dst_mask
) | (((x
& howto
->src_mask
) + relocation
) & howto
->dst_mask
);
924 bfd_put_16 (abfd
, (bfd_vma
) x
, data
+ offset
);
929 /* Handle the R_M32R_HI16_[SU]LO relocs.
930 HI16_SLO is for the add3 and load/store with displacement instructions.
931 HI16_ULO is for the or3 instruction.
932 For R_M32R_HI16_SLO, the lower 16 bits are sign extended when added to
933 the high 16 bytes so if the lower 16 bits are negative (bit 15 == 1) then
934 we must add one to the high 16 bytes (which will get subtracted off when
935 the low 16 bits are added).
936 These relocs have to be done in combination with an R_M32R_LO16 reloc
937 because there is a carry from the LO16 to the HI16. Here we just save
938 the information we need; we do the actual relocation when we see the LO16.
939 This code is copied from the elf32-mips.c. We also support an arbitrary
940 number of HI16 relocs to be associated with a single LO16 reloc. The
941 assembler sorts the relocs to ensure each HI16 immediately precedes its
942 LO16. However if there are multiple copies, the assembler may not find
943 the real LO16 so it picks the first one it finds. */
947 struct m32r_hi16
*next
;
952 /* FIXME: This should not be a static variable. */
954 static struct m32r_hi16
*m32r_hi16_list
;
956 static bfd_reloc_status_type
957 m32r_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
958 input_section
, output_bfd
, error_message
)
959 bfd
*abfd ATTRIBUTE_UNUSED
;
960 arelent
*reloc_entry
;
963 asection
*input_section
;
965 char **error_message ATTRIBUTE_UNUSED
;
967 bfd_reloc_status_type ret
;
971 /* This part is from bfd_elf_generic_reloc.
972 If we're relocating, and this an external symbol, we don't want
973 to change anything. */
974 if (output_bfd
!= (bfd
*) NULL
975 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
976 && reloc_entry
->addend
== 0)
978 reloc_entry
->address
+= input_section
->output_offset
;
982 /* Sanity check the address (offset in section). */
983 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
984 return bfd_reloc_outofrange
;
987 if (bfd_is_und_section (symbol
->section
)
988 && output_bfd
== (bfd
*) NULL
)
989 ret
= bfd_reloc_undefined
;
991 if (bfd_is_com_section (symbol
->section
))
994 relocation
= symbol
->value
;
996 relocation
+= symbol
->section
->output_section
->vma
;
997 relocation
+= symbol
->section
->output_offset
;
998 relocation
+= reloc_entry
->addend
;
1000 /* Save the information, and let LO16 do the actual relocation. */
1001 n
= (struct m32r_hi16
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
1003 return bfd_reloc_outofrange
;
1004 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
1005 n
->addend
= relocation
;
1006 n
->next
= m32r_hi16_list
;
1009 if (output_bfd
!= (bfd
*) NULL
)
1010 reloc_entry
->address
+= input_section
->output_offset
;
1015 /* Handle an M32R ELF HI16 reloc. */
1018 m32r_elf_relocate_hi16 (input_bfd
, type
, relhi
, rello
, contents
, addend
)
1021 Elf_Internal_Rela
*relhi
;
1022 Elf_Internal_Rela
*rello
;
1029 insn
= bfd_get_32 (input_bfd
, contents
+ relhi
->r_offset
);
1031 addlo
= bfd_get_32 (input_bfd
, contents
+ rello
->r_offset
);
1032 if (type
== R_M32R_HI16_SLO
)
1033 addlo
= ((addlo
& 0xffff) ^ 0x8000) - 0x8000;
1037 addend
+= ((insn
& 0xffff) << 16) + addlo
;
1039 /* Reaccount for sign extension of low part. */
1040 if (type
== R_M32R_HI16_SLO
1041 && (addend
& 0x8000) != 0)
1044 bfd_put_32 (input_bfd
,
1045 (insn
& 0xffff0000) | ((addend
>> 16) & 0xffff),
1046 contents
+ relhi
->r_offset
);
1049 /* Do an R_M32R_LO16 relocation. This is a straightforward 16 bit
1050 inplace relocation; this function exists in order to do the
1051 R_M32R_HI16_[SU]LO relocation described above. */
1053 bfd_reloc_status_type
1054 m32r_elf_lo16_reloc (input_bfd
, reloc_entry
, symbol
, data
,
1055 input_section
, output_bfd
, error_message
)
1057 arelent
*reloc_entry
;
1060 asection
*input_section
;
1062 char **error_message
;
1064 /* This part is from bfd_elf_generic_reloc.
1065 If we're relocating, and this an external symbol, we don't want
1066 to change anything. */
1067 if (output_bfd
!= (bfd
*) NULL
1068 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1069 && reloc_entry
->addend
== 0)
1071 reloc_entry
->address
+= input_section
->output_offset
;
1072 return bfd_reloc_ok
;
1075 if (m32r_hi16_list
!= NULL
)
1077 struct m32r_hi16
*l
;
1084 unsigned long vallo
;
1085 struct m32r_hi16
*next
;
1087 /* Do the HI16 relocation. Note that we actually don't need
1088 to know anything about the LO16 itself, except where to
1089 find the low 16 bits of the addend needed by the LO16. */
1090 insn
= bfd_get_32 (input_bfd
, l
->addr
);
1091 vallo
= ((bfd_get_32 (input_bfd
, (bfd_byte
*) data
+ reloc_entry
->address
)
1092 & 0xffff) ^ 0x8000) - 0x8000;
1093 val
= ((insn
& 0xffff) << 16) + vallo
;
1096 /* Reaccount for sign extension of low part. */
1097 if ((val
& 0x8000) != 0)
1100 insn
= (insn
&~ (bfd_vma
) 0xffff) | ((val
>> 16) & 0xffff);
1101 bfd_put_32 (input_bfd
, (bfd_vma
) insn
, l
->addr
);
1108 m32r_hi16_list
= NULL
;
1111 /* Now do the LO16 reloc in the usual way.
1112 ??? It would be nice to call bfd_elf_generic_reloc here,
1113 but we have partial_inplace set. bfd_elf_generic_reloc will
1114 pass the handling back to bfd_install_relocation which will install
1115 a section relative addend which is wrong. */
1116 return m32r_elf_generic_reloc (input_bfd
, reloc_entry
, symbol
, data
,
1117 input_section
, output_bfd
, error_message
);
1120 /* Do generic partial_inplace relocation.
1121 This is a local replacement for bfd_elf_generic_reloc. */
1123 bfd_reloc_status_type
1124 m32r_elf_generic_reloc (input_bfd
, reloc_entry
, symbol
, data
,
1125 input_section
, output_bfd
, error_message
)
1127 arelent
*reloc_entry
;
1130 asection
*input_section
;
1132 char **error_message ATTRIBUTE_UNUSED
;
1134 bfd_reloc_status_type ret
;
1136 bfd_byte
*inplace_address
;
1138 /* This part is from bfd_elf_generic_reloc.
1139 If we're relocating, and this an external symbol, we don't want
1140 to change anything. */
1141 if (output_bfd
!= (bfd
*) NULL
1142 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1143 && reloc_entry
->addend
== 0)
1145 reloc_entry
->address
+= input_section
->output_offset
;
1146 return bfd_reloc_ok
;
1149 /* Now do the reloc in the usual way.
1150 ??? It would be nice to call bfd_elf_generic_reloc here,
1151 but we have partial_inplace set. bfd_elf_generic_reloc will
1152 pass the handling back to bfd_install_relocation which will install
1153 a section relative addend which is wrong. */
1155 /* Sanity check the address (offset in section). */
1156 if (reloc_entry
->address
> bfd_get_section_limit (input_bfd
, input_section
))
1157 return bfd_reloc_outofrange
;
1160 if (bfd_is_und_section (symbol
->section
)
1161 && output_bfd
== (bfd
*) NULL
)
1162 ret
= bfd_reloc_undefined
;
1164 if (bfd_is_com_section (symbol
->section
)
1165 || output_bfd
!= (bfd
*) NULL
)
1168 relocation
= symbol
->value
;
1170 /* Only do this for a final link. */
1171 if (output_bfd
== (bfd
*) NULL
)
1173 relocation
+= symbol
->section
->output_section
->vma
;
1174 relocation
+= symbol
->section
->output_offset
;
1177 relocation
+= reloc_entry
->addend
;
1178 inplace_address
= (bfd_byte
*) data
+ reloc_entry
->address
;
1181 x = ( (x & ~reloc_entry->howto->dst_mask) | \
1182 (((x & reloc_entry->howto->src_mask) + relocation) & \
1183 reloc_entry->howto->dst_mask))
1185 switch (reloc_entry
->howto
->size
)
1189 short x
= bfd_get_16 (input_bfd
, inplace_address
);
1191 bfd_put_16 (input_bfd
, (bfd_vma
) x
, inplace_address
);
1196 unsigned long x
= bfd_get_32 (input_bfd
, inplace_address
);
1198 bfd_put_32 (input_bfd
, (bfd_vma
)x
, inplace_address
);
1205 if (output_bfd
!= (bfd
*) NULL
)
1206 reloc_entry
->address
+= input_section
->output_offset
;
1211 /* Handle the R_M32R_SDA16 reloc.
1212 This reloc is used to compute the address of objects in the small data area
1213 and to perform loads and stores from that area.
1214 The lower 16 bits are sign extended and added to the register specified
1215 in the instruction, which is assumed to point to _SDA_BASE_. */
1217 static bfd_reloc_status_type
1218 m32r_elf_sda16_reloc (abfd
, reloc_entry
, symbol
, data
,
1219 input_section
, output_bfd
, error_message
)
1220 bfd
*abfd ATTRIBUTE_UNUSED
;
1221 arelent
*reloc_entry
;
1223 PTR data ATTRIBUTE_UNUSED
;
1224 asection
*input_section
;
1226 char **error_message ATTRIBUTE_UNUSED
;
1228 /* This part is from bfd_elf_generic_reloc. */
1229 if (output_bfd
!= (bfd
*) NULL
1230 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1231 && (! reloc_entry
->howto
->partial_inplace
1232 || reloc_entry
->addend
== 0))
1234 reloc_entry
->address
+= input_section
->output_offset
;
1235 return bfd_reloc_ok
;
1238 if (output_bfd
!= NULL
)
1240 /* FIXME: See bfd_perform_relocation. Is this right? */
1241 return bfd_reloc_continue
;
1244 /* FIXME: not sure what to do here yet. But then again, the linker
1245 may never call us. */
1249 /* Map BFD reloc types to M32R ELF reloc types. */
1251 struct m32r_reloc_map
1253 bfd_reloc_code_real_type bfd_reloc_val
;
1254 unsigned char elf_reloc_val
;
1257 #ifdef USE_M32R_OLD_RELOC
1258 static const struct m32r_reloc_map m32r_reloc_map_old
[] =
1260 { BFD_RELOC_NONE
, R_M32R_NONE
},
1261 { BFD_RELOC_16
, R_M32R_16
},
1262 { BFD_RELOC_32
, R_M32R_32
},
1263 { BFD_RELOC_M32R_24
, R_M32R_24
},
1264 { BFD_RELOC_M32R_10_PCREL
, R_M32R_10_PCREL
},
1265 { BFD_RELOC_M32R_18_PCREL
, R_M32R_18_PCREL
},
1266 { BFD_RELOC_M32R_26_PCREL
, R_M32R_26_PCREL
},
1267 { BFD_RELOC_M32R_HI16_ULO
, R_M32R_HI16_ULO
},
1268 { BFD_RELOC_M32R_HI16_SLO
, R_M32R_HI16_SLO
},
1269 { BFD_RELOC_M32R_LO16
, R_M32R_LO16
},
1270 { BFD_RELOC_M32R_SDA16
, R_M32R_SDA16
},
1271 { BFD_RELOC_VTABLE_INHERIT
, R_M32R_GNU_VTINHERIT
},
1272 { BFD_RELOC_VTABLE_ENTRY
, R_M32R_GNU_VTENTRY
},
1275 static const struct m32r_reloc_map m32r_reloc_map
[] =
1277 { BFD_RELOC_NONE
, R_M32R_NONE
},
1278 { BFD_RELOC_16
, R_M32R_16_RELA
},
1279 { BFD_RELOC_32
, R_M32R_32_RELA
},
1280 { BFD_RELOC_M32R_24
, R_M32R_24_RELA
},
1281 { BFD_RELOC_M32R_10_PCREL
, R_M32R_10_PCREL_RELA
},
1282 { BFD_RELOC_M32R_18_PCREL
, R_M32R_18_PCREL_RELA
},
1283 { BFD_RELOC_M32R_26_PCREL
, R_M32R_26_PCREL_RELA
},
1284 { BFD_RELOC_M32R_HI16_ULO
, R_M32R_HI16_ULO_RELA
},
1285 { BFD_RELOC_M32R_HI16_SLO
, R_M32R_HI16_SLO_RELA
},
1286 { BFD_RELOC_M32R_LO16
, R_M32R_LO16_RELA
},
1287 { BFD_RELOC_M32R_SDA16
, R_M32R_SDA16_RELA
},
1288 { BFD_RELOC_VTABLE_INHERIT
, R_M32R_RELA_GNU_VTINHERIT
},
1289 { BFD_RELOC_VTABLE_ENTRY
, R_M32R_RELA_GNU_VTENTRY
},
1291 { BFD_RELOC_M32R_GOT24
, R_M32R_GOT24
},
1292 { BFD_RELOC_M32R_26_PLTREL
, R_M32R_26_PLTREL
},
1293 { BFD_RELOC_M32R_COPY
, R_M32R_COPY
},
1294 { BFD_RELOC_M32R_GLOB_DAT
, R_M32R_GLOB_DAT
},
1295 { BFD_RELOC_M32R_JMP_SLOT
, R_M32R_JMP_SLOT
},
1296 { BFD_RELOC_M32R_RELATIVE
, R_M32R_RELATIVE
},
1297 { BFD_RELOC_M32R_GOTOFF
, R_M32R_GOTOFF
},
1298 { BFD_RELOC_M32R_GOTPC24
, R_M32R_GOTPC24
},
1299 { BFD_RELOC_M32R_GOT16_HI_ULO
, R_M32R_GOT16_HI_ULO
},
1300 { BFD_RELOC_M32R_GOT16_HI_SLO
, R_M32R_GOT16_HI_SLO
},
1301 { BFD_RELOC_M32R_GOT16_LO
, R_M32R_GOT16_LO
},
1302 { BFD_RELOC_M32R_GOTPC_HI_ULO
, R_M32R_GOTPC_HI_ULO
},
1303 { BFD_RELOC_M32R_GOTPC_HI_SLO
, R_M32R_GOTPC_HI_SLO
},
1304 { BFD_RELOC_M32R_GOTPC_LO
, R_M32R_GOTPC_LO
},
1305 { BFD_RELOC_M32R_GOTOFF_HI_ULO
, R_M32R_GOTOFF_HI_ULO
},
1306 { BFD_RELOC_M32R_GOTOFF_HI_SLO
, R_M32R_GOTOFF_HI_SLO
},
1307 { BFD_RELOC_M32R_GOTOFF_LO
, R_M32R_GOTOFF_LO
},
1311 static reloc_howto_type
*
1312 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1313 bfd
*abfd ATTRIBUTE_UNUSED
;
1314 bfd_reloc_code_real_type code
;
1318 #ifdef USE_M32R_OLD_RELOC
1320 i
< sizeof (m32r_reloc_map_old
) / sizeof (struct m32r_reloc_map
);
1323 if (m32r_reloc_map_old
[i
].bfd_reloc_val
== code
)
1324 return &m32r_elf_howto_table
[m32r_reloc_map_old
[i
].elf_reloc_val
];
1326 #else /* ! USE_M32R_OLD_RELOC */
1329 i
< sizeof (m32r_reloc_map
) / sizeof (struct m32r_reloc_map
);
1332 if (m32r_reloc_map
[i
].bfd_reloc_val
== code
)
1333 return &m32r_elf_howto_table
[m32r_reloc_map
[i
].elf_reloc_val
];
1340 /* Set the howto pointer for an M32R ELF reloc. */
1343 m32r_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1344 bfd
*abfd ATTRIBUTE_UNUSED
;
1346 Elf_Internal_Rela
*dst
;
1348 unsigned int r_type
;
1350 r_type
= ELF32_R_TYPE (dst
->r_info
);
1351 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) <= (unsigned int) R_M32R_GNU_VTENTRY
);
1352 cache_ptr
->howto
= &m32r_elf_howto_table
[r_type
];
1356 m32r_info_to_howto (abfd
, cache_ptr
, dst
)
1357 bfd
*abfd ATTRIBUTE_UNUSED
;
1359 Elf_Internal_Rela
*dst
;
1361 BFD_ASSERT ((ELF32_R_TYPE(dst
->r_info
) == (unsigned int) R_M32R_NONE
)
1362 || ((ELF32_R_TYPE(dst
->r_info
) > (unsigned int) R_M32R_GNU_VTENTRY
)
1363 && (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_M32R_max
)));
1364 cache_ptr
->howto
= &m32r_elf_howto_table
[ELF32_R_TYPE(dst
->r_info
)];
1368 /* Given a BFD section, try to locate the corresponding ELF section
1372 _bfd_m32r_elf_section_from_bfd_section (abfd
, sec
, retval
)
1373 bfd
*abfd ATTRIBUTE_UNUSED
;
1377 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
1379 *retval
= SHN_M32R_SCOMMON
;
1385 /* M32R ELF uses two common sections. One is the usual one, and the other
1386 is for small objects. All the small objects are kept together, and then
1387 referenced via one register, which yields faster assembler code. It is
1388 up to the compiler to emit an instruction to load the register with
1389 _SDA_BASE. This is what we use for the small common section. This
1390 approach is copied from elf32-mips.c. */
1391 static asection m32r_elf_scom_section
;
1392 static asymbol m32r_elf_scom_symbol
;
1393 static asymbol
*m32r_elf_scom_symbol_ptr
;
1395 /* Handle the special M32R section numbers that a symbol may use. */
1398 _bfd_m32r_elf_symbol_processing (abfd
, asym
)
1399 bfd
*abfd ATTRIBUTE_UNUSED
;
1402 elf_symbol_type
*elfsym
;
1404 elfsym
= (elf_symbol_type
*) asym
;
1406 switch (elfsym
->internal_elf_sym
.st_shndx
)
1408 case SHN_M32R_SCOMMON
:
1409 if (m32r_elf_scom_section
.name
== NULL
)
1411 /* Initialize the small common section. */
1412 m32r_elf_scom_section
.name
= ".scommon";
1413 m32r_elf_scom_section
.flags
= SEC_IS_COMMON
;
1414 m32r_elf_scom_section
.output_section
= &m32r_elf_scom_section
;
1415 m32r_elf_scom_section
.symbol
= &m32r_elf_scom_symbol
;
1416 m32r_elf_scom_section
.symbol_ptr_ptr
= &m32r_elf_scom_symbol_ptr
;
1417 m32r_elf_scom_symbol
.name
= ".scommon";
1418 m32r_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
1419 m32r_elf_scom_symbol
.section
= &m32r_elf_scom_section
;
1420 m32r_elf_scom_symbol_ptr
= &m32r_elf_scom_symbol
;
1422 asym
->section
= &m32r_elf_scom_section
;
1423 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
1428 /* Hook called by the linker routine which adds symbols from an object
1429 file. We must handle the special M32R section numbers here.
1430 We also keep watching for whether we need to create the sdata special
1434 m32r_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
1436 struct bfd_link_info
*info
;
1437 Elf_Internal_Sym
*sym
;
1439 flagword
*flagsp ATTRIBUTE_UNUSED
;
1443 if (! info
->relocatable
1444 && (*namep
)[0] == '_' && (*namep
)[1] == 'S'
1445 && strcmp (*namep
, "_SDA_BASE_") == 0
1446 && is_elf_hash_table (info
->hash
))
1448 /* This is simpler than using _bfd_elf_create_linker_section
1449 (our needs are simpler than ppc's needs). Also
1450 _bfd_elf_create_linker_section currently has a bug where if a .sdata
1451 section already exists a new one is created that follows it which
1452 screws of _SDA_BASE_ address calcs because output_offset != 0. */
1453 struct elf_link_hash_entry
*h
;
1454 struct bfd_link_hash_entry
*bh
;
1455 asection
*s
= bfd_get_section_by_name (abfd
, ".sdata");
1457 /* The following code was cobbled from elf32-ppc.c and elflink.c. */
1461 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1462 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1464 s
= bfd_make_section_anyway (abfd
, ".sdata");
1467 bfd_set_section_flags (abfd
, s
, flags
);
1468 bfd_set_section_alignment (abfd
, s
, 2);
1471 bh
= bfd_link_hash_lookup (info
->hash
, "_SDA_BASE_",
1472 FALSE
, FALSE
, FALSE
);
1474 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
1475 && !(_bfd_generic_link_add_one_symbol (info
,
1481 (const char *) NULL
,
1483 get_elf_backend_data (abfd
)->collect
,
1486 h
= (struct elf_link_hash_entry
*) bh
;
1487 h
->type
= STT_OBJECT
;
1490 switch (sym
->st_shndx
)
1492 case SHN_M32R_SCOMMON
:
1493 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
1494 (*secp
)->flags
|= SEC_IS_COMMON
;
1495 *valp
= sym
->st_size
;
1502 /* We have to figure out the SDA_BASE value, so that we can adjust the
1503 symbol value correctly. We look up the symbol _SDA_BASE_ in the output
1504 BFD. If we can't find it, we're stuck. We cache it in the ELF
1505 target data. We don't need to adjust the symbol value for an
1506 external symbol if we are producing relocatable output. */
1508 static bfd_reloc_status_type
1509 m32r_elf_final_sda_base (output_bfd
, info
, error_message
, psb
)
1511 struct bfd_link_info
*info
;
1512 const char **error_message
;
1515 if (elf_gp (output_bfd
) == 0)
1517 struct bfd_link_hash_entry
*h
;
1519 h
= bfd_link_hash_lookup (info
->hash
, "_SDA_BASE_", FALSE
, FALSE
, TRUE
);
1520 if (h
!= (struct bfd_link_hash_entry
*) NULL
1521 && h
->type
== bfd_link_hash_defined
)
1522 elf_gp (output_bfd
) = (h
->u
.def
.value
1523 + h
->u
.def
.section
->output_section
->vma
1524 + h
->u
.def
.section
->output_offset
);
1527 /* Only get the error once. */
1528 *psb
= elf_gp (output_bfd
) = 4;
1530 (const char *) _("SDA relocation when _SDA_BASE_ not defined");
1531 return bfd_reloc_dangerous
;
1534 *psb
= elf_gp (output_bfd
);
1535 return bfd_reloc_ok
;
1538 /* Return size of a PLT entry. */
1539 #define elf_m32r_sizeof_plt(info) PLT_ENTRY_SIZE
1541 /* The m32r linker needs to keep track of the number of relocs that it
1542 decides to copy in check_relocs for each symbol. This is so that
1543 it can discard PC relative relocs if it doesn't need them when
1544 linking with -Bsymbolic. We store the information in a field
1545 extending the regular ELF linker hash table. */
1547 /* This structure keeps track of the number of PC relative relocs we
1548 have copied for a given symbol. */
1550 struct elf_m32r_pcrel_relocs_copied
1553 struct elf_m32r_pcrel_relocs_copied
*next
;
1554 /* A section in dynobj. */
1556 /* Number of relocs copied in this section. */
1557 bfd_size_type count
;
1560 /* The sh linker needs to keep track of the number of relocs that it
1561 decides to copy as dynamic relocs in check_relocs for each symbol.
1562 This is so that it can later discard them if they are found to be
1563 unnecessary. We store the information in a field extending the
1564 regular ELF linker hash table. */
1566 struct elf_m32r_dyn_relocs
1568 struct elf_m32r_dyn_relocs
*next
;
1570 /* The input section of the reloc. */
1573 /* Total number of relocs copied for the input section. */
1574 bfd_size_type count
;
1576 /* Number of pc-relative relocs copied for the input section. */
1577 bfd_size_type pc_count
;
1581 /* m32r ELF linker hash entry. */
1583 struct elf_m32r_link_hash_entry
1585 struct elf_link_hash_entry root
;
1587 /* Track dynamic relocs copied for this symbol. */
1588 struct elf_m32r_dyn_relocs
*dyn_relocs
;
1590 // bfd_signed_vma gotplt_refcount;
1592 /* Number of PC relative relocs copied for this symbol. */
1593 /* struct elf_m32r_pcrel_relocs_copied *pcrel_relocs_copied; FIXME */
1596 /* m32r ELF linker hash table. */
1598 struct elf_m32r_link_hash_table
1600 struct elf_link_hash_table root
;
1602 /* Short-cuts to get to dynamic linker sections. */
1611 /* Small local sym to section mapping cache. */
1612 struct sym_sec_cache sym_sec
;
1615 /* Traverse an m32r ELF linker hash table. */
1617 #define m32r_elf_link_hash_traverse(table, func, info) \
1618 (elf_link_hash_traverse \
1620 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
1623 /* Get the m32r ELF linker hash table from a link_info structure. */
1626 #define m32r_elf_hash_table(p) \
1627 ((struct elf_m32r_link_hash_table *) ((p)->hash))
1629 /* Create an entry in an m32r ELF linker hash table. */
1630 static struct bfd_hash_entry
*
1631 m32r_elf_link_hash_newfunc (struct bfd_hash_entry
*, struct bfd_hash_table
*,
1634 static struct bfd_hash_entry
*
1635 m32r_elf_link_hash_newfunc (entry
, table
, string
)
1636 struct bfd_hash_entry
*entry
;
1637 struct bfd_hash_table
*table
;
1640 struct elf_m32r_link_hash_entry
*ret
=
1641 (struct elf_m32r_link_hash_entry
*) entry
;
1643 /* Allocate the structure if it has not already been allocated by a
1645 if (ret
== (struct elf_m32r_link_hash_entry
*) NULL
)
1646 ret
= ((struct elf_m32r_link_hash_entry
*)
1647 bfd_hash_allocate (table
,
1648 sizeof (struct elf_m32r_link_hash_entry
)));
1649 if (ret
== (struct elf_m32r_link_hash_entry
*) NULL
)
1650 return (struct bfd_hash_entry
*) ret
;
1652 /* Call the allocation method of the superclass. */
1653 ret
= ((struct elf_m32r_link_hash_entry
*)
1654 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1656 if (ret
!= (struct elf_m32r_link_hash_entry
*) NULL
)
1658 struct elf_m32r_link_hash_entry
*eh
;
1660 eh
= (struct elf_m32r_link_hash_entry
*) ret
;
1661 eh
->dyn_relocs
= NULL
;
1662 // eh->gotplt_refcount = 0;
1663 /* eh->pcrel_relocs_copied = NULL; FIXME */
1666 return (struct bfd_hash_entry
*) ret
;
1669 /* Create an m32r ELF linker hash table. */
1670 static struct bfd_link_hash_table
*m32r_elf_link_hash_table_create (bfd
*);
1672 static struct bfd_link_hash_table
*
1673 m32r_elf_link_hash_table_create (abfd
)
1676 struct elf_m32r_link_hash_table
*ret
;
1677 bfd_size_type amt
= sizeof (struct elf_m32r_link_hash_table
);
1679 ret
= (struct elf_m32r_link_hash_table
*) bfd_malloc (amt
);
1680 if (ret
== (struct elf_m32r_link_hash_table
*) NULL
)
1683 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
1684 m32r_elf_link_hash_newfunc
))
1691 ret
->sgotplt
= NULL
;
1692 ret
->srelgot
= NULL
;
1694 ret
->srelplt
= NULL
;
1695 ret
->sdynbss
= NULL
;
1696 ret
->srelbss
= NULL
;
1697 ret
->sym_sec
.abfd
= NULL
;
1699 return &ret
->root
.root
;
1702 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
1703 shortcuts to them in our hash table. */
1704 static bfd_boolean
create_got_section (bfd
*, struct bfd_link_info
*);
1707 create_got_section (dynobj
, info
)
1709 struct bfd_link_info
*info
;
1711 struct elf_m32r_link_hash_table
*htab
;
1713 if (! _bfd_elf_create_got_section (dynobj
, info
))
1716 htab
= m32r_elf_hash_table (info
);
1717 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
1718 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1719 if (! htab
->sgot
|| ! htab
->sgotplt
)
1722 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
1723 if (htab
->srelgot
== NULL
1724 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
1729 | SEC_LINKER_CREATED
1731 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
1737 /* Create dynamic sections when linking against a dynamic object. */
1740 m32r_elf_create_dynamic_sections (abfd
, info
)
1742 struct bfd_link_info
*info
;
1744 struct elf_m32r_link_hash_table
*htab
;
1745 flagword flags
, pltflags
;
1746 register asection
*s
;
1747 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1748 int ptralign
= 2; /* 32bit */
1750 htab
= m32r_elf_hash_table (info
);
1752 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
1753 .rel[a].bss sections. */
1755 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1756 | SEC_LINKER_CREATED
);
1759 pltflags
|= SEC_CODE
;
1760 if (bed
->plt_not_loaded
)
1761 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
1762 if (bed
->plt_readonly
)
1763 pltflags
|= SEC_READONLY
;
1765 s
= bfd_make_section (abfd
, ".plt");
1768 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
1769 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
1772 if (bed
->want_plt_sym
)
1774 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
1776 struct bfd_link_hash_entry
*bh
= NULL
;
1777 struct elf_link_hash_entry
*h
;
1778 if (! (_bfd_generic_link_add_one_symbol
1779 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
1780 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
1781 get_elf_backend_data (abfd
)->collect
, &bh
)))
1783 h
= (struct elf_link_hash_entry
*) bh
;
1785 h
->type
= STT_OBJECT
;
1788 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1792 s
= bfd_make_section (abfd
,
1793 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
1796 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1797 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
1800 if (htab
->sgot
== NULL
1801 && ! create_got_section (abfd
, info
))
1805 const char *secname
;
1810 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
1812 secflags
= bfd_get_section_flags (abfd
, sec
);
1813 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
1814 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
1816 secname
= bfd_get_section_name (abfd
, sec
);
1817 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
1818 strcpy (relname
, ".rela");
1819 strcat (relname
, secname
);
1820 if (bfd_get_section_by_name (abfd
, secname
))
1822 s
= bfd_make_section (abfd
, relname
);
1824 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1825 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
1830 if (bed
->want_dynbss
)
1832 /* The .dynbss section is a place to put symbols which are defined
1833 by dynamic objects, are referenced by regular objects, and are
1834 not functions. We must allocate space for them in the process
1835 image and use a R_*_COPY reloc to tell the dynamic linker to
1836 initialize them at run time. The linker script puts the .dynbss
1837 section into the .bss section of the final image. */
1838 s
= bfd_make_section (abfd
, ".dynbss");
1841 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
1843 /* The .rel[a].bss section holds copy relocs. This section is not
1844 normally needed. We need to create it here, though, so that the
1845 linker will map it to an output section. We can't just create it
1846 only if we need it, because we will not know whether we need it
1847 until we have seen all the input files, and the first time the
1848 main linker code calls BFD after examining all the input files
1849 (size_dynamic_sections) the input sections have already been
1850 mapped to the output sections. If the section turns out not to
1851 be needed, we can discard it later. We will never need this
1852 section when generating a shared object, since they do not use
1856 s
= bfd_make_section (abfd
,
1857 (bed
->default_use_rela_p
1858 ? ".rela.bss" : ".rel.bss"));
1861 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1862 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
1870 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1871 static void m32r_elf_copy_indirect_symbol (const struct elf_backend_data
*,
1872 struct elf_link_hash_entry
*,
1873 struct elf_link_hash_entry
*);
1876 m32r_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
1877 struct elf_link_hash_entry
*dir
,
1878 struct elf_link_hash_entry
*ind
)
1880 struct elf_m32r_link_hash_entry
*edir
, *eind
;
1882 edir
= (struct elf_m32r_link_hash_entry
*) dir
;
1883 eind
= (struct elf_m32r_link_hash_entry
*) ind
;
1885 if (eind
->dyn_relocs
!= NULL
)
1887 if (edir
->dyn_relocs
!= NULL
)
1889 struct elf_m32r_dyn_relocs
**pp
;
1890 struct elf_m32r_dyn_relocs
*p
;
1892 if (ind
->root
.type
== bfd_link_hash_indirect
)
1895 /* Add reloc counts against the weak sym to the strong sym
1896 list. Merge any entries against the same section. */
1897 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1899 struct elf_m32r_dyn_relocs
*q
;
1901 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1902 if (q
->sec
== p
->sec
)
1904 q
->pc_count
+= p
->pc_count
;
1905 q
->count
+= p
->count
;
1912 *pp
= edir
->dyn_relocs
;
1915 edir
->dyn_relocs
= eind
->dyn_relocs
;
1916 eind
->dyn_relocs
= NULL
;
1919 // if (ind->root.type == bfd_link_hash_indirect
1920 // && dir->got.refcount <= 0)
1922 // edir->tls_type = eind->tls_type;
1923 // eind->tls_type = GOT_UNKNOWN;
1925 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
1929 /* Adjust a symbol defined by a dynamic object and referenced by a
1930 regular object. The current definition is in some section of the
1931 dynamic object, but we're not including those sections. We have to
1932 change the definition to something the rest of the link can
1936 m32r_elf_adjust_dynamic_symbol (info
, h
)
1937 struct bfd_link_info
*info
;
1938 struct elf_link_hash_entry
*h
;
1940 struct elf_m32r_link_hash_table
*htab
;
1941 struct elf_m32r_link_hash_entry
*eh
;
1942 struct elf_m32r_dyn_relocs
*p
;
1945 unsigned int power_of_two
;
1948 printf("m32r_elf_adjust_dynamic_symbol()\n");
1951 dynobj
= elf_hash_table (info
)->dynobj
;
1953 /* Make sure we know what is going on here. */
1954 BFD_ASSERT (dynobj
!= NULL
1956 || h
->u
.weakdef
!= NULL
1959 && !h
->def_regular
)));
1962 /* If this is a function, put it in the procedure linkage table. We
1963 will fill in the contents of the procedure linkage table later,
1964 when we know the address of the .got section. */
1965 if (h
->type
== STT_FUNC
1971 && h
->root
.type
!= bfd_link_hash_undefweak
1972 && h
->root
.type
!= bfd_link_hash_undefined
)
1974 /* This case can occur if we saw a PLT reloc in an input
1975 file, but the symbol was never referred to by a dynamic
1976 object. In such a case, we don't actually need to build
1977 a procedure linkage table, and we can just do a PCREL
1979 h
->plt
.offset
= (bfd_vma
) -1;
1986 h
->plt
.offset
= (bfd_vma
) -1;
1988 /* If this is a weak symbol, and there is a real definition, the
1989 processor independent code will have arranged for us to see the
1990 real definition first, and we can just use the same value. */
1991 if (h
->u
.weakdef
!= NULL
)
1993 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1994 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1995 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1996 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2000 /* This is a reference to a symbol defined by a dynamic object which
2001 is not a function. */
2003 /* If we are creating a shared library, we must presume that the
2004 only references to the symbol are via the global offset table.
2005 For such cases we need not do anything here; the relocations will
2006 be handled correctly by relocate_section. */
2010 /* If there are no references to this symbol that do not use the
2011 GOT, we don't need to generate a copy reloc. */
2012 if (!h
->non_got_ref
)
2015 /* If -z nocopyreloc was given, we won't generate them either. */
2016 if (info
->nocopyreloc
)
2022 eh
= (struct elf_m32r_link_hash_entry
*) h
;
2023 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2025 s
= p
->sec
->output_section
;
2026 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
2030 /* If we didn't find any dynamic relocs in sections which needs the
2031 copy reloc, then we'll be keeping the dynamic relocs and avoiding
2039 /* We must allocate the symbol in our .dynbss section, which will
2040 become part of the .bss section of the executable. There will be
2041 an entry for this symbol in the .dynsym section. The dynamic
2042 object will contain position independent code, so all references
2043 from the dynamic object to this symbol will go through the global
2044 offset table. The dynamic linker will use the .dynsym entry to
2045 determine the address it must put in the global offset table, so
2046 both the dynamic object and the regular object will refer to the
2047 same memory location for the variable. */
2049 htab
= m32r_elf_hash_table (info
);
2051 BFD_ASSERT (s
!= NULL
);
2053 /* We must generate a R_M32R_COPY reloc to tell the dynamic linker
2054 to copy the initial value out of the dynamic object and into the
2055 runtime process image. We need to remember the offset into the
2056 .rela.bss section we are going to use. */
2057 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2061 srel
= htab
->srelbss
;
2062 BFD_ASSERT (srel
!= NULL
);
2063 srel
->size
+= sizeof (Elf32_External_Rela
);
2067 /* We need to figure out the alignment required for this symbol. I
2068 have no idea how ELF linkers handle this. */
2069 power_of_two
= bfd_log2 (h
->size
);
2070 if (power_of_two
> 3)
2073 /* Apply the required alignment. */
2074 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
2075 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2077 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2081 /* Define the symbol as being at this point in the section. */
2082 h
->root
.u
.def
.section
= s
;
2083 h
->root
.u
.def
.value
= s
->size
;
2085 /* Increment the section size to make room for the symbol. */
2091 /* Allocate space in .plt, .got and associated reloc sections for
2095 allocate_dynrelocs (h
, inf
)
2096 struct elf_link_hash_entry
*h
;
2099 struct bfd_link_info
*info
;
2100 struct elf_m32r_link_hash_table
*htab
;
2101 struct elf_m32r_link_hash_entry
*eh
;
2102 struct elf_m32r_dyn_relocs
*p
;
2104 if (h
->root
.type
== bfd_link_hash_indirect
)
2107 if (h
->root
.type
== bfd_link_hash_warning
)
2108 /* When warning symbols are created, they **replace** the "real"
2109 entry in the hash table, thus we never get to see the real
2110 symbol in a hash traversal. So look at it now. */
2111 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2113 info
= (struct bfd_link_info
*) inf
;
2114 htab
= m32r_elf_hash_table (info
);
2116 eh
= (struct elf_m32r_link_hash_entry
*) h
;
2117 // if ((h->got.refcount > 0
2118 // || h->forced_local)
2119 // && eh->gotplt_refcount > 0)
2121 // /* The symbol has been forced local, or we have some direct got refs,
2122 // so treat all the gotplt refs as got refs. */
2123 // h->got.refcount += eh->gotplt_refcount;
2124 // if (h->plt.refcount >= eh->gotplt_refcount)
2125 // h->plt.refcount -= eh->gotplt_refcount;
2128 if (htab
->root
.dynamic_sections_created
2129 && h
->plt
.refcount
> 0)
2131 /* Make sure this symbol is output as a dynamic symbol.
2132 Undefined weak syms won't yet be marked as dynamic. */
2133 if (h
->dynindx
== -1
2134 && !h
->forced_local
)
2136 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2140 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
2142 asection
*s
= htab
->splt
;
2144 /* If this is the first .plt entry, make room for the special
2147 s
->size
+= PLT_ENTRY_SIZE
;
2149 h
->plt
.offset
= s
->size
;
2151 /* If this symbol is not defined in a regular file, and we are
2152 not generating a shared library, then set the symbol to this
2153 location in the .plt. This is required to make function
2154 pointers compare as equal between the normal executable and
2155 the shared library. */
2159 h
->root
.u
.def
.section
= s
;
2160 h
->root
.u
.def
.value
= h
->plt
.offset
;
2163 /* Make room for this entry. */
2164 s
->size
+= PLT_ENTRY_SIZE
;
2166 /* We also need to make an entry in the .got.plt section, which
2167 will be placed in the .got section by the linker script. */
2168 htab
->sgotplt
->size
+= 4;
2170 /* We also need to make an entry in the .rel.plt section. */
2171 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
2175 h
->plt
.offset
= (bfd_vma
) -1;
2181 h
->plt
.offset
= (bfd_vma
) -1;
2185 if (h
->got
.refcount
> 0)
2190 /* Make sure this symbol is output as a dynamic symbol.
2191 Undefined weak syms won't yet be marked as dynamic. */
2192 if (h
->dynindx
== -1
2193 && !h
->forced_local
)
2195 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2201 h
->got
.offset
= s
->size
;
2203 dyn
= htab
->root
.dynamic_sections_created
;
2204 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
2205 htab
->srelgot
->size
+= sizeof (Elf32_External_Rela
);
2208 h
->got
.offset
= (bfd_vma
) -1;
2210 if (eh
->dyn_relocs
== NULL
)
2213 /* In the shared -Bsymbolic case, discard space allocated for
2214 dynamic pc-relative relocs against symbols which turn out to be
2215 defined in regular objects. For the normal shared case, discard
2216 space for pc-relative relocs that have become local due to symbol
2217 visibility changes. */
2225 struct elf_m32r_dyn_relocs
**pp
;
2226 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2228 p
->count
-= p
->pc_count
;
2239 /* For the non-shared case, discard space for relocs against
2240 symbols which turn out to need copy relocs or are not
2246 || (htab
->root
.dynamic_sections_created
2247 && (h
->root
.type
== bfd_link_hash_undefweak
2248 || h
->root
.type
== bfd_link_hash_undefined
))))
2250 /* Make sure this symbol is output as a dynamic symbol.
2251 Undefined weak syms won't yet be marked as dynamic. */
2252 if (h
->dynindx
== -1
2253 && !h
->forced_local
)
2255 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2259 /* If that succeeded, we know we'll be keeping all the
2261 if (h
->dynindx
!= -1)
2265 eh
->dyn_relocs
= NULL
;
2270 /* Finally, allocate space. */
2271 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2273 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2274 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
2279 /* Find any dynamic relocs that apply to read-only sections. */
2282 readonly_dynrelocs (h
, inf
)
2283 struct elf_link_hash_entry
*h
;
2286 struct elf_m32r_link_hash_entry
*eh
;
2287 struct elf_m32r_dyn_relocs
*p
;
2289 if (h
->root
.type
== bfd_link_hash_warning
)
2290 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2292 eh
= (struct elf_m32r_link_hash_entry
*) h
;
2293 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2295 asection
*s
= p
->sec
->output_section
;
2297 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2299 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2301 info
->flags
|= DF_TEXTREL
;
2303 /* Not an error, just cut short the traversal. */
2310 /* Set the sizes of the dynamic sections. */
2313 m32r_elf_size_dynamic_sections (output_bfd
, info
)
2314 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2315 struct bfd_link_info
*info
;
2317 struct elf_m32r_link_hash_table
*htab
;
2324 printf("m32r_elf_size_dynamic_sections()\n");
2327 htab
= m32r_elf_hash_table (info
);
2328 dynobj
= htab
->root
.dynobj
;
2329 BFD_ASSERT (dynobj
!= NULL
);
2331 if (htab
->root
.dynamic_sections_created
)
2333 /* Set the contents of the .interp section to the interpreter. */
2336 s
= bfd_get_section_by_name (dynobj
, ".interp");
2337 BFD_ASSERT (s
!= NULL
);
2338 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2339 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2343 /* Set up .got offsets for local syms, and space for local dynamic
2345 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2347 bfd_signed_vma
*local_got
;
2348 bfd_signed_vma
*end_local_got
;
2349 bfd_size_type locsymcount
;
2350 Elf_Internal_Shdr
*symtab_hdr
;
2353 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2356 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2358 struct elf_m32r_dyn_relocs
*p
;
2360 for (p
= ((struct elf_m32r_dyn_relocs
*)
2361 elf_section_data (s
)->local_dynrel
);
2365 if (! bfd_is_abs_section (p
->sec
)
2366 && bfd_is_abs_section (p
->sec
->output_section
))
2368 /* Input section has been discarded, either because
2369 it is a copy of a linkonce section or due to
2370 linker script /DISCARD/, so we'll be discarding
2373 else if (p
->count
!= 0)
2375 srel
= elf_section_data (p
->sec
)->sreloc
;
2376 srel
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
2377 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
2378 info
->flags
|= DF_TEXTREL
;
2383 local_got
= elf_local_got_refcounts (ibfd
);
2387 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2388 locsymcount
= symtab_hdr
->sh_info
;
2389 end_local_got
= local_got
+ locsymcount
;
2391 srel
= htab
->srelgot
;
2392 for (; local_got
< end_local_got
; ++local_got
)
2396 *local_got
= s
->size
;
2399 srel
->size
+= sizeof (Elf32_External_Rela
);
2402 *local_got
= (bfd_vma
) -1;
2406 /* Allocate global sym .plt and .got entries, and space for global
2407 sym dynamic relocs. */
2408 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
2410 /* We now have determined the sizes of the various dynamic sections.
2411 Allocate memory for them. */
2413 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2415 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2420 || s
== htab
->sgotplt
)
2422 /* Strip this section if we don't need it; see the
2425 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
2427 if (s
->size
!= 0 && s
!= htab
->srelplt
)
2430 /* We use the reloc_count field as a counter if we need
2431 to copy relocs into the output file. */
2436 /* It's not one of our sections, so don't allocate space. */
2442 /* If we don't need this section, strip it from the
2443 output file. This is mostly to handle .rela.bss and
2444 .rela.plt. We must create both sections in
2445 create_dynamic_sections, because they must be created
2446 before the linker maps input sections to output
2447 sections. The linker does that before
2448 adjust_dynamic_symbol is called, and it is that
2449 function which decides whether anything needs to go
2450 into these sections. */
2451 _bfd_strip_section_from_output (info
, s
);
2455 /* Allocate memory for the section contents. We use bfd_zalloc
2456 here in case unused entries are not reclaimed before the
2457 section's contents are written out. This should not happen,
2458 but this way if it does, we get a R_M32R_NONE reloc instead
2460 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2461 if (s
->contents
== NULL
)
2465 if (htab
->root
.dynamic_sections_created
)
2467 /* Add some entries to the .dynamic section. We fill in the
2468 values later, in m32r_elf_finish_dynamic_sections, but we
2469 must add the entries now so that we get the correct size for
2470 the .dynamic section. The DT_DEBUG entry is filled in by the
2471 dynamic linker and used by the debugger. */
2472 #define add_dynamic_entry(TAG, VAL) \
2473 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2477 if (! add_dynamic_entry (DT_DEBUG
, 0))
2481 if (htab
->splt
->size
!= 0)
2483 if (! add_dynamic_entry (DT_PLTGOT
, 0)
2484 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
2485 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2486 || ! add_dynamic_entry (DT_JMPREL
, 0))
2492 if (! add_dynamic_entry (DT_RELA
, 0)
2493 || ! add_dynamic_entry (DT_RELASZ
, 0)
2494 || ! add_dynamic_entry (DT_RELAENT
,
2495 sizeof (Elf32_External_Rela
)))
2498 /* If any dynamic relocs apply to a read-only section,
2499 then we need a DT_TEXTREL entry. */
2500 if ((info
->flags
& DF_TEXTREL
) == 0)
2501 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
,
2504 if ((info
->flags
& DF_TEXTREL
) != 0)
2506 if (! add_dynamic_entry (DT_TEXTREL
, 0))
2511 #undef add_dynamic_entry
2515 /* Relocate an M32R/D ELF section.
2516 There is some attempt to make this function usable for many architectures,
2517 both for RELA and REL type relocs, if only to serve as a learning tool.
2519 The RELOCATE_SECTION function is called by the new ELF backend linker
2520 to handle the relocations for a section.
2522 The relocs are always passed as Rela structures; if the section
2523 actually uses Rel structures, the r_addend field will always be
2526 This function is responsible for adjust the section contents as
2527 necessary, and (if using Rela relocs and generating a
2528 relocatable output file) adjusting the reloc addend as
2531 This function does not have to worry about setting the reloc
2532 address or the reloc symbol index.
2534 LOCAL_SYMS is a pointer to the swapped in local symbols.
2536 LOCAL_SECTIONS is an array giving the section in the input file
2537 corresponding to the st_shndx field of each local symbol.
2539 The global hash table entry for the global symbols can be found
2540 via elf_sym_hashes (input_bfd).
2542 When generating relocatable output, this function must handle
2543 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2544 going to be the section symbol corresponding to the output
2545 section, which means that the addend must be adjusted
2549 m32r_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2550 contents
, relocs
, local_syms
, local_sections
)
2551 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2552 struct bfd_link_info
*info
;
2554 asection
*input_section
;
2556 Elf_Internal_Rela
*relocs
;
2557 Elf_Internal_Sym
*local_syms
;
2558 asection
**local_sections
;
2560 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2561 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2562 Elf_Internal_Rela
*rel
, *relend
;
2563 /* Assume success. */
2564 bfd_boolean ret
= TRUE
;
2566 struct elf_m32r_link_hash_table
*htab
= m32r_elf_hash_table (info
);
2568 bfd_vma
*local_got_offsets
;
2569 asection
*sgot
, *splt
, *sreloc
;
2570 bfd_vma high_address
= bfd_get_section_limit (input_bfd
, input_section
);
2572 dynobj
= htab
->root
.dynobj
;
2573 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2580 relend
= relocs
+ input_section
->reloc_count
;
2581 for (; rel
< relend
; rel
++)
2584 reloc_howto_type
*howto
;
2585 unsigned long r_symndx
;
2586 struct elf_link_hash_entry
*h
;
2587 /* We can't modify r_addend here as elf_link_input_bfd has an assert to
2588 ensure it's zero (we use REL relocs, not RELA). Therefore this
2589 should be assigning zero to `addend', but for clarity we use
2591 bfd_vma addend
= rel
->r_addend
;
2592 bfd_vma offset
= rel
->r_offset
;
2593 Elf_Internal_Sym
*sym
;
2595 const char *sym_name
;
2596 bfd_reloc_status_type r
;
2597 const char *errmsg
= NULL
;
2598 bfd_boolean use_rel
= FALSE
;
2601 r_type
= ELF32_R_TYPE (rel
->r_info
);
2602 if (r_type
< 0 || r_type
>= (int) R_M32R_max
)
2604 (*_bfd_error_handler
) (_("%B: unknown relocation type %d"),
2607 bfd_set_error (bfd_error_bad_value
);
2612 if (r_type
== R_M32R_GNU_VTENTRY
2613 || r_type
== R_M32R_GNU_VTINHERIT
2614 || r_type
== R_M32R_NONE
2615 || r_type
== R_M32R_RELA_GNU_VTENTRY
2616 || r_type
== R_M32R_RELA_GNU_VTINHERIT
)
2619 if (r_type
<= R_M32R_GNU_VTENTRY
)
2622 howto
= m32r_elf_howto_table
+ r_type
;
2623 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2625 if (info
->relocatable
&& use_rel
)
2627 /* This is a relocatable link. We don't have to change
2628 anything, unless the reloc is against a section symbol,
2629 in which case we have to adjust according to where the
2630 section symbol winds up in the output section. */
2632 if (r_symndx
>= symtab_hdr
->sh_info
)
2634 /* External symbol. */
2639 sym
= local_syms
+ r_symndx
;
2640 sym_name
= "<local symbol>";
2641 /* STT_SECTION: symbol is associated with a section. */
2642 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
2644 /* Symbol isn't associated with a section. Nothing to do. */
2648 sec
= local_sections
[r_symndx
];
2649 addend
+= sec
->output_offset
+ sym
->st_value
;
2651 /* If partial_inplace, we need to store any additional addend
2652 back in the section. */
2653 if (! howto
->partial_inplace
)
2655 /* ??? Here is a nice place to call a special_function
2657 if (r_type
!= R_M32R_HI16_SLO
&& r_type
!= R_M32R_HI16_ULO
)
2658 r
= _bfd_relocate_contents (howto
, input_bfd
,
2659 addend
, contents
+ offset
);
2662 Elf_Internal_Rela
*lorel
;
2664 /* We allow an arbitrary number of HI16 relocs before the
2665 LO16 reloc. This permits gcc to emit the HI and LO relocs
2667 for (lorel
= rel
+ 1;
2669 && (ELF32_R_TYPE (lorel
->r_info
) == R_M32R_HI16_SLO
2670 || ELF32_R_TYPE (lorel
->r_info
) == R_M32R_HI16_ULO
));
2674 && ELF32_R_TYPE (lorel
->r_info
) == R_M32R_LO16
)
2676 m32r_elf_relocate_hi16 (input_bfd
, r_type
, rel
, lorel
,
2681 r
= _bfd_relocate_contents (howto
, input_bfd
,
2682 addend
, contents
+ offset
);
2689 /* This is a final link. */
2694 if (r_symndx
< symtab_hdr
->sh_info
)
2697 sym
= local_syms
+ r_symndx
;
2698 sec
= local_sections
[r_symndx
];
2699 sym_name
= "<local symbol>";
2703 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
2704 addend
= rel
->r_addend
;
2706 if (info
->relocatable
)
2708 /* This is a relocatable link. We don't have to change
2709 anything, unless the reloc is against a section symbol,
2710 in which case we have to adjust according to where the
2711 section symbol winds up in the output section. */
2712 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2713 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2720 relocation
= (sec
->output_section
->vma
2721 + sec
->output_offset
2727 /* External symbol. */
2728 if (info
->relocatable
&& !use_rel
)
2731 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2732 while (h
->root
.type
== bfd_link_hash_indirect
2733 || h
->root
.type
== bfd_link_hash_warning
)
2734 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2735 sym_name
= h
->root
.root
.string
;
2737 if (h
->root
.type
== bfd_link_hash_defined
2738 || h
->root
.type
== bfd_link_hash_defweak
)
2741 sec
= h
->root
.u
.def
.section
;
2743 dyn
= htab
->root
.dynamic_sections_created
;
2744 sec
= h
->root
.u
.def
.section
;
2745 if (r_type
== R_M32R_GOTPC24
2746 || (r_type
== R_M32R_GOTPC_HI_ULO
2747 || r_type
== R_M32R_GOTPC_HI_SLO
2748 || r_type
== R_M32R_GOTPC_LO
)
2749 || (r_type
== R_M32R_26_PLTREL
2750 && h
->plt
.offset
!= (bfd_vma
) -1)
2751 || ((r_type
== R_M32R_GOT24
2752 || r_type
== R_M32R_GOT16_HI_ULO
2753 || r_type
== R_M32R_GOT16_HI_SLO
2754 || r_type
== R_M32R_GOT16_LO
)
2755 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
,
2758 || (! info
->symbolic
&& h
->dynindx
!= -1)
2759 || !h
->def_regular
))
2761 && ((! info
->symbolic
&& h
->dynindx
!= -1)
2763 && (((r_type
== R_M32R_16_RELA
2764 || r_type
== R_M32R_32_RELA
2765 || r_type
== R_M32R_24_RELA
2766 || r_type
== R_M32R_HI16_ULO_RELA
2767 || r_type
== R_M32R_HI16_SLO_RELA
2768 || r_type
== R_M32R_LO16_RELA
)
2769 && !h
->forced_local
)
2770 || r_type
== R_M32R_10_PCREL_RELA
2771 || r_type
== R_M32R_18_PCREL_RELA
2772 || r_type
== R_M32R_26_PCREL_RELA
)
2773 && ((input_section
->flags
& SEC_ALLOC
) != 0
2774 /* DWARF will emit R_M32R_16(24,32) relocations
2775 in its sections against symbols defined
2776 externally in shared libraries. We can't do
2777 anything with them here. */
2778 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
2779 && h
->def_dynamic
))))
2781 /* In these cases, we don't need the relocation
2782 value. We check specially because in some
2783 obscure cases sec->output_section will be NULL. */
2786 else if (sec
->output_section
== NULL
)
2788 (*_bfd_error_handler
)
2789 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
2790 bfd_get_filename (input_bfd
), h
->root
.root
.string
,
2791 bfd_get_section_name (input_bfd
, input_section
));
2796 relocation
= (h
->root
.u
.def
.value
2797 + sec
->output_section
->vma
2798 + sec
->output_offset
);
2800 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2802 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
2803 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2807 if (! ((*info
->callbacks
->undefined_symbol
)
2808 (info
, h
->root
.root
.string
, input_bfd
,
2809 input_section
, offset
,
2810 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
2811 || ELF_ST_VISIBILITY (h
->other
)))))
2817 /* Sanity check the address. */
2818 if (offset
> high_address
)
2820 r
= bfd_reloc_outofrange
;
2824 switch ((int) r_type
)
2827 /* Relocation is relative to the start of the global offset
2828 table (for ld24 rx, #uimm24). eg access at label+addend
2830 ld24 rx. #label@GOTOFF + addend
2833 BFD_ASSERT (sgot
!= NULL
);
2835 relocation
= -(relocation
- sgot
->output_section
->vma
);
2836 rel
->r_addend
= -rel
->r_addend
;
2839 case R_M32R_GOTOFF_HI_ULO
:
2840 case R_M32R_GOTOFF_HI_SLO
:
2841 case R_M32R_GOTOFF_LO
:
2842 BFD_ASSERT (sgot
!= NULL
);
2844 relocation
-= sgot
->output_section
->vma
;
2846 if ((r_type
== R_M32R_GOTOFF_HI_SLO
)
2847 && ((relocation
+ rel
->r_addend
) & 0x8000))
2848 rel
->r_addend
+= 0x10000;
2851 case R_M32R_GOTPC24
:
2852 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2853 ld24 rx,#_GLOBAL_OFFSET_TABLE_
2855 relocation
= sgot
->output_section
->vma
;
2858 case R_M32R_GOTPC_HI_ULO
:
2859 case R_M32R_GOTPC_HI_SLO
:
2860 case R_M32R_GOTPC_LO
:
2862 /* .got(_GLOBAL_OFFSET_TABLE_) - pc relocation
2864 seth rx,#high(_GLOBAL_OFFSET_TABLE_)
2865 or3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2868 seth rx,#shigh(_GLOBAL_OFFSET_TABLE_)
2869 add3 rx,rx,#low(_GLOBAL_OFFSET_TABLE_ +4)
2871 relocation
= sgot
->output_section
->vma
;
2872 relocation
-= (input_section
->output_section
->vma
2873 + input_section
->output_offset
2875 if ((r_type
== R_M32R_GOTPC_HI_SLO
)
2876 && ((relocation
+ rel
->r_addend
) & 0x8000))
2877 rel
->r_addend
+= 0x10000;
2881 case R_M32R_GOT16_HI_ULO
:
2882 case R_M32R_GOT16_HI_SLO
:
2883 case R_M32R_GOT16_LO
:
2886 /* Relocation is to the entry for this symbol in the global
2888 BFD_ASSERT (sgot
!= NULL
);
2895 off
= h
->got
.offset
;
2896 BFD_ASSERT (off
!= (bfd_vma
) -1);
2898 dyn
= htab
->root
.dynamic_sections_created
;
2899 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2906 /* This is actually a static link, or it is a
2907 -Bsymbolic link and the symbol is defined
2908 locally, or the symbol was forced to be local
2909 because of a version file. We must initialize
2910 this entry in the global offset table. Since the
2911 offset must always be a multiple of 4, we use the
2912 least significant bit to record whether we have
2913 initialized it already.
2915 When doing a dynamic link, we create a .rela.got
2916 relocation entry to initialize the value. This
2917 is done in the finish_dynamic_symbol routine. */
2922 bfd_put_32 (output_bfd
, relocation
,
2923 sgot
->contents
+ off
);
2928 relocation
= sgot
->output_offset
+ off
;
2935 BFD_ASSERT (local_got_offsets
!= NULL
2936 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
2938 off
= local_got_offsets
[r_symndx
];
2940 /* The offset must always be a multiple of 4. We use
2941 the least significant bit to record whether we have
2942 already processed this entry. */
2947 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
2952 Elf_Internal_Rela outrel
;
2954 /* We need to generate a R_M32R_RELATIVE reloc
2955 for the dynamic linker. */
2956 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2957 BFD_ASSERT (srelgot
!= NULL
);
2959 outrel
.r_offset
= (sgot
->output_section
->vma
2960 + sgot
->output_offset
2962 outrel
.r_info
= ELF32_R_INFO (0, R_M32R_RELATIVE
);
2963 outrel
.r_addend
= relocation
;
2964 loc
= srelgot
->contents
;
2965 loc
+= srelgot
->reloc_count
* sizeof(Elf32_External_Rela
);
2966 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,loc
);
2967 ++srelgot
->reloc_count
;
2970 local_got_offsets
[r_symndx
] |= 1;
2973 relocation
= sgot
->output_offset
+ off
;
2975 if ((r_type
== R_M32R_GOT16_HI_SLO
)
2976 && ((relocation
+ rel
->r_addend
) & 0x8000))
2977 rel
->r_addend
+= 0x10000;
2981 case R_M32R_26_PLTREL
:
2982 /* Relocation is to the entry for this symbol in the
2983 procedure linkage table. */
2985 /* The native assembler will generate a 26_PLTREL reloc
2986 for a local symbol if you assemble a call from one
2987 section to another when using -K pic. */
2991 //if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2992 // || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
2994 if (h
->forced_local
)
2997 if (h
->plt
.offset
== (bfd_vma
) -1)
2999 /* We didn't make a PLT entry for this symbol. This
3000 happens when statically linking PIC code, or when
3001 using -Bsymbolic. */
3005 relocation
= (splt
->output_section
->vma
3006 + splt
->output_offset
3010 case R_M32R_HI16_SLO_RELA
:
3012 if ((relocation
+ rel
->r_addend
) & 0x8000)
3014 rel
->r_addend
+= 0x10000;
3018 case R_M32R_16_RELA
:
3019 case R_M32R_24_RELA
:
3020 case R_M32R_32_RELA
:
3021 case R_M32R_18_PCREL_RELA
:
3022 case R_M32R_26_PCREL_RELA
:
3023 case R_M32R_HI16_ULO_RELA
:
3024 case R_M32R_LO16_RELA
:
3027 && (input_section
->flags
& SEC_ALLOC
) != 0
3028 && ((r_type
!= R_M32R_18_PCREL_RELA
3029 && r_type
!= R_M32R_26_PCREL_RELA
)
3032 && (! info
->symbolic
3033 || !h
->def_regular
))))
3035 Elf_Internal_Rela outrel
;
3036 bfd_boolean skip
, relocate
;
3039 /* When generating a shared object, these relocations
3040 are copied into the output file to be resolved at run
3047 name
= (bfd_elf_string_from_elf_section
3049 elf_elfheader (input_bfd
)->e_shstrndx
,
3050 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3054 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3055 && strcmp (bfd_get_section_name (input_bfd
,
3059 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3060 BFD_ASSERT (sreloc
!= NULL
);
3066 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
3070 if (outrel
.r_offset
== (bfd_vma
) -1)
3072 else if (outrel
.r_offset
== (bfd_vma
) -2)
3073 skip
= TRUE
, relocate
= TRUE
;
3074 outrel
.r_offset
+= (input_section
->output_section
->vma
3075 + input_section
->output_offset
);
3078 memset (&outrel
, 0, sizeof outrel
);
3079 else if (r_type
== R_M32R_18_PCREL_RELA
3080 || r_type
== R_M32R_26_PCREL_RELA
)
3082 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
3083 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3084 outrel
.r_addend
= rel
->r_addend
;
3088 /* h->dynindx may be -1 if this symbol was marked to
3091 || ((info
->symbolic
|| h
->dynindx
== -1)
3095 outrel
.r_info
= ELF32_R_INFO (0, R_M32R_RELATIVE
);
3096 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3100 BFD_ASSERT (h
->dynindx
!= -1);
3101 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3102 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3106 loc
= sreloc
->contents
;
3107 loc
+= sreloc
->reloc_count
* sizeof(Elf32_External_Rela
);
3108 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,loc
);
3109 ++sreloc
->reloc_count
;
3111 /* If this reloc is against an external symbol, we do
3112 not want to fiddle with the addend. Otherwise, we
3113 need to include the symbol value so that it becomes
3114 an addend for the dynamic reloc. */
3120 case (int) R_M32R_10_PCREL
:
3121 r
= m32r_elf_do_10_pcrel_reloc (input_bfd
, howto
, input_section
,
3123 sec
, relocation
, addend
);
3126 case (int) R_M32R_HI16_SLO
:
3127 case (int) R_M32R_HI16_ULO
:
3129 Elf_Internal_Rela
*lorel
;
3131 /* We allow an arbitrary number of HI16 relocs before the
3132 LO16 reloc. This permits gcc to emit the HI and LO relocs
3134 for (lorel
= rel
+ 1;
3136 && (ELF32_R_TYPE (lorel
->r_info
) == R_M32R_HI16_SLO
3137 || ELF32_R_TYPE (lorel
->r_info
) == R_M32R_HI16_ULO
));
3141 && ELF32_R_TYPE (lorel
->r_info
) == R_M32R_LO16
)
3143 m32r_elf_relocate_hi16 (input_bfd
, r_type
, rel
, lorel
,
3144 contents
, relocation
+ addend
);
3148 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3150 relocation
, addend
);
3155 case (int) R_M32R_SDA16_RELA
:
3156 case (int) R_M32R_SDA16
:
3160 BFD_ASSERT (sec
!= NULL
);
3161 name
= bfd_get_section_name (abfd
, sec
);
3163 if (strcmp (name
, ".sdata") == 0
3164 || strcmp (name
, ".sbss") == 0
3165 || strcmp (name
, ".scommon") == 0)
3168 bfd
*out_bfd
= sec
->output_section
->owner
;
3170 r
= m32r_elf_final_sda_base (out_bfd
, info
,
3173 if (r
!= bfd_reloc_ok
)
3179 /* At this point `relocation' contains the object's
3181 relocation
-= sda_base
;
3182 /* Now it contains the offset from _SDA_BASE_. */
3186 (*_bfd_error_handler
)
3187 (_("%B: The target (%s) of an %s relocation is in the wrong section (%A)"),
3191 m32r_elf_howto_table
[(int) r_type
].name
);
3192 /*bfd_set_error (bfd_error_bad_value); ??? why? */
3199 default : /* OLD_M32R_RELOC */
3201 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3203 relocation
, addend
);
3207 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
3208 contents
, rel
->r_offset
,
3209 relocation
, rel
->r_addend
);
3215 if (r
!= bfd_reloc_ok
)
3217 /* FIXME: This should be generic enough to go in a utility. */
3221 name
= h
->root
.root
.string
;
3224 name
= (bfd_elf_string_from_elf_section
3225 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
3226 if (name
== NULL
|| *name
== '\0')
3227 name
= bfd_section_name (input_bfd
, sec
);
3235 case bfd_reloc_overflow
:
3236 if (! ((*info
->callbacks
->reloc_overflow
)
3237 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
3238 (bfd_vma
) 0, input_bfd
, input_section
, offset
)))
3242 case bfd_reloc_undefined
:
3243 if (! ((*info
->callbacks
->undefined_symbol
)
3244 (info
, name
, input_bfd
, input_section
,
3249 case bfd_reloc_outofrange
:
3250 errmsg
= _("internal error: out of range error");
3253 case bfd_reloc_notsupported
:
3254 errmsg
= _("internal error: unsupported relocation error");
3257 case bfd_reloc_dangerous
:
3258 errmsg
= _("internal error: dangerous error");
3262 errmsg
= _("internal error: unknown error");
3266 if (!((*info
->callbacks
->warning
)
3267 (info
, errmsg
, name
, input_bfd
, input_section
,
3278 /* Finish up dynamic symbol handling. We set the contents of various
3279 dynamic sections here. */
3281 m32r_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3283 struct bfd_link_info
*info
;
3284 struct elf_link_hash_entry
*h
;
3285 Elf_Internal_Sym
*sym
;
3287 struct elf_m32r_link_hash_table
*htab
;
3292 printf("m32r_elf_finish_dynamic_symbol()\n");
3295 htab
= m32r_elf_hash_table (info
);
3296 dynobj
= htab
->root
.dynobj
;
3298 if (h
->plt
.offset
!= (bfd_vma
) -1)
3306 Elf_Internal_Rela rela
;
3308 /* This symbol has an entry in the procedure linkage table. Set
3311 BFD_ASSERT (h
->dynindx
!= -1);
3314 sgot
= htab
->sgotplt
;
3315 srela
= htab
->srelplt
;
3316 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
3318 /* Get the index in the procedure linkage table which
3319 corresponds to this symbol. This is the index of this symbol
3320 in all the symbols for which we are making plt entries. The
3321 first entry in the procedure linkage table is reserved. */
3322 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
3324 /* Get the offset into the .got table of the entry that
3325 corresponds to this function. Each .got entry is 4 bytes.
3326 The first three are reserved. */
3327 got_offset
= (plt_index
+ 3) * 4;
3329 /* Fill in the entry in the procedure linkage table. */
3332 bfd_put_32 (output_bfd
,
3334 + (((sgot
->output_section
->vma
3335 + sgot
->output_offset
3336 + got_offset
) >> 16) & 0xffff)),
3337 splt
->contents
+ h
->plt
.offset
);
3338 bfd_put_32 (output_bfd
,
3340 + ((sgot
->output_section
->vma
3341 + sgot
->output_offset
3342 + got_offset
) & 0xffff)),
3343 splt
->contents
+ h
->plt
.offset
+ 4);
3344 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
3345 splt
->contents
+ h
->plt
.offset
+ 8);
3346 bfd_put_32 (output_bfd
,
3348 + plt_index
* sizeof (Elf32_External_Rela
)),
3349 splt
->contents
+ h
->plt
.offset
+ 12);
3350 bfd_put_32 (output_bfd
,
3352 + (((unsigned int) ((- (h
->plt
.offset
+ 16)) >> 2)) & 0xffffff)),
3353 splt
->contents
+ h
->plt
.offset
+ 16);
3357 bfd_put_32 (output_bfd
,
3358 PLT_ENTRY_WORD0
+ got_offset
,
3359 splt
->contents
+ h
->plt
.offset
);
3360 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD1
,
3361 splt
->contents
+ h
->plt
.offset
+ 4);
3362 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
3363 splt
->contents
+ h
->plt
.offset
+ 8);
3364 bfd_put_32 (output_bfd
,
3366 + plt_index
* sizeof (Elf32_External_Rela
)),
3367 splt
->contents
+ h
->plt
.offset
+ 12);
3368 bfd_put_32 (output_bfd
,
3370 + (((unsigned int) ((- (h
->plt
.offset
+ 16)) >> 2)) & 0xffffff)),
3371 splt
->contents
+ h
->plt
.offset
+ 16);
3374 /* Fill in the entry in the global offset table. */
3375 bfd_put_32 (output_bfd
,
3376 (splt
->output_section
->vma
3377 + splt
->output_offset
3379 + 12), /* same offset */
3380 sgot
->contents
+ got_offset
);
3382 /* Fill in the entry in the .rela.plt section. */
3383 rela
.r_offset
= (sgot
->output_section
->vma
3384 + sgot
->output_offset
3386 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_M32R_JMP_SLOT
);
3388 loc
= srela
->contents
;
3389 loc
+= plt_index
* sizeof(Elf32_External_Rela
);
3390 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3392 if (!h
->def_regular
)
3394 /* Mark the symbol as undefined, rather than as defined in
3395 the .plt section. Leave the value alone. */
3396 sym
->st_shndx
= SHN_UNDEF
;
3400 if (h
->got
.offset
!= (bfd_vma
) -1)
3404 Elf_Internal_Rela rela
;
3406 /* This symbol has an entry in the global offset table. Set it
3410 srela
= htab
->srelgot
;
3411 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
3413 rela
.r_offset
= (sgot
->output_section
->vma
3414 + sgot
->output_offset
3415 + (h
->got
.offset
&~ 1));
3417 /* If this is a -Bsymbolic link, and the symbol is defined
3418 locally, we just want to emit a RELATIVE reloc. Likewise if
3419 the symbol was forced to be local because of a version file.
3420 The entry in the global offset table will already have been
3421 initialized in the relocate_section function. */
3428 rela
.r_info
= ELF32_R_INFO (0, R_M32R_RELATIVE
);
3429 rela
.r_addend
= (h
->root
.u
.def
.value
3430 + h
->root
.u
.def
.section
->output_section
->vma
3431 + h
->root
.u
.def
.section
->output_offset
);
3435 BFD_ASSERT((h
->got
.offset
& 1) == 0);
3436 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3437 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_M32R_GLOB_DAT
);
3441 loc
= srela
->contents
;
3442 loc
+= srela
->reloc_count
* sizeof(Elf32_External_Rela
);
3443 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3444 ++srela
->reloc_count
;
3450 Elf_Internal_Rela rela
;
3452 /* This symbols needs a copy reloc. Set it up. */
3454 BFD_ASSERT (h
->dynindx
!= -1
3455 && (h
->root
.type
== bfd_link_hash_defined
3456 || h
->root
.type
== bfd_link_hash_defweak
));
3458 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3460 BFD_ASSERT (s
!= NULL
);
3462 rela
.r_offset
= (h
->root
.u
.def
.value
3463 + h
->root
.u
.def
.section
->output_section
->vma
3464 + h
->root
.u
.def
.section
->output_offset
);
3465 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_M32R_COPY
);
3468 loc
+= s
->reloc_count
* sizeof(Elf32_External_Rela
);
3469 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
3473 /* Mark some specially defined symbols as absolute. */
3474 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
3475 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3476 sym
->st_shndx
= SHN_ABS
;
3482 /* Finish up the dynamic sections. */
3485 m32r_elf_finish_dynamic_sections (output_bfd
, info
)
3487 struct bfd_link_info
*info
;
3489 struct elf_m32r_link_hash_table
*htab
;
3495 printf("m32r_elf_finish_dynamic_sections()\n");
3498 htab
= m32r_elf_hash_table (info
);
3499 dynobj
= htab
->root
.dynobj
;
3501 sgot
= htab
->sgotplt
;
3502 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3504 if (htab
->root
.dynamic_sections_created
)
3507 Elf32_External_Dyn
*dyncon
, *dynconend
;
3509 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
3511 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
3512 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
3514 for (; dyncon
< dynconend
; dyncon
++)
3516 Elf_Internal_Dyn dyn
;
3520 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3529 s
= htab
->sgot
->output_section
;
3533 s
= htab
->srelplt
->output_section
;
3535 BFD_ASSERT (s
!= NULL
);
3536 dyn
.d_un
.d_ptr
= s
->vma
;
3537 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3541 s
= htab
->srelplt
->output_section
;
3542 BFD_ASSERT (s
!= NULL
);
3543 dyn
.d_un
.d_val
= s
->size
;
3544 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3548 /* My reading of the SVR4 ABI indicates that the
3549 procedure linkage table relocs (DT_JMPREL) should be
3550 included in the overall relocs (DT_RELA). This is
3551 what Solaris does. However, UnixWare can not handle
3552 that case. Therefore, we override the DT_RELASZ entry
3553 here to make it not include the JMPREL relocs. Since
3554 the linker script arranges for .rela.plt to follow all
3555 other relocation sections, we don't have to worry
3556 about changing the DT_RELA entry. */
3557 if (htab
->srelplt
!= NULL
)
3559 s
= htab
->srelplt
->output_section
;
3560 dyn
.d_un
.d_val
-= s
->size
;
3562 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3567 /* Fill in the first entry in the procedure linkage table. */
3569 if (splt
&& splt
->size
> 0)
3573 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD0
, splt
->contents
);
3574 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD1
, splt
->contents
+ 4);
3575 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD2
, splt
->contents
+ 8);
3576 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD3
, splt
->contents
+ 12);
3577 bfd_put_32 (output_bfd
, PLT0_PIC_ENTRY_WORD4
, splt
->contents
+ 16);
3582 /* addr = .got + 4 */
3583 addr
= sgot
->output_section
->vma
+ sgot
->output_offset
+ 4;
3584 bfd_put_32 (output_bfd
,
3585 PLT0_ENTRY_WORD0
| ((addr
>> 16) & 0xffff),
3587 bfd_put_32 (output_bfd
,
3588 PLT0_ENTRY_WORD1
| (addr
& 0xffff),
3589 splt
->contents
+ 4);
3590 bfd_put_32 (output_bfd
, PLT0_ENTRY_WORD2
, splt
->contents
+ 8);
3591 bfd_put_32 (output_bfd
, PLT0_ENTRY_WORD3
, splt
->contents
+ 12);
3592 bfd_put_32 (output_bfd
, PLT0_ENTRY_WORD4
, splt
->contents
+ 16);
3595 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
3600 /* Fill in the first three entries in the global offset table. */
3601 if (sgot
&& sgot
->size
> 0)
3604 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
3606 bfd_put_32 (output_bfd
,
3607 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
3609 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
3610 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
3612 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
3619 /* Set the right machine number. */
3621 m32r_elf_object_p (abfd
)
3624 switch (elf_elfheader (abfd
)->e_flags
& EF_M32R_ARCH
)
3627 case E_M32R_ARCH
: (void) bfd_default_set_arch_mach (abfd
, bfd_arch_m32r
, bfd_mach_m32r
); break;
3628 case E_M32RX_ARCH
: (void) bfd_default_set_arch_mach (abfd
, bfd_arch_m32r
, bfd_mach_m32rx
); break;
3629 case E_M32R2_ARCH
: (void) bfd_default_set_arch_mach (abfd
, bfd_arch_m32r
, bfd_mach_m32r2
); break;
3634 /* Store the machine number in the flags field. */
3636 m32r_elf_final_write_processing (abfd
, linker
)
3638 bfd_boolean linker ATTRIBUTE_UNUSED
;
3642 switch (bfd_get_mach (abfd
))
3645 case bfd_mach_m32r
: val
= E_M32R_ARCH
; break;
3646 case bfd_mach_m32rx
: val
= E_M32RX_ARCH
; break;
3647 case bfd_mach_m32r2
: val
= E_M32R2_ARCH
; break;
3650 elf_elfheader (abfd
)->e_flags
&=~ EF_M32R_ARCH
;
3651 elf_elfheader (abfd
)->e_flags
|= val
;
3654 /* Function to keep M32R specific file flags. */
3656 m32r_elf_set_private_flags (abfd
, flags
)
3660 BFD_ASSERT (!elf_flags_init (abfd
)
3661 || elf_elfheader (abfd
)->e_flags
== flags
);
3663 elf_elfheader (abfd
)->e_flags
= flags
;
3664 elf_flags_init (abfd
) = TRUE
;
3668 /* Merge backend specific data from an object file to the output
3669 object file when linking. */
3671 m32r_elf_merge_private_bfd_data (ibfd
, obfd
)
3678 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3679 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3682 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3683 out_flags
= elf_elfheader (obfd
)->e_flags
;
3685 if (! elf_flags_init (obfd
))
3687 /* If the input is the default architecture then do not
3688 bother setting the flags for the output architecture,
3689 instead allow future merges to do this. If no future
3690 merges ever set these flags then they will retain their
3691 unitialised values, which surprise surprise, correspond
3692 to the default values. */
3693 if (bfd_get_arch_info (ibfd
)->the_default
)
3696 elf_flags_init (obfd
) = TRUE
;
3697 elf_elfheader (obfd
)->e_flags
= in_flags
;
3699 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3700 && bfd_get_arch_info (obfd
)->the_default
)
3702 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
3708 /* Check flag compatibility. */
3709 if (in_flags
== out_flags
)
3712 if ((in_flags
& EF_M32R_ARCH
) != (out_flags
& EF_M32R_ARCH
))
3714 if ( ((in_flags
& EF_M32R_ARCH
) != E_M32R_ARCH
)
3715 || ((out_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
3716 || ((in_flags
& EF_M32R_ARCH
) == E_M32R2_ARCH
))
3718 (*_bfd_error_handler
)
3719 (_("%B: Instruction set mismatch with previous modules"), ibfd
);
3721 bfd_set_error (bfd_error_bad_value
);
3729 /* Display the flags field */
3731 m32r_elf_print_private_bfd_data (abfd
, ptr
)
3735 FILE * file
= (FILE *) ptr
;
3737 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3739 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3741 fprintf (file
, _("private flags = %lx"), elf_elfheader (abfd
)->e_flags
);
3743 switch (elf_elfheader (abfd
)->e_flags
& EF_M32R_ARCH
)
3746 case E_M32R_ARCH
: fprintf (file
, _(": m32r instructions")); break;
3747 case E_M32RX_ARCH
: fprintf (file
, _(": m32rx instructions")); break;
3748 case E_M32R2_ARCH
: fprintf (file
, _(": m32r2 instructions")); break;
3757 m32r_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
3759 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3760 Elf_Internal_Rela
*rel
;
3761 struct elf_link_hash_entry
*h
;
3762 Elf_Internal_Sym
*sym
;
3766 switch (ELF32_R_TYPE (rel
->r_info
))
3768 case R_M32R_GNU_VTINHERIT
:
3769 case R_M32R_GNU_VTENTRY
:
3770 case R_M32R_RELA_GNU_VTINHERIT
:
3771 case R_M32R_RELA_GNU_VTENTRY
:
3775 switch (h
->root
.type
)
3777 case bfd_link_hash_defined
:
3778 case bfd_link_hash_defweak
:
3779 return h
->root
.u
.def
.section
;
3781 case bfd_link_hash_common
:
3782 return h
->root
.u
.c
.p
->section
;
3790 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3796 m32r_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
3797 bfd
*abfd ATTRIBUTE_UNUSED
;
3798 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3799 asection
*sec ATTRIBUTE_UNUSED
;
3800 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
3802 /* Update the got entry reference counts for the section being removed. */
3803 Elf_Internal_Shdr
*symtab_hdr
;
3804 struct elf_link_hash_entry
**sym_hashes
;
3805 bfd_signed_vma
*local_got_refcounts
;
3806 const Elf_Internal_Rela
*rel
, *relend
;
3808 elf_section_data (sec
)->local_dynrel
= NULL
;
3810 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3811 sym_hashes
= elf_sym_hashes (abfd
);
3812 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3814 relend
= relocs
+ sec
->reloc_count
;
3815 for (rel
= relocs
; rel
< relend
; rel
++)
3817 unsigned long r_symndx
;
3818 struct elf_link_hash_entry
*h
= NULL
;
3820 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3821 if (r_symndx
>= symtab_hdr
->sh_info
)
3823 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3824 while (h
->root
.type
== bfd_link_hash_indirect
3825 || h
->root
.type
== bfd_link_hash_warning
)
3826 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3829 switch (ELF32_R_TYPE (rel
->r_info
))
3831 case R_M32R_GOT16_HI_ULO
:
3832 case R_M32R_GOT16_HI_SLO
:
3833 case R_M32R_GOT16_LO
:
3835 case R_M32R_GOTOFF_HI_ULO
:
3836 case R_M32R_GOTOFF_HI_SLO
:
3837 case R_M32R_GOTOFF_LO
:
3839 case R_M32R_GOTPC_HI_ULO
:
3840 case R_M32R_GOTPC_HI_SLO
:
3841 case R_M32R_GOTPC_LO
:
3842 case R_M32R_GOTPC24
:
3845 if (h
->got
.refcount
> 0)
3850 if (local_got_refcounts
&& local_got_refcounts
[r_symndx
] > 0)
3851 local_got_refcounts
[r_symndx
]--;
3855 case R_M32R_16_RELA
:
3856 case R_M32R_24_RELA
:
3857 case R_M32R_32_RELA
:
3858 case R_M32R_HI16_ULO_RELA
:
3859 case R_M32R_HI16_SLO_RELA
:
3860 case R_M32R_LO16_RELA
:
3861 case R_M32R_SDA16_RELA
:
3862 case R_M32R_18_PCREL_RELA
:
3863 case R_M32R_26_PCREL_RELA
:
3866 struct elf_m32r_link_hash_entry
*eh
;
3867 struct elf_m32r_dyn_relocs
**pp
;
3868 struct elf_m32r_dyn_relocs
*p
;
3870 if (!info
->shared
&& h
->plt
.refcount
> 0)
3871 h
->plt
.refcount
-= 1;
3873 eh
= (struct elf_m32r_link_hash_entry
*) h
;
3875 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3878 if (ELF32_R_TYPE (rel
->r_info
) == R_M32R_26_PCREL_RELA
3879 || ELF32_R_TYPE (rel
->r_info
) == R_M32R_26_PCREL_RELA
)
3889 case R_M32R_26_PLTREL
:
3892 if (h
->plt
.refcount
> 0)
3905 /* Look through the relocs for a section during the first phase.
3906 Since we don't do .gots or .plts, we just need to consider the
3907 virtual table relocs for gc. */
3910 m32r_elf_check_relocs (abfd
, info
, sec
, relocs
)
3912 struct bfd_link_info
*info
;
3914 const Elf_Internal_Rela
*relocs
;
3916 Elf_Internal_Shdr
*symtab_hdr
;
3917 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
3918 const Elf_Internal_Rela
*rel
;
3919 const Elf_Internal_Rela
*rel_end
;
3920 struct elf_m32r_link_hash_table
*htab
;
3922 bfd_vma
*local_got_offsets
;
3923 asection
*sgot
, *srelgot
, *sreloc
;
3925 if (info
->relocatable
)
3928 sgot
= srelgot
= sreloc
= NULL
;
3930 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3931 sym_hashes
= elf_sym_hashes (abfd
);
3932 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
3933 if (!elf_bad_symtab (abfd
))
3934 sym_hashes_end
-= symtab_hdr
->sh_info
;
3936 htab
= m32r_elf_hash_table (info
);
3937 dynobj
= htab
->root
.dynobj
;
3938 local_got_offsets
= elf_local_got_offsets (abfd
);
3940 rel_end
= relocs
+ sec
->reloc_count
;
3941 for (rel
= relocs
; rel
< rel_end
; rel
++)
3944 struct elf_link_hash_entry
*h
;
3945 unsigned long r_symndx
;
3947 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3948 r_type
= ELF32_R_TYPE (rel
->r_info
);
3949 if (r_symndx
< symtab_hdr
->sh_info
)
3952 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3954 /* Some relocs require a global offset table. */
3955 if (htab
->sgot
== NULL
)
3959 case R_M32R_GOT16_HI_ULO
:
3960 case R_M32R_GOT16_HI_SLO
:
3962 case R_M32R_GOTOFF_HI_ULO
:
3963 case R_M32R_GOTOFF_HI_SLO
:
3964 case R_M32R_GOTOFF_LO
:
3965 case R_M32R_GOT16_LO
:
3966 case R_M32R_GOTPC24
:
3967 case R_M32R_GOTPC_HI_ULO
:
3968 case R_M32R_GOTPC_HI_SLO
:
3969 case R_M32R_GOTPC_LO
:
3972 htab
->root
.dynobj
= dynobj
= abfd
;
3973 if (! create_got_section (dynobj
, info
))
3984 case R_M32R_GOT16_HI_ULO
:
3985 case R_M32R_GOT16_HI_SLO
:
3986 case R_M32R_GOT16_LO
:
3990 h
->got
.refcount
+= 1;
3993 bfd_signed_vma
*local_got_refcounts
;
3995 /* This is a global offset table entry for a local
3997 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3998 if (local_got_refcounts
== NULL
)
4002 size
= symtab_hdr
->sh_info
;
4003 size
*= sizeof (bfd_signed_vma
);
4004 local_got_refcounts
= ((bfd_signed_vma
*)
4005 bfd_zalloc (abfd
, size
));
4006 if (local_got_refcounts
== NULL
)
4008 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
4010 local_got_refcounts
[r_symndx
] += 1;
4014 case R_M32R_26_PLTREL
:
4015 /* This symbol requires a procedure linkage table entry. We
4016 actually build the entry in adjust_dynamic_symbol,
4017 because this might be a case of linking PIC code without
4018 linking in any dynamic objects, in which case we don't
4019 need to generate a procedure linkage table after all. */
4021 /* If this is a local symbol, we resolve it directly without
4022 creating a procedure linkage table entry. */
4026 if (h
->forced_local
)
4030 h
->plt
.refcount
+= 1;
4033 case R_M32R_16_RELA
:
4034 case R_M32R_24_RELA
:
4035 case R_M32R_32_RELA
:
4036 case R_M32R_HI16_ULO_RELA
:
4037 case R_M32R_HI16_SLO_RELA
:
4038 case R_M32R_LO16_RELA
:
4039 case R_M32R_SDA16_RELA
:
4040 case R_M32R_18_PCREL_RELA
:
4041 case R_M32R_26_PCREL_RELA
:
4043 if (h
!= NULL
&& !info
->shared
)
4046 h
->plt
.refcount
+= 1;
4049 /* If we are creating a shared library, and this is a reloc
4050 against a global symbol, or a non PC relative reloc
4051 against a local symbol, then we need to copy the reloc
4052 into the shared library. However, if we are linking with
4053 -Bsymbolic, we do not need to copy a reloc against a
4054 global symbol which is defined in an object we are
4055 including in the link (i.e., DEF_REGULAR is set). At
4056 this point we have not seen all the input files, so it is
4057 possible that DEF_REGULAR is not set now but will be set
4058 later (it is never cleared). We account for that
4059 possibility below by storing information in the
4060 dyn_relocs field of the hash table entry. A similar
4061 situation occurs when creating shared libraries and symbol
4062 visibility changes render the symbol local.
4064 If on the other hand, we are creating an executable, we
4065 may need to keep relocations for symbols satisfied by a
4066 dynamic library if we manage to avoid copy relocs for the
4069 && (sec
->flags
& SEC_ALLOC
) != 0
4070 && ((r_type
!= R_M32R_26_PCREL_RELA
4071 && r_type
!= R_M32R_18_PCREL_RELA
)
4073 && (! info
->symbolic
4074 || h
->root
.type
== bfd_link_hash_defweak
4075 || !h
->def_regular
))))
4077 && (sec
->flags
& SEC_ALLOC
) != 0
4079 && (h
->root
.type
== bfd_link_hash_defweak
4080 || !h
->def_regular
)))
4082 struct elf_m32r_dyn_relocs
*p
;
4083 struct elf_m32r_dyn_relocs
**head
;
4086 htab
->root
.dynobj
= dynobj
= abfd
;
4088 /* When creating a shared object, we must copy these
4089 relocs into the output file. We create a reloc
4090 section in dynobj and make room for the reloc. */
4095 name
= (bfd_elf_string_from_elf_section
4097 elf_elfheader (abfd
)->e_shstrndx
,
4098 elf_section_data (sec
)->rel_hdr
.sh_name
));
4102 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4103 && strcmp (bfd_get_section_name (abfd
, sec
),
4106 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4111 sreloc
= bfd_make_section (dynobj
, name
);
4112 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4113 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4114 if ((sec
->flags
& SEC_ALLOC
) != 0)
4115 flags
|= SEC_ALLOC
| SEC_LOAD
;
4117 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
4118 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
4121 elf_section_data (sec
)->sreloc
= sreloc
;
4124 /* If this is a global symbol, we count the number of
4125 relocations we need for this symbol. */
4127 head
= &((struct elf_m32r_link_hash_entry
*) h
)->dyn_relocs
;
4132 /* Track dynamic relocs needed for local syms too. */
4133 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4138 head
= ((struct elf_m32r_dyn_relocs
**)
4139 &elf_section_data (s
)->local_dynrel
);
4143 if (p
== NULL
|| p
->sec
!= sec
)
4145 bfd_size_type amt
= sizeof (*p
);
4146 p
= ((struct elf_m32r_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
4157 if (ELF32_R_TYPE (rel
->r_info
) == R_M32R_26_PCREL_RELA
4158 || ELF32_R_TYPE (rel
->r_info
) == R_M32R_18_PCREL_RELA
)
4163 /* This relocation describes the C++ object vtable hierarchy.
4164 Reconstruct it for later use during GC. */
4165 case R_M32R_RELA_GNU_VTINHERIT
:
4166 case R_M32R_GNU_VTINHERIT
:
4167 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4171 /* This relocation describes which C++ vtable entries are actually
4172 used. Record for later use during GC. */
4173 case R_M32R_GNU_VTENTRY
:
4174 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
4177 case R_M32R_RELA_GNU_VTENTRY
:
4178 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4187 static struct bfd_elf_special_section
const m32r_elf_special_sections
[]=
4189 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
4190 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
4191 { NULL
, 0, 0, 0, 0 }
4195 m32r_elf_fake_sections (abfd
, hdr
, sec
)
4197 Elf_Internal_Shdr
*hdr ATTRIBUTE_UNUSED
;
4200 register const char *name
;
4202 name
= bfd_get_section_name (abfd
, sec
);
4204 /* The generic elf_fake_sections will set up REL_HDR using the
4205 default kind of relocations. But, we may actually need both
4206 kinds of relocations, so we set up the second header here.
4208 This is not necessary for the O32 ABI since that only uses Elf32_Rel
4209 relocations (cf. System V ABI, MIPS RISC Processor Supplement,
4210 3rd Edition, p. 4-17). It breaks the IRIX 5/6 32-bit ld, since one
4211 of the resulting empty .rela.<section> sections starts with
4212 sh_offset == object size, and ld doesn't allow that. While the check
4213 is arguably bogus for empty or SHT_NOBITS sections, it can easily be
4214 avoided by not emitting those useless sections in the first place. */
4215 if ((sec
->flags
& SEC_RELOC
) != 0)
4217 struct bfd_elf_section_data
*esd
;
4218 bfd_size_type amt
= sizeof (Elf_Internal_Shdr
);
4220 esd
= elf_section_data (sec
);
4221 BFD_ASSERT (esd
->rel_hdr2
== NULL
);
4222 esd
->rel_hdr2
= (Elf_Internal_Shdr
*) bfd_zalloc (abfd
, amt
);
4225 _bfd_elf_init_reloc_shdr (abfd
, esd
->rel_hdr2
, sec
,
4232 static enum elf_reloc_type_class
4233 m32r_elf_reloc_type_class (rela
)
4234 const Elf_Internal_Rela
*rela
;
4236 switch ((int) ELF32_R_TYPE (rela
->r_info
))
4238 case R_M32R_RELATIVE
:
4239 return reloc_class_relative
;
4240 case R_M32R_JMP_SLOT
:
4241 return reloc_class_plt
;
4243 return reloc_class_copy
;
4245 return reloc_class_normal
;
4249 #define ELF_ARCH bfd_arch_m32r
4250 #define ELF_MACHINE_CODE EM_M32R
4251 #define ELF_MACHINE_ALT1 EM_CYGNUS_M32R
4252 #define ELF_MAXPAGESIZE 0x1 /* Explicitly requested by Mitsubishi. */
4254 #define TARGET_BIG_SYM bfd_elf32_m32r_vec
4255 #define TARGET_BIG_NAME "elf32-m32r"
4256 #define TARGET_LITTLE_SYM bfd_elf32_m32rle_vec
4257 #define TARGET_LITTLE_NAME "elf32-m32rle"
4259 #define elf_info_to_howto m32r_info_to_howto
4260 #define elf_info_to_howto_rel m32r_info_to_howto_rel
4261 #define elf_backend_section_from_bfd_section _bfd_m32r_elf_section_from_bfd_section
4262 #define elf_backend_symbol_processing _bfd_m32r_elf_symbol_processing
4263 #define elf_backend_add_symbol_hook m32r_elf_add_symbol_hook
4264 #define elf_backend_relocate_section m32r_elf_relocate_section
4265 #define elf_backend_gc_mark_hook m32r_elf_gc_mark_hook
4266 #define elf_backend_gc_sweep_hook m32r_elf_gc_sweep_hook
4267 #define elf_backend_check_relocs m32r_elf_check_relocs
4269 #define elf_backend_create_dynamic_sections m32r_elf_create_dynamic_sections
4270 #define bfd_elf32_bfd_link_hash_table_create m32r_elf_link_hash_table_create
4271 #define elf_backend_size_dynamic_sections m32r_elf_size_dynamic_sections
4272 #define elf_backend_finish_dynamic_sections m32r_elf_finish_dynamic_sections
4273 #define elf_backend_adjust_dynamic_symbol m32r_elf_adjust_dynamic_symbol
4274 #define elf_backend_finish_dynamic_symbol m32r_elf_finish_dynamic_symbol
4275 #define elf_backend_reloc_type_class m32r_elf_reloc_type_class
4276 #define elf_backend_copy_indirect_symbol m32r_elf_copy_indirect_symbol
4278 #define elf_backend_can_gc_sections 1
4280 #define elf_backend_rela_normal 1
4282 #define elf_backend_can_refcount 1
4283 #define elf_backend_want_got_plt 1
4284 #define elf_backend_plt_readonly 1
4285 #define elf_backend_want_plt_sym 0
4286 #define elf_backend_got_header_size 12
4288 #define elf_backend_may_use_rel_p 1
4289 #ifdef USE_M32R_OLD_RELOC
4290 #define elf_backend_default_use_rela_p 0
4291 #define elf_backend_may_use_rela_p 0
4293 #define elf_backend_default_use_rela_p 1
4294 #define elf_backend_may_use_rela_p 1
4295 #define elf_backend_fake_sections m32r_elf_fake_sections
4298 #define elf_backend_object_p m32r_elf_object_p
4299 #define elf_backend_final_write_processing m32r_elf_final_write_processing
4300 #define bfd_elf32_bfd_merge_private_bfd_data m32r_elf_merge_private_bfd_data
4301 #define bfd_elf32_bfd_set_private_flags m32r_elf_set_private_flags
4302 #define bfd_elf32_bfd_print_private_bfd_data m32r_elf_print_private_bfd_data
4303 #define elf_backend_special_sections m32r_elf_special_sections
4305 #include "elf32-target.h"
4307 #undef ELF_MAXPAGESIZE
4308 #define ELF_MAXPAGESIZE 0x1000
4310 #undef TARGET_BIG_SYM
4311 #define TARGET_BIG_SYM bfd_elf32_m32rlin_vec
4312 #undef TARGET_BIG_NAME
4313 #define TARGET_BIG_NAME "elf32-m32r-linux"
4314 #undef TARGET_LITTLE_SYM
4315 #define TARGET_LITTLE_SYM bfd_elf32_m32rlelin_vec
4316 #undef TARGET_LITTLE_NAME
4317 #define TARGET_LITTLE_NAME "elf32-m32rle-linux"
4319 #define elf32_bed elf32_m32r_lin_bed
4321 #include "elf32-target.h"