1 /* ARC-specific support for 32-bit ELF
2 Copyright (C) 1994-2017 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"
32 /* #define ARC_ENABLE_DEBUG 1 */
33 #ifdef ARC_ENABLE_DEBUG
35 name_for_global_symbol (struct elf_link_hash_entry *h)
37 static char *local_str = "(local)";
40 return h->root.root.string;
42 #define ARC_DEBUG(fmt, args...) fprintf (stderr, fmt, ##args)
44 #define ARC_DEBUG(...)
48 #define ADD_RELA(BFD, SECTION, OFFSET, SYM_IDX, TYPE, ADDEND) \
50 struct elf_link_hash_table *_htab = elf_hash_table (info); \
51 Elf_Internal_Rela _rel; \
54 BFD_ASSERT (_htab->srel##SECTION &&_htab->srel##SECTION->contents); \
55 _loc = _htab->srel##SECTION->contents \
56 + ((_htab->srel##SECTION->reloc_count) \
57 * sizeof (Elf32_External_Rela)); \
58 _htab->srel##SECTION->reloc_count++; \
59 _rel.r_addend = ADDEND; \
60 _rel.r_offset = (_htab->s##SECTION)->output_section->vma \
61 + (_htab->s##SECTION)->output_offset + OFFSET; \
62 BFD_ASSERT ((long) SYM_IDX != -1); \
63 _rel.r_info = ELF32_R_INFO (SYM_IDX, TYPE); \
64 bfd_elf32_swap_reloca_out (BFD, &_rel, _loc); \
68 /* The default symbols representing the init and fini dyn values.
69 TODO: Check what is the relation of those strings with arclinux.em
71 #define INIT_SYM_STRING "_init"
72 #define FINI_SYM_STRING "_fini"
74 char * init_str = INIT_SYM_STRING;
75 char * fini_str = FINI_SYM_STRING;
77 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
82 static ATTRIBUTE_UNUSED const char *
83 reloc_type_to_name (unsigned int type)
87 #include "elf/arc-reloc.def"
94 #undef ARC_RELOC_HOWTO
96 /* Try to minimize the amount of space occupied by relocation tables
97 on the ROM (not that the ROM won't be swamped by other ELF overhead). */
101 static ATTRIBUTE_UNUSED bfd_boolean
102 is_reloc_PC_relative (reloc_howto_type *howto)
104 return (strstr (howto->name, "PC") != NULL) ? TRUE : FALSE;
108 is_reloc_SDA_relative (reloc_howto_type *howto)
110 return (strstr (howto->name, "SDA") != NULL) ? TRUE : FALSE;
114 is_reloc_for_GOT (reloc_howto_type * howto)
116 if (strstr (howto->name, "TLS") != NULL)
118 return (strstr (howto->name, "GOT") != NULL) ? TRUE : FALSE;
122 is_reloc_for_PLT (reloc_howto_type * howto)
124 return (strstr (howto->name, "PLT") != NULL) ? TRUE : FALSE;
128 is_reloc_for_TLS (reloc_howto_type *howto)
130 return (strstr (howto->name, "TLS") != NULL) ? TRUE : FALSE;
133 struct arc_relocation_data
135 bfd_signed_vma reloc_offset;
136 bfd_signed_vma reloc_addend;
137 bfd_signed_vma got_offset_value;
139 bfd_signed_vma sym_value;
140 asection * sym_section;
142 reloc_howto_type *howto;
144 asection * input_section;
146 bfd_signed_vma sdata_begin_symbol_vma;
147 bfd_boolean sdata_begin_symbol_vma_set;
148 bfd_signed_vma got_symbol_vma;
150 bfd_boolean should_relocate;
152 const char * symbol_name;
155 /* Should be included at this location due to static declarations
156 * defined before this point. */
159 #define arc_bfd_get_8(A,B,C) bfd_get_8(A,B)
160 #define arc_bfd_get_16(A,B,C) bfd_get_16(A,B)
161 #define arc_bfd_get_32(A,B,C) bfd_get_32(A,B)
162 #define arc_bfd_put_8(A,B,C,D) bfd_put_8(A,B,C)
163 #define arc_bfd_put_16(A,B,C,D) bfd_put_16(A,B,C)
164 #define arc_bfd_put_32(A,B,C,D) bfd_put_32(A,B,C)
167 static bfd_reloc_status_type
168 arc_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
169 arelent *reloc_entry,
171 void *data ATTRIBUTE_UNUSED,
172 asection *input_section,
174 char ** error_message ATTRIBUTE_UNUSED)
176 if (output_bfd != NULL)
178 reloc_entry->address += input_section->output_offset;
180 /* In case of relocateable link and if the reloc is against a
181 section symbol, the addend needs to be adjusted according to
182 where the section symbol winds up in the output section. */
183 if ((symbol_in->flags & BSF_SECTION_SYM) && symbol_in->section)
184 reloc_entry->addend += symbol_in->section->output_offset;
189 return bfd_reloc_continue;
193 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
197 #include "elf/arc-reloc.def"
200 #undef ARC_RELOC_HOWTO
202 #define ARC_RELOC_HOWTO(TYPE, VALUE, RSIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
203 [TYPE] = HOWTO (R_##TYPE, 0, RSIZE, BITSIZE, FALSE, 0, \
204 complain_overflow_##OVERFLOW, arc_elf_reloc, \
205 "R_" #TYPE, FALSE, 0, 0, FALSE),
207 static struct reloc_howto_struct elf_arc_howto_table[] =
209 #include "elf/arc-reloc.def"
210 /* Example of what is generated by the preprocessor. Currently kept as an
212 HOWTO (R_ARC_NONE, // Type.
214 2, // Size (0 = byte, 1 = short, 2 = long).
216 FALSE, // PC_relative.
218 complain_overflow_bitfield, // Complain_on_overflow.
219 bfd_elf_generic_reloc, // Special_function.
220 "R_ARC_NONE", // Name.
221 TRUE, // Partial_inplace.
224 FALSE), // PCrel_offset.
227 #undef ARC_RELOC_HOWTO
229 static void arc_elf_howto_init (void)
231 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
232 elf_arc_howto_table[TYPE].pc_relative = \
233 (strstr (#FORMULA, " P ") != NULL || strstr (#FORMULA, " PDATA ") != NULL); \
234 elf_arc_howto_table[TYPE].dst_mask = RELOC_FUNCTION(0, ~0); \
235 /* Only 32 bit data relocations should be marked as ME. */ \
236 if (strstr (#FORMULA, " ME ") != NULL) \
238 BFD_ASSERT (SIZE == 2); \
241 #include "elf/arc-reloc.def"
244 #undef ARC_RELOC_HOWTO
247 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
249 const int howto_table_lookup[] =
251 #include "elf/arc-reloc.def"
253 #undef ARC_RELOC_HOWTO
255 static reloc_howto_type *
256 arc_elf_howto (unsigned int r_type)
258 if (elf_arc_howto_table[R_ARC_32].dst_mask == 0)
259 arc_elf_howto_init ();
260 return &elf_arc_howto_table[r_type];
263 /* Map BFD reloc types to ARC ELF reloc types. */
267 bfd_reloc_code_real_type bfd_reloc_val;
268 unsigned char elf_reloc_val;
271 /* ARC ELF linker hash entry. */
272 struct elf_arc_link_hash_entry
274 struct elf_link_hash_entry root;
276 /* Track dynamic relocs copied for this symbol. */
277 struct elf_dyn_relocs *dyn_relocs;
280 /* ARC ELF linker hash table. */
281 struct elf_arc_link_hash_table
283 struct elf_link_hash_table elf;
286 static struct bfd_hash_entry *
287 elf_arc_link_hash_newfunc (struct bfd_hash_entry *entry,
288 struct bfd_hash_table *table,
291 /* Allocate the structure if it has not already been allocated by a
295 entry = (struct bfd_hash_entry *)
296 bfd_hash_allocate (table,
297 sizeof (struct elf_arc_link_hash_entry));
302 /* Call the allocation method of the superclass. */
303 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
306 struct elf_arc_link_hash_entry *eh;
308 eh = (struct elf_arc_link_hash_entry *) entry;
309 eh->dyn_relocs = NULL;
315 /* Destroy an ARC ELF linker hash table. */
317 elf_arc_link_hash_table_free (bfd *obfd)
319 _bfd_elf_link_hash_table_free (obfd);
322 /* Create an ARC ELF linker hash table. */
324 static struct bfd_link_hash_table *
325 arc_elf_link_hash_table_create (bfd *abfd)
327 struct elf_arc_link_hash_table *ret;
329 ret = (struct elf_arc_link_hash_table *) bfd_zmalloc (sizeof (*ret));
333 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
334 elf_arc_link_hash_newfunc,
335 sizeof (struct elf_arc_link_hash_entry),
342 ret->elf.init_got_refcount.refcount = 0;
343 ret->elf.init_got_refcount.glist = NULL;
344 ret->elf.init_got_offset.offset = 0;
345 ret->elf.init_got_offset.glist = NULL;
347 ret->elf.root.hash_table_free = elf_arc_link_hash_table_free;
349 return &ret->elf.root;
352 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
353 { BFD_RELOC_##TYPE, R_##TYPE },
354 static const struct arc_reloc_map arc_reloc_map[] =
356 #include "elf/arc-reloc.def"
358 {BFD_RELOC_NONE, R_ARC_NONE},
359 {BFD_RELOC_8, R_ARC_8},
360 {BFD_RELOC_16, R_ARC_16},
361 {BFD_RELOC_24, R_ARC_24},
362 {BFD_RELOC_32, R_ARC_32},
364 #undef ARC_RELOC_HOWTO
366 typedef ATTRIBUTE_UNUSED bfd_vma (*replace_func) (unsigned, int ATTRIBUTE_UNUSED);
368 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
370 func = (void *) RELOC_FUNCTION; \
373 get_replace_function (bfd *abfd, unsigned int r_type)
379 #include "elf/arc-reloc.def"
382 if (func == replace_bits24 && bfd_big_endian (abfd))
383 return (replace_func) replace_bits24_be;
385 return (replace_func) func;
387 #undef ARC_RELOC_HOWTO
389 static reloc_howto_type *
390 arc_elf32_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
391 bfd_reloc_code_real_type code)
395 for (i = ARRAY_SIZE (arc_reloc_map); i--;)
397 if (arc_reloc_map[i].bfd_reloc_val == code)
398 return arc_elf_howto (arc_reloc_map[i].elf_reloc_val);
404 /* Function to set the ELF flag bits. */
406 arc_elf_set_private_flags (bfd *abfd, flagword flags)
408 elf_elfheader (abfd)->e_flags = flags;
409 elf_flags_init (abfd) = TRUE;
413 /* Print private flags. */
415 arc_elf_print_private_bfd_data (bfd *abfd, void * ptr)
417 FILE *file = (FILE *) ptr;
420 BFD_ASSERT (abfd != NULL && ptr != NULL);
422 /* Print normal ELF private data. */
423 _bfd_elf_print_private_bfd_data (abfd, ptr);
425 flags = elf_elfheader (abfd)->e_flags;
426 fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
428 switch (flags & EF_ARC_MACH_MSK)
430 case EF_ARC_CPU_ARCV2HS : fprintf (file, " -mcpu=ARCv2HS"); break;
431 case EF_ARC_CPU_ARCV2EM : fprintf (file, " -mcpu=ARCv2EM"); break;
432 case E_ARC_MACH_ARC600 : fprintf (file, " -mcpu=ARC600"); break;
433 case E_ARC_MACH_ARC601 : fprintf (file, " -mcpu=ARC601"); break;
434 case E_ARC_MACH_ARC700 : fprintf (file, " -mcpu=ARC700"); break;
436 fprintf (file, "-mcpu=unknown");
440 switch (flags & EF_ARC_OSABI_MSK)
442 case E_ARC_OSABI_ORIG : fprintf (file, " (ABI:legacy)"); break;
443 case E_ARC_OSABI_V2 : fprintf (file, " (ABI:v2)"); break;
444 case E_ARC_OSABI_V3 : fprintf (file, " (ABI:v3)"); break;
446 fprintf (file, "(ABI:unknown)");
454 /* Copy backend specific data from one object module to another. */
457 arc_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
459 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
460 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
463 BFD_ASSERT (!elf_flags_init (obfd)
464 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
466 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
467 elf_flags_init (obfd) = TRUE;
469 /* Copy object attributes. */
470 _bfd_elf_copy_obj_attributes (ibfd, obfd);
472 return _bfd_elf_copy_private_bfd_data (ibfd, obfd);
475 static reloc_howto_type *
476 bfd_elf32_bfd_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED,
481 for (i = 0; i < ARRAY_SIZE (elf_arc_howto_table); i++)
482 if (elf_arc_howto_table[i].name != NULL
483 && strcasecmp (elf_arc_howto_table[i].name, r_name) == 0)
484 return arc_elf_howto (i);
489 /* Set the howto pointer for an ARC ELF reloc. */
492 arc_info_to_howto_rel (bfd * abfd ATTRIBUTE_UNUSED,
494 Elf_Internal_Rela * dst)
498 r_type = ELF32_R_TYPE (dst->r_info);
499 BFD_ASSERT (r_type < (unsigned int) R_ARC_max);
500 cache_ptr->howto = arc_elf_howto (r_type);
503 /* Merge backend specific data from an object file to the output
504 object file when linking. */
507 arc_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
509 bfd *obfd = info->output_bfd;
510 unsigned short mach_ibfd;
511 static unsigned short mach_obfd = EM_NONE;
516 /* Check if we have the same endianess. */
517 if (! _bfd_generic_verify_endian_match (ibfd, info))
520 /* Collect ELF flags. */
521 in_flags = elf_elfheader (ibfd)->e_flags & EF_ARC_MACH_MSK;
522 out_flags = elf_elfheader (obfd)->e_flags & EF_ARC_MACH_MSK;
524 if (!elf_flags_init (obfd)) /* First call, no flags set. */
526 elf_flags_init (obfd) = TRUE;
527 out_flags = in_flags;
530 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
531 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
534 /* Check to see if the input BFD actually contains any sections. Do
535 not short-circuit dynamic objects; their section list may be
536 emptied by elf_link_add_object_symbols. */
537 if (!(ibfd->flags & DYNAMIC))
539 bfd_boolean null_input_bfd = TRUE;
540 bfd_boolean only_data_sections = TRUE;
542 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
544 if ((bfd_get_section_flags (ibfd, sec)
545 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
546 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
547 only_data_sections = FALSE;
549 null_input_bfd = FALSE;
552 if (null_input_bfd || only_data_sections)
556 /* Complain about various flag/architecture mismatches. */
557 mach_ibfd = elf_elfheader (ibfd)->e_machine;
558 if (mach_obfd == EM_NONE)
560 mach_obfd = mach_ibfd;
564 if (mach_ibfd != mach_obfd)
566 /* xgettext:c-format */
567 _bfd_error_handler (_("ERROR: Attempting to link %B "
568 "with a binary %B of different architecture"),
572 else if (in_flags != out_flags)
574 /* Warn if different flags. */
576 /* xgettext:c-format */
577 (_("%B: uses different e_flags (0x%lx) fields than "
578 "previous modules (0x%lx)"),
579 ibfd, (long) in_flags, (long) out_flags);
580 if (in_flags && out_flags)
582 /* MWDT doesnt set the eflags hence make sure we choose the
583 eflags set by gcc. */
584 in_flags = in_flags > out_flags ? in_flags : out_flags;
588 /* Update the flags. */
589 elf_elfheader (obfd)->e_flags = in_flags;
591 if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
593 return bfd_set_arch_mach (obfd, bfd_arch_arc, bfd_get_mach (ibfd));
599 /* Set the right machine number for an ARC ELF file. */
601 arc_elf_object_p (bfd * abfd)
603 /* Make sure this is initialised, or you'll have the potential of passing
604 garbage---or misleading values---into the call to
605 bfd_default_set_arch_mach (). */
606 int mach = bfd_mach_arc_arc700;
607 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH_MSK;
608 unsigned e_machine = elf_elfheader (abfd)->e_machine;
610 if (e_machine == EM_ARC_COMPACT || e_machine == EM_ARC_COMPACT2)
614 case E_ARC_MACH_ARC600:
615 mach = bfd_mach_arc_arc600;
617 case E_ARC_MACH_ARC601:
618 mach = bfd_mach_arc_arc601;
620 case E_ARC_MACH_ARC700:
621 mach = bfd_mach_arc_arc700;
623 case EF_ARC_CPU_ARCV2HS:
624 case EF_ARC_CPU_ARCV2EM:
625 mach = bfd_mach_arc_arcv2;
628 mach = (e_machine == EM_ARC_COMPACT)
629 ? bfd_mach_arc_arc700 : bfd_mach_arc_arcv2;
635 if (e_machine == EM_ARC)
638 (_("Error: The ARC4 architecture is no longer supported.\n"));
644 (_("Warning: unset or old architecture flags. \n"
645 " Use default machine.\n"));
649 return bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
652 /* The final processing done just before writing out an ARC ELF object file.
653 This gets the ARC architecture right based on the machine number. */
656 arc_elf_final_write_processing (bfd * abfd,
657 bfd_boolean linker ATTRIBUTE_UNUSED)
661 switch (bfd_get_mach (abfd))
663 case bfd_mach_arc_arc600:
664 emf = EM_ARC_COMPACT;
666 case bfd_mach_arc_arc601:
667 emf = EM_ARC_COMPACT;
669 case bfd_mach_arc_arc700:
670 emf = EM_ARC_COMPACT;
672 case bfd_mach_arc_arcv2:
673 emf = EM_ARC_COMPACT2;
679 elf_elfheader (abfd)->e_machine = emf;
681 /* Record whatever is the current syscall ABI version. */
682 elf_elfheader (abfd)->e_flags |= E_ARC_OSABI_CURRENT;
688 #ifdef ARC_ENABLE_DEBUG
689 #define DEBUG_ARC_RELOC(A) debug_arc_reloc (A)
692 debug_arc_reloc (struct arc_relocation_data reloc_data)
694 ARC_DEBUG ("Reloc type=%s, should_relocate = %s\n",
695 reloc_data.howto->name,
696 reloc_data.should_relocate ? "true" : "false");
697 ARC_DEBUG (" offset = 0x%x, addend = 0x%x\n",
698 (unsigned int) reloc_data.reloc_offset,
699 (unsigned int) reloc_data.reloc_addend);
700 ARC_DEBUG (" Symbol:\n");
701 ARC_DEBUG (" value = 0x%08x\n",
702 (unsigned int) reloc_data.sym_value);
703 if (reloc_data.sym_section != NULL)
705 ARC_DEBUG (" Symbol Section:\n");
706 ARC_DEBUG (" section name = %s, output_offset 0x%08x",
707 reloc_data.sym_section->name,
708 (unsigned int) reloc_data.sym_section->output_offset);
709 if (reloc_data.sym_section->output_section != NULL)
710 ARC_DEBUG (", output_section->vma = 0x%08x",
711 ((unsigned int) reloc_data.sym_section->output_section->vma));
713 if (reloc_data.sym_section->owner && reloc_data.sym_section->owner->filename)
714 ARC_DEBUG (" file: %s\n", reloc_data.sym_section->owner->filename);
718 ARC_DEBUG (" symbol section is NULL\n");
721 ARC_DEBUG (" Input_section:\n");
722 if (reloc_data.input_section != NULL)
724 ARC_DEBUG (" section name = %s, output_offset 0x%08x, output_section->vma = 0x%08x\n",
725 reloc_data.input_section->name,
726 (unsigned int) reloc_data.input_section->output_offset,
727 (unsigned int) reloc_data.input_section->output_section->vma);
728 ARC_DEBUG (" changed_address = 0x%08x\n",
729 (unsigned int) (reloc_data.input_section->output_section->vma
730 + reloc_data.input_section->output_offset
731 + reloc_data.reloc_offset));
732 ARC_DEBUG (" file: %s\n", reloc_data.input_section->owner->filename);
736 ARC_DEBUG (" input section is NULL\n");
740 #define DEBUG_ARC_RELOC(A)
741 #endif /* ARC_ENABLE_DEBUG */
744 middle_endian_convert (bfd_vma insn, bfd_boolean do_it)
749 = ((insn & 0xffff0000) >> 16)
750 | ((insn & 0xffff) << 16);
755 /* This function is called for relocations that are otherwise marked as NOT
756 requiring overflow checks. In here we perform non-standard checks of
757 the relocation value. */
759 static inline bfd_reloc_status_type
760 arc_special_overflow_checks (const struct arc_relocation_data reloc_data,
761 bfd_signed_vma relocation,
762 struct bfd_link_info *info ATTRIBUTE_UNUSED)
764 switch (reloc_data.howto->type)
766 case R_ARC_NPS_CMEM16:
767 if (((relocation >> 16) & 0xffff) != NPS_CMEM_HIGH_VALUE)
769 if (reloc_data.reloc_addend == 0)
771 /* xgettext:c-format */
772 (_("%B(%A+0x%lx): CMEM relocation to `%s' is invalid, "
773 "16 MSB should be 0x%04x (value is 0x%lx)"),
774 reloc_data.input_section->owner,
775 reloc_data.input_section,
776 reloc_data.reloc_offset,
777 reloc_data.symbol_name,
782 /* xgettext:c-format */
783 (_("%B(%A+0x%lx): CMEM relocation to `%s+0x%lx' is invalid, "
784 "16 MSB should be 0x%04x (value is 0x%lx)"),
785 reloc_data.input_section->owner,
786 reloc_data.input_section,
787 reloc_data.reloc_offset,
788 reloc_data.symbol_name,
789 reloc_data.reloc_addend,
792 return bfd_reloc_overflow;
803 #define ME(reloc) (reloc)
805 #define IS_ME(FORMULA,BFD) ((strstr (FORMULA, "ME") != NULL) \
806 && (!bfd_big_endian (BFD)))
808 #define S ((bfd_signed_vma) (reloc_data.sym_value \
809 + (reloc_data.sym_section->output_section != NULL ? \
810 (reloc_data.sym_section->output_offset \
811 + reloc_data.sym_section->output_section->vma) : 0)))
812 #define L ((bfd_signed_vma) (reloc_data.sym_value \
813 + (reloc_data.sym_section->output_section != NULL ? \
814 (reloc_data.sym_section->output_offset \
815 + reloc_data.sym_section->output_section->vma) : 0)))
816 #define A (reloc_data.reloc_addend)
818 #define G (reloc_data.got_offset_value)
819 #define GOT (reloc_data.got_symbol_vma)
820 #define GOT_BEGIN (htab->sgot->output_section->vma)
823 /* P: relative offset to PCL The offset should be to the
824 current location aligned to 32 bits. */
825 #define P ((bfd_signed_vma) ( \
827 (reloc_data.input_section->output_section != NULL ? \
828 reloc_data.input_section->output_section->vma : 0) \
829 + reloc_data.input_section->output_offset \
830 + (reloc_data.reloc_offset - (bitsize >= 32 ? 4 : 0))) \
832 #define PDATA ((bfd_signed_vma) ( \
833 (reloc_data.input_section->output_section->vma \
834 + reloc_data.input_section->output_offset \
835 + (reloc_data.reloc_offset))))
836 #define SECTSTART (bfd_signed_vma) (reloc_data.sym_section->output_section->vma \
837 + reloc_data.sym_section->output_offset)
839 #define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
840 #define TLS_REL (bfd_signed_vma) \
841 ((elf_hash_table (info))->tls_sec->output_section->vma)
847 #ifdef ARC_ENABLE_DEBUG
848 #define PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA, TYPE) \
851 asection *sym_section = reloc_data.sym_section; \
852 asection *input_section = reloc_data.input_section; \
853 ARC_DEBUG ("RELOC_TYPE = " TYPE "\n"); \
854 ARC_DEBUG ("FORMULA = " FORMULA "\n"); \
855 ARC_DEBUG ("S = %#lx\n", S); \
856 ARC_DEBUG ("A = %#lx\n", A); \
857 ARC_DEBUG ("L = %lx\n", L); \
858 if (sym_section->output_section != NULL) \
859 ARC_DEBUG ("symbol_section->vma = %#lx\n", \
860 sym_section->output_section->vma \
861 + sym_section->output_offset); \
863 ARC_DEBUG ("symbol_section->vma = NULL\n"); \
864 if (input_section->output_section != NULL) \
865 ARC_DEBUG ("symbol_section->vma = %#lx\n", \
866 input_section->output_section->vma \
867 + input_section->output_offset); \
869 ARC_DEBUG ("symbol_section->vma = NULL\n"); \
870 ARC_DEBUG ("PCL = %#lx\n", P); \
871 ARC_DEBUG ("P = %#lx\n", P); \
872 ARC_DEBUG ("G = %#lx\n", G); \
873 ARC_DEBUG ("SDA_OFFSET = %#lx\n", _SDA_BASE_); \
874 ARC_DEBUG ("SDA_SET = %d\n", reloc_data.sdata_begin_symbol_vma_set); \
875 ARC_DEBUG ("GOT_OFFSET = %#lx\n", GOT); \
876 ARC_DEBUG ("relocation = %#08lx\n", relocation); \
877 ARC_DEBUG ("before = %#08x\n", (unsigned) insn); \
878 ARC_DEBUG ("data = %08x (%u) (%d)\n", (unsigned) relocation, \
879 (unsigned) relocation, (int) relocation); \
883 #define PRINT_DEBUG_RELOC_INFO_AFTER \
886 ARC_DEBUG ("after = 0x%08x\n", (unsigned int) insn); \
892 #define PRINT_DEBUG_RELOC_INFO_BEFORE(...)
893 #define PRINT_DEBUG_RELOC_INFO_AFTER
895 #endif /* ARC_ENABLE_DEBUG */
897 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
900 bfd_signed_vma bitsize ATTRIBUTE_UNUSED = BITSIZE; \
901 relocation = FORMULA ; \
902 PRINT_DEBUG_RELOC_INFO_BEFORE (#FORMULA, #TYPE); \
903 insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
904 insn = (* get_replace_function (abfd, TYPE)) (insn, relocation); \
905 insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
906 PRINT_DEBUG_RELOC_INFO_AFTER; \
910 static bfd_reloc_status_type
911 arc_do_relocation (bfd_byte * contents,
912 struct arc_relocation_data reloc_data,
913 struct bfd_link_info *info)
915 bfd_signed_vma relocation = 0;
917 bfd_vma orig_insn ATTRIBUTE_UNUSED;
918 bfd * abfd = reloc_data.input_section->owner;
919 struct elf_link_hash_table *htab ATTRIBUTE_UNUSED = elf_hash_table (info);
920 bfd_reloc_status_type flag;
922 if (reloc_data.should_relocate == FALSE)
925 switch (reloc_data.howto->size)
928 insn = arc_bfd_get_32 (abfd,
929 contents + reloc_data.reloc_offset,
930 reloc_data.input_section);
933 insn = arc_bfd_get_16 (abfd,
934 contents + reloc_data.reloc_offset,
935 reloc_data.input_section);
938 insn = arc_bfd_get_8 (abfd,
939 contents + reloc_data.reloc_offset,
940 reloc_data.input_section);
950 switch (reloc_data.howto->type)
952 #include "elf/arc-reloc.def"
959 /* Check for relocation overflow. */
960 if (reloc_data.howto->complain_on_overflow != complain_overflow_dont)
961 flag = bfd_check_overflow (reloc_data.howto->complain_on_overflow,
962 reloc_data.howto->bitsize,
963 reloc_data.howto->rightshift,
964 bfd_arch_bits_per_address (abfd),
967 flag = arc_special_overflow_checks (reloc_data, relocation, info);
969 if (flag != bfd_reloc_ok)
971 ARC_DEBUG ("Relocation overflows !\n");
972 DEBUG_ARC_RELOC (reloc_data);
973 ARC_DEBUG ("Relocation value = signed -> %d, unsigned -> %u"
974 ", hex -> (0x%08x)\n",
975 (int) relocation, (unsigned) relocation, (int) relocation);
980 /* Write updated instruction back to memory. */
981 switch (reloc_data.howto->size)
984 arc_bfd_put_32 (abfd, insn,
985 contents + reloc_data.reloc_offset,
986 reloc_data.input_section);
989 arc_bfd_put_16 (abfd, insn,
990 contents + reloc_data.reloc_offset,
991 reloc_data.input_section);
994 arc_bfd_put_8 (abfd, insn,
995 contents + reloc_data.reloc_offset,
996 reloc_data.input_section);
999 ARC_DEBUG ("size = %d\n", reloc_data.howto->size);
1004 return bfd_reloc_ok;
1019 #undef ARC_RELOC_HOWTO
1022 /* Relocate an arc ELF section.
1023 Function : elf_arc_relocate_section
1024 Brief : Relocate an arc section, by handling all the relocations
1025 appearing in that section.
1026 Args : output_bfd : The bfd being written to.
1027 info : Link information.
1028 input_bfd : The input bfd.
1029 input_section : The section being relocated.
1030 contents : contents of the section being relocated.
1031 relocs : List of relocations in the section.
1032 local_syms : is a pointer to the swapped in local symbols.
1033 local_section : is an array giving the section in the input file
1034 corresponding to the st_shndx field of each
1037 elf_arc_relocate_section (bfd * output_bfd,
1038 struct bfd_link_info * info,
1040 asection * input_section,
1041 bfd_byte * contents,
1042 Elf_Internal_Rela * relocs,
1043 Elf_Internal_Sym * local_syms,
1044 asection ** local_sections)
1046 Elf_Internal_Shdr * symtab_hdr;
1047 struct elf_link_hash_entry ** sym_hashes;
1048 Elf_Internal_Rela * rel;
1049 Elf_Internal_Rela * wrel;
1050 Elf_Internal_Rela * relend;
1051 struct elf_link_hash_table * htab = elf_hash_table (info);
1053 symtab_hdr = &((elf_tdata (input_bfd))->symtab_hdr);
1054 sym_hashes = elf_sym_hashes (input_bfd);
1056 rel = wrel = relocs;
1057 relend = relocs + input_section->reloc_count;
1058 for (; rel < relend; wrel++, rel++)
1060 enum elf_arc_reloc_type r_type;
1061 reloc_howto_type * howto;
1062 unsigned long r_symndx;
1063 struct elf_link_hash_entry * h;
1064 Elf_Internal_Sym * sym;
1066 struct elf_link_hash_entry * h2;
1069 struct arc_relocation_data reloc_data =
1073 .got_offset_value = 0,
1075 .sym_section = NULL,
1077 .input_section = NULL,
1078 .sdata_begin_symbol_vma = 0,
1079 .sdata_begin_symbol_vma_set = FALSE,
1080 .got_symbol_vma = 0,
1081 .should_relocate = FALSE
1084 r_type = ELF32_R_TYPE (rel->r_info);
1086 if (r_type >= (int) R_ARC_max)
1088 bfd_set_error (bfd_error_bad_value);
1091 howto = arc_elf_howto (r_type);
1093 r_symndx = ELF32_R_SYM (rel->r_info);
1095 /* If we are generating another .o file and the symbol in not
1096 local, skip this relocation. */
1097 if (bfd_link_relocatable (info))
1099 /* This is a relocateable link. We don't have to change
1100 anything, unless the reloc is against a section symbol,
1101 in which case we have to adjust according to where the
1102 section symbol winds up in the output section. */
1104 /* Checks if this is a local symbol and thus the reloc
1105 might (will??) be against a section symbol. */
1106 if (r_symndx < symtab_hdr->sh_info)
1108 sym = local_syms + r_symndx;
1109 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1111 sec = local_sections[r_symndx];
1113 /* For RELA relocs. Just adjust the addend
1114 value in the relocation entry. */
1115 rel->r_addend += sec->output_offset + sym->st_value;
1117 ARC_DEBUG ("local symbols reloc (section=%d %s) seen in %s\n",
1118 (int) r_symndx, local_sections[r_symndx]->name,
1119 __PRETTY_FUNCTION__);
1124 h2 = elf_link_hash_lookup (elf_hash_table (info), "__SDATA_BEGIN__",
1125 FALSE, FALSE, TRUE);
1127 if (reloc_data.sdata_begin_symbol_vma_set == FALSE
1128 && h2 != NULL && h2->root.type != bfd_link_hash_undefined
1129 && h2->root.u.def.section->output_section != NULL)
1130 /* TODO: Verify this condition. */
1132 reloc_data.sdata_begin_symbol_vma =
1133 (h2->root.u.def.value
1134 + h2->root.u.def.section->output_section->vma);
1135 reloc_data.sdata_begin_symbol_vma_set = TRUE;
1138 reloc_data.input_section = input_section;
1139 reloc_data.howto = howto;
1140 reloc_data.reloc_offset = rel->r_offset;
1141 reloc_data.reloc_addend = rel->r_addend;
1143 /* This is a final link. */
1148 if (r_symndx < symtab_hdr->sh_info) /* A local symbol. */
1150 sym = local_syms + r_symndx;
1151 sec = local_sections[r_symndx];
1155 /* TODO: This code is repeated from below. We should
1156 clean it and remove duplications.
1157 Sec is used check for discarded sections.
1158 Need to redesign code below. */
1160 /* Get the symbol's entry in the symtab. */
1161 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1163 while (h->root.type == bfd_link_hash_indirect
1164 || h->root.type == bfd_link_hash_warning)
1165 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1167 /* If we have encountered a definition for this symbol. */
1168 if (h->root.type == bfd_link_hash_defined
1169 || h->root.type == bfd_link_hash_defweak)
1171 reloc_data.sym_value = h->root.u.def.value;
1172 sec = h->root.u.def.section;
1176 /* Clean relocs for symbols in discarded sections. */
1177 if (sec != NULL && discarded_section (sec))
1179 _bfd_clear_contents (howto, input_bfd, input_section,
1180 contents + rel->r_offset);
1181 rel->r_offset = rel->r_offset;
1185 /* For ld -r, remove relocations in debug sections against
1186 sections defined in discarded sections. Not done for
1187 eh_frame editing code expects to be present. */
1188 if (bfd_link_relocatable (info)
1189 && (input_section->flags & SEC_DEBUGGING))
1195 if (bfd_link_relocatable (info))
1202 if (r_symndx < symtab_hdr->sh_info) /* A local symbol. */
1204 reloc_data.sym_value = sym->st_value;
1205 reloc_data.sym_section = sec;
1206 reloc_data.symbol_name =
1207 bfd_elf_string_from_elf_section (input_bfd,
1208 symtab_hdr->sh_link,
1211 /* Mergeable section handling. */
1212 if ((sec->flags & SEC_MERGE)
1213 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1217 rel->r_addend = _bfd_elf_rel_local_sym (output_bfd, sym,
1218 &msec, rel->r_addend);
1219 rel->r_addend -= (sec->output_section->vma
1220 + sec->output_offset
1222 rel->r_addend += msec->output_section->vma + msec->output_offset;
1224 reloc_data.reloc_addend = rel->r_addend;
1227 BFD_ASSERT (htab->sgot != NULL || !is_reloc_for_GOT (howto));
1228 if (htab->sgot != NULL)
1229 reloc_data.got_symbol_vma = htab->sgot->output_section->vma
1230 + htab->sgot->output_offset;
1232 reloc_data.should_relocate = TRUE;
1234 else /* Global symbol. */
1236 /* FIXME: We should use the RELOC_FOR_GLOBAL_SYMBOL macro
1237 (defined in elf-bfd.h) here. */
1239 /* Get the symbol's entry in the symtab. */
1240 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1242 while (h->root.type == bfd_link_hash_indirect
1243 || h->root.type == bfd_link_hash_warning)
1244 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1246 /* TODO: Need to validate what was the intention. */
1247 /* BFD_ASSERT ((h->dynindx == -1) || (h->forced_local != 0)); */
1248 reloc_data.symbol_name = h->root.root.string;
1250 /* If we have encountered a definition for this symbol. */
1251 if (h->root.type == bfd_link_hash_defined
1252 || h->root.type == bfd_link_hash_defweak)
1254 reloc_data.sym_value = h->root.u.def.value;
1255 reloc_data.sym_section = h->root.u.def.section;
1257 reloc_data.should_relocate = TRUE;
1259 if (is_reloc_for_GOT (howto) && !bfd_link_pic (info))
1261 /* TODO: Change it to use arc_do_relocation with
1262 ARC_32 reloc. Try to use ADD_RELA macro. */
1263 bfd_vma relocation =
1264 reloc_data.sym_value + reloc_data.reloc_addend
1265 + (reloc_data.sym_section->output_section != NULL ?
1266 (reloc_data.sym_section->output_offset
1267 + reloc_data.sym_section->output_section->vma)
1270 BFD_ASSERT (h->got.glist);
1271 bfd_vma got_offset = h->got.glist->offset;
1272 bfd_put_32 (output_bfd, relocation,
1273 htab->sgot->contents + got_offset);
1275 if (is_reloc_for_PLT (howto) && h->plt.offset != (bfd_vma) -1)
1277 /* TODO: This is repeated up here. */
1278 reloc_data.sym_value = h->plt.offset;
1279 reloc_data.sym_section = htab->splt;
1282 else if (h->root.type == bfd_link_hash_undefweak)
1284 /* Is weak symbol and has no definition. */
1285 if (is_reloc_for_GOT (howto))
1287 reloc_data.sym_value = h->root.u.def.value;
1288 reloc_data.sym_section = htab->sgot;
1289 reloc_data.should_relocate = TRUE;
1291 else if (is_reloc_for_PLT (howto)
1292 && h->plt.offset != (bfd_vma) -1)
1294 /* TODO: This is repeated up here. */
1295 reloc_data.sym_value = h->plt.offset;
1296 reloc_data.sym_section = htab->splt;
1297 reloc_data.should_relocate = TRUE;
1304 if (is_reloc_for_GOT (howto))
1306 reloc_data.sym_value = h->root.u.def.value;
1307 reloc_data.sym_section = htab->sgot;
1309 reloc_data.should_relocate = TRUE;
1311 else if (is_reloc_for_PLT (howto))
1313 /* Fail if it is linking for PIE and the symbol is
1315 if (bfd_link_executable (info))
1316 (*info->callbacks->undefined_symbol)
1317 (info, h->root.root.string, input_bfd, input_section,
1318 rel->r_offset, TRUE);
1319 reloc_data.sym_value = h->plt.offset;
1320 reloc_data.sym_section = htab->splt;
1322 reloc_data.should_relocate = TRUE;
1324 else if (!bfd_link_pic (info) || bfd_link_executable (info))
1325 (*info->callbacks->undefined_symbol)
1326 (info, h->root.root.string, input_bfd, input_section,
1327 rel->r_offset, TRUE);
1330 BFD_ASSERT (htab->sgot != NULL || !is_reloc_for_GOT (howto));
1331 if (htab->sgot != NULL)
1332 reloc_data.got_symbol_vma = htab->sgot->output_section->vma
1333 + htab->sgot->output_offset;
1336 if ((is_reloc_for_GOT (howto)
1337 || is_reloc_for_TLS (howto)))
1339 reloc_data.should_relocate = TRUE;
1341 struct got_entry **list
1342 = get_got_entry_list_for_symbol (output_bfd, r_symndx, h);
1344 reloc_data.got_offset_value
1345 = relocate_fix_got_relocs_for_got_info (list,
1346 tls_type_for_reloc (howto),
1357 create_got_dynrelocs_for_single_entry (
1358 got_entry_for_type (list,
1359 arc_got_entry_type_for_reloc (howto)),
1360 output_bfd, info, NULL);
1369 case R_ARC_32_PCREL:
1370 if ((bfd_link_pic (info))
1371 && ((r_type != R_ARC_PC32 && r_type != R_ARC_32_PCREL)
1374 && (!info->symbolic || !h->def_regular))))
1376 Elf_Internal_Rela outrel;
1378 bfd_boolean skip = FALSE;
1379 bfd_boolean relocate = FALSE;
1380 asection *sreloc = _bfd_elf_get_dynamic_reloc_section
1381 (input_bfd, input_section,
1384 BFD_ASSERT (sreloc != NULL);
1386 outrel.r_offset = _bfd_elf_section_offset (output_bfd,
1390 if (outrel.r_offset == (bfd_vma) -1)
1393 outrel.r_addend = rel->r_addend;
1394 outrel.r_offset += (input_section->output_section->vma
1395 + input_section->output_offset);
1397 #define IS_ARC_PCREL_TYPE(TYPE) \
1398 ( (TYPE == R_ARC_PC32) \
1399 || (TYPE == R_ARC_32_PCREL))
1403 memset (&outrel, 0, sizeof outrel);
1408 && ((IS_ARC_PCREL_TYPE (r_type))
1409 || !(bfd_link_executable (info)
1410 || SYMBOLIC_BIND (info, h))
1411 || ! h->def_regular))
1413 BFD_ASSERT (h != NULL);
1414 if ((input_section->flags & SEC_ALLOC) != 0)
1419 BFD_ASSERT (h->dynindx != -1);
1420 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
1424 /* Handle local symbols, they either do not have a
1425 global hash table entry (h == NULL), or are
1426 forced local due to a version script
1427 (h->forced_local), or the third condition is
1428 legacy, it appears to say something like, for
1429 links where we are pre-binding the symbols, or
1430 there's not an entry for this symbol in the
1431 dynamic symbol table, and it's a regular symbol
1432 not defined in a shared object, then treat the
1433 symbol as local, resolve it now. */
1435 /* outrel.r_addend = 0; */
1436 outrel.r_info = ELF32_R_INFO (0, R_ARC_RELATIVE);
1439 BFD_ASSERT (sreloc->contents != 0);
1441 loc = sreloc->contents;
1442 loc += sreloc->reloc_count * sizeof (Elf32_External_Rela);
1443 sreloc->reloc_count += 1;
1445 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
1447 if (relocate == FALSE)
1455 if (is_reloc_SDA_relative (howto)
1456 && (reloc_data.sdata_begin_symbol_vma_set == FALSE))
1459 ("Error: Linker symbol __SDATA_BEGIN__ not found");
1460 bfd_set_error (bfd_error_bad_value);
1464 DEBUG_ARC_RELOC (reloc_data);
1466 /* Make sure we have with a dynamic linker. In case of GOT and PLT
1467 the sym_section should point to .got or .plt respectively. */
1468 if ((is_reloc_for_GOT (howto) || is_reloc_for_PLT (howto))
1469 && reloc_data.sym_section == NULL)
1472 (_("GOT and PLT relocations cannot be fixed with a non dynamic linker."));
1473 bfd_set_error (bfd_error_bad_value);
1478 switch (arc_do_relocation (contents, reloc_data, info))
1481 continue; /* The reloc processing loop. */
1483 case bfd_reloc_overflow:
1484 (*info->callbacks->reloc_overflow)
1485 (info, (h ? &h->root : NULL), reloc_data.symbol_name, howto->name, (bfd_vma) 0,
1486 input_bfd, input_section, rel->r_offset);
1489 case bfd_reloc_undefined:
1490 (*info->callbacks->undefined_symbol)
1491 (info, reloc_data.symbol_name, input_bfd, input_section, rel->r_offset, TRUE);
1494 case bfd_reloc_other:
1495 /* xgettext:c-format */
1496 msg = _("%B(%A): warning: unaligned access to symbol '%s' in the small data area");
1499 case bfd_reloc_outofrange:
1500 /* xgettext:c-format */
1501 msg = _("%B(%A): internal error: out of range error");
1504 case bfd_reloc_notsupported:
1505 /* xgettext:c-format */
1506 msg = _("%B(%A): internal error: unsupported relocation error");
1509 case bfd_reloc_dangerous:
1510 /* xgettext:c-format */
1511 msg = _("%B(%A): internal error: dangerous relocation");
1515 /* xgettext:c-format */
1516 msg = _("%B(%A): internal error: unknown error");
1521 _bfd_error_handler (msg, input_bfd, input_section, reloc_data.symbol_name);
1528 #define elf_arc_hash_table(p) \
1529 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
1530 == ARC_ELF_DATA ? ((struct elf_arc_link_hash_table *) ((p)->hash)) : NULL)
1533 elf_arc_check_relocs (bfd * abfd,
1534 struct bfd_link_info * info,
1536 const Elf_Internal_Rela * relocs)
1538 Elf_Internal_Shdr * symtab_hdr;
1539 struct elf_link_hash_entry ** sym_hashes;
1540 const Elf_Internal_Rela * rel;
1541 const Elf_Internal_Rela * rel_end;
1543 asection * sreloc = NULL;
1545 if (bfd_link_relocatable (info))
1548 dynobj = (elf_hash_table (info))->dynobj;
1549 symtab_hdr = &((elf_tdata (abfd))->symtab_hdr);
1550 sym_hashes = elf_sym_hashes (abfd);
1552 rel_end = relocs + sec->reloc_count;
1553 for (rel = relocs; rel < rel_end; rel++)
1555 enum elf_arc_reloc_type r_type;
1556 reloc_howto_type *howto;
1557 unsigned long r_symndx;
1558 struct elf_link_hash_entry *h;
1560 r_type = ELF32_R_TYPE (rel->r_info);
1562 if (r_type >= (int) R_ARC_max)
1564 bfd_set_error (bfd_error_bad_value);
1567 howto = arc_elf_howto (r_type);
1570 && (is_reloc_for_GOT (howto) == TRUE
1571 || is_reloc_for_TLS (howto) == TRUE))
1573 dynobj = elf_hash_table (info)->dynobj = abfd;
1574 if (! _bfd_elf_create_got_section (abfd, info))
1578 /* Load symbol information. */
1579 r_symndx = ELF32_R_SYM (rel->r_info);
1580 if (r_symndx < symtab_hdr->sh_info) /* Is a local symbol. */
1582 else /* Global one. */
1583 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1589 /* During shared library creation, these relocs should not
1590 appear in a shared library (as memory will be read only
1591 and the dynamic linker can not resolve these. However
1592 the error should not occur for e.g. debugging or
1593 non-readonly sections. */
1594 if ((bfd_link_dll (info) && !bfd_link_pie (info))
1595 && (sec->flags & SEC_ALLOC) != 0
1596 && (sec->flags & SEC_READONLY) != 0
1597 && ((sec->flags & SEC_CODE) != 0
1598 || (sec->flags & SEC_DEBUGGING) != 0))
1602 name = h->root.root.string;
1604 /* bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL); */
1607 /* xgettext:c-format */
1609 %B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
1611 arc_elf_howto (r_type)->name,
1613 bfd_set_error (bfd_error_bad_value);
1617 /* In some cases we are not setting the 'non_got_ref'
1618 flag, even though the relocations don't require a GOT
1619 access. We should extend the testing in this area to
1620 ensure that no significant cases are being missed. */
1625 case R_ARC_32_PCREL:
1626 if ((bfd_link_pic (info))
1627 && ((r_type != R_ARC_PC32 && r_type != R_ARC_32_PCREL)
1629 && (!info->symbolic || !h->def_regular))))
1633 sreloc = _bfd_elf_make_dynamic_reloc_section (sec, dynobj,
1641 sreloc->size += sizeof (Elf32_External_Rela);
1648 if (is_reloc_for_PLT (howto) == TRUE)
1656 /* Add info to the symbol got_entry_list. */
1657 if (is_reloc_for_GOT (howto) == TRUE
1658 || is_reloc_for_TLS (howto) == TRUE)
1660 arc_fill_got_info_for_reloc (
1661 arc_got_entry_type_for_reloc (howto),
1662 get_got_entry_list_for_symbol (abfd, r_symndx, h),
1671 #define ELF_DYNAMIC_INTERPRETER "/sbin/ld-uClibc.so"
1673 static struct plt_version_t *
1674 arc_get_plt_version (struct bfd_link_info *info)
1678 for (i = 0; i < 1; i++)
1680 ARC_DEBUG ("%d: size1 = %d, size2 = %d\n", i,
1681 (int) plt_versions[i].entry_size,
1682 (int) plt_versions[i].elem_size);
1685 if (bfd_get_mach (info->output_bfd) == bfd_mach_arc_arcv2)
1687 if (bfd_link_pic (info))
1688 return &(plt_versions[ELF_ARCV2_PIC]);
1690 return &(plt_versions[ELF_ARCV2_ABS]);
1694 if (bfd_link_pic (info))
1695 return &(plt_versions[ELF_ARC_PIC]);
1697 return &(plt_versions[ELF_ARC_ABS]);
1702 add_symbol_to_plt (struct bfd_link_info *info)
1704 struct elf_link_hash_table *htab = elf_hash_table (info);
1707 struct plt_version_t *plt_data = arc_get_plt_version (info);
1709 /* If this is the first .plt entry, make room for the special first
1711 if (htab->splt->size == 0)
1712 htab->splt->size += plt_data->entry_size;
1714 ret = htab->splt->size;
1716 htab->splt->size += plt_data->elem_size;
1717 ARC_DEBUG ("PLT_SIZE = %d\n", (int) htab->splt->size);
1719 htab->sgotplt->size += 4;
1720 htab->srelplt->size += sizeof (Elf32_External_Rela);
1725 #define PLT_DO_RELOCS_FOR_ENTRY(ABFD, DS, RELOCS) \
1726 plt_do_relocs_for_symbol (ABFD, DS, RELOCS, 0, 0)
1729 plt_do_relocs_for_symbol (bfd *abfd,
1730 struct elf_link_hash_table *htab,
1731 const struct plt_reloc *reloc,
1733 bfd_vma symbol_got_offset)
1735 while (SYM_ONLY (reloc->symbol) != LAST_RELOC)
1737 bfd_vma relocation = 0;
1739 switch (SYM_ONLY (reloc->symbol))
1743 = htab->sgotplt->output_section->vma
1744 + htab->sgotplt->output_offset + symbol_got_offset;
1747 relocation += reloc->addend;
1749 if (IS_RELATIVE (reloc->symbol))
1751 bfd_vma reloc_offset = reloc->offset;
1752 reloc_offset -= (IS_INSN_32 (reloc->symbol)) ? 4 : 0;
1753 reloc_offset -= (IS_INSN_24 (reloc->symbol)) ? 2 : 0;
1755 relocation -= htab->splt->output_section->vma
1756 + htab->splt->output_offset
1757 + plt_offset + reloc_offset;
1760 /* TODO: being ME is not a property of the relocation but of the
1761 section of which is applying the relocation. */
1762 if (IS_MIDDLE_ENDIAN (reloc->symbol) && !bfd_big_endian (abfd))
1765 = ((relocation & 0xffff0000) >> 16)
1766 | ((relocation & 0xffff) << 16);
1769 switch (reloc->size)
1772 bfd_put_32 (htab->splt->output_section->owner,
1774 htab->splt->contents + plt_offset + reloc->offset);
1778 reloc = &(reloc[1]); /* Jump to next relocation. */
1783 relocate_plt_for_symbol (bfd *output_bfd,
1784 struct bfd_link_info *info,
1785 struct elf_link_hash_entry *h)
1787 struct plt_version_t *plt_data = arc_get_plt_version (info);
1788 struct elf_link_hash_table *htab = elf_hash_table (info);
1790 bfd_vma plt_index = (h->plt.offset - plt_data->entry_size)
1791 / plt_data->elem_size;
1792 bfd_vma got_offset = (plt_index + 3) * 4;
1794 ARC_DEBUG ("arc_info: PLT_OFFSET = %#lx, PLT_ENTRY_VMA = %#lx, \
1795 GOT_ENTRY_OFFSET = %#lx, GOT_ENTRY_VMA = %#lx, for symbol %s\n",
1796 (long) h->plt.offset,
1797 (long) (htab->splt->output_section->vma
1798 + htab->splt->output_offset
1801 (long) (htab->sgotplt->output_section->vma
1802 + htab->sgotplt->output_offset
1804 h->root.root.string);
1808 uint16_t *ptr = (uint16_t *) plt_data->elem;
1810 for (i = 0; i < plt_data->elem_size/2; i++)
1812 uint16_t data = ptr[i];
1813 bfd_put_16 (output_bfd,
1815 htab->splt->contents + h->plt.offset + (i*2));
1819 plt_do_relocs_for_symbol (output_bfd, htab,
1820 plt_data->elem_relocs,
1824 /* Fill in the entry in the global offset table. */
1825 bfd_put_32 (output_bfd,
1826 (bfd_vma) (htab->splt->output_section->vma
1827 + htab->splt->output_offset),
1828 htab->sgotplt->contents + got_offset);
1830 /* TODO: Fill in the entry in the .rela.plt section. */
1832 Elf_Internal_Rela rel;
1835 rel.r_offset = (htab->sgotplt->output_section->vma
1836 + htab->sgotplt->output_offset
1840 BFD_ASSERT (h->dynindx != -1);
1841 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_JMP_SLOT);
1843 loc = htab->srelplt->contents;
1844 loc += plt_index * sizeof (Elf32_External_Rela); /* relA */
1845 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
1850 relocate_plt_for_entry (bfd *abfd,
1851 struct bfd_link_info *info)
1853 struct plt_version_t *plt_data = arc_get_plt_version (info);
1854 struct elf_link_hash_table *htab = elf_hash_table (info);
1858 uint16_t *ptr = (uint16_t *) plt_data->entry;
1859 for (i = 0; i < plt_data->entry_size/2; i++)
1861 uint16_t data = ptr[i];
1864 htab->splt->contents + (i*2));
1867 PLT_DO_RELOCS_FOR_ENTRY (abfd, htab, plt_data->entry_relocs);
1870 /* Desc : Adjust a symbol defined by a dynamic object and referenced
1871 by a regular object. The current definition is in some section of
1872 the dynamic object, but we're not including those sections. We
1873 have to change the definition to something the rest of the link can
1877 elf_arc_adjust_dynamic_symbol (struct bfd_link_info *info,
1878 struct elf_link_hash_entry *h)
1881 bfd *dynobj = (elf_hash_table (info))->dynobj;
1882 struct elf_link_hash_table *htab = elf_hash_table (info);
1884 if (h->type == STT_FUNC
1885 || h->type == STT_GNU_IFUNC
1886 || h->needs_plt == 1)
1888 if (!bfd_link_pic (info) && !h->def_dynamic && !h->ref_dynamic)
1890 /* This case can occur if we saw a PLT32 reloc in an input
1891 file, but the symbol was never referred to by a dynamic
1892 object. In such a case, we don't actually need to build
1893 a procedure linkage table, and we can just do a PC32
1895 BFD_ASSERT (h->needs_plt);
1899 /* Make sure this symbol is output as a dynamic symbol. */
1900 if (h->dynindx == -1 && !h->forced_local
1901 && !bfd_elf_link_record_dynamic_symbol (info, h))
1904 if (bfd_link_pic (info)
1905 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1907 bfd_vma loc = add_symbol_to_plt (info);
1909 if (bfd_link_executable (info) && !h->def_regular)
1911 h->root.u.def.section = htab->splt;
1912 h->root.u.def.value = loc;
1914 h->plt.offset = loc;
1918 h->plt.offset = (bfd_vma) -1;
1924 /* If this is a weak symbol, and there is a real definition, the
1925 processor independent code will have arranged for us to see the
1926 real definition first, and we can just use the same value. */
1927 if (h->u.weakdef != NULL)
1929 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1930 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1931 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1932 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1936 /* This is a reference to a symbol defined by a dynamic object which
1937 is not a function. */
1939 /* If we are creating a shared library, we must presume that the
1940 only references to the symbol are via the global offset table.
1941 For such cases we need not do anything here; the relocations will
1942 be handled correctly by relocate_section. */
1943 if (!bfd_link_executable (info))
1946 /* If there are no non-GOT references, we do not need a copy
1948 if (!h->non_got_ref)
1951 /* If -z nocopyreloc was given, we won't generate them either. */
1952 if (info->nocopyreloc)
1958 /* We must allocate the symbol in our .dynbss section, which will
1959 become part of the .bss section of the executable. There will be
1960 an entry for this symbol in the .dynsym section. The dynamic
1961 object will contain position independent code, so all references
1962 from the dynamic object to this symbol will go through the global
1963 offset table. The dynamic linker will use the .dynsym entry to
1964 determine the address it must put in the global offset table, so
1965 both the dynamic object and the regular object will refer to the
1966 same memory location for the variable. */
1971 /* We must generate a R_ARC_COPY reloc to tell the dynamic linker to
1972 copy the initial value out of the dynamic object and into the
1973 runtime process image. We need to remember the offset into the
1974 .rela.bss section we are going to use. */
1975 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1977 struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);
1979 BFD_ASSERT (arc_htab->elf.srelbss != NULL);
1980 arc_htab->elf.srelbss->size += sizeof (Elf32_External_Rela);
1984 /* TODO: Move this also to arc_hash_table. */
1985 s = bfd_get_section_by_name (dynobj, ".dynbss");
1986 BFD_ASSERT (s != NULL);
1988 return _bfd_elf_adjust_dynamic_copy (info, h, s);
1991 /* Function : elf_arc_finish_dynamic_symbol
1992 Brief : Finish up dynamic symbol handling. We set the
1993 contents of various dynamic sections here.
1998 Returns : True/False as the return status. */
2001 elf_arc_finish_dynamic_symbol (bfd * output_bfd,
2002 struct bfd_link_info *info,
2003 struct elf_link_hash_entry *h,
2004 Elf_Internal_Sym * sym)
2006 if (h->plt.offset != (bfd_vma) -1)
2008 relocate_plt_for_symbol (output_bfd, info, h);
2010 if (!h->def_regular)
2012 /* Mark the symbol as undefined, rather than as defined in
2013 the .plt section. Leave the value alone. */
2014 sym->st_shndx = SHN_UNDEF;
2019 /* This function traverses list of GOT entries and
2020 create respective dynamic relocs. */
2021 /* TODO: Make function to get list and not access the list directly. */
2022 /* TODO: Move function to relocate_section create this relocs eagerly. */
2023 create_got_dynrelocs_for_got_info (&h->got.glist,
2030 struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);
2032 if (h->dynindx == -1
2033 || (h->root.type != bfd_link_hash_defined
2034 && h->root.type != bfd_link_hash_defweak)
2035 || arc_htab->elf.srelbss == NULL)
2038 bfd_vma rel_offset = (h->root.u.def.value
2039 + h->root.u.def.section->output_section->vma
2040 + h->root.u.def.section->output_offset);
2042 bfd_byte * loc = arc_htab->elf.srelbss->contents
2043 + (arc_htab->elf.srelbss->reloc_count * sizeof (Elf32_External_Rela));
2044 arc_htab->elf.srelbss->reloc_count++;
2046 Elf_Internal_Rela rel;
2048 rel.r_offset = rel_offset;
2050 BFD_ASSERT (h->dynindx != -1);
2051 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARC_COPY);
2053 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
2056 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
2057 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2058 || strcmp (h->root.root.string, "__DYNAMIC") == 0
2059 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2060 sym->st_shndx = SHN_ABS;
2065 #define GET_SYMBOL_OR_SECTION(TAG, SYMBOL, SECTION) \
2067 if (SYMBOL != NULL) \
2068 h = elf_link_hash_lookup (elf_hash_table (info), \
2069 SYMBOL, FALSE, FALSE, TRUE); \
2070 else if (SECTION != NULL) \
2071 s = bfd_get_linker_section (dynobj, SECTION); \
2074 /* Function : elf_arc_finish_dynamic_sections
2075 Brief : Finish up the dynamic sections handling.
2080 Returns : True/False as the return status. */
2083 elf_arc_finish_dynamic_sections (bfd * output_bfd,
2084 struct bfd_link_info *info)
2086 struct elf_link_hash_table *htab = elf_hash_table (info);
2087 bfd *dynobj = (elf_hash_table (info))->dynobj;
2088 asection *sdyn = bfd_get_linker_section (dynobj, ".dynamic");
2092 Elf32_External_Dyn *dyncon, *dynconend;
2094 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2096 = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
2097 for (; dyncon < dynconend; dyncon++)
2099 Elf_Internal_Dyn internal_dyn;
2100 bfd_boolean do_it = FALSE;
2102 struct elf_link_hash_entry *h = NULL;
2105 bfd_elf32_swap_dyn_in (dynobj, dyncon, &internal_dyn);
2107 switch (internal_dyn.d_tag)
2109 GET_SYMBOL_OR_SECTION (DT_INIT, info->init_function, NULL)
2110 GET_SYMBOL_OR_SECTION (DT_FINI, info->fini_function, NULL)
2111 GET_SYMBOL_OR_SECTION (DT_PLTGOT, NULL, ".plt")
2112 GET_SYMBOL_OR_SECTION (DT_JMPREL, NULL, ".rela.plt")
2113 GET_SYMBOL_OR_SECTION (DT_PLTRELSZ, NULL, ".rela.plt")
2114 GET_SYMBOL_OR_SECTION (DT_VERSYM, NULL, ".gnu.version")
2115 GET_SYMBOL_OR_SECTION (DT_VERDEF, NULL, ".gnu.version_d")
2116 GET_SYMBOL_OR_SECTION (DT_VERNEED, NULL, ".gnu.version_r")
2121 /* In case the dynamic symbols should be updated with a symbol. */
2123 && (h->root.type == bfd_link_hash_defined
2124 || h->root.type == bfd_link_hash_defweak))
2128 internal_dyn.d_un.d_val = h->root.u.def.value;
2129 asec_ptr = h->root.u.def.section;
2130 if (asec_ptr->output_section != NULL)
2132 internal_dyn.d_un.d_val +=
2133 (asec_ptr->output_section->vma
2134 + asec_ptr->output_offset);
2138 /* The symbol is imported from another shared
2139 library and does not apply to this one. */
2140 internal_dyn.d_un.d_val = 0;
2144 else if (s != NULL) /* With a section information. */
2146 switch (internal_dyn.d_tag)
2153 internal_dyn.d_un.d_ptr = (s->output_section->vma
2154 + s->output_offset);
2159 internal_dyn.d_un.d_val = s->size;
2169 bfd_elf32_swap_dyn_out (output_bfd, &internal_dyn, dyncon);
2172 if (htab->splt->size > 0)
2174 relocate_plt_for_entry (output_bfd, info);
2177 /* TODO: Validate this. */
2178 if (htab->srelplt->output_section != bfd_abs_section_ptr)
2179 elf_section_data (htab->srelplt->output_section)
2180 ->this_hdr.sh_entsize = 12;
2183 /* Fill in the first three entries in the global offset table. */
2186 struct elf_link_hash_entry *h;
2187 h = elf_link_hash_lookup (elf_hash_table (info), "_GLOBAL_OFFSET_TABLE_",
2188 FALSE, FALSE, TRUE);
2190 if (h != NULL && h->root.type != bfd_link_hash_undefined
2191 && h->root.u.def.section != NULL)
2193 asection *sec = h->root.u.def.section;
2196 bfd_put_32 (output_bfd, (bfd_vma) 0,
2199 bfd_put_32 (output_bfd,
2200 sdyn->output_section->vma + sdyn->output_offset,
2202 bfd_put_32 (output_bfd, (bfd_vma) 0, sec->contents + 4);
2203 bfd_put_32 (output_bfd, (bfd_vma) 0, sec->contents + 8);
2210 #define ADD_DYNAMIC_SYMBOL(NAME, TAG) \
2211 h = elf_link_hash_lookup (elf_hash_table (info), \
2212 NAME, FALSE, FALSE, FALSE); \
2213 if ((h != NULL && (h->ref_regular || h->def_regular))) \
2214 if (! _bfd_elf_add_dynamic_entry (info, TAG, 0)) \
2217 /* Set the sizes of the dynamic sections. */
2219 elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
2220 struct bfd_link_info *info)
2224 bfd_boolean relocs_exist = FALSE;
2225 bfd_boolean reltext_exist = FALSE;
2226 struct elf_link_hash_table *htab = elf_hash_table (info);
2228 dynobj = htab->dynobj;
2229 BFD_ASSERT (dynobj != NULL);
2231 if (htab->dynamic_sections_created)
2233 struct elf_link_hash_entry *h;
2235 /* Set the contents of the .interp section to the
2237 if (bfd_link_executable (info) && !info->nointerp)
2239 s = bfd_get_section_by_name (dynobj, ".interp");
2240 BFD_ASSERT (s != NULL);
2241 s->size = sizeof (ELF_DYNAMIC_INTERPRETER);
2242 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2245 /* Add some entries to the .dynamic section. We fill in some of
2246 the values later, in elf_bfd_final_link, but we must add the
2247 entries now so that we know the final size of the .dynamic
2248 section. Checking if the .init section is present. We also
2249 create DT_INIT and DT_FINI entries if the init_str has been
2250 changed by the user. */
2251 ADD_DYNAMIC_SYMBOL (info->init_function, DT_INIT);
2252 ADD_DYNAMIC_SYMBOL (info->fini_function, DT_FINI);
2256 /* We may have created entries in the .rela.got section.
2257 However, if we are not creating the dynamic sections, we will
2258 not actually use these entries. Reset the size of .rela.got,
2259 which will cause it to get stripped from the output file
2261 if (htab->srelgot != NULL)
2262 htab->srelgot->size = 0;
2265 for (s = dynobj->sections; s != NULL; s = s->next)
2267 if ((s->flags & SEC_LINKER_CREATED) == 0)
2272 || s == htab->sgotplt
2273 || s == htab->sdynbss)
2275 /* Strip this section if we don't need it. */
2277 else if (strncmp (s->name, ".rela", 5) == 0)
2279 if (s->size != 0 && s != htab->srelplt)
2283 const char *name = s->name + 5;
2285 for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
2286 if (bfd_get_flavour (ibfd) == bfd_target_elf_flavour)
2288 asection *target = bfd_get_section_by_name (ibfd, name);
2290 && elf_section_data (target)->sreloc == s
2291 && ((target->output_section->flags
2292 & (SEC_READONLY | SEC_ALLOC))
2293 == (SEC_READONLY | SEC_ALLOC)))
2295 reltext_exist = TRUE;
2300 relocs_exist = TRUE;
2303 /* We use the reloc_count field as a counter if we need to
2304 copy relocs into the output file. */
2309 /* It's not one of our sections, so don't allocate space. */
2315 s->flags |= SEC_EXCLUDE;
2319 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2322 /* Allocate memory for the section contents. */
2323 s->contents = bfd_zalloc (dynobj, s->size);
2324 if (s->contents == NULL)
2328 if (htab->dynamic_sections_created)
2330 /* TODO: Check if this is needed. */
2331 if (!bfd_link_pic (info))
2332 if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
2335 if (htab->splt && (htab->splt->flags & SEC_EXCLUDE) == 0)
2336 if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
2337 || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
2338 || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
2339 || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
2343 if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
2344 || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
2345 || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
2346 sizeof (Elf32_External_Rela)))
2350 if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
2358 /* Classify dynamic relocs such that -z combreloc can reorder and combine
2360 static enum elf_reloc_type_class
2361 elf32_arc_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
2362 const asection *rel_sec ATTRIBUTE_UNUSED,
2363 const Elf_Internal_Rela *rela)
2365 switch ((int) ELF32_R_TYPE (rela->r_info))
2367 case R_ARC_RELATIVE:
2368 return reloc_class_relative;
2369 case R_ARC_JMP_SLOT:
2370 return reloc_class_plt;
2372 return reloc_class_copy;
2373 /* TODO: Needed in future to support ifunc. */
2375 case R_ARC_IRELATIVE:
2376 return reloc_class_ifunc;
2379 return reloc_class_normal;
2383 const struct elf_size_info arc_elf32_size_info =
2385 sizeof (Elf32_External_Ehdr),
2386 sizeof (Elf32_External_Phdr),
2387 sizeof (Elf32_External_Shdr),
2388 sizeof (Elf32_External_Rel),
2389 sizeof (Elf32_External_Rela),
2390 sizeof (Elf32_External_Sym),
2391 sizeof (Elf32_External_Dyn),
2392 sizeof (Elf_External_Note),
2396 ELFCLASS32, EV_CURRENT,
2397 bfd_elf32_write_out_phdrs,
2398 bfd_elf32_write_shdrs_and_ehdr,
2399 bfd_elf32_checksum_contents,
2400 bfd_elf32_write_relocs,
2401 bfd_elf32_swap_symbol_in,
2402 bfd_elf32_swap_symbol_out,
2403 bfd_elf32_slurp_reloc_table,
2404 bfd_elf32_slurp_symbol_table,
2405 bfd_elf32_swap_dyn_in,
2406 bfd_elf32_swap_dyn_out,
2407 bfd_elf32_swap_reloc_in,
2408 bfd_elf32_swap_reloc_out,
2409 bfd_elf32_swap_reloca_in,
2410 bfd_elf32_swap_reloca_out
2413 #define elf_backend_size_info arc_elf32_size_info
2415 /* Hook called by the linker routine which adds symbols from an object
2419 elf_arc_add_symbol_hook (bfd * abfd,
2420 struct bfd_link_info * info,
2421 Elf_Internal_Sym * sym,
2422 const char ** namep ATTRIBUTE_UNUSED,
2423 flagword * flagsp ATTRIBUTE_UNUSED,
2424 asection ** secp ATTRIBUTE_UNUSED,
2425 bfd_vma * valp ATTRIBUTE_UNUSED)
2427 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
2428 && (abfd->flags & DYNAMIC) == 0
2429 && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
2430 elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
2435 /* GDB expects general purpose registers to be in section .reg. However Linux
2436 kernel doesn't create this section and instead writes registers to NOTE
2437 section. It is up to the binutils to create a pseudo-section .reg from the
2438 contents of NOTE. Also BFD will read pid and signal number from NOTE. This
2439 function relies on offsets inside elf_prstatus structure in Linux to be
2443 elf32_arc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2448 switch (note->descsz)
2453 case 236: /* sizeof (struct elf_prstatus) on Linux/arc. */
2455 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2457 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
2460 size = (40 * 4); /* There are 40 registers in user_regs_struct. */
2463 /* Make a ".reg/999" section. */
2464 return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
2465 note->descpos + offset);
2468 #define TARGET_LITTLE_SYM arc_elf32_le_vec
2469 #define TARGET_LITTLE_NAME "elf32-littlearc"
2470 #define TARGET_BIG_SYM arc_elf32_be_vec
2471 #define TARGET_BIG_NAME "elf32-bigarc"
2472 #define ELF_ARCH bfd_arch_arc
2473 #define ELF_TARGET_ID ARC_ELF_DATA
2474 #define ELF_MACHINE_CODE EM_ARC_COMPACT
2475 #define ELF_MACHINE_ALT1 EM_ARC_COMPACT2
2476 #define ELF_MAXPAGESIZE 0x2000
2478 #define bfd_elf32_bfd_link_hash_table_create arc_elf_link_hash_table_create
2480 #define bfd_elf32_bfd_merge_private_bfd_data arc_elf_merge_private_bfd_data
2481 #define bfd_elf32_bfd_reloc_type_lookup arc_elf32_bfd_reloc_type_lookup
2482 #define bfd_elf32_bfd_set_private_flags arc_elf_set_private_flags
2483 #define bfd_elf32_bfd_print_private_bfd_data arc_elf_print_private_bfd_data
2484 #define bfd_elf32_bfd_copy_private_bfd_data arc_elf_copy_private_bfd_data
2486 #define elf_info_to_howto_rel arc_info_to_howto_rel
2487 #define elf_backend_object_p arc_elf_object_p
2488 #define elf_backend_final_write_processing arc_elf_final_write_processing
2490 #define elf_backend_relocate_section elf_arc_relocate_section
2491 #define elf_backend_check_relocs elf_arc_check_relocs
2492 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2494 #define elf_backend_reloc_type_class elf32_arc_reloc_type_class
2496 #define elf_backend_adjust_dynamic_symbol elf_arc_adjust_dynamic_symbol
2497 #define elf_backend_finish_dynamic_symbol elf_arc_finish_dynamic_symbol
2499 #define elf_backend_finish_dynamic_sections elf_arc_finish_dynamic_sections
2500 #define elf_backend_size_dynamic_sections elf_arc_size_dynamic_sections
2501 #define elf_backend_add_symbol_hook elf_arc_add_symbol_hook
2503 #define elf_backend_can_gc_sections 1
2504 #define elf_backend_want_got_plt 1
2505 #define elf_backend_plt_readonly 1
2506 #define elf_backend_rela_plts_and_copies_p 1
2507 #define elf_backend_want_plt_sym 0
2508 #define elf_backend_got_header_size 12
2509 #define elf_backend_dtrel_excludes_plt 1
2511 #define elf_backend_may_use_rel_p 0
2512 #define elf_backend_may_use_rela_p 1
2513 #define elf_backend_default_use_rela_p 1
2515 #define elf_backend_grok_prstatus elf32_arc_grok_prstatus
2517 #define elf_backend_default_execstack 0
2519 #include "elf32-target.h"