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