K&R compiler fixes
[binutils.git] / bfd / bout.c
blobc230e18c0ea69818e36f5b2b4efac3786bb859b4
1 /* BFD back-end for Intel 960 b.out binaries.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
26 #include "bfdlink.h"
27 #include "genlink.h"
28 #include "bout.h"
30 #include "aout/stab_gnu.h"
31 #include "libaout.h" /* BFD a.out internal data structures */
34 static int aligncode PARAMS ((bfd *abfd, asection *input_section,
35 arelent *r, unsigned int shrink));
36 static void perform_slip PARAMS ((bfd *abfd, unsigned int slip,
37 asection *input_section, bfd_vma value));
38 static boolean b_out_squirt_out_relocs PARAMS ((bfd *abfd, asection *section));
39 static const bfd_target *b_out_callback PARAMS ((bfd *));
40 static bfd_reloc_status_type calljx_callback
41 PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR src, PTR dst,
42 asection *));
43 static bfd_reloc_status_type callj_callback
44 PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR data,
45 unsigned int srcidx, unsigned int dstidx, asection *, boolean));
46 static bfd_vma get_value PARAMS ((arelent *, struct bfd_link_info *,
47 asection *));
48 static int abs32code PARAMS ((bfd *, asection *, arelent *,
49 unsigned int, struct bfd_link_info *));
50 static boolean b_out_bfd_relax_section PARAMS ((bfd *, asection *,
51 struct bfd_link_info *,
52 boolean *));
53 static bfd_byte *b_out_bfd_get_relocated_section_contents
54 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
55 bfd_byte *, boolean, asymbol **));
57 /* Swaps the information in an executable header taken from a raw byte
58 stream memory image, into the internal exec_header structure. */
60 void
61 bout_swap_exec_header_in (abfd, raw_bytes, execp)
62 bfd *abfd;
63 struct external_exec *raw_bytes;
64 struct internal_exec *execp;
66 struct external_exec *bytes = (struct external_exec *)raw_bytes;
68 /* Now fill in fields in the execp, from the bytes in the raw data. */
69 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);
70 execp->a_text = GET_WORD (abfd, bytes->e_text);
71 execp->a_data = GET_WORD (abfd, bytes->e_data);
72 execp->a_bss = GET_WORD (abfd, bytes->e_bss);
73 execp->a_syms = GET_WORD (abfd, bytes->e_syms);
74 execp->a_entry = GET_WORD (abfd, bytes->e_entry);
75 execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
76 execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
77 execp->a_tload = GET_WORD (abfd, bytes->e_tload);
78 execp->a_dload = GET_WORD (abfd, bytes->e_dload);
79 execp->a_talign = bytes->e_talign[0];
80 execp->a_dalign = bytes->e_dalign[0];
81 execp->a_balign = bytes->e_balign[0];
82 execp->a_relaxable = bytes->e_relaxable[0];
85 /* Swaps the information in an internal exec header structure into the
86 supplied buffer ready for writing to disk. */
88 PROTO(void, bout_swap_exec_header_out,
89 (bfd *abfd,
90 struct internal_exec *execp,
91 struct external_exec *raw_bytes));
92 void
93 bout_swap_exec_header_out (abfd, execp, raw_bytes)
94 bfd *abfd;
95 struct internal_exec *execp;
96 struct external_exec *raw_bytes;
98 struct external_exec *bytes = (struct external_exec *)raw_bytes;
100 /* Now fill in fields in the raw data, from the fields in the exec struct. */
101 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);
102 PUT_WORD (abfd, execp->a_text , bytes->e_text);
103 PUT_WORD (abfd, execp->a_data , bytes->e_data);
104 PUT_WORD (abfd, execp->a_bss , bytes->e_bss);
105 PUT_WORD (abfd, execp->a_syms , bytes->e_syms);
106 PUT_WORD (abfd, execp->a_entry , bytes->e_entry);
107 PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize);
108 PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);
109 PUT_WORD (abfd, execp->a_tload , bytes->e_tload);
110 PUT_WORD (abfd, execp->a_dload , bytes->e_dload);
111 bytes->e_talign[0] = execp->a_talign;
112 bytes->e_dalign[0] = execp->a_dalign;
113 bytes->e_balign[0] = execp->a_balign;
114 bytes->e_relaxable[0] = execp->a_relaxable;
118 static const bfd_target *
119 b_out_object_p (abfd)
120 bfd *abfd;
122 struct internal_exec anexec;
123 struct external_exec exec_bytes;
125 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
126 != EXEC_BYTES_SIZE) {
127 if (bfd_get_error () != bfd_error_system_call)
128 bfd_set_error (bfd_error_wrong_format);
129 return 0;
132 anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
134 if (N_BADMAG (anexec)) {
135 bfd_set_error (bfd_error_wrong_format);
136 return 0;
139 bout_swap_exec_header_in (abfd, &exec_bytes, &anexec);
140 return aout_32_some_aout_object_p (abfd, &anexec, b_out_callback);
144 /* Finish up the opening of a b.out file for reading. Fill in all the
145 fields that are not handled by common code. */
147 static const bfd_target *
148 b_out_callback (abfd)
149 bfd *abfd;
151 struct internal_exec *execp = exec_hdr (abfd);
152 unsigned long bss_start;
154 /* Architecture and machine type */
155 bfd_set_arch_mach(abfd,
156 bfd_arch_i960, /* B.out only used on i960 */
157 bfd_mach_i960_core /* Default */
160 /* The positions of the string table and symbol table. */
161 obj_str_filepos (abfd) = N_STROFF (*execp);
162 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
164 /* The alignments of the sections */
165 obj_textsec (abfd)->alignment_power = execp->a_talign;
166 obj_datasec (abfd)->alignment_power = execp->a_dalign;
167 obj_bsssec (abfd)->alignment_power = execp->a_balign;
169 /* The starting addresses of the sections. */
170 obj_textsec (abfd)->vma = execp->a_tload;
171 obj_datasec (abfd)->vma = execp->a_dload;
173 obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
174 obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
176 /* And reload the sizes, since the aout module zaps them */
177 obj_textsec (abfd)->_raw_size = execp->a_text;
179 bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section */
180 obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
182 obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
184 /* The file positions of the sections */
185 obj_textsec (abfd)->filepos = N_TXTOFF(*execp);
186 obj_datasec (abfd)->filepos = N_DATOFF(*execp);
188 /* The file positions of the relocation info */
189 obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
190 obj_datasec (abfd)->rel_filepos = N_DROFF(*execp);
192 adata(abfd).page_size = 1; /* Not applicable. */
193 adata(abfd).segment_size = 1; /* Not applicable. */
194 adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
196 if (execp->a_relaxable)
197 abfd->flags |= BFD_IS_RELAXABLE;
198 return abfd->xvec;
201 struct bout_data_struct {
202 struct aoutdata a;
203 struct internal_exec e;
206 static boolean
207 b_out_mkobject (abfd)
208 bfd *abfd;
210 struct bout_data_struct *rawptr;
212 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct));
213 if (rawptr == NULL)
214 return false;
216 abfd->tdata.bout_data = rawptr;
217 exec_hdr (abfd) = &rawptr->e;
219 obj_textsec (abfd) = (asection *)NULL;
220 obj_datasec (abfd) = (asection *)NULL;
221 obj_bsssec (abfd) = (asection *)NULL;
223 return true;
226 static int
227 b_out_symbol_cmp (a, b)
228 struct aout_symbol **a, **b;
230 asection *sec;
231 bfd_vma av, bv;
233 /* Primary key is address */
234 sec = bfd_get_section (&(*a)->symbol);
235 av = sec->output_section->vma + sec->output_offset + (*a)->symbol.value;
236 sec = bfd_get_section (&(*b)->symbol);
237 bv = sec->output_section->vma + sec->output_offset + (*b)->symbol.value;
239 if (av < bv)
240 return -1;
241 if (av > bv)
242 return 1;
244 /* Secondary key puts CALLNAME syms last and BALNAME syms first, so
245 that they have the best chance of being contiguous. */
246 if (IS_BALNAME ((*a)->other) || IS_CALLNAME ((*b)->other))
247 return -1;
248 if (IS_CALLNAME ((*a)->other) || IS_BALNAME ((*b)->other))
249 return 1;
251 return 0;
254 static boolean
255 b_out_write_object_contents (abfd)
256 bfd *abfd;
258 struct external_exec swapped_hdr;
260 if (! aout_32_make_sections (abfd))
261 return false;
263 exec_hdr (abfd)->a_info = BMAGIC;
265 exec_hdr (abfd)->a_text = obj_textsec (abfd)->_raw_size;
266 exec_hdr (abfd)->a_data = obj_datasec (abfd)->_raw_size;
267 exec_hdr (abfd)->a_bss = obj_bsssec (abfd)->_raw_size;
268 exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd) * sizeof (struct nlist);
269 exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);
270 exec_hdr (abfd)->a_trsize = ((obj_textsec (abfd)->reloc_count) *
271 sizeof (struct relocation_info));
272 exec_hdr (abfd)->a_drsize = ((obj_datasec (abfd)->reloc_count) *
273 sizeof (struct relocation_info));
275 exec_hdr (abfd)->a_talign = obj_textsec (abfd)->alignment_power;
276 exec_hdr (abfd)->a_dalign = obj_datasec (abfd)->alignment_power;
277 exec_hdr (abfd)->a_balign = obj_bsssec (abfd)->alignment_power;
279 exec_hdr (abfd)->a_tload = obj_textsec (abfd)->vma;
280 exec_hdr (abfd)->a_dload = obj_datasec (abfd)->vma;
282 bout_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);
284 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
285 || (bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd)
286 != EXEC_BYTES_SIZE))
287 return false;
289 /* Now write out reloc info, followed by syms and strings */
290 if (bfd_get_symcount (abfd) != 0)
292 /* Make sure {CALL,BAL}NAME symbols remain adjacent on output
293 by sorting. This is complicated by the fact that stabs are
294 also ordered. Solve this by shifting all stabs to the end
295 in order, then sorting the rest. */
297 asymbol **outsyms, **p, **q;
299 outsyms = bfd_get_outsymbols (abfd);
300 p = outsyms + bfd_get_symcount (abfd);
302 for (q = p--; p >= outsyms; p--)
304 if ((*p)->flags & BSF_DEBUGGING)
306 asymbol *t = *--q;
307 *q = *p;
308 *p = t;
312 if (q > outsyms)
313 qsort (outsyms, q - outsyms, sizeof(asymbol*), b_out_symbol_cmp);
315 /* Back to your regularly scheduled program. */
317 if (bfd_seek (abfd, (file_ptr)(N_SYMOFF(*exec_hdr(abfd))), SEEK_SET)
318 != 0)
319 return false;
321 if (! aout_32_write_syms (abfd))
322 return false;
324 if (bfd_seek (abfd, (file_ptr)(N_TROFF(*exec_hdr(abfd))), SEEK_SET) != 0)
325 return false;
327 if (!b_out_squirt_out_relocs (abfd, obj_textsec (abfd))) return false;
328 if (bfd_seek (abfd, (file_ptr)(N_DROFF(*exec_hdr(abfd))), SEEK_SET)
329 != 0)
330 return false;
332 if (!b_out_squirt_out_relocs (abfd, obj_datasec (abfd))) return false;
334 return true;
337 /** Some reloc hackery */
339 #define CALLS 0x66003800 /* Template for 'calls' instruction */
340 #define BAL 0x0b000000 /* Template for 'bal' instruction */
341 #define BAL_MASK 0x00ffffff
342 #define BALX 0x85f00000 /* Template for 'balx' instruction */
343 #define BALX_MASK 0x0007ffff
344 #define CALL 0x09000000
345 #define PCREL13_MASK 0x1fff
348 #define output_addr(sec) ((sec)->output_offset+(sec)->output_section->vma)
350 /* Magic to turn callx into calljx */
351 static bfd_reloc_status_type
352 calljx_callback (abfd, link_info, reloc_entry, src, dst, input_section)
353 bfd *abfd;
354 struct bfd_link_info *link_info;
355 arelent *reloc_entry;
356 PTR src;
357 PTR dst;
358 asection *input_section;
360 int word = bfd_get_32 (abfd, src);
361 asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr);
362 aout_symbol_type *symbol = aout_symbol (symbol_in);
363 bfd_vma value;
365 value = get_value (reloc_entry, link_info, input_section);
367 if (IS_CALLNAME (symbol->other))
369 aout_symbol_type *balsym = symbol+1;
370 int inst = bfd_get_32 (abfd, (bfd_byte *) src-4);
371 /* The next symbol should be an N_BALNAME */
372 BFD_ASSERT (IS_BALNAME (balsym->other));
373 inst &= BALX_MASK;
374 inst |= BALX;
375 bfd_put_32 (abfd, inst, (bfd_byte *) dst-4);
376 symbol = balsym;
377 value = (symbol->symbol.value
378 + output_addr (symbol->symbol.section));
381 word += value + reloc_entry->addend;
383 bfd_put_32(abfd, word, dst);
384 return bfd_reloc_ok;
388 /* Magic to turn call into callj */
389 static bfd_reloc_status_type
390 callj_callback (abfd, link_info, reloc_entry, data, srcidx, dstidx,
391 input_section, shrinking)
392 bfd *abfd;
393 struct bfd_link_info *link_info;
394 arelent *reloc_entry;
395 PTR data;
396 unsigned int srcidx;
397 unsigned int dstidx;
398 asection *input_section;
399 boolean shrinking;
401 int word = bfd_get_32 (abfd, (bfd_byte *) data + srcidx);
402 asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr);
403 aout_symbol_type *symbol = aout_symbol (symbol_in);
404 bfd_vma value;
406 value = get_value (reloc_entry, link_info, input_section);
408 if (IS_OTHER(symbol->other))
410 /* Call to a system procedure - replace code with system
411 procedure number. */
412 word = CALLS | (symbol->other - 1);
414 else if (IS_CALLNAME(symbol->other))
416 aout_symbol_type *balsym = symbol+1;
418 /* The next symbol should be an N_BALNAME. */
419 BFD_ASSERT(IS_BALNAME(balsym->other));
421 /* We are calling a leaf, so replace the call instruction with a
422 bal. */
423 word = BAL | ((word
424 + output_addr (balsym->symbol.section)
425 + balsym->symbol.value + reloc_entry->addend
426 - dstidx
427 - output_addr (input_section))
428 & BAL_MASK);
430 else if ((symbol->symbol.flags & BSF_SECTION_SYM) != 0)
432 /* A callj against a symbol in the same section is a fully
433 resolved relative call. We don't need to do anything here.
434 If the symbol is not in the same section, I'm not sure what
435 to do; fortunately, this case will probably never arise. */
436 BFD_ASSERT (! shrinking);
437 BFD_ASSERT (symbol->symbol.section == input_section);
439 else
441 word = CALL | (((word & BAL_MASK)
442 + value
443 + reloc_entry->addend
444 - (shrinking ? dstidx : 0)
445 - output_addr (input_section))
446 & BAL_MASK);
448 bfd_put_32(abfd, word, (bfd_byte *) data + dstidx);
449 return bfd_reloc_ok;
452 /* type rshift size bitsize pcrel bitpos absolute overflow check*/
454 #define ABS32CODE 0
455 #define ABS32CODE_SHRUNK 1
456 #define PCREL24 2
457 #define CALLJ 3
458 #define ABS32 4
459 #define PCREL13 5
460 #define ABS32_MAYBE_RELAXABLE 1
461 #define ABS32_WAS_RELAXABLE 2
463 #define ALIGNER 10
464 #define ALIGNDONE 11
465 static reloc_howto_type howto_reloc_callj =
466 HOWTO(CALLJ, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callj", true, 0x00ffffff, 0x00ffffff,false);
467 static reloc_howto_type howto_reloc_abs32 =
468 HOWTO(ABS32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"abs32", true, 0xffffffff,0xffffffff,false);
469 static reloc_howto_type howto_reloc_pcrel24 =
470 HOWTO(PCREL24, 0, 2, 24, true, 0, complain_overflow_signed,0,"pcrel24", true, 0x00ffffff,0x00ffffff,false);
472 static reloc_howto_type howto_reloc_pcrel13 =
473 HOWTO(PCREL13, 0, 2, 13, true, 0, complain_overflow_signed,0,"pcrel13", true, 0x00001fff,0x00001fff,false);
476 static reloc_howto_type howto_reloc_abs32codeshrunk =
477 HOWTO(ABS32CODE_SHRUNK, 0, 2, 24, true, 0, complain_overflow_signed, 0,"callx->callj", true, 0x00ffffff, 0x00ffffff,false);
479 static reloc_howto_type howto_reloc_abs32code =
480 HOWTO(ABS32CODE, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"callx", true, 0xffffffff,0xffffffff,false);
482 static reloc_howto_type howto_align_table[] = {
483 HOWTO (ALIGNER, 0, 0x1, 0, false, 0, complain_overflow_dont, 0, "align16", false, 0, 0, false),
484 HOWTO (ALIGNER, 0, 0x3, 0, false, 0, complain_overflow_dont, 0, "align32", false, 0, 0, false),
485 HOWTO (ALIGNER, 0, 0x7, 0, false, 0, complain_overflow_dont, 0, "align64", false, 0, 0, false),
486 HOWTO (ALIGNER, 0, 0xf, 0, false, 0, complain_overflow_dont, 0, "align128", false, 0, 0, false),
489 static reloc_howto_type howto_done_align_table[] = {
490 HOWTO (ALIGNDONE, 0x1, 0x1, 0, false, 0, complain_overflow_dont, 0, "donealign16", false, 0, 0, false),
491 HOWTO (ALIGNDONE, 0x3, 0x3, 0, false, 0, complain_overflow_dont, 0, "donealign32", false, 0, 0, false),
492 HOWTO (ALIGNDONE, 0x7, 0x7, 0, false, 0, complain_overflow_dont, 0, "donealign64", false, 0, 0, false),
493 HOWTO (ALIGNDONE, 0xf, 0xf, 0, false, 0, complain_overflow_dont, 0, "donealign128", false, 0, 0, false),
496 static reloc_howto_type *
497 b_out_bfd_reloc_type_lookup (abfd, code)
498 bfd *abfd ATTRIBUTE_UNUSED;
499 bfd_reloc_code_real_type code;
501 switch (code)
503 default:
504 return 0;
505 case BFD_RELOC_I960_CALLJ:
506 return &howto_reloc_callj;
507 case BFD_RELOC_32:
508 case BFD_RELOC_CTOR:
509 return &howto_reloc_abs32;
510 case BFD_RELOC_24_PCREL:
511 return &howto_reloc_pcrel24;
515 /* Allocate enough room for all the reloc entries, plus pointers to them all */
517 static boolean
518 b_out_slurp_reloc_table (abfd, asect, symbols)
519 bfd *abfd;
520 sec_ptr asect;
521 asymbol **symbols;
523 register struct relocation_info *rptr;
524 unsigned int counter ;
525 arelent *cache_ptr ;
526 int extern_mask, pcrel_mask, callj_mask, length_shift;
527 int incode_mask;
528 int size_mask;
529 bfd_vma prev_addr = 0;
530 unsigned int count;
531 size_t reloc_size;
532 struct relocation_info *relocs;
533 arelent *reloc_cache;
535 if (asect->relocation)
536 return true;
537 if (!aout_32_slurp_symbol_table (abfd))
538 return false;
540 if (asect == obj_datasec (abfd)) {
541 reloc_size = exec_hdr(abfd)->a_drsize;
542 goto doit;
545 if (asect == obj_textsec (abfd)) {
546 reloc_size = exec_hdr(abfd)->a_trsize;
547 goto doit;
550 if (asect == obj_bsssec (abfd)) {
551 reloc_size = 0;
552 goto doit;
555 bfd_set_error (bfd_error_invalid_operation);
556 return false;
558 doit:
559 if (bfd_seek (abfd, (file_ptr)(asect->rel_filepos), SEEK_SET) != 0)
560 return false;
561 count = reloc_size / sizeof (struct relocation_info);
563 relocs = (struct relocation_info *) bfd_malloc (reloc_size);
564 if (!relocs && reloc_size != 0)
565 return false;
566 reloc_cache = (arelent *) bfd_malloc ((count+1) * sizeof (arelent));
567 if (!reloc_cache) {
568 if (relocs != NULL)
569 free ((char*)relocs);
570 return false;
573 if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) {
574 free (reloc_cache);
575 if (relocs != NULL)
576 free (relocs);
577 return false;
582 if (bfd_header_big_endian (abfd)) {
583 /* big-endian bit field allocation order */
584 pcrel_mask = 0x80;
585 extern_mask = 0x10;
586 incode_mask = 0x08;
587 callj_mask = 0x02;
588 size_mask = 0x20;
589 length_shift = 5;
590 } else {
591 /* little-endian bit field allocation order */
592 pcrel_mask = 0x01;
593 extern_mask = 0x08;
594 incode_mask = 0x10;
595 callj_mask = 0x40;
596 size_mask = 0x02;
597 length_shift = 1;
600 for (rptr = relocs, cache_ptr = reloc_cache, counter = 0;
601 counter < count;
602 counter++, rptr++, cache_ptr++)
604 unsigned char *raw = (unsigned char *)rptr;
605 unsigned int symnum;
606 cache_ptr->address = bfd_h_get_32 (abfd, raw + 0);
607 cache_ptr->howto = 0;
608 if (bfd_header_big_endian (abfd))
610 symnum = (raw[4] << 16) | (raw[5] << 8) | raw[6];
612 else
614 symnum = (raw[6] << 16) | (raw[5] << 8) | raw[4];
617 if (raw[7] & extern_mask)
619 /* if this is set then the r_index is a index into the symbol table;
620 * if the bit is not set then r_index contains a section map.
621 * we either fill in the sym entry with a pointer to the symbol,
622 * or point to the correct section
624 cache_ptr->sym_ptr_ptr = symbols + symnum;
625 cache_ptr->addend = 0;
626 } else
628 /* in a.out symbols are relative to the beginning of the
629 * file rather than sections ?
630 * (look in translate_from_native_sym_flags)
631 * the reloc entry addend has added to it the offset into the
632 * file of the data, so subtract the base to make the reloc
633 * section relative */
634 int s;
636 /* sign-extend symnum from 24 bits to whatever host uses */
637 s = symnum;
638 if (s & (1 << 23))
639 s |= (~0) << 24;
641 cache_ptr->sym_ptr_ptr = (asymbol **)NULL;
642 switch (s)
644 case N_TEXT:
645 case N_TEXT | N_EXT:
646 cache_ptr->sym_ptr_ptr = obj_textsec(abfd)->symbol_ptr_ptr;
647 cache_ptr->addend = - obj_textsec(abfd)->vma;
648 break;
649 case N_DATA:
650 case N_DATA | N_EXT:
651 cache_ptr->sym_ptr_ptr = obj_datasec(abfd)->symbol_ptr_ptr;
652 cache_ptr->addend = - obj_datasec(abfd)->vma;
653 break;
654 case N_BSS:
655 case N_BSS | N_EXT:
656 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
657 cache_ptr->addend = - obj_bsssec(abfd)->vma;
658 break;
659 case N_ABS:
660 case N_ABS | N_EXT:
661 cache_ptr->sym_ptr_ptr = obj_bsssec(abfd)->symbol_ptr_ptr;
662 cache_ptr->addend = 0;
663 break;
664 case -2: /* .align */
665 if (raw[7] & pcrel_mask)
667 cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3];
668 cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
670 else
672 /* .org? */
673 abort ();
675 cache_ptr->addend = 0;
676 break;
677 default:
678 BFD_ASSERT(0);
679 break;
684 /* the i960 only has a few relocation types:
685 abs 32-bit and pcrel 24bit. except for callj's! */
686 if (cache_ptr->howto != 0)
688 else if (raw[7] & callj_mask)
690 cache_ptr->howto = &howto_reloc_callj;
692 else if ( raw[7] & pcrel_mask)
694 if (raw[7] & size_mask)
695 cache_ptr->howto = &howto_reloc_pcrel13;
696 else
697 cache_ptr->howto = &howto_reloc_pcrel24;
699 else
701 if (raw[7] & incode_mask)
703 cache_ptr->howto = &howto_reloc_abs32code;
705 else
707 cache_ptr->howto = &howto_reloc_abs32;
710 if (cache_ptr->address < prev_addr)
712 /* Ouch! this reloc is out of order, insert into the right place
714 arelent tmp;
715 arelent *cursor = cache_ptr-1;
716 bfd_vma stop = cache_ptr->address;
717 tmp = *cache_ptr;
718 while (cursor->address > stop && cursor >= reloc_cache)
720 cursor[1] = cursor[0];
721 cursor--;
723 cursor[1] = tmp;
725 else
727 prev_addr = cache_ptr->address;
732 if (relocs != NULL)
733 free (relocs);
734 asect->relocation = reloc_cache;
735 asect->reloc_count = count;
738 return true;
742 static boolean
743 b_out_squirt_out_relocs (abfd, section)
744 bfd *abfd;
745 asection *section;
747 arelent **generic;
748 int r_extern = 0;
749 int r_idx;
750 int incode_mask;
751 int len_1;
752 unsigned int count = section->reloc_count;
753 struct relocation_info *native, *natptr;
754 size_t natsize = count * sizeof (struct relocation_info);
755 int extern_mask, pcrel_mask, len_2, callj_mask;
756 if (count == 0) return true;
757 generic = section->orelocation;
758 native = ((struct relocation_info *) bfd_malloc (natsize));
759 if (!native && natsize != 0)
760 return false;
762 if (bfd_header_big_endian (abfd))
764 /* Big-endian bit field allocation order */
765 pcrel_mask = 0x80;
766 extern_mask = 0x10;
767 len_2 = 0x40;
768 len_1 = 0x20;
769 callj_mask = 0x02;
770 incode_mask = 0x08;
772 else
774 /* Little-endian bit field allocation order */
775 pcrel_mask = 0x01;
776 extern_mask = 0x08;
777 len_2 = 0x04;
778 len_1 = 0x02;
779 callj_mask = 0x40;
780 incode_mask = 0x10;
783 for (natptr = native; count > 0; --count, ++natptr, ++generic)
785 arelent *g = *generic;
786 unsigned char *raw = (unsigned char *)natptr;
787 asymbol *sym = *(g->sym_ptr_ptr);
789 asection *output_section = sym->section->output_section;
791 bfd_h_put_32(abfd, g->address, raw);
792 /* Find a type in the output format which matches the input howto -
793 * at the moment we assume input format == output format FIXME!!
795 r_idx = 0;
796 /* FIXME: Need callj stuff here, and to check the howto entries to
797 be sure they are real for this architecture. */
798 if (g->howto== &howto_reloc_callj)
800 raw[7] = callj_mask + pcrel_mask + len_2;
802 else if (g->howto == &howto_reloc_pcrel24)
804 raw[7] = pcrel_mask + len_2;
806 else if (g->howto == &howto_reloc_pcrel13)
808 raw[7] = pcrel_mask + len_1;
810 else if (g->howto == &howto_reloc_abs32code)
812 raw[7] = len_2 + incode_mask;
814 else if (g->howto >= howto_align_table
815 && g->howto <= (howto_align_table
816 + sizeof (howto_align_table) / sizeof (howto_align_table[0])
817 - 1))
819 /* symnum == -2; extern_mask not set, pcrel_mask set */
820 r_idx = -2;
821 r_extern = 0;
822 raw[7] = (pcrel_mask
823 | ((g->howto - howto_align_table) << 1));
825 else {
826 raw[7] = len_2;
829 if (r_idx != 0)
830 /* already mucked with r_extern, r_idx */;
831 else if (bfd_is_com_section (output_section)
832 || bfd_is_abs_section (output_section)
833 || bfd_is_und_section (output_section))
836 if (bfd_abs_section_ptr->symbol == sym)
838 /* Whoops, looked like an abs symbol, but is really an offset
839 from the abs section */
840 r_idx = 0;
841 r_extern = 0;
843 else
845 /* Fill in symbol */
847 r_extern = 1;
848 r_idx = (*g->sym_ptr_ptr)->udata.i;
851 else
853 /* Just an ordinary section */
854 r_extern = 0;
855 r_idx = output_section->target_index;
858 if (bfd_header_big_endian (abfd)) {
859 raw[4] = (unsigned char) (r_idx >> 16);
860 raw[5] = (unsigned char) (r_idx >> 8);
861 raw[6] = (unsigned char) (r_idx );
862 } else {
863 raw[6] = (unsigned char) (r_idx >> 16);
864 raw[5] = (unsigned char) (r_idx>> 8);
865 raw[4] = (unsigned char) (r_idx );
867 if (r_extern)
868 raw[7] |= extern_mask;
871 if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {
872 free((PTR)native);
873 return false;
875 free ((PTR)native);
877 return true;
880 /* This is stupid. This function should be a boolean predicate */
881 static long
882 b_out_canonicalize_reloc (abfd, section, relptr, symbols)
883 bfd *abfd;
884 sec_ptr section;
885 arelent **relptr;
886 asymbol **symbols;
888 arelent *tblptr;
889 unsigned int count;
891 if ((section->flags & SEC_CONSTRUCTOR) != 0)
893 arelent_chain *chain = section->constructor_chain;
894 for (count = 0; count < section->reloc_count; count++)
896 *relptr++ = &chain->relent;
897 chain = chain->next;
900 else
902 if (section->relocation == NULL
903 && ! b_out_slurp_reloc_table (abfd, section, symbols))
904 return -1;
906 tblptr = section->relocation;
907 for (count = 0; count++ < section->reloc_count;)
908 *relptr++ = tblptr++;
911 *relptr = NULL;
913 return section->reloc_count;
916 static long
917 b_out_get_reloc_upper_bound (abfd, asect)
918 bfd *abfd;
919 sec_ptr asect;
921 if (bfd_get_format (abfd) != bfd_object) {
922 bfd_set_error (bfd_error_invalid_operation);
923 return -1;
926 if (asect->flags & SEC_CONSTRUCTOR)
927 return sizeof (arelent *) * (asect->reloc_count + 1);
929 if (asect == obj_datasec (abfd))
930 return (sizeof (arelent *) *
931 ((exec_hdr(abfd)->a_drsize / sizeof (struct relocation_info))
932 +1));
934 if (asect == obj_textsec (abfd))
935 return (sizeof (arelent *) *
936 ((exec_hdr(abfd)->a_trsize / sizeof (struct relocation_info))
937 +1));
939 if (asect == obj_bsssec (abfd))
940 return 0;
942 bfd_set_error (bfd_error_invalid_operation);
943 return -1;
946 static boolean
947 b_out_set_section_contents (abfd, section, location, offset, count)
948 bfd *abfd;
949 asection *section;
950 PTR location;
951 file_ptr offset;
952 bfd_size_type count;
955 if (abfd->output_has_begun == false) { /* set by bfd.c handler */
956 if (! aout_32_make_sections (abfd))
957 return false;
959 obj_textsec (abfd)->filepos = sizeof(struct internal_exec);
960 obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos
961 + obj_textsec (abfd)->_raw_size;
964 /* regardless, once we know what we're doing, we might as well get going */
965 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
966 return false;
968 if (count != 0) {
969 return (bfd_write ((PTR)location, 1, count, abfd) == count) ?true:false;
971 return true;
974 static boolean
975 b_out_set_arch_mach (abfd, arch, machine)
976 bfd *abfd;
977 enum bfd_architecture arch;
978 unsigned long machine;
980 bfd_default_set_arch_mach(abfd, arch, machine);
982 if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */
983 return true;
984 if (arch == bfd_arch_i960) /* i960 default is OK */
985 switch (machine) {
986 case bfd_mach_i960_core:
987 case bfd_mach_i960_kb_sb:
988 case bfd_mach_i960_mc:
989 case bfd_mach_i960_xa:
990 case bfd_mach_i960_ca:
991 case bfd_mach_i960_ka_sa:
992 case bfd_mach_i960_jx:
993 case bfd_mach_i960_hx:
994 case 0:
995 return true;
996 default:
997 return false;
1000 return false;
1003 static int
1004 b_out_sizeof_headers (ignore_abfd, ignore)
1005 bfd *ignore_abfd ATTRIBUTE_UNUSED;
1006 boolean ignore ATTRIBUTE_UNUSED;
1008 return sizeof(struct internal_exec);
1013 /************************************************************************/
1014 static bfd_vma
1015 get_value (reloc, link_info, input_section)
1016 arelent *reloc;
1017 struct bfd_link_info *link_info;
1018 asection *input_section;
1020 bfd_vma value;
1021 asymbol *symbol = *(reloc->sym_ptr_ptr);
1023 /* A symbol holds a pointer to a section, and an offset from the
1024 base of the section. To relocate, we find where the section will
1025 live in the output and add that in */
1027 if (bfd_is_und_section (symbol->section))
1029 struct bfd_link_hash_entry *h;
1031 /* The symbol is undefined in this BFD. Look it up in the
1032 global linker hash table. FIXME: This should be changed when
1033 we convert b.out to use a specific final_link function and
1034 change the interface to bfd_relax_section to not require the
1035 generic symbols. */
1036 h = bfd_wrapped_link_hash_lookup (input_section->owner, link_info,
1037 bfd_asymbol_name (symbol),
1038 false, false, true);
1039 if (h != (struct bfd_link_hash_entry *) NULL
1040 && (h->type == bfd_link_hash_defined
1041 || h->type == bfd_link_hash_defweak))
1042 value = h->u.def.value + output_addr (h->u.def.section);
1043 else if (h != (struct bfd_link_hash_entry *) NULL
1044 && h->type == bfd_link_hash_common)
1045 value = h->u.c.size;
1046 else
1048 if (! ((*link_info->callbacks->undefined_symbol)
1049 (link_info, bfd_asymbol_name (symbol),
1050 input_section->owner, input_section, reloc->address,
1051 true)))
1052 abort ();
1053 value = 0;
1056 else
1058 value = symbol->value + output_addr (symbol->section);
1061 /* Add the value contained in the relocation */
1062 value += reloc->addend;
1064 return value;
1067 static void
1068 perform_slip (abfd, slip, input_section, value)
1069 bfd *abfd;
1070 unsigned int slip;
1071 asection *input_section;
1072 bfd_vma value;
1074 asymbol **s;
1076 s = _bfd_generic_link_get_symbols (abfd);
1077 BFD_ASSERT (s != (asymbol **) NULL);
1079 /* Find all symbols past this point, and make them know
1080 what's happened */
1081 while (*s)
1083 asymbol *p = *s;
1084 if (p->section == input_section)
1086 /* This was pointing into this section, so mangle it */
1087 if (p->value > value)
1089 p->value -=slip;
1090 if (p->udata.p != NULL)
1092 struct generic_link_hash_entry *h;
1094 h = (struct generic_link_hash_entry *) p->udata.p;
1095 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
1096 h->root.u.def.value -= slip;
1097 BFD_ASSERT (h->root.u.def.value == p->value);
1101 s++;
1106 /* This routine works out if the thing we want to get to can be
1107 reached with a 24bit offset instead of a 32 bit one.
1108 If it can, then it changes the amode */
1110 static int
1111 abs32code (abfd, input_section, r, shrink, link_info)
1112 bfd *abfd;
1113 asection *input_section;
1114 arelent *r;
1115 unsigned int shrink;
1116 struct bfd_link_info *link_info;
1118 bfd_vma value = get_value (r, link_info, input_section);
1119 bfd_vma dot = output_addr (input_section) + r->address;
1120 bfd_vma gap;
1122 /* See if the address we're looking at within 2^23 bytes of where
1123 we are, if so then we can use a small branch rather than the
1124 jump we were going to */
1126 gap = value - (dot - shrink);
1129 if (-1<<23 < (long)gap && (long)gap < 1<<23 )
1131 /* Change the reloc type from 32bitcode possible 24, to 24bit
1132 possible 32 */
1134 r->howto = &howto_reloc_abs32codeshrunk;
1135 /* The place to relc moves back by four bytes */
1136 r->address -=4;
1138 /* This will be four bytes smaller in the long run */
1139 shrink += 4 ;
1140 perform_slip (abfd, 4, input_section, r->address-shrink + 4);
1142 return shrink;
1145 static int
1146 aligncode (abfd, input_section, r, shrink)
1147 bfd *abfd;
1148 asection *input_section;
1149 arelent *r;
1150 unsigned int shrink;
1152 bfd_vma dot = output_addr (input_section) + r->address;
1153 bfd_vma gap;
1154 bfd_vma old_end;
1155 bfd_vma new_end;
1156 int shrink_delta;
1157 int size = r->howto->size;
1159 /* Reduce the size of the alignment so that it's still aligned but
1160 smaller - the current size is already the same size as or bigger
1161 than the alignment required. */
1163 /* calculate the first byte following the padding before we optimize */
1164 old_end = ((dot + size ) & ~size) + size+1;
1165 /* work out where the new end will be - remember that we're smaller
1166 than we used to be */
1167 new_end = ((dot - shrink + size) & ~size);
1169 /* This is the new end */
1170 gap = old_end - ((dot + size) & ~size);
1172 shrink_delta = (old_end - new_end) - shrink;
1174 if (shrink_delta)
1176 /* Change the reloc so that it knows how far to align to */
1177 r->howto = howto_done_align_table + (r->howto - howto_align_table);
1179 /* Encode the stuff into the addend - for future use we need to
1180 know how big the reloc used to be */
1181 r->addend = old_end - dot + r->address;
1183 /* This will be N bytes smaller in the long run, adjust all the symbols */
1184 perform_slip (abfd, shrink_delta, input_section, r->address - shrink);
1185 shrink += shrink_delta;
1187 return shrink;
1190 static boolean
1191 b_out_bfd_relax_section (abfd, i, link_info, again)
1192 bfd *abfd;
1193 asection *i;
1194 struct bfd_link_info *link_info;
1195 boolean *again;
1197 /* Get enough memory to hold the stuff */
1198 bfd *input_bfd = i->owner;
1199 asection *input_section = i;
1200 int shrink = 0 ;
1201 arelent **reloc_vector = NULL;
1202 long reloc_size = bfd_get_reloc_upper_bound(input_bfd,
1203 input_section);
1205 if (reloc_size < 0)
1206 return false;
1208 /* We only run this relaxation once. It might work to run it
1209 multiple times, but it hasn't been tested. */
1210 *again = false;
1212 if (reloc_size)
1214 long reloc_count;
1216 reloc_vector = (arelent **) bfd_malloc (reloc_size);
1217 if (reloc_vector == NULL && reloc_size != 0)
1218 goto error_return;
1220 /* Get the relocs and think about them */
1221 reloc_count =
1222 bfd_canonicalize_reloc (input_bfd, input_section, reloc_vector,
1223 _bfd_generic_link_get_symbols (input_bfd));
1224 if (reloc_count < 0)
1225 goto error_return;
1226 if (reloc_count > 0)
1228 arelent **parent;
1229 for (parent = reloc_vector; *parent; parent++)
1231 arelent *r = *parent;
1232 switch (r->howto->type)
1234 case ALIGNER:
1235 /* An alignment reloc */
1236 shrink = aligncode (abfd, input_section, r, shrink);
1237 break;
1238 case ABS32CODE:
1239 /* A 32bit reloc in an addressing mode */
1240 shrink = abs32code (input_bfd, input_section, r, shrink,
1241 link_info);
1242 break;
1243 case ABS32CODE_SHRUNK:
1244 shrink+=4;
1245 break;
1250 input_section->_cooked_size = input_section->_raw_size - shrink;
1252 if (reloc_vector != NULL)
1253 free (reloc_vector);
1254 return true;
1255 error_return:
1256 if (reloc_vector != NULL)
1257 free (reloc_vector);
1258 return false;
1261 static bfd_byte *
1262 b_out_bfd_get_relocated_section_contents (output_bfd, link_info, link_order,
1263 data, relocateable, symbols)
1264 bfd *output_bfd;
1265 struct bfd_link_info *link_info;
1266 struct bfd_link_order *link_order;
1267 bfd_byte *data;
1268 boolean relocateable;
1269 asymbol **symbols;
1271 /* Get enough memory to hold the stuff */
1272 bfd *input_bfd = link_order->u.indirect.section->owner;
1273 asection *input_section = link_order->u.indirect.section;
1274 long reloc_size = bfd_get_reloc_upper_bound (input_bfd,
1275 input_section);
1276 arelent **reloc_vector = NULL;
1277 long reloc_count;
1279 if (reloc_size < 0)
1280 goto error_return;
1282 /* If producing relocateable output, don't bother to relax. */
1283 if (relocateable)
1284 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
1285 link_order,
1286 data, relocateable,
1287 symbols);
1289 reloc_vector = (arelent **) bfd_malloc (reloc_size);
1290 if (reloc_vector == NULL && reloc_size != 0)
1291 goto error_return;
1293 input_section->reloc_done = 1;
1295 /* read in the section */
1296 BFD_ASSERT (true == bfd_get_section_contents (input_bfd,
1297 input_section,
1298 data,
1300 input_section->_raw_size));
1302 reloc_count = bfd_canonicalize_reloc (input_bfd,
1303 input_section,
1304 reloc_vector,
1305 symbols);
1306 if (reloc_count < 0)
1307 goto error_return;
1308 if (reloc_count > 0)
1310 arelent **parent = reloc_vector;
1311 arelent *reloc ;
1313 unsigned int dst_address = 0;
1314 unsigned int src_address = 0;
1315 unsigned int run;
1316 unsigned int idx;
1318 /* Find how long a run we can do */
1319 while (dst_address < link_order->size)
1321 reloc = *parent;
1322 if (reloc)
1324 /* Note that the relaxing didn't tie up the addresses in the
1325 relocation, so we use the original address to work out the
1326 run of non-relocated data */
1327 BFD_ASSERT (reloc->address >= src_address);
1328 run = reloc->address - src_address;
1329 parent++;
1331 else
1333 run = link_order->size - dst_address;
1335 /* Copy the bytes */
1336 for (idx = 0; idx < run; idx++)
1338 data[dst_address++] = data[src_address++];
1341 /* Now do the relocation */
1343 if (reloc)
1345 switch (reloc->howto->type)
1347 case ABS32CODE:
1348 calljx_callback (input_bfd, link_info, reloc,
1349 src_address + data, dst_address + data,
1350 input_section);
1351 src_address+=4;
1352 dst_address+=4;
1353 break;
1354 case ABS32:
1355 bfd_put_32 (input_bfd,
1356 (bfd_get_32 (input_bfd, data + src_address)
1357 + get_value (reloc, link_info, input_section)),
1358 data + dst_address);
1359 src_address+=4;
1360 dst_address+=4;
1361 break;
1362 case CALLJ:
1363 callj_callback (input_bfd, link_info, reloc, data,
1364 src_address, dst_address, input_section,
1365 false);
1366 src_address+=4;
1367 dst_address+=4;
1368 break;
1369 case ALIGNDONE:
1370 BFD_ASSERT (reloc->addend >= src_address);
1371 BFD_ASSERT (reloc->addend <= input_section->_raw_size);
1372 src_address = reloc->addend;
1373 dst_address = ((dst_address + reloc->howto->size)
1374 & ~reloc->howto->size);
1375 break;
1376 case ABS32CODE_SHRUNK:
1377 /* This used to be a callx, but we've found out that a
1378 callj will reach, so do the right thing. */
1379 callj_callback (input_bfd, link_info, reloc, data,
1380 src_address + 4, dst_address, input_section,
1381 true);
1382 dst_address+=4;
1383 src_address+=8;
1384 break;
1385 case PCREL24:
1387 long int word = bfd_get_32 (input_bfd,
1388 data + src_address);
1389 bfd_vma value;
1391 value = get_value (reloc, link_info, input_section);
1392 word = ((word & ~BAL_MASK)
1393 | (((word & BAL_MASK)
1394 + value
1395 - output_addr (input_section)
1396 + reloc->addend)
1397 & BAL_MASK));
1399 bfd_put_32 (input_bfd, word, data + dst_address);
1400 dst_address+=4;
1401 src_address+=4;
1404 break;
1406 case PCREL13:
1408 long int word = bfd_get_32 (input_bfd,
1409 data + src_address);
1410 bfd_vma value;
1412 value = get_value (reloc, link_info, input_section);
1413 word = ((word & ~PCREL13_MASK)
1414 | (((word & PCREL13_MASK)
1415 + value
1416 + reloc->addend
1417 - output_addr (input_section))
1418 & PCREL13_MASK));
1420 bfd_put_32 (input_bfd, word, data + dst_address);
1421 dst_address+=4;
1422 src_address+=4;
1425 break;
1427 default:
1428 abort();
1433 if (reloc_vector != NULL)
1434 free (reloc_vector);
1435 return data;
1436 error_return:
1437 if (reloc_vector != NULL)
1438 free (reloc_vector);
1439 return NULL;
1441 /***********************************************************************/
1443 /* Build the transfer vectors for Big and Little-Endian B.OUT files. */
1445 #define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
1446 #define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
1448 #define b_out_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
1449 #define b_out_bfd_link_add_symbols _bfd_generic_link_add_symbols
1450 #define b_out_bfd_final_link _bfd_generic_final_link
1451 #define b_out_bfd_link_split_section _bfd_generic_link_split_section
1452 #define b_out_bfd_gc_sections bfd_generic_gc_sections
1454 #define aout_32_get_section_contents_in_window \
1455 _bfd_generic_get_section_contents_in_window
1457 extern const bfd_target b_out_vec_little_host;
1459 const bfd_target b_out_vec_big_host =
1461 "b.out.big", /* name */
1462 bfd_target_aout_flavour,
1463 BFD_ENDIAN_LITTLE, /* data byte order is little */
1464 BFD_ENDIAN_BIG, /* hdr byte order is big */
1465 (HAS_RELOC | EXEC_P | /* object flags */
1466 HAS_LINENO | HAS_DEBUG |
1467 HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
1468 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
1469 '_', /* symbol leading char */
1470 ' ', /* ar_pad_char */
1471 16, /* ar_max_namelen */
1473 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1474 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1475 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
1476 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1477 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1478 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
1479 {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
1480 bfd_generic_archive_p, _bfd_dummy_target},
1481 {bfd_false, b_out_mkobject, /* bfd_set_format */
1482 _bfd_generic_mkarchive, bfd_false},
1483 {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
1484 _bfd_write_archive_contents, bfd_false},
1486 BFD_JUMP_TABLE_GENERIC (aout_32),
1487 BFD_JUMP_TABLE_COPY (_bfd_generic),
1488 BFD_JUMP_TABLE_CORE (_bfd_nocore),
1489 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
1490 BFD_JUMP_TABLE_SYMBOLS (aout_32),
1491 BFD_JUMP_TABLE_RELOCS (b_out),
1492 BFD_JUMP_TABLE_WRITE (b_out),
1493 BFD_JUMP_TABLE_LINK (b_out),
1494 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
1496 & b_out_vec_little_host,
1498 (PTR) 0,
1502 const bfd_target b_out_vec_little_host =
1504 "b.out.little", /* name */
1505 bfd_target_aout_flavour,
1506 BFD_ENDIAN_LITTLE, /* data byte order is little */
1507 BFD_ENDIAN_LITTLE, /* header byte order is little */
1508 (HAS_RELOC | EXEC_P | /* object flags */
1509 HAS_LINENO | HAS_DEBUG |
1510 HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
1511 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
1512 '_', /* symbol leading char */
1513 ' ', /* ar_pad_char */
1514 16, /* ar_max_namelen */
1515 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1516 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1517 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
1518 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
1519 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
1520 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
1522 {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */
1523 bfd_generic_archive_p, _bfd_dummy_target},
1524 {bfd_false, b_out_mkobject, /* bfd_set_format */
1525 _bfd_generic_mkarchive, bfd_false},
1526 {bfd_false, b_out_write_object_contents, /* bfd_write_contents */
1527 _bfd_write_archive_contents, bfd_false},
1529 BFD_JUMP_TABLE_GENERIC (aout_32),
1530 BFD_JUMP_TABLE_COPY (_bfd_generic),
1531 BFD_JUMP_TABLE_CORE (_bfd_nocore),
1532 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
1533 BFD_JUMP_TABLE_SYMBOLS (aout_32),
1534 BFD_JUMP_TABLE_RELOCS (b_out),
1535 BFD_JUMP_TABLE_WRITE (b_out),
1536 BFD_JUMP_TABLE_LINK (b_out),
1537 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
1539 & b_out_vec_big_host,
1541 (PTR) 0