1 /* NFP-specific support for 64-bit ELF
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
3 Contributed by Francois H. Theron <francois.theron@netronome.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,
20 Boston, MA 02110-1301, USA. */
29 static bfd_reloc_status_type
30 elf64_nfp_reloc (bfd
* abfd ATTRIBUTE_UNUSED
,
31 arelent
* reloc_entry
,
33 void *data ATTRIBUTE_UNUSED
,
34 asection
* input_section
,
36 char **error_message ATTRIBUTE_UNUSED
);
38 /* We don't actually apply any relocations in this toolset
39 so we make them all do nothing, but at least display useful
41 Most of these are mainly used by the NFP toolchain to resolve things
42 before the final ELF file is created. */
43 static reloc_howto_type elf_nfp_howto_table
[] =
45 HOWTO (R_NFP_NOTYPE
, /* Type. */
49 FALSE
, /* PC_relative. */
51 complain_overflow_dont
,/* Complain_on_overflow. */
52 elf64_nfp_reloc
, /* Special_function. */
53 "R_NFP_NOTYPE", /* Name. */
54 FALSE
, /* Partial_inplace. */
57 FALSE
), /* PCrel_offset. */
58 HOWTO (R_NFP_W32LE
, 0, 3, 0, FALSE
, 0,
59 complain_overflow_dont
, elf64_nfp_reloc
,
62 HOWTO (R_NFP_SRC8_A
, 0, 3, 0, FALSE
, 0,
63 complain_overflow_dont
, elf64_nfp_reloc
,
66 HOWTO (R_NFP_SRC8_B
, 0, 3, 0, FALSE
, 0,
67 complain_overflow_dont
, elf64_nfp_reloc
,
70 HOWTO (R_NFP_IMMED8_I
, 0, 3, 0, FALSE
, 0,
71 complain_overflow_dont
, elf64_nfp_reloc
,
74 HOWTO (R_NFP_SC
, 0, 3, 0, FALSE
, 0,
75 complain_overflow_dont
, elf64_nfp_reloc
,
78 HOWTO (R_NFP_IMMED_LO16_I_A
, 0, 3, 0, FALSE
, 0,
79 complain_overflow_dont
, elf64_nfp_reloc
,
80 "R_NFP_IMMED_LO16_I_A",
82 HOWTO (R_NFP_IMMED_LO16_I_B
, 0, 3, 0, FALSE
, 0,
83 complain_overflow_dont
, elf64_nfp_reloc
,
84 "R_NFP_IMMED_LO16_I_B",
86 HOWTO (R_NFP_SRC7_B
, 0, 3, 0, FALSE
, 0,
87 complain_overflow_dont
, elf64_nfp_reloc
,
90 HOWTO (R_NFP_SRC7_A
, 0, 3, 0, FALSE
, 0,
91 complain_overflow_dont
, elf64_nfp_reloc
,
94 HOWTO (R_NFP_SRC8_I_B
, 0, 3, 0, FALSE
, 0,
95 complain_overflow_dont
, elf64_nfp_reloc
,
98 HOWTO (R_NFP_SRC8_I_A
, 0, 3, 0, FALSE
, 0,
99 complain_overflow_dont
, elf64_nfp_reloc
,
102 HOWTO (R_NFP_IMMED_HI16_I_A
, 0, 3, 0, FALSE
, 0,
103 complain_overflow_dont
, elf64_nfp_reloc
,
104 "R_NFP_IMMED_HI16_I_A",
106 HOWTO (R_NFP_IMMED_HI16_I_B
, 0, 3, 0, FALSE
, 0,
107 complain_overflow_dont
, elf64_nfp_reloc
,
108 "R_NFP_IMMED_HI16_I_B",
110 HOWTO (R_NFP_W64LE
, 0, 3, 0, FALSE
, 0,
111 complain_overflow_dont
, elf64_nfp_reloc
,
114 HOWTO (R_NFP_SH_INFO
, 0, 3, 0, FALSE
, 0,
115 complain_overflow_dont
, elf64_nfp_reloc
,
118 HOWTO (R_NFP_W32BE
, 0, 3, 0, FALSE
, 0,
119 complain_overflow_dont
, elf64_nfp_reloc
,
122 HOWTO (R_NFP_W64BE
, 0, 3, 0, FALSE
, 0,
123 complain_overflow_dont
, elf64_nfp_reloc
,
126 HOWTO (R_NFP_W32_29_24
, 0, 3, 0, FALSE
, 0,
127 complain_overflow_dont
, elf64_nfp_reloc
,
130 HOWTO (R_NFP_W32LE_AND
, 0, 3, 0, FALSE
, 0,
131 complain_overflow_dont
, elf64_nfp_reloc
,
134 HOWTO (R_NFP_W32BE_AND
, 0, 3, 0, FALSE
, 0,
135 complain_overflow_dont
, elf64_nfp_reloc
,
138 HOWTO (R_NFP_W32LE_OR
, 0, 3, 0, FALSE
, 0,
139 complain_overflow_dont
, elf64_nfp_reloc
,
142 HOWTO (R_NFP_W32BE_OR
, 0, 3, 0, FALSE
, 0,
143 complain_overflow_dont
, elf64_nfp_reloc
,
146 HOWTO (R_NFP_W64LE_AND
, 0, 3, 0, FALSE
, 0,
147 complain_overflow_dont
, elf64_nfp_reloc
,
150 HOWTO (R_NFP_W64BE_AND
, 0, 3, 0, FALSE
, 0,
151 complain_overflow_dont
, elf64_nfp_reloc
,
154 HOWTO (R_NFP_W64LE_OR
, 0, 3, 0, FALSE
, 0,
155 complain_overflow_dont
, elf64_nfp_reloc
,
158 HOWTO (R_NFP_W64BE_OR
, 0, 3, 0, FALSE
, 0,
159 complain_overflow_dont
, elf64_nfp_reloc
,
165 elf64_nfp_object_p (bfd
* abfd
)
167 /* If the e_machine value is one of the unofficial ones, we convert
168 it first and set e_flags accordingly for later consistency. */
169 if (elf_elfheader (abfd
)->e_machine
== E_NFP_MACH_3200
)
171 elf_elfheader (abfd
)->e_machine
= EM_NFP
;
172 elf_elfheader (abfd
)->e_flags
&= ~EF_NFP_SET_MACH (~0);
173 elf_elfheader (abfd
)->e_flags
|= EF_NFP_SET_MACH (E_NFP_MACH_3200
);
175 else if (elf_elfheader (abfd
)->e_machine
== E_NFP_MACH_6000
)
177 elf_elfheader (abfd
)->e_machine
= EM_NFP
;
178 elf_elfheader (abfd
)->e_flags
&= ~EF_NFP_SET_MACH (~0);
179 elf_elfheader (abfd
)->e_flags
|= EF_NFP_SET_MACH (E_NFP_MACH_6000
);
182 if (elf_elfheader (abfd
)->e_machine
== EM_NFP
)
184 int e_mach
= EF_NFP_MACH (elf_elfheader (abfd
)->e_flags
);
188 case E_NFP_MACH_3200
:
189 case E_NFP_MACH_6000
:
190 if (!bfd_default_set_arch_mach (abfd
, bfd_arch_nfp
, e_mach
))
201 elf64_nfp_section_from_shdr (bfd
* abfd
,
202 Elf_Internal_Shdr
* hdr
,
203 const char *name
, int shindex
)
205 switch (hdr
->sh_type
)
207 case SHT_NFP_INITREG
:
208 case SHT_NFP_MECONFIG
:
210 return _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
);
216 bfd_reloc_status_type
217 elf64_nfp_reloc (bfd
* abfd ATTRIBUTE_UNUSED
,
218 arelent
* reloc_entry ATTRIBUTE_UNUSED
,
219 asymbol
* symbol ATTRIBUTE_UNUSED
,
220 void *data ATTRIBUTE_UNUSED
,
221 asection
* input_section ATTRIBUTE_UNUSED
,
222 bfd
* output_bfd ATTRIBUTE_UNUSED
,
223 char **error_message ATTRIBUTE_UNUSED
)
229 elf64_nfp_info_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
,
230 arelent
* cache_ptr
, Elf_Internal_Rela
* dst
)
234 r_type
= ELF64_R_TYPE (dst
->r_info
);
235 if (r_type
>= R_NFP_MAX
)
237 /* xgettext:c-format */
238 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
240 bfd_set_error (bfd_error_bad_value
);
243 cache_ptr
->howto
= &elf_nfp_howto_table
[r_type
];
247 static reloc_howto_type
*
248 elf64_nfp_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
249 bfd_reloc_code_real_type code ATTRIBUTE_UNUSED
)
254 static reloc_howto_type
*
255 elf64_nfp_reloc_name_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
256 const char *r_name ATTRIBUTE_UNUSED
)
261 #define ELF_ARCH bfd_arch_nfp
262 #define ELF_MACHINE_CODE EM_NFP
263 #define ELF_MACHINE_ALT1 E_NFP_MACH_6000
264 #define ELF_MACHINE_ALT2 E_NFP_MACH_3200
265 #define ELF_MAXPAGESIZE 1
266 #define TARGET_LITTLE_NAME "elf64-nfp"
267 #define TARGET_LITTLE_SYM nfp_elf64_vec
269 #define elf_backend_object_p elf64_nfp_object_p
270 #define elf_backend_section_from_shdr elf64_nfp_section_from_shdr
271 #define elf_info_to_howto elf64_nfp_info_to_howto
272 #define bfd_elf64_bfd_reloc_type_lookup elf64_nfp_reloc_type_lookup
273 #define bfd_elf64_bfd_reloc_name_lookup elf64_nfp_reloc_name_lookup
275 #include "elf64-target.h"