* Makefile.in (DEMANGLING_STYLE): New define to set default
[deliverable/binutils-gdb.git] / bfd / bout.c
CommitLineData
fb3be09b
JG
1/* BFD back-end for Intel 960 b.out binaries.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Written by Cygnus Support.
7ed4093a 4
fb3be09b 5This file is part of BFD, the Binary File Descriptor library.
7ed4093a 6
fb3be09b 7This program is free software; you can redistribute it and/or modify
7ed4093a 8it under the terms of the GNU General Public License as published by
fb3be09b
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
7ed4093a 11
fb3be09b 12This program is distributed in the hope that it will be useful,
7ed4093a
SC
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
fb3be09b
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
7ed4093a
SC
20
21/* $Id$ */
22
7ed4093a 23#include "bfd.h"
bbc8d484 24#include "sysdep.h"
7ed4093a
SC
25#include "libbfd.h"
26
7ed4093a
SC
27#include "bout.h"
28
c3eb25fc 29#include "aout/stab_gnu.h"
359f1dee 30#include "libaout.h" /* BFD a.out internal data structures */
7ed4093a 31
7ed4093a
SC
32PROTO (static boolean, b_out_squirt_out_relocs,(bfd *abfd, asection *section));
33PROTO (static bfd_target *, b_out_callback, (bfd *));
34
f4d2c0bb
SC
35PROTO (boolean, aout_32_slurp_symbol_table, (bfd *abfd));
36PROTO (void , aout_32_write_syms, ());
7ed4093a 37
bbc8d484
JG
38/* Swaps the information in an executable header taken from a raw byte
39 stream memory image, into the internal exec_header structure. */
87059abb 40
bbc8d484
JG
41PROTO(void, bout_swap_exec_header_in,
42 (bfd *abfd,
43 struct external_exec *raw_bytes,
44 struct internal_exec *execp));
45
46void
47DEFUN(bout_swap_exec_header_in,(abfd, raw_bytes, execp),
48 bfd *abfd AND
49 struct external_exec *raw_bytes AND
50 struct internal_exec *execp)
7ed4093a 51{
bbc8d484
JG
52 struct external_exec *bytes = (struct external_exec *)raw_bytes;
53
54 /* Now fill in fields in the execp, from the bytes in the raw data. */
55 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
56 execp->a_text = GET_WORD (abfd, bytes->e_text);
57 execp->a_data = GET_WORD (abfd, bytes->e_data);
58 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
59 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
60 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
61 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
62 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
63 execp->a_tload = GET_WORD (abfd, bytes->e_tload);
64 execp->a_dload = GET_WORD (abfd, bytes->e_dload);
65 execp->a_talign = bytes->e_talign[0];
66 execp->a_dalign = bytes->e_dalign[0];
67 execp->a_balign = bytes->e_balign[0];
68}
7ed4093a 69
bbc8d484
JG
70/* Swaps the information in an internal exec header structure into the
71 supplied buffer ready for writing to disk. */
72
73PROTO(void, bout_swap_exec_header_out,
74 (bfd *abfd,
75 struct internal_exec *execp,
76 struct external_exec *raw_bytes));
77void
78DEFUN(bout_swap_exec_header_out,(abfd, execp, raw_bytes),
79 bfd *abfd AND
80 struct internal_exec *execp AND
81 struct external_exec *raw_bytes)
82{
83 struct external_exec *bytes = (struct external_exec *)raw_bytes;
84
85 /* Now fill in fields in the raw data, from the fields in the exec struct. */
86 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);
87 PUT_WORD (abfd, execp->a_text , bytes->e_text);
88 PUT_WORD (abfd, execp->a_data , bytes->e_data);
89 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
90 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
91 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
92 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
93 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
94 PUT_WORD (abfd, execp->a_tload , bytes->e_tload);
95 PUT_WORD (abfd, execp->a_dload , bytes->e_dload);
96 bytes->e_talign[0] = execp->a_talign;
97 bytes->e_dalign[0] = execp->a_dalign;
98 bytes->e_balign[0] = execp->a_balign;
99 bytes->e_unused[0] = 0; /* Clean structs are godly structs */
7ed4093a
SC
100}
101
bbc8d484 102
7ed4093a 103static bfd_target *
bbc8d484 104b_out_object_p (abfd)
7ed4093a
SC
105 bfd *abfd;
106{
87059abb 107 struct internal_exec anexec;
bbc8d484 108 struct external_exec exec_bytes;
7ed4093a 109
bbc8d484
JG
110 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
111 != EXEC_BYTES_SIZE) {
112 bfd_error = wrong_format;
7ed4093a
SC
113 return 0;
114 }
115
bbc8d484 116 anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
7ed4093a
SC
117
118 if (N_BADMAG (anexec)) {
119 bfd_error = wrong_format;
120 return 0;
121 }
bbc8d484
JG
122
123 bout_swap_exec_header_in (abfd, &exec_bytes, &anexec);
124 return aout_32_some_aout_object_p (abfd, &anexec, b_out_callback);
7ed4093a
SC
125}
126
bbc8d484 127
7ed4093a
SC
128/* Finish up the opening of a b.out file for reading. Fill in all the
129 fields that are not handled by common code. */
130
131static bfd_target *
132b_out_callback (abfd)
133 bfd *abfd;
134{
bbc8d484 135 struct internal_exec *execp = exec_hdr (abfd);
7ed4093a
SC
136 unsigned long bss_start;
137
7ed4093a 138 /* Architecture and machine type */
9e2dad8e
JG
139 bfd_set_arch_mach(abfd,
140 bfd_arch_i960, /* B.out only used on i960 */
141 bfd_mach_i960_core /* Default */
142 );
7ed4093a
SC
143
144 /* The positions of the string table and symbol table. */
bbc8d484
JG
145 obj_str_filepos (abfd) = N_STROFF (*execp);
146 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
7ed4093a
SC
147
148 /* The alignments of the sections */
149 obj_textsec (abfd)->alignment_power = execp->a_talign;
150 obj_datasec (abfd)->alignment_power = execp->a_dalign;
151 obj_bsssec (abfd)->alignment_power = execp->a_balign;
152
153 /* The starting addresses of the sections. */
bbc8d484
JG
154 obj_textsec (abfd)->vma = execp->a_tload;
155 obj_datasec (abfd)->vma = execp->a_dload;
e98e6ec1
SC
156
157 /* And reload the sizes, since the aout module zaps them */
158 obj_textsec (abfd)->_raw_size = execp->a_text;
159
bbc8d484 160 bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section */
c3eb25fc 161 obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
7ed4093a
SC
162
163 /* The file positions of the sections */
bbc8d484
JG
164 obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
165 obj_datasec (abfd)->filepos = N_DATOFF(*execp);
7ed4093a
SC
166
167 /* The file positions of the relocation info */
bbc8d484
JG
168 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
169 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp);
7ed4093a 170
e98e6ec1
SC
171 adata(abfd).page_size = 1; /* Not applicable. */
172 adata(abfd).segment_size = 1; /* Not applicable. */
173 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
c3eb25fc 174
7ed4093a
SC
175 return abfd->xvec;
176}
177
e98e6ec1 178struct bout_data_struct {
bbc8d484
JG
179 struct aoutdata a;
180 struct internal_exec e;
181};
7ed4093a
SC
182
183static boolean
184b_out_mkobject (abfd)
185 bfd *abfd;
186{
e98e6ec1 187 struct bout_data_struct *rawptr;
7ed4093a 188
e98e6ec1 189 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
bbc8d484 190 if (rawptr == NULL) {
e98e6ec1
SC
191 bfd_error = no_memory;
192 return false;
193 }
7ed4093a 194
e98e6ec1 195 abfd->tdata.bout_data = rawptr;
bbc8d484 196 exec_hdr (abfd) = &rawptr->e;
7ed4093a
SC
197
198 /* For simplicity's sake we just make all the sections right here. */
199 obj_textsec (abfd) = (asection *)NULL;
200 obj_datasec (abfd) = (asection *)NULL;
201 obj_bsssec (abfd) = (asection *)NULL;
202
203 bfd_make_section (abfd, ".text");
204 bfd_make_section (abfd, ".data");
205 bfd_make_section (abfd, ".bss");
206
207 return true;
208}
209
210static boolean
211b_out_write_object_contents (abfd)
212 bfd *abfd;
213{
bbc8d484 214 struct external_exec swapped_hdr;
7ed4093a 215
bbc8d484 216 exec_hdr (abfd)->a_info = BMAGIC;
7ed4093a 217
fc2f4c75
SC
218 exec_hdr (abfd)->a_text = obj_textsec (abfd)->_raw_size;
219 exec_hdr (abfd)->a_data = obj_datasec (abfd)->_raw_size;
220 exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->_raw_size;
7ed4093a
SC
221 exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist);
222 exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
223 exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) *
224 sizeof (struct relocation_info));
225 exec_hdr (abfd)->a_drsize = ((obj_datasec (abfd)->reloc_count) *
226 sizeof (struct relocation_info));
227
228 exec_hdr (abfd)->a_talign = obj_textsec (abfd)->alignment_power;
229 exec_hdr (abfd)->a_dalign = obj_datasec (abfd)->alignment_power;
230 exec_hdr (abfd)->a_balign = obj_bsssec (abfd)->alignment_power;
231
232 exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma;
233 exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma;
234
bbc8d484 235 bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
7ed4093a
SC
236
237 bfd_seek (abfd, 0L, SEEK_SET);
bbc8d484 238 bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd);
7ed4093a
SC
239
240 /* Now write out reloc info, followed by syms and strings */
241 if (bfd_get_symcount (abfd) != 0)
242 {
243 bfd_seek (abfd,
244 (long)(N_SYMOFF(*exec_hdr(abfd))), SEEK_SET);
245
f4d2c0bb 246 aout_32_write_syms (abfd);
7ed4093a
SC
247
248 bfd_seek (abfd, (long)(N_TROFF(*exec_hdr(abfd))), SEEK_SET);
249
250 if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false;
251 bfd_seek (abfd, (long)(N_DROFF(*exec_hdr(abfd))), SEEK_SET);
252
253 if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false;
254 }
255 return true;
256}
7ed4093a
SC
257\f
258/** Some reloc hackery */
259
260#define CALLS 0x66003800 /* Template for 'calls' instruction */
261#define BAL 0x0b000000 /* Template for 'bal' instruction */
262#define BAL_MASK 0x00ffffff
263
9e2dad8e 264static bfd_reloc_status_type
7ed4093a
SC
265callj_callback(abfd, reloc_entry, symbol_in, data, input_section)
266bfd *abfd;
267arelent *reloc_entry;
268asymbol *symbol_in;
fc2f4c75 269PTR data;
7ed4093a
SC
270asection *input_section;
271{
5022aea5 272 int word = bfd_get_32(abfd, (bfd_byte *)data + reloc_entry->address);
7ed4093a
SC
273 aout_symbol_type *symbol = aout_symbol(symbol_in);
274
275 if (IS_OTHER(symbol->other)) {
276 /* Call to a system procedure - replace code with system
5022aea5 277 procedure number */
7ed4093a 278 word = CALLS | (symbol->other - 1);
5022aea5 279 bfd_put_32(abfd, word, (bfd_byte *)data + reloc_entry->address); /* rplc */
7ed4093a
SC
280 return bfd_reloc_ok;
281 }
fc2f4c75 282
7ed4093a
SC
283 if (IS_CALLNAME(symbol->other)) {
284 aout_symbol_type *balsym = symbol+1;
285 /* The next symbol should be an N_BALNAME */
286 BFD_ASSERT(IS_BALNAME(balsym->other));
287
288 /* We are calling a leaf - so replace the call instruction
289 with a bal */
290
291 word = BAL |
292 (((word & BAL_MASK) +
293 balsym->symbol.section->output_offset +
294 balsym->symbol.section->output_section->vma+
295 balsym->symbol.value + reloc_entry->addend -
296 ( input_section->output_section->vma + input_section->output_offset))
297 & BAL_MASK);
298
5022aea5 299 bfd_put_32(abfd, word, (bfd_byte *) data + reloc_entry->address); /* rplc */
7ed4093a
SC
300 return bfd_reloc_ok;
301 }
302 return bfd_reloc_continue;
303
304}
305/* type rshift size bitsize pcrel bitpos absolute overflow check*/
306
307
308static reloc_howto_type howto_reloc_callj =
309HOWTO( 3, 0, 2, 24, true, 0, true, true, callj_callback,"callj", true, 0x00ffffff, 0x00ffffff,false);
310static reloc_howto_type howto_reloc_abs32 =
311HOWTO(1, 0, 2, 32, false, 0, true, true,0,"abs32", true, 0xffffffff,0xffffffff,false);
312static reloc_howto_type howto_reloc_pcrel24 =
313HOWTO(2, 0, 2, 24, true, 0, true, true,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false);
314
315/* Allocate enough room for all the reloc entries, plus pointers to them all */
316
317static boolean
318b_out_slurp_reloc_table (abfd, asect, symbols)
319 bfd *abfd;
320 sec_ptr asect;
321 asymbol **symbols;
322{
fc2f4c75
SC
323 register struct relocation_info *rptr;
324 unsigned int counter ;
325 arelent *cache_ptr ;
326 int extern_mask, pcrel_mask, callj_mask;
327
7ed4093a
SC
328 unsigned int count;
329 size_t reloc_size;
330 struct relocation_info *relocs;
331 arelent *reloc_cache;
332
333 if (asect->relocation) return true;
f4d2c0bb 334 if (!aout_32_slurp_symbol_table (abfd)) return false;
7ed4093a
SC
335
336 if (asect == obj_datasec (abfd)) {
fc2f4c75
SC
337 reloc_size = exec_hdr(abfd)->a_drsize;
338 goto doit;
339 }
7ed4093a
SC
340
341 if (asect == obj_textsec (abfd)) {
fc2f4c75
SC
342 reloc_size = exec_hdr(abfd)->a_trsize;
343 goto doit;
344 }
7ed4093a
SC
345
346 bfd_error = invalid_operation;
347 return false;
348
349 doit:
fc2f4c75 350 bfd_seek (abfd, (long)(asect->rel_filepos), SEEK_SET);
7ed4093a
SC
351 count = reloc_size / sizeof (struct relocation_info);
352
c3eb25fc 353 relocs = (struct relocation_info *) bfd_xmalloc (reloc_size);
7ed4093a 354 if (!relocs) {
fc2f4c75
SC
355 bfd_error = no_memory;
356 return false;
357 }
c3eb25fc 358 reloc_cache = (arelent *) bfd_xmalloc ((count+1) * sizeof (arelent));
7ed4093a 359 if (!reloc_cache) {
fc2f4c75
SC
360 free ((char*)relocs);
361 bfd_error = no_memory;
362 return false;
363 }
7ed4093a
SC
364
365 if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) {
fc2f4c75
SC
366 bfd_error = system_call_error;
367 free (reloc_cache);
368 free (relocs);
369 return false;
370 }
371
7ed4093a 372
7ed4093a 373
fc2f4c75
SC
374 if (abfd->xvec->header_byteorder_big_p) {
375 /* big-endian bit field allocation order */
7ed4093a
SC
376 pcrel_mask = 0x80;
377 extern_mask = 0x10;
378 callj_mask = 0x02;
379 } else {
fc2f4c75
SC
380 /* little-endian bit field allocation order */
381 pcrel_mask = 0x01;
382 extern_mask = 0x08;
383 callj_mask = 0x40;
384 }
385
386 for (rptr = relocs, cache_ptr = reloc_cache, counter = 0;
387 counter < count;
388 counter++, rptr++, cache_ptr++)
389 {
390 unsigned char *raw = (unsigned char *)rptr;
391 unsigned int symnum;
392 cache_ptr->address = bfd_h_get_32 (abfd, raw + 0);
393 if (abfd->xvec->header_byteorder_big_p)
394 {
395 symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6];
396 }
397 else
398 {
399 symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4];
7ed4093a
SC
400 }
401
fc2f4c75
SC
402 if (raw[7] & extern_mask)
403 {
404 /* if this is set then the r_index is a index into the symbol table;
405 * if the bit is not set then r_index contains a section map.
406 * we either fill in the sym entry with a pointer to the symbol,
407 * or point to the correct section
408 */
409 cache_ptr->sym_ptr_ptr = symbols + symnum;
410 cache_ptr->addend = 0;
411 } else
7ed4093a 412 {
fc2f4c75 413 /* in a.out symbols are relative to the beginning of the
7ed4093a
SC
414 * file rather than sections ?
415 * (look in translate_from_native_sym_flags)
fc2f4c75 416 * the reloc entry addend has added to it the offset into the
7ed4093a
SC
417 * file of the data, so subtract the base to make the reloc
418 * section relative */
419 cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
fc2f4c75
SC
420 switch (symnum)
421 {
422 case N_TEXT:
423 case N_TEXT | N_EXT:
424 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr;
425 cache_ptr->addend = - obj_textsec(abfd)->vma;
426 break;
427 case N_DATA:
428 case N_DATA | N_EXT:
429 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr;
430 cache_ptr->addend = - obj_datasec(abfd)->vma;
431 break;
432 case N_BSS:
433 case N_BSS | N_EXT:
434 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
435 cache_ptr->addend = - obj_bsssec(abfd)->vma;
436 break;
437 case N_ABS:
438 case N_ABS | N_EXT:
5022aea5 439 BFD_ASSERT(0);
fc2f4c75
SC
440 break;
441 default:
5022aea5 442 BFD_ASSERT(0);
fc2f4c75
SC
443 break;
444 }
7ed4093a
SC
445
446 }
447
fc2f4c75
SC
448 /* the i960 only has a few relocation types:
449 abs 32-bit and pcrel 24bit. except for callj's! */
450 if (raw[7] & callj_mask)
451 cache_ptr->howto = &howto_reloc_callj;
452 else if ( raw[7] & pcrel_mask)
453 cache_ptr->howto = &howto_reloc_pcrel24;
454 else
455 cache_ptr->howto = &howto_reloc_abs32;
7ed4093a
SC
456 }
457
fc2f4c75 458
7ed4093a
SC
459 free (relocs);
460 asect->relocation = reloc_cache;
461 asect->reloc_count = count;
e98e6ec1 462
fc2f4c75 463
7ed4093a
SC
464 return true;
465}
466
467
468static boolean
469b_out_squirt_out_relocs (abfd, section)
470 bfd *abfd;
471 asection *section;
472{
7ed4093a 473
fc2f4c75
SC
474 arelent **generic;
475 int r_extern;
476 int r_idx;
477 int r_addend;
478
7ed4093a
SC
479 unsigned int count = section->reloc_count;
480 struct relocation_info *native, *natptr;
481 size_t natsize = count * sizeof (struct relocation_info);
482 int extern_mask, pcrel_mask, len_2, callj_mask;
483 if (count == 0) return true;
484 generic = section->orelocation;
c3eb25fc 485 native = ((struct relocation_info *) bfd_xmalloc (natsize));
7ed4093a 486 if (!native) {
fc2f4c75
SC
487 bfd_error = no_memory;
488 return false;
489 }
7ed4093a 490
fc2f4c75
SC
491 if (abfd->xvec->header_byteorder_big_p)
492 {
493 /* Big-endian bit field allocation order */
494 pcrel_mask = 0x80;
495 extern_mask = 0x10;
496 len_2 = 0x40;
497 callj_mask = 0x02;
498 }
499else
500 {
501 /* Little-endian bit field allocation order */
502 pcrel_mask = 0x01;
503 extern_mask = 0x08;
504 len_2 = 0x04;
505 callj_mask = 0x40;
506 }
7ed4093a
SC
507
508 for (natptr = native; count > 0; --count, ++natptr, ++generic)
fc2f4c75
SC
509 {
510 arelent *g = *generic;
511 unsigned char *raw = (unsigned char *)natptr;
fc2f4c75
SC
512 asymbol *sym = *(g->sym_ptr_ptr);
513
514 asection *output_section = sym->section->output_section;
515 bfd_h_put_32(abfd, g->address, raw);
516 /* Find a type in the output format which matches the input howto -
517 * at the moment we assume input format == output format FIXME!!
518 */
519 /* FIXME: Need callj stuff here, and to check the howto entries to
520 be sure they are real for this architecture. */
521 if (g->howto== &howto_reloc_callj)
7ed4093a 522 {
fc2f4c75
SC
523 raw[7] = callj_mask + pcrel_mask + len_2;
524 }
525 else if (g->howto == &howto_reloc_pcrel24)
526 {
527 raw[7] = pcrel_mask +len_2;
528 }
529 else {
7ed4093a
SC
530 raw[7] = len_2;
531 }
5022aea5 532 if (output_section == &bfd_com_section
b96a430e 533 || output_section == &bfd_abs_section
5022aea5 534 || output_section == &bfd_und_section)
fc2f4c75
SC
535 {
536 /* Fill in symbol */
537 r_extern = 1;
538 r_idx = stoi((*(g->sym_ptr_ptr))->flags);
539 }
540 else
541 {
542 /* Just an ordinary section */
543 r_extern = 0;
544 r_idx = output_section->target_index;
7ed4093a
SC
545 }
546
fc2f4c75
SC
547 if (abfd->xvec->header_byteorder_big_p) {
548 raw[4] = (unsigned char) (r_idx >> 16);
549 raw[5] = (unsigned char) (r_idx >> 8);
550 raw[6] = (unsigned char) (r_idx );
551 } else {
552 raw[6] = (unsigned char) (r_idx >> 16);
553 raw[5] = (unsigned char) (r_idx>> 8);
554 raw[4] = (unsigned char) (r_idx );
555 }
556if (r_extern)
557 raw[7] |= extern_mask;
7ed4093a 558 }
fc2f4c75
SC
559
560 if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
561 free((PTR)native);
562 return false;
563 }
7ed4093a 564 free ((PTR)native);
fc2f4c75 565
7ed4093a
SC
566 return true;
567}
568
569/* This is stupid. This function should be a boolean predicate */
570static unsigned int
571b_out_canonicalize_reloc (abfd, section, relptr, symbols)
572 bfd *abfd;
573 sec_ptr section;
574 arelent **relptr;
575 asymbol **symbols;
576{
577 arelent *tblptr = section->relocation;
578 unsigned int count = 0;
579
580 if (!(tblptr || b_out_slurp_reloc_table (abfd, section, symbols))) return 0;
581 tblptr = section->relocation;
582 if (!tblptr) return 0;
583
584 for (; count++ < section->reloc_count;)
585 *relptr++ = tblptr++;
586
587 *relptr = 0;
588
589 return section->reloc_count;
590}
591
592static unsigned int
593b_out_get_reloc_upper_bound (abfd, asect)
594 bfd *abfd;
595 sec_ptr asect;
596{
597 if (bfd_get_format (abfd) != bfd_object) {
598 bfd_error = invalid_operation;
599 return 0;
600 }
601
602 if (asect == obj_datasec (abfd))
603 return (sizeof (arelent *) *
604 ((exec_hdr(abfd)->a_drsize / sizeof (struct relocation_info))
605 +1));
606
607 if (asect == obj_textsec (abfd))
608 return (sizeof (arelent *) *
609 ((exec_hdr(abfd)->a_trsize / sizeof (struct relocation_info))
610 +1));
611
612 bfd_error = invalid_operation;
613 return 0;
614}
615\f
616static boolean
617b_out_set_section_contents (abfd, section, location, offset, count)
618 bfd *abfd;
619 sec_ptr section;
620 unsigned char *location;
621 file_ptr offset;
622 int count;
623{
fc2f4c75 624
7ed4093a
SC
625 if (abfd->output_has_begun == false) { /* set by bfd.c handler */
626 if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) /*||
e98e6ec1 627 (obj_textsec (abfd)->_cooked_size == 0) || (obj_datasec (abfd)->_cooked_size == 0)*/) {
7ed4093a
SC
628 bfd_error = invalid_operation;
629 return false;
630 }
631
87059abb 632 obj_textsec (abfd)->filepos = sizeof(struct internal_exec);
7ed4093a 633 obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos
0d65ac52 634 + obj_textsec (abfd)->_raw_size;
7ed4093a
SC
635
636 }
637 /* regardless, once we know what we're doing, we might as well get going */
638 bfd_seek (abfd, section->filepos + offset, SEEK_SET);
639
640 if (count != 0) {
641 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false;
642 }
fc2f4c75 643 return true;
7ed4093a
SC
644}
645
646static boolean
647b_out_set_arch_mach (abfd, arch, machine)
648 bfd *abfd;
649 enum bfd_architecture arch;
650 unsigned long machine;
651{
9e2dad8e
JG
652 bfd_default_set_arch_mach(abfd, arch, machine);
653
7ed4093a
SC
654 if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */
655 return true;
656 if (arch == bfd_arch_i960) /* i960 default is OK */
657 switch (machine) {
658 case bfd_mach_i960_core:
659 case bfd_mach_i960_kb_sb:
660 case bfd_mach_i960_mc:
661 case bfd_mach_i960_xa:
662 case bfd_mach_i960_ca:
663 case bfd_mach_i960_ka_sa:
3a278e04 664 case 0:
7ed4093a
SC
665 return true;
666 default:
667 return false;
668 }
669
670 return false;
671}
672
673static int
fb3be09b
JG
674DEFUN(b_out_sizeof_headers,(ignore_abfd, ignore),
675 bfd *ignore_abfd AND
676 boolean ignore)
7ed4093a 677{
3a278e04 678 return sizeof(struct internal_exec);
7ed4093a 679}
87059abb
SC
680
681
682
683
7ed4093a
SC
684/* Build the transfer vectors for Big and Little-Endian B.OUT files. */
685
686/* We don't have core files. */
c3eb25fc
SC
687#define aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command
688#define aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal
87059abb 689#define aout_32_core_file_matches_executable_p \
7ed4093a
SC
690 _bfd_dummy_core_file_matches_executable_p
691
692/* We use BSD-Unix generic archive files. */
87059abb
SC
693#define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
694#define aout_32_generic_stat_arch_elt bfd_generic_stat_arch_elt
695#define aout_32_slurp_armap bfd_slurp_bsd_armap
696#define aout_32_slurp_extended_name_table bfd_true
697#define aout_32_write_armap bsd_write_armap
698#define aout_32_truncate_arname bfd_bsd_truncate_arname
7ed4093a
SC
699
700/* We override these routines from the usual a.out file routines. */
fb3be09b 701#define aout_32_canonicalize_reloc b_out_canonicalize_reloc
87059abb
SC
702#define aout_32_get_reloc_upper_bound b_out_get_reloc_upper_bound
703#define aout_32_set_section_contents b_out_set_section_contents
704#define aout_32_set_arch_mach b_out_set_arch_mach
705#define aout_32_sizeof_headers b_out_sizeof_headers
706
707#define aout_32_bfd_debug_info_start bfd_void
708#define aout_32_bfd_debug_info_end bfd_void
709#define aout_32_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
7ed4093a 710
fc2f4c75
SC
711#define aout_32_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
712#define aout_32_bfd_relax_section bfd_generic_relax_section
7ed4093a
SC
713bfd_target b_out_vec_big_host =
714{
715 "b.out.big", /* name */
9e2dad8e 716 bfd_target_aout_flavour,
7ed4093a
SC
717 false, /* data byte order is little */
718 true, /* hdr byte order is big */
719 (HAS_RELOC | EXEC_P | /* object flags */
720 HAS_LINENO | HAS_DEBUG |
721 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ),
722 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
723 ' ', /* ar_pad_char */
724 16, /* ar_max_namelen */
87059abb 725 2, /* minumum alignment power */
7ed4093a
SC
726
727_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
728_do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
bbc8d484 729 {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
7ed4093a
SC
730 bfd_generic_archive_p, _bfd_dummy_target},
731 {bfd_false, b_out_mkobject, /* bfd_set_format */
732 _bfd_generic_mkarchive, bfd_false},
733 {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
734 _bfd_write_archive_contents, bfd_false},
735
87059abb 736 JUMP_TABLE(aout_32)
7ed4093a
SC
737};
738
739
740bfd_target b_out_vec_little_host =
741{
742 "b.out.little", /* name */
9e2dad8e 743 bfd_target_aout_flavour,
7ed4093a
SC
744 false, /* data byte order is little */
745 false, /* header byte order is little */
746 (HAS_RELOC | EXEC_P | /* object flags */
747 HAS_LINENO | HAS_DEBUG |
748 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ),
749 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
750 ' ', /* ar_pad_char */
751 16, /* ar_max_namelen */
87059abb 752 2, /* minum align */
7ed4093a
SC
753_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
754_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
755
bbc8d484 756 {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
7ed4093a
SC
757 bfd_generic_archive_p, _bfd_dummy_target},
758 {bfd_false, b_out_mkobject, /* bfd_set_format */
759 _bfd_generic_mkarchive, bfd_false},
760 {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
761 _bfd_write_archive_contents, bfd_false},
87059abb 762 JUMP_TABLE(aout_32)
7ed4093a 763};
This page took 0.083986 seconds and 4 git commands to generate.