* libbfd.c: Patch up the mmap code so that it is only built if BFD
[deliverable/binutils-gdb.git] / bfd / elf32-mn10200.c
1 /* Matsushita 10200 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 mn10200_info_to_howto
28 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
29 static bfd_reloc_status_type bfd_elf32_mn10200_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_MN10200_NONE = 0,
40 R_MN10200_32,
41 R_MN10200_16,
42 R_MN10200_8,
43 #if 0
44 R_MN10200_PCREL32_1BYTE,
45 R_MN10200_PCREL16_1BYTE,
46 R_MN10200_PCREL8_1BYTE,
47 R_MN10200_PCREL32_2BYTE,
48 R_MN10200_PCREL16_2BYTE,
49 #endif
50 R_MN10200_MAX
51 };
52
53 static reloc_howto_type elf_mn10200_howto_table[] =
54 {
55 /* Dummy relocation. Does nothing. */
56 HOWTO (R_MN10200_NONE,
57 0,
58 2,
59 16,
60 false,
61 0,
62 complain_overflow_bitfield,
63 bfd_elf_generic_reloc,
64 "R_MN10200_NONE",
65 false,
66 0,
67 0,
68 false),
69 /* Standard 32 bit reloc. */
70 HOWTO (R_MN10200_32,
71 0,
72 2,
73 32,
74 false,
75 0,
76 complain_overflow_bitfield,
77 bfd_elf_generic_reloc,
78 "R_MN10200_32",
79 false,
80 0xffffffff,
81 0xffffffff,
82 false),
83 /* Standard 16 bit reloc. */
84 HOWTO (R_MN10200_16,
85 0,
86 1,
87 16,
88 false,
89 0,
90 complain_overflow_bitfield,
91 bfd_elf_generic_reloc,
92 "R_MN10200_16",
93 false,
94 0xffff,
95 0xffff,
96 false),
97 /* Standard 8 bit reloc. */
98 HOWTO (R_MN10200_8,
99 0,
100 0,
101 8,
102 false,
103 0,
104 complain_overflow_bitfield,
105 bfd_elf_generic_reloc,
106 "R_MN10200_8",
107 false,
108 0xff,
109 0xff,
110 false),
111 #if 0
112 /* Simple 32bit pc-relative reloc with a 1 byte adjustment
113 to get the pc-relative offset correct. */
114 HOWTO (R_MN10200_PCREL32_1BYTE,
115 0,
116 2,
117 32,
118 true,
119 0,
120 complain_overflow_bitfield,
121 bfd_elf32_mn10200_reloc,
122 "R_MN10200_PCREL32_1BYTE",
123 true,
124 0xffffffff,
125 0xffffffff,
126 false),
127 /* Simple 16bit pc-relative reloc with a 1 byte adjustment
128 to get the pc-relative offset correct. */
129 HOWTO (R_MN10200_PCREL16_1BYTE,
130 0,
131 1,
132 16,
133 true,
134 0,
135 complain_overflow_bitfield,
136 bfd_elf32_mn10200_reloc,
137 "R_MN10200_PCREL16_1BYTE",
138 true,
139 0xffff,
140 0xffff,
141 false),
142 /* Simple 8 pc-relative reloc with a 1 byte adjustment
143 to get the pc-relative offset correct. */
144 HOWTO (R_MN10200_PCREL8_1BYTE,
145 0,
146 0,
147 8,
148 true,
149 0,
150 complain_overflow_bitfield,
151 bfd_elf32_mn10200_reloc,
152 "R_MN10200_PCREL8_1BYTE",
153 true,
154 0xff,
155 0xff,
156 true),
157 /* Simple 32 pc-relative reloc with a 2 byte adjustment
158 to get the pc-relative offset correct. */
159 HOWTO (R_MN10200_PCREL32_2BYTE,
160 0,
161 2,
162 32,
163 true,
164 0,
165 complain_overflow_bitfield,
166 bfd_elf32_mn10200_reloc,
167 "R_MN10200_PCREL32_2BYTE",
168 true,
169 0xffffffff,
170 0xffffffff,
171 true),
172 /* Simple 16 pc-relative reloc with a 2 byte adjustment
173 to get the pc-relative offset correct. */
174 HOWTO (R_MN10200_PCREL16_2BYTE,
175 0,
176 1,
177 16,
178 true,
179 0,
180 complain_overflow_bitfield,
181 bfd_elf32_mn10200_reloc,
182 "R_MN10200_PCREL16_2BYTE",
183 true,
184 0xffff,
185 0xffff,
186 true),
187 #endif
188 };
189
190 struct mn10200_reloc_map
191 {
192 unsigned char bfd_reloc_val;
193 unsigned char elf_reloc_val;
194 };
195
196 static const struct mn10200_reloc_map mn10200_reloc_map[] =
197 {
198 { BFD_RELOC_NONE, R_MN10200_NONE, },
199 { BFD_RELOC_32, R_MN10200_32, },
200 { BFD_RELOC_16, R_MN10200_16, },
201 { BFD_RELOC_8, R_MN10200_8, },
202 #if 0
203 { BFD_RELOC_MN10200_32B, R_MN10200_32B, },
204 { BFD_RELOC_MN10200_16B, R_MN10200_16B, },
205 { BFD_RELOC_32_PCREL, R_MN10200_PCREL32_1BYTE, },
206 { BFD_RELOC_16_PCREL, R_MN10200_PCREL16_1BYTE, },
207 { BFD_RELOC_8_PCREL, R_MN10200_PCREL8_1BYTE, },
208 { BFD_RELOC_MN10200_32_PCREL, R_MN10200_PCREL32_2BYTE, },
209 { BFD_RELOC_MN10200_16_PCREL, R_MN10200_PCREL16_2BYTE, },
210 #endif
211 };
212
213 static reloc_howto_type *
214 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
215 bfd *abfd;
216 bfd_reloc_code_real_type code;
217 {
218 unsigned int i;
219
220 for (i = 0;
221 i < sizeof (mn10200_reloc_map) / sizeof (struct mn10200_reloc_map);
222 i++)
223 {
224 if (mn10200_reloc_map[i].bfd_reloc_val == code)
225 return &elf_mn10200_howto_table[mn10200_reloc_map[i].elf_reloc_val];
226 }
227
228 return NULL;
229 }
230
231 /* Set the howto pointer for an MN10200 ELF reloc. */
232
233 static void
234 mn10200_info_to_howto (abfd, cache_ptr, dst)
235 bfd *abfd;
236 arelent *cache_ptr;
237 Elf32_Internal_Rela *dst;
238 {
239 unsigned int r_type;
240
241 r_type = ELF32_R_TYPE (dst->r_info);
242 BFD_ASSERT (r_type < (unsigned int) R_MN10200_MAX);
243 cache_ptr->howto = &elf_mn10200_howto_table[r_type];
244 }
245
246 static bfd_reloc_status_type
247 bfd_elf32_mn10200_reloc (abfd, reloc, symbol, data, isection, obfd, err)
248 bfd *abfd;
249 arelent *reloc;
250 asymbol *symbol;
251 PTR data;
252 asection *isection;
253 bfd *obfd;
254 char **err;
255 {
256 if (obfd != (bfd *) NULL
257 && (symbol->flags & BSF_SECTION_SYM) == 0
258 && (! reloc->howto->partial_inplace
259 || reloc->addend == 0))
260 {
261 reloc->address += isection->output_offset;
262 return bfd_reloc_ok;
263 }
264 else if (obfd != NULL)
265 {
266 return bfd_reloc_continue;
267 }
268
269 #if 0
270 /* Catch relocs involving undefined symbols. */
271 if (bfd_is_und_section (symbol->section)
272 && (symbol->flags & BSF_WEAK) == 0
273 && obfd == NULL)
274 return bfd_reloc_undefined;
275
276 /* We handle final linking of some relocs ourselves. */
277 {
278 long relocation;
279
280 /* Is the address of the relocation really within the section? */
281 if (reloc->address > isection->_cooked_size)
282 return bfd_reloc_outofrange;
283
284 /* Work out which section the relocation is targetted at and the
285 initial relocation command value. */
286
287 /* Get symbol value. (Common symbols are special.) */
288 if (bfd_is_com_section (symbol->section))
289 relocation = 0;
290 else
291 relocation = symbol->value;
292
293 /* Convert input-section-relative symbol value to absolute + addend. */
294 relocation += symbol->section->output_section->vma;
295 relocation += symbol->section->output_offset;
296 relocation += reloc->addend;
297
298 if (reloc->howto->pc_relative == true)
299 {
300 /* Here the variable relocation holds the final address of the
301 symbol we are relocating against, plus any addend. */
302 relocation -= isection->output_section->vma + isection->output_offset;
303
304 /* Deal with pcrel_offset */
305 relocation -= reloc->address;
306
307 if (reloc->howto->type == R_MN10200_PCREL32_1BYTE
308 || reloc->howto->type == R_MN10200_PCREL16_1BYTE
309 || reloc->howto->type == R_MN10200_PCREL8_1BYTE)
310 relocation += 1;
311 else if (reloc->howto->type == R_MN10200_PCREL32_2BYTE
312 || reloc->howto->type == R_MN10200_PCREL16_2BYTE)
313 relocation += 2;
314 }
315
316 /* I've got no clue... */
317 reloc->addend = 0;
318
319 if (reloc->howto->size == 0)
320 {
321 if (relocation > 0x7f || relocation < -0x80)
322 return bfd_reloc_overflow;
323
324 bfd_put_8 (abfd, relocation & 0xff,
325 (bfd_byte *)data + reloc->address);
326 }
327 else if (reloc->howto->size == 1)
328 {
329 if (relocation > 0x7fff || relocation < -0x8000)
330 return bfd_reloc_overflow;
331
332 bfd_putb16 (relocation & 0xffff, (bfd_byte *)data + reloc->address);
333 }
334 else if (reloc->howto->size == 2)
335 bfd_putb32 (relocation, (bfd_byte *)data + reloc->address);
336 return bfd_reloc_ok;
337 }
338 #endif
339
340 return bfd_reloc_continue;
341 }
342
343 #define TARGET_LITTLE_SYM bfd_elf32_mn10200_vec
344 #define TARGET_LITTLE_NAME "elf32-mn10200"
345 #define ELF_ARCH bfd_arch_mn10200
346 #define ELF_MACHINE_CODE EM_CYGNUS_MN10200
347 #define ELF_MAXPAGESIZE 0x1000
348
349 #define elf_info_to_howto mn10200_info_to_howto
350 #define elf_info_to_howto_rel 0
351
352 #define elf_symbol_leading_char '_'
353
354 #include "elf32-target.h"
This page took 0.037214 seconds and 4 git commands to generate.