1 /* ARC-specific support for 32-bit ELF
2 Copyright (C) 1994-2015 Free Software Foundation, Inc.
3 Contributed by Doug Evans (dje@cygnus.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"
29 /* Try to minimize the amount of space occupied by relocation tables
30 on the ROM (not that the ROM won't be swamped by other ELF overhead). */
34 static bfd_reloc_status_type
35 arc_elf_b22_pcrel (bfd * abfd,
36 arelent * reloc_entry,
39 asection * input_section,
41 char ** error_message)
43 /* If linking, back up the final symbol address by the address of the
44 reloc. This cannot be accomplished by setting the pcrel_offset
45 field to TRUE, as bfd_install_relocation will detect this and refuse
46 to install the offset in the first place, but bfd_perform_relocation
47 will still insist on removing it. */
48 if (output_bfd == NULL)
49 reloc_entry->addend -= reloc_entry->address;
51 /* Fall through to the default elf reloc handler. */
52 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
53 input_section, output_bfd, error_message);
56 static reloc_howto_type elf_arc_howto_table[] =
58 /* This reloc does nothing. */
59 HOWTO (R_ARC_NONE, /* Type. */
61 3, /* Size (0 = byte, 1 = short, 2 = long). */
63 FALSE, /* PC_relative. */
65 complain_overflow_bitfield, /* Complain_on_overflow. */
66 bfd_elf_generic_reloc, /* Special_function. */
67 "R_ARC_NONE", /* Name. */
68 TRUE, /* Partial_inplace. */
71 FALSE), /* PCrel_offset. */
73 /* A standard 32 bit relocation. */
74 HOWTO (R_ARC_32, /* Type. */
76 2, /* Size (0 = byte, 1 = short, 2 = long). */
78 FALSE, /* PC_relative. */
80 complain_overflow_bitfield, /* Complain_on_overflow. */
81 bfd_elf_generic_reloc, /* Special_function. */
82 "R_ARC_32", /* Name. */
83 TRUE, /* Partial_inplace. */
84 0xffffffff, /* Src_mask. */
85 0xffffffff, /* Dst_mask. */
86 FALSE), /* PCrel_offset. */
88 /* A 26 bit absolute branch, right shifted by 2. */
89 HOWTO (R_ARC_B26, /* Type. */
91 2, /* Size (0 = byte, 1 = short, 2 = long). */
93 FALSE, /* PC_relative. */
95 complain_overflow_bitfield, /* Complain_on_overflow. */
96 bfd_elf_generic_reloc, /* Special_function. */
97 "R_ARC_B26", /* Name. */
98 TRUE, /* Partial_inplace. */
99 0x00ffffff, /* Src_mask. */
100 0x00ffffff, /* Dst_mask. */
101 FALSE), /* PCrel_offset. */
103 /* A relative 22 bit branch; bits 21-2 are stored in bits 26-7. */
104 HOWTO (R_ARC_B22_PCREL, /* Type. */
106 2, /* Size (0 = byte, 1 = short, 2 = long). */
108 TRUE, /* PC_relative. */
110 complain_overflow_signed, /* Complain_on_overflow. */
111 arc_elf_b22_pcrel, /* Special_function. */
112 "R_ARC_B22_PCREL", /* Name. */
113 TRUE, /* Partial_inplace. */
114 0x07ffff80, /* Src_mask. */
115 0x07ffff80, /* Dst_mask. */
116 FALSE), /* PCrel_offset. */
119 /* Map BFD reloc types to ARC ELF reloc types. */
123 bfd_reloc_code_real_type bfd_reloc_val;
124 unsigned char elf_reloc_val;
127 static const struct arc_reloc_map arc_reloc_map[] =
129 { BFD_RELOC_NONE, R_ARC_NONE, },
130 { BFD_RELOC_32, R_ARC_32 },
131 { BFD_RELOC_CTOR, R_ARC_32 },
132 { BFD_RELOC_ARC_B26, R_ARC_B26 },
133 { BFD_RELOC_ARC_B22_PCREL, R_ARC_B22_PCREL },
136 static reloc_howto_type *
137 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
138 bfd_reloc_code_real_type code)
142 for (i = ARRAY_SIZE (arc_reloc_map); i--;)
143 if (arc_reloc_map[i].bfd_reloc_val == code)
144 return elf_arc_howto_table + arc_reloc_map[i].elf_reloc_val;
149 static reloc_howto_type *
150 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
156 i < sizeof (elf_arc_howto_table) / sizeof (elf_arc_howto_table[0]);
158 if (elf_arc_howto_table[i].name != NULL
159 && strcasecmp (elf_arc_howto_table[i].name, r_name) == 0)
160 return &elf_arc_howto_table[i];
165 /* Set the howto pointer for an ARC ELF reloc. */
168 arc_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
170 Elf_Internal_Rela *dst)
174 r_type = ELF32_R_TYPE (dst->r_info);
175 if (r_type >= (unsigned int) R_ARC_max)
177 _bfd_error_handler (_("%B: invalid ARC reloc number: %d"), abfd, r_type);
180 cache_ptr->howto = &elf_arc_howto_table[r_type];
183 /* Set the right machine number for an ARC ELF file. */
186 arc_elf_object_p (bfd *abfd)
188 unsigned int mach = bfd_mach_arc_6;
190 if (elf_elfheader(abfd)->e_machine == EM_ARC)
192 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH;
196 case E_ARC_MACH_ARC5:
197 mach = bfd_mach_arc_5;
200 case E_ARC_MACH_ARC6:
201 mach = bfd_mach_arc_6;
203 case E_ARC_MACH_ARC7:
204 mach = bfd_mach_arc_7;
206 case E_ARC_MACH_ARC8:
207 mach = bfd_mach_arc_8;
211 return bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
214 /* The final processing done just before writing out an ARC ELF object file.
215 This gets the ARC architecture right based on the machine number. */
218 arc_elf_final_write_processing (bfd *abfd,
219 bfd_boolean linker ATTRIBUTE_UNUSED)
223 switch (bfd_get_mach (abfd))
226 val = E_ARC_MACH_ARC5;
230 val = E_ARC_MACH_ARC6;
233 val = E_ARC_MACH_ARC7;
236 val = E_ARC_MACH_ARC8;
239 elf_elfheader (abfd)->e_flags &=~ EF_ARC_MACH;
240 elf_elfheader (abfd)->e_flags |= val;
243 #define TARGET_LITTLE_SYM arc_elf32_le_vec
244 #define TARGET_LITTLE_NAME "elf32-littlearc"
245 #define TARGET_BIG_SYM arc_elf32_be_vec
246 #define TARGET_BIG_NAME "elf32-bigarc"
247 #define ELF_ARCH bfd_arch_arc
248 #define ELF_MACHINE_CODE EM_ARC
249 #define ELF_MAXPAGESIZE 0x1000
251 #define elf_info_to_howto 0
252 #define elf_info_to_howto_rel arc_info_to_howto_rel
253 #define elf_backend_object_p arc_elf_object_p
254 #define elf_backend_final_write_processing arc_elf_final_write_processing
256 #include "elf32-target.h"