1 /* NFP-specific support for 64-bit ELF
2 Copyright (C) 2017-2018 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. */
27 #include "bfd_stdint.h"
30 static bfd_reloc_status_type
31 elf64_nfp_reloc (bfd * abfd ATTRIBUTE_UNUSED,
32 arelent * reloc_entry,
34 void *data ATTRIBUTE_UNUSED,
35 asection * input_section,
37 char **error_message ATTRIBUTE_UNUSED);
39 /* We don't actually apply any relocations in this toolset
40 so we make them all do nothing, but at least display useful
42 Most of these are mainly used by the NFP toolchain to resolve things
43 before the final ELF file is created. */
44 static reloc_howto_type elf_nfp_howto_table[] =
46 HOWTO (R_NFP_NOTYPE, /* Type. */
50 FALSE, /* PC_relative. */
52 complain_overflow_dont,/* Complain_on_overflow. */
53 elf64_nfp_reloc, /* Special_function. */
54 "R_NFP_NOTYPE", /* Name. */
55 FALSE, /* Partial_inplace. */
58 FALSE), /* PCrel_offset. */
59 HOWTO (R_NFP_W32LE, 0, 3, 0, FALSE, 0,
60 complain_overflow_dont, elf64_nfp_reloc,
63 HOWTO (R_NFP_SRC8_A, 0, 3, 0, FALSE, 0,
64 complain_overflow_dont, elf64_nfp_reloc,
67 HOWTO (R_NFP_SRC8_B, 0, 3, 0, FALSE, 0,
68 complain_overflow_dont, elf64_nfp_reloc,
71 HOWTO (R_NFP_IMMED8_I, 0, 3, 0, FALSE, 0,
72 complain_overflow_dont, elf64_nfp_reloc,
75 HOWTO (R_NFP_SC, 0, 3, 0, FALSE, 0,
76 complain_overflow_dont, elf64_nfp_reloc,
79 HOWTO (R_NFP_IMMED_LO16_I_A, 0, 3, 0, FALSE, 0,
80 complain_overflow_dont, elf64_nfp_reloc,
81 "R_NFP_IMMED_LO16_I_A",
83 HOWTO (R_NFP_IMMED_LO16_I_B, 0, 3, 0, FALSE, 0,
84 complain_overflow_dont, elf64_nfp_reloc,
85 "R_NFP_IMMED_LO16_I_B",
87 HOWTO (R_NFP_SRC7_B, 0, 3, 0, FALSE, 0,
88 complain_overflow_dont, elf64_nfp_reloc,
91 HOWTO (R_NFP_SRC7_A, 0, 3, 0, FALSE, 0,
92 complain_overflow_dont, elf64_nfp_reloc,
95 HOWTO (R_NFP_SRC8_I_B, 0, 3, 0, FALSE, 0,
96 complain_overflow_dont, elf64_nfp_reloc,
99 HOWTO (R_NFP_SRC8_I_A, 0, 3, 0, FALSE, 0,
100 complain_overflow_dont, elf64_nfp_reloc,
103 HOWTO (R_NFP_IMMED_HI16_I_A, 0, 3, 0, FALSE, 0,
104 complain_overflow_dont, elf64_nfp_reloc,
105 "R_NFP_IMMED_HI16_I_A",
107 HOWTO (R_NFP_IMMED_HI16_I_B, 0, 3, 0, FALSE, 0,
108 complain_overflow_dont, elf64_nfp_reloc,
109 "R_NFP_IMMED_HI16_I_B",
111 HOWTO (R_NFP_W64LE, 0, 3, 0, FALSE, 0,
112 complain_overflow_dont, elf64_nfp_reloc,
115 HOWTO (R_NFP_SH_INFO, 0, 3, 0, FALSE, 0,
116 complain_overflow_dont, elf64_nfp_reloc,
119 HOWTO (R_NFP_W32BE, 0, 3, 0, FALSE, 0,
120 complain_overflow_dont, elf64_nfp_reloc,
123 HOWTO (R_NFP_W64BE, 0, 3, 0, FALSE, 0,
124 complain_overflow_dont, elf64_nfp_reloc,
127 HOWTO (R_NFP_W32_29_24, 0, 3, 0, FALSE, 0,
128 complain_overflow_dont, elf64_nfp_reloc,
131 HOWTO (R_NFP_W32LE_AND, 0, 3, 0, FALSE, 0,
132 complain_overflow_dont, elf64_nfp_reloc,
135 HOWTO (R_NFP_W32BE_AND, 0, 3, 0, FALSE, 0,
136 complain_overflow_dont, elf64_nfp_reloc,
139 HOWTO (R_NFP_W32LE_OR, 0, 3, 0, FALSE, 0,
140 complain_overflow_dont, elf64_nfp_reloc,
143 HOWTO (R_NFP_W32BE_OR, 0, 3, 0, FALSE, 0,
144 complain_overflow_dont, elf64_nfp_reloc,
147 HOWTO (R_NFP_W64LE_AND, 0, 3, 0, FALSE, 0,
148 complain_overflow_dont, elf64_nfp_reloc,
151 HOWTO (R_NFP_W64BE_AND, 0, 3, 0, FALSE, 0,
152 complain_overflow_dont, elf64_nfp_reloc,
155 HOWTO (R_NFP_W64LE_OR, 0, 3, 0, FALSE, 0,
156 complain_overflow_dont, elf64_nfp_reloc,
159 HOWTO (R_NFP_W64BE_OR, 0, 3, 0, FALSE, 0,
160 complain_overflow_dont, elf64_nfp_reloc,
166 elf64_nfp_object_p (bfd * abfd)
168 /* If the e_machine value is one of the unofficial ones, we convert
169 it first and set e_flags accordingly for later consistency. */
170 if (elf_elfheader (abfd)->e_machine == E_NFP_MACH_3200)
172 elf_elfheader (abfd)->e_machine = EM_NFP;
173 elf_elfheader (abfd)->e_flags &= ~EF_NFP_SET_MACH (~0);
174 elf_elfheader (abfd)->e_flags |= EF_NFP_SET_MACH (E_NFP_MACH_3200);
176 else if (elf_elfheader (abfd)->e_machine == E_NFP_MACH_6000)
178 elf_elfheader (abfd)->e_machine = EM_NFP;
179 elf_elfheader (abfd)->e_flags &= ~EF_NFP_SET_MACH (~0);
180 elf_elfheader (abfd)->e_flags |= EF_NFP_SET_MACH (E_NFP_MACH_6000);
183 if (elf_elfheader (abfd)->e_machine == EM_NFP)
185 int e_mach = EF_NFP_MACH (elf_elfheader (abfd)->e_flags);
189 case E_NFP_MACH_3200:
190 case E_NFP_MACH_6000:
191 if (!bfd_default_set_arch_mach (abfd, bfd_arch_nfp, e_mach))
202 elf64_nfp_section_from_shdr (bfd * abfd,
203 Elf_Internal_Shdr * hdr,
204 const char *name, int shindex)
206 switch (hdr->sh_type)
208 case SHT_NFP_INITREG:
209 case SHT_NFP_MECONFIG:
211 return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
217 bfd_reloc_status_type
218 elf64_nfp_reloc (bfd * abfd ATTRIBUTE_UNUSED,
219 arelent * reloc_entry ATTRIBUTE_UNUSED,
220 asymbol * symbol ATTRIBUTE_UNUSED,
221 void *data ATTRIBUTE_UNUSED,
222 asection * input_section ATTRIBUTE_UNUSED,
223 bfd * output_bfd ATTRIBUTE_UNUSED,
224 char **error_message ATTRIBUTE_UNUSED)
230 elf64_nfp_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
231 arelent * cache_ptr, Elf_Internal_Rela * dst)
235 r_type = ELF64_R_TYPE (dst->r_info);
236 if (r_type >= R_NFP_MAX)
238 /* xgettext:c-format */
239 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
241 bfd_set_error (bfd_error_bad_value);
244 cache_ptr->howto = &elf_nfp_howto_table[r_type];
248 static reloc_howto_type *
249 elf64_nfp_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
250 bfd_reloc_code_real_type code ATTRIBUTE_UNUSED)
255 static reloc_howto_type *
256 elf64_nfp_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED,
257 const char *r_name ATTRIBUTE_UNUSED)
262 #define ELF_ARCH bfd_arch_nfp
263 #define ELF_MACHINE_CODE EM_NFP
264 #define ELF_MACHINE_ALT1 E_NFP_MACH_6000
265 #define ELF_MACHINE_ALT2 E_NFP_MACH_3200
266 #define ELF_MAXPAGESIZE 1
267 #define TARGET_LITTLE_NAME "elf64-nfp"
268 #define TARGET_LITTLE_SYM nfp_elf64_vec
270 #define elf_backend_object_p elf64_nfp_object_p
271 #define elf_backend_section_from_shdr elf64_nfp_section_from_shdr
272 #define elf_info_to_howto elf64_nfp_info_to_howto
273 #define bfd_elf64_bfd_reloc_type_lookup elf64_nfp_reloc_type_lookup
274 #define bfd_elf64_bfd_reloc_name_lookup elf64_nfp_reloc_name_lookup
276 #include "elf64-target.h"