OLD | NEW |
1 /* BFD back-end for OpenRISC 1000 COFF binaries. | 1 /* BFD back-end for OpenRISC 1000 COFF binaries. |
2 Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011 | 2 Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 Contributed by Ivan Guzvinec <ivang@opencores.org> | 4 Contributed by Ivan Guzvinec <ivang@opencores.org> |
5 | 5 |
6 This file is part of BFD, the Binary File Descriptor library. | 6 This file is part of BFD, the Binary File Descriptor library. |
7 | 7 |
8 This program is free software; you can redistribute it and/or modify | 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 | 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 | 10 the Free Software Foundation; either version 3 of the License, or |
11 (at your option) any later version. | 11 (at your option) any later version. |
12 | 12 |
13 This program is distributed in the hope that it will be useful, | 13 This program is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 GNU General Public License for more details. | 16 GNU General Public License for more details. |
17 | 17 |
18 You should have received a copy of the GNU General Public License | 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 | 19 along with this program; if not, write to the Free Software |
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | 20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 MA 02110-1301, USA. */ | 21 MA 02110-1301, USA. */ |
22 | 22 |
23 #define OR32 1 | 23 #define OR32 1 |
24 | 24 |
25 #include "sysdep.h" | 25 #include "sysdep.h" |
26 #include "bfd.h" | 26 #include "bfd.h" |
27 #include "libbfd.h" | 27 #include "libbfd.h" |
28 #include "coff/or32.h" | 28 #include "coff/or32.h" |
29 #include "coff/internal.h" | 29 #include "coff/internal.h" |
30 #include "libcoff.h" | 30 #include "libcoff.h" |
31 | 31 |
32 static long get_symbol_value | |
33 PARAMS ((asymbol *)); | |
34 static bfd_reloc_status_type or32_reloc | 32 static bfd_reloc_status_type or32_reloc |
35 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | 33 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
36 static bfd_boolean coff_or32_relocate_section | |
37 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
38 » struct internal_reloc *, struct internal_syment *, asection **)); | |
39 static bfd_boolean coff_or32_adjust_symndx | |
40 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, | |
41 » struct internal_reloc *, bfd_boolean *)); | |
42 static void reloc_processing | |
43 PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *)); | |
44 | 34 |
45 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) | 35 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) |
46 | 36 |
47 #define INSERT_HWORD(WORD,HWORD) \ | 37 #define INSERT_HWORD(WORD,HWORD) \ |
48 (((WORD) & 0xffff0000) | ((HWORD)& 0x0000ffff)) | 38 (((WORD) & 0xffff0000) | ((HWORD)& 0x0000ffff)) |
49 #define EXTRACT_HWORD(WORD) \ | 39 #define EXTRACT_HWORD(WORD) \ |
50 ((WORD) & 0x0000ffff) | 40 ((WORD) & 0x0000ffff) |
51 #define SIGN_EXTEND_HWORD(HWORD) \ | 41 #define SIGN_EXTEND_HWORD(HWORD) \ |
52 ((HWORD) & 0x8000 ? (HWORD)|(~0xffffL) : (HWORD)) | 42 ((HWORD) & 0x8000 ? (HWORD)|(~0xffffL) : (HWORD)) |
53 | 43 |
54 #define INSERT_JUMPTARG(WORD,JT) \ | 44 #define INSERT_JUMPTARG(WORD,JT) \ |
55 (((WORD) & 0xfc000000) | ((JT)& 0x03ffffff)) | 45 (((WORD) & 0xfc000000) | ((JT)& 0x03ffffff)) |
56 #define EXTRACT_JUMPTARG(WORD) \ | 46 #define EXTRACT_JUMPTARG(WORD) \ |
57 ((WORD) & 0x03ffffff) | 47 ((WORD) & 0x03ffffff) |
58 #define SIGN_EXTEND_JUMPTARG(JT) \ | 48 #define SIGN_EXTEND_JUMPTARG(JT) \ |
59 ((JT) & 0x04000000 ? (JT)|(~0x03ffffffL) : (JT)) | 49 ((JT) & 0x04000000 ? (JT)|(~0x03ffffffL) : (JT)) |
60 | 50 |
61 /* Provided the symbol, returns the value reffed. */ | 51 /* Provided the symbol, returns the value reffed. */ |
62 | 52 |
63 static long | 53 static long |
64 get_symbol_value (symbol) | 54 get_symbol_value (asymbol *symbol) |
65 asymbol *symbol; | |
66 { | 55 { |
67 long relocation = 0; | 56 long relocation = 0; |
68 | 57 |
69 if (bfd_is_com_section (symbol->section)) | 58 if (bfd_is_com_section (symbol->section)) |
70 relocation = 0; | 59 relocation = 0; |
71 else | 60 else |
72 relocation = symbol->value + | 61 relocation = symbol->value + |
73 symbol->section->output_section->vma + | 62 symbol->section->output_section->vma + |
74 symbol->section->output_offset; | 63 symbol->section->output_offset; |
75 | 64 |
76 return relocation; | 65 return relocation; |
77 } | 66 } |
78 | 67 |
79 /* This function is in charge of performing all the or32 relocations. */ | 68 /* This function is in charge of performing all the or32 relocations. */ |
80 | 69 |
81 static bfd_reloc_status_type | 70 static bfd_reloc_status_type |
82 or32_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | 71 or32_reloc (bfd *abfd, |
83 error_message) | 72 » arelent *reloc_entry, |
84 bfd *abfd; | 73 » asymbol *symbol_in, |
85 arelent *reloc_entry; | 74 » void * data, |
86 asymbol *symbol_in; | 75 » asection *input_section, |
87 PTR data; | 76 » bfd *output_bfd, |
88 asection *input_section; | 77 » char **error_message) |
89 bfd *output_bfd; | |
90 char **error_message; | |
91 { | 78 { |
92 /* The consth relocation comes in two parts, we have to remember | 79 /* The consth relocation comes in two parts, we have to remember |
93 the state between calls, in these variables. */ | 80 the state between calls, in these variables. */ |
94 static bfd_boolean part1_consth_active = FALSE; | 81 static bfd_boolean part1_consth_active = FALSE; |
95 static unsigned long part1_consth_value; | 82 static unsigned long part1_consth_value; |
96 | 83 |
97 unsigned long insn; | 84 unsigned long insn; |
98 unsigned long sym_value; | 85 unsigned long sym_value; |
99 unsigned long unsigned_value; | 86 unsigned long unsigned_value; |
100 unsigned short r_type; | 87 unsigned short r_type; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 { R_HWORD, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, or32_reloc, "H
WORD", TRUE, 0x0000ffff,0x0000ffff, FALSE }, | 269 { R_HWORD, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, or32_reloc, "H
WORD", TRUE, 0x0000ffff,0x0000ffff, FALSE }, |
283 { R_WORD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, or32_reloc, "W
ORD", TRUE, 0xffffffff,0xffffffff, FALSE }, | 270 { R_WORD, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, or32_reloc, "W
ORD", TRUE, 0xffffffff,0xffffffff, FALSE }, |
284 }; | 271 }; |
285 | 272 |
286 #define BADMAG(x) OR32BADMAG (x) | 273 #define BADMAG(x) OR32BADMAG (x) |
287 | 274 |
288 #define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \ | 275 #define RELOC_PROCESSING(relent, reloc, symbols, abfd, section) \ |
289 reloc_processing (relent, reloc, symbols, abfd, section) | 276 reloc_processing (relent, reloc, symbols, abfd, section) |
290 | 277 |
291 static void | 278 static void |
292 reloc_processing (relent,reloc, symbols, abfd, section) | 279 reloc_processing (arelent *relent, |
293 arelent *relent; | 280 » » struct internal_reloc *reloc, |
294 struct internal_reloc *reloc; | 281 » » asymbol **symbols, |
295 asymbol **symbols; | 282 » » bfd *abfd, |
296 bfd *abfd; | 283 » » asection *section) |
297 asection *section; | |
298 { | 284 { |
299 static bfd_vma ihihalf_vaddr = (bfd_vma) -1; | 285 static bfd_vma ihihalf_vaddr = (bfd_vma) -1; |
300 | 286 |
301 relent->address = reloc->r_vaddr; | 287 relent->address = reloc->r_vaddr; |
302 relent->howto = howto_table + reloc->r_type; | 288 relent->howto = howto_table + reloc->r_type; |
303 | 289 |
304 if (reloc->r_type == R_IHCONST) | 290 if (reloc->r_type == R_IHCONST) |
305 { | 291 { |
306 /* The address of an R_IHCONST should always be the address of | 292 /* The address of an R_IHCONST should always be the address of |
307 the immediately preceding R_IHIHALF. relocs generated by gas | 293 the immediately preceding R_IHIHALF. relocs generated by gas |
(...skipping 18 matching lines...) Expand all Loading... |
326 if (reloc->r_type == R_IHIHALF) | 312 if (reloc->r_type == R_IHIHALF) |
327 ihihalf_vaddr = relent->address; | 313 ihihalf_vaddr = relent->address; |
328 else if (ihihalf_vaddr != (bfd_vma) -1) | 314 else if (ihihalf_vaddr != (bfd_vma) -1) |
329 abort (); | 315 abort (); |
330 } | 316 } |
331 } | 317 } |
332 | 318 |
333 /* The reloc processing routine for the optimized COFF linker. */ | 319 /* The reloc processing routine for the optimized COFF linker. */ |
334 | 320 |
335 static bfd_boolean | 321 static bfd_boolean |
336 coff_or32_relocate_section (output_bfd, info, input_bfd, input_section, | 322 coff_or32_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, |
337 contents, relocs, syms, sections) | 323 » » » struct bfd_link_info *info, |
338 bfd *output_bfd ATTRIBUTE_UNUSED; | 324 » » » bfd *input_bfd, |
339 struct bfd_link_info *info; | 325 » » » asection *input_section, |
340 bfd *input_bfd; | 326 » » » bfd_byte *contents, |
341 asection *input_section; | 327 » » » struct internal_reloc *relocs, |
342 bfd_byte *contents; | 328 » » » struct internal_syment *syms, |
343 struct internal_reloc *relocs; | 329 » » » asection **sections) |
344 struct internal_syment *syms; | |
345 asection **sections; | |
346 { | 330 { |
347 struct internal_reloc *rel; | 331 struct internal_reloc *rel; |
348 struct internal_reloc *relend; | 332 struct internal_reloc *relend; |
349 bfd_boolean hihalf; | 333 bfd_boolean hihalf; |
350 bfd_vma hihalf_val; | 334 bfd_vma hihalf_val; |
351 | 335 |
352 /* If we are performing a relocatable link, we don't need to do a | 336 /* If we are performing a relocatable link, we don't need to do a |
353 thing. The caller will take care of adjusting the reloc | 337 thing. The caller will take care of adjusting the reloc |
354 addresses and symbol indices. */ | 338 addresses and symbol indices. */ |
355 if (info->relocatable) | 339 if (info->relocatable) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 531 |
548 return TRUE; | 532 return TRUE; |
549 } | 533 } |
550 | 534 |
551 #define coff_relocate_section coff_or32_relocate_section | 535 #define coff_relocate_section coff_or32_relocate_section |
552 | 536 |
553 /* We don't want to change the symndx of a R_IHCONST reloc, since it | 537 /* We don't want to change the symndx of a R_IHCONST reloc, since it |
554 is actually an addend, not a symbol index at all. */ | 538 is actually an addend, not a symbol index at all. */ |
555 | 539 |
556 static bfd_boolean | 540 static bfd_boolean |
557 coff_or32_adjust_symndx (obfd, info, ibfd, sec, irel, adjustedp) | 541 coff_or32_adjust_symndx (bfd *obfd ATTRIBUTE_UNUSED, |
558 bfd *obfd ATTRIBUTE_UNUSED; | 542 » » » struct bfd_link_info *info ATTRIBUTE_UNUSED, |
559 struct bfd_link_info *info ATTRIBUTE_UNUSED; | 543 » » » bfd *ibfd ATTRIBUTE_UNUSED, |
560 bfd *ibfd ATTRIBUTE_UNUSED; | 544 » » » asection *sec ATTRIBUTE_UNUSED, |
561 asection *sec ATTRIBUTE_UNUSED; | 545 » » » struct internal_reloc *irel, |
562 struct internal_reloc *irel; | 546 » » » bfd_boolean *adjustedp) |
563 bfd_boolean *adjustedp; | |
564 { | 547 { |
565 if (irel->r_type == R_IHCONST) | 548 if (irel->r_type == R_IHCONST) |
566 *adjustedp = TRUE; | 549 *adjustedp = TRUE; |
567 else | 550 else |
568 *adjustedp = FALSE; | 551 *adjustedp = FALSE; |
569 return TRUE; | 552 return TRUE; |
570 } | 553 } |
571 | 554 |
572 #define coff_adjust_symndx coff_or32_adjust_symndx | 555 #define coff_adjust_symndx coff_or32_adjust_symndx |
573 | 556 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 620 |
638 /* Alternative_target. */ | 621 /* Alternative_target. */ |
639 #ifdef TARGET_LITTLE_SYM | 622 #ifdef TARGET_LITTLE_SYM |
640 & TARGET_LITTLE_SYM, | 623 & TARGET_LITTLE_SYM, |
641 #else | 624 #else |
642 NULL, | 625 NULL, |
643 #endif | 626 #endif |
644 | 627 |
645 COFF_SWAP_TABLE | 628 COFF_SWAP_TABLE |
646 }; | 629 }; |
OLD | NEW |