/src/binutils-gdb/bfd/elf32-epiphany.c
Line | Count | Source |
1 | | /* Adapteva epiphany specific support for 32-bit ELF |
2 | | Copyright (C) 2000-2026 Free Software Foundation, Inc. |
3 | | Contributed by Embecosm on behalf of Adapteva, Inc. |
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 |
9 | | the Free Software Foundation; either version 3 of the License, or |
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 |
19 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | | MA 02110-1301, USA. */ |
21 | | |
22 | | #include "sysdep.h" |
23 | | #include "bfd.h" |
24 | | #include "libbfd.h" |
25 | | #include "elf-bfd.h" |
26 | | #include "elf/epiphany.h" |
27 | | #include "libiberty.h" |
28 | | |
29 | | /* Struct used to pass miscellaneous paramaters which |
30 | | helps to avoid overly long parameter lists. */ |
31 | | struct misc |
32 | | { |
33 | | Elf_Internal_Shdr * symtab_hdr; |
34 | | Elf_Internal_Rela * irelbase; |
35 | | bfd_byte * contents; |
36 | | Elf_Internal_Sym * isymbuf; |
37 | | }; |
38 | | |
39 | | struct epiphany_opcode |
40 | | { |
41 | | unsigned short opcode; |
42 | | unsigned short mask; |
43 | | }; |
44 | | |
45 | | /* Relocation tables. */ |
46 | | static reloc_howto_type epiphany_elf_howto_table [] = |
47 | | { |
48 | | #define AHOW(t,rs,s,bs,pr,bp,co,name,sm,dm) \ |
49 | | HOWTO(t, /* type */ \ |
50 | | rs, /* rightshift */ \ |
51 | | s, /* size */ \ |
52 | | bs, /* bitsize */ \ |
53 | | pr, /* pc_relative */ \ |
54 | | bp, /* bitpos */ \ |
55 | | co, /* complain_on_overflow */ \ |
56 | | bfd_elf_generic_reloc,/* special_function */ \ |
57 | | name, /* name */ \ |
58 | | false, /* partial_inplace */ \ |
59 | | sm, /* src_mask */ \ |
60 | | dm, /* dst_mask */ \ |
61 | | pr) /* pcrel_offset */ |
62 | | |
63 | | /* This reloc does nothing. */ |
64 | | AHOW (R_EPIPHANY_NONE, 0, 0,0, false, 0, complain_overflow_dont, "R_EPIPHANY_NONE", 0, 0), |
65 | | |
66 | | /* 8 bit absolute (not likely) */ |
67 | | AHOW (R_EPIPHANY_8, 0, 1, 8, false, 0, complain_overflow_bitfield, "R_EPIPHANY_8", 0x000000ff, 0x000000ff), |
68 | | /* 16 bit absolute */ |
69 | | AHOW (R_EPIPHANY_16, 0, 2,16, false, 0, complain_overflow_bitfield, "R_EPIPHANY_16", 0x0000ffff, 0x00ff1fe0), |
70 | | /* A 32 bit absolute relocation. */ |
71 | | AHOW (R_EPIPHANY_32, 0, 4,32, false, 0, complain_overflow_dont, "R_EPIPHANY_32", 0xffffffff, 0xffffffff), |
72 | | |
73 | | /* 8 bit relative relocation */ |
74 | | HOWTO ( R_EPIPHANY_8_PCREL, 0, 1, 8, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_EPIPHANY_8_PCREL", false, 0x000000ff, 0x000000ff, false), |
75 | | /* 16 bit relative relocation */ |
76 | | HOWTO ( R_EPIPHANY_16_PCREL, 0, 2, 16, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_EPIPHANY_8_PCREL", false, 0x000000ff, 0x000000ff, false), |
77 | | /* 32 bit relative relocation */ |
78 | | HOWTO ( R_EPIPHANY_32_PCREL, 0, 4, 32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_EPIPHANY_8_PCREL", false, 0x000000ff, 0x000000ff, false), |
79 | | |
80 | | /* 8 bit pc-relative relocation */ |
81 | | AHOW (R_EPIPHANY_SIMM8, 1, 1, 8, true, 8, complain_overflow_signed, "R_EPIPHANY_SIMM8", 0x000000ff, 0x0000ff00), |
82 | | /* 24 bit pc-relative relocation */ |
83 | | AHOW (R_EPIPHANY_SIMM24, 1, 4,24, true, 8, complain_overflow_signed, "R_EPIPHANY_SIMM24", 0x00ffffff, 0xffffff00), |
84 | | |
85 | | /* %HIGH(EA) */ |
86 | | AHOW (R_EPIPHANY_HIGH, 0, 4,16, false, 0, complain_overflow_dont, "R_EPIPHANY_HIGH", 0x0ff01fe0, 0x0ff01fe0), |
87 | | |
88 | | /* %LOW(EA) */ |
89 | | AHOW (R_EPIPHANY_LOW, 0, 4,16, false, 0, complain_overflow_dont, "R_EPIPHANY_LOW", 0x0ff01fe0, 0x0ff01fe0), |
90 | | |
91 | | /* simm11 */ |
92 | | AHOW (R_EPIPHANY_SIMM11, 0, 4,11, false, 0, complain_overflow_bitfield, "R_EPIPHANY_SIMM11", 0x00ff0380, 0x00ff0380), |
93 | | /* imm12 - sign-magnitude */ |
94 | | AHOW (R_EPIPHANY_IMM11, 0, 4,11, false, 0, complain_overflow_bitfield, "R_EPIPHANY_IMM12", 0x00ff0380, 0x00ff0380), |
95 | | /* imm8 */ |
96 | | AHOW (R_EPIPHANY_IMM8, 0, 2, 8, false, 8, complain_overflow_signed, "R_EPIPHANY_IMM8", 0x0000ff00, 0x0000ff00) |
97 | | |
98 | | |
99 | | }; |
100 | | #undef AHOW |
101 | | |
102 | | /* Map BFD reloc types to EPIPHANY ELF reloc types. */ |
103 | | |
104 | | static reloc_howto_type * |
105 | | epiphany_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
106 | | bfd_reloc_code_real_type code) |
107 | 0 | { |
108 | | /* Note that the epiphany_elf_howto_table is indxed by the R_ |
109 | | constants. Thus, the order that the howto records appear in the |
110 | | table *must* match the order of the relocation types defined in |
111 | | include/elf/epiphany.h. */ |
112 | |
|
113 | 0 | switch (code) |
114 | 0 | { |
115 | 0 | case BFD_RELOC_NONE: |
116 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_NONE]; |
117 | | |
118 | 0 | case BFD_RELOC_EPIPHANY_SIMM8: |
119 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_SIMM8]; |
120 | 0 | case BFD_RELOC_EPIPHANY_SIMM24: |
121 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_SIMM24]; |
122 | | |
123 | 0 | case BFD_RELOC_8_PCREL: |
124 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_8_PCREL]; |
125 | 0 | case BFD_RELOC_16_PCREL: |
126 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_16_PCREL]; |
127 | 0 | case BFD_RELOC_32_PCREL: |
128 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_32_PCREL]; |
129 | | |
130 | 0 | case BFD_RELOC_8: |
131 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_8]; |
132 | 0 | case BFD_RELOC_16: |
133 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_16]; |
134 | 0 | case BFD_RELOC_32: |
135 | 0 | return &epiphany_elf_howto_table[ (int) R_EPIPHANY_32]; |
136 | | |
137 | 0 | case BFD_RELOC_EPIPHANY_HIGH: |
138 | 0 | return & epiphany_elf_howto_table[ (int) R_EPIPHANY_HIGH]; |
139 | 0 | case BFD_RELOC_EPIPHANY_LOW: |
140 | 0 | return & epiphany_elf_howto_table[ (int) R_EPIPHANY_LOW]; |
141 | | |
142 | 0 | case BFD_RELOC_EPIPHANY_SIMM11: |
143 | 0 | return & epiphany_elf_howto_table[ (int) R_EPIPHANY_SIMM11]; |
144 | 0 | case BFD_RELOC_EPIPHANY_IMM11: |
145 | 0 | return & epiphany_elf_howto_table[ (int) R_EPIPHANY_IMM11]; |
146 | | |
147 | 0 | case BFD_RELOC_EPIPHANY_IMM8: |
148 | 0 | return & epiphany_elf_howto_table[ (int) R_EPIPHANY_IMM8]; |
149 | | |
150 | 0 | default: |
151 | | /* Pacify gcc -Wall. */ |
152 | 0 | return NULL; |
153 | 0 | } |
154 | 0 | return NULL; |
155 | 0 | } |
156 | | |
157 | | static reloc_howto_type * |
158 | | epiphany_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) |
159 | 0 | { |
160 | 0 | unsigned int i; |
161 | |
|
162 | 0 | for (i = 0; i < ARRAY_SIZE (epiphany_elf_howto_table); i++) |
163 | 0 | if (epiphany_elf_howto_table[i].name != NULL |
164 | 0 | && strcasecmp (epiphany_elf_howto_table[i].name, r_name) == 0) |
165 | 0 | return &epiphany_elf_howto_table[i]; |
166 | | |
167 | 0 | return NULL; |
168 | 0 | } |
169 | | |
170 | 0 | #define PAGENO(ABSADDR) ((ABSADDR) & 0xFFFFC000) |
171 | 0 | #define BASEADDR(SEC) ((SEC)->output_section->vma + (SEC)->output_offset) |
172 | | |
173 | | /* This function handles relaxing for the epiphany. |
174 | | Dummy placeholder for future optimizations. */ |
175 | | |
176 | | static bool |
177 | | epiphany_elf_relax_section (bfd *abfd, asection *sec, |
178 | | struct bfd_link_info *link_info, |
179 | | bool *again) |
180 | 0 | { |
181 | 0 | Elf_Internal_Shdr *symtab_hdr; |
182 | 0 | Elf_Internal_Rela *internal_relocs; |
183 | 0 | bfd_byte *contents = NULL; |
184 | 0 | Elf_Internal_Sym *isymbuf = NULL; |
185 | 0 | static asection * first_section = NULL; |
186 | 0 | static unsigned long search_addr; |
187 | 0 | static unsigned long page_start = 0; |
188 | 0 | static unsigned long page_end = 0; |
189 | 0 | static unsigned int pass = 0; |
190 | 0 | static bool new_pass = false; |
191 | 0 | static bool changed = false; |
192 | 0 | struct misc misc ATTRIBUTE_UNUSED; |
193 | 0 | asection *stab; |
194 | | |
195 | | /* Assume nothing changes. */ |
196 | 0 | *again = false; |
197 | |
|
198 | 0 | if (first_section == NULL) |
199 | 0 | first_section = sec; |
200 | |
|
201 | 0 | if (first_section == sec) |
202 | 0 | { |
203 | 0 | pass++; |
204 | 0 | new_pass = true; |
205 | 0 | } |
206 | | |
207 | | /* We don't have to do anything for a relocatable link, |
208 | | if this section does not have relocs, or if this is |
209 | | not a code section. */ |
210 | 0 | if (bfd_link_relocatable (link_info) |
211 | 0 | || sec->reloc_count == 0 |
212 | 0 | || (sec->flags & SEC_RELOC) == 0 |
213 | 0 | || (sec->flags & SEC_HAS_CONTENTS) == 0 |
214 | 0 | || (sec->flags & SEC_CODE) == 0) |
215 | 0 | return true; |
216 | | |
217 | 0 | symtab_hdr = &elf_symtab_hdr (abfd); |
218 | |
|
219 | 0 | internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, |
220 | 0 | link_info->keep_memory); |
221 | 0 | if (internal_relocs == NULL) |
222 | 0 | goto error_return; |
223 | | |
224 | | /* Make sure the stac.rela stuff gets read in. */ |
225 | 0 | stab = bfd_get_section_by_name (abfd, ".stab"); |
226 | |
|
227 | 0 | if (stab) |
228 | 0 | { |
229 | | /* So stab does exits. */ |
230 | 0 | Elf_Internal_Rela * irelbase ATTRIBUTE_UNUSED; |
231 | |
|
232 | 0 | irelbase = _bfd_elf_link_read_relocs (abfd, stab, NULL, NULL, |
233 | 0 | link_info->keep_memory); |
234 | 0 | } |
235 | | |
236 | | /* Get section contents cached copy if it exists. */ |
237 | 0 | if (contents == NULL) |
238 | 0 | { |
239 | | /* Get cached copy if it exists. */ |
240 | 0 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
241 | 0 | contents = elf_section_data (sec)->this_hdr.contents; |
242 | 0 | else |
243 | 0 | { |
244 | | /* Go get them off disk. */ |
245 | 0 | if (!bfd_malloc_and_get_section (abfd, sec, &contents)) |
246 | 0 | goto error_return; |
247 | 0 | } |
248 | 0 | } |
249 | | |
250 | | /* Read this BFD's symbols cached copy if it exists. */ |
251 | 0 | if (isymbuf == NULL && symtab_hdr->sh_info != 0) |
252 | 0 | { |
253 | 0 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
254 | 0 | if (isymbuf == NULL) |
255 | 0 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, |
256 | 0 | symtab_hdr->sh_info, 0, |
257 | 0 | NULL, NULL, NULL); |
258 | 0 | if (isymbuf == NULL) |
259 | 0 | goto error_return; |
260 | 0 | } |
261 | | |
262 | 0 | misc.symtab_hdr = symtab_hdr; |
263 | 0 | misc.isymbuf = isymbuf; |
264 | 0 | misc.irelbase = internal_relocs; |
265 | 0 | misc.contents = contents; |
266 | | |
267 | | /* This is where all the relaxation actually get done. */ |
268 | 0 | if ((pass == 1) || (new_pass && !changed)) |
269 | 0 | { |
270 | | /* On the first pass we simply search for the lowest page that |
271 | | we havn't relaxed yet. Note that the pass count is reset |
272 | | each time a page is complete in order to move on to the next page. |
273 | | If we can't find any more pages then we are finished. */ |
274 | 0 | if (new_pass) |
275 | 0 | { |
276 | 0 | pass = 1; |
277 | 0 | new_pass = false; |
278 | 0 | changed = true; /* Pre-initialize to break out of pass 1. */ |
279 | 0 | search_addr = 0xFFFFFFFF; |
280 | 0 | } |
281 | |
|
282 | 0 | if ((BASEADDR (sec) + sec->size < search_addr) |
283 | 0 | && (BASEADDR (sec) + sec->size > page_end)) |
284 | 0 | { |
285 | 0 | if (BASEADDR (sec) <= page_end) |
286 | 0 | search_addr = page_end + 1; |
287 | 0 | else |
288 | 0 | search_addr = BASEADDR (sec); |
289 | | |
290 | | /* Found a page => more work to do. */ |
291 | 0 | *again = true; |
292 | 0 | } |
293 | 0 | } |
294 | 0 | else |
295 | 0 | { |
296 | 0 | if (new_pass) |
297 | 0 | { |
298 | 0 | new_pass = false; |
299 | 0 | changed = false; |
300 | 0 | page_start = PAGENO (search_addr); |
301 | 0 | page_end = page_start | 0x00003FFF; |
302 | 0 | } |
303 | | |
304 | | /* Only process sections in range. */ |
305 | 0 | if ((BASEADDR (sec) + sec->size >= page_start) |
306 | 0 | && (BASEADDR (sec) <= page_end)) |
307 | 0 | { |
308 | | #if 0 |
309 | | if (!epiphany_elf_relax_section_page (abfd, sec, &changed, &misc, |
310 | | page_start, page_end)) |
311 | | #endif |
312 | 0 | return false; |
313 | 0 | } |
314 | 0 | *again = true; |
315 | 0 | } |
316 | | |
317 | | /* Perform some house keeping after relaxing the section. */ |
318 | | |
319 | 0 | if (isymbuf != NULL |
320 | 0 | && symtab_hdr->contents != (unsigned char *) isymbuf) |
321 | 0 | { |
322 | 0 | if (! link_info->keep_memory) |
323 | 0 | free (isymbuf); |
324 | 0 | else |
325 | 0 | symtab_hdr->contents = (unsigned char *) isymbuf; |
326 | 0 | } |
327 | |
|
328 | 0 | if (contents != NULL |
329 | 0 | && elf_section_data (sec)->this_hdr.contents != contents) |
330 | 0 | { |
331 | 0 | if (! link_info->keep_memory) |
332 | 0 | free (contents); |
333 | 0 | else |
334 | 0 | { |
335 | | /* Cache the section contents for elf_link_input_bfd. */ |
336 | 0 | elf_section_data (sec)->this_hdr.contents = contents; |
337 | 0 | } |
338 | 0 | } |
339 | |
|
340 | 0 | if (elf_section_data (sec)->relocs != internal_relocs) |
341 | 0 | free (internal_relocs); |
342 | |
|
343 | 0 | return true; |
344 | | |
345 | 0 | error_return: |
346 | 0 | if (symtab_hdr->contents != (unsigned char *) isymbuf) |
347 | 0 | free (isymbuf); |
348 | 0 | if (elf_section_data (sec)->this_hdr.contents != contents) |
349 | 0 | free (contents); |
350 | 0 | if (elf_section_data (sec)->relocs != internal_relocs) |
351 | 0 | free (internal_relocs); |
352 | 0 | return false; |
353 | 0 | } |
354 | | |
355 | | /* Set the howto pointer for a EPIPHANY ELF reloc. */ |
356 | | |
357 | | static bool |
358 | | epiphany_info_to_howto_rela (bfd * abfd, |
359 | | arelent * cache_ptr, |
360 | | Elf_Internal_Rela * dst) |
361 | 109 | { |
362 | 109 | unsigned int r_type; |
363 | | |
364 | 109 | r_type = ELF32_R_TYPE (dst->r_info); |
365 | 109 | if (r_type >= (unsigned int) R_EPIPHANY_max) |
366 | 16 | { |
367 | | /* xgettext:c-format */ |
368 | 16 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
369 | 16 | abfd, r_type); |
370 | 16 | bfd_set_error (bfd_error_bad_value); |
371 | 16 | return false; |
372 | 16 | } |
373 | 93 | cache_ptr->howto = & epiphany_elf_howto_table [r_type]; |
374 | 93 | return true; |
375 | 109 | } |
376 | | |
377 | | /* Perform a single relocation. |
378 | | By default we use the standard BFD routines. */ |
379 | | |
380 | | static bfd_reloc_status_type |
381 | | epiphany_final_link_relocate (reloc_howto_type * howto, |
382 | | bfd * input_bfd, |
383 | | asection * input_section, |
384 | | bfd_byte * contents, |
385 | | Elf_Internal_Rela * rel, |
386 | | bfd_vma relocation) |
387 | 0 | { |
388 | 0 | switch (howto->type) |
389 | 0 | { |
390 | | /* Handle 16 bit immediates. */ |
391 | 0 | case R_EPIPHANY_HIGH: |
392 | 0 | relocation += rel->r_addend; |
393 | 0 | relocation >>= 16; |
394 | 0 | goto common; |
395 | | |
396 | 0 | case R_EPIPHANY_LOW: |
397 | 0 | relocation += rel->r_addend; |
398 | 0 | common: |
399 | 0 | relocation = ((relocation & 0xff00L) << 12) |
400 | 0 | | ((relocation & 0x00ffL) << 5); |
401 | | /* Sanity check the address. */ |
402 | 0 | if (rel->r_offset > bfd_get_section_limit (input_bfd, input_section)) |
403 | 0 | return bfd_reloc_outofrange; |
404 | | |
405 | 0 | return _bfd_relocate_contents (howto, input_bfd, relocation, |
406 | 0 | contents + rel->r_offset); |
407 | | |
408 | 0 | case R_EPIPHANY_SIMM11: |
409 | 0 | relocation += rel->r_addend; |
410 | | /* Check signed overflow. */ |
411 | 0 | if ((int)relocation > 1023 || (int)relocation < -1024) |
412 | 0 | return bfd_reloc_outofrange; |
413 | 0 | goto disp11; |
414 | | |
415 | 0 | case R_EPIPHANY_IMM11: |
416 | 0 | relocation += rel->r_addend; |
417 | 0 | if ((unsigned int) relocation > 0x7ff) |
418 | 0 | return bfd_reloc_outofrange; |
419 | | /* Fall through. */ |
420 | 0 | disp11: |
421 | 0 | relocation = (((relocation & 7) << 5) |
422 | 0 | | ((relocation & 0x7f8 ) << 13)); |
423 | 0 | return _bfd_relocate_contents (howto, input_bfd, relocation, |
424 | 0 | contents + rel->r_offset); |
425 | | |
426 | | /* Pass others through. */ |
427 | 0 | default: |
428 | 0 | break; |
429 | 0 | } |
430 | | |
431 | | /* Only install relocation if above tests did not disqualify it. */ |
432 | 0 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
433 | 0 | contents, rel->r_offset, |
434 | 0 | relocation, rel->r_addend); |
435 | 0 | } |
436 | | |
437 | | /* Relocate an EPIPHANY ELF section. |
438 | | |
439 | | The RELOCATE_SECTION function is called by the new ELF backend linker |
440 | | to handle the relocations for a section. |
441 | | |
442 | | The relocs are always passed as Rela structures; if the section |
443 | | actually uses Rel structures, the r_addend field will always be |
444 | | zero. |
445 | | |
446 | | This function is responsible for adjusting the section contents as |
447 | | necessary, and (if using Rela relocs and generating a relocatable |
448 | | output file) adjusting the reloc addend as necessary. |
449 | | |
450 | | This function does not have to worry about setting the reloc |
451 | | address or the reloc symbol index. |
452 | | |
453 | | LOCAL_SYMS is a pointer to the swapped in local symbols. |
454 | | |
455 | | LOCAL_SECTIONS is an array giving the section in the input file |
456 | | corresponding to the st_shndx field of each local symbol. |
457 | | |
458 | | The global hash table entry for the global symbols can be found |
459 | | via elf_sym_hashes (input_bfd). |
460 | | |
461 | | When generating relocatable output, this function must handle |
462 | | STB_LOCAL/STT_SECTION symbols specially. The output symbol is |
463 | | going to be the section symbol corresponding to the output |
464 | | section, which means that the addend must be adjusted |
465 | | accordingly. */ |
466 | | |
467 | | static int |
468 | | epiphany_elf_relocate_section (struct bfd_link_info *info, |
469 | | bfd *input_bfd, |
470 | | asection *input_section, |
471 | | bfd_byte *contents, |
472 | | Elf_Internal_Rela *relocs, |
473 | | Elf_Internal_Sym *local_syms, |
474 | | asection **local_sections) |
475 | 0 | { |
476 | 0 | Elf_Internal_Shdr *symtab_hdr; |
477 | 0 | struct elf_link_hash_entry **sym_hashes; |
478 | 0 | Elf_Internal_Rela *rel; |
479 | 0 | Elf_Internal_Rela *relend; |
480 | |
|
481 | 0 | symtab_hdr = &elf_symtab_hdr (input_bfd); |
482 | 0 | sym_hashes = elf_sym_hashes (input_bfd); |
483 | 0 | relend = relocs + input_section->reloc_count; |
484 | |
|
485 | 0 | for (rel = relocs; rel < relend; rel ++) |
486 | 0 | { |
487 | 0 | reloc_howto_type * howto; |
488 | 0 | unsigned long r_symndx; |
489 | 0 | const Elf_Internal_Sym * sym; |
490 | 0 | asection * sec; |
491 | 0 | struct elf_link_hash_entry * h; |
492 | 0 | bfd_vma relocation; |
493 | 0 | bfd_reloc_status_type r; |
494 | 0 | const char * name = NULL; |
495 | 0 | int r_type ATTRIBUTE_UNUSED; |
496 | |
|
497 | 0 | r_type = ELF32_R_TYPE (rel->r_info); |
498 | 0 | r_symndx = ELF32_R_SYM (rel->r_info); |
499 | 0 | howto = epiphany_elf_howto_table + ELF32_R_TYPE (rel->r_info); |
500 | 0 | h = NULL; |
501 | 0 | sym = NULL; |
502 | 0 | sec = NULL; |
503 | |
|
504 | 0 | if (r_symndx < symtab_hdr->sh_info) |
505 | 0 | { |
506 | 0 | sym = local_syms + r_symndx; |
507 | 0 | sec = local_sections [r_symndx]; |
508 | 0 | relocation = BASEADDR (sec) + sym->st_value; |
509 | |
|
510 | 0 | name = bfd_elf_string_from_elf_section |
511 | 0 | (input_bfd, symtab_hdr->sh_link, sym->st_name); |
512 | 0 | name = name == NULL ? bfd_section_name (sec) : name; |
513 | 0 | } |
514 | 0 | else |
515 | 0 | { |
516 | 0 | bool warned ATTRIBUTE_UNUSED; |
517 | 0 | bool unresolved_reloc ATTRIBUTE_UNUSED; |
518 | 0 | bool ignored ATTRIBUTE_UNUSED; |
519 | |
|
520 | 0 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
521 | 0 | r_symndx, symtab_hdr, sym_hashes, |
522 | 0 | h, sec, relocation, |
523 | 0 | unresolved_reloc, warned, ignored); |
524 | |
|
525 | 0 | name = h->root.root.string; |
526 | 0 | } |
527 | |
|
528 | 0 | if (sec != NULL && discarded_section (sec)) |
529 | 0 | RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
530 | 0 | rel, 1, relend, R_EPIPHANY_NONE, |
531 | 0 | howto, 0, contents); |
532 | |
|
533 | 0 | if (bfd_link_relocatable (info)) |
534 | 0 | continue; |
535 | | |
536 | | /* Finally, the sole EPIPHANY-specific part. */ |
537 | 0 | r = epiphany_final_link_relocate (howto, input_bfd, input_section, |
538 | 0 | contents, rel, relocation); |
539 | |
|
540 | 0 | if (r != bfd_reloc_ok) |
541 | 0 | { |
542 | 0 | const char * msg = NULL; |
543 | |
|
544 | 0 | switch (r) |
545 | 0 | { |
546 | 0 | case bfd_reloc_overflow: |
547 | 0 | (*info->callbacks->reloc_overflow) |
548 | 0 | (info, (h ? &h->root : NULL), name, howto->name, |
549 | 0 | (bfd_vma) 0, input_bfd, input_section, rel->r_offset); |
550 | 0 | break; |
551 | | |
552 | 0 | case bfd_reloc_undefined: |
553 | 0 | (*info->callbacks->undefined_symbol) |
554 | 0 | (info, name, input_bfd, input_section, rel->r_offset, true); |
555 | 0 | break; |
556 | | |
557 | 0 | case bfd_reloc_outofrange: |
558 | 0 | msg = _("internal error: out of range error"); |
559 | 0 | break; |
560 | | |
561 | | /* This is how epiphany_final_link_relocate tells us of a |
562 | | non-kosher reference between insn & data address spaces. */ |
563 | 0 | case bfd_reloc_notsupported: |
564 | 0 | if (sym != NULL) /* Only if it's not an unresolved symbol. */ |
565 | 0 | msg = _("unsupported relocation between data/insn address spaces"); |
566 | 0 | break; |
567 | | |
568 | 0 | case bfd_reloc_dangerous: |
569 | 0 | msg = _("internal error: dangerous relocation"); |
570 | 0 | break; |
571 | | |
572 | 0 | default: |
573 | 0 | msg = _("internal error: unknown error"); |
574 | 0 | break; |
575 | 0 | } |
576 | | |
577 | 0 | if (msg) |
578 | 0 | (*info->callbacks->warning) (info, msg, name, input_bfd, |
579 | 0 | input_section, rel->r_offset); |
580 | 0 | } |
581 | 0 | } |
582 | | |
583 | 0 | return true; |
584 | 0 | } |
585 | | |
586 | | /* We only have a little-endian target. */ |
587 | | #define TARGET_LITTLE_SYM epiphany_elf32_vec |
588 | | #define TARGET_LITTLE_NAME "elf32-epiphany" |
589 | | |
590 | | #define ELF_ARCH bfd_arch_epiphany |
591 | | #define ELF_MACHINE_CODE EM_ADAPTEVA_EPIPHANY |
592 | | |
593 | | #define ELF_MAXPAGESIZE 0x8000 /* No pages on the EPIPHANY. */ |
594 | | |
595 | | #define elf_info_to_howto_rel NULL |
596 | | #define elf_info_to_howto epiphany_info_to_howto_rela |
597 | | |
598 | | #define elf_backend_can_gc_sections 1 |
599 | | #define elf_backend_rela_normal 1 |
600 | | #define elf_backend_relocate_section epiphany_elf_relocate_section |
601 | | |
602 | | #define elf_symbol_leading_char '_' |
603 | | #define bfd_elf32_bfd_reloc_type_lookup epiphany_reloc_type_lookup |
604 | | #define bfd_elf32_bfd_reloc_name_lookup epiphany_reloc_name_lookup |
605 | | #define bfd_elf32_bfd_relax_section epiphany_elf_relax_section |
606 | | |
607 | | #include "elf32-target.h" |