1 /* Matsushita 10300 specific support for 32-bit ELF
2 Copyright (C) 1996 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
26 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
27 static void mn10300_info_to_howto
28 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
29 static bfd_reloc_status_type bfd_elf32_mn10300_reloc
30 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
33 /* We have to use RELA instructions since md_apply_fix3 in the assembler
34 does absolutely nothing. */
45 R_MN10300_PCREL32_1BYTE,
46 R_MN10300_PCREL16_1BYTE,
47 R_MN10300_PCREL8_1BYTE,
48 R_MN10300_PCREL32_2BYTE,
49 R_MN10300_PCREL16_2BYTE,
53 static reloc_howto_type elf_mn10300_howto_table[] =
56 HOWTO (R_MN10300_NONE,
62 complain_overflow_bitfield,
63 bfd_elf_generic_reloc,
75 complain_overflow_bitfield,
76 bfd_elf_generic_reloc,
88 complain_overflow_bitfield,
89 bfd_elf_generic_reloc,
101 complain_overflow_bitfield,
102 bfd_elf_generic_reloc,
108 HOWTO (R_MN10300_32B,
114 complain_overflow_bitfield,
115 bfd_elf32_mn10300_reloc,
121 HOWTO (R_MN10300_16B,
127 complain_overflow_bitfield,
128 bfd_elf32_mn10300_reloc,
134 HOWTO (R_MN10300_PCREL32_1BYTE,
140 complain_overflow_bitfield,
141 bfd_elf32_mn10300_reloc,
142 "R_MN10300_PCREL32_1BYTE",
147 HOWTO (R_MN10300_PCREL16_1BYTE,
153 complain_overflow_bitfield,
154 bfd_elf32_mn10300_reloc,
155 "R_MN10300_PCREL16_1BYTE",
160 HOWTO (R_MN10300_PCREL8_1BYTE,
166 complain_overflow_bitfield,
167 bfd_elf32_mn10300_reloc,
168 "R_MN10300_PCREL8_1BYTE",
173 HOWTO (R_MN10300_PCREL32_2BYTE,
179 complain_overflow_bitfield,
180 bfd_elf32_mn10300_reloc,
181 "R_MN10300_PCREL32_2BYTE",
186 HOWTO (R_MN10300_PCREL16_2BYTE,
192 complain_overflow_bitfield,
193 bfd_elf32_mn10300_reloc,
194 "R_MN10300_PCREL16_2BYTE",
201 struct mn10300_reloc_map
203 unsigned char bfd_reloc_val;
204 unsigned char elf_reloc_val;
207 static const struct mn10300_reloc_map mn10300_reloc_map[] =
209 { BFD_RELOC_NONE, R_MN10300_NONE, },
210 { BFD_RELOC_32, R_MN10300_32, },
211 { BFD_RELOC_16, R_MN10300_16, },
212 { BFD_RELOC_8, R_MN10300_8, },
213 { BFD_RELOC_MN10300_32B, R_MN10300_32B, },
214 { BFD_RELOC_MN10300_16B, R_MN10300_16B, },
215 { BFD_RELOC_32_PCREL, R_MN10300_PCREL32_1BYTE, },
216 { BFD_RELOC_16_PCREL, R_MN10300_PCREL16_1BYTE, },
217 { BFD_RELOC_8_PCREL, R_MN10300_PCREL8_1BYTE, },
218 { BFD_RELOC_MN10300_32_PCREL, R_MN10300_PCREL32_2BYTE, },
219 { BFD_RELOC_MN10300_16_PCREL, R_MN10300_PCREL16_2BYTE, },
222 static reloc_howto_type *
223 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
225 bfd_reloc_code_real_type code;
230 i < sizeof (mn10300_reloc_map) / sizeof (struct mn10300_reloc_map);
233 if (mn10300_reloc_map[i].bfd_reloc_val == code)
234 return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
240 /* Set the howto pointer for an MN10300 ELF reloc. */
243 mn10300_info_to_howto (abfd, cache_ptr, dst)
246 Elf32_Internal_Rela *dst;
250 r_type = ELF32_R_TYPE (dst->r_info);
251 BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX);
252 cache_ptr->howto = &elf_mn10300_howto_table[r_type];
255 static bfd_reloc_status_type
256 bfd_elf32_mn10300_reloc (abfd, reloc, symbol, data, isection, obfd, err)
265 if (obfd != (bfd *) NULL
266 && (symbol->flags & BSF_SECTION_SYM) == 0
267 && (! reloc->howto->partial_inplace
268 || reloc->addend == 0))
270 reloc->address += isection->output_offset;
273 else if (obfd != NULL)
275 return bfd_reloc_continue;
278 /* Catch relocs involving undefined symbols. */
279 if (bfd_is_und_section (symbol->section)
280 && (symbol->flags & BSF_WEAK) == 0
282 return bfd_reloc_undefined;
284 /* We handle final linking of some relocs ourselves. */
286 long relocation, insn;
288 /* Is the address of the relocation really within the section? */
289 if (reloc->address > isection->_cooked_size)
290 return bfd_reloc_outofrange;
292 /* Work out which section the relocation is targetted at and the
293 initial relocation command value. */
295 /* Get symbol value. (Common symbols are special.) */
296 if (bfd_is_com_section (symbol->section))
299 relocation = symbol->value;
301 /* Convert input-section-relative symbol value to absolute + addend. */
302 relocation += symbol->section->output_section->vma;
303 relocation += symbol->section->output_offset;
304 relocation += reloc->addend;
306 if (reloc->howto->pc_relative == true)
308 /* Here the variable relocation holds the final address of the
309 symbol we are relocating against, plus any addend. */
310 relocation -= isection->output_section->vma + isection->output_offset;
312 /* Deal with pcrel_offset */
313 relocation -= reloc->address;
315 if (reloc->howto->type == R_MN10300_PCREL32_1BYTE
316 || reloc->howto->type == R_MN10300_PCREL16_1BYTE
317 || reloc->howto->type == R_MN10300_PCREL8_1BYTE)
319 else if (reloc->howto->type == R_MN10300_PCREL32_2BYTE
320 || reloc->howto->type == R_MN10300_PCREL16_2BYTE)
324 /* I've got no clue... */
327 if (reloc->howto->size == 0)
329 if (relocation > 0x7f || relocation < -0x80)
330 return bfd_reloc_overflow;
332 bfd_put_8 (abfd, relocation & 0xff,
333 (bfd_byte *)data + reloc->address);
335 else if (reloc->howto->size == 1)
337 if (relocation > 0x7fff || relocation < -0x8000)
338 return bfd_reloc_overflow;
340 bfd_putb16 (relocation & 0xffff, (bfd_byte *)data + reloc->address);
342 else if (reloc->howto->size == 2)
343 bfd_putb32 (relocation, (bfd_byte *)data + reloc->address);
347 return bfd_reloc_continue;
350 #define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec
351 #define TARGET_LITTLE_NAME "elf32-mn10300"
352 #define ELF_ARCH bfd_arch_mn10300
353 #define ELF_MACHINE_CODE EM_CYGNUS_MN10300
354 #define ELF_MAXPAGESIZE 0x1000
356 #define elf_info_to_howto mn10300_info_to_howto
357 #define elf_info_to_howto_rel 0
359 #include "elf32-target.h"