1*3d8817e4Smiod /* OR32-specific support for 32-bit ELF
2*3d8817e4Smiod Copyright 2002, 2004, 2005 Free Software Foundation, Inc.
3*3d8817e4Smiod Contributed by Ivan Guzvinec <ivang@opencores.org>
4*3d8817e4Smiod
5*3d8817e4Smiod This file is part of BFD, the Binary File Descriptor library.
6*3d8817e4Smiod
7*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
8*3d8817e4Smiod it under the terms of the GNU General Public License as published by
9*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
10*3d8817e4Smiod (at your option) any later version.
11*3d8817e4Smiod
12*3d8817e4Smiod This program is distributed in the hope that it will be useful,
13*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
14*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*3d8817e4Smiod GNU General Public License for more details.
16*3d8817e4Smiod
17*3d8817e4Smiod You should have received a copy of the GNU General Public License
18*3d8817e4Smiod along with this program; if not, write to the Free Software
19*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20*3d8817e4Smiod
21*3d8817e4Smiod #include "bfd.h"
22*3d8817e4Smiod #include "sysdep.h"
23*3d8817e4Smiod #include "libbfd.h"
24*3d8817e4Smiod #include "elf-bfd.h"
25*3d8817e4Smiod #include "elf/or32.h"
26*3d8817e4Smiod #include "libiberty.h"
27*3d8817e4Smiod
28*3d8817e4Smiod /* Try to minimize the amount of space occupied by relocation tables
29*3d8817e4Smiod on the ROM (not that the ROM won't be swamped by other ELF overhead). */
30*3d8817e4Smiod #define USE_REL 1
31*3d8817e4Smiod
32*3d8817e4Smiod /* Set the right machine number for an OR32 ELF file. */
33*3d8817e4Smiod
34*3d8817e4Smiod static bfd_boolean
or32_elf_object_p(bfd * abfd)35*3d8817e4Smiod or32_elf_object_p (bfd *abfd)
36*3d8817e4Smiod {
37*3d8817e4Smiod (void) bfd_default_set_arch_mach (abfd, bfd_arch_or32, 0);
38*3d8817e4Smiod return TRUE;
39*3d8817e4Smiod }
40*3d8817e4Smiod
41*3d8817e4Smiod /* The final processing done just before writing out an OR32 ELF object file.
42*3d8817e4Smiod This gets the OR32 architecture right based on the machine number. */
43*3d8817e4Smiod
44*3d8817e4Smiod static void
or32_elf_final_write_processing(bfd * abfd,bfd_boolean linker ATTRIBUTE_UNUSED)45*3d8817e4Smiod or32_elf_final_write_processing (bfd *abfd,
46*3d8817e4Smiod bfd_boolean linker ATTRIBUTE_UNUSED)
47*3d8817e4Smiod {
48*3d8817e4Smiod elf_elfheader (abfd)->e_flags &=~ EF_OR32_MACH;
49*3d8817e4Smiod }
50*3d8817e4Smiod
51*3d8817e4Smiod static bfd_reloc_status_type
or32_elf_32_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)52*3d8817e4Smiod or32_elf_32_reloc (bfd *abfd,
53*3d8817e4Smiod arelent *reloc_entry,
54*3d8817e4Smiod asymbol *symbol,
55*3d8817e4Smiod void * data,
56*3d8817e4Smiod asection *input_section,
57*3d8817e4Smiod bfd *output_bfd,
58*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
59*3d8817e4Smiod {
60*3d8817e4Smiod if (output_bfd != NULL)
61*3d8817e4Smiod {
62*3d8817e4Smiod unsigned long insn;
63*3d8817e4Smiod bfd_size_type addr = reloc_entry->address;
64*3d8817e4Smiod
65*3d8817e4Smiod reloc_entry->address += input_section->output_offset;
66*3d8817e4Smiod
67*3d8817e4Smiod insn = bfd_get_32 (abfd, (bfd_byte *) data + addr);
68*3d8817e4Smiod insn += symbol->section->output_section->vma;
69*3d8817e4Smiod insn += symbol->section->output_offset;
70*3d8817e4Smiod insn += symbol->value;
71*3d8817e4Smiod bfd_put_32 (abfd, insn, (bfd_byte *) data + addr);
72*3d8817e4Smiod
73*3d8817e4Smiod return bfd_reloc_ok;
74*3d8817e4Smiod }
75*3d8817e4Smiod
76*3d8817e4Smiod return bfd_reloc_continue;
77*3d8817e4Smiod }
78*3d8817e4Smiod
79*3d8817e4Smiod static bfd_reloc_status_type
or32_elf_16_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)80*3d8817e4Smiod or32_elf_16_reloc (bfd *abfd,
81*3d8817e4Smiod arelent *reloc_entry,
82*3d8817e4Smiod asymbol *symbol,
83*3d8817e4Smiod void * data,
84*3d8817e4Smiod asection *input_section,
85*3d8817e4Smiod bfd *output_bfd,
86*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
87*3d8817e4Smiod {
88*3d8817e4Smiod if (output_bfd != NULL)
89*3d8817e4Smiod {
90*3d8817e4Smiod unsigned short insn;
91*3d8817e4Smiod bfd_size_type addr = reloc_entry->address;
92*3d8817e4Smiod
93*3d8817e4Smiod reloc_entry->address += input_section->output_offset;
94*3d8817e4Smiod
95*3d8817e4Smiod insn = bfd_get_16 (abfd, (bfd_byte *) data + addr);
96*3d8817e4Smiod insn += symbol->section->output_section->vma;
97*3d8817e4Smiod insn += symbol->section->output_offset;
98*3d8817e4Smiod insn += symbol->value;
99*3d8817e4Smiod bfd_put_16 (abfd, insn, (bfd_byte *) data + addr);
100*3d8817e4Smiod
101*3d8817e4Smiod return bfd_reloc_ok;
102*3d8817e4Smiod }
103*3d8817e4Smiod
104*3d8817e4Smiod return bfd_reloc_continue;
105*3d8817e4Smiod }
106*3d8817e4Smiod
107*3d8817e4Smiod static bfd_reloc_status_type
or32_elf_8_reloc(bfd * abfd ATTRIBUTE_UNUSED,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)108*3d8817e4Smiod or32_elf_8_reloc (bfd *abfd ATTRIBUTE_UNUSED,
109*3d8817e4Smiod arelent *reloc_entry,
110*3d8817e4Smiod asymbol *symbol,
111*3d8817e4Smiod void * data,
112*3d8817e4Smiod asection *input_section,
113*3d8817e4Smiod bfd *output_bfd,
114*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
115*3d8817e4Smiod {
116*3d8817e4Smiod if (output_bfd != NULL)
117*3d8817e4Smiod {
118*3d8817e4Smiod unsigned char insn;
119*3d8817e4Smiod bfd_size_type addr = reloc_entry->address;
120*3d8817e4Smiod
121*3d8817e4Smiod reloc_entry->address += input_section->output_offset;
122*3d8817e4Smiod
123*3d8817e4Smiod insn = bfd_get_8 (abfd, (bfd_byte *) data + addr);
124*3d8817e4Smiod insn += symbol->section->output_section->vma;
125*3d8817e4Smiod insn += symbol->section->output_offset;
126*3d8817e4Smiod insn += symbol->value;
127*3d8817e4Smiod bfd_put_8 (abfd, insn, (bfd_byte *) data + addr);
128*3d8817e4Smiod
129*3d8817e4Smiod return bfd_reloc_ok;
130*3d8817e4Smiod }
131*3d8817e4Smiod
132*3d8817e4Smiod return bfd_reloc_continue;
133*3d8817e4Smiod }
134*3d8817e4Smiod
135*3d8817e4Smiod /* Do a R_OR32_CONSTH relocation. This has to be done in combination
136*3d8817e4Smiod with a R_OR32_CONST reloc, because there is a carry from the LO16 to
137*3d8817e4Smiod the HI16. Here we just save the information we need; we do the
138*3d8817e4Smiod actual relocation when we see the LO16. OR32 ELF requires that the
139*3d8817e4Smiod LO16 immediately follow the HI16. As a GNU extension, we permit an
140*3d8817e4Smiod arbitrary number of HI16 relocs to be associated with a single LO16
141*3d8817e4Smiod reloc. This extension permits gcc to output the HI and LO relocs
142*3d8817e4Smiod itself. This code is copied from the elf32-mips.c. */
143*3d8817e4Smiod
144*3d8817e4Smiod struct or32_consth
145*3d8817e4Smiod {
146*3d8817e4Smiod struct or32_consth *next;
147*3d8817e4Smiod bfd_byte *addr;
148*3d8817e4Smiod bfd_vma addend;
149*3d8817e4Smiod };
150*3d8817e4Smiod
151*3d8817e4Smiod /* FIXME: This should not be a static variable. */
152*3d8817e4Smiod
153*3d8817e4Smiod static struct or32_consth *or32_consth_list;
154*3d8817e4Smiod
155*3d8817e4Smiod static bfd_reloc_status_type
or32_elf_consth_reloc(bfd * abfd ATTRIBUTE_UNUSED,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)156*3d8817e4Smiod or32_elf_consth_reloc (bfd *abfd ATTRIBUTE_UNUSED,
157*3d8817e4Smiod arelent *reloc_entry,
158*3d8817e4Smiod asymbol *symbol,
159*3d8817e4Smiod void * data,
160*3d8817e4Smiod asection *input_section,
161*3d8817e4Smiod bfd *output_bfd,
162*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
163*3d8817e4Smiod {
164*3d8817e4Smiod bfd_reloc_status_type ret;
165*3d8817e4Smiod bfd_vma relocation;
166*3d8817e4Smiod struct or32_consth *n;
167*3d8817e4Smiod
168*3d8817e4Smiod ret = bfd_reloc_ok;
169*3d8817e4Smiod
170*3d8817e4Smiod if (bfd_is_und_section (symbol->section)
171*3d8817e4Smiod && output_bfd == NULL)
172*3d8817e4Smiod ret = bfd_reloc_undefined;
173*3d8817e4Smiod
174*3d8817e4Smiod if (bfd_is_com_section (symbol->section))
175*3d8817e4Smiod relocation = 0;
176*3d8817e4Smiod else
177*3d8817e4Smiod relocation = symbol->value;
178*3d8817e4Smiod
179*3d8817e4Smiod relocation += symbol->section->output_section->vma;
180*3d8817e4Smiod relocation += symbol->section->output_offset;
181*3d8817e4Smiod relocation += reloc_entry->addend;
182*3d8817e4Smiod
183*3d8817e4Smiod if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
184*3d8817e4Smiod return bfd_reloc_outofrange;
185*3d8817e4Smiod
186*3d8817e4Smiod /* Save the information, and let LO16 do the actual relocation. */
187*3d8817e4Smiod n = bfd_malloc (sizeof *n);
188*3d8817e4Smiod if (n == NULL)
189*3d8817e4Smiod return bfd_reloc_outofrange;
190*3d8817e4Smiod n->addr = (bfd_byte *) data + reloc_entry->address;
191*3d8817e4Smiod n->addend = relocation;
192*3d8817e4Smiod n->next = or32_consth_list;
193*3d8817e4Smiod or32_consth_list = n;
194*3d8817e4Smiod
195*3d8817e4Smiod if (output_bfd != NULL)
196*3d8817e4Smiod reloc_entry->address += input_section->output_offset;
197*3d8817e4Smiod
198*3d8817e4Smiod return ret;
199*3d8817e4Smiod }
200*3d8817e4Smiod
201*3d8817e4Smiod /* Do a R_OR32_CONST relocation. This is a straightforward 16 bit
202*3d8817e4Smiod inplace relocation; this function exists in order to do the
203*3d8817e4Smiod R_OR32_CONSTH relocation described above. */
204*3d8817e4Smiod
205*3d8817e4Smiod static bfd_reloc_status_type
or32_elf_const_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)206*3d8817e4Smiod or32_elf_const_reloc (bfd *abfd,
207*3d8817e4Smiod arelent *reloc_entry,
208*3d8817e4Smiod asymbol *symbol,
209*3d8817e4Smiod void * data,
210*3d8817e4Smiod asection *input_section,
211*3d8817e4Smiod bfd *output_bfd,
212*3d8817e4Smiod char **error_message)
213*3d8817e4Smiod {
214*3d8817e4Smiod if (or32_consth_list != NULL)
215*3d8817e4Smiod {
216*3d8817e4Smiod struct or32_consth *l;
217*3d8817e4Smiod
218*3d8817e4Smiod l = or32_consth_list;
219*3d8817e4Smiod while (l != NULL)
220*3d8817e4Smiod {
221*3d8817e4Smiod unsigned long insn;
222*3d8817e4Smiod unsigned long val;
223*3d8817e4Smiod unsigned long vallo;
224*3d8817e4Smiod struct or32_consth *next;
225*3d8817e4Smiod
226*3d8817e4Smiod /* Do the HI16 relocation. Note that we actually don't need
227*3d8817e4Smiod to know anything about the LO16 itself, except where to
228*3d8817e4Smiod find the low 16 bits of the addend needed by the LO16. */
229*3d8817e4Smiod insn = bfd_get_32 (abfd, l->addr);
230*3d8817e4Smiod vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
231*3d8817e4Smiod & 0xffff);
232*3d8817e4Smiod val = ((insn & 0xffff) << 16) + vallo;
233*3d8817e4Smiod val += l->addend;
234*3d8817e4Smiod
235*3d8817e4Smiod insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
236*3d8817e4Smiod bfd_put_32 (abfd, insn, l->addr);
237*3d8817e4Smiod
238*3d8817e4Smiod next = l->next;
239*3d8817e4Smiod free (l);
240*3d8817e4Smiod l = next;
241*3d8817e4Smiod }
242*3d8817e4Smiod
243*3d8817e4Smiod or32_consth_list = NULL;
244*3d8817e4Smiod }
245*3d8817e4Smiod
246*3d8817e4Smiod if (output_bfd != NULL)
247*3d8817e4Smiod {
248*3d8817e4Smiod unsigned long insn, tmp;
249*3d8817e4Smiod bfd_size_type addr = reloc_entry->address;
250*3d8817e4Smiod
251*3d8817e4Smiod reloc_entry->address += input_section->output_offset;
252*3d8817e4Smiod
253*3d8817e4Smiod insn = bfd_get_32 (abfd, (bfd_byte *) data + addr);
254*3d8817e4Smiod tmp = insn & 0x0000ffff;
255*3d8817e4Smiod tmp += symbol->section->output_section->vma;
256*3d8817e4Smiod tmp += symbol->section->output_offset;
257*3d8817e4Smiod tmp += symbol->value;
258*3d8817e4Smiod insn = (insn & 0xffff0000) | (tmp & 0x0000ffff);
259*3d8817e4Smiod bfd_put_32 (abfd, insn, (bfd_byte *) data + addr);
260*3d8817e4Smiod
261*3d8817e4Smiod return bfd_reloc_ok;
262*3d8817e4Smiod }
263*3d8817e4Smiod
264*3d8817e4Smiod /* Now do the LO16 reloc in the usual way. */
265*3d8817e4Smiod return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
266*3d8817e4Smiod input_section, output_bfd, error_message);
267*3d8817e4Smiod }
268*3d8817e4Smiod
269*3d8817e4Smiod static bfd_reloc_status_type
or32_elf_jumptarg_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol ATTRIBUTE_UNUSED,void * data,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)270*3d8817e4Smiod or32_elf_jumptarg_reloc (bfd *abfd,
271*3d8817e4Smiod arelent *reloc_entry,
272*3d8817e4Smiod asymbol *symbol ATTRIBUTE_UNUSED,
273*3d8817e4Smiod void * data,
274*3d8817e4Smiod asection *input_section,
275*3d8817e4Smiod bfd *output_bfd,
276*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
277*3d8817e4Smiod {
278*3d8817e4Smiod if (output_bfd != NULL)
279*3d8817e4Smiod {
280*3d8817e4Smiod unsigned long insn, tmp;
281*3d8817e4Smiod bfd_size_type addr = reloc_entry->address;
282*3d8817e4Smiod
283*3d8817e4Smiod reloc_entry->address += input_section->output_offset;
284*3d8817e4Smiod
285*3d8817e4Smiod insn = bfd_get_32 (abfd, (bfd_byte *) data + addr);
286*3d8817e4Smiod tmp = insn | 0xfc000000;
287*3d8817e4Smiod tmp -= (input_section->output_offset >> 2);
288*3d8817e4Smiod insn = (insn & 0xfc000000) | (tmp & 0x03ffffff);
289*3d8817e4Smiod bfd_put_32 (abfd, insn, (bfd_byte *) data + addr);
290*3d8817e4Smiod
291*3d8817e4Smiod return bfd_reloc_ok;
292*3d8817e4Smiod }
293*3d8817e4Smiod
294*3d8817e4Smiod return bfd_reloc_continue;
295*3d8817e4Smiod }
296*3d8817e4Smiod
297*3d8817e4Smiod static reloc_howto_type elf_or32_howto_table[] =
298*3d8817e4Smiod {
299*3d8817e4Smiod /* This reloc does nothing. */
300*3d8817e4Smiod HOWTO (R_OR32_NONE, /* type */
301*3d8817e4Smiod 0, /* rightshift */
302*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
303*3d8817e4Smiod 32, /* bitsize */
304*3d8817e4Smiod FALSE, /* pc_relative */
305*3d8817e4Smiod 0, /* bitpos */
306*3d8817e4Smiod complain_overflow_bitfield, /* complain_on_overflow */
307*3d8817e4Smiod bfd_elf_generic_reloc, /* special_function */
308*3d8817e4Smiod "R_OR32_NONE", /* name */
309*3d8817e4Smiod FALSE, /* partial_inplace */
310*3d8817e4Smiod 0, /* src_mask */
311*3d8817e4Smiod 0, /* dst_mask */
312*3d8817e4Smiod FALSE), /* pcrel_offset */
313*3d8817e4Smiod
314*3d8817e4Smiod /* A standard 32 bit relocation. */
315*3d8817e4Smiod HOWTO (R_OR32_32, /* type */
316*3d8817e4Smiod 0, /* rightshift */
317*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
318*3d8817e4Smiod 32, /* bitsize */
319*3d8817e4Smiod FALSE, /* pc_relative */
320*3d8817e4Smiod 0, /* bitpos */
321*3d8817e4Smiod complain_overflow_bitfield, /* complain_on_overflow */
322*3d8817e4Smiod or32_elf_32_reloc, /* special_function */
323*3d8817e4Smiod "R_OR32_32", /* name */
324*3d8817e4Smiod FALSE, /* partial_inplace */
325*3d8817e4Smiod 0xffffffff, /* src_mask */
326*3d8817e4Smiod 0xffffffff, /* dst_mask */
327*3d8817e4Smiod FALSE), /* pcrel_offset */
328*3d8817e4Smiod
329*3d8817e4Smiod /* A standard 16 bit relocation. */
330*3d8817e4Smiod HOWTO (R_OR32_16, /* type */
331*3d8817e4Smiod 0, /* rightshift */
332*3d8817e4Smiod 1, /* size (0 = byte, 1 = short, 2 = long) */
333*3d8817e4Smiod 16, /* bitsize */
334*3d8817e4Smiod FALSE, /* pc_relative */
335*3d8817e4Smiod 0, /* bitpos */
336*3d8817e4Smiod complain_overflow_bitfield, /* complain_on_overflow */
337*3d8817e4Smiod or32_elf_16_reloc, /* special_function */
338*3d8817e4Smiod "R_OR32_16", /* name */
339*3d8817e4Smiod FALSE, /* partial_inplace */
340*3d8817e4Smiod 0x0000ffff, /* src_mask */
341*3d8817e4Smiod 0x0000ffff, /* dst_mask */
342*3d8817e4Smiod FALSE), /* pcrel_offset */
343*3d8817e4Smiod
344*3d8817e4Smiod /* A standard 8 bit relocation. */
345*3d8817e4Smiod HOWTO (R_OR32_8, /* type */
346*3d8817e4Smiod 0, /* rightshift */
347*3d8817e4Smiod 0, /* size (0 = byte, 1 = short, 2 = long) */
348*3d8817e4Smiod 8, /* bitsize */
349*3d8817e4Smiod FALSE, /* pc_relative */
350*3d8817e4Smiod 0, /* bitpos */
351*3d8817e4Smiod complain_overflow_bitfield, /* complain_on_overflow */
352*3d8817e4Smiod or32_elf_8_reloc, /* special_function */
353*3d8817e4Smiod "R_OR32_8", /* name */
354*3d8817e4Smiod FALSE, /* partial_inplace */
355*3d8817e4Smiod 0x000000ff, /* src_mask */
356*3d8817e4Smiod 0x000000ff, /* dst_mask */
357*3d8817e4Smiod FALSE), /* pcrel_offset */
358*3d8817e4Smiod
359*3d8817e4Smiod /* A standard low 16 bit relocation. */
360*3d8817e4Smiod HOWTO (R_OR32_CONST, /* type */
361*3d8817e4Smiod 0, /* rightshift */
362*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
363*3d8817e4Smiod 16, /* bitsize */
364*3d8817e4Smiod FALSE, /* pc_relative */
365*3d8817e4Smiod 0, /* bitpos */
366*3d8817e4Smiod complain_overflow_dont, /* complain_on_overflow */
367*3d8817e4Smiod or32_elf_const_reloc, /* special_function */
368*3d8817e4Smiod "R_OR32_CONST", /* name */
369*3d8817e4Smiod FALSE, /* partial_inplace */
370*3d8817e4Smiod 0x0000ffff, /* src_mask */
371*3d8817e4Smiod 0x0000ffff, /* dst_mask */
372*3d8817e4Smiod FALSE), /* pcrel_offset */
373*3d8817e4Smiod
374*3d8817e4Smiod /* A standard high 16 bit relocation. */
375*3d8817e4Smiod HOWTO (R_OR32_CONSTH, /* type */
376*3d8817e4Smiod 16, /* rightshift */
377*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
378*3d8817e4Smiod 16, /* bitsize */
379*3d8817e4Smiod TRUE, /* pc_relative */
380*3d8817e4Smiod 0, /* bitpos */
381*3d8817e4Smiod complain_overflow_dont, /* complain_on_overflow */
382*3d8817e4Smiod or32_elf_consth_reloc, /* special_function */
383*3d8817e4Smiod "R_OR32_CONSTH", /* name */
384*3d8817e4Smiod FALSE, /* partial_inplace */
385*3d8817e4Smiod 0xffff0000, /* src_mask */
386*3d8817e4Smiod 0x0000ffff, /* dst_mask */
387*3d8817e4Smiod FALSE), /* pcrel_offset */
388*3d8817e4Smiod
389*3d8817e4Smiod /* A standard branch relocation. */
390*3d8817e4Smiod HOWTO (R_OR32_JUMPTARG, /* type */
391*3d8817e4Smiod 2, /* rightshift */
392*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
393*3d8817e4Smiod 28, /* bitsize */
394*3d8817e4Smiod TRUE, /* pc_relative */
395*3d8817e4Smiod 0, /* bitpos */
396*3d8817e4Smiod complain_overflow_signed, /* complain_on_overflow */
397*3d8817e4Smiod or32_elf_jumptarg_reloc,/* special_function */
398*3d8817e4Smiod "R_OR32_JUMPTARG", /* name */
399*3d8817e4Smiod FALSE, /* partial_inplace */
400*3d8817e4Smiod 0, /* src_mask */
401*3d8817e4Smiod 0x03ffffff, /* dst_mask */
402*3d8817e4Smiod TRUE), /* pcrel_offset */
403*3d8817e4Smiod
404*3d8817e4Smiod /* GNU extension to record C++ vtable hierarchy. */
405*3d8817e4Smiod HOWTO (R_OR32_GNU_VTINHERIT, /* type */
406*3d8817e4Smiod 0, /* rightshift */
407*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
408*3d8817e4Smiod 0, /* bitsize */
409*3d8817e4Smiod FALSE, /* pc_relative */
410*3d8817e4Smiod 0, /* bitpos */
411*3d8817e4Smiod complain_overflow_dont, /* complain_on_overflow */
412*3d8817e4Smiod NULL, /* special_function */
413*3d8817e4Smiod "R_OR32_GNU_VTINHERIT", /* name */
414*3d8817e4Smiod FALSE, /* partial_inplace */
415*3d8817e4Smiod 0, /* src_mask */
416*3d8817e4Smiod 0, /* dst_mask */
417*3d8817e4Smiod FALSE), /* pcrel_offset */
418*3d8817e4Smiod
419*3d8817e4Smiod /* GNU extension to record C++ vtable member usage. */
420*3d8817e4Smiod HOWTO (R_OR32_GNU_VTENTRY, /* type */
421*3d8817e4Smiod 0, /* rightshift */
422*3d8817e4Smiod 2, /* size (0 = byte, 1 = short, 2 = long) */
423*3d8817e4Smiod 0, /* bitsize */
424*3d8817e4Smiod FALSE, /* pc_relative */
425*3d8817e4Smiod 0, /* bitpos */
426*3d8817e4Smiod complain_overflow_dont, /* complain_on_overflow */
427*3d8817e4Smiod _bfd_elf_rel_vtable_reloc_fn, /* special_function */
428*3d8817e4Smiod "R_OR32_GNU_VTENTRY", /* name */
429*3d8817e4Smiod FALSE, /* partial_inplace */
430*3d8817e4Smiod 0, /* src_mask */
431*3d8817e4Smiod 0, /* dst_mask */
432*3d8817e4Smiod FALSE), /* pcrel_offset */
433*3d8817e4Smiod };
434*3d8817e4Smiod
435*3d8817e4Smiod /* Map BFD reloc types to OR32 ELF reloc types. */
436*3d8817e4Smiod
437*3d8817e4Smiod struct or32_reloc_map
438*3d8817e4Smiod {
439*3d8817e4Smiod bfd_reloc_code_real_type bfd_reloc_val;
440*3d8817e4Smiod unsigned char elf_reloc_val;
441*3d8817e4Smiod };
442*3d8817e4Smiod
443*3d8817e4Smiod static const struct or32_reloc_map or32_reloc_map[] =
444*3d8817e4Smiod {
445*3d8817e4Smiod { BFD_RELOC_NONE, R_OR32_NONE },
446*3d8817e4Smiod { BFD_RELOC_32, R_OR32_32 },
447*3d8817e4Smiod { BFD_RELOC_16, R_OR32_16 },
448*3d8817e4Smiod { BFD_RELOC_8, R_OR32_8 },
449*3d8817e4Smiod { BFD_RELOC_LO16, R_OR32_CONST },
450*3d8817e4Smiod { BFD_RELOC_HI16, R_OR32_CONSTH },
451*3d8817e4Smiod { BFD_RELOC_32_GOT_PCREL, R_OR32_JUMPTARG },
452*3d8817e4Smiod { BFD_RELOC_VTABLE_INHERIT, R_OR32_GNU_VTINHERIT },
453*3d8817e4Smiod { BFD_RELOC_VTABLE_ENTRY, R_OR32_GNU_VTENTRY },
454*3d8817e4Smiod };
455*3d8817e4Smiod
456*3d8817e4Smiod static reloc_howto_type *
bfd_elf32_bfd_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)457*3d8817e4Smiod bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
458*3d8817e4Smiod bfd_reloc_code_real_type code)
459*3d8817e4Smiod {
460*3d8817e4Smiod unsigned int i;
461*3d8817e4Smiod
462*3d8817e4Smiod for (i = ARRAY_SIZE (or32_reloc_map); i--;)
463*3d8817e4Smiod if (or32_reloc_map[i].bfd_reloc_val == code)
464*3d8817e4Smiod return &elf_or32_howto_table[or32_reloc_map[i].elf_reloc_val];
465*3d8817e4Smiod
466*3d8817e4Smiod return NULL;
467*3d8817e4Smiod }
468*3d8817e4Smiod
469*3d8817e4Smiod /* Set the howto pointer for an OR32 ELF reloc. */
470*3d8817e4Smiod
471*3d8817e4Smiod static void
or32_info_to_howto_rel(bfd * abfd ATTRIBUTE_UNUSED,arelent * cache_ptr,Elf_Internal_Rela * dst)472*3d8817e4Smiod or32_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
473*3d8817e4Smiod arelent *cache_ptr,
474*3d8817e4Smiod Elf_Internal_Rela *dst)
475*3d8817e4Smiod {
476*3d8817e4Smiod unsigned int r_type;
477*3d8817e4Smiod
478*3d8817e4Smiod r_type = ELF32_R_TYPE (dst->r_info);
479*3d8817e4Smiod BFD_ASSERT (r_type < (unsigned int) R_OR32_max);
480*3d8817e4Smiod cache_ptr->howto = &elf_or32_howto_table[r_type];
481*3d8817e4Smiod }
482*3d8817e4Smiod
483*3d8817e4Smiod #define TARGET_LITTLE_SYM bfd_elf32_or32_little_vec
484*3d8817e4Smiod #define TARGET_LITTLE_NAME "elf32-littleor32"
485*3d8817e4Smiod #define TARGET_BIG_SYM bfd_elf32_or32_big_vec
486*3d8817e4Smiod #define TARGET_BIG_NAME "elf32-or32"
487*3d8817e4Smiod #define ELF_ARCH bfd_arch_or32
488*3d8817e4Smiod #define ELF_MACHINE_CODE EM_OR32
489*3d8817e4Smiod #define ELF_MAXPAGESIZE 0x1000
490*3d8817e4Smiod
491*3d8817e4Smiod #define elf_info_to_howto 0
492*3d8817e4Smiod #define elf_info_to_howto_rel or32_info_to_howto_rel
493*3d8817e4Smiod #define elf_backend_object_p or32_elf_object_p
494*3d8817e4Smiod #define elf_backend_final_write_processing \
495*3d8817e4Smiod or32_elf_final_write_processing
496*3d8817e4Smiod
497*3d8817e4Smiod #include "elf32-target.h"
498