]> Git Repo - binutils.git/blob - bfd/elf32-mn10300.c
* elf32-mn10300.c (mn10300_info_howto): Renamed from
[binutils.git] / bfd / elf32-mn10300.c
1 /* Matsushita 10300 specific support for 32-bit ELF
2    Copyright (C) 1996 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 #include "bfd.h"
21 #include "sysdep.h"
22 #include "libbfd.h"
23 #include "elf-bfd.h"
24
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 **));
31
32
33 /* We have to use RELA instructions since md_apply_fix3 in the assembler
34    does absolutely nothing.  */
35 #define USE_RELA
36
37 enum reloc_type
38 {
39   R_MN10300_NONE = 0,
40   R_MN10300_32,
41   R_MN10300_16,
42   R_MN10300_8,
43   R_MN10300_32B,
44   R_MN10300_16B,
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,
50   R_MN10300_MAX
51 };
52
53 static reloc_howto_type elf_mn10300_howto_table[] =
54 {
55   /* */
56   HOWTO (R_MN10300_NONE,
57          0,
58          2,
59          16,
60          false,
61          0,
62          complain_overflow_bitfield,
63          bfd_elf_generic_reloc,
64          "R_MN10300_NONE",
65          false,
66          0,
67          0,
68          false),
69   HOWTO (R_MN10300_32,
70          0,
71          2,
72          32,
73          false,
74          0,
75          complain_overflow_bitfield,
76          bfd_elf_generic_reloc,
77          "R_MN10300_32",
78          true,
79          0xffffffff,
80          0xffffffff,
81          false),
82   HOWTO (R_MN10300_16,
83          0,
84          1,
85          16,
86          false,
87          0,
88          complain_overflow_bitfield,
89          bfd_elf_generic_reloc,
90          "R_MN10300_16",
91          true,
92          0xffff,
93          0xffff,
94          false),
95   HOWTO (R_MN10300_8,
96          0,
97          0,
98          8,
99          false,
100          0,
101          complain_overflow_bitfield,
102          bfd_elf_generic_reloc,
103          "R_MN10300_8",
104          true,
105          0xff,
106          0xff,
107          false),
108   HOWTO (R_MN10300_32B,
109          0,
110          2,
111          32,
112          false,
113          0,
114          complain_overflow_bitfield,
115          bfd_elf32_mn10300_reloc,
116          "R_MN10300_32B",
117          true,
118          0xffffffff,
119          0xffffffff,
120          false),
121   HOWTO (R_MN10300_16B,
122          0,
123          1,
124          16,
125          false,
126          0,
127          complain_overflow_bitfield,
128          bfd_elf32_mn10300_reloc,
129          "R_MN10300_16B",
130          true,
131          0xffff,
132          0xffff,
133          false),
134   HOWTO (R_MN10300_PCREL32_1BYTE,
135          0,
136          2,
137          32,
138          true,
139          0,
140          complain_overflow_bitfield,
141          bfd_elf32_mn10300_reloc,
142          "R_MN10300_PCREL32_1BYTE",
143          true,
144          0xffffffff,
145          0xffffffff,
146          false),
147   HOWTO (R_MN10300_PCREL16_1BYTE,
148          0,
149          1,
150          16,
151          true,
152          0,
153          complain_overflow_bitfield,
154          bfd_elf32_mn10300_reloc,
155          "R_MN10300_PCREL16_1BYTE",
156          true,
157          0xffff,
158          0xffff,
159          false),
160   HOWTO (R_MN10300_PCREL8_1BYTE,
161          0,
162          0,
163          8,
164          true,
165          0,
166          complain_overflow_bitfield,
167          bfd_elf32_mn10300_reloc,
168          "R_MN10300_PCREL8_1BYTE",
169          true,
170          0xff,
171          0xff,
172          true),
173   HOWTO (R_MN10300_PCREL32_2BYTE,
174          0,
175          2,
176          32,
177          true,
178          0,
179          complain_overflow_bitfield,
180          bfd_elf32_mn10300_reloc,
181          "R_MN10300_PCREL32_2BYTE",
182          true,
183          0xffffffff,
184          0xffffffff,
185          true),
186   HOWTO (R_MN10300_PCREL16_2BYTE,
187          0,
188          1,
189          16,
190          true,
191          0,
192          complain_overflow_bitfield,
193          bfd_elf32_mn10300_reloc,
194          "R_MN10300_PCREL16_2BYTE",
195          true,
196          0xffff,
197          0xffff,
198          true),
199 };
200
201 struct mn10300_reloc_map
202 {
203   unsigned char bfd_reloc_val;
204   unsigned char elf_reloc_val;
205 };
206
207 static const struct mn10300_reloc_map mn10300_reloc_map[] =
208 {
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, },
220 };
221
222 static reloc_howto_type *
223 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
224      bfd *abfd;
225      bfd_reloc_code_real_type code;
226 {
227   unsigned int i;
228
229   for (i = 0;
230        i < sizeof (mn10300_reloc_map) / sizeof (struct mn10300_reloc_map);
231        i++)
232     {
233       if (mn10300_reloc_map[i].bfd_reloc_val == code)
234         return &elf_mn10300_howto_table[mn10300_reloc_map[i].elf_reloc_val];
235     }
236
237   return NULL;
238 }
239
240 /* Set the howto pointer for an MN10300 ELF reloc.  */
241
242 static void
243 mn10300_info_to_howto (abfd, cache_ptr, dst)
244      bfd *abfd;
245      arelent *cache_ptr;
246      Elf32_Internal_Rela *dst;
247 {
248   unsigned int r_type;
249
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];
253 }
254
255 static bfd_reloc_status_type
256 bfd_elf32_mn10300_reloc (abfd, reloc, symbol, data, isection, obfd, err)
257      bfd *abfd;
258      arelent *reloc;
259      asymbol *symbol;
260      PTR data;
261      asection *isection;
262      bfd *obfd;
263      char **err;
264 {
265   if (obfd != (bfd *) NULL
266       && (symbol->flags & BSF_SECTION_SYM) == 0
267       && (! reloc->howto->partial_inplace
268           || reloc->addend == 0))
269     {
270       reloc->address += isection->output_offset;
271       return bfd_reloc_ok;
272     }
273   else if (obfd != NULL)
274     {
275       return bfd_reloc_continue;
276     }
277
278   /* Catch relocs involving undefined symbols.  */
279   if (bfd_is_und_section (symbol->section)
280       && (symbol->flags & BSF_WEAK) == 0
281       && obfd == NULL)
282     return bfd_reloc_undefined;
283
284   /* We handle final linking of some relocs ourselves.  */
285     {
286       long relocation, insn;
287
288       /* Is the address of the relocation really within the section?  */
289       if (reloc->address > isection->_cooked_size)
290         return bfd_reloc_outofrange;
291
292       /* Work out which section the relocation is targetted at and the
293          initial relocation command value.  */
294
295       /* Get symbol value.  (Common symbols are special.)  */
296       if (bfd_is_com_section (symbol->section))
297         relocation = 0;
298       else
299         relocation = symbol->value;
300
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;
305
306       if (reloc->howto->pc_relative == true)
307         {
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;
311
312           /* Deal with pcrel_offset */
313           relocation -= reloc->address;
314
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)
318             relocation += 1;
319           else if (reloc->howto->type == R_MN10300_PCREL32_2BYTE
320               || reloc->howto->type == R_MN10300_PCREL16_2BYTE)
321             relocation += 2;
322         }
323
324       /* I've got no clue... */
325       reloc->addend = 0;        
326
327       if (reloc->howto->size == 0)
328         {
329           if (relocation > 0x7f || relocation < -0x80)
330             return bfd_reloc_overflow;
331
332           bfd_put_8 (abfd, relocation & 0xff,
333                      (bfd_byte *)data + reloc->address);
334         }
335       else if (reloc->howto->size == 1)
336         {
337           if (relocation > 0x7fff || relocation < -0x8000)
338             return bfd_reloc_overflow;
339
340           bfd_putb16 (relocation & 0xffff, (bfd_byte *)data + reloc->address);
341         }
342       else if (reloc->howto->size == 2)
343         bfd_putb32 (relocation, (bfd_byte *)data + reloc->address);
344       return bfd_reloc_ok;
345     }
346
347   return bfd_reloc_continue;
348 }
349
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
355
356 #define elf_info_to_howto       mn10300_info_to_howto
357 #define elf_info_to_howto_rel   0
358
359 #include "elf32-target.h"
This page took 0.046746 seconds and 4 git commands to generate.