ChangeLog rotatation and copyright year update
[deliverable/binutils-gdb.git] / bfd / coff-i860.c
CommitLineData
c28b1c28 1/* BFD back-end for Intel i860 COFF files.
b90efa5b 2 Copyright (C) 1990-2015 Free Software Foundation, Inc.
252b5132
RH
3 Created mostly by substituting "860" for "386" in coff-i386.c
4 Harry Dolan <dolan@ssd.intel.com>, October 1995
5
cd123cb7 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
cd123cb7
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
252b5132 12
cd123cb7
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
cd123cb7
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132 22
252b5132 23#include "sysdep.h"
3db64b00 24#include "bfd.h"
252b5132
RH
25#include "libbfd.h"
26
27#include "coff/i860.h"
28
29#include "coff/internal.h"
30
2b5c217d
NC
31#ifndef bfd_pe_print_pdata
32#define bfd_pe_print_pdata NULL
33#endif
34
252b5132
RH
35#include "libcoff.h"
36
252b5132
RH
37
38#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
39/* The page size is a guess based on ELF. */
40
41#define COFF_PAGE_SIZE 0x1000
42
43/* For some reason when using i860 COFF the value stored in the .text
44 section for a reference to a common symbol is the value itself plus
45 any desired offset. Ian Taylor, Cygnus Support. */
46
1049f94e 47/* If we are producing relocatable output, we need to do some
252b5132
RH
48 adjustments to the object file that are not done by the
49 bfd_perform_relocation function. This function is called by every
50 reloc type to make any required adjustments. */
51
52static bfd_reloc_status_type
a62d170c
JE
53coff_i860_reloc (bfd *abfd,
54 arelent *reloc_entry,
55 asymbol *symbol,
56 void *data,
57 asection *input_section ATTRIBUTE_UNUSED,
58 bfd *output_bfd,
59 char **error_message ATTRIBUTE_UNUSED)
252b5132
RH
60{
61 symvalue diff;
62
63 if (output_bfd == (bfd *) NULL)
64 return bfd_reloc_continue;
65
252b5132
RH
66 if (bfd_is_com_section (symbol->section))
67 {
68 /* We are relocating a common symbol. The current value in the
69 object file is ORIG + OFFSET, where ORIG is the value of the
70 common symbol as seen by the object file when it was compiled
71 (this may be zero if the symbol was undefined) and OFFSET is
72 the offset into the common symbol (normally zero, but may be
73 non-zero when referring to a field in a common structure).
74 ORIG is the negative of reloc_entry->addend, which is set by
75 the CALC_ADDEND macro below. We want to replace the value in
76 the object file with NEW + OFFSET, where NEW is the value of
77 the common symbol which we are going to put in the final
78 object file. NEW is symbol->value. */
79 diff = symbol->value + reloc_entry->addend;
80 }
81 else
82 {
83 /* For some reason bfd_perform_relocation always effectively
84 ignores the addend for a COFF target when producing
1049f94e 85 relocatable output. This seems to be always wrong for 860
252b5132
RH
86 COFF, so we handle the addend here instead. */
87 diff = reloc_entry->addend;
88 }
89
252b5132
RH
90#define DOIT(x) \
91 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
92
93 if (diff != 0)
94 {
95 reloc_howto_type *howto = reloc_entry->howto;
96 unsigned char *addr = (unsigned char *) data + reloc_entry->address;
97
98 switch (howto->size)
99 {
100 case 0:
101 {
102 char x = bfd_get_8 (abfd, addr);
103 DOIT (x);
104 bfd_put_8 (abfd, x, addr);
105 }
106 break;
107
108 case 1:
109 {
110 short x = bfd_get_16 (abfd, addr);
111 DOIT (x);
dc810e39 112 bfd_put_16 (abfd, (bfd_vma) x, addr);
252b5132
RH
113 }
114 break;
115
116 case 2:
117 {
118 long x = bfd_get_32 (abfd, addr);
119 DOIT (x);
dc810e39 120 bfd_put_32 (abfd, (bfd_vma) x, addr);
252b5132
RH
121 }
122 break;
123
124 default:
125 abort ();
126 }
127 }
128
129 /* Now let bfd_perform_relocation finish everything up. */
130 return bfd_reloc_continue;
131}
132
68ffbac6 133/* This is just a temporary measure until we teach bfd to generate
c28b1c28
JE
134 these relocations. */
135
136static bfd_reloc_status_type
137coff_i860_reloc_nyi (bfd *abfd ATTRIBUTE_UNUSED,
138 arelent *reloc_entry,
139 asymbol *symbol ATTRIBUTE_UNUSED,
140 void *data ATTRIBUTE_UNUSED,
141 asection *input_section ATTRIBUTE_UNUSED,
142 bfd *output_bfd ATTRIBUTE_UNUSED,
143 char **error_message ATTRIBUTE_UNUSED)
144{
145 reloc_howto_type *howto = reloc_entry->howto;
4a97a0e5 146 (*_bfd_error_handler) (_("relocation `%s' not yet implemented"), howto->name);
1a101a42 147 return bfd_reloc_notsupported;
c28b1c28
JE
148}
149
252b5132 150#ifndef PCRELOFFSET
b34976b6 151#define PCRELOFFSET FALSE
252b5132
RH
152#endif
153
5fcfd273 154static reloc_howto_type howto_table[] =
252b5132 155{
5f771d47
ILT
156 EMPTY_HOWTO (0),
157 EMPTY_HOWTO (1),
158 EMPTY_HOWTO (2),
159 EMPTY_HOWTO (3),
160 EMPTY_HOWTO (4),
161 EMPTY_HOWTO (5),
5fcfd273
KH
162 HOWTO (R_DIR32, /* type */
163 0, /* rightshift */
164 2, /* size (0 = byte, 1 = short, 2 = long) */
165 32, /* bitsize */
b34976b6 166 FALSE, /* pc_relative */
5fcfd273 167 0, /* bitpos */
252b5132 168 complain_overflow_bitfield, /* complain_on_overflow */
5fcfd273
KH
169 coff_i860_reloc, /* special_function */
170 "dir32", /* name */
b34976b6 171 TRUE, /* partial_inplace */
5fcfd273
KH
172 0xffffffff, /* src_mask */
173 0xffffffff, /* dst_mask */
b34976b6 174 TRUE), /* pcrel_offset */
252b5132 175 /* {7}, */
5fcfd273
KH
176 HOWTO (R_IMAGEBASE, /* type */
177 0, /* rightshift */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
179 32, /* bitsize */
b34976b6 180 FALSE, /* pc_relative */
5fcfd273 181 0, /* bitpos */
252b5132 182 complain_overflow_bitfield, /* complain_on_overflow */
5fcfd273
KH
183 coff_i860_reloc, /* special_function */
184 "rva32", /* name */
b34976b6 185 TRUE, /* partial_inplace */
5fcfd273
KH
186 0xffffffff, /* src_mask */
187 0xffffffff, /* dst_mask */
b34976b6 188 FALSE), /* pcrel_offset */
5f771d47
ILT
189 EMPTY_HOWTO (010),
190 EMPTY_HOWTO (011),
191 EMPTY_HOWTO (012),
192 EMPTY_HOWTO (013),
193 EMPTY_HOWTO (014),
194 EMPTY_HOWTO (015),
195 EMPTY_HOWTO (016),
5fcfd273
KH
196 HOWTO (R_RELBYTE, /* type */
197 0, /* rightshift */
198 0, /* size (0 = byte, 1 = short, 2 = long) */
199 8, /* bitsize */
b34976b6 200 FALSE, /* pc_relative */
5fcfd273 201 0, /* bitpos */
252b5132 202 complain_overflow_bitfield, /* complain_on_overflow */
5fcfd273
KH
203 coff_i860_reloc, /* special_function */
204 "8", /* name */
b34976b6 205 TRUE, /* partial_inplace */
5fcfd273
KH
206 0x000000ff, /* src_mask */
207 0x000000ff, /* dst_mask */
252b5132 208 PCRELOFFSET), /* pcrel_offset */
5fcfd273
KH
209 HOWTO (R_RELWORD, /* type */
210 0, /* rightshift */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
212 16, /* bitsize */
b34976b6 213 FALSE, /* pc_relative */
5fcfd273 214 0, /* bitpos */
252b5132 215 complain_overflow_bitfield, /* complain_on_overflow */
5fcfd273
KH
216 coff_i860_reloc, /* special_function */
217 "16", /* name */
b34976b6 218 TRUE, /* partial_inplace */
5fcfd273
KH
219 0x0000ffff, /* src_mask */
220 0x0000ffff, /* dst_mask */
252b5132 221 PCRELOFFSET), /* pcrel_offset */
5fcfd273
KH
222 HOWTO (R_RELLONG, /* type */
223 0, /* rightshift */
224 2, /* size (0 = byte, 1 = short, 2 = long) */
225 32, /* bitsize */
b34976b6 226 FALSE, /* pc_relative */
5fcfd273 227 0, /* bitpos */
252b5132 228 complain_overflow_bitfield, /* complain_on_overflow */
5fcfd273
KH
229 coff_i860_reloc, /* special_function */
230 "32", /* name */
b34976b6 231 TRUE, /* partial_inplace */
5fcfd273
KH
232 0xffffffff, /* src_mask */
233 0xffffffff, /* dst_mask */
252b5132 234 PCRELOFFSET), /* pcrel_offset */
5fcfd273
KH
235 HOWTO (R_PCRBYTE, /* type */
236 0, /* rightshift */
237 0, /* size (0 = byte, 1 = short, 2 = long) */
238 8, /* bitsize */
b34976b6 239 TRUE, /* pc_relative */
5fcfd273 240 0, /* bitpos */
252b5132 241 complain_overflow_signed, /* complain_on_overflow */
5fcfd273
KH
242 coff_i860_reloc, /* special_function */
243 "DISP8", /* name */
b34976b6 244 TRUE, /* partial_inplace */
5fcfd273
KH
245 0x000000ff, /* src_mask */
246 0x000000ff, /* dst_mask */
252b5132 247 PCRELOFFSET), /* pcrel_offset */
5fcfd273
KH
248 HOWTO (R_PCRWORD, /* type */
249 0, /* rightshift */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
251 16, /* bitsize */
b34976b6 252 TRUE, /* pc_relative */
5fcfd273 253 0, /* bitpos */
252b5132 254 complain_overflow_signed, /* complain_on_overflow */
5fcfd273
KH
255 coff_i860_reloc, /* special_function */
256 "DISP16", /* name */
b34976b6 257 TRUE, /* partial_inplace */
5fcfd273
KH
258 0x0000ffff, /* src_mask */
259 0x0000ffff, /* dst_mask */
252b5132 260 PCRELOFFSET), /* pcrel_offset */
5fcfd273
KH
261 HOWTO (R_PCRLONG, /* type */
262 0, /* rightshift */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
264 32, /* bitsize */
b34976b6 265 TRUE, /* pc_relative */
5fcfd273 266 0, /* bitpos */
252b5132 267 complain_overflow_signed, /* complain_on_overflow */
5fcfd273
KH
268 coff_i860_reloc, /* special_function */
269 "DISP32", /* name */
b34976b6 270 TRUE, /* partial_inplace */
5fcfd273
KH
271 0xffffffff, /* src_mask */
272 0xffffffff, /* dst_mask */
c28b1c28
JE
273 PCRELOFFSET), /* pcrel_offset */
274 EMPTY_HOWTO (0x15),
275 EMPTY_HOWTO (0x16),
276 EMPTY_HOWTO (0x17),
277 EMPTY_HOWTO (0x18),
278 EMPTY_HOWTO (0x19),
279 EMPTY_HOWTO (0x1a),
280 EMPTY_HOWTO (0x1b),
281 HOWTO (COFF860_R_PAIR, /* type */
282 0, /* rightshift */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
284 16, /* bitsize */
285 FALSE, /* pc_relative */
286 0, /* bitpos */
287 complain_overflow_dont, /* complain_on_overflow */
288 coff_i860_reloc_nyi, /* special_function */
289 "PAIR", /* name */
290 FALSE, /* partial_inplace */
291 0xffff, /* src_mask */
292 0xffff, /* dst_mask */
293 FALSE), /* pcrel_offset */
294 EMPTY_HOWTO (0x1d),
295 HOWTO (COFF860_R_HIGH, /* type */
296 16, /* rightshift */
297 2, /* size (0 = byte, 1 = short, 2 = long) */
298 16, /* bitsize */
299 FALSE, /* pc_relative */
300 0, /* bitpos */
301 complain_overflow_dont, /* complain_on_overflow */
302 coff_i860_reloc, /* special_function */
303 "HIGH", /* name */
304 FALSE, /* partial_inplace */
305 0xffff, /* src_mask */
306 0xffff, /* dst_mask */
307 FALSE), /* pcrel_offset */
308 HOWTO (COFF860_R_LOW0, /* type */
309 0, /* rightshift */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
311 16, /* bitsize */
312 FALSE, /* pc_relative */
313 0, /* bitpos */
314 complain_overflow_dont, /* complain_on_overflow */
315 coff_i860_reloc, /* special_function */
316 "LOW0", /* name */
317 FALSE, /* partial_inplace */
318 0xffff, /* src_mask */
319 0xffff, /* dst_mask */
320 FALSE), /* pcrel_offset */
321 HOWTO (COFF860_R_LOW1, /* type */
322 0, /* rightshift */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
324 16, /* bitsize */
325 FALSE, /* pc_relative */
326 0, /* bitpos */
327 complain_overflow_dont, /* complain_on_overflow */
328 coff_i860_reloc, /* special_function */
329 "LOW1", /* name */
330 FALSE, /* partial_inplace */
331 0xfffe, /* src_mask */
332 0xfffe, /* dst_mask */
333 FALSE), /* pcrel_offset */
334 HOWTO (COFF860_R_LOW2, /* type */
335 0, /* rightshift */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
337 16, /* bitsize */
338 FALSE, /* pc_relative */
339 0, /* bitpos */
340 complain_overflow_dont, /* complain_on_overflow */
341 coff_i860_reloc, /* special_function */
342 "LOW2", /* name */
343 FALSE, /* partial_inplace */
344 0xfffc, /* src_mask */
345 0xfffc, /* dst_mask */
346 FALSE), /* pcrel_offset */
347 HOWTO (COFF860_R_LOW3, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 16, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_dont, /* complain_on_overflow */
354 coff_i860_reloc, /* special_function */
355 "LOW3", /* name */
356 FALSE, /* partial_inplace */
357 0xfff8, /* src_mask */
358 0xfff8, /* dst_mask */
359 FALSE), /* pcrel_offset */
360 HOWTO (COFF860_R_LOW4, /* type */
361 0, /* rightshift */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
363 16, /* bitsize */
364 FALSE, /* pc_relative */
365 0, /* bitpos */
366 complain_overflow_dont, /* complain_on_overflow */
367 coff_i860_reloc, /* special_function */
368 "LOW4", /* name */
369 FALSE, /* partial_inplace */
370 0xfff0, /* src_mask */
371 0xfff0, /* dst_mask */
372 FALSE), /* pcrel_offset */
373 HOWTO (COFF860_R_SPLIT0, /* type */
374 0, /* rightshift */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
376 16, /* bitsize */
377 FALSE, /* pc_relative */
378 0, /* bitpos */
379 complain_overflow_dont, /* complain_on_overflow */
380 coff_i860_reloc_nyi, /* special_function */
381 "SPLIT0", /* name */
382 FALSE, /* partial_inplace */
383 0x1f07ff, /* src_mask */
384 0x1f07ff, /* dst_mask */
385 FALSE), /* pcrel_offset */
386 HOWTO (COFF860_R_SPLIT1, /* type */
387 0, /* rightshift */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
389 16, /* bitsize */
390 FALSE, /* pc_relative */
391 0, /* bitpos */
392 complain_overflow_dont, /* complain_on_overflow */
393 coff_i860_reloc_nyi, /* special_function */
394 "SPLIT1", /* name */
395 FALSE, /* partial_inplace */
396 0x1f07fe, /* src_mask */
397 0x1f07fe, /* dst_mask */
398 FALSE), /* pcrel_offset */
399 HOWTO (COFF860_R_SPLIT2, /* type */
400 0, /* rightshift */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
402 16, /* bitsize */
403 FALSE, /* pc_relative */
404 0, /* bitpos */
405 complain_overflow_dont, /* complain_on_overflow */
406 coff_i860_reloc_nyi, /* special_function */
407 "SPLIT2", /* name */
408 FALSE, /* partial_inplace */
409 0x1f07fc, /* src_mask */
410 0x1f07fc, /* dst_mask */
411 FALSE), /* pcrel_offset */
412 HOWTO (COFF860_R_HIGHADJ, /* type */
413 0, /* rightshift */
414 2, /* size (0 = byte, 1 = short, 2 = long) */
415 16, /* bitsize */
416 FALSE, /* pc_relative */
417 0, /* bitpos */
418 complain_overflow_dont, /* complain_on_overflow */
419 coff_i860_reloc_nyi, /* special_function */
420 "HIGHADJ", /* name */
421 FALSE, /* partial_inplace */
422 0xffff, /* src_mask */
423 0xffff, /* dst_mask */
424 FALSE), /* pcrel_offset */
425 HOWTO (COFF860_R_BRADDR, /* type */
426 2, /* rightshift */
427 2, /* size (0 = byte, 1 = short, 2 = long) */
428 26, /* bitsize */
429 TRUE, /* pc_relative */
430 0, /* bitpos */
431 complain_overflow_bitfield, /* complain_on_overflow */
432 coff_i860_reloc_nyi, /* special_function */
433 "BRADDR", /* name */
434 FALSE, /* partial_inplace */
435 0x3ffffff, /* src_mask */
436 0x3ffffff, /* dst_mask */
437 TRUE) /* pcrel_offset */
252b5132
RH
438};
439
c28b1c28 440/* Turn a howto into a reloc number. */
252b5132
RH
441
442#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
443#define BADMAG(x) I860BADMAG(x)
444#define I860 1 /* Customize coffcode.h */
445
c28b1c28
JE
446#define RTYPE2HOWTO(cache_ptr, dst) \
447 ((cache_ptr)->howto = \
448 ((dst)->r_type < sizeof (howto_table) / sizeof (howto_table[0]) \
449 ? howto_table + (dst)->r_type \
450 : NULL))
252b5132
RH
451
452/* For 860 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
453 library. On some other COFF targets STYP_BSS is normally
454 STYP_NOLOAD. */
455#define BSS_NOLOAD_IS_SHARED_LIBRARY
456
457/* Compute the addend of a reloc. If the reloc is to a common symbol,
458 the object file contains the value of the common symbol. By the
459 time this is called, the linker may be using a different symbol
460 from a different object file with a different value. Therefore, we
461 hack wildly to locate the original symbol from this file so that we
462 can make the correct adjustment. This macro sets coffsym to the
463 symbol from the original file, and uses it to set the addend value
464 correctly. If this is not a common symbol, the usual addend
465 calculation is done, except that an additional tweak is needed for
466 PC relative relocs.
467 FIXME: This macro refers to symbols and asect; these are from the
468 calling function, not the macro arguments. */
469
6d1227b8 470#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)
252b5132
RH
471
472/* We use the special COFF backend linker. */
473#define coff_relocate_section _bfd_coff_generic_relocate_section
474
475static reloc_howto_type *
a62d170c
JE
476coff_i860_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
477 asection *sec,
478 struct internal_reloc *rel,
479 struct coff_link_hash_entry *h,
480 struct internal_syment *sym,
481 bfd_vma *addendp)
252b5132
RH
482{
483
484 reloc_howto_type *howto;
485
c28b1c28
JE
486 if (rel->r_type > sizeof (howto_table) / sizeof (howto_table[0]))
487 {
488 bfd_set_error (bfd_error_bad_value);
489 return NULL;
490 }
491
252b5132
RH
492 howto = howto_table + rel->r_type;
493
494 if (howto->pc_relative)
495 *addendp += sec->vma;
496
497 if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
498 {
499 /* This is a common symbol. The section contents include the
500 size (sym->n_value) as an addend. The relocate_section
501 function will be adding in the final value of the symbol. We
502 need to subtract out the current size in order to get the
503 correct result. */
252b5132 504
5fcfd273 505 BFD_ASSERT (h != NULL);
252b5132
RH
506
507 /* I think we *do* want to bypass this. If we don't, I have seen some data
5c4491d3 508 parameters get the wrong relocation address. If I link two versions
252b5132 509 with and without this section bypassed and then do a binary comparison,
5fcfd273 510 the addresses which are different can be looked up in the map. The
252b5132 511 case in which this section has been bypassed has addresses which correspond
917583ad 512 to values I can find in the map. */
252b5132
RH
513 *addendp -= sym->n_value;
514 }
515
516 /* If the output symbol is common (in which case this must be a
1049f94e 517 relocatable link), we need to add in the final size of the
252b5132 518 common symbol. */
5fcfd273 519 if (h != NULL && h->root.type == bfd_link_hash_common)
252b5132
RH
520 *addendp += h->root.u.c.size;
521
522 return howto;
523}
524
c28b1c28
JE
525static reloc_howto_type *
526coff_i860_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
527 bfd_reloc_code_real_type code)
528{
529 switch (code)
530 {
531 case BFD_RELOC_32:
532 return howto_table + R_DIR32;
533 case BFD_RELOC_860_PC26:
534 return howto_table + COFF860_R_BRADDR;
535 case BFD_RELOC_860_PC16:
536 /* ??? How to handle PC16 for COFF? SPLIT0 is close for now. */
537 return howto_table + COFF860_R_SPLIT0;
538 case BFD_RELOC_860_LOW0:
539 return howto_table + COFF860_R_LOW0;
540 case BFD_RELOC_860_SPLIT0:
541 return howto_table + COFF860_R_SPLIT0;
542 case BFD_RELOC_860_LOW1:
543 return howto_table + COFF860_R_LOW1;
544 case BFD_RELOC_860_SPLIT1:
545 return howto_table + COFF860_R_SPLIT1;
546 case BFD_RELOC_860_LOW2:
547 return howto_table + COFF860_R_LOW2;
548 case BFD_RELOC_860_SPLIT2:
549 return howto_table + COFF860_R_SPLIT2;
550 case BFD_RELOC_860_LOW3:
551 return howto_table + COFF860_R_LOW3;
552 case BFD_RELOC_860_HIGHADJ:
553 return howto_table + COFF860_R_HIGHADJ;
554 case BFD_RELOC_860_HIGH:
555 return howto_table + COFF860_R_HIGH;
556 default:
557 BFD_FAIL ();
558 return 0;
559 }
560}
561
157090f7
AM
562static reloc_howto_type *
563coff_i860_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
564 const char *r_name)
565{
566 unsigned int i;
567
568 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
569 if (howto_table[i].name != NULL
570 && strcasecmp (howto_table[i].name, r_name) == 0)
571 return &howto_table[i];
572
573 return NULL;
574}
575
c28b1c28
JE
576/* This is called from coff_slurp_reloc_table for each relocation
577 entry. This special handling is due to the `PAIR' relocation
578 which has a different meaning for the `r_symndx' field. */
579
580static void
581i860_reloc_processing (arelent *cache_ptr, struct internal_reloc *dst,
582 asymbol **symbols, bfd *abfd, asection *asect)
583{
584 if (dst->r_type == COFF860_R_PAIR)
585 {
586 /* Handle the PAIR relocation specially. */
587 cache_ptr->howto = howto_table + dst->r_type;
588 cache_ptr->address = dst->r_vaddr;
589 cache_ptr->addend = dst->r_symndx;
590 cache_ptr->sym_ptr_ptr= bfd_abs_section_ptr->symbol_ptr_ptr;
591 }
592 else
593 {
594 /* For every other relocation, do exactly what coff_slurp_reloc_table
595 would do (which this code is taken directly from). */
596 asymbol *ptr = NULL;
597 cache_ptr->address = dst->r_vaddr;
598
599 if (dst->r_symndx != -1)
600 {
601 if (dst->r_symndx < 0 || dst->r_symndx >= obj_conv_table_size (abfd))
602 {
603 (*_bfd_error_handler)
d003868e
AM
604 (_("%B: warning: illegal symbol index %ld in relocs"),
605 abfd, dst->r_symndx);
c28b1c28
JE
606 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
607 ptr = NULL;
608 }
609 else
610 {
611 cache_ptr->sym_ptr_ptr = (symbols
612 + obj_convert (abfd)[dst->r_symndx]);
613 ptr = *(cache_ptr->sym_ptr_ptr);
614 }
615 }
616 else
617 {
618 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
619 ptr = NULL;
620 }
621
622 /* The symbols definitions that we have read in have been
623 relocated as if their sections started at 0. But the offsets
624 refering to the symbols in the raw data have not been
625 modified, so we have to have a negative addend to compensate.
626
627 Note that symbols which used to be common must be left alone. */
628
629 /* Calculate any reloc addend by looking at the symbol. */
630 CALC_ADDEND (abfd, ptr, (*dst), cache_ptr);
c7e2358a 631 (void) ptr;
c28b1c28
JE
632
633 cache_ptr->address -= asect->vma;
634
635 /* Fill in the cache_ptr->howto field from dst->r_type. */
636 RTYPE2HOWTO (cache_ptr, dst);
637 }
638}
639\f
640#define coff_rtype_to_howto coff_i860_rtype_to_howto
641#define coff_bfd_reloc_type_lookup coff_i860_reloc_type_lookup
157090f7 642#define coff_bfd_reloc_name_lookup coff_i860_reloc_name_lookup
c28b1c28
JE
643
644#define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \
645 i860_reloc_processing (relent, reloc, symbols, abfd, section)
252b5132
RH
646
647#include "coffcode.h"
648
649static const bfd_target *
a62d170c 650i3coff_object_p(bfd *a)
252b5132 651{
917583ad 652 return coff_object_p (a);
252b5132
RH
653}
654
655const bfd_target
656#ifdef TARGET_SYM
657 TARGET_SYM =
658#else
6d00b590 659 i860_coff_vec =
252b5132
RH
660#endif
661{
662#ifdef TARGET_NAME
663 TARGET_NAME,
664#else
665 "coff-i860", /* name */
666#endif
667 bfd_target_coff_flavour,
668 BFD_ENDIAN_LITTLE, /* data byte order is little */
669 BFD_ENDIAN_LITTLE, /* header byte order is little */
670
671 (HAS_RELOC | EXEC_P | /* object flags */
672 HAS_LINENO | HAS_DEBUG |
673 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
674
675 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
676 '_', /* leading underscore */
677 '/', /* ar_pad_char */
678 15, /* ar_max_namelen */
0aabe54e 679 0, /* match priority. */
252b5132
RH
680
681 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
682 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
683 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
684 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
685 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
686 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
687
5fcfd273 688/* Note that we allow an object file to be treated as a core file as well. */
252b5132
RH
689 {_bfd_dummy_target, i3coff_object_p, /* bfd_check_format */
690 bfd_generic_archive_p, i3coff_object_p},
691 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
692 bfd_false},
693 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
694 _bfd_write_archive_contents, bfd_false},
695
696 BFD_JUMP_TABLE_GENERIC (coff),
697 BFD_JUMP_TABLE_COPY (coff),
698 BFD_JUMP_TABLE_CORE (_bfd_nocore),
699 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
700 BFD_JUMP_TABLE_SYMBOLS (coff),
701 BFD_JUMP_TABLE_RELOCS (coff),
702 BFD_JUMP_TABLE_WRITE (coff),
703 BFD_JUMP_TABLE_LINK (coff),
704 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
705
c3c89269 706 NULL,
5fcfd273 707
c3c89269 708 COFF_SWAP_TABLE
252b5132 709};
This page took 0.902926 seconds and 4 git commands to generate.