Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for Intel 960 COFF files. |
b34976b6 | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1999, 2000, 2001, |
157090f7 | 3 | 2002, 2003, 2004, 2007 Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Cygnus Support. |
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 RH |
22 | |
23 | #define I960 1 | |
24 | #define BADMAG(x) I960BADMAG(x) | |
25 | ||
252b5132 | 26 | #include "sysdep.h" |
3db64b00 | 27 | #include "bfd.h" |
252b5132 RH |
28 | #include "libbfd.h" |
29 | #include "coff/i960.h" | |
30 | #include "coff/internal.h" | |
31 | #include "libcoff.h" /* to allow easier abstraction-breaking */ | |
32 | ||
b34976b6 AM |
33 | static bfd_boolean coff_i960_is_local_label_name |
34 | PARAMS ((bfd *, const char *)); | |
252b5132 RH |
35 | static bfd_reloc_status_type optcall_callback |
36 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
37 | static bfd_reloc_status_type coff_i960_relocate | |
38 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
39 | static reloc_howto_type *coff_i960_reloc_type_lookup | |
40 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
b34976b6 | 41 | static bfd_boolean coff_i960_start_final_link |
252b5132 | 42 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 | 43 | static bfd_boolean coff_i960_relocate_section |
252b5132 RH |
44 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
45 | struct internal_reloc *, struct internal_syment *, asection **)); | |
b34976b6 | 46 | static bfd_boolean coff_i960_adjust_symndx |
252b5132 | 47 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, |
b34976b6 | 48 | struct internal_reloc *, bfd_boolean *)); |
252b5132 RH |
49 | |
50 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) | |
51 | #define COFF_ALIGN_IN_SECTION_HEADER 1 | |
52 | ||
dc810e39 AM |
53 | #define GET_SCNHDR_ALIGN H_GET_32 |
54 | #define PUT_SCNHDR_ALIGN H_PUT_32 | |
252b5132 RH |
55 | |
56 | /* The i960 does not support an MMU, so COFF_PAGE_SIZE can be | |
57 | arbitrarily small. */ | |
58 | #define COFF_PAGE_SIZE 1 | |
59 | ||
60 | #define COFF_LONG_FILENAMES | |
61 | ||
62 | /* This set of local label names is taken from gas. */ | |
63 | ||
b34976b6 | 64 | static bfd_boolean |
252b5132 | 65 | coff_i960_is_local_label_name (abfd, name) |
5f771d47 | 66 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
67 | const char *name; |
68 | { | |
69 | return (name[0] == 'L' | |
70 | || (name[0] == '.' | |
71 | && (name[1] == 'C' | |
72 | || name[1] == 'I' | |
73 | || name[1] == '.'))); | |
74 | } | |
75 | ||
76 | /* This is just like the usual CALC_ADDEND, but it includes the | |
77 | section VMA for PC relative relocs. */ | |
78 | #ifndef CALC_ADDEND | |
79 | #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \ | |
80 | { \ | |
81 | coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \ | |
82 | if (ptr && bfd_asymbol_bfd (ptr) != abfd) \ | |
83 | coffsym = (obj_symbols (abfd) \ | |
84 | + (cache_ptr->sym_ptr_ptr - symbols)); \ | |
85 | else if (ptr) \ | |
86 | coffsym = coff_symbol_from (abfd, ptr); \ | |
87 | if (coffsym != (coff_symbol_type *) NULL \ | |
88 | && coffsym->native->u.syment.n_scnum == 0) \ | |
89 | cache_ptr->addend = 0; \ | |
90 | else if (ptr && bfd_asymbol_bfd (ptr) == abfd \ | |
91 | && ptr->section != (asection *) NULL) \ | |
92 | cache_ptr->addend = - (ptr->section->vma + ptr->value); \ | |
93 | else \ | |
94 | cache_ptr->addend = 0; \ | |
95 | if (ptr && (reloc.r_type == 25 || reloc.r_type == 27)) \ | |
96 | cache_ptr->addend += asect->vma; \ | |
97 | } | |
98 | #endif | |
99 | ||
100 | #define CALLS 0x66003800 /* Template for 'calls' instruction */ | |
101 | #define BAL 0x0b000000 /* Template for 'bal' instruction */ | |
102 | #define BAL_MASK 0x00ffffff | |
103 | ||
5fcfd273 | 104 | static bfd_reloc_status_type |
252b5132 RH |
105 | optcall_callback (abfd, reloc_entry, symbol_in, data, |
106 | input_section, ignore_bfd, error_message) | |
107 | bfd *abfd; | |
108 | arelent *reloc_entry; | |
109 | asymbol *symbol_in; | |
110 | PTR data; | |
111 | asection *input_section; | |
5f771d47 | 112 | bfd *ignore_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
113 | char **error_message; |
114 | { | |
115 | /* This item has already been relocated correctly, but we may be | |
116 | * able to patch in yet better code - done by digging out the | |
117 | * correct info on this symbol */ | |
118 | bfd_reloc_status_type result; | |
119 | coff_symbol_type *cs = coffsymbol(symbol_in); | |
120 | ||
121 | /* Don't do anything with symbols which aren't tied up yet, | |
5fcfd273 | 122 | except move the reloc. */ |
252b5132 RH |
123 | if (bfd_is_und_section (cs->symbol.section)) { |
124 | reloc_entry->address += input_section->output_offset; | |
125 | return bfd_reloc_ok; | |
126 | } | |
5fcfd273 KH |
127 | |
128 | /* So the target symbol has to be of coff type, and the symbol | |
252b5132 RH |
129 | has to have the correct native information within it */ |
130 | if ((bfd_asymbol_flavour(&cs->symbol) != bfd_target_coff_flavour) | |
131 | || (cs->native == (combined_entry_type *)NULL)) | |
132 | { | |
133 | /* This is interesting, consider the case where we're outputting coff | |
134 | from a mix n match input, linking from coff to a symbol defined in a | |
135 | bout file will cause this match to be true. Should I complain? This | |
136 | will only work if the bout symbol is non leaf. */ | |
137 | *error_message = | |
138 | (char *) _("uncertain calling convention for non-COFF symbol"); | |
139 | result = bfd_reloc_dangerous; | |
140 | } | |
141 | else | |
142 | { | |
5fcfd273 | 143 | switch (cs->native->u.syment.n_sclass) |
252b5132 RH |
144 | { |
145 | case C_LEAFSTAT: | |
146 | case C_LEAFEXT: | |
147 | /* This is a call to a leaf procedure, replace instruction with a bal | |
148 | to the correct location. */ | |
149 | { | |
150 | union internal_auxent *aux = &((cs->native+2)->u.auxent); | |
6e301b2b | 151 | int word = bfd_get_32 (abfd, (bfd_byte *)data + reloc_entry->address); |
252b5132 RH |
152 | int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value); |
153 | BFD_ASSERT(cs->native->u.syment.n_numaux==2); | |
154 | ||
155 | /* We replace the original call instruction with a bal to | |
156 | the bal entry point - the offset of which is described in | |
157 | the 2nd auxent of the original symbol. We keep the native | |
158 | sym and auxents untouched, so the delta between the two | |
159 | is the offset of the bal entry point. */ | |
160 | word = ((word + olf) & BAL_MASK) | BAL; | |
dc810e39 AM |
161 | bfd_put_32 (abfd, (bfd_vma) word, |
162 | (bfd_byte *) data + reloc_entry->address); | |
252b5132 RH |
163 | } |
164 | result = bfd_reloc_ok; | |
165 | break; | |
166 | case C_SCALL: | |
167 | /* This is a call to a system call, replace with a calls to # */ | |
168 | BFD_ASSERT(0); | |
169 | result = bfd_reloc_ok; | |
170 | break; | |
171 | default: | |
172 | result = bfd_reloc_ok; | |
173 | break; | |
174 | } | |
175 | } | |
176 | return result; | |
177 | } | |
178 | ||
179 | /* i960 COFF is used by VxWorks 5.1. However, VxWorks 5.1 does not | |
180 | appear to correctly handle a reloc against a symbol defined in the | |
181 | same object file. It appears to simply discard such relocs, rather | |
182 | than adding their values into the object file. We handle this here | |
183 | by converting all relocs against defined symbols into relocs | |
1049f94e | 184 | against the section symbol, when generating a relocatable output |
252b5132 RH |
185 | file. |
186 | ||
187 | Note that this function is only called if we are not using the COFF | |
188 | specific backend linker. It only does something when doing a | |
1049f94e | 189 | relocatable link, which will almost certainly fail when not |
252b5132 RH |
190 | generating COFF i960 output, so this function is actually no longer |
191 | useful. It was used before this target was converted to use the | |
192 | COFF specific backend linker. */ | |
193 | ||
5fcfd273 | 194 | static bfd_reloc_status_type |
252b5132 RH |
195 | coff_i960_relocate (abfd, reloc_entry, symbol, data, input_section, |
196 | output_bfd, error_message) | |
197 | bfd *abfd; | |
198 | arelent *reloc_entry; | |
199 | asymbol *symbol; | |
5f771d47 ILT |
200 | PTR data ATTRIBUTE_UNUSED; |
201 | asection *input_section ATTRIBUTE_UNUSED; | |
252b5132 | 202 | bfd *output_bfd; |
5f771d47 | 203 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
204 | { |
205 | asection *osec; | |
206 | ||
207 | if (output_bfd == NULL) | |
208 | { | |
1049f94e | 209 | /* Not generating relocatable output file. */ |
252b5132 RH |
210 | return bfd_reloc_continue; |
211 | } | |
212 | ||
213 | if (bfd_is_und_section (bfd_get_section (symbol))) | |
214 | { | |
215 | /* Symbol is not defined, so no need to worry about it. */ | |
216 | return bfd_reloc_continue; | |
217 | } | |
218 | ||
219 | if (bfd_is_com_section (bfd_get_section (symbol))) | |
220 | { | |
221 | /* I don't really know what the right action is for a common | |
222 | symbol. */ | |
223 | return bfd_reloc_continue; | |
224 | } | |
225 | ||
226 | /* Convert the reloc to use the section symbol. FIXME: This method | |
227 | is ridiculous. */ | |
228 | osec = bfd_get_section (symbol)->output_section; | |
229 | if (coff_section_data (output_bfd, osec) != NULL | |
230 | && coff_section_data (output_bfd, osec)->tdata != NULL) | |
231 | reloc_entry->sym_ptr_ptr = | |
232 | (asymbol **) coff_section_data (output_bfd, osec)->tdata; | |
233 | else | |
234 | { | |
235 | const char *sec_name; | |
236 | asymbol **syms, **sym_end; | |
237 | ||
238 | sec_name = bfd_get_section_name (output_bfd, osec); | |
239 | syms = bfd_get_outsymbols (output_bfd); | |
240 | sym_end = syms + bfd_get_symcount (output_bfd); | |
241 | for (; syms < sym_end; syms++) | |
242 | { | |
243 | if (bfd_asymbol_name (*syms) != NULL | |
244 | && (*syms)->value == 0 | |
245 | && strcmp ((*syms)->section->output_section->name, | |
246 | sec_name) == 0) | |
247 | break; | |
248 | } | |
249 | ||
250 | if (syms >= sym_end) | |
251 | abort (); | |
252 | ||
253 | reloc_entry->sym_ptr_ptr = syms; | |
254 | ||
255 | if (coff_section_data (output_bfd, osec) == NULL) | |
256 | { | |
dc810e39 AM |
257 | bfd_size_type amt = sizeof (struct coff_section_tdata); |
258 | osec->used_by_bfd = (PTR) bfd_zalloc (abfd, amt); | |
252b5132 RH |
259 | if (osec->used_by_bfd == NULL) |
260 | return bfd_reloc_overflow; | |
261 | } | |
262 | coff_section_data (output_bfd, osec)->tdata = (PTR) syms; | |
263 | } | |
264 | ||
265 | /* Let bfd_perform_relocation do its thing, which will include | |
266 | stuffing the symbol addend into the object file. */ | |
267 | return bfd_reloc_continue; | |
268 | } | |
269 | ||
270 | static reloc_howto_type howto_rellong = | |
b34976b6 AM |
271 | HOWTO ((unsigned int) R_RELLONG, 0, 2, 32,FALSE, 0, |
272 | complain_overflow_bitfield, coff_i960_relocate,"rellong", TRUE, | |
252b5132 RH |
273 | 0xffffffff, 0xffffffff, 0); |
274 | static reloc_howto_type howto_iprmed = | |
b34976b6 AM |
275 | HOWTO (R_IPRMED, 0, 2, 24,TRUE,0, complain_overflow_signed, |
276 | coff_i960_relocate, "iprmed ", TRUE, 0x00ffffff, 0x00ffffff, 0); | |
252b5132 | 277 | static reloc_howto_type howto_optcall = |
b34976b6 AM |
278 | HOWTO (R_OPTCALL, 0,2,24,TRUE,0, complain_overflow_signed, |
279 | optcall_callback, "optcall", TRUE, 0x00ffffff, 0x00ffffff, 0); | |
252b5132 RH |
280 | |
281 | static reloc_howto_type * | |
282 | coff_i960_reloc_type_lookup (abfd, code) | |
5f771d47 | 283 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
284 | bfd_reloc_code_real_type code; |
285 | { | |
286 | switch (code) | |
287 | { | |
288 | default: | |
289 | return 0; | |
290 | case BFD_RELOC_I960_CALLJ: | |
291 | return &howto_optcall; | |
292 | case BFD_RELOC_32: | |
293 | case BFD_RELOC_CTOR: | |
294 | return &howto_rellong; | |
295 | case BFD_RELOC_24_PCREL: | |
296 | return &howto_iprmed; | |
297 | } | |
298 | } | |
299 | ||
157090f7 AM |
300 | static reloc_howto_type * |
301 | coff_i960_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
302 | const char *r_name) | |
303 | { | |
304 | if (strcasecmp (howto_optcall.name, r_name) == 0) | |
305 | return &howto_optcall; | |
306 | if (strcasecmp (howto_rellong.name, r_name) == 0) | |
307 | return &howto_rellong; | |
308 | if (strcasecmp (howto_iprmed.name, r_name) == 0) | |
309 | return &howto_iprmed; | |
310 | ||
311 | return NULL; | |
312 | } | |
313 | ||
252b5132 RH |
314 | /* The real code is in coffcode.h */ |
315 | ||
316 | #define RTYPE2HOWTO(cache_ptr, dst) \ | |
317 | { \ | |
318 | reloc_howto_type *howto_ptr; \ | |
319 | switch ((dst)->r_type) { \ | |
320 | case 17: howto_ptr = &howto_rellong; break; \ | |
321 | case 25: howto_ptr = &howto_iprmed; break; \ | |
322 | case 27: howto_ptr = &howto_optcall; break; \ | |
323 | default: howto_ptr = 0; break; \ | |
324 | } \ | |
325 | (cache_ptr)->howto = howto_ptr; \ | |
326 | } | |
327 | ||
328 | /* i960 COFF is used by VxWorks 5.1. However, VxWorks 5.1 does not | |
329 | appear to correctly handle a reloc against a symbol defined in the | |
330 | same object file. It appears to simply discard such relocs, rather | |
331 | than adding their values into the object file. We handle this by | |
332 | converting all relocs against global symbols into relocs against | |
333 | internal symbols at the start of the section. This routine is | |
334 | called at the start of the linking process, and it creates the | |
335 | necessary symbols. */ | |
336 | ||
b34976b6 | 337 | static bfd_boolean |
252b5132 RH |
338 | coff_i960_start_final_link (abfd, info) |
339 | bfd *abfd; | |
340 | struct bfd_link_info *info; | |
341 | { | |
342 | bfd_size_type symesz = bfd_coff_symesz (abfd); | |
343 | asection *o; | |
344 | bfd_byte *esym; | |
345 | ||
1049f94e | 346 | if (! info->relocatable) |
b34976b6 | 347 | return TRUE; |
252b5132 RH |
348 | |
349 | esym = (bfd_byte *) bfd_malloc (symesz); | |
350 | if (esym == NULL) | |
b34976b6 | 351 | return FALSE; |
252b5132 RH |
352 | |
353 | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0) | |
b34976b6 | 354 | return FALSE; |
252b5132 RH |
355 | |
356 | for (o = abfd->sections; o != NULL; o = o->next) | |
357 | { | |
358 | struct internal_syment isym; | |
359 | ||
360 | strncpy (isym._n._n_name, o->name, SYMNMLEN); | |
361 | isym.n_value = 0; | |
362 | isym.n_scnum = o->target_index; | |
363 | isym.n_type = T_NULL; | |
364 | isym.n_sclass = C_STAT; | |
365 | isym.n_numaux = 0; | |
366 | ||
367 | bfd_coff_swap_sym_out (abfd, (PTR) &isym, (PTR) esym); | |
368 | ||
dc810e39 | 369 | if (bfd_bwrite (esym, symesz, abfd) != symesz) |
252b5132 RH |
370 | { |
371 | free (esym); | |
b34976b6 | 372 | return FALSE; |
252b5132 RH |
373 | } |
374 | ||
375 | obj_raw_syment_count (abfd) += 1; | |
376 | } | |
377 | ||
378 | free (esym); | |
379 | ||
b34976b6 | 380 | return TRUE; |
252b5132 RH |
381 | } |
382 | ||
383 | /* The reloc processing routine for the optimized COFF linker. */ | |
384 | ||
b34976b6 | 385 | static bfd_boolean |
252b5132 RH |
386 | coff_i960_relocate_section (output_bfd, info, input_bfd, input_section, |
387 | contents, relocs, syms, sections) | |
5f771d47 | 388 | bfd *output_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
389 | struct bfd_link_info *info; |
390 | bfd *input_bfd; | |
391 | asection *input_section; | |
392 | bfd_byte *contents; | |
393 | struct internal_reloc *relocs; | |
394 | struct internal_syment *syms; | |
395 | asection **sections; | |
396 | { | |
397 | struct internal_reloc *rel; | |
398 | struct internal_reloc *relend; | |
399 | ||
400 | rel = relocs; | |
401 | relend = rel + input_section->reloc_count; | |
402 | for (; rel < relend; rel++) | |
403 | { | |
404 | long symndx; | |
405 | struct coff_link_hash_entry *h; | |
406 | struct internal_syment *sym; | |
407 | bfd_vma addend; | |
408 | bfd_vma val; | |
409 | reloc_howto_type *howto; | |
410 | bfd_reloc_status_type rstat = bfd_reloc_ok; | |
b34976b6 | 411 | bfd_boolean done; |
252b5132 RH |
412 | |
413 | symndx = rel->r_symndx; | |
414 | ||
415 | if (symndx == -1) | |
416 | { | |
417 | h = NULL; | |
418 | sym = NULL; | |
419 | } | |
420 | else | |
5fcfd273 | 421 | { |
252b5132 RH |
422 | h = obj_coff_sym_hashes (input_bfd)[symndx]; |
423 | sym = syms + symndx; | |
424 | } | |
425 | ||
426 | if (sym != NULL && sym->n_scnum != 0) | |
427 | addend = - sym->n_value; | |
428 | else | |
429 | addend = 0; | |
430 | ||
431 | switch (rel->r_type) | |
432 | { | |
433 | case 17: howto = &howto_rellong; break; | |
434 | case 25: howto = &howto_iprmed; break; | |
435 | case 27: howto = &howto_optcall; break; | |
436 | default: | |
437 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 438 | return FALSE; |
252b5132 RH |
439 | } |
440 | ||
441 | val = 0; | |
442 | ||
443 | if (h == NULL) | |
444 | { | |
445 | asection *sec; | |
446 | ||
447 | if (symndx == -1) | |
448 | { | |
449 | sec = bfd_abs_section_ptr; | |
450 | val = 0; | |
451 | } | |
452 | else | |
453 | { | |
454 | sec = sections[symndx]; | |
455 | val = (sec->output_section->vma | |
456 | + sec->output_offset | |
457 | + sym->n_value | |
458 | - sec->vma); | |
459 | } | |
460 | } | |
461 | else | |
462 | { | |
463 | if (h->root.type == bfd_link_hash_defined | |
464 | || h->root.type == bfd_link_hash_defweak) | |
465 | { | |
466 | asection *sec; | |
467 | ||
468 | sec = h->root.u.def.section; | |
469 | val = (h->root.u.def.value | |
470 | + sec->output_section->vma | |
471 | + sec->output_offset); | |
472 | } | |
1049f94e | 473 | else if (! info->relocatable) |
252b5132 RH |
474 | { |
475 | if (! ((*info->callbacks->undefined_symbol) | |
476 | (info, h->root.root.string, input_bfd, input_section, | |
b34976b6 AM |
477 | rel->r_vaddr - input_section->vma, TRUE))) |
478 | return FALSE; | |
252b5132 RH |
479 | } |
480 | } | |
481 | ||
b34976b6 | 482 | done = FALSE; |
252b5132 | 483 | |
1049f94e | 484 | if (howto->type == R_OPTCALL && ! info->relocatable && symndx != -1) |
252b5132 RH |
485 | { |
486 | int class; | |
487 | ||
488 | if (h != NULL) | |
489 | class = h->class; | |
490 | else | |
491 | class = sym->n_sclass; | |
492 | ||
493 | switch (class) | |
494 | { | |
495 | case C_NULL: | |
496 | /* This symbol is apparently not from a COFF input file. | |
497 | We warn, and then assume that it is not a leaf | |
498 | function. */ | |
499 | if (! ((*info->callbacks->reloc_dangerous) | |
500 | (info, | |
501 | _("uncertain calling convention for non-COFF symbol"), | |
502 | input_bfd, input_section, | |
503 | rel->r_vaddr - input_section->vma))) | |
b34976b6 | 504 | return FALSE; |
252b5132 RH |
505 | break; |
506 | case C_LEAFSTAT: | |
507 | case C_LEAFEXT: | |
508 | /* This is a call to a leaf procedure; use the bal | |
509 | instruction. */ | |
510 | { | |
511 | long olf; | |
512 | unsigned long word; | |
513 | ||
514 | if (h != NULL) | |
515 | { | |
516 | BFD_ASSERT (h->numaux == 2); | |
517 | olf = h->aux[1].x_bal.x_balntry; | |
518 | } | |
519 | else | |
520 | { | |
521 | bfd_byte *esyms; | |
522 | union internal_auxent aux; | |
523 | ||
524 | BFD_ASSERT (sym->n_numaux == 2); | |
525 | esyms = (bfd_byte *) obj_coff_external_syms (input_bfd); | |
526 | esyms += (symndx + 2) * bfd_coff_symesz (input_bfd); | |
527 | bfd_coff_swap_aux_in (input_bfd, (PTR) esyms, sym->n_type, | |
528 | sym->n_sclass, 1, sym->n_numaux, | |
529 | (PTR) &aux); | |
530 | olf = aux.x_bal.x_balntry; | |
531 | } | |
532 | ||
533 | word = bfd_get_32 (input_bfd, | |
534 | (contents | |
535 | + (rel->r_vaddr - input_section->vma))); | |
536 | word = ((word + olf - val) & BAL_MASK) | BAL; | |
537 | bfd_put_32 (input_bfd, | |
dc810e39 AM |
538 | (bfd_vma) word, |
539 | contents + (rel->r_vaddr - input_section->vma)); | |
b34976b6 | 540 | done = TRUE; |
252b5132 RH |
541 | } |
542 | break; | |
543 | case C_SCALL: | |
544 | BFD_ASSERT (0); | |
545 | break; | |
546 | } | |
547 | } | |
548 | ||
549 | if (! done) | |
550 | { | |
551 | if (howto->pc_relative) | |
552 | addend += input_section->vma; | |
553 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
554 | contents, | |
555 | rel->r_vaddr - input_section->vma, | |
556 | val, addend); | |
557 | } | |
558 | ||
559 | switch (rstat) | |
560 | { | |
561 | default: | |
562 | abort (); | |
563 | case bfd_reloc_ok: | |
564 | break; | |
565 | case bfd_reloc_overflow: | |
566 | { | |
567 | const char *name; | |
568 | char buf[SYMNMLEN + 1]; | |
569 | ||
570 | if (symndx == -1) | |
571 | name = "*ABS*"; | |
572 | else if (h != NULL) | |
dfeffb9f | 573 | name = NULL; |
252b5132 RH |
574 | else |
575 | { | |
576 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); | |
577 | if (name == NULL) | |
b34976b6 | 578 | return FALSE; |
252b5132 RH |
579 | } |
580 | ||
581 | if (! ((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
582 | (info, (h ? &h->root : NULL), name, howto->name, |
583 | (bfd_vma) 0, input_bfd, input_section, | |
584 | rel->r_vaddr - input_section->vma))) | |
b34976b6 | 585 | return FALSE; |
252b5132 RH |
586 | } |
587 | } | |
588 | } | |
589 | ||
b34976b6 | 590 | return TRUE; |
252b5132 RH |
591 | } |
592 | ||
593 | /* Adjust the symbol index of any reloc against a global symbol to | |
594 | instead be a reloc against the internal symbol we created specially | |
595 | for the section. */ | |
596 | ||
b34976b6 | 597 | static bfd_boolean |
252b5132 | 598 | coff_i960_adjust_symndx (obfd, info, ibfd, sec, irel, adjustedp) |
5f771d47 ILT |
599 | bfd *obfd ATTRIBUTE_UNUSED; |
600 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
252b5132 | 601 | bfd *ibfd; |
5f771d47 | 602 | asection *sec ATTRIBUTE_UNUSED; |
252b5132 | 603 | struct internal_reloc *irel; |
b34976b6 | 604 | bfd_boolean *adjustedp; |
252b5132 RH |
605 | { |
606 | struct coff_link_hash_entry *h; | |
607 | ||
b34976b6 | 608 | *adjustedp = FALSE; |
252b5132 RH |
609 | |
610 | h = obj_coff_sym_hashes (ibfd)[irel->r_symndx]; | |
611 | if (h == NULL | |
612 | || (h->root.type != bfd_link_hash_defined | |
613 | && h->root.type != bfd_link_hash_defweak)) | |
b34976b6 | 614 | return TRUE; |
252b5132 RH |
615 | |
616 | irel->r_symndx = h->root.u.def.section->output_section->target_index - 1; | |
b34976b6 | 617 | *adjustedp = TRUE; |
252b5132 | 618 | |
b34976b6 | 619 | return TRUE; |
252b5132 RH |
620 | } |
621 | ||
622 | #define coff_bfd_is_local_label_name coff_i960_is_local_label_name | |
623 | ||
624 | #define coff_start_final_link coff_i960_start_final_link | |
625 | ||
626 | #define coff_relocate_section coff_i960_relocate_section | |
627 | ||
628 | #define coff_adjust_symndx coff_i960_adjust_symndx | |
629 | ||
630 | #define coff_bfd_reloc_type_lookup coff_i960_reloc_type_lookup | |
157090f7 | 631 | #define coff_bfd_reloc_name_lookup coff_i960_reloc_name_lookup |
252b5132 RH |
632 | |
633 | #include "coffcode.h" | |
634 | ||
c3c89269 | 635 | extern const bfd_target icoff_big_vec; |
252b5132 | 636 | |
3fa78519 | 637 | CREATE_LITTLE_COFF_TARGET_VEC (icoff_little_vec, "coff-Intel-little", 0, 0, '_', & icoff_big_vec, COFF_SWAP_TABLE) |
252b5132 RH |
638 | |
639 | const bfd_target icoff_big_vec = | |
640 | { | |
641 | "coff-Intel-big", /* name */ | |
642 | bfd_target_coff_flavour, | |
643 | BFD_ENDIAN_LITTLE, /* data byte order is little */ | |
644 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
645 | ||
646 | (HAS_RELOC | EXEC_P | /* object flags */ | |
647 | HAS_LINENO | HAS_DEBUG | | |
648 | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
649 | ||
650 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
651 | '_', /* leading underscore */ | |
652 | '/', /* ar_pad_char */ | |
653 | 15, /* ar_max_namelen */ | |
654 | ||
655 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
656 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
657 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
658 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
659 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
660 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
661 | ||
662 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
663 | bfd_generic_archive_p, _bfd_dummy_target}, | |
664 | {bfd_false, coff_mkobject, /* bfd_set_format */ | |
665 | _bfd_generic_mkarchive, bfd_false}, | |
666 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
667 | _bfd_write_archive_contents, bfd_false}, | |
668 | ||
669 | BFD_JUMP_TABLE_GENERIC (coff), | |
670 | BFD_JUMP_TABLE_COPY (coff), | |
671 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
672 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
673 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
674 | BFD_JUMP_TABLE_RELOCS (coff), | |
675 | BFD_JUMP_TABLE_WRITE (coff), | |
676 | BFD_JUMP_TABLE_LINK (coff), | |
677 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
678 | ||
c3c89269 | 679 | & icoff_little_vec, |
5fcfd273 | 680 | |
c3c89269 | 681 | COFF_SWAP_TABLE |
252b5132 | 682 | }; |