1 /* 32-bit ELF support for S+core.
2 Copyright (C) 2006-2016 Free Software Foundation, Inc.
4 Brain.lin (brain.lin@sunplusct.com)
5 Mei Ligang (ligang@sunnorth.com.cn)
6 Pei-Lin Tsai (pltsai@sunplus.com)
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
28 #include "libiberty.h"
30 #include "elf/score.h"
31 #include "elf/common.h"
32 #include "elf/internal.h"
34 #include "elf32-score.h"
40 /* The SCORE ELF linker needs additional information for each symbol in
41 the global hash table. */
42 struct score_elf_link_hash_entry
44 struct elf_link_hash_entry root;
46 /* Number of R_SCORE_ABS32, R_SCORE_REL32 relocs against this symbol. */
47 unsigned int possibly_dynamic_relocs;
49 /* If the R_SCORE_ABS32, R_SCORE_REL32 reloc is against a readonly section. */
50 bfd_boolean readonly_reloc;
52 /* We must not create a stub for a symbol that has relocations related to
53 taking the function's address, i.e. any but R_SCORE_CALL15 ones. */
54 bfd_boolean no_fn_stub;
56 /* Are we forced local? This will only be set if we have converted
57 the initial global GOT entry to a local GOT entry. */
58 bfd_boolean forced_local;
61 /* Traverse a score ELF linker hash table. */
62 #define score_elf_link_hash_traverse(table, func, info) \
63 (elf_link_hash_traverse \
65 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
68 /* This structure is used to hold .got entries while estimating got sizes. */
69 struct score_got_entry
71 /* The input bfd in which the symbol is defined. */
73 /* The index of the symbol, as stored in the relocation r_info, if
74 we have a local symbol; -1 otherwise. */
78 /* If abfd == NULL, an address that must be stored in the got. */
80 /* If abfd != NULL && symndx != -1, the addend of the relocation
81 that should be added to the symbol value. */
83 /* If abfd != NULL && symndx == -1, the hash table entry
84 corresponding to a global symbol in the got (or, local, if
86 struct score_elf_link_hash_entry *h;
89 /* The offset from the beginning of the .got section to the entry
90 corresponding to this symbol+addend. If it's a global symbol
91 whose offset is yet to be decided, it's going to be -1. */
95 /* This structure is passed to score_elf_sort_hash_table_f when sorting
96 the dynamic symbols. */
98 struct score_elf_hash_sort_data
100 /* The symbol in the global GOT with the lowest dynamic symbol table index. */
101 struct elf_link_hash_entry *low;
102 /* The least dynamic symbol table index corresponding to a symbol with a GOT entry. */
103 long min_got_dynindx;
104 /* The greatest dynamic symbol table index corresponding to a symbol
105 with a GOT entry that is not referenced (e.g., a dynamic symbol
106 with dynamic relocations pointing to it from non-primary GOTs). */
107 long max_unref_got_dynindx;
108 /* The greatest dynamic symbol table index not corresponding to a
109 symbol without a GOT entry. */
110 long max_non_got_dynindx;
113 struct score_got_info
115 /* The global symbol in the GOT with the lowest index in the dynamic
117 struct elf_link_hash_entry *global_gotsym;
118 /* The number of global .got entries. */
119 unsigned int global_gotno;
120 /* The number of local .got entries. */
121 unsigned int local_gotno;
122 /* The number of local .got entries we have used. */
123 unsigned int assigned_gotno;
124 /* A hash table holding members of the got. */
125 struct htab *got_entries;
126 /* In multi-got links, a pointer to the next got (err, rather, most
127 of the time, it points to the previous got). */
128 struct score_got_info *next;
131 /* A structure used to count GOT entries, for GOT entry or ELF symbol table traversal. */
132 struct _score_elf_section_data
134 struct bfd_elf_section_data elf;
137 struct score_got_info *got_info;
143 #define score_elf_section_data(sec) \
144 ((struct _score_elf_section_data *) elf_section_data (sec))
146 /* The size of a symbol-table entry. */
147 #define SCORE_ELF_SYM_SIZE(abfd) \
148 (get_elf_backend_data (abfd)->s->sizeof_sym)
150 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
151 from smaller values. Start with zero, widen, *then* decrement. */
152 #define MINUS_ONE (((bfd_vma)0) - 1)
153 #define MINUS_TWO (((bfd_vma)0) - 2)
158 /* The number of local .got entries we reserve. */
159 #define SCORE_RESERVED_GOTNO (2)
160 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
162 /* The offset of $gp from the beginning of the .got section. */
163 #define ELF_SCORE_GP_OFFSET(abfd) (0x3ff0)
164 /* The maximum size of the GOT for it to be addressable using 15-bit offsets from $gp. */
165 #define SCORE_ELF_GOT_MAX_SIZE(abfd) (ELF_SCORE_GP_OFFSET(abfd) + 0x3fff)
167 #define SCORE_ELF_STUB_SECTION_NAME (".SCORE.stub")
168 #define SCORE_FUNCTION_STUB_SIZE (16)
170 #define STUB_LW 0xc3bcc010 /* lw r29, [r28, -0x3ff0] */
171 #define STUB_MOVE 0x8363bc56 /* mv r27, r3 */
172 #define STUB_LI16 0x87548000 /* ori r26, .dynsym_index */
173 #define STUB_BRL 0x801dbc09 /* brl r29 */
175 #define SCORE_ELF_GOT_SIZE(abfd) \
176 (get_elf_backend_data (abfd)->s->arch_size / 8)
178 #define SCORE_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
179 (_bfd_elf_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
181 /* The size of an external dynamic table entry. */
182 #define SCORE_ELF_DYN_SIZE(abfd) \
183 (get_elf_backend_data (abfd)->s->sizeof_dyn)
185 /* The size of an external REL relocation. */
186 #define SCORE_ELF_REL_SIZE(abfd) \
187 (get_elf_backend_data (abfd)->s->sizeof_rel)
189 /* The default alignment for sections, as a power of two. */
190 #define SCORE_ELF_LOG_FILE_ALIGN(abfd)\
191 (get_elf_backend_data (abfd)->s->log_file_align)
193 static bfd_byte *hi16_rel_addr;
195 /* This will be used when we sort the dynamic relocation records. */
196 static bfd *reldyn_sorting_bfd;
198 /* SCORE ELF uses two common sections. One is the usual one, and the
199 other is for small objects. All the small objects are kept
200 together, and then referenced via the gp pointer, which yields
201 faster assembler code. This is what we use for the small common
202 section. This approach is copied from ecoff.c. */
203 static asection score_elf_scom_section;
204 static asymbol score_elf_scom_symbol;
205 static asymbol *score_elf_scom_symbol_ptr;
208 score_bfd_get_16 (bfd *abfd, const void *data)
210 return bfd_get_16 (abfd, data);
214 score3_bfd_getl32 (const void *p)
216 const bfd_byte *addr = p;
219 v = (unsigned long) addr[2];
220 v |= (unsigned long) addr[3] << 8;
221 v |= (unsigned long) addr[0] << 16;
222 v |= (unsigned long) addr[1] << 24;
227 score3_bfd_getl48 (const void *p)
229 const bfd_byte *addr = p;
230 unsigned long long v;
232 v = (unsigned long long) addr[4];
233 v |= (unsigned long long) addr[5] << 8;
234 v |= (unsigned long long) addr[2] << 16;
235 v |= (unsigned long long) addr[3] << 24;
236 v |= (unsigned long long) addr[0] << 32;
237 v |= (unsigned long long) addr[1] << 40;
242 score_bfd_get_32 (bfd *abfd, const void *data)
244 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
245 return score3_bfd_getl32 (data);
247 return bfd_get_32 (abfd, data);
251 score_bfd_get_48 (bfd *abfd, const void *p)
253 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
254 return score3_bfd_getl48 (p);
256 return bfd_get_bits (p, 48, 1);
260 score_bfd_put_16 (bfd *abfd, bfd_vma addr, void *data)
262 return bfd_put_16 (abfd, addr, data);
266 score3_bfd_putl32 (bfd_vma data, void *p)
269 addr[0] = (data >> 16) & 0xff;
270 addr[1] = (data >> 24) & 0xff;
271 addr[2] = data & 0xff;
272 addr[3] = (data >> 8) & 0xff;
276 score3_bfd_putl48 (bfd_vma data, void *p)
279 addr[0] = (data >> 32) & 0xff;
280 addr[1] = (data >> 40) & 0xff;
281 addr[2] = (data >> 16) & 0xff;
282 addr[3] = (data >> 24) & 0xff;
283 addr[4] = data & 0xff;
284 addr[5] = (data >> 8) & 0xff;
288 score_bfd_put_32 (bfd *abfd, bfd_vma addr, void *data)
290 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
291 return score3_bfd_putl32 (addr, data);
293 return bfd_put_32 (abfd, addr, data);
297 score_bfd_put_48 (bfd *abfd, bfd_vma val, void *p)
299 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
300 return score3_bfd_putl48 (val, p);
302 return bfd_put_bits (val, p, 48, 1);
305 static bfd_reloc_status_type
306 score_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
307 arelent *reloc_entry,
308 asymbol *symbol ATTRIBUTE_UNUSED,
310 asection *input_section ATTRIBUTE_UNUSED,
311 bfd *output_bfd ATTRIBUTE_UNUSED,
312 char **error_message ATTRIBUTE_UNUSED)
314 hi16_rel_addr = (bfd_byte *) data + reloc_entry->address;
318 static bfd_reloc_status_type
319 score_elf_lo16_reloc (bfd *abfd,
320 arelent *reloc_entry,
321 asymbol *symbol ATTRIBUTE_UNUSED,
323 asection *input_section,
324 bfd *output_bfd ATTRIBUTE_UNUSED,
325 char **error_message ATTRIBUTE_UNUSED)
327 bfd_vma addend = 0, offset = 0;
329 unsigned long hi16_offset, hi16_value, uvalue;
331 hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
332 hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
333 addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
334 offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
335 val = reloc_entry->addend;
336 if (reloc_entry->address > input_section->size)
337 return bfd_reloc_outofrange;
338 uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
339 hi16_offset = (uvalue >> 16) << 1;
340 hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
341 score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
342 offset = (uvalue & 0xffff) << 1;
343 addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
344 score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
348 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
349 dangerous relocation. */
352 score_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
358 /* If we've already figured out what GP will be, just return it. */
359 *pgp = _bfd_get_gp_value (output_bfd);
363 count = bfd_get_symcount (output_bfd);
364 sym = bfd_get_outsymbols (output_bfd);
366 /* The linker script will have created a symbol named `_gp' with the
367 appropriate value. */
372 for (i = 0; i < count; i++, sym++)
376 name = bfd_asymbol_name (*sym);
377 if (*name == '_' && strcmp (name, "_gp") == 0)
379 *pgp = bfd_asymbol_value (*sym);
380 _bfd_set_gp_value (output_bfd, *pgp);
388 /* Only get the error once. */
390 _bfd_set_gp_value (output_bfd, *pgp);
397 /* We have to figure out the gp value, so that we can adjust the
398 symbol value correctly. We look up the symbol _gp in the output
399 BFD. If we can't find it, we're stuck. We cache it in the ELF
400 target data. We don't need to adjust the symbol value for an
401 external symbol if we are producing relocatable output. */
402 static bfd_reloc_status_type
403 score_elf_final_gp (bfd *output_bfd,
405 bfd_boolean relocatable,
406 char **error_message,
409 if (bfd_is_und_section (symbol->section)
413 return bfd_reloc_undefined;
416 *pgp = _bfd_get_gp_value (output_bfd);
419 || (symbol->flags & BSF_SECTION_SYM) != 0))
423 /* Make up a value. */
424 *pgp = symbol->section->output_section->vma + 0x4000;
425 _bfd_set_gp_value (output_bfd, *pgp);
427 else if (!score_elf_assign_gp (output_bfd, pgp))
430 (char *) _("GP relative relocation when _gp not defined");
431 return bfd_reloc_dangerous;
438 static bfd_reloc_status_type
439 score_elf_gprel15_with_gp (bfd *abfd,
441 arelent *reloc_entry,
442 asection *input_section,
443 bfd_boolean relocateable,
445 bfd_vma gp ATTRIBUTE_UNUSED)
450 if (bfd_is_com_section (symbol->section))
453 relocation = symbol->value;
455 relocation += symbol->section->output_section->vma;
456 relocation += symbol->section->output_offset;
457 if (reloc_entry->address > input_section->size)
458 return bfd_reloc_outofrange;
460 insn = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
461 if (((reloc_entry->addend & 0xffffc000) != 0)
462 && ((reloc_entry->addend & 0xffffc000) != 0xffffc000))
463 return bfd_reloc_overflow;
465 insn = (insn & ~0x7fff) | (reloc_entry->addend & 0x7fff);
466 score_bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
468 reloc_entry->address += input_section->output_offset;
473 static bfd_reloc_status_type
474 gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
475 asection *input_section, bfd_boolean relocatable,
476 void *data, bfd_vma gp)
481 if (bfd_is_com_section (symbol->section))
484 relocation = symbol->value;
486 relocation += symbol->section->output_section->vma;
487 relocation += symbol->section->output_offset;
489 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
490 return bfd_reloc_outofrange;
492 /* Set val to the offset into the section or symbol. */
493 val = reloc_entry->addend;
495 if (reloc_entry->howto->partial_inplace)
496 val += score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
498 /* Adjust val for the final section location and GP value. If we
499 are producing relocatable output, we don't want to do this for
500 an external symbol. */
502 || (symbol->flags & BSF_SECTION_SYM) != 0)
503 val += relocation - gp;
505 if (reloc_entry->howto->partial_inplace)
506 score_bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
508 reloc_entry->addend = val;
511 reloc_entry->address += input_section->output_offset;
516 static bfd_reloc_status_type
517 score_elf_gprel15_reloc (bfd *abfd,
518 arelent *reloc_entry,
521 asection *input_section,
523 char **error_message)
525 bfd_boolean relocateable;
526 bfd_reloc_status_type ret;
529 if (output_bfd != NULL
530 && (symbol->flags & BSF_SECTION_SYM) == 0 && reloc_entry->addend == 0)
532 reloc_entry->address += input_section->output_offset;
535 if (output_bfd != NULL)
539 relocateable = FALSE;
540 output_bfd = symbol->section->output_section->owner;
543 ret = score_elf_final_gp (output_bfd, symbol, relocateable, error_message, &gp);
544 if (ret != bfd_reloc_ok)
547 return score_elf_gprel15_with_gp (abfd, symbol, reloc_entry,
548 input_section, relocateable, data, gp);
551 /* Do a R_SCORE_GPREL32 relocation. This is a 32 bit value which must
552 become the offset from the gp register. */
554 static bfd_reloc_status_type
555 score_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
556 void *data, asection *input_section, bfd *output_bfd,
557 char **error_message)
559 bfd_boolean relocatable;
560 bfd_reloc_status_type ret;
563 /* R_SCORE_GPREL32 relocations are defined for local symbols only. */
564 if (output_bfd != NULL
565 && (symbol->flags & BSF_SECTION_SYM) == 0
566 && (symbol->flags & BSF_LOCAL) != 0)
568 *error_message = (char *)
569 _("32bits gp relative relocation occurs for an external symbol");
570 return bfd_reloc_outofrange;
573 if (output_bfd != NULL)
578 output_bfd = symbol->section->output_section->owner;
581 ret = score_elf_final_gp (output_bfd, symbol, relocatable, error_message, &gp);
582 if (ret != bfd_reloc_ok)
586 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
587 relocatable, data, gp);
590 /* A howto special_function for R_SCORE_GOT15 relocations. This is just
591 like any other 16-bit relocation when applied to global symbols, but is
592 treated in the same as R_SCORE_HI16 when applied to local symbols. */
593 static bfd_reloc_status_type
594 score_elf_got15_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
595 void *data, asection *input_section,
596 bfd *output_bfd, char **error_message)
598 if ((symbol->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
599 || bfd_is_und_section (bfd_get_section (symbol))
600 || bfd_is_com_section (bfd_get_section (symbol)))
601 /* The relocation is against a global symbol. */
602 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
603 input_section, output_bfd,
606 return score_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
607 input_section, output_bfd, error_message);
610 static bfd_reloc_status_type
611 score_elf_got_lo16_reloc (bfd *abfd,
612 arelent *reloc_entry,
613 asymbol *symbol ATTRIBUTE_UNUSED,
615 asection *input_section,
616 bfd *output_bfd ATTRIBUTE_UNUSED,
617 char **error_message ATTRIBUTE_UNUSED)
619 bfd_vma addend = 0, offset = 0;
621 signed long hi16_offset, hi16_value, uvalue;
623 hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
624 hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
625 addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
626 offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
627 val = reloc_entry->addend;
628 if (reloc_entry->address > input_section->size)
629 return bfd_reloc_outofrange;
630 uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
631 if ((uvalue > -0x8000) && (uvalue < 0x7fff))
634 hi16_offset = (uvalue >> 16) & 0x7fff;
635 hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
636 score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
637 offset = (uvalue & 0xffff) << 1;
638 addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
639 score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
643 static reloc_howto_type elf32_score_howto_table[] =
646 HOWTO (R_SCORE_NONE, /* type */
648 3, /* size (0 = byte, 1 = short, 2 = long) */
650 FALSE, /* pc_relative */
652 complain_overflow_dont,/* complain_on_overflow */
653 bfd_elf_generic_reloc, /* special_function */
654 "R_SCORE_NONE", /* name */
655 FALSE, /* partial_inplace */
658 FALSE), /* pcrel_offset */
661 HOWTO (R_SCORE_HI16, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 FALSE, /* pc_relative */
667 complain_overflow_dont,/* complain_on_overflow */
668 score_elf_hi16_reloc, /* special_function */
669 "R_SCORE_HI16", /* name */
670 TRUE, /* partial_inplace */
671 0x37fff, /* src_mask */
672 0x37fff, /* dst_mask */
673 FALSE), /* pcrel_offset */
676 HOWTO (R_SCORE_LO16, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE, /* pc_relative */
682 complain_overflow_dont,/* complain_on_overflow */
683 score_elf_lo16_reloc, /* special_function */
684 "R_SCORE_LO16", /* name */
685 TRUE, /* partial_inplace */
686 0x37fff, /* src_mask */
687 0x37fff, /* dst_mask */
688 FALSE), /* pcrel_offset */
691 HOWTO (R_SCORE_BCMP, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE, /* pc_relative */
697 complain_overflow_dont,/* complain_on_overflow */
698 bfd_elf_generic_reloc, /* special_function */
699 "R_SCORE_BCMP", /* name */
700 FALSE, /* partial_inplace */
701 0x03e00381, /* src_mask */
702 0x03e00381, /* dst_mask */
703 FALSE), /* pcrel_offset */
706 HOWTO (R_SCORE_24, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE, /* pc_relative */
712 complain_overflow_dont,/* complain_on_overflow */
713 bfd_elf_generic_reloc, /* special_function */
714 "R_SCORE_24", /* name */
715 FALSE, /* partial_inplace */
716 0x3ff7fff, /* src_mask */
717 0x3ff7fff, /* dst_mask */
718 FALSE), /* pcrel_offset */
721 HOWTO (R_SCORE_PC19, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 TRUE, /* pc_relative */
727 complain_overflow_dont,/* complain_on_overflow */
728 bfd_elf_generic_reloc, /* special_function */
729 "R_SCORE_PC19", /* name */
730 FALSE, /* partial_inplace */
731 0x3ff03fe, /* src_mask */
732 0x3ff03fe, /* dst_mask */
733 FALSE), /* pcrel_offset */
736 HOWTO (R_SCORE16_11, /* type */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE, /* pc_relative */
742 complain_overflow_dont,/* complain_on_overflow */
743 bfd_elf_generic_reloc, /* special_function */
744 "R_SCORE16_11", /* name */
745 FALSE, /* partial_inplace */
746 0x000000ffe, /* src_mask */
747 0x000000ffe, /* dst_mask */
748 FALSE), /* pcrel_offset */
751 HOWTO (R_SCORE16_PC8, /* type */
753 1, /* size (0 = byte, 1 = short, 2 = long) */
755 TRUE, /* pc_relative */
757 complain_overflow_dont,/* complain_on_overflow */
758 bfd_elf_generic_reloc, /* special_function */
759 "R_SCORE16_PC8", /* name */
760 FALSE, /* partial_inplace */
761 0x000001ff, /* src_mask */
762 0x000001ff, /* dst_mask */
763 FALSE), /* pcrel_offset */
765 /* 32 bit absolute */
766 HOWTO (R_SCORE_ABS32, /* type 8 */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 FALSE, /* pc_relative */
772 complain_overflow_bitfield, /* complain_on_overflow */
773 bfd_elf_generic_reloc, /* special_function */
774 "R_SCORE_ABS32", /* name */
775 FALSE, /* partial_inplace */
776 0xffffffff, /* src_mask */
777 0xffffffff, /* dst_mask */
778 FALSE), /* pcrel_offset */
780 /* 16 bit absolute */
781 HOWTO (R_SCORE_ABS16, /* type 11 */
783 1, /* size (0 = byte, 1 = short, 2 = long) */
785 FALSE, /* pc_relative */
787 complain_overflow_bitfield, /* complain_on_overflow */
788 bfd_elf_generic_reloc, /* special_function */
789 "R_SCORE_ABS16", /* name */
790 FALSE, /* partial_inplace */
791 0x0000ffff, /* src_mask */
792 0x0000ffff, /* dst_mask */
793 FALSE), /* pcrel_offset */
796 HOWTO (R_SCORE_DUMMY2, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 FALSE, /* pc_relative */
802 complain_overflow_dont,/* complain_on_overflow */
803 bfd_elf_generic_reloc, /* special_function */
804 "R_SCORE_DUMMY2", /* name */
805 TRUE, /* partial_inplace */
806 0x00007fff, /* src_mask */
807 0x00007fff, /* dst_mask */
808 FALSE), /* pcrel_offset */
811 HOWTO (R_SCORE_GP15, /* type */
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE, /* pc_relative */
817 complain_overflow_dont,/* complain_on_overflow */
818 score_elf_gprel15_reloc,/* special_function */
819 "R_SCORE_GP15", /* name */
820 TRUE, /* partial_inplace */
821 0x00007fff, /* src_mask */
822 0x00007fff, /* dst_mask */
823 FALSE), /* pcrel_offset */
825 /* GNU extension to record C++ vtable hierarchy. */
826 HOWTO (R_SCORE_GNU_VTINHERIT, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE, /* pc_relative */
832 complain_overflow_dont,/* complain_on_overflow */
833 NULL, /* special_function */
834 "R_SCORE_GNU_VTINHERIT", /* name */
835 FALSE, /* partial_inplace */
838 FALSE), /* pcrel_offset */
840 /* GNU extension to record C++ vtable member usage */
841 HOWTO (R_SCORE_GNU_VTENTRY, /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE, /* pc_relative */
847 complain_overflow_dont,/* complain_on_overflow */
848 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
849 "R_SCORE_GNU_VTENTRY", /* name */
850 FALSE, /* partial_inplace */
853 FALSE), /* pcrel_offset */
855 /* Reference to global offset table. */
856 HOWTO (R_SCORE_GOT15, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE, /* pc_relative */
862 complain_overflow_signed, /* complain_on_overflow */
863 score_elf_got15_reloc, /* special_function */
864 "R_SCORE_GOT15", /* name */
865 TRUE, /* partial_inplace */
866 0x00007fff, /* src_mask */
867 0x00007fff, /* dst_mask */
868 FALSE), /* pcrel_offset */
870 /* Low 16 bits of displacement in global offset table. */
871 HOWTO (R_SCORE_GOT_LO16, /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_dont,/* complain_on_overflow */
878 score_elf_got_lo16_reloc, /* special_function */
879 "R_SCORE_GOT_LO16", /* name */
880 TRUE, /* partial_inplace */
881 0x37ffe, /* src_mask */
882 0x37ffe, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 /* 15 bit call through global offset table. */
886 HOWTO (R_SCORE_CALL15, /* type */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE, /* pc_relative */
892 complain_overflow_signed, /* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 "R_SCORE_CALL15", /* name */
895 TRUE, /* partial_inplace */
896 0x0000ffff, /* src_mask */
897 0x0000ffff, /* dst_mask */
898 FALSE), /* pcrel_offset */
900 /* 32 bit GP relative reference. */
901 HOWTO (R_SCORE_GPREL32, /* type */
903 2, /* size (0 = byte, 1 = short, 2 = long) */
905 FALSE, /* pc_relative */
907 complain_overflow_dont,/* complain_on_overflow */
908 score_elf_gprel32_reloc, /* special_function */
909 "R_SCORE_GPREL32", /* name */
910 TRUE, /* partial_inplace */
911 0xffffffff, /* src_mask */
912 0xffffffff, /* dst_mask */
913 FALSE), /* pcrel_offset */
915 /* 32 bit symbol relative relocation. */
916 HOWTO (R_SCORE_REL32, /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 FALSE, /* pc_relative */
922 complain_overflow_dont,/* complain_on_overflow */
923 bfd_elf_generic_reloc, /* special_function */
924 "R_SCORE_REL32", /* name */
925 TRUE, /* partial_inplace */
926 0xffffffff, /* src_mask */
927 0xffffffff, /* dst_mask */
928 FALSE), /* pcrel_offset */
930 /* R_SCORE_DUMMY_HI16 */
931 HOWTO (R_SCORE_DUMMY_HI16, /* type */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
935 FALSE, /* pc_relative */
937 complain_overflow_dont,/* complain_on_overflow */
938 score_elf_hi16_reloc, /* special_function */
939 "R_SCORE_DUMMY_HI16", /* name */
940 TRUE, /* partial_inplace */
941 0x37fff, /* src_mask */
942 0x37fff, /* dst_mask */
943 FALSE), /* pcrel_offset */
946 HOWTO (R_SCORE_IMM30, /* type */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
950 FALSE, /* pc_relative */
952 complain_overflow_dont,/* complain_on_overflow */
953 bfd_elf_generic_reloc, /* special_function */
954 "R_SCORE_IMM30", /* name */
955 FALSE, /* partial_inplace */
956 0x7f7fff7f80LL, /* src_mask */
957 0x7f7fff7f80LL, /* dst_mask */
958 FALSE), /* pcrel_offset */
961 HOWTO (R_SCORE_IMM32, /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 FALSE, /* pc_relative */
967 complain_overflow_dont,/* complain_on_overflow */
968 bfd_elf_generic_reloc, /* special_function */
969 "R_SCORE_IMM32", /* name */
970 FALSE, /* partial_inplace */
971 0x7f7fff7fe0LL, /* src_mask */
972 0x7f7fff7fe0LL, /* dst_mask */
973 FALSE), /* pcrel_offset */
976 struct score_reloc_map
978 bfd_reloc_code_real_type bfd_reloc_val;
979 unsigned char elf_reloc_val;
982 static const struct score_reloc_map elf32_score_reloc_map[] =
984 {BFD_RELOC_NONE, R_SCORE_NONE},
985 {BFD_RELOC_HI16_S, R_SCORE_HI16},
986 {BFD_RELOC_LO16, R_SCORE_LO16},
987 {BFD_RELOC_SCORE_BCMP, R_SCORE_BCMP},
988 {BFD_RELOC_SCORE_JMP, R_SCORE_24},
989 {BFD_RELOC_SCORE_BRANCH, R_SCORE_PC19},
990 {BFD_RELOC_SCORE16_JMP, R_SCORE16_11},
991 {BFD_RELOC_SCORE16_BRANCH, R_SCORE16_PC8},
992 {BFD_RELOC_32, R_SCORE_ABS32},
993 {BFD_RELOC_16, R_SCORE_ABS16},
994 {BFD_RELOC_SCORE_DUMMY2, R_SCORE_DUMMY2},
995 {BFD_RELOC_SCORE_GPREL15, R_SCORE_GP15},
996 {BFD_RELOC_VTABLE_INHERIT, R_SCORE_GNU_VTINHERIT},
997 {BFD_RELOC_VTABLE_ENTRY, R_SCORE_GNU_VTENTRY},
998 {BFD_RELOC_SCORE_GOT15, R_SCORE_GOT15},
999 {BFD_RELOC_SCORE_GOT_LO16, R_SCORE_GOT_LO16},
1000 {BFD_RELOC_SCORE_CALL15, R_SCORE_CALL15},
1001 {BFD_RELOC_GPREL32, R_SCORE_GPREL32},
1002 {BFD_RELOC_32_PCREL, R_SCORE_REL32},
1003 {BFD_RELOC_SCORE_DUMMY_HI16, R_SCORE_DUMMY_HI16},
1004 {BFD_RELOC_SCORE_IMM30, R_SCORE_IMM30},
1005 {BFD_RELOC_SCORE_IMM32, R_SCORE_IMM32},
1008 /* got_entries only match if they're identical, except for gotidx, so
1009 use all fields to compute the hash, and compare the appropriate
1012 score_elf_got_entry_hash (const void *entry_)
1014 const struct score_got_entry *entry = (struct score_got_entry *)entry_;
1016 return entry->symndx
1017 + (!entry->abfd ? entry->d.address : entry->abfd->id);
1021 score_elf_got_entry_eq (const void *entry1, const void *entry2)
1023 const struct score_got_entry *e1 = (struct score_got_entry *)entry1;
1024 const struct score_got_entry *e2 = (struct score_got_entry *)entry2;
1026 return e1->abfd == e2->abfd && e1->symndx == e2->symndx
1027 && (! e1->abfd ? e1->d.address == e2->d.address
1028 : e1->symndx >= 0 ? e1->d.addend == e2->d.addend
1029 : e1->d.h == e2->d.h);
1032 /* If H needs a GOT entry, assign it the highest available dynamic
1033 index. Otherwise, assign it the lowest available dynamic
1036 score_elf_sort_hash_table_f (struct score_elf_link_hash_entry *h, void *data)
1038 struct score_elf_hash_sort_data *hsd = data;
1040 /* Symbols without dynamic symbol table entries aren't interesting at all. */
1041 if (h->root.dynindx == -1)
1044 /* Global symbols that need GOT entries that are not explicitly
1045 referenced are marked with got offset 2. Those that are
1046 referenced get a 1, and those that don't need GOT entries get
1048 if (h->root.got.offset == 2)
1050 if (hsd->max_unref_got_dynindx == hsd->min_got_dynindx)
1051 hsd->low = (struct elf_link_hash_entry *) h;
1052 h->root.dynindx = hsd->max_unref_got_dynindx++;
1054 else if (h->root.got.offset != 1)
1055 h->root.dynindx = hsd->max_non_got_dynindx++;
1058 h->root.dynindx = --hsd->min_got_dynindx;
1059 hsd->low = (struct elf_link_hash_entry *) h;
1066 score_elf_got_section (bfd *abfd, bfd_boolean maybe_excluded)
1068 asection *sgot = bfd_get_linker_section (abfd, ".got");
1070 if (sgot == NULL || (! maybe_excluded && (sgot->flags & SEC_EXCLUDE) != 0))
1075 /* Returns the GOT information associated with the link indicated by
1076 INFO. If SGOTP is non-NULL, it is filled in with the GOT section. */
1077 static struct score_got_info *
1078 score_elf_got_info (bfd *abfd, asection **sgotp)
1081 struct score_got_info *g;
1083 sgot = score_elf_got_section (abfd, TRUE);
1084 BFD_ASSERT (sgot != NULL);
1085 BFD_ASSERT (elf_section_data (sgot) != NULL);
1086 g = score_elf_section_data (sgot)->u.got_info;
1087 BFD_ASSERT (g != NULL);
1094 /* Sort the dynamic symbol table so that symbols that need GOT entries
1095 appear towards the end. This reduces the amount of GOT space
1096 required. MAX_LOCAL is used to set the number of local symbols
1097 known to be in the dynamic symbol table. During
1098 s3_bfd_score_elf_size_dynamic_sections, this value is 1. Afterward, the
1099 section symbols are added and the count is higher. */
1101 score_elf_sort_hash_table (struct bfd_link_info *info,
1102 unsigned long max_local)
1104 struct score_elf_hash_sort_data hsd;
1105 struct score_got_info *g;
1108 dynobj = elf_hash_table (info)->dynobj;
1110 g = score_elf_got_info (dynobj, NULL);
1113 hsd.max_unref_got_dynindx =
1114 hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount
1115 /* In the multi-got case, assigned_gotno of the master got_info
1116 indicate the number of entries that aren't referenced in the
1117 primary GOT, but that must have entries because there are
1118 dynamic relocations that reference it. Since they aren't
1119 referenced, we move them to the end of the GOT, so that they
1120 don't prevent other entries that are referenced from getting
1121 too large offsets. */
1122 - (g->next ? g->assigned_gotno : 0);
1123 hsd.max_non_got_dynindx = max_local;
1124 score_elf_link_hash_traverse (elf_hash_table (info),
1125 score_elf_sort_hash_table_f,
1128 /* There should have been enough room in the symbol table to
1129 accommodate both the GOT and non-GOT symbols. */
1130 BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
1131 BFD_ASSERT ((unsigned long)hsd.max_unref_got_dynindx
1132 <= elf_hash_table (info)->dynsymcount);
1134 /* Now we know which dynamic symbol has the lowest dynamic symbol
1135 table index in the GOT. */
1136 g->global_gotsym = hsd.low;
1141 /* Create an entry in an score ELF linker hash table. */
1143 static struct bfd_hash_entry *
1144 score_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
1145 struct bfd_hash_table *table,
1148 struct score_elf_link_hash_entry *ret = (struct score_elf_link_hash_entry *) entry;
1150 /* Allocate the structure if it has not already been allocated by a subclass. */
1152 ret = bfd_hash_allocate (table, sizeof (struct score_elf_link_hash_entry));
1154 return (struct bfd_hash_entry *) ret;
1156 /* Call the allocation method of the superclass. */
1157 ret = ((struct score_elf_link_hash_entry *)
1158 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
1162 ret->possibly_dynamic_relocs = 0;
1163 ret->readonly_reloc = FALSE;
1164 ret->no_fn_stub = FALSE;
1165 ret->forced_local = FALSE;
1168 return (struct bfd_hash_entry *) ret;
1171 /* Returns the first relocation of type r_type found, beginning with
1172 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1173 static const Elf_Internal_Rela *
1174 score_elf_next_relocation (bfd *abfd ATTRIBUTE_UNUSED, unsigned int r_type,
1175 const Elf_Internal_Rela *relocation,
1176 const Elf_Internal_Rela *relend)
1178 while (relocation < relend)
1180 if (ELF32_R_TYPE (relocation->r_info) == r_type)
1186 /* We didn't find it. */
1187 bfd_set_error (bfd_error_bad_value);
1191 /* This function is called via qsort() to sort the dynamic relocation
1192 entries by increasing r_symndx value. */
1194 score_elf_sort_dynamic_relocs (const void *arg1, const void *arg2)
1196 Elf_Internal_Rela int_reloc1;
1197 Elf_Internal_Rela int_reloc2;
1199 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, arg1, &int_reloc1);
1200 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, arg2, &int_reloc2);
1202 return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
1205 /* Return whether a relocation is against a local symbol. */
1207 score_elf_local_relocation_p (bfd *input_bfd,
1208 const Elf_Internal_Rela *relocation,
1209 asection **local_sections,
1210 bfd_boolean check_forced)
1212 unsigned long r_symndx;
1213 Elf_Internal_Shdr *symtab_hdr;
1214 struct score_elf_link_hash_entry *h;
1217 r_symndx = ELF32_R_SYM (relocation->r_info);
1218 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1219 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
1221 if (r_symndx < extsymoff)
1223 if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
1228 /* Look up the hash table to check whether the symbol was forced local. */
1229 h = (struct score_elf_link_hash_entry *)
1230 elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
1231 /* Find the real hash-table entry for this symbol. */
1232 while (h->root.root.type == bfd_link_hash_indirect
1233 || h->root.root.type == bfd_link_hash_warning)
1234 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1235 if (h->root.forced_local)
1242 /* Returns the dynamic relocation section for DYNOBJ. */
1244 score_elf_rel_dyn_section (bfd *dynobj, bfd_boolean create_p)
1246 static const char dname[] = ".rel.dyn";
1249 sreloc = bfd_get_linker_section (dynobj, dname);
1250 if (sreloc == NULL && create_p)
1252 sreloc = bfd_make_section_anyway_with_flags (dynobj, dname,
1257 | SEC_LINKER_CREATED
1260 || ! bfd_set_section_alignment (dynobj, sreloc,
1261 SCORE_ELF_LOG_FILE_ALIGN (dynobj)))
1268 score_elf_allocate_dynamic_relocations (bfd *abfd, unsigned int n)
1272 s = score_elf_rel_dyn_section (abfd, FALSE);
1273 BFD_ASSERT (s != NULL);
1277 /* Make room for a null element. */
1278 s->size += SCORE_ELF_REL_SIZE (abfd);
1281 s->size += n * SCORE_ELF_REL_SIZE (abfd);
1284 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
1285 is the original relocation, which is now being transformed into a
1286 dynamic relocation. The ADDENDP is adjusted if necessary; the
1287 caller should store the result in place of the original addend. */
1289 score_elf_create_dynamic_relocation (bfd *output_bfd,
1290 struct bfd_link_info *info,
1291 const Elf_Internal_Rela *rel,
1292 struct score_elf_link_hash_entry *h,
1294 bfd_vma *addendp, asection *input_section)
1296 Elf_Internal_Rela outrel[3];
1301 bfd_boolean defined_p;
1303 r_type = ELF32_R_TYPE (rel->r_info);
1304 dynobj = elf_hash_table (info)->dynobj;
1305 sreloc = score_elf_rel_dyn_section (dynobj, FALSE);
1306 BFD_ASSERT (sreloc != NULL);
1307 BFD_ASSERT (sreloc->contents != NULL);
1308 BFD_ASSERT (sreloc->reloc_count * SCORE_ELF_REL_SIZE (output_bfd) < sreloc->size);
1310 outrel[0].r_offset =
1311 _bfd_elf_section_offset (output_bfd, info, input_section, rel[0].r_offset);
1312 outrel[1].r_offset =
1313 _bfd_elf_section_offset (output_bfd, info, input_section, rel[1].r_offset);
1314 outrel[2].r_offset =
1315 _bfd_elf_section_offset (output_bfd, info, input_section, rel[2].r_offset);
1317 if (outrel[0].r_offset == MINUS_ONE)
1318 /* The relocation field has been deleted. */
1321 if (outrel[0].r_offset == MINUS_TWO)
1323 /* The relocation field has been converted into a relative value of
1324 some sort. Functions like _bfd_elf_write_section_eh_frame expect
1325 the field to be fully relocated, so add in the symbol's value. */
1330 /* We must now calculate the dynamic symbol table index to use
1331 in the relocation. */
1333 && (! info->symbolic || !h->root.def_regular)
1334 /* h->root.dynindx may be -1 if this symbol was marked to
1336 && h->root.dynindx != -1)
1338 indx = h->root.dynindx;
1339 /* ??? glibc's ld.so just adds the final GOT entry to the
1340 relocation field. It therefore treats relocs against
1341 defined symbols in the same way as relocs against
1342 undefined symbols. */
1351 /* If the relocation was previously an absolute relocation and
1352 this symbol will not be referred to by the relocation, we must
1353 adjust it by the value we give it in the dynamic symbol table.
1354 Otherwise leave the job up to the dynamic linker. */
1355 if (defined_p && r_type != R_SCORE_REL32)
1358 /* The relocation is always an REL32 relocation because we don't
1359 know where the shared library will wind up at load-time. */
1360 outrel[0].r_info = ELF32_R_INFO ((unsigned long) indx, R_SCORE_REL32);
1362 /* For strict adherence to the ABI specification, we should
1363 generate a R_SCORE_64 relocation record by itself before the
1364 _REL32/_64 record as well, such that the addend is read in as
1365 a 64-bit value (REL32 is a 32-bit relocation, after all).
1366 However, since none of the existing ELF64 SCORE dynamic
1367 loaders seems to care, we don't waste space with these
1368 artificial relocations. If this turns out to not be true,
1369 score_elf_allocate_dynamic_relocations() should be tweaked so
1370 as to make room for a pair of dynamic relocations per
1371 invocation if ABI_64_P, and here we should generate an
1372 additional relocation record with R_SCORE_64 by itself for a
1373 NULL symbol before this relocation record. */
1374 outrel[1].r_info = ELF32_R_INFO (0, R_SCORE_NONE);
1375 outrel[2].r_info = ELF32_R_INFO (0, R_SCORE_NONE);
1377 /* Adjust the output offset of the relocation to reference the
1378 correct location in the output file. */
1379 outrel[0].r_offset += (input_section->output_section->vma
1380 + input_section->output_offset);
1381 outrel[1].r_offset += (input_section->output_section->vma
1382 + input_section->output_offset);
1383 outrel[2].r_offset += (input_section->output_section->vma
1384 + input_section->output_offset);
1386 /* Put the relocation back out. We have to use the special
1387 relocation outputter in the 64-bit case since the 64-bit
1388 relocation format is non-standard. */
1389 bfd_elf32_swap_reloc_out
1390 (output_bfd, &outrel[0],
1391 (sreloc->contents + sreloc->reloc_count * sizeof (Elf32_External_Rel)));
1393 /* We've now added another relocation. */
1394 ++sreloc->reloc_count;
1396 /* Make sure the output section is writable. The dynamic linker
1397 will be writing to it. */
1398 elf_section_data (input_section->output_section)->this_hdr.sh_flags |= SHF_WRITE;
1404 score_elf_create_got_section (bfd *abfd,
1405 struct bfd_link_info *info,
1406 bfd_boolean maybe_exclude)
1410 struct elf_link_hash_entry *h;
1411 struct bfd_link_hash_entry *bh;
1412 struct score_got_info *g;
1415 /* This function may be called more than once. */
1416 s = score_elf_got_section (abfd, TRUE);
1419 if (! maybe_exclude)
1420 s->flags &= ~SEC_EXCLUDE;
1424 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1427 flags |= SEC_EXCLUDE;
1429 /* We have to use an alignment of 2**4 here because this is hardcoded
1430 in the function stub generation and in the linker script. */
1431 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
1433 || ! bfd_set_section_alignment (abfd, s, 4))
1436 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1437 linker script because we don't want to define the symbol if we
1438 are not creating a global offset table. */
1440 if (! (_bfd_generic_link_add_one_symbol
1441 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
1442 0, NULL, FALSE, get_elf_backend_data (abfd)->collect, &bh)))
1445 h = (struct elf_link_hash_entry *) bh;
1448 h->type = STT_OBJECT;
1450 if (bfd_link_pic (info) && ! bfd_elf_link_record_dynamic_symbol (info, h))
1453 amt = sizeof (struct score_got_info);
1454 g = bfd_alloc (abfd, amt);
1458 g->global_gotsym = NULL;
1459 g->global_gotno = 0;
1461 g->local_gotno = SCORE_RESERVED_GOTNO;
1462 g->assigned_gotno = SCORE_RESERVED_GOTNO;
1465 g->got_entries = htab_try_create (1, score_elf_got_entry_hash,
1466 score_elf_got_entry_eq, NULL);
1467 if (g->got_entries == NULL)
1469 score_elf_section_data (s)->u.got_info = g;
1470 score_elf_section_data (s)->elf.this_hdr.sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
1475 /* Calculate the %high function. */
1477 score_elf_high (bfd_vma value)
1479 return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff;
1482 /* Create a local GOT entry for VALUE. Return the index of the entry,
1483 or -1 if it could not be created. */
1484 static struct score_got_entry *
1485 score_elf_create_local_got_entry (bfd *abfd,
1486 bfd *ibfd ATTRIBUTE_UNUSED,
1487 struct score_got_info *gg,
1488 asection *sgot, bfd_vma value,
1489 unsigned long r_symndx ATTRIBUTE_UNUSED,
1490 struct score_elf_link_hash_entry *h ATTRIBUTE_UNUSED,
1491 int r_type ATTRIBUTE_UNUSED)
1493 struct score_got_entry entry, **loc;
1494 struct score_got_info *g;
1498 entry.d.address = value;
1501 loc = (struct score_got_entry **) htab_find_slot (g->got_entries, &entry, INSERT);
1505 entry.gotidx = SCORE_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
1507 *loc = bfd_alloc (abfd, sizeof entry);
1512 memcpy (*loc, &entry, sizeof entry);
1514 if (g->assigned_gotno >= g->local_gotno)
1516 (*loc)->gotidx = -1;
1517 /* We didn't allocate enough space in the GOT. */
1518 (*_bfd_error_handler)
1519 (_("not enough GOT space for local GOT entries"));
1520 bfd_set_error (bfd_error_bad_value);
1524 score_bfd_put_32 (abfd, value, (sgot->contents + entry.gotidx));
1529 /* Find a GOT entry whose higher-order 16 bits are the same as those
1530 for value. Return the index into the GOT for this entry. */
1532 score_elf_got16_entry (bfd *abfd, bfd *ibfd, struct bfd_link_info *info,
1533 bfd_vma value, bfd_boolean external)
1536 struct score_got_info *g;
1537 struct score_got_entry *entry;
1541 /* Although the ABI says that it is "the high-order 16 bits" that we
1542 want, it is really the %high value. The complete value is
1543 calculated with a `addiu' of a LO16 relocation, just as with a
1545 value = score_elf_high (value) << 16;
1548 g = score_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
1550 entry = score_elf_create_local_got_entry (abfd, ibfd, g, sgot, value, 0, NULL,
1553 return entry->gotidx;
1559 s3_bfd_score_elf_hide_symbol (struct bfd_link_info *info,
1560 struct elf_link_hash_entry *entry,
1561 bfd_boolean force_local)
1565 struct score_got_info *g;
1566 struct score_elf_link_hash_entry *h;
1568 h = (struct score_elf_link_hash_entry *) entry;
1569 if (h->forced_local)
1571 h->forced_local = TRUE;
1573 dynobj = elf_hash_table (info)->dynobj;
1574 if (dynobj != NULL && force_local)
1576 got = score_elf_got_section (dynobj, FALSE);
1579 g = score_elf_section_data (got)->u.got_info;
1583 struct score_got_entry e;
1584 struct score_got_info *gg = g;
1586 /* Since we're turning what used to be a global symbol into a
1587 local one, bump up the number of local entries of each GOT
1588 that had an entry for it. This will automatically decrease
1589 the number of global entries, since global_gotno is actually
1590 the upper limit of global entries. */
1595 for (g = g->next; g != gg; g = g->next)
1596 if (htab_find (g->got_entries, &e))
1598 BFD_ASSERT (g->global_gotno > 0);
1603 /* If this was a global symbol forced into the primary GOT, we
1604 no longer need an entry for it. We can't release the entry
1605 at this point, but we must at least stop counting it as one
1606 of the symbols that required a forced got entry. */
1607 if (h->root.got.offset == 2)
1609 BFD_ASSERT (gg->assigned_gotno > 0);
1610 gg->assigned_gotno--;
1613 else if (g->global_gotno == 0 && g->global_gotsym == NULL)
1614 /* If we haven't got through GOT allocation yet, just bump up the
1615 number of local entries, as this symbol won't be counted as
1618 else if (h->root.got.offset == 1)
1620 /* If we're past non-multi-GOT allocation and this symbol had
1621 been marked for a global got entry, give it a local entry
1623 BFD_ASSERT (g->global_gotno > 0);
1629 _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
1632 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1633 symbol table index lower than any we've seen to date, record it for
1636 score_elf_record_global_got_symbol (struct elf_link_hash_entry *h,
1638 struct bfd_link_info *info,
1639 struct score_got_info *g)
1641 struct score_got_entry entry, **loc;
1643 /* A global symbol in the GOT must also be in the dynamic symbol table. */
1644 if (h->dynindx == -1)
1646 switch (ELF_ST_VISIBILITY (h->other))
1650 s3_bfd_score_elf_hide_symbol (info, h, TRUE);
1653 if (!bfd_elf_link_record_dynamic_symbol (info, h))
1659 entry.d.h = (struct score_elf_link_hash_entry *)h;
1661 loc = (struct score_got_entry **)htab_find_slot (g->got_entries, &entry, INSERT);
1663 /* If we've already marked this entry as needing GOT space, we don't
1664 need to do it again. */
1668 *loc = bfd_alloc (abfd, sizeof entry);
1674 memcpy (*loc, &entry, sizeof (entry));
1676 if (h->got.offset != MINUS_ONE)
1679 /* By setting this to a value other than -1, we are indicating that
1680 there needs to be a GOT entry for H. Avoid using zero, as the
1681 generic ELF copy_indirect_symbol tests for <= 0. */
1687 /* Reserve space in G for a GOT entry containing the value of symbol
1688 SYMNDX in input bfd ABDF, plus ADDEND. */
1690 score_elf_record_local_got_symbol (bfd *abfd,
1693 struct score_got_info *g)
1695 struct score_got_entry entry, **loc;
1698 entry.symndx = symndx;
1699 entry.d.addend = addend;
1700 loc = (struct score_got_entry **)htab_find_slot (g->got_entries, &entry, INSERT);
1705 entry.gotidx = g->local_gotno++;
1707 *loc = bfd_alloc (abfd, sizeof(entry));
1711 memcpy (*loc, &entry, sizeof (entry));
1716 /* Returns the GOT offset at which the indicated address can be found.
1717 If there is not yet a GOT entry for this value, create one.
1718 Returns -1 if no satisfactory GOT offset can be found. */
1720 score_elf_local_got_index (bfd *abfd, bfd *ibfd, struct bfd_link_info *info,
1721 bfd_vma value, unsigned long r_symndx,
1722 struct score_elf_link_hash_entry *h, int r_type)
1725 struct score_got_info *g;
1726 struct score_got_entry *entry;
1728 g = score_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
1730 entry = score_elf_create_local_got_entry (abfd, ibfd, g, sgot, value,
1731 r_symndx, h, r_type);
1736 return entry->gotidx;
1739 /* Returns the GOT index for the global symbol indicated by H. */
1742 score_elf_global_got_index (bfd *abfd, struct elf_link_hash_entry *h)
1746 struct score_got_info *g;
1747 long global_got_dynindx = 0;
1749 g = score_elf_got_info (abfd, &sgot);
1750 if (g->global_gotsym != NULL)
1751 global_got_dynindx = g->global_gotsym->dynindx;
1753 /* Once we determine the global GOT entry with the lowest dynamic
1754 symbol table index, we must put all dynamic symbols with greater
1755 indices into the GOT. That makes it easy to calculate the GOT
1757 BFD_ASSERT (h->dynindx >= global_got_dynindx);
1758 got_index = ((h->dynindx - global_got_dynindx + g->local_gotno) * SCORE_ELF_GOT_SIZE (abfd));
1759 BFD_ASSERT (got_index < sgot->size);
1764 /* Returns the offset for the entry at the INDEXth position in the GOT. */
1767 score_elf_got_offset_from_index (bfd *dynobj,
1769 bfd *input_bfd ATTRIBUTE_UNUSED,
1775 score_elf_got_info (dynobj, &sgot);
1776 gp = _bfd_get_gp_value (output_bfd);
1778 return sgot->output_section->vma + sgot->output_offset + got_index - gp;
1781 /* Follow indirect and warning hash entries so that each got entry
1782 points to the final symbol definition. P must point to a pointer
1783 to the hash table we're traversing. Since this traversal may
1784 modify the hash table, we set this pointer to NULL to indicate
1785 we've made a potentially-destructive change to the hash table, so
1786 the traversal must be restarted. */
1788 score_elf_resolve_final_got_entry (void **entryp, void *p)
1790 struct score_got_entry *entry = (struct score_got_entry *)*entryp;
1791 htab_t got_entries = *(htab_t *)p;
1793 if (entry->abfd != NULL && entry->symndx == -1)
1795 struct score_elf_link_hash_entry *h = entry->d.h;
1797 while (h->root.root.type == bfd_link_hash_indirect
1798 || h->root.root.type == bfd_link_hash_warning)
1799 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1801 if (entry->d.h == h)
1806 /* If we can't find this entry with the new bfd hash, re-insert
1807 it, and get the traversal restarted. */
1808 if (! htab_find (got_entries, entry))
1810 htab_clear_slot (got_entries, entryp);
1811 entryp = htab_find_slot (got_entries, entry, INSERT);
1814 /* Abort the traversal, since the whole table may have
1815 moved, and leave it up to the parent to restart the
1817 *(htab_t *)p = NULL;
1820 /* We might want to decrement the global_gotno count, but it's
1821 either too early or too late for that at this point. */
1827 /* Turn indirect got entries in a got_entries table into their final locations. */
1829 score_elf_resolve_final_got_entries (struct score_got_info *g)
1835 got_entries = g->got_entries;
1837 htab_traverse (got_entries,
1838 score_elf_resolve_final_got_entry,
1841 while (got_entries == NULL);
1844 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. for -r */
1846 score_elf_add_to_rel (bfd *abfd,
1848 reloc_howto_type *howto,
1849 bfd_signed_vma increment)
1851 bfd_signed_vma addend;
1853 unsigned long offset;
1854 unsigned long r_type = howto->type;
1855 unsigned long hi16_addend, hi16_offset, hi16_value, uvalue;
1857 contents = score_bfd_get_32 (abfd, address);
1858 /* Get the (signed) value from the instruction. */
1859 addend = contents & howto->src_mask;
1860 if (addend & ((howto->src_mask + 1) >> 1))
1862 bfd_signed_vma mask;
1865 mask &= ~howto->src_mask;
1868 /* Add in the increment, (which is a byte value). */
1873 (((contents & howto->src_mask) & 0x3ff0000) >> 6) | ((contents & howto->src_mask) & 0x3ff);
1874 offset += increment;
1876 (contents & ~howto->
1877 src_mask) | (((offset << 6) & howto->src_mask) & 0x3ff0000) | (offset & 0x3ff);
1878 score_bfd_put_32 (abfd, contents, address);
1883 hi16_addend = score_bfd_get_32 (abfd, address - 4);
1884 hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
1885 offset = ((((contents >> 16) & 0x3) << 15) | (contents & 0x7fff)) >> 1;
1886 offset = (hi16_offset << 16) | (offset & 0xffff);
1887 uvalue = increment + offset;
1888 hi16_offset = (uvalue >> 16) << 1;
1889 hi16_value = (hi16_addend & (~(howto->dst_mask)))
1890 | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
1891 score_bfd_put_32 (abfd, hi16_value, address - 4);
1892 offset = (uvalue & 0xffff) << 1;
1893 contents = (contents & (~(howto->dst_mask))) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
1894 score_bfd_put_32 (abfd, contents, address);
1898 (((contents & howto->src_mask) >> 1) & 0x1ff8000) | ((contents & howto->src_mask) & 0x7fff);
1899 offset += increment;
1901 (contents & ~howto->
1902 src_mask) | (((offset << 1) & howto->src_mask) & 0x3ff0000) | (offset & 0x7fff);
1903 score_bfd_put_32 (abfd, contents, address);
1908 contents = score_bfd_get_16 (abfd, address);
1909 offset = contents & howto->src_mask;
1910 offset += increment;
1911 contents = (contents & ~howto->src_mask) | (offset & howto->src_mask);
1912 score_bfd_put_16 (abfd, contents, address);
1917 contents = score_bfd_get_16 (abfd, address);
1918 offset = (contents & howto->src_mask) + ((increment >> 1) & 0x1ff);
1919 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1920 score_bfd_put_16 (abfd, contents, address);
1925 contents = score_bfd_get_32 (abfd, address);
1926 offset = (contents & howto->src_mask);
1927 offset <<= howto->rightshift;
1928 offset += increment;
1929 offset >>= howto->rightshift;
1930 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1931 score_bfd_put_32 (abfd, contents, address);
1935 contents = score_bfd_get_48 (abfd, address);
1936 offset = (contents & howto->src_mask);
1937 offset <<= howto->rightshift;
1938 offset += increment;
1939 offset >>= howto->rightshift;
1940 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1941 score_bfd_put_48 (abfd, contents, address);
1945 contents = score_bfd_get_48 (abfd, address);
1946 offset = (contents & howto->src_mask);
1947 offset += increment;
1948 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1949 score_bfd_put_48 (abfd, contents, address);
1953 addend += increment;
1954 contents = (contents & ~howto->dst_mask) | (addend & howto->dst_mask);
1955 score_bfd_put_32 (abfd, contents, address);
1960 /* Perform a relocation as part of a final link. */
1961 static bfd_reloc_status_type
1962 score_elf_final_link_relocate (reloc_howto_type *howto,
1965 asection *input_section,
1967 Elf_Internal_Rela *rel,
1968 Elf_Internal_Rela *relocs,
1970 struct bfd_link_info *info,
1971 const char *sym_name ATTRIBUTE_UNUSED,
1972 int sym_flags ATTRIBUTE_UNUSED,
1973 struct score_elf_link_hash_entry *h,
1974 asection **local_sections,
1975 bfd_boolean gp_disp_p)
1977 unsigned long r_type;
1978 unsigned long r_symndx;
1979 bfd_byte *hit_data = contents + rel->r_offset;
1981 /* The final GP value to be used for the relocatable, executable, or
1982 shared object file being produced. */
1983 bfd_vma gp = MINUS_ONE;
1984 /* The place (section offset or address) of the storage unit being relocated. */
1986 /* The offset into the global offset table at which the address of the relocation entry
1987 symbol, adjusted by the addend, resides during execution. */
1988 bfd_vma g = MINUS_ONE;
1989 /* TRUE if the symbol referred to by this relocation is a local symbol. */
1990 bfd_boolean local_p;
1991 /* The eventual value we will relocate. */
1992 bfd_vma value = symbol;
1993 unsigned long hi16_addend, hi16_offset, hi16_value, uvalue, offset, abs_value = 0;
1996 if (elf_gp (output_bfd) == 0)
1998 struct bfd_link_hash_entry *bh;
2001 bh = bfd_link_hash_lookup (info->hash, "_gp", 0, 0, 1);
2002 if (bh != NULL && bh->type == bfd_link_hash_defined)
2003 elf_gp (output_bfd) = (bh->u.def.value
2004 + bh->u.def.section->output_section->vma
2005 + bh->u.def.section->output_offset);
2006 else if (bfd_link_relocatable (info))
2010 /* Find the GP-relative section with the lowest offset. */
2011 for (o = output_bfd->sections; o != NULL; o = o->next)
2014 /* And calculate GP relative to that. */
2015 elf_gp (output_bfd) = lo + ELF_SCORE_GP_OFFSET (input_bfd);
2019 /* If the relocate_section function needs to do a reloc
2020 involving the GP value, it should make a reloc_dangerous
2021 callback to warn that GP is not defined. */
2025 /* Parse the relocation. */
2026 r_symndx = ELF32_R_SYM (rel->r_info);
2027 r_type = ELF32_R_TYPE (rel->r_info);
2028 rel_addr = (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
2029 local_p = score_elf_local_relocation_p (input_bfd, rel, local_sections, TRUE);
2031 if (r_type == R_SCORE_GOT15)
2033 const Elf_Internal_Rela *relend;
2034 const Elf_Internal_Rela *lo16_rel;
2035 const struct elf_backend_data *bed;
2036 bfd_vma lo_value = 0;
2038 bed = get_elf_backend_data (output_bfd);
2039 relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel;
2040 lo16_rel = score_elf_next_relocation (input_bfd, R_SCORE_GOT_LO16, rel, relend);
2041 if ((local_p) && (lo16_rel != NULL))
2044 tmp = score_bfd_get_32 (input_bfd, contents + lo16_rel->r_offset);
2045 lo_value = (((tmp >> 16) & 0x3) << 14) | ((tmp & 0x7fff) >> 1);
2049 /* For score3 R_SCORE_ABS32. */
2050 else if (r_type == R_SCORE_ABS32 || r_type == R_SCORE_REL32)
2052 addend = (bfd_get_32 (input_bfd, hit_data) >> howto->bitpos) & howto->src_mask;
2056 addend = (score_bfd_get_32 (input_bfd, hit_data) >> howto->bitpos) & howto->src_mask;
2059 /* If we haven't already determined the GOT offset, or the GP value,
2060 and we're going to need it, get it now. */
2063 case R_SCORE_CALL15:
2067 g = score_elf_global_got_index (elf_hash_table (info)->dynobj,
2068 (struct elf_link_hash_entry *) h);
2069 if ((! elf_hash_table (info)->dynamic_sections_created
2070 || (bfd_link_pic (info)
2071 && (info->symbolic || h->root.dynindx == -1)
2072 && h->root.def_regular)))
2074 /* This is a static link or a -Bsymbolic link. The
2075 symbol is defined locally, or was forced to be local.
2076 We must initialize this entry in the GOT. */
2077 bfd *tmpbfd = elf_hash_table (info)->dynobj;
2078 asection *sgot = score_elf_got_section (tmpbfd, FALSE);
2079 score_bfd_put_32 (tmpbfd, value, sgot->contents + g);
2082 else if (r_type == R_SCORE_GOT15 || r_type == R_SCORE_CALL15)
2084 /* There's no need to create a local GOT entry here; the
2085 calculation for a local GOT15 entry does not involve G. */
2090 g = score_elf_local_got_index (output_bfd, input_bfd, info,
2091 symbol + addend, r_symndx, h, r_type);
2093 return bfd_reloc_outofrange;
2096 /* Convert GOT indices to actual offsets. */
2097 g = score_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
2098 output_bfd, input_bfd, g);
2103 case R_SCORE_GPREL32:
2104 gp = _bfd_get_gp_value (output_bfd);
2108 gp = _bfd_get_gp_value (output_bfd);
2117 return bfd_reloc_ok;
2121 if ((bfd_link_pic (info)
2122 || (elf_hash_table (info)->dynamic_sections_created
2124 && h->root.def_dynamic
2125 && !h->root.def_regular))
2126 && r_symndx != STN_UNDEF
2127 && (input_section->flags & SEC_ALLOC) != 0)
2129 /* If we're creating a shared library, or this relocation is against a symbol
2130 in a shared library, then we can't know where the symbol will end up.
2131 So, we create a relocation record in the output, and leave the job up
2132 to the dynamic linker. */
2134 if (!score_elf_create_dynamic_relocation (output_bfd, info, rel, h,
2137 return bfd_reloc_undefined;
2139 else if (r_symndx == STN_UNDEF)
2140 /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
2141 from removed linkonce sections, or sections discarded by
2146 if (r_type != R_SCORE_REL32)
2147 value = symbol + addend;
2151 value &= howto->dst_mask;
2152 bfd_put_32 (input_bfd, value, hit_data);
2153 return bfd_reloc_ok;
2157 if ((long)value > 0x7fff || (long)value < -0x8000)
2158 return bfd_reloc_overflow;
2159 score_bfd_put_16 (input_bfd, value, hit_data);
2160 return bfd_reloc_ok;
2163 addend = score_bfd_get_32 (input_bfd, hit_data);
2164 offset = (((addend & howto->src_mask) >> 1) & 0x1ff8000) | ((addend & howto->src_mask) & 0x7fff);
2165 if ((offset & 0x1000000) != 0)
2166 offset |= 0xfe000000;
2168 abs_value = value - rel_addr;
2169 if ((abs_value & 0xfe000000) != 0)
2170 return bfd_reloc_overflow;
2171 addend = (addend & ~howto->src_mask)
2172 | (((value << 1) & howto->src_mask) & 0x3ff0000) | (value & 0x7fff);
2173 score_bfd_put_32 (input_bfd, addend, hit_data);
2174 return bfd_reloc_ok;
2179 int not_word_align_p = 0;
2180 bfd_vma imm_offset = 0;
2181 addend = score_bfd_get_48 (input_bfd, hit_data);
2182 imm_offset = ((addend >> 7) & 0xff)
2183 | (((addend >> 16) & 0x7fff) << 8)
2184 | (((addend >> 32) & 0x7f) << 23);
2185 imm_offset <<= howto->rightshift;
2186 value += imm_offset;
2187 value &= 0xffffffff;
2189 /* Check lw48/sw48 rd, value/label word align. */
2190 if ((value & 0x3) != 0)
2191 not_word_align_p = 1;
2193 value >>= howto->rightshift;
2194 addend = (addend & ~howto->src_mask)
2195 | (((value & 0xff) >> 0) << 7)
2196 | (((value & 0x7fff00) >> 8) << 16)
2197 | (((value & 0x3f800000) >> 23) << 32);
2198 score_bfd_put_48 (input_bfd, addend, hit_data);
2199 if (not_word_align_p)
2200 return bfd_reloc_other;
2202 return bfd_reloc_ok;
2207 bfd_vma imm_offset = 0;
2208 addend = score_bfd_get_48 (input_bfd, hit_data);
2209 imm_offset = ((addend >> 5) & 0x3ff)
2210 | (((addend >> 16) & 0x7fff) << 10)
2211 | (((addend >> 32) & 0x7f) << 25);
2212 value += imm_offset;
2213 value &= 0xffffffff;
2214 addend = (addend & ~howto->src_mask)
2215 | ((value & 0x3ff) << 5)
2216 | (((value >> 10) & 0x7fff) << 16)
2217 | (((value >> 25) & 0x7f) << 32);
2218 score_bfd_put_48 (input_bfd, addend, hit_data);
2219 return bfd_reloc_ok;
2223 addend = score_bfd_get_32 (input_bfd, hit_data);
2224 offset = (((addend & howto->src_mask) & 0x3ff0000) >> 6) | ((addend & howto->src_mask) & 0x3ff);
2225 if ((offset & 0x80000) != 0)
2226 offset |= 0xfff00000;
2227 abs_value = value = value - rel_addr + offset;
2228 /* exceed 20 bit : overflow. */
2229 if ((abs_value & 0x80000000) == 0x80000000)
2230 abs_value = 0xffffffff - value + 1;
2231 if ((abs_value & 0xfff80000) != 0)
2232 return bfd_reloc_overflow;
2233 addend = (addend & ~howto->src_mask)
2234 | (((value << 6) & howto->src_mask) & 0x3ff0000) | (value & 0x3ff);
2235 score_bfd_put_32 (input_bfd, addend, hit_data);
2236 return bfd_reloc_ok;
2239 addend = score_bfd_get_16 (input_bfd, hit_data);
2240 offset = addend & howto->src_mask;
2241 if ((offset & 0x800) != 0) /* Offset is negative. */
2242 offset |= 0xfffff000;
2244 abs_value = value - rel_addr;
2245 if ((abs_value & 0xfffff000) != 0)
2246 return bfd_reloc_overflow;
2247 addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
2248 score_bfd_put_16 (input_bfd, addend, hit_data);
2249 return bfd_reloc_ok;
2252 addend = score_bfd_get_16 (input_bfd, hit_data);
2253 offset = (addend & howto->src_mask) << 1;
2254 if ((offset & 0x200) != 0) /* Offset is negative. */
2255 offset |= 0xfffffe00;
2256 abs_value = value = value - rel_addr + offset;
2257 /* Sign bit + exceed 9 bit. */
2258 if (((value & 0xfffffe00) != 0) && ((value & 0xfffffe00) != 0xfffffe00))
2259 return bfd_reloc_overflow;
2261 addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
2262 score_bfd_put_16 (input_bfd, addend, hit_data);
2263 return bfd_reloc_ok;
2266 addend = score_bfd_get_32 (input_bfd, hit_data);
2267 offset = (addend & howto->src_mask) << howto->rightshift;
2268 if ((offset & 0x200) != 0) /* Offset is negative. */
2269 offset |= 0xfffffe00;
2270 value = value - rel_addr + offset;
2271 /* Sign bit + exceed 9 bit. */
2272 if (((value & 0xfffffe00) != 0) && ((value & 0xfffffe00) != 0xfffffe00))
2273 return bfd_reloc_overflow;
2274 value >>= howto->rightshift;
2275 addend = (addend & ~howto->src_mask)
2277 | (((value >> 1) & 0x7) << 7)
2278 | (((value >> 4) & 0x1f) << 21);
2279 score_bfd_put_32 (input_bfd, addend, hit_data);
2280 return bfd_reloc_ok;
2283 return bfd_reloc_ok;
2286 hi16_addend = score_bfd_get_32 (input_bfd, hit_data - 4);
2287 hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
2288 addend = score_bfd_get_32 (input_bfd, hit_data);
2289 offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
2290 offset = (hi16_offset << 16) | (offset & 0xffff);
2293 uvalue = value + offset;
2295 uvalue = offset + gp - rel_addr + 4;
2297 hi16_offset = (uvalue >> 16) << 1;
2298 hi16_value = (hi16_addend & (~(howto->dst_mask)))
2299 | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
2300 score_bfd_put_32 (input_bfd, hi16_value, hit_data - 4);
2301 offset = (uvalue & 0xffff) << 1;
2302 value = (addend & (~(howto->dst_mask))) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
2303 score_bfd_put_32 (input_bfd, value, hit_data);
2304 return bfd_reloc_ok;
2307 addend = score_bfd_get_32 (input_bfd, hit_data);
2308 offset = addend & 0x7fff;
2309 if ((offset & 0x4000) == 0x4000)
2310 offset |= 0xffffc000;
2311 value = value + offset - gp;
2312 if (((value & 0xffffc000) != 0) && ((value & 0xffffc000) != 0xffffc000))
2313 return bfd_reloc_overflow;
2314 value = (addend & ~howto->src_mask) | (value & howto->src_mask);
2315 score_bfd_put_32 (input_bfd, value, hit_data);
2316 return bfd_reloc_ok;
2319 case R_SCORE_CALL15:
2324 /* The special case is when the symbol is forced to be local. We need the
2325 full address in the GOT since no R_SCORE_GOT_LO16 relocation follows. */
2326 forced = ! score_elf_local_relocation_p (input_bfd, rel,
2327 local_sections, FALSE);
2328 value = score_elf_got16_entry (output_bfd, input_bfd, info,
2329 symbol + addend, forced);
2330 if (value == MINUS_ONE)
2331 return bfd_reloc_outofrange;
2332 value = score_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
2333 output_bfd, input_bfd, value);
2340 if ((long) value > 0x3fff || (long) value < -0x4000)
2341 return bfd_reloc_overflow;
2343 addend = score_bfd_get_32 (input_bfd, hit_data);
2344 value = (addend & ~howto->dst_mask) | (value & howto->dst_mask);
2345 score_bfd_put_32 (input_bfd, value, hit_data);
2346 return bfd_reloc_ok;
2348 case R_SCORE_GPREL32:
2349 value = (addend + symbol - gp);
2350 value &= howto->dst_mask;
2351 score_bfd_put_32 (input_bfd, value, hit_data);
2352 return bfd_reloc_ok;
2354 case R_SCORE_GOT_LO16:
2355 addend = score_bfd_get_32 (input_bfd, hit_data);
2356 value = (((addend >> 16) & 0x3) << 14) | ((addend & 0x7fff) >> 1);
2358 value = (addend & (~(howto->dst_mask))) | ((value & 0x3fff) << 1)
2359 | (((value >> 14) & 0x3) << 16);
2361 score_bfd_put_32 (input_bfd, value, hit_data);
2362 return bfd_reloc_ok;
2364 case R_SCORE_DUMMY_HI16:
2365 return bfd_reloc_ok;
2367 case R_SCORE_GNU_VTINHERIT:
2368 case R_SCORE_GNU_VTENTRY:
2369 /* We don't do anything with these at present. */
2370 return bfd_reloc_continue;
2373 return bfd_reloc_notsupported;
2377 /* Score backend functions. */
2379 s3_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
2381 Elf_Internal_Rela *elf_reloc)
2383 unsigned int r_type;
2385 r_type = ELF32_R_TYPE (elf_reloc->r_info);
2386 if (r_type >= ARRAY_SIZE (elf32_score_howto_table))
2387 bfd_reloc->howto = NULL;
2389 bfd_reloc->howto = &elf32_score_howto_table[r_type];
2392 /* Relocate an score ELF section. */
2394 s3_bfd_score_elf_relocate_section (bfd *output_bfd,
2395 struct bfd_link_info *info,
2397 asection *input_section,
2399 Elf_Internal_Rela *relocs,
2400 Elf_Internal_Sym *local_syms,
2401 asection **local_sections)
2403 Elf_Internal_Shdr *symtab_hdr;
2404 Elf_Internal_Rela *rel;
2405 Elf_Internal_Rela *relend;
2407 unsigned long offset;
2408 unsigned long hi16_addend, hi16_offset, hi16_value, uvalue;
2410 bfd_boolean gp_disp_p = FALSE;
2413 if (elf_hash_table (info)->dynamic_sections_created)
2415 bfd_size_type dynsecsymcount = 0;
2416 if (bfd_link_pic (info))
2419 const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
2421 for (p = output_bfd->sections; p ; p = p->next)
2422 if ((p->flags & SEC_EXCLUDE) == 0
2423 && (p->flags & SEC_ALLOC) != 0
2424 && !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p))
2428 if (!score_elf_sort_hash_table (info, dynsecsymcount + 1))
2432 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2433 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
2435 relend = relocs + input_section->reloc_count;
2436 for (; rel < relend; rel++)
2439 reloc_howto_type *howto;
2440 unsigned long r_symndx;
2441 Elf_Internal_Sym *sym;
2443 struct score_elf_link_hash_entry *h;
2444 bfd_vma relocation = 0;
2445 bfd_reloc_status_type r;
2448 r_symndx = ELF32_R_SYM (rel->r_info);
2449 r_type = ELF32_R_TYPE (rel->r_info);
2451 s3_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel);
2452 howto = bfd_reloc.howto;
2458 if (r_symndx < extsymoff)
2460 sym = local_syms + r_symndx;
2461 sec = local_sections[r_symndx];
2462 relocation = (sec->output_section->vma
2463 + sec->output_offset
2465 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
2467 if (!bfd_link_relocatable (info)
2468 && (sec->flags & SEC_MERGE)
2469 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2472 bfd_vma addend, value;
2479 hi16_addend = score_bfd_get_32 (input_bfd, contents + rel->r_offset - 4);
2480 hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
2481 value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2482 offset = ((((value >> 16) & 0x3) << 15) | (value & 0x7fff)) >> 1;
2483 addend = (hi16_offset << 16) | (offset & 0xffff);
2485 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2486 addend -= relocation;
2487 addend += msec->output_section->vma + msec->output_offset;
2489 hi16_offset = (uvalue >> 16) << 1;
2490 hi16_value = (hi16_addend & (~(howto->dst_mask)))
2491 | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
2492 score_bfd_put_32 (input_bfd, hi16_value, contents + rel->r_offset - 4);
2493 offset = (uvalue & 0xffff) << 1;
2494 value = (value & (~(howto->dst_mask)))
2495 | (offset & 0x7fff) | ((offset << 1) & 0x30000);
2496 score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2501 value = score_bfd_get_48 (input_bfd, contents + rel->r_offset);
2502 addend = ((value >> 5) & 0x3ff)
2503 | (((value >> 16) & 0x7fff) << 10)
2504 | (((value >> 32) & 0x7f) << 25);
2506 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2507 addend -= relocation;
2508 addend += msec->output_section->vma + msec->output_offset;
2509 addend &= 0xffffffff;
2510 value = (value & ~howto->src_mask)
2511 | ((addend & 0x3ff) << 5)
2512 | (((addend >> 10) & 0x7fff) << 16)
2513 | (((addend >> 25) & 0x7f) << 32);
2514 score_bfd_put_48 (input_bfd, value, contents + rel->r_offset);
2520 int not_word_align_p = 0;
2521 value = score_bfd_get_48 (input_bfd, contents + rel->r_offset);
2522 addend = ((value >> 7) & 0xff)
2523 | (((value >> 16) & 0x7fff) << 8)
2524 | (((value >> 32) & 0x7f) << 23);
2525 addend <<= howto->rightshift;
2527 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2528 addend -= relocation;
2529 addend += msec->output_section->vma + msec->output_offset;
2530 addend &= 0xffffffff;
2532 /* Check lw48/sw48 rd, value/label word align. */
2533 if ((addend & 0x3) != 0)
2534 not_word_align_p = 1;
2536 addend >>= howto->rightshift;
2537 value = (value & ~howto->src_mask)
2538 | (((addend & 0xff) >> 0) << 7)
2539 | (((addend & 0x7fff00) >> 8) << 16)
2540 | (((addend & 0x3f800000) >> 23) << 32);
2541 score_bfd_put_48 (input_bfd, value, contents + rel->r_offset);
2543 if (not_word_align_p)
2544 return bfd_reloc_other;
2549 case R_SCORE_GOT_LO16:
2550 value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2551 addend = (((value >> 16) & 0x3) << 14) | ((value & 0x7fff) >> 1);
2553 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2554 addend += msec->output_section->vma + msec->output_offset;
2555 value = (value & (~(howto->dst_mask))) | ((addend & 0x3fff) << 1)
2556 | (((addend >> 14) & 0x3) << 16);
2558 score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2563 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
2564 /* Get the (signed) value from the instruction. */
2565 addend = value & howto->src_mask;
2566 if (addend & ((howto->src_mask + 1) >> 1))
2568 bfd_signed_vma mask;
2571 mask &= ~howto->src_mask;
2575 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2576 addend += msec->output_section->vma + msec->output_offset;
2577 value = (value & ~howto->dst_mask) | (addend & howto->dst_mask);
2578 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2582 value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2583 /* Get the (signed) value from the instruction. */
2584 addend = value & howto->src_mask;
2585 if (addend & ((howto->src_mask + 1) >> 1))
2587 bfd_signed_vma mask;
2590 mask &= ~howto->src_mask;
2594 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2595 addend += msec->output_section->vma + msec->output_offset;
2596 value = (value & ~howto->dst_mask) | (addend & howto->dst_mask);
2597 score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2604 /* For global symbols we look up the symbol in the hash-table. */
2605 h = ((struct score_elf_link_hash_entry *)
2606 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
2608 if (info->wrap_hash != NULL
2609 && (input_section->flags & SEC_DEBUGGING) != 0)
2610 h = ((struct score_elf_link_hash_entry *)
2611 unwrap_hash_lookup (info, input_bfd, &h->root.root));
2613 /* Find the real hash-table entry for this symbol. */
2614 while (h->root.root.type == bfd_link_hash_indirect
2615 || h->root.root.type == bfd_link_hash_warning)
2616 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
2618 /* Record the name of this symbol, for our caller. */
2619 name = h->root.root.root.string;
2621 /* See if this is the special GP_DISP_LABEL symbol. Note that such a
2622 symbol must always be a global symbol. */
2623 if (strcmp (name, GP_DISP_LABEL) == 0)
2625 /* Relocations against GP_DISP_LABEL are permitted only with
2626 R_SCORE_HI16 and R_SCORE_LO16 relocations. */
2627 if (r_type != R_SCORE_HI16 && r_type != R_SCORE_LO16)
2628 return bfd_reloc_notsupported;
2633 /* If this symbol is defined, calculate its address. Note that
2634 GP_DISP_LABEL is a magic symbol, always implicitly defined by the
2635 linker, so it's inappropriate to check to see whether or not
2637 else if ((h->root.root.type == bfd_link_hash_defined
2638 || h->root.root.type == bfd_link_hash_defweak)
2639 && h->root.root.u.def.section)
2641 sec = h->root.root.u.def.section;
2642 if (sec->output_section)
2643 relocation = (h->root.root.u.def.value
2644 + sec->output_section->vma
2645 + sec->output_offset);
2648 relocation = h->root.root.u.def.value;
2651 else if (h->root.root.type == bfd_link_hash_undefweak)
2652 /* We allow relocations against undefined weak symbols, giving
2653 it the value zero, so that you can undefined weak functions
2654 and check to see if they exist by looking at their addresses. */
2656 else if (info->unresolved_syms_in_objects == RM_IGNORE
2657 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
2659 else if (strcmp (name, "_DYNAMIC_LINK") == 0)
2661 /* If this is a dynamic link, we should have created a _DYNAMIC_LINK symbol
2662 in s3_bfd_score_elf_create_dynamic_sections. Otherwise, we should define
2663 the symbol with a value of 0. */
2664 BFD_ASSERT (! bfd_link_pic (info));
2665 BFD_ASSERT (bfd_get_section_by_name (output_bfd, ".dynamic") == NULL);
2668 else if (!bfd_link_relocatable (info))
2670 if (! ((*info->callbacks->undefined_symbol)
2671 (info, h->root.root.root.string, input_bfd,
2672 input_section, rel->r_offset,
2673 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
2674 || ELF_ST_VISIBILITY (h->root.other))))
2675 return bfd_reloc_undefined;
2680 if (sec != NULL && discarded_section (sec))
2681 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2682 rel, 1, relend, howto, 0, contents);
2684 if (bfd_link_relocatable (info))
2686 /* This is a relocatable link. We don't have to change
2687 anything, unless the reloc is against a section symbol,
2688 in which case we have to adjust according to where the
2689 section symbol winds up in the output section. */
2690 if (r_symndx < symtab_hdr->sh_info)
2692 sym = local_syms + r_symndx;
2693 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2695 sec = local_sections[r_symndx];
2696 score_elf_add_to_rel (input_bfd, contents + rel->r_offset,
2697 howto, (bfd_signed_vma) (sec->output_offset + sym->st_value));
2703 /* This is a final link. */
2704 r = score_elf_final_link_relocate (howto, input_bfd, output_bfd,
2705 input_section, contents, rel, relocs,
2706 relocation, info, name,
2707 (h ? ELF_ST_TYPE ((unsigned int)h->root.root.type) :
2708 ELF_ST_TYPE ((unsigned int)sym->st_info)), h, local_sections,
2711 if (r != bfd_reloc_ok)
2713 const char *msg = (const char *)0;
2717 case bfd_reloc_overflow:
2718 /* If the overflowing reloc was to an undefined symbol,
2719 we have already printed one error message and there
2720 is no point complaining again. */
2721 if (((!h) || (h->root.root.type != bfd_link_hash_undefined))
2722 && (!((*info->callbacks->reloc_overflow)
2723 (info, NULL, name, howto->name, (bfd_vma) 0,
2724 input_bfd, input_section, rel->r_offset))))
2727 case bfd_reloc_undefined:
2728 if (!((*info->callbacks->undefined_symbol)
2729 (info, name, input_bfd, input_section, rel->r_offset, TRUE)))
2733 case bfd_reloc_outofrange:
2734 msg = _("internal error: out of range error");
2737 case bfd_reloc_notsupported:
2738 msg = _("internal error: unsupported relocation error");
2741 case bfd_reloc_dangerous:
2742 msg = _("internal error: dangerous error");
2745 /* Use bfd_reloc_other to check lw48, sw48 word align. */
2746 case bfd_reloc_other:
2747 msg = _("address not word align");
2751 msg = _("internal error: unknown error");
2755 if (!((*info->callbacks->warning)
2756 (info, msg, name, input_bfd, input_section, rel->r_offset)))
2766 /* Look through the relocs for a section during the first phase, and
2767 allocate space in the global offset table. */
2769 s3_bfd_score_elf_check_relocs (bfd *abfd,
2770 struct bfd_link_info *info,
2772 const Elf_Internal_Rela *relocs)
2776 Elf_Internal_Shdr *symtab_hdr;
2777 struct elf_link_hash_entry **sym_hashes;
2778 struct score_got_info *g;
2780 const Elf_Internal_Rela *rel;
2781 const Elf_Internal_Rela *rel_end;
2784 const struct elf_backend_data *bed;
2786 if (bfd_link_relocatable (info))
2789 dynobj = elf_hash_table (info)->dynobj;
2790 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2791 sym_hashes = elf_sym_hashes (abfd);
2792 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
2794 name = bfd_get_section_name (abfd, sec);
2803 sgot = score_elf_got_section (dynobj, FALSE);
2808 BFD_ASSERT (score_elf_section_data (sgot) != NULL);
2809 g = score_elf_section_data (sgot)->u.got_info;
2810 BFD_ASSERT (g != NULL);
2815 bed = get_elf_backend_data (abfd);
2816 rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel;
2817 for (rel = relocs; rel < rel_end; ++rel)
2819 unsigned long r_symndx;
2820 unsigned int r_type;
2821 struct elf_link_hash_entry *h;
2823 r_symndx = ELF32_R_SYM (rel->r_info);
2824 r_type = ELF32_R_TYPE (rel->r_info);
2826 if (r_symndx < extsymoff)
2830 else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
2832 (*_bfd_error_handler) (_("%s: Malformed reloc detected for section %s"), abfd, name);
2833 bfd_set_error (bfd_error_bad_value);
2838 h = sym_hashes[r_symndx - extsymoff];
2840 /* This may be an indirect symbol created because of a version. */
2843 while (h->root.type == bfd_link_hash_indirect)
2844 h = (struct elf_link_hash_entry *)h->root.u.i.link;
2846 /* PR15323, ref flags aren't set for references in the
2848 h->root.non_ir_ref = 1;
2852 /* Some relocs require a global offset table. */
2853 if (dynobj == NULL || sgot == NULL)
2858 case R_SCORE_CALL15:
2860 elf_hash_table (info)->dynobj = dynobj = abfd;
2861 if (!score_elf_create_got_section (dynobj, info, FALSE))
2863 g = score_elf_got_info (dynobj, &sgot);
2868 && (bfd_link_pic (info) || h != NULL)
2869 && (sec->flags & SEC_ALLOC) != 0)
2870 elf_hash_table (info)->dynobj = dynobj = abfd;
2877 if (!h && (r_type == R_SCORE_GOT_LO16))
2879 if (! score_elf_record_local_got_symbol (abfd, r_symndx, rel->r_addend, g))
2885 case R_SCORE_CALL15:
2888 (*_bfd_error_handler)
2889 (_("%B: CALL15 reloc at 0x%lx not against global symbol"),
2890 abfd, (unsigned long) rel->r_offset);
2891 bfd_set_error (bfd_error_bad_value);
2896 /* This symbol requires a global offset table entry. */
2897 if (! score_elf_record_global_got_symbol (h, abfd, info, g))
2900 /* We need a stub, not a plt entry for the undefined function. But we record
2901 it as if it needs plt. See _bfd_elf_adjust_dynamic_symbol. */
2907 if (h && ! score_elf_record_global_got_symbol (h, abfd, info, g))
2912 if ((bfd_link_pic (info) || h != NULL)
2913 && (sec->flags & SEC_ALLOC) != 0)
2917 sreloc = score_elf_rel_dyn_section (dynobj, TRUE);
2921 #define SCORE_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
2922 if (bfd_link_pic (info))
2924 /* When creating a shared object, we must copy these reloc types into
2925 the output file as R_SCORE_REL32 relocs. We make room for this reloc
2926 in the .rel.dyn reloc section. */
2927 score_elf_allocate_dynamic_relocations (dynobj, 1);
2928 if ((sec->flags & SCORE_READONLY_SECTION)
2929 == SCORE_READONLY_SECTION)
2930 /* We tell the dynamic linker that there are
2931 relocations against the text segment. */
2932 info->flags |= DF_TEXTREL;
2936 struct score_elf_link_hash_entry *hscore;
2938 /* We only need to copy this reloc if the symbol is
2939 defined in a dynamic object. */
2940 hscore = (struct score_elf_link_hash_entry *)h;
2941 ++hscore->possibly_dynamic_relocs;
2942 if ((sec->flags & SCORE_READONLY_SECTION)
2943 == SCORE_READONLY_SECTION)
2944 /* We need it to tell the dynamic linker if there
2945 are relocations against the text segment. */
2946 hscore->readonly_reloc = TRUE;
2949 /* Even though we don't directly need a GOT entry for this symbol,
2950 a symbol must have a dynamic symbol table index greater that
2951 DT_SCORE_GOTSYM if there are dynamic relocations against it. */
2955 elf_hash_table (info)->dynobj = dynobj = abfd;
2956 if (! score_elf_create_got_section (dynobj, info, TRUE))
2958 g = score_elf_got_info (dynobj, &sgot);
2959 if (! score_elf_record_global_got_symbol (h, abfd, info, g))
2965 /* This relocation describes the C++ object vtable hierarchy.
2966 Reconstruct it for later use during GC. */
2967 case R_SCORE_GNU_VTINHERIT:
2968 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2972 /* This relocation describes which C++ vtable entries are actually
2973 used. Record for later use during GC. */
2974 case R_SCORE_GNU_VTENTRY:
2975 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
2982 /* We must not create a stub for a symbol that has relocations
2983 related to taking the function's address. */
2989 struct score_elf_link_hash_entry *sh;
2991 sh = (struct score_elf_link_hash_entry *) h;
2992 sh->no_fn_stub = TRUE;
2995 case R_SCORE_CALL15:
3004 s3_bfd_score_elf_add_symbol_hook (bfd *abfd,
3005 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3006 Elf_Internal_Sym *sym,
3007 const char **namep ATTRIBUTE_UNUSED,
3008 flagword *flagsp ATTRIBUTE_UNUSED,
3012 switch (sym->st_shndx)
3015 if (sym->st_size > elf_gp_size (abfd))
3018 case SHN_SCORE_SCOMMON:
3019 *secp = bfd_make_section_old_way (abfd, ".scommon");
3020 (*secp)->flags |= SEC_IS_COMMON;
3021 *valp = sym->st_size;
3029 s3_bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
3031 elf_symbol_type *elfsym;
3033 elfsym = (elf_symbol_type *) asym;
3034 switch (elfsym->internal_elf_sym.st_shndx)
3037 if (asym->value > elf_gp_size (abfd))
3040 case SHN_SCORE_SCOMMON:
3041 if (score_elf_scom_section.name == NULL)
3043 /* Initialize the small common section. */
3044 score_elf_scom_section.name = ".scommon";
3045 score_elf_scom_section.flags = SEC_IS_COMMON;
3046 score_elf_scom_section.output_section = &score_elf_scom_section;
3047 score_elf_scom_section.symbol = &score_elf_scom_symbol;
3048 score_elf_scom_section.symbol_ptr_ptr = &score_elf_scom_symbol_ptr;
3049 score_elf_scom_symbol.name = ".scommon";
3050 score_elf_scom_symbol.flags = BSF_SECTION_SYM;
3051 score_elf_scom_symbol.section = &score_elf_scom_section;
3052 score_elf_scom_symbol_ptr = &score_elf_scom_symbol;
3054 asym->section = &score_elf_scom_section;
3055 asym->value = elfsym->internal_elf_sym.st_size;
3061 s3_bfd_score_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3062 const char *name ATTRIBUTE_UNUSED,
3063 Elf_Internal_Sym *sym,
3064 asection *input_sec,
3065 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3067 /* If we see a common symbol, which implies a relocatable link, then
3068 if a symbol was small common in an input file, mark it as small
3069 common in the output file. */
3070 if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
3071 sym->st_shndx = SHN_SCORE_SCOMMON;
3077 s3_bfd_score_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3081 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
3083 *retval = SHN_SCORE_SCOMMON;
3090 /* Adjust a symbol defined by a dynamic object and referenced by a
3091 regular object. The current definition is in some section of the
3092 dynamic object, but we're not including those sections. We have to
3093 change the definition to something the rest of the link can understand. */
3095 s3_bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3096 struct elf_link_hash_entry *h)
3099 struct score_elf_link_hash_entry *hscore;
3102 dynobj = elf_hash_table (info)->dynobj;
3104 /* Make sure we know what is going on here. */
3105 BFD_ASSERT (dynobj != NULL
3107 || h->u.weakdef != NULL
3108 || (h->def_dynamic && h->ref_regular && !h->def_regular)));
3110 /* If this symbol is defined in a dynamic object, we need to copy
3111 any R_SCORE_ABS32 or R_SCORE_REL32 relocs against it into the output
3113 hscore = (struct score_elf_link_hash_entry *)h;
3114 if (!bfd_link_relocatable (info)
3115 && hscore->possibly_dynamic_relocs != 0
3116 && (h->root.type == bfd_link_hash_defweak || !h->def_regular))
3118 score_elf_allocate_dynamic_relocations (dynobj, hscore->possibly_dynamic_relocs);
3119 if (hscore->readonly_reloc)
3120 /* We tell the dynamic linker that there are relocations
3121 against the text segment. */
3122 info->flags |= DF_TEXTREL;
3125 /* For a function, create a stub, if allowed. */
3126 if (!hscore->no_fn_stub && h->needs_plt)
3128 if (!elf_hash_table (info)->dynamic_sections_created)
3131 /* If this symbol is not defined in a regular file, then set
3132 the symbol to the stub location. This is required to make
3133 function pointers compare as equal between the normal
3134 executable and the shared library. */
3135 if (!h->def_regular)
3137 /* We need .stub section. */
3138 s = bfd_get_linker_section (dynobj, SCORE_ELF_STUB_SECTION_NAME);
3139 BFD_ASSERT (s != NULL);
3141 h->root.u.def.section = s;
3142 h->root.u.def.value = s->size;
3144 /* XXX Write this stub address somewhere. */
3145 h->plt.offset = s->size;
3147 /* Make room for this stub code. */
3148 s->size += SCORE_FUNCTION_STUB_SIZE;
3150 /* The last half word of the stub will be filled with the index
3151 of this symbol in .dynsym section. */
3155 else if ((h->type == STT_FUNC) && !h->needs_plt)
3157 /* This will set the entry for this symbol in the GOT to 0, and
3158 the dynamic linker will take care of this. */
3159 h->root.u.def.value = 0;
3163 /* If this is a weak symbol, and there is a real definition, the
3164 processor independent code will have arranged for us to see the
3165 real definition first, and we can just use the same value. */
3166 if (h->u.weakdef != NULL)
3168 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3169 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3170 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3171 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3175 /* This is a reference to a symbol defined by a dynamic object which
3176 is not a function. */
3180 /* This function is called after all the input files have been read,
3181 and the input sections have been assigned to output sections. */
3183 s3_bfd_score_elf_always_size_sections (bfd *output_bfd,
3184 struct bfd_link_info *info)
3188 struct score_got_info *g;
3190 bfd_size_type loadable_size = 0;
3191 bfd_size_type local_gotno;
3194 dynobj = elf_hash_table (info)->dynobj;
3196 /* Relocatable links don't have it. */
3199 g = score_elf_got_info (dynobj, &s);
3203 /* Calculate the total loadable size of the output. That will give us the
3204 maximum number of GOT_PAGE entries required. */
3205 for (sub = info->input_bfds; sub; sub = sub->link.next)
3207 asection *subsection;
3209 for (subsection = sub->sections;
3211 subsection = subsection->next)
3213 if ((subsection->flags & SEC_ALLOC) == 0)
3215 loadable_size += ((subsection->size + 0xf)
3216 &~ (bfd_size_type) 0xf);
3220 /* There has to be a global GOT entry for every symbol with
3221 a dynamic symbol table index of DT_SCORE_GOTSYM or
3222 higher. Therefore, it make sense to put those symbols
3223 that need GOT entries at the end of the symbol table. We
3225 if (! score_elf_sort_hash_table (info, 1))
3228 if (g->global_gotsym != NULL)
3229 i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
3231 /* If there are no global symbols, or none requiring
3232 relocations, then GLOBAL_GOTSYM will be NULL. */
3235 /* In the worst case, we'll get one stub per dynamic symbol. */
3236 loadable_size += SCORE_FUNCTION_STUB_SIZE * i;
3238 /* Assume there are two loadable segments consisting of
3239 contiguous sections. Is 5 enough? */
3240 local_gotno = (loadable_size >> 16) + 5;
3242 g->local_gotno += local_gotno;
3243 s->size += g->local_gotno * SCORE_ELF_GOT_SIZE (output_bfd);
3245 g->global_gotno = i;
3246 s->size += i * SCORE_ELF_GOT_SIZE (output_bfd);
3248 score_elf_resolve_final_got_entries (g);
3250 if (s->size > SCORE_ELF_GOT_MAX_SIZE (output_bfd))
3252 /* Fixme. Error message or Warning message should be issued here. */
3258 /* Set the sizes of the dynamic sections. */
3260 s3_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3264 bfd_boolean reltext;
3266 dynobj = elf_hash_table (info)->dynobj;
3267 BFD_ASSERT (dynobj != NULL);
3269 if (elf_hash_table (info)->dynamic_sections_created)
3271 /* Set the contents of the .interp section to the interpreter. */
3272 if (!bfd_link_pic (info) && !info->nointerp)
3274 s = bfd_get_linker_section (dynobj, ".interp");
3275 BFD_ASSERT (s != NULL);
3276 s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
3277 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3281 /* The check_relocs and adjust_dynamic_symbol entry points have
3282 determined the sizes of the various dynamic sections. Allocate
3285 for (s = dynobj->sections; s != NULL; s = s->next)
3289 if ((s->flags & SEC_LINKER_CREATED) == 0)
3292 /* It's OK to base decisions on the section name, because none
3293 of the dynobj section names depend upon the input files. */
3294 name = bfd_get_section_name (dynobj, s);
3296 if (CONST_STRNEQ (name, ".rel"))
3300 /* We only strip the section if the output section name
3301 has the same name. Otherwise, there might be several
3302 input sections for this output section. FIXME: This
3303 code is probably not needed these days anyhow, since
3304 the linker now does not create empty output sections. */
3305 if (s->output_section != NULL
3307 bfd_get_section_name (s->output_section->owner,
3308 s->output_section)) == 0)
3309 s->flags |= SEC_EXCLUDE;
3313 const char *outname;
3316 /* If this relocation section applies to a read only
3317 section, then we probably need a DT_TEXTREL entry.
3318 If the relocation section is .rel.dyn, we always
3319 assert a DT_TEXTREL entry rather than testing whether
3320 there exists a relocation to a read only section or
3322 outname = bfd_get_section_name (output_bfd, s->output_section);
3323 target = bfd_get_section_by_name (output_bfd, outname + 4);
3325 && (target->flags & SEC_READONLY) != 0
3326 && (target->flags & SEC_ALLOC) != 0) || strcmp (outname, ".rel.dyn") == 0)
3329 /* We use the reloc_count field as a counter if we need
3330 to copy relocs into the output file. */
3331 if (strcmp (name, ".rel.dyn") != 0)
3335 else if (CONST_STRNEQ (name, ".got"))
3337 /* s3_bfd_score_elf_always_size_sections() has already done
3338 most of the work, but some symbols may have been mapped
3339 to versions that we must now resolve in the got_entries
3342 else if (strcmp (name, SCORE_ELF_STUB_SECTION_NAME) == 0)
3344 /* IRIX rld assumes that the function stub isn't at the end
3345 of .text section. So put a dummy. XXX */
3346 s->size += SCORE_FUNCTION_STUB_SIZE;
3348 else if (! CONST_STRNEQ (name, ".init"))
3350 /* It's not one of our sections, so don't allocate space. */
3354 /* Allocate memory for the section contents. */
3355 s->contents = bfd_zalloc (dynobj, s->size);
3356 if (s->contents == NULL && s->size != 0)
3358 bfd_set_error (bfd_error_no_memory);
3363 if (elf_hash_table (info)->dynamic_sections_created)
3365 /* Add some entries to the .dynamic section. We fill in the
3366 values later, in s3_bfd_score_elf_finish_dynamic_sections, but we
3367 must add the entries now so that we get the correct size for
3368 the .dynamic section. The DT_DEBUG entry is filled in by the
3369 dynamic linker and used by the debugger. */
3371 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
3375 info->flags |= DF_TEXTREL;
3377 if ((info->flags & DF_TEXTREL) != 0)
3379 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
3383 if (! SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
3386 if (score_elf_rel_dyn_section (dynobj, FALSE))
3388 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0))
3391 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0))
3394 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0))
3398 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_BASE_ADDRESS, 0))
3401 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_LOCAL_GOTNO, 0))
3404 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_SYMTABNO, 0))
3407 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_UNREFEXTNO, 0))
3410 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_GOTSYM, 0))
3413 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_HIPAGENO, 0))
3421 s3_bfd_score_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3423 struct elf_link_hash_entry *h;
3424 struct bfd_link_hash_entry *bh;
3428 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3429 | SEC_LINKER_CREATED | SEC_READONLY);
3431 /* ABI requests the .dynamic section to be read only. */
3432 s = bfd_get_linker_section (abfd, ".dynamic");
3435 if (!bfd_set_section_flags (abfd, s, flags))
3439 /* We need to create .got section. */
3440 if (!score_elf_create_got_section (abfd, info, FALSE))
3443 if (!score_elf_rel_dyn_section (elf_hash_table (info)->dynobj, TRUE))
3446 /* Create .stub section. */
3447 if (bfd_get_linker_section (abfd, SCORE_ELF_STUB_SECTION_NAME) == NULL)
3449 s = bfd_make_section_anyway_with_flags (abfd, SCORE_ELF_STUB_SECTION_NAME,
3452 || !bfd_set_section_alignment (abfd, s, 2))
3457 if (!bfd_link_pic (info))
3461 name = "_DYNAMIC_LINK";
3463 if (!(_bfd_generic_link_add_one_symbol
3464 (info, abfd, name, BSF_GLOBAL, bfd_abs_section_ptr,
3465 (bfd_vma) 0, NULL, FALSE, get_elf_backend_data (abfd)->collect, &bh)))
3468 h = (struct elf_link_hash_entry *)bh;
3471 h->type = STT_SECTION;
3473 if (!bfd_elf_link_record_dynamic_symbol (info, h))
3481 /* Finish up dynamic symbol handling. We set the contents of various
3482 dynamic sections here. */
3484 s3_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
3485 struct bfd_link_info *info,
3486 struct elf_link_hash_entry *h,
3487 Elf_Internal_Sym *sym)
3491 struct score_got_info *g;
3494 dynobj = elf_hash_table (info)->dynobj;
3496 if (h->plt.offset != MINUS_ONE)
3499 bfd_byte stub[SCORE_FUNCTION_STUB_SIZE];
3501 /* This symbol has a stub. Set it up. */
3502 BFD_ASSERT (h->dynindx != -1);
3504 s = bfd_get_linker_section (dynobj, SCORE_ELF_STUB_SECTION_NAME);
3505 BFD_ASSERT (s != NULL);
3507 /* FIXME: Can h->dynindex be more than 64K? */
3508 if (h->dynindx & 0xffff0000)
3511 /* Fill the stub. */
3512 score_bfd_put_32 (output_bfd, STUB_LW, stub);
3513 score_bfd_put_32 (output_bfd, STUB_MOVE, stub + 4);
3514 score_bfd_put_32 (output_bfd, STUB_LI16 | (h->dynindx << 1), stub + 8);
3515 score_bfd_put_32 (output_bfd, STUB_BRL, stub + 12);
3517 BFD_ASSERT (h->plt.offset <= s->size);
3518 memcpy (s->contents + h->plt.offset, stub, SCORE_FUNCTION_STUB_SIZE);
3520 /* Mark the symbol as undefined. plt.offset != -1 occurs
3521 only for the referenced symbol. */
3522 sym->st_shndx = SHN_UNDEF;
3524 /* The run-time linker uses the st_value field of the symbol
3525 to reset the global offset table entry for this external
3526 to its stub address when unlinking a shared object. */
3527 sym->st_value = (s->output_section->vma + s->output_offset + h->plt.offset);
3530 BFD_ASSERT (h->dynindx != -1 || h->forced_local);
3532 sgot = score_elf_got_section (dynobj, FALSE);
3533 BFD_ASSERT (sgot != NULL);
3534 BFD_ASSERT (score_elf_section_data (sgot) != NULL);
3535 g = score_elf_section_data (sgot)->u.got_info;
3536 BFD_ASSERT (g != NULL);
3538 /* Run through the global symbol table, creating GOT entries for all
3539 the symbols that need them. */
3540 if (g->global_gotsym != NULL && h->dynindx >= g->global_gotsym->dynindx)
3545 value = sym->st_value;
3546 offset = score_elf_global_got_index (dynobj, h);
3547 score_bfd_put_32 (output_bfd, value, sgot->contents + offset);
3550 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3551 name = h->root.root.string;
3552 if (h == elf_hash_table (info)->hdynamic
3553 || h == elf_hash_table (info)->hgot)
3554 sym->st_shndx = SHN_ABS;
3555 else if (strcmp (name, "_DYNAMIC_LINK") == 0)
3557 sym->st_shndx = SHN_ABS;
3558 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
3561 else if (strcmp (name, GP_DISP_LABEL) == 0)
3563 sym->st_shndx = SHN_ABS;
3564 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
3565 sym->st_value = elf_gp (output_bfd);
3571 /* Finish up the dynamic sections. */
3573 s3_bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
3574 struct bfd_link_info *info)
3580 struct score_got_info *g;
3582 dynobj = elf_hash_table (info)->dynobj;
3584 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3586 sgot = score_elf_got_section (dynobj, FALSE);
3591 BFD_ASSERT (score_elf_section_data (sgot) != NULL);
3592 g = score_elf_section_data (sgot)->u.got_info;
3593 BFD_ASSERT (g != NULL);
3596 if (elf_hash_table (info)->dynamic_sections_created)
3600 BFD_ASSERT (sdyn != NULL);
3601 BFD_ASSERT (g != NULL);
3603 for (b = sdyn->contents;
3604 b < sdyn->contents + sdyn->size;
3605 b += SCORE_ELF_DYN_SIZE (dynobj))
3607 Elf_Internal_Dyn dyn;
3610 bfd_boolean swap_out_p;
3612 /* Read in the current dynamic entry. */
3613 (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
3615 /* Assume that we're going to modify it and write it out. */
3621 s = score_elf_rel_dyn_section (dynobj, FALSE);
3622 BFD_ASSERT (s != NULL);
3623 dyn.d_un.d_val = SCORE_ELF_REL_SIZE (dynobj);
3627 /* Rewrite DT_STRSZ. */
3628 dyn.d_un.d_val = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
3633 s = bfd_get_section_by_name (output_bfd, name);
3634 BFD_ASSERT (s != NULL);
3635 dyn.d_un.d_ptr = s->vma;
3638 case DT_SCORE_BASE_ADDRESS:
3639 s = output_bfd->sections;
3640 BFD_ASSERT (s != NULL);
3641 dyn.d_un.d_ptr = s->vma & ~(bfd_vma) 0xffff;
3644 case DT_SCORE_LOCAL_GOTNO:
3645 dyn.d_un.d_val = g->local_gotno;
3648 case DT_SCORE_UNREFEXTNO:
3649 /* The index into the dynamic symbol table which is the
3650 entry of the first external symbol that is not
3651 referenced within the same object. */
3652 dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
3655 case DT_SCORE_GOTSYM:
3656 if (g->global_gotsym)
3658 dyn.d_un.d_val = g->global_gotsym->dynindx;
3661 /* In case if we don't have global got symbols we default
3662 to setting DT_SCORE_GOTSYM to the same value as
3663 DT_SCORE_SYMTABNO, so we just fall through. */
3665 case DT_SCORE_SYMTABNO:
3667 elemsize = SCORE_ELF_SYM_SIZE (output_bfd);
3668 s = bfd_get_section_by_name (output_bfd, name);
3669 BFD_ASSERT (s != NULL);
3671 dyn.d_un.d_val = s->size / elemsize;
3674 case DT_SCORE_HIPAGENO:
3675 dyn.d_un.d_val = g->local_gotno - SCORE_RESERVED_GOTNO;
3684 (*get_elf_backend_data (dynobj)->s->swap_dyn_out) (dynobj, &dyn, b);
3688 /* The first entry of the global offset table will be filled at
3689 runtime. The second entry will be used by some runtime loaders.
3690 This isn't the case of IRIX rld. */
3691 if (sgot != NULL && sgot->size > 0)
3693 score_bfd_put_32 (output_bfd, 0, sgot->contents);
3694 score_bfd_put_32 (output_bfd, 0x80000000, sgot->contents + SCORE_ELF_GOT_SIZE (output_bfd));
3698 elf_section_data (sgot->output_section)->this_hdr.sh_entsize
3699 = SCORE_ELF_GOT_SIZE (output_bfd);
3702 /* We need to sort the entries of the dynamic relocation section. */
3703 s = score_elf_rel_dyn_section (dynobj, FALSE);
3705 if (s != NULL && s->size > (bfd_vma)2 * SCORE_ELF_REL_SIZE (output_bfd))
3707 reldyn_sorting_bfd = output_bfd;
3708 qsort ((Elf32_External_Rel *) s->contents + 1, s->reloc_count - 1,
3709 sizeof (Elf32_External_Rel), score_elf_sort_dynamic_relocs);
3715 /* This function set up the ELF section header for a BFD section in preparation for writing
3716 it out. This is where the flags and type fields are set for unusual sections. */
3718 s3_bfd_score_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
3719 Elf_Internal_Shdr *hdr,
3724 name = bfd_get_section_name (abfd, sec);
3726 if (strcmp (name, ".got") == 0
3727 || strcmp (name, ".srdata") == 0
3728 || strcmp (name, ".sdata") == 0
3729 || strcmp (name, ".sbss") == 0)
3730 hdr->sh_flags |= SHF_SCORE_GPREL;
3735 /* This function do additional processing on the ELF section header before writing
3736 it out. This is used to set the flags and type fields for some sections. */
3738 /* assign_file_positions_except_relocs() check section flag and if it is allocatable,
3739 warning message will be issued. backend_fake_section is called before
3740 assign_file_positions_except_relocs(); backend_section_processing after it. so, we
3741 modify section flag there, but not backend_fake_section. */
3743 s3_bfd_score_elf_section_processing (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *hdr)
3745 if (hdr->bfd_section != NULL)
3747 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
3749 if (strcmp (name, ".sdata") == 0)
3751 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
3752 hdr->sh_type = SHT_PROGBITS;
3754 else if (strcmp (name, ".sbss") == 0)
3756 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
3757 hdr->sh_type = SHT_NOBITS;
3759 else if (strcmp (name, ".srdata") == 0)
3761 hdr->sh_flags |= SHF_ALLOC | SHF_SCORE_GPREL;
3762 hdr->sh_type = SHT_PROGBITS;
3770 s3_bfd_score_elf_write_section (bfd *output_bfd, asection *sec, bfd_byte *contents)
3772 bfd_byte *to, *from, *end;
3775 if (strcmp (sec->name, ".pdr") != 0)
3778 if (score_elf_section_data (sec)->u.tdata == NULL)
3782 end = contents + sec->size;
3783 for (from = contents, i = 0; from < end; from += PDR_SIZE, i++)
3785 if ((score_elf_section_data (sec)->u.tdata)[i] == 1)
3789 memcpy (to, from, PDR_SIZE);
3793 bfd_set_section_contents (output_bfd, sec->output_section, contents,
3794 (file_ptr) sec->output_offset, sec->size);
3799 /* Copy data from a SCORE ELF indirect symbol to its direct symbol, hiding the old
3800 indirect symbol. Process additional relocation information. */
3802 s3_bfd_score_elf_copy_indirect_symbol (struct bfd_link_info *info,
3803 struct elf_link_hash_entry *dir,
3804 struct elf_link_hash_entry *ind)
3806 struct score_elf_link_hash_entry *dirscore, *indscore;
3808 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3810 if (ind->root.type != bfd_link_hash_indirect)
3813 dirscore = (struct score_elf_link_hash_entry *) dir;
3814 indscore = (struct score_elf_link_hash_entry *) ind;
3815 dirscore->possibly_dynamic_relocs += indscore->possibly_dynamic_relocs;
3817 if (indscore->readonly_reloc)
3818 dirscore->readonly_reloc = TRUE;
3820 if (indscore->no_fn_stub)
3821 dirscore->no_fn_stub = TRUE;
3824 /* Remove information about discarded functions from other sections which mention them. */
3826 s3_bfd_score_elf_discard_info (bfd *abfd, struct elf_reloc_cookie *cookie,
3827 struct bfd_link_info *info)
3830 bfd_boolean ret = FALSE;
3831 unsigned char *tdata;
3834 o = bfd_get_section_by_name (abfd, ".pdr");
3835 if ((!o) || (o->size == 0) || (o->size % PDR_SIZE != 0)
3836 || (o->output_section != NULL && bfd_is_abs_section (o->output_section)))
3839 tdata = bfd_zmalloc (o->size / PDR_SIZE);
3843 cookie->rels = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, info->keep_memory);
3850 cookie->rel = cookie->rels;
3851 cookie->relend = cookie->rels + o->reloc_count;
3853 for (i = 0, skip = 0; i < o->size; i++)
3855 if (bfd_elf_reloc_symbol_deleted_p (i * PDR_SIZE, cookie))
3864 score_elf_section_data (o)->u.tdata = tdata;
3865 o->size -= skip * PDR_SIZE;
3871 if (!info->keep_memory)
3872 free (cookie->rels);
3877 /* Signal that discard_info() has removed the discarded relocations for this section. */
3879 s3_bfd_score_elf_ignore_discarded_relocs (asection *sec)
3881 if (strcmp (sec->name, ".pdr") == 0)
3886 /* Return the section that should be marked against GC for a given
3889 s3_bfd_score_elf_gc_mark_hook (asection *sec,
3890 struct bfd_link_info *info,
3891 Elf_Internal_Rela *rel,
3892 struct elf_link_hash_entry *h,
3893 Elf_Internal_Sym *sym)
3896 switch (ELF32_R_TYPE (rel->r_info))
3898 case R_SCORE_GNU_VTINHERIT:
3899 case R_SCORE_GNU_VTENTRY:
3903 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
3906 /* Support for core dump NOTE sections. */
3909 s3_bfd_score_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3912 unsigned int raw_size;
3914 switch (note->descsz)
3919 case 148: /* Linux/Score 32-bit. */
3921 elf_tdata (abfd)->core->signal
3922 = score_bfd_get_16 (abfd, note->descdata + 12);
3925 elf_tdata (abfd)->core->lwpid
3926 = score_bfd_get_32 (abfd, note->descdata + 24);
3935 /* Make a ".reg/999" section. */
3936 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
3937 note->descpos + offset);
3941 s3_bfd_score_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3943 switch (note->descsz)
3948 case 124: /* Linux/Score elf_prpsinfo. */
3949 elf_tdata (abfd)->core->program
3950 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
3951 elf_tdata (abfd)->core->command
3952 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
3955 /* Note that for some reason, a spurious space is tacked
3956 onto the end of the args in some (at least one anyway)
3957 implementations, so strip it off if it exists. */
3960 char *command = elf_tdata (abfd)->core->command;
3961 int n = strlen (command);
3963 if (0 < n && command[n - 1] == ' ')
3964 command[n - 1] = '\0';
3971 /* Score BFD functions. */
3972 static reloc_howto_type *
3973 s3_elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
3977 for (i = 0; i < ARRAY_SIZE (elf32_score_reloc_map); i++)
3978 if (elf32_score_reloc_map[i].bfd_reloc_val == code)
3979 return &elf32_score_howto_table[elf32_score_reloc_map[i].elf_reloc_val];
3984 static reloc_howto_type *
3985 elf32_score_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3991 i < (sizeof (elf32_score_howto_table)
3992 / sizeof (elf32_score_howto_table[0]));
3994 if (elf32_score_howto_table[i].name != NULL
3995 && strcasecmp (elf32_score_howto_table[i].name, r_name) == 0)
3996 return &elf32_score_howto_table[i];
4002 s3_elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
4004 FILE *file = (FILE *) ptr;
4006 BFD_ASSERT (abfd != NULL && ptr != NULL);
4008 /* Print normal ELF private data. */
4009 _bfd_elf_print_private_bfd_data (abfd, ptr);
4011 /* xgettext:c-format */
4012 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
4013 if (elf_elfheader (abfd)->e_flags & EF_SCORE_PIC)
4015 fprintf (file, _(" [pic]"));
4017 if (elf_elfheader (abfd)->e_flags & EF_SCORE_FIXDEP)
4019 fprintf (file, _(" [fix dep]"));
4027 s3_elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4032 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
4035 in_flags = elf_elfheader (ibfd)->e_flags;
4036 out_flags = elf_elfheader (obfd)->e_flags;
4038 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4039 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4042 in_flags = elf_elfheader (ibfd)->e_flags;
4043 out_flags = elf_elfheader (obfd)->e_flags;
4045 if (! elf_flags_init (obfd))
4047 elf_flags_init (obfd) = TRUE;
4048 elf_elfheader (obfd)->e_flags = in_flags;
4050 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4051 && bfd_get_arch_info (obfd)->the_default)
4053 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
4059 if (((in_flags & EF_SCORE_PIC) != 0) != ((out_flags & EF_SCORE_PIC) != 0))
4061 (*_bfd_error_handler) (_("%B: warning: linking PIC files with non-PIC files"), ibfd);
4064 /* FIXME: Maybe dependency fix compatibility should be checked here. */
4070 s3_elf32_score_new_section_hook (bfd *abfd, asection *sec)
4072 struct _score_elf_section_data *sdata;
4073 bfd_size_type amt = sizeof (*sdata);
4075 sdata = bfd_zalloc (abfd, amt);
4078 sec->used_by_bfd = sdata;
4080 return _bfd_elf_new_section_hook (abfd, sec);
4083 /*****************************************************************************/
4085 /* s3_s7: backend hooks. */
4087 _bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
4089 Elf_Internal_Rela *elf_reloc)
4091 if (bfd_get_mach (abfd) == bfd_mach_score3)
4092 return s3_bfd_score_info_to_howto (abfd, bfd_reloc, elf_reloc);
4094 return s7_bfd_score_info_to_howto (abfd, bfd_reloc, elf_reloc);
4098 _bfd_score_elf_relocate_section (bfd *output_bfd,
4099 struct bfd_link_info *info,
4101 asection *input_section,
4103 Elf_Internal_Rela *relocs,
4104 Elf_Internal_Sym *local_syms,
4105 asection **local_sections)
4107 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4108 return s3_bfd_score_elf_relocate_section (output_bfd,
4109 info, input_bfd, input_section, contents, relocs,
4110 local_syms, local_sections);
4112 return s7_bfd_score_elf_relocate_section (output_bfd,
4113 info, input_bfd, input_section, contents, relocs,
4114 local_syms, local_sections);
4118 _bfd_score_elf_check_relocs (bfd *abfd,
4119 struct bfd_link_info *info,
4121 const Elf_Internal_Rela *relocs)
4123 if (bfd_get_mach (abfd) == bfd_mach_score3)
4124 return s3_bfd_score_elf_check_relocs (abfd, info, sec, relocs);
4126 return s7_bfd_score_elf_check_relocs (abfd, info, sec, relocs);
4130 _bfd_score_elf_add_symbol_hook (bfd *abfd,
4131 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4132 Elf_Internal_Sym *sym,
4133 const char **namep ATTRIBUTE_UNUSED,
4134 flagword *flagsp ATTRIBUTE_UNUSED,
4138 if (bfd_get_mach (abfd) == bfd_mach_score3)
4139 return s3_bfd_score_elf_add_symbol_hook (abfd, info, sym, namep, flagsp,
4142 return s7_bfd_score_elf_add_symbol_hook (abfd, info, sym, namep, flagsp,
4147 _bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
4149 if (bfd_get_mach (abfd) == bfd_mach_score3)
4150 return s3_bfd_score_elf_symbol_processing (abfd, asym);
4152 return s7_bfd_score_elf_symbol_processing (abfd, asym);
4156 _bfd_score_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4157 const char *name ATTRIBUTE_UNUSED,
4158 Elf_Internal_Sym *sym,
4159 asection *input_sec,
4160 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
4162 /* If link a empty .o, then this filed is NULL. */
4163 if (info->input_bfds == NULL)
4165 /* If we see a common symbol, which implies a relocatable link, then
4166 if a symbol was small common in an input file, mark it as small
4167 common in the output file. */
4168 if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
4169 sym->st_shndx = SHN_SCORE_SCOMMON;
4173 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4174 return s3_bfd_score_elf_link_output_symbol_hook (info, name, sym, input_sec, h);
4176 return s7_bfd_score_elf_link_output_symbol_hook (info, name, sym, input_sec, h);
4180 _bfd_score_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4184 if (bfd_get_mach (abfd) == bfd_mach_score3)
4185 return s3_bfd_score_elf_section_from_bfd_section (abfd, sec, retval);
4187 return s7_bfd_score_elf_section_from_bfd_section (abfd, sec, retval);
4191 _bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4192 struct elf_link_hash_entry *h)
4194 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4195 return s3_bfd_score_elf_adjust_dynamic_symbol (info, h);
4197 return s7_bfd_score_elf_adjust_dynamic_symbol (info, h);
4201 _bfd_score_elf_always_size_sections (bfd *output_bfd,
4202 struct bfd_link_info *info)
4204 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4205 return s3_bfd_score_elf_always_size_sections (output_bfd, info);
4207 return s7_bfd_score_elf_always_size_sections (output_bfd, info);
4211 _bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4213 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4214 return s3_bfd_score_elf_size_dynamic_sections (output_bfd, info);
4216 return s7_bfd_score_elf_size_dynamic_sections (output_bfd, info);
4220 _bfd_score_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4222 if (bfd_get_mach (abfd) == bfd_mach_score3)
4223 return s3_bfd_score_elf_create_dynamic_sections (abfd, info);
4225 return s7_bfd_score_elf_create_dynamic_sections (abfd, info);
4229 _bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
4230 struct bfd_link_info *info,
4231 struct elf_link_hash_entry *h,
4232 Elf_Internal_Sym *sym)
4234 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4235 return s3_bfd_score_elf_finish_dynamic_symbol (output_bfd, info, h, sym);
4237 return s7_bfd_score_elf_finish_dynamic_symbol (output_bfd, info, h, sym);
4241 _bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
4242 struct bfd_link_info *info)
4244 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4245 return s3_bfd_score_elf_finish_dynamic_sections (output_bfd, info);
4247 return s7_bfd_score_elf_finish_dynamic_sections (output_bfd, info);
4251 _bfd_score_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
4252 Elf_Internal_Shdr *hdr,
4255 if (bfd_get_mach (abfd) == bfd_mach_score3)
4256 return s3_bfd_score_elf_fake_sections (abfd, hdr, sec);
4258 return s7_bfd_score_elf_fake_sections (abfd, hdr, sec);
4262 _bfd_score_elf_section_processing (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *hdr)
4264 if (bfd_get_mach (abfd) == bfd_mach_score3)
4265 return s3_bfd_score_elf_section_processing (abfd, hdr);
4267 return s7_bfd_score_elf_section_processing (abfd, hdr);
4271 _bfd_score_elf_write_section (bfd *output_bfd,
4272 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
4273 asection *sec, bfd_byte *contents)
4275 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4276 return s3_bfd_score_elf_write_section (output_bfd, sec, contents);
4278 return s7_bfd_score_elf_write_section (output_bfd, sec, contents);
4282 _bfd_score_elf_copy_indirect_symbol (struct bfd_link_info *info,
4283 struct elf_link_hash_entry *dir,
4284 struct elf_link_hash_entry *ind)
4286 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4287 return s3_bfd_score_elf_copy_indirect_symbol (info, dir, ind);
4289 return s7_bfd_score_elf_copy_indirect_symbol (info, dir, ind);
4293 _bfd_score_elf_hide_symbol (struct bfd_link_info *info,
4294 struct elf_link_hash_entry *entry,
4295 bfd_boolean force_local)
4297 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4298 return s3_bfd_score_elf_hide_symbol (info, entry, force_local);
4300 return s7_bfd_score_elf_hide_symbol (info, entry, force_local);
4304 _bfd_score_elf_discard_info (bfd *abfd, struct elf_reloc_cookie *cookie,
4305 struct bfd_link_info *info)
4307 if (bfd_get_mach (abfd) == bfd_mach_score3)
4308 return s3_bfd_score_elf_discard_info (abfd, cookie, info);
4310 return s7_bfd_score_elf_discard_info (abfd, cookie, info);
4314 _bfd_score_elf_ignore_discarded_relocs (asection *sec)
4316 if (bfd_get_mach (sec->owner) == bfd_mach_score3)
4317 return s3_bfd_score_elf_ignore_discarded_relocs (sec);
4319 return s7_bfd_score_elf_ignore_discarded_relocs (sec);
4323 _bfd_score_elf_gc_mark_hook (asection *sec,
4324 struct bfd_link_info *info,
4325 Elf_Internal_Rela *rel,
4326 struct elf_link_hash_entry *h,
4327 Elf_Internal_Sym *sym)
4329 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4330 return s3_bfd_score_elf_gc_mark_hook (sec, info, rel, h, sym);
4332 return s7_bfd_score_elf_gc_mark_hook (sec, info, rel, h, sym);
4336 _bfd_score_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4338 if (bfd_get_mach (abfd) == bfd_mach_score3)
4339 return s3_bfd_score_elf_grok_prstatus (abfd, note);
4341 return s7_bfd_score_elf_grok_prstatus (abfd, note);
4345 _bfd_score_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4347 if (bfd_get_mach (abfd) == bfd_mach_score3)
4348 return s3_bfd_score_elf_grok_psinfo (abfd, note);
4350 return s7_bfd_score_elf_grok_psinfo (abfd, note);
4353 static reloc_howto_type *
4354 elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
4357 gas will call elf32_score_reloc_type_lookup, and don't write elf file.
4358 So just using score3, but we don't know ld will call this or not.
4359 If so, this way can't work. */
4362 return s3_elf32_score_reloc_type_lookup (abfd, code);
4364 return s7_elf32_score_reloc_type_lookup (abfd, code);
4367 /* Create a score elf linker hash table.
4368 This is a copy of _bfd_elf_link_hash_table_create() except with a
4369 different hash table entry creation function. */
4371 static struct bfd_link_hash_table *
4372 elf32_score_link_hash_table_create (bfd *abfd)
4374 struct elf_link_hash_table *ret;
4375 bfd_size_type amt = sizeof (struct elf_link_hash_table);
4377 ret = (struct elf_link_hash_table *) bfd_zmalloc (amt);
4381 if (!_bfd_elf_link_hash_table_init (ret, abfd, score_elf_link_hash_newfunc,
4382 sizeof (struct score_elf_link_hash_entry),
4393 elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
4395 if (bfd_get_mach (abfd) == bfd_mach_score3)
4396 return s3_elf32_score_print_private_bfd_data (abfd, ptr);
4398 return s7_elf32_score_print_private_bfd_data (abfd, ptr);
4402 elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4404 if (bfd_get_mach (obfd) == bfd_mach_score3)
4405 return s3_elf32_score_merge_private_bfd_data (ibfd, obfd);
4407 return s7_elf32_score_merge_private_bfd_data (ibfd, obfd);
4411 elf32_score_new_section_hook (bfd *abfd, asection *sec)
4413 if (bfd_get_mach (abfd) == bfd_mach_score3)
4414 return s3_elf32_score_new_section_hook (abfd, sec);
4416 return s7_elf32_score_new_section_hook (abfd, sec);
4420 /* s3_s7: don't need to split. */
4422 /* Set the right machine number. */
4424 _bfd_score_elf_score_object_p (bfd * abfd)
4426 int e_set = bfd_mach_score7;
4428 if (elf_elfheader (abfd)->e_machine == EM_SCORE)
4430 int e_mach = elf_elfheader (abfd)->e_flags & EF_SCORE_MACH & EF_OMIT_PIC_FIXDD;
4433 /* Set default target is score7. */
4435 case E_SCORE_MACH_SCORE7:
4436 e_set = bfd_mach_score7;
4439 case E_SCORE_MACH_SCORE3:
4440 e_set = bfd_mach_score3;
4445 return bfd_default_set_arch_mach (abfd, bfd_arch_score, e_set);
4449 _bfd_score_elf_common_definition (Elf_Internal_Sym *sym)
4451 return (sym->st_shndx == SHN_COMMON || sym->st_shndx == SHN_SCORE_SCOMMON);
4454 /*****************************************************************************/
4458 #define TARGET_LITTLE_SYM score_elf32_le_vec
4459 #define TARGET_LITTLE_NAME "elf32-littlescore"
4460 #define TARGET_BIG_SYM score_elf32_be_vec
4461 #define TARGET_BIG_NAME "elf32-bigscore"
4462 #define ELF_ARCH bfd_arch_score
4463 #define ELF_MACHINE_CODE EM_SCORE
4464 #define ELF_MACHINE_ALT1 EM_SCORE_OLD
4465 #define ELF_MAXPAGESIZE 0x8000
4467 #define elf_info_to_howto 0
4468 #define elf_info_to_howto_rel _bfd_score_info_to_howto
4469 #define elf_backend_relocate_section _bfd_score_elf_relocate_section
4470 #define elf_backend_check_relocs _bfd_score_elf_check_relocs
4471 #define elf_backend_add_symbol_hook _bfd_score_elf_add_symbol_hook
4472 #define elf_backend_symbol_processing _bfd_score_elf_symbol_processing
4473 #define elf_backend_link_output_symbol_hook \
4474 _bfd_score_elf_link_output_symbol_hook
4475 #define elf_backend_section_from_bfd_section \
4476 _bfd_score_elf_section_from_bfd_section
4477 #define elf_backend_adjust_dynamic_symbol \
4478 _bfd_score_elf_adjust_dynamic_symbol
4479 #define elf_backend_always_size_sections \
4480 _bfd_score_elf_always_size_sections
4481 #define elf_backend_size_dynamic_sections \
4482 _bfd_score_elf_size_dynamic_sections
4483 #define elf_backend_omit_section_dynsym \
4484 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4485 #define elf_backend_create_dynamic_sections \
4486 _bfd_score_elf_create_dynamic_sections
4487 #define elf_backend_finish_dynamic_symbol \
4488 _bfd_score_elf_finish_dynamic_symbol
4489 #define elf_backend_finish_dynamic_sections \
4490 _bfd_score_elf_finish_dynamic_sections
4491 #define elf_backend_fake_sections _bfd_score_elf_fake_sections
4492 #define elf_backend_section_processing _bfd_score_elf_section_processing
4493 #define elf_backend_write_section _bfd_score_elf_write_section
4494 #define elf_backend_copy_indirect_symbol _bfd_score_elf_copy_indirect_symbol
4495 #define elf_backend_hide_symbol _bfd_score_elf_hide_symbol
4496 #define elf_backend_discard_info _bfd_score_elf_discard_info
4497 #define elf_backend_ignore_discarded_relocs \
4498 _bfd_score_elf_ignore_discarded_relocs
4499 #define elf_backend_gc_mark_hook _bfd_score_elf_gc_mark_hook
4500 #define elf_backend_grok_prstatus _bfd_score_elf_grok_prstatus
4501 #define elf_backend_grok_psinfo _bfd_score_elf_grok_psinfo
4502 #define elf_backend_can_gc_sections 1
4503 #define elf_backend_want_plt_sym 0
4504 #define elf_backend_got_header_size (4 * SCORE_RESERVED_GOTNO)
4505 #define elf_backend_plt_header_size 0
4506 #define elf_backend_collect TRUE
4507 #define elf_backend_type_change_ok TRUE
4508 #define elf_backend_object_p _bfd_score_elf_score_object_p
4510 #define bfd_elf32_bfd_reloc_type_lookup elf32_score_reloc_type_lookup
4511 #define bfd_elf32_bfd_reloc_name_lookup \
4512 elf32_score_reloc_name_lookup
4513 #define bfd_elf32_bfd_link_hash_table_create elf32_score_link_hash_table_create
4514 #define bfd_elf32_bfd_print_private_bfd_data elf32_score_print_private_bfd_data
4515 #define bfd_elf32_bfd_merge_private_bfd_data elf32_score_merge_private_bfd_data
4516 #define bfd_elf32_new_section_hook elf32_score_new_section_hook
4518 #include "elf32-target.h"