2009-06-12 Tristan Gingold <gingold@adacore.com>
[binutils.git] / bfd / elf32-score.c
bloba3308286d55ff7b16a2fc3ca168fb33ef2e10699
1 /* 32-bit ELF support for S+core.
2 Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
3 Contributed by
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. */
25 #include "sysdep.h"
26 #include "bfd.h"
27 #include "libbfd.h"
28 #include "libiberty.h"
29 #include "elf-bfd.h"
30 #include "elf/score.h"
31 #include "elf/common.h"
32 #include "elf/internal.h"
33 #include "hashtab.h"
34 #include "elf32-score.h"
37 int score3 = 0;
38 int score7 = 1;
40 /* Score ELF linker hash table. */
41 struct score_elf_link_hash_table
43 /* The main hash table. */
44 struct elf_link_hash_table root;
47 /* The SCORE ELF linker needs additional information for each symbol in
48 the global hash table. */
49 struct score_elf_link_hash_entry
51 struct elf_link_hash_entry root;
53 /* Number of R_SCORE_ABS32, R_SCORE_REL32 relocs against this symbol. */
54 unsigned int possibly_dynamic_relocs;
56 /* If the R_SCORE_ABS32, R_SCORE_REL32 reloc is against a readonly section. */
57 bfd_boolean readonly_reloc;
59 /* We must not create a stub for a symbol that has relocations related to
60 taking the function's address, i.e. any but R_SCORE_CALL15 ones. */
61 bfd_boolean no_fn_stub;
63 /* Are we forced local? This will only be set if we have converted
64 the initial global GOT entry to a local GOT entry. */
65 bfd_boolean forced_local;
68 /* Traverse a score ELF linker hash table. */
69 #define score_elf_link_hash_traverse(table, func, info) \
70 (elf_link_hash_traverse \
71 (&(table)->root, \
72 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
73 (info)))
75 /* Get the SCORE elf linker hash table from a link_info structure. */
76 #define score_elf_hash_table(info) \
77 ((struct score_elf_link_hash_table *) ((info)->hash))
79 /* This structure is used to hold .got entries while estimating got sizes. */
80 struct score_got_entry
82 /* The input bfd in which the symbol is defined. */
83 bfd *abfd;
84 /* The index of the symbol, as stored in the relocation r_info, if
85 we have a local symbol; -1 otherwise. */
86 long symndx;
87 union
89 /* If abfd == NULL, an address that must be stored in the got. */
90 bfd_vma address;
91 /* If abfd != NULL && symndx != -1, the addend of the relocation
92 that should be added to the symbol value. */
93 bfd_vma addend;
94 /* If abfd != NULL && symndx == -1, the hash table entry
95 corresponding to a global symbol in the got (or, local, if
96 h->forced_local). */
97 struct score_elf_link_hash_entry *h;
98 } d;
100 /* The offset from the beginning of the .got section to the entry
101 corresponding to this symbol+addend. If it's a global symbol
102 whose offset is yet to be decided, it's going to be -1. */
103 long gotidx;
106 /* This structure is passed to score_elf_sort_hash_table_f when sorting
107 the dynamic symbols. */
109 struct score_elf_hash_sort_data
111 /* The symbol in the global GOT with the lowest dynamic symbol table index. */
112 struct elf_link_hash_entry *low;
113 /* The least dynamic symbol table index corresponding to a symbol with a GOT entry. */
114 long min_got_dynindx;
115 /* The greatest dynamic symbol table index corresponding to a symbol
116 with a GOT entry that is not referenced (e.g., a dynamic symbol
117 with dynamic relocations pointing to it from non-primary GOTs). */
118 long max_unref_got_dynindx;
119 /* The greatest dynamic symbol table index not corresponding to a
120 symbol without a GOT entry. */
121 long max_non_got_dynindx;
124 struct score_got_info
126 /* The global symbol in the GOT with the lowest index in the dynamic
127 symbol table. */
128 struct elf_link_hash_entry *global_gotsym;
129 /* The number of global .got entries. */
130 unsigned int global_gotno;
131 /* The number of local .got entries. */
132 unsigned int local_gotno;
133 /* The number of local .got entries we have used. */
134 unsigned int assigned_gotno;
135 /* A hash table holding members of the got. */
136 struct htab *got_entries;
137 /* In multi-got links, a pointer to the next got (err, rather, most
138 of the time, it points to the previous got). */
139 struct score_got_info *next;
142 /* A structure used to count GOT entries, for GOT entry or ELF symbol table traversal. */
143 struct _score_elf_section_data
145 struct bfd_elf_section_data elf;
146 union
148 struct score_got_info *got_info;
149 bfd_byte *tdata;
154 #define score_elf_section_data(sec) \
155 ((struct _score_elf_section_data *) elf_section_data (sec))
157 /* The size of a symbol-table entry. */
158 #define SCORE_ELF_SYM_SIZE(abfd) \
159 (get_elf_backend_data (abfd)->s->sizeof_sym)
161 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
162 from smaller values. Start with zero, widen, *then* decrement. */
163 #define MINUS_ONE (((bfd_vma)0) - 1)
164 #define MINUS_TWO (((bfd_vma)0) - 2)
166 #define PDR_SIZE 32
169 /* The number of local .got entries we reserve. */
170 #define SCORE_RESERVED_GOTNO (2)
171 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
173 /* The offset of $gp from the beginning of the .got section. */
174 #define ELF_SCORE_GP_OFFSET(abfd) (0x3ff0)
175 /* The maximum size of the GOT for it to be addressable using 15-bit offsets from $gp. */
176 #define SCORE_ELF_GOT_MAX_SIZE(abfd) (ELF_SCORE_GP_OFFSET(abfd) + 0x3fff)
178 #define SCORE_ELF_STUB_SECTION_NAME (".SCORE.stub")
179 #define SCORE_FUNCTION_STUB_SIZE (16)
181 #define STUB_LW 0xc3bcc010 /* lw r29, [r28, -0x3ff0] */
182 #define STUB_MOVE 0x8363bc56 /* mv r27, r3 */
183 #define STUB_LI16 0x87548000 /* ori r26, .dynsym_index */
184 #define STUB_BRL 0x801dbc09 /* brl r29 */
186 #define SCORE_ELF_GOT_SIZE(abfd) \
187 (get_elf_backend_data (abfd)->s->arch_size / 8)
189 #define SCORE_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
190 (_bfd_elf_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
192 /* The size of an external dynamic table entry. */
193 #define SCORE_ELF_DYN_SIZE(abfd) \
194 (get_elf_backend_data (abfd)->s->sizeof_dyn)
196 /* The size of an external REL relocation. */
197 #define SCORE_ELF_REL_SIZE(abfd) \
198 (get_elf_backend_data (abfd)->s->sizeof_rel)
200 /* The default alignment for sections, as a power of two. */
201 #define SCORE_ELF_LOG_FILE_ALIGN(abfd)\
202 (get_elf_backend_data (abfd)->s->log_file_align)
204 static bfd_byte *hi16_rel_addr;
206 /* This will be used when we sort the dynamic relocation records. */
207 static bfd *reldyn_sorting_bfd;
209 /* SCORE ELF uses two common sections. One is the usual one, and the
210 other is for small objects. All the small objects are kept
211 together, and then referenced via the gp pointer, which yields
212 faster assembler code. This is what we use for the small common
213 section. This approach is copied from ecoff.c. */
214 static asection score_elf_scom_section;
215 static asymbol score_elf_scom_symbol;
216 static asymbol *score_elf_scom_symbol_ptr;
218 static bfd_vma
219 score_bfd_get_16 (bfd *abfd, const void *data)
221 return bfd_get_16 (abfd, data);
224 static bfd_vma
225 score3_bfd_getl32 (const void *p)
227 const bfd_byte *addr = p;
228 unsigned long v;
230 v = (unsigned long) addr[2];
231 v |= (unsigned long) addr[3] << 8;
232 v |= (unsigned long) addr[0] << 16;
233 v |= (unsigned long) addr[1] << 24;
234 return v;
237 static bfd_vma
238 score3_bfd_getl48 (const void *p)
240 const bfd_byte *addr = p;
241 unsigned long long v;
243 v = (unsigned long long) addr[4];
244 v |= (unsigned long long) addr[5] << 8;
245 v |= (unsigned long long) addr[2] << 16;
246 v |= (unsigned long long) addr[3] << 24;
247 v |= (unsigned long long) addr[0] << 32;
248 v |= (unsigned long long) addr[1] << 40;
249 return v;
252 static bfd_vma
253 score_bfd_get_32 (bfd *abfd, const void *data)
255 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
256 return score3_bfd_getl32 (data);
257 else
258 return bfd_get_32 (abfd, data);
261 static bfd_vma
262 score_bfd_get_48 (bfd *abfd, const void *p)
264 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
265 return score3_bfd_getl48 (p);
266 else
267 return bfd_get_bits (p, 48, 1);
270 static void
271 score_bfd_put_16 (bfd *abfd, bfd_vma addr, void *data)
273 return bfd_put_16 (abfd, addr, data);
276 static void
277 score3_bfd_putl32 (bfd_vma data, void *p)
279 bfd_byte *addr = p;
280 addr[0] = (data >> 16) & 0xff;
281 addr[1] = (data >> 24) & 0xff;
282 addr[2] = data & 0xff;
283 addr[3] = (data >> 8) & 0xff;
286 static void
287 score3_bfd_putl48 (bfd_vma data, void *p)
289 bfd_byte *addr = p;
290 addr[0] = (data >> 32) & 0xff;
291 addr[1] = (data >> 40) & 0xff;
292 addr[2] = (data >> 16) & 0xff;
293 addr[3] = (data >> 24) & 0xff;
294 addr[4] = data & 0xff;
295 addr[5] = (data >> 8) & 0xff;
298 static void
299 score_bfd_put_32 (bfd *abfd, bfd_vma addr, void *data)
301 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
302 return score3_bfd_putl32 (addr, data);
303 else
304 return bfd_put_32 (abfd, addr, data);
307 static void
308 score_bfd_put_48 (bfd *abfd, bfd_vma val, void *p)
310 if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
311 return score3_bfd_putl48 (val, p);
312 else
313 return bfd_put_bits (val, p, 48, 1);
316 static bfd_reloc_status_type
317 score_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
318 arelent *reloc_entry,
319 asymbol *symbol ATTRIBUTE_UNUSED,
320 void * data,
321 asection *input_section ATTRIBUTE_UNUSED,
322 bfd *output_bfd ATTRIBUTE_UNUSED,
323 char **error_message ATTRIBUTE_UNUSED)
325 hi16_rel_addr = (bfd_byte *) data + reloc_entry->address;
326 return bfd_reloc_ok;
329 static bfd_reloc_status_type
330 score_elf_lo16_reloc (bfd *abfd,
331 arelent *reloc_entry,
332 asymbol *symbol ATTRIBUTE_UNUSED,
333 void * data,
334 asection *input_section,
335 bfd *output_bfd ATTRIBUTE_UNUSED,
336 char **error_message ATTRIBUTE_UNUSED)
338 bfd_vma addend = 0, offset = 0;
339 unsigned long val;
340 unsigned long hi16_offset, hi16_value, uvalue;
342 hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
343 hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
344 addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
345 offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
346 val = reloc_entry->addend;
347 if (reloc_entry->address > input_section->size)
348 return bfd_reloc_outofrange;
349 uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
350 hi16_offset = (uvalue >> 16) << 1;
351 hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
352 score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
353 offset = (uvalue & 0xffff) << 1;
354 addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
355 score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
356 return bfd_reloc_ok;
359 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
360 dangerous relocation. */
362 static bfd_boolean
363 score_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
365 unsigned int count;
366 asymbol **sym;
367 unsigned int i;
369 /* If we've already figured out what GP will be, just return it. */
370 *pgp = _bfd_get_gp_value (output_bfd);
371 if (*pgp)
372 return TRUE;
374 count = bfd_get_symcount (output_bfd);
375 sym = bfd_get_outsymbols (output_bfd);
377 /* The linker script will have created a symbol named `_gp' with the
378 appropriate value. */
379 if (sym == NULL)
380 i = count;
381 else
383 for (i = 0; i < count; i++, sym++)
385 const char *name;
387 name = bfd_asymbol_name (*sym);
388 if (*name == '_' && strcmp (name, "_gp") == 0)
390 *pgp = bfd_asymbol_value (*sym);
391 _bfd_set_gp_value (output_bfd, *pgp);
392 break;
397 if (i >= count)
399 /* Only get the error once. */
400 *pgp = 4;
401 _bfd_set_gp_value (output_bfd, *pgp);
402 return FALSE;
405 return TRUE;
408 /* We have to figure out the gp value, so that we can adjust the
409 symbol value correctly. We look up the symbol _gp in the output
410 BFD. If we can't find it, we're stuck. We cache it in the ELF
411 target data. We don't need to adjust the symbol value for an
412 external symbol if we are producing relocatable output. */
413 static bfd_reloc_status_type
414 score_elf_final_gp (bfd *output_bfd,
415 asymbol *symbol,
416 bfd_boolean relocatable,
417 char **error_message,
418 bfd_vma *pgp)
420 if (bfd_is_und_section (symbol->section)
421 && ! relocatable)
423 *pgp = 0;
424 return bfd_reloc_undefined;
427 *pgp = _bfd_get_gp_value (output_bfd);
428 if (*pgp == 0
429 && (! relocatable
430 || (symbol->flags & BSF_SECTION_SYM) != 0))
432 if (relocatable)
434 /* Make up a value. */
435 *pgp = symbol->section->output_section->vma + 0x4000;
436 _bfd_set_gp_value (output_bfd, *pgp);
438 else if (!score_elf_assign_gp (output_bfd, pgp))
440 *error_message =
441 (char *) _("GP relative relocation when _gp not defined");
442 return bfd_reloc_dangerous;
446 return bfd_reloc_ok;
449 static bfd_reloc_status_type
450 score_elf_gprel15_with_gp (bfd *abfd,
451 asymbol *symbol,
452 arelent *reloc_entry,
453 asection *input_section,
454 bfd_boolean relocateable,
455 void * data,
456 bfd_vma gp ATTRIBUTE_UNUSED)
458 bfd_vma relocation;
459 unsigned long insn;
461 if (bfd_is_com_section (symbol->section))
462 relocation = 0;
463 else
464 relocation = symbol->value;
466 relocation += symbol->section->output_section->vma;
467 relocation += symbol->section->output_offset;
468 if (reloc_entry->address > input_section->size)
469 return bfd_reloc_outofrange;
471 insn = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
472 if (((reloc_entry->addend & 0xffffc000) != 0)
473 && ((reloc_entry->addend & 0xffffc000) != 0xffffc000))
474 return bfd_reloc_overflow;
476 insn = (insn & ~0x7fff) | (reloc_entry->addend & 0x7fff);
477 score_bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
478 if (relocateable)
479 reloc_entry->address += input_section->output_offset;
481 return bfd_reloc_ok;
484 static bfd_reloc_status_type
485 gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
486 asection *input_section, bfd_boolean relocatable,
487 void *data, bfd_vma gp)
489 bfd_vma relocation;
490 bfd_vma val;
492 if (bfd_is_com_section (symbol->section))
493 relocation = 0;
494 else
495 relocation = symbol->value;
497 relocation += symbol->section->output_section->vma;
498 relocation += symbol->section->output_offset;
500 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
501 return bfd_reloc_outofrange;
503 /* Set val to the offset into the section or symbol. */
504 val = reloc_entry->addend;
506 if (reloc_entry->howto->partial_inplace)
507 val += score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
509 /* Adjust val for the final section location and GP value. If we
510 are producing relocatable output, we don't want to do this for
511 an external symbol. */
512 if (! relocatable
513 || (symbol->flags & BSF_SECTION_SYM) != 0)
514 val += relocation - gp;
516 if (reloc_entry->howto->partial_inplace)
517 score_bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
518 else
519 reloc_entry->addend = val;
521 if (relocatable)
522 reloc_entry->address += input_section->output_offset;
524 return bfd_reloc_ok;
527 static bfd_reloc_status_type
528 score_elf_gprel15_reloc (bfd *abfd,
529 arelent *reloc_entry,
530 asymbol *symbol,
531 void * data,
532 asection *input_section,
533 bfd *output_bfd,
534 char **error_message)
536 bfd_boolean relocateable;
537 bfd_reloc_status_type ret;
538 bfd_vma gp;
540 if (output_bfd != NULL
541 && (symbol->flags & BSF_SECTION_SYM) == 0 && reloc_entry->addend == 0)
543 reloc_entry->address += input_section->output_offset;
544 return bfd_reloc_ok;
546 if (output_bfd != NULL)
547 relocateable = TRUE;
548 else
550 relocateable = FALSE;
551 output_bfd = symbol->section->output_section->owner;
554 ret = score_elf_final_gp (output_bfd, symbol, relocateable, error_message, &gp);
555 if (ret != bfd_reloc_ok)
556 return ret;
558 return score_elf_gprel15_with_gp (abfd, symbol, reloc_entry,
559 input_section, relocateable, data, gp);
562 /* Do a R_SCORE_GPREL32 relocation. This is a 32 bit value which must
563 become the offset from the gp register. */
565 static bfd_reloc_status_type
566 score_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
567 void *data, asection *input_section, bfd *output_bfd,
568 char **error_message)
570 bfd_boolean relocatable;
571 bfd_reloc_status_type ret;
572 bfd_vma gp;
574 /* R_SCORE_GPREL32 relocations are defined for local symbols only. */
575 if (output_bfd != NULL
576 && (symbol->flags & BSF_SECTION_SYM) == 0
577 && (symbol->flags & BSF_LOCAL) != 0)
579 *error_message = (char *)
580 _("32bits gp relative relocation occurs for an external symbol");
581 return bfd_reloc_outofrange;
584 if (output_bfd != NULL)
585 relocatable = TRUE;
586 else
588 relocatable = FALSE;
589 output_bfd = symbol->section->output_section->owner;
592 ret = score_elf_final_gp (output_bfd, symbol, relocatable, error_message, &gp);
593 if (ret != bfd_reloc_ok)
594 return ret;
596 gp = 0;
597 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
598 relocatable, data, gp);
601 /* A howto special_function for R_SCORE_GOT15 relocations. This is just
602 like any other 16-bit relocation when applied to global symbols, but is
603 treated in the same as R_SCORE_HI16 when applied to local symbols. */
604 static bfd_reloc_status_type
605 score_elf_got15_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
606 void *data, asection *input_section,
607 bfd *output_bfd, char **error_message)
609 if ((symbol->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
610 || bfd_is_und_section (bfd_get_section (symbol))
611 || bfd_is_com_section (bfd_get_section (symbol)))
612 /* The relocation is against a global symbol. */
613 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
614 input_section, output_bfd,
615 error_message);
617 return score_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
618 input_section, output_bfd, error_message);
621 static bfd_reloc_status_type
622 score_elf_got_lo16_reloc (bfd *abfd,
623 arelent *reloc_entry,
624 asymbol *symbol ATTRIBUTE_UNUSED,
625 void * data,
626 asection *input_section,
627 bfd *output_bfd ATTRIBUTE_UNUSED,
628 char **error_message ATTRIBUTE_UNUSED)
630 bfd_vma addend = 0, offset = 0;
631 signed long val;
632 signed long hi16_offset, hi16_value, uvalue;
634 hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
635 hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
636 addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
637 offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
638 val = reloc_entry->addend;
639 if (reloc_entry->address > input_section->size)
640 return bfd_reloc_outofrange;
641 uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
642 if ((uvalue > -0x8000) && (uvalue < 0x7fff))
643 hi16_offset = 0;
644 else
645 hi16_offset = (uvalue >> 16) & 0x7fff;
646 hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
647 score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
648 offset = (uvalue & 0xffff) << 1;
649 addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
650 score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
651 return bfd_reloc_ok;
654 static reloc_howto_type elf32_score_howto_table[] =
656 /* No relocation. */
657 HOWTO (R_SCORE_NONE, /* type */
658 0, /* rightshift */
659 0, /* size (0 = byte, 1 = short, 2 = long) */
660 0, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_dont,/* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_SCORE_NONE", /* name */
666 FALSE, /* partial_inplace */
667 0, /* src_mask */
668 0, /* dst_mask */
669 FALSE), /* pcrel_offset */
671 /* R_SCORE_HI16 */
672 HOWTO (R_SCORE_HI16, /* type */
673 0, /* rightshift */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
675 16, /* bitsize */
676 FALSE, /* pc_relative */
677 1, /* bitpos */
678 complain_overflow_dont,/* complain_on_overflow */
679 score_elf_hi16_reloc, /* special_function */
680 "R_SCORE_HI16", /* name */
681 TRUE, /* partial_inplace */
682 0x37fff, /* src_mask */
683 0x37fff, /* dst_mask */
684 FALSE), /* pcrel_offset */
686 /* R_SCORE_LO16 */
687 HOWTO (R_SCORE_LO16, /* type */
688 0, /* rightshift */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
690 16, /* bitsize */
691 FALSE, /* pc_relative */
692 1, /* bitpos */
693 complain_overflow_dont,/* complain_on_overflow */
694 score_elf_lo16_reloc, /* special_function */
695 "R_SCORE_LO16", /* name */
696 TRUE, /* partial_inplace */
697 0x37fff, /* src_mask */
698 0x37fff, /* dst_mask */
699 FALSE), /* pcrel_offset */
701 /* R_SCORE_BCMP */
702 HOWTO (R_SCORE_BCMP, /* type */
703 1, /* rightshift */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
705 16, /* bitsize */
706 TRUE, /* pc_relative */
707 1, /* bitpos */
708 complain_overflow_dont,/* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 "R_SCORE_BCMP", /* name */
711 FALSE, /* partial_inplace */
712 0x03e00381, /* src_mask */
713 0x03e00381, /* dst_mask */
714 FALSE), /* pcrel_offset */
716 /*R_SCORE_24 */
717 HOWTO (R_SCORE_24, /* type */
718 1, /* rightshift */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
720 24, /* bitsize */
721 FALSE, /* pc_relative */
722 1, /* bitpos */
723 complain_overflow_dont,/* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 "R_SCORE_24", /* name */
726 FALSE, /* partial_inplace */
727 0x3ff7fff, /* src_mask */
728 0x3ff7fff, /* dst_mask */
729 FALSE), /* pcrel_offset */
731 /*R_SCORE_PC19 */
732 HOWTO (R_SCORE_PC19, /* type */
733 1, /* rightshift */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
735 19, /* bitsize */
736 TRUE, /* pc_relative */
737 1, /* bitpos */
738 complain_overflow_dont,/* complain_on_overflow */
739 bfd_elf_generic_reloc, /* special_function */
740 "R_SCORE_PC19", /* name */
741 FALSE, /* partial_inplace */
742 0x3ff03fe, /* src_mask */
743 0x3ff03fe, /* dst_mask */
744 FALSE), /* pcrel_offset */
746 /*R_SCORE16_11 */
747 HOWTO (R_SCORE16_11, /* type */
748 1, /* rightshift */
749 1, /* size (0 = byte, 1 = short, 2 = long) */
750 11, /* bitsize */
751 FALSE, /* pc_relative */
752 1, /* bitpos */
753 complain_overflow_dont,/* complain_on_overflow */
754 bfd_elf_generic_reloc, /* special_function */
755 "R_SCORE16_11", /* name */
756 FALSE, /* partial_inplace */
757 0x000000ffe, /* src_mask */
758 0x000000ffe, /* dst_mask */
759 FALSE), /* pcrel_offset */
761 /* R_SCORE16_PC8 */
762 HOWTO (R_SCORE16_PC8, /* type */
763 1, /* rightshift */
764 1, /* size (0 = byte, 1 = short, 2 = long) */
765 9, /* bitsize */
766 TRUE, /* pc_relative */
767 0, /* bitpos */
768 complain_overflow_dont,/* complain_on_overflow */
769 bfd_elf_generic_reloc, /* special_function */
770 "R_SCORE16_PC8", /* name */
771 FALSE, /* partial_inplace */
772 0x000001ff, /* src_mask */
773 0x000001ff, /* dst_mask */
774 FALSE), /* pcrel_offset */
776 /* 32 bit absolute */
777 HOWTO (R_SCORE_ABS32, /* type 8 */
778 0, /* rightshift */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
780 32, /* bitsize */
781 FALSE, /* pc_relative */
782 0, /* bitpos */
783 complain_overflow_bitfield, /* complain_on_overflow */
784 bfd_elf_generic_reloc, /* special_function */
785 "R_SCORE_ABS32", /* name */
786 FALSE, /* partial_inplace */
787 0xffffffff, /* src_mask */
788 0xffffffff, /* dst_mask */
789 FALSE), /* pcrel_offset */
791 /* 16 bit absolute */
792 HOWTO (R_SCORE_ABS16, /* type 11 */
793 0, /* rightshift */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
795 16, /* bitsize */
796 FALSE, /* pc_relative */
797 0, /* bitpos */
798 complain_overflow_bitfield, /* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_SCORE_ABS16", /* name */
801 FALSE, /* partial_inplace */
802 0x0000ffff, /* src_mask */
803 0x0000ffff, /* dst_mask */
804 FALSE), /* pcrel_offset */
806 /* R_SCORE_DUMMY2 */
807 HOWTO (R_SCORE_DUMMY2, /* type */
808 0, /* rightshift */
809 2, /* size (0 = byte, 1 = short, 2 = long) */
810 16, /* bitsize */
811 FALSE, /* pc_relative */
812 0, /* bitpos */
813 complain_overflow_dont,/* complain_on_overflow */
814 bfd_elf_generic_reloc, /* special_function */
815 "R_SCORE_DUMMY2", /* name */
816 TRUE, /* partial_inplace */
817 0x00007fff, /* src_mask */
818 0x00007fff, /* dst_mask */
819 FALSE), /* pcrel_offset */
821 /* R_SCORE_GP15 */
822 HOWTO (R_SCORE_GP15, /* type */
823 0, /* rightshift */
824 2, /* size (0 = byte, 1 = short, 2 = long) */
825 16, /* bitsize */
826 FALSE, /* pc_relative */
827 0, /* bitpos */
828 complain_overflow_dont,/* complain_on_overflow */
829 score_elf_gprel15_reloc,/* special_function */
830 "R_SCORE_GP15", /* name */
831 TRUE, /* partial_inplace */
832 0x00007fff, /* src_mask */
833 0x00007fff, /* dst_mask */
834 FALSE), /* pcrel_offset */
836 /* GNU extension to record C++ vtable hierarchy. */
837 HOWTO (R_SCORE_GNU_VTINHERIT, /* type */
838 0, /* rightshift */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
840 0, /* bitsize */
841 FALSE, /* pc_relative */
842 0, /* bitpos */
843 complain_overflow_dont,/* complain_on_overflow */
844 NULL, /* special_function */
845 "R_SCORE_GNU_VTINHERIT", /* name */
846 FALSE, /* partial_inplace */
847 0, /* src_mask */
848 0, /* dst_mask */
849 FALSE), /* pcrel_offset */
851 /* GNU extension to record C++ vtable member usage */
852 HOWTO (R_SCORE_GNU_VTENTRY, /* type */
853 0, /* rightshift */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
855 0, /* bitsize */
856 FALSE, /* pc_relative */
857 0, /* bitpos */
858 complain_overflow_dont,/* complain_on_overflow */
859 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
860 "R_SCORE_GNU_VTENTRY", /* name */
861 FALSE, /* partial_inplace */
862 0, /* src_mask */
863 0, /* dst_mask */
864 FALSE), /* pcrel_offset */
866 /* Reference to global offset table. */
867 HOWTO (R_SCORE_GOT15, /* type */
868 0, /* rightshift */
869 2, /* size (0 = byte, 1 = short, 2 = long) */
870 16, /* bitsize */
871 FALSE, /* pc_relative */
872 0, /* bitpos */
873 complain_overflow_signed, /* complain_on_overflow */
874 score_elf_got15_reloc, /* special_function */
875 "R_SCORE_GOT15", /* name */
876 TRUE, /* partial_inplace */
877 0x00007fff, /* src_mask */
878 0x00007fff, /* dst_mask */
879 FALSE), /* pcrel_offset */
881 /* Low 16 bits of displacement in global offset table. */
882 HOWTO (R_SCORE_GOT_LO16, /* type */
883 0, /* rightshift */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
885 16, /* bitsize */
886 FALSE, /* pc_relative */
887 1, /* bitpos */
888 complain_overflow_dont,/* complain_on_overflow */
889 score_elf_got_lo16_reloc, /* special_function */
890 "R_SCORE_GOT_LO16", /* name */
891 TRUE, /* partial_inplace */
892 0x37ffe, /* src_mask */
893 0x37ffe, /* dst_mask */
894 FALSE), /* pcrel_offset */
896 /* 15 bit call through global offset table. */
897 HOWTO (R_SCORE_CALL15, /* type */
898 0, /* rightshift */
899 2, /* size (0 = byte, 1 = short, 2 = long) */
900 16, /* bitsize */
901 FALSE, /* pc_relative */
902 0, /* bitpos */
903 complain_overflow_signed, /* complain_on_overflow */
904 bfd_elf_generic_reloc, /* special_function */
905 "R_SCORE_CALL15", /* name */
906 TRUE, /* partial_inplace */
907 0x0000ffff, /* src_mask */
908 0x0000ffff, /* dst_mask */
909 FALSE), /* pcrel_offset */
911 /* 32 bit GP relative reference. */
912 HOWTO (R_SCORE_GPREL32, /* type */
913 0, /* rightshift */
914 2, /* size (0 = byte, 1 = short, 2 = long) */
915 32, /* bitsize */
916 FALSE, /* pc_relative */
917 0, /* bitpos */
918 complain_overflow_dont,/* complain_on_overflow */
919 score_elf_gprel32_reloc, /* special_function */
920 "R_SCORE_GPREL32", /* name */
921 TRUE, /* partial_inplace */
922 0xffffffff, /* src_mask */
923 0xffffffff, /* dst_mask */
924 FALSE), /* pcrel_offset */
926 /* 32 bit symbol relative relocation. */
927 HOWTO (R_SCORE_REL32, /* type */
928 0, /* rightshift */
929 2, /* size (0 = byte, 1 = short, 2 = long) */
930 32, /* bitsize */
931 FALSE, /* pc_relative */
932 0, /* bitpos */
933 complain_overflow_dont,/* complain_on_overflow */
934 bfd_elf_generic_reloc, /* special_function */
935 "R_SCORE_REL32", /* name */
936 TRUE, /* partial_inplace */
937 0xffffffff, /* src_mask */
938 0xffffffff, /* dst_mask */
939 FALSE), /* pcrel_offset */
941 /* R_SCORE_DUMMY_HI16 */
942 HOWTO (R_SCORE_DUMMY_HI16, /* type */
943 0, /* rightshift */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
945 16, /* bitsize */
946 FALSE, /* pc_relative */
947 1, /* bitpos */
948 complain_overflow_dont,/* complain_on_overflow */
949 score_elf_hi16_reloc, /* special_function */
950 "R_SCORE_DUMMY_HI16", /* name */
951 TRUE, /* partial_inplace */
952 0x37fff, /* src_mask */
953 0x37fff, /* dst_mask */
954 FALSE), /* pcrel_offset */
956 /* R_SCORE_IMM30 */
957 HOWTO (R_SCORE_IMM30, /* type */
958 2, /* rightshift */
959 2, /* size (0 = byte, 1 = short, 2 = long) */
960 30, /* bitsize */
961 FALSE, /* pc_relative */
962 7, /* bitpos */
963 complain_overflow_dont,/* complain_on_overflow */
964 bfd_elf_generic_reloc, /* special_function */
965 "R_SCORE_IMM30", /* name */
966 FALSE, /* partial_inplace */
967 0x7f7fff7f80LL, /* src_mask */
968 0x7f7fff7f80LL, /* dst_mask */
969 FALSE), /* pcrel_offset */
971 /* R_SCORE_IMM32 */
972 HOWTO (R_SCORE_IMM32, /* type */
973 0, /* rightshift */
974 2, /* size (0 = byte, 1 = short, 2 = long) */
975 32, /* bitsize */
976 FALSE, /* pc_relative */
977 5, /* bitpos */
978 complain_overflow_dont,/* complain_on_overflow */
979 bfd_elf_generic_reloc, /* special_function */
980 "R_SCORE_IMM32", /* name */
981 FALSE, /* partial_inplace */
982 0x7f7fff7fe0LL, /* src_mask */
983 0x7f7fff7fe0LL, /* dst_mask */
984 FALSE), /* pcrel_offset */
987 struct score_reloc_map
989 bfd_reloc_code_real_type bfd_reloc_val;
990 unsigned char elf_reloc_val;
993 static const struct score_reloc_map elf32_score_reloc_map[] =
995 {BFD_RELOC_NONE, R_SCORE_NONE},
996 {BFD_RELOC_HI16_S, R_SCORE_HI16},
997 {BFD_RELOC_LO16, R_SCORE_LO16},
998 {BFD_RELOC_SCORE_BCMP, R_SCORE_BCMP},
999 {BFD_RELOC_SCORE_JMP, R_SCORE_24},
1000 {BFD_RELOC_SCORE_BRANCH, R_SCORE_PC19},
1001 {BFD_RELOC_SCORE16_JMP, R_SCORE16_11},
1002 {BFD_RELOC_SCORE16_BRANCH, R_SCORE16_PC8},
1003 {BFD_RELOC_32, R_SCORE_ABS32},
1004 {BFD_RELOC_16, R_SCORE_ABS16},
1005 {BFD_RELOC_SCORE_DUMMY2, R_SCORE_DUMMY2},
1006 {BFD_RELOC_SCORE_GPREL15, R_SCORE_GP15},
1007 {BFD_RELOC_VTABLE_INHERIT, R_SCORE_GNU_VTINHERIT},
1008 {BFD_RELOC_VTABLE_ENTRY, R_SCORE_GNU_VTENTRY},
1009 {BFD_RELOC_SCORE_GOT15, R_SCORE_GOT15},
1010 {BFD_RELOC_SCORE_GOT_LO16, R_SCORE_GOT_LO16},
1011 {BFD_RELOC_SCORE_CALL15, R_SCORE_CALL15},
1012 {BFD_RELOC_GPREL32, R_SCORE_GPREL32},
1013 {BFD_RELOC_32_PCREL, R_SCORE_REL32},
1014 {BFD_RELOC_SCORE_DUMMY_HI16, R_SCORE_DUMMY_HI16},
1015 {BFD_RELOC_SCORE_IMM30, R_SCORE_IMM30},
1016 {BFD_RELOC_SCORE_IMM32, R_SCORE_IMM32},
1019 /* got_entries only match if they're identical, except for gotidx, so
1020 use all fields to compute the hash, and compare the appropriate
1021 union members. */
1022 static hashval_t
1023 score_elf_got_entry_hash (const void *entry_)
1025 const struct score_got_entry *entry = (struct score_got_entry *)entry_;
1027 return entry->symndx
1028 + (!entry->abfd ? entry->d.address : entry->abfd->id);
1031 static int
1032 score_elf_got_entry_eq (const void *entry1, const void *entry2)
1034 const struct score_got_entry *e1 = (struct score_got_entry *)entry1;
1035 const struct score_got_entry *e2 = (struct score_got_entry *)entry2;
1037 return e1->abfd == e2->abfd && e1->symndx == e2->symndx
1038 && (! e1->abfd ? e1->d.address == e2->d.address
1039 : e1->symndx >= 0 ? e1->d.addend == e2->d.addend
1040 : e1->d.h == e2->d.h);
1043 /* If H needs a GOT entry, assign it the highest available dynamic
1044 index. Otherwise, assign it the lowest available dynamic
1045 index. */
1046 static bfd_boolean
1047 score_elf_sort_hash_table_f (struct score_elf_link_hash_entry *h, void *data)
1049 struct score_elf_hash_sort_data *hsd = data;
1051 if (h->root.root.type == bfd_link_hash_warning)
1052 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1054 /* Symbols without dynamic symbol table entries aren't interesting at all. */
1055 if (h->root.dynindx == -1)
1056 return TRUE;
1058 /* Global symbols that need GOT entries that are not explicitly
1059 referenced are marked with got offset 2. Those that are
1060 referenced get a 1, and those that don't need GOT entries get
1061 -1. */
1062 if (h->root.got.offset == 2)
1064 if (hsd->max_unref_got_dynindx == hsd->min_got_dynindx)
1065 hsd->low = (struct elf_link_hash_entry *) h;
1066 h->root.dynindx = hsd->max_unref_got_dynindx++;
1068 else if (h->root.got.offset != 1)
1069 h->root.dynindx = hsd->max_non_got_dynindx++;
1070 else
1072 h->root.dynindx = --hsd->min_got_dynindx;
1073 hsd->low = (struct elf_link_hash_entry *) h;
1076 return TRUE;
1079 static asection *
1080 score_elf_got_section (bfd *abfd, bfd_boolean maybe_excluded)
1082 asection *sgot = bfd_get_section_by_name (abfd, ".got");
1084 if (sgot == NULL || (! maybe_excluded && (sgot->flags & SEC_EXCLUDE) != 0))
1085 return NULL;
1086 return sgot;
1089 /* Returns the GOT information associated with the link indicated by
1090 INFO. If SGOTP is non-NULL, it is filled in with the GOT section. */
1091 static struct score_got_info *
1092 score_elf_got_info (bfd *abfd, asection **sgotp)
1094 asection *sgot;
1095 struct score_got_info *g;
1097 sgot = score_elf_got_section (abfd, TRUE);
1098 BFD_ASSERT (sgot != NULL);
1099 BFD_ASSERT (elf_section_data (sgot) != NULL);
1100 g = score_elf_section_data (sgot)->u.got_info;
1101 BFD_ASSERT (g != NULL);
1103 if (sgotp)
1104 *sgotp = sgot;
1105 return g;
1108 /* Sort the dynamic symbol table so that symbols that need GOT entries
1109 appear towards the end. This reduces the amount of GOT space
1110 required. MAX_LOCAL is used to set the number of local symbols
1111 known to be in the dynamic symbol table. During
1112 s3_bfd_score_elf_size_dynamic_sections, this value is 1. Afterward, the
1113 section symbols are added and the count is higher. */
1114 static bfd_boolean
1115 score_elf_sort_hash_table (struct bfd_link_info *info,
1116 unsigned long max_local)
1118 struct score_elf_hash_sort_data hsd;
1119 struct score_got_info *g;
1120 bfd *dynobj;
1122 dynobj = elf_hash_table (info)->dynobj;
1124 g = score_elf_got_info (dynobj, NULL);
1126 hsd.low = NULL;
1127 hsd.max_unref_got_dynindx =
1128 hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount
1129 /* In the multi-got case, assigned_gotno of the master got_info
1130 indicate the number of entries that aren't referenced in the
1131 primary GOT, but that must have entries because there are
1132 dynamic relocations that reference it. Since they aren't
1133 referenced, we move them to the end of the GOT, so that they
1134 don't prevent other entries that are referenced from getting
1135 too large offsets. */
1136 - (g->next ? g->assigned_gotno : 0);
1137 hsd.max_non_got_dynindx = max_local;
1138 score_elf_link_hash_traverse (((struct score_elf_link_hash_table *)
1139 elf_hash_table (info)),
1140 score_elf_sort_hash_table_f,
1141 &hsd);
1143 /* There should have been enough room in the symbol table to
1144 accommodate both the GOT and non-GOT symbols. */
1145 BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
1146 BFD_ASSERT ((unsigned long)hsd.max_unref_got_dynindx
1147 <= elf_hash_table (info)->dynsymcount);
1149 /* Now we know which dynamic symbol has the lowest dynamic symbol
1150 table index in the GOT. */
1151 g->global_gotsym = hsd.low;
1153 return TRUE;
1156 /* Create an entry in an score ELF linker hash table. */
1157 static struct bfd_hash_entry *
1158 score_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
1159 struct bfd_hash_table *table,
1160 const char *string)
1162 struct score_elf_link_hash_entry *ret = (struct score_elf_link_hash_entry *)entry;
1164 /* Allocate the structure if it has not already been allocated by a subclass. */
1165 if (ret == NULL)
1166 ret = bfd_hash_allocate (table, sizeof (struct score_elf_link_hash_entry));
1167 if (ret == NULL)
1168 return (struct bfd_hash_entry *)ret;
1170 /* Call the allocation method of the superclass. */
1171 ret = ((struct score_elf_link_hash_entry *)
1172 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *)ret, table, string));
1174 if (ret != NULL)
1176 ret->possibly_dynamic_relocs = 0;
1177 ret->readonly_reloc = FALSE;
1178 ret->no_fn_stub = FALSE;
1179 ret->forced_local = FALSE;
1182 return (struct bfd_hash_entry *)ret;
1185 /* Returns the first relocation of type r_type found, beginning with
1186 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1187 static const Elf_Internal_Rela *
1188 score_elf_next_relocation (bfd *abfd ATTRIBUTE_UNUSED, unsigned int r_type,
1189 const Elf_Internal_Rela *relocation,
1190 const Elf_Internal_Rela *relend)
1192 while (relocation < relend)
1194 if (ELF32_R_TYPE (relocation->r_info) == r_type)
1195 return relocation;
1197 ++relocation;
1200 /* We didn't find it. */
1201 bfd_set_error (bfd_error_bad_value);
1202 return NULL;
1205 /* This function is called via qsort() to sort the dynamic relocation
1206 entries by increasing r_symndx value. */
1207 static int
1208 score_elf_sort_dynamic_relocs (const void *arg1, const void *arg2)
1210 Elf_Internal_Rela int_reloc1;
1211 Elf_Internal_Rela int_reloc2;
1213 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, arg1, &int_reloc1);
1214 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, arg2, &int_reloc2);
1216 return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
1219 /* Return whether a relocation is against a local symbol. */
1220 static bfd_boolean
1221 score_elf_local_relocation_p (bfd *input_bfd,
1222 const Elf_Internal_Rela *relocation,
1223 asection **local_sections,
1224 bfd_boolean check_forced)
1226 unsigned long r_symndx;
1227 Elf_Internal_Shdr *symtab_hdr;
1228 struct score_elf_link_hash_entry *h;
1229 size_t extsymoff;
1231 r_symndx = ELF32_R_SYM (relocation->r_info);
1232 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1233 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
1235 if (r_symndx < extsymoff)
1236 return TRUE;
1237 if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
1238 return TRUE;
1240 if (check_forced)
1242 /* Look up the hash table to check whether the symbol was forced local. */
1243 h = (struct score_elf_link_hash_entry *)
1244 elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
1245 /* Find the real hash-table entry for this symbol. */
1246 while (h->root.root.type == bfd_link_hash_indirect
1247 || h->root.root.type == bfd_link_hash_warning)
1248 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1249 if (h->root.forced_local)
1250 return TRUE;
1253 return FALSE;
1256 /* Returns the dynamic relocation section for DYNOBJ. */
1257 static asection *
1258 score_elf_rel_dyn_section (bfd *dynobj, bfd_boolean create_p)
1260 static const char dname[] = ".rel.dyn";
1261 asection *sreloc;
1263 sreloc = bfd_get_section_by_name (dynobj, dname);
1264 if (sreloc == NULL && create_p)
1266 sreloc = bfd_make_section_with_flags (dynobj, dname,
1267 (SEC_ALLOC
1268 | SEC_LOAD
1269 | SEC_HAS_CONTENTS
1270 | SEC_IN_MEMORY
1271 | SEC_LINKER_CREATED
1272 | SEC_READONLY));
1273 if (sreloc == NULL
1274 || ! bfd_set_section_alignment (dynobj, sreloc,
1275 SCORE_ELF_LOG_FILE_ALIGN (dynobj)))
1276 return NULL;
1278 return sreloc;
1281 static void
1282 score_elf_allocate_dynamic_relocations (bfd *abfd, unsigned int n)
1284 asection *s;
1286 s = score_elf_rel_dyn_section (abfd, FALSE);
1287 BFD_ASSERT (s != NULL);
1289 if (s->size == 0)
1291 /* Make room for a null element. */
1292 s->size += SCORE_ELF_REL_SIZE (abfd);
1293 ++s->reloc_count;
1295 s->size += n * SCORE_ELF_REL_SIZE (abfd);
1298 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
1299 is the original relocation, which is now being transformed into a
1300 dynamic relocation. The ADDENDP is adjusted if necessary; the
1301 caller should store the result in place of the original addend. */
1302 static bfd_boolean
1303 score_elf_create_dynamic_relocation (bfd *output_bfd,
1304 struct bfd_link_info *info,
1305 const Elf_Internal_Rela *rel,
1306 struct score_elf_link_hash_entry *h,
1307 bfd_vma symbol,
1308 bfd_vma *addendp, asection *input_section)
1310 Elf_Internal_Rela outrel[3];
1311 asection *sreloc;
1312 bfd *dynobj;
1313 int r_type;
1314 long indx;
1315 bfd_boolean defined_p;
1317 r_type = ELF32_R_TYPE (rel->r_info);
1318 dynobj = elf_hash_table (info)->dynobj;
1319 sreloc = score_elf_rel_dyn_section (dynobj, FALSE);
1320 BFD_ASSERT (sreloc != NULL);
1321 BFD_ASSERT (sreloc->contents != NULL);
1322 BFD_ASSERT (sreloc->reloc_count * SCORE_ELF_REL_SIZE (output_bfd) < sreloc->size);
1324 outrel[0].r_offset =
1325 _bfd_elf_section_offset (output_bfd, info, input_section, rel[0].r_offset);
1326 outrel[1].r_offset =
1327 _bfd_elf_section_offset (output_bfd, info, input_section, rel[1].r_offset);
1328 outrel[2].r_offset =
1329 _bfd_elf_section_offset (output_bfd, info, input_section, rel[2].r_offset);
1331 if (outrel[0].r_offset == MINUS_ONE)
1332 /* The relocation field has been deleted. */
1333 return TRUE;
1335 if (outrel[0].r_offset == MINUS_TWO)
1337 /* The relocation field has been converted into a relative value of
1338 some sort. Functions like _bfd_elf_write_section_eh_frame expect
1339 the field to be fully relocated, so add in the symbol's value. */
1340 *addendp += symbol;
1341 return TRUE;
1344 /* We must now calculate the dynamic symbol table index to use
1345 in the relocation. */
1346 if (h != NULL
1347 && (! info->symbolic || !h->root.def_regular)
1348 /* h->root.dynindx may be -1 if this symbol was marked to
1349 become local. */
1350 && h->root.dynindx != -1)
1352 indx = h->root.dynindx;
1353 /* ??? glibc's ld.so just adds the final GOT entry to the
1354 relocation field. It therefore treats relocs against
1355 defined symbols in the same way as relocs against
1356 undefined symbols. */
1357 defined_p = FALSE;
1359 else
1361 indx = 0;
1362 defined_p = TRUE;
1365 /* If the relocation was previously an absolute relocation and
1366 this symbol will not be referred to by the relocation, we must
1367 adjust it by the value we give it in the dynamic symbol table.
1368 Otherwise leave the job up to the dynamic linker. */
1369 if (defined_p && r_type != R_SCORE_REL32)
1370 *addendp += symbol;
1372 /* The relocation is always an REL32 relocation because we don't
1373 know where the shared library will wind up at load-time. */
1374 outrel[0].r_info = ELF32_R_INFO ((unsigned long) indx, R_SCORE_REL32);
1376 /* For strict adherence to the ABI specification, we should
1377 generate a R_SCORE_64 relocation record by itself before the
1378 _REL32/_64 record as well, such that the addend is read in as
1379 a 64-bit value (REL32 is a 32-bit relocation, after all).
1380 However, since none of the existing ELF64 SCORE dynamic
1381 loaders seems to care, we don't waste space with these
1382 artificial relocations. If this turns out to not be true,
1383 score_elf_allocate_dynamic_relocations() should be tweaked so
1384 as to make room for a pair of dynamic relocations per
1385 invocation if ABI_64_P, and here we should generate an
1386 additional relocation record with R_SCORE_64 by itself for a
1387 NULL symbol before this relocation record. */
1388 outrel[1].r_info = ELF32_R_INFO (0, R_SCORE_NONE);
1389 outrel[2].r_info = ELF32_R_INFO (0, R_SCORE_NONE);
1391 /* Adjust the output offset of the relocation to reference the
1392 correct location in the output file. */
1393 outrel[0].r_offset += (input_section->output_section->vma
1394 + input_section->output_offset);
1395 outrel[1].r_offset += (input_section->output_section->vma
1396 + input_section->output_offset);
1397 outrel[2].r_offset += (input_section->output_section->vma
1398 + input_section->output_offset);
1400 /* Put the relocation back out. We have to use the special
1401 relocation outputter in the 64-bit case since the 64-bit
1402 relocation format is non-standard. */
1403 bfd_elf32_swap_reloc_out
1404 (output_bfd, &outrel[0],
1405 (sreloc->contents + sreloc->reloc_count * sizeof (Elf32_External_Rel)));
1407 /* We've now added another relocation. */
1408 ++sreloc->reloc_count;
1410 /* Make sure the output section is writable. The dynamic linker
1411 will be writing to it. */
1412 elf_section_data (input_section->output_section)->this_hdr.sh_flags |= SHF_WRITE;
1414 return TRUE;
1417 static bfd_boolean
1418 score_elf_create_got_section (bfd *abfd,
1419 struct bfd_link_info *info,
1420 bfd_boolean maybe_exclude)
1422 flagword flags;
1423 asection *s;
1424 struct elf_link_hash_entry *h;
1425 struct bfd_link_hash_entry *bh;
1426 struct score_got_info *g;
1427 bfd_size_type amt;
1429 /* This function may be called more than once. */
1430 s = score_elf_got_section (abfd, TRUE);
1431 if (s)
1433 if (! maybe_exclude)
1434 s->flags &= ~SEC_EXCLUDE;
1435 return TRUE;
1438 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1440 if (maybe_exclude)
1441 flags |= SEC_EXCLUDE;
1443 /* We have to use an alignment of 2**4 here because this is hardcoded
1444 in the function stub generation and in the linker script. */
1445 s = bfd_make_section_with_flags (abfd, ".got", flags);
1446 if (s == NULL
1447 || ! bfd_set_section_alignment (abfd, s, 4))
1448 return FALSE;
1450 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1451 linker script because we don't want to define the symbol if we
1452 are not creating a global offset table. */
1453 bh = NULL;
1454 if (! (_bfd_generic_link_add_one_symbol
1455 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
1456 0, NULL, FALSE, get_elf_backend_data (abfd)->collect, &bh)))
1457 return FALSE;
1459 h = (struct elf_link_hash_entry *) bh;
1460 h->non_elf = 0;
1461 h->def_regular = 1;
1462 h->type = STT_OBJECT;
1464 if (info->shared && ! bfd_elf_link_record_dynamic_symbol (info, h))
1465 return FALSE;
1467 amt = sizeof (struct score_got_info);
1468 g = bfd_alloc (abfd, amt);
1469 if (g == NULL)
1470 return FALSE;
1472 g->global_gotsym = NULL;
1473 g->global_gotno = 0;
1475 g->local_gotno = SCORE_RESERVED_GOTNO;
1476 g->assigned_gotno = SCORE_RESERVED_GOTNO;
1477 g->next = NULL;
1479 g->got_entries = htab_try_create (1, score_elf_got_entry_hash,
1480 score_elf_got_entry_eq, NULL);
1481 if (g->got_entries == NULL)
1482 return FALSE;
1483 score_elf_section_data (s)->u.got_info = g;
1484 score_elf_section_data (s)->elf.this_hdr.sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
1486 return TRUE;
1489 /* Calculate the %high function. */
1490 static bfd_vma
1491 score_elf_high (bfd_vma value)
1493 return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff;
1496 /* Create a local GOT entry for VALUE. Return the index of the entry,
1497 or -1 if it could not be created. */
1498 static struct score_got_entry *
1499 score_elf_create_local_got_entry (bfd *abfd,
1500 bfd *ibfd ATTRIBUTE_UNUSED,
1501 struct score_got_info *gg,
1502 asection *sgot, bfd_vma value,
1503 unsigned long r_symndx ATTRIBUTE_UNUSED,
1504 struct score_elf_link_hash_entry *h ATTRIBUTE_UNUSED,
1505 int r_type ATTRIBUTE_UNUSED)
1507 struct score_got_entry entry, **loc;
1508 struct score_got_info *g;
1510 entry.abfd = NULL;
1511 entry.symndx = -1;
1512 entry.d.address = value;
1514 g = gg;
1515 loc = (struct score_got_entry **) htab_find_slot (g->got_entries, &entry, INSERT);
1516 if (*loc)
1517 return *loc;
1519 entry.gotidx = SCORE_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
1521 *loc = bfd_alloc (abfd, sizeof entry);
1523 if (! *loc)
1524 return NULL;
1526 memcpy (*loc, &entry, sizeof entry);
1528 if (g->assigned_gotno >= g->local_gotno)
1530 (*loc)->gotidx = -1;
1531 /* We didn't allocate enough space in the GOT. */
1532 (*_bfd_error_handler)
1533 (_("not enough GOT space for local GOT entries"));
1534 bfd_set_error (bfd_error_bad_value);
1535 return NULL;
1538 score_bfd_put_32 (abfd, value, (sgot->contents + entry.gotidx));
1540 return *loc;
1543 /* Find a GOT entry whose higher-order 16 bits are the same as those
1544 for value. Return the index into the GOT for this entry. */
1545 static bfd_vma
1546 score_elf_got16_entry (bfd *abfd, bfd *ibfd, struct bfd_link_info *info,
1547 bfd_vma value, bfd_boolean external)
1549 asection *sgot;
1550 struct score_got_info *g;
1551 struct score_got_entry *entry;
1553 if (!external)
1555 /* Although the ABI says that it is "the high-order 16 bits" that we
1556 want, it is really the %high value. The complete value is
1557 calculated with a `addiu' of a LO16 relocation, just as with a
1558 HI16/LO16 pair. */
1559 value = score_elf_high (value) << 16;
1562 g = score_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
1564 entry = score_elf_create_local_got_entry (abfd, ibfd, g, sgot, value, 0, NULL,
1565 R_SCORE_GOT15);
1566 if (entry)
1567 return entry->gotidx;
1568 else
1569 return MINUS_ONE;
1572 static void
1573 s3_bfd_score_elf_hide_symbol (struct bfd_link_info *info,
1574 struct elf_link_hash_entry *entry,
1575 bfd_boolean force_local)
1577 bfd *dynobj;
1578 asection *got;
1579 struct score_got_info *g;
1580 struct score_elf_link_hash_entry *h;
1582 h = (struct score_elf_link_hash_entry *) entry;
1583 if (h->forced_local)
1584 return;
1585 h->forced_local = TRUE;
1587 dynobj = elf_hash_table (info)->dynobj;
1588 if (dynobj != NULL && force_local)
1590 got = score_elf_got_section (dynobj, FALSE);
1591 if (got == NULL)
1592 return;
1593 g = score_elf_section_data (got)->u.got_info;
1595 if (g->next)
1597 struct score_got_entry e;
1598 struct score_got_info *gg = g;
1600 /* Since we're turning what used to be a global symbol into a
1601 local one, bump up the number of local entries of each GOT
1602 that had an entry for it. This will automatically decrease
1603 the number of global entries, since global_gotno is actually
1604 the upper limit of global entries. */
1605 e.abfd = dynobj;
1606 e.symndx = -1;
1607 e.d.h = h;
1609 for (g = g->next; g != gg; g = g->next)
1610 if (htab_find (g->got_entries, &e))
1612 BFD_ASSERT (g->global_gotno > 0);
1613 g->local_gotno++;
1614 g->global_gotno--;
1617 /* If this was a global symbol forced into the primary GOT, we
1618 no longer need an entry for it. We can't release the entry
1619 at this point, but we must at least stop counting it as one
1620 of the symbols that required a forced got entry. */
1621 if (h->root.got.offset == 2)
1623 BFD_ASSERT (gg->assigned_gotno > 0);
1624 gg->assigned_gotno--;
1627 else if (g->global_gotno == 0 && g->global_gotsym == NULL)
1628 /* If we haven't got through GOT allocation yet, just bump up the
1629 number of local entries, as this symbol won't be counted as
1630 global. */
1631 g->local_gotno++;
1632 else if (h->root.got.offset == 1)
1634 /* If we're past non-multi-GOT allocation and this symbol had
1635 been marked for a global got entry, give it a local entry
1636 instead. */
1637 BFD_ASSERT (g->global_gotno > 0);
1638 g->local_gotno++;
1639 g->global_gotno--;
1643 _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
1646 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1647 symbol table index lower than any we've seen to date, record it for
1648 posterity. */
1649 static bfd_boolean
1650 score_elf_record_global_got_symbol (struct elf_link_hash_entry *h,
1651 bfd *abfd,
1652 struct bfd_link_info *info,
1653 struct score_got_info *g)
1655 struct score_got_entry entry, **loc;
1657 /* A global symbol in the GOT must also be in the dynamic symbol table. */
1658 if (h->dynindx == -1)
1660 switch (ELF_ST_VISIBILITY (h->other))
1662 case STV_INTERNAL:
1663 case STV_HIDDEN:
1664 s3_bfd_score_elf_hide_symbol (info, h, TRUE);
1665 break;
1667 if (!bfd_elf_link_record_dynamic_symbol (info, h))
1668 return FALSE;
1671 entry.abfd = abfd;
1672 entry.symndx = -1;
1673 entry.d.h = (struct score_elf_link_hash_entry *)h;
1675 loc = (struct score_got_entry **)htab_find_slot (g->got_entries, &entry, INSERT);
1677 /* If we've already marked this entry as needing GOT space, we don't
1678 need to do it again. */
1679 if (*loc)
1680 return TRUE;
1682 *loc = bfd_alloc (abfd, sizeof entry);
1683 if (! *loc)
1684 return FALSE;
1686 entry.gotidx = -1;
1688 memcpy (*loc, &entry, sizeof (entry));
1690 if (h->got.offset != MINUS_ONE)
1691 return TRUE;
1693 /* By setting this to a value other than -1, we are indicating that
1694 there needs to be a GOT entry for H. Avoid using zero, as the
1695 generic ELF copy_indirect_symbol tests for <= 0. */
1696 h->got.offset = 1;
1698 return TRUE;
1701 /* Reserve space in G for a GOT entry containing the value of symbol
1702 SYMNDX in input bfd ABDF, plus ADDEND. */
1703 static bfd_boolean
1704 score_elf_record_local_got_symbol (bfd *abfd,
1705 long symndx,
1706 bfd_vma addend,
1707 struct score_got_info *g)
1709 struct score_got_entry entry, **loc;
1711 entry.abfd = abfd;
1712 entry.symndx = symndx;
1713 entry.d.addend = addend;
1714 loc = (struct score_got_entry **)htab_find_slot (g->got_entries, &entry, INSERT);
1716 if (*loc)
1717 return TRUE;
1719 entry.gotidx = g->local_gotno++;
1721 *loc = bfd_alloc (abfd, sizeof(entry));
1722 if (! *loc)
1723 return FALSE;
1725 memcpy (*loc, &entry, sizeof (entry));
1727 return TRUE;
1730 /* Returns the GOT offset at which the indicated address can be found.
1731 If there is not yet a GOT entry for this value, create one.
1732 Returns -1 if no satisfactory GOT offset can be found. */
1733 static bfd_vma
1734 score_elf_local_got_index (bfd *abfd, bfd *ibfd, struct bfd_link_info *info,
1735 bfd_vma value, unsigned long r_symndx,
1736 struct score_elf_link_hash_entry *h, int r_type)
1738 asection *sgot;
1739 struct score_got_info *g;
1740 struct score_got_entry *entry;
1742 g = score_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
1744 entry = score_elf_create_local_got_entry (abfd, ibfd, g, sgot, value,
1745 r_symndx, h, r_type);
1746 if (!entry)
1747 return MINUS_ONE;
1749 else
1750 return entry->gotidx;
1753 /* Returns the GOT index for the global symbol indicated by H. */
1755 static bfd_vma
1756 score_elf_global_got_index (bfd *abfd, struct elf_link_hash_entry *h)
1758 bfd_vma index;
1759 asection *sgot;
1760 struct score_got_info *g;
1761 long global_got_dynindx = 0;
1763 g = score_elf_got_info (abfd, &sgot);
1764 if (g->global_gotsym != NULL)
1765 global_got_dynindx = g->global_gotsym->dynindx;
1767 /* Once we determine the global GOT entry with the lowest dynamic
1768 symbol table index, we must put all dynamic symbols with greater
1769 indices into the GOT. That makes it easy to calculate the GOT
1770 offset. */
1771 BFD_ASSERT (h->dynindx >= global_got_dynindx);
1772 index = ((h->dynindx - global_got_dynindx + g->local_gotno) * SCORE_ELF_GOT_SIZE (abfd));
1773 BFD_ASSERT (index < sgot->size);
1775 return index;
1778 /* Returns the offset for the entry at the INDEXth position in the GOT. */
1779 static bfd_vma
1780 score_elf_got_offset_from_index (bfd *dynobj, bfd *output_bfd,
1781 bfd *input_bfd ATTRIBUTE_UNUSED, bfd_vma index)
1783 asection *sgot;
1784 bfd_vma gp;
1785 struct score_got_info *g;
1787 g = score_elf_got_info (dynobj, &sgot);
1788 gp = _bfd_get_gp_value (output_bfd);
1790 return sgot->output_section->vma + sgot->output_offset + index - gp;
1793 /* Follow indirect and warning hash entries so that each got entry
1794 points to the final symbol definition. P must point to a pointer
1795 to the hash table we're traversing. Since this traversal may
1796 modify the hash table, we set this pointer to NULL to indicate
1797 we've made a potentially-destructive change to the hash table, so
1798 the traversal must be restarted. */
1799 static int
1800 score_elf_resolve_final_got_entry (void **entryp, void *p)
1802 struct score_got_entry *entry = (struct score_got_entry *)*entryp;
1803 htab_t got_entries = *(htab_t *)p;
1805 if (entry->abfd != NULL && entry->symndx == -1)
1807 struct score_elf_link_hash_entry *h = entry->d.h;
1809 while (h->root.root.type == bfd_link_hash_indirect
1810 || h->root.root.type == bfd_link_hash_warning)
1811 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1813 if (entry->d.h == h)
1814 return 1;
1816 entry->d.h = h;
1818 /* If we can't find this entry with the new bfd hash, re-insert
1819 it, and get the traversal restarted. */
1820 if (! htab_find (got_entries, entry))
1822 htab_clear_slot (got_entries, entryp);
1823 entryp = htab_find_slot (got_entries, entry, INSERT);
1824 if (! *entryp)
1825 *entryp = entry;
1826 /* Abort the traversal, since the whole table may have
1827 moved, and leave it up to the parent to restart the
1828 process. */
1829 *(htab_t *)p = NULL;
1830 return 0;
1832 /* We might want to decrement the global_gotno count, but it's
1833 either too early or too late for that at this point. */
1836 return 1;
1839 /* Turn indirect got entries in a got_entries table into their final locations. */
1840 static void
1841 score_elf_resolve_final_got_entries (struct score_got_info *g)
1843 htab_t got_entries;
1847 got_entries = g->got_entries;
1849 htab_traverse (got_entries,
1850 score_elf_resolve_final_got_entry,
1851 &got_entries);
1853 while (got_entries == NULL);
1856 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. for -r */
1857 static void
1858 score_elf_add_to_rel (bfd *abfd,
1859 bfd_byte *address,
1860 reloc_howto_type *howto,
1861 bfd_signed_vma increment)
1863 bfd_signed_vma addend;
1864 bfd_vma contents;
1865 unsigned long offset;
1866 unsigned long r_type = howto->type;
1867 unsigned long hi16_addend, hi16_offset, hi16_value, uvalue;
1869 contents = score_bfd_get_32 (abfd, address);
1870 /* Get the (signed) value from the instruction. */
1871 addend = contents & howto->src_mask;
1872 if (addend & ((howto->src_mask + 1) >> 1))
1874 bfd_signed_vma mask;
1876 mask = -1;
1877 mask &= ~howto->src_mask;
1878 addend |= mask;
1880 /* Add in the increment, (which is a byte value). */
1881 switch (r_type)
1883 case R_SCORE_PC19:
1884 offset =
1885 (((contents & howto->src_mask) & 0x3ff0000) >> 6) | ((contents & howto->src_mask) & 0x3ff);
1886 offset += increment;
1887 contents =
1888 (contents & ~howto->
1889 src_mask) | (((offset << 6) & howto->src_mask) & 0x3ff0000) | (offset & 0x3ff);
1890 score_bfd_put_32 (abfd, contents, address);
1891 break;
1892 case R_SCORE_HI16:
1893 break;
1894 case R_SCORE_LO16:
1895 hi16_addend = score_bfd_get_32 (abfd, address - 4);
1896 hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
1897 offset = ((((contents >> 16) & 0x3) << 15) | (contents & 0x7fff)) >> 1;
1898 offset = (hi16_offset << 16) | (offset & 0xffff);
1899 uvalue = increment + offset;
1900 hi16_offset = (uvalue >> 16) << 1;
1901 hi16_value = (hi16_addend & (~(howto->dst_mask)))
1902 | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
1903 score_bfd_put_32 (abfd, hi16_value, address - 4);
1904 offset = (uvalue & 0xffff) << 1;
1905 contents = (contents & (~(howto->dst_mask))) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
1906 score_bfd_put_32 (abfd, contents, address);
1907 break;
1908 case R_SCORE_24:
1909 offset =
1910 (((contents & howto->src_mask) >> 1) & 0x1ff8000) | ((contents & howto->src_mask) & 0x7fff);
1911 offset += increment;
1912 contents =
1913 (contents & ~howto->
1914 src_mask) | (((offset << 1) & howto->src_mask) & 0x3ff0000) | (offset & 0x7fff);
1915 score_bfd_put_32 (abfd, contents, address);
1916 break;
1918 case R_SCORE16_11:
1920 contents = score_bfd_get_16 (abfd, address);
1921 offset = contents & howto->src_mask;
1922 offset += increment;
1923 contents = (contents & ~howto->src_mask) | (offset & howto->src_mask);
1924 score_bfd_put_16 (abfd, contents, address);
1926 break;
1927 case R_SCORE16_PC8:
1929 contents = score_bfd_get_16 (abfd, address);
1930 offset = (contents & howto->src_mask) + ((increment >> 1) & 0x1ff);
1931 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1932 score_bfd_put_16 (abfd, contents, address);
1934 break;
1936 case R_SCORE_BCMP:
1937 contents = score_bfd_get_32 (abfd, address);
1938 offset = (contents & howto->src_mask);
1939 offset <<= howto->rightshift;
1940 offset += increment;
1941 offset >>= howto->rightshift;
1942 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1943 score_bfd_put_32 (abfd, contents, address);
1944 break;
1946 case R_SCORE_IMM30:
1947 contents = score_bfd_get_48 (abfd, address);
1948 offset = (contents & howto->src_mask);
1949 offset <<= howto->rightshift;
1950 offset += increment;
1951 offset >>= howto->rightshift;
1952 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1953 score_bfd_put_48 (abfd, contents, address);
1954 break;
1956 case R_SCORE_IMM32:
1957 contents = score_bfd_get_48 (abfd, address);
1958 offset = (contents & howto->src_mask);
1959 offset += increment;
1960 contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1961 score_bfd_put_48 (abfd, contents, address);
1962 break;
1964 default:
1965 addend += increment;
1966 contents = (contents & ~howto->dst_mask) | (addend & howto->dst_mask);
1967 score_bfd_put_32 (abfd, contents, address);
1968 break;
1972 /* Perform a relocation as part of a final link. */
1973 static bfd_reloc_status_type
1974 score_elf_final_link_relocate (reloc_howto_type *howto,
1975 bfd *input_bfd,
1976 bfd *output_bfd,
1977 asection *input_section,
1978 bfd_byte *contents,
1979 Elf_Internal_Rela *rel,
1980 Elf_Internal_Rela *relocs,
1981 bfd_vma symbol,
1982 struct bfd_link_info *info,
1983 const char *sym_name ATTRIBUTE_UNUSED,
1984 int sym_flags ATTRIBUTE_UNUSED,
1985 struct score_elf_link_hash_entry *h,
1986 asection **local_sections,
1987 bfd_boolean gp_disp_p)
1989 unsigned long r_type;
1990 unsigned long r_symndx;
1991 bfd_byte *hit_data = contents + rel->r_offset;
1992 bfd_vma addend;
1993 /* The final GP value to be used for the relocatable, executable, or
1994 shared object file being produced. */
1995 bfd_vma gp = MINUS_ONE;
1996 /* The place (section offset or address) of the storage unit being relocated. */
1997 bfd_vma rel_addr;
1998 /* The value of GP used to create the relocatable object. */
1999 bfd_vma gp0 = MINUS_ONE;
2000 /* The offset into the global offset table at which the address of the relocation entry
2001 symbol, adjusted by the addend, resides during execution. */
2002 bfd_vma g = MINUS_ONE;
2003 /* TRUE if the symbol referred to by this relocation is a local symbol. */
2004 bfd_boolean local_p;
2005 /* The eventual value we will relocate. */
2006 bfd_vma value = symbol;
2007 unsigned long hi16_addend, hi16_offset, hi16_value, uvalue, offset, abs_value = 0;
2010 if (elf_gp (output_bfd) == 0)
2012 struct bfd_link_hash_entry *bh;
2013 asection *o;
2015 bh = bfd_link_hash_lookup (info->hash, "_gp", 0, 0, 1);
2016 if (bh != NULL && bh->type == bfd_link_hash_defined)
2017 elf_gp (output_bfd) = (bh->u.def.value
2018 + bh->u.def.section->output_section->vma
2019 + bh->u.def.section->output_offset);
2020 else if (info->relocatable)
2022 bfd_vma lo = -1;
2024 /* Find the GP-relative section with the lowest offset. */
2025 for (o = output_bfd->sections; o != NULL; o = o->next)
2026 if (o->vma < lo)
2027 lo = o->vma;
2028 /* And calculate GP relative to that. */
2029 elf_gp (output_bfd) = lo + ELF_SCORE_GP_OFFSET (input_bfd);
2031 else
2033 /* If the relocate_section function needs to do a reloc
2034 involving the GP value, it should make a reloc_dangerous
2035 callback to warn that GP is not defined. */
2039 /* Parse the relocation. */
2040 r_symndx = ELF32_R_SYM (rel->r_info);
2041 r_type = ELF32_R_TYPE (rel->r_info);
2042 rel_addr = (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
2043 local_p = score_elf_local_relocation_p (input_bfd, rel, local_sections, TRUE);
2045 if (r_type == R_SCORE_GOT15)
2047 const Elf_Internal_Rela *relend;
2048 const Elf_Internal_Rela *lo16_rel;
2049 const struct elf_backend_data *bed;
2050 bfd_vma lo_value = 0;
2052 bed = get_elf_backend_data (output_bfd);
2053 relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel;
2054 lo16_rel = score_elf_next_relocation (input_bfd, R_SCORE_GOT_LO16, rel, relend);
2055 if ((local_p) && (lo16_rel != NULL))
2057 bfd_vma tmp = 0;
2058 tmp = score_bfd_get_32 (input_bfd, contents + lo16_rel->r_offset);
2059 lo_value = (((tmp >> 16) & 0x3) << 14) | ((tmp & 0x7fff) >> 1);
2061 addend = lo_value;
2063 /* For score3 R_SCORE_ABS32. */
2064 else if (r_type == R_SCORE_ABS32 || r_type == R_SCORE_REL32)
2066 addend = (bfd_get_32 (input_bfd, hit_data) >> howto->bitpos) & howto->src_mask;
2068 else
2070 addend = (score_bfd_get_32 (input_bfd, hit_data) >> howto->bitpos) & howto->src_mask;
2073 /* If we haven't already determined the GOT offset, or the GP value,
2074 and we're going to need it, get it now. */
2075 switch (r_type)
2077 case R_SCORE_CALL15:
2078 case R_SCORE_GOT15:
2079 if (!local_p)
2081 g = score_elf_global_got_index (elf_hash_table (info)->dynobj,
2082 (struct elf_link_hash_entry *) h);
2083 if ((! elf_hash_table(info)->dynamic_sections_created
2084 || (info->shared
2085 && (info->symbolic || h->root.dynindx == -1)
2086 && h->root.def_regular)))
2088 /* This is a static link or a -Bsymbolic link. The
2089 symbol is defined locally, or was forced to be local.
2090 We must initialize this entry in the GOT. */
2091 bfd *tmpbfd = elf_hash_table (info)->dynobj;
2092 asection *sgot = score_elf_got_section (tmpbfd, FALSE);
2093 score_bfd_put_32 (tmpbfd, value, sgot->contents + g);
2096 else if (r_type == R_SCORE_GOT15 || r_type == R_SCORE_CALL15)
2098 /* There's no need to create a local GOT entry here; the
2099 calculation for a local GOT15 entry does not involve G. */
2102 else
2104 g = score_elf_local_got_index (output_bfd, input_bfd, info,
2105 symbol + addend, r_symndx, h, r_type);
2106 if (g == MINUS_ONE)
2107 return bfd_reloc_outofrange;
2110 /* Convert GOT indices to actual offsets. */
2111 g = score_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
2112 output_bfd, input_bfd, g);
2113 break;
2115 case R_SCORE_HI16:
2116 case R_SCORE_LO16:
2117 case R_SCORE_GPREL32:
2118 gp0 = _bfd_get_gp_value (input_bfd);
2119 gp = _bfd_get_gp_value (output_bfd);
2120 break;
2122 case R_SCORE_GP15:
2123 gp = _bfd_get_gp_value (output_bfd);
2125 default:
2126 break;
2129 switch (r_type)
2131 case R_SCORE_NONE:
2132 return bfd_reloc_ok;
2134 case R_SCORE_ABS32:
2135 case R_SCORE_REL32:
2136 if ((info->shared
2137 || (elf_hash_table (info)->dynamic_sections_created
2138 && h != NULL
2139 && h->root.def_dynamic
2140 && !h->root.def_regular))
2141 && r_symndx != 0
2142 && (input_section->flags & SEC_ALLOC) != 0)
2144 /* If we're creating a shared library, or this relocation is against a symbol
2145 in a shared library, then we can't know where the symbol will end up.
2146 So, we create a relocation record in the output, and leave the job up
2147 to the dynamic linker. */
2148 value = addend;
2149 if (!score_elf_create_dynamic_relocation (output_bfd, info, rel, h,
2150 symbol, &value,
2151 input_section))
2152 return bfd_reloc_undefined;
2154 else if (r_symndx == 0)
2155 /* r_symndx will be zero only for relocs against symbols
2156 from removed linkonce sections, or sections discarded by
2157 a linker script. */
2158 value = 0;
2159 else
2161 if (r_type != R_SCORE_REL32)
2162 value = symbol + addend;
2163 else
2164 value = addend;
2166 value &= howto->dst_mask;
2167 bfd_put_32 (input_bfd, value, hit_data);
2168 return bfd_reloc_ok;
2170 case R_SCORE_ABS16:
2171 value += addend;
2172 if ((long)value > 0x7fff || (long)value < -0x8000)
2173 return bfd_reloc_overflow;
2174 score_bfd_put_16 (input_bfd, value, hit_data);
2175 return bfd_reloc_ok;
2177 case R_SCORE_24:
2178 addend = score_bfd_get_32 (input_bfd, hit_data);
2179 offset = (((addend & howto->src_mask) >> 1) & 0x1ff8000) | ((addend & howto->src_mask) & 0x7fff);
2180 if ((offset & 0x1000000) != 0)
2181 offset |= 0xfe000000;
2182 value += offset;
2183 abs_value = abs (value - rel_addr);
2184 if ((abs_value & 0xfe000000) != 0)
2185 return bfd_reloc_overflow;
2186 addend = (addend & ~howto->src_mask)
2187 | (((value << 1) & howto->src_mask) & 0x3ff0000) | (value & 0x7fff);
2188 score_bfd_put_32 (input_bfd, addend, hit_data);
2189 return bfd_reloc_ok;
2191 /* signed imm32. */
2192 case R_SCORE_IMM30:
2194 int not_word_align_p = 0;
2195 bfd_vma imm_offset = 0;
2196 addend = score_bfd_get_48 (input_bfd, hit_data);
2197 imm_offset = ((addend >> 7) & 0xff)
2198 | (((addend >> 16) & 0x7fff) << 8)
2199 | (((addend >> 32) & 0x7f) << 23);
2200 imm_offset <<= howto->rightshift;
2201 value += imm_offset;
2202 value &= 0xffffffff;
2204 /* Check lw48/sw48 rd, value/label word align. */
2205 if ((value & 0x3) != 0)
2206 not_word_align_p = 1;
2208 value >>= howto->rightshift;
2209 addend = (addend & ~howto->src_mask)
2210 | (((value & 0xff) >> 0) << 7)
2211 | (((value & 0x7fff00) >> 8) << 16)
2212 | (((value & 0x3f800000) >> 23) << 32);
2213 score_bfd_put_48 (input_bfd, addend, hit_data);
2214 if (not_word_align_p)
2215 return bfd_reloc_other;
2216 else
2217 return bfd_reloc_ok;
2220 case R_SCORE_IMM32:
2222 bfd_vma imm_offset = 0;
2223 addend = score_bfd_get_48 (input_bfd, hit_data);
2224 imm_offset = ((addend >> 5) & 0x3ff)
2225 | (((addend >> 16) & 0x7fff) << 10)
2226 | (((addend >> 32) & 0x7f) << 25);
2227 value += imm_offset;
2228 value &= 0xffffffff;
2229 addend = (addend & ~howto->src_mask)
2230 | ((value & 0x3ff) << 5)
2231 | (((value >> 10) & 0x7fff) << 16)
2232 | (((value >> 25) & 0x7f) << 32);
2233 score_bfd_put_48 (input_bfd, addend, hit_data);
2234 return bfd_reloc_ok;
2237 case R_SCORE_PC19:
2238 addend = score_bfd_get_32 (input_bfd, hit_data);
2239 offset = (((addend & howto->src_mask) & 0x3ff0000) >> 6) | ((addend & howto->src_mask) & 0x3ff);
2240 if ((offset & 0x80000) != 0)
2241 offset |= 0xfff00000;
2242 abs_value = value = value - rel_addr + offset;
2243 /* exceed 20 bit : overflow. */
2244 if ((abs_value & 0x80000000) == 0x80000000)
2245 abs_value = 0xffffffff - value + 1;
2246 if ((abs_value & 0xfff80000) != 0)
2247 return bfd_reloc_overflow;
2248 addend = (addend & ~howto->src_mask)
2249 | (((value << 6) & howto->src_mask) & 0x3ff0000) | (value & 0x3ff);
2250 score_bfd_put_32 (input_bfd, addend, hit_data);
2251 return bfd_reloc_ok;
2253 case R_SCORE16_11:
2254 addend = score_bfd_get_16 (input_bfd, hit_data);
2255 offset = addend & howto->src_mask;
2256 if ((offset & 0x800) != 0) /* Offset is negative. */
2257 offset |= 0xfffff000;
2258 value += offset;
2259 abs_value = abs (value - rel_addr);
2260 if ((abs_value & 0xfffff000) != 0)
2261 return bfd_reloc_overflow;
2262 addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
2263 score_bfd_put_16 (input_bfd, addend, hit_data);
2264 return bfd_reloc_ok;
2266 case R_SCORE16_PC8:
2267 addend = score_bfd_get_16 (input_bfd, hit_data);
2268 offset = (addend & howto->src_mask) << 1;
2269 if ((offset & 0x200) != 0) /* Offset is negative. */
2270 offset |= 0xfffffe00;
2271 abs_value = value = value - rel_addr + offset;
2272 /* Sign bit + exceed 9 bit. */
2273 if (((value & 0xfffffe00) != 0) && ((value & 0xfffffe00) != 0xfffffe00))
2274 return bfd_reloc_overflow;
2275 value >>= 1;
2276 addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
2277 score_bfd_put_16 (input_bfd, addend, hit_data);
2278 return bfd_reloc_ok;
2280 case R_SCORE_BCMP:
2281 addend = score_bfd_get_32 (input_bfd, hit_data);
2282 offset = (addend & howto->src_mask) << howto->rightshift;
2283 if ((offset & 0x200) != 0) /* Offset is negative. */
2284 offset |= 0xfffffe00;
2285 value = value - rel_addr + offset;
2286 /* Sign bit + exceed 9 bit. */
2287 if (((value & 0xfffffe00) != 0) && ((value & 0xfffffe00) != 0xfffffe00))
2288 return bfd_reloc_overflow;
2289 value >>= howto->rightshift;
2290 addend = (addend & ~howto->src_mask)
2291 | (value & 0x1)
2292 | (((value >> 1) & 0x7) << 7)
2293 | (((value >> 4) & 0x1f) << 21);
2294 score_bfd_put_32 (input_bfd, addend, hit_data);
2295 return bfd_reloc_ok;
2297 case R_SCORE_HI16:
2298 return bfd_reloc_ok;
2300 case R_SCORE_LO16:
2301 hi16_addend = score_bfd_get_32 (input_bfd, hit_data - 4);
2302 hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
2303 addend = score_bfd_get_32 (input_bfd, hit_data);
2304 offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
2305 offset = (hi16_offset << 16) | (offset & 0xffff);
2307 if (!gp_disp_p)
2308 uvalue = value + offset;
2309 else
2310 uvalue = offset + gp - rel_addr + 4;
2312 hi16_offset = (uvalue >> 16) << 1;
2313 hi16_value = (hi16_addend & (~(howto->dst_mask)))
2314 | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
2315 score_bfd_put_32 (input_bfd, hi16_value, hit_data - 4);
2316 offset = (uvalue & 0xffff) << 1;
2317 value = (addend & (~(howto->dst_mask))) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
2318 score_bfd_put_32 (input_bfd, value, hit_data);
2319 return bfd_reloc_ok;
2321 case R_SCORE_GP15:
2322 addend = score_bfd_get_32 (input_bfd, hit_data);
2323 offset = addend & 0x7fff;
2324 if ((offset & 0x4000) == 0x4000)
2325 offset |= 0xffffc000;
2326 value = value + offset - gp;
2327 if (((value & 0xffffc000) != 0) && ((value & 0xffffc000) != 0xffffc000))
2328 return bfd_reloc_overflow;
2329 value = (addend & ~howto->src_mask) | (value & howto->src_mask);
2330 score_bfd_put_32 (input_bfd, value, hit_data);
2331 return bfd_reloc_ok;
2333 case R_SCORE_GOT15:
2334 case R_SCORE_CALL15:
2335 if (local_p)
2337 bfd_boolean forced;
2339 /* The special case is when the symbol is forced to be local. We need the
2340 full address in the GOT since no R_SCORE_GOT_LO16 relocation follows. */
2341 forced = ! score_elf_local_relocation_p (input_bfd, rel,
2342 local_sections, FALSE);
2343 value = score_elf_got16_entry (output_bfd, input_bfd, info,
2344 symbol + addend, forced);
2345 if (value == MINUS_ONE)
2346 return bfd_reloc_outofrange;
2347 value = score_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
2348 output_bfd, input_bfd, value);
2350 else
2352 value = g;
2355 if ((long) value > 0x3fff || (long) value < -0x4000)
2356 return bfd_reloc_overflow;
2358 addend = score_bfd_get_32 (input_bfd, hit_data);
2359 value = (addend & ~howto->dst_mask) | (value & howto->dst_mask);
2360 score_bfd_put_32 (input_bfd, value, hit_data);
2361 return bfd_reloc_ok;
2363 case R_SCORE_GPREL32:
2364 value = (addend + symbol - gp);
2365 value &= howto->dst_mask;
2366 score_bfd_put_32 (input_bfd, value, hit_data);
2367 return bfd_reloc_ok;
2369 case R_SCORE_GOT_LO16:
2370 addend = score_bfd_get_32 (input_bfd, hit_data);
2371 value = (((addend >> 16) & 0x3) << 14) | ((addend & 0x7fff) >> 1);
2372 value += symbol;
2373 value = (addend & (~(howto->dst_mask))) | ((value & 0x3fff) << 1)
2374 | (((value >> 14) & 0x3) << 16);
2376 score_bfd_put_32 (input_bfd, value, hit_data);
2377 return bfd_reloc_ok;
2379 case R_SCORE_DUMMY_HI16:
2380 return bfd_reloc_ok;
2382 case R_SCORE_GNU_VTINHERIT:
2383 case R_SCORE_GNU_VTENTRY:
2384 /* We don't do anything with these at present. */
2385 return bfd_reloc_continue;
2387 default:
2388 return bfd_reloc_notsupported;
2392 /* Score backend functions. */
2393 static void
2394 s3_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
2395 arelent *bfd_reloc,
2396 Elf_Internal_Rela *elf_reloc)
2398 unsigned int r_type;
2400 r_type = ELF32_R_TYPE (elf_reloc->r_info);
2401 if (r_type >= ARRAY_SIZE (elf32_score_howto_table))
2402 bfd_reloc->howto = NULL;
2403 else
2404 bfd_reloc->howto = &elf32_score_howto_table[r_type];
2407 /* Relocate an score ELF section. */
2408 static bfd_boolean
2409 s3_bfd_score_elf_relocate_section (bfd *output_bfd,
2410 struct bfd_link_info *info,
2411 bfd *input_bfd,
2412 asection *input_section,
2413 bfd_byte *contents,
2414 Elf_Internal_Rela *relocs,
2415 Elf_Internal_Sym *local_syms,
2416 asection **local_sections)
2418 Elf_Internal_Shdr *symtab_hdr;
2419 struct elf_link_hash_entry **sym_hashes;
2420 Elf_Internal_Rela *rel;
2421 Elf_Internal_Rela *relend;
2422 const char *name;
2423 unsigned long offset;
2424 unsigned long hi16_addend, hi16_offset, hi16_value, uvalue;
2425 size_t extsymoff;
2426 bfd_boolean gp_disp_p = FALSE;
2428 /* Sort dynsym. */
2429 if (elf_hash_table (info)->dynamic_sections_created)
2431 bfd_size_type dynsecsymcount = 0;
2432 if (info->shared)
2434 asection * p;
2435 const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
2437 for (p = output_bfd->sections; p ; p = p->next)
2438 if ((p->flags & SEC_EXCLUDE) == 0
2439 && (p->flags & SEC_ALLOC) != 0
2440 && !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p))
2441 ++ dynsecsymcount;
2444 if (!score_elf_sort_hash_table (info, dynsecsymcount + 1))
2445 return FALSE;
2448 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2449 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
2450 sym_hashes = elf_sym_hashes (input_bfd);
2451 rel = relocs;
2452 relend = relocs + input_section->reloc_count;
2453 for (; rel < relend; rel++)
2455 int r_type;
2456 reloc_howto_type *howto;
2457 unsigned long r_symndx;
2458 Elf_Internal_Sym *sym;
2459 asection *sec;
2460 struct score_elf_link_hash_entry *h;
2461 bfd_vma relocation = 0;
2462 bfd_reloc_status_type r;
2463 arelent bfd_reloc;
2465 r_symndx = ELF32_R_SYM (rel->r_info);
2466 r_type = ELF32_R_TYPE (rel->r_info);
2468 s3_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel);
2469 howto = bfd_reloc.howto;
2471 h = NULL;
2472 sym = NULL;
2473 sec = NULL;
2475 if (r_symndx < extsymoff)
2477 sym = local_syms + r_symndx;
2478 sec = local_sections[r_symndx];
2479 relocation = (sec->output_section->vma
2480 + sec->output_offset
2481 + sym->st_value);
2482 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
2484 if (!info->relocatable
2485 && (sec->flags & SEC_MERGE)
2486 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2488 asection *msec;
2489 bfd_vma addend, value;
2491 switch (r_type)
2493 case R_SCORE_HI16:
2494 break;
2495 case R_SCORE_LO16:
2496 hi16_addend = score_bfd_get_32 (input_bfd, contents + rel->r_offset - 4);
2497 hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
2498 value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2499 offset = ((((value >> 16) & 0x3) << 15) | (value & 0x7fff)) >> 1;
2500 addend = (hi16_offset << 16) | (offset & 0xffff);
2501 msec = sec;
2502 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2503 addend -= relocation;
2504 addend += msec->output_section->vma + msec->output_offset;
2505 uvalue = addend;
2506 hi16_offset = (uvalue >> 16) << 1;
2507 hi16_value = (hi16_addend & (~(howto->dst_mask)))
2508 | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
2509 score_bfd_put_32 (input_bfd, hi16_value, contents + rel->r_offset - 4);
2510 offset = (uvalue & 0xffff) << 1;
2511 value = (value & (~(howto->dst_mask)))
2512 | (offset & 0x7fff) | ((offset << 1) & 0x30000);
2513 score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2514 break;
2516 case R_SCORE_IMM32:
2518 value = score_bfd_get_48 (input_bfd, contents + rel->r_offset);
2519 addend = ((value >> 5) & 0x3ff)
2520 | (((value >> 16) & 0x7fff) << 10)
2521 | (((value >> 32) & 0x7f) << 25);
2522 msec = sec;
2523 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2524 addend -= relocation;
2525 addend += msec->output_section->vma + msec->output_offset;
2526 addend &= 0xffffffff;
2527 value = (value & ~howto->src_mask)
2528 | ((addend & 0x3ff) << 5)
2529 | (((addend >> 10) & 0x7fff) << 16)
2530 | (((addend >> 25) & 0x7f) << 32);
2531 score_bfd_put_48 (input_bfd, value, contents + rel->r_offset);
2532 break;
2535 case R_SCORE_IMM30:
2537 int not_word_align_p = 0;
2538 value = score_bfd_get_48 (input_bfd, contents + rel->r_offset);
2539 addend = ((value >> 7) & 0xff)
2540 | (((value >> 16) & 0x7fff) << 8)
2541 | (((value >> 32) & 0x7f) << 23);
2542 addend <<= howto->rightshift;
2543 msec = sec;
2544 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2545 addend -= relocation;
2546 addend += msec->output_section->vma + msec->output_offset;
2547 addend &= 0xffffffff;
2549 /* Check lw48/sw48 rd, value/label word align. */
2550 if ((addend & 0x3) != 0)
2551 not_word_align_p = 1;
2553 addend >>= howto->rightshift;
2554 value = (value & ~howto->src_mask)
2555 | (((addend & 0xff) >> 0) << 7)
2556 | (((addend & 0x7fff00) >> 8) << 16)
2557 | (((addend & 0x3f800000) >> 23) << 32);
2558 score_bfd_put_48 (input_bfd, value, contents + rel->r_offset);
2560 if (not_word_align_p)
2561 return bfd_reloc_other;
2562 else
2563 break;
2566 case R_SCORE_GOT_LO16:
2567 value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2568 addend = (((value >> 16) & 0x3) << 14) | ((value & 0x7fff) >> 1);
2569 msec = sec;
2570 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2571 addend += msec->output_section->vma + msec->output_offset;
2572 value = (value & (~(howto->dst_mask))) | ((addend & 0x3fff) << 1)
2573 | (((addend >> 14) & 0x3) << 16);
2575 score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2576 break;
2578 case R_SCORE_ABS32:
2579 case R_SCORE_REL32:
2580 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
2581 /* Get the (signed) value from the instruction. */
2582 addend = value & howto->src_mask;
2583 if (addend & ((howto->src_mask + 1) >> 1))
2585 bfd_signed_vma mask;
2587 mask = -1;
2588 mask &= ~howto->src_mask;
2589 addend |= mask;
2591 msec = sec;
2592 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2593 addend += msec->output_section->vma + msec->output_offset;
2594 value = (value & ~howto->dst_mask) | (addend & howto->dst_mask);
2595 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2596 break;
2598 default:
2599 value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2600 /* Get the (signed) value from the instruction. */
2601 addend = value & howto->src_mask;
2602 if (addend & ((howto->src_mask + 1) >> 1))
2604 bfd_signed_vma mask;
2606 mask = -1;
2607 mask &= ~howto->src_mask;
2608 addend |= mask;
2610 msec = sec;
2611 addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2612 addend += msec->output_section->vma + msec->output_offset;
2613 value = (value & ~howto->dst_mask) | (addend & howto->dst_mask);
2614 score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2615 break;
2619 else
2621 /* For global symbols we look up the symbol in the hash-table. */
2622 h = ((struct score_elf_link_hash_entry *)
2623 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
2624 /* Find the real hash-table entry for this symbol. */
2625 while (h->root.root.type == bfd_link_hash_indirect
2626 || h->root.root.type == bfd_link_hash_warning)
2627 h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
2629 /* Record the name of this symbol, for our caller. */
2630 name = h->root.root.root.string;
2632 /* See if this is the special GP_DISP_LABEL symbol. Note that such a
2633 symbol must always be a global symbol. */
2634 if (strcmp (name, GP_DISP_LABEL) == 0)
2636 /* Relocations against GP_DISP_LABEL are permitted only with
2637 R_SCORE_HI16 and R_SCORE_LO16 relocations. */
2638 if (r_type != R_SCORE_HI16 && r_type != R_SCORE_LO16)
2639 return bfd_reloc_notsupported;
2641 gp_disp_p = TRUE;
2644 /* If this symbol is defined, calculate its address. Note that
2645 GP_DISP_LABEL is a magic symbol, always implicitly defined by the
2646 linker, so it's inappropriate to check to see whether or not
2647 its defined. */
2648 else if ((h->root.root.type == bfd_link_hash_defined
2649 || h->root.root.type == bfd_link_hash_defweak)
2650 && h->root.root.u.def.section)
2652 sec = h->root.root.u.def.section;
2653 if (sec->output_section)
2654 relocation = (h->root.root.u.def.value
2655 + sec->output_section->vma
2656 + sec->output_offset);
2657 else
2659 relocation = h->root.root.u.def.value;
2662 else if (h->root.root.type == bfd_link_hash_undefweak)
2663 /* We allow relocations against undefined weak symbols, giving
2664 it the value zero, so that you can undefined weak functions
2665 and check to see if they exist by looking at their addresses. */
2666 relocation = 0;
2667 else if (info->unresolved_syms_in_objects == RM_IGNORE
2668 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
2669 relocation = 0;
2670 else if (strcmp (name, "_DYNAMIC_LINK") == 0)
2672 /* If this is a dynamic link, we should have created a _DYNAMIC_LINK symbol
2673 in s3_bfd_score_elf_create_dynamic_sections. Otherwise, we should define
2674 the symbol with a value of 0. */
2675 BFD_ASSERT (! info->shared);
2676 BFD_ASSERT (bfd_get_section_by_name (output_bfd, ".dynamic") == NULL);
2677 relocation = 0;
2679 else if (!info->relocatable)
2681 if (! ((*info->callbacks->undefined_symbol)
2682 (info, h->root.root.root.string, input_bfd,
2683 input_section, rel->r_offset,
2684 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
2685 || ELF_ST_VISIBILITY (h->root.other))))
2686 return bfd_reloc_undefined;
2687 relocation = 0;
2691 if (sec != NULL && elf_discarded_section (sec))
2693 /* For relocs against symbols from removed linkonce sections,
2694 or sections discarded by a linker script, we just want the
2695 section contents zeroed. Avoid any special processing. */
2696 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2697 rel->r_info = 0;
2698 rel->r_addend = 0;
2699 continue;
2702 if (info->relocatable)
2704 /* This is a relocatable link. We don't have to change
2705 anything, unless the reloc is against a section symbol,
2706 in which case we have to adjust according to where the
2707 section symbol winds up in the output section. */
2708 if (r_symndx < symtab_hdr->sh_info)
2710 sym = local_syms + r_symndx;
2711 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2713 sec = local_sections[r_symndx];
2714 score_elf_add_to_rel (input_bfd, contents + rel->r_offset,
2715 howto, (bfd_signed_vma) (sec->output_offset + sym->st_value));
2718 continue;
2721 /* This is a final link. */
2722 r = score_elf_final_link_relocate (howto, input_bfd, output_bfd,
2723 input_section, contents, rel, relocs,
2724 relocation, info, name,
2725 (h ? ELF_ST_TYPE ((unsigned int)h->root.root.type) :
2726 ELF_ST_TYPE ((unsigned int)sym->st_info)), h, local_sections,
2727 gp_disp_p);
2729 if (r != bfd_reloc_ok)
2731 const char *msg = (const char *)0;
2733 switch (r)
2735 case bfd_reloc_overflow:
2736 /* If the overflowing reloc was to an undefined symbol,
2737 we have already printed one error message and there
2738 is no point complaining again. */
2739 if (((!h) || (h->root.root.type != bfd_link_hash_undefined))
2740 && (!((*info->callbacks->reloc_overflow)
2741 (info, NULL, name, howto->name, (bfd_vma) 0,
2742 input_bfd, input_section, rel->r_offset))))
2743 return FALSE;
2744 break;
2745 case bfd_reloc_undefined:
2746 if (!((*info->callbacks->undefined_symbol)
2747 (info, name, input_bfd, input_section, rel->r_offset, TRUE)))
2748 return FALSE;
2749 break;
2751 case bfd_reloc_outofrange:
2752 msg = _("internal error: out of range error");
2753 goto common_error;
2755 case bfd_reloc_notsupported:
2756 msg = _("internal error: unsupported relocation error");
2757 goto common_error;
2759 case bfd_reloc_dangerous:
2760 msg = _("internal error: dangerous error");
2761 goto common_error;
2763 /* Use bfd_reloc_other to check lw48, sw48 word align. */
2764 case bfd_reloc_other:
2765 msg = _("address not word align");
2766 goto common_error;
2768 default:
2769 msg = _("internal error: unknown error");
2770 /* fall through */
2772 common_error:
2773 if (!((*info->callbacks->warning)
2774 (info, msg, name, input_bfd, input_section, rel->r_offset)))
2775 return FALSE;
2776 break;
2781 return TRUE;
2784 /* Look through the relocs for a section during the first phase, and
2785 allocate space in the global offset table. */
2786 static bfd_boolean
2787 s3_bfd_score_elf_check_relocs (bfd *abfd,
2788 struct bfd_link_info *info,
2789 asection *sec,
2790 const Elf_Internal_Rela *relocs)
2792 const char *name;
2793 bfd *dynobj;
2794 Elf_Internal_Shdr *symtab_hdr;
2795 struct elf_link_hash_entry **sym_hashes;
2796 struct score_got_info *g;
2797 size_t extsymoff;
2798 const Elf_Internal_Rela *rel;
2799 const Elf_Internal_Rela *rel_end;
2800 asection *sgot;
2801 asection *sreloc;
2802 const struct elf_backend_data *bed;
2804 if (info->relocatable)
2805 return TRUE;
2807 dynobj = elf_hash_table (info)->dynobj;
2808 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2809 sym_hashes = elf_sym_hashes (abfd);
2810 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
2812 name = bfd_get_section_name (abfd, sec);
2814 if (dynobj == NULL)
2816 sgot = NULL;
2817 g = NULL;
2819 else
2821 sgot = score_elf_got_section (dynobj, FALSE);
2822 if (sgot == NULL)
2823 g = NULL;
2824 else
2826 BFD_ASSERT (score_elf_section_data (sgot) != NULL);
2827 g = score_elf_section_data (sgot)->u.got_info;
2828 BFD_ASSERT (g != NULL);
2832 sreloc = NULL;
2833 bed = get_elf_backend_data (abfd);
2834 rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel;
2835 for (rel = relocs; rel < rel_end; ++rel)
2837 unsigned long r_symndx;
2838 unsigned int r_type;
2839 struct elf_link_hash_entry *h;
2841 r_symndx = ELF32_R_SYM (rel->r_info);
2842 r_type = ELF32_R_TYPE (rel->r_info);
2844 if (r_symndx < extsymoff)
2846 h = NULL;
2848 else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
2850 (*_bfd_error_handler) (_("%s: Malformed reloc detected for section %s"), abfd, name);
2851 bfd_set_error (bfd_error_bad_value);
2852 return FALSE;
2854 else
2856 h = sym_hashes[r_symndx - extsymoff];
2858 /* This may be an indirect symbol created because of a version. */
2859 if (h != NULL)
2861 while (h->root.type == bfd_link_hash_indirect)
2862 h = (struct elf_link_hash_entry *)h->root.u.i.link;
2866 /* Some relocs require a global offset table. */
2867 if (dynobj == NULL || sgot == NULL)
2869 switch (r_type)
2871 case R_SCORE_GOT15:
2872 case R_SCORE_CALL15:
2873 if (dynobj == NULL)
2874 elf_hash_table (info)->dynobj = dynobj = abfd;
2875 if (!score_elf_create_got_section (dynobj, info, FALSE))
2876 return FALSE;
2877 g = score_elf_got_info (dynobj, &sgot);
2878 break;
2879 case R_SCORE_ABS32:
2880 case R_SCORE_REL32:
2881 if (dynobj == NULL && (info->shared || h != NULL) && (sec->flags & SEC_ALLOC) != 0)
2882 elf_hash_table (info)->dynobj = dynobj = abfd;
2883 break;
2884 default:
2885 break;
2889 if (!h && (r_type == R_SCORE_GOT_LO16))
2891 if (! score_elf_record_local_got_symbol (abfd, r_symndx, rel->r_addend, g))
2892 return FALSE;
2895 switch (r_type)
2897 case R_SCORE_CALL15:
2898 if (h == NULL)
2900 (*_bfd_error_handler)
2901 (_("%B: CALL15 reloc at 0x%lx not against global symbol"),
2902 abfd, (unsigned long) rel->r_offset);
2903 bfd_set_error (bfd_error_bad_value);
2904 return FALSE;
2906 else
2908 /* This symbol requires a global offset table entry. */
2909 if (! score_elf_record_global_got_symbol (h, abfd, info, g))
2910 return FALSE;
2912 /* We need a stub, not a plt entry for the undefined function. But we record
2913 it as if it needs plt. See _bfd_elf_adjust_dynamic_symbol. */
2914 h->needs_plt = 1;
2915 h->type = STT_FUNC;
2917 break;
2918 case R_SCORE_GOT15:
2919 if (h && ! score_elf_record_global_got_symbol (h, abfd, info, g))
2920 return FALSE;
2921 break;
2922 case R_SCORE_ABS32:
2923 case R_SCORE_REL32:
2924 if ((info->shared || h != NULL) && (sec->flags & SEC_ALLOC) != 0)
2926 if (sreloc == NULL)
2928 sreloc = score_elf_rel_dyn_section (dynobj, TRUE);
2929 if (sreloc == NULL)
2930 return FALSE;
2932 #define SCORE_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
2933 if (info->shared)
2935 /* When creating a shared object, we must copy these reloc types into
2936 the output file as R_SCORE_REL32 relocs. We make room for this reloc
2937 in the .rel.dyn reloc section. */
2938 score_elf_allocate_dynamic_relocations (dynobj, 1);
2939 if ((sec->flags & SCORE_READONLY_SECTION)
2940 == SCORE_READONLY_SECTION)
2941 /* We tell the dynamic linker that there are
2942 relocations against the text segment. */
2943 info->flags |= DF_TEXTREL;
2945 else
2947 struct score_elf_link_hash_entry *hscore;
2949 /* We only need to copy this reloc if the symbol is
2950 defined in a dynamic object. */
2951 hscore = (struct score_elf_link_hash_entry *)h;
2952 ++hscore->possibly_dynamic_relocs;
2953 if ((sec->flags & SCORE_READONLY_SECTION)
2954 == SCORE_READONLY_SECTION)
2955 /* We need it to tell the dynamic linker if there
2956 are relocations against the text segment. */
2957 hscore->readonly_reloc = TRUE;
2960 /* Even though we don't directly need a GOT entry for this symbol,
2961 a symbol must have a dynamic symbol table index greater that
2962 DT_SCORE_GOTSYM if there are dynamic relocations against it. */
2963 if (h != NULL)
2965 if (dynobj == NULL)
2966 elf_hash_table (info)->dynobj = dynobj = abfd;
2967 if (! score_elf_create_got_section (dynobj, info, TRUE))
2968 return FALSE;
2969 g = score_elf_got_info (dynobj, &sgot);
2970 if (! score_elf_record_global_got_symbol (h, abfd, info, g))
2971 return FALSE;
2974 break;
2976 /* This relocation describes the C++ object vtable hierarchy.
2977 Reconstruct it for later use during GC. */
2978 case R_SCORE_GNU_VTINHERIT:
2979 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2980 return FALSE;
2981 break;
2983 /* This relocation describes which C++ vtable entries are actually
2984 used. Record for later use during GC. */
2985 case R_SCORE_GNU_VTENTRY:
2986 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
2987 return FALSE;
2988 break;
2989 default:
2990 break;
2993 /* We must not create a stub for a symbol that has relocations
2994 related to taking the function's address. */
2995 switch (r_type)
2997 default:
2998 if (h != NULL)
3000 struct score_elf_link_hash_entry *sh;
3002 sh = (struct score_elf_link_hash_entry *) h;
3003 sh->no_fn_stub = TRUE;
3005 break;
3006 case R_SCORE_CALL15:
3007 break;
3011 return TRUE;
3014 static bfd_boolean
3015 s3_bfd_score_elf_add_symbol_hook (bfd *abfd,
3016 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3017 Elf_Internal_Sym *sym,
3018 const char **namep ATTRIBUTE_UNUSED,
3019 flagword *flagsp ATTRIBUTE_UNUSED,
3020 asection **secp,
3021 bfd_vma *valp)
3023 switch (sym->st_shndx)
3025 case SHN_COMMON:
3026 if (sym->st_size > elf_gp_size (abfd))
3027 break;
3028 /* Fall through. */
3029 case SHN_SCORE_SCOMMON:
3030 *secp = bfd_make_section_old_way (abfd, ".scommon");
3031 (*secp)->flags |= SEC_IS_COMMON;
3032 *valp = sym->st_size;
3033 break;
3036 return TRUE;
3039 static void
3040 s3_bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
3042 elf_symbol_type *elfsym;
3044 elfsym = (elf_symbol_type *) asym;
3045 switch (elfsym->internal_elf_sym.st_shndx)
3047 case SHN_COMMON:
3048 if (asym->value > elf_gp_size (abfd))
3049 break;
3050 /* Fall through. */
3051 case SHN_SCORE_SCOMMON:
3052 if (score_elf_scom_section.name == NULL)
3054 /* Initialize the small common section. */
3055 score_elf_scom_section.name = ".scommon";
3056 score_elf_scom_section.flags = SEC_IS_COMMON;
3057 score_elf_scom_section.output_section = &score_elf_scom_section;
3058 score_elf_scom_section.symbol = &score_elf_scom_symbol;
3059 score_elf_scom_section.symbol_ptr_ptr = &score_elf_scom_symbol_ptr;
3060 score_elf_scom_symbol.name = ".scommon";
3061 score_elf_scom_symbol.flags = BSF_SECTION_SYM;
3062 score_elf_scom_symbol.section = &score_elf_scom_section;
3063 score_elf_scom_symbol_ptr = &score_elf_scom_symbol;
3065 asym->section = &score_elf_scom_section;
3066 asym->value = elfsym->internal_elf_sym.st_size;
3067 break;
3071 static int
3072 s3_bfd_score_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3073 const char *name ATTRIBUTE_UNUSED,
3074 Elf_Internal_Sym *sym,
3075 asection *input_sec,
3076 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3078 /* If we see a common symbol, which implies a relocatable link, then
3079 if a symbol was small common in an input file, mark it as small
3080 common in the output file. */
3081 if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
3082 sym->st_shndx = SHN_SCORE_SCOMMON;
3084 return 1;
3087 static bfd_boolean
3088 s3_bfd_score_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3089 asection *sec,
3090 int *retval)
3092 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
3094 *retval = SHN_SCORE_SCOMMON;
3095 return TRUE;
3098 return FALSE;
3101 /* Adjust a symbol defined by a dynamic object and referenced by a
3102 regular object. The current definition is in some section of the
3103 dynamic object, but we're not including those sections. We have to
3104 change the definition to something the rest of the link can understand. */
3105 static bfd_boolean
3106 s3_bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3107 struct elf_link_hash_entry *h)
3109 bfd *dynobj;
3110 struct score_elf_link_hash_entry *hscore;
3111 asection *s;
3113 dynobj = elf_hash_table (info)->dynobj;
3115 /* Make sure we know what is going on here. */
3116 BFD_ASSERT (dynobj != NULL
3117 && (h->needs_plt
3118 || h->u.weakdef != NULL
3119 || (h->def_dynamic && h->ref_regular && !h->def_regular)));
3121 /* If this symbol is defined in a dynamic object, we need to copy
3122 any R_SCORE_ABS32 or R_SCORE_REL32 relocs against it into the output
3123 file. */
3124 hscore = (struct score_elf_link_hash_entry *)h;
3125 if (!info->relocatable
3126 && hscore->possibly_dynamic_relocs != 0
3127 && (h->root.type == bfd_link_hash_defweak || !h->def_regular))
3129 score_elf_allocate_dynamic_relocations (dynobj, hscore->possibly_dynamic_relocs);
3130 if (hscore->readonly_reloc)
3131 /* We tell the dynamic linker that there are relocations
3132 against the text segment. */
3133 info->flags |= DF_TEXTREL;
3136 /* For a function, create a stub, if allowed. */
3137 if (!hscore->no_fn_stub && h->needs_plt)
3139 if (!elf_hash_table (info)->dynamic_sections_created)
3140 return TRUE;
3142 /* If this symbol is not defined in a regular file, then set
3143 the symbol to the stub location. This is required to make
3144 function pointers compare as equal between the normal
3145 executable and the shared library. */
3146 if (!h->def_regular)
3148 /* We need .stub section. */
3149 s = bfd_get_section_by_name (dynobj, SCORE_ELF_STUB_SECTION_NAME);
3150 BFD_ASSERT (s != NULL);
3152 h->root.u.def.section = s;
3153 h->root.u.def.value = s->size;
3155 /* XXX Write this stub address somewhere. */
3156 h->plt.offset = s->size;
3158 /* Make room for this stub code. */
3159 s->size += SCORE_FUNCTION_STUB_SIZE;
3161 /* The last half word of the stub will be filled with the index
3162 of this symbol in .dynsym section. */
3163 return TRUE;
3166 else if ((h->type == STT_FUNC) && !h->needs_plt)
3168 /* This will set the entry for this symbol in the GOT to 0, and
3169 the dynamic linker will take care of this. */
3170 h->root.u.def.value = 0;
3171 return TRUE;
3174 /* If this is a weak symbol, and there is a real definition, the
3175 processor independent code will have arranged for us to see the
3176 real definition first, and we can just use the same value. */
3177 if (h->u.weakdef != NULL)
3179 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
3180 || h->u.weakdef->root.type == bfd_link_hash_defweak);
3181 h->root.u.def.section = h->u.weakdef->root.u.def.section;
3182 h->root.u.def.value = h->u.weakdef->root.u.def.value;
3183 return TRUE;
3186 /* This is a reference to a symbol defined by a dynamic object which
3187 is not a function. */
3188 return TRUE;
3191 /* This function is called after all the input files have been read,
3192 and the input sections have been assigned to output sections. */
3193 static bfd_boolean
3194 s3_bfd_score_elf_always_size_sections (bfd *output_bfd,
3195 struct bfd_link_info *info)
3197 bfd *dynobj;
3198 asection *s;
3199 struct score_got_info *g;
3200 int i;
3201 bfd_size_type loadable_size = 0;
3202 bfd_size_type local_gotno;
3203 bfd *sub;
3205 dynobj = elf_hash_table (info)->dynobj;
3206 if (dynobj == NULL)
3207 /* Relocatable links don't have it. */
3208 return TRUE;
3210 g = score_elf_got_info (dynobj, &s);
3211 if (s == NULL)
3212 return TRUE;
3214 /* Calculate the total loadable size of the output. That will give us the
3215 maximum number of GOT_PAGE entries required. */
3216 for (sub = info->input_bfds; sub; sub = sub->link_next)
3218 asection *subsection;
3220 for (subsection = sub->sections;
3221 subsection;
3222 subsection = subsection->next)
3224 if ((subsection->flags & SEC_ALLOC) == 0)
3225 continue;
3226 loadable_size += ((subsection->size + 0xf)
3227 &~ (bfd_size_type) 0xf);
3231 /* There has to be a global GOT entry for every symbol with
3232 a dynamic symbol table index of DT_SCORE_GOTSYM or
3233 higher. Therefore, it make sense to put those symbols
3234 that need GOT entries at the end of the symbol table. We
3235 do that here. */
3236 if (! score_elf_sort_hash_table (info, 1))
3237 return FALSE;
3239 if (g->global_gotsym != NULL)
3240 i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
3241 else
3242 /* If there are no global symbols, or none requiring
3243 relocations, then GLOBAL_GOTSYM will be NULL. */
3244 i = 0;
3246 /* In the worst case, we'll get one stub per dynamic symbol. */
3247 loadable_size += SCORE_FUNCTION_STUB_SIZE * i;
3249 /* Assume there are two loadable segments consisting of
3250 contiguous sections. Is 5 enough? */
3251 local_gotno = (loadable_size >> 16) + 5;
3253 g->local_gotno += local_gotno;
3254 s->size += g->local_gotno * SCORE_ELF_GOT_SIZE (output_bfd);
3256 g->global_gotno = i;
3257 s->size += i * SCORE_ELF_GOT_SIZE (output_bfd);
3259 score_elf_resolve_final_got_entries (g);
3261 if (s->size > SCORE_ELF_GOT_MAX_SIZE (output_bfd))
3263 /* Fixme. Error message or Warning message should be issued here. */
3266 return TRUE;
3269 /* Set the sizes of the dynamic sections. */
3270 static bfd_boolean
3271 s3_bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
3273 bfd *dynobj;
3274 asection *s;
3275 bfd_boolean reltext;
3277 dynobj = elf_hash_table (info)->dynobj;
3278 BFD_ASSERT (dynobj != NULL);
3280 if (elf_hash_table (info)->dynamic_sections_created)
3282 /* Set the contents of the .interp section to the interpreter. */
3283 if (!info->shared)
3285 s = bfd_get_section_by_name (dynobj, ".interp");
3286 BFD_ASSERT (s != NULL);
3287 s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
3288 s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3292 /* The check_relocs and adjust_dynamic_symbol entry points have
3293 determined the sizes of the various dynamic sections. Allocate
3294 memory for them. */
3295 reltext = FALSE;
3296 for (s = dynobj->sections; s != NULL; s = s->next)
3298 const char *name;
3300 if ((s->flags & SEC_LINKER_CREATED) == 0)
3301 continue;
3303 /* It's OK to base decisions on the section name, because none
3304 of the dynobj section names depend upon the input files. */
3305 name = bfd_get_section_name (dynobj, s);
3307 if (CONST_STRNEQ (name, ".rel"))
3309 if (s->size == 0)
3311 /* We only strip the section if the output section name
3312 has the same name. Otherwise, there might be several
3313 input sections for this output section. FIXME: This
3314 code is probably not needed these days anyhow, since
3315 the linker now does not create empty output sections. */
3316 if (s->output_section != NULL
3317 && strcmp (name,
3318 bfd_get_section_name (s->output_section->owner,
3319 s->output_section)) == 0)
3320 s->flags |= SEC_EXCLUDE;
3322 else
3324 const char *outname;
3325 asection *target;
3327 /* If this relocation section applies to a read only
3328 section, then we probably need a DT_TEXTREL entry.
3329 If the relocation section is .rel.dyn, we always
3330 assert a DT_TEXTREL entry rather than testing whether
3331 there exists a relocation to a read only section or
3332 not. */
3333 outname = bfd_get_section_name (output_bfd, s->output_section);
3334 target = bfd_get_section_by_name (output_bfd, outname + 4);
3335 if ((target != NULL
3336 && (target->flags & SEC_READONLY) != 0
3337 && (target->flags & SEC_ALLOC) != 0) || strcmp (outname, ".rel.dyn") == 0)
3338 reltext = TRUE;
3340 /* We use the reloc_count field as a counter if we need
3341 to copy relocs into the output file. */
3342 if (strcmp (name, ".rel.dyn") != 0)
3343 s->reloc_count = 0;
3346 else if (CONST_STRNEQ (name, ".got"))
3348 /* s3_bfd_score_elf_always_size_sections() has already done
3349 most of the work, but some symbols may have been mapped
3350 to versions that we must now resolve in the got_entries
3351 hash tables. */
3353 else if (strcmp (name, SCORE_ELF_STUB_SECTION_NAME) == 0)
3355 /* IRIX rld assumes that the function stub isn't at the end
3356 of .text section. So put a dummy. XXX */
3357 s->size += SCORE_FUNCTION_STUB_SIZE;
3359 else if (! CONST_STRNEQ (name, ".init"))
3361 /* It's not one of our sections, so don't allocate space. */
3362 continue;
3365 /* Allocate memory for the section contents. */
3366 s->contents = bfd_zalloc (dynobj, s->size);
3367 if (s->contents == NULL && s->size != 0)
3369 bfd_set_error (bfd_error_no_memory);
3370 return FALSE;
3374 if (elf_hash_table (info)->dynamic_sections_created)
3376 /* Add some entries to the .dynamic section. We fill in the
3377 values later, in s3_bfd_score_elf_finish_dynamic_sections, but we
3378 must add the entries now so that we get the correct size for
3379 the .dynamic section. The DT_DEBUG entry is filled in by the
3380 dynamic linker and used by the debugger. */
3382 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
3383 return FALSE;
3385 if (reltext)
3386 info->flags |= DF_TEXTREL;
3388 if ((info->flags & DF_TEXTREL) != 0)
3390 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
3391 return FALSE;
3394 if (! SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
3395 return FALSE;
3397 if (score_elf_rel_dyn_section (dynobj, FALSE))
3399 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0))
3400 return FALSE;
3402 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0))
3403 return FALSE;
3405 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0))
3406 return FALSE;
3409 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_BASE_ADDRESS, 0))
3410 return FALSE;
3412 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_LOCAL_GOTNO, 0))
3413 return FALSE;
3415 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_SYMTABNO, 0))
3416 return FALSE;
3418 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_UNREFEXTNO, 0))
3419 return FALSE;
3421 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_GOTSYM, 0))
3422 return FALSE;
3424 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_HIPAGENO, 0))
3425 return FALSE;
3428 return TRUE;
3431 static bfd_boolean
3432 s3_bfd_score_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3434 struct elf_link_hash_entry *h;
3435 struct bfd_link_hash_entry *bh;
3436 flagword flags;
3437 asection *s;
3439 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3440 | SEC_LINKER_CREATED | SEC_READONLY);
3442 /* ABI requests the .dynamic section to be read only. */
3443 s = bfd_get_section_by_name (abfd, ".dynamic");
3444 if (s != NULL)
3446 if (!bfd_set_section_flags (abfd, s, flags))
3447 return FALSE;
3450 /* We need to create .got section. */
3451 if (!score_elf_create_got_section (abfd, info, FALSE))
3452 return FALSE;
3454 if (!score_elf_rel_dyn_section (elf_hash_table (info)->dynobj, TRUE))
3455 return FALSE;
3457 /* Create .stub section. */
3458 if (bfd_get_section_by_name (abfd, SCORE_ELF_STUB_SECTION_NAME) == NULL)
3460 s = bfd_make_section_with_flags (abfd, SCORE_ELF_STUB_SECTION_NAME,
3461 flags | SEC_CODE);
3462 if (s == NULL
3463 || !bfd_set_section_alignment (abfd, s, 2))
3465 return FALSE;
3468 if (!info->shared)
3470 const char *name;
3472 name = "_DYNAMIC_LINK";
3473 bh = NULL;
3474 if (!(_bfd_generic_link_add_one_symbol
3475 (info, abfd, name, BSF_GLOBAL, bfd_abs_section_ptr,
3476 (bfd_vma) 0, NULL, FALSE, get_elf_backend_data (abfd)->collect, &bh)))
3477 return FALSE;
3479 h = (struct elf_link_hash_entry *)bh;
3480 h->non_elf = 0;
3481 h->def_regular = 1;
3482 h->type = STT_SECTION;
3484 if (!bfd_elf_link_record_dynamic_symbol (info, h))
3485 return FALSE;
3488 return TRUE;
3492 /* Finish up dynamic symbol handling. We set the contents of various
3493 dynamic sections here. */
3494 static bfd_boolean
3495 s3_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
3496 struct bfd_link_info *info,
3497 struct elf_link_hash_entry *h,
3498 Elf_Internal_Sym *sym)
3500 bfd *dynobj;
3501 asection *sgot;
3502 struct score_got_info *g;
3503 const char *name;
3505 dynobj = elf_hash_table (info)->dynobj;
3507 if (h->plt.offset != MINUS_ONE)
3509 asection *s;
3510 bfd_byte stub[SCORE_FUNCTION_STUB_SIZE];
3512 /* This symbol has a stub. Set it up. */
3513 BFD_ASSERT (h->dynindx != -1);
3515 s = bfd_get_section_by_name (dynobj, SCORE_ELF_STUB_SECTION_NAME);
3516 BFD_ASSERT (s != NULL);
3518 /* FIXME: Can h->dynindex be more than 64K? */
3519 if (h->dynindx & 0xffff0000)
3520 return FALSE;
3522 /* Fill the stub. */
3523 score_bfd_put_32 (output_bfd, STUB_LW, stub);
3524 score_bfd_put_32 (output_bfd, STUB_MOVE, stub + 4);
3525 score_bfd_put_32 (output_bfd, STUB_LI16 | (h->dynindx << 1), stub + 8);
3526 score_bfd_put_32 (output_bfd, STUB_BRL, stub + 12);
3528 BFD_ASSERT (h->plt.offset <= s->size);
3529 memcpy (s->contents + h->plt.offset, stub, SCORE_FUNCTION_STUB_SIZE);
3531 /* Mark the symbol as undefined. plt.offset != -1 occurs
3532 only for the referenced symbol. */
3533 sym->st_shndx = SHN_UNDEF;
3535 /* The run-time linker uses the st_value field of the symbol
3536 to reset the global offset table entry for this external
3537 to its stub address when unlinking a shared object. */
3538 sym->st_value = (s->output_section->vma + s->output_offset + h->plt.offset);
3541 BFD_ASSERT (h->dynindx != -1 || h->forced_local);
3543 sgot = score_elf_got_section (dynobj, FALSE);
3544 BFD_ASSERT (sgot != NULL);
3545 BFD_ASSERT (score_elf_section_data (sgot) != NULL);
3546 g = score_elf_section_data (sgot)->u.got_info;
3547 BFD_ASSERT (g != NULL);
3549 /* Run through the global symbol table, creating GOT entries for all
3550 the symbols that need them. */
3551 if (g->global_gotsym != NULL && h->dynindx >= g->global_gotsym->dynindx)
3553 bfd_vma offset;
3554 bfd_vma value;
3556 value = sym->st_value;
3557 offset = score_elf_global_got_index (dynobj, h);
3558 score_bfd_put_32 (output_bfd, value, sgot->contents + offset);
3561 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3562 name = h->root.root.string;
3563 if (strcmp (name, "_DYNAMIC") == 0 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
3564 sym->st_shndx = SHN_ABS;
3565 else if (strcmp (name, "_DYNAMIC_LINK") == 0)
3567 sym->st_shndx = SHN_ABS;
3568 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
3569 sym->st_value = 1;
3571 else if (strcmp (name, GP_DISP_LABEL) == 0)
3573 sym->st_shndx = SHN_ABS;
3574 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
3575 sym->st_value = elf_gp (output_bfd);
3578 return TRUE;
3581 /* Finish up the dynamic sections. */
3582 static bfd_boolean
3583 s3_bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
3584 struct bfd_link_info *info)
3586 bfd *dynobj;
3587 asection *sdyn;
3588 asection *sgot;
3589 asection *s;
3590 struct score_got_info *g;
3592 dynobj = elf_hash_table (info)->dynobj;
3594 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3596 sgot = score_elf_got_section (dynobj, FALSE);
3597 if (sgot == NULL)
3598 g = NULL;
3599 else
3601 BFD_ASSERT (score_elf_section_data (sgot) != NULL);
3602 g = score_elf_section_data (sgot)->u.got_info;
3603 BFD_ASSERT (g != NULL);
3606 if (elf_hash_table (info)->dynamic_sections_created)
3608 bfd_byte *b;
3610 BFD_ASSERT (sdyn != NULL);
3611 BFD_ASSERT (g != NULL);
3613 for (b = sdyn->contents;
3614 b < sdyn->contents + sdyn->size;
3615 b += SCORE_ELF_DYN_SIZE (dynobj))
3617 Elf_Internal_Dyn dyn;
3618 const char *name;
3619 size_t elemsize;
3620 bfd_boolean swap_out_p;
3622 /* Read in the current dynamic entry. */
3623 (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
3625 /* Assume that we're going to modify it and write it out. */
3626 swap_out_p = TRUE;
3628 switch (dyn.d_tag)
3630 case DT_RELENT:
3631 s = score_elf_rel_dyn_section (dynobj, FALSE);
3632 BFD_ASSERT (s != NULL);
3633 dyn.d_un.d_val = SCORE_ELF_REL_SIZE (dynobj);
3634 break;
3636 case DT_STRSZ:
3637 /* Rewrite DT_STRSZ. */
3638 dyn.d_un.d_val = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
3639 break;
3641 case DT_PLTGOT:
3642 name = ".got";
3643 s = bfd_get_section_by_name (output_bfd, name);
3644 BFD_ASSERT (s != NULL);
3645 dyn.d_un.d_ptr = s->vma;
3646 break;
3648 case DT_SCORE_BASE_ADDRESS:
3649 s = output_bfd->sections;
3650 BFD_ASSERT (s != NULL);
3651 dyn.d_un.d_ptr = s->vma & ~(bfd_vma) 0xffff;
3652 break;
3654 case DT_SCORE_LOCAL_GOTNO:
3655 dyn.d_un.d_val = g->local_gotno;
3656 break;
3658 case DT_SCORE_UNREFEXTNO:
3659 /* The index into the dynamic symbol table which is the
3660 entry of the first external symbol that is not
3661 referenced within the same object. */
3662 dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
3663 break;
3665 case DT_SCORE_GOTSYM:
3666 if (g->global_gotsym)
3668 dyn.d_un.d_val = g->global_gotsym->dynindx;
3669 break;
3671 /* In case if we don't have global got symbols we default
3672 to setting DT_SCORE_GOTSYM to the same value as
3673 DT_SCORE_SYMTABNO, so we just fall through. */
3675 case DT_SCORE_SYMTABNO:
3676 name = ".dynsym";
3677 elemsize = SCORE_ELF_SYM_SIZE (output_bfd);
3678 s = bfd_get_section_by_name (output_bfd, name);
3679 BFD_ASSERT (s != NULL);
3681 dyn.d_un.d_val = s->size / elemsize;
3682 break;
3684 case DT_SCORE_HIPAGENO:
3685 dyn.d_un.d_val = g->local_gotno - SCORE_RESERVED_GOTNO;
3686 break;
3688 default:
3689 swap_out_p = FALSE;
3690 break;
3693 if (swap_out_p)
3694 (*get_elf_backend_data (dynobj)->s->swap_dyn_out) (dynobj, &dyn, b);
3698 /* The first entry of the global offset table will be filled at
3699 runtime. The second entry will be used by some runtime loaders.
3700 This isn't the case of IRIX rld. */
3701 if (sgot != NULL && sgot->size > 0)
3703 score_bfd_put_32 (output_bfd, 0, sgot->contents);
3704 score_bfd_put_32 (output_bfd, 0x80000000, sgot->contents + SCORE_ELF_GOT_SIZE (output_bfd));
3707 if (sgot != NULL)
3708 elf_section_data (sgot->output_section)->this_hdr.sh_entsize
3709 = SCORE_ELF_GOT_SIZE (output_bfd);
3712 /* We need to sort the entries of the dynamic relocation section. */
3713 s = score_elf_rel_dyn_section (dynobj, FALSE);
3715 if (s != NULL && s->size > (bfd_vma)2 * SCORE_ELF_REL_SIZE (output_bfd))
3717 reldyn_sorting_bfd = output_bfd;
3718 qsort ((Elf32_External_Rel *) s->contents + 1, s->reloc_count - 1,
3719 sizeof (Elf32_External_Rel), score_elf_sort_dynamic_relocs);
3722 return TRUE;
3725 /* This function set up the ELF section header for a BFD section in preparation for writing
3726 it out. This is where the flags and type fields are set for unusual sections. */
3727 static bfd_boolean
3728 s3_bfd_score_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
3729 Elf_Internal_Shdr *hdr,
3730 asection *sec)
3732 const char *name;
3734 name = bfd_get_section_name (abfd, sec);
3736 if (strcmp (name, ".got") == 0
3737 || strcmp (name, ".srdata") == 0
3738 || strcmp (name, ".sdata") == 0
3739 || strcmp (name, ".sbss") == 0)
3740 hdr->sh_flags |= SHF_SCORE_GPREL;
3742 return TRUE;
3745 /* This function do additional processing on the ELF section header before writing
3746 it out. This is used to set the flags and type fields for some sections. */
3748 /* assign_file_positions_except_relocs() check section flag and if it is allocatable,
3749 warning message will be issued. backend_fake_section is called before
3750 assign_file_positions_except_relocs(); backend_section_processing after it. so, we
3751 modify section flag there, but not backend_fake_section. */
3752 static bfd_boolean
3753 s3_bfd_score_elf_section_processing (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *hdr)
3755 if (hdr->bfd_section != NULL)
3757 const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
3759 if (strcmp (name, ".sdata") == 0)
3761 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
3762 hdr->sh_type = SHT_PROGBITS;
3764 else if (strcmp (name, ".sbss") == 0)
3766 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
3767 hdr->sh_type = SHT_NOBITS;
3769 else if (strcmp (name, ".srdata") == 0)
3771 hdr->sh_flags |= SHF_ALLOC | SHF_SCORE_GPREL;
3772 hdr->sh_type = SHT_PROGBITS;
3776 return TRUE;
3779 static bfd_boolean
3780 s3_bfd_score_elf_write_section (bfd *output_bfd, asection *sec, bfd_byte *contents)
3782 bfd_byte *to, *from, *end;
3783 int i;
3785 if (strcmp (sec->name, ".pdr") != 0)
3786 return FALSE;
3788 if (score_elf_section_data (sec)->u.tdata == NULL)
3789 return FALSE;
3791 to = contents;
3792 end = contents + sec->size;
3793 for (from = contents, i = 0; from < end; from += PDR_SIZE, i++)
3795 if ((score_elf_section_data (sec)->u.tdata)[i] == 1)
3796 continue;
3798 if (to != from)
3799 memcpy (to, from, PDR_SIZE);
3801 to += PDR_SIZE;
3803 bfd_set_section_contents (output_bfd, sec->output_section, contents,
3804 (file_ptr) sec->output_offset, sec->size);
3806 return TRUE;
3809 /* Copy data from a SCORE ELF indirect symbol to its direct symbol, hiding the old
3810 indirect symbol. Process additional relocation information. */
3811 static void
3812 s3_bfd_score_elf_copy_indirect_symbol (struct bfd_link_info *info,
3813 struct elf_link_hash_entry *dir,
3814 struct elf_link_hash_entry *ind)
3816 struct score_elf_link_hash_entry *dirscore, *indscore;
3818 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3820 if (ind->root.type != bfd_link_hash_indirect)
3821 return;
3823 dirscore = (struct score_elf_link_hash_entry *) dir;
3824 indscore = (struct score_elf_link_hash_entry *) ind;
3825 dirscore->possibly_dynamic_relocs += indscore->possibly_dynamic_relocs;
3827 if (indscore->readonly_reloc)
3828 dirscore->readonly_reloc = TRUE;
3830 if (indscore->no_fn_stub)
3831 dirscore->no_fn_stub = TRUE;
3834 /* Remove information about discarded functions from other sections which mention them. */
3835 static bfd_boolean
3836 s3_bfd_score_elf_discard_info (bfd *abfd, struct elf_reloc_cookie *cookie,
3837 struct bfd_link_info *info)
3839 asection *o;
3840 bfd_boolean ret = FALSE;
3841 unsigned char *tdata;
3842 size_t i, skip;
3844 o = bfd_get_section_by_name (abfd, ".pdr");
3845 if ((!o) || (o->size == 0) || (o->size % PDR_SIZE != 0)
3846 || (o->output_section != NULL && bfd_is_abs_section (o->output_section)))
3847 return FALSE;
3849 tdata = bfd_zmalloc (o->size / PDR_SIZE);
3850 if (!tdata)
3851 return FALSE;
3853 cookie->rels = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, info->keep_memory);
3854 if (!cookie->rels)
3856 free (tdata);
3857 return FALSE;
3860 cookie->rel = cookie->rels;
3861 cookie->relend = cookie->rels + o->reloc_count;
3863 for (i = 0, skip = 0; i < o->size; i++)
3865 if (bfd_elf_reloc_symbol_deleted_p (i * PDR_SIZE, cookie))
3867 tdata[i] = 1;
3868 skip++;
3872 if (skip != 0)
3874 score_elf_section_data (o)->u.tdata = tdata;
3875 o->size -= skip * PDR_SIZE;
3876 ret = TRUE;
3878 else
3879 free (tdata);
3881 if (!info->keep_memory)
3882 free (cookie->rels);
3884 return ret;
3887 /* Signal that discard_info() has removed the discarded relocations for this section. */
3888 static bfd_boolean
3889 s3_bfd_score_elf_ignore_discarded_relocs (asection *sec)
3891 if (strcmp (sec->name, ".pdr") == 0)
3892 return TRUE;
3893 return FALSE;
3896 /* Return the section that should be marked against GC for a given
3897 relocation. */
3898 static asection *
3899 s3_bfd_score_elf_gc_mark_hook (asection *sec,
3900 struct bfd_link_info *info,
3901 Elf_Internal_Rela *rel,
3902 struct elf_link_hash_entry *h,
3903 Elf_Internal_Sym *sym)
3905 if (h != NULL)
3906 switch (ELF32_R_TYPE (rel->r_info))
3908 case R_SCORE_GNU_VTINHERIT:
3909 case R_SCORE_GNU_VTENTRY:
3910 return NULL;
3913 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
3916 /* Support for core dump NOTE sections. */
3918 static bfd_boolean
3919 s3_bfd_score_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3921 int offset;
3922 unsigned int raw_size;
3924 switch (note->descsz)
3926 default:
3927 return FALSE;
3929 case 148: /* Linux/Score 32-bit. */
3930 /* pr_cursig */
3931 elf_tdata (abfd)->core_signal = score_bfd_get_16 (abfd, note->descdata + 12);
3933 /* pr_pid */
3934 elf_tdata (abfd)->core_pid = score_bfd_get_32 (abfd, note->descdata + 24);
3936 /* pr_reg */
3937 offset = 72;
3938 raw_size = 72;
3940 break;
3943 /* Make a ".reg/999" section. */
3944 return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size, note->descpos + offset);
3947 static bfd_boolean
3948 s3_bfd_score_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3950 switch (note->descsz)
3952 default:
3953 return FALSE;
3955 case 124: /* Linux/Score elf_prpsinfo. */
3956 elf_tdata (abfd)->core_program = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
3957 elf_tdata (abfd)->core_command = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
3960 /* Note that for some reason, a spurious space is tacked
3961 onto the end of the args in some (at least one anyway)
3962 implementations, so strip it off if it exists. */
3965 char *command = elf_tdata (abfd)->core_command;
3966 int n = strlen (command);
3968 if (0 < n && command[n - 1] == ' ')
3969 command[n - 1] = '\0';
3972 return TRUE;
3976 /* Score BFD functions. */
3977 static reloc_howto_type *
3978 s3_elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
3980 unsigned int i;
3982 for (i = 0; i < ARRAY_SIZE (elf32_score_reloc_map); i++)
3983 if (elf32_score_reloc_map[i].bfd_reloc_val == code)
3984 return &elf32_score_howto_table[elf32_score_reloc_map[i].elf_reloc_val];
3986 return NULL;
3989 static reloc_howto_type *
3990 elf32_score_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3991 const char *r_name)
3993 unsigned int i;
3995 for (i = 0;
3996 i < (sizeof (elf32_score_howto_table)
3997 / sizeof (elf32_score_howto_table[0]));
3998 i++)
3999 if (elf32_score_howto_table[i].name != NULL
4000 && strcasecmp (elf32_score_howto_table[i].name, r_name) == 0)
4001 return &elf32_score_howto_table[i];
4003 return NULL;
4006 /* Create a score elf linker hash table. */
4008 static struct bfd_link_hash_table *
4009 s3_elf32_score_link_hash_table_create (bfd *abfd)
4011 struct score_elf_link_hash_table *ret;
4012 bfd_size_type amt = sizeof (struct score_elf_link_hash_table);
4014 ret = bfd_malloc (amt);
4015 if (ret == NULL)
4016 return NULL;
4018 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, score_elf_link_hash_newfunc,
4019 sizeof (struct score_elf_link_hash_entry)))
4021 free (ret);
4022 return NULL;
4025 return &ret->root.root;
4028 static bfd_boolean
4029 s3_elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
4031 FILE *file = (FILE *) ptr;
4033 BFD_ASSERT (abfd != NULL && ptr != NULL);
4035 /* Print normal ELF private data. */
4036 _bfd_elf_print_private_bfd_data (abfd, ptr);
4038 /* xgettext:c-format */
4039 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
4040 if (elf_elfheader (abfd)->e_flags & EF_SCORE_PIC)
4042 fprintf (file, _(" [pic]"));
4044 if (elf_elfheader (abfd)->e_flags & EF_SCORE_FIXDEP)
4046 fprintf (file, _(" [fix dep]"));
4048 fputc ('\n', file);
4050 return TRUE;
4053 static bfd_boolean
4054 s3_elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4056 flagword in_flags;
4057 flagword out_flags;
4059 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
4060 return FALSE;
4062 in_flags = elf_elfheader (ibfd)->e_flags;
4063 out_flags = elf_elfheader (obfd)->e_flags;
4065 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4066 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4067 return TRUE;
4069 in_flags = elf_elfheader (ibfd)->e_flags;
4070 out_flags = elf_elfheader (obfd)->e_flags;
4072 if (! elf_flags_init (obfd))
4074 elf_flags_init (obfd) = TRUE;
4075 elf_elfheader (obfd)->e_flags = in_flags;
4077 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4078 && bfd_get_arch_info (obfd)->the_default)
4080 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
4083 return TRUE;
4086 if (((in_flags & EF_SCORE_PIC) != 0) != ((out_flags & EF_SCORE_PIC) != 0))
4088 (*_bfd_error_handler) (_("%B: warning: linking PIC files with non-PIC files"), ibfd);
4091 /* FIXME: Maybe dependency fix compatibility should be checked here. */
4093 return TRUE;
4096 static bfd_boolean
4097 s3_elf32_score_new_section_hook (bfd *abfd, asection *sec)
4099 struct _score_elf_section_data *sdata;
4100 bfd_size_type amt = sizeof (*sdata);
4102 sdata = bfd_zalloc (abfd, amt);
4103 if (sdata == NULL)
4104 return FALSE;
4105 sec->used_by_bfd = sdata;
4107 return _bfd_elf_new_section_hook (abfd, sec);
4110 /*****************************************************************************/
4112 /* s3_s7: backend hooks. */
4113 static void
4114 _bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
4115 arelent *bfd_reloc,
4116 Elf_Internal_Rela *elf_reloc)
4118 if (bfd_get_mach (abfd) == bfd_mach_score3)
4119 return s3_bfd_score_info_to_howto (abfd, bfd_reloc, elf_reloc);
4120 else
4121 return s7_bfd_score_info_to_howto (abfd, bfd_reloc, elf_reloc);
4124 static bfd_boolean
4125 _bfd_score_elf_relocate_section (bfd *output_bfd,
4126 struct bfd_link_info *info,
4127 bfd *input_bfd,
4128 asection *input_section,
4129 bfd_byte *contents,
4130 Elf_Internal_Rela *relocs,
4131 Elf_Internal_Sym *local_syms,
4132 asection **local_sections)
4134 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4135 return s3_bfd_score_elf_relocate_section (output_bfd,
4136 info, input_bfd, input_section, contents, relocs,
4137 local_syms, local_sections);
4138 else
4139 return s7_bfd_score_elf_relocate_section (output_bfd,
4140 info, input_bfd, input_section, contents, relocs,
4141 local_syms, local_sections);
4144 static bfd_boolean
4145 _bfd_score_elf_check_relocs (bfd *abfd,
4146 struct bfd_link_info *info,
4147 asection *sec,
4148 const Elf_Internal_Rela *relocs)
4150 if (bfd_get_mach (abfd) == bfd_mach_score3)
4151 return s3_bfd_score_elf_check_relocs (abfd, info, sec, relocs);
4152 else
4153 return s7_bfd_score_elf_check_relocs (abfd, info, sec, relocs);
4156 static bfd_boolean
4157 _bfd_score_elf_add_symbol_hook (bfd *abfd,
4158 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4159 Elf_Internal_Sym *sym,
4160 const char **namep ATTRIBUTE_UNUSED,
4161 flagword *flagsp ATTRIBUTE_UNUSED,
4162 asection **secp,
4163 bfd_vma *valp)
4165 if (bfd_get_mach (abfd) == bfd_mach_score3)
4166 return s3_bfd_score_elf_add_symbol_hook (abfd, info, sym, namep, flagsp,
4167 secp, valp);
4168 else
4169 return s7_bfd_score_elf_add_symbol_hook (abfd, info, sym, namep, flagsp,
4170 secp, valp);
4173 static void
4174 _bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
4176 if (bfd_get_mach (abfd) == bfd_mach_score3)
4177 return s3_bfd_score_elf_symbol_processing (abfd, asym);
4178 else
4179 return s7_bfd_score_elf_symbol_processing (abfd, asym);
4182 static int
4183 _bfd_score_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4184 const char *name ATTRIBUTE_UNUSED,
4185 Elf_Internal_Sym *sym,
4186 asection *input_sec,
4187 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
4189 /* If link a empty .o, then this filed is NULL. */
4190 if (info->input_bfds == NULL)
4192 /* If we see a common symbol, which implies a relocatable link, then
4193 if a symbol was small common in an input file, mark it as small
4194 common in the output file. */
4195 if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
4196 sym->st_shndx = SHN_SCORE_SCOMMON;
4197 return 1;
4200 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4201 return s3_bfd_score_elf_link_output_symbol_hook (info, name, sym, input_sec, h);
4202 else
4203 return s7_bfd_score_elf_link_output_symbol_hook (info, name, sym, input_sec, h);
4206 static bfd_boolean
4207 _bfd_score_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4208 asection *sec,
4209 int *retval)
4211 if (bfd_get_mach (abfd) == bfd_mach_score3)
4212 return s3_bfd_score_elf_section_from_bfd_section (abfd, sec, retval);
4213 else
4214 return s7_bfd_score_elf_section_from_bfd_section (abfd, sec, retval);
4217 static bfd_boolean
4218 _bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4219 struct elf_link_hash_entry *h)
4221 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4222 return s3_bfd_score_elf_adjust_dynamic_symbol (info, h);
4223 else
4224 return s7_bfd_score_elf_adjust_dynamic_symbol (info, h);
4227 static bfd_boolean
4228 _bfd_score_elf_always_size_sections (bfd *output_bfd,
4229 struct bfd_link_info *info)
4231 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4232 return s3_bfd_score_elf_always_size_sections (output_bfd, info);
4233 else
4234 return s7_bfd_score_elf_always_size_sections (output_bfd, info);
4237 static bfd_boolean
4238 _bfd_score_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4240 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4241 return s3_bfd_score_elf_size_dynamic_sections (output_bfd, info);
4242 else
4243 return s7_bfd_score_elf_size_dynamic_sections (output_bfd, info);
4246 static bfd_boolean
4247 _bfd_score_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4249 if (bfd_get_mach (abfd) == bfd_mach_score3)
4250 return s3_bfd_score_elf_create_dynamic_sections (abfd, info);
4251 else
4252 return s7_bfd_score_elf_create_dynamic_sections (abfd, info);
4255 static bfd_boolean
4256 _bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
4257 struct bfd_link_info *info,
4258 struct elf_link_hash_entry *h,
4259 Elf_Internal_Sym *sym)
4261 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4262 return s3_bfd_score_elf_finish_dynamic_symbol (output_bfd, info, h, sym);
4263 else
4264 return s7_bfd_score_elf_finish_dynamic_symbol (output_bfd, info, h, sym);
4267 static bfd_boolean
4268 _bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
4269 struct bfd_link_info *info)
4271 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4272 return s3_bfd_score_elf_finish_dynamic_sections (output_bfd, info);
4273 else
4274 return s7_bfd_score_elf_finish_dynamic_sections (output_bfd, info);
4277 static bfd_boolean
4278 _bfd_score_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
4279 Elf_Internal_Shdr *hdr,
4280 asection *sec)
4282 if (bfd_get_mach (abfd) == bfd_mach_score3)
4283 return s3_bfd_score_elf_fake_sections (abfd, hdr, sec);
4284 else
4285 return s7_bfd_score_elf_fake_sections (abfd, hdr, sec);
4288 static bfd_boolean
4289 _bfd_score_elf_section_processing (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *hdr)
4291 if (bfd_get_mach (abfd) == bfd_mach_score3)
4292 return s3_bfd_score_elf_section_processing (abfd, hdr);
4293 else
4294 return s7_bfd_score_elf_section_processing (abfd, hdr);
4297 static bfd_boolean
4298 _bfd_score_elf_write_section (bfd *output_bfd,
4299 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
4300 asection *sec, bfd_byte *contents)
4302 if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4303 return s3_bfd_score_elf_write_section (output_bfd, sec, contents);
4304 else
4305 return s7_bfd_score_elf_write_section (output_bfd, sec, contents);
4308 static void
4309 _bfd_score_elf_copy_indirect_symbol (struct bfd_link_info *info,
4310 struct elf_link_hash_entry *dir,
4311 struct elf_link_hash_entry *ind)
4313 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4314 return s3_bfd_score_elf_copy_indirect_symbol (info, dir, ind);
4315 else
4316 return s7_bfd_score_elf_copy_indirect_symbol (info, dir, ind);
4319 static void
4320 _bfd_score_elf_hide_symbol (struct bfd_link_info *info,
4321 struct elf_link_hash_entry *entry,
4322 bfd_boolean force_local)
4324 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4325 return s3_bfd_score_elf_hide_symbol (info, entry, force_local);
4326 else
4327 return s7_bfd_score_elf_hide_symbol (info, entry, force_local);
4330 static bfd_boolean
4331 _bfd_score_elf_discard_info (bfd *abfd, struct elf_reloc_cookie *cookie,
4332 struct bfd_link_info *info)
4334 if (bfd_get_mach (abfd) == bfd_mach_score3)
4335 return s3_bfd_score_elf_discard_info (abfd, cookie, info);
4336 else
4337 return s7_bfd_score_elf_discard_info (abfd, cookie, info);
4340 static bfd_boolean
4341 _bfd_score_elf_ignore_discarded_relocs (asection *sec)
4343 if (bfd_get_mach (sec->owner) == bfd_mach_score3)
4344 return s3_bfd_score_elf_ignore_discarded_relocs (sec);
4345 else
4346 return s7_bfd_score_elf_ignore_discarded_relocs (sec);
4349 static asection *
4350 _bfd_score_elf_gc_mark_hook (asection *sec,
4351 struct bfd_link_info *info,
4352 Elf_Internal_Rela *rel,
4353 struct elf_link_hash_entry *h,
4354 Elf_Internal_Sym *sym)
4356 if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4357 return s3_bfd_score_elf_gc_mark_hook (sec, info, rel, h, sym);
4358 else
4359 return s7_bfd_score_elf_gc_mark_hook (sec, info, rel, h, sym);
4362 static bfd_boolean
4363 _bfd_score_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4365 if (bfd_get_mach (abfd) == bfd_mach_score3)
4366 return s3_bfd_score_elf_grok_prstatus (abfd, note);
4367 else
4368 return s7_bfd_score_elf_grok_prstatus (abfd, note);
4371 static bfd_boolean
4372 _bfd_score_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4374 if (bfd_get_mach (abfd) == bfd_mach_score3)
4375 return s3_bfd_score_elf_grok_psinfo (abfd, note);
4376 else
4377 return s7_bfd_score_elf_grok_psinfo (abfd, note);
4380 static reloc_howto_type *
4381 elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
4383 /* s3: NOTE!!!
4384 gas will call elf32_score_reloc_type_lookup, and don't write elf file.
4385 So just using score3, but we don't know ld will call this or not.
4386 If so, this way can't work. */
4388 if (score3)
4389 return s3_elf32_score_reloc_type_lookup (abfd, code);
4390 else
4391 return s7_elf32_score_reloc_type_lookup (abfd, code);
4394 static struct bfd_link_hash_table *
4395 elf32_score_link_hash_table_create (bfd *abfd)
4397 if (bfd_get_mach (abfd) == bfd_mach_score3)
4398 return s3_elf32_score_link_hash_table_create (abfd);
4399 else
4400 return s7_elf32_score_link_hash_table_create (abfd);
4403 static bfd_boolean
4404 elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
4406 if (bfd_get_mach (abfd) == bfd_mach_score3)
4407 return s3_elf32_score_print_private_bfd_data (abfd, ptr);
4408 else
4409 return s7_elf32_score_print_private_bfd_data (abfd, ptr);
4412 static bfd_boolean
4413 elf32_score_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4415 if (bfd_get_mach (obfd) == bfd_mach_score3)
4416 return s3_elf32_score_merge_private_bfd_data (ibfd, obfd);
4417 else
4418 return s7_elf32_score_merge_private_bfd_data (ibfd, obfd);
4421 static bfd_boolean
4422 elf32_score_new_section_hook (bfd *abfd, asection *sec)
4424 if (bfd_get_mach (abfd) == bfd_mach_score3)
4425 return s3_elf32_score_new_section_hook (abfd, sec);
4426 else
4427 return s7_elf32_score_new_section_hook (abfd, sec);
4431 /* s3_s7: don't need to split. */
4433 /* Set the right machine number. */
4434 static bfd_boolean
4435 _bfd_score_elf_score_object_p (bfd * abfd)
4437 int e_set = bfd_mach_score7;
4439 if (elf_elfheader (abfd)->e_machine == EM_SCORE)
4441 int e_mach = elf_elfheader (abfd)->e_flags & EF_SCORE_MACH & EF_OMIT_PIC_FIXDD;
4442 switch (e_mach)
4444 /* Set default target is score7. */
4445 default:
4446 case E_SCORE_MACH_SCORE7:
4447 e_set = bfd_mach_score7;
4448 break;
4450 case E_SCORE_MACH_SCORE3:
4451 e_set = bfd_mach_score3;
4452 break;
4456 return bfd_default_set_arch_mach (abfd, bfd_arch_score, e_set);
4459 bfd_boolean
4460 _bfd_score_elf_common_definition (Elf_Internal_Sym *sym)
4462 return (sym->st_shndx == SHN_COMMON || sym->st_shndx == SHN_SCORE_SCOMMON);
4465 /*****************************************************************************/
4468 #define USE_REL 1
4469 #define TARGET_LITTLE_SYM bfd_elf32_littlescore_vec
4470 #define TARGET_LITTLE_NAME "elf32-littlescore"
4471 #define TARGET_BIG_SYM bfd_elf32_bigscore_vec
4472 #define TARGET_BIG_NAME "elf32-bigscore"
4473 #define ELF_ARCH bfd_arch_score
4474 #define ELF_MACHINE_CODE EM_SCORE
4475 #define ELF_MACHINE_ALT1 EM_SCORE_OLD
4476 #define ELF_MAXPAGESIZE 0x8000
4478 #define elf_info_to_howto 0
4479 #define elf_info_to_howto_rel _bfd_score_info_to_howto
4480 #define elf_backend_relocate_section _bfd_score_elf_relocate_section
4481 #define elf_backend_check_relocs _bfd_score_elf_check_relocs
4482 #define elf_backend_add_symbol_hook _bfd_score_elf_add_symbol_hook
4483 #define elf_backend_symbol_processing _bfd_score_elf_symbol_processing
4484 #define elf_backend_link_output_symbol_hook \
4485 _bfd_score_elf_link_output_symbol_hook
4486 #define elf_backend_section_from_bfd_section \
4487 _bfd_score_elf_section_from_bfd_section
4488 #define elf_backend_adjust_dynamic_symbol \
4489 _bfd_score_elf_adjust_dynamic_symbol
4490 #define elf_backend_always_size_sections \
4491 _bfd_score_elf_always_size_sections
4492 #define elf_backend_size_dynamic_sections \
4493 _bfd_score_elf_size_dynamic_sections
4494 #define elf_backend_omit_section_dynsym \
4495 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
4496 #define elf_backend_create_dynamic_sections \
4497 _bfd_score_elf_create_dynamic_sections
4498 #define elf_backend_finish_dynamic_symbol \
4499 _bfd_score_elf_finish_dynamic_symbol
4500 #define elf_backend_finish_dynamic_sections \
4501 _bfd_score_elf_finish_dynamic_sections
4502 #define elf_backend_fake_sections _bfd_score_elf_fake_sections
4503 #define elf_backend_section_processing _bfd_score_elf_section_processing
4504 #define elf_backend_write_section _bfd_score_elf_write_section
4505 #define elf_backend_copy_indirect_symbol _bfd_score_elf_copy_indirect_symbol
4506 #define elf_backend_hide_symbol _bfd_score_elf_hide_symbol
4507 #define elf_backend_discard_info _bfd_score_elf_discard_info
4508 #define elf_backend_ignore_discarded_relocs \
4509 _bfd_score_elf_ignore_discarded_relocs
4510 #define elf_backend_gc_mark_hook _bfd_score_elf_gc_mark_hook
4511 #define elf_backend_grok_prstatus _bfd_score_elf_grok_prstatus
4512 #define elf_backend_grok_psinfo _bfd_score_elf_grok_psinfo
4513 #define elf_backend_can_gc_sections 1
4514 #define elf_backend_want_plt_sym 0
4515 #define elf_backend_got_header_size (4 * SCORE_RESERVED_GOTNO)
4516 #define elf_backend_plt_header_size 0
4517 #define elf_backend_collect TRUE
4518 #define elf_backend_type_change_ok TRUE
4519 #define elf_backend_object_p _bfd_score_elf_score_object_p
4521 #define bfd_elf32_bfd_reloc_type_lookup elf32_score_reloc_type_lookup
4522 #define bfd_elf32_bfd_reloc_name_lookup \
4523 elf32_score_reloc_name_lookup
4524 #define bfd_elf32_bfd_link_hash_table_create elf32_score_link_hash_table_create
4525 #define bfd_elf32_bfd_print_private_bfd_data elf32_score_print_private_bfd_data
4526 #define bfd_elf32_bfd_merge_private_bfd_data elf32_score_merge_private_bfd_data
4527 #define bfd_elf32_new_section_hook elf32_score_new_section_hook
4529 #include "elf32-target.h"