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