1
/* Intel x86-64 Mach-O support for BFD.
3
Free Software Foundation, Inc.
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. */
26
#include "libiberty.h"
28
#define bfd_mach_o_object_p bfd_mach_o_x86_64_object_p
29
#define bfd_mach_o_core_p bfd_mach_o_x86_64_core_p
30
#define bfd_mach_o_mkobject bfd_mach_o_x86_64_mkobject
32
static const bfd_target *
33
bfd_mach_o_x86_64_object_p (bfd *abfd)
35
return bfd_mach_o_header_p (abfd, 0, BFD_MACH_O_CPU_TYPE_X86_64);
38
static const bfd_target *
39
bfd_mach_o_x86_64_core_p (bfd *abfd)
41
return bfd_mach_o_header_p (abfd,
42
BFD_MACH_O_MH_CORE, BFD_MACH_O_CPU_TYPE_X86_64);
46
bfd_mach_o_x86_64_mkobject (bfd *abfd)
48
bfd_mach_o_data_struct *mdata;
50
if (!bfd_mach_o_mkobject_init (abfd))
53
mdata = bfd_mach_o_get_data (abfd);
54
mdata->header.magic = BFD_MACH_O_MH_MAGIC;
55
mdata->header.cputype = BFD_MACH_O_CPU_TYPE_X86_64;
56
mdata->header.cpusubtype = BFD_MACH_O_CPU_SUBTYPE_X86_ALL;
57
mdata->header.byteorder = BFD_ENDIAN_LITTLE;
58
mdata->header.version = 1;
63
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
64
#define MINUS_ONE (~ (bfd_vma) 0)
66
static reloc_howto_type x86_64_howto_table[]=
69
HOWTO(BFD_RELOC_64, 0, 4, 64, FALSE, 0,
70
complain_overflow_bitfield,
72
FALSE, MINUS_ONE, MINUS_ONE, FALSE),
73
HOWTO(BFD_RELOC_32, 0, 2, 32, FALSE, 0,
74
complain_overflow_bitfield,
76
FALSE, 0xffffffff, 0xffffffff, FALSE),
77
HOWTO(BFD_RELOC_32_PCREL, 0, 2, 32, TRUE, 0,
78
complain_overflow_bitfield,
80
FALSE, 0xffffffff, 0xffffffff, TRUE),
81
HOWTO(BFD_RELOC_MACH_O_X86_64_PCREL32_1, 0, 2, 32, TRUE, 0,
82
complain_overflow_bitfield,
84
FALSE, 0xffffffff, 0xffffffff, TRUE),
86
HOWTO(BFD_RELOC_MACH_O_X86_64_PCREL32_2, 0, 2, 32, TRUE, 0,
87
complain_overflow_bitfield,
89
FALSE, 0xffffffff, 0xffffffff, TRUE),
90
HOWTO(BFD_RELOC_MACH_O_X86_64_PCREL32_4, 0, 2, 32, TRUE, 0,
91
complain_overflow_bitfield,
93
FALSE, 0xffffffff, 0xffffffff, TRUE),
94
HOWTO(BFD_RELOC_MACH_O_X86_64_BRANCH32, 0, 2, 32, TRUE, 0,
95
complain_overflow_bitfield,
97
FALSE, 0xffffffff, 0xffffffff, TRUE),
98
HOWTO(BFD_RELOC_MACH_O_X86_64_GOT_LOAD, 0, 2, 32, TRUE, 0,
99
complain_overflow_bitfield,
101
FALSE, 0xffffffff, 0xffffffff, TRUE),
103
HOWTO(BFD_RELOC_MACH_O_X86_64_SUBTRACTOR32, 0, 2, 32, FALSE, 0,
104
complain_overflow_bitfield,
105
NULL, "SUBTRACTOR32",
106
FALSE, 0xffffffff, 0xffffffff, FALSE),
107
HOWTO(BFD_RELOC_MACH_O_X86_64_SUBTRACTOR64, 0, 4, 64, FALSE, 0,
108
complain_overflow_bitfield,
109
NULL, "SUBTRACTOR64",
110
FALSE, MINUS_ONE, MINUS_ONE, FALSE),
111
HOWTO(BFD_RELOC_MACH_O_X86_64_GOT, 0, 2, 32, TRUE, 0,
112
complain_overflow_bitfield,
114
FALSE, 0xffffffff, 0xffffffff, TRUE),
115
HOWTO(BFD_RELOC_MACH_O_X86_64_BRANCH8, 0, 0, 8, TRUE, 0,
116
complain_overflow_bitfield,
118
FALSE, 0xff, 0xff, TRUE),
122
bfd_mach_o_x86_64_swap_reloc_in (arelent *res, bfd_mach_o_reloc_info *reloc)
124
/* On x86-64, scattered relocs are not used. */
125
if (reloc->r_scattered)
128
switch (reloc->r_type)
130
case BFD_MACH_O_X86_64_RELOC_UNSIGNED:
133
switch (reloc->r_length)
136
res->howto = &x86_64_howto_table[1];
139
res->howto = &x86_64_howto_table[0];
144
case BFD_MACH_O_X86_64_RELOC_SIGNED:
145
if (reloc->r_length == 2 && reloc->r_pcrel)
147
res->howto = &x86_64_howto_table[2];
151
case BFD_MACH_O_X86_64_RELOC_BRANCH:
154
switch (reloc->r_length)
157
res->howto = &x86_64_howto_table[6];
163
case BFD_MACH_O_X86_64_RELOC_GOT_LOAD:
164
if (reloc->r_length == 2 && reloc->r_pcrel && reloc->r_extern)
166
res->howto = &x86_64_howto_table[7];
170
case BFD_MACH_O_X86_64_RELOC_GOT:
171
if (reloc->r_length == 2 && reloc->r_pcrel && reloc->r_extern)
173
res->howto = &x86_64_howto_table[10];
177
case BFD_MACH_O_X86_64_RELOC_SUBTRACTOR:
180
switch (reloc->r_length)
183
res->howto = &x86_64_howto_table[8];
186
res->howto = &x86_64_howto_table[9];
192
case BFD_MACH_O_X86_64_RELOC_SIGNED_1:
193
if (reloc->r_length == 2 && reloc->r_pcrel)
195
res->howto = &x86_64_howto_table[3];
199
case BFD_MACH_O_X86_64_RELOC_SIGNED_2:
200
if (reloc->r_length == 2 && reloc->r_pcrel)
202
res->howto = &x86_64_howto_table[4];
206
case BFD_MACH_O_X86_64_RELOC_SIGNED_4:
207
if (reloc->r_length == 2 && reloc->r_pcrel)
209
res->howto = &x86_64_howto_table[5];
220
bfd_mach_o_x86_64_swap_reloc_out (arelent *rel, bfd_mach_o_reloc_info *rinfo)
222
rinfo->r_address = rel->address;
223
switch (rel->howto->type)
226
rinfo->r_scattered = 0;
227
rinfo->r_type = BFD_MACH_O_X86_64_RELOC_UNSIGNED;
229
rinfo->r_length = rel->howto->size; /* Correct in practice. */
230
if ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
233
rinfo->r_value = (*rel->sym_ptr_ptr)->section->target_index;
238
rinfo->r_value = (*rel->sym_ptr_ptr)->udata.i;
247
static reloc_howto_type *
248
bfd_mach_o_x86_64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
249
bfd_reloc_code_real_type code)
254
i < sizeof (x86_64_howto_table) / sizeof (*x86_64_howto_table);
256
if (code == x86_64_howto_table[i].type)
257
return &x86_64_howto_table[i];
261
static reloc_howto_type *
262
bfd_mach_o_x86_64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
263
const char *name ATTRIBUTE_UNUSED)
268
#define bfd_mach_o_swap_reloc_in bfd_mach_o_x86_64_swap_reloc_in
269
#define bfd_mach_o_swap_reloc_out bfd_mach_o_x86_64_swap_reloc_out
271
#define bfd_mach_o_bfd_reloc_type_lookup bfd_mach_o_x86_64_bfd_reloc_type_lookup
272
#define bfd_mach_o_bfd_reloc_name_lookup bfd_mach_o_x86_64_bfd_reloc_name_lookup
273
#define bfd_mach_o_print_thread NULL
275
#define TARGET_NAME mach_o_x86_64_vec
276
#define TARGET_STRING "mach-o-x86-64"
277
#define TARGET_ARCHITECTURE bfd_arch_i386
278
#define TARGET_BIG_ENDIAN 0
279
#define TARGET_ARCHIVE 0
280
#include "mach-o-target.c"