Commit | Line | Data |
---|---|---|
3b16e843 | 1 | /* BFD back-end for OpenRISC 1000 COFF binaries. |
3db64b00 | 2 | Copyright 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. |
3b16e843 NC |
3 | Contributed by Ivan Guzvinec <ivang@opencores.org> |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 9 | the Free Software Foundation; either version 3 of the License, or |
3b16e843 NC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
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 | |
18 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | MA 02110-1301, USA. */ | |
3b16e843 NC |
21 | |
22 | #define OR32 1 | |
23 | ||
3b16e843 | 24 | #include "sysdep.h" |
3db64b00 | 25 | #include "bfd.h" |
3b16e843 NC |
26 | #include "libbfd.h" |
27 | #include "coff/or32.h" | |
28 | #include "coff/internal.h" | |
29 | #include "libcoff.h" | |
30 | ||
b34976b6 AM |
31 | static long get_symbol_value |
32 | PARAMS ((asymbol *)); | |
33 | static bfd_reloc_status_type or32_reloc | |
34 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
35 | static bfd_boolean coff_or32_relocate_section | |
36 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
37 | struct internal_reloc *, struct internal_syment *, asection **)); | |
38 | static bfd_boolean coff_or32_adjust_symndx | |
39 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, | |
40 | struct internal_reloc *, bfd_boolean *)); | |
41 | static void reloc_processing | |
42 | PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *)); | |
3b16e843 NC |
43 | |
44 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) | |
45 | ||
46 | #define INSERT_HWORD(WORD,HWORD) \ | |
47 | (((WORD) & 0xffff0000) | ((HWORD)& 0x0000ffff)) | |
48 | #define EXTRACT_HWORD(WORD) \ | |
49 | ((WORD) & 0x0000ffff) | |
50 | #define SIGN_EXTEND_HWORD(HWORD) \ | |
51 | ((HWORD) & 0x8000 ? (HWORD)|(~0xffffL) : (HWORD)) | |
52 | ||
53 | #define INSERT_JUMPTARG(WORD,JT) \ | |
54 | (((WORD) & 0xfc000000) | ((JT)& 0x03ffffff)) | |
55 | #define EXTRACT_JUMPTARG(WORD) \ | |
56 | ((WORD) & 0x03ffffff) | |
57 | #define SIGN_EXTEND_JUMPTARG(JT) \ | |
58 | ((JT) & 0x04000000 ? (JT)|(~0x03ffffffL) : (JT)) | |
59 | ||
60 | /* Provided the symbol, returns the value reffed. */ | |
61 | ||
62 | static long | |
b34976b6 | 63 | get_symbol_value (symbol) |
3b16e843 | 64 | asymbol *symbol; |
b34976b6 | 65 | { |
3b16e843 NC |
66 | long relocation = 0; |
67 | ||
68 | if (bfd_is_com_section (symbol->section)) | |
b34976b6 AM |
69 | relocation = 0; |
70 | else | |
3b16e843 NC |
71 | relocation = symbol->value + |
72 | symbol->section->output_section->vma + | |
73 | symbol->section->output_offset; | |
74 | ||
75 | return relocation; | |
76 | } | |
77 | ||
78 | /* This function is in charge of performing all the or32 relocations. */ | |
79 | ||
80 | static bfd_reloc_status_type | |
81 | or32_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | |
82 | error_message) | |
83 | bfd *abfd; | |
84 | arelent *reloc_entry; | |
85 | asymbol *symbol_in; | |
86 | PTR data; | |
87 | asection *input_section; | |
88 | bfd *output_bfd; | |
89 | char **error_message; | |
90 | { | |
91 | /* The consth relocation comes in two parts, we have to remember | |
92 | the state between calls, in these variables. */ | |
b34976b6 | 93 | static bfd_boolean part1_consth_active = FALSE; |
3b16e843 NC |
94 | static unsigned long part1_consth_value; |
95 | ||
96 | unsigned long insn; | |
97 | unsigned long sym_value; | |
98 | unsigned long unsigned_value; | |
99 | unsigned short r_type; | |
100 | long signed_value; | |
101 | ||
102 | unsigned long addr = reloc_entry->address ; /*+ input_section->vma*/ | |
103 | bfd_byte *hit_data =addr + (bfd_byte *)(data); | |
b34976b6 | 104 | |
3b16e843 NC |
105 | r_type = reloc_entry->howto->type; |
106 | ||
b34976b6 | 107 | if (output_bfd) |
3b16e843 NC |
108 | { |
109 | /* Partial linking - do nothing. */ | |
110 | reloc_entry->address += input_section->output_offset; | |
111 | return bfd_reloc_ok; | |
112 | } | |
113 | ||
114 | if (symbol_in != NULL | |
115 | && bfd_is_und_section (symbol_in->section)) | |
116 | { | |
117 | /* Keep the state machine happy in case we're called again. */ | |
b34976b6 | 118 | if (r_type == R_IHIHALF) |
3b16e843 | 119 | { |
b34976b6 | 120 | part1_consth_active = TRUE; |
3b16e843 NC |
121 | part1_consth_value = 0; |
122 | } | |
123 | ||
124 | return bfd_reloc_undefined; | |
125 | } | |
126 | ||
b34976b6 | 127 | if ((part1_consth_active) && (r_type != R_IHCONST)) |
3b16e843 | 128 | { |
b34976b6 | 129 | part1_consth_active = FALSE; |
3b16e843 NC |
130 | *error_message = (char *) "Missing IHCONST"; |
131 | ||
132 | return bfd_reloc_dangerous; | |
133 | } | |
134 | ||
135 | sym_value = get_symbol_value (symbol_in); | |
136 | ||
b34976b6 | 137 | switch (r_type) |
3b16e843 | 138 | { |
b34976b6 AM |
139 | case R_IREL: |
140 | insn = bfd_get_32(abfd, hit_data); | |
3b16e843 NC |
141 | |
142 | /* Take the value in the field and sign extend it. */ | |
143 | signed_value = EXTRACT_JUMPTARG (insn); | |
144 | signed_value = SIGN_EXTEND_JUMPTARG (signed_value); | |
145 | signed_value <<= 2; | |
146 | ||
147 | /* See the note on the R_IREL reloc in coff_or32_relocate_section. */ | |
148 | if (signed_value == - (long) reloc_entry->address) | |
149 | signed_value = 0; | |
150 | ||
151 | signed_value += sym_value + reloc_entry->addend; | |
0e71e495 BE |
152 | /* Relative jmp/call, so subtract from the value the |
153 | address of the place we're coming from. */ | |
154 | signed_value -= (reloc_entry->address | |
155 | + input_section->output_section->vma | |
156 | + input_section->output_offset); | |
157 | if (signed_value > 0x7ffffff || signed_value < -0x8000000) | |
158 | return bfd_reloc_overflow; | |
159 | ||
3b16e843 NC |
160 | signed_value >>= 2; |
161 | insn = INSERT_JUMPTARG (insn, signed_value); | |
b34976b6 | 162 | bfd_put_32 (abfd, insn, hit_data); |
3b16e843 NC |
163 | break; |
164 | ||
b34976b6 AM |
165 | case R_ILOHALF: |
166 | insn = bfd_get_32 (abfd, hit_data); | |
3b16e843 NC |
167 | unsigned_value = EXTRACT_HWORD (insn); |
168 | unsigned_value += sym_value + reloc_entry->addend; | |
169 | insn = INSERT_HWORD (insn, unsigned_value); | |
b34976b6 | 170 | bfd_put_32 (abfd, insn, hit_data); |
3b16e843 NC |
171 | break; |
172 | ||
173 | case R_IHIHALF: | |
b34976b6 | 174 | insn = bfd_get_32 (abfd, hit_data); |
3b16e843 | 175 | |
b34976b6 | 176 | /* consth, part 1 |
3b16e843 | 177 | Just get the symbol value that is referenced. */ |
b34976b6 | 178 | part1_consth_active = TRUE; |
3b16e843 NC |
179 | part1_consth_value = sym_value + reloc_entry->addend; |
180 | ||
181 | /* Don't modify insn until R_IHCONST. */ | |
182 | break; | |
183 | ||
b34976b6 AM |
184 | case R_IHCONST: |
185 | insn = bfd_get_32 (abfd, hit_data); | |
3b16e843 | 186 | |
b34976b6 | 187 | /* consth, part 2 |
3b16e843 | 188 | Now relocate the reference. */ |
b34976b6 | 189 | if (! part1_consth_active) |
3b16e843 NC |
190 | { |
191 | *error_message = (char *) "Missing IHIHALF"; | |
192 | return bfd_reloc_dangerous; | |
193 | } | |
194 | ||
195 | /* sym_ptr_ptr = r_symndx, in coff_slurp_reloc_table() */ | |
196 | unsigned_value = 0; /*EXTRACT_HWORD(insn) << 16;*/ | |
197 | unsigned_value += reloc_entry->addend; /* r_symndx */ | |
198 | unsigned_value += part1_consth_value; | |
199 | unsigned_value = unsigned_value >> 16; | |
200 | insn = INSERT_HWORD (insn, unsigned_value); | |
b34976b6 AM |
201 | part1_consth_active = FALSE; |
202 | bfd_put_32 (abfd, insn, hit_data); | |
3b16e843 NC |
203 | break; |
204 | ||
205 | case R_BYTE: | |
b34976b6 AM |
206 | insn = bfd_get_8 (abfd, hit_data); |
207 | unsigned_value = insn + sym_value + reloc_entry->addend; | |
3b16e843 NC |
208 | if (unsigned_value & 0xffffff00) |
209 | return bfd_reloc_overflow; | |
b34976b6 | 210 | bfd_put_8 (abfd, unsigned_value, hit_data); |
3b16e843 NC |
211 | break; |
212 | ||
213 | case R_HWORD: | |
b34976b6 AM |
214 | insn = bfd_get_16 (abfd, hit_data); |
215 | unsigned_value = insn + sym_value + reloc_entry->addend; | |
3b16e843 NC |
216 | if (unsigned_value & 0xffff0000) |
217 | return bfd_reloc_overflow; | |
b34976b6 | 218 | bfd_put_16 (abfd, insn, hit_data); |
3b16e843 NC |
219 | break; |
220 | ||
221 | case R_WORD: | |
b34976b6 AM |
222 | insn = bfd_get_32 (abfd, hit_data); |
223 | insn += sym_value + reloc_entry->addend; | |
3b16e843 NC |
224 | bfd_put_32 (abfd, insn, hit_data); |
225 | break; | |
226 | ||
227 | default: | |
228 | *error_message = _("Unrecognized reloc"); | |
229 | return bfd_reloc_dangerous; | |
230 | } | |
231 | ||
232 | return bfd_reloc_ok; | |
233 | } | |
234 | ||
235 | /* type rightshift | |
236 | size | |
237 | bitsize | |
238 | pc-relative | |
239 | bitpos | |
240 | absolute | |
241 | complain_on_overflow | |
242 | special_function | |
243 | relocation name | |
b34976b6 | 244 | partial_inplace |
3b16e843 NC |
245 | src_mask |
246 | */ | |
247 | ||
248 | /* FIXME: I'm not real sure about this table. */ | |
b34976b6 | 249 | static reloc_howto_type howto_table[] = |
3b16e843 | 250 | { |
b34976b6 | 251 | { R_ABS, 0, 3, 32, FALSE, 0, complain_overflow_bitfield, or32_reloc, "ABS", TRUE, 0xffffffff,0xffffffff, FALSE }, |
5e37cc46 NC |
252 | EMPTY_HOWTO (1), |
253 | EMPTY_HOWTO (2), | |
254 | EMPTY_HOWTO (3), | |
255 | EMPTY_HOWTO (4), | |
256 | EMPTY_HOWTO (5), | |
257 | EMPTY_HOWTO (6), | |
258 | EMPTY_HOWTO (7), | |
259 | EMPTY_HOWTO (8), | |
260 | EMPTY_HOWTO (9), | |
261 | EMPTY_HOWTO (10), | |
262 | EMPTY_HOWTO (11), | |
263 | EMPTY_HOWTO (12), | |
264 | EMPTY_HOWTO (13), | |
265 | EMPTY_HOWTO (14), | |
266 | EMPTY_HOWTO (15), | |
267 | EMPTY_HOWTO (16), | |
268 | EMPTY_HOWTO (17), | |
269 | EMPTY_HOWTO (18), | |
270 | EMPTY_HOWTO (19), | |
271 | EMPTY_HOWTO (20), | |
272 | EMPTY_HOWTO (21), | |
273 | EMPTY_HOWTO (22), | |
274 | EMPTY_HOWTO (23), | |
b34976b6 AM |
275 | { R_IREL, 0, 3, 32, TRUE, 0, complain_overflow_signed, or32_reloc, "IREL", TRUE, 0xffffffff,0xffffffff, FALSE }, |
276 | { R_IABS, 0, 3, 32, FALSE, 0, complain_overflow_bitfield, or32_reloc, "IABS", TRUE, 0xffffffff,0xffffffff, FALSE }, | |
277 | { R_ILOHALF, 0, 3, 16, TRUE, 0, complain_overflow_signed, or32_reloc, "ILOHALF", TRUE, 0x0000ffff,0x0000ffff, FALSE }, | |
278 | { R_IHIHALF, 0, 3, 16, TRUE, 16,complain_overflow_signed, or32_reloc, "IHIHALF", TRUE, 0xffff0000,0xffff0000, FALSE }, | |
279 | { R_IHCONST, 0, 3, 16, TRUE, 0, complain_overflow_signed, or32_reloc, "IHCONST", TRUE, 0xffff0000,0xffff0000, FALSE }, | |
280 | { R_BYTE, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, or32_reloc, "BYTE", TRUE, 0x000000ff,0x000000ff, FALSE }, | |
281 | { R_HWORD, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, or32_reloc, "HWORD", TRUE, 0x0000ffff,0x0000ffff, FALSE }, | |
282 | { R_WORD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, or32_reloc, "WORD", TRUE, 0xffffffff,0xffffffff, FALSE }, | |
3b16e843 NC |
283 | }; |
284 | ||
285 | #define BADMAG(x) OR32BADMAG (x) | |
286 | ||
287 | #define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \ | |
288 | reloc_processing (relent, reloc, symbols, abfd, section) | |
289 | ||
290 | static void | |
291 | reloc_processing (relent,reloc, symbols, abfd, section) | |
292 | arelent *relent; | |
293 | struct internal_reloc *reloc; | |
294 | asymbol **symbols; | |
295 | bfd *abfd; | |
296 | asection *section; | |
297 | { | |
298 | static bfd_vma ihihalf_vaddr = (bfd_vma) -1; | |
299 | ||
b34976b6 | 300 | relent->address = reloc->r_vaddr; |
3b16e843 NC |
301 | relent->howto = howto_table + reloc->r_type; |
302 | ||
b34976b6 AM |
303 | if (reloc->r_type == R_IHCONST) |
304 | { | |
3b16e843 NC |
305 | /* The address of an R_IHCONST should always be the address of |
306 | the immediately preceding R_IHIHALF. relocs generated by gas | |
307 | are correct, but relocs generated by High C are different (I | |
308 | can't figure out what the address means for High C). We can | |
309 | handle both gas and High C by ignoring the address here, and | |
310 | simply reusing the address saved for R_IHIHALF. */ | |
311 | if (ihihalf_vaddr == (bfd_vma) -1) | |
312 | abort (); | |
313 | ||
314 | relent->address = ihihalf_vaddr; | |
315 | ihihalf_vaddr = (bfd_vma) -1; | |
316 | relent->addend = reloc->r_symndx; | |
317 | relent->sym_ptr_ptr= bfd_abs_section_ptr->symbol_ptr_ptr; | |
318 | } | |
319 | else | |
320 | { | |
3b16e843 | 321 | relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; |
3b16e843 NC |
322 | relent->addend = 0; |
323 | relent->address-= section->vma; | |
324 | ||
325 | if (reloc->r_type == R_IHIHALF) | |
326 | ihihalf_vaddr = relent->address; | |
327 | else if (ihihalf_vaddr != (bfd_vma) -1) | |
328 | abort (); | |
329 | } | |
330 | } | |
331 | ||
332 | /* The reloc processing routine for the optimized COFF linker. */ | |
333 | ||
b34976b6 | 334 | static bfd_boolean |
3b16e843 NC |
335 | coff_or32_relocate_section (output_bfd, info, input_bfd, input_section, |
336 | contents, relocs, syms, sections) | |
5e37cc46 | 337 | bfd *output_bfd ATTRIBUTE_UNUSED; |
3b16e843 NC |
338 | struct bfd_link_info *info; |
339 | bfd *input_bfd; | |
340 | asection *input_section; | |
341 | bfd_byte *contents; | |
342 | struct internal_reloc *relocs; | |
343 | struct internal_syment *syms; | |
344 | asection **sections; | |
345 | { | |
346 | struct internal_reloc *rel; | |
347 | struct internal_reloc *relend; | |
b34976b6 | 348 | bfd_boolean hihalf; |
3b16e843 NC |
349 | bfd_vma hihalf_val; |
350 | ||
1049f94e | 351 | /* If we are performing a relocatable link, we don't need to do a |
3b16e843 NC |
352 | thing. The caller will take care of adjusting the reloc |
353 | addresses and symbol indices. */ | |
1049f94e | 354 | if (info->relocatable) |
b34976b6 | 355 | return TRUE; |
3b16e843 | 356 | |
b34976b6 | 357 | hihalf = FALSE; |
3b16e843 NC |
358 | hihalf_val = 0; |
359 | ||
360 | rel = relocs; | |
361 | relend = rel + input_section->reloc_count; | |
362 | ||
363 | for (; rel < relend; rel++) | |
364 | { | |
365 | long symndx; | |
366 | bfd_byte *loc; | |
367 | struct coff_link_hash_entry *h; | |
368 | struct internal_syment *sym; | |
369 | asection *sec; | |
370 | bfd_vma val; | |
b34976b6 | 371 | bfd_boolean overflow; |
3b16e843 NC |
372 | unsigned long insn; |
373 | long signed_value; | |
374 | unsigned long unsigned_value; | |
375 | bfd_reloc_status_type rstat; | |
376 | ||
377 | symndx = rel->r_symndx; | |
378 | loc = contents + rel->r_vaddr - input_section->vma; | |
379 | ||
380 | if (symndx == -1 || rel->r_type == R_IHCONST) | |
381 | h = NULL; | |
382 | else | |
383 | h = obj_coff_sym_hashes (input_bfd)[symndx]; | |
384 | ||
385 | sym = NULL; | |
386 | sec = NULL; | |
387 | val = 0; | |
388 | ||
389 | /* An R_IHCONST reloc does not have a symbol. Instead, the | |
390 | symbol index is an addend. R_IHCONST is always used in | |
391 | conjunction with R_IHHALF. */ | |
392 | if (rel->r_type != R_IHCONST) | |
393 | { | |
394 | if (h == NULL) | |
395 | { | |
396 | if (symndx == -1) | |
397 | sec = bfd_abs_section_ptr; | |
398 | else | |
399 | { | |
400 | sym = syms + symndx; | |
401 | sec = sections[symndx]; | |
402 | val = (sec->output_section->vma | |
403 | + sec->output_offset | |
404 | + sym->n_value | |
405 | - sec->vma); | |
406 | } | |
407 | } | |
408 | else | |
409 | { | |
410 | if (h->root.type == bfd_link_hash_defined | |
411 | || h->root.type == bfd_link_hash_defweak) | |
412 | { | |
413 | sec = h->root.u.def.section; | |
414 | val = (h->root.u.def.value | |
415 | + sec->output_section->vma | |
416 | + sec->output_offset); | |
417 | } | |
418 | else | |
419 | { | |
420 | if (! ((*info->callbacks->undefined_symbol) | |
421 | (info, h->root.root.string, input_bfd, input_section, | |
b34976b6 AM |
422 | rel->r_vaddr - input_section->vma, TRUE))) |
423 | return FALSE; | |
3b16e843 NC |
424 | } |
425 | } | |
426 | ||
427 | if (hihalf) | |
428 | { | |
429 | if (! ((*info->callbacks->reloc_dangerous) | |
430 | (info, "missing IHCONST reloc", input_bfd, | |
431 | input_section, rel->r_vaddr - input_section->vma))) | |
b34976b6 AM |
432 | return FALSE; |
433 | hihalf = FALSE; | |
3b16e843 NC |
434 | } |
435 | } | |
436 | ||
b34976b6 | 437 | overflow = FALSE; |
3b16e843 NC |
438 | |
439 | switch (rel->r_type) | |
440 | { | |
441 | default: | |
442 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 443 | return FALSE; |
3b16e843 NC |
444 | |
445 | case R_IREL: | |
446 | insn = bfd_get_32 (input_bfd, loc); | |
447 | ||
448 | /* Extract the addend. */ | |
449 | signed_value = EXTRACT_JUMPTARG (insn); | |
450 | signed_value = SIGN_EXTEND_JUMPTARG (signed_value); | |
451 | signed_value <<= 2; | |
452 | ||
453 | /* Determine the destination of the jump. */ | |
454 | signed_value += val; | |
455 | ||
0e71e495 BE |
456 | /* Make the destination PC relative. */ |
457 | signed_value -= (input_section->output_section->vma | |
458 | + input_section->output_offset | |
459 | + (rel->r_vaddr - input_section->vma)); | |
460 | if (signed_value > 0x7ffffff || signed_value < - 0x8000000) | |
461 | { | |
462 | overflow = TRUE; | |
463 | signed_value = 0; | |
464 | } | |
3b16e843 NC |
465 | |
466 | /* Put the adjusted value back into the instruction. */ | |
467 | signed_value >>= 2; | |
468 | insn = INSERT_JUMPTARG(insn, signed_value); | |
469 | ||
470 | bfd_put_32 (input_bfd, (bfd_vma) insn, loc); | |
471 | break; | |
472 | ||
473 | case R_ILOHALF: | |
474 | insn = bfd_get_32 (input_bfd, loc); | |
475 | unsigned_value = EXTRACT_HWORD (insn); | |
476 | unsigned_value += val; | |
477 | insn = INSERT_HWORD (insn, unsigned_value); | |
478 | bfd_put_32 (input_bfd, insn, loc); | |
479 | break; | |
480 | ||
481 | case R_IHIHALF: | |
482 | /* Save the value for the R_IHCONST reloc. */ | |
b34976b6 | 483 | hihalf = TRUE; |
3b16e843 NC |
484 | hihalf_val = val; |
485 | break; | |
486 | ||
487 | case R_IHCONST: | |
488 | if (! hihalf) | |
489 | { | |
490 | if (! ((*info->callbacks->reloc_dangerous) | |
491 | (info, "missing IHIHALF reloc", input_bfd, | |
492 | input_section, rel->r_vaddr - input_section->vma))) | |
b34976b6 | 493 | return FALSE; |
3b16e843 NC |
494 | hihalf_val = 0; |
495 | } | |
496 | ||
497 | insn = bfd_get_32 (input_bfd, loc); | |
498 | unsigned_value = rel->r_symndx + hihalf_val; | |
499 | unsigned_value >>= 16; | |
500 | insn = INSERT_HWORD (insn, unsigned_value); | |
501 | bfd_put_32 (input_bfd, (bfd_vma) insn, loc); | |
502 | ||
b34976b6 | 503 | hihalf = FALSE; |
3b16e843 NC |
504 | break; |
505 | ||
506 | case R_BYTE: | |
507 | case R_HWORD: | |
508 | case R_WORD: | |
509 | rstat = _bfd_relocate_contents (howto_table + rel->r_type, | |
510 | input_bfd, val, loc); | |
511 | if (rstat == bfd_reloc_overflow) | |
b34976b6 | 512 | overflow = TRUE; |
3b16e843 NC |
513 | else if (rstat != bfd_reloc_ok) |
514 | abort (); | |
515 | break; | |
516 | } | |
517 | ||
518 | if (overflow) | |
519 | { | |
520 | const char *name; | |
521 | char buf[SYMNMLEN + 1]; | |
522 | ||
523 | if (symndx == -1) | |
524 | name = "*ABS*"; | |
525 | else if (h != NULL) | |
dfeffb9f | 526 | name = NULL; |
3b16e843 NC |
527 | else if (sym == NULL) |
528 | name = "*unknown*"; | |
529 | else if (sym->_n._n_n._n_zeroes == 0 | |
530 | && sym->_n._n_n._n_offset != 0) | |
531 | name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; | |
532 | else | |
533 | { | |
534 | strncpy (buf, sym->_n._n_name, SYMNMLEN); | |
535 | buf[SYMNMLEN] = '\0'; | |
536 | name = buf; | |
537 | } | |
538 | ||
539 | if (! ((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
540 | (info, (h ? &h->root : NULL), name, |
541 | howto_table[rel->r_type].name, (bfd_vma) 0, input_bfd, | |
542 | input_section, rel->r_vaddr - input_section->vma))) | |
b34976b6 | 543 | return FALSE; |
3b16e843 | 544 | } |
b34976b6 | 545 | } |
3b16e843 | 546 | |
b34976b6 | 547 | return TRUE; |
3b16e843 NC |
548 | } |
549 | ||
550 | #define coff_relocate_section coff_or32_relocate_section | |
551 | ||
552 | /* We don't want to change the symndx of a R_IHCONST reloc, since it | |
553 | is actually an addend, not a symbol index at all. */ | |
554 | ||
b34976b6 | 555 | static bfd_boolean |
3b16e843 NC |
556 | coff_or32_adjust_symndx (obfd, info, ibfd, sec, irel, adjustedp) |
557 | bfd *obfd ATTRIBUTE_UNUSED; | |
558 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
559 | bfd *ibfd ATTRIBUTE_UNUSED; | |
560 | asection *sec ATTRIBUTE_UNUSED; | |
561 | struct internal_reloc *irel; | |
b34976b6 | 562 | bfd_boolean *adjustedp; |
3b16e843 NC |
563 | { |
564 | if (irel->r_type == R_IHCONST) | |
b34976b6 | 565 | *adjustedp = TRUE; |
3b16e843 | 566 | else |
b34976b6 AM |
567 | *adjustedp = FALSE; |
568 | return TRUE; | |
3b16e843 NC |
569 | } |
570 | ||
571 | #define coff_adjust_symndx coff_or32_adjust_symndx | |
572 | ||
573 | #include "coffcode.h" | |
574 | ||
575 | const bfd_target or32coff_big_vec = | |
576 | { | |
577 | "coff-or32-big", /* Name. */ | |
578 | bfd_target_coff_flavour, | |
579 | BFD_ENDIAN_BIG, /* Data byte order is big. */ | |
580 | BFD_ENDIAN_BIG, /* Header byte order is big. */ | |
581 | ||
582 | (HAS_RELOC | EXEC_P | /* Object flags. */ | |
583 | HAS_LINENO | HAS_DEBUG | | |
584 | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
585 | ||
586 | (SEC_HAS_CONTENTS | SEC_ALLOC | /* Section flags. */ | |
b34976b6 | 587 | SEC_LOAD | SEC_RELOC | |
3b16e843 NC |
588 | SEC_READONLY ), |
589 | '_', /* Leading underscore. */ | |
590 | '/', /* ar_pad_char. */ | |
591 | 15, /* ar_max_namelen. */ | |
592 | ||
593 | /* Data. */ | |
594 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
595 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
596 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, | |
597 | ||
598 | /* Headers. */ | |
599 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
600 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
601 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, | |
602 | ||
b34976b6 | 603 | { |
3b16e843 NC |
604 | _bfd_dummy_target, |
605 | coff_object_p, | |
606 | bfd_generic_archive_p, | |
607 | _bfd_dummy_target | |
608 | }, | |
609 | { | |
610 | bfd_false, | |
611 | coff_mkobject, | |
612 | _bfd_generic_mkarchive, | |
613 | bfd_false | |
614 | }, | |
615 | { | |
616 | bfd_false, | |
617 | coff_write_object_contents, | |
618 | _bfd_write_archive_contents, | |
619 | bfd_false | |
620 | }, | |
621 | ||
622 | BFD_JUMP_TABLE_GENERIC (coff), | |
623 | BFD_JUMP_TABLE_COPY (coff), | |
624 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
625 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
626 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
627 | BFD_JUMP_TABLE_RELOCS (coff), | |
628 | BFD_JUMP_TABLE_WRITE (coff), | |
629 | BFD_JUMP_TABLE_LINK (coff), | |
630 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
b34976b6 | 631 | |
3b16e843 NC |
632 | /* Alternative_target. */ |
633 | #ifdef TARGET_LITTLE_SYM | |
634 | & TARGET_LITTLE_SYM, | |
635 | #else | |
636 | NULL, | |
637 | #endif | |
638 | ||
639 | COFF_SWAP_TABLE | |
640 | }; |