1 /* BFD back-end for Intel i860 COFF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2007, 2008, 2010 Free Software Foundation, Inc.
4 Created mostly by substituting "860" for "386" in coff-i386.c
5 Harry Dolan <dolan@ssd.intel.com>, October 1995
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
28 #include "coff/i860.h"
30 #include "coff/internal.h"
32 #ifndef bfd_pe_print_pdata
33 #define bfd_pe_print_pdata NULL
39 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
40 /* The page size is a guess based on ELF. */
42 #define COFF_PAGE_SIZE 0x1000
44 /* For some reason when using i860 COFF the value stored in the .text
45 section for a reference to a common symbol is the value itself plus
46 any desired offset. Ian Taylor, Cygnus Support. */
48 /* If we are producing relocatable output, we need to do some
49 adjustments to the object file that are not done by the
50 bfd_perform_relocation function. This function is called by every
51 reloc type to make any required adjustments. */
53 static bfd_reloc_status_type
54 coff_i860_reloc (bfd
*abfd
,
58 asection
*input_section ATTRIBUTE_UNUSED
,
60 char **error_message ATTRIBUTE_UNUSED
)
64 if (output_bfd
== (bfd
*) NULL
)
65 return bfd_reloc_continue
;
67 if (bfd_is_com_section (symbol
->section
))
69 /* We are relocating a common symbol. The current value in the
70 object file is ORIG + OFFSET, where ORIG is the value of the
71 common symbol as seen by the object file when it was compiled
72 (this may be zero if the symbol was undefined) and OFFSET is
73 the offset into the common symbol (normally zero, but may be
74 non-zero when referring to a field in a common structure).
75 ORIG is the negative of reloc_entry->addend, which is set by
76 the CALC_ADDEND macro below. We want to replace the value in
77 the object file with NEW + OFFSET, where NEW is the value of
78 the common symbol which we are going to put in the final
79 object file. NEW is symbol->value. */
80 diff
= symbol
->value
+ reloc_entry
->addend
;
84 /* For some reason bfd_perform_relocation always effectively
85 ignores the addend for a COFF target when producing
86 relocatable output. This seems to be always wrong for 860
87 COFF, so we handle the addend here instead. */
88 diff
= reloc_entry
->addend
;
92 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
96 reloc_howto_type
*howto
= reloc_entry
->howto
;
97 unsigned char *addr
= (unsigned char *) data
+ reloc_entry
->address
;
103 char x
= bfd_get_8 (abfd
, addr
);
105 bfd_put_8 (abfd
, x
, addr
);
111 short x
= bfd_get_16 (abfd
, addr
);
113 bfd_put_16 (abfd
, (bfd_vma
) x
, addr
);
119 long x
= bfd_get_32 (abfd
, addr
);
121 bfd_put_32 (abfd
, (bfd_vma
) x
, addr
);
130 /* Now let bfd_perform_relocation finish everything up. */
131 return bfd_reloc_continue
;
134 /* This is just a temporary measure until we teach bfd to generate
135 these relocations. */
137 static bfd_reloc_status_type
138 coff_i860_reloc_nyi (bfd
*abfd ATTRIBUTE_UNUSED
,
139 arelent
*reloc_entry
,
140 asymbol
*symbol ATTRIBUTE_UNUSED
,
141 void *data ATTRIBUTE_UNUSED
,
142 asection
*input_section ATTRIBUTE_UNUSED
,
143 bfd
*output_bfd ATTRIBUTE_UNUSED
,
144 char **error_message ATTRIBUTE_UNUSED
)
146 reloc_howto_type
*howto
= reloc_entry
->howto
;
147 fprintf (stderr
, _("Relocation `%s' not yet implemented\n"), howto
->name
);
148 return bfd_reloc_notsupported
;
152 #define PCRELOFFSET FALSE
155 static reloc_howto_type howto_table
[] =
163 HOWTO (R_DIR32
, /* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 FALSE
, /* pc_relative */
169 complain_overflow_bitfield
, /* complain_on_overflow */
170 coff_i860_reloc
, /* special_function */
172 TRUE
, /* partial_inplace */
173 0xffffffff, /* src_mask */
174 0xffffffff, /* dst_mask */
175 TRUE
), /* pcrel_offset */
177 HOWTO (R_IMAGEBASE
, /* type */
179 2, /* size (0 = byte, 1 = short, 2 = long) */
181 FALSE
, /* pc_relative */
183 complain_overflow_bitfield
, /* complain_on_overflow */
184 coff_i860_reloc
, /* special_function */
186 TRUE
, /* partial_inplace */
187 0xffffffff, /* src_mask */
188 0xffffffff, /* dst_mask */
189 FALSE
), /* pcrel_offset */
197 HOWTO (R_RELBYTE
, /* type */
199 0, /* size (0 = byte, 1 = short, 2 = long) */
201 FALSE
, /* pc_relative */
203 complain_overflow_bitfield
, /* complain_on_overflow */
204 coff_i860_reloc
, /* special_function */
206 TRUE
, /* partial_inplace */
207 0x000000ff, /* src_mask */
208 0x000000ff, /* dst_mask */
209 PCRELOFFSET
), /* pcrel_offset */
210 HOWTO (R_RELWORD
, /* type */
212 1, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE
, /* pc_relative */
216 complain_overflow_bitfield
, /* complain_on_overflow */
217 coff_i860_reloc
, /* special_function */
219 TRUE
, /* partial_inplace */
220 0x0000ffff, /* src_mask */
221 0x0000ffff, /* dst_mask */
222 PCRELOFFSET
), /* pcrel_offset */
223 HOWTO (R_RELLONG
, /* type */
225 2, /* size (0 = byte, 1 = short, 2 = long) */
227 FALSE
, /* pc_relative */
229 complain_overflow_bitfield
, /* complain_on_overflow */
230 coff_i860_reloc
, /* special_function */
232 TRUE
, /* partial_inplace */
233 0xffffffff, /* src_mask */
234 0xffffffff, /* dst_mask */
235 PCRELOFFSET
), /* pcrel_offset */
236 HOWTO (R_PCRBYTE
, /* type */
238 0, /* size (0 = byte, 1 = short, 2 = long) */
240 TRUE
, /* pc_relative */
242 complain_overflow_signed
, /* complain_on_overflow */
243 coff_i860_reloc
, /* special_function */
245 TRUE
, /* partial_inplace */
246 0x000000ff, /* src_mask */
247 0x000000ff, /* dst_mask */
248 PCRELOFFSET
), /* pcrel_offset */
249 HOWTO (R_PCRWORD
, /* type */
251 1, /* size (0 = byte, 1 = short, 2 = long) */
253 TRUE
, /* pc_relative */
255 complain_overflow_signed
, /* complain_on_overflow */
256 coff_i860_reloc
, /* special_function */
258 TRUE
, /* partial_inplace */
259 0x0000ffff, /* src_mask */
260 0x0000ffff, /* dst_mask */
261 PCRELOFFSET
), /* pcrel_offset */
262 HOWTO (R_PCRLONG
, /* type */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
266 TRUE
, /* pc_relative */
268 complain_overflow_signed
, /* complain_on_overflow */
269 coff_i860_reloc
, /* special_function */
271 TRUE
, /* partial_inplace */
272 0xffffffff, /* src_mask */
273 0xffffffff, /* dst_mask */
274 PCRELOFFSET
), /* pcrel_offset */
282 HOWTO (COFF860_R_PAIR
, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE
, /* pc_relative */
288 complain_overflow_dont
, /* complain_on_overflow */
289 coff_i860_reloc_nyi
, /* special_function */
291 FALSE
, /* partial_inplace */
292 0xffff, /* src_mask */
293 0xffff, /* dst_mask */
294 FALSE
), /* pcrel_offset */
296 HOWTO (COFF860_R_HIGH
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 FALSE
, /* pc_relative */
302 complain_overflow_dont
, /* complain_on_overflow */
303 coff_i860_reloc
, /* special_function */
305 FALSE
, /* partial_inplace */
306 0xffff, /* src_mask */
307 0xffff, /* dst_mask */
308 FALSE
), /* pcrel_offset */
309 HOWTO (COFF860_R_LOW0
, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 FALSE
, /* pc_relative */
315 complain_overflow_dont
, /* complain_on_overflow */
316 coff_i860_reloc
, /* special_function */
318 FALSE
, /* partial_inplace */
319 0xffff, /* src_mask */
320 0xffff, /* dst_mask */
321 FALSE
), /* pcrel_offset */
322 HOWTO (COFF860_R_LOW1
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 FALSE
, /* pc_relative */
328 complain_overflow_dont
, /* complain_on_overflow */
329 coff_i860_reloc
, /* special_function */
331 FALSE
, /* partial_inplace */
332 0xfffe, /* src_mask */
333 0xfffe, /* dst_mask */
334 FALSE
), /* pcrel_offset */
335 HOWTO (COFF860_R_LOW2
, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
339 FALSE
, /* pc_relative */
341 complain_overflow_dont
, /* complain_on_overflow */
342 coff_i860_reloc
, /* special_function */
344 FALSE
, /* partial_inplace */
345 0xfffc, /* src_mask */
346 0xfffc, /* dst_mask */
347 FALSE
), /* pcrel_offset */
348 HOWTO (COFF860_R_LOW3
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 FALSE
, /* pc_relative */
354 complain_overflow_dont
, /* complain_on_overflow */
355 coff_i860_reloc
, /* special_function */
357 FALSE
, /* partial_inplace */
358 0xfff8, /* src_mask */
359 0xfff8, /* dst_mask */
360 FALSE
), /* pcrel_offset */
361 HOWTO (COFF860_R_LOW4
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 FALSE
, /* pc_relative */
367 complain_overflow_dont
, /* complain_on_overflow */
368 coff_i860_reloc
, /* special_function */
370 FALSE
, /* partial_inplace */
371 0xfff0, /* src_mask */
372 0xfff0, /* dst_mask */
373 FALSE
), /* pcrel_offset */
374 HOWTO (COFF860_R_SPLIT0
, /* type */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
378 FALSE
, /* pc_relative */
380 complain_overflow_dont
, /* complain_on_overflow */
381 coff_i860_reloc_nyi
, /* special_function */
383 FALSE
, /* partial_inplace */
384 0x1f07ff, /* src_mask */
385 0x1f07ff, /* dst_mask */
386 FALSE
), /* pcrel_offset */
387 HOWTO (COFF860_R_SPLIT1
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 FALSE
, /* pc_relative */
393 complain_overflow_dont
, /* complain_on_overflow */
394 coff_i860_reloc_nyi
, /* special_function */
396 FALSE
, /* partial_inplace */
397 0x1f07fe, /* src_mask */
398 0x1f07fe, /* dst_mask */
399 FALSE
), /* pcrel_offset */
400 HOWTO (COFF860_R_SPLIT2
, /* type */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
404 FALSE
, /* pc_relative */
406 complain_overflow_dont
, /* complain_on_overflow */
407 coff_i860_reloc_nyi
, /* special_function */
409 FALSE
, /* partial_inplace */
410 0x1f07fc, /* src_mask */
411 0x1f07fc, /* dst_mask */
412 FALSE
), /* pcrel_offset */
413 HOWTO (COFF860_R_HIGHADJ
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 FALSE
, /* pc_relative */
419 complain_overflow_dont
, /* complain_on_overflow */
420 coff_i860_reloc_nyi
, /* special_function */
421 "HIGHADJ", /* name */
422 FALSE
, /* partial_inplace */
423 0xffff, /* src_mask */
424 0xffff, /* dst_mask */
425 FALSE
), /* pcrel_offset */
426 HOWTO (COFF860_R_BRADDR
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 TRUE
, /* pc_relative */
432 complain_overflow_bitfield
, /* complain_on_overflow */
433 coff_i860_reloc_nyi
, /* special_function */
435 FALSE
, /* partial_inplace */
436 0x3ffffff, /* src_mask */
437 0x3ffffff, /* dst_mask */
438 TRUE
) /* pcrel_offset */
441 /* Turn a howto into a reloc number. */
443 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
444 #define BADMAG(x) I860BADMAG(x)
445 #define I860 1 /* Customize coffcode.h */
447 #define RTYPE2HOWTO(cache_ptr, dst) \
448 ((cache_ptr)->howto = \
449 ((dst)->r_type < sizeof (howto_table) / sizeof (howto_table[0]) \
450 ? howto_table + (dst)->r_type \
453 /* For 860 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
454 library. On some other COFF targets STYP_BSS is normally
456 #define BSS_NOLOAD_IS_SHARED_LIBRARY
458 /* Compute the addend of a reloc. If the reloc is to a common symbol,
459 the object file contains the value of the common symbol. By the
460 time this is called, the linker may be using a different symbol
461 from a different object file with a different value. Therefore, we
462 hack wildly to locate the original symbol from this file so that we
463 can make the correct adjustment. This macro sets coffsym to the
464 symbol from the original file, and uses it to set the addend value
465 correctly. If this is not a common symbol, the usual addend
466 calculation is done, except that an additional tweak is needed for
468 FIXME: This macro refers to symbols and asect; these are from the
469 calling function, not the macro arguments. */
471 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)
473 /* We use the special COFF backend linker. */
474 #define coff_relocate_section _bfd_coff_generic_relocate_section
476 static reloc_howto_type
*
477 coff_i860_rtype_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
479 struct internal_reloc
*rel
,
480 struct coff_link_hash_entry
*h
,
481 struct internal_syment
*sym
,
485 reloc_howto_type
*howto
;
487 if (rel
->r_type
> sizeof (howto_table
) / sizeof (howto_table
[0]))
489 bfd_set_error (bfd_error_bad_value
);
493 howto
= howto_table
+ rel
->r_type
;
495 if (howto
->pc_relative
)
496 *addendp
+= sec
->vma
;
498 if (sym
!= NULL
&& sym
->n_scnum
== 0 && sym
->n_value
!= 0)
500 /* This is a common symbol. The section contents include the
501 size (sym->n_value) as an addend. The relocate_section
502 function will be adding in the final value of the symbol. We
503 need to subtract out the current size in order to get the
506 BFD_ASSERT (h
!= NULL
);
508 /* I think we *do* want to bypass this. If we don't, I have seen some data
509 parameters get the wrong relocation address. If I link two versions
510 with and without this section bypassed and then do a binary comparison,
511 the addresses which are different can be looked up in the map. The
512 case in which this section has been bypassed has addresses which correspond
513 to values I can find in the map. */
514 *addendp
-= sym
->n_value
;
517 /* If the output symbol is common (in which case this must be a
518 relocatable link), we need to add in the final size of the
520 if (h
!= NULL
&& h
->root
.type
== bfd_link_hash_common
)
521 *addendp
+= h
->root
.u
.c
.size
;
526 static reloc_howto_type
*
527 coff_i860_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
528 bfd_reloc_code_real_type code
)
533 return howto_table
+ R_DIR32
;
534 case BFD_RELOC_860_PC26
:
535 return howto_table
+ COFF860_R_BRADDR
;
536 case BFD_RELOC_860_PC16
:
537 /* ??? How to handle PC16 for COFF? SPLIT0 is close for now. */
538 return howto_table
+ COFF860_R_SPLIT0
;
539 case BFD_RELOC_860_LOW0
:
540 return howto_table
+ COFF860_R_LOW0
;
541 case BFD_RELOC_860_SPLIT0
:
542 return howto_table
+ COFF860_R_SPLIT0
;
543 case BFD_RELOC_860_LOW1
:
544 return howto_table
+ COFF860_R_LOW1
;
545 case BFD_RELOC_860_SPLIT1
:
546 return howto_table
+ COFF860_R_SPLIT1
;
547 case BFD_RELOC_860_LOW2
:
548 return howto_table
+ COFF860_R_LOW2
;
549 case BFD_RELOC_860_SPLIT2
:
550 return howto_table
+ COFF860_R_SPLIT2
;
551 case BFD_RELOC_860_LOW3
:
552 return howto_table
+ COFF860_R_LOW3
;
553 case BFD_RELOC_860_HIGHADJ
:
554 return howto_table
+ COFF860_R_HIGHADJ
;
555 case BFD_RELOC_860_HIGH
:
556 return howto_table
+ COFF860_R_HIGH
;
563 static reloc_howto_type
*
564 coff_i860_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
569 for (i
= 0; i
< sizeof (howto_table
) / sizeof (howto_table
[0]); i
++)
570 if (howto_table
[i
].name
!= NULL
571 && strcasecmp (howto_table
[i
].name
, r_name
) == 0)
572 return &howto_table
[i
];
577 /* This is called from coff_slurp_reloc_table for each relocation
578 entry. This special handling is due to the `PAIR' relocation
579 which has a different meaning for the `r_symndx' field. */
582 i860_reloc_processing (arelent
*cache_ptr
, struct internal_reloc
*dst
,
583 asymbol
**symbols
, bfd
*abfd
, asection
*asect
)
585 if (dst
->r_type
== COFF860_R_PAIR
)
587 /* Handle the PAIR relocation specially. */
588 cache_ptr
->howto
= howto_table
+ dst
->r_type
;
589 cache_ptr
->address
= dst
->r_vaddr
;
590 cache_ptr
->addend
= dst
->r_symndx
;
591 cache_ptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
595 /* For every other relocation, do exactly what coff_slurp_reloc_table
596 would do (which this code is taken directly from). */
598 cache_ptr
->address
= dst
->r_vaddr
;
600 if (dst
->r_symndx
!= -1)
602 if (dst
->r_symndx
< 0 || dst
->r_symndx
>= obj_conv_table_size (abfd
))
604 (*_bfd_error_handler
)
605 (_("%B: warning: illegal symbol index %ld in relocs"),
606 abfd
, dst
->r_symndx
);
607 cache_ptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
612 cache_ptr
->sym_ptr_ptr
= (symbols
613 + obj_convert (abfd
)[dst
->r_symndx
]);
614 ptr
= *(cache_ptr
->sym_ptr_ptr
);
619 cache_ptr
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
623 /* The symbols definitions that we have read in have been
624 relocated as if their sections started at 0. But the offsets
625 refering to the symbols in the raw data have not been
626 modified, so we have to have a negative addend to compensate.
628 Note that symbols which used to be common must be left alone. */
630 /* Calculate any reloc addend by looking at the symbol. */
631 CALC_ADDEND (abfd
, ptr
, (*dst
), cache_ptr
);
634 cache_ptr
->address
-= asect
->vma
;
636 /* Fill in the cache_ptr->howto field from dst->r_type. */
637 RTYPE2HOWTO (cache_ptr
, dst
);
641 #define coff_rtype_to_howto coff_i860_rtype_to_howto
642 #define coff_bfd_reloc_type_lookup coff_i860_reloc_type_lookup
643 #define coff_bfd_reloc_name_lookup coff_i860_reloc_name_lookup
645 #define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \
646 i860_reloc_processing (relent, reloc, symbols, abfd, section)
648 #include "coffcode.h"
650 static const bfd_target
*
651 i3coff_object_p(bfd
*a
)
653 return coff_object_p (a
);
666 "coff-i860", /* name */
668 bfd_target_coff_flavour
,
669 BFD_ENDIAN_LITTLE
, /* data byte order is little */
670 BFD_ENDIAN_LITTLE
, /* header byte order is little */
672 (HAS_RELOC
| EXEC_P
| /* object flags */
673 HAS_LINENO
| HAS_DEBUG
|
674 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
676 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
677 '_', /* leading underscore */
678 '/', /* ar_pad_char */
679 15, /* ar_max_namelen */
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 */
688 /* Note that we allow an object file to be treated as a core file as well. */
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 */
693 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
694 _bfd_write_archive_contents
, bfd_false
},
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
),