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