Commit | Line | Data |
---|---|---|
5c4491d3 | 1 | /* BFD back-end for Motorola 88000 COFF "Binary Compatibility Standard" files. |
dc810e39 | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000, |
3db64b00 | 3 | 2001, 2002, 2003, 2007 Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Cygnus Support. |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
3e110533 | 20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
21 | |
22 | #define M88 1 /* Customize various include files */ | |
252b5132 | 23 | #include "sysdep.h" |
3db64b00 | 24 | #include "bfd.h" |
252b5132 RH |
25 | #include "libbfd.h" |
26 | #include "coff/m88k.h" | |
27 | #include "coff/internal.h" | |
28 | #include "libcoff.h" | |
29 | ||
b34976b6 | 30 | static bfd_boolean m88k_is_local_label_name PARAMS ((bfd *, const char *)); |
252b5132 RH |
31 | static bfd_reloc_status_type m88k_special_reloc |
32 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
33 | static void rtype2howto PARAMS ((arelent *, struct internal_reloc *)); | |
34 | static void reloc_processing | |
35 | PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *)); | |
36 | ||
37 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) | |
38 | ||
dc810e39 AM |
39 | #define GET_SCNHDR_NRELOC H_GET_32 |
40 | #define GET_SCNHDR_NLNNO H_GET_32 | |
252b5132 RH |
41 | |
42 | /* On coff-m88k, local labels start with '@'. */ | |
43 | ||
44 | #define coff_bfd_is_local_label_name m88k_is_local_label_name | |
45 | ||
b34976b6 | 46 | static bfd_boolean |
252b5132 | 47 | m88k_is_local_label_name (abfd, name) |
5f771d47 | 48 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
49 | const char *name; |
50 | { | |
51 | return name[0] == '@'; | |
52 | } | |
53 | ||
b48499ec | 54 | static bfd_reloc_status_type |
252b5132 RH |
55 | m88k_special_reloc (abfd, reloc_entry, symbol, data, |
56 | input_section, output_bfd, error_message) | |
57 | bfd *abfd; | |
58 | arelent *reloc_entry; | |
59 | asymbol *symbol; | |
60 | PTR data; | |
61 | asection *input_section; | |
62 | bfd *output_bfd; | |
5f771d47 | 63 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
64 | { |
65 | reloc_howto_type *howto = reloc_entry->howto; | |
66 | ||
67 | switch (howto->type) | |
68 | { | |
69 | case R_HVRT16: | |
70 | case R_LVRT16: | |
71 | if (output_bfd != (bfd *) NULL) | |
72 | { | |
73 | /* This is a partial relocation, and we want to apply the | |
74 | relocation to the reloc entry rather than the raw data. | |
75 | Modify the reloc inplace to reflect what we now know. */ | |
76 | ||
77 | reloc_entry->address += input_section->output_offset; | |
78 | } | |
79 | else | |
80 | { | |
81 | bfd_vma output_base = 0; | |
82 | bfd_vma addr = reloc_entry->address; | |
83 | bfd_vma x = bfd_get_16 (abfd, (bfd_byte *) data + addr); | |
84 | asection *reloc_target_output_section; | |
85 | long relocation = 0; | |
86 | ||
5c4491d3 | 87 | /* Work out which section the relocation is targeted at and the |
252b5132 RH |
88 | initial relocation command value. */ |
89 | ||
90 | /* Get symbol value. (Common symbols are special.) */ | |
91 | if (bfd_is_com_section (symbol->section)) | |
92 | relocation = 0; | |
93 | else | |
94 | relocation = symbol->value; | |
95 | ||
96 | reloc_target_output_section = symbol->section->output_section; | |
97 | ||
98 | /* Convert input-section-relative symbol value to absolute. */ | |
99 | if (output_bfd) | |
100 | output_base = 0; | |
101 | else | |
102 | output_base = reloc_target_output_section->vma; | |
103 | ||
104 | relocation += output_base + symbol->section->output_offset; | |
105 | ||
106 | /* Add in supplied addend. */ | |
107 | relocation += ((reloc_entry->addend << howto->bitsize) + x); | |
108 | ||
109 | reloc_entry->addend = 0; | |
110 | ||
111 | relocation >>= (bfd_vma) howto->rightshift; | |
112 | ||
113 | /* Shift everything up to where it's going to be used */ | |
114 | ||
115 | relocation <<= (bfd_vma) howto->bitpos; | |
116 | ||
117 | if (relocation) | |
dc810e39 AM |
118 | bfd_put_16 (abfd, (bfd_vma) relocation, |
119 | (unsigned char *) data + addr); | |
252b5132 RH |
120 | } |
121 | ||
1049f94e | 122 | /* If we are not producing relocatable output, return an error if |
252b5132 RH |
123 | the symbol is not defined. */ |
124 | if (bfd_is_und_section (symbol->section) && output_bfd == (bfd *) NULL) | |
125 | return bfd_reloc_undefined; | |
126 | ||
127 | return bfd_reloc_ok; | |
128 | ||
129 | default: | |
130 | if (output_bfd != (bfd *) NULL) | |
131 | { | |
132 | /* This is a partial relocation, and we want to apply the | |
133 | relocation to the reloc entry rather than the raw data. | |
134 | Modify the reloc inplace to reflect what we now know. */ | |
135 | ||
136 | reloc_entry->address += input_section->output_offset; | |
137 | return bfd_reloc_ok; | |
138 | } | |
139 | break; | |
140 | } | |
141 | ||
142 | if (output_bfd == (bfd *) NULL) | |
143 | return bfd_reloc_continue; | |
144 | ||
145 | return bfd_reloc_ok; | |
146 | } | |
147 | ||
b48499ec | 148 | static reloc_howto_type howto_table[] = |
252b5132 RH |
149 | { |
150 | HOWTO (R_PCR16L, /* type */ | |
151 | 02, /* rightshift */ | |
152 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
153 | 16, /* bitsize */ | |
b34976b6 | 154 | TRUE, /* pc_relative */ |
252b5132 RH |
155 | 0, /* bitpos */ |
156 | complain_overflow_signed, /* complain_on_overflow */ | |
157 | m88k_special_reloc, /* special_function */ | |
158 | "PCR16L", /* name */ | |
b34976b6 | 159 | FALSE, /* partial_inplace */ |
252b5132 RH |
160 | 0x0000ffff, /* src_mask */ |
161 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 162 | TRUE), /* pcrel_offset */ |
252b5132 RH |
163 | |
164 | HOWTO (R_PCR26L, /* type */ | |
165 | 02, /* rightshift */ | |
166 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
167 | 26, /* bitsize */ | |
b34976b6 | 168 | TRUE, /* pc_relative */ |
252b5132 RH |
169 | 0, /* bitpos */ |
170 | complain_overflow_signed, /* complain_on_overflow */ | |
171 | m88k_special_reloc, /* special_function */ | |
172 | "PCR26L", /* name */ | |
b34976b6 | 173 | FALSE, /* partial_inplace */ |
252b5132 RH |
174 | 0x03ffffff, /* src_mask */ |
175 | 0x03ffffff, /* dst_mask */ | |
b34976b6 | 176 | TRUE), /* pcrel_offset */ |
252b5132 RH |
177 | |
178 | HOWTO (R_VRT16, /* type */ | |
179 | 00, /* rightshift */ | |
180 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
181 | 16, /* bitsize */ | |
b34976b6 | 182 | FALSE, /* pc_relative */ |
252b5132 RH |
183 | 0, /* bitpos */ |
184 | complain_overflow_bitfield, /* complain_on_overflow */ | |
185 | m88k_special_reloc, /* special_function */ | |
186 | "VRT16", /* name */ | |
b34976b6 | 187 | FALSE, /* partial_inplace */ |
252b5132 RH |
188 | 0x0000ffff, /* src_mask */ |
189 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 190 | TRUE), /* pcrel_offset */ |
252b5132 RH |
191 | |
192 | HOWTO (R_HVRT16, /* type */ | |
193 | 16, /* rightshift */ | |
194 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
195 | 16, /* bitsize */ | |
b34976b6 | 196 | FALSE, /* pc_relative */ |
252b5132 RH |
197 | 0, /* bitpos */ |
198 | complain_overflow_dont, /* complain_on_overflow */ | |
199 | m88k_special_reloc, /* special_function */ | |
200 | "HVRT16", /* name */ | |
b34976b6 | 201 | FALSE, /* partial_inplace */ |
252b5132 RH |
202 | 0x0000ffff, /* src_mask */ |
203 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 204 | TRUE), /* pcrel_offset */ |
252b5132 RH |
205 | |
206 | HOWTO (R_LVRT16, /* type */ | |
207 | 00, /* rightshift */ | |
208 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
209 | 16, /* bitsize */ | |
b34976b6 | 210 | FALSE, /* pc_relative */ |
252b5132 RH |
211 | 0, /* bitpos */ |
212 | complain_overflow_dont, /* complain_on_overflow */ | |
213 | m88k_special_reloc, /* special_function */ | |
214 | "LVRT16", /* name */ | |
b34976b6 | 215 | FALSE, /* partial_inplace */ |
252b5132 RH |
216 | 0x0000ffff, /* src_mask */ |
217 | 0x0000ffff, /* dst_mask */ | |
b34976b6 | 218 | TRUE), /* pcrel_offset */ |
252b5132 RH |
219 | |
220 | HOWTO (R_VRT32, /* type */ | |
221 | 00, /* rightshift */ | |
222 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
223 | 32, /* bitsize */ | |
b34976b6 | 224 | FALSE, /* pc_relative */ |
252b5132 RH |
225 | 0, /* bitpos */ |
226 | complain_overflow_bitfield, /* complain_on_overflow */ | |
227 | m88k_special_reloc, /* special_function */ | |
228 | "VRT32", /* name */ | |
b34976b6 | 229 | FALSE, /* partial_inplace */ |
252b5132 RH |
230 | 0xffffffff, /* src_mask */ |
231 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 232 | TRUE), /* pcrel_offset */ |
252b5132 RH |
233 | }; |
234 | ||
235 | /* Code to turn an external r_type into a pointer to an entry in the | |
236 | above howto table. */ | |
237 | static void | |
238 | rtype2howto (cache_ptr, dst) | |
239 | arelent *cache_ptr; | |
240 | struct internal_reloc *dst; | |
241 | { | |
242 | if (dst->r_type >= R_PCR16L && dst->r_type <= R_VRT32) | |
243 | { | |
244 | cache_ptr->howto = howto_table + dst->r_type - R_PCR16L; | |
245 | } | |
246 | else | |
247 | { | |
248 | BFD_ASSERT (0); | |
249 | } | |
250 | } | |
251 | ||
252 | #define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst) | |
253 | ||
252b5132 | 254 | /* Code to swap in the reloc offset */ |
dc810e39 AM |
255 | #define SWAP_IN_RELOC_OFFSET H_GET_16 |
256 | #define SWAP_OUT_RELOC_OFFSET H_PUT_16 | |
252b5132 | 257 | |
252b5132 RH |
258 | #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ |
259 | reloc_processing(relent, reloc, symbols, abfd, section) | |
260 | ||
261 | static void | |
262 | reloc_processing (relent, reloc, symbols, abfd, section) | |
263 | arelent *relent; | |
264 | struct internal_reloc *reloc; | |
265 | asymbol **symbols; | |
266 | bfd *abfd; | |
267 | asection *section; | |
268 | { | |
269 | relent->address = reloc->r_vaddr; | |
270 | rtype2howto (relent, reloc); | |
271 | ||
272 | if (((int) reloc->r_symndx) > 0) | |
273 | { | |
274 | relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; | |
275 | } | |
276 | else | |
277 | { | |
278 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
279 | } | |
280 | ||
281 | relent->addend = reloc->r_offset; | |
282 | relent->address -= section->vma; | |
283 | } | |
284 | ||
285 | #define BADMAG(x) MC88BADMAG(x) | |
286 | #include "coffcode.h" | |
287 | ||
288 | #undef coff_write_armap | |
289 | ||
3fa78519 | 290 | CREATE_BIG_COFF_TARGET_VEC (m88kbcs_vec, "coff-m88kbcs", 0, 0, '_', NULL, COFF_SWAP_TABLE) |