1*3d8817e4Smiod /* BFD back-end for raw ARM a.out binaries.
2*3d8817e4Smiod Copyright 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
3*3d8817e4Smiod Free Software Foundation, Inc.
4*3d8817e4Smiod Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
5*3d8817e4Smiod
6*3d8817e4Smiod This file is part of BFD, the Binary File Descriptor library.
7*3d8817e4Smiod
8*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
9*3d8817e4Smiod it under the terms of the GNU General Public License as published by
10*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
11*3d8817e4Smiod (at your option) any later version.
12*3d8817e4Smiod
13*3d8817e4Smiod This program is distributed in the hope that it will be useful,
14*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
15*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*3d8817e4Smiod GNU General Public License for more details.
17*3d8817e4Smiod
18*3d8817e4Smiod You should have received a copy of the GNU General Public License
19*3d8817e4Smiod along with this program; if not, write to the Free Software
20*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21*3d8817e4Smiod
22*3d8817e4Smiod #include "bfd.h"
23*3d8817e4Smiod #include "sysdep.h"
24*3d8817e4Smiod
25*3d8817e4Smiod /* Avoid multiple definitions from aoutx if supporting standard a.out
26*3d8817e4Smiod as well as our own. */
27*3d8817e4Smiod /* Do not "beautify" the CONCAT* macro args. Traditional C will not
28*3d8817e4Smiod remove whitespace added here, and thus will fail to concatenate
29*3d8817e4Smiod the tokens. */
30*3d8817e4Smiod #define NAME(x,y) CONCAT3 (aoutarm,_32_,y)
31*3d8817e4Smiod
32*3d8817e4Smiod #define N_TXTADDR(x) \
33*3d8817e4Smiod ((N_MAGIC (x) == NMAGIC) \
34*3d8817e4Smiod ? (bfd_vma) 0x8000 \
35*3d8817e4Smiod : ((N_MAGIC (x) != ZMAGIC) \
36*3d8817e4Smiod ? (bfd_vma) 0 \
37*3d8817e4Smiod : ((N_SHARED_LIB (x)) \
38*3d8817e4Smiod ? ((x).a_entry & ~(bfd_vma) (TARGET_PAGE_SIZE - 1)) \
39*3d8817e4Smiod : (bfd_vma) TEXT_START_ADDR)))
40*3d8817e4Smiod
41*3d8817e4Smiod #define TEXT_START_ADDR 0x8000
42*3d8817e4Smiod #define TARGET_PAGE_SIZE 0x8000
43*3d8817e4Smiod #define SEGMENT_SIZE TARGET_PAGE_SIZE
44*3d8817e4Smiod #define DEFAULT_ARCH bfd_arch_arm
45*3d8817e4Smiod
46*3d8817e4Smiod #define MY(OP) CONCAT2 (aoutarm_,OP)
47*3d8817e4Smiod #define N_BADMAG(x) ((((x).a_info & ~007200) != ZMAGIC) && \
48*3d8817e4Smiod (((x).a_info & ~006000) != OMAGIC) && \
49*3d8817e4Smiod ((x).a_info != NMAGIC))
50*3d8817e4Smiod #define N_MAGIC(x) ((x).a_info & ~07200)
51*3d8817e4Smiod
52*3d8817e4Smiod #define MY_bfd_reloc_type_lookup aoutarm_bfd_reloc_type_lookup
53*3d8817e4Smiod
54*3d8817e4Smiod #include "libaout.h"
55*3d8817e4Smiod #include "aout/aout64.h"
56*3d8817e4Smiod
57*3d8817e4Smiod
58*3d8817e4Smiod static bfd_reloc_status_type
59*3d8817e4Smiod MY (fix_pcrel_26) (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
60*3d8817e4Smiod static bfd_reloc_status_type
61*3d8817e4Smiod MY (fix_pcrel_26_done) (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
62*3d8817e4Smiod
63*3d8817e4Smiod reloc_howto_type MY (howto_table)[] =
64*3d8817e4Smiod {
65*3d8817e4Smiod /* Type rs size bsz pcrel bitpos ovrf sf name part_inpl
66*3d8817e4Smiod readmask setmask pcdone. */
67*3d8817e4Smiod HOWTO (0, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, 0, "8", TRUE,
68*3d8817e4Smiod 0x000000ff, 0x000000ff, FALSE),
69*3d8817e4Smiod HOWTO (1, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, 0, "16", TRUE,
70*3d8817e4Smiod 0x0000ffff, 0x0000ffff, FALSE),
71*3d8817e4Smiod HOWTO (2, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "32", TRUE,
72*3d8817e4Smiod 0xffffffff, 0xffffffff, FALSE),
73*3d8817e4Smiod HOWTO (3, 2, 2, 26, TRUE, 0, complain_overflow_signed, MY (fix_pcrel_26),
74*3d8817e4Smiod "ARM26", TRUE, 0x00ffffff, 0x00ffffff, TRUE),
75*3d8817e4Smiod HOWTO (4, 0, 0, 8, TRUE, 0, complain_overflow_signed, 0, "DISP8", TRUE,
76*3d8817e4Smiod 0x000000ff, 0x000000ff, TRUE),
77*3d8817e4Smiod HOWTO (5, 0, 1, 16, TRUE, 0, complain_overflow_signed, 0, "DISP16", TRUE,
78*3d8817e4Smiod 0x0000ffff, 0x0000ffff, TRUE),
79*3d8817e4Smiod HOWTO (6, 0, 2, 32, TRUE, 0, complain_overflow_signed, 0, "DISP32", TRUE,
80*3d8817e4Smiod 0xffffffff, 0xffffffff, TRUE),
81*3d8817e4Smiod HOWTO (7, 2, 2, 26, FALSE, 0, complain_overflow_signed,
82*3d8817e4Smiod MY (fix_pcrel_26_done), "ARM26D", TRUE, 0x0, 0x0,
83*3d8817e4Smiod FALSE),
84*3d8817e4Smiod EMPTY_HOWTO (-1),
85*3d8817e4Smiod HOWTO (9, 0, -1, 16, FALSE, 0, complain_overflow_bitfield, 0, "NEG16", TRUE,
86*3d8817e4Smiod 0x0000ffff, 0x0000ffff, FALSE),
87*3d8817e4Smiod HOWTO (10, 0, -2, 32, FALSE, 0, complain_overflow_bitfield, 0, "NEG32", TRUE,
88*3d8817e4Smiod 0xffffffff, 0xffffffff, FALSE)
89*3d8817e4Smiod };
90*3d8817e4Smiod
91*3d8817e4Smiod #define RELOC_ARM_BITS_NEG_BIG ((unsigned int) 0x08)
92*3d8817e4Smiod #define RELOC_ARM_BITS_NEG_LITTLE ((unsigned int) 0x10)
93*3d8817e4Smiod
94*3d8817e4Smiod static reloc_howto_type *
MY(reloc_howto)95*3d8817e4Smiod MY (reloc_howto) (bfd *abfd,
96*3d8817e4Smiod struct reloc_std_external *rel,
97*3d8817e4Smiod int *r_index,
98*3d8817e4Smiod int *r_extern,
99*3d8817e4Smiod int *r_pcrel)
100*3d8817e4Smiod {
101*3d8817e4Smiod unsigned int r_length;
102*3d8817e4Smiod unsigned int r_pcrel_done;
103*3d8817e4Smiod unsigned int r_neg;
104*3d8817e4Smiod int index;
105*3d8817e4Smiod
106*3d8817e4Smiod *r_pcrel = 0;
107*3d8817e4Smiod if (bfd_header_big_endian (abfd))
108*3d8817e4Smiod {
109*3d8817e4Smiod *r_index = ((rel->r_index[0] << 16)
110*3d8817e4Smiod | (rel->r_index[1] << 8)
111*3d8817e4Smiod | rel->r_index[2]);
112*3d8817e4Smiod *r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
113*3d8817e4Smiod r_pcrel_done = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
114*3d8817e4Smiod r_neg = (0 != (rel->r_type[0] & RELOC_ARM_BITS_NEG_BIG));
115*3d8817e4Smiod r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)
116*3d8817e4Smiod >> RELOC_STD_BITS_LENGTH_SH_BIG);
117*3d8817e4Smiod }
118*3d8817e4Smiod else
119*3d8817e4Smiod {
120*3d8817e4Smiod *r_index = ((rel->r_index[2] << 16)
121*3d8817e4Smiod | (rel->r_index[1] << 8)
122*3d8817e4Smiod | rel->r_index[0]);
123*3d8817e4Smiod *r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
124*3d8817e4Smiod r_pcrel_done = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
125*3d8817e4Smiod r_neg = (0 != (rel->r_type[0] & RELOC_ARM_BITS_NEG_LITTLE));
126*3d8817e4Smiod r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)
127*3d8817e4Smiod >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
128*3d8817e4Smiod }
129*3d8817e4Smiod index = r_length + 4 * r_pcrel_done + 8 * r_neg;
130*3d8817e4Smiod if (index == 3)
131*3d8817e4Smiod *r_pcrel = 1;
132*3d8817e4Smiod
133*3d8817e4Smiod return MY (howto_table) + index;
134*3d8817e4Smiod }
135*3d8817e4Smiod
136*3d8817e4Smiod #define MY_reloc_howto(BFD, REL, IN, EX, PC) \
137*3d8817e4Smiod MY (reloc_howto) (BFD, REL, &IN, &EX, &PC)
138*3d8817e4Smiod
139*3d8817e4Smiod static void
MY(put_reloc)140*3d8817e4Smiod MY (put_reloc) (bfd *abfd,
141*3d8817e4Smiod int r_extern,
142*3d8817e4Smiod int r_index,
143*3d8817e4Smiod bfd_vma value,
144*3d8817e4Smiod reloc_howto_type *howto,
145*3d8817e4Smiod struct reloc_std_external *reloc)
146*3d8817e4Smiod {
147*3d8817e4Smiod unsigned int r_length;
148*3d8817e4Smiod int r_pcrel;
149*3d8817e4Smiod int r_neg;
150*3d8817e4Smiod
151*3d8817e4Smiod PUT_WORD (abfd, value, reloc->r_address);
152*3d8817e4Smiod /* Size as a power of two. */
153*3d8817e4Smiod r_length = howto->size;
154*3d8817e4Smiod
155*3d8817e4Smiod /* Special case for branch relocations. */
156*3d8817e4Smiod if (howto->type == 3 || howto->type == 7)
157*3d8817e4Smiod r_length = 3;
158*3d8817e4Smiod
159*3d8817e4Smiod r_pcrel = howto->type & 4; /* PC Relative done? */
160*3d8817e4Smiod r_neg = howto->type & 8; /* Negative relocation. */
161*3d8817e4Smiod
162*3d8817e4Smiod if (bfd_header_big_endian (abfd))
163*3d8817e4Smiod {
164*3d8817e4Smiod reloc->r_index[0] = r_index >> 16;
165*3d8817e4Smiod reloc->r_index[1] = r_index >> 8;
166*3d8817e4Smiod reloc->r_index[2] = r_index;
167*3d8817e4Smiod reloc->r_type[0] =
168*3d8817e4Smiod ((r_extern ? RELOC_STD_BITS_EXTERN_BIG : 0)
169*3d8817e4Smiod | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG : 0)
170*3d8817e4Smiod | (r_neg ? RELOC_ARM_BITS_NEG_BIG : 0)
171*3d8817e4Smiod | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
172*3d8817e4Smiod }
173*3d8817e4Smiod else
174*3d8817e4Smiod {
175*3d8817e4Smiod reloc->r_index[2] = r_index >> 16;
176*3d8817e4Smiod reloc->r_index[1] = r_index >> 8;
177*3d8817e4Smiod reloc->r_index[0] = r_index;
178*3d8817e4Smiod reloc->r_type[0] =
179*3d8817e4Smiod ((r_extern ? RELOC_STD_BITS_EXTERN_LITTLE : 0)
180*3d8817e4Smiod | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE : 0)
181*3d8817e4Smiod | (r_neg ? RELOC_ARM_BITS_NEG_LITTLE : 0)
182*3d8817e4Smiod | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
183*3d8817e4Smiod }
184*3d8817e4Smiod }
185*3d8817e4Smiod
186*3d8817e4Smiod #define MY_put_reloc(BFD, EXT, IDX, VAL, HOWTO, RELOC) \
187*3d8817e4Smiod MY (put_reloc) (BFD, EXT, IDX, VAL, HOWTO, RELOC)
188*3d8817e4Smiod
189*3d8817e4Smiod static void
MY(relocatable_reloc)190*3d8817e4Smiod MY (relocatable_reloc) (reloc_howto_type *howto,
191*3d8817e4Smiod bfd *abfd,
192*3d8817e4Smiod struct reloc_std_external *reloc,
193*3d8817e4Smiod bfd_vma *amount,
194*3d8817e4Smiod bfd_vma r_addr)
195*3d8817e4Smiod {
196*3d8817e4Smiod if (howto->type == 3)
197*3d8817e4Smiod {
198*3d8817e4Smiod if (reloc->r_type[0]
199*3d8817e4Smiod & (bfd_header_big_endian (abfd)
200*3d8817e4Smiod ? RELOC_STD_BITS_EXTERN_BIG : RELOC_STD_BITS_EXTERN_LITTLE))
201*3d8817e4Smiod /* The reloc is still external, so don't modify anything. */
202*3d8817e4Smiod *amount = 0;
203*3d8817e4Smiod else
204*3d8817e4Smiod {
205*3d8817e4Smiod *amount -= r_addr;
206*3d8817e4Smiod /* Change the r_pcrel value -- on the ARM, this bit is set once the
207*3d8817e4Smiod relocation is done. */
208*3d8817e4Smiod if (bfd_header_big_endian (abfd))
209*3d8817e4Smiod reloc->r_type[0] |= RELOC_STD_BITS_PCREL_BIG;
210*3d8817e4Smiod else
211*3d8817e4Smiod reloc->r_type[0] |= RELOC_STD_BITS_PCREL_LITTLE;
212*3d8817e4Smiod }
213*3d8817e4Smiod }
214*3d8817e4Smiod else if (howto->type == 7)
215*3d8817e4Smiod *amount = 0;
216*3d8817e4Smiod }
217*3d8817e4Smiod
218*3d8817e4Smiod #define MY_relocatable_reloc(HOW, BFD, REL, AMOUNT, ADDR) \
219*3d8817e4Smiod MY (relocatable_reloc) (HOW, BFD, REL, &(AMOUNT), ADDR)
220*3d8817e4Smiod
221*3d8817e4Smiod static bfd_reloc_status_type
MY(fix_pcrel_26_done)222*3d8817e4Smiod MY (fix_pcrel_26_done) (bfd *abfd ATTRIBUTE_UNUSED,
223*3d8817e4Smiod arelent *reloc_entry ATTRIBUTE_UNUSED,
224*3d8817e4Smiod asymbol *symbol ATTRIBUTE_UNUSED,
225*3d8817e4Smiod void * data ATTRIBUTE_UNUSED,
226*3d8817e4Smiod asection *input_section ATTRIBUTE_UNUSED,
227*3d8817e4Smiod bfd *output_bfd ATTRIBUTE_UNUSED,
228*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
229*3d8817e4Smiod {
230*3d8817e4Smiod /* This is dead simple at present. */
231*3d8817e4Smiod return bfd_reloc_ok;
232*3d8817e4Smiod }
233*3d8817e4Smiod
234*3d8817e4Smiod static bfd_reloc_status_type
MY(fix_pcrel_26)235*3d8817e4Smiod MY (fix_pcrel_26) (bfd *abfd,
236*3d8817e4Smiod arelent *reloc_entry,
237*3d8817e4Smiod asymbol *symbol,
238*3d8817e4Smiod void * data,
239*3d8817e4Smiod asection *input_section,
240*3d8817e4Smiod bfd *output_bfd,
241*3d8817e4Smiod char **error_message ATTRIBUTE_UNUSED)
242*3d8817e4Smiod {
243*3d8817e4Smiod bfd_vma relocation;
244*3d8817e4Smiod bfd_size_type addr = reloc_entry->address;
245*3d8817e4Smiod bfd_vma target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
246*3d8817e4Smiod bfd_reloc_status_type flag = bfd_reloc_ok;
247*3d8817e4Smiod
248*3d8817e4Smiod /* If this is an undefined symbol, return error. */
249*3d8817e4Smiod if (symbol->section == &bfd_und_section
250*3d8817e4Smiod && (symbol->flags & BSF_WEAK) == 0)
251*3d8817e4Smiod return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
252*3d8817e4Smiod
253*3d8817e4Smiod /* If the sections are different, and we are doing a partial relocation,
254*3d8817e4Smiod just ignore it for now. */
255*3d8817e4Smiod if (symbol->section->name != input_section->name
256*3d8817e4Smiod && output_bfd != NULL)
257*3d8817e4Smiod return bfd_reloc_ok;
258*3d8817e4Smiod
259*3d8817e4Smiod relocation = (target & 0x00ffffff) << 2;
260*3d8817e4Smiod relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend. */
261*3d8817e4Smiod relocation += symbol->value;
262*3d8817e4Smiod relocation += symbol->section->output_section->vma;
263*3d8817e4Smiod relocation += symbol->section->output_offset;
264*3d8817e4Smiod relocation += reloc_entry->addend;
265*3d8817e4Smiod relocation -= input_section->output_section->vma;
266*3d8817e4Smiod relocation -= input_section->output_offset;
267*3d8817e4Smiod relocation -= addr;
268*3d8817e4Smiod if (relocation & 3)
269*3d8817e4Smiod return bfd_reloc_overflow;
270*3d8817e4Smiod
271*3d8817e4Smiod /* Check for overflow. */
272*3d8817e4Smiod if (relocation & 0x02000000)
273*3d8817e4Smiod {
274*3d8817e4Smiod if ((relocation & ~ (bfd_vma) 0x03ffffff) != ~ (bfd_vma) 0x03ffffff)
275*3d8817e4Smiod flag = bfd_reloc_overflow;
276*3d8817e4Smiod }
277*3d8817e4Smiod else if (relocation & ~ (bfd_vma) 0x03ffffff)
278*3d8817e4Smiod flag = bfd_reloc_overflow;
279*3d8817e4Smiod
280*3d8817e4Smiod target &= ~ (bfd_vma) 0x00ffffff;
281*3d8817e4Smiod target |= (relocation >> 2) & 0x00ffffff;
282*3d8817e4Smiod bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
283*3d8817e4Smiod
284*3d8817e4Smiod /* Now the ARM magic... Change the reloc type so that it is marked as done.
285*3d8817e4Smiod Strictly this is only necessary if we are doing a partial relocation. */
286*3d8817e4Smiod reloc_entry->howto = &MY (howto_table)[7];
287*3d8817e4Smiod
288*3d8817e4Smiod return flag;
289*3d8817e4Smiod }
290*3d8817e4Smiod
291*3d8817e4Smiod static reloc_howto_type *
MY(bfd_reloc_type_lookup)292*3d8817e4Smiod MY (bfd_reloc_type_lookup) (bfd *abfd,
293*3d8817e4Smiod bfd_reloc_code_real_type code)
294*3d8817e4Smiod {
295*3d8817e4Smiod #define ASTD(i,j) case i: return & MY (howto_table)[j]
296*3d8817e4Smiod
297*3d8817e4Smiod if (code == BFD_RELOC_CTOR)
298*3d8817e4Smiod switch (bfd_get_arch_info (abfd)->bits_per_address)
299*3d8817e4Smiod {
300*3d8817e4Smiod case 32:
301*3d8817e4Smiod code = BFD_RELOC_32;
302*3d8817e4Smiod break;
303*3d8817e4Smiod default:
304*3d8817e4Smiod return NULL;
305*3d8817e4Smiod }
306*3d8817e4Smiod
307*3d8817e4Smiod switch (code)
308*3d8817e4Smiod {
309*3d8817e4Smiod ASTD (BFD_RELOC_16, 1);
310*3d8817e4Smiod ASTD (BFD_RELOC_32, 2);
311*3d8817e4Smiod ASTD (BFD_RELOC_ARM_PCREL_BRANCH, 3);
312*3d8817e4Smiod ASTD (BFD_RELOC_8_PCREL, 4);
313*3d8817e4Smiod ASTD (BFD_RELOC_16_PCREL, 5);
314*3d8817e4Smiod ASTD (BFD_RELOC_32_PCREL, 6);
315*3d8817e4Smiod default:
316*3d8817e4Smiod return NULL;
317*3d8817e4Smiod }
318*3d8817e4Smiod }
319*3d8817e4Smiod
320*3d8817e4Smiod #define MY_swap_std_reloc_in MY (swap_std_reloc_in)
321*3d8817e4Smiod #define MY_swap_std_reloc_out MY (swap_std_reloc_out)
322*3d8817e4Smiod #define MY_get_section_contents _bfd_generic_get_section_contents
323*3d8817e4Smiod
324*3d8817e4Smiod void MY_swap_std_reloc_in (bfd *, struct reloc_std_external *, arelent *, asymbol **, bfd_size_type);
325*3d8817e4Smiod void MY_swap_std_reloc_out (bfd *, arelent *, struct reloc_std_external *);
326*3d8817e4Smiod
327*3d8817e4Smiod #include "aoutx.h"
328*3d8817e4Smiod
329*3d8817e4Smiod void
MY_swap_std_reloc_in(bfd * abfd,struct reloc_std_external * bytes,arelent * cache_ptr,asymbol ** symbols,bfd_size_type symcount ATTRIBUTE_UNUSED)330*3d8817e4Smiod MY_swap_std_reloc_in (bfd *abfd,
331*3d8817e4Smiod struct reloc_std_external *bytes,
332*3d8817e4Smiod arelent *cache_ptr,
333*3d8817e4Smiod asymbol **symbols,
334*3d8817e4Smiod bfd_size_type symcount ATTRIBUTE_UNUSED)
335*3d8817e4Smiod {
336*3d8817e4Smiod int r_index;
337*3d8817e4Smiod int r_extern;
338*3d8817e4Smiod int r_pcrel;
339*3d8817e4Smiod struct aoutdata *su = &(abfd->tdata.aout_data->a);
340*3d8817e4Smiod
341*3d8817e4Smiod cache_ptr->address = H_GET_32 (abfd, bytes->r_address);
342*3d8817e4Smiod
343*3d8817e4Smiod cache_ptr->howto = MY_reloc_howto (abfd, bytes, r_index, r_extern, r_pcrel);
344*3d8817e4Smiod
345*3d8817e4Smiod MOVE_ADDRESS (0);
346*3d8817e4Smiod }
347*3d8817e4Smiod
348*3d8817e4Smiod void
MY_swap_std_reloc_out(bfd * abfd,arelent * g,struct reloc_std_external * natptr)349*3d8817e4Smiod MY_swap_std_reloc_out (bfd *abfd,
350*3d8817e4Smiod arelent *g,
351*3d8817e4Smiod struct reloc_std_external *natptr)
352*3d8817e4Smiod {
353*3d8817e4Smiod int r_index;
354*3d8817e4Smiod asymbol *sym = *(g->sym_ptr_ptr);
355*3d8817e4Smiod int r_extern;
356*3d8817e4Smiod int r_length;
357*3d8817e4Smiod int r_pcrel;
358*3d8817e4Smiod int r_neg = 0; /* Negative relocs use the BASEREL bit. */
359*3d8817e4Smiod asection *output_section = sym->section->output_section;
360*3d8817e4Smiod
361*3d8817e4Smiod PUT_WORD (abfd, g->address, natptr->r_address);
362*3d8817e4Smiod
363*3d8817e4Smiod r_length = g->howto->size ; /* Size as a power of two. */
364*3d8817e4Smiod if (r_length < 0)
365*3d8817e4Smiod {
366*3d8817e4Smiod r_length = -r_length;
367*3d8817e4Smiod r_neg = 1;
368*3d8817e4Smiod }
369*3d8817e4Smiod
370*3d8817e4Smiod r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
371*3d8817e4Smiod
372*3d8817e4Smiod /* For RISC iX, in pc-relative relocs the r_pcrel bit means that the
373*3d8817e4Smiod relocation has been done already (Only for the 26-bit one I think). */
374*3d8817e4Smiod if (g->howto->type == 3)
375*3d8817e4Smiod {
376*3d8817e4Smiod r_length = 3;
377*3d8817e4Smiod r_pcrel = 0;
378*3d8817e4Smiod }
379*3d8817e4Smiod else if (g->howto->type == 7)
380*3d8817e4Smiod {
381*3d8817e4Smiod r_length = 3;
382*3d8817e4Smiod r_pcrel = 1;
383*3d8817e4Smiod }
384*3d8817e4Smiod
385*3d8817e4Smiod /* Name was clobbered by aout_write_syms to be symbol index. */
386*3d8817e4Smiod
387*3d8817e4Smiod /* If this relocation is relative to a symbol then set the
388*3d8817e4Smiod r_index to the symbols index, and the r_extern bit.
389*3d8817e4Smiod
390*3d8817e4Smiod Absolute symbols can come in in two ways, either as an offset
391*3d8817e4Smiod from the abs section, or as a symbol which has an abs value.
392*3d8817e4Smiod check for that here. */
393*3d8817e4Smiod
394*3d8817e4Smiod if (bfd_is_com_section (output_section)
395*3d8817e4Smiod || output_section == &bfd_abs_section
396*3d8817e4Smiod || output_section == &bfd_und_section)
397*3d8817e4Smiod {
398*3d8817e4Smiod if (bfd_abs_section.symbol == sym)
399*3d8817e4Smiod {
400*3d8817e4Smiod /* Whoops, looked like an abs symbol, but is really an offset
401*3d8817e4Smiod from the abs section. */
402*3d8817e4Smiod r_index = 0;
403*3d8817e4Smiod r_extern = 0;
404*3d8817e4Smiod }
405*3d8817e4Smiod else
406*3d8817e4Smiod {
407*3d8817e4Smiod /* Fill in symbol. */
408*3d8817e4Smiod r_extern = 1;
409*3d8817e4Smiod r_index = (*(g->sym_ptr_ptr))->KEEPIT;
410*3d8817e4Smiod }
411*3d8817e4Smiod }
412*3d8817e4Smiod else
413*3d8817e4Smiod {
414*3d8817e4Smiod /* Just an ordinary section. */
415*3d8817e4Smiod r_extern = 0;
416*3d8817e4Smiod r_index = output_section->target_index;
417*3d8817e4Smiod }
418*3d8817e4Smiod
419*3d8817e4Smiod /* Now the fun stuff. */
420*3d8817e4Smiod if (bfd_header_big_endian (abfd))
421*3d8817e4Smiod {
422*3d8817e4Smiod natptr->r_index[0] = r_index >> 16;
423*3d8817e4Smiod natptr->r_index[1] = r_index >> 8;
424*3d8817e4Smiod natptr->r_index[2] = r_index;
425*3d8817e4Smiod natptr->r_type[0] =
426*3d8817e4Smiod ( (r_extern ? RELOC_STD_BITS_EXTERN_BIG: 0)
427*3d8817e4Smiod | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG: 0)
428*3d8817e4Smiod | (r_neg ? RELOC_ARM_BITS_NEG_BIG: 0)
429*3d8817e4Smiod | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG));
430*3d8817e4Smiod }
431*3d8817e4Smiod else
432*3d8817e4Smiod {
433*3d8817e4Smiod natptr->r_index[2] = r_index >> 16;
434*3d8817e4Smiod natptr->r_index[1] = r_index >> 8;
435*3d8817e4Smiod natptr->r_index[0] = r_index;
436*3d8817e4Smiod natptr->r_type[0] =
437*3d8817e4Smiod ( (r_extern ? RELOC_STD_BITS_EXTERN_LITTLE: 0)
438*3d8817e4Smiod | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE: 0)
439*3d8817e4Smiod | (r_neg ? RELOC_ARM_BITS_NEG_LITTLE: 0)
440*3d8817e4Smiod | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE));
441*3d8817e4Smiod }
442*3d8817e4Smiod }
443*3d8817e4Smiod
444*3d8817e4Smiod #define MY_BFD_TARGET
445*3d8817e4Smiod
446*3d8817e4Smiod #include "aout-target.h"
447*3d8817e4Smiod
448*3d8817e4Smiod extern const bfd_target aout_arm_big_vec;
449*3d8817e4Smiod
450*3d8817e4Smiod const bfd_target aout_arm_little_vec =
451*3d8817e4Smiod {
452*3d8817e4Smiod "a.out-arm-little", /* Name. */
453*3d8817e4Smiod bfd_target_aout_flavour,
454*3d8817e4Smiod BFD_ENDIAN_LITTLE, /* Target byte order (little). */
455*3d8817e4Smiod BFD_ENDIAN_LITTLE, /* Target headers byte order (little). */
456*3d8817e4Smiod (HAS_RELOC | EXEC_P | /* Object flags. */
457*3d8817e4Smiod HAS_LINENO | HAS_DEBUG |
458*3d8817e4Smiod HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
459*3d8817e4Smiod (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
460*3d8817e4Smiod MY_symbol_leading_char,
461*3d8817e4Smiod AR_PAD_CHAR, /* AR_pad_char. */
462*3d8817e4Smiod 15, /* AR_max_namelen. */
463*3d8817e4Smiod bfd_getl64, bfd_getl_signed_64, bfd_putl64,
464*3d8817e4Smiod bfd_getl32, bfd_getl_signed_32, bfd_putl32,
465*3d8817e4Smiod bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */
466*3d8817e4Smiod bfd_getl64, bfd_getl_signed_64, bfd_putl64,
467*3d8817e4Smiod bfd_getl32, bfd_getl_signed_32, bfd_putl32,
468*3d8817e4Smiod bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Headers. */
469*3d8817e4Smiod {_bfd_dummy_target, MY_object_p, /* bfd_check_format. */
470*3d8817e4Smiod bfd_generic_archive_p, MY_core_file_p},
471*3d8817e4Smiod {bfd_false, MY_mkobject, /* bfd_set_format. */
472*3d8817e4Smiod _bfd_generic_mkarchive, bfd_false},
473*3d8817e4Smiod {bfd_false, MY_write_object_contents, /* bfd_write_contents. */
474*3d8817e4Smiod _bfd_write_archive_contents, bfd_false},
475*3d8817e4Smiod
476*3d8817e4Smiod BFD_JUMP_TABLE_GENERIC (MY),
477*3d8817e4Smiod BFD_JUMP_TABLE_COPY (MY),
478*3d8817e4Smiod BFD_JUMP_TABLE_CORE (MY),
479*3d8817e4Smiod BFD_JUMP_TABLE_ARCHIVE (MY),
480*3d8817e4Smiod BFD_JUMP_TABLE_SYMBOLS (MY),
481*3d8817e4Smiod BFD_JUMP_TABLE_RELOCS (MY),
482*3d8817e4Smiod BFD_JUMP_TABLE_WRITE (MY),
483*3d8817e4Smiod BFD_JUMP_TABLE_LINK (MY),
484*3d8817e4Smiod BFD_JUMP_TABLE_DYNAMIC (MY),
485*3d8817e4Smiod
486*3d8817e4Smiod & aout_arm_big_vec,
487*3d8817e4Smiod
488*3d8817e4Smiod (void *) MY_backend_data,
489*3d8817e4Smiod };
490*3d8817e4Smiod
491*3d8817e4Smiod const bfd_target aout_arm_big_vec =
492*3d8817e4Smiod {
493*3d8817e4Smiod "a.out-arm-big", /* Name. */
494*3d8817e4Smiod bfd_target_aout_flavour,
495*3d8817e4Smiod BFD_ENDIAN_BIG, /* Target byte order (big). */
496*3d8817e4Smiod BFD_ENDIAN_BIG, /* Target headers byte order (big). */
497*3d8817e4Smiod (HAS_RELOC | EXEC_P | /* Object flags. */
498*3d8817e4Smiod HAS_LINENO | HAS_DEBUG |
499*3d8817e4Smiod HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
500*3d8817e4Smiod (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
501*3d8817e4Smiod MY_symbol_leading_char,
502*3d8817e4Smiod AR_PAD_CHAR, /* AR_pad_char. */
503*3d8817e4Smiod 15, /* AR_max_namelen. */
504*3d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64,
505*3d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32,
506*3d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
507*3d8817e4Smiod bfd_getb64, bfd_getb_signed_64, bfd_putb64,
508*3d8817e4Smiod bfd_getb32, bfd_getb_signed_32, bfd_putb32,
509*3d8817e4Smiod bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
510*3d8817e4Smiod {_bfd_dummy_target, MY_object_p, /* bfd_check_format. */
511*3d8817e4Smiod bfd_generic_archive_p, MY_core_file_p},
512*3d8817e4Smiod {bfd_false, MY_mkobject, /* bfd_set_format. */
513*3d8817e4Smiod _bfd_generic_mkarchive, bfd_false},
514*3d8817e4Smiod {bfd_false, MY_write_object_contents, /* bfd_write_contents. */
515*3d8817e4Smiod _bfd_write_archive_contents, bfd_false},
516*3d8817e4Smiod
517*3d8817e4Smiod BFD_JUMP_TABLE_GENERIC (MY),
518*3d8817e4Smiod BFD_JUMP_TABLE_COPY (MY),
519*3d8817e4Smiod BFD_JUMP_TABLE_CORE (MY),
520*3d8817e4Smiod BFD_JUMP_TABLE_ARCHIVE (MY),
521*3d8817e4Smiod BFD_JUMP_TABLE_SYMBOLS (MY),
522*3d8817e4Smiod BFD_JUMP_TABLE_RELOCS (MY),
523*3d8817e4Smiod BFD_JUMP_TABLE_WRITE (MY),
524*3d8817e4Smiod BFD_JUMP_TABLE_LINK (MY),
525*3d8817e4Smiod BFD_JUMP_TABLE_DYNAMIC (MY),
526*3d8817e4Smiod
527*3d8817e4Smiod & aout_arm_little_vec,
528*3d8817e4Smiod
529*3d8817e4Smiod (void *) MY_backend_data,
530*3d8817e4Smiod };
531