* gdb.base/attach.exp (do_attach_tests): Don't forget to kill second
[deliverable/binutils-gdb.git] / bfd / elf32-i860.c
... / ...
CommitLineData
1/* Intel i860 specific support for 32-bit ELF.
2 Copyright 1993, 1995, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4
5 Full i860 support contributed by Jason Eckhardt <jle@cygnus.com>.
6
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23#include "bfd.h"
24#include "sysdep.h"
25#include "libbfd.h"
26#include "elf-bfd.h"
27#include "elf/i860.h"
28
29/* special_function for R_860_PC26 relocation. */
30static bfd_reloc_status_type
31i860_howto_pc26_reloc (bfd *abfd ATTRIBUTE_UNUSED,
32 arelent *reloc_entry,
33 asymbol *symbol,
34 void *data ATTRIBUTE_UNUSED,
35 asection *input_section,
36 bfd *output_bfd,
37 char **error_message ATTRIBUTE_UNUSED)
38{
39 bfd_vma insn;
40 bfd_vma relocation;
41 bfd_size_type sz;
42 bfd_byte *addr;
43
44 if (output_bfd != NULL
45 && (symbol->flags & BSF_SECTION_SYM) == 0
46 && (! reloc_entry->howto->partial_inplace
47 || reloc_entry->addend == 0))
48 {
49 reloc_entry->address += input_section->output_offset;
50 return bfd_reloc_ok;
51 }
52
53 /* Used elf32-mips.c as an example. */
54 if (bfd_is_und_section (symbol->section)
55 && output_bfd == (bfd *) NULL)
56 return bfd_reloc_undefined;
57
58 if (bfd_is_com_section (symbol->section))
59 relocation = 0;
60 else
61 relocation = symbol->value;
62
63 relocation += symbol->section->output_section->vma;
64 relocation += symbol->section->output_offset;
65 relocation += reloc_entry->addend;
66
67 sz = input_section->rawsize ? input_section->rawsize : input_section->size;
68 if (reloc_entry->address > sz)
69 return bfd_reloc_outofrange;
70
71 /* Adjust for PC-relative relocation. */
72 relocation -= (input_section->output_section->vma
73 + input_section->output_offset
74 + reloc_entry->address
75 + 4);
76
77 /* Check for target out of range. */
78 if ((bfd_signed_vma)relocation > (0x3ffffff << 2)
79 || (bfd_signed_vma)relocation < (-0x4000000 << 2))
80 return bfd_reloc_outofrange;
81
82 addr = (bfd_byte *) data + reloc_entry->address;
83 insn = bfd_get_32 (abfd, addr);
84
85 relocation >>= reloc_entry->howto->rightshift;
86 insn = (insn & ~reloc_entry->howto->dst_mask)
87 | (relocation & reloc_entry->howto->dst_mask);
88
89 bfd_put_32 (abfd, (bfd_vma) insn, addr);
90
91 return bfd_reloc_ok;
92}
93
94/* special_function for R_860_PC16 relocation. */
95static bfd_reloc_status_type
96i860_howto_pc16_reloc (bfd *abfd,
97 arelent *reloc_entry,
98 asymbol *symbol,
99 void *data,
100 asection *input_section,
101 bfd *output_bfd,
102 char **error_message ATTRIBUTE_UNUSED)
103{
104 bfd_vma insn;
105 bfd_vma relocation;
106 bfd_size_type sz;
107 bfd_byte *addr;
108
109 if (output_bfd != NULL
110 && (symbol->flags & BSF_SECTION_SYM) == 0
111 && (! reloc_entry->howto->partial_inplace
112 || reloc_entry->addend == 0))
113 {
114 reloc_entry->address += input_section->output_offset;
115 return bfd_reloc_ok;
116 }
117
118 /* Used elf32-mips.c as an example. */
119 if (bfd_is_und_section (symbol->section)
120 && output_bfd == (bfd *) NULL)
121 return bfd_reloc_undefined;
122
123 if (bfd_is_com_section (symbol->section))
124 relocation = 0;
125 else
126 relocation = symbol->value;
127
128 relocation += symbol->section->output_section->vma;
129 relocation += symbol->section->output_offset;
130 relocation += reloc_entry->addend;
131
132 sz = input_section->rawsize ? input_section->rawsize : input_section->size;
133 if (reloc_entry->address > sz)
134 return bfd_reloc_outofrange;
135
136 /* Adjust for PC-relative relocation. */
137 relocation -= (input_section->output_section->vma
138 + input_section->output_offset
139 + reloc_entry->address
140 + 4);
141
142 /* Check for target out of range. */
143 if ((bfd_signed_vma)relocation > (0x7fff << 2)
144 || (bfd_signed_vma)relocation < (-0x8000 << 2))
145 return bfd_reloc_outofrange;
146
147 addr = (bfd_byte *) data + reloc_entry->address;
148 insn = bfd_get_32 (abfd, addr);
149
150 relocation >>= reloc_entry->howto->rightshift;
151 relocation = (((relocation & 0xf800) << 5) | (relocation & 0x7ff))
152 & reloc_entry->howto->dst_mask;
153 insn = (insn & ~reloc_entry->howto->dst_mask) | relocation;
154
155 bfd_put_32 (abfd, (bfd_vma) insn, addr);
156
157 return bfd_reloc_ok;
158}
159
160/* special_function for R_860_HIGHADJ relocation. */
161static bfd_reloc_status_type
162i860_howto_highadj_reloc (bfd *abfd,
163 arelent *reloc_entry,
164 asymbol *symbol,
165 void *data,
166 asection *input_section,
167 bfd *output_bfd,
168 char **error_message ATTRIBUTE_UNUSED)
169{
170 bfd_vma insn;
171 bfd_vma relocation;
172 bfd_size_type sz;
173 bfd_byte *addr;
174
175 if (output_bfd != NULL
176 && (symbol->flags & BSF_SECTION_SYM) == 0
177 && (! reloc_entry->howto->partial_inplace
178 || reloc_entry->addend == 0))
179 {
180 reloc_entry->address += input_section->output_offset;
181 return bfd_reloc_ok;
182 }
183
184 /* Used elf32-mips.c as an example. */
185 if (bfd_is_und_section (symbol->section)
186 && output_bfd == (bfd *) NULL)
187 return bfd_reloc_undefined;
188
189 if (bfd_is_com_section (symbol->section))
190 relocation = 0;
191 else
192 relocation = symbol->value;
193
194 relocation += symbol->section->output_section->vma;
195 relocation += symbol->section->output_offset;
196 relocation += reloc_entry->addend;
197 relocation += 0x8000;
198
199 sz = input_section->rawsize ? input_section->rawsize : input_section->size;
200 if (reloc_entry->address > sz)
201 return bfd_reloc_outofrange;
202
203 addr = (bfd_byte *) data + reloc_entry->address;
204 insn = bfd_get_32 (abfd, addr);
205
206 relocation = ((relocation >> 16) & 0xffff);
207
208 insn = (insn & 0xffff0000) | relocation;
209
210 bfd_put_32 (abfd, (bfd_vma) insn, addr);
211
212 return bfd_reloc_ok;
213}
214
215/* special_function for R_860_SPLITn relocations. */
216static bfd_reloc_status_type
217i860_howto_splitn_reloc (bfd *abfd,
218 arelent *reloc_entry,
219 asymbol *symbol,
220 void *data,
221 asection *input_section,
222 bfd *output_bfd,
223 char **error_message ATTRIBUTE_UNUSED)
224{
225 bfd_vma insn;
226 bfd_vma relocation;
227 bfd_size_type sz;
228 bfd_byte *addr;
229
230 if (output_bfd != NULL
231 && (symbol->flags & BSF_SECTION_SYM) == 0
232 && (! reloc_entry->howto->partial_inplace
233 || reloc_entry->addend == 0))
234 {
235 reloc_entry->address += input_section->output_offset;
236 return bfd_reloc_ok;
237 }
238
239 /* Used elf32-mips.c as an example. */
240 if (bfd_is_und_section (symbol->section)
241 && output_bfd == (bfd *) NULL)
242 return bfd_reloc_undefined;
243
244 if (bfd_is_com_section (symbol->section))
245 relocation = 0;
246 else
247 relocation = symbol->value;
248
249 relocation += symbol->section->output_section->vma;
250 relocation += symbol->section->output_offset;
251 relocation += reloc_entry->addend;
252
253 sz = input_section->rawsize ? input_section->rawsize : input_section->size;
254 if (reloc_entry->address > sz)
255 return bfd_reloc_outofrange;
256
257 addr = (bfd_byte *) data + reloc_entry->address;
258 insn = bfd_get_32 (abfd, addr);
259
260 relocation = (((relocation & 0xf800) << 5) | (relocation & 0x7ff))
261 & reloc_entry->howto->dst_mask;
262 insn = (insn & ~reloc_entry->howto->dst_mask) | relocation;
263
264 bfd_put_32 (abfd, (bfd_vma) insn, addr);
265
266 return bfd_reloc_ok;
267}
268
269/* This howto table is preliminary. */
270static reloc_howto_type elf32_i860_howto_table [] =
271{
272 /* This relocation does nothing. */
273 HOWTO (R_860_NONE, /* type */
274 0, /* rightshift */
275 2, /* size (0 = byte, 1 = short, 2 = long) */
276 32, /* bitsize */
277 FALSE, /* pc_relative */
278 0, /* bitpos */
279 complain_overflow_bitfield, /* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_860_NONE", /* name */
282 FALSE, /* partial_inplace */
283 0, /* src_mask */
284 0, /* dst_mask */
285 FALSE), /* pcrel_offset */
286
287 /* A 32-bit absolute relocation. */
288 HOWTO (R_860_32, /* type */
289 0, /* rightshift */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
291 32, /* bitsize */
292 FALSE, /* pc_relative */
293 0, /* bitpos */
294 complain_overflow_bitfield, /* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_860_32", /* name */
297 FALSE, /* partial_inplace */
298 0xffffffff, /* src_mask */
299 0xffffffff, /* dst_mask */
300 FALSE), /* pcrel_offset */
301
302 HOWTO (R_860_COPY, /* type */
303 0, /* rightshift */
304 2, /* size (0 = byte, 1 = short, 2 = long) */
305 32, /* bitsize */
306 FALSE, /* pc_relative */
307 0, /* bitpos */
308 complain_overflow_bitfield, /* complain_on_overflow */
309 bfd_elf_generic_reloc, /* special_function */
310 "R_860_COPY", /* name */
311 TRUE, /* partial_inplace */
312 0xffffffff, /* src_mask */
313 0xffffffff, /* dst_mask */
314 FALSE), /* pcrel_offset */
315
316 HOWTO (R_860_GLOB_DAT, /* type */
317 0, /* rightshift */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
319 32, /* bitsize */
320 FALSE, /* pc_relative */
321 0, /* bitpos */
322 complain_overflow_bitfield, /* complain_on_overflow */
323 bfd_elf_generic_reloc, /* special_function */
324 "R_860_GLOB_DAT", /* name */
325 TRUE, /* partial_inplace */
326 0xffffffff, /* src_mask */
327 0xffffffff, /* dst_mask */
328 FALSE), /* pcrel_offset */
329
330 HOWTO (R_860_JUMP_SLOT, /* type */
331 0, /* rightshift */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
333 32, /* bitsize */
334 FALSE, /* pc_relative */
335 0, /* bitpos */
336 complain_overflow_bitfield, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 "R_860_JUMP_SLOT", /* name */
339 TRUE, /* partial_inplace */
340 0xffffffff, /* src_mask */
341 0xffffffff, /* dst_mask */
342 FALSE), /* pcrel_offset */
343
344 HOWTO (R_860_RELATIVE, /* type */
345 0, /* rightshift */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
347 32, /* bitsize */
348 FALSE, /* pc_relative */
349 0, /* bitpos */
350 complain_overflow_bitfield, /* complain_on_overflow */
351 bfd_elf_generic_reloc, /* special_function */
352 "R_860_RELATIVE", /* name */
353 TRUE, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 FALSE), /* pcrel_offset */
357
358 /* A 26-bit PC-relative relocation. */
359 HOWTO (R_860_PC26, /* type */
360 2, /* rightshift */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
362 26, /* bitsize */
363 TRUE, /* pc_relative */
364 0, /* bitpos */
365 complain_overflow_bitfield, /* complain_on_overflow */
366 i860_howto_pc26_reloc, /* special_function */
367 "R_860_PC26", /* name */
368 FALSE, /* partial_inplace */
369 0x3ffffff, /* src_mask */
370 0x3ffffff, /* dst_mask */
371 TRUE), /* pcrel_offset */
372
373 HOWTO (R_860_PLT26, /* type */
374 0, /* rightshift */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
376 26, /* bitsize */
377 TRUE, /* pc_relative */
378 0, /* bitpos */
379 complain_overflow_bitfield, /* complain_on_overflow */
380 bfd_elf_generic_reloc, /* special_function */
381 "R_860_PLT26", /* name */
382 TRUE, /* partial_inplace */
383 0xffffffff, /* src_mask */
384 0xffffffff, /* dst_mask */
385 TRUE), /* pcrel_offset */
386
387 /* A 16-bit PC-relative relocation. */
388 HOWTO (R_860_PC16, /* type */
389 2, /* rightshift */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
391 16, /* bitsize */
392 TRUE, /* pc_relative */
393 0, /* bitpos */
394 complain_overflow_bitfield, /* complain_on_overflow */
395 i860_howto_pc16_reloc, /* special_function */
396 "R_860_PC16", /* name */
397 FALSE, /* partial_inplace */
398 0x1f07ff, /* src_mask */
399 0x1f07ff, /* dst_mask */
400 TRUE), /* pcrel_offset */
401
402 HOWTO (R_860_LOW0, /* type */
403 0, /* rightshift */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
405 16, /* bitsize */
406 FALSE, /* pc_relative */
407 0, /* bitpos */
408 complain_overflow_dont, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 "R_860_LOW0", /* name */
411 FALSE, /* partial_inplace */
412 0xffff, /* src_mask */
413 0xffff, /* dst_mask */
414 FALSE), /* pcrel_offset */
415
416 HOWTO (R_860_SPLIT0, /* type */
417 0, /* rightshift */
418 2, /* size (0 = byte, 1 = short, 2 = long) */
419 16, /* bitsize */
420 FALSE, /* pc_relative */
421 0, /* bitpos */
422 complain_overflow_dont, /* complain_on_overflow */
423 i860_howto_splitn_reloc, /* special_function */
424 "R_860_SPLIT0", /* name */
425 FALSE, /* partial_inplace */
426 0x1f07ff, /* src_mask */
427 0x1f07ff, /* dst_mask */
428 FALSE), /* pcrel_offset */
429
430 HOWTO (R_860_LOW1, /* type */
431 0, /* rightshift */
432 2, /* size (0 = byte, 1 = short, 2 = long) */
433 16, /* bitsize */
434 FALSE, /* pc_relative */
435 0, /* bitpos */
436 complain_overflow_dont, /* complain_on_overflow */
437 bfd_elf_generic_reloc, /* special_function */
438 "R_860_LOW1", /* name */
439 FALSE, /* partial_inplace */
440 0xfffe, /* src_mask */
441 0xfffe, /* dst_mask */
442 FALSE), /* pcrel_offset */
443
444 HOWTO (R_860_SPLIT1, /* type */
445 0, /* rightshift */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
447 16, /* bitsize */
448 FALSE, /* pc_relative */
449 0, /* bitpos */
450 complain_overflow_dont, /* complain_on_overflow */
451 i860_howto_splitn_reloc, /* special_function */
452 "R_860_SPLIT1", /* name */
453 FALSE, /* partial_inplace */
454 0x1f07fe, /* src_mask */
455 0x1f07fe, /* dst_mask */
456 FALSE), /* pcrel_offset */
457
458 HOWTO (R_860_LOW2, /* type */
459 0, /* rightshift */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
461 16, /* bitsize */
462 FALSE, /* pc_relative */
463 0, /* bitpos */
464 complain_overflow_dont, /* complain_on_overflow */
465 bfd_elf_generic_reloc, /* special_function */
466 "R_860_LOW2", /* name */
467 FALSE, /* partial_inplace */
468 0xfffc, /* src_mask */
469 0xfffc, /* dst_mask */
470 FALSE), /* pcrel_offset */
471
472 HOWTO (R_860_SPLIT2, /* type */
473 0, /* rightshift */
474 2, /* size (0 = byte, 1 = short, 2 = long) */
475 16, /* bitsize */
476 FALSE, /* pc_relative */
477 0, /* bitpos */
478 complain_overflow_dont, /* complain_on_overflow */
479 i860_howto_splitn_reloc, /* special_function */
480 "R_860_SPLIT2", /* name */
481 FALSE, /* partial_inplace */
482 0x1f07fc, /* src_mask */
483 0x1f07fc, /* dst_mask */
484 FALSE), /* pcrel_offset */
485
486 HOWTO (R_860_LOW3, /* type */
487 0, /* rightshift */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
489 16, /* bitsize */
490 FALSE, /* pc_relative */
491 0, /* bitpos */
492 complain_overflow_dont, /* complain_on_overflow */
493 bfd_elf_generic_reloc, /* special_function */
494 "R_860_LOW3", /* name */
495 FALSE, /* partial_inplace */
496 0xfff8, /* src_mask */
497 0xfff8, /* dst_mask */
498 FALSE), /* pcrel_offset */
499
500 HOWTO (R_860_LOGOT0, /* type */
501 0, /* rightshift */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
503 16, /* bitsize */
504 FALSE, /* pc_relative */
505 0, /* bitpos */
506 complain_overflow_dont, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 "R_860_LOGOT0", /* name */
509 FALSE, /* partial_inplace */
510 0, /* src_mask */
511 0xffff, /* dst_mask */
512 TRUE), /* pcrel_offset */
513
514 HOWTO (R_860_SPGOT0, /* type */
515 0, /* rightshift */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
517 16, /* bitsize */
518 FALSE, /* pc_relative */
519 0, /* bitpos */
520 complain_overflow_dont, /* complain_on_overflow */
521 bfd_elf_generic_reloc, /* special_function */
522 "R_860_SPGOT0", /* name */
523 FALSE, /* partial_inplace */
524 0, /* src_mask */
525 0xffff, /* dst_mask */
526 TRUE), /* pcrel_offset */
527
528 HOWTO (R_860_LOGOT1, /* type */
529 0, /* rightshift */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
531 16, /* bitsize */
532 FALSE, /* pc_relative */
533 0, /* bitpos */
534 complain_overflow_dont, /* complain_on_overflow */
535 bfd_elf_generic_reloc, /* special_function */
536 "R_860_LOGOT1", /* name */
537 FALSE, /* partial_inplace */
538 0, /* src_mask */
539 0xffff, /* dst_mask */
540 TRUE), /* pcrel_offset */
541
542 HOWTO (R_860_SPGOT1, /* type */
543 0, /* rightshift */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
545 16, /* bitsize */
546 FALSE, /* pc_relative */
547 0, /* bitpos */
548 complain_overflow_dont, /* complain_on_overflow */
549 bfd_elf_generic_reloc, /* special_function */
550 "R_860_SPGOT1", /* name */
551 FALSE, /* partial_inplace */
552 0, /* src_mask */
553 0xffff, /* dst_mask */
554 TRUE), /* pcrel_offset */
555
556 HOWTO (R_860_LOGOTOFF0, /* type */
557 0, /* rightshift */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
559 32, /* bitsize */
560 FALSE, /* pc_relative */
561 0, /* bitpos */
562 complain_overflow_dont, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 "R_860_LOGOTOFF0", /* name */
565 TRUE, /* partial_inplace */
566 0xffffffff, /* src_mask */
567 0xffffffff, /* dst_mask */
568 FALSE), /* pcrel_offset */
569
570 HOWTO (R_860_SPGOTOFF0, /* type */
571 0, /* rightshift */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
573 32, /* bitsize */
574 FALSE, /* pc_relative */
575 0, /* bitpos */
576 complain_overflow_dont, /* complain_on_overflow */
577 bfd_elf_generic_reloc, /* special_function */
578 "R_860_SPGOTOFF0", /* name */
579 TRUE, /* partial_inplace */
580 0xffffffff, /* src_mask */
581 0xffffffff, /* dst_mask */
582 FALSE), /* pcrel_offset */
583
584 HOWTO (R_860_LOGOTOFF1, /* type */
585 0, /* rightshift */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
587 32, /* bitsize */
588 FALSE, /* pc_relative */
589 0, /* bitpos */
590 complain_overflow_dont, /* complain_on_overflow */
591 bfd_elf_generic_reloc, /* special_function */
592 "R_860_LOGOTOFF1", /* name */
593 TRUE, /* partial_inplace */
594 0xffffffff, /* src_mask */
595 0xffffffff, /* dst_mask */
596 FALSE), /* pcrel_offset */
597
598 HOWTO (R_860_SPGOTOFF1, /* type */
599 0, /* rightshift */
600 2, /* size (0 = byte, 1 = short, 2 = long) */
601 32, /* bitsize */
602 FALSE, /* pc_relative */
603 0, /* bitpos */
604 complain_overflow_dont, /* complain_on_overflow */
605 bfd_elf_generic_reloc, /* special_function */
606 "R_860_SPGOTOFF1", /* name */
607 TRUE, /* partial_inplace */
608 0xffffffff, /* src_mask */
609 0xffffffff, /* dst_mask */
610 FALSE), /* pcrel_offset */
611
612 HOWTO (R_860_LOGOTOFF2, /* type */
613 0, /* rightshift */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
615 32, /* bitsize */
616 FALSE, /* pc_relative */
617 0, /* bitpos */
618 complain_overflow_dont, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 "R_860_LOGOTOFF2", /* name */
621 TRUE, /* partial_inplace */
622 0xffffffff, /* src_mask */
623 0xffffffff, /* dst_mask */
624 FALSE), /* pcrel_offset */
625
626 HOWTO (R_860_LOGOTOFF3, /* type */
627 0, /* rightshift */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
629 32, /* bitsize */
630 FALSE, /* pc_relative */
631 0, /* bitpos */
632 complain_overflow_dont, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 "R_860_LOGOTOFF3", /* name */
635 TRUE, /* partial_inplace */
636 0xffffffff, /* src_mask */
637 0xffffffff, /* dst_mask */
638 FALSE), /* pcrel_offset */
639
640 HOWTO (R_860_LOPC, /* type */
641 0, /* rightshift */
642 2, /* size (0 = byte, 1 = short, 2 = long) */
643 16, /* bitsize */
644 TRUE, /* pc_relative */
645 0, /* bitpos */
646 complain_overflow_bitfield, /* complain_on_overflow */
647 bfd_elf_generic_reloc, /* special_function */
648 "R_860_LOPC", /* name */
649 FALSE, /* partial_inplace */
650 0xffff, /* src_mask */
651 0xffff, /* dst_mask */
652 TRUE), /* pcrel_offset */
653
654 HOWTO (R_860_HIGHADJ, /* type */
655 0, /* rightshift */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
657 16, /* bitsize */
658 FALSE, /* pc_relative */
659 0, /* bitpos */
660 complain_overflow_dont, /* complain_on_overflow */
661 i860_howto_highadj_reloc, /* special_function */
662 "R_860_HIGHADJ", /* name */
663 FALSE, /* partial_inplace */
664 0xffff, /* src_mask */
665 0xffff, /* dst_mask */
666 FALSE), /* pcrel_offset */
667
668 HOWTO (R_860_HAGOT, /* type */
669 0, /* rightshift */
670 2, /* size (0 = byte, 1 = short, 2 = long) */
671 16, /* bitsize */
672 FALSE, /* pc_relative */
673 0, /* bitpos */
674 complain_overflow_dont, /* complain_on_overflow */
675 bfd_elf_generic_reloc, /* special_function */
676 "R_860_HAGOT", /* name */
677 FALSE, /* partial_inplace */
678 0, /* src_mask */
679 0xffff, /* dst_mask */
680 TRUE), /* pcrel_offset */
681
682 HOWTO (R_860_HAGOTOFF, /* type */
683 0, /* rightshift */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
685 32, /* bitsize */
686 FALSE, /* pc_relative */
687 0, /* bitpos */
688 complain_overflow_dont, /* complain_on_overflow */
689 bfd_elf_generic_reloc, /* special_function */
690 "R_860_HAGOTOFF", /* name */
691 TRUE, /* partial_inplace */
692 0xffffffff, /* src_mask */
693 0xffffffff, /* dst_mask */
694 FALSE), /* pcrel_offset */
695
696 HOWTO (R_860_HAPC, /* type */
697 0, /* rightshift */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
699 16, /* bitsize */
700 TRUE, /* pc_relative */
701 0, /* bitpos */
702 complain_overflow_bitfield, /* complain_on_overflow */
703 bfd_elf_generic_reloc, /* special_function */
704 "R_860_HAPC", /* name */
705 FALSE, /* partial_inplace */
706 0xffff, /* src_mask */
707 0xffff, /* dst_mask */
708 TRUE), /* pcrel_offset */
709
710 HOWTO (R_860_HIGH, /* type */
711 16, /* rightshift */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
713 16, /* bitsize */
714 FALSE, /* pc_relative */
715 0, /* bitpos */
716 complain_overflow_dont, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
718 "R_860_HIGH", /* name */
719 FALSE, /* partial_inplace */
720 0xffff, /* src_mask */
721 0xffff, /* dst_mask */
722 FALSE), /* pcrel_offset */
723
724 HOWTO (R_860_HIGOT, /* type */
725 0, /* rightshift */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
727 16, /* bitsize */
728 FALSE, /* pc_relative */
729 0, /* bitpos */
730 complain_overflow_dont, /* complain_on_overflow */
731 bfd_elf_generic_reloc, /* special_function */
732 "R_860_HIGOT", /* name */
733 FALSE, /* partial_inplace */
734 0, /* src_mask */
735 0xffff, /* dst_mask */
736 TRUE), /* pcrel_offset */
737
738 HOWTO (R_860_HIGOTOFF, /* type */
739 0, /* rightshift */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
741 32, /* bitsize */
742 FALSE, /* pc_relative */
743 0, /* bitpos */
744 complain_overflow_dont, /* complain_on_overflow */
745 bfd_elf_generic_reloc, /* special_function */
746 "R_860_HIGOTOFF", /* name */
747 TRUE, /* partial_inplace */
748 0xffffffff, /* src_mask */
749 0xffffffff, /* dst_mask */
750 FALSE), /* pcrel_offset */
751};
752\f
753static unsigned char elf_code_to_howto_index[R_860_max + 1];
754
755static reloc_howto_type *
756lookup_howto (unsigned int rtype)
757{
758 static int initialized = 0;
759 int i;
760 int howto_tbl_size = (int) (sizeof (elf32_i860_howto_table)
761 / sizeof (elf32_i860_howto_table[0]));
762
763 if (! initialized)
764 {
765 initialized = 1;
766 memset (elf_code_to_howto_index, 0xff,
767 sizeof (elf_code_to_howto_index));
768 for (i = 0; i < howto_tbl_size; i++)
769 elf_code_to_howto_index[elf32_i860_howto_table[i].type] = i;
770 }
771
772 BFD_ASSERT (rtype <= R_860_max);
773 i = elf_code_to_howto_index[rtype];
774 if (i >= howto_tbl_size)
775 return 0;
776 return elf32_i860_howto_table + i;
777}
778
779/* Given a BFD reloc, return the matching HOWTO structure. */
780static reloc_howto_type *
781elf32_i860_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
782 bfd_reloc_code_real_type code)
783{
784 unsigned int rtype;
785
786 switch (code)
787 {
788 case BFD_RELOC_NONE:
789 rtype = R_860_NONE;
790 break;
791 case BFD_RELOC_32:
792 rtype = R_860_32;
793 break;
794 case BFD_RELOC_860_COPY:
795 rtype = R_860_COPY;
796 break;
797 case BFD_RELOC_860_GLOB_DAT:
798 rtype = R_860_GLOB_DAT;
799 break;
800 case BFD_RELOC_860_JUMP_SLOT:
801 rtype = R_860_JUMP_SLOT;
802 break;
803 case BFD_RELOC_860_RELATIVE:
804 rtype = R_860_RELATIVE;
805 break;
806 case BFD_RELOC_860_PC26:
807 rtype = R_860_PC26;
808 break;
809 case BFD_RELOC_860_PLT26:
810 rtype = R_860_PLT26;
811 break;
812 case BFD_RELOC_860_PC16:
813 rtype = R_860_PC16;
814 break;
815 case BFD_RELOC_860_LOW0:
816 rtype = R_860_LOW0;
817 break;
818 case BFD_RELOC_860_SPLIT0:
819 rtype = R_860_SPLIT0;
820 break;
821 case BFD_RELOC_860_LOW1:
822 rtype = R_860_LOW1;
823 break;
824 case BFD_RELOC_860_SPLIT1:
825 rtype = R_860_SPLIT1;
826 break;
827 case BFD_RELOC_860_LOW2:
828 rtype = R_860_LOW2;
829 break;
830 case BFD_RELOC_860_SPLIT2:
831 rtype = R_860_SPLIT2;
832 break;
833 case BFD_RELOC_860_LOW3:
834 rtype = R_860_LOW3;
835 break;
836 case BFD_RELOC_860_LOGOT0:
837 rtype = R_860_LOGOT0;
838 break;
839 case BFD_RELOC_860_SPGOT0:
840 rtype = R_860_SPGOT0;
841 break;
842 case BFD_RELOC_860_LOGOT1:
843 rtype = R_860_LOGOT1;
844 break;
845 case BFD_RELOC_860_SPGOT1:
846 rtype = R_860_SPGOT1;
847 break;
848 case BFD_RELOC_860_LOGOTOFF0:
849 rtype = R_860_LOGOTOFF0;
850 break;
851 case BFD_RELOC_860_SPGOTOFF0:
852 rtype = R_860_SPGOTOFF0;
853 break;
854 case BFD_RELOC_860_LOGOTOFF1:
855 rtype = R_860_LOGOTOFF1;
856 break;
857 case BFD_RELOC_860_SPGOTOFF1:
858 rtype = R_860_SPGOTOFF1;
859 break;
860 case BFD_RELOC_860_LOGOTOFF2:
861 rtype = R_860_LOGOTOFF2;
862 break;
863 case BFD_RELOC_860_LOGOTOFF3:
864 rtype = R_860_LOGOTOFF3;
865 break;
866 case BFD_RELOC_860_LOPC:
867 rtype = R_860_LOPC;
868 break;
869 case BFD_RELOC_860_HIGHADJ:
870 rtype = R_860_HIGHADJ;
871 break;
872 case BFD_RELOC_860_HAGOT:
873 rtype = R_860_HAGOT;
874 break;
875 case BFD_RELOC_860_HAGOTOFF:
876 rtype = R_860_HAGOTOFF;
877 break;
878 case BFD_RELOC_860_HAPC:
879 rtype = R_860_HAPC;
880 break;
881 case BFD_RELOC_860_HIGH:
882 rtype = R_860_HIGH;
883 break;
884 case BFD_RELOC_860_HIGOT:
885 rtype = R_860_HIGOT;
886 break;
887 case BFD_RELOC_860_HIGOTOFF:
888 rtype = R_860_HIGOTOFF;
889 break;
890 default:
891 rtype = 0;
892 break;
893 }
894 return lookup_howto (rtype);
895}
896
897/* Given a ELF reloc, return the matching HOWTO structure. */
898static void
899elf32_i860_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
900 arelent *bfd_reloc,
901 Elf_Internal_Rela *elf_reloc)
902{
903 bfd_reloc->howto
904 = lookup_howto ((unsigned) ELF32_R_TYPE (elf_reloc->r_info));
905}
906\f
907/* Specialized relocation handler for R_860_SPLITn. These relocations
908 involves a 16-bit field that is split into two contiguous parts. */
909static bfd_reloc_status_type
910elf32_i860_relocate_splitn (bfd *input_bfd,
911 Elf_Internal_Rela *rello,
912 bfd_byte *contents,
913 bfd_vma value)
914{
915 bfd_vma insn;
916 reloc_howto_type *howto;
917 howto = lookup_howto ((unsigned) ELF32_R_TYPE (rello->r_info));
918 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
919
920 /* Relocate. */
921 value += rello->r_addend;
922
923 /* Separate the fields and insert. */
924 value = (((value & 0xf800) << 5) | (value & 0x7ff)) & howto->dst_mask;
925 insn = (insn & ~howto->dst_mask) | value;
926
927 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
928 return bfd_reloc_ok;
929}
930
931/* Specialized relocation handler for R_860_PC16. This relocation
932 involves a 16-bit, PC-relative field that is split into two contiguous
933 parts. */
934static bfd_reloc_status_type
935elf32_i860_relocate_pc16 (bfd *input_bfd,
936 asection *input_section,
937 Elf_Internal_Rela *rello,
938 bfd_byte *contents,
939 bfd_vma value)
940{
941 bfd_vma insn;
942 reloc_howto_type *howto;
943 howto = lookup_howto ((unsigned) ELF32_R_TYPE (rello->r_info));
944 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
945
946 /* Adjust for PC-relative relocation. */
947 value -= (input_section->output_section->vma
948 + input_section->output_offset);
949 value -= rello->r_offset;
950
951 /* Relocate. */
952 value += rello->r_addend;
953
954 /* Adjust the value by 4, then separate the fields and insert. */
955 value = (value - 4) >> howto->rightshift;
956 value = (((value & 0xf800) << 5) | (value & 0x7ff)) & howto->dst_mask;
957 insn = (insn & ~howto->dst_mask) | value;
958
959 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
960 return bfd_reloc_ok;
961
962}
963
964/* Specialized relocation handler for R_860_PC26. This relocation
965 involves a 26-bit, PC-relative field which must be adjusted by 4. */
966static bfd_reloc_status_type
967elf32_i860_relocate_pc26 (bfd *input_bfd,
968 asection *input_section,
969 Elf_Internal_Rela *rello,
970 bfd_byte *contents,
971 bfd_vma value)
972{
973 bfd_vma insn;
974 reloc_howto_type *howto;
975 howto = lookup_howto ((unsigned) ELF32_R_TYPE (rello->r_info));
976 insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
977
978 /* Adjust for PC-relative relocation. */
979 value -= (input_section->output_section->vma
980 + input_section->output_offset);
981 value -= rello->r_offset;
982
983 /* Relocate. */
984 value += rello->r_addend;
985
986 /* Adjust value by 4 and insert the field. */
987 value = ((value - 4) >> howto->rightshift) & howto->dst_mask;
988 insn = (insn & ~howto->dst_mask) | value;
989
990 bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
991 return bfd_reloc_ok;
992
993}
994
995/* Specialized relocation handler for R_860_HIGHADJ. */
996static bfd_reloc_status_type
997elf32_i860_relocate_highadj (bfd *input_bfd,
998 Elf_Internal_Rela *rel,
999 bfd_byte *contents,
1000 bfd_vma value)
1001{
1002 bfd_vma insn;
1003
1004 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
1005
1006 value += rel->r_addend;
1007 value += 0x8000;
1008 value = ((value >> 16) & 0xffff);
1009
1010 insn = (insn & 0xffff0000) | value;
1011
1012 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
1013 return bfd_reloc_ok;
1014}
1015
1016/* Perform a single relocation. By default we use the standard BFD
1017 routines. However, we handle some specially. */
1018static bfd_reloc_status_type
1019i860_final_link_relocate (reloc_howto_type *howto,
1020 bfd *input_bfd,
1021 asection *input_section,
1022 bfd_byte *contents,
1023 Elf_Internal_Rela *rel,
1024 bfd_vma relocation)
1025{
1026 return _bfd_final_link_relocate (howto, input_bfd, input_section,
1027 contents, rel->r_offset, relocation,
1028 rel->r_addend);
1029}
1030
1031/* Relocate an i860 ELF section.
1032
1033 This is boiler-plate code copied from fr30.
1034
1035 The RELOCATE_SECTION function is called by the new ELF backend linker
1036 to handle the relocations for a section.
1037
1038 The relocs are always passed as Rela structures; if the section
1039 actually uses Rel structures, the r_addend field will always be
1040 zero.
1041
1042 This function is responsible for adjusting the section contents as
1043 necessary, and (if using Rela relocs and generating a relocatable
1044 output file) adjusting the reloc addend as necessary.
1045
1046 This function does not have to worry about setting the reloc
1047 address or the reloc symbol index.
1048
1049 LOCAL_SYMS is a pointer to the swapped in local symbols.
1050
1051 LOCAL_SECTIONS is an array giving the section in the input file
1052 corresponding to the st_shndx field of each local symbol.
1053
1054 The global hash table entry for the global symbols can be found
1055 via elf_sym_hashes (input_bfd).
1056
1057 When generating relocatable output, this function must handle
1058 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1059 going to be the section symbol corresponding to the output
1060 section, which means that the addend must be adjusted
1061 accordingly. */
1062static bfd_boolean
1063elf32_i860_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
1064 struct bfd_link_info *info,
1065 bfd *input_bfd,
1066 asection *input_section,
1067 bfd_byte *contents,
1068 Elf_Internal_Rela *relocs,
1069 Elf_Internal_Sym *local_syms,
1070 asection **local_sections)
1071{
1072 Elf_Internal_Shdr *symtab_hdr;
1073 struct elf_link_hash_entry **sym_hashes;
1074 Elf_Internal_Rela *rel;
1075 Elf_Internal_Rela *relend;
1076
1077 if (info->relocatable)
1078 return TRUE;
1079
1080 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1081 sym_hashes = elf_sym_hashes (input_bfd);
1082 relend = relocs + input_section->reloc_count;
1083
1084 for (rel = relocs; rel < relend; rel ++)
1085 {
1086 reloc_howto_type * howto;
1087 unsigned long r_symndx;
1088 Elf_Internal_Sym * sym;
1089 asection * sec;
1090 struct elf_link_hash_entry * h;
1091 bfd_vma relocation;
1092 bfd_reloc_status_type r;
1093 const char * name = NULL;
1094 int r_type;
1095
1096 r_type = ELF32_R_TYPE (rel->r_info);
1097
1098#if 0
1099 if ( r_type == R_860_GNU_VTINHERIT
1100 || r_type == R_860_GNU_VTENTRY)
1101 continue;
1102#endif
1103
1104 r_symndx = ELF32_R_SYM (rel->r_info);
1105
1106 howto = lookup_howto ((unsigned) ELF32_R_TYPE (rel->r_info));
1107 h = NULL;
1108 sym = NULL;
1109 sec = NULL;
1110
1111 if (r_symndx < symtab_hdr->sh_info)
1112 {
1113 sym = local_syms + r_symndx;
1114 sec = local_sections [r_symndx];
1115 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1116
1117 name = bfd_elf_string_from_elf_section
1118 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1119 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1120 }
1121 else
1122 {
1123 bfd_boolean unresolved_reloc, warned;
1124
1125 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1126 r_symndx, symtab_hdr, sym_hashes,
1127 h, sec, relocation,
1128 unresolved_reloc, warned);
1129 }
1130
1131 switch (r_type)
1132 {
1133 default:
1134 r = i860_final_link_relocate (howto, input_bfd, input_section,
1135 contents, rel, relocation);
1136 break;
1137
1138 case R_860_HIGHADJ:
1139 r = elf32_i860_relocate_highadj (input_bfd, rel, contents,
1140 relocation);
1141 break;
1142
1143 case R_860_PC16:
1144 r = elf32_i860_relocate_pc16 (input_bfd, input_section, rel,
1145 contents, relocation);
1146 break;
1147
1148 case R_860_PC26:
1149 r = elf32_i860_relocate_pc26 (input_bfd, input_section, rel,
1150 contents, relocation);
1151 break;
1152
1153 case R_860_SPLIT0:
1154 case R_860_SPLIT1:
1155 case R_860_SPLIT2:
1156 r = elf32_i860_relocate_splitn (input_bfd, rel, contents,
1157 relocation);
1158 break;
1159
1160 /* We do not yet handle GOT/PLT/Dynamic relocations. */
1161 case R_860_COPY:
1162 case R_860_GLOB_DAT:
1163 case R_860_JUMP_SLOT:
1164 case R_860_RELATIVE:
1165 case R_860_PLT26:
1166 case R_860_LOGOT0:
1167 case R_860_SPGOT0:
1168 case R_860_LOGOT1:
1169 case R_860_SPGOT1:
1170 case R_860_LOGOTOFF0:
1171 case R_860_SPGOTOFF0:
1172 case R_860_LOGOTOFF1:
1173 case R_860_SPGOTOFF1:
1174 case R_860_LOGOTOFF2:
1175 case R_860_LOGOTOFF3:
1176 case R_860_LOPC:
1177 case R_860_HAGOT:
1178 case R_860_HAGOTOFF:
1179 case R_860_HAPC:
1180 case R_860_HIGOT:
1181 case R_860_HIGOTOFF:
1182 r = bfd_reloc_notsupported;
1183 break;
1184 }
1185
1186 if (r != bfd_reloc_ok)
1187 {
1188 const char * msg = (const char *) NULL;
1189
1190 switch (r)
1191 {
1192 case bfd_reloc_overflow:
1193 r = info->callbacks->reloc_overflow
1194 (info, name, howto->name, (bfd_vma) 0,
1195 input_bfd, input_section, rel->r_offset);
1196 break;
1197
1198 case bfd_reloc_undefined:
1199 r = info->callbacks->undefined_symbol
1200 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
1201 break;
1202
1203 case bfd_reloc_outofrange:
1204 msg = _("internal error: out of range error");
1205 break;
1206
1207 case bfd_reloc_notsupported:
1208 msg = _("internal error: unsupported relocation error");
1209 break;
1210
1211 case bfd_reloc_dangerous:
1212 msg = _("internal error: dangerous relocation");
1213 break;
1214
1215 default:
1216 msg = _("internal error: unknown error");
1217 break;
1218 }
1219
1220 if (msg)
1221 r = info->callbacks->warning
1222 (info, msg, name, input_bfd, input_section, rel->r_offset);
1223
1224 if (! r)
1225 return FALSE;
1226 }
1227 }
1228
1229 return TRUE;
1230}
1231
1232/* Return whether a symbol name implies a local label. SVR4/860 compilers
1233 generate labels of the form ".ep.function_name" to denote the end of a
1234 function prolog. These should be local.
1235 ??? Do any other SVR4 compilers have this convention? If so, this should
1236 be added to the generic routine. */
1237static bfd_boolean
1238elf32_i860_is_local_label_name (bfd *abfd, const char *name)
1239{
1240 if (name[0] == '.' && name[1] == 'e' && name[2] == 'p' && name[3] == '.')
1241 return TRUE;
1242
1243 return _bfd_elf_is_local_label_name (abfd, name);
1244}
1245\f
1246#define TARGET_BIG_SYM bfd_elf32_i860_vec
1247#define TARGET_BIG_NAME "elf32-i860"
1248#define TARGET_LITTLE_SYM bfd_elf32_i860_little_vec
1249#define TARGET_LITTLE_NAME "elf32-i860-little"
1250#define ELF_ARCH bfd_arch_i860
1251#define ELF_MACHINE_CODE EM_860
1252#define ELF_MAXPAGESIZE 4096
1253
1254#define elf_backend_rela_normal 1
1255#define elf_info_to_howto_rel NULL
1256#define elf_info_to_howto elf32_i860_info_to_howto_rela
1257#define elf_backend_relocate_section elf32_i860_relocate_section
1258#define bfd_elf32_bfd_reloc_type_lookup elf32_i860_reloc_type_lookup
1259#define bfd_elf32_bfd_is_local_label_name elf32_i860_is_local_label_name
1260
1261#include "elf32-target.h"
This page took 0.027508 seconds and 4 git commands to generate.