1 /* 32-bit ELF support for S+core.
2 Copyright 2006, 2007 Free Software Foundation, Inc.
4 Mei Ligang (ligang@sunnorth.com.cn)
5 Pei-Lin Tsai (pltsai@sunplus.com)
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
27 #include "libiberty.h"
29 #include "elf/score.h"
30 #include "elf/common.h"
31 #include "elf/internal.h"
35 /* Score ELF linker hash table. */
37 struct score_elf_link_hash_table
39 /* The main hash table. */
40 struct elf_link_hash_table root
;
43 /* The SCORE ELF linker needs additional information for each symbol in
44 the global hash table. */
46 struct score_elf_link_hash_entry
48 struct elf_link_hash_entry root
;
50 /* Number of R_SCORE_ABS32, R_SCORE_REL32 relocs against this symbol. */
51 unsigned int possibly_dynamic_relocs
;
53 /* If the R_SCORE_ABS32, R_SCORE_REL32 reloc is against a readonly section. */
54 bfd_boolean readonly_reloc
;
56 /* We must not create a stub for a symbol that has relocations related to
57 taking the function's address, i.e. any but R_SCORE_CALL15 ones. */
58 bfd_boolean no_fn_stub
;
60 /* Are we forced local? This will only be set if we have converted
61 the initial global GOT entry to a local GOT entry. */
62 bfd_boolean forced_local
;
65 /* Traverse a score ELF linker hash table. */
66 #define score_elf_link_hash_traverse(table, func, info) \
67 (elf_link_hash_traverse \
69 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
72 /* Get the SCORE elf linker hash table from a link_info structure. */
73 #define score_elf_hash_table(info) \
74 ((struct score_elf_link_hash_table *) ((info)->hash))
76 /* This structure is used to hold .got entries while estimating got sizes. */
77 struct score_got_entry
79 /* The input bfd in which the symbol is defined. */
81 /* The index of the symbol, as stored in the relocation r_info, if
82 we have a local symbol; -1 otherwise. */
86 /* If abfd == NULL, an address that must be stored in the got. */
88 /* If abfd != NULL && symndx != -1, the addend of the relocation
89 that should be added to the symbol value. */
91 /* If abfd != NULL && symndx == -1, the hash table entry
92 corresponding to a global symbol in the got (or, local, if
94 struct score_elf_link_hash_entry
*h
;
97 /* The offset from the beginning of the .got section to the entry
98 corresponding to this symbol+addend. If it's a global symbol
99 whose offset is yet to be decided, it's going to be -1. */
103 /* This structure is passed to score_elf_sort_hash_table_f when sorting
104 the dynamic symbols. */
106 struct score_elf_hash_sort_data
108 /* The symbol in the global GOT with the lowest dynamic symbol table index. */
109 struct elf_link_hash_entry
*low
;
110 /* The least dynamic symbol table index corresponding to a symbol with a GOT entry. */
111 long min_got_dynindx
;
112 /* The greatest dynamic symbol table index corresponding to a symbol
113 with a GOT entry that is not referenced (e.g., a dynamic symbol
114 with dynamic relocations pointing to it from non-primary GOTs). */
115 long max_unref_got_dynindx
;
116 /* The greatest dynamic symbol table index not corresponding to a
117 symbol without a GOT entry. */
118 long max_non_got_dynindx
;
121 struct score_got_info
123 /* The global symbol in the GOT with the lowest index in the dynamic
125 struct elf_link_hash_entry
*global_gotsym
;
126 /* The number of global .got entries. */
127 unsigned int global_gotno
;
128 /* The number of local .got entries. */
129 unsigned int local_gotno
;
130 /* The number of local .got entries we have used. */
131 unsigned int assigned_gotno
;
132 /* A hash table holding members of the got. */
133 struct htab
*got_entries
;
134 /* In multi-got links, a pointer to the next got (err, rather, most
135 of the time, it points to the previous got). */
136 struct score_got_info
*next
;
139 /* A structure used to count GOT entries, for GOT entry or ELF symbol table traversal. */
140 struct _score_elf_section_data
142 struct bfd_elf_section_data elf
;
145 struct score_got_info
*got_info
;
151 #define score_elf_section_data(sec) \
152 ((struct _score_elf_section_data *) elf_section_data (sec))
154 /* The size of a symbol-table entry. */
155 #define SCORE_ELF_SYM_SIZE(abfd) \
156 (get_elf_backend_data (abfd)->s->sizeof_sym)
158 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
159 from smaller values. Start with zero, widen, *then* decrement. */
160 #define MINUS_ONE (((bfd_vma)0) - 1)
161 #define MINUS_TWO (((bfd_vma)0) - 2)
166 /* The number of local .got entries we reserve. */
167 #define SCORE_RESERVED_GOTNO (2)
168 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
170 /* The offset of $gp from the beginning of the .got section. */
171 #define ELF_SCORE_GP_OFFSET(abfd) (0x3ff0)
172 /* The maximum size of the GOT for it to be addressable using 15-bit offsets from $gp. */
173 #define SCORE_ELF_GOT_MAX_SIZE(abfd) (ELF_SCORE_GP_OFFSET(abfd) + 0x3fff)
175 #define SCORE_ELF_STUB_SECTION_NAME (".SCORE.stub")
176 #define SCORE_FUNCTION_STUB_SIZE (16)
178 #define STUB_LW 0xc3bcc010 /* lw r29, [r28, -0x3ff0] */
179 #define STUB_MOVE 0x8363bc56 /* mv r27, r3 */
180 #define STUB_LI16 0x87548000 /* ori r26, .dynsym_index */
181 #define STUB_BRL 0x801dbc09 /* brl r29 */
183 #define SCORE_ELF_GOT_SIZE(abfd) \
184 (get_elf_backend_data (abfd)->s->arch_size / 8)
186 #define SCORE_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
187 (_bfd_elf_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
189 /* The size of an external dynamic table entry. */
190 #define SCORE_ELF_DYN_SIZE(abfd) \
191 (get_elf_backend_data (abfd)->s->sizeof_dyn)
193 /* The size of an external REL relocation. */
194 #define SCORE_ELF_REL_SIZE(abfd) \
195 (get_elf_backend_data (abfd)->s->sizeof_rel)
197 /* The default alignment for sections, as a power of two. */
198 #define SCORE_ELF_LOG_FILE_ALIGN(abfd)\
199 (get_elf_backend_data (abfd)->s->log_file_align)
202 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
205 static bfd_byte
*hi16_rel_addr
;
207 /* This will be used when we sort the dynamic relocation records. */
208 static bfd
*reldyn_sorting_bfd
;
210 /* SCORE ELF uses two common sections. One is the usual one, and the
211 other is for small objects. All the small objects are kept
212 together, and then referenced via the gp pointer, which yields
213 faster assembler code. This is what we use for the small common
214 section. This approach is copied from ecoff.c. */
215 static asection score_elf_scom_section
;
216 static asymbol score_elf_scom_symbol
;
217 static asymbol
*score_elf_scom_symbol_ptr
;
219 static bfd_reloc_status_type
220 score_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
221 arelent
*reloc_entry
,
222 asymbol
*symbol ATTRIBUTE_UNUSED
,
224 asection
*input_section ATTRIBUTE_UNUSED
,
225 bfd
*output_bfd ATTRIBUTE_UNUSED
,
226 char **error_message ATTRIBUTE_UNUSED
)
228 hi16_rel_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
232 static bfd_reloc_status_type
233 score_elf_lo16_reloc (bfd
*abfd
,
234 arelent
*reloc_entry
,
235 asymbol
*symbol ATTRIBUTE_UNUSED
,
237 asection
*input_section
,
238 bfd
*output_bfd ATTRIBUTE_UNUSED
,
239 char **error_message ATTRIBUTE_UNUSED
)
241 bfd_vma addend
= 0, offset
= 0;
243 unsigned long hi16_offset
, hi16_value
, uvalue
;
245 hi16_value
= bfd_get_32 (abfd
, hi16_rel_addr
);
246 hi16_offset
= ((((hi16_value
>> 16) & 0x3) << 15) | (hi16_value
& 0x7fff)) >> 1;
247 addend
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
248 offset
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
249 val
= reloc_entry
->addend
;
250 if (reloc_entry
->address
> input_section
->size
)
251 return bfd_reloc_outofrange
;
252 uvalue
= ((hi16_offset
<< 16) | (offset
& 0xffff)) + val
;
253 hi16_offset
= (uvalue
>> 16) << 1;
254 hi16_value
= (hi16_value
& ~0x37fff) | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
255 bfd_put_32 (abfd
, hi16_value
, hi16_rel_addr
);
256 offset
= (uvalue
& 0xffff) << 1;
257 addend
= (addend
& ~0x37fff) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
258 bfd_put_32 (abfd
, addend
, (bfd_byte
*) data
+ reloc_entry
->address
);
262 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
263 dangerous relocation. */
266 score_elf_assign_gp (bfd
*output_bfd
, bfd_vma
*pgp
)
272 /* If we've already figured out what GP will be, just return it. */
273 *pgp
= _bfd_get_gp_value (output_bfd
);
277 count
= bfd_get_symcount (output_bfd
);
278 sym
= bfd_get_outsymbols (output_bfd
);
280 /* The linker script will have created a symbol named `_gp' with the
281 appropriate value. */
286 for (i
= 0; i
< count
; i
++, sym
++)
290 name
= bfd_asymbol_name (*sym
);
291 if (*name
== '_' && strcmp (name
, "_gp") == 0)
293 *pgp
= bfd_asymbol_value (*sym
);
294 _bfd_set_gp_value (output_bfd
, *pgp
);
302 /* Only get the error once. */
304 _bfd_set_gp_value (output_bfd
, *pgp
);
311 /* We have to figure out the gp value, so that we can adjust the
312 symbol value correctly. We look up the symbol _gp in the output
313 BFD. If we can't find it, we're stuck. We cache it in the ELF
314 target data. We don't need to adjust the symbol value for an
315 external symbol if we are producing relocatable output. */
317 static bfd_reloc_status_type
318 score_elf_final_gp (bfd
*output_bfd
,
320 bfd_boolean relocatable
,
321 char **error_message
,
324 if (bfd_is_und_section (symbol
->section
)
328 return bfd_reloc_undefined
;
331 *pgp
= _bfd_get_gp_value (output_bfd
);
334 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
338 /* Make up a value. */
339 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
340 _bfd_set_gp_value (output_bfd
, *pgp
);
342 else if (!score_elf_assign_gp (output_bfd
, pgp
))
345 (char *) _("GP relative relocation when _gp not defined");
346 return bfd_reloc_dangerous
;
353 static bfd_reloc_status_type
354 score_elf_gprel15_with_gp (bfd
*abfd
,
356 arelent
*reloc_entry
,
357 asection
*input_section
,
358 bfd_boolean relocateable
,
360 bfd_vma gp ATTRIBUTE_UNUSED
)
365 if (bfd_is_com_section (symbol
->section
))
368 relocation
= symbol
->value
;
370 relocation
+= symbol
->section
->output_section
->vma
;
371 relocation
+= symbol
->section
->output_offset
;
372 if (reloc_entry
->address
> input_section
->size
)
373 return bfd_reloc_outofrange
;
375 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
376 if (((reloc_entry
->addend
& 0xffffc000) != 0)
377 && ((reloc_entry
->addend
& 0xffffc000) != 0xffffc000))
378 return bfd_reloc_overflow
;
380 insn
= (insn
& ~0x7fff) | (reloc_entry
->addend
& 0x7fff);
381 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
383 reloc_entry
->address
+= input_section
->output_offset
;
388 static bfd_reloc_status_type
389 gprel32_with_gp (bfd
*abfd
, asymbol
*symbol
, arelent
*reloc_entry
,
390 asection
*input_section
, bfd_boolean relocatable
,
391 void *data
, bfd_vma gp
)
396 if (bfd_is_com_section (symbol
->section
))
399 relocation
= symbol
->value
;
401 relocation
+= symbol
->section
->output_section
->vma
;
402 relocation
+= symbol
->section
->output_offset
;
404 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
405 return bfd_reloc_outofrange
;
407 /* Set val to the offset into the section or symbol. */
408 val
= reloc_entry
->addend
;
410 if (reloc_entry
->howto
->partial_inplace
)
411 val
+= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
413 /* Adjust val for the final section location and GP value. If we
414 are producing relocatable output, we don't want to do this for
415 an external symbol. */
417 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
418 val
+= relocation
- gp
;
420 if (reloc_entry
->howto
->partial_inplace
)
421 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
423 reloc_entry
->addend
= val
;
426 reloc_entry
->address
+= input_section
->output_offset
;
431 static bfd_reloc_status_type
432 score_elf_gprel15_reloc (bfd
*abfd
,
433 arelent
*reloc_entry
,
436 asection
*input_section
,
438 char **error_message
)
440 bfd_boolean relocateable
;
441 bfd_reloc_status_type ret
;
444 if (output_bfd
!= (bfd
*) NULL
445 && (symbol
->flags
& BSF_SECTION_SYM
) == 0 && reloc_entry
->addend
== 0)
447 reloc_entry
->address
+= input_section
->output_offset
;
450 if (output_bfd
!= (bfd
*) NULL
)
454 relocateable
= FALSE
;
455 output_bfd
= symbol
->section
->output_section
->owner
;
458 ret
= score_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, &gp
);
459 if (ret
!= bfd_reloc_ok
)
462 return score_elf_gprel15_with_gp (abfd
, symbol
, reloc_entry
,
463 input_section
, relocateable
, data
, gp
);
466 /* Do a R_SCORE_GPREL32 relocation. This is a 32 bit value which must
467 become the offset from the gp register. */
469 static bfd_reloc_status_type
470 score_elf_gprel32_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
471 void *data
, asection
*input_section
, bfd
*output_bfd
,
472 char **error_message
)
474 bfd_boolean relocatable
;
475 bfd_reloc_status_type ret
;
478 /* R_SCORE_GPREL32 relocations are defined for local symbols only. */
479 if (output_bfd
!= NULL
480 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
481 && (symbol
->flags
& BSF_LOCAL
) != 0)
483 *error_message
= (char *)
484 _("32bits gp relative relocation occurs for an external symbol");
485 return bfd_reloc_outofrange
;
488 if (output_bfd
!= NULL
)
493 output_bfd
= symbol
->section
->output_section
->owner
;
496 ret
= score_elf_final_gp (output_bfd
, symbol
, relocatable
, error_message
, &gp
);
497 if (ret
!= bfd_reloc_ok
)
501 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
502 relocatable
, data
, gp
);
505 /* A howto special_function for R_SCORE_GOT15 relocations. This is just
506 like any other 16-bit relocation when applied to global symbols, but is
507 treated in the same as R_SCORE_HI16 when applied to local symbols. */
509 static bfd_reloc_status_type
510 score_elf_got15_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
511 void *data
, asection
*input_section
,
512 bfd
*output_bfd
, char **error_message
)
514 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
515 || bfd_is_und_section (bfd_get_section (symbol
))
516 || bfd_is_com_section (bfd_get_section (symbol
)))
517 /* The relocation is against a global symbol. */
518 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
519 input_section
, output_bfd
,
522 return score_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
523 input_section
, output_bfd
, error_message
);
526 static bfd_reloc_status_type
527 score_elf_got_lo16_reloc (bfd
*abfd
,
528 arelent
*reloc_entry
,
529 asymbol
*symbol ATTRIBUTE_UNUSED
,
531 asection
*input_section
,
532 bfd
*output_bfd ATTRIBUTE_UNUSED
,
533 char **error_message ATTRIBUTE_UNUSED
)
535 bfd_vma addend
= 0, offset
= 0;
537 signed long hi16_offset
, hi16_value
, uvalue
;
539 hi16_value
= bfd_get_32 (abfd
, hi16_rel_addr
);
540 hi16_offset
= ((((hi16_value
>> 16) & 0x3) << 15) | (hi16_value
& 0x7fff)) >> 1;
541 addend
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
542 offset
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
543 val
= reloc_entry
->addend
;
544 if (reloc_entry
->address
> input_section
->size
)
545 return bfd_reloc_outofrange
;
546 uvalue
= ((hi16_offset
<< 16) | (offset
& 0xffff)) + val
;
547 if ((uvalue
> -0x8000) && (uvalue
< 0x7fff))
550 hi16_offset
= (uvalue
>> 16) & 0x7fff;
551 hi16_value
= (hi16_value
& ~0x37fff) | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
552 bfd_put_32 (abfd
, hi16_value
, hi16_rel_addr
);
553 offset
= (uvalue
& 0xffff) << 1;
554 addend
= (addend
& ~0x37fff) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
555 bfd_put_32 (abfd
, addend
, (bfd_byte
*) data
+ reloc_entry
->address
);
559 static reloc_howto_type elf32_score_howto_table
[] =
562 HOWTO (R_SCORE_NONE
, /* type */
564 0, /* size (0 = byte, 1 = short, 2 = long) */
566 FALSE
, /* pc_relative */
568 complain_overflow_dont
,/* complain_on_overflow */
569 bfd_elf_generic_reloc
, /* special_function */
570 "R_SCORE_NONE", /* name */
571 FALSE
, /* partial_inplace */
574 FALSE
), /* pcrel_offset */
577 HOWTO (R_SCORE_HI16
, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 FALSE
, /* pc_relative */
583 complain_overflow_dont
,/* complain_on_overflow */
584 score_elf_hi16_reloc
, /* special_function */
585 "R_SCORE_HI16", /* name */
586 TRUE
, /* partial_inplace */
587 0x37fff, /* src_mask */
588 0x37fff, /* dst_mask */
589 FALSE
), /* pcrel_offset */
592 HOWTO (R_SCORE_LO16
, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 FALSE
, /* pc_relative */
598 complain_overflow_dont
,/* complain_on_overflow */
599 score_elf_lo16_reloc
, /* special_function */
600 "R_SCORE_LO16", /* name */
601 TRUE
, /* partial_inplace */
602 0x37fff, /* src_mask */
603 0x37fff, /* dst_mask */
604 FALSE
), /* pcrel_offset */
607 HOWTO (R_SCORE_DUMMY1
, /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 FALSE
, /* pc_relative */
613 complain_overflow_dont
,/* complain_on_overflow */
614 bfd_elf_generic_reloc
, /* special_function */
615 "R_SCORE_DUMMY1", /* name */
616 TRUE
, /* partial_inplace */
617 0x0000ffff, /* src_mask */
618 0x0000ffff, /* dst_mask */
619 FALSE
), /* pcrel_offset */
622 HOWTO (R_SCORE_24
, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 FALSE
, /* pc_relative */
628 complain_overflow_dont
,/* complain_on_overflow */
629 bfd_elf_generic_reloc
, /* special_function */
630 "R_SCORE_24", /* name */
631 FALSE
, /* partial_inplace */
632 0x3ff7fff, /* src_mask */
633 0x3ff7fff, /* dst_mask */
634 FALSE
), /* pcrel_offset */
637 HOWTO (R_SCORE_PC19
, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 TRUE
, /* pc_relative */
643 complain_overflow_dont
,/* complain_on_overflow */
644 bfd_elf_generic_reloc
, /* special_function */
645 "R_SCORE_PC19", /* name */
646 FALSE
, /* partial_inplace */
647 0x3ff03fe, /* src_mask */
648 0x3ff03fe, /* dst_mask */
649 FALSE
), /* pcrel_offset */
652 HOWTO (R_SCORE16_11
, /* type */
654 1, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE
, /* pc_relative */
658 complain_overflow_dont
,/* complain_on_overflow */
659 bfd_elf_generic_reloc
, /* special_function */
660 "R_SCORE16_11", /* name */
661 FALSE
, /* partial_inplace */
662 0x000000ffe, /* src_mask */
663 0x000000ffe, /* dst_mask */
664 FALSE
), /* pcrel_offset */
667 HOWTO (R_SCORE16_PC8
, /* type */
669 1, /* size (0 = byte, 1 = short, 2 = long) */
671 TRUE
, /* pc_relative */
673 complain_overflow_dont
,/* complain_on_overflow */
674 bfd_elf_generic_reloc
, /* special_function */
675 "R_SCORE16_PC8", /* name */
676 FALSE
, /* partial_inplace */
677 0x000000ff, /* src_mask */
678 0x000000ff, /* dst_mask */
679 FALSE
), /* pcrel_offset */
681 /* 32 bit absolute */
682 HOWTO (R_SCORE_ABS32
, /* type 8 */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE
, /* pc_relative */
688 complain_overflow_bitfield
, /* complain_on_overflow */
689 bfd_elf_generic_reloc
, /* special_function */
690 "R_SCORE_ABS32", /* name */
691 FALSE
, /* partial_inplace */
692 0xffffffff, /* src_mask */
693 0xffffffff, /* dst_mask */
694 FALSE
), /* pcrel_offset */
696 /* 16 bit absolute */
697 HOWTO (R_SCORE_ABS16
, /* type 11 */
699 1, /* size (0 = byte, 1 = short, 2 = long) */
701 FALSE
, /* pc_relative */
703 complain_overflow_bitfield
, /* complain_on_overflow */
704 bfd_elf_generic_reloc
, /* special_function */
705 "R_SCORE_ABS16", /* name */
706 FALSE
, /* partial_inplace */
707 0x0000ffff, /* src_mask */
708 0x0000ffff, /* dst_mask */
709 FALSE
), /* pcrel_offset */
712 HOWTO (R_SCORE_DUMMY2
, /* type */
714 2, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE
, /* pc_relative */
718 complain_overflow_dont
,/* complain_on_overflow */
719 bfd_elf_generic_reloc
, /* special_function */
720 "R_SCORE_DUMMY2", /* name */
721 TRUE
, /* partial_inplace */
722 0x00007fff, /* src_mask */
723 0x00007fff, /* dst_mask */
724 FALSE
), /* pcrel_offset */
727 HOWTO (R_SCORE_GP15
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_dont
,/* complain_on_overflow */
734 score_elf_gprel15_reloc
,/* special_function */
735 "R_SCORE_GP15", /* name */
736 TRUE
, /* partial_inplace */
737 0x00007fff, /* src_mask */
738 0x00007fff, /* dst_mask */
739 FALSE
), /* pcrel_offset */
741 /* GNU extension to record C++ vtable hierarchy. */
742 HOWTO (R_SCORE_GNU_VTINHERIT
, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE
, /* pc_relative */
748 complain_overflow_dont
,/* complain_on_overflow */
749 NULL
, /* special_function */
750 "R_SCORE_GNU_VTINHERIT", /* name */
751 FALSE
, /* partial_inplace */
754 FALSE
), /* pcrel_offset */
756 /* GNU extension to record C++ vtable member usage */
757 HOWTO (R_SCORE_GNU_VTENTRY
, /* type */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE
, /* pc_relative */
763 complain_overflow_dont
,/* complain_on_overflow */
764 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
765 "R_SCORE_GNU_VTENTRY", /* name */
766 FALSE
, /* partial_inplace */
769 FALSE
), /* pcrel_offset */
771 /* Reference to global offset table. */
772 HOWTO (R_SCORE_GOT15
, /* type */
774 2, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE
, /* pc_relative */
778 complain_overflow_signed
, /* complain_on_overflow */
779 score_elf_got15_reloc
, /* special_function */
780 "R_SCORE_GOT15", /* name */
781 TRUE
, /* partial_inplace */
782 0x00007fff, /* src_mask */
783 0x00007fff, /* dst_mask */
784 FALSE
), /* pcrel_offset */
786 /* Low 16 bits of displacement in global offset table. */
787 HOWTO (R_SCORE_GOT_LO16
, /* type */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE
, /* pc_relative */
793 complain_overflow_dont
,/* complain_on_overflow */
794 score_elf_got_lo16_reloc
, /* special_function */
795 "R_SCORE_GOT_LO16", /* name */
796 TRUE
, /* partial_inplace */
797 0x37ffe, /* src_mask */
798 0x37ffe, /* dst_mask */
799 FALSE
), /* pcrel_offset */
801 /* 15 bit call through global offset table. */
802 HOWTO (R_SCORE_CALL15
, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 FALSE
, /* pc_relative */
808 complain_overflow_signed
, /* complain_on_overflow */
809 bfd_elf_generic_reloc
, /* special_function */
810 "R_SCORE_CALL15", /* name */
811 TRUE
, /* partial_inplace */
812 0x0000ffff, /* src_mask */
813 0x0000ffff, /* dst_mask */
814 FALSE
), /* pcrel_offset */
816 /* 32 bit GP relative reference. */
817 HOWTO (R_SCORE_GPREL32
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 FALSE
, /* pc_relative */
823 complain_overflow_dont
,/* complain_on_overflow */
824 score_elf_gprel32_reloc
, /* special_function */
825 "R_SCORE_GPREL32", /* name */
826 TRUE
, /* partial_inplace */
827 0xffffffff, /* src_mask */
828 0xffffffff, /* dst_mask */
829 FALSE
), /* pcrel_offset */
831 /* 32 bit symbol relative relocation. */
832 HOWTO (R_SCORE_REL32
, /* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 FALSE
, /* pc_relative */
838 complain_overflow_dont
,/* complain_on_overflow */
839 bfd_elf_generic_reloc
, /* special_function */
840 "R_SCORE_REL32", /* name */
841 TRUE
, /* partial_inplace */
842 0xffffffff, /* src_mask */
843 0xffffffff, /* dst_mask */
844 FALSE
), /* pcrel_offset */
846 /* R_SCORE_DUMMY_HI16 */
847 HOWTO (R_SCORE_DUMMY_HI16
, /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 FALSE
, /* pc_relative */
853 complain_overflow_dont
,/* complain_on_overflow */
854 score_elf_hi16_reloc
, /* special_function */
855 "R_SCORE_DUMMY_HI16", /* name */
856 TRUE
, /* partial_inplace */
857 0x37fff, /* src_mask */
858 0x37fff, /* dst_mask */
859 FALSE
), /* pcrel_offset */
862 struct score_reloc_map
864 bfd_reloc_code_real_type bfd_reloc_val
;
865 unsigned char elf_reloc_val
;
868 static const struct score_reloc_map elf32_score_reloc_map
[] =
870 {BFD_RELOC_NONE
, R_SCORE_NONE
},
871 {BFD_RELOC_HI16_S
, R_SCORE_HI16
},
872 {BFD_RELOC_LO16
, R_SCORE_LO16
},
873 {BFD_RELOC_SCORE_DUMMY1
, R_SCORE_DUMMY1
},
874 {BFD_RELOC_SCORE_JMP
, R_SCORE_24
},
875 {BFD_RELOC_SCORE_BRANCH
, R_SCORE_PC19
},
876 {BFD_RELOC_SCORE16_JMP
, R_SCORE16_11
},
877 {BFD_RELOC_SCORE16_BRANCH
, R_SCORE16_PC8
},
878 {BFD_RELOC_32
, R_SCORE_ABS32
},
879 {BFD_RELOC_16
, R_SCORE_ABS16
},
880 {BFD_RELOC_SCORE_DUMMY2
, R_SCORE_DUMMY2
},
881 {BFD_RELOC_SCORE_GPREL15
, R_SCORE_GP15
},
882 {BFD_RELOC_VTABLE_INHERIT
, R_SCORE_GNU_VTINHERIT
},
883 {BFD_RELOC_VTABLE_ENTRY
, R_SCORE_GNU_VTENTRY
},
884 {BFD_RELOC_SCORE_GOT15
, R_SCORE_GOT15
},
885 {BFD_RELOC_SCORE_GOT_LO16
, R_SCORE_GOT_LO16
},
886 {BFD_RELOC_SCORE_CALL15
, R_SCORE_CALL15
},
887 {BFD_RELOC_GPREL32
, R_SCORE_GPREL32
},
888 {BFD_RELOC_32_PCREL
, R_SCORE_REL32
},
889 {BFD_RELOC_SCORE_DUMMY_HI16
, R_SCORE_DUMMY_HI16
},
892 /* got_entries only match if they're identical, except for gotidx, so
893 use all fields to compute the hash, and compare the appropriate
897 score_elf_got_entry_hash (const void *entry_
)
899 const struct score_got_entry
*entry
= (struct score_got_entry
*)entry_
;
902 + (!entry
->abfd
? entry
->d
.address
: entry
->abfd
->id
);
906 score_elf_got_entry_eq (const void *entry1
, const void *entry2
)
908 const struct score_got_entry
*e1
= (struct score_got_entry
*)entry1
;
909 const struct score_got_entry
*e2
= (struct score_got_entry
*)entry2
;
911 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
912 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
913 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
914 : e1
->d
.h
== e2
->d
.h
);
917 /* If H needs a GOT entry, assign it the highest available dynamic
918 index. Otherwise, assign it the lowest available dynamic
922 score_elf_sort_hash_table_f (struct score_elf_link_hash_entry
*h
, void *data
)
924 struct score_elf_hash_sort_data
*hsd
= data
;
926 if (h
->root
.root
.type
== bfd_link_hash_warning
)
927 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
929 /* Symbols without dynamic symbol table entries aren't interesting at all. */
930 if (h
->root
.dynindx
== -1)
933 /* Global symbols that need GOT entries that are not explicitly
934 referenced are marked with got offset 2. Those that are
935 referenced get a 1, and those that don't need GOT entries get
937 if (h
->root
.got
.offset
== 2)
939 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
940 hsd
->low
= (struct elf_link_hash_entry
*) h
;
941 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
943 else if (h
->root
.got
.offset
!= 1)
944 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
947 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
948 hsd
->low
= (struct elf_link_hash_entry
*) h
;
955 score_elf_got_section (bfd
*abfd
, bfd_boolean maybe_excluded
)
957 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
959 if (sgot
== NULL
|| (! maybe_excluded
&& (sgot
->flags
& SEC_EXCLUDE
) != 0))
964 /* Returns the GOT information associated with the link indicated by
965 INFO. If SGOTP is non-NULL, it is filled in with the GOT section. */
967 static struct score_got_info
*
968 score_elf_got_info (bfd
*abfd
, asection
**sgotp
)
971 struct score_got_info
*g
;
973 sgot
= score_elf_got_section (abfd
, TRUE
);
974 BFD_ASSERT (sgot
!= NULL
);
975 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
976 g
= score_elf_section_data (sgot
)->u
.got_info
;
977 BFD_ASSERT (g
!= NULL
);
984 /* Sort the dynamic symbol table so that symbols that need GOT entries
985 appear towards the end. This reduces the amount of GOT space
986 required. MAX_LOCAL is used to set the number of local symbols
987 known to be in the dynamic symbol table. During
988 _bfd_score_elf_size_dynamic_sections, this value is 1. Afterward, the
989 section symbols are added and the count is higher. */
992 score_elf_sort_hash_table (struct bfd_link_info
*info
,
993 unsigned long max_local
)
995 struct score_elf_hash_sort_data hsd
;
996 struct score_got_info
*g
;
999 dynobj
= elf_hash_table (info
)->dynobj
;
1001 g
= score_elf_got_info (dynobj
, NULL
);
1004 hsd
.max_unref_got_dynindx
=
1005 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
1006 /* In the multi-got case, assigned_gotno of the master got_info
1007 indicate the number of entries that aren't referenced in the
1008 primary GOT, but that must have entries because there are
1009 dynamic relocations that reference it. Since they aren't
1010 referenced, we move them to the end of the GOT, so that they
1011 don't prevent other entries that are referenced from getting
1012 too large offsets. */
1013 - (g
->next
? g
->assigned_gotno
: 0);
1014 hsd
.max_non_got_dynindx
= max_local
;
1015 score_elf_link_hash_traverse (((struct score_elf_link_hash_table
*)
1016 elf_hash_table (info
)),
1017 score_elf_sort_hash_table_f
,
1020 /* There should have been enough room in the symbol table to
1021 accommodate both the GOT and non-GOT symbols. */
1022 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1023 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
1024 <= elf_hash_table (info
)->dynsymcount
);
1026 /* Now we know which dynamic symbol has the lowest dynamic symbol
1027 table index in the GOT. */
1028 g
->global_gotsym
= hsd
.low
;
1033 /* Create an entry in an score ELF linker hash table. */
1035 static struct bfd_hash_entry
*
1036 score_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1037 struct bfd_hash_table
*table
,
1040 struct score_elf_link_hash_entry
*ret
= (struct score_elf_link_hash_entry
*)entry
;
1042 /* Allocate the structure if it has not already been allocated by a subclass. */
1044 ret
= bfd_hash_allocate (table
, sizeof (struct score_elf_link_hash_entry
));
1046 return (struct bfd_hash_entry
*)ret
;
1048 /* Call the allocation method of the superclass. */
1049 ret
= ((struct score_elf_link_hash_entry
*)
1050 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*)ret
, table
, string
));
1054 ret
->possibly_dynamic_relocs
= 0;
1055 ret
->readonly_reloc
= FALSE
;
1056 ret
->no_fn_stub
= FALSE
;
1057 ret
->forced_local
= FALSE
;
1060 return (struct bfd_hash_entry
*)ret
;
1063 /* Returns the first relocation of type r_type found, beginning with
1064 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1066 static const Elf_Internal_Rela
*
1067 score_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
1068 const Elf_Internal_Rela
*relocation
,
1069 const Elf_Internal_Rela
*relend
)
1071 while (relocation
< relend
)
1073 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
1079 /* We didn't find it. */
1080 bfd_set_error (bfd_error_bad_value
);
1084 /* This function is called via qsort() to sort the dynamic relocation
1085 entries by increasing r_symndx value. */
1088 score_elf_sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1090 Elf_Internal_Rela int_reloc1
;
1091 Elf_Internal_Rela int_reloc2
;
1093 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1094 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1096 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
1099 /* Return whether a relocation is against a local symbol. */
1102 score_elf_local_relocation_p (bfd
*input_bfd
,
1103 const Elf_Internal_Rela
*relocation
,
1104 asection
**local_sections
,
1105 bfd_boolean check_forced
)
1107 unsigned long r_symndx
;
1108 Elf_Internal_Shdr
*symtab_hdr
;
1109 struct score_elf_link_hash_entry
*h
;
1112 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
1113 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1114 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
1116 if (r_symndx
< extsymoff
)
1118 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
1123 /* Look up the hash table to check whether the symbol was forced local. */
1124 h
= (struct score_elf_link_hash_entry
*)
1125 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
1126 /* Find the real hash-table entry for this symbol. */
1127 while (h
->root
.root
.type
== bfd_link_hash_indirect
1128 || h
->root
.root
.type
== bfd_link_hash_warning
)
1129 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1130 if (h
->root
.forced_local
)
1137 /* Returns the dynamic relocation section for DYNOBJ. */
1140 score_elf_rel_dyn_section (bfd
*dynobj
, bfd_boolean create_p
)
1142 static const char dname
[] = ".rel.dyn";
1145 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
1146 if (sreloc
== NULL
&& create_p
)
1148 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
1153 | SEC_LINKER_CREATED
1156 || ! bfd_set_section_alignment (dynobj
, sreloc
,
1157 SCORE_ELF_LOG_FILE_ALIGN (dynobj
)))
1164 score_elf_allocate_dynamic_relocations (bfd
*abfd
, unsigned int n
)
1168 s
= score_elf_rel_dyn_section (abfd
, FALSE
);
1169 BFD_ASSERT (s
!= NULL
);
1173 /* Make room for a null element. */
1174 s
->size
+= SCORE_ELF_REL_SIZE (abfd
);
1177 s
->size
+= n
* SCORE_ELF_REL_SIZE (abfd
);
1180 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
1181 is the original relocation, which is now being transformed into a
1182 dynamic relocation. The ADDENDP is adjusted if necessary; the
1183 caller should store the result in place of the original addend. */
1186 score_elf_create_dynamic_relocation (bfd
*output_bfd
,
1187 struct bfd_link_info
*info
,
1188 const Elf_Internal_Rela
*rel
,
1189 struct score_elf_link_hash_entry
*h
,
1191 bfd_vma
*addendp
, asection
*input_section
)
1193 Elf_Internal_Rela outrel
[3];
1198 bfd_boolean defined_p
;
1200 r_type
= ELF32_R_TYPE (rel
->r_info
);
1201 dynobj
= elf_hash_table (info
)->dynobj
;
1202 sreloc
= score_elf_rel_dyn_section (dynobj
, FALSE
);
1203 BFD_ASSERT (sreloc
!= NULL
);
1204 BFD_ASSERT (sreloc
->contents
!= NULL
);
1205 BFD_ASSERT (sreloc
->reloc_count
* SCORE_ELF_REL_SIZE (output_bfd
) < sreloc
->size
);
1207 outrel
[0].r_offset
=
1208 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
1209 outrel
[1].r_offset
=
1210 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
1211 outrel
[2].r_offset
=
1212 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
1214 if (outrel
[0].r_offset
== MINUS_ONE
)
1215 /* The relocation field has been deleted. */
1218 if (outrel
[0].r_offset
== MINUS_TWO
)
1220 /* The relocation field has been converted into a relative value of
1221 some sort. Functions like _bfd_elf_write_section_eh_frame expect
1222 the field to be fully relocated, so add in the symbol's value. */
1227 /* We must now calculate the dynamic symbol table index to use
1228 in the relocation. */
1230 && (! info
->symbolic
|| !h
->root
.def_regular
)
1231 /* h->root.dynindx may be -1 if this symbol was marked to
1233 && h
->root
.dynindx
!= -1)
1235 indx
= h
->root
.dynindx
;
1236 /* ??? glibc's ld.so just adds the final GOT entry to the
1237 relocation field. It therefore treats relocs against
1238 defined symbols in the same way as relocs against
1239 undefined symbols. */
1248 /* If the relocation was previously an absolute relocation and
1249 this symbol will not be referred to by the relocation, we must
1250 adjust it by the value we give it in the dynamic symbol table.
1251 Otherwise leave the job up to the dynamic linker. */
1252 if (defined_p
&& r_type
!= R_SCORE_REL32
)
1255 /* The relocation is always an REL32 relocation because we don't
1256 know where the shared library will wind up at load-time. */
1257 outrel
[0].r_info
= ELF32_R_INFO ((unsigned long) indx
, R_SCORE_REL32
);
1259 /* For strict adherence to the ABI specification, we should
1260 generate a R_SCORE_64 relocation record by itself before the
1261 _REL32/_64 record as well, such that the addend is read in as
1262 a 64-bit value (REL32 is a 32-bit relocation, after all).
1263 However, since none of the existing ELF64 SCORE dynamic
1264 loaders seems to care, we don't waste space with these
1265 artificial relocations. If this turns out to not be true,
1266 score_elf_allocate_dynamic_relocations() should be tweaked so
1267 as to make room for a pair of dynamic relocations per
1268 invocation if ABI_64_P, and here we should generate an
1269 additional relocation record with R_SCORE_64 by itself for a
1270 NULL symbol before this relocation record. */
1271 outrel
[1].r_info
= ELF32_R_INFO (0, R_SCORE_NONE
);
1272 outrel
[2].r_info
= ELF32_R_INFO (0, R_SCORE_NONE
);
1274 /* Adjust the output offset of the relocation to reference the
1275 correct location in the output file. */
1276 outrel
[0].r_offset
+= (input_section
->output_section
->vma
1277 + input_section
->output_offset
);
1278 outrel
[1].r_offset
+= (input_section
->output_section
->vma
1279 + input_section
->output_offset
);
1280 outrel
[2].r_offset
+= (input_section
->output_section
->vma
1281 + input_section
->output_offset
);
1283 /* Put the relocation back out. We have to use the special
1284 relocation outputter in the 64-bit case since the 64-bit
1285 relocation format is non-standard. */
1286 bfd_elf32_swap_reloc_out
1287 (output_bfd
, &outrel
[0],
1288 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
1290 /* We've now added another relocation. */
1291 ++sreloc
->reloc_count
;
1293 /* Make sure the output section is writable. The dynamic linker
1294 will be writing to it. */
1295 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
|= SHF_WRITE
;
1301 score_elf_create_got_section (bfd
*abfd
,
1302 struct bfd_link_info
*info
,
1303 bfd_boolean maybe_exclude
)
1307 struct elf_link_hash_entry
*h
;
1308 struct bfd_link_hash_entry
*bh
;
1309 struct score_got_info
*g
;
1312 /* This function may be called more than once. */
1313 s
= score_elf_got_section (abfd
, TRUE
);
1316 if (! maybe_exclude
)
1317 s
->flags
&= ~SEC_EXCLUDE
;
1321 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1324 flags
|= SEC_EXCLUDE
;
1326 /* We have to use an alignment of 2**4 here because this is hardcoded
1327 in the function stub generation and in the linker script. */
1328 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
1330 || ! bfd_set_section_alignment (abfd
, s
, 4))
1333 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1334 linker script because we don't want to define the symbol if we
1335 are not creating a global offset table. */
1337 if (! (_bfd_generic_link_add_one_symbol
1338 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
1339 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
1342 h
= (struct elf_link_hash_entry
*) bh
;
1345 h
->type
= STT_OBJECT
;
1347 if (info
->shared
&& ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1350 amt
= sizeof (struct score_got_info
);
1351 g
= bfd_alloc (abfd
, amt
);
1355 g
->global_gotsym
= NULL
;
1356 g
->global_gotno
= 0;
1358 g
->local_gotno
= SCORE_RESERVED_GOTNO
;
1359 g
->assigned_gotno
= SCORE_RESERVED_GOTNO
;
1362 g
->got_entries
= htab_try_create (1, score_elf_got_entry_hash
,
1363 score_elf_got_entry_eq
, NULL
);
1364 if (g
->got_entries
== NULL
)
1366 score_elf_section_data (s
)->u
.got_info
= g
;
1367 score_elf_section_data (s
)->elf
.this_hdr
.sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_SCORE_GPREL
;
1372 /* Calculate the %high function. */
1375 score_elf_high (bfd_vma value
)
1377 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1380 /* Create a local GOT entry for VALUE. Return the index of the entry,
1381 or -1 if it could not be created. */
1383 static struct score_got_entry
*
1384 score_elf_create_local_got_entry (bfd
*abfd
,
1385 bfd
*ibfd ATTRIBUTE_UNUSED
,
1386 struct score_got_info
*gg
,
1387 asection
*sgot
, bfd_vma value
,
1388 unsigned long r_symndx ATTRIBUTE_UNUSED
,
1389 struct score_elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
1390 int r_type ATTRIBUTE_UNUSED
)
1392 struct score_got_entry entry
, **loc
;
1393 struct score_got_info
*g
;
1397 entry
.d
.address
= value
;
1400 loc
= (struct score_got_entry
**) htab_find_slot (g
->got_entries
, &entry
, INSERT
);
1404 entry
.gotidx
= SCORE_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1406 *loc
= bfd_alloc (abfd
, sizeof entry
);
1411 memcpy (*loc
, &entry
, sizeof entry
);
1413 if (g
->assigned_gotno
>= g
->local_gotno
)
1415 (*loc
)->gotidx
= -1;
1416 /* We didn't allocate enough space in the GOT. */
1417 (*_bfd_error_handler
)
1418 (_("not enough GOT space for local GOT entries"));
1419 bfd_set_error (bfd_error_bad_value
);
1423 bfd_put_32 (abfd
, value
, (sgot
->contents
+ entry
.gotidx
));
1428 /* Find a GOT entry whose higher-order 16 bits are the same as those
1429 for value. Return the index into the GOT for this entry. */
1432 score_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1433 bfd_vma value
, bfd_boolean external
)
1436 struct score_got_info
*g
;
1437 struct score_got_entry
*entry
;
1441 /* Although the ABI says that it is "the high-order 16 bits" that we
1442 want, it is really the %high value. The complete value is
1443 calculated with a `addiu' of a LO16 relocation, just as with a
1445 value
= score_elf_high (value
) << 16;
1448 g
= score_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1450 entry
= score_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
, 0, NULL
,
1453 return entry
->gotidx
;
1459 _bfd_score_elf_hide_symbol (struct bfd_link_info
*info
,
1460 struct elf_link_hash_entry
*entry
,
1461 bfd_boolean force_local
)
1465 struct score_got_info
*g
;
1466 struct score_elf_link_hash_entry
*h
;
1468 h
= (struct score_elf_link_hash_entry
*) entry
;
1469 if (h
->forced_local
)
1471 h
->forced_local
= TRUE
;
1473 dynobj
= elf_hash_table (info
)->dynobj
;
1474 if (dynobj
!= NULL
&& force_local
)
1476 got
= score_elf_got_section (dynobj
, FALSE
);
1479 g
= score_elf_section_data (got
)->u
.got_info
;
1483 struct score_got_entry e
;
1484 struct score_got_info
*gg
= g
;
1486 /* Since we're turning what used to be a global symbol into a
1487 local one, bump up the number of local entries of each GOT
1488 that had an entry for it. This will automatically decrease
1489 the number of global entries, since global_gotno is actually
1490 the upper limit of global entries. */
1495 for (g
= g
->next
; g
!= gg
; g
= g
->next
)
1496 if (htab_find (g
->got_entries
, &e
))
1498 BFD_ASSERT (g
->global_gotno
> 0);
1503 /* If this was a global symbol forced into the primary GOT, we
1504 no longer need an entry for it. We can't release the entry
1505 at this point, but we must at least stop counting it as one
1506 of the symbols that required a forced got entry. */
1507 if (h
->root
.got
.offset
== 2)
1509 BFD_ASSERT (gg
->assigned_gotno
> 0);
1510 gg
->assigned_gotno
--;
1513 else if (g
->global_gotno
== 0 && g
->global_gotsym
== NULL
)
1514 /* If we haven't got through GOT allocation yet, just bump up the
1515 number of local entries, as this symbol won't be counted as
1518 else if (h
->root
.got
.offset
== 1)
1520 /* If we're past non-multi-GOT allocation and this symbol had
1521 been marked for a global got entry, give it a local entry
1523 BFD_ASSERT (g
->global_gotno
> 0);
1529 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
1532 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1533 symbol table index lower than any we've seen to date, record it for
1537 score_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
1539 struct bfd_link_info
*info
,
1540 struct score_got_info
*g
)
1542 struct score_got_entry entry
, **loc
;
1544 /* A global symbol in the GOT must also be in the dynamic symbol table. */
1545 if (h
->dynindx
== -1)
1547 switch (ELF_ST_VISIBILITY (h
->other
))
1551 _bfd_score_elf_hide_symbol (info
, h
, TRUE
);
1554 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
1560 entry
.d
.h
= (struct score_elf_link_hash_entry
*)h
;
1562 loc
= (struct score_got_entry
**)htab_find_slot (g
->got_entries
, &entry
, INSERT
);
1564 /* If we've already marked this entry as needing GOT space, we don't
1565 need to do it again. */
1569 *loc
= bfd_alloc (abfd
, sizeof entry
);
1575 memcpy (*loc
, &entry
, sizeof (entry
));
1577 if (h
->got
.offset
!= MINUS_ONE
)
1580 /* By setting this to a value other than -1, we are indicating that
1581 there needs to be a GOT entry for H. Avoid using zero, as the
1582 generic ELF copy_indirect_symbol tests for <= 0. */
1588 /* Reserve space in G for a GOT entry containing the value of symbol
1589 SYMNDX in input bfd ABDF, plus ADDEND. */
1592 score_elf_record_local_got_symbol (bfd
*abfd
,
1595 struct score_got_info
*g
)
1597 struct score_got_entry entry
, **loc
;
1600 entry
.symndx
= symndx
;
1601 entry
.d
.addend
= addend
;
1602 loc
= (struct score_got_entry
**)htab_find_slot (g
->got_entries
, &entry
, INSERT
);
1607 entry
.gotidx
= g
->local_gotno
++;
1609 *loc
= bfd_alloc (abfd
, sizeof(entry
));
1613 memcpy (*loc
, &entry
, sizeof (entry
));
1618 /* Returns the GOT offset at which the indicated address can be found.
1619 If there is not yet a GOT entry for this value, create one.
1620 Returns -1 if no satisfactory GOT offset can be found. */
1623 score_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1624 bfd_vma value
, unsigned long r_symndx
,
1625 struct score_elf_link_hash_entry
*h
, int r_type
)
1628 struct score_got_info
*g
;
1629 struct score_got_entry
*entry
;
1631 g
= score_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1633 entry
= score_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
,
1634 r_symndx
, h
, r_type
);
1639 return entry
->gotidx
;
1642 /* Returns the GOT index for the global symbol indicated by H. */
1645 score_elf_global_got_index (bfd
*abfd
, struct elf_link_hash_entry
*h
)
1649 struct score_got_info
*g
;
1650 long global_got_dynindx
= 0;
1652 g
= score_elf_got_info (abfd
, &sgot
);
1653 if (g
->global_gotsym
!= NULL
)
1654 global_got_dynindx
= g
->global_gotsym
->dynindx
;
1656 /* Once we determine the global GOT entry with the lowest dynamic
1657 symbol table index, we must put all dynamic symbols with greater
1658 indices into the GOT. That makes it easy to calculate the GOT
1660 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
1661 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
) * SCORE_ELF_GOT_SIZE (abfd
));
1662 BFD_ASSERT (index
< sgot
->size
);
1667 /* Returns the offset for the entry at the INDEXth position in the GOT. */
1670 score_elf_got_offset_from_index (bfd
*dynobj
, bfd
*output_bfd
,
1671 bfd
*input_bfd ATTRIBUTE_UNUSED
, bfd_vma index
)
1675 struct score_got_info
*g
;
1677 g
= score_elf_got_info (dynobj
, &sgot
);
1678 gp
= _bfd_get_gp_value (output_bfd
);
1680 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
1683 /* Follow indirect and warning hash entries so that each got entry
1684 points to the final symbol definition. P must point to a pointer
1685 to the hash table we're traversing. Since this traversal may
1686 modify the hash table, we set this pointer to NULL to indicate
1687 we've made a potentially-destructive change to the hash table, so
1688 the traversal must be restarted. */
1690 score_elf_resolve_final_got_entry (void **entryp
, void *p
)
1692 struct score_got_entry
*entry
= (struct score_got_entry
*)*entryp
;
1693 htab_t got_entries
= *(htab_t
*)p
;
1695 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
1697 struct score_elf_link_hash_entry
*h
= entry
->d
.h
;
1699 while (h
->root
.root
.type
== bfd_link_hash_indirect
1700 || h
->root
.root
.type
== bfd_link_hash_warning
)
1701 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1703 if (entry
->d
.h
== h
)
1708 /* If we can't find this entry with the new bfd hash, re-insert
1709 it, and get the traversal restarted. */
1710 if (! htab_find (got_entries
, entry
))
1712 htab_clear_slot (got_entries
, entryp
);
1713 entryp
= htab_find_slot (got_entries
, entry
, INSERT
);
1716 /* Abort the traversal, since the whole table may have
1717 moved, and leave it up to the parent to restart the
1719 *(htab_t
*)p
= NULL
;
1722 /* We might want to decrement the global_gotno count, but it's
1723 either too early or too late for that at this point. */
1729 /* Turn indirect got entries in a got_entries table into their final locations. */
1731 score_elf_resolve_final_got_entries (struct score_got_info
*g
)
1737 got_entries
= g
->got_entries
;
1739 htab_traverse (got_entries
,
1740 score_elf_resolve_final_got_entry
,
1743 while (got_entries
== NULL
);
1746 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. for -r */
1749 score_elf_add_to_rel (bfd
*abfd
,
1751 reloc_howto_type
*howto
,
1752 bfd_signed_vma increment
)
1754 bfd_signed_vma addend
;
1756 unsigned long offset
;
1757 unsigned long r_type
= howto
->type
;
1758 unsigned long hi16_addend
, hi16_offset
, hi16_value
, uvalue
;
1760 contents
= bfd_get_32 (abfd
, address
);
1761 /* Get the (signed) value from the instruction. */
1762 addend
= contents
& howto
->src_mask
;
1763 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1765 bfd_signed_vma mask
;
1768 mask
&= ~howto
->src_mask
;
1771 /* Add in the increment, (which is a byte value). */
1776 (((contents
& howto
->src_mask
) & 0x3ff0000) >> 6) | ((contents
& howto
->src_mask
) & 0x3ff);
1777 offset
+= increment
;
1779 (contents
& ~howto
->
1780 src_mask
) | (((offset
<< 6) & howto
->src_mask
) & 0x3ff0000) | (offset
& 0x3ff);
1781 bfd_put_32 (abfd
, contents
, address
);
1786 hi16_addend
= bfd_get_32 (abfd
, address
- 4);
1787 hi16_offset
= ((((hi16_addend
>> 16) & 0x3) << 15) | (hi16_addend
& 0x7fff)) >> 1;
1788 offset
= ((((contents
>> 16) & 0x3) << 15) | (contents
& 0x7fff)) >> 1;
1789 offset
= (hi16_offset
<< 16) | (offset
& 0xffff);
1790 uvalue
= increment
+ offset
;
1791 hi16_offset
= (uvalue
>> 16) << 1;
1792 hi16_value
= (hi16_addend
& (~(howto
->dst_mask
)))
1793 | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
1794 bfd_put_32 (abfd
, hi16_value
, address
- 4);
1795 offset
= (uvalue
& 0xffff) << 1;
1796 contents
= (contents
& (~(howto
->dst_mask
))) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
1797 bfd_put_32 (abfd
, contents
, address
);
1801 (((contents
& howto
->src_mask
) >> 1) & 0x1ff8000) | ((contents
& howto
->src_mask
) & 0x7fff);
1802 offset
+= increment
;
1804 (contents
& ~howto
->
1805 src_mask
) | (((offset
<< 1) & howto
->src_mask
) & 0x3ff0000) | (offset
& 0x7fff);
1806 bfd_put_32 (abfd
, contents
, address
);
1810 contents
= bfd_get_16 (abfd
, address
);
1811 offset
= contents
& howto
->src_mask
;
1812 offset
+= increment
;
1813 contents
= (contents
& ~howto
->src_mask
) | (offset
& howto
->src_mask
);
1814 bfd_put_16 (abfd
, contents
, address
);
1819 contents
= bfd_get_16 (abfd
, address
);
1820 offset
= (contents
& howto
->src_mask
) + ((increment
>> 1) & 0xff);
1821 contents
= (contents
& (~howto
->src_mask
)) | (offset
& howto
->src_mask
);
1822 bfd_put_16 (abfd
, contents
, address
);
1826 addend
+= increment
;
1827 contents
= (contents
& ~howto
->dst_mask
) | (addend
& howto
->dst_mask
);
1828 bfd_put_32 (abfd
, contents
, address
);
1833 /* Perform a relocation as part of a final link. */
1835 static bfd_reloc_status_type
1836 score_elf_final_link_relocate (reloc_howto_type
*howto
,
1839 asection
*input_section
,
1841 Elf_Internal_Rela
*rel
,
1842 Elf_Internal_Rela
*relocs
,
1844 struct bfd_link_info
*info
,
1845 const char *sym_name ATTRIBUTE_UNUSED
,
1846 int sym_flags ATTRIBUTE_UNUSED
,
1847 struct score_elf_link_hash_entry
*h
,
1848 asection
**local_sections
,
1849 bfd_boolean gp_disp_p
)
1851 unsigned long r_type
;
1852 unsigned long r_symndx
;
1853 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
1855 /* The final GP value to be used for the relocatable, executable, or
1856 shared object file being produced. */
1857 bfd_vma gp
= MINUS_ONE
;
1858 /* The place (section offset or address) of the storage unit being relocated. */
1860 /* The value of GP used to create the relocatable object. */
1861 bfd_vma gp0
= MINUS_ONE
;
1862 /* The offset into the global offset table at which the address of the relocation entry
1863 symbol, adjusted by the addend, resides during execution. */
1864 bfd_vma g
= MINUS_ONE
;
1865 /* TRUE if the symbol referred to by this relocation is a local symbol. */
1866 bfd_boolean local_p
;
1867 /* The eventual value we will relocate. */
1868 bfd_vma value
= symbol
;
1869 unsigned long hi16_addend
, hi16_offset
, hi16_value
, uvalue
, offset
, abs_value
= 0;
1871 if (elf_gp (output_bfd
) == 0)
1873 struct bfd_link_hash_entry
*bh
;
1876 bh
= bfd_link_hash_lookup (info
->hash
, "_gp", 0, 0, 1);
1877 if (bh
!= (struct bfd_link_hash_entry
*)NULL
&& bh
->type
== bfd_link_hash_defined
)
1878 elf_gp (output_bfd
) = (bh
->u
.def
.value
1879 + bh
->u
.def
.section
->output_section
->vma
1880 + bh
->u
.def
.section
->output_offset
);
1881 else if (info
->relocatable
)
1885 /* Find the GP-relative section with the lowest offset. */
1886 for (o
= output_bfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
1889 /* And calculate GP relative to that. */
1890 elf_gp (output_bfd
) = lo
+ ELF_SCORE_GP_OFFSET (input_bfd
);
1894 /* If the relocate_section function needs to do a reloc
1895 involving the GP value, it should make a reloc_dangerous
1896 callback to warn that GP is not defined. */
1900 /* Parse the relocation. */
1901 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1902 r_type
= ELF32_R_TYPE (rel
->r_info
);
1903 rel_addr
= (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
1904 local_p
= score_elf_local_relocation_p (input_bfd
, rel
, local_sections
, TRUE
);
1906 if (r_type
== R_SCORE_GOT15
)
1908 const Elf_Internal_Rela
*relend
;
1909 const Elf_Internal_Rela
*lo16_rel
;
1910 const struct elf_backend_data
*bed
;
1911 bfd_vma lo_value
= 0;
1913 bed
= get_elf_backend_data (output_bfd
);
1914 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
1915 lo16_rel
= score_elf_next_relocation (input_bfd
, R_SCORE_GOT_LO16
, rel
, relend
);
1916 if ((local_p
) && (lo16_rel
!= NULL
))
1919 tmp
= bfd_get_32 (input_bfd
, contents
+ lo16_rel
->r_offset
);
1920 lo_value
= (((tmp
>> 16) & 0x3) << 14) | ((tmp
& 0x7fff) >> 1);
1926 addend
= (bfd_get_32 (input_bfd
, hit_data
) >> howto
->bitpos
) & howto
->src_mask
;
1929 /* If we haven't already determined the GOT offset, or the GP value,
1930 and we're going to need it, get it now. */
1933 case R_SCORE_CALL15
:
1937 g
= score_elf_global_got_index (elf_hash_table (info
)->dynobj
,
1938 (struct elf_link_hash_entry
*) h
);
1939 if ((! elf_hash_table(info
)->dynamic_sections_created
1941 && (info
->symbolic
|| h
->root
.dynindx
== -1)
1942 && h
->root
.def_regular
)))
1944 /* This is a static link or a -Bsymbolic link. The
1945 symbol is defined locally, or was forced to be local.
1946 We must initialize this entry in the GOT. */
1947 bfd
*tmpbfd
= elf_hash_table (info
)->dynobj
;
1948 asection
*sgot
= score_elf_got_section (tmpbfd
, FALSE
);
1949 bfd_put_32 (tmpbfd
, value
, sgot
->contents
+ g
);
1952 else if (r_type
== R_SCORE_GOT15
|| r_type
== R_SCORE_CALL15
)
1954 /* There's no need to create a local GOT entry here; the
1955 calculation for a local GOT15 entry does not involve G. */
1960 g
= score_elf_local_got_index (output_bfd
, input_bfd
, info
,
1961 symbol
+ addend
, r_symndx
, h
, r_type
);
1963 return bfd_reloc_outofrange
;
1966 /* Convert GOT indices to actual offsets. */
1967 g
= score_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
1968 output_bfd
, input_bfd
, g
);
1973 case R_SCORE_GPREL32
:
1974 gp0
= _bfd_get_gp_value (input_bfd
);
1975 gp
= _bfd_get_gp_value (output_bfd
);
1979 gp
= _bfd_get_gp_value (output_bfd
);
1988 return bfd_reloc_ok
;
1993 || (elf_hash_table (info
)->dynamic_sections_created
1995 && h
->root
.def_dynamic
1996 && !h
->root
.def_regular
))
1998 && (input_section
->flags
& SEC_ALLOC
) != 0)
2000 /* If we're creating a shared library, or this relocation is against a symbol
2001 in a shared library, then we can't know where the symbol will end up.
2002 So, we create a relocation record in the output, and leave the job up
2003 to the dynamic linker. */
2005 if (!score_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
,
2008 return bfd_reloc_undefined
;
2012 if (r_type
!= R_SCORE_REL32
)
2013 value
= symbol
+ addend
;
2017 value
&= howto
->dst_mask
;
2018 bfd_put_32 (input_bfd
, value
, hit_data
);
2019 return bfd_reloc_ok
;
2023 if ((long)value
> 0x7fff || (long)value
< -0x8000)
2024 return bfd_reloc_overflow
;
2025 bfd_put_16 (input_bfd
, value
, hit_data
);
2026 return bfd_reloc_ok
;
2029 addend
= bfd_get_32 (input_bfd
, hit_data
);
2030 offset
= (((addend
& howto
->src_mask
) >> 1) & 0x1ff8000) | ((addend
& howto
->src_mask
) & 0x7fff);
2031 if ((offset
& 0x1000000) != 0)
2032 offset
|= 0xfe000000;
2034 addend
= (addend
& ~howto
->src_mask
)
2035 | (((value
<< 1) & howto
->src_mask
) & 0x3ff0000) | (value
& 0x7fff);
2036 bfd_put_32 (input_bfd
, addend
, hit_data
);
2037 return bfd_reloc_ok
;
2040 addend
= bfd_get_32 (input_bfd
, hit_data
);
2041 offset
= (((addend
& howto
->src_mask
) & 0x3ff0000) >> 6) | ((addend
& howto
->src_mask
) & 0x3ff);
2042 if ((offset
& 0x80000) != 0)
2043 offset
|= 0xfff00000;
2044 abs_value
= value
= value
- rel_addr
+ offset
;
2045 /* exceed 20 bit : overflow. */
2046 if ((abs_value
& 0x80000000) == 0x80000000)
2047 abs_value
= 0xffffffff - value
+ 1;
2048 if ((abs_value
& 0xfff80000) != 0)
2049 return bfd_reloc_overflow
;
2050 addend
= (addend
& ~howto
->src_mask
)
2051 | (((value
<< 6) & howto
->src_mask
) & 0x3ff0000) | (value
& 0x3ff);
2052 bfd_put_32 (input_bfd
, addend
, hit_data
);
2053 return bfd_reloc_ok
;
2056 addend
= bfd_get_16 (input_bfd
, hit_data
);
2057 offset
= addend
& howto
->src_mask
;
2058 if ((offset
& 0x800) != 0) /* Offset is negative. */
2059 offset
|= 0xfffff000;
2061 addend
= (addend
& ~howto
->src_mask
) | (value
& howto
->src_mask
);
2062 bfd_put_16 (input_bfd
, addend
, hit_data
);
2063 return bfd_reloc_ok
;
2066 addend
= bfd_get_16 (input_bfd
, hit_data
);
2067 offset
= (addend
& howto
->src_mask
) << 1;
2068 if ((offset
& 0x100) != 0) /* Offset is negative. */
2069 offset
|= 0xfffffe00;
2070 abs_value
= value
= value
- rel_addr
+ offset
;
2071 /* Sign bit + exceed 9 bit. */
2072 if (((value
& 0xffffff00) != 0) && ((value
& 0xffffff00) != 0xffffff00))
2073 return bfd_reloc_overflow
;
2075 addend
= (addend
& ~howto
->src_mask
) | (value
& howto
->src_mask
);
2076 bfd_put_16 (input_bfd
, addend
, hit_data
);
2077 return bfd_reloc_ok
;
2080 return bfd_reloc_ok
;
2083 hi16_addend
= bfd_get_32 (input_bfd
, hit_data
- 4);
2084 hi16_offset
= ((((hi16_addend
>> 16) & 0x3) << 15) | (hi16_addend
& 0x7fff)) >> 1;
2085 addend
= bfd_get_32 (input_bfd
, hit_data
);
2086 offset
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
2087 offset
= (hi16_offset
<< 16) | (offset
& 0xffff);
2090 uvalue
= value
+ offset
;
2092 uvalue
= offset
+ gp
- rel_addr
+ 4;
2094 hi16_offset
= (uvalue
>> 16) << 1;
2095 hi16_value
= (hi16_addend
& (~(howto
->dst_mask
)))
2096 | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
2097 bfd_put_32 (input_bfd
, hi16_value
, hit_data
- 4);
2098 offset
= (uvalue
& 0xffff) << 1;
2099 value
= (addend
& (~(howto
->dst_mask
))) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
2100 bfd_put_32 (input_bfd
, value
, hit_data
);
2101 return bfd_reloc_ok
;
2104 addend
= bfd_get_32 (input_bfd
, hit_data
);
2105 offset
= addend
& 0x7fff;
2106 if ((offset
& 0x4000) == 0x4000)
2107 offset
|= 0xffffc000;
2108 value
= value
+ offset
- gp
;
2109 if (((value
& 0xffffc000) != 0) && ((value
& 0xffffc000) != 0xffffc000))
2110 return bfd_reloc_overflow
;
2111 value
= (addend
& ~howto
->src_mask
) | (value
& howto
->src_mask
);
2112 bfd_put_32 (input_bfd
, value
, hit_data
);
2113 return bfd_reloc_ok
;
2116 case R_SCORE_CALL15
:
2121 /* The special case is when the symbol is forced to be local. We need the
2122 full address in the GOT since no R_SCORE_GOT_LO16 relocation follows. */
2123 forced
= ! score_elf_local_relocation_p (input_bfd
, rel
,
2124 local_sections
, FALSE
);
2125 value
= score_elf_got16_entry (output_bfd
, input_bfd
, info
,
2126 symbol
+ addend
, forced
);
2127 if (value
== MINUS_ONE
)
2128 return bfd_reloc_outofrange
;
2129 value
= score_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2130 output_bfd
, input_bfd
, value
);
2137 if ((long) value
> 0x3fff || (long) value
< -0x4000)
2138 return bfd_reloc_overflow
;
2140 addend
= bfd_get_32 (input_bfd
, hit_data
);
2141 value
= (addend
& ~howto
->dst_mask
) | (value
& howto
->dst_mask
);
2142 bfd_put_32 (input_bfd
, value
, hit_data
);
2143 return bfd_reloc_ok
;
2145 case R_SCORE_GPREL32
:
2146 value
= (addend
+ symbol
- gp
);
2147 value
&= howto
->dst_mask
;
2148 bfd_put_32 (input_bfd
, value
, hit_data
);
2149 return bfd_reloc_ok
;
2151 case R_SCORE_GOT_LO16
:
2152 addend
= bfd_get_32 (input_bfd
, hit_data
);
2153 value
= (((addend
>> 16) & 0x3) << 14) | ((addend
& 0x7fff) >> 1);
2155 value
= (addend
& (~(howto
->dst_mask
))) | ((value
& 0x3fff) << 1)
2156 | (((value
>> 14) & 0x3) << 16);
2158 bfd_put_32 (input_bfd
, value
, hit_data
);
2159 return bfd_reloc_ok
;
2161 case R_SCORE_DUMMY_HI16
:
2162 return bfd_reloc_ok
;
2164 case R_SCORE_GNU_VTINHERIT
:
2165 case R_SCORE_GNU_VTENTRY
:
2166 /* We don't do anything with these at present. */
2167 return bfd_reloc_continue
;
2170 return bfd_reloc_notsupported
;
2174 /* Score backend functions. */
2177 _bfd_score_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2179 Elf_Internal_Rela
*elf_reloc
)
2181 unsigned int r_type
;
2183 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
2184 if (r_type
>= NUM_ELEM (elf32_score_howto_table
))
2185 bfd_reloc
->howto
= NULL
;
2187 bfd_reloc
->howto
= &elf32_score_howto_table
[r_type
];
2190 /* Relocate an score ELF section. */
2193 _bfd_score_elf_relocate_section (bfd
*output_bfd
,
2194 struct bfd_link_info
*info
,
2196 asection
*input_section
,
2198 Elf_Internal_Rela
*relocs
,
2199 Elf_Internal_Sym
*local_syms
,
2200 asection
**local_sections
)
2202 Elf_Internal_Shdr
*symtab_hdr
;
2203 struct elf_link_hash_entry
**sym_hashes
;
2204 Elf_Internal_Rela
*rel
;
2205 Elf_Internal_Rela
*relend
;
2207 unsigned long offset
;
2208 unsigned long hi16_addend
, hi16_offset
, hi16_value
, uvalue
;
2210 bfd_boolean gp_disp_p
= FALSE
;
2213 if (elf_hash_table (info
)->dynamic_sections_created
)
2215 bfd_size_type dynsecsymcount
= 0;
2219 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
2221 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
2222 if ((p
->flags
& SEC_EXCLUDE
) == 0
2223 && (p
->flags
& SEC_ALLOC
) != 0
2224 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
2228 if (!score_elf_sort_hash_table (info
, dynsecsymcount
+ 1))
2232 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2233 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
2234 sym_hashes
= elf_sym_hashes (input_bfd
);
2236 relend
= relocs
+ input_section
->reloc_count
;
2237 for (; rel
< relend
; rel
++)
2240 reloc_howto_type
*howto
;
2241 unsigned long r_symndx
;
2242 Elf_Internal_Sym
*sym
;
2244 struct score_elf_link_hash_entry
*h
;
2245 bfd_vma relocation
= 0;
2246 bfd_reloc_status_type r
;
2249 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2250 r_type
= ELF32_R_TYPE (rel
->r_info
);
2252 _bfd_score_info_to_howto (input_bfd
, &bfd_reloc
, (Elf_Internal_Rela
*) rel
);
2253 howto
= bfd_reloc
.howto
;
2259 if (r_symndx
< extsymoff
)
2261 sym
= local_syms
+ r_symndx
;
2262 sec
= local_sections
[r_symndx
];
2263 relocation
= (sec
->output_section
->vma
2264 + sec
->output_offset
2266 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
2268 if (!info
->relocatable
2269 && (sec
->flags
& SEC_MERGE
) != 0
2270 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2273 bfd_vma addend
, value
;
2280 hi16_addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- 4);
2281 hi16_offset
= ((((hi16_addend
>> 16) & 0x3) << 15) | (hi16_addend
& 0x7fff)) >> 1;
2282 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2283 offset
= ((((value
>> 16) & 0x3) << 15) | (value
& 0x7fff)) >> 1;
2284 addend
= (hi16_offset
<< 16) | (offset
& 0xffff);
2286 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
);
2287 addend
-= relocation
;
2288 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2290 hi16_offset
= (uvalue
>> 16) << 1;
2291 hi16_value
= (hi16_addend
& (~(howto
->dst_mask
)))
2292 | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
2293 bfd_put_32 (input_bfd
, hi16_value
, contents
+ rel
->r_offset
- 4);
2294 offset
= (uvalue
& 0xffff) << 1;
2295 value
= (value
& (~(howto
->dst_mask
)))
2296 | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
2297 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2299 case R_SCORE_GOT_LO16
:
2300 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2301 addend
= (((value
>> 16) & 0x3) << 14) | ((value
& 0x7fff) >> 1);
2303 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
) - relocation
;
2304 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2305 value
= (value
& (~(howto
->dst_mask
))) | ((addend
& 0x3fff) << 1)
2306 | (((addend
>> 14) & 0x3) << 16);
2308 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2311 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2312 /* Get the (signed) value from the instruction. */
2313 addend
= value
& howto
->src_mask
;
2314 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2316 bfd_signed_vma mask
;
2319 mask
&= ~howto
->src_mask
;
2323 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
) - relocation
;
2324 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2325 value
= (value
& ~howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2326 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2333 /* For global symbols we look up the symbol in the hash-table. */
2334 h
= ((struct score_elf_link_hash_entry
*)
2335 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2336 /* Find the real hash-table entry for this symbol. */
2337 while (h
->root
.root
.type
== bfd_link_hash_indirect
2338 || h
->root
.root
.type
== bfd_link_hash_warning
)
2339 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2341 /* Record the name of this symbol, for our caller. */
2342 name
= h
->root
.root
.root
.string
;
2344 /* See if this is the special GP_DISP_LABEL symbol. Note that such a
2345 symbol must always be a global symbol. */
2346 if (strcmp (name
, GP_DISP_LABEL
) == 0)
2348 /* Relocations against GP_DISP_LABEL are permitted only with
2349 R_SCORE_HI16 and R_SCORE_LO16 relocations. */
2350 if (r_type
!= R_SCORE_HI16
&& r_type
!= R_SCORE_LO16
)
2351 return bfd_reloc_notsupported
;
2356 /* If this symbol is defined, calculate its address. Note that
2357 GP_DISP_LABEL is a magic symbol, always implicitly defined by the
2358 linker, so it's inappropriate to check to see whether or not
2360 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2361 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2362 && h
->root
.root
.u
.def
.section
)
2364 sec
= h
->root
.root
.u
.def
.section
;
2365 if (sec
->output_section
)
2366 relocation
= (h
->root
.root
.u
.def
.value
2367 + sec
->output_section
->vma
2368 + sec
->output_offset
);
2371 relocation
= h
->root
.root
.u
.def
.value
;
2374 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2375 /* We allow relocations against undefined weak symbols, giving
2376 it the value zero, so that you can undefined weak functions
2377 and check to see if they exist by looking at their addresses. */
2379 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
2380 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2382 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
2384 /* If this is a dynamic link, we should have created a _DYNAMIC_LINK symbol
2385 in _bfd_score_elf_create_dynamic_sections. Otherwise, we should define
2386 the symbol with a value of 0. */
2387 BFD_ASSERT (! info
->shared
);
2388 BFD_ASSERT (bfd_get_section_by_name (output_bfd
, ".dynamic") == NULL
);
2391 else if (!info
->relocatable
)
2393 if (! ((*info
->callbacks
->undefined_symbol
)
2394 (info
, h
->root
.root
.root
.string
, input_bfd
,
2395 input_section
, rel
->r_offset
,
2396 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
2397 || ELF_ST_VISIBILITY (h
->root
.other
))))
2398 return bfd_reloc_undefined
;
2403 if (sec
!= NULL
&& elf_discarded_section (sec
))
2405 /* For relocs against symbols from removed linkonce sections,
2406 or sections discarded by a linker script, we just want the
2407 section contents zeroed. Avoid any special processing. */
2408 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
2414 if (info
->relocatable
)
2416 /* This is a relocatable link. We don't have to change
2417 anything, unless the reloc is against a section symbol,
2418 in which case we have to adjust according to where the
2419 section symbol winds up in the output section. */
2420 if (sym
!= NULL
&& ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2421 score_elf_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2422 howto
, (bfd_signed_vma
) sec
->output_offset
);
2426 r
= score_elf_final_link_relocate (howto
, input_bfd
, output_bfd
,
2427 input_section
, contents
, rel
, relocs
,
2428 relocation
, info
, name
,
2429 (h
? ELF_ST_TYPE ((unsigned int)h
->root
.root
.type
) :
2430 ELF_ST_TYPE ((unsigned int)sym
->st_info
)), h
, local_sections
,
2433 if (r
!= bfd_reloc_ok
)
2435 const char *msg
= (const char *)0;
2439 case bfd_reloc_overflow
:
2440 /* If the overflowing reloc was to an undefined symbol,
2441 we have already printed one error message and there
2442 is no point complaining again. */
2443 if (((!h
) || (h
->root
.root
.type
!= bfd_link_hash_undefined
))
2444 && (!((*info
->callbacks
->reloc_overflow
)
2445 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
2446 input_bfd
, input_section
, rel
->r_offset
))))
2449 case bfd_reloc_undefined
:
2450 if (!((*info
->callbacks
->undefined_symbol
)
2451 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
)))
2455 case bfd_reloc_outofrange
:
2456 msg
= _("internal error: out of range error");
2459 case bfd_reloc_notsupported
:
2460 msg
= _("internal error: unsupported relocation error");
2463 case bfd_reloc_dangerous
:
2464 msg
= _("internal error: dangerous error");
2468 msg
= _("internal error: unknown error");
2472 if (!((*info
->callbacks
->warning
)
2473 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
)))
2483 /* Look through the relocs for a section during the first phase, and
2484 allocate space in the global offset table. */
2487 _bfd_score_elf_check_relocs (bfd
*abfd
,
2488 struct bfd_link_info
*info
,
2490 const Elf_Internal_Rela
*relocs
)
2494 Elf_Internal_Shdr
*symtab_hdr
;
2495 struct elf_link_hash_entry
**sym_hashes
;
2496 struct score_got_info
*g
;
2498 const Elf_Internal_Rela
*rel
;
2499 const Elf_Internal_Rela
*rel_end
;
2502 const struct elf_backend_data
*bed
;
2504 if (info
->relocatable
)
2507 dynobj
= elf_hash_table (info
)->dynobj
;
2508 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2509 sym_hashes
= elf_sym_hashes (abfd
);
2510 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
2512 name
= bfd_get_section_name (abfd
, sec
);
2521 sgot
= score_elf_got_section (dynobj
, FALSE
);
2526 BFD_ASSERT (score_elf_section_data (sgot
) != NULL
);
2527 g
= score_elf_section_data (sgot
)->u
.got_info
;
2528 BFD_ASSERT (g
!= NULL
);
2533 bed
= get_elf_backend_data (abfd
);
2534 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
2535 for (rel
= relocs
; rel
< rel_end
; ++rel
)
2537 unsigned long r_symndx
;
2538 unsigned int r_type
;
2539 struct elf_link_hash_entry
*h
;
2541 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2542 r_type
= ELF32_R_TYPE (rel
->r_info
);
2544 if (r_symndx
< extsymoff
)
2548 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
2550 (*_bfd_error_handler
) (_("%s: Malformed reloc detected for section %s"), abfd
, name
);
2551 bfd_set_error (bfd_error_bad_value
);
2556 h
= sym_hashes
[r_symndx
- extsymoff
];
2558 /* This may be an indirect symbol created because of a version. */
2561 while (h
->root
.type
== bfd_link_hash_indirect
)
2562 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
2566 /* Some relocs require a global offset table. */
2567 if (dynobj
== NULL
|| sgot
== NULL
)
2572 case R_SCORE_CALL15
:
2574 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2575 if (!score_elf_create_got_section (dynobj
, info
, FALSE
))
2577 g
= score_elf_got_info (dynobj
, &sgot
);
2581 if (dynobj
== NULL
&& (info
->shared
|| h
!= NULL
) && (sec
->flags
& SEC_ALLOC
) != 0)
2582 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2589 if (!h
&& (r_type
== R_SCORE_GOT_LO16
))
2591 if (! score_elf_record_local_got_symbol (abfd
, r_symndx
, rel
->r_addend
, g
))
2597 case R_SCORE_CALL15
:
2600 (*_bfd_error_handler
)
2601 (_("%B: CALL15 reloc at 0x%lx not against global symbol"),
2602 abfd
, (unsigned long) rel
->r_offset
);
2603 bfd_set_error (bfd_error_bad_value
);
2608 /* This symbol requires a global offset table entry. */
2609 if (! score_elf_record_global_got_symbol (h
, abfd
, info
, g
))
2612 /* We need a stub, not a plt entry for the undefined function. But we record
2613 it as if it needs plt. See _bfd_elf_adjust_dynamic_symbol. */
2619 if (h
&& ! score_elf_record_global_got_symbol (h
, abfd
, info
, g
))
2624 if ((info
->shared
|| h
!= NULL
) && (sec
->flags
& SEC_ALLOC
) != 0)
2628 sreloc
= score_elf_rel_dyn_section (dynobj
, TRUE
);
2632 #define SCORE_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
2635 /* When creating a shared object, we must copy these reloc types into
2636 the output file as R_SCORE_REL32 relocs. We make room for this reloc
2637 in the .rel.dyn reloc section. */
2638 score_elf_allocate_dynamic_relocations (dynobj
, 1);
2639 if ((sec
->flags
& SCORE_READONLY_SECTION
)
2640 == SCORE_READONLY_SECTION
)
2641 /* We tell the dynamic linker that there are
2642 relocations against the text segment. */
2643 info
->flags
|= DF_TEXTREL
;
2647 struct score_elf_link_hash_entry
*hscore
;
2649 /* We only need to copy this reloc if the symbol is
2650 defined in a dynamic object. */
2651 hscore
= (struct score_elf_link_hash_entry
*)h
;
2652 ++hscore
->possibly_dynamic_relocs
;
2653 if ((sec
->flags
& SCORE_READONLY_SECTION
)
2654 == SCORE_READONLY_SECTION
)
2655 /* We need it to tell the dynamic linker if there
2656 are relocations against the text segment. */
2657 hscore
->readonly_reloc
= TRUE
;
2660 /* Even though we don't directly need a GOT entry for this symbol,
2661 a symbol must have a dynamic symbol table index greater that
2662 DT_SCORE_GOTSYM if there are dynamic relocations against it. */
2666 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2667 if (! score_elf_create_got_section (dynobj
, info
, TRUE
))
2669 g
= score_elf_got_info (dynobj
, &sgot
);
2670 if (! score_elf_record_global_got_symbol (h
, abfd
, info
, g
))
2676 /* This relocation describes the C++ object vtable hierarchy.
2677 Reconstruct it for later use during GC. */
2678 case R_SCORE_GNU_VTINHERIT
:
2679 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2683 /* This relocation describes which C++ vtable entries are actually
2684 used. Record for later use during GC. */
2685 case R_SCORE_GNU_VTENTRY
:
2686 BFD_ASSERT (h
!= NULL
);
2688 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
2695 /* We must not create a stub for a symbol that has relocations
2696 related to taking the function's address. */
2702 struct score_elf_link_hash_entry
*sh
;
2704 sh
= (struct score_elf_link_hash_entry
*) h
;
2705 sh
->no_fn_stub
= TRUE
;
2708 case R_SCORE_CALL15
:
2717 _bfd_score_elf_add_symbol_hook (bfd
*abfd
,
2718 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2719 Elf_Internal_Sym
*sym
,
2720 const char **namep ATTRIBUTE_UNUSED
,
2721 flagword
*flagsp ATTRIBUTE_UNUSED
,
2725 switch (sym
->st_shndx
)
2728 if (sym
->st_size
> elf_gp_size (abfd
))
2731 case SHN_SCORE_SCOMMON
:
2732 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
2733 (*secp
)->flags
|= SEC_IS_COMMON
;
2734 *valp
= sym
->st_size
;
2742 _bfd_score_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
2744 elf_symbol_type
*elfsym
;
2746 elfsym
= (elf_symbol_type
*) asym
;
2747 switch (elfsym
->internal_elf_sym
.st_shndx
)
2750 if (asym
->value
> elf_gp_size (abfd
))
2753 case SHN_SCORE_SCOMMON
:
2754 if (score_elf_scom_section
.name
== NULL
)
2756 /* Initialize the small common section. */
2757 score_elf_scom_section
.name
= ".scommon";
2758 score_elf_scom_section
.flags
= SEC_IS_COMMON
;
2759 score_elf_scom_section
.output_section
= &score_elf_scom_section
;
2760 score_elf_scom_section
.symbol
= &score_elf_scom_symbol
;
2761 score_elf_scom_section
.symbol_ptr_ptr
= &score_elf_scom_symbol_ptr
;
2762 score_elf_scom_symbol
.name
= ".scommon";
2763 score_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
2764 score_elf_scom_symbol
.section
= &score_elf_scom_section
;
2765 score_elf_scom_symbol_ptr
= &score_elf_scom_symbol
;
2767 asym
->section
= &score_elf_scom_section
;
2768 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
2774 _bfd_score_elf_link_output_symbol_hook (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2775 const char *name ATTRIBUTE_UNUSED
,
2776 Elf_Internal_Sym
*sym
,
2777 asection
*input_sec
,
2778 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
2780 /* If we see a common symbol, which implies a relocatable link, then
2781 if a symbol was small common in an input file, mark it as small
2782 common in the output file. */
2783 if (sym
->st_shndx
== SHN_COMMON
&& strcmp (input_sec
->name
, ".scommon") == 0)
2784 sym
->st_shndx
= SHN_SCORE_SCOMMON
;
2790 _bfd_score_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
2794 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
2796 *retval
= SHN_SCORE_SCOMMON
;
2803 /* Adjust a symbol defined by a dynamic object and referenced by a
2804 regular object. The current definition is in some section of the
2805 dynamic object, but we're not including those sections. We have to
2806 change the definition to something the rest of the link can understand. */
2809 _bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2810 struct elf_link_hash_entry
*h
)
2813 struct score_elf_link_hash_entry
*hscore
;
2816 dynobj
= elf_hash_table (info
)->dynobj
;
2818 /* Make sure we know what is going on here. */
2819 BFD_ASSERT (dynobj
!= NULL
2821 || h
->u
.weakdef
!= NULL
2822 || (h
->def_dynamic
&& h
->ref_regular
&& !h
->def_regular
)));
2824 /* If this symbol is defined in a dynamic object, we need to copy
2825 any R_SCORE_ABS32 or R_SCORE_REL32 relocs against it into the output
2827 hscore
= (struct score_elf_link_hash_entry
*)h
;
2828 if (!info
->relocatable
2829 && hscore
->possibly_dynamic_relocs
!= 0
2830 && (h
->root
.type
== bfd_link_hash_defweak
|| !h
->def_regular
))
2832 score_elf_allocate_dynamic_relocations (dynobj
, hscore
->possibly_dynamic_relocs
);
2833 if (hscore
->readonly_reloc
)
2834 /* We tell the dynamic linker that there are relocations
2835 against the text segment. */
2836 info
->flags
|= DF_TEXTREL
;
2839 /* For a function, create a stub, if allowed. */
2840 if (!hscore
->no_fn_stub
&& h
->needs_plt
)
2842 if (!elf_hash_table (info
)->dynamic_sections_created
)
2845 /* If this symbol is not defined in a regular file, then set
2846 the symbol to the stub location. This is required to make
2847 function pointers compare as equal between the normal
2848 executable and the shared library. */
2849 if (!h
->def_regular
)
2851 /* We need .stub section. */
2852 s
= bfd_get_section_by_name (dynobj
, SCORE_ELF_STUB_SECTION_NAME
);
2853 BFD_ASSERT (s
!= NULL
);
2855 h
->root
.u
.def
.section
= s
;
2856 h
->root
.u
.def
.value
= s
->size
;
2858 /* XXX Write this stub address somewhere. */
2859 h
->plt
.offset
= s
->size
;
2861 /* Make room for this stub code. */
2862 s
->size
+= SCORE_FUNCTION_STUB_SIZE
;
2864 /* The last half word of the stub will be filled with the index
2865 of this symbol in .dynsym section. */
2869 else if ((h
->type
== STT_FUNC
) && !h
->needs_plt
)
2871 /* This will set the entry for this symbol in the GOT to 0, and
2872 the dynamic linker will take care of this. */
2873 h
->root
.u
.def
.value
= 0;
2877 /* If this is a weak symbol, and there is a real definition, the
2878 processor independent code will have arranged for us to see the
2879 real definition first, and we can just use the same value. */
2880 if (h
->u
.weakdef
!= NULL
)
2882 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2883 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2884 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2885 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2889 /* This is a reference to a symbol defined by a dynamic object which
2890 is not a function. */
2894 /* This function is called after all the input files have been read,
2895 and the input sections have been assigned to output sections. */
2898 _bfd_score_elf_always_size_sections (bfd
*output_bfd
,
2899 struct bfd_link_info
*info
)
2903 struct score_got_info
*g
;
2905 bfd_size_type loadable_size
= 0;
2906 bfd_size_type local_gotno
;
2909 dynobj
= elf_hash_table (info
)->dynobj
;
2911 /* Relocatable links don't have it. */
2914 g
= score_elf_got_info (dynobj
, &s
);
2918 /* Calculate the total loadable size of the output. That will give us the
2919 maximum number of GOT_PAGE entries required. */
2920 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
2922 asection
*subsection
;
2924 for (subsection
= sub
->sections
;
2926 subsection
= subsection
->next
)
2928 if ((subsection
->flags
& SEC_ALLOC
) == 0)
2930 loadable_size
+= ((subsection
->size
+ 0xf)
2931 &~ (bfd_size_type
) 0xf);
2935 /* There has to be a global GOT entry for every symbol with
2936 a dynamic symbol table index of DT_SCORE_GOTSYM or
2937 higher. Therefore, it make sense to put those symbols
2938 that need GOT entries at the end of the symbol table. We
2940 if (! score_elf_sort_hash_table (info
, 1))
2943 if (g
->global_gotsym
!= NULL
)
2944 i
= elf_hash_table (info
)->dynsymcount
- g
->global_gotsym
->dynindx
;
2946 /* If there are no global symbols, or none requiring
2947 relocations, then GLOBAL_GOTSYM will be NULL. */
2950 /* In the worst case, we'll get one stub per dynamic symbol. */
2951 loadable_size
+= SCORE_FUNCTION_STUB_SIZE
* i
;
2953 /* Assume there are two loadable segments consisting of
2954 contiguous sections. Is 5 enough? */
2955 local_gotno
= (loadable_size
>> 16) + 5;
2957 g
->local_gotno
+= local_gotno
;
2958 s
->size
+= g
->local_gotno
* SCORE_ELF_GOT_SIZE (output_bfd
);
2960 g
->global_gotno
= i
;
2961 s
->size
+= i
* SCORE_ELF_GOT_SIZE (output_bfd
);
2963 score_elf_resolve_final_got_entries (g
);
2965 if (s
->size
> SCORE_ELF_GOT_MAX_SIZE (output_bfd
))
2967 /* Fixme. Error message or Warning message should be issued here. */
2973 /* Set the sizes of the dynamic sections. */
2976 _bfd_score_elf_size_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
2980 bfd_boolean reltext
;
2982 dynobj
= elf_hash_table (info
)->dynobj
;
2983 BFD_ASSERT (dynobj
!= NULL
);
2985 if (elf_hash_table (info
)->dynamic_sections_created
)
2987 /* Set the contents of the .interp section to the interpreter. */
2990 s
= bfd_get_section_by_name (dynobj
, ".interp");
2991 BFD_ASSERT (s
!= NULL
);
2992 s
->size
= strlen (ELF_DYNAMIC_INTERPRETER
) + 1;
2993 s
->contents
= (bfd_byte
*) ELF_DYNAMIC_INTERPRETER
;
2997 /* The check_relocs and adjust_dynamic_symbol entry points have
2998 determined the sizes of the various dynamic sections. Allocate
3001 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3005 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3008 /* It's OK to base decisions on the section name, because none
3009 of the dynobj section names depend upon the input files. */
3010 name
= bfd_get_section_name (dynobj
, s
);
3012 if (CONST_STRNEQ (name
, ".rel"))
3016 /* We only strip the section if the output section name
3017 has the same name. Otherwise, there might be several
3018 input sections for this output section. FIXME: This
3019 code is probably not needed these days anyhow, since
3020 the linker now does not create empty output sections. */
3021 if (s
->output_section
!= NULL
3023 bfd_get_section_name (s
->output_section
->owner
,
3024 s
->output_section
)) == 0)
3025 s
->flags
|= SEC_EXCLUDE
;
3029 const char *outname
;
3032 /* If this relocation section applies to a read only
3033 section, then we probably need a DT_TEXTREL entry.
3034 If the relocation section is .rel.dyn, we always
3035 assert a DT_TEXTREL entry rather than testing whether
3036 there exists a relocation to a read only section or
3038 outname
= bfd_get_section_name (output_bfd
, s
->output_section
);
3039 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
3041 && (target
->flags
& SEC_READONLY
) != 0
3042 && (target
->flags
& SEC_ALLOC
) != 0) || strcmp (outname
, ".rel.dyn") == 0)
3045 /* We use the reloc_count field as a counter if we need
3046 to copy relocs into the output file. */
3047 if (strcmp (name
, ".rel.dyn") != 0)
3051 else if (CONST_STRNEQ (name
, ".got"))
3053 /* _bfd_score_elf_always_size_sections() has already done
3054 most of the work, but some symbols may have been mapped
3055 to versions that we must now resolve in the got_entries
3058 else if (strcmp (name
, SCORE_ELF_STUB_SECTION_NAME
) == 0)
3060 /* IRIX rld assumes that the function stub isn't at the end
3061 of .text section. So put a dummy. XXX */
3062 s
->size
+= SCORE_FUNCTION_STUB_SIZE
;
3064 else if (! CONST_STRNEQ (name
, ".init"))
3066 /* It's not one of our sections, so don't allocate space. */
3070 /* Allocate memory for the section contents. */
3071 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
3072 if (s
->contents
== NULL
&& s
->size
!= 0)
3074 bfd_set_error (bfd_error_no_memory
);
3079 if (elf_hash_table (info
)->dynamic_sections_created
)
3081 /* Add some entries to the .dynamic section. We fill in the
3082 values later, in _bfd_score_elf_finish_dynamic_sections, but we
3083 must add the entries now so that we get the correct size for
3084 the .dynamic section. The DT_DEBUG entry is filled in by the
3085 dynamic linker and used by the debugger. */
3087 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
3091 info
->flags
|= DF_TEXTREL
;
3093 if ((info
->flags
& DF_TEXTREL
) != 0)
3095 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
3099 if (! SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
3102 if (score_elf_rel_dyn_section (dynobj
, FALSE
))
3104 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
3107 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
3110 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
3114 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_SCORE_BASE_ADDRESS
, 0))
3117 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_SCORE_LOCAL_GOTNO
, 0))
3120 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_SCORE_SYMTABNO
, 0))
3123 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_SCORE_UNREFEXTNO
, 0))
3126 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_SCORE_GOTSYM
, 0))
3129 if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info
, DT_SCORE_HIPAGENO
, 0))
3137 _bfd_score_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3139 struct elf_link_hash_entry
*h
;
3140 struct bfd_link_hash_entry
*bh
;
3144 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3145 | SEC_LINKER_CREATED
| SEC_READONLY
);
3147 /* ABI requests the .dynamic section to be read only. */
3148 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3151 if (!bfd_set_section_flags (abfd
, s
, flags
))
3155 /* We need to create .got section. */
3156 if (!score_elf_create_got_section (abfd
, info
, FALSE
))
3159 if (!score_elf_rel_dyn_section (elf_hash_table (info
)->dynobj
, TRUE
))
3162 /* Create .stub section. */
3163 if (bfd_get_section_by_name (abfd
, SCORE_ELF_STUB_SECTION_NAME
) == NULL
)
3165 s
= bfd_make_section_with_flags (abfd
, SCORE_ELF_STUB_SECTION_NAME
,
3168 || !bfd_set_section_alignment (abfd
, s
, 2))
3177 name
= "_DYNAMIC_LINK";
3179 if (!(_bfd_generic_link_add_one_symbol
3180 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
3181 (bfd_vma
) 0, (const char *)NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
3184 h
= (struct elf_link_hash_entry
*)bh
;
3187 h
->type
= STT_SECTION
;
3189 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3197 /* Finish up dynamic symbol handling. We set the contents of various
3198 dynamic sections here. */
3201 _bfd_score_elf_finish_dynamic_symbol (bfd
*output_bfd
,
3202 struct bfd_link_info
*info
,
3203 struct elf_link_hash_entry
*h
,
3204 Elf_Internal_Sym
*sym
)
3208 struct score_got_info
*g
;
3211 dynobj
= elf_hash_table (info
)->dynobj
;
3213 if (h
->plt
.offset
!= MINUS_ONE
)
3216 bfd_byte stub
[SCORE_FUNCTION_STUB_SIZE
];
3218 /* This symbol has a stub. Set it up. */
3219 BFD_ASSERT (h
->dynindx
!= -1);
3221 s
= bfd_get_section_by_name (dynobj
, SCORE_ELF_STUB_SECTION_NAME
);
3222 BFD_ASSERT (s
!= NULL
);
3224 /* FIXME: Can h->dynindex be more than 64K? */
3225 if (h
->dynindx
& 0xffff0000)
3228 /* Fill the stub. */
3229 bfd_put_32 (output_bfd
, STUB_LW
, stub
);
3230 bfd_put_32 (output_bfd
, STUB_MOVE
, stub
+ 4);
3231 bfd_put_32 (output_bfd
, STUB_LI16
| (h
->dynindx
<< 1), stub
+ 8);
3232 bfd_put_32 (output_bfd
, STUB_BRL
, stub
+ 12);
3234 BFD_ASSERT (h
->plt
.offset
<= s
->size
);
3235 memcpy (s
->contents
+ h
->plt
.offset
, stub
, SCORE_FUNCTION_STUB_SIZE
);
3237 /* Mark the symbol as undefined. plt.offset != -1 occurs
3238 only for the referenced symbol. */
3239 sym
->st_shndx
= SHN_UNDEF
;
3241 /* The run-time linker uses the st_value field of the symbol
3242 to reset the global offset table entry for this external
3243 to its stub address when unlinking a shared object. */
3244 sym
->st_value
= (s
->output_section
->vma
+ s
->output_offset
+ h
->plt
.offset
);
3247 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
3249 sgot
= score_elf_got_section (dynobj
, FALSE
);
3250 BFD_ASSERT (sgot
!= NULL
);
3251 BFD_ASSERT (score_elf_section_data (sgot
) != NULL
);
3252 g
= score_elf_section_data (sgot
)->u
.got_info
;
3253 BFD_ASSERT (g
!= NULL
);
3255 /* Run through the global symbol table, creating GOT entries for all
3256 the symbols that need them. */
3257 if (g
->global_gotsym
!= NULL
&& h
->dynindx
>= g
->global_gotsym
->dynindx
)
3262 value
= sym
->st_value
;
3263 offset
= score_elf_global_got_index (dynobj
, h
);
3264 bfd_put_32 (output_bfd
, value
, sgot
->contents
+ offset
);
3267 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
3268 name
= h
->root
.root
.string
;
3269 if (strcmp (name
, "_DYNAMIC") == 0 || strcmp (name
, "_GLOBAL_OFFSET_TABLE_") == 0)
3270 sym
->st_shndx
= SHN_ABS
;
3271 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
3273 sym
->st_shndx
= SHN_ABS
;
3274 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
3277 else if (strcmp (name
, GP_DISP_LABEL
) == 0)
3279 sym
->st_shndx
= SHN_ABS
;
3280 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
3281 sym
->st_value
= elf_gp (output_bfd
);
3287 /* Finish up the dynamic sections. */
3290 _bfd_score_elf_finish_dynamic_sections (bfd
*output_bfd
,
3291 struct bfd_link_info
*info
)
3297 struct score_got_info
*g
;
3299 dynobj
= elf_hash_table (info
)->dynobj
;
3301 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3303 sgot
= score_elf_got_section (dynobj
, FALSE
);
3308 BFD_ASSERT (score_elf_section_data (sgot
) != NULL
);
3309 g
= score_elf_section_data (sgot
)->u
.got_info
;
3310 BFD_ASSERT (g
!= NULL
);
3313 if (elf_hash_table (info
)->dynamic_sections_created
)
3317 BFD_ASSERT (sdyn
!= NULL
);
3318 BFD_ASSERT (g
!= NULL
);
3320 for (b
= sdyn
->contents
;
3321 b
< sdyn
->contents
+ sdyn
->size
;
3322 b
+= SCORE_ELF_DYN_SIZE (dynobj
))
3324 Elf_Internal_Dyn dyn
;
3327 bfd_boolean swap_out_p
;
3329 /* Read in the current dynamic entry. */
3330 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
3332 /* Assume that we're going to modify it and write it out. */
3338 s
= score_elf_rel_dyn_section (dynobj
, FALSE
);
3339 BFD_ASSERT (s
!= NULL
);
3340 dyn
.d_un
.d_val
= SCORE_ELF_REL_SIZE (dynobj
);
3344 /* Rewrite DT_STRSZ. */
3345 dyn
.d_un
.d_val
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
3350 s
= bfd_get_section_by_name (output_bfd
, name
);
3351 BFD_ASSERT (s
!= NULL
);
3352 dyn
.d_un
.d_ptr
= s
->vma
;
3355 case DT_SCORE_BASE_ADDRESS
:
3356 s
= output_bfd
->sections
;
3357 BFD_ASSERT (s
!= NULL
);
3358 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
3361 case DT_SCORE_LOCAL_GOTNO
:
3362 dyn
.d_un
.d_val
= g
->local_gotno
;
3365 case DT_SCORE_UNREFEXTNO
:
3366 /* The index into the dynamic symbol table which is the
3367 entry of the first external symbol that is not
3368 referenced within the same object. */
3369 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
3372 case DT_SCORE_GOTSYM
:
3373 if (g
->global_gotsym
)
3375 dyn
.d_un
.d_val
= g
->global_gotsym
->dynindx
;
3378 /* In case if we don't have global got symbols we default
3379 to setting DT_SCORE_GOTSYM to the same value as
3380 DT_SCORE_SYMTABNO, so we just fall through. */
3382 case DT_SCORE_SYMTABNO
:
3384 elemsize
= SCORE_ELF_SYM_SIZE (output_bfd
);
3385 s
= bfd_get_section_by_name (output_bfd
, name
);
3386 BFD_ASSERT (s
!= NULL
);
3388 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
3391 case DT_SCORE_HIPAGENO
:
3392 dyn
.d_un
.d_val
= g
->local_gotno
- SCORE_RESERVED_GOTNO
;
3401 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
) (dynobj
, &dyn
, b
);
3405 /* The first entry of the global offset table will be filled at
3406 runtime. The second entry will be used by some runtime loaders.
3407 This isn't the case of IRIX rld. */
3408 if (sgot
!= NULL
&& sgot
->size
> 0)
3410 bfd_put_32 (output_bfd
, 0, sgot
->contents
);
3411 bfd_put_32 (output_bfd
, 0x80000000, sgot
->contents
+ SCORE_ELF_GOT_SIZE (output_bfd
));
3415 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
3416 = SCORE_ELF_GOT_SIZE (output_bfd
);
3419 /* We need to sort the entries of the dynamic relocation section. */
3420 s
= score_elf_rel_dyn_section (dynobj
, FALSE
);
3422 if (s
!= NULL
&& s
->size
> (bfd_vma
)2 * SCORE_ELF_REL_SIZE (output_bfd
))
3424 reldyn_sorting_bfd
= output_bfd
;
3425 qsort ((Elf32_External_Rel
*) s
->contents
+ 1, s
->reloc_count
- 1,
3426 sizeof (Elf32_External_Rel
), score_elf_sort_dynamic_relocs
);
3432 /* This function set up the ELF section header for a BFD section in preparation for writing
3433 it out. This is where the flags and type fields are set for unusual sections. */
3436 _bfd_score_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
3437 Elf_Internal_Shdr
*hdr
,
3442 name
= bfd_get_section_name (abfd
, sec
);
3444 if (strcmp (name
, ".got") == 0
3445 || strcmp (name
, ".srdata") == 0
3446 || strcmp (name
, ".sdata") == 0
3447 || strcmp (name
, ".sbss") == 0)
3448 hdr
->sh_flags
|= SHF_SCORE_GPREL
;
3453 /* This function do additional processing on the ELF section header before writing
3454 it out. This is used to set the flags and type fields for some sections. */
3456 /* assign_file_positions_except_relocs() check section flag and if it is allocatable,
3457 warning message will be issued. backend_fake_section is called before
3458 assign_file_positions_except_relocs(); backend_section_processing after it. so, we
3459 modify section flag there, but not backend_fake_section. */
3462 _bfd_score_elf_section_processing (bfd
*abfd ATTRIBUTE_UNUSED
, Elf_Internal_Shdr
*hdr
)
3464 if (hdr
->bfd_section
!= NULL
)
3466 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
3468 if (strcmp (name
, ".sdata") == 0)
3470 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_SCORE_GPREL
;
3471 hdr
->sh_type
= SHT_PROGBITS
;
3473 else if (strcmp (name
, ".sbss") == 0)
3475 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_SCORE_GPREL
;
3476 hdr
->sh_type
= SHT_NOBITS
;
3478 else if (strcmp (name
, ".srdata") == 0)
3480 hdr
->sh_flags
|= SHF_ALLOC
| SHF_SCORE_GPREL
;
3481 hdr
->sh_type
= SHT_PROGBITS
;
3489 _bfd_score_elf_write_section (bfd
*output_bfd
,
3490 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
3491 asection
*sec
, bfd_byte
*contents
)
3493 bfd_byte
*to
, *from
, *end
;
3496 if (strcmp (sec
->name
, ".pdr") != 0)
3499 if (score_elf_section_data (sec
)->u
.tdata
== NULL
)
3503 end
= contents
+ sec
->size
;
3504 for (from
= contents
, i
= 0; from
< end
; from
+= PDR_SIZE
, i
++)
3506 if ((score_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
3510 memcpy (to
, from
, PDR_SIZE
);
3514 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
3515 (file_ptr
) sec
->output_offset
, sec
->size
);
3520 /* Copy data from a SCORE ELF indirect symbol to its direct symbol, hiding the old
3521 indirect symbol. Process additional relocation information. */
3524 _bfd_score_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3525 struct elf_link_hash_entry
*dir
,
3526 struct elf_link_hash_entry
*ind
)
3528 struct score_elf_link_hash_entry
*dirscore
, *indscore
;
3530 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3532 if (ind
->root
.type
!= bfd_link_hash_indirect
)
3535 dirscore
= (struct score_elf_link_hash_entry
*) dir
;
3536 indscore
= (struct score_elf_link_hash_entry
*) ind
;
3537 dirscore
->possibly_dynamic_relocs
+= indscore
->possibly_dynamic_relocs
;
3539 if (indscore
->readonly_reloc
)
3540 dirscore
->readonly_reloc
= TRUE
;
3542 if (indscore
->no_fn_stub
)
3543 dirscore
->no_fn_stub
= TRUE
;
3546 /* Remove information about discarded functions from other sections which mention them. */
3549 _bfd_score_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
3550 struct bfd_link_info
*info
)
3553 bfd_boolean ret
= FALSE
;
3554 unsigned char *tdata
;
3557 o
= bfd_get_section_by_name (abfd
, ".pdr");
3558 if ((!o
) || (o
->size
== 0) || (o
->size
% PDR_SIZE
!= 0)
3559 || (o
->output_section
!= NULL
&& bfd_is_abs_section (o
->output_section
)))
3562 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
3566 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
, info
->keep_memory
);
3573 cookie
->rel
= cookie
->rels
;
3574 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
3576 for (i
= 0, skip
= 0; i
< o
->size
; i
++)
3578 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
3587 score_elf_section_data (o
)->u
.tdata
= tdata
;
3588 o
->size
-= skip
* PDR_SIZE
;
3594 if (!info
->keep_memory
)
3595 free (cookie
->rels
);
3600 /* Signal that discard_info() has removed the discarded relocations for this section. */
3603 _bfd_score_elf_ignore_discarded_relocs (asection
*sec
)
3605 if (strcmp (sec
->name
, ".pdr") == 0)
3610 /* Return the section that should be marked against GC for a given
3614 _bfd_score_elf_gc_mark_hook (asection
*sec
,
3615 struct bfd_link_info
*info
,
3616 Elf_Internal_Rela
*rel
,
3617 struct elf_link_hash_entry
*h
,
3618 Elf_Internal_Sym
*sym
)
3621 switch (ELF32_R_TYPE (rel
->r_info
))
3623 case R_SCORE_GNU_VTINHERIT
:
3624 case R_SCORE_GNU_VTENTRY
:
3628 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
3631 /* Support for core dump NOTE sections. */
3634 _bfd_score_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
3637 unsigned int raw_size
;
3639 switch (note
->descsz
)
3644 case 148: /* Linux/Score 32-bit. */
3646 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3649 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3658 /* Make a ".reg/999" section. */
3659 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
, note
->descpos
+ offset
);
3663 _bfd_score_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
3665 switch (note
->descsz
)
3670 case 124: /* Linux/Score elf_prpsinfo. */
3671 elf_tdata (abfd
)->core_program
= _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
3672 elf_tdata (abfd
)->core_command
= _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
3675 /* Note that for some reason, a spurious space is tacked
3676 onto the end of the args in some (at least one anyway)
3677 implementations, so strip it off if it exists. */
3680 char *command
= elf_tdata (abfd
)->core_command
;
3681 int n
= strlen (command
);
3683 if (0 < n
&& command
[n
- 1] == ' ')
3684 command
[n
- 1] = '\0';
3691 /* Score BFD functions. */
3693 static reloc_howto_type
*
3694 elf32_score_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_reloc_code_real_type code
)
3698 for (i
= 0; i
< NUM_ELEM (elf32_score_reloc_map
); i
++)
3699 if (elf32_score_reloc_map
[i
].bfd_reloc_val
== code
)
3700 return &elf32_score_howto_table
[elf32_score_reloc_map
[i
].elf_reloc_val
];
3705 static reloc_howto_type
*
3706 elf32_score_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
3712 i
< (sizeof (elf32_score_howto_table
)
3713 / sizeof (elf32_score_howto_table
[0]));
3715 if (elf32_score_howto_table
[i
].name
!= NULL
3716 && strcasecmp (elf32_score_howto_table
[i
].name
, r_name
) == 0)
3717 return &elf32_score_howto_table
[i
];
3722 /* Create a score elf linker hash table. */
3724 static struct bfd_link_hash_table
*
3725 elf32_score_link_hash_table_create (bfd
*abfd
)
3727 struct score_elf_link_hash_table
*ret
;
3728 bfd_size_type amt
= sizeof (struct score_elf_link_hash_table
);
3730 ret
= bfd_malloc (amt
);
3734 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, score_elf_link_hash_newfunc
,
3735 sizeof (struct score_elf_link_hash_entry
)))
3741 return &ret
->root
.root
;
3745 elf32_score_print_private_bfd_data (bfd
*abfd
, void * ptr
)
3747 FILE *file
= (FILE *) ptr
;
3749 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3751 /* Print normal ELF private data. */
3752 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3754 /* xgettext:c-format */
3755 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
3756 if (elf_elfheader (abfd
)->e_flags
& EF_SCORE_PIC
)
3758 fprintf (file
, _(" [pic]"));
3760 if (elf_elfheader (abfd
)->e_flags
& EF_SCORE_FIXDEP
)
3762 fprintf (file
, _(" [fix dep]"));
3770 elf32_score_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3775 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
3778 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3779 out_flags
= elf_elfheader (obfd
)->e_flags
;
3781 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3782 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3785 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3786 out_flags
= elf_elfheader (obfd
)->e_flags
;
3788 if (! elf_flags_init (obfd
))
3790 elf_flags_init (obfd
) = TRUE
;
3791 elf_elfheader (obfd
)->e_flags
= in_flags
;
3793 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3794 && bfd_get_arch_info (obfd
)->the_default
)
3796 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
3802 if (((in_flags
& EF_SCORE_PIC
) != 0) != ((out_flags
& EF_SCORE_PIC
) != 0))
3804 (*_bfd_error_handler
) (_("%B: warning: linking PIC files with non-PIC files"), ibfd
);
3807 /* FIXME: Maybe dependency fix compatibility should be checked here. */
3813 elf32_score_new_section_hook (bfd
*abfd
, asection
*sec
)
3815 struct _score_elf_section_data
*sdata
;
3816 bfd_size_type amt
= sizeof (*sdata
);
3818 sdata
= bfd_zalloc (abfd
, amt
);
3821 sec
->used_by_bfd
= sdata
;
3823 return _bfd_elf_new_section_hook (abfd
, sec
);
3828 #define TARGET_LITTLE_SYM bfd_elf32_littlescore_vec
3829 #define TARGET_LITTLE_NAME "elf32-littlescore"
3830 #define TARGET_BIG_SYM bfd_elf32_bigscore_vec
3831 #define TARGET_BIG_NAME "elf32-bigscore"
3832 #define ELF_ARCH bfd_arch_score
3833 #define ELF_MACHINE_CODE EM_SCORE
3834 #define ELF_MAXPAGESIZE 0x8000
3836 #define elf_info_to_howto 0
3837 #define elf_info_to_howto_rel _bfd_score_info_to_howto
3838 #define elf_backend_relocate_section _bfd_score_elf_relocate_section
3839 #define elf_backend_check_relocs _bfd_score_elf_check_relocs
3840 #define elf_backend_add_symbol_hook _bfd_score_elf_add_symbol_hook
3841 #define elf_backend_symbol_processing _bfd_score_elf_symbol_processing
3842 #define elf_backend_link_output_symbol_hook \
3843 _bfd_score_elf_link_output_symbol_hook
3844 #define elf_backend_section_from_bfd_section \
3845 _bfd_score_elf_section_from_bfd_section
3846 #define elf_backend_adjust_dynamic_symbol \
3847 _bfd_score_elf_adjust_dynamic_symbol
3848 #define elf_backend_always_size_sections \
3849 _bfd_score_elf_always_size_sections
3850 #define elf_backend_size_dynamic_sections \
3851 _bfd_score_elf_size_dynamic_sections
3852 #define elf_backend_omit_section_dynsym \
3853 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
3854 #define elf_backend_create_dynamic_sections \
3855 _bfd_score_elf_create_dynamic_sections
3856 #define elf_backend_finish_dynamic_symbol \
3857 _bfd_score_elf_finish_dynamic_symbol
3858 #define elf_backend_finish_dynamic_sections \
3859 _bfd_score_elf_finish_dynamic_sections
3860 #define elf_backend_fake_sections _bfd_score_elf_fake_sections
3861 #define elf_backend_section_processing _bfd_score_elf_section_processing
3862 #define elf_backend_write_section _bfd_score_elf_write_section
3863 #define elf_backend_copy_indirect_symbol _bfd_score_elf_copy_indirect_symbol
3864 #define elf_backend_hide_symbol _bfd_score_elf_hide_symbol
3865 #define elf_backend_discard_info _bfd_score_elf_discard_info
3866 #define elf_backend_ignore_discarded_relocs \
3867 _bfd_score_elf_ignore_discarded_relocs
3868 #define elf_backend_gc_mark_hook _bfd_score_elf_gc_mark_hook
3869 #define elf_backend_grok_prstatus _bfd_score_elf_grok_prstatus
3870 #define elf_backend_grok_psinfo _bfd_score_elf_grok_psinfo
3871 #define elf_backend_can_gc_sections 1
3872 #define elf_backend_want_plt_sym 0
3873 #define elf_backend_got_header_size (4 * SCORE_RESERVED_GOTNO)
3874 #define elf_backend_plt_header_size 0
3875 #define elf_backend_collect TRUE
3876 #define elf_backend_type_change_ok TRUE
3878 #define bfd_elf32_bfd_reloc_type_lookup elf32_score_reloc_type_lookup
3879 #define bfd_elf32_bfd_reloc_name_lookup \
3880 elf32_score_reloc_name_lookup
3881 #define bfd_elf32_bfd_link_hash_table_create elf32_score_link_hash_table_create
3882 #define bfd_elf32_bfd_print_private_bfd_data elf32_score_print_private_bfd_data
3883 #define bfd_elf32_bfd_merge_private_bfd_data elf32_score_merge_private_bfd_data
3884 #define bfd_elf32_new_section_hook elf32_score_new_section_hook
3886 #include "elf32-target.h"