2000-04-03 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / bfd / elf32-arc.c
CommitLineData
252b5132 1/* ARC-specific support for 32-bit ELF
5f771d47 2 Copyright (C) 1994, 1995, 1997, 1999 Free Software Foundation, Inc.
252b5132
RH
3 Contributed by Doug Evans (dje@cygnus.com).
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#include "bfd.h"
22#include "sysdep.h"
23#include "libbfd.h"
24#include "elf-bfd.h"
25#include "elf/arc.h"
26
27static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
28 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
29static void arc_info_to_howto_rel
30 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
31static boolean arc_elf_object_p PARAMS ((bfd *));
32static void arc_elf_final_write_processing PARAMS ((bfd *, boolean));
33
34/* Try to minimize the amount of space occupied by relocation tables
35 on the ROM (not that the ROM won't be swamped by other ELF overhead). */
36#define USE_REL
37
38static reloc_howto_type elf_arc_howto_table[] =
39{
40 /* This reloc does nothing. */
41 HOWTO (R_ARC_NONE, /* type */
42 0, /* rightshift */
43 2, /* size (0 = byte, 1 = short, 2 = long) */
44 32, /* bitsize */
45 false, /* pc_relative */
46 0, /* bitpos */
47 complain_overflow_bitfield, /* complain_on_overflow */
48 bfd_elf_generic_reloc, /* special_function */
49 "R_ARC_NONE", /* name */
50 false, /* partial_inplace */
51 0, /* src_mask */
52 0, /* dst_mask */
53 false), /* pcrel_offset */
54
55 /* A standard 32 bit relocation. */
56 HOWTO (R_ARC_32, /* type */
57 0, /* rightshift */
58 2, /* size (0 = byte, 1 = short, 2 = long) */
59 32, /* bitsize */
60 false, /* pc_relative */
61 0, /* bitpos */
62 complain_overflow_bitfield, /* complain_on_overflow */
63 bfd_elf_generic_reloc, /* special_function */
64 "R_ARC_32", /* name */
65 false, /* partial_inplace */
66 0xffffffff, /* src_mask */
67 0xffffffff, /* dst_mask */
68 false), /* pcrel_offset */
69
70 /* A 26 bit absolute branch, right shifted by 2. */
71 HOWTO (R_ARC_B26, /* type */
72 2, /* rightshift */
73 2, /* size (0 = byte, 1 = short, 2 = long) */
74 26, /* bitsize */
75 false, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_bitfield, /* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARC_B26", /* name */
80 false, /* partial_inplace */
81 0x00ffffff, /* src_mask */
82 0x00ffffff, /* dst_mask */
83 false), /* pcrel_offset */
84
85 /* A relative 22 bit branch; bits 21-2 are stored in bits 26-7. */
86 HOWTO (R_ARC_B22_PCREL, /* type */
87 2, /* rightshift */
88 2, /* size (0 = byte, 1 = short, 2 = long) */
89 22, /* bitsize */
90 true, /* pc_relative */
91 7, /* bitpos */
92 complain_overflow_signed, /* complain_on_overflow */
93 bfd_elf_generic_reloc, /* special_function */
94 "R_ARC_B22_PCREL", /* name */
95 false, /* partial_inplace */
96 0x07ffff80, /* src_mask */
97 0x07ffff80, /* dst_mask */
98 true), /* pcrel_offset */
99
100};
101
102/* Map BFD reloc types to ARC ELF reloc types. */
103
104struct arc_reloc_map
105{
106 bfd_reloc_code_real_type bfd_reloc_val;
107 unsigned char elf_reloc_val;
108};
109
110static const struct arc_reloc_map arc_reloc_map[] =
111{
112 { BFD_RELOC_NONE, R_ARC_NONE, },
113 { BFD_RELOC_32, R_ARC_32 },
114 { BFD_RELOC_CTOR, R_ARC_32 },
115 { BFD_RELOC_ARC_B26, R_ARC_B26 },
116 { BFD_RELOC_ARC_B22_PCREL, R_ARC_B22_PCREL },
117};
118
119static reloc_howto_type *
120bfd_elf32_bfd_reloc_type_lookup (abfd, code)
5f771d47 121 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
122 bfd_reloc_code_real_type code;
123{
124 unsigned int i;
125
126 for (i = 0;
127 i < sizeof (arc_reloc_map) / sizeof (struct arc_reloc_map);
128 i++)
129 {
130 if (arc_reloc_map[i].bfd_reloc_val == code)
131 return &elf_arc_howto_table[arc_reloc_map[i].elf_reloc_val];
132 }
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)
5f771d47 141 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
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;
159 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH;
160
161 switch (arch)
162 {
163 case E_ARC_MACH_BASE:
164 mach = bfd_mach_arc_base;
165 break;
166 default:
167 /* Unknown cpu type. ??? What to do? */
168 return false;
169 }
170
171 (void) bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
172 return true;
173}
174
175/* The final processing done just before writing out an ARC ELF object file.
176 This gets the ARC architecture right based on the machine number. */
177
178static void
179arc_elf_final_write_processing (abfd, linker)
180 bfd *abfd;
5f771d47 181 boolean linker ATTRIBUTE_UNUSED;
252b5132
RH
182{
183 int mach;
184 unsigned long val;
185
186 switch (mach = bfd_get_mach (abfd))
187 {
188 case bfd_mach_arc_base:
189 val = E_ARC_MACH_BASE;
190 break;
191 default:
192 return;
193 }
194
195 elf_elfheader (abfd)->e_flags &=~ EF_ARC_MACH;
196 elf_elfheader (abfd)->e_flags |= val;
197}
198
199#define TARGET_LITTLE_SYM bfd_elf32_littlearc_vec
200#define TARGET_LITTLE_NAME "elf32-littlearc"
201#define TARGET_BIG_SYM bfd_elf32_bigarc_vec
202#define TARGET_BIG_NAME "elf32-bigarc"
203#define ELF_ARCH bfd_arch_arc
204#define ELF_MACHINE_CODE EM_CYGNUS_ARC
205#define ELF_MAXPAGESIZE 0x1000
206
207#define elf_info_to_howto 0
208#define elf_info_to_howto_rel arc_info_to_howto_rel
209#define elf_backend_object_p arc_elf_object_p
210#define elf_backend_final_write_processing \
211 arc_elf_final_write_processing
212
213#include "elf32-target.h"
This page took 0.048455 seconds and 4 git commands to generate.