Commit | Line | Data |
---|---|---|
6812b607 | 1 | /* BFD back-end for Intel 960 COFF files. |
22aabad5 | 2 | Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
3b4f1a5d | 3 | Written by Cygnus Support. |
fc723380 | 4 | |
3b4f1a5d | 5 | This file is part of BFD, the Binary File Descriptor library. |
4a81b561 | 6 | |
3b4f1a5d | 7 | This program is free software; you can redistribute it and/or modify |
4a81b561 | 8 | it under the terms of the GNU General Public License as published by |
3b4f1a5d SC |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
4a81b561 | 11 | |
3b4f1a5d | 12 | This program is distributed in the hope that it will be useful, |
4a81b561 DHW |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
3b4f1a5d SC |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
4a81b561 | 20 | |
4a81b561 | 21 | #define I960 1 |
fc723380 JG |
22 | #define BADMAG(x) I960BADMAG(x) |
23 | ||
4a81b561 | 24 | #include "bfd.h" |
3b4f1a5d | 25 | #include "sysdep.h" |
4a81b561 | 26 | #include "libbfd.h" |
9872a49c | 27 | #include "obstack.h" |
8070f29d KR |
28 | #include "coff/i960.h" |
29 | #include "coff/internal.h" | |
4a81b561 | 30 | #include "libcoff.h" /* to allow easier abstraction-breaking */ |
6812b607 ILT |
31 | |
32 | static bfd_reloc_status_type optcall_callback | |
33 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
5e694c29 JMD |
34 | static bfd_reloc_status_type coff_i960_relocate |
35 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
36 | ||
294eaca4 | 37 | #define COFF_LONG_FILENAMES |
4a81b561 | 38 | |
4a81b561 DHW |
39 | #define CALLS 0x66003800 /* Template for 'calls' instruction */ |
40 | #define BAL 0x0b000000 /* Template for 'bal' instruction */ | |
41 | #define BAL_MASK 0x00ffffff | |
42 | ||
3b4f1a5d | 43 | static bfd_reloc_status_type |
6812b607 ILT |
44 | optcall_callback (abfd, reloc_entry, symbol_in, data, |
45 | ignore_input_section, ignore_bfd, error_message) | |
46 | bfd *abfd; | |
47 | arelent *reloc_entry; | |
48 | asymbol *symbol_in; | |
49 | PTR data; | |
50 | asection *ignore_input_section; | |
51 | bfd *ignore_bfd; | |
52 | char **error_message; | |
4a81b561 DHW |
53 | { |
54 | /* This item has already been relocated correctly, but we may be | |
55 | * able to patch in yet better code - done by digging out the | |
56 | * correct info on this symbol */ | |
3b4f1a5d | 57 | bfd_reloc_status_type result; |
4a81b561 DHW |
58 | coff_symbol_type *cs = coffsymbol(symbol_in); |
59 | ||
fc723380 JG |
60 | /* So the target symbol has to be of coff type, and the symbol |
61 | has to have the correct native information within it */ | |
6812b607 ILT |
62 | if ((bfd_asymbol_flavour(&cs->symbol) != bfd_target_coff_flavour) |
63 | || (cs->native == (combined_entry_type *)NULL)) | |
64 | { | |
65 | /* This is interesting, consider the case where we're outputting coff | |
66 | from a mix n match input, linking from coff to a symbol defined in a | |
67 | bout file will cause this match to be true. Should I complain? This | |
68 | will only work if the bout symbol is non leaf. */ | |
69 | *error_message = | |
70 | (char *) "uncertain calling convention for non-COFF symbol"; | |
71 | result = bfd_reloc_dangerous; | |
72 | } | |
73 | else | |
74 | { | |
3b4f1a5d | 75 | switch (cs->native->u.syment.n_sclass) |
4a81b561 DHW |
76 | { |
77 | case C_LEAFSTAT: | |
78 | case C_LEAFEXT: | |
79 | /* This is a call to a leaf procedure, replace instruction with a bal | |
6812b607 | 80 | to the correct location. */ |
4a81b561 | 81 | { |
3b4f1a5d | 82 | union internal_auxent *aux = &((cs->native+2)->u.auxent); |
8070f29d | 83 | int word = bfd_get_32(abfd, (bfd_byte *)data + reloc_entry->address); |
3b4f1a5d SC |
84 | int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value); |
85 | BFD_ASSERT(cs->native->u.syment.n_numaux==2); | |
8e3c8f47 | 86 | |
6812b607 ILT |
87 | /* We replace the original call instruction with a bal to |
88 | the bal entry point - the offset of which is described in | |
89 | the 2nd auxent of the original symbol. We keep the native | |
90 | sym and auxents untouched, so the delta between the two | |
91 | is the offset of the bal entry point. */ | |
8e3c8f47 | 92 | word = ((word + olf) & BAL_MASK) | BAL; |
8070f29d | 93 | bfd_put_32(abfd, word, (bfd_byte *) data + reloc_entry->address); |
4a81b561 DHW |
94 | } |
95 | result = bfd_reloc_ok; | |
96 | break; | |
97 | case C_SCALL: | |
3b4f1a5d SC |
98 | /* This is a call to a system call, replace with a calls to # */ |
99 | BFD_ASSERT(0); | |
100 | result = bfd_reloc_ok; | |
4a81b561 DHW |
101 | break; |
102 | default: | |
103 | result = bfd_reloc_ok; | |
104 | break; | |
105 | } | |
106 | } | |
107 | return result; | |
108 | } | |
109 | ||
1b8a11d4 JMD |
110 | /* i960 COFF is used by VxWorks 5.1. However, VxWorks 5.1 does not |
111 | appear to correctly handle a reloc against a symbol defined in the | |
112 | same object file. It appears to simply discard such relocs, rather | |
113 | than adding their values into the object file. We handle this here | |
114 | by converting all relocs against defined symbols into relocs | |
115 | against the section symbol, when generating a relocateable output | |
116 | file. */ | |
5e694c29 JMD |
117 | |
118 | static bfd_reloc_status_type | |
119 | coff_i960_relocate (abfd, reloc_entry, symbol, data, input_section, | |
120 | output_bfd, error_message) | |
121 | bfd *abfd; | |
122 | arelent *reloc_entry; | |
123 | asymbol *symbol; | |
124 | PTR data; | |
125 | asection *input_section; | |
126 | bfd *output_bfd; | |
127 | char **error_message; | |
128 | { | |
1b8a11d4 JMD |
129 | const char *sec_name; |
130 | asymbol **syms, **sym_end; | |
131 | ||
132 | if (output_bfd == NULL) | |
5e694c29 | 133 | { |
1b8a11d4 JMD |
134 | /* Not generating relocateable output file. */ |
135 | return bfd_reloc_continue; | |
5e694c29 JMD |
136 | } |
137 | ||
1b8a11d4 JMD |
138 | if (bfd_is_und_section (bfd_get_section (symbol))) |
139 | { | |
140 | /* Symbol is not defined, so no need to worry about it. */ | |
141 | return bfd_reloc_continue; | |
142 | } | |
143 | ||
144 | /* Convert the reloc to use the section symbol. FIXME: This method | |
145 | is ridiculous. */ | |
146 | sec_name = bfd_get_section_name (output_bfd, | |
147 | bfd_get_section (symbol)->output_section); | |
148 | syms = bfd_get_outsymbols (output_bfd); | |
149 | sym_end = syms + bfd_get_symcount (output_bfd); | |
150 | for (; syms < sym_end; syms++) | |
151 | { | |
152 | if (bfd_asymbol_name (*syms) != NULL | |
153 | && strcmp (bfd_asymbol_name (*syms), sec_name) == 0 | |
154 | && (*syms)->value == 0) | |
155 | { | |
156 | reloc_entry->sym_ptr_ptr = syms; | |
157 | break; | |
158 | } | |
159 | } | |
160 | ||
161 | if (syms >= sym_end) | |
162 | abort (); | |
163 | ||
164 | /* Let bfd_perform_relocation do its thing, which will include | |
165 | stuffing the symbol addend into the object file. */ | |
5e694c29 JMD |
166 | return bfd_reloc_continue; |
167 | } | |
168 | ||
8070f29d | 169 | static reloc_howto_type howto_rellong = |
ffeef0bb | 170 | HOWTO ((unsigned int) R_RELLONG, 0, 2, 32,false, 0, |
5e694c29 JMD |
171 | complain_overflow_bitfield, coff_i960_relocate,"rellong", true, |
172 | 0xffffffff, 0xffffffff, 0); | |
8070f29d | 173 | static reloc_howto_type howto_iprmed = |
5e694c29 JMD |
174 | HOWTO (R_IPRMED, 0, 2, 24,true,0, complain_overflow_signed, |
175 | coff_i960_relocate, "iprmed ", true, 0x00ffffff, 0x00ffffff, 0); | |
8070f29d | 176 | static reloc_howto_type howto_optcall = |
ffeef0bb KR |
177 | HOWTO (R_OPTCALL, 0,2,24,true,0, complain_overflow_signed, |
178 | optcall_callback, "optcall", true, 0x00ffffff, 0x00ffffff, 0); | |
4a81b561 | 179 | |
6812b607 ILT |
180 | static const reloc_howto_type * |
181 | coff_i960_reloc_type_lookup (abfd, code) | |
182 | bfd *abfd; | |
183 | bfd_reloc_code_real_type code; | |
8070f29d KR |
184 | { |
185 | switch (code) | |
186 | { | |
187 | default: | |
188 | return 0; | |
189 | case BFD_RELOC_I960_CALLJ: | |
190 | return &howto_optcall; | |
191 | case BFD_RELOC_32: | |
22aabad5 | 192 | case BFD_RELOC_CTOR: |
8070f29d KR |
193 | return &howto_rellong; |
194 | case BFD_RELOC_24_PCREL: | |
195 | return &howto_iprmed; | |
196 | } | |
197 | } | |
4a81b561 | 198 | |
924bbb38 | 199 | /* The real code is in coffcode.h */ |
4a81b561 | 200 | |
3b4f1a5d | 201 | #define RTYPE2HOWTO(cache_ptr, dst) \ |
8070f29d KR |
202 | { \ |
203 | reloc_howto_type *howto_ptr; \ | |
204 | switch ((dst)->r_type) { \ | |
205 | case 17: howto_ptr = &howto_rellong; break; \ | |
206 | case 25: howto_ptr = &howto_iprmed; break; \ | |
207 | case 27: howto_ptr = &howto_optcall; break; \ | |
208 | default: howto_ptr = 0; break; \ | |
209 | } \ | |
210 | cache_ptr->howto = howto_ptr; \ | |
211 | } | |
3b4f1a5d | 212 | |
7ed4093a | 213 | #include "coffcode.h" |
4a81b561 | 214 | |
6812b607 ILT |
215 | #undef coff_bfd_reloc_type_lookup |
216 | #define coff_bfd_reloc_type_lookup coff_i960_reloc_type_lookup | |
217 | ||
ffeef0bb | 218 | const bfd_target icoff_little_vec = |
4a81b561 | 219 | { |
9872a49c | 220 | "coff-Intel-little", /* name */ |
3b4f1a5d | 221 | bfd_target_coff_flavour, |
4a81b561 | 222 | false, /* data byte order is little */ |
9872a49c | 223 | false, /* header byte order is little */ |
4a81b561 DHW |
224 | |
225 | (HAS_RELOC | EXEC_P | /* object flags */ | |
226 | HAS_LINENO | HAS_DEBUG | | |
6812b607 | 227 | HAS_SYMS | HAS_LOCALS | WP_TEXT), |
4a81b561 DHW |
228 | |
229 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
22aabad5 | 230 | '_', /* leading underscore */ |
4a81b561 DHW |
231 | '/', /* ar_pad_char */ |
232 | 15, /* ar_max_namelen */ | |
4a81b561 | 233 | |
294eaca4 | 234 | 3, /* minimum alignment power */ |
6812b607 ILT |
235 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
236 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
237 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
238 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
239 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
240 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
4a81b561 | 241 | |
294eaca4 SC |
242 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
243 | bfd_generic_archive_p, _bfd_dummy_target}, | |
244 | {bfd_false, coff_mkobject, /* bfd_set_format */ | |
245 | _bfd_generic_mkarchive, bfd_false}, | |
246 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
247 | _bfd_write_archive_contents, bfd_false}, | |
6812b607 ILT |
248 | |
249 | BFD_JUMP_TABLE_GENERIC (coff), | |
250 | BFD_JUMP_TABLE_COPY (coff), | |
251 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
252 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
253 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
254 | BFD_JUMP_TABLE_RELOCS (coff), | |
255 | BFD_JUMP_TABLE_WRITE (coff), | |
256 | BFD_JUMP_TABLE_LINK (coff), | |
22aabad5 | 257 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
6812b607 | 258 | |
8070f29d | 259 | COFF_SWAP_TABLE, |
8070f29d | 260 | }; |
4a81b561 DHW |
261 | |
262 | ||
ffeef0bb | 263 | const bfd_target icoff_big_vec = |
4a81b561 | 264 | { |
9872a49c | 265 | "coff-Intel-big", /* name */ |
3b4f1a5d | 266 | bfd_target_coff_flavour, |
4a81b561 | 267 | false, /* data byte order is little */ |
9872a49c | 268 | true, /* header byte order is big */ |
4a81b561 DHW |
269 | |
270 | (HAS_RELOC | EXEC_P | /* object flags */ | |
271 | HAS_LINENO | HAS_DEBUG | | |
6812b607 | 272 | HAS_SYMS | HAS_LOCALS | WP_TEXT), |
4a81b561 DHW |
273 | |
274 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
22aabad5 | 275 | '_', /* leading underscore */ |
4a81b561 DHW |
276 | '/', /* ar_pad_char */ |
277 | 15, /* ar_max_namelen */ | |
4a81b561 | 278 | |
3b4f1a5d | 279 | 3, /* minimum alignment power */ |
6812b607 ILT |
280 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
281 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
282 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
283 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
284 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
285 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
4a81b561 | 286 | |
2b1d8a50 JG |
287 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
288 | bfd_generic_archive_p, _bfd_dummy_target}, | |
289 | {bfd_false, coff_mkobject, /* bfd_set_format */ | |
290 | _bfd_generic_mkarchive, bfd_false}, | |
291 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
292 | _bfd_write_archive_contents, bfd_false}, | |
6812b607 ILT |
293 | |
294 | BFD_JUMP_TABLE_GENERIC (coff), | |
295 | BFD_JUMP_TABLE_COPY (coff), | |
296 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
297 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
298 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
299 | BFD_JUMP_TABLE_RELOCS (coff), | |
300 | BFD_JUMP_TABLE_WRITE (coff), | |
301 | BFD_JUMP_TABLE_LINK (coff), | |
22aabad5 | 302 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
6812b607 | 303 | |
8070f29d | 304 | COFF_SWAP_TABLE, |
fc723380 | 305 | }; |