elf64-nfp.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* NFP-specific support for 64-bit ELF
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. Contributed by Francois H. Theron <francois.theron@netronome.com>
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "elf-bfd.h"
  21. #include "elf/nfp.h"
  22. static bfd_reloc_status_type
  23. elf64_nfp_reloc (bfd * abfd ATTRIBUTE_UNUSED,
  24. arelent * reloc_entry,
  25. asymbol * symbol,
  26. void *data ATTRIBUTE_UNUSED,
  27. asection * input_section,
  28. bfd * output_bfd,
  29. char **error_message ATTRIBUTE_UNUSED);
  30. /* We don't actually apply any relocations in this toolset
  31. so we make them all do nothing, but at least display useful
  32. names.
  33. Most of these are mainly used by the NFP toolchain to resolve things
  34. before the final ELF file is created. */
  35. static reloc_howto_type elf_nfp_howto_table[] =
  36. {
  37. HOWTO (R_NFP_NOTYPE, /* Type. */
  38. 0, /* Rightshift. */
  39. 3, /* Size. */
  40. 0, /* Bitsize. */
  41. false, /* PC_relative. */
  42. 0, /* Bitpos. */
  43. complain_overflow_dont,/* Complain_on_overflow. */
  44. elf64_nfp_reloc, /* Special_function. */
  45. "R_NFP_NOTYPE", /* Name. */
  46. false, /* Partial_inplace. */
  47. 0, /* Src_mask. */
  48. 0, /* Dst_mask. */
  49. false), /* PCrel_offset. */
  50. HOWTO (R_NFP_W32LE, 0, 3, 0, false, 0,
  51. complain_overflow_dont, elf64_nfp_reloc,
  52. "R_NFP_W32LE",
  53. false, 0, 0, false),
  54. HOWTO (R_NFP_SRC8_A, 0, 3, 0, false, 0,
  55. complain_overflow_dont, elf64_nfp_reloc,
  56. "R_NFP_SRC8_A",
  57. false, 0, 0, false),
  58. HOWTO (R_NFP_SRC8_B, 0, 3, 0, false, 0,
  59. complain_overflow_dont, elf64_nfp_reloc,
  60. "R_NFP_SRC8_B",
  61. false, 0, 0, false),
  62. HOWTO (R_NFP_IMMED8_I, 0, 3, 0, false, 0,
  63. complain_overflow_dont, elf64_nfp_reloc,
  64. "R_NFP_IMMED8_I",
  65. false, 0, 0, false),
  66. HOWTO (R_NFP_SC, 0, 3, 0, false, 0,
  67. complain_overflow_dont, elf64_nfp_reloc,
  68. "R_NFP_SC",
  69. false, 0, 0, false),
  70. HOWTO (R_NFP_IMMED_LO16_I_A, 0, 3, 0, false, 0,
  71. complain_overflow_dont, elf64_nfp_reloc,
  72. "R_NFP_IMMED_LO16_I_A",
  73. false, 0, 0, false),
  74. HOWTO (R_NFP_IMMED_LO16_I_B, 0, 3, 0, false, 0,
  75. complain_overflow_dont, elf64_nfp_reloc,
  76. "R_NFP_IMMED_LO16_I_B",
  77. true, 0, 0, false),
  78. HOWTO (R_NFP_SRC7_B, 0, 3, 0, false, 0,
  79. complain_overflow_dont, elf64_nfp_reloc,
  80. "R_NFP_SRC7_B",
  81. false, 0, 0, false),
  82. HOWTO (R_NFP_SRC7_A, 0, 3, 0, false, 0,
  83. complain_overflow_dont, elf64_nfp_reloc,
  84. "R_NFP_SRC7_A",
  85. false, 0, 0, false),
  86. HOWTO (R_NFP_SRC8_I_B, 0, 3, 0, false, 0,
  87. complain_overflow_dont, elf64_nfp_reloc,
  88. "R_NFP_SRC8_I_B",
  89. false, 0, 0, false),
  90. HOWTO (R_NFP_SRC8_I_A, 0, 3, 0, false, 0,
  91. complain_overflow_dont, elf64_nfp_reloc,
  92. "R_NFP_SRC8_I_A",
  93. false, 0, 0, false),
  94. HOWTO (R_NFP_IMMED_HI16_I_A, 0, 3, 0, false, 0,
  95. complain_overflow_dont, elf64_nfp_reloc,
  96. "R_NFP_IMMED_HI16_I_A",
  97. false, 0, 0, false),
  98. HOWTO (R_NFP_IMMED_HI16_I_B, 0, 3, 0, false, 0,
  99. complain_overflow_dont, elf64_nfp_reloc,
  100. "R_NFP_IMMED_HI16_I_B",
  101. false, 0, 0, false),
  102. HOWTO (R_NFP_W64LE, 0, 3, 0, false, 0,
  103. complain_overflow_dont, elf64_nfp_reloc,
  104. "R_NFP_W64LE",
  105. false, 0, 0, false),
  106. HOWTO (R_NFP_SH_INFO, 0, 3, 0, false, 0,
  107. complain_overflow_dont, elf64_nfp_reloc,
  108. "R_NFP_SH_INFO",
  109. false, 0, 0, false),
  110. HOWTO (R_NFP_W32BE, 0, 3, 0, false, 0,
  111. complain_overflow_dont, elf64_nfp_reloc,
  112. "R_NFP_W32BE",
  113. false, 0, 0, false),
  114. HOWTO (R_NFP_W64BE, 0, 3, 0, false, 0,
  115. complain_overflow_dont, elf64_nfp_reloc,
  116. "R_NFP_W64BE",
  117. false, 0, 0, false),
  118. HOWTO (R_NFP_W32_29_24, 0, 3, 0, false, 0,
  119. complain_overflow_dont, elf64_nfp_reloc,
  120. "R_NFP_W32_29_24",
  121. false, 0, 0, false),
  122. HOWTO (R_NFP_W32LE_AND, 0, 3, 0, false, 0,
  123. complain_overflow_dont, elf64_nfp_reloc,
  124. "R_NFP_W32LE_AND",
  125. false, 0, 0, false),
  126. HOWTO (R_NFP_W32BE_AND, 0, 3, 0, false, 0,
  127. complain_overflow_dont, elf64_nfp_reloc,
  128. "R_NFP_W32BE_AND",
  129. false, 0, 0, false),
  130. HOWTO (R_NFP_W32LE_OR, 0, 3, 0, false, 0,
  131. complain_overflow_dont, elf64_nfp_reloc,
  132. "R_NFP_W32LE_OR",
  133. false, 0, 0, false),
  134. HOWTO (R_NFP_W32BE_OR, 0, 3, 0, false, 0,
  135. complain_overflow_dont, elf64_nfp_reloc,
  136. "R_NFP_W32BE_OR",
  137. false, 0, 0, false),
  138. HOWTO (R_NFP_W64LE_AND, 0, 3, 0, false, 0,
  139. complain_overflow_dont, elf64_nfp_reloc,
  140. "R_NFP_W64LE_AND",
  141. false, 0, 0, false),
  142. HOWTO (R_NFP_W64BE_AND, 0, 3, 0, false, 0,
  143. complain_overflow_dont, elf64_nfp_reloc,
  144. "R_NFP_W64BE_AND",
  145. false, 0, 0, false),
  146. HOWTO (R_NFP_W64LE_OR, 0, 3, 0, false, 0,
  147. complain_overflow_dont, elf64_nfp_reloc,
  148. "R_NFP_W64LE_OR",
  149. false, 0, 0, false),
  150. HOWTO (R_NFP_W64BE_OR, 0, 3, 0, false, 0,
  151. complain_overflow_dont, elf64_nfp_reloc,
  152. "R_NFP_W64BE_OR",
  153. false, 0, 0, false)
  154. };
  155. static bool
  156. elf64_nfp_object_p (bfd * abfd)
  157. {
  158. /* If the e_machine value is one of the unofficial ones, we convert
  159. it first and set e_flags accordingly for later consistency. */
  160. if (elf_elfheader (abfd)->e_machine == E_NFP_MACH_3200)
  161. {
  162. elf_elfheader (abfd)->e_machine = EM_NFP;
  163. elf_elfheader (abfd)->e_flags &= ~EF_NFP_SET_MACH (~0);
  164. elf_elfheader (abfd)->e_flags |= EF_NFP_SET_MACH (E_NFP_MACH_3200);
  165. }
  166. else if (elf_elfheader (abfd)->e_machine == E_NFP_MACH_6000)
  167. {
  168. elf_elfheader (abfd)->e_machine = EM_NFP;
  169. elf_elfheader (abfd)->e_flags &= ~EF_NFP_SET_MACH (~0);
  170. elf_elfheader (abfd)->e_flags |= EF_NFP_SET_MACH (E_NFP_MACH_6000);
  171. }
  172. if (elf_elfheader (abfd)->e_machine == EM_NFP)
  173. {
  174. int e_mach = EF_NFP_MACH (elf_elfheader (abfd)->e_flags);
  175. switch (e_mach)
  176. {
  177. case E_NFP_MACH_3200:
  178. case E_NFP_MACH_6000:
  179. if (!bfd_default_set_arch_mach (abfd, bfd_arch_nfp, e_mach))
  180. return false;
  181. default:
  182. break;
  183. }
  184. }
  185. return true;
  186. }
  187. static bool
  188. elf64_nfp_section_from_shdr (bfd * abfd,
  189. Elf_Internal_Shdr * hdr,
  190. const char *name, int shindex)
  191. {
  192. switch (hdr->sh_type)
  193. {
  194. case SHT_NFP_INITREG:
  195. case SHT_NFP_MECONFIG:
  196. case SHT_NFP_UDEBUG:
  197. return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
  198. default:
  199. return false;
  200. }
  201. }
  202. bfd_reloc_status_type
  203. elf64_nfp_reloc (bfd * abfd ATTRIBUTE_UNUSED,
  204. arelent * reloc_entry ATTRIBUTE_UNUSED,
  205. asymbol * symbol ATTRIBUTE_UNUSED,
  206. void *data ATTRIBUTE_UNUSED,
  207. asection * input_section ATTRIBUTE_UNUSED,
  208. bfd * output_bfd ATTRIBUTE_UNUSED,
  209. char **error_message ATTRIBUTE_UNUSED)
  210. {
  211. return bfd_reloc_ok;
  212. }
  213. static bool
  214. elf64_nfp_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
  215. arelent * cache_ptr, Elf_Internal_Rela * dst)
  216. {
  217. unsigned int r_type;
  218. r_type = ELF64_R_TYPE (dst->r_info);
  219. if (r_type >= R_NFP_MAX)
  220. {
  221. /* xgettext:c-format */
  222. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  223. abfd, r_type);
  224. bfd_set_error (bfd_error_bad_value);
  225. return false;
  226. }
  227. cache_ptr->howto = &elf_nfp_howto_table[r_type];
  228. return true;
  229. }
  230. static reloc_howto_type *
  231. elf64_nfp_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  232. bfd_reloc_code_real_type code ATTRIBUTE_UNUSED)
  233. {
  234. return NULL;
  235. }
  236. static reloc_howto_type *
  237. elf64_nfp_reloc_name_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  238. const char *r_name ATTRIBUTE_UNUSED)
  239. {
  240. return NULL;
  241. }
  242. #define ELF_ARCH bfd_arch_nfp
  243. #define ELF_MACHINE_CODE EM_NFP
  244. #define ELF_MACHINE_ALT1 E_NFP_MACH_6000
  245. #define ELF_MACHINE_ALT2 E_NFP_MACH_3200
  246. #define ELF_MAXPAGESIZE 1
  247. #define TARGET_LITTLE_NAME "elf64-nfp"
  248. #define TARGET_LITTLE_SYM nfp_elf64_vec
  249. #define elf_backend_object_p elf64_nfp_object_p
  250. #define elf_backend_section_from_shdr elf64_nfp_section_from_shdr
  251. #define elf_info_to_howto elf64_nfp_info_to_howto
  252. #define bfd_elf64_bfd_reloc_type_lookup elf64_nfp_reloc_type_lookup
  253. #define bfd_elf64_bfd_reloc_name_lookup elf64_nfp_reloc_name_lookup
  254. #include "elf64-target.h"