elf32-i960.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Intel 960 specific support for 32-bit ELF
  2. Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "libbfd.h"
  19. #include "elf-bfd.h"
  20. #include "elf/i960.h"
  21. #define USE_REL 1
  22. #define bfd_elf32_bfd_reloc_type_lookup elf32_i960_reloc_type_lookup
  23. #define bfd_elf32_bfd_reloc_name_lookup \
  24. elf32_i960_reloc_name_lookup
  25. #define elf_info_to_howto elf32_i960_info_to_howto
  26. #define elf_info_to_howto_rel elf32_i960_info_to_howto_rel
  27. /* ELF relocs are against symbols. If we are producing relocatable
  28. output, and the reloc is against an external symbol, and nothing
  29. has given us any additional addend, the resulting reloc will also
  30. be against the same symbol. In such a case, we don't want to
  31. change anything about the way the reloc is handled, since it will
  32. all be done at final link time. Rather than put special case code
  33. into bfd_perform_relocation, all the reloc types use this howto
  34. function. It just short circuits the reloc if producing
  35. relocatable output against an external symbol. */
  36. static bfd_reloc_status_type
  37. elf32_i960_relocate (bfd *abfd ATTRIBUTE_UNUSED,
  38. arelent *reloc_entry,
  39. asymbol *symbol,
  40. void * data ATTRIBUTE_UNUSED,
  41. asection *input_section,
  42. bfd *output_bfd,
  43. char **error_message ATTRIBUTE_UNUSED)
  44. {
  45. /* HACK: I think this first condition is necessary when producing
  46. relocatable output. After the end of HACK, the code is identical
  47. to bfd_elf_generic_reloc(). I would _guess_ the first change
  48. belongs there rather than here. martindo 1998-10-23. */
  49. if (output_bfd != (bfd *) NULL
  50. && reloc_entry->howto->pc_relative
  51. && !reloc_entry->howto->pcrel_offset)
  52. reloc_entry->addend -= symbol->value;
  53. /* This is more dubious. */
  54. else if (output_bfd != (bfd *) NULL
  55. && (symbol->flags & BSF_SECTION_SYM) != 0)
  56. reloc_entry->addend -= symbol->section->output_section->vma;
  57. else
  58. {
  59. /* ...end of HACK. */
  60. if (output_bfd != (bfd *) NULL
  61. && (symbol->flags & BSF_SECTION_SYM) == 0
  62. && (! reloc_entry->howto->partial_inplace
  63. || reloc_entry->addend == 0))
  64. {
  65. reloc_entry->address += input_section->output_offset;
  66. return bfd_reloc_ok;
  67. }
  68. }
  69. return bfd_reloc_continue;
  70. }
  71. static reloc_howto_type elf_howto_table[]=
  72. {
  73. HOWTO (R_960_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
  74. elf32_i960_relocate, "R_960_NONE", TRUE,
  75. 0x00000000, 0x00000000, FALSE),
  76. EMPTY_HOWTO (1),
  77. HOWTO (R_960_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
  78. elf32_i960_relocate, "R_960_32", TRUE,
  79. 0xffffffff, 0xffffffff, FALSE),
  80. HOWTO (R_960_IP24, 0, 2, 24, TRUE, 0, complain_overflow_signed,
  81. elf32_i960_relocate, "R_960_IP24 ", TRUE,
  82. 0x00ffffff, 0x00ffffff, FALSE),
  83. EMPTY_HOWTO (4),
  84. EMPTY_HOWTO (5),
  85. EMPTY_HOWTO (6),
  86. EMPTY_HOWTO (7)
  87. };
  88. static enum elf_i960_reloc_type
  89. elf32_i960_bfd_to_reloc_type (bfd_reloc_code_real_type code)
  90. {
  91. switch (code)
  92. {
  93. default:
  94. return R_960_NONE;
  95. case BFD_RELOC_I960_CALLJ:
  96. return R_960_OPTCALL;
  97. case BFD_RELOC_32:
  98. case BFD_RELOC_CTOR:
  99. return R_960_32;
  100. case BFD_RELOC_24_PCREL:
  101. return R_960_IP24;
  102. }
  103. }
  104. static void
  105. elf32_i960_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
  106. arelent * cache_ptr ATTRIBUTE_UNUSED,
  107. Elf_Internal_Rela * dst ATTRIBUTE_UNUSED)
  108. {
  109. abort ();
  110. }
  111. static void
  112. elf32_i960_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
  113. arelent *cache_ptr,
  114. Elf_Internal_Rela *dst)
  115. {
  116. enum elf_i960_reloc_type type;
  117. type = (enum elf_i960_reloc_type) ELF32_R_TYPE (dst->r_info);
  118. /* PR 17521: file: 9609b8d6. */
  119. if (type >= R_960_max)
  120. {
  121. _bfd_error_handler (_("%B: invalid i960 reloc number: %d"), abfd, type);
  122. type = 0;
  123. }
  124. cache_ptr->howto = &elf_howto_table[(int) type];
  125. }
  126. static reloc_howto_type *
  127. elf32_i960_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  128. bfd_reloc_code_real_type code)
  129. {
  130. return elf_howto_table + elf32_i960_bfd_to_reloc_type (code);
  131. }
  132. static reloc_howto_type *
  133. elf32_i960_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  134. const char *r_name)
  135. {
  136. unsigned int i;
  137. for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++)
  138. if (elf_howto_table[i].name != NULL
  139. && strcasecmp (elf_howto_table[i].name, r_name) == 0)
  140. return &elf_howto_table[i];
  141. return NULL;
  142. }
  143. #define TARGET_LITTLE_SYM i960_elf32_vec
  144. #define TARGET_LITTLE_NAME "elf32-i960"
  145. #define ELF_ARCH bfd_arch_i960
  146. #define ELF_MACHINE_CODE EM_960
  147. #define ELF_MAXPAGESIZE 1 /* FIXME: This number is wrong, It should be the page size in bytes. */
  148. #include "elf32-target.h"