1 /* ARC-specific support for 32-bit ELF
2 Copyright (C) 1994-2016 Free Software Foundation, Inc.
3 Contributed by Cupertino Miranda (cmiranda@synopsys.com).
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 #include "libiberty.h"
28 #include "opcode/arc-func.h"
29 #include "opcode/arc.h"
33 # define PR_DEBUG(fmt, args...) fprintf (stderr, fmt, ##args)
35 # define PR_DEBUG(fmt, args...)
38 /* #define ARC_ENABLE_DEBUG 1 */
39 #ifndef ARC_ENABLE_DEBUG
40 #define ARC_DEBUG(...)
43 name_for_global_symbol (struct elf_link_hash_entry
*h
)
45 static char *local_str
= "(local)";
49 return h
->root
.root
.string
;
51 #define ARC_DEBUG(args...) fprintf (stderr, ##args)
55 #define ADD_RELA(BFD, SECTION, OFFSET, SYM_IDX, TYPE, ADDEND) \
57 struct elf_link_hash_table *_htab = elf_hash_table (info); \
58 Elf_Internal_Rela _rel; \
61 BFD_ASSERT (_htab->srel##SECTION &&_htab->srel##SECTION->contents); \
62 _loc = _htab->srel##SECTION->contents \
63 + ((_htab->srel##SECTION->reloc_count) \
64 * sizeof (Elf32_External_Rela)); \
65 _htab->srel##SECTION->reloc_count++; \
66 _rel.r_addend = ADDEND; \
67 _rel.r_offset = (_htab->s##SECTION)->output_section->vma \
68 + (_htab->s##SECTION)->output_offset + OFFSET; \
69 BFD_ASSERT ((long) SYM_IDX != -1); \
70 _rel.r_info = ELF32_R_INFO (SYM_IDX, TYPE); \
71 bfd_elf32_swap_reloca_out (BFD, &_rel, _loc); \
74 struct dynamic_sections
76 bfd_boolean initialized
;
80 asection
* srelgotplt
;
86 enum dyn_section_types
97 const char * dyn_section_names
[DYN_SECTION_TYPES_END
] =
108 /* The default symbols representing the init and fini dyn values.
109 TODO: Check what is the relation of those strings with arclinux.em
111 #define INIT_SYM_STRING "_init"
112 #define FINI_SYM_STRING "_fini"
114 char * init_str
= INIT_SYM_STRING
;
115 char * fini_str
= FINI_SYM_STRING
;
117 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
122 static ATTRIBUTE_UNUSED
const char *
123 reloc_type_to_name (unsigned int type
)
127 #include "elf/arc-reloc.def"
134 #undef ARC_RELOC_HOWTO
136 /* Try to minimize the amount of space occupied by relocation tables
137 on the ROM (not that the ROM won't be swamped by other ELF overhead). */
141 static ATTRIBUTE_UNUSED bfd_boolean
142 is_reloc_PC_relative (reloc_howto_type
*howto
)
144 return (strstr (howto
->name
, "PC") != NULL
) ? TRUE
: FALSE
;
148 is_reloc_SDA_relative (reloc_howto_type
*howto
)
150 return (strstr (howto
->name
, "SDA") != NULL
) ? TRUE
: FALSE
;
154 is_reloc_for_GOT (reloc_howto_type
* howto
)
156 if (strstr (howto
->name
, "TLS") != NULL
)
158 return (strstr (howto
->name
, "GOT") != NULL
) ? TRUE
: FALSE
;
162 is_reloc_for_PLT (reloc_howto_type
* howto
)
164 return (strstr (howto
->name
, "PLT") != NULL
) ? TRUE
: FALSE
;
168 is_reloc_for_TLS (reloc_howto_type
*howto
)
170 return (strstr (howto
->name
, "TLS") != NULL
) ? TRUE
: FALSE
;
173 struct arc_relocation_data
175 bfd_signed_vma reloc_offset
;
176 bfd_signed_vma reloc_addend
;
177 bfd_signed_vma got_offset_value
;
179 bfd_signed_vma sym_value
;
180 asection
* sym_section
;
182 reloc_howto_type
*howto
;
184 asection
* input_section
;
186 bfd_signed_vma sdata_begin_symbol_vma
;
187 bfd_boolean sdata_begin_symbol_vma_set
;
188 bfd_signed_vma got_symbol_vma
;
190 bfd_boolean should_relocate
;
192 const char * symbol_name
;
195 /* Should be included at this location due to static declarations
196 * defined before this point. */
199 #define arc_bfd_get_8(A,B,C) bfd_get_8(A,B)
200 #define arc_bfd_get_16(A,B,C) bfd_get_16(A,B)
201 #define arc_bfd_get_32(A,B,C) bfd_get_32(A,B)
202 #define arc_bfd_put_8(A,B,C,D) bfd_put_8(A,B,C)
203 #define arc_bfd_put_16(A,B,C,D) bfd_put_16(A,B,C)
204 #define arc_bfd_put_32(A,B,C,D) bfd_put_32(A,B,C)
207 static bfd_reloc_status_type
208 arc_elf_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
209 arelent
*reloc_entry
,
211 void *data ATTRIBUTE_UNUSED
,
212 asection
*input_section
,
214 char ** error_message ATTRIBUTE_UNUSED
)
216 if (output_bfd
!= NULL
)
218 reloc_entry
->address
+= input_section
->output_offset
;
220 /* In case of relocateable link and if the reloc is against a
221 section symbol, the addend needs to be adjusted according to
222 where the section symbol winds up in the output section. */
223 if ((symbol_in
->flags
& BSF_SECTION_SYM
) && symbol_in
->section
)
224 reloc_entry
->addend
+= symbol_in
->section
->output_offset
;
229 return bfd_reloc_continue
;
233 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
237 #include "elf/arc-reloc.def"
240 #undef ARC_RELOC_HOWTO
242 #define ARC_RELOC_HOWTO(TYPE, VALUE, RSIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
243 [TYPE] = HOWTO (R_##TYPE, 0, RSIZE, BITSIZE, FALSE, 0, complain_overflow_##OVERFLOW, arc_elf_reloc, "R_" #TYPE, FALSE, 0, 0, FALSE),
245 static struct reloc_howto_struct elf_arc_howto_table
[] =
247 #include "elf/arc-reloc.def"
248 /* Example of what is generated by the preprocessor. Currently kept as an
250 HOWTO (R_ARC_NONE, // Type.
252 2, // Size (0 = byte, 1 = short, 2 = long).
254 FALSE, // PC_relative.
256 complain_overflow_bitfield, // Complain_on_overflow.
257 bfd_elf_generic_reloc, // Special_function.
258 "R_ARC_NONE", // Name.
259 TRUE, // Partial_inplace.
262 FALSE), // PCrel_offset.
265 #undef ARC_RELOC_HOWTO
267 static void arc_elf_howto_init (void)
269 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
270 elf_arc_howto_table[TYPE].pc_relative = \
271 (strstr (#FORMULA, " P ") != NULL || strstr (#FORMULA, " PDATA ") != NULL); \
272 elf_arc_howto_table[TYPE].dst_mask = RELOC_FUNCTION(0, ~0); \
273 /* Only 32 bit data relocations should be marked as ME. */ \
274 if (strstr (#FORMULA, " ME ") != NULL) \
276 BFD_ASSERT (SIZE == 2); \
279 #include "elf/arc-reloc.def"
282 #undef ARC_RELOC_HOWTO
285 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
287 const int howto_table_lookup
[] =
289 #include "elf/arc-reloc.def"
291 #undef ARC_RELOC_HOWTO
293 static reloc_howto_type
*
294 arc_elf_howto (unsigned int r_type
)
296 if (elf_arc_howto_table
[R_ARC_32
].dst_mask
== 0)
297 arc_elf_howto_init ();
298 return &elf_arc_howto_table
[r_type
];
301 /* Map BFD reloc types to ARC ELF reloc types. */
305 bfd_reloc_code_real_type bfd_reloc_val
;
306 unsigned char elf_reloc_val
;
309 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
310 { BFD_RELOC_##TYPE, R_##TYPE },
311 static const struct arc_reloc_map arc_reloc_map
[] =
313 #include "elf/arc-reloc.def"
315 {BFD_RELOC_NONE
, R_ARC_NONE
},
316 {BFD_RELOC_8
, R_ARC_8
},
317 {BFD_RELOC_16
, R_ARC_16
},
318 {BFD_RELOC_24
, R_ARC_24
},
319 {BFD_RELOC_32
, R_ARC_32
},
321 #undef ARC_RELOC_HOWTO
323 typedef ATTRIBUTE_UNUSED
bfd_vma (*replace_func
) (unsigned, int ATTRIBUTE_UNUSED
);
325 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
327 func = (void *) RELOC_FUNCTION; \
330 get_replace_function (bfd
*abfd
, unsigned int r_type
)
336 #include "elf/arc-reloc.def"
339 if (func
== replace_bits24
&& bfd_big_endian (abfd
))
340 return (replace_func
) replace_bits24_be
;
342 return (replace_func
) func
;
344 #undef ARC_RELOC_HOWTO
346 static reloc_howto_type
*
347 arc_elf32_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
348 bfd_reloc_code_real_type code
)
352 for (i
= ARRAY_SIZE (arc_reloc_map
); i
--;)
354 if (arc_reloc_map
[i
].bfd_reloc_val
== code
)
355 return arc_elf_howto (arc_reloc_map
[i
].elf_reloc_val
);
361 /* Function to set the ELF flag bits. */
363 arc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
365 elf_elfheader (abfd
)->e_flags
= flags
;
366 elf_flags_init (abfd
) = TRUE
;
370 /* Print private flags. */
372 arc_elf_print_private_bfd_data (bfd
*abfd
, void * ptr
)
374 FILE *file
= (FILE *) ptr
;
377 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
379 /* Print normal ELF private data. */
380 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
382 flags
= elf_elfheader (abfd
)->e_flags
;
383 fprintf (file
, _("private flags = 0x%lx:"), (unsigned long) flags
);
385 switch (flags
& EF_ARC_MACH_MSK
)
387 case EF_ARC_CPU_ARCV2HS
: fprintf (file
, " -mcpu=ARCv2HS"); break;
388 case EF_ARC_CPU_ARCV2EM
: fprintf (file
, " -mcpu=ARCv2EM"); break;
389 case E_ARC_MACH_ARC600
: fprintf (file
, " -mcpu=ARC600"); break;
390 case E_ARC_MACH_ARC601
: fprintf (file
, " -mcpu=ARC601"); break;
391 case E_ARC_MACH_ARC700
: fprintf (file
, " -mcpu=ARC700"); break;
393 fprintf (file
, "-mcpu=unknown");
397 switch (flags
& EF_ARC_OSABI_MSK
)
399 case E_ARC_OSABI_ORIG
: fprintf (file
, " (ABI:legacy)"); break;
400 case E_ARC_OSABI_V2
: fprintf (file
, " (ABI:v2)"); break;
401 case E_ARC_OSABI_V3
: fprintf (file
, " (ABI:v3)"); break;
403 fprintf (file
, "(ABI:unknown)");
411 /* Copy backend specific data from one object module to another. */
414 arc_elf_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
416 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
417 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
420 BFD_ASSERT (!elf_flags_init (obfd
)
421 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
423 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
424 elf_flags_init (obfd
) = TRUE
;
426 /* Copy object attributes. */
427 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
429 return _bfd_elf_copy_private_bfd_data (ibfd
, obfd
);
432 static reloc_howto_type
*
433 bfd_elf32_bfd_reloc_name_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
438 for (i
= 0; i
< ARRAY_SIZE (elf_arc_howto_table
); i
++)
439 if (elf_arc_howto_table
[i
].name
!= NULL
440 && strcasecmp (elf_arc_howto_table
[i
].name
, r_name
) == 0)
441 return arc_elf_howto (i
);
446 /* Set the howto pointer for an ARC ELF reloc. */
449 arc_info_to_howto_rel (bfd
* abfd ATTRIBUTE_UNUSED
,
451 Elf_Internal_Rela
* dst
)
455 r_type
= ELF32_R_TYPE (dst
->r_info
);
456 BFD_ASSERT (r_type
< (unsigned int) R_ARC_max
);
457 cache_ptr
->howto
= arc_elf_howto (r_type
);
460 /* Merge backend specific data from an object file to the output
461 object file when linking. */
464 arc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
466 unsigned short mach_ibfd
;
467 static unsigned short mach_obfd
= EM_NONE
;
472 /* Check if we have the same endianess. */
473 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
475 _bfd_error_handler (_("ERROR: Endian Match failed. Attempting to link "
476 "%B with binary %s of opposite endian-ness"),
477 ibfd
, bfd_get_filename (obfd
));
481 /* Collect ELF flags. */
482 in_flags
= elf_elfheader (ibfd
)->e_flags
& EF_ARC_MACH_MSK
;
483 out_flags
= elf_elfheader (obfd
)->e_flags
& EF_ARC_MACH_MSK
;
485 if (!elf_flags_init (obfd
)) /* First call, no flags set. */
487 elf_flags_init (obfd
) = TRUE
;
488 out_flags
= in_flags
;
491 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
492 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
495 /* Check to see if the input BFD actually contains any sections. Do
496 not short-circuit dynamic objects; their section list may be
497 emptied by elf_link_add_object_symbols. */
498 if (!(ibfd
->flags
& DYNAMIC
))
500 bfd_boolean null_input_bfd
= TRUE
;
501 bfd_boolean only_data_sections
= TRUE
;
503 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
505 if ((bfd_get_section_flags (ibfd
, sec
)
506 & (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
507 == (SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
))
508 only_data_sections
= FALSE
;
510 null_input_bfd
= FALSE
;
513 if (null_input_bfd
|| only_data_sections
)
517 /* Complain about various flag/architecture mismatches. */
518 mach_ibfd
= elf_elfheader (ibfd
)->e_machine
;
519 if (mach_obfd
== EM_NONE
)
521 mach_obfd
= mach_ibfd
;
525 if (mach_ibfd
!= mach_obfd
)
527 _bfd_error_handler (_("ERROR: Attempting to link %B "
528 "with a binary %s of different architecture"),
529 ibfd
, bfd_get_filename (obfd
));
532 else if (in_flags
!= out_flags
)
534 /* Warn if different flags. */
535 (*_bfd_error_handler
)
536 (_("%s: uses different e_flags (0x%lx) fields than "
537 "previous modules (0x%lx)"),
538 bfd_get_filename (ibfd
), (long)in_flags
, (long)out_flags
);
539 if (in_flags
&& out_flags
)
541 /* MWDT doesnt set the eflags hence make sure we choose the
542 eflags set by gcc. */
543 in_flags
= in_flags
> out_flags
? in_flags
: out_flags
;
547 /* Update the flags. */
548 elf_elfheader (obfd
)->e_flags
= in_flags
;
550 if (bfd_get_mach (obfd
) < bfd_get_mach (ibfd
))
552 return bfd_set_arch_mach (obfd
, bfd_arch_arc
, bfd_get_mach (ibfd
));
558 /* Set the right machine number for an ARC ELF file. */
560 arc_elf_object_p (bfd
* abfd
)
562 /* Make sure this is initialised, or you'll have the potential of passing
563 garbage---or misleading values---into the call to
564 bfd_default_set_arch_mach (). */
565 int mach
= bfd_mach_arc_arc700
;
566 unsigned long arch
= elf_elfheader (abfd
)->e_flags
& EF_ARC_MACH_MSK
;
567 unsigned e_machine
= elf_elfheader (abfd
)->e_machine
;
569 if (e_machine
== EM_ARC_COMPACT
|| e_machine
== EM_ARC_COMPACT2
)
573 case E_ARC_MACH_ARC600
:
574 mach
= bfd_mach_arc_arc600
;
576 case E_ARC_MACH_ARC601
:
577 mach
= bfd_mach_arc_arc601
;
579 case E_ARC_MACH_ARC700
:
580 mach
= bfd_mach_arc_arc700
;
582 case EF_ARC_CPU_ARCV2HS
:
583 case EF_ARC_CPU_ARCV2EM
:
584 mach
= bfd_mach_arc_arcv2
;
587 mach
= (e_machine
== EM_ARC_COMPACT
)
588 ? bfd_mach_arc_arc700
: bfd_mach_arc_arcv2
;
594 if (e_machine
== EM_ARC
)
596 (*_bfd_error_handler
)
597 (_("Error: The ARC4 architecture is no longer supported.\n"));
602 (*_bfd_error_handler
)
603 (_("Warning: unset or old architecture flags. \n"
604 " Use default machine.\n"));
608 return bfd_default_set_arch_mach (abfd
, bfd_arch_arc
, mach
);
611 /* The final processing done just before writing out an ARC ELF object file.
612 This gets the ARC architecture right based on the machine number. */
615 arc_elf_final_write_processing (bfd
* abfd
,
616 bfd_boolean linker ATTRIBUTE_UNUSED
)
620 switch (bfd_get_mach (abfd
))
622 case bfd_mach_arc_arc600
:
623 emf
= EM_ARC_COMPACT
;
625 case bfd_mach_arc_arc601
:
626 emf
= EM_ARC_COMPACT
;
628 case bfd_mach_arc_arc700
:
629 emf
= EM_ARC_COMPACT
;
631 case bfd_mach_arc_arcv2
:
632 emf
= EM_ARC_COMPACT2
;
638 elf_elfheader (abfd
)->e_machine
= emf
;
640 /* Record whatever is the current syscall ABI version. */
641 elf_elfheader (abfd
)->e_flags
|= E_ARC_OSABI_CURRENT
;
647 #define BFD_DEBUG_PIC(...)
651 debug_arc_reloc (struct arc_relocation_data reloc_data
)
653 PR_DEBUG ("Reloc type=%s, should_relocate = %s\n",
654 reloc_data
.howto
->name
,
655 reloc_data
.should_relocate
? "true" : "false");
656 PR_DEBUG (" offset = 0x%x, addend = 0x%x\n",
657 (unsigned int) reloc_data
.reloc_offset
,
658 (unsigned int) reloc_data
.reloc_addend
);
659 PR_DEBUG (" Symbol:\n");
660 PR_DEBUG (" value = 0x%08x\n",
661 (unsigned int) reloc_data
.sym_value
);
662 if (reloc_data
.sym_section
!= NULL
)
664 PR_DEBUG (" Symbol Section:\n");
666 " section name = %s, output_offset 0x%08x",
667 reloc_data
.sym_section
->name
,
668 (unsigned int) reloc_data
.sym_section
->output_offset
);
669 if (reloc_data
.sym_section
->output_section
!= NULL
)
672 ", output_section->vma = 0x%08x",
673 ((unsigned int) reloc_data
.sym_section
->output_section
->vma
));
676 PR_DEBUG (" file: %s\n", reloc_data
.sym_section
->owner
->filename
);
680 PR_DEBUG ( " symbol section is NULL\n");
683 PR_DEBUG ( " Input_section:\n");
684 if (reloc_data
.input_section
!= NULL
)
687 " section name = %s, output_offset 0x%08x, output_section->vma = 0x%08x\n",
688 reloc_data
.input_section
->name
,
689 (unsigned int) reloc_data
.input_section
->output_offset
,
690 (unsigned int) reloc_data
.input_section
->output_section
->vma
);
691 PR_DEBUG ( " changed_address = 0x%08x\n",
692 (unsigned int) (reloc_data
.input_section
->output_section
->vma
693 + reloc_data
.input_section
->output_offset
694 + reloc_data
.reloc_offset
));
695 PR_DEBUG (" file: %s\n", reloc_data
.input_section
->owner
->filename
);
699 PR_DEBUG ( " input section is NULL\n");
704 middle_endian_convert (bfd_vma insn
, bfd_boolean do_it
)
709 = ((insn
& 0xffff0000) >> 16)
710 | ((insn
& 0xffff) << 16);
715 /* This function is called for relocations that are otherwise marked as NOT
716 requiring overflow checks. In here we perform non-standard checks of
717 the relocation value. */
719 static inline bfd_reloc_status_type
720 arc_special_overflow_checks (const struct arc_relocation_data reloc_data
,
721 bfd_signed_vma relocation
,
722 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
724 switch (reloc_data
.howto
->type
)
726 case R_ARC_NPS_CMEM16
:
727 if (((relocation
>> 16) & 0xffff) != NPS_CMEM_HIGH_VALUE
)
729 if (reloc_data
.reloc_addend
== 0)
730 (*_bfd_error_handler
)
731 (_("%B(%A+0x%lx): CMEM relocation to `%s' is invalid, "
732 "16 MSB should be 0x%04x (value is 0x%lx)"),
733 reloc_data
.input_section
->owner
,
734 reloc_data
.input_section
,
735 reloc_data
.reloc_offset
,
736 reloc_data
.symbol_name
,
740 (*_bfd_error_handler
)
741 (_("%B(%A+0x%lx): CMEM relocation to `%s+0x%lx' is invalid, "
742 "16 MSB should be 0x%04x (value is 0x%lx)"),
743 reloc_data
.input_section
->owner
,
744 reloc_data
.input_section
,
745 reloc_data
.reloc_offset
,
746 reloc_data
.symbol_name
,
747 reloc_data
.reloc_addend
,
750 return bfd_reloc_overflow
;
761 #define ME(reloc) (reloc)
763 #define IS_ME(FORMULA,BFD) ((strstr (FORMULA, "ME") != NULL) \
764 && (!bfd_big_endian (BFD)))
766 #define S ((bfd_signed_vma) (reloc_data.sym_value \
767 + (reloc_data.sym_section->output_section != NULL ? \
768 (reloc_data.sym_section->output_offset \
769 + reloc_data.sym_section->output_section->vma) : 0)))
770 #define L ((bfd_signed_vma) (reloc_data.sym_value \
771 + (reloc_data.sym_section->output_section != NULL ? \
772 (reloc_data.sym_section->output_offset \
773 + reloc_data.sym_section->output_section->vma) : 0)))
774 #define A (reloc_data.reloc_addend)
776 #define G (reloc_data.got_offset_value)
777 #define GOT (reloc_data.got_symbol_vma)
778 #define GOT_BEGIN (htab->sgot->output_section->vma)
781 /* P: relative offset to PCL The offset should be to the
782 current location aligned to 32 bits. */
783 #define P ((bfd_signed_vma) ( \
785 (reloc_data.input_section->output_section != NULL ? \
786 reloc_data.input_section->output_section->vma : 0) \
787 + reloc_data.input_section->output_offset \
788 + (reloc_data.reloc_offset - (bitsize >= 32 ? 4 : 0))) \
790 #define PDATA ((bfd_signed_vma) ( \
791 (reloc_data.input_section->output_section->vma \
792 + reloc_data.input_section->output_offset \
793 + (reloc_data.reloc_offset))))
794 #define SECTSTART (bfd_signed_vma) (reloc_data.sym_section->output_section->vma \
795 + reloc_data.sym_section->output_offset)
797 #define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
798 #define TLS_REL (bfd_signed_vma) \
799 ((elf_hash_table (info))->tls_sec->output_section->vma)
805 #define PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA, TYPE) \
807 asection *sym_section = reloc_data.sym_section; \
808 asection *input_section = reloc_data.input_section; \
809 ARC_DEBUG ("RELOC_TYPE = " TYPE "\n"); \
810 ARC_DEBUG ("FORMULA = " FORMULA "\n"); \
811 ARC_DEBUG ("S = 0x%x\n", S); \
812 ARC_DEBUG ("A = 0x%x\n", A); \
813 ARC_DEBUG ("L = 0x%x\n", L); \
814 if (sym_section->output_section != NULL) \
816 ARC_DEBUG ("symbol_section->vma = 0x%x\n", \
817 sym_section->output_section->vma + sym_section->output_offset); \
821 ARC_DEBUG ("symbol_section->vma = NULL\n"); \
823 if (input_section->output_section != NULL) \
825 ARC_DEBUG ("symbol_section->vma = 0x%x\n", \
826 input_section->output_section->vma + input_section->output_offset); \
830 ARC_DEBUG ("symbol_section->vma = NULL\n"); \
832 ARC_DEBUG ("PCL = 0x%x\n", P); \
833 ARC_DEBUG ("P = 0x%x\n", P); \
834 ARC_DEBUG ("G = 0x%x\n", G); \
835 ARC_DEBUG ("SDA_OFFSET = 0x%x\n", _SDA_BASE_); \
836 ARC_DEBUG ("SDA_SET = %d\n", reloc_data.sdata_begin_symbol_vma_set); \
837 ARC_DEBUG ("GOT_OFFSET = 0x%x\n", GOT); \
838 ARC_DEBUG ("relocation = 0x%08x\n", relocation); \
839 ARC_DEBUG ("before = 0x%08x\n", (unsigned int) insn); \
840 ARC_DEBUG ("data = 0x%08x (%u) (%d)\n", (unsigned int) relocation, (unsigned int) relocation, (int) relocation); \
843 #define PRINT_DEBUG_RELOC_INFO_AFTER \
845 ARC_DEBUG ("after = 0x%08x\n", (unsigned int) insn); \
848 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
851 bfd_signed_vma bitsize ATTRIBUTE_UNUSED = BITSIZE; \
852 relocation = FORMULA ; \
853 PRINT_DEBUG_RELOC_INFO_BEFORE (#FORMULA, #TYPE); \
854 insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
855 insn = (* get_replace_function (abfd, TYPE)) (insn, relocation); \
856 insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
857 PRINT_DEBUG_RELOC_INFO_AFTER \
861 static bfd_reloc_status_type
862 arc_do_relocation (bfd_byte
* contents
,
863 struct arc_relocation_data reloc_data
,
864 struct bfd_link_info
*info
)
866 bfd_signed_vma relocation
= 0;
868 bfd_vma orig_insn ATTRIBUTE_UNUSED
;
869 bfd
* abfd
= reloc_data
.input_section
->owner
;
870 struct elf_link_hash_table
*htab ATTRIBUTE_UNUSED
= elf_hash_table (info
);
871 bfd_reloc_status_type flag
;
873 if (reloc_data
.should_relocate
== FALSE
)
876 switch (reloc_data
.howto
->size
)
879 insn
= arc_bfd_get_32 (abfd
,
880 contents
+ reloc_data
.reloc_offset
,
881 reloc_data
.input_section
);
884 insn
= arc_bfd_get_16 (abfd
,
885 contents
+ reloc_data
.reloc_offset
,
886 reloc_data
.input_section
);
889 insn
= arc_bfd_get_8 (abfd
,
890 contents
+ reloc_data
.reloc_offset
,
891 reloc_data
.input_section
);
901 switch (reloc_data
.howto
->type
)
903 #include "elf/arc-reloc.def"
910 /* Check for relocation overflow. */
911 if (reloc_data
.howto
->complain_on_overflow
!= complain_overflow_dont
)
912 flag
= bfd_check_overflow (reloc_data
.howto
->complain_on_overflow
,
913 reloc_data
.howto
->bitsize
,
914 reloc_data
.howto
->rightshift
,
915 bfd_arch_bits_per_address (abfd
),
918 flag
= arc_special_overflow_checks (reloc_data
, relocation
, info
);
920 #undef DEBUG_ARC_RELOC
921 #define DEBUG_ARC_RELOC(A) debug_arc_reloc (A)
922 if (flag
!= bfd_reloc_ok
)
924 PR_DEBUG ( "Relocation overflows !!!!\n");
926 DEBUG_ARC_RELOC (reloc_data
);
929 "Relocation value = signed -> %d, unsigned -> %u"
930 ", hex -> (0x%08x)\n",
932 (unsigned int) relocation
,
933 (unsigned int) relocation
);
936 #undef DEBUG_ARC_RELOC
937 #define DEBUG_ARC_RELOC(A)
939 /* Write updated instruction back to memory. */
940 switch (reloc_data
.howto
->size
)
943 arc_bfd_put_32 (abfd
, insn
,
944 contents
+ reloc_data
.reloc_offset
,
945 reloc_data
.input_section
);
948 arc_bfd_put_16 (abfd
, insn
,
949 contents
+ reloc_data
.reloc_offset
,
950 reloc_data
.input_section
);
953 arc_bfd_put_8 (abfd
, insn
,
954 contents
+ reloc_data
.reloc_offset
,
955 reloc_data
.input_section
);
958 ARC_DEBUG ("size = %d\n", reloc_data
.howto
->size
);
978 #undef ARC_RELOC_HOWTO
981 /* Relocate an arc ELF section.
982 Function : elf_arc_relocate_section
983 Brief : Relocate an arc section, by handling all the relocations
984 appearing in that section.
985 Args : output_bfd : The bfd being written to.
986 info : Link information.
987 input_bfd : The input bfd.
988 input_section : The section being relocated.
989 contents : contents of the section being relocated.
990 relocs : List of relocations in the section.
991 local_syms : is a pointer to the swapped in local symbols.
992 local_section : is an array giving the section in the input file
993 corresponding to the st_shndx field of each
996 elf_arc_relocate_section (bfd
* output_bfd
,
997 struct bfd_link_info
* info
,
999 asection
* input_section
,
1000 bfd_byte
* contents
,
1001 Elf_Internal_Rela
* relocs
,
1002 Elf_Internal_Sym
* local_syms
,
1003 asection
** local_sections
)
1005 Elf_Internal_Shdr
* symtab_hdr
;
1006 struct elf_link_hash_entry
** sym_hashes
;
1007 Elf_Internal_Rela
* rel
;
1008 Elf_Internal_Rela
* wrel
;
1009 Elf_Internal_Rela
* relend
;
1010 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1012 symtab_hdr
= &((elf_tdata (input_bfd
))->symtab_hdr
);
1013 sym_hashes
= elf_sym_hashes (input_bfd
);
1015 rel
= wrel
= relocs
;
1016 relend
= relocs
+ input_section
->reloc_count
;
1017 for (; rel
< relend
; wrel
++, rel
++)
1019 enum elf_arc_reloc_type r_type
;
1020 reloc_howto_type
* howto
;
1021 unsigned long r_symndx
;
1022 struct elf_link_hash_entry
* h
;
1023 Elf_Internal_Sym
* sym
;
1025 struct elf_link_hash_entry
*h2
;
1027 struct arc_relocation_data reloc_data
=
1031 .got_offset_value
= 0,
1033 .sym_section
= NULL
,
1035 .input_section
= NULL
,
1036 .sdata_begin_symbol_vma
= 0,
1037 .sdata_begin_symbol_vma_set
= FALSE
,
1038 .got_symbol_vma
= 0,
1039 .should_relocate
= FALSE
1042 r_type
= ELF32_R_TYPE (rel
->r_info
);
1044 if (r_type
>= (int) R_ARC_max
)
1046 bfd_set_error (bfd_error_bad_value
);
1049 howto
= arc_elf_howto (r_type
);
1051 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1053 /* If we are generating another .o file and the symbol in not
1054 local, skip this relocation. */
1055 if (bfd_link_relocatable (info
))
1057 /* This is a relocateable link. We don't have to change
1058 anything, unless the reloc is against a section symbol,
1059 in which case we have to adjust according to where the
1060 section symbol winds up in the output section. */
1062 /* Checks if this is a local symbol and thus the reloc
1063 might (will??) be against a section symbol. */
1064 if (r_symndx
< symtab_hdr
->sh_info
)
1066 sym
= local_syms
+ r_symndx
;
1067 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1069 sec
= local_sections
[r_symndx
];
1071 /* for RELA relocs.Just adjust the addend
1072 value in the relocation entry. */
1073 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1076 PR_DEBUG ("local symbols reloc "
1077 "(section=%d %s) seen in %s\n",
1079 local_sections
[r_symndx
]->name
,
1080 __PRETTY_FUNCTION__
)
1086 h2
= elf_link_hash_lookup (elf_hash_table (info
), "__SDATA_BEGIN__",
1087 FALSE
, FALSE
, TRUE
);
1089 if (reloc_data
.sdata_begin_symbol_vma_set
== FALSE
1090 && h2
!= NULL
&& h2
->root
.type
!= bfd_link_hash_undefined
1091 && h2
->root
.u
.def
.section
->output_section
!= NULL
)
1092 /* TODO: Verify this condition. */
1094 reloc_data
.sdata_begin_symbol_vma
=
1095 (h2
->root
.u
.def
.value
1096 + h2
->root
.u
.def
.section
->output_section
->vma
);
1097 reloc_data
.sdata_begin_symbol_vma_set
= TRUE
;
1100 reloc_data
.input_section
= input_section
;
1101 reloc_data
.howto
= howto
;
1102 reloc_data
.reloc_offset
= rel
->r_offset
;
1103 reloc_data
.reloc_addend
= rel
->r_addend
;
1105 /* This is a final link. */
1110 if (r_symndx
< symtab_hdr
->sh_info
) /* A local symbol. */
1112 sym
= local_syms
+ r_symndx
;
1113 sec
= local_sections
[r_symndx
];
1117 /* TODO: This code is repeated from below. We should
1118 clean it and remove duplications.
1119 Sec is used check for discarded sections.
1120 Need to redesign code below. */
1122 /* Get the symbol's entry in the symtab. */
1123 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1125 while (h
->root
.type
== bfd_link_hash_indirect
1126 || h
->root
.type
== bfd_link_hash_warning
)
1127 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1129 /* If we have encountered a definition for this symbol. */
1130 if (h
->root
.type
== bfd_link_hash_defined
1131 || h
->root
.type
== bfd_link_hash_defweak
)
1133 reloc_data
.sym_value
= h
->root
.u
.def
.value
;
1134 sec
= h
->root
.u
.def
.section
;
1138 /* Clean relocs for symbols in discarded sections. */
1139 if (sec
!= NULL
&& discarded_section (sec
))
1141 _bfd_clear_contents (howto
, input_bfd
, input_section
,
1142 contents
+ rel
->r_offset
);
1143 rel
->r_offset
= rel
->r_offset
;
1147 /* For ld -r, remove relocations in debug sections against
1148 sections defined in discarded sections. Not done for
1149 eh_frame editing code expects to be present. */
1150 if (bfd_link_relocatable (info
)
1151 && (input_section
->flags
& SEC_DEBUGGING
))
1157 if (bfd_link_relocatable (info
))
1164 if (r_symndx
< symtab_hdr
->sh_info
) /* A local symbol. */
1166 reloc_data
.sym_value
= sym
->st_value
;
1167 reloc_data
.sym_section
= sec
;
1168 reloc_data
.symbol_name
=
1169 bfd_elf_string_from_elf_section (input_bfd
,
1170 symtab_hdr
->sh_link
,
1173 /* Mergeable section handling. */
1174 if ((sec
->flags
& SEC_MERGE
)
1175 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1179 rel
->r_addend
= _bfd_elf_rel_local_sym (output_bfd
, sym
,
1180 &msec
, rel
->r_addend
);
1181 rel
->r_addend
-= (sec
->output_section
->vma
1182 + sec
->output_offset
1184 rel
->r_addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
1186 reloc_data
.reloc_addend
= rel
->r_addend
;
1189 BFD_ASSERT (htab
->sgot
!= NULL
|| !is_reloc_for_GOT (howto
));
1190 if (htab
->sgot
!= NULL
)
1191 reloc_data
.got_symbol_vma
= htab
->sgot
->output_section
->vma
1192 + htab
->sgot
->output_offset
;
1194 reloc_data
.should_relocate
= TRUE
;
1196 else /* Global symbol. */
1198 /* Get the symbol's entry in the symtab. */
1199 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1201 while (h
->root
.type
== bfd_link_hash_indirect
1202 || h
->root
.type
== bfd_link_hash_warning
)
1203 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1205 /* TODO: Need to validate what was the intention. */
1206 /* BFD_ASSERT ((h->dynindx == -1) || (h->forced_local != 0)); */
1207 reloc_data
.symbol_name
= h
->root
.root
.string
;
1209 /* If we have encountered a definition for this symbol. */
1210 if (h
->root
.type
== bfd_link_hash_defined
1211 || h
->root
.type
== bfd_link_hash_defweak
)
1213 reloc_data
.sym_value
= h
->root
.u
.def
.value
;
1214 reloc_data
.sym_section
= h
->root
.u
.def
.section
;
1216 reloc_data
.should_relocate
= TRUE
;
1218 if (is_reloc_for_GOT (howto
) && !bfd_link_pic (info
))
1220 /* TODO: Change it to use arc_do_relocation with
1221 ARC_32 reloc. Try to use ADD_RELA macro. */
1222 bfd_vma relocation
=
1223 reloc_data
.sym_value
+ reloc_data
.reloc_addend
1224 + (reloc_data
.sym_section
->output_section
!= NULL
?
1225 (reloc_data
.sym_section
->output_offset
1226 + reloc_data
.sym_section
->output_section
->vma
)
1229 BFD_ASSERT (h
->got
.glist
);
1230 bfd_vma got_offset
= h
->got
.glist
->offset
;
1231 bfd_put_32 (output_bfd
, relocation
,
1232 htab
->sgot
->contents
+ got_offset
);
1234 if (is_reloc_for_PLT (howto
) && h
->plt
.offset
!= (bfd_vma
) -1)
1236 /* TODO: This is repeated up here. */
1237 reloc_data
.sym_value
= h
->plt
.offset
;
1238 reloc_data
.sym_section
= htab
->splt
;
1241 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1243 /* Is weak symbol and has no definition. */
1244 if (is_reloc_for_GOT (howto
))
1246 reloc_data
.sym_value
= h
->root
.u
.def
.value
;
1247 reloc_data
.sym_section
= htab
->sgot
;
1248 reloc_data
.should_relocate
= TRUE
;
1250 else if (is_reloc_for_PLT (howto
)
1251 && h
->plt
.offset
!= (bfd_vma
) -1)
1253 /* TODO: This is repeated up here. */
1254 reloc_data
.sym_value
= h
->plt
.offset
;
1255 reloc_data
.sym_section
= htab
->splt
;
1256 reloc_data
.should_relocate
= TRUE
;
1263 if (is_reloc_for_GOT (howto
))
1265 reloc_data
.sym_value
= h
->root
.u
.def
.value
;
1266 reloc_data
.sym_section
= htab
->sgot
;
1268 reloc_data
.should_relocate
= TRUE
;
1270 else if (is_reloc_for_PLT (howto
))
1272 /* Fail if it is linking for PIE and the symbol is
1274 if (bfd_link_executable (info
))
1275 (*info
->callbacks
->undefined_symbol
)
1276 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
1277 rel
->r_offset
, TRUE
);
1278 reloc_data
.sym_value
= h
->plt
.offset
;
1279 reloc_data
.sym_section
= htab
->splt
;
1281 reloc_data
.should_relocate
= TRUE
;
1283 else if (!bfd_link_pic (info
))
1284 (*info
->callbacks
->undefined_symbol
)
1285 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
1286 rel
->r_offset
, TRUE
);
1289 BFD_ASSERT (htab
->sgot
!= NULL
|| !is_reloc_for_GOT (howto
));
1290 if (htab
->sgot
!= NULL
)
1291 reloc_data
.got_symbol_vma
= htab
->sgot
->output_section
->vma
1292 + htab
->sgot
->output_offset
;
1295 if ((is_reloc_for_GOT (howto
)
1296 || is_reloc_for_TLS (howto
)))
1298 struct got_entry
**list
1299 = get_got_entry_list_for_symbol (output_bfd
, r_symndx
, h
);
1301 reloc_data
.got_offset_value
1302 = relocate_fix_got_relocs_for_got_info (list
,
1303 tls_type_for_reloc (howto
),
1314 create_got_dynrelocs_for_single_entry (
1315 got_entry_for_type (list
,
1316 arc_got_entry_type_for_reloc (howto
)),
1317 output_bfd
, info
, NULL
);
1325 case R_ARC_32_PCREL
:
1326 if ((bfd_link_pic (info
))// || bfd_link_pie (info))
1327 && ((r_type
!= R_ARC_PC32
&& r_type
!= R_ARC_32_PCREL
)
1330 && (!info
->symbolic
|| !h
->def_regular
))))
1332 Elf_Internal_Rela outrel
;
1334 bfd_boolean skip
= FALSE
;
1335 bfd_boolean relocate
= FALSE
;
1336 asection
*sreloc
= _bfd_elf_get_dynamic_reloc_section
1337 (input_bfd
, input_section
,
1340 BFD_ASSERT (sreloc
!= NULL
);
1342 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
,
1346 if (outrel
.r_offset
== (bfd_vma
) -1)
1349 outrel
.r_addend
= rel
->r_addend
;
1350 outrel
.r_offset
+= (input_section
->output_section
->vma
1351 + input_section
->output_offset
);
1353 #define IS_ARC_PCREL_TYPE(TYPE) \
1354 ( (TYPE == R_ARC_PC32) \
1355 || (TYPE == R_ARC_32_PCREL))
1358 memset (&outrel
, 0, sizeof outrel
);
1363 && ((IS_ARC_PCREL_TYPE (r_type
))
1364 || !(bfd_link_executable (info
)
1365 || SYMBOLIC_BIND (info
, h
))
1366 || ! h
->def_regular
))
1368 BFD_ASSERT (h
!= NULL
);
1369 if ((input_section
->flags
& SEC_ALLOC
) != 0)
1374 BFD_ASSERT (h
->dynindx
!= -1);
1375 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1379 /* Handle local symbols, they either do not have a
1380 global hash table entry (h == NULL), or are
1381 forced local due to a version script
1382 (h->forced_local), or the third condition is
1383 legacy, it appears to say something like, for
1384 links where we are pre-binding the symbols, or
1385 there's not an entry for this symbol in the
1386 dynamic symbol table, and it's a regular symbol
1387 not defined in a shared object, then treat the
1388 symbol as local, resolve it now. */
1390 /* outrel.r_addend = 0; */
1391 outrel
.r_info
= ELF32_R_INFO (0, R_ARC_RELATIVE
);
1394 BFD_ASSERT (sreloc
->contents
!= 0);
1396 loc
= sreloc
->contents
;
1397 loc
+= sreloc
->reloc_count
* sizeof (Elf32_External_Rela
);
1398 sreloc
->reloc_count
+= 1;
1400 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
1402 if (relocate
== FALSE
)
1410 if (is_reloc_SDA_relative (howto
)
1411 && (reloc_data
.sdata_begin_symbol_vma_set
== FALSE
))
1413 (*_bfd_error_handler
)
1414 ("Error: Linker symbol __SDATA_BEGIN__ not found");
1415 bfd_set_error (bfd_error_bad_value
);
1419 DEBUG_ARC_RELOC (reloc_data
);
1421 /* Make sure we have with a dynamic linker. In case of GOT and PLT
1422 the sym_section should point to .got or .plt respectively. */
1423 if ((is_reloc_for_GOT (howto
) || is_reloc_for_PLT (howto
))
1424 && reloc_data
.sym_section
== NULL
)
1426 (*_bfd_error_handler
)
1427 (_("GOT and PLT relocations cannot be fixed with a non dynamic linker."));
1428 bfd_set_error (bfd_error_bad_value
);
1432 if (arc_do_relocation (contents
, reloc_data
, info
) != bfd_reloc_ok
)
1439 static struct dynamic_sections
1440 arc_create_dynamic_sections (bfd
* abfd
, struct bfd_link_info
*info
)
1442 struct elf_link_hash_table
*htab
;
1444 struct dynamic_sections ds
=
1446 .initialized
= FALSE
,
1456 htab
= elf_hash_table (info
);
1459 /* Create dynamic sections for relocatable executables so that we
1460 can copy relocations. */
1461 if (! htab
->dynamic_sections_created
&& bfd_link_pic (info
))
1463 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
1467 dynobj
= (elf_hash_table (info
))->dynobj
;
1471 ds
.sgot
= htab
->sgot
;
1472 ds
.srelgot
= htab
->srelgot
;
1474 ds
.sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1475 ds
.srelgotplt
= ds
.srelplt
;
1477 ds
.splt
= bfd_get_section_by_name (dynobj
, ".plt");
1478 ds
.srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1481 if (htab
->dynamic_sections_created
)
1483 ds
.sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1486 ds
.initialized
= TRUE
;
1492 elf_arc_check_relocs (bfd
* abfd
,
1493 struct bfd_link_info
* info
,
1495 const Elf_Internal_Rela
* relocs
)
1497 Elf_Internal_Shdr
* symtab_hdr
;
1498 struct elf_link_hash_entry
** sym_hashes
;
1499 const Elf_Internal_Rela
* rel
;
1500 const Elf_Internal_Rela
* rel_end
;
1502 asection
* sreloc
= NULL
;
1504 if (bfd_link_relocatable (info
))
1507 dynobj
= (elf_hash_table (info
))->dynobj
;
1508 symtab_hdr
= &((elf_tdata (abfd
))->symtab_hdr
);
1509 sym_hashes
= elf_sym_hashes (abfd
);
1511 rel_end
= relocs
+ sec
->reloc_count
;
1512 for (rel
= relocs
; rel
< rel_end
; rel
++)
1514 enum elf_arc_reloc_type r_type
;
1515 reloc_howto_type
*howto
;
1516 unsigned long r_symndx
;
1517 struct elf_link_hash_entry
*h
;
1519 r_type
= ELF32_R_TYPE (rel
->r_info
);
1521 if (r_type
>= (int) R_ARC_max
)
1523 bfd_set_error (bfd_error_bad_value
);
1526 howto
= arc_elf_howto (r_type
);
1529 && (is_reloc_for_GOT (howto
) == TRUE
1530 || is_reloc_for_TLS (howto
) == TRUE
))
1532 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1533 if (! _bfd_elf_create_got_section (abfd
, info
))
1537 /* Load symbol information. */
1538 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1539 if (r_symndx
< symtab_hdr
->sh_info
) /* Is a local symbol. */
1541 else /* Global one. */
1542 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1548 /* During shared library creation, these relocs should not
1549 appear in a shared library (as memory will be read only
1550 and the dynamic linker can not resolve these. However
1551 the error should not occur for e.g. debugging or
1552 non-readonly sections. */
1553 if ((bfd_link_dll (info
) && !bfd_link_pie (info
))
1554 && (sec
->flags
& SEC_ALLOC
) != 0
1555 && (sec
->flags
& SEC_READONLY
) != 0
1556 && ((sec
->flags
& SEC_CODE
) != 0
1557 || (sec
->flags
& SEC_DEBUGGING
) != 0))
1561 name
= h
->root
.root
.string
;
1563 /* bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); */
1565 (*_bfd_error_handler
)
1567 %B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1569 arc_elf_howto (r_type
)->name
,
1571 bfd_set_error (bfd_error_bad_value
);
1575 /* In some cases we are not setting the 'non_got_ref'
1576 flag, even though the relocations don't require a GOT
1577 access. We should extend the testing in this area to
1578 ensure that no significant cases are being missed. */
1583 case R_ARC_32_PCREL
:
1584 if ((bfd_link_pic (info
))// || bfd_link_pie (info))
1585 && ((r_type
!= R_ARC_PC32
&& r_type
!= R_ARC_32_PCREL
)
1588 && (!info
->symbolic
|| !h
->def_regular
))))
1592 sreloc
= _bfd_elf_make_dynamic_reloc_section (sec
, dynobj
,
1600 sreloc
->size
+= sizeof (Elf32_External_Rela
);
1607 if (is_reloc_for_PLT (howto
) == TRUE
)
1615 /* Add info to the symbol got_entry_list. */
1616 if (is_reloc_for_GOT (howto
) == TRUE
1617 || is_reloc_for_TLS (howto
) == TRUE
)
1619 arc_fill_got_info_for_reloc (
1620 arc_got_entry_type_for_reloc (howto
),
1621 get_got_entry_list_for_symbol (abfd
, r_symndx
, h
),
1630 #define ELF_DYNAMIC_INTERPRETER "/sbin/ld-uClibc.so"
1632 static struct plt_version_t
*
1633 arc_get_plt_version (struct bfd_link_info
*info
)
1637 for (i
= 0; i
< 1; i
++)
1639 ARC_DEBUG ("%d: size1 = %d, size2 = %d\n", i
,
1640 plt_versions
[i
].entry_size
,
1641 plt_versions
[i
].elem_size
);
1644 if (bfd_get_mach (info
->output_bfd
) == bfd_mach_arc_arcv2
)
1646 if (bfd_link_pic (info
))
1647 return &(plt_versions
[ELF_ARCV2_PIC
]);
1649 return &(plt_versions
[ELF_ARCV2_ABS
]);
1653 if (bfd_link_pic (info
))
1654 return &(plt_versions
[ELF_ARC_PIC
]);
1656 return &(plt_versions
[ELF_ARC_ABS
]);
1661 add_symbol_to_plt (struct bfd_link_info
*info
)
1663 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1666 struct plt_version_t
*plt_data
= arc_get_plt_version (info
);
1668 /* If this is the first .plt entry, make room for the special first
1670 if (htab
->splt
->size
== 0)
1671 htab
->splt
->size
+= plt_data
->entry_size
;
1673 ret
= htab
->splt
->size
;
1675 htab
->splt
->size
+= plt_data
->elem_size
;
1676 ARC_DEBUG ("PLT_SIZE = %d\n", htab
->splt
->size
);
1678 htab
->sgotplt
->size
+= 4;
1679 htab
->srelplt
->size
+= sizeof (Elf32_External_Rela
);
1684 #define PLT_DO_RELOCS_FOR_ENTRY(ABFD, DS, RELOCS) \
1685 plt_do_relocs_for_symbol (ABFD, DS, RELOCS, 0, 0)
1688 plt_do_relocs_for_symbol (bfd
*abfd
,
1689 struct elf_link_hash_table
*htab
,
1690 const struct plt_reloc
*reloc
,
1692 bfd_vma symbol_got_offset
)
1694 while (SYM_ONLY (reloc
->symbol
) != LAST_RELOC
)
1696 bfd_vma relocation
= 0;
1698 switch (SYM_ONLY (reloc
->symbol
))
1702 = htab
->sgotplt
->output_section
->vma
1703 + htab
->sgotplt
->output_offset
+ symbol_got_offset
;
1706 relocation
+= reloc
->addend
;
1708 if (IS_RELATIVE (reloc
->symbol
))
1710 bfd_vma reloc_offset
= reloc
->offset
;
1711 reloc_offset
-= (IS_INSN_32 (reloc
->symbol
)) ? 4 : 0;
1712 reloc_offset
-= (IS_INSN_24 (reloc
->symbol
)) ? 2 : 0;
1714 relocation
-= htab
->splt
->output_section
->vma
1715 + htab
->splt
->output_offset
1716 + plt_offset
+ reloc_offset
;
1719 /* TODO: being ME is not a property of the relocation but of the
1720 section of which is applying the relocation. */
1721 if (IS_MIDDLE_ENDIAN (reloc
->symbol
) && !bfd_big_endian (abfd
))
1724 = ((relocation
& 0xffff0000) >> 16)
1725 | ((relocation
& 0xffff) << 16);
1728 switch (reloc
->size
)
1731 bfd_put_32 (htab
->splt
->output_section
->owner
,
1733 htab
->splt
->contents
+ plt_offset
+ reloc
->offset
);
1737 reloc
= &(reloc
[1]); /* Jump to next relocation. */
1742 relocate_plt_for_symbol (bfd
*output_bfd
,
1743 struct bfd_link_info
*info
,
1744 struct elf_link_hash_entry
*h
)
1746 struct plt_version_t
*plt_data
= arc_get_plt_version (info
);
1747 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1749 bfd_vma plt_index
= (h
->plt
.offset
- plt_data
->entry_size
)
1750 / plt_data
->elem_size
;
1751 bfd_vma got_offset
= (plt_index
+ 3) * 4;
1753 ARC_DEBUG ("arc_info: PLT_OFFSET = 0x%x, PLT_ENTRY_VMA = 0x%x, \
1754 GOT_ENTRY_OFFSET = 0x%x, GOT_ENTRY_VMA = 0x%x, for symbol %s\n",
1756 htab
->splt
->output_section
->vma
1757 + htab
->splt
->output_offset
1760 htab
->sgotplt
->output_section
->vma
1761 + htab
->sgotplt
->output_offset
1763 h
->root
.root
.string
);
1768 uint16_t *ptr
= (uint16_t *) plt_data
->elem
;
1769 for (i
= 0; i
< plt_data
->elem_size
/2; i
++)
1771 uint16_t data
= ptr
[i
];
1772 bfd_put_16 (output_bfd
,
1774 htab
->splt
->contents
+ h
->plt
.offset
+ (i
*2));
1778 plt_do_relocs_for_symbol (output_bfd
, htab
,
1779 plt_data
->elem_relocs
,
1783 /* Fill in the entry in the global offset table. */
1784 bfd_put_32 (output_bfd
,
1785 (bfd_vma
) (htab
->splt
->output_section
->vma
1786 + htab
->splt
->output_offset
),
1787 htab
->sgotplt
->contents
+ got_offset
);
1789 /* TODO: Fill in the entry in the .rela.plt section. */
1791 Elf_Internal_Rela rel
;
1794 rel
.r_offset
= (htab
->sgotplt
->output_section
->vma
1795 + htab
->sgotplt
->output_offset
1799 BFD_ASSERT (h
->dynindx
!= -1);
1800 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARC_JMP_SLOT
);
1802 loc
= htab
->srelplt
->contents
;
1803 loc
+= plt_index
* sizeof (Elf32_External_Rela
); /* relA */
1804 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
1809 relocate_plt_for_entry (bfd
*abfd
,
1810 struct bfd_link_info
*info
)
1812 struct plt_version_t
*plt_data
= arc_get_plt_version (info
);
1813 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1817 uint16_t *ptr
= (uint16_t *) plt_data
->entry
;
1818 for (i
= 0; i
< plt_data
->entry_size
/2; i
++)
1820 uint16_t data
= ptr
[i
];
1823 htab
->splt
->contents
+ (i
*2));
1826 PLT_DO_RELOCS_FOR_ENTRY (abfd
, htab
, plt_data
->entry_relocs
);
1829 /* Desc : Adjust a symbol defined by a dynamic object and referenced
1830 by a regular object. The current definition is in some section of
1831 the dynamic object, but we're not including those sections. We
1832 have to change the definition to something the rest of the link can
1836 elf_arc_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1837 struct elf_link_hash_entry
*h
)
1840 bfd
*dynobj
= (elf_hash_table (info
))->dynobj
;
1841 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
1843 if (h
->type
== STT_FUNC
1844 || h
->type
== STT_GNU_IFUNC
1845 || h
->needs_plt
== 1)
1847 if (!bfd_link_pic (info
) && !h
->def_dynamic
&& !h
->ref_dynamic
)
1849 /* This case can occur if we saw a PLT32 reloc in an input
1850 file, but the symbol was never referred to by a dynamic
1851 object. In such a case, we don't actually need to build
1852 a procedure linkage table, and we can just do a PC32
1854 BFD_ASSERT (h
->needs_plt
);
1858 /* Make sure this symbol is output as a dynamic symbol. */
1859 if (h
->dynindx
== -1 && !h
->forced_local
1860 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
1863 if (bfd_link_pic (info
)
1864 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
1866 bfd_vma loc
= add_symbol_to_plt (info
);
1868 if (bfd_link_executable (info
) && !h
->def_regular
)
1870 h
->root
.u
.def
.section
= htab
->splt
;
1871 h
->root
.u
.def
.value
= loc
;
1873 h
->plt
.offset
= loc
;
1877 h
->plt
.offset
= (bfd_vma
) -1;
1883 /* If this is a weak symbol, and there is a real definition, the
1884 processor independent code will have arranged for us to see the
1885 real definition first, and we can just use the same value. */
1886 if (h
->u
.weakdef
!= NULL
)
1888 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
1889 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
1890 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
1891 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
1895 /* This is a reference to a symbol defined by a dynamic object which
1896 is not a function. */
1898 /* If we are creating a shared library, we must presume that the
1899 only references to the symbol are via the global offset table.
1900 For such cases we need not do anything here; the relocations will
1901 be handled correctly by relocate_section. */
1902 if (!bfd_link_executable (info
))
1905 /* If there are no non-GOT references, we do not need a copy
1907 if (!h
->non_got_ref
)
1910 /* If -z nocopyreloc was given, we won't generate them either. */
1911 if (info
->nocopyreloc
)
1917 /* We must allocate the symbol in our .dynbss section, which will
1918 become part of the .bss section of the executable. There will be
1919 an entry for this symbol in the .dynsym section. The dynamic
1920 object will contain position independent code, so all references
1921 from the dynamic object to this symbol will go through the global
1922 offset table. The dynamic linker will use the .dynsym entry to
1923 determine the address it must put in the global offset table, so
1924 both the dynamic object and the regular object will refer to the
1925 same memory location for the variable. */
1930 /* We must generate a R_ARC_COPY reloc to tell the dynamic linker to
1931 copy the initial value out of the dynamic object and into the
1932 runtime process image. We need to remember the offset into the
1933 .rela.bss section we are going to use. */
1934 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1938 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1939 BFD_ASSERT (srel
!= NULL
);
1940 srel
->size
+= sizeof (Elf32_External_Rela
);
1944 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1945 BFD_ASSERT (s
!= NULL
);
1947 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
1950 /* Function : elf_arc_finish_dynamic_symbol
1951 Brief : Finish up dynamic symbol handling. We set the
1952 contents of various dynamic sections here.
1957 Returns : True/False as the return status. */
1960 elf_arc_finish_dynamic_symbol (bfd
* output_bfd
,
1961 struct bfd_link_info
*info
,
1962 struct elf_link_hash_entry
*h
,
1963 Elf_Internal_Sym
* sym
)
1965 if (h
->plt
.offset
!= (bfd_vma
) -1)
1967 relocate_plt_for_symbol (output_bfd
, info
, h
);
1969 if (!h
->def_regular
)
1971 /* Mark the symbol as undefined, rather than as defined in
1972 the .plt section. Leave the value alone. */
1973 sym
->st_shndx
= SHN_UNDEF
;
1978 /* This function traverses list of GOT entries and
1979 create respective dynamic relocs. */
1980 /* TODO: Make function to get list and not access the list directly. */
1981 /* TODO: Move function to relocate_section create this relocs eagerly. */
1982 create_got_dynrelocs_for_got_info (&h
->got
.glist
,
1989 bfd_vma rel_offset
= (h
->root
.u
.def
.value
1990 + h
->root
.u
.def
.section
->output_section
->vma
1991 + h
->root
.u
.def
.section
->output_offset
);
1994 = bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1997 bfd_byte
* loc
= srelbss
->contents
1998 + (srelbss
->reloc_count
* sizeof (Elf32_External_Rela
));
1999 srelbss
->reloc_count
++;
2001 Elf_Internal_Rela rel
;
2003 rel
.r_offset
= rel_offset
;
2005 BFD_ASSERT (h
->dynindx
!= -1);
2006 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_ARC_COPY
);
2008 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
2011 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2012 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2013 || strcmp (h
->root
.root
.string
, "__DYNAMIC") == 0
2014 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2015 sym
->st_shndx
= SHN_ABS
;
2020 #define GET_SYMBOL_OR_SECTION(TAG, SYMBOL, SECTION) \
2022 if (SYMBOL != NULL) \
2023 h = elf_link_hash_lookup (elf_hash_table (info), \
2024 SYMBOL, FALSE, FALSE, TRUE); \
2025 else if (SECTION != NULL) \
2026 s = bfd_get_linker_section (dynobj, SECTION); \
2029 /* Function : elf_arc_finish_dynamic_sections
2030 Brief : Finish up the dynamic sections handling.
2035 Returns : True/False as the return status. */
2038 elf_arc_finish_dynamic_sections (bfd
* output_bfd
,
2039 struct bfd_link_info
*info
)
2041 struct dynamic_sections ds
= arc_create_dynamic_sections (output_bfd
, info
);
2042 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2043 bfd
*dynobj
= (elf_hash_table (info
))->dynobj
;
2047 Elf32_External_Dyn
*dyncon
, *dynconend
;
2049 dyncon
= (Elf32_External_Dyn
*) ds
.sdyn
->contents
;
2051 = (Elf32_External_Dyn
*) (ds
.sdyn
->contents
+ ds
.sdyn
->size
);
2052 for (; dyncon
< dynconend
; dyncon
++)
2054 Elf_Internal_Dyn internal_dyn
;
2055 bfd_boolean do_it
= FALSE
;
2057 struct elf_link_hash_entry
*h
= NULL
;
2060 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &internal_dyn
);
2062 switch (internal_dyn
.d_tag
)
2064 GET_SYMBOL_OR_SECTION (DT_INIT
, "_init", NULL
)
2065 GET_SYMBOL_OR_SECTION (DT_FINI
, "_fini", NULL
)
2066 GET_SYMBOL_OR_SECTION (DT_PLTGOT
, NULL
, ".plt")
2067 GET_SYMBOL_OR_SECTION (DT_JMPREL
, NULL
, ".rela.plt")
2068 GET_SYMBOL_OR_SECTION (DT_PLTRELSZ
, NULL
, ".rela.plt")
2069 GET_SYMBOL_OR_SECTION (DT_RELASZ
, NULL
, ".rela.plt")
2070 GET_SYMBOL_OR_SECTION (DT_VERSYM
, NULL
, ".gnu.version")
2071 GET_SYMBOL_OR_SECTION (DT_VERDEF
, NULL
, ".gnu.version_d")
2072 GET_SYMBOL_OR_SECTION (DT_VERNEED
, NULL
, ".gnu.version_r")
2077 /* In case the dynamic symbols should be updated with a symbol. */
2079 && (h
->root
.type
== bfd_link_hash_defined
2080 || h
->root
.type
== bfd_link_hash_defweak
))
2084 internal_dyn
.d_un
.d_val
= h
->root
.u
.def
.value
;
2085 asec_ptr
= h
->root
.u
.def
.section
;
2086 if (asec_ptr
->output_section
!= NULL
)
2088 internal_dyn
.d_un
.d_val
+=
2089 (asec_ptr
->output_section
->vma
2090 + asec_ptr
->output_offset
);
2094 /* The symbol is imported from another shared
2095 library and does not apply to this one. */
2096 internal_dyn
.d_un
.d_val
= 0;
2100 else if (s
!= NULL
) /* With a section information. */
2102 switch (internal_dyn
.d_tag
)
2109 internal_dyn
.d_un
.d_ptr
= (s
->output_section
->vma
2110 + s
->output_offset
);
2115 internal_dyn
.d_un
.d_val
= s
->size
;
2121 internal_dyn
.d_un
.d_val
-= s
->size
;
2131 bfd_elf32_swap_dyn_out (output_bfd
, &internal_dyn
, dyncon
);
2134 if (htab
->splt
->size
> 0)
2136 relocate_plt_for_entry (output_bfd
, info
);
2139 /* TODO: Validate this. */
2140 elf_section_data (htab
->srelplt
->output_section
)->this_hdr
.sh_entsize
2144 /* Fill in the first three entries in the global offset table. */
2147 struct elf_link_hash_entry
*h
;
2148 h
= elf_link_hash_lookup (elf_hash_table (info
), "_GLOBAL_OFFSET_TABLE_",
2149 FALSE
, FALSE
, TRUE
);
2151 if (h
!= NULL
&& h
->root
.type
!= bfd_link_hash_undefined
2152 && h
->root
.u
.def
.section
!= NULL
)
2154 asection
*sec
= h
->root
.u
.def
.section
;
2156 if (ds
.sdyn
== NULL
)
2157 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
2160 bfd_put_32 (output_bfd
,
2161 ds
.sdyn
->output_section
->vma
+ ds
.sdyn
->output_offset
,
2163 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sec
->contents
+ 4);
2164 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sec
->contents
+ 8);
2171 #define ADD_DYNAMIC_SYMBOL(NAME, TAG) \
2172 h = elf_link_hash_lookup (elf_hash_table (info), \
2173 NAME, FALSE, FALSE, FALSE); \
2174 if ((h != NULL && (h->ref_regular || h->def_regular))) \
2175 if (! _bfd_elf_add_dynamic_entry (info, TAG, 0)) \
2178 /* Set the sizes of the dynamic sections. */
2180 elf_arc_size_dynamic_sections (bfd
* output_bfd
,
2181 struct bfd_link_info
*info
)
2185 bfd_boolean relocs_exist
= FALSE
;
2186 bfd_boolean reltext_exist
= FALSE
;
2187 struct dynamic_sections ds
= arc_create_dynamic_sections (output_bfd
, info
);
2188 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
2190 dynobj
= (elf_hash_table (info
))->dynobj
;
2191 BFD_ASSERT (dynobj
!= NULL
);
2193 if ((elf_hash_table (info
))->dynamic_sections_created
)
2195 struct elf_link_hash_entry
*h
;
2197 /* Set the contents of the .interp section to the
2199 if (!bfd_link_pic (info
))
2201 s
= bfd_get_section_by_name (dynobj
, ".interp");
2202 BFD_ASSERT (s
!= NULL
);
2203 s
->size
= sizeof (ELF_DYNAMIC_INTERPRETER
);
2204 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2207 /* Add some entries to the .dynamic section. We fill in some of
2208 the values later, in elf_bfd_final_link, but we must add the
2209 entries now so that we know the final size of the .dynamic
2210 section. Checking if the .init section is present. We also
2211 create DT_INIT and DT_FINI entries if the init_str has been
2212 changed by the user. */
2213 ADD_DYNAMIC_SYMBOL ("init", DT_INIT
);
2214 ADD_DYNAMIC_SYMBOL ("fini", DT_FINI
);
2218 /* We may have created entries in the .rela.got section.
2219 However, if we are not creating the dynamic sections, we will
2220 not actually use these entries. Reset the size of .rela.got,
2221 which will cause it to get stripped from the output file
2223 if (htab
->srelgot
!= NULL
)
2224 htab
->srelgot
->size
= 0;
2227 if (htab
->splt
!= NULL
&& htab
->splt
->size
== 0)
2228 htab
->splt
->flags
|= SEC_EXCLUDE
;
2229 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2231 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2234 if (strncmp (s
->name
, ".rela", 5) == 0)
2238 s
->flags
|= SEC_EXCLUDE
;
2242 if (strcmp (s
->name
, ".rela.plt") != 0)
2244 const char *outname
=
2245 bfd_get_section_name (output_bfd
,
2246 htab
->srelplt
->output_section
);
2248 asection
*target
= bfd_get_section_by_name (output_bfd
,
2251 relocs_exist
= TRUE
;
2252 if (target
!= NULL
&& target
->size
!= 0
2253 && (target
->flags
& SEC_READONLY
) != 0
2254 && (target
->flags
& SEC_ALLOC
) != 0)
2255 reltext_exist
= TRUE
;
2259 /* We use the reloc_count field as a counter if we need to
2260 copy relocs into the output file. */
2264 if (strcmp (s
->name
, ".dynamic") == 0)
2268 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->size
);
2270 if (s
->contents
== NULL
&& s
->size
!= 0)
2276 /* TODO: Check if this is needed. */
2277 if (!bfd_link_pic (info
))
2278 if (!_bfd_elf_add_dynamic_entry (info
, DT_DEBUG
, 0))
2281 if (htab
->splt
&& (htab
->splt
->flags
& SEC_EXCLUDE
) == 0)
2282 if (!_bfd_elf_add_dynamic_entry (info
, DT_PLTGOT
, 0)
2283 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2284 || !_bfd_elf_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2285 || !_bfd_elf_add_dynamic_entry (info
, DT_JMPREL
, 0)
2289 if (relocs_exist
== TRUE
)
2290 if (!_bfd_elf_add_dynamic_entry (info
, DT_RELA
, 0)
2291 || !_bfd_elf_add_dynamic_entry (info
, DT_RELASZ
, 0)
2292 || !_bfd_elf_add_dynamic_entry (info
, DT_RELAENT
,
2293 sizeof (Elf32_External_Rela
))
2297 if (reltext_exist
== TRUE
)
2298 if (!_bfd_elf_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2306 /* Classify dynamic relocs such that -z combreloc can reorder and combine
2308 static enum elf_reloc_type_class
2309 elf32_arc_reloc_type_class (const struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
2310 const asection
*rel_sec ATTRIBUTE_UNUSED
,
2311 const Elf_Internal_Rela
*rela
)
2313 switch ((int) ELF32_R_TYPE (rela
->r_info
))
2315 case R_ARC_RELATIVE
:
2316 return reloc_class_relative
;
2317 case R_ARC_JMP_SLOT
:
2318 return reloc_class_plt
;
2320 return reloc_class_copy
;
2321 /* TODO: Needed in future to support ifunc. */
2323 case R_ARC_IRELATIVE:
2324 return reloc_class_ifunc;
2327 return reloc_class_normal
;
2331 const struct elf_size_info arc_elf32_size_info
=
2333 sizeof (Elf32_External_Ehdr
),
2334 sizeof (Elf32_External_Phdr
),
2335 sizeof (Elf32_External_Shdr
),
2336 sizeof (Elf32_External_Rel
),
2337 sizeof (Elf32_External_Rela
),
2338 sizeof (Elf32_External_Sym
),
2339 sizeof (Elf32_External_Dyn
),
2340 sizeof (Elf_External_Note
),
2344 ELFCLASS32
, EV_CURRENT
,
2345 bfd_elf32_write_out_phdrs
,
2346 bfd_elf32_write_shdrs_and_ehdr
,
2347 bfd_elf32_checksum_contents
,
2348 bfd_elf32_write_relocs
,
2349 bfd_elf32_swap_symbol_in
,
2350 bfd_elf32_swap_symbol_out
,
2351 bfd_elf32_slurp_reloc_table
,
2352 bfd_elf32_slurp_symbol_table
,
2353 bfd_elf32_swap_dyn_in
,
2354 bfd_elf32_swap_dyn_out
,
2355 bfd_elf32_swap_reloc_in
,
2356 bfd_elf32_swap_reloc_out
,
2357 bfd_elf32_swap_reloca_in
,
2358 bfd_elf32_swap_reloca_out
2361 #define elf_backend_size_info arc_elf32_size_info
2363 static struct bfd_link_hash_table
*
2364 arc_elf_link_hash_table_create (bfd
*abfd
)
2366 struct elf_link_hash_table
*htab
;
2368 htab
= bfd_zmalloc (sizeof (*htab
));
2372 if (!_bfd_elf_link_hash_table_init (htab
, abfd
,
2373 _bfd_elf_link_hash_newfunc
,
2374 sizeof (struct elf_link_hash_entry
),
2381 htab
->init_got_refcount
.refcount
= 0;
2382 htab
->init_got_refcount
.glist
= NULL
;
2383 htab
->init_got_offset
.offset
= 0;
2384 htab
->init_got_offset
.glist
= NULL
;
2385 return (struct bfd_link_hash_table
*) htab
;
2388 /* Hook called by the linker routine which adds symbols from an object
2392 elf_arc_add_symbol_hook (bfd
* abfd
,
2393 struct bfd_link_info
* info
,
2394 Elf_Internal_Sym
* sym
,
2395 const char ** namep ATTRIBUTE_UNUSED
,
2396 flagword
* flagsp ATTRIBUTE_UNUSED
,
2397 asection
** secp ATTRIBUTE_UNUSED
,
2398 bfd_vma
* valp ATTRIBUTE_UNUSED
)
2400 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
2401 && (abfd
->flags
& DYNAMIC
) == 0
2402 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
2403 elf_tdata (info
->output_bfd
)->has_gnu_symbols
|= elf_gnu_symbol_ifunc
;
2408 #define TARGET_LITTLE_SYM arc_elf32_le_vec
2409 #define TARGET_LITTLE_NAME "elf32-littlearc"
2410 #define TARGET_BIG_SYM arc_elf32_be_vec
2411 #define TARGET_BIG_NAME "elf32-bigarc"
2412 #define ELF_ARCH bfd_arch_arc
2413 #define ELF_MACHINE_CODE EM_ARC_COMPACT
2414 #define ELF_MACHINE_ALT1 EM_ARC_COMPACT2
2415 #define ELF_MAXPAGESIZE 0x2000
2417 #define bfd_elf32_bfd_link_hash_table_create arc_elf_link_hash_table_create
2419 #define bfd_elf32_bfd_merge_private_bfd_data arc_elf_merge_private_bfd_data
2420 #define bfd_elf32_bfd_reloc_type_lookup arc_elf32_bfd_reloc_type_lookup
2421 #define bfd_elf32_bfd_set_private_flags arc_elf_set_private_flags
2422 #define bfd_elf32_bfd_print_private_bfd_data arc_elf_print_private_bfd_data
2423 #define bfd_elf32_bfd_copy_private_bfd_data arc_elf_copy_private_bfd_data
2425 #define elf_info_to_howto_rel arc_info_to_howto_rel
2426 #define elf_backend_object_p arc_elf_object_p
2427 #define elf_backend_final_write_processing arc_elf_final_write_processing
2429 #define elf_backend_relocate_section elf_arc_relocate_section
2430 #define elf_backend_check_relocs elf_arc_check_relocs
2431 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2433 #define elf_backend_reloc_type_class elf32_arc_reloc_type_class
2435 #define elf_backend_adjust_dynamic_symbol elf_arc_adjust_dynamic_symbol
2436 #define elf_backend_finish_dynamic_symbol elf_arc_finish_dynamic_symbol
2438 #define elf_backend_finish_dynamic_sections elf_arc_finish_dynamic_sections
2439 #define elf_backend_size_dynamic_sections elf_arc_size_dynamic_sections
2440 #define elf_backend_add_symbol_hook elf_arc_add_symbol_hook
2442 #define elf_backend_can_gc_sections 1
2443 #define elf_backend_want_got_plt 1
2444 #define elf_backend_plt_readonly 1
2445 #define elf_backend_rela_plts_and_copies_p 1
2446 #define elf_backend_want_plt_sym 0
2447 #define elf_backend_got_header_size 12
2449 #define elf_backend_may_use_rel_p 0
2450 #define elf_backend_may_use_rela_p 1
2451 #define elf_backend_default_use_rela_p 1
2453 #define elf_backend_default_execstack 0
2455 #include "elf32-target.h"