bfd/
[deliverable/binutils-gdb.git] / bfd / coff-sparc.c
CommitLineData
252b5132 1/* BFD back-end for Sparc COFF files.
eac93a98 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
157090f7 3 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
252b5132
RH
4 Written by Cygnus Support.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
3e110533 20Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132 21
252b5132 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
252b5132
RH
24#include "libbfd.h"
25#include "coff/sparc.h"
26#include "coff/internal.h"
27#include "libcoff.h"
28
29#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
30
31#define BADMAG(x) ((x).f_magic != SPARCMAGIC && (x).f_magic != LYNXCOFFMAGIC)
32
33/* The page size is a guess based on ELF. */
34#define COFF_PAGE_SIZE 0x10000
35
5a65713f
AJ
36
37static reloc_howto_type *coff_sparc_reloc_type_lookup
38 PARAMS ((bfd *, bfd_reloc_code_real_type));
39static void rtype2howto PARAMS ((arelent *, struct internal_reloc *));
dc810e39 40
252b5132
RH
41enum reloc_type
42 {
43 R_SPARC_NONE = 0,
cbfe05c4
KH
44 R_SPARC_8, R_SPARC_16, R_SPARC_32,
45 R_SPARC_DISP8, R_SPARC_DISP16, R_SPARC_DISP32,
252b5132
RH
46 R_SPARC_WDISP30, R_SPARC_WDISP22,
47 R_SPARC_HI22, R_SPARC_22,
48 R_SPARC_13, R_SPARC_LO10,
49 R_SPARC_GOT10, R_SPARC_GOT13, R_SPARC_GOT22,
50 R_SPARC_PC10, R_SPARC_PC22,
51 R_SPARC_WPLT30,
52 R_SPARC_COPY,
53 R_SPARC_GLOB_DAT, R_SPARC_JMP_SLOT,
54 R_SPARC_RELATIVE,
55 R_SPARC_UA32,
56 R_SPARC_max
57 };
58
252b5132
RH
59/* This is stolen pretty directly from elf.c. */
60static bfd_reloc_status_type
61bfd_coff_generic_reloc PARAMS ((bfd *, arelent *, asymbol *, PTR,
62 asection *, bfd *, char **));
63
64static bfd_reloc_status_type
65bfd_coff_generic_reloc (abfd, reloc_entry, symbol, data, input_section,
66 output_bfd, error_message)
5f771d47 67 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
68 arelent *reloc_entry;
69 asymbol *symbol;
5f771d47 70 PTR data ATTRIBUTE_UNUSED;
252b5132
RH
71 asection *input_section;
72 bfd *output_bfd;
5f771d47 73 char **error_message ATTRIBUTE_UNUSED;
252b5132
RH
74{
75 if (output_bfd != (bfd *) NULL
76 && (symbol->flags & BSF_SECTION_SYM) == 0)
77 {
78 reloc_entry->address += input_section->output_offset;
79 return bfd_reloc_ok;
80 }
81
82 return bfd_reloc_continue;
83}
84
cbfe05c4 85static reloc_howto_type coff_sparc_howto_table[] =
252b5132 86{
b34976b6
AM
87 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
88 HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_8", FALSE,0,0x000000ff,TRUE),
89 HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
90 HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_32", FALSE,0,0xffffffff,TRUE),
91 HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
92 HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
93 HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_DISP32", FALSE,0,0x00ffffff,TRUE),
94 HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
95 HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_coff_generic_reloc,"R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
96 HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
97 HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_22", FALSE,0,0x003fffff,TRUE),
98 HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_13", FALSE,0,0x00001fff,TRUE),
99 HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
100 HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
101 HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
102 HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
103 HOWTO(R_SPARC_PC10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
104 HOWTO(R_SPARC_PC22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
105 HOWTO(R_SPARC_WPLT30, 0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_WPLT30", FALSE,0,0x00000000,TRUE),
106 HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
107 HOWTO(R_SPARC_GLOB_DAT,0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_GLOB_DAT",FALSE,0,0x00000000,TRUE),
108 HOWTO(R_SPARC_JMP_SLOT,0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_JMP_SLOT",FALSE,0,0x00000000,TRUE),
109 HOWTO(R_SPARC_RELATIVE,0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
110 HOWTO(R_SPARC_UA32, 0,0,00,FALSE,0,complain_overflow_dont, bfd_coff_generic_reloc,"R_SPARC_UA32", FALSE,0,0x00000000,TRUE),
252b5132
RH
111};
112
113struct coff_reloc_map {
114 bfd_reloc_code_real_type bfd_reloc_val;
115 unsigned char coff_reloc_val;
116};
117
dc810e39 118static const struct coff_reloc_map sparc_reloc_map[] =
252b5132
RH
119{
120 { BFD_RELOC_NONE, R_SPARC_NONE, },
121 { BFD_RELOC_16, R_SPARC_16, },
122 { BFD_RELOC_8, R_SPARC_8 },
123 { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
124 { BFD_RELOC_CTOR, R_SPARC_32 }, /* @@ Assumes 32 bits. */
125 { BFD_RELOC_32, R_SPARC_32 },
126 { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
127 { BFD_RELOC_HI22, R_SPARC_HI22 },
128 { BFD_RELOC_LO10, R_SPARC_LO10, },
129 { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
130 { BFD_RELOC_SPARC22, R_SPARC_22 },
131 { BFD_RELOC_SPARC13, R_SPARC_13 },
132 { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
133 { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
134 { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
135 { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
136 { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
137 { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
138 { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
139 { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
140 { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
141 { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
142 { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
143 /* { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
144};
145
146static reloc_howto_type *
147coff_sparc_reloc_type_lookup (abfd, code)
5f771d47 148 bfd *abfd ATTRIBUTE_UNUSED;
252b5132
RH
149 bfd_reloc_code_real_type code;
150{
151 unsigned int i;
152 for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct coff_reloc_map); i++)
153 {
154 if (sparc_reloc_map[i].bfd_reloc_val == code)
155 return &coff_sparc_howto_table[(int) sparc_reloc_map[i].coff_reloc_val];
156 }
157 return 0;
158}
159#define coff_bfd_reloc_type_lookup coff_sparc_reloc_type_lookup
160
157090f7
AM
161static reloc_howto_type *
162coff_sparc_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
163 const char *r_name)
164{
165 unsigned int i;
166
167 for (i = 0;
168 i < (sizeof (coff_sparc_howto_table)
169 / sizeof (coff_sparc_howto_table[0]));
170 i++)
171 if (coff_sparc_howto_table[i].name != NULL
172 && strcasecmp (coff_sparc_howto_table[i].name, r_name) == 0)
173 return &coff_sparc_howto_table[i];
174
175 return NULL;
176}
177#define coff_bfd_reloc_name_lookup coff_sparc_reloc_name_lookup
178
252b5132
RH
179static void
180rtype2howto (cache_ptr, dst)
181 arelent *cache_ptr;
182 struct internal_reloc *dst;
183{
184 BFD_ASSERT (dst->r_type < (unsigned int) R_SPARC_max);
185 cache_ptr->howto = &coff_sparc_howto_table[dst->r_type];
186}
187
188#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
189
dc810e39
AM
190#define SWAP_IN_RELOC_OFFSET H_GET_32
191#define SWAP_OUT_RELOC_OFFSET H_PUT_32
252b5132
RH
192#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
193 cache_ptr->addend = reloc.r_offset;
194
195/* Clear the r_spare field in relocs. */
196#define SWAP_OUT_RELOC_EXTRA(abfd,src,dst) \
197 do { \
198 dst->r_spare[0] = 0; \
199 dst->r_spare[1] = 0; \
200 } while (0)
201
202#define __A_MAGIC_SET__
203
cbfe05c4 204/* Enable Sparc-specific hacks in coffcode.h. */
252b5132
RH
205
206#define COFF_SPARC
207
208#include "coffcode.h"
209
c3c89269
NC
210#ifndef TARGET_SYM
211#define TARGET_SYM sparccoff_vec
252b5132 212#endif
252b5132 213
c3c89269
NC
214#ifndef TARGET_NAME
215#define TARGET_NAME "coff-sparc"
216#endif
252b5132 217
3fa78519 218CREATE_BIG_COFF_TARGET_VEC (TARGET_SYM, TARGET_NAME, D_PAGED, 0, '_', NULL, COFF_SWAP_TABLE)
This page took 0.345578 seconds and 4 git commands to generate.