1 /* 32-bit ELF support for S+core.
2 Copyright 2006 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 2 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, MA 02110-1301, USA. */
26 #include "libiberty.h"
28 #include "elf/score.h"
29 #include "elf/common.h"
30 #include "elf/internal.h"
34 /* Score ELF linker hash table. */
36 struct score_elf_link_hash_table
38 /* The main hash table. */
39 struct elf_link_hash_table root
;
42 /* The SCORE ELF linker needs additional information for each symbol in
43 the global hash table. */
45 struct score_elf_link_hash_entry
47 struct elf_link_hash_entry root
;
49 /* Number of R_SCORE_ABS32, R_SCORE_REL32 relocs against this symbol. */
50 unsigned int possibly_dynamic_relocs
;
52 /* If the R_SCORE_ABS32, R_SCORE_REL32 reloc is against a readonly section. */
53 bfd_boolean readonly_reloc
;
55 /* We must not create a stub for a symbol that has relocations related to
56 taking the function's address, i.e. any but R_SCORE_CALL15 ones. */
57 bfd_boolean no_fn_stub
;
59 /* Are we forced local? This will only be set if we have converted
60 the initial global GOT entry to a local GOT entry. */
61 bfd_boolean forced_local
;
64 /* Traverse a score ELF linker hash table. */
65 #define score_elf_link_hash_traverse(table, func, info) \
66 (elf_link_hash_traverse \
68 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
71 /* Get the SCORE elf linker hash table from a link_info structure. */
72 #define score_elf_hash_table(info) \
73 ((struct score_elf_link_hash_table *) ((info)->hash))
75 /* This structure is used to hold .got entries while estimating got sizes. */
76 struct score_got_entry
78 /* The input bfd in which the symbol is defined. */
80 /* The index of the symbol, as stored in the relocation r_info, if
81 we have a local symbol; -1 otherwise. */
85 /* If abfd == NULL, an address that must be stored in the got. */
87 /* If abfd != NULL && symndx != -1, the addend of the relocation
88 that should be added to the symbol value. */
90 /* If abfd != NULL && symndx == -1, the hash table entry
91 corresponding to a global symbol in the got (or, local, if
93 struct score_elf_link_hash_entry
*h
;
96 /* The offset from the beginning of the .got section to the entry
97 corresponding to this symbol+addend. If it's a global symbol
98 whose offset is yet to be decided, it's going to be -1. */
102 /* This structure is passed to score_elf_sort_hash_table_f when sorting
103 the dynamic symbols. */
105 struct score_elf_hash_sort_data
107 /* The symbol in the global GOT with the lowest dynamic symbol table index. */
108 struct elf_link_hash_entry
*low
;
109 /* The least dynamic symbol table index corresponding to a symbol with a GOT entry. */
110 long min_got_dynindx
;
111 /* The greatest dynamic symbol table index corresponding to a symbol
112 with a GOT entry that is not referenced (e.g., a dynamic symbol
113 with dynamic relocations pointing to it from non-primary GOTs). */
114 long max_unref_got_dynindx
;
115 /* The greatest dynamic symbol table index not corresponding to a
116 symbol without a GOT entry. */
117 long max_non_got_dynindx
;
120 struct score_got_info
122 /* The global symbol in the GOT with the lowest index in the dynamic
124 struct elf_link_hash_entry
*global_gotsym
;
125 /* The number of global .got entries. */
126 unsigned int global_gotno
;
127 /* The number of local .got entries. */
128 unsigned int local_gotno
;
129 /* The number of local .got entries we have used. */
130 unsigned int assigned_gotno
;
131 /* A hash table holding members of the got. */
132 struct htab
*got_entries
;
133 /* In multi-got links, a pointer to the next got (err, rather, most
134 of the time, it points to the previous got). */
135 struct score_got_info
*next
;
138 /* A structure used to count GOT entries, for GOT entry or ELF symbol table traversal. */
139 struct _score_elf_section_data
141 struct bfd_elf_section_data elf
;
144 struct score_got_info
*got_info
;
150 #define score_elf_section_data(sec) \
151 ((struct _score_elf_section_data *) elf_section_data (sec))
153 /* The size of a symbol-table entry. */
154 #define SCORE_ELF_SYM_SIZE(abfd) \
155 (get_elf_backend_data (abfd)->s->sizeof_sym)
157 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
158 from smaller values. Start with zero, widen, *then* decrement. */
159 #define MINUS_ONE (((bfd_vma)0) - 1)
160 #define MINUS_TWO (((bfd_vma)0) - 2)
165 /* The number of local .got entries we reserve. */
166 #define SCORE_RESERVED_GOTNO (2)
167 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
169 /* The offset of $gp from the beginning of the .got section. */
170 #define ELF_SCORE_GP_OFFSET(abfd) (0x3ff0)
171 /* The maximum size of the GOT for it to be addressable using 15-bit offsets from $gp. */
172 #define SCORE_ELF_GOT_MAX_SIZE(abfd) (ELF_SCORE_GP_OFFSET(abfd) + 0x3fff)
174 #define SCORE_ELF_STUB_SECTION_NAME (".SCORE.stub")
175 #define SCORE_FUNCTION_STUB_SIZE (16)
177 #define STUB_LW 0xc3bcc010 /* lw r29, [r28, -0x3ff0] */
178 #define STUB_MOVE 0x8363bc56 /* mv r27, r3 */
179 #define STUB_LI16 0x87548000 /* ori r26, .dynsym_index */
180 #define STUB_BRL 0x801dbc09 /* brl r29 */
182 #define SCORE_ELF_GOT_SIZE(abfd) \
183 (get_elf_backend_data (abfd)->s->arch_size / 8)
185 #define SCORE_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
186 (_bfd_elf_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
188 /* The size of an external dynamic table entry. */
189 #define SCORE_ELF_DYN_SIZE(abfd) \
190 (get_elf_backend_data (abfd)->s->sizeof_dyn)
192 /* The size of an external REL relocation. */
193 #define SCORE_ELF_REL_SIZE(abfd) \
194 (get_elf_backend_data (abfd)->s->sizeof_rel)
196 /* The default alignment for sections, as a power of two. */
197 #define SCORE_ELF_LOG_FILE_ALIGN(abfd)\
198 (get_elf_backend_data (abfd)->s->log_file_align)
201 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
204 static bfd_byte
*hi16_rel_addr
;
206 /* This will be used when we sort the dynamic relocation records. */
207 static bfd
*reldyn_sorting_bfd
;
209 /* SCORE ELF uses two common sections. One is the usual one, and the
210 other is for small objects. All the small objects are kept
211 together, and then referenced via the gp pointer, which yields
212 faster assembler code. This is what we use for the small common
213 section. This approach is copied from ecoff.c. */
214 static asection score_elf_scom_section
;
215 static asymbol score_elf_scom_symbol
;
216 static asymbol
*score_elf_scom_symbol_ptr
;
218 static bfd_reloc_status_type
219 score_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
220 arelent
*reloc_entry
,
221 asymbol
*symbol ATTRIBUTE_UNUSED
,
223 asection
*input_section ATTRIBUTE_UNUSED
,
224 bfd
*output_bfd ATTRIBUTE_UNUSED
,
225 char **error_message ATTRIBUTE_UNUSED
)
227 hi16_rel_addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
231 static bfd_reloc_status_type
232 score_elf_lo16_reloc (bfd
*abfd
,
233 arelent
*reloc_entry
,
234 asymbol
*symbol ATTRIBUTE_UNUSED
,
236 asection
*input_section
,
237 bfd
*output_bfd ATTRIBUTE_UNUSED
,
238 char **error_message ATTRIBUTE_UNUSED
)
240 bfd_vma addend
= 0, offset
= 0;
242 unsigned long hi16_offset
, hi16_value
, uvalue
;
244 hi16_value
= bfd_get_32 (abfd
, hi16_rel_addr
);
245 hi16_offset
= ((((hi16_value
>> 16) & 0x3) << 15) | (hi16_value
& 0x7fff)) >> 1;
246 addend
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
247 offset
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
248 val
= reloc_entry
->addend
;
249 if (reloc_entry
->address
> input_section
->size
)
250 return bfd_reloc_outofrange
;
251 uvalue
= ((hi16_offset
<< 16) | (offset
& 0xffff)) + val
;
252 hi16_offset
= (uvalue
>> 16) << 1;
253 hi16_value
= (hi16_value
& ~0x37fff) | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
254 bfd_put_32 (abfd
, hi16_value
, hi16_rel_addr
);
255 offset
= (uvalue
& 0xffff) << 1;
256 addend
= (addend
& ~0x37fff) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
257 bfd_put_32 (abfd
, addend
, (bfd_byte
*) data
+ reloc_entry
->address
);
261 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
262 dangerous relocation. */
265 score_elf_assign_gp (bfd
*output_bfd
, bfd_vma
*pgp
)
271 /* If we've already figured out what GP will be, just return it. */
272 *pgp
= _bfd_get_gp_value (output_bfd
);
276 count
= bfd_get_symcount (output_bfd
);
277 sym
= bfd_get_outsymbols (output_bfd
);
279 /* The linker script will have created a symbol named `_gp' with the
280 appropriate value. */
285 for (i
= 0; i
< count
; i
++, sym
++)
289 name
= bfd_asymbol_name (*sym
);
290 if (*name
== '_' && strcmp (name
, "_gp") == 0)
292 *pgp
= bfd_asymbol_value (*sym
);
293 _bfd_set_gp_value (output_bfd
, *pgp
);
301 /* Only get the error once. */
303 _bfd_set_gp_value (output_bfd
, *pgp
);
310 /* We have to figure out the gp value, so that we can adjust the
311 symbol value correctly. We look up the symbol _gp in the output
312 BFD. If we can't find it, we're stuck. We cache it in the ELF
313 target data. We don't need to adjust the symbol value for an
314 external symbol if we are producing relocatable output. */
316 static bfd_reloc_status_type
317 score_elf_final_gp (bfd
*output_bfd
,
319 bfd_boolean relocatable
,
320 char **error_message
,
323 if (bfd_is_und_section (symbol
->section
)
327 return bfd_reloc_undefined
;
330 *pgp
= _bfd_get_gp_value (output_bfd
);
333 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
337 /* Make up a value. */
338 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
339 _bfd_set_gp_value (output_bfd
, *pgp
);
341 else if (!score_elf_assign_gp (output_bfd
, pgp
))
344 (char *) _("GP relative relocation when _gp not defined");
345 return bfd_reloc_dangerous
;
352 static bfd_reloc_status_type
353 score_elf_gprel15_with_gp (bfd
*abfd
,
355 arelent
*reloc_entry
,
356 asection
*input_section
,
357 bfd_boolean relocateable
,
359 bfd_vma gp ATTRIBUTE_UNUSED
)
364 if (bfd_is_com_section (symbol
->section
))
367 relocation
= symbol
->value
;
369 relocation
+= symbol
->section
->output_section
->vma
;
370 relocation
+= symbol
->section
->output_offset
;
371 if (reloc_entry
->address
> input_section
->size
)
372 return bfd_reloc_outofrange
;
374 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
375 if (((reloc_entry
->addend
& 0xffffc000) != 0)
376 && ((reloc_entry
->addend
& 0xffffc000) != 0xffffc000))
377 return bfd_reloc_overflow
;
379 insn
= (insn
& ~0x7fff) | (reloc_entry
->addend
& 0x7fff);
380 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
382 reloc_entry
->address
+= input_section
->output_offset
;
387 static bfd_reloc_status_type
388 gprel32_with_gp (bfd
*abfd
, asymbol
*symbol
, arelent
*reloc_entry
,
389 asection
*input_section
, bfd_boolean relocatable
,
390 void *data
, bfd_vma gp
)
395 if (bfd_is_com_section (symbol
->section
))
398 relocation
= symbol
->value
;
400 relocation
+= symbol
->section
->output_section
->vma
;
401 relocation
+= symbol
->section
->output_offset
;
403 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
404 return bfd_reloc_outofrange
;
406 /* Set val to the offset into the section or symbol. */
407 val
= reloc_entry
->addend
;
409 if (reloc_entry
->howto
->partial_inplace
)
410 val
+= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
412 /* Adjust val for the final section location and GP value. If we
413 are producing relocatable output, we don't want to do this for
414 an external symbol. */
416 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
417 val
+= relocation
- gp
;
419 if (reloc_entry
->howto
->partial_inplace
)
420 bfd_put_32 (abfd
, val
, (bfd_byte
*) data
+ reloc_entry
->address
);
422 reloc_entry
->addend
= val
;
425 reloc_entry
->address
+= input_section
->output_offset
;
430 static bfd_reloc_status_type
431 score_elf_gprel15_reloc (bfd
*abfd
,
432 arelent
*reloc_entry
,
435 asection
*input_section
,
437 char **error_message
)
439 bfd_boolean relocateable
;
440 bfd_reloc_status_type ret
;
443 if (output_bfd
!= (bfd
*) NULL
444 && (symbol
->flags
& BSF_SECTION_SYM
) == 0 && reloc_entry
->addend
== 0)
446 reloc_entry
->address
+= input_section
->output_offset
;
449 if (output_bfd
!= (bfd
*) NULL
)
453 relocateable
= FALSE
;
454 output_bfd
= symbol
->section
->output_section
->owner
;
457 ret
= score_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, &gp
);
458 if (ret
!= bfd_reloc_ok
)
461 return score_elf_gprel15_with_gp (abfd
, symbol
, reloc_entry
,
462 input_section
, relocateable
, data
, gp
);
465 /* Do a R_SCORE_GPREL32 relocation. This is a 32 bit value which must
466 become the offset from the gp register. */
468 static bfd_reloc_status_type
469 score_elf_gprel32_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
470 void *data
, asection
*input_section
, bfd
*output_bfd
,
471 char **error_message
)
473 bfd_boolean relocatable
;
474 bfd_reloc_status_type ret
;
477 /* R_SCORE_GPREL32 relocations are defined for local symbols only. */
478 if (output_bfd
!= NULL
479 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
480 && (symbol
->flags
& BSF_LOCAL
) != 0)
482 *error_message
= (char *)
483 _("32bits gp relative relocation occurs for an external symbol");
484 return bfd_reloc_outofrange
;
487 if (output_bfd
!= NULL
)
492 output_bfd
= symbol
->section
->output_section
->owner
;
495 ret
= score_elf_final_gp (output_bfd
, symbol
, relocatable
, error_message
, &gp
);
496 if (ret
!= bfd_reloc_ok
)
500 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
501 relocatable
, data
, gp
);
504 /* A howto special_function for R_SCORE_GOT15 relocations. This is just
505 like any other 16-bit relocation when applied to global symbols, but is
506 treated in the same as R_SCORE_HI16 when applied to local symbols. */
508 static bfd_reloc_status_type
509 score_elf_got15_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
510 void *data
, asection
*input_section
,
511 bfd
*output_bfd
, char **error_message
)
513 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
514 || bfd_is_und_section (bfd_get_section (symbol
))
515 || bfd_is_com_section (bfd_get_section (symbol
)))
516 /* The relocation is against a global symbol. */
517 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
518 input_section
, output_bfd
,
521 return score_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
522 input_section
, output_bfd
, error_message
);
525 static bfd_reloc_status_type
526 score_elf_got_lo16_reloc (bfd
*abfd
,
527 arelent
*reloc_entry
,
528 asymbol
*symbol ATTRIBUTE_UNUSED
,
530 asection
*input_section
,
531 bfd
*output_bfd ATTRIBUTE_UNUSED
,
532 char **error_message ATTRIBUTE_UNUSED
)
534 bfd_vma addend
= 0, offset
= 0;
536 unsigned long hi16_offset
, hi16_value
, uvalue
;
538 hi16_value
= bfd_get_32 (abfd
, hi16_rel_addr
);
539 hi16_offset
= ((((hi16_value
>> 16) & 0x3) << 15) | (hi16_value
& 0x7fff)) >> 1;
540 addend
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
541 offset
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
542 val
= reloc_entry
->addend
;
543 if (reloc_entry
->address
> input_section
->size
)
544 return bfd_reloc_outofrange
;
545 uvalue
= ((hi16_offset
<< 16) | (offset
& 0xffff)) + val
;
546 hi16_offset
= (uvalue
>> 16) & 0x7fff;
547 hi16_value
= (hi16_value
& ~0x37fff) | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
548 bfd_put_32 (abfd
, hi16_value
, hi16_rel_addr
);
549 offset
= (uvalue
& 0xffff) << 1;
550 addend
= (addend
& ~0x37fff) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
551 bfd_put_32 (abfd
, addend
, (bfd_byte
*) data
+ reloc_entry
->address
);
555 static reloc_howto_type elf32_score_howto_table
[] =
558 HOWTO (R_SCORE_NONE
, /* type */
560 0, /* size (0 = byte, 1 = short, 2 = long) */
562 FALSE
, /* pc_relative */
564 complain_overflow_dont
,/* complain_on_overflow */
565 bfd_elf_generic_reloc
, /* special_function */
566 "R_SCORE_NONE", /* name */
567 FALSE
, /* partial_inplace */
570 FALSE
), /* pcrel_offset */
573 HOWTO (R_SCORE_HI16
, /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_dont
,/* complain_on_overflow */
580 score_elf_hi16_reloc
, /* special_function */
581 "R_SCORE_HI16", /* name */
582 TRUE
, /* partial_inplace */
583 0x37fff, /* src_mask */
584 0x37fff, /* dst_mask */
585 FALSE
), /* pcrel_offset */
588 HOWTO (R_SCORE_LO16
, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE
, /* pc_relative */
594 complain_overflow_dont
,/* complain_on_overflow */
595 score_elf_lo16_reloc
, /* special_function */
596 "R_SCORE_LO16", /* name */
597 TRUE
, /* partial_inplace */
598 0x37fff, /* src_mask */
599 0x37fff, /* dst_mask */
600 FALSE
), /* pcrel_offset */
603 HOWTO (R_SCORE_DUMMY1
, /* type */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
607 FALSE
, /* pc_relative */
609 complain_overflow_dont
,/* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_SCORE_DUMMY1", /* name */
612 TRUE
, /* partial_inplace */
613 0x0000ffff, /* src_mask */
614 0x0000ffff, /* dst_mask */
615 FALSE
), /* pcrel_offset */
618 HOWTO (R_SCORE_24
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 FALSE
, /* pc_relative */
624 complain_overflow_dont
,/* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 "R_SCORE_24", /* name */
627 FALSE
, /* partial_inplace */
628 0x3ff7fff, /* src_mask */
629 0x3ff7fff, /* dst_mask */
630 FALSE
), /* pcrel_offset */
633 HOWTO (R_SCORE_PC19
, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 TRUE
, /* pc_relative */
639 complain_overflow_dont
,/* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_SCORE_PC19", /* name */
642 FALSE
, /* partial_inplace */
643 0x3ff03fe, /* src_mask */
644 0x3ff03fe, /* dst_mask */
645 FALSE
), /* pcrel_offset */
648 HOWTO (R_SCORE16_11
, /* type */
650 1, /* size (0 = byte, 1 = short, 2 = long) */
652 FALSE
, /* pc_relative */
654 complain_overflow_dont
,/* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_SCORE16_11", /* name */
657 FALSE
, /* partial_inplace */
658 0x000000ffe, /* src_mask */
659 0x000000ffe, /* dst_mask */
660 FALSE
), /* pcrel_offset */
663 HOWTO (R_SCORE16_PC8
, /* type */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
667 TRUE
, /* pc_relative */
669 complain_overflow_dont
,/* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 "R_SCORE16_PC8", /* name */
672 FALSE
, /* partial_inplace */
673 0x000000ff, /* src_mask */
674 0x000000ff, /* dst_mask */
675 FALSE
), /* pcrel_offset */
677 /* 32 bit absolute */
678 HOWTO (R_SCORE_ABS32
, /* type 8 */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE
, /* pc_relative */
684 complain_overflow_bitfield
, /* complain_on_overflow */
685 bfd_elf_generic_reloc
, /* special_function */
686 "R_SCORE_ABS32", /* name */
687 FALSE
, /* partial_inplace */
688 0xffffffff, /* src_mask */
689 0xffffffff, /* dst_mask */
690 FALSE
), /* pcrel_offset */
692 /* 16 bit absolute */
693 HOWTO (R_SCORE_ABS16
, /* type 11 */
695 1, /* size (0 = byte, 1 = short, 2 = long) */
697 FALSE
, /* pc_relative */
699 complain_overflow_bitfield
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_SCORE_ABS16", /* name */
702 FALSE
, /* partial_inplace */
703 0x0000ffff, /* src_mask */
704 0x0000ffff, /* dst_mask */
705 FALSE
), /* pcrel_offset */
708 HOWTO (R_SCORE_DUMMY2
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 FALSE
, /* pc_relative */
714 complain_overflow_dont
,/* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_SCORE_DUMMY2", /* name */
717 TRUE
, /* partial_inplace */
718 0x00007fff, /* src_mask */
719 0x00007fff, /* dst_mask */
720 FALSE
), /* pcrel_offset */
723 HOWTO (R_SCORE_GP15
, /* type */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
727 FALSE
, /* pc_relative */
729 complain_overflow_dont
,/* complain_on_overflow */
730 score_elf_gprel15_reloc
,/* special_function */
731 "R_SCORE_GP15", /* name */
732 TRUE
, /* partial_inplace */
733 0x00007fff, /* src_mask */
734 0x00007fff, /* dst_mask */
735 FALSE
), /* pcrel_offset */
737 /* GNU extension to record C++ vtable hierarchy. */
738 HOWTO (R_SCORE_GNU_VTINHERIT
, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 FALSE
, /* pc_relative */
744 complain_overflow_dont
,/* complain_on_overflow */
745 NULL
, /* special_function */
746 "R_SCORE_GNU_VTINHERIT", /* name */
747 FALSE
, /* partial_inplace */
750 FALSE
), /* pcrel_offset */
752 /* GNU extension to record C++ vtable member usage */
753 HOWTO (R_SCORE_GNU_VTENTRY
, /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 FALSE
, /* pc_relative */
759 complain_overflow_dont
,/* complain_on_overflow */
760 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
761 "R_SCORE_GNU_VTENTRY", /* name */
762 FALSE
, /* partial_inplace */
765 FALSE
), /* pcrel_offset */
767 /* Reference to global offset table. */
768 HOWTO (R_SCORE_GOT15
, /* type */
770 2, /* size (0 = byte, 1 = short, 2 = long) */
772 FALSE
, /* pc_relative */
774 complain_overflow_signed
, /* complain_on_overflow */
775 score_elf_got15_reloc
, /* special_function */
776 "R_SCORE_GOT15", /* name */
777 TRUE
, /* partial_inplace */
778 0x00007fff, /* src_mask */
779 0x00007fff, /* dst_mask */
780 FALSE
), /* pcrel_offset */
782 /* Low 16 bits of displacement in global offset table. */
783 HOWTO (R_SCORE_GOT_LO16
, /* type */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
787 FALSE
, /* pc_relative */
789 complain_overflow_dont
,/* complain_on_overflow */
790 score_elf_got_lo16_reloc
, /* special_function */
791 "R_SCORE_GOT_LO16", /* name */
792 TRUE
, /* partial_inplace */
793 0x37ffe, /* src_mask */
794 0x37ffe, /* dst_mask */
795 FALSE
), /* pcrel_offset */
797 /* 15 bit call through global offset table. */
798 HOWTO (R_SCORE_CALL15
, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 FALSE
, /* pc_relative */
804 complain_overflow_signed
, /* complain_on_overflow */
805 bfd_elf_generic_reloc
, /* special_function */
806 "R_SCORE_CALL15", /* name */
807 TRUE
, /* partial_inplace */
808 0x0000ffff, /* src_mask */
809 0x0000ffff, /* dst_mask */
810 FALSE
), /* pcrel_offset */
812 /* 32 bit GP relative reference. */
813 HOWTO (R_SCORE_GPREL32
, /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 FALSE
, /* pc_relative */
819 complain_overflow_dont
,/* complain_on_overflow */
820 score_elf_gprel32_reloc
, /* special_function */
821 "R_SCORE_GPREL32", /* name */
822 TRUE
, /* partial_inplace */
823 0xffffffff, /* src_mask */
824 0xffffffff, /* dst_mask */
825 FALSE
), /* pcrel_offset */
827 /* 32 bit symbol relative relocation. */
828 HOWTO (R_SCORE_REL32
, /* type */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
832 FALSE
, /* pc_relative */
834 complain_overflow_dont
,/* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 "R_SCORE_REL32", /* name */
837 TRUE
, /* partial_inplace */
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
840 FALSE
), /* pcrel_offset */
842 /* R_SCORE_DUMMY_HI16 */
843 HOWTO (R_SCORE_DUMMY_HI16
, /* type */
845 2, /* size (0 = byte, 1 = short, 2 = long) */
847 FALSE
, /* pc_relative */
849 complain_overflow_dont
,/* complain_on_overflow */
850 score_elf_hi16_reloc
, /* special_function */
851 "R_SCORE_DUMMY_HI16", /* name */
852 TRUE
, /* partial_inplace */
853 0x37fff, /* src_mask */
854 0x37fff, /* dst_mask */
855 FALSE
), /* pcrel_offset */
858 struct score_reloc_map
860 bfd_reloc_code_real_type bfd_reloc_val
;
861 unsigned char elf_reloc_val
;
864 static const struct score_reloc_map elf32_score_reloc_map
[] =
866 {BFD_RELOC_NONE
, R_SCORE_NONE
},
867 {BFD_RELOC_HI16_S
, R_SCORE_HI16
},
868 {BFD_RELOC_LO16
, R_SCORE_LO16
},
869 {BFD_RELOC_SCORE_DUMMY1
, R_SCORE_DUMMY1
},
870 {BFD_RELOC_SCORE_JMP
, R_SCORE_24
},
871 {BFD_RELOC_SCORE_BRANCH
, R_SCORE_PC19
},
872 {BFD_RELOC_SCORE16_JMP
, R_SCORE16_11
},
873 {BFD_RELOC_SCORE16_BRANCH
, R_SCORE16_PC8
},
874 {BFD_RELOC_32
, R_SCORE_ABS32
},
875 {BFD_RELOC_16
, R_SCORE_ABS16
},
876 {BFD_RELOC_SCORE_DUMMY2
, R_SCORE_DUMMY2
},
877 {BFD_RELOC_SCORE_GPREL15
, R_SCORE_GP15
},
878 {BFD_RELOC_VTABLE_INHERIT
, R_SCORE_GNU_VTINHERIT
},
879 {BFD_RELOC_VTABLE_ENTRY
, R_SCORE_GNU_VTENTRY
},
880 {BFD_RELOC_SCORE_GOT15
, R_SCORE_GOT15
},
881 {BFD_RELOC_SCORE_GOT_LO16
, R_SCORE_GOT_LO16
},
882 {BFD_RELOC_SCORE_CALL15
, R_SCORE_CALL15
},
883 {BFD_RELOC_GPREL32
, R_SCORE_GPREL32
},
884 {BFD_RELOC_32_PCREL
, R_SCORE_REL32
},
885 {BFD_RELOC_SCORE_DUMMY_HI16
, R_SCORE_DUMMY_HI16
},
888 /* got_entries only match if they're identical, except for gotidx, so
889 use all fields to compute the hash, and compare the appropriate
893 score_elf_got_entry_hash (const void *entry_
)
895 const struct score_got_entry
*entry
= (struct score_got_entry
*)entry_
;
898 + (!entry
->abfd
? entry
->d
.address
: entry
->abfd
->id
);
902 score_elf_got_entry_eq (const void *entry1
, const void *entry2
)
904 const struct score_got_entry
*e1
= (struct score_got_entry
*)entry1
;
905 const struct score_got_entry
*e2
= (struct score_got_entry
*)entry2
;
907 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
908 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
909 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
910 : e1
->d
.h
== e2
->d
.h
);
913 /* If H needs a GOT entry, assign it the highest available dynamic
914 index. Otherwise, assign it the lowest available dynamic
918 score_elf_sort_hash_table_f (struct score_elf_link_hash_entry
*h
, void *data
)
920 struct score_elf_hash_sort_data
*hsd
= data
;
922 if (h
->root
.root
.type
== bfd_link_hash_warning
)
923 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
925 /* Symbols without dynamic symbol table entries aren't interesting at all. */
926 if (h
->root
.dynindx
== -1)
929 /* Global symbols that need GOT entries that are not explicitly
930 referenced are marked with got offset 2. Those that are
931 referenced get a 1, and those that don't need GOT entries get
933 if (h
->root
.got
.offset
== 2)
935 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
936 hsd
->low
= (struct elf_link_hash_entry
*) h
;
937 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
939 else if (h
->root
.got
.offset
!= 1)
940 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
943 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
944 hsd
->low
= (struct elf_link_hash_entry
*) h
;
951 score_elf_got_section (bfd
*abfd
, bfd_boolean maybe_excluded
)
953 asection
*sgot
= bfd_get_section_by_name (abfd
, ".got");
955 if (sgot
== NULL
|| (! maybe_excluded
&& (sgot
->flags
& SEC_EXCLUDE
) != 0))
960 /* Returns the GOT information associated with the link indicated by
961 INFO. If SGOTP is non-NULL, it is filled in with the GOT section. */
963 static struct score_got_info
*
964 score_elf_got_info (bfd
*abfd
, asection
**sgotp
)
967 struct score_got_info
*g
;
969 sgot
= score_elf_got_section (abfd
, TRUE
);
970 BFD_ASSERT (sgot
!= NULL
);
971 BFD_ASSERT (elf_section_data (sgot
) != NULL
);
972 g
= score_elf_section_data (sgot
)->u
.got_info
;
973 BFD_ASSERT (g
!= NULL
);
980 /* Sort the dynamic symbol table so that symbols that need GOT entries
981 appear towards the end. This reduces the amount of GOT space
982 required. MAX_LOCAL is used to set the number of local symbols
983 known to be in the dynamic symbol table. During
984 _bfd_score_elf_size_dynamic_sections, this value is 1. Afterward, the
985 section symbols are added and the count is higher. */
988 score_elf_sort_hash_table (struct bfd_link_info
*info
,
989 unsigned long max_local
)
991 struct score_elf_hash_sort_data hsd
;
992 struct score_got_info
*g
;
995 dynobj
= elf_hash_table (info
)->dynobj
;
997 g
= score_elf_got_info (dynobj
, NULL
);
1000 hsd
.max_unref_got_dynindx
=
1001 hsd
.min_got_dynindx
= elf_hash_table (info
)->dynsymcount
1002 /* In the multi-got case, assigned_gotno of the master got_info
1003 indicate the number of entries that aren't referenced in the
1004 primary GOT, but that must have entries because there are
1005 dynamic relocations that reference it. Since they aren't
1006 referenced, we move them to the end of the GOT, so that they
1007 don't prevent other entries that are referenced from getting
1008 too large offsets. */
1009 - (g
->next
? g
->assigned_gotno
: 0);
1010 hsd
.max_non_got_dynindx
= max_local
;
1011 score_elf_link_hash_traverse (((struct score_elf_link_hash_table
*)
1012 elf_hash_table (info
)),
1013 score_elf_sort_hash_table_f
,
1016 /* There should have been enough room in the symbol table to
1017 accommodate both the GOT and non-GOT symbols. */
1018 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
1019 BFD_ASSERT ((unsigned long)hsd
.max_unref_got_dynindx
1020 <= elf_hash_table (info
)->dynsymcount
);
1022 /* Now we know which dynamic symbol has the lowest dynamic symbol
1023 table index in the GOT. */
1024 g
->global_gotsym
= hsd
.low
;
1029 /* Create an entry in an score ELF linker hash table. */
1031 static struct bfd_hash_entry
*
1032 score_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1033 struct bfd_hash_table
*table
,
1036 struct score_elf_link_hash_entry
*ret
= (struct score_elf_link_hash_entry
*)entry
;
1038 /* Allocate the structure if it has not already been allocated by a subclass. */
1040 ret
= bfd_hash_allocate (table
, sizeof (struct score_elf_link_hash_entry
));
1042 return (struct bfd_hash_entry
*)ret
;
1044 /* Call the allocation method of the superclass. */
1045 ret
= ((struct score_elf_link_hash_entry
*)
1046 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*)ret
, table
, string
));
1050 ret
->possibly_dynamic_relocs
= 0;
1051 ret
->readonly_reloc
= FALSE
;
1052 ret
->no_fn_stub
= FALSE
;
1053 ret
->forced_local
= FALSE
;
1056 return (struct bfd_hash_entry
*)ret
;
1059 /* Returns the first relocation of type r_type found, beginning with
1060 RELOCATION. RELEND is one-past-the-end of the relocation table. */
1062 static const Elf_Internal_Rela
*
1063 score_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
1064 const Elf_Internal_Rela
*relocation
,
1065 const Elf_Internal_Rela
*relend
)
1067 while (relocation
< relend
)
1069 if (ELF32_R_TYPE (relocation
->r_info
) == r_type
)
1075 /* We didn't find it. */
1076 bfd_set_error (bfd_error_bad_value
);
1080 /* This function is called via qsort() to sort the dynamic relocation
1081 entries by increasing r_symndx value. */
1084 score_elf_sort_dynamic_relocs (const void *arg1
, const void *arg2
)
1086 Elf_Internal_Rela int_reloc1
;
1087 Elf_Internal_Rela int_reloc2
;
1089 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
1090 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
1092 return (ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
));
1095 /* Return whether a relocation is against a local symbol. */
1098 score_elf_local_relocation_p (bfd
*input_bfd
,
1099 const Elf_Internal_Rela
*relocation
,
1100 asection
**local_sections
,
1101 bfd_boolean check_forced
)
1103 unsigned long r_symndx
;
1104 Elf_Internal_Shdr
*symtab_hdr
;
1105 struct score_elf_link_hash_entry
*h
;
1108 r_symndx
= ELF32_R_SYM (relocation
->r_info
);
1109 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1110 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
1112 if (r_symndx
< extsymoff
)
1114 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
1119 /* Look up the hash table to check whether the symbol was forced local. */
1120 h
= (struct score_elf_link_hash_entry
*)
1121 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
1122 /* Find the real hash-table entry for this symbol. */
1123 while (h
->root
.root
.type
== bfd_link_hash_indirect
1124 || h
->root
.root
.type
== bfd_link_hash_warning
)
1125 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1126 if (h
->root
.forced_local
)
1133 /* Returns the dynamic relocation section for DYNOBJ. */
1136 score_elf_rel_dyn_section (bfd
*dynobj
, bfd_boolean create_p
)
1138 static const char dname
[] = ".rel.dyn";
1141 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
1142 if (sreloc
== NULL
&& create_p
)
1144 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
1149 | SEC_LINKER_CREATED
1152 || ! bfd_set_section_alignment (dynobj
, sreloc
,
1153 SCORE_ELF_LOG_FILE_ALIGN (dynobj
)))
1160 score_elf_allocate_dynamic_relocations (bfd
*abfd
, unsigned int n
)
1164 s
= score_elf_rel_dyn_section (abfd
, FALSE
);
1165 BFD_ASSERT (s
!= NULL
);
1169 /* Make room for a null element. */
1170 s
->size
+= SCORE_ELF_REL_SIZE (abfd
);
1173 s
->size
+= n
* SCORE_ELF_REL_SIZE (abfd
);
1176 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
1177 is the original relocation, which is now being transformed into a
1178 dynamic relocation. The ADDENDP is adjusted if necessary; the
1179 caller should store the result in place of the original addend. */
1182 score_elf_create_dynamic_relocation (bfd
*output_bfd
,
1183 struct bfd_link_info
*info
,
1184 const Elf_Internal_Rela
*rel
,
1185 struct score_elf_link_hash_entry
*h
,
1186 asection
*sec
, bfd_vma symbol
,
1187 bfd_vma
*addendp
, asection
*input_section
)
1189 Elf_Internal_Rela outrel
[3];
1194 bfd_boolean defined_p
;
1196 r_type
= ELF32_R_TYPE (rel
->r_info
);
1197 dynobj
= elf_hash_table (info
)->dynobj
;
1198 sreloc
= score_elf_rel_dyn_section (dynobj
, FALSE
);
1199 BFD_ASSERT (sreloc
!= NULL
);
1200 BFD_ASSERT (sreloc
->contents
!= NULL
);
1201 BFD_ASSERT (sreloc
->reloc_count
* SCORE_ELF_REL_SIZE (output_bfd
) < sreloc
->size
);
1203 outrel
[0].r_offset
=
1204 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
1205 outrel
[1].r_offset
=
1206 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
1207 outrel
[2].r_offset
=
1208 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
1210 if (outrel
[0].r_offset
== MINUS_ONE
)
1211 /* The relocation field has been deleted. */
1214 if (outrel
[0].r_offset
== MINUS_TWO
)
1216 /* The relocation field has been converted into a relative value of
1217 some sort. Functions like _bfd_elf_write_section_eh_frame expect
1218 the field to be fully relocated, so add in the symbol's value. */
1223 /* We must now calculate the dynamic symbol table index to use
1224 in the relocation. */
1226 && (! info
->symbolic
|| !h
->root
.def_regular
)
1227 /* h->root.dynindx may be -1 if this symbol was marked to
1229 && h
->root
.dynindx
!= -1)
1231 indx
= h
->root
.dynindx
;
1232 /* ??? glibc's ld.so just adds the final GOT entry to the
1233 relocation field. It therefore treats relocs against
1234 defined symbols in the same way as relocs against
1235 undefined symbols. */
1240 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1242 else if (sec
== NULL
|| sec
->owner
== NULL
)
1244 bfd_set_error (bfd_error_bad_value
);
1249 indx
= elf_section_data (sec
->output_section
)->dynindx
;
1254 /* Instead of generating a relocation using the section
1255 symbol, we may as well make it a fully relative
1256 relocation. We want to avoid generating relocations to
1257 local symbols because we used to generate them
1258 incorrectly, without adding the original symbol value,
1259 which is mandated by the ABI for section symbols. In
1260 order to give dynamic loaders and applications time to
1261 phase out the incorrect use, we refrain from emitting
1262 section-relative relocations. It's not like they're
1263 useful, after all. This should be a bit more efficient
1265 /* ??? Although this behavior is compatible with glibc's ld.so,
1266 the ABI says that relocations against STN_UNDEF should have
1267 a symbol value of 0. Irix rld honors this, so relocations
1268 against STN_UNDEF have no effect. */
1272 /* If the relocation was previously an absolute relocation and
1273 this symbol will not be referred to by the relocation, we must
1274 adjust it by the value we give it in the dynamic symbol table.
1275 Otherwise leave the job up to the dynamic linker. */
1276 if (defined_p
&& r_type
!= R_SCORE_REL32
)
1279 /* The relocation is always an REL32 relocation because we don't
1280 know where the shared library will wind up at load-time. */
1281 outrel
[0].r_info
= ELF32_R_INFO ((unsigned long) indx
, R_SCORE_REL32
);
1283 /* For strict adherence to the ABI specification, we should
1284 generate a R_SCORE_64 relocation record by itself before the
1285 _REL32/_64 record as well, such that the addend is read in as
1286 a 64-bit value (REL32 is a 32-bit relocation, after all).
1287 However, since none of the existing ELF64 SCORE dynamic
1288 loaders seems to care, we don't waste space with these
1289 artificial relocations. If this turns out to not be true,
1290 score_elf_allocate_dynamic_relocations() should be tweaked so
1291 as to make room for a pair of dynamic relocations per
1292 invocation if ABI_64_P, and here we should generate an
1293 additional relocation record with R_SCORE_64 by itself for a
1294 NULL symbol before this relocation record. */
1295 outrel
[1].r_info
= ELF32_R_INFO (0, R_SCORE_NONE
);
1296 outrel
[2].r_info
= ELF32_R_INFO (0, R_SCORE_NONE
);
1298 /* Adjust the output offset of the relocation to reference the
1299 correct location in the output file. */
1300 outrel
[0].r_offset
+= (input_section
->output_section
->vma
1301 + input_section
->output_offset
);
1302 outrel
[1].r_offset
+= (input_section
->output_section
->vma
1303 + input_section
->output_offset
);
1304 outrel
[2].r_offset
+= (input_section
->output_section
->vma
1305 + input_section
->output_offset
);
1307 /* Put the relocation back out. We have to use the special
1308 relocation outputter in the 64-bit case since the 64-bit
1309 relocation format is non-standard. */
1310 bfd_elf32_swap_reloc_out
1311 (output_bfd
, &outrel
[0],
1312 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
1314 /* We've now added another relocation. */
1315 ++sreloc
->reloc_count
;
1317 /* Make sure the output section is writable. The dynamic linker
1318 will be writing to it. */
1319 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
|= SHF_WRITE
;
1325 score_elf_create_got_section (bfd
*abfd
,
1326 struct bfd_link_info
*info
,
1327 bfd_boolean maybe_exclude
)
1331 struct elf_link_hash_entry
*h
;
1332 struct bfd_link_hash_entry
*bh
;
1333 struct score_got_info
*g
;
1336 /* This function may be called more than once. */
1337 s
= score_elf_got_section (abfd
, TRUE
);
1340 if (! maybe_exclude
)
1341 s
->flags
&= ~SEC_EXCLUDE
;
1345 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1348 flags
|= SEC_EXCLUDE
;
1350 /* We have to use an alignment of 2**4 here because this is hardcoded
1351 in the function stub generation and in the linker script. */
1352 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
1354 || ! bfd_set_section_alignment (abfd
, s
, 4))
1357 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
1358 linker script because we don't want to define the symbol if we
1359 are not creating a global offset table. */
1361 if (! (_bfd_generic_link_add_one_symbol
1362 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
1363 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
1366 h
= (struct elf_link_hash_entry
*) bh
;
1369 h
->type
= STT_OBJECT
;
1371 if (info
->shared
&& ! bfd_elf_link_record_dynamic_symbol (info
, h
))
1374 amt
= sizeof (struct score_got_info
);
1375 g
= bfd_alloc (abfd
, amt
);
1379 g
->global_gotsym
= NULL
;
1380 g
->global_gotno
= 0;
1382 g
->local_gotno
= SCORE_RESERVED_GOTNO
;
1383 g
->assigned_gotno
= SCORE_RESERVED_GOTNO
;
1386 g
->got_entries
= htab_try_create (1, score_elf_got_entry_hash
,
1387 score_elf_got_entry_eq
, NULL
);
1388 if (g
->got_entries
== NULL
)
1390 score_elf_section_data (s
)->u
.got_info
= g
;
1391 score_elf_section_data (s
)->elf
.this_hdr
.sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_SCORE_GPREL
;
1396 /* Calculate the %high function. */
1399 score_elf_high (bfd_vma value
)
1401 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
1404 /* Create a local GOT entry for VALUE. Return the index of the entry,
1405 or -1 if it could not be created. */
1407 static struct score_got_entry
*
1408 score_elf_create_local_got_entry (bfd
*abfd
,
1409 bfd
*ibfd ATTRIBUTE_UNUSED
,
1410 struct score_got_info
*gg
,
1411 asection
*sgot
, bfd_vma value
,
1412 unsigned long r_symndx ATTRIBUTE_UNUSED
,
1413 struct score_elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
1414 int r_type ATTRIBUTE_UNUSED
)
1416 struct score_got_entry entry
, **loc
;
1417 struct score_got_info
*g
;
1421 entry
.d
.address
= value
;
1424 loc
= (struct score_got_entry
**) htab_find_slot (g
->got_entries
, &entry
, INSERT
);
1428 entry
.gotidx
= SCORE_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
1430 *loc
= bfd_alloc (abfd
, sizeof entry
);
1435 memcpy (*loc
, &entry
, sizeof entry
);
1437 if (g
->assigned_gotno
>= g
->local_gotno
)
1439 (*loc
)->gotidx
= -1;
1440 /* We didn't allocate enough space in the GOT. */
1441 (*_bfd_error_handler
)
1442 (_("not enough GOT space for local GOT entries"));
1443 bfd_set_error (bfd_error_bad_value
);
1447 bfd_put_32 (abfd
, value
, (sgot
->contents
+ entry
.gotidx
));
1452 /* Find a GOT entry whose higher-order 16 bits are the same as those
1453 for value. Return the index into the GOT for this entry. */
1456 score_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1457 bfd_vma value
, bfd_boolean external
)
1460 struct score_got_info
*g
;
1461 struct score_got_entry
*entry
;
1465 /* Although the ABI says that it is "the high-order 16 bits" that we
1466 want, it is really the %high value. The complete value is
1467 calculated with a `addiu' of a LO16 relocation, just as with a
1469 value
= score_elf_high (value
) << 16;
1472 g
= score_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1474 entry
= score_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
, 0, NULL
,
1477 return entry
->gotidx
;
1483 _bfd_score_elf_hide_symbol (struct bfd_link_info
*info
,
1484 struct elf_link_hash_entry
*entry
,
1485 bfd_boolean force_local
)
1489 struct score_got_info
*g
;
1490 struct score_elf_link_hash_entry
*h
;
1492 h
= (struct score_elf_link_hash_entry
*) entry
;
1493 if (h
->forced_local
)
1495 h
->forced_local
= TRUE
;
1497 dynobj
= elf_hash_table (info
)->dynobj
;
1498 if (dynobj
!= NULL
&& force_local
)
1500 got
= score_elf_got_section (dynobj
, FALSE
);
1503 g
= score_elf_section_data (got
)->u
.got_info
;
1507 struct score_got_entry e
;
1508 struct score_got_info
*gg
= g
;
1510 /* Since we're turning what used to be a global symbol into a
1511 local one, bump up the number of local entries of each GOT
1512 that had an entry for it. This will automatically decrease
1513 the number of global entries, since global_gotno is actually
1514 the upper limit of global entries. */
1519 for (g
= g
->next
; g
!= gg
; g
= g
->next
)
1520 if (htab_find (g
->got_entries
, &e
))
1522 BFD_ASSERT (g
->global_gotno
> 0);
1527 /* If this was a global symbol forced into the primary GOT, we
1528 no longer need an entry for it. We can't release the entry
1529 at this point, but we must at least stop counting it as one
1530 of the symbols that required a forced got entry. */
1531 if (h
->root
.got
.offset
== 2)
1533 BFD_ASSERT (gg
->assigned_gotno
> 0);
1534 gg
->assigned_gotno
--;
1537 else if (g
->global_gotno
== 0 && g
->global_gotsym
== NULL
)
1538 /* If we haven't got through GOT allocation yet, just bump up the
1539 number of local entries, as this symbol won't be counted as
1542 else if (h
->root
.got
.offset
== 1)
1544 /* If we're past non-multi-GOT allocation and this symbol had
1545 been marked for a global got entry, give it a local entry
1547 BFD_ASSERT (g
->global_gotno
> 0);
1553 _bfd_elf_link_hash_hide_symbol (info
, &h
->root
, force_local
);
1556 /* If H is a symbol that needs a global GOT entry, but has a dynamic
1557 symbol table index lower than any we've seen to date, record it for
1561 score_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
1563 struct bfd_link_info
*info
,
1564 struct score_got_info
*g
)
1566 struct score_got_entry entry
, **loc
;
1568 /* A global symbol in the GOT must also be in the dynamic symbol table. */
1569 if (h
->dynindx
== -1)
1571 switch (ELF_ST_VISIBILITY (h
->other
))
1575 _bfd_score_elf_hide_symbol (info
, h
, TRUE
);
1578 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
1584 entry
.d
.h
= (struct score_elf_link_hash_entry
*)h
;
1586 loc
= (struct score_got_entry
**)htab_find_slot (g
->got_entries
, &entry
, INSERT
);
1588 /* If we've already marked this entry as needing GOT space, we don't
1589 need to do it again. */
1593 *loc
= bfd_alloc (abfd
, sizeof entry
);
1599 memcpy (*loc
, &entry
, sizeof (entry
));
1601 if (h
->got
.offset
!= MINUS_ONE
)
1604 /* By setting this to a value other than -1, we are indicating that
1605 there needs to be a GOT entry for H. Avoid using zero, as the
1606 generic ELF copy_indirect_symbol tests for <= 0. */
1612 /* Reserve space in G for a GOT entry containing the value of symbol
1613 SYMNDX in input bfd ABDF, plus ADDEND. */
1616 score_elf_record_local_got_symbol (bfd
*abfd
,
1619 struct score_got_info
*g
)
1621 struct score_got_entry entry
, **loc
;
1624 entry
.symndx
= symndx
;
1625 entry
.d
.addend
= addend
;
1626 loc
= (struct score_got_entry
**)htab_find_slot (g
->got_entries
, &entry
, INSERT
);
1631 entry
.gotidx
= g
->local_gotno
++;
1633 *loc
= bfd_alloc (abfd
, sizeof(entry
));
1637 memcpy (*loc
, &entry
, sizeof (entry
));
1642 /* Returns the GOT offset at which the indicated address can be found.
1643 If there is not yet a GOT entry for this value, create one.
1644 Returns -1 if no satisfactory GOT offset can be found. */
1647 score_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
1648 bfd_vma value
, unsigned long r_symndx
,
1649 struct score_elf_link_hash_entry
*h
, int r_type
)
1652 struct score_got_info
*g
;
1653 struct score_got_entry
*entry
;
1655 g
= score_elf_got_info (elf_hash_table (info
)->dynobj
, &sgot
);
1657 entry
= score_elf_create_local_got_entry (abfd
, ibfd
, g
, sgot
, value
,
1658 r_symndx
, h
, r_type
);
1663 return entry
->gotidx
;
1666 /* Returns the GOT index for the global symbol indicated by H. */
1669 score_elf_global_got_index (bfd
*abfd
, struct elf_link_hash_entry
*h
)
1673 struct score_got_info
*g
;
1674 long global_got_dynindx
= 0;
1676 g
= score_elf_got_info (abfd
, &sgot
);
1677 if (g
->global_gotsym
!= NULL
)
1678 global_got_dynindx
= g
->global_gotsym
->dynindx
;
1680 /* Once we determine the global GOT entry with the lowest dynamic
1681 symbol table index, we must put all dynamic symbols with greater
1682 indices into the GOT. That makes it easy to calculate the GOT
1684 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
1685 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
) * SCORE_ELF_GOT_SIZE (abfd
));
1686 BFD_ASSERT (index
< sgot
->size
);
1691 /* Returns the offset for the entry at the INDEXth position in the GOT. */
1694 score_elf_got_offset_from_index (bfd
*dynobj
, bfd
*output_bfd
,
1695 bfd
*input_bfd ATTRIBUTE_UNUSED
, bfd_vma index
)
1699 struct score_got_info
*g
;
1701 g
= score_elf_got_info (dynobj
, &sgot
);
1702 gp
= _bfd_get_gp_value (output_bfd
);
1704 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
1707 /* Follow indirect and warning hash entries so that each got entry
1708 points to the final symbol definition. P must point to a pointer
1709 to the hash table we're traversing. Since this traversal may
1710 modify the hash table, we set this pointer to NULL to indicate
1711 we've made a potentially-destructive change to the hash table, so
1712 the traversal must be restarted. */
1714 score_elf_resolve_final_got_entry (void **entryp
, void *p
)
1716 struct score_got_entry
*entry
= (struct score_got_entry
*)*entryp
;
1717 htab_t got_entries
= *(htab_t
*)p
;
1719 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
1721 struct score_elf_link_hash_entry
*h
= entry
->d
.h
;
1723 while (h
->root
.root
.type
== bfd_link_hash_indirect
1724 || h
->root
.root
.type
== bfd_link_hash_warning
)
1725 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1727 if (entry
->d
.h
== h
)
1732 /* If we can't find this entry with the new bfd hash, re-insert
1733 it, and get the traversal restarted. */
1734 if (! htab_find (got_entries
, entry
))
1736 htab_clear_slot (got_entries
, entryp
);
1737 entryp
= htab_find_slot (got_entries
, entry
, INSERT
);
1740 /* Abort the traversal, since the whole table may have
1741 moved, and leave it up to the parent to restart the
1743 *(htab_t
*)p
= NULL
;
1746 /* We might want to decrement the global_gotno count, but it's
1747 either too early or too late for that at this point. */
1753 /* Turn indirect got entries in a got_entries table into their final locations. */
1755 score_elf_resolve_final_got_entries (struct score_got_info
*g
)
1761 got_entries
= g
->got_entries
;
1763 htab_traverse (got_entries
,
1764 score_elf_resolve_final_got_entry
,
1767 while (got_entries
== NULL
);
1770 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. for -r */
1773 score_elf_add_to_rel (bfd
*abfd
,
1775 reloc_howto_type
*howto
,
1776 bfd_signed_vma increment
)
1778 bfd_signed_vma addend
;
1780 unsigned long offset
;
1781 unsigned long r_type
= howto
->type
;
1782 unsigned long hi16_addend
, hi16_offset
, hi16_value
, uvalue
;
1784 contents
= bfd_get_32 (abfd
, address
);
1785 /* Get the (signed) value from the instruction. */
1786 addend
= contents
& howto
->src_mask
;
1787 if (addend
& ((howto
->src_mask
+ 1) >> 1))
1789 bfd_signed_vma mask
;
1792 mask
&= ~howto
->src_mask
;
1795 /* Add in the increment, (which is a byte value). */
1800 (((contents
& howto
->src_mask
) & 0x3ff0000) >> 6) | ((contents
& howto
->src_mask
) & 0x3ff);
1801 offset
+= increment
;
1803 (contents
& ~howto
->
1804 src_mask
) | (((offset
<< 6) & howto
->src_mask
) & 0x3ff0000) | (offset
& 0x3ff);
1805 bfd_put_32 (abfd
, contents
, address
);
1810 hi16_addend
= bfd_get_32 (abfd
, address
- 4);
1811 hi16_offset
= ((((hi16_addend
>> 16) & 0x3) << 15) | (hi16_addend
& 0x7fff)) >> 1;
1812 offset
= ((((contents
>> 16) & 0x3) << 15) | (contents
& 0x7fff)) >> 1;
1813 offset
= (hi16_offset
<< 16) | (offset
& 0xffff);
1814 uvalue
= increment
+ offset
;
1815 hi16_offset
= (uvalue
>> 16) << 1;
1816 hi16_value
= (hi16_addend
& (~(howto
->dst_mask
)))
1817 | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
1818 bfd_put_32 (abfd
, hi16_value
, address
- 4);
1819 offset
= (uvalue
& 0xffff) << 1;
1820 contents
= (contents
& (~(howto
->dst_mask
))) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
1821 bfd_put_32 (abfd
, contents
, address
);
1825 (((contents
& howto
->src_mask
) >> 1) & 0x1ff8000) | ((contents
& howto
->src_mask
) & 0x7fff);
1826 offset
+= increment
;
1828 (contents
& ~howto
->
1829 src_mask
) | (((offset
<< 1) & howto
->src_mask
) & 0x3ff0000) | (offset
& 0x7fff);
1830 bfd_put_32 (abfd
, contents
, address
);
1834 contents
= bfd_get_16 (abfd
, address
);
1835 offset
= contents
& howto
->src_mask
;
1836 offset
+= increment
;
1837 contents
= (contents
& ~howto
->src_mask
) | (offset
& howto
->src_mask
);
1838 bfd_put_16 (abfd
, contents
, address
);
1843 contents
= bfd_get_16 (abfd
, address
);
1844 offset
= (contents
& howto
->src_mask
) + ((increment
>> 1) & 0xff);
1845 contents
= (contents
& (~howto
->src_mask
)) | (offset
& howto
->src_mask
);
1846 bfd_put_16 (abfd
, contents
, address
);
1850 addend
+= increment
;
1851 contents
= (contents
& ~howto
->dst_mask
) | (addend
& howto
->dst_mask
);
1852 bfd_put_32 (abfd
, contents
, address
);
1857 /* Perform a relocation as part of a final link. */
1859 static bfd_reloc_status_type
1860 score_elf_final_link_relocate (reloc_howto_type
*howto
,
1863 asection
*input_section
,
1865 Elf_Internal_Rela
*rel
,
1866 Elf_Internal_Rela
*relocs
,
1868 struct bfd_link_info
*info
,
1870 const char *sym_name ATTRIBUTE_UNUSED
,
1871 int sym_flags ATTRIBUTE_UNUSED
,
1872 struct score_elf_link_hash_entry
*h
,
1873 asection
**local_sections
,
1874 bfd_boolean gp_disp_p
)
1876 unsigned long r_type
;
1877 unsigned long r_symndx
;
1878 bfd_byte
*hit_data
= contents
+ rel
->r_offset
;
1880 /* The final GP value to be used for the relocatable, executable, or
1881 shared object file being produced. */
1882 bfd_vma gp
= MINUS_ONE
;
1883 /* The place (section offset or address) of the storage unit being relocated. */
1885 /* The value of GP used to create the relocatable object. */
1886 bfd_vma gp0
= MINUS_ONE
;
1887 /* The offset into the global offset table at which the address of the relocation entry
1888 symbol, adjusted by the addend, resides during execution. */
1889 bfd_vma g
= MINUS_ONE
;
1890 /* TRUE if the symbol referred to by this relocation is a local symbol. */
1891 bfd_boolean local_p
;
1892 /* The eventual value we will relocate. */
1893 bfd_vma value
= symbol
;
1894 unsigned long hi16_addend
, hi16_offset
, hi16_value
, uvalue
, offset
, abs_value
= 0;
1896 if (elf_gp (output_bfd
) == 0)
1898 struct bfd_link_hash_entry
*bh
;
1901 bh
= bfd_link_hash_lookup (info
->hash
, "_gp", 0, 0, 1);
1902 if (bh
!= (struct bfd_link_hash_entry
*)NULL
&& bh
->type
== bfd_link_hash_defined
)
1903 elf_gp (output_bfd
) = (bh
->u
.def
.value
1904 + bh
->u
.def
.section
->output_section
->vma
1905 + bh
->u
.def
.section
->output_offset
);
1906 else if (info
->relocatable
)
1910 /* Find the GP-relative section with the lowest offset. */
1911 for (o
= output_bfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
1914 /* And calculate GP relative to that. */
1915 elf_gp (output_bfd
) = lo
+ ELF_SCORE_GP_OFFSET (input_bfd
);
1919 /* If the relocate_section function needs to do a reloc
1920 involving the GP value, it should make a reloc_dangerous
1921 callback to warn that GP is not defined. */
1925 /* Parse the relocation. */
1926 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1927 r_type
= ELF32_R_TYPE (rel
->r_info
);
1928 rel_addr
= (input_section
->output_section
->vma
+ input_section
->output_offset
+ rel
->r_offset
);
1930 if (r_type
== R_SCORE_GOT15
)
1932 const Elf_Internal_Rela
*relend
;
1933 const Elf_Internal_Rela
*lo16_rel
;
1934 const struct elf_backend_data
*bed
;
1935 bfd_vma lo_value
= 0;
1937 addend
= (bfd_get_32 (input_bfd
, hit_data
) >> howto
->bitpos
) & howto
->src_mask
;
1939 bed
= get_elf_backend_data (output_bfd
);
1940 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
1941 lo16_rel
= score_elf_next_relocation (input_bfd
, R_SCORE_GOT_LO16
, rel
, relend
);
1942 if (lo16_rel
!= NULL
)
1944 lo_value
= (bfd_get_32 (input_bfd
, contents
+ lo16_rel
->r_offset
) >> howto
->bitpos
)
1947 addend
= (addend
<< 16) + lo_value
;
1951 addend
= (bfd_get_32 (input_bfd
, hit_data
) >> howto
->bitpos
) & howto
->src_mask
;
1954 local_p
= score_elf_local_relocation_p (input_bfd
, rel
, local_sections
, TRUE
);
1956 /* If we haven't already determined the GOT offset, or the GP value,
1957 and we're going to need it, get it now. */
1960 case R_SCORE_CALL15
:
1964 g
= score_elf_global_got_index (elf_hash_table (info
)->dynobj
,
1965 (struct elf_link_hash_entry
*) h
);
1967 else if (r_type
== R_SCORE_GOT15
|| r_type
== R_SCORE_CALL15
)
1969 /* There's no need to create a local GOT entry here; the
1970 calculation for a local GOT15 entry does not involve G. */
1975 g
= score_elf_local_got_index (output_bfd
, input_bfd
, info
,
1976 symbol
+ addend
, r_symndx
, h
, r_type
);
1978 return bfd_reloc_outofrange
;
1981 /* Convert GOT indices to actual offsets. */
1982 g
= score_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
1983 output_bfd
, input_bfd
, g
);
1988 case R_SCORE_GPREL32
:
1989 gp0
= _bfd_get_gp_value (input_bfd
);
1990 gp
= _bfd_get_gp_value (output_bfd
);
1994 gp
= _bfd_get_gp_value (output_bfd
);
2003 return bfd_reloc_ok
;
2008 || (elf_hash_table (info
)->dynamic_sections_created
2010 && h
->root
.def_dynamic
2011 && !h
->root
.def_regular
))
2013 && (input_section
->flags
& SEC_ALLOC
) != 0)
2015 /* If we're creating a shared library, or this relocation is against a symbol
2016 in a shared library, then we can't know where the symbol will end up.
2017 So, we create a relocation record in the output, and leave the job up
2018 to the dynamic linker. */
2020 if (!score_elf_create_dynamic_relocation (output_bfd
, info
, rel
, h
,
2021 sym_sec
, symbol
, &value
,
2023 return bfd_reloc_undefined
;
2027 if (r_type
!= R_SCORE_REL32
)
2028 value
= symbol
+ addend
;
2032 value
&= howto
->dst_mask
;
2033 bfd_put_32 (input_bfd
, value
, hit_data
);
2034 return bfd_reloc_ok
;
2038 if ((long)value
> 0x7fff || (long)value
< -0x8000)
2039 return bfd_reloc_overflow
;
2040 bfd_put_16 (input_bfd
, value
, hit_data
);
2041 return bfd_reloc_ok
;
2044 addend
= bfd_get_32 (input_bfd
, hit_data
);
2045 offset
= (((addend
& howto
->src_mask
) >> 1) & 0x1ff8000) | ((addend
& howto
->src_mask
) & 0x7fff);
2046 if ((offset
& 0x1000000) != 0)
2047 offset
|= 0xfe000000;
2049 addend
= (addend
& ~howto
->src_mask
)
2050 | (((value
<< 1) & howto
->src_mask
) & 0x3ff0000) | (value
& 0x7fff);
2051 bfd_put_32 (input_bfd
, addend
, hit_data
);
2052 return bfd_reloc_ok
;
2055 addend
= bfd_get_32 (input_bfd
, hit_data
);
2056 offset
= (((addend
& howto
->src_mask
) & 0x3ff0000) >> 6) | ((addend
& howto
->src_mask
) & 0x3ff);
2057 if ((offset
& 0x80000) != 0)
2058 offset
|= 0xfff00000;
2059 abs_value
= value
= value
- rel_addr
+ offset
;
2060 /* exceed 20 bit : overflow. */
2061 if ((abs_value
& 0x80000000) == 0x80000000)
2062 abs_value
= 0xffffffff - value
+ 1;
2063 if ((abs_value
& 0xfff80000) != 0)
2064 return bfd_reloc_overflow
;
2065 addend
= (addend
& ~howto
->src_mask
)
2066 | (((value
<< 6) & howto
->src_mask
) & 0x3ff0000) | (value
& 0x3ff);
2067 bfd_put_32 (input_bfd
, addend
, hit_data
);
2068 return bfd_reloc_ok
;
2071 addend
= bfd_get_16 (input_bfd
, hit_data
);
2072 offset
= addend
& howto
->src_mask
;
2073 if ((offset
& 0x800) != 0) /* Offset is negative. */
2074 offset
|= 0xfffff000;
2076 addend
= (addend
& ~howto
->src_mask
) | (value
& howto
->src_mask
);
2077 bfd_put_16 (input_bfd
, addend
, hit_data
);
2078 return bfd_reloc_ok
;
2081 addend
= bfd_get_16 (input_bfd
, hit_data
);
2082 offset
= (addend
& howto
->src_mask
) << 1;
2083 if ((offset
& 0x100) != 0) /* Offset is negative. */
2084 offset
|= 0xfffffe00;
2085 abs_value
= value
= value
- rel_addr
+ offset
;
2086 /* Sign bit + exceed 9 bit. */
2087 if (((value
& 0xffffff00) != 0) && ((value
& 0xffffff00) != 0xffffff00))
2088 return bfd_reloc_overflow
;
2090 addend
= (addend
& ~howto
->src_mask
) | (value
& howto
->src_mask
);
2091 bfd_put_16 (input_bfd
, addend
, hit_data
);
2092 return bfd_reloc_ok
;
2095 return bfd_reloc_ok
;
2098 hi16_addend
= bfd_get_32 (input_bfd
, hit_data
- 4);
2099 hi16_offset
= ((((hi16_addend
>> 16) & 0x3) << 15) | (hi16_addend
& 0x7fff)) >> 1;
2100 addend
= bfd_get_32 (input_bfd
, hit_data
);
2101 offset
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
2102 offset
= (hi16_offset
<< 16) | (offset
& 0xffff);
2105 uvalue
= value
+ offset
;
2107 uvalue
= offset
+ gp
- rel_addr
+ 4;
2109 hi16_offset
= (uvalue
>> 16) << 1;
2110 hi16_value
= (hi16_addend
& (~(howto
->dst_mask
)))
2111 | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
2112 bfd_put_32 (input_bfd
, hi16_value
, hit_data
- 4);
2113 offset
= (uvalue
& 0xffff) << 1;
2114 value
= (addend
& (~(howto
->dst_mask
))) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
2115 bfd_put_32 (input_bfd
, value
, hit_data
);
2116 return bfd_reloc_ok
;
2119 addend
= bfd_get_32 (input_bfd
, hit_data
);
2120 offset
= addend
& 0x7fff;
2121 if ((offset
& 0x4000) == 0x4000)
2122 offset
|= 0xffffc000;
2123 value
= value
+ offset
- gp
;
2124 if (((value
& 0xffffc000) != 0) && ((value
& 0xffffc000) != 0xffffc000))
2125 return bfd_reloc_overflow
;
2126 value
= (addend
& ~howto
->src_mask
) | (value
& howto
->src_mask
);
2127 bfd_put_32 (input_bfd
, value
, hit_data
);
2128 return bfd_reloc_ok
;
2131 case R_SCORE_CALL15
:
2136 /* The special case is when the symbol is forced to be local. We need the
2137 full address in the GOT since no R_SCORE_GOT_LO16 relocation follows. */
2138 forced
= ! score_elf_local_relocation_p (input_bfd
, rel
,
2139 local_sections
, FALSE
);
2140 value
= score_elf_got16_entry (output_bfd
, input_bfd
, info
,
2141 symbol
+ addend
, forced
);
2142 if (value
== MINUS_ONE
)
2143 return bfd_reloc_outofrange
;
2144 value
= score_elf_got_offset_from_index (elf_hash_table (info
)->dynobj
,
2145 output_bfd
, input_bfd
, value
);
2152 if ((long) value
> 0x3fff || (long) value
< -0x4000)
2153 return bfd_reloc_overflow
;
2154 bfd_put_16 (input_bfd
, value
, hit_data
+ 2);
2155 return bfd_reloc_ok
;
2157 case R_SCORE_GPREL32
:
2158 value
= (addend
+ symbol
- gp
);
2159 value
&= howto
->dst_mask
;
2160 bfd_put_32 (input_bfd
, value
, hit_data
);
2161 return bfd_reloc_ok
;
2163 case R_SCORE_GOT_LO16
:
2164 addend
= bfd_get_32 (input_bfd
, hit_data
);
2165 value
= ((((addend
>> 16) & 0x3) << 15) | (addend
& 0x7fff)) >> 1;
2167 offset
= (value
& 0xffff) << 1;
2168 value
= (addend
& (~(howto
->dst_mask
))) | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
2170 bfd_put_32 (input_bfd
, value
, hit_data
);
2171 return bfd_reloc_ok
;
2173 case R_SCORE_DUMMY_HI16
:
2174 return bfd_reloc_ok
;
2176 case R_SCORE_GNU_VTINHERIT
:
2177 case R_SCORE_GNU_VTENTRY
:
2178 /* We don't do anything with these at present. */
2179 return bfd_reloc_continue
;
2182 return bfd_reloc_notsupported
;
2186 /* Score backend functions. */
2189 _bfd_score_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2191 Elf_Internal_Rela
*elf_reloc
)
2193 unsigned int r_type
;
2195 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
2196 if (r_type
>= NUM_ELEM (elf32_score_howto_table
))
2197 bfd_reloc
->howto
= NULL
;
2199 bfd_reloc
->howto
= &elf32_score_howto_table
[r_type
];
2202 /* Relocate an score ELF section. */
2205 _bfd_score_elf_relocate_section (bfd
*output_bfd
,
2206 struct bfd_link_info
*info
,
2208 asection
*input_section
,
2210 Elf_Internal_Rela
*relocs
,
2211 Elf_Internal_Sym
*local_syms
,
2212 asection
**local_sections
)
2214 Elf_Internal_Shdr
*symtab_hdr
;
2215 struct elf_link_hash_entry
**sym_hashes
;
2216 Elf_Internal_Rela
*rel
;
2217 Elf_Internal_Rela
*relend
;
2219 unsigned long offset
;
2220 unsigned long hi16_addend
, hi16_offset
, hi16_value
, uvalue
;
2222 bfd_boolean gp_disp_p
= FALSE
;
2225 if (info
->relocatable
)
2230 if (elf_hash_table (info
)->dynamic_sections_created
)
2232 bfd_size_type dynsecsymcount
= 0;
2236 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
2238 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
2239 if ((p
->flags
& SEC_EXCLUDE
) == 0
2240 && (p
->flags
& SEC_ALLOC
) != 0
2241 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
2245 if (!score_elf_sort_hash_table (info
, dynsecsymcount
+ 1))
2249 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2250 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
2251 sym_hashes
= elf_sym_hashes (input_bfd
);
2253 relend
= relocs
+ input_section
->reloc_count
;
2254 for (; rel
< relend
; rel
++)
2257 reloc_howto_type
*howto
;
2258 unsigned long r_symndx
;
2259 Elf_Internal_Sym
*sym
;
2261 struct score_elf_link_hash_entry
*h
;
2262 bfd_vma relocation
= 0;
2263 bfd_reloc_status_type r
;
2266 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2267 r_type
= ELF32_R_TYPE (rel
->r_info
);
2269 _bfd_score_info_to_howto (input_bfd
, &bfd_reloc
, (Elf_Internal_Rela
*) rel
);
2270 howto
= bfd_reloc
.howto
;
2272 if (info
->relocatable
)
2274 /* This is a relocatable link. We don't have to change
2275 anything, unless the reloc is against a section symbol,
2276 in which case we have to adjust according to where the
2277 section symbol winds up in the output section. */
2278 if (r_symndx
< symtab_hdr
->sh_info
)
2280 sym
= local_syms
+ r_symndx
;
2281 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2283 sec
= local_sections
[r_symndx
];
2284 score_elf_add_to_rel (input_bfd
, contents
+ rel
->r_offset
,
2285 howto
, (bfd_signed_vma
) (sec
->output_offset
+ sym
->st_value
));
2291 /* This is a final link. */
2296 if (r_symndx
< extsymoff
)
2298 sym
= local_syms
+ r_symndx
;
2299 sec
= local_sections
[r_symndx
];
2300 relocation
= (sec
->output_section
->vma
2301 + sec
->output_offset
2303 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
2305 if ((sec
->flags
& SEC_MERGE
)
2306 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2309 bfd_vma addend
, value
;
2316 hi16_addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- 4);
2317 hi16_offset
= ((((hi16_addend
>> 16) & 0x3) << 15) | (hi16_addend
& 0x7fff)) >> 1;
2318 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2319 offset
= ((((value
>> 16) & 0x3) << 15) | (value
& 0x7fff)) >> 1;
2320 addend
= (hi16_offset
<< 16) | (offset
& 0xffff);
2322 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
);
2323 addend
-= relocation
;
2324 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2326 hi16_offset
= (uvalue
>> 16) << 1;
2327 hi16_value
= (hi16_addend
& (~(howto
->dst_mask
)))
2328 | (hi16_offset
& 0x7fff) | ((hi16_offset
<< 1) & 0x30000);
2329 bfd_put_32 (input_bfd
, hi16_value
, contents
+ rel
->r_offset
- 4);
2330 offset
= (uvalue
& 0xffff) << 1;
2331 value
= (value
& (~(howto
->dst_mask
)))
2332 | (offset
& 0x7fff) | ((offset
<< 1) & 0x30000);
2333 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2336 value
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2337 /* Get the (signed) value from the instruction. */
2338 addend
= value
& howto
->src_mask
;
2339 if (addend
& ((howto
->src_mask
+ 1) >> 1))
2341 bfd_signed_vma mask
;
2344 mask
&= ~howto
->src_mask
;
2348 addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
) - relocation
;
2349 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
2350 value
= (value
& ~howto
->dst_mask
) | (addend
& howto
->dst_mask
);
2351 bfd_put_32 (input_bfd
, value
, contents
+ rel
->r_offset
);
2358 /* For global symbols we look up the symbol in the hash-table. */
2359 h
= ((struct score_elf_link_hash_entry
*)
2360 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
2361 /* Find the real hash-table entry for this symbol. */
2362 while (h
->root
.root
.type
== bfd_link_hash_indirect
2363 || h
->root
.root
.type
== bfd_link_hash_warning
)
2364 h
= (struct score_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2366 /* Record the name of this symbol, for our caller. */
2367 name
= h
->root
.root
.root
.string
;
2369 /* See if this is the special GP_DISP_LABEL symbol. Note that such a
2370 symbol must always be a global symbol. */
2371 if (strcmp (name
, GP_DISP_LABEL
) == 0)
2373 /* Relocations against GP_DISP_LABEL are permitted only with
2374 R_SCORE_HI16 and R_SCORE_LO16 relocations. */
2375 if (r_type
!= R_SCORE_HI16
&& r_type
!= R_SCORE_LO16
)
2376 return bfd_reloc_notsupported
;
2381 /* If this symbol is defined, calculate its address. Note that
2382 GP_DISP_LABEL is a magic symbol, always implicitly defined by the
2383 linker, so it's inappropriate to check to see whether or not
2385 else if ((h
->root
.root
.type
== bfd_link_hash_defined
2386 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2387 && h
->root
.root
.u
.def
.section
)
2389 sec
= h
->root
.root
.u
.def
.section
;
2390 if (sec
->output_section
)
2391 relocation
= (h
->root
.root
.u
.def
.value
2392 + sec
->output_section
->vma
2393 + sec
->output_offset
);
2396 relocation
= h
->root
.root
.u
.def
.value
;
2399 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
2400 /* We allow relocations against undefined weak symbols, giving
2401 it the value zero, so that you can undefined weak functions
2402 and check to see if they exist by looking at their addresses. */
2404 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
2405 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
2407 else if (strcmp (name
, "_DYNAMIC_LINK") == 0)
2409 /* If this is a dynamic link, we should have created a _DYNAMIC_LINK symbol
2410 in _bfd_score_elf_create_dynamic_sections. Otherwise, we should define
2411 the symbol with a value of 0. */
2412 BFD_ASSERT (! info
->shared
);
2413 BFD_ASSERT (bfd_get_section_by_name (output_bfd
, ".dynamic") == NULL
);
2418 if (! ((*info
->callbacks
->undefined_symbol
)
2419 (info
, h
->root
.root
.root
.string
, input_bfd
,
2420 input_section
, rel
->r_offset
,
2421 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
2422 || ELF_ST_VISIBILITY (h
->root
.other
))))
2423 return bfd_reloc_undefined
;
2428 r
= score_elf_final_link_relocate (howto
, input_bfd
, output_bfd
,
2429 input_section
, contents
, rel
, relocs
,
2430 relocation
, info
, sec
, name
,
2431 (h
? ELF_ST_TYPE ((unsigned int)h
->root
.root
.type
) :
2432 ELF_ST_TYPE ((unsigned int)sym
->st_info
)), h
, local_sections
,
2435 if (r
!= bfd_reloc_ok
)
2437 const char *msg
= (const char *)0;
2441 case bfd_reloc_overflow
:
2442 /* If the overflowing reloc was to an undefined symbol,
2443 we have already printed one error message and there
2444 is no point complaining again. */
2445 if (((!h
) || (h
->root
.root
.type
!= bfd_link_hash_undefined
))
2446 && (!((*info
->callbacks
->reloc_overflow
)
2447 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
2448 input_bfd
, input_section
, rel
->r_offset
))))
2451 case bfd_reloc_undefined
:
2452 if (!((*info
->callbacks
->undefined_symbol
)
2453 (info
, name
, input_bfd
, input_section
, rel
->r_offset
, TRUE
)))
2457 case bfd_reloc_outofrange
:
2458 msg
= _("internal error: out of range error");
2461 case bfd_reloc_notsupported
:
2462 msg
= _("internal error: unsupported relocation error");
2465 case bfd_reloc_dangerous
:
2466 msg
= _("internal error: dangerous error");
2470 msg
= _("internal error: unknown error");
2474 if (!((*info
->callbacks
->warning
)
2475 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
)))
2485 /* Look through the relocs for a section during the first phase, and
2486 allocate space in the global offset table. */
2489 _bfd_score_elf_check_relocs (bfd
*abfd
,
2490 struct bfd_link_info
*info
,
2492 const Elf_Internal_Rela
*relocs
)
2496 Elf_Internal_Shdr
*symtab_hdr
;
2497 struct elf_link_hash_entry
**sym_hashes
;
2498 struct score_got_info
*g
;
2500 const Elf_Internal_Rela
*rel
;
2501 const Elf_Internal_Rela
*rel_end
;
2504 const struct elf_backend_data
*bed
;
2506 if (info
->relocatable
)
2509 dynobj
= elf_hash_table (info
)->dynobj
;
2510 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2511 sym_hashes
= elf_sym_hashes (abfd
);
2512 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
2514 name
= bfd_get_section_name (abfd
, sec
);
2523 sgot
= score_elf_got_section (dynobj
, FALSE
);
2528 BFD_ASSERT (score_elf_section_data (sgot
) != NULL
);
2529 g
= score_elf_section_data (sgot
)->u
.got_info
;
2530 BFD_ASSERT (g
!= NULL
);
2535 bed
= get_elf_backend_data (abfd
);
2536 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
2537 for (rel
= relocs
; rel
< rel_end
; ++rel
)
2539 unsigned long r_symndx
;
2540 unsigned int r_type
;
2541 struct elf_link_hash_entry
*h
;
2543 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2544 r_type
= ELF32_R_TYPE (rel
->r_info
);
2546 if (r_symndx
< extsymoff
)
2550 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
2552 (*_bfd_error_handler
) (_("%s: Malformed reloc detected for section %s"), abfd
, name
);
2553 bfd_set_error (bfd_error_bad_value
);
2558 h
= sym_hashes
[r_symndx
- extsymoff
];
2560 /* This may be an indirect symbol created because of a version. */
2563 while (h
->root
.type
== bfd_link_hash_indirect
)
2564 h
= (struct elf_link_hash_entry
*)h
->root
.u
.i
.link
;
2568 /* Some relocs require a global offset table. */
2569 if (dynobj
== NULL
|| sgot
== NULL
)
2574 case R_SCORE_CALL15
:
2576 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2577 if (!score_elf_create_got_section (dynobj
, info
, FALSE
))
2579 g
= score_elf_got_info (dynobj
, &sgot
);
2583 if (dynobj
== NULL
&& (info
->shared
|| h
!= NULL
) && (sec
->flags
& SEC_ALLOC
) != 0)
2584 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2591 if (!h
&& (r_type
== R_SCORE_GOT_LO16
))
2593 if (! score_elf_record_local_got_symbol (abfd
, r_symndx
, rel
->r_addend
, g
))
2599 case R_SCORE_CALL15
:
2602 (*_bfd_error_handler
)
2603 (_("%B: CALL15 reloc at 0x%lx not against global symbol"),
2604 abfd
, (unsigned long) rel
->r_offset
);
2605 bfd_set_error (bfd_error_bad_value
);
2610 /* This symbol requires a global offset table entry. */
2611 if (! score_elf_record_global_got_symbol (h
, abfd
, info
, g
))
2614 /* We need a stub, not a plt entry for the undefined function. But we record
2615 it as if it needs plt. See _bfd_elf_adjust_dynamic_symbol. */
2621 if (h
&& ! score_elf_record_global_got_symbol (h
, abfd
, info
, g
))
2626 if ((info
->shared
|| h
!= NULL
) && (sec
->flags
& SEC_ALLOC
) != 0)
2630 sreloc
= score_elf_rel_dyn_section (dynobj
, TRUE
);
2634 #define SCORE_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
2637 /* When creating a shared object, we must copy these reloc types into
2638 the output file as R_SCORE_REL32 relocs. We make room for this reloc
2639 in the .rel.dyn reloc section. */
2640 score_elf_allocate_dynamic_relocations (dynobj
, 1);
2641 if ((sec
->flags
& SCORE_READONLY_SECTION
)
2642 == SCORE_READONLY_SECTION
)
2643 /* We tell the dynamic linker that there are
2644 relocations against the text segment. */
2645 info
->flags
|= DF_TEXTREL
;
2649 struct score_elf_link_hash_entry
*hscore
;
2651 /* We only need to copy this reloc if the symbol is
2652 defined in a dynamic object. */
2653 hscore
= (struct score_elf_link_hash_entry
*)h
;
2654 ++hscore
->possibly_dynamic_relocs
;
2655 if ((sec
->flags
& SCORE_READONLY_SECTION
)
2656 == SCORE_READONLY_SECTION
)
2657 /* We need it to tell the dynamic linker if there
2658 are relocations against the text segment. */
2659 hscore
->readonly_reloc
= TRUE
;
2662 /* Even though we don't directly need a GOT entry for this symbol,
2663 a symbol must have a dynamic symbol table index greater that
2664 DT_SCORE_GOTSYM if there are dynamic relocations against it. */
2668 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2669 if (! score_elf_create_got_section (dynobj
, info
, TRUE
))
2671 g
= score_elf_got_info (dynobj
, &sgot
);
2672 if (! score_elf_record_global_got_symbol (h
, abfd
, info
, g
))
2678 /* This relocation describes the C++ object vtable hierarchy.
2679 Reconstruct it for later use during GC. */
2680 case R_SCORE_GNU_VTINHERIT
:
2681 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2685 /* This relocation describes which C++ vtable entries are actually
2686 used. Record for later use during GC. */
2687 case R_SCORE_GNU_VTENTRY
:
2688 if (!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
, asection
*sec
, bfd_byte
*contents
)
3491 bfd_byte
*to
, *from
, *end
;
3494 if (strcmp (sec
->name
, ".pdr") != 0)
3497 if (score_elf_section_data (sec
)->u
.tdata
== NULL
)
3501 end
= contents
+ sec
->size
;
3502 for (from
= contents
, i
= 0; from
< end
; from
+= PDR_SIZE
, i
++)
3504 if ((score_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
3508 memcpy (to
, from
, PDR_SIZE
);
3512 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
3513 (file_ptr
) sec
->output_offset
, sec
->size
);
3518 /* Copy data from a SCORE ELF indirect symbol to its direct symbol, hiding the old
3519 indirect symbol. Process additional relocation information. */
3522 _bfd_score_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3523 struct elf_link_hash_entry
*dir
,
3524 struct elf_link_hash_entry
*ind
)
3526 struct score_elf_link_hash_entry
*dirscore
, *indscore
;
3528 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3530 if (ind
->root
.type
!= bfd_link_hash_indirect
)
3533 dirscore
= (struct score_elf_link_hash_entry
*) dir
;
3534 indscore
= (struct score_elf_link_hash_entry
*) ind
;
3535 dirscore
->possibly_dynamic_relocs
+= indscore
->possibly_dynamic_relocs
;
3537 if (indscore
->readonly_reloc
)
3538 dirscore
->readonly_reloc
= TRUE
;
3540 if (indscore
->no_fn_stub
)
3541 dirscore
->no_fn_stub
= TRUE
;
3544 /* Remove information about discarded functions from other sections which mention them. */
3547 _bfd_score_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
3548 struct bfd_link_info
*info
)
3551 bfd_boolean ret
= FALSE
;
3552 unsigned char *tdata
;
3555 o
= bfd_get_section_by_name (abfd
, ".pdr");
3556 if ((!o
) || (o
->size
== 0) || (o
->size
% PDR_SIZE
!= 0)
3557 || (o
->output_section
!= NULL
&& bfd_is_abs_section (o
->output_section
)))
3560 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
3564 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
, info
->keep_memory
);
3571 cookie
->rel
= cookie
->rels
;
3572 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
3574 for (i
= 0, skip
= 0; i
< o
->size
; i
++)
3576 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
3585 score_elf_section_data (o
)->u
.tdata
= tdata
;
3586 o
->size
-= skip
* PDR_SIZE
;
3592 if (!info
->keep_memory
)
3593 free (cookie
->rels
);
3598 /* Signal that discard_info() has removed the discarded relocations for this section. */
3601 _bfd_score_elf_ignore_discarded_relocs (asection
*sec
)
3603 if (strcmp (sec
->name
, ".pdr") == 0)
3608 /* Return the section that should be marked against GC for a given
3612 _bfd_score_elf_gc_mark_hook (asection
*sec
,
3613 struct bfd_link_info
*info
,
3614 Elf_Internal_Rela
*rel
,
3615 struct elf_link_hash_entry
*h
,
3616 Elf_Internal_Sym
*sym
)
3619 switch (ELF32_R_TYPE (rel
->r_info
))
3621 case R_SCORE_GNU_VTINHERIT
:
3622 case R_SCORE_GNU_VTENTRY
:
3626 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
3629 /* Support for core dump NOTE sections. */
3632 _bfd_score_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
3635 unsigned int raw_size
;
3637 switch (note
->descsz
)
3642 case 148: /* Linux/Score 32-bit. */
3644 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3647 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3656 /* Make a ".reg/999" section. */
3657 return _bfd_elfcore_make_pseudosection (abfd
, ".reg", raw_size
, note
->descpos
+ offset
);
3661 _bfd_score_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
3663 switch (note
->descsz
)
3668 case 124: /* Linux/Score elf_prpsinfo. */
3669 elf_tdata (abfd
)->core_program
= _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
3670 elf_tdata (abfd
)->core_command
= _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
3673 /* Note that for some reason, a spurious space is tacked
3674 onto the end of the args in some (at least one anyway)
3675 implementations, so strip it off if it exists. */
3678 char *command
= elf_tdata (abfd
)->core_command
;
3679 int n
= strlen (command
);
3681 if (0 < n
&& command
[n
- 1] == ' ')
3682 command
[n
- 1] = '\0';
3689 /* Score BFD functions. */
3691 static reloc_howto_type
*
3692 elf32_score_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_reloc_code_real_type code
)
3696 for (i
= 0; i
< NUM_ELEM (elf32_score_reloc_map
); i
++)
3697 if (elf32_score_reloc_map
[i
].bfd_reloc_val
== code
)
3698 return &elf32_score_howto_table
[elf32_score_reloc_map
[i
].elf_reloc_val
];
3703 /* Create a score elf linker hash table. */
3705 static struct bfd_link_hash_table
*
3706 elf32_score_link_hash_table_create (bfd
*abfd
)
3708 struct score_elf_link_hash_table
*ret
;
3709 bfd_size_type amt
= sizeof (struct score_elf_link_hash_table
);
3711 ret
= bfd_malloc (amt
);
3715 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
, score_elf_link_hash_newfunc
,
3716 sizeof (struct score_elf_link_hash_entry
)))
3722 return &ret
->root
.root
;
3726 elf32_score_print_private_bfd_data (bfd
*abfd
, void * ptr
)
3728 FILE *file
= (FILE *) ptr
;
3730 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
3732 /* Print normal ELF private data. */
3733 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
3735 /* xgettext:c-format */
3736 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
3737 if (elf_elfheader (abfd
)->e_flags
& EF_SCORE_PIC
)
3739 fprintf (file
, _(" [pic]"));
3741 if (elf_elfheader (abfd
)->e_flags
& EF_SCORE_FIXDEP
)
3743 fprintf (file
, _(" [fix dep]"));
3751 elf32_score_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
3756 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
3759 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3760 out_flags
= elf_elfheader (obfd
)->e_flags
;
3762 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
3763 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
3766 in_flags
= elf_elfheader (ibfd
)->e_flags
;
3767 out_flags
= elf_elfheader (obfd
)->e_flags
;
3769 if (! elf_flags_init (obfd
))
3771 elf_flags_init (obfd
) = TRUE
;
3772 elf_elfheader (obfd
)->e_flags
= in_flags
;
3774 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
3775 && bfd_get_arch_info (obfd
)->the_default
)
3777 return bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
), bfd_get_mach (ibfd
));
3783 if (((in_flags
& EF_SCORE_PIC
) != 0) != ((out_flags
& EF_SCORE_PIC
) != 0))
3785 (*_bfd_error_handler
) (_("%B: warning: linking PIC files with non-PIC files"), ibfd
);
3788 /* FIXME: Maybe dependency fix compatibility should be checked here. */
3794 elf32_score_new_section_hook (bfd
*abfd
, asection
*sec
)
3796 struct _score_elf_section_data
*sdata
;
3797 bfd_size_type amt
= sizeof (*sdata
);
3799 sdata
= bfd_zalloc (abfd
, amt
);
3802 sec
->used_by_bfd
= sdata
;
3804 return _bfd_elf_new_section_hook (abfd
, sec
);
3809 #define TARGET_LITTLE_SYM bfd_elf32_littlescore_vec
3810 #define TARGET_LITTLE_NAME "elf32-littlescore"
3811 #define TARGET_BIG_SYM bfd_elf32_bigscore_vec
3812 #define TARGET_BIG_NAME "elf32-bigscore"
3813 #define ELF_ARCH bfd_arch_score
3814 #define ELF_MACHINE_CODE EM_SCORE
3815 #define ELF_MAXPAGESIZE 0x8000
3817 #define elf_info_to_howto 0
3818 #define elf_info_to_howto_rel _bfd_score_info_to_howto
3819 #define elf_backend_relocate_section _bfd_score_elf_relocate_section
3820 #define elf_backend_check_relocs _bfd_score_elf_check_relocs
3821 #define elf_backend_add_symbol_hook _bfd_score_elf_add_symbol_hook
3822 #define elf_backend_symbol_processing _bfd_score_elf_symbol_processing
3823 #define elf_backend_link_output_symbol_hook _bfd_score_elf_link_output_symbol_hook
3824 #define elf_backend_section_from_bfd_section _bfd_score_elf_section_from_bfd_section
3825 #define elf_backend_adjust_dynamic_symbol _bfd_score_elf_adjust_dynamic_symbol
3826 #define elf_backend_always_size_sections _bfd_score_elf_always_size_sections
3827 #define elf_backend_size_dynamic_sections _bfd_score_elf_size_dynamic_sections
3828 #define elf_backend_create_dynamic_sections _bfd_score_elf_create_dynamic_sections
3829 #define elf_backend_finish_dynamic_symbol _bfd_score_elf_finish_dynamic_symbol
3830 #define elf_backend_finish_dynamic_sections _bfd_score_elf_finish_dynamic_sections
3831 #define elf_backend_fake_sections _bfd_score_elf_fake_sections
3832 #define elf_backend_section_processing _bfd_score_elf_section_processing
3833 #define elf_backend_write_section _bfd_score_elf_write_section
3834 #define elf_backend_copy_indirect_symbol _bfd_score_elf_copy_indirect_symbol
3835 #define elf_backend_hide_symbol _bfd_score_elf_hide_symbol
3836 #define elf_backend_discard_info _bfd_score_elf_discard_info
3837 #define elf_backend_ignore_discarded_relocs _bfd_score_elf_ignore_discarded_relocs
3838 #define elf_backend_gc_mark_hook _bfd_score_elf_gc_mark_hook
3839 #define elf_backend_grok_prstatus _bfd_score_elf_grok_prstatus
3840 #define elf_backend_grok_psinfo _bfd_score_elf_grok_psinfo
3841 #define elf_backend_can_gc_sections 1
3842 #define elf_backend_want_plt_sym 0
3843 #define elf_backend_got_header_size (4 * SCORE_RESERVED_GOTNO)
3844 #define elf_backend_plt_header_size 0
3845 #define elf_backend_collect TRUE
3846 #define elf_backend_type_change_ok TRUE
3848 #define bfd_elf32_bfd_reloc_type_lookup elf32_score_reloc_type_lookup
3849 #define bfd_elf32_bfd_link_hash_table_create elf32_score_link_hash_table_create
3850 #define bfd_elf32_bfd_print_private_bfd_data elf32_score_print_private_bfd_data
3851 #define bfd_elf32_bfd_merge_private_bfd_data elf32_score_merge_private_bfd_data
3852 #define bfd_elf32_new_section_hook elf32_score_new_section_hook
3854 #include "elf32-target.h"