bfd_section_* macros
[binutils-gdb.git] / bfd / elf32-bfin.c
1 /* ADI Blackfin BFD support for 32-bit ELF.
2 Copyright (C) 2005-2019 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
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 3 of the License, or
9 (at your option) any later version.
10
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.
15
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., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "libbfd.h"
24 #include "elf-bfd.h"
25 #include "elf/bfin.h"
26 #include "dwarf2.h"
27 #include "hashtab.h"
28
29 /* FUNCTION : bfin_pltpc_reloc
30 ABSTRACT : TODO : figure out how to handle pltpc relocs. */
31 static bfd_reloc_status_type
32 bfin_pltpc_reloc (
33 bfd *abfd ATTRIBUTE_UNUSED,
34 arelent *reloc_entry ATTRIBUTE_UNUSED,
35 asymbol *symbol ATTRIBUTE_UNUSED,
36 void * data ATTRIBUTE_UNUSED,
37 asection *input_section ATTRIBUTE_UNUSED,
38 bfd *output_bfd ATTRIBUTE_UNUSED,
39 char **error_message ATTRIBUTE_UNUSED)
40 {
41 bfd_reloc_status_type flag = bfd_reloc_ok;
42 return flag;
43 }
44 \f
45
46 static bfd_reloc_status_type
47 bfin_pcrel24_reloc (bfd *abfd,
48 arelent *reloc_entry,
49 asymbol *symbol,
50 void * data,
51 asection *input_section,
52 bfd *output_bfd,
53 char **error_message ATTRIBUTE_UNUSED)
54 {
55 bfd_vma relocation;
56 bfd_size_type addr = reloc_entry->address;
57 bfd_vma output_base = 0;
58 reloc_howto_type *howto = reloc_entry->howto;
59 asection *output_section;
60 bfd_boolean relocatable = (output_bfd != NULL);
61
62 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
63 return bfd_reloc_outofrange;
64
65 if (bfd_is_und_section (symbol->section)
66 && (symbol->flags & BSF_WEAK) == 0
67 && !relocatable)
68 return bfd_reloc_undefined;
69
70 if (bfd_is_com_section (symbol->section))
71 relocation = 0;
72 else
73 relocation = symbol->value;
74
75 output_section = symbol->section->output_section;
76
77 if (relocatable)
78 output_base = 0;
79 else
80 output_base = output_section->vma;
81
82 if (!relocatable || !strcmp (symbol->name, symbol->section->name))
83 relocation += output_base + symbol->section->output_offset;
84
85 if (!relocatable && !strcmp (symbol->name, symbol->section->name))
86 relocation += reloc_entry->addend;
87
88 relocation -= input_section->output_section->vma + input_section->output_offset;
89 relocation -= reloc_entry->address;
90
91 if (howto->complain_on_overflow != complain_overflow_dont)
92 {
93 bfd_reloc_status_type status;
94 status = bfd_check_overflow (howto->complain_on_overflow,
95 howto->bitsize,
96 howto->rightshift,
97 bfd_arch_bits_per_address(abfd),
98 relocation);
99 if (status != bfd_reloc_ok)
100 return status;
101 }
102
103 /* if rightshift is 1 and the number odd, return error. */
104 if (howto->rightshift && (relocation & 0x01))
105 {
106 _bfd_error_handler (_("relocation should be even number"));
107 return bfd_reloc_overflow;
108 }
109
110 relocation >>= (bfd_vma) howto->rightshift;
111 /* Shift everything up to where it's going to be used. */
112
113 relocation <<= (bfd_vma) howto->bitpos;
114
115 if (relocatable)
116 {
117 reloc_entry->address += input_section->output_offset;
118 reloc_entry->addend += symbol->section->output_offset;
119 }
120
121 {
122 short x;
123
124 /* We are getting reloc_entry->address 2 byte off from
125 the start of instruction. Assuming absolute postion
126 of the reloc data. But, following code had been written assuming
127 reloc address is starting at begining of instruction.
128 To compensate that I have increased the value of
129 relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
130
131 relocation += 1;
132 x = bfd_get_16 (abfd, (bfd_byte *) data + addr - 2);
133 x = (x & 0xff00) | ((relocation >> 16) & 0xff);
134 bfd_put_16 (abfd, x, (unsigned char *) data + addr - 2);
135
136 x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
137 x = relocation & 0xFFFF;
138 bfd_put_16 (abfd, x, (unsigned char *) data + addr );
139 }
140 return bfd_reloc_ok;
141 }
142
143 static bfd_reloc_status_type
144 bfin_imm16_reloc (bfd *abfd,
145 arelent *reloc_entry,
146 asymbol *symbol,
147 void * data,
148 asection *input_section,
149 bfd *output_bfd,
150 char **error_message ATTRIBUTE_UNUSED)
151 {
152 bfd_vma relocation, x;
153 bfd_size_type reloc_addr = reloc_entry->address;
154 bfd_vma output_base = 0;
155 reloc_howto_type *howto = reloc_entry->howto;
156 asection *output_section;
157 bfd_boolean relocatable = (output_bfd != NULL);
158
159 /* Is the address of the relocation really within the section? */
160 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
161 return bfd_reloc_outofrange;
162
163 if (bfd_is_und_section (symbol->section)
164 && (symbol->flags & BSF_WEAK) == 0
165 && !relocatable)
166 return bfd_reloc_undefined;
167
168 output_section = symbol->section->output_section;
169 relocation = symbol->value;
170
171 /* Convert input-section-relative symbol value to absolute. */
172 if (relocatable)
173 output_base = 0;
174 else
175 output_base = output_section->vma;
176
177 if (!relocatable || !strcmp (symbol->name, symbol->section->name))
178 relocation += output_base + symbol->section->output_offset;
179
180 /* Add in supplied addend. */
181 relocation += reloc_entry->addend;
182
183 if (relocatable)
184 {
185 reloc_entry->address += input_section->output_offset;
186 reloc_entry->addend += symbol->section->output_offset;
187 }
188 else
189 {
190 reloc_entry->addend = 0;
191 }
192
193 if (howto->complain_on_overflow != complain_overflow_dont)
194 {
195 bfd_reloc_status_type flag;
196 flag = bfd_check_overflow (howto->complain_on_overflow,
197 howto->bitsize,
198 howto->rightshift,
199 bfd_arch_bits_per_address(abfd),
200 relocation);
201 if (flag != bfd_reloc_ok)
202 return flag;
203 }
204
205 /* Here the variable relocation holds the final address of the
206 symbol we are relocating against, plus any addend. */
207
208 relocation >>= (bfd_vma) howto->rightshift;
209 x = relocation;
210 bfd_put_16 (abfd, x, (unsigned char *) data + reloc_addr);
211 return bfd_reloc_ok;
212 }
213
214
215 static bfd_reloc_status_type
216 bfin_byte4_reloc (bfd *abfd,
217 arelent *reloc_entry,
218 asymbol *symbol,
219 void * data,
220 asection *input_section,
221 bfd *output_bfd,
222 char **error_message ATTRIBUTE_UNUSED)
223 {
224 bfd_vma relocation, x;
225 bfd_size_type addr = reloc_entry->address;
226 bfd_vma output_base = 0;
227 asection *output_section;
228 bfd_boolean relocatable = (output_bfd != NULL);
229
230 /* Is the address of the relocation really within the section? */
231 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
232 return bfd_reloc_outofrange;
233
234 if (bfd_is_und_section (symbol->section)
235 && (symbol->flags & BSF_WEAK) == 0
236 && !relocatable)
237 return bfd_reloc_undefined;
238
239 output_section = symbol->section->output_section;
240 relocation = symbol->value;
241 /* Convert input-section-relative symbol value to absolute. */
242 if (relocatable)
243 output_base = 0;
244 else
245 output_base = output_section->vma;
246
247 if ((symbol->name
248 && symbol->section->name
249 && !strcmp (symbol->name, symbol->section->name))
250 || !relocatable)
251 {
252 relocation += output_base + symbol->section->output_offset;
253 }
254
255 relocation += reloc_entry->addend;
256
257 if (relocatable)
258 {
259 /* This output will be relocatable ... like ld -r. */
260 reloc_entry->address += input_section->output_offset;
261 reloc_entry->addend += symbol->section->output_offset;
262 }
263 else
264 {
265 reloc_entry->addend = 0;
266 }
267
268 /* Here the variable relocation holds the final address of the
269 symbol we are relocating against, plus any addend. */
270 x = relocation & 0xFFFF0000;
271 x >>=16;
272 bfd_put_16 (abfd, x, (unsigned char *) data + addr + 2);
273
274 x = relocation & 0x0000FFFF;
275 bfd_put_16 (abfd, x, (unsigned char *) data + addr);
276 return bfd_reloc_ok;
277 }
278
279 /* bfin_bfd_reloc handles the blackfin arithmetic relocations.
280 Use this instead of bfd_perform_relocation. */
281 static bfd_reloc_status_type
282 bfin_bfd_reloc (bfd *abfd,
283 arelent *reloc_entry,
284 asymbol *symbol,
285 void * data,
286 asection *input_section,
287 bfd *output_bfd,
288 char **error_message ATTRIBUTE_UNUSED)
289 {
290 bfd_vma relocation;
291 bfd_size_type addr = reloc_entry->address;
292 bfd_vma output_base = 0;
293 reloc_howto_type *howto = reloc_entry->howto;
294 asection *output_section;
295 bfd_boolean relocatable = (output_bfd != NULL);
296
297 /* Is the address of the relocation really within the section? */
298 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
299 return bfd_reloc_outofrange;
300
301 if (bfd_is_und_section (symbol->section)
302 && (symbol->flags & BSF_WEAK) == 0
303 && !relocatable)
304 return bfd_reloc_undefined;
305
306 /* Get symbol value. (Common symbols are special.) */
307 if (bfd_is_com_section (symbol->section))
308 relocation = 0;
309 else
310 relocation = symbol->value;
311
312 output_section = symbol->section->output_section;
313
314 /* Convert input-section-relative symbol value to absolute. */
315 if (relocatable)
316 output_base = 0;
317 else
318 output_base = output_section->vma;
319
320 if (!relocatable || !strcmp (symbol->name, symbol->section->name))
321 relocation += output_base + symbol->section->output_offset;
322
323 if (!relocatable && !strcmp (symbol->name, symbol->section->name))
324 {
325 /* Add in supplied addend. */
326 relocation += reloc_entry->addend;
327 }
328
329 /* Here the variable relocation holds the final address of the
330 symbol we are relocating against, plus any addend. */
331
332 if (howto->pc_relative)
333 {
334 relocation -= input_section->output_section->vma + input_section->output_offset;
335
336 if (howto->pcrel_offset)
337 relocation -= reloc_entry->address;
338 }
339
340 if (relocatable)
341 {
342 reloc_entry->address += input_section->output_offset;
343 reloc_entry->addend += symbol->section->output_offset;
344 }
345
346 if (howto->complain_on_overflow != complain_overflow_dont)
347 {
348 bfd_reloc_status_type status;
349
350 status = bfd_check_overflow (howto->complain_on_overflow,
351 howto->bitsize,
352 howto->rightshift,
353 bfd_arch_bits_per_address(abfd),
354 relocation);
355 if (status != bfd_reloc_ok)
356 return status;
357 }
358
359 /* If rightshift is 1 and the number odd, return error. */
360 if (howto->rightshift && (relocation & 0x01))
361 {
362 _bfd_error_handler (_("relocation should be even number"));
363 return bfd_reloc_overflow;
364 }
365
366 relocation >>= (bfd_vma) howto->rightshift;
367
368 /* Shift everything up to where it's going to be used. */
369
370 relocation <<= (bfd_vma) howto->bitpos;
371
372 #define DOIT(x) \
373 x = ( (x & ~howto->dst_mask) | (relocation & howto->dst_mask))
374
375 /* handle 8 and 16 bit relocations here. */
376 switch (howto->size)
377 {
378 case 0:
379 {
380 char x = bfd_get_8 (abfd, (char *) data + addr);
381 DOIT (x);
382 bfd_put_8 (abfd, x, (unsigned char *) data + addr);
383 }
384 break;
385
386 case 1:
387 {
388 unsigned short x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
389 DOIT (x);
390 bfd_put_16 (abfd, (bfd_vma) x, (unsigned char *) data + addr);
391 }
392 break;
393
394 default:
395 return bfd_reloc_other;
396 }
397
398 return bfd_reloc_ok;
399 }
400
401 /* HOWTO Table for blackfin.
402 Blackfin relocations are fairly complicated.
403 Some of the salient features are
404 a. Even numbered offsets. A number of (not all) relocations are
405 even numbered. This means that the rightmost bit is not stored.
406 Needs to right shift by 1 and check to see if value is not odd
407 b. A relocation can be an expression. An expression takes on
408 a variety of relocations arranged in a stack.
409 As a result, we cannot use the standard generic function as special
410 function. We will have our own, which is very similar to the standard
411 generic function except that it understands how to get the value from
412 the relocation stack. . */
413
414 #define BFIN_RELOC_MIN 0
415 #define BFIN_RELOC_MAX 0x21
416 #define BFIN_GNUEXT_RELOC_MIN 0x40
417 #define BFIN_GNUEXT_RELOC_MAX 0x43
418 #define BFIN_ARELOC_MIN 0xE0
419 #define BFIN_ARELOC_MAX 0xF3
420
421 static reloc_howto_type bfin_howto_table [] =
422 {
423 /* This reloc does nothing. . */
424 HOWTO (R_BFIN_UNUSED0, /* type. */
425 0, /* rightshift. */
426 3, /* size (0 = byte, 1 = short, 2 = long). */
427 0, /* bitsize. */
428 FALSE, /* pc_relative. */
429 0, /* bitpos. */
430 complain_overflow_dont, /* complain_on_overflow. */
431 bfd_elf_generic_reloc, /* special_function. */
432 "R_BFIN_UNUSED0", /* name. */
433 FALSE, /* partial_inplace. */
434 0, /* src_mask. */
435 0, /* dst_mask. */
436 FALSE), /* pcrel_offset. */
437
438 HOWTO (R_BFIN_PCREL5M2, /* type. */
439 1, /* rightshift. */
440 1, /* size (0 = byte, 1 = short, 2 = long).. */
441 4, /* bitsize. */
442 TRUE, /* pc_relative. */
443 0, /* bitpos. */
444 complain_overflow_unsigned, /* complain_on_overflow. */
445 bfin_bfd_reloc, /* special_function. */
446 "R_BFIN_PCREL5M2", /* name. */
447 FALSE, /* partial_inplace. */
448 0, /* src_mask. */
449 0x0000000F, /* dst_mask. */
450 FALSE), /* pcrel_offset. */
451
452 HOWTO (R_BFIN_UNUSED1, /* type. */
453 0, /* rightshift. */
454 3, /* size (0 = byte, 1 = short, 2 = long). */
455 0, /* bitsize. */
456 FALSE, /* pc_relative. */
457 0, /* bitpos. */
458 complain_overflow_dont, /* complain_on_overflow. */
459 bfd_elf_generic_reloc, /* special_function. */
460 "R_BFIN_UNUSED1", /* name. */
461 FALSE, /* partial_inplace. */
462 0, /* src_mask. */
463 0, /* dst_mask. */
464 FALSE), /* pcrel_offset. */
465
466 HOWTO (R_BFIN_PCREL10, /* type. */
467 1, /* rightshift. */
468 1, /* size (0 = byte, 1 = short, 2 = long). */
469 10, /* bitsize. */
470 TRUE, /* pc_relative. */
471 0, /* bitpos. */
472 complain_overflow_signed, /* complain_on_overflow. */
473 bfin_bfd_reloc, /* special_function. */
474 "R_BFIN_PCREL10", /* name. */
475 FALSE, /* partial_inplace. */
476 0, /* src_mask. */
477 0x000003FF, /* dst_mask. */
478 TRUE), /* pcrel_offset. */
479
480 HOWTO (R_BFIN_PCREL12_JUMP, /* type. */
481 1, /* rightshift. */
482 /* the offset is actually 13 bit
483 aligned on a word boundary so
484 only 12 bits have to be used.
485 Right shift the rightmost bit.. */
486 1, /* size (0 = byte, 1 = short, 2 = long). */
487 12, /* bitsize. */
488 TRUE, /* pc_relative. */
489 0, /* bitpos. */
490 complain_overflow_signed, /* complain_on_overflow. */
491 bfin_bfd_reloc, /* special_function. */
492 "R_BFIN_PCREL12_JUMP", /* name. */
493 FALSE, /* partial_inplace. */
494 0, /* src_mask. */
495 0x0FFF, /* dst_mask. */
496 TRUE), /* pcrel_offset. */
497
498 HOWTO (R_BFIN_RIMM16, /* type. */
499 0, /* rightshift. */
500 1, /* size (0 = byte, 1 = short, 2 = long). */
501 16, /* bitsize. */
502 FALSE, /* pc_relative. */
503 0, /* bitpos. */
504 complain_overflow_signed, /* complain_on_overflow. */
505 bfin_imm16_reloc, /* special_function. */
506 "R_BFIN_RIMM16", /* name. */
507 FALSE, /* partial_inplace. */
508 0, /* src_mask. */
509 0x0000FFFF, /* dst_mask. */
510 TRUE), /* pcrel_offset. */
511
512 HOWTO (R_BFIN_LUIMM16, /* type. */
513 0, /* rightshift. */
514 1, /* size (0 = byte, 1 = short, 2 = long). */
515 16, /* bitsize. */
516 FALSE, /* pc_relative. */
517 0, /* bitpos. */
518 complain_overflow_dont, /* complain_on_overflow. */
519 bfin_imm16_reloc, /* special_function. */
520 "R_BFIN_LUIMM16", /* name. */
521 FALSE, /* partial_inplace. */
522 0, /* src_mask. */
523 0x0000FFFF, /* dst_mask. */
524 TRUE), /* pcrel_offset. */
525
526 HOWTO (R_BFIN_HUIMM16, /* type. */
527 16, /* rightshift. */
528 1, /* size (0 = byte, 1 = short, 2 = long). */
529 16, /* bitsize. */
530 FALSE, /* pc_relative. */
531 0, /* bitpos. */
532 complain_overflow_unsigned, /* complain_on_overflow. */
533 bfin_imm16_reloc, /* special_function. */
534 "R_BFIN_HUIMM16", /* name. */
535 FALSE, /* partial_inplace. */
536 0, /* src_mask. */
537 0x0000FFFF, /* dst_mask. */
538 TRUE), /* pcrel_offset. */
539
540 HOWTO (R_BFIN_PCREL12_JUMP_S, /* type. */
541 1, /* rightshift. */
542 1, /* size (0 = byte, 1 = short, 2 = long). */
543 12, /* bitsize. */
544 TRUE, /* pc_relative. */
545 0, /* bitpos. */
546 complain_overflow_signed, /* complain_on_overflow. */
547 bfin_bfd_reloc, /* special_function. */
548 "R_BFIN_PCREL12_JUMP_S", /* name. */
549 FALSE, /* partial_inplace. */
550 0, /* src_mask. */
551 0x00000FFF, /* dst_mask. */
552 TRUE), /* pcrel_offset. */
553
554 HOWTO (R_BFIN_PCREL24_JUMP_X, /* type. */
555 1, /* rightshift. */
556 2, /* size (0 = byte, 1 = short, 2 = long). */
557 24, /* bitsize. */
558 TRUE, /* pc_relative. */
559 0, /* bitpos. */
560 complain_overflow_signed, /* complain_on_overflow. */
561 bfin_pcrel24_reloc, /* special_function. */
562 "R_BFIN_PCREL24_JUMP_X", /* name. */
563 FALSE, /* partial_inplace. */
564 0, /* src_mask. */
565 0x00FFFFFF, /* dst_mask. */
566 TRUE), /* pcrel_offset. */
567
568 HOWTO (R_BFIN_PCREL24, /* type. */
569 1, /* rightshift. */
570 2, /* size (0 = byte, 1 = short, 2 = long). */
571 24, /* bitsize. */
572 TRUE, /* pc_relative. */
573 0, /* bitpos. */
574 complain_overflow_signed, /* complain_on_overflow. */
575 bfin_pcrel24_reloc, /* special_function. */
576 "R_BFIN_PCREL24", /* name. */
577 FALSE, /* partial_inplace. */
578 0, /* src_mask. */
579 0x00FFFFFF, /* dst_mask. */
580 TRUE), /* pcrel_offset. */
581
582 HOWTO (R_BFIN_UNUSEDB, /* type. */
583 0, /* rightshift. */
584 3, /* size (0 = byte, 1 = short, 2 = long). */
585 0, /* bitsize. */
586 FALSE, /* pc_relative. */
587 0, /* bitpos. */
588 complain_overflow_dont, /* complain_on_overflow. */
589 bfd_elf_generic_reloc, /* special_function. */
590 "R_BFIN_UNUSEDB", /* name. */
591 FALSE, /* partial_inplace. */
592 0, /* src_mask. */
593 0, /* dst_mask. */
594 FALSE), /* pcrel_offset. */
595
596 HOWTO (R_BFIN_UNUSEDC, /* type. */
597 0, /* rightshift. */
598 3, /* size (0 = byte, 1 = short, 2 = long). */
599 0, /* bitsize. */
600 FALSE, /* pc_relative. */
601 0, /* bitpos. */
602 complain_overflow_dont, /* complain_on_overflow. */
603 bfd_elf_generic_reloc, /* special_function. */
604 "R_BFIN_UNUSEDC", /* name. */
605 FALSE, /* partial_inplace. */
606 0, /* src_mask. */
607 0, /* dst_mask. */
608 FALSE), /* pcrel_offset. */
609
610 HOWTO (R_BFIN_PCREL24_JUMP_L, /* type. */
611 1, /* rightshift. */
612 2, /* size (0 = byte, 1 = short, 2 = long). */
613 24, /* bitsize. */
614 TRUE, /* pc_relative. */
615 0, /* bitpos. */
616 complain_overflow_signed, /* complain_on_overflow. */
617 bfin_pcrel24_reloc, /* special_function. */
618 "R_BFIN_PCREL24_JUMP_L", /* name. */
619 FALSE, /* partial_inplace. */
620 0, /* src_mask. */
621 0x00FFFFFF, /* dst_mask. */
622 TRUE), /* pcrel_offset. */
623
624 HOWTO (R_BFIN_PCREL24_CALL_X, /* type. */
625 1, /* rightshift. */
626 2, /* size (0 = byte, 1 = short, 2 = long). */
627 24, /* bitsize. */
628 TRUE, /* pc_relative. */
629 0, /* bitpos. */
630 complain_overflow_signed, /* complain_on_overflow. */
631 bfin_pcrel24_reloc, /* special_function. */
632 "R_BFIN_PCREL24_CALL_X", /* name. */
633 FALSE, /* partial_inplace. */
634 0, /* src_mask. */
635 0x00FFFFFF, /* dst_mask. */
636 TRUE), /* pcrel_offset. */
637
638 HOWTO (R_BFIN_VAR_EQ_SYMB, /* type. */
639 0, /* rightshift. */
640 2, /* size (0 = byte, 1 = short, 2 = long). */
641 32, /* bitsize. */
642 FALSE, /* pc_relative. */
643 0, /* bitpos. */
644 complain_overflow_bitfield, /* complain_on_overflow. */
645 bfin_bfd_reloc, /* special_function. */
646 "R_BFIN_VAR_EQ_SYMB", /* name. */
647 FALSE, /* partial_inplace. */
648 0, /* src_mask. */
649 0, /* dst_mask. */
650 FALSE), /* pcrel_offset. */
651
652 HOWTO (R_BFIN_BYTE_DATA, /* type. */
653 0, /* rightshift. */
654 0, /* size (0 = byte, 1 = short, 2 = long). */
655 8, /* bitsize. */
656 FALSE, /* pc_relative. */
657 0, /* bitpos. */
658 complain_overflow_unsigned, /* complain_on_overflow. */
659 bfin_bfd_reloc, /* special_function. */
660 "R_BFIN_BYTE_DATA", /* name. */
661 FALSE, /* partial_inplace. */
662 0, /* src_mask. */
663 0xFF, /* dst_mask. */
664 TRUE), /* pcrel_offset. */
665
666 HOWTO (R_BFIN_BYTE2_DATA, /* type. */
667 0, /* rightshift. */
668 1, /* size (0 = byte, 1 = short, 2 = long). */
669 16, /* bitsize. */
670 FALSE, /* pc_relative. */
671 0, /* bitpos. */
672 complain_overflow_signed, /* complain_on_overflow. */
673 bfin_bfd_reloc, /* special_function. */
674 "R_BFIN_BYTE2_DATA", /* name. */
675 FALSE, /* partial_inplace. */
676 0, /* src_mask. */
677 0xFFFF, /* dst_mask. */
678 TRUE), /* pcrel_offset. */
679
680 HOWTO (R_BFIN_BYTE4_DATA, /* type. */
681 0, /* rightshift. */
682 2, /* size (0 = byte, 1 = short, 2 = long). */
683 32, /* bitsize. */
684 FALSE, /* pc_relative. */
685 0, /* bitpos. */
686 complain_overflow_unsigned, /* complain_on_overflow. */
687 bfin_byte4_reloc, /* special_function. */
688 "R_BFIN_BYTE4_DATA", /* name. */
689 FALSE, /* partial_inplace. */
690 0, /* src_mask. */
691 0xFFFFFFFF, /* dst_mask. */
692 TRUE), /* pcrel_offset. */
693
694 HOWTO (R_BFIN_PCREL11, /* type. */
695 1, /* rightshift. */
696 1, /* size (0 = byte, 1 = short, 2 = long). */
697 10, /* bitsize. */
698 TRUE, /* pc_relative. */
699 0, /* bitpos. */
700 complain_overflow_unsigned, /* complain_on_overflow. */
701 bfin_bfd_reloc, /* special_function. */
702 "R_BFIN_PCREL11", /* name. */
703 FALSE, /* partial_inplace. */
704 0, /* src_mask. */
705 0x000003FF, /* dst_mask. */
706 FALSE), /* pcrel_offset. */
707
708
709 /* A 18-bit signed operand with the GOT offset for the address of
710 the symbol. */
711 HOWTO (R_BFIN_GOT17M4, /* type */
712 2, /* rightshift */
713 1, /* size (0 = byte, 1 = short, 2 = long) */
714 16, /* bitsize */
715 FALSE, /* pc_relative */
716 0, /* bitpos */
717 complain_overflow_signed, /* complain_on_overflow */
718 bfd_elf_generic_reloc, /* special_function */
719 "R_BFIN_GOT17M4", /* name */
720 FALSE, /* partial_inplace */
721 0xffff, /* src_mask */
722 0xffff, /* dst_mask */
723 FALSE), /* pcrel_offset */
724
725 /* The upper 16 bits of the GOT offset for the address of the
726 symbol. */
727 HOWTO (R_BFIN_GOTHI, /* type */
728 0, /* rightshift */
729 1, /* size (0 = byte, 1 = short, 2 = long) */
730 16, /* bitsize */
731 FALSE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_dont, /* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_BFIN_GOTHI", /* name */
736 FALSE, /* partial_inplace */
737 0xffff, /* src_mask */
738 0xffff, /* dst_mask */
739 FALSE), /* pcrel_offset */
740
741 /* The lower 16 bits of the GOT offset for the address of the
742 symbol. */
743 HOWTO (R_BFIN_GOTLO, /* type */
744 0, /* rightshift */
745 1, /* size (0 = byte, 1 = short, 2 = long) */
746 16, /* bitsize */
747 FALSE, /* pc_relative */
748 0, /* bitpos */
749 complain_overflow_dont, /* complain_on_overflow */
750 bfd_elf_generic_reloc, /* special_function */
751 "R_BFIN_GOTLO", /* name */
752 FALSE, /* partial_inplace */
753 0xffff, /* src_mask */
754 0xffff, /* dst_mask */
755 FALSE), /* pcrel_offset */
756
757 /* The 32-bit address of the canonical descriptor of a function. */
758 HOWTO (R_BFIN_FUNCDESC, /* type */
759 0, /* rightshift */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
761 32, /* bitsize */
762 FALSE, /* pc_relative */
763 0, /* bitpos */
764 complain_overflow_bitfield, /* complain_on_overflow */
765 bfd_elf_generic_reloc, /* special_function */
766 "R_BFIN_FUNCDESC", /* name */
767 FALSE, /* partial_inplace */
768 0xffffffff, /* src_mask */
769 0xffffffff, /* dst_mask */
770 FALSE), /* pcrel_offset */
771
772 /* A 12-bit signed operand with the GOT offset for the address of
773 canonical descriptor of a function. */
774 HOWTO (R_BFIN_FUNCDESC_GOT17M4, /* type */
775 2, /* rightshift */
776 1, /* size (0 = byte, 1 = short, 2 = long) */
777 16, /* bitsize */
778 FALSE, /* pc_relative */
779 0, /* bitpos */
780 complain_overflow_signed, /* complain_on_overflow */
781 bfd_elf_generic_reloc, /* special_function */
782 "R_BFIN_FUNCDESC_GOT17M4", /* name */
783 FALSE, /* partial_inplace */
784 0xffff, /* src_mask */
785 0xffff, /* dst_mask */
786 FALSE), /* pcrel_offset */
787
788 /* The upper 16 bits of the GOT offset for the address of the
789 canonical descriptor of a function. */
790 HOWTO (R_BFIN_FUNCDESC_GOTHI, /* type */
791 0, /* rightshift */
792 1, /* size (0 = byte, 1 = short, 2 = long) */
793 16, /* bitsize */
794 FALSE, /* pc_relative */
795 0, /* bitpos */
796 complain_overflow_dont, /* complain_on_overflow */
797 bfd_elf_generic_reloc, /* special_function */
798 "R_BFIN_FUNCDESC_GOTHI", /* name */
799 FALSE, /* partial_inplace */
800 0xffff, /* src_mask */
801 0xffff, /* dst_mask */
802 FALSE), /* pcrel_offset */
803
804 /* The lower 16 bits of the GOT offset for the address of the
805 canonical descriptor of a function. */
806 HOWTO (R_BFIN_FUNCDESC_GOTLO, /* type */
807 0, /* rightshift */
808 1, /* size (0 = byte, 1 = short, 2 = long) */
809 16, /* bitsize */
810 FALSE, /* pc_relative */
811 0, /* bitpos */
812 complain_overflow_dont, /* complain_on_overflow */
813 bfd_elf_generic_reloc, /* special_function */
814 "R_BFIN_FUNCDESC_GOTLO", /* name */
815 FALSE, /* partial_inplace */
816 0xffff, /* src_mask */
817 0xffff, /* dst_mask */
818 FALSE), /* pcrel_offset */
819
820 /* The 32-bit address of the canonical descriptor of a function. */
821 HOWTO (R_BFIN_FUNCDESC_VALUE, /* type */
822 0, /* rightshift */
823 2, /* size (0 = byte, 1 = short, 2 = long) */
824 64, /* bitsize */
825 FALSE, /* pc_relative */
826 0, /* bitpos */
827 complain_overflow_bitfield, /* complain_on_overflow */
828 bfd_elf_generic_reloc, /* special_function */
829 "R_BFIN_FUNCDESC_VALUE", /* name */
830 FALSE, /* partial_inplace */
831 0xffffffff, /* src_mask */
832 0xffffffff, /* dst_mask */
833 FALSE), /* pcrel_offset */
834
835 /* A 12-bit signed operand with the GOT offset for the address of
836 canonical descriptor of a function. */
837 HOWTO (R_BFIN_FUNCDESC_GOTOFF17M4, /* type */
838 2, /* rightshift */
839 1, /* size (0 = byte, 1 = short, 2 = long) */
840 16, /* bitsize */
841 FALSE, /* pc_relative */
842 0, /* bitpos */
843 complain_overflow_signed, /* complain_on_overflow */
844 bfd_elf_generic_reloc, /* special_function */
845 "R_BFIN_FUNCDESC_GOTOFF17M4", /* name */
846 FALSE, /* partial_inplace */
847 0xffff, /* src_mask */
848 0xffff, /* dst_mask */
849 FALSE), /* pcrel_offset */
850
851 /* The upper 16 bits of the GOT offset for the address of the
852 canonical descriptor of a function. */
853 HOWTO (R_BFIN_FUNCDESC_GOTOFFHI, /* type */
854 0, /* rightshift */
855 1, /* size (0 = byte, 1 = short, 2 = long) */
856 16, /* bitsize */
857 FALSE, /* pc_relative */
858 0, /* bitpos */
859 complain_overflow_dont, /* complain_on_overflow */
860 bfd_elf_generic_reloc, /* special_function */
861 "R_BFIN_FUNCDESC_GOTOFFHI", /* name */
862 FALSE, /* partial_inplace */
863 0xffff, /* src_mask */
864 0xffff, /* dst_mask */
865 FALSE), /* pcrel_offset */
866
867 /* The lower 16 bits of the GOT offset for the address of the
868 canonical descriptor of a function. */
869 HOWTO (R_BFIN_FUNCDESC_GOTOFFLO, /* type */
870 0, /* rightshift */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
872 16, /* bitsize */
873 FALSE, /* pc_relative */
874 0, /* bitpos */
875 complain_overflow_dont, /* complain_on_overflow */
876 bfd_elf_generic_reloc, /* special_function */
877 "R_BFIN_FUNCDESC_GOTOFFLO", /* name */
878 FALSE, /* partial_inplace */
879 0xffff, /* src_mask */
880 0xffff, /* dst_mask */
881 FALSE), /* pcrel_offset */
882
883 /* A 12-bit signed operand with the GOT offset for the address of
884 the symbol. */
885 HOWTO (R_BFIN_GOTOFF17M4, /* type */
886 2, /* rightshift */
887 1, /* size (0 = byte, 1 = short, 2 = long) */
888 16, /* bitsize */
889 FALSE, /* pc_relative */
890 0, /* bitpos */
891 complain_overflow_signed, /* complain_on_overflow */
892 bfd_elf_generic_reloc, /* special_function */
893 "R_BFIN_GOTOFF17M4", /* name */
894 FALSE, /* partial_inplace */
895 0xffff, /* src_mask */
896 0xffff, /* dst_mask */
897 FALSE), /* pcrel_offset */
898
899 /* The upper 16 bits of the GOT offset for the address of the
900 symbol. */
901 HOWTO (R_BFIN_GOTOFFHI, /* type */
902 0, /* rightshift */
903 1, /* size (0 = byte, 1 = short, 2 = long) */
904 16, /* bitsize */
905 FALSE, /* pc_relative */
906 0, /* bitpos */
907 complain_overflow_dont, /* complain_on_overflow */
908 bfd_elf_generic_reloc, /* special_function */
909 "R_BFIN_GOTOFFHI", /* name */
910 FALSE, /* partial_inplace */
911 0xffff, /* src_mask */
912 0xffff, /* dst_mask */
913 FALSE), /* pcrel_offset */
914
915 /* The lower 16 bits of the GOT offset for the address of the
916 symbol. */
917 HOWTO (R_BFIN_GOTOFFLO, /* type */
918 0, /* rightshift */
919 1, /* size (0 = byte, 1 = short, 2 = long) */
920 16, /* bitsize */
921 FALSE, /* pc_relative */
922 0, /* bitpos */
923 complain_overflow_dont, /* complain_on_overflow */
924 bfd_elf_generic_reloc, /* special_function */
925 "R_BFIN_GOTOFFLO", /* name */
926 FALSE, /* partial_inplace */
927 0xffff, /* src_mask */
928 0xffff, /* dst_mask */
929 FALSE), /* pcrel_offset */
930 };
931
932 static reloc_howto_type bfin_gnuext_howto_table [] =
933 {
934 HOWTO (R_BFIN_PLTPC, /* type. */
935 0, /* rightshift. */
936 1, /* size (0 = byte, 1 = short, 2 = long). */
937 16, /* bitsize. */
938 FALSE, /* pc_relative. */
939 0, /* bitpos. */
940 complain_overflow_bitfield, /* complain_on_overflow. */
941 bfin_pltpc_reloc, /* special_function. */
942 "R_BFIN_PLTPC", /* name. */
943 FALSE, /* partial_inplace. */
944 0xffff, /* src_mask. */
945 0xffff, /* dst_mask. */
946 FALSE), /* pcrel_offset. */
947
948 HOWTO (R_BFIN_GOT, /* type. */
949 0, /* rightshift. */
950 1, /* size (0 = byte, 1 = short, 2 = long). */
951 16, /* bitsize. */
952 FALSE, /* pc_relative. */
953 0, /* bitpos. */
954 complain_overflow_bitfield, /* complain_on_overflow. */
955 bfd_elf_generic_reloc, /* special_function. */
956 "R_BFIN_GOT", /* name. */
957 FALSE, /* partial_inplace. */
958 0x7fff, /* src_mask. */
959 0x7fff, /* dst_mask. */
960 FALSE), /* pcrel_offset. */
961
962 /* GNU extension to record C++ vtable hierarchy. */
963 HOWTO (R_BFIN_GNU_VTINHERIT, /* type. */
964 0, /* rightshift. */
965 2, /* size (0 = byte, 1 = short, 2 = long). */
966 0, /* bitsize. */
967 FALSE, /* pc_relative. */
968 0, /* bitpos. */
969 complain_overflow_dont, /* complain_on_overflow. */
970 NULL, /* special_function. */
971 "R_BFIN_GNU_VTINHERIT", /* name. */
972 FALSE, /* partial_inplace. */
973 0, /* src_mask. */
974 0, /* dst_mask. */
975 FALSE), /* pcrel_offset. */
976
977 /* GNU extension to record C++ vtable member usage. */
978 HOWTO (R_BFIN_GNU_VTENTRY, /* type. */
979 0, /* rightshift. */
980 2, /* size (0 = byte, 1 = short, 2 = long). */
981 0, /* bitsize. */
982 FALSE, /* pc_relative. */
983 0, /* bitpos. */
984 complain_overflow_dont, /* complain_on_overflow. */
985 _bfd_elf_rel_vtable_reloc_fn, /* special_function. */
986 "R_BFIN_GNU_VTENTRY", /* name. */
987 FALSE, /* partial_inplace. */
988 0, /* src_mask. */
989 0, /* dst_mask. */
990 FALSE) /* pcrel_offset. */
991 };
992
993 struct bfin_reloc_map
994 {
995 bfd_reloc_code_real_type bfd_reloc_val;
996 unsigned int bfin_reloc_val;
997 };
998
999 static const struct bfin_reloc_map bfin_reloc_map [] =
1000 {
1001 { BFD_RELOC_NONE, R_BFIN_UNUSED0 },
1002 { BFD_RELOC_BFIN_5_PCREL, R_BFIN_PCREL5M2 },
1003 { BFD_RELOC_NONE, R_BFIN_UNUSED1 },
1004 { BFD_RELOC_BFIN_10_PCREL, R_BFIN_PCREL10 },
1005 { BFD_RELOC_BFIN_12_PCREL_JUMP, R_BFIN_PCREL12_JUMP },
1006 { BFD_RELOC_BFIN_16_IMM, R_BFIN_RIMM16 },
1007 { BFD_RELOC_BFIN_16_LOW, R_BFIN_LUIMM16 },
1008 { BFD_RELOC_BFIN_16_HIGH, R_BFIN_HUIMM16 },
1009 { BFD_RELOC_BFIN_12_PCREL_JUMP_S, R_BFIN_PCREL12_JUMP_S },
1010 { BFD_RELOC_24_PCREL, R_BFIN_PCREL24 },
1011 { BFD_RELOC_24_PCREL, R_BFIN_PCREL24 },
1012 { BFD_RELOC_BFIN_24_PCREL_JUMP_L, R_BFIN_PCREL24_JUMP_L },
1013 { BFD_RELOC_NONE, R_BFIN_UNUSEDB },
1014 { BFD_RELOC_NONE, R_BFIN_UNUSEDC },
1015 { BFD_RELOC_BFIN_24_PCREL_CALL_X, R_BFIN_PCREL24_CALL_X },
1016 { BFD_RELOC_8, R_BFIN_BYTE_DATA },
1017 { BFD_RELOC_16, R_BFIN_BYTE2_DATA },
1018 { BFD_RELOC_32, R_BFIN_BYTE4_DATA },
1019 { BFD_RELOC_BFIN_11_PCREL, R_BFIN_PCREL11 },
1020 { BFD_RELOC_BFIN_GOT, R_BFIN_GOT },
1021 { BFD_RELOC_BFIN_PLTPC, R_BFIN_PLTPC },
1022
1023 { BFD_RELOC_BFIN_GOT17M4, R_BFIN_GOT17M4 },
1024 { BFD_RELOC_BFIN_GOTHI, R_BFIN_GOTHI },
1025 { BFD_RELOC_BFIN_GOTLO, R_BFIN_GOTLO },
1026 { BFD_RELOC_BFIN_FUNCDESC, R_BFIN_FUNCDESC },
1027 { BFD_RELOC_BFIN_FUNCDESC_GOT17M4, R_BFIN_FUNCDESC_GOT17M4 },
1028 { BFD_RELOC_BFIN_FUNCDESC_GOTHI, R_BFIN_FUNCDESC_GOTHI },
1029 { BFD_RELOC_BFIN_FUNCDESC_GOTLO, R_BFIN_FUNCDESC_GOTLO },
1030 { BFD_RELOC_BFIN_FUNCDESC_VALUE, R_BFIN_FUNCDESC_VALUE },
1031 { BFD_RELOC_BFIN_FUNCDESC_GOTOFF17M4, R_BFIN_FUNCDESC_GOTOFF17M4 },
1032 { BFD_RELOC_BFIN_FUNCDESC_GOTOFFHI, R_BFIN_FUNCDESC_GOTOFFHI },
1033 { BFD_RELOC_BFIN_FUNCDESC_GOTOFFLO, R_BFIN_FUNCDESC_GOTOFFLO },
1034 { BFD_RELOC_BFIN_GOTOFF17M4, R_BFIN_GOTOFF17M4 },
1035 { BFD_RELOC_BFIN_GOTOFFHI, R_BFIN_GOTOFFHI },
1036 { BFD_RELOC_BFIN_GOTOFFLO, R_BFIN_GOTOFFLO },
1037
1038 { BFD_RELOC_VTABLE_INHERIT, R_BFIN_GNU_VTINHERIT },
1039 { BFD_RELOC_VTABLE_ENTRY, R_BFIN_GNU_VTENTRY },
1040 };
1041
1042
1043 static bfd_boolean
1044 bfin_info_to_howto (bfd *abfd,
1045 arelent *cache_ptr,
1046 Elf_Internal_Rela *dst)
1047 {
1048 unsigned int r_type;
1049
1050 r_type = ELF32_R_TYPE (dst->r_info);
1051
1052 if (r_type <= BFIN_RELOC_MAX)
1053 cache_ptr->howto = &bfin_howto_table [r_type];
1054
1055 else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX)
1056 cache_ptr->howto = &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN];
1057
1058 else
1059 {
1060 /* xgettext:c-format */
1061 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1062 abfd, r_type);
1063 bfd_set_error (bfd_error_bad_value);
1064 return FALSE;
1065 }
1066
1067 return TRUE;
1068 }
1069
1070 /* Given a BFD reloc type, return the howto. */
1071 static reloc_howto_type *
1072 bfin_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
1073 bfd_reloc_code_real_type code)
1074 {
1075 unsigned int i;
1076 unsigned int r_type = (unsigned int) -1;
1077
1078 for (i = sizeof (bfin_reloc_map) / sizeof (bfin_reloc_map[0]); i--;)
1079 if (bfin_reloc_map[i].bfd_reloc_val == code)
1080 r_type = bfin_reloc_map[i].bfin_reloc_val;
1081
1082 if (r_type <= BFIN_RELOC_MAX)
1083 return &bfin_howto_table [r_type];
1084
1085 else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX)
1086 return &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN];
1087
1088 return (reloc_howto_type *) NULL;
1089 }
1090
1091 static reloc_howto_type *
1092 bfin_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1093 const char *r_name)
1094 {
1095 unsigned int i;
1096
1097 for (i = 0;
1098 i < (sizeof (bfin_howto_table)
1099 / sizeof (bfin_howto_table[0]));
1100 i++)
1101 if (bfin_howto_table[i].name != NULL
1102 && strcasecmp (bfin_howto_table[i].name, r_name) == 0)
1103 return &bfin_howto_table[i];
1104
1105 for (i = 0;
1106 i < (sizeof (bfin_gnuext_howto_table)
1107 / sizeof (bfin_gnuext_howto_table[0]));
1108 i++)
1109 if (bfin_gnuext_howto_table[i].name != NULL
1110 && strcasecmp (bfin_gnuext_howto_table[i].name, r_name) == 0)
1111 return &bfin_gnuext_howto_table[i];
1112
1113 return NULL;
1114 }
1115
1116 /* Given a bfin relocation type, return the howto. */
1117 static reloc_howto_type *
1118 bfin_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
1119 unsigned int r_type)
1120 {
1121 if (r_type <= BFIN_RELOC_MAX)
1122 return &bfin_howto_table [r_type];
1123
1124 else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX)
1125 return &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN];
1126
1127 return (reloc_howto_type *) NULL;
1128 }
1129
1130 /* Set by ld emulation if --code-in-l1. */
1131 bfd_boolean elf32_bfin_code_in_l1 = 0;
1132
1133 /* Set by ld emulation if --data-in-l1. */
1134 bfd_boolean elf32_bfin_data_in_l1 = 0;
1135
1136 static bfd_boolean
1137 elf32_bfin_final_write_processing (bfd *abfd)
1138 {
1139 if (elf32_bfin_code_in_l1)
1140 elf_elfheader (abfd)->e_flags |= EF_BFIN_CODE_IN_L1;
1141 if (elf32_bfin_data_in_l1)
1142 elf_elfheader (abfd)->e_flags |= EF_BFIN_DATA_IN_L1;
1143 return _bfd_elf_final_write_processing (abfd);
1144 }
1145
1146 /* Return TRUE if the name is a local label.
1147 bfin local labels begin with L$. */
1148 static bfd_boolean
1149 bfin_is_local_label_name (bfd *abfd, const char *label)
1150 {
1151 if (label[0] == 'L' && label[1] == '$' )
1152 return TRUE;
1153
1154 return _bfd_elf_is_local_label_name (abfd, label);
1155 }
1156 \f
1157 /* Look through the relocs for a section during the first phase, and
1158 allocate space in the global offset table or procedure linkage
1159 table. */
1160
1161 static bfd_boolean
1162 bfin_check_relocs (bfd * abfd,
1163 struct bfd_link_info *info,
1164 asection *sec,
1165 const Elf_Internal_Rela *relocs)
1166 {
1167 bfd *dynobj;
1168 Elf_Internal_Shdr *symtab_hdr;
1169 struct elf_link_hash_entry **sym_hashes;
1170 bfd_signed_vma *local_got_refcounts;
1171 const Elf_Internal_Rela *rel;
1172 const Elf_Internal_Rela *rel_end;
1173 asection *sgot;
1174 asection *srelgot;
1175
1176 if (bfd_link_relocatable (info))
1177 return TRUE;
1178
1179 dynobj = elf_hash_table (info)->dynobj;
1180 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1181 sym_hashes = elf_sym_hashes (abfd);
1182 local_got_refcounts = elf_local_got_refcounts (abfd);
1183
1184 sgot = NULL;
1185 srelgot = NULL;
1186
1187 rel_end = relocs + sec->reloc_count;
1188 for (rel = relocs; rel < rel_end; rel++)
1189 {
1190 unsigned long r_symndx;
1191 struct elf_link_hash_entry *h;
1192
1193 r_symndx = ELF32_R_SYM (rel->r_info);
1194 if (r_symndx < symtab_hdr->sh_info)
1195 h = NULL;
1196 else
1197 {
1198 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1199 }
1200
1201 switch (ELF32_R_TYPE (rel->r_info))
1202 {
1203 /* This relocation describes the C++ object vtable hierarchy.
1204 Reconstruct it for later use during GC. */
1205 case R_BFIN_GNU_VTINHERIT:
1206 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1207 return FALSE;
1208 break;
1209
1210 /* This relocation describes which C++ vtable entries
1211 are actually used. Record for later use during GC. */
1212 case R_BFIN_GNU_VTENTRY:
1213 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1214 return FALSE;
1215 break;
1216
1217 case R_BFIN_GOT:
1218 if (h != NULL
1219 && strcmp (h->root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1220 break;
1221 /* Fall through. */
1222
1223 if (dynobj == NULL)
1224 {
1225 /* Create the .got section. */
1226 elf_hash_table (info)->dynobj = dynobj = abfd;
1227 if (!_bfd_elf_create_got_section (dynobj, info))
1228 return FALSE;
1229 }
1230
1231 sgot = elf_hash_table (info)->sgot;
1232 srelgot = elf_hash_table (info)->srelgot;
1233 BFD_ASSERT (sgot != NULL);
1234
1235 if (h != NULL)
1236 {
1237 if (h->got.refcount == 0)
1238 {
1239 /* Make sure this symbol is output as a dynamic symbol. */
1240 if (h->dynindx == -1 && !h->forced_local)
1241 {
1242 if (!bfd_elf_link_record_dynamic_symbol (info, h))
1243 return FALSE;
1244 }
1245
1246 /* Allocate space in the .got section. */
1247 sgot->size += 4;
1248 /* Allocate relocation space. */
1249 srelgot->size += sizeof (Elf32_External_Rela);
1250 }
1251 h->got.refcount++;
1252 }
1253 else
1254 {
1255 /* This is a global offset table entry for a local symbol. */
1256 if (local_got_refcounts == NULL)
1257 {
1258 bfd_size_type size;
1259
1260 size = symtab_hdr->sh_info;
1261 size *= sizeof (bfd_signed_vma);
1262 local_got_refcounts = ((bfd_signed_vma *)
1263 bfd_zalloc (abfd, size));
1264 if (local_got_refcounts == NULL)
1265 return FALSE;
1266 elf_local_got_refcounts (abfd) = local_got_refcounts;
1267 }
1268 if (local_got_refcounts[r_symndx] == 0)
1269 {
1270 sgot->size += 4;
1271 if (bfd_link_pic (info))
1272 {
1273 /* If we are generating a shared object, we need to
1274 output a R_68K_RELATIVE reloc so that the dynamic
1275 linker can adjust this GOT entry. */
1276 srelgot->size += sizeof (Elf32_External_Rela);
1277 }
1278 }
1279 local_got_refcounts[r_symndx]++;
1280 }
1281 break;
1282
1283 default:
1284 break;
1285 }
1286 }
1287
1288 return TRUE;
1289 }
1290
1291 static enum elf_reloc_type_class
1292 elf32_bfin_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
1293 const asection *rel_sec ATTRIBUTE_UNUSED,
1294 const Elf_Internal_Rela * rela)
1295 {
1296 switch ((int) ELF32_R_TYPE (rela->r_info))
1297 {
1298 default:
1299 return reloc_class_normal;
1300 }
1301 }
1302 \f
1303 static bfd_reloc_status_type
1304 bfin_final_link_relocate (Elf_Internal_Rela *rel, reloc_howto_type *howto,
1305 bfd *input_bfd, asection *input_section,
1306 bfd_byte *contents, bfd_vma address,
1307 bfd_vma value, bfd_vma addend)
1308 {
1309 int r_type = ELF32_R_TYPE (rel->r_info);
1310
1311 if (r_type == R_BFIN_PCREL24 || r_type == R_BFIN_PCREL24_JUMP_L)
1312 {
1313 bfd_reloc_status_type r = bfd_reloc_ok;
1314 bfd_vma x;
1315
1316 if (address > bfd_get_section_limit (input_bfd, input_section))
1317 return bfd_reloc_outofrange;
1318
1319 value += addend;
1320
1321 /* Perform usual pc-relative correction. */
1322 value -= input_section->output_section->vma + input_section->output_offset;
1323 value -= address;
1324
1325 /* We are getting reloc_entry->address 2 byte off from
1326 the start of instruction. Assuming absolute postion
1327 of the reloc data. But, following code had been written assuming
1328 reloc address is starting at begining of instruction.
1329 To compensate that I have increased the value of
1330 relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
1331
1332 value += 2;
1333 address -= 2;
1334
1335 if ((value & 0xFF000000) != 0
1336 && (value & 0xFF000000) != 0xFF000000)
1337 r = bfd_reloc_overflow;
1338
1339 value >>= 1;
1340
1341 x = bfd_get_16 (input_bfd, contents + address);
1342 x = (x & 0xff00) | ((value >> 16) & 0xff);
1343 bfd_put_16 (input_bfd, x, contents + address);
1344
1345 x = bfd_get_16 (input_bfd, contents + address + 2);
1346 x = value & 0xFFFF;
1347 bfd_put_16 (input_bfd, x, contents + address + 2);
1348 return r;
1349 }
1350
1351 return _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
1352 rel->r_offset, value, addend);
1353
1354 }
1355
1356 static bfd_boolean
1357 bfin_relocate_section (bfd * output_bfd,
1358 struct bfd_link_info *info,
1359 bfd * input_bfd,
1360 asection * input_section,
1361 bfd_byte * contents,
1362 Elf_Internal_Rela * relocs,
1363 Elf_Internal_Sym * local_syms,
1364 asection ** local_sections)
1365 {
1366 bfd *dynobj;
1367 Elf_Internal_Shdr *symtab_hdr;
1368 struct elf_link_hash_entry **sym_hashes;
1369 bfd_vma *local_got_offsets;
1370 asection *sgot;
1371 Elf_Internal_Rela *rel;
1372 Elf_Internal_Rela *relend;
1373 int i = 0;
1374
1375 dynobj = elf_hash_table (info)->dynobj;
1376 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1377 sym_hashes = elf_sym_hashes (input_bfd);
1378 local_got_offsets = elf_local_got_offsets (input_bfd);
1379
1380 sgot = NULL;
1381
1382 rel = relocs;
1383 relend = relocs + input_section->reloc_count;
1384 for (; rel < relend; rel++, i++)
1385 {
1386 int r_type;
1387 reloc_howto_type *howto;
1388 unsigned long r_symndx;
1389 struct elf_link_hash_entry *h;
1390 Elf_Internal_Sym *sym;
1391 asection *sec;
1392 bfd_vma relocation = 0;
1393 bfd_boolean unresolved_reloc;
1394 bfd_reloc_status_type r;
1395 bfd_vma address;
1396
1397 r_type = ELF32_R_TYPE (rel->r_info);
1398 if (r_type < 0 || r_type >= 243)
1399 {
1400 bfd_set_error (bfd_error_bad_value);
1401 return FALSE;
1402 }
1403
1404 if (r_type == R_BFIN_GNU_VTENTRY
1405 || r_type == R_BFIN_GNU_VTINHERIT)
1406 continue;
1407
1408 howto = bfin_reloc_type_lookup (input_bfd, r_type);
1409 if (howto == NULL)
1410 {
1411 bfd_set_error (bfd_error_bad_value);
1412 return FALSE;
1413 }
1414 r_symndx = ELF32_R_SYM (rel->r_info);
1415
1416 h = NULL;
1417 sym = NULL;
1418 sec = NULL;
1419 unresolved_reloc = FALSE;
1420
1421 if (r_symndx < symtab_hdr->sh_info)
1422 {
1423 sym = local_syms + r_symndx;
1424 sec = local_sections[r_symndx];
1425 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1426 }
1427 else
1428 {
1429 bfd_boolean warned, ignored;
1430
1431 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1432 r_symndx, symtab_hdr, sym_hashes,
1433 h, sec, relocation,
1434 unresolved_reloc, warned, ignored);
1435 }
1436
1437 if (sec != NULL && discarded_section (sec))
1438 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1439 rel, 1, relend, howto, 0, contents);
1440
1441 if (bfd_link_relocatable (info))
1442 continue;
1443
1444 address = rel->r_offset;
1445
1446 /* Then, process normally. */
1447 switch (r_type)
1448 {
1449 case R_BFIN_GNU_VTINHERIT:
1450 case R_BFIN_GNU_VTENTRY:
1451 return bfd_reloc_ok;
1452
1453 case R_BFIN_GOT:
1454 /* Relocation is to the address of the entry for this symbol
1455 in the global offset table. */
1456 if (h != NULL
1457 && strcmp (h->root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
1458 goto do_default;
1459 /* Fall through. */
1460 /* Relocation is the offset of the entry for this symbol in
1461 the global offset table. */
1462
1463 {
1464 bfd_vma off;
1465
1466 if (dynobj == NULL)
1467 {
1468 /* Create the .got section. */
1469 elf_hash_table (info)->dynobj = dynobj = output_bfd;
1470 if (!_bfd_elf_create_got_section (dynobj, info))
1471 return FALSE;
1472 }
1473
1474 sgot = elf_hash_table (info)->sgot;
1475 BFD_ASSERT (sgot != NULL);
1476
1477 if (h != NULL)
1478 {
1479 bfd_boolean dyn;
1480
1481 off = h->got.offset;
1482 BFD_ASSERT (off != (bfd_vma) - 1);
1483 dyn = elf_hash_table (info)->dynamic_sections_created;
1484
1485 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
1486 bfd_link_pic (info),
1487 h)
1488 || (bfd_link_pic (info)
1489 && (info->symbolic
1490 || h->dynindx == -1
1491 || h->forced_local)
1492 && h->def_regular))
1493 {
1494 /* This is actually a static link, or it is a
1495 -Bsymbolic link and the symbol is defined
1496 locally, or the symbol was forced to be local
1497 because of a version file.. We must initialize
1498 this entry in the global offset table. Since
1499 the offset must always be a multiple of 4, we
1500 use the least significant bit to record whether
1501 we have initialized it already.
1502
1503 When doing a dynamic link, we create a .rela.got
1504 relocation entry to initialize the value. This
1505 is done in the finish_dynamic_symbol routine. */
1506 if ((off & 1) != 0)
1507 off &= ~1;
1508 else
1509 {
1510 bfd_put_32 (output_bfd, relocation,
1511 sgot->contents + off);
1512 h->got.offset |= 1;
1513 }
1514 }
1515 else
1516 unresolved_reloc = FALSE;
1517 }
1518 else
1519 {
1520 BFD_ASSERT (local_got_offsets != NULL);
1521 off = local_got_offsets[r_symndx];
1522 BFD_ASSERT (off != (bfd_vma) - 1);
1523
1524 /* The offset must always be a multiple of 4. We use
1525 the least significant bit to record whether we have
1526 already generated the necessary reloc. */
1527 if ((off & 1) != 0)
1528 off &= ~1;
1529 else
1530 {
1531 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
1532
1533 if (bfd_link_pic (info))
1534 {
1535 asection *s;
1536 Elf_Internal_Rela outrel;
1537 bfd_byte *loc;
1538
1539 s = elf_hash_table (info)->srelgot;
1540 BFD_ASSERT (s != NULL);
1541
1542 outrel.r_offset = (sgot->output_section->vma
1543 + sgot->output_offset + off);
1544 outrel.r_info =
1545 ELF32_R_INFO (0, R_BFIN_PCREL24);
1546 outrel.r_addend = relocation;
1547 loc = s->contents;
1548 loc +=
1549 s->reloc_count++ * sizeof (Elf32_External_Rela);
1550 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1551 }
1552
1553 local_got_offsets[r_symndx] |= 1;
1554 }
1555 }
1556
1557 relocation = sgot->output_offset + off;
1558 rel->r_addend = 0;
1559 /* bfin : preg = [preg + 17bitdiv4offset] relocation is div by 4. */
1560 relocation /= 4;
1561 }
1562 goto do_default;
1563
1564 default:
1565 do_default:
1566 r = bfin_final_link_relocate (rel, howto, input_bfd, input_section,
1567 contents, address,
1568 relocation, rel->r_addend);
1569
1570 break;
1571 }
1572
1573 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
1574 because such sections are not SEC_ALLOC and thus ld.so will
1575 not process them. */
1576 if (unresolved_reloc
1577 && !((input_section->flags & SEC_DEBUGGING) != 0 && h->def_dynamic)
1578 && _bfd_elf_section_offset (output_bfd, info, input_section,
1579 rel->r_offset) != (bfd_vma) -1)
1580 {
1581 _bfd_error_handler
1582 /* xgettext:c-format */
1583 (_("%pB(%pA+%#" PRIx64 "): "
1584 "unresolvable relocation against symbol `%s'"),
1585 input_bfd, input_section, (uint64_t) rel->r_offset,
1586 h->root.root.string);
1587 return FALSE;
1588 }
1589
1590 if (r != bfd_reloc_ok)
1591 {
1592 const char *name;
1593
1594 if (h != NULL)
1595 name = h->root.root.string;
1596 else
1597 {
1598 name = bfd_elf_string_from_elf_section (input_bfd,
1599 symtab_hdr->sh_link,
1600 sym->st_name);
1601 if (name == NULL)
1602 return FALSE;
1603 if (*name == '\0')
1604 name = bfd_section_name (sec);
1605 }
1606
1607 if (r == bfd_reloc_overflow)
1608 (*info->callbacks->reloc_overflow)
1609 (info, (h ? &h->root : NULL), name, howto->name,
1610 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
1611 else
1612 {
1613 _bfd_error_handler
1614 /* xgettext:c-format */
1615 (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
1616 input_bfd, input_section, (uint64_t) rel->r_offset,
1617 name, (int) r);
1618 return FALSE;
1619 }
1620 }
1621 }
1622
1623 return TRUE;
1624 }
1625
1626 static asection *
1627 bfin_gc_mark_hook (asection * sec,
1628 struct bfd_link_info *info,
1629 Elf_Internal_Rela * rel,
1630 struct elf_link_hash_entry *h,
1631 Elf_Internal_Sym * sym)
1632 {
1633 if (h != NULL)
1634 switch (ELF32_R_TYPE (rel->r_info))
1635 {
1636 case R_BFIN_GNU_VTINHERIT:
1637 case R_BFIN_GNU_VTENTRY:
1638 return NULL;
1639 }
1640
1641 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1642 }
1643 \f
1644 extern const bfd_target bfin_elf32_fdpic_vec;
1645 #define IS_FDPIC(bfd) ((bfd)->xvec == &bfin_elf32_fdpic_vec)
1646
1647 /* An extension of the elf hash table data structure,
1648 containing some additional Blackfin-specific data. */
1649 struct bfinfdpic_elf_link_hash_table
1650 {
1651 struct elf_link_hash_table elf;
1652
1653 /* A pointer to the .rofixup section. */
1654 asection *sgotfixup;
1655 /* GOT base offset. */
1656 bfd_vma got0;
1657 /* Location of the first non-lazy PLT entry, i.e., the number of
1658 bytes taken by lazy PLT entries. */
1659 bfd_vma plt0;
1660 /* A hash table holding information about which symbols were
1661 referenced with which PIC-related relocations. */
1662 struct htab *relocs_info;
1663 /* Summary reloc information collected by
1664 _bfinfdpic_count_got_plt_entries. */
1665 struct _bfinfdpic_dynamic_got_info *g;
1666 };
1667
1668 /* Get the Blackfin ELF linker hash table from a link_info structure. */
1669
1670 #define bfinfdpic_hash_table(info) \
1671 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \
1672 == BFIN_ELF_DATA ? ((struct bfinfdpic_elf_link_hash_table *) ((info)->hash)) : NULL)
1673
1674 #define bfinfdpic_got_section(info) \
1675 (bfinfdpic_hash_table (info)->elf.sgot)
1676 #define bfinfdpic_gotrel_section(info) \
1677 (bfinfdpic_hash_table (info)->elf.srelgot)
1678 #define bfinfdpic_gotfixup_section(info) \
1679 (bfinfdpic_hash_table (info)->sgotfixup)
1680 #define bfinfdpic_plt_section(info) \
1681 (bfinfdpic_hash_table (info)->elf.splt)
1682 #define bfinfdpic_pltrel_section(info) \
1683 (bfinfdpic_hash_table (info)->elf.srelplt)
1684 #define bfinfdpic_relocs_info(info) \
1685 (bfinfdpic_hash_table (info)->relocs_info)
1686 #define bfinfdpic_got_initial_offset(info) \
1687 (bfinfdpic_hash_table (info)->got0)
1688 #define bfinfdpic_plt_initial_offset(info) \
1689 (bfinfdpic_hash_table (info)->plt0)
1690 #define bfinfdpic_dynamic_got_plt_info(info) \
1691 (bfinfdpic_hash_table (info)->g)
1692
1693 /* The name of the dynamic interpreter. This is put in the .interp
1694 section. */
1695
1696 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
1697
1698 #define DEFAULT_STACK_SIZE 0x20000
1699
1700 /* This structure is used to collect the number of entries present in
1701 each addressable range of the got. */
1702 struct _bfinfdpic_dynamic_got_info
1703 {
1704 /* Several bits of information about the current link. */
1705 struct bfd_link_info *info;
1706 /* Total size needed for GOT entries within the 18- or 32-bit
1707 ranges. */
1708 bfd_vma got17m4, gothilo;
1709 /* Total size needed for function descriptor entries within the 18-
1710 or 32-bit ranges. */
1711 bfd_vma fd17m4, fdhilo;
1712 /* Total size needed function descriptor entries referenced in PLT
1713 entries, that would be profitable to place in offsets close to
1714 the PIC register. */
1715 bfd_vma fdplt;
1716 /* Total size needed by lazy PLT entries. */
1717 bfd_vma lzplt;
1718 /* Number of relocations carried over from input object files. */
1719 unsigned long relocs;
1720 /* Number of fixups introduced by relocations in input object files. */
1721 unsigned long fixups;
1722 };
1723
1724 /* Create a Blackfin ELF linker hash table. */
1725
1726 static struct bfd_link_hash_table *
1727 bfinfdpic_elf_link_hash_table_create (bfd *abfd)
1728 {
1729 struct bfinfdpic_elf_link_hash_table *ret;
1730 bfd_size_type amt = sizeof (struct bfinfdpic_elf_link_hash_table);
1731
1732 ret = bfd_zmalloc (amt);
1733 if (ret == NULL)
1734 return NULL;
1735
1736 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
1737 _bfd_elf_link_hash_newfunc,
1738 sizeof (struct elf_link_hash_entry),
1739 BFIN_ELF_DATA))
1740 {
1741 free (ret);
1742 return NULL;
1743 }
1744
1745 return &ret->elf.root;
1746 }
1747
1748 /* Decide whether a reference to a symbol can be resolved locally or
1749 not. If the symbol is protected, we want the local address, but
1750 its function descriptor must be assigned by the dynamic linker. */
1751 #define BFINFDPIC_SYM_LOCAL(INFO, H) \
1752 (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
1753 || ! elf_hash_table (INFO)->dynamic_sections_created)
1754 #define BFINFDPIC_FUNCDESC_LOCAL(INFO, H) \
1755 ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
1756
1757 /* This structure collects information on what kind of GOT, PLT or
1758 function descriptors are required by relocations that reference a
1759 certain symbol. */
1760 struct bfinfdpic_relocs_info
1761 {
1762 /* The index of the symbol, as stored in the relocation r_info, if
1763 we have a local symbol; -1 otherwise. */
1764 long symndx;
1765 union
1766 {
1767 /* The input bfd in which the symbol is defined, if it's a local
1768 symbol. */
1769 bfd *abfd;
1770 /* If symndx == -1, the hash table entry corresponding to a global
1771 symbol (even if it turns out to bind locally, in which case it
1772 should ideally be replaced with section's symndx + addend). */
1773 struct elf_link_hash_entry *h;
1774 } d;
1775 /* The addend of the relocation that references the symbol. */
1776 bfd_vma addend;
1777
1778 /* The fields above are used to identify an entry. The fields below
1779 contain information on how an entry is used and, later on, which
1780 locations it was assigned. */
1781 /* The following 2 fields record whether the symbol+addend above was
1782 ever referenced with a GOT relocation. The 17M4 suffix indicates a
1783 GOT17M4 relocation; hilo is used for GOTLO/GOTHI pairs. */
1784 unsigned got17m4;
1785 unsigned gothilo;
1786 /* Whether a FUNCDESC relocation references symbol+addend. */
1787 unsigned fd;
1788 /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
1789 unsigned fdgot17m4;
1790 unsigned fdgothilo;
1791 /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
1792 unsigned fdgoff17m4;
1793 unsigned fdgoffhilo;
1794 /* Whether symbol+addend is referenced with GOTOFF17M4, GOTOFFLO or
1795 GOTOFFHI relocations. The addend doesn't really matter, since we
1796 envision that this will only be used to check whether the symbol
1797 is mapped to the same segment as the got. */
1798 unsigned gotoff;
1799 /* Whether symbol+addend is referenced by a LABEL24 relocation. */
1800 unsigned call;
1801 /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
1802 relocation. */
1803 unsigned sym;
1804 /* Whether we need a PLT entry for a symbol. Should be implied by
1805 something like:
1806 (call && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h)) */
1807 unsigned plt:1;
1808 /* Whether a function descriptor should be created in this link unit
1809 for symbol+addend. Should be implied by something like:
1810 (plt || fdgotoff17m4 || fdgotofflohi
1811 || ((fd || fdgot17m4 || fdgothilo)
1812 && (symndx != -1 || BFINFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
1813 unsigned privfd:1;
1814 /* Whether a lazy PLT entry is needed for this symbol+addend.
1815 Should be implied by something like:
1816 (privfd && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h)
1817 && ! (info->flags & DF_BIND_NOW)) */
1818 unsigned lazyplt:1;
1819 /* Whether we've already emitted GOT relocations and PLT entries as
1820 needed for this symbol. */
1821 unsigned done:1;
1822
1823 /* The number of R_BFIN_BYTE4_DATA, R_BFIN_FUNCDESC and R_BFIN_FUNCDESC_VALUE
1824 relocations referencing the symbol. */
1825 unsigned relocs32, relocsfd, relocsfdv;
1826
1827 /* The number of .rofixups entries and dynamic relocations allocated
1828 for this symbol, minus any that might have already been used. */
1829 unsigned fixups, dynrelocs;
1830
1831 /* The offsets of the GOT entries assigned to symbol+addend, to the
1832 function descriptor's address, and to a function descriptor,
1833 respectively. Should be zero if unassigned. The offsets are
1834 counted from the value that will be assigned to the PIC register,
1835 not from the beginning of the .got section. */
1836 bfd_signed_vma got_entry, fdgot_entry, fd_entry;
1837 /* The offsets of the PLT entries assigned to symbol+addend,
1838 non-lazy and lazy, respectively. If unassigned, should be
1839 (bfd_vma)-1. */
1840 bfd_vma plt_entry, lzplt_entry;
1841 };
1842
1843 /* Compute a hash with the key fields of an bfinfdpic_relocs_info entry. */
1844 static hashval_t
1845 bfinfdpic_relocs_info_hash (const void *entry_)
1846 {
1847 const struct bfinfdpic_relocs_info *entry = entry_;
1848
1849 return (entry->symndx == -1
1850 ? (long) entry->d.h->root.root.hash
1851 : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
1852 }
1853
1854 /* Test whether the key fields of two bfinfdpic_relocs_info entries are
1855 identical. */
1856 static int
1857 bfinfdpic_relocs_info_eq (const void *entry1, const void *entry2)
1858 {
1859 const struct bfinfdpic_relocs_info *e1 = entry1;
1860 const struct bfinfdpic_relocs_info *e2 = entry2;
1861
1862 return e1->symndx == e2->symndx && e1->addend == e2->addend
1863 && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
1864 }
1865
1866 /* Find or create an entry in a hash table HT that matches the key
1867 fields of the given ENTRY. If it's not found, memory for a new
1868 entry is allocated in ABFD's obstack. */
1869 static struct bfinfdpic_relocs_info *
1870 bfinfdpic_relocs_info_find (struct htab *ht,
1871 bfd *abfd,
1872 const struct bfinfdpic_relocs_info *entry,
1873 enum insert_option insert)
1874 {
1875 struct bfinfdpic_relocs_info **loc;
1876
1877 if (!ht)
1878 return NULL;
1879
1880 loc = (struct bfinfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
1881
1882 if (! loc)
1883 return NULL;
1884
1885 if (*loc)
1886 return *loc;
1887
1888 *loc = bfd_zalloc (abfd, sizeof (**loc));
1889
1890 if (! *loc)
1891 return *loc;
1892
1893 (*loc)->symndx = entry->symndx;
1894 (*loc)->d = entry->d;
1895 (*loc)->addend = entry->addend;
1896 (*loc)->plt_entry = (bfd_vma)-1;
1897 (*loc)->lzplt_entry = (bfd_vma)-1;
1898
1899 return *loc;
1900 }
1901
1902 /* Obtain the address of the entry in HT associated with H's symbol +
1903 addend, creating a new entry if none existed. ABFD is only used
1904 for memory allocation purposes. */
1905 inline static struct bfinfdpic_relocs_info *
1906 bfinfdpic_relocs_info_for_global (struct htab *ht,
1907 bfd *abfd,
1908 struct elf_link_hash_entry *h,
1909 bfd_vma addend,
1910 enum insert_option insert)
1911 {
1912 struct bfinfdpic_relocs_info entry;
1913
1914 entry.symndx = -1;
1915 entry.d.h = h;
1916 entry.addend = addend;
1917
1918 return bfinfdpic_relocs_info_find (ht, abfd, &entry, insert);
1919 }
1920
1921 /* Obtain the address of the entry in HT associated with the SYMNDXth
1922 local symbol of the input bfd ABFD, plus the addend, creating a new
1923 entry if none existed. */
1924 inline static struct bfinfdpic_relocs_info *
1925 bfinfdpic_relocs_info_for_local (struct htab *ht,
1926 bfd *abfd,
1927 long symndx,
1928 bfd_vma addend,
1929 enum insert_option insert)
1930 {
1931 struct bfinfdpic_relocs_info entry;
1932
1933 entry.symndx = symndx;
1934 entry.d.abfd = abfd;
1935 entry.addend = addend;
1936
1937 return bfinfdpic_relocs_info_find (ht, abfd, &entry, insert);
1938 }
1939
1940 /* Merge fields set by check_relocs() of two entries that end up being
1941 mapped to the same (presumably global) symbol. */
1942
1943 inline static void
1944 bfinfdpic_pic_merge_early_relocs_info (struct bfinfdpic_relocs_info *e2,
1945 struct bfinfdpic_relocs_info const *e1)
1946 {
1947 e2->got17m4 |= e1->got17m4;
1948 e2->gothilo |= e1->gothilo;
1949 e2->fd |= e1->fd;
1950 e2->fdgot17m4 |= e1->fdgot17m4;
1951 e2->fdgothilo |= e1->fdgothilo;
1952 e2->fdgoff17m4 |= e1->fdgoff17m4;
1953 e2->fdgoffhilo |= e1->fdgoffhilo;
1954 e2->gotoff |= e1->gotoff;
1955 e2->call |= e1->call;
1956 e2->sym |= e1->sym;
1957 }
1958
1959 /* Every block of 65535 lazy PLT entries shares a single call to the
1960 resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
1961 32767, counting from 0). All other lazy PLT entries branch to it
1962 in a single instruction. */
1963
1964 #define LZPLT_RESOLVER_EXTRA 10
1965 #define LZPLT_NORMAL_SIZE 6
1966 #define LZPLT_ENTRIES 1362
1967
1968 #define BFINFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) LZPLT_NORMAL_SIZE * LZPLT_ENTRIES + LZPLT_RESOLVER_EXTRA)
1969 #define BFINFDPIC_LZPLT_RESOLV_LOC (LZPLT_NORMAL_SIZE * LZPLT_ENTRIES / 2)
1970
1971 /* Add a dynamic relocation to the SRELOC section. */
1972
1973 inline static bfd_vma
1974 _bfinfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
1975 int reloc_type, long dynindx, bfd_vma addend,
1976 struct bfinfdpic_relocs_info *entry)
1977 {
1978 Elf_Internal_Rela outrel;
1979 bfd_vma reloc_offset;
1980
1981 outrel.r_offset = offset;
1982 outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
1983 outrel.r_addend = addend;
1984
1985 reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
1986 BFD_ASSERT (reloc_offset < sreloc->size);
1987 bfd_elf32_swap_reloc_out (output_bfd, &outrel,
1988 sreloc->contents + reloc_offset);
1989 sreloc->reloc_count++;
1990
1991 /* If the entry's index is zero, this relocation was probably to a
1992 linkonce section that got discarded. We reserved a dynamic
1993 relocation, but it was for another entry than the one we got at
1994 the time of emitting the relocation. Unfortunately there's no
1995 simple way for us to catch this situation, since the relocation
1996 is cleared right before calling relocate_section, at which point
1997 we no longer know what the relocation used to point to. */
1998 if (entry->symndx)
1999 {
2000 BFD_ASSERT (entry->dynrelocs > 0);
2001 entry->dynrelocs--;
2002 }
2003
2004 return reloc_offset;
2005 }
2006
2007 /* Add a fixup to the ROFIXUP section. */
2008
2009 static bfd_vma
2010 _bfinfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
2011 struct bfinfdpic_relocs_info *entry)
2012 {
2013 bfd_vma fixup_offset;
2014
2015 if (rofixup->flags & SEC_EXCLUDE)
2016 return -1;
2017
2018 fixup_offset = rofixup->reloc_count * 4;
2019 if (rofixup->contents)
2020 {
2021 BFD_ASSERT (fixup_offset < rofixup->size);
2022 bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
2023 }
2024 rofixup->reloc_count++;
2025
2026 if (entry && entry->symndx)
2027 {
2028 /* See discussion about symndx == 0 in _bfinfdpic_add_dyn_reloc
2029 above. */
2030 BFD_ASSERT (entry->fixups > 0);
2031 entry->fixups--;
2032 }
2033
2034 return fixup_offset;
2035 }
2036
2037 /* Find the segment number in which OSEC, and output section, is
2038 located. */
2039
2040 static unsigned
2041 _bfinfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
2042 {
2043 Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
2044
2045 return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
2046 }
2047
2048 inline static bfd_boolean
2049 _bfinfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
2050 {
2051 unsigned seg = _bfinfdpic_osec_to_segment (output_bfd, osec);
2052
2053 return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
2054 }
2055
2056 /* Generate relocations for GOT entries, function descriptors, and
2057 code for PLT and lazy PLT entries. */
2058
2059 inline static bfd_boolean
2060 _bfinfdpic_emit_got_relocs_plt_entries (struct bfinfdpic_relocs_info *entry,
2061 bfd *output_bfd,
2062 struct bfd_link_info *info,
2063 asection *sec,
2064 Elf_Internal_Sym *sym,
2065 bfd_vma addend)
2066 {
2067 bfd_vma fd_lazy_rel_offset = (bfd_vma) -1;
2068 int dynindx = -1;
2069
2070 if (entry->done)
2071 return TRUE;
2072 entry->done = 1;
2073
2074 if (entry->got_entry || entry->fdgot_entry || entry->fd_entry)
2075 {
2076 /* If the symbol is dynamic, consider it for dynamic
2077 relocations, otherwise decay to section + offset. */
2078 if (entry->symndx == -1 && entry->d.h->dynindx != -1)
2079 dynindx = entry->d.h->dynindx;
2080 else
2081 {
2082 if (sec
2083 && sec->output_section
2084 && ! bfd_is_abs_section (sec->output_section)
2085 && ! bfd_is_und_section (sec->output_section))
2086 dynindx = elf_section_data (sec->output_section)->dynindx;
2087 else
2088 dynindx = 0;
2089 }
2090 }
2091
2092 /* Generate relocation for GOT entry pointing to the symbol. */
2093 if (entry->got_entry)
2094 {
2095 int idx = dynindx;
2096 bfd_vma ad = addend;
2097
2098 /* If the symbol is dynamic but binds locally, use
2099 section+offset. */
2100 if (sec && (entry->symndx != -1
2101 || BFINFDPIC_SYM_LOCAL (info, entry->d.h)))
2102 {
2103 if (entry->symndx == -1)
2104 ad += entry->d.h->root.u.def.value;
2105 else
2106 ad += sym->st_value;
2107 ad += sec->output_offset;
2108 if (sec->output_section && elf_section_data (sec->output_section))
2109 idx = elf_section_data (sec->output_section)->dynindx;
2110 else
2111 idx = 0;
2112 }
2113
2114 /* If we're linking an executable at a fixed address, we can
2115 omit the dynamic relocation as long as the symbol is local to
2116 this module. */
2117 if (bfd_link_pde (info)
2118 && (entry->symndx != -1
2119 || BFINFDPIC_SYM_LOCAL (info, entry->d.h)))
2120 {
2121 if (sec)
2122 ad += sec->output_section->vma;
2123 if (entry->symndx != -1
2124 || entry->d.h->root.type != bfd_link_hash_undefweak)
2125 _bfinfdpic_add_rofixup (output_bfd,
2126 bfinfdpic_gotfixup_section (info),
2127 bfinfdpic_got_section (info)->output_section
2128 ->vma
2129 + bfinfdpic_got_section (info)->output_offset
2130 + bfinfdpic_got_initial_offset (info)
2131 + entry->got_entry, entry);
2132 }
2133 else
2134 _bfinfdpic_add_dyn_reloc (output_bfd, bfinfdpic_gotrel_section (info),
2135 _bfd_elf_section_offset
2136 (output_bfd, info,
2137 bfinfdpic_got_section (info),
2138 bfinfdpic_got_initial_offset (info)
2139 + entry->got_entry)
2140 + bfinfdpic_got_section (info)
2141 ->output_section->vma
2142 + bfinfdpic_got_section (info)->output_offset,
2143 R_BFIN_BYTE4_DATA, idx, ad, entry);
2144
2145 bfd_put_32 (output_bfd, ad,
2146 bfinfdpic_got_section (info)->contents
2147 + bfinfdpic_got_initial_offset (info)
2148 + entry->got_entry);
2149 }
2150
2151 /* Generate relocation for GOT entry pointing to a canonical
2152 function descriptor. */
2153 if (entry->fdgot_entry)
2154 {
2155 int reloc, idx;
2156 bfd_vma ad = 0;
2157
2158 if (! (entry->symndx == -1
2159 && entry->d.h->root.type == bfd_link_hash_undefweak
2160 && BFINFDPIC_SYM_LOCAL (info, entry->d.h)))
2161 {
2162 /* If the symbol is dynamic and there may be dynamic symbol
2163 resolution because we are, or are linked with, a shared
2164 library, emit a FUNCDESC relocation such that the dynamic
2165 linker will allocate the function descriptor. If the
2166 symbol needs a non-local function descriptor but binds
2167 locally (e.g., its visibility is protected, emit a
2168 dynamic relocation decayed to section+offset. */
2169 if (entry->symndx == -1
2170 && ! BFINFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
2171 && BFINFDPIC_SYM_LOCAL (info, entry->d.h)
2172 && !bfd_link_pde (info))
2173 {
2174 reloc = R_BFIN_FUNCDESC;
2175 idx = elf_section_data (entry->d.h->root.u.def.section
2176 ->output_section)->dynindx;
2177 ad = entry->d.h->root.u.def.section->output_offset
2178 + entry->d.h->root.u.def.value;
2179 }
2180 else if (entry->symndx == -1
2181 && ! BFINFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
2182 {
2183 reloc = R_BFIN_FUNCDESC;
2184 idx = dynindx;
2185 ad = addend;
2186 if (ad)
2187 return FALSE;
2188 }
2189 else
2190 {
2191 /* Otherwise, we know we have a private function descriptor,
2192 so reference it directly. */
2193 if (elf_hash_table (info)->dynamic_sections_created)
2194 BFD_ASSERT (entry->privfd);
2195 reloc = R_BFIN_BYTE4_DATA;
2196 idx = elf_section_data (bfinfdpic_got_section (info)
2197 ->output_section)->dynindx;
2198 ad = bfinfdpic_got_section (info)->output_offset
2199 + bfinfdpic_got_initial_offset (info) + entry->fd_entry;
2200 }
2201
2202 /* If there is room for dynamic symbol resolution, emit the
2203 dynamic relocation. However, if we're linking an
2204 executable at a fixed location, we won't have emitted a
2205 dynamic symbol entry for the got section, so idx will be
2206 zero, which means we can and should compute the address
2207 of the private descriptor ourselves. */
2208 if (bfd_link_pde (info)
2209 && (entry->symndx != -1
2210 || BFINFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
2211 {
2212 ad += bfinfdpic_got_section (info)->output_section->vma;
2213 _bfinfdpic_add_rofixup (output_bfd,
2214 bfinfdpic_gotfixup_section (info),
2215 bfinfdpic_got_section (info)
2216 ->output_section->vma
2217 + bfinfdpic_got_section (info)
2218 ->output_offset
2219 + bfinfdpic_got_initial_offset (info)
2220 + entry->fdgot_entry, entry);
2221 }
2222 else
2223 _bfinfdpic_add_dyn_reloc (output_bfd,
2224 bfinfdpic_gotrel_section (info),
2225 _bfd_elf_section_offset
2226 (output_bfd, info,
2227 bfinfdpic_got_section (info),
2228 bfinfdpic_got_initial_offset (info)
2229 + entry->fdgot_entry)
2230 + bfinfdpic_got_section (info)
2231 ->output_section->vma
2232 + bfinfdpic_got_section (info)
2233 ->output_offset,
2234 reloc, idx, ad, entry);
2235 }
2236
2237 bfd_put_32 (output_bfd, ad,
2238 bfinfdpic_got_section (info)->contents
2239 + bfinfdpic_got_initial_offset (info)
2240 + entry->fdgot_entry);
2241 }
2242
2243 /* Generate relocation to fill in a private function descriptor in
2244 the GOT. */
2245 if (entry->fd_entry)
2246 {
2247 int idx = dynindx;
2248 bfd_vma ad = addend;
2249 bfd_vma ofst;
2250 long lowword, highword;
2251
2252 /* If the symbol is dynamic but binds locally, use
2253 section+offset. */
2254 if (sec && (entry->symndx != -1
2255 || BFINFDPIC_SYM_LOCAL (info, entry->d.h)))
2256 {
2257 if (entry->symndx == -1)
2258 ad += entry->d.h->root.u.def.value;
2259 else
2260 ad += sym->st_value;
2261 ad += sec->output_offset;
2262 if (sec->output_section && elf_section_data (sec->output_section))
2263 idx = elf_section_data (sec->output_section)->dynindx;
2264 else
2265 idx = 0;
2266 }
2267
2268 /* If we're linking an executable at a fixed address, we can
2269 omit the dynamic relocation as long as the symbol is local to
2270 this module. */
2271 if (bfd_link_pde (info)
2272 && (entry->symndx != -1 || BFINFDPIC_SYM_LOCAL (info, entry->d.h)))
2273 {
2274 if (sec)
2275 ad += sec->output_section->vma;
2276 ofst = 0;
2277 if (entry->symndx != -1
2278 || entry->d.h->root.type != bfd_link_hash_undefweak)
2279 {
2280 _bfinfdpic_add_rofixup (output_bfd,
2281 bfinfdpic_gotfixup_section (info),
2282 bfinfdpic_got_section (info)
2283 ->output_section->vma
2284 + bfinfdpic_got_section (info)
2285 ->output_offset
2286 + bfinfdpic_got_initial_offset (info)
2287 + entry->fd_entry, entry);
2288 _bfinfdpic_add_rofixup (output_bfd,
2289 bfinfdpic_gotfixup_section (info),
2290 bfinfdpic_got_section (info)
2291 ->output_section->vma
2292 + bfinfdpic_got_section (info)
2293 ->output_offset
2294 + bfinfdpic_got_initial_offset (info)
2295 + entry->fd_entry + 4, entry);
2296 }
2297 }
2298 else
2299 {
2300 ofst
2301 = _bfinfdpic_add_dyn_reloc (output_bfd,
2302 entry->lazyplt
2303 ? bfinfdpic_pltrel_section (info)
2304 : bfinfdpic_gotrel_section (info),
2305 _bfd_elf_section_offset
2306 (output_bfd, info,
2307 bfinfdpic_got_section (info),
2308 bfinfdpic_got_initial_offset (info)
2309 + entry->fd_entry)
2310 + bfinfdpic_got_section (info)
2311 ->output_section->vma
2312 + bfinfdpic_got_section (info)
2313 ->output_offset,
2314 R_BFIN_FUNCDESC_VALUE, idx, ad, entry);
2315 }
2316
2317 /* If we've omitted the dynamic relocation, just emit the fixed
2318 addresses of the symbol and of the local GOT base offset. */
2319 if (bfd_link_pde (info)
2320 && sec
2321 && sec->output_section)
2322 {
2323 lowword = ad;
2324 highword = bfinfdpic_got_section (info)->output_section->vma
2325 + bfinfdpic_got_section (info)->output_offset
2326 + bfinfdpic_got_initial_offset (info);
2327 }
2328 else if (entry->lazyplt)
2329 {
2330 if (ad)
2331 return FALSE;
2332
2333 fd_lazy_rel_offset = ofst;
2334
2335 /* A function descriptor used for lazy or local resolving is
2336 initialized such that its high word contains the output
2337 section index in which the PLT entries are located, and
2338 the low word contains the address of the lazy PLT entry
2339 entry point, that must be within the memory region
2340 assigned to that section. */
2341 lowword = entry->lzplt_entry + 4
2342 + bfinfdpic_plt_section (info)->output_offset
2343 + bfinfdpic_plt_section (info)->output_section->vma;
2344 highword = _bfinfdpic_osec_to_segment
2345 (output_bfd, bfinfdpic_plt_section (info)->output_section);
2346 }
2347 else
2348 {
2349 /* A function descriptor for a local function gets the index
2350 of the section. For a non-local function, it's
2351 disregarded. */
2352 lowword = ad;
2353 if (sec == NULL
2354 || (entry->symndx == -1 && entry->d.h->dynindx != -1
2355 && entry->d.h->dynindx == idx))
2356 highword = 0;
2357 else
2358 highword = _bfinfdpic_osec_to_segment
2359 (output_bfd, sec->output_section);
2360 }
2361
2362 bfd_put_32 (output_bfd, lowword,
2363 bfinfdpic_got_section (info)->contents
2364 + bfinfdpic_got_initial_offset (info)
2365 + entry->fd_entry);
2366 bfd_put_32 (output_bfd, highword,
2367 bfinfdpic_got_section (info)->contents
2368 + bfinfdpic_got_initial_offset (info)
2369 + entry->fd_entry + 4);
2370 }
2371
2372 /* Generate code for the PLT entry. */
2373 if (entry->plt_entry != (bfd_vma) -1)
2374 {
2375 bfd_byte *plt_code = bfinfdpic_plt_section (info)->contents
2376 + entry->plt_entry;
2377
2378 BFD_ASSERT (entry->fd_entry);
2379
2380 /* Figure out what kind of PLT entry we need, depending on the
2381 location of the function descriptor within the GOT. */
2382 if (entry->fd_entry >= -(1 << (18 - 1))
2383 && entry->fd_entry + 4 < (1 << (18 - 1)))
2384 {
2385 /* P1 = [P3 + fd_entry]; P3 = [P3 + fd_entry + 4] */
2386 bfd_put_32 (output_bfd,
2387 0xe519 | ((entry->fd_entry << 14) & 0xFFFF0000),
2388 plt_code);
2389 bfd_put_32 (output_bfd,
2390 0xe51b | (((entry->fd_entry + 4) << 14) & 0xFFFF0000),
2391 plt_code + 4);
2392 plt_code += 8;
2393 }
2394 else
2395 {
2396 /* P1.L = fd_entry; P1.H = fd_entry;
2397 P3 = P3 + P1;
2398 P1 = [P3];
2399 P3 = [P3 + 4]; */
2400 bfd_put_32 (output_bfd,
2401 0xe109 | (entry->fd_entry << 16),
2402 plt_code);
2403 bfd_put_32 (output_bfd,
2404 0xe149 | (entry->fd_entry & 0xFFFF0000),
2405 plt_code + 4);
2406 bfd_put_16 (output_bfd, 0x5ad9, plt_code + 8);
2407 bfd_put_16 (output_bfd, 0x9159, plt_code + 10);
2408 bfd_put_16 (output_bfd, 0xac5b, plt_code + 12);
2409 plt_code += 14;
2410 }
2411 /* JUMP (P1) */
2412 bfd_put_16 (output_bfd, 0x0051, plt_code);
2413 }
2414
2415 /* Generate code for the lazy PLT entry. */
2416 if (entry->lzplt_entry != (bfd_vma) -1)
2417 {
2418 bfd_byte *lzplt_code = bfinfdpic_plt_section (info)->contents
2419 + entry->lzplt_entry;
2420 bfd_vma resolverStub_addr;
2421
2422 bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
2423 lzplt_code += 4;
2424
2425 resolverStub_addr = entry->lzplt_entry / BFINFDPIC_LZPLT_BLOCK_SIZE
2426 * BFINFDPIC_LZPLT_BLOCK_SIZE + BFINFDPIC_LZPLT_RESOLV_LOC;
2427 if (resolverStub_addr >= bfinfdpic_plt_initial_offset (info))
2428 resolverStub_addr = bfinfdpic_plt_initial_offset (info) - LZPLT_NORMAL_SIZE - LZPLT_RESOLVER_EXTRA;
2429
2430 if (entry->lzplt_entry == resolverStub_addr)
2431 {
2432 /* This is a lazy PLT entry that includes a resolver call.
2433 P2 = [P3];
2434 R3 = [P3 + 4];
2435 JUMP (P2); */
2436 bfd_put_32 (output_bfd,
2437 0xa05b915a,
2438 lzplt_code);
2439 bfd_put_16 (output_bfd, 0x0052, lzplt_code + 4);
2440 }
2441 else
2442 {
2443 /* JUMP.S resolverStub */
2444 bfd_put_16 (output_bfd,
2445 0x2000
2446 | (((resolverStub_addr - entry->lzplt_entry)
2447 / 2) & (((bfd_vma)1 << 12) - 1)),
2448 lzplt_code);
2449 }
2450 }
2451
2452 return TRUE;
2453 }
2454 \f
2455 /* Relocate an Blackfin ELF section.
2456
2457 The RELOCATE_SECTION function is called by the new ELF backend linker
2458 to handle the relocations for a section.
2459
2460 The relocs are always passed as Rela structures; if the section
2461 actually uses Rel structures, the r_addend field will always be
2462 zero.
2463
2464 This function is responsible for adjusting the section contents as
2465 necessary, and (if using Rela relocs and generating a relocatable
2466 output file) adjusting the reloc addend as necessary.
2467
2468 This function does not have to worry about setting the reloc
2469 address or the reloc symbol index.
2470
2471 LOCAL_SYMS is a pointer to the swapped in local symbols.
2472
2473 LOCAL_SECTIONS is an array giving the section in the input file
2474 corresponding to the st_shndx field of each local symbol.
2475
2476 The global hash table entry for the global symbols can be found
2477 via elf_sym_hashes (input_bfd).
2478
2479 When generating relocatable output, this function must handle
2480 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2481 going to be the section symbol corresponding to the output
2482 section, which means that the addend must be adjusted
2483 accordingly. */
2484
2485 static bfd_boolean
2486 bfinfdpic_relocate_section (bfd * output_bfd,
2487 struct bfd_link_info *info,
2488 bfd * input_bfd,
2489 asection * input_section,
2490 bfd_byte * contents,
2491 Elf_Internal_Rela * relocs,
2492 Elf_Internal_Sym * local_syms,
2493 asection ** local_sections)
2494 {
2495 Elf_Internal_Shdr *symtab_hdr;
2496 struct elf_link_hash_entry **sym_hashes;
2497 Elf_Internal_Rela *rel;
2498 Elf_Internal_Rela *relend;
2499 unsigned isec_segment, got_segment, plt_segment,
2500 check_segment[2];
2501 int silence_segment_error = !bfd_link_pic (info);
2502
2503 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2504 sym_hashes = elf_sym_hashes (input_bfd);
2505 relend = relocs + input_section->reloc_count;
2506
2507 isec_segment = _bfinfdpic_osec_to_segment (output_bfd,
2508 input_section->output_section);
2509 if (IS_FDPIC (output_bfd) && bfinfdpic_got_section (info))
2510 got_segment = _bfinfdpic_osec_to_segment (output_bfd,
2511 bfinfdpic_got_section (info)
2512 ->output_section);
2513 else
2514 got_segment = -1;
2515 if (IS_FDPIC (output_bfd) && elf_hash_table (info)->dynamic_sections_created)
2516 plt_segment = _bfinfdpic_osec_to_segment (output_bfd,
2517 bfinfdpic_plt_section (info)
2518 ->output_section);
2519 else
2520 plt_segment = -1;
2521
2522 for (rel = relocs; rel < relend; rel ++)
2523 {
2524 reloc_howto_type *howto;
2525 unsigned long r_symndx;
2526 Elf_Internal_Sym *sym;
2527 asection *sec;
2528 struct elf_link_hash_entry *h;
2529 bfd_vma relocation;
2530 bfd_reloc_status_type r;
2531 const char * name = NULL;
2532 int r_type;
2533 asection *osec;
2534 struct bfinfdpic_relocs_info *picrel;
2535 bfd_vma orig_addend = rel->r_addend;
2536
2537 r_type = ELF32_R_TYPE (rel->r_info);
2538
2539 if (r_type == R_BFIN_GNU_VTINHERIT
2540 || r_type == R_BFIN_GNU_VTENTRY)
2541 continue;
2542
2543 r_symndx = ELF32_R_SYM (rel->r_info);
2544 howto = bfin_reloc_type_lookup (input_bfd, r_type);
2545 if (howto == NULL)
2546 {
2547 bfd_set_error (bfd_error_bad_value);
2548 return FALSE;
2549 }
2550
2551 h = NULL;
2552 sym = NULL;
2553 sec = NULL;
2554
2555 if (r_symndx < symtab_hdr->sh_info)
2556 {
2557 sym = local_syms + r_symndx;
2558 osec = sec = local_sections [r_symndx];
2559 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2560
2561 name = bfd_elf_string_from_elf_section
2562 (input_bfd, symtab_hdr->sh_link, sym->st_name);
2563 name = name == NULL ? bfd_section_name (sec) : name;
2564 }
2565 else
2566 {
2567 bfd_boolean warned, ignored;
2568 bfd_boolean unresolved_reloc;
2569
2570 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2571 r_symndx, symtab_hdr, sym_hashes,
2572 h, sec, relocation,
2573 unresolved_reloc, warned, ignored);
2574 osec = sec;
2575 }
2576
2577 if (sec != NULL && discarded_section (sec))
2578 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2579 rel, 1, relend, howto, 0, contents);
2580
2581 if (bfd_link_relocatable (info))
2582 continue;
2583
2584 if (h != NULL
2585 && (h->root.type == bfd_link_hash_defined
2586 || h->root.type == bfd_link_hash_defweak)
2587 && !BFINFDPIC_SYM_LOCAL (info, h))
2588 {
2589 osec = sec = NULL;
2590 relocation = 0;
2591 }
2592
2593 switch (r_type)
2594 {
2595 case R_BFIN_PCREL24:
2596 case R_BFIN_PCREL24_JUMP_L:
2597 case R_BFIN_BYTE4_DATA:
2598 if (! IS_FDPIC (output_bfd))
2599 goto non_fdpic;
2600 /* Fall through. */
2601
2602 case R_BFIN_GOT17M4:
2603 case R_BFIN_GOTHI:
2604 case R_BFIN_GOTLO:
2605 case R_BFIN_FUNCDESC_GOT17M4:
2606 case R_BFIN_FUNCDESC_GOTHI:
2607 case R_BFIN_FUNCDESC_GOTLO:
2608 case R_BFIN_GOTOFF17M4:
2609 case R_BFIN_GOTOFFHI:
2610 case R_BFIN_GOTOFFLO:
2611 case R_BFIN_FUNCDESC_GOTOFF17M4:
2612 case R_BFIN_FUNCDESC_GOTOFFHI:
2613 case R_BFIN_FUNCDESC_GOTOFFLO:
2614 case R_BFIN_FUNCDESC:
2615 case R_BFIN_FUNCDESC_VALUE:
2616 if (h != NULL)
2617 picrel = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info
2618 (info), input_bfd, h,
2619 orig_addend, INSERT);
2620 else
2621 /* In order to find the entry we created before, we must
2622 use the original addend, not the one that may have been
2623 modified by _bfd_elf_rela_local_sym(). */
2624 picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info
2625 (info), input_bfd, r_symndx,
2626 orig_addend, INSERT);
2627 if (! picrel)
2628 return FALSE;
2629
2630 if (!_bfinfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
2631 osec, sym,
2632 rel->r_addend))
2633 {
2634 _bfd_error_handler
2635 /* xgettext:c-format */
2636 (_("%pB: relocation at `%pA+%#" PRIx64 "' "
2637 "references symbol `%s' with nonzero addend"),
2638 input_bfd, input_section, (uint64_t) rel->r_offset, name);
2639 return FALSE;
2640
2641 }
2642
2643 break;
2644
2645 default:
2646 non_fdpic:
2647 picrel = NULL;
2648 if (h && ! BFINFDPIC_SYM_LOCAL (info, h)
2649 && _bfd_elf_section_offset (output_bfd, info, input_section,
2650 rel->r_offset) != (bfd_vma) -1)
2651 {
2652 info->callbacks->warning
2653 (info, _("relocation references symbol not defined in the module"),
2654 name, input_bfd, input_section, rel->r_offset);
2655 return FALSE;
2656 }
2657 break;
2658 }
2659
2660 switch (r_type)
2661 {
2662 case R_BFIN_PCREL24:
2663 case R_BFIN_PCREL24_JUMP_L:
2664 check_segment[0] = isec_segment;
2665 if (! IS_FDPIC (output_bfd))
2666 check_segment[1] = isec_segment;
2667 else if (picrel->plt)
2668 {
2669 relocation = bfinfdpic_plt_section (info)->output_section->vma
2670 + bfinfdpic_plt_section (info)->output_offset
2671 + picrel->plt_entry;
2672 check_segment[1] = plt_segment;
2673 }
2674 /* We don't want to warn on calls to undefined weak symbols,
2675 as calls to them must be protected by non-NULL tests
2676 anyway, and unprotected calls would invoke undefined
2677 behavior. */
2678 else if (picrel->symndx == -1
2679 && picrel->d.h->root.type == bfd_link_hash_undefweak)
2680 check_segment[1] = check_segment[0];
2681 else
2682 check_segment[1] = sec
2683 ? _bfinfdpic_osec_to_segment (output_bfd, sec->output_section)
2684 : (unsigned)-1;
2685 break;
2686
2687 case R_BFIN_GOT17M4:
2688 case R_BFIN_GOTHI:
2689 case R_BFIN_GOTLO:
2690 relocation = picrel->got_entry;
2691 check_segment[0] = check_segment[1] = got_segment;
2692 break;
2693
2694 case R_BFIN_FUNCDESC_GOT17M4:
2695 case R_BFIN_FUNCDESC_GOTHI:
2696 case R_BFIN_FUNCDESC_GOTLO:
2697 relocation = picrel->fdgot_entry;
2698 check_segment[0] = check_segment[1] = got_segment;
2699 break;
2700
2701 case R_BFIN_GOTOFFHI:
2702 case R_BFIN_GOTOFF17M4:
2703 case R_BFIN_GOTOFFLO:
2704 relocation -= bfinfdpic_got_section (info)->output_section->vma
2705 + bfinfdpic_got_section (info)->output_offset
2706 + bfinfdpic_got_initial_offset (info);
2707 check_segment[0] = got_segment;
2708 check_segment[1] = sec
2709 ? _bfinfdpic_osec_to_segment (output_bfd, sec->output_section)
2710 : (unsigned)-1;
2711 break;
2712
2713 case R_BFIN_FUNCDESC_GOTOFF17M4:
2714 case R_BFIN_FUNCDESC_GOTOFFHI:
2715 case R_BFIN_FUNCDESC_GOTOFFLO:
2716 relocation = picrel->fd_entry;
2717 check_segment[0] = check_segment[1] = got_segment;
2718 break;
2719
2720 case R_BFIN_FUNCDESC:
2721 {
2722 int dynindx;
2723 bfd_vma addend = rel->r_addend;
2724
2725 if (! (h && h->root.type == bfd_link_hash_undefweak
2726 && BFINFDPIC_SYM_LOCAL (info, h)))
2727 {
2728 /* If the symbol is dynamic and there may be dynamic
2729 symbol resolution because we are or are linked with a
2730 shared library, emit a FUNCDESC relocation such that
2731 the dynamic linker will allocate the function
2732 descriptor. If the symbol needs a non-local function
2733 descriptor but binds locally (e.g., its visibility is
2734 protected, emit a dynamic relocation decayed to
2735 section+offset. */
2736 if (h && ! BFINFDPIC_FUNCDESC_LOCAL (info, h)
2737 && BFINFDPIC_SYM_LOCAL (info, h)
2738 && !bfd_link_pde (info))
2739 {
2740 dynindx = elf_section_data (h->root.u.def.section
2741 ->output_section)->dynindx;
2742 addend += h->root.u.def.section->output_offset
2743 + h->root.u.def.value;
2744 }
2745 else if (h && ! BFINFDPIC_FUNCDESC_LOCAL (info, h))
2746 {
2747 if (addend)
2748 {
2749 info->callbacks->warning
2750 (info, _("R_BFIN_FUNCDESC references dynamic symbol with nonzero addend"),
2751 name, input_bfd, input_section, rel->r_offset);
2752 return FALSE;
2753 }
2754 dynindx = h->dynindx;
2755 }
2756 else
2757 {
2758 /* Otherwise, we know we have a private function
2759 descriptor, so reference it directly. */
2760 BFD_ASSERT (picrel->privfd);
2761 r_type = R_BFIN_BYTE4_DATA;
2762 dynindx = elf_section_data (bfinfdpic_got_section (info)
2763 ->output_section)->dynindx;
2764 addend = bfinfdpic_got_section (info)->output_offset
2765 + bfinfdpic_got_initial_offset (info)
2766 + picrel->fd_entry;
2767 }
2768
2769 /* If there is room for dynamic symbol resolution, emit
2770 the dynamic relocation. However, if we're linking an
2771 executable at a fixed location, we won't have emitted a
2772 dynamic symbol entry for the got section, so idx will
2773 be zero, which means we can and should compute the
2774 address of the private descriptor ourselves. */
2775 if (bfd_link_pde (info)
2776 && (!h || BFINFDPIC_FUNCDESC_LOCAL (info, h)))
2777 {
2778 bfd_vma offset;
2779
2780 addend += bfinfdpic_got_section (info)->output_section->vma;
2781 if ((bfd_section_flags (input_section->output_section)
2782 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2783 {
2784 if (_bfinfdpic_osec_readonly_p (output_bfd,
2785 input_section
2786 ->output_section))
2787 {
2788 info->callbacks->warning
2789 (info,
2790 _("cannot emit fixups in read-only section"),
2791 name, input_bfd, input_section, rel->r_offset);
2792 return FALSE;
2793 }
2794
2795 offset = _bfd_elf_section_offset
2796 (output_bfd, info,
2797 input_section, rel->r_offset);
2798
2799 if (offset != (bfd_vma)-1)
2800 _bfinfdpic_add_rofixup (output_bfd,
2801 bfinfdpic_gotfixup_section
2802 (info),
2803 offset + input_section
2804 ->output_section->vma
2805 + input_section->output_offset,
2806 picrel);
2807 }
2808 }
2809 else if ((bfd_section_flags (input_section->output_section)
2810 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2811 {
2812 bfd_vma offset;
2813
2814 if (_bfinfdpic_osec_readonly_p (output_bfd,
2815 input_section
2816 ->output_section))
2817 {
2818 info->callbacks->warning
2819 (info,
2820 _("cannot emit dynamic relocations in read-only section"),
2821 name, input_bfd, input_section, rel->r_offset);
2822 return FALSE;
2823 }
2824 offset = _bfd_elf_section_offset (output_bfd, info,
2825 input_section, rel->r_offset);
2826
2827 if (offset != (bfd_vma)-1)
2828 _bfinfdpic_add_dyn_reloc (output_bfd,
2829 bfinfdpic_gotrel_section (info),
2830 offset + input_section
2831 ->output_section->vma
2832 + input_section->output_offset,
2833 r_type,
2834 dynindx, addend, picrel);
2835 }
2836 else
2837 addend += bfinfdpic_got_section (info)->output_section->vma;
2838 }
2839
2840 /* We want the addend in-place because dynamic
2841 relocations are REL. Setting relocation to it should
2842 arrange for it to be installed. */
2843 relocation = addend - rel->r_addend;
2844 }
2845 check_segment[0] = check_segment[1] = got_segment;
2846 break;
2847
2848 case R_BFIN_BYTE4_DATA:
2849 if (! IS_FDPIC (output_bfd))
2850 {
2851 check_segment[0] = check_segment[1] = -1;
2852 break;
2853 }
2854 /* Fall through. */
2855 case R_BFIN_FUNCDESC_VALUE:
2856 {
2857 int dynindx;
2858 bfd_vma addend = rel->r_addend;
2859 bfd_vma offset;
2860 offset = _bfd_elf_section_offset (output_bfd, info,
2861 input_section, rel->r_offset);
2862
2863 /* If the symbol is dynamic but binds locally, use
2864 section+offset. */
2865 if (h && ! BFINFDPIC_SYM_LOCAL (info, h))
2866 {
2867 if (addend && r_type == R_BFIN_FUNCDESC_VALUE)
2868 {
2869 info->callbacks->warning
2870 (info, _("R_BFIN_FUNCDESC_VALUE references dynamic symbol with nonzero addend"),
2871 name, input_bfd, input_section, rel->r_offset);
2872 return FALSE;
2873 }
2874 dynindx = h->dynindx;
2875 }
2876 else
2877 {
2878 if (h)
2879 addend += h->root.u.def.value;
2880 else
2881 addend += sym->st_value;
2882 if (osec)
2883 addend += osec->output_offset;
2884 if (osec && osec->output_section
2885 && ! bfd_is_abs_section (osec->output_section)
2886 && ! bfd_is_und_section (osec->output_section))
2887 dynindx = elf_section_data (osec->output_section)->dynindx;
2888 else
2889 dynindx = 0;
2890 }
2891
2892 /* If we're linking an executable at a fixed address, we
2893 can omit the dynamic relocation as long as the symbol
2894 is defined in the current link unit (which is implied
2895 by its output section not being NULL). */
2896 if (bfd_link_pde (info)
2897 && (!h || BFINFDPIC_SYM_LOCAL (info, h)))
2898 {
2899 if (osec)
2900 addend += osec->output_section->vma;
2901 if (IS_FDPIC (input_bfd)
2902 && (bfd_section_flags (input_section->output_section)
2903 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2904 {
2905 if (_bfinfdpic_osec_readonly_p (output_bfd,
2906 input_section
2907 ->output_section))
2908 {
2909 info->callbacks->warning
2910 (info,
2911 _("cannot emit fixups in read-only section"),
2912 name, input_bfd, input_section, rel->r_offset);
2913 return FALSE;
2914 }
2915 if (!h || h->root.type != bfd_link_hash_undefweak)
2916 {
2917 if (offset != (bfd_vma)-1)
2918 {
2919 _bfinfdpic_add_rofixup (output_bfd,
2920 bfinfdpic_gotfixup_section
2921 (info),
2922 offset + input_section
2923 ->output_section->vma
2924 + input_section->output_offset,
2925 picrel);
2926
2927 if (r_type == R_BFIN_FUNCDESC_VALUE)
2928 _bfinfdpic_add_rofixup
2929 (output_bfd,
2930 bfinfdpic_gotfixup_section (info),
2931 offset + input_section->output_section->vma
2932 + input_section->output_offset + 4, picrel);
2933 }
2934 }
2935 }
2936 }
2937 else
2938 {
2939 if ((bfd_section_flags (input_section->output_section)
2940 & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
2941 {
2942 if (_bfinfdpic_osec_readonly_p (output_bfd,
2943 input_section
2944 ->output_section))
2945 {
2946 info->callbacks->warning
2947 (info,
2948 _("cannot emit dynamic relocations in read-only section"),
2949 name, input_bfd, input_section, rel->r_offset);
2950 return FALSE;
2951 }
2952
2953 if (offset != (bfd_vma)-1)
2954 _bfinfdpic_add_dyn_reloc (output_bfd,
2955 bfinfdpic_gotrel_section (info),
2956 offset
2957 + input_section->output_section->vma
2958 + input_section->output_offset,
2959 r_type, dynindx, addend, picrel);
2960 }
2961 else if (osec)
2962 addend += osec->output_section->vma;
2963 /* We want the addend in-place because dynamic
2964 relocations are REL. Setting relocation to it
2965 should arrange for it to be installed. */
2966 relocation = addend - rel->r_addend;
2967 }
2968
2969 if (r_type == R_BFIN_FUNCDESC_VALUE)
2970 {
2971 /* If we've omitted the dynamic relocation, just emit
2972 the fixed addresses of the symbol and of the local
2973 GOT base offset. */
2974 if (bfd_link_pde (info)
2975 && (!h || BFINFDPIC_SYM_LOCAL (info, h)))
2976 bfd_put_32 (output_bfd,
2977 bfinfdpic_got_section (info)->output_section->vma
2978 + bfinfdpic_got_section (info)->output_offset
2979 + bfinfdpic_got_initial_offset (info),
2980 contents + rel->r_offset + 4);
2981 else
2982 /* A function descriptor used for lazy or local
2983 resolving is initialized such that its high word
2984 contains the output section index in which the
2985 PLT entries are located, and the low word
2986 contains the offset of the lazy PLT entry entry
2987 point into that section. */
2988 bfd_put_32 (output_bfd,
2989 h && ! BFINFDPIC_SYM_LOCAL (info, h)
2990 ? 0
2991 : _bfinfdpic_osec_to_segment (output_bfd,
2992 sec
2993 ->output_section),
2994 contents + rel->r_offset + 4);
2995 }
2996 }
2997 check_segment[0] = check_segment[1] = got_segment;
2998 break;
2999
3000 default:
3001 check_segment[0] = isec_segment;
3002 check_segment[1] = sec
3003 ? _bfinfdpic_osec_to_segment (output_bfd, sec->output_section)
3004 : (unsigned)-1;
3005 break;
3006 }
3007
3008 if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
3009 {
3010 #if 1 /* If you take this out, remove the #error from fdpic-static-6.d
3011 in the ld testsuite. */
3012 /* This helps catch problems in GCC while we can't do more
3013 than static linking. The idea is to test whether the
3014 input file basename is crt0.o only once. */
3015 if (silence_segment_error == 1)
3016 silence_segment_error =
3017 (strlen (input_bfd->filename) == 6
3018 && filename_cmp (input_bfd->filename, "crt0.o") == 0)
3019 || (strlen (input_bfd->filename) > 6
3020 && filename_cmp (input_bfd->filename
3021 + strlen (input_bfd->filename) - 7,
3022 "/crt0.o") == 0)
3023 ? -1 : 0;
3024 #endif
3025 if (!silence_segment_error
3026 /* We don't want duplicate errors for undefined
3027 symbols. */
3028 && !(picrel && picrel->symndx == -1
3029 && picrel->d.h->root.type == bfd_link_hash_undefined))
3030 info->callbacks->warning
3031 (info,
3032 bfd_link_pic (info)
3033 ? _("relocations between different segments are not supported")
3034 : _("warning: relocation references a different segment"),
3035 name, input_bfd, input_section, rel->r_offset);
3036 if (!silence_segment_error && bfd_link_pic (info))
3037 return FALSE;
3038 elf_elfheader (output_bfd)->e_flags |= EF_BFIN_PIC;
3039 }
3040
3041 switch (r_type)
3042 {
3043 case R_BFIN_GOTOFFHI:
3044 /* We need the addend to be applied before we shift the
3045 value right. */
3046 relocation += rel->r_addend;
3047 /* Fall through. */
3048 case R_BFIN_GOTHI:
3049 case R_BFIN_FUNCDESC_GOTHI:
3050 case R_BFIN_FUNCDESC_GOTOFFHI:
3051 relocation >>= 16;
3052 /* Fall through. */
3053
3054 case R_BFIN_GOTLO:
3055 case R_BFIN_FUNCDESC_GOTLO:
3056 case R_BFIN_GOTOFFLO:
3057 case R_BFIN_FUNCDESC_GOTOFFLO:
3058 relocation &= 0xffff;
3059 break;
3060
3061 default:
3062 break;
3063 }
3064
3065 switch (r_type)
3066 {
3067 case R_BFIN_PCREL24:
3068 case R_BFIN_PCREL24_JUMP_L:
3069 if (! IS_FDPIC (output_bfd) || ! picrel->plt)
3070 break;
3071 /* Fall through. */
3072
3073 /* When referencing a GOT entry, a function descriptor or a
3074 PLT, we don't want the addend to apply to the reference,
3075 but rather to the referenced symbol. The actual entry
3076 will have already been created taking the addend into
3077 account, so cancel it out here. */
3078 case R_BFIN_GOT17M4:
3079 case R_BFIN_GOTHI:
3080 case R_BFIN_GOTLO:
3081 case R_BFIN_FUNCDESC_GOT17M4:
3082 case R_BFIN_FUNCDESC_GOTHI:
3083 case R_BFIN_FUNCDESC_GOTLO:
3084 case R_BFIN_FUNCDESC_GOTOFF17M4:
3085 case R_BFIN_FUNCDESC_GOTOFFHI:
3086 case R_BFIN_FUNCDESC_GOTOFFLO:
3087 /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF17M4
3088 here, since we do want to apply the addend to the others.
3089 Note that we've applied the addend to GOTOFFHI before we
3090 shifted it right. */
3091 case R_BFIN_GOTOFFHI:
3092 relocation -= rel->r_addend;
3093 break;
3094
3095 default:
3096 break;
3097 }
3098
3099 r = bfin_final_link_relocate (rel, howto, input_bfd, input_section,
3100 contents, rel->r_offset,
3101 relocation, rel->r_addend);
3102
3103 if (r != bfd_reloc_ok)
3104 {
3105 const char * msg = (const char *) NULL;
3106
3107 switch (r)
3108 {
3109 case bfd_reloc_overflow:
3110 (*info->callbacks->reloc_overflow)
3111 (info, (h ? &h->root : NULL), name, howto->name,
3112 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
3113 break;
3114
3115 case bfd_reloc_undefined:
3116 (*info->callbacks->undefined_symbol)
3117 (info, name, input_bfd, input_section, rel->r_offset, TRUE);
3118 break;
3119
3120 case bfd_reloc_outofrange:
3121 msg = _("internal error: out of range error");
3122 break;
3123
3124 case bfd_reloc_notsupported:
3125 msg = _("internal error: unsupported relocation error");
3126 break;
3127
3128 case bfd_reloc_dangerous:
3129 msg = _("internal error: dangerous relocation");
3130 break;
3131
3132 default:
3133 msg = _("internal error: unknown error");
3134 break;
3135 }
3136
3137 if (msg)
3138 (*info->callbacks->warning) (info, msg, name, input_bfd,
3139 input_section, rel->r_offset);
3140 }
3141 }
3142
3143 return TRUE;
3144 }
3145
3146 /* We need dynamic symbols for every section, since segments can
3147 relocate independently. */
3148 static bfd_boolean
3149 _bfinfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
3150 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3151 asection *p)
3152 {
3153 switch (elf_section_data (p)->this_hdr.sh_type)
3154 {
3155 case SHT_PROGBITS:
3156 case SHT_NOBITS:
3157 /* If sh_type is yet undecided, assume it could be
3158 SHT_PROGBITS/SHT_NOBITS. */
3159 case SHT_NULL:
3160 return FALSE;
3161
3162 /* There shouldn't be section relative relocations
3163 against any other section. */
3164 default:
3165 return TRUE;
3166 }
3167 }
3168
3169 /* Create a .got section, as well as its additional info field. This
3170 is almost entirely copied from
3171 elflink.c:_bfd_elf_create_got_section(). */
3172
3173 static bfd_boolean
3174 _bfin_create_got_section (bfd *abfd, struct bfd_link_info *info)
3175 {
3176 flagword flags, pltflags;
3177 asection *s;
3178 struct elf_link_hash_entry *h;
3179 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3180 int ptralign;
3181
3182 /* This function may be called more than once. */
3183 s = elf_hash_table (info)->sgot;
3184 if (s != NULL)
3185 return TRUE;
3186
3187 /* Machine specific: although pointers are 32-bits wide, we want the
3188 GOT to be aligned to a 64-bit boundary, such that function
3189 descriptors in it can be accessed with 64-bit loads and
3190 stores. */
3191 ptralign = 3;
3192
3193 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3194 | SEC_LINKER_CREATED);
3195 pltflags = flags;
3196
3197 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
3198 elf_hash_table (info)->sgot = s;
3199 if (s == NULL
3200 || !bfd_set_section_alignment (s, ptralign))
3201 return FALSE;
3202
3203 if (bed->want_got_sym)
3204 {
3205 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
3206 (or .got.plt) section. We don't do this in the linker script
3207 because we don't want to define the symbol if we are not creating
3208 a global offset table. */
3209 h = _bfd_elf_define_linkage_sym (abfd, info, s, "__GLOBAL_OFFSET_TABLE_");
3210 elf_hash_table (info)->hgot = h;
3211 if (h == NULL)
3212 return FALSE;
3213
3214 /* Machine-specific: we want the symbol for executables as
3215 well. */
3216 if (! bfd_elf_link_record_dynamic_symbol (info, h))
3217 return FALSE;
3218 }
3219
3220 /* The first bit of the global offset table is the header. */
3221 s->size += bed->got_header_size;
3222
3223 /* This is the machine-specific part. Create and initialize section
3224 data for the got. */
3225 if (IS_FDPIC (abfd))
3226 {
3227 bfinfdpic_relocs_info (info) = htab_try_create (1,
3228 bfinfdpic_relocs_info_hash,
3229 bfinfdpic_relocs_info_eq,
3230 (htab_del) NULL);
3231 if (! bfinfdpic_relocs_info (info))
3232 return FALSE;
3233
3234 s = bfd_make_section_anyway_with_flags (abfd, ".rel.got",
3235 (flags | SEC_READONLY));
3236 if (s == NULL
3237 || !bfd_set_section_alignment (s, 2))
3238 return FALSE;
3239
3240 bfinfdpic_gotrel_section (info) = s;
3241
3242 /* Machine-specific. */
3243 s = bfd_make_section_anyway_with_flags (abfd, ".rofixup",
3244 (flags | SEC_READONLY));
3245 if (s == NULL
3246 || !bfd_set_section_alignment (s, 2))
3247 return FALSE;
3248
3249 bfinfdpic_gotfixup_section (info) = s;
3250 }
3251
3252 pltflags |= SEC_CODE;
3253 if (bed->plt_not_loaded)
3254 pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
3255 if (bed->plt_readonly)
3256 pltflags |= SEC_READONLY;
3257
3258 s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
3259 if (s == NULL
3260 || !bfd_set_section_alignment (s, bed->plt_alignment))
3261 return FALSE;
3262 /* Blackfin-specific: remember it. */
3263 bfinfdpic_plt_section (info) = s;
3264
3265 if (bed->want_plt_sym)
3266 {
3267 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3268 .plt section. */
3269 struct bfd_link_hash_entry *bh = NULL;
3270
3271 if (! (_bfd_generic_link_add_one_symbol
3272 (info, abfd, "__PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s, 0, NULL,
3273 FALSE, get_elf_backend_data (abfd)->collect, &bh)))
3274 return FALSE;
3275 h = (struct elf_link_hash_entry *) bh;
3276 h->def_regular = 1;
3277 h->type = STT_OBJECT;
3278
3279 if (! bfd_link_executable (info)
3280 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3281 return FALSE;
3282 }
3283
3284 /* Blackfin-specific: we want rel relocations for the plt. */
3285 s = bfd_make_section_anyway_with_flags (abfd, ".rel.plt",
3286 flags | SEC_READONLY);
3287 if (s == NULL
3288 || !bfd_set_section_alignment (s, bed->s->log_file_align))
3289 return FALSE;
3290 /* Blackfin-specific: remember it. */
3291 bfinfdpic_pltrel_section (info) = s;
3292
3293 return TRUE;
3294 }
3295
3296 /* Make sure the got and plt sections exist, and that our pointers in
3297 the link hash table point to them. */
3298
3299 static bfd_boolean
3300 elf32_bfinfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3301 {
3302 /* This is mostly copied from
3303 elflink.c:_bfd_elf_create_dynamic_sections(). */
3304 flagword flags;
3305 asection *s;
3306 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3307
3308 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3309 | SEC_LINKER_CREATED);
3310
3311 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3312 .rel[a].bss sections. */
3313
3314 /* Blackfin-specific: we want to create the GOT in the Blackfin way. */
3315 if (! _bfin_create_got_section (abfd, info))
3316 return FALSE;
3317
3318 /* Blackfin-specific: make sure we created everything we wanted. */
3319 BFD_ASSERT (bfinfdpic_got_section (info) && bfinfdpic_gotrel_section (info)
3320 /* && bfinfdpic_gotfixup_section (info) */
3321 && bfinfdpic_plt_section (info)
3322 && bfinfdpic_pltrel_section (info));
3323
3324 if (bed->want_dynbss)
3325 {
3326 /* The .dynbss section is a place to put symbols which are defined
3327 by dynamic objects, are referenced by regular objects, and are
3328 not functions. We must allocate space for them in the process
3329 image and use a R_*_COPY reloc to tell the dynamic linker to
3330 initialize them at run time. The linker script puts the .dynbss
3331 section into the .bss section of the final image. */
3332 s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
3333 SEC_ALLOC | SEC_LINKER_CREATED);
3334 if (s == NULL)
3335 return FALSE;
3336
3337 /* The .rel[a].bss section holds copy relocs. This section is not
3338 normally needed. We need to create it here, though, so that the
3339 linker will map it to an output section. We can't just create it
3340 only if we need it, because we will not know whether we need it
3341 until we have seen all the input files, and the first time the
3342 main linker code calls BFD after examining all the input files
3343 (size_dynamic_sections) the input sections have already been
3344 mapped to the output sections. If the section turns out not to
3345 be needed, we can discard it later. We will never need this
3346 section when generating a shared object, since they do not use
3347 copy relocs. */
3348 if (! bfd_link_pic (info))
3349 {
3350 s = bfd_make_section_anyway_with_flags (abfd,
3351 ".rela.bss",
3352 flags | SEC_READONLY);
3353 if (s == NULL
3354 || !bfd_set_section_alignment (s, bed->s->log_file_align))
3355 return FALSE;
3356 }
3357 }
3358
3359 return TRUE;
3360 }
3361
3362 /* Compute the total GOT size required by each symbol in each range.
3363 Symbols may require up to 4 words in the GOT: an entry pointing to
3364 the symbol, an entry pointing to its function descriptor, and a
3365 private function descriptors taking two words. */
3366
3367 static void
3368 _bfinfdpic_count_nontls_entries (struct bfinfdpic_relocs_info *entry,
3369 struct _bfinfdpic_dynamic_got_info *dinfo)
3370 {
3371 /* Allocate space for a GOT entry pointing to the symbol. */
3372 if (entry->got17m4)
3373 dinfo->got17m4 += 4;
3374 else if (entry->gothilo)
3375 dinfo->gothilo += 4;
3376 else
3377 entry->relocs32--;
3378 entry->relocs32++;
3379
3380 /* Allocate space for a GOT entry pointing to the function
3381 descriptor. */
3382 if (entry->fdgot17m4)
3383 dinfo->got17m4 += 4;
3384 else if (entry->fdgothilo)
3385 dinfo->gothilo += 4;
3386 else
3387 entry->relocsfd--;
3388 entry->relocsfd++;
3389
3390 /* Decide whether we need a PLT entry, a function descriptor in the
3391 GOT, and a lazy PLT entry for this symbol. */
3392 entry->plt = entry->call
3393 && entry->symndx == -1 && ! BFINFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
3394 && elf_hash_table (dinfo->info)->dynamic_sections_created;
3395 entry->privfd = entry->plt
3396 || entry->fdgoff17m4 || entry->fdgoffhilo
3397 || ((entry->fd || entry->fdgot17m4 || entry->fdgothilo)
3398 && (entry->symndx != -1
3399 || BFINFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
3400 entry->lazyplt = entry->privfd
3401 && entry->symndx == -1 && ! BFINFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
3402 && ! (dinfo->info->flags & DF_BIND_NOW)
3403 && elf_hash_table (dinfo->info)->dynamic_sections_created;
3404
3405 /* Allocate space for a function descriptor. */
3406 if (entry->fdgoff17m4)
3407 dinfo->fd17m4 += 8;
3408 else if (entry->privfd && entry->plt)
3409 dinfo->fdplt += 8;
3410 else if (entry->privfd)
3411 dinfo->fdhilo += 8;
3412 else
3413 entry->relocsfdv--;
3414 entry->relocsfdv++;
3415
3416 if (entry->lazyplt)
3417 dinfo->lzplt += LZPLT_NORMAL_SIZE;
3418 }
3419
3420 /* Compute the number of dynamic relocations and fixups that a symbol
3421 requires, and add (or subtract) from the grand and per-symbol
3422 totals. */
3423
3424 static void
3425 _bfinfdpic_count_relocs_fixups (struct bfinfdpic_relocs_info *entry,
3426 struct _bfinfdpic_dynamic_got_info *dinfo,
3427 bfd_boolean subtract)
3428 {
3429 bfd_vma relocs = 0, fixups = 0;
3430
3431 if (!bfd_link_pde (dinfo->info))
3432 relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv;
3433 else
3434 {
3435 if (entry->symndx != -1 || BFINFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
3436 {
3437 if (entry->symndx != -1
3438 || entry->d.h->root.type != bfd_link_hash_undefweak)
3439 fixups += entry->relocs32 + 2 * entry->relocsfdv;
3440 }
3441 else
3442 relocs += entry->relocs32 + entry->relocsfdv;
3443
3444 if (entry->symndx != -1
3445 || BFINFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
3446 {
3447 if (entry->symndx != -1
3448 || entry->d.h->root.type != bfd_link_hash_undefweak)
3449 fixups += entry->relocsfd;
3450 }
3451 else
3452 relocs += entry->relocsfd;
3453 }
3454
3455 if (subtract)
3456 {
3457 relocs = - relocs;
3458 fixups = - fixups;
3459 }
3460
3461 entry->dynrelocs += relocs;
3462 entry->fixups += fixups;
3463 dinfo->relocs += relocs;
3464 dinfo->fixups += fixups;
3465 }
3466
3467 /* Compute the total GOT and PLT size required by each symbol in each range. *
3468 Symbols may require up to 4 words in the GOT: an entry pointing to
3469 the symbol, an entry pointing to its function descriptor, and a
3470 private function descriptors taking two words. */
3471
3472 static int
3473 _bfinfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
3474 {
3475 struct bfinfdpic_relocs_info *entry = *entryp;
3476 struct _bfinfdpic_dynamic_got_info *dinfo = dinfo_;
3477
3478 _bfinfdpic_count_nontls_entries (entry, dinfo);
3479
3480 _bfinfdpic_count_relocs_fixups (entry, dinfo, FALSE);
3481
3482 return 1;
3483 }
3484
3485 /* This structure is used to assign offsets to got entries, function
3486 descriptors, plt entries and lazy plt entries. */
3487
3488 struct _bfinfdpic_dynamic_got_plt_info
3489 {
3490 /* Summary information collected with _bfinfdpic_count_got_plt_entries. */
3491 struct _bfinfdpic_dynamic_got_info g;
3492
3493 /* For each addressable range, we record a MAX (positive) and MIN
3494 (negative) value. CUR is used to assign got entries, and it's
3495 incremented from an initial positive value to MAX, then from MIN
3496 to FDCUR (unless FDCUR wraps around first). FDCUR is used to
3497 assign function descriptors, and it's decreased from an initial
3498 non-positive value to MIN, then from MAX down to CUR (unless CUR
3499 wraps around first). All of MIN, MAX, CUR and FDCUR always point
3500 to even words. ODD, if non-zero, indicates an odd word to be
3501 used for the next got entry, otherwise CUR is used and
3502 incremented by a pair of words, wrapping around when it reaches
3503 MAX. FDCUR is decremented (and wrapped) before the next function
3504 descriptor is chosen. FDPLT indicates the number of remaining
3505 slots that can be used for function descriptors used only by PLT
3506 entries. */
3507 struct _bfinfdpic_dynamic_got_alloc_data
3508 {
3509 bfd_signed_vma max, cur, odd, fdcur, min;
3510 bfd_vma fdplt;
3511 } got17m4, gothilo;
3512 };
3513
3514 /* Determine the positive and negative ranges to be used by each
3515 offset range in the GOT. FDCUR and CUR, that must be aligned to a
3516 double-word boundary, are the minimum (negative) and maximum
3517 (positive) GOT offsets already used by previous ranges, except for
3518 an ODD entry that may have been left behind. GOT and FD indicate
3519 the size of GOT entries and function descriptors that must be
3520 placed within the range from -WRAP to WRAP. If there's room left,
3521 up to FDPLT bytes should be reserved for additional function
3522 descriptors. */
3523
3524 inline static bfd_signed_vma
3525 _bfinfdpic_compute_got_alloc_data (struct _bfinfdpic_dynamic_got_alloc_data *gad,
3526 bfd_signed_vma fdcur,
3527 bfd_signed_vma odd,
3528 bfd_signed_vma cur,
3529 bfd_vma got,
3530 bfd_vma fd,
3531 bfd_vma fdplt,
3532 bfd_vma wrap)
3533 {
3534 bfd_signed_vma wrapmin = -wrap;
3535
3536 /* Start at the given initial points. */
3537 gad->fdcur = fdcur;
3538 gad->cur = cur;
3539
3540 /* If we had an incoming odd word and we have any got entries that
3541 are going to use it, consume it, otherwise leave gad->odd at
3542 zero. We might force gad->odd to zero and return the incoming
3543 odd such that it is used by the next range, but then GOT entries
3544 might appear to be out of order and we wouldn't be able to
3545 shorten the GOT by one word if it turns out to end with an
3546 unpaired GOT entry. */
3547 if (odd && got)
3548 {
3549 gad->odd = odd;
3550 got -= 4;
3551 odd = 0;
3552 }
3553 else
3554 gad->odd = 0;
3555
3556 /* If we're left with an unpaired GOT entry, compute its location
3557 such that we can return it. Otherwise, if got doesn't require an
3558 odd number of words here, either odd was already zero in the
3559 block above, or it was set to zero because got was non-zero, or
3560 got was already zero. In the latter case, we want the value of
3561 odd to carry over to the return statement, so we don't want to
3562 reset odd unless the condition below is true. */
3563 if (got & 4)
3564 {
3565 odd = cur + got;
3566 got += 4;
3567 }
3568
3569 /* Compute the tentative boundaries of this range. */
3570 gad->max = cur + got;
3571 gad->min = fdcur - fd;
3572 gad->fdplt = 0;
3573
3574 /* If function descriptors took too much space, wrap some of them
3575 around. */
3576 if (gad->min < wrapmin)
3577 {
3578 gad->max += wrapmin - gad->min;
3579 gad->min = wrapmin;
3580 }
3581 /* If there is space left and we have function descriptors
3582 referenced in PLT entries that could take advantage of shorter
3583 offsets, place them here. */
3584 else if (fdplt && gad->min > wrapmin)
3585 {
3586 bfd_vma fds;
3587 if ((bfd_vma) (gad->min - wrapmin) < fdplt)
3588 fds = gad->min - wrapmin;
3589 else
3590 fds = fdplt;
3591
3592 fdplt -= fds;
3593 gad->min -= fds;
3594 gad->fdplt += fds;
3595 }
3596
3597 /* If GOT entries took too much space, wrap some of them around.
3598 This may well cause gad->min to become lower than wrapmin. This
3599 will cause a relocation overflow later on, so we don't have to
3600 report it here . */
3601 if ((bfd_vma) gad->max > wrap)
3602 {
3603 gad->min -= gad->max - wrap;
3604 gad->max = wrap;
3605 }
3606 /* If there is more space left, try to place some more function
3607 descriptors for PLT entries. */
3608 else if (fdplt && (bfd_vma) gad->max < wrap)
3609 {
3610 bfd_vma fds;
3611 if ((bfd_vma) (wrap - gad->max) < fdplt)
3612 fds = wrap - gad->max;
3613 else
3614 fds = fdplt;
3615
3616 fdplt -= fds;
3617 gad->max += fds;
3618 gad->fdplt += fds;
3619 }
3620
3621 /* If odd was initially computed as an offset past the wrap point,
3622 wrap it around. */
3623 if (odd > gad->max)
3624 odd = gad->min + odd - gad->max;
3625
3626 /* _bfinfdpic_get_got_entry() below will always wrap gad->cur if needed
3627 before returning, so do it here too. This guarantees that,
3628 should cur and fdcur meet at the wrap point, they'll both be
3629 equal to min. */
3630 if (gad->cur == gad->max)
3631 gad->cur = gad->min;
3632
3633 return odd;
3634 }
3635
3636 /* Compute the location of the next GOT entry, given the allocation
3637 data for a range. */
3638
3639 inline static bfd_signed_vma
3640 _bfinfdpic_get_got_entry (struct _bfinfdpic_dynamic_got_alloc_data *gad)
3641 {
3642 bfd_signed_vma ret;
3643
3644 if (gad->odd)
3645 {
3646 /* If there was an odd word left behind, use it. */
3647 ret = gad->odd;
3648 gad->odd = 0;
3649 }
3650 else
3651 {
3652 /* Otherwise, use the word pointed to by cur, reserve the next
3653 as an odd word, and skip to the next pair of words, possibly
3654 wrapping around. */
3655 ret = gad->cur;
3656 gad->odd = gad->cur + 4;
3657 gad->cur += 8;
3658 if (gad->cur == gad->max)
3659 gad->cur = gad->min;
3660 }
3661
3662 return ret;
3663 }
3664
3665 /* Compute the location of the next function descriptor entry in the
3666 GOT, given the allocation data for a range. */
3667
3668 inline static bfd_signed_vma
3669 _bfinfdpic_get_fd_entry (struct _bfinfdpic_dynamic_got_alloc_data *gad)
3670 {
3671 /* If we're at the bottom, wrap around, and only then allocate the
3672 next pair of words. */
3673 if (gad->fdcur == gad->min)
3674 gad->fdcur = gad->max;
3675 return gad->fdcur -= 8;
3676 }
3677
3678 /* Assign GOT offsets for every GOT entry and function descriptor.
3679 Doing everything in a single pass is tricky. */
3680
3681 static int
3682 _bfinfdpic_assign_got_entries (void **entryp, void *info_)
3683 {
3684 struct bfinfdpic_relocs_info *entry = *entryp;
3685 struct _bfinfdpic_dynamic_got_plt_info *dinfo = info_;
3686
3687 if (entry->got17m4)
3688 entry->got_entry = _bfinfdpic_get_got_entry (&dinfo->got17m4);
3689 else if (entry->gothilo)
3690 entry->got_entry = _bfinfdpic_get_got_entry (&dinfo->gothilo);
3691
3692 if (entry->fdgot17m4)
3693 entry->fdgot_entry = _bfinfdpic_get_got_entry (&dinfo->got17m4);
3694 else if (entry->fdgothilo)
3695 entry->fdgot_entry = _bfinfdpic_get_got_entry (&dinfo->gothilo);
3696
3697 if (entry->fdgoff17m4)
3698 entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->got17m4);
3699 else if (entry->plt && dinfo->got17m4.fdplt)
3700 {
3701 dinfo->got17m4.fdplt -= 8;
3702 entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->got17m4);
3703 }
3704 else if (entry->plt)
3705 {
3706 dinfo->gothilo.fdplt -= 8;
3707 entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->gothilo);
3708 }
3709 else if (entry->privfd)
3710 entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->gothilo);
3711
3712 return 1;
3713 }
3714
3715 /* Assign GOT offsets to private function descriptors used by PLT
3716 entries (or referenced by 32-bit offsets), as well as PLT entries
3717 and lazy PLT entries. */
3718
3719 static int
3720 _bfinfdpic_assign_plt_entries (void **entryp, void *info_)
3721 {
3722 struct bfinfdpic_relocs_info *entry = *entryp;
3723 struct _bfinfdpic_dynamic_got_plt_info *dinfo = info_;
3724
3725 /* If this symbol requires a local function descriptor, allocate
3726 one. */
3727 if (entry->privfd && entry->fd_entry == 0)
3728 {
3729 if (dinfo->got17m4.fdplt)
3730 {
3731 entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->got17m4);
3732 dinfo->got17m4.fdplt -= 8;
3733 }
3734 else
3735 {
3736 BFD_ASSERT (dinfo->gothilo.fdplt);
3737 entry->fd_entry = _bfinfdpic_get_fd_entry (&dinfo->gothilo);
3738 dinfo->gothilo.fdplt -= 8;
3739 }
3740 }
3741
3742 if (entry->plt)
3743 {
3744 int size;
3745
3746 /* We use the section's raw size to mark the location of the
3747 next PLT entry. */
3748 entry->plt_entry = bfinfdpic_plt_section (dinfo->g.info)->size;
3749
3750 /* Figure out the length of this PLT entry based on the
3751 addressing mode we need to reach the function descriptor. */
3752 BFD_ASSERT (entry->fd_entry);
3753 if (entry->fd_entry >= -(1 << (18 - 1))
3754 && entry->fd_entry + 4 < (1 << (18 - 1)))
3755 size = 10;
3756 else
3757 size = 16;
3758
3759 bfinfdpic_plt_section (dinfo->g.info)->size += size;
3760 }
3761
3762 if (entry->lazyplt)
3763 {
3764 entry->lzplt_entry = dinfo->g.lzplt;
3765 dinfo->g.lzplt += LZPLT_NORMAL_SIZE;
3766 /* If this entry is the one that gets the resolver stub, account
3767 for the additional instruction. */
3768 if (entry->lzplt_entry % BFINFDPIC_LZPLT_BLOCK_SIZE
3769 == BFINFDPIC_LZPLT_RESOLV_LOC)
3770 dinfo->g.lzplt += LZPLT_RESOLVER_EXTRA;
3771 }
3772
3773 return 1;
3774 }
3775
3776 /* Cancel out any effects of calling _bfinfdpic_assign_got_entries and
3777 _bfinfdpic_assign_plt_entries. */
3778
3779 static int
3780 _bfinfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
3781 {
3782 struct bfinfdpic_relocs_info *entry = *entryp;
3783
3784 entry->got_entry = 0;
3785 entry->fdgot_entry = 0;
3786 entry->fd_entry = 0;
3787 entry->plt_entry = (bfd_vma)-1;
3788 entry->lzplt_entry = (bfd_vma)-1;
3789
3790 return 1;
3791 }
3792
3793 /* Follow indirect and warning hash entries so that each got entry
3794 points to the final symbol definition. P must point to a pointer
3795 to the hash table we're traversing. Since this traversal may
3796 modify the hash table, we set this pointer to NULL to indicate
3797 we've made a potentially-destructive change to the hash table, so
3798 the traversal must be restarted. */
3799 static int
3800 _bfinfdpic_resolve_final_relocs_info (void **entryp, void *p)
3801 {
3802 struct bfinfdpic_relocs_info *entry = *entryp;
3803 htab_t *htab = p;
3804
3805 if (entry->symndx == -1)
3806 {
3807 struct elf_link_hash_entry *h = entry->d.h;
3808 struct bfinfdpic_relocs_info *oentry;
3809
3810 while (h->root.type == bfd_link_hash_indirect
3811 || h->root.type == bfd_link_hash_warning)
3812 h = (struct elf_link_hash_entry *)h->root.u.i.link;
3813
3814 if (entry->d.h == h)
3815 return 1;
3816
3817 oentry = bfinfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
3818 NO_INSERT);
3819
3820 if (oentry)
3821 {
3822 /* Merge the two entries. */
3823 bfinfdpic_pic_merge_early_relocs_info (oentry, entry);
3824 htab_clear_slot (*htab, entryp);
3825 return 1;
3826 }
3827
3828 entry->d.h = h;
3829
3830 /* If we can't find this entry with the new bfd hash, re-insert
3831 it, and get the traversal restarted. */
3832 if (! htab_find (*htab, entry))
3833 {
3834 htab_clear_slot (*htab, entryp);
3835 entryp = htab_find_slot (*htab, entry, INSERT);
3836 if (! *entryp)
3837 *entryp = entry;
3838 /* Abort the traversal, since the whole table may have
3839 moved, and leave it up to the parent to restart the
3840 process. */
3841 *(htab_t *)p = NULL;
3842 return 0;
3843 }
3844 }
3845
3846 return 1;
3847 }
3848
3849 /* Compute the total size of the GOT, the PLT, the dynamic relocations
3850 section and the rofixup section. Assign locations for GOT and PLT
3851 entries. */
3852
3853 static bfd_boolean
3854 _bfinfdpic_size_got_plt (bfd *output_bfd,
3855 struct _bfinfdpic_dynamic_got_plt_info *gpinfop)
3856 {
3857 bfd_signed_vma odd;
3858 bfd_vma limit;
3859 struct bfd_link_info *info = gpinfop->g.info;
3860 bfd *dynobj = elf_hash_table (info)->dynobj;
3861
3862 memcpy (bfinfdpic_dynamic_got_plt_info (info), &gpinfop->g,
3863 sizeof (gpinfop->g));
3864
3865 odd = 12;
3866 /* Compute the total size taken by entries in the 18-bit range,
3867 to tell how many PLT function descriptors we can bring into it
3868 without causing it to overflow. */
3869 limit = odd + gpinfop->g.got17m4 + gpinfop->g.fd17m4;
3870 if (limit < (bfd_vma)1 << 18)
3871 limit = ((bfd_vma)1 << 18) - limit;
3872 else
3873 limit = 0;
3874 if (gpinfop->g.fdplt < limit)
3875 limit = gpinfop->g.fdplt;
3876
3877 /* Determine the ranges of GOT offsets that we can use for each
3878 range of addressing modes. */
3879 odd = _bfinfdpic_compute_got_alloc_data (&gpinfop->got17m4,
3880 0,
3881 odd,
3882 16,
3883 gpinfop->g.got17m4,
3884 gpinfop->g.fd17m4,
3885 limit,
3886 (bfd_vma)1 << (18-1));
3887 odd = _bfinfdpic_compute_got_alloc_data (&gpinfop->gothilo,
3888 gpinfop->got17m4.min,
3889 odd,
3890 gpinfop->got17m4.max,
3891 gpinfop->g.gothilo,
3892 gpinfop->g.fdhilo,
3893 gpinfop->g.fdplt - gpinfop->got17m4.fdplt,
3894 (bfd_vma)1 << (32-1));
3895
3896 /* Now assign (most) GOT offsets. */
3897 htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_assign_got_entries,
3898 gpinfop);
3899
3900 bfinfdpic_got_section (info)->size = gpinfop->gothilo.max
3901 - gpinfop->gothilo.min
3902 /* If an odd word is the last word of the GOT, we don't need this
3903 word to be part of the GOT. */
3904 - (odd + 4 == gpinfop->gothilo.max ? 4 : 0);
3905 if (bfinfdpic_got_section (info)->size == 0)
3906 bfinfdpic_got_section (info)->flags |= SEC_EXCLUDE;
3907 else if (bfinfdpic_got_section (info)->size == 12
3908 && ! elf_hash_table (info)->dynamic_sections_created)
3909 {
3910 bfinfdpic_got_section (info)->flags |= SEC_EXCLUDE;
3911 bfinfdpic_got_section (info)->size = 0;
3912 }
3913 else
3914 {
3915 bfinfdpic_got_section (info)->contents =
3916 (bfd_byte *) bfd_zalloc (dynobj,
3917 bfinfdpic_got_section (info)->size);
3918 if (bfinfdpic_got_section (info)->contents == NULL)
3919 return FALSE;
3920 }
3921
3922 if (elf_hash_table (info)->dynamic_sections_created)
3923 /* Subtract the number of lzplt entries, since those will generate
3924 relocations in the pltrel section. */
3925 bfinfdpic_gotrel_section (info)->size =
3926 (gpinfop->g.relocs - gpinfop->g.lzplt / LZPLT_NORMAL_SIZE)
3927 * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3928 else
3929 BFD_ASSERT (gpinfop->g.relocs == 0);
3930 if (bfinfdpic_gotrel_section (info)->size == 0)
3931 bfinfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
3932 else
3933 {
3934 bfinfdpic_gotrel_section (info)->contents =
3935 (bfd_byte *) bfd_zalloc (dynobj,
3936 bfinfdpic_gotrel_section (info)->size);
3937 if (bfinfdpic_gotrel_section (info)->contents == NULL)
3938 return FALSE;
3939 }
3940
3941 bfinfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
3942 if (bfinfdpic_gotfixup_section (info)->size == 0)
3943 bfinfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
3944 else
3945 {
3946 bfinfdpic_gotfixup_section (info)->contents =
3947 (bfd_byte *) bfd_zalloc (dynobj,
3948 bfinfdpic_gotfixup_section (info)->size);
3949 if (bfinfdpic_gotfixup_section (info)->contents == NULL)
3950 return FALSE;
3951 }
3952
3953 if (elf_hash_table (info)->dynamic_sections_created)
3954 bfinfdpic_pltrel_section (info)->size =
3955 gpinfop->g.lzplt / LZPLT_NORMAL_SIZE * get_elf_backend_data (output_bfd)->s->sizeof_rel;
3956 if (bfinfdpic_pltrel_section (info)->size == 0)
3957 bfinfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
3958 else
3959 {
3960 bfinfdpic_pltrel_section (info)->contents =
3961 (bfd_byte *) bfd_zalloc (dynobj,
3962 bfinfdpic_pltrel_section (info)->size);
3963 if (bfinfdpic_pltrel_section (info)->contents == NULL)
3964 return FALSE;
3965 }
3966
3967 /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
3968 such that there's room for the additional instruction needed to
3969 call the resolver. Since _bfinfdpic_assign_got_entries didn't
3970 account for them, our block size is 4 bytes smaller than the real
3971 block size. */
3972 if (elf_hash_table (info)->dynamic_sections_created)
3973 {
3974 bfinfdpic_plt_section (info)->size = gpinfop->g.lzplt
3975 + ((gpinfop->g.lzplt + (BFINFDPIC_LZPLT_BLOCK_SIZE - 4) - LZPLT_NORMAL_SIZE)
3976 / (BFINFDPIC_LZPLT_BLOCK_SIZE - 4) * LZPLT_RESOLVER_EXTRA);
3977 }
3978
3979 /* Reset it, such that _bfinfdpic_assign_plt_entries() can use it to
3980 actually assign lazy PLT entries addresses. */
3981 gpinfop->g.lzplt = 0;
3982
3983 /* Save information that we're going to need to generate GOT and PLT
3984 entries. */
3985 bfinfdpic_got_initial_offset (info) = -gpinfop->gothilo.min;
3986
3987 if (get_elf_backend_data (output_bfd)->want_got_sym)
3988 elf_hash_table (info)->hgot->root.u.def.value
3989 = bfinfdpic_got_initial_offset (info);
3990
3991 if (elf_hash_table (info)->dynamic_sections_created)
3992 bfinfdpic_plt_initial_offset (info) =
3993 bfinfdpic_plt_section (info)->size;
3994
3995 htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_assign_plt_entries,
3996 gpinfop);
3997
3998 /* Allocate the PLT section contents only after
3999 _bfinfdpic_assign_plt_entries has a chance to add the size of the
4000 non-lazy PLT entries. */
4001 if (bfinfdpic_plt_section (info)->size == 0)
4002 bfinfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
4003 else
4004 {
4005 bfinfdpic_plt_section (info)->contents =
4006 (bfd_byte *) bfd_zalloc (dynobj,
4007 bfinfdpic_plt_section (info)->size);
4008 if (bfinfdpic_plt_section (info)->contents == NULL)
4009 return FALSE;
4010 }
4011
4012 return TRUE;
4013 }
4014
4015 /* Set the sizes of the dynamic sections. */
4016
4017 static bfd_boolean
4018 elf32_bfinfdpic_size_dynamic_sections (bfd *output_bfd,
4019 struct bfd_link_info *info)
4020 {
4021 struct elf_link_hash_table *htab;
4022 bfd *dynobj;
4023 asection *s;
4024 struct _bfinfdpic_dynamic_got_plt_info gpinfo;
4025
4026 htab = elf_hash_table (info);
4027 dynobj = htab->dynobj;
4028 BFD_ASSERT (dynobj != NULL);
4029
4030 if (htab->dynamic_sections_created)
4031 {
4032 /* Set the contents of the .interp section to the interpreter. */
4033 if (bfd_link_executable (info) && !info->nointerp)
4034 {
4035 s = bfd_get_linker_section (dynobj, ".interp");
4036 BFD_ASSERT (s != NULL);
4037 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4038 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
4039 }
4040 }
4041
4042 memset (&gpinfo, 0, sizeof (gpinfo));
4043 gpinfo.g.info = info;
4044
4045 for (;;)
4046 {
4047 htab_t relocs = bfinfdpic_relocs_info (info);
4048
4049 htab_traverse (relocs, _bfinfdpic_resolve_final_relocs_info, &relocs);
4050
4051 if (relocs == bfinfdpic_relocs_info (info))
4052 break;
4053 }
4054
4055 htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_count_got_plt_entries,
4056 &gpinfo.g);
4057
4058 /* Allocate space to save the summary information, we're going to
4059 use it if we're doing relaxations. */
4060 bfinfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
4061
4062 if (!_bfinfdpic_size_got_plt (output_bfd, &gpinfo))
4063 return FALSE;
4064
4065 if (elf_hash_table (info)->dynamic_sections_created)
4066 {
4067 if (bfinfdpic_got_section (info)->size)
4068 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
4069 return FALSE;
4070
4071 if (bfinfdpic_pltrel_section (info)->size)
4072 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
4073 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
4074 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
4075 return FALSE;
4076
4077 if (bfinfdpic_gotrel_section (info)->size)
4078 if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
4079 || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
4080 || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
4081 sizeof (Elf32_External_Rel)))
4082 return FALSE;
4083 }
4084
4085 s = bfd_get_linker_section (dynobj, ".dynbss");
4086 if (s && s->size == 0)
4087 s->flags |= SEC_EXCLUDE;
4088
4089 s = bfd_get_linker_section (dynobj, ".rela.bss");
4090 if (s && s->size == 0)
4091 s->flags |= SEC_EXCLUDE;
4092
4093 return TRUE;
4094 }
4095
4096 static bfd_boolean
4097 elf32_bfinfdpic_always_size_sections (bfd *output_bfd,
4098 struct bfd_link_info *info)
4099 {
4100 if (!bfd_link_relocatable (info)
4101 && !bfd_elf_stack_segment_size (output_bfd, info,
4102 "__stacksize", DEFAULT_STACK_SIZE))
4103 return FALSE;
4104
4105 return TRUE;
4106 }
4107
4108 /* Check whether any of the relocations was optimized away, and
4109 subtract it from the relocation or fixup count. */
4110 static bfd_boolean
4111 _bfinfdpic_check_discarded_relocs (bfd *abfd, asection *sec,
4112 struct bfd_link_info *info,
4113 bfd_boolean *changed)
4114 {
4115 Elf_Internal_Shdr *symtab_hdr;
4116 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
4117 Elf_Internal_Rela *rel, *erel;
4118
4119 if ((sec->flags & SEC_RELOC) == 0
4120 || sec->reloc_count == 0)
4121 return TRUE;
4122
4123 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4124 sym_hashes = elf_sym_hashes (abfd);
4125 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
4126 if (!elf_bad_symtab (abfd))
4127 sym_hashes_end -= symtab_hdr->sh_info;
4128
4129 rel = elf_section_data (sec)->relocs;
4130
4131 /* Now examine each relocation. */
4132 for (erel = rel + sec->reloc_count; rel < erel; rel++)
4133 {
4134 struct elf_link_hash_entry *h;
4135 unsigned long r_symndx;
4136 struct bfinfdpic_relocs_info *picrel;
4137 struct _bfinfdpic_dynamic_got_info *dinfo;
4138
4139 if (ELF32_R_TYPE (rel->r_info) != R_BFIN_BYTE4_DATA
4140 && ELF32_R_TYPE (rel->r_info) != R_BFIN_FUNCDESC)
4141 continue;
4142
4143 if (_bfd_elf_section_offset (sec->output_section->owner,
4144 info, sec, rel->r_offset)
4145 != (bfd_vma)-1)
4146 continue;
4147
4148 r_symndx = ELF32_R_SYM (rel->r_info);
4149 if (r_symndx < symtab_hdr->sh_info)
4150 h = NULL;
4151 else
4152 {
4153 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4154 while (h->root.type == bfd_link_hash_indirect
4155 || h->root.type == bfd_link_hash_warning)
4156 h = (struct elf_link_hash_entry *)h->root.u.i.link;
4157 }
4158
4159 if (h != NULL)
4160 picrel = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info),
4161 abfd, h,
4162 rel->r_addend, NO_INSERT);
4163 else
4164 picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info (info),
4165 abfd, r_symndx,
4166 rel->r_addend, NO_INSERT);
4167
4168 if (! picrel)
4169 return FALSE;
4170
4171 *changed = TRUE;
4172 dinfo = bfinfdpic_dynamic_got_plt_info (info);
4173
4174 _bfinfdpic_count_relocs_fixups (picrel, dinfo, TRUE);
4175 if (ELF32_R_TYPE (rel->r_info) == R_BFIN_BYTE4_DATA)
4176 picrel->relocs32--;
4177 else /* we know (ELF32_R_TYPE (rel->r_info) == R_BFIN_FUNCDESC) */
4178 picrel->relocsfd--;
4179 _bfinfdpic_count_relocs_fixups (picrel, dinfo, FALSE);
4180 }
4181
4182 return TRUE;
4183 }
4184
4185 static bfd_boolean
4186 bfinfdpic_elf_discard_info (bfd *ibfd,
4187 struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED,
4188 struct bfd_link_info *info)
4189 {
4190 bfd_boolean changed = FALSE;
4191 asection *s;
4192 bfd *obfd = NULL;
4193
4194 /* Account for relaxation of .eh_frame section. */
4195 for (s = ibfd->sections; s; s = s->next)
4196 if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
4197 {
4198 if (!_bfinfdpic_check_discarded_relocs (ibfd, s, info, &changed))
4199 return FALSE;
4200 obfd = s->output_section->owner;
4201 }
4202
4203 if (changed)
4204 {
4205 struct _bfinfdpic_dynamic_got_plt_info gpinfo;
4206
4207 memset (&gpinfo, 0, sizeof (gpinfo));
4208 memcpy (&gpinfo.g, bfinfdpic_dynamic_got_plt_info (info),
4209 sizeof (gpinfo.g));
4210
4211 /* Clear GOT and PLT assignments. */
4212 htab_traverse (bfinfdpic_relocs_info (info),
4213 _bfinfdpic_reset_got_plt_entries,
4214 NULL);
4215
4216 if (!_bfinfdpic_size_got_plt (obfd, &gpinfo))
4217 return FALSE;
4218 }
4219
4220 return TRUE;
4221 }
4222
4223 static bfd_boolean
4224 elf32_bfinfdpic_finish_dynamic_sections (bfd *output_bfd,
4225 struct bfd_link_info *info)
4226 {
4227 bfd *dynobj;
4228 asection *sdyn;
4229
4230 dynobj = elf_hash_table (info)->dynobj;
4231
4232 if (bfinfdpic_got_section (info))
4233 {
4234 BFD_ASSERT (bfinfdpic_gotrel_section (info)->size
4235 /* PR 17334: It appears that the GOT section can end up
4236 being bigger than the number of relocs. Presumably
4237 because some relocs have been deleted. A test case has
4238 yet to be generated for verify this, but in the meantime
4239 the test below has been changed from == to >= so that
4240 applications can continue to be built. */
4241 >= (bfinfdpic_gotrel_section (info)->reloc_count
4242 * sizeof (Elf32_External_Rel)));
4243
4244 if (bfinfdpic_gotfixup_section (info))
4245 {
4246 struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
4247 bfd_vma got_value = hgot->root.u.def.value
4248 + hgot->root.u.def.section->output_section->vma
4249 + hgot->root.u.def.section->output_offset;
4250
4251 _bfinfdpic_add_rofixup (output_bfd, bfinfdpic_gotfixup_section (info),
4252 got_value, 0);
4253
4254 if (bfinfdpic_gotfixup_section (info)->size
4255 != (bfinfdpic_gotfixup_section (info)->reloc_count * 4))
4256 {
4257 _bfd_error_handler
4258 ("LINKER BUG: .rofixup section size mismatch");
4259 return FALSE;
4260 }
4261 }
4262 }
4263 if (elf_hash_table (info)->dynamic_sections_created)
4264 {
4265 BFD_ASSERT (bfinfdpic_pltrel_section (info)->size
4266 == (bfinfdpic_pltrel_section (info)->reloc_count
4267 * sizeof (Elf32_External_Rel)));
4268 }
4269
4270 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4271
4272 if (elf_hash_table (info)->dynamic_sections_created)
4273 {
4274 Elf32_External_Dyn * dyncon;
4275 Elf32_External_Dyn * dynconend;
4276
4277 BFD_ASSERT (sdyn != NULL);
4278
4279 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4280 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4281
4282 for (; dyncon < dynconend; dyncon++)
4283 {
4284 Elf_Internal_Dyn dyn;
4285
4286 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4287
4288 switch (dyn.d_tag)
4289 {
4290 default:
4291 break;
4292
4293 case DT_PLTGOT:
4294 dyn.d_un.d_ptr = bfinfdpic_got_section (info)->output_section->vma
4295 + bfinfdpic_got_section (info)->output_offset
4296 + bfinfdpic_got_initial_offset (info);
4297 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4298 break;
4299
4300 case DT_JMPREL:
4301 dyn.d_un.d_ptr = bfinfdpic_pltrel_section (info)
4302 ->output_section->vma
4303 + bfinfdpic_pltrel_section (info)->output_offset;
4304 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4305 break;
4306
4307 case DT_PLTRELSZ:
4308 dyn.d_un.d_val = bfinfdpic_pltrel_section (info)->size;
4309 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4310 break;
4311 }
4312 }
4313 }
4314
4315 return TRUE;
4316 }
4317
4318 /* Adjust a symbol defined by a dynamic object and referenced by a
4319 regular object. */
4320
4321 static bfd_boolean
4322 elf32_bfinfdpic_adjust_dynamic_symbol (struct bfd_link_info *info,
4323 struct elf_link_hash_entry *h)
4324 {
4325 bfd * dynobj;
4326
4327 dynobj = elf_hash_table (info)->dynobj;
4328
4329 /* Make sure we know what is going on here. */
4330 BFD_ASSERT (dynobj != NULL
4331 && (h->is_weakalias
4332 || (h->def_dynamic
4333 && h->ref_regular
4334 && !h->def_regular)));
4335
4336 /* If this is a weak symbol, and there is a real definition, the
4337 processor independent code will have arranged for us to see the
4338 real definition first, and we can just use the same value. */
4339 if (h->is_weakalias)
4340 {
4341 struct elf_link_hash_entry *def = weakdef (h);
4342 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
4343 h->root.u.def.section = def->root.u.def.section;
4344 h->root.u.def.value = def->root.u.def.value;
4345 }
4346
4347 return TRUE;
4348 }
4349
4350 /* Perform any actions needed for dynamic symbols. */
4351
4352 static bfd_boolean
4353 elf32_bfinfdpic_finish_dynamic_symbol
4354 (bfd *output_bfd ATTRIBUTE_UNUSED,
4355 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4356 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
4357 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
4358 {
4359 return TRUE;
4360 }
4361
4362 /* Decide whether to attempt to turn absptr or lsda encodings in
4363 shared libraries into pcrel within the given input section. */
4364
4365 static bfd_boolean
4366 bfinfdpic_elf_use_relative_eh_frame
4367 (bfd *input_bfd ATTRIBUTE_UNUSED,
4368 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4369 asection *eh_frame_section ATTRIBUTE_UNUSED)
4370 {
4371 /* We can't use PC-relative encodings in FDPIC binaries, in general. */
4372 return FALSE;
4373 }
4374
4375 /* Adjust the contents of an eh_frame_hdr section before they're output. */
4376
4377 static bfd_byte
4378 bfinfdpic_elf_encode_eh_address (bfd *abfd,
4379 struct bfd_link_info *info,
4380 asection *osec, bfd_vma offset,
4381 asection *loc_sec, bfd_vma loc_offset,
4382 bfd_vma *encoded)
4383 {
4384 struct elf_link_hash_entry *h;
4385
4386 h = elf_hash_table (info)->hgot;
4387 BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
4388
4389 if (! h || (_bfinfdpic_osec_to_segment (abfd, osec)
4390 == _bfinfdpic_osec_to_segment (abfd, loc_sec->output_section)))
4391 return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
4392 loc_sec, loc_offset, encoded);
4393
4394 BFD_ASSERT (_bfinfdpic_osec_to_segment (abfd, osec)
4395 == (_bfinfdpic_osec_to_segment
4396 (abfd, h->root.u.def.section->output_section)));
4397
4398 *encoded = osec->vma + offset
4399 - (h->root.u.def.value
4400 + h->root.u.def.section->output_section->vma
4401 + h->root.u.def.section->output_offset);
4402
4403 return DW_EH_PE_datarel | DW_EH_PE_sdata4;
4404 }
4405
4406
4407
4408 /* Look through the relocs for a section during the first phase.
4409
4410 Besides handling virtual table relocs for gc, we have to deal with
4411 all sorts of PIC-related relocations. We describe below the
4412 general plan on how to handle such relocations, even though we only
4413 collect information at this point, storing them in hash tables for
4414 perusal of later passes.
4415
4416 32 relocations are propagated to the linker output when creating
4417 position-independent output. LO16 and HI16 relocations are not
4418 supposed to be encountered in this case.
4419
4420 LABEL16 should always be resolvable by the linker, since it's only
4421 used by branches.
4422
4423 LABEL24, on the other hand, is used by calls. If it turns out that
4424 the target of a call is a dynamic symbol, a PLT entry must be
4425 created for it, which triggers the creation of a private function
4426 descriptor and, unless lazy binding is disabled, a lazy PLT entry.
4427
4428 GPREL relocations require the referenced symbol to be in the same
4429 segment as _gp, but this can only be checked later.
4430
4431 All GOT, GOTOFF and FUNCDESC relocations require a .got section to
4432 exist. LABEL24 might as well, since it may require a PLT entry,
4433 that will require a got.
4434
4435 Non-FUNCDESC GOT relocations require a GOT entry to be created
4436 regardless of whether the symbol is dynamic. However, since a
4437 global symbol that turns out to not be exported may have the same
4438 address of a non-dynamic symbol, we don't assign GOT entries at
4439 this point, such that we can share them in this case. A relocation
4440 for the GOT entry always has to be created, be it to offset a
4441 private symbol by the section load address, be it to get the symbol
4442 resolved dynamically.
4443
4444 FUNCDESC GOT relocations require a GOT entry to be created, and
4445 handled as if a FUNCDESC relocation was applied to the GOT entry in
4446 an object file.
4447
4448 FUNCDESC relocations referencing a symbol that turns out to NOT be
4449 dynamic cause a private function descriptor to be created. The
4450 FUNCDESC relocation then decays to a 32 relocation that points at
4451 the private descriptor. If the symbol is dynamic, the FUNCDESC
4452 relocation is propagated to the linker output, such that the
4453 dynamic linker creates the canonical descriptor, pointing to the
4454 dynamically-resolved definition of the function.
4455
4456 Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
4457 symbols that are assigned to the same segment as the GOT, but we
4458 can only check this later, after we know the complete set of
4459 symbols defined and/or exported.
4460
4461 FUNCDESC GOTOFF relocations require a function descriptor to be
4462 created and, unless lazy binding is disabled or the symbol is not
4463 dynamic, a lazy PLT entry. Since we can't tell at this point
4464 whether a symbol is going to be dynamic, we have to decide later
4465 whether to create a lazy PLT entry or bind the descriptor directly
4466 to the private function.
4467
4468 FUNCDESC_VALUE relocations are not supposed to be present in object
4469 files, but they may very well be simply propagated to the linker
4470 output, since they have no side effect.
4471
4472
4473 A function descriptor always requires a FUNCDESC_VALUE relocation.
4474 Whether it's in .plt.rel or not depends on whether lazy binding is
4475 enabled and on whether the referenced symbol is dynamic.
4476
4477 The existence of a lazy PLT requires the resolverStub lazy PLT
4478 entry to be present.
4479
4480
4481 As for assignment of GOT, PLT and lazy PLT entries, and private
4482 descriptors, we might do them all sequentially, but we can do
4483 better than that. For example, we can place GOT entries and
4484 private function descriptors referenced using 12-bit operands
4485 closer to the PIC register value, such that these relocations don't
4486 overflow. Those that are only referenced with LO16 relocations
4487 could come next, but we may as well place PLT-required function
4488 descriptors in the 12-bit range to make them shorter. Symbols
4489 referenced with LO16/HI16 may come next, but we may place
4490 additional function descriptors in the 16-bit range if we can
4491 reliably tell that we've already placed entries that are ever
4492 referenced with only LO16. PLT entries are therefore generated as
4493 small as possible, while not introducing relocation overflows in
4494 GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
4495 generated before or after PLT entries, but not intermingled with
4496 them, such that we can have more lazy PLT entries in range for a
4497 branch to the resolverStub. The resolverStub should be emitted at
4498 the most distant location from the first lazy PLT entry such that
4499 it's still in range for a branch, or closer, if there isn't a need
4500 for so many lazy PLT entries. Additional lazy PLT entries may be
4501 emitted after the resolverStub, as long as branches are still in
4502 range. If the branch goes out of range, longer lazy PLT entries
4503 are emitted.
4504
4505 We could further optimize PLT and lazy PLT entries by giving them
4506 priority in assignment to closer-to-gr17 locations depending on the
4507 number of occurrences of references to them (assuming a function
4508 that's called more often is more important for performance, so its
4509 PLT entry should be faster), or taking hints from the compiler.
4510 Given infinite time and money... :-) */
4511
4512 static bfd_boolean
4513 bfinfdpic_check_relocs (bfd *abfd, struct bfd_link_info *info,
4514 asection *sec, const Elf_Internal_Rela *relocs)
4515 {
4516 Elf_Internal_Shdr *symtab_hdr;
4517 struct elf_link_hash_entry **sym_hashes;
4518 const Elf_Internal_Rela *rel;
4519 const Elf_Internal_Rela *rel_end;
4520 bfd *dynobj;
4521 struct bfinfdpic_relocs_info *picrel;
4522
4523 if (bfd_link_relocatable (info))
4524 return TRUE;
4525
4526 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4527 sym_hashes = elf_sym_hashes (abfd);
4528
4529 dynobj = elf_hash_table (info)->dynobj;
4530 rel_end = relocs + sec->reloc_count;
4531 for (rel = relocs; rel < rel_end; rel++)
4532 {
4533 struct elf_link_hash_entry *h;
4534 unsigned long r_symndx;
4535
4536 r_symndx = ELF32_R_SYM (rel->r_info);
4537 if (r_symndx < symtab_hdr->sh_info)
4538 h = NULL;
4539 else
4540 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4541
4542 switch (ELF32_R_TYPE (rel->r_info))
4543 {
4544 case R_BFIN_GOT17M4:
4545 case R_BFIN_GOTHI:
4546 case R_BFIN_GOTLO:
4547 case R_BFIN_FUNCDESC_GOT17M4:
4548 case R_BFIN_FUNCDESC_GOTHI:
4549 case R_BFIN_FUNCDESC_GOTLO:
4550 case R_BFIN_GOTOFF17M4:
4551 case R_BFIN_GOTOFFHI:
4552 case R_BFIN_GOTOFFLO:
4553 case R_BFIN_FUNCDESC_GOTOFF17M4:
4554 case R_BFIN_FUNCDESC_GOTOFFHI:
4555 case R_BFIN_FUNCDESC_GOTOFFLO:
4556 case R_BFIN_FUNCDESC:
4557 case R_BFIN_FUNCDESC_VALUE:
4558 if (! IS_FDPIC (abfd))
4559 goto bad_reloc;
4560 /* Fall through. */
4561 case R_BFIN_PCREL24:
4562 case R_BFIN_PCREL24_JUMP_L:
4563 case R_BFIN_BYTE4_DATA:
4564 if (IS_FDPIC (abfd) && ! dynobj)
4565 {
4566 elf_hash_table (info)->dynobj = dynobj = abfd;
4567 if (! _bfin_create_got_section (abfd, info))
4568 return FALSE;
4569 }
4570 if (! IS_FDPIC (abfd))
4571 {
4572 picrel = NULL;
4573 break;
4574 }
4575 if (h != NULL)
4576 {
4577 if (h->dynindx == -1)
4578 switch (ELF_ST_VISIBILITY (h->other))
4579 {
4580 case STV_INTERNAL:
4581 case STV_HIDDEN:
4582 break;
4583 default:
4584 bfd_elf_link_record_dynamic_symbol (info, h);
4585 break;
4586 }
4587 picrel
4588 = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info),
4589 abfd, h,
4590 rel->r_addend, INSERT);
4591 }
4592 else
4593 picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info
4594 (info), abfd, r_symndx,
4595 rel->r_addend, INSERT);
4596 if (! picrel)
4597 return FALSE;
4598 break;
4599
4600 default:
4601 picrel = NULL;
4602 break;
4603 }
4604
4605 switch (ELF32_R_TYPE (rel->r_info))
4606 {
4607 case R_BFIN_PCREL24:
4608 case R_BFIN_PCREL24_JUMP_L:
4609 if (IS_FDPIC (abfd))
4610 picrel->call++;
4611 break;
4612
4613 case R_BFIN_FUNCDESC_VALUE:
4614 picrel->relocsfdv++;
4615 if (bfd_section_flags (sec) & SEC_ALLOC)
4616 picrel->relocs32--;
4617 /* Fall through. */
4618
4619 case R_BFIN_BYTE4_DATA:
4620 if (! IS_FDPIC (abfd))
4621 break;
4622
4623 picrel->sym++;
4624 if (bfd_section_flags (sec) & SEC_ALLOC)
4625 picrel->relocs32++;
4626 break;
4627
4628 case R_BFIN_GOT17M4:
4629 picrel->got17m4++;
4630 break;
4631
4632 case R_BFIN_GOTHI:
4633 case R_BFIN_GOTLO:
4634 picrel->gothilo++;
4635 break;
4636
4637 case R_BFIN_FUNCDESC_GOT17M4:
4638 picrel->fdgot17m4++;
4639 break;
4640
4641 case R_BFIN_FUNCDESC_GOTHI:
4642 case R_BFIN_FUNCDESC_GOTLO:
4643 picrel->fdgothilo++;
4644 break;
4645
4646 case R_BFIN_GOTOFF17M4:
4647 case R_BFIN_GOTOFFHI:
4648 case R_BFIN_GOTOFFLO:
4649 picrel->gotoff++;
4650 break;
4651
4652 case R_BFIN_FUNCDESC_GOTOFF17M4:
4653 picrel->fdgoff17m4++;
4654 break;
4655
4656 case R_BFIN_FUNCDESC_GOTOFFHI:
4657 case R_BFIN_FUNCDESC_GOTOFFLO:
4658 picrel->fdgoffhilo++;
4659 break;
4660
4661 case R_BFIN_FUNCDESC:
4662 picrel->fd++;
4663 picrel->relocsfd++;
4664 break;
4665
4666 /* This relocation describes the C++ object vtable hierarchy.
4667 Reconstruct it for later use during GC. */
4668 case R_BFIN_GNU_VTINHERIT:
4669 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4670 return FALSE;
4671 break;
4672
4673 /* This relocation describes which C++ vtable entries are actually
4674 used. Record for later use during GC. */
4675 case R_BFIN_GNU_VTENTRY:
4676 BFD_ASSERT (h != NULL);
4677 if (h != NULL
4678 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4679 return FALSE;
4680 break;
4681
4682 case R_BFIN_HUIMM16:
4683 case R_BFIN_LUIMM16:
4684 case R_BFIN_PCREL12_JUMP_S:
4685 case R_BFIN_PCREL10:
4686 break;
4687
4688 default:
4689 bad_reloc:
4690 _bfd_error_handler
4691 /* xgettext:c-format */
4692 (_("%pB: unsupported relocation type %#x"),
4693 abfd, (int) ELF32_R_TYPE (rel->r_info));
4694 return FALSE;
4695 }
4696 }
4697
4698 return TRUE;
4699 }
4700
4701 /* Set the right machine number for a Blackfin ELF file. */
4702
4703 static bfd_boolean
4704 elf32_bfin_object_p (bfd *abfd)
4705 {
4706 bfd_default_set_arch_mach (abfd, bfd_arch_bfin, 0);
4707 return (((elf_elfheader (abfd)->e_flags & EF_BFIN_FDPIC) != 0)
4708 == (IS_FDPIC (abfd)));
4709 }
4710
4711 static bfd_boolean
4712 elf32_bfin_set_private_flags (bfd * abfd, flagword flags)
4713 {
4714 elf_elfheader (abfd)->e_flags = flags;
4715 elf_flags_init (abfd) = TRUE;
4716 return TRUE;
4717 }
4718
4719 /* Display the flags field. */
4720 static bfd_boolean
4721 elf32_bfin_print_private_bfd_data (bfd * abfd, void * ptr)
4722 {
4723 FILE *file = (FILE *) ptr;
4724 flagword flags;
4725
4726 BFD_ASSERT (abfd != NULL && ptr != NULL);
4727
4728 /* Print normal ELF private data. */
4729 _bfd_elf_print_private_bfd_data (abfd, ptr);
4730
4731 flags = elf_elfheader (abfd)->e_flags;
4732
4733 /* xgettext:c-format */
4734 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
4735
4736 if (flags & EF_BFIN_PIC)
4737 fprintf (file, " -fpic");
4738
4739 if (flags & EF_BFIN_FDPIC)
4740 fprintf (file, " -mfdpic");
4741
4742 fputc ('\n', file);
4743
4744 return TRUE;
4745 }
4746
4747 /* Merge backend specific data from an object file to the output
4748 object file when linking. */
4749
4750 static bfd_boolean
4751 elf32_bfin_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4752 {
4753 bfd *obfd = info->output_bfd;
4754 flagword old_flags, new_flags;
4755 bfd_boolean error = FALSE;
4756
4757 new_flags = elf_elfheader (ibfd)->e_flags;
4758 old_flags = elf_elfheader (obfd)->e_flags;
4759
4760 if (new_flags & EF_BFIN_FDPIC)
4761 new_flags &= ~EF_BFIN_PIC;
4762
4763 #ifndef DEBUG
4764 if (0)
4765 #endif
4766 _bfd_error_handler
4767 ("old_flags = 0x%.8x, new_flags = 0x%.8x, init = %s, filename = %pB",
4768 old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no", ibfd);
4769
4770 if (!elf_flags_init (obfd)) /* First call, no flags set. */
4771 {
4772 elf_flags_init (obfd) = TRUE;
4773 elf_elfheader (obfd)->e_flags = new_flags;
4774 }
4775
4776 if (((new_flags & EF_BFIN_FDPIC) == 0) != (! IS_FDPIC (obfd)))
4777 {
4778 error = TRUE;
4779 if (IS_FDPIC (obfd))
4780 _bfd_error_handler
4781 (_("%pB: cannot link non-fdpic object file into fdpic executable"),
4782 ibfd);
4783 else
4784 _bfd_error_handler
4785 (_("%pB: cannot link fdpic object file into non-fdpic executable"),
4786 ibfd);
4787 }
4788
4789 if (error)
4790 bfd_set_error (bfd_error_bad_value);
4791
4792 return !error;
4793 }
4794 \f
4795 /* bfin ELF linker hash entry. */
4796
4797 struct bfin_link_hash_entry
4798 {
4799 struct elf_link_hash_entry root;
4800
4801 /* Number of PC relative relocs copied for this symbol. */
4802 struct bfin_pcrel_relocs_copied *pcrel_relocs_copied;
4803 };
4804
4805 /* bfin ELF linker hash table. */
4806
4807 struct bfin_link_hash_table
4808 {
4809 struct elf_link_hash_table root;
4810
4811 /* Small local sym cache. */
4812 struct sym_cache sym_cache;
4813 };
4814
4815 #define bfin_hash_entry(ent) ((struct bfin_link_hash_entry *) (ent))
4816
4817 static struct bfd_hash_entry *
4818 bfin_link_hash_newfunc (struct bfd_hash_entry *entry,
4819 struct bfd_hash_table *table, const char *string)
4820 {
4821 struct bfd_hash_entry *ret = entry;
4822
4823 /* Allocate the structure if it has not already been allocated by a
4824 subclass. */
4825 if (ret == NULL)
4826 ret = bfd_hash_allocate (table, sizeof (struct bfin_link_hash_entry));
4827 if (ret == NULL)
4828 return ret;
4829
4830 /* Call the allocation method of the superclass. */
4831 ret = _bfd_elf_link_hash_newfunc (ret, table, string);
4832 if (ret != NULL)
4833 bfin_hash_entry (ret)->pcrel_relocs_copied = NULL;
4834
4835 return ret;
4836 }
4837
4838 /* Create an bfin ELF linker hash table. */
4839
4840 static struct bfd_link_hash_table *
4841 bfin_link_hash_table_create (bfd * abfd)
4842 {
4843 struct bfin_link_hash_table *ret;
4844 bfd_size_type amt = sizeof (struct bfin_link_hash_table);
4845
4846 ret = bfd_zmalloc (amt);
4847 if (ret == NULL)
4848 return NULL;
4849
4850 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
4851 bfin_link_hash_newfunc,
4852 sizeof (struct elf_link_hash_entry),
4853 BFIN_ELF_DATA))
4854 {
4855 free (ret);
4856 return NULL;
4857 }
4858
4859 ret->sym_cache.abfd = NULL;
4860
4861 return &ret->root.root;
4862 }
4863
4864 /* The size in bytes of an entry in the procedure linkage table. */
4865
4866 /* Finish up the dynamic sections. */
4867
4868 static bfd_boolean
4869 bfin_finish_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
4870 struct bfd_link_info *info)
4871 {
4872 bfd *dynobj;
4873 asection *sdyn;
4874
4875 dynobj = elf_hash_table (info)->dynobj;
4876
4877 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4878
4879 if (elf_hash_table (info)->dynamic_sections_created)
4880 {
4881 Elf32_External_Dyn *dyncon, *dynconend;
4882
4883 BFD_ASSERT (sdyn != NULL);
4884
4885 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4886 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4887 for (; dyncon < dynconend; dyncon++)
4888 {
4889 Elf_Internal_Dyn dyn;
4890
4891 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4892
4893 }
4894
4895 }
4896 return TRUE;
4897 }
4898
4899 /* Finish up dynamic symbol handling. We set the contents of various
4900 dynamic sections here. */
4901
4902 static bfd_boolean
4903 bfin_finish_dynamic_symbol (bfd * output_bfd,
4904 struct bfd_link_info *info,
4905 struct elf_link_hash_entry *h,
4906 Elf_Internal_Sym * sym)
4907 {
4908 if (h->got.offset != (bfd_vma) - 1)
4909 {
4910 asection *sgot;
4911 asection *srela;
4912 Elf_Internal_Rela rela;
4913 bfd_byte *loc;
4914
4915 /* This symbol has an entry in the global offset table.
4916 Set it up. */
4917
4918 sgot = elf_hash_table (info)->sgot;
4919 srela = elf_hash_table (info)->srelgot;
4920 BFD_ASSERT (sgot != NULL && srela != NULL);
4921
4922 rela.r_offset = (sgot->output_section->vma
4923 + sgot->output_offset
4924 + (h->got.offset & ~(bfd_vma) 1));
4925
4926 /* If this is a -Bsymbolic link, and the symbol is defined
4927 locally, we just want to emit a RELATIVE reloc. Likewise if
4928 the symbol was forced to be local because of a version file.
4929 The entry in the global offset table will already have been
4930 initialized in the relocate_section function. */
4931 if (bfd_link_pic (info)
4932 && (info->symbolic
4933 || h->dynindx == -1 || h->forced_local) && h->def_regular)
4934 {
4935 _bfd_error_handler (_("*** check this relocation %s"),
4936 __FUNCTION__);
4937 rela.r_info = ELF32_R_INFO (0, R_BFIN_PCREL24);
4938 rela.r_addend = bfd_get_signed_32 (output_bfd,
4939 (sgot->contents
4940 +
4941 (h->got.
4942 offset & ~(bfd_vma) 1)));
4943 }
4944 else
4945 {
4946 bfd_put_32 (output_bfd, (bfd_vma) 0,
4947 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
4948 rela.r_info = ELF32_R_INFO (h->dynindx, R_BFIN_GOT);
4949 rela.r_addend = 0;
4950 }
4951
4952 loc = srela->contents;
4953 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
4954 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4955 }
4956
4957 if (h->needs_copy)
4958 {
4959 BFD_ASSERT (0);
4960 }
4961 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
4962 if (strcmp (h->root.root.string, "__DYNAMIC") == 0
4963 || h == elf_hash_table (info)->hgot)
4964 sym->st_shndx = SHN_ABS;
4965
4966 return TRUE;
4967 }
4968
4969 /* Adjust a symbol defined by a dynamic object and referenced by a
4970 regular object. The current definition is in some section of the
4971 dynamic object, but we're not including those sections. We have to
4972 change the definition to something the rest of the link can
4973 understand. */
4974
4975 static bfd_boolean
4976 bfin_adjust_dynamic_symbol (struct bfd_link_info *info,
4977 struct elf_link_hash_entry *h)
4978 {
4979 bfd *dynobj;
4980 asection *s;
4981 unsigned int power_of_two;
4982
4983 dynobj = elf_hash_table (info)->dynobj;
4984
4985 /* Make sure we know what is going on here. */
4986 BFD_ASSERT (dynobj != NULL
4987 && (h->needs_plt
4988 || h->is_weakalias
4989 || (h->def_dynamic && h->ref_regular && !h->def_regular)));
4990
4991 /* If this is a function, put it in the procedure linkage table. We
4992 will fill in the contents of the procedure linkage table later,
4993 when we know the address of the .got section. */
4994 if (h->type == STT_FUNC || h->needs_plt)
4995 {
4996 BFD_ASSERT(0);
4997 }
4998
4999 /* If this is a weak symbol, and there is a real definition, the
5000 processor independent code will have arranged for us to see the
5001 real definition first, and we can just use the same value. */
5002 if (h->is_weakalias)
5003 {
5004 struct elf_link_hash_entry *def = weakdef (h);
5005 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
5006 h->root.u.def.section = def->root.u.def.section;
5007 h->root.u.def.value = def->root.u.def.value;
5008 return TRUE;
5009 }
5010
5011 /* This is a reference to a symbol defined by a dynamic object which
5012 is not a function. */
5013
5014 /* If we are creating a shared library, we must presume that the
5015 only references to the symbol are via the global offset table.
5016 For such cases we need not do anything here; the relocations will
5017 be handled correctly by relocate_section. */
5018 if (bfd_link_pic (info))
5019 return TRUE;
5020
5021 /* We must allocate the symbol in our .dynbss section, which will
5022 become part of the .bss section of the executable. There will be
5023 an entry for this symbol in the .dynsym section. The dynamic
5024 object will contain position independent code, so all references
5025 from the dynamic object to this symbol will go through the global
5026 offset table. The dynamic linker will use the .dynsym entry to
5027 determine the address it must put in the global offset table, so
5028 both the dynamic object and the regular object will refer to the
5029 same memory location for the variable. */
5030
5031 s = bfd_get_linker_section (dynobj, ".dynbss");
5032 BFD_ASSERT (s != NULL);
5033
5034 #if 0 /* Bfin does not currently have a COPY reloc. */
5035 /* We must generate a R_BFIN_COPY reloc to tell the dynamic linker to
5036 copy the initial value out of the dynamic object and into the
5037 runtime process image. We need to remember the offset into the
5038 .rela.bss section we are going to use. */
5039 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
5040 {
5041 asection *srel;
5042
5043 srel = bfd_get_linker_section (dynobj, ".rela.bss");
5044 BFD_ASSERT (srel != NULL);
5045 srel->size += sizeof (Elf32_External_Rela);
5046 h->needs_copy = 1;
5047 }
5048 #else
5049 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
5050 {
5051 _bfd_error_handler (_("the bfin target does not currently support the generation of copy relocations"));
5052 return FALSE;
5053 }
5054 #endif
5055 /* We need to figure out the alignment required for this symbol. I
5056 have no idea how ELF linkers handle this. */
5057 power_of_two = bfd_log2 (h->size);
5058 if (power_of_two > 3)
5059 power_of_two = 3;
5060
5061 /* Apply the required alignment. */
5062 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
5063 if (power_of_two > bfd_section_alignment (s))
5064 {
5065 if (!bfd_set_section_alignment (s, power_of_two))
5066 return FALSE;
5067 }
5068
5069 /* Define the symbol as being at this point in the section. */
5070 h->root.u.def.section = s;
5071 h->root.u.def.value = s->size;
5072
5073 /* Increment the section size to make room for the symbol. */
5074 s->size += h->size;
5075
5076 return TRUE;
5077 }
5078
5079 /* The bfin linker needs to keep track of the number of relocs that it
5080 decides to copy in check_relocs for each symbol. This is so that it
5081 can discard PC relative relocs if it doesn't need them when linking
5082 with -Bsymbolic. We store the information in a field extending the
5083 regular ELF linker hash table. */
5084
5085 /* This structure keeps track of the number of PC relative relocs we have
5086 copied for a given symbol. */
5087
5088 struct bfin_pcrel_relocs_copied
5089 {
5090 /* Next section. */
5091 struct bfin_pcrel_relocs_copied *next;
5092 /* A section in dynobj. */
5093 asection *section;
5094 /* Number of relocs copied in this section. */
5095 bfd_size_type count;
5096 };
5097
5098 /* This function is called via elf_link_hash_traverse if we are
5099 creating a shared object. In the -Bsymbolic case it discards the
5100 space allocated to copy PC relative relocs against symbols which
5101 are defined in regular objects. For the normal shared case, it
5102 discards space for pc-relative relocs that have become local due to
5103 symbol visibility changes. We allocated space for them in the
5104 check_relocs routine, but we won't fill them in in the
5105 relocate_section routine.
5106
5107 We also check whether any of the remaining relocations apply
5108 against a readonly section, and set the DF_TEXTREL flag in this
5109 case. */
5110
5111 static bfd_boolean
5112 bfin_discard_copies (struct elf_link_hash_entry *h, void * inf)
5113 {
5114 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5115 struct bfin_pcrel_relocs_copied *s;
5116
5117 if (!h->def_regular || (!info->symbolic && !h->forced_local))
5118 {
5119 if ((info->flags & DF_TEXTREL) == 0)
5120 {
5121 /* Look for relocations against read-only sections. */
5122 for (s = bfin_hash_entry (h)->pcrel_relocs_copied;
5123 s != NULL; s = s->next)
5124 if ((s->section->flags & SEC_READONLY) != 0)
5125 {
5126 info->flags |= DF_TEXTREL;
5127 break;
5128 }
5129 }
5130
5131 return TRUE;
5132 }
5133
5134 for (s = bfin_hash_entry (h)->pcrel_relocs_copied;
5135 s != NULL; s = s->next)
5136 s->section->size -= s->count * sizeof (Elf32_External_Rela);
5137
5138 return TRUE;
5139 }
5140
5141 static bfd_boolean
5142 bfin_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
5143 struct bfd_link_info *info)
5144 {
5145 bfd *dynobj;
5146 asection *s;
5147 bfd_boolean relocs;
5148
5149 dynobj = elf_hash_table (info)->dynobj;
5150 BFD_ASSERT (dynobj != NULL);
5151
5152 if (elf_hash_table (info)->dynamic_sections_created)
5153 {
5154 /* Set the contents of the .interp section to the interpreter. */
5155 if (bfd_link_executable (info) && !info->nointerp)
5156 {
5157 s = bfd_get_linker_section (dynobj, ".interp");
5158 BFD_ASSERT (s != NULL);
5159 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5160 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5161 }
5162 }
5163 else
5164 {
5165 /* We may have created entries in the .rela.got section.
5166 However, if we are not creating the dynamic sections, we will
5167 not actually use these entries. Reset the size of .rela.got,
5168 which will cause it to get stripped from the output file
5169 below. */
5170 s = elf_hash_table (info)->srelgot;
5171 if (s != NULL)
5172 s->size = 0;
5173 }
5174
5175 /* If this is a -Bsymbolic shared link, then we need to discard all
5176 PC relative relocs against symbols defined in a regular object.
5177 For the normal shared case we discard the PC relative relocs
5178 against symbols that have become local due to visibility changes.
5179 We allocated space for them in the check_relocs routine, but we
5180 will not fill them in in the relocate_section routine. */
5181 if (bfd_link_pic (info))
5182 elf_link_hash_traverse (elf_hash_table (info),
5183 bfin_discard_copies, info);
5184
5185 /* The check_relocs and adjust_dynamic_symbol entry points have
5186 determined the sizes of the various dynamic sections. Allocate
5187 memory for them. */
5188 relocs = FALSE;
5189 for (s = dynobj->sections; s != NULL; s = s->next)
5190 {
5191 const char *name;
5192 bfd_boolean strip;
5193
5194 if ((s->flags & SEC_LINKER_CREATED) == 0)
5195 continue;
5196
5197 /* It's OK to base decisions on the section name, because none
5198 of the dynobj section names depend upon the input files. */
5199 name = bfd_section_name (s);
5200
5201 strip = FALSE;
5202
5203 if (CONST_STRNEQ (name, ".rela"))
5204 {
5205 if (s->size == 0)
5206 {
5207 /* If we don't need this section, strip it from the
5208 output file. This is mostly to handle .rela.bss and
5209 .rela.plt. We must create both sections in
5210 create_dynamic_sections, because they must be created
5211 before the linker maps input sections to output
5212 sections. The linker does that before
5213 adjust_dynamic_symbol is called, and it is that
5214 function which decides whether anything needs to go
5215 into these sections. */
5216 strip = TRUE;
5217 }
5218 else
5219 {
5220 relocs = TRUE;
5221
5222 /* We use the reloc_count field as a counter if we need
5223 to copy relocs into the output file. */
5224 s->reloc_count = 0;
5225 }
5226 }
5227 else if (! CONST_STRNEQ (name, ".got"))
5228 {
5229 /* It's not one of our sections, so don't allocate space. */
5230 continue;
5231 }
5232
5233 if (strip)
5234 {
5235 s->flags |= SEC_EXCLUDE;
5236 continue;
5237 }
5238
5239 /* Allocate memory for the section contents. */
5240 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
5241 Unused entries should be reclaimed before the section's contents
5242 are written out, but at the moment this does not happen. Thus in
5243 order to prevent writing out garbage, we initialise the section's
5244 contents to zero. */
5245 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
5246 if (s->contents == NULL && s->size != 0)
5247 return FALSE;
5248 }
5249
5250 if (elf_hash_table (info)->dynamic_sections_created)
5251 {
5252 /* Add some entries to the .dynamic section. We fill in the
5253 values later, in bfin_finish_dynamic_sections, but we
5254 must add the entries now so that we get the correct size for
5255 the .dynamic section. The DT_DEBUG entry is filled in by the
5256 dynamic linker and used by the debugger. */
5257 #define add_dynamic_entry(TAG, VAL) \
5258 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5259
5260 if (!bfd_link_pic (info))
5261 {
5262 if (!add_dynamic_entry (DT_DEBUG, 0))
5263 return FALSE;
5264 }
5265
5266
5267 if (relocs)
5268 {
5269 if (!add_dynamic_entry (DT_RELA, 0)
5270 || !add_dynamic_entry (DT_RELASZ, 0)
5271 || !add_dynamic_entry (DT_RELAENT,
5272 sizeof (Elf32_External_Rela)))
5273 return FALSE;
5274 }
5275
5276 if ((info->flags & DF_TEXTREL) != 0)
5277 {
5278 if (!add_dynamic_entry (DT_TEXTREL, 0))
5279 return FALSE;
5280 }
5281 }
5282 #undef add_dynamic_entry
5283
5284 return TRUE;
5285 }
5286 \f
5287 /* Given a .data section and a .emreloc in-memory section, store
5288 relocation information into the .emreloc section which can be
5289 used at runtime to relocate the section. This is called by the
5290 linker when the --embedded-relocs switch is used. This is called
5291 after the add_symbols entry point has been called for all the
5292 objects, and before the final_link entry point is called. */
5293
5294 bfd_boolean
5295 bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
5296 struct bfd_link_info *info,
5297 asection *datasec,
5298 asection *relsec,
5299 char **errmsg)
5300 {
5301 Elf_Internal_Shdr *symtab_hdr;
5302 Elf_Internal_Sym *isymbuf = NULL;
5303 Elf_Internal_Rela *internal_relocs = NULL;
5304 Elf_Internal_Rela *irel, *irelend;
5305 bfd_byte *p;
5306 bfd_size_type amt;
5307
5308 BFD_ASSERT (! bfd_link_relocatable (info));
5309
5310 *errmsg = NULL;
5311
5312 if (datasec->reloc_count == 0)
5313 return TRUE;
5314
5315 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5316
5317 /* Get a copy of the native relocations. */
5318 internal_relocs = (_bfd_elf_link_read_relocs
5319 (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL,
5320 info->keep_memory));
5321 if (internal_relocs == NULL)
5322 goto error_return;
5323
5324 amt = (bfd_size_type) datasec->reloc_count * 12;
5325 relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
5326 if (relsec->contents == NULL)
5327 goto error_return;
5328
5329 p = relsec->contents;
5330
5331 irelend = internal_relocs + datasec->reloc_count;
5332 for (irel = internal_relocs; irel < irelend; irel++, p += 12)
5333 {
5334 asection *targetsec;
5335
5336 /* We are going to write a four byte longword into the runtime
5337 reloc section. The longword will be the address in the data
5338 section which must be relocated. It is followed by the name
5339 of the target section NUL-padded or truncated to 8
5340 characters. */
5341
5342 /* We can only relocate absolute longword relocs at run time. */
5343 if (ELF32_R_TYPE (irel->r_info) != (int) R_BFIN_BYTE4_DATA)
5344 {
5345 *errmsg = _("unsupported relocation type");
5346 bfd_set_error (bfd_error_bad_value);
5347 goto error_return;
5348 }
5349
5350 /* Get the target section referred to by the reloc. */
5351 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
5352 {
5353 /* A local symbol. */
5354 Elf_Internal_Sym *isym;
5355
5356 /* Read this BFD's local symbols if we haven't done so already. */
5357 if (isymbuf == NULL)
5358 {
5359 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5360 if (isymbuf == NULL)
5361 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
5362 symtab_hdr->sh_info, 0,
5363 NULL, NULL, NULL);
5364 if (isymbuf == NULL)
5365 goto error_return;
5366 }
5367
5368 isym = isymbuf + ELF32_R_SYM (irel->r_info);
5369 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
5370 }
5371 else
5372 {
5373 unsigned long indx;
5374 struct elf_link_hash_entry *h;
5375
5376 /* An external symbol. */
5377 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
5378 h = elf_sym_hashes (abfd)[indx];
5379 BFD_ASSERT (h != NULL);
5380 if (h->root.type == bfd_link_hash_defined
5381 || h->root.type == bfd_link_hash_defweak)
5382 targetsec = h->root.u.def.section;
5383 else
5384 targetsec = NULL;
5385 }
5386
5387 bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
5388 memset (p + 4, 0, 8);
5389 if (targetsec != NULL)
5390 strncpy ((char *) p + 4, targetsec->output_section->name, 8);
5391 }
5392
5393 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
5394 free (isymbuf);
5395 if (internal_relocs != NULL
5396 && elf_section_data (datasec)->relocs != internal_relocs)
5397 free (internal_relocs);
5398 return TRUE;
5399
5400 error_return:
5401 if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
5402 free (isymbuf);
5403 if (internal_relocs != NULL
5404 && elf_section_data (datasec)->relocs != internal_relocs)
5405 free (internal_relocs);
5406 return FALSE;
5407 }
5408
5409 struct bfd_elf_special_section const elf32_bfin_special_sections[] =
5410 {
5411 { ".l1.text", 8, -2, SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
5412 { ".l1.data", 8, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
5413 { NULL, 0, 0, 0, 0 }
5414 };
5415
5416 \f
5417 #define TARGET_LITTLE_SYM bfin_elf32_vec
5418 #define TARGET_LITTLE_NAME "elf32-bfin"
5419 #define ELF_ARCH bfd_arch_bfin
5420 #define ELF_TARGET_ID BFIN_ELF_DATA
5421 #define ELF_MACHINE_CODE EM_BLACKFIN
5422 #define ELF_MAXPAGESIZE 0x1000
5423 #define elf_symbol_leading_char '_'
5424
5425 #define bfd_elf32_bfd_reloc_type_lookup bfin_bfd_reloc_type_lookup
5426 #define bfd_elf32_bfd_reloc_name_lookup \
5427 bfin_bfd_reloc_name_lookup
5428 #define elf_info_to_howto bfin_info_to_howto
5429 #define elf_info_to_howto_rel NULL
5430 #define elf_backend_object_p elf32_bfin_object_p
5431
5432 #define bfd_elf32_bfd_is_local_label_name \
5433 bfin_is_local_label_name
5434 #define bfin_hash_table(p) \
5435 ((struct bfin_link_hash_table *) (p)->hash)
5436
5437
5438
5439 #define elf_backend_create_dynamic_sections \
5440 _bfd_elf_create_dynamic_sections
5441 #define bfd_elf32_bfd_link_hash_table_create \
5442 bfin_link_hash_table_create
5443 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link
5444
5445 #define elf_backend_check_relocs bfin_check_relocs
5446 #define elf_backend_adjust_dynamic_symbol \
5447 bfin_adjust_dynamic_symbol
5448 #define elf_backend_size_dynamic_sections \
5449 bfin_size_dynamic_sections
5450 #define elf_backend_relocate_section bfin_relocate_section
5451 #define elf_backend_finish_dynamic_symbol \
5452 bfin_finish_dynamic_symbol
5453 #define elf_backend_finish_dynamic_sections \
5454 bfin_finish_dynamic_sections
5455 #define elf_backend_gc_mark_hook bfin_gc_mark_hook
5456 #define bfd_elf32_bfd_merge_private_bfd_data \
5457 elf32_bfin_merge_private_bfd_data
5458 #define bfd_elf32_bfd_set_private_flags \
5459 elf32_bfin_set_private_flags
5460 #define bfd_elf32_bfd_print_private_bfd_data \
5461 elf32_bfin_print_private_bfd_data
5462 #define elf_backend_final_write_processing \
5463 elf32_bfin_final_write_processing
5464 #define elf_backend_reloc_type_class elf32_bfin_reloc_type_class
5465 #define elf_backend_stack_align 8
5466 #define elf_backend_can_gc_sections 1
5467 #define elf_backend_special_sections elf32_bfin_special_sections
5468 #define elf_backend_can_refcount 1
5469 #define elf_backend_want_got_plt 0
5470 #define elf_backend_plt_readonly 1
5471 #define elf_backend_want_plt_sym 0
5472 #define elf_backend_got_header_size 12
5473 #define elf_backend_rela_normal 1
5474
5475 #include "elf32-target.h"
5476
5477 #undef TARGET_LITTLE_SYM
5478 #define TARGET_LITTLE_SYM bfin_elf32_fdpic_vec
5479 #undef TARGET_LITTLE_NAME
5480 #define TARGET_LITTLE_NAME "elf32-bfinfdpic"
5481 #undef elf32_bed
5482 #define elf32_bed elf32_bfinfdpic_bed
5483
5484 #undef elf_backend_got_header_size
5485 #define elf_backend_got_header_size 0
5486
5487 #undef elf_backend_relocate_section
5488 #define elf_backend_relocate_section bfinfdpic_relocate_section
5489 #undef elf_backend_check_relocs
5490 #define elf_backend_check_relocs bfinfdpic_check_relocs
5491
5492 #undef bfd_elf32_bfd_link_hash_table_create
5493 #define bfd_elf32_bfd_link_hash_table_create \
5494 bfinfdpic_elf_link_hash_table_create
5495 #undef elf_backend_always_size_sections
5496 #define elf_backend_always_size_sections \
5497 elf32_bfinfdpic_always_size_sections
5498
5499 #undef elf_backend_create_dynamic_sections
5500 #define elf_backend_create_dynamic_sections \
5501 elf32_bfinfdpic_create_dynamic_sections
5502 #undef elf_backend_adjust_dynamic_symbol
5503 #define elf_backend_adjust_dynamic_symbol \
5504 elf32_bfinfdpic_adjust_dynamic_symbol
5505 #undef elf_backend_size_dynamic_sections
5506 #define elf_backend_size_dynamic_sections \
5507 elf32_bfinfdpic_size_dynamic_sections
5508 #undef elf_backend_finish_dynamic_symbol
5509 #define elf_backend_finish_dynamic_symbol \
5510 elf32_bfinfdpic_finish_dynamic_symbol
5511 #undef elf_backend_finish_dynamic_sections
5512 #define elf_backend_finish_dynamic_sections \
5513 elf32_bfinfdpic_finish_dynamic_sections
5514
5515 #undef elf_backend_discard_info
5516 #define elf_backend_discard_info \
5517 bfinfdpic_elf_discard_info
5518 #undef elf_backend_can_make_relative_eh_frame
5519 #define elf_backend_can_make_relative_eh_frame \
5520 bfinfdpic_elf_use_relative_eh_frame
5521 #undef elf_backend_can_make_lsda_relative_eh_frame
5522 #define elf_backend_can_make_lsda_relative_eh_frame \
5523 bfinfdpic_elf_use_relative_eh_frame
5524 #undef elf_backend_encode_eh_address
5525 #define elf_backend_encode_eh_address \
5526 bfinfdpic_elf_encode_eh_address
5527
5528 #undef elf_backend_may_use_rel_p
5529 #define elf_backend_may_use_rel_p 1
5530 #undef elf_backend_may_use_rela_p
5531 #define elf_backend_may_use_rela_p 1
5532 /* We use REL for dynamic relocations only. */
5533 #undef elf_backend_default_use_rela_p
5534 #define elf_backend_default_use_rela_p 1
5535
5536 #undef elf_backend_omit_section_dynsym
5537 #define elf_backend_omit_section_dynsym _bfinfdpic_link_omit_section_dynsym
5538
5539 #include "elf32-target.h"