1 /* BFD back-end for Intel 860 COFF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003
3 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "coff/i860.h"
29 #include "coff/internal.h"
34 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
35 /* The page size is a guess based on ELF. */
37 #define COFF_PAGE_SIZE 0x1000
39 /* For some reason when using i860 COFF the value stored in the .text
40 section for a reference to a common symbol is the value itself plus
41 any desired offset. Ian Taylor, Cygnus Support. */
43 /* If we are producing relocatable output, we need to do some
44 adjustments to the object file that are not done by the
45 bfd_perform_relocation function. This function is called by every
46 reloc type to make any required adjustments. */
48 static bfd_reloc_status_type
49 coff_i860_reloc (bfd *abfd,
53 asection *input_section ATTRIBUTE_UNUSED,
55 char **error_message ATTRIBUTE_UNUSED)
59 if (output_bfd == (bfd *) NULL)
60 return bfd_reloc_continue;
62 if (bfd_is_com_section (symbol->section))
64 /* We are relocating a common symbol. The current value in the
65 object file is ORIG + OFFSET, where ORIG is the value of the
66 common symbol as seen by the object file when it was compiled
67 (this may be zero if the symbol was undefined) and OFFSET is
68 the offset into the common symbol (normally zero, but may be
69 non-zero when referring to a field in a common structure).
70 ORIG is the negative of reloc_entry->addend, which is set by
71 the CALC_ADDEND macro below. We want to replace the value in
72 the object file with NEW + OFFSET, where NEW is the value of
73 the common symbol which we are going to put in the final
74 object file. NEW is symbol->value. */
75 diff = symbol->value + reloc_entry->addend;
79 /* For some reason bfd_perform_relocation always effectively
80 ignores the addend for a COFF target when producing
81 relocatable output. This seems to be always wrong for 860
82 COFF, so we handle the addend here instead. */
83 diff = reloc_entry->addend;
87 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
91 reloc_howto_type *howto = reloc_entry->howto;
92 unsigned char *addr = (unsigned char *) data + reloc_entry->address;
98 char x = bfd_get_8 (abfd, addr);
100 bfd_put_8 (abfd, x, addr);
106 short x = bfd_get_16 (abfd, addr);
108 bfd_put_16 (abfd, (bfd_vma) x, addr);
114 long x = bfd_get_32 (abfd, addr);
116 bfd_put_32 (abfd, (bfd_vma) x, addr);
125 /* Now let bfd_perform_relocation finish everything up. */
126 return bfd_reloc_continue;
130 #define PCRELOFFSET FALSE
133 static reloc_howto_type howto_table[] =
141 HOWTO (R_DIR32, /* type */
143 2, /* size (0 = byte, 1 = short, 2 = long) */
145 FALSE, /* pc_relative */
147 complain_overflow_bitfield, /* complain_on_overflow */
148 coff_i860_reloc, /* special_function */
150 TRUE, /* partial_inplace */
151 0xffffffff, /* src_mask */
152 0xffffffff, /* dst_mask */
153 TRUE), /* pcrel_offset */
155 HOWTO (R_IMAGEBASE, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 FALSE, /* pc_relative */
161 complain_overflow_bitfield, /* complain_on_overflow */
162 coff_i860_reloc, /* special_function */
164 TRUE, /* partial_inplace */
165 0xffffffff, /* src_mask */
166 0xffffffff, /* dst_mask */
167 FALSE), /* pcrel_offset */
175 HOWTO (R_RELBYTE, /* type */
177 0, /* size (0 = byte, 1 = short, 2 = long) */
179 FALSE, /* pc_relative */
181 complain_overflow_bitfield, /* complain_on_overflow */
182 coff_i860_reloc, /* special_function */
184 TRUE, /* partial_inplace */
185 0x000000ff, /* src_mask */
186 0x000000ff, /* dst_mask */
187 PCRELOFFSET), /* pcrel_offset */
188 HOWTO (R_RELWORD, /* type */
190 1, /* size (0 = byte, 1 = short, 2 = long) */
192 FALSE, /* pc_relative */
194 complain_overflow_bitfield, /* complain_on_overflow */
195 coff_i860_reloc, /* special_function */
197 TRUE, /* partial_inplace */
198 0x0000ffff, /* src_mask */
199 0x0000ffff, /* dst_mask */
200 PCRELOFFSET), /* pcrel_offset */
201 HOWTO (R_RELLONG, /* type */
203 2, /* size (0 = byte, 1 = short, 2 = long) */
205 FALSE, /* pc_relative */
207 complain_overflow_bitfield, /* complain_on_overflow */
208 coff_i860_reloc, /* special_function */
210 TRUE, /* partial_inplace */
211 0xffffffff, /* src_mask */
212 0xffffffff, /* dst_mask */
213 PCRELOFFSET), /* pcrel_offset */
214 HOWTO (R_PCRBYTE, /* type */
216 0, /* size (0 = byte, 1 = short, 2 = long) */
218 TRUE, /* pc_relative */
220 complain_overflow_signed, /* complain_on_overflow */
221 coff_i860_reloc, /* special_function */
223 TRUE, /* partial_inplace */
224 0x000000ff, /* src_mask */
225 0x000000ff, /* dst_mask */
226 PCRELOFFSET), /* pcrel_offset */
227 HOWTO (R_PCRWORD, /* type */
229 1, /* size (0 = byte, 1 = short, 2 = long) */
231 TRUE, /* pc_relative */
233 complain_overflow_signed, /* complain_on_overflow */
234 coff_i860_reloc, /* special_function */
236 TRUE, /* partial_inplace */
237 0x0000ffff, /* src_mask */
238 0x0000ffff, /* dst_mask */
239 PCRELOFFSET), /* pcrel_offset */
240 HOWTO (R_PCRLONG, /* type */
242 2, /* size (0 = byte, 1 = short, 2 = long) */
244 TRUE, /* pc_relative */
246 complain_overflow_signed, /* complain_on_overflow */
247 coff_i860_reloc, /* special_function */
249 TRUE, /* partial_inplace */
250 0xffffffff, /* src_mask */
251 0xffffffff, /* dst_mask */
252 PCRELOFFSET) /* pcrel_offset */
255 /* Turn a howto into a reloc nunmber */
257 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
258 #define BADMAG(x) I860BADMAG(x)
259 #define I860 1 /* Customize coffcode.h */
261 #define RTYPE2HOWTO(cache_ptr, dst) \
262 (cache_ptr)->howto = howto_table + (dst)->r_type;
264 /* For 860 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
265 library. On some other COFF targets STYP_BSS is normally
267 #define BSS_NOLOAD_IS_SHARED_LIBRARY
269 /* Compute the addend of a reloc. If the reloc is to a common symbol,
270 the object file contains the value of the common symbol. By the
271 time this is called, the linker may be using a different symbol
272 from a different object file with a different value. Therefore, we
273 hack wildly to locate the original symbol from this file so that we
274 can make the correct adjustment. This macro sets coffsym to the
275 symbol from the original file, and uses it to set the addend value
276 correctly. If this is not a common symbol, the usual addend
277 calculation is done, except that an additional tweak is needed for
279 FIXME: This macro refers to symbols and asect; these are from the
280 calling function, not the macro arguments. */
282 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
284 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
285 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
286 coffsym = (obj_symbols (abfd) \
287 + (cache_ptr->sym_ptr_ptr - symbols)); \
289 coffsym = coff_symbol_from (abfd, ptr); \
290 if (coffsym != (coff_symbol_type *) NULL \
291 && coffsym->native->u.syment.n_scnum == 0) \
292 cache_ptr->addend = - coffsym->native->u.syment.n_value; \
293 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
294 && ptr->section != (asection *) NULL) \
295 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
297 cache_ptr->addend = 0; \
298 if (ptr && howto_table[reloc.r_type].pc_relative) \
299 cache_ptr->addend += asect->vma; \
302 /* We use the special COFF backend linker. */
303 #define coff_relocate_section _bfd_coff_generic_relocate_section
305 static reloc_howto_type *
306 coff_i860_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
308 struct internal_reloc *rel,
309 struct coff_link_hash_entry *h,
310 struct internal_syment *sym,
314 reloc_howto_type *howto;
316 howto = howto_table + rel->r_type;
318 if (howto->pc_relative)
319 *addendp += sec->vma;
321 if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
323 /* This is a common symbol. The section contents include the
324 size (sym->n_value) as an addend. The relocate_section
325 function will be adding in the final value of the symbol. We
326 need to subtract out the current size in order to get the
329 BFD_ASSERT (h != NULL);
331 /* I think we *do* want to bypass this. If we don't, I have seen some data
332 parameters get the wrong relcation address. If I link two versions
333 with and without this section bypassed and then do a binary comparison,
334 the addresses which are different can be looked up in the map. The
335 case in which this section has been bypassed has addresses which correspond
336 to values I can find in the map. */
337 *addendp -= sym->n_value;
340 /* If the output symbol is common (in which case this must be a
341 relocatable link), we need to add in the final size of the
343 if (h != NULL && h->root.type == bfd_link_hash_common)
344 *addendp += h->root.u.c.size;
349 #define coff_rtype_to_howto coff_i860_rtype_to_howto
351 #include "coffcode.h"
353 static const bfd_target *
354 i3coff_object_p(bfd *a)
356 return coff_object_p (a);
369 "coff-i860", /* name */
371 bfd_target_coff_flavour,
372 BFD_ENDIAN_LITTLE, /* data byte order is little */
373 BFD_ENDIAN_LITTLE, /* header byte order is little */
375 (HAS_RELOC | EXEC_P | /* object flags */
376 HAS_LINENO | HAS_DEBUG |
377 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
379 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
380 '_', /* leading underscore */
381 '/', /* ar_pad_char */
382 15, /* ar_max_namelen */
384 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
385 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
386 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
387 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
388 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
389 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
391 /* Note that we allow an object file to be treated as a core file as well. */
392 {_bfd_dummy_target, i3coff_object_p, /* bfd_check_format */
393 bfd_generic_archive_p, i3coff_object_p},
394 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
396 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
397 _bfd_write_archive_contents, bfd_false},
399 BFD_JUMP_TABLE_GENERIC (coff),
400 BFD_JUMP_TABLE_COPY (coff),
401 BFD_JUMP_TABLE_CORE (_bfd_nocore),
402 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
403 BFD_JUMP_TABLE_SYMBOLS (coff),
404 BFD_JUMP_TABLE_RELOCS (coff),
405 BFD_JUMP_TABLE_WRITE (coff),
406 BFD_JUMP_TABLE_LINK (coff),
407 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),