Fix compile time warnings building the binutils with gcc 7.1.1.
[deliverable/binutils-gdb.git] / bfd / mach-o-arm.c
CommitLineData
f075eb5e 1/* ARM Mach-O support for BFD.
2571583a 2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
f075eb5e
TG
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21#include "sysdep.h"
22#include "mach-o.h"
23#include "bfd.h"
24#include "libbfd.h"
25#include "libiberty.h"
26#include "mach-o/arm.h"
27
28#define bfd_mach_o_object_p bfd_mach_o_arm_object_p
29#define bfd_mach_o_core_p bfd_mach_o_arm_core_p
30#define bfd_mach_o_mkobject bfd_mach_o_arm_mkobject
31
32#define bfd_mach_o_canonicalize_one_reloc bfd_mach_o_arm_canonicalize_one_reloc
33#define bfd_mach_o_swap_reloc_out NULL
34#define bfd_mach_o_bfd_reloc_type_lookup bfd_mach_o_arm_bfd_reloc_type_lookup
35#define bfd_mach_o_bfd_reloc_name_lookup bfd_mach_o_arm_bfd_reloc_name_lookup
36
37#define bfd_mach_o_print_thread NULL
38#define bfd_mach_o_tgt_seg_table NULL
39#define bfd_mach_o_section_type_valid_for_tgt NULL
40
41static const bfd_target *
42bfd_mach_o_arm_object_p (bfd *abfd)
43{
44 return bfd_mach_o_header_p (abfd, 0, 0, BFD_MACH_O_CPU_TYPE_ARM);
45}
46
47static const bfd_target *
48bfd_mach_o_arm_core_p (bfd *abfd)
49{
50 return bfd_mach_o_header_p (abfd, 0,
51 BFD_MACH_O_MH_CORE, BFD_MACH_O_CPU_TYPE_ARM);
52}
53
54static bfd_boolean
55bfd_mach_o_arm_mkobject (bfd *abfd)
56{
57 bfd_mach_o_data_struct *mdata;
58
59 if (!bfd_mach_o_mkobject_init (abfd))
60 return FALSE;
61
62 mdata = bfd_mach_o_get_data (abfd);
63 mdata->header.magic = BFD_MACH_O_MH_MAGIC;
64 mdata->header.cputype = BFD_MACH_O_CPU_TYPE_ARM;
65 mdata->header.cpusubtype = BFD_MACH_O_CPU_SUBTYPE_ARM_ALL;
66 mdata->header.byteorder = BFD_ENDIAN_LITTLE;
67 mdata->header.version = 1;
68
69 return TRUE;
70}
71
72static reloc_howto_type arm_howto_table[]=
73{
74 /* 0 */
75 HOWTO (BFD_RELOC_32, 0, 2, 32, FALSE, 0,
76 complain_overflow_bitfield,
77 NULL, "32",
78 FALSE, 0xffffffff, 0xffffffff, FALSE),
79 HOWTO (BFD_RELOC_16, 0, 1, 16, FALSE, 0,
80 complain_overflow_bitfield,
81 NULL, "16",
82 FALSE, 0xffff, 0xffff, FALSE),
83 HOWTO (BFD_RELOC_8, 0, 0, 8, FALSE, 0,
84 complain_overflow_bitfield,
85 NULL, "8",
86 FALSE, 0xff, 0xff, FALSE),
87 HOWTO (BFD_RELOC_32_PCREL, 0, 2, 32, TRUE, 0,
88 complain_overflow_bitfield,
89 NULL, "DISP32",
90 FALSE, 0xffffffff, 0xffffffff, TRUE),
91 /* 4 */
92 HOWTO (BFD_RELOC_16_PCREL, 0, 1, 16, TRUE, 0,
93 complain_overflow_bitfield,
94 NULL, "DISP16",
95 FALSE, 0xffff, 0xffff, TRUE),
96 HOWTO (BFD_RELOC_MACH_O_SECTDIFF, 0, 2, 32, FALSE, 0,
97 complain_overflow_bitfield,
98 NULL, "SECTDIFF_32",
99 FALSE, 0xffffffff, 0xffffffff, FALSE),
100 HOWTO (BFD_RELOC_MACH_O_LOCAL_SECTDIFF, 0, 2, 32, FALSE, 0,
101 complain_overflow_bitfield,
102 NULL, "LSECTDIFF_32",
103 FALSE, 0xffffffff, 0xffffffff, FALSE),
104 HOWTO (BFD_RELOC_MACH_O_PAIR, 0, 2, 32, FALSE, 0,
105 complain_overflow_bitfield,
106 NULL, "PAIR_32",
107 FALSE, 0xffffffff, 0xffffffff, FALSE),
108 /* 8 */
109 HOWTO (BFD_RELOC_MACH_O_SECTDIFF, 0, 1, 16, FALSE, 0,
110 complain_overflow_bitfield,
111 NULL, "SECTDIFF_16",
112 FALSE, 0xffff, 0xffff, FALSE),
113 HOWTO (BFD_RELOC_MACH_O_LOCAL_SECTDIFF, 0, 1, 16, FALSE, 0,
114 complain_overflow_bitfield,
115 NULL, "LSECTDIFF_16",
116 FALSE, 0xffff, 0xffff, FALSE),
117 HOWTO (BFD_RELOC_MACH_O_PAIR, 0, 1, 16, FALSE, 0,
118 complain_overflow_bitfield,
119 NULL, "PAIR_16",
120 FALSE, 0xffff, 0xffff, FALSE),
121 HOWTO (BFD_RELOC_ARM_PCREL_CALL, 2, 2, 24, TRUE, 0,
122 complain_overflow_signed,
123 NULL, "BR24",
124 FALSE, 0x00ffffff, 0x00ffffff, TRUE),
125 /* 12 */
126 HOWTO (BFD_RELOC_ARM_MOVW, 0, 2, 16, FALSE, 0,
127 complain_overflow_dont,
128 NULL, "MOVW",
129 FALSE, 0x000f0fff, 0x000f0fff, FALSE),
130 HOWTO (BFD_RELOC_MACH_O_PAIR, 0, 2, 16, FALSE, 0,
131 complain_overflow_bitfield,
132 NULL, "PAIR_W",
133 FALSE, 0x000f0fff, 0x000f0fff, FALSE),
134 HOWTO (BFD_RELOC_ARM_MOVT, 0, 2, 16, FALSE, 0,
135 complain_overflow_bitfield,
136 NULL, "MOVT",
137 FALSE, 0x000f0fff, 0x000f0fff, FALSE),
138 HOWTO (BFD_RELOC_MACH_O_PAIR, 0, 2, 16, FALSE, 0,
139 complain_overflow_bitfield,
140 NULL, "PAIR_T",
141 FALSE, 0x000f0fff, 0x000f0fff, FALSE),
142 /* 16 */
143 HOWTO (BFD_RELOC_THUMB_PCREL_BLX, 2, 2, 24, TRUE, 0,
144 complain_overflow_signed,
145 NULL, "TBR22",
146 FALSE, 0x07ff2fff, 0x07ff2fff, TRUE)
147};
148
149static bfd_boolean
150bfd_mach_o_arm_canonicalize_one_reloc (bfd *abfd,
151 struct mach_o_reloc_info_external *raw,
152 arelent *res, asymbol **syms)
0bae9e9e 153{
f075eb5e
TG
154 bfd_mach_o_reloc_info reloc;
155
156 if (!bfd_mach_o_pre_canonicalize_one_reloc (abfd, raw, &reloc, res, syms))
157 return FALSE;
158
159 if (reloc.r_scattered)
160 {
161 switch (reloc.r_type)
162 {
163 case BFD_MACH_O_ARM_RELOC_PAIR:
164 if (reloc.r_length == 2)
165 {
166 res->howto = &arm_howto_table[7];
167 res->address = res[-1].address;
168 return TRUE;
169 }
170 else if (reloc.r_length == 1)
171 {
172 res->howto = &arm_howto_table[10];
173 res->address = res[-1].address;
174 return TRUE;
175 }
176 return FALSE;
0bae9e9e 177
f075eb5e
TG
178 case BFD_MACH_O_ARM_RELOC_SECTDIFF:
179 if (reloc.r_length == 2)
180 {
181 res->howto = &arm_howto_table[5];
182 return TRUE;
183 }
184 else if (reloc.r_length == 1)
185 {
186 res->howto = &arm_howto_table[8];
187 return TRUE;
188 }
189 return FALSE;
0bae9e9e 190
f075eb5e
TG
191 case BFD_MACH_O_ARM_RELOC_LOCAL_SECTDIFF:
192 if (reloc.r_length == 2)
193 {
194 res->howto = &arm_howto_table[6];
195 return TRUE;
196 }
197 else if (reloc.r_length == 1)
198 {
199 res->howto = &arm_howto_table[9];
200 return TRUE;
201 }
202 return FALSE;
0bae9e9e 203
f075eb5e
TG
204 case BFD_MACH_O_ARM_RELOC_HALF_SECTDIFF:
205 switch (reloc.r_length)
206 {
207 case 2: /* :lower16: for movw arm. */
208 res->howto = &arm_howto_table[12];
209 return TRUE;
210 case 3: /* :upper16: for movt arm. */
211 res->howto = &arm_howto_table[14];
212 return TRUE;
213 }
214 return FALSE;
0bae9e9e 215
f075eb5e 216 default:
0bae9e9e 217 break;
f075eb5e
TG
218 }
219 }
220 else
221 {
222 switch (reloc.r_type)
223 {
224 case BFD_MACH_O_ARM_RELOC_VANILLA:
225 switch ((reloc.r_length << 1) | reloc.r_pcrel)
226 {
227 case 0: /* len = 0, pcrel = 0 */
228 res->howto = &arm_howto_table[2];
229 return TRUE;
230 case 2: /* len = 1, pcrel = 0 */
231 res->howto = &arm_howto_table[1];
232 return TRUE;
233 case 3: /* len = 1, pcrel = 1 */
234 res->howto = &arm_howto_table[4];
235 return TRUE;
236 case 4: /* len = 2, pcrel = 0 */
237 res->howto = &arm_howto_table[0];
238 return TRUE;
239 case 5: /* len = 2, pcrel = 1 */
240 res->howto = &arm_howto_table[3];
241 return TRUE;
242 default:
243 return FALSE;
244 }
245 break;
0bae9e9e 246
f075eb5e
TG
247 case BFD_MACH_O_ARM_RELOC_BR24:
248 if (reloc.r_length == 2 && reloc.r_pcrel == 1)
249 {
250 res->howto = &arm_howto_table[11];
251 return TRUE;
252 }
f075eb5e 253 break;
0bae9e9e 254
f075eb5e
TG
255 case BFD_MACH_O_THUMB_RELOC_BR22:
256 if (reloc.r_length == 2 && reloc.r_pcrel == 1)
257 {
258 res->howto = &arm_howto_table[16];
259 return TRUE;
260 }
f075eb5e 261 break;
0bae9e9e 262
f075eb5e
TG
263 case BFD_MACH_O_ARM_RELOC_HALF:
264 if (reloc.r_pcrel == 0)
265 switch (reloc.r_length)
266 {
267 case 0: /* :lower16: for movw arm. */
268 res->howto = &arm_howto_table[12];
269 return TRUE;
270 case 1: /* :upper16: for movt arm. */
271 res->howto = &arm_howto_table[14];
272 return TRUE;
273 }
0bae9e9e
NC
274 break;
275
f075eb5e
TG
276 case BFD_MACH_O_ARM_RELOC_PAIR:
277 if (res[-1].howto == &arm_howto_table[12]
278 && reloc.r_length == 0)
279 {
280 /* Pair for :lower16: of movw arm. */
281 res->howto = &arm_howto_table[13];
282 /* This reloc contains the other half in its r_address field. */
283 res[-1].addend += (res->address & 0xffff) << 16;
284 res->address = res[-1].address;
285 return TRUE;
286 }
287 else if (res[-1].howto == &arm_howto_table[14]
288 && reloc.r_length == 1)
289 {
290 /* Pair for :upper16: of movt arm. */
291 res->howto = &arm_howto_table[15];
292 /* This reloc contains the other half in its r_address field. */
293 res[-1].addend += res->address & 0xffff;
294 res->address = res[-1].address;
295 return TRUE;
296 }
0bae9e9e
NC
297 break;
298
f075eb5e 299 default:
0bae9e9e 300 break;
f075eb5e
TG
301 }
302 }
0bae9e9e
NC
303
304 return FALSE;
f075eb5e
TG
305}
306
307static reloc_howto_type *
308bfd_mach_o_arm_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
309 bfd_reloc_code_real_type code)
310{
311 unsigned int i;
312
313 for (i = 0; i < sizeof (arm_howto_table) / sizeof (*arm_howto_table); i++)
314 if (code == arm_howto_table[i].type)
315 return &arm_howto_table[i];
316 return NULL;
317}
318
319static reloc_howto_type *
320bfd_mach_o_arm_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
321 const char *name ATTRIBUTE_UNUSED)
322{
323 return NULL;
324}
325
326#define TARGET_NAME arm_mach_o_vec
327#define TARGET_STRING "mach-o-arm"
328#define TARGET_ARCHITECTURE bfd_arch_arm
329#define TARGET_PAGESIZE 4096
330#define TARGET_BIG_ENDIAN 0
331#define TARGET_ARCHIVE 0
332#define TARGET_PRIORITY 0
333#include "mach-o-target.c"
This page took 0.144941 seconds and 4 git commands to generate.