* elf32-mips.c (mips_elf_find_nearest_line): Set SEC_HAS_CONTENTS
[deliverable/binutils-gdb.git] / bfd / coff-i960.c
CommitLineData
6812b607 1/* BFD back-end for Intel 960 COFF files.
943fbd5b 2 Copyright (C) 1990, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
3b4f1a5d 3 Written by Cygnus Support.
fc723380 4
3b4f1a5d 5This file is part of BFD, the Binary File Descriptor library.
4a81b561 6
3b4f1a5d 7This program is free software; you can redistribute it and/or modify
4a81b561 8it under the terms of the GNU General Public License as published by
3b4f1a5d
SC
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
4a81b561 11
3b4f1a5d 12This program is distributed in the hope that it will be useful,
4a81b561
DHW
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
3b4f1a5d 18along with this program; if not, write to the Free Software
943fbd5b 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
4a81b561 20
4a81b561 21#define I960 1
fc723380
JG
22#define BADMAG(x) I960BADMAG(x)
23
4a81b561 24#include "bfd.h"
3b4f1a5d 25#include "sysdep.h"
4a81b561 26#include "libbfd.h"
9872a49c 27#include "obstack.h"
8070f29d
KR
28#include "coff/i960.h"
29#include "coff/internal.h"
4a81b561 30#include "libcoff.h" /* to allow easier abstraction-breaking */
6812b607
ILT
31
32static bfd_reloc_status_type optcall_callback
33 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
5e694c29
JMD
34static bfd_reloc_status_type coff_i960_relocate
35 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
36
943fbd5b
KR
37#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
38
39/* The i960 does not support an MMU, so COFF_PAGE_SIZE can be
40 arbitrarily small. */
41#define COFF_PAGE_SIZE 1
42
294eaca4 43#define COFF_LONG_FILENAMES
4a81b561 44
4a81b561
DHW
45#define CALLS 0x66003800 /* Template for 'calls' instruction */
46#define BAL 0x0b000000 /* Template for 'bal' instruction */
47#define BAL_MASK 0x00ffffff
48
3b4f1a5d 49static bfd_reloc_status_type
6812b607 50optcall_callback (abfd, reloc_entry, symbol_in, data,
943fbd5b 51 input_section, ignore_bfd, error_message)
6812b607
ILT
52 bfd *abfd;
53 arelent *reloc_entry;
54 asymbol *symbol_in;
55 PTR data;
943fbd5b 56 asection *input_section;
6812b607
ILT
57 bfd *ignore_bfd;
58 char **error_message;
4a81b561
DHW
59{
60 /* This item has already been relocated correctly, but we may be
61 * able to patch in yet better code - done by digging out the
62 * correct info on this symbol */
3b4f1a5d 63 bfd_reloc_status_type result;
4a81b561
DHW
64 coff_symbol_type *cs = coffsymbol(symbol_in);
65
943fbd5b
KR
66 /* Don't do anything with symbols which aren't tied up yet,
67 except move the reloc. */
68 if (bfd_is_und_section (cs->symbol.section)) {
69 reloc_entry->address += input_section->output_offset;
70 return bfd_reloc_ok;
71 }
72
fc723380
JG
73 /* So the target symbol has to be of coff type, and the symbol
74 has to have the correct native information within it */
6812b607
ILT
75 if ((bfd_asymbol_flavour(&cs->symbol) != bfd_target_coff_flavour)
76 || (cs->native == (combined_entry_type *)NULL))
77 {
78 /* This is interesting, consider the case where we're outputting coff
79 from a mix n match input, linking from coff to a symbol defined in a
80 bout file will cause this match to be true. Should I complain? This
81 will only work if the bout symbol is non leaf. */
82 *error_message =
83 (char *) "uncertain calling convention for non-COFF symbol";
84 result = bfd_reloc_dangerous;
85 }
86 else
87 {
3b4f1a5d 88 switch (cs->native->u.syment.n_sclass)
4a81b561
DHW
89 {
90 case C_LEAFSTAT:
91 case C_LEAFEXT:
92 /* This is a call to a leaf procedure, replace instruction with a bal
6812b607 93 to the correct location. */
4a81b561 94 {
3b4f1a5d 95 union internal_auxent *aux = &((cs->native+2)->u.auxent);
8070f29d 96 int word = bfd_get_32(abfd, (bfd_byte *)data + reloc_entry->address);
3b4f1a5d
SC
97 int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value);
98 BFD_ASSERT(cs->native->u.syment.n_numaux==2);
8e3c8f47 99
6812b607
ILT
100 /* We replace the original call instruction with a bal to
101 the bal entry point - the offset of which is described in
102 the 2nd auxent of the original symbol. We keep the native
103 sym and auxents untouched, so the delta between the two
104 is the offset of the bal entry point. */
8e3c8f47 105 word = ((word + olf) & BAL_MASK) | BAL;
8070f29d 106 bfd_put_32(abfd, word, (bfd_byte *) data + reloc_entry->address);
4a81b561
DHW
107 }
108 result = bfd_reloc_ok;
109 break;
110 case C_SCALL:
3b4f1a5d
SC
111 /* This is a call to a system call, replace with a calls to # */
112 BFD_ASSERT(0);
113 result = bfd_reloc_ok;
4a81b561
DHW
114 break;
115 default:
116 result = bfd_reloc_ok;
117 break;
118 }
119 }
120 return result;
121}
122
1b8a11d4
JMD
123/* i960 COFF is used by VxWorks 5.1. However, VxWorks 5.1 does not
124 appear to correctly handle a reloc against a symbol defined in the
125 same object file. It appears to simply discard such relocs, rather
126 than adding their values into the object file. We handle this here
127 by converting all relocs against defined symbols into relocs
128 against the section symbol, when generating a relocateable output
129 file. */
5e694c29
JMD
130
131static bfd_reloc_status_type
132coff_i960_relocate (abfd, reloc_entry, symbol, data, input_section,
133 output_bfd, error_message)
134 bfd *abfd;
135 arelent *reloc_entry;
136 asymbol *symbol;
137 PTR data;
138 asection *input_section;
139 bfd *output_bfd;
140 char **error_message;
141{
943fbd5b 142 asection *osec;
1b8a11d4
JMD
143
144 if (output_bfd == NULL)
5e694c29 145 {
1b8a11d4
JMD
146 /* Not generating relocateable output file. */
147 return bfd_reloc_continue;
5e694c29
JMD
148 }
149
1b8a11d4
JMD
150 if (bfd_is_und_section (bfd_get_section (symbol)))
151 {
152 /* Symbol is not defined, so no need to worry about it. */
153 return bfd_reloc_continue;
154 }
155
943fbd5b
KR
156 if (bfd_is_com_section (bfd_get_section (symbol)))
157 {
158 /* I don't really know what the right action is for a common
159 symbol. */
160 return bfd_reloc_continue;
161 }
162
1b8a11d4 163 /* Convert the reloc to use the section symbol. FIXME: This method
943fbd5b
KR
164 is ridiculous. Fortunately, we don't use the used_by_bfd field
165 in COFF. */
166 osec = bfd_get_section (symbol)->output_section;
167 if (osec->used_by_bfd != NULL)
168 reloc_entry->sym_ptr_ptr = (asymbol **) osec->used_by_bfd;
169 else
1b8a11d4 170 {
943fbd5b
KR
171 const char *sec_name;
172 asymbol **syms, **sym_end;
173
174 sec_name = bfd_get_section_name (output_bfd, osec);
175 syms = bfd_get_outsymbols (output_bfd);
176 sym_end = syms + bfd_get_symcount (output_bfd);
177 for (; syms < sym_end; syms++)
1b8a11d4 178 {
943fbd5b
KR
179 if (bfd_asymbol_name (*syms) != NULL
180 && (*syms)->value == 0
181 && strcmp (!(*syms)->section->output_section->name, sec_name))
182 {
183 osec->used_by_bfd = (PTR) syms;
184 reloc_entry->sym_ptr_ptr = syms;
185 break;
186 }
1b8a11d4 187 }
1b8a11d4 188
943fbd5b
KR
189 if (syms >= sym_end)
190 abort ();
191 }
1b8a11d4
JMD
192
193 /* Let bfd_perform_relocation do its thing, which will include
194 stuffing the symbol addend into the object file. */
5e694c29
JMD
195 return bfd_reloc_continue;
196}
197
8070f29d 198static reloc_howto_type howto_rellong =
ffeef0bb 199 HOWTO ((unsigned int) R_RELLONG, 0, 2, 32,false, 0,
5e694c29
JMD
200 complain_overflow_bitfield, coff_i960_relocate,"rellong", true,
201 0xffffffff, 0xffffffff, 0);
8070f29d 202static reloc_howto_type howto_iprmed =
5e694c29
JMD
203 HOWTO (R_IPRMED, 0, 2, 24,true,0, complain_overflow_signed,
204 coff_i960_relocate, "iprmed ", true, 0x00ffffff, 0x00ffffff, 0);
8070f29d 205static reloc_howto_type howto_optcall =
ffeef0bb
KR
206 HOWTO (R_OPTCALL, 0,2,24,true,0, complain_overflow_signed,
207 optcall_callback, "optcall", true, 0x00ffffff, 0x00ffffff, 0);
4a81b561 208
943fbd5b 209static reloc_howto_type *
6812b607
ILT
210coff_i960_reloc_type_lookup (abfd, code)
211 bfd *abfd;
212 bfd_reloc_code_real_type code;
8070f29d
KR
213{
214 switch (code)
215 {
216 default:
217 return 0;
218 case BFD_RELOC_I960_CALLJ:
219 return &howto_optcall;
220 case BFD_RELOC_32:
22aabad5 221 case BFD_RELOC_CTOR:
8070f29d
KR
222 return &howto_rellong;
223 case BFD_RELOC_24_PCREL:
224 return &howto_iprmed;
225 }
226}
4a81b561 227
924bbb38 228/* The real code is in coffcode.h */
4a81b561 229
3b4f1a5d 230#define RTYPE2HOWTO(cache_ptr, dst) \
8070f29d
KR
231{ \
232 reloc_howto_type *howto_ptr; \
233 switch ((dst)->r_type) { \
234 case 17: howto_ptr = &howto_rellong; break; \
235 case 25: howto_ptr = &howto_iprmed; break; \
236 case 27: howto_ptr = &howto_optcall; break; \
237 default: howto_ptr = 0; break; \
238 } \
943fbd5b 239 (cache_ptr)->howto = howto_ptr; \
8070f29d 240 }
3b4f1a5d 241
7ed4093a 242#include "coffcode.h"
4a81b561 243
6812b607
ILT
244#undef coff_bfd_reloc_type_lookup
245#define coff_bfd_reloc_type_lookup coff_i960_reloc_type_lookup
246
ffeef0bb 247const bfd_target icoff_little_vec =
4a81b561 248{
9872a49c 249 "coff-Intel-little", /* name */
3b4f1a5d 250 bfd_target_coff_flavour,
4a81b561 251 false, /* data byte order is little */
9872a49c 252 false, /* header byte order is little */
4a81b561
DHW
253
254 (HAS_RELOC | EXEC_P | /* object flags */
255 HAS_LINENO | HAS_DEBUG |
6812b607 256 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4a81b561
DHW
257
258 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
22aabad5 259 '_', /* leading underscore */
4a81b561
DHW
260 '/', /* ar_pad_char */
261 15, /* ar_max_namelen */
4a81b561 262
294eaca4 263 3, /* minimum alignment power */
6812b607
ILT
264 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
265 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
266 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
267 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
268 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
269 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
4a81b561 270
294eaca4
SC
271 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
272 bfd_generic_archive_p, _bfd_dummy_target},
273 {bfd_false, coff_mkobject, /* bfd_set_format */
274 _bfd_generic_mkarchive, bfd_false},
275 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
276 _bfd_write_archive_contents, bfd_false},
6812b607
ILT
277
278 BFD_JUMP_TABLE_GENERIC (coff),
279 BFD_JUMP_TABLE_COPY (coff),
280 BFD_JUMP_TABLE_CORE (_bfd_nocore),
281 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
282 BFD_JUMP_TABLE_SYMBOLS (coff),
283 BFD_JUMP_TABLE_RELOCS (coff),
284 BFD_JUMP_TABLE_WRITE (coff),
285 BFD_JUMP_TABLE_LINK (coff),
22aabad5 286 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 287
8070f29d 288 COFF_SWAP_TABLE,
8070f29d 289};
4a81b561
DHW
290
291
ffeef0bb 292const bfd_target icoff_big_vec =
4a81b561 293{
9872a49c 294 "coff-Intel-big", /* name */
3b4f1a5d 295 bfd_target_coff_flavour,
4a81b561 296 false, /* data byte order is little */
9872a49c 297 true, /* header byte order is big */
4a81b561
DHW
298
299 (HAS_RELOC | EXEC_P | /* object flags */
300 HAS_LINENO | HAS_DEBUG |
6812b607 301 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4a81b561
DHW
302
303 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
22aabad5 304 '_', /* leading underscore */
4a81b561
DHW
305 '/', /* ar_pad_char */
306 15, /* ar_max_namelen */
4a81b561 307
3b4f1a5d 308 3, /* minimum alignment power */
6812b607
ILT
309bfd_getl64, bfd_getl_signed_64, bfd_putl64,
310 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
311 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
312bfd_getb64, bfd_getb_signed_64, bfd_putb64,
313 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
314 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
4a81b561 315
2b1d8a50
JG
316 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
317 bfd_generic_archive_p, _bfd_dummy_target},
318 {bfd_false, coff_mkobject, /* bfd_set_format */
319 _bfd_generic_mkarchive, bfd_false},
320 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
321 _bfd_write_archive_contents, bfd_false},
6812b607
ILT
322
323 BFD_JUMP_TABLE_GENERIC (coff),
324 BFD_JUMP_TABLE_COPY (coff),
325 BFD_JUMP_TABLE_CORE (_bfd_nocore),
326 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
327 BFD_JUMP_TABLE_SYMBOLS (coff),
328 BFD_JUMP_TABLE_RELOCS (coff),
329 BFD_JUMP_TABLE_WRITE (coff),
330 BFD_JUMP_TABLE_LINK (coff),
22aabad5 331 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 332
8070f29d 333 COFF_SWAP_TABLE,
fc723380 334};
This page took 0.153153 seconds and 4 git commands to generate.