elf32-z80.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /* Zilog (e)Z80-specific support for 32-bit ELF
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. (Heavily copied from the S12Z port by Sergey Belyashov (sergey.belyashov@gmail.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, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "bfdlink.h"
  20. #include "libbfd.h"
  21. #include "elf-bfd.h"
  22. #include "elf/z80.h"
  23. /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
  24. #define OCTETS_PER_BYTE(ABFD, SEC) 1
  25. typedef const struct {
  26. bfd_reloc_code_real_type r_type;
  27. reloc_howto_type howto;
  28. } bfd_howto_type;
  29. #define BFD_EMPTY_HOWTO(rt,x) {rt, EMPTY_HOWTO(x)}
  30. #define BFD_HOWTO(rt,a,b,c,d,e,f,g,h,i,j,k,l,m) {rt, HOWTO(a,b,c,d,e,f,g,h,i,j,k,l,m)}
  31. static bfd_reloc_status_type
  32. z80_elf_16_be_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  33. void *data, asection *input_section, bfd *output_bfd,
  34. char **error_message);
  35. static const
  36. bfd_howto_type elf_z80_howto_table[] =
  37. {
  38. /* This reloc does nothing. */
  39. BFD_HOWTO (BFD_RELOC_NONE,
  40. R_Z80_NONE, /* type */
  41. 0, /* rightshift */
  42. 3, /* size (0 = byte, 1 = short, 2 = long) */
  43. 0, /* bitsize */
  44. false, /* pc_relative */
  45. 0, /* bitpos */
  46. complain_overflow_dont,/* complain_on_overflow */
  47. bfd_elf_generic_reloc, /* special_function */
  48. "R_NONE", /* name */
  49. false, /* partial_inplace */
  50. 0, /* src_mask */
  51. 0, /* dst_mask */
  52. false), /* pcrel_offset */
  53. /* A 8 bit relocation */
  54. BFD_HOWTO (BFD_RELOC_8,
  55. R_Z80_8, /* type */
  56. 0, /* rightshift */
  57. 0, /* size (0 = byte, 1 = short, 2 = long) */
  58. 8, /* bitsize */
  59. false, /* pc_relative */
  60. 0, /* bitpos */
  61. complain_overflow_bitfield, /* complain_on_overflow */
  62. bfd_elf_generic_reloc, /* special_function */
  63. "r_imm8", /* name */
  64. false, /* partial_inplace */
  65. 0x00, /* src_mask */
  66. 0xff, /* dst_mask */
  67. false), /* pcrel_offset */
  68. /* A 8 bit index register displacement relocation */
  69. BFD_HOWTO (BFD_RELOC_Z80_DISP8,
  70. R_Z80_8_DIS, /* type */
  71. 0, /* rightshift */
  72. 0, /* size (0 = byte, 1 = short, 2 = long) */
  73. 8, /* bitsize */
  74. false, /* pc_relative */
  75. 0, /* bitpos */
  76. complain_overflow_signed, /* complain_on_overflow */
  77. bfd_elf_generic_reloc, /* special_function */
  78. "r_off", /* name */
  79. false, /* partial_inplace */
  80. 0x00, /* src_mask */
  81. 0xff, /* dst_mask */
  82. false), /* pcrel_offset */
  83. /* A 8 bit PC-rel relocation */
  84. BFD_HOWTO (BFD_RELOC_8_PCREL,
  85. R_Z80_8_PCREL, /* type */
  86. 0, /* rightshift */
  87. 0, /* size (0 = byte, 1 = short, 2 = long) */
  88. 8, /* bitsize */
  89. true, /* pc_relative */
  90. 0, /* bitpos */
  91. complain_overflow_signed, /* complain_on_overflow */
  92. bfd_elf_generic_reloc, /* special_function */
  93. "r_jr", /* name */
  94. false, /* partial_inplace */
  95. 0x00, /* src_mask */
  96. 0xff, /* dst_mask */
  97. true), /* pcrel_offset */
  98. /* An 16 bit absolute relocation */
  99. BFD_HOWTO (BFD_RELOC_16,
  100. R_Z80_16, /* type */
  101. 0, /* rightshift */
  102. 1, /* size (0 = byte, 1 = short, 2 = long) */
  103. 16, /* bitsize */
  104. false, /* pc_relative */
  105. 0, /* bitpos */
  106. complain_overflow_bitfield, /* complain_on_overflow */
  107. bfd_elf_generic_reloc, /* special_function */
  108. "r_imm16", /* name */
  109. false, /* partial_inplace */
  110. 0x00000000, /* src_mask */
  111. 0x0000ffff, /* dst_mask */
  112. false), /* pcrel_offset */
  113. /* A 24 bit absolute relocation emitted by ADL mode operands */
  114. BFD_HOWTO (BFD_RELOC_24,
  115. R_Z80_24, /* type */
  116. 0, /* rightshift */
  117. 5, /* size (0 = byte, 1 = short, 2 = long) */
  118. 24, /* bitsize */
  119. false, /* pc_relative */
  120. 0, /* bitpos */
  121. complain_overflow_bitfield, /* complain_on_overflow */
  122. bfd_elf_generic_reloc, /* special_function */
  123. "r_imm24", /* name */
  124. false, /* partial_inplace */
  125. 0x00000000, /* src_mask */
  126. 0x00ffffff, /* dst_mask */
  127. false), /* pcrel_offset */
  128. BFD_HOWTO (BFD_RELOC_32,
  129. R_Z80_32, /* type */
  130. 0, /* rightshift */
  131. 2, /* size (0 = byte, 1 = short, 2 = long) */
  132. 32, /* bitsize */
  133. false, /* pc_relative */
  134. 0, /* bitpos */
  135. complain_overflow_dont,/* complain_on_overflow */
  136. bfd_elf_generic_reloc, /* special_function */
  137. "r_imm32", /* name */
  138. false, /* partial_inplace */
  139. 0x00000000, /* src_mask */
  140. 0xffffffff, /* dst_mask */
  141. false), /* pcrel_offset */
  142. /* First (lowest) 8 bits of multibyte relocation */
  143. BFD_HOWTO (BFD_RELOC_Z80_BYTE0,
  144. R_Z80_BYTE0, /* type */
  145. 0, /* rightshift */
  146. 0, /* size (0 = byte, 1 = short, 2 = long) */
  147. 32, /* bitsize */
  148. false, /* pc_relative */
  149. 0, /* bitpos */
  150. complain_overflow_dont,/* complain_on_overflow */
  151. bfd_elf_generic_reloc, /* special_function */
  152. "r_byte0", /* name */
  153. false, /* partial_inplace */
  154. 0, /* src_mask */
  155. 0xff, /* dst_mask */
  156. false), /* pcrel_offset */
  157. /* Second 8 bits of multibyte relocation */
  158. BFD_HOWTO (BFD_RELOC_Z80_BYTE1,
  159. R_Z80_BYTE1, /* type */
  160. 8, /* rightshift */
  161. 0, /* size (0 = byte, 1 = short, 2 = long) */
  162. 32, /* bitsize */
  163. false, /* pc_relative */
  164. 0, /* bitpos */
  165. complain_overflow_dont,/* complain_on_overflow */
  166. bfd_elf_generic_reloc, /* special_function */
  167. "r_byte1", /* name */
  168. false, /* partial_inplace */
  169. 0, /* src_mask */
  170. 0xff, /* dst_mask */
  171. false), /* pcrel_offset */
  172. /* Third 8 bits of multibyte relocation */
  173. BFD_HOWTO (BFD_RELOC_Z80_BYTE2,
  174. R_Z80_BYTE2, /* type */
  175. 16, /* rightshift */
  176. 0, /* size (0 = byte, 1 = short, 2 = long) */
  177. 32, /* bitsize */
  178. false, /* pc_relative */
  179. 0, /* bitpos */
  180. complain_overflow_dont,/* complain_on_overflow */
  181. bfd_elf_generic_reloc, /* special_function */
  182. "r_byte2", /* name */
  183. false, /* partial_inplace */
  184. 0, /* src_mask */
  185. 0xff, /* dst_mask */
  186. false), /* pcrel_offset */
  187. /* Fourth (highest) 8 bits of multibyte relocation */
  188. BFD_HOWTO (BFD_RELOC_Z80_BYTE3,
  189. R_Z80_BYTE3, /* type */
  190. 24, /* rightshift */
  191. 0, /* size (0 = byte, 1 = short, 2 = long) */
  192. 32, /* bitsize */
  193. false, /* pc_relative */
  194. 0, /* bitpos */
  195. complain_overflow_dont,/* complain_on_overflow */
  196. bfd_elf_generic_reloc, /* special_function */
  197. "r_byte3", /* name */
  198. false, /* partial_inplace */
  199. 0, /* src_mask */
  200. 0xff, /* dst_mask */
  201. false), /* pcrel_offset */
  202. /* An 16 bit absolute relocation of lower word of multibyte value */
  203. BFD_HOWTO (BFD_RELOC_Z80_WORD0,
  204. R_Z80_WORD0, /* type */
  205. 0, /* rightshift */
  206. 1, /* size (0 = byte, 1 = short, 2 = long) */
  207. 32, /* bitsize */
  208. false, /* pc_relative */
  209. 0, /* bitpos */
  210. complain_overflow_dont,/* complain_on_overflow */
  211. bfd_elf_generic_reloc, /* special_function */
  212. "r_word0", /* name */
  213. false, /* partial_inplace */
  214. 0, /* src_mask */
  215. 0xffff, /* dst_mask */
  216. false), /* pcrel_offset */
  217. /* An 16 bit absolute relocation of higher word of multibyte value */
  218. BFD_HOWTO (BFD_RELOC_Z80_WORD1,
  219. R_Z80_WORD1, /* type */
  220. 16, /* rightshift */
  221. 1, /* size (0 = byte, 1 = short, 2 = long) */
  222. 32, /* bitsize */
  223. false, /* pc_relative */
  224. 0, /* bitpos */
  225. complain_overflow_dont,/* complain_on_overflow */
  226. bfd_elf_generic_reloc, /* special_function */
  227. "r_word1", /* name */
  228. false, /* partial_inplace */
  229. 0, /* src_mask */
  230. 0xffff, /* dst_mask */
  231. false), /* pcrel_offset */
  232. /* An 16 bit big endian absolute relocation */
  233. BFD_HOWTO (BFD_RELOC_Z80_16_BE,
  234. R_Z80_16_BE, /* type */
  235. 0, /* rightshift */
  236. 1, /* size (0 = byte, 1 = short, 2 = long) */
  237. 16, /* bitsize */
  238. false, /* pc_relative */
  239. 0, /* bitpos */
  240. complain_overflow_bitfield, /* complain_on_overflow */
  241. z80_elf_16_be_reloc, /* special_function */
  242. "r_imm16be", /* name */
  243. false, /* partial_inplace */
  244. 0x00000000, /* src_mask */
  245. 0x0000ffff, /* dst_mask */
  246. false), /* pcrel_offset */
  247. };
  248. static reloc_howto_type *
  249. z80_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  250. bfd_reloc_code_real_type code)
  251. {
  252. enum
  253. {
  254. table_size = sizeof (elf_z80_howto_table) / sizeof (elf_z80_howto_table[0])
  255. };
  256. unsigned int i;
  257. for (i = 0; i < table_size; i++)
  258. {
  259. if (elf_z80_howto_table[i].r_type == code)
  260. return &elf_z80_howto_table[i].howto;
  261. }
  262. printf ("%s:%d Not found BFD reloc type %d\n", __FILE__, __LINE__, code);
  263. return NULL;
  264. }
  265. static reloc_howto_type *
  266. z80_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
  267. {
  268. enum
  269. {
  270. table_size = sizeof (elf_z80_howto_table) / sizeof (elf_z80_howto_table[0])
  271. };
  272. unsigned int i;
  273. for (i = 0; i < table_size; i++)
  274. {
  275. if (elf_z80_howto_table[i].howto.name != NULL
  276. && strcasecmp (elf_z80_howto_table[i].howto.name, r_name) == 0)
  277. return &elf_z80_howto_table[i].howto;
  278. }
  279. printf ("%s:%d Not found ELF reloc name `%s'\n", __FILE__, __LINE__, r_name);
  280. return NULL;
  281. }
  282. static reloc_howto_type *
  283. z80_rtype_to_howto (bfd *abfd, unsigned r_type)
  284. {
  285. enum
  286. {
  287. table_size = sizeof (elf_z80_howto_table) / sizeof (elf_z80_howto_table[0])
  288. };
  289. unsigned int i;
  290. for (i = 0; i < table_size; i++)
  291. {
  292. if (elf_z80_howto_table[i].howto.type == r_type)
  293. return &elf_z80_howto_table[i].howto;
  294. }
  295. /* xgettext:c-format */
  296. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  297. abfd, r_type);
  298. return NULL;
  299. }
  300. /* Set the howto pointer for an z80 ELF reloc. */
  301. static bool
  302. z80_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
  303. {
  304. unsigned int r_type = ELF32_R_TYPE (dst->r_info);
  305. reloc_howto_type *howto = z80_rtype_to_howto (abfd, r_type);
  306. if (howto != NULL)
  307. {
  308. cache_ptr->howto = howto;
  309. return true;
  310. }
  311. bfd_set_error (bfd_error_bad_value);
  312. return false;
  313. }
  314. static bfd_reloc_status_type
  315. z80_elf_final_link_relocate (unsigned long r_type,
  316. bfd *input_bfd,
  317. bfd *output_bfd ATTRIBUTE_UNUSED,
  318. asection *input_section ATTRIBUTE_UNUSED,
  319. bfd_byte *contents,
  320. bfd_vma offset,
  321. bfd_vma value,
  322. bfd_vma addend,
  323. struct bfd_link_info *info ATTRIBUTE_UNUSED,
  324. asection *sym_sec ATTRIBUTE_UNUSED,
  325. int is_local ATTRIBUTE_UNUSED)
  326. {
  327. bool r;
  328. reloc_howto_type *howto;
  329. switch (r_type)
  330. {
  331. case R_Z80_16_BE:
  332. value += addend;
  333. bfd_put_8 (input_bfd, value >> 8, contents + offset + 0);
  334. bfd_put_8 (input_bfd, value >> 0, contents + offset + 1);
  335. return bfd_reloc_ok;
  336. }
  337. howto = z80_rtype_to_howto (input_bfd, r_type);
  338. if (howto == NULL)
  339. return bfd_reloc_notsupported;
  340. r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
  341. offset, value, addend);
  342. return r ? bfd_reloc_ok : bfd_reloc_notsupported;
  343. }
  344. static int
  345. z80_elf_relocate_section (bfd *output_bfd,
  346. struct bfd_link_info *info,
  347. bfd *input_bfd,
  348. asection *input_section,
  349. bfd_byte *contents,
  350. Elf_Internal_Rela *relocs,
  351. Elf_Internal_Sym *local_syms,
  352. asection **local_sections)
  353. {
  354. Elf_Internal_Shdr *symtab_hdr;
  355. struct elf_link_hash_entry **sym_hashes;
  356. Elf_Internal_Rela *rel, *relend;
  357. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  358. sym_hashes = elf_sym_hashes (input_bfd);
  359. rel = relocs;
  360. relend = relocs + input_section->reloc_count;
  361. for (; rel < relend; rel++)
  362. {
  363. unsigned int r_type;
  364. unsigned long r_symndx;
  365. Elf_Internal_Sym *sym;
  366. asection *sec;
  367. struct elf_link_hash_entry *h;
  368. bfd_vma relocation;
  369. /* This is a final link. */
  370. r_symndx = ELF32_R_SYM (rel->r_info);
  371. r_type = ELF32_R_TYPE (rel->r_info);
  372. h = NULL;
  373. sym = NULL;
  374. sec = NULL;
  375. if (r_symndx < symtab_hdr->sh_info)
  376. {
  377. sym = local_syms + r_symndx;
  378. sec = local_sections[r_symndx];
  379. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  380. }
  381. else
  382. {
  383. bool unresolved_reloc, warned, ignored;
  384. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  385. r_symndx, symtab_hdr, sym_hashes,
  386. h, sec, relocation,
  387. unresolved_reloc, warned, ignored);
  388. }
  389. if (sec != NULL && discarded_section (sec))
  390. {
  391. /* For relocs against symbols from removed linkonce sections,
  392. or sections discarded by a linker script, we just want the
  393. section contents cleared. Avoid any special processing. */
  394. reloc_howto_type *howto;
  395. howto = z80_rtype_to_howto (input_bfd, r_type);
  396. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  397. rel, 1, relend, howto, 0, contents);
  398. }
  399. if (bfd_link_relocatable (info))
  400. continue;
  401. z80_elf_final_link_relocate (r_type, input_bfd, output_bfd,
  402. input_section,
  403. contents, rel->r_offset,
  404. relocation, rel->r_addend,
  405. info, sec, h == NULL);
  406. }
  407. return true;
  408. }
  409. /* The final processing done just before writing out a Z80 ELF object
  410. file. This gets the Z80 architecture right based on the machine
  411. number. */
  412. static bool
  413. z80_elf_final_write_processing (bfd *abfd)
  414. {
  415. unsigned long val = bfd_get_mach (abfd);
  416. switch (val)
  417. {
  418. default:
  419. _bfd_error_handler (_("%pB: unsupported bfd mach %#lx"),
  420. abfd, val);
  421. /* fall through */
  422. case bfd_mach_z80:
  423. case bfd_mach_z80full:
  424. case bfd_mach_z80strict:
  425. val = EF_Z80_MACH_Z80;
  426. break;
  427. case bfd_mach_gbz80:
  428. val = EF_Z80_MACH_GBZ80;
  429. break;
  430. case bfd_mach_z80n:
  431. val = EF_Z80_MACH_Z80N;
  432. break;
  433. case bfd_mach_z180:
  434. val = EF_Z80_MACH_Z180;
  435. break;
  436. case bfd_mach_ez80_z80:
  437. val = EF_Z80_MACH_EZ80_Z80;
  438. break;
  439. case bfd_mach_ez80_adl:
  440. val = EF_Z80_MACH_EZ80_ADL;
  441. break;
  442. case bfd_mach_r800:
  443. val = EF_Z80_MACH_R800;
  444. break;
  445. }
  446. elf_elfheader (abfd)->e_machine = EM_Z80;
  447. elf_elfheader (abfd)->e_flags &= ~EF_Z80_MACH_MSK;
  448. elf_elfheader (abfd)->e_flags |= val;
  449. return _bfd_elf_final_write_processing (abfd);
  450. }
  451. /* Set the right machine number. */
  452. static bool
  453. z80_elf_object_p (bfd *abfd)
  454. {
  455. unsigned int mach;
  456. if (elf_elfheader (abfd)->e_machine == EM_Z80)
  457. {
  458. int e_mach = elf_elfheader (abfd)->e_flags & EF_Z80_MACH_MSK;
  459. switch (e_mach)
  460. {
  461. default:
  462. _bfd_error_handler (_("%pB: unsupported mach %#x"),
  463. abfd, e_mach);
  464. /* fall through */
  465. case EF_Z80_MACH_Z80:
  466. mach = bfd_mach_z80;
  467. break;
  468. case EF_Z80_MACH_GBZ80:
  469. mach = bfd_mach_gbz80;
  470. break;
  471. case EF_Z80_MACH_Z180:
  472. mach = bfd_mach_z180;
  473. break;
  474. case EF_Z80_MACH_EZ80_Z80:
  475. mach = bfd_mach_ez80_z80;
  476. break;
  477. case EF_Z80_MACH_EZ80_ADL:
  478. mach = bfd_mach_ez80_adl;
  479. break;
  480. case EF_Z80_MACH_R800:
  481. mach = bfd_mach_r800;
  482. break;
  483. case EF_Z80_MACH_Z80N:
  484. mach = bfd_mach_z80n;
  485. break;
  486. }
  487. }
  488. else
  489. {
  490. _bfd_error_handler (_("%pB: unsupported arch %#x"),
  491. abfd, elf_elfheader (abfd)->e_machine);
  492. mach = bfd_mach_z80;
  493. }
  494. return bfd_default_set_arch_mach (abfd, bfd_arch_z80, mach);
  495. }
  496. static bool
  497. z80_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
  498. const char * name)
  499. {
  500. return (name[0] == '.' && name[1] == 'L') ||
  501. _bfd_elf_is_local_label_name (abfd, name);
  502. }
  503. static bfd_reloc_status_type
  504. z80_elf_16_be_reloc (bfd *abfd,
  505. arelent *reloc_entry,
  506. asymbol *symbol,
  507. void *data,
  508. asection *input_section,
  509. bfd *output_bfd,
  510. char **error_message)
  511. {
  512. bfd_vma val;
  513. long x;
  514. bfd_size_type octets = (reloc_entry->address
  515. * OCTETS_PER_BYTE (abfd, input_section));
  516. /* If this is a relocatable link (output_bfd test tells us), just
  517. call the generic function. Any adjustment will be done at final
  518. link time. */
  519. if (output_bfd != NULL)
  520. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  521. input_section, output_bfd, error_message);
  522. /* Get symbol value. */
  523. val = 0;
  524. if (!bfd_is_com_section (symbol->section))
  525. val = symbol->value;
  526. val += symbol->section->output_offset + input_section->output_offset;
  527. if (symbol->section->output_section)
  528. val += symbol->section->output_section->vma;
  529. val += reloc_entry->addend;
  530. if (reloc_entry->howto->partial_inplace)
  531. {
  532. x = bfd_get_8 (abfd, (bfd_byte *) data + octets + 0) * 0x100;
  533. x += bfd_get_8 (abfd, (bfd_byte *) data + octets + 1);
  534. x &= ~reloc_entry->howto->src_mask;
  535. }
  536. else
  537. x = 0;
  538. x |= val & reloc_entry->howto->dst_mask;
  539. if (x < -0x8000 || x >= 0x10000)
  540. return bfd_reloc_outofrange;
  541. bfd_put_8 (abfd, x >> 8, (bfd_byte *) data + octets + 0);
  542. bfd_put_8 (abfd, x >> 0, (bfd_byte *) data + octets + 1);
  543. return bfd_reloc_ok;
  544. }
  545. #define ELF_ARCH bfd_arch_z80
  546. #define ELF_MACHINE_CODE EM_Z80
  547. #define ELF_MAXPAGESIZE 0x10000
  548. #define TARGET_LITTLE_SYM z80_elf32_vec
  549. #define TARGET_LITTLE_NAME "elf32-z80"
  550. #define elf_backend_can_refcount 1
  551. #define elf_backend_can_gc_sections 1
  552. #define elf_backend_stack_align 1
  553. #define elf_backend_rela_normal 1
  554. #define elf_info_to_howto z80_info_to_howto_rela
  555. #define elf_info_to_howto_rel z80_info_to_howto_rela
  556. #define elf_backend_final_write_processing z80_elf_final_write_processing
  557. #define elf_backend_object_p z80_elf_object_p
  558. #define elf_backend_relocate_section z80_elf_relocate_section
  559. #define bfd_elf32_bfd_reloc_type_lookup z80_reloc_type_lookup
  560. #define bfd_elf32_bfd_reloc_name_lookup z80_reloc_name_lookup
  561. #define bfd_elf32_bfd_is_local_label_name z80_is_local_label_name
  562. #include "elf32-target.h"