Fallout from recent bfd_reloc_outofrange changes
[deliverable/binutils-gdb.git] / bfd / elf32-arc.c
CommitLineData
252b5132 1/* ARC-specific support for 32-bit ELF
b90efa5b 2 Copyright (C) 1994-2015 Free Software Foundation, Inc.
252b5132
RH
3 Contributed by Doug Evans (dje@cygnus.com).
4
0d2bcfaf 5 This file is part of BFD, the Binary File Descriptor library.
252b5132 6
0d2bcfaf
NC
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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
0d2bcfaf 10 (at your option) any later version.
252b5132 11
0d2bcfaf
NC
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.
252b5132 16
0d2bcfaf
NC
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
47b0e7ad
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
252b5132 21
252b5132 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
252b5132
RH
24#include "libbfd.h"
25#include "elf-bfd.h"
26#include "elf/arc.h"
ea04a8f6 27#include "libiberty.h"
252b5132 28
252b5132
RH
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). */
0d2bcfaf 31
acf8aed4 32#define USE_REL 1
252b5132 33
47b0e7ad
NC
34static bfd_reloc_status_type
35arc_elf_b22_pcrel (bfd * abfd,
36 arelent * reloc_entry,
37 asymbol * symbol,
38 void * data,
39 asection * input_section,
40 bfd * output_bfd,
41 char ** error_message)
42{
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;
50
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);
54}
55
252b5132
RH
56static reloc_howto_type elf_arc_howto_table[] =
57{
58 /* This reloc does nothing. */
47b0e7ad
NC
59 HOWTO (R_ARC_NONE, /* Type. */
60 0, /* Rightshift. */
6346d5ca
AM
61 3, /* Size (0 = byte, 1 = short, 2 = long). */
62 0, /* Bitsize. */
47b0e7ad
NC
63 FALSE, /* PC_relative. */
64 0, /* Bitpos. */
65 complain_overflow_bitfield, /* Complain_on_overflow. */
66 bfd_elf_generic_reloc, /* Special_function. */
67 "R_ARC_NONE", /* Name. */
68 TRUE, /* Partial_inplace. */
69 0, /* Src_mask. */
70 0, /* Dst_mask. */
71 FALSE), /* PCrel_offset. */
252b5132
RH
72
73 /* A standard 32 bit relocation. */
47b0e7ad
NC
74 HOWTO (R_ARC_32, /* Type. */
75 0, /* Rightshift. */
76 2, /* Size (0 = byte, 1 = short, 2 = long). */
77 32, /* Bitsize. */
78 FALSE, /* PC_relative. */
79 0, /* Bitpos. */
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. */
252b5132
RH
87
88 /* A 26 bit absolute branch, right shifted by 2. */
47b0e7ad
NC
89 HOWTO (R_ARC_B26, /* Type. */
90 2, /* Rightshift. */
91 2, /* Size (0 = byte, 1 = short, 2 = long). */
92 26, /* Bitsize. */
93 FALSE, /* PC_relative. */
94 0, /* Bitpos. */
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. */
252b5132
RH
102
103 /* A relative 22 bit branch; bits 21-2 are stored in bits 26-7. */
47b0e7ad
NC
104 HOWTO (R_ARC_B22_PCREL, /* Type. */
105 2, /* Rightshift. */
106 2, /* Size (0 = byte, 1 = short, 2 = long). */
107 22, /* Bitsize. */
108 TRUE, /* PC_relative. */
109 7, /* Bitpos. */
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. */
252b5132
RH
117};
118
119/* Map BFD reloc types to ARC ELF reloc types. */
120
121struct arc_reloc_map
122{
123 bfd_reloc_code_real_type bfd_reloc_val;
124 unsigned char elf_reloc_val;
125};
126
127static const struct arc_reloc_map arc_reloc_map[] =
128{
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 },
134};
135
136static reloc_howto_type *
47b0e7ad
NC
137bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
138 bfd_reloc_code_real_type code)
252b5132
RH
139{
140 unsigned int i;
141
ea04a8f6
NC
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;
145
252b5132
RH
146 return NULL;
147}
148
157090f7
AM
149static reloc_howto_type *
150bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
151 const char *r_name)
152{
153 unsigned int i;
154
155 for (i = 0;
156 i < sizeof (elf_arc_howto_table) / sizeof (elf_arc_howto_table[0]);
157 i++)
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];
161
162 return NULL;
163}
164
252b5132
RH
165/* Set the howto pointer for an ARC ELF reloc. */
166
167static void
47b0e7ad
NC
168arc_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
169 arelent *cache_ptr,
170 Elf_Internal_Rela *dst)
252b5132
RH
171{
172 unsigned int r_type;
173
174 r_type = ELF32_R_TYPE (dst->r_info);
5860e3f8
NC
175 if (r_type >= (unsigned int) R_ARC_max)
176 {
177 _bfd_error_handler (_("%A: invalid ARC reloc number: %d"), abfd, r_type);
178 r_type = 0;
179 }
252b5132
RH
180 cache_ptr->howto = &elf_arc_howto_table[r_type];
181}
182
183/* Set the right machine number for an ARC ELF file. */
184
b34976b6 185static bfd_boolean
47b0e7ad 186arc_elf_object_p (bfd *abfd)
252b5132 187{
dc810e39 188 unsigned int mach = bfd_mach_arc_6;
252b5132 189
0d2bcfaf 190 if (elf_elfheader(abfd)->e_machine == EM_ARC)
252b5132 191 {
0d2bcfaf
NC
192 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH;
193
194 switch (arch)
195 {
0d2bcfaf
NC
196 case E_ARC_MACH_ARC5:
197 mach = bfd_mach_arc_5;
198 break;
bcee8eb8 199 default:
0d2bcfaf
NC
200 case E_ARC_MACH_ARC6:
201 mach = bfd_mach_arc_6;
202 break;
203 case E_ARC_MACH_ARC7:
204 mach = bfd_mach_arc_7;
205 break;
206 case E_ARC_MACH_ARC8:
207 mach = bfd_mach_arc_8;
208 break;
209 }
252b5132 210 }
0d2bcfaf 211 return bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
252b5132
RH
212}
213
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. */
216
217static void
47b0e7ad
NC
218arc_elf_final_write_processing (bfd *abfd,
219 bfd_boolean linker ATTRIBUTE_UNUSED)
252b5132 220{
252b5132
RH
221 unsigned long val;
222
0d2bcfaf 223 switch (bfd_get_mach (abfd))
252b5132 224 {
0d2bcfaf
NC
225 case bfd_mach_arc_5:
226 val = E_ARC_MACH_ARC5;
227 break;
bcee8eb8 228 default:
0d2bcfaf
NC
229 case bfd_mach_arc_6:
230 val = E_ARC_MACH_ARC6;
231 break;
232 case bfd_mach_arc_7:
233 val = E_ARC_MACH_ARC7;
234 break;
235 case bfd_mach_arc_8:
236 val = E_ARC_MACH_ARC8;
237 break;
252b5132 238 }
252b5132
RH
239 elf_elfheader (abfd)->e_flags &=~ EF_ARC_MACH;
240 elf_elfheader (abfd)->e_flags |= val;
241}
242
6d00b590 243#define TARGET_LITTLE_SYM arc_elf32_le_vec
47b0e7ad 244#define TARGET_LITTLE_NAME "elf32-littlearc"
6d00b590 245#define TARGET_BIG_SYM arc_elf32_be_vec
47b0e7ad
NC
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
250
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
252b5132
RH
255
256#include "elf32-target.h"
This page took 0.717452 seconds and 4 git commands to generate.