daily update
[deliverable/binutils-gdb.git] / bfd / elf32-arc.c
CommitLineData
252b5132 1/* ARC-specific support for 32-bit ELF
7898deda 2 Copyright 1994, 1995, 1997, 1999, 2001 Free Software Foundation, Inc.
252b5132
RH
3 Contributed by Doug Evans (dje@cygnus.com).
4
0d2bcfaf 5 This file is part of BFD, the Binary File Descriptor library.
252b5132 6
0d2bcfaf
NC
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
252b5132 11
0d2bcfaf
NC
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
252b5132 16
0d2bcfaf
NC
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
252b5132
RH
20
21#include "bfd.h"
22#include "sysdep.h"
23#include "libbfd.h"
24#include "elf-bfd.h"
25#include "elf/arc.h"
ea04a8f6 26#include "libiberty.h"
252b5132
RH
27
28static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
0d2bcfaf 29 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
252b5132
RH
30static void arc_info_to_howto_rel
31 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
0d2bcfaf
NC
32static boolean arc_elf_object_p
33 PARAMS ((bfd *));
34static void arc_elf_final_write_processing
35 PARAMS ((bfd *, boolean));
ea04a8f6
NC
36static bfd_reloc_status_type arc_elf_b22_pcrel
37 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
252b5132
RH
38
39/* Try to minimize the amount of space occupied by relocation tables
40 on the ROM (not that the ROM won't be swamped by other ELF overhead). */
0d2bcfaf 41
252b5132
RH
42#define USE_REL
43
44static reloc_howto_type elf_arc_howto_table[] =
45{
46 /* This reloc does nothing. */
0d2bcfaf
NC
47 HOWTO (R_ARC_NONE, /* type */
48 0, /* rightshift */
49 2, /* size (0 = byte, 1 = short, 2 = long) */
50 32, /* bitsize */
51 false, /* pc_relative */
52 0, /* bitpos */
53 complain_overflow_bitfield, /* complain_on_overflow */
54 bfd_elf_generic_reloc, /* special_function */
55 "R_ARC_NONE", /* name */
fb9ceeac 56 true, /* partial_inplace */
0d2bcfaf
NC
57 0, /* src_mask */
58 0, /* dst_mask */
59 false), /* pcrel_offset */
252b5132
RH
60
61 /* A standard 32 bit relocation. */
0d2bcfaf 62 HOWTO (R_ARC_32, /* type */
bcee8eb8
AM
63 0, /* rightshift */
64 2, /* size (0 = byte, 1 = short, 2 = long) */
65 32, /* bitsize */
66 false, /* pc_relative */
67 0, /* bitpos */
0d2bcfaf 68 complain_overflow_bitfield, /* complain_on_overflow */
bcee8eb8 69 bfd_elf_generic_reloc, /* special_function */
0d2bcfaf 70 "R_ARC_32", /* name */
fb9ceeac 71 true, /* partial_inplace */
bcee8eb8
AM
72 0xffffffff, /* src_mask */
73 0xffffffff, /* dst_mask */
74 false), /* pcrel_offset */
252b5132
RH
75
76 /* A 26 bit absolute branch, right shifted by 2. */
0d2bcfaf
NC
77 HOWTO (R_ARC_B26, /* type */
78 2, /* rightshift */
79 2, /* size (0 = byte, 1 = short, 2 = long) */
80 26, /* bitsize */
81 false, /* pc_relative */
82 0, /* bitpos */
83 complain_overflow_bitfield, /* complain_on_overflow */
84 bfd_elf_generic_reloc, /* special_function */
85 "R_ARC_B26", /* name */
fb9ceeac 86 true, /* partial_inplace */
0d2bcfaf
NC
87 0x00ffffff, /* src_mask */
88 0x00ffffff, /* dst_mask */
89 false), /* pcrel_offset */
252b5132
RH
90
91 /* A relative 22 bit branch; bits 21-2 are stored in bits 26-7. */
0d2bcfaf
NC
92 HOWTO (R_ARC_B22_PCREL, /* type */
93 2, /* rightshift */
94 2, /* size (0 = byte, 1 = short, 2 = long) */
95 22, /* bitsize */
96 true, /* pc_relative */
97 7, /* bitpos */
98 complain_overflow_signed, /* complain_on_overflow */
ea04a8f6 99 arc_elf_b22_pcrel, /* special_function */
0d2bcfaf 100 "R_ARC_B22_PCREL", /* name */
1c26dc27 101 true, /* partial_inplace */
0d2bcfaf
NC
102 0x07ffff80, /* src_mask */
103 0x07ffff80, /* dst_mask */
1c26dc27 104 false), /* pcrel_offset */
252b5132
RH
105};
106
107/* Map BFD reloc types to ARC ELF reloc types. */
108
109struct arc_reloc_map
110{
111 bfd_reloc_code_real_type bfd_reloc_val;
112 unsigned char elf_reloc_val;
113};
114
115static const struct arc_reloc_map arc_reloc_map[] =
116{
117 { BFD_RELOC_NONE, R_ARC_NONE, },
118 { BFD_RELOC_32, R_ARC_32 },
119 { BFD_RELOC_CTOR, R_ARC_32 },
120 { BFD_RELOC_ARC_B26, R_ARC_B26 },
121 { BFD_RELOC_ARC_B22_PCREL, R_ARC_B22_PCREL },
122};
123
124static reloc_howto_type *
125bfd_elf32_bfd_reloc_type_lookup (abfd, code)
5f771d47 126 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
127 bfd_reloc_code_real_type code;
128{
129 unsigned int i;
130
ea04a8f6
NC
131 for (i = ARRAY_SIZE (arc_reloc_map); i--;)
132 if (arc_reloc_map[i].bfd_reloc_val == code)
133 return elf_arc_howto_table + arc_reloc_map[i].elf_reloc_val;
134
252b5132
RH
135 return NULL;
136}
137
138/* Set the howto pointer for an ARC ELF reloc. */
139
140static void
141arc_info_to_howto_rel (abfd, cache_ptr, dst)
5f771d47 142 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
143 arelent *cache_ptr;
144 Elf32_Internal_Rel *dst;
145{
146 unsigned int r_type;
147
148 r_type = ELF32_R_TYPE (dst->r_info);
149 BFD_ASSERT (r_type < (unsigned int) R_ARC_max);
150 cache_ptr->howto = &elf_arc_howto_table[r_type];
151}
152
153/* Set the right machine number for an ARC ELF file. */
154
155static boolean
156arc_elf_object_p (abfd)
157 bfd *abfd;
158{
dc810e39 159 unsigned int mach = bfd_mach_arc_6;
252b5132 160
0d2bcfaf 161 if (elf_elfheader(abfd)->e_machine == EM_ARC)
252b5132 162 {
0d2bcfaf
NC
163 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH;
164
165 switch (arch)
166 {
0d2bcfaf
NC
167 case E_ARC_MACH_ARC5:
168 mach = bfd_mach_arc_5;
169 break;
bcee8eb8 170 default:
0d2bcfaf
NC
171 case E_ARC_MACH_ARC6:
172 mach = bfd_mach_arc_6;
173 break;
174 case E_ARC_MACH_ARC7:
175 mach = bfd_mach_arc_7;
176 break;
177 case E_ARC_MACH_ARC8:
178 mach = bfd_mach_arc_8;
179 break;
180 }
252b5132 181 }
0d2bcfaf 182 return bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
252b5132
RH
183}
184
185/* The final processing done just before writing out an ARC ELF object file.
186 This gets the ARC architecture right based on the machine number. */
187
188static void
189arc_elf_final_write_processing (abfd, linker)
190 bfd *abfd;
5f771d47 191 boolean linker ATTRIBUTE_UNUSED;
252b5132 192{
252b5132
RH
193 unsigned long val;
194
0d2bcfaf 195 switch (bfd_get_mach (abfd))
252b5132 196 {
0d2bcfaf
NC
197 case bfd_mach_arc_5:
198 val = E_ARC_MACH_ARC5;
199 break;
bcee8eb8 200 default:
0d2bcfaf
NC
201 case bfd_mach_arc_6:
202 val = E_ARC_MACH_ARC6;
203 break;
204 case bfd_mach_arc_7:
205 val = E_ARC_MACH_ARC7;
206 break;
207 case bfd_mach_arc_8:
208 val = E_ARC_MACH_ARC8;
209 break;
252b5132 210 }
252b5132
RH
211 elf_elfheader (abfd)->e_flags &=~ EF_ARC_MACH;
212 elf_elfheader (abfd)->e_flags |= val;
213}
214
ea04a8f6
NC
215bfd_reloc_status_type
216arc_elf_b22_pcrel (abfd, reloc_entry, symbol, data, input_section,
217 output_bfd, error_message)
218 bfd * abfd;
219 arelent * reloc_entry;
220 asymbol * symbol;
221 PTR data;
222 asection * input_section;
223 bfd * output_bfd;
224 char ** error_message;
225{
226 /* If linking, back up the final symbol address by the address of the
227 reloc. This cannot be accomplished by setting the pcrel_offset
228 field to true, as bfd_install_relocation will detect this and refuse
229 to install the offset in the first place, but bfd_perform_relocation
230 will still insist on removing it. */
231 if (output_bfd == (bfd *) NULL)
232 reloc_entry->addend -= reloc_entry->address;
233
234 /* Fall through to the default elf reloc handler. */
235 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
236 input_section, output_bfd, error_message);
237}
cedb70c5 238
0d2bcfaf
NC
239#define TARGET_LITTLE_SYM bfd_elf32_littlearc_vec
240#define TARGET_LITTLE_NAME "elf32-littlearc"
241#define TARGET_BIG_SYM bfd_elf32_bigarc_vec
242#define TARGET_BIG_NAME "elf32-bigarc"
243#define ELF_ARCH bfd_arch_arc
244#define ELF_MACHINE_CODE EM_ARC
245#define ELF_MAXPAGESIZE 0x1000
246
247#define elf_info_to_howto 0
248#define elf_info_to_howto_rel arc_info_to_howto_rel
249#define elf_backend_object_p arc_elf_object_p
250#define elf_backend_final_write_processing arc_elf_final_write_processing
252b5132
RH
251
252#include "elf32-target.h"
This page took 0.152711 seconds and 4 git commands to generate.