elf32-arc.c revision 85815
160107Sobrien/* ARC-specific support for 32-bit ELF 22786Ssos Copyright 1994, 1995, 1997, 1999, 2001 Free Software Foundation, Inc. 32786Ssos Contributed by Doug Evans (dje@cygnus.com). 42786Ssos 52786Ssos This file is part of BFD, the Binary File Descriptor library. 62786Ssos 732822Syokota This program is free software; you can redistribute it and/or modify 82786Ssos it under the terms of the GNU General Public License as published by 96851Ssos the Free Software Foundation; either version 2 of the License, or 102786Ssos (at your option) any later version. 112786Ssos 122786Ssos This program is distributed in the hope that it will be useful, 132786Ssos but WITHOUT ANY WARRANTY; without even the implied warranty of 142786Ssos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 152786Ssos GNU General Public License for more details. 162786Ssos 172786Ssos You should have received a copy of the GNU General Public License 1838140Syokota along with this program; if not, write to the Free Software 192786Ssos Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 207420Ssos 212786Ssos#include "bfd.h" 222786Ssos#include "sysdep.h" 232786Ssos#include "libbfd.h" 242786Ssos#include "elf-bfd.h" 252786Ssos#include "elf/arc.h" 262786Ssos 272786Ssosstatic reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup 282786Ssos PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); 292786Ssosstatic void arc_info_to_howto_rel 302786Ssos PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *)); 312786Ssosstatic boolean arc_elf_object_p 322786Ssos PARAMS ((bfd *)); 332786Ssosstatic void arc_elf_final_write_processing 342786Ssos PARAMS ((bfd *, boolean)); 352786Ssos 362786Ssos/* Try to minimize the amount of space occupied by relocation tables 372786Ssos on the ROM (not that the ROM won't be swamped by other ELF overhead). */ 382786Ssos 392786Ssos#define USE_REL 402786Ssos 412786Ssosstatic reloc_howto_type elf_arc_howto_table[] = 422786Ssos{ 432786Ssos /* This reloc does nothing. */ 442786Ssos HOWTO (R_ARC_NONE, /* type */ 452786Ssos 0, /* rightshift */ 462786Ssos 2, /* size (0 = byte, 1 = short, 2 = long) */ 472786Ssos 32, /* bitsize */ 482786Ssos false, /* pc_relative */ 492786Ssos 0, /* bitpos */ 502786Ssos complain_overflow_bitfield, /* complain_on_overflow */ 512786Ssos bfd_elf_generic_reloc, /* special_function */ 522786Ssos "R_ARC_NONE", /* name */ 532786Ssos false, /* partial_inplace */ 542786Ssos 0, /* src_mask */ 552786Ssos 0, /* dst_mask */ 562786Ssos false), /* pcrel_offset */ 572786Ssos 582786Ssos /* A standard 32 bit relocation. */ 592786Ssos HOWTO (R_ARC_32, /* type */ 602786Ssos 0, /* rightshift */ 6143334Syokota 2, /* size (0 = byte, 1 = short, 2 = long) */ 622786Ssos 32, /* bitsize */ 6332822Syokota false, /* pc_relative */ 6462420Sjoe 0, /* bitpos */ 652786Ssos complain_overflow_bitfield, /* complain_on_overflow */ 662786Ssos bfd_elf_generic_reloc, /* special_function */ 672786Ssos "R_ARC_32", /* name */ 682786Ssos false, /* partial_inplace */ 692786Ssos 0xffffffff, /* src_mask */ 702786Ssos 0xffffffff, /* dst_mask */ 712786Ssos false), /* pcrel_offset */ 722786Ssos 732786Ssos /* A 26 bit absolute branch, right shifted by 2. */ 742786Ssos HOWTO (R_ARC_B26, /* type */ 7543334Syokota 2, /* rightshift */ 7643334Syokota 2, /* size (0 = byte, 1 = short, 2 = long) */ 772786Ssos 26, /* bitsize */ 782786Ssos false, /* pc_relative */ 792786Ssos 0, /* bitpos */ 802786Ssos complain_overflow_bitfield, /* complain_on_overflow */ 812786Ssos bfd_elf_generic_reloc, /* special_function */ 825994Ssos "R_ARC_B26", /* name */ 832786Ssos false, /* partial_inplace */ 842786Ssos 0x00ffffff, /* src_mask */ 852786Ssos 0x00ffffff, /* dst_mask */ 862786Ssos false), /* pcrel_offset */ 872786Ssos 882786Ssos /* A relative 22 bit branch; bits 21-2 are stored in bits 26-7. */ 896045Ssos HOWTO (R_ARC_B22_PCREL, /* type */ 9043334Syokota 2, /* rightshift */ 912786Ssos 2, /* size (0 = byte, 1 = short, 2 = long) */ 922786Ssos 22, /* bitsize */ 932786Ssos true, /* pc_relative */ 942786Ssos 7, /* bitpos */ 9518194Ssos complain_overflow_signed, /* complain_on_overflow */ 962786Ssos bfd_elf_generic_reloc, /* special_function */ 972786Ssos "R_ARC_B22_PCREL", /* name */ 9874119Sache false, /* partial_inplace */ 992786Ssos 0x07ffff80, /* src_mask */ 1002786Ssos 0x07ffff80, /* dst_mask */ 1012786Ssos true), /* pcrel_offset */ 1022786Ssos 1032786Ssos}; 1042786Ssos 1052786Ssos/* Map BFD reloc types to ARC ELF reloc types. */ 1062786Ssos 1072786Ssosstruct arc_reloc_map 10874119Sache{ 1096851Ssos bfd_reloc_code_real_type bfd_reloc_val; 11043334Syokota unsigned char elf_reloc_val; 11143334Syokota}; 11243334Syokota 11343334Syokotastatic const struct arc_reloc_map arc_reloc_map[] = 11443334Syokota{ 115 { BFD_RELOC_NONE, R_ARC_NONE, }, 116 { BFD_RELOC_32, R_ARC_32 }, 117 { BFD_RELOC_CTOR, R_ARC_32 }, 118 { BFD_RELOC_ARC_B26, R_ARC_B26 }, 119 { BFD_RELOC_ARC_B22_PCREL, R_ARC_B22_PCREL }, 120}; 121 122static reloc_howto_type * 123bfd_elf32_bfd_reloc_type_lookup (abfd, code) 124 bfd *abfd ATTRIBUTE_UNUSED; 125 bfd_reloc_code_real_type code; 126{ 127 unsigned int i; 128 129 for (i = 0; i < sizeof (arc_reloc_map) / sizeof (struct arc_reloc_map); i++) 130 { 131 if (arc_reloc_map[i].bfd_reloc_val == code) 132 return &elf_arc_howto_table[arc_reloc_map[i].elf_reloc_val]; 133 } 134 return NULL; 135} 136 137/* Set the howto pointer for an ARC ELF reloc. */ 138 139static void 140arc_info_to_howto_rel (abfd, cache_ptr, dst) 141 bfd *abfd ATTRIBUTE_UNUSED; 142 arelent *cache_ptr; 143 Elf32_Internal_Rel *dst; 144{ 145 unsigned int r_type; 146 147 r_type = ELF32_R_TYPE (dst->r_info); 148 BFD_ASSERT (r_type < (unsigned int) R_ARC_max); 149 cache_ptr->howto = &elf_arc_howto_table[r_type]; 150} 151 152/* Set the right machine number for an ARC ELF file. */ 153 154static boolean 155arc_elf_object_p (abfd) 156 bfd *abfd; 157{ 158 int mach = bfd_mach_arc_6; 159 160 if (elf_elfheader(abfd)->e_machine == EM_ARC) 161 { 162 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH; 163 164 switch (arch) 165 { 166 case E_ARC_MACH_ARC5: 167 mach = bfd_mach_arc_5; 168 break; 169 default: 170 case E_ARC_MACH_ARC6: 171 mach = bfd_mach_arc_6; 172 break; 173 case E_ARC_MACH_ARC7: 174 mach = bfd_mach_arc_7; 175 break; 176 case E_ARC_MACH_ARC8: 177 mach = bfd_mach_arc_8; 178 break; 179 } 180 } 181 return bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach); 182} 183 184/* The final processing done just before writing out an ARC ELF object file. 185 This gets the ARC architecture right based on the machine number. */ 186 187static void 188arc_elf_final_write_processing (abfd, linker) 189 bfd *abfd; 190 boolean linker ATTRIBUTE_UNUSED; 191{ 192 unsigned long val; 193 194 switch (bfd_get_mach (abfd)) 195 { 196 case bfd_mach_arc_5: 197 val = E_ARC_MACH_ARC5; 198 break; 199 default: 200 case bfd_mach_arc_6: 201 val = E_ARC_MACH_ARC6; 202 break; 203 case bfd_mach_arc_7: 204 val = E_ARC_MACH_ARC7; 205 break; 206 case bfd_mach_arc_8: 207 val = E_ARC_MACH_ARC8; 208 break; 209 } 210 elf_elfheader (abfd)->e_machine = EM_ARC; 211 elf_elfheader (abfd)->e_flags &=~ EF_ARC_MACH; 212 elf_elfheader (abfd)->e_flags |= val; 213} 214 215#define TARGET_LITTLE_SYM bfd_elf32_littlearc_vec 216#define TARGET_LITTLE_NAME "elf32-littlearc" 217#define TARGET_BIG_SYM bfd_elf32_bigarc_vec 218#define TARGET_BIG_NAME "elf32-bigarc" 219#define ELF_ARCH bfd_arch_arc 220#define ELF_MACHINE_CODE EM_ARC 221#define ELF_MAXPAGESIZE 0x1000 222 223#define elf_info_to_howto 0 224#define elf_info_to_howto_rel arc_info_to_howto_rel 225#define elf_backend_object_p arc_elf_object_p 226#define elf_backend_final_write_processing arc_elf_final_write_processing 227 228#include "elf32-target.h" 229