1 /* Ubicom IP2xxx specific support for 32-bit ELF
2 Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 /* Struct used to pass miscellaneous paramaters which
27 helps to avoid overly long parameter lists. */
30 Elf_Internal_Shdr * symtab_hdr;
31 Elf_Internal_Rela * irelbase;
33 Elf_Internal_Sym * isymbuf;
38 unsigned short opcode;
43 static reloc_howto_type *ip2k_reloc_type_lookup
44 PARAMS ((bfd *, bfd_reloc_code_real_type));
45 static int ip2k_is_opcode
46 PARAMS ((bfd_byte *, const struct ip2k_opcode *));
47 static bfd_vma symbol_value
48 PARAMS ((bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *,
49 Elf_Internal_Rela *));
50 static void ip2k_get_mem
51 PARAMS ((bfd *, bfd_byte *, int, bfd_byte *));
52 static bfd_vma ip2k_nominal_page_bits
53 PARAMS ((bfd *, asection *, bfd_vma, bfd_byte *));
54 static bfd_boolean ip2k_test_page_insn
55 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, struct misc *));
56 static bfd_boolean ip2k_delete_page_insn
57 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_boolean *, struct misc *));
58 static int ip2k_is_switch_table_128
59 PARAMS ((bfd *, asection *, bfd_vma, bfd_byte *));
60 static bfd_boolean ip2k_relax_switch_table_128
61 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_boolean *, struct misc *));
62 static int ip2k_is_switch_table_256
63 PARAMS ((bfd *, asection *, bfd_vma, bfd_byte *));
64 static bfd_boolean ip2k_relax_switch_table_256
65 PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_boolean *, struct misc *));
66 static bfd_boolean ip2k_elf_relax_section
67 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
68 static bfd_boolean ip2k_elf_relax_section_page
69 PARAMS ((bfd *, asection *, bfd_boolean *, struct misc *, unsigned long, unsigned long));
70 static void adjust_all_relocations
71 PARAMS ((bfd *, asection *, bfd_vma, bfd_vma, int, int));
72 static bfd_boolean ip2k_elf_relax_delete_bytes
73 PARAMS ((bfd *, asection *, bfd_vma, int));
74 static void ip2k_info_to_howto_rela
75 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
76 static bfd_reloc_status_type ip2k_final_link_relocate
77 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
78 Elf_Internal_Rela *, bfd_vma));
79 static bfd_boolean ip2k_elf_relocate_section
80 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
81 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
82 static asection *ip2k_elf_gc_mark_hook
83 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
84 struct elf_link_hash_entry *, Elf_Internal_Sym *));
85 static bfd_boolean ip2k_elf_gc_sweep_hook
86 PARAMS ((bfd *, struct bfd_link_info *, asection *,
87 const Elf_Internal_Rela *));
89 static bfd_boolean ip2k_relaxed = FALSE;
91 static const struct ip2k_opcode ip2k_page_opcode[] =
93 {0x0010, 0xFFF8}, /* page */
97 #define IS_PAGE_OPCODE(code) \
98 ip2k_is_opcode (code, ip2k_page_opcode)
100 static const struct ip2k_opcode ip2k_jmp_opcode[] =
102 {0xE000, 0xE000}, /* jmp */
106 #define IS_JMP_OPCODE(code) \
107 ip2k_is_opcode (code, ip2k_jmp_opcode)
109 static const struct ip2k_opcode ip2k_snc_opcode[] =
111 {0xA00B, 0xFFFF}, /* snc */
115 #define IS_SNC_OPCODE(code) \
116 ip2k_is_opcode (code, ip2k_snc_opcode)
118 static const struct ip2k_opcode ip2k_inc_1sp_opcode[] =
120 {0x2B81, 0xFFFF}, /* inc 1(SP) */
124 #define IS_INC_1SP_OPCODE(code) \
125 ip2k_is_opcode (code, ip2k_inc_1sp_opcode)
127 static const struct ip2k_opcode ip2k_add_2sp_w_opcode[] =
129 {0x1F82, 0xFFFF}, /* add 2(SP),w */
133 #define IS_ADD_2SP_W_OPCODE(code) \
134 ip2k_is_opcode (code, ip2k_add_2sp_w_opcode)
136 static const struct ip2k_opcode ip2k_add_w_wreg_opcode[] =
138 {0x1C0A, 0xFFFF}, /* add w,wreg */
139 {0x1E0A, 0xFFFF}, /* add wreg,w */
143 #define IS_ADD_W_WREG_OPCODE(code) \
144 ip2k_is_opcode (code, ip2k_add_w_wreg_opcode)
146 static const struct ip2k_opcode ip2k_add_pcl_w_opcode[] =
148 {0x1E09, 0xFFFF}, /* add pcl,w */
152 #define IS_ADD_PCL_W_OPCODE(code) \
153 ip2k_is_opcode (code, ip2k_add_pcl_w_opcode)
155 static const struct ip2k_opcode ip2k_skip_opcodes[] =
157 {0xB000, 0xF000}, /* sb */
158 {0xA000, 0xF000}, /* snb */
159 {0x7600, 0xFE00}, /* cse/csne #lit */
160 {0x5800, 0xFC00}, /* incsnz */
161 {0x4C00, 0xFC00}, /* decsnz */
162 {0x4000, 0xFC00}, /* cse/csne */
163 {0x3C00, 0xFC00}, /* incsz */
164 {0x2C00, 0xFC00}, /* decsz */
168 #define IS_SKIP_OPCODE(code) \
169 ip2k_is_opcode (code, ip2k_skip_opcodes)
171 /* Relocation tables. */
172 static reloc_howto_type ip2k_elf_howto_table [] =
174 #define IP2K_HOWTO(t,rs,s,bs,pr,bp,name,sm,dm) \
175 HOWTO(t, /* type */ \
176 rs, /* rightshift */ \
177 s, /* size (0 = byte, 1 = short, 2 = long) */ \
179 pr, /* pc_relative */ \
181 complain_overflow_dont,/* complain_on_overflow */ \
182 bfd_elf_generic_reloc,/* special_function */ \
184 FALSE, /* partial_inplace */ \
187 pr) /* pcrel_offset */
189 /* This reloc does nothing. */
190 IP2K_HOWTO (R_IP2K_NONE, 0,2,32, FALSE, 0, "R_IP2K_NONE", 0, 0),
191 /* A 16 bit absolute relocation. */
192 IP2K_HOWTO (R_IP2K_16, 0,1,16, FALSE, 0, "R_IP2K_16", 0, 0xffff),
193 /* A 32 bit absolute relocation. */
194 IP2K_HOWTO (R_IP2K_32, 0,2,32, FALSE, 0, "R_IP2K_32", 0, 0xffffffff),
195 /* A 8-bit data relocation for the FR9 field. Ninth bit is computed specially. */
196 IP2K_HOWTO (R_IP2K_FR9, 0,1,9, FALSE, 0, "R_IP2K_FR9", 0, 0x00ff),
197 /* A 4-bit data relocation. */
198 IP2K_HOWTO (R_IP2K_BANK, 8,1,4, FALSE, 0, "R_IP2K_BANK", 0, 0x000f),
199 /* A 13-bit insn relocation - word address => right-shift 1 bit extra. */
200 IP2K_HOWTO (R_IP2K_ADDR16CJP, 1,1,13, FALSE, 0, "R_IP2K_ADDR16CJP", 0, 0x1fff),
201 /* A 3-bit insn relocation - word address => right-shift 1 bit extra. */
202 IP2K_HOWTO (R_IP2K_PAGE3, 14,1,3, FALSE, 0, "R_IP2K_PAGE3", 0, 0x0007),
203 /* Two 8-bit data relocations. */
204 IP2K_HOWTO (R_IP2K_LO8DATA, 0,1,8, FALSE, 0, "R_IP2K_LO8DATA", 0, 0x00ff),
205 IP2K_HOWTO (R_IP2K_HI8DATA, 8,1,8, FALSE, 0, "R_IP2K_HI8DATA", 0, 0x00ff),
206 /* Two 8-bit insn relocations. word address => right-shift 1 bit extra. */
207 IP2K_HOWTO (R_IP2K_LO8INSN, 1,1,8, FALSE, 0, "R_IP2K_LO8INSN", 0, 0x00ff),
208 IP2K_HOWTO (R_IP2K_HI8INSN, 9,1,8, FALSE, 0, "R_IP2K_HI8INSN", 0, 0x00ff),
210 /* Special 1 bit relocation for SKIP instructions. */
211 IP2K_HOWTO (R_IP2K_PC_SKIP, 1,1,1, FALSE, 12, "R_IP2K_PC_SKIP", 0xfffe, 0x1000),
212 /* 16 bit word address. */
213 IP2K_HOWTO (R_IP2K_TEXT, 1,1,16, FALSE, 0, "R_IP2K_TEXT", 0, 0xffff),
214 /* A 7-bit offset relocation for the FR9 field. Eigth and ninth bit comes from insn. */
215 IP2K_HOWTO (R_IP2K_FR_OFFSET, 0,1,9, FALSE, 0, "R_IP2K_FR_OFFSET", 0x180, 0x007f),
216 /* Bits 23:16 of an address. */
217 IP2K_HOWTO (R_IP2K_EX8DATA, 16,1,8, FALSE, 0, "R_IP2K_EX8DATA", 0, 0x00ff),
221 /* Map BFD reloc types to IP2K ELF reloc types. */
222 static reloc_howto_type *
223 ip2k_reloc_type_lookup (abfd, code)
224 bfd * abfd ATTRIBUTE_UNUSED;
225 bfd_reloc_code_real_type code;
227 /* Note that the ip2k_elf_howto_table is indxed by the R_
228 constants. Thus, the order that the howto records appear in the
229 table *must* match the order of the relocation types defined in
230 include/elf/ip2k.h. */
235 return &ip2k_elf_howto_table[ (int) R_IP2K_NONE];
237 return &ip2k_elf_howto_table[ (int) R_IP2K_16];
239 return &ip2k_elf_howto_table[ (int) R_IP2K_32];
240 case BFD_RELOC_IP2K_FR9:
241 return &ip2k_elf_howto_table[ (int) R_IP2K_FR9];
242 case BFD_RELOC_IP2K_BANK:
243 return &ip2k_elf_howto_table[ (int) R_IP2K_BANK];
244 case BFD_RELOC_IP2K_ADDR16CJP:
245 return &ip2k_elf_howto_table[ (int) R_IP2K_ADDR16CJP];
246 case BFD_RELOC_IP2K_PAGE3:
247 return &ip2k_elf_howto_table[ (int) R_IP2K_PAGE3];
248 case BFD_RELOC_IP2K_LO8DATA:
249 return &ip2k_elf_howto_table[ (int) R_IP2K_LO8DATA];
250 case BFD_RELOC_IP2K_HI8DATA:
251 return &ip2k_elf_howto_table[ (int) R_IP2K_HI8DATA];
252 case BFD_RELOC_IP2K_LO8INSN:
253 return &ip2k_elf_howto_table[ (int) R_IP2K_LO8INSN];
254 case BFD_RELOC_IP2K_HI8INSN:
255 return &ip2k_elf_howto_table[ (int) R_IP2K_HI8INSN];
256 case BFD_RELOC_IP2K_PC_SKIP:
257 return &ip2k_elf_howto_table[ (int) R_IP2K_PC_SKIP];
258 case BFD_RELOC_IP2K_TEXT:
259 return &ip2k_elf_howto_table[ (int) R_IP2K_TEXT];
260 case BFD_RELOC_IP2K_FR_OFFSET:
261 return &ip2k_elf_howto_table[ (int) R_IP2K_FR_OFFSET];
262 case BFD_RELOC_IP2K_EX8DATA:
263 return &ip2k_elf_howto_table[ (int) R_IP2K_EX8DATA];
265 /* Pacify gcc -Wall. */
272 ip2k_get_mem (abfd, addr, length, ptr)
273 bfd *abfd ATTRIBUTE_UNUSED;
279 * ptr ++ = bfd_get_8 (abfd, addr ++);
283 ip2k_is_opcode (code, opcodes)
285 const struct ip2k_opcode *opcodes;
287 unsigned short insn = (code[0] << 8) | code[1];
289 while (opcodes->mask != 0)
291 if ((insn & opcodes->mask) == opcodes->opcode)
300 #define PAGENO(ABSADDR) ((ABSADDR) & 0xFFFFC000)
301 #define BASEADDR(SEC) ((SEC)->output_section->vma + (SEC)->output_offset)
303 #define UNDEFINED_SYMBOL (~(bfd_vma)0)
305 /* Return the value of the symbol associated with the relocation IREL. */
308 symbol_value (abfd, symtab_hdr, isymbuf, irel)
310 Elf_Internal_Shdr *symtab_hdr;
311 Elf_Internal_Sym *isymbuf;
312 Elf_Internal_Rela *irel;
314 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
316 Elf_Internal_Sym *isym;
319 isym = isymbuf + ELF32_R_SYM (irel->r_info);
320 if (isym->st_shndx == SHN_UNDEF)
321 sym_sec = bfd_und_section_ptr;
322 else if (isym->st_shndx == SHN_ABS)
323 sym_sec = bfd_abs_section_ptr;
324 else if (isym->st_shndx == SHN_COMMON)
325 sym_sec = bfd_com_section_ptr;
327 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
329 return isym->st_value + BASEADDR (sym_sec);
334 struct elf_link_hash_entry *h;
336 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
337 h = elf_sym_hashes (abfd)[indx];
338 BFD_ASSERT (h != NULL);
340 if (h->root.type != bfd_link_hash_defined
341 && h->root.type != bfd_link_hash_defweak)
342 return UNDEFINED_SYMBOL;
344 return (h->root.u.def.value + BASEADDR (h->root.u.def.section));
348 /* Returns the expected page state for the given instruction not including
349 the effect of page instructions. */
352 ip2k_nominal_page_bits (abfd, sec, addr, contents)
353 bfd *abfd ATTRIBUTE_UNUSED;
358 bfd_vma page = PAGENO (BASEADDR (sec) + addr);
360 /* Check if section flows into this page. If not then the page
361 bits are assumed to match the PC. This will be true unless
362 the user has a page instruction without a call/jump, in which
363 case they are on their own. */
364 if (PAGENO (BASEADDR (sec)) == page)
367 /* Section flows across page boundary. The page bits should match
368 the PC unless there is a possible flow from the previous page,
369 in which case it is not possible to determine the value of the
371 while (PAGENO (BASEADDR (sec) + addr - 2) == page)
376 ip2k_get_mem (abfd, contents + addr, 2, code);
377 if (!IS_PAGE_OPCODE (code))
380 /* Found a page instruction, check if jump table. */
381 if (ip2k_is_switch_table_128 (abfd, sec, addr, contents) != -1)
382 /* Jump table => page is conditional. */
385 if (ip2k_is_switch_table_256 (abfd, sec, addr, contents) != -1)
386 /* Jump table => page is conditional. */
389 /* Found a page instruction, check if conditional. */
392 ip2k_get_mem (abfd, contents + addr - 2, 2, code);
393 if (IS_SKIP_OPCODE (code))
394 /* Page is conditional. */
398 /* Unconditional page instruction => page bits should be correct. */
402 /* Flow from previous page => page bits are impossible to determine. */
407 ip2k_test_page_insn (abfd, sec, irel, misc)
408 bfd *abfd ATTRIBUTE_UNUSED;
410 Elf_Internal_Rela *irel;
415 /* Get the value of the symbol referred to by the reloc. */
416 symval = symbol_value (abfd, misc->symtab_hdr, misc->isymbuf, irel);
417 if (symval == UNDEFINED_SYMBOL)
418 /* This appears to be a reference to an undefined
419 symbol. Just ignore it--it will be caught by the
420 regular reloc processing. */
423 /* Test if we can delete this page instruction. */
424 if (PAGENO (symval + irel->r_addend) !=
425 ip2k_nominal_page_bits (abfd, sec, irel->r_offset, misc->contents))
432 ip2k_delete_page_insn (abfd, sec, irel, again, misc)
433 bfd *abfd ATTRIBUTE_UNUSED;
435 Elf_Internal_Rela *irel;
439 /* Note that we've changed the relocs, section contents, etc. */
440 elf_section_data (sec)->relocs = misc->irelbase;
441 elf_section_data (sec)->this_hdr.contents = misc->contents;
442 misc->symtab_hdr->contents = (bfd_byte *) misc->isymbuf;
444 /* Fix the relocation's type. */
445 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_IP2K_NONE);
447 /* Delete the PAGE insn. */
448 if (!ip2k_elf_relax_delete_bytes (abfd, sec, irel->r_offset, 2))
451 /* Modified => will need to iterate relaxation again. */
457 /* Determine if the instruction sequence matches that for
458 the prologue of a switch dispatch table with fewer than
487 ip2k_is_switch_table_128 (abfd, sec, addr, contents)
488 bfd *abfd ATTRIBUTE_UNUSED;
496 /* Check current page-jmp. */
497 if (addr + 4 > sec->size)
500 ip2k_get_mem (abfd, contents + addr, 4, code);
502 if ((! IS_PAGE_OPCODE (code + 0))
503 || (! IS_JMP_OPCODE (code + 2)))
512 /* Check previous 2 instructions. */
513 ip2k_get_mem (abfd, contents + addr - 4, 4, code);
514 if ((IS_ADD_W_WREG_OPCODE (code + 0))
515 && (IS_ADD_PCL_W_OPCODE (code + 2)))
518 if ((! IS_PAGE_OPCODE (code + 0))
519 || (! IS_JMP_OPCODE (code + 2)))
528 ip2k_relax_switch_table_128 (abfd, sec, irel, again, misc)
529 bfd *abfd ATTRIBUTE_UNUSED;
531 Elf_Internal_Rela *irel;
535 Elf_Internal_Rela *irelend = misc->irelbase + sec->reloc_count;
536 Elf_Internal_Rela *ireltest = irel;
540 /* Test all page instructions. */
541 addr = irel->r_offset;
544 if (addr + 4 > sec->size)
547 ip2k_get_mem (abfd, misc->contents + addr, 4, code);
548 if ((! IS_PAGE_OPCODE (code + 0))
549 || (! IS_JMP_OPCODE (code + 2)))
552 /* Validate relocation entry (every entry should have a matching
553 relocation entry). */
554 if (ireltest >= irelend)
556 _bfd_error_handler (_("ip2k relaxer: switch table without complete matching relocation information."));
560 if (ireltest->r_offset != addr)
562 _bfd_error_handler (_("ip2k relaxer: switch table without complete matching relocation information."));
566 if (! ip2k_test_page_insn (abfd, sec, ireltest, misc))
567 /* Un-removable page insn => nothing can be done. */
574 /* Relaxable. Adjust table header. */
575 ip2k_get_mem (abfd, misc->contents + irel->r_offset - 4, 4, code);
576 if ((! IS_ADD_W_WREG_OPCODE (code + 0))
577 || (! IS_ADD_PCL_W_OPCODE (code + 2)))
579 _bfd_error_handler (_("ip2k relaxer: switch table header corrupt."));
583 if (!ip2k_elf_relax_delete_bytes (abfd, sec, irel->r_offset - 4, 2))
588 /* Delete all page instructions in table. */
589 while (irel < ireltest)
591 if (!ip2k_delete_page_insn (abfd, sec, irel, again, misc))
599 /* Determine if the instruction sequence matches that for
600 the prologue switch dispatch table with fewer than
601 256 entries but more than 127.
604 push %lo8insn(label) ; Push address of table
606 add w,wreg ; index*2 => offset
608 inc 1(sp) ; Propagate MSB into table address
609 add 2(sp),w ; Add low bits of offset to table address
610 snc ; and handle any carry-out
613 page __indjmp ; Do an indirect jump to that location
615 label: ; case dispatch table starts here
625 push %lo8insn(label) ; Push address of table
627 add 2(sp),w ; Add low bits of offset to table address
628 snc ; and handle any carry-out
631 page __indjmp ; Do an indirect jump to that location
633 label: ; case dispatch table starts here
640 ip2k_is_switch_table_256 (abfd, sec, addr, contents)
641 bfd *abfd ATTRIBUTE_UNUSED;
649 /* Check current page-jmp. */
650 if (addr + 4 > sec->size)
653 ip2k_get_mem (abfd, contents + addr, 4, code);
654 if ((! IS_PAGE_OPCODE (code + 0))
655 || (! IS_JMP_OPCODE (code + 2)))
664 /* Check previous 8 instructions. */
665 ip2k_get_mem (abfd, contents + addr - 16, 16, code);
666 if ((IS_ADD_W_WREG_OPCODE (code + 0))
667 && (IS_SNC_OPCODE (code + 2))
668 && (IS_INC_1SP_OPCODE (code + 4))
669 && (IS_ADD_2SP_W_OPCODE (code + 6))
670 && (IS_SNC_OPCODE (code + 8))
671 && (IS_INC_1SP_OPCODE (code + 10))
672 && (IS_PAGE_OPCODE (code + 12))
673 && (IS_JMP_OPCODE (code + 14)))
676 if ((IS_ADD_W_WREG_OPCODE (code + 2))
677 && (IS_SNC_OPCODE (code + 4))
678 && (IS_INC_1SP_OPCODE (code + 6))
679 && (IS_ADD_2SP_W_OPCODE (code + 8))
680 && (IS_SNC_OPCODE (code + 10))
681 && (IS_INC_1SP_OPCODE (code + 12))
682 && (IS_JMP_OPCODE (code + 14)))
685 if ((! IS_PAGE_OPCODE (code + 0))
686 || (! IS_JMP_OPCODE (code + 2)))
695 ip2k_relax_switch_table_256 (abfd, sec, irel, again, misc)
696 bfd *abfd ATTRIBUTE_UNUSED;
698 Elf_Internal_Rela *irel;
702 Elf_Internal_Rela *irelend = misc->irelbase + sec->reloc_count;
703 Elf_Internal_Rela *ireltest = irel;
707 /* Test all page instructions. */
708 addr = irel->r_offset;
712 if (addr + 4 > sec->size)
715 ip2k_get_mem (abfd, misc->contents + addr, 4, code);
717 if ((! IS_PAGE_OPCODE (code + 0))
718 || (! IS_JMP_OPCODE (code + 2)))
721 /* Validate relocation entry (every entry should have a matching
722 relocation entry). */
723 if (ireltest >= irelend)
725 _bfd_error_handler (_("ip2k relaxer: switch table without complete matching relocation information."));
729 if (ireltest->r_offset != addr)
731 _bfd_error_handler (_("ip2k relaxer: switch table without complete matching relocation information."));
735 if (!ip2k_test_page_insn (abfd, sec, ireltest, misc))
736 /* Un-removable page insn => nothing can be done. */
743 /* Relaxable. Adjust table header. */
744 ip2k_get_mem (abfd, misc->contents + irel->r_offset - 4, 2, code);
745 if (IS_PAGE_OPCODE (code))
746 addr = irel->r_offset - 16;
748 addr = irel->r_offset - 14;
750 ip2k_get_mem (abfd, misc->contents + addr, 12, code);
751 if ((!IS_ADD_W_WREG_OPCODE (code + 0))
752 || (!IS_SNC_OPCODE (code + 2))
753 || (!IS_INC_1SP_OPCODE (code + 4))
754 || (!IS_ADD_2SP_W_OPCODE (code + 6))
755 || (!IS_SNC_OPCODE (code + 8))
756 || (!IS_INC_1SP_OPCODE (code + 10)))
758 _bfd_error_handler (_("ip2k relaxer: switch table header corrupt."));
762 /* Delete first 3 opcodes. */
763 if (!ip2k_elf_relax_delete_bytes (abfd, sec, addr + 0, 6))
768 /* Delete all page instructions in table. */
769 while (irel < ireltest)
771 if (!ip2k_delete_page_insn (abfd, sec, irel, again, misc))
779 /* This function handles relaxing for the ip2k.
781 Principle: Start with the first page and remove page instructions that
782 are not require on this first page. By removing page instructions more
783 code will fit into this page - repeat until nothing more can be achieved
784 for this page. Move on to the next page.
786 Processing the pages one at a time from the lowest page allows a removal
787 only policy to be used - pages can be removed but are never reinserted. */
790 ip2k_elf_relax_section (abfd, sec, link_info, again)
793 struct bfd_link_info *link_info;
796 Elf_Internal_Shdr *symtab_hdr;
797 Elf_Internal_Rela *internal_relocs;
798 bfd_byte *contents = NULL;
799 Elf_Internal_Sym *isymbuf = NULL;
800 static asection * first_section = NULL;
801 static unsigned long search_addr;
802 static unsigned long page_start = 0;
803 static unsigned long page_end = 0;
804 static unsigned int pass = 0;
805 static bfd_boolean new_pass = FALSE;
806 static bfd_boolean changed = FALSE;
810 /* Assume nothing changes. */
813 if (first_section == NULL)
819 if (first_section == sec)
825 /* We don't have to do anything for a relocatable link,
826 if this section does not have relocs, or if this is
827 not a code section. */
828 if (link_info->relocatable
829 || (sec->flags & SEC_RELOC) == 0
830 || sec->reloc_count == 0
831 || (sec->flags & SEC_CODE) == 0)
834 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
836 internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL,
837 (Elf_Internal_Rela *)NULL,
838 link_info->keep_memory);
839 if (internal_relocs == NULL)
842 /* Make sure the stac.rela stuff gets read in. */
843 stab = bfd_get_section_by_name (abfd, ".stab");
847 /* So stab does exits. */
848 Elf_Internal_Rela * irelbase;
850 irelbase = _bfd_elf_link_read_relocs (abfd, stab, NULL,
851 (Elf_Internal_Rela *)NULL,
852 link_info->keep_memory);
855 /* Get section contents cached copy if it exists. */
856 if (contents == NULL)
858 /* Get cached copy if it exists. */
859 if (elf_section_data (sec)->this_hdr.contents != NULL)
860 contents = elf_section_data (sec)->this_hdr.contents;
863 /* Go get them off disk. */
864 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
869 /* Read this BFD's symbols cached copy if it exists. */
870 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
872 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
874 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
875 symtab_hdr->sh_info, 0,
881 misc.symtab_hdr = symtab_hdr;
882 misc.isymbuf = isymbuf;
883 misc.irelbase = internal_relocs;
884 misc.contents = contents;
886 /* This is where all the relaxation actually get done. */
887 if ((pass == 1) || (new_pass && !changed))
889 /* On the first pass we simply search for the lowest page that
890 we havn't relaxed yet. Note that the pass count is reset
891 each time a page is complete in order to move on to the next page.
892 If we can't find any more pages then we are finished. */
897 changed = TRUE; /* Pre-initialize to break out of pass 1. */
898 search_addr = 0xFFFFFFFF;
901 if ((BASEADDR (sec) + sec->size < search_addr)
902 && (BASEADDR (sec) + sec->size > page_end))
904 if (BASEADDR (sec) <= page_end)
905 search_addr = page_end + 1;
907 search_addr = BASEADDR (sec);
909 /* Found a page => more work to do. */
919 page_start = PAGENO (search_addr);
920 page_end = page_start | 0x00003FFF;
923 /* Only process sections in range. */
924 if ((BASEADDR (sec) + sec->size >= page_start)
925 && (BASEADDR (sec) <= page_end))
927 if (!ip2k_elf_relax_section_page (abfd, sec, &changed, &misc, page_start, page_end))
933 /* Perform some house keeping after relaxing the section. */
936 && symtab_hdr->contents != (unsigned char *) isymbuf)
938 if (! link_info->keep_memory)
941 symtab_hdr->contents = (unsigned char *) isymbuf;
945 && elf_section_data (sec)->this_hdr.contents != contents)
947 if (! link_info->keep_memory)
951 /* Cache the section contents for elf_link_input_bfd. */
952 elf_section_data (sec)->this_hdr.contents = contents;
956 if (internal_relocs != NULL
957 && elf_section_data (sec)->relocs != internal_relocs)
958 free (internal_relocs);
964 && symtab_hdr->contents != (unsigned char *) isymbuf)
967 && elf_section_data (sec)->this_hdr.contents != contents)
969 if (internal_relocs != NULL
970 && elf_section_data (sec)->relocs != internal_relocs)
971 free (internal_relocs);
975 /* This function handles relaxation of a section in a specific page. */
978 ip2k_elf_relax_section_page (abfd, sec, again, misc, page_start, page_end)
983 unsigned long page_start;
984 unsigned long page_end;
986 Elf_Internal_Rela *irelend = misc->irelbase + sec->reloc_count;
987 Elf_Internal_Rela *irel;
988 int switch_table_128;
989 int switch_table_256;
991 /* Walk thru the section looking for relaxation opportunities. */
992 for (irel = misc->irelbase; irel < irelend; irel++)
994 if (ELF32_R_TYPE (irel->r_info) != (int) R_IP2K_PAGE3)
995 /* Ignore non page instructions. */
998 if (BASEADDR (sec) + irel->r_offset < page_start)
999 /* Ignore page instructions on earlier page - they have
1000 already been processed. Remember that there is code flow
1001 that crosses a page boundary. */
1004 if (BASEADDR (sec) + irel->r_offset > page_end)
1005 /* Flow beyond end of page => nothing more to do for this page. */
1008 /* Detect switch tables. */
1009 switch_table_128 = ip2k_is_switch_table_128 (abfd, sec, irel->r_offset, misc->contents);
1010 switch_table_256 = ip2k_is_switch_table_256 (abfd, sec, irel->r_offset, misc->contents);
1012 if ((switch_table_128 > 0) || (switch_table_256 > 0))
1013 /* If the index is greater than 0 then it has already been processed. */
1016 if (switch_table_128 == 0)
1018 if (!ip2k_relax_switch_table_128 (abfd, sec, irel, again, misc))
1024 if (switch_table_256 == 0)
1026 if (!ip2k_relax_switch_table_256 (abfd, sec, irel, again, misc))
1033 if (ip2k_test_page_insn (abfd, sec, irel, misc))
1035 if (!ip2k_delete_page_insn (abfd, sec, irel, again, misc))
1045 /* Parts of a Stabs entry. */
1047 #define STRDXOFF (0)
1049 #define OTHEROFF (5)
1052 #define STABSIZE (12)
1054 /* Adjust all the relocations entries after adding or inserting instructions. */
1057 adjust_all_relocations (abfd, sec, addr, endaddr, count, noadj)
1065 Elf_Internal_Shdr *symtab_hdr;
1066 Elf_Internal_Sym *isymbuf, *isym, *isymend;
1069 Elf_Internal_Rela *irel, *irelend, *irelbase;
1070 struct elf_link_hash_entry **sym_hashes;
1071 struct elf_link_hash_entry **end_hashes;
1072 unsigned int symcount;
1075 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1076 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1078 shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
1080 contents = elf_section_data (sec)->this_hdr.contents;
1082 irelbase = elf_section_data (sec)->relocs;
1083 irelend = irelbase + sec->reloc_count;
1085 for (irel = irelbase; irel < irelend; irel++)
1087 if (ELF32_R_TYPE (irel->r_info) != R_IP2K_NONE)
1089 /* Get the value of the symbol referred to by the reloc. */
1090 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1094 /* A local symbol. */
1095 isym = isymbuf + ELF32_R_SYM (irel->r_info);
1096 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1098 if (isym->st_shndx == shndx)
1100 bfd_vma baseaddr = BASEADDR (sec);
1101 bfd_vma symval = BASEADDR (sym_sec) + isym->st_value
1104 if ((baseaddr + addr + noadj) <= symval
1105 && symval < (baseaddr + endaddr))
1106 irel->r_addend += count;
1111 /* Do this only for PC space relocations. */
1112 if (addr <= irel->r_offset && irel->r_offset < endaddr)
1113 irel->r_offset += count;
1116 /* Now fix the stab relocations. */
1117 stab = bfd_get_section_by_name (abfd, ".stab");
1120 bfd_byte *stabcontents, *stabend, *stabp;
1121 bfd_size_type stab_size = stab->rawsize ? stab->rawsize : stab->size;
1123 irelbase = elf_section_data (stab)->relocs;
1124 irelend = irelbase + stab->reloc_count;
1126 /* Pull out the contents of the stab section. */
1127 if (elf_section_data (stab)->this_hdr.contents != NULL)
1128 stabcontents = elf_section_data (stab)->this_hdr.contents;
1131 if (!bfd_malloc_and_get_section (abfd, stab, &stabcontents))
1133 if (stabcontents != NULL)
1134 free (stabcontents);
1138 /* We need to remember this. */
1139 elf_section_data (stab)->this_hdr.contents = stabcontents;
1142 stabend = stabcontents + stab_size;
1144 for (irel = irelbase; irel < irelend; irel++)
1146 if (ELF32_R_TYPE (irel->r_info) != R_IP2K_NONE)
1148 /* Get the value of the symbol referred to by the reloc. */
1149 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1153 /* A local symbol. */
1154 isym = isymbuf + ELF32_R_SYM (irel->r_info);
1155 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1161 unsigned char type, other;
1162 unsigned short desc;
1164 bfd_vma baseaddr = BASEADDR (sec);
1165 bfd_vma symval = BASEADDR (sym_sec) + isym->st_value
1168 if ((baseaddr + addr) <= symval
1169 && symval <= (baseaddr + endaddr))
1170 irel->r_addend += count;
1172 /* Go hunt up a function and fix its line info if needed. */
1173 stabp = stabcontents + irel->r_offset - 8;
1175 /* Go pullout the stab entry. */
1176 strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
1177 type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
1178 other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
1179 desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
1180 value = bfd_h_get_32 (abfd, stabp + VALOFF);
1182 name = bfd_get_stab_name (type);
1184 if (strcmp (name, "FUN") == 0)
1186 int function_adjusted = 0;
1188 if (symval > (baseaddr + addr))
1189 /* Not in this function. */
1192 /* Hey we got a function hit. */
1194 for (;stabp < stabend; stabp += STABSIZE)
1196 /* Go pullout the stab entry. */
1197 strx = bfd_h_get_32 (abfd, stabp + STRDXOFF);
1198 type = bfd_h_get_8 (abfd, stabp + TYPEOFF);
1199 other = bfd_h_get_8 (abfd, stabp + OTHEROFF);
1200 desc = bfd_h_get_16 (abfd, stabp + DESCOFF);
1201 value = bfd_h_get_32 (abfd, stabp + VALOFF);
1203 name = bfd_get_stab_name (type);
1205 if (strcmp (name, "FUN") == 0)
1207 /* Hit another function entry. */
1208 if (function_adjusted)
1210 /* Adjust the value. */
1213 /* We need to put it back. */
1214 bfd_h_put_32 (abfd, value,stabp + VALOFF);
1217 /* And then bale out. */
1221 if (strcmp (name, "SLINE") == 0)
1223 /* Got a line entry. */
1224 if ((baseaddr + addr) <= (symval + value))
1226 /* Adjust the line entry. */
1229 /* We need to put it back. */
1230 bfd_h_put_32 (abfd, value,stabp + VALOFF);
1231 function_adjusted = 1;
1242 /* When adding an instruction back it is sometimes necessary to move any
1243 global or local symbol that was referencing the first instruction of
1244 the moved block to refer to the first instruction of the inserted block.
1246 For example adding a PAGE instruction before a CALL or JMP requires
1247 that any label on the CALL or JMP is moved to the PAGE insn. */
1250 /* Adjust the local symbols defined in this section. */
1251 isymend = isymbuf + symtab_hdr->sh_info;
1252 for (isym = isymbuf; isym < isymend; isym++)
1254 if (isym->st_shndx == shndx
1255 && addr <= isym->st_value
1256 && isym->st_value < endaddr)
1257 isym->st_value += count;
1260 /* Now adjust the global symbols defined in this section. */
1261 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
1262 - symtab_hdr->sh_info);
1263 sym_hashes = elf_sym_hashes (abfd);
1264 end_hashes = sym_hashes + symcount;
1265 for (; sym_hashes < end_hashes; sym_hashes++)
1267 struct elf_link_hash_entry *sym_hash = *sym_hashes;
1269 if ((sym_hash->root.type == bfd_link_hash_defined
1270 || sym_hash->root.type == bfd_link_hash_defweak)
1271 && sym_hash->root.u.def.section == sec)
1273 if (addr <= sym_hash->root.u.def.value
1274 && sym_hash->root.u.def.value < endaddr)
1275 sym_hash->root.u.def.value += count;
1282 /* Delete some bytes from a section while relaxing. */
1285 ip2k_elf_relax_delete_bytes (abfd, sec, addr, count)
1291 bfd_byte *contents = elf_section_data (sec)->this_hdr.contents;
1292 bfd_vma endaddr = sec->size;
1294 /* Actually delete the bytes. */
1295 memmove (contents + addr, contents + addr + count,
1296 endaddr - addr - count);
1300 adjust_all_relocations (abfd, sec, addr + count, endaddr, -count, 0);
1304 /* -------------------------------------------------------------------- */
1306 /* XXX: The following code is the result of a cut&paste. This unfortunate
1307 practice is very widespread in the various target back-end files. */
1309 /* Set the howto pointer for a IP2K ELF reloc. */
1312 ip2k_info_to_howto_rela (abfd, cache_ptr, dst)
1313 bfd * abfd ATTRIBUTE_UNUSED;
1314 arelent * cache_ptr;
1315 Elf_Internal_Rela * dst;
1317 unsigned int r_type;
1319 r_type = ELF32_R_TYPE (dst->r_info);
1323 cache_ptr->howto = & ip2k_elf_howto_table [r_type];
1328 /* Perform a single relocation.
1329 By default we use the standard BFD routines. */
1331 static bfd_reloc_status_type
1332 ip2k_final_link_relocate (howto, input_bfd, input_section, contents, rel,
1334 reloc_howto_type * howto;
1336 asection * input_section;
1337 bfd_byte * contents;
1338 Elf_Internal_Rela * rel;
1341 static bfd_vma page_addr = 0;
1343 bfd_reloc_status_type r = bfd_reloc_ok;
1344 switch (howto->type)
1346 /* Handle data space relocations. */
1349 if ((relocation & IP2K_DATA_MASK) == IP2K_DATA_VALUE)
1350 relocation &= ~IP2K_DATA_MASK;
1352 r = bfd_reloc_notsupported;
1355 case R_IP2K_LO8DATA:
1356 case R_IP2K_HI8DATA:
1357 case R_IP2K_EX8DATA:
1360 /* Handle insn space relocations. */
1362 page_addr = BASEADDR (input_section) + rel->r_offset;
1363 if ((relocation & IP2K_INSN_MASK) == IP2K_INSN_VALUE)
1364 relocation &= ~IP2K_INSN_MASK;
1366 r = bfd_reloc_notsupported;
1369 case R_IP2K_ADDR16CJP:
1370 if (BASEADDR (input_section) + rel->r_offset != page_addr + 2)
1372 /* No preceding page instruction, verify that it isn't needed. */
1373 if (PAGENO (relocation + rel->r_addend) !=
1374 ip2k_nominal_page_bits (input_bfd, input_section,
1375 rel->r_offset, contents))
1376 _bfd_error_handler (_("ip2k linker: missing page instruction at 0x%08lx (dest = 0x%08lx)."),
1377 BASEADDR (input_section) + rel->r_offset,
1378 relocation + rel->r_addend);
1380 else if (ip2k_relaxed)
1382 /* Preceding page instruction. Verify that the page instruction is
1383 really needed. One reason for the relaxation to miss a page is if
1384 the section is not marked as executable. */
1385 if (!ip2k_is_switch_table_128 (input_bfd, input_section, rel->r_offset - 2, contents) &&
1386 !ip2k_is_switch_table_256 (input_bfd, input_section, rel->r_offset - 2, contents) &&
1387 (PAGENO (relocation + rel->r_addend) ==
1388 ip2k_nominal_page_bits (input_bfd, input_section,
1389 rel->r_offset - 2, contents)))
1390 _bfd_error_handler (_("ip2k linker: redundant page instruction at 0x%08lx (dest = 0x%08lx)."),
1392 relocation + rel->r_addend);
1394 if ((relocation & IP2K_INSN_MASK) == IP2K_INSN_VALUE)
1395 relocation &= ~IP2K_INSN_MASK;
1397 r = bfd_reloc_notsupported;
1400 case R_IP2K_LO8INSN:
1401 case R_IP2K_HI8INSN:
1402 case R_IP2K_PC_SKIP:
1403 if ((relocation & IP2K_INSN_MASK) == IP2K_INSN_VALUE)
1404 relocation &= ~IP2K_INSN_MASK;
1406 r = bfd_reloc_notsupported;
1410 /* If this is a relocation involving a TEXT
1411 symbol, reduce it to a word address. */
1412 if ((relocation & IP2K_INSN_MASK) == IP2K_INSN_VALUE)
1413 howto = &ip2k_elf_howto_table[ (int) R_IP2K_TEXT];
1416 /* Pass others through. */
1421 /* Only install relocation if above tests did not disqualify it. */
1422 if (r == bfd_reloc_ok)
1423 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1424 contents, rel->r_offset,
1425 relocation, rel->r_addend);
1430 /* Relocate a IP2K ELF section.
1432 The RELOCATE_SECTION function is called by the new ELF backend linker
1433 to handle the relocations for a section.
1435 The relocs are always passed as Rela structures; if the section
1436 actually uses Rel structures, the r_addend field will always be
1439 This function is responsible for adjusting the section contents as
1440 necessary, and (if using Rela relocs and generating a relocatable
1441 output file) adjusting the reloc addend as necessary.
1443 This function does not have to worry about setting the reloc
1444 address or the reloc symbol index.
1446 LOCAL_SYMS is a pointer to the swapped in local symbols.
1448 LOCAL_SECTIONS is an array giving the section in the input file
1449 corresponding to the st_shndx field of each local symbol.
1451 The global hash table entry for the global symbols can be found
1452 via elf_sym_hashes (input_bfd).
1454 When generating relocatable output, this function must handle
1455 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1456 going to be the section symbol corresponding to the output
1457 section, which means that the addend must be adjusted
1461 ip2k_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1462 contents, relocs, local_syms, local_sections)
1463 bfd *output_bfd ATTRIBUTE_UNUSED;
1464 struct bfd_link_info *info;
1466 asection *input_section;
1468 Elf_Internal_Rela *relocs;
1469 Elf_Internal_Sym *local_syms;
1470 asection **local_sections;
1472 Elf_Internal_Shdr *symtab_hdr;
1473 struct elf_link_hash_entry **sym_hashes;
1474 Elf_Internal_Rela *rel;
1475 Elf_Internal_Rela *relend;
1477 if (info->relocatable)
1480 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1481 sym_hashes = elf_sym_hashes (input_bfd);
1482 relend = relocs + input_section->reloc_count;
1484 for (rel = relocs; rel < relend; rel ++)
1486 reloc_howto_type * howto;
1487 unsigned long r_symndx;
1488 Elf_Internal_Sym * sym;
1490 struct elf_link_hash_entry * h;
1492 bfd_reloc_status_type r;
1493 const char * name = NULL;
1496 /* This is a final link. */
1497 r_type = ELF32_R_TYPE (rel->r_info);
1498 r_symndx = ELF32_R_SYM (rel->r_info);
1499 howto = ip2k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
1504 if (r_symndx < symtab_hdr->sh_info)
1506 sym = local_syms + r_symndx;
1507 sec = local_sections [r_symndx];
1508 relocation = BASEADDR (sec) + sym->st_value;
1510 name = bfd_elf_string_from_elf_section
1511 (input_bfd, symtab_hdr->sh_link, sym->st_name);
1512 name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
1517 bfd_boolean unresolved_reloc;
1519 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1520 r_symndx, symtab_hdr, sym_hashes,
1522 unresolved_reloc, warned);
1524 name = h->root.root.string;
1527 /* Finally, the sole IP2K-specific part. */
1528 r = ip2k_final_link_relocate (howto, input_bfd, input_section,
1529 contents, rel, relocation);
1531 if (r != bfd_reloc_ok)
1533 const char * msg = (const char *) NULL;
1537 case bfd_reloc_overflow:
1538 r = info->callbacks->reloc_overflow
1539 (info, (h ? &h->root : NULL), name, howto->name,
1540 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1543 case bfd_reloc_undefined:
1544 r = info->callbacks->undefined_symbol
1545 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
1548 case bfd_reloc_outofrange:
1549 msg = _("internal error: out of range error");
1552 /* This is how ip2k_final_link_relocate tells us of a non-kosher
1553 reference between insn & data address spaces. */
1554 case bfd_reloc_notsupported:
1555 if (sym != NULL) /* Only if it's not an unresolved symbol. */
1556 msg = _("unsupported relocation between data/insn address spaces");
1559 case bfd_reloc_dangerous:
1560 msg = _("internal error: dangerous relocation");
1564 msg = _("internal error: unknown error");
1569 r = info->callbacks->warning
1570 (info, msg, name, input_bfd, input_section, rel->r_offset);
1581 ip2k_elf_gc_mark_hook (sec, info, rel, h, sym)
1583 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1584 Elf_Internal_Rela *rel;
1585 struct elf_link_hash_entry *h;
1586 Elf_Internal_Sym *sym;
1590 switch (ELF32_R_TYPE (rel->r_info))
1593 switch (h->root.type)
1595 case bfd_link_hash_defined:
1596 case bfd_link_hash_defweak:
1597 return h->root.u.def.section;
1599 case bfd_link_hash_common:
1600 return h->root.u.c.p->section;
1609 if (!(elf_bad_symtab (sec->owner)
1610 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
1611 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
1612 && sym->st_shndx != SHN_COMMON))
1613 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
1619 ip2k_elf_gc_sweep_hook (abfd, info, sec, relocs)
1620 bfd *abfd ATTRIBUTE_UNUSED;
1621 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1622 asection *sec ATTRIBUTE_UNUSED;
1623 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
1625 /* We don't use got and plt entries for ip2k. */
1629 #define TARGET_BIG_SYM bfd_elf32_ip2k_vec
1630 #define TARGET_BIG_NAME "elf32-ip2k"
1632 #define ELF_ARCH bfd_arch_ip2k
1633 #define ELF_MACHINE_CODE EM_IP2K
1634 #define ELF_MACHINE_ALT1 EM_IP2K_OLD
1635 #define ELF_MAXPAGESIZE 1 /* No pages on the IP2K. */
1637 #define elf_info_to_howto_rel NULL
1638 #define elf_info_to_howto ip2k_info_to_howto_rela
1640 #define elf_backend_can_gc_sections 1
1641 #define elf_backend_rela_normal 1
1642 #define elf_backend_gc_mark_hook ip2k_elf_gc_mark_hook
1643 #define elf_backend_gc_sweep_hook ip2k_elf_gc_sweep_hook
1644 #define elf_backend_relocate_section ip2k_elf_relocate_section
1646 #define elf_symbol_leading_char '_'
1647 #define bfd_elf32_bfd_reloc_type_lookup ip2k_reloc_type_lookup
1648 #define bfd_elf32_bfd_relax_section ip2k_elf_relax_section
1650 #include "elf32-target.h"